summaryrefslogtreecommitdiffhomepage
path: root/tun
diff options
context:
space:
mode:
authorKay Diam <kay.diam@gmail.com>2021-03-07 17:21:31 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2021-03-08 21:32:27 -0700
commit6005c573e24a8f1eb7503bf976cbabaecdce61f0 (patch)
treeea78edd67a42c33f54a9cacf323c3dc41843faa6 /tun
parent82f3e9e2afc1b52a88a691b1ce173623e525e4f0 (diff)
tun: freebsd: allow empty names
This change allows omitting the tun interface name setting. When the name is not set, the kernel automatically picks up the tun name and index. Signed-off-by: Kay Diam <kay.diam@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'tun')
-rw-r--r--tun/tun_freebsd.go34
1 files changed, 18 insertions, 16 deletions
diff --git a/tun/tun_freebsd.go b/tun/tun_freebsd.go
index 12b44da..1883aad 100644
--- a/tun/tun_freebsd.go
+++ b/tun/tun_freebsd.go
@@ -346,22 +346,24 @@ func CreateTUN(name string, mtu int) (Device, error) {
return nil, fmt.Errorf("Unable to set nd6 flags for %s: %w", assignedName, errno)
}
- // Rename the interface
- var newnp [unix.IFNAMSIZ]byte
- copy(newnp[:], name)
- var ifr ifreq_ptr
- copy(ifr.Name[:], assignedName)
- ifr.Data = uintptr(unsafe.Pointer(&newnp[0]))
- _, _, errno = unix.Syscall(
- unix.SYS_IOCTL,
- uintptr(confd),
- uintptr(unix.SIOCSIFNAME),
- uintptr(unsafe.Pointer(&ifr)),
- )
- if errno != 0 {
- tunFile.Close()
- tunDestroy(assignedName)
- return nil, fmt.Errorf("Failed to rename %s to %s: %w", assignedName, name, errno)
+ if name != "" {
+ // Rename the interface
+ var newnp [unix.IFNAMSIZ]byte
+ copy(newnp[:], name)
+ var ifr ifreq_ptr
+ copy(ifr.Name[:], assignedName)
+ ifr.Data = uintptr(unsafe.Pointer(&newnp[0]))
+ _, _, errno = unix.Syscall(
+ unix.SYS_IOCTL,
+ uintptr(confd),
+ uintptr(unix.SIOCSIFNAME),
+ uintptr(unsafe.Pointer(&ifr)),
+ )
+ if errno != 0 {
+ tunFile.Close()
+ tunDestroy(assignedName)
+ return nil, fmt.Errorf("Failed to rename %s to %s: %w", assignedName, name, errno)
+ }
}
return CreateTUNFromFile(tunFile, mtu)