diff --git a/conn.go b/conn.go index 636f073..7a9435d 100644 --- a/conn.go +++ b/conn.go @@ -1049,18 +1049,10 @@ func ipFromAnswerHeader(a dnsmessage.ResourceHeader, p dnsmessage.Parser) (ip [] return } -// The conditions of invalidation written below are defined in -// https://tools.ietf.org/html/rfc8445#section-5.1.1.1 func isSupportedIPv6(ip net.IP, ipv6Only bool) bool { if len(ip) != net.IPv6len || - isZeros(ip[0:12]) || // !(IPv4-compatible IPv6) - // IPv4-mapped IPv6 addresses SHOULD NOT be included in the address - // candidates unless the application using ICE does not support IPv4 - // (i.e., it is an IPv6-only application - (!ipv6Only && isZeros(ip[0:10]) && ip[10] == 0xff && ip[11] == 0xff) || - ip[0] == 0xfe && ip[1]&0xc0 == 0xc0 || // !(IPv6 site-local unicast) - ip.IsLinkLocalUnicast() || - ip.IsLinkLocalMulticast() { + // IPv4-mapped IPv6 addresses cannot be connected to + (!ipv6Only && isZeros(ip[0:10]) && ip[10] == 0xff && ip[11] == 0xff) { return false } return true diff --git a/conn_test.go b/conn_test.go index 09190e2..c01a568 100644 --- a/conn_test.go +++ b/conn_test.go @@ -388,14 +388,12 @@ func TestValidCommunicationIPv46Mixed(t *testing.T) { bServer, err := Server(nil, ipv6.NewPacketConn(bSock6), &Config{}) check(err, t) - ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond) - defer cancel() - - // we want ipv6 but all we can offer is an ipv4 address, so it should fail until we support - // allowing this explicitly via configuration on the aServer side - if _, _, err := bServer.Query(ctx, "pion-mdns-1.local"); !errors.Is(err, errContextElapsed) { - t.Fatalf("Query expired but returned unexpected error %v", err) + header, addr, err := bServer.Query(context.TODO(), "pion-mdns-1.local") + check(err, t) + if header.Type != dnsmessage.TypeAAAA { + t.Fatalf("expected AAAA but got %s", header.Type) } + checkIPv6(addr, t) check(aServer.Close(), t) check(bServer.Close(), t) @@ -434,7 +432,7 @@ func TestValidCommunicationIPv46MixedLocalAddress(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond) defer cancel() - // we want ipv6 but all we can offer is an ipv4 address, so it should fail until we support + // we want ipv6 but all we can offer is an ipv4 mapped address, so it should fail until we support // allowing this explicitly via configuration on the aServer side if _, _, err := bServer.Query(ctx, "pion-mdns-1.local"); !errors.Is(err, errContextElapsed) { t.Fatalf("Query expired but returned unexpected error %v", err) @@ -474,9 +472,6 @@ func TestValidCommunicationIPv66MixedLocalAddress(t *testing.T) { bServer, err := Server(nil, ipv6.NewPacketConn(bSock6), &Config{}) check(err, t) - // this will work compared to TestValidCommunicationIPv46MixedLocalAddress - // since this is considered to be an IPv6 only application so IPv4-mapped IPv6 addresses - // are allowed header, addr, err := bServer.Query(context.TODO(), "pion-mdns-1.local") check(err, t) if header.Type != dnsmessage.TypeAAAA {