if (config_timer->expires == 0)
return CONF_NOTHING;
- tm_stop(config_timer);
+ tm2_stop(config_timer);
return CONF_CONFIRM;
}
return CONF_NOTHING;
undo_available = 0;
- tm_stop(config_timer);
+ tm2_stop(config_timer);
if (configuring)
{
config_event = ev_new(&root_pool);
config_event->hook = config_done;
- config_timer = tm_new(&root_pool);
+ config_timer = tm2_new(&root_pool);
config_timer->hook = config_timeout;
}
/* Microsecond time */
typedef s64 btime;
-typedef s64 bird_clock_t;
+//typedef s64 bird_clock_t;
#define S_ * (btime) 1000000
#define MS_ * (btime) 1000
#define NS /1000
#endif
+#define TIME_INFINITY ((s64) 0x7fffffffffffffff)
+
/* Rate limiting */
struct tbf {
- bird_clock_t timestamp; /* Last update */
- u16 count; /* Available tokens */
+ btime timestamp; /* Last update */
+ u64 count; /* Available micro-tokens */
u16 burst; /* Max number of tokens */
- u16 rate; /* Rate of replenishment */
- u16 mark; /* Whether last op was limited */
+ u16 rate; /* Rate of replenishment (tokens / sec) */
+ u32 drop; /* Number of failed request since last successful */
};
/* Default TBF values for rate limiting log messages */
#define TBF_DEFAULT_LOG_LIMITS { .rate = 1, .burst = 5 }
-void tbf_update(struct tbf *f);
-
-static inline int
-tbf_limit(struct tbf *f)
-{
- tbf_update(f);
-
- if (!f->count)
- {
- f->mark = 1;
- return 1;
- }
-
- f->count--;
- f->mark = 0;
- return 0;
-}
+int tbf_limit(struct tbf *f);
/* Logging and dying */
#include "nest/bird.h"
#include "lib/timer.h"
-void
-tbf_update(struct tbf *f)
+int
+tbf_limit(struct tbf *f)
{
- bird_clock_t delta = now - f->timestamp;
+ btime delta = current_time() - f->timestamp;
- if (delta == 0)
- return;
-
- f->timestamp = now;
+ if (delta > 0)
+ {
+ u64 next = f->count + delta * f->rate;
+ u64 burst = (u64) f->burst << 20;
+ f->count = MIN(next, burst);
+ f->timestamp += delta;
+ }
- if ((0 < delta) && (delta < f->burst))
+ if (f->count < 1000000)
{
- u32 next = f->count + delta * f->rate;
- f->count = MIN(next, f->burst);
+ f->drop++;
+ return 1;
}
else
- f->count = f->burst;
+ {
+ f->count -= 1000000;
+ f->drop = 0;
+ return 0;
+ }
}
btime current_time(void);
btime current_real_time(void);
-#define now (current_time() TO_S)
-#define now_real (current_real_time() TO_S)
+//#define now (current_time() TO_S)
+//#define now_real (current_real_time() TO_S)
extern btime boot_time;
timer2 *tm2_new(pool *p);
#endif
proto_pool = rp_new(&root_pool, "Protocols");
- proto_shutdown_timer = tm_new(proto_pool);
+ proto_shutdown_timer = tm2_new(proto_pool);
proto_shutdown_timer->hook = proto_shutdown_loop;
}
log_rl(&p->log_lsa_tbf, L_REMOTE "%s: " msg, p->p.name, args)
#define LOG_LSA2(msg, args...) \
- do { if (! p->log_lsa_tbf.mark) \
+ do { if (! p->log_lsa_tbf.drop) \
log(L_REMOTE "%s: " msg, p->p.name, args); } while(0)
* have the same CSN. We are using real time, but enforcing monotonicity.
*/
if (ifa->cf->auth_type == RIP_AUTH_CRYPTO)
- ifa->csn = (ifa->csn < (u32) now_real) ? (u32) now_real : ifa->csn + 1;
+ {
+ u32 now_real = (u32) (current_real_time() TO_S);
+ ifa->csn = (ifa->csn < now_real) ? now_real : ifa->csn + 1;
+ }
}
static void
nl->fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (nl->fd < 0)
die("Unable to open rtnetlink socket: %m");
- nl->seq = now;
+ nl->seq = (u32) (current_time() TO_S); /* Or perhaps random_u32() ? */
nl->rx_buffer = xmalloc(NL_RX_SIZE);
nl->last_hdr = NULL;
nl->last_size = 0;
// XXX init_times();
// XXX update_times();
boot_time = current_time();
- srandom((int) now_real);
+ srandom((uint) (current_real_time() TO_S));
}
static int short_loops = 0;
void
log_rl(struct tbf *f, const char *msg, ...)
{
- int last_hit = f->mark;
int class = 1;
va_list args;
/* Rate limiting is a bit tricky here as it also logs '...' during the first hit */
- if (tbf_limit(f) && last_hit)
+ if (tbf_limit(f) && (f->drop > 1))
return;
if (*msg >= 1 && *msg <= 8)
class = *msg++;
va_start(args, msg);
- vlog(class, (f->mark ? "..." : msg), args);
+ vlog(class, (f->drop ? "..." : msg), args);
va_end(args);
}
mrt_dump_message(struct proto *p, u16 type, u16 subtype, byte *buf, u32 len)
{
/* Prepare header */
- put_u32(buf+0, now_real);
+ put_u32(buf+0, current_real_time() TO_S);
put_u16(buf+4, type);
put_u16(buf+6, subtype);
put_u32(buf+8, len - MRTDUMP_HDR_LENGTH);
typedef struct timer2 timer;
-
+#if 0
static inline timer *tm_new(pool *p)
{ return (void *) tm2_new(p); }
static inline timer * tm_new_set(pool *p, void (*hook)(timer *), void *data, uint rand, uint rec)
{ return tm2_new_init(p, hook, data, rec S_, rand S_); }
+#endif
-#define TIME_INFINITY ((s64) 0x7fffffffffffffff)
#endif