1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
4 * Marek Lindner, Simon Wunderlich
7 #ifndef _NET_BATMAN_ADV_LOG_H_
8 #define _NET_BATMAN_ADV_LOG_H_
12 #include <linux/bitops.h>
13 #include <linux/compiler.h>
14 #include <linux/printk.h>
16 #ifdef CONFIG_BATMAN_ADV_DEBUG
18 int batadv_debug_log_setup(struct batadv_priv *bat_priv);
19 void batadv_debug_log_cleanup(struct batadv_priv *bat_priv);
23 static inline int batadv_debug_log_setup(struct batadv_priv *bat_priv)
28 static inline void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
35 * enum batadv_dbg_level - available log levels
37 enum batadv_dbg_level {
38 /** @BATADV_DBG_BATMAN: OGM and TQ computations related messages */
39 BATADV_DBG_BATMAN = BIT(0),
41 /** @BATADV_DBG_ROUTES: route added / changed / deleted */
42 BATADV_DBG_ROUTES = BIT(1),
44 /** @BATADV_DBG_TT: translation table messages */
45 BATADV_DBG_TT = BIT(2),
47 /** @BATADV_DBG_BLA: bridge loop avoidance messages */
48 BATADV_DBG_BLA = BIT(3),
50 /** @BATADV_DBG_DAT: ARP snooping and DAT related messages */
51 BATADV_DBG_DAT = BIT(4),
53 /** @BATADV_DBG_NC: network coding related messages */
54 BATADV_DBG_NC = BIT(5),
56 /** @BATADV_DBG_MCAST: multicast related messages */
57 BATADV_DBG_MCAST = BIT(6),
59 /** @BATADV_DBG_TP_METER: throughput meter messages */
60 BATADV_DBG_TP_METER = BIT(7),
62 /** @BATADV_DBG_ALL: the union of all the above log levels */
66 #ifdef CONFIG_BATMAN_ADV_DEBUG
67 int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
71 * _batadv_dbg() - Store debug output with(out) ratelimiting
72 * @type: type of debug message
73 * @bat_priv: the bat priv with all the soft interface information
74 * @ratelimited: whether output should be rate limited
76 * @arg...: variable arguments
78 #define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...) \
80 struct batadv_priv *__batpriv = (bat_priv); \
81 if (atomic_read(&__batpriv->log_level) & (type) && \
82 (!(ratelimited) || net_ratelimit())) \
83 batadv_debug_log(__batpriv, fmt, ## arg); \
86 #else /* !CONFIG_BATMAN_ADV_DEBUG */
88 static inline void _batadv_dbg(int type __always_unused,
89 struct batadv_priv *bat_priv __always_unused,
90 int ratelimited __always_unused,
91 const char *fmt __always_unused, ...)
97 * batadv_dbg() - Store debug output without ratelimiting
98 * @type: type of debug message
99 * @bat_priv: the bat priv with all the soft interface information
100 * @arg...: format string and variable arguments
102 #define batadv_dbg(type, bat_priv, arg...) \
103 _batadv_dbg(type, bat_priv, 0, ## arg)
106 * batadv_dbg_ratelimited() - Store debug output with ratelimiting
107 * @type: type of debug message
108 * @bat_priv: the bat priv with all the soft interface information
109 * @arg...: format string and variable arguments
111 #define batadv_dbg_ratelimited(type, bat_priv, arg...) \
112 _batadv_dbg(type, bat_priv, 1, ## arg)
115 * batadv_info() - Store message in debug buffer and print it to kmsg buffer
116 * @net_dev: the soft interface net device
117 * @fmt: format string
118 * @arg...: variable arguments
120 #define batadv_info(net_dev, fmt, arg...) \
122 struct net_device *_netdev = (net_dev); \
123 struct batadv_priv *_batpriv = netdev_priv(_netdev); \
124 batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
125 pr_info("%s: " fmt, _netdev->name, ## arg); \
129 * batadv_err() - Store error in debug buffer and print it to kmsg buffer
130 * @net_dev: the soft interface net device
131 * @fmt: format string
132 * @arg...: variable arguments
134 #define batadv_err(net_dev, fmt, arg...) \
136 struct net_device *_netdev = (net_dev); \
137 struct batadv_priv *_batpriv = netdev_priv(_netdev); \
138 batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
139 pr_err("%s: " fmt, _netdev->name, ## arg); \
142 #endif /* _NET_BATMAN_ADV_LOG_H_ */