From: "mrbff (Code Review)" Attention is currently required from: flichtenheld, plaisthos. mrbff uploaded patch set #12 to this change.PUSH_UPDATE: Added update_option() function.
When the function re=
ceives an option to update, it first checks whether it has
already recei=
ved 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 option.
Change-Id: Ia45c99e6df7b3ad24020c10b8a9b3577984ecdc2
Signed-off-by:=
Marco Baffo <marco@...2726...>
---
M src/openvpn/options.c
=
1 file changed, 247 insertions(+), 10 deletions(-)git pull ssh:=
//gerrit.openvpn.net:29418/openvpn refs/changes/10/810/12
diff --=
git a/src/openvpn/options.c b/src/openvpn/options.c
<=
p>To view, visit change 810. To unsubscribe, or for help writing mail filters,=
visit settings.
index 7=
e38d2c..bedbbb0 100644
--- a/src/openvpn/options.c+++ b/src/openvpn/options.c
@@ -5563,6 +5563,13 @@<=
/span>
return options->forward_compatible ? M_WARN : msgle=
vel;
}
+#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 P=
USH_UPDATE message that are preceded by the `-` flag.
* =
This function is used in push-updates to reset specified options.
@@ -5617,11 +5624,7 @@
delete_rou=
tes_v4(c->c1.route_list, c->c1.tuntap,
=
ROUTE_OPTION_FLAGS(&c->options),
=
es, &c->net_ctx);
- if (options->routes)<=
br>- {
- options->routes-&g=
t;routes =3D NULL;
- =
options->routes->flags =3D 0;
- }
+ RESET_OPTION_ROUTES(options->routes, ro=
utes);
}
}
=
else if (streq(p[0], "route-ipv6") && !p[1])
@@ -5632,11 +5635,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->flags =3D 0;
- }
+ RESET_OPTION_ROUTES(optio=
ns->routes_ipv6, routes_ipv6);
}
else if (streq(p[0], "route-gateway"=
;) && !p[1])
@@ -5755,6 +5754,238 @@
msg(msglevel, "Error occurred trying to r=
emove %s option", p[0]);
}
+
+/**
+ * @br=
ief Processes an option to update. It first checks whether it has already=
span>
+ * received an=
option of the same type within the same update message.
+ * If the option has already be=
en 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 arr=
ay of strings containing the options and their parameters.
+ * @param is_inline A boolean indica=
ting if the option is inline.
+ * @param file The file where the function is called.
<=
span style=3D"color: hsl(120, 100%, 40%);">+ * @param line The line number =
where the function is called.
+ * @param level The level of the option.
+ * @param msglevel The message level for log=
ging.
+ * @param perm=
ission_mask The permission mask used by VERIFY_PERMISSION().
+ * @param e=
s The environment set structure.
+ * @param update_options_found A pointer to the variable where=
the flags corresponding 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,
+ cons=
t 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(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);
+ rol_check_alloc(options);
+ if (pull_mode)
+ {+ if (!ip_or_d=
ns_addr_safe(p[1], options->allow_pull_fqdn) && !is_special_addr=
(p[1])) /* FQDN -- may be DNS name */
+ {
+ msg(msglevel, "route parameter net=
work/IP '%s' must be a valid address", p[1]);
+ goto err;=
+ }+ if (p[2] &am=
p;& !ip_addr_dotted_quad_safe(p[2])) /* FQDN -- must be IP address */=
span>
+ {
+ 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-&=
gt;allow_pull_fqdn) && !is_special_addr(p[3])) /* FQDN -- may be DN=
S name */
+ =
{
+ =
msg(msglevel, "route parameter gateway '%s' must be a =
valid address", p[3]);
+ 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_opt=
ions_found |=3D OPT_P_U_ROUTE;
+ }
=
+ }
+ else if (=
streq(p[0], "route-ipv6") && p[1] && !p[4])
+ {
+ if (!(*update_options_found &am=
p; OPT_P_U_ROUTE6))
+=
{
+ =
VERIFY_PERMISSION(OPT_P_ROUTE);
+ rol6_check_alloc(options);
+ if (pull_mode)
+ if (!ipv6_addr_safe_hexp=
lusbits(p[1]))
+ =
{
+ =
msg(msglevel, "route-ipv6 parameter network/IP '%s=
9; must be a valid address", p[1]);
+ goto err;
+ }
+ if (p[2] && !ipv6_addr=
_safe(p[2]))
+ =
{
+ =
msg(msglevel, "route-ipv6 parameter gateway '%s' mu=
st be a valid address", p[2]);
+ goto err;
+ }
+ /* p[3] is metric, if present */
+ }+ 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 (streq(p[=
1], "server") && p[2] && p[3] && p[4])
+ {+ long priorit=
y;
+ i=
f (!dns_server_priority_parse(&priority, p[2], pull_mode))+ {
+ goto =
err;
+ =
}
+
+ struct dns_server se=
rver;
+ =
CLEAR(server);
+ =
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 maxim=
um exceeded '%s'", priority, p[i]);
+ goto err;+ }
+ }<=
/span>
+ }
+ else i=
f (streq(p[3], "dnssec") && !p[5])
+ {
+ if (!streq(p[4], &quo=
t;yes") && !streq(p[4], "no") && !streq(p[4]=
, "optional"))
+ {
+ msg(msglevel, "--dns server %ld: malfor=
med dnssec value '%s'", priority, p[4]);
+ goto err;<=
br>+ }
+ }<=
br>+ else if (st=
req(p[3], "transport") && !p[5])
+ {
+ if (!streq(p[4], "pla=
in") && !streq(p[4], "DoH") && !streq(p[4], =
"DoT"))
+ =
{
+=
msg(msglevel, "--dns server %ld: malformed tra=
nsport value '%s'", priority, p[4]);
+ goto err;
<=
span style=3D"color: hsl(120, 100%, 40%);">+ }
+ }
<=
span style=3D"color: hsl(120, 100%, 40%);">+ else if (!streq=
(p[3], "resolve-domains")
+ && !(streq(p[3], "sni=
") && !p[5]))
+ {
+ msg(msglevel, "--dns server %ld: unknown opti=
on type '%s' or missing or unknown parameter", priority, p[3])=
;
+ =
goto err;
+ =
}
+ =
}
+ else=
if (!(streq(p[1], "search-domains") && p[2]))
=
+ {
+ msg(msglevel, "=
--dns: unknown option type '%s' or missing or unknown parameter&quo=
t;, p[1]);
+ =
goto err;
+ =
}
++ gc_free(&opt=
ions->dns_options.gc);
+ CLEAR(options->dns_options);
+ *update_options_found |=3D OPT_P_=
U_DNS;
+ }
+ }
+#if defined(_WIN32) || defined(TARGET=
_ANDROID)
+ else i=
f (streq(p[0], "dhcp-option") && p[1] && !p[3])=
span>
+ {
+ if (!(*update_options_found=
& OPT_P_U_DHCP))
+ {
+ =
struct tuntap_options *o =3D &options->tuntap_options;
+ VERIFY_PERMISSION=
(OPT_P_DHCPDNS);
+
+ o->doma=
in =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->nt=
p);
+ o-&g=
t;nbdd_len =3D 0;
+ =
CLEAR(o->nbdd);
+ while (o->domain_search_list_len-- > 0)+ {
+ }
+ 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_ANDR=
OID) */
+ else if =
(streq(p[0], "dhcp-option") && p[1] && !p[3])
+ {
+ if (!(*update_options_found &=
amp; OPT_P_U_DHCP))
+=
{
+ =
VERIFY_PERMISSION(OPT_P_DHCPDNS);
+ delete_all_dhcp_fo(options, &es->list);<=
/span>
+ *update_=
options_found |=3D OPT_P_U_DHCP;
+ }
+ }
+#endif /* i=
f defined(_WIN32) || defined(TARGET_ANDROID) */
+ add_option(options, p, is_inline, file, lin=
e,
+ le=
vel, msglevel, permission_mask,
+ option_types_found, es);
+ return;
+err:
+ msg(msglevel, "Error occurred trying to update %s optio=
n", p[0]);
+}
+
bool=
apply_push_options(struct context *c,
=
struct options *options,
@@ -5768,6 +5999,=
7 @@
int line_num =3D 0;
const ch=
ar *file =3D "[PUSH-OPTIONS]";
const int msg=
level =3D D_PUSH_ERRORS|M_OPTERR;
+ unsigned int update_options_found =3D 0;
=
while (buf_parse(buf, ',', line, sizeof(line=
)))
{
@@ -5793,6 +6025,11 @@
remove_option(c, options, p, false, file, line_num,=
msglevel,
permission_mask, =
option_types_found, es);
}
+ else
+ {
+ update_option(c, options, p, fa=
lse, file, line_num, 0, msglevel,
+ permission_mask, option_types_f=
ound, es, &update_options_found);
+ }
}
=
}
return true;