Skip to content

Commit

Permalink
Merge pull request #5 from masa23/main
Browse files Browse the repository at this point in the history
Fixed IPv6 address parsing to handle IPv6: prefix
  • Loading branch information
d--j authored Apr 5, 2023
2 parents 46df6fc + e3eda61 commit d568301
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ func (m *serverSession) Process(msg *wire.Message) (*Response, error) {
if addr != nil {
address = addr.String()
}
} else if strings.HasPrefix(address, "IPv6:") {
addr = net.ParseIP(address[5:])
if addr != nil {
address = addr.String()
}
} else {
addr = net.ParseIP(address)
}
Expand Down
22 changes: 20 additions & 2 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func Test_milterSession_Process(t *testing.T) {
check: func(t *testing.T, s *serverSession) {
p := s.backend.(*processTestMilter)
if p.family != "tcp6" {
t.Errorf("expected tcp4, got %q", p.family)
t.Errorf("expected tcp6, got %q", p.family)
}
if p.addr != "::" {
t.Errorf("expected ::, got %q", p.addr)
Expand All @@ -278,7 +278,7 @@ func Test_milterSession_Process(t *testing.T) {
check: func(t *testing.T, s *serverSession) {
p := s.backend.(*processTestMilter)
if p.family != "tcp6" {
t.Errorf("expected tcp4, got %q", p.family)
t.Errorf("expected tcp6, got %q", p.family)
}
if p.addr != "::" {
t.Errorf("expected ::, got %q", p.addr)
Expand All @@ -291,6 +291,24 @@ func Test_milterSession_Process(t *testing.T) {
}
},
}, &wire.Message{wire.CodeConn, []byte{'h', 0, '6', 9, 251, '[', ':', ':', ']', 0}}, cont, false},
{"conn tcp6 protocol 3", fields{
backend: &processTestMilter{},
check: func(t *testing.T, s *serverSession) {
p := s.backend.(*processTestMilter)
if p.family != "tcp6" {
t.Errorf("expected tcp6, got %q", p.family)
}
if p.addr != "::1" {
t.Errorf("expected ::1, got %q", p.addr)
}
if p.port != 2555 {
t.Errorf("expected 2555, got %v", p.port)
}
if p.host != "h" {
t.Errorf("expected \"h\", got %q", p.host)
}
},
}, &wire.Message{wire.CodeConn, []byte{'h', 0, '6', 9, 251, 'I', 'P', 'v', '6', ':', '0', ':', '0', ':', '0', ':', '0', ':', '0', ':', '0', ':', '0', ':', '1', 0}}, cont, false},
{"conn tcp6 protocol err", fields{
backend: &processTestMilter{},
}, &wire.Message{wire.CodeConn, []byte{'h', 0, '6', 9, 251, '[', '@', ']', 0}}, nil, true},
Expand Down

0 comments on commit d568301

Please sign in to comment.