mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-03 19:50:14 +01:00
core: inline _add_local_route_from_addr[46] helper function
In this case, the functions are only called once. Having a helper function that has no clear, unique purpose does not necessarily make the code simpler. Also, NMIP[46]Config is going to change completely. It will thereby move this code (and change it). Doing that is simpler, if we see all the relevant parts in one place.
This commit is contained in:
parent
8225785956
commit
ba9c150286
2 changed files with 42 additions and 68 deletions
|
|
@ -614,30 +614,6 @@ nm_ip4_config_update_routes_metric (NMIP4Config *self, gint64 metric)
|
|||
g_object_thaw_notify (G_OBJECT (self));
|
||||
}
|
||||
|
||||
static void
|
||||
_add_local_route_from_addr4 (NMIP4Config * self,
|
||||
const NMPlatformIP4Address *addr,
|
||||
int ifindex,
|
||||
guint32 route_table,
|
||||
gboolean is_vrf)
|
||||
{
|
||||
nm_auto_nmpobj NMPObject *r = NULL;
|
||||
NMPlatformIP4Route *route;
|
||||
|
||||
r = nmp_object_new (NMP_OBJECT_TYPE_IP4_ROUTE, NULL);
|
||||
route = NMP_OBJECT_CAST_IP4_ROUTE (r);
|
||||
route->ifindex = ifindex;
|
||||
route->rt_source = NM_IP_CONFIG_SOURCE_KERNEL;
|
||||
route->network = addr->address;
|
||||
route->plen = 32;
|
||||
route->pref_src = addr->address;
|
||||
route->type_coerced = nm_platform_route_type_coerce (RTN_LOCAL);
|
||||
route->scope_inv = nm_platform_route_scope_inv (RT_SCOPE_HOST);
|
||||
route->table_coerced = nm_platform_route_table_coerce (is_vrf ? route_table : RT_TABLE_LOCAL);
|
||||
|
||||
_add_route (self, r, NULL, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
nm_ip4_config_add_dependent_routes (NMIP4Config *self,
|
||||
guint32 route_table,
|
||||
|
|
@ -675,7 +651,19 @@ nm_ip4_config_add_dependent_routes (NMIP4Config *self,
|
|||
if (my_addr->external)
|
||||
continue;
|
||||
|
||||
_add_local_route_from_addr4 (self, my_addr, ifindex, route_table, is_vrf);
|
||||
/* Pre-generate local route added by kernel */
|
||||
r = nmp_object_new (NMP_OBJECT_TYPE_IP4_ROUTE, NULL);
|
||||
route = NMP_OBJECT_CAST_IP4_ROUTE (r);
|
||||
route->ifindex = ifindex;
|
||||
route->rt_source = NM_IP_CONFIG_SOURCE_KERNEL;
|
||||
route->network = my_addr->address;
|
||||
route->plen = 32;
|
||||
route->pref_src = my_addr->address;
|
||||
route->type_coerced = nm_platform_route_type_coerce (RTN_LOCAL);
|
||||
route->scope_inv = nm_platform_route_scope_inv (RT_SCOPE_HOST);
|
||||
route->table_coerced = nm_platform_route_table_coerce (is_vrf ? route_table : RT_TABLE_LOCAL);
|
||||
_add_route (self, r, NULL, NULL);
|
||||
nm_clear_pointer (&r, nmp_object_unref);
|
||||
|
||||
if (nm_utils_ip4_address_is_zeronet (network)) {
|
||||
/* Kernel doesn't add device-routes for destinations that
|
||||
|
|
|
|||
|
|
@ -364,46 +364,6 @@ nm_ip6_config_update_routes_metric (NMIP6Config *self, gint64 metric)
|
|||
g_object_thaw_notify (G_OBJECT (self));
|
||||
}
|
||||
|
||||
static void
|
||||
_add_multicast_route6 (NMIP6Config *self, int ifindex)
|
||||
{
|
||||
nm_auto_nmpobj NMPObject *r = NULL;
|
||||
NMPlatformIP6Route *route;
|
||||
|
||||
r = nmp_object_new (NMP_OBJECT_TYPE_IP6_ROUTE, NULL);
|
||||
route = NMP_OBJECT_CAST_IP6_ROUTE (r);
|
||||
route->ifindex = ifindex;
|
||||
route->network.s6_addr[0] = 0xffu;
|
||||
route->plen = 8;
|
||||
route->table_coerced = nm_platform_route_table_coerce (RT_TABLE_LOCAL);
|
||||
route->type_coerced = nm_platform_route_type_coerce (RTN_UNICAST);
|
||||
route->metric = 256;
|
||||
|
||||
_add_route (self, r, NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
_add_local_route_from_addr6 (NMIP6Config * self,
|
||||
const NMPlatformIP6Address *addr,
|
||||
int ifindex,
|
||||
guint32 route_table,
|
||||
gboolean is_vrf)
|
||||
{
|
||||
nm_auto_nmpobj NMPObject *r = NULL;
|
||||
NMPlatformIP6Route * route;
|
||||
|
||||
r = nmp_object_new (NMP_OBJECT_TYPE_IP6_ROUTE, NULL);
|
||||
route = NMP_OBJECT_CAST_IP6_ROUTE (r);
|
||||
route->ifindex = ifindex;
|
||||
route->network = addr->address;
|
||||
route->plen = 128;
|
||||
route->type_coerced = nm_platform_route_type_coerce (RTN_LOCAL);
|
||||
route->metric = 0;
|
||||
route->table_coerced = nm_platform_route_table_coerce (is_vrf ? route_table : RT_TABLE_LOCAL);
|
||||
|
||||
_add_route (self, r, NULL, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
nm_ip6_config_add_dependent_routes (NMIP6Config *self,
|
||||
guint32 route_table,
|
||||
|
|
@ -426,7 +386,21 @@ nm_ip6_config_add_dependent_routes (NMIP6Config *self,
|
|||
* For manually added IPv6 routes, add the device routes explicitly. */
|
||||
|
||||
/* Pre-generate multicast route */
|
||||
_add_multicast_route6 (self, ifindex);
|
||||
{
|
||||
nm_auto_nmpobj NMPObject *r = NULL;
|
||||
NMPlatformIP6Route *route;
|
||||
|
||||
r = nmp_object_new (NMP_OBJECT_TYPE_IP6_ROUTE, NULL);
|
||||
route = NMP_OBJECT_CAST_IP6_ROUTE (r);
|
||||
route->ifindex = ifindex;
|
||||
route->network.s6_addr[0] = 0xffu;
|
||||
route->plen = 8;
|
||||
route->table_coerced = nm_platform_route_table_coerce (RT_TABLE_LOCAL);
|
||||
route->type_coerced = nm_platform_route_type_coerce (RTN_UNICAST);
|
||||
route->metric = 256;
|
||||
|
||||
_add_route (self, r, NULL, NULL);
|
||||
}
|
||||
|
||||
nm_ip_config_iter_ip6_address_for_each (&iter, self, &my_addr) {
|
||||
NMPlatformIP6Route *route;
|
||||
|
|
@ -436,8 +410,20 @@ nm_ip6_config_add_dependent_routes (NMIP6Config *self,
|
|||
if (my_addr->external)
|
||||
continue;
|
||||
|
||||
/* Pre-generate local route added by kernel */
|
||||
_add_local_route_from_addr6 (self, my_addr, ifindex, route_table, is_vrf);
|
||||
{
|
||||
nm_auto_nmpobj NMPObject *r = NULL;
|
||||
|
||||
/* Pre-generate local route added by kernel */
|
||||
r = nmp_object_new (NMP_OBJECT_TYPE_IP6_ROUTE, NULL);
|
||||
route = NMP_OBJECT_CAST_IP6_ROUTE (r);
|
||||
route->ifindex = ifindex;
|
||||
route->network = my_addr->address;
|
||||
route->plen = 128;
|
||||
route->type_coerced = nm_platform_route_type_coerce (RTN_LOCAL);
|
||||
route->metric = 0;
|
||||
route->table_coerced = nm_platform_route_table_coerce (is_vrf ? route_table : RT_TABLE_LOCAL);
|
||||
_add_route (self, r, NULL, NULL);
|
||||
}
|
||||
|
||||
if (NM_FLAGS_HAS (my_addr->n_ifa_flags, IFA_F_NOPREFIXROUTE))
|
||||
continue;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue