Add auto_route and auto_detect_interface for linux
This commit is contained in:
23
common/dialer/auto_linux.go
Normal file
23
common/dialer/auto_linux.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package dialer
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing/common/control"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
)
|
||||
|
||||
func BindToInterface(router adapter.Router) control.Func {
|
||||
return func(network, address string, conn syscall.RawConn) error {
|
||||
interfaceName := router.DefaultInterfaceName()
|
||||
if interfaceName == "" {
|
||||
return nil
|
||||
}
|
||||
var innerErr error
|
||||
err := conn.Control(func(fd uintptr) {
|
||||
innerErr = syscall.BindToDevice(int(fd), interfaceName)
|
||||
})
|
||||
return E.Errors(innerErr, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user