mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-20 17:10:08 +08:00
Some checks are pending
Test / test (1.20, macos-13) (push) Waiting to run
Test / test (1.20, macos-latest) (push) Waiting to run
Test / test (1.20, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.20, ubuntu-latest) (push) Waiting to run
Test / test (1.20, windows-latest) (push) Waiting to run
Test / test (1.21, macos-13) (push) Waiting to run
Test / test (1.21, macos-latest) (push) Waiting to run
Test / test (1.21, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.21, ubuntu-latest) (push) Waiting to run
Test / test (1.21, windows-latest) (push) Waiting to run
Test / test (1.22, macos-13) (push) Waiting to run
Test / test (1.22, macos-latest) (push) Waiting to run
Test / test (1.22, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.22, ubuntu-latest) (push) Waiting to run
Test / test (1.22, windows-latest) (push) Waiting to run
Test / test (1.23, macos-13) (push) Waiting to run
Test / test (1.23, macos-latest) (push) Waiting to run
Test / test (1.23, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.23, ubuntu-latest) (push) Waiting to run
Test / test (1.23, windows-latest) (push) Waiting to run
Test / test (1.24, macos-13) (push) Waiting to run
Test / test (1.24, macos-latest) (push) Waiting to run
Test / test (1.24, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.24, ubuntu-latest) (push) Waiting to run
Test / test (1.24, windows-latest) (push) Waiting to run
Test / test (1.25, macos-13) (push) Waiting to run
Test / test (1.25, macos-latest) (push) Waiting to run
Test / test (1.25, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.25, ubuntu-latest) (push) Waiting to run
Test / test (1.25, windows-latest) (push) Waiting to run
Trigger CMFA Update / trigger-CMFA-update (push) Waiting to run
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package dialer
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"net/netip"
|
|
"syscall"
|
|
|
|
"github.com/metacubex/mihomo/component/iface"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func bindControl(ifaceIdx int) controlFn {
|
|
return func(ctx context.Context, network, address string, c syscall.RawConn) (err error) {
|
|
addrPort, err := netip.ParseAddrPort(address)
|
|
if err == nil && !addrPort.Addr().IsGlobalUnicast() {
|
|
return
|
|
}
|
|
|
|
var innerErr error
|
|
err = c.Control(func(fd uintptr) {
|
|
switch network {
|
|
case "tcp6", "udp6", "ip6":
|
|
innerErr = unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_BOUND_IF, ifaceIdx)
|
|
default:
|
|
innerErr = unix.SetsockoptInt(int(fd), unix.IPPROTO_IP, unix.IP_BOUND_IF, ifaceIdx)
|
|
}
|
|
})
|
|
|
|
if innerErr != nil {
|
|
err = innerErr
|
|
}
|
|
|
|
return
|
|
}
|
|
}
|
|
|
|
func bindIfaceToDialer(ifaceName string, dialer *net.Dialer, _ string, _ netip.Addr) error {
|
|
ifaceObj, err := iface.ResolveInterface(ifaceName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
addControlToDialer(dialer, bindControl(ifaceObj.Index))
|
|
return nil
|
|
}
|
|
|
|
func bindIfaceToListenConfig(ifaceName string, lc *net.ListenConfig, _, address string, rAddrPort netip.AddrPort) (string, error) {
|
|
ifaceObj, err := iface.ResolveInterface(ifaceName)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
addControlToListenConfig(lc, bindControl(ifaceObj.Index))
|
|
return address, nil
|
|
}
|
|
|
|
func ParseNetwork(network string, addr netip.Addr) string {
|
|
return network
|
|
}
|