mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-09-24 08:50:29 +00:00
Fix crash when interface monitor is unavailable
This commit is contained in:
@@ -109,7 +109,11 @@ func (t *Transport) Start(stage adapter.StartStage) error {
|
||||
return nil
|
||||
}
|
||||
if t.interfaceName == "" {
|
||||
t.interfaceCallback = t.networkManager.InterfaceMonitor().RegisterCallback(t.interfaceUpdated)
|
||||
interfaceMonitor := t.networkManager.InterfaceMonitor()
|
||||
if interfaceMonitor == nil {
|
||||
return E.New("missing monitor for auto DHCP, set route.auto_detect_interface")
|
||||
}
|
||||
t.interfaceCallback = interfaceMonitor.RegisterCallback(t.interfaceUpdated)
|
||||
}
|
||||
go func() {
|
||||
err := t.fetch()
|
||||
|
||||
@@ -99,7 +99,11 @@ func (h *Outbound) Start(stage adapter.StartStage) error {
|
||||
}
|
||||
|
||||
func (h *Outbound) fetchMyAddresses() {
|
||||
myInterfaceNames := h.network.InterfaceMonitor().MyInterfaces()
|
||||
interfaceMonitor := h.network.InterfaceMonitor()
|
||||
if interfaceMonitor == nil {
|
||||
return
|
||||
}
|
||||
myInterfaceNames := interfaceMonitor.MyInterfaces()
|
||||
if len(myInterfaceNames) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -29,6 +29,9 @@ func NewDefaultInterfaceAddressItem(networkManager adapter.NetworkManager, inter
|
||||
}
|
||||
|
||||
func (r *DefaultInterfaceAddressItem) Match(metadata *adapter.InboundContext) bool {
|
||||
if r.interfaceMonitor == nil {
|
||||
return false
|
||||
}
|
||||
defaultInterface := r.interfaceMonitor.DefaultInterface()
|
||||
if defaultInterface == nil {
|
||||
return false
|
||||
|
||||
@@ -40,7 +40,11 @@ func NewNetworkInterfaceAddressItem(networkManager adapter.NetworkManager, inter
|
||||
|
||||
func (r *NetworkInterfaceAddressItem) Match(metadata *adapter.InboundContext) bool {
|
||||
interfaces := r.networkManager.NetworkInterfaces()
|
||||
myInterfaces := r.networkManager.InterfaceMonitor().MyInterfaces()
|
||||
var myInterfaces []string
|
||||
interfaceMonitor := r.networkManager.InterfaceMonitor()
|
||||
if interfaceMonitor != nil {
|
||||
myInterfaces = interfaceMonitor.MyInterfaces()
|
||||
}
|
||||
match:
|
||||
for ifType, addresses := range r.interfaceAddresses {
|
||||
for _, networkInterface := range interfaces {
|
||||
|
||||
Reference in New Issue
Block a user