diff --git a/pkg/slayers/scion.go b/pkg/slayers/scion.go index 7e24772f14..66ff20c755 100644 --- a/pkg/slayers/scion.go +++ b/pkg/slayers/scion.go @@ -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())) diff --git a/pkg/slayers/scion_test.go b/pkg/slayers/scion_test.go index 06d4967551..a794587614 100644 --- a/pkg/slayers/scion_test.go +++ b/pkg/slayers/scion_test.go @@ -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" + @@ -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,