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="bdyHcSx44ZI="; charset=UTF-8 Subject: [Openvpn-devel] [L] Change in openvpn[master]: PUSH_UPDATE: Added update_option() function. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld , stipa Cc: openvpn-devel --bdyHcSx44ZI= 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/+/810?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 update_option() function. ...................................................................... PUSH_UPDATE: Added update_option() function. When the function receives an option to update, it first checks whether it = has already received an option of the same type within the same update message. If it has already received it, it simply calls add_option(), otherwise it deletes all the values =E2=80=8B=E2=80=8Balready present regarding that opt= ion. Change-Id: Ia45c99e6df7b3ad24020c10b8a9b3577984ecdc2 Signed-off-by: Marco Baffo --- M src/openvpn/options.c 1 file changed, 331 insertions(+), 124 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/10/810/22 diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 683dae6..d5f8826 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -5372,6 +5372,20 @@ struct env_set *es); static void +update_option(struct context *c, + struct options *options, + char *p[], + bool is_inline, + const char *file, + int line, + const int level, + const int msglevel, + const unsigned int permission_mask, + unsigned int *option_types_found, + struct env_set *es, + unsigned int *update_options_found); + +static void read_config_file(struct options *options, const char *file, int level, @@ -5557,6 +5571,7 @@ int line_num =3D 0; const char *file =3D "[PUSH-OPTIONS]"; const int msglevel =3D D_PUSH_ERRORS|M_OPTERR; + unsigned int update_options_found =3D 0; while (buf_parse(buf, ',', line, sizeof(line))) { @@ -5598,6 +5613,11 @@ remove_option(c, options, p, false, file, line_num, msglev= el, permission_mask, option_types_found, es); } + else + { + update_option(c, options, p, false, file, line_num, 0, msg= level, + permission_mask, option_types_found, es, &up= date_options_found); + } } } return true; @@ -5736,6 +5756,13 @@ return options->forward_compatible ? M_WARN : msglevel; } +#define RESET_OPTION_ROUTES(option_ptr, field) \ + if (option_ptr) \ + { \ + option_ptr->field =3D NULL; \ + option_ptr->flags =3D 0; \ + } + /** * @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. @@ -5790,11 +5817,7 @@ 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; - } + RESET_OPTION_ROUTES(options->routes, routes); } } else if (streq(p[0], "route-ipv6") && !p[1]) @@ -5805,11 +5828,7 @@ 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; - } + RESET_OPTION_ROUTES(options->routes_ipv6, routes_ipv6); } } else if (streq(p[0], "route-gateway") && !p[1]) @@ -5929,6 +5948,303 @@ msg(msglevel, "Error occurred trying to remove %s option", p[0]); } + +static bool +check_route_option(struct options *options, char *p[], const int msglevel,= bool pull_mode) +{ + rol_check_alloc(options); + if (pull_mode) + { + if (!ip_or_dns_addr_safe(p[1], options->allow_pull_fqdn) && !is_sp= ecial_addr(p[1])) /* FQDN -- may be DNS name */ + { + msg(msglevel, "route parameter network/IP '%s' must be a valid= address", p[1]); + return false; + } + if (p[2] && !ip_addr_dotted_quad_safe(p[2])) /* FQDN -- must be IP= address */ + { + msg(msglevel, "route parameter netmask '%s' must be an IP addr= ess", p[2]); + return false; + } + if (p[3] && !ip_or_dns_addr_safe(p[3], options->allow_pull_fqdn) &= & !is_special_addr(p[3])) /* FQDN -- may be DNS name */ + { + msg(msglevel, "route parameter gateway '%s' must be a valid ad= dress", p[3]); + return false; + } + } + return true; +} + + +static bool +check_route6_option(struct options *options, char *p[], const int msglevel= , bool pull_mode) +{ + rol6_check_alloc(options); + if (pull_mode) + { + if (!ipv6_addr_safe_hexplusbits(p[1])) + { + msg(msglevel, "route-ipv6 parameter network/IP '%s' must be a = valid address", p[1]); + return false; + } + if (p[2] && !ipv6_addr_safe(p[2])) + { + msg(msglevel, "route-ipv6 parameter gateway '%s' must be a val= id address", p[2]); + return false; + } + /* p[3] is metric, if present */ + } + return true; +} + +static bool +check_dns_option(struct options *options, char *p[], const int msglevel, b= ool pull_mode) +{ + if (streq(p[1], "search-domains") && p[2]) + { + dns_domain_list_append(&options->dns_options.search_domains, &p[2]= , &options->dns_options.gc); + } + else if (streq(p[1], "server") && p[2] && p[3] && p[4]) + { + long priority; + if (!dns_server_priority_parse(&priority, p[2], pull_mode)) + { + msg(msglevel, "--dns server: invalid priority value '%s'", p[2= ]); + return false; + } + + struct dns_server *server =3D dns_server_get(&options->dns_options= .servers, priority, &options->dns_options.gc); + + if (streq(p[3], "address") && p[4]) + { + for (int i =3D 4; p[i]; ++i) + { + if (!dns_server_addr_parse(server, p[i])) + { + msg(msglevel, "--dns server %ld: malformed address or = maximum exceeded '%s'", priority, p[i]); + return false; + } + } + } + else if (streq(p[3], "resolve-domains")) + { + dns_domain_list_append(&server->domains, &p[4], &options->dns_= options.gc); + } + else if (streq(p[3], "dnssec") && !p[5]) + { + if (streq(p[4], "yes")) + { + server->dnssec =3D DNS_SECURITY_YES; + } + else if (streq(p[4], "no")) + { + server->dnssec =3D DNS_SECURITY_NO; + } + else if (streq(p[4], "optional")) + { + server->dnssec =3D DNS_SECURITY_OPTIONAL; + } + else + { + msg(msglevel, "--dns server %ld: malformed dnssec value '%= s'", priority, p[4]); + return false; + } + } + else if (streq(p[3], "transport") && !p[5]) + { + if (streq(p[4], "plain")) + { + server->transport =3D DNS_TRANSPORT_PLAIN; + } + else if (streq(p[4], "DoH")) + { + server->transport =3D DNS_TRANSPORT_HTTPS; + } + else if (streq(p[4], "DoT")) + { + server->transport =3D DNS_TRANSPORT_TLS; + } + else + { + msg(msglevel, "--dns server %ld: malformed transport value= '%s'", priority, p[4]); + return false; + } + } + else if (streq(p[3], "sni") && !p[5]) + { + server->sni =3D p[4]; + } + else + { + msg(msglevel, "--dns server %ld: unknown option type '%s' or m= issing or unknown parameter", priority, p[3]); + return false; + } + } + else + { + msg(msglevel, "--dns: unknown option type '%s' or missing or unkno= wn parameter", p[1]); + return false; + } + return true; +} + +/** + * @brief Processes an option to update. It first checks whether it has al= ready + * received an option of the same type within the same update messa= ge. + * If the option has already been received, it calls add_option(). + * Otherwise, it deletes all existing values related to that option= before calling add_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 level The level of the option. + * @param msglevel The message level for logging. + * @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. + * @param update_options_found A pointer to the variable where the flags c= orresponding to the update options found are stored, + * used to check if an option of the same type= has already been processed by update_option() within the same push-update = message. + */ +static void +update_option(struct context *c, + struct options *options, + char *p[], + bool is_inline, + const char *file, + int line, + const int level, + const int msglevel, + const unsigned int permission_mask, + unsigned int *option_types_found, + struct env_set *es, + unsigned int *update_options_found) +{ + const bool pull_mode =3D BOOL_CAST(permission_mask & OPT_P_PULL_MODE); + ASSERT(MAX_PARMS >=3D 7); + + if (streq(p[0], "route") && p[1] && !p[5]) + { + if (!(*update_options_found & OPT_P_U_ROUTE)) + { + VERIFY_PERMISSION(OPT_P_ROUTE); + if (!check_route_option(options, p, msglevel, pull_mode)) + { + goto err; + } + if (c->c1.route_list) + { + delete_routes_v4(c->c1.route_list, c->c1.tuntap, + ROUTE_OPTION_FLAGS(&c->options), + es, &c->net_ctx); + RESET_OPTION_ROUTES(options->routes, routes); + } + *update_options_found |=3D OPT_P_U_ROUTE; + } + } + else if (streq(p[0], "route-ipv6") && p[1] && !p[4]) + { + if (!(*update_options_found & OPT_P_U_ROUTE6)) + { + VERIFY_PERMISSION(OPT_P_ROUTE); + if (!check_route6_option(options, p, msglevel, pull_mode)) + { + goto err; + } + 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); + RESET_OPTION_ROUTES(options->routes_ipv6, routes_ipv6); + } + *update_options_found |=3D OPT_P_U_ROUTE6; + } + } + else if (streq(p[0], "redirect-gateway") || streq(p[0], "redirect-priv= ate")) + { + if (!(*update_options_found & OPT_P_U_REDIR_GATEWAY)) + { + VERIFY_PERMISSION(OPT_P_ROUTE); + if (options->routes) + { + options->routes->flags =3D 0; + } + if (options->routes_ipv6) + { + options->routes_ipv6->flags =3D 0; + } + *update_options_found |=3D OPT_P_U_REDIR_GATEWAY; + } + } + else if (streq(p[0], "dns") && p[1]) + { + if (!(*update_options_found & OPT_P_U_DNS)) + { + VERIFY_PERMISSION(OPT_P_DHCPDNS); + if (!check_dns_option(options, p, msglevel, pull_mode)) + { + goto err; + } + gc_free(&options->dns_options.gc); + CLEAR(options->dns_options); + *update_options_found |=3D OPT_P_U_DNS; + } + } +#if defined(_WIN32) || defined(TARGET_ANDROID) + else if (streq(p[0], "dhcp-option") && p[1] && !p[3]) + { + if (!(*update_options_found & OPT_P_U_DHCP)) + { + 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; + CLEAR(o->dns6); + o->dns_len =3D 0; + CLEAR(o->dns); + o->wins_len =3D 0; + CLEAR(o->wins); + o->ntp_len =3D 0; + CLEAR(o->ntp); + o->nbdd_len =3D 0; + CLEAR(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 + *update_options_found |=3D OPT_P_U_DHCP; + } + } +#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */ + else if (streq(p[0], "dhcp-option") && p[1] && !p[3]) + { + if (!(*update_options_found & OPT_P_U_DHCP)) + { + VERIFY_PERMISSION(OPT_P_DHCPDNS); + delete_all_dhcp_fo(options, &es->list); + *update_options_found |=3D OPT_P_U_DHCP; + } + } +#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */ + add_option(options, p, is_inline, file, line, + level, msglevel, permission_mask, + option_types_found, es); + return; +err: + msg(msglevel, "Error occurred trying to update %s option", p[0]); +} + static void set_user_script(struct options *options, const char **script, @@ -7292,45 +7608,18 @@ else if (streq(p[0], "route") && p[1] && !p[5]) { VERIFY_PERMISSION(OPT_P_ROUTE); - rol_check_alloc(options); - if (pull_mode) + if (!check_route_option(options, p, msglevel, pull_mode)) { - if (!ip_or_dns_addr_safe(p[1], options->allow_pull_fqdn) && !i= s_special_addr(p[1])) /* FQDN -- may be DNS name */ - { - msg(msglevel, "route parameter network/IP '%s' must be a v= alid address", p[1]); - goto err; - } - if (p[2] && !ip_addr_dotted_quad_safe(p[2])) /* FQDN -- must b= e IP address */ - { - msg(msglevel, "route parameter netmask '%s' must be an IP = address", p[2]); - goto err; - } - if (p[3] && !ip_or_dns_addr_safe(p[3], options->allow_pull_fqd= n) && !is_special_addr(p[3])) /* FQDN -- may be DNS name */ - { - msg(msglevel, "route parameter gateway '%s' must be a vali= d address", p[3]); - goto err; - } - /* p[4] is metric, if specified */ + goto err; } add_route_to_option_list(options->routes, p[1], p[2], p[3], p[4], = options->route_default_table_id); } else if (streq(p[0], "route-ipv6") && p[1] && !p[4]) { VERIFY_PERMISSION(OPT_P_ROUTE); - rol6_check_alloc(options); - if (pull_mode) + if (!check_route6_option(options, p, msglevel, pull_mode)) { - if (!ipv6_addr_safe_hexplusbits(p[1])) - { - msg(msglevel, "route-ipv6 parameter network/IP '%s' must b= e a valid address", p[1]); - goto err; - } - if (p[2] && !ipv6_addr_safe(p[2])) - { - msg(msglevel, "route-ipv6 parameter gateway '%s' must be a= valid address", p[2]); - goto err; - } - /* p[3] is metric, if specified */ + goto err; } add_route_ipv6_to_option_list(options->routes_ipv6, p[1], p[2], p[= 3], options->route_default_table_id); } @@ -8418,90 +8707,8 @@ else if (streq(p[0], "dns") && p[1]) { VERIFY_PERMISSION(OPT_P_DHCPDNS); - - if (streq(p[1], "search-domains") && p[2]) + if (!check_dns_option(options, p, msglevel, pull_mode)) { - dns_domain_list_append(&options->dns_options.search_domains, &= p[2], &options->dns_options.gc); - } - else if (streq(p[1], "server") && p[2] && p[3] && p[4]) - { - long priority; - if (!dns_server_priority_parse(&priority, p[2], pull_mode)) - { - msg(msglevel, "--dns server: invalid priority value '%s'",= p[2]); - goto err; - } - - struct dns_server *server =3D dns_server_get(&options->dns_opt= ions.servers, priority, &options->dns_options.gc); - - if (streq(p[3], "address") && p[4]) - { - for (int i =3D 4; p[i]; ++i) - { - if (!dns_server_addr_parse(server, p[i])) - { - msg(msglevel, "--dns server %ld: malformed address= or maximum exceeded '%s'", priority, p[i]); - goto err; - } - } - } - else if (streq(p[3], "resolve-domains")) - { - dns_domain_list_append(&server->domains, &p[4], &options->= dns_options.gc); - } - else if (streq(p[3], "dnssec") && !p[5]) - { - if (streq(p[4], "yes")) - { - server->dnssec =3D DNS_SECURITY_YES; - } - else if (streq(p[4], "no")) - { - server->dnssec =3D DNS_SECURITY_NO; - } - else if (streq(p[4], "optional")) - { - server->dnssec =3D DNS_SECURITY_OPTIONAL; - } - else - { - msg(msglevel, "--dns server %ld: malformed dnssec valu= e '%s'", priority, p[4]); - goto err; - } - } - else if (streq(p[3], "transport") && !p[5]) - { - if (streq(p[4], "plain")) - { - server->transport =3D DNS_TRANSPORT_PLAIN; - } - else if (streq(p[4], "DoH")) - { - server->transport =3D DNS_TRANSPORT_HTTPS; - } - else if (streq(p[4], "DoT")) - { - server->transport =3D DNS_TRANSPORT_TLS; - } - else - { - msg(msglevel, "--dns server %ld: malformed transport v= alue '%s'", priority, p[4]); - goto err; - } - } - else if (streq(p[3], "sni") && !p[5]) - { - server->sni =3D p[4]; - } - else - { - msg(msglevel, "--dns server %ld: unknown option type '%s' = or missing or unknown parameter", priority, p[3]); - goto err; - } - } - else - { - msg(msglevel, "--dns: unknown option type '%s' or missing or u= nknown parameter", p[1]); goto err; } } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/810?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: Ia45c99e6df7b3ad24020c10b8a9b3577984ecdc2 Gerrit-Change-Number: 810 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 --bdyHcSx44ZI= 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 update_option() function.

