summaryrefslogtreecommitdiffstats
path: root/sysdep/unix
diff options
context:
space:
mode:
Diffstat (limited to 'sysdep/unix')
-rw-r--r--sysdep/unix/krt.c22
-rw-r--r--sysdep/unix/log.c32
2 files changed, 44 insertions, 10 deletions
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