| 1 |
|
| 2 | |
| 3 | *
|
| 4 | * Marek Lindner, Simon Wunderlich
|
| 5 |
|
| 6 |
|
| 7 | #ifndef _NET_BATMAN_ADV_LOG_H_
|
| 8 | #define _NET_BATMAN_ADV_LOG_H_
|
| 9 |
|
| 10 | #include "main.h"
|
| 11 |
|
| 12 | #include <linux/atomic.h>
|
| 13 | #include <linux/bitops.h>
|
| 14 | #include <linux/compiler.h>
|
| 15 | #include <linux/printk.h>
|
| 16 |
|
| 17 | #ifdef CONFIG_BATMAN_ADV_DEBUG
|
| 18 |
|
| 19 | int batadv_debug_log_setup(struct batadv_priv *bat_priv);
|
| 20 | void batadv_debug_log_cleanup(struct batadv_priv *bat_priv);
|
| 21 |
|
| 22 | #else
|
| 23 |
|
| 24 | static inline int batadv_debug_log_setup(struct batadv_priv *bat_priv)
|
| 25 | {
|
| 26 | return 0;
|
| 27 | }
|
| 28 |
|
| 29 | static 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
|
| 37 |
|
| 38 | enum batadv_dbg_level {
|
| 39 |
|
| 40 | BATADV_DBG_BATMAN = BIT(0),
|
| 41 |
|
| 42 |
|
| 43 | BATADV_DBG_ROUTES = BIT(1),
|
| 44 |
|
| 45 |
|
| 46 | BATADV_DBG_TT = BIT(2),
|
| 47 |
|
| 48 |
|
| 49 | BATADV_DBG_BLA = BIT(3),
|
| 50 |
|
| 51 |
|
| 52 | BATADV_DBG_DAT = BIT(4),
|
| 53 |
|
| 54 |
|
| 55 | BATADV_DBG_MCAST = BIT(6),
|
| 56 |
|
| 57 |
|
| 58 | BATADV_DBG_TP_METER = BIT(7),
|
| 59 |
|
| 60 |
|
| 61 | BATADV_DBG_ALL = 255,
|
| 62 | };
|
| 63 |
|
| 64 | #ifdef CONFIG_BATMAN_ADV_DEBUG
|
| 65 | int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
|
| 66 | __printf(2, 3);
|
| 67 |
|
| 68 | |
| 69 | * _batadv_dbg() - Store debug output with(out) rate limiting
|
| 70 | * @type: type of debug message
|
| 71 | * @bat_priv: the bat priv with all the mesh interface information
|
| 72 | * @ratelimited: whether output should be rate limited
|
| 73 | * @fmt: format string
|
| 74 | * @arg: variable arguments
|
| 75 |
|
| 76 | #define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...) \
|
| 77 | do { \
|
| 78 | struct batadv_priv *__batpriv = (bat_priv); \
|
| 79 | if (READ_ONCE(__batpriv->log_level) & (type) && \
|
| 80 | (!(ratelimited) || net_ratelimit())) \
|
| 81 | batadv_debug_log(__batpriv, fmt, ## arg); \
|
| 82 | } \
|
| 83 | while (0)
|
| 84 | #else
|
| 85 | __printf(4, 5)
|
| 86 | static inline void _batadv_dbg(int type __always_unused,
|
| 87 | struct batadv_priv *bat_priv __always_unused,
|
| 88 | int ratelimited __always_unused,
|
| 89 | const char *fmt __always_unused, ...)
|
| 90 | {
|
| 91 | }
|
| 92 | #endif
|
| 93 |
|
| 94 | |
| 95 | * batadv_dbg() - Store debug output without rate limiting
|
| 96 | * @type: type of debug message
|
| 97 | * @bat_priv: the bat priv with all the mesh interface information
|
| 98 | * @arg: format string and variable arguments
|
| 99 |
|
| 100 | #define batadv_dbg(type, bat_priv, arg...) \
|
| 101 | _batadv_dbg(type, bat_priv, 0, ## arg)
|
| 102 |
|
| 103 | |
| 104 | * batadv_dbg_ratelimited() - Store debug output with rate limiting
|
| 105 | * @type: type of debug message
|
| 106 | * @bat_priv: the bat priv with all the mesh interface information
|
| 107 | * @arg: format string and variable arguments
|
| 108 |
|
| 109 | #define batadv_dbg_ratelimited(type, bat_priv, arg...) \
|
| 110 | _batadv_dbg(type, bat_priv, 1, ## arg)
|
| 111 |
|
| 112 | |
| 113 | * batadv_info() - Store message in debug buffer and print it to kmsg buffer
|
| 114 | * @net_dev: the mesh interface net device
|
| 115 | * @fmt: format string
|
| 116 | * @arg: variable arguments
|
| 117 |
|
| 118 | #define batadv_info(net_dev, fmt, arg...) \
|
| 119 | do { \
|
| 120 | struct batadv_priv *_batpriv; \
|
| 121 | struct net_device *_netdev; \
|
| 122 | \
|
| 123 | _netdev = (net_dev); \
|
| 124 | _batpriv = netdev_priv(_netdev); \
|
| 125 | \
|
| 126 | batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
|
| 127 | pr_info("%s: " fmt, _netdev->name, ## arg); \
|
| 128 | } while (0)
|
| 129 |
|
| 130 | |
| 131 | * batadv_err() - Store error in debug buffer and print it to kmsg buffer
|
| 132 | * @net_dev: the mesh interface net device
|
| 133 | * @fmt: format string
|
| 134 | * @arg: variable arguments
|
| 135 |
|
| 136 | #define batadv_err(net_dev, fmt, arg...) \
|
| 137 | do { \
|
| 138 | struct batadv_priv *_batpriv; \
|
| 139 | struct net_device *_netdev; \
|
| 140 | \
|
| 141 | _netdev = (net_dev); \
|
| 142 | _batpriv = netdev_priv(_netdev); \
|
| 143 | \
|
| 144 | batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
|
| 145 | pr_err("%s: " fmt, _netdev->name, ## arg); \
|
| 146 | } while (0)
|
| 147 |
|
| 148 | #endif
|