mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-11 08:20:30 +01: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.
This commit is contained in:
parent
1dae47e9cc
commit
d2de83e0f7
1 changed files with 18 additions and 4 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue