netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] extensions: libxt_connlabel: Add translation to nft
@ 2016-03-05 21:47 Shivani Bhardwaj
  2016-03-06  0:07 ` Florian Westphal
  0 siblings, 1 reply; 8+ messages in thread
From: Shivani Bhardwaj @ 2016-03-05 21:47 UTC (permalink / raw)
  To: netfilter-devel

Add translation for connlabel to nftables.
Full translation for this match awaits the support for --set option.

Examples:

$ sudo iptables-translate -A INPUT -m connlabel --label eth0-in
nft add rule ip filter INPUT ct label eth0-in counter

$ sudo iptables-translate -A INPUT -m connlabel ! --label eth0-out
nft add rule ip filter INPUT ct label != eth0-out counter

Signed-off-by: Shivani Bhardwaj <shivanib134@gmail.com>
---
 extensions/libxt_connlabel.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/extensions/libxt_connlabel.c b/extensions/libxt_connlabel.c
index 1f83095..c3a96a6 100644
--- a/extensions/libxt_connlabel.c
+++ b/extensions/libxt_connlabel.c
@@ -118,6 +118,28 @@ connlabel_mt_save(const void *ip, const struct xt_entry_match *match)
 	connlabel_mt_print_op(info, "--");
 }
 
+static int
+connlabel_mt_xlate(const struct xt_entry_match *match,
+		   struct xt_xlate *xl, int numeric)
+{
+	const struct xt_connlabel_mtinfo *info = (const void *)match->data;
+	const char *name = connlabel_get_name(info->bit);
+
+	if (name)
+		xt_xlate_add(xl, "ct label %s%s ",
+			     info->options & XT_CONNLABEL_OP_INVERT ? "!= " : "",
+			     name);
+	else
+		xt_xlate_add(xl, "ct label %s%u ",
+			     info->options & XT_CONNLABEL_OP_INVERT ? "!= " : "",
+			     info->bit);
+
+	if (info->options & XT_CONNLABEL_OP_SET)
+		return 0;
+
+	return 1;
+}
+
 static struct xtables_match connlabel_mt_reg = {
 	.family        = NFPROTO_UNSPEC,
 	.name          = "connlabel",
@@ -129,6 +151,7 @@ static struct xtables_match connlabel_mt_reg = {
 	.save          = connlabel_mt_save,
 	.x6_parse      = connlabel_mt_parse,
 	.x6_options    = connlabel_mt_opts,
+	.xlate	       = connlabel_mt_xlate,
 };
 
 void _init(void)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] extensions: libxt_connlabel: Add translation to nft
  2016-03-05 21:47 [PATCH] extensions: libxt_connlabel: Add translation to nft Shivani Bhardwaj
@ 2016-03-06  0:07 ` Florian Westphal
  2016-03-07 13:05   ` Pablo Neira Ayuso
  0 siblings, 1 reply; 8+ messages in thread
From: Florian Westphal @ 2016-03-06  0:07 UTC (permalink / raw)
  To: Shivani Bhardwaj; +Cc: netfilter-devel

Shivani Bhardwaj <shivanib134@gmail.com> wrote:
> Add translation for connlabel to nftables.
> Full translation for this match awaits the support for --set option.

Hmm, I sent patches for that a while ago, don't know why they were
not applied... Pablo?

> Examples:
> 
> $ sudo iptables-translate -A INPUT -m connlabel --label eth0-in
> nft add rule ip filter INPUT ct label eth0-in counter

Looks good, thanks!

> $ sudo iptables-translate -A INPUT -m connlabel ! --label eth0-out
> nft add rule ip filter INPUT ct label != eth0-out counter

This one however is not correct.
It will match when eth0-out is not set, yes, but it will also match
if eth0-out and something else is also set.

(!= generates

[ cmp neq reg 1 0x00000004 0x00000000 0x00000000 0x00000000 ]

This should do the same thing as the -m connlabel ! --label ... command:

nft add rule ip filter INPUT ct label & eth0-in != eth0-in counter

[ ct load label => reg 1 ]
[ bitwise reg 1 = (reg=1 & 0x00000004 0x00000000 0x00000000 0x00000000 ) ^ 0x00000000 0x00000000 0x00000000 0x00000000 ]
[ cmp neq reg 1 0x00000004 0x00000000 0x00000000 0x00000000 ]

... so we load labels, then mask out everything except eth0-in, then
we check that this bit was not set.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] extensions: libxt_connlabel: Add translation to nft
  2016-03-06  0:07 ` Florian Westphal
@ 2016-03-07 13:05   ` Pablo Neira Ayuso
  2016-03-07 13:25     ` Shivani Bhardwaj
  0 siblings, 1 reply; 8+ messages in thread
