diff options
author | Thomas Haller <thaller@redhat.com> | 2014-11-04 17:28:22 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-11-07 13:44:58 +0100 |
commit | e0138b0a0a19cfdd6d469f6c2edaebc308dfdf19 (patch) | |
tree | 88dab9a54ba532cc3a654ba692965ca18fe9fc23 | |
parent | 40274aaae8ebe8fba9bfcb6d94a33b53218be4ad (diff) | |
download | NetworkManager-th/bgo735512_route_metric.tar.gz |
policy: return best config based on the internal sorting of NMDefaultRouteManagerth/bgo735512_route_metric
Now that both VPN and devices are managed (and ordered) by
NMDefaultRouteManager, refactor get_best_config() to use the
priority accordingly.
Before, we would first iterate over all VPN connections and
returning the best one. Only if no suitable VPN connection
was found, a best device would be returned.
Modify get_best_config() to treat VPN and device the same and
return the best one based on the route metric.
With this change, get_best_config() gives consistent results
together with get_best_device(). Also, you can configure
that a device gets a higher priority then a VPN.
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | src/nm-default-route-manager.c | 87 | ||||
-rw-r--r-- | src/nm-default-route-manager.h | 4 | ||||
-rw-r--r-- | src/nm-policy.c | 8 |
3 files changed, 24 insertions, 75 deletions
diff --git a/src/nm-default-route-manager.c b/src/nm-default-route-manager.c index 35cd620247..7c215ef195 100644 --- a/src/nm-default-route-manager.c +++ b/src/nm-default-route-manager.c @@ -794,18 +794,15 @@ nm_default_route_manager_ip6_get_best_device (NMDefaultRouteManager *self, const static gpointer _ipx_get_best_config (const VTableIP *vtable, NMDefaultRouteManager *self, - NMManager *manager, gboolean ignore_never_default, - NMDevice *preferred_device, const char **out_ip_iface, NMActiveConnection **out_ac, NMDevice **out_device, NMVpnConnection **out_vpn) { NMDefaultRouteManagerPrivate *priv; - const GSList *connections, *iter; - NMDevice *device; - NMActRequest *req = NULL; + GPtrArray *entries; + guint i; gpointer config_result = NULL; g_return_val_if_fail (NM_IS_DEFAULT_ROUTE_MANAGER (self), NULL); @@ -821,65 +818,36 @@ _ipx_get_best_config (const VTableIP *vtable, priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self); - /* If a VPN connection is active, it is preferred */ - connections = nm_manager_get_active_connections (manager); - for (iter = connections; iter; iter = g_slist_next (iter)) { - NMActiveConnection *active = NM_ACTIVE_CONNECTION (iter->data); - NMVpnConnection *candidate; - NMConnection *tmp; - NMVpnConnectionState vpn_state; - - if (!NM_IS_VPN_CONNECTION (active)) - continue; - - candidate = NM_VPN_CONNECTION (active); + g_return_val_if_fail (NM_IS_DEFAULT_ROUTE_MANAGER (self), NULL); - tmp = nm_active_connection_get_connection (active); - g_assert (tmp); + priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self); + entries = vtable->get_entries (priv); - vpn_state = nm_vpn_connection_get_vpn_state (candidate); - if (vpn_state != NM_VPN_CONNECTION_STATE_ACTIVATED) - continue; + for (i = 0; i < entries->len; i++) { + Entry *entry = g_ptr_array_index (entries, i); - if (VTABLE_IS_IP4) { - NMIP4Config *vpn_ip4; - NMSettingIP4Config *s_ip4; + if (!NM_IS_DEVICE (entry->source.pointer)) { + NMVpnConnection *vpn = NM_VPN_CONNECTION (entry->source.vpn); - vpn_ip4 = nm_vpn_connection_get_ip4_config (candidate); - if (!vpn_ip4) + if (entry->never_default && !ignore_never_default) continue; - if (!ignore_never_default && nm_ip4_config_get_never_default (vpn_ip4)) - continue; + if (VTABLE_IS_IP4) + config_result = nm_vpn_connection_get_ip4_config (vpn); + else + config_result = nm_vpn_connection_get_ip6_config (vpn); + g_assert (config_result); - config_result = vpn_ip4; + if (out_vpn) + *out_vpn = vpn; + if (out_ac) + *out_ac = NM_ACTIVE_CONNECTION (vpn); + if (out_ip_iface) + *out_ip_iface = nm_vpn_connection_get_ip_iface (vpn); } else { - NMIP6Config *vpn_ip6; - NMSettingIP6Config *s_ip6; - - vpn_ip6 = nm_vpn_connection_get_ip6_config (candidate); - if (!vpn_ip6) - continue; - - if (!ignore_never_default && nm_ip6_config_get_never_default (vpn_ip6)) - continue; + NMDevice *device = entry->source.device; + NMActRequest *req; - config_result = vpn_ip6; - } - - if (out_vpn) - *out_vpn = candidate; - if (out_ac) - *out_ac = active; - if (out_ip_iface) - *out_ip_iface = nm_vpn_connection_get_ip_iface (candidate); - break; - } - - /* If no VPN connections, we use the best device instead */ - if (!config_result) { - device = _ipx_get_best_device (vtable, self); - if (device) { if (VTABLE_IS_IP4) config_result = nm_device_get_ip4_config (device); else @@ -895,6 +863,7 @@ _ipx_get_best_config (const VTableIP *vtable, if (out_ip_iface) *out_ip_iface = nm_device_get_ip_iface (device); } + break; } return config_result; @@ -902,9 +871,7 @@ _ipx_get_best_config (const VTableIP *vtable, NMIP4Config * nm_default_route_manager_ip4_get_best_config (NMDefaultRouteManager *self, - NMManager *manager, gboolean ignore_never_default, - NMDevice *preferred_device, const char **out_ip_iface, NMActiveConnection **out_ac, NMDevice **out_device, @@ -912,9 +879,7 @@ nm_default_route_manager_ip4_get_best_config (NMDefaultRouteManager *self, { return _ipx_get_best_config (&vtable_ip4, self, - manager, ignore_never_default, - preferred_device, out_ip_iface, out_ac, out_device, @@ -923,9 +888,7 @@ nm_default_route_manager_ip4_get_best_config (NMDefaultRouteManager *self, NMIP6Config * nm_default_route_manager_ip6_get_best_config (NMDefaultRouteManager *self, - NMManager *manager, gboolean ignore_never_default, - NMDevice *preferred_device, const char **out_ip_iface, NMActiveConnection **out_ac, NMDevice **out_device, @@ -933,9 +896,7 @@ nm_default_route_manager_ip6_get_best_config (NMDefaultRouteManager *self, { return _ipx_get_best_config (&vtable_ip6, self, - manager, ignore_never_default, - preferred_device, out_ip_iface, out_ac, out_device, diff --git a/src/nm-default-route-manager.h b/src/nm-default-route-manager.h index 6f49d3130a..88fb59f0c9 100644 --- a/src/nm-default-route-manager.h +++ b/src/nm-default-route-manager.h @@ -61,17 +61,13 @@ NMDevice *nm_default_route_manager_ip4_get_best_device (NMDefaultRouteManager *m NMDevice *nm_default_route_manager_ip6_get_best_device (NMDefaultRouteManager *manager, const GSList *devices, gboolean fully_activated, NMDevice *preferred_device); NMIP4Config *nm_default_route_manager_ip4_get_best_config (NMDefaultRouteManager *manager, - NMManager *nm_manager, gboolean ignore_never_default, - NMDevice *preferred_device, const char **out_ip_iface, NMActiveConnection **out_ac, NMDevice **out_device, NMVpnConnection **out_vpn); NMIP6Config *nm_default_route_manager_ip6_get_best_config (NMDefaultRouteManager *manager, - NMManager *nm_manager, gboolean ignore_never_default, - NMDevice *preferred_device, const char **out_ip_iface, NMActiveConnection **out_ac, NMDevice **out_device, diff --git a/src/nm-policy.c b/src/nm-policy.c index e31ba13e11..963be3099b 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -386,12 +386,8 @@ get_best_ip4_config (NMPolicy *self, NMDevice **out_device, NMVpnConnection **out_vpn) { - NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); - return nm_default_route_manager_ip4_get_best_config (nm_default_route_manager_get (), - priv->manager, ignore_never_default, - priv->default_device4, out_ip_iface, out_ac, out_device, @@ -485,12 +481,8 @@ get_best_ip6_config (NMPolicy *self, NMDevice **out_device, NMVpnConnection **out_vpn) { - NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); - return nm_default_route_manager_ip6_get_best_config (nm_default_route_manager_get (), - priv->manager, ignore_never_default, - priv->default_device6, out_ip_iface, out_ac, out_device, |