-/* $OpenBSD: rtr.c,v 1.12 2023/03/09 17:21:21 claudio Exp $ */
+/* $OpenBSD: rtr.c,v 1.13 2023/03/28 12:15:23 claudio Exp $ */
/*
* Copyright (c) 2020 Claudio Jeker <claudio@openbsd.org>
static struct imsgbuf *ibuf_rde;
static struct bgpd_config *conf, *nconf;
static struct timer_head expire_timer;
+static int rtr_recalc_semaphore;
static void
rtr_sighdlr(int sig)
#define EXPIRE_TIMEOUT 300
+void
+rtr_sem_acquire(int cnt)
+{
+ rtr_recalc_semaphore += cnt;
+}
+
+void
+rtr_sem_release(int cnt)
+{
+ rtr_recalc_semaphore -= cnt;
+ if (rtr_recalc_semaphore < 0)
+ fatalx("rtr recalc semaphore underflow");
+}
+
/*
* Every EXPIRE_TIMEOUT seconds traverse the static roa-set table and expire
* all elements where the expires timestamp is smaller or equal to now.
struct aspa_set *aspa;
struct aspa_prep ap = { 0 };
+ if (rtr_recalc_semaphore > 0)
+ return;
+
RB_INIT(&rt);
RB_INIT(&at);
-/* $OpenBSD: rtr_proto.c,v 1.15 2023/03/17 11:14:10 claudio Exp $ */
+/* $OpenBSD: rtr_proto.c,v 1.16 2023/03/28 12:15:23 claudio Exp $ */
/*
* Copyright (c) 2020 Claudio Jeker <claudio@openbsd.org>
#define RTR_DEFAULT_REFRESH 3600
#define RTR_DEFAULT_RETRY 600
#define RTR_DEFAULT_EXPIRE 7200
+#define RTR_DEFAULT_ACTIVE 60
enum rtr_pdu_type {
SERIAL_NOTIFY = 0,
RTR_EVNT_TIMER_REFRESH,
RTR_EVNT_TIMER_RETRY,
RTR_EVNT_TIMER_EXPIRE,
+ RTR_EVNT_TIMER_ACTIVE,
RTR_EVNT_SEND_ERROR,
RTR_EVNT_SERIAL_NOTIFY,
RTR_EVNT_CACHE_RESPONSE,
"refresh timer expired",
"retry timer expired",
"expire timer expired",
+ "activity timer expired",
"sent error",
"serial notify received",
"cache response received",
uint32_t refresh;
uint32_t retry;
uint32_t expire;
+ uint32_t active;
int session_id;
int fd;
+ int active_lock;
enum rtr_state state;
enum reconf_action reconf_action;
enum rtr_error last_sent_error;
rtr_reset_cache(rs);
rtr_recalc();
break;
+ case RTR_EVNT_TIMER_ACTIVE:
+ log_warnx("rtr %s: activity timer fired", log_rtr(rs));
+ rtr_sem_release(rs->active_lock);
+ rtr_recalc();
+ rs->active_lock = 0;
+ break;
case RTR_EVNT_CACHE_RESPONSE:
rs->state = RTR_STATE_ACTIVE;
timer_stop(&rs->timers, Timer_Rtr_Refresh);
timer_stop(&rs->timers, Timer_Rtr_Retry);
- /* XXX start timer to limit active time */
+ timer_set(&rs->timers, Timer_Rtr_Active, rs->active);
+ /* prevent rtr_recalc from running while active */
+ rs->active_lock = 1;
+ rtr_sem_acquire(rs->active_lock);
break;
case RTR_EVNT_END_OF_DATA:
/* start refresh and expire timers */
timer_set(&rs->timers, Timer_Rtr_Refresh, rs->refresh);
timer_set(&rs->timers, Timer_Rtr_Expire, rs->expire);
+ timer_stop(&rs->timers, Timer_Rtr_Active);
rs->state = RTR_STATE_IDLE;
+ rtr_sem_release(rs->active_lock);
rtr_recalc();
+ rs->active_lock = 0;
break;
case RTR_EVNT_CACHE_RESET:
rtr_reset_cache(rs);
case Timer_Rtr_Expire:
rtr_fsm(rs, RTR_EVNT_TIMER_EXPIRE);
break;
+ case Timer_Rtr_Active:
+ rtr_fsm(rs, RTR_EVNT_TIMER_ACTIVE);
+ break;
default:
fatalx("King Bula lost in time");
}
rs->refresh = RTR_DEFAULT_REFRESH;
rs->retry = RTR_DEFAULT_RETRY;
rs->expire = RTR_DEFAULT_EXPIRE;
+ rs->active = RTR_DEFAULT_ACTIVE;
rs->state = RTR_STATE_CLOSED;
rs->reconf_action = RECONF_REINIT;
rs->last_recv_error = NO_ERROR;
-/* $OpenBSD: session.h,v 1.161 2023/03/09 17:21:21 claudio Exp $ */
+/* $OpenBSD: session.h,v 1.162 2023/03/28 12:15:23 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
Timer_Rtr_Refresh,
Timer_Rtr_Retry,
Timer_Rtr_Expire,
+ Timer_Rtr_Active,
Timer_Max
};
void rtr_show(struct rtr_session *, pid_t);
/* rtr.c */
+void rtr_sem_acquire(int);
+void rtr_sem_release(int);
void rtr_roa_insert(struct roa_tree *, struct roa *);
void rtr_aspa_insert(struct aspa_tree *, struct aspa_set *);
void rtr_main(int, int);