@@ -93,7 +93,14 @@ static int batadv_interface_release(struct net_device *dev)
93
93
static struct net_device_stats * batadv_interface_stats (struct net_device * dev )
94
94
{
95
95
struct batadv_priv * bat_priv = netdev_priv (dev );
96
- return & bat_priv -> stats ;
96
+ struct net_device_stats * stats = & bat_priv -> stats ;
97
+
98
+ stats -> tx_packets = batadv_sum_counter (bat_priv , BATADV_CNT_TX );
99
+ stats -> tx_bytes = batadv_sum_counter (bat_priv , BATADV_CNT_TX_BYTES );
100
+ stats -> tx_dropped = batadv_sum_counter (bat_priv , BATADV_CNT_TX_DROPPED );
101
+ stats -> rx_packets = batadv_sum_counter (bat_priv , BATADV_CNT_RX );
102
+ stats -> rx_bytes = batadv_sum_counter (bat_priv , BATADV_CNT_RX_BYTES );
103
+ return stats ;
97
104
}
98
105
99
106
static int batadv_interface_set_mac_addr (struct net_device * dev , void * p )
@@ -246,14 +253,14 @@ static int batadv_interface_tx(struct sk_buff *skb,
246
253
goto dropped_freed ;
247
254
}
248
255
249
- bat_priv -> stats . tx_packets ++ ;
250
- bat_priv -> stats . tx_bytes += data_len ;
256
+ batadv_inc_counter ( bat_priv , BATADV_CNT_TX ) ;
257
+ batadv_add_counter ( bat_priv , BATADV_CNT_TX_BYTES , data_len ) ;
251
258
goto end ;
252
259
253
260
dropped :
254
261
kfree_skb (skb );
255
262
dropped_freed :
256
- bat_priv -> stats . tx_dropped ++ ;
263
+ batadv_inc_counter ( bat_priv , BATADV_CNT_TX_DROPPED ) ;
257
264
end :
258
265
if (primary_if )
259
266
batadv_hardif_free_ref (primary_if );
@@ -308,8 +315,9 @@ void batadv_interface_rx(struct net_device *soft_iface,
308
315
309
316
/* skb->ip_summed = CHECKSUM_UNNECESSARY; */
310
317
311
- bat_priv -> stats .rx_packets ++ ;
312
- bat_priv -> stats .rx_bytes += skb -> len + ETH_HLEN ;
318
+ batadv_inc_counter (bat_priv , BATADV_CNT_RX );
319
+ batadv_add_counter (bat_priv , BATADV_CNT_RX_BYTES ,
320
+ skb -> len + ETH_HLEN );
313
321
314
322
soft_iface -> last_rx = jiffies ;
315
323
@@ -379,15 +387,22 @@ struct net_device *batadv_softif_create(const char *name)
379
387
if (!soft_iface )
380
388
goto out ;
381
389
390
+ bat_priv = netdev_priv (soft_iface );
391
+
392
+ /* batadv_interface_stats() needs to be available as soon as
393
+ * register_netdevice() has been called
394
+ */
395
+ bat_priv -> bat_counters = __alloc_percpu (cnt_len , __alignof__(uint64_t ));
396
+ if (!bat_priv -> bat_counters )
397
+ goto free_soft_iface ;
398
+
382
399
ret = register_netdevice (soft_iface );
383
400
if (ret < 0 ) {
384
401
pr_err ("Unable to register the batman interface '%s': %i\n" ,
385
402
name , ret );
386
- goto free_soft_iface ;
403
+ goto free_bat_counters ;
387
404
}
388
405
389
- bat_priv = netdev_priv (soft_iface );
390
-
391
406
atomic_set (& bat_priv -> aggregated_ogms , 1 );
392
407
atomic_set (& bat_priv -> bonding , 0 );
393
408
atomic_set (& bat_priv -> bridge_loop_avoidance , 0 );
@@ -417,17 +432,13 @@ struct net_device *batadv_softif_create(const char *name)
417
432
bat_priv -> primary_if = NULL ;
418
433
bat_priv -> num_ifaces = 0 ;
419
434
420
- bat_priv -> bat_counters = __alloc_percpu (cnt_len , __alignof__(uint64_t ));
421
- if (!bat_priv -> bat_counters )
422
- goto unreg_soft_iface ;
423
-
424
435
ret = batadv_algo_select (bat_priv , batadv_routing_algo );
425
436
if (ret < 0 )
426
- goto free_bat_counters ;
437
+ goto unreg_soft_iface ;
427
438
428
439
ret = batadv_sysfs_add_meshif (soft_iface );
429
440
if (ret < 0 )
430
- goto free_bat_counters ;
441
+ goto unreg_soft_iface ;
431
442
432
443
ret = batadv_debugfs_add_meshif (soft_iface );
433
444
if (ret < 0 )
@@ -443,12 +454,13 @@ struct net_device *batadv_softif_create(const char *name)
443
454
batadv_debugfs_del_meshif (soft_iface );
444
455
unreg_sysfs :
445
456
batadv_sysfs_del_meshif (soft_iface );
446
- free_bat_counters :
447
- free_percpu (bat_priv -> bat_counters );
448
457
unreg_soft_iface :
458
+ free_percpu (bat_priv -> bat_counters );
449
459
unregister_netdevice (soft_iface );
450
460
return NULL ;
451
461
462
+ free_bat_counters :
463
+ free_percpu (bat_priv -> bat_counters );
452
464
free_soft_iface :
453
465
free_netdev (soft_iface );
454
466
out :
@@ -518,6 +530,11 @@ static u32 batadv_get_link(struct net_device *dev)
518
530
static const struct {
519
531
const char name [ETH_GSTRING_LEN ];
520
532
} batadv_counters_strings [] = {
533
+ { "tx" },
534
+ { "tx_bytes" },
535
+ { "tx_dropped" },
536
+ { "rx" },
537
+ { "rx_bytes" },
521
538
{ "forward" },
522
539
{ "forward_bytes" },
523
540
{ "mgmt_tx" },
0 commit comments