Commit 52711b5d authored by Lubomir Rintel's avatar Lubomir Rintel 🥕

ip6-config: keep track of ifindex

No functional change, a cosmetic thing for now.

We want it set before any routes are added and ensure routes have a valid
ifindex before we pass it to the platform.

In a future NMRouteManager will need to look up the route for a device in
its cache thus we'll need to make sure routes passed to the it have an
appropriate ifindex set.
parent 747292a4
......@@ -2877,6 +2877,7 @@ ensure_con_ipx_config (NMDevice *self)
priv->con_ip6_config = nm_ip6_config_new ();
nm_ip4_config_set_ifindex (priv->con_ip4_config, nm_device_get_ifindex (self));
nm_ip6_config_set_ifindex (priv->con_ip6_config, nm_device_get_ifindex (self));
nm_ip4_config_merge_setting (priv->con_ip4_config,
nm_connection_get_setting_ip4_config (connection),
......@@ -3525,8 +3526,10 @@ ip6_config_merge_and_apply (NMDevice *self,
/* If no config was passed in, create a new one */
composite = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (composite, nm_device_get_ifindex (self));
ensure_con_ipx_config (self);
g_assert (composite);
/* Merge all the IP configs into the composite config */
if (priv->ac_ip6_config)
......@@ -4113,8 +4116,10 @@ rdisc_config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed, NMDevice *self)
g_return_if_fail (priv->act_request);
if (!priv->ac_ip6_config)
if (!priv->ac_ip6_config) {
priv->ac_ip6_config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (priv->ac_ip6_config, nm_device_get_ifindex (self));
}
if (changed & NM_RDISC_CONFIG_GATEWAYS) {
/* Use the first gateway as ordered in router discovery cache. */
......@@ -4619,6 +4624,7 @@ act_stage3_ip6_config_start (NMDevice *self,
if (ret == NM_ACT_STAGE_RETURN_SUCCESS) {
/* New blank config; LL address is already in priv->ext_ip6_config */
*out_config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (*out_config, nm_device_get_ifindex (self));
g_assert (*out_config);
}
} else if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0) {
......@@ -4631,6 +4637,7 @@ act_stage3_ip6_config_start (NMDevice *self,
} else if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0) {
/* New blank config */
*out_config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (*out_config, nm_device_get_ifindex (self));
g_assert (*out_config);
ret = NM_ACT_STAGE_RETURN_SUCCESS;
......
......@@ -198,8 +198,10 @@ modem_ip6_config_result (NMModem *modem,
/* Re-enable IPv6 on the interface */
nm_device_ipv6_sysctl_set (device, "disable_ipv6", "0");
if (config)
if (config) {
nm_ip6_config_set_ifindex (config, nm_device_get_ifindex (device));
nm_device_set_wwan_ip6_config (device, config);
}
if (do_slaac == FALSE) {
if (got_config)
......
......@@ -758,7 +758,8 @@ nm_dhcp_client_handle_event (gpointer unused,
g_warn_if_fail (g_hash_table_size (str_options));
if (g_hash_table_size (str_options)) {
if (priv->ipv6) {
ip_config = (GObject *) nm_dhcp_utils_ip6_config_from_options (priv->iface,
ip_config = (GObject *) nm_dhcp_utils_ip6_config_from_options (priv->ifindex,
priv->iface,
str_options,
priv->priority,
priv->info_only);
......
......@@ -593,7 +593,8 @@ ip6_add_domain_search (gpointer data, gpointer user_data)
}
NMIP6Config *
nm_dhcp_utils_ip6_config_from_options (const char *iface,
nm_dhcp_utils_ip6_config_from_options (int ifindex,
const char *iface,
GHashTable *options,
guint32 priority,
gboolean info_only)
......@@ -618,6 +619,7 @@ nm_dhcp_utils_ip6_config_from_options (const char *iface,
}
ip6_config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (ip6_config, ifindex);
str = g_hash_table_lookup (options, "max_life");
if (str) {
......
......@@ -29,7 +29,8 @@ NMIP4Config *nm_dhcp_utils_ip4_config_from_options (int ifindex,
GHashTable *options,
guint priority);
NMIP6Config *nm_dhcp_utils_ip6_config_from_options (const char *iface,
NMIP6Config *nm_dhcp_utils_ip6_config_from_options (int ifindex,
const char *iface,
GHashTable *options,
guint priority,
gboolean info_only);
......
......@@ -137,6 +137,7 @@ rdisc_config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed, gpointer user_da
}
ip6_config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (ip6_config, ifindex);
if (changed & NM_RDISC_CONFIG_GATEWAYS) {
/* Use the first gateway as ordered in router discovery cache. */
......@@ -232,6 +233,7 @@ rdisc_config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed, gpointer user_da
if (last_config) {
g_object_unref (last_config);
last_config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (last_config, ifindex);
nm_ip6_config_replace (last_config, ip6_config, NULL);
}
}
......
......@@ -50,6 +50,7 @@ typedef struct {
GPtrArray *domains;
GPtrArray *searches;
guint32 mss;
int ifindex;
} NMIP6ConfigPrivate;
......@@ -98,6 +99,17 @@ nm_ip6_config_get_dbus_path (const NMIP6Config *config)
/******************************************************************/
void
nm_ip6_config_set_ifindex (NMIP6Config *config, int ifindex)
{
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
g_return_if_fail (priv->ifindex == 0);
g_assert (priv->routes->len == 0);
priv->ifindex = ifindex;
}
static gboolean
same_prefix (const struct in6_addr *address1, const struct in6_addr *address2, int plen)
{
......@@ -304,6 +316,7 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co
config = nm_ip6_config_new ();
priv = NM_IP6_CONFIG_GET_PRIVATE (config);
nm_ip6_config_set_ifindex (config, ifindex);
g_array_unref (priv->addresses);
g_array_unref (priv->routes);
......@@ -889,6 +902,12 @@ nm_ip6_config_replace (NMIP6Config *dst, const NMIP6Config *src, gboolean *relev
g_object_freeze_notify (G_OBJECT (dst));
/* ifindex */
if (src_priv->ifindex != dst_priv->ifindex) {
nm_ip6_config_set_ifindex (dst, src_priv->ifindex);
has_minor_changes = TRUE;
}
/* never_default */
if (src_priv->never_default != dst_priv->never_default) {
dst_priv->never_default = src_priv->never_default;
......@@ -1260,6 +1279,7 @@ nm_ip6_config_add_route (NMIP6Config *config, const NMPlatformIP6Route *new)
g_return_if_fail (new != NULL);
g_return_if_fail (new->plen > 0);
g_assert (priv->ifindex);
for (i = 0; i < priv->routes->len; i++ ) {
NMPlatformIP6Route *item = &g_array_index (priv->routes, NMPlatformIP6Route, i);
......@@ -1276,6 +1296,7 @@ nm_ip6_config_add_route (NMIP6Config *config, const NMPlatformIP6Route *new)
}
g_array_append_val (priv->routes, *new);
g_array_index (priv->routes, NMPlatformIP6Route, priv->routes->len - 1).ifindex = priv->ifindex;
NOTIFY:
_NOTIFY (config, PROP_ROUTE_DATA);
_NOTIFY (config, PROP_ROUTES);
......
......@@ -58,6 +58,8 @@ GType nm_ip6_config_get_type (void);
NMIP6Config * nm_ip6_config_new (void);
void nm_ip6_config_set_ifindex (NMIP6Config *config, int ifindex);
/* D-Bus integration */
void nm_ip6_config_export (NMIP6Config *config);
const char * nm_ip6_config_get_dbus_path (const NMIP6Config *config);
......
......@@ -548,6 +548,7 @@ impl_ppp_manager_set_ip4_config (NMPPPManager *manager,
config = nm_ip4_config_new ();
nm_ip4_config_set_ifindex (config, nm_platform_link_get_ifindex (priv->ip_iface));
memset (&address, 0, sizeof (address));
address.plen = 32;
......@@ -652,6 +653,7 @@ impl_ppp_manager_set_ip6_config (NMPPPManager *manager,
remove_timeout_handler (manager);
config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (config, nm_platform_link_get_ifindex (priv->ip_iface));
memset (&addr, 0, sizeof (addr));
addr.plen = 64;
......
......@@ -37,6 +37,7 @@ build_test_config (void)
/* Build up the config to subtract */
config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (config, 1);
nm_ip6_config_add_address (config, nmtst_platform_ip6_address ("abcd:1234:4321::cdde", "1:2:3:4::5", 64));
nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2"));
......@@ -130,7 +131,9 @@ test_compare_with_source (void)
NMPlatformIP6Route route;
a = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (a, 1);
b = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (b, 2);
/* Address */
addr = *nmtst_platform_ip6_address ("1122:3344:5566::7788", NULL, 64);
......@@ -163,6 +166,7 @@ test_add_address_with_source (void)
const NMPlatformIP6Address *test_addr;
a = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (a, 1);
/* Test that a higher priority source is not overwritten */
addr = *nmtst_platform_ip6_address ("1122:3344:5566::7788", NULL, 64);
......@@ -203,6 +207,7 @@ test_add_route_with_source (void)
const NMPlatformIP6Route *test_route;
a = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (a, 1);
/* Test that a higher priority source is not overwritten */
route = *nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2");
......
......@@ -897,8 +897,10 @@ apply_parent_device_config (NMVpnConnection *connection)
vpn4_parent_config = nm_ip4_config_new ();
nm_ip4_config_set_ifindex (vpn4_parent_config, priv->ip_ifindex);
}
if (priv->ip6_config)
if (priv->ip6_config) {
vpn6_parent_config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (vpn6_parent_config, priv->ip_ifindex);
}
if (priv->ip_ifindex <= 0) {
/* If the VPN didn't return a network interface, it is a route-based
......@@ -1339,6 +1341,7 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy,
}
config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (config, priv->ip_ifindex);
memset (&address, 0, sizeof (address));
address.plen = 128;
......
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