diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index b861f2cb6..397296373 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1645,9 +1645,9 @@ route_metric_with_penalty (NMDevice *self, guint32 metric) return metric; } -static guint32 -_get_ipx_route_metric (NMDevice *self, - gboolean is_v4) +guint32 +nm_device_get_ip_route_metric (NMDevice *self, + int addr_family) { char *value; gint64 route_metric; @@ -1655,10 +1655,11 @@ _get_ipx_route_metric (NMDevice *self, NMConnection *connection; g_return_val_if_fail (NM_IS_DEVICE (self), G_MAXUINT32); + g_return_val_if_fail (NM_IN_SET (addr_family, AF_INET, AF_INET6), G_MAXUINT32); connection = nm_device_get_applied_connection (self); if (connection) { - s_ip = is_v4 + s_ip = addr_family == AF_INET ? nm_connection_get_setting_ip4_config (connection) : nm_connection_get_setting_ip6_config (connection); @@ -1677,7 +1678,7 @@ _get_ipx_route_metric (NMDevice *self, * Note that that means that the route-metric might change between SIGHUP. * You must cache the returned value if that is a problem. */ value = nm_config_data_get_connection_default (NM_CONFIG_GET_DATA, - is_v4 ? "ipv4.route-metric" : "ipv6.route-metric", self); + addr_family == AF_INET ? "ipv4.route-metric" : "ipv6.route-metric", self); if (value) { route_metric = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT32, -1); g_free (value); @@ -1687,21 +1688,7 @@ _get_ipx_route_metric (NMDevice *self, } route_metric = nm_device_get_priority (self); out: - if (!is_v4) - route_metric = nm_utils_ip6_route_metric_normalize (route_metric); - return route_metric; -} - -guint32 -nm_device_get_ip4_route_metric (NMDevice *self) -{ - return _get_ipx_route_metric (self, TRUE); -} - -guint32 -nm_device_get_ip6_route_metric (NMDevice *self) -{ - return _get_ipx_route_metric (self, FALSE); + return nm_utils_ip_route_metric_normalize (addr_family, route_metric); } static void diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 358b59af2..f46a64ca2 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -445,8 +445,20 @@ NMLinkType nm_device_get_link_type (NMDevice *dev); NMMetered nm_device_get_metered (NMDevice *dev); int nm_device_get_priority (NMDevice *dev); -guint32 nm_device_get_ip4_route_metric (NMDevice *dev); -guint32 nm_device_get_ip6_route_metric (NMDevice *dev); + +guint32 nm_device_get_ip_route_metric (NMDevice *dev, int addr_family); + +static inline guint32 +nm_device_get_ip4_route_metric (NMDevice *self) +{ + return nm_device_get_ip_route_metric (self, AF_INET); +} + +static inline guint32 +nm_device_get_ip6_route_metric (NMDevice *self) +{ + return nm_device_get_ip_route_metric (self, AF_INET6); +} const char * nm_device_get_hw_address (NMDevice *dev); const char * nm_device_get_permanent_hw_address (NMDevice *self);