mirror of
https://github.com/netbirdio/ice.git
synced 2026-05-22 17:10:58 -07:00
Fix IPv6 addresses gathering
Fix isSupportedIPv6 function, when a global unicast address passed to, the function returns false. Resolves #176
This commit is contained in:
@@ -52,6 +52,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu
|
||||
* [Ori Bernstein](https://eigenstate.org)
|
||||
* [Sam Lancia](https://github.com/nerd2)
|
||||
* [Lander Noterman](https://github.com/LanderN)
|
||||
* [BUPTCZQ](https://github.com/buptczq)
|
||||
* [Henry](https://github.com/cryptix)
|
||||
|
||||
### License
|
||||
|
||||
@@ -25,7 +25,7 @@ func (a *atomicError) Load() error {
|
||||
// https://tools.ietf.org/html/rfc8445#section-5.1.1.1
|
||||
func isSupportedIPv6(ip net.IP) bool {
|
||||
if len(ip) != net.IPv6len ||
|
||||
!isZeros(ip[0:12]) || // !(IPv4-compatible IPv6)
|
||||
isZeros(ip[0:12]) || // !(IPv4-compatible IPv6)
|
||||
ip[0] == 0xfe && ip[1]&0xc0 == 0xc0 || // !(IPv6 site-local unicast)
|
||||
ip.IsLinkLocalUnicast() ||
|
||||
ip.IsLinkLocalMulticast() {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package ice
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIsSupportedIPv6(t *testing.T) {
|
||||
if isSupportedIPv6(net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}) {
|
||||
t.Errorf("isSupportedIPv6 return true with IPv4-compatible IPv6 address")
|
||||
}
|
||||
|
||||
if isSupportedIPv6(net.ParseIP("fec0::2333")) {
|
||||
t.Errorf("isSupportedIPv6 return true with IPv6 site-local unicast address")
|
||||
}
|
||||
|
||||
if isSupportedIPv6(net.ParseIP("fe80::2333")) {
|
||||
t.Errorf("isSupportedIPv6 return true with IPv6 link-local address")
|
||||
}
|
||||
|
||||
if isSupportedIPv6(net.ParseIP("ff02::2333")) {
|
||||
t.Errorf("isSupportedIPv6 return true with IPv6 link-local multicast address")
|
||||
}
|
||||
|
||||
if !isSupportedIPv6(net.ParseIP("2001::1")) {
|
||||
t.Errorf("isSupportedIPv6 return false with IPv6 global unicast address")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user