Fix linux route

This commit is contained in:
世界 2022-07-15 16:49:34 +08:00
parent 9dc73c0bcc
commit 9968d2c8e9
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
5 changed files with 489 additions and 103 deletions

View file

@ -2,7 +2,6 @@ package tun
import (
"context"
"net"
"os"
"sync"
@ -122,41 +121,6 @@ func (m *defaultInterfaceMonitor) Close() error {
return nil
}
func (m *defaultInterfaceMonitor) checkUpdate() error {
routes, err := netlink.RouteList(nil, netlink.FAMILY_V4)
if err != nil {
return err
}
for _, route := range routes {
var link netlink.Link
link, err = netlink.LinkByIndex(route.LinkIndex)
if err != nil {
return err
}
if link.Attrs().Flags&net.FlagUp == 0 {
continue
}
if link.Type() == "tuntap" {
continue
}
oldInterface := m.defaultInterfaceName
oldIndex := m.defaultInterfaceIndex
m.defaultInterfaceName = link.Attrs().Name
m.defaultInterfaceIndex = link.Attrs().Index
if oldInterface == m.defaultInterfaceName && oldIndex == m.defaultInterfaceIndex {
return nil
}
m.callback()
return nil
}
return E.New("no route to internet")
}
func (m *defaultInterfaceMonitor) DefaultInterfaceName() string {
return m.defaultInterfaceName
}