diff options
author | Florian Westphal <fw@strlen.de> | 2023-11-07 12:15:38 +0100 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2023-11-07 23:40:14 +0100 |
commit | 5b7324e0675e332ae186e1bd6978aa320f628086 (patch) | |
tree | e258f128ccfe5637759cbce7031b6c491f8492f1 /extensions/libarpt_mangle.c | |
parent | ab2d5f8c7bbeea49d9dddaaf3d2fac8c7fdeae56 (diff) |
nft-arp: add arptables-translate
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'extensions/libarpt_mangle.c')
-rw-r--r-- | extensions/libarpt_mangle.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/extensions/libarpt_mangle.c b/extensions/libarpt_mangle.c index a846e97e..364c9ce7 100644 --- a/extensions/libarpt_mangle.c +++ b/extensions/libarpt_mangle.c @@ -170,6 +170,52 @@ static void arpmangle_save(const void *ip, const struct xt_entry_target *target) arpmangle_print(ip, target, 0); } +static void print_devaddr_xlate(const char *macaddress, struct xt_xlate *xl) +{ + unsigned int i; + + xt_xlate_add(xl, "%02x", macaddress[0]); + for (i = 1; i < ETH_ALEN; ++i) + xt_xlate_add(xl, ":%02x", macaddress[i]); +} + +static int arpmangle_xlate(struct xt_xlate *xl, + const struct xt_xlate_tg_params *params) +{ + const struct arpt_mangle *m = (const void *)params->target->data; + + if (m->flags & ARPT_MANGLE_SIP) + xt_xlate_add(xl, "arp saddr ip set %s ", + xtables_ipaddr_to_numeric(&m->u_s.src_ip)); + + if (m->flags & ARPT_MANGLE_SDEV) { + xt_xlate_add(xl, "arp %caddr ether set ", 's'); + print_devaddr_xlate(m->src_devaddr, xl); + } + + if (m->flags & ARPT_MANGLE_TIP) + xt_xlate_add(xl, "arp daddr ip set %s ", + xtables_ipaddr_to_numeric(&m->u_t.tgt_ip)); + + if (m->flags & ARPT_MANGLE_TDEV) { + xt_xlate_add(xl, "arp %caddr ether set ", 'd'); + print_devaddr_xlate(m->tgt_devaddr, xl); + } + + switch (m->target) { + case NF_ACCEPT: + xt_xlate_add(xl, "accept"); + break; + case NF_DROP: + xt_xlate_add(xl, "drop"); + break; + default: + break; + } + + return 1; +} + static struct xtables_target arpmangle_target = { .name = "mangle", .revision = 0, @@ -184,6 +230,7 @@ static struct xtables_target arpmangle_target = { .print = arpmangle_print, .save = arpmangle_save, .extra_opts = arpmangle_opts, + .xlate = arpmangle_xlate, }; void _init(void) |