diff options
author | Florian Westphal <fw@strlen.de> | 2024-03-08 15:24:28 +0100 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2024-03-09 00:01:17 +0100 |
commit | a62fe15abcc997c38c3b46c5273961d3e9579293 (patch) | |
tree | a534c555f99064620b99b19537ee15cfa8b98e25 /extensions/libxt_TPROXY.c | |
parent | 494eae37f2690be4a86fd6516264979afbfe95ca (diff) |
extensions: xt_TPROXY: add txlate support
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'extensions/libxt_TPROXY.c')
-rw-r--r-- | extensions/libxt_TPROXY.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/extensions/libxt_TPROXY.c b/extensions/libxt_TPROXY.c index d13ec85f..ffc9da13 100644 --- a/extensions/libxt_TPROXY.c +++ b/extensions/libxt_TPROXY.c @@ -147,6 +147,62 @@ static void tproxy_tg1_parse(struct xt_option_call *cb) } } +static int tproxy_tg_xlate(struct xt_xlate *xl, + const struct xt_tproxy_target_info_v1 *info) +{ + int family = xt_xlate_get_family(xl); + uint32_t mask = info->mark_mask; + bool port_mandatory = false; + char buf[INET6_ADDRSTRLEN]; + + xt_xlate_add(xl, "tproxy to"); + + inet_ntop(family, &info->laddr, buf, sizeof(buf)); + + if (family == AF_INET6 && !IN6_IS_ADDR_UNSPECIFIED(&info->laddr.in6)) + xt_xlate_add(xl, "[%s]", buf); + else if (family == AF_INET && info->laddr.ip) + xt_xlate_add(xl, "%s", buf); + else + port_mandatory = true; + + if (port_mandatory) + xt_xlate_add(xl, " :%d", ntohs(info->lport)); + else if (info->lport) + xt_xlate_add(xl, ":%d", ntohs(info->lport)); + + /* xt_TPROXY.c does: skb->mark = (skb->mark & ~mark_mask) ^ mark_value */ + if (mask == 0xffffffff) + xt_xlate_add(xl, "meta mark set 0x%x", info->mark_value); + else if (mask || info->mark_value) + xt_xlate_add(xl, "meta mark set meta mark & 0x%x xor 0x%x", + ~mask, info->mark_value); + + return 1; +} + +static int tproxy_tg_xlate_v1(struct xt_xlate *xl, + const struct xt_xlate_tg_params *params) +{ + const struct xt_tproxy_target_info_v1 *data = (const void *)params->target->data; + + return tproxy_tg_xlate(xl, data); +} + +static int tproxy_tg_xlate_v0(struct xt_xlate *xl, + const struct xt_xlate_tg_params *params) +{ + const struct xt_tproxy_target_info *info = (const void *)params->target->data; + struct xt_tproxy_target_info_v1 t = { + .mark_mask = info->mark_mask, + .mark_value = info->mark_value, + .laddr.ip = info->laddr, + .lport = info->lport, + }; + + return tproxy_tg_xlate(xl, &t); +} + static struct xtables_target tproxy_tg_reg[] = { { .name = "TPROXY", @@ -160,6 +216,7 @@ static struct xtables_target tproxy_tg_reg[] = { .save = tproxy_tg_save, .x6_options = tproxy_tg0_opts, .x6_parse = tproxy_tg0_parse, + .xlate = tproxy_tg_xlate_v0, }, { .name = "TPROXY", @@ -173,6 +230,7 @@ static struct xtables_target tproxy_tg_reg[] = { .save = tproxy_tg_save4, .x6_options = tproxy_tg1_opts, .x6_parse = tproxy_tg1_parse, + .xlate = tproxy_tg_xlate_v1, }, { .name = "TPROXY", @@ -186,6 +244,7 @@ static struct xtables_target tproxy_tg_reg[] = { .save = tproxy_tg_save6, .x6_options = tproxy_tg1_opts, .x6_parse = tproxy_tg1_parse, + .xlate = tproxy_tg_xlate_v1, }, }; |