{"record":{"id":"47701d5f42430796","repo":"slackhq/nebula","slug":"failed-to-set-tun-address-s-s-47701d","errorCode":null,"errorMessage":"failed to set tun address %s: %s","messagePattern":"failed to set tun address (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"overlay/tun_netbsd.go","lineNumber":264,"sourceCode":"\t\treq.DstAddr = unix.RawSockaddrInet4{\n\t\t\tLen:    unix.SizeofSockaddrInet4,\n\t\t\tFamily: unix.AF_INET,\n\t\t\tAddr:   cidr.Addr().As4(),\n\t\t}\n\t\treq.MaskAddr = unix.RawSockaddrInet4{\n\t\t\tLen:    unix.SizeofSockaddrInet4,\n\t\t\tFamily: unix.AF_INET,\n\t\t\tAddr:   prefixToMask(cidr).As4(),\n\t\t}\n\n\t\ts, err := unix.Socket(unix.AF_INET, unix.SOCK_DGRAM, unix.IPPROTO_IP)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tdefer syscall.Close(s)\n\n\t\tif err := ioctl(uintptr(s), unix.SIOCAIFADDR, uintptr(unsafe.Pointer(&req))); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to set tun address %s: %s\", cidr.Addr(), err)\n\t\t}\n\n\t\treturn nil\n\t}\n\n\tif cidr.Addr().Is6() {\n\t\tvar req ifreqAlias6\n\t\treq.Name = t.deviceBytes()\n\t\treq.Addr = unix.RawSockaddrInet6{\n\t\t\tLen:    unix.SizeofSockaddrInet6,\n\t\t\tFamily: unix.AF_INET6,\n\t\t\tAddr:   cidr.Addr().As16(),\n\t\t}\n\t\treq.PrefixMask = unix.RawSockaddrInet6{\n\t\t\tLen:    unix.SizeofSockaddrInet6,\n\t\t\tFamily: unix.AF_INET6,\n\t\t\tAddr:   prefixToMask(cidr).As16(),\n\t\t}","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/slackhq/nebula/blob/dd8f660c0ac37903ec4080ca4d3c861ba9342ceb/overlay/tun_netbsd.go#L246-L282","documentation":"addIp configures an IPv4 address on the tun device using the SIOCAIFADDR ioctl on a UDP socket. If the ioctl fails, the library wraps the errno with this message naming the CIDR being assigned. Commonly the interface is down, the address/mask is invalid, or permission is lacking.","triggerScenarios":"Calling Activate()/addIp with an IPv4 CIDR while the SIOCAIFADDR ioctl returns an error (EADDRNOTAVAIL, EINVAL, EPERM, or interface not created/up).","commonSituations":"Running without root/CAP_NET_ADMIN on NetBSD; assigning an address before the tun device exists; netmask mismatches.","solutions":["Run the process as root (or with appropriate privilege) — tun ioctls require elevated rights","Create the device first: ifconfig tun0 create, and bring it up before/after address assignment","Verify the IPv4 CIDR is valid and matches the configured range"],"exampleFix":"// before\nsudo ./app\n// after\n# as root, and ensure device exists first\nifconfig tun0 create\nsudo ./app","handlingStrategy":"try-catch","validationCode":"if err := validateCIDRv4(cidr); err != nil { return err }\nif os.Geteuid() != 0 { return errors.New(\"tun address setup requires root\") }","typeGuard":null,"tryCatchPattern":"if err := iface.AddIp(cidr); err != nil {\n    log.Printf(\"add IPv4 %s failed: %v — check privileges and that the device exists\", cidr, err)\n}","preventionTips":["Run as root when configuring tun addresses","Create the device (ifconfig tunN create) before assigning addresses","Validate IPv4 CIDR syntax before activation"],"tags":["netbsd","tun","ioctl","ip-address","permissions"],"backgroundTag":"tun-address-assignment-failed","analyzedSha":"dd8f660c0ac37903ec4080ca4d3c861ba9342ceb","analyzedAt":"2026-09-03T11:13:55.444Z","contentChangedAt":"2026-09-03T11:13:55.444Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}