netconfig: Refactor setting new values to system
Andrew Zaborowski
PATCH 1/9 netconfig: Refactor setting new values to system
Refactor and unify how the netconfig values, that we obtain from DHCP or the settings or otherwise, are written/committed to the system netdevs. We basically concentrate all of those actions in a new function netconfig_set() that is called whenever any value changes. The only exceptions are the sysfs writes and some of the ARP table writes.
This will allow us to more easily delegate committing the values to an (optional) D-Bus agent, or expose them as D-Bus properties if we ever choose to do that in the future. For that I'm also passing a bitmask telling netconfig_set() which values may have actually changed, so we don't bother looking at those that definitely haven't changed.
--- src/netconfig.c | 541 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 398 insertions(+), 143 deletions(-)
src/netconfig.c +398 -143
@@ -52,6 +52,15 @@#include "src/netconfig.h" #include "src/sysfs.h" +enum netconfig_changed_flags { +NETCONFIG_CHANGED_ADDRESS =1 <<0 , +NETCONFIG_CHANGED_NETMASK =1 <<1 , +NETCONFIG_CHANGED_GATEWAY =1 <<2 , +NETCONFIG_CHANGED_DNS =1 <<3 , +NETCONFIG_CHANGED_DOMAINS =1 <<4 , +NETCONFIG_CHANGED_ALL =0x1f , +}; +struct netconfig {uint32_t ifindex;struct l_dhcp_client *dhcp_client;
@@ -59,7 +68,9 @@ struct netconfig {uint8_t rtm_protocol;uint8_t rtm_v6_protocol;struct l_rtnl_address *v4_address; +struct l_rtnl_address *stale_v4_address;struct l_rtnl_address *v6_address; +struct l_rtnl_address *stale_v6_address;char **dns4_overrides;char **dns6_overrides;char **dns4_list;
@@ -70,6 +81,8 @@ struct netconfig {char *v6_gateway_str;char *v4_domain;char **v6_domains; +unsigned int pending_v4_set; +unsigned int pending_v6_set;const struct l_settings *active_settings;
@@ -813,10 +826,8 @@ static void netconfig_route6_add_cb(int error, uint16_t type, } } -static bool netconfig_ipv4_routes_install (struct netconfig *netconfig) +static bool netconfig_ipv4_subnet_route_install (struct netconfig *netconfig) { - L_AUTO_FREE_VAR(char *, gateway) = NULL; -const uint8_t *gateway_mac =NULL ;struct in_addr in_addr;char ip[INET_ADDRSTRLEN ];char network[INET_ADDRSTRLEN ];
@@ -839,10 +850,19 @@ static bool netconfig_ipv4_routes_install(struct netconfig *netconfig) netconfig_route_generic_cb, netconfig, NULL)) {l_error ("netconfig: Failed to add subnet route." ); -return false; } +return true; +} + +static bool netconfig_ipv4_gateway_route_install (struct netconfig *netconfig) +{ + L_AUTO_FREE_VAR(char *, gateway) = NULL; +const uint8_t *gateway_mac =NULL ; +struct in_addr in_addr; +char ip[INET_ADDRSTRLEN ]; + gateway =netconfig_ipv4_get_gateway (netconfig, &gateway_mac);if (!gateway) { l_debug("No gateway obtained from %s.",
@@ -858,6 +878,10 @@ static bool netconfig_ipv4_routes_install(struct netconfig *netconfig)return true; } +if (!l_rtnl_address_get_address (netconfig->v4_address, ip) || +inet_pton (AF_INET , ip, &in_addr) <1 ) +return false; + netconfig->route4_add_gateway_cmd_id = l_rtnl_route4_add_gateway(rtnl, netconfig->ifindex, gateway, ip, ROUTE_PRIORITY_OFFSET,
@@ -871,50 +895,77 @@ static bool netconfig_ipv4_routes_install(struct netconfig *netconfig)return false; } -if (gateway_mac) { -/* -* Attempt to use the gateway MAC address received from the AP -* by writing the mapping directly into the netdev's ARP table -* so as to save one data frame roundtrip before first IP -* connections are established. This is very low-priority but -* print error messages just because they may indicate bigger -* problems. -*/ -if (!l_rtnl_neighbor_set_hwaddr (rtnl, netconfig->ifindex, +/* +* Attempt to use the gateway MAC address received from the AP by +* writing the mapping directly into the netdev's ARP table so as +* to save one data frame roundtrip before first IP connections +* are established. This is very low-priority but print error +* messages just because they may indicate bigger problems. +*/ +if (gateway_mac && !l_rtnl_neighbor_set_hwaddr (rtnl, netconfig->ifindex,AF_INET , &netconfig->fils_override->ipv4_gateway, gateway_mac,6 , netconfig_set_neighbor_entry_cb,NULL ,NULL )) -l_debug ("l_rtnl_neighbor_set_hwaddr failed" ); +l_debug ("l_rtnl_neighbor_set_hwaddr failed" ); + +return true; +} + +static bool netconfig_ipv6_static_gateway_route_install ( +struct netconfig *netconfig) +{ + _auto_(l_rtnl_route_free) struct l_rtnl_route *gateway = NULL; +const uint8_t *gateway_mac; + + gateway =netconfig_get_static6_gateway (netconfig, + &netconfig->v6_gateway_str, + &gateway_mac); +if (!gateway) { +l_debug ("No IPv6 gateway set" ); +return true; } + netconfig->route6_add_cmd_id =l_rtnl_route_add (rtnl, + netconfig->ifindex, + gateway, + netconfig_route6_add_cb, + netconfig,NULL ); +if (!L_WARN_ON (unlikely (!netconfig->route6_add_cmd_id))) +return false; + +if (gateway_mac && !l_rtnl_neighbor_set_hwaddr (rtnl, netconfig->ifindex, +AF_INET6 , + netconfig->fils_override->ipv6_gateway, + gateway_mac,6 , + netconfig_set_neighbor_entry_cb,NULL , +NULL )) +l_debug ("l_rtnl_neighbor_set_hwaddr failed" ); +return true; } +static void netconfig_set (struct netconfig *netconfig,uint8_t af, +unsigned int changed); +static void netconfig_ipv4_ifaddr_add_cmd_cb (int error,uint16_t type,const void *data,uint32_t len,void *user_data) {struct netconfig *netconfig = user_data; +unsigned int changed = netconfig->pending_v4_set; netconfig->addr4_add_cmd_id =0 ; -if (error && error != -EEXIST ) { +if (error && error != -EEXIST )l_error ("netconfig: Failed to add IP address. " "Error %d: %s" , error,strerror (-error)); -return ; - } - -netconfig_gateway_to_arp (netconfig); - -if (!netconfig_ipv4_routes_install (netconfig)) { -l_error ("netconfig: Failed to install IPv4 routes." ); -return ; - } +else +netconfig_ipv4_subnet_route_install (netconfig); -netconfig_set_dns (netconfig); -netconfig_set_domains (netconfig); + netconfig->pending_v4_set =0 ; +netconfig_set (netconfig,AF_INET , changed); } static void netconfig_ipv6_ifaddr_add_cmd_cb(int error, uint16_t type,
@@ -922,40 +973,16 @@ static void netconfig_ipv6_ifaddr_add_cmd_cb(int error, uint16_t type, void *user_data) {struct netconfig *netconfig = user_data; -struct l_rtnl_route *gateway; -const uint8_t *gateway_mac; +unsigned int changed = netconfig->pending_v4_set; netconfig->addr6_add_cmd_id =0 ; -if (error && error != -EEXIST ) { +if (error && error != -EEXIST )l_error ("netconfig: Failed to add IPv6 address. " "Error %d: %s" , error,strerror (-error)); -return ; - } - - 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, - 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, - netconfig->ifindex,AF_INET6 , - netconfig->fils_override->ipv6_gateway, - gateway_mac,6 , - netconfig_set_neighbor_entry_cb,NULL , -NULL )) -l_debug ("l_rtnl_neighbor_set_hwaddr failed" ); - } -netconfig_set_dns (netconfig); -netconfig_set_domains (netconfig); + netconfig->pending_v6_set =0 ; +netconfig_set (netconfig,AF_INET6 , changed); } static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type,
@@ -978,21 +1005,169 @@ static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, "Error %d: %s", error, strerror(-error)); } +static bool netconfig_address_cmp_address (const struct l_rtnl_address *a, +const struct l_rtnl_address *b) +{ +char str_a[INET6_ADDRSTRLEN ]; +char str_b[INET6_ADDRSTRLEN ]; + +if (a == b) +return true; + +if (!a || !b) +return false; + +if (!l_rtnl_address_get_address (a, str_a) || + !l_rtnl_address_get_address (b, str_b)) +return false; + +return !strcmp (str_a, str_b); +} + +static bool netconfig_address_cmp_prefix_len (const struct l_rtnl_address *a, +const struct l_rtnl_address *b) +{ +if (a == b) +return true; + +if (!a || !b) +return false; + +return l_rtnl_address_get_prefix_length (a) == +l_rtnl_address_get_prefix_length (b); +} + +static void netconfig_set (struct netconfig *netconfig,uint8_t af, +unsigned int changed) +{ +struct l_rtnl_address *stale_addr; + +if (af ==AF_INET ) + stale_addr =l_steal_ptr (netconfig->stale_v4_address); +else + stale_addr =l_steal_ptr (netconfig->stale_v6_address); + +if (stale_addr) { +L_WARN_ON (!l_rtnl_ifaddr_delete (rtnl, netconfig->ifindex, + stale_addr, + netconfig_ifaddr_del_cmd_cb, + netconfig,NULL )); +l_rtnl_address_free (stale_addr); + } + +if (af ==AF_INET ) { +if (!netconfig->v4_address) +return ; + +if ((changed & (NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK )) && + !netconfig->addr4_add_cmd_id) { + netconfig->addr4_add_cmd_id =l_rtnl_ifaddr_add (rtnl, + netconfig->ifindex, + netconfig->v4_address, + netconfig_ipv4_ifaddr_add_cmd_cb, + netconfig,NULL ); +if (!L_WARN_ON (!netconfig->addr4_add_cmd_id)) + changed &= ~(NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK ); + } + +/* +* If we either started the address addition now or one was +* already in progress, wait for that operation's callback +* and we'll be called again to set the rest of the values +* in the changed bitmask. +*/ +if (netconfig->addr4_add_cmd_id) { + netconfig->pending_v4_set |= changed; +return ; + } + +/* +* For IPv6 the address, the subnet route and the gateway +* route are handled automatically for DHCP, only cover the +* static and FILS-provided cases here. +*/ + }else if (netconfig->rtm_v6_protocol ==RTPROT_STATIC || + (netconfig->fils_override && + !l_memeqzero (netconfig->fils_override->ipv6_addr, +16 ))) { +if (!netconfig->v6_address) +return ; + +if ((changed & (NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK )) && + !netconfig->addr6_add_cmd_id) { + netconfig->addr6_add_cmd_id =l_rtnl_ifaddr_add (rtnl, + netconfig->ifindex, + netconfig->v6_address, + netconfig_ipv6_ifaddr_add_cmd_cb, + netconfig,NULL ); +if (!L_WARN_ON (!netconfig->addr6_add_cmd_id)) + changed &= ~(NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK ); + } + +/* +* If we either started the address addition now or one was +* already in progress, wait for that operation's callback +* and we'll be called again to set the rest of the values +* in the changed bitmask. +*/ +if (netconfig->addr6_add_cmd_id) { + netconfig->pending_v4_set |= changed; +return ; + } + } + +if (af ==AF_INET ) { +if (changed &NETCONFIG_CHANGED_GATEWAY ) { +netconfig_gateway_to_arp (netconfig); + +if (netconfig_ipv4_gateway_route_install (netconfig)) + changed &= ~NETCONFIG_CHANGED_GATEWAY ; + }else if (netconfig->notify) { +/* +* The gateway route addition callback notifies the user +* of netconfig success if a gateway is provided, otherwise +* notify here. +*/ + netconfig->notify (NETCONFIG_EVENT_CONNECTED , + netconfig->user_data); + netconfig->notify =NULL ; + } + }else if (netconfig->rtm_v6_protocol ==RTPROT_STATIC || + (netconfig->fils_override && + !l_memeqzero (netconfig->fils_override->ipv6_gateway, +16 ))) { +if (changed & (NETCONFIG_CHANGED_GATEWAY )) +if (netconfig_ipv6_static_gateway_route_install ( + netconfig)) + changed &= ~NETCONFIG_CHANGED_GATEWAY ; + } + +if (changed &NETCONFIG_CHANGED_DNS ) { +netconfig_set_dns (netconfig); + changed &= ~NETCONFIG_CHANGED_DNS ; + } + +if (changed &NETCONFIG_CHANGED_DOMAINS ) { +netconfig_set_domains (netconfig); + changed &= ~NETCONFIG_CHANGED_DOMAINS ; + } +} +static void netconfig_ipv4_dhcp_event_handler (struct l_dhcp_client *client,enum l_dhcp_client_event event,void *userdata) {struct netconfig *netconfig = userdata; +unsigned int changed =0 ;l_debug ("DHCPv4 event %d" , event);switch (event) {case L_DHCP_CLIENT_EVENT_IP_CHANGED : -L_WARN_ON (!l_rtnl_ifaddr_delete (rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ifaddr_del_cmd_cb, - netconfig,NULL )); -/* Fall through. */ case L_DHCP_CLIENT_EVENT_LEASE_OBTAINED : {char *gateway_str;
@@ -1004,9 +1179,19 @@ static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client,else {l_free (netconfig->v4_gateway_str); netconfig->v4_gateway_str = gateway_str; + changed |=NETCONFIG_CHANGED_GATEWAY ; } address =netconfig_get_dhcp4_address (netconfig); + +if (!netconfig_address_cmp_prefix_len (netconfig->v4_address, + address)) + changed |=NETCONFIG_CHANGED_NETMASK ; + +if (!netconfig_address_cmp_address (netconfig->v4_address, + address)) + changed |=NETCONFIG_CHANGED_ADDRESS ; +l_rtnl_address_free (netconfig->v4_address); netconfig->v4_address = address;
@@ -1016,26 +1201,36 @@ static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client,return ; } -netconfig_dns_list_update (netconfig,AF_INET ); -netconfig_domains_update (netconfig,AF_INET ); +if (netconfig_dns_list_update (netconfig,AF_INET )) + changed |=NETCONFIG_CHANGED_DNS ; -L_WARN_ON (!(netconfig->addr4_add_cmd_id = -l_rtnl_ifaddr_add (rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ipv4_ifaddr_add_cmd_cb, - netconfig,NULL ))); +if (netconfig_domains_update (netconfig,AF_INET )) + changed |=NETCONFIG_CHANGED_DOMAINS ; + +netconfig_set (netconfig,AF_INET , changed);break ; }case L_DHCP_CLIENT_EVENT_LEASE_RENEWED :break ;case L_DHCP_CLIENT_EVENT_LEASE_EXPIRED : -L_WARN_ON (!l_rtnl_ifaddr_delete (rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ifaddr_del_cmd_cb, - netconfig,NULL )); -l_rtnl_address_free (netconfig->v4_address); - netconfig->v4_address =NULL ; -l_free (l_steal_ptr (netconfig->v4_gateway_str)); +l_debug ("Lease for interface %u expired" , netconfig->ifindex); + changed =NETCONFIG_CHANGED_ADDRESS |NETCONFIG_CHANGED_NETMASK ; +l_rtnl_address_free (netconfig->stale_v4_address); + netconfig->stale_v4_address = +l_steal_ptr (netconfig->v4_address); + +if (netconfig->v4_gateway_str) { + changed |=NETCONFIG_CHANGED_GATEWAY ; +l_free (l_steal_ptr (netconfig->v4_gateway_str)); + } + +if (netconfig_dns_list_update (netconfig,AF_INET )) + changed |=NETCONFIG_CHANGED_DNS ; + +if (netconfig_domains_update (netconfig,AF_INET )) + changed |=NETCONFIG_CHANGED_DOMAINS ; + +netconfig_set (netconfig,AF_INET , changed);/* Fall through. */ case L_DHCP_CLIENT_EVENT_NO_LEASE :
@@ -1059,6 +1254,7 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client, void *userdata) {struct netconfig *netconfig = userdata; +unsigned int changed =0 ;switch (event) {case L_DHCP6_CLIENT_EVENT_IP_CHANGED :
@@ -1081,28 +1277,52 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,else {l_free (netconfig->v6_gateway_str); netconfig->v6_gateway_str = gateway_str; + changed |=NETCONFIG_CHANGED_GATEWAY ; } address =l_rtnl_address_new (addr_str,l_dhcp6_lease_get_prefix_length (lease)); + +if (!netconfig_address_cmp_prefix_len (netconfig->v6_address, + address)) + changed |=NETCONFIG_CHANGED_NETMASK ; + +if (!netconfig_address_cmp_address (netconfig->v6_address, + address)) + changed |=NETCONFIG_CHANGED_ADDRESS ; +l_rtnl_address_free (netconfig->v6_address); 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); +if (netconfig_dns_list_update (netconfig,AF_INET6 )) + changed |=NETCONFIG_CHANGED_DNS ; + +if (netconfig_domains_update (netconfig,AF_INET6 )) + changed |=NETCONFIG_CHANGED_DOMAINS ; + +netconfig_set (netconfig,AF_INET6 , changed);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_domains_update (netconfig,AF_INET6 ); -netconfig_set_dns (netconfig); -netconfig_set_domains (netconfig); -l_rtnl_address_free (netconfig->v6_address); - netconfig->v6_address =NULL ; -l_free (l_steal_ptr (netconfig->v6_gateway_str)); +l_debug ("IPv6 lease for interface %u expired" , + netconfig->ifindex); + changed =NETCONFIG_CHANGED_ADDRESS |NETCONFIG_CHANGED_NETMASK ; +l_rtnl_address_free (netconfig->stale_v6_address); + netconfig->stale_v6_address = +l_steal_ptr (netconfig->v6_address); + +if (netconfig->v6_gateway_str) { + changed |=NETCONFIG_CHANGED_GATEWAY ; +l_free (l_steal_ptr (netconfig->v6_gateway_str)); + } + +if (netconfig_dns_list_update (netconfig,AF_INET6 )) + changed |=NETCONFIG_CHANGED_DNS ; + +if (netconfig_domains_update (netconfig,AF_INET6 )) + changed |=NETCONFIG_CHANGED_DOMAINS ; + +netconfig_set (netconfig,AF_INET6 , changed);/* Fall through */ case L_DHCP6_CLIENT_EVENT_NO_LEASE :
@@ -1113,50 +1333,93 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client, } } -static void netconfig_remove_v4_address (struct netconfig *netconfig) -{ -if (!netconfig->v4_address) -return ; - -L_WARN_ON (!l_rtnl_ifaddr_delete (rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ifaddr_del_cmd_cb, - netconfig,NULL )); -l_rtnl_address_free (netconfig->v4_address); - netconfig->v4_address =NULL ; -} -static void netconfig_reset_v4 (struct netconfig *netconfig) {if (netconfig->rtm_protocol) { -netconfig_remove_v4_address (netconfig); +unsigned int changed =0 ; + +if (netconfig->v4_address) + changed |=NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK ; + +l_rtnl_address_free (netconfig->stale_v4_address); + netconfig->stale_v4_address =l_steal_ptr (netconfig->v4_address); + +if (netconfig->v4_gateway_str) + changed |=NETCONFIG_CHANGED_GATEWAY ; + +l_free (l_steal_ptr (netconfig->v4_gateway_str)); + +if (netconfig->dns4_list) + changed |=NETCONFIG_CHANGED_DNS ;l_strv_free (l_steal_ptr (netconfig->dns4_overrides));l_strv_free (l_steal_ptr (netconfig->dns4_list)); +if (netconfig->v4_domain) + changed |=NETCONFIG_CHANGED_DOMAINS ; + +l_free (l_steal_ptr (netconfig->v4_domain)); + +netconfig_set (netconfig,AF_INET , changed); +l_dhcp_client_stop (netconfig->dhcp_client); netconfig->rtm_protocol =0 ;l_acd_destroy (netconfig->acd); netconfig->acd =NULL ; + } +} -l_free (l_steal_ptr (netconfig->v4_gateway_str)); +static void netconfig_reset_v6 (struct netconfig *netconfig) +{ +if (netconfig->rtm_v6_protocol) { +unsigned int changed =0 ; +struct netdev *netdev =netdev_find (netconfig->ifindex); -l_free (l_steal_ptr (netconfig->v4_domain)); +if (netconfig->v6_address) + changed |=NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK ; + +l_rtnl_address_free (netconfig->stale_v6_address); + netconfig->stale_v6_address =l_steal_ptr (netconfig->v6_address); + +if (netconfig->v6_gateway_str) + changed |=NETCONFIG_CHANGED_GATEWAY ; + +l_free (l_steal_ptr (netconfig->v6_gateway_str)); + +if (netconfig->dns6_list) + changed |=NETCONFIG_CHANGED_DNS ; + +l_strv_free (l_steal_ptr (netconfig->dns6_overrides)); +l_strv_free (l_steal_ptr (netconfig->dns6_list)); + +if (netconfig->v6_domains) + changed |=NETCONFIG_CHANGED_DOMAINS ; + +l_free (l_steal_ptr (netconfig->v6_domains)); + +netconfig_set (netconfig,AF_INET6 , changed); + +l_dhcp6_client_stop (netconfig->dhcp6_client); + netconfig->rtm_v6_protocol =0 ; + +sysfs_write_ipv6_setting (netdev_get_name (netdev), +"disable_ipv6" ,"1" ); } }static void netconfig_ipv4_acd_event (enum l_acd_event event,void *user_data) {struct netconfig *netconfig = user_data; +unsigned int changed;switch (event) {case L_ACD_EVENT_AVAILABLE : -L_WARN_ON (!(netconfig->addr4_add_cmd_id = -l_rtnl_ifaddr_add (rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ipv4_ifaddr_add_cmd_cb, - netconfig,NULL ))); + changed = netconfig->pending_v4_set; + netconfig->pending_v4_set =0 ; +netconfig_set (netconfig,AF_INET , changed);return ;case L_ACD_EVENT_CONFLICT :/*
@@ -1174,7 +1437,10 @@ static void netconfig_ipv4_acd_event(enum l_acd_event event, void *user_data)* case. */ l_error ("netconfig: statically configured address was lost" ); -netconfig_remove_v4_address (netconfig); + +l_rtnl_address_free (netconfig->stale_v4_address); + netconfig->stale_v4_address =l_steal_ptr (netconfig->v4_address); +netconfig_set (netconfig,AF_INET ,NETCONFIG_CHANGED_ALL );break ; } }
@@ -1212,6 +1478,17 @@ static bool netconfig_ipv4_select_and_install(struct netconfig *netconfig) if (set_address) { char ip[INET6_ADDRSTRLEN]; + unsigned int changed = NETCONFIG_CHANGED_ADDRESS | + NETCONFIG_CHANGED_NETMASK; + + if (netconfig->v4_gateway_str) + changed |= NETCONFIG_CHANGED_GATEWAY; + + if (netconfig_dns_list_update(netconfig, AF_INET)) + changed |= NETCONFIG_CHANGED_DNS; + + if (netconfig_domains_update(netconfig, AF_INET)) + changed |= NETCONFIG_CHANGED_DOMAINS; if (L_WARN_ON(!netconfig->v4_address || !l_rtnl_address_get_address(
@@ -1219,9 +1496,6 @@ static bool netconfig_ipv4_select_and_install(struct netconfig *netconfig) ip)))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, netconfig_ipv4_acd_event, netconfig,
@@ -1235,12 +1509,9 @@ static bool netconfig_ipv4_select_and_install(struct netconfig *netconfig)l_acd_destroy (netconfig->acd); netconfig->acd =NULL ; -L_WARN_ON (!(netconfig->addr4_add_cmd_id = -l_rtnl_ifaddr_add (rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ipv4_ifaddr_add_cmd_cb, - netconfig,NULL ))); - } +netconfig_set (netconfig,AF_INET , changed); + }else + netconfig->pending_v4_set |= changed;return true; }
@@ -1293,13 +1564,16 @@ static bool netconfig_ipv6_select_and_install(struct netconfig *netconfig) }if (netconfig->v6_address) { -netconfig_dns_list_update (netconfig,AF_INET6 ); +unsigned int changed =NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK ; -L_WARN_ON (!(netconfig->addr6_add_cmd_id = -l_rtnl_ifaddr_add (rtnl, netconfig->ifindex, - netconfig->v6_address, - netconfig_ipv6_ifaddr_add_cmd_cb, - netconfig,NULL ))); +if (netconfig->v6_gateway_str) + changed |=NETCONFIG_CHANGED_GATEWAY ; + +if (netconfig_dns_list_update (netconfig,AF_INET6 )) + changed |=NETCONFIG_CHANGED_DNS ; + +netconfig_set (netconfig,AF_INET6 , changed);return true; }
@@ -1493,8 +1767,6 @@ bool netconfig_reconfigure(struct netconfig *netconfig, bool set_arp_gw)bool netconfig_reset (struct netconfig *netconfig) { -struct netdev *netdev =netdev_find (netconfig->ifindex); -if (netconfig->route4_add_gateway_cmd_id) {l_netlink_cancel (rtnl, netconfig->route4_add_gateway_cmd_id); netconfig->route4_add_gateway_cmd_id =0 ;
@@ -1519,24 +1791,7 @@ bool netconfig_reset(struct netconfig *netconfig)resolve_revert (netconfig->resolve);netconfig_reset_v4 (netconfig); - -if (netconfig->rtm_v6_protocol) { -l_rtnl_address_free (netconfig->v6_address); - netconfig->v6_address =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 ; - -sysfs_write_ipv6_setting (netdev_get_name (netdev), -"disable_ipv6" ,"1" ); - -l_free (l_steal_ptr (netconfig->v6_gateway_str)); - -l_strv_free (l_steal_ptr (netconfig->v6_domains)); - } +netconfig_reset_v6 (netconfig);l_free (l_steal_ptr (netconfig->fils_override));
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 2/9 netconfig: Move FILS override checks to common functions
--- src/netconfig.c | 56 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 19 deletions(-)
src/netconfig.c +37 -19
@@ -189,6 +189,36 @@ static inline char *netconfig_ipv6_to_string(const uint8_t *addr)return addr_str; } +static bool netconfig_use_fils_addr (struct netconfig *netconfig,int af) +{ +if ((af ==AF_INET ? netconfig->rtm_protocol : + netconfig->rtm_v6_protocol) !=RTPROT_DHCP ) +return false; + +if (!netconfig->fils_override) +return false; + +if (af ==AF_INET ) +return !!netconfig->fils_override->ipv4_addr; + +return !l_memeqzero (netconfig->fils_override->ipv6_addr,16 ); +} + +static bool netconfig_use_fils_gateway (struct netconfig *netconfig,int af) +{ +if ((af ==AF_INET ? netconfig->rtm_protocol : + netconfig->rtm_v6_protocol) !=RTPROT_DHCP ) +return false; + +if (!netconfig->fils_override) +return false; + +if (af ==AF_INET ) +return !!netconfig->fils_override->ipv4_gateway; + +return !l_memeqzero (netconfig->fils_override->ipv6_gateway,16 ); +} +static char **netconfig_get_dns_list (struct netconfig *netconfig,int af,const uint8_t **out_dns_mac) {
@@ -472,7 +502,7 @@ static char *netconfig_ipv4_get_gateway(struct netconfig *netconfig,return gateway;case RTPROT_DHCP : -if (fils && fils->ipv4_gateway) { +if (netconfig_use_fils_gateway (netconfig,AF_INET )) { gateway =netconfig_ipv4_to_string (fils->ipv4_gateway); if (gateway && out_mac &&
@@ -540,10 +570,7 @@ static struct l_rtnl_route *netconfig_get_static6_gateway( gateway =l_settings_get_string (netconfig->active_settings,"IPv6" ,"Gateway" ); -if (!gateway && netconfig->rtm_v6_protocol ==RTPROT_DHCP && - netconfig->fils_override && - !l_memeqzero (netconfig->fils_override->ipv6_gateway, -16 )) { +if (!gateway &&netconfig_use_fils_gateway (netconfig,AF_INET6 )) { gateway =netconfig_ipv6_to_string ( netconfig->fils_override->ipv6_gateway);
@@ -711,8 +738,7 @@ static void netconfig_ifaddr_ipv6_added(struct netconfig *netconfig, ip, ifa->ifa_prefixlen);if (netconfig->rtm_v6_protocol !=RTPROT_DHCP || - (netconfig->fils_override && - !l_memeqzero (netconfig->fils_override->ipv6_addr,16 ))) +netconfig_use_fils_addr (netconfig,AF_INET6 ))return ;inet_pton (AF_INET6 , ip, &in6);
@@ -1089,9 +1115,7 @@ static void netconfig_set(struct netconfig *netconfig, uint8_t af,* static and FILS-provided cases here. */ }else if (netconfig->rtm_v6_protocol ==RTPROT_STATIC || - (netconfig->fils_override && - !l_memeqzero (netconfig->fils_override->ipv6_addr, -16 ))) { +netconfig_use_fils_addr (netconfig,AF_INET6 )) {if (!netconfig->v6_address)return ;
@@ -1137,9 +1161,7 @@ static void netconfig_set(struct netconfig *netconfig, uint8_t af, netconfig->notify =NULL ; } }else if (netconfig->rtm_v6_protocol ==RTPROT_STATIC || - (netconfig->fils_override && - !l_memeqzero (netconfig->fils_override->ipv6_gateway, -16 ))) { +netconfig_use_fils_gateway (netconfig,AF_INET6 )) {if (changed & (NETCONFIG_CHANGED_GATEWAY ))if (netconfig_ipv6_static_gateway_route_install ( netconfig))
@@ -1450,9 +1472,7 @@ static bool netconfig_ipv4_select_and_install(struct netconfig *netconfig)struct netdev *netdev =netdev_find (netconfig->ifindex);bool set_address = (netconfig->rtm_protocol ==RTPROT_STATIC ); -if (netconfig->rtm_protocol ==RTPROT_DHCP && - netconfig->fils_override && - netconfig->fils_override->ipv4_addr) { +if (netconfig_use_fils_addr (netconfig,AF_INET )) { L_AUTO_FREE_VAR(char *, addr_str) = netconfig_ipv4_to_string( netconfig->fils_override->ipv4_addr);uint8_t prefix_len = netconfig->fils_override->ipv4_prefix_len;
@@ -1538,9 +1558,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_DHCP && - netconfig->fils_override && - !l_memeqzero (netconfig->fils_override->ipv6_addr,16 )) { +if (netconfig_use_fils_addr (netconfig,AF_INET6 )) {uint8_t prefix_len = netconfig->fils_override->ipv6_prefix_len; L_AUTO_FREE_VAR(char *, addr_str) = netconfig_ipv6_to_string( netconfig->fils_override->ipv6_addr);
Signature · 1 line
2.32.0
Denis Kenzior
Re: [PATCH 2/9] netconfig: Move FILS override checks to common functions
Hi Andrew,
Quoted 4 lines · Andrew Zaborowski
--- src/netconfig.c | 56 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 19 deletions(-)
Applied (without the chunks in netconfig_set).
Regards,
-Denis
Andrew Zaborowski
PATCH 3/9 doc: Add NetworkConfigurationAgent API description
In reply to Andrew ZaborowskiDocument the new API that clients can use to get notified of new network configuration and be responsible for committing it to the netdev, the resolver, etc.
--- doc/agent-api.txt | 106 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+)
doc/agent-api.txt +106 -0
@@ -25,6 +25,48 @@ Methods void RegisterAgent(object path) [service].Failed [service].NotFound + void RegisterNetworkConfigurationAgent(object path) + + Register the agent for handling IPv4 and IPv6 + configuration setting. This method and its + corresponding unregister method are only supported + if network configuration is enabled: see + EnableNetworkConfiguration in iwd.config(5) and + NetworkConfigurationEnabled in + net.connman.iwd.Daemon.GetInfo in daemon-api.txt. + + During a station-mode, AP-mode or P2P connection, IWD + will obtain the IP configuration values for a network + interface, either automatically from a remote server + (DHCP or otherwise), generate it or read it from a + settings file. If no network configuration agent is + present, IWD immediately writes (commits) those + values to the corresponding interface, the routing + table and communicates them to the resolver. If such + agent is registered, IWD requests the agent to do + this last step. + + Connection success is not signalled until the agent + method has returned. The agent may also be invoked + during the connection lifetime whenever the IP + configuration changes and after a roam. The agent + object must have the NetworkConfigurationAgent + interface. + + Possible Errors: [service].InvalidArguments + [service].Failed + [service].AlreadyExists + [service].NotSupported + + void UnregisterNetworkConfigurationAgent(object path) + + Unregister an existing network configuration agent. + + Possible Errors: [service].InvalidArguments + [service].Failed + [service].NotFound + [service].NotAvailable + Agent hierarchy ===============
@@ -86,3 +128,67 @@ Examples Requesting a passphrase for WPA2 network RequestPassphrase("/net/connman/iwd/0/3/54657374_psk") ==> "secret123" + + +NetworkConfigurationAgent hierarchy +=================================== + +Service unique name +Interface net.connman.iwd.NetworkConfigurationAgent +Object path freely definable + +Methods void Release() [noreply] + + This method gets called when the service daemon + unregisters the agent. An agent can use it to do + cleanup tasks. There is no need to unregister the + agent, because when this method gets called it has + already been unregistered. + + void ConfigureIPv4(object device, string interface, dict config) + + This method gets called during a connection setup + when a new set of IPv4 configuration values is to + be written to a network interface. The connection + is aborted if the method call returns an error or + times out. The 'config' dictionary (a{sv}) maps + string keys to values of types defined per key. + + The following key/value pairs are used, but more + may be added in future versions. + + string Method - Indicates whether the local address + was set statically (value "static") or obtained + automatically such as through DHCP (value "auto"). + Even when the address was obtained from the remote + end some configuration bits, such as DNS addresses, + may have been overridden locally. + + string Address - Local IP address string. + + byte PrefixLength - Holds the prefix-length of the + local subnet. For IPv4 this maps to the netmask. + + string Gateway [optional] - Local subnet's gateway + address if one exists. + + array(string) DomainNameServers [optional] - Holds + the list of DNS addresses configured if any exist. + + array(string) DomainNames [optional] - Holds the + network's local domain names if any exist. + + Possible Errors: net.connman.iwd.Agent.Error.Canceled + + void ConfigureIPv6(object device, string interface, dict config) + + Same as ConfigureIPv4 above but for IPv6. + + void Cancel(object device, string interface, + string reason) [noreply] + + This method gets called to indicate that the connection + request failed before a reply was returned. The + argument will indicate why the request is being + cancelled and may be "out-of-range", "user-canceled", + "timed-out" or "shutdown".
Signature · 1 line
2.32.0
Denis Kenzior
AppliedRe: [PATCH 3/9] doc: Add NetworkConfigurationAgent API description
Hi Andrew,
Quoted 7 lines · Andrew Zaborowski
Document the new API that clients can use to get notified of new network configuration and be responsible for committing it to the netdev, the resolver, etc.
--- doc/agent-api.txt | 106 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+)
Applied, thanks.
Regards,
-Denis
Andrew Zaborowski
PATCH 4/9 agent: Implement the NetworkConfigurationAgent dbus API
In reply to Andrew Zaborowski--- src/agent.c | 337 ++++++++++++++++++++++++++++++++++++++++++++---- src/agent.h | 11 ++ src/dbus.h | 2 + src/netconfig.h | 15 +++ 4 files changed, 343 insertions(+), 22 deletions(-)
src/agent.c +315 -22
@@ -25,15 +25,22 @@#endif #include <errno.h> +#include <arpa/inet.h> #include <ell/ell.h> #include "src/dbus.h" #include "src/agent.h" #include "src/iwd.h" #include "src/module.h" +#include "src/netconfig.h" static unsigned int next_request_id =0 ; +enum agent_type { +AGENT_TYPE_SECRET , +AGENT_TYPE_NETCONFIG , +}; +enum agent_request_type {AGENT_REQUEST_TYPE_PASSPHRASE ,AGENT_REQUEST_TYPE_USER_NAME_PASSWD ,
@@ -50,6 +57,18 @@ struct agent_request {agent_request_destroy_func_t destroy; }; +/* Netconfig requests are not queued and can run in parallel */ +struct netconfig_request { +unsigned int dbus_id; +unsigned int id; +char *path; +char *ifname; +struct l_timeout *timeout; +void *user_data; +void *user_callback; +agent_request_destroy_func_t destroy; +}; +struct agent {char *owner;char *path;
@@ -58,9 +77,11 @@ struct agent {struct l_timeout *timeout;int timeout_secs;struct l_queue *requests; +enum agent_type type; }; -static struct l_queue *agents; +static struct l_queue *secret_agents; +static struct agent *netconfig_agent;/* * How long we wait for user to input things.
@@ -74,7 +95,8 @@ static unsigned int agent_timeout_input_request(void)return 120 ; } -static void send_cancel_request (void *user_data,int reason) +static void send_cancel_request (void *user_data,int reason, +const char *path,const char *ifname) {struct agent *agent = user_data;struct l_dbus_message *message;
@@ -106,7 +128,12 @@ static void send_cancel_request(void *user_data, int reason)IWD_AGENT_INTERFACE , "Cancel"); -l_dbus_message_set_arguments (message,"s" , reasonstr); +if (path) +l_dbus_message_set_arguments (message,"oss" , path, ifname, + reasonstr); +else +l_dbus_message_set_arguments (message,"s" , reasonstr); +l_dbus_message_set_no_reply (message, true);l_dbus_send (dbus_get_bus (), message);
@@ -128,6 +155,20 @@ static void agent_request_free(void *user_data)l_free (request); } +static void netconfig_request_free (void *user_data) +{ +struct netconfig_request *request = user_data; + +if (request->destroy) + request->destroy (request->user_data); + +l_timeout_remove (request->timeout); +l_dbus_cancel (dbus_get_bus (), request->dbus_id); +l_free (request->path); +l_free (request->ifname); +l_free (request); +} +static void passphrase_reply (struct l_dbus_message *reply,struct agent_request *request) {
@@ -212,7 +253,10 @@ static void agent_free(void *data)if (agent->pending_id)l_dbus_cancel (dbus_get_bus (), agent->pending_id); -l_queue_destroy (agent->requests, agent_request_free); +if (agent->type ==AGENT_TYPE_SECRET ) +l_queue_destroy (agent->requests, agent_request_free); +else +l_queue_destroy (agent->requests, netconfig_request_free);if (agent->disconnect_watch)l_dbus_remove_watch (dbus_get_bus (), agent->disconnect_watch);
@@ -230,7 +274,7 @@ static void request_timeout(struct l_timeout *timeout, void *user_data)l_dbus_cancel (dbus_get_bus (), agent->pending_id); -send_cancel_request (agent, -ETIMEDOUT ); +send_cancel_request (agent, -ETIMEDOUT ,NULL ,NULL );agent_finalize_pending (agent,NULL );
@@ -313,7 +357,8 @@ static struct agent *agent_lookup(const char *owner)if (!owner)return NULL ; -for (entry =l_queue_get_entries (agents); entry; entry = entry->next) { +for (entry =l_queue_get_entries (secret_agents); entry; + entry = entry->next) {struct agent *agent = entry->data;if (strcmp (agent->owner, owner))
@@ -332,7 +377,7 @@ static struct agent *get_agent(const char *owner)if (agent)return agent; -return l_queue_peek_head (agents); +return l_queue_peek_head (secret_agents); }/**
@@ -347,7 +392,7 @@ static struct agent *get_agent(const char *owner)* id that can be used to cancel the request. * * If @trigger is not NULL, then a reference is taken automatically. If -* agent_cancel_request is called subsequently, a dbus_aborted error is +* agent_request_cancel is called subsequently, a dbus_aborted error is * automatically generated for @trigger. Otherwise, after @callback is * called, the reference to @trigger is dropped. It is assumed that the * caller will take ownership of @trigger in the callback if needed.
@@ -456,6 +501,156 @@ unsigned int agent_request_user_password(const char *path, const char *user, callback, trigger, user_data, destroy); } +static void netconfig_data_to_dict (const struct netconfig_data *data, +struct l_dbus_message_builder *builder) +{ +const char *ip_method_str = data->method ==NETCONFIG_METHOD_STATIC ? +"static" :"auto" ; + +l_dbus_message_builder_enter_array (builder,"{sv}" ); +dbus_append_dict_basic (builder,"Method" ,'s' , ip_method_str); +dbus_append_dict_basic (builder,"Address" ,'s' , data->addr); +dbus_append_dict_basic (builder,"PrefixLength" ,'y' , &data->prefix_len); + +if (data->gateway_addr) +dbus_append_dict_basic (builder,"Gateway" ,'s' , + data->gateway_addr); + +if (data->dns) { +char **str; + +l_dbus_message_builder_enter_dict (builder,"sv" ); +l_dbus_message_builder_append_basic (builder,'s' , +"DomainNameServers" ); +l_dbus_message_builder_enter_variant (builder,"as" ); +l_dbus_message_builder_enter_array (builder,"s" ); + +for (str = data->dns; *str; str++) +l_dbus_message_builder_append_basic (builder,'s' , str); + +l_dbus_message_builder_leave_array (builder); +l_dbus_message_builder_leave_variant (builder); +l_dbus_message_builder_leave_dict (builder); + } + +if (data->domain_names) { +char **str; + +l_dbus_message_builder_enter_dict (builder,"sv" ); +l_dbus_message_builder_append_basic (builder,'s' , +"DomainNames" ); +l_dbus_message_builder_enter_variant (builder,"as" ); +l_dbus_message_builder_enter_array (builder,"s" ); + +for (str = data->domain_names; *str; str++) +l_dbus_message_builder_append_basic (builder,'s' , str); + +l_dbus_message_builder_leave_array (builder); +l_dbus_message_builder_leave_variant (builder); +l_dbus_message_builder_leave_dict (builder); + } + +l_dbus_message_builder_leave_array (builder); +} + +static void netconfig_timeout_cb (struct l_timeout *timeout,void *user_data) +{ +struct netconfig_request *request = user_data; +agent_request_netconfig_func_t user_callback = request->user_callback; + +l_debug ("path %s ifname %s" , request->path, request->ifname); + +l_queue_remove (netconfig_agent->requests, request); + +send_cancel_request (netconfig_agent, -ETIMEDOUT , + request->path, request->ifname); + +user_callback (request->id,AGENT_RESULT_FAILED , request->user_data); +netconfig_request_free (request); +} + +static void netconfig_reply_cb (struct l_dbus_message *message, +void *user_data) +{ +struct netconfig_request *request = user_data; +agent_request_netconfig_func_t user_callback = request->user_callback; +const char *error, *text; +enum agent_result result =AGENT_RESULT_OK ; + +l_debug ("path %s ifname %s" , request->path, request->ifname); + + request->dbus_id =0 ; +l_queue_remove (netconfig_agent->requests, request); + +if (l_dbus_message_get_error (message, &error, &text)) { +if (!strcmp (error,"net.connman.iwd.Agent.Error.Canceled" )) + result =AGENT_RESULT_CANCELLED ; +else + result =AGENT_RESULT_FAILED ; + }else if (!l_dbus_message_get_arguments (message,"" )) + result =AGENT_RESULT_FAILED ; + +user_callback (request->id, result, request->user_data); +netconfig_request_free (request); +} + +unsigned int agent_request_netconfig (const char *path,const char *ifname, +const struct netconfig_data *data, +agent_request_netconfig_func_t callback, +void *user_data, +agent_request_destroy_func_t destroy) +{ +struct l_dbus_message *message; +struct l_dbus_message_builder *builder; +struct netconfig_request *request; +unsigned int dbus_id; +const char *method_name; + +l_debug ("path %s ifname %s" , path, ifname); + +if (!netconfig_agent || !callback) +return 0 ; + + method_name = data->family ==AF_INET ?"ConfigureIPv4" :"ConfigureIPv6" ; + message =l_dbus_message_new_method_call (dbus_get_bus (), + netconfig_agent->owner, + netconfig_agent->path, +IWD_NETCONFIG_AGENT_INTERFACE , + method_name); + + builder =l_dbus_message_builder_new (message); +l_dbus_message_builder_append_basic (builder,'o' , path); +l_dbus_message_builder_append_basic (builder,'s' , ifname); +netconfig_data_to_dict (data, builder); +l_dbus_message_builder_finalize (builder); +l_dbus_message_builder_destroy (builder); + + request = l_new(struct netconfig_request, 1); + + dbus_id =l_dbus_send_with_reply (dbus_get_bus (), message, + netconfig_reply_cb, + request,NULL ); +if (!dbus_id) { +l_error ("l_dbus_send_with_reply failed" ); +l_dbus_message_unref (message); +l_free (request); +return 0 ; + } + + request->dbus_id = dbus_id; + request->id = ++next_request_id; + request->path =l_strdup (path); + request->ifname =l_strdup (ifname); + request->timeout =l_timeout_create (5 , netconfig_timeout_cb, + request,NULL ); + request->user_data = user_data; + request->user_callback = callback; + request->destroy = destroy; + +l_queue_push_tail (netconfig_agent->requests, request); +return request->id; +} +static bool find_request (const void *a,const void *b) {const struct agent_request *request = a;
@@ -464,13 +659,22 @@ static bool find_request(const void *a, const void *b)return request->id == id; } +static bool find_netconfig_request (const void *a,const void *b) +{ +const struct netconfig_request *request = a; +unsigned int id =L_PTR_TO_UINT (b); + +return request->id == id; +} +bool agent_request_cancel (unsigned int req_id,int reason) {struct agent_request *request =NULL ;struct agent *agent;const struct l_queue_entry *entry; -for (entry =l_queue_get_entries (agents); entry; entry = entry->next) { +for (entry =l_queue_get_entries (secret_agents); entry; + entry = entry->next) { agent = entry->data; request = l_queue_remove_if(agent->requests, find_request,
@@ -479,11 +683,27 @@ bool agent_request_cancel(unsigned int req_id, int reason)break ; } -if (!request) -return false; +if (!request) { +struct netconfig_request *nc_request; + +if (!netconfig_agent) +return false; + + nc_request =l_queue_remove_if (netconfig_agent->requests, + find_netconfig_request, +L_UINT_TO_PTR (req_id)); +if (!nc_request) +return false; + +send_cancel_request (netconfig_agent, reason, + nc_request->path, nc_request->ifname); + +netconfig_request_free (nc_request); +return true; + }if (!request->message) { -send_cancel_request (agent, reason); +send_cancel_request (agent, reason,NULL ,NULL );l_dbus_cancel (dbus_get_bus (), agent->pending_id);
@@ -511,18 +731,19 @@ static void agent_disconnect(struct l_dbus *dbus, void *user_data)if (agent->pending_id)agent_finalize_pending (agent,NULL ); -l_queue_remove (agents, agent); +l_queue_remove (secret_agents, agent);l_idle_oneshot (agent_free, agent,NULL ); } -static struct agent *agent_create (struct l_dbus *dbus,const char *name, -const char *path) +static struct agent *agent_create (struct l_dbus *dbus,enum agent_type type, +const char *name,const char *path) {struct agent *agent; agent = l_new(struct agent, 1); + agent->type = type; agent->owner =l_strdup (name); agent->path =l_strdup (path); agent->requests =l_queue_new ();
@@ -548,11 +769,12 @@ static struct l_dbus_message *agent_register(struct l_dbus *dbus,if (!l_dbus_message_get_arguments (message,"o" , &path))return dbus_error_invalid_args (message); - agent =agent_create (dbus,l_dbus_message_get_sender (message), path); + agent =agent_create (dbus,AGENT_TYPE_SECRET , +l_dbus_message_get_sender (message), path);if (!agent)return dbus_error_failed (message); -l_queue_push_tail (agents, agent); +l_queue_push_tail (secret_agents, agent);l_debug ("agent %s path %s" , agent->owner, agent->path);
@@ -575,7 +797,7 @@ static struct l_dbus_message *agent_unregister(struct l_dbus *dbus,if (!agent)return dbus_error_not_found (message); -l_queue_remove (agents, agent); +l_queue_remove (secret_agents, agent);agent_free (agent);
@@ -586,6 +808,64 @@ static struct l_dbus_message *agent_unregister(struct l_dbus *dbus,return reply; } +static struct l_dbus_message *netconfig_agent_register (struct l_dbus *dbus, +struct l_dbus_message *message, +void *user_data) +{ +struct l_dbus_message *reply; +const char *path; + +l_debug ("" ); + +if (!l_dbus_message_get_arguments (message,"o" , &path)) +return dbus_error_invalid_args (message); + +if (!netconfig_enabled ()) +return dbus_error_not_supported (message); + +if (netconfig_agent) +return dbus_error_already_exists (message); + + netconfig_agent =agent_create (dbus,AGENT_TYPE_NETCONFIG , +l_dbus_message_get_sender (message), + path); +if (!netconfig_agent) +return dbus_error_failed (message); + +l_debug ("agent %s path %s" , + netconfig_agent->owner, netconfig_agent->path); + + reply =l_dbus_message_new_method_return (message); +l_dbus_message_set_arguments (reply,"" ); +return reply; +} + +static struct l_dbus_message *netconfig_agent_unregister (struct l_dbus *dbus, +struct l_dbus_message *message, +void *user_data) +{ +struct l_dbus_message *reply; +const char *path; + +l_debug ("" ); + +if (!l_dbus_message_get_arguments (message,"o" , &path)) +return dbus_error_invalid_args (message); + +if (!netconfig_agent ||strcmp (netconfig_agent->path, path)) +return dbus_error_not_found (message); + +if (strcmp (netconfig_agent->owner,l_dbus_message_get_sender (message))) +return dbus_error_not_available (message); + +agent_free (netconfig_agent); + netconfig_agent =NULL ; + + reply =l_dbus_message_new_method_return (message); +l_dbus_message_set_arguments (reply,"" ); +return reply; +} +static void setup_agent_interface (struct l_dbus_interface *interface) { l_dbus_interface_method(interface, "RegisterAgent", 0,
@@ -594,6 +874,13 @@ static void setup_agent_interface(struct l_dbus_interface *interface)l_dbus_interface_method (interface,"UnregisterAgent" ,0 , agent_unregister,"" ,"o" ,"path" ); + +l_dbus_interface_method (interface, +"RegisterNetworkConfigurationAgent" ,0 , + netconfig_agent_register,"" ,"o" ,"path" ); +l_dbus_interface_method (interface, +"UnregisterNetworkConfigurationAgent" ,0 , + netconfig_agent_unregister,"" ,"o" ,"path" ); }static bool release_agent (void *data,void *user_data)
@@ -622,7 +909,7 @@ static int agent_init(void) { struct l_dbus *dbus = dbus_get_bus(); - agents = l_queue_new(); + secret_agents = l_queue_new(); if (!l_dbus_register_interface(dbus, IWD_AGENT_MANAGER_INTERFACE, setup_agent_interface,
@@ -650,13 +937,19 @@ static void agent_exit(void)l_dbus_unregister_interface (dbus,IWD_AGENT_MANAGER_INTERFACE ); -l_queue_destroy (agents, agent_free); - agents =NULL ; +l_queue_destroy (secret_agents, agent_free); + secret_agents =NULL ; + +if (netconfig_agent) +agent_free (l_steal_ptr (netconfig_agent)); }void agent_shutdown (void ) { -l_queue_foreach_remove (agents, release_agent,NULL ); +l_queue_foreach_remove (secret_agents, release_agent,NULL ); + +if (netconfig_agent) +release_agent (l_steal_ptr (netconfig_agent),NULL ); }IWD_MODULE (agent, agent_init, agent_exit);
src/agent.h +11 -0
@@ -25,8 +25,11 @@enum agent_result {AGENT_RESULT_OK ,AGENT_RESULT_FAILED , +AGENT_RESULT_CANCELLED , }; +struct netconfig_data ; + typedef void (*agent_request_passphrase_func_t) (enum agent_result result, const char *passphrase, struct l_dbus_message *message,
@@ -35,6 +38,9 @@ typedef void (*agent_request_user_name_passwd_func_t) (enum agent_result result, const char *user, const char *password, struct l_dbus_message *message, void *user_data); +typedef void (*agent_request_netconfig_func_t ) (unsigned int id, +enum agent_result result, +void *user_data);typedef void (*agent_request_destroy_func_t )(void *user_data);void agent_shutdown (void );
@@ -58,4 +64,9 @@ unsigned int agent_request_user_password(const char *path, const char *user,agent_request_passphrase_func_t callback, struct l_dbus_message *trigger, void *user_data, agent_request_destroy_func_t destroy); +unsigned int agent_request_netconfig (const char *path,const char *ifname, +const struct netconfig_data *data, +agent_request_netconfig_func_t callback, +void *user_data, +agent_request_destroy_func_t destroy);bool agent_request_cancel (unsigned int req_id,int reason);
src/dbus.h +2 -0
@@ -43,6 +43,8 @@#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_NETCONFIG_AGENT_INTERFACE \ + "net.connman.iwd.NetworkConfigurationAgent"#define IWD_BASE_PATH "/net/connman/iwd"#define IWD_AGENT_MANAGER_PATH IWD_BASE_PATH
src/netconfig.h +15 -0
@@ -28,6 +28,21 @@ enum netconfig_event { NETCONFIG_EVENT_CONNECTED, }; +enum netconfig_method { +NETCONFIG_METHOD_STATIC , +NETCONFIG_METHOD_AUTO , +}; + +struct netconfig_data { +uint8_t family; +enum netconfig_method method; +char *addr; +uint8_t prefix_len; +char *gateway_addr; +char **dns; +char **domain_names; +}; +typedef void (*netconfig_notify_func_t )(enum netconfig_event event,void *user_data);
Signature · 1 line
2.32.0
Denis Kenzior
Re: [PATCH 4/9] agent: Implement the NetworkConfigurationAgent dbus API
Hi Andrew,
Quoted 7 lines · Andrew Zaborowski
--- src/agent.c | 337 ++++++++++++++++++++++++++++++++++++++++++++---- src/agent.h | 11 ++ src/dbus.h | 2 + src/netconfig.h | 15 +++ 4 files changed, 343 insertions(+), 22 deletions(-)
<snip>
src/agent.c line 43
Quoted 5 lines
src/agent.c +5
-0+enum agent_type { +AGENT_TYPE_SECRET , +AGENT_TYPE_NETCONFIG , +}; +
Have you considered using agent_ops, container_of, or simply an agent_free version for the netconfig agent? Given that there can be only one netconfig agent, this enum seems overkill.
src/agent.c struct agent_request { · line 64
Quoted 12 lines
enum agent_request_type { AGENT_REQUEST_TYPE_PASSPHRASE, AGENT_REQUEST_TYPE_USER_NAME_PASSWD,src/agent.c +5
-0@@ -50,6 +57,18 @@ struct agent_request {agent_request_destroy_func_t destroy; }; +/* Netconfig requests are not queued and can run in parallel */ +struct netconfig_request { +unsigned int dbus_id; +unsigned int id; +char *path;
Is path and ifname correspond to the same device object? Maybe you should use that instead?
src/agent.c struct agent_request { · line 66
Quoted 2 lines
src/agent.c +2
-0+char *ifname; +struct l_timeout *timeout;
Remember that each timeout corresponds to an open fd. Are you sure this is necessary?
Quoted 32 lines
src/agent.c +10
-2+void *user_data; +void *user_callback; +agent_request_destroy_func_t destroy; +}; +struct agent {char *owner;char *path;@@ -58,9 +77,11 @@ struct agent {struct l_timeout *timeout;int timeout_secs;struct l_queue *requests; +enum agent_type type; }; -static struct l_queue *agents; +static struct l_queue *secret_agents; +static struct agent *netconfig_agent;/* * How long we wait for user to input things. @@ -74,7 +95,8 @@ static unsigned int agent_timeout_input_request(void)return 120 ; } -static void send_cancel_request (void *user_data,int reason) +static void send_cancel_request (void *user_data,int reason, +const char *path,const char *ifname) {struct agent *agent = user_data;struct l_dbus_message *message;
src/agent.c static void send_cancel_request(void *user_data, int reason) · line 136
Quoted 10 lines
src/agent.c +6
-1@@ -106,7 +128,12 @@ static void send_cancel_request(void *user_data, int reason)IWD_AGENT_INTERFACE , "Cancel"); -l_dbus_message_set_arguments (message,"s" , reasonstr); +if (path) +l_dbus_message_set_arguments (message,"oss" , path, ifname, + reasonstr); +else +l_dbus_message_set_arguments (message,"s" , reasonstr); +
Please don't do this. Seeing send_cancel_request(foo, reason, NULL, NULL) is quite confusing. Use a separate method for this.
Quoted 3 lines
src/agent.c +0
-0l_dbus_message_set_no_reply (message, true);l_dbus_send (dbus_get_bus (), message);
<snip>
Quoted 4 lines
src/agent.c +4
-0+static void netconfig_timeout_cb (struct l_timeout *timeout,void *user_data) +{ +struct netconfig_request *request = user_data; +agent_request_netconfig_func_t user_callback = request->user_callback;
src/agent.c unsigned int agent_request_user_password(const char *path, const char *user, · line 569
Quoted 10 lines
src/agent.c +10
-0+ +l_debug ("path %s ifname %s" , request->path, request->ifname); + +l_queue_remove (netconfig_agent->requests, request); + +send_cancel_request (netconfig_agent, -ETIMEDOUT , + request->path, request->ifname); + +user_callback (request->id,AGENT_RESULT_FAILED , request->user_data); +netconfig_request_free (request);
We only care about results/timeouts in a very specific case (to signal we're connected). In theory, all subsequent updates might as well be sent with noreply.
How do you plan to handle situations where a change is requested while an ongoing transaction is in progress? For example, a change to wlan0 AF_INET is pending, and another wlan0 AF_INET change is requested? It shouldn't really happen, but the agent backend timing is outside of our control.
Quoted 2 lines
(quoted diff) +2
-0+} +
<snip>
Quoted 45 lines
src/agent.c +25
-3@@ -464,13 +659,22 @@ static bool find_request(const void *a, const void *b)return request->id == id; } +static bool find_netconfig_request (const void *a,const void *b) +{ +const struct netconfig_request *request = a; +unsigned int id =L_PTR_TO_UINT (b); + +return request->id == id; +} +bool agent_request_cancel (unsigned int req_id,int reason) {struct agent_request *request =NULL ;struct agent *agent;const struct l_queue_entry *entry; -for (entry =l_queue_get_entries (agents); entry; entry = entry->next) { +for (entry =l_queue_get_entries (secret_agents); entry; + entry = entry->next) { agent = entry->data; request = l_queue_remove_if(agent->requests, find_request,@@ -479,11 +683,27 @@ bool agent_request_cancel(unsigned int req_id, int reason)break ; } -if (!request) -return false; +if (!request) { +struct netconfig_request *nc_request; + +if (!netconfig_agent) +return false; + + nc_request =l_queue_remove_if (netconfig_agent->requests, + find_netconfig_request, +L_UINT_TO_PTR (req_id)); +if (!nc_request) +return false; + +send_cancel_request (netconfig_agent, reason, + nc_request->path, nc_request->ifname); +
src/agent.c bool agent_request_cancel(unsigned int req_id, int reason) · line 709
Quoted 10 lines
src/agent.c +4
-1+netconfig_request_free (nc_request); +return true; + }if (!request->message) { -send_cancel_request (agent, reason); +send_cancel_request (agent, reason,NULL ,NULL );l_dbus_cancel (dbus_get_bus (), agent->pending_id);
Just make this a separate function, there's almost no reuse here anyway.
src/agent.c static void agent_disconnect(struct l_dbus *dbus, void *user_data) · line 736
Quoted 8 lines
src/agent.c +1
-1@@ -511,18 +731,19 @@ static void agent_disconnect(struct l_dbus *dbus, void *user_data)if (agent->pending_id)agent_finalize_pending (agent,NULL ); -l_queue_remove (agents, agent); +l_queue_remove (secret_agents, agent);l_idle_oneshot (agent_free, agent,NULL );
What about the netconfig agent?
Quoted 2 lines
(quoted diff) +0
-0}
<snip>
src/agent.h line 28
Quoted 9 lines
src/agent.h +1
-0@@ -25,8 +25,11 @@enum agent_result {AGENT_RESULT_OK ,AGENT_RESULT_FAILED , +AGENT_RESULT_CANCELLED ,
I think we prefer 'CANCELED'
Quoted 2 lines
src/agent.h +0
-0};
<snip>
Quoted 13 lines
src/netconfig.h +5
-0@@ -28,6 +28,21 @@ enum netconfig_event { NETCONFIG_EVENT_CONNECTED, }; +enum netconfig_method { +NETCONFIG_METHOD_STATIC , +NETCONFIG_METHOD_AUTO , +}; +
src/netconfig.h enum netconfig_event { · line 45
Quoted 10 lines
src/netconfig.h +10
-0+struct netconfig_data { +uint8_t family; +enum netconfig_method method; +char *addr; +uint8_t prefix_len; +char *gateway_addr; +char **dns; +char **domain_names; +}; +
Since we want to introduce the 'netconfig settings applier entity', I'd say the netconfig version of this structure should use l_rtnl_* objects. That way, both the 'immediate' and 'agent' backends for that entity can operate on the same input.
If you want to introduce a separate structure for agent use, then it should probably be declared inside agent.h.
src/netconfig.h enum netconfig_event { · line 48
Quoted 4 lines
src/netconfig.h +0
-0typedef void (*netconfig_notify_func_t )(enum netconfig_event event,void *user_data);
Regards,
-Denis
Andrew Zaborowski
Re: [PATCH 4/9] agent: Implement the NetworkConfigurationAgent dbus API
Quoted 10 lines · Denis Kenzior
src/agent.c line 43
Quoted 5 lines · Andrew Zaborowski
src/agent.c +5
-0+enum agent_type { +AGENT_TYPE_SECRET , +AGENT_TYPE_NETCONFIG , +}; +Have you considered using
agent_ops,container_of, or simply anagent_freeversion for the netconfig agent? Given that there can be only one netconfig agent, this enum seems overkill.
Ok, I use a "container" struct around struct agent. Or if we use both a separate agent_free() and send_cancel_request() then it may be easier to have completely separate structs too. The agent_ops approach seems like a bigger gun than this enum.
Quoted 8 lines
Quoted 8 lines
enum agent_request_type { AGENT_REQUEST_TYPE_PASSPHRASE, AGENT_REQUEST_TYPE_USER_NAME_PASSWD,src/agent.c +0
-0@@ -50,6 +57,18 @@ struct agent_request {agent_request_destroy_func_t destroy; };
Quoted 8 lines
src/agent.c struct agent_request { · line 64
Quoted 5 lines
src/agent.c +5
-0+/* Netconfig requests are not queued and can run in parallel */ +struct netconfig_request { +unsigned int dbus_id; +unsigned int id; +char *path;Is path and ifname correspond to the same device object? Maybe you should use that instead?
The path (in station case) is to the network object same as when we ask for the PSK.
Quoted 6 lines
src/agent.c struct agent_request { · line 66
Quoted 3 lines
src/agent.c +2
-0+char *ifname; +struct l_timeout *timeout;Remember that each timeout corresponds to an open fd. Are you sure this is necessary?
We use this timeout in place of the one in "struct agent". What we could do is use one actual timeout and keep re-arming it for new expiry times, but then I think this would be better done directly in ell if we want to save fds.
Quoted 36 lines
Quoted 36 lines
src/agent.c +10
-2+void *user_data; +void *user_callback; +agent_request_destroy_func_t destroy; +}; +struct agent {char *owner;char *path;@@ -58,9 +77,11 @@ struct agent {struct l_timeout *timeout;int timeout_secs;struct l_queue *requests; +enum agent_type type; }; -static struct l_queue *agents; +static struct l_queue *secret_agents; +static struct agent *netconfig_agent;/* * How long we wait for user to input things. @@ -74,7 +95,8 @@ static unsigned int agent_timeout_input_request(void)return 120 ; } -static void send_cancel_request (void *user_data,int reason) +static void send_cancel_request (void *user_data,int reason, +const char *path,const char *ifname) {struct agent *agent = user_data;struct l_dbus_message *message;@@ -106,7 +128,12 @@ static void send_cancel_request(void *user_data, int reason)IWD_AGENT_INTERFACE , "Cancel");
Quoted 10 lines
src/agent.c static void send_cancel_request(void *user_data, int reason) · line 136
Quoted 7 lines
src/agent.c +6
-1-l_dbus_message_set_arguments (message,"s" , reasonstr); +if (path) +l_dbus_message_set_arguments (message,"oss" , path, ifname, + reasonstr); +else +l_dbus_message_set_arguments (message,"s" , reasonstr); +Please don't do this. Seeing
send_cancel_request(foo, reason, NULL, NULL)is quite confusing. Use a separate method for this.
Ok.
Quoted 9 lines
Quoted 9 lines
src/agent.c +9
-0+static void netconfig_timeout_cb (struct l_timeout *timeout,void *user_data) +{ +struct netconfig_request *request = user_data; +agent_request_netconfig_func_t user_callback = request->user_callback; + +l_debug ("path %s ifname %s" , request->path, request->ifname); + +l_queue_remove (netconfig_agent->requests, request); +
Quoted 8 lines
src/agent.c unsigned int agent_request_user_password(const char *path, const char *user, · line 569
Quoted 5 lines
src/agent.c +5
-0+send_cancel_request (netconfig_agent, -ETIMEDOUT , + request->path, request->ifname); + +user_callback (request->id,AGENT_RESULT_FAILED , request->user_data); +netconfig_request_free (request);We only care about results/timeouts in a very specific case (to signal we're connected). In theory, all subsequent updates might as well be sent with noreply.
True, that would also save fds, but it may be better to not hardcode this assumption in agent.c.
Quoted 5 lines
How do you plan to handle situations where a change is requested while an ongoing transaction is in progress? For example, a change to wlan0
AF_INETis pending, and another wlan0AF_INETchange is requested? It shouldn't really happen, but the agent backend timing is outside of our control.
Right, my idea was that this result in simultaneous ConfigureIPvX calls running and the agent has to see if that poses a problem for them.
Quoted 25 lines
Quoted 25 lines
src/agent.c +18
-2@@ -479,11 +683,27 @@ bool agent_request_cancel(unsigned int req_id, int reason)break ; } -if (!request) -return false; +if (!request) { +struct netconfig_request *nc_request; + +if (!netconfig_agent) +return false; + + nc_request =l_queue_remove_if (netconfig_agent->requests, + find_netconfig_request, +L_UINT_TO_PTR (req_id)); +if (!nc_request) +return false; + +send_cancel_request (netconfig_agent, reason, + nc_request->path, nc_request->ifname); + +netconfig_request_free (nc_request); +return true; + }
Quoted 8 lines
src/agent.c bool agent_request_cancel(unsigned int req_id, int reason) · line 709
Quoted 6 lines
src/agent.c +1
-1if (!request->message) { -send_cancel_request (agent, reason); +send_cancel_request (agent, reason,NULL ,NULL );l_dbus_cancel (dbus_get_bus (), agent->pending_id);Just make this a separate function, there's almost no reuse here anyway.
Ok.
Quoted 11 lines
src/agent.c static void agent_disconnect(struct l_dbus *dbus, void *user_data) · line 736
Quoted 9 lines
src/agent.c +1
-1@@ -511,18 +731,19 @@ static void agent_disconnect(struct l_dbus *dbus, void *user_data)if (agent->pending_id)agent_finalize_pending (agent,NULL ); -l_queue_remove (agents, agent); +l_queue_remove (secret_agents, agent);l_idle_oneshot (agent_free, agent,NULL );What about the netconfig agent?
Good point..
Quoted 6 lines
Quoted 3 lines
(quoted diff) +0
-0}<snip>
Quoted 11 lines
src/agent.h line 28
Quoted 9 lines
src/agent.h +1
-0@@ -25,8 +25,11 @@enum agent_result {AGENT_RESULT_OK ,AGENT_RESULT_FAILED , +AGENT_RESULT_CANCELLED ,I think we prefer 'CANCELED'
Ok.
Quoted 34 lines
Quoted 3 lines
src/agent.h +0
-0};<snip>
Quoted 13 lines
src/netconfig.h +5
-0@@ -28,6 +28,21 @@ enum netconfig_event { NETCONFIG_EVENT_CONNECTED, }; +enum netconfig_method { +NETCONFIG_METHOD_STATIC , +NETCONFIG_METHOD_AUTO , +}; +src/netconfig.h enum netconfig_event { · line 45
Quoted 10 lines
src/netconfig.h +10
-0+struct netconfig_data { +uint8_t family; +enum netconfig_method method; +char *addr; +uint8_t prefix_len; +char *gateway_addr; +char **dns; +char **domain_names; +}; +Since we want to introduce the 'netconfig settings applier entity', I'd say the netconfig version of this structure should use l_rtnl_* objects. That way, both the 'immediate' and 'agent' backends for that entity can operate on the same input.
Quoted 2 lines
If you want to introduce a separate structure for agent use, then it should probably be declared inside
agent.h.
Ok, let's see which works better.
Best regards
Andrew Zaborowski
PATCH 5/9 netconfig: Try calling the agent before setting new values
In reply to Andrew ZaborowskiImplement the logic where, after netconfig decides on what address, gateway, DNS, etc. data to use, it calls the NetworkConfigurationAgent that may be registered and relies on it to commit the new values. If no agent is registered it will proceed to set the new values as usual. If it does make an agent call, it wlil wait for the call to return before signalling NETCONFIG_EVENT_CONNECTED.
--- src/netconfig.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++ src/netconfig.h | 1 + src/station.c | 4 ++ 3 files changed, 119 insertions(+)
src/netconfig.c +114 -0
@@ -49,6 +49,7 @@#include "src/resolve.h" #include "src/util.h" #include "src/ie.h" +#include "src/agent.h" #include "src/netconfig.h" #include "src/sysfs.h"
@@ -97,6 +98,10 @@ struct netconfig {uint32_t addr6_add_cmd_id;uint32_t route4_add_gateway_cmd_id;uint32_t route6_add_cmd_id; + +const char *dbus_obj_path; +unsigned int agent_v4_req_id; +unsigned int agent_v6_req_id; };static struct l_netlink *rtnl;
@@ -1031,6 +1036,92 @@ static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, "Error %d: %s", error, strerror(-error)); } +static void netconfig_agent_req_cb (unsigned int req_id,enum agent_result result, +void *user_data) +{ +struct netconfig *netconfig = user_data; +bool v4 = req_id == netconfig->agent_v4_req_id; + +if (v4) + netconfig->agent_v4_req_id =0 ; +else + netconfig->agent_v6_req_id =0 ; + +if (result !=AGENT_RESULT_OK ) { +l_error ("Netconfig agent request for %s failed" , + v4 ?"IPv4" :"IPv6" ); +/* TODO: report to user if v4 */ +return ; + } + +l_debug ("Netconfig agent request success for %s" , v4 ?"IPv4" :"IPv6" ); + +if (!v4) +return ; + +if (netconfig->notify) { + netconfig->notify (NETCONFIG_EVENT_CONNECTED , + netconfig->user_data); + netconfig->notify =NULL ; + } +} + +static bool netconfig_try_agent (struct netconfig *netconfig,uint8_t af) +{ +struct netconfig_data data = { .family = af }; +const struct l_rtnl_address *addr; +char addr_str[INET6_ADDRSTRLEN ]; +char *v4_domains[] = { netconfig->v4_domain,NULL }; +struct netdev *netdev =netdev_find (netconfig->ifindex); +unsigned int *id = (af ==AF_INET ) ? + &netconfig->agent_v4_req_id : &netconfig->agent_v6_req_id; + +if (!netconfig->dbus_obj_path) +return false; + + addr = (af ==AF_INET ) ? netconfig->v4_address : netconfig->v6_address; + +if ((af ==AF_INET && netconfig->rtm_protocol ==RTPROT_STATIC ) || + (af ==AF_INET6 && + netconfig->rtm_v6_protocol ==RTPROT_STATIC )) + data.method =NETCONFIG_METHOD_STATIC ; +else if ((af ==AF_INET && netconfig->rtm_protocol ==RTPROT_DHCP ) || + (af ==AF_INET6 && + netconfig->rtm_v6_protocol ==RTPROT_DHCP )) + data.method =NETCONFIG_METHOD_AUTO ; +else +return true; + +if (addr) { +if (l_rtnl_address_get_address (addr, addr_str)) + data.addr = addr_str; + + data.prefix_len =l_rtnl_address_get_prefix_length (addr); + } + + data.gateway_addr = (af ==AF_INET ) ? + netconfig->v4_gateway_str : netconfig->v6_gateway_str; + data.dns = (af ==AF_INET ) ? + netconfig->dns4_list : netconfig->dns6_list; + data.domain_names = (af ==AF_INET ) ? + (v4_domains[0 ] ? v4_domains :NULL ) : netconfig->v6_domains; + +if (*id) +agent_request_cancel (*id, -ECANCELED ); + + *id =agent_request_netconfig (netconfig->dbus_obj_path, +netdev_get_name (netdev), + &data, + netconfig_agent_req_cb, + netconfig,NULL ); +if (!*id) +return false; + +l_debug ("Netconfig request for %s on %s sent to agent" , + (af ==AF_INET ) ?"IPv4" :"IPv6" ,netdev_get_name (netdev)); +return true; +} +static bool netconfig_address_cmp_address (const struct l_rtnl_address *a,const struct l_rtnl_address *b) {
@@ -1068,6 +1159,9 @@ static void netconfig_set(struct netconfig *netconfig, uint8_t af, {struct l_rtnl_address *stale_addr; +if (netconfig_try_agent (netconfig, af)) +return ; +if (af ==AF_INET ) stale_addr =l_steal_ptr (netconfig->stale_v4_address);else
@@ -1390,6 +1484,12 @@ static void netconfig_reset_v4(struct netconfig *netconfig)l_acd_destroy (netconfig->acd); netconfig->acd =NULL ; + +if (netconfig->agent_v4_req_id) { +agent_request_cancel (netconfig->agent_v4_req_id, + -ECANCELED ); + netconfig->agent_v4_req_id =0 ; + } } }
@@ -1429,6 +1529,12 @@ static void netconfig_reset_v6(struct netconfig *netconfig)sysfs_write_ipv6_setting (netdev_get_name (netdev),"disable_ipv6" ,"1" ); + +if (netconfig->agent_v6_req_id) { +agent_request_cancel (netconfig->agent_v6_req_id, + -ECANCELED ); + netconfig->agent_v6_req_id =0 ; + } } }
@@ -1785,6 +1891,8 @@ bool netconfig_reconfigure(struct netconfig *netconfig, bool set_arp_gw)bool netconfig_reset (struct netconfig *netconfig) { + netconfig->dbus_obj_path =NULL ; +if (netconfig->route4_add_gateway_cmd_id) {l_netlink_cancel (rtnl, netconfig->route4_add_gateway_cmd_id); netconfig->route4_add_gateway_cmd_id =0 ;
@@ -1925,6 +2033,11 @@ void netconfig_destroy(struct netconfig *netconfig)netconfig_free (netconfig); } +void netconfig_set_dbus_path (struct netconfig *netconfig,const char *path) +{ + netconfig->dbus_obj_path = path; +} +bool netconfig_enabled (void ) {bool enabled;
@@ -2004,3 +2117,4 @@ static void netconfig_exit(void) } IWD_MODULE(netconfig, netconfig_init, netconfig_exit) +IWD_MODULE_DEPENDS (netconfig, agent)
src/netconfig.h +1 -0
@@ -61,5 +61,6 @@ void netconfig_handle_fils_ip_resp(struct netconfig *netconfig,struct netconfig *netconfig_new (uint32_t ifindex);void netconfig_destroy (struct netconfig *netconfig); +void netconfig_set_dbus_path (struct netconfig *netconfig,const char *path);bool netconfig_enabled (void );
src/station.c +4 -0
@@ -2816,6 +2816,10 @@ static void station_connect_ok(struct station *station) } } +/* The path remains valid until connected_network changes */ +netconfig_set_dbus_path (station->netconfig, +network_get_path (station->connected_network)); +if (L_WARN_ON (!netconfig_configure (station->netconfig, station_netconfig_event_handler, station)))
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 6/9 netconfig: Don't start ACD with FILS IP Assignment
In reply to Andrew ZaborowskiRestore the older behaviour where ACD was started only with static addressing. There are various arguments for saving setup time by not doing ACD when a wifi network has IP addresses managed centrally (and some arguments against), for now just restore the behaviour from before FILS IP Assignment was added.
--- src/netconfig.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-)
src/netconfig.c +20 -14
@@ -1622,22 +1622,28 @@ static bool netconfig_ipv4_select_and_install(struct netconfig *netconfig) ip)))return false; - netconfig->acd =l_acd_new (netconfig->ifindex); -l_acd_set_event_handler (netconfig->acd, - netconfig_ipv4_acd_event, netconfig, -NULL ); -if (getenv ("IWD_ACD_DEBUG" )) -l_acd_set_debug (netconfig->acd, do_debug, -"[ACD] " ,NULL ); - -if (!l_acd_start (netconfig->acd, ip)) { -l_error ("failed to start ACD, continuing anyways" ); -l_acd_destroy (netconfig->acd); - netconfig->acd =NULL ; +if (netconfig->rtm_protocol ==RTPROT_STATIC ) { + netconfig->acd =l_acd_new (netconfig->ifindex); +l_acd_set_event_handler (netconfig->acd, + netconfig_ipv4_acd_event, + netconfig,NULL ); -netconfig_set (netconfig,AF_INET , changed); - }else +if (getenv ("IWD_ACD_DEBUG" )) +l_acd_set_debug (netconfig->acd, do_debug, +"[ACD] " ,NULL ); + +if (!l_acd_start (netconfig->acd, ip)) { +l_error ("failed to start ACD, continuing " +"anyways" ); +l_acd_destroy (netconfig->acd); + netconfig->acd =NULL ; + } + } + +if (netconfig->acd) netconfig->pending_v4_set |= changed; +else +netconfig_set (netconfig,AF_INET , changed);return true; }
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 7/9 ap: Delay ap_free if called inside event handler
In reply to Andrew Zaborowskiap.c has been mostly careful to call the event handler at the end of any externally called function to allow methods like ap_free() to be called within the handler, but that isn't enough. For example in ap_del_station we may end up emitting two events: STATION_REMOVED and DHCP_LEASE_EXPIRED. Use a slightly more complicated mechanism to explicitly guard ap_free calls inside the event handler.
To make it easier, simplify cleanup in ap_assoc_reassoc with the use of _auto_.
In ap_del_station reorder the actions to send the STATION_REMOVED event first as the DHCP_LEASE_EXPIRED is a consequence of the former and it makes sense for the handler to react to it first.
--- src/ap.c | 125 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 80 insertions(+), 45 deletions(-)
src/ap.c +80 -45
@@ -101,6 +101,8 @@ struct ap_state { bool started : 1; bool gtk_set : 1; bool netconfig_set_addr4 : 1; + bool in_event : 1; + bool free_pending : 1; };struct sta_state {
@@ -250,6 +252,35 @@ static void ap_reset(struct ap_state *ap) } } +static bool ap_event_done (struct ap_state *ap,bool prev_in_event) +{ + ap->in_event = prev_in_event; + +if (!prev_in_event && ap->free_pending) { +ap_free (ap); +return true; + } + +return ap->free_pending; +} + +/* +* Returns true if the AP is considered freed and the caller must avoid +* accessing @ap. +*/ +static bool ap_event (struct ap_state *ap,enum ap_event_type event, +const void *event_data) +{ +bool prev = ap->in_event; + +if (ap->free_pending) +return true; + + ap->in_event = true; + ap->ops->handle_event (event, event_data, ap->user_data); +return ap_event_done (ap, prev); +} +static void ap_del_station (struct sta_state *sta,uint16_t reason,bool disassociate) {
@@ -283,6 +314,14 @@ static void ap_del_station(struct sta_state *sta, uint16_t reason,ap_stop_handshake (sta); +/* +* If the event handler tears the AP down, we've made sure above that +* a subsequent ap_sta_free(sta) has no need to access sta->ap. +*/ +if (send_event) +if (ap_event (ap,AP_EVENT_STATION_REMOVED , &event_data)) +return ; +/* * Expire any DHCP leases owned by this client when it disconnects to * make it harder for somebody to DoS the IP pool. If the client
@@ -290,17 +329,20 @@ static void ap_del_station(struct sta_state *sta, uint16_t reason,* will get their IP back. */ if (ap->netconfig_dhcp) { +bool prev = ap->in_event; + +/* +* If the LEASE_EXPIRED event in ap_dhcp_event_cb triggers an +* ap_free(), delay cleanup to avoid destroying the DHCP +* server midway through l_dhcp_server_expire_by_mac(). +*/ + ap->in_event = true; + sta->ip_alloc_lease =NULL ;l_dhcp_server_expire_by_mac (ap->netconfig_dhcp, sta->addr); - } -/* -* If the event handler tears the AP down, we've made sure above that -* a subsequent ap_sta_free(sta) has no need to access sta->ap. -*/ -if (send_event) - ap->ops->handle_event (AP_EVENT_STATION_REMOVED , &event_data, - ap->user_data); +ap_event_done (ap, prev); + } }static bool ap_sta_match_addr (const void *a,const void *b)
@@ -335,19 +377,16 @@ static void ap_del_key_cb(struct l_genl_msg *msg, void *user_data)static void ap_new_rsna (struct sta_state *sta) {struct ap_state *ap = sta->ap; +struct ap_event_station_added_data event_data = {};l_debug ("STA " MAC " authenticated" ,MAC_STR (sta->addr)); sta->rsna = true; -if (ap->ops->handle_event) { -struct ap_event_station_added_data event_data = {}; - event_data.mac = sta->addr; - event_data.assoc_ies = sta->assoc_ies; - event_data.assoc_ies_len = sta->assoc_ies_len; - ap->ops->handle_event (AP_EVENT_STATION_ADDED , &event_data, - ap->user_data); - } + event_data.mac = sta->addr; + event_data.assoc_ies = sta->assoc_ies; + event_data.assoc_ies_len = sta->assoc_ies_len; +ap_event (ap,AP_EVENT_STATION_ADDED , &event_data); }static void ap_drop_rsna (struct sta_state *sta)
@@ -356,6 +395,7 @@ static void ap_drop_rsna(struct sta_state *sta)struct l_genl_msg *msg;uint32_t ifindex =netdev_get_ifindex (sta->ap->netdev);uint8_t key_id =0 ; +struct ap_event_station_removed_data event_data = {}; sta->rsna = false;
@@ -380,12 +420,8 @@ static void ap_drop_rsna(struct sta_state *sta)ap_stop_handshake (sta); -if (ap->ops->handle_event) { -struct ap_event_station_removed_data event_data = {}; - event_data.mac = sta->addr; - ap->ops->handle_event (AP_EVENT_STATION_REMOVED , &event_data, - ap->user_data); - } + event_data.mac = sta->addr; +ap_event (ap,AP_EVENT_STATION_REMOVED , &event_data); }static void ap_set_rsn_info (struct ap_state *ap,struct ie_rsn_info *rsn)
@@ -405,7 +441,7 @@ static void ap_wsc_exit_pbc(struct ap_state *ap) ap->wsc_dpid =0 ;ap_update_beacon (ap); - ap->ops->handle_event (AP_EVENT_PBC_MODE_EXIT ,NULL , ap->user_data); +ap_event (ap,AP_EVENT_PBC_MODE_EXIT ,NULL ); }struct ap_pbc_record_expiry_data {
@@ -1090,9 +1126,7 @@ static void ap_wsc_handshake_event(struct handshake_state *hs, &expiry_data); event_data.mac = sta->addr; - sta->ap->ops->handle_event (AP_EVENT_REGISTRATION_SUCCESS , - &event_data, - sta->ap->user_data); +ap_event (sta->ap,AP_EVENT_REGISTRATION_SUCCESS , &event_data);break ;default :break ;
@@ -1594,11 +1628,11 @@ static void ap_assoc_reassoc(struct sta_state *sta, bool reassoc,const char *ssid =NULL ;const uint8_t *rsn =NULL ;size_t ssid_len =0 ; -struct l_uintset *rates =NULL ; + _auto_(l_uintset_free) struct l_uintset *rates = NULL;struct ie_rsn_info rsn_info;int err;struct ie_tlv_iter iter; -uint8_t *wsc_data =NULL ; + _auto_(l_free) uint8_t *wsc_data = NULL;ssize_t wsc_data_len;bool fils_ip_req = false;struct ie_fils_ip_addr_request_info fils_ip_req_info;
@@ -1685,9 +1719,6 @@ static void ap_assoc_reassoc(struct sta_state *sta, bool reassoc, goto bad_frame; } -l_free (wsc_data); - wsc_data =NULL ; -if (wsc_req.request_type !=WSC_REQUEST_TYPE_ENROLLEE_OPEN_8021X ) { err =MMPDU_REASON_CODE_INVALID_IE ;
@@ -1728,8 +1759,9 @@ static void ap_assoc_reassoc(struct sta_state *sta, bool reassoc, event_data.mac = sta->addr; event_data.assoc_ies = ies; event_data.assoc_ies_len = ies_len; - ap->ops->handle_event (AP_EVENT_REGISTRATION_START , &event_data, - ap->user_data); + +if (ap_event (ap,AP_EVENT_REGISTRATION_START , &event_data)) +return ;/* * Since we're starting the PBC Registration Protocol
@@ -1781,7 +1813,7 @@ static void ap_assoc_reassoc(struct sta_state *sta, bool reassoc,if (sta->rates)l_uintset_free (sta->rates); - sta->rates = rates; + sta->rates =l_steal_ptr (rates);l_free (sta->assoc_ies);
@@ -1823,11 +1855,6 @@ bad_frame:else if (sta->associated)ap_stop_handshake (sta); -if (rates) -l_uintset_free (rates); - -l_free (wsc_data); -if (!ap_assoc_resp (ap, sta, sta->addr, err, reassoc, req, (void *) ies + ies_len - (void *) req,NULL , ap_fail_assoc_resp_cb))
@@ -2209,6 +2236,7 @@ static void ap_start_failed(struct ap_state *ap, int err) {struct ap_event_start_failed_data data = { err }; + ap->in_event = true; ap->ops->handle_event (AP_EVENT_START_FAILED , &data, ap->user_data);ap_reset (ap);l_genl_family_free (ap->nl80211);
@@ -2224,13 +2252,11 @@ static void ap_dhcp_event_cb(struct l_dhcp_server *server,switch (event) {case L_DHCP_SERVER_EVENT_NEW_LEASE : - ap->ops->handle_event (AP_EVENT_DHCP_NEW_LEASE , lease, - ap->user_data); +ap_event (ap,AP_EVENT_DHCP_NEW_LEASE , lease);break ;case L_DHCP_SERVER_EVENT_LEASE_EXPIRED : - ap->ops->handle_event (AP_EVENT_DHCP_LEASE_EXPIRED , lease, - ap->user_data); +ap_event (ap,AP_EVENT_DHCP_LEASE_EXPIRED , lease);break ;default :
@@ -2267,7 +2293,7 @@ static void ap_start_cb(struct l_genl_msg *msg, void *user_data) } ap->started = true; - ap->ops->handle_event (AP_EVENT_STARTED ,NULL , ap->user_data); +ap_event (ap,AP_EVENT_STARTED ,NULL ); }static struct l_genl_msg *ap_build_cmd_start_ap (struct ap_state *ap)
@@ -2552,6 +2578,8 @@ static void ap_mlme_notify(struct l_genl_msg *msg, void *user_data)switch (l_genl_msg_get_command (msg)) {case NL80211_CMD_STOP_AP : + ap->in_event = true; +if (ap->start_stop_cmd_id) {struct ap_event_start_failed_data data = { -ECANCELED };
@@ -3304,7 +3332,9 @@ void ap_shutdown(struct ap_state *ap, ap_stopped_func_t stopped_func,if (ap->started) { ap->started = false; - ap->ops->handle_event (AP_EVENT_STOPPING ,NULL , ap->user_data); + +if (ap_event (ap,AP_EVENT_STOPPING ,NULL )) +return ; }ap_reset (ap);
@@ -3355,6 +3385,11 @@ free_ap:/* Free @ap without a graceful shutdown */ void ap_free (struct ap_state *ap) { +if (ap->in_event) { + ap->free_pending = true; +return ; + } +ap_reset (ap);l_genl_family_free (ap->nl80211);l_free (ap);
Signature · 1 line
2.32.0
Denis Kenzior
AppliedRe: [PATCH 7/9] ap: Delay ap_free if called inside event handler
Hi Andrew,
Quoted 10 lines · Andrew Zaborowski
ap.chas been mostly careful to call the event handler at the end of any externally called function to allow methods likeap_free()to be called within the handler, but that isn't enough. For example inap_del_stationwe may end up emitting two events:STATION_REMOVEDandDHCP_LEASE_EXPIRED. Use a slightly more complicated mechanism to explicitly guardap_freecalls inside the event handler.To make it easier, simplify cleanup in
ap_assoc_reassocwith the use of _auto_.
Quoted 7 lines
In
ap_del_stationreorder the actions to send theSTATION_REMOVEDevent first as theDHCP_LEASE_EXPIREDis a consequence of the former and it makes sense for the handler to react to it first.--- src/ap.c | 125 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 80 insertions(+), 45 deletions(-)
Applied, thanks.
Regards,
-Denis
Andrew Zaborowski
PATCH 8/9 autotests: Test DHCPv6 client in testNetconfig
In reply to Andrew Zaborowski--- autotests/testNetconfig/connection_test.py | 34 ++++++++++++++++++++-- autotests/testNetconfig/dhcpd-v6.conf | 6 ++++ autotests/testNetconfig/main.conf | 3 ++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 autotests/testNetconfig/dhcpd-v6.conf
autotests/testNetconfig/connection_test.py +31 -3
@@ -11,7 +11,7 @@ from iwd import NetworkType from hostapd import HostapdCLI import testutil from config import ctx -import os +import os, time class Test(unittest.TestCase):
@@ -39,6 +39,10 @@ class Test(unittest.TestCase): testutil.test_iface_operstate() testutil.test_ifaces_connected() + time.sleep(2) + ret = os.system('ip addr show ' + device.name + ' | grep \'inet6 3ffe:501:ffff:100::\'') + self.assertEqual(os.waitstatus_to_exitcode(ret), 0) + device.disconnect() condition = 'not obj.connected'
@@ -48,12 +52,18 @@ class Test(unittest.TestCase): @classmethod def setUpClass(cls): - def remove_lease(): + def remove_lease4(): try: os.remove('/tmp/dhcpd.leases') os.remove('/tmp/dhcpd.leases~') except: pass + def remove_lease6(): + try: + os.remove('/tmp/dhcpd6.leases') + os.remove('/tmp/dhcpd6.leases~') + except: + pass hapd = HostapdCLI() # TODO: This could be moved into test-runner itself if other tests ever
@@ -64,13 +74,31 @@ class Test(unittest.TestCase): ctx.start_process(['touch', '/tmp/dhcpd.leases']).wait() cls.dhcpd_pid = ctx.start_process(['dhcpd', '-f', '-cf', '/tmp/dhcpd.conf', '-lf', '/tmp/dhcpd.leases', - hapd.ifname], cleanup=remove_lease) + hapd.ifname], cleanup=remove_lease4) + + ctx.start_process(['ifconfig', hapd.ifname, 'inet6', + 'add', '3ffe:501:ffff:100::1/64']).wait() + ctx.start_process(['touch', '/tmp/dhcpd6.leases']).wait() + cls.dhcpd6_pid = ctx.start_process(['dhcpd', '-6', '-f', '-cf', '/tmp/dhcpd-v6.conf', + '-lf', '/tmp/dhcpd6.leases', + hapd.ifname], cleanup=remove_lease6) + ctx.start_process(['sysctl', 'net.ipv6.conf.' + hapd.ifname + '.forwarding=1']).wait() + # Tell clients to use DHCPv6 + config = open('/tmp/radvd.conf', 'w') + config.write('interface ' + hapd.ifname + ' { AdvSendAdvert on; AdvManagedFlag on; };') + config.close() + cls.radvd_pid = ctx.start_process(['radvd', '-n', '-C', '/tmp/radvd.conf']) @classmethod def tearDownClass(cls): IWD.clear_storage() ctx.stop_process(cls.dhcpd_pid) cls.dhcpd_pid = None + ctx.stop_process(cls.dhcpd6_pid) + cls.dhcpd6_pid = None + ctx.stop_process(cls.radvd_pid) + cls.radvd_pid = None + os.remove('/tmp/radvd.conf') if __name__ == '__main__': unittest.main(exit=True)
autotests/testNetconfig/dhcpd-v6.conf new file +6 -0
@@ -0,0 +1,6 @@ +subnet6 3ffe:501:ffff:100::/64 + { + option dhcp6.name-servers 3ffe:501:ffff:100::1; + range6 3ffe:501:ffff:100::10 3ffe:501:ffff:100::20; + range6 3ffe:501:ffff:100::100 3ffe:501:ffff:100::200; + }
autotests/testNetconfig/main.conf +3 -0
@@ -1,2 +1,5 @@ [General] EnableNetworkConfiguration=true + +[Network] +EnableIPv6=true
Signature · 1 line
2.32.0
Denis Kenzior
Re: [PATCH 8/9] autotests: Test DHCPv6 client in testNetconfig
Hi Andrew,
Quoted 7 lines · Andrew Zaborowski
--- autotests/testNetconfig/connection_test.py | 34 ++++++++++++++++++++-- autotests/testNetconfig/dhcpd-v6.conf | 6 ++++ autotests/testNetconfig/main.conf | 3 ++ 3 files changed, 40 insertions(+), 3 deletions(-)create mode 100644
autotests/testNetconfig/dhcpd-v6.conf
I went ahead and applied this, but see below. I also added a small fix afterwards to specify radvd pid file since radvd was refusing to start on my setup (and the test was failing).
<snip>
autotests/testNetconfig/connection_test.py class Test(unittest.TestCase): · line 42
Quoted 5 lines
autotests/testNetconfig/connection_test.py +1
-0@@ -39,6 +39,10 @@ class Test(unittest.TestCase): testutil.test_iface_operstate() testutil.test_ifaces_connected() + time.sleep(2)
Using time.sleep() isn't a great idea since the timing can be quite variable. Especially if qemu is running inside the VM (like the setup I have for example).
In general, just forget that sleep() exists and listen for the right events.
autotests/testNetconfig/connection_test.py class Test(unittest.TestCase): · line 45
Quoted 3 lines
autotests/testNetconfig/connection_test.py +3
-0+ ret = os.system('ip addr show ' + device.name + ' | grep \'inet6 3ffe:501:ffff:100::\'') + self.assertEqual(os.waitstatus_to_exitcode(ret), 0) +
Note that os.waitstatus_to_exitcode is a python 3.9 feature. I updated the docs to reflect that.
autotests/testNetconfig/connection_test.py class Test(unittest.TestCase): · line 48
Quoted 3 lines
autotests/testNetconfig/connection_test.py +0
-0device.disconnect() condition = 'not obj.connected'
Regards,
-Denis
Andrew Zaborowski
Re: [PATCH 8/9] autotests: Test DHCPv6 client in testNetconfig
Hi Denis,
Quoted 11 lines · Denis Kenzior
Quoted 6 lines · Andrew Zaborowski
autotests/testNetconfig/connection_test.py | 34 ++++++++++++++++++++-- autotests/testNetconfig/dhcpd-v6.conf | 6 ++++ autotests/testNetconfig/main.conf | 3 ++ 3 files changed, 40 insertions(+), 3 deletions(-)create mode 100644
autotests/testNetconfig/dhcpd-v6.confI went ahead and applied this, but see below. I also added a small fix afterwards to specify radvd pid file since radvd was refusing to start on my setup (and the test was failing).
Thanks for fixing this.
Quoted 7 lines
<snip>
Quoted 4 lines
autotests/testNetconfig/connection_test.py +0
-0@@ -39,6 +39,10 @@ class Test(unittest.TestCase): testutil.test_iface_operstate() testutil.test_ifaces_connected()
Quoted 5 lines
autotests/testNetconfig/connection_test.py class Test(unittest.TestCase): · line 42
Quoted 1 line
autotests/testNetconfig/connection_test.py +1
-0+ time.sleep(2)Using
time.sleep()isn't a great idea since the timing can be quite variable. Especially if qemu is running inside the VM (like the setup I have for example).
In general, just forget thatsleep()exists and listen for the right events.
Right, it took me some effort to force myself to use it ;) but writing the code to listen for rtnl events in the test didn't seem worthwhile. I tested this in qemu without acceleration which is likely slower than nested VMs but using acceleration. And the time saving here would be about 1s.
Quoted 7 lines
autotests/testNetconfig/connection_test.py class Test(unittest.TestCase): · line 45
Quoted 4 lines
autotests/testNetconfig/connection_test.py +3
-0+ ret = os.system('ip addr show ' + device.name + ' | grep \'inet6 3ffe:501:ffff:100::\'') + self.assertEqual(os.waitstatus_to_exitcode(ret), 0) +Note that os.waitstatus_to_exitcode is a python 3.9 feature. I updated the docs to reflect that.
Good catch, too.
Best regards
Andrew Zaborowski
PATCH 9/9 doc: Document autotest radvd dependency
In reply to Andrew Zaborowski--- doc/test-runner.txt | 1 + 1 file changed, 1 insertion(+)
doc/test-runner.txt +1 -0
@@ -29,6 +29,7 @@ OS: 11. ofono (optional) 12. phonesim (optional) 13. wpa_supplicant 2.9 + 14. radvd 2.18 Note: The version for hostapd is listed as 'recent'. Older hostapd versions will work but we are continually adopting new features from hostapd and using
Signature · 1 line
2.32.0
Denis Kenzior
AppliedRe: [PATCH 9/9] doc: Document autotest radvd dependency
Hi Andrew,
Quoted 4 lines · Andrew Zaborowski
--- doc/test-runner.txt | 1 + 1 file changed, 1 insertion(+)
Applied, thanks.
Regards,
-Denis
Denis Kenzior
Hi Andrew,
Quoted 6 lines · Andrew Zaborowski
Refactor and unify how the netconfig values, that we obtain from DHCP or the settings or otherwise, are written/committed to the system netdevs. We basically concentrate all of those actions in a new function
netconfig_set()that is called whenever any value changes. The only exceptions are the sysfs writes and some of the ARP table writes.
Quoted 9 lines
This will allow us to more easily delegate committing the values to an (optional) D-Bus agent, or expose them as D-Bus properties if we ever choose to do that in the future. For that I'm also passing a bitmask telling
netconfig_set()which values may have actually changed, so we don't bother looking at those that definitely haven't changed.--- src/netconfig.c | 541 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 398 insertions(+), 143 deletions(-)
It would be far easier if this was broken down into more digestible chunks. I could even apply some right away since many make sense on their own.
src/netconfig.c line 57
Quoted 11 lines
src/netconfig.c +3
-0@@ -52,6 +52,15 @@#include "src/netconfig.h" #include "src/sysfs.h" +enum netconfig_changed_flags { +NETCONFIG_CHANGED_ADDRESS =1 <<0 , +NETCONFIG_CHANGED_NETMASK =1 <<1 ,
Isn't netmask effectively part of the address? If netmask changes, then you need to change the connected route and the address on the interface anyway.
Quoted 10 lines
src/netconfig.c +6
-0+NETCONFIG_CHANGED_GATEWAY =1 <<2 , +NETCONFIG_CHANGED_DNS =1 <<3 , +NETCONFIG_CHANGED_DOMAINS =1 <<4 , + NETCONFIG_CHANGED_ALL = 0x1f, +}; +struct netconfig {uint32_t ifindex;struct l_dhcp_client *dhcp_client;
src/netconfig.c struct netconfig { · line 73
Quoted 6 lines
src/netconfig.c +2
-0@@ -59,7 +68,9 @@ struct netconfig {uint8_t rtm_protocol;uint8_t rtm_v6_protocol;struct l_rtnl_address *v4_address; +struct l_rtnl_address *stale_v4_address;struct l_rtnl_address *v6_address; +struct l_rtnl_address *stale_v6_address;
I really don't think these belong here. If we're going in the direction of netconfig delegating the management of applying IP configuration settings, then this is up to the applying entity to store this information. netconfig would only be responsible for obtaining the settings and notifying the new management entity.
The new management entity would either:
A) invoke the agent, or
B) apply the settings itself.
Preferably, A & B would use the same API and be subclasses of some generic abstract interface. Similarly to how we handle auth_protos, or perhaps modeled after resolv_ops.
src/netconfig.c struct netconfig { · line 85
Quoted 9 lines
src/netconfig.c +2
-0char **dns4_overrides;char **dns6_overrides;char **dns4_list;@@ -70,6 +81,8 @@ struct netconfig {char *v6_gateway_str;char *v4_domain;char **v6_domains; +unsigned int pending_v4_set; +unsigned int pending_v6_set;
These probably belong in the new management entity as well.
Quoted 69 lines
src/netconfig.c +23
-14const struct l_settings *active_settings;@@ -813,10 +826,8 @@ static void netconfig_route6_add_cb(int error, uint16_t type, } } -static bool netconfig_ipv4_routes_install (struct netconfig *netconfig) +static bool netconfig_ipv4_subnet_route_install (struct netconfig *netconfig) { - L_AUTO_FREE_VAR(char *, gateway) = NULL; -const uint8_t *gateway_mac =NULL ;struct in_addr in_addr;char ip[INET_ADDRSTRLEN ];char network[INET_ADDRSTRLEN ];@@ -839,10 +850,19 @@ static bool netconfig_ipv4_routes_install(struct netconfig *netconfig) netconfig_route_generic_cb, netconfig, NULL)) {l_error ("netconfig: Failed to add subnet route." ); -return false; } +return true; +} + +static bool netconfig_ipv4_gateway_route_install (struct netconfig *netconfig) +{ + L_AUTO_FREE_VAR(char *, gateway) = NULL; +const uint8_t *gateway_mac =NULL ; +struct in_addr in_addr; +char ip[INET_ADDRSTRLEN ]; + gateway =netconfig_ipv4_get_gateway (netconfig, &gateway_mac);if (!gateway) { l_debug("No gateway obtained from %s.",@@ -858,6 +878,10 @@ static bool netconfig_ipv4_routes_install(struct netconfig *netconfig)return true; } +if (!l_rtnl_address_get_address (netconfig->v4_address, ip) || +inet_pton (AF_INET , ip, &in_addr) <1 ) +return false; + netconfig->route4_add_gateway_cmd_id = l_rtnl_route4_add_gateway(rtnl, netconfig->ifindex, gateway, ip, ROUTE_PRIORITY_OFFSET,@@ -871,50 +895,77 @@ static bool netconfig_ipv4_routes_install(struct netconfig *netconfig)return false; } - if (gateway_mac) { - /* - * Attempt to use the gateway MAC address received from the AP - * by writing the mapping directly into the netdev's ARP table - * so as to save one data frame roundtrip before first IP - * connections are established. This is very low-priority but - * print error messages just because they may indicate bigger - * problems. - */ - if (!l_rtnl_neighbor_set_hwaddr(rtnl, netconfig->ifindex, +/* +* Attempt to use the gateway MAC address received from the AP by +* writing the mapping directly into the netdev's ARP table so as +* to save one data frame roundtrip before first IP connections +* are established. This is very low-priority but print error +* messages just because they may indicate bigger problems. +*/ + if (gateway_mac && !l_rtnl_neighbor_set_hwaddr(rtnl, netconfig->ifindex,
src/netconfig.c static bool netconfig_ipv4_routes_install(struct netconfig *netconfig) · line 914
Quoted 10 lines
src/netconfig.c +4
-1AF_INET, &netconfig->fils_override->ipv4_gateway, gateway_mac, 6, netconfig_set_neighbor_entry_cb, NULL, NULL)) -l_debug ("l_rtnl_neighbor_set_hwaddr failed" ); +l_debug ("l_rtnl_neighbor_set_hwaddr failed" ); + +return true; +}
I cherry-picked these changes into a separate commit, please review.
Quoted 23 lines
src/netconfig.c +21
-0+ +static bool netconfig_ipv6_static_gateway_route_install ( +struct netconfig *netconfig) +{ + _auto_(l_rtnl_route_free) struct l_rtnl_route *gateway = NULL; +const uint8_t *gateway_mac; + + gateway =netconfig_get_static6_gateway (netconfig, + &netconfig->v6_gateway_str, + &gateway_mac); +if (!gateway) { +l_debug ("No IPv6 gateway set" ); +return true; } + netconfig->route6_add_cmd_id =l_rtnl_route_add (rtnl, + netconfig->ifindex, + gateway, + netconfig_route6_add_cb, + netconfig,NULL ); +if (!L_WARN_ON (unlikely (!netconfig->route6_add_cmd_id))) +return false; +
src/netconfig.c static bool netconfig_ipv4_routes_install(struct netconfig *netconfig) · line 947
Quoted 10 lines
src/netconfig.c +8
-0+if (gateway_mac && !l_rtnl_neighbor_set_hwaddr (rtnl, netconfig->ifindex, +AF_INET6 , + netconfig->fils_override->ipv6_gateway, + gateway_mac,6 , + netconfig_set_neighbor_entry_cb,NULL , +NULL )) +l_debug ("l_rtnl_neighbor_set_hwaddr failed" ); +return true; }
Note that netconfig behaves differently with dhcp6 client vs dhcp. With dhcp, netconfig is the one setting routes and addresses. But with dhcp6, we let the dhcp6_client itself set the route and the address. So this may need to be refactored to act similarly to how dhcp client is managed. Otherwise the settings would be applied despite the agent being registered.
src/netconfig.c static bool netconfig_ipv4_routes_install(struct netconfig *netconfig) · line 951
Quoted 4 lines
src/netconfig.c +3
-0+static void netconfig_set (struct netconfig *netconfig,uint8_t af, +unsigned int changed); +
doc/coding-style.txt item M17
<snip>
Quoted 13 lines
src/netconfig.c +9
-0@@ -978,21 +1005,169 @@ static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, "Error %d: %s", error, strerror(-error)); } +static bool netconfig_address_cmp_address (const struct l_rtnl_address *a, +const struct l_rtnl_address *b) +{ +char str_a[INET6_ADDRSTRLEN ]; +char str_b[INET6_ADDRSTRLEN ]; + +if (a == b) +return true; +
src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1026
Quoted 10 lines
src/netconfig.c +10
-0+if (!a || !b) +return false; + +if (!l_rtnl_address_get_address (a, str_a) || + !l_rtnl_address_get_address (b, str_b)) +return false; + +return !strcmp (str_a, str_b); +} +
This probably belongs in ell.
Quoted 30 lines
src/netconfig.c +30
-0+static void netconfig_set (struct netconfig *netconfig,uint8_t af, +unsigned int changed) +{ +struct l_rtnl_address *stale_addr; + +if (af ==AF_INET ) + stale_addr =l_steal_ptr (netconfig->stale_v4_address); +else + stale_addr =l_steal_ptr (netconfig->stale_v6_address); + +if (stale_addr) { +L_WARN_ON (!l_rtnl_ifaddr_delete (rtnl, netconfig->ifindex, + stale_addr, + netconfig_ifaddr_del_cmd_cb, + netconfig,NULL )); +l_rtnl_address_free (stale_addr); + } + +if (af ==AF_INET ) { +if (!netconfig->v4_address) +return ; + +if ((changed & (NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK )) && + !netconfig->addr4_add_cmd_id) { + netconfig->addr4_add_cmd_id =l_rtnl_ifaddr_add (rtnl, + netconfig->ifindex, + netconfig->v4_address, + netconfig_ipv4_ifaddr_add_cmd_cb, + netconfig,NULL );
src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1079
Quoted 10 lines
src/netconfig.c +10
-0+if (!L_WARN_ON (!netconfig->addr4_add_cmd_id)) + changed &= ~(NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK ); + } + +/* +* If we either started the address addition now or one was +* already in progress, wait for that operation's callback +* and we'll be called again to set the rest of the values +* in the changed bitmask.
So I'd rather see the ipv4_ifaddr_add_cmd_cb or an intermediate function being invoked than trying to re-invoke netconfig_set in the callback.
Quoted 8 lines
src/netconfig.c +8
-0+*/ +if (netconfig->addr4_add_cmd_id) { + netconfig->pending_v4_set |= changed; +return ; + } + +/* +* For IPv6 the address, the subnet route and the gateway
src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1097
Quoted 10 lines
src/netconfig.c +10
-0+* route are handled automatically for DHCP, only cover the +* static and FILS-provided cases here. +*/ + }else if (netconfig->rtm_v6_protocol ==RTPROT_STATIC || + (netconfig->fils_override && + !l_memeqzero (netconfig->fils_override->ipv6_addr, +16 ))) { +if (!netconfig->v6_address) +return ; +
See my comment above about dhcp6_client setting addresses & routes by itself.
Quoted 9 lines
src/netconfig.c +9
-0+if ((changed & (NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK )) && + !netconfig->addr6_add_cmd_id) { + netconfig->addr6_add_cmd_id =l_rtnl_ifaddr_add (rtnl, + netconfig->ifindex, + netconfig->v6_address, + netconfig_ipv6_ifaddr_add_cmd_cb, + netconfig,NULL ); +if (!L_WARN_ON (!netconfig->addr6_add_cmd_id))
src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1116
Quoted 10 lines
src/netconfig.c +10
-0+ changed &= ~(NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK ); + } + +/* +* If we either started the address addition now or one was +* already in progress, wait for that operation's callback +* and we'll be called again to set the rest of the values +* in the changed bitmask. +*/
Is there a reason why we need to wait for the ipv4 address to be set prior to setting the v6 address?
src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1129
Quoted 13 lines
src/netconfig.c +13
-0+if (netconfig->addr6_add_cmd_id) { + netconfig->pending_v4_set |= changed; +return ; + } + } + +if (af ==AF_INET ) { +if (changed &NETCONFIG_CHANGED_GATEWAY ) { +netconfig_gateway_to_arp (netconfig); + +if (netconfig_ipv4_gateway_route_install (netconfig)) + changed &= ~NETCONFIG_CHANGED_GATEWAY ; + }else if (netconfig->notify) {
This is really quite weird since netconfig_ipv4_gateway_route_install() checks that the gateway is NULL. What is this trying to take care of?
Quoted 56 lines
src/netconfig.c +32
-5+/* +* The gateway route addition callback notifies the user +* of netconfig success if a gateway is provided, otherwise +* notify here. +*/ + netconfig->notify (NETCONFIG_EVENT_CONNECTED , + netconfig->user_data); + netconfig->notify =NULL ; + } + }else if (netconfig->rtm_v6_protocol ==RTPROT_STATIC || + (netconfig->fils_override && + !l_memeqzero (netconfig->fils_override->ipv6_gateway, +16 ))) { +if (changed & (NETCONFIG_CHANGED_GATEWAY )) +if (netconfig_ipv6_static_gateway_route_install ( + netconfig)) + changed &= ~NETCONFIG_CHANGED_GATEWAY ; + } + +if (changed &NETCONFIG_CHANGED_DNS ) { +netconfig_set_dns (netconfig); + changed &= ~NETCONFIG_CHANGED_DNS ; + } + +if (changed &NETCONFIG_CHANGED_DOMAINS ) { +netconfig_set_domains (netconfig); + changed &= ~NETCONFIG_CHANGED_DOMAINS ; + } +} +static void netconfig_ipv4_dhcp_event_handler (struct l_dhcp_client *client,enum l_dhcp_client_event event,void *userdata) {struct netconfig *netconfig = userdata; +unsigned int changed =0 ;l_debug ("DHCPv4 event %d" , event);switch (event) {case L_DHCP_CLIENT_EVENT_IP_CHANGED : -L_WARN_ON (!l_rtnl_ifaddr_delete (rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ifaddr_del_cmd_cb, - netconfig,NULL )); -/* Fall through. */ case L_DHCP_CLIENT_EVENT_LEASE_OBTAINED : {char *gateway_str;@@ -1004,9 +1179,19 @@ static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client,else {l_free (netconfig->v4_gateway_str); netconfig->v4_gateway_str = gateway_str; + changed |=NETCONFIG_CHANGED_GATEWAY ; }
src/netconfig.c static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client, · line 1194
Quoted 10 lines
src/netconfig.c +9
-0address =netconfig_get_dhcp4_address (netconfig); + +if (!netconfig_address_cmp_prefix_len (netconfig->v4_address, + address)) + changed |=NETCONFIG_CHANGED_NETMASK ; + +if (!netconfig_address_cmp_address (netconfig->v4_address, + address)) + changed |=NETCONFIG_CHANGED_ADDRESS ; +
My impression is that the comparison of new vs old settings should be given over to the new management entity.
Quoted 32 lines
src/netconfig.c +6
-13l_rtnl_address_free (netconfig->v4_address); netconfig->v4_address = address;@@ -1016,26 +1201,36 @@ static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client,return ; } -netconfig_dns_list_update (netconfig,AF_INET ); -netconfig_domains_update (netconfig,AF_INET ); +if (netconfig_dns_list_update (netconfig,AF_INET )) + changed |=NETCONFIG_CHANGED_DNS ; -L_WARN_ON (!(netconfig->addr4_add_cmd_id = -l_rtnl_ifaddr_add (rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ipv4_ifaddr_add_cmd_cb, - netconfig,NULL ))); +if (netconfig_domains_update (netconfig,AF_INET )) + changed |=NETCONFIG_CHANGED_DOMAINS ; + +netconfig_set (netconfig,AF_INET , changed);break ; }case L_DHCP_CLIENT_EVENT_LEASE_RENEWED :break ;case L_DHCP_CLIENT_EVENT_LEASE_EXPIRED : -L_WARN_ON (!l_rtnl_ifaddr_delete (rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ifaddr_del_cmd_cb, - netconfig,NULL )); -l_rtnl_address_free (netconfig->v4_address); - netconfig->v4_address =NULL ;
src/netconfig.c static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client, · line 1224
Quoted 10 lines
src/netconfig.c +9
-1-l_free (l_steal_ptr (netconfig->v4_gateway_str)); +l_debug ("Lease for interface %u expired" , netconfig->ifindex); + changed =NETCONFIG_CHANGED_ADDRESS |NETCONFIG_CHANGED_NETMASK ; +l_rtnl_address_free (netconfig->stale_v4_address); + netconfig->stale_v4_address = +l_steal_ptr (netconfig->v4_address); + +if (netconfig->v4_gateway_str) { + changed |=NETCONFIG_CHANGED_GATEWAY ; +l_free (l_steal_ptr (netconfig->v4_gateway_str));
Gateway should be cleared, not changed. I believe this is done automagically when removing the address.
src/netconfig.c static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client, · line 1233
Quoted 9 lines
src/netconfig.c +9
-0+ } + +if (netconfig_dns_list_update (netconfig,AF_INET )) + changed |=NETCONFIG_CHANGED_DNS ; + +if (netconfig_domains_update (netconfig,AF_INET )) + changed |=NETCONFIG_CHANGED_DOMAINS ; + +netconfig_set (netconfig,AF_INET , changed);
Perhaps lease expiration, and thus the clearing out of all settings should be a separate operation? There's not much point setting domains, dns, etc in this case.
src/netconfig.c static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client, · line 1236
Quoted 3 lines
src/netconfig.c +0
-0/* Fall through. */ case L_DHCP_CLIENT_EVENT_NO_LEASE :
<snip>
Regards,
-Denis
Andrew Zaborowski
Hi Denis,
Quoted 7 lines · Denis Kenzior
Quoted 3 lines · Andrew Zaborowski
src/netconfig.c | 541 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 398 insertions(+), 143 deletions(-)It would be far easier if this was broken down into more digestible chunks. I could even apply some right away since many make sense on their own.
Right, it's grown some again but it was already a result of splitting the previous version.
Quoted 9 lines
Quoted 9 lines
src/netconfig.c +0
-0@@ -52,6 +52,15 @@#include "src/netconfig.h" #include "src/sysfs.h"
Quoted 5 lines
src/netconfig.c line 57
Quoted 3 lines
src/netconfig.c +3
-0+enum netconfig_changed_flags { +NETCONFIG_CHANGED_ADDRESS =1 <<0 , +NETCONFIG_CHANGED_NETMASK =1 <<1 ,Isn't netmask effectively part of the address?
It's more closely related to the gateway since it's part of talking to outside subnets (unlike address).. but you can treat it in different ways. I tried to make this granular to give us flexibility in how this gets exposed to user but ok, let's skip the netmask.
Quoted 26 lines
If netmask changes, then you
need to change the connected route and the address on the interface anyway.Quoted 10 lines
src/netconfig.c +6
-0+NETCONFIG_CHANGED_GATEWAY =1 <<2 , +NETCONFIG_CHANGED_DNS =1 <<3 , +NETCONFIG_CHANGED_DOMAINS =1 <<4 , + NETCONFIG_CHANGED_ALL = 0x1f, +}; +struct netconfig {uint32_t ifindex;struct l_dhcp_client *dhcp_client;src/netconfig.c struct netconfig { · line 73
Quoted 6 lines
src/netconfig.c +2
-0@@ -59,7 +68,9 @@ struct netconfig {uint8_t rtm_protocol;uint8_t rtm_v6_protocol;struct l_rtnl_address *v4_address; +struct l_rtnl_address *stale_v4_address;struct l_rtnl_address *v6_address; +struct l_rtnl_address *stale_v6_address;I really don't think these belong here. If we're going in the direction of netconfig delegating the management of applying IP configuration settings, then this is up to the applying entity to store this information. netconfig would only be responsible for obtaining the settings and notifying the new management entity.
Quoted 7 lines
The new management entity would either:
A) invoke the agent, or
B) apply the settings itself.Preferably, A & B would use the same API and be subclasses of some generic abstract interface. Similarly to how we handle
auth_protos, or perhaps modeled afterresolv_ops.
Ok, having these RTNL calls etc., in a separate file from where we handle the config methods and policies will make the code a little clearer but the API will probably need to include the optional details like the MAC addresses.
Quoted 86 lines
src/netconfig.c struct netconfig { · line 85
Quoted 10 lines
src/netconfig.c +2
-0char **dns4_overrides;char **dns6_overrides;char **dns4_list;@@ -70,6 +81,8 @@ struct netconfig {char *v6_gateway_str;char *v4_domain;char **v6_domains; +unsigned int pending_v4_set; +unsigned int pending_v6_set;These probably belong in the new management entity as well.
Quoted 73 lines
src/netconfig.c +23
-14const struct l_settings *active_settings;@@ -813,10 +826,8 @@ static void netconfig_route6_add_cb(int error, uint16_t type, } } -static bool netconfig_ipv4_routes_install (struct netconfig *netconfig) +static bool netconfig_ipv4_subnet_route_install (struct netconfig *netconfig) { - L_AUTO_FREE_VAR(char *, gateway) = NULL; -const uint8_t *gateway_mac =NULL ;struct in_addr in_addr;char ip[INET_ADDRSTRLEN ];char network[INET_ADDRSTRLEN ];@@ -839,10 +850,19 @@ static bool netconfig_ipv4_routes_install(struct netconfig *netconfig) netconfig_route_generic_cb, netconfig, NULL)) {l_error ("netconfig: Failed to add subnet route." ); -return false; } +return true; +} + +static bool netconfig_ipv4_gateway_route_install (struct netconfig *netconfig) +{ + L_AUTO_FREE_VAR(char *, gateway) = NULL; +const uint8_t *gateway_mac =NULL ; +struct in_addr in_addr; +char ip[INET_ADDRSTRLEN ]; + gateway =netconfig_ipv4_get_gateway (netconfig, &gateway_mac);if (!gateway) { l_debug("No gateway obtained from %s.",@@ -858,6 +878,10 @@ static bool netconfig_ipv4_routes_install(struct netconfig *netconfig)return true; } +if (!l_rtnl_address_get_address (netconfig->v4_address, ip) || +inet_pton (AF_INET , ip, &in_addr) <1 ) +return false; + netconfig->route4_add_gateway_cmd_id = l_rtnl_route4_add_gateway(rtnl, netconfig->ifindex, gateway, ip, ROUTE_PRIORITY_OFFSET,@@ -871,50 +895,77 @@ static bool netconfig_ipv4_routes_install(struct netconfig *netconfig)return false; } - if (gateway_mac) { - /* - * Attempt to use the gateway MAC address received from the AP - * by writing the mapping directly into the netdev's ARP table - * so as to save one data frame roundtrip before first IP - * connections are established. This is very low-priority but - * print error messages just because they may indicate bigger - * problems. - */ - if (!l_rtnl_neighbor_set_hwaddr(rtnl, netconfig->ifindex, +/* +* Attempt to use the gateway MAC address received from the AP by +* writing the mapping directly into the netdev's ARP table so as +* to save one data frame roundtrip before first IP connections +* are established. This is very low-priority but print error +* messages just because they may indicate bigger problems. +*/ + if (gateway_mac && !l_rtnl_neighbor_set_hwaddr(rtnl, netconfig->ifindex, AF_INET, &netconfig->fils_override->ipv4_gateway, gateway_mac, 6, netconfig_set_neighbor_entry_cb, NULL,
Quoted 8 lines
src/netconfig.c static bool netconfig_ipv4_routes_install(struct netconfig *netconfig) · line 914
Quoted 6 lines
src/netconfig.c +4
-1NULL)) -l_debug ("l_rtnl_neighbor_set_hwaddr failed" ); +l_debug ("l_rtnl_neighbor_set_hwaddr failed" ); + +return true; +}I cherry-picked these changes into a separate commit, please review.
Looks good.
Quoted 32 lines
Quoted 32 lines
src/netconfig.c +29
-0+ +static bool netconfig_ipv6_static_gateway_route_install ( +struct netconfig *netconfig) +{ + _auto_(l_rtnl_route_free) struct l_rtnl_route *gateway = NULL; +const uint8_t *gateway_mac; + + gateway =netconfig_get_static6_gateway (netconfig, + &netconfig->v6_gateway_str, + &gateway_mac); +if (!gateway) { +l_debug ("No IPv6 gateway set" ); +return true; } + netconfig->route6_add_cmd_id =l_rtnl_route_add (rtnl, + netconfig->ifindex, + gateway, + netconfig_route6_add_cb, + netconfig,NULL ); +if (!L_WARN_ON (unlikely (!netconfig->route6_add_cmd_id))) +return false; + +if (gateway_mac && !l_rtnl_neighbor_set_hwaddr (rtnl, netconfig->ifindex, +AF_INET6 , + netconfig->fils_override->ipv6_gateway, + gateway_mac,6 , + netconfig_set_neighbor_entry_cb,NULL , +NULL )) +l_debug ("l_rtnl_neighbor_set_hwaddr failed" ); +
Quoted 8 lines
src/netconfig.c static bool netconfig_ipv4_routes_install(struct netconfig *netconfig) · line 947
Quoted 2 lines
src/netconfig.c +0
-0return true; }Note that netconfig behaves differently with dhcp6 client vs dhcp. With dhcp, netconfig is the one setting routes and addresses. But with dhcp6, we let the
dhcp6_clientitself set the route and the address. So this may need to be refactored to act similarly to how dhcp client is managed. Otherwise the settings would be applied despite the agent being registered.
I don't think that's much of an issue but let's do it, one difficulty is going to be synchronising the ell and iwd changes though.
Quoted 7 lines
src/netconfig.c static bool netconfig_ipv4_routes_install(struct netconfig *netconfig) · line 951
Quoted 5 lines
src/netconfig.c +3
-0+static void netconfig_set (struct netconfig *netconfig,uint8_t af, +unsigned int changed); +
doc/coding-style.txtitem M17
It's the exception M17 talks about.
Quoted 20 lines
<snip>
Quoted 17 lines
src/netconfig.c +13
-0@@ -978,21 +1005,169 @@ static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, "Error %d: %s", error, strerror(-error)); } +static bool netconfig_address_cmp_address (const struct l_rtnl_address *a, +const struct l_rtnl_address *b) +{ +char str_a[INET6_ADDRSTRLEN ]; +char str_b[INET6_ADDRSTRLEN ]; + +if (a == b) +return true; + +if (!a || !b) +return false; + + if (!l_rtnl_address_get_address(a, str_a) ||
Quoted 8 lines
src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1026
Quoted 6 lines
src/netconfig.c +6
-0+ !l_rtnl_address_get_address(b, str_b)) +return false; + +return !strcmp (str_a, str_b); +} +This probably belongs in ell.
Ok.
Quoted 36 lines
Quoted 36 lines
src/netconfig.c +35
-0+static void netconfig_set (struct netconfig *netconfig,uint8_t af, +unsigned int changed) +{ +struct l_rtnl_address *stale_addr; + +if (af ==AF_INET ) + stale_addr =l_steal_ptr (netconfig->stale_v4_address); +else + stale_addr =l_steal_ptr (netconfig->stale_v6_address); + +if (stale_addr) { +L_WARN_ON (!l_rtnl_ifaddr_delete (rtnl, netconfig->ifindex, + stale_addr, + netconfig_ifaddr_del_cmd_cb, + netconfig,NULL )); +l_rtnl_address_free (stale_addr); + } + +if (af ==AF_INET ) { +if (!netconfig->v4_address) +return ; + +if ((changed & (NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK )) && + !netconfig->addr4_add_cmd_id) { + netconfig->addr4_add_cmd_id =l_rtnl_ifaddr_add (rtnl, + netconfig->ifindex, + netconfig->v4_address, + netconfig_ipv4_ifaddr_add_cmd_cb, + netconfig,NULL ); +if (!L_WARN_ON (!netconfig->addr4_add_cmd_id)) + changed &= ~(NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK ); + } +
Quoted 8 lines
src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1079
Quoted 5 lines
src/netconfig.c +5
-0+/* +* If we either started the address addition now or one was +* already in progress, wait for that operation's callback +* and we'll be called again to set the rest of the values +* in the changed bitmask. So I'd rather see the
ipv4_ifaddr_add_cmd_cbor an intermediate function being invoked than trying to re-invokenetconfig_setin the callback.
The advantage of this approach is that it handles these async operations well, i.e. you look at the bitmask and start the async ops to apply the config bits that have changed, clearing the corresponding bits from the bitmap. If during one of those calls a new change happens we don't apply the remaining bits and go back to the beginning. Let me see if these can be done differently...
Quoted 42 lines
Quoted 9 lines
src/netconfig.c +8
-0+*/ +if (netconfig->addr4_add_cmd_id) { + netconfig->pending_v4_set |= changed; +return ; + } + +/* +* For IPv6 the address, the subnet route and the gateway src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1097
Quoted 10 lines
src/netconfig.c +10
-0+* route are handled automatically for DHCP, only cover the +* static and FILS-provided cases here. +*/ + }else if (netconfig->rtm_v6_protocol ==RTPROT_STATIC || + (netconfig->fils_override && + !l_memeqzero (netconfig->fils_override->ipv6_addr, +16 ))) { +if (!netconfig->v6_address) +return ; +See my comment above about
dhcp6_clientsetting addresses & routes by itself.Quoted 9 lines
src/netconfig.c +9
-0+if ((changed & (NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK )) && + !netconfig->addr6_add_cmd_id) { + netconfig->addr6_add_cmd_id =l_rtnl_ifaddr_add (rtnl, + netconfig->ifindex, + netconfig->v6_address, + netconfig_ipv6_ifaddr_add_cmd_cb, + netconfig,NULL ); +if (!L_WARN_ON (!netconfig->addr6_add_cmd_id))src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1116
Quoted 10 lines
src/netconfig.c +10
-0+ changed &= ~(NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK ); + } + +/* +* If we either started the address addition now or one was +* already in progress, wait for that operation's callback +* and we'll be called again to set the rest of the values +* in the changed bitmask. +*/
Quoted 2 lines
Is there a reason why we need to wait for the ipv4 address to be set prior to setting the v6 address?
So within netconfig_set we don't wait, we can be setting them simultaneously.
Quoted 17 lines
Quoted 4 lines
src/netconfig.c +3
-0+if (netconfig->addr6_add_cmd_id) { + netconfig->pending_v4_set |= changed; +return ;src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1129
Quoted 10 lines
src/netconfig.c +10
-0+ } + } + +if (af ==AF_INET ) { +if (changed &NETCONFIG_CHANGED_GATEWAY ) { +netconfig_gateway_to_arp (netconfig); + +if (netconfig_ipv4_gateway_route_install (netconfig)) + changed &= ~NETCONFIG_CHANGED_GATEWAY ; + }else if (netconfig->notify) {This is really quite weird since
netconfig_ipv4_gateway_route_install()checks that the gateway is NULL. What is this trying to take care of?
You mean what is the if (netconfig_ipv4_gateway_route_install) trying to take care of? Error handling, though errors are not really expected to happen there.
Quoted 57 lines
Quoted 57 lines
src/netconfig.c +32
-5+/* +* The gateway route addition callback notifies the user +* of netconfig success if a gateway is provided, otherwise +* notify here. +*/ + netconfig->notify (NETCONFIG_EVENT_CONNECTED , + netconfig->user_data); + netconfig->notify =NULL ; + } + }else if (netconfig->rtm_v6_protocol ==RTPROT_STATIC || + (netconfig->fils_override && + !l_memeqzero (netconfig->fils_override->ipv6_gateway, +16 ))) { +if (changed & (NETCONFIG_CHANGED_GATEWAY )) +if (netconfig_ipv6_static_gateway_route_install ( + netconfig)) + changed &= ~NETCONFIG_CHANGED_GATEWAY ; + } + +if (changed &NETCONFIG_CHANGED_DNS ) { +netconfig_set_dns (netconfig); + changed &= ~NETCONFIG_CHANGED_DNS ; + } + +if (changed &NETCONFIG_CHANGED_DOMAINS ) { +netconfig_set_domains (netconfig); + changed &= ~NETCONFIG_CHANGED_DOMAINS ; + } +} +static void netconfig_ipv4_dhcp_event_handler (struct l_dhcp_client *client,enum l_dhcp_client_event event,void *userdata) {struct netconfig *netconfig = userdata; +unsigned int changed =0 ;l_debug ("DHCPv4 event %d" , event);switch (event) {case L_DHCP_CLIENT_EVENT_IP_CHANGED : -L_WARN_ON (!l_rtnl_ifaddr_delete (rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ifaddr_del_cmd_cb, - netconfig,NULL )); -/* Fall through. */ case L_DHCP_CLIENT_EVENT_LEASE_OBTAINED : {char *gateway_str;@@ -1004,9 +1179,19 @@ static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client,else {l_free (netconfig->v4_gateway_str); netconfig->v4_gateway_str = gateway_str; + changed |=NETCONFIG_CHANGED_GATEWAY ; }
Quoted 13 lines
src/netconfig.c static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client, · line 1194
Quoted 10 lines
src/netconfig.c +9
-0address =netconfig_get_dhcp4_address (netconfig); + +if (!netconfig_address_cmp_prefix_len (netconfig->v4_address, + address)) + changed |=NETCONFIG_CHANGED_NETMASK ; + +if (!netconfig_address_cmp_address (netconfig->v4_address, + address)) + changed |=NETCONFIG_CHANGED_ADDRESS ; +My impression is that the comparison of new vs old settings should be given over to the new management entity.
Ok.
So basically we pass a set of new values to the new "netconfig-committer" entity, it checks what's changed, calls the agent method first, if no agent is registered it falls back to the local implementation.
Honestly I see no place for an "ops" structure there, it can be forced between the "entity" and the agent code but it's adding more problems than solving.
Quoted 38 lines
Quoted 38 lines
src/netconfig.c +10
-14l_rtnl_address_free (netconfig->v4_address); netconfig->v4_address = address;@@ -1016,26 +1201,36 @@ static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client,return ; } -netconfig_dns_list_update (netconfig,AF_INET ); -netconfig_domains_update (netconfig,AF_INET ); +if (netconfig_dns_list_update (netconfig,AF_INET )) + changed |=NETCONFIG_CHANGED_DNS ; -L_WARN_ON (!(netconfig->addr4_add_cmd_id = -l_rtnl_ifaddr_add (rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ipv4_ifaddr_add_cmd_cb, - netconfig,NULL ))); +if (netconfig_domains_update (netconfig,AF_INET )) + changed |=NETCONFIG_CHANGED_DOMAINS ; + +netconfig_set (netconfig,AF_INET , changed);break ; }case L_DHCP_CLIENT_EVENT_LEASE_RENEWED :break ;case L_DHCP_CLIENT_EVENT_LEASE_EXPIRED : -L_WARN_ON (!l_rtnl_ifaddr_delete (rtnl, netconfig->ifindex, - netconfig->v4_address, - netconfig_ifaddr_del_cmd_cb, - netconfig,NULL )); -l_rtnl_address_free (netconfig->v4_address); - netconfig->v4_address =NULL ; -l_free (l_steal_ptr (netconfig->v4_gateway_str)); +l_debug ("Lease for interface %u expired" , netconfig->ifindex); + changed =NETCONFIG_CHANGED_ADDRESS |NETCONFIG_CHANGED_NETMASK ; +l_rtnl_address_free (netconfig->stale_v4_address); + netconfig->stale_v4_address =
Quoted 8 lines
src/netconfig.c static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client, · line 1224
Quoted 5 lines
src/netconfig.c +5
-0+l_steal_ptr (netconfig->v4_address); + +if (netconfig->v4_gateway_str) { + changed |=NETCONFIG_CHANGED_GATEWAY ; +l_free (l_steal_ptr (netconfig->v4_gateway_str));Gateway should be cleared, not changed. I believe this is done automagically when removing the address.
Right, netconfig_set doesn't take the "CHANGED" part literally, it's more like a dbus property changed signal ;-)
Quoted 13 lines
src/netconfig.c static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client, · line 1233
Quoted 10 lines
src/netconfig.c +9
-0+ } + +if (netconfig_dns_list_update (netconfig,AF_INET )) + changed |=NETCONFIG_CHANGED_DNS ; + +if (netconfig_domains_update (netconfig,AF_INET )) + changed |=NETCONFIG_CHANGED_DOMAINS ; + +netconfig_set (netconfig,AF_INET , changed);Perhaps lease expiration, and thus the clearing out of all settings should be a separate operation? There's not much point setting domains, dns, etc in this case.
Special-casing it won't make the code clearer but ok.
Best regards
Denis Kenzior
Hi Andrew,
Quoted 10 lines
Quoted 10 lines
I really don't think these belong here. If we're going in the direction of netconfig delegating the management of applying IP configuration settings, then this is up to the applying entity to store this information. netconfig would only be responsible for obtaining the settings and notifying the new management entity.
The new management entity would either:
A) invoke the agent, or
B) apply the settings itself.
Quoted 9 lines
Quoted 3 lines
Preferably, A & B would use the same API and be subclasses of some generic abstract interface. Similarly to how we handle
auth_protos, or perhaps modeled afterresolv_ops.Ok, having these RTNL calls etc., in a separate file from where we handle the config methods and policies will make the code a little clearer but the API will probably need to include the optional details like the MAC addresses.
That is fine. Every time we logically separate pieces behind a clear API makes the code more maintainable and easier to understand. We pay a bit in code size, but it is worth it in my opinion.
Quoted 8 lines
Quoted 5 lines
Note that netconfig behaves differently with dhcp6 client vs dhcp. With dhcp, netconfig is the one setting routes and addresses. But with dhcp6, we let the
dhcp6_clientitself set the route and the address. So this may need to be refactored to act similarly to how dhcp client is managed. Otherwise the settings would be applied despite the agent being registered.I don't think that's much of an issue but let's do it, one difficulty is going to be synchronising the ell and iwd changes though.
So I'm not sure how to interpret the statement that it isn't 'much of an issue'?
The contract we have is that if the agent is registered, then iwd doesn't
apply any settings to the netdevs. But what I'm pointing out above is that: the way l_dhcp6_client is being driven today, this contract is broken. netconfig delegates setting of the address and routes to l_dhcp6_client/l_icmp6_client and these settings are always applied if IPv6 support is enabled / detected.
So yes, this is a an issue. And it should probably be among the first things that are refactored as a result of this agent-based approach since these changes can be regression-tested rather easily.
Quoted 44 lines
Quoted 35 lines
Quoted 35 lines
src/netconfig.c +35
-0+static void netconfig_set (struct netconfig *netconfig,uint8_t af, +unsigned int changed) +{ +struct l_rtnl_address *stale_addr; + +if (af ==AF_INET ) + stale_addr =l_steal_ptr (netconfig->stale_v4_address); +else + stale_addr =l_steal_ptr (netconfig->stale_v6_address); + +if (stale_addr) { +L_WARN_ON (!l_rtnl_ifaddr_delete (rtnl, netconfig->ifindex, + stale_addr, + netconfig_ifaddr_del_cmd_cb, + netconfig,NULL )); +l_rtnl_address_free (stale_addr); + } + +if (af ==AF_INET ) { +if (!netconfig->v4_address) +return ; + +if ((changed & (NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK )) && + !netconfig->addr4_add_cmd_id) { + netconfig->addr4_add_cmd_id =l_rtnl_ifaddr_add (rtnl, + netconfig->ifindex, + netconfig->v4_address, + netconfig_ipv4_ifaddr_add_cmd_cb, + netconfig,NULL ); +if (!L_WARN_ON (!netconfig->addr4_add_cmd_id)) + changed &= ~(NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK ); + } +Quoted 8 lines
src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1079
Quoted 5 lines
src/netconfig.c +5
-0+/* +* If we either started the address addition now or one was +* already in progress, wait for that operation's callback +* and we'll be called again to set the rest of the values +* in the changed bitmask. So I'd rather see the
ipv4_ifaddr_add_cmd_cbor an intermediate function being invoked than trying to re-invokenetconfig_setin the callback.
Quoted 7 lines
The advantage of this approach is that it handles these async operations well, i.e. you look at the bitmask and start the async ops to apply the config bits that have changed, clearing the corresponding bits from the bitmap. If during one of those calls a new change happens we don't apply the remaining bits and go back to the beginning. Let me see if these can be done differently...
Ok, I can understand the logic behind this, but then again, we set the routes, dns and domains once the address is set. So you can really only 'interrupt' the ongoing setting operation after the address has been set. Explicitly calling the address set callback would better reflect this reality. But I can be convinced either way...
Quoted 42 lines
Quoted 42 lines
Quoted 9 lines
src/netconfig.c +8
-0+*/ +if (netconfig->addr4_add_cmd_id) { + netconfig->pending_v4_set |= changed; +return ; + } + +/* +* For IPv6 the address, the subnet route and the gateway src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1097
Quoted 10 lines
src/netconfig.c +10
-0+* route are handled automatically for DHCP, only cover the +* static and FILS-provided cases here. +*/ + }else if (netconfig->rtm_v6_protocol ==RTPROT_STATIC || + (netconfig->fils_override && + !l_memeqzero (netconfig->fils_override->ipv6_addr, +16 ))) { +if (!netconfig->v6_address) +return ; +See my comment above about
dhcp6_clientsetting addresses & routes by itself.Quoted 19 lines
src/netconfig.c +19
-0+if ((changed & (NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK )) && + !netconfig->addr6_add_cmd_id) { + netconfig->addr6_add_cmd_id =l_rtnl_ifaddr_add (rtnl, + netconfig->ifindex, + netconfig->v6_address, + netconfig_ipv6_ifaddr_add_cmd_cb, + netconfig,NULL ); +if (!L_WARN_ON (!netconfig->addr6_add_cmd_id)) + changed &= ~(NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK ); + } + +/* +* If we either started the address addition now or one was +* already in progress, wait for that operation's callback +* and we'll be called again to set the rest of the values +* in the changed bitmask. +*/
Quoted 5 lines
Quoted 2 lines
Is there a reason why we need to wait for the ipv4 address to be set prior to setting the v6 address?
So within
netconfig_setwe don't wait, we can be setting them simultaneously.
Ok, cool.
Quoted 18 lines
Quoted 17 lines
Quoted 4 lines
src/netconfig.c +3
-0+if (netconfig->addr6_add_cmd_id) { + netconfig->pending_v4_set |= changed; +return ;src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1129
Quoted 10 lines
src/netconfig.c +10
-0+ } + } + +if (af ==AF_INET ) { +if (changed &NETCONFIG_CHANGED_GATEWAY ) { +netconfig_gateway_to_arp (netconfig); + +if (netconfig_ipv4_gateway_route_install (netconfig)) + changed &= ~NETCONFIG_CHANGED_GATEWAY ; + }else if (netconfig->notify) {This is really quite weird since
netconfig_ipv4_gateway_route_install()checks that the gateway is NULL. What is this trying to take care of?
Quoted 3 lines
You mean what is the if (
netconfig_ipv4_gateway_route_install) trying to take care of? Error handling, though errors are not really expected to happen there.
You have a special case for gateway being NULL in netconfig_ipv4_gateway_route_install(). When lease is lost or cleaning up, you set NETCONFIG_CHANGED_GATEWAY flag and a debug message and other special processing takes place. That seems bogus.
Quoted 11 lines
Quoted 11 lines
src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1138
Quoted 11 lines
src/netconfig.c +9
-0+/* +* The gateway route addition callback notifies the user +* of netconfig success if a gateway is provided, otherwise +* notify here. +*/ + netconfig->notify (NETCONFIG_EVENT_CONNECTED , + netconfig->user_data); + netconfig->notify =NULL ; + }
Also, it looks like even if a lease is obtained without a gateway, the changed flag is still set. The only time a changed flag is not set is if the lease is renewed and the gateway is the same. Which makes the block above pretty suspect?
Quoted 9 lines
So basically we pass a set of new values to the new "netconfig-committer" entity, it checks what's changed, calls the agent method first, if no agent is registered it falls back to the local implementation.
Honestly I see no place for an "ops" structure there, it can be forced between the "entity" and the agent code but it's adding more problems than solving.
I disagree here. It isn't forced at all. The new entity just selects a backend to be used based on some policy. Similar to how resolve class works.
Right now we would have 2 backends, the agent one and our native one. But we could add more in the future. The change tracking wouldn't need to be in the entity itself, but the backend. This is because the agent based backend has no need to track changes at all.
Quoted 7 lines
Quoted 3 lines
Gateway should be cleared, not changed. I believe this is done automagically when removing the address.
Right,
netconfig_setdoesn't take the "CHANGED" part literally, it's more like a dbus property changed signal ;-)
I think this gets you into all sorts of trouble and should be changed. See above.
Quoted 14 lines
Quoted 13 lines
src/netconfig.c static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client, · line 1233
Quoted 10 lines
src/netconfig.c +9
-0+ } + +if (netconfig_dns_list_update (netconfig,AF_INET )) + changed |=NETCONFIG_CHANGED_DNS ; + +if (netconfig_domains_update (netconfig,AF_INET )) + changed |=NETCONFIG_CHANGED_DOMAINS ; + +netconfig_set (netconfig,AF_INET , changed);Perhaps lease expiration, and thus the clearing out of all settings should be a separate operation? There's not much point setting domains, dns, etc in this case.
Quoted 1 line
Special-casing it won't make the code clearer but ok.
Again, I disagree completely. There isn't much point to set empty domains or DNS info and cause unnecessary D-Bus traffic. We do have resolve_revert for a reason.
Regards,
-Denis
Andrew Zaborowski
Quoted 20 lines · Denis Kenzior
Quoted 10 lines
Quoted 10 lines
I really don't think these belong here. If we're going in the direction of netconfig delegating the management of applying IP configuration settings, then this is up to the applying entity to store this information. netconfig would only be responsible for obtaining the settings and notifying the new management entity.
The new management entity would either:
A) invoke the agent, or
B) apply the settings itself.Quoted 9 lines
Quoted 3 lines
Preferably, A & B would use the same API and be subclasses of some generic abstract interface. Similarly to how we handle
auth_protos, or perhaps modeled afterresolv_ops.Ok, having these RTNL calls etc., in a separate file from where we handle the config methods and policies will make the code a little clearer but the API will probably need to include the optional details like the MAC addresses.
Quoted 3 lines
That is fine. Every time we logically separate pieces behind a clear API makes the code more maintainable and easier to understand. We pay a bit in code size, but it is worth it in my opinion.
Every time we say "every time" it's probably wrong ;-)
I mean let's do this, but there's obviously a threshold of complexity where this starts to make sense.
And in general clear APIs are not generally ones that use function pointers, or wrap simple things like a memcpy or integer operations in functions -- in terms of readability you simply can't beat a language feature (I know you disagree, not proposing we spend any more time on this topic..).
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Note that netconfig behaves differently with dhcp6 client vs dhcp. With dhcp, netconfig is the one setting routes and addresses. But with dhcp6, we let the
dhcp6_clientitself set the route and the address. So this may need to be refactored to act similarly to how dhcp client is managed. Otherwise the settings would be applied despite the agent being registered.
Quoted 6 lines
Quoted 2 lines
I don't think that's much of an issue but let's do it, one difficulty is going to be synchronising the ell and iwd changes though.
So I'm not sure how to interpret the statement that it isn't 'much of an issue'?
The contract we have is that if the agent is registered, then iwd doesn't
apply any settings to the netdevs.
Well that's the proposal, not a contract that we have or one that has to be implemented fully from the start (there's hardly any protocol we implement 100% and especially in netconfig -- yet it got merged). In any case there's not much that that agent can do other than the same thing l_dhcp6_client does.
Quoted 4 lines
But what I'm pointing out above is that: the
wayl_dhcp6_clientis being driven today, this contract is broken. netconfig delegates setting of the address and routes to l_dhcp6_client/l_icmp6_client and these settings are always applied if IPv6 support is enabled / detected.
Right, the difference between l_dhcp_client and l_dhcp6_client is strange and didn't seem to be mentioned anywhere in the netconfig.c until the comment I add in this patch.
Quoted 57 lines
So yes, this is a an issue. And it should probably be among the first things that are refactored as a result of this agent-based approach since these changes can be regression-tested rather easily.
Quoted 44 lines
Quoted 35 lines
Quoted 35 lines
src/netconfig.c +35
-0+static void netconfig_set (struct netconfig *netconfig,uint8_t af, +unsigned int changed) +{ +struct l_rtnl_address *stale_addr; + +if (af ==AF_INET ) + stale_addr =l_steal_ptr (netconfig->stale_v4_address); +else + stale_addr =l_steal_ptr (netconfig->stale_v6_address); + +if (stale_addr) { +L_WARN_ON (!l_rtnl_ifaddr_delete (rtnl, netconfig->ifindex, + stale_addr, + netconfig_ifaddr_del_cmd_cb, + netconfig,NULL )); +l_rtnl_address_free (stale_addr); + } + +if (af ==AF_INET ) { +if (!netconfig->v4_address) +return ; + +if ((changed & (NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK )) && + !netconfig->addr4_add_cmd_id) { + netconfig->addr4_add_cmd_id =l_rtnl_ifaddr_add (rtnl, + netconfig->ifindex, + netconfig->v4_address, + netconfig_ipv4_ifaddr_add_cmd_cb, + netconfig,NULL ); +if (!L_WARN_ON (!netconfig->addr4_add_cmd_id)) + changed &= ~(NETCONFIG_CHANGED_ADDRESS | +NETCONFIG_CHANGED_NETMASK ); + } +Quoted 8 lines
src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1079
Quoted 5 lines
src/netconfig.c +5
-0+/* +* If we either started the address addition now or one was +* already in progress, wait for that operation's callback +* and we'll be called again to set the rest of the values +* in the changed bitmask. So I'd rather see the
ipv4_ifaddr_add_cmd_cbor an intermediate function being invoked than trying to re-invokenetconfig_setin the callback.Quoted 7 lines
The advantage of this approach is that it handles these async operations well, i.e. you look at the bitmask and start the async ops to apply the config bits that have changed, clearing the corresponding bits from the bitmap. If during one of those calls a new change happens we don't apply the remaining bits and go back to the beginning. Let me see if these can be done differently...
Quoted 5 lines
Ok, I can understand the logic behind this, but then again, we set the routes, dns and domains once the address is set. So you can really only 'interrupt' the ongoing setting operation after the address has been set. Explicitly calling the address set callback would better reflect this reality. But I can be convinced either way...
(we do call ipv4_ifaddr_add_cmd_cb, and from *there* is where we look at what's the next step)
Quoted 39 lines
Quoted 18 lines
Quoted 17 lines
Quoted 4 lines
src/netconfig.c +3
-0+if (netconfig->addr6_add_cmd_id) { + netconfig->pending_v4_set |= changed; +return ;src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1129
Quoted 10 lines
src/netconfig.c +10
-0+ } + } + +if (af ==AF_INET ) { +if (changed &NETCONFIG_CHANGED_GATEWAY ) { +netconfig_gateway_to_arp (netconfig); + +if (netconfig_ipv4_gateway_route_install (netconfig)) + changed &= ~NETCONFIG_CHANGED_GATEWAY ; + }else if (netconfig->notify) {This is really quite weird since
netconfig_ipv4_gateway_route_install()checks that the gateway is NULL. What is this trying to take care of?Quoted 3 lines
You mean what is the if (
netconfig_ipv4_gateway_route_install) trying to take care of? Error handling, though errors are not really expected to happen there.You have a special case for gateway being NULL in
netconfig_ipv4_gateway_route_install(). When lease is lost or cleaning up, you setNETCONFIG_CHANGED_GATEWAYflag and a debug message and other special processing takes place. That seems bogus.Quoted 11 lines
Quoted 11 lines
src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1138
Quoted 11 lines
src/netconfig.c +9
-0+/* +* The gateway route addition callback notifies the user +* of netconfig success if a gateway is provided, otherwise +* notify here. +*/ + netconfig->notify (NETCONFIG_EVENT_CONNECTED , + netconfig->user_data); + netconfig->notify =NULL ; + }
Quoted 3 lines
Also, it looks like even if a lease is obtained without a gateway, the changed flag is still set. The only time a changed flag is not set is if the lease is renewed and the gateway is the same. Which makes the block above pretty suspect?
If there was no gateway and the new lease has no gateway (or the lease is gone), then there's no change in the gateway, right? We don't set NETCONFIG_CHANGED_GATEWAY in that case.
When the value has changed then we set NETCONFIG_CHANGED_GATEWAY. I'm not sure I understand what is bogus about this. The wording CHANGED is because it's literally changing (new is different than the old -- that's how you define a change), now if this is committed at the system level through an erase and re-add doesn't mean that the gateway address hasn't changed...
Quoted 11 lines
Quoted 10 lines
So basically we pass a set of new values to the new "netconfig-committer" entity, it checks what's changed, calls the agent method first, if no agent is registered it falls back to the local implementation.
Honestly I see no place for an "ops" structure there, it can be forced between the "entity" and the agent code but it's adding more problems than solving.
Quoted 5 lines
I disagree here. It isn't forced at all. The new entity just selects a backend to be used based on some policy. Similar to how resolve class works.
Right now we would have 2 backends, the agent one and our native one. But we could add more in the future.
Hypothetically we could but in the end each backend basically does the same simple thing in this case.
What I suspect that someone will eventually have a usecase for is exposing those config properties on D-Bus, in fact I think there was talk about this since very early on when Tim added netconfig and then again when I was adding P2P (I eventually added the "ConnectedIP" property to start with the bare minimum).
Quoted 3 lines
The change tracking wouldn't need to be in the
entity itself, but the backend. This is because the agent based backend has no need to track changes at all.
Well we can send all of the parameters to the agent every time, that will work too.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Perhaps lease expiration, and thus the clearing out of all settings should be a separate operation? There's not much point setting domains, dns, etc in this case.
Special-casing it won't make the code clearer but ok.
Again, I disagree completely. There isn't much point to set empty domains or DNS info and cause unnecessary D-Bus traffic. We do have
resolve_revertfor a reason.
We don't set them when they're empty, but we make the "committer" part aware that the value has changed (is different than it was).
Best regards
Denis Kenzior
Hi Andrew,
Quoted 21 lines · Andrew Zaborowski
Quoted 20 lines · Denis Kenzior
Quoted 19 lines
Quoted 6 lines
I really don't think these belong here. If we're going in the direction of netconfig delegating the management of applying IP configuration settings, then this is up to the applying entity to store this information. netconfig would only be responsible for obtaining the settings and notifying the new management entity.
Quoted 7 lines
The new management entity would either:
A) invoke the agent, or
B) apply the settings itself.Preferably, A & B would use the same API and be subclasses of some generic abstract interface. Similarly to how we handle
auth_protos, or perhaps modeled afterresolv_ops.Ok, having these RTNL calls etc., in a separate file from where we handle the config methods and policies will make the code a little clearer but the API will probably need to include the optional details like the MAC addresses.
Quoted 8 lines
Quoted 3 lines
That is fine. Every time we logically separate pieces behind a clear API makes the code more maintainable and easier to understand. We pay a bit in code size, but it is worth it in my opinion.
Every time we say "every time" it's probably wrong ;-)
I mean let's do this, but there's obviously a threshold of complexity where this starts to make sense.
Oh I agree. And so far I would say that we only did such restructuring when it made sense. Of course you can disagree, but I don't recall any situation where we did something like this and said: "that was a terrible idea."
Quoted 6 lines
And in general clear APIs are not generally ones that use function pointers, or wrap simple things like a memcpy or integer operations in functions -- in terms of readability you simply can't beat a language feature (I know you disagree, not proposing we spend any more time on this topic..).
This is a classic example of polymorphic behavior. Hiding this behind a virtual interface + backend is about as clear as things can get ;)
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines
Note that netconfig behaves differently with dhcp6 client vs dhcp. With dhcp, netconfig is the one setting routes and addresses. But with dhcp6, we let the
dhcp6_clientitself set the route and the address. So this may need to be refactored to act similarly to how dhcp client is managed. Otherwise the settings would be applied despite the agent being registered.I don't think that's much of an issue but let's do it, one difficulty is going to be synchronising the ell and iwd changes though.
Quoted 6 lines
Quoted 3 lines
So I'm not sure how to interpret the statement that it isn't 'much of an issue'?
The contract we have is that if the agent is registered, then iwd doesn't
apply any settings to the netdevs.Well that's the proposal, not a contract that we have or one that has to be implemented fully from the start (there's hardly any protocol we
Eh, why not? Especially if you want NM to use it? Not honoring contracts is amateur hour. I mean why would they even bother if we can't keep our contracts?
Quoted 3 lines
implement 100% and especially in netconfig -- yet it got merged). In any case there's not much that that agent can do other than the same thing
l_dhcp6_clientdoes.
Sure, but it has to be done, not hand-waved away.
Quoted 9 lines
Quoted 5 lines
But what I'm pointing out above is that: the
wayl_dhcp6_clientis being driven today, this contract is broken. netconfig delegates setting of the address and routes to l_dhcp6_client/l_icmp6_client and these settings are always applied if IPv6 support is enabled / detected.Right, the difference between
l_dhcp_clientandl_dhcp6_clientis strange and didn't seem to be mentioned anywhere in thenetconfig.cuntil the comment I add in this patch.
Well, we tried it one way with dhcpv4. We tried another approach with dhcpv6. Arguably, the dhcpv6 approach made a whole lot more sense until this agent proposal came about. Having ell / dhcp{4|6}_client be able to set settings directly still might make sense for certain applications...
Quoted 38 lines
Quoted 38 lines
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
src/netconfig.c +8
-0+if (netconfig->addr6_add_cmd_id) { + netconfig->pending_v4_set |= changed; +return ; + } + } + +if (af ==AF_INET ) { +if (changed &NETCONFIG_CHANGED_GATEWAY ) {Quoted 8 lines
src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1129
Quoted 5 lines
src/netconfig.c +5
-0+netconfig_gateway_to_arp (netconfig); + +if (netconfig_ipv4_gateway_route_install (netconfig)) + changed &= ~NETCONFIG_CHANGED_GATEWAY ; + }else if (netconfig->notify) {This is really quite weird since
netconfig_ipv4_gateway_route_install()checks that the gateway is NULL. What is this trying to take care of?Quoted 3 lines
You mean what is the if (
netconfig_ipv4_gateway_route_install) trying to take care of? Error handling, though errors are not really expected to happen there.You have a special case for gateway being NULL in
netconfig_ipv4_gateway_route_install(). When lease is lost or cleaning up, you setNETCONFIG_CHANGED_GATEWAYflag and a debug message and other special processing takes place. That seems bogus.Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
src/netconfig.c +9
-0+/* +* The gateway route addition callback notifies the user +* of netconfig success if a gateway is provided, otherwise +* notify here. +*/ + netconfig->notify (NETCONFIG_EVENT_CONNECTED , + netconfig->user_data); + netconfig->notify =NULL ; + }
Quoted 7 lines
Quoted 3 lines
Also, it looks like even if a lease is obtained without a gateway, the changed flag is still set. The only time a changed flag is not set is if the lease is renewed and the gateway is the same. Which makes the block above pretty suspect?
If there was no gateway and the new lease has no gateway (or the lease is gone), then there's no change in the gateway, right? We don't set
NETCONFIG_CHANGED_GATEWAYin that case.
Sure, but you still try to call the notifier saying that we're 'connected'? How does that make sense? Yes, I know the notifier is likely NULL by now. But I see no circumstances where this code path would even be hit. And if it is hit, it is probably doing the wrong thing anyway. So why have it in the first place?
Quoted 8 lines
When the value has changed then we set
NETCONFIG_CHANGED_GATEWAY. I'm not sure I understand what is bogus about this. The wording CHANGED is because it's literally changing (new is different than the old -- that's how you define a change), now if this is committed at the system level through an erase and re-add doesn't mean that the gateway address hasn't changed...
What you say is absolutely correct. Yet still wrong ;) Just look at what happens on a 'change'. You try to call the notifier with 'connected' event. You also print a debug message saying there's no gateway in the lease. Neither make sense.
Quoted 17 lines
Quoted 11 lines
Quoted 10 lines
So basically we pass a set of new values to the new "netconfig-committer" entity, it checks what's changed, calls the agent method first, if no agent is registered it falls back to the local implementation.
Honestly I see no place for an "ops" structure there, it can be forced between the "entity" and the agent code but it's adding more problems than solving.
Quoted 5 lines
I disagree here. It isn't forced at all. The new entity just selects a backend to be used based on some policy. Similar to how resolve class works.
Right now we would have 2 backends, the agent one and our native one. But we could add more in the future.
Quoted 8 lines
Hypothetically we could but in the end each backend basically does the same simple thing in this case.
What I suspect that someone will eventually have a usecase for is exposing those config properties on D-Bus, in fact I think there was talk about this since very early on when Tim added netconfig and then again when I was adding P2P (I eventually added the "ConnectedIP" property to start with the bare minimum).
Sure. But why do you think this is somehow at odds with the proposed architecture?
Quoted 7 lines
Quoted 4 lines
The change tracking wouldn't need to be in the
entity itself, but the backend. This is because the agent based backend has no need to track changes at all.Well we can send all of the parameters to the agent every time, that will work too.
We could.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Perhaps lease expiration, and thus the clearing out of all settings should be a separate operation? There's not much point setting domains, dns, etc in this case.
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
Special-casing it won't make the code clearer but ok.
Again, I disagree completely. There isn't much point to set empty domains or DNS info and cause unnecessary D-Bus traffic. We do have
resolve_revertfor a reason.We don't set them when they're empty, but we make the "committer" part aware that the value has changed (is different than it was).
We have to see. I think an explicit flag stating that v4/v6 info is invalidated would be a nice hint to the backend to simply invoke RevertLink or whatever. Given this, I'd also generate events and give both ipv4 and ipv6 change sets in one operation. Even if only ipv4 or ipv6 changes were made.
Regards,
-Denis
Denis Kenzior
Hi Andrew,
Quoted 6 lines
What you say is absolutely correct. Yet still wrong ;) Just look at what happens on a 'change'. You try to call the notifier with 'connected' event. You also print a debug message saying there's no gateway in the lease. Neither make sense.
Note, I'm not saying you shouldn't use 'CHANGED'. Perhaps that is the right approach if netconfig would inform the backend only of the 'new' settings. But the way CHANGED is being handled in this patch seems problematic.
Regards,
-Denis
Andrew Zaborowski
Hi Denis,
Quoted 18 lines · Denis Kenzior
Quoted 10 lines · Andrew Zaborowski
Quoted 9 lines · Denis Kenzior
Quoted 8 lines
Quoted 5 lines
Note that netconfig behaves differently with dhcp6 client vs dhcp. With dhcp, netconfig is the one setting routes and addresses. But with dhcp6, we let the
dhcp6_clientitself set the route and the address. So this may need to be refactored to act similarly to how dhcp client is managed. Otherwise the settings would be applied despite the agent being registered.I don't think that's much of an issue but let's do it, one difficulty is going to be synchronising the ell and iwd changes though.
Quoted 6 lines
Quoted 3 lines
So I'm not sure how to interpret the statement that it isn't 'much of an issue'?
The contract we have is that if the agent is registered, then iwd doesn't
apply any settings to the netdevs.Well that's the proposal, not a contract that we have or one that has to be implemented fully from the start (there's hardly any protocol we
Quoted 8 lines
Eh, why not? Especially if you want NM to use it? Not honoring contracts is amateur hour. I mean why would they even bother if we can't keep our contracts?
Quoted 3 lines
implement 100% and especially in netconfig -- yet it got merged). In any case there's not much that that agent can do other than the same thing
l_dhcp6_clientdoes.Sure, but it has to be done, not hand-waved away.
Right, but the risk is that it's done twice (less harmful), not that it doesn't get done.
So looking at l_dhcp6_client it looks like simply skipping l_dhcp6_client_set_rtnl()/l_icmp6_client_set_rtnl() will make it behave like l_dhcp_client, no new flag is needed.
Quoted 42 lines
Quoted 42 lines
Quoted 41 lines
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
src/netconfig.c +8
-0+if (netconfig->addr6_add_cmd_id) { + netconfig->pending_v4_set |= changed; +return ; + } + } + +if (af ==AF_INET ) { +if (changed &NETCONFIG_CHANGED_GATEWAY ) {Quoted 8 lines
src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1129
Quoted 5 lines
src/netconfig.c +5
-0+netconfig_gateway_to_arp (netconfig); + +if (netconfig_ipv4_gateway_route_install (netconfig)) + changed &= ~NETCONFIG_CHANGED_GATEWAY ; + }else if (netconfig->notify) {This is really quite weird since
netconfig_ipv4_gateway_route_install()checks that the gateway is NULL. What is this trying to take care of?Quoted 3 lines
You mean what is the if (
netconfig_ipv4_gateway_route_install) trying to take care of? Error handling, though errors are not really expected to happen there.You have a special case for gateway being NULL in
netconfig_ipv4_gateway_route_install(). When lease is lost or cleaning up, you setNETCONFIG_CHANGED_GATEWAYflag and a debug message and other special processing takes place. That seems bogus.Quoted 11 lines
Quoted 11 lines
src/netconfig.c static void netconfig_ifaddr_del_cmd_cb(int error, uint16_t type, · line 1138
Quoted 11 lines
src/netconfig.c +9
-0+/* +* The gateway route addition callback notifies the user +* of netconfig success if a gateway is provided, otherwise +* notify here. +*/ + netconfig->notify (NETCONFIG_EVENT_CONNECTED , + netconfig->user_data); + netconfig->notify =NULL ; + }Also, it looks like even if a lease is obtained without a gateway, the changed flag is still set. The only time a changed flag is not set is if the lease is renewed and the gateway is the same. Which makes the block above pretty suspect?
Quoted 8 lines
Quoted 3 lines
If there was no gateway and the new lease has no gateway (or the lease is gone), then there's no change in the gateway, right? We don't set
NETCONFIG_CHANGED_GATEWAYin that case.Sure, but you still try to call the notifier saying that we're 'connected'? How does that make sense? Yes, I know the notifier is likely NULL by now. But I see no circumstances where this code path would even be hit. And if it is hit, it is probably doing the wrong thing anyway. So why have it in the first place?
Ok, I think I see what you mean. It's not really clear why we're trying to signal NETCONFIG_EVENT_CONNECTED whenever netconfig_set is called. It's basically to mirror how the original code works, I could have probably improved it.
In the original code, when it's time to set the new gateway (i.e. after we've set the address etc.) we either notify in the route_add_cmd_cb, or if no gateway address is received, we emit NETCONFIG_EVENT_CONNECTED directly in netconfig_ipv4_gateway_route_install. I mirrored this behaviour for the sake of review, so it's easy to confirm that this is pure refactoring and the sequence of RTNL commands, netconfig events and other interactions is unaffected in the end.
Perhaps we should add a function that is guaranteed to be called after all the bits from a new lease have been committed to the netdev and that's where we'd emit the event, if we're not yet in connected state (in a separate commit).
Quoted 10 lines
Quoted 9 lines
When the value has changed then we set
NETCONFIG_CHANGED_GATEWAY. I'm not sure I understand what is bogus about this. The wording CHANGED is because it's literally changing (new is different than the old -- that's how you define a change), now if this is committed at the system level through an erase and re-add doesn't mean that the gateway address hasn't changed...
Quoted 4 lines
What you say is absolutely correct. Yet still wrong ;) Just look at what happens on a 'change'. You try to call the notifier with 'connected' event. You also print a debug message saying there's no gateway in the lease. Neither make sense.
Ok the debug message is indeed wrong if we're handling an L_DHCP_CLIENT_EVENT_LEASE_EXPIRED.
Quoted 21 lines
Quoted 21 lines
Quoted 12 lines
Quoted 11 lines
So basically we pass a set of new values to the new "netconfig-committer" entity, it checks what's changed, calls the agent method first, if no agent is registered it falls back to the local implementation.
Honestly I see no place for an "ops" structure there, it can be forced between the "entity" and the agent code but it's adding more problems than solving.
Quoted 5 lines
I disagree here. It isn't forced at all. The new entity just selects a backend to be used based on some policy. Similar to how resolve class works.
Right now we would have 2 backends, the agent one and our native one. But we could add more in the future.
Hypothetically we could but in the end each backend basically does the same simple thing in this case.
Quoted 7 lines
Quoted 5 lines
What I suspect that someone will eventually have a usecase for is exposing those config properties on D-Bus, in fact I think there was talk about this since very early on when Tim added netconfig and then again when I was adding P2P (I eventually added the "ConnectedIP" property to start with the bare minimum).
Sure. But why do you think this is somehow at odds with the proposed architecture?
The "changed" flags logic is helpful for that kind of interface. Moving that logic into one of those proposed "backends" prevents the other backends and interfaces from having this information.
Quoted 4 lines
We have to see. I think an explicit flag stating that v4/v6 info is invalidated would be a nice hint to the backend to simply invoke RevertLink or whatever. Given this, I'd also generate events and give both ipv4 and ipv6 change sets in one operation. Even if only ipv4 or ipv6 changes were made.
Ok.
Best regards