mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-08 10:20:30 +01:00
core: detect route-metric when creating nm-generated-assumed connection
When generating a connection to assume it, also record the route-metric.
Do that by looking at the metric of the (best) default-route.
This is especially important since d51975ed92.
Now NM would also manage the default-route for assumed connections.
So the generated assumed connection would have a route metric based on
the device type, which might differ from the external configuration.
This caused NM to replace the externally configured default-route.
https://bugzilla.gnome.org/show_bug.cgi?id=750405
This commit is contained in:
parent
2a5d17eb5f
commit
bc75cd53a8
4 changed files with 90 additions and 2 deletions
|
|
@ -58,6 +58,7 @@ typedef struct {
|
|||
guint32 mtu;
|
||||
NMIPConfigSource mtu_source;
|
||||
int ifindex;
|
||||
gint64 route_metric;
|
||||
} NMIP4ConfigPrivate;
|
||||
|
||||
/* internal guint32 are assigned to gobject properties of type uint. Ensure, that uint is large enough */
|
||||
|
|
@ -246,6 +247,10 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf)
|
|||
}
|
||||
}
|
||||
|
||||
/* we detect the route metric based on the default route. All non-default
|
||||
* routes have their route metrics explicitly set. */
|
||||
priv->route_metric = has_gateway ? (gint64) lowest_metric : (gint64) -1;
|
||||
|
||||
/* If there is a host route to the gateway, ignore that route. It is
|
||||
* automatically added by NetworkManager when needed.
|
||||
*/
|
||||
|
|
@ -325,6 +330,7 @@ nm_ip4_config_commit (const NMIP4Config *config, int ifindex, guint32 default_ro
|
|||
void
|
||||
nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, guint32 default_route_metric)
|
||||
{
|
||||
NMIP4ConfigPrivate *priv;
|
||||
guint naddresses, nroutes, nnameservers, nsearches;
|
||||
int i;
|
||||
|
||||
|
|
@ -333,6 +339,8 @@ nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, gu
|
|||
|
||||
g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
|
||||
|
||||
priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
||||
|
||||
g_object_freeze_notify (G_OBJECT (config));
|
||||
|
||||
naddresses = nm_setting_ip_config_get_num_addresses (setting);
|
||||
|
|
@ -352,6 +360,9 @@ nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, gu
|
|||
nm_ip4_config_set_gateway (config, gateway);
|
||||
}
|
||||
|
||||
if (priv->route_metric == -1)
|
||||
priv->route_metric = nm_setting_ip_config_get_route_metric (setting);
|
||||
|
||||
/* Addresses */
|
||||
for (i = 0; i < naddresses; i++) {
|
||||
NMIPAddress *s_addr = nm_setting_ip_config_get_address (setting, i);
|
||||
|
|
@ -426,6 +437,7 @@ nm_ip4_config_create_setting (const NMIP4Config *config)
|
|||
guint naddresses, nroutes, nnameservers, nsearches, noptions;
|
||||
const char *method = NULL;
|
||||
int i;
|
||||
gint64 route_metric;
|
||||
|
||||
s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ());
|
||||
|
||||
|
|
@ -442,6 +454,7 @@ nm_ip4_config_create_setting (const NMIP4Config *config)
|
|||
nnameservers = nm_ip4_config_get_num_nameservers (config);
|
||||
nsearches = nm_ip4_config_get_num_searches (config);
|
||||
noptions = nm_ip4_config_get_num_dns_options (config);
|
||||
route_metric = nm_ip4_config_get_route_metric (config);
|
||||
|
||||
/* Addresses */
|
||||
for (i = 0; i < naddresses; i++) {
|
||||
|
|
@ -477,7 +490,11 @@ nm_ip4_config_create_setting (const NMIP4Config *config)
|
|||
/* Use 'disabled' if the method wasn't previously set */
|
||||
if (!method)
|
||||
method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED;
|
||||
g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, method, NULL);
|
||||
|
||||
g_object_set (s_ip4,
|
||||
NM_SETTING_IP_CONFIG_METHOD, method,
|
||||
NM_SETTING_IP_CONFIG_ROUTE_METRIC, (gint64) route_metric,
|
||||
NULL);
|
||||
|
||||
/* Routes */
|
||||
for (i = 0; i < nroutes; i++) {
|
||||
|
|
@ -526,11 +543,15 @@ nm_ip4_config_create_setting (const NMIP4Config *config)
|
|||
void
|
||||
nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src)
|
||||
{
|
||||
NMIP4ConfigPrivate *dst_priv, *src_priv;
|
||||
guint32 i;
|
||||
|
||||
g_return_if_fail (src != NULL);
|
||||
g_return_if_fail (dst != NULL);
|
||||
|
||||
dst_priv = NM_IP4_CONFIG_GET_PRIVATE (dst);
|
||||
src_priv = NM_IP4_CONFIG_GET_PRIVATE (src);
|
||||
|
||||
g_object_freeze_notify (G_OBJECT (dst));
|
||||
|
||||
/* addresses */
|
||||
|
|
@ -549,6 +570,11 @@ nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src)
|
|||
for (i = 0; i < nm_ip4_config_get_num_routes (src); i++)
|
||||
nm_ip4_config_add_route (dst, nm_ip4_config_get_route (src, i));
|
||||
|
||||
if (dst_priv->route_metric == -1)
|
||||
dst_priv->route_metric = src_priv->route_metric;
|
||||
else
|
||||
dst_priv->route_metric = MIN (dst_priv->route_metric, src_priv->route_metric);
|
||||
|
||||
/* domains */
|
||||
for (i = 0; i < nm_ip4_config_get_num_domains (src); i++)
|
||||
nm_ip4_config_add_domain (dst, nm_ip4_config_get_domain (src, i));
|
||||
|
|
@ -749,6 +775,8 @@ nm_ip4_config_subtract (NMIP4Config *dst, const NMIP4Config *src)
|
|||
if (!nm_ip4_config_get_num_addresses (dst))
|
||||
nm_ip4_config_set_gateway (dst, 0);
|
||||
|
||||
/* ignore route_metric */
|
||||
|
||||
/* routes */
|
||||
for (i = 0; i < nm_ip4_config_get_num_routes (src); i++) {
|
||||
idx = _routes_get_index (dst, nm_ip4_config_get_route (src, i));
|
||||
|
|
@ -825,6 +853,7 @@ nm_ip4_config_intersect (NMIP4Config *dst, const NMIP4Config *src)
|
|||
i++;
|
||||
}
|
||||
|
||||
/* ignore route_metric */
|
||||
/* ignore nameservers */
|
||||
|
||||
/* default gateway */
|
||||
|
|
@ -908,6 +937,11 @@ nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relev
|
|||
has_relevant_changes = TRUE;
|
||||
}
|
||||
|
||||
if (src_priv->route_metric != dst_priv->route_metric) {
|
||||
dst_priv->route_metric = src_priv->route_metric;
|
||||
has_minor_changes = TRUE;
|
||||
}
|
||||
|
||||
/* addresses */
|
||||
num = nm_ip4_config_get_num_addresses (src);
|
||||
are_equal = num == nm_ip4_config_get_num_addresses (dst);
|
||||
|
|
@ -1213,6 +1247,14 @@ nm_ip4_config_get_gateway (const NMIP4Config *config)
|
|||
return priv->gateway;
|
||||
}
|
||||
|
||||
gint64
|
||||
nm_ip4_config_get_route_metric (const NMIP4Config *config)
|
||||
{
|
||||
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
||||
|
||||
return priv->route_metric;
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
void
|
||||
|
|
@ -1983,6 +2025,7 @@ nm_ip4_config_init (NMIP4Config *config)
|
|||
priv->dns_options = g_ptr_array_new_with_free_func (g_free);
|
||||
priv->nis = g_array_new (FALSE, TRUE, sizeof (guint32));
|
||||
priv->wins = g_array_new (FALSE, TRUE, sizeof (guint32));
|
||||
priv->route_metric = -1;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ void nm_ip4_config_set_never_default (NMIP4Config *config, gboolean never_defaul
|
|||
gboolean nm_ip4_config_get_never_default (const NMIP4Config *config);
|
||||
void nm_ip4_config_set_gateway (NMIP4Config *config, guint32 gateway);
|
||||
guint32 nm_ip4_config_get_gateway (const NMIP4Config *config);
|
||||
gint64 nm_ip4_config_get_route_metric (const NMIP4Config *config);
|
||||
|
||||
/* Addresses */
|
||||
void nm_ip4_config_reset_addresses (NMIP4Config *config);
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ typedef struct {
|
|||
GPtrArray *dns_options;
|
||||
guint32 mss;
|
||||
int ifindex;
|
||||
gint64 route_metric;
|
||||
} NMIP6ConfigPrivate;
|
||||
|
||||
|
||||
|
|
@ -360,6 +361,10 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co
|
|||
}
|
||||
}
|
||||
|
||||
/* we detect the route metric based on the default route. All non-default
|
||||
* routes have their route metrics explicitly set. */
|
||||
priv->route_metric = has_gateway ? (gint64) lowest_metric : (gint64) -1;
|
||||
|
||||
/* If there is a host route to the gateway, ignore that route. It is
|
||||
* automatically added by NetworkManager when needed.
|
||||
*/
|
||||
|
|
@ -441,6 +446,7 @@ nm_ip6_config_commit (const NMIP6Config *config, int ifindex)
|
|||
void
|
||||
nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIPConfig *setting, guint32 default_route_metric)
|
||||
{
|
||||
NMIP6ConfigPrivate *priv;
|
||||
guint naddresses, nroutes, nnameservers, nsearches;
|
||||
const char *gateway_str;
|
||||
int i;
|
||||
|
|
@ -450,6 +456,8 @@ nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIPConfig *setting, gu
|
|||
|
||||
g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
|
||||
|
||||
priv = NM_IP6_CONFIG_GET_PRIVATE (config);
|
||||
|
||||
naddresses = nm_setting_ip_config_get_num_addresses (setting);
|
||||
nroutes = nm_setting_ip_config_get_num_routes (setting);
|
||||
nnameservers = nm_setting_ip_config_get_num_dns (setting);
|
||||
|
|
@ -470,6 +478,9 @@ nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIPConfig *setting, gu
|
|||
nm_ip6_config_set_gateway (config, &gateway);
|
||||
}
|
||||
|
||||
if (priv->route_metric == -1)
|
||||
priv->route_metric = nm_setting_ip_config_get_route_metric (setting);
|
||||
|
||||
/* Addresses */
|
||||
for (i = 0; i < naddresses; i++) {
|
||||
NMIPAddress *s_addr = nm_setting_ip_config_get_address (setting, i);
|
||||
|
|
@ -539,6 +550,7 @@ nm_ip6_config_create_setting (const NMIP6Config *config)
|
|||
guint naddresses, nroutes, nnameservers, nsearches, noptions;
|
||||
const char *method = NULL;
|
||||
int i;
|
||||
gint64 route_metric;
|
||||
|
||||
s_ip6 = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new ());
|
||||
|
||||
|
|
@ -555,6 +567,7 @@ nm_ip6_config_create_setting (const NMIP6Config *config)
|
|||
nnameservers = nm_ip6_config_get_num_nameservers (config);
|
||||
nsearches = nm_ip6_config_get_num_searches (config);
|
||||
noptions = nm_ip6_config_get_num_dns_options (config);
|
||||
route_metric = nm_ip6_config_get_route_metric (config);
|
||||
|
||||
/* Addresses */
|
||||
for (i = 0; i < naddresses; i++) {
|
||||
|
|
@ -594,7 +607,11 @@ nm_ip6_config_create_setting (const NMIP6Config *config)
|
|||
/* Use 'ignore' if the method wasn't previously set */
|
||||
if (!method)
|
||||
method = NM_SETTING_IP6_CONFIG_METHOD_IGNORE;
|
||||
g_object_set (s_ip6, NM_SETTING_IP_CONFIG_METHOD, method, NULL);
|
||||
|
||||
g_object_set (s_ip6,
|
||||
NM_SETTING_IP_CONFIG_METHOD, method,
|
||||
NM_SETTING_IP_CONFIG_ROUTE_METRIC, (gint64) route_metric,
|
||||
NULL);
|
||||
|
||||
/* Routes */
|
||||
for (i = 0; i < nroutes; i++) {
|
||||
|
|
@ -647,11 +664,15 @@ nm_ip6_config_create_setting (const NMIP6Config *config)
|
|||
void
|
||||
nm_ip6_config_merge (NMIP6Config *dst, const NMIP6Config *src)
|
||||
{
|
||||
NMIP6ConfigPrivate *dst_priv, *src_priv;
|
||||
guint32 i;
|
||||
|
||||
g_return_if_fail (src != NULL);
|
||||
g_return_if_fail (dst != NULL);
|
||||
|
||||
dst_priv = NM_IP6_CONFIG_GET_PRIVATE (dst);
|
||||
src_priv = NM_IP6_CONFIG_GET_PRIVATE (src);
|
||||
|
||||
g_object_freeze_notify (G_OBJECT (dst));
|
||||
|
||||
/* addresses */
|
||||
|
|
@ -670,6 +691,11 @@ nm_ip6_config_merge (NMIP6Config *dst, const NMIP6Config *src)
|
|||
for (i = 0; i < nm_ip6_config_get_num_routes (src); i++)
|
||||
nm_ip6_config_add_route (dst, nm_ip6_config_get_route (src, i));
|
||||
|
||||
if (dst_priv->route_metric == -1)
|
||||
dst_priv->route_metric = src_priv->route_metric;
|
||||
else
|
||||
dst_priv->route_metric = MIN (dst_priv->route_metric, src_priv->route_metric);
|
||||
|
||||
/* domains */
|
||||
for (i = 0; i < nm_ip6_config_get_num_domains (src); i++)
|
||||
nm_ip6_config_add_domain (dst, nm_ip6_config_get_domain (src, i));
|
||||
|
|
@ -841,6 +867,8 @@ nm_ip6_config_subtract (NMIP6Config *dst, const NMIP6Config *src)
|
|||
if (!nm_ip6_config_get_num_addresses (dst))
|
||||
nm_ip6_config_set_gateway (dst, NULL);
|
||||
|
||||
/* ignore route_metric */
|
||||
|
||||
/* routes */
|
||||
for (i = 0; i < nm_ip6_config_get_num_routes (src); i++) {
|
||||
idx = _routes_get_index (dst, nm_ip6_config_get_route (src, i));
|
||||
|
|
@ -896,6 +924,7 @@ nm_ip6_config_intersect (NMIP6Config *dst, const NMIP6Config *src)
|
|||
i++;
|
||||
}
|
||||
|
||||
/* ignore route_metric */
|
||||
/* ignore nameservers */
|
||||
|
||||
/* default gateway */
|
||||
|
|
@ -981,6 +1010,11 @@ nm_ip6_config_replace (NMIP6Config *dst, const NMIP6Config *src, gboolean *relev
|
|||
has_relevant_changes = TRUE;
|
||||
}
|
||||
|
||||
if (src_priv->route_metric != dst_priv->route_metric) {
|
||||
dst_priv->route_metric = src_priv->route_metric;
|
||||
has_minor_changes = TRUE;
|
||||
}
|
||||
|
||||
/* addresses */
|
||||
num = nm_ip6_config_get_num_addresses (src);
|
||||
are_equal = num == nm_ip6_config_get_num_addresses (dst);
|
||||
|
|
@ -1214,6 +1248,14 @@ nm_ip6_config_get_gateway (const NMIP6Config *config)
|
|||
return IN6_IS_ADDR_UNSPECIFIED (&priv->gateway) ? NULL : &priv->gateway;
|
||||
}
|
||||
|
||||
gint64
|
||||
nm_ip6_config_get_route_metric (const NMIP6Config *config)
|
||||
{
|
||||
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
|
||||
|
||||
return priv->route_metric;
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
void
|
||||
|
|
@ -1841,6 +1883,7 @@ nm_ip6_config_init (NMIP6Config *config)
|
|||
priv->domains = g_ptr_array_new_with_free_func (g_free);
|
||||
priv->searches = g_ptr_array_new_with_free_func (g_free);
|
||||
priv->dns_options = g_ptr_array_new_with_free_func (g_free);
|
||||
priv->route_metric = -1;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ void nm_ip6_config_set_never_default (NMIP6Config *config, gboolean never_defaul
|
|||
gboolean nm_ip6_config_get_never_default (const NMIP6Config *config);
|
||||
void nm_ip6_config_set_gateway (NMIP6Config *config, const struct in6_addr *);
|
||||
const struct in6_addr *nm_ip6_config_get_gateway (const NMIP6Config *config);
|
||||
gint64 nm_ip6_config_get_route_metric (const NMIP6Config *config);
|
||||
|
||||
/* Addresses */
|
||||
void nm_ip6_config_reset_addresses (NMIP6Config *config);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue