Linux Netfilter discussions
 help / color / mirror / Atom feed
* Traffic shaping with nftables maps and tc
@ 2017-11-02 20:34 Tomas Mudrunka
  2017-11-03  0:07 ` Tomas Mudrunka
  0 siblings, 1 reply; 6+ messages in thread
From: Tomas Mudrunka @ 2017-11-02 20:34 UTC (permalink / raw)
  To: netfilter

Hello,
i am thinking about improving the way we do bandwidth shaping (traffic 
control) in our network.

Currently we have like 80000 rules that do something like this:

iptables -A post_10_11_171_248_29 -d 10.11.171.249/32 -o vlan1100 -j 
CLASSIFY --set-class 0001:3065

And even when there is some level of optimalization using subchains, i 
guess that nftables can optimize this simply by internal hashing in 
named map (or dictionary - i did not get how these two are different).

I need to have $IP : $CLASS map like this:

10.11.171.247/32 : 0001:4095
10.11.171.248/32 : 0001:3065
10.11.171.249/32 : 0001:2023

And then simply classify the packets using single rule like this:

-d $IP -j CLASSIFY --set-class $CLASS

So i can later shape the classified packets using tc. (BTW i've heard 
that nft has something called "ingress hook" that could replace tc, so i 
could have everything configured thru nft, is that true?)

Is there way to do this in nftables?

-- 
S pozdravem
Best regards
      Tomáš Mudruňka - SPOJE.NET s.r.o.

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

* Re: Traffic shaping with nftables maps and tc
  2017-11-02 20:34 Traffic shaping with nftables maps and tc Tomas Mudrunka
@ 2017-11-03  0:07 ` Tomas Mudrunka
  2017-11-03 10:48   ` Arturo Borrero Gonzalez
  0 siblings, 1 reply; 6+ messages in thread
From: Tomas Mudrunka @ 2017-11-03  0:07 UTC (permalink / raw)
  To: netfilter

I've been doing some online research and done several experiments:

1.) This seems to load properly, but i have not checked if it sets the 
classid correctly:

table ip filter {
	chain input {
		type filter hook input priority 0; policy accept;
		meta priority set 1:3065
	}
}

however this is not really usefull as it does not do any real hashing / 
maping, so i can't just use it for lots of rules. So i tried to adapt it 
to use maps or dictionaries:

=======================================================

2.) This does not load:


table ip filter {
	map prometheus {
		type ipv4_addr : classid
		elements = {
			10.11.171.247 : "0001:4095",
			10.11.171.248 : "0001:3065",
			10.11.171.249 : "0001:2023"
		}
	}
}


test2.nft:3:34-40: Error: syntax error, unexpected classid, expecting 
string or dscp or ecn or mark
		type ipv4_addr : classid
                                  ^^^^^^^
test2.nft:2:13-22: Error: map definition does not specify key data type
	map prometheus {
             ^^^^^^^^^^

=======================================================

3.) This also does not load:

table ip filter {
	map prometheus {
		type ipv4_addr : verdict
		elements = {
			10.11.171.247 : meta priority set "0001:4095",
			10.11.171.248 : meta priority set "0001:3065",
			10.11.171.249 : meta priority set "0001:2023"
		}
	}
}



test2.nft:5:41-44: Error: syntax error, unexpected meta
			10.11.171.247 : meta priority set "0001:4095",
                                         ^^^^
test2.nft:6:25-37: Error: syntax error, unexpected string
			10.11.171.248 : meta priority set "0001:3065",
                         ^^^^^^^^^^^^^
test2.nft:7:25-37: Error: syntax error, unexpected string
			10.11.171.249 : meta priority set "0001:2023"
                         ^^^^^^^^^^^^^
test2.nft:10:1-1: Error: syntax error, unexpected '}'
}
^




It seems to me that maps are not generic enough to work with relatively 
new "meta priority set" feature.

Do you have any suggestions how to make this work?


-- 
S pozdravem
Best regards
      Tomáš Mudruňka - SPOJE.NET s.r.o.

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

* Re: Traffic shaping with nftables maps and tc
  2017-11-03  0:07 ` Tomas Mudrunka
@ 2017-11-03 10:48   ` Arturo Borrero Gonzalez
  2017-11-03 12:37     ` Tomas Mudrunka
  0 siblings, 1 reply; 6+ messages in thread
From: Arturo Borrero Gonzalez @ 2017-11-03 10:48 UTC (permalink / raw)
  To: Tomas Mudrunka; +Cc: Netfilter Users Mailing list

Try this:

meta priority set ip daddr map { 1.1.1.2 : 2:2222, 1.1.1.3 : 3:3333 }

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

