summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libnm-core/nm-setting-ip-config.c11
-rw-r--r--libnm-core/nm-utils.c3
-rw-r--r--src/devices/nm-device.c76
-rw-r--r--src/nm-default-route-manager.c4
-rw-r--r--src/nm-ip4-config.c67
-rw-r--r--src/nm-ip4-config.h2
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c2
7 files changed, 110 insertions, 55 deletions
diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c
index 949a9e3d08..e2e3450a26 100644
--- a/libnm-core/nm-setting-ip-config.c
+++ b/libnm-core/nm-setting-ip-config.c
@@ -71,10 +71,8 @@ canonicalize_ip (int family, const char *ip, gboolean null_any)
char addr_str[NM_UTILS_INET_ADDRSTRLEN];
int ret;
- if (!ip) {
- g_return_val_if_fail (null_any == TRUE, NULL);
+ if (!ip)
return NULL;
- }
ret = inet_pton (family, ip, addr_bytes);
g_return_val_if_fail (ret == 1, NULL);
@@ -92,6 +90,11 @@ canonicalize_ip (int family, const char *ip, gboolean null_any)
static gboolean
valid_ip (int family, const char *ip, GError **error)
{
+ if (!ip) {
+ g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
+ family == AF_INET ? _("Missing IPv4 address") : _("Missing IPv6 address'"));
+ return FALSE;
+ }
if (!nm_utils_ipaddr_valid (family, ip)) {
g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
family == AF_INET ? _("Invalid IPv4 address '%s'") : _("Invalid IPv6 address '%s'"),
@@ -2283,7 +2286,7 @@ set_property (GObject *object, guint prop_id,
gateway = g_value_get_string (value);
g_return_if_fail (!gateway || nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), gateway));
g_free (priv->gateway);
- priv->gateway = canonicalize_ip (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), gateway, TRUE);
+ priv->gateway = canonicalize_ip (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), gateway, FALSE);
break;
case PROP_ROUTES:
g_ptr_array_unref (priv->routes);
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c
index 478e6806db..66878e8cc0 100644
--- a/libnm-core/nm-utils.c
+++ b/libnm-core/nm-utils.c
@@ -3353,6 +3353,9 @@ nm_utils_ipaddr_valid (int family, const char *ip)
g_return_val_if_fail (family == AF_INET || family == AF_INET6 || family == AF_UNSPEC, FALSE);
+ if (!ip)
+ return FALSE;
+
if (family == AF_UNSPEC)
family = strchr (ip, ':') ? AF_INET6 : AF_INET;
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 046152c917..985b0c65f6 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -274,14 +274,15 @@ typedef struct {
struct {
gboolean v4_has;
gboolean v4_is_assumed;
- gboolean v4_configure_first_time;
NMPlatformIP4Route v4;
gboolean v6_has;
gboolean v6_is_assumed;
- gboolean v6_configure_first_time;
NMPlatformIP6Route v6;
} default_route;
+ gboolean v4_commit_first_time;
+ gboolean v6_commit_first_time;
+
/* DHCPv4 tracking */
NMDhcpClient * dhcp4_client;
gulong dhcp4_state_sigid;
@@ -3315,21 +3316,26 @@ ip4_config_merge_and_apply (NMDevice *self,
priv->default_route.v4_has = FALSE;
priv->default_route.v4_is_assumed = TRUE;
- routes_full_sync = commit
- && priv->default_route.v4_configure_first_time
- && !nm_device_uses_assumed_connection (self);
-
if (!commit) {
/* during a non-commit event, we always pickup whatever is configured. */
goto END_ADD_DEFAULT_ROUTE;
}
+ if (nm_device_uses_generated_assumed_connection (self)) {
+ /* a generate-assumed-connection always detects the default route from platform */
+ goto END_ADD_DEFAULT_ROUTE;
+ }
+
+ /* At this point, we treat assumed and non-assumed connections alike.
+ * For assumed connections we do that because we still manage RA and DHCP
+ * leases for them, so we must extend/update the default route on commits.
+ */
+
connection_has_default_route
= nm_default_route_manager_ip4_connection_has_default_route (nm_default_route_manager_get (),
connection, &connection_is_never_default);
- if ( !priv->default_route.v4_configure_first_time
- && !nm_device_uses_assumed_connection (self)
+ if ( !priv->v4_commit_first_time
&& connection_is_never_default) {
/* If the connection is explicitly configured as never-default, we enforce the (absence of the)
* default-route only once. That allows the user to configure a connection as never-default,
@@ -3337,14 +3343,8 @@ ip4_config_merge_and_apply (NMDevice *self,
goto END_ADD_DEFAULT_ROUTE;
}
- /* At this point, we treat assumed and non-assumed connections alike.
- * For assumed connections we do that because we still manage RA and DHCP
- * leases for them, so we must extend/update the default route on commits.
- */
-
/* we are about to commit (for a non-assumed connection). Enforce whatever we have
* configured. */
- priv->default_route.v4_configure_first_time = FALSE;
priv->default_route.v4_is_assumed = FALSE;
if (!connection_has_default_route)
@@ -3356,7 +3356,7 @@ ip4_config_merge_and_apply (NMDevice *self,
}
gateway = nm_ip4_config_get_gateway (composite);
- if ( !gateway
+ if ( !nm_ip4_config_has_gateway (composite)
&& nm_device_get_device_type (self) != NM_DEVICE_TYPE_MODEM)
goto END_ADD_DEFAULT_ROUTE;
@@ -3398,8 +3398,15 @@ END_ADD_DEFAULT_ROUTE:
NM_DEVICE_GET_CLASS (self)->ip4_config_pre_commit (self, composite);
}
+ routes_full_sync = commit
+ && priv->v4_commit_first_time
+ && !nm_device_uses_assumed_connection (self);
+
success = nm_device_set_ip4_config (self, composite, default_route_metric, commit, routes_full_sync, out_reason);
g_object_unref (composite);
+
+ if (commit)
+ priv->v4_commit_first_time = FALSE;
return success;
}
@@ -3934,21 +3941,26 @@ ip6_config_merge_and_apply (NMDevice *self,
priv->default_route.v6_has = FALSE;
priv->default_route.v6_is_assumed = TRUE;
- routes_full_sync = commit
- && priv->default_route.v6_configure_first_time
- && !nm_device_uses_assumed_connection (self);
-
if (!commit) {
/* during a non-commit event, we always pickup whatever is configured. */
goto END_ADD_DEFAULT_ROUTE;
}
+ if (nm_device_uses_generated_assumed_connection (self)) {
+ /* a generate-assumed-connection always detects the default route from platform */
+ goto END_ADD_DEFAULT_ROUTE;
+ }
+
+ /* At this point, we treat assumed and non-assumed connections alike.
+ * For assumed connections we do that because we still manage RA and DHCP
+ * leases for them, so we must extend/update the default route on commits.
+ */
+
connection_has_default_route
= nm_default_route_manager_ip6_connection_has_default_route (nm_default_route_manager_get (),
connection, &connection_is_never_default);
- if ( !priv->default_route.v6_configure_first_time
- && !nm_device_uses_assumed_connection (self)
+ if ( !priv->v6_commit_first_time
&& connection_is_never_default) {
/* If the connection is explicitly configured as never-default, we enforce the (absence of the)
* default-route only once. That allows the user to configure a connection as never-default,
@@ -3956,14 +3968,8 @@ ip6_config_merge_and_apply (NMDevice *self,
goto END_ADD_DEFAULT_ROUTE;
}
- /* At this point, we treat assumed and non-assumed connections alike.
- * For assumed connections we do that because we still manage RA and DHCP
- * leases for them, so we must extend/update the default route on commits.
- */
-
/* we are about to commit (for a non-assumed connection). Enforce whatever we have
* configured. */
- priv->default_route.v6_configure_first_time = FALSE;
priv->default_route.v6_is_assumed = FALSE;
if (!connection_has_default_route)
@@ -4020,8 +4026,14 @@ END_ADD_DEFAULT_ROUTE:
NM_DEVICE_GET_CLASS (self)->ip6_config_pre_commit (self, composite);
}
+ routes_full_sync = commit
+ && priv->v6_commit_first_time
+ && !nm_device_uses_assumed_connection (self);
+
success = nm_device_set_ip6_config (self, composite, commit, routes_full_sync, out_reason);
g_object_unref (composite);
+ if (commit)
+ priv->v6_commit_first_time = FALSE;
return success;
}
@@ -7943,10 +7955,11 @@ _cleanup_generic_post (NMDevice *self, CleanupType cleanup_type)
priv->default_route.v4_has = FALSE;
priv->default_route.v4_is_assumed = TRUE;
- priv->default_route.v4_configure_first_time = TRUE;
priv->default_route.v6_has = FALSE;
priv->default_route.v6_is_assumed = TRUE;
- priv->default_route.v6_configure_first_time = TRUE;
+
+ priv->v4_commit_first_time = TRUE;
+ priv->v6_commit_first_time = TRUE;
nm_default_route_manager_ip4_update_default_route (nm_default_route_manager_get (), self);
nm_default_route_manager_ip6_update_default_route (nm_default_route_manager_get (), self);
@@ -8900,9 +8913,10 @@ nm_device_init (NMDevice *self)
priv->ip6_saved_properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
priv->default_route.v4_is_assumed = TRUE;
- priv->default_route.v4_configure_first_time = TRUE;
priv->default_route.v6_is_assumed = TRUE;
- priv->default_route.v6_configure_first_time = TRUE;
+
+ priv->v4_commit_first_time = TRUE;
+ priv->v6_commit_first_time = TRUE;
}
static GObject*
diff --git a/src/nm-default-route-manager.c b/src/nm-default-route-manager.c
index fbb07ce3fc..b36dd44f3a 100644
--- a/src/nm-default-route-manager.c
+++ b/src/nm-default-route-manager.c
@@ -1290,7 +1290,9 @@ _resync_idle_reschedule (NMDefaultRouteManager *self)
g_source_remove (priv->resync.idle_handle);
else
_LOGD (0, "resync: schedule on idle");
- priv->resync.idle_handle = g_idle_add ((GSourceFunc) _resync_idle_now, self);
+ /* Schedule this at low priority so that on an external change to platform
+ * a NMDevice has a chance to picks up the changes first. */
+ priv->resync.idle_handle = g_idle_add_full (G_PRIORITY_LOW, (GSourceFunc) _resync_idle_now, self, NULL);
} else if (!priv->resync.idle_handle) {
priv->resync.idle_handle = g_timeout_add (priv->resync.backoff_wait_time_ms, (GSourceFunc) _resync_idle_now, self);
_LOGD (0, "resync: schedule in %u.%03u seconds (%u)", priv->resync.backoff_wait_time_ms/1000,
diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c
index 2b137ff73a..87da7c7545 100644
--- a/src/nm-ip4-config.c
+++ b/src/nm-ip4-config.c
@@ -46,6 +46,7 @@ typedef struct {
gboolean never_default;
guint32 gateway;
+ gboolean has_gateway;
GArray *addresses;
GArray *routes;
GArray *nameservers;
@@ -217,7 +218,7 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf)
guint i;
guint32 lowest_metric = G_MAXUINT32;
guint32 old_gateway = 0;
- gboolean has_gateway = FALSE;
+ gboolean old_has_gateway = FALSE;
/* Slaves have no IP configuration */
if (nm_platform_link_get_master (NM_PLATFORM_GET, ifindex) > 0)
@@ -234,6 +235,7 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf)
/* Extract gateway from default route */
old_gateway = priv->gateway;
+ old_has_gateway = priv->has_gateway;
for (i = 0; i < priv->routes->len; ) {
const NMPlatformIP4Route *route = &g_array_index (priv->routes, NMPlatformIP4Route, i);
@@ -242,7 +244,7 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf)
priv->gateway = route->gateway;
lowest_metric = route->metric;
}
- has_gateway = TRUE;
+ priv->has_gateway = TRUE;
/* Remove the default route from the list */
g_array_remove_index_fast (priv->routes, i);
continue;
@@ -252,12 +254,12 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf)
/* we detect the route metric based on the default route. All non-default
* routes have their route metrics explicitly set. */
- priv->route_metric = has_gateway ? (gint64) lowest_metric : (gint64) -1;
+ priv->route_metric = priv->has_gateway ? (gint64) lowest_metric : (gint64) -1;
/* If there is a host route to the gateway, ignore that route. It is
* automatically added by NetworkManager when needed.
*/
- if (has_gateway) {
+ if (priv->has_gateway) {
for (i = 0; i < priv->routes->len; i++) {
const NMPlatformIP4Route *route = &g_array_index (priv->routes, NMPlatformIP4Route, i);
@@ -273,7 +275,7 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf)
/* If the interface has the default route, and has IPv4 addresses, capture
* nameservers from /etc/resolv.conf.
*/
- if (priv->addresses->len && has_gateway && capture_resolv_conf) {
+ if (priv->addresses->len && priv->has_gateway && capture_resolv_conf) {
if (nm_ip4_config_capture_resolv_conf (priv->nameservers, priv->dns_options, NULL))
_NOTIFY (config, PROP_NAMESERVERS);
}
@@ -283,7 +285,8 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf)
_NOTIFY (config, PROP_ROUTE_DATA);
_NOTIFY (config, PROP_ADDRESSES);
_NOTIFY (config, PROP_ROUTES);
- if (priv->gateway != old_gateway)
+ if ( priv->gateway != old_gateway
+ || priv->has_gateway != old_has_gateway)
_NOTIFY (config, PROP_GATEWAY);
return config;
@@ -521,7 +524,7 @@ nm_ip4_config_create_setting (const NMIP4Config *config)
}
/* Gateway */
- if ( gateway
+ if ( nm_ip4_config_has_gateway (config)
&& nm_setting_ip_config_get_num_addresses (s_ip4) > 0) {
g_object_set (s_ip4,
NM_SETTING_IP_CONFIG_GATEWAY, nm_utils_inet4_ntop (gateway, NULL),
@@ -604,7 +607,7 @@ nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src)
nm_ip4_config_add_nameserver (dst, nm_ip4_config_get_nameserver (src, i));
/* default gateway */
- if (nm_ip4_config_get_gateway (src))
+ if (nm_ip4_config_has_gateway (src))
nm_ip4_config_set_gateway (dst, nm_ip4_config_get_gateway (src));
/* routes */
@@ -814,11 +817,12 @@ nm_ip4_config_subtract (NMIP4Config *dst, const NMIP4Config *src)
}
/* default gateway */
- if (nm_ip4_config_get_gateway (src) == nm_ip4_config_get_gateway (dst))
- nm_ip4_config_set_gateway (dst, 0);
+ if ( (nm_ip4_config_has_gateway (src) == nm_ip4_config_has_gateway (dst))
+ && (nm_ip4_config_get_gateway (src) == nm_ip4_config_get_gateway (dst)))
+ nm_ip4_config_unset_gateway (dst);
if (!nm_ip4_config_get_num_addresses (dst))
- nm_ip4_config_set_gateway (dst, 0);
+ nm_ip4_config_unset_gateway (dst);
/* ignore route_metric */
@@ -903,8 +907,10 @@ nm_ip4_config_intersect (NMIP4Config *dst, const NMIP4Config *src)
/* default gateway */
if ( !nm_ip4_config_get_num_addresses (dst)
- || (nm_ip4_config_get_gateway (src) != nm_ip4_config_get_gateway (dst)))
- nm_ip4_config_set_gateway (dst, 0);
+ || (nm_ip4_config_has_gateway (src) != nm_ip4_config_has_gateway (dst))
+ || (nm_ip4_config_get_gateway (src) != nm_ip4_config_get_gateway (dst))) {
+ nm_ip4_config_unset_gateway (dst);
+ }
/* routes */
for (i = 0; i < nm_ip4_config_get_num_routes (dst); ) {
@@ -977,7 +983,8 @@ nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relev
}
/* default gateway */
- if (src_priv->gateway != dst_priv->gateway) {
+ if ( src_priv->gateway != dst_priv->gateway
+ || src_priv->has_gateway != dst_priv->has_gateway) {
nm_ip4_config_set_gateway (dst, src_priv->gateway);
has_relevant_changes = TRUE;
}
@@ -1199,8 +1206,10 @@ nm_ip4_config_dump (const NMIP4Config *config, const char *detail)
g_message (" a: %s", nm_platform_ip4_address_to_string (nm_ip4_config_get_address (config, i)));
/* default gateway */
- tmp = nm_ip4_config_get_gateway (config);
- g_message (" gw: %s", nm_utils_inet4_ntop (tmp, NULL));
+ if (nm_ip4_config_has_gateway (config)) {
+ tmp = nm_ip4_config_get_gateway (config);
+ g_message (" gw: %s", nm_utils_inet4_ntop (tmp, NULL));
+ }
/* nameservers */
for (i = 0; i < nm_ip4_config_get_num_nameservers (config); i++) {
@@ -1285,12 +1294,33 @@ nm_ip4_config_set_gateway (NMIP4Config *config, guint32 gateway)
{
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
- if (priv->gateway != gateway) {
+ if (priv->gateway != gateway || !priv->has_gateway) {
priv->gateway = gateway;
+ priv->has_gateway = TRUE;
+ _NOTIFY (config, PROP_GATEWAY);
+ }
+}
+
+void
+nm_ip4_config_unset_gateway (NMIP4Config *config)
+{
+ NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
+
+ if (priv->has_gateway) {
+ priv->gateway = 0;
+ priv->has_gateway = FALSE;
_NOTIFY (config, PROP_GATEWAY);
}
}
+gboolean
+nm_ip4_config_has_gateway (const NMIP4Config *config)
+{
+ NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
+
+ return priv->has_gateway;
+}
+
guint32
nm_ip4_config_get_gateway (const NMIP4Config *config)
{
@@ -1992,6 +2022,7 @@ nm_ip4_config_hash (const NMIP4Config *config, GChecksum *sum, gboolean dns_only
g_return_if_fail (sum);
if (!dns_only) {
+ hash_u32 (sum, nm_ip4_config_has_gateway (config));
hash_u32 (sum, nm_ip4_config_get_gateway (config));
for (i = 0; i < nm_ip4_config_get_num_addresses (config); i++) {
@@ -2264,7 +2295,7 @@ get_property (GObject *object, guint prop_id,
}
break;
case PROP_GATEWAY:
- if (priv->gateway)
+ if (priv->has_gateway)
g_value_set_string (value, nm_utils_inet4_ntop (priv->gateway, NULL));
else
g_value_set_string (value, NULL);
diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h
index 0f457217a4..4415c453ea 100644
--- a/src/nm-ip4-config.h
+++ b/src/nm-ip4-config.h
@@ -87,6 +87,8 @@ void nm_ip4_config_dump (const NMIP4Config *config, const char *detail);
void nm_ip4_config_set_never_default (NMIP4Config *config, gboolean never_default);
gboolean nm_ip4_config_get_never_default (const NMIP4Config *config);
void nm_ip4_config_set_gateway (NMIP4Config *config, guint32 gateway);
+void nm_ip4_config_unset_gateway (NMIP4Config *config);
+gboolean nm_ip4_config_has_gateway (const NMIP4Config *config);
guint32 nm_ip4_config_get_gateway (const NMIP4Config *config);
gint64 nm_ip4_config_get_route_metric (const NMIP4Config *config);
diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
index 350ea534fc..d541cd6151 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -6572,7 +6572,7 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data)
g_assert (addr6);
/* assert that the gateway was written and reloaded as expected */
- if (!gateway6 || !strcmp (gateway6, "::")) {
+ if (!gateway6) {
g_assert (nm_setting_ip_config_get_gateway (s_ip6) == NULL);
g_assert (written_ifcfg_gateway == NULL);
} else {