diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2024-01-16 17:49:57 +0100 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2024-01-29 08:54:08 +0100 |
commit | c415eaca762867d948cc7d582988a791a8732736 (patch) | |
tree | 858b94c656eaa000a8383eb3b95ab57e6a126184 | |
parent | 23f45d0e180c110c4b2e6fe21f053014332cee79 (diff) |
vpn: accept pref-src for IPv6 routes returned by plugins
As done for IPv4 in commit 3b145a33b748 ('vpn-connections: allow the
plugin to specify route preferred src'), allow VPN plugins to return a
preferred source address for routes. Still accept the old format.
-rw-r--r-- | src/core/vpn/nm-vpn-connection.c | 92 |
1 files changed, 61 insertions, 31 deletions
diff --git a/src/core/vpn/nm-vpn-connection.c b/src/core/vpn/nm-vpn-connection.c index dddc6e0b3d..de0c9f7104 100644 --- a/src/core/vpn/nm-vpn-connection.c +++ b/src/core/vpn/nm-vpn-connection.c @@ -2147,50 +2147,80 @@ _dbus_signal_ip_config_cb(NMVpnConnection *self, int addr_family, GVariant *dict } else { _nm_unused nm_auto_free_variant_iter GVariantIter *var_iter_ref_owner = NULL; NMPlatformIPXRoute route = {}; - GVariant *next_hop; - GVariant *dest; guint32 prefix; guint32 metric; + NMOptionBool new_signature = NM_OPTION_BOOL_DEFAULT; /* IPv6 and no "preserve-routes" */ - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP6_CONFIG_ROUTES, "a(ayuayu)", &var_iter)) { - var_iter_ref_owner = var_iter; - while ( - g_variant_iter_next(var_iter, "(@ayu@ayu)", &dest, &prefix, &next_hop, &metric)) { - _nm_unused gs_unref_variant GVariant *next_hop_ref_owner = next_hop; - _nm_unused gs_unref_variant GVariant *dest_ref_owner = dest; + if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP6_CONFIG_ROUTES, "a(ayuayu)", &var_iter)) + new_signature = FALSE; + else if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP6_CONFIG_ROUTES, "a(ayuayuay)", &var_iter)) + new_signature = TRUE; + else + var_iter = NULL; + + var_iter_ref_owner = var_iter; + + while (TRUE) { + gs_unref_variant GVariant *next_hop = NULL; + gs_unref_variant GVariant *dest = NULL; + gs_unref_variant GVariant *pref_src = NULL; + + if (new_signature == NM_OPTION_BOOL_DEFAULT) { + break; + } else if (new_signature) { + if (!g_variant_iter_next(var_iter, + "(@ayu@ayu@ay)", + &dest, + &prefix, + &next_hop, + &metric, + &pref_src)) + break; + } else { + if (!g_variant_iter_next(var_iter, + "(@ayu@ayu)", + &dest, + &prefix, + &next_hop, + &metric)) + break; + } - if (prefix > 128) - continue; + if (prefix > 128) + continue; - route.r6 = (NMPlatformIP6Route){ - .plen = prefix, - .table_any = TRUE, - .metric_any = TRUE, - .rt_source = NM_IP_CONFIG_SOURCE_VPN, - }; + route.r6 = (NMPlatformIP6Route){ + .plen = prefix, + .table_any = TRUE, + .metric_any = TRUE, + .rt_source = NM_IP_CONFIG_SOURCE_VPN, + }; - if (!nm_ip_addr_set_from_variant(AF_INET6, &route.r6.network, dest, NULL)) - continue; + if (!nm_ip_addr_set_from_variant(AF_INET6, &route.r6.network, dest, NULL)) + continue; - nm_ip_addr_set_from_variant(AF_INET6, &route.r6.gateway, next_hop, NULL); + if (pref_src + && !nm_ip_addr_set_from_variant(AF_INET6, &route.r6.pref_src, pref_src, NULL)) + continue; - nm_ip6_addr_clear_host_address(&route.r6.network, &route.r6.network, route.r6.plen); + nm_ip_addr_set_from_variant(AF_INET6, &route.r6.gateway, next_hop, NULL); - if (!IN6_IS_ADDR_UNSPECIFIED(&priv->ip_data_6.gw_external.addr6) - && IN6_ARE_ADDR_EQUAL(&route.r6.network, &priv->ip_data_6.gw_external.addr6) - && route.r6.plen == 128) { - /* Ignore host routes to the VPN gateway since NM adds one itself. - * Since NM knows more about the routing situation than the VPN - * server, we want to use the NM created route instead of whatever - * the server provides. - */ - continue; - } + nm_ip6_addr_clear_host_address(&route.r6.network, &route.r6.network, route.r6.plen); - nm_l3_config_data_add_route_6(l3cd, &route.r6); + if (!IN6_IS_ADDR_UNSPECIFIED(&priv->ip_data_6.gw_external.addr6) + && IN6_ARE_ADDR_EQUAL(&route.r6.network, &priv->ip_data_6.gw_external.addr6) + && route.r6.plen == 128) { + /* Ignore host routes to the VPN gateway since NM adds one itself. + * Since NM knows more about the routing situation than the VPN + * server, we want to use the NM created route instead of whatever + * the server provides. + */ + continue; } + + nm_l3_config_data_add_route_6(l3cd, &route.r6); } } |