This commit is contained in:
世界 2022-08-24 18:56:17 +08:00
parent b2bb9b3d2a
commit e5c59fc756
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
3 changed files with 31 additions and 16 deletions

View file

@ -6,3 +6,16 @@ fmt:
fmt_install:
go install -v mvdan.cc/gofumpt@latest
go install -v github.com/daixiang0/gci@v0.4.0
lint:
GOOS=linux golangci-lint run .
GOOS=android golangci-lint run .
GOOS=windows golangci-lint run .
GOOS=darwin golangci-lint run .
GOOS=freebsd golangci-lint run .
lint_install:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
test:
go test -v ./...

View file

@ -6,6 +6,7 @@ import (
"net"
E "github.com/sagernet/sing/common/exceptions"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
)

View file

@ -27,9 +27,12 @@ func (m *defaultInterfaceMonitor) checkUpdate() error {
return err
}
for _, route := range routes {
if len(routes) == 0 {
return E.Extend(ErrNoRoute, "no route in default table ", defaultTableIndex)
}
var link netlink.Link
link, err = netlink.LinkByIndex(route.LinkIndex)
link, err = netlink.LinkByIndex(routes[0].LinkIndex)
if err != nil {
return err
}
@ -43,9 +46,7 @@ func (m *defaultInterfaceMonitor) checkUpdate() error {
if oldInterface == m.defaultInterfaceName && oldIndex == m.defaultInterfaceIndex {
return nil
}
m.emit()
return nil
}
return E.Extend(ErrNoRoute, "no route in default table ", defaultTableIndex)
}