From patchwork Mon Oct 3 22:28:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 12997856 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 948297B for ; Mon, 3 Oct 2022 22:29:02 +0000 (UTC) Received: by mail-wr1-f47.google.com with SMTP id j7so13342628wrr.3 for ; Mon, 03 Oct 2022 15:29:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date; bh=CrKNBnXAILvA9Ci9v32Smok3Yxnp1wH8M9yG7seoSF0=; b=7NDXXKRICiWXnTeQXTkWmyhHubJbs/pmcfuH6mXve6FjEz1F6pUHqel9V/Lz0EoXUW MQ/HQpKhS36rqOVEu90NQsFuPXgvpVngdz/SKiYmuQ19BsrUatDZhznpd5C0xOoIyl1E +ZyQ4jTPtgGlcKPKBGdjH/LeQ9oDoxTM4DEkXCkMiLIgL+0buPf68yXYq/V9X49a4CiQ EvY739v+S3gTUKPfrfK/WnYN/KOAfrJikZb2MGfB2eR07aydN3A9DZC/ywirZgUXXh8W SRACmR4bjniTa8cV8t63Znl0Wm3TNnHWGfhC1aGoGyq5r1M1DJXYF3TN+KyR7gX9Voji Cp+g== X-Gm-Message-State: ACrzQf09dJgtlwv+uWeqFmZbafYwsUY8pBnV1exOeT4sVbipoo9Dilg+ fBbjjUbkhK1ewQprupmZbcYN6d/4f1NVkQ== X-Google-Smtp-Source: AMsMyM63QKMED2wdCgJXWQGiRfEVhRMda4K1OHJCV9kLXMemJDh8Ir/lZSGzpuCkh+ABjUyv41b4rg== X-Received: by 2002:a05:6000:1566:b0:22e:2d99:76c3 with SMTP id 6-20020a056000156600b0022e2d9976c3mr7580478wrz.328.1664836140404; Mon, 03 Oct 2022 15:29:00 -0700 (PDT) Received: from localhost.localdomain ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id l9-20020a056000022900b0022b315b4649sm10434207wrz.26.2022.10.03.15.28.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 15:28:59 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 1/5] dhcp6: Fix emitting LEASE_OBTAINED in stateless mode Date: Tue, 4 Oct 2022 00:28:43 +0200 Message-Id: <20221003222847.699047-1-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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(-) diff --git a/ell/dhcp6.c b/ell/dhcp6.c index 2792ff2..3dbd0cd 100644 --- a/ell/dhcp6.c +++ b/ell/dhcp6.c @@ -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, From patchwork Mon Oct 3 22:28:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 12997857 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A645733C9 for ; Mon, 3 Oct 2022 22:29:03 +0000 (UTC) Received: by mail-wm1-f49.google.com with SMTP id ay36so7865965wmb.0 for ; Mon, 03 Oct 2022 15:29:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=U+cNKTXXloGb92ESHveJ5DLwyMf+edpInQque0FO0zM=; b=Yduiuu4S2mr0THOlWvUuvwL9KGKu5eqi1QzGbJIL2gIJidnaj4+xsG/AsTC/UrhGar Bbat82AHpdtI5B3iL/cX2N69TjCxUk84gaPcu3FxpkPXV5wumFFNFdAV1DSaBEYlOxHd 4SWuWs4ZvFZkkZlXrRMn2/fGI3MzurvxU6/5bMAtt41fLKOn46XR60oICyiWFDK7sxPR 2FAwLlrI7TFMJ5QpFkato6wbrJB20pWu6/j2rdHb/vTU7jIJ9oK9MG/6K3J090uIuE8b uoCRvtBYNPdLPpLCwfiaH+RKpwpYxmNghJXkMWcDxEDLZQGJjbMWdYgzUBE0a8RfjBjJ hBcg== X-Gm-Message-State: ACrzQf0eDAdH3028Qw/22sRCNF+y0LgADFileuX3W2KEdm8aMHh9ENNf gCTrAQgfcgeGh5t7yln6HyVWrOM3M7dk/Q== X-Google-Smtp-Source: AMsMyM7k/lkb70DV8Kq88a6RkL/Pdvjkjsx0w7AiW1sucLdOKrEl6dKMhNUpLSOL4JCPxPUNsV3JxA== X-Received: by 2002:a05:600c:27d1:b0:3b4:5e9c:23ed with SMTP id l17-20020a05600c27d100b003b45e9c23edmr7854207wmb.180.1664836141559; Mon, 03 Oct 2022 15:29:01 -0700 (PDT) Received: from localhost.localdomain ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id l9-20020a056000022900b0022b315b4649sm10434207wrz.26.2022.10.03.15.29.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 15:29:01 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 2/5] netconfig: Enable stateless DHCP mode Date: Tue, 4 Oct 2022 00:28:44 +0200 Message-Id: <20221003222847.699047-2-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221003222847.699047-1-andrew.zaborowski@intel.com> References: <20221003222847.699047-1-andrew.zaborowski@intel.com> Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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(-) diff --git a/ell/netconfig.c b/ell/netconfig.c index fe5bf40..e54e2f9 100644 --- a/ell/netconfig.c +++ b/ell/netconfig.c @@ -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; } From patchwork Mon Oct 3 22:28:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 12997858 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC2CC7B for ; Mon, 3 Oct 2022 22:29:04 +0000 (UTC) Received: by mail-wm1-f43.google.com with SMTP id 130-20020a1c0288000000b003b494ffc00bso9287499wmc.0 for ; Mon, 03 Oct 2022 15:29:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=352np4+Vvl4GITWnXLxw5PiWkWduXovJunaijCyYwTY=; b=Yh16O+V2I4HP2MeW6TCOYQyptT33EMI4lxAXiaOiIue66Gs+UVdDI9gSgGSwJfErBx k2+WLi3wAsKkUOSBSu0/v8Y8BYan3fLiwT7166JOIo24kDu7Cj3fxgs+z9AWnFJ/z//f tWZod2GCUYMCbqWdOhez4axfIBQhPzHoPs37jrSdg3ptTOTr8tXrpfj9Zq0UDbEaMlV8 ZZngKZ40eKwOP+DUhpZwLlUuI44r+mQnmquPYGfh8Y/YqBwElx6ujVVYlF5wVMLCRD6R a5z3tQFb1TRmEThWttPwUvrxDYD1yI4XwoqzmoOwtRbnCWS1TP1kq4qXYm7mgw2NmRTP 6slg== X-Gm-Message-State: ACrzQf23peRC1cn1AGGRbfYHRV4KiSn7CvLMfFhc8eLsUjyWKk8BozT2 U+FrS48KiuKYfnWaYwXpOrQJV2kbP7zNjQ== X-Google-Smtp-Source: AMsMyM5hrczSuJEEJ6JM29VHLZmugBNNdBZ/UsrTG1O3eLSD64x/h8Fi7nYyKhZ1teuH2uqBEuu5tA== X-Received: by 2002:a1c:7412:0:b0:3b4:7a81:e7e4 with SMTP id p18-20020a1c7412000000b003b47a81e7e4mr7734283wmc.15.1664836142717; Mon, 03 Oct 2022 15:29:02 -0700 (PDT) Received: from localhost.localdomain ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id l9-20020a056000022900b0022b315b4649sm10434207wrz.26.2022.10.03.15.29.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 15:29:01 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 3/5] netconfig: Return SLAAC+DHCP6 DNS info from getters Date: Tue, 4 Oct 2022 00:28:45 +0200 Message-Id: <20221003222847.699047-3-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221003222847.699047-1-andrew.zaborowski@intel.com> References: <20221003222847.699047-1-andrew.zaborowski@intel.com> Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In 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(-) diff --git a/ell/netconfig.c b/ell/netconfig.c index e54e2f9..7aac5ad 100644 --- a/ell/netconfig.c +++ b/ell/netconfig.c @@ -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; From patchwork Mon Oct 3 22:28:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 12997860 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0F3C33C9 for ; Mon, 3 Oct 2022 22:29:05 +0000 (UTC) Received: by mail-wr1-f51.google.com with SMTP id bk15so18691113wrb.13 for ; Mon, 03 Oct 2022 15:29:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=TVzIy4OOYGtD8U3hCNP460aQxBdJlNFEpxfDuXjjKsg=; b=MsW0SRpJuI5qKCzJ1jjYU4ruQvOf5+9GQ8JJJQGiC/a554nAiTXfZFK3LJmlsrBb/t p0lzlOOuXc3zKsiQYHYh8rQ85aJ+hdPbXKRl0XLz2wa/FJ8GCzn584382KC0DJpD6DUG QkLClRptJPaacbVcKYbSo5CAzUE8Zs9d9CXTa9zKsDgSTi6S5kuz1Gbatn2vyEtYL1bv StVi+RmuPrElejRKZJCfNHtEPQm9imCexjknzVfp9/ga1QEJiG639ONiP0QMeKFIOCze FvaF9fqhKIxKXYosbnPkTgCsIt2seYWlpl8AUtQ+4N7apH9H7px/A16T3cPN3qo9YrQg UG8g== X-Gm-Message-State: ACrzQf2q9s3Zg1/Y/VcQ6bY75MewYEocHF1Jf/64CLmScAmwAAtJB+G/ l4EJD45T6fwF0cZ76weOLZKsgtVn6ebvfQ== X-Google-Smtp-Source: AMsMyM6OdAzArzqVwaQ5UTfqBrcCXyv/JTvZ78ekT5RRqXNHvb7+pJ/Ebt+Oe0QeplCVsvdVsnvm3g== X-Received: by 2002:a05:6000:78a:b0:22e:4c41:9e36 with SMTP id bu10-20020a056000078a00b0022e4c419e36mr369513wrb.160.1664836143734; Mon, 03 Oct 2022 15:29:03 -0700 (PDT) Received: from localhost.localdomain ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id l9-20020a056000022900b0022b315b4649sm10434207wrz.26.2022.10.03.15.29.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 15:29:03 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 4/5] netconfig: Stop ongoing work on failure Date: Tue, 4 Oct 2022 00:28:46 +0200 Message-Id: <20221003222847.699047-4-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221003222847.699047-1-andrew.zaborowski@intel.com> References: <20221003222847.699047-1-andrew.zaborowski@intel.com> Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When 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(-) diff --git a/ell/netconfig.c b/ell/netconfig.c index 7aac5ad..76b18a7 100644 --- a/ell/netconfig.c +++ b/ell/netconfig.c @@ -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; } From patchwork Mon Oct 3 22:28:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 12997859 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A609833D9 for ; Mon, 3 Oct 2022 22:29:05 +0000 (UTC) Received: by mail-wr1-f47.google.com with SMTP id j7so13342798wrr.3 for ; Mon, 03 Oct 2022 15:29:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=YMlLnTf3srE3i5/B/X2C9Q8R1Z+Y0QSr7luB+e7ADrQ=; b=wwqrbK0FXm+79nw377Ll8GehYwvvsLObDGlkXlFNNzcNfzZcEbU08z65Vln5ozYWbh CF6noKIM1MAonAyZlaUdd6rwAnQBcFg+H+KgqmFtmUXFMrhnehPwZb/YlJ9FdahJQ8+4 Tye6+MME0qPd5DOTMjq24Ti5qXyFTbpOHf8nQ1DiVZClwiqTvf5iSmxspkePCKKTUy6W cPocrd3Kdp29yK4SvD5bXZYE1dFrYcjSHhHjOsEBrEaNaNjCAeF/3EhX1TrRVXrggWki qeGQL5rw+kmsAMsd73F/C8l4vAUL3+mUPFsrgDP2pJ2jqNYUmUva80X1rXfafnMzYsEh Y3rg== X-Gm-Message-State: ACrzQf2mYD7QKzggH+PItQfbNENhypDhDsW7NUt7Ts6pY+Ugi9+b7rfI /XmBnEaZnXhmlzOZL5sZZPBobBHVX2ThLg== X-Google-Smtp-Source: AMsMyM7VGCMUtf6smTaEMvE6/pn+bOaPCxnj4ItJlOkG3rnPvlTr3HWIPBKR7UXjiy5q6W03k2MxPw== X-Received: by 2002:a5d:404b:0:b0:22e:331e:1cba with SMTP id w11-20020a5d404b000000b0022e331e1cbamr6447593wrp.488.1664836144902; Mon, 03 Oct 2022 15:29:04 -0700 (PDT) Received: from localhost.localdomain ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id l9-20020a056000022900b0022b315b4649sm10434207wrz.26.2022.10.03.15.29.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 15:29:04 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 5/5] dhcp6: Don't require Client ID in Information-request reply Date: Tue, 4 Oct 2022 00:28:47 +0200 Message-Id: <20221003222847.699047-5-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221003222847.699047-1-andrew.zaborowski@intel.com> References: <20221003222847.699047-1-andrew.zaborowski@intel.com> Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since 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(-) diff --git a/ell/dhcp6.c b/ell/dhcp6.c index 3dbd0cd..a17dc49 100644 --- a/ell/dhcp6.c +++ b/ell/dhcp6.c @@ -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;