Attention is currently required from: Arne Schwabe, Marco Baffo, Răzvan
Cojocaru.
Hello Arne Schwabe, Răzvan Cojocaru,
I'd like you to reexamine a change. Please visit
https://gerrit.openvpn.net/c/openvpn/+/2360?usp=email
to look at the new patch set (#3).
The following approvals got outdated and were removed:
Code-Review+2 by Răzvan Cojocaru
The change is no longer submittable: Code-Review and checks~ChecksSubmitRule
are unsatisfied now.
Change subject: options: preserve local DNS across PUSH_UPDATE
......................................................................
options: preserve local DNS across PUSH_UPDATE
A DNS update clears the client's local DNS configuration along with
the previous pushed values. It also clears --dns-updown, so the DNS
script is skipped when the tunnel reopens.
Parse the first dns directive in a PUSH_UPDATE into a copy of the
pre-connect DNS configuration and install the copy on success.
Accumulate subsequent dns directives in the same update sequence and
use the regular pull merge rules. For -dns, restore the local DNS
configuration.
Keep the active --dns-updown command and flags. Preserve from_dhcp
across dns updates so -dns can fall back to the current --dhcp-option
DNS values. Clear from_dhcp when DHCP options are replaced or removed.
GitHub: OpenVPN/openvpn#1159
Change-Id: Ib20f4965f25472f47b98981d54eaf4e2269d7408
Signed-off-by: Marco Baffo <[email protected]>
---
M doc/management-notes.txt
M src/openvpn/options.c
2 files changed, 58 insertions(+), 20 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/60/2360/3
diff --git a/doc/management-notes.txt b/doc/management-notes.txt
index a98b45f..a9f2b69 100644
--- a/doc/management-notes.txt
+++ b/doc/management-notes.txt
@@ -1210,9 +1210,13 @@
The updatable options are: "block-ipv6", "block-outside-dns", "dhcp-option",
"dns", "ifconfig", "ifconfig-ipv6", "redirect-gateway", "redirect-private",
"route", "route-gateway", "route-ipv6", "route-metric", "topology",
-"tun-mtu", "keepalive". When a valid option is pushed, the receiving client
will
-delete every previous value and set new value, so the update of the option will
-not be incremental even when theoretically possible (ex. with
"redirect-gateway").
+"tun-mtu", "keepalive". When a valid option is pushed, the receiving client
+replaces its previous values as a group. This also applies to options such as
+"redirect-gateway" that could otherwise be updated incrementally.
+For "dns", the client combines the new pushed values with its local "dns"
+configuration using the same rules as the initial pull. An update with "-dns"
+removes the pushed values and restores the local "dns" configuration.
+
The '-' symbol in front of an option means the option should be removed.
When an option is used with '-', it cannot take any parameter.
The '?' symbol in front of an option means the option's update is optional
diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index 1e0b4d8..ae6f4d7 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -2387,6 +2387,24 @@
o->pre_connect->comp = o->comp;
}
+static struct dns_options
+clone_pre_connect_dns_options(const struct options *options)
+{
+ const struct options_pre_connect *pp = options->pre_connect;
+ /* The server parses outgoing updates with a temporary options struct. */
+ if (!pp)
+ {
+ return (struct dns_options){ .gc = gc_new() };
+ }
+
+ /* Pull preprocessing moves local servers to servers_prepull before
saving. */
+ ASSERT(!options->pull || !pp->dns_options.servers);
+ struct gc_arena gc = gc_new();
+ struct dns_options dns = clone_dns_options(&pp->dns_options, &gc);
+ dns.gc = gc;
+ return dns;
+}
+
void
pre_connect_restore(struct options *o, struct gc_arena *gc)
{
@@ -2427,9 +2445,7 @@
/* Free DNS options and reset them to pre-pull state */
gc_free(&o->dns_options.gc);
- struct gc_arena dns_gc = gc_new();
- o->dns_options = clone_dns_options(&pp->dns_options, &dns_gc);
- o->dns_options.gc = dns_gc;
+ o->dns_options = clone_pre_connect_dns_options(o);
if (pp->client_nat_defined)
{
@@ -3616,11 +3632,26 @@
env_set_del(es, "route_redirect_gateway_ipv6");
}
+/**
+ * @brief Install DNS options rebuilt from the pre-connect snapshot.
+ *
+ * For a `dns` update, apply the first pushed directive to the snapshot copy
+ * before calling. For `-dns`, pass the copy as-is.
+ *
+ * @param options Options to update. Its current `--dns-updown` and
+ * `--dhcp-option` values carry over.
+ * @param dns Replacement DNS options. This function takes ownership of
`dns.gc`.
+ */
static void
-reset_dns_options(struct options *options)
+replace_dns_options(struct options *options, struct dns_options dns)
{
- gc_free(&options->dns_options.gc);
- CLEAR(options->dns_options);
+ struct dns_options *current = &options->dns_options;
+
+ dns.updown = current->updown;
+ dns.updown_flags = current->updown_flags;
+ dns.from_dhcp = current->from_dhcp;
+ gc_free(¤t->gc);
+ *current = dns;
}
static void
@@ -3646,7 +3677,6 @@
CLEAR(o->domain_search_list);
o->disable_nbt = 0;
o->dhcp_options = 0;
- CLEAR(options->dns_options.from_dhcp);
#if defined(TARGET_ANDROID)
o->http_proxy_port = 0;
@@ -3655,6 +3685,7 @@
#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
delete_all_dhcp_fo(options, &es->list);
#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
+ CLEAR(options->dns_options.from_dhcp);
}
void
@@ -3712,7 +3743,7 @@
else if (streq(p[0], "dns") && !p[1])
{
VERIFY_PERMISSION(OPT_P_DHCPDNS);
- reset_dns_options(options);
+ replace_dns_options(options, clone_pre_connect_dns_options(options));
}
else if (streq(p[0], "topology") && !p[1])
{
@@ -3806,12 +3837,11 @@
}
static bool
-check_dns_option(struct options *options, char *p[], const msglvl_t msglevel,
bool pull_mode)
+add_dns_option(struct dns_options *dns, char *p[], const msglvl_t msglevel,
bool pull_mode)
{
if (streq(p[1], "search-domains") && p[2])
{
- if (!dns_domain_list_append(&options->dns_options.search_domains,
&p[2],
- &options->dns_options.gc))
+ if (!dns_domain_list_append(&dns->search_domains, &p[2], &dns->gc))
{
msg(msglevel, "--dns %s contain invalid characters", p[1]);
return false;
@@ -3826,8 +3856,7 @@
return false;
}
- struct dns_server *server =
- dns_server_get(&options->dns_options.servers, priority,
&options->dns_options.gc);
+ struct dns_server *server = dns_server_get(&dns->servers, priority,
&dns->gc);
if (streq(p[3], "address"))
{
@@ -3843,7 +3872,7 @@
}
else if (streq(p[3], "resolve-domains"))
{
- if (!dns_domain_list_append(&server->domains, &p[4],
&options->dns_options.gc))
+ if (!dns_domain_list_append(&server->domains, &p[4], &dns->gc))
{
msg(msglevel, "--dns server %ld: %s contain invalid
characters", priority, p[3]);
return false;
@@ -3963,12 +3992,17 @@
if (!(options->push_update_options_found & OPT_P_U_DNS))
{
VERIFY_PERMISSION(OPT_P_DHCPDNS);
- if (!check_dns_option(options, p, msglevel, pull_mode))
+ /* Apply the first DNS option to the saved local configuration. */
+ struct dns_options dns = clone_pre_connect_dns_options(options);
+ if (!add_dns_option(&dns, p, msglevel, pull_mode))
{
+ gc_free(&dns.gc);
goto err;
}
- reset_dns_options(options);
+ replace_dns_options(options, dns);
options->push_update_options_found |= OPT_P_U_DNS;
+ /* Skip add_option() to avoid adding this twice. */
+ return;
}
}
else if (streq(p[0], "dhcp-option") && p[1] && !p[3])
@@ -6409,7 +6443,7 @@
else if (streq(p[0], "dns") && p[1])
{
VERIFY_PERMISSION(OPT_P_DHCPDNS);
- if (!check_dns_option(options, p, msglevel, pull_mode))
+ if (!add_dns_option(&options->dns_options, p, msglevel, pull_mode))
{
goto err;
}
--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2360?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib20f4965f25472f47b98981d54eaf4e2269d7408
Gerrit-Change-Number: 2360
Gerrit-PatchSet: 3
Gerrit-Owner: Marco Baffo <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-Reviewer: Răzvan Cojocaru <[email protected]>
Gerrit-CC: Heiko Hund <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Marco Baffo <[email protected]>
Gerrit-Attention: Răzvan Cojocaru <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel