From patchwork Fri Sep 30 13:52: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: 12995443 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.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 69B7233C7 for ; Fri, 30 Sep 2022 13:53:15 +0000 (UTC) Received: by mail-wm1-f51.google.com with SMTP id c192-20020a1c35c9000000b003b51339d350so5079250wma.3 for ; Fri, 30 Sep 2022 06:53:15 -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=vpFAl3rqIU1iYzhZEiuF5G4ulQ+7hkV9H48xUc5Lkgw=; b=xw8e2r5uCgxdB0bBksWQlaLRZxboKhG3xrYK213x68B6L3fqt7acdizKcjpr4MnLQg 5ecXWK0nab93S2IOGd+TnXMnG757GFRbcM6itwd5/+Qfx7eTM5VhgTPEvMMCnIQa2lQ+ uoqSOGGR0W4NjQMLNpS8Fg7Cxx9bjUlu0cvhBSO4Oiq1KlFNHZHR30JanbgPKPhKJ7OR XGyoUZx/hhZSslMjbXZlQvt+UrC2jDHiVNzLoDM0BM+Zv4IAr14RjP5qtYcZB+sTD5rl Lm0iKwL4p56pD8Y0pxCSswq9SW81Vtm4FPCO5EBLn2nPhOoDRiUiNhDWNXePJq7Lvx0W gWeQ== X-Gm-Message-State: ACrzQf1febIE037FaS9Xiz2nYgAWiX1W8lFILoVM34TjIcFQqei3pbHA sytslJPApuAFEC+cdhW2c5tP1qirVqs= X-Google-Smtp-Source: AMsMyM5OwLSQNgMoxpia3luQUP4wu5gkXIZK6S3TDdwShmFSAQUKZknMkehxGu8P13zKn1x2lsg1Hw== X-Received: by 2002:a7b:c40e:0:b0:3b3:3faa:10c2 with SMTP id k14-20020a7bc40e000000b003b33faa10c2mr6100954wmi.32.1664545993270; Fri, 30 Sep 2022 06:53:13 -0700 (PDT) Received: from localhost.localdomain ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id p5-20020a05600c1d8500b003b492b30822sm2249801wms.2.2022.09.30.06.53.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 06:53:12 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 1/5] dhcp6: Include Client ID in Information-Request Date: Fri, 30 Sep 2022 15:52:46 +0200 Message-Id: <20220930135250.534296-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 The Reply parser requires that the Client ID be present in the Reply but the server only includes that if the Information-Request included the Client ID. 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." --- The obvious alternative is to not include the Client ID and not require it in the Reply validation, or make this configurable to avoid privacy concerns. I'm happy to go with either of these options. ell/dhcp6.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ell/dhcp6.c b/ell/dhcp6.c index 2792ff2..0705a7b 100644 --- a/ell/dhcp6.c +++ b/ell/dhcp6.c @@ -738,6 +738,8 @@ static int dhcp6_client_send_information_request(struct l_dhcp6_client *client) option_append_elapsed_time(builder, client->transaction_start_t); option_append_option_request(builder, client->request_options, DHCP6_STATE_REQUESTING_INFORMATION); + option_append_bytes(builder, DHCP6_OPTION_CLIENT_ID, + client->duid, client->duid_len); information_request = dhcp6_message_builder_free(builder, false, &information_request_len); From patchwork Fri Sep 30 13:52: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: 12995444 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 E2FB233D6 for ; Fri, 30 Sep 2022 13:53:15 +0000 (UTC) Received: by mail-wm1-f44.google.com with SMTP id iv17so2968655wmb.4 for ; Fri, 30 Sep 2022 06:53:15 -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=zfQrYDdRxoyURg/S7DaWn6z2piQ7bNf26UxoiAoEFUQ=; b=UUVOkEsLYxklHFbbA3PhXJtJtlBJEaSROXRIqdX/l5BR/2/L4m1lmm5jJ2DDS+HSLB HsT3EkbfgX66iZHLb9oqQGte4sk0TgfYt7i+yH2cgTRi8L3mhtSAB/f69PbZkGF7oHnB 4c2XGiBzqY7FsuPub1W5v9oXFzzzSaAyKmOwhVQBkkRtHk6DTte2Ed3xEgurqmCD1ZNT qbz7lNqH2hG/xc/QB1XFATipucmUE0hJPGozUy9mhAEfIsdKntEF6LS1HlGThtPMU3dx H/EeSkXNNM0Glma4IctK9TQyCNRfbsLTZkwawBogbVlDZsBWBrNet/Z8FYbtpn0ssXqY BGQg== X-Gm-Message-State: ACrzQf0DYg9TpsASqhqOu9Vy0poLFR99f2Akpm1bwyxOmttI9catjChy vqJIqSQcQEY++Idm5I6mNGdK7FnAcRM= X-Google-Smtp-Source: AMsMyM6V3Y/tMU7PtV/ps/9yKMkqSfES6YWhIyl3La8/ImSZp0/1hZYBLXP/HSVXT0nOJ+cvC6QXBw== X-Received: by 2002:a05:600c:548b:b0:3b5:95b:57d3 with SMTP id iv11-20020a05600c548b00b003b5095b57d3mr14527823wmb.153.1664545993995; Fri, 30 Sep 2022 06:53:13 -0700 (PDT) Received: from localhost.localdomain ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id p5-20020a05600c1d8500b003b492b30822sm2249801wms.2.2022.09.30.06.53.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 06:53:13 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 2/5] dhcp6: Fix emitting LEASE_OBTAINED in stateless mode Date: Fri, 30 Sep 2022 15:52:47 +0200 Message-Id: <20220930135250.534296-2-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220930135250.534296-1-andrew.zaborowski@intel.com> References: <20220930135250.534296-1-andrew.zaborowski@intel.com> 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 0705a7b..a4c13ee 100644 --- a/ell/dhcp6.c +++ b/ell/dhcp6.c @@ -973,8 +973,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; @@ -1387,7 +1388,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; @@ -1529,7 +1531,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, @@ -1805,6 +1806,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 Fri Sep 30 13:52:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 12995445 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 B201733DD for ; Fri, 30 Sep 2022 13:53:16 +0000 (UTC) Received: by mail-wr1-f54.google.com with SMTP id n10so6950628wrw.12 for ; Fri, 30 Sep 2022 06:53:16 -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=8KA5XiuPuC0jYbmr8XYokYhWvuDuU7kzKZLJmZwUzuJMCYbq1X4QVY59A9DMtLTtdF txiLct+OB9j04oX7TGYKFAPxPvS8YY4yTi1AQfYGFqXX67QP/wvHcDQasZy0jWxXNXqg I90E5bF6bNXBZudMsJAkV8v7WUl84riSA/05e4ITaodcYAF0fvCsdx2nnysF8x1Eys4b pK/qZ2rPnKhmNRmAvbINasOZVLy3ccH1z95ddKopUfeaPkI7J7h2Q6I3skA1O1cAp0ZT VFdBB0mq2pkbKs/Y1uGqQ4ClBhjH4ihQkds82sc4RNNxszG4UYeMJz6+KGMrUSBe2uFN QRuQ== X-Gm-Message-State: ACrzQf2Pd9CdTa3hCAgAhyWSp0/TfezNx7MsUuLhjesqHu0z3ptAml1z aqzLbzrN1tQRIEU6nUZB8VVUVnQ7gBI= X-Google-Smtp-Source: AMsMyM7FZO+iT7qg1IE2nqgbH/YOxLkMm2zN4vCLSxR6QCni9WAQnkjan+oeyhCDcCUyOTwZtJUPPg== X-Received: by 2002:a5d:4bc3:0:b0:22a:4b7a:6f60 with SMTP id l3-20020a5d4bc3000000b0022a4b7a6f60mr5866955wrt.549.1664545994743; Fri, 30 Sep 2022 06:53:14 -0700 (PDT) Received: from localhost.localdomain ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id p5-20020a05600c1d8500b003b492b30822sm2249801wms.2.2022.09.30.06.53.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 06:53:14 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 3/5] netconfig: Enable stateless DHCP mode Date: Fri, 30 Sep 2022 15:52:48 +0200 Message-Id: <20220930135250.534296-3-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220930135250.534296-1-andrew.zaborowski@intel.com> References: <20220930135250.534296-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 Fri Sep 30 13:52:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 12995446 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 7C48833C7 for ; Fri, 30 Sep 2022 13:53:17 +0000 (UTC) Received: by mail-wr1-f47.google.com with SMTP id bk15so6956120wrb.13 for ; Fri, 30 Sep 2022 06:53:17 -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=csSyTrRZAQ7LJ2AhwIEwwd0X1oGuRzuD2UQ2Y1UmuYGKLMmp3bop/ouiuXtpANXmTs 5ZPI4qJQxAxOriUycXwA45sHjwWifTrWqrcxAtZG3y81Lj7p9aqyiiIinUbQeaFPQZqF OwvTW5YfUnJ79aWRNILF79GpxaJnxNtuE5AhAOtcImc41Lc/8RAFMJfd8IiQXs/QawW9 XVdxsmmR8YYksLlALmuW0q+Z2ReixXqcWmzBudLy7NLxBgvAyihwYu1Zev+8txABkLbw UmFHZyQ//UMbmUw+Bw/wBn2LYcMa0aOIO36Nu8kRuRLsSeDFrgf+aFr59zkHsiPr8p6E a0pg== X-Gm-Message-State: ACrzQf08ejtC4jw6z8b8o+mUz77lZbxoa0dsN2cEs6dxws7Y1NEYMrcL /QsqYu1eRLxRBtISUdaLUkkne3efok0= X-Google-Smtp-Source: AMsMyM7tByFYrhHpxD/FE6Ev0cGhf9obZHXeWOLIzG3/wyv6rJ23XVnlZQHRpoKE6djfrMDo1m1nSw== X-Received: by 2002:adf:d1c2:0:b0:22a:66ad:2669 with SMTP id b2-20020adfd1c2000000b0022a66ad2669mr5947428wrd.468.1664545995519; Fri, 30 Sep 2022 06:53:15 -0700 (PDT) Received: from localhost.localdomain ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id p5-20020a05600c1d8500b003b492b30822sm2249801wms.2.2022.09.30.06.53.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 06:53:15 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 4/5] netconfig: Return SLAAC+DHCP6 DNS info from getters Date: Fri, 30 Sep 2022 15:52:49 +0200 Message-Id: <20220930135250.534296-4-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220930135250.534296-1-andrew.zaborowski@intel.com> References: <20220930135250.534296-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 Fri Sep 30 13:52:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 12995447 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 4EC4D33D6 for ; Fri, 30 Sep 2022 13:53:18 +0000 (UTC) Received: by mail-wr1-f48.google.com with SMTP id bq9so6974817wrb.4 for ; Fri, 30 Sep 2022 06:53:18 -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=b7uGN73tl9BPQyBTOenY40qVxxsYOzmK9SPMffs579Qw9PY78PuHIkH753zgnksDkZ tIole8lF6uRuI/a2/NA8OSVWs4LzJkpuUfMxNHM9/yS18LOESjL78dP0YMli3i4NH3Rb c+hHd7q0J/Z0IhbskWsoUkoY8y6+m1rIZDOCDjcX19D5CPq9Aodv/cE1zzGtu+wM/oQF dI+h5796QM0csM/Xe0G3VRdn64QHWLO099Xe4I4SfRuwRjtrwR4NPWDPIKDFQdCxF1w1 u3RGSAMO8fcchU/eGZxwo87O6+bIa0R7Vg65XulASFHZ+XTWK68Fi8AlpBsvEFOmBZ+Q a4UQ== X-Gm-Message-State: ACrzQf0ZI768Lzi5cOlvoNi8VIqsHVMa+9/ZvsFpcgScorhRgzlH7Wkp wRpaFWch7z5Lit92NIqsYhIC6mgQXbM= X-Google-Smtp-Source: AMsMyM56gq0GaKwu6841HItAL08Th8BUcfVF9E7cqqwtPwllNNAnqwhsgojbkI1FIlXmoLE2Zv0wmw== X-Received: by 2002:a05:6000:98b:b0:22c:c3b1:3f2a with SMTP id by11-20020a056000098b00b0022cc3b13f2amr6032249wrb.11.1664545996303; Fri, 30 Sep 2022 06:53:16 -0700 (PDT) Received: from localhost.localdomain ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id p5-20020a05600c1d8500b003b492b30822sm2249801wms.2.2022.09.30.06.53.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 06:53:15 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 5/5] netconfig: Stop ongoing work on failure Date: Fri, 30 Sep 2022 15:52:50 +0200 Message-Id: <20220930135250.534296-5-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220930135250.534296-1-andrew.zaborowski@intel.com> References: <20220930135250.534296-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; }