-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathbind_linux.go
More file actions
32 lines (27 loc) · 879 Bytes
/
Copy pathbind_linux.go
File metadata and controls
32 lines (27 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//go:build linux
package main
import (
"syscall"
"golang.org/x/sys/unix"
)
const deviceBindSupported = true
// SO_BINDTODEVICE needs CAP_NET_RAW. A positive maxseg clamps TCP MSS: a tun
// that advertises a large MTU but really egresses over a smaller internet path
// PMTU-blackholes big TLS records, so registration over such an interface must
// cap the segment size.
func deviceControl(iface string, maxseg int) func(network, address string, c syscall.RawConn) error {
return func(_, _ string, c syscall.RawConn) error {
var opErr error
if err := c.Control(func(fd uintptr) {
if opErr = unix.SetsockoptString(int(fd), unix.SOL_SOCKET, unix.SO_BINDTODEVICE, iface); opErr != nil {
return
}
if maxseg > 0 {
opErr = unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_MAXSEG, maxseg)
}
}); err != nil {
return err
}
return opErr
}
}