Skip to content

Commit 2d36097

Browse files
nhormandavem330
authored andcommitted
af_packet: Add Queue mapping mode to af_packet fanout operation
This patch adds a queue mapping mode to the fanout operation of af_packet sockets. This allows user space af_packet users to better filter on flows ingressing and egressing via a specific hardware queue, and avoids the potential packet reordering that can occur when FANOUT_CPU is being used and irq affinity varies. Tested successfully by myself. applies to net-next Signed-off-by: Neil Horman <nhorman@tuxdriver.com> CC: "David S. Miller" <davem@davemloft.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b414ac9 commit 2d36097

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎include/uapi/linux/if_packet.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct sockaddr_ll {
6060
#define PACKET_FANOUT_CPU 2
6161
#define PACKET_FANOUT_ROLLOVER 3
6262
#define PACKET_FANOUT_RND 4
63+
#define PACKET_FANOUT_QM 5
6364
#define PACKET_FANOUT_FLAG_ROLLOVER 0x1000
6465
#define PACKET_FANOUT_FLAG_DEFRAG 0x8000
6566

‎net/packet/af_packet.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,13 @@ static unsigned int fanout_demux_rollover(struct packet_fanout *f,
13121312
return idx;
13131313
}
13141314

1315+
static unsigned int fanout_demux_qm(struct packet_fanout *f,
1316+
struct sk_buff *skb,
1317+
unsigned int num)
1318+
{
1319+
return skb_get_queue_mapping(skb) % num;
1320+
}
1321+
13151322
static bool fanout_has_flag(struct packet_fanout *f, u16 flag)
13161323
{
13171324
return f->flags & (flag >> 8);
@@ -1351,6 +1358,9 @@ static int packet_rcv_fanout(struct sk_buff *skb, struct net_device *dev,
13511358
case PACKET_FANOUT_RND:
13521359
idx = fanout_demux_rnd(f, skb, num);
13531360
break;
1361+
case PACKET_FANOUT_QM:
1362+
idx = fanout_demux_qm(f, skb, num);
1363+
break;
13541364
case PACKET_FANOUT_ROLLOVER:
13551365
idx = fanout_demux_rollover(f, skb, 0, (unsigned int) -1, num);
13561366
break;
@@ -1421,6 +1431,7 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
14211431
case PACKET_FANOUT_LB:
14221432
case PACKET_FANOUT_CPU:
14231433
case PACKET_FANOUT_RND:
1434+
case PACKET_FANOUT_QM:
14241435
break;
14251436
default:
14261437
return -EINVAL;

0 commit comments

Comments
 (0)