From 6a67921e40d92052385b96375a3c7c256eef7156 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Thu, 2 Jun 2016 20:40:30 +0000 Subject: [PATCH] vendor: Revert to github.com/jackpal/gateway instead of fork It now includes all the fixes GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3246 --- lib/pmp/pmp.go | 2 +- .../calmh/gateway/gateway_common.go | 38 ------ .../calmh/gateway/gateway_darwin.go | 40 ------ .../github.com/calmh/gateway/gateway_linux.go | 75 ---------- .../{calmh => jackpal}/gateway/LICENSE | 0 .../jackpal/gateway/gateway_common.go | 129 ++++++++++++++++++ .../jackpal/gateway/gateway_darwin.go | 16 +++ .../jackpal/gateway/gateway_freebsd.go | 16 +++ .../jackpal/gateway/gateway_linux.go | 34 +++++ .../jackpal/gateway/gateway_solaris.go | 16 +++ .../gateway/gateway_unimplemented.go | 2 +- .../gateway/gateway_windows.go | 2 +- vendor/manifest | 14 +- 13 files changed, 221 insertions(+), 163 deletions(-) delete mode 100644 vendor/github.com/calmh/gateway/gateway_common.go delete mode 100644 vendor/github.com/calmh/gateway/gateway_darwin.go delete mode 100644 vendor/github.com/calmh/gateway/gateway_linux.go rename vendor/github.com/{calmh => jackpal}/gateway/LICENSE (100%) create mode 100644 vendor/github.com/jackpal/gateway/gateway_common.go create mode 100644 vendor/github.com/jackpal/gateway/gateway_darwin.go create mode 100644 vendor/github.com/jackpal/gateway/gateway_freebsd.go create mode 100644 vendor/github.com/jackpal/gateway/gateway_linux.go create mode 100644 vendor/github.com/jackpal/gateway/gateway_solaris.go rename vendor/github.com/{calmh => jackpal}/gateway/gateway_unimplemented.go (78%) rename vendor/github.com/{calmh => jackpal}/gateway/gateway_windows.go (85%) diff --git a/lib/pmp/pmp.go b/lib/pmp/pmp.go index 3327a1bfe..9dcabe7d3 100644 --- a/lib/pmp/pmp.go +++ b/lib/pmp/pmp.go @@ -13,7 +13,7 @@ import ( "time" "github.com/AudriusButkevicius/go-nat-pmp" - "github.com/calmh/gateway" + "github.com/jackpal/gateway" "github.com/syncthing/syncthing/lib/nat" ) diff --git a/vendor/github.com/calmh/gateway/gateway_common.go b/vendor/github.com/calmh/gateway/gateway_common.go deleted file mode 100644 index b04f4b9c5..000000000 --- a/vendor/github.com/calmh/gateway/gateway_common.go +++ /dev/null @@ -1,38 +0,0 @@ -package gateway - -import ( - "bytes" - "errors" - "net" -) - -var errNoGateway = errors.New("no gateway found") - -func parseRoutePrint(output []byte) (net.IP, error) { - // Windows route output format is always like this: - // =========================================================================== - // Active Routes: - // Network Destination Netmask Gateway Interface Metric - // 0.0.0.0 0.0.0.0 192.168.1.1 192.168.1.100 20 - // =========================================================================== - // I'm trying to pick the active route, - // then jump 2 lines and pick the third IP - // Not using regex because output is quite standard from Windows XP to 8 (NEEDS TESTING) - outputLines := bytes.Split(output, []byte("\n")) - for idx, line := range outputLines { - if bytes.Contains(line, []byte("Active Routes:")) { - if len(outputLines) <= idx+2 { - return nil, errNoGateway - } - - ipFields := bytes.Fields(outputLines[idx+2]) - if len(ipFields) < 3 { - return nil, errNoGateway - } - - ip := net.ParseIP(string(ipFields[2])) - return ip, nil - } - } - return nil, errNoGateway -} diff --git a/vendor/github.com/calmh/gateway/gateway_darwin.go b/vendor/github.com/calmh/gateway/gateway_darwin.go deleted file mode 100644 index 7fe7b5199..000000000 --- a/vendor/github.com/calmh/gateway/gateway_darwin.go +++ /dev/null @@ -1,40 +0,0 @@ -package gateway - -import ( - "bytes" - "io/ioutil" - "net" - "os/exec" -) - -func DiscoverGateway() (ip net.IP, err error) { - routeCmd := exec.Command("/sbin/route", "-n", "get", "0.0.0.0") - stdOut, err := routeCmd.StdoutPipe() - if err != nil { - return - } - if err = routeCmd.Start(); err != nil { - return - } - output, err := ioutil.ReadAll(stdOut) - if err != nil { - return - } - - // Darwin route out format is always like this: - // route to: default - // destination: default - // mask: default - // gateway: 192.168.1.1 - outputLines := bytes.Split(output, []byte("\n")) - for _, line := range outputLines { - if bytes.Contains(line, []byte("gateway:")) { - gatewayFields := bytes.Fields(line) - ip = net.ParseIP(string(gatewayFields[1])) - break - } - } - - err = routeCmd.Wait() - return -} diff --git a/vendor/github.com/calmh/gateway/gateway_linux.go b/vendor/github.com/calmh/gateway/gateway_linux.go deleted file mode 100644 index 333bde1dc..000000000 --- a/vendor/github.com/calmh/gateway/gateway_linux.go +++ /dev/null @@ -1,75 +0,0 @@ -package gateway - -import ( - "bytes" - "io/ioutil" - "net" - "os/exec" -) - -func discoverGatewayUsingIp() (ip net.IP, err error) { - routeCmd := exec.Command("ip", "route", "show") - stdOut, err := routeCmd.StdoutPipe() - if err != nil { - return - } - if err = routeCmd.Start(); err != nil { - return - } - output, err := ioutil.ReadAll(stdOut) - if err != nil { - return - } - - // Linux 'ip route show' format looks like this: - // default via 192.168.178.1 dev wlp3s0 metric 303 - // 192.168.178.0/24 dev wlp3s0 proto kernel scope link src 192.168.178.76 metric 303 - outputLines := bytes.Split(output, []byte("\n")) - for _, line := range outputLines { - if bytes.Contains(line, []byte("default")) { - ipFields := bytes.Fields(line) - ip = net.ParseIP(string(ipFields[2])) - break - } - } - err = routeCmd.Wait() - return -} - -func discoverGatewayUsingRoute() (ip net.IP, err error) { - routeCmd := exec.Command("route", "-n") - stdOut, err := routeCmd.StdoutPipe() - if err != nil { - return - } - if err = routeCmd.Start(); err != nil { - return - } - output, err := ioutil.ReadAll(stdOut) - if err != nil { - return - } - - // Linux route out format is always like this: - // Kernel IP routing table - // Destination Gateway Genmask Flags Metric Ref Use Iface - // 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0 - outputLines := bytes.Split(output, []byte("\n")) - for _, line := range outputLines { - if bytes.Contains(line, []byte("0.0.0.0")) { - ipFields := bytes.Fields(line) - ip = net.ParseIP(string(ipFields[1])) - break - } - } - err = routeCmd.Wait() - return -} - -func DiscoverGateway() (ip net.IP, err error) { - ip, err = discoverGatewayUsingRoute() - if err != nil { - ip, err = discoverGatewayUsingIp() - } - return -} diff --git a/vendor/github.com/calmh/gateway/LICENSE b/vendor/github.com/jackpal/gateway/LICENSE similarity index 100% rename from vendor/github.com/calmh/gateway/LICENSE rename to vendor/github.com/jackpal/gateway/LICENSE diff --git a/vendor/github.com/jackpal/gateway/gateway_common.go b/vendor/github.com/jackpal/gateway/gateway_common.go new file mode 100644 index 000000000..74cc7b267 --- /dev/null +++ b/vendor/github.com/jackpal/gateway/gateway_common.go @@ -0,0 +1,129 @@ +package gateway + +import ( + "errors" + "net" + "strings" +) + +var errNoGateway = errors.New("no gateway found") + +func parseWindowsRoutePrint(output []byte) (net.IP, error) { + // Windows route output format is always like this: + // =========================================================================== + // Active Routes: + // Network Destination Netmask Gateway Interface Metric + // 0.0.0.0 0.0.0.0 192.168.1.1 192.168.1.100 20 + // =========================================================================== + // I'm trying to pick the active route, + // then jump 2 lines and pick the third IP + // Not using regex because output is quite standard from Windows XP to 8 (NEEDS TESTING) + lines := strings.Split(string(output), "\n") + for idx, line := range lines { + if strings.HasPrefix(line, "Active Routes:") { + if len(lines) <= idx+2 { + return nil, errNoGateway + } + + fields := strings.Fields(lines[idx+2]) + if len(fields) < 3 { + return nil, errNoGateway + } + + ip := net.ParseIP(fields[2]) + if ip != nil { + return ip, nil + } + } + } + return nil, errNoGateway +} + +func parseLinuxIPRoute(output []byte) (net.IP, error) { + // Linux '/usr/bin/ip route show' format looks like this: + // default via 192.168.178.1 dev wlp3s0 metric 303 + // 192.168.178.0/24 dev wlp3s0 proto kernel scope link src 192.168.178.76 metric 303 + lines := strings.Split(string(output), "\n") + for _, line := range lines { + fields := strings.Fields(line) + if len(fields) >= 3 && fields[0] == "default" { + ip := net.ParseIP(fields[2]) + if ip != nil { + return ip, nil + } + } + } + + return nil, errNoGateway +} + +func parseLinuxRoute(output []byte) (net.IP, error) { + // Linux route out format is always like this: + // Kernel IP routing table + // Destination Gateway Genmask Flags Metric Ref Use Iface + // 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0 + lines := strings.Split(string(output), "\n") + for _, line := range lines { + fields := strings.Fields(line) + if len(fields) >= 2 && fields[0] == "0.0.0.0" { + ip := net.ParseIP(fields[1]) + if ip != nil { + return ip, nil + } + } + } + + return nil, errNoGateway +} + +func parseDarwinRouteGet(output []byte) (net.IP, error) { + // Darwin route out format is always like this: + // route to: default + // destination: default + // mask: default + // gateway: 192.168.1.1 + lines := strings.Split(string(output), "\n") + for _, line := range lines { + fields := strings.Fields(line) + if len(fields) >= 2 && fields[0] == "gateway:" { + ip := net.ParseIP(fields[1]) + if ip != nil { + return ip, nil + } + } + } + + return nil, errNoGateway +} + +func parseBSDSolarisNetstat(output []byte) (net.IP, error) { + // netstat -rn produces the following on FreeBSD: + // Routing tables + // + // Internet: + // Destination Gateway Flags Netif Expire + // default 10.88.88.2 UGS em0 + // 10.88.88.0/24 link#1 U em0 + // 10.88.88.148 link#1 UHS lo0 + // 127.0.0.1 link#2 UH lo0 + // + // Internet6: + // Destination Gateway Flags Netif Expire + // ::/96 ::1 UGRS lo0 + // ::1 link#2 UH lo0 + // ::ffff:0.0.0.0/96 ::1 UGRS lo0 + // fe80::/10 ::1 UGRS lo0 + // ... + outputLines := strings.Split(string(output), "\n") + for _, line := range outputLines { + fields := strings.Fields(line) + if len(fields) >= 2 && fields[0] == "default" { + ip := net.ParseIP(fields[1]) + if ip != nil { + return ip, nil + } + } + } + + return nil, errNoGateway +} diff --git a/vendor/github.com/jackpal/gateway/gateway_darwin.go b/vendor/github.com/jackpal/gateway/gateway_darwin.go new file mode 100644 index 000000000..32e755cbf --- /dev/null +++ b/vendor/github.com/jackpal/gateway/gateway_darwin.go @@ -0,0 +1,16 @@ +package gateway + +import ( + "net" + "os/exec" +) + +func DiscoverGateway() (net.IP, error) { + routeCmd := exec.Command("/sbin/route", "-n", "get", "0.0.0.0") + output, err := routeCmd.CombinedOutput() + if err != nil { + return nil, err + } + + return parseDarwinRouteGet(output) +} diff --git a/vendor/github.com/jackpal/gateway/gateway_freebsd.go b/vendor/github.com/jackpal/gateway/gateway_freebsd.go new file mode 100644 index 000000000..3d6691087 --- /dev/null +++ b/vendor/github.com/jackpal/gateway/gateway_freebsd.go @@ -0,0 +1,16 @@ +package gateway + +import ( + "net" + "os/exec" +) + +func DiscoverGateway() (ip net.IP, err error) { + routeCmd := exec.Command("netstat", "-rn") + output, err := routeCmd.CombinedOutput() + if err != nil { + return nil, err + } + + return parseBSDSolarisNetstat(output) +} diff --git a/vendor/github.com/jackpal/gateway/gateway_linux.go b/vendor/github.com/jackpal/gateway/gateway_linux.go new file mode 100644 index 000000000..c705632c2 --- /dev/null +++ b/vendor/github.com/jackpal/gateway/gateway_linux.go @@ -0,0 +1,34 @@ +package gateway + +import ( + "net" + "os/exec" +) + +func DiscoverGateway() (ip net.IP, err error) { + ip, err = discoverGatewayUsingRoute() + if err != nil { + ip, err = discoverGatewayUsingIp() + } + return +} + +func discoverGatewayUsingIp() (net.IP, error) { + routeCmd := exec.Command("/usr/bin/ip", "route", "show") + output, err := routeCmd.CombinedOutput() + if err != nil { + return nil, err + } + + return parseLinuxIPRoute(output) +} + +func discoverGatewayUsingRoute() (net.IP, error) { + routeCmd := exec.Command("/usr/bin/route", "-n") + output, err := routeCmd.CombinedOutput() + if err != nil { + return nil, err + } + + return parseLinuxRoute(output) +} diff --git a/vendor/github.com/jackpal/gateway/gateway_solaris.go b/vendor/github.com/jackpal/gateway/gateway_solaris.go new file mode 100644 index 000000000..3d6691087 --- /dev/null +++ b/vendor/github.com/jackpal/gateway/gateway_solaris.go @@ -0,0 +1,16 @@ +package gateway + +import ( + "net" + "os/exec" +) + +func DiscoverGateway() (ip net.IP, err error) { + routeCmd := exec.Command("netstat", "-rn") + output, err := routeCmd.CombinedOutput() + if err != nil { + return nil, err + } + + return parseBSDSolarisNetstat(output) +} diff --git a/vendor/github.com/calmh/gateway/gateway_unimplemented.go b/vendor/github.com/jackpal/gateway/gateway_unimplemented.go similarity index 78% rename from vendor/github.com/calmh/gateway/gateway_unimplemented.go rename to vendor/github.com/jackpal/gateway/gateway_unimplemented.go index 35042b910..750ac4b7a 100644 --- a/vendor/github.com/calmh/gateway/gateway_unimplemented.go +++ b/vendor/github.com/jackpal/gateway/gateway_unimplemented.go @@ -1,4 +1,4 @@ -// +build !darwin,!linux,!windows +// +build !darwin,!linux,!windows,!solaris,!freebsd package gateway diff --git a/vendor/github.com/calmh/gateway/gateway_windows.go b/vendor/github.com/jackpal/gateway/gateway_windows.go similarity index 85% rename from vendor/github.com/calmh/gateway/gateway_windows.go rename to vendor/github.com/jackpal/gateway/gateway_windows.go index 5f68bc1b0..4e944eefb 100644 --- a/vendor/github.com/calmh/gateway/gateway_windows.go +++ b/vendor/github.com/jackpal/gateway/gateway_windows.go @@ -12,5 +12,5 @@ func DiscoverGateway() (ip net.IP, err error) { return nil, err } - return parseRoutePrint(output) + return parseWindowsRoutePrint(output) } diff --git a/vendor/manifest b/vendor/manifest index 8d776fb28..0c91c777a 100644 --- a/vendor/manifest +++ b/vendor/manifest @@ -19,13 +19,6 @@ "revision": "3c0690cca16228b97741327b1b6781397afbdb24", "branch": "master" }, - { - "importpath": "github.com/calmh/gateway", - "repository": "https://github.com/calmh/gateway", - "revision": "edad739645120eeb82866bc1901d3317b57909b1", - "branch": "master", - "notests": true - }, { "importpath": "github.com/calmh/luhn", "repository": "https://github.com/calmh/luhn", @@ -121,6 +114,13 @@ "revision": "5f1c01d9f64b941dd9582c638279d046eda6ca31", "branch": "master" }, + { + "importpath": "github.com/jackpal/gateway", + "repository": "https://github.com/jackpal/gateway", + "revision": "3e333950771011fed13be63e62b9f473c5e0d9bf", + "branch": "master", + "notests": true + }, { "importpath": "github.com/juju/ratelimit", "repository": "https://github.com/juju/ratelimit",