diff options
author | Eric Faurot <eric@cvs.openbsd.org> | 2013-10-30 21:37:49 +0000 |
---|---|---|
committer | Eric Faurot <eric@cvs.openbsd.org> | 2013-10-30 21:37:49 +0000 |
commit | 496abbc7cb241944aedd953ac7f2d1f0eb334488 (patch) | |
tree | db9ba1dcb57d4d0b0c35b01bbbed923a7beafd3a /usr.sbin | |
parent | 737874eed6d00bb00479fb5cb44543382033dcca (diff) |
add "smtpctl show relays" and "smtpctl show hosts" commands
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/smtpd/control.c | 6 | ||||
-rw-r--r-- | usr.sbin/smtpd/mta.c | 122 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpctl.c | 20 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.c | 5 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 7 |
5 files changed, 154 insertions, 6 deletions
diff --git a/usr.sbin/smtpd/control.c b/usr.sbin/smtpd/control.c index b63704875ed..72eea7b83b3 100644 --- a/usr.sbin/smtpd/control.c +++ b/usr.sbin/smtpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.91 2013/10/27 07:56:25 eric Exp $ */ +/* $OpenBSD: control.c,v 1.92 2013/10/30 21:37:48 eric Exp $ */ /* * Copyright (c) 2012 Gilles Chehade <gilles@poolp.org> @@ -121,6 +121,8 @@ control_imsg(struct mproc *p, struct imsg *imsg) } if (p->proc == PROC_MTA) { switch (imsg->hdr.type) { + case IMSG_CTL_MTA_SHOW_HOSTS: + case IMSG_CTL_MTA_SHOW_RELAYS: case IMSG_CTL_MTA_SHOW_ROUTES: case IMSG_CTL_MTA_SHOW_HOSTSTATS: c = tree_get(&ctl_conns, imsg->hdr.peerid); @@ -705,6 +707,8 @@ control_dispatch_ext(struct mproc *p, struct imsg *imsg) imsg->data, imsg->hdr.len - sizeof(imsg->hdr)); return; + case IMSG_CTL_MTA_SHOW_HOSTS: + case IMSG_CTL_MTA_SHOW_RELAYS: case IMSG_CTL_MTA_SHOW_ROUTES: case IMSG_CTL_MTA_SHOW_HOSTSTATS: if (c->euid) diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c index 613aae66987..f1d30012db3 100644 --- a/usr.sbin/smtpd/mta.c +++ b/usr.sbin/smtpd/mta.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mta.c,v 1.169 2013/10/29 17:04:45 eric Exp $ */ +/* $OpenBSD: mta.c,v 1.170 2013/10/30 21:37:48 eric Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -82,6 +82,7 @@ SPLAY_HEAD(mta_relay_tree, mta_relay); static struct mta_relay *mta_relay(struct envelope *); static void mta_relay_ref(struct mta_relay *); static void mta_relay_unref(struct mta_relay *); +static void mta_relay_show(struct mta_relay *, struct mproc *, uint32_t, time_t); static int mta_relay_cmp(const struct mta_relay *, const struct mta_relay *); SPLAY_PROTOTYPE(mta_relay_tree, mta_relay, entry, mta_relay_cmp); @@ -163,6 +164,7 @@ mta_imsg(struct mproc *p, struct imsg *imsg) struct mta_relay *relay; struct mta_task *task; struct mta_domain *domain; + struct mta_host *host; struct mta_route *route; struct mta_mx *mx, *imx; struct hoststat *hs; @@ -393,6 +395,32 @@ mta_imsg(struct mproc *p, struct imsg *imsg) } return; + case IMSG_CTL_MTA_SHOW_HOSTS: + t = time(NULL); + SPLAY_FOREACH(host, mta_host_tree, &hosts) { + snprintf(buf, sizeof(buf), + "%s %s refcount=%d nconn=%zu lastconn=%s", + sockaddr_to_text(host->sa), + host->ptrname, + host->refcount, + host->nconn, + host->lastconn ? duration_to_text(t - host->lastconn) : "-"); + m_compose(p, IMSG_CTL_MTA_SHOW_HOSTS, + imsg->hdr.peerid, 0, -1, + buf, strlen(buf) + 1); + } + m_compose(p, IMSG_CTL_MTA_SHOW_HOSTS, imsg->hdr.peerid, + 0, -1, NULL, 0); + return; + + case IMSG_CTL_MTA_SHOW_RELAYS: + t = time(NULL); + SPLAY_FOREACH(relay, mta_relay_tree, &relays) + mta_relay_show(relay, p, imsg->hdr.peerid, t); + m_compose(p, IMSG_CTL_MTA_SHOW_RELAYS, imsg->hdr.peerid, + 0, -1, NULL, 0); + return; + case IMSG_CTL_MTA_SHOW_ROUTES: SPLAY_FOREACH(route, mta_route_tree, &routes) { v = runq_pending(runq_route, NULL, route, &t); @@ -1693,6 +1721,98 @@ mta_relay_to_text(struct mta_relay *relay) return (buf); } +static void +mta_relay_show(struct mta_relay *r, struct mproc *p, uint32_t id, time_t t) +{ + struct mta_connector *c; + void *iter; + char buf[1024], flags[1024], dur[64]; + time_t to; + + flags[0] = '\0'; + +#define SHOWSTATUS(f, n) do { \ + if (r->status & (f)) { \ + if (flags[0]) \ + strlcat(flags, ",", sizeof(flags)); \ + strlcat(flags, (n), sizeof(flags)); \ + } \ + } while(0) + + SHOWSTATUS(RELAY_WAIT_MX, "MX"); + SHOWSTATUS(RELAY_WAIT_PREFERENCE, "preference"); + SHOWSTATUS(RELAY_WAIT_SECRET, "secret"); + SHOWSTATUS(RELAY_WAIT_LIMITS, "limits"); + SHOWSTATUS(RELAY_WAIT_SOURCE, "source"); + SHOWSTATUS(RELAY_WAIT_CONNECTOR, "connector"); +#undef SHOWSTATUS + + if (runq_pending(runq_relay, NULL, r, &to)) + snprintf(dur, sizeof(dur), "%s", duration_to_text(to - t)); + else + strlcpy(dur, "-", sizeof(dur)); + + snprintf(buf, sizeof(buf), "%s refcount=%d ntask=%zu nconn=%zu lastconn=%s timeout=%s wait=%s%s", + mta_relay_to_text(r), + r->refcount, + r->ntask, + r->nconn, + r->lastconn ? duration_to_text(t - r->lastconn) : "-", + dur, + flags, + (r->state & RELAY_ONHOLD) ? "ONHOLD" : ""); + m_compose(p, IMSG_CTL_MTA_SHOW_RELAYS, id, 0, -1, buf, strlen(buf) + 1); + + iter = NULL; + while (tree_iter(&r->connectors, &iter, NULL, (void **)&c)) { + + if (runq_pending(runq_connector, NULL, c, &to)) + snprintf(dur, sizeof(dur), "%s", duration_to_text(to - t)); + else + strlcpy(dur, "-", sizeof(dur)); + + flags[0] = '\0'; + +#define SHOWFLAG(f, n) do { \ + if (c->flags & (f)) { \ + if (flags[0]) \ + strlcat(flags, ",", sizeof(flags)); \ + strlcat(flags, (n), sizeof(flags)); \ + } \ + } while(0) + + SHOWFLAG(CONNECTOR_NEW, "NEW"); + SHOWFLAG(CONNECTOR_WAIT, "WAIT"); + + SHOWFLAG(CONNECTOR_ERROR_FAMILY, "ERROR_FAMILY"); + SHOWFLAG(CONNECTOR_ERROR_SOURCE, "ERROR_SOURCE"); + SHOWFLAG(CONNECTOR_ERROR_MX, "ERROR_MX"); + SHOWFLAG(CONNECTOR_ERROR_ROUTE_NET, "ERROR_ROUTE_NET"); + SHOWFLAG(CONNECTOR_ERROR_ROUTE_SMTP, "ERROR_ROUTE_SMTP"); + + SHOWFLAG(CONNECTOR_LIMIT_HOST, "LIMIT_HOST"); + SHOWFLAG(CONNECTOR_LIMIT_ROUTE, "LIMIT_ROUTE"); + SHOWFLAG(CONNECTOR_LIMIT_SOURCE, "LIMIT_SOURCE"); + SHOWFLAG(CONNECTOR_LIMIT_RELAY, "LIMIT_RELAY"); + SHOWFLAG(CONNECTOR_LIMIT_CONN, "LIMIT_CONN"); + SHOWFLAG(CONNECTOR_LIMIT_DOMAIN, "LIMIT_DOMAIN"); +#undef SHOWFLAG + + snprintf(buf, sizeof(buf), + " connector %s refcount=%d nconn=%zu lastconn=%s timeout=%s flags=%s", + mta_source_to_text(c->source), + c->refcount, + c->nconn, + c->lastconn ? duration_to_text(t - c->lastconn) : "-", + dur, + flags); + m_compose(p, IMSG_CTL_MTA_SHOW_RELAYS, id, 0, -1, buf, + strlen(buf) + 1); + + + } +} + static int mta_relay_cmp(const struct mta_relay *a, const struct mta_relay *b) { diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c index 51c91aeb083..58415c30ae2 100644 --- a/usr.sbin/smtpd/smtpctl.c +++ b/usr.sbin/smtpd/smtpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpctl.c,v 1.111 2013/10/27 17:47:53 eric Exp $ */ +/* $OpenBSD: smtpctl.c,v 1.112 2013/10/30 21:37:48 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot <eric@openbsd.org> @@ -679,6 +679,22 @@ do_show_queue(int argc, struct parameter *argv) } static int +do_show_hosts(int argc, struct parameter *argv) +{ + srv_show_cmd(IMSG_CTL_MTA_SHOW_HOSTS, NULL, 0); + + return (0); +} + +static int +do_show_relays(int argc, struct parameter *argv) +{ + srv_show_cmd(IMSG_CTL_MTA_SHOW_RELAYS, NULL, 0); + + return (0); +} + +static int do_show_routes(int argc, struct parameter *argv) { srv_show_cmd(IMSG_CTL_MTA_SHOW_ROUTES, NULL, 0); @@ -827,6 +843,8 @@ main(int argc, char **argv) cmd_install("show message <evpid>", do_show_message); cmd_install("show queue", do_show_queue); cmd_install("show queue <msgid>", do_show_queue); + cmd_install("show hosts", do_show_hosts); + cmd_install("show relays", do_show_relays); cmd_install("show routes", do_show_routes); cmd_install("show stats", do_show_stats); cmd_install("stop", do_stop); diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c index 620e14f6e09..4ed2631723d 100644 --- a/usr.sbin/smtpd/smtpd.c +++ b/usr.sbin/smtpd/smtpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.c,v 1.202 2013/10/27 17:47:53 eric Exp $ */ +/* $OpenBSD: smtpd.c,v 1.203 2013/10/30 21:37:48 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -1458,6 +1458,8 @@ imsg_to_str(int type) CASE(IMSG_CTL_PROFILE); CASE(IMSG_CTL_UNPROFILE); + CASE(IMSG_CTL_MTA_SHOW_HOSTS); + CASE(IMSG_CTL_MTA_SHOW_RELAYS); CASE(IMSG_CTL_MTA_SHOW_ROUTES); CASE(IMSG_CTL_MTA_SHOW_HOSTSTATS); @@ -1470,6 +1472,7 @@ imsg_to_str(int type) CASE(IMSG_CONF_RULE_SOURCE); CASE(IMSG_CONF_RULE_SENDER); CASE(IMSG_CONF_RULE_DESTINATION); + CASE(IMSG_CONF_RULE_RECIPIENT); CASE(IMSG_CONF_RULE_MAPPING); CASE(IMSG_CONF_RULE_USERS); CASE(IMSG_CONF_FILTER); diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 9b9cd7d1eb4..3baddd8f243 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.431 2013/10/29 17:04:46 eric Exp $ */ +/* $OpenBSD: smtpd.h,v 1.432 2013/10/30 21:37:48 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -151,7 +151,7 @@ union lookup { * Bump IMSG_VERSION whenever a change is made to enum imsg_type. * This will ensure that we can never use a wrong version of smtpctl with smtpd. */ -#define IMSG_VERSION 6 +#define IMSG_VERSION 7 enum imsg_type { IMSG_NONE, @@ -178,6 +178,8 @@ enum imsg_type { IMSG_CTL_PROFILE, IMSG_CTL_UNPROFILE, + IMSG_CTL_MTA_SHOW_HOSTS, + IMSG_CTL_MTA_SHOW_RELAYS, IMSG_CTL_MTA_SHOW_ROUTES, IMSG_CTL_MTA_SHOW_HOSTSTATS, @@ -190,6 +192,7 @@ enum imsg_type { IMSG_CONF_RULE_SOURCE, IMSG_CONF_RULE_SENDER, IMSG_CONF_RULE_DESTINATION, + IMSG_CONF_RULE_RECIPIENT, IMSG_CONF_RULE_MAPPING, IMSG_CONF_RULE_USERS, IMSG_CONF_FILTER, |