connman.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services
@ 2023-12-06 23:49 Grant Erickson
  2023-12-06 23:49 ` [PATCH 01/90] connection: Rename 'find_active_gateway_data' Grant Erickson
                   ` (92 more replies)
  0 siblings, 93 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

In what is perhaps a violation of the "rule of least astonishment",
when attempting to keep Ethernet + Wi-Fi + Cellular (or any other
combination of network service technologies) connected at all times,
there is an expectation that if the application binds to an interface,
it can still get Internet reachability with that
interface. Unfortunately, this ONLY works for the default service,
ostensibly so named because it has the default route.

This patch series addresses this "violation" by adding support for
low-priority gateway default routes for non-default serices. The
changes impact:

    * src/connman.h
    * src/connection.c
    * src/inet.c
    * src/ipconfig.c
    * src/rtnl.c

with the biggest changes in src/connection.c, which, despite its name,
implements non-client-facing functionality for managing network
service gateways and routes. It also serves as a Linux Routing Netlink
(rtnl) listener for routing table additions and deletions in the Linux
kernel.

Gateway lifecycle is generally top-down, from user space to
kernel. That is, Connection Manager manages and adds/sets or gateway
routes and then uses notifications from the kernel Routing Netlink
(rtnl) to confirm and "activate" those routes. Likewise, Connection
Manager removes/clears/deletes gateway routes an then uses
notifications from the kernel Routing Netlink (rtnl) to confirm and
"inactivate" those routes. The following is the state machine for that
lifecycle:


                          .----------.    SIOCADDRT /
                          |          |    RTM_NEWROUTE
       .------------------| Inactive |--------------------.
       |                  |          |                    |
       |                  '----------'                    |
       | connman_rtnl                                     |
       | .delgateway                                      |
       |                                                  V
  .---------.         SIOCADDRT / RTM_NEWROUTE        .-------.
  |         |---------------------------------------->|       |
  | Removed |                                         | Added |
  |         |<----------------------------------------|       |
  '---------'         SIOCDELRT / RTM_DELROUTE        '-------'
       ^                                                  |
       | SIOCDELRT /                                      |
       | RTM_DELROUTE                                     |
       |                   .--------.     connman_rtnl    |
       |                   |        |     .newgateway     |
       '-------------------| Active |<--------------------'
                           |        |
                           '--------'

Gateways, and their associated routes, are generally of two types:

  1. High-priority (that is, metric 0) default route.

     This is used by the default service and its underlying
     network interface.

  2. Low-priority (that is, metric > 0) default route.

     This is used by non-default services and their underlying
     network interface.

     For IPv6, these are handled and managed automatically by
     the kernel as part of Router Discovery (RD) Router
     Advertisements (RAs) and because link-local addresses and
     multi-homing are a natural part of IPv6, nothing needs to
     be done here. These routes show up in 'ip -6 route show'
     as:

         default via fe80::f29f:c2ff:fe10:271e dev eth0
             proto ra metric 1024 expires 1622sec hoplimit 64
             pref medium
         default via fe80::f29f:c2ff:fe10:271e dev wlan0
             proto ra metric 1024 expires 1354sec hoplimit 64
             pref medium

     For IPv4, largely invented before the advent of link-local
     addresses and multi-homing hosts, these need to be
     fully-managed here and, with such management, should show up
     in 'ip -4 route show' as low-priority (that is, high metric
     value) default routes:

         default via 192.168.2.1 dev wlan0 metric 4294967295

     The other alternative to low-priority routes would be to
     use "def1" default routes commonly used by VPNs that have a
     prefix length of 1 (hence the "def1" name). These would
     show up as:

         0.0.0.0/1 via 192.168.2.1 dev wlan0
         128.0.0.0/1 via 192.168.2.1 dev wlan0

     However, since these require twice the number of routing
     table entries and seem no more effective than the low-
     priority route approach, this alternative is not used here
     at present.

VPNs and point-to-point (P2P) links get special treatment but
otherwise utilize the same states and types as described above.

Operationally, down calls from outside this module (src/connection.c)
generally come from the following three functions:

  1. __connman_connection_gateway_add
  2. __connman_connection_gateway_remove
  3. __connman_connection_update_gateway

and up calls generally come from the following two functions:

  1. connection_newgateway
  2. connection_delgateway

From these five functions above, we are then attempting to do the
following for a gateway associated with a network service and its
underlying network interface:

  1. Set, or add, the high- or low-priority default route(s).
  2. Unset, or remove, the high- or low-priority default route(s).
  3. Promote the default route from low- to high-priority.
  4. Demote the default route from high- to low-priority.

The call trees for these operations amount to:

  set_default_gateway (1)
    |
    '-mutate_default_gateway
        |
        |-set_ipv4_high_priority_default_gateway
        |   |
        |   '-set_default_gateway_route_common
        |       |
        |       '-set_ipv4_high_priority_default_gateway_route_cb
        |
        '-set_ipv6_high_priority_default_gateway
            |
            '-set_default_gateway_route_common
                |
                '-set_ipv6_high_priority_default_gateway_route_cb

  set_low_priority_default_gateway (1)
    |
    '-mutate_default_gateway
        |
        '-set_ipv4_low_priority_default_gateway
            |
            '-set_default_gateway_route_common
                |
                '-set_ipv4_low_priority_default_gateway_route_cb
                    |
                    '-compute_low_priority_metric

  unset_default_gateway (2)
    |
    '-mutate_default_gateway
        |
        |-unset_ipv4_high_priority_default_gateway
        |   |
        |   '-unset_default_gateway_route_common
        |       |
        |       '-unset_ipv4_high_priority_default_gateway_route_cb
        |
        '-unset_ipv6_high_priority_default_gateway
            |
            '-unset_default_gateway_route_common
                |
                '-unset_ipv6_high_priority_default_gateway_route_cb

  unset_low_priority_default_gateway (2)
    |
    '-mutate_default_gateway
        |
        '-unset_ipv4_low_priority_default_gateway
            |
            '-unset_default_gateway_route_common
                |
                '-unset_ipv4_low_priority_default_gateway_route_cb
                    |
                    '-compute_low_priority_metric

  promote_default_gateway (3)
    |
    |-unset_low_priority_default_gateway (2)
    |
    '-set_default_gateway (1)

  demote_default_gateway (4)
    |
    |-unset_default_gateway (2)
    |
    '-set_low_priority_default_gateway (1)

where:

  * 'mutate_default_gateway' and
    '{un,}set_default_gateway_route_common' are abstract,
    generalized handlers that manage the broad error conditions
    and gateway data and configuration lifecycle management.

  * '*_route_cb' callbacks handle the actual routing table
    manipulation as appropriate for the IP configuration and
    gateway type, largely through the use of gateway
    configuration "ops" to help neutralize differences between
    IPv4 and IPv6.

    In the fullness of time, the use of the gateway
    configuration "ops" should allow further collapsing the IPv4
    and IPv6 cases and simplifying the IP type-specific branches
    of the above call trees.

    The low-priority metric is determined on a per-network
    interface basis and is computed by
    'compute_low_priority_metric'.

Grant Erickson (90):
  connection: Rename 'find_active_gateway_data'.
  connection: Document 'find_any_active_gateway_data'.
  connection: Replace gateway config active Boolean.
  connection: Document gateway configuration state.
  connection: Replace gateway config VPN Boolean.
  connection: Document gateway configuration flags.
  connection: Introduce gateway configuration 'type'.
  connection: Document 'gateway_config_type'.
  connection: Add function parameter to {un,}set_default_gateway.
  connection: Fix 'DBG' copy-and-paste typo.
  connection: Split '{un,}_default_gateway' IP-specific functions.
  connection: Add 'DBG' to 'del_gateway_routes'.
  connection: Rename 'active_gateway' local.
  connection: Check 'service' parameter for null.
  connection: Check service network index for validity.
  connection: Refactor '__connman_connection_gateway_add'.
  connection: Remove 'DBG' from '__connman_connection_update_gateway'.
  connection: Refactor 'yield_default_gateway'.
  connection: Document 'gateway_data_config_get'.
  connection: Document 'yield_default_gateway_for_type'.
  connection: Add 'gateway_config_free'.
  connection: Document 'gateway_config_free'.
  connection: Introduce and leverage 'mutate_default_gateway'.
  connection: Document 'mutate_default_gateway_ops'.
  connection: Document 'mutate_default_gateway'.
  connection: Add gateway config ADDED/REMOVED states.
  connection: Add low-priority default gateway config type.
  connection: Change return type of 'unset_default_gateway'.
  connection: Leverage 'unset_default_gateway' in 'del_gateway_routes'.
  connection: Change return type of 'set_default_gateway'.
  connection: Fan out route manipulation into callbacks.
  connection: Document 'mutate_default_gateway_route_cb_t'.
  connection: Document 'set_default_gateway_route_common'.
  connection: Document 'unset_default_gateway_route_common'.
  inet: Add '__connman_inet_table2string'.
  inet: Document '__connman_inet_table2string'.
  inet: Leverage '__connman_inet_table2string'.
  rtnl: Add support for extracting the table identifier.
  ipconfig: Pass the rtnl table to '__connman_ipconfig_{new,del}route'.
  rtnl: Add support for extracting the metric/priority.
  ipconfig: Pass the rtnl metric to '__connman_ipconfig_{new,del}route'.
  ipconfig: Pass the rtnl dst prefixlen to
    '__connman_ipconfig_{new,del}route'.
  inet: Include interface index and name in 'DBG'.
  inet: Include the command value and string in 'DBG'
  ipconfig: Use 'RT_SCOPE_*' mnemonics.
  inet: Add a metric parameter to 'iproute_default_modify'.
  inet: Document 'iproute_default_modify'.
  connection: Document '__connman_inet_add_default_to_table'.
  connection: Document '__connman_inet_del_default_to_table'.
  inet: Add
    '__connman_inet_{add,del}_default_{to,from}_table_with_metric'.
  inet: Document
    '__connman_inet_{add,del}_default_{to,from}_table_with_metric'.
  connection: Add support for low-priority default routes.
  connection: Introduce '{de,pro}mote_default_gateway'.
  connection: Add 'is_addr_any_str'.
  connection: Introduce gateway config 'ops'
  connection: Refactor 'add_host_route'.
  connection: Add 'DBG' else clauses to 'connection_delgateway'.
  connection: Document 'gateway_config_state' finite state machine.
  connection: Document 'gateway_config_ops'.
  connection: Document 'gateway_config'.
  connection: Document 'gateway_data'.
  connection: Document 'gateway_hash'.
  connection: Document 'is_addr_any_str'.
  connection: Update 'find_any_active_gateway_data' documentation.
  connection: Document 'compute_low_priority_metric'.
  connection: Document 'add_host_route'.
  connection: Document call to 'connman_service_unref'.
  connection: Document 'demote_default_gateway'.
  connection: Document 'promote_default_gateway'.
  connection: Document
    'set_ipv4_high_priority_default_gateway_route_cb'.
  connection: Document
    'set_ipv6_high_priority_default_gateway_route_cb'.
  connection: Document 'set_ipv4_high_priority_default_gateway'.
  connection: Document 'set_ipv6_high_priority_default_gateway'.
  connection: Document
    'unset_ipv4_high_priority_default_gateway_route_cb'.
  connection: Document
    'unset_ipv6_high_priority_default_gateway_route_cb'.
  connection: Document 'unset_ipv4_high_priority_default_gateway'.
  connection: Document 'unset_ipv6_high_priority_default_gateway'.
  connection: Document 'set_ipv4_low_priority_default_gateway_route_cb'.
  connection: Document 'set_ipv4_low_priority_default_gateway'.
  connection: Document 'set_low_priority_default_gateway'.
  connection: Document
    'unset_ipv4_low_priority_default_gateway_route_cb'.
  connection: Document 'unset_ipv4_low_priority_default_gateway'.
  connection: Document 'unset_low_priority_default_gateway'.
  connection: Fix documentation typos.
  connection: Update 'set_default_gateway_route_common' documentation.
  connection: Update 'unset_default_gateway_route_common' documentation.
  connection: Update '{un,}set_default_gateway' documentation.
  connection: Add @file comment.
  connection: Add whitespace around 'del_gateway_routes_if_active'.
  connection: Ensure function attribution 'DBG' output is consistent.

 src/connection.c | 2937 +++++++++++++++++++++++++++++++++++++++-------
 src/connman.h    |   20 +-
 src/inet.c       |  298 ++++-
 src/ipconfig.c   |   26 +-
 src/rtnl.c       |   60 +-
 5 files changed, 2895 insertions(+), 446 deletions(-)

-- 
2.42.0


^ permalink raw reply	[flat|nested] 94+ messages in thread

* [PATCH 01/90] connection: Rename 'find_active_gateway_data'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 02/90] connection: Document 'find_any_active_gateway_data' Grant Erickson
                   ` (91 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This module has a map that maps services to their gateway data and IP
type-specific configuration. That configuration includes a state
variable indicating whether the configuration is actively contributing
to route that has been confirmed (or "activated") by a Routing Netlink
(rtnl) notification from the kernel.

In a multi-technology and -service environment, there are potentially
at least as many gateways as there are technologies and connected
services. Consequently, the function name 'find_active_gateway_data'
is ambiguous in that "which activate gateway data?" is
unspecified. While the purpose of this function remains unclear, the
name is being updated to accurately reflect what it does, which is to
return any active gateway data.
---
 src/connection.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 94b2f90f515b..f0da0c3c442c 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -352,7 +352,7 @@ static struct gateway_data *find_gateway_data(
 	return NULL;
 }
 
-static struct gateway_data *find_active_gateway_data(void)
+static struct gateway_data *find_any_active_gateway_data(void)
 {
 	GHashTableIter iter;
 	gpointer value, key;
@@ -390,7 +390,7 @@ static struct gateway_data *find_active_gateway_data(void)
  *    with the default network service (that is, has the default
  *    route) on success; otherwise, null.
  *
- *  @sa find_active_gateway_data
+ *  @sa find_any_active_gateway_data
  *  @sa find_gateway_data
  *
  */
@@ -1518,7 +1518,7 @@ int __connman_connection_gateway_add(struct connman_service *service,
 					enum connman_ipconfig_type type,
 					const char *peer)
 {
-	struct gateway_data *active_gateway = NULL;
+	struct gateway_data *any_active_gateway = NULL;
 	struct gateway_data *new_gateway = NULL;
 	enum connman_ipconfig_type type4 = CONNMAN_IPCONFIG_TYPE_UNKNOWN,
 		type6 = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
@@ -1560,12 +1560,9 @@ int __connman_connection_gateway_add(struct connman_service *service,
 
 	GATEWAY_DATA_DBG("new_gateway", new_gateway);
 
-	active_gateway = find_active_gateway_data();
+	any_active_gateway = find_any_active_gateway_data();
 
-	DBG("active %p index %d new %p", active_gateway,
-		active_gateway ? active_gateway->index : -1, new_gateway);
-
-	GATEWAY_DATA_DBG("active_gateway", active_gateway);
+	GATEWAY_DATA_DBG("any_active_gateway", any_active_gateway);
 
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
 				new_gateway->ipv4_config) {
@@ -1586,7 +1583,7 @@ int __connman_connection_gateway_add(struct connman_service *service,
 	if (service_type == CONNMAN_SERVICE_TYPE_VPN) {
 
 		set_vpn_routes(new_gateway, service, gateway, type, peer,
-							active_gateway);
+							any_active_gateway);
 
 	} else {
 		if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
@@ -1598,7 +1595,7 @@ int __connman_connection_gateway_add(struct connman_service *service,
 			new_gateway->ipv6_config->vpn = false;
 	}
 
-	if (!active_gateway) {
+	if (!any_active_gateway) {
 		set_default_gateway(new_gateway, type);
 		goto done;
 	}
@@ -1608,8 +1605,8 @@ int __connman_connection_gateway_add(struct connman_service *service,
 				new_gateway->ipv4_config->vpn) {
 		if (!__connman_service_is_split_routing(new_gateway->service))
 			connman_inet_clear_gateway_address(
-					active_gateway->index,
-					active_gateway->ipv4_config->gateway);
+				any_active_gateway->index,
+				any_active_gateway->ipv4_config->gateway);
 	}
 
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
@@ -1617,8 +1614,8 @@ int __connman_connection_gateway_add(struct connman_service *service,
 				new_gateway->ipv6_config->vpn) {
 		if (!__connman_service_is_split_routing(new_gateway->service))
 			connman_inet_clear_ipv6_gateway_address(
-					active_gateway->index,
-					active_gateway->ipv6_config->gateway);
+				any_active_gateway->index,
+				any_active_gateway->ipv6_config->gateway);
 	}
 
 done:
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 02/90] connection: Document 'find_any_active_gateway_data'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
  2023-12-06 23:49 ` [PATCH 01/90] connection: Rename 'find_active_gateway_data' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 03/90] connection: Replace gateway config active Boolean Grant Erickson
                   ` (90 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds documentation to the 'find_any_active_gateway_data'
function.
---
 src/connection.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index f0da0c3c442c..6be39a773df1 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -352,6 +352,21 @@ static struct gateway_data *find_gateway_data(
 	return NULL;
 }
 
+/**
+ *  @brief
+ *    Find the first, or any, gateway data marked active.
+ *
+ *  This attempts to find the first, or any, gateway data marked
+ *  active.
+ *
+ *  @returns
+ *    A pointer to the first, or any, gateway data marked active on
+ *    success; otherwise, null.
+ *
+ *  @sa find_default_gateway_data
+ *  @sa find_gateway_data
+ *
+ */
 static struct gateway_data *find_any_active_gateway_data(void)
 {
 	GHashTableIter iter;
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 03/90] connection: Replace gateway config active Boolean.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
  2023-12-06 23:49 ` [PATCH 01/90] connection: Rename 'find_active_gateway_data' Grant Erickson
  2023-12-06 23:49 ` [PATCH 02/90] connection: Document 'find_any_active_gateway_data' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 04/90] connection: Document gateway configuration state Grant Erickson
                   ` (89 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

There is presently overloading of gateway configuration state, in
particular, the 'active' field. By "overloading", that is, using the
gateway configuration field for a purpose beyond that for which it may
have been originally intended.

The intent of the 'active' field was to make it a state indicating
that a gateway route, added or deleted, had been confirmed or
"activated" by a Linux Routing Netlink (rtnl) notification via this
module's 'connection_{new,del}gateway' functions.

This returns 'active' to its former and sole role as a representative
of that gateway configuration lifecycle state by making it a state
enumeration, currently with two values, ACTIVE and INACTIVE. In the
future, these will be expanded to further represent all states of the
gateway configuration lifecycle.
---
 src/connection.c | 116 ++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 89 insertions(+), 27 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 6be39a773df1..6c735f761a54 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -38,8 +38,13 @@
 #define GATEWAY_DATA_DBG(description, data) \
 	gateway_data_debug(__func__, description, data)
 
+enum gateway_config_state {
+	CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE = 0,
+	CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE	  = 1
+};
+
 struct gateway_config {
-	bool active;
+	enum gateway_config_state state;
 	char *gateway;
 
 	/* VPN extra data */
@@ -87,6 +92,41 @@ static const char *maybe_null(const void *pointer)
 	return pointer ? pointer : "<null>";
 }
 
+static const char *gateway_config_state2string(enum gateway_config_state state)
+{
+	switch (state) {
+	case CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE:
+		return "inactive";
+	case CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE:
+		return "active";
+	}
+
+	return NULL;
+}
+
+static void gateway_config_state_set(struct gateway_config *config,
+				enum gateway_config_state state)
+{
+	DBG("config %p old state %d (%s) => new state %d (%s)",
+		config,
+		config->state, gateway_config_state2string(config->state),
+		state, gateway_config_state2string(state));
+
+	config->state = state;
+}
+
+static bool is_gateway_config_state(const struct gateway_config *config,
+				enum gateway_config_state state)
+{
+	return config->state == state;
+}
+
+static bool is_gateway_config_state_active(const struct gateway_config *config)
+{
+	return is_gateway_config_state(config,
+				CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
+}
+
 /**
  *  @brief
  *    Conditionally log the specified gateway configuration.
@@ -125,13 +165,15 @@ static void gateway_config_debug(const char *function,
 			vpn_phy_interface =
 				connman_inet_ifname(config->vpn_phy_index);
 
-		DBG("from %s %s %p: { active: %u, gateway: %p (%s), "
+		DBG("from %s() "
+			"%s %p: { state: %d (%s), gateway: %p (%s), "
 			"vpn: %u, vpn_ip: %p (%s), vpn_phy_index: %d (%s), "
 			"vpn_phy_ip: %p (%s) }",
 			function,
 			description,
 			config,
-			config->active,
+			config->state,
+			maybe_null(gateway_config_state2string(config->state)),
 			config->gateway, maybe_null(config->gateway),
 			config->vpn,
 			config->vpn_ip, maybe_null(config->vpn_ip),
@@ -380,11 +422,13 @@ static struct gateway_data *find_any_active_gateway_data(void)
 		struct gateway_data *data = value;
 
 		if (data->ipv4_config &&
-				data->ipv4_config->active)
+				is_gateway_config_state_active(
+					data->ipv4_config))
 			return data;
 
 		if (data->ipv6_config &&
-				data->ipv6_config->active)
+				is_gateway_config_state_active(
+					data->ipv6_config))
 			return data;
 	}
 
@@ -738,14 +782,16 @@ static int del_gateway_routes_if_active(struct gateway_data *data,
 
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
 		if (data->ipv4_config)
-			active = data->ipv4_config->active;
+			active = is_gateway_config_state_active(
+						data->ipv4_config);
 	} else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
 		if (data->ipv6_config)
-			active = data->ipv6_config->active;
+			active = is_gateway_config_state_active(
+						data->ipv6_config);
 	} else if (type == CONNMAN_IPCONFIG_TYPE_ALL)
 		active = true;
 
-	DBG("type %d active %d", type, active);
+	DBG("active %u", active);
 
 	if (active)
 		return del_gateway_routes(data, type);
@@ -837,12 +883,12 @@ static int add_gateway(struct connman_service *service,
 	if (!config)
 		return -ENOMEM;
 
+	config->state = CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE;
 	config->gateway = g_strdup(gateway);
 	config->vpn_ip = NULL;
 	config->vpn_phy_ip = NULL;
 	config->vpn = false;
 	config->vpn_phy_index = -1;
-	config->active = false;
 
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
 		temp_data->ipv4_config = config;
@@ -932,7 +978,8 @@ static void set_default_gateway(struct gateway_data *data,
 		if (data->ipv4_config->vpn) {
 			connman_inet_set_gateway_interface(data->index);
 
-			data->ipv4_config->active = true;
+			gateway_config_state_set(data->ipv4_config,
+				CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
 
 			DBG("set %p index %d vpn %s index %d phy %s",
 				data, data->index, data->ipv4_config->vpn_ip,
@@ -943,7 +990,8 @@ static void set_default_gateway(struct gateway_data *data,
 						data->index) < 0)
 				return;
 
-			data->ipv4_config->active = true;
+			gateway_config_state_set(data->ipv4_config,
+				CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
 
 			DBG("set %p index %d",
 				data, data->index);
@@ -962,7 +1010,8 @@ static void set_default_gateway(struct gateway_data *data,
 		if (data->ipv6_config->vpn) {
 			connman_inet_set_ipv6_gateway_interface(data->index);
 
-			data->ipv6_config->active = true;
+			gateway_config_state_set(data->ipv6_config,
+				CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
 
 			DBG("set %p index %d vpn %s index %d phy %s",
 				data, data->index, data->ipv6_config->vpn_ip,
@@ -973,7 +1022,8 @@ static void set_default_gateway(struct gateway_data *data,
 						data->index) < 0)
 				return;
 
-			data->ipv6_config->active = true;
+			gateway_config_state_set(data->ipv6_config,
+				CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
 
 			DBG("set %p index %d",
 				data, data->index);
@@ -1046,7 +1096,8 @@ static void unset_default_gateway(struct gateway_data *data,
 		if (data->ipv4_config->vpn) {
 			connman_inet_clear_gateway_interface(data->index);
 
-			data->ipv4_config->active = false;
+			gateway_config_state_set(data->ipv4_config,
+				CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
 
 			DBG("unset %p index %d vpn %s index %d phy %s",
 				data, data->index, data->ipv4_config->vpn_ip,
@@ -1055,7 +1106,8 @@ static void unset_default_gateway(struct gateway_data *data,
 		} else if (is_ipv4_addr_any_str(data->ipv4_config->gateway)) {
 			connman_inet_clear_gateway_interface(data->index);
 
-			data->ipv4_config->active = false;
+			gateway_config_state_set(data->ipv4_config,
+				CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
 
 			DBG("unset %p index %d",
 				data, data->index);
@@ -1072,7 +1124,8 @@ static void unset_default_gateway(struct gateway_data *data,
 		if (data->ipv6_config->vpn) {
 			connman_inet_clear_ipv6_gateway_interface(data->index);
 
-			data->ipv6_config->active = false;
+			gateway_config_state_set(data->ipv6_config,
+				CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
 
 			DBG("unset %p index %d vpn %s index %d phy %s",
 				data, data->index, data->ipv6_config->vpn_ip,
@@ -1081,7 +1134,8 @@ static void unset_default_gateway(struct gateway_data *data,
 		} else if (is_ipv6_addr_any_str(data->ipv6_config->gateway)) {
 			connman_inet_clear_ipv6_gateway_interface(data->index);
 
-			data->ipv6_config->active = false;
+			gateway_config_state_set(data->ipv6_config,
+				CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
 
 			DBG("unset %p index %d",
 				data, data->index);
@@ -1145,7 +1199,7 @@ static bool yield_default_gateway(struct gateway_data *activated,
 		 * lifecycle), then it yields the default gateway to the
 		 * activated gateway data.
 		 */
-		if (!existing->ipv4_config->active) {
+		if (!is_gateway_config_state_active(existing->ipv4_config)) {
 			DBG("ipv4 existing %p yielding default", existing);
 
 			unset_default_gateway(existing, type);
@@ -1158,7 +1212,7 @@ static bool yield_default_gateway(struct gateway_data *activated,
 		 * service sort order, then the activated gateway data yields
 		 * the default gateway to the existing gateway data.
 		 */
-		if (existing->ipv4_config->active &&
+		if (is_gateway_config_state_active(existing->ipv4_config) &&
 				__connman_service_compare(existing->service,
 						activated->service) < 0) {
 			DBG("ipv4 activated %p yielding default", activated);
@@ -1183,7 +1237,7 @@ static bool yield_default_gateway(struct gateway_data *activated,
 		 * lifecycle), then it yields the default gateway to the
 		 * activated gateway data.
 		 */
-		if (!existing->ipv6_config->active) {
+		if (!is_gateway_config_state_active(existing->ipv6_config)) {
 			DBG("ipv6 existing %p yielding default", existing);
 
 			unset_default_gateway(existing, type);
@@ -1196,7 +1250,7 @@ static bool yield_default_gateway(struct gateway_data *activated,
 		 * service sort order, then the activated gateway data yields
 		 * the default gateway to the existing gateway data.
 		 */
-		if (existing->ipv6_config->active &&
+		if (is_gateway_config_state_active(existing->ipv6_config) &&
 			__connman_service_compare(existing->service,
 					activated->service) < 0) {
 			DBG("ipv6 activated %p yielding default", activated);
@@ -1333,7 +1387,8 @@ static void connection_newgateway(int index, const char *gateway)
 	 * prospectively mark it as active; however, this may be
 	 * subsequently modified as default route determinations are made.
 	 */
-	config->active = true;
+	gateway_config_state_set(config,
+		CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
 
 	/*
 	 * It is possible that we have two default routes atm
@@ -1422,7 +1477,8 @@ static void connection_delgateway(int index, const char *gateway)
 	if (config) {
 		GATEWAY_CONFIG_DBG("config", config);
 
-		config->active = false;
+		gateway_config_state_set(config,
+			CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
 	}
 
 	/*
@@ -1817,7 +1873,8 @@ bool __connman_connection_update_gateway(void)
 			continue;
 
 		if (active_gateway->ipv4_config &&
-				active_gateway->ipv4_config->active) {
+				is_gateway_config_state_active(
+					active_gateway->ipv4_config)) {
 
 			unset_default_gateway(active_gateway,
 						CONNMAN_IPCONFIG_TYPE_IPV4);
@@ -1825,7 +1882,8 @@ bool __connman_connection_update_gateway(void)
 		}
 
 		if (active_gateway->ipv6_config &&
-				active_gateway->ipv6_config->active) {
+				is_gateway_config_state_active(
+					active_gateway->ipv6_config)) {
 
 			unset_default_gateway(active_gateway,
 						CONNMAN_IPCONFIG_TYPE_IPV6);
@@ -1839,12 +1897,16 @@ bool __connman_connection_update_gateway(void)
 	 */
 	if (default_gateway) {
 		if (default_gateway->ipv4_config &&
-			(updated || !default_gateway->ipv4_config->active))
+			(updated ||
+			!is_gateway_config_state_active(
+				default_gateway->ipv4_config)))
 			set_default_gateway(default_gateway,
 					CONNMAN_IPCONFIG_TYPE_IPV4);
 
 		if (default_gateway->ipv6_config &&
-			(updated || !default_gateway->ipv6_config->active))
+			(updated ||
+			!is_gateway_config_state_active(
+				default_gateway->ipv6_config)))
 			set_default_gateway(default_gateway,
 					CONNMAN_IPCONFIG_TYPE_IPV6);
 	}
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 04/90] connection: Document gateway configuration state.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (2 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 03/90] connection: Replace gateway config active Boolean Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 05/90] connection: Replace gateway config VPN Boolean Grant Erickson
                   ` (88 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds documentation to the 'gateway_config_state' enumeration.
---
 src/connection.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 6c735f761a54..63c22be0cf83 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -38,12 +38,40 @@
 #define GATEWAY_DATA_DBG(description, data) \
 	gateway_data_debug(__func__, description, data)
 
+/**
+ *	@brief
+ *    Indicates the current lifecycle state of the gateway
+ *    configuration.
+ *
+ *  Gateway lifecycle is generally top-down, from user space to
+ *  kernel. That is, Connection Manager manages and adds/sets or
+ *  gateway routes and then uses notifications from the kernel Routing
+ *  Netlink (rtnl) to confirm and "activate" those routes. Likewise,
+ *  Connection Manager removes/clears/deletes gateway routes an then
+ *  uses notifications from the kernel Routing Netlink (rtnl) to
+ *  confirm and "inactivate" those routes.
+ *
+ */
 enum gateway_config_state {
+	/**
+	 *	Indicates whether the gateway, or default router, is inactive.
+	 */
 	CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE = 0,
+
+	/**
+	 *	Indicates whether the gateway, or default router, is added and
+	 *	acknowledged by the kernel through a Routing Netlink (rtnl)
+	 *	notification and, consequently, is active (that is, in use).
+	 */
 	CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE	  = 1
 };
 
 struct gateway_config {
+
+	/**
+	 *	Indicates the current state of the gateway configuration. See
+	 *	#gateway_config_state.
+	 */
 	enum gateway_config_state state;
 	char *gateway;
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 05/90] connection: Replace gateway config VPN Boolean.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (3 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 04/90] connection: Document gateway configuration state Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 06/90] connection: Document gateway configuration flags Grant Erickson
                   ` (87 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

There is presently overloading of gateway configuration state. That
is, using configuration fields for purposes beyond those for which
they may have originally been intended.

While the current VPN Boolean appears unoverloaded, this migrates it
from a single Boolean to a flag in a 32-bit flags field, allowing for
other future flags that alter how a gateway configuration behaves or
is treated, relative to its state and type.
---
 src/connection.c | 91 +++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 71 insertions(+), 20 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 63c22be0cf83..b13403c4a673 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -38,6 +38,11 @@
 #define GATEWAY_DATA_DBG(description, data) \
 	gateway_data_debug(__func__, description, data)
 
+enum gateway_config_flags {
+	CONNMAN_GATEWAY_CONFIG_FLAG_NONE = 0,
+	CONNMAN_GATEWAY_CONFIG_FLAG_VPN	 = 1U << 0
+};
+
 /**
  *	@brief
  *    Indicates the current lifecycle state of the gateway
@@ -67,6 +72,7 @@ enum gateway_config_state {
 };
 
 struct gateway_config {
+	uint32_t flags;
 
 	/**
 	 *	Indicates the current state of the gateway configuration. See
@@ -76,7 +82,6 @@ struct gateway_config {
 	char *gateway;
 
 	/* VPN extra data */
-	bool vpn;
 	char *vpn_ip;
 	int vpn_phy_index;
 	char *vpn_phy_ip;
@@ -120,6 +125,48 @@ static const char *maybe_null(const void *pointer)
 	return pointer ? pointer : "<null>";
 }
 
+static bool is_gateway_config_flags_set(const struct gateway_config *config,
+		uint32_t flags)
+{
+	return config && ((config->flags & flags) == flags);
+}
+
+static void gateway_config_flags_clear(struct gateway_config *config,
+		uint32_t flags)
+{
+	config->flags &= ~flags;
+}
+
+static void gateway_config_flags_set(struct gateway_config *config,
+	uint32_t flags)
+{
+	config->flags |= flags;
+}
+
+static bool is_gateway_config_vpn(const struct gateway_config *config)
+{
+	static const uint32_t flags =
+		CONNMAN_GATEWAY_CONFIG_FLAG_VPN;
+
+	return is_gateway_config_flags_set(config, flags);
+}
+
+static void gateway_config_set_vpn(struct gateway_config *config)
+{
+	static const uint32_t flags =
+		CONNMAN_GATEWAY_CONFIG_FLAG_VPN;
+
+	return gateway_config_flags_set(config, flags);
+}
+
+static void gateway_config_clear_vpn(struct gateway_config *config)
+{
+	static const uint32_t flags =
+		CONNMAN_GATEWAY_CONFIG_FLAG_VPN;
+
+	return gateway_config_flags_clear(config, flags);
+}
+
 static const char *gateway_config_state2string(enum gateway_config_state state)
 {
 	switch (state) {
@@ -194,16 +241,19 @@ static void gateway_config_debug(const char *function,
 				connman_inet_ifname(config->vpn_phy_index);
 
 		DBG("from %s() "
-			"%s %p: { state: %d (%s), gateway: %p (%s), "
-			"vpn: %u, vpn_ip: %p (%s), vpn_phy_index: %d (%s), "
+			"%s %p: { state: %d (%s), "
+			"flags: 0x%x (%s), "
+			"gateway: %p (%s), "
+			"vpn_ip: %p (%s), vpn_phy_index: %d (%s), "
 			"vpn_phy_ip: %p (%s) }",
 			function,
 			description,
 			config,
 			config->state,
 			maybe_null(gateway_config_state2string(config->state)),
+			config->flags,
+			is_gateway_config_vpn(config) ? "VPN" : "",
 			config->gateway, maybe_null(config->gateway),
-			config->vpn,
 			config->vpn_ip, maybe_null(config->vpn_ip),
 			config->vpn_phy_index, maybe_null(vpn_phy_interface),
 			config->vpn_phy_ip, maybe_null(config->vpn_phy_ip));
@@ -590,7 +640,8 @@ static void set_vpn_routes(struct gateway_data *new_gateway,
 		int index = __connman_ipconfig_get_index(ipconfig);
 		struct get_gateway_params *params;
 
-		config->vpn = true;
+		gateway_config_set_vpn(config);
+
 		if (peer)
 			config->vpn_ip = g_strdup(peer);
 		else if (gateway)
@@ -720,7 +771,7 @@ static int del_gateway_routes(struct gateway_data *data,
 		return -EINVAL;
 
 	if (do_ipv4 && data->ipv4_config) {
-		if (data->ipv4_config->vpn) {
+		if (is_gateway_config_vpn(data->ipv4_config)) {
 			status4 = connman_inet_clear_gateway_address(
 						data->index,
 						data->ipv4_config->vpn_ip);
@@ -738,7 +789,7 @@ static int del_gateway_routes(struct gateway_data *data,
 	}
 
 	if (do_ipv6 && data->ipv6_config) {
-		if (data->ipv6_config->vpn) {
+		if (is_gateway_config_vpn(data->ipv6_config)) {
 			status6 = connman_inet_clear_ipv6_gateway_address(
 						data->index,
 						data->ipv6_config->vpn_ip);
@@ -912,10 +963,10 @@ static int add_gateway(struct connman_service *service,
 		return -ENOMEM;
 
 	config->state = CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE;
+	config->flags = CONNMAN_GATEWAY_CONFIG_FLAG_NONE;
 	config->gateway = g_strdup(gateway);
 	config->vpn_ip = NULL;
 	config->vpn_phy_ip = NULL;
-	config->vpn = false;
 	config->vpn_phy_index = -1;
 
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
@@ -1003,7 +1054,7 @@ static void set_default_gateway(struct gateway_data *data,
 		return;
 
 	if (do_ipv4 && data->ipv4_config) {
-		if (data->ipv4_config->vpn) {
+		if (is_gateway_config_vpn(data->ipv4_config)) {
 			connman_inet_set_gateway_interface(data->index);
 
 			gateway_config_state_set(data->ipv4_config,
@@ -1035,7 +1086,7 @@ static void set_default_gateway(struct gateway_data *data,
 	}
 
 	if (do_ipv6 && data->ipv6_config) {
-		if (data->ipv6_config->vpn) {
+		if (is_gateway_config_vpn(data->ipv6_config)) {
 			connman_inet_set_ipv6_gateway_interface(data->index);
 
 			gateway_config_state_set(data->ipv6_config,
@@ -1121,7 +1172,7 @@ static void unset_default_gateway(struct gateway_data *data,
 		return;
 
 	if (do_ipv4 && data->ipv4_config) {
-		if (data->ipv4_config->vpn) {
+		if (is_gateway_config_vpn(data->ipv4_config)) {
 			connman_inet_clear_gateway_interface(data->index);
 
 			gateway_config_state_set(data->ipv4_config,
@@ -1149,7 +1200,7 @@ static void unset_default_gateway(struct gateway_data *data,
 	}
 
 	if (do_ipv6 && data->ipv6_config) {
-		if (data->ipv6_config->vpn) {
+		if (is_gateway_config_vpn(data->ipv6_config)) {
 			connman_inet_clear_ipv6_gateway_interface(data->index);
 
 			gateway_config_state_set(data->ipv6_config,
@@ -1687,11 +1738,11 @@ int __connman_connection_gateway_add(struct connman_service *service,
 	} else {
 		if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
 					new_gateway->ipv4_config)
-			new_gateway->ipv4_config->vpn = false;
+			gateway_config_clear_vpn(new_gateway->ipv4_config);
 
 		if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
 					new_gateway->ipv6_config)
-			new_gateway->ipv6_config->vpn = false;
+			gateway_config_clear_vpn(new_gateway->ipv6_config);
 	}
 
 	if (!any_active_gateway) {
@@ -1700,8 +1751,8 @@ int __connman_connection_gateway_add(struct connman_service *service,
 	}
 
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
-				new_gateway->ipv4_config &&
-				new_gateway->ipv4_config->vpn) {
+			new_gateway->ipv4_config &&
+			is_gateway_config_vpn(new_gateway->ipv4_config)) {
 		if (!__connman_service_is_split_routing(new_gateway->service))
 			connman_inet_clear_gateway_address(
 				any_active_gateway->index,
@@ -1709,8 +1760,8 @@ int __connman_connection_gateway_add(struct connman_service *service,
 	}
 
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
-				new_gateway->ipv6_config &&
-				new_gateway->ipv6_config->vpn) {
+			new_gateway->ipv6_config &&
+			is_gateway_config_vpn(new_gateway->ipv6_config)) {
 		if (!__connman_service_is_split_routing(new_gateway->service))
 			connman_inet_clear_ipv6_gateway_address(
 				any_active_gateway->index,
@@ -1791,10 +1842,10 @@ void __connman_connection_gateway_remove(struct connman_service *service,
 	GATEWAY_DATA_DBG("service_data", data);
 
 	if (do_ipv4 && data->ipv4_config)
-		is_vpn4 = data->ipv4_config->vpn;
+		is_vpn4 = is_gateway_config_vpn(data->ipv4_config);
 
 	if (do_ipv6 && data->ipv6_config)
-		is_vpn6 = data->ipv6_config->vpn;
+		is_vpn6 = is_gateway_config_vpn(data->ipv6_config);
 
 	DBG("ipv4 gateway %s ipv6 gateway %s vpn %d/%d",
 		data->ipv4_config ? data->ipv4_config->gateway : "<null>",
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 06/90] connection: Document gateway configuration flags.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (4 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 05/90] connection: Replace gateway config VPN Boolean Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 07/90] connection: Introduce gateway configuration 'type' Grant Erickson
                   ` (86 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds documentation to the 'gateway_config_flags' enumeration.
---
 src/connection.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index b13403c4a673..17d3805cd5fd 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -38,8 +38,18 @@
 #define GATEWAY_DATA_DBG(description, data) \
 	gateway_data_debug(__func__, description, data)
 
+/**
+ *  Flags governing the state and use of a gateway configuration.
+ */
 enum gateway_config_flags {
+	/**
+	 *	Indicates there are no gateway configuration flags asserted.
+	 */
 	CONNMAN_GATEWAY_CONFIG_FLAG_NONE = 0,
+
+	/**
+	 *	Indicates whether the gateway configuration is part of a VPN.
+	 */
 	CONNMAN_GATEWAY_CONFIG_FLAG_VPN	 = 1U << 0
 };
 
@@ -72,6 +82,10 @@ enum gateway_config_state {
 };
 
 struct gateway_config {
+	/**
+	 *	A 32-bit flag bitfield governing the state and use of the
+	 *	configuration. See #gateway_config_flags.
+	 */
 	uint32_t flags;
 
 	/**
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 07/90] connection: Introduce gateway configuration 'type'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (5 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 06/90] connection: Document gateway configuration flags Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 08/90] connection: Document 'gateway_config_type' Grant Erickson
                   ` (85 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

There is presently overloading of gateway configuration state. That
is, using configuration fields for purposes beyond those for which
they may have originally been intended.

This adds a new gateway configuration field, 'type', an enumeration
indicating the current type or use of the gateway configuration. This
may be used in conjunction with the 'state' and 'flags' fields to
conditionally treat the gateway configuration.
---
 src/connection.c | 69 ++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 64 insertions(+), 5 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 17d3805cd5fd..bcecd886b85b 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -81,6 +81,11 @@ enum gateway_config_state {
 	CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE	  = 1
 };
 
+enum gateway_config_type {
+	CONNMAN_GATEWAY_CONFIG_TYPE_NONE				  = 0,
+	CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT = 1
+};
+
 struct gateway_config {
 	/**
 	 *	A 32-bit flag bitfield governing the state and use of the
@@ -93,6 +98,7 @@ struct gateway_config {
 	 *	#gateway_config_state.
 	 */
 	enum gateway_config_state state;
+	enum gateway_config_type type;
 	char *gateway;
 
 	/* VPN extra data */
@@ -193,6 +199,18 @@ static const char *gateway_config_state2string(enum gateway_config_state state)
 	return NULL;
 }
 
+static const char *gateway_config_type2string(enum gateway_config_type type)
+{
+	switch (type) {
+	case CONNMAN_GATEWAY_CONFIG_TYPE_NONE:
+		return "none";
+	case CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT:
+		return "high-priority default";
+	}
+
+	return NULL;
+}
+
 static void gateway_config_state_set(struct gateway_config *config,
 				enum gateway_config_state state)
 {
@@ -216,6 +234,17 @@ static bool is_gateway_config_state_active(const struct gateway_config *config)
 				CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
 }
 
+static void gateway_config_type_set(struct gateway_config *config,
+				enum gateway_config_type type)
+{
+	DBG("config %p old type %d (%s) => new type %d (%s)",
+		config,
+		config->type, gateway_config_type2string(config->type),
+		type, gateway_config_type2string(type));
+
+	config->type = type;
+}
+
 /**
  *  @brief
  *    Conditionally log the specified gateway configuration.
@@ -255,7 +284,7 @@ static void gateway_config_debug(const char *function,
 				connman_inet_ifname(config->vpn_phy_index);
 
 		DBG("from %s() "
-			"%s %p: { state: %d (%s), "
+			"%s %p: { state: %d (%s), type %d (%s), "
 			"flags: 0x%x (%s), "
 			"gateway: %p (%s), "
 			"vpn_ip: %p (%s), vpn_phy_index: %d (%s), "
@@ -265,6 +294,8 @@ static void gateway_config_debug(const char *function,
 			config,
 			config->state,
 			maybe_null(gateway_config_state2string(config->state)),
+			config->type,
+			maybe_null(gateway_config_type2string(config->type)),
 			config->flags,
 			is_gateway_config_vpn(config) ? "VPN" : "",
 			config->gateway, maybe_null(config->gateway),
@@ -977,6 +1008,7 @@ static int add_gateway(struct connman_service *service,
 		return -ENOMEM;
 
 	config->state = CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE;
+	config->type = CONNMAN_GATEWAY_CONFIG_TYPE_NONE;
 	config->flags = CONNMAN_GATEWAY_CONFIG_FLAG_NONE;
 	config->gateway = g_strdup(gateway);
 	config->vpn_ip = NULL;
@@ -1097,6 +1129,9 @@ static void set_default_gateway(struct gateway_data *data,
 			DBG("set %p index %d gateway %s",
 				data, data->index, data->ipv4_config->gateway);
 		}
+
+		gateway_config_type_set(data->ipv4_config,
+			CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT);
 	}
 
 	if (do_ipv6 && data->ipv6_config) {
@@ -1129,6 +1164,9 @@ static void set_default_gateway(struct gateway_data *data,
 			DBG("set %p index %d gateway %s",
 				data, data->index, data->ipv4_config->gateway);
 		}
+
+		gateway_config_type_set(data->ipv6_config,
+			CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT);
 	}
 
 	DBG("status4 %d status6 %d", status4, status6);
@@ -1270,6 +1308,8 @@ static void unset_default_gateway(struct gateway_data *data,
 static bool yield_default_gateway(struct gateway_data *activated,
 					struct gateway_data *existing)
 {
+	static const enum gateway_config_type config_type =
+		CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT;
 	enum connman_ipconfig_type type;
 	bool yield_activated = false;
 
@@ -1293,7 +1333,11 @@ static bool yield_default_gateway(struct gateway_data *activated,
 		 * activated gateway data.
 		 */
 		if (!is_gateway_config_state_active(existing->ipv4_config)) {
-			DBG("ipv4 existing %p yielding default", existing);
+			DBG("%s existing %p yielding %s",
+				__connman_ipconfig_type2string(type),
+				existing,
+				maybe_null(gateway_config_type2string(
+					config_type)));
 
 			unset_default_gateway(existing, type);
 		}
@@ -1308,7 +1352,11 @@ static bool yield_default_gateway(struct gateway_data *activated,
 		if (is_gateway_config_state_active(existing->ipv4_config) &&
 				__connman_service_compare(existing->service,
 						activated->service) < 0) {
-			DBG("ipv4 activated %p yielding default", activated);
+			DBG("%s activated %p yielding %s",
+				__connman_ipconfig_type2string(type),
+				activated,
+				maybe_null(gateway_config_type2string(
+					config_type)));
 
 			unset_default_gateway(activated, type);
 
@@ -1331,7 +1379,11 @@ static bool yield_default_gateway(struct gateway_data *activated,
 		 * activated gateway data.
 		 */
 		if (!is_gateway_config_state_active(existing->ipv6_config)) {
-			DBG("ipv6 existing %p yielding default", existing);
+			DBG("%s existing %p yielding %s",
+				__connman_ipconfig_type2string(type),
+				existing,
+				maybe_null(gateway_config_type2string(
+					config_type)));
 
 			unset_default_gateway(existing, type);
 		}
@@ -1346,7 +1398,11 @@ static bool yield_default_gateway(struct gateway_data *activated,
 		if (is_gateway_config_state_active(existing->ipv6_config) &&
 			__connman_service_compare(existing->service,
 					activated->service) < 0) {
-			DBG("ipv6 activated %p yielding default", activated);
+			DBG("%s activated %p yielding %s",
+				__connman_ipconfig_type2string(type),
+				activated,
+				maybe_null(gateway_config_type2string(
+					config_type)));
 
 			unset_default_gateway(activated, type);
 
@@ -1572,6 +1628,9 @@ static void connection_delgateway(int index, const char *gateway)
 
 		gateway_config_state_set(config,
 			CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
+
+		gateway_config_type_set(config,
+			CONNMAN_GATEWAY_CONFIG_TYPE_NONE);
 	}
 
 	/*
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 08/90] connection: Document 'gateway_config_type'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (6 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 07/90] connection: Introduce gateway configuration 'type' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 09/90] connection: Add function parameter to {un,}set_default_gateway Grant Erickson
                   ` (84 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds documentation to the 'gateway_config_type' enumeration.
---
 src/connection.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index bcecd886b85b..1f5997786c13 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -81,8 +81,20 @@ enum gateway_config_state {
 	CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE	  = 1
 };
 
+/**
+ *	Indicates the current type or use of the gateway configuration.
+ */
 enum gateway_config_type {
+	/**
+	 *	Indicates the gateway, or default router, is not used for any
+	 *	route.
+	 */
 	CONNMAN_GATEWAY_CONFIG_TYPE_NONE				  = 0,
+
+	/**
+	 *	Indicates the gateway, or default router, is a high-priority
+	 *	(that is, metric 0) default route.
+	 */
 	CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT = 1
 };
 
@@ -98,6 +110,11 @@ struct gateway_config {
 	 *	#gateway_config_state.
 	 */
 	enum gateway_config_state state;
+
+	/**
+	 *	Indicates the current type or use of the gateway configuration.
+	 *	See #gateway_config_type.
+	 */
 	enum gateway_config_type type;
 	char *gateway;
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 09/90] connection: Add function parameter to {un,}set_default_gateway.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (7 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 08/90] connection: Document 'gateway_config_type' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 10/90] connection: Fix 'DBG' copy-and-paste typo Grant Erickson
                   ` (83 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

There are 13 unique call sites for '{un,}set_default_gateway' in this
module.

To aid debugging, a function parameter is added to
'{un,}set_default_gateway', which is a pointer to an immutable
null-terminated C string, ostenisbly the name of the function that
invoked '{un,}set_default_gateway'.

In addition, '{UN,}SET_DEFAULT_GATEWAY' macros are added and leveraged
at those 13 call sites. These macros invoke
'{un,}set_default_gateway', passing the C preprocessor predefined
'__func__' macro as the function parameter.
---
 src/connection.c | 87 +++++++++++++++++++++++++++++++-----------------
 1 file changed, 56 insertions(+), 31 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 1f5997786c13..6df29fe31aa9 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -32,6 +32,18 @@
 
 #include "connman.h"
 
+/*
+ * There are many call sites throughout this module for these
+ * functions. These are macros to help, during debugging, to acertain
+ * where they were called from.
+ */
+
+#define SET_DEFAULT_GATEWAY(data, type) \
+	set_default_gateway(data, type, __func__)
+
+#define UNSET_DEFAULT_GATEWAY(data, type) \
+	unset_default_gateway(data, type, __func__)
+
 #define GATEWAY_CONFIG_DBG(description, config) \
 	gateway_config_debug(__func__, description, config)
 
@@ -1083,12 +1095,16 @@ static int add_gateway(struct connman_service *service,
  *  service @a service will be signaled as the default via
  *  #__connman_service_indicate_default.
  *
- *  @param[in,out]  data  A pointer to the mutable gateway data to
- *                        assign as the default route.
- *  @param[in]      type  The IP configuration type for which the
- *                        gateway, or default router, configuration
- *                        will be selected from @a data and used to
- *                        set the default route.
+ *  @param[in,out]  data      A pointer to the mutable gateway data
+ *                            to assign as the default route.
+ *  @param[in]      type      The IP configuration type for which the
+ *                            gateway, or default router,
+ *                            configuration will be selected from @a
+ *                            data and used to set the default route.
+ *  @param[in]      function  A pointer to an immutable null-terminated
+ *                            C string containing the function name to
+ *                            which the call to this function should
+ *                            be attributed.
  *
  *  @sa __connman_inet_add_default_to_table
  *  @sa __connman_service_indicate_default
@@ -1097,13 +1113,15 @@ static int add_gateway(struct connman_service *service,
  *
  */
 static void set_default_gateway(struct gateway_data *data,
-				enum connman_ipconfig_type type)
+				enum connman_ipconfig_type type,
+				const char *function)
 {
 	int status4 = 0, status6 = 0;
 	bool do_ipv4 = false, do_ipv6 = false;
 
-	DBG("data %p type %d (%s)", data,
-		type, __connman_ipconfig_type2string(type));
+	DBG("data %p type %d (%s) from %s()", data,
+		type, __connman_ipconfig_type2string(type),
+		function);
 
 	GATEWAY_DATA_DBG("data", data);
 
@@ -1208,12 +1226,17 @@ static void set_default_gateway(struct gateway_data *data,
  *  On success, the gateway configuration specific to @a type will
  *  have its @a active field set to false.
  *
- *  @param[in,out]  data  A pointer to the mutable gateway data to
- *                        clear as the default route.
- *  @param[in]      type  The IP configuration type for which the
- *                        gateway, or default router, configuration
- *                        will be selected from @a data and used to
- *                        unset the default route.
+ *  @param[in,out]  data      A pointer to the mutable gateway data
+ *                            to clear as the default route.
+ *  @param[in]      type      The IP configuration type for which
+ *                            the gateway, or default router,
+ *                            configuration will be selected from @a
+ *                            data and used to unset the default route.
+ *  @param[in]      function  A pointer to an immutable null-terminated
+ *                            C string containing the function name to
+ *                            which the call to this function should
+ *                            be attributed.
+ *
  *
  *  @sa connman_inet_clear_gateway_address
  *  @sa connman_inet_clear_gateway_interface
@@ -1222,12 +1245,14 @@ static void set_default_gateway(struct gateway_data *data,
  *
  */
 static void unset_default_gateway(struct gateway_data *data,
-				enum connman_ipconfig_type type)
+				enum connman_ipconfig_type type,
+				const char *function)
 {
 	bool do_ipv4 = false, do_ipv6 = false;
 
-	DBG("data %p type %d (%s)", data,
-		type, __connman_ipconfig_type2string(type));
+	DBG("data %p type %d (%s) from %s()", data,
+		type, __connman_ipconfig_type2string(type),
+		function);
 
 	GATEWAY_DATA_DBG("data", data);
 
@@ -1356,7 +1381,7 @@ static bool yield_default_gateway(struct gateway_data *activated,
 				maybe_null(gateway_config_type2string(
 					config_type)));
 
-			unset_default_gateway(existing, type);
+			UNSET_DEFAULT_GATEWAY(existing, type);
 		}
 
 		/*
@@ -1375,7 +1400,7 @@ static bool yield_default_gateway(struct gateway_data *activated,
 				maybe_null(gateway_config_type2string(
 					config_type)));
 
-			unset_default_gateway(activated, type);
+			UNSET_DEFAULT_GATEWAY(activated, type);
 
 			yield_activated = true;
 		}
@@ -1402,7 +1427,7 @@ static bool yield_default_gateway(struct gateway_data *activated,
 				maybe_null(gateway_config_type2string(
 					config_type)));
 
-			unset_default_gateway(existing, type);
+			UNSET_DEFAULT_GATEWAY(existing, type);
 		}
 
 		/*
@@ -1421,7 +1446,7 @@ static bool yield_default_gateway(struct gateway_data *activated,
 				maybe_null(gateway_config_type2string(
 					config_type)));
 
-			unset_default_gateway(activated, type);
+			UNSET_DEFAULT_GATEWAY(activated, type);
 
 			yield_activated = true;
 		}
@@ -1490,11 +1515,11 @@ static void check_default_gateway(struct gateway_data *activated)
 
 	if (!yield_activated) {
 		if (activated->ipv4_config)
-			set_default_gateway(activated,
+			SET_DEFAULT_GATEWAY(activated,
 				CONNMAN_IPCONFIG_TYPE_IPV4);
 
 		if (activated->ipv6_config)
-			set_default_gateway(activated,
+			SET_DEFAULT_GATEWAY(activated,
 				CONNMAN_IPCONFIG_TYPE_IPV6);
 	}
 
@@ -1660,7 +1685,7 @@ static void connection_delgateway(int index, const char *gateway)
 	if (data) {
 		GATEWAY_DATA_DBG("data", data);
 
-		set_default_gateway(data, CONNMAN_IPCONFIG_TYPE_ALL);
+		SET_DEFAULT_GATEWAY(data, CONNMAN_IPCONFIG_TYPE_ALL);
 	}
 }
 
@@ -1836,7 +1861,7 @@ int __connman_connection_gateway_add(struct connman_service *service,
 	}
 
 	if (!any_active_gateway) {
-		set_default_gateway(new_gateway, type);
+		SET_DEFAULT_GATEWAY(new_gateway, type);
 		goto done;
 	}
 
@@ -1983,7 +2008,7 @@ void __connman_connection_gateway_remove(struct connman_service *service,
 		GATEWAY_DATA_DBG("default_data", data);
 
 		if (data)
-			set_default_gateway(data, type);
+			SET_DEFAULT_GATEWAY(data, type);
 	}
 }
 
@@ -2045,7 +2070,7 @@ bool __connman_connection_update_gateway(void)
 				is_gateway_config_state_active(
 					active_gateway->ipv4_config)) {
 
-			unset_default_gateway(active_gateway,
+			UNSET_DEFAULT_GATEWAY(active_gateway,
 						CONNMAN_IPCONFIG_TYPE_IPV4);
 			updated = true;
 		}
@@ -2054,7 +2079,7 @@ bool __connman_connection_update_gateway(void)
 				is_gateway_config_state_active(
 					active_gateway->ipv6_config)) {
 
-			unset_default_gateway(active_gateway,
+			UNSET_DEFAULT_GATEWAY(active_gateway,
 						CONNMAN_IPCONFIG_TYPE_IPV6);
 			updated = true;
 		}
@@ -2069,14 +2094,14 @@ bool __connman_connection_update_gateway(void)
 			(updated ||
 			!is_gateway_config_state_active(
 				default_gateway->ipv4_config)))
-			set_default_gateway(default_gateway,
+			SET_DEFAULT_GATEWAY(default_gateway,
 					CONNMAN_IPCONFIG_TYPE_IPV4);
 
 		if (default_gateway->ipv6_config &&
 			(updated ||
 			!is_gateway_config_state_active(
 				default_gateway->ipv6_config)))
-			set_default_gateway(default_gateway,
+			SET_DEFAULT_GATEWAY(default_gateway,
 					CONNMAN_IPCONFIG_TYPE_IPV6);
 	}
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 10/90] connection: Fix 'DBG' copy-and-paste typo.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (8 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 09/90] connection: Add function parameter to {un,}set_default_gateway Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 11/90] connection: Split '{un,}_default_gateway' IP-specific functions Grant Erickson
                   ` (82 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

This corrects an "ipv4" -> "ipv6" copy-and-paste typo in 'DBG'
statements in '{un,}set_default_gateway'.
---
 src/connection.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 6df29fe31aa9..ac0565c14257 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1197,7 +1197,7 @@ static void set_default_gateway(struct gateway_data *data,
 						data->ipv6_config->gateway);
 
 			DBG("set %p index %d gateway %s",
-				data, data->index, data->ipv4_config->gateway);
+				data, data->index, data->ipv6_config->gateway);
 		}
 
 		gateway_config_type_set(data->ipv6_config,
@@ -1317,7 +1317,7 @@ static void unset_default_gateway(struct gateway_data *data,
 						data->ipv6_config->gateway);
 
 			DBG("unset %p index %d gateway %s",
-				data, data->index, data->ipv4_config->gateway);
+				data, data->index, data->ipv6_config->gateway);
 		}
 	}
 }
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 11/90] connection: Split '{un,}_default_gateway' IP-specific functions.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (9 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 10/90] connection: Fix 'DBG' copy-and-paste typo Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 12/90] connection: Add 'DBG' to 'del_gateway_routes' Grant Erickson
                   ` (81 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

As this module is refactored, there are common patterns across both
set and unset as well as across IPv4 and IPv6.

To set the stage for further aligning these, split the core bodies of
'{un,}_default_gateway' into '{un,}set_ipv{4,6}_default_gateway',
leaving '{un,}_default_gateway' nearly identical.
---
 src/connection.c | 264 +++++++++++++++++++++++++++--------------------
 1 file changed, 150 insertions(+), 114 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index ac0565c14257..2c4c716560fe 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1079,6 +1079,94 @@ static int add_gateway(struct connman_service *service,
 	return err;
 }
 
+static int set_ipv4_default_gateway(struct gateway_data *data,
+				struct gateway_config *config)
+{
+	int err = 0;
+
+	if (is_gateway_config_vpn(config)) {
+		connman_inet_set_gateway_interface(data->index);
+
+		gateway_config_state_set(config,
+			CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
+
+		DBG("set %p index %d vpn %s index %d phy %s",
+			data, data->index, config->vpn_ip,
+			config->vpn_phy_index,
+			config->vpn_phy_ip);
+	} else if (is_ipv4_addr_any_str(config->gateway)) {
+		if (connman_inet_set_gateway_interface(
+					data->index) < 0)
+			goto done;
+
+		gateway_config_state_set(config,
+			CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
+
+		DBG("set %p index %d",
+			data, data->index);
+	} else {
+		err = __connman_inet_add_default_to_table(
+					RT_TABLE_MAIN,
+					data->index,
+					config->gateway);
+		if (err < 0)
+			goto done;
+
+		DBG("set %p index %d gateway %s",
+			data, data->index, config->gateway);
+	}
+
+	gateway_config_type_set(config,
+		CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT);
+
+done:
+	return err;
+}
+
+static int set_ipv6_default_gateway(struct gateway_data *data,
+				struct gateway_config *config)
+{
+	int err = 0;
+
+	if (is_gateway_config_vpn(config)) {
+		connman_inet_set_ipv6_gateway_interface(data->index);
+
+		gateway_config_state_set(config,
+			CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
+
+		DBG("set %p index %d vpn %s index %d phy %s",
+			data, data->index, config->vpn_ip,
+			config->vpn_phy_index,
+			config->vpn_phy_ip);
+	} else if (is_ipv6_addr_any_str(config->gateway)) {
+		if (connman_inet_set_ipv6_gateway_interface(
+					data->index) < 0)
+			goto done;
+
+		gateway_config_state_set(config,
+			CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
+
+		DBG("set %p index %d",
+			data, data->index);
+	} else {
+		err = __connman_inet_add_default_to_table(
+					RT_TABLE_MAIN,
+					data->index,
+					config->gateway);
+		if (err < 0)
+			goto done;
+
+		DBG("set %p index %d gateway %s",
+			data, data->index, config->gateway);
+	}
+
+	gateway_config_type_set(config,
+		CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT);
+
+done:
+	return err;
+}
+
 /**
  *  @brief
  *    Set, or assign, the gateway, or default route, for the specified
@@ -1134,82 +1222,80 @@ static void set_default_gateway(struct gateway_data *data,
 	else
 		return;
 
-	if (do_ipv4 && data->ipv4_config) {
-		if (is_gateway_config_vpn(data->ipv4_config)) {
-			connman_inet_set_gateway_interface(data->index);
+	if (do_ipv4 && data->ipv4_config)
+		status4 = set_ipv4_default_gateway(data, data->ipv4_config);
 
-			gateway_config_state_set(data->ipv4_config,
-				CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
+	if (do_ipv6 && data->ipv6_config)
+		status6 = set_ipv6_default_gateway(data, data->ipv6_config);
 
-			DBG("set %p index %d vpn %s index %d phy %s",
-				data, data->index, data->ipv4_config->vpn_ip,
-				data->ipv4_config->vpn_phy_index,
-				data->ipv4_config->vpn_phy_ip);
-		} else if (is_ipv4_addr_any_str(data->ipv4_config->gateway)) {
-			if (connman_inet_set_gateway_interface(
-						data->index) < 0)
-				return;
+	DBG("status4 %d (%s) status6 %d (%s)",
+		status4, strerror(-status4),
+		status6, strerror(-status6));
 
-			gateway_config_state_set(data->ipv4_config,
-				CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
+	if (status4 < 0 || status6 < 0)
+		return;
 
-			DBG("set %p index %d",
-				data, data->index);
-		} else {
-			status4 = __connman_inet_add_default_to_table(
-						RT_TABLE_MAIN,
-						data->index,
-						data->ipv4_config->gateway);
+	__connman_service_indicate_default(data->service);
+}
 
-			DBG("set %p index %d gateway %s",
-				data, data->index, data->ipv4_config->gateway);
-		}
+static void unset_ipv4_default_gateway(struct gateway_data *data,
+				struct gateway_config *config)
+{
+	if (is_gateway_config_vpn(config)) {
+		connman_inet_clear_gateway_interface(data->index);
 
-		gateway_config_type_set(data->ipv4_config,
-			CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT);
-	}
+		gateway_config_state_set(config,
+			CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
 
-	if (do_ipv6 && data->ipv6_config) {
-		if (is_gateway_config_vpn(data->ipv6_config)) {
-			connman_inet_set_ipv6_gateway_interface(data->index);
+		DBG("unset %p index %d vpn %s index %d phy %s",
+			data, data->index, config->vpn_ip,
+			config->vpn_phy_index,
+			config->vpn_phy_ip);
+	} else if (is_ipv4_addr_any_str(config->gateway)) {
+		connman_inet_clear_gateway_interface(data->index);
 
-			gateway_config_state_set(data->ipv6_config,
-				CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
+		gateway_config_state_set(config,
+			CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
 
-			DBG("set %p index %d vpn %s index %d phy %s",
-				data, data->index, data->ipv6_config->vpn_ip,
-				data->ipv6_config->vpn_phy_index,
-				data->ipv6_config->vpn_phy_ip);
-		} else if (is_ipv6_addr_any_str(data->ipv6_config->gateway)) {
-			if (connman_inet_set_ipv6_gateway_interface(
-						data->index) < 0)
-				return;
+		DBG("unset %p index %d",
+			data, data->index);
+	} else {
+		connman_inet_clear_gateway_address(data->index,
+					config->gateway);
 
-			gateway_config_state_set(data->ipv6_config,
-				CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
+		DBG("unset %p index %d gateway %s",
+			data, data->index, config->gateway);
+	}
+}
 
-			DBG("set %p index %d",
-				data, data->index);
-		} else {
-			status6 = __connman_inet_add_default_to_table(
-						RT_TABLE_MAIN,
-						data->index,
-						data->ipv6_config->gateway);
+static void unset_ipv6_default_gateway(struct gateway_data *data,
+				struct gateway_config *config)
+{
+	if (is_gateway_config_vpn(config)) {
+		connman_inet_clear_ipv6_gateway_interface(data->index);
 
-			DBG("set %p index %d gateway %s",
-				data, data->index, data->ipv6_config->gateway);
-		}
+		gateway_config_state_set(config,
+			CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
 
-		gateway_config_type_set(data->ipv6_config,
-			CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT);
-	}
+		DBG("unset %p index %d vpn %s index %d phy %s",
+			data, data->index, config->vpn_ip,
+			config->vpn_phy_index,
+			config->vpn_phy_ip);
+	} else if (is_ipv6_addr_any_str(config->gateway)) {
+		connman_inet_clear_ipv6_gateway_interface(data->index);
 
-	DBG("status4 %d status6 %d", status4, status6);
+		gateway_config_state_set(config,
+			CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
 
-	if (status4 < 0 || status6 < 0)
-		return;
+		DBG("unset %p index %d",
+			data, data->index);
+	} else {
+		connman_inet_clear_ipv6_gateway_address(data->index,
+					config->gateway);
 
-	__connman_service_indicate_default(data->service);
+		DBG("unset %p index %d gateway %s",
+			data, data->index, config->gateway);
+	}
 }
 
 /**
@@ -1265,61 +1351,11 @@ static void unset_default_gateway(struct gateway_data *data,
 	else
 		return;
 
-	if (do_ipv4 && data->ipv4_config) {
-		if (is_gateway_config_vpn(data->ipv4_config)) {
-			connman_inet_clear_gateway_interface(data->index);
-
-			gateway_config_state_set(data->ipv4_config,
-				CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
-
-			DBG("unset %p index %d vpn %s index %d phy %s",
-				data, data->index, data->ipv4_config->vpn_ip,
-				data->ipv4_config->vpn_phy_index,
-				data->ipv4_config->vpn_phy_ip);
-		} else if (is_ipv4_addr_any_str(data->ipv4_config->gateway)) {
-			connman_inet_clear_gateway_interface(data->index);
-
-			gateway_config_state_set(data->ipv4_config,
-				CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
-
-			DBG("unset %p index %d",
-				data, data->index);
-		} else {
-			connman_inet_clear_gateway_address(data->index,
-						data->ipv4_config->gateway);
-
-			DBG("unset %p index %d gateway %s",
-				data, data->index, data->ipv4_config->gateway);
-		}
-	}
-
-	if (do_ipv6 && data->ipv6_config) {
-		if (is_gateway_config_vpn(data->ipv6_config)) {
-			connman_inet_clear_ipv6_gateway_interface(data->index);
-
-			gateway_config_state_set(data->ipv6_config,
-				CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
-
-			DBG("unset %p index %d vpn %s index %d phy %s",
-				data, data->index, data->ipv6_config->vpn_ip,
-				data->ipv6_config->vpn_phy_index,
-				data->ipv6_config->vpn_phy_ip);
-		} else if (is_ipv6_addr_any_str(data->ipv6_config->gateway)) {
-			connman_inet_clear_ipv6_gateway_interface(data->index);
-
-			gateway_config_state_set(data->ipv6_config,
-				CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
-
-			DBG("unset %p index %d",
-				data, data->index);
-		} else {
-			connman_inet_clear_ipv6_gateway_address(data->index,
-						data->ipv6_config->gateway);
+	if (do_ipv4 && data->ipv4_config)
+		unset_ipv4_default_gateway(data, data->ipv4_config);
 
-			DBG("unset %p index %d gateway %s",
-				data, data->index, data->ipv6_config->gateway);
-		}
-	}
+	if (do_ipv6 && data->ipv6_config)
+		unset_ipv6_default_gateway(data, data->ipv6_config);
 }
 
 /**
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 12/90] connection: Add 'DBG' to 'del_gateway_routes'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (10 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 11/90] connection: Split '{un,}_default_gateway' IP-specific functions Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 13/90] connection: Rename 'active_gateway' local Grant Erickson
                   ` (80 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

To aid in debugging gateway route handling in multi-technology and
-service configurations, particularly during online check-driven
failover, add additional 'DBG' statements to 'del_gateway_routes'.
---
 src/connection.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 2c4c716560fe..d81ed8648175 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -833,6 +833,9 @@ static int del_gateway_routes(struct gateway_data *data,
 	int status4 = 0, status6 = 0;
 	bool do_ipv4 = false, do_ipv6 = false;
 
+	DBG("data %p type %d (%s)", data,
+		type, __connman_ipconfig_type2string(type));
+
 	GATEWAY_DATA_DBG("data", data);
 
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
@@ -880,6 +883,10 @@ static int del_gateway_routes(struct gateway_data *data,
 		}
 	}
 
+	DBG("status4 %d (%s) status6 %d (%s)",
+		status4, strerror(-status4),
+		status6, strerror(-status6));
+
 	return (status4 < 0 ? status4 : status6);
 }
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 13/90] connection: Rename 'active_gateway' local.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (11 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 12/90] connection: Add 'DBG' to 'del_gateway_routes' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 14/90] connection: Check 'service' parameter for null Grant Erickson
                   ` (79 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

In '__connman_connection_update_gateway' there is a local variable
inside a loop control block, 'active_gateway'. This renames this local
varable to 'current_gateway' to avoid any confusion with the term
"active" which has implications for the 'ACTIVE' gateway configuration
state, which is definitely not the case for this local.
---
 src/connection.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index d81ed8648175..e80443c02a5a 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2102,27 +2102,27 @@ bool __connman_connection_update_gateway(void)
 	g_hash_table_iter_init(&iter, gateway_hash);
 
 	while (g_hash_table_iter_next(&iter, &key, &value)) {
-		struct gateway_data *active_gateway = value;
+		struct gateway_data *current_gateway = value;
 
-		GATEWAY_DATA_DBG("active_gateway", active_gateway);
+		GATEWAY_DATA_DBG("current_gateway", current_gateway);
 
-		if (active_gateway == default_gateway)
+		if (current_gateway == default_gateway)
 			continue;
 
-		if (active_gateway->ipv4_config &&
+		if (current_gateway->ipv4_config &&
 				is_gateway_config_state_active(
-					active_gateway->ipv4_config)) {
+					current_gateway->ipv4_config)) {
 
-			UNSET_DEFAULT_GATEWAY(active_gateway,
+			UNSET_DEFAULT_GATEWAY(current_gateway,
 						CONNMAN_IPCONFIG_TYPE_IPV4);
 			updated = true;
 		}
 
-		if (active_gateway->ipv6_config &&
+		if (current_gateway->ipv6_config &&
 				is_gateway_config_state_active(
-					active_gateway->ipv6_config)) {
+					current_gateway->ipv6_config)) {
 
-			UNSET_DEFAULT_GATEWAY(active_gateway,
+			UNSET_DEFAULT_GATEWAY(current_gateway,
 						CONNMAN_IPCONFIG_TYPE_IPV6);
 			updated = true;
 		}
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 14/90] connection: Check 'service' parameter for null.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (12 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 13/90] connection: Rename 'active_gateway' local Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 15/90] connection: Check service network index for validity Grant Erickson
                   ` (78 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

In '__connman_connection_gateway_add', as an internal, cross-module
function, check that the 'service' parameter is not null. If it is,
return -EINVAL.
---
 src/connection.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index e80443c02a5a..e6a6ea42dc59 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1830,8 +1830,7 @@ int __connman_connection_gateway_add(struct connman_service *service,
 	struct gateway_data *new_gateway = NULL;
 	enum connman_ipconfig_type type4 = CONNMAN_IPCONFIG_TYPE_UNKNOWN,
 		type6 = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
-	enum connman_service_type service_type =
-					connman_service_get_type(service);
+	enum connman_service_type service_type;
 	int index;
 	g_autofree char *interface = NULL;
 	int err = 0;
@@ -1842,12 +1841,17 @@ int __connman_connection_gateway_add(struct connman_service *service,
 		type, __connman_ipconfig_type2string(type),
 		peer, maybe_null(peer));
 
+	if (!service)
+		return -EINVAL;
+
 	index = __connman_service_get_index(service);
 
 	interface = connman_inet_ifname(index);
 
 	DBG("index %d (%s)", index, maybe_null(interface));
 
+	service_type = connman_service_get_type(service);
+
 	/*
 	 * If gateway is NULL, it's a point to point link and the default
 	 * gateway for ipv4 is 0.0.0.0 and for ipv6 is ::, meaning the
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 15/90] connection: Check service network index for validity.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (13 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 14/90] connection: Check 'service' parameter for null Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 16/90] connection: Refactor '__connman_connection_gateway_add' Grant Erickson
                   ` (77 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

In '__connman_connection_gateway_add', the network interface index is
retrieved from the 'service' parameter; however, it is not checked for
validity. Since the index will go on and later populate the gateway
data, via 'add_gateway, ensure that the index is valid. If it is not,
return -EINVAL.
---
 src/connection.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index e6a6ea42dc59..d645078d85ee 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1845,6 +1845,8 @@ int __connman_connection_gateway_add(struct connman_service *service,
 		return -EINVAL;
 
 	index = __connman_service_get_index(service);
+	if (index < 0)
+		return -EINVAL;
 
 	interface = connman_inet_ifname(index);
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 16/90] connection: Refactor '__connman_connection_gateway_add'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (14 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 15/90] connection: Check service network index for validity Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 17/90] connection: Remove 'DBG' from '__connman_connection_update_gateway' Grant Erickson
                   ` (76 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

In '__connman_connection_gateway_add', there are only two allowable
values for the 'type' parameter among four total in the enumeration
for 'type'. Error-check against the two invalid values from that
enumeration and return -EINVAL for the invalid values.

In addition, use this check to set 'do_ipv4' and 'do_ipv6' local
Booleans (similar to other functions in the module) that allows for
simplifying the overall logic and flow of the function.
---
 src/connection.c | 54 ++++++++++++++++++++++++++----------------------
 1 file changed, 29 insertions(+), 25 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index d645078d85ee..354340f0ef87 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1828,11 +1828,11 @@ int __connman_connection_gateway_add(struct connman_service *service,
 {
 	struct gateway_data *any_active_gateway = NULL;
 	struct gateway_data *new_gateway = NULL;
-	enum connman_ipconfig_type type4 = CONNMAN_IPCONFIG_TYPE_UNKNOWN,
-		type6 = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
 	enum connman_service_type service_type;
 	int index;
 	g_autofree char *interface = NULL;
+	bool do_ipv4 = false, do_ipv6 = false;
+	bool is_vpn4 = false, is_vpn6 = false;
 	int err = 0;
 
 	DBG("service %p (%s) gateway %p (%s) type %d (%s) peer %p (%s)",
@@ -1844,6 +1844,13 @@ int __connman_connection_gateway_add(struct connman_service *service,
 	if (!service)
 		return -EINVAL;
 
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		do_ipv4 = true;
+	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+		do_ipv6 = true;
+	else
+		return -EINVAL;
+
 	index = __connman_service_get_index(service);
 	if (index < 0)
 		return -EINVAL;
@@ -1859,15 +1866,12 @@ int __connman_connection_gateway_add(struct connman_service *service,
 	 * gateway for ipv4 is 0.0.0.0 and for ipv6 is ::, meaning the
 	 * interface
 	 */
-	if (!gateway && type == CONNMAN_IPCONFIG_TYPE_IPV4)
+	if (!gateway && do_ipv4)
 		gateway = ipv4_addr_any_str;
 
-	if (!gateway && type == CONNMAN_IPCONFIG_TYPE_IPV6)
+	if (!gateway && do_ipv6)
 		gateway = ipv6_addr_any_str;
 
-	DBG("service %p index %d gateway %s vpn ip %s type %d",
-		service, index, gateway, peer, type);
-
 	err = add_gateway(service, index, gateway, type, &new_gateway);
 	if (err < 0)
 		return err;
@@ -1878,20 +1882,16 @@ int __connman_connection_gateway_add(struct connman_service *service,
 
 	GATEWAY_DATA_DBG("any_active_gateway", any_active_gateway);
 
-	if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
-				new_gateway->ipv4_config) {
+	if (do_ipv4 && new_gateway->ipv4_config) {
 		add_host_route(AF_INET, index, gateway, service_type);
 		__connman_service_nameserver_add_routes(service,
 					new_gateway->ipv4_config->gateway);
-		type4 = CONNMAN_IPCONFIG_TYPE_IPV4;
 	}
 
-	if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
-				new_gateway->ipv6_config) {
+	if (do_ipv6 && new_gateway->ipv6_config) {
 		add_host_route(AF_INET6, index, gateway, service_type);
 		__connman_service_nameserver_add_routes(service,
 					new_gateway->ipv6_config->gateway);
-		type6 = CONNMAN_IPCONFIG_TYPE_IPV6;
 	}
 
 	if (service_type == CONNMAN_SERVICE_TYPE_VPN) {
@@ -1899,13 +1899,21 @@ int __connman_connection_gateway_add(struct connman_service *service,
 		set_vpn_routes(new_gateway, service, gateway, type, peer,
 							any_active_gateway);
 
+		is_vpn4 = do_ipv4 &&
+					new_gateway->ipv4_config &&
+					is_gateway_config_vpn(
+						new_gateway->ipv4_config);
+
+		is_vpn6 = do_ipv4 &&
+					new_gateway->ipv4_config &&
+					is_gateway_config_vpn(
+						new_gateway->ipv4_config);
+
 	} else {
-		if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
-					new_gateway->ipv4_config)
+		if (do_ipv4 && new_gateway->ipv4_config)
 			gateway_config_clear_vpn(new_gateway->ipv4_config);
 
-		if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
-					new_gateway->ipv6_config)
+		if (do_ipv6 && new_gateway->ipv6_config)
 			gateway_config_clear_vpn(new_gateway->ipv6_config);
 	}
 
@@ -1914,18 +1922,14 @@ int __connman_connection_gateway_add(struct connman_service *service,
 		goto done;
 	}
 
-	if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
-			new_gateway->ipv4_config &&
-			is_gateway_config_vpn(new_gateway->ipv4_config)) {
+	if (is_vpn4) {
 		if (!__connman_service_is_split_routing(new_gateway->service))
 			connman_inet_clear_gateway_address(
 				any_active_gateway->index,
 				any_active_gateway->ipv4_config->gateway);
 	}
 
-	if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
-			new_gateway->ipv6_config &&
-			is_gateway_config_vpn(new_gateway->ipv6_config)) {
+	if (is_vpn6) {
 		if (!__connman_service_is_split_routing(new_gateway->service))
 			connman_inet_clear_ipv6_gateway_address(
 				any_active_gateway->index,
@@ -1933,12 +1937,12 @@ int __connman_connection_gateway_add(struct connman_service *service,
 	}
 
 done:
-	if (type4 == CONNMAN_IPCONFIG_TYPE_IPV4)
+	if (do_ipv4)
 		__connman_service_ipconfig_indicate_state(service,
 						CONNMAN_SERVICE_STATE_READY,
 						CONNMAN_IPCONFIG_TYPE_IPV4);
 
-	if (type6 == CONNMAN_IPCONFIG_TYPE_IPV6)
+	if (do_ipv6)
 		__connman_service_ipconfig_indicate_state(service,
 						CONNMAN_SERVICE_STATE_READY,
 						CONNMAN_IPCONFIG_TYPE_IPV6);
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 17/90] connection: Remove 'DBG' from '__connman_connection_update_gateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (15 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 16/90] connection: Refactor '__connman_connection_gateway_add' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 18/90] connection: Refactor 'yield_default_gateway' Grant Erickson
                   ` (75 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This removes a 'DBG' statement from
'__connman_connection_update_gateway' that is duplicative to the
'GATEWAY_DATA_DBG' that follows it.
---
 src/connection.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 354340f0ef87..ecb8e6b4037a 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2101,8 +2101,6 @@ bool __connman_connection_update_gateway(void)
 
 	default_gateway = find_default_gateway_data();
 
-	DBG("default_gateway %p", default_gateway);
-
 	GATEWAY_DATA_DBG("default_gateway", default_gateway);
 
 	/*
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 18/90] connection: Refactor 'yield_default_gateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (16 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 17/90] connection: Remove 'DBG' from '__connman_connection_update_gateway' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 19/90] connection: Document 'gateway_data_config_get' Grant Erickson
                   ` (74 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

The IPv4 and IPv6 sub-blocks of 'yield_default_gateway' are nearly-
identical and differ only in a parameterizable IP configuration type
value and the gateway configuration.

This adds a new function, 'gateway_data_config_get', that selects from
between the IPv4 and IPv6 gateway configuration pointers from gateway
data, using an IP configuration type parameter.

This then splits out those common blocks from 'yield_default_gateway'
into 'yield_defalt_gateway_for_type', passing the IP configuration
type parameter, and then leverages 'gateway_data_config_get' to select
the desired gateway configuration from the passed 'activated' and
'existing' gateway data.
---
 src/connection.c | 203 +++++++++++++++++++++++++----------------------
 1 file changed, 107 insertions(+), 96 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index ecb8e6b4037a..e328a929b306 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -394,6 +394,30 @@ static void gateway_data_debug(const char *function,
 	}
 }
 
+static struct gateway_config *gateway_data_config_get(struct gateway_data *data,
+				enum connman_ipconfig_type type)
+{
+	struct gateway_config *config = NULL;
+
+	if (!data)
+		return config;
+
+	switch (type) {
+	case CONNMAN_IPCONFIG_TYPE_IPV4:
+		config = data->ipv4_config;
+		break;
+	case CONNMAN_IPCONFIG_TYPE_IPV6:
+		config = data->ipv6_config;
+		break;
+	case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
+	case CONNMAN_IPCONFIG_TYPE_ALL:
+	default:
+		break;
+	}
+
+	return config;
+}
+
 /**
  *  @brief
  *    Determine whether the specified text-formatted IPv4 address is
@@ -1365,6 +1389,76 @@ static void unset_default_gateway(struct gateway_data *data,
 		unset_ipv6_default_gateway(data, data->ipv6_config);
 }
 
+static bool yield_default_gateway_for_type(struct gateway_data *activated,
+					struct gateway_data *existing,
+					enum connman_ipconfig_type type)
+{
+	static const enum gateway_config_type config_type =
+		CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT;
+	const struct gateway_config *const activated_config =
+		gateway_data_config_get(activated, type);
+	const struct gateway_config *const existing_config =
+		gateway_data_config_get(existing, type);
+	bool yield_activated = false;
+
+	DBG("activated data %p config %p "
+		"existing data %p config %p "
+		"type %d (%s)",
+		activated, activated_config,
+		existing, existing_config,
+		type, __connman_ipconfig_type2string(type));
+
+	/*
+	 * There is only an default gateway yield decision to be
+	 * considered if there is an gateway configuration for BOTH the
+	 * activated and existing gateway data.
+	 */
+	if (!activated_config || !existing_config)
+		goto done;
+
+	/*
+	 * If the existing gateway data IS NOT active (that is, HAS
+	 * NOT made it to the RTNL notification phase of its
+	 * lifecycle), then it yields the default gateway to the
+	 * activated gateway data.
+	 */
+	if (!is_gateway_config_state_active(existing_config)) {
+		DBG("%s existing %p yielding %s",
+			__connman_ipconfig_type2string(type),
+			existing,
+			maybe_null(gateway_config_type2string(
+				config_type)));
+
+		UNSET_DEFAULT_GATEWAY(existing, type);
+	}
+
+	/*
+	 * If the existing gateway data IS active (that is, HAS made
+	 * it to the RTNL notification phase of its lifecycle) and if
+	 * its associated service is more "senior" in the service sort
+	 * order, then the activated gateway data yields the default
+	 * gateway to the existing gateway data.
+	 */
+	if (is_gateway_config_state_active(existing_config) &&
+		__connman_service_compare(existing->service,
+				activated->service) < 0) {
+		DBG("%s activated %p yielding %s",
+			__connman_ipconfig_type2string(type),
+			activated,
+			maybe_null(gateway_config_type2string(
+				config_type)));
+
+		UNSET_DEFAULT_GATEWAY(activated, type);
+
+		yield_activated = true;
+	}
+
+	DBG("yield_activated %u", yield_activated);
+
+done:
+	return yield_activated;
+}
+
 /**
  *  @brief
  *    Decide whether either of the specified gateways should yield the
@@ -1393,109 +1487,26 @@ static void unset_default_gateway(struct gateway_data *data,
 static bool yield_default_gateway(struct gateway_data *activated,
 					struct gateway_data *existing)
 {
-	static const enum gateway_config_type config_type =
-		CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT;
-	enum connman_ipconfig_type type;
-	bool yield_activated = false;
-
-	DBG("activated %p existing %p", activated, existing);
+	bool yield_ipv4_activated = false, yield_ipv6_activated = false;
 
 	GATEWAY_DATA_DBG("activated", activated);
 	GATEWAY_DATA_DBG("existing", existing);
 
-	/*
-	 * There is only an IPv4 default gateway yield decision to be
-	 * considered if there is an IPv4 gateway configuration for BOTH
-	 * the activated and existing gateway data.
-	 */
-	if (activated->ipv4_config && existing->ipv4_config) {
-		type = CONNMAN_IPCONFIG_TYPE_IPV4;
-
-		/*
-		 * If the existing IPv4 gateway data IS NOT active (that is,
-		 * HAS NOT made it to the RTNL notification phase of its
-		 * lifecycle), then it yields the default gateway to the
-		 * activated gateway data.
-		 */
-		if (!is_gateway_config_state_active(existing->ipv4_config)) {
-			DBG("%s existing %p yielding %s",
-				__connman_ipconfig_type2string(type),
-				existing,
-				maybe_null(gateway_config_type2string(
-					config_type)));
-
-			UNSET_DEFAULT_GATEWAY(existing, type);
-		}
-
-		/*
-		 * If the existing IPv4 gateway data IS active (that is, HAS
-		 * made it to the RTNL notification phase of its lifecycle)
-		 * and if its associated service is more "senior" in the
-		 * service sort order, then the activated gateway data yields
-		 * the default gateway to the existing gateway data.
-		 */
-		if (is_gateway_config_state_active(existing->ipv4_config) &&
-				__connman_service_compare(existing->service,
-						activated->service) < 0) {
-			DBG("%s activated %p yielding %s",
-				__connman_ipconfig_type2string(type),
-				activated,
-				maybe_null(gateway_config_type2string(
-					config_type)));
-
-			UNSET_DEFAULT_GATEWAY(activated, type);
-
-			yield_activated = true;
-		}
-	}
-
-	/*
-	 * There is only an IPv6 default gateway yield decision to be
-	 * considered if there is an IPv6 gateway configuration for BOTH
-	 * the activated and existing gateway data.
-	 */
-	if (activated->ipv6_config && existing->ipv6_config) {
-		type = CONNMAN_IPCONFIG_TYPE_IPV6;
+	yield_ipv4_activated = yield_default_gateway_for_type(
+						activated,
+						existing,
+						CONNMAN_IPCONFIG_TYPE_IPV4);
 
-		/*
-		 * If the existing IPv6 gateway data IS NOT active (that is,
-		 * HAS NOT made it to the RTNL notification phase of its
-		 * lifecycle), then it yields the default gateway to the
-		 * activated gateway data.
-		 */
-		if (!is_gateway_config_state_active(existing->ipv6_config)) {
-			DBG("%s existing %p yielding %s",
-				__connman_ipconfig_type2string(type),
-				existing,
-				maybe_null(gateway_config_type2string(
-					config_type)));
-
-			UNSET_DEFAULT_GATEWAY(existing, type);
-		}
+	yield_ipv6_activated = yield_default_gateway_for_type(
+						activated,
+						existing,
+						CONNMAN_IPCONFIG_TYPE_IPV6);
 
-		/*
-		 * If the existing IPv6 gateway data IS active (that is, HAS
-		 * made it to the RTNL notification phase of its lifecycle)
-		 * and if its associated service is more "senior" in the
-		 * service sort order, then the activated gateway data yields
-		 * the default gateway to the existing gateway data.
-		 */
-		if (is_gateway_config_state_active(existing->ipv6_config) &&
-			__connman_service_compare(existing->service,
-					activated->service) < 0) {
-			DBG("%s activated %p yielding %s",
-				__connman_ipconfig_type2string(type),
-				activated,
-				maybe_null(gateway_config_type2string(
-					config_type)));
-
-			UNSET_DEFAULT_GATEWAY(activated, type);
-
-			yield_activated = true;
-		}
-	}
+	DBG("yield_ipv4_activated %u yield_ipv6_activated %u",
+		yield_ipv4_activated,
+		yield_ipv6_activated);
 
-	return yield_activated;
+	return yield_ipv4_activated || yield_ipv6_activated;
 }
 
 /**
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 19/90] connection: Document 'gateway_data_config_get'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (17 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 18/90] connection: Refactor 'yield_default_gateway' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 20/90] connection: Document 'yield_default_gateway_for_type' Grant Erickson
                   ` (73 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds documentation to the 'gateway_data_config_get' function.
---
 src/connection.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index e328a929b306..a89fec393960 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -394,6 +394,22 @@ static void gateway_data_debug(const char *function,
 	}
 }
 
+/**
+ *  @brief
+ *    Return the IP-specific gateway configuration for the specified
+ *    gateway data.
+ *
+ *  @param[in]  data  A pointer to the mutable gateway data for which
+ *                    the gateway configuration is to be returned,
+ *                    specific to @a type.
+ *  @param[in]  type  The IP configuration type for which the gateway
+ *                    configuration is to be returned.
+ *
+ *  @returns
+ *    The IP-specific gateway configuration for the specified gateway
+ *    data on success; otherwise, null.
+ *
+ */
 static struct gateway_config *gateway_data_config_get(struct gateway_data *data,
 				enum connman_ipconfig_type type)
 {
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 20/90] connection: Document 'yield_default_gateway_for_type'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (18 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 19/90] connection: Document 'gateway_data_config_get' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 21/90] connection: Add 'gateway_config_free' Grant Erickson
                   ` (72 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds documentation to the 'yield_default_gateway_for_type'
enumeration.
---
 src/connection.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/connection.c b/src/connection.c
index a89fec393960..72a82dd87f76 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1405,6 +1405,34 @@ static void unset_default_gateway(struct gateway_data *data,
 		unset_ipv6_default_gateway(data, data->ipv6_config);
 }
 
+/**
+ *  @brief
+ *    Decide whether either of the specified gateways should yield the
+ *    default gateway route.
+ *
+ *  This determines whether either of the specified gateway data
+ *  should yield the IP-specific default gateway route via
+ *  #unset_default_gateway. @a activated is a newly-activated gateway
+ *  from a Routing Netlink (rtnl) notification. @a existing is an
+ *  existing gateway from the services-to-gateway data hash.
+ *
+ *  @param[in,out]  activated  A pointer to a mutable newly-activated
+ *                             gateway.
+ *  @param[in,out]  existing   A pointer to a mutable existing
+ *                             gateway.
+ *  @param[in]      type       The IP configuration type for which
+ *                             gateway, or default router, is to be
+ *                             yielded.
+ *
+ *  @returns
+ *    True if @a activated yielded the IP-specific default gateway;
+ *    otherwise, false.
+ *
+ *  @sa __connman_service_compare
+ *  @sa unset_default_gateway
+ *  @sa yield_default_gateway
+ *
+ */
 static bool yield_default_gateway_for_type(struct gateway_data *activated,
 					struct gateway_data *existing,
 					enum connman_ipconfig_type type)
@@ -1492,12 +1520,13 @@ done:
  *                             gateway.
  *
  *  @returns
- *    True of @a activated yielded the default gateway; otherwise,
+ *    True if @a activated yielded the default gateway; otherwise,
  *    false.
  *
  *  @sa check_default_gateway
  *  @sa __connman_service_compare
  *  @sa unset_default_gateway
+ *  @sa yield_default_gateway_for_type
  *
  */
 static bool yield_default_gateway(struct gateway_data *activated,
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 21/90] connection: Add 'gateway_config_free'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (19 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 20/90] connection: Document 'yield_default_gateway_for_type' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 22/90] connection: Document 'gateway_config_free' Grant Erickson
                   ` (71 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

Since there are two identical instances of gateway configuration in
gateway data, introduce a function, 'gateway_config_free' to free
those instances rather than copying-and-pasting the logic to free them
twice in 'remove_gateway'.
---
 src/connection.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 72a82dd87f76..5b0f18627f40 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1698,27 +1698,27 @@ static void connection_newgateway(int index, const char *gateway)
 	check_default_gateway(data);
 }
 
+static void gateway_config_free(struct gateway_config *config)
+{
+	DBG("config %p", config);
+
+	if (config) {
+		g_free(config->gateway);
+		g_free(config->vpn_ip);
+		g_free(config->vpn_phy_ip);
+		g_free(config);
+	}
+}
+
 static void remove_gateway(gpointer user_data)
 {
 	struct gateway_data *data = user_data;
 
-	DBG("data %p", data);
-
 	GATEWAY_DATA_DBG("data", data);
 
-	if (data->ipv4_config) {
-		g_free(data->ipv4_config->gateway);
-		g_free(data->ipv4_config->vpn_ip);
-		g_free(data->ipv4_config->vpn_phy_ip);
-		g_free(data->ipv4_config);
-	}
+	gateway_config_free(data->ipv4_config);
 
-	if (data->ipv6_config) {
-		g_free(data->ipv6_config->gateway);
-		g_free(data->ipv6_config->vpn_ip);
-		g_free(data->ipv6_config->vpn_phy_ip);
-		g_free(data->ipv6_config);
-	}
+	gateway_config_free(data->ipv6_config);
 
 	connman_service_unref(data->service);
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 22/90] connection: Document 'gateway_config_free'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (20 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 21/90] connection: Add 'gateway_config_free' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 23/90] connection: Introduce and leverage 'mutate_default_gateway' Grant Erickson
                   ` (70 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds documentation to the 'gateway_config_free' function.
---
 src/connection.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 5b0f18627f40..f07974aee938 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1698,6 +1698,17 @@ static void connection_newgateway(int index, const char *gateway)
 	check_default_gateway(data);
 }
 
+/**
+ *  @brief
+ *    Deallocate gateway configuration resources.
+ *
+ *  This attempts to deallocate resources associated with the
+ *  specified gateway configuration.
+ *
+ *  @param[in,out]  config  A pointer to the mutable gateway
+ *                  configuration to deallocate.
+ *
+ */
 static void gateway_config_free(struct gateway_config *config)
 {
 	DBG("config %p", config);
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 23/90] connection: Introduce and leverage 'mutate_default_gateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (21 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 22/90] connection: Document 'gateway_config_free' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 24/90] connection: Document 'mutate_default_gateway_ops' Grant Erickson
                   ` (69 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

The bodies of '{un,}set_default_gateway' are nearly identical, aside
from the functions they call.

Factor out the common implementation into a new function,
'mutate_default_gateway' and pass in the functions they call via a new
structure, 'mutate_default_gateway_ops'.
---
 src/connection.c | 142 +++++++++++++++++++++++++++--------------------
 1 file changed, 83 insertions(+), 59 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index f07974aee938..0136754128d5 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -144,6 +144,13 @@ struct gateway_data {
 	bool default_checked;
 };
 
+struct mutate_default_gateway_ops {
+	int (*mutate_ipv4)(struct gateway_data *data,
+				struct gateway_config *config);
+	int (*mutate_ipv6)(struct gateway_data *data,
+				struct gateway_config *config);
+};
+
 /*
  * These are declared as 'const char *const' to effect an immutable
  * pointer to an immutable null-terminated character string such that
@@ -1126,7 +1133,48 @@ static int add_gateway(struct connman_service *service,
 	return err;
 }
 
-static int set_ipv4_default_gateway(struct gateway_data *data,
+static int mutate_default_gateway(struct gateway_data *data,
+				enum connman_ipconfig_type type,
+				const struct mutate_default_gateway_ops *ops,
+				const char *function)
+{
+	int status4 = 0, status6 = 0;
+	bool do_ipv4 = false, do_ipv6 = false;
+
+	DBG("data %p type %d (%s) ops %p from %s()", data,
+		type, __connman_ipconfig_type2string(type),
+		ops,
+		function);
+
+	if (!data || !ops || !function)
+		return -EINVAL;
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		do_ipv4 = true;
+	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+		do_ipv6 = true;
+	else if (type == CONNMAN_IPCONFIG_TYPE_ALL)
+		do_ipv4 = do_ipv6 = true;
+	else
+		return -EINVAL;
+
+	GATEWAY_DATA_DBG("data", data);
+
+	if (do_ipv4 && ops->mutate_ipv4 && data->ipv4_config)
+		status4 = ops->mutate_ipv4(data, data->ipv4_config);
+
+	if (do_ipv6 && ops->mutate_ipv6 && data->ipv6_config)
+		status6 = ops->mutate_ipv6(data, data->ipv6_config);
+
+	DBG("status4 %d (%s) status6 %d (%s)",
+		status4, strerror(-status4),
+		status6, strerror(-status6));
+
+	return (status4 < 0 ? status4 : status6);
+}
+
+static int set_ipv4_high_priority_default_gateway(
+				struct gateway_data *data,
 				struct gateway_config *config)
 {
 	int err = 0;
@@ -1170,7 +1218,8 @@ done:
 	return err;
 }
 
-static int set_ipv6_default_gateway(struct gateway_data *data,
+static int set_ipv6_high_priority_default_gateway(
+				struct gateway_data *data,
 				struct gateway_config *config)
 {
 	int err = 0;
@@ -1241,53 +1290,36 @@ done:
  *                            which the call to this function should
  *                            be attributed.
  *
- *  @sa __connman_inet_add_default_to_table
- *  @sa __connman_service_indicate_default
- *  @sa connman_inet_set_gateway_interface
- *  @sa connman_inet_set_ipv6_gateway_interface
+ *  @sa mutate_default_gateway
+ *  @sa set_ipv4_high_priority_default_gateway
+ *  @sa set_ipv6_high_priority_default_gateway
  *
  */
 static void set_default_gateway(struct gateway_data *data,
 				enum connman_ipconfig_type type,
 				const char *function)
 {
-	int status4 = 0, status6 = 0;
-	bool do_ipv4 = false, do_ipv6 = false;
-
-	DBG("data %p type %d (%s) from %s()", data,
-		type, __connman_ipconfig_type2string(type),
-		function);
+	static const struct mutate_default_gateway_ops ops = {
+		set_ipv4_high_priority_default_gateway,
+		set_ipv6_high_priority_default_gateway
+	};
+	int status = 0;
 
-	GATEWAY_DATA_DBG("data", data);
+	DBG("from %s()", function);
 
-	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
-		do_ipv4 = true;
-	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
-		do_ipv6 = true;
-	else if (type == CONNMAN_IPCONFIG_TYPE_ALL)
-		do_ipv4 = do_ipv6 = true;
-	else
-		return;
-
-	if (do_ipv4 && data->ipv4_config)
-		status4 = set_ipv4_default_gateway(data, data->ipv4_config);
-
-	if (do_ipv6 && data->ipv6_config)
-		status6 = set_ipv6_default_gateway(data, data->ipv6_config);
-
-	DBG("status4 %d (%s) status6 %d (%s)",
-		status4, strerror(-status4),
-		status6, strerror(-status6));
-
-	if (status4 < 0 || status6 < 0)
+	status = mutate_default_gateway(data, type, &ops, __func__);
+	if (status < 0)
 		return;
 
 	__connman_service_indicate_default(data->service);
 }
 
-static void unset_ipv4_default_gateway(struct gateway_data *data,
+static int unset_ipv4_high_priority_default_gateway(
+				struct gateway_data *data,
 				struct gateway_config *config)
 {
+	int err = 0;
+
 	if (is_gateway_config_vpn(config)) {
 		connman_inet_clear_gateway_interface(data->index);
 
@@ -1313,11 +1345,16 @@ static void unset_ipv4_default_gateway(struct gateway_data *data,
 		DBG("unset %p index %d gateway %s",
 			data, data->index, config->gateway);
 	}
+
+	return err;
 }
 
-static void unset_ipv6_default_gateway(struct gateway_data *data,
+static int unset_ipv6_high_priority_default_gateway(
+				struct gateway_data *data,
 				struct gateway_config *config)
 {
+	int err = 0;
+
 	if (is_gateway_config_vpn(config)) {
 		connman_inet_clear_ipv6_gateway_interface(data->index);
 
@@ -1343,6 +1380,8 @@ static void unset_ipv6_default_gateway(struct gateway_data *data,
 		DBG("unset %p index %d gateway %s",
 			data, data->index, config->gateway);
 	}
+
+	return err;
 }
 
 /**
@@ -1371,38 +1410,23 @@ static void unset_ipv6_default_gateway(struct gateway_data *data,
  *                            be attributed.
  *
  *
- *  @sa connman_inet_clear_gateway_address
- *  @sa connman_inet_clear_gateway_interface
- *  @sa connman_inet_clear_ipv6_gateway_address
- *  @sa connman_inet_clear_ipv6_gateway_interface
+ *  @sa mutate_default_gateway
+ *  @sa unset_ipv4_default_gateway
+ *  @sa unset_ipv6_default_gateway
  *
  */
 static void unset_default_gateway(struct gateway_data *data,
 				enum connman_ipconfig_type type,
 				const char *function)
 {
-	bool do_ipv4 = false, do_ipv6 = false;
+	static const struct mutate_default_gateway_ops ops = {
+		unset_ipv4_high_priority_default_gateway,
+		unset_ipv6_high_priority_default_gateway
+	};
 
-	DBG("data %p type %d (%s) from %s()", data,
-		type, __connman_ipconfig_type2string(type),
-		function);
-
-	GATEWAY_DATA_DBG("data", data);
+	DBG("from %s()", function);
 
-	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
-		do_ipv4 = true;
-	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
-		do_ipv6 = true;
-	else if (type == CONNMAN_IPCONFIG_TYPE_ALL)
-		do_ipv4 = do_ipv6 = true;
-	else
-		return;
-
-	if (do_ipv4 && data->ipv4_config)
-		unset_ipv4_default_gateway(data, data->ipv4_config);
-
-	if (do_ipv6 && data->ipv6_config)
-		unset_ipv6_default_gateway(data, data->ipv6_config);
+	mutate_default_gateway(data, type, &ops, __func__);
 }
 
 /**
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 24/90] connection: Document 'mutate_default_gateway_ops'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (22 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 23/90] connection: Introduce and leverage 'mutate_default_gateway' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 25/90] connection: Document 'mutate_default_gateway' Grant Erickson
                   ` (68 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

This adds documentation to the 'mutate_default_gateway_ops' structure.
---
 src/connection.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 0136754128d5..d78b3f0400a9 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -144,9 +144,43 @@ struct gateway_data {
 	bool default_checked;
 };
 
+/**
+ *	Function pointers to mutating (including, but not limited to,
+ *	adding/setting or clearing/deleting/removing routes) IPv4 and/or
+ *	IPv6 default gateways.
+ */
 struct mutate_default_gateway_ops {
+	/**
+	 *  An optional pointer to a function for mutating (including, but
+	 *  not limited to, adding/setting or clearing/deleting/removing
+	 *  routes) an IPv4 default gateway.
+	 *
+	 *  @param[in,out]  data    A pointer to the mutable IPv4 gateway
+	 *                          data to mutate.
+	 *  @param[in,out]  config  A pointer to the mutable IPv4 gateway
+	 *                          configuration to mutate.
+	 *
+	 *  @returns
+	 *    0 if successful; otherwise, < 0 on error.
+	 *
+	 */
 	int (*mutate_ipv4)(struct gateway_data *data,
 				struct gateway_config *config);
+
+	/**
+	 *  An optional pointer to a function for mutating (including, but
+	 *  not limited to, adding/setting or clearing/deleting/removing
+	 *  routes) an IPv6 default gateway.
+	 *
+	 *  @param[in,out]  data    A pointer to the mutable IPv6 gateway
+	 *                          data to mutate.
+	 *  @param[in,out]  config  A pointer to the mutable IPv6 gateway
+	 *                          configuration to mutate.
+	 *
+	 *  @returns
+	 *    0 if successful; otherwise, < 0 on error.
+	 *
+	 */
 	int (*mutate_ipv6)(struct gateway_data *data,
 				struct gateway_config *config);
 };
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 25/90] connection: Document 'mutate_default_gateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (23 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 24/90] connection: Document 'mutate_default_gateway_ops' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 26/90] connection: Add gateway config ADDED/REMOVED states Grant Erickson
                   ` (67 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

This adds documentation to the 'mutate_default_gateway' function.
---
 src/connection.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index d78b3f0400a9..532b8f06713c 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1167,6 +1167,31 @@ static int add_gateway(struct connman_service *service,
 	return err;
 }
 
+/**
+ *  @brief
+ *    Mutate the gateway for the specified IP configuration type for
+ *    the provided gateway data.
+ *
+ *  This attempts to mutate (including, but not limited to, adding/
+ *  setting or clearing/deleting/removing routes) the gateway for the
+ *  specified IP configuration type for the provided gateway data.
+ *
+ *  @param[in,out]  data      A pointer to the mutable gateway data
+ *                            to mutate.
+ *  @param[in]      type      The IP configuration type for which the
+ *                            gateway configuration will be selected
+ *                            from @a data and used for mutation.
+ *  @param[in]      ops       A pointer to the default gateway mutation
+ *                            operations to use for the mutation.
+ *  @param[in]      function  A pointer to an immutable null-terminated
+ *                            C string containing the function name to
+ *                            which the call to this function should
+ *                            be attributed.
+ *
+ *  @returns
+ *    0 if successful; otherwise, < 0 on error.
+ *
+ */
 static int mutate_default_gateway(struct gateway_data *data,
 				enum connman_ipconfig_type type,
 				const struct mutate_default_gateway_ops *ops,
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 26/90] connection: Add gateway config ADDED/REMOVED states.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (24 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 25/90] connection: Document 'mutate_default_gateway' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 27/90] connection: Add low-priority default gateway config type Grant Erickson
                   ` (66 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds two new gateway configuration lifecycle states: ADDED and
REMOVED.

ADDED indicates whether the gateway has been added, or set, to the
kernel but not acknowledged round-trip via a Routing Netlink (rtnl)
notification.

REMOVED indicates whether the gateway has been removed, or cleared,
from the kernel but not acknowledged round-trip via a Routing Netlink
(rtnl) notification.
---
 src/connection.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/connection.c b/src/connection.c
index 532b8f06713c..18ab007f0893 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -85,12 +85,24 @@ enum gateway_config_state {
 	 */
 	CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE = 0,
 
+	/**
+	 *	Indicates whether the gateway has been added, or set, to the
+	 *	kernel but not acknowledged round-trip.
+	 */
+	CONNMAN_GATEWAY_CONFIG_STATE_ADDED	  = 1,
+
 	/**
 	 *	Indicates whether the gateway, or default router, is added and
 	 *	acknowledged by the kernel through a Routing Netlink (rtnl)
 	 *	notification and, consequently, is active (that is, in use).
 	 */
-	CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE	  = 1
+	CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE	  = 2,
+
+	/**
+	 *	Indicates whether the gateway has been removed, or cleared,
+	 *	from the kernel but not acknowledged round-trip.
+	 */
+	CONNMAN_GATEWAY_CONFIG_STATE_REMOVED  = 3
 };
 
 /**
@@ -262,8 +274,12 @@ static const char *gateway_config_state2string(enum gateway_config_state state)
 	switch (state) {
 	case CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE:
 		return "inactive";
+	case CONNMAN_GATEWAY_CONFIG_STATE_ADDED:
+		return "added";
 	case CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE:
 		return "active";
+	case CONNMAN_GATEWAY_CONFIG_STATE_REMOVED:
+		return "removed";
 	}
 
 	return NULL;
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 27/90] connection: Add low-priority default gateway config type.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (25 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 26/90] connection: Add gateway config ADDED/REMOVED states Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 28/90] connection: Change return type of 'unset_default_gateway' Grant Erickson
                   ` (65 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds a low-priority gateway default route type as a parallel peer
to the existing high-priority type.
---
 src/connection.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/connection.c b/src/connection.c
index 18ab007f0893..5091a229b4d1 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -119,7 +119,13 @@ enum gateway_config_type {
 	 *	Indicates the gateway, or default router, is a high-priority
 	 *	(that is, metric 0) default route.
 	 */
-	CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT = 1
+	CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT = 1,
+
+	/**
+	 *	Indicates the gateway, or default router, is a low-priority
+	 *	(that is, metric > 0) default route.
+	 */
+	CONNMAN_GATEWAY_CONFIG_TYPE_LOW_PRIORITY_DEFAULT  = 2
 };
 
 struct gateway_config {
@@ -292,6 +298,8 @@ static const char *gateway_config_type2string(enum gateway_config_type type)
 		return "none";
 	case CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT:
 		return "high-priority default";
+	case CONNMAN_GATEWAY_CONFIG_TYPE_LOW_PRIORITY_DEFAULT:
+		return "low-priority default";
 	}
 
 	return NULL;
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 28/90] connection: Change return type of 'unset_default_gateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (26 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 27/90] connection: Add low-priority default gateway config type Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 29/90] connection: Leverage 'unset_default_gateway' in 'del_gateway_routes' Grant Erickson
                   ` (64 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This changes the return signature of 'unset_default_gateway' from
'void' to 'int' such that its status can be leveraged for conditional
execution where it is called.
---
 src/connection.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 5091a229b4d1..179649a714bd 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1493,12 +1493,15 @@ static int unset_ipv6_high_priority_default_gateway(
  *                            be attributed.
  *
  *
+ * @returns
+ *   0 if successful; otherwise, < 0 on error.
+ *
  *  @sa mutate_default_gateway
  *  @sa unset_ipv4_default_gateway
  *  @sa unset_ipv6_default_gateway
  *
  */
-static void unset_default_gateway(struct gateway_data *data,
+static int unset_default_gateway(struct gateway_data *data,
 				enum connman_ipconfig_type type,
 				const char *function)
 {
@@ -1509,7 +1512,7 @@ static void unset_default_gateway(struct gateway_data *data,
 
 	DBG("from %s()", function);
 
-	mutate_default_gateway(data, type, &ops, __func__);
+	return mutate_default_gateway(data, type, &ops, __func__);
 }
 
 /**
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 29/90] connection: Leverage 'unset_default_gateway' in 'del_gateway_routes'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (27 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 28/90] connection: Change return type of 'unset_default_gateway' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 30/90] connection: Change return type of 'set_default_gateway' Grant Erickson
                   ` (63 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

Much of the logic in 'del_gateway_routes' is otherwise identical to
that of 'unset_default_gateway'. However, it side steps managing the
gateway state, type, and flags state, potentially leaving
inconsistencies.

Rather than this separate-but-equal existence, simply leverage
'unset_default_gateway' in 'del_gateway_routes'.
---
 src/connection.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 179649a714bd..702e08dbe37c 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -203,6 +203,10 @@ struct mutate_default_gateway_ops {
 				struct gateway_config *config);
 };
 
+static int unset_default_gateway(struct gateway_data *data,
+				enum connman_ipconfig_type type,
+				const char *function);
+
 /*
  * These are declared as 'const char *const' to effect an immutable
  * pointer to an immutable null-terminated character string such that
@@ -958,15 +962,12 @@ static int del_gateway_routes(struct gateway_data *data,
 						data->index,
 						data->ipv4_config->vpn_ip);
 
-		} else if (is_ipv4_addr_any_str(data->ipv4_config->gateway)) {
-			status4 = connman_inet_clear_gateway_interface(
-								data->index);
 		} else {
 			connman_inet_del_host_route(data->index,
 						data->ipv4_config->gateway);
-			status4 = connman_inet_clear_gateway_address(
-						data->index,
-						data->ipv4_config->gateway);
+
+			status4 = UNSET_DEFAULT_GATEWAY(data, type);
+
 		}
 	}
 
@@ -976,15 +977,12 @@ static int del_gateway_routes(struct gateway_data *data,
 						data->index,
 						data->ipv6_config->vpn_ip);
 
-		} else if (is_ipv6_addr_any_str(data->ipv6_config->gateway)) {
-			status6 = connman_inet_clear_ipv6_gateway_interface(
-								data->index);
 		} else {
 			connman_inet_del_ipv6_host_route(data->index,
 						data->ipv6_config->gateway);
-			status6 = connman_inet_clear_ipv6_gateway_address(
-						data->index,
-						data->ipv6_config->gateway);
+
+			status6 = UNSET_DEFAULT_GATEWAY(data, type);
+
 		}
 	}
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 30/90] connection: Change return type of 'set_default_gateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (28 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 29/90] connection: Leverage 'unset_default_gateway' in 'del_gateway_routes' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 31/90] connection: Fan out route manipulation into callbacks Grant Erickson
                   ` (62 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This changes the return signature of 'set_default_gateway' from
'void' to 'int' such that its status can be leveraged for conditional
execution where it is called.
---
 src/connection.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 702e08dbe37c..2a21e476bc53 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1371,12 +1371,15 @@ done:
  *                            which the call to this function should
  *                            be attributed.
  *
+ * @returns
+ *   0 if successful; otherwise, < 0 on error.
+ *
  *  @sa mutate_default_gateway
  *  @sa set_ipv4_high_priority_default_gateway
  *  @sa set_ipv6_high_priority_default_gateway
  *
  */
-static void set_default_gateway(struct gateway_data *data,
+static int set_default_gateway(struct gateway_data *data,
 				enum connman_ipconfig_type type,
 				const char *function)
 {
@@ -1390,9 +1393,12 @@ static void set_default_gateway(struct gateway_data *data,
 
 	status = mutate_default_gateway(data, type, &ops, __func__);
 	if (status < 0)
-		return;
+		goto done;
 
 	__connman_service_indicate_default(data->service);
+
+done:
+	return status;
 }
 
 static int unset_ipv4_high_priority_default_gateway(
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 31/90] connection: Fan out route manipulation into callbacks.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (29 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 30/90] connection: Change return type of 'set_default_gateway' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 32/90] connection: Document 'mutate_default_gateway_route_cb_t' Grant Erickson
                   ` (61 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

There is an appreciable amount of boilerplate copied-and-pasted among
the four set/unset IPv4/IPv6 gateway default route mutation functions.

This introduces two new functions to handle that common boilerplate:
'set_default_gateway_route_common' and
'unset_default_gateway_route_common' and introduces a new function
pointer, 'mutate_default_gateway_route_cb_t' that they take as a
parameter.

The four remaining set/unset IPv4/IPv6 gateway default route mutation
functions are then solely responsible only for making additions or
deletions to the routing table(s).
---
 src/connection.c | 101 ++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 91 insertions(+), 10 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 2a21e476bc53..1bcf16dee616 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -203,6 +203,9 @@ struct mutate_default_gateway_ops {
 				struct gateway_config *config);
 };
 
+typedef int (*mutate_default_gateway_route_cb_t)(struct gateway_data *data,
+				struct gateway_config *config);
+
 static int unset_default_gateway(struct gateway_data *data,
 				enum connman_ipconfig_type type,
 				const char *function);
@@ -1254,7 +1257,45 @@ static int mutate_default_gateway(struct gateway_data *data,
 	return (status4 < 0 ? status4 : status6);
 }
 
-static int set_ipv4_high_priority_default_gateway(
+static int set_default_gateway_route_common(struct gateway_data *data,
+				struct gateway_config *config,
+				enum gateway_config_type type,
+				mutate_default_gateway_route_cb_t cb)
+{
+	int err = 0;
+
+	if (!data || !config || !cb)
+		return -EINVAL;
+
+	err = cb(data, config);
+	if (err < 0)
+		goto done;
+
+	gateway_config_type_set(config, type);
+
+done:
+	return err;
+}
+
+static int unset_default_gateway_route_common(struct gateway_data *data,
+				struct gateway_config *config,
+				enum gateway_config_type type,
+				mutate_default_gateway_route_cb_t cb)
+{
+	int err = 0;
+
+	if (!data || !config || !cb)
+		return -EINVAL;
+
+	err = cb(data, config);
+	if (err < 0)
+		goto done;
+
+done:
+	return err;
+}
+
+static int set_ipv4_high_priority_default_gateway_route_cb(
 				struct gateway_data *data,
 				struct gateway_config *config)
 {
@@ -1292,14 +1333,11 @@ static int set_ipv4_high_priority_default_gateway(
 			data, data->index, config->gateway);
 	}
 
-	gateway_config_type_set(config,
-		CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT);
-
 done:
 	return err;
 }
 
-static int set_ipv6_high_priority_default_gateway(
+static int set_ipv6_high_priority_default_gateway_route_cb(
 				struct gateway_data *data,
 				struct gateway_config *config)
 {
@@ -1337,13 +1375,32 @@ static int set_ipv6_high_priority_default_gateway(
 			data, data->index, config->gateway);
 	}
 
-	gateway_config_type_set(config,
-		CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT);
-
 done:
 	return err;
 }
 
+static int set_ipv4_high_priority_default_gateway(struct gateway_data *data,
+				struct gateway_config *config)
+{
+	static const enum gateway_config_type type =
+			CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT;
+	static const mutate_default_gateway_route_cb_t cb =
+			set_ipv4_high_priority_default_gateway_route_cb;
+
+	return set_default_gateway_route_common(data, config, type, cb);
+}
+
+static int set_ipv6_high_priority_default_gateway(struct gateway_data *data,
+				struct gateway_config *config)
+{
+	static const enum gateway_config_type type =
+			CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT;
+	static const mutate_default_gateway_route_cb_t cb =
+			set_ipv6_high_priority_default_gateway_route_cb;
+
+	return set_default_gateway_route_common(data, config, type, cb);
+}
+
 /**
  *  @brief
  *    Set, or assign, the gateway, or default route, for the specified
@@ -1401,7 +1458,7 @@ done:
 	return status;
 }
 
-static int unset_ipv4_high_priority_default_gateway(
+static int unset_ipv4_high_priority_default_gateway_route_cb(
 				struct gateway_data *data,
 				struct gateway_config *config)
 {
@@ -1436,7 +1493,7 @@ static int unset_ipv4_high_priority_default_gateway(
 	return err;
 }
 
-static int unset_ipv6_high_priority_default_gateway(
+static int unset_ipv6_high_priority_default_gateway_route_cb(
 				struct gateway_data *data,
 				struct gateway_config *config)
 {
@@ -1471,6 +1528,30 @@ static int unset_ipv6_high_priority_default_gateway(
 	return err;
 }
 
+static int unset_ipv4_high_priority_default_gateway(
+				struct gateway_data *data,
+				struct gateway_config *config)
+{
+	static const enum gateway_config_type type =
+			CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT;
+	static const mutate_default_gateway_route_cb_t cb =
+			unset_ipv4_high_priority_default_gateway_route_cb;
+
+	return unset_default_gateway_route_common(data, config, type, cb);
+}
+
+static int unset_ipv6_high_priority_default_gateway(
+				struct gateway_data *data,
+				struct gateway_config *config)
+{
+	static const enum gateway_config_type type =
+			CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT;
+	static const mutate_default_gateway_route_cb_t cb =
+			unset_ipv6_high_priority_default_gateway_route_cb;
+
+	return unset_default_gateway_route_common(data, config, type, cb);
+}
+
 /**
  *  @brief
  *    Unset the gateway, or default route, for the specified IP
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 32/90] connection: Document 'mutate_default_gateway_route_cb_t'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (30 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 31/90] connection: Fan out route manipulation into callbacks Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 33/90] connection: Document 'set_default_gateway_route_common' Grant Erickson
                   ` (60 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

This adds documentation to the 'mutate_default_gateway_route_cb_t'
typedef.
---
 src/connection.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 1bcf16dee616..53563d057ab3 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -203,6 +203,23 @@ struct mutate_default_gateway_ops {
 				struct gateway_config *config);
 };
 
+/**
+ *  Prototype for a function callback to mutate (that is, add/set or
+ *  clear/delete/remove) a default route for a gateway using a function
+ *  utilizing a SIOCADDRT / SIOCDELRT socket ioctl or a RTM_NEWROUTE /
+ *  RTM_DELROUTE Linux Routing Netlink (rtnl) command to modify the Linux
+ *  routing table.
+ *
+ *  @param[in,out]  data    A pointer to the mutable gateway data to
+ *                          use to mutate the default route.
+ *  @param[in,out]  config  A pointer to the mutable gateway
+ *                          configuration to use to mutate the
+ *                          default route.
+ *
+ *  @returns
+ *    0 if successful; otherwise, < 0 on error.
+ *
+ */
 typedef int (*mutate_default_gateway_route_cb_t)(struct gateway_data *data,
 				struct gateway_config *config);
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 33/90] connection: Document 'set_default_gateway_route_common'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (31 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 32/90] connection: Document 'mutate_default_gateway_route_cb_t' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 34/90] connection: Document 'unset_default_gateway_route_common' Grant Erickson
                   ` (59 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

This adds documentation to the 'set_default_gateway_route_common'
function.
---
 src/connection.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 53563d057ab3..6dcb93f887ca 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1274,6 +1274,51 @@ static int mutate_default_gateway(struct gateway_data *data,
 	return (status4 < 0 ? status4 : status6);
 }
 
+/**
+ *  @brief
+ *    Set, or add, the default route, for the specified gateway data
+ *    and configuration using the provided gateway configuration type
+ *    and callback function.
+ *
+ *  This attempts to set, or add, the default route for the specified
+ *  gateway data and configuration using the provided gateway
+ *  configuration type and callback function.
+ *
+ *  On success, the gateway configuration type will be set to @a type
+ *  and its state to #CONNMAN_GATEWAY_CONFIG_STATE_ADDED.
+ *
+ *  @param[in,out]  data    A pointer to the mutable gateway data to
+ *                          set, or add, as the default route.
+ *  @param[in,out]  config  A pointer to the mutable gateway
+ *                          configuration to set, or add, as the
+ *                          default route.
+ *  @param[in]      type    The gateway configuration type that will
+ *                          be assigned to @a config on success.
+ *  @param[in]      cb      The callback function used to set, or
+ *                          add, the default route.
+ *
+ *  @retval  0              If successful.
+ *  @retval  -EINVAL        If @a data, @a config, or @a cb are
+ *                          null; if the gateway configuration type is
+ *                          not #CONNMAN_GATEWAY_CONFIG_TYPE_NONE or
+ *                          @a type; or if the routing information to
+ *                          be set, or added, was invalid.
+ *  @retval  -EINPROGRESS   If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_ADDED.
+ *  @retval  -EALREADY      If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE.
+ *  @retval  -EFAULT        If the address to the routing information
+ *                          to be set, or added, was invalid.
+ *  @retval  -EPERM         If the current process does not have the
+ *                          credentials or capabilities to set, or
+ *                          add, routes.
+ *  @retval  -EEXIST        A request was made to add an existing
+ *                          routing entry.
+ *
+ *  @sa gateway_config_type_set
+ *  @sa unset_default_gateway_route_common
+ *
+ */
 static int set_default_gateway_route_common(struct gateway_data *data,
 				struct gateway_config *config,
 				enum gateway_config_type type,
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 34/90] connection: Document 'unset_default_gateway_route_common'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (32 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 33/90] connection: Document 'set_default_gateway_route_common' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 35/90] inet: Add '__connman_inet_table2string' Grant Erickson
                   ` (58 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

This adds documentation to the 'unset_default_gateway_route_common'
function.
---
 src/connection.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 6dcb93f887ca..f29f42870cdf 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1339,6 +1339,49 @@ done:
 	return err;
 }
 
+/**
+ *  @brief
+ *    Unset, or remove, the default route, for the specified gateway
+ *    data and configuration using the provided gateway configuration
+ *    type and callback function.
+ *
+ *  This attempts to unset, or remove, the default route for the
+ *  specified gateway data and configuration using the provided
+ *  gateway configuration type and callback function.
+ *
+ *  On success, the gateway configuration state will be set to
+ *  #CONNMAN_GATEWAY_CONFIG_STATE_REMOVED.
+ *
+ *  @param[in,out]  data    A pointer to the mutable gateway data to
+ *                          unset, or remove, as the default route.
+ *  @param[in,out]  config  A pointer to the mutable gateway
+ *                          configuration to unset, or remove, as the
+ *                          default route.
+ *  @param[in]      type    The gateway configuration type that @a
+ *                          config is expected to be.
+ *  @param[in]      cb      The callback function used to unset, or
+ *                          remove, the default route.
+ *
+ *  @retval  0              If successful.
+ *  @retval  -EINVAL        If @a data, @a config, or @a cb are
+ *                          null; if the gateway configuration type is
+ *                          not @a type; or if the routing information
+ *                          to be unset, or cleared, was invalid.
+ *  @retval  -EINPROGRESS   If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_REMOVED.
+ *  @retval  -EALREADY      If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE.
+ *  @retval  -EFAULT        If the address to the routing information
+ *                          to be unset, or cleared, was invalid.
+ *  @retval  -EPERM         If the current process does not have the
+ *                          credentials or capabilities to unset, or
+ *                          clear, routes.
+ *  @retval  -ESRCH         A request was made to unset, or clear a
+ *                          non-existing routing entry.
+ *
+ *  @sa set_default_gateway_route_common
+ *
+ */
 static int unset_default_gateway_route_common(struct gateway_data *data,
 				struct gateway_config *config,
 				enum gateway_config_type type,
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 35/90] inet: Add '__connman_inet_table2string'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (33 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 34/90] connection: Document 'unset_default_gateway_route_common' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:49 ` [PATCH 36/90] inet: Document '__connman_inet_table2string' Grant Erickson
                   ` (57 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

This adds the function '__connman_inet_table2string', which returns a
null-terminated C string describing a Linux Routing Netlink (rtnl)
routing table identifier.
---
 src/connman.h |  2 ++
 src/inet.c    | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/src/connman.h b/src/connman.h
index 6b86be6f5ab3..19de86346565 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -174,6 +174,8 @@ int __connman_inet_get_interface_mac_address(int index, uint8_t *mac_address);
 
 bool __connman_inet_is_any_addr(const char *address, int family);
 
+const char *__connman_inet_table2string(uint32_t table_id);
+
 #include <netinet/ip6.h>
 #include <netinet/icmp6.h>
 
diff --git a/src/inet.c b/src/inet.c
index 3465d50cc84b..3d40f8d09e82 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -256,6 +256,24 @@ out:
 	return ret;
 }
 
+const char *__connman_inet_table2string(uint32_t table_id)
+{
+	switch (table_id) {
+	case RT_TABLE_UNSPEC:
+		return "unspecified";
+	case RT_TABLE_COMPAT:
+		return "compat";
+	case RT_TABLE_DEFAULT:
+		return "default";
+	case RT_TABLE_MAIN:
+		return "main";
+	case RT_TABLE_LOCAL:
+		return "local";
+	}
+
+	return "";
+}
+
 int connman_inet_ifindex(const char *name)
 {
 	struct ifreq ifr;
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 36/90] inet: Document '__connman_inet_table2string'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (34 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 35/90] inet: Add '__connman_inet_table2string' Grant Erickson
@ 2023-12-06 23:49 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 37/90] inet: Leverage '__connman_inet_table2string' Grant Erickson
                   ` (56 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:49 UTC (permalink / raw)
  To: connman

This adds documentation to the '__connman_inet_table2string'
function.
---
 src/inet.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/inet.c b/src/inet.c
index 3d40f8d09e82..74a5a78619b9 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -256,6 +256,23 @@ out:
 	return ret;
 }
 
+/**
+ *  @brief
+ *    Return a string describing a Linux Routing Netlink (rtnl)
+ *    routing table identifier.
+ *
+ *  This returns a null-terminated C string describing a Linux Routing
+ *  Netlink (rtnl) routing table identifier.
+ *
+ *  @param[in]  table_id   The Linux Routing Netlink (rtnl) routing
+ *                         table identifier for which to return a
+ *                         descriptive string.
+ *
+ *  @returns
+ *    A pointer to a immutable null-terminated C string describing @a
+ *    table_id on success; otherwise, an empty string ("").
+ *
+ */
 const char *__connman_inet_table2string(uint32_t table_id)
 {
 	switch (table_id) {
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 37/90] inet: Leverage '__connman_inet_table2string'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (35 preceding siblings ...)
  2023-12-06 23:49 ` [PATCH 36/90] inet: Document '__connman_inet_table2string' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 38/90] rtnl: Add support for extracting the table identifier Grant Erickson
                   ` (55 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This leverages '__connman_inet_table2string' when logging the Routing
Netlink (rtnl) table identifier in 'iproute_default_modify'.
---
 src/inet.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/inet.c b/src/inet.c
index 74a5a78619b9..e135d1ad3cae 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -3205,7 +3205,9 @@ static int iproute_default_modify(int cmd, uint32_t table_id, int ifindex,
 	int family = connman_inet_check_ipaddress(gateway);
 	char *dst = NULL;
 
-	DBG("gateway %s/%u table %u", gateway, prefixlen, table_id);
+	DBG("gateway %s/%u table %u <%s>",
+		gateway, prefixlen,
+		table_id, __connman_inet_table2string(table_id));
 
 	switch (family) {
 	case AF_INET:
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 38/90] rtnl: Add support for extracting the table identifier.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (36 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 37/90] inet: Leverage '__connman_inet_table2string' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 39/90] ipconfig: Pass the rtnl table to '__connman_ipconfig_{new,del}route' Grant Erickson
                   ` (54 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds support for extracting the Routing Netlink (rtnl) table
identifier attribute from rtnl messages.
---
 src/rtnl.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/rtnl.c b/src/rtnl.c
index e8a8325ee22b..056107831038 100644
--- a/src/rtnl.c
+++ b/src/rtnl.c
@@ -670,7 +670,8 @@ static void process_deladdr(unsigned char family, unsigned char prefixlen,
 
 static void extract_ipv4_route(struct rtmsg *msg, int bytes, int *index,
 						struct in_addr *dst,
-						struct in_addr *gateway)
+						struct in_addr *gateway,
+						uint32_t *table_id)
 {
 	struct rtattr *attr;
 
@@ -689,13 +690,18 @@ static void extract_ipv4_route(struct rtmsg *msg, int bytes, int *index,
 			if (index)
 				*index = *((int *) RTA_DATA(attr));
 			break;
+		case RTA_TABLE:
+			if (table_id)
+				*table_id = *((uint32_t *) RTA_DATA(attr));
+			break;
 		}
 	}
 }
 
 static void extract_ipv6_route(struct rtmsg *msg, int bytes, int *index,
 						struct in6_addr *dst,
-						struct in6_addr *gateway)
+						struct in6_addr *gateway,
+						uint32_t *table_id)
 {
 	struct rtattr *attr;
 
@@ -715,6 +721,10 @@ static void extract_ipv6_route(struct rtmsg *msg, int bytes, int *index,
 			if (index)
 				*index = *((int *) RTA_DATA(attr));
 			break;
+		case RTA_TABLE:
+			if (table_id)
+				*table_id = *((uint32_t *) RTA_DATA(attr));
+			break;
 		}
 	}
 }
@@ -729,7 +739,8 @@ static void process_newroute(unsigned char family, unsigned char scope,
 	if (family == AF_INET) {
 		struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
 
-		extract_ipv4_route(msg, bytes, &index, &dst, &gateway);
+		extract_ipv4_route(msg, bytes, &index, &dst, &gateway,
+			NULL);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
@@ -749,7 +760,8 @@ static void process_newroute(unsigned char family, unsigned char scope,
 		struct in6_addr dst = IN6ADDR_ANY_INIT,
 				gateway = IN6ADDR_ANY_INIT;
 
-		extract_ipv6_route(msg, bytes, &index, &dst, &gateway);
+		extract_ipv6_route(msg, bytes, &index, &dst, &gateway,
+			NULL);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
@@ -786,7 +798,8 @@ static void process_delroute(unsigned char family, unsigned char scope,
 	if (family == AF_INET) {
 		struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
 
-		extract_ipv4_route(msg, bytes, &index, &dst, &gateway);
+		extract_ipv4_route(msg, bytes, &index, &dst, &gateway,
+			NULL);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
@@ -806,7 +819,8 @@ static void process_delroute(unsigned char family, unsigned char scope,
 		struct in6_addr dst = IN6ADDR_ANY_INIT,
 				gateway = IN6ADDR_ANY_INIT;
 
-		extract_ipv6_route(msg, bytes, &index, &dst, &gateway);
+		extract_ipv6_route(msg, bytes, &index, &dst, &gateway,
+			NULL);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 39/90] ipconfig: Pass the rtnl table to '__connman_ipconfig_{new,del}route'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (37 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 38/90] rtnl: Add support for extracting the table identifier Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 39/90] ipconfig: Pass the rtnl table to " Grant Erickson
                   ` (53 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds support for extracting and passing the Routing Netlink
(rtnl) table identifier to '__connman_ipconfig_{new,del}route' from
'process_{new,del}route'.
---
 src/connman.h  |  6 ++++--
 src/ipconfig.c | 16 ++++++++++------
 src/rtnl.c     | 22 ++++++++++++++--------
 3 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index 19de86346565..35f11e92ac3c 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -367,9 +367,11 @@ int __connman_ipconfig_newaddr(int index, int family, const char *label,
 void __connman_ipconfig_deladdr(int index, int family, const char *label,
 				unsigned char prefixlen, const char *address);
 void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
-					const char *dst, const char *gateway);
+					const char *dst, const char *gateway,
+					uint32_t table_id);
 void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
-					const char *dst, const char *gateway);
+					const char *dst, const char *gateway,
+					uint32_t table_id);
 
 void __connman_ipconfig_foreach(void (*function) (int index, void *user_data),
 							void *user_data);
diff --git a/src/ipconfig.c b/src/ipconfig.c
index 0f40ac207016..011367ec60c3 100644
--- a/src/ipconfig.c
+++ b/src/ipconfig.c
@@ -1038,7 +1038,8 @@ out:
 }
 
 void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
-					const char *dst, const char *gateway)
+					const char *dst, const char *gateway,
+					uint32_t table_id)
 {
 	struct connman_ipdevice *ipdevice;
 	char *ifname;
@@ -1099,15 +1100,17 @@ void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
 		}
 	}
 
-	connman_info("%s {add} route %s gw %s scope %u <%s>",
-		ifname, dst, gateway, scope, scope2str(scope));
+	connman_info("%s {add} route %s gw %s scope %u <%s> table %u <%s>",
+		ifname, dst, gateway, scope, scope2str(scope),
+		table_id, __connman_inet_table2string(table_id));
 
 out:
 	g_free(ifname);
 }
 
 void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
-					const char *dst, const char *gateway)
+					const char *dst, const char *gateway,
+					uint32_t table_id)
 {
 	struct connman_ipdevice *ipdevice;
 	char *ifname;
@@ -1166,8 +1169,9 @@ void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
 		}
 	}
 
-	connman_info("%s {del} route %s gw %s scope %u <%s>",
-		ifname, dst, gateway, scope, scope2str(scope));
+	connman_info("%s {del} route %s gw %s scope %u <%s> table %u <%s>",
+		ifname, dst, gateway, scope, scope2str(scope),
+		table_id, __connman_inet_table2string(table_id));
 
 out:
 	g_free(ifname);
diff --git a/src/rtnl.c b/src/rtnl.c
index 056107831038..eb0ba63961cd 100644
--- a/src/rtnl.c
+++ b/src/rtnl.c
@@ -735,18 +735,20 @@ static void process_newroute(unsigned char family, unsigned char scope,
 	GSList *list;
 	char dststr[INET6_ADDRSTRLEN], gatewaystr[INET6_ADDRSTRLEN];
 	int index = -1;
+	uint32_t table_id = RT_TABLE_UNSPEC;
 
 	if (family == AF_INET) {
 		struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
 
 		extract_ipv4_route(msg, bytes, &index, &dst, &gateway,
-			NULL);
+			&table_id);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_newroute(index, family, scope, dststr,
-								gatewaystr);
+								gatewaystr,
+								table_id);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -761,13 +763,14 @@ static void process_newroute(unsigned char family, unsigned char scope,
 				gateway = IN6ADDR_ANY_INIT;
 
 		extract_ipv6_route(msg, bytes, &index, &dst, &gateway,
-			NULL);
+			&table_id);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_newroute(index, family, scope, dststr,
-								gatewaystr);
+								gatewaystr,
+								table_id);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -794,18 +797,20 @@ static void process_delroute(unsigned char family, unsigned char scope,
 	GSList *list;
 	char dststr[INET6_ADDRSTRLEN], gatewaystr[INET6_ADDRSTRLEN];
 	int index = -1;
+	uint32_t table_id = RT_TABLE_UNSPEC;
 
 	if (family == AF_INET) {
 		struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
 
 		extract_ipv4_route(msg, bytes, &index, &dst, &gateway,
-			NULL);
+			&table_id);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_delroute(index, family, scope, dststr,
-								gatewaystr);
+								gatewaystr,
+								table_id);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -820,13 +825,14 @@ static void process_delroute(unsigned char family, unsigned char scope,
 				gateway = IN6ADDR_ANY_INIT;
 
 		extract_ipv6_route(msg, bytes, &index, &dst, &gateway,
-			NULL);
+			&table_id);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_delroute(index, family, scope, dststr,
-						gatewaystr);
+								gatewaystr,
+								table_id);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 39/90] ipconfig: Pass the rtnl table to to '__connman_ipconfig_{new,del}route'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (38 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 39/90] ipconfig: Pass the rtnl table to '__connman_ipconfig_{new,del}route' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 40/90] rtnl: Add support for extracting the metric/priority Grant Erickson
                   ` (52 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds support for extracting and passing the Routing Netlink
(rtnl) table identifier to '__connman_ipconfig_{new,del}route' from
'process_{new,del}route'.
---
 src/connman.h  |  6 ++++--
 src/ipconfig.c | 16 ++++++++++------
 src/rtnl.c     | 22 ++++++++++++++--------
 3 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index 19de86346565..35f11e92ac3c 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -367,9 +367,11 @@ int __connman_ipconfig_newaddr(int index, int family, const char *label,
 void __connman_ipconfig_deladdr(int index, int family, const char *label,
 				unsigned char prefixlen, const char *address);
 void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
-					const char *dst, const char *gateway);
+					const char *dst, const char *gateway,
+					uint32_t table_id);
 void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
-					const char *dst, const char *gateway);
+					const char *dst, const char *gateway,
+					uint32_t table_id);
 
 void __connman_ipconfig_foreach(void (*function) (int index, void *user_data),
 							void *user_data);
diff --git a/src/ipconfig.c b/src/ipconfig.c
index 0f40ac207016..011367ec60c3 100644
--- a/src/ipconfig.c
+++ b/src/ipconfig.c
@@ -1038,7 +1038,8 @@ out:
 }
 
 void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
-					const char *dst, const char *gateway)
+					const char *dst, const char *gateway,
+					uint32_t table_id)
 {
 	struct connman_ipdevice *ipdevice;
 	char *ifname;
@@ -1099,15 +1100,17 @@ void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
 		}
 	}
 
-	connman_info("%s {add} route %s gw %s scope %u <%s>",
-		ifname, dst, gateway, scope, scope2str(scope));
+	connman_info("%s {add} route %s gw %s scope %u <%s> table %u <%s>",
+		ifname, dst, gateway, scope, scope2str(scope),
+		table_id, __connman_inet_table2string(table_id));
 
 out:
 	g_free(ifname);
 }
 
 void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
-					const char *dst, const char *gateway)
+					const char *dst, const char *gateway,
+					uint32_t table_id)
 {
 	struct connman_ipdevice *ipdevice;
 	char *ifname;
@@ -1166,8 +1169,9 @@ void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
 		}
 	}
 
-	connman_info("%s {del} route %s gw %s scope %u <%s>",
-		ifname, dst, gateway, scope, scope2str(scope));
+	connman_info("%s {del} route %s gw %s scope %u <%s> table %u <%s>",
+		ifname, dst, gateway, scope, scope2str(scope),
+		table_id, __connman_inet_table2string(table_id));
 
 out:
 	g_free(ifname);
diff --git a/src/rtnl.c b/src/rtnl.c
index 056107831038..eb0ba63961cd 100644
--- a/src/rtnl.c
+++ b/src/rtnl.c
@@ -735,18 +735,20 @@ static void process_newroute(unsigned char family, unsigned char scope,
 	GSList *list;
 	char dststr[INET6_ADDRSTRLEN], gatewaystr[INET6_ADDRSTRLEN];
 	int index = -1;
+	uint32_t table_id = RT_TABLE_UNSPEC;
 
 	if (family == AF_INET) {
 		struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
 
 		extract_ipv4_route(msg, bytes, &index, &dst, &gateway,
-			NULL);
+			&table_id);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_newroute(index, family, scope, dststr,
-								gatewaystr);
+								gatewaystr,
+								table_id);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -761,13 +763,14 @@ static void process_newroute(unsigned char family, unsigned char scope,
 				gateway = IN6ADDR_ANY_INIT;
 
 		extract_ipv6_route(msg, bytes, &index, &dst, &gateway,
-			NULL);
+			&table_id);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_newroute(index, family, scope, dststr,
-								gatewaystr);
+								gatewaystr,
+								table_id);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -794,18 +797,20 @@ static void process_delroute(unsigned char family, unsigned char scope,
 	GSList *list;
 	char dststr[INET6_ADDRSTRLEN], gatewaystr[INET6_ADDRSTRLEN];
 	int index = -1;
+	uint32_t table_id = RT_TABLE_UNSPEC;
 
 	if (family == AF_INET) {
 		struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
 
 		extract_ipv4_route(msg, bytes, &index, &dst, &gateway,
-			NULL);
+			&table_id);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_delroute(index, family, scope, dststr,
-								gatewaystr);
+								gatewaystr,
+								table_id);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -820,13 +825,14 @@ static void process_delroute(unsigned char family, unsigned char scope,
 				gateway = IN6ADDR_ANY_INIT;
 
 		extract_ipv6_route(msg, bytes, &index, &dst, &gateway,
-			NULL);
+			&table_id);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_delroute(index, family, scope, dststr,
-						gatewaystr);
+								gatewaystr,
+								table_id);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 40/90] rtnl: Add support for extracting the metric/priority.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (39 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 39/90] ipconfig: Pass the rtnl table to " Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 41/90] ipconfig: Pass the rtnl metric to '__connman_ipconfig_{new,del}route' Grant Erickson
                   ` (51 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds support for extracting the Routing Netlink (rtnl) table
metric/priority attribute from rtnl messages.
---
 src/rtnl.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/rtnl.c b/src/rtnl.c
index eb0ba63961cd..fe53eb2eb5b6 100644
--- a/src/rtnl.c
+++ b/src/rtnl.c
@@ -671,7 +671,8 @@ static void process_deladdr(unsigned char family, unsigned char prefixlen,
 static void extract_ipv4_route(struct rtmsg *msg, int bytes, int *index,
 						struct in_addr *dst,
 						struct in_addr *gateway,
-						uint32_t *table_id)
+						uint32_t *table_id,
+						uint32_t *metric)
 {
 	struct rtattr *attr;
 
@@ -694,6 +695,10 @@ static void extract_ipv4_route(struct rtmsg *msg, int bytes, int *index,
 			if (table_id)
 				*table_id = *((uint32_t *) RTA_DATA(attr));
 			break;
+		case RTA_PRIORITY:
+			if (metric)
+				*metric = *((uint32_t *) RTA_DATA(attr));
+			break;
 		}
 	}
 }
@@ -701,7 +706,8 @@ static void extract_ipv4_route(struct rtmsg *msg, int bytes, int *index,
 static void extract_ipv6_route(struct rtmsg *msg, int bytes, int *index,
 						struct in6_addr *dst,
 						struct in6_addr *gateway,
-						uint32_t *table_id)
+						uint32_t *table_id,
+						uint32_t *metric)
 {
 	struct rtattr *attr;
 
@@ -725,6 +731,10 @@ static void extract_ipv6_route(struct rtmsg *msg, int bytes, int *index,
 			if (table_id)
 				*table_id = *((uint32_t *) RTA_DATA(attr));
 			break;
+		case RTA_PRIORITY:
+			if (metric)
+				*metric = *((uint32_t *) RTA_DATA(attr));
+			break;
 		}
 	}
 }
@@ -741,7 +751,7 @@ static void process_newroute(unsigned char family, unsigned char scope,
 		struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
 
 		extract_ipv4_route(msg, bytes, &index, &dst, &gateway,
-			&table_id);
+			&table_id, NULL);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
@@ -763,7 +773,7 @@ static void process_newroute(unsigned char family, unsigned char scope,
 				gateway = IN6ADDR_ANY_INIT;
 
 		extract_ipv6_route(msg, bytes, &index, &dst, &gateway,
-			&table_id);
+			&table_id, NULL);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
@@ -803,7 +813,7 @@ static void process_delroute(unsigned char family, unsigned char scope,
 		struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
 
 		extract_ipv4_route(msg, bytes, &index, &dst, &gateway,
-			&table_id);
+			&table_id, NULL);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
@@ -825,7 +835,7 @@ static void process_delroute(unsigned char family, unsigned char scope,
 				gateway = IN6ADDR_ANY_INIT;
 
 		extract_ipv6_route(msg, bytes, &index, &dst, &gateway,
-			&table_id);
+			&table_id, NULL);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 41/90] ipconfig: Pass the rtnl metric to '__connman_ipconfig_{new,del}route'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (40 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 40/90] rtnl: Add support for extracting the metric/priority Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 41/90] ipconfig: Pass the rtnl metric to " Grant Erickson
                   ` (50 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds support for extracting and passing the Routing Netlink
(rtnl) metric/priority to '__connman_ipconfig_{new,del}route' from
'process_{new,del}route'.
---
 src/connman.h  |  4 ++--
 src/ipconfig.c | 14 ++++++++------
 src/rtnl.c     | 22 ++++++++++++++--------
 3 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index 35f11e92ac3c..397e0e42c7f8 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -368,10 +368,10 @@ void __connman_ipconfig_deladdr(int index, int family, const char *label,
 				unsigned char prefixlen, const char *address);
 void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
 					const char *dst, const char *gateway,
-					uint32_t table_id);
+					uint32_t table_id, uint32_t metric);
 void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
 					const char *dst, const char *gateway,
-					uint32_t table_id);
+					uint32_t table_id, uint32_t metric);
 
 void __connman_ipconfig_foreach(void (*function) (int index, void *user_data),
 							void *user_data);
diff --git a/src/ipconfig.c b/src/ipconfig.c
index 011367ec60c3..c23d7a5ab4d6 100644
--- a/src/ipconfig.c
+++ b/src/ipconfig.c
@@ -1039,7 +1039,7 @@ out:
 
 void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
 					const char *dst, const char *gateway,
-					uint32_t table_id)
+					uint32_t table_id, uint32_t metric)
 {
 	struct connman_ipdevice *ipdevice;
 	char *ifname;
@@ -1100,9 +1100,10 @@ void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
 		}
 	}
 
-	connman_info("%s {add} route %s gw %s scope %u <%s> table %u <%s>",
+	connman_info("%s {add} route %s gw %s scope %u <%s> table %u <%s> "
+		"metric %u",
 		ifname, dst, gateway, scope, scope2str(scope),
-		table_id, __connman_inet_table2string(table_id));
+		table_id, __connman_inet_table2string(table_id), metric);
 
 out:
 	g_free(ifname);
@@ -1110,7 +1111,7 @@ out:
 
 void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
 					const char *dst, const char *gateway,
-					uint32_t table_id)
+					uint32_t table_id, uint32_t metric)
 {
 	struct connman_ipdevice *ipdevice;
 	char *ifname;
@@ -1169,9 +1170,10 @@ void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
 		}
 	}
 
-	connman_info("%s {del} route %s gw %s scope %u <%s> table %u <%s>",
+	connman_info("%s {del} route %s gw %s scope %u <%s> table %u <%s> "
+		"metric %u",
 		ifname, dst, gateway, scope, scope2str(scope),
-		table_id, __connman_inet_table2string(table_id));
+		table_id, __connman_inet_table2string(table_id), metric);
 
 out:
 	g_free(ifname);
diff --git a/src/rtnl.c b/src/rtnl.c
index fe53eb2eb5b6..596e8e4ae124 100644
--- a/src/rtnl.c
+++ b/src/rtnl.c
@@ -746,19 +746,21 @@ static void process_newroute(unsigned char family, unsigned char scope,
 	char dststr[INET6_ADDRSTRLEN], gatewaystr[INET6_ADDRSTRLEN];
 	int index = -1;
 	uint32_t table_id = RT_TABLE_UNSPEC;
+	uint32_t metric = 0;
 
 	if (family == AF_INET) {
 		struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
 
 		extract_ipv4_route(msg, bytes, &index, &dst, &gateway,
-			&table_id, NULL);
+			&table_id, &metric);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_newroute(index, family, scope, dststr,
 								gatewaystr,
-								table_id);
+								table_id,
+								metric);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -773,14 +775,15 @@ static void process_newroute(unsigned char family, unsigned char scope,
 				gateway = IN6ADDR_ANY_INIT;
 
 		extract_ipv6_route(msg, bytes, &index, &dst, &gateway,
-			&table_id, NULL);
+			&table_id, &metric);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_newroute(index, family, scope, dststr,
 								gatewaystr,
-								table_id);
+								table_id,
+								metric);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -808,19 +811,21 @@ static void process_delroute(unsigned char family, unsigned char scope,
 	char dststr[INET6_ADDRSTRLEN], gatewaystr[INET6_ADDRSTRLEN];
 	int index = -1;
 	uint32_t table_id = RT_TABLE_UNSPEC;
+	uint32_t metric = 0;
 
 	if (family == AF_INET) {
 		struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
 
 		extract_ipv4_route(msg, bytes, &index, &dst, &gateway,
-			&table_id, NULL);
+			&table_id, &metric);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_delroute(index, family, scope, dststr,
 								gatewaystr,
-								table_id);
+								table_id,
+								metric);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -835,14 +840,15 @@ static void process_delroute(unsigned char family, unsigned char scope,
 				gateway = IN6ADDR_ANY_INIT;
 
 		extract_ipv6_route(msg, bytes, &index, &dst, &gateway,
-			&table_id, NULL);
+			&table_id, &metric);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_delroute(index, family, scope, dststr,
 								gatewaystr,
-								table_id);
+								table_id,
+								metric);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 41/90] ipconfig: Pass the rtnl metric to to '__connman_ipconfig_{new,del}route'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (41 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 41/90] ipconfig: Pass the rtnl metric to '__connman_ipconfig_{new,del}route' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 42/90] ipconfig: Pass the rtnl dst prefixlen " Grant Erickson
                   ` (49 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds support for extracting and passing the Routing Netlink
(rtnl) metric/priority to '__connman_ipconfig_{new,del}route' from
'process_{new,del}route'.
---
 src/connman.h  |  4 ++--
 src/ipconfig.c | 14 ++++++++------
 src/rtnl.c     | 22 ++++++++++++++--------
 3 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index 35f11e92ac3c..397e0e42c7f8 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -368,10 +368,10 @@ void __connman_ipconfig_deladdr(int index, int family, const char *label,
 				unsigned char prefixlen, const char *address);
 void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
 					const char *dst, const char *gateway,
-					uint32_t table_id);
+					uint32_t table_id, uint32_t metric);
 void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
 					const char *dst, const char *gateway,
-					uint32_t table_id);
+					uint32_t table_id, uint32_t metric);
 
 void __connman_ipconfig_foreach(void (*function) (int index, void *user_data),
 							void *user_data);
diff --git a/src/ipconfig.c b/src/ipconfig.c
index 011367ec60c3..c23d7a5ab4d6 100644
--- a/src/ipconfig.c
+++ b/src/ipconfig.c
@@ -1039,7 +1039,7 @@ out:
 
 void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
 					const char *dst, const char *gateway,
-					uint32_t table_id)
+					uint32_t table_id, uint32_t metric)
 {
 	struct connman_ipdevice *ipdevice;
 	char *ifname;
@@ -1100,9 +1100,10 @@ void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
 		}
 	}
 
-	connman_info("%s {add} route %s gw %s scope %u <%s> table %u <%s>",
+	connman_info("%s {add} route %s gw %s scope %u <%s> table %u <%s> "
+		"metric %u",
 		ifname, dst, gateway, scope, scope2str(scope),
-		table_id, __connman_inet_table2string(table_id));
+		table_id, __connman_inet_table2string(table_id), metric);
 
 out:
 	g_free(ifname);
@@ -1110,7 +1111,7 @@ out:
 
 void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
 					const char *dst, const char *gateway,
-					uint32_t table_id)
+					uint32_t table_id, uint32_t metric)
 {
 	struct connman_ipdevice *ipdevice;
 	char *ifname;
@@ -1169,9 +1170,10 @@ void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
 		}
 	}
 
-	connman_info("%s {del} route %s gw %s scope %u <%s> table %u <%s>",
+	connman_info("%s {del} route %s gw %s scope %u <%s> table %u <%s> "
+		"metric %u",
 		ifname, dst, gateway, scope, scope2str(scope),
-		table_id, __connman_inet_table2string(table_id));
+		table_id, __connman_inet_table2string(table_id), metric);
 
 out:
 	g_free(ifname);
diff --git a/src/rtnl.c b/src/rtnl.c
index fe53eb2eb5b6..596e8e4ae124 100644
--- a/src/rtnl.c
+++ b/src/rtnl.c
@@ -746,19 +746,21 @@ static void process_newroute(unsigned char family, unsigned char scope,
 	char dststr[INET6_ADDRSTRLEN], gatewaystr[INET6_ADDRSTRLEN];
 	int index = -1;
 	uint32_t table_id = RT_TABLE_UNSPEC;
+	uint32_t metric = 0;
 
 	if (family == AF_INET) {
 		struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
 
 		extract_ipv4_route(msg, bytes, &index, &dst, &gateway,
-			&table_id, NULL);
+			&table_id, &metric);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_newroute(index, family, scope, dststr,
 								gatewaystr,
-								table_id);
+								table_id,
+								metric);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -773,14 +775,15 @@ static void process_newroute(unsigned char family, unsigned char scope,
 				gateway = IN6ADDR_ANY_INIT;
 
 		extract_ipv6_route(msg, bytes, &index, &dst, &gateway,
-			&table_id, NULL);
+			&table_id, &metric);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_newroute(index, family, scope, dststr,
 								gatewaystr,
-								table_id);
+								table_id,
+								metric);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -808,19 +811,21 @@ static void process_delroute(unsigned char family, unsigned char scope,
 	char dststr[INET6_ADDRSTRLEN], gatewaystr[INET6_ADDRSTRLEN];
 	int index = -1;
 	uint32_t table_id = RT_TABLE_UNSPEC;
+	uint32_t metric = 0;
 
 	if (family == AF_INET) {
 		struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
 
 		extract_ipv4_route(msg, bytes, &index, &dst, &gateway,
-			&table_id, NULL);
+			&table_id, &metric);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_delroute(index, family, scope, dststr,
 								gatewaystr,
-								table_id);
+								table_id,
+								metric);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -835,14 +840,15 @@ static void process_delroute(unsigned char family, unsigned char scope,
 				gateway = IN6ADDR_ANY_INIT;
 
 		extract_ipv6_route(msg, bytes, &index, &dst, &gateway,
-			&table_id, NULL);
+			&table_id, &metric);
 
 		inet_ntop(family, &dst, dststr, sizeof(dststr));
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_delroute(index, family, scope, dststr,
 								gatewaystr,
-								table_id);
+								table_id,
+								metric);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 42/90] ipconfig: Pass the rtnl dst prefixlen to '__connman_ipconfig_{new,del}route'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (42 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 41/90] ipconfig: Pass the rtnl metric to " Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 42/90] ipconfig: Pass the rtnl dst prefixlen to " Grant Erickson
                   ` (48 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds support for extracting and passing the Routing Netlink
(rtnl) destination prefix length to
'__connman_ipconfig_{new,del}route' from 'process_{new,del}route'.
---
 src/connman.h  |  8 ++++++--
 src/ipconfig.c | 16 ++++++++++------
 src/rtnl.c     | 28 ++++++++++++++++------------
 3 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index 397e0e42c7f8..d9ce353c4df4 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -367,10 +367,14 @@ int __connman_ipconfig_newaddr(int index, int family, const char *label,
 void __connman_ipconfig_deladdr(int index, int family, const char *label,
 				unsigned char prefixlen, const char *address);
 void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
-					const char *dst, const char *gateway,
+					const char *dst,
+					unsigned char dst_prefixlen,
+					const char *gateway,
 					uint32_t table_id, uint32_t metric);
 void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
-					const char *dst, const char *gateway,
+					const char *dst,
+					unsigned char dst_prefixlen,
+					const char *gateway,
 					uint32_t table_id, uint32_t metric);
 
 void __connman_ipconfig_foreach(void (*function) (int index, void *user_data),
diff --git a/src/ipconfig.c b/src/ipconfig.c
index c23d7a5ab4d6..55a05694ff14 100644
--- a/src/ipconfig.c
+++ b/src/ipconfig.c
@@ -1038,7 +1038,9 @@ out:
 }
 
 void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
-					const char *dst, const char *gateway,
+					const char *dst,
+					unsigned char dst_prefixlen,
+					const char *gateway,
 					uint32_t table_id, uint32_t metric)
 {
 	struct connman_ipdevice *ipdevice;
@@ -1100,9 +1102,9 @@ void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
 		}
 	}
 
-	connman_info("%s {add} route %s gw %s scope %u <%s> table %u <%s> "
+	connman_info("%s {add} route %s/%u gw %s scope %u <%s> table %u <%s> "
 		"metric %u",
-		ifname, dst, gateway, scope, scope2str(scope),
+		ifname, dst, dst_prefixlen, gateway, scope, scope2str(scope),
 		table_id, __connman_inet_table2string(table_id), metric);
 
 out:
@@ -1110,7 +1112,9 @@ out:
 }
 
 void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
-					const char *dst, const char *gateway,
+					const char *dst,
+					unsigned char dst_prefixlen,
+					const char *gateway,
 					uint32_t table_id, uint32_t metric)
 {
 	struct connman_ipdevice *ipdevice;
@@ -1170,9 +1174,9 @@ void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
 		}
 	}
 
-	connman_info("%s {del} route %s gw %s scope %u <%s> table %u <%s> "
+	connman_info("%s {del} route %s/%u gw %s scope %u <%s> table %u <%s> "
 		"metric %u",
-		ifname, dst, gateway, scope, scope2str(scope),
+		ifname, dst, dst_prefixlen, gateway, scope, scope2str(scope),
 		table_id, __connman_inet_table2string(table_id), metric);
 
 out:
diff --git a/src/rtnl.c b/src/rtnl.c
index 596e8e4ae124..a28370ae0f0f 100644
--- a/src/rtnl.c
+++ b/src/rtnl.c
@@ -758,9 +758,10 @@ static void process_newroute(unsigned char family, unsigned char scope,
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_newroute(index, family, scope, dststr,
-								gatewaystr,
-								table_id,
-								metric);
+							msg->rtm_dst_len,
+							gatewaystr,
+							table_id,
+							metric);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -781,9 +782,10 @@ static void process_newroute(unsigned char family, unsigned char scope,
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_newroute(index, family, scope, dststr,
-								gatewaystr,
-								table_id,
-								metric);
+							msg->rtm_dst_len,
+							gatewaystr,
+							table_id,
+							metric);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -823,9 +825,10 @@ static void process_delroute(unsigned char family, unsigned char scope,
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_delroute(index, family, scope, dststr,
-								gatewaystr,
-								table_id,
-								metric);
+							msg->rtm_dst_len,
+							gatewaystr,
+							table_id,
+							metric);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -846,9 +849,10 @@ static void process_delroute(unsigned char family, unsigned char scope,
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_delroute(index, family, scope, dststr,
-								gatewaystr,
-								table_id,
-								metric);
+							msg->rtm_dst_len,
+							gatewaystr,
+							table_id,
+							metric);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 42/90] ipconfig: Pass the rtnl dst prefixlen to to '__connman_ipconfig_{new,del}route'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (43 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 42/90] ipconfig: Pass the rtnl dst prefixlen " Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 43/90] inet: Include interface index and name in 'DBG' Grant Erickson
                   ` (47 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds support for extracting and passing the Routing Netlink
(rtnl) destination prefix length to
'__connman_ipconfig_{new,del}route' from 'process_{new,del}route'.
---
 src/connman.h  |  8 ++++++--
 src/ipconfig.c | 16 ++++++++++------
 src/rtnl.c     | 28 ++++++++++++++++------------
 3 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index 397e0e42c7f8..d9ce353c4df4 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -367,10 +367,14 @@ int __connman_ipconfig_newaddr(int index, int family, const char *label,
 void __connman_ipconfig_deladdr(int index, int family, const char *label,
 				unsigned char prefixlen, const char *address);
 void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
-					const char *dst, const char *gateway,
+					const char *dst,
+					unsigned char dst_prefixlen,
+					const char *gateway,
 					uint32_t table_id, uint32_t metric);
 void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
-					const char *dst, const char *gateway,
+					const char *dst,
+					unsigned char dst_prefixlen,
+					const char *gateway,
 					uint32_t table_id, uint32_t metric);
 
 void __connman_ipconfig_foreach(void (*function) (int index, void *user_data),
diff --git a/src/ipconfig.c b/src/ipconfig.c
index c23d7a5ab4d6..55a05694ff14 100644
--- a/src/ipconfig.c
+++ b/src/ipconfig.c
@@ -1038,7 +1038,9 @@ out:
 }
 
 void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
-					const char *dst, const char *gateway,
+					const char *dst,
+					unsigned char dst_prefixlen,
+					const char *gateway,
 					uint32_t table_id, uint32_t metric)
 {
 	struct connman_ipdevice *ipdevice;
@@ -1100,9 +1102,9 @@ void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
 		}
 	}
 
-	connman_info("%s {add} route %s gw %s scope %u <%s> table %u <%s> "
+	connman_info("%s {add} route %s/%u gw %s scope %u <%s> table %u <%s> "
 		"metric %u",
-		ifname, dst, gateway, scope, scope2str(scope),
+		ifname, dst, dst_prefixlen, gateway, scope, scope2str(scope),
 		table_id, __connman_inet_table2string(table_id), metric);
 
 out:
@@ -1110,7 +1112,9 @@ out:
 }
 
 void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
-					const char *dst, const char *gateway,
+					const char *dst,
+					unsigned char dst_prefixlen,
+					const char *gateway,
 					uint32_t table_id, uint32_t metric)
 {
 	struct connman_ipdevice *ipdevice;
@@ -1170,9 +1174,9 @@ void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
 		}
 	}
 
-	connman_info("%s {del} route %s gw %s scope %u <%s> table %u <%s> "
+	connman_info("%s {del} route %s/%u gw %s scope %u <%s> table %u <%s> "
 		"metric %u",
-		ifname, dst, gateway, scope, scope2str(scope),
+		ifname, dst, dst_prefixlen, gateway, scope, scope2str(scope),
 		table_id, __connman_inet_table2string(table_id), metric);
 
 out:
diff --git a/src/rtnl.c b/src/rtnl.c
index 596e8e4ae124..a28370ae0f0f 100644
--- a/src/rtnl.c
+++ b/src/rtnl.c
@@ -758,9 +758,10 @@ static void process_newroute(unsigned char family, unsigned char scope,
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_newroute(index, family, scope, dststr,
-								gatewaystr,
-								table_id,
-								metric);
+							msg->rtm_dst_len,
+							gatewaystr,
+							table_id,
+							metric);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -781,9 +782,10 @@ static void process_newroute(unsigned char family, unsigned char scope,
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_newroute(index, family, scope, dststr,
-								gatewaystr,
-								table_id,
-								metric);
+							msg->rtm_dst_len,
+							gatewaystr,
+							table_id,
+							metric);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -823,9 +825,10 @@ static void process_delroute(unsigned char family, unsigned char scope,
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_delroute(index, family, scope, dststr,
-								gatewaystr,
-								table_id,
-								metric);
+							msg->rtm_dst_len,
+							gatewaystr,
+							table_id,
+							metric);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
@@ -846,9 +849,10 @@ static void process_delroute(unsigned char family, unsigned char scope,
 		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
 
 		__connman_ipconfig_delroute(index, family, scope, dststr,
-								gatewaystr,
-								table_id,
-								metric);
+							msg->rtm_dst_len,
+							gatewaystr,
+							table_id,
+							metric);
 
 		/* skip host specific routes */
 		if (scope != RT_SCOPE_UNIVERSE &&
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 43/90] inet: Include interface index and name in 'DBG'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (44 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 42/90] ipconfig: Pass the rtnl dst prefixlen to " Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 44/90] inet: Include the command value and string " Grant Erickson
                   ` (46 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This includes both the network interface index and name in the 'DBG'
statement in 'iproute_default_modify' to aid in debugging.
---
 src/inet.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/inet.c b/src/inet.c
index e135d1ad3cae..9d5841fdf2e3 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -3204,8 +3204,12 @@ static int iproute_default_modify(int cmd, uint32_t table_id, int ifindex,
 	int ret, len;
 	int family = connman_inet_check_ipaddress(gateway);
 	char *dst = NULL;
+	g_autofree char *interface = NULL;
 
-	DBG("gateway %s/%u table %u <%s>",
+	interface = connman_inet_ifname(ifindex);
+
+	DBG("ifindex %d (%s) gateway %s/%u table %u <%s>",
+		ifindex, interface,
 		gateway, prefixlen,
 		table_id, __connman_inet_table2string(table_id));
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 44/90] inet: Include the command value and string in 'DBG'
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (45 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 43/90] inet: Include interface index and name in 'DBG' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 45/90] ipconfig: Use 'RT_SCOPE_*' mnemonics Grant Erickson
                   ` (45 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This includes the Routing Netlink (rtnl) command value and string in
'DBG' in 'iproute_default_modify' to aid in debugging.
---
 src/inet.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/inet.c b/src/inet.c
index 9d5841fdf2e3..4882f9b78205 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -3196,6 +3196,18 @@ int __connman_inet_del_fwmark_rule(uint32_t table_id, int family, uint32_t fwmar
 	return iprule_modify(RTM_DELRULE, family, table_id, fwmark);
 }
 
+static const char *rtnl_route_cmd2string(int cmd)
+{
+	switch (cmd) {
+	case RTM_NEWROUTE:
+		return "add";
+	case RTM_DELROUTE:
+		return "del";
+	}
+
+	return "";
+}
+
 static int iproute_default_modify(int cmd, uint32_t table_id, int ifindex,
 			const char *gateway, unsigned char prefixlen)
 {
@@ -3208,7 +3220,8 @@ static int iproute_default_modify(int cmd, uint32_t table_id, int ifindex,
 
 	interface = connman_inet_ifname(ifindex);
 
-	DBG("ifindex %d (%s) gateway %s/%u table %u <%s>",
+	DBG("cmd %d (%s) ifindex %d (%s) gateway %s/%u table %u <%s>",
+		cmd, rtnl_route_cmd2string(cmd),
 		ifindex, interface,
 		gateway, prefixlen,
 		table_id, __connman_inet_table2string(table_id));
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 45/90] ipconfig: Use 'RT_SCOPE_*' mnemonics.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (46 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 44/90] inet: Include the command value and string " Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 46/90] inet: Add a metric parameter to 'iproute_default_modify' Grant Erickson
                   ` (44 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This leverages 'RT_SCOPE_*' mnemonics rather than magic numbers for
'scope2str'.
---
 src/ipconfig.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/ipconfig.c b/src/ipconfig.c
index 55a05694ff14..e26fc13799fb 100644
--- a/src/ipconfig.c
+++ b/src/ipconfig.c
@@ -263,9 +263,9 @@ static const char *type2str(unsigned short type)
 static const char *scope2str(unsigned char scope)
 {
 	switch (scope) {
-	case 0:
+	case RT_SCOPE_UNIVERSE:
 		return "UNIVERSE";
-	case 253:
+	case RT_SCOPE_LINK:
 		return "LINK";
 	}
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 46/90] inet: Add a metric parameter to 'iproute_default_modify'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (47 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 45/90] ipconfig: Use 'RT_SCOPE_*' mnemonics Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 47/90] inet: Document 'iproute_default_modify' Grant Erickson
                   ` (43 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds a Routing Netlink (rtnl) metric/priority parameter to
'iproute_default_modify'.
---
 src/inet.c | 47 +++++++++++++++++++++++++++++++++++------------
 1 file changed, 35 insertions(+), 12 deletions(-)

diff --git a/src/inet.c b/src/inet.c
index 4882f9b78205..650eb9cbadf1 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -3208,8 +3208,9 @@ static const char *rtnl_route_cmd2string(int cmd)
 	return "";
 }
 
-static int iproute_default_modify(int cmd, uint32_t table_id, int ifindex,
-			const char *gateway, unsigned char prefixlen)
+static int iproute_default_modify(int cmd, uint32_t table_id, uint32_t metric,
+			int ifindex, const char *gateway,
+			unsigned char prefixlen)
 {
 	struct __connman_inet_rtnl_handle rth;
 	unsigned char buf[sizeof(struct in6_addr)];
@@ -3220,11 +3221,12 @@ static int iproute_default_modify(int cmd, uint32_t table_id, int ifindex,
 
 	interface = connman_inet_ifname(ifindex);
 
-	DBG("cmd %d (%s) ifindex %d (%s) gateway %s/%u table %u <%s>",
+	DBG("cmd %d (%s) ifindex %d (%s) gateway %s/%u table %u <%s> metric %u",
 		cmd, rtnl_route_cmd2string(cmd),
 		ifindex, interface,
 		gateway, prefixlen,
-		table_id, __connman_inet_table2string(table_id));
+		table_id, __connman_inet_table2string(table_id),
+		metric);
 
 	switch (family) {
 	case AF_INET:
@@ -3280,6 +3282,9 @@ static int iproute_default_modify(int cmd, uint32_t table_id, int ifindex,
 	__connman_inet_rtnl_addattr32(&rth.req.n, sizeof(rth.req),
 							RTA_OIF, ifindex);
 
+	__connman_inet_rtnl_addattr32(&rth.req.n, sizeof(rth.req),
+							RTA_PRIORITY, metric);
+
 	ret = __connman_inet_rtnl_open(&rth);
 	if (ret < 0)
 		goto done;
@@ -3295,31 +3300,49 @@ done:
 int __connman_inet_add_default_to_table(uint32_t table_id, int ifindex,
 						const char *gateway)
 {
-	/* ip route add default via 1.2.3.4 dev wlan0 table 1234 */
+	static const uint32_t metric = 0;
+	static const unsigned char prefixlen = 0;
 
-	return iproute_default_modify(RTM_NEWROUTE, table_id, ifindex, gateway, 0);
+	/*
+	 * ip route add default/0 via <gateway> dev wlan0 table <table_id>
+	 * metric 0
+	 */
+	return iproute_default_modify(RTM_NEWROUTE, table_id, metric, ifindex,
+		gateway, prefixlen);
 }
 
 int __connman_inet_add_subnet_to_table(uint32_t table_id, int ifindex,
 						const char *gateway, unsigned char prefixlen)
 {
-	/* ip route add 1.2.3.4/24 dev eth0 table 1234 */
-	return iproute_default_modify(RTM_NEWROUTE, table_id, ifindex, gateway, prefixlen);
+	static const uint32_t metric = 0;
+
+	/* ip route add 1.2.3.4/24 dev eth0 table 1234 metric 0 */
+	return iproute_default_modify(RTM_NEWROUTE, table_id, metric, ifindex,
+		gateway, prefixlen);
 }
 
 int __connman_inet_del_default_from_table(uint32_t table_id, int ifindex,
 						const char *gateway)
 {
-	/* ip route del default via 1.2.3.4 dev wlan0 table 1234 */
+	static const uint32_t metric = 0;
+	static const unsigned char prefixlen = 0;
 
-	return iproute_default_modify(RTM_DELROUTE, table_id, ifindex, gateway, 0);
+	/*
+	 * ip route del default/0 via <gateway> dev wlan0 table <table_id>
+	 * metric 0
+	 */
+	return iproute_default_modify(RTM_DELROUTE, table_id, metric, ifindex,
+		gateway, prefixlen);
 }
 
 int __connman_inet_del_subnet_from_table(uint32_t table_id, int ifindex,
 						const char *gateway, unsigned char prefixlen)
 {
-	/* ip route del 1.2.3.4/24 dev eth0 table 1234 */
-	return iproute_default_modify(RTM_DELROUTE, table_id, ifindex, gateway, prefixlen);
+	static const uint32_t metric = 0;
+
+	/* ip route del 1.2.3.4/24 dev eth0 table 1234 metric 0 */
+	return iproute_default_modify(RTM_DELROUTE, table_id, metric, ifindex,
+		gateway, prefixlen);
 }
 
 int __connman_inet_get_interface_ll_address(int index, int family,
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 47/90] inet: Document 'iproute_default_modify'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (48 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 46/90] inet: Add a metric parameter to 'iproute_default_modify' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 48/90] connection: Document '__connman_inet_add_default_to_table' Grant Erickson
                   ` (42 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds documentation to the 'iproute_default_modify' function.
---
 src/inet.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/src/inet.c b/src/inet.c
index 650eb9cbadf1..7bd084ff79e4 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -3208,6 +3208,45 @@ static const char *rtnl_route_cmd2string(int cmd)
 	return "";
 }
 
+/**
+ *  @brief
+ *    Add or remove a gateway default route.
+ *
+ *  This attempts to add or remove a gateway default route to or from
+ *  the kernel using a Linux Route Netlink (rtnl) socket and protocol
+ *  with the specified attributes.
+ *
+ *  @param[in]  cmd        The Linux Route Netlink command to send. This
+ *                         is expected to be either RTM_NEWROUTE (add
+ *                         new route) or RTM_DELROUTE (delete existing
+ *                         route).
+ *  @param[in]  table_id   The table to add/delete this route to/from.
+ *  @param[in]  metric     The routing priority metric for the route.
+ *  @param[in]  ifindex    The network interface index associated with
+ *                         the output network device for the route.
+ *  @param[in]  gateway    A pointer to an immutable null-terminated C
+ *                         string containing the IPv4 or IPv6 address,
+ *                         in text form, of the route destination or
+ *                         next hop gateway address.
+ *  @param[in]  prefixlen  The destination prefix length of the route.
+ *
+ *  @retval  0        If successful.
+ *  @retval  -EINVAL  If the address family of @a gateway was not AF_INET
+ *                    (IPv4) or AF_INET6 (IPv6), if @a gateway does not
+ *                    contain a character string representing a valid
+ *                    network address in either the AF_INET or
+ *                    AF_INET6 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  -EEXIST  A request was made to add an existing routing
+ *                    entry.
+ *  @retval  -ESRCH   A request was made to delete a non-existing
+ *                    routing entry.
+ *
+ */
 static int iproute_default_modify(int cmd, uint32_t table_id, uint32_t metric,
 			int ifindex, const char *gateway,
 			unsigned char prefixlen)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 48/90] connection: Document '__connman_inet_add_default_to_table'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (49 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 47/90] inet: Document 'iproute_default_modify' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 49/90] connection: Document '__connman_inet_del_default_to_table' Grant Erickson
                   ` (41 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the '__connman_inet_add_default_to_table'
function.
---
 src/inet.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/inet.c b/src/inet.c
index 7bd084ff79e4..32bae2a3500c 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -3336,6 +3336,38 @@ done:
 	return ret;
 }
 
+/**
+ *  @brief
+ *    Add a gateway default route.
+ *
+ *  This attempts to add a gateway default route to the kernel routing
+ *  table, @a table_id, using a Linux Route Netlink (rtnl) socket and
+ *  protocol with the specified attributes, including an implicit
+ *  metric/prioity of zero (0), the highest priority.
+ *
+ *  @param[in]  table_id   The table to add this route to.
+ *  @param[in]  ifindex    The network interface index associated with
+ *                         the output network device for the route.
+ *  @param[in]  gateway    A pointer to an immutable null-terminated C
+ *                         string containing the IPv4 or IPv6 address,
+ *                         in text form, of the route destination or
+ *                         next hop gateway address.
+ *
+ *  @retval  0        If successful.
+ *  @retval  -EINVAL  If the address family of @a gateway was not AF_INET
+ *                    (IPv4) or AF_INET6 (IPv6), if @a gateway does not
+ *                    contain a character string representing a valid
+ *                    network address in either the AF_INET or
+ *                    AF_INET6 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  -EEXIST  A request was made to add an existing routing
+ *                    entry.
+ *
+ */
 int __connman_inet_add_default_to_table(uint32_t table_id, int ifindex,
 						const char *gateway)
 {
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 49/90] connection: Document '__connman_inet_del_default_to_table'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (50 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 48/90] connection: Document '__connman_inet_add_default_to_table' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 50/90] inet: Add '__connman_inet_{add,del}_default_{to,from}_table_with_metric' Grant Erickson
                   ` (40 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the '__connman_inet_del_default_to_table'
function.
---
 src/inet.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/inet.c b/src/inet.c
index 32bae2a3500c..5c5100e25f86 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -3392,6 +3392,38 @@ int __connman_inet_add_subnet_to_table(uint32_t table_id, int ifindex,
 		gateway, prefixlen);
 }
 
+/**
+ *  @brief
+ *    Delete a gateway default route.
+ *
+ *  This attempts to delete a gateway default route from the kernel
+ *  routing table, @a table_id, using a Linux Route Netlink (rtnl)
+ *  socket and protocol with the specified attributes, including an
+ *  implicit metric/prioity of zero (0), the highest priority.
+ *
+ *  @param[in]  table_id   The table to delete this route from.
+ *  @param[in]  ifindex    The network interface index associated with
+ *                         the output network device for the route.
+ *  @param[in]  gateway    A pointer to an immutable null-terminated C
+ *                         string containing the IPv4 or IPv6 address,
+ *                         in text form, of the route destination or
+ *                         next hop gateway address.
+ *
+ *  @retval  0        If successful.
+ *  @retval  -EINVAL  If the address family of @a gateway was not AF_INET
+ *                    (IPv4) or AF_INET6 (IPv6), if @a gateway does not
+ *                    contain a character string representing a valid
+ *                    network address in either the AF_INET or
+ *                    AF_INET6 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.
+ *
+ */
 int __connman_inet_del_default_from_table(uint32_t table_id, int ifindex,
 						const char *gateway)
 {
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 50/90] inet: Add '__connman_inet_{add,del}_default_{to,from}_table_with_metric'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (51 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 49/90] connection: Document '__connman_inet_del_default_to_table' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 51/90] inet: Document '__connman_inet_{add,del}_default_{to,from}_table_with_metric' Grant Erickson
                   ` (39 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds two new functions for adding a gateway default route:
'__connman_inet_{add,del}_default_{to,from}_table_with_metric', which
expands on the existing
'__connman_inet_{add,del}_default_{to,from}_table' by allowing the
caller to pass a non-zero metric/priority.
---
 src/connman.h |  8 ++++++++
 src/inet.c    | 30 ++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/src/connman.h b/src/connman.h
index d9ce353c4df4..472429bfc1a2 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -254,9 +254,17 @@ int __connman_inet_rtnl_addattr32(struct nlmsghdr *n, size_t maxlen,
 int __connman_inet_add_fwmark_rule(uint32_t table_id, int family, uint32_t fwmark);
 int __connman_inet_del_fwmark_rule(uint32_t table_id, int family, uint32_t fwmark);
 int __connman_inet_add_default_to_table(uint32_t table_id, int ifindex, const char *gateway);
+int __connman_inet_add_default_to_table_with_metric(uint32_t table_id,
+			int ifindex,
+			const char *gateway,
+			uint32_t metric);
 int __connman_inet_add_subnet_to_table(uint32_t table_id, int ifindex,
 			const char *gateway, unsigned char prefixlen);
 int __connman_inet_del_default_from_table(uint32_t table_id, int ifindex, const char *gateway);
+int __connman_inet_del_default_from_table_with_metric(uint32_t table_id,
+			int ifindex,
+			const char *gateway,
+			uint32_t metric);
 int __connman_inet_del_subnet_from_table(uint32_t table_id, int ifindex,
 			const char *gateway, unsigned char prefixlen);
 int __connman_inet_get_address_netmask(int ifindex,
diff --git a/src/inet.c b/src/inet.c
index 5c5100e25f86..3270a854eb6b 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -3382,6 +3382,21 @@ int __connman_inet_add_default_to_table(uint32_t table_id, int ifindex,
 		gateway, prefixlen);
 }
 
+int __connman_inet_add_default_to_table_with_metric(uint32_t table_id,
+						int ifindex,
+						const char *gateway,
+						uint32_t metric)
+{
+	static const unsigned char prefixlen = 0;
+
+	/*
+	 * ip route add default/0 via <gateway> dev wlan0 table <table_id>
+	 * metric <metric>
+	 */
+	return iproute_default_modify(RTM_NEWROUTE, table_id, metric, ifindex,
+		gateway, prefixlen);
+}
+
 int __connman_inet_add_subnet_to_table(uint32_t table_id, int ifindex,
 						const char *gateway, unsigned char prefixlen)
 {
@@ -3438,6 +3453,21 @@ int __connman_inet_del_default_from_table(uint32_t table_id, int ifindex,
 		gateway, prefixlen);
 }
 
+int __connman_inet_del_default_from_table_with_metric(uint32_t table_id,
+						int ifindex,
+						const char *gateway,
+						uint32_t metric)
+{
+	static const unsigned char prefixlen = 0;
+
+	/*
+	 * ip route del default/0 via <gateway> dev wlan0 table <table_id>
+	 * metric <metric>
+	 */
+	return iproute_default_modify(RTM_DELROUTE, table_id, metric, ifindex,
+		gateway, prefixlen);
+}
+
 int __connman_inet_del_subnet_from_table(uint32_t table_id, int ifindex,
 						const char *gateway, unsigned char prefixlen)
 {
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 51/90] inet: Document '__connman_inet_{add,del}_default_{to,from}_table_with_metric'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (52 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 50/90] inet: Add '__connman_inet_{add,del}_default_{to,from}_table_with_metric' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 52/90] connection: Add support for low-priority default routes Grant Erickson
                   ` (38 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds documentation to the
'__connman_inet_{add,del}_default_{to,from}_table_with_metric' functions.
---
 src/inet.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/src/inet.c b/src/inet.c
index 3270a854eb6b..31596a76a140 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -3382,6 +3382,39 @@ int __connman_inet_add_default_to_table(uint32_t table_id, int ifindex,
 		gateway, prefixlen);
 }
 
+/**
+ *  @brief
+ *    Add a gateway default route with metric/priority.
+ *
+ *  This attempts to add a gateway default route to the kernel routing
+ *  table, @a table_id, using a Linux Route Netlink (rtnl) socket and
+ *  protocol with the specified attributes, including an explicit
+ *  metric/prioity from the range [0, UINT32_MAX].
+ *
+ *  @param[in]  table_id   The table to add this route to.
+ *  @param[in]  ifindex    The network interface index associated with
+ *                         the output network device for the route.
+ *  @param[in]  gateway    A pointer to an immutable null-terminated C
+ *                         string containing the IPv4 or IPv6 address,
+ *                         in text form, of the route destination or
+ *                         next hop gateway address.
+ *  @param[in]  metric     The routing priority metric for the route.
+ *
+ *  @retval  0        If successful.
+ *  @retval  -EINVAL  If the address family of @a gateway was not AF_INET
+ *                    (IPv4) or AF_INET6 (IPv6), if @a gateway does not
+ *                    contain a character string representing a valid
+ *                    network address in either the AF_INET or
+ *                    AF_INET6 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  -EEXIST  A request was made to add an existing routing
+ *                    entry.
+ *
+ */
 int __connman_inet_add_default_to_table_with_metric(uint32_t table_id,
 						int ifindex,
 						const char *gateway,
@@ -3453,6 +3486,39 @@ int __connman_inet_del_default_from_table(uint32_t table_id, int ifindex,
 		gateway, prefixlen);
 }
 
+/**
+ *  @brief
+ *    Delete a gateway default route with metric/priority.
+ *
+ *  This attempts to delete a gateway default route from the kernel
+ *  routing table, @a table_id, using a Linux Route Netlink (rtnl)
+ *  socket and protocol with the specified attributes, including an
+ *  explicit metric/prioity from the range [0, UINT32_MAX].
+ *
+ *  @param[in]  table_id   The table to delete this route from.
+ *  @param[in]  ifindex    The network interface index associated with
+ *                         the output network device for the route.
+ *  @param[in]  gateway    A pointer to an immutable null-terminated C
+ *                         string containing the IPv4 or IPv6 address,
+ *                         in text form, of the route destination or
+ *                         next hop gateway address.
+ *  @param[in]  metric     The routing priority metric for the route.
+ *
+ *  @retval  0        If successful.
+ *  @retval  -EINVAL  If the address family of @a gateway was not AF_INET
+ *                    (IPv4) or AF_INET6 (IPv6), if @a gateway does not
+ *                    contain a character string representing a valid
+ *                    network address in either the AF_INET or
+ *                    AF_INET6 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.
+ *
+ */
 int __connman_inet_del_default_from_table_with_metric(uint32_t table_id,
 						int ifindex,
 						const char *gateway,
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 52/90] connection: Add support for low-priority default routes.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (53 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 51/90] inet: Document '__connman_inet_{add,del}_default_{to,from}_table_with_metric' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 53/90] connection: Introduce '{de,pro}mote_default_gateway' Grant Erickson
                   ` (37 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds support for low-priority (that is, metric > 0) default
routes along side the existing high-priority (that is, metric 0)
default route taken on by the default service.

For IPv6, these are handled and managed automatically by the kernel as
part of Router Discovery (RD) Router Advertisements (RAs) and because
link-local addresses and multi-homing are a natural part of IPv6,
nothing needs to be done for these here. Such routes show up in 'ip -6
route show' as:

    default via fe80::f29f:c2ff:fe10:271e dev eth0
        proto ra metric 1024 expires 1622sec hoplimit 64
        pref medium
    default via fe80::f29f:c2ff:fe10:271e dev wlan0
        proto ra metric 1024 expires 1354sec hoplimit 64
        pref medium

For IPv4, largely invented before the advent of link-local addresses
and multi-homing hosts, these need to be fully-managed here and, with
such management, should up in 'ip -4 route show' as low-priority (that
is, metric > 0) default routes:

    default via 192.168.2.1 dev wlan0 metric 4294967295

The other alternative to low-priority routes would be to use "def1"
default routes commonly used by VPNs that have a prefix length of 1
(hence the "def1" name). These would should up as:

    0.0.0.0/1 via 192.168.2.1 dev wlan0
    128.0.0.0/1 via 192.168.2.1 dev wlan0

However, since these require twice the number of routing table entries
and seem no more effective than the low-priority route approach, this
alternative is not used here at present.

The low-priority metric is determined on a per-network interface basis
and is computed by 'compute_low_priority_metric'.

Operationally, down calls from outside this module generally come from
the following three functions:

  1. __connman_connection_gateway_add
  2. __connman_connection_gateway_remove
  3. __connman_connection_update_gateway

and up calls generally come from the following two functions:

  1. connection_newgateway
  2. connection_delgateway

From these five functions above, we are then either attempting to do
the following for a gateway associated with a network service and its
underlying network interface:

  1. Set, or add, the high- or low-priority default route(s).
  2. Unset, or remove, the high- or low-priority default route(s).
  3. Promote the default route from low- to high-priority.
  4. Demote the default route from high- to low-priority.
---
 src/connection.c | 371 +++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 308 insertions(+), 63 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index f29f42870cdf..d41c4010bb61 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -44,6 +44,12 @@
 #define UNSET_DEFAULT_GATEWAY(data, type) \
 	unset_default_gateway(data, type, __func__)
 
+#define SET_LOW_PRIORITY_DEFAULT_GATEWAY(data, type) \
+	set_low_priority_default_gateway(data, type, __func__)
+
+#define UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(data, type) \
+	unset_low_priority_default_gateway(data, type, __func__)
+
 #define GATEWAY_CONFIG_DBG(description, config) \
 	gateway_config_debug(__func__, description, config)
 
@@ -226,6 +232,9 @@ typedef int (*mutate_default_gateway_route_cb_t)(struct gateway_data *data,
 static int unset_default_gateway(struct gateway_data *data,
 				enum connman_ipconfig_type type,
 				const char *function);
+static int unset_low_priority_default_gateway(struct gateway_data *data,
+				enum connman_ipconfig_type type,
+				const char *function);
 
 /*
  * These are declared as 'const char *const' to effect an immutable
@@ -346,6 +355,26 @@ static bool is_gateway_config_state(const struct gateway_config *config,
 	return config->state == state;
 }
 
+static bool is_gateway_config_state_inactive(
+				const struct gateway_config *config)
+{
+	return is_gateway_config_state(config,
+				CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
+}
+
+static bool is_gateway_config_state_added(const struct gateway_config *config)
+{
+	return is_gateway_config_state(config,
+				CONNMAN_GATEWAY_CONFIG_STATE_ADDED);
+}
+
+static bool is_gateway_config_state_removed(
+				const struct gateway_config *config)
+{
+	return is_gateway_config_state(config,
+				CONNMAN_GATEWAY_CONFIG_STATE_REMOVED);
+}
+
 static bool is_gateway_config_state_active(const struct gateway_config *config)
 {
 	return is_gateway_config_state(config,
@@ -363,6 +392,18 @@ static void gateway_config_type_set(struct gateway_config *config,
 	config->type = type;
 }
 
+static bool is_gateway_config_type(const struct gateway_config *config,
+				enum gateway_config_type type)
+{
+	return config->type == type;
+}
+
+static bool is_gateway_config_type_none(const struct gateway_config *config)
+{
+	return is_gateway_config_type(config,
+				CONNMAN_GATEWAY_CONFIG_TYPE_NONE);
+}
+
 /**
  *  @brief
  *    Conditionally log the specified gateway configuration.
@@ -988,6 +1029,7 @@ static int del_gateway_routes(struct gateway_data *data,
 
 			status4 = UNSET_DEFAULT_GATEWAY(data, type);
 
+			UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(data, type);
 		}
 	}
 
@@ -1003,6 +1045,7 @@ static int del_gateway_routes(struct gateway_data *data,
 
 			status6 = UNSET_DEFAULT_GATEWAY(data, type);
 
+			UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(data, type);
 		}
 	}
 
@@ -1329,10 +1372,23 @@ static int set_default_gateway_route_common(struct gateway_data *data,
 	if (!data || !config || !cb)
 		return -EINVAL;
 
+	if (!is_gateway_config_type_none(config) &&
+		!is_gateway_config_type(config, type))
+		return -EINVAL;
+
+	if (is_gateway_config_state_added(config))
+		return -EINPROGRESS;
+
+	if (is_gateway_config_state_active(config))
+		return -EALREADY;
+
 	err = cb(data, config);
 	if (err < 0)
 		goto done;
 
+	gateway_config_state_set(config,
+		CONNMAN_GATEWAY_CONFIG_STATE_ADDED);
+
 	gateway_config_type_set(config, type);
 
 done:
@@ -1392,10 +1448,22 @@ static int unset_default_gateway_route_common(struct gateway_data *data,
 	if (!data || !config || !cb)
 		return -EINVAL;
 
+	if (!is_gateway_config_type(config, type))
+		return -EINVAL;
+
+	if (is_gateway_config_state_removed(config))
+		return -EINPROGRESS;
+
+	if (is_gateway_config_state_inactive(config))
+		return -EALREADY;
+
 	err = cb(data, config);
 	if (err < 0)
 		goto done;
 
+	gateway_config_state_set(config,
+		CONNMAN_GATEWAY_CONFIG_STATE_REMOVED);
+
 done:
 	return err;
 }
@@ -1407,23 +1475,20 @@ static int set_ipv4_high_priority_default_gateway_route_cb(
 	int err = 0;
 
 	if (is_gateway_config_vpn(config)) {
-		connman_inet_set_gateway_interface(data->index);
-
-		gateway_config_state_set(config,
-			CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
+		err = connman_inet_set_gateway_interface(data->index);
+		if (err < 0)
+			goto done;
 
 		DBG("set %p index %d vpn %s index %d phy %s",
 			data, data->index, config->vpn_ip,
 			config->vpn_phy_index,
 			config->vpn_phy_ip);
 	} else if (is_ipv4_addr_any_str(config->gateway)) {
-		if (connman_inet_set_gateway_interface(
-					data->index) < 0)
+		err = connman_inet_set_gateway_interface(
+					data->index);
+		if (err < 0)
 			goto done;
 
-		gateway_config_state_set(config,
-			CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
-
 		DBG("set %p index %d",
 			data, data->index);
 	} else {
@@ -1449,23 +1514,20 @@ static int set_ipv6_high_priority_default_gateway_route_cb(
 	int err = 0;
 
 	if (is_gateway_config_vpn(config)) {
-		connman_inet_set_ipv6_gateway_interface(data->index);
-
-		gateway_config_state_set(config,
-			CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
+		err = connman_inet_set_ipv6_gateway_interface(data->index);
+		if (err < 0)
+			goto done;
 
 		DBG("set %p index %d vpn %s index %d phy %s",
 			data, data->index, config->vpn_ip,
 			config->vpn_phy_index,
 			config->vpn_phy_ip);
 	} else if (is_ipv6_addr_any_str(config->gateway)) {
-		if (connman_inet_set_ipv6_gateway_interface(
-					data->index) < 0)
+		err = connman_inet_set_ipv6_gateway_interface(
+					data->index);
+		if (err < 0)
 			goto done;
 
-		gateway_config_state_set(config,
-			CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
-
 		DBG("set %p index %d",
 			data, data->index);
 	} else {
@@ -1570,31 +1632,32 @@ static int unset_ipv4_high_priority_default_gateway_route_cb(
 	int err = 0;
 
 	if (is_gateway_config_vpn(config)) {
-		connman_inet_clear_gateway_interface(data->index);
-
-		gateway_config_state_set(config,
-			CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
+		err = connman_inet_clear_gateway_interface(data->index);
+		if (err < 0)
+			goto done;
 
 		DBG("unset %p index %d vpn %s index %d phy %s",
 			data, data->index, config->vpn_ip,
 			config->vpn_phy_index,
 			config->vpn_phy_ip);
 	} else if (is_ipv4_addr_any_str(config->gateway)) {
-		connman_inet_clear_gateway_interface(data->index);
-
-		gateway_config_state_set(config,
-			CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
+		err = connman_inet_clear_gateway_interface(data->index);
+		if (err < 0)
+			goto done;
 
 		DBG("unset %p index %d",
 			data, data->index);
 	} else {
-		connman_inet_clear_gateway_address(data->index,
+		err = connman_inet_clear_gateway_address(data->index,
 					config->gateway);
+		if (err < 0)
+			goto done;
 
 		DBG("unset %p index %d gateway %s",
 			data, data->index, config->gateway);
 	}
 
+done:
 	return err;
 }
 
@@ -1605,31 +1668,32 @@ static int unset_ipv6_high_priority_default_gateway_route_cb(
 	int err = 0;
 
 	if (is_gateway_config_vpn(config)) {
-		connman_inet_clear_ipv6_gateway_interface(data->index);
-
-		gateway_config_state_set(config,
-			CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
+		err = connman_inet_clear_ipv6_gateway_interface(data->index);
+		if (err < 0)
+			goto done;
 
 		DBG("unset %p index %d vpn %s index %d phy %s",
 			data, data->index, config->vpn_ip,
 			config->vpn_phy_index,
 			config->vpn_phy_ip);
 	} else if (is_ipv6_addr_any_str(config->gateway)) {
-		connman_inet_clear_ipv6_gateway_interface(data->index);
-
-		gateway_config_state_set(config,
-			CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
+		err = connman_inet_clear_ipv6_gateway_interface(data->index);
+		if (err < 0)
+			goto done;
 
 		DBG("unset %p index %d",
 			data, data->index);
 	} else {
-		connman_inet_clear_ipv6_gateway_address(data->index,
+		err = connman_inet_clear_ipv6_gateway_address(data->index,
 					config->gateway);
+		if (err < 0)
+			goto done;
 
 		DBG("unset %p index %d gateway %s",
 			data, data->index, config->gateway);
 	}
 
+done:
 	return err;
 }
 
@@ -1705,6 +1769,98 @@ static int unset_default_gateway(struct gateway_data *data,
 	return mutate_default_gateway(data, type, &ops, __func__);
 }
 
+static uint32_t compute_low_priority_metric(const struct gateway_data *data)
+{
+	static const uint32_t metric_base = UINT32_MAX;
+	static const uint32_t metric_ceiling = (1 << 20);
+	static const uint32_t metric_index_step = (1 << 10);
+
+	return MAX(metric_ceiling,
+				metric_base -
+				(data->index * metric_index_step));
+}
+
+static int set_ipv4_low_priority_default_gateway_route_cb(
+				struct gateway_data *data,
+				struct gateway_config *config)
+{
+	const uint32_t metric = compute_low_priority_metric(data);
+
+	DBG("using metric %u for index %d", metric, data->index);
+
+	return __connman_inet_add_default_to_table_with_metric(
+				RT_TABLE_MAIN,
+				data->index,
+				config->gateway,
+				metric);
+}
+
+static int set_ipv4_low_priority_default_gateway(
+				struct gateway_data *data,
+				struct gateway_config *config)
+{
+	static const enum gateway_config_type type =
+			CONNMAN_GATEWAY_CONFIG_TYPE_LOW_PRIORITY_DEFAULT;
+	static const mutate_default_gateway_route_cb_t cb =
+			set_ipv4_low_priority_default_gateway_route_cb;
+
+	return set_default_gateway_route_common(data, config, type, cb);
+}
+
+static int set_low_priority_default_gateway(struct gateway_data *data,
+				enum connman_ipconfig_type type,
+				const char *function)
+{
+	static const struct mutate_default_gateway_ops ops = {
+		set_ipv4_low_priority_default_gateway,
+		NULL
+	};
+
+	DBG("from %s()", function);
+
+	return mutate_default_gateway(data, type, &ops, __func__);
+}
+
+static int unset_ipv4_low_priority_default_gateway_route_cb(
+				struct gateway_data *data,
+				struct gateway_config *config)
+{
+	const uint32_t metric = compute_low_priority_metric(data);
+
+	DBG("using metric %u for index %d", metric, data->index);
+
+	return __connman_inet_del_default_from_table_with_metric(
+				RT_TABLE_MAIN,
+				data->index,
+				config->gateway,
+				metric);
+}
+
+static int unset_ipv4_low_priority_default_gateway(struct gateway_data *data,
+				struct gateway_config *config)
+{
+	static const enum gateway_config_type type =
+			CONNMAN_GATEWAY_CONFIG_TYPE_LOW_PRIORITY_DEFAULT;
+	static const mutate_default_gateway_route_cb_t cb =
+			unset_ipv4_low_priority_default_gateway_route_cb;
+
+	return unset_default_gateway_route_common(data, config, type, cb);
+}
+
+static int unset_low_priority_default_gateway(struct gateway_data *data,
+				enum connman_ipconfig_type type,
+				const char *function)
+{
+	static const struct mutate_default_gateway_ops ops = {
+		unset_ipv4_low_priority_default_gateway,
+		NULL
+	};
+
+	DBG("from %s()", function);
+
+	return mutate_default_gateway(data, type, &ops, __func__);
+}
+
 /**
  *  @brief
  *    Decide whether either of the specified gateways should yield the
@@ -1774,6 +1930,8 @@ static bool yield_default_gateway_for_type(struct gateway_data *activated,
 				config_type)));
 
 		UNSET_DEFAULT_GATEWAY(existing, type);
+
+		SET_LOW_PRIORITY_DEFAULT_GATEWAY(existing, type);
 	}
 
 	/*
@@ -1794,6 +1952,8 @@ static bool yield_default_gateway_for_type(struct gateway_data *activated,
 
 		UNSET_DEFAULT_GATEWAY(activated, type);
 
+		SET_LOW_PRIORITY_DEFAULT_GATEWAY(activated, type);
+
 		yield_activated = true;
 	}
 
@@ -1878,6 +2038,7 @@ static void check_default_gateway(struct gateway_data *activated)
 {
 	GHashTableIter iter;
 	gpointer value, key;
+	enum connman_ipconfig_type type;
 	bool yield_activated = false;
 
 	DBG("activated %p", activated);
@@ -1913,13 +2074,21 @@ static void check_default_gateway(struct gateway_data *activated)
 	DBG("yield_activated %u", yield_activated);
 
 	if (!yield_activated) {
-		if (activated->ipv4_config)
-			SET_DEFAULT_GATEWAY(activated,
-				CONNMAN_IPCONFIG_TYPE_IPV4);
+		if (activated->ipv4_config) {
+			type = CONNMAN_IPCONFIG_TYPE_IPV4;
+
+			UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(activated, type);
+
+			SET_DEFAULT_GATEWAY(activated, type);
+		}
+
+		if (activated->ipv6_config) {
+			type = CONNMAN_IPCONFIG_TYPE_IPV6;
+
+			UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(activated, type);
 
-		if (activated->ipv6_config)
-			SET_DEFAULT_GATEWAY(activated,
-				CONNMAN_IPCONFIG_TYPE_IPV6);
+			SET_DEFAULT_GATEWAY(activated, type);
+		}
 	}
 
 	activated->default_checked = true;
@@ -1971,11 +2140,23 @@ static void connection_newgateway(int index, const char *gateway)
 
 	GATEWAY_CONFIG_DBG("config", config);
 
+    /*
+     * If the state is removed, then we may have gone a full
+     * added/removed cycle before the added gateway route was even
+     * activated. In this case, it is now a stale added
+     * activation; simply ignore it.
+     */
+	if (is_gateway_config_state_removed(config)) {
+		DBG("ignoring gateway stale added activation; "
+			"probably removed before added activation completed");
+
+		return;
+	}
+
 	/*
-	 * Otherwise, this is a gateway, or default router, route we added
-	 * or set and it is now acknowledged by the kernel. Consequently,
-	 * prospectively mark it as active; however, this may be
-	 * subsequently modified as default route determinations are made.
+	 * Otherwise, this is a gateway default route we added, or set,
+	 * and it is now acknowledged by the kernel. Consequently, mark it
+	 * as active.
 	 */
 	gateway_config_state_set(config,
 		CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
@@ -2095,7 +2276,11 @@ static void connection_delgateway(int index, const char *gateway)
 	if (data) {
 		GATEWAY_DATA_DBG("data", data);
 
-		SET_DEFAULT_GATEWAY(data, CONNMAN_IPCONFIG_TYPE_ALL);
+		UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(data,
+			CONNMAN_IPCONFIG_TYPE_ALL);
+
+		SET_DEFAULT_GATEWAY(data,
+			CONNMAN_IPCONFIG_TYPE_ALL);
 	}
 }
 
@@ -2194,6 +2379,7 @@ int __connman_connection_gateway_add(struct connman_service *service,
 					const char *peer)
 {
 	struct gateway_data *any_active_gateway = NULL;
+	struct gateway_data *default_gateway = NULL;
 	struct gateway_data *new_gateway = NULL;
 	enum connman_service_type service_type;
 	int index;
@@ -2249,6 +2435,10 @@ int __connman_connection_gateway_add(struct connman_service *service,
 
 	GATEWAY_DATA_DBG("any_active_gateway", any_active_gateway);
 
+	default_gateway = find_default_gateway_data();
+
+	GATEWAY_DATA_DBG("default_gateway", default_gateway);
+
 	if (do_ipv4 && new_gateway->ipv4_config) {
 		add_host_route(AF_INET, index, gateway, service_type);
 		__connman_service_nameserver_add_routes(service,
@@ -2284,9 +2474,26 @@ int __connman_connection_gateway_add(struct connman_service *service,
 			gateway_config_clear_vpn(new_gateway->ipv6_config);
 	}
 
+	/*
+	 * If there is no active gateway, then this is the first and only
+	 * gateway. Set the high-priority default route for the gateway
+	 * and service/network interface tuple.
+	 *
+	 * Otherwise, if there is no default gateway either, then set the
+	 * low-priority default route for the gateway and service/network
+	 * interface tuple.
+	 *
+	 * NOTE: Beyond historical momentum, it is not clear that
+	 * '!any_active_gateway' and 'find_any_active_gateway_data' are
+	 * the best fit here. This should likely be '!default_gateway'
+	 * from 'find_default_gateway_data'.
+	 */
 	if (!any_active_gateway) {
 		SET_DEFAULT_GATEWAY(new_gateway, type);
 		goto done;
+	} else if (default_gateway && !is_vpn4 && !is_vpn6) {
+		SET_LOW_PRIORITY_DEFAULT_GATEWAY(new_gateway, type);
+		goto done;
 	}
 
 	if (is_vpn4) {
@@ -2427,8 +2634,11 @@ void __connman_connection_gateway_remove(struct connman_service *service,
 
 		GATEWAY_DATA_DBG("default_data", data);
 
-		if (data)
+		if (data) {
+			UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(data, type);
+
 			SET_DEFAULT_GATEWAY(data, type);
+		}
 	}
 }
 
@@ -2453,9 +2663,11 @@ void __connman_connection_gateway_remove(struct connman_service *service,
 bool __connman_connection_update_gateway(void)
 {
 	struct gateway_data *default_gateway;
-	bool updated = false;
 	GHashTableIter iter;
 	gpointer value, key;
+	enum connman_ipconfig_type type;
+	int set_status = 0, unset_status = 0;
+	bool updated4 = false, updated6 = false;
 
 	DBG("");
 
@@ -2464,7 +2676,7 @@ bool __connman_connection_update_gateway(void)
 	 * nothing to update and do; simply return.
 	 */
 	if (!gateway_hash)
-		return updated;
+		goto done;
 
 	default_gateway = find_default_gateway_data();
 
@@ -2487,43 +2699,76 @@ bool __connman_connection_update_gateway(void)
 		if (current_gateway->ipv4_config &&
 				is_gateway_config_state_active(
 					current_gateway->ipv4_config)) {
+			type = CONNMAN_IPCONFIG_TYPE_IPV4;
 
-			UNSET_DEFAULT_GATEWAY(current_gateway,
-						CONNMAN_IPCONFIG_TYPE_IPV4);
-			updated = true;
+			unset_status =
+				UNSET_DEFAULT_GATEWAY(
+					current_gateway,
+					type);
+
+			set_status =
+				SET_LOW_PRIORITY_DEFAULT_GATEWAY(
+					current_gateway,
+					type);
+
+			updated4 = (unset_status == 0 || set_status == 0);
 		}
 
 		if (current_gateway->ipv6_config &&
 				is_gateway_config_state_active(
 					current_gateway->ipv6_config)) {
+			type = CONNMAN_IPCONFIG_TYPE_IPV6;
 
-			UNSET_DEFAULT_GATEWAY(current_gateway,
-						CONNMAN_IPCONFIG_TYPE_IPV6);
-			updated = true;
+			unset_status =
+				UNSET_DEFAULT_GATEWAY(
+					current_gateway,
+					type);
+
+			set_status =
+				SET_LOW_PRIORITY_DEFAULT_GATEWAY(
+					current_gateway,
+					type);
+
+			updated6 = (unset_status == 0 || set_status == 0);
 		}
 	}
 
+	DBG("updated4 %u updated6 %u", updated4, updated6);
+
 	/*
 	 * Set default gateway if it has been updated or if it has not been
 	 * set as active yet.
 	 */
 	if (default_gateway) {
 		if (default_gateway->ipv4_config &&
-			(updated ||
+			(updated4 ||
 			!is_gateway_config_state_active(
-				default_gateway->ipv4_config)))
+				default_gateway->ipv4_config))) {
+			type = CONNMAN_IPCONFIG_TYPE_IPV4;
+
+			UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(default_gateway,
+				type);
+
 			SET_DEFAULT_GATEWAY(default_gateway,
-					CONNMAN_IPCONFIG_TYPE_IPV4);
+				type);
+		}
 
 		if (default_gateway->ipv6_config &&
-			(updated ||
+			(updated6 ||
 			!is_gateway_config_state_active(
-				default_gateway->ipv6_config)))
+				default_gateway->ipv6_config))) {
+			type = CONNMAN_IPCONFIG_TYPE_IPV6;
+
+			UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(default_gateway,
+				type);
+
 			SET_DEFAULT_GATEWAY(default_gateway,
-					CONNMAN_IPCONFIG_TYPE_IPV6);
+				type);
+		}
 	}
 
-	return updated;
+done:
+	return updated4 || updated6;
 }
 
 int __connman_connection_get_vpn_index(int phy_index)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 53/90] connection: Introduce '{de,pro}mote_default_gateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (54 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 52/90] connection: Add support for low-priority default routes Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 54/90] connection: Add 'is_addr_any_str' Grant Erickson
                   ` (36 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

There are 10 instances of either:

    UNSET_DEFAULT_GATEWAY(data, type);

    SET_LOW_PRIORITY_DEFAULT_GATEWAY(data, type);

or:

    UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(data, type);

    SET_DEFAULT_GATEWAY(data, type);

This formalizes the former as 'demote_default_gateway' and the latter
as 'promote_default_gateway'.

In addition, '{DE,PRO}MOTE_DEFAULT_GATEWAY' macros are added and
leveraged at those 10 call sites. These macros invoke
'{de,pro}mote_default_gateway', passing the C preprocessor predefined
'__func__' macro as the function parameter.
---
 src/connection.c | 181 ++++++++++++++++++++++++++---------------------
 1 file changed, 100 insertions(+), 81 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index d41c4010bb61..1f8152e7a7e4 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -50,6 +50,12 @@
 #define UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(data, type) \
 	unset_low_priority_default_gateway(data, type, __func__)
 
+#define PROMOTE_DEFAULT_GATEWAY(data, type) \
+	promote_default_gateway(data, type, __func__)
+
+#define DEMOTE_DEFAULT_GATEWAY(data, type) \
+	demote_default_gateway(data, type, __func__)
+
 #define GATEWAY_CONFIG_DBG(description, config) \
 	gateway_config_debug(__func__, description, config)
 
@@ -1861,6 +1867,58 @@ static int unset_low_priority_default_gateway(struct gateway_data *data,
 	return mutate_default_gateway(data, type, &ops, __func__);
 }
 
+static int demote_default_gateway(struct gateway_data *data,
+				enum connman_ipconfig_type type,
+				const char *function)
+{
+	int unset_status = 0, set_status = 0;
+
+	DBG("from %s() data %p type %d (%s)",
+		function,
+		data,
+		type, __connman_ipconfig_type2string(type));
+
+	unset_status = UNSET_DEFAULT_GATEWAY(data, type);
+
+	set_status = SET_LOW_PRIORITY_DEFAULT_GATEWAY(data, type);
+
+	DBG("unset_status %d (%s) set_status %d (%s)",
+		unset_status, strerror(-unset_status),
+		set_status, strerror(-set_status));
+
+	/*
+	 * Prefer unset status to set status since unsetting is what effects
+	 * the priority demotion.
+	 */
+	return (unset_status == 0 ? unset_status : set_status);
+}
+
+static int promote_default_gateway(struct gateway_data *data,
+				enum connman_ipconfig_type type,
+				const char *function)
+{
+	int unset_status = 0, set_status = 0;
+
+	DBG("from %s() data %p type %d (%s)",
+		function,
+		data,
+		type, __connman_ipconfig_type2string(type));
+
+	unset_status = UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(data, type);
+
+	set_status = SET_DEFAULT_GATEWAY(data, type);
+
+	DBG("unset_status %d (%s) set_status %d (%s)",
+		unset_status, strerror(-unset_status),
+		set_status, strerror(-set_status));
+
+	/*
+	 * Prefer set status to unset status since setting is what effects
+	 * the priority promotion.
+	 */
+	return (set_status == 0 ? set_status : unset_status);
+}
+
 /**
  *  @brief
  *    Decide whether either of the specified gateways should yield the
@@ -1929,9 +1987,7 @@ static bool yield_default_gateway_for_type(struct gateway_data *activated,
 			maybe_null(gateway_config_type2string(
 				config_type)));
 
-		UNSET_DEFAULT_GATEWAY(existing, type);
-
-		SET_LOW_PRIORITY_DEFAULT_GATEWAY(existing, type);
+		DEMOTE_DEFAULT_GATEWAY(existing, type);
 	}
 
 	/*
@@ -1950,9 +2006,7 @@ static bool yield_default_gateway_for_type(struct gateway_data *activated,
 			maybe_null(gateway_config_type2string(
 				config_type)));
 
-		UNSET_DEFAULT_GATEWAY(activated, type);
-
-		SET_LOW_PRIORITY_DEFAULT_GATEWAY(activated, type);
+		DEMOTE_DEFAULT_GATEWAY(activated, type);
 
 		yield_activated = true;
 	}
@@ -2038,7 +2092,6 @@ static void check_default_gateway(struct gateway_data *activated)
 {
 	GHashTableIter iter;
 	gpointer value, key;
-	enum connman_ipconfig_type type;
 	bool yield_activated = false;
 
 	DBG("activated %p", activated);
@@ -2074,21 +2127,13 @@ static void check_default_gateway(struct gateway_data *activated)
 	DBG("yield_activated %u", yield_activated);
 
 	if (!yield_activated) {
-		if (activated->ipv4_config) {
-			type = CONNMAN_IPCONFIG_TYPE_IPV4;
-
-			UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(activated, type);
-
-			SET_DEFAULT_GATEWAY(activated, type);
-		}
-
-		if (activated->ipv6_config) {
-			type = CONNMAN_IPCONFIG_TYPE_IPV6;
+		if (activated->ipv4_config)
+			PROMOTE_DEFAULT_GATEWAY(activated,
+				CONNMAN_IPCONFIG_TYPE_IPV4);
 
-			UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(activated, type);
-
-			SET_DEFAULT_GATEWAY(activated, type);
-		}
+		if (activated->ipv6_config)
+			PROMOTE_DEFAULT_GATEWAY(activated,
+				CONNMAN_IPCONFIG_TYPE_IPV6);
 	}
 
 	activated->default_checked = true;
@@ -2276,11 +2321,7 @@ static void connection_delgateway(int index, const char *gateway)
 	if (data) {
 		GATEWAY_DATA_DBG("data", data);
 
-		UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(data,
-			CONNMAN_IPCONFIG_TYPE_ALL);
-
-		SET_DEFAULT_GATEWAY(data,
-			CONNMAN_IPCONFIG_TYPE_ALL);
+		PROMOTE_DEFAULT_GATEWAY(data, CONNMAN_IPCONFIG_TYPE_ALL);
 	}
 }
 
@@ -2634,11 +2675,8 @@ void __connman_connection_gateway_remove(struct connman_service *service,
 
 		GATEWAY_DATA_DBG("default_data", data);
 
-		if (data) {
-			UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(data, type);
-
-			SET_DEFAULT_GATEWAY(data, type);
-		}
+		if (data)
+			PROMOTE_DEFAULT_GATEWAY(data, type);
 	}
 }
 
@@ -2666,7 +2704,7 @@ bool __connman_connection_update_gateway(void)
 	GHashTableIter iter;
 	gpointer value, key;
 	enum connman_ipconfig_type type;
-	int set_status = 0, unset_status = 0;
+	int status = 0;
 	bool updated4 = false, updated6 = false;
 
 	DBG("");
@@ -2690,46 +2728,35 @@ bool __connman_connection_update_gateway(void)
 
 	while (g_hash_table_iter_next(&iter, &key, &value)) {
 		struct gateway_data *current_gateway = value;
+		struct gateway_config *current_config;
 
 		GATEWAY_DATA_DBG("current_gateway", current_gateway);
 
 		if (current_gateway == default_gateway)
 			continue;
 
-		if (current_gateway->ipv4_config &&
-				is_gateway_config_state_active(
-					current_gateway->ipv4_config)) {
-			type = CONNMAN_IPCONFIG_TYPE_IPV4;
-
-			unset_status =
-				UNSET_DEFAULT_GATEWAY(
-					current_gateway,
-					type);
+		type = CONNMAN_IPCONFIG_TYPE_IPV4;
+		current_config = gateway_data_config_get(current_gateway, type);
 
-			set_status =
-				SET_LOW_PRIORITY_DEFAULT_GATEWAY(
-					current_gateway,
-					type);
+		if (current_config &&
+				is_gateway_config_state_active(
+					current_config)) {
+			status = DEMOTE_DEFAULT_GATEWAY(current_gateway,
+						type);
 
-			updated4 = (unset_status == 0 || set_status == 0);
+			updated4 = status == 0;
 		}
 
-		if (current_gateway->ipv6_config &&
-				is_gateway_config_state_active(
-					current_gateway->ipv6_config)) {
-			type = CONNMAN_IPCONFIG_TYPE_IPV6;
+		type = CONNMAN_IPCONFIG_TYPE_IPV6;
+		current_config = gateway_data_config_get(current_gateway, type);
 
-			unset_status =
-				UNSET_DEFAULT_GATEWAY(
-					current_gateway,
-					type);
-
-			set_status =
-				SET_LOW_PRIORITY_DEFAULT_GATEWAY(
-					current_gateway,
-					type);
+		if (current_config &&
+				is_gateway_config_state_active(
+					current_config)) {
+			status = DEMOTE_DEFAULT_GATEWAY(current_gateway,
+						type);
 
-			updated6 = (unset_status == 0 || set_status == 0);
+			updated6 = status == 0;
 		}
 	}
 
@@ -2740,31 +2767,23 @@ bool __connman_connection_update_gateway(void)
 	 * set as active yet.
 	 */
 	if (default_gateway) {
-		if (default_gateway->ipv4_config &&
-			(updated4 ||
-			!is_gateway_config_state_active(
-				default_gateway->ipv4_config))) {
-			type = CONNMAN_IPCONFIG_TYPE_IPV4;
+		const struct gateway_config *default_config;
 
-			UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(default_gateway,
-				type);
+		type = CONNMAN_IPCONFIG_TYPE_IPV4;
+		default_config = gateway_data_config_get(default_gateway, type);
 
-			SET_DEFAULT_GATEWAY(default_gateway,
-				type);
-		}
-
-		if (default_gateway->ipv6_config &&
-			(updated6 ||
-			!is_gateway_config_state_active(
-				default_gateway->ipv6_config))) {
-			type = CONNMAN_IPCONFIG_TYPE_IPV6;
+		if (default_config &&
+			(updated4 ||
+			!is_gateway_config_state_active(default_config)))
+			PROMOTE_DEFAULT_GATEWAY(default_gateway, type);
 
-			UNSET_LOW_PRIORITY_DEFAULT_GATEWAY(default_gateway,
-				type);
+		type = CONNMAN_IPCONFIG_TYPE_IPV6;
+		default_config = gateway_data_config_get(default_gateway, type);
 
-			SET_DEFAULT_GATEWAY(default_gateway,
-				type);
-		}
+		if (default_config &&
+			(updated6 ||
+			!is_gateway_config_state_active(default_config)))
+			PROMOTE_DEFAULT_GATEWAY(default_gateway, type);
 	}
 
 done:
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 54/90] connection: Add 'is_addr_any_str'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (55 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 53/90] connection: Introduce '{de,pro}mote_default_gateway' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 55/90] connection: Introduce gateway config 'ops' Grant Erickson
                   ` (35 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds 'is_addr_any_str' which can successfully determine whether a
specified text-formatted IP address is the "any" or "unspecified"
address for either an IPv4 or an IPv6 address.

Application of 'is_addr_any_str' helps neutralize any/unspecified
address string comparisons and moves IPv4- and IPv6-specific blocks of
code closer to unification.
---
 src/connection.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 1f8152e7a7e4..cfae70f2055c 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -620,6 +620,15 @@ static bool is_ipv6_addr_any_str(const char *address)
 	return g_strcmp0(ipv6_addr_any_str, address) == 0;
 }
 
+static bool is_addr_any_str(const char *address)
+{
+	if (!address)
+		return false;
+
+	return (!strchr(address, ':') && is_ipv4_addr_any_str(address)) ||
+				is_ipv6_addr_any_str(address);
+}
+
 /**
  *  @brief
  *    Find the gateway, or default router, configuration associated
@@ -934,7 +943,7 @@ static void set_vpn_routes(struct gateway_data *new_gateway,
 
 		DBG("active gw %s", active_gateway->ipv4_config->gateway);
 
-		if (!is_ipv4_addr_any_str(active_gateway->ipv4_config->gateway))
+		if (!is_addr_any_str(active_gateway->ipv4_config->gateway))
 			dest = active_gateway->ipv4_config->gateway;
 		else
 			dest = NULL;
@@ -953,7 +962,7 @@ static void set_vpn_routes(struct gateway_data *new_gateway,
 
 		DBG("active gw %s", active_gateway->ipv6_config->gateway);
 
-		if (!is_ipv6_addr_any_str(active_gateway->ipv6_config->gateway))
+		if (!is_addr_any_str(active_gateway->ipv6_config->gateway))
 			dest = active_gateway->ipv6_config->gateway;
 		else
 			dest = NULL;
@@ -1489,7 +1498,7 @@ static int set_ipv4_high_priority_default_gateway_route_cb(
 			data, data->index, config->vpn_ip,
 			config->vpn_phy_index,
 			config->vpn_phy_ip);
-	} else if (is_ipv4_addr_any_str(config->gateway)) {
+	} else if (is_addr_any_str(config->gateway)) {
 		err = connman_inet_set_gateway_interface(
 					data->index);
 		if (err < 0)
@@ -1528,7 +1537,7 @@ static int set_ipv6_high_priority_default_gateway_route_cb(
 			data, data->index, config->vpn_ip,
 			config->vpn_phy_index,
 			config->vpn_phy_ip);
-	} else if (is_ipv6_addr_any_str(config->gateway)) {
+	} else if (is_addr_any_str(config->gateway)) {
 		err = connman_inet_set_ipv6_gateway_interface(
 					data->index);
 		if (err < 0)
@@ -1646,7 +1655,7 @@ static int unset_ipv4_high_priority_default_gateway_route_cb(
 			data, data->index, config->vpn_ip,
 			config->vpn_phy_index,
 			config->vpn_phy_ip);
-	} else if (is_ipv4_addr_any_str(config->gateway)) {
+	} else if (is_addr_any_str(config->gateway)) {
 		err = connman_inet_clear_gateway_interface(data->index);
 		if (err < 0)
 			goto done;
@@ -1682,7 +1691,7 @@ static int unset_ipv6_high_priority_default_gateway_route_cb(
 			data, data->index, config->vpn_ip,
 			config->vpn_phy_index,
 			config->vpn_phy_ip);
-	} else if (is_ipv6_addr_any_str(config->gateway)) {
+	} else if (is_addr_any_str(config->gateway)) {
 		err = connman_inet_clear_ipv6_gateway_interface(data->index);
 		if (err < 0)
 			goto done;
@@ -2336,7 +2345,7 @@ static void add_host_route(int family, int index, const char *gateway,
 {
 	switch (family) {
 	case AF_INET:
-		if (!is_ipv4_addr_any_str(gateway)) {
+		if (!is_addr_any_str(gateway)) {
 			/*
 			 * We must not set route to the phy dev gateway in
 			 * VPN link. The packets to VPN link might be routed
@@ -2361,7 +2370,7 @@ static void add_host_route(int family, int index, const char *gateway,
 		break;
 
 	case AF_INET6:
-		if (!is_ipv6_addr_any_str(gateway)) {
+		if (!is_addr_any_str(gateway)) {
 			if (service_type != CONNMAN_SERVICE_TYPE_VPN)
 				connman_inet_add_ipv6_host_route(index,
 								gateway, NULL);
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 55/90] connection: Introduce gateway config 'ops'
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (56 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 54/90] connection: Add 'is_addr_any_str' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 56/90] connection: Refactor 'add_host_route' Grant Erickson
                   ` (34 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This introduces a gateway configuration 'ops' data structure of IPv4-
and IPv6-specific addressing and routing functions.

With this introduction, all accesses to these functions are done
through a pointer to an "ops" structure. This further neutralizes
IPv4- and IPv6-specific code blocks and clears a path towards their
unification.
---
 src/connection.c | 164 ++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 134 insertions(+), 30 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index cfae70f2055c..023501c81895 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -140,6 +140,39 @@ enum gateway_config_type {
 	CONNMAN_GATEWAY_CONFIG_TYPE_LOW_PRIORITY_DEFAULT  = 2
 };
 
+struct gateway_config_ops {
+	bool (*compare_subnet)(int index,
+		const char *address);
+
+	int (*get_dest_addr)(int index,
+		char **dest);
+
+	int (*add_interface_route)(int index);
+	int (*del_interface_route)(int index);
+
+	int (*add_default_route)(uint32_t table,
+		int index,
+		const char *gateway);
+	int (*del_default_route)(uint32_t table,
+		int index,
+		const char *gateway);
+
+	int (*add_default_route_with_metric)(uint32_t table,
+		int index,
+		const char *gateway,
+		uint32_t metric);
+	int (*del_default_route_with_metric)(uint32_t table,
+		int index,
+		const char *gateway,
+		uint32_t metric);
+
+	int (*add_host_route)(int index,
+		const char *gateway,
+		const char *host);
+	int (*del_host_route)(int index,
+		const char *gateway);
+};
+
 struct gateway_config {
 	/**
 	 *	A 32-bit flag bitfield governing the state and use of the
@@ -158,6 +191,7 @@ struct gateway_config {
 	 *	See #gateway_config_type.
 	 */
 	enum gateway_config_type type;
+	const struct gateway_config_ops *ops;
 	char *gateway;
 
 	/* VPN extra data */
@@ -242,6 +276,62 @@ static int unset_low_priority_default_gateway(struct gateway_data *data,
 				enum connman_ipconfig_type type,
 				const char *function);
 
+static const struct gateway_config_ops ipv4_gateway_config_ops = {
+	.compare_subnet				   =
+		connman_inet_compare_subnet,
+
+	.get_dest_addr				   =
+		connman_inet_get_dest_addr,
+
+	.add_interface_route		   =
+		connman_inet_set_gateway_interface,
+	.del_interface_route		   =
+		connman_inet_clear_gateway_interface,
+
+	.add_default_route			   =
+		__connman_inet_add_default_to_table,
+	.del_default_route			   =
+		__connman_inet_del_default_from_table,
+
+	.add_default_route_with_metric =
+		__connman_inet_add_default_to_table_with_metric,
+	.del_default_route_with_metric =
+		__connman_inet_del_default_from_table_with_metric,
+
+	.add_host_route				   =
+		connman_inet_add_host_route,
+	.del_host_route				   =
+		connman_inet_del_host_route
+};
+
+static const struct gateway_config_ops ipv6_gateway_config_ops = {
+	.compare_subnet				   =
+		connman_inet_compare_ipv6_subnet,
+
+	.get_dest_addr				   =
+		connman_inet_ipv6_get_dest_addr,
+
+	.add_interface_route		   =
+		connman_inet_set_ipv6_gateway_interface,
+	.del_interface_route		   =
+		connman_inet_clear_ipv6_gateway_interface,
+
+	.add_default_route			   =
+		__connman_inet_add_default_to_table,
+	.del_default_route			   =
+		__connman_inet_del_default_from_table,
+
+	.add_default_route_with_metric =
+		__connman_inet_add_default_to_table_with_metric,
+	.del_default_route_with_metric =
+		__connman_inet_del_default_from_table_with_metric,
+
+	.add_host_route				   =
+		connman_inet_add_ipv6_host_route,
+	.del_host_route				   =
+		connman_inet_del_ipv6_host_route
+};
+
 /*
  * These are declared as 'const char *const' to effect an immutable
  * pointer to an immutable null-terminated character string such that
@@ -451,6 +541,7 @@ static void gateway_config_debug(const char *function,
 		DBG("from %s() "
 			"%s %p: { state: %d (%s), type %d (%s), "
 			"flags: 0x%x (%s), "
+			"ops: %p, "
 			"gateway: %p (%s), "
 			"vpn_ip: %p (%s), vpn_phy_index: %d (%s), "
 			"vpn_phy_ip: %p (%s) }",
@@ -463,6 +554,7 @@ static void gateway_config_debug(const char *function,
 			maybe_null(gateway_config_type2string(config->type)),
 			config->flags,
 			is_gateway_config_vpn(config) ? "VPN" : "",
+			config->ops,
 			config->gateway, maybe_null(config->gateway),
 			config->vpn_ip, maybe_null(config->vpn_ip),
 			config->vpn_phy_index, maybe_null(vpn_phy_interface),
@@ -937,7 +1029,7 @@ static void set_vpn_routes(struct gateway_data *new_gateway,
 		 * If VPN server is on same subnet as we are, skip adding
 		 * route.
 		 */
-		if (connman_inet_compare_subnet(active_gateway->index,
+		if (config->ops->compare_subnet(active_gateway->index,
 								gateway))
 			return;
 
@@ -948,15 +1040,17 @@ static void set_vpn_routes(struct gateway_data *new_gateway,
 		else
 			dest = NULL;
 
-		connman_inet_add_host_route(active_gateway->index, gateway,
-									dest);
+		active_gateway->ipv4_config->ops->add_host_route(
+							active_gateway->index,
+							gateway,
+							dest);
 
 	} else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
 
 		if (!active_gateway->ipv6_config)
 			return;
 
-		if (connman_inet_compare_ipv6_subnet(active_gateway->index,
+		if (config->ops->compare_subnet(active_gateway->index,
 								gateway))
 			return;
 
@@ -967,8 +1061,10 @@ static void set_vpn_routes(struct gateway_data *new_gateway,
 		else
 			dest = NULL;
 
-		connman_inet_add_ipv6_host_route(active_gateway->index,
-								gateway, dest);
+		active_gateway->ipv6_config->ops->add_host_route(
+							active_gateway->index,
+							gateway,
+							dest);
 	}
 }
 
@@ -1039,7 +1135,8 @@ static int del_gateway_routes(struct gateway_data *data,
 						data->ipv4_config->vpn_ip);
 
 		} else {
-			connman_inet_del_host_route(data->index,
+			data->ipv4_config->ops->del_host_route(
+						data->index,
 						data->ipv4_config->gateway);
 
 			status4 = UNSET_DEFAULT_GATEWAY(data, type);
@@ -1055,7 +1152,8 @@ static int del_gateway_routes(struct gateway_data *data,
 						data->ipv6_config->vpn_ip);
 
 		} else {
-			connman_inet_del_ipv6_host_route(data->index,
+			data->ipv6_config->ops->del_host_route(
+						data->index,
 						data->ipv6_config->gateway);
 
 			status6 = UNSET_DEFAULT_GATEWAY(data, type);
@@ -1232,10 +1330,13 @@ static int add_gateway(struct connman_service *service,
 	config->vpn_phy_ip = NULL;
 	config->vpn_phy_index = -1;
 
-	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
 		temp_data->ipv4_config = config;
-	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+		temp_data->ipv4_config->ops = &ipv4_gateway_config_ops;
+	} else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
 		temp_data->ipv6_config = config;
+		temp_data->ipv6_config->ops = &ipv6_gateway_config_ops;
+	}
 
 	temp_data->service = service;
 
@@ -1490,7 +1591,7 @@ static int set_ipv4_high_priority_default_gateway_route_cb(
 	int err = 0;
 
 	if (is_gateway_config_vpn(config)) {
-		err = connman_inet_set_gateway_interface(data->index);
+		err = config->ops->add_interface_route(data->index);
 		if (err < 0)
 			goto done;
 
@@ -1499,15 +1600,14 @@ static int set_ipv4_high_priority_default_gateway_route_cb(
 			config->vpn_phy_index,
 			config->vpn_phy_ip);
 	} else if (is_addr_any_str(config->gateway)) {
-		err = connman_inet_set_gateway_interface(
-					data->index);
+		err = config->ops->add_interface_route(data->index);
 		if (err < 0)
 			goto done;
 
 		DBG("set %p index %d",
 			data, data->index);
 	} else {
-		err = __connman_inet_add_default_to_table(
+		err = config->ops->add_default_route(
 					RT_TABLE_MAIN,
 					data->index,
 					config->gateway);
@@ -1529,7 +1629,7 @@ static int set_ipv6_high_priority_default_gateway_route_cb(
 	int err = 0;
 
 	if (is_gateway_config_vpn(config)) {
-		err = connman_inet_set_ipv6_gateway_interface(data->index);
+		err = config->ops->add_interface_route(data->index);
 		if (err < 0)
 			goto done;
 
@@ -1538,15 +1638,14 @@ static int set_ipv6_high_priority_default_gateway_route_cb(
 			config->vpn_phy_index,
 			config->vpn_phy_ip);
 	} else if (is_addr_any_str(config->gateway)) {
-		err = connman_inet_set_ipv6_gateway_interface(
-					data->index);
+		err = config->ops->add_interface_route(data->index);
 		if (err < 0)
 			goto done;
 
 		DBG("set %p index %d",
 			data, data->index);
 	} else {
-		err = __connman_inet_add_default_to_table(
+		err = config->ops->add_default_route(
 					RT_TABLE_MAIN,
 					data->index,
 					config->gateway);
@@ -1647,7 +1746,7 @@ static int unset_ipv4_high_priority_default_gateway_route_cb(
 	int err = 0;
 
 	if (is_gateway_config_vpn(config)) {
-		err = connman_inet_clear_gateway_interface(data->index);
+		err = config->ops->del_interface_route(data->index);
 		if (err < 0)
 			goto done;
 
@@ -1656,14 +1755,16 @@ static int unset_ipv4_high_priority_default_gateway_route_cb(
 			config->vpn_phy_index,
 			config->vpn_phy_ip);
 	} else if (is_addr_any_str(config->gateway)) {
-		err = connman_inet_clear_gateway_interface(data->index);
+		err = config->ops->del_interface_route(data->index);
 		if (err < 0)
 			goto done;
 
 		DBG("unset %p index %d",
 			data, data->index);
 	} else {
-		err = connman_inet_clear_gateway_address(data->index,
+		err = config->ops->del_default_route(
+					RT_TABLE_MAIN,
+					data->index,
 					config->gateway);
 		if (err < 0)
 			goto done;
@@ -1683,7 +1784,7 @@ static int unset_ipv6_high_priority_default_gateway_route_cb(
 	int err = 0;
 
 	if (is_gateway_config_vpn(config)) {
-		err = connman_inet_clear_ipv6_gateway_interface(data->index);
+		err = config->ops->del_interface_route(data->index);
 		if (err < 0)
 			goto done;
 
@@ -1692,14 +1793,16 @@ static int unset_ipv6_high_priority_default_gateway_route_cb(
 			config->vpn_phy_index,
 			config->vpn_phy_ip);
 	} else if (is_addr_any_str(config->gateway)) {
-		err = connman_inet_clear_ipv6_gateway_interface(data->index);
+		err = config->ops->del_interface_route(data->index);
 		if (err < 0)
 			goto done;
 
 		DBG("unset %p index %d",
 			data, data->index);
 	} else {
-		err = connman_inet_clear_ipv6_gateway_address(data->index,
+		err = config->ops->del_default_route(
+					RT_TABLE_MAIN,
+					data->index,
 					config->gateway);
 		if (err < 0)
 			goto done;
@@ -1803,7 +1906,7 @@ static int set_ipv4_low_priority_default_gateway_route_cb(
 
 	DBG("using metric %u for index %d", metric, data->index);
 
-	return __connman_inet_add_default_to_table_with_metric(
+	return config->ops->add_default_route_with_metric(
 				RT_TABLE_MAIN,
 				data->index,
 				config->gateway,
@@ -1844,7 +1947,7 @@ static int unset_ipv4_low_priority_default_gateway_route_cb(
 
 	DBG("using metric %u for index %d", metric, data->index);
 
-	return __connman_inet_del_default_from_table_with_metric(
+	return config->ops->del_default_route_with_metric(
 				RT_TABLE_MAIN,
 				data->index,
 				config->gateway,
@@ -2647,13 +2750,14 @@ void __connman_connection_gateway_remove(struct connman_service *service,
     /* If necessary, delete any VPN-related host routes. */
 
 	if (is_vpn4 && data->index >= 0)
-		connman_inet_del_host_route(data->ipv4_config->vpn_phy_index,
-						data->ipv4_config->gateway);
+		data->ipv4_config->ops->del_host_route(
+					data->ipv4_config->vpn_phy_index,
+					data->ipv4_config->gateway);
 
 	if (is_vpn6 && data->index >= 0)
-		connman_inet_del_ipv6_host_route(
+		data->ipv6_config->ops->del_host_route(
 					data->ipv6_config->vpn_phy_index,
-						data->ipv6_config->gateway);
+					data->ipv6_config->gateway);
 
 	/* Remove all active routes associated with this gateway data. */
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 56/90] connection: Refactor 'add_host_route'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (57 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 55/90] connection: Introduce gateway config 'ops' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 57/90] connection: Add 'DBG' else clauses to 'connection_delgateway' Grant Erickson
                   ` (33 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This refactors 'add_host_route' to take advantage of the
recently-introduced gateway configuration 'ops'.

This faciliates collapsing the IPv4- and IPv6-specific sub-blocks into
one, hanlding both IPv4 and IPv6.
---
 src/connection.c | 74 +++++++++++++++++++++---------------------------
 1 file changed, 32 insertions(+), 42 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 023501c81895..771f9eaccc28 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2443,51 +2443,39 @@ static struct connman_rtnl connection_rtnl = {
 	.delgateway	= connection_delgateway,
 };
 
-static void add_host_route(int family, int index, const char *gateway,
+static void add_host_route(struct gateway_data *data,
+			enum connman_ipconfig_type ipconfig_type,
 			enum connman_service_type service_type)
 {
-	switch (family) {
-	case AF_INET:
-		if (!is_addr_any_str(gateway)) {
-			/*
-			 * We must not set route to the phy dev gateway in
-			 * VPN link. The packets to VPN link might be routed
-			 * back to itself and not routed into phy link gateway.
-			 */
-			if (service_type != CONNMAN_SERVICE_TYPE_VPN)
-				connman_inet_add_host_route(index, gateway,
-									NULL);
-		} else {
-			/*
-			 * Add host route to P-t-P link so that services can
-			 * be moved around and we can have some link to P-t-P
-			 * network (although those P-t-P links have limited
-			 * usage if default route is not directed to them)
-			 */
-			char *dest;
-			if (connman_inet_get_dest_addr(index, &dest) == 0) {
-				connman_inet_add_host_route(index, dest, NULL);
-				g_free(dest);
-			}
-		}
-		break;
+	const struct gateway_config *const config =
+		gateway_data_config_get(data, ipconfig_type);
 
-	case AF_INET6:
-		if (!is_addr_any_str(gateway)) {
-			if (service_type != CONNMAN_SERVICE_TYPE_VPN)
-				connman_inet_add_ipv6_host_route(index,
-								gateway, NULL);
-		} else {
-			/* P-t-P link, add route to destination */
-			char *dest;
-			if (connman_inet_ipv6_get_dest_addr(index,
-								&dest) == 0) {
-				connman_inet_add_ipv6_host_route(index, dest,
+	if (!config)
+		return;
+
+	if (!is_addr_any_str(config->gateway)) {
+		/*
+		 * We must not set route to the phy dev gateway in
+		 * VPN link. The packets to VPN link might be routed
+		 * back to itself and not routed into phy link gateway.
+		 */
+		if (service_type != CONNMAN_SERVICE_TYPE_VPN)
+			config->ops->add_host_route(data->index,
+								config->gateway,
 								NULL);
-				g_free(dest);
-			}
+	} else {
+		/*
+		 * Add host route to P-t-P link so that services can
+		 * be moved around and we can have some link to P-t-P
+		 * network (although those P-t-P links have limited
+		 * usage if default route is not directed to them)
+		 */
+		char *dest;
+
+		if (config->ops->get_dest_addr(data->index, &dest) == 0) {
+			config->ops->add_host_route(data->index, dest, NULL);
+			g_free(dest);
 		}
-		break;
 	}
 }
 
@@ -2593,13 +2581,15 @@ int __connman_connection_gateway_add(struct connman_service *service,
 	GATEWAY_DATA_DBG("default_gateway", default_gateway);
 
 	if (do_ipv4 && new_gateway->ipv4_config) {
-		add_host_route(AF_INET, index, gateway, service_type);
+		add_host_route(new_gateway, type, service_type);
+
 		__connman_service_nameserver_add_routes(service,
 					new_gateway->ipv4_config->gateway);
 	}
 
 	if (do_ipv6 && new_gateway->ipv6_config) {
-		add_host_route(AF_INET6, index, gateway, service_type);
+		add_host_route(new_gateway, type, service_type);
+
 		__connman_service_nameserver_add_routes(service,
 					new_gateway->ipv6_config->gateway);
 	}
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 57/90] connection: Add 'DBG' else clauses to 'connection_delgateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (58 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 56/90] connection: Refactor 'add_host_route' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 58/90] connection: Document 'gateway_config_state' finite state machine Grant Erickson
                   ` (32 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This adds 'DBG' else clauses to 'connection_delgateway' to aid in
debugging cases that otherwise "skip out" of 'connection_delgateway'.
---
 src/connection.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 771f9eaccc28..68c919049f20 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2421,7 +2421,8 @@ static void connection_delgateway(int index, const char *gateway)
 
 		gateway_config_type_set(config,
 			CONNMAN_GATEWAY_CONFIG_TYPE_NONE);
-	}
+	} else
+		DBG("no matching gateway config");
 
 	/*
 	 * Due to the newly-removed gateway route, there may have been a
@@ -2434,7 +2435,8 @@ static void connection_delgateway(int index, const char *gateway)
 		GATEWAY_DATA_DBG("data", data);
 
 		PROMOTE_DEFAULT_GATEWAY(data, CONNMAN_IPCONFIG_TYPE_ALL);
-	}
+	} else
+		DBG("no default gateway data");
 }
 
 static struct connman_rtnl connection_rtnl = {
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 58/90] connection: Document 'gateway_config_state' finite state machine.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (59 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 57/90] connection: Add 'DBG' else clauses to 'connection_delgateway' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 59/90] connection: Document 'gateway_config_ops' Grant Erickson
                   ` (31 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This documents the finite state machine (FSM) implied by
'gateway_config_state' and the implementation leveraging it.
---
 src/connection.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/connection.c b/src/connection.c
index 68c919049f20..2022a64727d6 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -88,7 +88,30 @@ enum gateway_config_flags {
  *  Netlink (rtnl) to confirm and "activate" those routes. Likewise,
  *  Connection Manager removes/clears/deletes gateway routes an then
  *  uses notifications from the kernel Routing Netlink (rtnl) to
- *  confirm and "inactivate" those routes.
+ *  confirm and "inactivate" those routes. The following is the state
+ *  machine for that lifecycle:
+ *
+ *                              .----------.    SIOCADDRT /
+ *                              |          |    RTM_NEWROUTE
+ *           .------------------| Inactive |--------------------.
+ *           |                  |          |                    |
+ *           |                  '----------'                    |
+ *           | connman_rtnl                                     |
+ *           | .delgateway                                      |
+ *           |                                                  V
+ *      .---------.         SIOCADDRT / RTM_NEWROUTE        .-------.
+ *      |         |---------------------------------------->|       |
+ *      | Removed |                                         | Added |
+ *      |         |<----------------------------------------|       |
+ *      '---------'         SIOCDELRT / RTM_DELROUTE        '-------'
+ *           ^                                                  |
+ *           | SIOCDELRT /                                      |
+ *           | RTM_DELROUTE                                     |
+ *           |                   .--------.     connman_rtnl    |
+ *           |                   |        |     .newgateway     |
+ *           '-------------------| Active |<--------------------'
+ *                               |        |
+ *                               '--------'
  *
  */
 enum gateway_config_state {
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 59/90] connection: Document 'gateway_config_ops'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (60 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 58/90] connection: Document 'gateway_config_state' finite state machine Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 60/90] connection: Document 'gateway_config' Grant Erickson
                   ` (30 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the 'gateway_config_ops' structure and its
instantiation in 'gateway_config'.
---
 src/connection.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 2022a64727d6..8d2ac801c330 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -163,6 +163,10 @@ enum gateway_config_type {
 	CONNMAN_GATEWAY_CONFIG_TYPE_LOW_PRIORITY_DEFAULT  = 2
 };
 
+/**
+ *  Gateway configuration function pointers for IP configuration
+ *  type-specific route set/clear/add/delete operations.
+ */
 struct gateway_config_ops {
 	bool (*compare_subnet)(int index,
 		const char *address);
@@ -214,6 +218,11 @@ struct gateway_config {
 	 *	See #gateway_config_type.
 	 */
 	enum gateway_config_type type;
+
+	/**
+	 *  A pointer to immutable function pointers for route
+	 *  set/clear/add/delete operations.
+	 */
 	const struct gateway_config_ops *ops;
 	char *gateway;
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 60/90] connection: Document 'gateway_config'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (61 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 59/90] connection: Document 'gateway_config_ops' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 61/90] connection: Document 'gateway_data' Grant Erickson
                   ` (29 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the 'gateway_config' structure.
---
 src/connection.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 8d2ac801c330..04a336e0b619 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -200,6 +200,11 @@ struct gateway_config_ops {
 		const char *gateway);
 };
 
+/**
+ *	An IP configuration type-specific data structure used to maintain
+ *	gateway-specific configuration information about a gateway, or
+ *	default router, and, for VPNs, the VPN peer.
+ */
 struct gateway_config {
 	/**
 	 *	A 32-bit flag bitfield governing the state and use of the
@@ -224,6 +229,12 @@ struct gateway_config {
 	 *  set/clear/add/delete operations.
 	 */
 	const struct gateway_config_ops *ops;
+
+	/**
+	 *	A pointer to a mutable, dynamically-allocated null-terminated
+	 *	C string containing the text-formatted address of the gateway,
+	 *	or default router.
+	 */
 	char *gateway;
 
 	/* VPN extra data */
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 61/90] connection: Document 'gateway_data'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (62 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 60/90] connection: Document 'gateway_config' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 62/90] connection: Document 'gateway_hash' Grant Erickson
                   ` (28 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the 'gateway_data' structure.
---
 src/connection.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 04a336e0b619..d575e514e101 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -243,11 +243,43 @@ struct gateway_config {
 	char *vpn_phy_ip;
 };
 
+/**
+ *	The key data structure used to associate a network service with a
+ *	gateway, or default router.
+ */
 struct gateway_data {
+	/**
+	 *	The network interface index associated with the underlying
+	 *	network interface for the assigned @a service field.
+	 */
 	int index;
+
+	/**
+	 *	A strong (that is, uses #connman_service_{ref,unref})
+	 *	reference to the network service associated with this gateway.
+	 */
 	struct connman_service *service;
+
+	/**
+	 *	An optional weak reference to dynamically-allocated storage
+	 *	for the gateway-specific configuration, if the gateway is IPv4.
+	 */
 	struct gateway_config *ipv4_config;
+
+	/**
+	 *	An optional weak reference to dynamically-allocated storage
+	 *	for the gateway-specific configuration, if the gateway is IPv6.
+	 */
 	struct gateway_config *ipv6_config;
+
+	/**
+	 *	A Boolean indicating whether this gateway / network interface
+	 *	index tuple has been handled by the #connman_rtnl @a
+	 *	newgateway Linux Routing Netlink (rtnl) new gateway listener
+	 *	method and, specifically, whether that method has checked a
+	 *	new, incoming gateway against the current gateway / default
+	 *	router.
+	 */
 	bool default_checked;
 };
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 62/90] connection: Document 'gateway_hash'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (63 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 61/90] connection: Document 'gateway_data' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 63/90] connection: Document 'is_addr_any_str' Grant Erickson
                   ` (27 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the 'gateway_hash' global.
---
 src/connection.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index d575e514e101..f1e91c7c8518 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -418,6 +418,11 @@ static const struct gateway_config_ops ipv6_gateway_config_ops = {
 static const char *const ipv4_addr_any_str = "0.0.0.0";
 static const char *const ipv6_addr_any_str = "::";
 
+/**
+ *	A dictionary / hash table of network services to gateway, or
+ *	default router, data.
+ *
+ */
 static GHashTable *gateway_hash = NULL;
 
 /**
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 63/90] connection: Document 'is_addr_any_str'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (64 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 62/90] connection: Document 'gateway_hash' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 64/90] connection: Update 'find_any_active_gateway_data' documentation Grant Erickson
                   ` (26 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the 'is_addr_any_str' function.
---
 src/connection.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index f1e91c7c8518..053164c36297 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -792,6 +792,27 @@ static bool is_ipv6_addr_any_str(const char *address)
 	return g_strcmp0(ipv6_addr_any_str, address) == 0;
 }
 
+/**
+ *  @brief
+ *    Determine whether the specified text-formatted IP address is
+ *    the "any" or "unspecified" address.
+ *
+ *  This determines whether the specified text-formatted IP address
+ *  is the "any" or "unspecified" address.
+ *
+ *  @param[in]  address  A pointer to an immutable null-terminated C
+ *                       string containing the text-formatted address
+ *                       to determine whether it is the IP "any" or
+ *                       "unspecified address.
+ *
+ *  @returns
+ *    True if @a address is the "any" or "unspecified" IP address;
+ *    otherwise, false.
+ *
+ *  @sa is_ipv4_addr_any_str
+ *  @sa is_ipv6_addr_any_str
+ *
+ */
 static bool is_addr_any_str(const char *address)
 {
 	if (!address)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 64/90] connection: Update 'find_any_active_gateway_data' documentation.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (65 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 63/90] connection: Document 'is_addr_any_str' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 65/90] connection: Document 'compute_low_priority_metric' Grant Erickson
                   ` (25 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This updates documentation to the 'find_any_active_gateway_data'
function now that the module supports both high- and low-priority
default gateways and their routes.
---
 src/connection.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 053164c36297..7bfbefb2cfda 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -971,13 +971,13 @@ static struct gateway_data *find_any_active_gateway_data(void)
  *    default service.
  *
  *  This attempts to find the gateway, or default router, data
- *  associated with default network service (that is, has the default
- *  route).
+ *  associated with default network service (that is, has the
+ *  high-priority default route).
  *
  *  @returns
  *    A pointer to the gateway, or default router, data associated
- *    with the default network service (that is, has the default
- *    route) on success; otherwise, null.
+ *    with the default network service (that is, has the high-priority
+ *    default route) on success; otherwise, null.
  *
  *  @sa find_any_active_gateway_data
  *  @sa find_gateway_data
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 65/90] connection: Document 'compute_low_priority_metric'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (66 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 64/90] connection: Update 'find_any_active_gateway_data' documentation Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 66/90] connection: Document 'add_host_route' Grant Erickson
                   ` (24 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the 'compute_low_priority_metric' function.
---
 src/connection.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 7bfbefb2cfda..b2b5f01867b9 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1988,12 +1988,57 @@ static int unset_default_gateway(struct gateway_data *data,
 	return mutate_default_gateway(data, type, &ops, __func__);
 }
 
+/**
+ *  @brief
+ *    Compute and return a low-priority gateway default route metric
+ *    unique to the specified gateway data.
+ *
+ *  This computes and returns a low-priority gateway default route
+ *  metric unique to the specified gateway data, @a data.
+ *
+ *  @param[in]  data  A pointer to the immutable gateway data with
+ *                    which to compute the low-priority default route
+ *                    metric.
+ *
+ *  @returns
+ *    The low-priority default route metric/priority.
+ *
+ */
 static uint32_t compute_low_priority_metric(const struct gateway_data *data)
 {
 	static const uint32_t metric_base = UINT32_MAX;
 	static const uint32_t metric_ceiling = (1 << 20);
 	static const uint32_t metric_index_step = (1 << 10);
 
+	/*
+	 * The algorithm uses the network interface index since it is
+	 * assumed to be stable for the uptime of the network interface
+	 * and, consequently, the potential maximum lifetime of the route.
+	 *
+	 * The algorithm establishes UINT32_MAX as the metric base (the
+	 * lowest possible priority) and a somewhat-arbitrary 2^20 as the
+	 * ceiling (to keep metrics out of a range that might be used by
+	 * other applications). The metric is then adjusted in increments
+	 * of 1,024 (2^10) from the base, but less than the ceiling, by
+	 * multiplying the increment by the network interface index. This
+	 * is easy and simple to compute and is invariant on service
+	 * order.
+	 *
+	 * In the fullness of time, the "rule of least astonishment" for
+	 * Connection Manager might be that low priority metrics follow
+	 * the service order with the default service always having metric
+	 * zero (0) and lowest priority metric assigned to the lowest
+	 * priority service, etc. Achieving this would require 1) caching
+	 * the computed metric in the gateway data since services may
+	 * re-sort by the time we are asked to recompute high- and
+	 * low-priority routes and we need a stable and matching metric to
+	 * successfully delete a previously-created route and 2) having
+	 * access to an API (such as
+	 * '__connman_service_get_order(data->service)') that exposes a
+	 * strictly-in/decreasing service order with no duplicates. Today,
+	 * there is no such API nor is there such a durable service order
+	 * meeting that mathematical requirement.
+	 */
 	return MAX(metric_ceiling,
 				metric_base -
 				(data->index * metric_index_step));
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 66/90] connection: Document 'add_host_route'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (67 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 65/90] connection: Document 'compute_low_priority_metric' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 67/90] connection: Document call to 'connman_service_unref' Grant Erickson
                   ` (23 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the 'add_host_route' function.
---
 src/connection.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index b2b5f01867b9..90e6f9f9d6be 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2591,6 +2591,29 @@ static struct connman_rtnl connection_rtnl = {
 	.delgateway	= connection_delgateway,
 };
 
+/**
+ *  @brief
+ *    Add, or set, a host route for the specified IP configuration
+ *    type for the provided gateway data.
+ *
+ *  This attempts to add, or set, a host route (that is, the RTF_HOST
+ *  flag is asserted on the route) for the specified IP configuration
+ *  type for the provided gateway data.
+ *
+ *  @param[in]  data           A pointer to the mutable gateway data
+ *                             for which to add a host route.
+ *  @param[in]  ipconfig_type  The IP configuration type for which the
+ *                             gateway host route(s) are to be added.
+ *  @param[in]  service_type   The service type for the network service
+ *                             associated with @a index for which the
+ *                             host route is being added.
+ *
+ *  @sa connman_inet_add_host_route
+ *  @sa connman_inet_add_ipv6_host_route
+ *  @sa connman_inet_get_dest_addr
+ *  @sa connman_inet_ipv6_get_dest_addr
+ *
+ */
 static void add_host_route(struct gateway_data *data,
 			enum connman_ipconfig_type ipconfig_type,
 			enum connman_service_type service_type)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 67/90] connection: Document call to 'connman_service_unref'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (68 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 66/90] connection: Document 'add_host_route' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 68/90] connection: Document 'demote_default_gateway' Grant Erickson
                   ` (22 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This documents the call to 'connman_service_unref' to help point
readers or maintainers where its balancing retained reference is
located.
---
 src/connection.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 90e6f9f9d6be..fddf0d5406e2 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2515,6 +2515,10 @@ static void remove_gateway(gpointer user_data)
 
 	gateway_config_free(data->ipv6_config);
 
+	/*
+	 * Release, and balance, the strong reference to the service
+	 * retained in #add_gateway.
+	 */
 	connman_service_unref(data->service);
 
 	g_free(data);
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 68/90] connection: Document 'demote_default_gateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (69 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 67/90] connection: Document call to 'connman_service_unref' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 69/90] connection: Document 'promote_default_gateway' Grant Erickson
                   ` (21 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the 'demote_default_gateway' function.
---
 src/connection.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index fddf0d5406e2..17aa4e7a7562 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2125,6 +2125,55 @@ static int unset_low_priority_default_gateway(struct gateway_data *data,
 	return mutate_default_gateway(data, type, &ops, __func__);
 }
 
+/**
+ *  @brief
+ *    Demote, from high- to low-priority, the default route associated
+ *    with the specified gateway data and IP configuration type.
+ *
+ *  This attempts to demote, from high- (that is, metric 0) to low-
+ *  (that is, metric > 0) priority, the default route associated with
+ *  the specified gateway data and IP configuration type.
+ *
+ *  @param[in,out]  data      The gateway data associated with the
+ *                            default route for which the priority is
+ *                            to be demoted.
+ *  @param[in]      type      The IP configuration type for which
+ *                            the gateway, or default router, is to be
+ *                            demoted.
+ *  @param[in]      function  A pointer to an immutable null-terminated
+ *                            C string containing the function name to
+ *                            which the call to this function should be
+ *                            attributed.
+ *
+ *  @retval  0              If successful.
+ *  @retval  -EINVAL        If @a data is null, if @a type is
+ *                          #CONNMAN_IPCONFIG_TYPE_UNKNOWN, if the
+ *                          gateway configuration type is invalid; or
+ *                          if the routing information to be added or
+ *                          deleted was invalid.
+ *  @retval  -EINPROGRESS   If the state of the gateway configuration
+ *                          for @a data is already
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_ADDED or
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_REMOVED.
+ *  @retval  -EALREADY      If the state of the gateway configuration
+ *                          for @a data is already
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE or
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE.
+ *  @retval  -EFAULT        If the address to the routing information
+ *                          to be added or deleted was invalid.
+ *  @retval  -EPERM         If the current process does not have the
+ *                          credentials or capabilities to add or
+ *                          delete routes.
+ *  @retval  -EEXIST        A request was made to add an existing
+ *                          routing entry.
+ *  @retval  -ESRCH         A request was made to delete a non-
+ *                          existing routing entry.
+ *
+ *  @sa unset_default_gateway
+ *  @sa set_low_priority_default_gateway
+ *  @sa promote_default_gateway
+ *
+ */
 static int demote_default_gateway(struct gateway_data *data,
 				enum connman_ipconfig_type type,
 				const char *function)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 69/90] connection: Document 'promote_default_gateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (70 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 68/90] connection: Document 'demote_default_gateway' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 70/90] connection: Document 'set_ipv4_high_priority_default_gateway_route_cb' Grant Erickson
                   ` (20 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the 'promote_default_gateway' function.
---
 src/connection.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 17aa4e7a7562..4fa2218def11 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2200,6 +2200,56 @@ static int demote_default_gateway(struct gateway_data *data,
 	return (unset_status == 0 ? unset_status : set_status);
 }
 
+/**
+ *  @brief
+ *    Promote, from low- to high-priority, the default route
+ *    associated with the specified gateway data and IP configuration
+ *    type.
+ *
+ *  This attempts to promote, from low- (that is, metric > 0) to high-
+ *  (that is, metric 0) priority, the default route associated with
+ *  the specified gateway data and IP configuration type.
+ *
+ *  @param[in,out]  data      The gateway data associated with the
+ *                            default route for which the priority is
+ *                            to be promoted.
+ *  @param[in]      type      The IP configuration type for which
+ *                            the gateway, or default router, is to be
+ *                            promoted.
+ *  @param[in]      function  A pointer to an immutable null-terminated
+ *                            C string containing the function name to
+ *                            which the call to this function should be
+ *                            attributed.
+ *
+ *  @retval  0              If successful.
+ *  @retval  -EINVAL        If @a data is null, if @a type is
+ *                          #CONNMAN_IPCONFIG_TYPE_UNKNOWN, if the
+ *                          gateway configuration type is invalid; or
+ *                          if the routing information to be added or
+ *                          deleted was invalid.
+ *  @retval  -EINPROGRESS   If the state of the gateway configuration
+ *                          for @a data is already
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_ADDED or
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_REMOVED.
+ *  @retval  -EALREADY      If the state of the gateway configuration
+ *                          for @a data is already
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE or
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE.
+ *  @retval  -EFAULT        If the address to the routing information
+ *                          to be added or deleted was invalid.
+ *  @retval  -EPERM         If the current process does not have the
+ *                          credentials or capabilities to add or
+ *                          delete routes.
+ *  @retval  -EEXIST        A request was made to add an existing
+ *                          routing entry.
+ *  @retval  -ESRCH         A request was made to delete a non-
+ *                          existing routing entry.
+ *
+ *  @sa set_default_gateway
+ *  @sa unset_low_priority_default_gateway
+ *  @sa demote_default_gateway
+ *
+ */
 static int promote_default_gateway(struct gateway_data *data,
 				enum connman_ipconfig_type type,
 				const char *function)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 70/90] connection: Document 'set_ipv4_high_priority_default_gateway_route_cb'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (71 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 69/90] connection: Document 'promote_default_gateway' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 71/90] connection: Document 'set_ipv6_high_priority_default_gateway_route_cb' Grant Erickson
                   ` (19 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the
'set_ipv4_high_priority_default_gateway_route_cb' function.
---
 src/connection.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 4fa2218def11..d2e9c089d65d 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1685,6 +1685,42 @@ done:
 	return err;
 }
 
+/**
+ *  @brief
+ *    Set, or add, the IPv4 high-priority default route for the
+ *    specified gateway data and configuration using a function
+ *    utilizing a SIOCADDRT socket ioctl or a RTM_NEWROUTE Linux
+ *    Routing Netlink (rtnl) command.
+ *
+ *  This attempts to set, or add, the IPv4 high-priority (that is,
+ *  metric 0) default route for the specified gateway data and
+ *  configuration using a function utilizing a SIOCADDRT socket ioctl
+ *  or a RTM_NEWROUTE Linux Routing Netlink (rtnl) command to modify
+ *  the Linux routing table.
+ *
+ *  @param[in,out]  data    A pointer to the mutable gateway data to
+ *                          use to set, or add, the IPv4 high-priority
+ *                          default route.
+ *  @param[in,out]  config  A pointer to the mutable gateway
+ *                          configuration to use to set, or add,
+ *                          the IPv4 high-priority default route.
+ *
+ *  @retval  0        If successful.
+ *  @retval  -EINVAL  If @a data or @a config are null; or if
+ *                    the routing information to be set, or
+ *                    added, was invalid.
+ *  @retval  -EFAULT  If the address to the routing information
+ *                    to be set, or added, was invalid.
+ *  @retval  -EPERM   If the current process does not have the
+ *                    credentials or capabilities to set, or
+ *                    add, routes.
+ *  @retval  -EEXIST  A request was made to add an existing
+ *                    routing entry.
+ *
+ *  @sa connman_inet_set_gateway_interface
+ *  @sa __connman_inet_add_default_to_table
+ *
+ */
 static int set_ipv4_high_priority_default_gateway_route_cb(
 				struct gateway_data *data,
 				struct gateway_config *config)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 71/90] connection: Document 'set_ipv6_high_priority_default_gateway_route_cb'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (72 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 70/90] connection: Document 'set_ipv4_high_priority_default_gateway_route_cb' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 72/90] connection: Document 'set_ipv4_high_priority_default_gateway' Grant Erickson
                   ` (18 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the
'set_ipv6_high_priority_default_gateway_route_cb' function.
---
 src/connection.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index d2e9c089d65d..9db3df13340a 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1759,6 +1759,42 @@ done:
 	return err;
 }
 
+/**
+ *  @brief
+ *    Set, or add, the IPv6 high-priority default route for the
+ *    specified gateway data and configuration using a function
+ *    utilizing a SIOCADDRT socket ioctl or a RTM_NEWROUTE Linux
+ *    Routing Netlink (rtnl) command.
+ *
+ *  This attempts to set, or add, the IPv6 high-priority (that is,
+ *  metric 0) default route for the specified gateway data and
+ *  configuration using a function utilizing a SIOCADDRT socket ioctl
+ *  or a RTM_NEWROUTE Linux Routing Netlink (rtnl) command to modify
+ *  the Linux routing table.
+ *
+ *  @param[in,out]  data    A pointer to the mutable gateway data to
+ *                          use to set, or add, the IPv6 high-priority
+ *                          default route.
+ *  @param[in,out]  config  A pointer to the mutable gateway
+ *                          configuration to use to set, or add,
+ *                          the IPv6 high-priority default route.
+ *
+ *  @retval  0        If successful.
+ *  @retval  -EINVAL  If @a data or @a config are null; or if
+ *                    the routing information to be set, or
+ *                    added, was invalid.
+ *  @retval  -EFAULT  If the address to the routing information
+ *                    to be set, or added, was invalid.
+ *  @retval  -EPERM   If the current process does not have the
+ *                    credentials or capabilities to set, or
+ *                    add, routes.
+ *  @retval  -EEXIST  A request was made to add an existing
+ *                    routing entry.
+ *
+ *  @sa connman_inet_set_ipv6_gateway_interface
+ *  @sa __connman_inet_add_default_to_table
+ *
+ */
 static int set_ipv6_high_priority_default_gateway_route_cb(
 				struct gateway_data *data,
 				struct gateway_config *config)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 72/90] connection: Document 'set_ipv4_high_priority_default_gateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (73 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 71/90] connection: Document 'set_ipv6_high_priority_default_gateway_route_cb' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 73/90] connection: Document 'set_ipv6_high_priority_default_gateway' Grant Erickson
                   ` (17 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the
'set_ipv4_high_priority_default_gateway' function.
---
 src/connection.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 9db3df13340a..1d31a42ce334 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1833,6 +1833,49 @@ done:
 	return err;
 }
 
+/**
+ *  @brief
+ *    Set, or add, the IPv4 high-priority default route for the
+ *    specified gateway data and configuration.
+ *
+ *  This attempts to set, or add, the IPv4 high-priority (that is,
+ *  metric 0) default route for the specified gateway data and
+ *  configuration.
+ *
+ *  On success, the gateway configuration type will be set to
+ *  #CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT and its state
+ *  to #CONNMAN_GATEWAY_CONFIG_STATE_ADDED.
+ *
+ *  @param[in,out]  data    A pointer to the mutable gateway data to
+ *                          assign as the IPv4 high-priority default
+ *                          route.
+ *  @param[in,out]  config  A pointer to the mutable gateway
+ *                          configuration to assign as the IPv4
+ *                          high-priority default route.
+ *
+ *  @retval  0              If successful.
+ *  @retval  -EINVAL        If @a data or @a config are
+ *                          null; if the gateway configuration type is
+ *                          not #CONNMAN_GATEWAY_CONFIG_TYPE_NONE or
+ *                          #CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT;
+ *                          or if the routing information to be set,
+ *                          or added, was invalid.
+ *  @retval  -EINPROGRESS   If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_ADDED.
+ *  @retval  -EALREADY      If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE.
+ *  @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, or
+ *                          set, routes.
+ *  @retval  -EEXIST        A request was made to add an existing
+ *                          routing entry.
+ *
+ *  @sa set_default_gateway_route_common
+ *  @sa set_ipv4_high_priority_default_gateway_func
+ *
+ */
 static int set_ipv4_high_priority_default_gateway(struct gateway_data *data,
 				struct gateway_config *config)
 {
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 73/90] connection: Document 'set_ipv6_high_priority_default_gateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (74 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 72/90] connection: Document 'set_ipv4_high_priority_default_gateway' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 74/90] connection: Document 'unset_ipv4_high_priority_default_gateway_route_cb' Grant Erickson
                   ` (16 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the
'set_ipv6_high_priority_default_gateway' function.
---
 src/connection.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 1d31a42ce334..74f63faf7320 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1887,6 +1887,49 @@ static int set_ipv4_high_priority_default_gateway(struct gateway_data *data,
 	return set_default_gateway_route_common(data, config, type, cb);
 }
 
+/**
+ *  @brief
+ *    Set, or add, the IPv6 high-priority default route for the
+ *    specified gateway data and configuration.
+ *
+ *  This attempts to set, or add, the IPv6 high-priority (that is,
+ *  metric 0) default route for the specified gateway data and
+ *  configuration.
+ *
+ *  On success, the gateway configuration type will be set to
+ *  #CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT and its state
+ *  to #CONNMAN_GATEWAY_CONFIG_STATE_ADDED.
+ *
+ *  @param[in,out]  data    A pointer to the mutable gateway data to
+ *                          assign as the IPv6 high-priority default
+ *                          route.
+ *  @param[in,out]  config  A pointer to the mutable gateway
+ *                          configuration to assign as the IPv6
+ *                          high-priority default route.
+ *
+ *  @retval  0              If successful.
+ *  @retval  -EINVAL        If @a data or @a config are
+ *                          null; if the gateway configuration type is
+ *                          not #CONNMAN_GATEWAY_CONFIG_TYPE_NONE or
+ *                          #CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT;
+ *                          or if the routing information to be set,
+ *                          or added, was invalid.
+ *  @retval  -EINPROGRESS   If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_ADDED.
+ *  @retval  -EALREADY      If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE.
+ *  @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, or
+ *                          set, routes.
+ *  @retval  -EEXIST        A request was made to add an existing
+ *                          routing entry.
+ *
+ *  @sa set_default_gateway_route_common
+ *  @sa set_ipv6_high_priority_default_gateway_route_cb
+ *
+ */
 static int set_ipv6_high_priority_default_gateway(struct gateway_data *data,
 				struct gateway_config *config)
 {
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 74/90] connection: Document 'unset_ipv4_high_priority_default_gateway_route_cb'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (75 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 73/90] connection: Document 'set_ipv6_high_priority_default_gateway' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 75/90] connection: Document 'unset_ipv6_high_priority_default_gateway_route_cb' Grant Erickson
                   ` (15 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the
'unset_ipv4_high_priority_default_gateway_route_cb' function.
---
 src/connection.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 74f63faf7320..e890877f21b0 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1998,6 +1998,42 @@ done:
 	return status;
 }
 
+/**
+ *  @brief
+ *    Unset, or remove, the IPv4 high-priority default route for the
+ *    specified gateway data and configuration using a function
+ *    utilizing a SIOCDELRT socket ioctl or a RTM_DELROUTE Linux
+ *    Routing Netlink (rtnl) command.
+ *
+ *  This attempts to unset, or remove, the IPv4 high-priority (that
+ *  is, metric 0) default route for the specified gateway data and
+ *  configuration using a function utilizing a SIOCDELRT socket ioctl
+ *  or a RTM_DELROUTE Linux Routing Netlink (rtnl) command to modify
+ *  the Linux routing table.
+ *
+ *  @param[in,out]  data    A pointer to the mutable gateway data to
+ *                          use to unset, or remove, the IPv4
+ *                          high-priority default route.
+ *  @param[in,out]  config  A pointer to the mutable gateway
+ *                          configuration to use to unset, or remove,
+ *                          the IPv4 high-priority default route.
+ *
+ *  @retval  0        If successful.
+ *  @retval  -EINVAL  If @a data or @a config are null; or if
+ *                    the routing information to be unset, or
+ *                    removed, was invalid.
+ *  @retval  -EFAULT  If the address to the routing information
+ *                    to be set, or added, was invalid.
+ *  @retval  -EPERM   If the current process does not have the
+ *                    credentials or capabilities to set, or
+ *                    add, routes.
+ *  @retval  -ESRCH   A request was made to delete a non-existing
+ *                    routing entry.
+ *
+ *  @sa connman_inet_clear_gateway_interface
+ *  @sa connman_inet_clear_gateway_address
+ *
+ */
 static int unset_ipv4_high_priority_default_gateway_route_cb(
 				struct gateway_data *data,
 				struct gateway_config *config)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 75/90] connection: Document 'unset_ipv6_high_priority_default_gateway_route_cb'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (76 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 74/90] connection: Document 'unset_ipv4_high_priority_default_gateway_route_cb' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 76/90] connection: Document 'unset_ipv4_high_priority_default_gateway' Grant Erickson
                   ` (14 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the
'unset_ipv6_high_priority_default_gateway_route_cb' function.
---
 src/connection.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index e890877f21b0..4aaffbf7e5c3 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2072,6 +2072,42 @@ done:
 	return err;
 }
 
+/**
+ *  @brief
+ *    Unset, or remove, the IPv6 high-priority default route for the
+ *    specified gateway data and configuration using a function
+ *    utilizing a SIOCDELRT socket ioctl or a RTM_DELROUTE Linux
+ *    Routing Netlink (rtnl) command.
+ *
+ *  This attempts to unset, or remove, the IPv6 high-priority (that
+ *  is, metric 0) default route for the specified gateway data and
+ *  configuration using a function utilizing a SIOCDELRT socket ioctl
+ *  or a RTM_DELROUTE Linux Routing Netlink (rtnl) command to modify
+ *  the Linux routing table.
+ *
+ *  @param[in,out]  data    A pointer to the mutable gateway data to
+ *                          use to unset, or remove, the IPv6
+ *                          high-priority default route.
+ *  @param[in,out]  config  A pointer to the mutable gateway
+ *                          configuration to use to unset, or remove,
+ *                          the IPv6 high-priority default route.
+ *
+ *  @retval  0        If successful.
+ *  @retval  -EINVAL  If @a data or @a config are null; or if
+ *                    the routing information to be unset, or
+ *                    removed, was invalid.
+ *  @retval  -EFAULT  If the address to the routing information
+ *                    to be set, or added, was invalid.
+ *  @retval  -EPERM   If the current process does not have the
+ *                    credentials or capabilities to set, or
+ *                    add, routes.
+ *  @retval  -ESRCH   A request was made to delete a non-existing
+ *                    routing entry.
+ *
+ *  @sa connman_inet_clear_ipv6_gateway_interface
+ *  @sa connman_inet_clear_ipv6_gateway_address
+ *
+ */
 static int unset_ipv6_high_priority_default_gateway_route_cb(
 				struct gateway_data *data,
 				struct gateway_config *config)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 76/90] connection: Document 'unset_ipv4_high_priority_default_gateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (77 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 75/90] connection: Document 'unset_ipv6_high_priority_default_gateway_route_cb' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 77/90] connection: Document 'unset_ipv6_high_priority_default_gateway' Grant Erickson
                   ` (13 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the
'unset_ipv4_high_priority_default_gateway' function.
---
 src/connection.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 4aaffbf7e5c3..df5c4d158dad 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2146,6 +2146,38 @@ done:
 	return err;
 }
 
+/**
+ *  @brief
+ *    Unset, or clear, the IPv4 high-priority default route for the
+ *    specified gateway data and configuration.
+ *
+ *  This attempts to unset, or clear, the IPv4 high-priority (that is,
+ *  metric 0) default route from the provided gateway data and
+ *  configuration.
+ *
+ *  @param[in,out]  data    A pointer to the mutable gateway data to
+ *                          use to unset, or remove, the IPv4
+ *                          high-priority default route.
+ *  @param[in,out]  config  A pointer to the mutable gateway
+ *                          configuration to use to unset, or remove,
+ *                          the IPv4 high-priority default route.
+ *
+ *  @retval  0        If successful.
+ *  @retval  -EINVAL  If @a data or @a config are null; or if
+ *                    the routing information to be unset, or
+ *                    removed, was invalid.
+ *  @retval  -EFAULT  If the address to the routing information
+ *                    to be unset, or cleared, was invalid.
+ *  @retval  -EPERM   If the current process does not have the
+ *                    credentials or capabilities to unset, or
+ *                    clear, routes.
+ *  @retval  -ESRCH   A request was made to unset, or clear a
+ *                    non-existing routing entry.
+ *
+ *  @sa unset_default_gateway_route_common
+ *  @sa unset_ipv4_high_priority_default_gateway_route_cb
+ *
+ */
 static int unset_ipv4_high_priority_default_gateway(
 				struct gateway_data *data,
 				struct gateway_config *config)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 77/90] connection: Document 'unset_ipv6_high_priority_default_gateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (78 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 76/90] connection: Document 'unset_ipv4_high_priority_default_gateway' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 78/90] connection: Document 'set_ipv4_low_priority_default_gateway_route_cb' Grant Erickson
                   ` (12 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the
'unset_ipv6_high_priority_default_gateway' function.
---
 src/connection.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index df5c4d158dad..62e9f3bc07f6 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2190,6 +2190,38 @@ static int unset_ipv4_high_priority_default_gateway(
 	return unset_default_gateway_route_common(data, config, type, cb);
 }
 
+/**
+ *  @brief
+ *    Unset, or clear, the IPv6 high-priority default route for the
+ *    specified gateway data and configuration.
+ *
+ *  This attempts to unset, or clear, the IPv6 high-priority (that is,
+ *  metric 0) default route from the provided gateway data and
+ *  configuration.
+ *
+ *  @param[in,out]  data    A pointer to the mutable gateway data to
+ *                          use to unset, or remove, the IPv6
+ *                          high-priority default route.
+ *  @param[in,out]  config  A pointer to the mutable gateway
+ *                          configuration to use to unset, or remove,
+ *                          the IPv6 high-priority default route.
+ *
+ *  @retval  0        If successful.
+ *  @retval  -EINVAL  If @a data or @a config are null; or if
+ *                    the routing information to be unset, or
+ *                    removed, was invalid.
+ *  @retval  -EFAULT  If the address to the routing information
+ *                    to be unset, or cleared, was invalid.
+ *  @retval  -EPERM   If the current process does not have the
+ *                    credentials or capabilities to unset, or
+ *                    clear, routes.
+ *  @retval  -ESRCH   A request was made to unset, or clear a
+ *                    non-existing routing entry.
+ *
+ *  @sa unset_default_gateway_route_common
+ *  @sa unset_ipv6_high_priority_default_gateway_route_cb
+ *
+ */
 static int unset_ipv6_high_priority_default_gateway(
 				struct gateway_data *data,
 				struct gateway_config *config)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 78/90] connection: Document 'set_ipv4_low_priority_default_gateway_route_cb'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (79 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 77/90] connection: Document 'unset_ipv6_high_priority_default_gateway' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 79/90] connection: Document 'set_ipv4_low_priority_default_gateway' Grant Erickson
                   ` (11 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the
'set_ipv4_low_priority_default_gateway_route_cb' function.
---
 src/connection.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 62e9f3bc07f6..a199b90802e2 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2338,6 +2338,42 @@ static uint32_t compute_low_priority_metric(const struct gateway_data *data)
 				(data->index * metric_index_step));
 }
 
+/**
+ *  @brief
+ *    Set, or add, the IPv4 low-priority default route for the
+ *    specified gateway data and configuration using a function
+ *    utilizing a SIOCADDRT socket ioctl or a RTM_NEWROUTE Linux
+ *    Routing Netlink (rtnl) command.
+ *
+ *  This attempts to set, or add, the IPv4 low-priority (that is,
+ *  metric > 0) default route for the specified gateway data and
+ *  configuration using a function utilizing a SIOCADDRT socket ioctl
+ *  or a RTM_NEWROUTE Linux Routing Netlink (rtnl) command to modify
+ *  the Linux routing table.
+ *
+ *  @param[in,out]  data    A pointer to the mutable gateway data to
+ *                          use to set, or add, the IPv4 low-priority
+ *                          default route.
+ *  @param[in,out]  config  A pointer to the mutable gateway
+ *                          configuration to use to set, or add, the
+ *                          IPv4 low-priority default route.
+ *
+ *  @retval  0        If successful.
+ *  @retval  -EINVAL  If @a data or @a config are null; or if
+ *                    the routing information to be set, or
+ *                    added, was invalid.
+ *  @retval  -EFAULT  If the address to the routing information
+ *                    to be set, or added, was invalid.
+ *  @retval  -EPERM   If the current process does not have the
+ *                    credentials or capabilities to set, or
+ *                    add, routes.
+ *  @retval  -EEXIST  A request was made to add an existing
+ *                    routing entry.
+ *
+ *  @sa connman_inet_set_gateway_interface
+ *  @sa __connman_inet_add_default_to_table
+ *
+ */
 static int set_ipv4_low_priority_default_gateway_route_cb(
 				struct gateway_data *data,
 				struct gateway_config *config)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 79/90] connection: Document 'set_ipv4_low_priority_default_gateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (80 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 78/90] connection: Document 'set_ipv4_low_priority_default_gateway_route_cb' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 80/90] connection: Document 'set_low_priority_default_gateway' Grant Erickson
                   ` (10 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the 'set_ipv4_low_priority_default_gateway'
function.
---
 src/connection.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index a199b90802e2..84b3bb1c80bf 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2389,6 +2389,49 @@ static int set_ipv4_low_priority_default_gateway_route_cb(
 				metric);
 }
 
+/**
+ *  @brief
+ *    Set, or add, the IPv4 low-priority default route for the
+ *    specified gateway data and configuration.
+ *
+ *  This attempts to set, or add, the IPv4 low-priority (that is,
+ *  metric > 0) default route for the specified gateway data and
+ *  configuration.
+ *
+ *  On success, the gateway configuration type will be set to
+ *  #CONNMAN_GATEWAY_CONFIG_TYPE_LOW_PRIORITY_DEFAULT and its state
+ *  to #CONNMAN_GATEWAY_CONFIG_STATE_ADDED.
+ *
+ *  @param[in,out]  data    A pointer to the mutable gateway data to
+ *                          assign as the IPv4 low-priority default
+ *                          route.
+ *  @param[in,out]  config  A pointer to the mutable gateway
+ *                          configuration to assign as the IPv4
+ *                          low-priority default route.
+ *
+ *  @retval  0              If successful.
+ *  @retval  -EINVAL        If @a data or @a config are
+ *                          null; if the gateway configuration type is
+ *                          not #CONNMAN_GATEWAY_CONFIG_TYPE_NONE or
+ *                          #CONNMAN_GATEWAY_CONFIG_TYPE_LOW_PRIORITY_DEFAULT;
+ *                          or if the routing information to be set,
+ *                          or added, was invalid.
+ *  @retval  -EINPROGRESS   If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_ADDED.
+ *  @retval  -EALREADY      If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE.
+ *  @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, or
+ *                          set, routes.
+ *  @retval  -EEXIST        A request was made to add an existing
+ *                          routing entry.
+ *
+ *  @sa set_default_gateway_route_common
+ *  @sa set_ipv4_low_priority_default_gateway_route_cb
+ *
+ */
 static int set_ipv4_low_priority_default_gateway(
 				struct gateway_data *data,
 				struct gateway_config *config)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 80/90] connection: Document 'set_low_priority_default_gateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (81 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 79/90] connection: Document 'set_ipv4_low_priority_default_gateway' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 81/90] connection: Document 'unset_ipv4_low_priority_default_gateway_route_cb' Grant Erickson
                   ` (9 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the 'set_low_priority_default_gateway'
function.
---
 src/connection.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 84b3bb1c80bf..5740e4522d1a 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2444,6 +2444,38 @@ static int set_ipv4_low_priority_default_gateway(
 	return set_default_gateway_route_common(data, config, type, cb);
 }
 
+/**
+ *  @brief
+ *    Set, or add, the gateway low-priority default route for the
+ *    specified IP configuration type from the provided gateway data.
+ *
+ *  This attempts to set, or add, the low-priority (that is, metric
+ *  > 0) default route for the specified IP configuration type from
+ *  the provided gateway data. The network interface and, by
+ *  extension, the network service with which the gateway is
+ *  associated is determined by the @a index field of @a data.
+ *
+ *  On success, the gateway configuration state and type specific to
+ *  @a type will be set to #CONNMAN_GATEWAY_CONFIG_STATE_ADDED and
+ *  #CONNMAN_GATEWAY_CONFIG_TYPE_LOW_PRIORITY_DEFAULT, respectively.
+ *
+ *  @param[in,out]  data      A pointer to the mutable gateway data
+ *                            to assign as the low-priority default
+ *                            route.
+ *  @param[in]      type      The IP configuration type for which the
+ *                            gateway, or default router,
+ *                            configuration will be selected from @a
+ *                            data and used to set the low-priority
+ *                            default route.
+ *  @param[in]      function  A pointer to an immutable null-terminated
+ *                            C string containing the function name to
+ *                            which the call to this function should
+ *                            be attributed.
+ *
+ *  @sa mutate_default_gateway
+ *  @sa set_ipv4_low_priority_default_gateway
+ *
+ */
 static int set_low_priority_default_gateway(struct gateway_data *data,
 				enum connman_ipconfig_type type,
 				const char *function)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 81/90] connection: Document 'unset_ipv4_low_priority_default_gateway_route_cb'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (82 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 80/90] connection: Document 'set_low_priority_default_gateway' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 82/90] connection: Document 'unset_ipv4_low_priority_default_gateway' Grant Erickson
                   ` (8 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the
'unset_ipv4_low_priority_default_gateway_route_cb' function.
---
 src/connection.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 5740e4522d1a..0a7d9c919452 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2490,6 +2490,41 @@ static int set_low_priority_default_gateway(struct gateway_data *data,
 	return mutate_default_gateway(data, type, &ops, __func__);
 }
 
+/**
+ *  @brief
+ *    Unset, or remove, the IPv4 low-priority default route for the
+ *    specified gateway data and configuration using a function
+ *    utilizing a SIOCDELRT socket ioctl or a RTM_DELROUTE Linux
+ *    Routing Netlink (rtnl) command.
+ *
+ *  This attempts to unset, or remove, the IPv4 low-priority (that
+ *  is, metric > 0) default route for the specified gateway data and
+ *  configuration using a function utilizing a SIOCDELRT socket ioctl
+ *  or a RTM_DELROUTE Linux Routing Netlink (rtnl) command to modify
+ *  the Linux routing table.
+ *
+ *  @param[in,out]  data    A pointer to the mutable gateway data to
+ *                          use to unset, or remove, the IPv4
+ *                          low-priority default route.
+ *  @param[in,out]  config  A pointer to the mutable gateway
+ *                          configuration to use to unset, or remove,
+ *                          the IPv4 low-priority default route.
+ *
+ *  @retval  0        If successful.
+ *  @retval  -EINVAL  If @a data or @a config are null; or if
+ *                    the routing information to be set, or
+ *                    added, was invalid.
+ *  @retval  -EFAULT  If the address to the routing information
+ *                    to be set, or added, was invalid.
+ *  @retval  -EPERM   If the current process does not have the
+ *                    credentials or capabilities to set, or
+ *                    add, routes.
+ *  @retval  -ESRCH   A request was made to delete a non-existing
+ *                    routing entry.
+ *
+ *  @sa __connman_inet_del_default_from_table_with_metric;
+ *
+ */
 static int unset_ipv4_low_priority_default_gateway_route_cb(
 				struct gateway_data *data,
 				struct gateway_config *config)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 82/90] connection: Document 'unset_ipv4_low_priority_default_gateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (83 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 81/90] connection: Document 'unset_ipv4_low_priority_default_gateway_route_cb' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 83/90] connection: Document 'unset_low_priority_default_gateway' Grant Erickson
                   ` (7 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the
'unset_ipv4_low_priority_default_gateway' function.
---
 src/connection.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 0a7d9c919452..1f250a62f24c 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2540,6 +2540,50 @@ static int unset_ipv4_low_priority_default_gateway_route_cb(
 				metric);
 }
 
+/**
+ *  @brief
+ *    Unset the IPv4 low-priority default route for the specified IP
+ *    configuration type from the provided gateway data.
+ *
+ *  This attempts to unset, or clear, the IPv4 low-priority (that is,
+ *  metric > 0) default route for the specified IP configuration type
+ *  from the provided gateway data. The network interface and, by
+ *  extension, the network service with which the gateway is
+ *  associated is determined by the @a index field of @a data.
+ *
+ *  On success, the gateway configuration state will be set to
+ *  #CONNMAN_GATEWAY_CONFIG_STATE_REMOVED.
+ *
+ *  @param[in,out]  data  A pointer to the mutable gateway data to
+ *                        clear as the IPv4 low-priority default
+ *                        route.
+ *  @param[in]      type  The IP configuration type for which the
+ *                        gateway, or default router, configuration
+ *                        will be selected from @a data and used to
+ *                        unset the IPv4 low-priority default route.
+ *
+ *  @retval  0              If successful.
+ *  @retval  -EINVAL        If @a data or @a config are null, if the
+ *                          gateway configuration type is not
+ *                          #CONNMAN_GATEWAY_CONFIG_TYPE_LOW_PRIORITY_DEFAULT,
+ *                          or if the routing information to be unset,
+ *                          or cleared, was invalid.
+ *  @retval  -EINPROGRESS   If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_REMOVED.
+ *  @retval  -EALREADY      If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE.
+ *  @retval  -EFAULT        If the address to the routing information
+ *                          to be unset, or cleared, was invalid.
+ *  @retval  -EPERM         If the current process does not have the
+ *                          credentials or capabilities to unset, or
+ *                          clear, routes.
+ *  @retval  -ESRCH         A request was made to unset, or clear a
+ *                          non-existing routing entry.
+ *
+ *  @sa unset_default_gateway_route_common
+ *  @sa unset_ipv4_low_priority_default_gateway_route_cb
+ *
+ */
 static int unset_ipv4_low_priority_default_gateway(struct gateway_data *data,
 				struct gateway_config *config)
 {
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 83/90] connection: Document 'unset_low_priority_default_gateway'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (84 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 82/90] connection: Document 'unset_ipv4_low_priority_default_gateway' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 84/90] connection: Fix documentation typos Grant Erickson
                   ` (6 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds documentation to the 'unset_low_priority_default_gateway'
function.
---
 src/connection.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 1f250a62f24c..db108ed03a19 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2595,6 +2595,50 @@ static int unset_ipv4_low_priority_default_gateway(struct gateway_data *data,
 	return unset_default_gateway_route_common(data, config, type, cb);
 }
 
+/**
+ *  @brief
+ *    Unset the low-priority default route for the specified IP
+ *    configuration type from the provided gateway data.
+ *
+ *  This attempts to unset, or clear, the low-priority (that is,
+ *  metric > 0) default route for the specified IP configuration type
+ *  from the provided gateway data. The network interface and, by
+ *  extension, the network service with which the gateway is
+ *  associated is determined by the @a index field of @a data.
+ *
+ *  On success, the gateway configuration state specific to @a type
+ *  will be set to #CONNMAN_GATEWAY_CONFIG_STATE_REMOVED.
+ *
+ *  @param[in,out]  data  A pointer to the mutable gateway data to
+ *                        clear as the low-priority default route.
+ *  @param[in]      type  The IP configuration type for which the
+ *                        gateway, or default router, configuration
+ *                        will be selected from @a data and used to
+ *                        unset the low-priority default route.
+ *
+ *  @retval  0              If successful.
+ *  @retval  -EINVAL        If @a data is null, if @a type is invalid,
+ *                          if the gateway configuration type is not
+ *                          type
+ *                          #CONNMAN_GATEWAY_CONFIG_TYPE_LOW_PRIORITY_DEFAULT,
+ *                          or if the routing information to be unset,
+ *                          or cleared, was invalid.
+ *  @retval  -EINPROGRESS   If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_REMOVED.
+ *  @retval  -EALREADY      If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE.
+ *  @retval  -EFAULT        If the address to the routing information
+ *                          to be unset, or cleared, was invalid.
+ *  @retval  -EPERM         If the current process does not have the
+ *                          credentials or capabilities to unset, or
+ *                          clear, routes.
+ *  @retval  -ESRCH         A request was made to unset, or clear a
+ *                          non-existing routing entry.
+ *
+ *  @sa mutatate_default_gateway
+ *  @sa unset_ipv4_low_priority_default_gateway
+ *
+ */
 static int unset_low_priority_default_gateway(struct gateway_data *data,
 				enum connman_ipconfig_type type,
 				const char *function)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 84/90] connection: Fix documentation typos.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (85 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 83/90] connection: Document 'unset_low_priority_default_gateway' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 85/90] connection: Update 'set_default_gateway_route_common' documentation Grant Erickson
                   ` (5 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

This corrects prior documentation '@param' typos for
'check_default_gateway' and 'remove_gateway'.
---
 src/connection.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index db108ed03a19..0dadc99e2337 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -3038,7 +3038,7 @@ static void check_default_gateway(struct gateway_data *activated)
  *
  *  @param[in]  index    The network interface index associated with
  *                       the newly-added gateway, or default router.
- *  @param[in]  gateway  An pointer to an immutable null-terminated
+ *  @param[in]  gateway  A pointer to an immutable null-terminated
  *                       C string containing the text-
  *                       formatted address of the gateway, or default
  *                       router, that was added.
@@ -3165,7 +3165,7 @@ static void remove_gateway(gpointer user_data)
  *
  *  @param[in]  index    The network interface index associated with
  *                       the newly-removed gateway, or default router.
- *  @param[in]  gateway  An pointer to an immutable null-terminated
+ *  @param[in]  gateway  A pointer to an immutable null-terminated
  *                       C string containing the text-
  *                       formatted address of the gateway, or default
  *                       router, that was removed.
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 85/90] connection: Update 'set_default_gateway_route_common' documentation.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (86 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 84/90] connection: Fix documentation typos Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 86/90] connection: Update 'unset_default_gateway_route_common' documentation Grant Erickson
                   ` (4 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This updates the "see also" documentation for
'set_default_gateway_route_common' to reflect other functions it calls
or depends on.
---
 src/connection.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 0dadc99e2337..84718d491ded 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1575,7 +1575,10 @@ static int mutate_default_gateway(struct gateway_data *data,
  *  @retval  -EEXIST        A request was made to add an existing
  *                          routing entry.
  *
+ *  @sa gateway_config_state_set
  *  @sa gateway_config_type_set
+ *  @sa is_gateway_config_state
+ *  @sa is_gateway_config_type
  *  @sa unset_default_gateway_route_common
  *
  */
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 86/90] connection: Update 'unset_default_gateway_route_common' documentation.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (87 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 85/90] connection: Update 'set_default_gateway_route_common' documentation Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 87/90] connection: Update '{un,}set_default_gateway' documentation Grant Erickson
                   ` (3 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This updates the "see also" documentation for
'unset_default_gateway_route_common' to reflect other functions it calls
or depends on.
---
 src/connection.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 84718d491ded..a7b2777f53f4 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1655,6 +1655,9 @@ done:
  *  @retval  -ESRCH         A request was made to unset, or clear a
  *                          non-existing routing entry.
  *
+ *  @sa gateway_config_state_set
+ *  @sa is_gateway_config_state
+ *  @sa is_gateway_config_type
  *  @sa set_default_gateway_route_common
  *
  */
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 87/90] connection: Update '{un,}set_default_gateway' documentation.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (88 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 86/90] connection: Update 'unset_default_gateway_route_common' documentation Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 88/90] connection: Add @file comment Grant Erickson
                   ` (2 subsequent siblings)
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This updates the '{un,}set_default_gateway' function documentation to
reflect changes due to adding support for both high- and low-priority
default gateway routes.
---
 src/connection.c | 92 +++++++++++++++++++++++++++++++++---------------
 1 file changed, 64 insertions(+), 28 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index a7b2777f53f4..8f745a4387bb 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1949,33 +1949,52 @@ static int set_ipv6_high_priority_default_gateway(struct gateway_data *data,
 
 /**
  *  @brief
- *    Set, or assign, the gateway, or default route, for the specified
- *    IP configuration type from the provided gateway data.
+ *    Set, or add, the gateway high-priority default route for the
+ *    specified IP configuration type from the provided gateway data.
  *
- *  This attempts to set, or assign, the gateway, or default, route
- *  for the specified IP configuration type from the provided gateway
- *  data. The network interface and, by extension, the network service
- *  with which the gateway is associated is determined by the @a index
- *  field of @a data.
+ *  This attempts to set, or add, the high-priority (that is,
+ *  metric 0) default route for the specified IP configuration type
+ *  from the provided gateway data. The network interface and, by
+ *  extension, the network service with which the gateway is
+ *  associated is determined by the @a index field of @a data.
  *
- *  On success, the gateway configuration specific to @a type will
- *  have its @a active field set to true and the gateway data network
- *  service @a service will be signaled as the default via
- *  #__connman_service_indicate_default.
+ *  On success, the gateway configuration state and type specific to
+ *  @a type will be set to #CONNMAN_GATEWAY_CONFIG_STATE_ADDED and
+ *  #CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT, respectively,
+ *  and the gateway data network service @a service will be signaled
+ *  as the default via #__connman_service_indicate_default.
  *
  *  @param[in,out]  data      A pointer to the mutable gateway data
- *                            to assign as the default route.
+ *                            to assign as the high-priority default
+ *                            route.
  *  @param[in]      type      The IP configuration type for which the
  *                            gateway, or default router,
  *                            configuration will be selected from @a
- *                            data and used to set the default route.
+ *                            data and used to set the high-priority
+ *                            default route.
  *  @param[in]      function  A pointer to an immutable null-terminated
  *                            C string containing the function name to
  *                            which the call to this function should
  *                            be attributed.
  *
- * @returns
- *   0 if successful; otherwise, < 0 on error.
+ *  @retval  0              If successful.
+ *  @retval  -EINVAL        If @a data or @a config are
+ *                          null; if the gateway configuration type is
+ *                          not #CONNMAN_GATEWAY_CONFIG_TYPE_NONE or
+ *                          #CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT;
+ *                          or if the routing information to be set,
+ *                          or added, was invalid.
+ *  @retval  -EINPROGRESS   If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_ADDED.
+ *  @retval  -EALREADY      If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE.
+ *  @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, or
+ *                          set, routes.
+ *  @retval  -EEXIST        A request was made to add an existing
+ *                          routing entry.
  *
  *  @sa mutate_default_gateway
  *  @sa set_ipv4_high_priority_default_gateway
@@ -2242,32 +2261,49 @@ static int unset_ipv6_high_priority_default_gateway(
 
 /**
  *  @brief
- *    Unset the gateway, or default route, for the specified IP
+ *    Unset the high-priority default route for the specified IP
  *    configuration type from the provided gateway data.
  *
- *  This attempts to unset, or clear, the gateway, or default, route
- *  for the specified IP configuration type from the provided gateway
- *  data. The network interface and, by extension, the network service
- *  with which the gateway is associated is determined by the @a index
- *  field of @a data.
+ *  This attempts to unset, or clear, the high-priority (that is,
+ *  metric 0) default route for the specified IP configuration type
+ *  from the provided gateway data. The network interface and, by
+ *  extension, the network service with which the gateway is
+ *  associated is determined by the @a index field of @a data.
  *
- *  On success, the gateway configuration specific to @a type will
- *  have its @a active field set to false.
+ *  On success, the gateway configuration state specific to @a type
+ *  will be set to #CONNMAN_GATEWAY_CONFIG_STATE_REMOVED.
  *
  *  @param[in,out]  data      A pointer to the mutable gateway data
- *                            to clear as the default route.
+ *                            to clear as the high-priority default
+ *                            route.
  *  @param[in]      type      The IP configuration type for which
  *                            the gateway, or default router,
  *                            configuration will be selected from @a
- *                            data and used to unset the default route.
+ *                            data and used to unset the high-priority
+ *                            default route.
  *  @param[in]      function  A pointer to an immutable null-terminated
  *                            C string containing the function name to
  *                            which the call to this function should
  *                            be attributed.
  *
- *
- * @returns
- *   0 if successful; otherwise, < 0 on error.
+ *  @retval  0              If successful.
+ *  @retval  -EINVAL        If @a data is null, if @a type is invalid,
+ *                          if the gateway configuration type is not
+ *                          type
+ *                          #CONNMAN_GATEWAY_CONFIG_TYPE_HIGH_PRIORITY_DEFAULT,
+ *                          or if the routing information to be unset,
+ *                          or cleared, was invalid.
+ *  @retval  -EINPROGRESS   If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_REMOVED.
+ *  @retval  -EALREADY      If the state of @a config is
+ *                          #CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE.
+ *  @retval  -EFAULT        If the address to the routing information
+ *                          to be unset, or cleared, was invalid.
+ *  @retval  -EPERM         If the current process does not have the
+ *                          credentials or capabilities to unset, or
+ *                          clear, routes.
+ *  @retval  -ESRCH         A request was made to unset, or clear a
+ *                          non-existing routing entry.
  *
  *  @sa mutate_default_gateway
  *  @sa unset_ipv4_default_gateway
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 88/90] connection: Add @file comment.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (89 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 87/90] connection: Update '{un,}set_default_gateway' documentation Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 89/90] connection: Add whitespace around 'del_gateway_routes_if_active' Grant Erickson
  2023-12-06 23:50 ` [PATCH 90/90] connection: Ensure function attribution 'DBG' output is consistent Grant Erickson
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This adds a detailed @file comment, providing a high-level overview of
the module, key issues and principles, and theory of operation.
---
 src/connection.c | 208 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 208 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 8f745a4387bb..47ec67e6717a 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -20,6 +20,214 @@
  *
  */
 
+/**
+ *  @file
+ *    This implements non-client-facing functionality for managing
+ *    network service gateways and routes. It also serves as a Linux
+ *    Routing Netlink (rtnl) listener for routing table additions and
+ *    deletions in the Linux kernel.
+ *
+ *    Gateway lifecycle is generally top-down, from user space to
+ *    kernel. That is, Connection Manager manages and adds/sets or
+ *    gateway routes and then uses notifications from the kernel
+ *    Routing Netlink (rtnl) to confirm and "activate" those
+ *    routes. Likewise, Connection Manager removes/clears/deletes
+ *    gateway routes an then uses notifications from the kernel
+ *    Routing Netlink (rtnl) to confirm and "inactivate" those
+ *    routes. The following is the state machine for that lifecycle:
+ *
+ *                              .----------.    SIOCADDRT /
+ *                              |          |    RTM_NEWROUTE
+ *           .------------------| Inactive |--------------------.
+ *           |                  |          |                    |
+ *           |                  '----------'                    |
+ *           | connman_rtnl                                     |
+ *           | .delgateway                                      |
+ *           |                                                  V
+ *      .---------.         SIOCADDRT / RTM_NEWROUTE        .-------.
+ *      |         |---------------------------------------->|       |
+ *      | Removed |                                         | Added |
+ *      |         |<----------------------------------------|       |
+ *      '---------'         SIOCDELRT / RTM_DELROUTE        '-------'
+ *           ^                                                  |
+ *           | SIOCDELRT /                                      |
+ *           | RTM_DELROUTE                                     |
+ *           |                   .--------.     connman_rtnl    |
+ *           |                   |        |     .newgateway     |
+ *           '-------------------| Active |<--------------------'
+ *                               |        |
+ *                               '--------'
+ *
+ *    Gateways, and their associated routes, are generally of two types:
+ *
+ *      1. High-priority (that is, metric 0) default route.
+ *
+ *         This is used by the default service and its underlying
+ *         network interface.
+ *
+ *      2. Low-priority (that is, metric > 0) default route.
+ *
+ *         This is used by non-default services and their underlying
+ *         network interface.
+ *
+ *         For IPv6, these are handled and managed automatically by
+ *         the kernel as part of Router Discovery (RD) Router
+ *         Advertisements (RAs) and because link-local addresses and
+ *         multi-homing are a natural part of IPv6, nothing needs to
+ *         be done here. These routes show up in 'ip -6 route show'
+ *         as:
+ *
+ *             default via fe80::f29f:c2ff:fe10:271e dev eth0
+ *                 proto ra metric 1024 expires 1622sec hoplimit 64
+ *                 pref medium
+ *             default via fe80::f29f:c2ff:fe10:271e dev wlan0
+ *                 proto ra metric 1024 expires 1354sec hoplimit 64
+ *                 pref medium
+ *
+ *         For IPv4, largely invented before the advent of link-local
+ *         addresses and multi-homing hosts, these need to be
+ *         fully-managed here and, with such management, show up in
+ *         'ip -4 route show' as low-priority (that is, high metric
+ *         value) default routes:
+ *
+ *             default via 192.168.2.1 dev wlan0 metric 4294967295
+ *
+ *         The other alternative to low-priority routes would be to
+ *         use "def1" default routes commonly used by VPNs that have a
+ *         prefix length of 1 (hence the "def1" name). These would
+ *         show up as:
+ *
+ *             0.0.0.0/1 via 192.168.2.1 dev wlan0
+ *             128.0.0.0/1 via 192.168.2.1 dev wlan0
+ *
+ *         However, since these require twice the number of routing
+ *         table entries and seem no more effective than the
+ *         low-priority route approach, this alternative is not used
+ *         here at present.
+ *
+ *    VPNs and point-to-point (P2P) links get special treatment but
+ *    otherwise utilize the same states and types as described above.
+ *
+ *    Operationally, down calls from outside this module generally
+ *    come from the following three functions:
+ *
+ *      1. __connman_connection_gateway_add
+ *      2. __connman_connection_gateway_remove
+ *      3. __connman_connection_update_gateway
+ *
+ *    and up calls generally come from the following two functions:
+ *
+ *      1. connection_newgateway
+ *      2. connection_delgateway
+ *
+ *    From these five functions above, we are then attempting to do
+ *    the following for a gateway associated with a network service
+ *    and its underlying network interface:
+ *
+ *      1. Set, or add, the high- or low-priority default route(s).
+ *      2. Unset, or remove, the high- or low-priority default route(s).
+ *      3. Promote the default route from low- to high-priority.
+ *      4. Demote the default route from high- to low-priority.
+ *
+ *    The call trees for these operations amount to:
+ *
+ *      set_default_gateway (1)
+ *        |
+ *        '-mutate_default_gateway
+ *            |
+ *            |-set_ipv4_high_priority_default_gateway
+ *            |   |
+ *            |   '-set_default_gateway_route_common
+ *            |       |
+ *            |       '-set_ipv4_high_priority_default_gateway_route_cb
+ *            |
+ *            '-set_ipv6_high_priority_default_gateway
+ *                |
+ *                '-set_default_gateway_route_common
+ *                    |
+ *                    '-set_ipv6_high_priority_default_gateway_route_cb
+ *
+ *      set_low_priority_default_gateway (1)
+ *        |
+ *        '-mutate_default_gateway
+ *            |
+ *            '-set_ipv4_low_priority_default_gateway
+ *                |
+ *                '-set_default_gateway_route_common
+ *                    |
+ *                    '-set_ipv4_low_priority_default_gateway_route_cb
+ *                        |
+ *                        '-compute_low_priority_metric
+ *
+ *      unset_default_gateway (2)
+ *        |
+ *        '-mutate_default_gateway
+ *            |
+ *            |-unset_ipv4_high_priority_default_gateway
+ *            |   |
+ *            |   '-unset_default_gateway_route_common
+ *            |       |
+ *            |       '-unset_ipv4_high_priority_default_gateway_route_cb
+ *            |
+ *            '-unset_ipv6_high_priority_default_gateway
+ *                |
+ *                '-unset_default_gateway_route_common
+ *                    |
+ *                    '-unset_ipv6_high_priority_default_gateway_route_cb
+ *
+ *      unset_low_priority_default_gateway (2)
+ *        |
+ *        '-mutate_default_gateway
+ *            |
+ *            '-unset_ipv4_low_priority_default_gateway
+ *                |
+ *                '-unset_default_gateway_route_common
+ *                    |
+ *                    '-unset_ipv4_low_priority_default_gateway_route_cb
+ *                        |
+ *                        '-compute_low_priority_metric
+ *
+ *      promote_default_gateway (3)
+ *        |
+ *        |-unset_low_priority_default_gateway (2)
+ *        |
+ *        '-set_default_gateway (1)
+ *
+ *      demote_default_gateway (4)
+ *        |
+ *        |-unset_default_gateway (2)
+ *        |
+ *        '-set_low_priority_default_gateway (1)
+ *
+ *    where:
+ *
+ *      * 'mutate_default_gateway' and
+ *        '{un,}set_default_gateway_route_common' are abstract,
+ *        generalized handlers that manage the broad error conditions
+ *        and gateway data and configuration lifecycle management.
+ *
+ *      * '*_route_cb' callbacks handle the actual routing table
+ *        manipulation as appropriate for the IP configuration and
+ *        gateway type, largely through the use of gateway
+ *        configuration "ops" to help neutralize differences between
+ *        IPv4 and IPv6.
+ *
+ *        In the fullness of time, the use of the gateway
+ *        configuration "ops" should allow further collapsing the IPv4
+ *        and IPv6 cases and simplifying the IP type-specific branches
+ *        of the above call trees.
+ *
+ *        The low-priority metric is determined on a per-network
+ *        interface basis and is computed by
+ *        'compute_low_priority_metric'.
+ *
+ *    Historically, this file started life as "connection.c". However,
+ *    today it might be better named "route.c" or, perhaps more
+ *    precisely, "gateway.c" since its primary focus is gateway routes
+ *    and gateway route management.
+ *
+ */
+
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 89/90] connection: Add whitespace around 'del_gateway_routes_if_active'.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (90 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 88/90] connection: Add @file comment Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  2023-12-06 23:50 ` [PATCH 90/90] connection: Ensure function attribution 'DBG' output is consistent Grant Erickson
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

From: Grant Erickson <erick205@umn.edu>

Increase visual visibility of 'del_gateway_routes_if_active' in
'add_gateway' by adding blank lines both before and after the function
call.
---
 src/connection.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 47ec67e6717a..3128110a27e2 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1659,7 +1659,9 @@ static int add_gateway(struct connman_service *service,
 	if (old) {
 		DBG("Replacing gw %p ipv4 %p ipv6 %p", old,
 			old->ipv4_config, old->ipv6_config);
+
 		del_gateway_routes_if_active(old, type);
+
 		if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
 			temp_data->ipv6_config = old->ipv6_config;
 			old->ipv6_config = NULL;
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [PATCH 90/90] connection: Ensure function attribution 'DBG' output is consistent.
  2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
                   ` (91 preceding siblings ...)
  2023-12-06 23:50 ` [PATCH 89/90] connection: Add whitespace around 'del_gateway_routes_if_active' Grant Erickson
@ 2023-12-06 23:50 ` Grant Erickson
  92 siblings, 0 replies; 94+ messages in thread
From: Grant Erickson @ 2023-12-06 23:50 UTC (permalink / raw)
  To: connman

This ensures that function call attribution 'DBG' output is consistent
in the format "from %s()".
---
 src/connection.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 3128110a27e2..0c1bdba7f515 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -820,7 +820,7 @@ static void gateway_config_debug(const char *function,
 		return;
 
 	if (!config)
-		DBG("from %s %s %p", function, description, config);
+		DBG("from %s() %s %p", function, description, config);
 	else {
 		if (config->vpn_phy_index >= 0)
 			vpn_phy_interface =
@@ -883,11 +883,11 @@ static void gateway_data_debug(const char *function,
 		return;
 
 	if (!data)
-		DBG("from %s %s %p", function, description, data);
+		DBG("from %s() %s %p", function, description, data);
 	else {
 		interface = connman_inet_ifname(data->index);
 
-		DBG("from %s %s %p: { index: %d (%s), service: %p (%s), "
+		DBG("from %s() %s %p: { index: %d (%s), service: %p (%s), "
 			"ipv4_config: %p, ipv6_config: %p, default_checked: %u }",
 			function,
 			description,
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 94+ messages in thread

end of thread, other threads:[~2023-12-06 23:51 UTC | newest]

Thread overview: 94+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-06 23:49 [PATCH 00/90] Add Gateway Low-priority Default Routes for Non-default Services Grant Erickson
2023-12-06 23:49 ` [PATCH 01/90] connection: Rename 'find_active_gateway_data' Grant Erickson
2023-12-06 23:49 ` [PATCH 02/90] connection: Document 'find_any_active_gateway_data' Grant Erickson
2023-12-06 23:49 ` [PATCH 03/90] connection: Replace gateway config active Boolean Grant Erickson
2023-12-06 23:49 ` [PATCH 04/90] connection: Document gateway configuration state Grant Erickson
2023-12-06 23:49 ` [PATCH 05/90] connection: Replace gateway config VPN Boolean Grant Erickson
2023-12-06 23:49 ` [PATCH 06/90] connection: Document gateway configuration flags Grant Erickson
2023-12-06 23:49 ` [PATCH 07/90] connection: Introduce gateway configuration 'type' Grant Erickson
2023-12-06 23:49 ` [PATCH 08/90] connection: Document 'gateway_config_type' Grant Erickson
2023-12-06 23:49 ` [PATCH 09/90] connection: Add function parameter to {un,}set_default_gateway Grant Erickson
2023-12-06 23:49 ` [PATCH 10/90] connection: Fix 'DBG' copy-and-paste typo Grant Erickson
2023-12-06 23:49 ` [PATCH 11/90] connection: Split '{un,}_default_gateway' IP-specific functions Grant Erickson
2023-12-06 23:49 ` [PATCH 12/90] connection: Add 'DBG' to 'del_gateway_routes' Grant Erickson
2023-12-06 23:49 ` [PATCH 13/90] connection: Rename 'active_gateway' local Grant Erickson
2023-12-06 23:49 ` [PATCH 14/90] connection: Check 'service' parameter for null Grant Erickson
2023-12-06 23:49 ` [PATCH 15/90] connection: Check service network index for validity Grant Erickson
2023-12-06 23:49 ` [PATCH 16/90] connection: Refactor '__connman_connection_gateway_add' Grant Erickson
2023-12-06 23:49 ` [PATCH 17/90] connection: Remove 'DBG' from '__connman_connection_update_gateway' Grant Erickson
2023-12-06 23:49 ` [PATCH 18/90] connection: Refactor 'yield_default_gateway' Grant Erickson
2023-12-06 23:49 ` [PATCH 19/90] connection: Document 'gateway_data_config_get' Grant Erickson
2023-12-06 23:49 ` [PATCH 20/90] connection: Document 'yield_default_gateway_for_type' Grant Erickson
2023-12-06 23:49 ` [PATCH 21/90] connection: Add 'gateway_config_free' Grant Erickson
2023-12-06 23:49 ` [PATCH 22/90] connection: Document 'gateway_config_free' Grant Erickson
2023-12-06 23:49 ` [PATCH 23/90] connection: Introduce and leverage 'mutate_default_gateway' Grant Erickson
2023-12-06 23:49 ` [PATCH 24/90] connection: Document 'mutate_default_gateway_ops' Grant Erickson
2023-12-06 23:49 ` [PATCH 25/90] connection: Document 'mutate_default_gateway' Grant Erickson
2023-12-06 23:49 ` [PATCH 26/90] connection: Add gateway config ADDED/REMOVED states Grant Erickson
2023-12-06 23:49 ` [PATCH 27/90] connection: Add low-priority default gateway config type Grant Erickson
2023-12-06 23:49 ` [PATCH 28/90] connection: Change return type of 'unset_default_gateway' Grant Erickson
2023-12-06 23:49 ` [PATCH 29/90] connection: Leverage 'unset_default_gateway' in 'del_gateway_routes' Grant Erickson
2023-12-06 23:49 ` [PATCH 30/90] connection: Change return type of 'set_default_gateway' Grant Erickson
2023-12-06 23:49 ` [PATCH 31/90] connection: Fan out route manipulation into callbacks Grant Erickson
2023-12-06 23:49 ` [PATCH 32/90] connection: Document 'mutate_default_gateway_route_cb_t' Grant Erickson
2023-12-06 23:49 ` [PATCH 33/90] connection: Document 'set_default_gateway_route_common' Grant Erickson
2023-12-06 23:49 ` [PATCH 34/90] connection: Document 'unset_default_gateway_route_common' Grant Erickson
2023-12-06 23:49 ` [PATCH 35/90] inet: Add '__connman_inet_table2string' Grant Erickson
2023-12-06 23:49 ` [PATCH 36/90] inet: Document '__connman_inet_table2string' Grant Erickson
2023-12-06 23:50 ` [PATCH 37/90] inet: Leverage '__connman_inet_table2string' Grant Erickson
2023-12-06 23:50 ` [PATCH 38/90] rtnl: Add support for extracting the table identifier Grant Erickson
2023-12-06 23:50 ` [PATCH 39/90] ipconfig: Pass the rtnl table to '__connman_ipconfig_{new,del}route' Grant Erickson
2023-12-06 23:50 ` [PATCH 39/90] ipconfig: Pass the rtnl table to " Grant Erickson
2023-12-06 23:50 ` [PATCH 40/90] rtnl: Add support for extracting the metric/priority Grant Erickson
2023-12-06 23:50 ` [PATCH 41/90] ipconfig: Pass the rtnl metric to '__connman_ipconfig_{new,del}route' Grant Erickson
2023-12-06 23:50 ` [PATCH 41/90] ipconfig: Pass the rtnl metric to " Grant Erickson
2023-12-06 23:50 ` [PATCH 42/90] ipconfig: Pass the rtnl dst prefixlen " Grant Erickson
2023-12-06 23:50 ` [PATCH 42/90] ipconfig: Pass the rtnl dst prefixlen to " Grant Erickson
2023-12-06 23:50 ` [PATCH 43/90] inet: Include interface index and name in 'DBG' Grant Erickson
2023-12-06 23:50 ` [PATCH 44/90] inet: Include the command value and string " Grant Erickson
2023-12-06 23:50 ` [PATCH 45/90] ipconfig: Use 'RT_SCOPE_*' mnemonics Grant Erickson
2023-12-06 23:50 ` [PATCH 46/90] inet: Add a metric parameter to 'iproute_default_modify' Grant Erickson
2023-12-06 23:50 ` [PATCH 47/90] inet: Document 'iproute_default_modify' Grant Erickson
2023-12-06 23:50 ` [PATCH 48/90] connection: Document '__connman_inet_add_default_to_table' Grant Erickson
2023-12-06 23:50 ` [PATCH 49/90] connection: Document '__connman_inet_del_default_to_table' Grant Erickson
2023-12-06 23:50 ` [PATCH 50/90] inet: Add '__connman_inet_{add,del}_default_{to,from}_table_with_metric' Grant Erickson
2023-12-06 23:50 ` [PATCH 51/90] inet: Document '__connman_inet_{add,del}_default_{to,from}_table_with_metric' Grant Erickson
2023-12-06 23:50 ` [PATCH 52/90] connection: Add support for low-priority default routes Grant Erickson
2023-12-06 23:50 ` [PATCH 53/90] connection: Introduce '{de,pro}mote_default_gateway' Grant Erickson
2023-12-06 23:50 ` [PATCH 54/90] connection: Add 'is_addr_any_str' Grant Erickson
2023-12-06 23:50 ` [PATCH 55/90] connection: Introduce gateway config 'ops' Grant Erickson
2023-12-06 23:50 ` [PATCH 56/90] connection: Refactor 'add_host_route' Grant Erickson
2023-12-06 23:50 ` [PATCH 57/90] connection: Add 'DBG' else clauses to 'connection_delgateway' Grant Erickson
2023-12-06 23:50 ` [PATCH 58/90] connection: Document 'gateway_config_state' finite state machine Grant Erickson
2023-12-06 23:50 ` [PATCH 59/90] connection: Document 'gateway_config_ops' Grant Erickson
2023-12-06 23:50 ` [PATCH 60/90] connection: Document 'gateway_config' Grant Erickson
2023-12-06 23:50 ` [PATCH 61/90] connection: Document 'gateway_data' Grant Erickson
2023-12-06 23:50 ` [PATCH 62/90] connection: Document 'gateway_hash' Grant Erickson
2023-12-06 23:50 ` [PATCH 63/90] connection: Document 'is_addr_any_str' Grant Erickson
2023-12-06 23:50 ` [PATCH 64/90] connection: Update 'find_any_active_gateway_data' documentation Grant Erickson
2023-12-06 23:50 ` [PATCH 65/90] connection: Document 'compute_low_priority_metric' Grant Erickson
2023-12-06 23:50 ` [PATCH 66/90] connection: Document 'add_host_route' Grant Erickson
2023-12-06 23:50 ` [PATCH 67/90] connection: Document call to 'connman_service_unref' Grant Erickson
2023-12-06 23:50 ` [PATCH 68/90] connection: Document 'demote_default_gateway' Grant Erickson
2023-12-06 23:50 ` [PATCH 69/90] connection: Document 'promote_default_gateway' Grant Erickson
2023-12-06 23:50 ` [PATCH 70/90] connection: Document 'set_ipv4_high_priority_default_gateway_route_cb' Grant Erickson
2023-12-06 23:50 ` [PATCH 71/90] connection: Document 'set_ipv6_high_priority_default_gateway_route_cb' Grant Erickson
2023-12-06 23:50 ` [PATCH 72/90] connection: Document 'set_ipv4_high_priority_default_gateway' Grant Erickson
2023-12-06 23:50 ` [PATCH 73/90] connection: Document 'set_ipv6_high_priority_default_gateway' Grant Erickson
2023-12-06 23:50 ` [PATCH 74/90] connection: Document 'unset_ipv4_high_priority_default_gateway_route_cb' Grant Erickson
2023-12-06 23:50 ` [PATCH 75/90] connection: Document 'unset_ipv6_high_priority_default_gateway_route_cb' Grant Erickson
2023-12-06 23:50 ` [PATCH 76/90] connection: Document 'unset_ipv4_high_priority_default_gateway' Grant Erickson
2023-12-06 23:50 ` [PATCH 77/90] connection: Document 'unset_ipv6_high_priority_default_gateway' Grant Erickson
2023-12-06 23:50 ` [PATCH 78/90] connection: Document 'set_ipv4_low_priority_default_gateway_route_cb' Grant Erickson
2023-12-06 23:50 ` [PATCH 79/90] connection: Document 'set_ipv4_low_priority_default_gateway' Grant Erickson
2023-12-06 23:50 ` [PATCH 80/90] connection: Document 'set_low_priority_default_gateway' Grant Erickson
2023-12-06 23:50 ` [PATCH 81/90] connection: Document 'unset_ipv4_low_priority_default_gateway_route_cb' Grant Erickson
2023-12-06 23:50 ` [PATCH 82/90] connection: Document 'unset_ipv4_low_priority_default_gateway' Grant Erickson
2023-12-06 23:50 ` [PATCH 83/90] connection: Document 'unset_low_priority_default_gateway' Grant Erickson
2023-12-06 23:50 ` [PATCH 84/90] connection: Fix documentation typos Grant Erickson
2023-12-06 23:50 ` [PATCH 85/90] connection: Update 'set_default_gateway_route_common' documentation Grant Erickson
2023-12-06 23:50 ` [PATCH 86/90] connection: Update 'unset_default_gateway_route_common' documentation Grant Erickson
2023-12-06 23:50 ` [PATCH 87/90] connection: Update '{un,}set_default_gateway' documentation Grant Erickson
2023-12-06 23:50 ` [PATCH 88/90] connection: Add @file comment Grant Erickson
2023-12-06 23:50 ` [PATCH 89/90] connection: Add whitespace around 'del_gateway_routes_if_active' Grant Erickson
2023-12-06 23:50 ` [PATCH 90/90] connection: Ensure function attribution 'DBG' output is consistent Grant Erickson

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 NNTP newsgroup(s).