Index | Thread | Search

From:
Claudio Jeker <cjeker@diehard.n-r-g.com>
Subject:
bgpd: include rtr state in bgpctl output
To:
tech@openbsd.org
Date:
Thu, 11 Jan 2024 12:59:01 +0100

Download raw body.

Thread
bgpctl needs to report the session state to know if a RTR session is up or
not. Without this information the bgpctl show rtr output is unclear.

New output:
RTR neighbor is 192.0.2.138, port 8282
 State: established
 Description: stayrtr
 Version: 1 Session ID: 28339 Serial #: 21
 Refresh: 3600, Retry: 600, Expire: 7200
 Last received error: Unsupported Protocol Version
   with reason "Bad protocol version"

  RTR RefreshTimer     due in 00:57:21     
  RTR ExpireTimer      due in 01:57:21     

RTR neighbor is 127.0.0.1, port 8282
 State: closed
 Description: routinator
 Refresh: 3600, Retry: 600, Expire: 7200

  RTR RetryTimer       due in 00:06:52     
  RTR ExpireTimer      due in 01:56:52     

-- 
:wq Claudio

Index: usr.sbin/bgpctl/output.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpctl/output.c,v
diff -u -p -r1.44 output.c
--- usr.sbin/bgpctl/output.c	10 Jan 2024 14:59:41 -0000	1.44
+++ usr.sbin/bgpctl/output.c	11 Jan 2024 11:55:39 -0000
@@ -1171,12 +1171,13 @@ show_rtr(struct ctl_show_rtr *rtr)
 
 	printf("RTR neighbor is %s, port %u\n",
 	    log_addr(&rtr->remote_addr), rtr->remote_port);
+	printf(" State: %s\n", rtr->state);
 	if (rtr->descr[0])
 		printf(" Description: %s\n", rtr->descr);
 	if (rtr->local_addr.aid != AID_UNSPEC)
 		printf(" Local Address: %s\n", log_addr(&rtr->local_addr));
 	if (rtr->session_id != -1)
-		printf("Version: %u Session ID: %d Serial #: %u\n",
+		printf(" Version: %u Session ID: %d Serial #: %u\n",
 		    rtr->version, rtr->session_id, rtr->serial);
 	printf(" Refresh: %u, Retry: %u, Expire: %u\n",
 	    rtr->refresh, rtr->retry, rtr->expire);
Index: usr.sbin/bgpctl/output_json.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpctl/output_json.c,v
diff -u -p -r1.37 output_json.c
--- usr.sbin/bgpctl/output_json.c	19 Dec 2023 10:32:20 -0000	1.37
+++ usr.sbin/bgpctl/output_json.c	11 Jan 2024 11:55:39 -0000
@@ -1007,6 +1007,7 @@ json_rtr(struct ctl_show_rtr *rtr)
 	json_do_uint("remote_port", rtr->remote_port);
 	if (rtr->local_addr.aid != AID_UNSPEC)
 		json_do_string("local_addr", log_addr(&rtr->local_addr));
+	json_do_string("state", rtr->state);
 
 	if (rtr->session_id != -1) {
 		json_do_uint("version", rtr->version);
Index: usr.sbin/bgpd/bgpd.h
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
diff -u -p -r1.480 bgpd.h
--- usr.sbin/bgpd/bgpd.h	10 Jan 2024 13:31:09 -0000	1.480
+++ usr.sbin/bgpd/bgpd.h	11 Jan 2024 11:55:40 -0000
@@ -562,6 +562,7 @@ struct rtr_config {
 
 struct ctl_show_rtr {
 	char			descr[PEER_DESCR_LEN];
+	char			state[PEER_DESCR_LEN];
 	struct bgpd_addr	remote_addr;
 	struct bgpd_addr	local_addr;
 	uint32_t		serial;
Index: usr.sbin/bgpd/rtr_proto.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rtr_proto.c,v
diff -u -p -r1.29 rtr_proto.c
--- usr.sbin/bgpd/rtr_proto.c	11 Jan 2024 11:43:07 -0000	1.29
+++ usr.sbin/bgpd/rtr_proto.c	11 Jan 2024 11:55:40 -0000
@@ -1509,6 +1509,7 @@ rtr_show(struct rtr_session *rs, pid_t p
 	msg.session_id = rs->session_id;
 	msg.last_sent_error = rs->last_sent_error;
 	msg.last_recv_error = rs->last_recv_error;
+	strlcpy(msg.state, rtr_statenames[rs->state], sizeof(msg.state));
 	strlcpy(msg.last_sent_msg, rs->last_sent_msg,
 	    sizeof(msg.last_sent_msg));
 	strlcpy(msg.last_recv_msg, rs->last_recv_msg,