1 /* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors:
3 * Marek Lindner, Simon Wunderlich
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 #ifndef _NET_BATMAN_ADV_LOG_H_
19 #define _NET_BATMAN_ADV_LOG_H_
23 #include <linux/bitops.h>
24 #include <linux/compiler.h>
25 #include <linux/printk.h>
27 #ifdef CONFIG_BATMAN_ADV_DEBUG
29 int batadv_debug_log_setup(struct batadv_priv
*bat_priv
);
30 void batadv_debug_log_cleanup(struct batadv_priv
*bat_priv
);
34 static inline int batadv_debug_log_setup(struct batadv_priv
*bat_priv
)
39 static inline void batadv_debug_log_cleanup(struct batadv_priv
*bat_priv
)
46 * enum batadv_dbg_level - available log levels
47 * @BATADV_DBG_BATMAN: OGM and TQ computations related messages
48 * @BATADV_DBG_ROUTES: route added / changed / deleted
49 * @BATADV_DBG_TT: translation table messages
50 * @BATADV_DBG_BLA: bridge loop avoidance messages
51 * @BATADV_DBG_DAT: ARP snooping and DAT related messages
52 * @BATADV_DBG_NC: network coding related messages
53 * @BATADV_DBG_MCAST: multicast related messages
54 * @BATADV_DBG_TP_METER: throughput meter messages
55 * @BATADV_DBG_ALL: the union of all the above log levels
57 enum batadv_dbg_level
{
58 BATADV_DBG_BATMAN
= BIT(0),
59 BATADV_DBG_ROUTES
= BIT(1),
60 BATADV_DBG_TT
= BIT(2),
61 BATADV_DBG_BLA
= BIT(3),
62 BATADV_DBG_DAT
= BIT(4),
63 BATADV_DBG_NC
= BIT(5),
64 BATADV_DBG_MCAST
= BIT(6),
65 BATADV_DBG_TP_METER
= BIT(7),
69 #ifdef CONFIG_BATMAN_ADV_DEBUG
70 int batadv_debug_log(struct batadv_priv
*bat_priv
, const char *fmt
, ...)
73 /* possibly ratelimited debug output */
74 #define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...) \
76 if (atomic_read(&bat_priv->log_level) & type && \
77 (!ratelimited || net_ratelimit())) \
78 batadv_debug_log(bat_priv, fmt, ## arg);\
81 #else /* !CONFIG_BATMAN_ADV_DEBUG */
83 static inline void _batadv_dbg(int type __always_unused
,
84 struct batadv_priv
*bat_priv __always_unused
,
85 int ratelimited __always_unused
,
86 const char *fmt __always_unused
, ...)
91 #define batadv_dbg(type, bat_priv, arg...) \
92 _batadv_dbg(type, bat_priv, 0, ## arg)
93 #define batadv_dbg_ratelimited(type, bat_priv, arg...) \
94 _batadv_dbg(type, bat_priv, 1, ## arg)
96 #define batadv_info(net_dev, fmt, arg...) \
98 struct net_device *_netdev = (net_dev); \
99 struct batadv_priv *_batpriv = netdev_priv(_netdev); \
100 batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
101 pr_info("%s: " fmt, _netdev->name, ## arg); \
103 #define batadv_err(net_dev, fmt, arg...) \
105 struct net_device *_netdev = (net_dev); \
106 struct batadv_priv *_batpriv = netdev_priv(_netdev); \
107 batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
108 pr_err("%s: " fmt, _netdev->name, ## arg); \
111 #endif /* _NET_BATMAN_ADV_LOG_H_ */