@@ -1321,16 +1321,18 @@ static unsigned int fanout_demux_rollover(struct packet_fanout *f,
1321
1321
unsigned int idx , bool try_self ,
1322
1322
unsigned int num )
1323
1323
{
1324
+ struct packet_sock * po ;
1324
1325
unsigned int i , j ;
1325
1326
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 ))
1327
1329
return idx ;
1328
1330
1329
- i = j = min_t (int , f -> next [ idx ] , num - 1 );
1331
+ i = j = min_t (int , po -> rollover -> sock , num - 1 );
1330
1332
do {
1331
1333
if (i != idx && packet_rcv_has_room (pkt_sk (f -> arr [i ]), skb )) {
1332
1334
if (i != j )
1333
- f -> next [ idx ] = i ;
1335
+ po -> rollover -> sock = i ;
1334
1336
return i ;
1335
1337
}
1336
1338
@@ -1468,6 +1470,12 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
1468
1470
if (po -> fanout )
1469
1471
return - EALREADY ;
1470
1472
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
+
1471
1479
mutex_lock (& fanout_mutex );
1472
1480
match = NULL ;
1473
1481
list_for_each_entry (f , & fanout_list , list ) {
@@ -1516,6 +1524,10 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
1516
1524
}
1517
1525
out :
1518
1526
mutex_unlock (& fanout_mutex );
1527
+ if (err ) {
1528
+ kfree (po -> rollover );
1529
+ po -> rollover = NULL ;
1530
+ }
1519
1531
return err ;
1520
1532
}
1521
1533
@@ -1537,6 +1549,8 @@ static void fanout_release(struct sock *sk)
1537
1549
kfree (f );
1538
1550
}
1539
1551
mutex_unlock (& fanout_mutex );
1552
+
1553
+ kfree (po -> rollover );
1540
1554
}
1541
1555
1542
1556
static const struct proto_ops packet_ops ;
@@ -2866,6 +2880,7 @@ static int packet_create(struct net *net, struct socket *sock, int protocol,
2866
2880
2867
2881
spin_lock_init (& po -> bind_lock );
2868
2882
mutex_init (& po -> pg_vec_lock );
2883
+ po -> rollover = NULL ;
2869
2884
po -> prot_hook .func = packet_rcv ;
2870
2885
2871
2886
if (sock -> type == SOCK_PACKET )
0 commit comments