From: claudio Date: Wed, 28 Aug 2024 13:21:39 +0000 (+0000) Subject: Introduce peer_is_up() and use it instead of peer->state == PEER_UP checks X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c4328fc634db1e3992e000a04a70634da0a5e4c3;p=openbsd Introduce peer_is_up() and use it instead of peer->state == PEER_UP checks also enqueue update and rrfresh imsgs only if the peer is up and flush them once this is no longer the case. OK tb@ --- diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index eefd7880def..d72afb28051 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.628 2024/08/28 13:18:11 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.629 2024/08/28 13:21:39 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -398,7 +398,8 @@ rde_dispatch_imsg_session(struct imsgbuf *imsgbuf) peerid); break; } - peer_imsg_push(peer, &imsg); + if (peer_is_up(peer)) + peer_imsg_push(peer, &imsg); break; case IMSG_SESSION_ADD: if (imsg_get_data(&imsg, &pconf, sizeof(pconf)) == -1) @@ -1311,13 +1312,16 @@ rde_dispatch_imsg_peer(struct rde_peer *peer, void *bula) struct imsg imsg; struct ibuf ibuf; + if (!peer_is_up(peer)) { + peer_imsg_flush(peer); + return; + } + if (!peer_imsg_pop(peer, &imsg)) return; switch (imsg_get_type(&imsg)) { case IMSG_UPDATE: - if (peer->state != PEER_UP) - break; if (imsg_get_ibuf(&imsg, &ibuf) == -1) log_warn("update: bad imsg"); else @@ -3332,7 +3336,7 @@ rde_update_queue_pending(void) RB_FOREACH(peer, peer_tree, &peertable) { if (peer->conf.id == 0) continue; - if (peer->state != PEER_UP) + if (!peer_is_up(peer)) continue; if (peer->throttled) continue; @@ -3358,7 +3362,7 @@ rde_update_queue_runner(uint8_t aid) RB_FOREACH(peer, peer_tree, &peertable) { if (peer->conf.id == 0) continue; - if (peer->state != PEER_UP) + if (!peer_is_up(peer)) continue; if (peer->throttled) continue; @@ -3387,7 +3391,7 @@ rde_update_queue_runner(uint8_t aid) RB_FOREACH(peer, peer_tree, &peertable) { if (peer->conf.id == 0) continue; - if (peer->state != PEER_UP) + if (!peer_is_up(peer)) continue; if (peer->throttled) continue; diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h index 899833da05f..78494240aea 100644 --- a/usr.sbin/bgpd/rde.h +++ b/usr.sbin/bgpd/rde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.h,v 1.304 2024/08/14 19:09:51 claudio Exp $ */ +/* $OpenBSD: rde.h,v 1.305 2024/08/28 13:21:39 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker and @@ -379,6 +379,12 @@ int peer_imsg_pop(struct rde_peer *, struct imsg *); int peer_imsg_pending(void); void peer_imsg_flush(struct rde_peer *); +static inline int +peer_is_up(struct rde_peer *peer) +{ + return (peer->state == PEER_UP); +} + RB_PROTOTYPE(peer_tree, rde_peer, entry, peer_cmp); /* rde_attr.c */ diff --git a/usr.sbin/bgpd/rde_peer.c b/usr.sbin/bgpd/rde_peer.c index 9ddd692266c..351c0b4415a 100644 --- a/usr.sbin/bgpd/rde_peer.c +++ b/usr.sbin/bgpd/rde_peer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_peer.c,v 1.37 2024/05/22 08:41:14 claudio Exp $ */ +/* $OpenBSD: rde_peer.c,v 1.38 2024/08/28 13:21:39 claudio Exp $ */ /* * Copyright (c) 2019 Claudio Jeker @@ -234,7 +234,7 @@ peer_generate_update(struct rde_peer *peer, struct rib_entry *re, /* skip ourself */ if (peer == peerself) return; - if (peer->state != PEER_UP) + if (!peer_is_up(peer)) return; /* skip peers using a different rib */ if (peer->loc_rib_id != re->rib_id)