From patchwork Tue Sep 20 13:31:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 12982188 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 3D1001C14 for ; Tue, 20 Sep 2022 13:32:07 +0000 (UTC) Received: by mail-wr1-f48.google.com with SMTP id g3so4243842wrq.13 for ; Tue, 20 Sep 2022 06:32:07 -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=p+uD+/L+jxWQUGdqxtyjWsUrv0xM55qHt3jLx4B27ZA=; b=yOikbv0ZG3i9dHEVoMrn4o6X1UBAip2ytFX5rmz8h52pSXZjj/40zRb5BDDzfYBjd9 JtH+CJcUrSrOMv8a8hbh5W1J7hbWr7jVl++CtoNb+e/JgEuOqdIvkPztaviWxIL94WDe L+KN0g1AxN4AzJbZMdtGnLL1uWdsYz5rxHAdLwNtBdnsl2A4mw49R63wjPUP10umqHL/ kpk0XNPgCzt8TvtODQ2Aph23aON9YcnlXuH9Dv328al9wEJUV7L3EdJH6TJXyJnWLZY7 v/woboeChFzcz0/t/AKgMkTzv5xZs+TX262UVlw1xE1nw/TIGYQxvOqUktAR6Fpx6NwB +L9Q== X-Gm-Message-State: ACrzQf2RlKVIEsNG1bK9W6MQaADDnnkkDd5aMaPPMzxtID+LA44pncev ruzykAMJkbv9nX6X958tA1s8FbXo/MGL8yyl X-Google-Smtp-Source: AMsMyM488yun7hSrNNQGDXFfXd7nUVx4w/G2/vMlbM3wZH7mzPPsWDabZOX5zHCz2DhmWyWLpnpDlg== X-Received: by 2002:a5d:52cb:0:b0:21a:3cc5:f5f4 with SMTP id r11-20020a5d52cb000000b0021a3cc5f5f4mr14548670wrv.367.1663680725087; Tue, 20 Sep 2022 06:32:05 -0700 (PDT) Received: from iss.ger.corp.intel.com ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id d16-20020adff2d0000000b0022863395912sm2082wrp.53.2022.09.20.06.32.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 06:32:04 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 1/6] net: Allow padding in net_domain_list_parse Date: Tue, 20 Sep 2022 15:31:56 +0200 Message-Id: <20220920133201.3303119-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 domain name lists in ICMPv6 options may be 0-padded meaning that a 0-byte at the beginning of a domain record (ie. a domain with no labels) is allowed and should be treated as the end of the list. Add a boolean parameter to tell net_domain_list_parse() whether to allow this. Fixes: 4b1ce9b3e3d0 ("icmp6: Parse RDNSS and DNSSL options") --- ell/dhcp6-lease.c | 2 +- ell/icmp6.c | 6 +++--- ell/net-private.h | 2 +- ell/net.c | 8 +++++++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ell/dhcp6-lease.c b/ell/dhcp6-lease.c index 978176a..a92cff9 100644 --- a/ell/dhcp6-lease.c +++ b/ell/dhcp6-lease.c @@ -312,7 +312,7 @@ struct l_dhcp6_lease *_dhcp6_lease_parse_options( lease->rapid_commit = true; break; case L_DHCP6_OPTION_DOMAIN_LIST: - lease->domain_list = net_domain_list_parse(v, l); + lease->domain_list = net_domain_list_parse(v, l, false); if (!lease->domain_list) goto error; diff --git a/ell/icmp6.c b/ell/icmp6.c index a2765ea..5ddc494 100644 --- a/ell/icmp6.c +++ b/ell/icmp6.c @@ -1104,11 +1104,11 @@ struct l_icmp6_router *_icmp6_router_parse(const struct nd_router_advert *ra, { struct domain_info *info = &r->domains[n_domains]; _auto_(l_free) char **domain_list = - net_domain_list_parse(opts + 8, l - 8); + net_domain_list_parse(opts + 8, l - 8, true); char **i; - /* Ignore invalid option */ - if (!domain_list) + /* Ignore malformed option */ + if (!domain_list || !domain_list[0]) break; for (i = domain_list; *i; i++) { diff --git a/ell/net-private.h b/ell/net-private.h index 39d4d98..a864034 100644 --- a/ell/net-private.h +++ b/ell/net-private.h @@ -21,7 +21,7 @@ */ char *net_domain_name_parse(const uint8_t *raw, size_t raw_len); -char **net_domain_list_parse(const uint8_t *raw, size_t raw_len); +char **net_domain_list_parse(const uint8_t *raw, size_t raw_len, bool padded); static inline const void *net_prefix_from_ipv6(const uint8_t *address, uint8_t prefix_len) diff --git a/ell/net.c b/ell/net.c index 378b9f2..aa7fc20 100644 --- a/ell/net.c +++ b/ell/net.c @@ -295,7 +295,7 @@ char *net_domain_name_parse(const uint8_t *raw, size_t raw_len) /* * Parse list of domain names encoded according to RFC 1035 Section 3.1 */ -char **net_domain_list_parse(const uint8_t *raw, size_t raw_len) +char **net_domain_list_parse(const uint8_t *raw, size_t raw_len, bool padded) { size_t remaining = raw_len; const uint8_t *p = raw; @@ -305,6 +305,9 @@ char **net_domain_list_parse(const uint8_t *raw, size_t raw_len) struct l_string *growable = NULL; while (remaining) { + if (padded && p[0] == 0) + break; + r = validate_next_domain_name(p, remaining); if (r < 0) return NULL; @@ -323,6 +326,9 @@ char **net_domain_list_parse(const uint8_t *raw, size_t raw_len) remaining -= *p + 1; if (*p == 0) { + if (!growable) + break; + p += 1; ret[nitems++] = l_string_unwrap(growable); growable = NULL; From patchwork Tue Sep 20 13:31:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 12982189 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 E38631C2D for ; Tue, 20 Sep 2022 13:32:07 +0000 (UTC) Received: by mail-wr1-f48.google.com with SMTP id bq9so4325744wrb.4 for ; Tue, 20 Sep 2022 06:32:07 -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=DUiwdwzhPJguHKXKA3ySWVT+9rY4F7aeUFf/xvB39Xw=; b=XAVlzRTNlGRgp4kMg2cUkb6TzIU04TzcxlND05l0qtk7DbWJE2JZKpzDXriQNzpILm FQhAH7D1V7rgfMmKmGbs+PcH6MRY+zdtcYwRMyu2Gtxb6zh1xvdRqv8mDO2Jgma4i1qr d/t1yWtQYrTwkdmOGe80kBUgRg86lhqXMK7D4tQWQPIL8Hh3wbfkPYcDSBp9/v+RXfCh SQRw++LUJLqFw+IB/gDJeEi7byJamOlGDny3IrrKMwxNyAAGK3cZo7LP2RXPw/AYqm+3 PxjshWU7rgRnaTAdGaLDjxJ5rqbD3stEnSxS+59Ofwx80YF5+v90yxPQDlCGiUK7EhTp bphg== X-Gm-Message-State: ACrzQf1N+7HThr8S13TPNcT11ZOHysP3evTznu3vlIb72faSulFi/ctL 75v8ThZ3TJ3FpLqSGZY7ocovuIxyVAioKtJB X-Google-Smtp-Source: AMsMyM7LxRfRLmaFVohEVL9ATeFJzi9lTzvea1mkvHFAbGy2j5gPrWT+5lXIxJbZk/kZGbzctn0DEQ== X-Received: by 2002:a05:6000:1687:b0:22a:3516:4f98 with SMTP id y7-20020a056000168700b0022a35164f98mr14055871wrd.525.1663680725976; Tue, 20 Sep 2022 06:32:05 -0700 (PDT) Received: from iss.ger.corp.intel.com ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id d16-20020adff2d0000000b0022863395912sm2082wrp.53.2022.09.20.06.32.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 06:32:05 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 2/6] unit: Update net_domain_list_parse test Date: Tue, 20 Sep 2022 15:31:57 +0200 Message-Id: <20220920133201.3303119-2-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220920133201.3303119-1-andrew.zaborowski@intel.com> References: <20220920133201.3303119-1-andrew.zaborowski@intel.com> Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- unit/test-net.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/unit/test-net.c b/unit/test-net.c index ff5d2b0..f3f1522 100644 --- a/unit/test-net.c +++ b/unit/test-net.c @@ -113,11 +113,13 @@ static void test_net_domain_list_parse(const void *data) static const uint8_t l1[] = { 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 3, 'c', 'o', 'm', 0, 4, 't', 'e', 's', 't', 0 }; - static const uint8_t l2[] = { 0, 0}; + static const uint8_t l2[] = { 0, 0 }; static const uint8_t l3[] = { 4, '.', '=', '2', '3', 0 }; + static const uint8_t l4[] = { 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', + 3, 'c', 'o', 'm', 0, 0 }; char **domains; - domains = net_domain_list_parse(l1, sizeof(l1)); + domains = net_domain_list_parse(l1, sizeof(l1), false); assert(domains); assert(domains[0]); assert(!strcmp(domains[0], "example.com")); @@ -126,14 +128,21 @@ static void test_net_domain_list_parse(const void *data) assert(!domains[2]); l_strfreev(domains); - assert(!net_domain_list_parse(l2, sizeof(l2))); + assert(!net_domain_list_parse(l2, sizeof(l2), false)); - domains = net_domain_list_parse(l3, sizeof(l3)); + domains = net_domain_list_parse(l3, sizeof(l3), false); assert(domains); assert(domains[0]); assert(!strcmp(domains[0], "\\.\\06123")); assert(!domains[1]); l_strfreev(domains); + + domains = net_domain_list_parse(l4, sizeof(l4), true); + assert(domains); + assert(domains[0]); + assert(!strcmp(domains[0], "example.com")); + assert(!domains[1]); + l_strfreev(domains); } int main(int argc, char *argv[]) From patchwork Tue Sep 20 13:31:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 12982190 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 B5DBB1C33 for ; Tue, 20 Sep 2022 13:32:08 +0000 (UTC) Received: by mail-wr1-f52.google.com with SMTP id cc5so4314148wrb.6 for ; Tue, 20 Sep 2022 06:32:08 -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=JLhqwAlbrMsNsRZNtb/RuhRTR9JVrlsRMis9PRUC6HI=; b=VxuAXuAnZsRMQqtz/aOOb0JZRBBBtj+hk5KLTmchHdO7Eu3v+37MDtvUXVEPfLII1E 1MdoAz3oEJITGB5NDAQcAIDPfjsR2UIdi5KpkwVoWpTMgZDc43n374j1s93ooW15buyr TpoRSnv86etN2dvCLni51MuqBZCApPoi0I/jKCezU5AKG7IEYGAtsqc7fxS7NL9zP2nI zR6LVEfR+8obEryK3VFge0G7LIrifOGtuwXeHymBpp3WYUGNRqTmeYo8/fIo/Qz6mdqJ 3tGOFDQTENIsI+FqfyTjPpvxZBzCroQPuWtpIvibjgtoNyiOQLgRVU/qPQhP/0uSZ7Rt GV8Q== X-Gm-Message-State: ACrzQf0gVfqNi7SuMDS/QNEcWoq23Zc2EtJMoZqpbC+d9OKq7Ww/NAVP E6oAzCdFS6gnys/b9p73eFLhHLIqWjeoP7yR X-Google-Smtp-Source: AMsMyM5sRAYom4O4ONewW++iISw28OLgVJ2URc+ysmFQRfoy5v7ztyD14v+d/DmbB23KASYs/Vhx9g== X-Received: by 2002:a5d:6d89:0:b0:22a:f378:e701 with SMTP id l9-20020a5d6d89000000b0022af378e701mr9720803wrs.199.1663680726708; Tue, 20 Sep 2022 06:32:06 -0700 (PDT) Received: from iss.ger.corp.intel.com ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id d16-20020adff2d0000000b0022863395912sm2082wrp.53.2022.09.20.06.32.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 06:32:06 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 3/6] netconfig: Set .v6_configured when we set an address Date: Tue, 20 Sep 2022 15:31:58 +0200 Message-Id: <20220920133201.3303119-3-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220920133201.3303119-1-andrew.zaborowski@intel.com> References: <20220920133201.3303119-1-andrew.zaborowski@intel.com> Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The DNS getters won't work without this as they return NULL if .v6_configured is false. Fixes: 6adf0f5db455 ("netconfig: Create SLAAC address") --- ell/netconfig.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ell/netconfig.c b/ell/netconfig.c index 7a9ee89..e5c7b51 100644 --- a/ell/netconfig.c +++ b/ell/netconfig.c @@ -750,6 +750,7 @@ 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); /* TODO: set a renew timeout */ From patchwork Tue Sep 20 13:31:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 12982191 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 D71E01C14 for ; Tue, 20 Sep 2022 13:32:09 +0000 (UTC) Received: by mail-wm1-f49.google.com with SMTP id n8so1928669wmr.5 for ; Tue, 20 Sep 2022 06:32:09 -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=AZi3cbry6UKzY4JlMsSbIQlN6BVUAUgZlnk+ekcym10=; b=6KixW1z+4SNGB8xxTUELVb7AJ8Nr3lPY7GIlj0sGvi0A1s7gXIWoy2VNToJ8am5APV zIl7JqMZ3kKxR7F1By3C8h+TtKo/acnlKoiqh0xg0HLS2iFmJ17Ya+LkzZtxU931C2eq 9AC006aJ8tTTU1ApOpzkPA+gCrUT+hU5Byn1a4MvSHwz7fXH27bEg9/y0FbghMt8pKhY Bu3sD8AeE/8A6pXfQTZQVd/vSmYDrlp1AmT9rbcgx4/99c9xL8EYoujdynVOc7H4OA6/ FJUN+u3CULQtiraEgWPYOUykBH0dTAj4Zo4GGT30JkWvnakV51LUVQTfTUx0lX5HZLRH n+yQ== X-Gm-Message-State: ACrzQf2lTKGLmsgDNfPaBTUxbu0mG5XsMzkB/Ldf5Wch2jhYYkS5MxLM JZnIoOA+UKn27aLVKup5tBlJG5kAZQtvCue0 X-Google-Smtp-Source: AMsMyM7nPKTymL4mLW57nLO5LSBu86baNXFWfbY3krDIXyDEi3jPwXUVfTiB+4zGJpzR+MNTO/uEaA== X-Received: by 2002:a7b:cb49:0:b0:3b4:b08a:89b with SMTP id v9-20020a7bcb49000000b003b4b08a089bmr2405898wmj.173.1663680727712; Tue, 20 Sep 2022 06:32:07 -0700 (PDT) Received: from iss.ger.corp.intel.com ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id d16-20020adff2d0000000b0022863395912sm2082wrp.53.2022.09.20.06.32.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 06:32:07 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 4/6] netconfig: Handle DNS data from l_icmp6_router Date: Tue, 20 Sep 2022 15:31:59 +0200 Message-Id: <20220920133201.3303119-4-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220920133201.3303119-1-andrew.zaborowski@intel.com> References: <20220920133201.3303119-1-andrew.zaborowski@intel.com> Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Track the lists of DNSes and search domains based on Router Advertisement options parsed by l_icmp6_client. Return them in l_netconfig_get_dns_list, l_netconfig_get_domain_names. --- ell/netconfig.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 154 insertions(+), 6 deletions(-) diff --git a/ell/netconfig.c b/ell/netconfig.c index e5c7b51..765703b 100644 --- a/ell/netconfig.c +++ b/ell/netconfig.c @@ -98,6 +98,8 @@ struct l_netconfig { NETCONFIG_V6_METHOD_DHCP, NETCONFIG_V6_METHOD_SLAAC, } v6_auto_method; + struct l_queue *slaac_dnses; + struct l_queue *slaac_domains; /* These objects, if not NULL, are owned by @addresses and @routes */ struct l_rtnl_address *v4_address; @@ -151,6 +153,8 @@ static struct l_queue *addr_wait_list; static unsigned int rtnl_id; static const unsigned int max_icmp6_routes = 100; +static const unsigned int max_icmp6_dnses = 10; +static const unsigned int max_icmp6_domains = 10; static void netconfig_update_cleanup(struct l_netconfig *nc) { @@ -681,6 +685,16 @@ static bool netconfig_match(const void *a, const void *b) return a == b; } +static bool netconfig_match_addr(const void *a, const void *b) +{ + return memcmp(a, b, 16) == 0; +} + +static bool netconfig_match_str(const void *a, const void *b) +{ + return strcmp(a, b) == 0; +} + static bool netconfig_check_start_dhcp6(struct l_netconfig *nc) { /* Don't start DHCPv6 until we get an RA with the managed bit set */ @@ -809,6 +823,88 @@ static void netconfig_set_slaac_address_lifetimes(struct l_netconfig *nc, l_queue_push_tail(nc->addresses.updated, nc->v6_address); } +static bool netconfig_process_slaac_dns_info(struct l_netconfig *nc, + const struct l_icmp6_router *r) +{ + bool updated = false; + unsigned int i; + unsigned int n_dns = l_queue_length(nc->slaac_dnses); + unsigned int n_domains = l_queue_length(nc->slaac_domains); + + for (i = 0; i < r->n_dns; i++) { + const struct dns_info *info = &r->dns_list[i]; + + /* + * For simplicity don't track lifetimes (TODO), add entries + * when the lifetime is non-zero, remove them when the + * lifetime is zero. We have no API to add time-limited + * entries to the system either. + * + * RFC8106 Section 5.1: "A value of zero means that the RDNSS + * addresses MUST no longer be used." + */ + if (info->lifetime) { + if (n_dns >= max_icmp6_dnses) + continue; + + if (l_queue_find(nc->slaac_dnses, netconfig_match_addr, + info->address)) + continue; + + l_queue_push_tail(nc->slaac_dnses, + l_memdup(info->address, 16)); + n_dns++; + } else { + void *addr = l_queue_remove_if(nc->slaac_dnses, + netconfig_match_addr, + info->address); + + if (!addr) + continue; + + l_free(addr); + n_dns--; + } + + updated = true; + } + + for (i = 0; i < r->n_domains; i++) { + const struct domain_info *info = &r->domains[i]; + + /* + * RFC8106 Section 5.2: "A value of zero means that the DNSSL + * domain names MUST no longer be used." + */ + if (info->lifetime) { + if (n_domains >= max_icmp6_domains) + continue; + + if (l_queue_find(nc->slaac_domains, netconfig_match_str, + info->domain)) + continue; + + l_queue_push_tail(nc->slaac_domains, + l_strdup(info->domain)); + n_domains++; + } else { + void *str = l_queue_remove_if(nc->slaac_domains, + netconfig_match_str, + info->domain); + + if (!str) + continue; + + l_free(str); + n_domains--; + } + + updated = true; + } + + return updated; +} + static uint64_t now; static bool netconfig_check_route_expired(void *data, void *user_data) @@ -1027,6 +1123,7 @@ static void netconfig_icmp6_event_handler(struct l_icmp6_client *client, const struct l_icmp6_router *r; struct netconfig_route_data *default_rd; unsigned int i; + bool dns_updated = false; if (event != L_ICMP6_CLIENT_EVENT_ROUTER_FOUND) return; @@ -1122,6 +1219,14 @@ process_nondefault_routes: r->n_ac_prefixes) { 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 @@ -1156,6 +1261,7 @@ 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: /* @@ -1168,7 +1274,8 @@ emit_event: !l_queue_isempty(nc->routes.updated) || !l_queue_isempty(nc->routes.removed) || !l_queue_isempty(nc->routes.expired) || - !l_queue_isempty(nc->addresses.updated)) + !l_queue_isempty(nc->addresses.updated) || + dns_updated) netconfig_emit_event(nc, AF_INET6, L_NETCONFIG_EVENT_UPDATE); } @@ -2007,6 +2114,8 @@ LIB_EXPORT void l_netconfig_stop(struct l_netconfig *netconfig) l_queue_clear(netconfig->routes.current, (l_queue_destroy_func_t) l_rtnl_route_free); l_queue_clear(netconfig->icmp_route_data, l_free); + l_queue_clear(netconfig->slaac_dnses, l_free); + l_queue_clear(netconfig->slaac_domains, l_free); netconfig->v4_address = NULL; netconfig->v4_subnet_route = NULL; netconfig->v4_default_route = NULL; @@ -2255,9 +2364,31 @@ append_v6: if (netconfig->v6_dns_override) netconfig_strv_cat(&ret, netconfig->v6_dns_override, false); - else if ((v6_lease = - l_dhcp6_client_get_lease(netconfig->dhcp6_client))) + else if (netconfig->v6_auto_method == NETCONFIG_V6_METHOD_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)) { + unsigned int dest_len = l_strv_length(ret); + unsigned int src_len = l_queue_length(netconfig->slaac_dnses); + char **i; + const struct l_queue_entry *entry; + + ret = l_realloc(ret, sizeof(char *) * (dest_len + src_len + 1)); + i = ret + dest_len; + + for (entry = l_queue_get_entries(netconfig->slaac_dnses); + entry; entry = entry->next) { + char addr_str[INET6_ADDRSTRLEN]; + + if (inet_ntop(AF_INET6, entry->data, addr_str, + sizeof(addr_str))) + *i++ = l_strdup(addr_str); + } + + *i = NULL; + } done: return ret; @@ -2288,13 +2419,30 @@ append_v6: if (!netconfig->v6_configured) goto done; - if (netconfig->v6_dns_override) + if (netconfig->v6_domain_names_override) netconfig_strv_cat(&ret, netconfig->v6_domain_names_override, false); - else if ((v6_lease = - l_dhcp6_client_get_lease(netconfig->dhcp6_client))) + else if (netconfig->v6_auto_method == NETCONFIG_V6_METHOD_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)) { + unsigned int dest_len = l_strv_length(ret); + unsigned int src_len = l_queue_length(netconfig->slaac_domains); + char **i; + const struct l_queue_entry *entry; + + ret = l_realloc(ret, sizeof(char *) * (dest_len + src_len + 1)); + i = ret + dest_len; + + for (entry = l_queue_get_entries(netconfig->slaac_domains); + entry; entry = entry->next) + *i++ = l_strdup(entry->data); + + *i = NULL; + } done: return ret; From patchwork Tue Sep 20 13:32:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 12982192 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 C639F1C33 for ; Tue, 20 Sep 2022 13:32:10 +0000 (UTC) Received: by mail-wr1-f48.google.com with SMTP id n10so4244818wrw.12 for ; Tue, 20 Sep 2022 06:32:10 -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=OtK7kWrHD4n3tNmGYWwa7daNLr6uxs5H43rd9QcxanI=; b=vGQOqiaTdeEtcvwxYmNR3XEq5rI4tRiwpap9AxsnnSQWuPlNWa0wf/9m3BtI2MM5sJ 9vCo8t6k0s4dSrbanJEwLo66Z7VIjxL5GjsHqyu54l2eTkOKbyLudmTfJLUNBNLKcgPx BSh8e3L+UJ1TEkEv05vgt1wpgS7SAQakWNV7Z/Yr1DGDJVdzTYGobEN0V5+eh+3N0yNT BVlE/3B4gajUGQeJ6q1fZE7Gzw+B3N3mru3hnzbJWBtVTgnrwYmDtJKFadm5fX37Q7hN 9AsC/GE1Blx9Outu9tZQMyzz6f+jLyclvuJK4iIYCE61PbVsBKQZYQt4iuu+Dl07RXkD g1Ug== X-Gm-Message-State: ACrzQf1/sTX8OKWS2wXwpV0cOITfOhef+jMIQ6iTp0p/KpfZcORBDylY t3SwUauiP3D8dLWfy7ZJB+zJH+8lbcaF5NMt X-Google-Smtp-Source: AMsMyM6CBHvdUSDPy6IW568ALo2xTTGW+xqNEJZIyPYiXMk26qWeCNdJcv5D2NL1lzZscX0u9p4wJA== X-Received: by 2002:a5d:588f:0:b0:22a:fe0c:afb8 with SMTP id n15-20020a5d588f000000b0022afe0cafb8mr7011701wrf.431.1663680728675; Tue, 20 Sep 2022 06:32:08 -0700 (PDT) Received: from iss.ger.corp.intel.com ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id d16-20020adff2d0000000b0022863395912sm2082wrp.53.2022.09.20.06.32.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 06:32:08 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 5/6] icmp6,netconfig: Skip SLLAO if RS sent from optimistic address Date: Tue, 20 Sep 2022 15:32:00 +0200 Message-Id: <20220920133201.3303119-5-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220920133201.3303119-1-andrew.zaborowski@intel.com> References: <20220920133201.3303119-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 don't include de Source Link-Local Address Option in our Router Solicitations until the source link-local address completes DAD. Extand the recently added l_icmp6_client_set_link_local_address() with a parameter to tell us whether the address is optimistic. Don't change the l_dhcp6_client_set_link_local_address signature to avoid breaking existing users. --- ell/dhcp6.c | 2 +- ell/icmp6.c | 29 +++++++++++++++++++++-------- ell/icmp6.h | 3 ++- ell/netconfig.c | 30 ++++++++++++++++++++++++++---- 4 files changed, 50 insertions(+), 14 deletions(-) diff --git a/ell/dhcp6.c b/ell/dhcp6.c index e234eb0..2792ff2 100644 --- a/ell/dhcp6.c +++ b/ell/dhcp6.c @@ -1623,7 +1623,7 @@ LIB_EXPORT bool l_dhcp6_client_set_link_local_address( return false; if (!client->nora) - l_icmp6_client_set_link_local_address(client->icmp6, ll); + l_icmp6_client_set_link_local_address(client->icmp6, ll, false); return true; } diff --git a/ell/icmp6.c b/ell/icmp6.c index 5ddc494..f087ba3 100644 --- a/ell/icmp6.c +++ b/ell/icmp6.c @@ -206,7 +206,8 @@ static uint16_t icmp6_checksum(const struct iovec *iov, unsigned int iov_len) static int icmp6_send_router_solicitation(int s, int ifindex, const uint8_t src_mac[static 6], - const struct in6_addr *src_ip) + const struct in6_addr *src_ip, + bool src_ip_optimistic) { struct nd_router_solicit rs = { .nd_rs_type = ND_ROUTER_SOLICIT, @@ -247,11 +248,17 @@ static int icmp6_send_router_solicitation(int s, int ifindex, memcpy(&ip_hdr.ip6_src, src_ip, 16); - if (l_memeqzero(src_ip, 16)) { + if (l_memeqzero(src_ip, 16) || src_ip_optimistic) { /* - * radvd will discard and warn about RSs from the unspecified - * address with the SLLAO, omit that option by dropping the - * last two iov buffers. + * RFC 4429 Section 3.2: "A node MUST NOT send a Router + * Solicitation with a SLLAO from an Optimistic Address. + * Router Solicitations SHOULD be sent from a non-Optimistic + * or the Unspecified Address; however, they MAY be sent from + * an Optimistic Address as long as the SLLAO is not included." + * + * Additionally radvd will also discard and warn about RSs + * from the unspecified address with the SLLAO. Omit that + * option by dropping the last two iov buffers. */ msg.msg_iovlen -= 2; ip_hdr.ip6_plen = htons(ntohs(ip_hdr.ip6_plen) - rs_sllao_size); @@ -347,6 +354,7 @@ struct l_icmp6_client { uint64_t retransmit_time; struct l_io *io; struct in6_addr src_ip; + bool src_ip_optimistic; struct l_icmp6_router *ra; struct l_netlink *rtnl; @@ -547,7 +555,8 @@ static void icmp6_client_timeout_send(struct l_timeout *timeout, r = icmp6_send_router_solicitation(l_io_get_fd(client->io), client->ifindex, client->mac, - &client->src_ip); + &client->src_ip, + client->src_ip_optimistic); if (r < 0) { CLIENT_DEBUG("Error sending Router Solicitation: %s", strerror(-r)); @@ -766,7 +775,7 @@ LIB_EXPORT bool l_icmp6_client_set_route_priority( LIB_EXPORT bool l_icmp6_client_set_link_local_address( struct l_icmp6_client *client, - const char *ll) + const char *ll, bool optimistic) { if (unlikely(!client)) return false; @@ -777,7 +786,11 @@ LIB_EXPORT bool l_icmp6_client_set_link_local_address( * is fine. Once we have a confirmed link-local address we use that * as the source address. */ - return inet_pton(AF_INET6, ll, &client->src_ip) == 1; + if (inet_pton(AF_INET6, ll, &client->src_ip) != 1) + return false; + + client->src_ip_optimistic = optimistic; + return true; } struct l_icmp6_router *_icmp6_router_new() diff --git a/ell/icmp6.h b/ell/icmp6.h index ffbb8a8..ad3d661 100644 --- a/ell/icmp6.h +++ b/ell/icmp6.h @@ -66,7 +66,8 @@ bool l_icmp6_client_set_rtnl(struct l_icmp6_client *client, bool l_icmp6_client_set_route_priority(struct l_icmp6_client *client, uint32_t priority); bool l_icmp6_client_set_link_local_address(struct l_icmp6_client *client, - const char *ll); + const char *ll, + bool optimistic); char *l_icmp6_router_get_address(const struct l_icmp6_router *r); bool l_icmp6_router_get_managed(const struct l_icmp6_router *r); diff --git a/ell/netconfig.c b/ell/netconfig.c index 765703b..c558cad 100644 --- a/ell/netconfig.c +++ b/ell/netconfig.c @@ -93,6 +93,7 @@ struct l_netconfig { unsigned int orig_optimistic_dad; uint8_t mac[ETH_ALEN]; struct l_timeout *ra_timeout; + bool have_lla; enum { NETCONFIG_V6_METHOD_UNSET, NETCONFIG_V6_METHOD_DHCP, @@ -702,7 +703,7 @@ static bool netconfig_check_start_dhcp6(struct l_netconfig *nc) return true; /* Don't start DHCPv6 while waiting for the link-local address */ - if (l_queue_find(addr_wait_list, netconfig_match, nc)) + if (!nc->have_lla) return true; return l_dhcp6_client_start(nc->dhcp6_client); @@ -1844,6 +1845,7 @@ static void netconfig_ifaddr_ipv6_added(struct l_netconfig *nc, { struct in6_addr in6; _auto_(l_free) char *ip = NULL; + bool new_lla; if ((ifa->ifa_flags & IFA_F_TENTATIVE) && !(ifa->ifa_flags & IFA_F_OPTIMISTIC)) @@ -1858,16 +1860,28 @@ static void netconfig_ifaddr_ipv6_added(struct l_netconfig *nc, if (!IN6_IS_ADDR_LINKLOCAL(&in6)) return; - netconfig_addr_wait_unregister(nc, true); + new_lla = !nc->have_lla; + nc->have_lla = true; + + if (!(ifa->ifa_flags & IFA_F_TENTATIVE)) + netconfig_addr_wait_unregister(nc, true); + else if (nc->ifaddr6_dump_cmd_id) { + struct l_netlink *rtnl = l_rtnl_get(); + unsigned int cmd_id = nc->ifaddr6_dump_cmd_id; + + nc->ifaddr6_dump_cmd_id = 0; + l_netlink_cancel(rtnl, cmd_id); + } l_dhcp6_client_set_link_local_address(nc->dhcp6_client, ip); - l_icmp6_client_set_link_local_address(nc->icmp6_client, ip); + l_icmp6_client_set_link_local_address(nc->icmp6_client, ip, + !!(ifa->ifa_flags & IFA_F_OPTIMISTIC)); /* * Only now that we have a link-local address see if we can start * actual DHCPv6 setup. */ - if (netconfig_check_start_dhcp6(nc)) + if (new_lla && netconfig_check_start_dhcp6(nc)) return; netconfig_emit_event(nc, AF_INET6, L_NETCONFIG_EVENT_FAILED); @@ -2022,6 +2036,13 @@ configure_ipv6: * before we start the dump, instead of after it ends, to eliminate * the possibility of missing an RTM_NEWADDR between the end of * the dump command and registering for the events. + * + * We stay on that list until we receive a non-tentative LL address. + * Note that we may set .have_lla earlier, specifically when we + * receive a tentative LL address that is also optimistic. We will + * however stay on addr_wait_list because we want to notify + * l_icmp6_client again when the LL address completes DAD and becomes + * non-tentative. */ if (!addr_wait_list) { addr_wait_list = l_queue_new(); @@ -2041,6 +2062,7 @@ configure_ipv6: goto unregister; l_queue_push_tail(addr_wait_list, netconfig); + netconfig->have_lla = false; if (!l_net_get_mac_address(netconfig->ifindex, netconfig->mac)) goto unregister; From patchwork Tue Sep 20 13:32:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 12982193 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (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 6B56B1C39 for ; Tue, 20 Sep 2022 13:32:11 +0000 (UTC) Received: by mail-wr1-f45.google.com with SMTP id t7so4267132wrm.10 for ; Tue, 20 Sep 2022 06:32:11 -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=NUmJw8AAv70r4A9N9K6OuV1PvZ5NQn1u6+ADzwrchUQ=; b=knJZUVb/rR3aPQ2xRN0KcEZrMpA++ie/dkQVJttIden2f/+8cwPdJuY8otbZRXc9+7 X1WdJt0etEKX/PyagV0MZGT6OWAoO+GEWmwfXVGJ6s7zJstVZVSb6dVS/abRicPIVIv1 bnwDqtV8D2cuCRqZf/NXpxrstZKjcKdTxKBVPe8lSFQqXe7cqveXwS2kyM0/vy1iTc4H y4Mh1izBiu2U++vTSWxgNsB9n8Zd0LZeDBf1CVOpNX/5AmRmzMLcRSaYBEaaE8wRDE4O GSfnCCRKRFcZ47a2Pf04CD5stgSO5qZnK2otcxTn/JbQ+EiLzfdoLgoBQ9faasHczV0t KESg== X-Gm-Message-State: ACrzQf2ga0Ypjqt4LXBV6zR+xrQfJwdQhukxufKg+tSc5nEJcowlr6Fq GtjVwRl8gVedfRVXF+NarQRIJQelIyXmmCi4 X-Google-Smtp-Source: AMsMyM5n8ErAumtqjyq4SYtN/0UM0qRQrRzTWWoUwGOejhYj0dxuZ/qd2p17O9J5lhiDhmvxr4+zgw== X-Received: by 2002:a05:6000:1d8f:b0:228:57f3:1f72 with SMTP id bk15-20020a0560001d8f00b0022857f31f72mr14415001wrb.276.1663680729494; Tue, 20 Sep 2022 06:32:09 -0700 (PDT) Received: from iss.ger.corp.intel.com ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id d16-20020adff2d0000000b0022863395912sm2082wrp.53.2022.09.20.06.32.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 06:32:08 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 6/6] netconfig: Handle missing optimistic_dad /proc file Date: Tue, 20 Sep 2022 15:32:01 +0200 Message-Id: <20220920133201.3303119-6-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220920133201.3303119-1-andrew.zaborowski@intel.com> References: <20220920133201.3303119-1-andrew.zaborowski@intel.com> Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Handle netconfig_proc_read_ipv6_uint_setting(..., "optimistic_dad") failures more cleanly in case CONFIG_IPV6_OPTIMISTIC_DAD has not been enabled in the kernel config. This commit makes no noticeable difference to the user. --- ell/netconfig.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ell/netconfig.c b/ell/netconfig.c index c558cad..fe5bf40 100644 --- a/ell/netconfig.c +++ b/ell/netconfig.c @@ -90,7 +90,7 @@ struct l_netconfig { struct l_queue *icmp_route_data; struct l_acd *acd; unsigned int orig_disable_ipv6; - unsigned int orig_optimistic_dad; + long orig_optimistic_dad; uint8_t mac[ETH_ALEN]; struct l_timeout *ra_timeout; bool have_lla; @@ -2010,7 +2010,8 @@ configure_ipv6: netconfig_proc_read_ipv6_uint_setting(netconfig, "optimistic_dad"); - if (!!netconfig->orig_optimistic_dad != optimistic_dad) + if (netconfig->orig_optimistic_dad >= 0 && + !!netconfig->orig_optimistic_dad != optimistic_dad) netconfig_proc_write_ipv6_uint_setting(netconfig, "optimistic_dad", optimistic_dad ? 1 : 0); @@ -2160,7 +2161,8 @@ LIB_EXPORT void l_netconfig_stop(struct l_netconfig *netconfig) optimistic_dad = netconfig->optimistic_dad_enabled && !netconfig->v6_static_addr; - if (!!netconfig->orig_optimistic_dad != optimistic_dad) + if (netconfig->orig_optimistic_dad >= 0 && + !!netconfig->orig_optimistic_dad != optimistic_dad) netconfig_proc_write_ipv6_uint_setting(netconfig, "optimistic_dad", netconfig->orig_optimistic_dad);