diff options
author | Pierre-Yves Ritschard <pyr@cvs.openbsd.org> | 2007-02-01 20:03:40 +0000 |
---|---|---|
committer | Pierre-Yves Ritschard <pyr@cvs.openbsd.org> | 2007-02-01 20:03:40 +0000 |
commit | 46916cfa3030ecdd425a21f5c24dd678f3ebc921 (patch) | |
tree | 9ce456c6fd8ebd072c0120d564bbe0c558b3dd28 /usr.sbin | |
parent | c38997fcc31e1562eb59356cb266390c618c4939 (diff) |
add a monitor mode to hoststatectl to continuously report changes in
hoststated.
ok reyk@, "looks nice and clean" niallo@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/hoststatectl/hoststatectl.8 | 5 | ||||
-rw-r--r-- | usr.sbin/hoststatectl/hoststatectl.c | 60 | ||||
-rw-r--r-- | usr.sbin/hoststatectl/parser.c | 3 | ||||
-rw-r--r-- | usr.sbin/hoststatectl/parser.h | 5 | ||||
-rw-r--r-- | usr.sbin/hoststated/control.c | 55 | ||||
-rw-r--r-- | usr.sbin/hoststated/hoststated.h | 9 | ||||
-rw-r--r-- | usr.sbin/hoststated/pfe.c | 9 | ||||
-rw-r--r-- | usr.sbin/relayctl/parser.c | 3 | ||||
-rw-r--r-- | usr.sbin/relayctl/parser.h | 5 | ||||
-rw-r--r-- | usr.sbin/relayctl/relayctl.8 | 5 | ||||
-rw-r--r-- | usr.sbin/relayctl/relayctl.c | 60 | ||||
-rw-r--r-- | usr.sbin/relayd/control.c | 55 | ||||
-rw-r--r-- | usr.sbin/relayd/pfe.c | 9 | ||||
-rw-r--r-- | usr.sbin/relayd/relayd.h | 9 |
14 files changed, 256 insertions, 36 deletions
diff --git a/usr.sbin/hoststatectl/hoststatectl.8 b/usr.sbin/hoststatectl/hoststatectl.8 index cf9ec96a120..f131b8139b8 100644 --- a/usr.sbin/hoststatectl/hoststatectl.8 +++ b/usr.sbin/hoststatectl/hoststatectl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: hoststatectl.8,v 1.6 2007/01/09 13:50:10 pyr Exp $ +.\" $OpenBSD: hoststatectl.8,v 1.7 2007/02/01 20:03:38 pyr Exp $ .\" .\" Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> .\" @@ -39,6 +39,9 @@ Treat it as though it were always down. .It Cm host enable Op Ar name | id Enable the host. Start checking its health again. +.It Cm monitor +Continuously report any changes in the host checking engine and the +pf engine. .It Cm service disable Op Ar name | id Disable a service. If it has diff --git a/usr.sbin/hoststatectl/hoststatectl.c b/usr.sbin/hoststatectl/hoststatectl.c index 8ef62fff0e2..5c6abbd5074 100644 --- a/usr.sbin/hoststatectl/hoststatectl.c +++ b/usr.sbin/hoststatectl/hoststatectl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hoststatectl.c,v 1.9 2007/01/29 14:23:31 pyr Exp $ */ +/* $OpenBSD: hoststatectl.c,v 1.10 2007/02/01 20:03:38 pyr Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -44,6 +44,7 @@ __dead void usage(void); int show_summary_msg(struct imsg *); int show_command_output(struct imsg *); +int monitor(struct imsg *); char *print_service_status(int); char *print_host_status(int, int); char *print_table_status(int, int); @@ -134,6 +135,9 @@ main(int argc, char *argv[]) case RELOAD: imsg_compose(ibuf, IMSG_CTL_RELOAD, 0, 0, NULL, 0); break; + case MONITOR: + imsg_compose(ibuf, IMSG_CTL_NOTIFY, 0, 0, NULL, 0); + break; } while (ibuf->w.queued) @@ -167,6 +171,9 @@ main(int argc, char *argv[]) case SHUTDOWN: case NONE: break; + case MONITOR: + done = monitor(&imsg); + break; } imsg_free(&imsg); } @@ -178,6 +185,57 @@ main(int argc, char *argv[]) } int +monitor(struct imsg *imsg) +{ + time_t now; + int done; + struct ctl_status cs; + struct ctl_id id; + + done = 0; + now = time(NULL); + printf("got message of size %u on %s", imsg->hdr.len, ctime(&now)); + switch (imsg->hdr.type) { + case IMSG_HOST_STATUS: + memcpy(&cs, imsg->data, sizeof(cs)); + printf("HOST_STATUS: %u is in state %d\n", cs.id, cs.up); + break; + case IMSG_CTL_SERVICE_DISABLE: + memcpy(&id, imsg->data, sizeof(id)); + printf("CTL_SERVICE_DISABLE: %u\n", id.id); + break; + case IMSG_CTL_SERVICE_ENABLE: + memcpy(&id, imsg->data, sizeof(id)); + printf("CTL_SERVICE_ENABLE: %u\n", id.id); + break; + case IMSG_CTL_TABLE_DISABLE: + memcpy(&id, imsg->data, sizeof(id)); + printf("CTL_TABLE_DISABLE: %u\n", id.id); + break; + case IMSG_CTL_TABLE_ENABLE: + memcpy(&id, imsg->data, sizeof(id)); + printf("CTL_TABLE_ENABLE: %u\n", id.id); + break; + case IMSG_CTL_HOST_DISABLE: + memcpy(&id, imsg->data, sizeof(id)); + printf("CTL_HOST_DISABLE: %u\n", id.id); + break; + case IMSG_CTL_HOST_ENABLE: + memcpy(&id, imsg->data, sizeof(id)); + printf("CTL_HOST_ENABLE: %u\n", id.id); + break; + case IMSG_SYNC: + printf("SYNC\n"); + break; + default: + printf("INVALID\n"); + done = 1; + break; + } + return (done); +} + +int show_summary_msg(struct imsg *imsg) { struct service *service; diff --git a/usr.sbin/hoststatectl/parser.c b/usr.sbin/hoststatectl/parser.c index aca5a16c9e9..3347f2639f0 100644 --- a/usr.sbin/hoststatectl/parser.c +++ b/usr.sbin/hoststatectl/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.7 2007/01/29 14:23:31 pyr Exp $ */ +/* $OpenBSD: parser.c,v 1.8 2007/02/01 20:03:38 pyr Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -63,6 +63,7 @@ static const struct token t_table_id[]; static const struct token t_host_id[]; static const struct token t_main[] = { + {KEYWORD, "monitor", MONITOR, NULL}, {KEYWORD, "show", SHOW_SUM, NULL}, {KEYWORD, "stop", SHUTDOWN, NULL}, {KEYWORD, "service", NULL, t_service}, diff --git a/usr.sbin/hoststatectl/parser.h b/usr.sbin/hoststatectl/parser.h index 1f1c8e879e1..9d0cbeb62a7 100644 --- a/usr.sbin/hoststatectl/parser.h +++ b/usr.sbin/hoststatectl/parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.h,v 1.2 2006/12/16 18:50:33 reyk Exp $ */ +/* $OpenBSD: parser.h,v 1.3 2007/02/01 20:03:38 pyr Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -26,7 +26,8 @@ enum actions { HOST_DISABLE, HOST_ENABLE, SHUTDOWN, - RELOAD + RELOAD, + MONITOR }; struct parse_result { diff --git a/usr.sbin/hoststated/control.c b/usr.sbin/hoststated/control.c index b7f78b2434e..a24b86deada 100644 --- a/usr.sbin/hoststated/control.c +++ b/usr.sbin/hoststated/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.10 2007/01/29 14:23:31 pyr Exp $ */ +/* $OpenBSD: control.c,v 1.11 2007/02/01 20:03:39 pyr Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -39,8 +39,6 @@ struct ctl_connlist ctl_conns; -int control_imsg_relay(struct imsg *imsg); - struct ctl_conn *control_connbyfd(int); struct ctl_conn *control_connbypid(pid_t); void control_close(int); @@ -238,9 +236,12 @@ control_dispatch_imsg(int fd, short event, void *arg) if (disable_service(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_SERVICE_ENABLE: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id)) @@ -249,9 +250,12 @@ control_dispatch_imsg(int fd, short event, void *arg) if (enable_service(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_TABLE_DISABLE: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id)) @@ -260,9 +264,12 @@ control_dispatch_imsg(int fd, short event, void *arg) if (disable_table(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_TABLE_ENABLE: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id)) @@ -271,9 +278,12 @@ control_dispatch_imsg(int fd, short event, void *arg) if (enable_table(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_HOST_DISABLE: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id)) @@ -282,9 +292,12 @@ control_dispatch_imsg(int fd, short event, void *arg) if (disable_host(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_HOST_ENABLE: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id)) @@ -293,14 +306,27 @@ control_dispatch_imsg(int fd, short event, void *arg) if (enable_host(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_SHUTDOWN: case IMSG_CTL_RELOAD: imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); break; + case IMSG_CTL_NOTIFY: + if (c->flags & CTL_CONN_NOTIFY) { + log_debug("control_dispatch_imsg: " + "client requested notify more than once"); + imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, + NULL, 0); + break; + } + c->flags |= CTL_CONN_NOTIFY; + break; default: log_debug("control_dispatch_imsg: " "error handling imsg %d", imsg.hdr.type); @@ -325,6 +351,17 @@ control_imsg_relay(struct imsg *imsg) } void +control_imsg_forward(struct imsg *imsg) +{ + struct ctl_conn *c; + + TAILQ_FOREACH(c, &ctl_conns, entry) + if (c->flags & CTL_CONN_NOTIFY) + imsg_compose(&c->ibuf, imsg->hdr.type, 0, imsg->hdr.pid, + imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE); +} + +void session_socket_blockmode(int fd, enum blockmodes bm) { int flags; diff --git a/usr.sbin/hoststated/hoststated.h b/usr.sbin/hoststated/hoststated.h index ba216828970..07931328c8f 100644 --- a/usr.sbin/hoststated/hoststated.h +++ b/usr.sbin/hoststated/hoststated.h @@ -1,4 +1,4 @@ -/* $OpenBSD: hoststated.h,v 1.17 2007/01/29 14:23:31 pyr Exp $ */ +/* $OpenBSD: hoststated.h,v 1.18 2007/02/01 20:03:39 pyr Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -89,14 +89,14 @@ enum imsg_type { IMSG_CTL_HOST_DISABLE, IMSG_CTL_SHUTDOWN, IMSG_CTL_RELOAD, + IMSG_CTL_NOTIFY, IMSG_SERVICE_ENABLE, /* notifies from pfe to hce */ IMSG_SERVICE_DISABLE, IMSG_TABLE_ENABLE, IMSG_TABLE_DISABLE, IMSG_HOST_ENABLE, IMSG_HOST_DISABLE, - IMSG_TABLE_STATUS, /* notifies from hce to pfe */ - IMSG_HOST_STATUS, + IMSG_HOST_STATUS, /* notifies from hce to pfe */ IMSG_SYNC }; @@ -270,6 +270,8 @@ enum blockmodes { struct ctl_conn { TAILQ_ENTRY(ctl_conn) entry; + u_int8_t flags; +#define CTL_CONN_NOTIFY 0x01 struct imsgbuf ibuf; }; @@ -281,6 +283,7 @@ int control_listen(void); void control_accept(int, short, void *); void control_dispatch_imsg(int, short, void *); int control_imsg_relay(struct imsg *); +void control_imsg_forward(struct imsg *); void control_cleanup(void); void session_socket_blockmode(int, enum blockmodes); diff --git a/usr.sbin/hoststated/pfe.c b/usr.sbin/hoststated/pfe.c index 43c6f358c37..b77b411d82b 100644 --- a/usr.sbin/hoststated/pfe.c +++ b/usr.sbin/hoststated/pfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfe.c,v 1.9 2007/01/29 14:23:31 pyr Exp $ */ +/* $OpenBSD: pfe.c,v 1.10 2007/02/01 20:03:39 pyr Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -182,6 +182,7 @@ pfe_dispatch_imsg(int fd, short event, void *ptr) if (n == 0) break; + control_imsg_forward(&imsg); switch (imsg.hdr.type) { case IMSG_HOST_STATUS: if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(st)) @@ -314,6 +315,7 @@ disable_service(struct ctl_conn *c, struct ctl_id *id) service = service_findbyname(env, id->name); else service = service_find(env, id->id); + id->id = service->id; if (service == NULL) return (-1); @@ -339,6 +341,7 @@ enable_service(struct ctl_conn *c, struct ctl_id *id) service = service_findbyname(env, id->name); else service = service_find(env, id->id); + id->id = service->id; if (service == NULL) return (-1); @@ -373,6 +376,7 @@ disable_table(struct ctl_conn *c, struct ctl_id *id) table = table_findbyname(env, id->name); else table = table_find(env, id->id); + id->id = table->id; if (table == NULL) return (-1); if ((service = service_find(env, table->serviceid)) == NULL) @@ -402,6 +406,7 @@ enable_table(struct ctl_conn *c, struct ctl_id *id) table = table_findbyname(env, id->name); else table = table_find(env, id->id); + id->id = table->id; if (table == NULL) return (-1); @@ -432,6 +437,7 @@ disable_host(struct ctl_conn *c, struct ctl_id *id) host = host_findbyname(env, id->name); else host = host_find(env, id->id); + id->id = host->id; if (host == NULL) return (-1); @@ -466,6 +472,7 @@ enable_host(struct ctl_conn *c, struct ctl_id *id) host = host_findbyname(env, id->name); else host = host_find(env, id->id); + id->id = host->id; if (host == NULL) return (-1); diff --git a/usr.sbin/relayctl/parser.c b/usr.sbin/relayctl/parser.c index aca5a16c9e9..3347f2639f0 100644 --- a/usr.sbin/relayctl/parser.c +++ b/usr.sbin/relayctl/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.7 2007/01/29 14:23:31 pyr Exp $ */ +/* $OpenBSD: parser.c,v 1.8 2007/02/01 20:03:38 pyr Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -63,6 +63,7 @@ static const struct token t_table_id[]; static const struct token t_host_id[]; static const struct token t_main[] = { + {KEYWORD, "monitor", MONITOR, NULL}, {KEYWORD, "show", SHOW_SUM, NULL}, {KEYWORD, "stop", SHUTDOWN, NULL}, {KEYWORD, "service", NULL, t_service}, diff --git a/usr.sbin/relayctl/parser.h b/usr.sbin/relayctl/parser.h index 1f1c8e879e1..9d0cbeb62a7 100644 --- a/usr.sbin/relayctl/parser.h +++ b/usr.sbin/relayctl/parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.h,v 1.2 2006/12/16 18:50:33 reyk Exp $ */ +/* $OpenBSD: parser.h,v 1.3 2007/02/01 20:03:38 pyr Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -26,7 +26,8 @@ enum actions { HOST_DISABLE, HOST_ENABLE, SHUTDOWN, - RELOAD + RELOAD, + MONITOR }; struct parse_result { diff --git a/usr.sbin/relayctl/relayctl.8 b/usr.sbin/relayctl/relayctl.8 index 61a11ce7942..5b26cb1d91a 100644 --- a/usr.sbin/relayctl/relayctl.8 +++ b/usr.sbin/relayctl/relayctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: relayctl.8,v 1.6 2007/01/09 13:50:10 pyr Exp $ +.\" $OpenBSD: relayctl.8,v 1.7 2007/02/01 20:03:38 pyr Exp $ .\" .\" Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> .\" @@ -39,6 +39,9 @@ Treat it as though it were always down. .It Cm host enable Op Ar name | id Enable the host. Start checking its health again. +.It Cm monitor +Continuously report any changes in the host checking engine and the +pf engine. .It Cm service disable Op Ar name | id Disable a service. If it has diff --git a/usr.sbin/relayctl/relayctl.c b/usr.sbin/relayctl/relayctl.c index 8332f2f0229..cfb796c43ce 100644 --- a/usr.sbin/relayctl/relayctl.c +++ b/usr.sbin/relayctl/relayctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relayctl.c,v 1.9 2007/01/29 14:23:31 pyr Exp $ */ +/* $OpenBSD: relayctl.c,v 1.10 2007/02/01 20:03:38 pyr Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -44,6 +44,7 @@ __dead void usage(void); int show_summary_msg(struct imsg *); int show_command_output(struct imsg *); +int monitor(struct imsg *); char *print_service_status(int); char *print_host_status(int, int); char *print_table_status(int, int); @@ -134,6 +135,9 @@ main(int argc, char *argv[]) case RELOAD: imsg_compose(ibuf, IMSG_CTL_RELOAD, 0, 0, NULL, 0); break; + case MONITOR: + imsg_compose(ibuf, IMSG_CTL_NOTIFY, 0, 0, NULL, 0); + break; } while (ibuf->w.queued) @@ -167,6 +171,9 @@ main(int argc, char *argv[]) case SHUTDOWN: case NONE: break; + case MONITOR: + done = monitor(&imsg); + break; } imsg_free(&imsg); } @@ -178,6 +185,57 @@ main(int argc, char *argv[]) } int +monitor(struct imsg *imsg) +{ + time_t now; + int done; + struct ctl_status cs; + struct ctl_id id; + + done = 0; + now = time(NULL); + printf("got message of size %u on %s", imsg->hdr.len, ctime(&now)); + switch (imsg->hdr.type) { + case IMSG_HOST_STATUS: + memcpy(&cs, imsg->data, sizeof(cs)); + printf("HOST_STATUS: %u is in state %d\n", cs.id, cs.up); + break; + case IMSG_CTL_SERVICE_DISABLE: + memcpy(&id, imsg->data, sizeof(id)); + printf("CTL_SERVICE_DISABLE: %u\n", id.id); + break; + case IMSG_CTL_SERVICE_ENABLE: + memcpy(&id, imsg->data, sizeof(id)); + printf("CTL_SERVICE_ENABLE: %u\n", id.id); + break; + case IMSG_CTL_TABLE_DISABLE: + memcpy(&id, imsg->data, sizeof(id)); + printf("CTL_TABLE_DISABLE: %u\n", id.id); + break; + case IMSG_CTL_TABLE_ENABLE: + memcpy(&id, imsg->data, sizeof(id)); + printf("CTL_TABLE_ENABLE: %u\n", id.id); + break; + case IMSG_CTL_HOST_DISABLE: + memcpy(&id, imsg->data, sizeof(id)); + printf("CTL_HOST_DISABLE: %u\n", id.id); + break; + case IMSG_CTL_HOST_ENABLE: + memcpy(&id, imsg->data, sizeof(id)); + printf("CTL_HOST_ENABLE: %u\n", id.id); + break; + case IMSG_SYNC: + printf("SYNC\n"); + break; + default: + printf("INVALID\n"); + done = 1; + break; + } + return (done); +} + +int show_summary_msg(struct imsg *imsg) { struct service *service; diff --git a/usr.sbin/relayd/control.c b/usr.sbin/relayd/control.c index b7f78b2434e..a24b86deada 100644 --- a/usr.sbin/relayd/control.c +++ b/usr.sbin/relayd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.10 2007/01/29 14:23:31 pyr Exp $ */ +/* $OpenBSD: control.c,v 1.11 2007/02/01 20:03:39 pyr Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -39,8 +39,6 @@ struct ctl_connlist ctl_conns; -int control_imsg_relay(struct imsg *imsg); - struct ctl_conn *control_connbyfd(int); struct ctl_conn *control_connbypid(pid_t); void control_close(int); @@ -238,9 +236,12 @@ control_dispatch_imsg(int fd, short event, void *arg) if (disable_service(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_SERVICE_ENABLE: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id)) @@ -249,9 +250,12 @@ control_dispatch_imsg(int fd, short event, void *arg) if (enable_service(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_TABLE_DISABLE: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id)) @@ -260,9 +264,12 @@ control_dispatch_imsg(int fd, short event, void *arg) if (disable_table(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_TABLE_ENABLE: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id)) @@ -271,9 +278,12 @@ control_dispatch_imsg(int fd, short event, void *arg) if (enable_table(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_HOST_DISABLE: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id)) @@ -282,9 +292,12 @@ control_dispatch_imsg(int fd, short event, void *arg) if (disable_host(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_HOST_ENABLE: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id)) @@ -293,14 +306,27 @@ control_dispatch_imsg(int fd, short event, void *arg) if (enable_host(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_SHUTDOWN: case IMSG_CTL_RELOAD: imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); break; + case IMSG_CTL_NOTIFY: + if (c->flags & CTL_CONN_NOTIFY) { + log_debug("control_dispatch_imsg: " + "client requested notify more than once"); + imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, + NULL, 0); + break; + } + c->flags |= CTL_CONN_NOTIFY; + break; default: log_debug("control_dispatch_imsg: " "error handling imsg %d", imsg.hdr.type); @@ -325,6 +351,17 @@ control_imsg_relay(struct imsg *imsg) } void +control_imsg_forward(struct imsg *imsg) +{ + struct ctl_conn *c; + + TAILQ_FOREACH(c, &ctl_conns, entry) + if (c->flags & CTL_CONN_NOTIFY) + imsg_compose(&c->ibuf, imsg->hdr.type, 0, imsg->hdr.pid, + imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE); +} + +void session_socket_blockmode(int fd, enum blockmodes bm) { int flags; diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c index 43c6f358c37..b77b411d82b 100644 --- a/usr.sbin/relayd/pfe.c +++ b/usr.sbin/relayd/pfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfe.c,v 1.9 2007/01/29 14:23:31 pyr Exp $ */ +/* $OpenBSD: pfe.c,v 1.10 2007/02/01 20:03:39 pyr Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -182,6 +182,7 @@ pfe_dispatch_imsg(int fd, short event, void *ptr) if (n == 0) break; + control_imsg_forward(&imsg); switch (imsg.hdr.type) { case IMSG_HOST_STATUS: if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(st)) @@ -314,6 +315,7 @@ disable_service(struct ctl_conn *c, struct ctl_id *id) service = service_findbyname(env, id->name); else service = service_find(env, id->id); + id->id = service->id; if (service == NULL) return (-1); @@ -339,6 +341,7 @@ enable_service(struct ctl_conn *c, struct ctl_id *id) service = service_findbyname(env, id->name); else service = service_find(env, id->id); + id->id = service->id; if (service == NULL) return (-1); @@ -373,6 +376,7 @@ disable_table(struct ctl_conn *c, struct ctl_id *id) table = table_findbyname(env, id->name); else table = table_find(env, id->id); + id->id = table->id; if (table == NULL) return (-1); if ((service = service_find(env, table->serviceid)) == NULL) @@ -402,6 +406,7 @@ enable_table(struct ctl_conn *c, struct ctl_id *id) table = table_findbyname(env, id->name); else table = table_find(env, id->id); + id->id = table->id; if (table == NULL) return (-1); @@ -432,6 +437,7 @@ disable_host(struct ctl_conn *c, struct ctl_id *id) host = host_findbyname(env, id->name); else host = host_find(env, id->id); + id->id = host->id; if (host == NULL) return (-1); @@ -466,6 +472,7 @@ enable_host(struct ctl_conn *c, struct ctl_id *id) host = host_findbyname(env, id->name); else host = host_find(env, id->id); + id->id = host->id; if (host == NULL) return (-1); diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h index f375d5724c6..bd16884396a 100644 --- a/usr.sbin/relayd/relayd.h +++ b/usr.sbin/relayd/relayd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: relayd.h,v 1.17 2007/01/29 14:23:31 pyr Exp $ */ +/* $OpenBSD: relayd.h,v 1.18 2007/02/01 20:03:39 pyr Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -89,14 +89,14 @@ enum imsg_type { IMSG_CTL_HOST_DISABLE, IMSG_CTL_SHUTDOWN, IMSG_CTL_RELOAD, + IMSG_CTL_NOTIFY, IMSG_SERVICE_ENABLE, /* notifies from pfe to hce */ IMSG_SERVICE_DISABLE, IMSG_TABLE_ENABLE, IMSG_TABLE_DISABLE, IMSG_HOST_ENABLE, IMSG_HOST_DISABLE, - IMSG_TABLE_STATUS, /* notifies from hce to pfe */ - IMSG_HOST_STATUS, + IMSG_HOST_STATUS, /* notifies from hce to pfe */ IMSG_SYNC }; @@ -270,6 +270,8 @@ enum blockmodes { struct ctl_conn { TAILQ_ENTRY(ctl_conn) entry; + u_int8_t flags; +#define CTL_CONN_NOTIFY 0x01 struct imsgbuf ibuf; }; @@ -281,6 +283,7 @@ int control_listen(void); void control_accept(int, short, void *); void control_dispatch_imsg(int, short, void *); int control_imsg_relay(struct imsg *); +void control_imsg_forward(struct imsg *); void control_cleanup(void); void session_socket_blockmode(int, enum blockmodes); |