blob: 35f4f397ed57dd351ca2eb4135ddaffd84235d61 [file] [log] [blame]
Sven Eckelmann7db7d9f2017-11-19 15:05:11 +01001/* SPDX-License-Identifier: GPL-2.0 */
Sven Eckelmann6b1aea82018-01-01 00:00:00 +01002/* Copyright (C) 2007-2018 B.A.T.M.A.N. contributors:
Sven Eckelmannba412082016-05-15 23:48:31 +02003 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef _NET_BATMAN_ADV_LOG_H_
20#define _NET_BATMAN_ADV_LOG_H_
21
22#include "main.h"
23
24#include <linux/bitops.h>
25#include <linux/compiler.h>
26#include <linux/printk.h>
27
28#ifdef CONFIG_BATMAN_ADV_DEBUG
29
30int batadv_debug_log_setup(struct batadv_priv *bat_priv);
31void batadv_debug_log_cleanup(struct batadv_priv *bat_priv);
32
33#else
34
35static inline int batadv_debug_log_setup(struct batadv_priv *bat_priv)
36{
37 return 0;
38}
39
40static inline void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
41{
42}
43
44#endif
45
46/**
47 * enum batadv_dbg_level - available log levels
Sven Eckelmannba412082016-05-15 23:48:31 +020048 */
49enum batadv_dbg_level {
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010050 /** @BATADV_DBG_BATMAN: OGM and TQ computations related messages */
Antonio Quartulli33a3bb42016-05-05 13:09:43 +020051 BATADV_DBG_BATMAN = BIT(0),
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010052
53 /** @BATADV_DBG_ROUTES: route added / changed / deleted */
Antonio Quartulli33a3bb42016-05-05 13:09:43 +020054 BATADV_DBG_ROUTES = BIT(1),
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010055
56 /** @BATADV_DBG_TT: translation table messages */
Antonio Quartulli33a3bb42016-05-05 13:09:43 +020057 BATADV_DBG_TT = BIT(2),
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010058
59 /** @BATADV_DBG_BLA: bridge loop avoidance messages */
Antonio Quartulli33a3bb42016-05-05 13:09:43 +020060 BATADV_DBG_BLA = BIT(3),
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010061
62 /** @BATADV_DBG_DAT: ARP snooping and DAT related messages */
Antonio Quartulli33a3bb42016-05-05 13:09:43 +020063 BATADV_DBG_DAT = BIT(4),
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010064
65 /** @BATADV_DBG_NC: network coding related messages */
Antonio Quartulli33a3bb42016-05-05 13:09:43 +020066 BATADV_DBG_NC = BIT(5),
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010067
68 /** @BATADV_DBG_MCAST: multicast related messages */
Antonio Quartulli33a3bb42016-05-05 13:09:43 +020069 BATADV_DBG_MCAST = BIT(6),
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010070
71 /** @BATADV_DBG_TP_METER: throughput meter messages */
Antonio Quartulli33a3bb42016-05-05 13:09:43 +020072 BATADV_DBG_TP_METER = BIT(7),
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010073
74 /** @BATADV_DBG_ALL: the union of all the above log levels */
Sven Eckelmann611b9752016-07-16 21:30:20 +020075 BATADV_DBG_ALL = 255,
Sven Eckelmannba412082016-05-15 23:48:31 +020076};
77
78#ifdef CONFIG_BATMAN_ADV_DEBUG
79int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
80__printf(2, 3);
81
Sven Eckelmanne57acf82017-12-02 19:51:52 +010082/**
83 * _batadv_dbg() - Store debug output with(out) ratelimiting
84 * @type: type of debug message
85 * @bat_priv: the bat priv with all the soft interface information
86 * @ratelimited: whether output should be rate limited
87 * @fmt: format string
88 * @arg...: variable arguments
89 */
Sven Eckelmann4c7da0f2016-09-21 09:23:50 +020090#define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...) \
91 do { \
Sven Eckelmanna09c94d2017-02-22 17:16:41 +010092 struct batadv_priv *__batpriv = (bat_priv); \
93 if (atomic_read(&__batpriv->log_level) & (type) && \
Sven Eckelmann4c7da0f2016-09-21 09:23:50 +020094 (!(ratelimited) || net_ratelimit())) \
Sven Eckelmanna09c94d2017-02-22 17:16:41 +010095 batadv_debug_log(__batpriv, fmt, ## arg); \
Sven Eckelmann4c7da0f2016-09-21 09:23:50 +020096 } \
Sven Eckelmannba412082016-05-15 23:48:31 +020097 while (0)
98#else /* !CONFIG_BATMAN_ADV_DEBUG */
99__printf(4, 5)
100static inline void _batadv_dbg(int type __always_unused,
101 struct batadv_priv *bat_priv __always_unused,
102 int ratelimited __always_unused,
103 const char *fmt __always_unused, ...)
104{
105}
106#endif
107
Sven Eckelmanne57acf82017-12-02 19:51:52 +0100108/**
109 * batadv_dbg() - Store debug output without ratelimiting
110 * @type: type of debug message
111 * @bat_priv: the bat priv with all the soft interface information
112 * @arg...: format string and variable arguments
113 */
Sven Eckelmannba412082016-05-15 23:48:31 +0200114#define batadv_dbg(type, bat_priv, arg...) \
115 _batadv_dbg(type, bat_priv, 0, ## arg)
Sven Eckelmanne57acf82017-12-02 19:51:52 +0100116
117/**
118 * batadv_dbg_ratelimited() - Store debug output with ratelimiting
119 * @type: type of debug message
120 * @bat_priv: the bat priv with all the soft interface information
121 * @arg...: format string and variable arguments
122 */
Sven Eckelmannba412082016-05-15 23:48:31 +0200123#define batadv_dbg_ratelimited(type, bat_priv, arg...) \
124 _batadv_dbg(type, bat_priv, 1, ## arg)
125
Sven Eckelmanne57acf82017-12-02 19:51:52 +0100126/**
127 * batadv_info() - Store message in debug buffer and print it to kmsg buffer
128 * @net_dev: the soft interface net device
129 * @fmt: format string
130 * @arg...: variable arguments
131 */
Sven Eckelmannba412082016-05-15 23:48:31 +0200132#define batadv_info(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_info("%s: " fmt, _netdev->name, ## arg); \
138 } while (0)
Sven Eckelmanne57acf82017-12-02 19:51:52 +0100139
140/**
141 * batadv_err() - Store error in debug buffer and print it to kmsg buffer
142 * @net_dev: the soft interface net device
143 * @fmt: format string
144 * @arg...: variable arguments
145 */
Sven Eckelmannba412082016-05-15 23:48:31 +0200146#define batadv_err(net_dev, fmt, arg...) \
147 do { \
148 struct net_device *_netdev = (net_dev); \
149 struct batadv_priv *_batpriv = netdev_priv(_netdev); \
150 batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
151 pr_err("%s: " fmt, _netdev->name, ## arg); \
152 } while (0)
153
154#endif /* _NET_BATMAN_ADV_LOG_H_ */