Skip to content

Commit db67add

Browse files
committed
Ignore system bind error
1 parent 9c6e70b commit db67add

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

stack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type StackOptions struct {
2525
Router Router
2626
Handler Handler
2727
Logger logger.Logger
28-
UnderPlatform bool
28+
ForwarderBindInterface bool
2929
}
3030

3131
func NewStack(

system.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

4646
type 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

9797
func (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

Comments
 (0)