From: Paul Blakey <hidden> Date: 2016-12-28 13:06:55
Enhance flower to support matching on flags.
The 1st flag allows to match on whether the packet is
an IP fragment.
Example:
# add a flower filter that will drop fragmented packets
# (bit 0 of control flags)
tc filter add dev ens4f0 protocol ip parent ffff: \
flower \
src_mac e4:1d:2d:fd:8b:01 \
dst_mac e4:1d:2d:fd:8b:02 \
indev ens4f0 \
matching_flags 0x1/0x1 \
action drop
Signed-off-by: Paul Blakey <redacted>
Signed-off-by: Or Gerlitz <redacted>
Reviewed-by: Roi Dayan <redacted>
---
man/man8/tc-flower.8 | 11 +++++++++++
tc/f_flower.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 63 insertions(+), 1 deletion(-)
@@ -39,6 +39,8 @@ flower \- flow based traffic control filter .IRKEY-ID" | {" .BRenc_dst_ip" | "enc_src_ip" } { " .IRipv4_address" | "ipv6_address" } | "+.Bmatching_flags+.IRMATCHING-FLAGS" }" .SHDESCRIPTION The .Bflower
@@ -134,6 +136,15 @@ Match on IP tunnel metadata. Key id is a 32 bit tunnel key id (e.g. VNI for VXLAN tunnel). .IADDRESS must be a valid IPv4 or IPv6 address.+.TP+.BImatching_flags" MATCHING-FLAGS"+Match on various dissector flags.+.IMATCHING-FLAGS+may be specified with or without a mask:+.BRFLAGS+or+.BRFLAGS/FLAGS_MASK+where each arg is an unsigned 32bit value in hexadecimal format. .SHNOTES As stated above where applicable, matches of a certain layer implicitly depend on the matches of the next lower layer. Precisely, layer one and two matches
From: Stephen Hemminger <stephen@networkplumber.org> Date: 2016-12-29 18:43:55
On Wed, 28 Dec 2016 15:06:49 +0200
Paul Blakey [off-list ref] wrote:
Enhance flower to support matching on flags.
The 1st flag allows to match on whether the packet is
an IP fragment.
Example:
# add a flower filter that will drop fragmented packets
# (bit 0 of control flags)
tc filter add dev ens4f0 protocol ip parent ffff: \
flower \
src_mac e4:1d:2d:fd:8b:01 \
dst_mac e4:1d:2d:fd:8b:02 \
indev ens4f0 \
matching_flags 0x1/0x1 \
action drop
Signed-off-by: Paul Blakey <redacted>
Signed-off-by: Or Gerlitz <redacted>
Reviewed-by: Roi Dayan <redacted>
Applied. Had to manually fixup merge conflicts with other flower changes.
On Wed, 28 Dec 2016 15:06:49 +0200, Paul Blakey wrote:
Enhance flower to support matching on flags.
The 1st flag allows to match on whether the packet is
an IP fragment.
Example:
# add a flower filter that will drop fragmented packets
# (bit 0 of control flags)
tc filter add dev ens4f0 protocol ip parent ffff: \
flower \
src_mac e4:1d:2d:fd:8b:01 \
dst_mac e4:1d:2d:fd:8b:02 \
indev ens4f0 \
matching_flags 0x1/0x1 \
action drop
This is very poor API. First, how is the user supposed to know what
those magic values in "matching_flags" mean? At the very least, it
should be documented in the man page.
Second, why "matching_flags"? That name suggests that those modify the
way the matching is done (to illustrate my point, I'd expect things
like "if the packet is too short, match this rule anyway" to be a
"matching flag"). But this is not the case. What's wrong with plain
"flags"? Or, if you want to be more specific, perhaps packet_flags?
Third, all of this looks very wrong anyway. There should be separate
keywords for individual flags. In this case, there should be an
"ip_fragment" flag. The tc tool should be responsible for putting the
flags together and creating the appropriate mask. The example would
then be:
tc filter add dev ens4f0 protocol ip parent ffff: \
flower \
src_mac e4:1d:2d:fd:8b:01 \
dst_mac e4:1d:2d:fd:8b:02 \
indev ens4f0 \
ip_fragment yes\
action drop
I don't care whether it's "ip_fragment yes/no", "ip_fragment 1/0",
"ip_fragment/noip_fragment" or similar. The important thing is it's a
boolean flag; if specified, it's set to 0/1 and unmasked, if not
specified, it's wildcarded.
Stephen, I understand that you already applied this patch but given how
horrible the proposed API is and that's even undocumented in this
patch, please reconsider this. If this is released, the API is set in
stone and, frankly, it's very user unfriendly this way.
Paul, could you please prepare a patch that would introduce a more sane
API? I'd strongly prefer what I described under "third" but should you
strongly disagree, at least implement "second" and document the
currently known flag values.
Thanks,
Jiri
From: Paul Blakey <hidden> Date: 2017-01-03 11:54:43
On 02/01/2017 20:55, Jiri Benc wrote:
On Wed, 28 Dec 2016 15:06:49 +0200, Paul Blakey wrote:
quoted
Enhance flower to support matching on flags.
The 1st flag allows to match on whether the packet is
an IP fragment.
Example:
# add a flower filter that will drop fragmented packets
# (bit 0 of control flags)
tc filter add dev ens4f0 protocol ip parent ffff: \
flower \
src_mac e4:1d:2d:fd:8b:01 \
dst_mac e4:1d:2d:fd:8b:02 \
indev ens4f0 \
matching_flags 0x1/0x1 \
action drop
This is very poor API. First, how is the user supposed to know what
those magic values in "matching_flags" mean? At the very least, it
should be documented in the man page.
Second, why "matching_flags"? That name suggests that those modify the
way the matching is done (to illustrate my point, I'd expect things
like "if the packet is too short, match this rule anyway" to be a
"matching flag"). But this is not the case. What's wrong with plain
"flags"? Or, if you want to be more specific, perhaps packet_flags?
Third, all of this looks very wrong anyway. There should be separate
keywords for individual flags. In this case, there should be an
"ip_fragment" flag. The tc tool should be responsible for putting the
flags together and creating the appropriate mask. The example would
then be:
tc filter add dev ens4f0 protocol ip parent ffff: \
flower \
src_mac e4:1d:2d:fd:8b:01 \
dst_mac e4:1d:2d:fd:8b:02 \
indev ens4f0 \
ip_fragment yes\
action drop
I don't care whether it's "ip_fragment yes/no", "ip_fragment 1/0",
"ip_fragment/noip_fragment" or similar. The important thing is it's a
boolean flag; if specified, it's set to 0/1 and unmasked, if not
specified, it's wildcarded.
Stephen, I understand that you already applied this patch but given how
horrible the proposed API is and that's even undocumented in this
patch, please reconsider this. If this is released, the API is set in
stone and, frankly, it's very user unfriendly this way.
Paul, could you please prepare a patch that would introduce a more sane
API? I'd strongly prefer what I described under "third" but should you
strongly disagree, at least implement "second" and document the
currently known flag values.
Thanks,
Jiri
Matching name was from the idea that we are doing is matching.
And regarding documentation/flag names I didn't want tc tool to be need
of a update each time a new flag is introduced,
But I guess I can add two options like with ip_proto where you can
specify known flags by name but can also give a value.
What do you think about that?
flags <FLAGS> / <HEX'/'HEX>
FLAGS => frag/no_frag/tcp_syn/no_tcp_syn ['|'<FLAGS>]*
e.g: flags frag|no_tcp_syn or flags 0x01/0x15
and the mask will have a on bits corresponds only to those flags specified.
On Tue, 3 Jan 2017 13:54:34 +0200, Paul Blakey wrote:
Matching name was from the idea that we are doing is matching.
But we don't have matching_src_mac etc., either, although we're
matching on those fields.
And regarding documentation/flag names I didn't want tc tool to be need
of a update each time a new flag is introduced,
It will be needed anyway because the whole thing would be useless
without proper documentation. So each time a new flag is added, a new
patch to the tc tool will be needed, at least with an addition to its
man page.
Please, let's focus on the *user*. The tc tool is hard to grasp for
users as it is. It's crystal clear to you but you know the kernel
internals. I'm very sure that except for the few kernel developers, no
one would understand what the "flags" field does. And even among the
kernel developers, very few would remember what the magic numeric
values mean.
If we want wider adoption of flower, we should make it as easy to use
as possible. Even when it means a bit more work for us.
But I guess I can add two options like with ip_proto where you can
specify known flags by name but can also give a value.
What do you think about that?
flags <FLAGS> / <HEX'/'HEX>
FLAGS => frag/no_frag/tcp_syn/no_tcp_syn ['|'<FLAGS>]*
e.g: flags frag|no_tcp_syn or flags 0x01/0x15
and the mask will have a on bits corresponds only to those flags specified.
From: Simon Horman <hidden> Date: 2017-01-04 10:33:17
On Tue, Jan 03, 2017 at 01:54:34PM +0200, Paul Blakey wrote:
...
Hi Paul,
Matching name was from the idea that we are doing is matching.
And regarding documentation/flag names I didn't want tc tool to be need of a
update each time a new flag is introduced,
But I guess I can add two options like with ip_proto where you can specify
known flags by name but can also give a value.
What do you think about that?
flags <FLAGS> / <HEX'/'HEX>
FLAGS => frag/no_frag/tcp_syn/no_tcp_syn ['|'<FLAGS>]*
e.g: flags frag|no_tcp_syn or flags 0x01/0x15
and the mask will have a on bits corresponds only to those flags specified.
I suppose a flag is a flag and bitwise masking allows arbitrary matching
on one or more flags. But I wonder if, as per your example above,
it makes sense to mix IP (frag) and TCP flags in the same field of the
classifier.
From: Paul Blakey <hidden> Date: 2017-01-04 11:52:01
On 04/01/2017 12:33, Simon Horman wrote:
On Tue, Jan 03, 2017 at 01:54:34PM +0200, Paul Blakey wrote:
...
Hi Paul,
quoted
Matching name was from the idea that we are doing is matching.
And regarding documentation/flag names I didn't want tc tool to be need of a
update each time a new flag is introduced,
But I guess I can add two options like with ip_proto where you can specify
known flags by name but can also give a value.
What do you think about that?
flags <FLAGS> / <HEX'/'HEX>
FLAGS => frag/no_frag/tcp_syn/no_tcp_syn ['|'<FLAGS>]*
e.g: flags frag|no_tcp_syn or flags 0x01/0x15
and the mask will have a on bits corresponds only to those flags specified.
I suppose a flag is a flag and bitwise masking allows arbitrary matching
on one or more flags. But I wonder if, as per your example above,
it makes sense to mix IP (frag) and TCP flags in the same field of the
classifier.
It mimics the kernel packing of flags, I have no problem either way
(flags, or ip_flags/tcp_flags pairs), what do you think jiri?