mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-21 06:01:42 +00:00
net/dnscache: parse passed CIDR
Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
This commit is contained in:
parent
4800926006
commit
5a1ce4adae
@ -133,7 +133,7 @@ func (r *Resolver) addIPCache(host string, ip net.IP, d time.Duration) net.IP {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func mustCIDR(s string) *net.IPNet {
|
func mustCIDR(s string) *net.IPNet {
|
||||||
_, ipNet, err := net.ParseCIDR("100.64.0.0/10")
|
_, ipNet, err := net.ParseCIDR(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
24
net/dnscache/dnscache_test.go
Normal file
24
net/dnscache/dnscache_test.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package dnscache
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestIsPrivateIP(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
ip string
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{"10.1.2.3", true},
|
||||||
|
{"172.16.1.100", true},
|
||||||
|
{"192.168.1.1", true},
|
||||||
|
{"1.2.3.4", false},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
if got := isPrivateIP(net.ParseIP(test.ip)); got != test.want {
|
||||||
|
t.Errorf("isPrivateIP(%q)=%v, want %v", test.ip, got, test.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user