IsGloballyRoutable returns true for unicast addresses that aren't private,
loopback, or link local.

Change-Id: Iecab0f2910fdea604613ca774484bf3b2f503732
diff --git a/runtimes/google/lib/netconfig/isgloballyroutable.go b/runtimes/google/lib/netconfig/isgloballyroutable.go
new file mode 100644
index 0000000..4fa5916
--- /dev/null
+++ b/runtimes/google/lib/netconfig/isgloballyroutable.go
@@ -0,0 +1,29 @@
+package netconfig
+
+import (
+	"net"
+)
+
+var privateCIDRs = []net.IPNet{
+	net.IPNet{IP: net.IPv4(10, 0, 0, 0), Mask: net.IPv4Mask(0xff, 0, 0, 0)},
+	net.IPNet{IP: net.IPv4(172, 16, 0, 0), Mask: net.IPv4Mask(0xff, 0xf0, 0, 0)},
+	net.IPNet{IP: net.IPv4(192, 168, 0, 0), Mask: net.IPv4Mask(0xff, 0xff, 0, 0)},
+}
+
+// IsGloballyRoutable returns true if the argument is a globally routable IP address.
+func IsGloballyRoutable(ip net.IP) bool {
+	if !ip.IsGlobalUnicast() {
+		return false
+	}
+	if ip4 := ip.To4(); ip4 != nil {
+		for _, cidr := range privateCIDRs {
+			if cidr.Contains(ip4) {
+				return false
+			}
+		}
+		if ip4.Equal(net.IPv4bcast) {
+			return false
+		}
+	}
+	return true
+}
diff --git a/runtimes/google/lib/netconfig/isgloballyroutable_test.go b/runtimes/google/lib/netconfig/isgloballyroutable_test.go
new file mode 100644
index 0000000..3cce082
--- /dev/null
+++ b/runtimes/google/lib/netconfig/isgloballyroutable_test.go
@@ -0,0 +1,31 @@
+package netconfig
+
+import (
+	"net"
+	"testing"
+)
+
+func TestIsGloballyRoutable(t *testing.T) {
+	tests := []struct {
+		ip   string
+		want bool
+	}{
+		{"192.168.1.1", false},
+		{"192.169.0.3", true},
+		{"10.1.1.1", false},
+		{"172.17.100.255", false},
+		{"172.32.0.1", true},
+		{"255.255.255.255", false},
+		{"127.0.0.1", false},
+		{"224.0.0.1", false},
+		{"FF02::FB", false},
+		{"fe80::be30:5bff:fed3:843f", false},
+		{"2620:0:1000:8400:be30:5bff:fed3:843f", true},
+	}
+	for _, test := range tests {
+		ip := net.ParseIP(test.ip)
+		if got := IsGloballyRoutable(ip); got != test.want {
+			t.Fatalf("%s: want %v got %v", test.ip, test.want, got)
+		}
+	}
+}