ConnMan network manager
 help / color / mirror / Atom feed
From: Grant Erickson <gerickson@nuovations.com>
To: connman@lists.linux.dev
Subject: [PATCH] connection: Explicitly handle CONNMAN_IPCONFIG_TYPE_ALL.
Date: Wed, 29 Nov 2023 15:38:01 -0800	[thread overview]
Message-ID: <20231129233801.1313129-1-gerickson@nuovations.com> (raw)

At commit 89f70d225df6 ("ipconfig: Define unique value for
CONNMAN_IPCONFIG_TYPE_ALL"), a unique enumertion value was provided
for 'CONNMAN_IPCONFIG_TYPE_ALL' to make it semantically different from
'CONNMAN_IPCONFIG_TYPE_UNKNOWN'.

However, with that change, the connection module was never updated to
explicitly treat 'CONNMAN_IPCONFIG_TYPE_ALL' as a synonym for
'CONNMAN_IPCONFIG_TYPE_IPV4' + 'CONNMAN_IPCONFIG_TYPE_IPV6' and to
treat 'CONNMAN_IPCONFIG_TYPE_UNKNOWN' as an error.

This makes those changes, treating 'CONNMAN_IPCONFIG_TYPE_ALL' as such
a synonym and 'CONNMAN_IPCONFIG_TYPE_UNKNOWN' as an error.
---
 src/connection.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 91ce39adc167..2d9e259c2d28 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -627,8 +627,10 @@ static int del_gateway_routes(struct gateway_data *data,
 		do_ipv4 = true;
 	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
 		do_ipv6 = true;
-	else
+	else if (type == CONNMAN_IPCONFIG_TYPE_ALL)
 		do_ipv4 = do_ipv6 = true;
+	else
+		return -EINVAL;
 
 	if (do_ipv4 && data->ipv4_config) {
 		if (data->ipv4_config->vpn) {
@@ -711,6 +713,12 @@ static int del_gateway_routes_if_active(struct gateway_data *data,
 {
 	bool active = false;
 
+	DBG("data %p type %d (%s)", data,
+		type, __connman_ipconfig_type2string(type));
+
+	if (!data || type == CONNMAN_IPCONFIG_TYPE_UNKNOWN)
+		return -EINVAL;
+
 	GATEWAY_DATA_DBG("data", data);
 
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
@@ -719,7 +727,7 @@ static int del_gateway_routes_if_active(struct gateway_data *data,
 	} else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
 		if (data->ipv6_config)
 			active = data->ipv6_config->active;
-	} else
+	} else if (type == CONNMAN_IPCONFIG_TYPE_ALL)
 		active = true;
 
 	DBG("type %d active %d", type, active);
@@ -871,8 +879,10 @@ static void set_default_gateway(struct gateway_data *data,
 		do_ipv4 = true;
 	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
 		do_ipv6 = true;
-	else
+	else if (type == CONNMAN_IPCONFIG_TYPE_ALL)
 		do_ipv4 = do_ipv6 = true;
+	else
+		return;
 
 	if (do_ipv4 && data->ipv4_config &&
 					data->ipv4_config->vpn) {
@@ -949,11 +959,10 @@ static void unset_default_gateway(struct gateway_data *data,
 		do_ipv4 = true;
 	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
 		do_ipv6 = true;
-	else
+	else if (type == CONNMAN_IPCONFIG_TYPE_ALL)
 		do_ipv4 = do_ipv6 = true;
-
-	DBG("type %d gateway ipv4 %p ipv6 %p", type, data->ipv4_config,
-						data->ipv6_config);
+	else
+		return;
 
 	if (do_ipv4 && data->ipv4_config &&
 					data->ipv4_config->vpn) {
@@ -1599,8 +1608,10 @@ void __connman_connection_gateway_remove(struct connman_service *service,
 		do_ipv4 = true;
 	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
 		do_ipv6 = true;
-	else
+	else if (type == CONNMAN_IPCONFIG_TYPE_ALL)
 		do_ipv4 = do_ipv6 = true;
+	else
+		return;
 
     /* Delete any routes associated with this service's nameservers. */
 
-- 
2.42.0


                 reply	other threads:[~2023-11-29 23:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231129233801.1313129-1-gerickson@nuovations.com \
    --to=gerickson@nuovations.com \
    --cc=connman@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).