Index | Thread | Search

From:
Claudio Jeker <cjeker@diehard.n-r-g.com>
Subject:
bgpd: fix peer match logic
To:
tech@openbsd.org
Date:
Mon, 28 Oct 2024 13:35:16 +0100

Download raw body.

Thread
I noticed that the "no such peer" logic is actually incorrect.
We want to send an error when there was no match but only if there are
neighbors configured. So the check for RB_EMPTY() needs to be reversed.

Another option is to remove the RB_EMPTY() checks all together. Then
'bgpctl show' would print 'no such neighbor' when no neighbor is
configured. Do we care about that?
-- 
:wq Claudio

Index: control.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/control.c,v
diff -u -p -r1.120 control.c
--- control.c	1 Oct 2024 18:31:10 -0000	1.120
+++ control.c	28 Oct 2024 12:07:40 -0000
@@ -352,7 +352,7 @@ control_dispatch_msg(struct pollfd *pfd,
 					}
 				}
 			}
-			if (!matched && RB_EMPTY(peers)) {
+			if (!matched && !RB_EMPTY(peers)) {
 				control_result(c, CTL_RES_NOSUCHPEER);
 			} else if (!neighbor.show_timers) {
 				imsg_ctl_rde_msg(IMSG_CTL_END, 0, pid);
@@ -473,7 +473,7 @@ control_dispatch_msg(struct pollfd *pfd,
 			RB_FOREACH(p, peer_head, peers)
 				if (peer_matched(p, &ribreq.neighbor))
 					break;
-			if (p == NULL && RB_EMPTY(peers)) {
+			if (p == NULL && !RB_EMPTY(peers)) {
 				control_result(c, CTL_RES_NOSUCHPEER);
 				break;
 			}