{"record":{"id":"6205d204b92eac20","repo":"OpenNHP/opennhp","slug":"failed-to-parse-default-route","errorCode":null,"errorMessage":"failed to parse default route","messagePattern":"failed to parse default route","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"endpoints/ac/ebpf/ebpfegine.go","lineNumber":287,"sourceCode":"\t\tip&0xFF,\n\t\t(ip>>8)&0xFF,\n\t\t(ip>>16)&0xFF,\n\t\t(ip>>24)&0xFF)\n}\n\nfunc getDefaultRouteInterface() (string, error) {\n\tcmd := exec.Command(\"ip\", \"route\")\n\toutput, err := cmd.Output()\n\tif err != nil {\n\t\tlog.Error(\"failed to get running ip route:\")\n\t\treturn \"\", err\n\t}\n\n\tre := regexp.MustCompile(`default via (\\S+) dev (\\S+)`)\n\tmatches := re.FindStringSubmatch(string(output))\n\tif len(matches) < 3 {\n\t\tlog.Error(\"failed to parse default route\")\n\t\treturn \"\", fmt.Errorf(\"failed to parse default route\")\n\t}\n\tinterfaceName := matches[2]\n\treturn interfaceName, nil\n}\n\n// clean eBPF map file\nfunc CleanupBPFFiles() {\n\tbpfFiles := []string{\n\t\t\"/sys/fs/bpf/xdp_white_prog\",\n\t\t\"/sys/fs/bpf/conn_track\",\n\t\t\"/sys/fs/bpf/icmpwhitelist\",\n\t\t\"/sys/fs/bpf/port_list\",\n\t\t\"/sys/fs/bpf/protocol_port\",\n\t\t\"/sys/fs/bpf/sdwhitelist\",\n\t\t\"/sys/fs/bpf/src_port\",\n\t\t\"/sys/fs/bpf/spp\",\n\t\t\"/sys/fs/bpf/tc_egress_prog\",\n\t}","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/endpoints/ac/ebpf/ebpfegine.go#L269-L305","documentation":"getDefaultRouteInterface parses `ip route show default` output with the regex `default via (\\S+) dev (\\S+)` and returns \"failed to parse default route\" when fewer than 3 matches are found, i.e. the route table has no `default via X dev Y` line. EbpfEngineLoad depends on this to know which interface to attach the XDP program to.","triggerScenarios":"`ip route show default` returns empty or unexpected output: no default route configured, a default route without a 'via' hop (point-to-point/on-link), localized/modified iproute2 output, or the `ip` binary is missing (command output empty).","commonSituations":"EC2/containers with only a link-scoped default route (`default dev eth0`); minimal container images without iproute2; hosts using multiple default routes or networkmanager custom formatting.","solutions":["Ensure the host has a standard default route: `ip route add default via <gw> dev eth0`","Handle the via-less form by falling back to regex `default(?: via (\\S+))? dev (\\S+)` and reading the dev group","Fall back to parsing /proc/net/route or `ip -j route show default` JSON when regex parsing fails","Install iproute2 in minimal images and verify `ip route show default` manually"],"exampleFix":"// before\nre := regexp.MustCompile(`default via (\\S+) dev (\\S+)`)\nmatches := re.FindStringSubmatch(string(output))\nif len(matches) < 3 {\n\treturn \"\", fmt.Errorf(\"failed to parse default route\")\n}\n// after\nre := regexp.MustCompile(`default(?: via (\\S+))? dev (\\S+)`)\nmatches := re.FindStringSubmatch(string(output))\nif len(matches) < 3 {\n\treturn \"\", fmt.Errorf(\"failed to parse default route from %q\", string(output))\n}\ninterfaceName := matches[2]","handlingStrategy":"fallback","validationCode":"out, err := exec.Command(\"ip\", \"route\", \"show\", \"default\").Output()\nif err != nil || len(out) == 0 {\n\treturn fmt.Errorf(\"no default route: ip output empty (install iproute2?)\")\n}","typeGuard":null,"tryCatchPattern":"iface, err := getDefaultRouteInterface()\nif err != nil {\n\tiface = os.Getenv(\"NHP_XDP_IFACE\") // manual override\n\tif iface == \"\" { return err }\n}","preventionTips":["Ensure a standard `default via <gw> dev <if>` route exists","Install iproute2 in container/minimal images","Support an explicit interface config option as fallback"],"tags":["network","routing","ebpf","linux"],"backgroundTag":"resource-not-found","analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}