(ipStr string)
| 902 | var privateIPBlocks []*net.IPNet |
| 903 | |
| 904 | func isRoutableIP(ipStr string) bool { |
| 905 | ip := net.ParseIP(ipStr) |
| 906 | if ip == nil { |
| 907 | return false |
| 908 | } |
| 909 | |
| 910 | if ip.IsLoopback() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() { |
| 911 | return false |
| 912 | } |
| 913 | |
| 914 | if privateIPBlocks == nil { |
| 915 | for _, cidr := range []string{ |
| 916 | "10.0.0.0/8", // RFC1918 |
| 917 | "172.16.0.0/12", // RFC1918 |
| 918 | "192.168.0.0/16", // RFC1918 |
| 919 | "fc00::/7", // RFC4193, IPv6 unique local addr |
| 920 | } { |
| 921 | _, block, _ := net.ParseCIDR(cidr) |
| 922 | privateIPBlocks = append(privateIPBlocks, block) |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | for _, block := range privateIPBlocks { |
| 927 | if block.Contains(ip) { |
| 928 | return false |
| 929 | } |
| 930 | } |
| 931 | return true |
| 932 | } |
no test coverage detected