summaryrefslogtreecommitdiff
path: root/src/nm-ip4-config.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-11-07 19:49:39 +0100
committerThomas Haller <thaller@redhat.com>2017-11-13 11:35:44 +0100
commit433d2f8659e31719fe13f16cc48b404d926f6ae3 (patch)
tree47e8246bf7ee7f1c058cd216f803e913f19b206b /src/nm-ip4-config.c
parenta9d1f5e543bba46a5a97a2e440d607550a54a283 (diff)
downloadNetworkManager-433d2f8659e31719fe13f16cc48b404d926f6ae3.tar.gz
core: merge IPv4 and IPv6 version of _nm_ip_config_merge_route_attributes()
Diffstat (limited to 'src/nm-ip4-config.c')
-rw-r--r--src/nm-ip4-config.c102
1 files changed, 70 insertions, 32 deletions
diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c
index 06137764f5..d63b3103be 100644
--- a/src/nm-ip4-config.c
+++ b/src/nm-ip4-config.c
@@ -806,44 +806,79 @@ nm_ip4_config_commit (const NMIP4Config *self,
return success;
}
-static void
-merge_route_attributes (NMIPRoute *s_route,
- NMPlatformIP4Route *r,
- guint32 route_table)
+void
+_nm_ip_config_merge_route_attributes (int addr_family,
+ NMIPRoute *s_route,
+ NMPlatformIPRoute *r,
+ guint32 route_table)
{
GVariant *variant;
- guint32 u32;
- 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);
-
- variant = nm_ip_route_get_attribute (s_route, NM_IP_ROUTE_ATTRIBUTE_TABLE);
- u32 = variant && g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT32)
- ? g_variant_get_uint32 (variant)
- : 0;
- r->table_coerced = nm_platform_route_table_coerce (u32 ?: (route_table ?: RT_TABLE_MAIN));
-
- 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);
+ guint32 table;
+ NMIPAddr addr;
+ NMPlatformIP4Route *r4 = (NMPlatformIP4Route *) r;
+ NMPlatformIP6Route *r6 = (NMPlatformIP6Route *) r;
+
+ nm_assert (s_route);
+ nm_assert_addr_family (addr_family);
+ nm_assert (r);
+
+#define GET_ATTR(name, dst, variant_type, type, dflt) \
+ G_STMT_START { \
+ GVariant *_variant = nm_ip_route_get_attribute (s_route, ""name""); \
+ \
+ if ( _variant \
+ && g_variant_is_of_type (_variant, G_VARIANT_TYPE_ ## variant_type)) \
+ (dst) = g_variant_get_ ## type (_variant); \
+ else \
+ (dst) = (dflt); \
+ } G_STMT_END
+
+ GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_TABLE, table, UINT32, uint32, 0);
+ r->table_coerced = nm_platform_route_table_coerce (table ?: (route_table ?: RT_TABLE_MAIN));
+
+ if (addr_family == AF_INET)
+ GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_TOS, r4->tos, BYTE, byte, 0);
+
+ GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_WINDOW, r->window, UINT32, uint32, 0);
+ GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_CWND, r->cwnd, UINT32, uint32, 0);
+ GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_INITCWND, r->initcwnd, UINT32, uint32, 0);
+ GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_INITRWND, r->initrwnd, UINT32, uint32, 0);
+ GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_MTU, r->mtu, UINT32, uint32, 0);
+ GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_LOCK_WINDOW, r->lock_window, BOOLEAN, boolean, FALSE);
+ GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_LOCK_CWND, r->lock_cwnd, BOOLEAN, boolean, FALSE);
+ GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_LOCK_INITCWND, r->lock_initcwnd, BOOLEAN, boolean, FALSE);
+ GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_LOCK_INITRWND, r->lock_initrwnd, BOOLEAN, boolean, FALSE);
+ GET_ATTR (NM_IP_ROUTE_ATTRIBUTE_LOCK_MTU, r->lock_mtu, BOOLEAN, boolean, FALSE);
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;
+ if (inet_pton (addr_family, g_variant_get_string (variant, NULL), &addr) == 1) {
+ if (addr_family == AF_INET)
+ r4->pref_src = addr.addr4;
+ else
+ r6->pref_src = addr.addr6;
+ }
}
+ if ( addr_family == AF_INET6
+ && (variant = nm_ip_route_get_attribute (s_route, NM_IP_ROUTE_ATTRIBUTE_FROM))
+ && g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING)) {
+ gs_free char *string = NULL;
+ guint8 plen = 128;
+ char *sep;
+
+ string = g_variant_dup_string (variant, NULL);
+ sep = strchr (string, '/');
+ if (sep) {
+ *sep = 0;
+ plen = _nm_utils_ascii_str_to_int64 (sep + 1, 10, 1, 128, 255);
+ }
+ if ( plen <= 128
+ && inet_pton (AF_INET6, string, &addr) == 1) {
+ r6->src = addr.addr6;
+ r6->src_plen = plen;
+ }
+ }
#undef GET_ATTR
}
@@ -939,7 +974,10 @@ nm_ip4_config_merge_setting (NMIP4Config *self,
route.network = nm_utils_ip4_address_clear_host_address (route.network, route.plen);
- merge_route_attributes (s_route, &route, route_table);
+ _nm_ip_config_merge_route_attributes (AF_INET,
+ s_route,
+ NM_PLATFORM_IP_ROUTE_CAST (&route),
+ route_table);
_add_route (self, NULL, &route, NULL);
}