Index | Thread | Search

From:
Claudio Jeker <cjeker@diehard.n-r-g.com>
Subject:
bgpd: rename rtr session states
To:
tech@openbsd.org
Date:
Wed, 3 Jan 2024 16:50:53 +0100

Download raw body.

Thread
The RTR session states are a bit confusing since "idle" and "active" are
also states in the BGP state machine. In BGP "idle" and "active" are
states where the session is not established. So this leads to confusion.

Use "established" instead of "idle" and "exchange" instead of "active".
By default the session will be in "established" state and quicly switch to
"exchange" when a new delta is received. I think these names are better
and less confusing.

OK?
-- 
:wq Claudio

Index: rtr_proto.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rtr_proto.c,v
diff -u -p -r1.20 rtr_proto.c
--- rtr_proto.c	27 Dec 2023 12:00:30 -0000	1.20
+++ rtr_proto.c	30 Dec 2023 09:35:25 -0000
@@ -133,16 +133,16 @@ enum rtr_state {
 	RTR_STATE_CLOSED,
 	RTR_STATE_ERROR,
 	/* sessions with a state below this line will poll for incoming data */
-	RTR_STATE_IDLE,
-	RTR_STATE_ACTIVE,
+	RTR_STATE_ESTABLISHED,
+	RTR_STATE_EXCHANGE,
 	RTR_STATE_NEGOTIATION,
 };
 
 static const char *rtr_statenames[] = {
 	"closed",
 	"error",
-	"idle",
-	"active",
+	"established",
+	"exchange",
 	"negotiation",
 };
 
@@ -465,7 +465,7 @@ rtr_parse_header(struct rtr_session *rs,
 static int
 rtr_parse_notify(struct rtr_session *rs, uint8_t *buf, size_t len)
 {
-	if (rs->state == RTR_STATE_ACTIVE ||
+	if (rs->state == RTR_STATE_EXCHANGE ||
 	    rs->state == RTR_STATE_NEGOTIATION) {
 		log_warnx("rtr %s: received %s: while in state %s (ignored)",
 		    log_rtr(rs), log_rtr_type(SERIAL_NOTIFY),
@@ -480,7 +480,8 @@ rtr_parse_notify(struct rtr_session *rs,
 static int
 rtr_parse_cache_response(struct rtr_session *rs, uint8_t *buf, size_t len)
 {
-	if (rs->state != RTR_STATE_IDLE && rs->state != RTR_STATE_NEGOTIATION) {
+	if (rs->state != RTR_STATE_ESTABLISHED &&
+	    rs->state != RTR_STATE_NEGOTIATION) {
 		log_warnx("rtr %s: received %s: out of context",
 		    log_rtr(rs), log_rtr_type(CACHE_RESPONSE));
 		return -1;
@@ -503,7 +504,7 @@ rtr_parse_ipv4_prefix(struct rtr_session
 		return -1;
 	}
 
-	if (rs->state != RTR_STATE_ACTIVE) {
+	if (rs->state != RTR_STATE_EXCHANGE) {
 		log_warnx("rtr %s: received %s: out of context",
 		    log_rtr(rs), log_rtr_type(IPV4_PREFIX));
 		rtr_send_error(rs, CORRUPT_DATA, NULL, buf, len);
@@ -572,7 +573,7 @@ rtr_parse_ipv6_prefix(struct rtr_session
 		return -1;
 	}
 
-	if (rs->state != RTR_STATE_ACTIVE) {
+	if (rs->state != RTR_STATE_EXCHANGE) {
 		log_warnx("rtr %s: received %s: out of context",
 		    log_rtr(rs), log_rtr_type(IPV6_PREFIX));
 		rtr_send_error(rs, CORRUPT_DATA, NULL, buf, len);
@@ -646,7 +647,7 @@ rtr_parse_aspa(struct rtr_session *rs, u
 		return -1;
 	}
 
-	if (rs->state != RTR_STATE_ACTIVE) {
+	if (rs->state != RTR_STATE_EXCHANGE) {
 		log_warnx("rtr %s: received %s: out of context",
 		    log_rtr(rs), log_rtr_type(ASPA));
 		rtr_send_error(rs, CORRUPT_DATA, NULL, buf, len);
@@ -732,7 +733,7 @@ rtr_parse_end_of_data(struct rtr_session
 		return -1;
 	}
 
-	if (rs->state != RTR_STATE_ACTIVE) {
+	if (rs->state != RTR_STATE_EXCHANGE) {
 		log_warnx("rtr %s: received %s: out of context",
 		    log_rtr(rs), log_rtr_type(END_OF_DATA));
 		return -1;
@@ -769,7 +770,7 @@ bad:
 static int
 rtr_parse_cache_reset(struct rtr_session *rs, uint8_t *buf, size_t len)
 {
-	if (rs->state != RTR_STATE_IDLE) {
+	if (rs->state != RTR_STATE_ESTABLISHED) {
 		log_warnx("rtr %s: received %s: out of context",
 		    log_rtr(rs), log_rtr_type(CACHE_RESET));
 		return -1;
@@ -1048,7 +1049,7 @@ rtr_fsm(struct rtr_session *rs, enum rtr
 		rs->active_lock = 0;
 		break;
 	case RTR_EVNT_CACHE_RESPONSE:
-		rs->state = RTR_STATE_ACTIVE;
+		rs->state = RTR_STATE_EXCHANGE;
 		timer_stop(&rs->timers, Timer_Rtr_Refresh);
 		timer_stop(&rs->timers, Timer_Rtr_Retry);
 		timer_set(&rs->timers, Timer_Rtr_Active, rs->active);
@@ -1061,7 +1062,7 @@ rtr_fsm(struct rtr_session *rs, enum rtr
 		timer_set(&rs->timers, Timer_Rtr_Refresh, rs->refresh);
 		timer_set(&rs->timers, Timer_Rtr_Expire, rs->expire);
 		timer_stop(&rs->timers, Timer_Rtr_Active);
-		rs->state = RTR_STATE_IDLE;
+		rs->state = RTR_STATE_ESTABLISHED;
 		rtr_sem_release(rs->active_lock);
 		rtr_recalc();
 		rs->active_lock = 0;
@@ -1078,7 +1079,7 @@ rtr_fsm(struct rtr_session *rs, enum rtr
 		timer_set(&rs->timers, Timer_Rtr_Retry, rs->retry);
 		/* stop refresh timer just to be sure */
 		timer_stop(&rs->timers, Timer_Rtr_Refresh);
-		rs->state = RTR_STATE_IDLE;
+		rs->state = RTR_STATE_ESTABLISHED;
 		break;
 	case RTR_EVNT_SEND_ERROR:
 		rtr_reset_cache(rs);
@@ -1232,7 +1233,7 @@ rtr_poll_events(struct pollfd *pfds, siz
 
 		if (rs->w.queued)
 			pfd->events |= POLLOUT;
-		if (rs->state >= RTR_STATE_IDLE)
+		if (rs->state >= RTR_STATE_ESTABLISHED)
 			pfd->events |= POLLIN;
 	}