Skip to content

Commit

Permalink
Relax isSupportedIPv6 to just no mapped
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniels committed Feb 9, 2024
1 parent 7c8d1a0 commit a94c441
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
12 changes: 2 additions & 10 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 6 additions & 11 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a94c441

Please sign in to comment.