mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-22 22:58:25 +00:00
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
This commit is contained in:
parent
8709fec517
commit
6a67921e40
@ -13,7 +13,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AudriusButkevicius/go-nat-pmp"
|
"github.com/AudriusButkevicius/go-nat-pmp"
|
||||||
"github.com/calmh/gateway"
|
"github.com/jackpal/gateway"
|
||||||
"github.com/syncthing/syncthing/lib/nat"
|
"github.com/syncthing/syncthing/lib/nat"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
38
vendor/github.com/calmh/gateway/gateway_common.go
generated
vendored
38
vendor/github.com/calmh/gateway/gateway_common.go
generated
vendored
@ -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
|
|
||||||
}
|
|
40
vendor/github.com/calmh/gateway/gateway_darwin.go
generated
vendored
40
vendor/github.com/calmh/gateway/gateway_darwin.go
generated
vendored
@ -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
|
|
||||||
}
|
|
75
vendor/github.com/calmh/gateway/gateway_linux.go
generated
vendored
75
vendor/github.com/calmh/gateway/gateway_linux.go
generated
vendored
@ -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
|
|
||||||
}
|
|
0
vendor/github.com/calmh/gateway/LICENSE → vendor/github.com/jackpal/gateway/LICENSE
generated
vendored
0
vendor/github.com/calmh/gateway/LICENSE → vendor/github.com/jackpal/gateway/LICENSE
generated
vendored
129
vendor/github.com/jackpal/gateway/gateway_common.go
generated
vendored
Normal file
129
vendor/github.com/jackpal/gateway/gateway_common.go
generated
vendored
Normal file
@ -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
|
||||||
|
}
|
16
vendor/github.com/jackpal/gateway/gateway_darwin.go
generated
vendored
Normal file
16
vendor/github.com/jackpal/gateway/gateway_darwin.go
generated
vendored
Normal file
@ -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)
|
||||||
|
}
|
16
vendor/github.com/jackpal/gateway/gateway_freebsd.go
generated
vendored
Normal file
16
vendor/github.com/jackpal/gateway/gateway_freebsd.go
generated
vendored
Normal file
@ -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)
|
||||||
|
}
|
34
vendor/github.com/jackpal/gateway/gateway_linux.go
generated
vendored
Normal file
34
vendor/github.com/jackpal/gateway/gateway_linux.go
generated
vendored
Normal file
@ -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)
|
||||||
|
}
|
16
vendor/github.com/jackpal/gateway/gateway_solaris.go
generated
vendored
Normal file
16
vendor/github.com/jackpal/gateway/gateway_solaris.go
generated
vendored
Normal file
@ -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)
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
// +build !darwin,!linux,!windows
|
// +build !darwin,!linux,!windows,!solaris,!freebsd
|
||||||
|
|
||||||
package gateway
|
package gateway
|
||||||
|
|
@ -12,5 +12,5 @@ func DiscoverGateway() (ip net.IP, err error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return parseRoutePrint(output)
|
return parseWindowsRoutePrint(output)
|
||||||
}
|
}
|
14
vendor/manifest
vendored
14
vendor/manifest
vendored
@ -19,13 +19,6 @@
|
|||||||
"revision": "3c0690cca16228b97741327b1b6781397afbdb24",
|
"revision": "3c0690cca16228b97741327b1b6781397afbdb24",
|
||||||
"branch": "master"
|
"branch": "master"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"importpath": "github.com/calmh/gateway",
|
|
||||||
"repository": "https://github.com/calmh/gateway",
|
|
||||||
"revision": "edad739645120eeb82866bc1901d3317b57909b1",
|
|
||||||
"branch": "master",
|
|
||||||
"notests": true
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"importpath": "github.com/calmh/luhn",
|
"importpath": "github.com/calmh/luhn",
|
||||||
"repository": "https://github.com/calmh/luhn",
|
"repository": "https://github.com/calmh/luhn",
|
||||||
@ -121,6 +114,13 @@
|
|||||||
"revision": "5f1c01d9f64b941dd9582c638279d046eda6ca31",
|
"revision": "5f1c01d9f64b941dd9582c638279d046eda6ca31",
|
||||||
"branch": "master"
|
"branch": "master"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"importpath": "github.com/jackpal/gateway",
|
||||||
|
"repository": "https://github.com/jackpal/gateway",
|
||||||
|
"revision": "3e333950771011fed13be63e62b9f473c5e0d9bf",
|
||||||
|
"branch": "master",
|
||||||
|
"notests": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"importpath": "github.com/juju/ratelimit",
|
"importpath": "github.com/juju/ratelimit",
|
||||||
"repository": "https://github.com/juju/ratelimit",
|
"repository": "https://github.com/juju/ratelimit",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user