diff options
author | Willem de Bruijn <willemb@google.com> | 2015-05-12 18:56:46 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-05-13 22:42:59 +0300 |
commit | 0648ab70afe6c3bf2369a6d779b44a85121c063d (patch) | |
tree | d46581955bce49448791e1849ce7283f65917d33 /net/packet/af_packet.c | |
parent | ad377cab4966e2f9162f05be1f7eeae466d411a8 (diff) | |
download | linux-0648ab70afe6c3bf2369a6d779b44a85121c063d.tar.xz |
packet: rollover prepare: per-socket state
Replace rollover state per fanout group with state per socket. Future
patches will add fields to the new structure.
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 | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 5c88ecf22cc0..ad3d9ff56541 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -1321,16 +1321,18 @@ static unsigned int fanout_demux_rollover(struct packet_fanout *f, unsigned int idx, bool try_self, unsigned int num) { + struct packet_sock *po; unsigned int i, j; - if (try_self && packet_rcv_has_room(pkt_sk(f->arr[idx]), skb)) + po = pkt_sk(f->arr[idx]); + if (try_self && packet_rcv_has_room(po, skb)) return idx; - i = j = min_t(int, f->next[idx], num - 1); + i = j = min_t(int, po->rollover->sock, num - 1); do { if (i != idx && packet_rcv_has_room(pkt_sk(f->arr[i]), skb)) { if (i != j) - f->next[idx] = i; + po->rollover->sock = i; return i; } @@ -1468,6 +1470,12 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags) if (po->fanout) return -EALREADY; + if (type_flags & PACKET_FANOUT_FLAG_ROLLOVER) { + po->rollover = kzalloc(sizeof(*po->rollover), GFP_KERNEL); + if (!po->rollover) + return -ENOMEM; + } + mutex_lock(&fanout_mutex); match = NULL; list_for_each_entry(f, &fanout_list, list) { @@ -1516,6 +1524,10 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags) } out: mutex_unlock(&fanout_mutex); + if (err) { + kfree(po->rollover); + po->rollover = NULL; + } return err; } @@ -1537,6 +1549,8 @@ static void fanout_release(struct sock *sk) kfree(f); } mutex_unlock(&fanout_mutex); + + kfree(po->rollover); } static const struct proto_ops packet_ops; @@ -2866,6 +2880,7 @@ static int packet_create(struct net *net, struct socket *sock, int protocol, spin_lock_init(&po->bind_lock); mutex_init(&po->pg_vec_lock); + po->rollover = NULL; po->prot_hook.func = packet_rcv; if (sock->type == SOCK_PACKET) |