diff options
author | 2007-02-22 03:32:39 +0000 | |
---|---|---|
committer | 2007-02-22 03:32:39 +0000 | |
commit | 2edd718bd68a9c827be137ebb51a319071210c69 (patch) | |
tree | 8c1c5b888f71aa148d70db79b9527a623ad5e0be /usr.sbin/relayctl | |
parent | Expand description. (diff) | |
download | wireguard-openbsd-2edd718bd68a9c827be137ebb51a319071210c69.tar.xz wireguard-openbsd-2edd718bd68a9c827be137ebb51a319071210c69.zip |
Add layer 7 functionality to hoststated used for layer 7
loadbalancing, SSL acceleration, general-purpose TCP relaying, and
transparent proxying.
see hoststated.conf(5) and my upcoming article on undeadly.org for
details.
ok to commit deraadt@ pyr@
Diffstat (limited to 'usr.sbin/relayctl')
-rw-r--r-- | usr.sbin/relayctl/parser.c | 12 | ||||
-rw-r--r-- | usr.sbin/relayctl/parser.h | 4 | ||||
-rw-r--r-- | usr.sbin/relayctl/relayctl.8 | 20 | ||||
-rw-r--r-- | usr.sbin/relayctl/relayctl.c | 98 |
4 files changed, 111 insertions, 23 deletions
diff --git a/usr.sbin/relayctl/parser.c b/usr.sbin/relayctl/parser.c index 12ce147835f..3490043d865 100644 --- a/usr.sbin/relayctl/parser.c +++ b/usr.sbin/relayctl/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.9 2007/02/06 16:24:14 pyr Exp $ */ +/* $OpenBSD: parser.c,v 1.10 2007/02/22 03:32:40 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -55,6 +55,7 @@ struct token { }; static const struct token t_main[]; +static const struct token t_show[]; static const struct token t_service[]; static const struct token t_table[]; static const struct token t_host[]; @@ -64,7 +65,7 @@ static const struct token t_host_id[]; static const struct token t_main[] = { {KEYWORD, "monitor", MONITOR, NULL}, - {KEYWORD, "show", SHOW_SUM, NULL}, + {KEYWORD, "show", NULL, t_show}, {KEYWORD, "stop", SHUTDOWN, NULL}, {KEYWORD, "service", NONE, t_service}, {KEYWORD, "table", NONE, t_table}, @@ -72,6 +73,13 @@ static const struct token t_main[] = { {ENDTOKEN, "", NONE, NULL} }; +static const struct token t_show[] = { + {KEYWORD, "summary", SHOW_SUM, NULL}, + {KEYWORD, "hosts", SHOW_HOSTS, NULL}, + {KEYWORD, "relays", SHOW_RELAYS, NULL}, + {ENDTOKEN, "", NONE, NULL} +}; + static const struct token t_service[] = { {NOTOKEN, "", NONE, NULL}, {KEYWORD, "disable", SERV_DISABLE, t_service_id}, diff --git a/usr.sbin/relayctl/parser.h b/usr.sbin/relayctl/parser.h index 9d0cbeb62a7..0f9509f7dbf 100644 --- a/usr.sbin/relayctl/parser.h +++ b/usr.sbin/relayctl/parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.h,v 1.3 2007/02/01 20:03:38 pyr Exp $ */ +/* $OpenBSD: parser.h,v 1.4 2007/02/22 03:32:40 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -19,6 +19,8 @@ enum actions { NONE, SHOW_SUM, + SHOW_HOSTS, + SHOW_RELAYS, SERV_DISABLE, SERV_ENABLE, TABLE_DISABLE, diff --git a/usr.sbin/relayctl/relayctl.8 b/usr.sbin/relayctl/relayctl.8 index 5b26cb1d91a..51b94ffd90a 100644 --- a/usr.sbin/relayctl/relayctl.8 +++ b/usr.sbin/relayctl/relayctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: relayctl.8,v 1.7 2007/02/01 20:03:38 pyr Exp $ +.\" $OpenBSD: relayctl.8,v 1.8 2007/02/22 03:32:40 reyk Exp $ .\" .\" Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> .\" @@ -53,11 +53,14 @@ if applicable \(en backup table disabled as well. Enable a service. Mark the service's main table and \(en if applicable \(en backup table enabled as well. -.It Cm show Op Cm summary -Show status of services, tables, and hosts. -The keyword -.Cm summary -is optional. +.It Cm show hosts +Show detailed status of hosts, tables, and services. +.It Cm show relays +Show detailed status of relays including the current and average +access statistics. +The statistics will be updated every minute. +.It Cm show summary +Display a list of all relays, services, tables, and hosts. .It Cm table disable Op Ar name | id Disable a table. Consider all hosts disabled. @@ -78,3 +81,8 @@ Unix-domain socket used for communication with .El .Sh SEE ALSO .Xr hoststated 8 +.Sh HISTORY +The +.Nm +program first appeared in +.Ox 4.1 . diff --git a/usr.sbin/relayctl/relayctl.c b/usr.sbin/relayctl/relayctl.c index b5993bd237f..b0b494c2ecc 100644 --- a/usr.sbin/relayctl/relayctl.c +++ b/usr.sbin/relayctl/relayctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relayctl.c,v 1.14 2007/02/06 08:45:46 pyr Exp $ */ +/* $OpenBSD: relayctl.c,v 1.15 2007/02/22 03:32:40 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -43,11 +43,12 @@ #include "parser.h" __dead void usage(void); -int show_summary_msg(struct imsg *); +int show_summary_msg(struct imsg *, int); int show_command_output(struct imsg *); char *print_service_status(int); char *print_host_status(int, int); char *print_table_status(int, int); +char *print_relay_status(int); struct imsgname { int type; @@ -139,8 +140,11 @@ main(int argc, char *argv[]) usage(); /* not reached */ case SHOW_SUM: + case SHOW_HOSTS: + case SHOW_RELAYS: imsg_compose(ibuf, IMSG_CTL_SHOW_SUM, 0, 0, NULL, 0); - printf("Type\t%4s\t%-24s\tStatus\n", "Id", "Name"); + printf("Type\t%4s\t%-24s\t%-7s\tStatus\n", + "Id", "Name", "Avlblty"); break; case SERV_ENABLE: imsg_compose(ibuf, IMSG_CTL_SERVICE_ENABLE, 0, 0, @@ -194,7 +198,13 @@ main(int argc, char *argv[]) break; switch (res->action) { case SHOW_SUM: - done = show_summary_msg(&imsg); + done = show_summary_msg(&imsg, SHOW_SUM); + break; + case SHOW_HOSTS: + done = show_summary_msg(&imsg, SHOW_HOSTS); + break; + case SHOW_RELAYS: + done = show_summary_msg(&imsg, SHOW_RELAYS); break; case SERV_DISABLE: case SERV_ENABLE: @@ -286,31 +296,81 @@ monitor(struct imsg *imsg) } int -show_summary_msg(struct imsg *imsg) +show_summary_msg(struct imsg *imsg, int type) { - struct service *service; - struct table *table; - struct host *host; + struct service *service; + struct table *table; + struct host *host; + struct relay *rlay; + struct ctl_stats stats[RELAY_MAXPROC], crs; + int i; switch (imsg->hdr.type) { case IMSG_CTL_SERVICE: + if (type == SHOW_RELAYS) + break; service = imsg->data; - printf("service\t%4u\t%-24s\t%s\n", - service->id, service->name, + printf("service\t%4u\t%-24s\t%-7s\t%s\n", + service->id, service->name, "", print_service_status(service->flags)); break; case IMSG_CTL_TABLE: + if (type == SHOW_RELAYS) + break; table = imsg->data; - printf("table\t%4u\t%-24s\t%s", - table->id, table->name, + printf("table\t%4u\t%-24s\t%-7s\t%s\n", + table->id, table->name, "", print_table_status(table->up, table->flags)); - printf("\n"); break; case IMSG_CTL_HOST: + if (type == SHOW_RELAYS) + break; host = imsg->data; - printf("host\t%4u\t%-24s\t%s\n", + printf("host\t%4u\t%-24s\t%-7s\t%s\n", host->id, host->name, + print_availability(host->check_cnt, host->up_cnt), print_host_status(host->up, host->flags)); + if (type == SHOW_HOSTS && host->check_cnt) { + printf("\t%4s\ttotal: %lu/%lu checks", + "", host->up_cnt, host->check_cnt); + if (host->retry_cnt) + printf(", %d retries", host->retry_cnt); + printf("\n"); + } + break; + case IMSG_CTL_RELAY: + if (type == SHOW_HOSTS) + break; + rlay = imsg->data; + printf("relay\t%4u\t%-24s\t%-7s\t%s\n", + rlay->id, rlay->name, "", + print_relay_status(rlay->flags)); + break; + case IMSG_CTL_STATISTICS: + if (type != SHOW_RELAYS) + break; + bcopy(imsg->data, &stats, sizeof(stats)); + bzero(&crs, sizeof(crs)); + crs.interval = stats[0].interval; + for (i = 0; stats[i].id != EMPTY_ID; i++) { + crs.cnt += stats[i].cnt; + crs.last += stats[i].last; + crs.avg += stats[i].avg; + crs.last_hour += stats[i].last_hour; + crs.avg_hour += stats[i].avg_hour; + crs.last_day += stats[i].last_day; + crs.avg_day += stats[i].avg_day; + } + if (crs.cnt == 0) + break; + printf("\t%4s\ttotal: %lu sessions\n" + "\t%4s\tlast: %lu/%us %lu/h %lu/d sessions\n" + "\t%4s\taverage: %lu/%us %lu/h %lu/d sessions\n", + "", crs.cnt, + "", crs.last, crs.interval, + crs.last_hour, crs.last_day, + "", crs.avg, crs.interval, + crs.avg_hour, crs.avg_day); break; case IMSG_CTL_END: return (1); @@ -383,3 +443,13 @@ print_host_status(int status, int fl) errx(1, "invalid status: %d", status); } } + +char * +print_relay_status(int flags) +{ + if (flags & F_DISABLE) { + return ("disabled"); + } else + return ("active"); +} + |