[PATCH v2 12/42] wireguard: Use positive errors for VPN provider connect_cb
Jussi Laakkonen <[email protected]> Wed, 13 Aug 2025 18:01:44 +0300
| Newsgroups | dev.linux.lists.connman |
|---|---|
| Message-ID | <[email protected]> |
The vpn-provider.c:connect_cb() expects the errors to be positive ints.
Remove the sign when calling the cb.
And add debug to see what is really causing the error. For example, when
parsing fails.
---
vpn/plugins/wireguard.c | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/vpn/plugins/wireguard.c b/vpn/plugins/wireguard.c
index 735bac58..de57b15f 100644
--- a/vpn/plugins/wireguard.c
+++ b/vpn/plugins/wireguard.c
@@ -349,8 +349,10 @@ static int wg_connect(struct vpn_provider *provider,
option = vpn_provider_get_string(provider, "WireGuard.DNS");
if (option) {
err = vpn_provider_set_nameservers(provider, option);
- if (err)
+ if (err) {
+ DBG("Cannot set nameservers %s", option);
goto done;
+ }
}
option = vpn_provider_get_string(provider, "WireGuard.PrivateKey");
@@ -359,8 +361,10 @@ static int wg_connect(struct vpn_provider *provider,
goto done;
}
err = parse_key(option, info->device.private_key);
- if (err)
+ if (err) {
+ DBG("Failed to parse private key");
goto done;
+ }
option = vpn_provider_get_string(provider, "WireGuard.PublicKey");
if (!option) {
@@ -368,15 +372,19 @@ static int wg_connect(struct vpn_provider *provider,
goto done;
}
err = parse_key(option, info->peer.public_key);
- if (err)
+ if (err) {
+ DBG("Failed to parse public key");
goto done;
+ }
option = vpn_provider_get_string(provider, "WireGuard.PresharedKey");
if (option) {
info->peer.flags |= WGPEER_HAS_PRESHARED_KEY;
err = parse_key(option, info->peer.preshared_key);
- if (err)
+ if (err) {
+ DBG("Failed to parse pre-shared key");
goto done;
+ }
}
option = vpn_provider_get_string(provider, "WireGuard.AllowedIPs");
@@ -385,8 +393,10 @@ static int wg_connect(struct vpn_provider *provider,
goto done;
}
err = parse_allowed_ips(option, &info->peer);
- if (err)
+ if (err) {
+ DBG("Failed to parse allowed IPs %s", option);
goto done;
+ }
option = vpn_provider_get_string(provider,
"WireGuard.PersistentKeepalive");
@@ -404,8 +414,10 @@ static int wg_connect(struct vpn_provider *provider,
gateway = vpn_provider_get_string(provider, "Host");
err = parse_endpoint(gateway, option,
(struct sockaddr_u *)&info->peer.endpoint.addr);
- if (err)
+ if (err) {
+ DBG("Failed to parse endpoint %s gateway %s", option, gateway);
goto done;
+ }
info->endpoint_fqdn = g_strdup(gateway);
info->port = g_strdup(option);
@@ -416,8 +428,10 @@ static int wg_connect(struct vpn_provider *provider,
goto done;
}
err = parse_address(option, gateway, &ipaddress);
- if (err)
+ if (err) {
+ DBG("Failed to parse address %s gateway %s", option, gateway);
goto done;
+ }
ifname = get_ifname();
if (!ifname) {
@@ -446,7 +460,7 @@ static int wg_connect(struct vpn_provider *provider,
done:
if (cb)
- cb(provider, user_data, err);
+ cb(provider, user_data, -err);
connman_ipaddress_free(ipaddress);
--
2.39.5