diff options
author | Willem de Bruijn <willemb@google.com> | 2015-05-12 11:56:45 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-05-13 15:42:59 -0400 |
commit | ad377cab4966e2f9162f05be1f7eeae466d411a8 (patch) | |
tree | a6ff169cd641b60acbb5099e54b632de3e751479 /net/packet/af_packet.c | |
parent | 7d771aaac7b2459013e9a246f16c06d4f2b819e1 (diff) |
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 <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/packet/af_packet.c')
-rw-r--r-- | net/packet/af_packet.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 12c5dde8e344..5c88ecf22cc0 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -1318,18 +1318,22 @@ static unsigned int fanout_demux_rnd(struct packet_fanout *f, static unsigned int fanout_demux_rollover(struct packet_fanout *f, struct sk_buff *skb, - unsigned int idx, unsigned int skip, + unsigned int idx, bool try_self, unsigned int num) { unsigned int i, j; + if (try_self && packet_rcv_has_room(pkt_sk(f->arr[idx]), skb)) + return idx; + i = j = min_t(int, f->next[idx], num - 1); do { - if (i != skip && packet_rcv_has_room(pkt_sk(f->arr[i]), skb)) { + if (i != idx && packet_rcv_has_room(pkt_sk(f->arr[i]), skb)) { if (i != j) f->next[idx] = i; return i; } + if (++i == num) i = 0; } while (i != j); @@ -1386,17 +1390,14 @@ static int packet_rcv_fanout(struct sk_buff *skb, struct net_device *dev, idx = fanout_demux_qm(f, skb, num); break; case PACKET_FANOUT_ROLLOVER: - idx = fanout_demux_rollover(f, skb, 0, (unsigned int) -1, num); + idx = fanout_demux_rollover(f, skb, 0, false, num); break; } - po = pkt_sk(f->arr[idx]); - if (fanout_has_flag(f, PACKET_FANOUT_FLAG_ROLLOVER) && - unlikely(!packet_rcv_has_room(po, skb))) { - idx = fanout_demux_rollover(f, skb, idx, idx, num); - po = pkt_sk(f->arr[idx]); - } + if (fanout_has_flag(f, PACKET_FANOUT_FLAG_ROLLOVER)) + idx = fanout_demux_rollover(f, skb, idx, true, num); + po = pkt_sk(f->arr[idx]); return po->prot_hook.func(skb, dev, &po->prot_hook, orig_dev); } |