From: Pablo Neira Ayuso @ 2016-03-07 13:05 UTC (permalink / raw)
  To: Florian Westphal; +Cc: Shivani Bhardwaj, netfilter-devel

On Sun, Mar 06, 2016 at 01:07:03AM +0100, Florian Westphal wrote:
> Shivani Bhardwaj <shivanib134@gmail.com> wrote:
> > Add translation for connlabel to nftables.
> > Full translation for this match awaits the support for --set option.
> 
> Hmm, I sent patches for that a while ago, don't know why they were
> not applied... Pablo?

Please, push the the connlabel support to nft.

We can probably introduce something like:

        ct connlabel bitset bar

instead of:

        ct connlabel set ct connlabel | bar

in a follow up patch, which looks more compact to me. We can accept
both syntax I'd say so we can introduce this without breaking
backward.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] extensions: libxt_connlabel: Add translation to nft
  2016-03-07 13:05   ` Pablo Neira Ayuso
@ 2016-03-07 13:25     ` Shivani Bhardwaj
  2016-03-07 13:30       ` Florian Westphal
  2016-03-07 13:32       ` Pablo Neira Ayuso
  0 siblings, 2 replies; 8+ messages in thread
From: Shivani Bhardwaj @ 2016-03-07 13:25 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: Florian Westphal, Netfilter Development Mailing list

On Mon, Mar 7, 2016 at 6:35 PM, Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Sun, Mar 06, 2016 at 01:07:03AM +0100, Florian Westphal wrote:
>> Shivani Bhardwaj <shivanib134@gmail.com> wrote:
>> > Add translation for connlabel to nftables.
>> > Full translation for this match awaits the support for --set option.
>>
>> Hmm, I sent patches for that a while ago, don't know why they were
>> not applied... Pablo?
>
> Please, push the the connlabel support to nft.
>
> We can probably introduce something like:
>
>         ct connlabel bitset bar
>
> instead of:
>
>         ct connlabel set ct connlabel | bar
>
> in a follow up patch, which looks more compact to me. We can accept
> both syntax I'd say so we can introduce this without breaking
> backward.

Should I be waiting for this or send a v2 with the existing options?
Please let me know.
Thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] extensions: libxt_connlabel: Add translation to nft
  2016-03-07 13:25     ` Shivani Bhardwaj
@ 2016-03-07 13:30       ` Florian Westphal
  2016-03-07 13:33         ` Pablo Neira Ayuso
  2016-03-07 13:32       ` Pablo Neira Ayuso
  1 sibling, 1 reply; 8+ messages in thread
From: Florian Westphal @ 2016-03-07 13:30 UTC (permalink / raw)
  To: Shivani Bhardwaj
  Cc: Pablo Neira Ayuso, Florian Westphal,
	Netfilter Development Mailing list

Shivani Bhardwaj <shivanib134@gmail.com> wrote:
> On Mon, Mar 7, 2016 at 6:35 PM, Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> > On Sun, Mar 06, 2016 at 01:07:03AM +0100, Florian Westphal wrote:
> >> Shivani Bhardwaj <shivanib134@gmail.com> wrote:
> >> > Add translation for connlabel to nftables.
> >> > Full translation for this match awaits the support for --set option.
> >>
> >> Hmm, I sent patches for that a while ago, don't know why they were
> >> not applied... Pablo?
> >
> > Please, push the the connlabel support to nft.
> >
> > We can probably introduce something like:
> >
> >         ct connlabel bitset bar
> >
> > instead of:
> >
> >         ct connlabel set ct connlabel | bar
> >
> > in a follow up patch, which looks more compact to me. We can accept
> > both syntax I'd say so we can introduce this without breaking
> > backward.
> 
> Should I be waiting for this or send a v2 with the existing options?
> Please let me know.

I'd suggest you just send a v2, lets handle translation of --set in
a followup change later.

I'm currently not at home but I plan to push set support this week.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] extensions: libxt_connlabel: Add translation to nft
  2016-03-07 13:25     ` Shivani Bhardwaj
  2016-03-07 13:30       ` Florian Westphal
@ 2016-03-07 13:32       ` Pablo Neira Ayuso
  2016-03-07 13:33         ` Shivani Bhardwaj
  1 sibling, 1 reply; 8+ messages in thread
From: Pablo Neira Ayuso @ 2016-03-07 13:32 UTC (permalink / raw)
  To: Shivani Bhardwaj; +Cc: Florian Westphal, Netfilter Development Mailing list

