github.com/apernet/sing-tun@v0.2.6-0.20240323130332-b9f6511036ad/monitor.go (about)

     1  package tun
     2  
     3  import (
     4  	"net/netip"
     5  
     6  	E "github.com/sagernet/sing/common/exceptions"
     7  	"github.com/sagernet/sing/common/x/list"
     8  )
     9  
    10  var ErrNoRoute = E.New("no route to internet")
    11  
    12  type (
    13  	NetworkUpdateCallback          = func()
    14  	DefaultInterfaceUpdateCallback = func(event int)
    15  )
    16  
    17  const (
    18  	EventInterfaceUpdate  = 1
    19  	EventAndroidVPNUpdate = 2
    20  	EventNoRoute          = 4
    21  )
    22  
    23  type NetworkUpdateMonitor interface {
    24  	Start() error
    25  	Close() error
    26  	RegisterCallback(callback NetworkUpdateCallback) *list.Element[NetworkUpdateCallback]
    27  	UnregisterCallback(element *list.Element[NetworkUpdateCallback])
    28  }
    29  
    30  type DefaultInterfaceMonitor interface {
    31  	Start() error
    32  	Close() error
    33  	DefaultInterfaceName(destination netip.Addr) string
    34  	DefaultInterfaceIndex(destination netip.Addr) int
    35  	DefaultInterface(destination netip.Addr) (string, int)
    36  	OverrideAndroidVPN() bool
    37  	AndroidVPNEnabled() bool
    38  	RegisterCallback(callback DefaultInterfaceUpdateCallback) *list.Element[DefaultInterfaceUpdateCallback]
    39  	UnregisterCallback(element *list.Element[DefaultInterfaceUpdateCallback])
    40  }
    41  
    42  type DefaultInterfaceMonitorOptions struct {
    43  	OverrideAndroidVPN    bool
    44  	UnderNetworkExtension bool
    45  }