Introduce peer_is_up() and use it instead of peer->state == PEER_UP checks
authorclaudio <claudio@openbsd.org>
Wed, 28 Aug 2024 13:21:39 +0000 (13:21 +0000)
committerclaudio <claudio@openbsd.org>
Wed, 28 Aug 2024 13:21:39 +0000 (13:21 +0000)
also enqueue update and rrfresh imsgs only if the peer is up and flush them
once this is no longer the case.
OK tb@

usr.sbin/bgpd/rde.c
usr.sbin/bgpd/rde.h
usr.sbin/bgpd/rde_peer.c

index eefd788..d72afb2 100644 (file)
@@ -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 <henning@openbsd.org>
@@ -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;
index 899833d..7849424 100644 (file)
@@ -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 <claudio@openbsd.org> 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 */
index 9ddd692..351c0b4 100644 (file)
@@ -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 <claudio@openbsd.org>
@@ -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)