Refactor bind control

This commit is contained in:
世界 2022-09-13 22:14:36 +08:00
parent a606585cf7
commit 93cc53b60c
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
8 changed files with 93 additions and 173 deletions

View file

@ -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)
})
}