Skip to content

Commit bd687fe

Browse files
ecsvsimonwunderlich
authored andcommitted
batman-adv: use consume_skb for non-dropped packets
kfree_skb assumes that an skb is dropped after an failure and notes that. consume_skb should be used in non-failure situations. Such information is important for dropmonitor netlink which tells how many packets were dropped and where this drop happened. Signed-off-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
1 parent 3111bee commit bd687fe

6 files changed

Lines changed: 59 additions & 30 deletions

File tree

‎net/batman-adv/bat_iv_ogm.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
698698

699699
forw_packet_aggr->skb = netdev_alloc_skb_ip_align(NULL, skb_size);
700700
if (!forw_packet_aggr->skb) {
701-
batadv_forw_packet_free(forw_packet_aggr);
701+
batadv_forw_packet_free(forw_packet_aggr, true);
702702
return;
703703
}
704704

@@ -1611,7 +1611,7 @@ batadv_iv_ogm_process_per_outif(const struct sk_buff *skb, int ogm_offset,
16111611
if (hardif_neigh)
16121612
batadv_hardif_neigh_put(hardif_neigh);
16131613

1614-
kfree_skb(skb_priv);
1614+
consume_skb(skb_priv);
16151615
}
16161616

16171617
/**
@@ -1783,6 +1783,7 @@ static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work)
17831783
struct delayed_work *delayed_work;
17841784
struct batadv_forw_packet *forw_packet;
17851785
struct batadv_priv *bat_priv;
1786+
bool dropped = false;
17861787

17871788
delayed_work = to_delayed_work(work);
17881789
forw_packet = container_of(delayed_work, struct batadv_forw_packet,
@@ -1792,8 +1793,10 @@ static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work)
17921793
hlist_del(&forw_packet->list);
17931794
spin_unlock_bh(&bat_priv->forw_bat_list_lock);
17941795

1795-
if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING)
1796+
if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING) {
1797+
dropped = true;
17961798
goto out;
1799+
}
17971800

17981801
batadv_iv_ogm_emit(forw_packet);
17991802

@@ -1810,7 +1813,7 @@ static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work)
18101813
batadv_iv_ogm_schedule(forw_packet->if_incoming);
18111814

18121815
out:
1813-
batadv_forw_packet_free(forw_packet);
1816+
batadv_forw_packet_free(forw_packet, dropped);
18141817
}
18151818

18161819
static int batadv_iv_ogm_receive(struct sk_buff *skb,
@@ -1851,7 +1854,7 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb,
18511854
ogm_packet = (struct batadv_ogm_packet *)packet_pos;
18521855
}
18531856

1854-
kfree_skb(skb);
1857+
consume_skb(skb);
18551858
return NET_RX_SUCCESS;
18561859
}
18571860

‎net/batman-adv/fragmentation.c‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,23 @@
4242
/**
4343
* batadv_frag_clear_chain - delete entries in the fragment buffer chain
4444
* @head: head of chain with entries.
45+
* @dropped: whether the chain is cleared because all fragments are dropped
4546
*
4647
* Free fragments in the passed hlist. Should be called with appropriate lock.
4748
*/
48-
static void batadv_frag_clear_chain(struct hlist_head *head)
49+
static void batadv_frag_clear_chain(struct hlist_head *head, bool dropped)
4950
{
5051
struct batadv_frag_list_entry *entry;
5152
struct hlist_node *node;
5253

5354
hlist_for_each_entry_safe(entry, node, head, list) {
5455
hlist_del(&entry->list);
55-
kfree_skb(entry->skb);
56+
57+
if (dropped)
58+
kfree_skb(entry->skb);
59+
else
60+
consume_skb(entry->skb);
61+
5662
kfree(entry);
5763
}
5864
}
@@ -73,7 +79,7 @@ void batadv_frag_purge_orig(struct batadv_orig_node *orig_node,
7379
spin_lock_bh(&chain->lock);
7480

7581
if (!check_cb || check_cb(chain)) {
76-
batadv_frag_clear_chain(&chain->fragment_list);
82+
batadv_frag_clear_chain(&chain->fragment_list, true);
7783
chain->size = 0;
7884
}
7985

@@ -118,7 +124,7 @@ static bool batadv_frag_init_chain(struct batadv_frag_table_entry *chain,
118124
return false;
119125

120126
if (!hlist_empty(&chain->fragment_list))
121-
batadv_frag_clear_chain(&chain->fragment_list);
127+
batadv_frag_clear_chain(&chain->fragment_list, true);
122128

123129
chain->size = 0;
124130
chain->seqno = seqno;
@@ -220,7 +226,7 @@ static bool batadv_frag_insert_packet(struct batadv_orig_node *orig_node,
220226
* exceeds the maximum size of one merged packet. Don't allow
221227
* packets to have different total_size.
222228
*/
223-
batadv_frag_clear_chain(&chain->fragment_list);
229+
batadv_frag_clear_chain(&chain->fragment_list, true);
224230
chain->size = 0;
225231
} else if (ntohs(frag_packet->total_size) == chain->size) {
226232
/* All fragments received. Hand over chain to caller. */
@@ -254,6 +260,7 @@ batadv_frag_merge_packets(struct hlist_head *chain)
254260
struct batadv_frag_list_entry *entry;
255261
struct sk_buff *skb_out;
256262
int size, hdr_size = sizeof(struct batadv_frag_packet);
263+
bool dropped = false;
257264

258265
/* Remove first entry, as this is the destination for the rest of the
259266
* fragments.
@@ -270,6 +277,7 @@ batadv_frag_merge_packets(struct hlist_head *chain)
270277
if (pskb_expand_head(skb_out, 0, size - skb_out->len, GFP_ATOMIC) < 0) {
271278
kfree_skb(skb_out);
272279
skb_out = NULL;
280+
dropped = true;
273281
goto free;
274282
}
275283

@@ -291,7 +299,7 @@ batadv_frag_merge_packets(struct hlist_head *chain)
291299

292300
free:
293301
/* Locking is not needed, because 'chain' is not part of any orig. */
294-
batadv_frag_clear_chain(chain);
302+
batadv_frag_clear_chain(chain, dropped);
295303
return skb_out;
296304
}
297305

‎net/batman-adv/network-coding.c‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,16 @@ static void batadv_nc_path_put(struct batadv_nc_path *nc_path)
260260
/**
261261
* batadv_nc_packet_free - frees nc packet
262262
* @nc_packet: the nc packet to free
263+
* @dropped: whether the packet is freed because is is dropped
263264
*/
264-
static void batadv_nc_packet_free(struct batadv_nc_packet *nc_packet)
265+
static void batadv_nc_packet_free(struct batadv_nc_packet *nc_packet,
266+
bool dropped)
265267
{
266-
kfree_skb(nc_packet->skb);
268+
if (dropped)
269+
kfree_skb(nc_packet->skb);
270+
else
271+
consume_skb(nc_packet->skb);
272+
267273
batadv_nc_path_put(nc_packet->nc_path);
268274
kfree(nc_packet);
269275
}
@@ -576,7 +582,7 @@ static void batadv_nc_send_packet(struct batadv_nc_packet *nc_packet)
576582
{
577583
batadv_send_unicast_skb(nc_packet->skb, nc_packet->neigh_node);
578584
nc_packet->skb = NULL;
579-
batadv_nc_packet_free(nc_packet);
585+
batadv_nc_packet_free(nc_packet, false);
580586
}
581587

582588
/**
@@ -610,7 +616,7 @@ static bool batadv_nc_sniffed_purge(struct batadv_priv *bat_priv,
610616

611617
/* purge nc packet */
612618
list_del(&nc_packet->list);
613-
batadv_nc_packet_free(nc_packet);
619+
batadv_nc_packet_free(nc_packet, true);
614620

615621
res = true;
616622

@@ -1208,11 +1214,11 @@ static bool batadv_nc_code_packets(struct batadv_priv *bat_priv,
12081214
}
12091215

12101216
/* skb_src is now coded into skb_dest, so free it */
1211-
kfree_skb(skb_src);
1217+
consume_skb(skb_src);
12121218

12131219
/* avoid duplicate free of skb from nc_packet */
12141220
nc_packet->skb = NULL;
1215-
batadv_nc_packet_free(nc_packet);
1221+
batadv_nc_packet_free(nc_packet, false);
12161222

12171223
/* Send the coded packet and return true */
12181224
batadv_send_unicast_skb(skb_dest, first_dest);
@@ -1399,7 +1405,7 @@ static void batadv_nc_skb_store_before_coding(struct batadv_priv *bat_priv,
13991405
/* batadv_nc_skb_store_for_decoding() clones the skb, so we must free
14001406
* our ref
14011407
*/
1402-
kfree_skb(skb);
1408+
consume_skb(skb);
14031409
}
14041410

14051411
/**
@@ -1723,7 +1729,7 @@ batadv_nc_skb_decode_packet(struct batadv_priv *bat_priv, struct sk_buff *skb,
17231729
ether_addr_copy(unicast_packet->dest, orig_dest);
17241730
unicast_packet->ttvn = ttvn;
17251731

1726-
batadv_nc_packet_free(nc_packet);
1732+
batadv_nc_packet_free(nc_packet, false);
17271733
return unicast_packet;
17281734
}
17291735

@@ -1860,7 +1866,7 @@ static int batadv_nc_recv_coded_packet(struct sk_buff *skb,
18601866
return batadv_recv_unicast_packet(skb, recv_if);
18611867

18621868
free_nc_packet:
1863-
batadv_nc_packet_free(nc_packet);
1869+
batadv_nc_packet_free(nc_packet, true);
18641870
return NET_RX_DROP;
18651871
}
18661872

‎net/batman-adv/send.c‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,19 @@ int batadv_send_skb_via_gw(struct batadv_priv *bat_priv, struct sk_buff *skb,
451451
/**
452452
* batadv_forw_packet_free - free a forwarding packet
453453
* @forw_packet: The packet to free
454+
* @dropped: whether the packet is freed because is is dropped
454455
*
455456
* This frees a forwarding packet and releases any resources it might
456457
* have claimed.
457458
*/
458-
void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet)
459+
void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet,
460+
bool dropped)
459461
{
460-
kfree_skb(forw_packet->skb);
462+
if (dropped)
463+
kfree_skb(forw_packet->skb);
464+
else
465+
consume_skb(forw_packet->skb);
466+
461467
if (forw_packet->if_incoming)
462468
batadv_hardif_put(forw_packet->if_incoming);
463469
if (forw_packet->if_outgoing)
@@ -598,7 +604,7 @@ int batadv_add_bcast_packet_to_list(struct batadv_priv *bat_priv,
598604
return NETDEV_TX_OK;
599605

600606
err_packet_free:
601-
batadv_forw_packet_free(forw_packet);
607+
batadv_forw_packet_free(forw_packet, true);
602608
err:
603609
return NETDEV_TX_BUSY;
604610
}
@@ -613,6 +619,7 @@ static void batadv_send_outstanding_bcast_packet(struct work_struct *work)
613619
struct sk_buff *skb1;
614620
struct net_device *soft_iface;
615621
struct batadv_priv *bat_priv;
622+
bool dropped = false;
616623
u8 *neigh_addr;
617624
u8 *orig_neigh;
618625
int ret = 0;
@@ -627,11 +634,15 @@ static void batadv_send_outstanding_bcast_packet(struct work_struct *work)
627634
hlist_del(&forw_packet->list);
628635
spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
629636

630-
if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING)
637+
if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING) {
638+
dropped = true;
631639
goto out;
640+
}
632641

