mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-01 12:38:04 +02:00
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.
(cherry picked from commit d2de83e0f7)
This commit is contained in:
parent
a8833a4dbd
commit
6e77c1ba2f
1 changed files with 18 additions and 4 deletions
|
|
@ -723,14 +723,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);
|
||||
}
|
||||
|
|
@ -739,14 +746,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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue