Index | Thread | Search

From:
Claudio Jeker <cjeker@diehard.n-r-g.com>
Subject:
bgpd: simplify / fix path_id_tx assignment in peer_add
To:
tech@openbsd.org
Date:
Thu, 7 May 2026 10:51:30 +0200

Download raw body.

Thread
The logic in peer_add() to handle 0 path_id_tx values is a bit convoluted
and theoretically the first peer could end up with a 0 value since the
RB_FOREACH block is skipped.

Let's write this in a way that is more obvious.
-- 
:wq Claudio

Index: rde_peer.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde_peer.c,v
diff -u -p -r1.70 rde_peer.c
--- rde_peer.c	2 Mar 2026 12:08:30 -0000	1.70
+++ rde_peer.c	6 May 2026 08:37:00 -0000
@@ -192,11 +192,11 @@ peer_add(uint32_t id, struct peer_config
 	do {
 		struct rde_peer *p;
 
+		while ((peer->path_id_tx = arc4random() << 1) == 0)
+			;
 		conflict = 0;
-		peer->path_id_tx = arc4random() << 1;
 		RB_FOREACH(p, peer_tree, &peertable) {
-			if (peer->path_id_tx == 0 ||
-			    p->path_id_tx == peer->path_id_tx) {
+			if (p->path_id_tx == peer->path_id_tx) {
 				conflict = 1;
 				break;
 			}