summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2018-12-22 16:12:41 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2018-12-22 16:12:41 +0000
commitac380545c764bd2db71d6382d01ac05f8ac09fce (patch)
treec117d0e39a1663c6ec72c13063bd9f41c7394da8 /usr.sbin
parentaa4d83a3b71a254224304b3680c77da74efd7115 (diff)
bgpctl can cause bgpd to do a lot of work (e.g. dumping all of the RIB)
but then bgpctl can quickly exit and bgpd still has to do all the work. Instead introduce a terminate imsg to stop such long running commands if bgpctl closes the connection before the run is over. OK benno@, sthen@, deraadt@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/bgpd/bgpd.h3
-rw-r--r--usr.sbin/bgpd/control.c20
-rw-r--r--usr.sbin/bgpd/rde.c40
-rw-r--r--usr.sbin/bgpd/session.h3
4 files changed, 55 insertions, 11 deletions
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h
index fd4e9484f2a..7f981155023 100644
--- a/usr.sbin/bgpd/bgpd.h
+++ b/usr.sbin/bgpd/bgpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.h,v 1.358 2018/12/19 15:26:42 claudio Exp $ */
+/* $OpenBSD: bgpd.h,v 1.359 2018/12/22 16:12:40 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -437,6 +437,7 @@ enum imsg_type {
IMSG_CTL_SHOW_TIMER,
IMSG_CTL_LOG_VERBOSE,
IMSG_CTL_SHOW_FIB_TABLES,
+ IMSG_CTL_TERMINATE,
IMSG_NETWORK_ADD,
IMSG_NETWORK_ASPATH,
IMSG_NETWORK_ATTR,
diff --git a/usr.sbin/bgpd/control.c b/usr.sbin/bgpd/control.c
index 3ba8ed1c86d..0e2b1813eb8 100644
--- a/usr.sbin/bgpd/control.c
+++ b/usr.sbin/bgpd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.91 2018/11/28 08:32:27 claudio Exp $ */
+/* $OpenBSD: control.c,v 1.92 2018/12/22 16:12:40 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -188,6 +188,9 @@ control_close(int fd)
return (0);
}
+ if (c->terminate && c->ibuf.pid)
+ imsg_ctl_rde(IMSG_CTL_TERMINATE, c->ibuf.pid, NULL, 0);
+
msgbuf_clear(&c->ibuf.w);
TAILQ_REMOVE(&ctl_conns, c, entry);
@@ -247,12 +250,12 @@ control_dispatch_msg(struct pollfd *pfd, u_int *ctl_cnt)
case IMSG_CTL_SHOW_NEIGHBOR:
case IMSG_CTL_SHOW_NEXTHOP:
case IMSG_CTL_SHOW_INTERFACE:
- case IMSG_CTL_SHOW_RIB:
- case IMSG_CTL_SHOW_RIB_PREFIX:
case IMSG_CTL_SHOW_RIB_MEM:
- case IMSG_CTL_SHOW_NETWORK:
case IMSG_CTL_SHOW_TERSE:
case IMSG_CTL_SHOW_TIMER:
+ case IMSG_CTL_SHOW_NETWORK:
+ case IMSG_CTL_SHOW_RIB:
+ case IMSG_CTL_SHOW_RIB_PREFIX:
break;
default:
/* clear imsg type to prevent processing */
@@ -459,14 +462,17 @@ control_dispatch_msg(struct pollfd *pfd, u_int *ctl_cnt)
break;
}
c->ibuf.pid = imsg.hdr.pid;
+ c->terminate = 1;
imsg_ctl_rde(imsg.hdr.type, imsg.hdr.pid,
imsg.data, imsg.hdr.len - IMSG_HEADER_SIZE);
} else
log_warnx("got IMSG_CTL_SHOW_RIB with "
"wrong length");
break;
- case IMSG_CTL_SHOW_RIB_MEM:
case IMSG_CTL_SHOW_NETWORK:
+ c->terminate = 1;
+ /* FALLTHROUGH */
+ case IMSG_CTL_SHOW_RIB_MEM:
c->ibuf.pid = imsg.hdr.pid;
imsg_ctl_rde(imsg.hdr.type, imsg.hdr.pid,
imsg.data, imsg.hdr.len - IMSG_HEADER_SIZE);
@@ -512,6 +518,10 @@ control_imsg_relay(struct imsg *imsg)
if ((c = control_connbypid(imsg->hdr.pid)) == NULL)
return (0);
+ /* if command finished no need to send exit message */
+ if (imsg->hdr.type == IMSG_CTL_END || imsg->hdr.type == IMSG_CTL_RESULT)
+ c->terminate = 0;
+
if (!c->throttled && c->ibuf.w.queued > CTL_MSG_HIGH_MARK) {
if (imsg_ctl_rde(IMSG_XOFF, imsg->hdr.pid, NULL, 0) != -1)
c->throttled = 1;
diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c
index 7b183cb9670..01b47a6aac5 100644
--- a/usr.sbin/bgpd/rde.c
+++ b/usr.sbin/bgpd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.453 2018/12/19 15:26:42 claudio Exp $ */
+/* $OpenBSD: rde.c,v 1.454 2018/12/22 16:12:40 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -71,7 +71,8 @@ void rde_reflector(struct rde_peer *, struct rde_aspath *);
void rde_dump_ctx_new(struct ctl_show_rib_request *, pid_t,
enum imsg_type);
-void rde_dump_ctx_throttle(pid_t pid, int throttle);
+void rde_dump_ctx_throttle(pid_t, int);
+void rde_dump_ctx_terminate(pid_t);
void rde_dump_mrt_new(struct mrt *, pid_t, int);
int rde_rdomain_import(struct rde_aspath *, struct rdomain *);
@@ -133,7 +134,7 @@ int softreconfig;
struct rde_dump_ctx {
LIST_ENTRY(rde_dump_ctx) entry;
struct ctl_show_rib_request req;
- sa_family_t af;
+ u_int16_t rid;
u_int8_t throttled;
};
@@ -658,6 +659,9 @@ badnetdel:
rde_dump_ctx_throttle(imsg.hdr.pid, 1);
}
break;
+ case IMSG_CTL_TERMINATE:
+ rde_dump_ctx_terminate(imsg.hdr.pid);
+ break;
default:
break;
}
@@ -2321,6 +2325,7 @@ rde_dump_ctx_new(struct ctl_show_rib_request *req, pid_t pid,
memcpy(&ctx->req, req, sizeof(struct ctl_show_rib_request));
ctx->req.pid = pid;
ctx->req.type = type;
+ ctx->rid = rid;
switch (ctx->req.type) {
case IMSG_CTL_SHOW_NETWORK:
if (rib_dump_new(rid, ctx->req.aid, CTL_MSG_HIGH_MARK, ctx,
@@ -2364,7 +2369,7 @@ rde_dump_ctx_new(struct ctl_show_rib_request *req, pid_t pid,
free(ctx);
return;
default:
- fatalx("rde_dump_ctx_new: unsupported imsg type");
+ fatalx("%s: unsupported imsg type", __func__);
}
LIST_INSERT_HEAD(&rde_dump_h, ctx, entry);
}
@@ -2382,6 +2387,33 @@ rde_dump_ctx_throttle(pid_t pid, int throttle)
}
}
+void
+rde_dump_ctx_terminate(pid_t pid)
+{
+ struct rde_dump_ctx *ctx;
+
+ LIST_FOREACH(ctx, &rde_dump_h, entry) {
+ if (ctx->req.pid == pid) {
+ void (*upcall)(struct rib_entry *, void *);
+ switch (ctx->req.type) {
+ case IMSG_CTL_SHOW_NETWORK:
+ upcall = network_dump_upcall;
+ break;
+ case IMSG_CTL_SHOW_RIB:
+ upcall = rde_dump_upcall;
+ break;
+ case IMSG_CTL_SHOW_RIB_PREFIX:
+ upcall = rde_dump_prefix_upcall;
+ break;
+ default:
+ fatalx("%s: unsupported imsg type", __func__);
+ }
+ rib_dump_terminate(ctx->rid, ctx, upcall);
+ return;
+ }
+ }
+}
+
static int
rde_mrt_throttled(void *arg)
{
diff --git a/usr.sbin/bgpd/session.h b/usr.sbin/bgpd/session.h
index 17b1b4529ea..1c87025d7ef 100644
--- a/usr.sbin/bgpd/session.h
+++ b/usr.sbin/bgpd/session.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.h,v 1.125 2018/10/24 08:26:37 claudio Exp $ */
+/* $OpenBSD: session.h,v 1.126 2018/12/22 16:12:40 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -143,6 +143,7 @@ struct ctl_conn {
struct imsgbuf ibuf;
int restricted;
int throttled;
+ int terminate;
};
TAILQ_HEAD(ctl_conns, ctl_conn) ctl_conns;