Index | Thread | Search

From:
Claudio Jeker <cjeker@diehard.n-r-g.com>
Subject:
bgpd: make session
To:
tech@openbsd.org
Date:
Tue, 11 Feb 2025 17:41:04 +0100

Download raw body.

Thread
  • Claudio Jeker:

    bgpd: make session

All session_xyz functions take a struct peer * as arguement with the
exception of session_update(). Make it the same pass in struct peer and
look it up in the imsg handler like for all other calls.

In the imsg handler add the imsg to the "no such peer" error message.
Now this error should never show but if it does it helps to know where to
look.

-- 
:wq Claudio

Index: session.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/session.c,v
diff -u -p -r1.512 session.c
--- session.c	11 Feb 2025 14:29:05 -0000	1.512
+++ session.c	11 Feb 2025 16:34:37 -0000
@@ -71,7 +71,7 @@ struct ibuf	*session_newmsg(enum msg_typ
 void	session_sendmsg(struct ibuf *, struct peer *, enum msg_type);
 void	session_open(struct peer *);
 void	session_keepalive(struct peer *);
-void	session_update(uint32_t, struct ibuf *);
+void	session_update(struct peer *, struct ibuf *);
 void	session_notification(struct peer *, uint8_t, uint8_t, struct ibuf *);
 void	session_notification_data(struct peer *, uint8_t, uint8_t, void *,
 	    size_t);
@@ -1700,17 +1700,11 @@ session_keepalive(struct peer *p)
 }
 
 void
-session_update(uint32_t peerid, struct ibuf *ibuf)
+session_update(struct peer *p, struct ibuf *ibuf)
 {
-	struct peer	*p;
 	struct ibuf	*buf;
 	size_t		 len, maxsize = MAX_PKTSIZE;
 
-	if ((p = getpeerbyid(conf, peerid)) == NULL) {
-		log_warnx("%s: no such peer: id=%u", __func__, peerid);
-		return;
-	}
-
 	if (p->state != STATE_ESTABLISHED)
 		return;
 
@@ -3125,7 +3119,8 @@ session_dispatch_imsg(struct imsgbuf *im
 			if (idx != PFD_PIPE_MAIN)
 				fatalx("reconf request not from parent");
 			if ((p = getpeerbyid(nconf, peerid)) == NULL) {
-				log_warnx("no such peer: id=%u", peerid);
+				log_warnx("%s: no such peer: id=%u",
+				    "IMSG_RECONF_PEER_AUTH", peerid);
 				break;
 			}
 			if (pfkey_recv_conf(p, &imsg) == -1)
@@ -3344,16 +3339,22 @@ session_dispatch_imsg(struct imsgbuf *im
 		case IMSG_UPDATE:
 			if (idx != PFD_PIPE_ROUTE)
 				fatalx("update request not from RDE");
+			if ((p = getpeerbyid(conf, peerid)) == NULL) {
+				log_warnx("%s: no such peer: id=%u",
+				    "IMSG_UPDATE", peerid);
+				break;
+			}
 			if (imsg_get_ibuf(&imsg, &ibuf) == -1)
 				log_warn("RDE sent invalid update");
 			else
-				session_update(peerid, &ibuf);
+				session_update(p, &ibuf);
 			break;
 		case IMSG_UPDATE_ERR:
 			if (idx != PFD_PIPE_ROUTE)
 				fatalx("update request not from RDE");
 			if ((p = getpeerbyid(conf, peerid)) == NULL) {
-				log_warnx("no such peer: id=%u", peerid);
+				log_warnx("%s: no such peer: id=%u",
+				    "IMSG_UPDATE_ERR", peerid);
 				break;
 			}
 			if (imsg_get_ibuf(&imsg, &ibuf) == -1 ||
@@ -3391,12 +3392,13 @@ session_dispatch_imsg(struct imsgbuf *im
 		case IMSG_REFRESH:
 			if (idx != PFD_PIPE_ROUTE)
 				fatalx("route refresh request not from RDE");
-			if (imsg_get_data(&imsg, &rr, sizeof(rr)) == -1) {
-				log_warnx("RDE sent invalid refresh msg");
+			if ((p = getpeerbyid(conf, peerid)) == NULL) {
+				log_warnx("%s: no such peer: id=%u",
+				    "IMSG_REFRESH", peerid);
 				break;
 			}
-			if ((p = getpeerbyid(conf, peerid)) == NULL) {
-				log_warnx("no such peer: id=%u", peerid);
+			if (imsg_get_data(&imsg, &rr, sizeof(rr)) == -1) {
+				log_warnx("RDE sent invalid refresh msg");
 				break;
 			}
 			if (rr.aid < AID_MIN || rr.aid >= AID_MAX)
@@ -3406,12 +3408,13 @@ session_dispatch_imsg(struct imsgbuf *im
 		case IMSG_SESSION_RESTARTED:
 			if (idx != PFD_PIPE_ROUTE)
 				fatalx("session restart not from RDE");
-			if (imsg_get_data(&imsg, &aid, sizeof(aid)) == -1) {
-				log_warnx("RDE sent invalid restart msg");
+			if ((p = getpeerbyid(conf, peerid)) == NULL) {
+				log_warnx("%s: no such peer: id=%u",
+				    "IMSG_SESSION_RESTARTED", peerid);
 				break;
 			}
-			if ((p = getpeerbyid(conf, peerid)) == NULL) {
-				log_warnx("no such peer: id=%u", peerid);
+			if (imsg_get_data(&imsg, &aid, sizeof(aid)) == -1) {
+				log_warnx("RDE sent invalid restart msg");
 				break;
 			}
 			if (aid < AID_MIN || aid >= AID_MAX)