[PATCH 43/45] wireguard: Add option for using transport nameservers for DNS reresolve
Jussi Laakkonen <[email protected]> Fri, 11 Jul 2025 17:27:34 +0300
| Newsgroups | dev.linux.lists.connman |
|---|---|
| Message-ID | <[email protected]> |
If the "WireGuard.ReresolveUseTransportDNS" is defined add the
nameservers of the transport to be used for DNS reresolve queries. This
affects only the GResolv queries done after the intial connection to
reresolve the endpoint address.
---
vpn/plugins/wireguard.c | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/vpn/plugins/wireguard.c b/vpn/plugins/wireguard.c
index a2d92ec6..2787aa7e 100644
--- a/vpn/plugins/wireguard.c
+++ b/vpn/plugins/wireguard.c
@@ -53,6 +53,7 @@
#define DNS_RERESOLVE_TIMEOUT 20
#define DNS_RERESOLVE_ERROR_LIMIT 5
+#define DNS_DEFAULT_PORT 53
#define ROUTE_SETUP_TIMEOUT 200 // ms
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
@@ -90,7 +91,8 @@ struct {
{"WireGuard.PublicKey", true},
{"WireGuard.AllowedIPs", true},
{"WireGuard.EndpointPort", true},
- {"WireGuard.PersistentKeepalive", true}
+ {"WireGuard.PersistentKeepalive", true},
+ {"WireGuard.ReresolveUseTransportDNS", false}
};
static struct wireguard_info *create_private_data(struct vpn_provider *provider)
@@ -532,7 +534,7 @@ static void resolve_endpoint_cb(GResolvResultStatus status,
case G_RESOLV_RESULT_STATUS_NO_ANSWER:
case G_RESOLV_RESULT_STATUS_NO_RESPONSE:
case G_RESOLV_RESULT_STATUS_SERVER_FAILURE:
- DBG("retry DNS reresolve");
+ DBG("retry DNS reresolve, status %d", status);
if (info->provider)
vpn_provider_add_error(info->provider,
VPN_PROVIDER_ERROR_CONNECT_FAILED);
@@ -544,7 +546,7 @@ static void resolve_endpoint_cb(GResolvResultStatus status,
case G_RESOLV_RESULT_STATUS_FORMAT_ERROR:
case G_RESOLV_RESULT_STATUS_NOT_IMPLEMENTED:
case G_RESOLV_RESULT_STATUS_REFUSED:
- DBG("stop DNS reresolve, error %d", status);
+ DBG("stop DNS reresolve, status %d", status);
if (err && info->provider)
vpn_provider_add_error(info->provider,
VPN_PROVIDER_ERROR_CONNECT_FAILED);
@@ -598,7 +600,10 @@ static int disconnect(struct vpn_provider *provider, int error);
static gboolean wg_dns_reresolve_cb(gpointer user_data)
{
struct wireguard_info *info = user_data;
+ char **nameservers;
+ bool option;
int err;
+ int i;
DBG("");
@@ -617,6 +622,18 @@ static gboolean wg_dns_reresolve_cb(gpointer user_data)
DBG("endpoint_fqdn %s", info->endpoint_fqdn);
+ option = vpn_provider_get_boolean(info->provider,
+ "WireGuard.ReresolveUseTransportDNS",
+ false);
+ if (option) {
+ nameservers = vpn_provider_get_string_list(info->provider,
+ "TransportNameservers");
+ for (i = 0; nameservers && nameservers[i]; i++)
+ vpn_util_resolv_add_nameserver(info->resolv,
+ nameservers[i],
+ DNS_DEFAULT_PORT, 0);
+ }
+
info->resolv_id = vpn_util_resolve_hostname(info->resolv,
info->endpoint_fqdn,
resolve_endpoint_cb, info);
--
2.39.5