Skip to content

Commit ad377ca

Browse files
wdebruijdavem330
authored andcommitted
packet: rollover prepare: move code out of callsites
packet_rcv_fanout calls fanout_demux_rollover twice. Move all rollover logic into the callee to simplify these callsites, especially with upcoming changes. The main differences between the two callsites is that the FLAG variant tests whether the socket previously selected by another mode (RR, RND, HASH, ..) has room before migrating flows, whereas the rollover mode has no original socket to test. Signed-off-by: Willem de Bruijn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7d771aa commit ad377ca

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

net/packet/af_packet.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,18 +1318,22 @@ static unsigned int fanout_demux_rnd(struct packet_fanout *f,
13181318

13191319
static unsigned int fanout_demux_rollover(struct packet_fanout *f,
13201320
struct sk_buff *skb,
1321-
unsigned int idx, unsigned int skip,
1321+
unsigned int idx, bool try_self,
13221322
unsigned int num)
13231323
{
13241324
unsigned int i, j;
13251325

1326+
if (try_self && packet_rcv_has_room(pkt_sk(f->arr[idx]), skb))
1327+
return idx;
1328+
13261329
i = j = min_t(int, f->next[idx], num - 1);
13271330
do {
1328-
if (i != skip && packet_rcv_has_room(pkt_sk(f->arr[i]), skb)) {
1331+
if (i != idx && packet_rcv_has_room(pkt_sk(f->arr[i]), skb)) {
13291332
if (i != j)
13301333
f->next[idx] = i;
13311334
return i;
13321335
}
1336+
13331337
if (++i == num)
13341338
i = 0;
13351339
} while (i != j);
@@ -1386,17 +1390,14 @@ static int packet_rcv_fanout(struct sk_buff *skb, struct net_device *dev,
13861390
idx = fanout_demux_qm(f, skb, num);
13871391
break;
13881392
case PACKET_FANOUT_ROLLOVER:
1389-
idx = fanout_demux_rollover(f, skb, 0, (unsigned int) -1, num);
1393+
idx = fanout_demux_rollover(f, skb, 0, false, num);
13901394
break;
13911395
}
13921396

1393-
po = pkt_sk(f->arr[idx]);
1394-
if (fanout_has_flag(f, PACKET_FANOUT_FLAG_ROLLOVER) &&
1395-
unlikely(!packet_rcv_has_room(po, skb))) {
1396-
idx = fanout_demux_rollover(f, skb, idx, idx, num);
1397-
po = pkt_sk(f->arr[idx]);
1398-
}
1397+
if (fanout_has_flag(f, PACKET_FANOUT_FLAG_ROLLOVER))
1398+
idx = fanout_demux_rollover(f, skb, idx, true, num);
13991399

1400+
po = pkt_sk(f->arr[idx]);
14001401
return po->prot_hook.func(skb, dev, &po->prot_hook, orig_dev);
14011402
}
14021403

0 commit comments

Comments
 (0)