diff options
author | Thomas Haller <thaller@redhat.com> | 2014-08-28 18:11:35 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-11-07 15:19:06 +0100 |
commit | 172c1eb65241ca420050787d92ed71776718d184 (patch) | |
tree | b5b32017ff64f0df3cb5645def73832d61fb6054 | |
parent | a2662633a5ea21387cb9645440dc48b96b6100df (diff) | |
download | NetworkManager-172c1eb65241ca420050787d92ed71776718d184.tar.gz |
core: add explicit functions for the 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.
Also add new function nm_vpn_connection_get_ip4_route_metric() and
nm_vpn_connection_get_ip6_route_metric().
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | src/devices/nm-device.c | 24 | ||||
-rw-r--r-- | src/devices/nm-device.h | 2 | ||||
-rw-r--r-- | src/vpn-manager/nm-vpn-connection.c | 48 | ||||
-rw-r--r-- | src/vpn-manager/nm-vpn-connection.h | 3 |
4 files changed, 60 insertions, 17 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index efb4a69257..419ea87174 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -681,6 +681,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_ip_config_get_dhcp_send_hostname (s_ip4), nm_setting_ip_config_get_dhcp_hostname (s_ip4), nm_setting_ip4_config_get_dhcp_client_id (NM_SETTING_IP4_CONFIG (s_ip4)), @@ -3163,7 +3175,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, @@ -3356,7 +3368,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_ip_config_get_dhcp_send_hostname (s_ip6), nm_setting_ip_config_get_dhcp_hostname (s_ip6), priv->dhcp_timeout, @@ -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 81936e4dbe..9f5e47b65e 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -487,6 +487,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)); @@ -502,6 +503,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; @@ -515,7 +518,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 @@ -527,7 +530,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); } @@ -540,6 +543,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)); @@ -551,6 +555,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; @@ -564,7 +570,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 @@ -576,7 +582,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); } @@ -1104,8 +1110,8 @@ nm_vpn_connection_config_get (DBusGProxy *proxy, g_clear_object (&priv->ip6_config); } -static guint32 -vpn_routing_metric (NMVpnConnection *connection) +guint32 +nm_vpn_connection_get_ip4_route_metric (NMVpnConnection *connection) { NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); @@ -1114,7 +1120,21 @@ 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_ip4_route_metric (parent_dev); + } +} + +guint32 +nm_vpn_connection_get_ip6_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_ip6_route_metric (parent_dev); } } @@ -1129,6 +1149,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); @@ -1226,6 +1247,8 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, nm_ip4_config_add_domain (config, *domain); } + route_metric = nm_vpn_connection_get_ip4_route_metric (connection); + val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_ROUTES); if (val) { GSList *routes; @@ -1241,7 +1264,7 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, route.plen = nm_ip_route_get_prefix (item); nm_ip_route_get_next_hop_binary (item, &route.gateway); 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 @@ -1265,7 +1288,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); g_clear_object (&priv->ip4_config); priv->ip4_config = config; @@ -1285,6 +1308,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)); @@ -1373,6 +1397,8 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy, nm_ip6_config_add_domain (config, *domain); } + route_metric = nm_vpn_connection_get_ip6_route_metric (connection); + val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP6_CONFIG_ROUTES); if (val) { GSList *routes; @@ -1388,7 +1414,7 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy, route.plen = nm_ip_route_get_prefix (item); nm_ip_route_get_next_hop_binary (item, &route.gateway); 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 @@ -1412,7 +1438,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); g_clear_object (&priv->ip6_config); priv->ip6_config = config; diff --git a/src/vpn-manager/nm-vpn-connection.h b/src/vpn-manager/nm-vpn-connection.h index 047113c318..512bdf932a 100644 --- a/src/vpn-manager/nm-vpn-connection.h +++ b/src/vpn-manager/nm-vpn-connection.h @@ -96,4 +96,7 @@ int nm_vpn_connection_get_ip_ifindex (NMVpnConnection *connect guint32 nm_vpn_connection_get_ip4_internal_gateway (NMVpnConnection *connection); struct in6_addr * nm_vpn_connection_get_ip6_internal_gateway (NMVpnConnection *connection); +guint32 nm_vpn_connection_get_ip4_route_metric (NMVpnConnection *connection); +guint32 nm_vpn_connection_get_ip6_route_metric (NMVpnConnection *connection); + #endif /* __NETWORKMANAGER_VPN_CONNECTION_H__ */ |