Index | Thread | Search

From:
Claudio Jeker <cjeker@diehard.n-r-g.com>
Subject:
bgpd: rename ibuf to imsgbuf in struct ctl_conn
To:
tech@openbsd.org
Date:
Thu, 11 Jan 2024 15:52:46 +0100

Download raw body.

Thread
See subject :) as requested by tb@

-- 
:wq Claudio

Index: control.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/control.c,v
diff -u -p -r1.115 control.c
--- control.c	10 Jan 2024 11:08:04 -0000	1.115
+++ control.c	11 Jan 2024 14:50:17 -0000
@@ -145,9 +145,9 @@ control_fill_pfds(struct pollfd *pfd, si
 	size_t i = 0;
 
 	TAILQ_FOREACH(ctl_conn, &ctl_conns, entry) {
-		pfd[i].fd = ctl_conn->ibuf.fd;
+		pfd[i].fd = ctl_conn->imsgbuf.fd;
 		pfd[i].events = POLLIN;
-		if (ctl_conn->ibuf.w.queued > 0)
+		if (ctl_conn->imsgbuf.w.queued > 0)
 			pfd[i].events |= POLLOUT;
 		i++;
 	}
@@ -181,7 +181,7 @@ control_accept(int listenfd, int restric
 		return (0);
 	}
 
-	imsg_init(&ctl_conn->ibuf, connfd);
+	imsg_init(&ctl_conn->imsgbuf, connfd);
 	ctl_conn->restricted = restricted;
 
 	TAILQ_INSERT_TAIL(&ctl_conns, ctl_conn, entry);
@@ -195,7 +195,7 @@ control_connbyfd(int fd)
 	struct ctl_conn	*c;
 
 	TAILQ_FOREACH(c, &ctl_conns, entry) {
-		if (c->ibuf.fd == fd)
+		if (c->imsgbuf.fd == fd)
 			break;
 	}
 
@@ -208,7 +208,7 @@ control_connbypid(pid_t pid)
 	struct ctl_conn	*c;
 
 	TAILQ_FOREACH(c, &ctl_conns, entry) {
-		if (c->ibuf.pid == pid)
+		if (c->imsgbuf.pid == pid)
 			break;
 	}
 
@@ -218,13 +218,13 @@ control_connbypid(pid_t pid)
 int
 control_close(struct ctl_conn *c)
 {
-	if (c->terminate && c->ibuf.pid)
-		imsg_ctl_rde_msg(IMSG_CTL_TERMINATE, 0, c->ibuf.pid);
+	if (c->terminate && c->imsgbuf.pid)
+		imsg_ctl_rde_msg(IMSG_CTL_TERMINATE, 0, c->imsgbuf.pid);
 
-	msgbuf_clear(&c->ibuf.w);
+	msgbuf_clear(&c->imsgbuf.w);
 	TAILQ_REMOVE(&ctl_conns, c, entry);
 
-	close(c->ibuf.fd);
+	close(c->imsgbuf.fd);
 	free(c);
 	pauseaccept = 0;
 	return (1);
@@ -249,10 +249,10 @@ control_dispatch_msg(struct pollfd *pfd,
 	}
 
 	if (pfd->revents & POLLOUT) {
-		if (msgbuf_write(&c->ibuf.w) <= 0 && errno != EAGAIN)
+		if (msgbuf_write(&c->imsgbuf.w) <= 0 && errno != EAGAIN)
 			return control_close(c);
-		if (c->throttled && c->ibuf.w.queued < CTL_MSG_LOW_MARK) {
-			if (imsg_ctl_rde_msg(IMSG_XON, 0, c->ibuf.pid) != -1)
+		if (c->throttled && c->imsgbuf.w.queued < CTL_MSG_LOW_MARK) {
+			if (imsg_ctl_rde_msg(IMSG_XON, 0, c->imsgbuf.pid) != -1)
 				c->throttled = 0;
 		}
 	}
@@ -260,12 +260,12 @@ control_dispatch_msg(struct pollfd *pfd,
 	if (!(pfd->revents & POLLIN))
 		return (0);
 
-	if (((n = imsg_read_nofd(&c->ibuf)) == -1 && errno != EAGAIN) ||
+	if (((n = imsg_read_nofd(&c->imsgbuf)) == -1 && errno != EAGAIN) ||
 	    n == 0)
 		return control_close(c);
 
 	for (;;) {
-		if ((n = imsg_get(&c->ibuf, &imsg)) == -1)
+		if ((n = imsg_get(&c->imsgbuf, &imsg)) == -1)
 			return control_close(c);
 
 		if (n == 0)
@@ -301,7 +301,7 @@ control_dispatch_msg(struct pollfd *pfd,
 		 * The imsg.hdr.pid is from the remote end and should not
 		 * be trusted.
 		 */
-		c->ibuf.pid = pid;
+		c->imsgbuf.pid = pid;
 		switch (type) {
 		case IMSG_NONE:
 			/* message was filtered out, nothing to do */
@@ -312,9 +312,11 @@ control_dispatch_msg(struct pollfd *pfd,
 			break;
 		case IMSG_CTL_SHOW_TERSE:
 			RB_FOREACH(p, peer_head, peers)
-				imsg_compose(&c->ibuf, IMSG_CTL_SHOW_NEIGHBOR,
-				    0, 0, -1, p, sizeof(struct peer));
-			imsg_compose(&c->ibuf, IMSG_CTL_END, 0, 0, -1, NULL, 0);
+				imsg_compose(&c->imsgbuf,
+				    IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1,
+				    p, sizeof(struct peer));
+			imsg_compose(&c->imsgbuf, IMSG_CTL_END, 0, 0, -1,
+			    NULL, 0);
 			break;
 		case IMSG_CTL_SHOW_NEIGHBOR:
 			if (imsg_get_data(&imsg, &neighbor,
@@ -335,7 +337,7 @@ control_dispatch_msg(struct pollfd *pfd,
 					time_t			 d;
 					struct ctl_timer	 ct;
 
-					imsg_compose(&c->ibuf,
+					imsg_compose(&c->imsgbuf,
 					    IMSG_CTL_SHOW_NEIGHBOR,
 					    0, 0, -1, p, sizeof(*p));
 					for (i = 1; i < Timer_Max; i++) {
@@ -344,7 +346,7 @@ control_dispatch_msg(struct pollfd *pfd,
 							continue;
 						ct.type = i;
 						ct.val = d;
-						imsg_compose(&c->ibuf,
+						imsg_compose(&c->imsgbuf,
 						    IMSG_CTL_SHOW_TIMER,
 						    0, 0, -1, &ct, sizeof(ct));
 					}
@@ -355,8 +357,8 @@ control_dispatch_msg(struct pollfd *pfd,
 			} else if (!neighbor.show_timers) {
 				imsg_ctl_rde_msg(IMSG_CTL_END, 0, pid);
 			} else {
-				imsg_compose(&c->ibuf, IMSG_CTL_END, 0, 0, -1,
-				    NULL, 0);
+				imsg_compose(&c->imsgbuf, IMSG_CTL_END, 0, 0,
+				    -1, NULL, 0);
 			}
 			break;
 		case IMSG_CTL_NEIGHBOR_UP:
@@ -566,25 +568,26 @@ control_imsg_relay(struct imsg *imsg, st
 		p->stats.pending_update = stats.pending_update;
 		p->stats.pending_withdraw = stats.pending_withdraw;
 
-		return imsg_compose(&c->ibuf, type, 0, pid, -1, p, sizeof(*p));
+		return imsg_compose(&c->imsgbuf, type, 0, pid, -1,
+		   p, sizeof(*p));
 	}
 
 	/* if command finished no need to send exit message */
 	if (type == IMSG_CTL_END || type == IMSG_CTL_RESULT)
 		c->terminate = 0;
 
-	if (!c->throttled && c->ibuf.w.queued > CTL_MSG_HIGH_MARK) {
+	if (!c->throttled && c->imsgbuf.w.queued > CTL_MSG_HIGH_MARK) {
 		if (imsg_ctl_rde_msg(IMSG_XOFF, 0, pid) != -1)
 			c->throttled = 1;
 	}
 
-	return (imsg_forward(&c->ibuf, imsg));
+	return (imsg_forward(&c->imsgbuf, imsg));
 }
 
 void
 control_result(struct ctl_conn *c, u_int code)
 {
-	imsg_compose(&c->ibuf, IMSG_CTL_RESULT, 0, c->ibuf.pid, -1,
+	imsg_compose(&c->imsgbuf, IMSG_CTL_RESULT, 0, c->imsgbuf.pid, -1,
 	    &code, sizeof(code));
 }
 
Index: session.h
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/session.h,v
diff -u -p -r1.165 session.h
--- session.h	10 Jan 2024 11:08:04 -0000	1.165
+++ session.h	11 Jan 2024 14:48:19 -0000
@@ -130,7 +130,7 @@ struct bgpd_sysdep {
 
 struct ctl_conn {
 	TAILQ_ENTRY(ctl_conn)	entry;
-	struct imsgbuf		ibuf;
+	struct imsgbuf		imsgbuf;
 	int			restricted;
 	int			throttled;
 	int			terminate;