Unverified Commit 53d1ae09 authored by Seungbae Yu's avatar Seungbae Yu Committed by GitHub

p2p/nat: use IP.IsPrivate (#26252)

parent 8c6e74ee
...@@ -95,13 +95,6 @@ func discoverPMP() Interface { ...@@ -95,13 +95,6 @@ func discoverPMP() Interface {
return nil return nil
} }
var (
// LAN IP ranges
_, lan10, _ = net.ParseCIDR("10.0.0.0/8")
_, lan176, _ = net.ParseCIDR("172.16.0.0/12")
_, lan192, _ = net.ParseCIDR("192.168.0.0/16")
)
// TODO: improve this. We currently assume that (on most networks) // TODO: improve this. We currently assume that (on most networks)
// the router is X.X.X.1 in a local LAN range. // the router is X.X.X.1 in a local LAN range.
func potentialGateways() (gws []net.IP) { func potentialGateways() (gws []net.IP) {
...@@ -116,7 +109,7 @@ func potentialGateways() (gws []net.IP) { ...@@ -116,7 +109,7 @@ func potentialGateways() (gws []net.IP) {
} }
for _, addr := range ifaddrs { for _, addr := range ifaddrs {
if x, ok := addr.(*net.IPNet); ok { if x, ok := addr.(*net.IPNet); ok {
if lan10.Contains(x.IP) || lan176.Contains(x.IP) || lan192.Contains(x.IP) { if x.IP.IsPrivate() {
ip := x.IP.Mask(x.Mask).To4() ip := x.IP.Mask(x.Mask).To4()
if ip != nil { if ip != nil {
ip[3] = ip[3] | 0x01 ip[3] = ip[3] | 0x01
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment