FILE
log.h
File preview with syntax highlighting.
linux-6.19.14/net/batman-adv/log.h
1/* SPDX-License-Identifier: GPL-2.0 */ 2/* Copyright (C) B.A.T.M.A.N. contributors: 3 * 4 * Marek Lindner, Simon Wunderlich 5 */ 6 7#ifndef _NET_BATMAN_ADV_LOG_H_ 8#define _NET_BATMAN_ADV_LOG_H_ 9 10#include "main.h" 11 12#include <linux/atomic.h> 13#include <linux/bitops.h> 14#include <linux/compiler.h> 15#include <linux/printk.h> 16 17#ifdef CONFIG_BATMAN_ADV_DEBUG 18 19int batadv_debug_log_setup(struct batadv_priv *bat_priv); 20void batadv_debug_log_cleanup(struct batadv_priv *bat_priv); 21 22#else 23 24static inline int batadv_debug_log_setup(struct batadv_priv *bat_priv) 25{ 26 return 0; 27} 28 29static inline void batadv_debug_log_cleanup(struct batadv_priv *bat_priv) 30{ 31} 32 33#endif 34 35/** 36 * enum batadv_dbg_level - available log levels 37 */ 38enum batadv_dbg_level { 39 /** @BATADV_DBG_BATMAN: OGM and TQ computations related messages */ 40 BATADV_DBG_BATMAN = BIT(0), 41 42 /** @BATADV_DBG_ROUTES: route added / changed / deleted */ 43 BATADV_DBG_ROUTES = BIT(1), 44 45 /** @BATADV_DBG_TT: translation table messages */ 46 BATADV_DBG_TT = BIT(2), 47 48 /** @BATADV_DBG_BLA: bridge loop avoidance messages */ 49 BATADV_DBG_BLA = BIT(3), 50 51 /** @BATADV_DBG_DAT: ARP snooping and DAT related messages */ 52 BATADV_DBG_DAT = BIT(4), 53 54 /** @BATADV_DBG_MCAST: multicast related messages */ 55 BATADV_DBG_MCAST = BIT(6), 56 57 /** @BATADV_DBG_TP_METER: throughput meter messages */ 58 BATADV_DBG_TP_METER = BIT(7), 59 60 /** @BATADV_DBG_ALL: the union of all the above log levels */ 61 BATADV_DBG_ALL = 255, 62}; 63 64#ifdef CONFIG_BATMAN_ADV_DEBUG 65int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...) 66__printf(2, 3); 67 68/** 69 * _batadv_dbg() - Store debug output with(out) rate limiting 70 * @type: type of debug message 71 * @bat_priv: the bat priv with all the mesh interface information 72 * @ratelimited: whether output should be rate limited 73 * @fmt: format string 74 * @arg: variable arguments 75 */ 76#define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...) \ 77 do { \ 78 struct batadv_priv *__batpriv = (bat_priv); \ 79 if (atomic_read(&__batpriv->log_level) & (type) && \ 80 (!(ratelimited) || net_ratelimit())) \ 81 batadv_debug_log(__batpriv, fmt, ## arg); \ 82 } \ 83 while (0) 84#else /* !CONFIG_BATMAN_ADV_DEBUG */ 85__printf(4, 5) 86static inline void _batadv_dbg(int type __always_unused, 87 struct batadv_priv *bat_priv __always_unused, 88 int ratelimited __always_unused, 89 const char *fmt __always_unused, ...) 90{ 91} 92#endif 93 94/** 95 * batadv_dbg() - Store debug output without rate limiting 96 * @type: type of debug message 97 * @bat_priv: the bat priv with all the mesh interface information 98 * @arg: format string and variable arguments 99 */ 100#define batadv_dbg(type, bat_priv, arg...) \ 101 _batadv_dbg(type, bat_priv, 0, ## arg) 102 103/** 104 * batadv_dbg_ratelimited() - Store debug output with rate limiting 105 * @type: type of debug message 106 * @bat_priv: the bat priv with all the mesh interface information 107 * @arg: format string and variable arguments 108 */ 109#define batadv_dbg_ratelimited(type, bat_priv, arg...) \ 110 _batadv_dbg(type, bat_priv, 1, ## arg) 111 112/** 113 * batadv_info() - Store message in debug buffer and print it to kmsg buffer 114 * @net_dev: the mesh interface net device 115 * @fmt: format string 116 * @arg: variable arguments 117 */ 118#define batadv_info(net_dev, fmt, arg...) \ 119 do { \ 120 struct net_device *_netdev = (net_dev); \ 121 struct batadv_priv *_batpriv = netdev_priv(_netdev); \ 122 batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \ 123 pr_info("%s: " fmt, _netdev->name, ## arg); \ 124 } while (0) 125 126/** 127 * batadv_err() - Store error in debug buffer and print it to kmsg buffer 128 * @net_dev: the mesh interface net device 129 * @fmt: format string 130 * @arg: variable arguments 131 */ 132#define batadv_err(net_dev, fmt, arg...) \ 133 do { \ 134 struct net_device *_netdev = (net_dev); \ 135 struct batadv_priv *_batpriv = netdev_priv(_netdev); \ 136 batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \ 137 pr_err("%s: " fmt, _netdev->name, ## arg); \ 138 } while (0) 139 140#endif /* _NET_BATMAN_ADV_LOG_H_ */
~/
Read-only file preview.