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 /* one stat */
15 struct ovpn_peer_stat {
16 atomic64_t bytes;
17 atomic64_t packets;
18 };
19
20 /* rx and tx stats combined */
21 struct ovpn_peer_stats {
22 struct ovpn_peer_stat rx;
23 struct ovpn_peer_stat tx;
24 };
25
26 void ovpn_peer_stats_init(struct ovpn_peer_stats *ps);
27
ovpn_peer_stats_increment(struct ovpn_peer_stat * stat,const unsigned int n)28 static inline void ovpn_peer_stats_increment(struct ovpn_peer_stat *stat,
29 const unsigned int n)
30 {
31 atomic64_add(n, &stat->bytes);
32 atomic64_inc(&stat->packets);
33 }
34
ovpn_peer_stats_increment_rx(struct ovpn_peer_stats * stats,const unsigned int n)35 static inline void ovpn_peer_stats_increment_rx(struct ovpn_peer_stats *stats,
36 const unsigned int n)
37 {
38 ovpn_peer_stats_increment(&stats->rx, n);
39 }
40
ovpn_peer_stats_increment_tx(struct ovpn_peer_stats * stats,const unsigned int n)41 static inline void ovpn_peer_stats_increment_tx(struct ovpn_peer_stats *stats,
42 const unsigned int n)
43 {
44 ovpn_peer_stats_increment(&stats->tx, n);
45 }
46
47 #endif /* _NET_OVPN_OVPNSTATS_H_ */
48