Skip to content

Commit e5dfb81

Browse files
kaberdavem330
authored andcommitted
[NET_SCHED]: Add flow classifier
Add new "flow" classifier, which is meant to extend the SFQ hashing capabilities without hard-coding new hash functions and also allows deterministic mappings of keys to classes, replacing some out of tree iptables patches like IPCLASSIFY (maps IPs to classes), IPMARK (maps IPs to marks, with fw filters to classes), ... Some examples: - Classic SFQ hash: tc filter add ... flow hash \ keys src,dst,proto,proto-src,proto-dst divisor 1024 - Classic SFQ hash, but using information from conntrack to work properly in combination with NAT: tc filter add ... flow hash \ keys nfct-src,nfct-dst,proto,nfct-proto-src,nfct-proto-dst divisor 1024 - Map destination IPs of 192.168.0.0/24 to classids 1-257: tc filter add ... flow map \ key dst addend -192.168.0.0 divisor 256 - alternatively: tc filter add ... flow map \ key dst and 0xff - similar, but reverse ordered: tc filter add ... flow map \ key dst and 0xff xor 0xff Perturbation is currently not supported because we can't reliable kill the timer on destruction. Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 94de78d commit e5dfb81

File tree

4 files changed

+722
-0
lines changed

4 files changed

+722
-0
lines changed

include/linux/pkt_cls.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,56 @@ enum
328328

329329
#define TCA_TCINDEX_MAX (__TCA_TCINDEX_MAX - 1)
330330

331+
/* Flow filter */
332+
333+
enum
334+
{
335+
FLOW_KEY_SRC,
336+
FLOW_KEY_DST,
337+
FLOW_KEY_PROTO,
338+
FLOW_KEY_PROTO_SRC,
339+
FLOW_KEY_PROTO_DST,
340+
FLOW_KEY_IIF,
341+
FLOW_KEY_PRIORITY,
342+
FLOW_KEY_MARK,
343+
FLOW_KEY_NFCT,
344+
FLOW_KEY_NFCT_SRC,
345+
FLOW_KEY_NFCT_DST,
346+
FLOW_KEY_NFCT_PROTO_SRC,
347+
FLOW_KEY_NFCT_PROTO_DST,
348+
FLOW_KEY_RTCLASSID,
349+
FLOW_KEY_SKUID,
350+
FLOW_KEY_SKGID,
351+
__FLOW_KEY_MAX,
352+
};
353+
354+
#define FLOW_KEY_MAX (__FLOW_KEY_MAX - 1)
355+
356+
enum
357+
{
358+
FLOW_MODE_MAP,
359+
FLOW_MODE_HASH,
360+
};
361+
362+
enum
363+
{
364+
TCA_FLOW_UNSPEC,
365+
TCA_FLOW_KEYS,
366+
TCA_FLOW_MODE,
367+
TCA_FLOW_BASECLASS,
368+
TCA_FLOW_RSHIFT,
369+
TCA_FLOW_ADDEND,
370+
TCA_FLOW_MASK,
371+
TCA_FLOW_XOR,
372+
TCA_FLOW_DIVISOR,
373+
TCA_FLOW_ACT,
374+
TCA_FLOW_POLICE,
375+
TCA_FLOW_EMATCHES,
376+
__TCA_FLOW_MAX
377+
};
378+
379+
#define TCA_FLOW_MAX (__TCA_FLOW_MAX - 1)
380+
331381
/* Basic filter */
332382

333383
enum

net/sched/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,17 @@ config NET_CLS_RSVP6
307307
To compile this code as a module, choose M here: the
308308
module will be called cls_rsvp6.
309309

310+
config NET_CLS_FLOW
311+
tristate "Flow classifier"
312+
select NET_CLS
313+
---help---
314+
If you say Y here, you will be able to classify packets based on
315+
a configurable combination of packet keys. This is mostly useful
316+
in combination with SFQ.
317+
318+
To compile this code as a module, choose M here: the
319+
module will be called cls_flow.
320+
310321
config NET_EMATCH
311322
bool "Extended Matches"
312323
select NET_CLS

net/sched/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ obj-$(CONFIG_NET_CLS_RSVP) += cls_rsvp.o
3535
obj-$(CONFIG_NET_CLS_TCINDEX) += cls_tcindex.o
3636
obj-$(CONFIG_NET_CLS_RSVP6) += cls_rsvp6.o
3737
obj-$(CONFIG_NET_CLS_BASIC) += cls_basic.o
38+
obj-$(CONFIG_NET_CLS_FLOW) += cls_flow.o
3839
obj-$(CONFIG_NET_EMATCH) += ematch.o
3940
obj-$(CONFIG_NET_EMATCH_CMP) += em_cmp.o
4041
obj-$(CONFIG_NET_EMATCH_NBYTE) += em_nbyte.o

0 commit comments

Comments
 (0)