From 0f4fcd44e1ee4a290858fad539210d23d9c5d71f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 28 Aug 2014 18:11:35 +0200 Subject: core: add explicit functions for the device route priority/metric Before, we would always call unanimously nm_device_get_priority() to get the default route metric for a device. Add new functions nm_device_get_ip4_route_priority() and nm_device_get_ip6_route_priority() and use them at the proper places. Signed-off-by: Thomas Haller --- src/devices/nm-device.c | 24 ++++++++++++++----- src/devices/nm-device.h | 2 ++ src/vpn-manager/nm-vpn-connection.c | 46 +++++++++++++++++++++++++++++-------- 3 files changed, 56 insertions(+), 16 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index af5e52750c..2863701dd7 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -680,6 +680,18 @@ nm_device_get_priority (NMDevice *self) } } +guint32 +nm_device_get_ip4_route_metric (NMDevice *self) +{ + return nm_device_get_priority (self); +} + +guint32 +nm_device_get_ip6_route_metric (NMDevice *self) +{ + return nm_device_get_priority (self); +} + const char * nm_device_get_type_desc (NMDevice *self) { @@ -2394,7 +2406,7 @@ aipd_get_ip4_config (NMDevice *self, guint32 lla) route.network = htonl (0xE0000000L); route.plen = 4; route.source = NM_IP_CONFIG_SOURCE_IP4LL; - route.metric = nm_device_get_priority (self); + route.metric = nm_device_get_ip4_route_metric (self); nm_ip4_config_add_route (config, &route); return config; @@ -2662,7 +2674,7 @@ ip4_config_merge_and_apply (NMDevice *self, && !nm_settings_connection_get_nm_generated_assumed (NM_SETTINGS_CONNECTION (connection))) { nm_ip4_config_merge_setting (composite, nm_connection_get_setting_ip4_config (connection), - nm_device_get_priority (self)); + nm_device_get_ip4_route_metric (self)); } /* Allow setting MTU etc */ @@ -2803,7 +2815,7 @@ dhcp4_start (NMDevice *self, nm_device_get_ip_ifindex (self), tmp, nm_connection_get_uuid (connection), - nm_device_get_priority (self), + nm_device_get_ip4_route_metric (self), nm_setting_ip4_config_get_dhcp_send_hostname (s_ip4), nm_setting_ip4_config_get_dhcp_hostname (s_ip4), nm_setting_ip4_config_get_dhcp_client_id (s_ip4), @@ -3164,7 +3176,7 @@ ip6_config_merge_and_apply (NMDevice *self, && !nm_settings_connection_get_nm_generated_assumed (NM_SETTINGS_CONNECTION (connection))) { nm_ip6_config_merge_setting (composite, nm_connection_get_setting_ip6_config (connection), - nm_device_get_priority (self)); + nm_device_get_ip6_route_metric (self)); } nm_ip6_config_addresses_sort (composite, @@ -3357,7 +3369,7 @@ dhcp6_start (NMDevice *self, nm_device_get_ip_ifindex (self), tmp, nm_connection_get_uuid (connection), - nm_device_get_priority (self), + nm_device_get_ip6_route_metric (self), nm_setting_ip6_config_get_dhcp_hostname (s_ip6), priv->dhcp_timeout, priv->dhcp_anycast_address, @@ -3700,7 +3712,7 @@ rdisc_config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed, NMDevice *self) route.plen = discovered_route->plen; route.gateway = discovered_route->gateway; route.source = NM_IP_CONFIG_SOURCE_RDISC; - route.metric = nm_device_get_priority (self); + route.metric = nm_device_get_ip6_route_metric (self); nm_ip6_config_add_route (priv->ac_ip6_config, &route); } diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index b053070388..a2663a0253 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -228,6 +228,8 @@ const char * nm_device_get_type_desc (NMDevice *dev); NMDeviceType nm_device_get_device_type (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); const char * nm_device_get_hw_address (NMDevice *dev); diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index dfe213b021..b17e249257 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -460,6 +460,7 @@ add_ip4_vpn_gateway_route (NMIP4Config *config, NMDevice *parent_device, guint32 NMIP4Config *parent_config; guint32 parent_gw; NMPlatformIP4Route route; + guint32 route_metric; g_return_if_fail (NM_IS_IP4_CONFIG (config)); g_return_if_fail (NM_IS_DEVICE (parent_device)); @@ -475,6 +476,8 @@ add_ip4_vpn_gateway_route (NMIP4Config *config, NMDevice *parent_device, guint32 if (!parent_gw) return; + route_metric = nm_device_get_ip4_route_metric (parent_device); + memset (&route, 0, sizeof (route)); route.network = vpn_gw; route.plen = 32; @@ -488,7 +491,7 @@ add_ip4_vpn_gateway_route (NMIP4Config *config, NMDevice *parent_device, guint32 route.gateway = 0; route.source = NM_IP_CONFIG_SOURCE_VPN; - route.metric = nm_device_get_priority (parent_device); + route.metric = route_metric; nm_ip4_config_add_route (config, &route); /* Ensure there's a route to the parent device's gateway through the @@ -500,7 +503,7 @@ add_ip4_vpn_gateway_route (NMIP4Config *config, NMDevice *parent_device, guint32 route.network = parent_gw; route.plen = 32; route.source = NM_IP_CONFIG_SOURCE_VPN; - route.metric = nm_device_get_priority (parent_device); + route.metric = route_metric; nm_ip4_config_add_route (config, &route); } @@ -513,6 +516,7 @@ add_ip6_vpn_gateway_route (NMIP6Config *config, NMIP6Config *parent_config; const struct in6_addr *parent_gw; NMPlatformIP6Route route; + guint32 route_metric; g_return_if_fail (NM_IS_IP6_CONFIG (config)); g_return_if_fail (NM_IS_DEVICE (parent_device)); @@ -524,6 +528,8 @@ add_ip6_vpn_gateway_route (NMIP6Config *config, if (!parent_gw) return; + route_metric = nm_device_get_ip6_route_metric (parent_device); + memset (&route, 0, sizeof (route)); route.network = *vpn_gw; route.plen = 128; @@ -537,7 +543,7 @@ add_ip6_vpn_gateway_route (NMIP6Config *config, route.gateway = in6addr_any; route.source = NM_IP_CONFIG_SOURCE_VPN; - route.metric = nm_device_get_priority (parent_device); + route.metric = route_metric; nm_ip6_config_add_route (config, &route); /* Ensure there's a route to the parent device's gateway through the @@ -549,7 +555,7 @@ add_ip6_vpn_gateway_route (NMIP6Config *config, route.network = *parent_gw; route.plen = 128; route.source = NM_IP_CONFIG_SOURCE_VPN; - route.metric = nm_device_get_priority (parent_device); + route.metric = route_metric; nm_ip6_config_add_route (config, &route); } @@ -1048,7 +1054,21 @@ nm_vpn_connection_config_get (DBusGProxy *proxy, } static guint32 -vpn_routing_metric (NMVpnConnection *connection) +get_vpn_ip4_route_metric (NMVpnConnection *connection) +{ + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); + + if (priv->ip_ifindex) + return NM_PLATFORM_ROUTE_METRIC_DEFAULT; + else { + NMDevice *parent_dev = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (connection)); + + return nm_device_get_ip4_route_metric (parent_dev); + } +} + +static guint32 +get_vpn_ip6_route_metric (NMVpnConnection *connection) { NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); @@ -1057,7 +1077,7 @@ vpn_routing_metric (NMVpnConnection *connection) else { NMDevice *parent_dev = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (connection)); - return nm_device_get_priority (parent_dev); + return nm_device_get_ip6_route_metric (parent_dev); } } @@ -1072,6 +1092,7 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, NMIP4Config *config; GValue *val; int i; + guint32 route_metric; if (priv->vpn_state == STATE_CONNECT) _set_vpn_state (connection, STATE_IP_CONFIG_GET, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE); @@ -1169,6 +1190,8 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, nm_ip4_config_add_domain (config, *domain); } + route_metric = get_vpn_ip4_route_metric (connection); + val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_ROUTES); if (val) { GSList *routes; @@ -1184,7 +1207,7 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, route.plen = nm_ip4_route_get_prefix (item); route.gateway = nm_ip4_route_get_next_hop (item); route.source = NM_IP_CONFIG_SOURCE_VPN; - route.metric = vpn_routing_metric (connection); + route.metric = route_metric; /* Ignore host routes to the VPN gateway since NM adds one itself * below. Since NM knows more about the routing situation than @@ -1208,7 +1231,7 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, /* Merge in user overrides from the NMConnection's IPv4 setting */ nm_ip4_config_merge_setting (config, nm_connection_get_setting_ip4_config (priv->connection), - vpn_routing_metric (connection)); + route_metric); priv->ip4_config = config; nm_ip4_config_export (config); @@ -1227,6 +1250,7 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy, NMIP6Config *config; GValue *val; int i; + guint32 route_metric; nm_log_info (LOGD_VPN, "VPN connection '%s' (IP6 Config Get) reply received.", nm_connection_get_id (priv->connection)); @@ -1315,6 +1339,8 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy, nm_ip6_config_add_domain (config, *domain); } + route_metric = get_vpn_ip6_route_metric (connection); + val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP6_CONFIG_ROUTES); if (val) { GSList *routes; @@ -1330,7 +1356,7 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy, route.plen = nm_ip6_route_get_prefix (item); route.gateway = *nm_ip6_route_get_next_hop (item); route.source = NM_IP_CONFIG_SOURCE_VPN; - route.metric = vpn_routing_metric (connection); + route.metric = route_metric; /* Ignore host routes to the VPN gateway since NM adds one itself * below. Since NM knows more about the routing situation than @@ -1354,7 +1380,7 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy, /* Merge in user overrides from the NMConnection's IPv6 setting */ nm_ip6_config_merge_setting (config, nm_connection_get_setting_ip6_config (priv->connection), - vpn_routing_metric (connection)); + route_metric); priv->ip6_config = config; nm_ip6_config_export (config); -- cgit v1.2.1