diff --git a/src/nm-route-manager.c b/src/nm-route-manager.c index 77cc761456..8c4c6a14f7 100644 --- a/src/nm-route-manager.c +++ b/src/nm-route-manager.c @@ -515,7 +515,7 @@ _vx_route_sync (const VTableIP *vtable, NMRouteManager *self, int ifindex, const * device routes, on the second the others (gateway routes). */ continue; } - vtable->vt->route_add (NM_PLATFORM_GET, 0, rest_route, 0); + vtable->vt->route_add (NM_PLATFORM_GET, 0, rest_route); } } g_array_unref (to_restore_routes); @@ -559,7 +559,7 @@ _vx_route_sync (const VTableIP *vtable, NMRouteManager *self, int ifindex, const || route_id_cmp_result != 0 || !_route_equals_ignoring_ifindex (vtable, cur_plat_route, cur_ipx_route)) { - if (!vtable->vt->route_add (NM_PLATFORM_GET, ifindex, cur_ipx_route, 0)) { + if (!vtable->vt->route_add (NM_PLATFORM_GET, ifindex, cur_ipx_route)) { if (cur_ipx_route->rx.source < NM_IP_CONFIG_SOURCE_USER) { _LOGD (vtable->vt->addr_family, "ignore error adding IPv%c route to kernel: %s", diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 1299dea7a5..0582c0d714 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -1289,6 +1289,7 @@ _nmp_vt_cmd_plobj_init_from_nl_ip4_route (NMPlatform *platform, NMPlatformObject struct rtnl_route *nlo = (struct rtnl_route *) _nlo; struct nl_addr *dst, *gw; struct rtnl_nexthop *nexthop; + struct nl_addr *pref_src; if (rtnl_route_get_type (nlo) != RTN_UNICAST || rtnl_route_get_table (nlo) != RT_TABLE_MAIN || @@ -1334,6 +1335,14 @@ _nmp_vt_cmd_plobj_init_from_nl_ip4_route (NMPlatform *platform, NMPlatformObject } else obj->source = _nm_ip_config_source_from_rtprot (rtnl_route_get_protocol (nlo)); + pref_src = rtnl_route_get_pref_src (nlo); + if (pref_src) { + if (nl_addr_get_len (pref_src) != sizeof (obj->pref_src)) + g_warn_if_reached (); + else + memcpy (&obj->pref_src, nl_addr_get_binary_addr (pref_src), sizeof (obj->pref_src)); + } + return TRUE; } @@ -4346,7 +4355,7 @@ _nmp_vt_cmd_plobj_to_nl_ip4_route (NMPlatform *platform, const NMPlatformObject &obj->network, obj->plen, &obj->gateway, - NULL, + obj->pref_src ? &obj->pref_src : NULL, obj->metric, obj->mss); } diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 52e5e51aa4..8439191d18 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -2177,7 +2177,6 @@ nm_platform_ip4_route_add (NMPlatform *self, if (nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) { NMPlatformIP4Route route = { 0 }; - char pref_src_buf[NM_UTILS_INET_ADDRSTRLEN]; route.ifindex = ifindex; route.source = source; @@ -2186,11 +2185,9 @@ nm_platform_ip4_route_add (NMPlatform *self, route.gateway = gateway; route.metric = metric; route.mss = mss; + route.pref_src = pref_src; - debug ("route: adding or updating IPv4 route: %s%s%s%s", nm_platform_ip4_route_to_string (&route), - pref_src ? " (src: " : "", - pref_src ? nm_utils_inet4_ntop (pref_src, pref_src_buf) : "", - pref_src ? ")" : ""); + debug ("route: adding or updating IPv4 route: %s", nm_platform_ip4_route_to_string (&route)); } return klass->ip4_route_add (self, ifindex, source, network, plen, gateway, pref_src, metric, mss); } @@ -2595,6 +2592,7 @@ const char * nm_platform_ip4_route_to_string (const NMPlatformIP4Route *route) { char s_network[INET_ADDRSTRLEN], s_gateway[INET_ADDRSTRLEN]; + char s_pref_src[INET_ADDRSTRLEN]; char str_dev[TO_STRING_DEV_BUF_SIZE]; char str_scope[30]; @@ -2613,6 +2611,7 @@ nm_platform_ip4_route_to_string (const NMPlatformIP4Route *route) " mss %"G_GUINT32_FORMAT " src %s" /* source */ "%s%s" /* scope */ + "%s%s" /* pref-src */ "", s_network, route->plen, s_gateway, @@ -2621,7 +2620,9 @@ nm_platform_ip4_route_to_string (const NMPlatformIP4Route *route) route->mss, source_to_string (route->source), route->scope_inv ? " scope " : "", - route->scope_inv ? (rtnl_scope2str (nm_platform_route_scope_inv (route->scope_inv), str_scope, sizeof (str_scope))) : ""); + route->scope_inv ? (rtnl_scope2str (nm_platform_route_scope_inv (route->scope_inv), str_scope, sizeof (str_scope))) : "", + route->pref_src ? " pref-src " : "", + route->pref_src ? inet_ntop (AF_INET, &route->pref_src, s_pref_src, sizeof(s_pref_src)) : ""); return _nm_platform_to_string_buffer; } @@ -2800,6 +2801,7 @@ nm_platform_ip4_route_cmp (const NMPlatformIP4Route *a, const NMPlatformIP4Route _CMP_FIELD (a, b, metric); _CMP_FIELD (a, b, mss); _CMP_FIELD (a, b, scope_inv); + _CMP_FIELD (a, b, pref_src); return 0; } @@ -2922,7 +2924,7 @@ log_ip6_route (NMPlatform *p, NMPObjectType obj_type, int ifindex, NMPlatformIP6 /******************************************************************/ static gboolean -_vtr_v4_route_add (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route, guint32 v4_pref_src) +_vtr_v4_route_add (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route) { return nm_platform_ip4_route_add (self, ifindex > 0 ? ifindex : route->rx.ifindex, @@ -2930,13 +2932,13 @@ _vtr_v4_route_add (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *rout route->r4.network, route->rx.plen, route->r4.gateway, - v4_pref_src, + route->r4.pref_src, route->rx.metric, route->rx.mss); } static gboolean -_vtr_v6_route_add (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route, guint32 v4_pref_src) +_vtr_v6_route_add (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route) { return nm_platform_ip6_route_add (self, ifindex > 0 ? ifindex : route->rx.ifindex, diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 4ad30b7de1..89f218b363 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -276,6 +276,10 @@ struct _NMPlatformIP4Route { /* The bitwise inverse of the route scope. It is inverted so that the * default value (RT_SCOPE_NOWHERE) is nul. */ guint8 scope_inv; + + /* RTA_PREFSRC/rtnl_route_get_pref_src(). A value of zero means that + * no pref-src is set. */ + guint32 pref_src; }; G_STATIC_ASSERT (G_STRUCT_OFFSET (NMPlatformIPRoute, network_ptr) == G_STRUCT_OFFSET (NMPlatformIP4Route, network)); @@ -305,7 +309,7 @@ typedef struct { int (*route_cmp) (const NMPlatformIPXRoute *a, const NMPlatformIPXRoute *b); const char *(*route_to_string) (const NMPlatformIPXRoute *route); GArray *(*route_get_all) (NMPlatform *self, int ifindex, NMPlatformGetRouteMode mode); - gboolean (*route_add) (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route, guint32 v4_pref_src); + gboolean (*route_add) (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route); gboolean (*route_delete) (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route); gboolean (*route_delete_default) (NMPlatform *self, int ifindex, guint32 metric); guint32 (*metric_normalize) (guint32 metric);