Implement IMSG_CTL_SHOW_FLOWSPEC and IMSG_FLOWSPEC_FLUSH and add bits for
IMSG_FLOWSPEC_ADD and IMSG_FLOWSPEC_REMOVE received from bgpctl via SE.
This is mostly streight forward code (copying the bits which are already
around).
--
:wq Claudio
Index: bgpd.h
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.473
diff -u -p -r1.473 bgpd.h
--- bgpd.h 19 Apr 2023 07:12:22 - 1.473
+++ bgpd.h 19 Apr 2023 15:58:28 -
@@ -599,6 +599,7 @@ enum imsg_type {
IMSG_CTL_SHOW_RIB_COMMUNITIES,
IMSG_CTL_SHOW_RIB_ATTR,
IMSG_CTL_SHOW_NETWORK,
+ IMSG_CTL_SHOW_FLOWSPEC,
IMSG_CTL_SHOW_RIB_MEM,
IMSG_CTL_SHOW_TERSE,
IMSG_CTL_SHOW_TIMER,
@@ -616,6 +617,7 @@ enum imsg_type {
IMSG_FLOWSPEC_ADD,
IMSG_FLOWSPEC_DONE,
IMSG_FLOWSPEC_REMOVE,
+ IMSG_FLOWSPEC_FLUSH,
IMSG_FILTER_SET,
IMSG_SOCKET_CONN,
IMSG_SOCKET_CONN_CTL,
Index: control.c
===
RCS file: /cvs/src/usr.sbin/bgpd/control.c,v
retrieving revision 1.109
diff -u -p -r1.109 control.c
--- control.c 9 Feb 2023 13:43:23 - 1.109
+++ control.c 19 Apr 2023 15:58:28 -
@@ -279,6 +279,7 @@ control_dispatch_msg(struct pollfd *pfd,
case IMSG_CTL_SHOW_TERSE:
case IMSG_CTL_SHOW_TIMER:
case IMSG_CTL_SHOW_NETWORK:
+ case IMSG_CTL_SHOW_FLOWSPEC:
case IMSG_CTL_SHOW_RIB:
case IMSG_CTL_SHOW_RIB_PREFIX:
case IMSG_CTL_SHOW_SET:
@@ -498,6 +499,7 @@ control_dispatch_msg(struct pollfd *pfd,
imsg.data, imsg.hdr.len - IMSG_HEADER_SIZE);
break;
case IMSG_CTL_SHOW_NETWORK:
+ case IMSG_CTL_SHOW_FLOWSPEC:
c->terminate = 1;
/* FALLTHROUGH */
case IMSG_CTL_SHOW_RIB_MEM:
@@ -512,6 +514,10 @@ control_dispatch_msg(struct pollfd *pfd,
case IMSG_NETWORK_REMOVE:
case IMSG_NETWORK_FLUSH:
case IMSG_NETWORK_DONE:
+ case IMSG_FLOWSPEC_ADD:
+ case IMSG_FLOWSPEC_REMOVE:
+ case IMSG_FLOWSPEC_DONE:
+ case IMSG_FLOWSPEC_FLUSH:
case IMSG_FILTER_SET:
imsg_ctl_rde(imsg.hdr.type, 0, 0,
imsg.data, imsg.hdr.len - IMSG_HEADER_SIZE);
Index: rde.c
===
RCS file: /cvs/src/usr.sbin/bgpd/rde.c,v
retrieving revision 1.603
diff -u -p -r1.603 rde.c
--- rde.c 19 Apr 2023 13:23:33 - 1.603
+++ rde.c 19 Apr 2023 15:58:28 -
@@ -105,6 +105,9 @@ static void network_flush_upcall(struct
voidflowspec_add(struct flowspec *, struct filterstate *,
struct filter_set_head *);
voidflowspec_delete(struct flowspec *);
+static void flowspec_flush_upcall(struct rib_entry *, void *);
+static void flowspec_dump_upcall(struct rib_entry *, void *);
+static void flowspec_dump_done(void *, uint8_t);
voidrde_shutdown(void);
static int ovs_match(struct prefix *, uint32_t);
@@ -361,6 +364,7 @@ struct filter_set_head parent_set = TAIL
void
rde_dispatch_imsg_session(struct imsgbuf *ibuf)
{
+ static struct flowspec *curflow;
struct imsg imsg;
struct rde_peer_statsstats;
struct ctl_show_set cset;
@@ -577,6 +581,97 @@ badnetdel:
NULL, NULL) == -1)
log_warn("rde_dispatch: IMSG_NETWORK_FLUSH");
break;
+ case IMSG_FLOWSPEC_ADD:
+ if (imsg.hdr.len - IMSG_HEADER_SIZE <= FLOWSPEC_SIZE) {
+ log_warnx("rde_dispatch: wrong imsg len");
+ break;
+ }
+ if (curflow != NULL) {
+ log_warnx("rde_dispatch: "
+ "unexpected flowspec add");
+ break;
+ }
+ curflow = malloc(imsg.hdr.len - IMSG_HEADER_SIZE);
+ if (curflow == NULL)
+ fatal(NULL);
+ memcpy(curflow, imsg.data,
+ imsg.hdr.len - IMSG_HEADER_SIZE);
+ if (curflow->len + FLOWSPEC_SIZE !=
+ imsg.hdr.len - IMSG_HEADER_SIZE) {
+ free(curflow);
+ curflow = NULL;
+ log_warnx("rde_dispatch: wrong flowspec len");
+ break;
+