3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 23:09:34 +01:00

netconfig: Cache the IPv6 l_rtnl_address object

For symmetry with netconfig->v4_address add a netconfig->v6_address
so that we can track what the current address is at any time.
This commit is contained in:
Andrew Zaborowski 2021-10-21 10:50:31 +02:00 committed by Denis Kenzior
parent d702e037c0
commit 927a3dc322

View File

@ -58,6 +58,7 @@ struct netconfig {
uint8_t rtm_protocol; uint8_t rtm_protocol;
uint8_t rtm_v6_protocol; uint8_t rtm_v6_protocol;
struct l_rtnl_address *v4_address; struct l_rtnl_address *v4_address;
struct l_rtnl_address *v6_address;
char **dns4_overrides; char **dns4_overrides;
char **dns6_overrides; char **dns6_overrides;
char *mdns; char *mdns;
@ -131,6 +132,8 @@ static void netconfig_free_settings(struct netconfig *netconfig)
{ {
l_rtnl_address_free(netconfig->v4_address); l_rtnl_address_free(netconfig->v4_address);
netconfig->v4_address = NULL; netconfig->v4_address = NULL;
l_rtnl_address_free(netconfig->v6_address);
netconfig->v6_address = NULL;
l_strfreev(netconfig->dns4_overrides); l_strfreev(netconfig->dns4_overrides);
netconfig->dns4_overrides = NULL; netconfig->dns4_overrides = NULL;
@ -1031,13 +1034,28 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,
case L_DHCP6_CLIENT_EVENT_IP_CHANGED: case L_DHCP6_CLIENT_EVENT_IP_CHANGED:
case L_DHCP6_CLIENT_EVENT_LEASE_OBTAINED: case L_DHCP6_CLIENT_EVENT_LEASE_OBTAINED:
case L_DHCP6_CLIENT_EVENT_LEASE_RENEWED: case L_DHCP6_CLIENT_EVENT_LEASE_RENEWED:
{
const struct l_dhcp6_lease *lease =
l_dhcp6_client_get_lease(netconfig->dhcp6_client);
_auto_(l_free) char *addr_str =
l_dhcp6_lease_get_address(lease);
struct l_rtnl_address *address;
address = l_rtnl_address_new(addr_str,
l_dhcp6_lease_get_prefix_length(lease));
l_rtnl_address_free(netconfig->v6_address);
netconfig->v6_address = address;
netconfig_set_dns(netconfig); netconfig_set_dns(netconfig);
netconfig_set_domains(netconfig); netconfig_set_domains(netconfig);
break; break;
}
case L_DHCP6_CLIENT_EVENT_LEASE_EXPIRED: case L_DHCP6_CLIENT_EVENT_LEASE_EXPIRED:
l_debug("Lease for interface %u expired", netconfig->ifindex); l_debug("Lease for interface %u expired", netconfig->ifindex);
netconfig_set_dns(netconfig); netconfig_set_dns(netconfig);
netconfig_set_domains(netconfig); netconfig_set_domains(netconfig);
l_rtnl_address_free(netconfig->v6_address);
netconfig->v6_address = NULL;
/* Fall through */ /* Fall through */
case L_DHCP6_CLIENT_EVENT_NO_LEASE: case L_DHCP6_CLIENT_EVENT_NO_LEASE:
@ -1187,7 +1205,6 @@ static bool netconfig_ipv4_select_and_install(struct netconfig *netconfig)
static bool netconfig_ipv6_select_and_install(struct netconfig *netconfig) static bool netconfig_ipv6_select_and_install(struct netconfig *netconfig)
{ {
struct netdev *netdev = netdev_find(netconfig->ifindex); struct netdev *netdev = netdev_find(netconfig->ifindex);
struct l_rtnl_address *address = NULL;
if (netconfig->rtm_v6_protocol == RTPROT_UNSPEC) { if (netconfig->rtm_v6_protocol == RTPROT_UNSPEC) {
l_debug("IPV6 configuration disabled"); l_debug("IPV6 configuration disabled");
@ -1196,10 +1213,7 @@ static bool netconfig_ipv6_select_and_install(struct netconfig *netconfig)
sysfs_write_ipv6_setting(netdev_get_name(netdev), "disable_ipv6", "0"); sysfs_write_ipv6_setting(netdev_get_name(netdev), "disable_ipv6", "0");
if (netconfig->rtm_v6_protocol == RTPROT_STATIC) if (netconfig->rtm_v6_protocol == RTPROT_DHCP &&
address = netconfig_get_static6_address(
netconfig->active_settings);
else if (netconfig->rtm_v6_protocol == RTPROT_DHCP &&
netconfig->fils_override && netconfig->fils_override &&
!l_memeqzero(netconfig->fils_override->ipv6_addr, 16)) { !l_memeqzero(netconfig->fils_override->ipv6_addr, 16)) {
uint8_t prefix_len = netconfig->fils_override->ipv6_prefix_len; uint8_t prefix_len = netconfig->fils_override->ipv6_prefix_len;
@ -1209,11 +1223,12 @@ static bool netconfig_ipv6_select_and_install(struct netconfig *netconfig)
if (unlikely(!addr_str)) if (unlikely(!addr_str))
return false; return false;
if (L_WARN_ON(unlikely(!(address = l_rtnl_address_new(addr_str, netconfig->v6_address = l_rtnl_address_new(addr_str,
prefix_len))))) prefix_len);
if (L_WARN_ON(unlikely(!netconfig->v6_address)))
return false; return false;
l_rtnl_address_set_noprefixroute(address, true); l_rtnl_address_set_noprefixroute(netconfig->v6_address, true);
/* /*
* TODO: If netconfig->fils_override->ipv6_lifetime is set, * TODO: If netconfig->fils_override->ipv6_lifetime is set,
@ -1223,12 +1238,12 @@ static bool netconfig_ipv6_select_and_install(struct netconfig *netconfig)
*/ */
} }
if (address) { if (netconfig->v6_address) {
L_WARN_ON(!(netconfig->addr6_add_cmd_id = L_WARN_ON(!(netconfig->addr6_add_cmd_id =
l_rtnl_ifaddr_add(rtnl, netconfig->ifindex, address, l_rtnl_ifaddr_add(rtnl, netconfig->ifindex,
netconfig->v6_address,
netconfig_ipv6_ifaddr_add_cmd_cb, netconfig_ipv6_ifaddr_add_cmd_cb,
netconfig, NULL))); netconfig, NULL)));
l_rtnl_address_free(address);
return true; return true;
} }
@ -1345,7 +1360,6 @@ bool netconfig_load_settings(struct netconfig *netconfig,
if (l_settings_has_key(active_settings, "IPv6", "Address")) { if (l_settings_has_key(active_settings, "IPv6", "Address")) {
v6_address = netconfig_get_static6_address(active_settings); v6_address = netconfig_get_static6_address(active_settings);
l_rtnl_address_free(v6_address);
if (unlikely(!v6_address)) { if (unlikely(!v6_address)) {
l_error("netconfig: Can't parse IPv6 address"); l_error("netconfig: Can't parse IPv6 address");
@ -1371,6 +1385,9 @@ bool netconfig_load_settings(struct netconfig *netconfig,
if (netconfig->rtm_protocol == RTPROT_STATIC) if (netconfig->rtm_protocol == RTPROT_STATIC)
netconfig->v4_address = v4_address; netconfig->v4_address = v4_address;
if (netconfig->rtm_v6_protocol == RTPROT_STATIC)
netconfig->v6_address = v6_address;
netconfig->active_settings = active_settings; netconfig->active_settings = active_settings;
netconfig->dns4_overrides = dns4_overrides; netconfig->dns4_overrides = dns4_overrides;
netconfig->dns6_overrides = dns6_overrides; netconfig->dns6_overrides = dns6_overrides;
@ -1457,6 +1474,9 @@ bool netconfig_reset(struct netconfig *netconfig)
netconfig_reset_v4(netconfig); netconfig_reset_v4(netconfig);
if (netconfig->rtm_v6_protocol) { if (netconfig->rtm_v6_protocol) {
l_rtnl_address_free(netconfig->v6_address);
netconfig->v6_address = NULL;
l_strfreev(netconfig->dns6_overrides); l_strfreev(netconfig->dns6_overrides);
netconfig->dns6_overrides = NULL; netconfig->dns6_overrides = NULL;