Skip to content

Commit 0648ab7

Browse files
wdebruijdavem330
authored andcommitted
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ad377ca commit 0648ab7

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

net/packet/af_packet.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,16 +1321,18 @@ static unsigned int fanout_demux_rollover(struct packet_fanout *f,
13211321
unsigned int idx, bool try_self,
13221322
unsigned int num)
13231323
{
1324+
struct packet_sock *po;
13241325
unsigned int i, j;
13251326

1326-
if (try_self && packet_rcv_has_room(pkt_sk(f->arr[idx]), skb))
1327+
po = pkt_sk(f->arr[idx]);
1328+
if (try_self && packet_rcv_has_room(po, skb))
13271329
return idx;
13281330

1329-
i = j = min_t(int, f->next[idx], num - 1);
1331+
i = j = min_t(int, po->rollover->sock, num - 1);
13301332
do {
13311333
if (i != idx && packet_rcv_has_room(pkt_sk(f->arr[i]), skb)) {
13321334
if (i != j)
1333-
f->next[idx] = i;
1335+
po->rollover->sock = i;
13341336
return i;
13351337
}
13361338

@@ -1468,6 +1470,12 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
14681470
if (po->fanout)
14691471
return -EALREADY;
14701472

1473+
if (type_flags & PACKET_FANOUT_FLAG_ROLLOVER) {
1474+
po->rollover = kzalloc(sizeof(*po->rollover), GFP_KERNEL);
1475+
if (!po->rollover)
1476+
return -ENOMEM;
1477+
}
1478+
14711479
mutex_lock(&fanout_mutex);
14721480
match = NULL;
14731481
list_for_each_entry(f, &fanout_list, list) {
@@ -1516,6 +1524,10 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
15161524
}
15171525
out:
15181526
mutex_unlock(&fanout_mutex);
1527+
if (err) {
1528+
kfree(po->rollover);
1529+
po->rollover = NULL;
1530+
}
15191531
return err;
15201532
}
15211533

@@ -1537,6 +1549,8 @@ static void fanout_release(struct sock *sk)
15371549
kfree(f);
15381550
}
15391551
mutex_unlock(&fanout_mutex);
1552+
1553+
kfree(po->rollover);
15401554
}
15411555

15421556
static const struct proto_ops packet_ops;
@@ -2866,6 +2880,7 @@ static int packet_create(struct net *net, struct socket *sock, int protocol,
28662880

28672881
spin_lock_init(&po->bind_lock);
28682882
mutex_init(&po->pg_vec_lock);
2883+
po->rollover = NULL;
28692884
po->prot_hook.func = packet_rcv;
28702885

28712886
if (sock->type == SOCK_PACKET)

net/packet/internal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,15 @@ struct packet_fanout {
8282
atomic_t rr_cur;
8383
struct list_head list;
8484
struct sock *arr[PACKET_FANOUT_MAX];
85-
int next[PACKET_FANOUT_MAX];
8685
spinlock_t lock;
8786
atomic_t sk_ref;
8887
struct packet_type prot_hook ____cacheline_aligned_in_smp;
8988
};
9089

90+
struct packet_rollover {
91+
int sock;
92+
} ____cacheline_aligned_in_smp;
93+
9194
struct packet_sock {
9295
/* struct sock has to be the first member of packet_sock */
9396
struct sock sk;
@@ -104,6 +107,7 @@ struct packet_sock {
104107
has_vnet_hdr:1;
105108
int ifindex; /* bound device */
106109
__be16 num;
110+
struct packet_rollover *rollover;
107111
struct packet_mclist *mclist;
108112
atomic_t mapped;
109113
enum tpacket_versions tp_version;

0 commit comments

Comments
 (0)