From: "mrbff (Code Review)" Date: Wed, 23 Jul 2025 17:10:11 +0000 In-Reply-To: References: Reply-To: marco@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., lstipakov@...277..., gert@...1296... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="hG4WzCOuDSQ="; charset=UTF-8 Subject: [Openvpn-devel] [L] Change in openvpn[master]: PUSH_UPDATE: Added remove_option() and do_update(). List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld , stipa Cc: openvpn-devel --hG4WzCOuDSQ= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, flichtenheld, mrbff, plaisthos= , stipa. Hello cron2, flichtenheld, plaisthos, stipa, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/809?usp=3Demail to look at the new patch set (#22). The following approvals got outdated and were removed: Code-Review+2 by stipa, Code-Review-1 by cron2 The change is no longer submittable: Code-Review and checks~ChecksSubmitRul= e are unsatisfied now. Change subject: PUSH_UPDATE: Added remove_option() and do_update(). ...................................................................... PUSH_UPDATE: Added remove_option() and do_update(). * Added remove_option() function and some utility functions to remove optio= ns at runtime following the push-update logic. * Added do_update() function to close and reopen the tun and apply option u= pdates. Change-Id: I507180d7397b6959844a30908010132bc3411067 Signed-off-by: Marco Baffo --- M src/openvpn/init.c M src/openvpn/init.h M src/openvpn/multi.c M src/openvpn/options.c M src/openvpn/push.c M src/openvpn/route.c M src/openvpn/route.h 7 files changed, 350 insertions(+), 11 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/09/809/22 diff --git a/src/openvpn/init.c b/src/openvpn/init.c index ba1dda4..3254cc6 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -2470,7 +2470,7 @@ if (pulled_options) { - if (!do_deferred_options(c, option_types_found)) + if (!do_deferred_options(c, option_types_found, false)) { msg(D_PUSH_ERRORS, "ERROR: Failed to apply push options"); return false; @@ -2594,6 +2594,55 @@ return true; } +bool +do_update(struct context *c, unsigned int option_types_found) +{ + /* Not necessary since to receive the update the openvpn + * instance must be up and running but just in case + */ + if (!c->c2.do_up_ran) + { + return false; + } + + bool tt_dco_win =3D tuntap_is_dco_win(c->c1.tuntap); + if (tt_dco_win) + { + msg(M_NONFATAL, "dco-win doesn't yet support reopening TUN device"= ); + return false; + } + + if (!do_deferred_options(c, option_types_found, true)) + { + msg(D_PUSH_ERRORS, "ERROR: Failed to apply push options"); + return false; + } + + do_close_tun(c, true); + + management_sleep(1); + int error_flags =3D 0; + c->c2.did_open_tun =3D do_open_tun(c, &error_flags); + update_time(); + + if (c->c2.did_open_tun) + { + /* if --route-delay was specified, start timer */ + if ((route_order(c->c1.tuntap) =3D=3D ROUTE_AFTER_TUN) && c->optio= ns.route_delay_defined) + { + event_timeout_init(&c->c2.route_wakeup, c->options.route_delay= , now); + event_timeout_init(&c->c2.route_wakeup_expire, c->options.rout= e_delay + c->options.route_delay_window, now); + tun_standby_init(c->c1.tuntap); + } + + initialization_sequence_completed(c, error_flags); + } + + CLEAR(c->c1.pulled_options_digest_save); + + return true; +} + /* * These are the option categories which will be accepted by pull. */ @@ -2672,11 +2721,8 @@ return true; } -/* - * Handle non-tun-related pulled options. - */ bool -do_deferred_options(struct context *c, const unsigned int found) +do_deferred_options(struct context *c, const unsigned int found, const boo= l is_update) { if (found & OPT_P_MESSAGES) { @@ -2784,7 +2830,10 @@ /* process (potentially) pushed options */ if (c->options.pull) { - if (!check_pull_client_ncp(c, found)) + /* On PUSH_UPDATE, NCP related flags are never updated, and so the= code + * would assume "no cipher pushed =3D NCP failed" - so, don't call= it on + * updates */ + if (!is_update && !check_pull_client_ncp(c, found)) { return false; } diff --git a/src/openvpn/init.h b/src/openvpn/init.h index 5c6b9c1..25078a6 100644 --- a/src/openvpn/init.h +++ b/src/openvpn/init.h @@ -86,13 +86,29 @@ bool pulled_options, unsigned int option_types_found); +/** + * @brief A simplified version of the do_up() function. This function is c= alled + * after receiving a successful PUSH_UPDATE message. It closes and = reopens + * the TUN device to apply the updated options. + * + * @param c The context structure. + * @param option_types_found The options found in the PUSH_UPDATE message. + * @return true on success. + * @return false on error. + */ +bool do_update(struct context *c, unsigned int option_types_found); + unsigned int pull_permission_mask(const struct context *c); const char *format_common_name(struct context *c, struct gc_arena *gc); void reset_coarse_timers(struct context *c); -bool do_deferred_options(struct context *c, const unsigned int found); +/* + * Handle non-tun-related pulled options. + * Set `is_update` param to true to skip NCP check. + */ +bool do_deferred_options(struct context *c, const unsigned int found, cons= t bool is_update); void inherit_context_child(struct context *dest, const struct context *src, diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index ec260a2..26f95ec 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -2424,7 +2424,7 @@ /* * Process sourced options. */ - do_deferred_options(&mi->context, option_types_found); + do_deferred_options(&mi->context, option_types_found, false); /* * make sure we got ifconfig settings from somewhere diff --git a/src/openvpn/options.c b/src/openvpn/options.c index b214d91..683dae6 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -1086,6 +1086,40 @@ gc_free(&gc); } } + +static void +delete_all_dhcp_fo(struct options *o, struct env_item **list) +{ + struct env_item *current, *prev; + + ASSERT(list); + + for (current =3D *list, prev =3D NULL; current !=3D NULL; current =3D = current->next) + { + char *tmp_value =3D NULL; + if (!strncmp(current->string, "foreign_option_", sizeof("foreign_o= ption_")-1)) + { + tmp_value =3D strchr(current->string, '=3D'); + if (tmp_value && ++tmp_value) + { + if (!strncmp(tmp_value, "dhcp-option ", sizeof("dhcp-optio= n ")-1)) + { + if (prev) + { + prev->next =3D current->next; + } + else + { + *list =3D current->next; + } + o->foreign_option_index--; + } + } + } + prev =3D current; + } +} + #endif /* ifndef _WIN32 */ static in_addr_t @@ -3091,7 +3125,7 @@ opt->routes->flags |=3D RG_DEF1; } } -#endif +#endif /* ifdef _WIN32 */ /* * Save/Restore certain option defaults before --pull is applied. @@ -5326,6 +5360,18 @@ struct env_set *es); static void +remove_option(struct context *c, + struct options *options, + char *p[], + bool is_inline, + const char *file, + int line, + const int msglevel, + const unsigned int permission_mask, + unsigned int *option_types_found, + struct env_set *es); + +static void read_config_file(struct options *options, const char *file, int level, @@ -5547,6 +5593,11 @@ add_option(options, p, false, file, line_num, 0, msglevel, permission_mask, option_types_found, es); } + else if (push_update_option_flags & PUSH_OPT_TO_REMOVE) + { + remove_option(c, options, p, false, file, line_num, msglev= el, + permission_mask, option_types_found, es); + } } } return true; @@ -5685,6 +5736,199 @@ return options->forward_compatible ? M_WARN : msglevel; } +/** + * @brief Resets options found in the PUSH_UPDATE message that are precede= d by the `-` flag. + * This function is used in push-updates to reset specified options. + * The number of parameters `p` must always be 1. If the permission= is verified, + * all related options are erased or reset to their default values. + * Upon successful permission verification (by VERIFY_PERMISSION()), + * `option_types_found` is filled with the flag corresponding to th= e option. + * + * @param c The context structure. + * @param options A pointer to the options structure. + * @param p An array of strings containing the options and their parameter= s. + * @param is_inline A boolean indicating if the option is inline. + * @param file The file where the function is called. + * @param line The line number where the function is called. + * @param msglevel The message level. + * @param permission_mask The permission mask used by VERIFY_PERMISSION(). + * @param option_types_found A pointer to the variable where the flags cor= responding to the options found are stored. + * @param es The environment set structure. + */ +static void +remove_option(struct context *c, + struct options *options, + char *p[], + bool is_inline, + const char *file, + int line, + const int msglevel, + const unsigned int permission_mask, + unsigned int *option_types_found, + struct env_set *es) +{ + int msglevel_fc =3D msglevel_forward_compatible(options, msglevel); + + if (streq(p[0], "ifconfig") && !p[1]) + { + VERIFY_PERMISSION(OPT_P_UP); + options->ifconfig_local =3D NULL; + options->ifconfig_remote_netmask =3D NULL; + } + else if (streq(p[0], "ifconfig-ipv6") && !p[1]) + { + VERIFY_PERMISSION(OPT_P_UP); + options->ifconfig_ipv6_local =3D NULL; + options->ifconfig_ipv6_netbits =3D 0; + options->ifconfig_ipv6_remote =3D NULL; + } + else if (streq(p[0], "route") && !p[1]) + { + VERIFY_PERMISSION(OPT_P_ROUTE); + if (c->c1.route_list) + { + delete_routes_v4(c->c1.route_list, c->c1.tuntap, + ROUTE_OPTION_FLAGS(&c->options), + es, &c->net_ctx); + if (options->routes) + { + options->routes->routes =3D NULL; + options->routes->flags =3D 0; + } + } + } + else if (streq(p[0], "route-ipv6") && !p[1]) + { + VERIFY_PERMISSION(OPT_P_ROUTE); + if (c->c1.route_ipv6_list) + { + delete_routes_v6(c->c1.route_ipv6_list, c->c1.tuntap, + ROUTE_OPTION_FLAGS(&c->options), + es, &c->net_ctx); + if (options->routes_ipv6) + { + options->routes_ipv6->routes_ipv6 =3D NULL; + options->routes_ipv6->flags =3D 0; + } + } + } + else if (streq(p[0], "route-gateway") && !p[1]) + { + VERIFY_PERMISSION(OPT_P_ROUTE_EXTRAS); + options->route_gateway_via_dhcp =3D false; + options->route_default_gateway =3D NULL; + } + else if (streq(p[0], "route-metric") && !p[1]) + { + VERIFY_PERMISSION(OPT_P_ROUTE); + options->route_default_metric =3D 0; + } + else if (streq(p[0], "push-continuation") && !p[1]) + { + VERIFY_PERMISSION(OPT_P_PULL_MODE); + options->push_continuation =3D 0; + } + else if ((streq(p[0], "redirect-gateway") || streq(p[0], "redirect-pri= vate")) && !p[1]) + { + VERIFY_PERMISSION(OPT_P_ROUTE); + if (options->routes) + { + options->routes->flags =3D 0; + } + if (options->routes_ipv6) + { + options->routes_ipv6->flags =3D 0; + } + } + else if (streq(p[0], "dns") && !p[1]) + { + VERIFY_PERMISSION(OPT_P_DHCPDNS); + gc_free(&options->dns_options.gc); + CLEAR(options->dns_options); + } + else if (streq(p[0], "topology") && !p[1]) + { + VERIFY_PERMISSION(OPT_P_UP); + options->topology =3D TOP_UNDEF; + helper_setdefault_topology(options); + } + else if (streq(p[0], "tun-mtu") && !p[1]) + { + VERIFY_PERMISSION(OPT_P_PUSH_MTU|OPT_P_CONNECTION); + options->ce.tun_mtu =3D TUN_MTU_DEFAULT; + options->ce.tun_mtu_defined =3D false; + options->ce.occ_mtu =3D 0; + } + else if (streq(p[0], "block-ipv6") && !p[1]) + { + VERIFY_PERMISSION(OPT_P_ROUTE); + options->block_ipv6 =3D false; + } +#if defined(_WIN32) || defined(TARGET_ANDROID) + else if (streq(p[0], "dhcp-option") && !p[1]) + { + struct tuntap_options *o =3D &options->tuntap_options; + VERIFY_PERMISSION(OPT_P_DHCPDNS); + + o->domain =3D NULL; + o->netbios_scope =3D NULL; + o->netbios_node_type =3D 0; + o->dns6_len =3D 0; + memset(o->dns6, 0, sizeof(o->dns6)); + o->dns_len =3D 0; + memset(o->dns, 0, sizeof(o->dns)); + o->wins_len =3D 0; + memset(o->wins, 0, sizeof(o->wins)); + o->ntp_len =3D 0; + memset(o->ntp, 0, sizeof(o->ntp)); + o->nbdd_len =3D 0; + memset(o->nbdd, 0, sizeof(o->nbdd)); + while (o->domain_search_list_len-- > 0) + { + o->domain_search_list[o->domain_search_list_len] =3D NULL; + } + o->disable_nbt =3D 0; + o->dhcp_options =3D 0; +#if defined(TARGET_ANDROID) + o->http_proxy_port =3D 0; + o->http_proxy =3D NULL; +#endif + } +#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */ +#ifdef _WIN32 + else if (streq(p[0], "block-outside-dns") && !p[1]) + { + VERIFY_PERMISSION(OPT_P_DHCPDNS); + options->block_outside_dns =3D false; + } +#else /* ifdef _WIN32 */ + else if (streq(p[0], "dhcp-option") && !p[1]) + { + VERIFY_PERMISSION(OPT_P_DHCPDNS); + delete_all_dhcp_fo(options, &es->list); + } +#endif + else + { + int i; + int msglevel_unknown =3D msglevel_fc; + /* Check if an option is in --ignore-unknown-option and + * set warning level to non fatal */ + for (i =3D 0; options->ignore_unknown_option && options->ignore_un= known_option[i]; i++) + { + if (streq(p[0], options->ignore_unknown_option[i])) + { + msglevel_unknown =3D M_WARN; + break; + } + } + msg(msglevel_unknown, "Unrecognized option or missing or extra par= ameter(s) in %s:%d: -%s (%s)", file, line, p[0], PACKAGE_VERSION); + } + return; +err: + msg(msglevel, "Error occurred trying to remove %s option", p[0]); +} + static void set_user_script(struct options *options, const char **script, diff --git a/src/openvpn/push.c b/src/openvpn/push.c index 858b821..22082a9 100644 --- a/src/openvpn/push.c +++ b/src/openvpn/push.c @@ -542,6 +542,11 @@ { msg(M_WARN, "No updatable options found in incoming PU= SH_UPDATE message"); } + else if (!do_update(c, option_types_found)) + { + msg(D_PUSH_ERRORS, "Failed to update options"); + goto error; + } } } event_timeout_clear(&c->c2.push_request_interval); diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 156262a..89ebaee 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -1265,7 +1265,16 @@ const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx) { - if (rl && rl->iflags & RL_ROUTES_ADDED) + delete_routes_v4(rl, tt, flags, es, ctx); + delete_routes_v6(rl6, tt, flags, es, ctx); +} + +void +delete_routes_v4(struct route_list *rl, const struct tuntap *tt, + unsigned int flags, const struct env_set *es, + openvpn_net_ctx_t *ctx) +{ + if (rl && (rl->iflags & RL_ROUTES_ADDED)) { struct route_ipv4 *r; for (r =3D rl->routes; r; r =3D r->next) @@ -1281,8 +1290,14 @@ { clear_route_list(rl); } +} - if (rl6 && (rl6->iflags & RL_ROUTES_ADDED) ) +void +delete_routes_v6(struct route_ipv6_list *rl6, const struct tuntap *tt, + unsigned int flags, const struct env_set *es, + openvpn_net_ctx_t *ctx) +{ + if (rl6 && (rl6->iflags & RL_ROUTES_ADDED)) { struct route_ipv6 *r6; for (r6 =3D rl6->routes_ipv6; r6; r6 =3D r6->next) diff --git a/src/openvpn/route.h b/src/openvpn/route.h index 237375c..b89ec9f 100644 --- a/src/openvpn/route.h +++ b/src/openvpn/route.h @@ -335,6 +335,16 @@ const struct env_set *es, openvpn_net_ctx_t *ctx); +void +delete_routes_v4(struct route_list *rl, const struct tuntap *tt, + unsigned int flags, const struct env_set *es, + openvpn_net_ctx_t *ctx); + +void +delete_routes_v6(struct route_ipv6_list *rl6, const struct tuntap *tt, + unsigned int flags, const struct env_set *es, + openvpn_net_ctx_t *ctx); + void setenv_routes(struct env_set *es, const struct route_list *rl); void setenv_routes_ipv6(struct env_set *es, const struct route_ipv6_list *= rl6); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/809?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I507180d7397b6959844a30908010132bc3411067 Gerrit-Change-Number: 809 Gerrit-PatchSet: 22 Gerrit-Owner: mrbff Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-Reviewer: stipa Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: cron2 Gerrit-Attention: flichtenheld Gerrit-Attention: stipa Gerrit-Attention: mrbff Gerrit-MessageType: newpatchset --hG4WzCOuDSQ= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: cron2, flichtenheld, mrbff, plais= thos, stipa.

mrbff uploaded patch set #22 to this change.

View Change

The following approvals got outdated and were removed: Code-Review+2 by stipa, Code-Review-1 by cron2

The change is no longe= r submittable: Code-Review and checks~ChecksSubmitRule are unsatisfied now.=

PUSH_UPDATE: Added remove_option() and do_update().

* Added remove_= option() function and some utility functions to remove options at
runt= ime following the push-update logic.
* Added do_update() function to clo= se and reopen the tun and apply option updates.

Change-Id: I507180d7= 397b6959844a30908010132bc3411067
Signed-off-by: Marco Baffo <marco@...1186...= .2726...>
---
M src/openvpn/init.c
M src/openvpn/init.h
M sr= c/openvpn/multi.c
M src/openvpn/options.c
M src/openvpn/push.c
M s= rc/openvpn/route.c
M src/openvpn/route.h
7 files changed, 350 inserti= ons(+), 11 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/o=
penvpn refs/changes/09/809/22
diff --git a/src/openvpn/init.c b/src=
/openvpn/init.c
index ba1dda4..3254cc6 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c=
@@ -2470,7 +2470,7 @@

= if (pulled_options)
{
- if (!do_deferred_options(c, option_typ= es_found))
+ = if (!do_deferred_options(c, option_types_found, false))
= {
msg(D_PUSH_ERRORS, "ER= ROR: Failed to apply push options");
= return false;
@@ -2594,6 +2594,55 @@
r= eturn true;
}

+bool
+do_update(struct context *c, unsigned int option_types_found)=
+{
+ /* Not necessary since to receive= the update the openvpn
+ * instance must be up and running but just in case
+ */
+ if (!c->c2.do_up_ran)
+ {
+ return false;
+ }
+
+ bool= tt_dco_win =3D tuntap_is_dco_win(c->c1.tuntap);
+ if (tt_dco_win)
+ {
+ msg(M_NONFATAL, "dco-win doesn't yet s= upport reopening TUN device");
+ return false;
+ }
+
+ if (!do_def= erred_options(c, option_types_found, true))
+ {
+ msg(D_PUSH_ERRORS, "ERROR: Failed to apply push opti= ons");
+ = return false;
+ }<= /span>
+
+ do_close_tun(c, true);
+

+ management_sleep(1);
+ int error_flags =3D 0;
+ c->c2.did_open_tun =3D do_open_t= un(c, &error_flags);
+ update_time();
+
+ if (c->c= 2.did_open_tun)
+ = {
+ /* if --ro= ute-delay was specified, start timer */
+ if ((route_order(c->c1.tuntap) =3D=3D ROUTE_= AFTER_TUN) && c->options.route_delay_defined)
+ {
+ event_timeout_init(&c->c2.rou= te_wakeup, c->options.route_delay, now);
+ event_timeout_init(&c->c2.route_= wakeup_expire, c->options.route_delay + c->options.route_delay_window= , now);
+ = tun_standby_init(c->c1.tuntap);
+ }
+
+ initia= lization_sequence_completed(c, error_flags);
+ }
+
+ CLEA= R(c->c1.pulled_options_digest_save);
+
= + return true;
+}<= /span>
+
/*=
* These are the option categories which will be accepted= by pull.
*/
@@ -2672,11 +2721,8 @@

return true;
}
-/*
- * Handle non-tun-related pulled options.- */
bool
-do_deferred_options(struct= context *c, const unsigned int found)
+do_deferred_options(struct context *c, const unsigned in= t found, const bool is_update)
{
if (= found & OPT_P_MESSAGES)
{
@@ -2784= ,7 +2830,10 @@
/* process (potentially) pushed options= */
if (c->options.pull)
{

- if (!check_pull_c= lient_ncp(c, found))
= + /* On PUSH_UPDATE, NCP related flags are never updated, and so the= code
+ * wou= ld assume "no cipher pushed =3D NCP failed" - so, don't call = it on
+ * upd= ates */
+ if (= !is_update && !check_pull_client_ncp(c, found))
= {
return false;
= }
diff --git a/src/openvpn/init.h b/src/openvpn/init.h
index 5c6b9c1..25078a6 100644
--- a/src/openvp= n/init.h
+++ b/src/openvpn/init.h
@@ -86,13= +86,29 @@
bool pulled_options,
unsigned int option_types_found);


= +/**
+ * @brief A simplified version of the do_up() = function. This function is called
+ * after receiving a successful PUSH_UPDATE message. I= t closes and reopens
= + * the TUN device to apply the updated options.
+ *
+ * @param c The context structure.
+ * @param option_types_found The options = found in the PUSH_UPDATE message.
+ * @return true on success.
+ * @return false on error.
+ */
+bool do_update(struct context *c, unsigned int option_types_fo= und);
+
unsigned int pull_permission_mask(const struct context *c);
<= span>
const char *format_common_name(struct context *c, s= truct gc_arena *gc);

void reset_coarse_t= imers(struct context *c);

-bool do_deferred_options(struct context *c, const uns= igned int found);
+/*=
+ * Handle non-tun-r= elated pulled options.
+ */
+bool do_deferred_options(struct context *c, const unsign= ed int found, const bool is_update);

voi= d inherit_context_child(struct context *dest,
= const struct context *src,
diff --git a/src/= openvpn/multi.c b/src/openvpn/multi.c
index ec260a2..26f95e= c 100644
--- a/src/openvpn/multi.c
+++ b/sr= c/openvpn/multi.c
@@ -2424,7 +2424,7 @@
= /*
* Process sourced options.
= */
- do_deferred_op= tions(&mi->context, option_types_found);
+ do_deferred_options(&mi->context, op= tion_types_found, false);

/*<= br> * make sure we got ifconfig settings from somewherediff --git a/src/openvpn/options.c b/src/openvpn/options.cindex b214d91..683dae6 100644
--- a/src/openvpn/opt= ions.c
+++ b/src/openvpn/options.c
@@ -1086= ,6 +1086,40 @@
gc_free(&gc);
= }
}
+
+static void
+delete_all_dhcp_fo(str= uct options *o, struct env_item **list)
+{
+ struct env_item *current, *prev;
+
+= ASSERT(list);
+
+ for (current =3D = *list, prev =3D NULL; current !=3D NULL; current =3D current->next)
+ {
+ char *tmp_value =3D NULL;
+ if (!strncmp(cur= rent->string, "foreign_option_", sizeof("foreign_option_&= quot;)-1))
+ {=
+ tmp_val= ue =3D strchr(current->string, '=3D');
+ if (tmp_value && ++tmp_va= lue)
+ {
+ if (!= strncmp(tmp_value, "dhcp-option ", sizeof("dhcp-option "= ;)-1))
+ = {
+ = if (prev)
+ = {
+ = prev->next =3D current->next;
+ }
+ else
<= span style=3D"color: hsl(120, 100%, 40%);">+ {
+ *list= =3D current->next;
+ o->foreign_option_index--;
+ }
+ }
+ }
+ prev =3D current;
+ }
+}
+<= br> #endif /* ifndef _WIN32 */

sta= tic in_addr_t
@@ -3091,7 +3125,7 @@
= opt->routes->flags |=3D RG_DEF1;
}
<= span> }

-#endif<= br>+#endif /* ifdef _WIN32 */

/*
* Save/Restore certa= in option defaults before --pull is applied.
@@ -5326,6 +53= 60,18 @@
struct env_set *es);
=
static void
+remove_option(struct context *c,
+ struct options *options,
+ char *p[],
+ bool is_inline= ,
+ cons= t char *file,
+ = int line,
+ = const int msglevel,
+ const unsigned int permission_mask,
+ unsigned int *optio= n_types_found,

+ = struct env_set *es);
+
+static vo= id
read_config_file(struct options *options,
const char *file,

in= t level,
@@ -5547,6 +5593,11 @@
= add_option(options, p, false, file, line_num, 0, msglevel,
= permission_mask, option_types_found, es);=
}
+ else if (push_update_option_flags & PUSH_OPT_TO= _REMOVE)
+ = {
+ r= emove_option(c, options, p, false, file, line_num, msglevel,
+ perm= ission_mask, option_types_found, es);

+ }
}
= }
return true;
@@ -5685,6 +5736,1= 99 @@
return options->forward_compatible ? M_WARN := msglevel;
}

+/**
+ * @brief Resets options found in the PUSH_UPDATE message that = are preceded by the `-` flag.
+ * This function is used in push-updates to reset specifie= d options.
+ * = The number of parameters `p` must always be 1. If the permission is verifi= ed,
+ * all re= lated options are erased or reset to their default values.
+ * Upon successful permission= verification (by VERIFY_PERMISSION()),
+ * `option_types_found` is filled with the flag = corresponding to the option.
+ *
+ * @para= m c The context structure.
+ * @param options A pointer to the options structure.
+ * @param p An array of strings co= ntaining the options and their parameters.
+ * @param is_inline A boolean indicating if the opti= on is inline.
+ * @pa= ram file The file where the function is called.
+ * @param line The line number where the functi= on is called.
+ * @pa= ram msglevel The message level.
+ * @param permission_mask The permission mask used by VERIFY_PE= RMISSION().
+ * @para= m option_types_found A pointer to the variable where the flags correspondin= g to the options found are stored.
+ * @param es The environment set structure.
+ */
+static void
+remove_option(struct context *c,
+ struct options *options,+ char *p[],

+ bool is_i= nline,
+ = const char *file,
+ = int line,
+ const unsigned int permission_mask,+ unsigned int *= option_types_found,
+= struct env_set *es)
+{
+ = int msglevel_fc =3D msglevel_forward_compatible(options, msglevel);<= br>+
+ if (streq(p[0], "ifconfig") &= ;& !p[1])
+ {<= /span>
+ VERIFY_PERMI= SSION(OPT_P_UP);
+ = options->ifconfig_local =3D NULL;
+ options->ifconfig_remote_netmask =3D NULL;=
+ }
+ else if (streq(p[0], "if= config-ipv6") && !p[1])

+ {
+ options->ifconfig_ipv6_local =3D NULL;
+ options->ifcon= fig_ipv6_netbits =3D 0;
+ options->ifconfig_ipv6_remote =3D NULL;
+ }
+ else if (streq(p[0], "route") &&= !p[1])
+ {=
+ VERIFY_PERMISSION(= OPT_P_ROUTE);
+ = if (c->c1.route_list)
+ {
+ = delete_routes_v4(c->c1.route_list, c->c1.tuntap,
<= span style=3D"color: hsl(120, 100%, 40%);">+ RO= UTE_OPTION_FLAGS(&c->options),

+ es, &c->net_ctx);
+ if (options= ->routes)
+ = {
+ = options->routes->routes =3D NULL;
+ options->routes->flags =3D 0;<= /span>
+ }=
+ }
+ }
+ else if (streq(p[0], "route-ipv6") &= amp;& !p[1])
+ = {
+ VERIFY_PE= RMISSION(OPT_P_ROUTE);
+ {
+ delete_routes_v6(c->c1.route_ipv6_list, c->c1.= tuntap,
+ = ROUTE_OPTION_FLAGS(&c->options),
+ es, &= c->net_ctx);
+ = if (options->routes_ipv6)
+ {
+ options->routes_ipv6->routes_ipv6 =3D NULL= ;
+ op= tions->routes_ipv6->flags =3D 0;
+ }
+ }
+ else if= (streq(p[0], "route-gateway") && !p[1])
+ {
+ VERIFY_PERMISSION(OPT_P_ROUTE_EXTRAS);
+ options->rou= te_gateway_via_dhcp =3D false;
+ options->route_default_gateway =3D NULL;
+ }

+ else if (streq(p[0], "route-metric&qu= ot;) && !p[1])
+ VER= IFY_PERMISSION(OPT_P_ROUTE);
+ options->route_default_metric =3D 0;
+ }
+ else if (streq(p[0], "push-continuation&quo= t;) && !p[1])
+ {
+ VERI= FY_PERMISSION(OPT_P_PULL_MODE);
+ options->push_continuation =3D 0;
+ }
+ else if ((streq(p[0], "redirect-gateway&quo= t;) || streq(p[0], "redirect-private")) && !p[1])<= br>+ {
+ VERIFY_PERMISSION(OPT_P_ROUTE);
+ if (options-&= gt;routes)
+ {=
+ options= ->routes->flags =3D 0;
+ }
+ = if (options->routes_ipv6)
+ {
+ options->routes_ipv6->flags =3D 0;
+ }
+ }
+ else if (streq(p[0], "dns") && !p[1])<= /span>
+ {
+ VERIFY_PERMISSION(OPT_P_DH= CPDNS);

+ gc_f= ree(&options->dns_options.gc);
+ CLEAR(options->dns_options);
+ }
+ else if (streq(p[0], "topology") &= ;& !p[1])
+ {<= /span>
+ VERIFY_PERMI= SSION(OPT_P_UP);
+ = options->topology =3D TOP_UNDEF;
+ helper_setdefault_topology(options);+ }
+ else if (streq(p[0], "tun-mtu&qu= ot;) && !p[1])
+ VER= IFY_PERMISSION(OPT_P_PUSH_MTU|OPT_P_CONNECTION);
+ options->ce.tun_mtu =3D TUN_MTU_DEF= AULT;
+ option= s->ce.tun_mtu_defined =3D false;
+ options->ce.occ_mtu =3D 0;
+ }
+ else if (streq(p[0], "block-ipv6") &&= amp; !p[1])
+ {
+ VERIFY_PERMISS= ION(OPT_P_ROUTE);
+ = options->block_ipv6 =3D false;
+ }
+#if defined(_WIN32) || defined(TARGET_ANDROID)
+ else if (streq(p[0], "dhcp-optio= n") && !p[1])
+ {
+ = struct tuntap_options *o =3D &options->tuntap_options;
+ VERIFY_PERMISSION(OPT_P_= DHCPDNS);

++ o->domain =3D NULL= ;
+ o->netb= ios_scope =3D NULL;
+= o->netbios_node_type =3D 0;
+ o->dns6_len =3D 0;
+ memset(o->dns6, 0, sizeof(o->dns= 6));
+ o->d= ns_len =3D 0;
+ = memset(o->dns, 0, sizeof(o->dns));
+ o->wins_len =3D 0;
+ memset(o->wins, 0, sizeof(o-&g= t;wins));
+ o-= >ntp_len =3D 0;
+ = memset(o->ntp, 0, sizeof(o->ntp));
+ o->nbdd_len =3D 0;
+ memset(o->nbdd, 0, sizeof(= o->nbdd));
+ = while (o->domain_search_list_len-- > 0)
+ {
+ o->domain_search_list[o->domain_search_= list_len] =3D NULL;
+= }
+ o-= >disable_nbt =3D 0;
+#if defined(TARGET_ANDROID)
+ o->http_proxy_port =3D 0;
+ o->http_proxy =3D NULL= ;

+#endif
<= span style=3D"color: hsl(120, 100%, 40%);">+ }

+#endif /* if defined(_WIN32) || defined(TARGE= T_ANDROID) */
+#ifdef= _WIN32
+ else if = (streq(p[0], "block-outside-dns") && !p[1])
+ {

+ VERIFY_PERMISSION(OPT_P_DHCPDNS);
+ options->block= _outside_dns =3D false;
+ }
+#else /* i= fdef _WIN32 */
+ e= lse if (streq(p[0], "dhcp-option") && !p[1])
+ {

+ VERIFY_PERMISSION(OPT_P_DHCPDNS);
+ delete_all_dhcp_= fo(options, &es->list);
+ }
+#en= dif
+ else<= br>+ {
+ int i;
+ int msglevel_unknown =3D msglevel_fc;<= /span>
+ /* Check if = an option is in --ignore-unknown-option and
+ * set warning level to non fatal */=
+ for (i =3D 0; opti= ons->ignore_unknown_option && options->ignore_unknown_option[= i]; i++)
+ {
+ if (streq= (p[0], options->ignore_unknown_option[i]))
+ {
+ msglevel_unknown =3D M_WARN;
= + break;<= br>+ }
+ }

+ msg(msglevel_unknown, "Unrec= ognized option or missing or extra parameter(s) in %s:%d: -%s (%s)", f= ile, line, p[0], PACKAGE_VERSION);
+ }
= + return;
+err:
+ msg(msglevel, &quo= t;Error occurred trying to remove %s option", p[0]);
+}
+
static void
set_user= _script(struct options *options,
const cha= r **script,
diff --git a/src/openvpn/push.c b/src/openvpn/p= ush.c
index 858b821..22082a9 100644
--- a/s= rc/openvpn/push.c
+++ b/src/openvpn/push.c
= @@ -542,6 +542,11 @@
{
= msg(M_WARN, "No updatable options found in incoming = PUSH_UPDATE message");
}
+ else if (!do_upd= ate(c, option_types_found))

+ {
+ msg(D_PUSH_ERRORS, "Failed to update options= ");
+ = goto error;
= + }
}
= }
event_timeout_clear(&c->c2.push_request_i= nterval);
diff --git a/src/openvpn/route.c b/src/openvpn/ro= ute.c
index 156262a..89ebaee 100644
--- a/s= rc/openvpn/route.c
+++ b/src/openvpn/route.c
@@ -1265,7 +1265,16 @@

const struct tuntap= *tt, unsigned int flags,
const struct env_s= et *es, openvpn_net_ctx_t *ctx)
{
- if (rl && rl->iflags & RL_R= OUTES_ADDED)
+ del= ete_routes_v4(rl, tt, flags, es, ctx);
+ delete_routes_v6(rl6, tt, flags, es, ctx);+}
+
+void
+delete= _routes_v4(struct route_list *rl, const struct tuntap *tt,
+ unsigned int flags,= const struct env_set *es,
+ openvpn_net_ctx_t *ctx)
+{
+ if (rl && (rl->iflags & RL_ROUTES_ADDED))
{
struct route_ipv4 *r; for (r =3D rl->routes; r; r =3D r->next)
@@ -1281,8 +1290,14 @@

{
= clear_route_list(rl);
}
+}

- if (rl6 && (rl6->iflags & RL_ROUT= ES_ADDED) )
+void
+delete_routes_v6(struct= route_ipv6_list *rl6, const struct tuntap *tt,
+ unsigned int flags, const stru= ct env_set *es,
+ = openvpn_net_ctx_t *ctx)
+{
+ = if (rl6 && (rl6->iflags & RL_ROUTES_ADDED))
{

struct route_ipv6 *r6;
= for (r6 =3D rl6->routes_ipv6; r6; r6 =3D r6->next)
= diff --git a/src/openvpn/route.h b/src/openvpn/route.h
index 237375c..b89ec9f 100644

--- a/src/openvpn/route.h
+++ b/src/openvpn/route.h
@@ -335,6 +335,16 = @@
const struct env_set *es,
= openvpn_net_ctx_t *ctx);
=
+void
+delete_routes_v4(struct route_list *rl, c= onst struct tuntap *tt,
+ unsigned int flags, const struct env_set *es,+ openvpn_net= _ctx_t *ctx);
+
+void
+delete_routes_v6(struct route_ipv6_list = *rl6, const struct tuntap *tt,
+ unsigned int flags, const struct env_set *es,
+ open= vpn_net_ctx_t *ctx);
= +
void setenv_routes(struct env_set *es, const struct rout= e_list *rl);

void setenv_routes_ipv6(str= uct env_set *es, const struct route_ipv6_list *rl6);

To view, visit change 809. To unsubscribe, or for help writing mai= l filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I507180d7397b6959844a3090801= 0132bc3411067
Gerrit-Change-Number: 809
Gerrit-PatchSet: 22
Gerrit-Owner: mrbff <marco@...2726...> <= /div>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-Reviewer: stipa <lstipakov@...277...= >
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: cron2 <gert@...1296...>= ;
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-Attention: stipa <lstipakov@...1663...= .>
Gerrit-Attention: mrbff <marco@...2726...&g= t;
Gerrit-MessageType: newpatchset
--hG4WzCOuDSQ=--