410-limit_debug_messages.patch 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. From: Felix Fietkau <[email protected]>
  2. Date: Mon, 20 Feb 2012 23:41:52 +0000
  3. Subject: [PATCH] hostapd: add configurable debug message minimum priority to
  4. cut down on bloat generated by excessive debug messages
  5. --- a/src/utils/wpa_debug.c
  6. +++ b/src/utils/wpa_debug.c
  7. @@ -206,7 +206,7 @@ void wpa_debug_close_linux_tracing(void)
  8. *
  9. * Note: New line '\n' is added to the end of the text when printing to stdout.
  10. */
  11. -void wpa_printf(int level, const char *fmt, ...)
  12. +void _wpa_printf(int level, const char *fmt, ...)
  13. {
  14. va_list ap;
  15. @@ -255,7 +255,7 @@ void wpa_printf(int level, const char *f
  16. }
  17. -static void _wpa_hexdump(int level, const char *title, const u8 *buf,
  18. +void _wpa_hexdump(int level, const char *title, const u8 *buf,
  19. size_t len, int show, int only_syslog)
  20. {
  21. size_t i;
  22. @@ -382,19 +382,7 @@ static void _wpa_hexdump(int level, cons
  23. #endif /* CONFIG_ANDROID_LOG */
  24. }
  25. -void wpa_hexdump(int level, const char *title, const void *buf, size_t len)
  26. -{
  27. - _wpa_hexdump(level, title, buf, len, 1, 0);
  28. -}
  29. -
  30. -
  31. -void wpa_hexdump_key(int level, const char *title, const void *buf, size_t len)
  32. -{
  33. - _wpa_hexdump(level, title, buf, len, wpa_debug_show_keys, 0);
  34. -}
  35. -
  36. -
  37. -static void _wpa_hexdump_ascii(int level, const char *title, const void *buf,
  38. +void _wpa_hexdump_ascii(int level, const char *title, const void *buf,
  39. size_t len, int show)
  40. {
  41. size_t i, llen;
  42. @@ -507,20 +495,6 @@ file_done:
  43. }
  44. -void wpa_hexdump_ascii(int level, const char *title, const void *buf,
  45. - size_t len)
  46. -{
  47. - _wpa_hexdump_ascii(level, title, buf, len, 1);
  48. -}
  49. -
  50. -
  51. -void wpa_hexdump_ascii_key(int level, const char *title, const void *buf,
  52. - size_t len)
  53. -{
  54. - _wpa_hexdump_ascii(level, title, buf, len, wpa_debug_show_keys);
  55. -}
  56. -
  57. -
  58. #ifdef CONFIG_DEBUG_FILE
  59. static char *last_path = NULL;
  60. #endif /* CONFIG_DEBUG_FILE */
  61. @@ -644,7 +618,7 @@ void wpa_msg_register_ifname_cb(wpa_msg_
  62. }
  63. -void wpa_msg(void *ctx, int level, const char *fmt, ...)
  64. +void _wpa_msg(void *ctx, int level, const char *fmt, ...)
  65. {
  66. va_list ap;
  67. char *buf;
  68. @@ -682,7 +656,7 @@ void wpa_msg(void *ctx, int level, const
  69. }
  70. -void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
  71. +void _wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
  72. {
  73. va_list ap;
  74. char *buf;
  75. --- a/src/utils/wpa_debug.h
  76. +++ b/src/utils/wpa_debug.h
  77. @@ -52,6 +52,17 @@ void wpa_debug_close_file(void);
  78. void wpa_debug_setup_stdout(void);
  79. void wpa_debug_stop_log(void);
  80. +/* internal */
  81. +void _wpa_hexdump(int level, const char *title, const u8 *buf,
  82. + size_t len, int show, int only_syslog);
  83. +void _wpa_hexdump_ascii(int level, const char *title, const void *buf,
  84. + size_t len, int show);
  85. +extern int wpa_debug_show_keys;
  86. +
  87. +#ifndef CONFIG_MSG_MIN_PRIORITY
  88. +#define CONFIG_MSG_MIN_PRIORITY 0
  89. +#endif
  90. +
  91. /**
  92. * wpa_debug_printf_timestamp - Print timestamp for debug output
  93. *
  94. @@ -72,9 +83,15 @@ void wpa_debug_print_timestamp(void);
  95. *
  96. * Note: New line '\n' is added to the end of the text when printing to stdout.
  97. */
  98. -void wpa_printf(int level, const char *fmt, ...)
  99. +void _wpa_printf(int level, const char *fmt, ...)
  100. PRINTF_FORMAT(2, 3);
  101. +#define wpa_printf(level, ...) \
  102. + do { \
  103. + if (level >= CONFIG_MSG_MIN_PRIORITY) \
  104. + _wpa_printf(level, __VA_ARGS__); \
  105. + } while(0)
  106. +
  107. /**
  108. * wpa_hexdump - conditional hex dump
  109. * @level: priority level (MSG_*) of the message
  110. @@ -86,7 +103,13 @@ PRINTF_FORMAT(2, 3);
  111. * output may be directed to stdout, stderr, and/or syslog based on
  112. * configuration. The contents of buf is printed out has hex dump.
  113. */
  114. -void wpa_hexdump(int level, const char *title, const void *buf, size_t len);
  115. +static inline void wpa_hexdump(int level, const char *title, const void *buf, size_t len)
  116. +{
  117. + if (level < CONFIG_MSG_MIN_PRIORITY)
  118. + return;
  119. +
  120. + _wpa_hexdump(level, title, buf, len, 1, 1);
  121. +}
  122. static inline void wpa_hexdump_buf(int level, const char *title,
  123. const struct wpabuf *buf)
  124. @@ -108,7 +131,13 @@ static inline void wpa_hexdump_buf(int l
  125. * like wpa_hexdump(), but by default, does not include secret keys (passwords,
  126. * etc.) in debug output.
  127. */
  128. -void wpa_hexdump_key(int level, const char *title, const void *buf, size_t len);
  129. +static inline void wpa_hexdump_key(int level, const char *title, const u8 *buf, size_t len)
  130. +{
  131. + if (level < CONFIG_MSG_MIN_PRIORITY)
  132. + return;
  133. +
  134. + _wpa_hexdump(level, title, buf, len, wpa_debug_show_keys, 1);
  135. +}
  136. static inline void wpa_hexdump_buf_key(int level, const char *title,
  137. const struct wpabuf *buf)
  138. @@ -130,8 +159,14 @@ static inline void wpa_hexdump_buf_key(i
  139. * the hex numbers and ASCII characters (for printable range) are shown. 16
  140. * bytes per line will be shown.
  141. */
  142. -void wpa_hexdump_ascii(int level, const char *title, const void *buf,
  143. - size_t len);
  144. +static inline void wpa_hexdump_ascii(int level, const char *title,
  145. + const u8 *buf, size_t len)
  146. +{
  147. + if (level < CONFIG_MSG_MIN_PRIORITY)
  148. + return;
  149. +
  150. + _wpa_hexdump_ascii(level, title, buf, len, 1);
  151. +}
  152. /**
  153. * wpa_hexdump_ascii_key - conditional hex dump, hide keys
  154. @@ -147,8 +182,14 @@ void wpa_hexdump_ascii(int level, const
  155. * bytes per line will be shown. This works like wpa_hexdump_ascii(), but by
  156. * default, does not include secret keys (passwords, etc.) in debug output.
  157. */
  158. -void wpa_hexdump_ascii_key(int level, const char *title, const void *buf,
  159. - size_t len);
  160. +static inline void wpa_hexdump_ascii_key(int level, const char *title,
  161. + const u8 *buf, size_t len)
  162. +{
  163. + if (level < CONFIG_MSG_MIN_PRIORITY)
  164. + return;
  165. +
  166. + _wpa_hexdump_ascii(level, title, buf, len, wpa_debug_show_keys);
  167. +}
  168. /*
  169. * wpa_dbg() behaves like wpa_msg(), but it can be removed from build to reduce
  170. @@ -185,7 +226,12 @@ void wpa_hexdump_ascii_key(int level, co
  171. *
  172. * Note: New line '\n' is added to the end of the text when printing to stdout.
  173. */
  174. -void wpa_msg(void *ctx, int level, const char *fmt, ...) PRINTF_FORMAT(3, 4);
  175. +void _wpa_msg(void *ctx, int level, const char *fmt, ...) PRINTF_FORMAT(3, 4);
  176. +#define wpa_msg(ctx, level, ...) \
  177. + do { \
  178. + if (level >= CONFIG_MSG_MIN_PRIORITY) \
  179. + _wpa_msg(ctx, level, __VA_ARGS__); \
  180. + } while(0)
  181. /**
  182. * wpa_msg_ctrl - Conditional printf for ctrl_iface monitors
  183. @@ -199,8 +245,13 @@ void wpa_msg(void *ctx, int level, const
  184. * attached ctrl_iface monitors. In other words, it can be used for frequent
  185. * events that do not need to be sent to syslog.
  186. */
  187. -void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
  188. +void _wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
  189. PRINTF_FORMAT(3, 4);
  190. +#define wpa_msg_ctrl(ctx, level, ...) \
  191. + do { \
  192. + if (level >= CONFIG_MSG_MIN_PRIORITY) \
  193. + _wpa_msg_ctrl(ctx, level, __VA_ARGS__); \
  194. + } while(0)
  195. /**
  196. * wpa_msg_global - Global printf for ctrl_iface monitors