blob: 6717c965f0faf5ee3b7fa9536fd94e0d275a8bb0 [file] [log] [blame]
Sven Eckelmann7db7d9f2017-11-19 15:05:11 +01001/* SPDX-License-Identifier: GPL-2.0 */
Sven Eckelmanncfa55c62021-01-01 00:00:01 +01002/* Copyright (C) B.A.T.M.A.N. contributors:
Sven Eckelmannba412082016-05-15 23:48:31 +02003 *
4 * Marek Lindner, Simon Wunderlich
Sven Eckelmannba412082016-05-15 23:48:31 +02005 */
6
7#ifndef _NET_BATMAN_ADV_LOG_H_
8#define _NET_BATMAN_ADV_LOG_H_
9
10#include "main.h"
11
Sven Eckelmann47d45222019-05-24 16:51:29 +020012#include <linux/atomic.h>
Sven Eckelmannba412082016-05-15 23:48:31 +020013#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
Sven Eckelmannba412082016-05-15 23:48:31 +020037 */
38enum batadv_dbg_level {
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010039 /** @BATADV_DBG_BATMAN: OGM and TQ computations related messages */
Antonio Quartulli33a3bb42016-05-05 13:09:43 +020040 BATADV_DBG_BATMAN = BIT(0),
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010041
42 /** @BATADV_DBG_ROUTES: route added / changed / deleted */
Antonio Quartulli33a3bb42016-05-05 13:09:43 +020043 BATADV_DBG_ROUTES = BIT(1),
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010044
45 /** @BATADV_DBG_TT: translation table messages */
Antonio Quartulli33a3bb42016-05-05 13:09:43 +020046 BATADV_DBG_TT = BIT(2),
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010047
48 /** @BATADV_DBG_BLA: bridge loop avoidance messages */
Antonio Quartulli33a3bb42016-05-05 13:09:43 +020049 BATADV_DBG_BLA = BIT(3),
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010050
51 /** @BATADV_DBG_DAT: ARP snooping and DAT related messages */
Antonio Quartulli33a3bb42016-05-05 13:09:43 +020052 BATADV_DBG_DAT = BIT(4),
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010053
54 /** @BATADV_DBG_NC: network coding related messages */
Antonio Quartulli33a3bb42016-05-05 13:09:43 +020055 BATADV_DBG_NC = BIT(5),
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010056
57 /** @BATADV_DBG_MCAST: multicast related messages */
Antonio Quartulli33a3bb42016-05-05 13:09:43 +020058 BATADV_DBG_MCAST = BIT(6),
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010059
60 /** @BATADV_DBG_TP_METER: throughput meter messages */
Antonio Quartulli33a3bb42016-05-05 13:09:43 +020061 BATADV_DBG_TP_METER = BIT(7),
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010062
63 /** @BATADV_DBG_ALL: the union of all the above log levels */
Sven Eckelmann611b9752016-07-16 21:30:20 +020064 BATADV_DBG_ALL = 255,
Sven Eckelmannba412082016-05-15 23:48:31 +020065};
66
67#ifdef CONFIG_BATMAN_ADV_DEBUG
68int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
69__printf(2, 3);
70
Sven Eckelmanne57acf82017-12-02 19:51:52 +010071/**
Sven Eckelmannbccb48c2020-06-01 20:13:21 +020072 * _batadv_dbg() - Store debug output with(out) rate limiting
Sven Eckelmanne57acf82017-12-02 19:51:52 +010073 * @type: type of debug message
74 * @bat_priv: the bat priv with all the soft interface information
75 * @ratelimited: whether output should be rate limited
76 * @fmt: format string
Sven Eckelmannf4191c62019-11-14 22:12:37 +010077 * @arg: variable arguments
Sven Eckelmanne57acf82017-12-02 19:51:52 +010078 */
Sven Eckelmann4c7da0f2016-09-21 09:23:50 +020079#define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...) \
80 do { \
Sven Eckelmanna09c94d2017-02-22 17:16:41 +010081 struct batadv_priv *__batpriv = (bat_priv); \
82 if (atomic_read(&__batpriv->log_level) & (type) && \
Sven Eckelmann4c7da0f2016-09-21 09:23:50 +020083 (!(ratelimited) || net_ratelimit())) \
Sven Eckelmanna09c94d2017-02-22 17:16:41 +010084 batadv_debug_log(__batpriv, fmt, ## arg); \
Sven Eckelmann4c7da0f2016-09-21 09:23:50 +020085 } \
Sven Eckelmannba412082016-05-15 23:48:31 +020086 while (0)
87#else /* !CONFIG_BATMAN_ADV_DEBUG */
88__printf(4, 5)
89static inline void _batadv_dbg(int type __always_unused,
90 struct batadv_priv *bat_priv __always_unused,
91 int ratelimited __always_unused,
92 const char *fmt __always_unused, ...)
93{
94}
95#endif
96
Sven Eckelmanne57acf82017-12-02 19:51:52 +010097/**
Sven Eckelmannbccb48c2020-06-01 20:13:21 +020098 * batadv_dbg() - Store debug output without rate limiting
Sven Eckelmanne57acf82017-12-02 19:51:52 +010099 * @type: type of debug message
100 * @bat_priv: the bat priv with all the soft interface information
Sven Eckelmannf4191c62019-11-14 22:12:37 +0100101 * @arg: format string and variable arguments
Sven Eckelmanne57acf82017-12-02 19:51:52 +0100102 */
Sven Eckelmannba412082016-05-15 23:48:31 +0200103#define batadv_dbg(type, bat_priv, arg...) \
104 _batadv_dbg(type, bat_priv, 0, ## arg)
Sven Eckelmanne57acf82017-12-02 19:51:52 +0100105
106/**
Sven Eckelmannbccb48c2020-06-01 20:13:21 +0200107 * batadv_dbg_ratelimited() - Store debug output with rate limiting
Sven Eckelmanne57acf82017-12-02 19:51:52 +0100108 * @type: type of debug message
109 * @bat_priv: the bat priv with all the soft interface information
Sven Eckelmannf4191c62019-11-14 22:12:37 +0100110 * @arg: format string and variable arguments
Sven Eckelmanne57acf82017-12-02 19:51:52 +0100111 */
Sven Eckelmannba412082016-05-15 23:48:31 +0200112#define batadv_dbg_ratelimited(type, bat_priv, arg...) \
113 _batadv_dbg(type, bat_priv, 1, ## arg)
114
Sven Eckelmanne57acf82017-12-02 19:51:52 +0100115/**
116 * batadv_info() - Store message in debug buffer and print it to kmsg buffer
117 * @net_dev: the soft interface net device
118 * @fmt: format string
Sven Eckelmannf4191c62019-11-14 22:12:37 +0100119 * @arg: variable arguments
Sven Eckelmanne57acf82017-12-02 19:51:52 +0100120 */
Sven Eckelmannba412082016-05-15 23:48:31 +0200121#define batadv_info(net_dev, fmt, arg...) \
122 do { \
123 struct net_device *_netdev = (net_dev); \
124 struct batadv_priv *_batpriv = netdev_priv(_netdev); \
125 batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
126 pr_info("%s: " fmt, _netdev->name, ## arg); \
127 } while (0)
Sven Eckelmanne57acf82017-12-02 19:51:52 +0100128
129/**
130 * batadv_err() - Store error in debug buffer and print it to kmsg buffer
131 * @net_dev: the soft interface net device
132 * @fmt: format string
Sven Eckelmannf4191c62019-11-14 22:12:37 +0100133 * @arg: variable arguments
Sven Eckelmanne57acf82017-12-02 19:51:52 +0100134 */
Sven Eckelmannba412082016-05-15 23:48:31 +0200135#define batadv_err(net_dev, fmt, arg...) \
136 do { \
137 struct net_device *_netdev = (net_dev); \
138 struct batadv_priv *_batpriv = netdev_priv(_netdev); \
139 batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
140 pr_err("%s: " fmt, _netdev->name, ## arg); \
141 } while (0)
142
143#endif /* _NET_BATMAN_ADV_LOG_H_ */