Improve control options

This commit is contained in:
世界 2022-07-14 21:02:41 +08:00
parent f8c0f71a89
commit 09b55ce4b6
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
7 changed files with 197 additions and 5 deletions

View file

@ -6,7 +6,11 @@ import (
E "github.com/sagernet/sing/common/exceptions"
)
func BindToInterface(interfaceName string) Func {
func NewBindManager() BindManager {
return nil
}
func BindToInterface(manager BindManager, interfaceName string) Func {
return func(network, address string, conn syscall.RawConn) error {
var innerErr error
err := conn.Control(func(fd uintptr) {
@ -15,3 +19,21 @@ func BindToInterface(interfaceName string) Func {
return E.Errors(innerErr, err)
}
}
func BindToInterfaceFunc(manager BindManager, interfaceNameFunc func() string) Func {
return func(network, address string, conn syscall.RawConn) error {
interfaceName := interfaceNameFunc()
if interfaceName == "" {
return nil
}
var innerErr error
err := conn.Control(func(fd uintptr) {
innerErr = syscall.BindToDevice(int(fd), interfaceName)
})
return E.Errors(innerErr, err)
}
}
func BindToInterfaceIndexFunc(interfaceIndexFunc func() int) Func {
return nil
}