550-limit_debug_messages.patch 6.5 KB

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