diff options
-rw-r--r-- | usr.sbin/relayd/ca.c | 3 | ||||
-rw-r--r-- | usr.sbin/relayd/control.c | 49 | ||||
-rw-r--r-- | usr.sbin/relayd/pfe.c | 10 | ||||
-rw-r--r-- | usr.sbin/relayd/proc.c | 33 | ||||
-rw-r--r-- | usr.sbin/relayd/relay.c | 5 | ||||
-rw-r--r-- | usr.sbin/relayd/relayd.c | 3 | ||||
-rw-r--r-- | usr.sbin/relayd/relayd.h | 6 |
7 files changed, 52 insertions, 57 deletions
diff --git a/usr.sbin/relayd/ca.c b/usr.sbin/relayd/ca.c index cf98615317c..4938782878d 100644 --- a/usr.sbin/relayd/ca.c +++ b/usr.sbin/relayd/ca.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ca.c,v 1.18 2016/09/02 11:51:49 reyk Exp $ */ +/* $OpenBSD: ca.c,v 1.19 2016/09/02 12:12:51 reyk Exp $ */ /* * Copyright (c) 2014 Reyk Floeter <reyk@openbsd.org> @@ -80,7 +80,6 @@ ca_init(struct privsep *ps, struct privsep_proc *p, void *arg) if (config_init(ps->ps_env) == -1) fatal("failed to initialize configuration"); - proc_id = p->p_instance; env->sc_id = getpid() & 0xffff; } diff --git a/usr.sbin/relayd/control.c b/usr.sbin/relayd/control.c index 3b0a12e28a9..516c4189aba 100644 --- a/usr.sbin/relayd/control.c +++ b/usr.sbin/relayd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.52 2015/12/05 13:13:11 claudio Exp $ */ +/* $OpenBSD: control.c,v 1.53 2016/09/02 12:12:51 reyk Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -224,6 +224,7 @@ control_dispatch_imsg(int fd, short event, void *arg) int n; int verbose; struct relayd *env = cs->cs_env; + struct privsep *ps = env->sc_ps; if ((c = control_connbyfd(fd)) == NULL) { log_warn("%s: fd %d not found", __func__, fd); @@ -275,12 +276,12 @@ control_dispatch_imsg(int fd, short event, void *arg) memcpy(&id, imsg.data, sizeof(id)); if (disable_rdr(c, &id)) imsg_compose_event(&c->iev, IMSG_CTL_FAIL, - 0, 0, -1, NULL, 0); + 0, ps->ps_instance + 1, -1, NULL, 0); else { memcpy(imsg.data, &id, sizeof(id)); - control_imsg_forward(&imsg); + control_imsg_forward(ps, &imsg); imsg_compose_event(&c->iev, IMSG_CTL_OK, - 0, 0, -1, NULL, 0); + 0, ps->ps_instance + 1, -1, NULL, 0); } break; case IMSG_CTL_RDR_ENABLE: @@ -289,12 +290,12 @@ control_dispatch_imsg(int fd, short event, void *arg) memcpy(&id, imsg.data, sizeof(id)); if (enable_rdr(c, &id)) imsg_compose_event(&c->iev, IMSG_CTL_FAIL, - 0, 0, -1, NULL, 0); + 0, ps->ps_instance + 1, -1, NULL, 0); else { memcpy(imsg.data, &id, sizeof(id)); - control_imsg_forward(&imsg); + control_imsg_forward(ps, &imsg); imsg_compose_event(&c->iev, IMSG_CTL_OK, - 0, 0, -1, NULL, 0); + 0, ps->ps_instance + 1, -1, NULL, 0); } break; case IMSG_CTL_TABLE_DISABLE: @@ -303,12 +304,12 @@ control_dispatch_imsg(int fd, short event, void *arg) memcpy(&id, imsg.data, sizeof(id)); if (disable_table(c, &id)) imsg_compose_event(&c->iev, IMSG_CTL_FAIL, - 0, 0, -1, NULL, 0); + 0, ps->ps_instance + 1, -1, NULL, 0); else { memcpy(imsg.data, &id, sizeof(id)); - control_imsg_forward(&imsg); + control_imsg_forward(ps, &imsg); imsg_compose_event(&c->iev, IMSG_CTL_OK, - 0, 0, -1, NULL, 0); + 0, ps->ps_instance + 1, -1, NULL, 0); } break; case IMSG_CTL_TABLE_ENABLE: @@ -317,12 +318,12 @@ control_dispatch_imsg(int fd, short event, void *arg) memcpy(&id, imsg.data, sizeof(id)); if (enable_table(c, &id)) imsg_compose_event(&c->iev, IMSG_CTL_FAIL, - 0, 0, -1, NULL, 0); + 0, ps->ps_instance + 1, -1, NULL, 0); else { memcpy(imsg.data, &id, sizeof(id)); - control_imsg_forward(&imsg); + control_imsg_forward(ps, &imsg); imsg_compose_event(&c->iev, IMSG_CTL_OK, - 0, 0, -1, NULL, 0); + 0, ps->ps_instance + 1, -1, NULL, 0); } break; case IMSG_CTL_HOST_DISABLE: @@ -331,12 +332,12 @@ control_dispatch_imsg(int fd, short event, void *arg) memcpy(&id, imsg.data, sizeof(id)); if (disable_host(c, &id, NULL)) imsg_compose_event(&c->iev, IMSG_CTL_FAIL, - 0, 0, -1, NULL, 0); + 0, ps->ps_instance + 1, -1, NULL, 0); else { memcpy(imsg.data, &id, sizeof(id)); - control_imsg_forward(&imsg); + control_imsg_forward(ps, &imsg); imsg_compose_event(&c->iev, IMSG_CTL_OK, - 0, 0, -1, NULL, 0); + 0, ps->ps_instance + 1, -1, NULL, 0); } break; case IMSG_CTL_HOST_ENABLE: @@ -345,12 +346,12 @@ control_dispatch_imsg(int fd, short event, void *arg) memcpy(&id, imsg.data, sizeof(id)); if (enable_host(c, &id, NULL)) imsg_compose_event(&c->iev, IMSG_CTL_FAIL, - 0, 0, -1, NULL, 0); + 0, ps->ps_instance + 1, -1, NULL, 0); else { memcpy(imsg.data, &id, sizeof(id)); - control_imsg_forward(&imsg); + control_imsg_forward(ps, &imsg); imsg_compose_event(&c->iev, IMSG_CTL_OK, - 0, 0, -1, NULL, 0); + 0, ps->ps_instance + 1, -1, NULL, 0); } break; case IMSG_CTL_SHUTDOWN: @@ -360,7 +361,7 @@ control_dispatch_imsg(int fd, short event, void *arg) case IMSG_CTL_POLL: proc_compose(env->sc_ps, PROC_HCE, IMSG_CTL_POLL, NULL, 0); imsg_compose_event(&c->iev, IMSG_CTL_OK, - 0, 0, -1, NULL, 0); + 0, ps->ps_instance + 1, -1, NULL, 0); break; case IMSG_CTL_NOTIFY: if (c->flags & CTL_CONN_NOTIFY) { @@ -368,7 +369,7 @@ control_dispatch_imsg(int fd, short event, void *arg) "client requested notify more than once", __func__); imsg_compose_event(&c->iev, IMSG_CTL_FAIL, - 0, 0, -1, NULL, 0); + 0, ps->ps_instance + 1, -1, NULL, 0); break; } c->flags |= CTL_CONN_NOTIFY; @@ -383,7 +384,7 @@ control_dispatch_imsg(int fd, short event, void *arg) proc_forward_imsg(env->sc_ps, &imsg, PROC_RELAY, -1); memcpy(imsg.data, &verbose, sizeof(verbose)); - control_imsg_forward(&imsg); + control_imsg_forward(ps, &imsg); log_verbose(verbose); break; default: @@ -398,13 +399,13 @@ control_dispatch_imsg(int fd, short event, void *arg) } void -control_imsg_forward(struct imsg *imsg) +control_imsg_forward(struct privsep *ps, struct imsg *imsg) { struct ctl_conn *c; TAILQ_FOREACH(c, &ctl_conns, entry) if (c->flags & CTL_CONN_NOTIFY) imsg_compose_event(&c->iev, imsg->hdr.type, - 0, imsg->hdr.pid, -1, imsg->data, + 0, ps->ps_instance + 1, -1, imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE); } diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c index 2ed98b81ed5..265b3cc12dd 100644 --- a/usr.sbin/relayd/pfe.c +++ b/usr.sbin/relayd/pfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfe.c,v 1.84 2016/09/02 11:51:49 reyk Exp $ */ +/* $OpenBSD: pfe.c,v 1.85 2016/09/02 12:12:51 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -103,7 +103,7 @@ pfe_dispatch_hce(int fd, struct privsep_proc *p, struct imsg *imsg) struct table *table; struct ctl_status st; - control_imsg_forward(imsg); + control_imsg_forward(p->p_ps, imsg); switch (imsg->hdr.type) { case IMSG_HOST_STATUS: @@ -687,7 +687,7 @@ pfe_sync(void) imsg.hdr.len = sizeof(id) + IMSG_HEADER_SIZE; imsg.data = &id; sync_table(env, rdr, active); - control_imsg_forward(&imsg); + control_imsg_forward(env->sc_ps, &imsg); } if (rdr->conf.flags & F_DOWN) { @@ -700,7 +700,7 @@ pfe_sync(void) imsg.hdr.len = sizeof(id) + IMSG_HEADER_SIZE; imsg.data = &id; sync_ruleset(env, rdr, 0); - control_imsg_forward(&imsg); + control_imsg_forward(env->sc_ps, &imsg); } } else if (!(rdr->conf.flags & F_ACTIVE_RULESET)) { log_debug("%s: enabling ruleset", __func__); @@ -710,7 +710,7 @@ pfe_sync(void) imsg.hdr.len = sizeof(id) + IMSG_HEADER_SIZE; imsg.data = &id; sync_ruleset(env, rdr, 1); - control_imsg_forward(&imsg); + control_imsg_forward(env->sc_ps, &imsg); } } diff --git a/usr.sbin/relayd/proc.c b/usr.sbin/relayd/proc.c index 02f4bd3444e..b5c2671b323 100644 --- a/usr.sbin/relayd/proc.c +++ b/usr.sbin/relayd/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.28 2016/09/02 11:51:49 reyk Exp $ */ +/* $OpenBSD: proc.c,v 1.29 2016/09/02 12:12:51 reyk Exp $ */ /* * Copyright (c) 2010 - 2014 Reyk Floeter <reyk@openbsd.org> @@ -61,6 +61,12 @@ proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc) unsigned int i, j, src, dst; struct privsep_pipes *pp; + for (src = 0; src < PROC_MAX; src++) { + /* Default to 1 process instance */ + if (ps->ps_instances[src] < 1) + ps->ps_instances[src] = 1; + } + /* * Allocate pipes for all process instances (incl. parent) * @@ -76,22 +82,22 @@ proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc) */ for (src = 0; src < PROC_MAX; src++) { /* Allocate destination array for each process */ - if ((ps->ps_pipes[src] = calloc(ps->ps_ninstances, + if ((ps->ps_pipes[src] = calloc(ps->ps_instances[src], sizeof(struct privsep_pipes))) == NULL) fatal("proc_init: calloc"); - for (i = 0; i < ps->ps_ninstances; i++) { + for (i = 0; i < ps->ps_instances[src]; i++) { pp = &ps->ps_pipes[src][i]; for (dst = 0; dst < PROC_MAX; dst++) { /* Allocate maximum fd integers */ if ((pp->pp_pipes[dst] = - calloc(ps->ps_ninstances, + calloc(ps->ps_instances[dst], sizeof(int))) == NULL) fatal("proc_init: calloc"); /* Mark fd as unused */ - for (j = 0; j < ps->ps_ninstances; j++) + for (j = 0; j < ps->ps_instances[dst]; j++) pp->pp_pipes[dst][j] = -1; } } @@ -105,12 +111,8 @@ proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc) ps->ps_title[PROC_PARENT] = "parent"; ps->ps_pp = &ps->ps_pipes[privsep_process][0]; - for (i = 0; i < nproc; i++) { - /* Default to 1 process instance */ - if (ps->ps_instances[procs[i].p_id] < 1) - ps->ps_instances[procs[i].p_id] = 1; + for (i = 0; i < nproc; i++) ps->ps_title[procs[i].p_id] = procs[i].p_title; - } proc_open(ps, NULL, procs, nproc); @@ -260,7 +262,6 @@ proc_listen(struct privsep *ps, struct privsep_proc *procs, size_t nproc) ps->ps_ievs[dst][n].events = EV_READ; ps->ps_ievs[dst][n].proc = &procs[i]; ps->ps_ievs[dst][n].data = &ps->ps_ievs[dst][n]; - procs[i].p_instance = n; event_set(&(ps->ps_ievs[dst][n].ev), ps->ps_ievs[dst][n].ibuf.fd, @@ -404,7 +405,7 @@ proc_run(struct privsep *ps, struct privsep_proc *p, /* Fork child handlers */ for (n = 1; n < ps->ps_instances[p->p_id]; n++) { if (fork() == 0) { - ps->ps_instance = p->p_instance = n; + ps->ps_instance = n; break; } } @@ -489,7 +490,7 @@ proc_dispatch(int fd, short event, void *arg) #if DEBUG > 1 log_debug("%s: %s %d got imsg %d peerid %d from %s %d", __func__, title, ps->ps_instance + 1, - imsg.hdr.type, imsg.hdr.peerid, p->p_title, p->p_instance); + imsg.hdr.type, imsg.hdr.peerid, p->p_title, imsg.hdr.pid); #endif /* @@ -515,7 +516,7 @@ proc_dispatch(int fd, short event, void *arg) "from %s %d", __func__, title, ps->ps_instance + 1, imsg.hdr.type, imsg.hdr.peerid, - p->p_title, p->p_instance); + p->p_title, imsg.hdr.pid); fatalx(__func__); } imsg_free(&imsg); @@ -598,7 +599,7 @@ proc_compose_imsg(struct privsep *ps, enum privsep_procid id, int n, proc_range(ps, id, &n, &m); for (; n < m; n++) { if (imsg_compose_event(&ps->ps_ievs[id][n], - type, peerid, 0, fd, data, datalen) == -1) + type, peerid, ps->ps_instance + 1, fd, data, datalen) == -1) return (-1); } @@ -621,7 +622,7 @@ proc_composev_imsg(struct privsep *ps, enum privsep_procid id, int n, proc_range(ps, id, &n, &m); for (; n < m; n++) if (imsg_composev_event(&ps->ps_ievs[id][n], - type, peerid, 0, fd, iov, iovcnt) == -1) + type, peerid, ps->ps_instance + 1, fd, iov, iovcnt) == -1) return (-1); return (0); diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c index 1c809ebec62..359034595bc 100644 --- a/usr.sbin/relayd/relay.c +++ b/usr.sbin/relayd/relay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay.c,v 1.208 2016/09/02 11:51:49 reyk Exp $ */ +/* $OpenBSD: relay.c,v 1.209 2016/09/02 12:12:51 reyk Exp $ */ /* * Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org> @@ -325,9 +325,6 @@ relay_init(struct privsep *ps, struct privsep_proc *p, void *arg) if (config_init(ps->ps_env) == -1) fatal("failed to initialize configuration"); - /* Set to current prefork id */ - proc_id = p->p_instance; - /* We use a custom shutdown callback */ p->p_shutdown = relay_shutdown; diff --git a/usr.sbin/relayd/relayd.c b/usr.sbin/relayd/relayd.c index 4d8fbb292f2..8a8ca2852c5 100644 --- a/usr.sbin/relayd/relayd.c +++ b/usr.sbin/relayd/relayd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relayd.c,v 1.157 2016/09/02 11:51:50 reyk Exp $ */ +/* $OpenBSD: relayd.c,v 1.158 2016/09/02 12:12:51 reyk Exp $ */ /* * Copyright (c) 2007 - 2016 Reyk Floeter <reyk@openbsd.org> @@ -199,7 +199,6 @@ main(int argc, char *argv[]) ps->ps_instances[PROC_RELAY] = env->sc_prefork_relay; ps->ps_instances[PROC_CA] = env->sc_prefork_relay; - ps->ps_ninstances = env->sc_prefork_relay; proc_init(ps, procs, nitems(procs)); log_procinit("parent"); diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h index e713ec0e55e..0d5c07ac9fb 100644 --- a/usr.sbin/relayd/relayd.h +++ b/usr.sbin/relayd/relayd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: relayd.h,v 1.228 2016/09/02 11:51:50 reyk Exp $ */ +/* $OpenBSD: relayd.h,v 1.229 2016/09/02 12:12:51 reyk Exp $ */ /* * Copyright (c) 2006 - 2016 Reyk Floeter <reyk@openbsd.org> @@ -1003,7 +1003,6 @@ struct privsep { u_int8_t ps_what[PROC_MAX]; u_int ps_instances[PROC_MAX]; - u_int ps_ninstances; u_int ps_instance; struct control_sock ps_csock; @@ -1030,7 +1029,6 @@ struct privsep_proc { void (*p_init)(struct privsep *, struct privsep_proc *); void (*p_shutdown)(void); - u_int p_instance; const char *p_chroot; struct privsep *p_ps; struct relayd *p_env; @@ -1105,7 +1103,7 @@ int control_init(struct privsep *, struct control_sock *); int control_listen(struct control_sock *); void control_cleanup(struct control_sock *); void control_dispatch_imsg(int, short, void *); -void control_imsg_forward(struct imsg *); +void control_imsg_forward(struct privsep *ps, struct imsg *); struct ctl_conn * control_connbyfd(int); |