410-limit_debug_messages.patch 6.5 KB

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