Skip to content

Commit 98a6fdb

Browse files
authored
tun: bsd: remove redundant ioctl to set MTU (#1172)
wireguard's CreateTUN() sets the MTU using the same ioctl(2), on both FreeBSD and OpenBSD. Tested on OpenBSD (outputwith this patch): ``` # ktrace ./yggdrasil -autoconf | grep Interface 2024/09/24 17:26:29 Interface name: tun0 2024/09/24 17:26:29 Interface IPv6: 201:26e:68f0:502e:f445:13eb:2fe1:f7cd/7 2024/09/24 17:26:29 Interface MTU: 16384 ``` ``` $ ifconfig tun0 | head -n1 tun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 16384 ``` ``` # kdump | grep ioctl 53097 yggdrasil CALL ioctl(10,SIOCGIFMTU,0xc0000376b8) 53097 yggdrasil RET ioctl 0 53097 yggdrasil CALL ioctl(10,SIOCSIFMTU,0xc0000376c0) 53097 yggdrasil RET ioctl 0 53097 yggdrasil CALL ioctl(10,SIOCGIFMTU,0xc0000377f8) 53097 yggdrasil RET ioctl 0 53097 yggdrasil CALL ioctl(10,_IOW('i',12,0x20),0xc00003777c) 53097 yggdrasil RET ioctl -1 errno 25 Inappropriate ioctl for device "2024/09/24 17:26:29 Error in SIOCSIFADDR_IN6: inappropriate ioctl for device ``` (The completely broken address ioctl is another story...)
1 parent c00779c commit 98a6fdb

File tree

1 file changed

+0
-25
lines changed

1 file changed

+0
-25
lines changed

src/tun/tun_bsd.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ struct in6_ifreq {
5454
290 };
5555
*/
5656

57-
type in6_ifreq_mtu struct {
58-
ifr_name [syscall.IFNAMSIZ]byte
59-
ifru_mtu int
60-
}
61-
6257
type in6_ifreq_addr struct {
6358
ifr_name [syscall.IFNAMSIZ]byte
6459
ifru_addr sockaddr_in6
@@ -112,26 +107,6 @@ func (tun *TunAdapter) setupAddress(addr string) error {
112107
tun.log.Infof("Interface IPv6: %s", addr)
113108
tun.log.Infof("Interface MTU: %d", tun.mtu)
114109

115-
// Create the MTU request
116-
var ir in6_ifreq_mtu
117-
copy(ir.ifr_name[:], tun.Name())
118-
ir.ifru_mtu = int(tun.mtu)
119-
120-
// Set the MTU
121-
if _, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(sfd), uintptr(syscall.SIOCSIFMTU), uintptr(unsafe.Pointer(&ir))); errno != 0 {
122-
err = errno
123-
tun.log.Errorf("Error in SIOCSIFMTU: %v", errno)
124-
125-
// Fall back to ifconfig to set the MTU
126-
cmd := exec.Command("ifconfig", tun.Name(), "mtu", string(tun.mtu))
127-
tun.log.Warnf("Using ifconfig as fallback: %v", strings.Join(cmd.Args, " "))
128-
output, err := cmd.CombinedOutput()
129-
if err != nil {
130-
tun.log.Errorf("SIOCSIFMTU fallback failed: %v.", err)
131-
tun.log.Traceln(string(output))
132-
}
133-
}
134-
135110
// Create the address request
136111
// FIXME: I don't work!
137112
var ar in6_ifreq_addr

0 commit comments

Comments
 (0)