device: expose nm_device_get_ip_route_metric() function

Will be used later.
This commit is contained in:
Thomas Haller
2017-08-30 19:10:15 +02:00
parent c16e871888
commit e99a603944
2 changed files with 21 additions and 22 deletions

View File

@@ -1645,9 +1645,9 @@ route_metric_with_penalty (NMDevice *self, guint32 metric)
return metric; return metric;
} }
static guint32 guint32
_get_ipx_route_metric (NMDevice *self, nm_device_get_ip_route_metric (NMDevice *self,
gboolean is_v4) int addr_family)
{ {
char *value; char *value;
gint64 route_metric; gint64 route_metric;
@@ -1655,10 +1655,11 @@ _get_ipx_route_metric (NMDevice *self,
NMConnection *connection; NMConnection *connection;
g_return_val_if_fail (NM_IS_DEVICE (self), G_MAXUINT32); 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); connection = nm_device_get_applied_connection (self);
if (connection) { if (connection) {
s_ip = is_v4 s_ip = addr_family == AF_INET
? nm_connection_get_setting_ip4_config (connection) ? nm_connection_get_setting_ip4_config (connection)
: nm_connection_get_setting_ip6_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. * Note that that means that the route-metric might change between SIGHUP.
* You must cache the returned value if that is a problem. */ * You must cache the returned value if that is a problem. */
value = nm_config_data_get_connection_default (NM_CONFIG_GET_DATA, 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) { if (value) {
route_metric = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT32, -1); route_metric = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT32, -1);
g_free (value); g_free (value);
@@ -1687,21 +1688,7 @@ _get_ipx_route_metric (NMDevice *self,
} }
route_metric = nm_device_get_priority (self); route_metric = nm_device_get_priority (self);
out: out:
if (!is_v4) return nm_utils_ip_route_metric_normalize (addr_family, route_metric);
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);
} }
static void static void

View File

@@ -445,8 +445,20 @@ NMLinkType nm_device_get_link_type (NMDevice *dev);
NMMetered nm_device_get_metered (NMDevice *dev); NMMetered nm_device_get_metered (NMDevice *dev);
int nm_device_get_priority (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_hw_address (NMDevice *dev);
const char * nm_device_get_permanent_hw_address (NMDevice *self); const char * nm_device_get_permanent_hw_address (NMDevice *self);