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>
This commit is contained in:
Willem de Bruijn 2015-05-12 11:56:46 -04:00 committed by David S. Miller
parent ad377cab49
commit 0648ab70af
2 changed files with 23 additions and 4 deletions

View File

@ -1321,16 +1321,18 @@ static unsigned int fanout_demux_rollover(struct packet_fanout *f,
unsigned int idx, bool try_self, unsigned int idx, bool try_self,
unsigned int num) unsigned int num)
{ {
struct packet_sock *po;
unsigned int i, j; 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; return idx;
i = j = min_t(int, f->next[idx], num - 1); i = j = min_t(int, po->rollover->sock, num - 1);
do { do {
if (i != idx && 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) if (i != j)
f->next[idx] = i; po->rollover->sock = i;
return i; return i;
} }
@ -1468,6 +1470,12 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
if (po->fanout) if (po->fanout)
return -EALREADY; 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); mutex_lock(&fanout_mutex);
match = NULL; match = NULL;
list_for_each_entry(f, &fanout_list, list) { 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: out:
mutex_unlock(&fanout_mutex); mutex_unlock(&fanout_mutex);
if (err) {
kfree(po->rollover);
po->rollover = NULL;
}
return err; return err;
} }
@ -1537,6 +1549,8 @@ static void fanout_release(struct sock *sk)
kfree(f); kfree(f);
} }
mutex_unlock(&fanout_mutex); mutex_unlock(&fanout_mutex);
kfree(po->rollover);
} }
static const struct proto_ops packet_ops; 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); spin_lock_init(&po->bind_lock);
mutex_init(&po->pg_vec_lock); mutex_init(&po->pg_vec_lock);
po->rollover = NULL;
po->prot_hook.func = packet_rcv; po->prot_hook.func = packet_rcv;
if (sock->type == SOCK_PACKET) if (sock->type == SOCK_PACKET)

View File

@ -82,12 +82,15 @@ struct packet_fanout {
atomic_t rr_cur; atomic_t rr_cur;
struct list_head list; struct list_head list;
struct sock *arr[PACKET_FANOUT_MAX]; struct sock *arr[PACKET_FANOUT_MAX];
int next[PACKET_FANOUT_MAX];
spinlock_t lock; spinlock_t lock;
atomic_t sk_ref; atomic_t sk_ref;
struct packet_type prot_hook ____cacheline_aligned_in_smp; struct packet_type prot_hook ____cacheline_aligned_in_smp;
}; };
struct packet_rollover {
int sock;
} ____cacheline_aligned_in_smp;
struct packet_sock { struct packet_sock {
/* struct sock has to be the first member of packet_sock */ /* struct sock has to be the first member of packet_sock */
struct sock sk; struct sock sk;
@ -104,6 +107,7 @@ struct packet_sock {
has_vnet_hdr:1; has_vnet_hdr:1;
int ifindex; /* bound device */ int ifindex; /* bound device */
__be16 num; __be16 num;
struct packet_rollover *rollover;
struct packet_mclist *mclist; struct packet_mclist *mclist;
atomic_t mapped; atomic_t mapped;
enum tpacket_versions tp_version; enum tpacket_versions tp_version;