633-
if (batadv_dat_drop_broadcast_packet(bat_priv, forw_packet))
642+
if (batadv_dat_drop_broadcast_packet(bat_priv, forw_packet)) {
643+
dropped = true;
634644
goto out;
645+
}
635646

636647
bcast_packet = (struct batadv_bcast_packet *)forw_packet->skb->data;
637648

@@ -709,7 +720,7 @@ static void batadv_send_outstanding_bcast_packet(struct work_struct *work)
709720
}
710721

711722
out:
712-
batadv_forw_packet_free(forw_packet);
723+
batadv_forw_packet_free(forw_packet, dropped);
713724
}
714725

715726
void
@@ -750,7 +761,7 @@ batadv_purge_outstanding_packets(struct batadv_priv *bat_priv,
750761

751762
if (pending) {
752763
hlist_del(&forw_packet->list);
753-
batadv_forw_packet_free(forw_packet);
764+
batadv_forw_packet_free(forw_packet, true);
754765
}
755766
}
756767
spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
@@ -777,7 +788,7 @@ batadv_purge_outstanding_packets(struct batadv_priv *bat_priv,
777788

778789
if (pending) {
779790
hlist_del(&forw_packet->list);
780-
batadv_forw_packet_free(forw_packet);
791+
batadv_forw_packet_free(forw_packet, true);
781792
}
782793
}
783794
spin_unlock_bh(&bat_priv->forw_bat_list_lock);

‎net/batman-adv/send.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
struct sk_buff;
2929

30-
void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet);
30+
void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet,
31+
bool dropped);
3132
struct batadv_forw_packet *
3233
batadv_forw_packet_alloc(struct batadv_hard_iface *if_incoming,
3334
struct batadv_hard_iface *if_outgoing,

‎net/batman-adv/soft-interface.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
362362
/* a copy is stored in the bcast list, therefore removing
363363
* the original skb.
364364
*/
365-
kfree_skb(skb);
365+
consume_skb(skb);
366366

367367
/* unicast packet */
368368
} else {

0 commit comments

Comments
 (0)