mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-04-04 04:17:39 +03:00
Fix lint
This commit is contained in:
parent
b2bb9b3d2a
commit
e5c59fc756
3 changed files with 31 additions and 16 deletions
15
Makefile
15
Makefile
|
@ -5,4 +5,17 @@ fmt:
|
||||||
|
|
||||||
fmt_install:
|
fmt_install:
|
||||||
go install -v mvdan.cc/gofumpt@latest
|
go install -v mvdan.cc/gofumpt@latest
|
||||||
go install -v github.com/daixiang0/gci@v0.4.0
|
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 ./...
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
E "github.com/sagernet/sing/common/exceptions"
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
|
|
||||||
"gvisor.dev/gvisor/pkg/tcpip"
|
"gvisor.dev/gvisor/pkg/tcpip"
|
||||||
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
|
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,25 +27,26 @@ func (m *defaultInterfaceMonitor) checkUpdate() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, route := range routes {
|
if len(routes) == 0 {
|
||||||
var link netlink.Link
|
return E.Extend(ErrNoRoute, "no route in default table ", defaultTableIndex)
|
||||||
link, err = netlink.LinkByIndex(route.LinkIndex)
|
}
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
oldInterface := m.defaultInterfaceName
|
var link netlink.Link
|
||||||
oldIndex := m.defaultInterfaceIndex
|
link, err = netlink.LinkByIndex(routes[0].LinkIndex)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
m.defaultInterfaceName = link.Attrs().Name
|
oldInterface := m.defaultInterfaceName
|
||||||
m.defaultInterfaceIndex = link.Attrs().Index
|
oldIndex := m.defaultInterfaceIndex
|
||||||
|
|
||||||
if oldInterface == m.defaultInterfaceName && oldIndex == m.defaultInterfaceIndex {
|
m.defaultInterfaceName = link.Attrs().Name
|
||||||
return nil
|
m.defaultInterfaceIndex = link.Attrs().Index
|
||||||
}
|
|
||||||
m.emit()
|
if oldInterface == m.defaultInterfaceName && oldIndex == m.defaultInterfaceIndex {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return E.Extend(ErrNoRoute, "no route in default table ", defaultTableIndex)
|
m.emit()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue