aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe2023-03-23 18:05:58 +0100
committerGert Doering2023-03-23 18:17:23 +0100
commit5fed4be1bf4b2c6e4ff0117bceb9613fa68b412d (patch)
tree5a9495e9c4badca066114e51806d8bf4f14a84aa
parent1fd69b9085f4c21542ec506d101eb73b3cd0abc4 (diff)
downloadopenvpn-5fed4be1bf4b2c6e4ff0117bceb9613fa68b412d.zip
openvpn-5fed4be1bf4b2c6e4ff0117bceb9613fa68b412d.tar.gz
Simplify --compress parsing in options.c
This removes a level of identation and make the "stub" condition easier to see. Change-Id: Iae47b191f522625f81eedd3a237b272cb7374d90 Signed-off-by: Arne Schwabe <arne@rfc2549.org> Acked-by: Gert Doering <gert@greenie.muc.de> Message-Id: <20230323170601.1256132-1-arne@rfc2549.org> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26501.html Signed-off-by: Gert Doering <gert@greenie.muc.de> (cherry picked from commit bfc00a01c10bbdd9683aab5db2c2e7dcbb2f7378)
-rw-r--r--src/openvpn/options.c87
1 files changed, 43 insertions, 44 deletions
diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index 64a8250..2bed4ce 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -8458,60 +8458,59 @@ add_option(struct options *options,
else if (streq(p[0], "compress") && !p[2])
{
VERIFY_PERMISSION(OPT_P_COMP);
+ const char *alg = "stub";
if (p[1])
{
- if (streq(p[1], "stub"))
- {
- options->comp.alg = COMP_ALG_STUB;
- options->comp.flags |= (COMP_F_SWAP|COMP_F_ADVERTISE_STUBS_ONLY);
- }
- else if (streq(p[1], "stub-v2"))
- {
- options->comp.alg = COMP_ALGV2_UNCOMPRESSED;
- options->comp.flags |= COMP_F_ADVERTISE_STUBS_ONLY;
- }
- else if (streq(p[1], "migrate"))
- {
- options->comp.alg = COMP_ALG_UNDEF;
- options->comp.flags = COMP_F_MIGRATE;
+ alg = p[1];
+ }
- }
- else if (options->comp.flags & COMP_F_ALLOW_STUB_ONLY)
- {
- /* Also printed on a push to hint at configuration problems */
- msg(msglevel, "Cannot set compress to '%s', "
- "allow-compression is set to 'no'", p[1]);
- goto err;
- }
+ if (streq(alg, "stub"))
+ {
+ options->comp.alg = COMP_ALG_STUB;
+ options->comp.flags |= (COMP_F_SWAP|COMP_F_ADVERTISE_STUBS_ONLY);
+ }
+ else if (streq(alg, "stub-v2"))
+ {
+ options->comp.alg = COMP_ALGV2_UNCOMPRESSED;
+ options->comp.flags |= COMP_F_ADVERTISE_STUBS_ONLY;
+ }
+ else if (streq(alg, "migrate"))
+ {
+ options->comp.alg = COMP_ALG_UNDEF;
+ options->comp.flags = COMP_F_MIGRATE;
+
+ }
+ else if (options->comp.flags & COMP_F_ALLOW_STUB_ONLY)
+ {
+ /* Also printed on a push to hint at configuration problems */
+ msg(msglevel, "Cannot set compress to '%s', "
+ "allow-compression is set to 'no'", alg);
+ goto err;
+ }
#if defined(ENABLE_LZO)
- else if (streq(p[1], "lzo"))
- {
- options->comp.alg = COMP_ALG_LZO;
- options->comp.flags &= ~(COMP_F_ADAPTIVE | COMP_F_SWAP);
- }
+ else if (streq(alg, "lzo"))
+ {
+ options->comp.alg = COMP_ALG_LZO;
+ options->comp.flags &= ~(COMP_F_ADAPTIVE | COMP_F_SWAP);
+ }
#endif
#if defined(ENABLE_LZ4)
- else if (streq(p[1], "lz4"))
- {
- options->comp.alg = COMP_ALG_LZ4;
- options->comp.flags |= COMP_F_SWAP;
- }
- else if (streq(p[1], "lz4-v2"))
- {
- options->comp.alg = COMP_ALGV2_LZ4;
- }
-#endif
- else
- {
- msg(msglevel, "bad comp option: %s", p[1]);
- goto err;
- }
+ else if (streq(alg, "lz4"))
+ {
+ options->comp.alg = COMP_ALG_LZ4;
+ options->comp.flags |= COMP_F_SWAP;
+ }
+ else if (streq(alg, "lz4-v2"))
+ {
+ options->comp.alg = COMP_ALGV2_LZ4;
}
+#endif
else
{
- options->comp.alg = COMP_ALG_STUB;
- options->comp.flags |= COMP_F_SWAP;
+ msg(msglevel, "bad comp option: %s", alg);
+ goto err;
}
+
show_compression_warning(&options->comp);
}
#endif /* USE_COMP */