MCPcopy Create free account
hub / github.com/tinode/chat / isRoutableIP

Function isRoutableIP

server/utils.go:904–932  ·  view source on GitHub ↗
(ipStr string)

Source from the content-addressed store, hash-verified

902var privateIPBlocks []*net.IPNet
903
904func 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}

Callers 2

getRemoteAddrFunction · 0.85
serveWebSocketFunction · 0.85

Calls 1

ContainsMethod · 0.80

Tested by

no test coverage detected