Index | Thread | Search

From:
Claudio Jeker <cjeker@diehard.n-r-g.com>
Subject:
bgpd: another enum msg_type rename
To:
tech@openbsd.org
Date:
Fri, 31 Jan 2025 14:47:27 +0100

Download raw body.

Thread
So some time ago we added a MSG_ prefix to enum msg_type because
NOTIFICATION caused a conflict with the bison produced parse.y file.

Now MSG_NOTIFICATION is again causing a conflict but this time with a
define in sys/socket.h on some systems. It seems that SCPT introduced this
into the socket API.

So lets use BGP_ as a prefix instead of MSG_. Hopefully this time nobody
else defines BGP_NOTIFICATION for some doubious reason.

-- 
:wq Claudio


Index: bgpctl/bgpctl.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.c,v
diff -u -p -r1.314 bgpctl.c
--- bgpctl/bgpctl.c	16 Dec 2024 16:10:46 -0000	1.314
+++ bgpctl/bgpctl.c	31 Jan 2025 13:42:49 -0000
@@ -1776,7 +1776,7 @@ show_mrt_msg(struct mrt_bgp_msg *mm, voi
 	}
 
 	switch (type) {
-	case MSG_OPEN:
+	case BGP_OPEN:
 		printf("%s ", msgtypenames[type]);
 		if (len < MSGSIZE_OPEN_MIN) {
 			printf("bad length: %u bytes\n", len);
@@ -1784,7 +1784,7 @@ show_mrt_msg(struct mrt_bgp_msg *mm, voi
 		}
 		show_mrt_open(b);
 		break;
-	case MSG_NOTIFICATION:
+	case BGP_NOTIFICATION:
 		printf("%s ", msgtypenames[type]);
 		if (len < MSGSIZE_NOTIFICATION_MIN) {
 			printf("bad length: %u bytes\n", len);
@@ -1792,7 +1792,7 @@ show_mrt_msg(struct mrt_bgp_msg *mm, voi
 		}
 		show_mrt_notification(b);
 		break;
-	case MSG_UPDATE:
+	case BGP_UPDATE:
 		printf("%s ", msgtypenames[type]);
 		if (len < MSGSIZE_UPDATE_MIN) {
 			printf("bad length: %u bytes\n", len);
@@ -1800,7 +1800,7 @@ show_mrt_msg(struct mrt_bgp_msg *mm, voi
 		}
 		show_mrt_update(b, req->flags, mm->add_path);
 		break;
-	case MSG_KEEPALIVE:
+	case BGP_KEEPALIVE:
 		printf("%s ", msgtypenames[type]);
 		if (len != MSGSIZE_KEEPALIVE) {
 			printf("bad length: %u bytes\n", len);
@@ -1808,7 +1808,7 @@ show_mrt_msg(struct mrt_bgp_msg *mm, voi
 		}
 		/* nothing */
 		break;
-	case MSG_RREFRESH:
+	case BGP_RREFRESH:
 		printf("%s ", msgtypenames[type]);
 		if (len != MSGSIZE_RREFRESH) {
 			printf("bad length: %u bytes\n", len);
Index: bgpd/mrt.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/mrt.c,v
diff -u -p -r1.123 mrt.c
--- bgpd/mrt.c	16 Dec 2024 16:10:10 -0000	1.123
+++ bgpd/mrt.c	31 Jan 2025 13:42:16 -0000
@@ -134,7 +134,7 @@ mrt_bgp_msg_subtype(struct mrt *mrt, str
 	if (peer->capa.neg.as4byte)
 		subtype = BGP4MP_MESSAGE_AS4;
 
-	if (msgtype != MSG_UPDATE)
+	if (msgtype != BGP_UPDATE)
 		return subtype;
 
 	/*
Index: bgpd/session.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/session.c,v
diff -u -p -r1.508 session.c
--- bgpd/session.c	22 Jan 2025 12:19:47 -0000	1.508
+++ bgpd/session.c	31 Jan 2025 13:41:48 -0000
@@ -1446,7 +1446,7 @@ session_sendmsg(struct ibuf *msg, struct
 	struct mrt		*mrt;
 
 	LIST_FOREACH(mrt, &mrthead, entry) {
-		if (!(mrt->type == MRT_ALL_OUT || (msgtype == MSG_UPDATE &&
+		if (!(mrt->type == MRT_ALL_OUT || (msgtype == BGP_UPDATE &&
 		    mrt->type == MRT_UPDATE_OUT)))
 			continue;
 		if ((mrt->peer_id == 0 && mrt->group_id == 0) ||
@@ -1636,7 +1636,7 @@ session_open(struct peer *p)
 		len += 2;
 	}
 
-	if ((buf = session_newmsg(MSG_OPEN, len)) == NULL) {
+	if ((buf = session_newmsg(BGP_OPEN, len)) == NULL) {
 		ibuf_free(opb);
 		bgp_fsm(p, EVNT_CON_FATAL, NULL);
 		return;
@@ -1680,7 +1680,7 @@ session_open(struct peer *p)
 		return;
 	}
 
-	session_sendmsg(buf, p, MSG_OPEN);
+	session_sendmsg(buf, p, BGP_OPEN);
 	p->stats.msg_sent_open++;
 }
 
@@ -1689,12 +1689,12 @@ session_keepalive(struct peer *p)
 {
 	struct ibuf		*buf;
 
-	if ((buf = session_newmsg(MSG_KEEPALIVE, MSGSIZE_KEEPALIVE)) == NULL) {
+	if ((buf = session_newmsg(BGP_KEEPALIVE, MSGSIZE_KEEPALIVE)) == NULL) {
 		bgp_fsm(p, EVNT_CON_FATAL, NULL);
 		return;
 	}
 
-	session_sendmsg(buf, p, MSG_KEEPALIVE);
+	session_sendmsg(buf, p, BGP_KEEPALIVE);
 	start_timer_keepalive(p);
 	p->stats.msg_sent_keepalive++;
 }
@@ -1723,7 +1723,7 @@ session_update(uint32_t peerid, struct i
 		return;
 	}
 
-	if ((buf = session_newmsg(MSG_UPDATE, MSGSIZE_HEADER + len)) == NULL) {
+	if ((buf = session_newmsg(BGP_UPDATE, MSGSIZE_HEADER + len)) == NULL) {
 		bgp_fsm(p, EVNT_CON_FATAL, NULL);
 		return;
 	}
@@ -1734,7 +1734,7 @@ session_update(uint32_t peerid, struct i
 		return;
 	}
 
-	session_sendmsg(buf, p, MSG_UPDATE);
+	session_sendmsg(buf, p, BGP_UPDATE);
 	start_timer_keepalive(p);
 	p->stats.msg_sent_update++;
 }
@@ -1825,7 +1825,7 @@ session_notification(struct peer *p, uin
 		datalen += ibuf_size(ibuf);
 	}
 
-	if ((buf = session_newmsg(MSG_NOTIFICATION,
+	if ((buf = session_newmsg(BGP_NOTIFICATION,
 	    MSGSIZE_NOTIFICATION_MIN + datalen)) == NULL) {
 		bgp_fsm(p, EVNT_CON_FATAL, NULL);
 		return;
@@ -1848,7 +1848,7 @@ session_notification(struct peer *p, uin
 		return;
 	}
 
-	session_sendmsg(buf, p, MSG_NOTIFICATION);
+	session_sendmsg(buf, p, BGP_NOTIFICATION);
 	p->stats.msg_sent_notification++;
 	p->stats.last_sent_errcode = errcode;
 	p->stats.last_sent_suberr = subcode;
@@ -1899,7 +1899,7 @@ session_rrefresh(struct peer *p, uint8_t
 	if (aid2afi(aid, &afi, &safi) == -1)
 		fatalx("session_rrefresh: bad afi/safi pair");
 
-	if ((buf = session_newmsg(MSG_RREFRESH, MSGSIZE_RREFRESH)) == NULL) {
+	if ((buf = session_newmsg(BGP_RREFRESH, MSGSIZE_RREFRESH)) == NULL) {
 		bgp_fsm(p, EVNT_CON_FATAL, NULL);
 		return;
 	}
@@ -1914,7 +1914,7 @@ session_rrefresh(struct peer *p, uint8_t
 		return;
 	}
 
-	session_sendmsg(buf, p, MSG_RREFRESH);
+	session_sendmsg(buf, p, BGP_RREFRESH);
 	p->stats.msg_sent_rrefresh++;
 }
 
@@ -2094,7 +2094,7 @@ session_process_msg(struct peer *p)
 		/* dump to MRT as soon as we have a full packet */
 		LIST_FOREACH(mrt, &mrthead, entry) {
 			if (!(mrt->type == MRT_ALL_IN ||
-			    (msgtype == MSG_UPDATE &&
+			    (msgtype == BGP_UPDATE &&
 			    mrt->type == MRT_UPDATE_IN)))
 				continue;
 			if ((mrt->peer_id == 0 && mrt->group_id == 0) ||
@@ -2106,23 +2106,23 @@ session_process_msg(struct peer *p)
 		ibuf_skip(msg, MSGSIZE_HEADER);
 
 		switch (msgtype) {
-		case MSG_OPEN:
+		case BGP_OPEN:
 			bgp_fsm(p, EVNT_RCVD_OPEN, msg);
 			p->stats.msg_rcvd_open++;
 			break;
-		case MSG_UPDATE:
+		case BGP_UPDATE:
 			bgp_fsm(p, EVNT_RCVD_UPDATE, msg);
 			p->stats.msg_rcvd_update++;
 			break;
-		case MSG_NOTIFICATION:
+		case BGP_NOTIFICATION:
 			bgp_fsm(p, EVNT_RCVD_NOTIFICATION, msg);
 			p->stats.msg_rcvd_notification++;
 			break;
-		case MSG_KEEPALIVE:
+		case BGP_KEEPALIVE:
 			bgp_fsm(p, EVNT_RCVD_KEEPALIVE, msg);
 			p->stats.msg_rcvd_keepalive++;
 			break;
-		case MSG_RREFRESH:
+		case BGP_RREFRESH:
 			parse_rrefresh(p, msg);
 			p->stats.msg_rcvd_rrefresh++;
 			break;
@@ -2173,35 +2173,35 @@ parse_header(struct ibuf *msg, void *arg
 	}
 
 	switch (type) {
-	case MSG_OPEN:
+	case BGP_OPEN:
 		if (len < MSGSIZE_OPEN_MIN || len > MAX_PKTSIZE) {
 			log_peer_warnx(&peer->conf,
 			    "received OPEN: illegal len: %u byte", len);
 			goto badlen;
 		}
 		break;
-	case MSG_NOTIFICATION:
+	case BGP_NOTIFICATION:
 		if (len < MSGSIZE_NOTIFICATION_MIN) {
 			log_peer_warnx(&peer->conf,
 			    "received NOTIFICATION: illegal len: %u byte", len);
 			goto badlen;
 		}
 		break;
-	case MSG_UPDATE:
+	case BGP_UPDATE:
 		if (len < MSGSIZE_UPDATE_MIN) {
 			log_peer_warnx(&peer->conf,
 			    "received UPDATE: illegal len: %u byte", len);
 			goto badlen;
 		}
 		break;
-	case MSG_KEEPALIVE:
+	case BGP_KEEPALIVE:
 		if (len != MSGSIZE_KEEPALIVE) {
 			log_peer_warnx(&peer->conf,
 			    "received KEEPALIVE: illegal len: %u byte", len);
 			goto badlen;
 		}
 		break;
-	case MSG_RREFRESH:
+	case BGP_RREFRESH:
 		if (len < MSGSIZE_RREFRESH_MIN) {
 			log_peer_warnx(&peer->conf,
 			    "received RREFRESH: illegal len: %u byte", len);
Index: bgpd/session.h
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/session.h,v
diff -u -p -r1.184 session.h
--- bgpd/session.h	16 Dec 2024 16:10:10 -0000	1.184
+++ bgpd/session.h	31 Jan 2025 13:41:17 -0000
@@ -70,11 +70,11 @@ enum session_events {
 };
 
 enum msg_type {
-	MSG_OPEN = 1,
-	MSG_UPDATE,
-	MSG_NOTIFICATION,
-	MSG_KEEPALIVE,
-	MSG_RREFRESH
+	BGP_OPEN = 1,
+	BGP_UPDATE,
+	BGP_NOTIFICATION,
+	BGP_KEEPALIVE,
+	BGP_RREFRESH
 };
 
 enum suberr_header {