From patchwork Mon Aug 15 18:26: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: 12943943 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.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 DA95C4C82 for ; Mon, 15 Aug 2022 18:26:10 +0000 (UTC) Received: by mail-wr1-f43.google.com with SMTP id e27so5276418wra.11 for ; Mon, 15 Aug 2022 11:26: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:message-id:date:subject:to :from:x-gm-message-state:from:to:cc; bh=fgVeknC3GYUxHbPxCrFv+ZVcNYkRwkYN4G/61+IIZ/I=; b=xtJ9gJADOUxZLzjwguRhU565j14hUSy7JpWnSaeZWnrMz2uK1SUz2PXfOQG/iRVEtn iYQ+hD9RARfsQJdjH3LhB34LDQ8/wAG/OOkYOFNefPFvZ5SoEsSAx6yJKGelYK4SC4LC skaSnzbq9CjAyEsWgl8AYhJN2YtIuO+1YFVUKm6JyOIGTzqZ+iD0ih08BAwtyfEEYWBH hYy/f9JveG41mNORJOfGe7dtMyT4PSHO4M8VQGiZdod9vAZeoqqROXMGGmGEBxMd72wk S0tNJL+ktEKNcns9geKnkdwZ33/WoBWJHtCKfQvl7L9qThB+Bl4QWjSKSS3Zr6ehB9pP DtIQ== X-Gm-Message-State: ACgBeo2E54cJdKSZ49eFDCTj628/nlsta0XrlbrRqswpA2MCFowPFXUy ZJdmCJO4asZWLG92ptnQOA/D+M1kNdI= X-Google-Smtp-Source: AA6agR6CkoCvbXqkVvT28S+cqnfcpfMCi3bINisy6qC//rJt1AeYLw7ff7vbPEr8DThwPFXjyAXbGQ== X-Received: by 2002:a5d:60c5:0:b0:220:6780:2701 with SMTP id x5-20020a5d60c5000000b0022067802701mr9959943wrt.450.1660587968748; Mon, 15 Aug 2022 11:26:08 -0700 (PDT) Received: from iss.ger.corp.intel.com ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id r18-20020a05600c35d200b003a2e92edeccsm10733101wmq.46.2022.08.15.11.26.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 11:26:08 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 1/2] netconfig: API to disable/enable ACD Date: Mon, 15 Aug 2022 20:26:01 +0200 Message-Id: <20220815182602.1146368-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 When using FILS IP Assignment, the received configuration will be passed to l_netconfig as "static", yet we may want to skip ACD to avoid the overhead. --- ell/ell.sym | 1 + ell/netconfig.c | 40 ++++++++++++++++++++++++++++------------ ell/netconfig.h | 1 + 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/ell/ell.sym b/ell/ell.sym index 8f4e59d..81cec64 100644 --- a/ell/ell.sym +++ b/ell/ell.sym @@ -747,6 +747,7 @@ global: l_netconfig_set_gateway_override; l_netconfig_set_dns_override; l_netconfig_set_domain_names_override; + l_netconfig_set_acd_enabled; l_netconfig_check_config; l_netconfig_reset_config; l_netconfig_start; diff --git a/ell/netconfig.c b/ell/netconfig.c index 28afa9b..8f87e64 100644 --- a/ell/netconfig.c +++ b/ell/netconfig.c @@ -67,6 +67,7 @@ struct l_netconfig { char *v4_gateway_override; char **v4_dns_override; char **v4_domain_names_override; + bool acd_enabled; bool v6_enabled; struct l_rtnl_address *v6_static_addr; @@ -1031,7 +1032,6 @@ LIB_EXPORT struct l_netconfig *l_netconfig_new(uint32_t ifindex) nc = l_new(struct l_netconfig, 1); nc->ifindex = ifindex; - nc->v4_enabled = true; nc->addresses.current = l_queue_new(); nc->addresses.added = l_queue_new(); @@ -1061,6 +1061,7 @@ LIB_EXPORT struct l_netconfig *l_netconfig_new(uint32_t ifindex) /* Disable in-kernel autoconfiguration for the interface */ netconfig_proc_write_ipv6_uint_setting(nc, "accept_ra", 0); + l_netconfig_reset_config(nc); return nc; } @@ -1275,6 +1276,16 @@ LIB_EXPORT bool l_netconfig_set_domain_names_override( return true; } +LIB_EXPORT bool l_netconfig_set_acd_enabled(struct l_netconfig *netconfig, + bool enabled) +{ + if (unlikely(!netconfig || netconfig->started)) + return false; + + netconfig->acd_enabled = enabled; + return true; +} + static bool netconfig_check_family_config(struct l_netconfig *nc, uint8_t family) { @@ -1343,6 +1354,7 @@ LIB_EXPORT bool l_netconfig_reset_config(struct l_netconfig *netconfig) l_netconfig_set_gateway_override(netconfig, AF_INET, NULL); l_netconfig_set_dns_override(netconfig, AF_INET, NULL); l_netconfig_set_domain_names_override(netconfig, AF_INET, NULL); + l_netconfig_set_acd_enabled(netconfig, true); l_netconfig_set_family_enabled(netconfig, AF_INET6, false); l_netconfig_set_static_addr(netconfig, AF_INET6, NULL); l_netconfig_set_gateway_override(netconfig, AF_INET6, NULL); @@ -1434,25 +1446,29 @@ static void netconfig_do_static_config(struct l_idle *idle, void *user_data) l_idle_remove(l_steal_ptr(nc->do_static_work)); if (nc->v4_static_addr && !nc->v4_configured) { - char ip[INET_ADDRSTRLEN]; + if (nc->acd_enabled) { + char ip[INET_ADDRSTRLEN]; - l_rtnl_address_get_address(nc->v4_static_addr, ip); + l_rtnl_address_get_address(nc->v4_static_addr, ip); - nc->acd = l_acd_new(nc->ifindex); - l_acd_set_event_handler(nc->acd, netconfig_ipv4_acd_event, nc, - NULL); + nc->acd = l_acd_new(nc->ifindex); + l_acd_set_event_handler(nc->acd, + netconfig_ipv4_acd_event, nc, + NULL); - if (!l_acd_start(nc->acd, ip)) { - l_acd_destroy(l_steal_ptr(nc->acd)); + if (l_acd_start(nc->acd, ip)) + goto configure_ipv6; + l_acd_destroy(l_steal_ptr(nc->acd)); /* Configure right now as a fallback */ - netconfig_add_v4_static_address_routes(nc); - nc->v4_configured = true; - netconfig_emit_event(nc, AF_INET, - L_NETCONFIG_EVENT_CONFIGURE); } + + netconfig_add_v4_static_address_routes(nc); + nc->v4_configured = true; + netconfig_emit_event(nc, AF_INET, L_NETCONFIG_EVENT_CONFIGURE); } +configure_ipv6: if (nc->v6_static_addr && !nc->v6_configured) { netconfig_add_v6_static_address_routes(nc); nc->v6_configured = true; diff --git a/ell/netconfig.h b/ell/netconfig.h index ac467b6..7710d83 100644 --- a/ell/netconfig.h +++ b/ell/netconfig.h @@ -68,6 +68,7 @@ bool l_netconfig_set_dns_override(struct l_netconfig *netconfig, uint8_t family, char **dns_list); bool l_netconfig_set_domain_names_override(struct l_netconfig *netconfig, uint8_t family, char **names); +bool l_netconfig_set_acd_enabled(struct l_netconfig *netconfig, bool enabled); bool l_netconfig_check_config(struct l_netconfig *netconfig); bool l_netconfig_reset_config(struct l_netconfig *netconfig); From patchwork Mon Aug 15 18:26:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 12943944 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 B19C44C8A for ; Mon, 15 Aug 2022 18:26:11 +0000 (UTC) Received: by mail-wr1-f53.google.com with SMTP id b4so6870464wrn.4 for ; Mon, 15 Aug 2022 11:26: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; bh=R5J7ThmxcZRPBUYyjivgcfCLae7YSIKnwl3DSzTOPMQ=; b=hTcHoJHwYvg1JWcYaMDyAzs1zjSWHLgYZFhZwJyrOXSMyO11oxfnVcSaqwNrfYd3hh wbu5VH1DYzzqE11FI/Q5VcRZU0l+DrWfbyYmycqCYJTXZfAYCW9ZEwtVS8OmFLFLQkAm NPCBFDWKfiHgVT2A6dHMA/MGkyvtR/tQ3qxuhlGlR58syJ31+5MsRyYoUMXPctM7Otwp lWmMPvjF4mZBfK1+SFOWyUjRCRx9aSMin+bML/u5nEXpeWIByLyXjHOnl2GM5yXVcQX5 5DL4p5/P0u7Ce7fP3oJ6STrXGxsZvVkQqH2Xf5Aip7DLiprQTO3Fq6eVMIK10hAzwzAW PNyA== X-Gm-Message-State: ACgBeo2MU5lIrLN7l4a5D0THretbmalL272+LzmbWLw/BWirB7pWGImU 2bca2sfNXBJQiS+JcxYwaQPno5zaPaY= X-Google-Smtp-Source: AA6agR4fT/SImAMkE0iAIyyos89i3e882FR7lyOIXAN6zdoLsXyyl8v4WwxDXfmSOCJEWlkk4XP2AQ== X-Received: by 2002:adf:fe81:0:b0:21b:88ea:6981 with SMTP id l1-20020adffe81000000b0021b88ea6981mr10024900wrr.616.1660587969564; Mon, 15 Aug 2022 11:26:09 -0700 (PDT) Received: from iss.ger.corp.intel.com ([82.213.228.103]) by smtp.gmail.com with ESMTPSA id r18-20020a05600c35d200b003a2e92edeccsm10733101wmq.46.2022.08.15.11.26.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 11:26:09 -0700 (PDT) From: Andrew Zaborowski To: ell@lists.linux.dev Subject: [PATCH 2/2] netconfig: Add l_netconfig_unconfigure Date: Mon, 15 Aug 2022 20:26:02 +0200 Message-Id: <20220815182602.1146368-2-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220815182602.1146368-1-andrew.zaborowski@intel.com> References: <20220815182602.1146368-1-andrew.zaborowski@intel.com> Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add method to trigger an UNCONFIGURE event with all routes and addresses removed, if there were any. Make sure l_netconfig_get_dns_list() and l_netconfig_get_domain_names() return empty too. --- ell/ell.sym | 1 + ell/netconfig.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ ell/netconfig.h | 1 + 3 files changed, 67 insertions(+) diff --git a/ell/ell.sym b/ell/ell.sym index 81cec64..0dcf8f8 100644 --- a/ell/ell.sym +++ b/ell/ell.sym @@ -752,6 +752,7 @@ global: l_netconfig_reset_config; l_netconfig_start; l_netconfig_stop; + l_netconfig_unconfigure; l_netconfig_get_dhcp_client; l_netconfig_get_dhcp6_client; l_netconfig_get_icmp6_client; diff --git a/ell/netconfig.c b/ell/netconfig.c index 8f87e64..29e95b7 100644 --- a/ell/netconfig.c +++ b/ell/netconfig.c @@ -1747,6 +1747,55 @@ LIB_EXPORT void l_netconfig_stop(struct l_netconfig *netconfig) } } +/* + * Undo any configuration already applied to the interface by previous + * calls to the event handler, by synchronously emitting + * L_NETCONFIG_EVENT_UNCONFIGURE events. This can be called before + * l_netconfig_stop() which won't emit any events. It mainly makes + * sense if the interface isn't being removed or brought DOWN, which + * would otherwise implicitly remove routes and addresses. + */ +LIB_EXPORT void l_netconfig_unconfigure(struct l_netconfig *netconfig) +{ + const struct l_queue_entry *entry; + + if (netconfig->v4_configured) { + netconfig_remove_v4_address_routes(netconfig, false); + netconfig->v4_configured = false; + + netconfig_emit_event(netconfig, AF_INET, + L_NETCONFIG_EVENT_UNCONFIGURE); + } + + if (netconfig->v6_configured) { + netconfig_remove_dhcp6_address(netconfig, false); + netconfig->v6_configured = false; + } + + /* Bulk remove any other routes or addresses */ + for (entry = l_queue_get_entries(netconfig->addresses.current); entry; + entry = entry->next) + l_queue_push_tail(netconfig->addresses.removed, entry->data); + + l_queue_clear(netconfig->addresses.added, NULL); + l_queue_clear(netconfig->addresses.updated, NULL); + l_queue_clear(netconfig->addresses.current, NULL); + + for (entry = l_queue_get_entries(netconfig->routes.current); entry; + entry = entry->next) + l_queue_push_tail(netconfig->routes.removed, entry->data); + + l_queue_clear(netconfig->routes.added, NULL); + l_queue_clear(netconfig->routes.updated, NULL); + l_queue_clear(netconfig->routes.current, NULL); + l_queue_clear(netconfig->icmp_route_data, l_free); + + if (!l_queue_isempty(netconfig->addresses.removed) || + !l_queue_isempty(netconfig->routes.removed)) + netconfig_emit_event(netconfig, AF_INET6, + L_NETCONFIG_EVENT_UNCONFIGURE); +} + LIB_EXPORT struct l_dhcp_client *l_netconfig_get_dhcp_client( struct l_netconfig *netconfig) { @@ -1903,18 +1952,26 @@ LIB_EXPORT char **l_netconfig_get_dns_list(struct l_netconfig *netconfig) const struct l_dhcp_lease *v4_lease; const struct l_dhcp6_lease *v6_lease; + if (!netconfig->v4_configured) + goto append_v6; + if (netconfig->v4_dns_override) netconfig_strv_cat(&ret, netconfig->v4_dns_override, false); else if ((v4_lease = l_dhcp_client_get_lease(netconfig->dhcp_client))) netconfig_strv_cat(&ret, l_dhcp_lease_get_dns(v4_lease), true); +append_v6: + if (!netconfig->v6_configured) + goto done; + 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))) netconfig_strv_cat(&ret, l_dhcp6_lease_get_dns(v6_lease), true); +done: return ret; } @@ -1926,6 +1983,9 @@ LIB_EXPORT char **l_netconfig_get_domain_names(struct l_netconfig *netconfig) const struct l_dhcp6_lease *v6_lease; char *dn; + if (!netconfig->v4_configured) + goto append_v6; + if (netconfig->v4_domain_names_override) netconfig_strv_cat(&ret, netconfig->v4_domain_names_override, false); @@ -1936,6 +1996,10 @@ LIB_EXPORT char **l_netconfig_get_domain_names(struct l_netconfig *netconfig) ret[0] = dn; } +append_v6: + if (!netconfig->v6_configured) + goto done; + if (netconfig->v6_dns_override) netconfig_strv_cat(&ret, netconfig->v6_domain_names_override, false); @@ -1944,5 +2008,6 @@ LIB_EXPORT char **l_netconfig_get_domain_names(struct l_netconfig *netconfig) netconfig_strv_cat(&ret, l_dhcp6_lease_get_domains(v6_lease), true); +done: return ret; } diff --git a/ell/netconfig.h b/ell/netconfig.h index 7710d83..fb3c536 100644 --- a/ell/netconfig.h +++ b/ell/netconfig.h @@ -74,6 +74,7 @@ bool l_netconfig_reset_config(struct l_netconfig *netconfig); bool l_netconfig_start(struct l_netconfig *netconfig); void l_netconfig_stop(struct l_netconfig *netconfig); +void l_netconfig_unconfigure(struct l_netconfig *netconfig); struct l_dhcp_client *l_netconfig_get_dhcp_client( struct l_netconfig *netconfig);