{"record":{"id":"16a788eee7563051","repo":"ginuerzh/gost","slug":"s-v-16a788","errorCode":null,"errorMessage":"%s: %v","messagePattern":"%s: %v","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tuntap_unix.go","lineNumber":38,"sourceCode":"\t}\n\n\tifce, err := water.New(water.Config{\n\t\tDeviceType: water.TUN,\n\t})\n\tif err != nil {\n\t\treturn\n\t}\n\n\tmtu := cfg.MTU\n\tif mtu <= 0 {\n\t\tmtu = DefaultMTU\n\t}\n\n\tcmd := fmt.Sprintf(\"ifconfig %s inet %s mtu %d up\", ifce.Name(), cfg.Addr, mtu)\n\tlog.Log(\"[tun]\", cmd)\n\targs := strings.Split(cmd, \" \")\n\tif er := exec.Command(args[0], args[1:]...).Run(); er != nil {\n\t\terr = fmt.Errorf(\"%s: %v\", cmd, er)\n\t\treturn\n\t}\n\n\tif err = addTunRoutes(ifce.Name(), cfg.Routes...); err != nil {\n\t\treturn\n\t}\n\n\titf, err = net.InterfaceByName(ifce.Name())\n\tif err != nil {\n\t\treturn\n\t}\n\n\tconn = &tunTapConn{\n\t\tifce: ifce,\n\t\taddr: &net.IPAddr{IP: ip},\n\t}\n\treturn\n}","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/tuntap_unix.go#L20-L56","documentation":"On BSD/macOS, createTun brings the newly created TUN interface up via `ifconfig <name> inet <addr> mtu <mtu> up`; if ifconfig fails (non-zero exit) the error is wrapped with the full command line. It is returned as the named error of createTun, so interface creation appears to fail even though the device node may already exist.","triggerScenarios":"Calling createTun on macOS/BSD when the address is invalid, MTU is out of range, the interface does not exist/was destroyed, or the process lacks privileges to configure the interface.","commonSituations":"Not running as root on macOS (ifconfig needs privileges to set addresses); passing an IPv6 address to a command formatted for `inet` only; devfs/BSD device not created because kext not loaded.","solutions":["Run the process as root (sudo) — ifconfig needs privileges to set an address on the interface","Verify cfg.Addr is a valid IPv4 address/prefix in CIDR form","Check the wrapped message: 'permission denied' vs 'invalid argument' vs 'does not exist' to decide between privilege, config, or device problems","Confirm the TUN kext/driver is loaded and the interface exists (`ifconfig <name>` before configure)"],"exampleFix":"// before\n_, err := tun.CreateTun(tun.Config{Addr: \"10.0.0.1/xx\", MTU: 1500}) // bad CIDR -> ifconfig fails\n// after\n_, err := tun.CreateTun(tun.Config{Addr: \"10.0.0.1/24\", MTU: 1500}) // run with sudo","handlingStrategy":"validation","validationCode":"func checkTunCfg(cfg tun.Config) error {\n    ip, _, err := net.ParseCIDR(cfg.Addr)\n    if err != nil || ip.To4() == nil {\n        return fmt.Errorf(\"tun: Addr must be IPv4 CIDR, got %q\", cfg.Addr)\n    }\n    if cfg.MTU < 68 || cfg.MTU > 65535 {\n        return fmt.Errorf(\"tun: invalid MTU %d\", cfg.MTU)\n    }\n    return nil\n}","typeGuard":"func validIPv4CIDR(s string) bool {\n    ip, _, err := net.ParseCIDR(s)\n    return err == nil && ip.To4() != nil\n}","tryCatchPattern":"ifce, err := tun.CreateTun(cfg)\nif err != nil {\n    if strings.Contains(err.Error(), \"permission denied\") {\n        return fmt.Errorf(\"re-run with sudo: %w\", err)\n    }\n    if strings.Contains(err.Error(), \"does not exist\") {\n        return fmt.Errorf(\"tun device missing — load driver: %w\", err)\n    }\n    return err\n}","preventionTips":["Run privileged on macOS/BSD when configuring interfaces","Validate Addr as IPv4 CIDR and MTU range before calling createTun","Verify the TUN driver/kext is loaded and the interface exists before configure","Read the wrapped command in the error — it names the exact tool and args that failed"],"tags":["ifconfig","macos","bsd","tuntap","privileges"],"backgroundTag":"command-execution-failed","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}