[PATCH v2 08/42] vpn: Add VPN agent use flag for plugins
Jussi Laakkonen <[email protected]> Wed, 13 Aug 2025 18:01:40 +0300
| Newsgroups | dev.linux.lists.connman |
|---|---|
| Message-ID | <[email protected]> |
Add a flag 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 flag
is omitted.
This is done to accommodate the state transition in vpn-provider when
the VPN does not utilize VPN agent.
---
vpn/plugins/vpn.c | 19 +++++++++++++++++++
vpn/plugins/vpn.h | 1 +
vpn/vpn-provider.h | 1 +
3 files changed, 21 insertions(+)
diff --git a/vpn/plugins/vpn.c b/vpn/plugins/vpn.c
index 52f7cac7..ea64fdc2 100644
--- a/vpn/plugins/vpn.c
+++ b/vpn/plugins/vpn.c
@@ -800,6 +800,24 @@ 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)
+ return false;
+
+ /* The use of VPN agent must be explicitly dropped by the driver. */
+ return !(vpn_driver_data->vpn_driver->flags & VPN_FLAG_NO_AGENT);
+}
+
int vpn_register(const char *name, const struct vpn_driver *vpn_driver,
const char *program)
{
@@ -825,6 +843,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..21cb2481 100644
--- a/vpn/plugins/vpn.h
+++ b/vpn/plugins/vpn.h
@@ -30,6 +30,7 @@ extern "C" {
#define VPN_FLAG_NO_TUN 1
#define VPN_FLAG_NO_DAEMON 2
+#define VPN_FLAG_NO_AGENT 4
enum vpn_state {
VPN_STATE_UNKNOWN = 0,
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