netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Florian Westphal <fw@strlen.de>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH xtables] extensions: xt_TPROXY: add txlate support
Date: Fri, 8 Mar 2024 12:57:35 +0100	[thread overview]
Message-ID: <Zer9L_EgbICxBu0m@orbyte.nwl.cc> (raw)
In-Reply-To: <20240307140531.9822-1-fw@strlen.de>

On Thu, Mar 07, 2024 at 03:05:28PM +0100, Florian Westphal wrote:
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
>  extensions/libxt_TPROXY.c      | 59 ++++++++++++++++++++++++++++++++++
>  extensions/libxt_TPROXY.txlate | 17 ++++++++++
>  2 files changed, 76 insertions(+)
>  create mode 100644 extensions/libxt_TPROXY.txlate
> 
> diff --git a/extensions/libxt_TPROXY.c b/extensions/libxt_TPROXY.c
> index d13ec85f92d0..4d2d7961ca2c 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);

Could you please add a testcase involving an IPv6 address? Just so we
exercise this code path.

> +	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 or 0x%x",
> +			     ~mask, info->mark_value);

Shouldn't this be 'xor' instead of 'or' in translated output? I wanted
to suggest "meta mark set meta mark and not <mask> xor <mark_value>",
but it seems nft supports only boolean negations.

Thanks, Phil

  reply	other threads:[~2024-03-08 11:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-07 14:05 [PATCH xtables] extensions: xt_TPROXY: add txlate support Florian Westphal
2024-03-08 11:57 ` Phil Sutter [this message]
2024-03-08 14:25   ` Florian Westphal

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=Zer9L_EgbICxBu0m@orbyte.nwl.cc \
    --to=phil@nwl.cc \
    --cc=fw@strlen.de \
    --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).