summaryrefslogtreecommitdiffstats
path: root/sysdep
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2009-02-26 14:23:54 +0100
committerOndrej Zajicek <santiago@crfreenet.org>2009-02-26 14:23:54 +0100
commitcb5303927188de9504a6e18aedec299956a22b6f (patch)
tree0d8ac146c9d84b85e382fb994d9e10688c2e3e36 /sysdep
parenta9dc5e1ef2fd08c53bceb54690f6dac83ddf0c81 (diff)
downloadbird-cb5303927188de9504a6e18aedec299956a22b6f.tar
bird-cb5303927188de9504a6e18aedec299956a22b6f.zip
Rate limit for most abundant log messages
Diffstat (limited to 'sysdep')
-rw-r--r--sysdep/linux/netlink/netlink.c4
-rw-r--r--sysdep/unix/krt.c22
-rw-r--r--sysdep/unix/log.c32
3 files changed, 47 insertions, 11 deletions
diff --git a/sysdep/linux/netlink/netlink.c b/sysdep/linux/netlink/netlink.c
index 08817ca..734247e 100644
--- a/sysdep/linux/netlink/netlink.c
+++ b/sysdep/linux/netlink/netlink.c
@@ -129,6 +129,8 @@ nl_get_reply(void)
}
}
+static struct rate_limit rl_netlink_err;
+
static int
nl_error(struct nlmsghdr *h)
{
@@ -143,7 +145,7 @@ nl_error(struct nlmsghdr *h)
e = (struct nlmsgerr *) NLMSG_DATA(h);
ec = -e->error;
if (ec)
- log(L_WARN "Netlink: %s", strerror(ec));
+ log_rl(&rl_netlink_err, L_WARN "Netlink: %s", strerror(ec));
return ec;
}
diff --git a/sysdep/unix/krt.c b/sysdep/unix/krt.c
index fded9ab..816eb44 100644
--- a/sysdep/unix/krt.c
+++ b/sysdep/unix/krt.c
@@ -183,18 +183,18 @@ struct protocol proto_unix_iface = {
* Tracing of routes
*/
-static void
-krt_trace_in_print(struct krt_proto *p, rte *e, char *msg)
+static inline void
+krt_trace_in(struct krt_proto *p, rte *e, char *msg)
{
- DBG("KRT: %I/%d: %s\n", e->net->n.prefix, e->net->n.pxlen, msg);
- log(L_TRACE "%s: %I/%d: %s", p->p.name, e->net->n.prefix, e->net->n.pxlen, msg);
+ if (p->p.debug & D_PACKETS)
+ log(L_TRACE "%s: %I/%d: %s", p->p.name, e->net->n.prefix, e->net->n.pxlen, msg);
}
static inline void
-krt_trace_in(struct krt_proto *p, rte *e, char *msg)
+krt_trace_in_rl(struct rate_limit *rl, struct krt_proto *p, rte *e, char *msg)
{
if (p->p.debug & D_PACKETS)
- krt_trace_in_print(p, e, msg);
+ log_rl(rl, L_TRACE "%s: %I/%d: %s", p->p.name, e->net->n.prefix, e->net->n.pxlen, msg);
}
/*
@@ -203,6 +203,8 @@ krt_trace_in(struct krt_proto *p, rte *e, char *msg)
#ifdef KRT_ALLOW_LEARN
+static struct rate_limit rl_alien_seen, rl_alien_updated, rl_alien_created, rl_alien_ignored;
+
static inline int
krt_same_key(rte *a, rte *b)
{
@@ -249,20 +251,20 @@ krt_learn_scan(struct krt_proto *p, rte *e)
{
if (krt_uptodate(m, e))
{
- krt_trace_in(p, e, "[alien] seen");
+ krt_trace_in_rl(&rl_alien_seen, p, e, "[alien] seen");
rte_free(e);
m->u.krt.seen = 1;
}
else
{
- krt_trace_in(p, e, "[alien] updated");
+ krt_trace_in_rl(&rl_alien_updated, p, e, "[alien] updated");
*mm = m->next;
rte_free(m);
m = NULL;
}
}
else
- krt_trace_in(p, e, "[alien] created");
+ krt_trace_in_rl(&rl_alien_created, p, e, "[alien] created");
if (!m)
{
e->attrs = rta_lookup(e->attrs);
@@ -516,7 +518,7 @@ krt_got_route(struct krt_proto *p, rte *e)
krt_learn_scan(p, e);
else
{
- krt_trace_in(p, e, "alien route, ignored");
+ krt_trace_in_rl(&rl_alien_ignored, p, e, "alien route, ignored");
rte_free(e);
}
return;
diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c
index 08711e1..eb08309 100644
--- a/sysdep/unix/log.c
+++ b/sysdep/unix/log.c
@@ -30,6 +30,9 @@ static FILE *dbgf = NULL;
static list *current_log_list;
static list init_log_list;
+bird_clock_t rate_limit_time = 5;
+int rate_limit_count = 5;
+
#ifdef HAVE_SYSLOG
#include <sys/syslog.h>
@@ -126,6 +129,35 @@ log_msg(char *msg, ...)
va_end(args);
}
+void
+log_rl(struct rate_limit *rl, char *msg, ...)
+{
+ int class = 1;
+ va_list args;
+
+ bird_clock_t delta = now - rl->timestamp;
+ if ((0 <= delta) && (delta < rate_limit_time))
+ {
+ rl->count++;
+ }
+ else
+ {
+ rl->timestamp = now;
+ rl->count = 1;
+ }
+
+ if (rl->count > rate_limit_count)
+ return;
+
+ va_start(args, msg);
+ if (*msg >= 1 && *msg <= 8)
+ class = *msg++;
+ vlog(class, msg, args);
+ if (rl->count == rate_limit_count)
+ vlog(class, "...", args);
+ va_end(args);
+}
+
/**
* bug - report an internal error
* @msg: a printf-like error message