Feature: add fwmark support

This commit is contained in:
xjasonlyu
2021-02-10 15:46:55 +08:00
parent ea62deb0b6
commit 7f7f2913a8
11 changed files with 136 additions and 40 deletions

View File

@@ -7,13 +7,15 @@ import (
"golang.org/x/sys/unix"
)
func bindToInterface(network, address string, c syscall.RawConn) error {
ipStr, _, _ := net.SplitHostPort(address)
if ip := net.ParseIP(ipStr); ip != nil && !ip.IsGlobalUnicast() {
return nil
}
func bindToInterface(i *net.Interface) controlFunc {
return func(network, address string, c syscall.RawConn) error {
ipStr, _, _ := net.SplitHostPort(address)
if ip := net.ParseIP(ipStr); ip != nil && !ip.IsGlobalUnicast() {
return nil
}
return c.Control(func(fd uintptr) {
unix.BindToDevice(int(fd), _boundInterface.Name)
})
return c.Control(func(fd uintptr) {
unix.BindToDevice(int(fd), i.Name)
})
}
}