diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2018-06-28 17:16:15 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2018-07-09 13:34:29 +0200 |
commit | e1888ad4e5044f54dd1476f2a41cc8b7e72ce371 (patch) | |
tree | 05f8634d608171d8db843b67147944f95e935ac9 | |
parent | e205664ba8c25939f1678d1b078a67989c180046 (diff) | |
download | NetworkManager-e1888ad4e5044f54dd1476f2a41cc8b7e72ce371.tar.gz |
policy: choose best VPN based on metrics
As the FIXME suggests, select the VPN with best metric to determine
the best IP config.
-rw-r--r-- | src/nm-policy.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/nm-policy.c b/src/nm-policy.c index 125f27041a..0f10c5e308 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -853,15 +853,19 @@ get_best_ip_config (NMPolicy *self, { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); NMDevice *device; - gpointer conf; + gpointer conf, best_conf = NULL; const CList *tmp_list; NMActiveConnection *ac; + guint64 best_metric = G_MAXUINT64; + NMVpnConnection *best_vpn = NULL; nm_assert (NM_IN_SET (addr_family, AF_INET, AF_INET6)); nm_manager_for_each_active_connection (priv->manager, ac, tmp_list) { NMVpnConnection *candidate; NMVpnConnectionState vpn_state; + const NMPObject *obj; + guint32 metric; if (!NM_IS_VPN_CONNECTION (ac)) continue; @@ -879,21 +883,27 @@ get_best_ip_config (NMPolicy *self, if (!conf) continue; - if (addr_family == AF_INET) { - if (!nm_ip4_config_best_default_route_get (conf)) - continue; - } else { - if (!nm_ip6_config_best_default_route_get (conf)) - continue; + if (addr_family == AF_INET) + obj = nm_ip4_config_best_default_route_get (conf); + else + obj = nm_ip6_config_best_default_route_get (conf); + if (!obj) + continue; + + metric = NMP_OBJECT_CAST_IPX_ROUTE (obj)->rx.metric; + if (metric <= best_metric) { + best_metric = metric; + best_conf = conf; + best_vpn = candidate; } + } - /* FIXME: in case of multiple VPN candidates, choose the one with the - * best metric. */ + if (best_metric != G_MAXUINT64) { NM_SET_OUT (out_device, NULL); - NM_SET_OUT (out_vpn, candidate); - NM_SET_OUT (out_ac, ac); - NM_SET_OUT (out_ip_iface, nm_vpn_connection_get_ip_iface (candidate, TRUE)); - return conf; + NM_SET_OUT (out_vpn, best_vpn); + NM_SET_OUT (out_ac, NM_ACTIVE_CONNECTION (best_vpn)); + NM_SET_OUT (out_ip_iface, nm_vpn_connection_get_ip_iface (best_vpn, TRUE)); + return best_conf; } device = get_best_ip_device (self, addr_family, TRUE); |