When the function rece= ives an option to update, it first checks whether it has
already receive= d an option of the same type within the same update message.
If it has a= lready received it, it simply calls add_option(), otherwise it
deletes a= ll the values =E2=80=8B=E2=80=8Balready present regarding that option.
<= br>Change-Id: Ia45c99e6df7b3ad24020c10b8a9b3577984ecdc2
Signed-off-by: M= arco Baffo <marco@...2726...>
---
M src/openvpn/options.c
1 = file changed, 331 insertions(+), 124 deletions(-)

git pull ssh:=
//gerrit.openvpn.net:29418/openvpn refs/changes/10/810/22
diff --=
git a/src/openvpn/options.c b/src/openvpn/options.c
index 6= 83dae6..d5f8826 100644
--- a/src/openvpn/options.c+++ b/src/openvpn/options.c
@@ -5372,6 +5372,20 @@<= /span>
struct env_set *es);

static void
+update_option(struct context *c,
+ struct options *options,
+ char *p[],
+ bool is_inline,
+ const char= *file,
+ = int line,
+ = const int level,
+ const unsigned int permission_mask,+ unsigned int *= option_types_found,
+= struct env_set *es,
+ unsigned int *update_options_found);
= +
+static void
read_config_file(str= uct options *options,
const char *file,
int level,
@@ -5557,6 +557= 1,7 @@
int line_num =3D 0;
const = char *file =3D "[PUSH-OPTIONS]";
const int m= sglevel =3D D_PUSH_ERRORS|M_OPTERR;
+ unsigned int update_options_found =3D 0;

while (buf_parse(buf, ',', line, sizeof(li= ne)))
{
@@ -5598,6 +5613,11 @@<= br> remove_option(c, options, p, false, file, line_nu= m, msglevel,
permission_mask= , option_types_found, es);
}
+ else
+ {
+ update_option(c, options, p, f= alse, file, line_num, 0, msglevel,
+ permission_mask, option_types_= found, es, &update_options_found);
+ }
}
}

