@@ -40,7 +40,7 @@ type System struct {
4040 tcpNat * TCPNat
4141 udpNat * udpnat.Service [netip.AddrPort ]
4242 routeMapping * RouteMapping
43- underPlatform bool
43+ bindInterface bool
4444}
4545
4646type Session struct {
@@ -62,7 +62,7 @@ func NewSystem(options StackOptions) (Stack, error) {
6262 logger : options .Logger ,
6363 inet4Prefixes : options .Inet4Address ,
6464 inet6Prefixes : options .Inet6Address ,
65- underPlatform : options .UnderPlatform ,
65+ bindInterface : options .ForwarderBindInterface ,
6666 }
6767 if stack .router != nil {
6868 stack .routeMapping = NewRouteMapping (options .UDPTimeout )
@@ -96,8 +96,14 @@ func (s *System) Close() error {
9696
9797func (s * System ) Start () error {
9898 var listener net.ListenConfig
99- if s .underPlatform {
100- listener .Control = control .Append (listener .Control , control .BindToInterface (control .DefaultInterfaceFinder (), s .tunName , - 1 ))
99+ if s .bindInterface {
100+ listener .Control = control .Append (listener .Control , func (network , address string , conn syscall.RawConn ) error {
101+ err := control .BindToInterface (nil , s .tunName , - 1 )(network , address , conn )
102+ if err != nil {
103+ s .logger .Warn ("bind forwarder to interface: " , err )
104+ }
105+ return nil
106+ })
101107 }
102108 if s .inet4Address .IsValid () {
103109 tcpListener , err := listener .Listen (s .ctx , "tcp4" , net .JoinHostPort (s .inet4ServerAddress .String (), "0" ))
0 commit comments