Skip to content

Commit 5df0ddf

Browse files
Daniel Borkmanndavem330
authored andcommitted
net: packet: add randomized fanout scheduler
We currently allow for different fanout scheduling policies in pf_packet such as scheduling by skb's rxhash, round-robin, by cpu, and rollover. Also allow for a random, equidistributed selection of the socket from the fanout process group. Signed-off-by: Daniel Borkmann <dborkman@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4885948 commit 5df0ddf

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

include/uapi/linux/if_packet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct sockaddr_ll {
5656
#define PACKET_FANOUT_LB 1
5757
#define PACKET_FANOUT_CPU 2
5858
#define PACKET_FANOUT_ROLLOVER 3
59+
#define PACKET_FANOUT_RND 4
5960
#define PACKET_FANOUT_FLAG_ROLLOVER 0x1000
6061
#define PACKET_FANOUT_FLAG_DEFRAG 0x8000
6162

net/packet/af_packet.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
#include <linux/virtio_net.h>
8989
#include <linux/errqueue.h>
9090
#include <linux/net_tstamp.h>
91-
91+
#include <linux/reciprocal_div.h>
9292
#ifdef CONFIG_INET
9393
#include <net/inet_common.h>
9494
#endif
@@ -1158,6 +1158,13 @@ static unsigned int fanout_demux_cpu(struct packet_fanout *f,
11581158
return smp_processor_id() % num;
11591159
}
11601160

1161+
static unsigned int fanout_demux_rnd(struct packet_fanout *f,
1162+
struct sk_buff *skb,
1163+
unsigned int num)
1164+
{
1165+
return reciprocal_divide(prandom_u32(), num);
1166+
}
1167+
11611168
static unsigned int fanout_demux_rollover(struct packet_fanout *f,
11621169
struct sk_buff *skb,
11631170
unsigned int idx, unsigned int skip,
@@ -1215,6 +1222,9 @@ static int packet_rcv_fanout(struct sk_buff *skb, struct net_device *dev,
12151222
case PACKET_FANOUT_CPU:
12161223
idx = fanout_demux_cpu(f, skb, num);
12171224
break;
1225+
case PACKET_FANOUT_RND:
1226+
idx = fanout_demux_rnd(f, skb, num);
1227+
break;
12181228
case PACKET_FANOUT_ROLLOVER:
12191229
idx = fanout_demux_rollover(f, skb, 0, (unsigned int) -1, num);
12201230
break;
@@ -1284,6 +1294,7 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
12841294
case PACKET_FANOUT_HASH:
12851295
case PACKET_FANOUT_LB:
12861296
case PACKET_FANOUT_CPU:
1297+
case PACKET_FANOUT_RND:
12871298
break;
12881299
default:
12891300
return -EINVAL;

0 commit comments

Comments
 (0)