summaryrefslogtreecommitdiffstats
path: root/xtoptions.c
diff options
context:
space:
mode:
authorJan Engelhardt <jengelh@medozas.de>2011-05-07 12:56:39 +0200
committerJan Engelhardt <jengelh@medozas.de>2011-05-09 00:52:18 +0200
commit170cf49a630fd0d237818b537c01794dde00b07a (patch)
treed58add04cfebb184de35c75ad0ab22b5dba10f08 /xtoptions.c
parent0f77e2e40a498688f3d8f8a65bf74ce13db893b2 (diff)
libxtables: XTTYPE_PROTOCOL support
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
Diffstat (limited to 'xtoptions.c')
-rw-r--r--xtoptions.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/xtoptions.c b/xtoptions.c
index 413de1b8..70370edb 100644
--- a/xtoptions.c
+++ b/xtoptions.c
@@ -493,6 +493,29 @@ static int xtables_getportbyname(const char *name)
}
/**
+ * Validate and parse a protocol specification (number or name) by use of
+ * /etc/protocols and put the result into @cb->val.protocol.
+ */
+static void xtopt_parse_protocol(struct xt_option_call *cb)
+{
+ const struct protoent *entry;
+ unsigned int value = -1;
+
+ if (xtables_strtoui(cb->arg, NULL, &value, 0, UINT8_MAX)) {
+ cb->val.protocol = value;
+ return;
+ }
+ entry = getprotobyname(cb->arg);
+ if (entry == NULL)
+ xt_params->exit_err(PARAMETER_PROBLEM,
+ "Protocol \"%s\" does not resolve to anything.\n",
+ cb->arg);
+ cb->val.protocol = entry->p_proto;
+ if (cb->entry->flags & XTOPT_PUT)
+ *(uint8_t *)XTOPT_MKPTR(cb) = cb->val.protocol;
+}
+
+/**
* Validate and parse a port specification and put the result into
* @cb->val.port.
*/
@@ -665,6 +688,7 @@ static void (*const xtopt_subparse[])(struct xt_option_call *) = {
[XTTYPE_SYSLOGLEVEL] = xtopt_parse_sysloglevel,
[XTTYPE_HOST] = xtopt_parse_host,
[XTTYPE_HOSTMASK] = xtopt_parse_hostmask,
+ [XTTYPE_PROTOCOL] = xtopt_parse_protocol,
[XTTYPE_PORT] = xtopt_parse_port,
[XTTYPE_PORT_NE] = xtopt_parse_port,
[XTTYPE_PORTRC] = xtopt_parse_mport,
@@ -691,6 +715,7 @@ static const size_t xtopt_psize[] = {
[XTTYPE_SYSLOGLEVEL] = sizeof(uint8_t),
[XTTYPE_HOST] = sizeof(union nf_inet_addr),
[XTTYPE_HOSTMASK] = sizeof(union nf_inet_addr),
+ [XTTYPE_PROTOCOL] = sizeof(uint8_t),
[XTTYPE_PORT] = sizeof(uint16_t),
[XTTYPE_PORT_NE] = sizeof(uint16_t),
[XTTYPE_PORTRC] = sizeof(uint16_t[2]),