[PATCH 09/45] vpn: Add VPN agent use callback for plugins
Jussi Laakkonen <[email protected]> Fri, 11 Jul 2025 17:27:00 +0300
| Newsgroups | dev.linux.lists.connman |
|---|---|
| Message-ID | <[email protected]> |
Add callback that can be used by the VPN plugins to tell the vpn_driver
whether it uses VPN agent or not. Default to using VPN agent if the
function is not defined.
This is done to accommodate the state transition in vpn-provider when
the VPN does not utilize VPN agent.
---
vpn/plugins/vpn.c | 22 ++++++++++++++++++++++
vpn/plugins/vpn.h | 1 +
vpn/vpn-provider.h | 1 +
3 files changed, 24 insertions(+)
diff --git a/vpn/plugins/vpn.c b/vpn/plugins/vpn.c
index 52f7cac7..2f87cf04 100644
--- a/vpn/plugins/vpn.c
+++ b/vpn/plugins/vpn.c
@@ -800,6 +800,27 @@ static int vpn_route_env_parse(struct vpn_provider *provider, const char *key,
return 0;
}
+static bool vpn_uses_vpn_agent(struct vpn_provider *provider)
+{
+ struct vpn_driver_data *vpn_driver_data = NULL;
+ const char *name = NULL;
+
+ if (!provider)
+ return false;
+
+ name = vpn_provider_get_driver_name(provider);
+ vpn_driver_data = g_hash_table_lookup(driver_hash, name);
+
+ if (vpn_driver_data && vpn_driver_data->vpn_driver->uses_vpn_agent)
+ return vpn_driver_data->vpn_driver->uses_vpn_agent(provider);
+
+ /*
+ * Default to using the VPN agent, in cases where the function is not
+ * implemented. The use of VPN agent must be explicitly dropped.
+ */
+ return true;
+}
+
int vpn_register(const char *name, const struct vpn_driver *vpn_driver,
const char *program)
{
@@ -825,6 +846,7 @@ int vpn_register(const char *name, const struct vpn_driver *vpn_driver,
data->provider_driver.save = vpn_save;
data->provider_driver.set_state = vpn_set_state;
data->provider_driver.route_env_parse = vpn_route_env_parse;
+ data->provider_driver.uses_vpn_agent = vpn_uses_vpn_agent;
if (!driver_hash)
driver_hash = g_hash_table_new_full(g_str_hash,
diff --git a/vpn/plugins/vpn.h b/vpn/plugins/vpn.h
index a8d24fc3..b24cbf9b 100644
--- a/vpn/plugins/vpn.h
+++ b/vpn/plugins/vpn.h
@@ -57,6 +57,7 @@ struct vpn_driver {
int (*route_env_parse) (struct vpn_provider *provider, const char *key,
int *family, unsigned long *idx,
enum vpn_provider_route_type *type);
+ bool (*uses_vpn_agent) (struct vpn_provider *provider);
};
int vpn_register(const char *name, const struct vpn_driver *driver,
diff --git a/vpn/vpn-provider.h b/vpn/vpn-provider.h
index c81476c6..8a8b6bfd 100644
--- a/vpn/vpn-provider.h
+++ b/vpn/vpn-provider.h
@@ -167,6 +167,7 @@ struct vpn_provider_driver {
int (*route_env_parse) (struct vpn_provider *provider, const char *key,
int *family, unsigned long *idx,
enum vpn_provider_route_type *type);
+ bool (*uses_vpn_agent) (struct vpn_provider *provider);
};
int vpn_provider_driver_register(struct vpn_provider_driver *driver);
--
2.39.5