1 /* 2 * Copyright (c) 2019 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef __PPP_STATS_H__ 8 #define __PPP_STATS_H__ 9 10 #if defined(CONFIG_NET_STATISTICS_PPP) 11 12 #include <zephyr/net/net_ip.h> 13 #include <zephyr/net/net_stats.h> 14 #include <zephyr/net/net_if.h> 15 ppp_stats_update_bytes_rx(struct net_if * iface,uint32_t bytes)16static inline void ppp_stats_update_bytes_rx(struct net_if *iface, 17 uint32_t bytes) 18 { 19 const struct ppp_api *api = (const struct ppp_api *) 20 net_if_get_device(iface)->api; 21 struct net_stats_ppp *stats; 22 23 if (!api->get_stats) { 24 return; 25 } 26 27 stats = api->get_stats(net_if_get_device(iface)); 28 if (!stats) { 29 return; 30 } 31 32 stats->bytes.received += bytes; 33 } 34 ppp_stats_update_bytes_tx(struct net_if * iface,uint32_t bytes)35static inline void ppp_stats_update_bytes_tx(struct net_if *iface, 36 uint32_t bytes) 37 { 38 const struct ppp_api *api = (const struct ppp_api *) 39 net_if_get_device(iface)->api; 40 struct net_stats_ppp *stats; 41 42 if (!api->get_stats) { 43 return; 44 } 45 46 stats = api->get_stats(net_if_get_device(iface)); 47 if (!stats) { 48 return; 49 } 50 51 stats->bytes.sent += bytes; 52 } 53 ppp_stats_update_pkts_rx(struct net_if * iface)54static inline void ppp_stats_update_pkts_rx(struct net_if *iface) 55 { 56 const struct ppp_api *api = (const struct ppp_api *) 57 net_if_get_device(iface)->api; 58 struct net_stats_ppp *stats; 59 60 if (!api->get_stats) { 61 return; 62 } 63 64 stats = api->get_stats(net_if_get_device(iface)); 65 if (!stats) { 66 return; 67 } 68 69 stats->pkts.rx++; 70 } 71 ppp_stats_update_pkts_tx(struct net_if * iface)72static inline void ppp_stats_update_pkts_tx(struct net_if *iface) 73 { 74 const struct ppp_api *api = (const struct ppp_api *) 75 net_if_get_device(iface)->api; 76 struct net_stats_ppp *stats; 77 78 if (!api->get_stats) { 79 return; 80 } 81 82 stats = api->get_stats(net_if_get_device(iface)); 83 if (!stats) { 84 return; 85 } 86 87 stats->pkts.tx++; 88 } 89 ppp_stats_update_drop_rx(struct net_if * iface)90static inline void ppp_stats_update_drop_rx(struct net_if *iface) 91 { 92 const struct ppp_api *api = ((const struct ppp_api *) 93 net_if_get_device(iface)->api); 94 struct net_stats_ppp *stats; 95 96 if (!api->get_stats) { 97 return; 98 } 99 100 stats = api->get_stats(net_if_get_device(iface)); 101 if (!stats) { 102 return; 103 } 104 105 stats->drop++; 106 } 107 ppp_stats_update_fcs_error_rx(struct net_if * iface)108static inline void ppp_stats_update_fcs_error_rx(struct net_if *iface) 109 { 110 const struct ppp_api *api = ((const struct ppp_api *) 111 net_if_get_device(iface)->api); 112 struct net_stats_ppp *stats; 113 114 if (!api->get_stats) { 115 return; 116 } 117 118 stats = api->get_stats(net_if_get_device(iface)); 119 if (!stats) { 120 return; 121 } 122 123 stats->chkerr++; 124 } 125 126 #else /* CONFIG_NET_STATISTICS_PPP */ 127 128 #define ppp_stats_update_bytes_rx(iface, bytes) 129 #define ppp_stats_update_bytes_tx(iface, bytes) 130 #define ppp_stats_update_pkts_rx(iface) 131 #define ppp_stats_update_pkts_tx(iface) 132 #define ppp_stats_update_drop_rx(iface) 133 #define ppp_stats_update_fcs_error_rx(iface) 134 135 #endif /* CONFIG_NET_STATISTICS_PPP */ 136 137 #endif /* __PPP_STATS_H__ */ 138