log.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2007-2018 B.A.T.M.A.N. contributors:
  3. *
  4. * Marek Lindner, Simon Wunderlich
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of version 2 of the GNU General Public
  8. * License as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef _NET_BATMAN_ADV_LOG_H_
  19. #define _NET_BATMAN_ADV_LOG_H_
  20. #include "main.h"
  21. #include <linux/bitops.h>
  22. #include <linux/compiler.h>
  23. #include <linux/printk.h>
  24. #ifdef CONFIG_BATMAN_ADV_DEBUG
  25. int batadv_debug_log_setup(struct batadv_priv *bat_priv);
  26. void batadv_debug_log_cleanup(struct batadv_priv *bat_priv);
  27. #else
  28. static inline int batadv_debug_log_setup(struct batadv_priv *bat_priv)
  29. {
  30. return 0;
  31. }
  32. static inline void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
  33. {
  34. }
  35. #endif
  36. /**
  37. * enum batadv_dbg_level - available log levels
  38. */
  39. enum batadv_dbg_level {
  40. /** @BATADV_DBG_BATMAN: OGM and TQ computations related messages */
  41. BATADV_DBG_BATMAN = BIT(0),
  42. /** @BATADV_DBG_ROUTES: route added / changed / deleted */
  43. BATADV_DBG_ROUTES = BIT(1),
  44. /** @BATADV_DBG_TT: translation table messages */
  45. BATADV_DBG_TT = BIT(2),
  46. /** @BATADV_DBG_BLA: bridge loop avoidance messages */
  47. BATADV_DBG_BLA = BIT(3),
  48. /** @BATADV_DBG_DAT: ARP snooping and DAT related messages */
  49. BATADV_DBG_DAT = BIT(4),
  50. /** @BATADV_DBG_NC: network coding related messages */
  51. BATADV_DBG_NC = BIT(5),
  52. /** @BATADV_DBG_MCAST: multicast related messages */
  53. BATADV_DBG_MCAST = BIT(6),
  54. /** @BATADV_DBG_TP_METER: throughput meter messages */
  55. BATADV_DBG_TP_METER = BIT(7),
  56. /** @BATADV_DBG_ALL: the union of all the above log levels */
  57. BATADV_DBG_ALL = 255,
  58. };
  59. #ifdef CONFIG_BATMAN_ADV_DEBUG
  60. int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
  61. __printf(2, 3);
  62. /**
  63. * _batadv_dbg() - Store debug output with(out) ratelimiting
  64. * @type: type of debug message
  65. * @bat_priv: the bat priv with all the soft interface information
  66. * @ratelimited: whether output should be rate limited
  67. * @fmt: format string
  68. * @arg...: variable arguments
  69. */
  70. #define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...) \
  71. do { \
  72. struct batadv_priv *__batpriv = (bat_priv); \
  73. if (atomic_read(&__batpriv->log_level) & (type) && \
  74. (!(ratelimited) || net_ratelimit())) \
  75. batadv_debug_log(__batpriv, fmt, ## arg); \
  76. } \
  77. while (0)
  78. #else /* !CONFIG_BATMAN_ADV_DEBUG */
  79. __printf(4, 5)
  80. static inline void _batadv_dbg(int type __always_unused,
  81. struct batadv_priv *bat_priv __always_unused,
  82. int ratelimited __always_unused,
  83. const char *fmt __always_unused, ...)
  84. {
  85. }
  86. #endif
  87. /**
  88. * batadv_dbg() - Store debug output without ratelimiting
  89. * @type: type of debug message
  90. * @bat_priv: the bat priv with all the soft interface information
  91. * @arg...: format string and variable arguments
  92. */
  93. #define batadv_dbg(type, bat_priv, arg...) \
  94. _batadv_dbg(type, bat_priv, 0, ## arg)
  95. /**
  96. * batadv_dbg_ratelimited() - Store debug output with ratelimiting
  97. * @type: type of debug message
  98. * @bat_priv: the bat priv with all the soft interface information
  99. * @arg...: format string and variable arguments
  100. */
  101. #define batadv_dbg_ratelimited(type, bat_priv, arg...) \
  102. _batadv_dbg(type, bat_priv, 1, ## arg)
  103. /**
  104. * batadv_info() - Store message in debug buffer and print it to kmsg buffer
  105. * @net_dev: the soft interface net device
  106. * @fmt: format string
  107. * @arg...: variable arguments
  108. */
  109. #define batadv_info(net_dev, fmt, arg...) \
  110. do { \
  111. struct net_device *_netdev = (net_dev); \
  112. struct batadv_priv *_batpriv = netdev_priv(_netdev); \
  113. batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
  114. pr_info("%s: " fmt, _netdev->name, ## arg); \
  115. } while (0)
  116. /**
  117. * batadv_err() - Store error in debug buffer and print it to kmsg buffer
  118. * @net_dev: the soft interface net device
  119. * @fmt: format string
  120. * @arg...: variable arguments
  121. */
  122. #define batadv_err(net_dev, fmt, arg...) \
  123. do { \
  124. struct net_device *_netdev = (net_dev); \
  125. struct batadv_priv *_batpriv = netdev_priv(_netdev); \
  126. batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
  127. pr_err("%s: " fmt, _netdev->name, ## arg); \
  128. } while (0)
  129. #endif /* _NET_BATMAN_ADV_LOG_H_ */