return true;
@@ -5736,6 +5756,= 13 @@
return options->forward_compatible ? M_WARN := msglevel;
}

+#define RESET_OPTION_ROUTES(option_ptr, field) = \
+ if (option_ptr= ) \
+ { \
+ option_ptr->field =3D NULL; = \
+ opt= ion_ptr->flags =3D 0; \
+ }
+
/**
* @brief Resets options found = in the PUSH_UPDATE message that are preceded by the `-` flag.
* This function is used in push-updates to reset specified opti= ons.

@@ -5790,11 +5817,7 @@
de= lete_routes_v4(c->c1.route_list, c->c1.tuntap,
= ROUTE_OPTION_FLAGS(&c->options),
<= span> es, &c->net_ctx);
- if (options->routes)
- {- options->rou= tes->routes =3D NULL;
- }
+ RESET_OPTION_ROUTES(options->rout= es, routes);
}
}
else if (streq(p[0], "route-ipv6") && !p[1])
@@ -5805,11 +5828,7 @@
delete_rou= tes_v6(c->c1.route_ipv6_list, c->c1.tuntap,
= ROUTE_OPTION_FLAGS(&c->options),
es, &c->net_ctx);
- if (options->routes_ipv6)=
- {<= br>- options->r= outes_ipv6->routes_ipv6 =3D NULL;
- options->routes_ipv6->flags =3D 0;
- }
<= span style=3D"color: hsl(120, 100%, 40%);">+ RESET_OPTION_ROUTES= (options->routes_ipv6, routes_ipv6);

} }
else if (streq(p[0], "route-gatewa= y") && !p[1])
@@ -5929,6 +5948,303 @@ msg(msglevel, "Error occurred trying to remove %s option&= quot;, p[0]);
}

+
+static bool
+check_route_option(struct options *options, char *p[], const int msglev= el, bool pull_mode)
+= {
+ rol_check_allo= c(options);
+ if (= pull_mode)
+ {
+ if (!ip_or_dns_= addr_safe(p[1], options->allow_pull_fqdn) && !is_special_addr(p[= 1])) /* FQDN -- may be DNS name */
+ {
+ msg(msglevel, "route parameter network/IP '%s'= ; must be a valid address", p[1]);
+ return false;
+ }
+ if (p[2] && !ip_addr_dotted_quad_safe(p[2])= ) /* FQDN -- must be IP address */
+ {
+ msg(msglevel, "route parameter netmask '%s' m= ust be an IP address", p[2]);
+ return false;
+ }
+ if (p[3] && !ip_or_dns_addr_safe(p[3], options-&= gt;allow_pull_fqdn) && !is_special_addr(p[3])) /* FQDN -- may be DN= S name */
+ {<= /span>
+ msg(msgl= evel, "route parameter gateway '%s' must be a valid address&qu= ot;, p[3]);
+ = return false;
+ = }
+ }=
+ return true;+}
+
+
+static boo= l
+check_route6_optio= n(struct options *options, char *p[], const int msglevel, bool pull_mode)
+{
+ rol6_check_alloc(options);+ if (pull_mode)+ {
+ if (!ipv6_addr_safe_hexplusbits(p= [1]))
+ {

+ msg(msglevel= , "route-ipv6 parameter network/IP '%s' must be a valid addres= s", p[1]);
+ = return false;
+ }
+ = if (p[2] && !ipv6_addr_safe(p[2]))
+ {
+ msg(msglevel, "route-ipv6 parameter gateway &= #39;%s' must be a valid address", p[2]);
+ return false;
+ }
+ /* p[3] is metric, if present */+ }
+ return true;
+}
+
+static= bool
+check_dns_opti= on(struct options *options, char *p[], const int msglevel, bool pull_mode)<= /span>
+{
+ if (streq(p[1], "search-domai= ns") && p[2])
+ {
+ = dns_domain_list_append(&options->dns_options.search_domains, &p= [2], &options->dns_options.gc);
+ }
+ else if (streq(p[1], "server") && p[2] &&= ; p[3] && p[4])
+ {
+ lo= ng priority;
+ = if (!dns_server_priority_parse(&priority, p[2], pull_mode))
= + {
+ msg(msglevel, "--dns se= rver: invalid priority value '%s'", p[2]);
+ return false;
+ }

+
+ struct dns_server *server =3D dns_server_get(&op= tions->dns_options.servers, priority, &options->dns_options.gc);<= /span>
+
+ if (streq(p[3], "address&q= uot;) && p[4])
+ = for (int i =3D 4; p[i]; ++i)
+ {
+ if (!dns_server_addr_parse(server, p[i]))+ {
<= span style=3D"color: hsl(120, 100%, 40%);">+ msg(msgleve= l, "--dns server %ld: malformed address or maximum exceeded '%s= 9;", priority, p[i]);

+ return false;
+ }
+ }
+ }
+ {
+ dns_domain_list_append(&s= erver->domains, &p[4], &options->dns_options.gc);
<= span style=3D"color: hsl(120, 100%, 40%);">+ }
+ else if (streq(p[3], "dnssec= ") && !p[5])
+ {
+ = if (streq(p[4], "yes"))
+ {
+ server->dnssec =3D DNS_SECURITY_YES;
+ }+ else if (streq(p[= 4], "no"))
= + {
+ = server->dnssec =3D DNS_SECURITY_NO;
+ }
+ else if (streq(p[4], "optional&quo= t;))
+ {
+ serve= r->dnssec =3D DNS_SECURITY_OPTIONAL;
+ }
+ else
+ {
+ msg(msglevel, "--dns server %ld: malformed dnssec= value '%s'", priority, p[4]);
+ return false;
+ }
+ }
+ else if (streq(p[3], "transport") &= & !p[5])
+ = {
+ if (s= treq(p[4], "plain"))
+ {
+ server->transport =3D DNS_TRANSPORT_PLAIN;+ }
+ else if (streq(p[4], &= quot;DoH"))

+ = {
+ = server->transport =3D DNS_TRANSPORT_HTTPS;
+ }
+ else if (streq(p[4], "DoT"= ;))
+ {

+ server= ->transport =3D DNS_TRANSPORT_TLS;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else if (streq(p[3], "sni") &&= !p[5])
+ {
+ server->= ;sni =3D p[4];
+ = }
+ else
+ {
+ msg(msglevel, "= --dns server %ld: unknown option type '%s' or missing or unknown pa= rameter", priority, p[3]);

+ return false;
+ }
+ }
+ el= se
+ {
<= span style=3D"color: hsl(120, 100%, 40%);">+ msg(msglevel, "--d= ns: unknown option type '%s' or missing or unknown parameter",= p[1]);

+ retu= rn false;
+ }
+ return true;<= br>+}
+
+/**
+ * @b= rief Processes an option to update. It first checks whether it has already<= /span>
+ * received a= n option of the same type within the same update message.
+ * If the option has already b= een received, it calls add_option().
+ * Otherwise, it deletes all existing values relate= d to that option before calling add_option().
+ *
+ * @param c The context structure.
+ * @param options A pointer to the options structur= e.
+ * @param p An ar= ray of strings containing the options and their parameters.
+ * @param is_inline A boolean indic= ating 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 level The level of the option.
+ * @param msglevel The message level for = logging.
+ * @param p= ermission_mask The permission mask used by VERIFY_PERMISSION().
<= span style=3D"color: hsl(120, 100%, 40%);">+ * @param option_types_found A = pointer to the variable where the flags corresponding to the options found = are stored.

+ * @para= m es The environment set structure.
+ * @param update_options_found A pointer to the variable wh= ere the flags corresponding to the update options found are stored,<= br>+ * = used to check if an option of the same type has already been processed = by update_option() within the same push-update message.
+ */
+static void
+update_option(struct context *c,
+ struct options *options,
<= span style=3D"color: hsl(120, 100%, 40%);">+ char *p[],=
+ bool is_inli= ne,
+ co= nst char *file,
+ = int line,
+= const int level,
+ const int msglevel,
+ const unsigned int permission_mask,<= /span>
+ unsign= ed int *option_types_found,
+ struct env_set *es,
+ unsigned int *update_options_found)
+{
+ const bool pull_mode =3D BOOL_CAST(pe= rmission_mask & OPT_P_PULL_MODE);
+ ASSERT(MAX_PARMS >=3D 7);
+
+ if (streq(p[0], "route") && p[1] &&am= p; !p[5])
+ {
+ if (!(*update_op= tions_found & OPT_P_U_ROUTE))
+ {
+ VERIFY_PERMISSION(OPT_P_ROUTE);
+ if (!check_route_option(options, p,= msglevel, pull_mode))
+ = goto err;
+ = if (c->c1.route_list)
+ {
+ delete_routes_v4(c->c1.route_list, c->c1.tunt= ap,
+ = ROUTE_OPTION_FLAGS(&c->options),
+ es, &= amp;c->net_ctx);
+= RESET_OPTION_ROUTES(options->routes, routes);
= + }
+ *update_options_found |= =3D OPT_P_U_ROUTE;
+ = }
+ }

+ else if (streq(p[0], = "route-ipv6") && p[1] && !p[4])
+ {
+ if (!(*update_options_found & OPT_P_U_R= OUTE6))
+ {
+ VERIFY_PER= MISSION(OPT_P_ROUTE);
+ if (!check_route6_option(options, p, msglevel, pull_mode))
+ {+ goto err;
+ }+ if (c->c1.rou= te_ipv6_list)
+ = {
+ = delete_routes_v6(c->c1.route_ipv6_list, c->c1.tuntap,
<= span style=3D"color: hsl(120, 100%, 40%);">+ = ROUTE_OPTION_FLAGS(&c->options),

+ es, &c->net_c= tx);
+ = RESET_OPTION_ROUTES(options->routes_ipv6, routes_ipv6);
+ }

+ *update_options_found |=3D OP= T_P_U_ROUTE6;
+ = }
+ }
= + else if (streq(p[0], "= ;redirect-gateway") || streq(p[0], "redirect-private"))
+ {
+ if (!(*update_options_found &a= mp; OPT_P_U_REDIR_GATEWAY))
+ {
+ = VERIFY_PERMISSION(OPT_P_ROUTE);
+ if (options->routes)
+ {
+ options->routes->fl= ags =3D 0;
+ = }
+ if = (options->routes_ipv6)
+ {
+= options->routes_ipv6->flags =3D 0;
+ }
+ *update_options_found |=3D OPT_P= _U_REDIR_GATEWAY;
+ = }
+ }=
+ else if (streq(p[0], &= quot;dns") && p[1])
+ {
+ = if (!(*update_options_found & OPT_P_U_DNS))
+ {
+ VERIFY_PERMISSION(OPT_P_DHCPDNS);
+ if (!check_d= ns_option(options, p, msglevel, pull_mode))
+ {
+ goto err;
+ }
+ gc_free(&options->dns_options.gc);
+ CLEAR(optio= ns->dns_options);
= + *update_options_found |=3D OPT_P_U_DNS;
+ }
+ }
+#if defined(_WIN32) || defined(TARGET_ANDROID)
+ else if (streq(p[0], "dhcp-op= tion") && p[1] && !p[3])
+ {
+ if (!(*update_options_found & OPT_P_U_DHCP))=
+ {
+ struct tuntap_options *o= =3D &options->tuntap_options;
+ VERIFY_PERMISSION(OPT_P_DHCPDNS);
<= span style=3D"color: hsl(120, 100%, 40%);">+

+ o->domain =3D NULL;
+ o->netbios_scope =3D= NULL;

+ o= ->netbios_node_type =3D 0;
+ o->dns6_len =3D 0;
+ CLEAR(o->dns6);
+ o->dns_len =3D 0;<= br>+ CLEAR(o->dns= );
+ o->= ;wins_len =3D 0;
+ = CLEAR(o->wins);
+ o->ntp_len =3D 0;
+ CLEAR(o->ntp);
+ o->nbdd_len =3D 0;
= + CLEAR(o->nbdd);=
+ while (= o->domain_search_list_len-- > 0)
+ {
+ o->domain_search_list[o->domain_search_l= ist_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
+ = *update_options_found |=3D OPT_P_U_DHCP;
+ }
+ }
+#el= se /* if defined(_WIN32) || defined(TARGET_ANDROID) */
+ else if (streq(p[0], "dhcp-opti= on") && p[1] && !p[3])
+ {
+ if (!(*update_options_found & OPT_P_U_DHCP))+ {
+ VERIFY_PERMISSION(OPT_P_DH= CPDNS);
+ = delete_all_dhcp_fo(options, &es->list);
+ *update_options_found |=3D OPT_P_U_D= HCP;
+ }
+ }
+#endif /* if defined(_WIN32) || defined= (TARGET_ANDROID) */
+= add_option(options, p, is_inline, file, line,
+ level, msglevel, permission_ma= sk,
+ o= ption_types_found, es);
+ return;
+err:=
+ msg(msglevel, &= quot;Error occurred trying to update %s option", p[0]);
+}

+
static void
set_u= ser_script(struct options *options,
const = char **script,
@@ -7292,45 +7608,18 @@
= else if (streq(p[0], "route") && p[1] && !p[5])<= /span>
{
VERIFY_PERMISSION(OPT_P_ROU= TE);
- rol_check= _alloc(options);
- = if (pull_mode)
+ = if (!check_route_option(options, p, msglevel, pull_mode))
<= span> {

- = if (!ip_or_dns_addr_safe(p[1], options->allow_pull_fqdn) &&= ; !is_special_addr(p[1])) /* FQDN -- may be DNS name */
- {
- msg(msglevel, "route paramet= er network/IP '%s' must be a valid address", p[1]);
= - goto err;=
- }
- if (p[2] && !ip_= addr_dotted_quad_safe(p[2])) /* FQDN -- must be IP address */

- {

- msg(msglevel, "route p= arameter netmask '%s' must be an IP address", p[2]);- goto err;
- }
- if (p[3] && !ip= _or_dns_addr_safe(p[3], options->allow_pull_fqdn) && !is_special= _addr(p[3])) /* FQDN -- may be DNS name */

- {
- msg(msglevel, "route parameter gateway &#= 39;%s' must be a valid address", p[3]);
- goto err;
- }
- /* p[4] is metric, if specified */
+ goto err;
}
add_route_to_option_list(= options->routes, p[1], p[2], p[3], p[4], options->route_default_table= _id);
}
else if (streq(p[0], &quo= t;route-ipv6") && p[1] && !p[4])
= {
VERIFY_PERMISSION(OPT_P_ROUTE);
- rol6_check_alloc(options);
- if (pull_mode)
+ if (!check_rou= te6_option(options, p, msglevel, pull_mode))
{
- if (!ipv6_add= r_safe_hexplusbits(p[1]))
- {
- = msg(msglevel, "route-ipv6 parameter network/IP '%s'= ; must be a valid address", p[1]);
- goto err;
- }
- if (p[2] && !ipv6_addr_safe(p[2]))=
- {
- msg(msglevel, "= route-ipv6 parameter gateway '%s' must be a valid address", p[= 2]);

- g= oto err;
- }=
- /* p[3] i= s metric, if specified */
+ goto err;
}
= add_route_ipv6_to_option_list(options->routes_ipv6, p[1], p[2], p[3= ], options->route_default_table_id);
}
@@ -8418,90 +8707,8 @@

else if (streq(p[0], "= dns") && p[1])
{
= VERIFY_PERMISSION(OPT_P_DHCPDNS);
-
- = if (streq(p[1], "search-domains") && p[2])
+ if (!check_dns_option(opti= ons, p, msglevel, pull_mode))

{
- dns_domain_list_append(&= options->dns_options.search_domains, &p[2], &options->dns_opt= ions.gc);
- }
- else if (streq(p= [1], "server") && p[2] && p[3] && p[4])
- {
- long priority;
- if (!dns_server_pr= iority_parse(&priority, p[2], pull_mode))
- {
- msg(msglevel, "--dns server: invalid p= riority value '%s'", p[2]);
- goto err;
- }
-
- = struct dns_server *server =3D dns_server_get(&options->dns_opt= ions.servers, priority, &options->dns_options.gc);
-
- if (streq(p[3], "address") && = p[4])
- {
- for (int= i =3D 4; p[i]; ++i)
- = {
- = if (!dns_server_addr_parse(server, p[i]))
- {
- msg(msglevel, &q= uot;--dns server %ld: malformed address or maximum exceeded '%s'&qu= ot;, priority, p[i]);
-= goto err;
- }
- }
- }
-= else if (streq(p[3], "resolve-domains"))
- {

- dns_domain_list_append(&am= p;server->domains, &p[4], &options->dns_options.gc);- }
- else if (streq(p[3], "= ;dnssec") && !p[5])
- {
- {
- server->dnssec =3D DNS_S= ECURITY_YES;
- = }
- = else if (streq(p[4], "no"))
- {
- server->dnssec =3D DNS_SECURITY_NO;
- }
- else if (st= req(p[4], "optional"))
- {
- server->dnssec =3D DNS_SECURITY_OPTIONAL;
- }<= br>- else- {
- msg(msglevel, = "--dns server %ld: malformed dnssec value '%s'", priority= , p[4]);

- = goto err;
- = }
- = }
- else = if (streq(p[3], "transport") && !p[5])
- {
- if (streq(p[4], "plain"= ;))
- {<= /span>
- se= rver->transport =3D DNS_TRANSPORT_PLAIN;
- }
- else if (streq(p[4], "DoH"))
- {=
- server-&= gt;transport =3D DNS_TRANSPORT_HTTPS;
- }
- else if (streq(p[4], "DoT"))- {
- server->tra= nsport =3D DNS_TRANSPORT_TLS;

- }
- else
- = msg(msglevel, "--dns server %ld: malformed transpor= t value '%s'", priority, p[4]);
- goto err;
- }
- }
- else if (streq(p[3], "sni") &= & !p[5])
- = {
- s= erver->sni =3D p[4];
- }
- = else
- = {
- msg= (msglevel, "--dns server %ld: unknown option type '%s' or miss= ing or unknown parameter", priority, p[3]);
- goto err;
- }
- }
- else
- = msg(msglevel, "--dns: unknown option type '%s' or missing o= r unknown parameter", p[1]);
goto err;
}
}

=

To view, visit change 810. To unsubscribe, or for help writing mail fil= ters, visit settings.

<= meta itemprop=3D"name" content=3D"View Change"/>
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia45c99e6df7b3ad24020c10b8a9= b3577984ecdc2
Gerrit-Change-Number: 810
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
--bdyHcSx44ZI=--