log.h 4.0 KB

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