On Mon, Mar 07, 2016 at 06:55:31PM +0530, Shivani Bhardwaj wrote:
> On Mon, Mar 7, 2016 at 6:35 PM, Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> > On Sun, Mar 06, 2016 at 01:07:03AM +0100, Florian Westphal wrote:
> >> Shivani Bhardwaj <shivanib134@gmail.com> wrote:
> >> > Add translation for connlabel to nftables.
> >> > Full translation for this match awaits the support for --set option.
> >>
> >> Hmm, I sent patches for that a while ago, don't know why they were
> >> not applied... Pablo?
> >
> > Please, push the the connlabel support to nft.
> >
> > We can probably introduce something like:
> >
> >         ct connlabel bitset bar
> >
> > instead of:
> >
> >         ct connlabel set ct connlabel | bar
> >
> > in a follow up patch, which looks more compact to me. We can accept
> > both syntax I'd say so we can introduce this without breaking
> > backward.
> 
> Should I be waiting for this or send a v2 with the existing options?

The current translation seems fine (unless Florian indicates
otherwise). We can incrementally improve this.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] extensions: libxt_connlabel: Add translation to nft
  2016-03-07 13:30       ` Florian Westphal
@ 2016-03-07 13:33         ` Pablo Neira Ayuso
  0 siblings, 0 replies; 8+ messages in thread
From: Pablo Neira Ayuso @ 2016-03-07 13:33 UTC (permalink / raw)
  To: Florian Westphal; +Cc: Shivani Bhardwaj, Netfilter Development Mailing list

On Mon, Mar 07, 2016 at 02:30:04PM +0100, Florian Westphal wrote:
> Shivani Bhardwaj <shivanib134@gmail.com> wrote:
> > On Mon, Mar 7, 2016 at 6:35 PM, Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> > > On Sun, Mar 06, 2016 at 01:07:03AM +0100, Florian Westphal wrote:
> > >> Shivani Bhardwaj <shivanib134@gmail.com> wrote:
> > >> > Add translation for connlabel to nftables.
> > >> > Full translation for this match awaits the support for --set option.
> > >>
> > >> Hmm, I sent patches for that a while ago, don't know why they were
> > >> not applied... Pablo?
> > >
> > > Please, push the the connlabel support to nft.
> > >
> > > We can probably introduce something like:
> > >
> > >         ct connlabel bitset bar
> > >
> > > instead of:
> > >
> > >         ct connlabel set ct connlabel | bar
> > >
> > > in a follow up patch, which looks more compact to me. We can accept
> > > both syntax I'd say so we can introduce this without breaking
> > > backward.
> > 
> > Should I be waiting for this or send a v2 with the existing options?
> > Please let me know.
> 
> I'd suggest you just send a v2, lets handle translation of --set in
> a followup change later.
>
> I'm currently not at home but I plan to push set support this week.

OK; then please wait to send a v2 Shivani.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] extensions: libxt_connlabel: Add translation to nft
  2016-03-07 13:32       ` Pablo Neira Ayuso
@ 2016-03-07 13:33         ` Shivani Bhardwaj
  0 siblings, 0 replies; 8+ messages in thread
From: Shivani Bhardwaj @ 2016-03-07 13:33 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: Florian Westphal, Netfilter Development Mailing list

On Mon, Mar 7, 2016 at 7:02 PM, Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Mon, Mar 07, 2016 at 06:55:31PM +0530, Shivani Bhardwaj wrote:
>> On Mon, Mar 7, 2016 at 6:35 PM, Pablo Neira Ayuso <pablo@netfilter.org> wrote:
>> > On Sun, Mar 06, 2016 at 01:07:03AM +0100, Florian Westphal wrote:
>> >> Shivani Bhardwaj <shivanib134@gmail.com> wrote:
>> >> > Add translation for connlabel to nftables.
>> >> > Full translation for this match awaits the support for --set option.
>> >>
>> >> Hmm, I sent patches for that a while ago, don't know why they were
>> >> not applied... Pablo?
>> >
>> > Please, push the the connlabel support to nft.
>> >
>> > We can probably introduce something like:
>> >
>> >         ct connlabel bitset bar
>> >
>> > instead of:
>> >
>> >         ct connlabel set ct connlabel | bar
>> >
>> > in a follow up patch, which looks more compact to me. We can accept
>> > both syntax I'd say so we can introduce this without breaking
>> > backward.
>>
>> Should I be waiting for this or send a v2 with the existing options?
>
> The current translation seems fine (unless Florian indicates
> otherwise). We can incrementally improve this.

Yes, Florian pointed that the translation corresponding to inversion
is incorrect. So, I already need to fix that.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-03-07 13:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-05 21:47 [PATCH] extensions: libxt_connlabel: Add translation to nft Shivani Bhardwaj
2016-03-06  0:07 ` Florian Westphal
2016-03-07 13:05   ` Pablo Neira Ayuso
2016-03-07 13:25     ` Shivani Bhardwaj
2016-03-07 13:30       ` Florian Westphal
2016-03-07 13:33         ` Pablo Neira Ayuso
2016-03-07 13:32       ` Pablo Neira Ayuso
2016-03-07 13:33         ` Shivani Bhardwaj

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).