dhcp6: Fix emitting LEASE_OBTAINED in stateless mode
PATCH 1/5 dhcp6: Fix emitting LEASE_OBTAINED in stateless mode
Make sure we emit the LEASE_OBTAINED and not LEASE_RENEWED event after obtaining a reply to an Information-Request. Only set client->request_na in stateful mode so as not to require the NA in the lease object when we're later validating it. Fix switching to BOUND state after dhcp6_client_receive_reply() returns BOUND.
--- ell/dhcp6.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
ell/dhcp6.c +7 -4
@@ -971,8 +971,9 @@ static void dhcp6_client_setup_lease(struct l_dhcp6_client *client, client->lease->start_time = timestamp;/* TODO: Emit IP_CHANGED if any addresses were removed / added */ -if (client->state ==DHCP6_STATE_REQUESTING || - client->state ==DHCP6_STATE_SOLICITING ) +if (L_IN_SET (client->state,DHCP6_STATE_REQUESTING , +DHCP6_STATE_SOLICITING , +DHCP6_STATE_REQUESTING_INFORMATION )) event =L_DHCP6_CLIENT_EVENT_LEASE_OBTAINED ;else event =L_DHCP6_CLIENT_EVENT_LEASE_RENEWED ;
@@ -1385,7 +1386,8 @@ static void dhcp6_client_rx_message(const void *data, size_t len,case DHCP6_STATE_BOUND :return ;case DHCP6_STATE_REQUESTING_INFORMATION : -if (dhcp6_client_receive_reply (client, message, len) <0 ) + r =dhcp6_client_receive_reply (client, message, len); +if (r <0 )return ;break ;
@@ -1527,7 +1529,6 @@ LIB_EXPORT struct l_dhcp6_client *l_dhcp6_client_new(uint32_t ifindex) client->state =DHCP6_STATE_INIT ; client->ifindex = ifindex; - client->request_na = true; client->icmp6 =l_icmp6_client_new (ifindex); l_icmp6_client_add_event_handler(client->icmp6,
@@ -1803,6 +1804,8 @@ LIB_EXPORT bool l_dhcp6_client_start(struct l_dhcp6_client *client)else client_duid_generate_addr_plus_time (client); + client->request_na = !client->stateless; +if (!client->transport) { client->transport = _dhcp6_default_transport_new(client->ifindex,
Signature · 1 line
2.34.1
PATCH 2/5 netconfig: Enable stateless DHCP mode
When using SLAAC, if the "Other" bit in Router Advertisements is set, start DHCP6 in stateless mode and use the DNS entries from the lease object created by l_dhcp6_client. If there is DNS information in the RA then emit the CONFIGURE event immediately after we've generated the addresses as before. If there's no DNS information, wait for the l_dhcp6_client LEASE_OBTAINED event before we emit CONFIGURE and set netconfig->v6_configured.
--- ell/netconfig.c | 53 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 14 deletions(-)
ell/netconfig.c +39 -14
@@ -96,8 +96,9 @@ struct l_netconfig {bool have_lla;enum {NETCONFIG_V6_METHOD_UNSET , -NETCONFIG_V6_METHOD_DHCP , -NETCONFIG_V6_METHOD_SLAAC , +NETCONFIG_V6_METHOD_DHCP ,/* Managed bit set in RA */ +NETCONFIG_V6_METHOD_SLAAC_DHCP ,/* Other bit set in RA */ +NETCONFIG_V6_METHOD_SLAAC ,/* Neither flag set in RA */ } v6_auto_method;struct l_queue *slaac_dnses;struct l_queue *slaac_domains;
@@ -624,13 +625,17 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,if (L_WARN_ON (nc->v6_configured))break ; -netconfig_add_dhcp6_address (nc); -netconfig_set_dhcp6_address_lifetimes (nc, false); +if (nc->v6_auto_method ==NETCONFIG_V6_METHOD_DHCP ) { +netconfig_add_dhcp6_address (nc); +netconfig_set_dhcp6_address_lifetimes (nc, false); + } + nc->v6_configured = true;netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_CONFIGURE );break ;case L_DHCP6_CLIENT_EVENT_IP_CHANGED : -if (L_WARN_ON (!nc->v6_configured)) +if (L_WARN_ON (!nc->v6_configured || + nc->v6_auto_method !=NETCONFIG_V6_METHOD_DHCP ))break ;netconfig_remove_dhcp6_address (nc, false);
@@ -639,7 +644,8 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_UPDATE );break ;case L_DHCP6_CLIENT_EVENT_LEASE_EXPIRED : -if (L_WARN_ON (!nc->v6_configured)) +if (L_WARN_ON (!nc->v6_configured || + nc->v6_auto_method !=NETCONFIG_V6_METHOD_DHCP ))break ;netconfig_remove_dhcp6_address (nc, true);
@@ -658,13 +664,19 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,if (L_WARN_ON (!nc->v6_configured))break ; -netconfig_set_dhcp6_address_lifetimes (nc, true); +if (nc->v6_auto_method ==NETCONFIG_V6_METHOD_DHCP ) +netconfig_set_dhcp6_address_lifetimes (nc, true); +netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_UPDATE );break ;case L_DHCP6_CLIENT_EVENT_NO_LEASE :if (L_WARN_ON (nc->v6_configured))break ; +if (nc->v6_auto_method ==NETCONFIG_V6_METHOD_SLAAC_DHCP && + !l_queue_isempty (nc->slaac_dnses)) +break ; +/* * The requested address is no longer available, try to restart * the client.
@@ -699,7 +711,9 @@ static bool netconfig_match_str(const void *a, const void *b)static bool netconfig_check_start_dhcp6 (struct l_netconfig *nc) {/* Don't start DHCPv6 until we get an RA with the managed bit set */ -if (nc->ra_timeout || nc->v6_auto_method !=NETCONFIG_V6_METHOD_DHCP ) +if (nc->ra_timeout || !L_IN_SET (nc->v6_auto_method, +NETCONFIG_V6_METHOD_DHCP , +NETCONFIG_V6_METHOD_SLAAC_DHCP ))return true;/* Don't start DHCPv6 while waiting for the link-local address */
@@ -765,8 +779,13 @@ static void netconfig_add_slaac_address(struct l_netconfig *nc,l_queue_push_tail (nc->addresses.current, nc->v6_address);l_queue_push_tail (nc->addresses.added, nc->v6_address); - nc->v6_configured = true; -netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_CONFIGURE ); + +if (nc->v6_auto_method ==NETCONFIG_V6_METHOD_SLAAC || + nc->slaac_dnses) { + nc->v6_configured = true; +netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_CONFIGURE ); + }else +netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_UPDATE );/* TODO: set a renew timeout */ }
@@ -1202,6 +1221,7 @@ process_nondefault_routes:if (nc->v6_auto_method ==NETCONFIG_V6_METHOD_UNSET &&l_icmp6_router_get_managed (r)) { nc->v6_auto_method =NETCONFIG_V6_METHOD_DHCP ; +l_dhcp6_client_set_stateless (nc->dhcp6_client, false);if (!netconfig_check_start_dhcp6 (nc)) { netconfig_emit_event(nc, AF_INET6,
@@ -1213,12 +1233,17 @@ process_nondefault_routes: }/* -* DHCP not available according to this router, check if any of the -* prefixes allow SLAAC. +* Stateful DHCP not available according to this router, check if +* any of the prefixes allow SLAAC. */ if (nc->v6_auto_method ==NETCONFIG_V6_METHOD_UNSET && r->n_ac_prefixes) { - nc->v6_auto_method =NETCONFIG_V6_METHOD_SLAAC ; +if (l_icmp6_router_get_other (r)) { + nc->v6_auto_method =NETCONFIG_V6_METHOD_SLAAC_DHCP ; +l_dhcp6_client_set_stateless (nc->dhcp6_client, true); +netconfig_check_start_dhcp6 (nc); + }else + nc->v6_auto_method =NETCONFIG_V6_METHOD_SLAAC ;/* * Do this first so that any changes are included in the
@@ -2188,7 +2213,7 @@ LIB_EXPORT void l_netconfig_unconfigure(struct l_netconfig *netconfig) L_NETCONFIG_EVENT_UNCONFIGURE); } -if (netconfig->v6_configured) { +if (netconfig->v6_address) {netconfig_remove_dhcp6_address (netconfig, false); netconfig->v6_configured = false; }
Signature · 1 line
2.34.1
PATCH 3/5 netconfig: Return SLAAC+DHCP6 DNS info from getters
In reply to Andrew ZaborowskiIn l_netconfig_get_dns_list(), l_netconfig_get_domain_names() return both the DNS information from Router Advertisements if any, and from the l_dhcp6_client lease if any, to cover the SLAAC+DHCP6 mode and other possible corner cases.
--- ell/netconfig.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-)
ell/netconfig.c +30 -17
@@ -1209,6 +1209,20 @@ process_nondefault_routes:netconfig_remove_icmp6_route (nc, rd); } +/* +* Do this first so that any changes are included in the event +* emitted next, be it UPDATE or CONFIGURE. +*/ +if (r->n_dns || r->n_domains) { +if (!nc->slaac_dnses && r->n_dns) + nc->slaac_dnses =l_queue_new (); + +if (!nc->slaac_domains && r->n_domains) + nc->slaac_domains =l_queue_new (); + + dns_updated =netconfig_process_slaac_dns_info (nc, r); + } +/* * For lack of a better policy, select between DHCPv6 and SLAAC based * on the first RA received. Prefer DHCPv6.
@@ -1245,14 +1259,6 @@ process_nondefault_routes: }else nc->v6_auto_method =NETCONFIG_V6_METHOD_SLAAC ; -/* -* Do this first so that any changes are included in the -* CONFIGURE event emitted next. -*/ - nc->slaac_dnses =l_queue_new (); - nc->slaac_domains =l_queue_new (); -netconfig_process_slaac_dns_info (nc, r); -/* * The DAD for the link-local address may be still running * but again we can generate the global address already and
@@ -1287,7 +1293,6 @@ process_nondefault_routes:* and allows us to extend its lifetime. */ netconfig_set_slaac_address_lifetimes (nc, r); - dns_updated =netconfig_process_slaac_dns_info (nc, r); emit_event:/*
@@ -2411,14 +2416,18 @@ append_v6:if (!netconfig->v6_configured) goto done; -if (netconfig->v6_dns_override) +if (netconfig->v6_dns_override) {netconfig_strv_cat (&ret, netconfig->v6_dns_override, false); -else if (netconfig->v6_auto_method ==NETCONFIG_V6_METHOD_DHCP && + goto done; + } + +if (L_IN_SET (netconfig->v6_auto_method,NETCONFIG_V6_METHOD_DHCP , +NETCONFIG_V6_METHOD_SLAAC_DHCP ) && (v6_lease =l_dhcp6_client_get_lease ( netconfig->dhcp6_client)))netconfig_strv_cat (&ret,l_dhcp6_lease_get_dns (v6_lease), true); -else if (netconfig->v6_auto_method ==NETCONFIG_V6_METHOD_SLAAC && - !l_queue_isempty (netconfig->slaac_dnses)) { + +if (!l_queue_isempty (netconfig->slaac_dnses)) {unsigned int dest_len =l_strv_length (ret);unsigned int src_len =l_queue_length (netconfig->slaac_dnses);char **i;
@@ -2468,16 +2477,20 @@ append_v6:if (!netconfig->v6_configured) goto done; -if (netconfig->v6_domain_names_override) +if (netconfig->v6_domain_names_override) {netconfig_strv_cat (&ret, netconfig->v6_domain_names_override, false); -else if (netconfig->v6_auto_method ==NETCONFIG_V6_METHOD_DHCP && + goto done; + } + +if (L_IN_SET (netconfig->v6_auto_method,NETCONFIG_V6_METHOD_DHCP , +NETCONFIG_V6_METHOD_SLAAC_DHCP ) && (v6_lease =l_dhcp6_client_get_lease ( netconfig->dhcp6_client)))netconfig_strv_cat (&ret,l_dhcp6_lease_get_domains (v6_lease), true); -else if (netconfig->v6_auto_method ==NETCONFIG_V6_METHOD_SLAAC && - !l_queue_isempty (netconfig->slaac_domains)) { + +if (!l_queue_isempty (netconfig->slaac_domains)) {unsigned int dest_len =l_strv_length (ret);unsigned int src_len =l_queue_length (netconfig->slaac_domains);char **i;
Signature · 1 line
2.34.1
PATCH 4/5 netconfig: Stop ongoing work on failure
In reply to Andrew ZaborowskiWhen we emit L_NETCONFIG_EVENT_FAILED for either address family, stop any timeouts and processing of events for that family. The assumption was that the user will call l_netconfig_unconfigure() and/or l_netconfig_stop() when this happens but the user may want to ignore one of the address families setup failing and continue with the other one.
--- ell/netconfig.c | 53 ++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 23 deletions(-)
ell/netconfig.c +30 -23
@@ -188,6 +188,24 @@ static void netconfig_emit_event(struct l_netconfig *nc, uint8_t family,netconfig_update_cleanup (nc); } +static void netconfig_addr_wait_unregister (struct l_netconfig *nc, +bool in_notify); + +static void netconfig_failed (struct l_netconfig *nc,uint8_t family) +{ +if (family ==AF_INET ) { +l_dhcp_client_stop (nc->dhcp_client); +l_acd_destroy (l_steal_ptr (nc->acd)); + }else { +netconfig_addr_wait_unregister (nc, false); +l_dhcp6_client_stop (nc->dhcp6_client); +l_icmp6_client_stop (nc->icmp6_client); +l_timeout_remove (l_steal_ptr (nc->ra_timeout)); + } + +netconfig_emit_event (nc, family,L_NETCONFIG_EVENT_FAILED ); +} + static struct l_rtnl_route *netconfig_route_new(struct l_netconfig *nc, uint8_t family, const void *dst,
@@ -523,8 +541,7 @@ static void netconfig_dhcp_event_handler(struct l_dhcp_client *client,netconfig_emit_event (nc,AF_INET ,L_NETCONFIG_EVENT_UNCONFIGURE ); else -netconfig_emit_event (nc ,AF_INET , -L_NETCONFIG_EVENT_FAILED ); +netconfig_failed (nc ,AF_INET );break ;case L_DHCP_CLIENT_EVENT_NO_LEASE :
@@ -539,8 +556,7 @@ static void netconfig_dhcp_event_handler(struct l_dhcp_client *client,* better yet a configurable timeout. */ if (!l_dhcp_client_start (nc->dhcp_client)) -netconfig_emit_event (nc,AF_INET , -L_NETCONFIG_EVENT_FAILED ); +netconfig_failed (nc,AF_INET );break ; }
@@ -656,8 +672,7 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_UNCONFIGURE ); else -netconfig_emit_event (nc ,AF_INET6 , -L_NETCONFIG_EVENT_FAILED ); +netconfig_failed (nc ,AF_INET6 );break ;case L_DHCP6_CLIENT_EVENT_LEASE_RENEWED :
@@ -686,8 +701,7 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,* or better yet a configurable timeout. */ if (!l_dhcp6_client_start (nc->dhcp6_client)) -netconfig_emit_event (nc,AF_INET6 , -L_NETCONFIG_EVENT_FAILED ); +netconfig_failed (nc,AF_INET6 );break ; }
@@ -727,11 +741,8 @@ static void netconfig_ra_timeout_cb(struct l_timeout *timeout, void *user_data) {struct l_netconfig *nc = user_data; -l_timeout_remove (l_steal_ptr (nc->ra_timeout)); -/* No Router Advertisements received, assume no DHCPv6 or SLAAC */ -l_icmp6_client_stop (nc->icmp6_client); -netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_FAILED ); +netconfig_failed (nc,AF_INET6 ); } static void netconfig_add_slaac_address(struct l_netconfig *nc,
@@ -1238,8 +1249,7 @@ process_nondefault_routes:l_dhcp6_client_set_stateless (nc->dhcp6_client, false);if (!netconfig_check_start_dhcp6 (nc)) { -netconfig_emit_event (nc,AF_INET6 , -L_NETCONFIG_EVENT_FAILED ); +netconfig_failed (nc,AF_INET6 );return ; }
@@ -1279,7 +1289,7 @@ process_nondefault_routes:/* Neither method seems available, fail */ if (nc->v6_auto_method ==NETCONFIG_V6_METHOD_UNSET ) { -netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_FAILED ); +netconfig_failed (nc,AF_INET6 );return ; }
@@ -1777,7 +1787,7 @@ static void netconfig_ipv4_acd_event(enum l_acd_event event, void *user_data)* Conflict found, no IP was actually set or routes added so * just emit the event. */ -netconfig_emit_event (nc,AF_INET ,L_NETCONFIG_EVENT_FAILED ); +netconfig_failed (nc,AF_INET );break ;case L_ACD_EVENT_LOST :if (L_WARN_ON (!nc->v4_configured))
@@ -1790,7 +1800,7 @@ static void netconfig_ipv4_acd_event(enum l_acd_event event, void *user_data)*/ netconfig_remove_v4_address_routes (nc, false); nc->v4_configured = false; -netconfig_emit_event (nc,AF_INET ,L_NETCONFIG_EVENT_FAILED ); +netconfig_failed (nc,AF_INET );break ; } }
@@ -1911,10 +1921,8 @@ static void netconfig_ifaddr_ipv6_added(struct l_netconfig *nc,* Only now that we have a link-local address see if we can start * actual DHCPv6 setup. */ -if (new_lla &&netconfig_check_start_dhcp6 (nc)) -return ; - -netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_FAILED ); +if (new_lla && !netconfig_check_start_dhcp6 (nc)) +netconfig_failed (nc,AF_INET6 ); } static void netconfig_ifaddr_ipv6_notify(uint16_t type, const void *data,
@@ -1951,8 +1959,7 @@ static void netconfig_ifaddr_ipv6_dump_cb(int error, uint16_t type,return ;if (error) { -netconfig_addr_wait_unregister (nc, false); -netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_FAILED ); +netconfig_failed (nc,AF_INET6 );return ; }
Signature · 1 line
2.34.1
PATCH 5/5 dhcp6: Don't require Client ID in Information-request reply
In reply to Andrew ZaborowskiSince we don't include our Client ID option when sending an Information-request, the server can't send it back in its Reply. Don't require it when validating.
RFC 8415 Section 18.2.6 has this to say about the Client ID:
"The client SHOULD include a Client Identifier option (see Section 21.2) to identify itself to the server (however, see Section 4.3.1 of [RFC7844] for reasons why a client may not want to include this option). If the client does not include a Client Identifier option, the server will not be able to return any client-specific options to the client, or the server may choose not to respond to the message at all."
RFC 7833 Section 4.3.1 says this:
"When using stateless DHCPv6, clients wanting to protect their privacy SHOULD NOT include client identifiers in their Information-request messages. This will prevent the server from specifying client-specific options if it is configured to do so, but the need for anonymity precludes such options anyway."
--- ell/dhcp6.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
ell/dhcp6.c +10 -3
@@ -1098,6 +1098,7 @@ bool _dhcp6_option_iter_next(struct dhcp6_option_iter *iter, uint16_t *type, }static int dhcp6_client_validate_message (struct l_dhcp6_client *client, +bool expect_client_id,const struct dhcp6_message *message,size_t len) {
@@ -1205,7 +1206,7 @@ static int dhcp6_client_validate_message(struct l_dhcp6_client *client, } } -if (!duid_verified) { +if (expect_client_id && !duid_verified) {CLIENT_DEBUG ("Message %s - no client id option found" , mstr);return -EBADMSG ; }
@@ -1229,7 +1230,7 @@ static int dhcp6_client_receive_advertise(struct l_dhcp6_client *client,if (advertise->msg_type !=DHCP6_MESSAGE_TYPE_ADVERTISE )return -EINVAL ; - r =dhcp6_client_validate_message (client, advertise, len); + r =dhcp6_client_validate_message (client, true, advertise, len);if (r <0 )return r;
@@ -1311,11 +1312,17 @@ static int dhcp6_client_receive_reply(struct l_dhcp6_client *client,struct l_dhcp6_lease *lease;struct dhcp6_option_iter iter;int r; +/* +* Per RFC 7844 Section 4.3.1 we never send Client ID options in +* Information-requests so don't expect the replies to contain them. +*/ +bool expect_client_id = + (client->state !=DHCP6_STATE_REQUESTING_INFORMATION );if (reply->msg_type !=DHCP6_MESSAGE_TYPE_REPLY )return -EINVAL ; - r =dhcp6_client_validate_message (client, reply, len); + r =dhcp6_client_validate_message (client, expect_client_id, reply, len);if (r <0 )return r;
Signature · 1 line
2.34.1
Hi Andrew,
Quoted 9 lines · Andrew Zaborowski
Make sure we emit the
LEASE_OBTAINEDand notLEASE_RENEWEDevent after obtaining a reply to an Information-Request. Only setclient->request_nain stateful mode so as not to require the NA in the lease object when we're later validating it. Fix switching to BOUND state afterdhcp6_client_receive_reply()returns BOUND.--- ell/dhcp6.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
All applied, thanks.
Regards,
-Denis