diff options
author | Dan Williams <dcbw@redhat.com> | 2015-03-12 15:04:16 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2015-03-12 15:04:16 -0500 |
commit | d2de83e0f78edcc09181913b3308a3b2663b8ebd (patch) | |
tree | c735651213992ff94b750256c3a8cc924927fd0e | |
parent | 1dae47e9cc4c2ec43bcabf9fa8610acc0b6e257b (diff) | |
download | NetworkManager-d2de83e0f78edcc09181913b3308a3b2663b8ebd.tar.gz |
device: don't assume valid ip4/ip6 config in nm_device_get_ipX_route_metric()
These functions will sometimes get called on updates to the device's IP
config due to external changes, or when addresses get flushed from the
device when activating it. If the device is a slave device, then at
this point its NMConnection won't have an IP settings. Suppress the
warning that gets printed when s_ip == NULL, because it's expected.
-rw-r--r-- | src/devices/nm-device.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 7a6113642b..fa5c4db2a9 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -730,14 +730,21 @@ guint32 nm_device_get_ip4_route_metric (NMDevice *self) { NMConnection *connection; + NMSettingIPConfig *s_ip = NULL; gint64 route_metric = -1; g_return_val_if_fail (NM_IS_DEVICE (self), G_MAXUINT32); connection = nm_device_get_connection (self); - if (connection) - route_metric = nm_setting_ip_config_get_route_metric (nm_connection_get_setting_ip4_config (connection)); + s_ip = nm_connection_get_setting_ip4_config (connection); + + /* Slave interfaces don't have IP settings, but we may get here when + * external changes are made or when noticing IP changes when starting + * the slave connection. + */ + if (s_ip) + route_metric = nm_setting_ip_config_get_route_metric (s_ip); return route_metric >= 0 ? route_metric : nm_device_get_priority (self); } @@ -746,14 +753,21 @@ guint32 nm_device_get_ip6_route_metric (NMDevice *self) { NMConnection *connection; + NMSettingIPConfig *s_ip = NULL; gint64 route_metric = -1; g_return_val_if_fail (NM_IS_DEVICE (self), G_MAXUINT32); connection = nm_device_get_connection (self); - if (connection) - route_metric = nm_setting_ip_config_get_route_metric (nm_connection_get_setting_ip6_config (connection)); + s_ip = nm_connection_get_setting_ip6_config (connection); + + /* Slave interfaces don't have IP settings, but we may get here when + * external changes are made or when noticing IP changes when starting + * the slave connection. + */ + if (s_ip) + route_metric = nm_setting_ip_config_get_route_metric (s_ip); return route_metric >= 0 ? route_metric : nm_device_get_priority (self); } |