android: Check netlink available on monitor create
This commit is contained in:
parent
b6d323004e
commit
8adce0ea02
1 changed files with 10 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ package tun
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/sagernet/netlink"
|
"github.com/sagernet/netlink"
|
||||||
|
|
@ -20,12 +21,19 @@ type networkUpdateMonitor struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNetworkUpdateMonitor(logger logger.Logger) (NetworkUpdateMonitor, error) {
|
func NewNetworkUpdateMonitor(logger logger.Logger) (NetworkUpdateMonitor, error) {
|
||||||
return &networkUpdateMonitor{
|
monitor := &networkUpdateMonitor{
|
||||||
routeUpdate: make(chan netlink.RouteUpdate, 2),
|
routeUpdate: make(chan netlink.RouteUpdate, 2),
|
||||||
linkUpdate: make(chan netlink.LinkUpdate, 2),
|
linkUpdate: make(chan netlink.LinkUpdate, 2),
|
||||||
close: make(chan struct{}),
|
close: make(chan struct{}),
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}, nil
|
}
|
||||||
|
if runtime.GOOS == "android" {
|
||||||
|
_, err := netlink.LinkList()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return monitor, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *networkUpdateMonitor) Start() error {
|
func (m *networkUpdateMonitor) Start() error {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue