From: Claudio Jeker Subject: bgpd vs bison: rename some enums To: tech@openbsd.org Date: Mon, 16 Dec 2024 16:40:25 +0100 Bison uses an enum for the yacc tokens and so we end up with the redefinition of NOTIFICATION. parse.c:390:5: warning: declaration shadows a variable in the global scope [-Wshadow] 390 | NOTIFICATION = 318, /* NOTIFICATION */ | ^ ./session.h:75:2: note: previous declaration is here 75 | NOTIFICATION, | ^ Now it is easier to prefix the msg_type enums in session.h so the below diff does that. With that make YACC=bison works. -- :wq Claudio Index: usr.sbin/bgpctl/bgpctl.c =================================================================== RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.c,v diff -u -p -r1.313 bgpctl.c --- usr.sbin/bgpctl/bgpctl.c 9 Dec 2024 10:52:27 -0000 1.313 +++ usr.sbin/bgpctl/bgpctl.c 16 Dec 2024 15:35:51 -0000 @@ -1776,7 +1776,7 @@ show_mrt_msg(struct mrt_bgp_msg *mm, voi } switch (type) { - case OPEN: + case MSG_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 NOTIFICATION: + case MSG_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 UPDATE: + case MSG_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 KEEPALIVE: + case MSG_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 RREFRESH: + case MSG_RREFRESH: printf("%s ", msgtypenames[type]); if (len != MSGSIZE_RREFRESH) { printf("bad length: %u bytes\n", len); Index: usr.sbin/bgpd/mrt.c =================================================================== RCS file: /cvs/src/usr.sbin/bgpd/mrt.c,v diff -u -p -r1.122 mrt.c --- usr.sbin/bgpd/mrt.c 21 Nov 2024 13:34:01 -0000 1.122 +++ usr.sbin/bgpd/mrt.c 16 Dec 2024 15:35:51 -0000 @@ -134,7 +134,7 @@ mrt_bgp_msg_subtype(struct mrt *mrt, str if (peer->capa.neg.as4byte) subtype = BGP4MP_MESSAGE_AS4; - if (msgtype != UPDATE) + if (msgtype != MSG_UPDATE) return subtype; /* Index: usr.sbin/bgpd/session.c =================================================================== RCS file: /cvs/src/usr.sbin/bgpd/session.c,v diff -u -p -r1.504 session.c --- usr.sbin/bgpd/session.c 13 Dec 2024 19:21:03 -0000 1.504 +++ usr.sbin/bgpd/session.c 16 Dec 2024 15:35:51 -0000 @@ -1427,7 +1427,7 @@ session_sendmsg(struct ibuf *msg, struct struct mrt *mrt; LIST_FOREACH(mrt, &mrthead, entry) { - if (!(mrt->type == MRT_ALL_OUT || (msgtype == UPDATE && + if (!(mrt->type == MRT_ALL_OUT || (msgtype == MSG_UPDATE && mrt->type == MRT_UPDATE_OUT))) continue; if ((mrt->peer_id == 0 && mrt->group_id == 0) || @@ -1602,7 +1602,7 @@ session_open(struct peer *p) len += 2; } - if ((buf = session_newmsg(OPEN, len)) == NULL) { + if ((buf = session_newmsg(MSG_OPEN, len)) == NULL) { ibuf_free(opb); bgp_fsm(p, EVNT_CON_FATAL, NULL); return; @@ -1646,7 +1646,7 @@ session_open(struct peer *p) return; } - session_sendmsg(buf, p, OPEN); + session_sendmsg(buf, p, MSG_OPEN); p->stats.msg_sent_open++; } @@ -1655,12 +1655,12 @@ session_keepalive(struct peer *p) { struct ibuf *buf; - if ((buf = session_newmsg(KEEPALIVE, MSGSIZE_KEEPALIVE)) == NULL) { + if ((buf = session_newmsg(MSG_KEEPALIVE, MSGSIZE_KEEPALIVE)) == NULL) { bgp_fsm(p, EVNT_CON_FATAL, NULL); return; } - session_sendmsg(buf, p, KEEPALIVE); + session_sendmsg(buf, p, MSG_KEEPALIVE); start_timer_keepalive(p); p->stats.msg_sent_keepalive++; } @@ -1689,7 +1689,7 @@ session_update(uint32_t peerid, struct i return; } - if ((buf = session_newmsg(UPDATE, MSGSIZE_HEADER + len)) == NULL) { + if ((buf = session_newmsg(MSG_UPDATE, MSGSIZE_HEADER + len)) == NULL) { bgp_fsm(p, EVNT_CON_FATAL, NULL); return; } @@ -1700,7 +1700,7 @@ session_update(uint32_t peerid, struct i return; } - session_sendmsg(buf, p, UPDATE); + session_sendmsg(buf, p, MSG_UPDATE); start_timer_keepalive(p); p->stats.msg_sent_update++; } @@ -1791,7 +1791,7 @@ session_notification(struct peer *p, uin datalen += ibuf_size(ibuf); } - if ((buf = session_newmsg(NOTIFICATION, + if ((buf = session_newmsg(MSG_NOTIFICATION, MSGSIZE_NOTIFICATION_MIN + datalen)) == NULL) { bgp_fsm(p, EVNT_CON_FATAL, NULL); return; @@ -1814,7 +1814,7 @@ session_notification(struct peer *p, uin return; } - session_sendmsg(buf, p, NOTIFICATION); + session_sendmsg(buf, p, MSG_NOTIFICATION); p->stats.msg_sent_notification++; p->stats.last_sent_errcode = errcode; p->stats.last_sent_suberr = subcode; @@ -1865,7 +1865,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(RREFRESH, MSGSIZE_RREFRESH)) == NULL) { + if ((buf = session_newmsg(MSG_RREFRESH, MSGSIZE_RREFRESH)) == NULL) { bgp_fsm(p, EVNT_CON_FATAL, NULL); return; } @@ -1880,7 +1880,7 @@ session_rrefresh(struct peer *p, uint8_t return; } - session_sendmsg(buf, p, RREFRESH); + session_sendmsg(buf, p, MSG_RREFRESH); p->stats.msg_sent_rrefresh++; } @@ -2059,7 +2059,8 @@ 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 == UPDATE && + if (!(mrt->type == MRT_ALL_IN || + (msgtype == MSG_UPDATE && mrt->type == MRT_UPDATE_IN))) continue; if ((mrt->peer_id == 0 && mrt->group_id == 0) || @@ -2071,23 +2072,23 @@ session_process_msg(struct peer *p) ibuf_skip(msg, MSGSIZE_HEADER); switch (msgtype) { - case OPEN: + case MSG_OPEN: bgp_fsm(p, EVNT_RCVD_OPEN, msg); p->stats.msg_rcvd_open++; break; - case UPDATE: + case MSG_UPDATE: bgp_fsm(p, EVNT_RCVD_UPDATE, msg); p->stats.msg_rcvd_update++; break; - case NOTIFICATION: + case MSG_NOTIFICATION: bgp_fsm(p, EVNT_RCVD_NOTIFICATION, msg); p->stats.msg_rcvd_notification++; break; - case KEEPALIVE: + case MSG_KEEPALIVE: bgp_fsm(p, EVNT_RCVD_KEEPALIVE, msg); p->stats.msg_rcvd_keepalive++; break; - case RREFRESH: + case MSG_RREFRESH: parse_rrefresh(p, msg); p->stats.msg_rcvd_rrefresh++; break; @@ -2138,35 +2139,35 @@ parse_header(struct ibuf *msg, void *arg } switch (type) { - case OPEN: + case MSG_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 NOTIFICATION: + case MSG_NOTIFICATION: if (len < MSGSIZE_NOTIFICATION_MIN) { log_peer_warnx(&peer->conf, "received NOTIFICATION: illegal len: %u byte", len); goto badlen; } break; - case UPDATE: + case MSG_UPDATE: if (len < MSGSIZE_UPDATE_MIN) { log_peer_warnx(&peer->conf, "received UPDATE: illegal len: %u byte", len); goto badlen; } break; - case KEEPALIVE: + case MSG_KEEPALIVE: if (len != MSGSIZE_KEEPALIVE) { log_peer_warnx(&peer->conf, "received KEEPALIVE: illegal len: %u byte", len); goto badlen; } break; - case RREFRESH: + case MSG_RREFRESH: if (len < MSGSIZE_RREFRESH_MIN) { log_peer_warnx(&peer->conf, "received RREFRESH: illegal len: %u byte", len); Index: usr.sbin/bgpd/session.h =================================================================== RCS file: /cvs/src/usr.sbin/bgpd/session.h,v diff -u -p -r1.183 session.h --- usr.sbin/bgpd/session.h 13 Dec 2024 19:21:03 -0000 1.183 +++ usr.sbin/bgpd/session.h 16 Dec 2024 15:35:51 -0000 @@ -70,11 +70,11 @@ enum session_events { }; enum msg_type { - OPEN = 1, - UPDATE, - NOTIFICATION, - KEEPALIVE, - RREFRESH + MSG_OPEN = 1, + MSG_UPDATE, + MSG_NOTIFICATION, + MSG_KEEPALIVE, + MSG_RREFRESH }; enum suberr_header {