diff options
author | Joe Perches <joe@perches.com> | 2012-05-13 17:56:25 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-05-15 13:45:02 -0400 |
commit | 3a3bfb61e64476ff1e4ac3122cb6dec9c79b795c (patch) | |
tree | 174111aa514c3d94a0c7953467b335e88b58b364 | |
parent | 9f486619f4545a8e36fa0fcae60722cb9e075887 (diff) |
net: Add net_ratelimited_function and net_<level>_ratelimited macros
__ratelimit() can be considered an inverted bool test because
it returns true when not ratelimited. Several tests in the
kernel tree use this __ratelimit() function incorrectly.
No net_ratelimit uses are incorrect currently though.
Most uses of net_ratelimit are to log something via printk or
pr_<level>.
In order to minimize the uses of net_ratelimit, and to start
standardizing the code style used for __ratelimit() and net_ratelimit(),
add a net_ratelimited_function() macro and net_<level>_ratelimited()
logging macros similar to pr_<level>_ratelimited that use the global
net_ratelimit instead of a static per call site "struct ratelimit_state".
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/linux/net.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/include/linux/net.h b/include/linux/net.h index be60c7f5e145..2d7510f38934 100644 --- a/include/linux/net.h +++ b/include/linux/net.h | |||
@@ -250,6 +250,29 @@ extern struct socket *sockfd_lookup(int fd, int *err); | |||
250 | #define sockfd_put(sock) fput(sock->file) | 250 | #define sockfd_put(sock) fput(sock->file) |
251 | extern int net_ratelimit(void); | 251 | extern int net_ratelimit(void); |
252 | 252 | ||
253 | #define net_ratelimited_function(function, ...) \ | ||
254 | do { \ | ||
255 | if (net_ratelimit()) \ | ||
256 | function(__VA_ARGS__); \ | ||
257 | } while (0) | ||
258 | |||
259 | #define net_emerg_ratelimited(fmt, ...) \ | ||
260 | net_ratelimited_function(pr_emerg, fmt, ##__VA_ARGS__) | ||
261 | #define net_alert_ratelimited(fmt, ...) \ | ||
262 | net_ratelimited_function(pr_alert, fmt, ##__VA_ARGS__) | ||
263 | #define net_crit_ratelimited(fmt, ...) \ | ||
264 | net_ratelimited_function(pr_crit, fmt, ##__VA_ARGS__) | ||
265 | #define net_err_ratelimited(fmt, ...) \ | ||
266 | net_ratelimited_function(pr_err, fmt, ##__VA_ARGS__) | ||
267 | #define net_notice_ratelimited(fmt, ...) \ | ||
268 | net_ratelimited_function(pr_notice, fmt, ##__VA_ARGS__) | ||
269 | #define net_warn_ratelimited(fmt, ...) \ | ||
270 | net_ratelimited_function(pr_warn, fmt, ##__VA_ARGS__) | ||
271 | #define net_info_ratelimited(fmt, ...) \ | ||
272 | net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__) | ||
273 | #define net_dbg_ratelimited(fmt, ...) \ | ||
274 | net_ratelimited_function(pr_debug, fmt, ##__VA_ARGS__) | ||
275 | |||
253 | #define net_random() random32() | 276 | #define net_random() random32() |
254 | #define net_srandom(seed) srandom32((__force u32)seed) | 277 | #define net_srandom(seed) srandom32((__force u32)seed) |
255 | 278 | ||