* Re: Traffic shaping with nftables maps and tc
  2017-11-03 10:48   ` Arturo Borrero Gonzalez
@ 2017-11-03 12:37     ` Tomas Mudrunka
  2017-11-03 16:01       ` Arturo Borrero Gonzalez
  0 siblings, 1 reply; 6+ messages in thread
From: Tomas Mudrunka @ 2017-11-03 12:37 UTC (permalink / raw)
  To: Netfilter Users Mailing list

> Try this:
> meta priority set ip daddr map { 1.1.1.2 : 2:2222, 1.1.1.3 : 3:3333 }

Thank you, that looks promising. However is there way to name this map, 
so i can dynamicaly edit it? I've checked nft describe:

$ nft describe ip daddr
payload expression, datatype ipv4_addr (IPv4 address) (basetype 
integer), 32 bits

$ nft describe meta priority
meta expression, datatype classid (TC classid) (basetype integer), 32 
bits

But then later "classid" seems to fail when name defining table:

#  nft add map filter deucalion { type ipv4_addr : classid\; }
<cmdline>:1:45-51: Error: syntax error, unexpected classid, expecting 
string or dscp or ecn or mark
add map filter deucalion { type ipv4_addr : classid; }
                                             ^^^^^^^
<cmdline>:1:26-52: Error: map definition does not specify key data type
add map filter deucalion { type ipv4_addr : classid; }
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Same goes for this:

	map deucalion {
		type ipv4_addr : classid;
		elements = { 1.1.1.2 : 2:2222, 1.1.1.3 : 3:3333 }
	}


	chain input {
		type filter hook input priority 0; policy accept;
		meta priority set ip daddr map @deucalion;
	}


-- 
S pozdravem
Best regards
      Tomáš Mudruňka - SPOJE.NET s.r.o.

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

* Re: Traffic shaping with nftables maps and tc
  2017-11-03 12:37     ` Tomas Mudrunka
@ 2017-11-03 16:01       ` Arturo Borrero Gonzalez
  2017-11-03 16:28         ` Tomas Mudrunka
  0 siblings, 1 reply; 6+ messages in thread
From: Arturo Borrero Gonzalez @ 2017-11-03 16:01 UTC (permalink / raw)
  To: Tomas Mudrunka; +Cc: Netfilter Users Mailing list

[-- Attachment #1: Type: text/plain, Size: 483 bytes --]

On 3 November 2017 at 13:37, Tomas Mudrunka <mudrunka@spoje.net> wrote:
>> Try this:
>> meta priority set ip daddr map { 1.1.1.2 : 2:2222, 1.1.1.3 : 3:3333 }
>
>
> Thank you, that looks promising. However is there way to name this map, so i
> can dynamicaly edit it? I've checked nft describe:

It seems there is some issue with the parser.

Could you please test the attached patch? It is quick and dirty, not
even compiled tested.
Hope there aren't shift/reduce errors from bison.

[-- Attachment #2: x.patch --]
[-- Type: text/x-patch, Size: 670 bytes --]

parser: allow classid as set key

From: Arturo Borrero Gonzalez <arturo@netfilter.org>

Allow TC classid as set key.

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
---
 src/parser_bison.y |    1 +
 1 file changed, 1 insertion(+)

diff --git a/src/parser_bison.y b/src/parser_bison.y
index 7016f5b..2918875 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -1545,6 +1545,7 @@ type_identifier		:	STRING	{ $$ = $1; }
 			|	MARK	{ $$ = xstrdup("mark"); }
 			|	DSCP	{ $$ = xstrdup("dscp"); }
 			|	ECN	{ $$ = xstrdup("ecn"); }
+			|	CLASSID { $$ = xstrdup("classid"); }
 			;
 
 hook_spec		:	TYPE		STRING		HOOK		STRING		dev_spec	PRIORITY	prio_spec

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

* Re: Traffic shaping with nftables maps and tc
  2017-11-03 16:01       ` Arturo Borrero Gonzalez
@ 2017-11-03 16:28         ` Tomas Mudrunka
  0 siblings, 0 replies; 6+ messages in thread
From: Tomas Mudrunka @ 2017-11-03 16:28 UTC (permalink / raw)
  To: netfilter

> Could you please test the attached patch? It is quick and dirty, not
> even compiled tested.

Hell yeah! It loaded :-) Thank you.
That's one small line for a bison, one giant leap for traffic shaping on 
nftables.


> +++ b/src/parser_bison.y
> @@ -1545,6 +1545,7 @@ type_identifier		:	STRING	{ $$ = $1; }
>  			|	MARK	{ $$ = xstrdup("mark"); }
>  			|	DSCP	{ $$ = xstrdup("dscp"); }
>  			|	ECN	{ $$ = xstrdup("ecn"); }
> +			|	CLASSID { $$ = xstrdup("classid"); }
> 			;
> 

-- 
S pozdravem
Best regards
      Tomáš Mudruňka - SPOJE.NET s.r.o.

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

end of thread, other threads:[~2017-11-03 16:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-02 20:34 Traffic shaping with nftables maps and tc Tomas Mudrunka
2017-11-03  0:07 ` Tomas Mudrunka
2017-11-03 10:48   ` Arturo Borrero Gonzalez
2017-11-03 12:37     ` Tomas Mudrunka
2017-11-03 16:01       ` Arturo Borrero Gonzalez
2017-11-03 16:28         ` Tomas Mudrunka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox