550-limit_debug_messages.patch 6.6 KB

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