Commit 6e409ef9 authored by Thomas Haller's avatar Thomas Haller

policy: return best config based on the internal sorting of NMDefaultRouteManager

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's avatarThomas Haller <thaller@redhat.com>
parent f22c72d2
......@@ -790,18 +790,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);
......@@ -817,63 +814,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);
tmp = nm_active_connection_get_connection (active);
g_assert (tmp);
vpn_state = nm_vpn_connection_get_vpn_state (candidate);
if (vpn_state != NM_VPN_CONNECTION_STATE_ACTIVATED)
continue;
if (VTABLE_IS_IP4) {
NMIP4Config *vpn_ip4;
vpn_ip4 = nm_vpn_connection_get_ip4_config (candidate);
if (!vpn_ip4)
continue;
g_return_val_if_fail (NM_IS_DEFAULT_ROUTE_MANAGER (self), NULL);
if (!ignore_never_default && nm_ip4_config_get_never_default (vpn_ip4))
continue;
priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self);
entries = vtable->get_entries (priv);
config_result = vpn_ip4;
} else {
NMIP6Config *vpn_ip6;
for (i = 0; i < entries->len; i++) {
Entry *entry = g_ptr_array_index (entries, i);
vpn_ip6 = nm_vpn_connection_get_ip6_config (candidate);
if (!vpn_ip6)
continue;
if (!NM_IS_DEVICE (entry->source.pointer)) {
NMVpnConnection *vpn = NM_VPN_CONNECTION (entry->source.vpn);
if (!ignore_never_default && nm_ip6_config_get_never_default (vpn_ip6))
if (entry->never_default && !ignore_never_default)
continue;
config_result = vpn_ip6;
}
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);
if (out_vpn)
*out_vpn = candidate;
*out_vpn = vpn;
if (out_ac)
*out_ac = active;
*out_ac = NM_ACTIVE_CONNECTION (vpn);
if (out_ip_iface)
*out_ip_iface = nm_vpn_connection_get_ip_iface (candidate);
break;
}
*out_ip_iface = nm_vpn_connection_get_ip_iface (vpn);
} else {
NMDevice *device = entry->source.device;
NMActRequest *req;
/* 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
......@@ -889,6 +859,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;
......@@ -896,9 +867,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,
......@@ -906,9 +875,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,
......@@ -917,9 +884,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,
......@@ -927,9 +892,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,
......
......@@ -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,
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment