{"record":{"id":"80cd2f6933c6c0d6","repo":"slackhq/nebula","slug":"failed-to-create-route-routemessage-for-change-w-80cd2f","errorCode":null,"errorMessage":"failed to create route.RouteMessage for change: %w","messagePattern":"failed to create route\\.RouteMessage for change: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"overlay/tun_netbsd.go","lineNumber":493,"sourceCode":"\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: &netroute.Inet6Addr{IP: gw.Addr().As16()},\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\tif errors.Is(err, unix.EEXIST) {\n\t\t\t// Try to do a change\n\t\t\troute.Type = unix.RTM_CHANGE\n\t\t\tdata, err = route.Marshal()\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to create route.RouteMessage for change: %w\", err)\n\t\t\t}\n\t\t\t_, err = unix.Write(sock, data[:])\n\t\t\treturn err\n\t\t}\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, gateways []netip.Prefix) 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":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/slackhq/nebula/blob/dd8f660c0ac37903ec4080ca4d3c861ba9342ceb/overlay/tun_netbsd.go#L475-L511","documentation":"When adding a route returns EEXIST (route already present), addRoute retries by re-marshaling the same message as RTM_CHANGE. This error is returned if that second Marshal() fails, meaning the fallback route-update could not be serialized either.","triggerScenarios":"addRoute encountering unix.EEXIST on the initial RTM_ADD write, then route.Marshal() failing again for the RTM_CHANGE message due to malformed message fields.","commonSituations":"Same malformed-prefix causes as the RTM_ADD marshal failure; the route already existed from a previous run while the message fields are also subtly invalid.","solutions":["Validate the prefix/gateway values as for the initial marshal failure (valid netip.Prefix, matching families).","Delete the stale existing route manually (route delete) and retry to confirm the message content is the problem.","Log the prefix, gateway, and route message fields before Marshal to pinpoint the invalid data.","Check the netroute library version for known NetBSD RTM_CHANGE serialization issues."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Same validation as RTM_ADD applies before the RTM_CHANGE fallback\nif !prefix.IsValid() || len(gateways) == 0 || !gateways[0].Addr().IsValid() {\n    return fmt.Errorf(\"cannot build RTM_CHANGE for invalid route %v\", prefix)\n}","typeGuard":null,"tryCatchPattern":"if err := addRoute(prefix, gateways); err != nil {\n    if strings.Contains(err.Error(), \"route.RouteMessage for change\") {\n        // EEXIST fallback also failed to marshal — remove stale route and retry once\n        _ = delRoute(prefix, gateways)\n        return addRoute(prefix, gateways)\n    }\n    return err\n}","preventionTips":["Validate route fields before calling addRoute so both RTM_ADD and RTM_CHANGE marshal cleanly.","Clean up stale routes from previous runs at startup to avoid the EEXIST path.","Log the exact route being installed when change fallbacks occur.","Prefer delete-then-add over relying on RTM_CHANGE when the route state is uncertain."],"tags":["netbsd","routing","marshal","eexist"],"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"}