From: Jan Engelhardt <jengelh@medozas.de>
To: kaber@trash.net
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH 03/11] libxtables: XTTYPE_ETHERMAC support
Date: Wed, 11 May 2011 15:52:48 +0200 [thread overview]
Message-ID: <1305121977-4361-4-git-send-email-jengelh@medozas.de> (raw)
In-Reply-To: <1305121977-4361-1-git-send-email-jengelh@medozas.de>
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
---
include/xtables.h.in | 3 +++
xtoptions.c | 26 ++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/include/xtables.h.in b/include/xtables.h.in
index c3996a0..0fe4b90 100644
--- a/include/xtables.h.in
+++ b/include/xtables.h.in
@@ -70,6 +70,7 @@ struct in_addr;
* %XTTYPE_PORTRC_NE: same as %XTTYPE_PORTRC, stored in network-endian
* %XTTYPE_PLEN: prefix length
* %XTTYPE_PLENMASK: prefix length (ptr: union nf_inet_addr)
+ * %XTTYPE_ETHERMAC: Ethernet MAC address in hex form
*/
enum xt_option_type {
XTTYPE_NONE,
@@ -95,6 +96,7 @@ enum xt_option_type {
XTTYPE_PORTRC_NE,
XTTYPE_PLEN,
XTTYPE_PLENMASK,
+ XTTYPE_ETHERMAC,
};
/**
@@ -164,6 +166,7 @@ struct xt_option_call {
struct {
uint32_t mark, mask;
};
+ uint8_t ethermac[6];
} val;
/* Wished for a world where the ones below were gone: */
union {
diff --git a/xtoptions.c b/xtoptions.c
index 70370ed..8d54dd8 100644
--- a/xtoptions.c
+++ b/xtoptions.c
@@ -672,6 +672,30 @@ static void xtopt_parse_hostmask(struct xt_option_call *cb)
cb->arg = orig_arg;
}
+static void xtopt_parse_ethermac(struct xt_option_call *cb)
+{
+ const char *arg = cb->arg;
+ unsigned int i;
+ char *end;
+
+ for (i = 0; i < ARRAY_SIZE(cb->val.ethermac) - 1; ++i) {
+ cb->val.ethermac[i] = strtoul(arg, &end, 16);
+ if (cb->val.ethermac[i] > UINT8_MAX || *end != ':')
+ goto out;
+ arg = end + 1;
+ }
+ i = ARRAY_SIZE(cb->val.ethermac) - 1;
+ cb->val.ethermac[i] = strtoul(arg, &end, 16);
+ if (cb->val.ethermac[i] > UINT8_MAX || *end != '\0')
+ goto out;
+ if (cb->entry->flags & XTOPT_PUT)
+ memcpy(XTOPT_MKPTR(cb), cb->val.ethermac,
+ sizeof(cb->val.ethermac));
+ return;
+ out:
+ xt_params->exit_err(PARAMETER_PROBLEM, "ether");
+}
+
static void (*const xtopt_subparse[])(struct xt_option_call *) = {
[XTTYPE_UINT8] = xtopt_parse_int,
[XTTYPE_UINT16] = xtopt_parse_int,
@@ -695,6 +719,7 @@ static void (*const xtopt_subparse[])(struct xt_option_call *) = {
[XTTYPE_PORTRC_NE] = xtopt_parse_mport,
[XTTYPE_PLEN] = xtopt_parse_plen,
[XTTYPE_PLENMASK] = xtopt_parse_plenmask,
+ [XTTYPE_ETHERMAC] = xtopt_parse_ethermac,
};
static const size_t xtopt_psize[] = {
@@ -721,6 +746,7 @@ static const size_t xtopt_psize[] = {
[XTTYPE_PORTRC] = sizeof(uint16_t[2]),
[XTTYPE_PORTRC_NE] = sizeof(uint16_t[2]),
[XTTYPE_PLENMASK] = sizeof(union nf_inet_addr),
+ [XTTYPE_ETHERMAC] = sizeof(uint8_t[6]),
};
/**
--
1.7.1
next prev parent reply other threads:[~2011-05-11 15:48 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-11 13:52 guided option parser, run 7 Jan Engelhardt
2011-05-11 13:52 ` [PATCH 01/11] libip6t_mh: use guided option parser Jan Engelhardt
2011-05-11 13:52 ` [PATCH 02/11] libip6t_rt: " Jan Engelhardt
2011-05-11 13:52 ` Jan Engelhardt [this message]
2011-05-11 13:52 ` [PATCH 04/11] libxt_mac: " Jan Engelhardt
2011-05-11 13:52 ` [PATCH 05/11] libipt_CLUSTERIP: " Jan Engelhardt
2011-05-11 13:52 ` [PATCH 06/11] libxt_iprange: " Jan Engelhardt
2011-05-11 13:52 ` [PATCH 07/11] libipt_DNAT: " Jan Engelhardt
2011-05-18 13:58 ` Lutz Jaenicke
2011-05-18 14:00 ` Jan Engelhardt
2011-05-18 14:05 ` Lutz Jaenicke
2011-05-18 14:17 ` Jan Engelhardt
2011-05-11 13:52 ` [PATCH 08/11] libipt_SNAT: " Jan Engelhardt
2011-05-11 13:52 ` [PATCH 09/11] libipt_MASQUERADE: " Jan Engelhardt
2011-05-11 13:52 ` [PATCH 10/11] libipt_REDIRECT: " Jan Engelhardt
2011-05-11 13:52 ` [PATCH 11/11] libipt_SAME: " Jan Engelhardt
2011-05-12 9:14 ` guided option parser, run 7 Patrick McHardy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1305121977-4361-4-git-send-email-jengelh@medozas.de \
--to=jengelh@medozas.de \
--cc=kaber@trash.net \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).