at v5.2 142 lines 4.1 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 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/bitops.h> 13#include <linux/compiler.h> 14#include <linux/printk.h> 15 16#ifdef CONFIG_BATMAN_ADV_DEBUG 17 18int batadv_debug_log_setup(struct batadv_priv *bat_priv); 19void batadv_debug_log_cleanup(struct batadv_priv *bat_priv); 20 21#else 22 23static inline int batadv_debug_log_setup(struct batadv_priv *bat_priv) 24{ 25 return 0; 26} 27 28static inline void batadv_debug_log_cleanup(struct batadv_priv *bat_priv) 29{ 30} 31 32#endif 33 34/** 35 * enum batadv_dbg_level - available log levels 36 */ 37enum batadv_dbg_level { 38 /** @BATADV_DBG_BATMAN: OGM and TQ computations related messages */ 39 BATADV_DBG_BATMAN = BIT(0), 40 41 /** @BATADV_DBG_ROUTES: route added / changed / deleted */ 42 BATADV_DBG_ROUTES = BIT(1), 43 44 /** @BATADV_DBG_TT: translation table messages */ 45 BATADV_DBG_TT = BIT(2), 46 47 /** @BATADV_DBG_BLA: bridge loop avoidance messages */ 48 BATADV_DBG_BLA = BIT(3), 49 50 /** @BATADV_DBG_DAT: ARP snooping and DAT related messages */ 51 BATADV_DBG_DAT = BIT(4), 52 53 /** @BATADV_DBG_NC: network coding related messages */ 54 BATADV_DBG_NC = BIT(5), 55 56 /** @BATADV_DBG_MCAST: multicast related messages */ 57 BATADV_DBG_MCAST = BIT(6), 58 59 /** @BATADV_DBG_TP_METER: throughput meter messages */ 60 BATADV_DBG_TP_METER = BIT(7), 61 62 /** @BATADV_DBG_ALL: the union of all the above log levels */ 63 BATADV_DBG_ALL = 255, 64}; 65 66#ifdef CONFIG_BATMAN_ADV_DEBUG 67int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...) 68__printf(2, 3); 69 70/** 71 * _batadv_dbg() - Store debug output with(out) ratelimiting 72 * @type: type of debug message 73 * @bat_priv: the bat priv with all the soft interface information 74 * @ratelimited: whether output should be rate limited 75 * @fmt: format string 76 * @arg...: variable arguments 77 */ 78#define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...) \ 79 do { \ 80 struct batadv_priv *__batpriv = (bat_priv); \ 81 if (atomic_read(&__batpriv->log_level) & (type) && \ 82 (!(ratelimited) || net_ratelimit())) \ 83 batadv_debug_log(__batpriv, fmt, ## arg); \ 84 } \ 85 while (0) 86#else /* !CONFIG_BATMAN_ADV_DEBUG */ 87__printf(4, 5) 88static inline void _batadv_dbg(int type __always_unused, 89 struct batadv_priv *bat_priv __always_unused, 90 int ratelimited __always_unused, 91 const char *fmt __always_unused, ...) 92{ 93} 94#endif 95 96/** 97 * batadv_dbg() - Store debug output without ratelimiting 98 * @type: type of debug message 99 * @bat_priv: the bat priv with all the soft interface information 100 * @arg...: format string and variable arguments 101 */ 102#define batadv_dbg(type, bat_priv, arg...) \ 103 _batadv_dbg(type, bat_priv, 0, ## arg) 104 105/** 106 * batadv_dbg_ratelimited() - Store debug output with ratelimiting 107 * @type: type of debug message 108 * @bat_priv: the bat priv with all the soft interface information 109 * @arg...: format string and variable arguments 110 */ 111#define batadv_dbg_ratelimited(type, bat_priv, arg...) \ 112 _batadv_dbg(type, bat_priv, 1, ## arg) 113 114/** 115 * batadv_info() - Store message in debug buffer and print it to kmsg buffer 116 * @net_dev: the soft interface net device 117 * @fmt: format string 118 * @arg...: variable arguments 119 */ 120#define batadv_info(net_dev, fmt, arg...) \ 121 do { \ 122 struct net_device *_netdev = (net_dev); \ 123 struct batadv_priv *_batpriv = netdev_priv(_netdev); \ 124 batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \ 125 pr_info("%s: " fmt, _netdev->name, ## arg); \ 126 } while (0) 127 128/** 129 * batadv_err() - Store error in debug buffer and print it to kmsg buffer 130 * @net_dev: the soft interface net device 131 * @fmt: format string 132 * @arg...: variable arguments 133 */ 134#define batadv_err(net_dev, fmt, arg...) \ 135 do { \ 136 struct net_device *_netdev = (net_dev); \ 137 struct batadv_priv *_batpriv = netdev_priv(_netdev); \ 138 batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \ 139 pr_err("%s: " fmt, _netdev->name, ## arg); \ 140 } while (0) 141 142#endif /* _NET_BATMAN_ADV_LOG_H_ */