diff options
| author | Sjoerd Simons <sjoerd@luon.net> | 2014-04-26 20:55:09 +0200 |
|---|---|---|
| committer | Sjoerd Simons <sjoerd@luon.net> | 2014-04-26 20:55:09 +0200 |
| commit | 59c3714a494c3b3765657c0551ad82842d98a7d2 (patch) | |
| tree | e4dcdf9791fc40581f02bfaf870c30b102b3133a /src/nm-policy.c | |
| parent | a4256940da049f91bbbea5e53e469a59ea9c10f7 (diff) | |
Imported Upstream version 0.9.8.10 upstream/0.9.8.10
Diffstat (limited to 'src/nm-policy.c')
| -rw-r--r-- | src/nm-policy.c | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/src/nm-policy.c b/src/nm-policy.c index e8e7c606..f95caf93 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -97,16 +97,14 @@ static void schedule_activate_all (NMPolicy *policy); static NMDevice * -get_best_ip4_device (NMManager *manager, gboolean fully_activated) +get_best_ip4_device (NMPolicy *self, gboolean fully_activated) { + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); GSList *devices, *iter; NMDevice *best = NULL; int best_prio = G_MAXINT; - g_return_val_if_fail (manager != NULL, NULL); - g_return_val_if_fail (NM_IS_MANAGER (manager), NULL); - - devices = nm_manager_get_devices (manager); + devices = nm_manager_get_devices (priv->manager); for (iter = devices; iter; iter = g_slist_next (iter)) { NMDevice *dev = NM_DEVICE (iter->data); NMDeviceType devtype = nm_device_get_device_type (dev); @@ -167,7 +165,9 @@ get_best_ip4_device (NMManager *manager, gboolean fully_activated) } prio = nm_device_get_priority (dev); - if (prio > 0 && prio < best_prio) { + if ( prio < best_prio + || (priv->default_device4 == dev && prio == best_prio) + || !best) { best = dev; best_prio = prio; } @@ -191,16 +191,14 @@ get_best_ip4_device (NMManager *manager, gboolean fully_activated) } static NMDevice * -get_best_ip6_device (NMManager *manager, gboolean fully_activated) +get_best_ip6_device (NMPolicy *self, gboolean fully_activated) { + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); GSList *devices, *iter; NMDevice *best = NULL; int best_prio = G_MAXINT; - g_return_val_if_fail (manager != NULL, NULL); - g_return_val_if_fail (NM_IS_MANAGER (manager), NULL); - - devices = nm_manager_get_devices (manager); + devices = nm_manager_get_devices (priv->manager); for (iter = devices; iter; iter = g_slist_next (iter)) { NMDevice *dev = NM_DEVICE (iter->data); NMDeviceType devtype = nm_device_get_device_type (dev); @@ -257,7 +255,9 @@ get_best_ip6_device (NMManager *manager, gboolean fully_activated) } prio = nm_device_get_priority (dev); - if (prio > 0 && prio < best_prio) { + if ( prio < best_prio + || (priv->default_device6 == dev && prio == best_prio) + || !best) { best = dev; best_prio = prio; } @@ -383,9 +383,9 @@ update_system_hostname (NMPolicy *policy, NMDevice *best4, NMDevice *best6) /* Try automatically determined hostname from the best device's IP config */ if (!best4) - best4 = get_best_ip4_device (priv->manager, TRUE); + best4 = get_best_ip4_device (policy, TRUE); if (!best6) - best6 = get_best_ip6_device (priv->manager, TRUE); + best6 = get_best_ip6_device (policy, TRUE); if (!best4 && !best6) { /* No best device; fall back to original hostname or if there wasn't @@ -582,7 +582,7 @@ get_best_ip4_config (NMPolicy *policy, /* If no VPN connections, we use the best device instead */ if (!ip4_config) { - device = get_best_ip4_device (priv->manager, TRUE); + device = get_best_ip4_device (policy, TRUE); if (device) { ip4_config = nm_device_get_ip4_config (device); g_assert (ip4_config); @@ -627,7 +627,7 @@ static void update_ip4_routing (NMPolicy *policy, gboolean force_update) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy); - NMDevice *best = NULL, *parent; + NMDevice *best = NULL, *parent, *default_device; NMConnection *connection = NULL; NMVPNConnection *vpn = NULL; NMActiveConnection *best_ac = NULL; @@ -680,15 +680,20 @@ update_ip4_routing (NMPolicy *policy, gboolean force_update) nm_ip4_config_get_mss (ip4_config), nm_device_get_ip_ifindex (parent), parent_mss); + default_device = parent; } else { nm_system_replace_default_ip4_route (ip_ifindex, gw_addr, nm_ip4_config_get_mss (ip4_config)); + default_device = best; } update_default_ac (policy, best_ac, nm_active_connection_set_default); - priv->default_device4 = best; + if (default_device == priv->default_device4) + return; + + priv->default_device4 = default_device; connection = nm_active_connection_get_connection (best_ac); nm_log_info (LOGD_CORE, "Policy set '%s' (%s) as default for IPv4 routing and DNS.", nm_connection_get_id (connection), ip_iface); @@ -761,7 +766,7 @@ get_best_ip6_config (NMPolicy *policy, /* If no VPN connections, we use the best device instead */ if (!ip6_config) { - device = get_best_ip6_device (priv->manager, TRUE); + device = get_best_ip6_device (policy, TRUE); if (device) { req = nm_device_get_act_request (device); g_assert (req); @@ -806,7 +811,7 @@ static void update_ip6_routing (NMPolicy *policy, gboolean force_update) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy); - NMDevice *best = NULL, *parent; + NMDevice *best = NULL, *parent, *default_device6; NMConnection *connection = NULL; NMVPNConnection *vpn = NULL; NMActiveConnection *best_ac = NULL; @@ -868,16 +873,21 @@ update_ip6_routing (NMPolicy *policy, gboolean force_update) nm_ip6_config_get_mss (ip6_config), nm_device_get_ip_ifindex (parent), parent_mss); + default_device6 = parent; } else { if (gw_addr) nm_system_replace_default_ip6_route (ip_ifindex, gw_addr); else nm_log_dbg (LOGD_IP6, "missing default IPv6 gateway"); + default_device6 = best; } update_default_ac (policy, best_ac, nm_active_connection_set_default6); - priv->default_device6 = best; + if (default_device6 == priv->default_device6) + return; + + priv->default_device6 = default_device6; connection = nm_active_connection_get_connection (best_ac); nm_log_info (LOGD_CORE, "Policy set '%s' (%s) as default for IPv6 routing and DNS.", nm_connection_get_id (connection), ip_iface); @@ -913,8 +923,8 @@ check_activating_devices (NMPolicy *policy) GObject *object = G_OBJECT (policy); NMDevice *best4, *best6 = NULL; - best4 = get_best_ip4_device (priv->manager, FALSE); - best6 = get_best_ip6_device (priv->manager, FALSE); + best4 = get_best_ip4_device (policy, FALSE); + best6 = get_best_ip6_device (policy, FALSE); g_object_freeze_notify (object); |