410-limit_debug_messages.patch 6.5 KB

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