diff options
Diffstat (limited to 'usr.sbin/relayd/pfe.c')
-rw-r--r-- | usr.sbin/relayd/pfe.c | 687 |
1 files changed, 227 insertions, 460 deletions
diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c index a9d376d42e1..ba3a6260390 100644 --- a/usr.sbin/relayd/pfe.c +++ b/usr.sbin/relayd/pfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfe.c,v 1.67 2011/05/05 12:01:43 reyk Exp $ */ +/* $OpenBSD: pfe.c,v 1.68 2011/05/09 12:08:47 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -35,180 +35,56 @@ #include "relayd.h" -void pfe_sig_handler(int sig, short, void *); -void pfe_shutdown(void); -void pfe_setup_events(void); -void pfe_disable_events(void); -void pfe_dispatch_imsg(int, short, void *); -void pfe_dispatch_parent(int, short, void *); -void pfe_dispatch_relay(int, short, void *); -void pfe_sync(void); -void pfe_statistics(int, short, void *); +void pfe_init(struct privsep *, struct privsep_proc *p, void *); +void pfe_shutdown(void); +void pfe_setup_events(void); +void pfe_disable_events(void); +void pfe_sync(void); +void pfe_statistics(int, short, void *); -static struct relayd *env = NULL; +int pfe_dispatch_parent(int, struct privsep_proc *, struct imsg *); +int pfe_dispatch_hce(int, struct privsep_proc *, struct imsg *); +int pfe_dispatch_relay(int, struct privsep_proc *, struct imsg *); -struct imsgev *iev_main; -struct imsgev *iev_hce; -struct imsgev *iev_relay; +static struct relayd *env = NULL; -void -pfe_sig_handler(int sig, short event, void *arg) -{ - switch (sig) { - case SIGINT: - case SIGTERM: - pfe_shutdown(); - break; - case SIGCHLD: - case SIGHUP: - case SIGPIPE: - /* ignore */ - break; - default: - fatalx("pfe_sig_handler: unexpected signal"); - } -} +static struct privsep_proc procs[] = { + { "parent", PROC_PARENT, pfe_dispatch_parent }, + { "relay", PROC_RELAY, pfe_dispatch_relay }, + { "hce", PROC_HCE, pfe_dispatch_hce } +}; pid_t -pfe(struct relayd *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2], - int pipe_parent2relay[RELAY_MAXPROC][2], int pipe_pfe2hce[2], - int pipe_pfe2relay[RELAY_MAXPROC][2]) +pfe(struct privsep *ps, struct privsep_proc *p) { - pid_t pid; - struct passwd *pw; - int i; - size_t size; - - switch (pid = fork()) { - case -1: - fatal("pfe: cannot fork"); - case 0: - break; - default: - return (pid); - } - - env = x_env; - purge_config(env, PURGE_PROTOS); - - if (control_init() == -1) - fatalx("pfe: control socket setup failed"); + env = ps->ps_env; init_filter(env); init_tables(env); - if ((pw = getpwnam(RELAYD_USER)) == NULL) - fatal("pfe: getpwnam"); - -#ifndef DEBUG - if (chroot(pw->pw_dir) == -1) - fatal("pfe: chroot"); - if (chdir("/") == -1) - fatal("pfe: chdir(\"/\")"); -#else -#warning disabling privilege revocation and chroot in DEBUG mode -#endif - - setproctitle("pf update engine"); - relayd_process = PROC_PFE; - -#ifndef DEBUG - if (setgroups(1, &pw->pw_gid) || - setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || - setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) - fatal("pfe: cannot drop privileges"); -#endif - - event_init(); - - signal_set(&env->sc_evsigint, SIGINT, pfe_sig_handler, env); - signal_set(&env->sc_evsigterm, SIGTERM, pfe_sig_handler, env); - signal_set(&env->sc_evsigchld, SIGCHLD, pfe_sig_handler, env); - signal_set(&env->sc_evsighup, SIGHUP, pfe_sig_handler, env); - signal_set(&env->sc_evsigpipe, SIGPIPE, pfe_sig_handler, env); - - signal_add(&env->sc_evsigint, NULL); - signal_add(&env->sc_evsigterm, NULL); - signal_add(&env->sc_evsigchld, NULL); - signal_add(&env->sc_evsighup, NULL); - signal_add(&env->sc_evsigpipe, NULL); - - /* setup pipes */ - close(pipe_pfe2hce[0]); - close(pipe_parent2pfe[0]); - close(pipe_parent2hce[0]); - close(pipe_parent2hce[1]); - for (i = 0; i < env->sc_prefork_relay; i++) { - close(pipe_parent2relay[i][0]); - close(pipe_parent2relay[i][1]); - close(pipe_pfe2relay[i][0]); - } - - size = sizeof(struct imsgev); - if ((iev_hce = calloc(1, size)) == NULL || - (iev_relay = calloc(env->sc_prefork_relay, size)) == NULL || - (iev_main = calloc(1, size)) == NULL) - fatal("pfe"); - - imsg_init(&iev_hce->ibuf, pipe_pfe2hce[1]); - iev_hce->handler = pfe_dispatch_imsg; - imsg_init(&iev_main->ibuf, pipe_parent2pfe[1]); - iev_main->handler = pfe_dispatch_parent; - for (i = 0; i < env->sc_prefork_relay; i++) { - imsg_init(&iev_relay[i].ibuf, pipe_pfe2relay[i][1]); - iev_relay[i].handler = pfe_dispatch_relay; - } - - iev_main->events = EV_READ; - event_set(&iev_main->ev, iev_main->ibuf.fd, iev_main->events, - iev_main->handler, iev_main); - event_add(&iev_main->ev, NULL); + return (proc_run(ps, p, procs, nitems(procs), pfe_init, NULL)); +} +void +pfe_init(struct privsep *ps, struct privsep_proc *p, void *arg) +{ + p->p_shutdown = pfe_shutdown; + purge_config(env, PURGE_PROTOS); pfe_setup_events(); - - TAILQ_INIT(&ctl_conns); - - if (control_listen(env, iev_main, iev_hce) == -1) - fatalx("pfe: control socket listen failed"); - - /* Initial sync */ pfe_sync(); - - event_dispatch(); - pfe_shutdown(); - - return (0); } void pfe_shutdown(void) { flush_rulesets(env); - log_info("pf update engine exiting"); - _exit(0); } void pfe_setup_events(void) { - int i; - struct imsgev *iev; struct timeval tv; - iev_hce->events = EV_READ; - event_set(&iev_hce->ev, iev_hce->ibuf.fd, iev_hce->events, - iev_hce->handler, iev_hce); - event_add(&iev_hce->ev, NULL); - - for (i = 0; i < env->sc_prefork_relay; i++) { - iev = &iev_relay[i]; - - iev->events = EV_READ; - event_set(&iev->ev, iev->ibuf.fd, iev->events, - iev->handler, iev); - event_add(&iev->ev, NULL); - } - /* Schedule statistics timer */ evtimer_set(&env->sc_statev, pfe_statistics, NULL); bcopy(&env->sc_statinterval, &tv, sizeof(tv)); @@ -218,318 +94,209 @@ pfe_setup_events(void) void pfe_disable_events(void) { - int i; - - event_del(&iev_hce->ev); - - for (i = 0; i < env->sc_prefork_relay; i++) - event_del(&iev_relay[i].ev); - event_del(&env->sc_statev); } -void -pfe_dispatch_imsg(int fd, short event, void *ptr) +int +pfe_dispatch_hce(int fd, struct privsep_proc *p, struct imsg *imsg) { - struct imsgev *iev; - struct imsgbuf *ibuf; - struct imsg imsg; - ssize_t n; - struct host *host; struct table *table; struct ctl_status st; - iev = ptr; - ibuf = &iev->ibuf; - - if (event & EV_READ) { - if ((n = imsg_read(ibuf)) == -1) - fatal("pfe_dispatch_imsg: imsg_read_error"); - if (n == 0) { - /* this pipe is dead, so remove the event handler */ - event_del(&iev->ev); - event_loopexit(NULL); - return; - } - } + control_imsg_forward(imsg); - if (event & EV_WRITE) { - if (msgbuf_write(&ibuf->w) == -1) - fatal("pfe_dispatch_imsg: msgbuf_write"); - } + switch (imsg->hdr.type) { + case IMSG_HOST_STATUS: + IMSG_SIZE_CHECK(imsg, &st); + memcpy(&st, imsg->data, sizeof(st)); + if ((host = host_find(env, st.id)) == NULL) + fatalx("pfe_dispatch_imsg: invalid host id"); + host->he = st.he; + if (host->flags & F_DISABLE) + break; + host->retry_cnt = st.retry_cnt; + if (st.up != HOST_UNKNOWN) { + host->check_cnt++; + if (st.up == HOST_UP) + host->up_cnt++; + } + if (host->check_cnt != st.check_cnt) { + log_debug("%s: host %d => %d", __func__, + host->conf.id, host->up); + fatalx("pfe_dispatch_imsg: desynchronized"); + } - for (;;) { - if ((n = imsg_get(ibuf, &imsg)) == -1) - fatal("pfe_dispatch_imsg: imsg_read error"); - if (n == 0) + if (host->up == st.up) break; - control_imsg_forward(&imsg); - switch (imsg.hdr.type) { - case IMSG_HOST_STATUS: - if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(st)) - fatalx("pfe_dispatch_imsg: invalid request"); - memcpy(&st, imsg.data, sizeof(st)); - if ((host = host_find(env, st.id)) == NULL) - fatalx("pfe_dispatch_imsg: invalid host id"); - host->he = st.he; - if (host->flags & F_DISABLE) - break; - host->retry_cnt = st.retry_cnt; - if (st.up != HOST_UNKNOWN) { - host->check_cnt++; - if (st.up == HOST_UP) - host->up_cnt++; - } - if (host->check_cnt != st.check_cnt) { - log_debug("%s: host %d => %d", __func__, - host->conf.id, host->up); - fatalx("pfe_dispatch_imsg: desynchronized"); - } + /* Forward to relay engine(s) */ + proc_compose_imsg(env->sc_ps, PROC_RELAY, -1, + IMSG_HOST_STATUS, -1, &st, sizeof(st)); - if (host->up == st.up) - break; - - /* Forward to relay engine(s) */ - for (n = 0; n < env->sc_prefork_relay; n++) - imsg_compose_event(&iev_relay[n], - IMSG_HOST_STATUS, 0, 0, -1, &st, - sizeof(st)); - - if ((table = table_find(env, host->conf.tableid)) - == NULL) - fatalx("pfe_dispatch_imsg: invalid table id"); - - log_debug("%s: state %d for host %u %s", __func__, - st.up, host->conf.id, host->conf.name); - - /* - * Do not change the table state when the host - * state switches between UNKNOWN and DOWN. - */ - if (HOST_ISUP(st.up)) { - table->conf.flags |= F_CHANGED; - table->up++; - host->flags |= F_ADD; - host->flags &= ~(F_DEL); - } else if (HOST_ISUP(host->up)) { - table->up--; - table->conf.flags |= F_CHANGED; - host->flags |= F_DEL; - host->flags &= ~(F_ADD); - } + if ((table = table_find(env, host->conf.tableid)) + == NULL) + fatalx("pfe_dispatch_imsg: invalid table id"); - host->up = st.up; - break; - case IMSG_SYNC: - pfe_sync(); - break; - default: - log_debug("%s: unexpected imsg %d", __func__, - imsg.hdr.type); - break; + log_debug("%s: state %d for host %u %s", __func__, + st.up, host->conf.id, host->conf.name); + + /* + * Do not change the table state when the host + * state switches between UNKNOWN and DOWN. + */ + if (HOST_ISUP(st.up)) { + table->conf.flags |= F_CHANGED; + table->up++; + host->flags |= F_ADD; + host->flags &= ~(F_DEL); + } else if (HOST_ISUP(host->up)) { + table->up--; + table->conf.flags |= F_CHANGED; + host->flags |= F_DEL; + host->flags &= ~(F_ADD); } - imsg_free(&imsg); + + host->up = st.up; + break; + case IMSG_SYNC: + pfe_sync(); + break; + default: + return (-1); } - imsg_event_add(iev); + + return (0); } -void -pfe_dispatch_parent(int fd, short event, void * ptr) +int +pfe_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg) { - struct imsgev *iev; - struct imsgbuf *ibuf; - struct imsg imsg; - ssize_t n; - static struct rdr *rdr = NULL; static struct table *table = NULL; struct host *host, *parent; struct address *virt; - iev = ptr; - ibuf = &iev->ibuf; - - if (event & EV_READ) { - if ((n = imsg_read(ibuf)) == -1) - fatal("imsg_read error"); - if (n == 0) { - /* this pipe is dead, so remove the event handler */ - event_del(&iev->ev); - event_loopexit(NULL); - return; - } - } + switch (imsg->hdr.type) { + case IMSG_RECONF: + IMSG_SIZE_CHECK(imsg, env); + log_debug("%s: reloading configuration", __func__); - if (event & EV_WRITE) { - if (msgbuf_write(&ibuf->w) == -1) - fatal("msgbuf_write"); - } + pfe_disable_events(); + purge_config(env, PURGE_RDRS|PURGE_TABLES); + merge_config(env, (struct relayd *)imsg->data); - for (;;) { - if ((n = imsg_get(ibuf, &imsg)) == -1) - fatal("pfe_dispatch_parent: imsg_read error"); - if (n == 0) - break; + /* + * no relays when reconfiguring yet. + */ + env->sc_relays = NULL; + env->sc_protos = NULL; - switch (imsg.hdr.type) { - case IMSG_RECONF: - log_debug("%s: reloading configuration", __func__); - if (imsg.hdr.len != - sizeof(struct relayd) + IMSG_HEADER_SIZE) - fatalx("corrupted reload data"); - pfe_disable_events(); - purge_config(env, PURGE_RDRS|PURGE_TABLES); - merge_config(env, (struct relayd *)imsg.data); - /* - * no relays when reconfiguring yet. - */ - env->sc_relays = NULL; - env->sc_protos = NULL; - - env->sc_tables = calloc(1, sizeof(*env->sc_tables)); - env->sc_rdrs = calloc(1, sizeof(*env->sc_rdrs)); - if (env->sc_tables == NULL || env->sc_rdrs == NULL) - fatal(NULL); - - TAILQ_INIT(env->sc_tables); - TAILQ_INIT(env->sc_rdrs); - break; - case IMSG_RECONF_TABLE: - if ((table = calloc(1, sizeof(*table))) == NULL) - fatal(NULL); - memcpy(&table->conf, imsg.data, sizeof(table->conf)); - TAILQ_INIT(&table->hosts); - TAILQ_INSERT_TAIL(env->sc_tables, table, entry); - break; - case IMSG_RECONF_HOST: - if ((host = calloc(1, sizeof(*host))) == NULL) - fatal(NULL); - memcpy(&host->conf, imsg.data, sizeof(host->conf)); - host->tablename = table->conf.name; - TAILQ_INSERT_TAIL(&table->hosts, host, entry); - if (host->conf.parentid) { - parent = host_find(env, host->conf.parentid); - SLIST_INSERT_HEAD(&parent->children, - host, child); - } - break; - case IMSG_RECONF_RDR: - if ((rdr = calloc(1, sizeof(*rdr))) == NULL) - fatal(NULL); - memcpy(&rdr->conf, imsg.data, - sizeof(rdr->conf)); - rdr->table = table_find(env, - rdr->conf.table_id); - if (rdr->conf.backup_id == EMPTY_TABLE) - rdr->backup = &env->sc_empty_table; - else - rdr->backup = table_find(env, - rdr->conf.backup_id); - if (rdr->table == NULL || rdr->backup == NULL) - fatal("pfe_dispatch_parent:" - " corrupted configuration"); - log_debug("%s: redirect table %s, backup %s", - __func__, - rdr->table->conf.name, - rdr->backup->conf.name); - TAILQ_INIT(&rdr->virts); - TAILQ_INSERT_TAIL(env->sc_rdrs, rdr, entry); - break; - case IMSG_RECONF_VIRT: - if ((virt = calloc(1, sizeof(*virt))) == NULL) - fatal(NULL); - memcpy(virt, imsg.data, sizeof(*virt)); - TAILQ_INSERT_TAIL(&rdr->virts, virt, entry); - break; - case IMSG_RECONF_END: - log_warnx("%s: configuration reloaded", __func__); - init_tables(env); - pfe_setup_events(); - pfe_sync(); - break; - default: - log_debug("%s: unexpected imsg %d", __func__, - imsg.hdr.type); - break; + env->sc_tables = calloc(1, sizeof(*env->sc_tables)); + env->sc_rdrs = calloc(1, sizeof(*env->sc_rdrs)); + if (env->sc_tables == NULL || env->sc_rdrs == NULL) + fatal(NULL); + + TAILQ_INIT(env->sc_tables); + TAILQ_INIT(env->sc_rdrs); + break; + case IMSG_RECONF_TABLE: + if ((table = calloc(1, sizeof(*table))) == NULL) + fatal(NULL); + memcpy(&table->conf, imsg->data, sizeof(table->conf)); + TAILQ_INIT(&table->hosts); + TAILQ_INSERT_TAIL(env->sc_tables, table, entry); + break; + case IMSG_RECONF_HOST: + if ((host = calloc(1, sizeof(*host))) == NULL) + fatal(NULL); + memcpy(&host->conf, imsg->data, sizeof(host->conf)); + host->tablename = table->conf.name; + TAILQ_INSERT_TAIL(&table->hosts, host, entry); + if (host->conf.parentid) { + parent = host_find(env, host->conf.parentid); + SLIST_INSERT_HEAD(&parent->children, + host, child); } - imsg_free(&imsg); + break; + case IMSG_RECONF_RDR: + if ((rdr = calloc(1, sizeof(*rdr))) == NULL) + fatal(NULL); + memcpy(&rdr->conf, imsg->data, + sizeof(rdr->conf)); + rdr->table = table_find(env, + rdr->conf.table_id); + if (rdr->conf.backup_id == EMPTY_TABLE) + rdr->backup = &env->sc_empty_table; + else + rdr->backup = table_find(env, + rdr->conf.backup_id); + if (rdr->table == NULL || rdr->backup == NULL) + fatal("pfe_dispatch_parent:" + " corrupted configuration"); + log_debug("%s: redirect table %s, backup %s", + __func__, + rdr->table->conf.name, + rdr->backup->conf.name); + TAILQ_INIT(&rdr->virts); + TAILQ_INSERT_TAIL(env->sc_rdrs, rdr, entry); + break; + case IMSG_RECONF_VIRT: + if ((virt = calloc(1, sizeof(*virt))) == NULL) + fatal(NULL); + memcpy(virt, imsg->data, sizeof(*virt)); + TAILQ_INSERT_TAIL(&rdr->virts, virt, entry); + break; + case IMSG_RECONF_END: + log_warnx("%s: configuration reloaded", __func__); + init_tables(env); + pfe_setup_events(); + pfe_sync(); + break; + default: + return (-1); } - imsg_event_add(iev); + + return (0); } -void -pfe_dispatch_relay(int fd, short event, void * ptr) +int +pfe_dispatch_relay(int fd, struct privsep_proc *p, struct imsg *imsg) { - struct imsgev *iev; - struct imsgbuf *ibuf; - struct imsg imsg; - ssize_t n; struct ctl_natlook cnl; struct ctl_stats crs; struct relay *rlay; - iev = ptr; - ibuf = &iev->ibuf; - - if (event & EV_READ) { - if ((n = imsg_read(ibuf)) == -1) - fatal("imsg_read error"); - if (n == 0) { - /* this pipe is dead, so remove the event handler */ - event_del(&iev->ev); - event_loopexit(NULL); - return; - } - } - - if (event & EV_WRITE) { - if (msgbuf_write(&ibuf->w) == -1) - fatal("msgbuf_write"); + switch (imsg->hdr.type) { + case IMSG_NATLOOK: + IMSG_SIZE_CHECK(imsg, &cnl); + bcopy(imsg->data, &cnl, sizeof(cnl)); + if (cnl.proc > env->sc_prefork_relay) + fatalx("pfe_dispatch_relay: " + "invalid relay proc"); + if (natlook(env, &cnl) != 0) + cnl.in = -1; + proc_compose_imsg(env->sc_ps, PROC_RELAY, cnl.proc, + IMSG_NATLOOK, -1, &cnl, sizeof(cnl)); + break; + case IMSG_STATISTICS: + IMSG_SIZE_CHECK(imsg, &crs); + bcopy(imsg->data, &crs, sizeof(crs)); + if (crs.proc > env->sc_prefork_relay) + fatalx("pfe_dispatch_relay: " + "invalid relay proc"); + if ((rlay = relay_find(env, crs.id)) == NULL) + fatalx("pfe_dispatch_relay: invalid relay id"); + bcopy(&crs, &rlay->rl_stats[crs.proc], sizeof(crs)); + rlay->rl_stats[crs.proc].interval = + env->sc_statinterval.tv_sec; + break; + default: + return (-1); } - for (;;) { - if ((n = imsg_get(ibuf, &imsg)) == -1) - fatal("pfe_dispatch_relay: imsg_read error"); - if (n == 0) - break; - - switch (imsg.hdr.type) { - case IMSG_NATLOOK: - if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(cnl)) - fatalx("invalid imsg header len"); - bcopy(imsg.data, &cnl, sizeof(cnl)); - if (cnl.proc > env->sc_prefork_relay) - fatalx("pfe_dispatch_relay: " - "invalid relay proc"); - if (natlook(env, &cnl) != 0) - cnl.in = -1; - imsg_compose_event(&iev_relay[cnl.proc], IMSG_NATLOOK, - 0, 0, -1, &cnl, sizeof(cnl)); - break; - case IMSG_STATISTICS: - if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(crs)) - fatalx("invalid imsg header len"); - bcopy(imsg.data, &crs, sizeof(crs)); - if (crs.proc > env->sc_prefork_relay) - fatalx("pfe_dispatch_relay: " - "invalid relay proc"); - if ((rlay = relay_find(env, crs.id)) == NULL) - fatalx("pfe_dispatch_relay: invalid relay id"); - bcopy(&crs, &rlay->rl_stats[crs.proc], sizeof(crs)); - rlay->rl_stats[crs.proc].interval = - env->sc_statinterval.tv_sec; - break; - default: - log_debug("%s: unexpected imsg %d", __func__, - imsg.hdr.type); - break; - } - imsg_free(&imsg); - } - imsg_event_add(iev); + return (0); } void @@ -624,19 +391,21 @@ end: void show_sessions(struct ctl_conn *c) { - int n, proc, done; - struct imsg imsg; + int n, proc, done; + struct imsg imsg; + struct imsgbuf *ibuf; + struct rsession con; for (proc = 0; proc < env->sc_prefork_relay; proc++) { + ibuf = proc_ibuf(env->sc_ps, PROC_RELAY, proc); + /* * Request all the running sessions from the process */ - imsg_compose_event(&iev_relay[proc], - IMSG_CTL_SESSION, 0, 0, -1, NULL, 0); - while (iev_relay[proc].ibuf.w.queued) - if (msgbuf_write(&iev_relay[proc].ibuf.w) < 0) - fatalx("write error"); - + proc_compose_imsg(env->sc_ps, PROC_RELAY, proc, + IMSG_CTL_SESSION, -1, NULL, 0); + proc_flush_imsg(env->sc_ps, PROC_RELAY, proc); + /* * Wait for the reply and forward the messages to the * control connection. @@ -644,20 +413,23 @@ show_sessions(struct ctl_conn *c) done = 0; while (!done) { do { - if ((n = imsg_read(&iev_relay[proc].ibuf)) == -1) + if ((n = imsg_read(ibuf)) == -1) fatalx("imsg_read error"); } while (n == -2); /* handle non-blocking I/O */ while (!done) { - if ((n = imsg_get(&iev_relay[proc].ibuf, - &imsg)) == -1) + if ((n = imsg_get(ibuf, &imsg)) == -1) fatalx("imsg_get error"); if (n == 0) break; + switch (imsg.hdr.type) { case IMSG_CTL_SESSION: + IMSG_SIZE_CHECK(&imsg, &con); + memcpy(&con, imsg.data, sizeof(con)); + imsg_compose_event(&c->iev, - IMSG_CTL_SESSION, proc, 0, -1, - imsg.data, sizeof(struct rsession)); + IMSG_CTL_SESSION, 0, 0, -1, + &con, sizeof(con)); break; case IMSG_CTL_END: done = 1; @@ -740,7 +512,6 @@ disable_table(struct ctl_conn *c, struct ctl_id *id) { struct table *table; struct host *host; - int n; if (id->id == EMPTY_ID) table = table_findbyname(env, id->name); @@ -758,13 +529,13 @@ disable_table(struct ctl_conn *c, struct ctl_id *id) table->up = 0; TAILQ_FOREACH(host, &table->hosts, entry) host->up = HOST_UNKNOWN; - imsg_compose_event(iev_hce, IMSG_TABLE_DISABLE, 0, 0, -1, + proc_compose_imsg(env->sc_ps, PROC_HCE, -1, IMSG_TABLE_DISABLE, -1, &table->conf.id, sizeof(table->conf.id)); + /* Forward to relay engine(s) */ - for (n = 0; n < env->sc_prefork_relay; n++) - imsg_compose_event(&iev_relay[n], - IMSG_TABLE_DISABLE, 0, 0, -1, - &table->conf.id, sizeof(table->conf.id)); + proc_compose_imsg(env->sc_ps, PROC_RELAY, -1, IMSG_TABLE_DISABLE, -1, + &table->conf.id, sizeof(table->conf.id)); + log_debug("%s: table %d", __func__, table->conf.id); pfe_sync(); return (0); @@ -775,7 +546,6 @@ enable_table(struct ctl_conn *c, struct ctl_id *id) { struct table *table; struct host *host; - int n; if (id->id == EMPTY_ID) table = table_findbyname(env, id->name); @@ -795,13 +565,13 @@ enable_table(struct ctl_conn *c, struct ctl_id *id) table->up = 0; TAILQ_FOREACH(host, &table->hosts, entry) host->up = HOST_UNKNOWN; - imsg_compose_event(iev_hce, IMSG_TABLE_ENABLE, 0, 0, -1, + proc_compose_imsg(env->sc_ps, PROC_HCE, -1, IMSG_TABLE_ENABLE, -1, &table->conf.id, sizeof(table->conf.id)); + /* Forward to relay engine(s) */ - for (n = 0; n < env->sc_prefork_relay; n++) - imsg_compose_event(&iev_relay[n], - IMSG_TABLE_ENABLE, 0, 0, -1, - &table->conf.id, sizeof(table->conf.id)); + proc_compose_imsg(env->sc_ps, PROC_RELAY, -1, IMSG_TABLE_ENABLE, -1, + &table->conf.id, sizeof(table->conf.id)); + log_debug("%s: table %d", __func__, table->conf.id); pfe_sync(); return (0); @@ -812,7 +582,6 @@ disable_host(struct ctl_conn *c, struct ctl_id *id, struct host *host) { struct host *h; struct table *table; - int n; if (host == NULL) { if (id->id == EMPTY_ID) @@ -841,13 +610,12 @@ disable_host(struct ctl_conn *c, struct ctl_id *id, struct host *host) host->check_cnt = 0; host->up_cnt = 0; - imsg_compose_event(iev_hce, IMSG_HOST_DISABLE, 0, 0, -1, + proc_compose_imsg(env->sc_ps, PROC_HCE, -1, IMSG_HOST_DISABLE, -1, &host->conf.id, sizeof(host->conf.id)); + /* Forward to relay engine(s) */ - for (n = 0; n < env->sc_prefork_relay; n++) - imsg_compose_event(&iev_relay[n], - IMSG_HOST_DISABLE, 0, 0, -1, - &host->conf.id, sizeof(host->conf.id)); + proc_compose_imsg(env->sc_ps, PROC_RELAY, -1, IMSG_HOST_DISABLE, -1, + &host->conf.id, sizeof(host->conf.id)); log_debug("%s: host %d", __func__, host->conf.id); if (!host->conf.parentid) { @@ -863,7 +631,6 @@ int enable_host(struct ctl_conn *c, struct ctl_id *id, struct host *host) { struct host *h; - int n; if (host == NULL) { if (id->id == EMPTY_ID) @@ -883,13 +650,13 @@ enable_host(struct ctl_conn *c, struct ctl_id *id, struct host *host) host->flags &= ~(F_DEL); host->flags &= ~(F_ADD); - imsg_compose_event(iev_hce, IMSG_HOST_ENABLE, 0, 0, -1, + proc_compose_imsg(env->sc_ps, PROC_HCE, -1, IMSG_HOST_ENABLE, -1, &host->conf.id, sizeof (host->conf.id)); + /* Forward to relay engine(s) */ - for (n = 0; n < env->sc_prefork_relay; n++) - imsg_compose_event(&iev_relay[n], - IMSG_HOST_ENABLE, 0, 0, -1, - &host->conf.id, sizeof(host->conf.id)); + proc_compose_imsg(env->sc_ps, PROC_RELAY, -1, IMSG_HOST_ENABLE, -1, + &host->conf.id, sizeof(host->conf.id)); + log_debug("%s: host %d", __func__, host->conf.id); if (!host->conf.parentid) { @@ -999,7 +766,7 @@ pfe_sync(void) demote.level, table->conf.name, table->conf.demote_group); (void)strlcpy(demote.group, table->conf.demote_group, sizeof(demote.group)); - imsg_compose_event(iev_main, IMSG_DEMOTE, 0, 0, -1, + proc_compose_imsg(env->sc_ps, PROC_PARENT, -1, IMSG_DEMOTE, -1, &demote, sizeof(demote)); } } |