Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Copyright (C) B.A.T.M.A.N. contributors:
0003  *
0004  * Marek Lindner, Simon Wunderlich
0005  */
0006 
0007 #ifndef _NET_BATMAN_ADV_LOG_H_
0008 #define _NET_BATMAN_ADV_LOG_H_
0009 
0010 #include "main.h"
0011 
0012 #include <linux/atomic.h>
0013 #include <linux/bitops.h>
0014 #include <linux/compiler.h>
0015 #include <linux/printk.h>
0016 
0017 #ifdef CONFIG_BATMAN_ADV_DEBUG
0018 
0019 int batadv_debug_log_setup(struct batadv_priv *bat_priv);
0020 void batadv_debug_log_cleanup(struct batadv_priv *bat_priv);
0021 
0022 #else
0023 
0024 static inline int batadv_debug_log_setup(struct batadv_priv *bat_priv)
0025 {
0026     return 0;
0027 }
0028 
0029 static inline void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
0030 {
0031 }
0032 
0033 #endif
0034 
0035 /**
0036  * enum batadv_dbg_level - available log levels
0037  */
0038 enum batadv_dbg_level {
0039     /** @BATADV_DBG_BATMAN: OGM and TQ computations related messages */
0040     BATADV_DBG_BATMAN   = BIT(0),
0041 
0042     /** @BATADV_DBG_ROUTES: route added / changed / deleted */
0043     BATADV_DBG_ROUTES   = BIT(1),
0044 
0045     /** @BATADV_DBG_TT: translation table messages */
0046     BATADV_DBG_TT       = BIT(2),
0047 
0048     /** @BATADV_DBG_BLA: bridge loop avoidance messages */
0049     BATADV_DBG_BLA      = BIT(3),
0050 
0051     /** @BATADV_DBG_DAT: ARP snooping and DAT related messages */
0052     BATADV_DBG_DAT      = BIT(4),
0053 
0054     /** @BATADV_DBG_NC: network coding related messages */
0055     BATADV_DBG_NC       = BIT(5),
0056 
0057     /** @BATADV_DBG_MCAST: multicast related messages */
0058     BATADV_DBG_MCAST    = BIT(6),
0059 
0060     /** @BATADV_DBG_TP_METER: throughput meter messages */
0061     BATADV_DBG_TP_METER = BIT(7),
0062 
0063     /** @BATADV_DBG_ALL: the union of all the above log levels */
0064     BATADV_DBG_ALL      = 255,
0065 };
0066 
0067 #ifdef CONFIG_BATMAN_ADV_DEBUG
0068 int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
0069 __printf(2, 3);
0070 
0071 /**
0072  * _batadv_dbg() - Store debug output with(out) rate limiting
0073  * @type: type of debug message
0074  * @bat_priv: the bat priv with all the soft interface information
0075  * @ratelimited: whether output should be rate limited
0076  * @fmt: format string
0077  * @arg: variable arguments
0078  */
0079 #define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...)       \
0080     do {                                \
0081         struct batadv_priv *__batpriv = (bat_priv);     \
0082         if (atomic_read(&__batpriv->log_level) & (type) &&  \
0083             (!(ratelimited) || net_ratelimit()))        \
0084             batadv_debug_log(__batpriv, fmt, ## arg);   \
0085     }                               \
0086     while (0)
0087 #else /* !CONFIG_BATMAN_ADV_DEBUG */
0088 __printf(4, 5)
0089 static inline void _batadv_dbg(int type __always_unused,
0090                    struct batadv_priv *bat_priv __always_unused,
0091                    int ratelimited __always_unused,
0092                    const char *fmt __always_unused, ...)
0093 {
0094 }
0095 #endif
0096 
0097 /**
0098  * batadv_dbg() - Store debug output without rate limiting
0099  * @type: type of debug message
0100  * @bat_priv: the bat priv with all the soft interface information
0101  * @arg: format string and variable arguments
0102  */
0103 #define batadv_dbg(type, bat_priv, arg...) \
0104     _batadv_dbg(type, bat_priv, 0, ## arg)
0105 
0106 /**
0107  * batadv_dbg_ratelimited() - Store debug output with rate limiting
0108  * @type: type of debug message
0109  * @bat_priv: the bat priv with all the soft interface information
0110  * @arg: format string and variable arguments
0111  */
0112 #define batadv_dbg_ratelimited(type, bat_priv, arg...) \
0113     _batadv_dbg(type, bat_priv, 1, ## arg)
0114 
0115 /**
0116  * batadv_info() - Store message in debug buffer and print it to kmsg buffer
0117  * @net_dev: the soft interface net device
0118  * @fmt: format string
0119  * @arg: variable arguments
0120  */
0121 #define batadv_info(net_dev, fmt, arg...)               \
0122     do {                                \
0123         struct net_device *_netdev = (net_dev);                 \
0124         struct batadv_priv *_batpriv = netdev_priv(_netdev);    \
0125         batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg);  \
0126         pr_info("%s: " fmt, _netdev->name, ## arg);     \
0127     } while (0)
0128 
0129 /**
0130  * batadv_err() - Store error in debug buffer and print it to kmsg buffer
0131  * @net_dev: the soft interface net device
0132  * @fmt: format string
0133  * @arg: variable arguments
0134  */
0135 #define batadv_err(net_dev, fmt, arg...)                \
0136     do {                                \
0137         struct net_device *_netdev = (net_dev);                 \
0138         struct batadv_priv *_batpriv = netdev_priv(_netdev);    \
0139         batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg);  \
0140         pr_err("%s: " fmt, _netdev->name, ## arg);      \
0141     } while (0)
0142 
0143 #endif /* _NET_BATMAN_ADV_LOG_H_ */