policy: minor refactoring in get_best_ipx_device()

In get_best_ip4_device() and get_best_ip6_device(), move
conditions to check for suitable connection first.
Makes the following patch more coherent.

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller
2014-11-03 12:13:14 +01:00
parent 227aebf4b6
commit 2f90ecbfbb

View File

@@ -121,22 +121,6 @@ get_best_ip4_device (NMPolicy *self, gboolean fully_activated)
if (fully_activated && state < NM_DEVICE_STATE_SECONDARIES)
continue;
if (fully_activated) {
NMIP4Config *ip4_config;
ip4_config = nm_device_get_ip4_config (dev);
if (!ip4_config)
continue;
/* Make sure the device has a gateway */
if (!nm_ip4_config_get_gateway (ip4_config) && (devtype != NM_DEVICE_TYPE_MODEM))
continue;
/* 'never-default' devices can't ever be the default */
if (nm_ip4_config_get_never_default (ip4_config))
continue;
}
req = nm_device_get_act_request (dev);
g_assert (req);
connection = nm_act_request_get_connection (req);
@@ -154,6 +138,22 @@ get_best_ip4_device (NMPolicy *self, gboolean fully_activated)
if (nm_setting_ip_config_get_never_default (s_ip4))
continue;
if (fully_activated) {
NMIP4Config *ip4_config;
ip4_config = nm_device_get_ip4_config (dev);
if (!ip4_config)
continue;
/* Make sure the device has a gateway */
if (!nm_ip4_config_get_gateway (ip4_config) && (devtype != NM_DEVICE_TYPE_MODEM))
continue;
/* 'never-default' devices can't ever be the default */
if (nm_ip4_config_get_never_default (ip4_config))
continue;
}
prio = nm_device_get_priority (dev);
if ( prio < best_prio
|| (priv->default_device4 == dev && prio == best_prio)
@@ -205,20 +205,6 @@ get_best_ip6_device (NMPolicy *self, gboolean fully_activated)
if (fully_activated && state < NM_DEVICE_STATE_SECONDARIES)
continue;
if (fully_activated) {
NMIP6Config *ip6_config;
ip6_config = nm_device_get_ip6_config (dev);
if (!ip6_config)
continue;
if (!nm_ip6_config_get_gateway (ip6_config) && (devtype != NM_DEVICE_TYPE_MODEM))
continue;
if (nm_ip6_config_get_never_default (ip6_config))
continue;
}
req = nm_device_get_act_request (dev);
g_assert (req);
connection = nm_act_request_get_connection (req);
@@ -234,6 +220,20 @@ get_best_ip6_device (NMPolicy *self, gboolean fully_activated)
if (nm_setting_ip_config_get_never_default (s_ip6))
continue;
if (fully_activated) {
NMIP6Config *ip6_config;
ip6_config = nm_device_get_ip6_config (dev);
if (!ip6_config)
continue;
if (!nm_ip6_config_get_gateway (ip6_config) && (devtype != NM_DEVICE_TYPE_MODEM))
continue;
if (nm_ip6_config_get_never_default (ip6_config))
continue;
}
prio = nm_device_get_priority (dev);
if ( prio < best_prio
|| (priv->default_device6 == dev && prio == best_prio)