{"record":{"id":"f88f6c779e851009","repo":"slackhq/nebula","slug":"failed-to-create-route-routemessage-w","errorCode":null,"errorMessage":"failed to create route.RouteMessage: %w","messagePattern":"failed to create route\\.RouteMessage: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"overlay/tun_darwin.go","lineNumber":452,"sourceCode":"\t}\n\n\tif prefix.Addr().Is4() {\n\t\troute.Addrs = []netroute.Addr{\n\t\t\tunix.RTAX_DST:     &netroute.Inet4Addr{IP: prefix.Masked().Addr().As4()},\n\t\t\tunix.RTAX_NETMASK: &netroute.Inet4Addr{IP: prefixToMask(prefix).As4()},\n\t\t\tunix.RTAX_GATEWAY: gateway,\n\t\t}\n\t} else {\n\t\troute.Addrs = []netroute.Addr{\n\t\t\tunix.RTAX_DST:     &netroute.Inet6Addr{IP: prefix.Masked().Addr().As16()},\n\t\t\tunix.RTAX_NETMASK: &netroute.Inet6Addr{IP: prefixToMask(prefix).As16()},\n\t\t\tunix.RTAX_GATEWAY: gateway,\n\t\t}\n\t}\n\n\tdata, err := route.Marshal()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create route.RouteMessage: %w\", err)\n\t}\n\n\t_, err = unix.Write(sock, data[:])\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to write route.RouteMessage to socket: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc delRoute(prefix netip.Prefix, gateway netroute.Addr) error {\n\tsock, err := unix.Socket(unix.AF_ROUTE, unix.SOCK_RAW, unix.AF_UNSPEC)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to create AF_ROUTE socket: %v\", err)\n\t}\n\tdefer unix.Close(sock)\n\n\troute := netroute.RouteMessage{","sourceCodeStart":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/slackhq/nebula/blob/dd8f660c0ac37903ec4080ca4d3c861ba9342ceb/overlay/tun_darwin.go#L434-L470","documentation":"addRoute() builds a netroute.RouteMessage (RTM_ADD) and calls route.Marshal() to serialize it for the kernel routing socket. This error is returned when Marshal() fails, meaning the route message could not be encoded for the kernel before any bytes are written.","triggerScenarios":"Called from activate4() or addRoutes(); route.Marshal() returns an error, typically because a required route attribute (e.g. the gateway netroute.Addr or destination addresses) is invalid or the message structure is malformed.","commonSituations":"A link-layer gateway address (netroute.LinkAddr) was not discovered correctly for the utun interface; unusual prefix lengths or zero-valued route fields make the message invalid; upstream x/net/route version incompatibilities.","solutions":["Verify the utun interface has a valid link address (the earlier 'unable to discover link_addr for tun interface' error would indicate a deeper device problem).","Check the configured route prefix in the tun.routes section is well-formed (valid IP and mask).","Update the golang.org/x/net dependency and rebuild, since Marshal behavior lives in x/net/route.","Reboot or recreate the tun device if the kernel interface state is stale, then retry activation."],"exampleFix":"// before: malformed route\nroutes:\n  - route: 10.0.0/24\n    via: 10.1.1.1\n// after\nroutes:\n  - route: 10.0.0.0/24\n    via: 10.1.1.1","handlingStrategy":"validation","validationCode":"func validateRoute(r Route) error {\n    if !r.Route.IsValid() || r.Route.Addr().IsUnspecified() {\n        return fmt.Errorf(\"route prefix invalid: %v\", r.Route)\n    }\n    if r.Via != nil && !r.Via.IsValid() {\n        return fmt.Errorf(\"route via invalid: %v\", r.Via)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := iface.Activate(); err != nil {\n    if strings.Contains(err.Error(), \"failed to create route.RouteMessage\") {\n        // re-check the tun.routes entries; fix malformed prefixes/gateways\n    }\n    return err\n}","preventionTips":["Validate all tun.routes prefixes with netip.ParsePrefix at config load","Keep the utun device healthy so the LinkAddr gateway resolves","Keep golang.org/x/net up to date","Avoid editing route tables externally while nebula activates"],"tags":["network","darwin","routing","route-message"],"backgroundTag":"route-message-marshal-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"}