Skip to contentSkip to conversation

inet: Add Missing Gateway Parameter to Host Route Deletion Interfaces

PATCH In review Grant Erickson 2 participants 11 messages Dec 16, 2023

lore
Share & tools
lore
#0 lore raw

cover inet: Add Missing Gateway Parameter to Host Route Deletion Interfaces

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.

This adds a previously-missing gateway address parameter to the 'connman_inet_del_{,ipv6_}host_route' functions. In addition, call sites to 'connman_inet_del_{,ipv6_}host_route' are updated to pass the gateway parameter.

In addition, in the process, this refactors 'nameserver_del_routes' into a second, helper function 'del_nameserver_route' such that host route deletion is separated from DNS server iteration. This structure now mirrors that of 'nameserver_add_routes' and 'add_nameserver_route' since, again, route addition and deletion should be symmetric.

NOTE: This is only the first half of the necessary change. The second half is revising the actual implementation of 'connman_inet_del_{,ipv6_}host_route' to take advantage of the newly-added gateway parameter. Implementation notes in each of 'connman_inet_del_{,ipv6_}host_route' have been added toward that end.

Grant Erickson (9):
service: Refactor 'nameserver_del_routes'.
service: Add gateway parameter to DNS host route deletion paths.
inet: Add gateway parameter to 'connman_inet_del_{,ipv6_}host_route'.
inet: Document 'connman_inet_{add,del}_{,ipv6_}host_route'.
service: Const-qualify 'add_nameserver_route'.
service: Add 'DBG' to 'add_nameserver_route'.
inet: Document '{add,del}_nameserver_route'.
inet: Document 'nameserver_{add,del}_routes'.
inet: Document '__connman_service_nameserver_{add,del}_routes'.

 include/inet.h |  17 ++--
 src/connman.h  |   1 +
 src/gateway.c  |  33 +++++---
 src/inet.c     | 184 ++++++++++++++++++++++++++++++++++++++--
 src/service.c  | 225 ++++++++++++++++++++++++++++++++++++++++++++-----
 5 files changed, 419 insertions(+), 41 deletions(-)
Signature · 1 line
2.42.0
#1 lore raw

PATCH 1/9 service: Refactor 'nameserver_del_routes'.

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(-)
src/service.c +26 -15
index 1f2c9f54db9a..54c12532e9ca 100644
@@ -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);
 	}
 }
 
Signature · 1 line
2.42.0
#2 lore raw

PATCH 2/9 service: Add gateway parameter to DNS host route deletion paths.

In reply to Grant Erickson

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(-)
src/connman.h +1 -0
index 90d5a34b8c58..622a778590b1 100644
@@ -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);
src/gateway.c +12 -4
index 61f3226a6771..b97abe0dd991 100644
@@ -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);
 
src/service.c +17 -8
index 54c12532e9ca..21b83e51e788 100644
@@ -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);
Signature · 1 line
2.42.0
#3 lore raw

PATCH 3/9 inet: Add gateway parameter to 'connman_inet_del_{,ipv6_}host_route'.

In reply to Grant Erickson

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(-)
include/inet.h +12 -5
index c7488165720c..5b2015eda76a 100644
@@ -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,
src/gateway.c +11 -6
index b97abe0dd991..29115250d243 100644
@@ -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. */
 
src/inet.c +35 -5
index 371b3328175f..55684dc2fd65 100644
@@ -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);
 }
 
src/service.c +19 -6
index 21b83e51e788..1f227a2e0125 100644
@@ -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;
 	}
 }
Signature · 1 line
2.42.0
#4 lore raw

PATCH 4/9 inet: Document 'connman_inet_{add,del}_{,ipv6_}host_route'.

In reply to Grant Erickson

This adds documentation to the 'connman_inet_{add,del}_{,ipv6_}host_route' functions.

---
 src/inet.c | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 144 insertions(+)
src/inet.c +144 -0
index 55684dc2fd65..e0f927a12dcb 100644
@@ -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)
Signature · 1 line
2.42.0
#5 lore raw

PATCH 5/9 service: Const-qualify 'add_nameserver_route'.

In reply to Grant Erickson

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(-)
src/service.c +1 -1
index 1f227a2e0125..55eb4d8d757d 100644
@@ -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) {
Signature · 1 line
2.42.0
#6 lore raw

PATCH 6/9 service: Add 'DBG' to 'add_nameserver_route'.

In reply to Grant Erickson

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(+)
src/service.c +3 -0
index 55eb4d8d757d..e0a11a2bc6a2 100644
@@ -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))
Signature · 1 line
2.42.0
#7 lore raw

PATCH 7/9 inet: Document '{add,del}_nameserver_route'.

In reply to Grant Erickson

This adds documentation to the '{add,del}_nameserver_route' functions.

---
 src/service.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
src/service.c +53 -0
index e0a11a2bc6a2..8821445f32e7 100644
@@ -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)
Signature · 1 line
2.42.0
#8 lore raw

PATCH 8/9 inet: Document 'nameserver_{add,del}_routes'.

In reply to Grant Erickson

This adds documentation to the 'nameserver_{add,del}_routes' functions.

---
 src/service.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
src/service.c +50 -0
index 8821445f32e7..7e14a3dbf496 100644
@@ -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)
Signature · 1 line
2.42.0
#9 lore raw

PATCH 9/9 inet: Document '__connman_service_nameserver_{add,del}_routes'.

In reply to Grant Erickson

This adds documentation to the '__connman_service_nameserver_{add,del}_routes' functions.

---
 src/service.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
src/service.c +44 -0
index 7e14a3dbf496..b8224e8ff0bc 100644
@@ -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,
Signature · 1 line
2.42.0
#10 lore raw
In reply to Grant Erickson

Hi Grant,

Quoted 36 lines

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.

This adds a previously-missing gateway address parameter to the 'connman_inet_del_{,ipv6_}host_route' functions. In addition, call sites to 'connman_inet_del_{,ipv6_}host_route' are updated to pass the gateway parameter.

In addition, in the process, this refactors 'nameserver_del_routes' into a second, helper function 'del_nameserver_route' such that host route deletion is separated from DNS server iteration. This structure now mirrors that of 'nameserver_add_routes' and 'add_nameserver_route' since, again, route addition and deletion should be symmetric.

NOTE: This is only the first half of the necessary change. The second half is revising the actual implementation of 'connman_inet_del_{,ipv6_}host_route' to take advantage of the newly-added gateway parameter. Implementation notes in each of 'connman_inet_del_{,ipv6_}host_route' have been added toward that end.

Grant Erickson (9):
service: Refactor 'nameserver_del_routes'.
service: Add gateway parameter to DNS host route deletion paths.
inet: Add gateway parameter to 'connman_inet_del_{,ipv6_}host_route'.
inet: Document 'connman_inet_{add,del}_{,ipv6_}host_route'.
service: Const-qualify 'add_nameserver_route'.
service: Add 'DBG' to 'add_nameserver_route'.
inet: Document '{add,del}_nameserver_route'.
inet: Document 'nameserver_{add,del}_routes'.
inet: Document '__connman_service_nameserver_{add,del}_routes'.

Quoted 6 lines
include/inet.h |  17 ++--
src/connman.h  |   1 +
src/gateway.c  |  33 +++++---
src/inet.c     | 184 ++++++++++++++++++++++++++++++++++++++--
src/service.c  | 225 ++++++++++++++++++++++++++++++++++++++++++++-----
5 files changed, 419 insertions(+), 41 deletions(-)

all 9 patches have been applied.

Regards

Marcel