From patchwork Sat Dec 16 08:27:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13495522 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5A7D13FF3 for ; Sat, 16 Dec 2023 08:28:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id C7F4373100 for ; Sat, 16 Dec 2023 03:28:06 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:29e5:59c3:7c60:32d3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 8950A7312B for ; Sat, 16 Dec 2023 03:28:06 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 1/9] service: Refactor 'nameserver_del_routes'. Date: Sat, 16 Dec 2023 00:27:56 -0800 Message-ID: <20231216082805.2221938-2-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231216082805.2221938-1-gerickson@nuovations.com> References: <20231216082805.2221938-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This refactors 'nameserver_del_routes' into a second, helper function 'del_nameserver_route' such that host route deletion is separated from nameserver iteration. In addition, the structure now mirrors that of 'nameserver_add_routes' and 'add_nameserver_route'. This is beneficial since route addition and deletion should be symmetric. --- src/service.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/service.c b/src/service.c index 1f2c9f54db9a..54c12532e9ca 100644 --- a/src/service.c +++ b/src/service.c @@ -1367,6 +1367,27 @@ static void add_nameserver_route(int family, int index, char *nameserver, } } +static void del_nameserver_route(int family, int index, const char *nameserver, + const char *gw, + enum connman_ipconfig_type type) +{ + DBG("family %d index %d nameserver %s gw %s", + family, index, nameserver, gw); + + switch (family) { + case AF_INET: + if (type != CONNMAN_IPCONFIG_TYPE_IPV6) + connman_inet_del_host_route(index, + nameserver); + break; + case AF_INET6: + if (type != CONNMAN_IPCONFIG_TYPE_IPV4) + connman_inet_del_ipv6_host_route(index, + nameserver); + break; + } +} + static void nameserver_add_routes(int index, char **nameservers, const char *gw) { @@ -1388,25 +1409,15 @@ static void nameserver_add_routes(int index, char **nameservers, static void nameserver_del_routes(int index, char **nameservers, enum connman_ipconfig_type type) { - int i, family; + int i, ns_family; for (i = 0; nameservers[i]; i++) { - family = connman_inet_check_ipaddress(nameservers[i]); - if (family < 0) + ns_family = connman_inet_check_ipaddress(nameservers[i]); + if (ns_family < 0) continue; - switch (family) { - case AF_INET: - if (type != CONNMAN_IPCONFIG_TYPE_IPV6) - connman_inet_del_host_route(index, - nameservers[i]); - break; - case AF_INET6: - if (type != CONNMAN_IPCONFIG_TYPE_IPV4) - connman_inet_del_ipv6_host_route(index, - nameservers[i]); - break; - } + del_nameserver_route(ns_family, index, nameservers[i], + NULL, type); } } From patchwork Sat Dec 16 08:27:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13495523 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2499D13FF8 for ; Sat, 16 Dec 2023 08:28:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 306AF73122 for ; Sat, 16 Dec 2023 03:28:07 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:29e5:59c3:7c60:32d3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id E6FFC73145 for ; Sat, 16 Dec 2023 03:28:06 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 2/9] service: Add gateway parameter to DNS host route deletion paths. Date: Sat, 16 Dec 2023 00:27:57 -0800 Message-ID: <20231216082805.2221938-3-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231216082805.2221938-1-gerickson@nuovations.com> References: <20231216082805.2221938-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds a gateway address parameter to domain name service (DNS) server host route deletion paths. Routing table manipulation, host routes among them, should be fundamentally symmetric. The routing table entry parameters used to add a route should be identical to those used to delete the same route. The following interfaces were missing the gateway address parameter and now have it: * __connman_service_nameserver_del_routes * nameserver_del_routes to match: * __connman_service_nameserver_add_routes * nameserver_add_routes which had such a parameter. --- src/connman.h | 1 + src/gateway.c | 16 ++++++++++++---- src/service.c | 25 +++++++++++++++++-------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/connman.h b/src/connman.h index 90d5a34b8c58..622a778590b1 100644 --- a/src/connman.h +++ b/src/connman.h @@ -808,6 +808,7 @@ void __connman_service_nameserver_clear(struct connman_service *service); void __connman_service_nameserver_add_routes(const struct connman_service *service, const char *gw); void __connman_service_nameserver_del_routes(const struct connman_service *service, + const char *gw, enum connman_ipconfig_type type); void __connman_service_set_timeservers(struct connman_service *service, char **timeservers); diff --git a/src/gateway.c b/src/gateway.c index 61f3226a6771..b97abe0dd991 100644 --- a/src/gateway.c +++ b/src/gateway.c @@ -3765,10 +3765,6 @@ void __connman_gateway_remove(struct connman_service *service, else return; - /* Delete any routes associated with this service's nameservers. */ - - __connman_service_nameserver_del_routes(service, type); - /* * If there is no hash table / map entry for this service, then * there are no gateways associated with it; simply return. @@ -3779,6 +3775,18 @@ void __connman_gateway_remove(struct connman_service *service, GATEWAY_DATA_DBG("service_data", data); + /* Delete any routes associated with this service's nameservers. */ + + if (do_ipv4 && data->ipv4_config) + __connman_service_nameserver_del_routes(service, + data->ipv4_config->gateway, + type); + + if (do_ipv6 && data->ipv6_config) + __connman_service_nameserver_del_routes(service, + data->ipv6_config->gateway, + type); + if (do_ipv4 && data->ipv4_config) is_vpn4 = is_gateway_config_vpn(data->ipv4_config); diff --git a/src/service.c b/src/service.c index 54c12532e9ca..21b83e51e788 100644 --- a/src/service.c +++ b/src/service.c @@ -1407,22 +1407,28 @@ static void nameserver_add_routes(int index, char **nameservers, } static void nameserver_del_routes(int index, char **nameservers, + const char *gw, enum connman_ipconfig_type type) { - int i, ns_family; + int i, ns_family, gw_family; + + gw_family = connman_inet_check_ipaddress(gw); + if (gw_family < 0) + return; for (i = 0; nameservers[i]; i++) { ns_family = connman_inet_check_ipaddress(nameservers[i]); - if (ns_family < 0) + if (ns_family < 0 || ns_family != gw_family) continue; del_nameserver_route(ns_family, index, nameservers[i], - NULL, type); + gw, type); } } -void __connman_service_nameserver_add_routes(const struct connman_service *service, - const char *gw) +void __connman_service_nameserver_add_routes( + const struct connman_service *service, + const char *gw) { int index; @@ -1449,7 +1455,9 @@ void __connman_service_nameserver_add_routes(const struct connman_service *servi } } -void __connman_service_nameserver_del_routes(const struct connman_service *service, +void __connman_service_nameserver_del_routes( + const struct connman_service *service, + const char *gw, enum connman_ipconfig_type type) { int index; @@ -1461,9 +1469,9 @@ void __connman_service_nameserver_del_routes(const struct connman_service *servi if (service->nameservers_config) nameserver_del_routes(index, service->nameservers_config, - type); + gw, type); else if (service->nameservers) - nameserver_del_routes(index, service->nameservers, type); + nameserver_del_routes(index, service->nameservers, gw, type); } /** @@ -4483,6 +4491,7 @@ static DBusMessage *set_property(DBusConnection *conn, if (gw && strlen(gw)) __connman_service_nameserver_del_routes(service, + gw, CONNMAN_IPCONFIG_TYPE_ALL); dbus_message_iter_recurse(&value, &entry); From patchwork Sat Dec 16 08:27:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13495524 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 980AE14000 for ; Sat, 16 Dec 2023 08:28:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 8E9617312C for ; Sat, 16 Dec 2023 03:28:07 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:29e5:59c3:7c60:32d3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 5151173147 for ; Sat, 16 Dec 2023 03:28:07 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 3/9] inet: Add gateway parameter to 'connman_inet_del_{,ipv6_}host_route'. Date: Sat, 16 Dec 2023 00:27:58 -0800 Message-ID: <20231216082805.2221938-4-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231216082805.2221938-1-gerickson@nuovations.com> References: <20231216082805.2221938-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds a gateway address parameter to the 'connman_inet_del_{,ipv6_}host_route' functions. Routing table manipulation, host routes among them, should be fundamentally symmetric. The routing table entry parameters used to add a route should be identical to those used to delete the same route. Otherwise, an ESRCH error may occur which, at present, are suppressed due to commit e03a01d3182d ("inet: Fix error handling when adding/removing routes") that is masking route deletion errors where this gateway parameter asymmetry is occurring. In addition, call sites to 'connman_inet_del_{,ipv6_}host_route' are updated to pass the gateway parameter. --- include/inet.h | 17 ++++++++++++----- src/gateway.c | 17 +++++++++++------ src/inet.c | 40 +++++++++++++++++++++++++++++++++++----- src/service.c | 25 +++++++++++++++++++------ 4 files changed, 77 insertions(+), 22 deletions(-) diff --git a/include/inet.h b/include/inet.h index c7488165720c..5b2015eda76a 100644 --- a/include/inet.h +++ b/include/inet.h @@ -50,8 +50,12 @@ int connman_inet_del_host_route_with_metric(int index, const char *host, const char *gateway, uint32_t metric); -int connman_inet_add_host_route(int index, const char *host, const char *gateway); -int connman_inet_del_host_route(int index, const char *host); +int connman_inet_add_host_route(int index, + const char *host, + const char *gateway); +int connman_inet_del_host_route(int index, + const char *host, + const char *gateway); int connman_inet_add_network_route_with_metric(int index, const char *host, const char *gateway, @@ -82,9 +86,12 @@ int connman_inet_del_ipv6_host_route_with_metric(int index, const char *host, const char *gateway, uint32_t metric); -int connman_inet_add_ipv6_host_route(int index, const char *host, - const char *gateway); -int connman_inet_del_ipv6_host_route(int index, const char *host); +int connman_inet_add_ipv6_host_route(int index, + const char *host, + const char *gateway); +int connman_inet_del_ipv6_host_route(int index, + const char *host, + const char *gateway); int connman_inet_del_ipv6_network_route_with_metric(int index, const char *host, const char *gateway, diff --git a/src/gateway.c b/src/gateway.c index b97abe0dd991..29115250d243 100644 --- a/src/gateway.c +++ b/src/gateway.c @@ -401,9 +401,10 @@ struct gateway_config_ops { uint32_t metric); int (*add_host_route)(int index, - const char *gateway, - const char *host); + const char *host, + const char *gateway); int (*del_host_route)(int index, + const char *host, const char *gateway); }; @@ -1445,7 +1446,8 @@ static int del_gateway_routes(struct gateway_data *data, } else { data->ipv4_config->ops->del_host_route( data->index, - data->ipv4_config->gateway); + data->ipv4_config->gateway, + NULL); status4 = UNSET_DEFAULT_GATEWAY(data, type); @@ -1462,7 +1464,8 @@ static int del_gateway_routes(struct gateway_data *data, } else { data->ipv6_config->ops->del_host_route( data->index, - data->ipv6_config->gateway); + data->ipv6_config->gateway, + NULL); status6 = UNSET_DEFAULT_GATEWAY(data, type); @@ -3803,12 +3806,14 @@ void __connman_gateway_remove(struct connman_service *service, if (is_vpn4 && data->index >= 0) data->ipv4_config->ops->del_host_route( data->ipv4_config->vpn_phy_index, - data->ipv4_config->gateway); + data->ipv4_config->gateway, + NULL); if (is_vpn6 && data->index >= 0) data->ipv6_config->ops->del_host_route( data->ipv6_config->vpn_phy_index, - data->ipv6_config->gateway); + data->ipv6_config->gateway, + NULL); /* Remove all active routes associated with this gateway data. */ diff --git a/src/inet.c b/src/inet.c index 371b3328175f..55684dc2fd65 100644 --- a/src/inet.c +++ b/src/inet.c @@ -1545,14 +1545,29 @@ int connman_inet_del_network_route_with_metric(int index, metric); } -int connman_inet_add_host_route(int index, const char *host, +int connman_inet_add_host_route(int index, + const char *host, const char *gateway) { return connman_inet_add_network_route(index, host, gateway, NULL); } -int connman_inet_del_host_route(int index, const char *host) +int connman_inet_del_host_route(int index, + const char *host, + const char *gateway) { + /* + * NOTE: The 'connman_inet_del_network_route' is deficient in that + * it is missing the requisite 'gateway' parameter making it + * symmetric with 'connman_inet_add_host_route' and + * 'connman_inet_add_network_route'. Consequently, host route + * deletion may fail. + * + * This, 'connman_inet_add_host_route', and + * 'connman_inet_del_network_route' should probably be migrated to + * the same RTNL-based call stack as + * 'connman_inet_del_host_route_with_metric'. + */ return connman_inet_del_network_route(index, host); } @@ -1936,14 +1951,29 @@ int connman_inet_del_ipv6_network_route_with_metric(int index, metric); } -int connman_inet_add_ipv6_host_route(int index, const char *host, - const char *gateway) +int connman_inet_add_ipv6_host_route(int index, + const char *host, + const char *gateway) { return connman_inet_add_ipv6_network_route(index, host, gateway, 128); } -int connman_inet_del_ipv6_host_route(int index, const char *host) +int connman_inet_del_ipv6_host_route(int index, + const char *host, + const char *gateway) { + /* + * NOTE: The 'connman_inet_del_ipv6_network_route' is deficient in + * that it is missing the requisite 'gateway' parameter making it + * symmetric with 'connman_inet_add_ipv6_host_route' and + * 'connman_inet_add_ipv6_network_route'. Consequently, host route + * deletion may fail. + * + * This, 'connman_inet_add_ipv6_host_route', and + * 'connman_inet_del_ipv6_network_route' should probably be + * migrated to the same RTNL-based call stack as + * 'connman_inet_del_ipv6_host_route_with_metric'. + */ return connman_inet_del_ipv6_network_route(index, host, 128); } diff --git a/src/service.c b/src/service.c index 21b83e51e788..1f227a2e0125 100644 --- a/src/service.c +++ b/src/service.c @@ -1376,14 +1376,27 @@ static void del_nameserver_route(int family, int index, const char *nameserver, switch (family) { case AF_INET: - if (type != CONNMAN_IPCONFIG_TYPE_IPV6) - connman_inet_del_host_route(index, - nameserver); + if (type != CONNMAN_IPCONFIG_TYPE_IPV4 && + type != CONNMAN_IPCONFIG_TYPE_ALL) + break; + + if (connman_inet_compare_subnet(index, nameserver)) + break; + + if (connman_inet_del_host_route(index, nameserver, gw) < 0) + /* For P-t-P link the above route del will fail */ + connman_inet_del_host_route(index, nameserver, NULL); break; + case AF_INET6: - if (type != CONNMAN_IPCONFIG_TYPE_IPV4) - connman_inet_del_ipv6_host_route(index, - nameserver); + if (type != CONNMAN_IPCONFIG_TYPE_IPV6 && + type != CONNMAN_IPCONFIG_TYPE_ALL) + break; + + if (connman_inet_del_ipv6_host_route(index, nameserver, + gw) < 0) + connman_inet_del_ipv6_host_route(index, nameserver, + NULL); break; } } From patchwork Sat Dec 16 08:27:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13495525 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F083C14001 for ; Sat, 16 Dec 2023 08:28:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id EEE927311A for ; Sat, 16 Dec 2023 03:28:07 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:29e5:59c3:7c60:32d3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id B05B273144 for ; Sat, 16 Dec 2023 03:28:07 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 4/9] inet: Document 'connman_inet_{add,del}_{,ipv6_}host_route'. Date: Sat, 16 Dec 2023 00:27:59 -0800 Message-ID: <20231216082805.2221938-5-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231216082805.2221938-1-gerickson@nuovations.com> References: <20231216082805.2221938-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds documentation to the 'connman_inet_{add,del}_{,ipv6_}host_route' functions. --- src/inet.c | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/src/inet.c b/src/inet.c index 55684dc2fd65..e0f927a12dcb 100644 --- a/src/inet.c +++ b/src/inet.c @@ -1545,6 +1545,42 @@ int connman_inet_del_network_route_with_metric(int index, metric); } +/** + * @brief + * Add an IPv4 host route. + * + * This attempts to add an IPv4 host route to the kernel with the + * specified attributes. + * + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] host A pointer to an immutable null- + * terminated C string containing the + * IPv4 address, in text form, of the + * route host destination address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv4 address, in text form, of + * the route next hop gateway address. + * + * @retval 0 If successful. + * @retval -EINVAL If @a host is null; if @a index is invalid; if + * @a host or @a gateway, if present, do not + * contain a character string representing a valid + * network address in the AF_INET family; or if the + * routing information to be added was invalid. + * @retval -EFAULT If the address to the routing information to be + * added was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to add routes. + * @retval -EEXIST A request was made to add an existing routing + * entry. + * + * @sa connman_inet_del_host_route + * @sa connman_inet_add_ipv6_host_route + * + */ int connman_inet_add_host_route(int index, const char *host, const char *gateway) @@ -1552,6 +1588,42 @@ int connman_inet_add_host_route(int index, return connman_inet_add_network_route(index, host, gateway, NULL); } +/** + * @brief + * Delete an IPv4 host route. + * + * This attempts to delete an IPv4 host route to the kernel with the + * specified attributes. + * + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] host A pointer to an immutable null- + * terminated C string containing the + * IPv4 address, in text form, of the + * route host destination address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv4 address, in text form, of + * the route next hop gateway address. + * + * @retval 0 If successful. + * @retval -EINVAL If @a host is null; if @a index is invalid; if + * @a host or @a gateway, if present, do not + * contain a character string representing a valid + * network address in the AF_INET family; or if the + * routing information to be deleted was invalid. + * @retval -EFAULT If the address to the routing information to be + * deleted was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to delete routes. + * @retval -ESRCH A request was made to delete a non-existing + * routing entry. + * + * @sa connman_inet_add_host_route + * @sa connman_inet_del_ipv6_host_route + * + */ int connman_inet_del_host_route(int index, const char *host, const char *gateway) @@ -1951,6 +2023,42 @@ int connman_inet_del_ipv6_network_route_with_metric(int index, metric); } +/** + * @brief + * Add an IPv6 host route. + * + * This attempts to add an IPv6 host route to the kernel with the + * specified attributes. + * + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] host A pointer to an immutable null- + * terminated C string containing the + * IPv6 address, in text form, of the + * route host destination address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv6 address, in text form, of + * the route next hop gateway address. + * + * @retval 0 If successful. + * @retval -EINVAL If @a host is null; if @a index is invalid; if + * @a host or @a gateway, if present, do not + * contain a character string representing a valid + * network address in the AF_INET family; or if the + * routing information to be added was invalid. + * @retval -EFAULT If the address to the routing information to be + * added was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to add routes. + * @retval -EEXIST A request was made to add an existing routing + * entry. + * + * @sa connman_inet_add_host_route + * @sa connman_inet_del_ipv6_host_route + * + */ int connman_inet_add_ipv6_host_route(int index, const char *host, const char *gateway) @@ -1958,6 +2066,42 @@ int connman_inet_add_ipv6_host_route(int index, return connman_inet_add_ipv6_network_route(index, host, gateway, 128); } +/** + * @brief + * Delete an IPv6 host route. + * + * This attempts to delete an IPv6 host route to the kernel with the + * specified attributes. + * + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] host A pointer to an immutable null- + * terminated C string containing the + * IPv6 address, in text form, of the + * route host destination address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv6 address, in text form, of + * the route next hop gateway address. + * + * @retval 0 If successful. + * @retval -EINVAL If @a host is null; if @a index is invalid; if + * @a host or @a gateway, if present, do not + * contain a character string representing a valid + * network address in the AF_INET family; or if the + * routing information to be deleted was invalid. + * @retval -EFAULT If the address to the routing information to be + * deleted was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to delete routes. + * @retval -ESRCH A request was made to delete a non-existing + * routing entry. + * + * @sa connman_inet_add_ipv6_host_route + * @sa connman_inet_del_host_route + * + */ int connman_inet_del_ipv6_host_route(int index, const char *host, const char *gateway) From patchwork Sat Dec 16 08:28:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13495526 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAE5213FF8 for ; Sat, 16 Dec 2023 08:28:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 6367273128 for ; Sat, 16 Dec 2023 03:28:08 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:29e5:59c3:7c60:32d3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 1B8BA73146 for ; Sat, 16 Dec 2023 03:28:08 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 5/9] service: Const-qualify 'add_nameserver_route'. Date: Sat, 16 Dec 2023 00:28:00 -0800 Message-ID: <20231216082805.2221938-6-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231216082805.2221938-1-gerickson@nuovations.com> References: <20231216082805.2221938-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 Const-qualify the nameserver argument of 'add_nameserver_route' to make it clear to the compiler, static analyzers, and human readers that the function is strictly a getter with no nameserver argument mutation side effects. --- src/service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service.c b/src/service.c index 1f227a2e0125..55eb4d8d757d 100644 --- a/src/service.c +++ b/src/service.c @@ -1345,7 +1345,7 @@ void __connman_service_nameserver_clear(struct connman_service *service) nameserver_add_all(service, CONNMAN_IPCONFIG_TYPE_ALL); } -static void add_nameserver_route(int family, int index, char *nameserver, +static void add_nameserver_route(int family, int index, const char *nameserver, const char *gw) { switch (family) { From patchwork Sat Dec 16 08:28:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13495530 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAE891400F for ; Sat, 16 Dec 2023 08:28:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id CCDF47312B for ; Sat, 16 Dec 2023 03:28:08 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:29e5:59c3:7c60:32d3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 8432A7314B for ; Sat, 16 Dec 2023 03:28:08 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 6/9] service: Add 'DBG' to 'add_nameserver_route'. Date: Sat, 16 Dec 2023 00:28:01 -0800 Message-ID: <20231216082805.2221938-7-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231216082805.2221938-1-gerickson@nuovations.com> References: <20231216082805.2221938-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds a 'DBG' statement to 'add_nameserver_route' to match that in 'del_nameserver_route'. --- src/service.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/service.c b/src/service.c index 55eb4d8d757d..e0a11a2bc6a2 100644 --- a/src/service.c +++ b/src/service.c @@ -1348,6 +1348,9 @@ void __connman_service_nameserver_clear(struct connman_service *service) static void add_nameserver_route(int family, int index, const char *nameserver, const char *gw) { + DBG("family %d index %d nameserver %s gw %s", + family, index, nameserver, gw); + switch (family) { case AF_INET: if (connman_inet_compare_subnet(index, nameserver)) From patchwork Sat Dec 16 08:28:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13495527 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 912FD13FF3 for ; Sat, 16 Dec 2023 08:28:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 3703473144 for ; Sat, 16 Dec 2023 03:28:09 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:29e5:59c3:7c60:32d3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id ED9607314E for ; Sat, 16 Dec 2023 03:28:08 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 7/9] inet: Document '{add,del}_nameserver_route'. Date: Sat, 16 Dec 2023 00:28:02 -0800 Message-ID: <20231216082805.2221938-8-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231216082805.2221938-1-gerickson@nuovations.com> References: <20231216082805.2221938-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds documentation to the '{add,del}_nameserver_route' functions. --- src/service.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/service.c b/src/service.c index e0a11a2bc6a2..8821445f32e7 100644 --- a/src/service.c +++ b/src/service.c @@ -1345,6 +1345,32 @@ void __connman_service_nameserver_clear(struct connman_service *service) nameserver_add_all(service, CONNMAN_IPCONFIG_TYPE_ALL); } +/** + * @brief + * Add an IPv4 or IPv6 host route for the specified domain name + * service (DNS) server. + * + * This attempts to add an IPv4 or IPv6 host route for the specified + * domain name service (DNS) server with the specified attributes. + * + * @param[in] family The address family describing the + * address pointed to by @a nameserver. + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] nameserver A pointer to an immutable null-terminated + * C string containing the IPv4 or IPv6 + * address, in text form, of the route + * DNS server destination address. + * @param[in] gw A pointer to an immutable null-terminated + * C string containing the IPv4 or IPv6 + * address, in text form, of the route next + * hop gateway address. + * + * @sa del_nameserver_route + * @sa nameserver_add_routes + * + */ static void add_nameserver_route(int family, int index, const char *nameserver, const char *gw) { @@ -1370,6 +1396,33 @@ static void add_nameserver_route(int family, int index, const char *nameserver, } } +/** + * @brief + * Delete an IPv4 or IPv6 host route for the specified domain name + * service (DNS) server. + * + * This attempts to delete an IPv4 or IPv6 host route for the + * specified domain name service (DNS) server with the specified + * attributes. + * + * @param[in] family The address family describing the + * address pointed to by @a nameserver. + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] nameserver A pointer to an immutable null-terminated + * C string containing the IPv4 or IPv6 + * address, in text form, of the route + * DNS server destination address. + * @param[in] gw A pointer to an immutable null-terminated + * C string containing the IPv4 or IPv6 + * address, in text form, of the route next + * hop gateway address. + * + * @sa add_nameserver_route + * @sa nameserver_del_routes + * + */ static void del_nameserver_route(int family, int index, const char *nameserver, const char *gw, enum connman_ipconfig_type type) From patchwork Sat Dec 16 08:28:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13495528 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEAED14016 for ; Sat, 16 Dec 2023 08:28:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 9579073146 for ; Sat, 16 Dec 2023 03:28:09 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:29e5:59c3:7c60:32d3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 57B0C73154 for ; Sat, 16 Dec 2023 03:28:09 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 8/9] inet: Document 'nameserver_{add,del}_routes'. Date: Sat, 16 Dec 2023 00:28:03 -0800 Message-ID: <20231216082805.2221938-9-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231216082805.2221938-1-gerickson@nuovations.com> References: <20231216082805.2221938-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds documentation to the 'nameserver_{add,del}_routes' functions. --- src/service.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/service.c b/src/service.c index 8821445f32e7..7e14a3dbf496 100644 --- a/src/service.c +++ b/src/service.c @@ -1457,6 +1457,31 @@ static void del_nameserver_route(int family, int index, const char *nameserver, } } +/** + * @brief + * Add IPv4 or IPv6 host routes for the specified domain name + * service (DNS) servers. + * + * This attempts to add IPv4 or IPv6 host routes for the specified + * domain name service (DNS) servers with the specified attributes. + * + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] nameservers A pointer to a null-terminated array of + * mutable null-terminated C strings + * containing the IPv4 or IPv6 addresses, in + * text form, of the route DNS server + * destination addresses. + * @param[in] gw A pointer to an immutable null-terminated + * C string containing the IPv4 or IPv6 + * address, in text form, of the route next + * hop gateway address. + * + * @sa add_nameserver_route + * @sa nameserver_del_routes + * + */ static void nameserver_add_routes(int index, char **nameservers, const char *gw) { @@ -1475,6 +1500,31 @@ static void nameserver_add_routes(int index, char **nameservers, } } +/** + * @brief + * Delete IPv4 or IPv6 host routes for the specified domain name + * service (DNS) servers. + * + * This attempts to delete IPv4 or IPv6 host routes for the specified + * domain name service (DNS) servers with the specified attributes. + * + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] nameservers A pointer to a null-terminated array of + * mutable null-terminated C strings + * containing the IPv4 or IPv6 addresses, in + * text form, of the route DNS server + * destination addresses. + * @param[in] gw A pointer to an immutable null-terminated + * C string containing the IPv4 or IPv6 + * address, in text form, of the route next + * hop gateway address. + * + * @sa del_nameserver_route + * @sa nameserver_add_routes + * + */ static void nameserver_del_routes(int index, char **nameservers, const char *gw, enum connman_ipconfig_type type) From patchwork Sat Dec 16 08:28:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13495529 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5371E14018 for ; Sat, 16 Dec 2023 08:28:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 002C273145 for ; Sat, 16 Dec 2023 03:28:10 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:29e5:59c3:7c60:32d3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id B61E87315A for ; Sat, 16 Dec 2023 03:28:09 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 9/9] inet: Document '__connman_service_nameserver_{add,del}_routes'. Date: Sat, 16 Dec 2023 00:28:04 -0800 Message-ID: <20231216082805.2221938-10-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231216082805.2221938-1-gerickson@nuovations.com> References: <20231216082805.2221938-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds documentation to the '__connman_service_nameserver_{add,del}_routes' functions. --- src/service.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/service.c b/src/service.c index 7e14a3dbf496..b8224e8ff0bc 100644 --- a/src/service.c +++ b/src/service.c @@ -1545,6 +1545,27 @@ static void nameserver_del_routes(int index, char **nameservers, } } +/** + * @brief + * Add IPv4 or IPv6 host routes for the domain name service (DNS) + * servers associated with the specified service. + * + * This attempts to add IPv4 or IPv6 host routes for both the + * automatic and configured domain name service (DNS) servers + * associated with the specified network service. + * + * @param[in] service A pointer to the immutable network + * service for which to add DNS server host + * routes. + * @param[in] gw A pointer to an immutable null-terminated + * C string containing the IPv4 or IPv6 + * address, in text form, of the route next + * hop gateway address. + * + * @sa __connman_service_nameserver_del_routes + * @sa nameserver_add_routes + * + */ void __connman_service_nameserver_add_routes( const struct connman_service *service, const char *gw) @@ -1574,6 +1595,29 @@ void __connman_service_nameserver_add_routes( } } +/** + * @brief + * Delete IPv4 or IPv6 host routes for the domain name service (DNS) + * servers associated with the specified service. + * + * This attempts to delete IPv4 or IPv6 host routes for both the + * automatic and configured domain name service (DNS) servers + * associated with the specified network service. + * + * @param[in] service A pointer to the immutable network + * service for which to delete DNS server + * host routes. + * @param[in] gw A pointer to an immutable null-terminated + * C string containing the IPv4 or IPv6 + * address, in text form, of the route next + * hop gateway address. + * @param[in] type The IP configuration type for which to + * delete DNS server host routes. + * + * @sa __connman_service_nameserver_del_routes + * @sa nameserver_add_routes + * + */ void __connman_service_nameserver_del_routes( const struct connman_service *service, const char *gw,