diff mbox series

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

Message ID 20231216082805.2221938-3-gerickson@nuovations.com (mailing list archive)
State Accepted, archived
Headers show
Series inet: Add Missing Gateway Parameter to Host Route Deletion Interfaces | expand

Commit Message

Grant Erickson Dec. 16, 2023, 8:27 a.m. UTC
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 mbox series

Patch

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);