1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef _NET_BATMAN_ADV_LOG_H_
19#define _NET_BATMAN_ADV_LOG_H_
20
21#include "main.h"
22
23#include <linux/bitops.h>
24#include <linux/compiler.h>
25#include <linux/printk.h>
26
27#ifdef CONFIG_BATMAN_ADV_DEBUG
28
29int batadv_debug_log_setup(struct batadv_priv *bat_priv);
30void batadv_debug_log_cleanup(struct batadv_priv *bat_priv);
31
32#else
33
34static inline int batadv_debug_log_setup(struct batadv_priv *bat_priv)
35{
36 return 0;
37}
38
39static inline void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
40{
41}
42
43#endif
44
45
46
47
48
49
50
51
52
53
54
55
56
57enum 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),
66 BATADV_DBG_ALL = 255,
67};
68
69#ifdef CONFIG_BATMAN_ADV_DEBUG
70int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
71__printf(2, 3);
72
73
74#define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...) \
75 do { \
76 if (atomic_read(&(bat_priv)->log_level) & (type) && \
77 (!(ratelimited) || net_ratelimit())) \
78 batadv_debug_log(bat_priv, fmt, ## arg); \
79 } \
80 while (0)
81#else
82__printf(4, 5)
83static 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, ...)
87{
88}
89#endif
90
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)
95
96#define batadv_info(net_dev, fmt, arg...) \
97 do { \
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); \
102 } while (0)
103#define batadv_err(net_dev, fmt, arg...) \
104 do { \
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); \
109 } while (0)
110
111#endif
112