diff options
Diffstat (limited to 'src/nm-ip4-config.c')
| -rw-r--r-- | src/nm-ip4-config.c | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index 1486edcc..20532e86 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -249,7 +249,7 @@ notify_addresses (NMIP4Config *self) } NMIP4Config * -nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf) +nm_ip4_config_capture (NMPlatform *platform, int ifindex, gboolean capture_resolv_conf) { NMIP4Config *config; NMIP4ConfigPrivate *priv; @@ -259,7 +259,7 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf) gboolean old_has_gateway = FALSE; /* Slaves have no IP configuration */ - if (nm_platform_link_get_master (NM_PLATFORM_GET, ifindex) > 0) + if (nm_platform_link_get_master (platform, ifindex) > 0) return NULL; config = nm_ip4_config_new (ifindex); @@ -268,8 +268,8 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf) g_array_unref (priv->addresses); g_array_unref (priv->routes); - priv->addresses = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex); - priv->routes = nm_platform_ip4_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT | NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT); + priv->addresses = nm_platform_ip4_address_get_all (platform, ifindex); + priv->routes = nm_platform_ip4_route_get_all (platform, ifindex, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT | NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT); /* Extract gateway from default route */ old_gateway = priv->gateway; @@ -331,7 +331,7 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf) } gboolean -nm_ip4_config_commit (const NMIP4Config *config, int ifindex, gboolean routes_full_sync, gint64 default_route_metric) +nm_ip4_config_commit (const NMIP4Config *config, NMPlatform *platform, NMRouteManager *route_manager, int ifindex, gboolean routes_full_sync, gint64 default_route_metric) { const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); gs_unref_ptrarray GPtrArray *added_addresses = NULL; @@ -340,7 +340,7 @@ nm_ip4_config_commit (const NMIP4Config *config, int ifindex, gboolean routes_fu g_return_val_if_fail (config != NULL, FALSE); /* Addresses */ - nm_platform_ip4_address_sync (NM_PLATFORM_GET, ifindex, priv->addresses, + nm_platform_ip4_address_sync (platform, ifindex, priv->addresses, default_route_metric >= 0 ? &added_addresses : NULL); /* Routes */ @@ -401,9 +401,9 @@ nm_ip4_config_commit (const NMIP4Config *config, int ifindex, gboolean routes_fu g_array_append_vals (routes, route, 1); } - nm_route_manager_ip4_route_register_device_route_purge_list (nm_route_manager_get (), device_route_purge_list); + nm_route_manager_ip4_route_register_device_route_purge_list (route_manager, device_route_purge_list); - success = nm_route_manager_ip4_route_sync (nm_route_manager_get (), ifindex, routes, default_route_metric < 0, routes_full_sync); + success = nm_route_manager_ip4_route_sync (route_manager, ifindex, routes, default_route_metric < 0, routes_full_sync); g_array_unref (routes); if (!success) return FALSE; @@ -412,6 +412,38 @@ nm_ip4_config_commit (const NMIP4Config *config, int ifindex, gboolean routes_fu return TRUE; } +static void +merge_route_attributes (NMIPRoute *s_route, NMPlatformIP4Route *r) +{ + GVariant *variant; + in_addr_t addr; + +#define GET_ATTR(name, field, variant_type, type) \ + variant = nm_ip_route_get_attribute (s_route, name); \ + if (variant && g_variant_is_of_type (variant, G_VARIANT_TYPE_ ## variant_type)) \ + r->field = g_variant_get_ ## type (variant); + + GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_TOS, tos, BYTE, byte); + GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_WINDOW, window, UINT32, uint32); + GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_CWND, cwnd, UINT32, uint32); + GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_INITCWND, initcwnd, UINT32, uint32); + GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_INITRWND, initrwnd, UINT32, uint32); + GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_MTU, mtu, UINT32, uint32); + GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_LOCK_WINDOW, lock_window, BOOLEAN, boolean); + GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_LOCK_CWND, lock_cwnd, BOOLEAN, boolean); + GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_LOCK_INITCWND, lock_initcwnd, BOOLEAN, boolean); + GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_LOCK_INITRWND, lock_initrwnd, BOOLEAN, boolean); + GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_LOCK_MTU, lock_mtu, BOOLEAN, boolean); + + if ( (variant = nm_ip_route_get_attribute (s_route, NM_IP_ROUTE_ATTRIBUTE_SRC)) + && g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING)) { + if (inet_pton (AF_INET, g_variant_get_string (variant, NULL), &addr) == 1) + r->pref_src = addr; + } + +#undef GET_ATTR +} + void nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, guint32 default_route_metric) { @@ -492,6 +524,7 @@ nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, gu route.metric = nm_ip_route_get_metric (s_route); route.rt_source = NM_IP_CONFIG_SOURCE_USER; + merge_route_attributes (s_route, &route); nm_ip4_config_add_route (config, &route); } @@ -1822,7 +1855,7 @@ nm_ip4_config_add_search (NMIP4Config *config, const char *new) return; } - if (_nm_utils_strv_find_first ((char **) priv->searches->pdata, + if (nm_utils_strv_find_first ((char **) priv->searches->pdata, priv->searches->len, search) >= 0) { g_free (search); return; |