Skip to content

Commit

Permalink
android: Fix netlink check
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Sep 26, 2023
1 parent 8adce0e commit 2a0a0ab
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions monitor_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/sagernet/netlink"
"github.com/sagernet/sing/common/logger"
"github.com/sagernet/sing/common/x/list"

"golang.org/x/sys/unix"
)

type networkUpdateMonitor struct {
Expand All @@ -27,10 +29,18 @@ func NewNetworkUpdateMonitor(logger logger.Logger) (NetworkUpdateMonitor, error)
close: make(chan struct{}),
logger: logger,
}
// check is netlink banned by google
if runtime.GOOS == "android" {
_, err := netlink.LinkList()
netlinkSocket, err := unix.Socket(unix.AF_NETLINK, unix.SOCK_DGRAM, unix.NETLINK_ROUTE)
if err != nil {
return nil, os.ErrInvalid
}
err = unix.Bind(netlinkSocket, &unix.SockaddrNetlink{
Family: unix.AF_NETLINK,
})
unix.Close(netlinkSocket)
if err != nil {
return nil, err
return nil, os.ErrInvalid
}
}
return monitor, nil
Expand Down

0 comments on commit 2a0a0ab

Please sign in to comment.