1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* OpenVPN data channel offload 3 * 4 * Copyright (C) 2020-2025 OpenVPN, Inc. 5 * 6 * Author: James Yonan <james@openvpn.net> 7 * Antonio Quartulli <antonio@openvpn.net> 8 * Lev Stipakov <lev@openvpn.net> 9 */ 10 11 #ifndef _NET_OVPN_OVPNSTATS_H_ 12 #define _NET_OVPN_OVPNSTATS_H_ 13 14 #include <linux/netdevice.h> 15 16 /* one stat */ 17 struct ovpn_peer_stat { 18 atomic64_t bytes; 19 atomic64_t packets; 20 }; 21 22 /* rx and tx stats combined */ 23 struct ovpn_peer_stats { 24 struct ovpn_peer_stat rx; 25 struct ovpn_peer_stat tx; 26 }; 27 28 void ovpn_peer_stats_init(struct ovpn_peer_stats *ps); 29 30 static inline void ovpn_peer_stats_increment(struct ovpn_peer_stat *stat, 31 const unsigned int n) 32 { 33 atomic64_add(n, &stat->bytes); 34 atomic64_inc(&stat->packets); 35 } 36 37 static inline void ovpn_peer_stats_increment_rx(struct ovpn_peer_stats *stats, 38 const unsigned int n) 39 { 40 ovpn_peer_stats_increment(&stats->rx, n); 41 } 42 43 static inline void ovpn_peer_stats_increment_tx(struct ovpn_peer_stats *stats, 44 const unsigned int n) 45 { 46 ovpn_peer_stats_increment(&stats->tx, n); 47 } 48 49 static inline void ovpn_dev_dstats_tx_dropped(struct net_device *dev) 50 { 51 local_bh_disable(); 52 dev_dstats_tx_dropped(dev); 53 local_bh_enable(); 54 } 55 56 static inline void ovpn_dev_dstats_rx_dropped(struct net_device *dev) 57 { 58 local_bh_disable(); 59 dev_dstats_rx_dropped(dev); 60 local_bh_enable(); 61 } 62 63 #endif /* _NET_OVPN_OVPNSTATS_H_ */ 64