Commit 8f07b3ac authored by Beniamino Galvani's avatar Beniamino Galvani

ip-config: add @intersect_routes argument to intersect functions

In some cases we want to intersect two IP configurations without
considering routes.
parent 46ed7561
......@@ -12602,7 +12602,9 @@ nm_device_get_firmware_missing (NMDevice *self)
}
static void
intersect_ext_config (NMDevice *self, AppliedConfig *config)
intersect_ext_config (NMDevice *self,
AppliedConfig *config,
gboolean intersect_routes)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMIPConfig *ext;
......@@ -12619,10 +12621,11 @@ intersect_ext_config (NMDevice *self, AppliedConfig *config)
: (NMIPConfig *) priv->ext_ip_config_6;
if (config->current)
nm_ip_config_intersect (config->current, ext, penalty);
nm_ip_config_intersect (config->current, ext, intersect_routes, penalty);
else {
config->current = nm_ip_config_intersect_alloc (config->orig,
ext,
intersect_routes,
penalty);
}
}
......@@ -12654,14 +12657,15 @@ update_ext_ip_config (NMDevice *self, int addr_family, gboolean intersect_config
* by the user. */
if (priv->con_ip_config_4) {
nm_ip4_config_intersect (priv->con_ip_config_4, priv->ext_ip_config_4,
TRUE,
default_route_metric_penalty_get (self, AF_INET));
}
intersect_ext_config (self, &priv->dev_ip4_config);
intersect_ext_config (self, &priv->wwan_ip_config_4);
intersect_ext_config (self, &priv->dev_ip4_config, TRUE);
intersect_ext_config (self, &priv->wwan_ip_config_4, TRUE);
for (iter = priv->vpn_configs_4; iter; iter = iter->next)
nm_ip4_config_intersect (iter->data, priv->ext_ip_config_4, 0);
nm_ip4_config_intersect (iter->data, priv->ext_ip_config_4, TRUE, 0);
}
/* Remove parts from ext_ip_config_4 to only contain the information that
......@@ -12705,15 +12709,16 @@ update_ext_ip_config (NMDevice *self, int addr_family, gboolean intersect_config
* by the user. */
if (priv->con_ip_config_6) {
nm_ip6_config_intersect (priv->con_ip_config_6, priv->ext_ip_config_6,
TRUE,
default_route_metric_penalty_get (self, AF_INET6));
}
intersect_ext_config (self, &priv->ac_ip6_config);
intersect_ext_config (self, &priv->dhcp6.ip6_config);
intersect_ext_config (self, &priv->wwan_ip_config_6);
intersect_ext_config (self, &priv->ac_ip6_config, TRUE);
intersect_ext_config (self, &priv->dhcp6.ip6_config, TRUE);
intersect_ext_config (self, &priv->wwan_ip_config_6, TRUE);
for (iter = priv->vpn_configs_6; iter; iter = iter->next)
nm_ip6_config_intersect (iter->data, priv->ext_ip_config_6, 0);
nm_ip6_config_intersect (iter->data, priv->ext_ip_config_6, TRUE, 0);
if ( priv->ipv6ll_has
&& !nm_ip6_config_lookup_address (priv->ext_ip_config_6, &priv->ipv6ll_addr))
......
......@@ -1511,6 +1511,7 @@ nm_ip4_config_subtract (NMIP4Config *dst,
static gboolean
_nm_ip4_config_intersect_helper (NMIP4Config *dst,
const NMIP4Config *src,
gboolean intersect_routes,
guint32 default_route_metric_penalty,
gboolean update_dst)
{
......@@ -1555,6 +1556,9 @@ _nm_ip4_config_intersect_helper (NMIP4Config *dst,
/* ignore nameservers */
/* routes */
if (!intersect_routes)
goto skip_routes;
changed = FALSE;
new_best_default_route = NULL;
nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, dst, &r) {
......@@ -1595,6 +1599,7 @@ _nm_ip4_config_intersect_helper (NMIP4Config *dst,
_notify (dst, PROP_GATEWAY);
}
skip_routes:
if (changed) {
_notify_routes (dst);
result = TRUE;
......@@ -1625,9 +1630,10 @@ _nm_ip4_config_intersect_helper (NMIP4Config *dst,
void
nm_ip4_config_intersect (NMIP4Config *dst,
const NMIP4Config *src,
gboolean intersect_routes,
guint32 default_route_metric_penalty)
{
_nm_ip4_config_intersect_helper (dst, src, default_route_metric_penalty, TRUE);
_nm_ip4_config_intersect_helper (dst, src, intersect_routes, default_route_metric_penalty, TRUE);
}
/**
......@@ -1648,14 +1654,17 @@ nm_ip4_config_intersect (NMIP4Config *dst,
NMIP4Config *
nm_ip4_config_intersect_alloc (const NMIP4Config *a,
const NMIP4Config *b,
gboolean intersect_routes,
guint32 default_route_metric_penalty)
{
NMIP4Config *a_copy;
if (_nm_ip4_config_intersect_helper ((NMIP4Config *) a, b,
intersect_routes,
default_route_metric_penalty, FALSE)) {
a_copy = nm_ip4_config_clone (a);
_nm_ip4_config_intersect_helper (a_copy, b, default_route_metric_penalty, TRUE);
_nm_ip4_config_intersect_helper (a_copy, b, intersect_routes,
default_route_metric_penalty, TRUE);
return a_copy;
} else
return NULL;
......
......@@ -189,9 +189,11 @@ void nm_ip4_config_subtract (NMIP4Config *dst,
guint32 default_route_metric_penalty);
void nm_ip4_config_intersect (NMIP4Config *dst,
const NMIP4Config *src,
gboolean intersect_routes,
guint32 default_route_metric_penalty);
NMIP4Config *nm_ip4_config_intersect_alloc (const NMIP4Config *a,
const NMIP4Config *b,
gboolean intersect_routes,
guint32 default_route_metric_penalty);
gboolean nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relevant_changes);
......@@ -541,11 +543,13 @@ nm_ip_config_best_default_route_get (const NMIPConfig *self)
static inline void
nm_ip_config_intersect (NMIPConfig *dst,
const NMIPConfig *src,
gboolean intersect_routes,
guint32 default_route_metric_penalty)
{
_NM_IP_CONFIG_DISPATCH_SET_OP (, dst, src,
nm_ip4_config_intersect,
nm_ip6_config_intersect,
intersect_routes,
default_route_metric_penalty);
}
......@@ -587,18 +591,21 @@ nm_ip_config_replace (NMIPConfig *dst,
static inline NMIPConfig *
nm_ip_config_intersect_alloc (const NMIPConfig *a,
const NMIPConfig *b,
gboolean intersect_routes,
guint32 default_route_metric_penalty)
{
if (NM_IS_IP4_CONFIG (a)) {
nm_assert (NM_IS_IP4_CONFIG (b));
return (NMIPConfig *) nm_ip4_config_intersect_alloc ((const NMIP4Config *) a,
(const NMIP4Config *) b,
intersect_routes,
default_route_metric_penalty);
} else {
nm_assert (NM_IS_IP6_CONFIG (a));
nm_assert (NM_IS_IP6_CONFIG (b));
return (NMIPConfig *) nm_ip6_config_intersect_alloc ((const NMIP6Config *) a,
(const NMIP6Config *) b,
intersect_routes,
default_route_metric_penalty);
}
}
......
......@@ -1084,6 +1084,7 @@ nm_ip6_config_subtract (NMIP6Config *dst,
static gboolean
_nm_ip6_config_intersect_helper (NMIP6Config *dst,
const NMIP6Config *src,
gboolean intersect_routes,
guint32 default_route_metric_penalty,
gboolean update_dst)
{
......@@ -1128,6 +1129,9 @@ _nm_ip6_config_intersect_helper (NMIP6Config *dst,
/* ignore nameservers */
/* routes */
if (!intersect_routes)
goto skip_routes;
changed = FALSE;
new_best_default_route = NULL;
nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, dst, &r) {
......@@ -1172,6 +1176,7 @@ _nm_ip6_config_intersect_helper (NMIP6Config *dst,
result = TRUE;
}
skip_routes:
/* ignore domains */
/* ignore dns searches */
/* ignore dns options */
......@@ -1194,9 +1199,10 @@ _nm_ip6_config_intersect_helper (NMIP6Config *dst,
void
nm_ip6_config_intersect (NMIP6Config *dst,
const NMIP6Config *src,
gboolean intersect_routes,
guint32 default_route_metric_penalty)
{
_nm_ip6_config_intersect_helper (dst, src, default_route_metric_penalty, TRUE);
_nm_ip6_config_intersect_helper (dst, src, intersect_routes, default_route_metric_penalty, TRUE);
}
/**
......@@ -1217,14 +1223,17 @@ nm_ip6_config_intersect (NMIP6Config *dst,
NMIP6Config *
nm_ip6_config_intersect_alloc (const NMIP6Config *a,
const NMIP6Config *b,
gboolean intersect_routes,
guint32 default_route_metric_penalty)
{
NMIP6Config *a_copy;
if (_nm_ip6_config_intersect_helper ((NMIP6Config *) a, b,
intersect_routes,
default_route_metric_penalty, FALSE)) {
a_copy = nm_ip6_config_clone (a);
_nm_ip6_config_intersect_helper (a_copy, b, default_route_metric_penalty, TRUE);
_nm_ip6_config_intersect_helper (a_copy, b, intersect_routes,
default_route_metric_penalty, TRUE);
return a_copy;
} else
return NULL;
......
......@@ -130,9 +130,11 @@ void nm_ip6_config_subtract (NMIP6Config *dst,
guint32 default_route_metric_penalty);
void nm_ip6_config_intersect (NMIP6Config *dst,
const NMIP6Config *src,
gboolean intersect_routes,
guint32 default_route_metric_penalty);
NMIP6Config *nm_ip6_config_intersect_alloc (const NMIP6Config *a,
const NMIP6Config *b,
gboolean intersect_routes,
guint32 default_route_metric_penalty);
gboolean nm_ip6_config_replace (NMIP6Config *dst, const NMIP6Config *src, gboolean *relevant_changes);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment