summaryrefslogtreecommitdiffstats
path: root/iptables/xshared.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2019-04-05 13:21:19 +0200
committerPhil Sutter <phil@nwl.cc>2021-11-23 15:01:23 +0100
commit1189d830ea4fd269da87761d400ebabca02e1ef3 (patch)
treeb7c6e734d3dfc43727b3ce589633d80c264e01b1 /iptables/xshared.c
parent1eab8e83aec0e6965f11f8cad460add1caeae629 (diff)
xshared: Merge and share parse_chain()
Have a common routine to perform chain name checks, combining all variants' requirements. Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'iptables/xshared.c')
-rw-r--r--iptables/xshared.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/iptables/xshared.c b/iptables/xshared.c
index 2d3ef679..bd545d6b 100644
--- a/iptables/xshared.c
+++ b/iptables/xshared.c
@@ -892,3 +892,27 @@ set_option(unsigned int *options, unsigned int option, u_int16_t *invflg,
*invflg |= inverse_for_options[i];
}
}
+
+void parse_chain(const char *chainname)
+{
+ const char *ptr;
+
+ if (strlen(chainname) >= XT_EXTENSION_MAXNAMELEN)
+ xtables_error(PARAMETER_PROBLEM,
+ "chain name `%s' too long (must be under %u chars)",
+ chainname, XT_EXTENSION_MAXNAMELEN);
+
+ if (*chainname == '-' || *chainname == '!')
+ xtables_error(PARAMETER_PROBLEM,
+ "chain name not allowed to start with `%c'\n",
+ *chainname);
+
+ if (xtables_find_target(chainname, XTF_TRY_LOAD))
+ xtables_error(PARAMETER_PROBLEM,
+ "chain name may not clash with target name\n");
+
+ for (ptr = chainname; *ptr; ptr++)
+ if (isspace(*ptr))
+ xtables_error(PARAMETER_PROBLEM,
+ "Invalid chain name `%s'", chainname);
+}