sing-box/constant/network.go
世界 9e27f3413b
Fix unbounded ICMP sockets in direct outbound
The direct outbound opens one ICMP socket for each echo flow. The
sockets were kept for one minute after the last packet and their
number was not limited, so scanning hosts through the outbound could
accumulate an unbounded number of sockets, which has been reported to
panic the kernel on macOS.

Close idle flows after ICMPTimeout as the stacks do, and keep at most
1024 flows, closing a least recently active one when the limit is
reached.
2026-11-16 06:46:49 +00:00

60 lines
1.2 KiB
Go

package constant
import (
"github.com/sagernet/sing/common"
F "github.com/sagernet/sing/common/format"
)
const ICMPFlowMax = 1024
type InterfaceType uint8
const (
InterfaceTypeWIFI InterfaceType = iota
InterfaceTypeCellular
InterfaceTypeEthernet
InterfaceTypeOther
)
var (
interfaceTypeToString = map[InterfaceType]string{
InterfaceTypeWIFI: "wifi",
InterfaceTypeCellular: "cellular",
InterfaceTypeEthernet: "ethernet",
InterfaceTypeOther: "other",
}
StringToInterfaceType = common.ReverseMap(interfaceTypeToString)
)
func (t InterfaceType) String() string {
name, loaded := interfaceTypeToString[t]
if !loaded {
return F.ToString(int(t))
}
return name
}
type NetworkStrategy uint8
const (
NetworkStrategyDefault NetworkStrategy = iota
NetworkStrategyFallback
NetworkStrategyHybrid
)
var (
networkStrategyToString = map[NetworkStrategy]string{
NetworkStrategyDefault: "default",
NetworkStrategyFallback: "fallback",
NetworkStrategyHybrid: "hybrid",
}
StringToNetworkStrategy = common.ReverseMap(networkStrategyToString)
)
func (s NetworkStrategy) String() string {
name, loaded := networkStrategyToString[s]
if !loaded {
return F.ToString(int(s))
}
return name
}