diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2024-12-10 14:34:52 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2024-12-10 14:34:52 +0000 |
commit | bcf2c5ca37a933514dbe840b9d64a3adb0f03f3d (patch) | |
tree | ea9f86a02f9d6d04d3c423bb033255e51969504d /usr.sbin/bgpd | |
parent | bf56d6494be52b3fbdf7a709ebe028b0bc5fbf2b (diff) |
Introduce a SessionDownTimer that is started when a session goes down
and is stopped when the session comes up (ESTABLISHED state).
Right now it is used to remove cloned sessions. For that the SessionDownTimer
is also started when a clone is created.
OK tb@
Diffstat (limited to 'usr.sbin/bgpd')
-rw-r--r-- | usr.sbin/bgpd/bgpd.h | 3 | ||||
-rw-r--r-- | usr.sbin/bgpd/session.c | 31 | ||||
-rw-r--r-- | usr.sbin/bgpd/session.h | 5 |
3 files changed, 27 insertions, 12 deletions
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index 9f435523a5c..b6a90cce936 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.502 2024/12/09 10:51:46 claudio Exp $ */ +/* $OpenBSD: bgpd.h,v 1.503 2024/12/10 14:34:51 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -1761,6 +1761,7 @@ static const char * const timernames[] = { "IdleHoldResetTimer", "CarpUndemoteTimer", "RestartTimer", + "SessionDownTimer", "RTR RefreshTimer", "RTR RetryTimer", "RTR ExpireTimer", diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c index dfa45c500a1..597ac25fd0b 100644 --- a/usr.sbin/bgpd/session.c +++ b/usr.sbin/bgpd/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.501 2024/12/09 10:51:46 claudio Exp $ */ +/* $OpenBSD: session.c,v 1.502 2024/12/10 14:34:51 claudio Exp $ */ /* * Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org> @@ -257,13 +257,6 @@ session_main(int debug, int verbose) /* check for peers to be initialized or deleted */ if (!pending_reconf) { RB_FOREACH_SAFE(p, peer_head, &conf->peers, next) { - /* cloned peer that idled out? */ - if (p->template && (p->state == STATE_IDLE || - p->state == STATE_ACTIVE) && - getmonotime() - p->stats.last_updown >= - INTERVAL_HOLD_CLONED) - p->reconf_action = RECONF_DELETE; - /* new peer that needs init? */ if (p->state == STATE_NONE) init_peer(p); @@ -409,6 +402,14 @@ session_main(int debug, int verbose) Timer_RestartTimeout); session_graceful_stop(p); break; + case Timer_SessionDown: + timer_stop(&p->timers, + Timer_SessionDown); + /* finally delete this cloned peer */ + if (p->template) + p->reconf_action = + RECONF_DELETE; + break; default: fatalx("King Bula lost in time"); } @@ -2266,7 +2267,11 @@ parse_open(struct peer *peer, struct ibuf *msg) return (-1); } - /* if remote-as is zero and it's a cloned neighbor, accept any */ + /* + * if remote-as is zero and it's a cloned neighbor, accept any + * but only on the first connect, after that the remote-as needs + * to remain the same. + */ if (peer->template && !peer->conf.remote_as && as != AS_TRANS) { peer->conf.remote_as = as; peer->conf.ebgp = (peer->conf.remote_as != peer->conf.local_as); @@ -3338,6 +3343,9 @@ getpeerbyip(struct bgpd_config *c, struct sockaddr *ip) newpeer->rpending = 0; newpeer->wbuf = NULL; init_peer(newpeer); + /* start delete timer, it is stopped when session goes up. */ + timer_set(&newpeer->timers, Timer_SessionDown, + INTERVAL_SESSION_DOWN); bgp_fsm(newpeer, EVNT_START, NULL); if (RB_INSERT(peer_head, &c->peers, newpeer) != NULL) fatalx("%s: peer tree is corrupt", __func__); @@ -3426,6 +3434,9 @@ session_down(struct peer *peer) { memset(&peer->capa.neg, 0, sizeof(peer->capa.neg)); peer->stats.last_updown = getmonotime(); + + timer_set(&peer->timers, Timer_SessionDown, INTERVAL_SESSION_DOWN); + /* * session_down is called in the exit code path so check * if the RDE is still around, if not there is no need to @@ -3449,6 +3460,8 @@ session_up(struct peer *p) p->stats.last_rcvd_suberr = 0; memset(p->stats.last_reason, 0, sizeof(p->stats.last_reason)); + timer_stop(&p->timers, Timer_SessionDown); + if (imsg_rde(IMSG_SESSION_ADD, p->conf.id, &p->conf, sizeof(p->conf)) == -1) fatalx("imsg_compose error"); diff --git a/usr.sbin/bgpd/session.h b/usr.sbin/bgpd/session.h index 9759645ec28..34482524ae6 100644 --- a/usr.sbin/bgpd/session.h +++ b/usr.sbin/bgpd/session.h @@ -1,4 +1,4 @@ -/* $OpenBSD: session.h,v 1.180 2024/11/21 13:34:30 claudio Exp $ */ +/* $OpenBSD: session.h,v 1.181 2024/12/10 14:34:51 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -25,8 +25,8 @@ #define INTERVAL_HOLD_INITIAL 240 #define INTERVAL_HOLD 90 #define INTERVAL_IDLE_HOLD_INITIAL 30 -#define INTERVAL_HOLD_CLONED 3600 #define INTERVAL_HOLD_DEMOTED 60 +#define INTERVAL_SESSION_DOWN 3600 #define MAX_IDLE_HOLD 3600 #define MSGSIZE_HEADER 19 #define MSGSIZE_HEADER_MARKER 16 @@ -176,6 +176,7 @@ enum Timer { Timer_IdleHoldReset, Timer_CarpUndemote, Timer_RestartTimeout, + Timer_SessionDown, Timer_Rtr_Refresh, Timer_Rtr_Retry, Timer_Rtr_Expire, |