Skip to content

Commit

Permalink
filter: add SKF_AD_RXHASH and SKF_AD_CPU
Browse files Browse the repository at this point in the history
Add SKF_AD_RXHASH and SKF_AD_CPU to filter ancillary mechanism,
to be able to build advanced filters.

This can help spreading packets on several sockets with a fast
selection, after RPS dispatch to N cpus for example, or to catch a
percentage of flows in one queue.

tcpdump -s 500 "cpu = 1" :

[0] ld CPU
[1] jeq #1  jt 2  jf 3
[2] ret #500
[3] ret #0

# take 12.5 % of flows (average)
tcpdump -s 1000 "rxhash & 7 = 2" :

[0] ld RXHASH
[1] and #7
[2] jeq #2  jt 3  jf 4
[3] ret #1000
[4] ret #0

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Rui <wirelesser@gmail.com>
Acked-by: Changli Gao <xiaosuo@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Dec 6, 2010
1 parent 539995d commit da2033c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/linux/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
#define SKF_AD_MARK 20
#define SKF_AD_QUEUE 24
#define SKF_AD_HATYPE 28
#define SKF_AD_MAX 32
#define SKF_AD_RXHASH 32
#define SKF_AD_CPU 36
#define SKF_AD_MAX 40
#define SKF_NET_OFF (-0x100000)
#define SKF_LL_OFF (-0x200000)

Expand Down
6 changes: 6 additions & 0 deletions net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ unsigned int sk_run_filter(struct sk_buff *skb, const struct sock_filter *fentry
return 0;
A = skb->dev->type;
continue;
case SKF_AD_RXHASH:
A = skb->rxhash;
continue;
case SKF_AD_CPU:
A = raw_smp_processor_id();
continue;
case SKF_AD_NLATTR: {
struct nlattr *nla;

Expand Down

0 comments on commit da2033c

Please sign in to comment.