diff mbox series

[4/5] gateway: Add and leveage 'gateway_config_set_{,in}active'.

Message ID 20231220055613.2287074-5-gerickson@nuovations.com (mailing list archive)
State Accepted, archived
Headers show
Series Address Unhandled Gateway Route Lifecycle Events/Transitions | expand

Commit Message

Grant Erickson Dec. 20, 2023, 5:56 a.m. UTC
This encapsulates and makes symmetric the actions at the "terminal
ends" of the gateway configuration lifecycle / state machine by adding
and leveraging 'gateway_config_set_{,in}active' to set the gateway
configuration state and type appropriately.
---
 src/gateway.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/src/gateway.c b/src/gateway.c
index b5a1e2ddbf19..42a8da72642c 100644
--- a/src/gateway.c
+++ b/src/gateway.c
@@ -787,6 +787,20 @@  static bool is_gateway_config_type(const struct gateway_config *config,
 	return config->type == type;
 }
 
+static void gateway_config_set_active(struct gateway_config *config)
+{
+	gateway_config_state_set(config, CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
+}
+
+static void gateway_config_set_inactive(struct gateway_config *config)
+{
+	gateway_config_state_set(config,
+		CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
+
+	gateway_config_type_set(config,
+		CONNMAN_GATEWAY_CONFIG_TYPE_NONE);
+}
+
 /**
  *  @brief
  *    Conditionally log the specified gateway configuration.
@@ -3366,8 +3380,7 @@  static void gateway_rtnl_new(int index, const char *gateway)
 	 * and it is now acknowledged by the kernel. Consequently, mark it
 	 * as active.
 	 */
-	gateway_config_state_set(config,
-		CONNMAN_GATEWAY_CONFIG_STATE_ACTIVE);
+	gateway_config_set_active(config);
 
 	/*
 	 * It is possible that we have two default routes atm
@@ -3471,13 +3484,9 @@  static void gateway_rtnl_del(int index, const char *gateway)
 	if (config) {
 		GATEWAY_CONFIG_DBG("config", config);
 
-		if (is_gateway_config_state_removed(config)) {
-			gateway_config_state_set(config,
-				CONNMAN_GATEWAY_CONFIG_STATE_INACTIVE);
-
-			gateway_config_type_set(config,
-				CONNMAN_GATEWAY_CONFIG_TYPE_NONE);
-		} else {
+		if (is_gateway_config_state_removed(config))
+			gateway_config_set_inactive(config);
+		else {
 			DBG("ignoring gateway stale removed activation; "
 			"probably added before removed activation completed");