Skip to content

Commit

Permalink
tun.c: don't attempt to delete DNS and WINS servers if they're not set
Browse files Browse the repository at this point in the history
Commits

    1c4a47f ("wintun: set adapter properties via interactive service")
    18826de ("Set WINS servers via interactice service")

added functionality of add/remove DNS/WINS via interactive
service, which is used mostly by dco-win and wintun (tap-windows6
normally uses DHCP). There is a check in code - if DNS/WINS addresses
are not pushed, nothing is added.

However, due to bug we always attempted to remove DNS/WINS,
even if nothing was added. Removing WINS, for example, could take
up to 3 seconds.

This change fixes this by improving check "has DNS/WINS been pushed?".

While on it, convert do_XXX_service() functions to "void" from "bool",
since we never check their return values.

Change-Id: I21a36d24f8e213c780f55acbe3e4df555c93542a
Signed-off-by: Lev Stipakov <[email protected]>
Acked-by: Frank Lichtenheld <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg27843.html
Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
lstipakov authored and cron2 committed Dec 21, 2023
1 parent 855030f commit c590868
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions src/openvpn/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,16 @@ do_address_service(const bool add, const short family, const struct tuntap *tt)
return ret;
}

static bool
static void
do_dns_domain_service(bool add, const struct tuntap *tt)
{
bool ret = false;
ack_message_t ack;
struct gc_arena gc = gc_new();
HANDLE pipe = tt->options.msg_channel;

if (!tt->options.domain) /* no domain to add or delete */
{
return true;
goto out;
}

/* Use dns_cfg_msg with addr_len = 0 for setting only the DOMAIN */
Expand Down Expand Up @@ -195,27 +194,25 @@ do_dns_domain_service(bool add, const struct tuntap *tt)
}

msg(M_INFO, "DNS domain %s using service", (add ? "set" : "deleted"));
ret = true;

out:
gc_free(&gc);
return ret;
}

static bool
static void
do_dns_service(bool add, const short family, const struct tuntap *tt)
{
bool ret = false;
ack_message_t ack;
struct gc_arena gc = gc_new();
HANDLE pipe = tt->options.msg_channel;
int len = family == AF_INET6 ? tt->options.dns6_len : tt->options.dns_len;
int addr_len = add ? len : 0;
const char *ip_proto_name = family == AF_INET6 ? "IPv6" : "IPv4";

if (addr_len == 0 && add) /* no addresses to add */
if (len == 0)
{
return true;
/* nothing to do */
goto out;
}

/* Use dns_cfg_msg with domain = "" for setting only the DNS servers */
Expand Down Expand Up @@ -272,26 +269,23 @@ do_dns_service(bool add, const short family, const struct tuntap *tt)
}

msg(M_INFO, "%s dns servers %s using service", ip_proto_name, (add ? "set" : "deleted"));
ret = true;

out:
gc_free(&gc);
return ret;
}

static bool
static void
do_wins_service(bool add, const struct tuntap *tt)
{
bool ret = false;
ack_message_t ack;
struct gc_arena gc = gc_new();
HANDLE pipe = tt->options.msg_channel;
int len = tt->options.wins_len;
int addr_len = add ? len : 0;
int addr_len = add ? tt->options.wins_len : 0;

if (addr_len == 0 && add) /* no addresses to add */
if (tt->options.wins_len == 0)
{
return true;
/* nothing to do */
goto out;
}

wins_cfg_message_t wins = {
Expand Down Expand Up @@ -338,11 +332,9 @@ do_wins_service(bool add, const struct tuntap *tt)
}

msg(M_INFO, "WINS servers %s using service", (add ? "set" : "deleted"));
ret = true;

out:
gc_free(&gc);
return ret;
}

static bool
Expand Down Expand Up @@ -7019,10 +7011,7 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
{
do_dns_domain_service(false, tt);
}
if (tt->options.dns6_len > 0)
{
do_dns_service(false, AF_INET6, tt);
}
do_dns_service(false, AF_INET6, tt);
delete_route_connected_v6_net(tt);
do_address_service(false, AF_INET6, tt);
}
Expand Down

0 comments on commit c590868

Please sign in to comment.