log.h 3.4 KB

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