netconfig: Track the IPv6 route add netlink command
Andrew Zaborowski
PATCH 1/8 netconfig: Track the IPv6 route add netlink command
For symmetry with IPv4, save the command id for this netlink command so we can later add logic to the callback as well as be able to cancel the command. No functional change in this commit alone.
--- src/netconfig.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-)
src/netconfig.c +27 -4
@@ -74,6 +74,7 @@ struct netconfig {uint32_t addr4_add_cmd_id;uint32_t addr6_add_cmd_id;uint32_t route4_add_gateway_cmd_id; +uint32_t route6_add_cmd_id; };static struct l_netlink *rtnl;
@@ -739,6 +740,21 @@ static void netconfig_route_add_cmd_cb(int error, uint16_t type, netconfig->notify =NULL ; } +static void netconfig_route6_add_cb (int error,uint16_t type, +const void *data,uint32_t len, +void *user_data) +{ +struct netconfig *netconfig = user_data; + + netconfig->route6_add_cmd_id =0 ; + +if (error) { +l_error ("netconfig: Failed to add route. Error %d: %s" , + error,strerror (-error)); +return ; + } +} +static bool netconfig_ipv4_routes_install (struct netconfig *netconfig) { L_AUTO_FREE_VAR(char *, gateway) = NULL;
@@ -859,10 +875,12 @@ static void netconfig_ipv6_ifaddr_add_cmd_cb(int error, uint16_t type, gateway =netconfig_get_static6_gateway (netconfig, &gateway_mac); if (gateway) { - L_WARN_ON(!l_rtnl_route_add(rtnl, netconfig->ifindex, - gateway, - netconfig_route_generic_cb, - netconfig, NULL)); + netconfig->route6_add_cmd_id = l_rtnl_route_add(rtnl, + netconfig->ifindex, + gateway, + netconfig_route6_add_cb, + netconfig, NULL); + L_WARN_ON(unlikely(!netconfig->route6_add_cmd_id)); l_rtnl_route_free(gateway); if (gateway_mac && !l_rtnl_neighbor_set_hwaddr(rtnl,
@@ -1360,6 +1378,11 @@ bool netconfig_reset(struct netconfig *netconfig) netconfig->route4_add_gateway_cmd_id =0 ; } +if (netconfig->route6_add_cmd_id) { +l_netlink_cancel (rtnl, netconfig->route6_add_cmd_id); + netconfig->route6_add_cmd_id =0 ; + } +if (netconfig->addr4_add_cmd_id) {l_netlink_cancel (rtnl, netconfig->addr4_add_cmd_id); netconfig->addr4_add_cmd_id =0 ;
Signature · 1 line
2.30.2
Andrew Zaborowski
PATCH 2/8 netconfig: Cache the IPv6 l_rtnl_address object
For symmetry with IPv4 and to make it easier to track changes to the IPv6 address and netmask in future commits, add a netconfig->v6_address treated in the same way as the existing netconfig->v4_address.
--- src/netconfig.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-)
src/netconfig.c +32 -14
@@ -58,6 +58,7 @@ struct netconfig {uint8_t rtm_protocol;uint8_t rtm_v6_protocol;struct l_rtnl_address *v4_address; +struct l_rtnl_address *v6_address;char **dns4_overrides;char **dns6_overrides;struct ie_fils_ip_addr_response_info *fils_override;
@@ -983,13 +984,28 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,case L_DHCP6_CLIENT_EVENT_IP_CHANGED :case L_DHCP6_CLIENT_EVENT_LEASE_OBTAINED :case L_DHCP6_CLIENT_EVENT_LEASE_RENEWED : + { +__auto_type lease = +l_dhcp6_client_get_lease (netconfig->dhcp6_client); + L_AUTO_FREE_VAR(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_domains (netconfig);break ; + }case L_DHCP6_CLIENT_EVENT_LEASE_EXPIRED :l_debug ("Lease for interface %u expired" , netconfig->ifindex);netconfig_set_dns (netconfig);netconfig_set_domains (netconfig); +l_rtnl_address_free (netconfig->v6_address); + netconfig->v6_address =NULL ;/* Fall through */ case L_DHCP6_CLIENT_EVENT_NO_LEASE :
@@ -1135,7 +1151,6 @@ static bool netconfig_ipv4_select_and_install(struct netconfig *netconfig)static bool netconfig_ipv6_select_and_install (struct netconfig *netconfig) {struct netdev *netdev =netdev_find (netconfig->ifindex); -struct l_rtnl_address *address =NULL ;if (netconfig->rtm_v6_protocol ==RTPROT_UNSPEC ) {l_debug ("IPV6 configuration disabled" );
@@ -1144,10 +1159,7 @@ static bool netconfig_ipv6_select_and_install(struct netconfig *netconfig)sysfs_write_ipv6_setting (netdev_get_name (netdev),"disable_ipv6" ,"0" ); -if (netconfig->rtm_v6_protocol ==RTPROT_STATIC ) - address =netconfig_get_static6_address ( - netconfig->active_settings); -else if (netconfig->rtm_v6_protocol ==RTPROT_DHCP && +if (netconfig->rtm_v6_protocol ==RTPROT_DHCP && netconfig->fils_override && !l_memeqzero (netconfig->fils_override->ipv6_addr,16 )) {uint8_t prefix_len = netconfig->fils_override->ipv6_prefix_len;
@@ -1157,11 +1169,12 @@ static bool netconfig_ipv6_select_and_install(struct netconfig *netconfig)if (unlikely (!addr_str))return false; -if (L_WARN_ON (unlikely (!(address =l_rtnl_address_new (addr_str, - prefix_len))))) + netconfig->v6_address =l_rtnl_address_new (addr_str, + prefix_len); +if (L_WARN_ON (unlikely (!netconfig->v6_address)))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,
@@ -1171,12 +1184,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_rtnl_ifaddr_add (rtnl, netconfig->ifindex, address, +l_rtnl_ifaddr_add (rtnl, netconfig->ifindex, + netconfig->v6_address, netconfig_ipv6_ifaddr_add_cmd_cb, netconfig,NULL ))); -l_rtnl_address_free (address);return true; }
@@ -1291,7 +1304,6 @@ bool netconfig_load_settings(struct netconfig *netconfig,if (l_settings_has_key (active_settings,"IPv6" ,"Address" )) { v6_address =netconfig_get_static6_address (active_settings); -l_rtnl_address_free (v6_address);if (unlikely (!v6_address)) {l_error ("netconfig: Can't parse IPv6 address" );
@@ -1309,11 +1321,14 @@ bool netconfig_load_settings(struct netconfig *netconfig,if (!v6_enabled) netconfig->rtm_v6_protocol =RTPROT_UNSPEC ; -else if (v6_address) +else if (v6_address) { + netconfig->v6_address =l_steal_ptr (v6_address); netconfig->rtm_v6_protocol =RTPROT_STATIC ; -else + }else netconfig->rtm_v6_protocol =RTPROT_DHCP ; +l_rtnl_address_free (v6_address); +if (send_hostname)l_dhcp_client_set_hostname (netconfig->dhcp_client, hostname);
@@ -1399,6 +1414,9 @@ bool netconfig_reset(struct netconfig *netconfig)netconfig_reset_v4 (netconfig);if (netconfig->rtm_v6_protocol) { +l_rtnl_address_free (netconfig->v6_address); + netconfig->v6_address =NULL ; +l_strfreev (netconfig->dns6_overrides); netconfig->dns6_overrides =NULL ;
Signature · 1 line
2.30.2
Denis Kenzior
Re: [PATCH 2/8] netconfig: Cache the IPv6 l_rtnl_address object
Hi Andrew,
Quoted 20 lines · Andrew Zaborowski
For symmetry with IPv4 and to make it easier to track changes to the IPv6 address and netmask in future commits, add a
netconfig->v6_addresstreated in the same way as the existingnetconfig->v4_address.--- src/netconfig.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-)src/netconfig.c +1
-0@@ -58,6 +58,7 @@ struct netconfig {uint8_t rtm_protocol;uint8_t rtm_v6_protocol;struct l_rtnl_address *v4_address; +struct l_rtnl_address *v6_address;char **dns4_overrides;char **dns6_overrides;struct ie_fils_ip_addr_response_info *fils_override;
src/netconfig.c static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client, · line 989
Quoted 6 lines
src/netconfig.c +3
-0@@ -983,13 +984,28 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,case L_DHCP6_CLIENT_EVENT_IP_CHANGED :case L_DHCP6_CLIENT_EVENT_LEASE_OBTAINED :case L_DHCP6_CLIENT_EVENT_LEASE_RENEWED : + { +__auto_type lease = +l_dhcp6_client_get_lease (netconfig->dhcp6_client);
Please no. It is fine to use __auto_type in macros where they're out of sight, but we shouldn't use this in the general case.
src/netconfig.c static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client, · line 991
Quoted 2 lines
src/netconfig.c +2
-0+ L_AUTO_FREE_VAR(char *, addr_str) = +l_dhcp6_lease_get_address (lease);
_auto_ would be preferred and shorter.
Quoted 20 lines
src/netconfig.c +10
-0+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_domains (netconfig);break ; + }case L_DHCP6_CLIENT_EVENT_LEASE_EXPIRED :l_debug ("Lease for interface %u expired" , netconfig->ifindex);netconfig_set_dns (netconfig);netconfig_set_domains (netconfig); +l_rtnl_address_free (netconfig->v6_address); + netconfig->v6_address =NULL ;/* Fall through */ case L_DHCP6_CLIENT_EVENT_NO_LEASE :
<snip>
src/netconfig.c bool netconfig_load_settings(struct netconfig *netconfig, · line 1294
Quoted 5 lines
src/netconfig.c +0
-1@@ -1291,7 +1304,6 @@ bool netconfig_load_settings(struct netconfig *netconfig,if (l_settings_has_key (active_settings,"IPv6" ,"Address" )) { v6_address =netconfig_get_static6_address (active_settings); -l_rtnl_address_free (v6_address);
Ugh. Can we just make v6_address use _auto_. The current upstream code is bonkers right now.
src/netconfig.c bool netconfig_load_settings(struct netconfig *netconfig, · line 1325
Quoted 10 lines
src/netconfig.c +2
-1if (unlikely (!v6_address)) {l_error ("netconfig: Can't parse IPv6 address" );@@ -1309,11 +1321,14 @@ bool netconfig_load_settings(struct netconfig *netconfig,if (!v6_enabled) netconfig->rtm_v6_protocol =RTPROT_UNSPEC ; -else if (v6_address) +else if (v6_address) { + netconfig->v6_address =l_steal_ptr (v6_address);
If the intent behind netconfig_load_settings to do more than validate the settings, then you should make sure you're not leaking anything.
Before you started refactoring the API, the semantics were quite clear:
netconfig_configure() --> Apply settingsnetconfig_reset() -> Tear down
ad228461abbf ("netconfig: Move loading settings to new method, refactor") does not mention anything about changing the API semantics of this method, and for the most part it didn't. I think only problem area is v4_address handling.
If you want to change the API semantics, then you need to explicitly call that
out. netconfig_load_settings() should either be safely callable multiple
times, or introduce a new API that would tear down anything that netconfig_load_settings did.
src/netconfig.c bool netconfig_load_settings(struct netconfig *netconfig, · line 1334
Quoted 10 lines
src/netconfig.c +3
-1netconfig->rtm_v6_protocol =RTPROT_STATIC ; - else + }else netconfig->rtm_v6_protocol =RTPROT_DHCP ; +l_rtnl_address_free (v6_address); +if (send_hostname)l_dhcp_client_set_hostname (netconfig->dhcp_client, hostname);
Regards,
-Denis
Andrew Zaborowski
PATCH 3/8 netconfig: Set netconfig_get_static6_gateway out param on success
In reply to Andrew ZaborowskiMake sure to only set the netconfig_get_static6_gateway's out_mac parameter on successful return and make sure to always set it, even if to NULL.
--- src/netconfig.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
src/netconfig.c +4 -2
@@ -498,6 +498,7 @@ static struct l_rtnl_route *netconfig_get_static6_gateway( { L_AUTO_FREE_VAR(char *, gateway);struct l_rtnl_route *ret; +const uint8_t *mac =NULL ; gateway =l_settings_get_string (netconfig->active_settings,"IPv6" ,"Gateway" );
@@ -509,7 +510,7 @@ static struct l_rtnl_route *netconfig_get_static6_gateway( netconfig->fils_override->ipv6_gateway);if (!l_memeqzero (netconfig->fils_override->ipv6_gateway_mac,6 )) - *out_mac = netconfig->fils_override->ipv6_gateway_mac; + mac = netconfig->fils_override->ipv6_gateway_mac; }else if (!gateway)return NULL ;
@@ -523,6 +524,7 @@ static struct l_rtnl_route *netconfig_get_static6_gateway(l_rtnl_route_set_priority (ret,ROUTE_PRIORITY_OFFSET );l_rtnl_route_set_protocol (ret,RTPROT_STATIC ); + *out_mac = mac;return ret; }
@@ -864,7 +866,7 @@ static void netconfig_ipv6_ifaddr_add_cmd_cb(int error, uint16_t type, {struct netconfig *netconfig = user_data;struct l_rtnl_route *gateway; -const uint8_t *gateway_mac =NULL ; +const uint8_t *gateway_mac; netconfig->addr6_add_cmd_id =0 ;
Signature · 1 line
2.30.2
Denis Kenzior
AppliedRe: [PATCH 3/8] netconfig: Set netconfig_get_static6_gateway out param on success
Hi Andrew,
Quoted 7 lines · Andrew Zaborowski
Make sure to only set the netconfig_get_static6_gateway's
out_macparameter on successful return and make sure to always set it, even if to NULL.--- src/netconfig.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Applied, thanks.
Regards,
-Denis
Andrew Zaborowski
PATCH 4/8 netconfig: Track gateway address strings
In reply to Andrew ZaborowskiCache the latest v4 and v6 gateway IP string in struct netconfig state to be able to more easily detect changes in those values in future commits and perhaps to simplify the ..._routes_install functions. netconfig_ipv4_get_gateway's out_mac parameter can now be NULL. While editing that function fix a small formatting annoyance.
--- src/netconfig.c | 63 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 12 deletions(-)
src/netconfig.c +51 -12
@@ -62,6 +62,8 @@ struct netconfig {char **dns4_overrides;char **dns6_overrides;struct ie_fils_ip_addr_response_info *fils_override; +char *v4_gateway_str; +char *v6_gateway_str;const struct l_settings *active_settings;
@@ -419,6 +421,8 @@ static char *netconfig_ipv4_get_gateway(struct netconfig *netconfig, {const struct l_dhcp_lease *lease;char *gateway; +const struct ie_fils_ip_addr_response_info *fils = + netconfig->fils_override;switch (netconfig->rtm_protocol) {case RTPROT_STATIC :
@@ -432,15 +436,12 @@ static char *netconfig_ipv4_get_gateway(struct netconfig *netconfig,return gateway;case RTPROT_DHCP : -if (netconfig->fils_override && - netconfig->fils_override->ipv4_gateway) { - gateway =netconfig_ipv4_to_string ( - netconfig->fils_override->ipv4_gateway); +if (fils && fils->ipv4_gateway) { + gateway =netconfig_ipv4_to_string (fils->ipv4_gateway); -if (gateway && !l_memeqzero (netconfig->fils_override-> - ipv4_gateway_mac,6 )) - *out_mac = netconfig->fils_override-> - ipv4_gateway_mac; +if (gateway && out_mac && + !l_memeqzero (fils->ipv4_gateway_mac,6 )) + *out_mac = fils->ipv4_gateway_mac;return gateway; }
@@ -478,7 +479,7 @@ static struct l_rtnl_address *netconfig_get_static6_address( prefix_len =strtoul (p,NULL ,10 );if (!unlikely (errno ==EINVAL || errno ==ERANGE || !prefix_len || prefix_len >128 )) { -l_error ("netconfig: Invalid prefix '%s' provided in network" +l_error ("netconfig: Invalid prefix '%s' provided in network" " configuration file" , p);return NULL ; }
@@ -494,6 +495,7 @@ no_prefix_len:static struct l_rtnl_route *netconfig_get_static6_gateway (struct netconfig *netconfig, +char **out_str,const uint8_t **out_mac) { L_AUTO_FREE_VAR(char *, gateway);
@@ -524,6 +526,7 @@ static struct l_rtnl_route *netconfig_get_static6_gateway(l_rtnl_route_set_priority (ret,ROUTE_PRIORITY_OFFSET );l_rtnl_route_set_protocol (ret,RTPROT_STATIC ); + *out_str =l_steal_ptr (gateway); *out_mac = mac;return ret;
@@ -876,7 +879,9 @@ static void netconfig_ipv6_ifaddr_add_cmd_cb(int error, uint16_t type,return ; } - gateway =netconfig_get_static6_gateway (netconfig, &gateway_mac); + gateway =netconfig_get_static6_gateway (netconfig, + &netconfig->v6_gateway_str, + &gateway_mac);if (gateway) { netconfig->route6_add_cmd_id = l_rtnl_route_add(rtnl, netconfig->ifindex,
@@ -933,10 +938,24 @@ static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client, netconfig->v4_address, netconfig_ifaddr_del_cmd_cb, netconfig, NULL)); -l_rtnl_address_free (netconfig->v4_address);/* Fall through. */ case L_DHCP_CLIENT_EVENT_LEASE_OBTAINED : - netconfig->v4_address =netconfig_get_dhcp4_address (netconfig); + { +char *gateway_str; +struct l_rtnl_address *address; + + gateway_str =netconfig_ipv4_get_gateway (netconfig,NULL ); +if (l_streq0 (netconfig->v4_gateway_str, gateway_str)) +l_free (gateway_str); +else { +l_free (netconfig->v4_gateway_str); + netconfig->v4_gateway_str = gateway_str; + } + + address =netconfig_get_dhcp4_address (netconfig); +l_rtnl_address_free (netconfig->v4_address); + netconfig->v4_address = address; +if (!netconfig->v4_address) {l_error ("netconfig: Failed to obtain IP addresses from " "DHCPv4 lease." );
@@ -949,6 +968,7 @@ static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client, netconfig_ipv4_ifaddr_add_cmd_cb, netconfig, NULL)));break ; + }case L_DHCP_CLIENT_EVENT_LEASE_RENEWED :break ;case L_DHCP_CLIENT_EVENT_LEASE_EXPIRED :
@@ -958,6 +978,7 @@ static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client, netconfig, NULL));l_rtnl_address_free (netconfig->v4_address); netconfig->v4_address =NULL ; +l_free (l_steal_ptr (netconfig->v4_gateway_str));/* Fall through. */ case L_DHCP_CLIENT_EVENT_NO_LEASE :
@@ -992,6 +1013,17 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client, L_AUTO_FREE_VAR(char *, addr_str) =l_dhcp6_lease_get_address (lease);struct l_rtnl_address *address; +__auto_type icmp6 = +l_dhcp6_client_get_icmp6 (netconfig->dhcp6_client); +__auto_type router =l_icmp6_client_get_router (icmp6); +char *gateway_str =l_icmp6_router_get_address (router); + +if (l_streq0 (netconfig->v6_gateway_str, gateway_str)) +l_free (gateway_str); +else { +l_free (netconfig->v6_gateway_str); + netconfig->v6_gateway_str = gateway_str; + } address =l_rtnl_address_new (addr_str,l_dhcp6_lease_get_prefix_length (lease));
@@ -1008,6 +1040,7 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,netconfig_set_domains (netconfig);l_rtnl_address_free (netconfig->v6_address); netconfig->v6_address =NULL ; +l_free (l_steal_ptr (netconfig->v6_gateway_str));/* Fall through */ case L_DHCP6_CLIENT_EVENT_NO_LEASE :
@@ -1044,6 +1077,9 @@ static void netconfig_reset_v4(struct netconfig *netconfig)l_acd_destroy (netconfig->acd); netconfig->acd =NULL ; + +l_free (netconfig->v4_gateway_str); + netconfig->v4_gateway_str =NULL ; } }
@@ -1427,6 +1463,9 @@ bool netconfig_reset(struct netconfig *netconfig)sysfs_write_ipv6_setting (netdev_get_name (netdev),"disable_ipv6" ,"1" ); + +l_free (netconfig->v6_gateway_str); + netconfig->v6_gateway_str =NULL ; }l_free (l_steal_ptr (netconfig->fils_override));
Signature · 1 line
2.30.2
Andrew Zaborowski
PATCH 5/8 netconfig: Track DNS address string lists
In reply to Andrew ZaborowskiCache the latest v4 and v6 DNS IP string lists in struct netconfig state to be able to more easily detect changes in those values in future commits. For that split netconfig_set_dns's code into this function, which now only commit the values in netconfig->dns{4,6}_list to the resolver, and netconfig_dns_list_update() which figures out the active DNS IP address list and saves it in netconfig->dns{4,6} list. This probably saves some cycles as the callers can now decide to only recalculate the dns_list which may have changed.
While there simplify netconfig_set_dns return type to void as the result was always 0 anyway and was never checked by callers.
--- src/netconfig.c | 99 +++++++++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 41 deletions(-)
src/netconfig.c +58 -41
@@ -61,6 +61,8 @@ struct netconfig {struct l_rtnl_address *v6_address;char **dns4_overrides;char **dns6_overrides; +char **dns4_list; +char **dns6_list;struct ie_fils_ip_addr_response_info *fils_override;char *v4_gateway_str;char *v6_gateway_str;
@@ -261,52 +263,59 @@ static void netconfig_set_neighbor_entry_cb(int error, strerror(-error), error); } -static int netconfig_set_dns (struct netconfig *netconfig) +static void netconfig_set_dns (struct netconfig *netconfig) { -const uint8_t *fils_dns4_mac =NULL ; -const uint8_t *fils_dns6_mac =NULL ; -char **dns4_list =netconfig_get_dns_list (netconfig,AF_INET , - &fils_dns4_mac); -char **dns6_list =netconfig_get_dns_list (netconfig,AF_INET6 , - &fils_dns6_mac); -unsigned int n_entries4 =l_strv_length (dns4_list); -unsigned int n_entries6 =l_strv_length (dns6_list); -char **dns_list; -const struct ie_fils_ip_addr_response_info *fils = - netconfig->fils_override; - -if (!dns4_list && !dns6_list) -return 0 ; +if (!netconfig->dns4_list && !netconfig->dns6_list) +return ; - dns_list = dns4_list; +if (netconfig->dns4_list && netconfig->dns6_list) { +unsigned int n_entries4 =l_strv_length (netconfig->dns4_list); +unsigned int n_entries6 =l_strv_length (netconfig->dns6_list); +char **dns_list =l_malloc (sizeof (char *) * + (n_entries4 + n_entries6 +1 )); -if (dns6_list) { - dns_list =l_realloc (dns_list, -sizeof (char *) * (n_entries4 + n_entries6 +1 )); -memcpy (dns_list + n_entries4, dns6_list, +memcpy (dns_list, netconfig->dns4_list, +sizeof (char *) * n_entries4); +memcpy (dns_list + n_entries4, netconfig->dns6_list,sizeof (char *) * (n_entries6 +1 )); -/* Contents now belong to dns_list, so no l_strfreev */ -l_free (dns6_list); +resolve_set_dns (netconfig->resolve, dns_list); +l_free (dns_list); +return ; } -resolve_set_dns (netconfig->resolve, dns_list); -l_strv_free (dns_list); +resolve_set_dns (netconfig->resolve, + netconfig->dns4_list ?: netconfig->dns6_list); +} -if (fils_dns4_mac && !l_rtnl_neighbor_set_hwaddr (rtnl, - netconfig->ifindex,AF_INET , - &fils->ipv4_dns, fils_dns4_mac,6 , - netconfig_set_neighbor_entry_cb,NULL , -NULL )) -l_debug ("l_rtnl_neighbor_set_hwaddr failed" ); +static void netconfig_dns_list_update (struct netconfig *netconfig,uint8_t af) +{ +const uint8_t *fils_dns_mac =NULL ; +char ***dns_list_ptr = af ==AF_INET ? + &netconfig->dns4_list : &netconfig->dns6_list; +char **new_dns_list =netconfig_get_dns_list (netconfig, af, + &fils_dns_mac); + +if (l_strv_eq (*dns_list_ptr, new_dns_list)) { +l_strv_free (new_dns_list); +return ; + } -if (fils_dns6_mac && !l_rtnl_neighbor_set_hwaddr (rtnl, - netconfig->ifindex,AF_INET6 , - fils->ipv6_dns, fils_dns6_mac,6 , - netconfig_set_neighbor_entry_cb,NULL , -NULL )) -l_debug ("l_rtnl_neighbor_set_hwaddr failed" ); +l_strv_free (*dns_list_ptr); + *dns_list_ptr = new_dns_list; -return 0 ; +if (fils_dns_mac) { +const struct ie_fils_ip_addr_response_info *fils = + netconfig->fils_override; +const void *dns_ip = af ==AF_INET ? + (const void *) &fils->ipv4_dns : + (const void *) &fils->ipv6_dns; + +if (!l_rtnl_neighbor_set_hwaddr (rtnl, netconfig->ifindex, af, + dns_ip, fils_dns_mac,6 , + netconfig_set_neighbor_entry_cb, +NULL ,NULL )) +l_debug ("l_rtnl_neighbor_set_hwaddr failed" ); + } } static void append_domain(char **domains, unsigned int *n_domains,
@@ -962,6 +971,8 @@ static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client,return ; } +netconfig_dns_list_update (netconfig,AF_INET ); + L_WARN_ON(!(netconfig->addr4_add_cmd_id = l_rtnl_ifaddr_add(rtnl, netconfig->ifindex, netconfig->v4_address,
@@ -1030,12 +1041,14 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,l_rtnl_address_free (netconfig->v6_address); netconfig->v6_address = address; +netconfig_dns_list_update (netconfig,AF_INET6 );netconfig_set_dns (netconfig);netconfig_set_domains (netconfig);break ; }case L_DHCP6_CLIENT_EVENT_LEASE_EXPIRED :l_debug ("Lease for interface %u expired" , netconfig->ifindex); +netconfig_dns_list_update (netconfig,AF_INET6 );netconfig_set_dns (netconfig);netconfig_set_domains (netconfig);l_rtnl_address_free (netconfig->v6_address);
@@ -1069,8 +1082,8 @@ static void netconfig_reset_v4(struct netconfig *netconfig)if (netconfig->rtm_protocol) {netconfig_remove_v4_address (netconfig); -l_strfreev (netconfig->dns4_overrides); - netconfig->dns4_overrides =NULL ; +l_strv_free (l_steal_ptr (netconfig->dns4_overrides)); +l_strv_free (l_steal_ptr (netconfig->dns4_list));l_dhcp_client_stop (netconfig->dhcp_client); netconfig->rtm_protocol =0 ;
@@ -1155,6 +1168,8 @@ static bool netconfig_ipv4_select_and_install(struct netconfig *netconfig) ip)))return false; +netconfig_dns_list_update (netconfig,AF_INET ); + netconfig->acd =l_acd_new (netconfig->ifindex); l_acd_set_event_handler(netconfig->acd, netconfig_ipv4_acd_event, netconfig,
@@ -1223,6 +1238,8 @@ static bool netconfig_ipv6_select_and_install(struct netconfig *netconfig) } if (netconfig->v6_address) { + netconfig_dns_list_update(netconfig, AF_INET6); + L_WARN_ON(!(netconfig->addr6_add_cmd_id = l_rtnl_ifaddr_add(rtnl, netconfig->ifindex, netconfig->v6_address,
@@ -1455,8 +1472,8 @@ bool netconfig_reset(struct netconfig *netconfig)l_rtnl_address_free (netconfig->v6_address); netconfig->v6_address =NULL ; -l_strfreev (netconfig->dns6_overrides); - netconfig->dns6_overrides =NULL ; +l_strv_free (l_steal_ptr (netconfig->dns6_overrides)); +l_strv_free (l_steal_ptr (netconfig->dns6_list));l_dhcp6_client_stop (netconfig->dhcp6_client); netconfig->rtm_v6_protocol =0 ;
Signature · 1 line
2.30.2
Andrew Zaborowski
PATCH 6/8 netconfig: Track local domains lists
In reply to Andrew ZaborowskiCache the latest v4 and v6 domain string lists in struct netconfig state to be able to more easily detect changes in those values in future commits. For that split netconfig_set_domains's code into this function, which now only commits the values in netconfig->v{4,6}_domain{,s} to the resolver, and netconfig_domains_update() which figures out the active domains string list and saves it into netconfig->v{4,6}_domain{,s}. This probably saves some cycles as the callers can now decide to only recalculate the domains list which may have changed.
While there simplify netconfig_set_domains return type to void as the result was always 0 anyway and was never checked by callers.
--- src/netconfig.c | 86 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 27 deletions(-)
src/netconfig.c +59 -27
@@ -66,6 +66,8 @@ struct netconfig {struct ie_fils_ip_addr_response_info *fils_override;char *v4_gateway_str;char *v6_gateway_str; +char *v4_domain; +char **v6_domains;const struct l_settings *active_settings;
@@ -334,47 +336,69 @@ static void append_domain(char **domains, unsigned int *n_domains, *n_domains +=1 ; } -static int netconfig_set_domains (struct netconfig *netconfig) +static void netconfig_set_domains (struct netconfig *netconfig) {char *domains[31 ];unsigned int n_domains =0 ; -char *v4_domain =NULL ; -char **v6_domains =NULL ;char **p;memset (domains,0 ,sizeof (domains)); -/* Allow to override the DHCP domain name with setting entry. */ - v4_domain =l_settings_get_string (netconfig->active_settings, -"IPv4" ,"DomainName" ); -if (!v4_domain && netconfig->rtm_protocol ==RTPROT_DHCP ) { -const struct l_dhcp_lease *lease = -l_dhcp_client_get_lease (netconfig->dhcp_client); +append_domain (domains, &n_domains, +L_ARRAY_SIZE (domains) -1 , netconfig->v4_domain); -if (lease) - v4_domain =l_dhcp_lease_get_domain_name (lease); - } +for (p = netconfig->v6_domains; p && *p; p++) +append_domain (domains, &n_domains, +L_ARRAY_SIZE (domains) -1 , *p); -append_domain (domains, &n_domains, -L_ARRAY_SIZE (domains) -1 , v4_domain); +resolve_set_domains (netconfig->resolve, domains); +} -if (netconfig->rtm_v6_protocol ==RTPROT_DHCP ) { -const struct l_dhcp6_lease *lease = -l_dhcp6_client_get_lease (netconfig->dhcp6_client); +static void netconfig_domains_update (struct netconfig *netconfig,uint8_t af) +{ +bool changed = false; -if (lease) - v6_domains =l_dhcp6_lease_get_domains (lease); - } +if (af ==AF_INET ) { +/* Allow to override the DHCP domain name with setting entry. */ +char *v4_domain =l_settings_get_string ( + netconfig->active_settings, +"IPv4" ,"DomainName" ); -for (p = v6_domains; p && *p; p++) -append_domain (domains, &n_domains, -L_ARRAY_SIZE (domains) -1 , *p); +if (!v4_domain && netconfig->rtm_protocol ==RTPROT_DHCP ) { +const struct l_dhcp_lease *lease = +l_dhcp_client_get_lease (netconfig->dhcp_client); -resolve_set_domains (netconfig->resolve, domains); -l_strv_free (v6_domains); -l_free (v4_domain); +if (lease) + v4_domain =l_dhcp_lease_get_domain_name (lease); + } -return 0 ; +if (l_streq0 (v4_domain, netconfig->v4_domain)) +l_free (v4_domain); +else { +l_free (netconfig->v4_domain); + netconfig->v4_domain = v4_domain; + changed = true; + } + }else { +char **v6_domains =NULL ; + +if (netconfig->rtm_v6_protocol ==RTPROT_DHCP ) { +const struct l_dhcp6_lease *lease = +l_dhcp6_client_get_lease ( + netconfig->dhcp6_client); + +if (lease) + v6_domains =l_dhcp6_lease_get_domains (lease); + } + +if (l_strv_eq (netconfig->v6_domains, v6_domains)) +l_strv_free (v6_domains); +else { +l_strv_free (netconfig->v6_domains); + netconfig->v6_domains = v6_domains; + changed = true; + } + } } static struct l_rtnl_address *netconfig_get_static4_address(
@@ -972,6 +996,7 @@ static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client, }netconfig_dns_list_update (netconfig,AF_INET ); +netconfig_domains_update (netconfig,AF_INET ); L_WARN_ON(!(netconfig->addr4_add_cmd_id = l_rtnl_ifaddr_add(rtnl, netconfig->ifindex,
@@ -1042,6 +1067,7 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client, netconfig->v6_address = address;netconfig_dns_list_update (netconfig,AF_INET6 ); +netconfig_domains_update (netconfig,AF_INET6 );netconfig_set_dns (netconfig);netconfig_set_domains (netconfig);break ;
@@ -1049,6 +1075,7 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,case L_DHCP6_CLIENT_EVENT_LEASE_EXPIRED :l_debug ("Lease for interface %u expired" , netconfig->ifindex);netconfig_dns_list_update (netconfig,AF_INET6 ); +netconfig_domains_update (netconfig,AF_INET6 );netconfig_set_dns (netconfig);netconfig_set_domains (netconfig);l_rtnl_address_free (netconfig->v6_address);
@@ -1093,6 +1120,8 @@ static void netconfig_reset_v4(struct netconfig *netconfig)l_free (netconfig->v4_gateway_str); netconfig->v4_gateway_str =NULL ; + +l_free (l_steal_ptr (netconfig->v4_domain)); } }
@@ -1169,6 +1198,7 @@ static bool netconfig_ipv4_select_and_install(struct netconfig *netconfig)return false;netconfig_dns_list_update (netconfig,AF_INET ); +netconfig_domains_update (netconfig,AF_INET ); netconfig->acd =l_acd_new (netconfig->ifindex); l_acd_set_event_handler(netconfig->acd,
@@ -1483,6 +1513,8 @@ bool netconfig_reset(struct netconfig *netconfig)l_free (netconfig->v6_gateway_str); netconfig->v6_gateway_str =NULL ; + +l_strv_free (l_steal_ptr (netconfig->v6_domains)); }l_free (l_steal_ptr (netconfig->fils_override));
Signature · 1 line
2.30.2
Andrew Zaborowski
PATCH 7/8 netconfig: Add IPv4 configuration properties on Station and P2P
In reply to Andrew ZaborowskiAdd the IPv4Configuration D-Bus interface on the station and P2P objects that expose current netconfig values. Access Point and P2P-GO are not handled yet.
--- src/dbus.h | 1 + src/netconfig.c | 293 ++++++++++++++++++++++++++++++++++++++++++++++-- src/netconfig.h | 2 +- src/p2p.c | 4 +- src/station.c | 8 +- 5 files changed, 291 insertions(+), 17 deletions(-)
src/dbus.h +1 -0
@@ -43,6 +43,7 @@#define IWD_STATION_DIAGNOSTIC_INTERFACE "net.connman.iwd.StationDiagnostic"#define IWD_AP_DIAGNOSTIC_INTERFACE "net.connman.iwd.AccessPointDiagnostic"#define IWD_STATION_DEBUG_INTERFACE "net.connman.iwd.StationDebug" +#define IWD_IPV4_CONFIG_INTERFACE "net.connman.iwd.IPv4Configuration"#define IWD_BASE_PATH "/net/connman/iwd"#define IWD_AGENT_MANAGER_PATH IWD_BASE_PATH
src/netconfig.c +281 -12
422 lines not on this page · raw message
src/netconfig.h +1 -1
@@ -45,5 +45,5 @@ bool netconfig_get_fils_ip_req(struct netconfig *netconfig,void netconfig_handle_fils_ip_resp (struct netconfig *netconfig,const struct ie_fils_ip_addr_response_info *info); -struct netconfig *netconfig_new (uint32_t ifindex); +struct netconfig *netconfig_new (uint32_t ifindex,const char *dbus_path);void netconfig_destroy (struct netconfig *netconfig);
src/p2p.c +3 -1
@@ -1319,7 +1319,9 @@ static void p2p_start_client_netconfig(struct p2p_device *dev)struct l_settings *settings;if (!dev->conn_netconfig) { - dev->conn_netconfig =netconfig_new (ifindex); +const char *peer_path =p2p_peer_get_path (dev->conn_peer); + + dev->conn_netconfig =netconfig_new (ifindex, peer_path);if (!dev->conn_netconfig) {p2p_connect_failed (dev);return ;
src/station.c +5 -3
@@ -3826,6 +3826,7 @@ static struct station *station_create(struct netdev *netdev)struct station *station;struct l_dbus *dbus =dbus_get_bus ();bool autoconnect = true; +const char *path; station = l_new(struct station, 1);watchlist_init (&station->state_watches,NULL );
@@ -3843,11 +3844,12 @@ static struct station *station_create(struct netdev *netdev)l_queue_push_head (station_list, station); -l_dbus_object_add_interface (dbus,netdev_get_path (netdev), -IWD_STATION_INTERFACE , station); + path =netdev_get_path (netdev); +l_dbus_object_add_interface (dbus, path,IWD_STATION_INTERFACE , station);if (netconfig_enabled) - station->netconfig =netconfig_new (netdev_get_ifindex (netdev)); + station->netconfig =netconfig_new (netdev_get_ifindex (netdev), + path); station->anqp_pending =l_queue_new ();
Signature · 1 line
2.30.2
Andrew Zaborowski
PATCH 8/8 netconfig: Add IPv6 configuration properties on Station
In reply to Andrew ZaborowskiAdd the net.connman.iwd.IPv6Configuration D-Bus interface on the station objects to expose current netconfig values.
--- src/dbus.h | 1 + src/netconfig.c | 127 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 121 insertions(+), 7 deletions(-)
src/dbus.h +1 -0
@@ -44,6 +44,7 @@#define IWD_AP_DIAGNOSTIC_INTERFACE "net.connman.iwd.AccessPointDiagnostic"#define IWD_STATION_DEBUG_INTERFACE "net.connman.iwd.StationDebug"#define IWD_IPV4_CONFIG_INTERFACE "net.connman.iwd.IPv4Configuration" +#define IWD_IPV6_CONFIG_INTERFACE "net.connman.iwd.IPv6Configuration"#define IWD_BASE_PATH "/net/connman/iwd"#define IWD_AGENT_MANAGER_PATH IWD_BASE_PATH
src/netconfig.c +120 -7
233 lines not on this page · raw message
Signature · 1 line
2.30.2
Denis Kenzior
AppliedHi Andrew,
Quoted 7 lines · Andrew Zaborowski
For symmetry with IPv4, save the command id for this netlink command so we can later add logic to the callback as well as be able to cancel the command. No functional change in this commit alone.
--- src/netconfig.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-)
Applied, thanks.
Regards,
-Denis