Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slayers: unmap IPv4-mapped IPv6 addresses #4377

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pkg/slayers/scion.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,15 +394,16 @@ func ParseAddr(addrType AddrType, raw []byte) (addr.Host, error) {
func PackAddr(host addr.Host) (AddrType, []byte, error) {
switch host.Type() {
case addr.HostTypeIP:
ip := host.IP()
// The IP is potentially IPv4-in-IPv6. We need to unmap it to ensure
// we only have true IPv4 or IPv6 addresses.
ip := host.IP().Unmap()
if !ip.IsValid() {
break
}
t := T4Ip
if ip.Is6() {
t = T16Ip
return T16Ip, ip.AsSlice(), nil
}
return t, ip.AsSlice(), nil
return T4Ip, ip.AsSlice(), nil
case addr.HostTypeSVC:
raw := make([]byte, 4)
binary.BigEndian.PutUint16(raw, uint16(host.SVC()))
Expand Down
15 changes: 11 additions & 4 deletions pkg/slayers/scion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ import (
)

var (
ip6Addr = addr.MustParseHost("2001:db8::68")
ip4Addr = addr.MustParseHost("10.0.0.100")
svcAddr = addr.MustParseHost("Wildcard")
rawPath = func() []byte {
ip6Addr = addr.MustParseHost("2001:db8::68")
ip4Addr = addr.MustParseHost("10.0.0.100")
ip4in6Addr = addr.MustParseHost("::ffff:10.0.0.100")
svcAddr = addr.MustParseHost("Wildcard")
rawPath = func() []byte {
return []byte("\x00\x00\x20\x80\x00\x00\x01\x11\x00\x00\x01\x00\x01\x00\x02\x22\x00" +
"\x00\x01\x00\x00\x3f\x00\x01\x00\x00\x01\x02\x03\x04\x05\x06\x00\x3f\x00\x03\x00" +
"\x02\x01\x02\x03\x04\x05\x06\x00\x3f\x00\x00\x00\x02\x01\x02\x03\x04\x05\x06\x00" +
Expand Down Expand Up @@ -311,6 +312,12 @@ func TestPackAddr(t *testing.T) {
rawAddr: ip4Addr.IP().AsSlice(),
errorFunc: assert.NoError,
},
"pack IPv4-mapped IPv6": {
addr: ip4in6Addr,
addrType: slayers.T4Ip,
rawAddr: []byte{0xa, 0x0, 0x0, 0x64},
errorFunc: assert.NoError,
},
"pack IPv6": {
addr: ip6Addr,
addrType: slayers.T16Ip,
Expand Down
Loading