mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-06 13:27:39 +03:00
Refactor bind control
This commit is contained in:
parent
a606585cf7
commit
93cc53b60c
8 changed files with 93 additions and 173 deletions
|
@ -2,32 +2,12 @@ package control
|
|||
|
||||
import (
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func NewBindManager() BindManager {
|
||||
return nil
|
||||
}
|
||||
|
||||
func BindToInterface(manager BindManager, interfaceName string) Func {
|
||||
return func(network, address string, conn syscall.RawConn) error {
|
||||
return Raw(conn, func(fd uintptr) error {
|
||||
return syscall.BindToDevice(int(fd), interfaceName)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BindToInterfaceFunc(manager BindManager, interfaceNameFunc func(network, address string) string) Func {
|
||||
return func(network, address string, conn syscall.RawConn) error {
|
||||
interfaceName := interfaceNameFunc(network, address)
|
||||
if interfaceName == "" {
|
||||
return nil
|
||||
}
|
||||
return Raw(conn, func(fd uintptr) error {
|
||||
return syscall.BindToDevice(int(fd), interfaceName)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BindToInterfaceIndexFunc(interfaceIndexFunc func(network, address string) int) Func {
|
||||
return nil
|
||||
func bindToInterface(conn syscall.RawConn, network string, address string, interfaceName string, interfaceIndex int) error {
|
||||
return Raw(conn, func(fd uintptr) error {
|
||||
return unix.BindToDevice(int(fd), interfaceName)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue