summaryrefslogtreecommitdiff
path: root/usr.sbin/relayd
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/relayd')
-rw-r--r--usr.sbin/relayd/hce.c8
-rw-r--r--usr.sbin/relayd/parse.y18
-rw-r--r--usr.sbin/relayd/pfe.c11
-rw-r--r--usr.sbin/relayd/relay.c12
-rw-r--r--usr.sbin/relayd/relayd.c100
-rw-r--r--usr.sbin/relayd/relayd.h22
6 files changed, 101 insertions, 70 deletions
diff --git a/usr.sbin/relayd/hce.c b/usr.sbin/relayd/hce.c
index 490ebb10168..e8f48b11cf8 100644
--- a/usr.sbin/relayd/hce.c
+++ b/usr.sbin/relayd/hce.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hce.c,v 1.18 2007/03/07 17:40:32 reyk Exp $ */
+/* $OpenBSD: hce.c,v 1.19 2007/05/26 19:58:48 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -64,7 +64,7 @@ hce_sig_handler(int sig, short event, void *arg)
pid_t
hce(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
- int pipe_parent2relay[2], int pipe_pfe2hce[2],
+ int pipe_parent2relay[RELAY_MAXPROC][2], int pipe_pfe2hce[2],
int pipe_pfe2relay[RELAY_MAXPROC][2])
{
pid_t pid;
@@ -118,9 +118,9 @@ hce(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
close(pipe_parent2hce[0]);
close(pipe_parent2pfe[0]);
close(pipe_parent2pfe[1]);
- close(pipe_parent2relay[0]);
- close(pipe_parent2relay[1]);
for (i = 0; i < env->prefork_relay; i++) {
+ close(pipe_parent2relay[i][0]);
+ close(pipe_parent2relay[i][1]);
close(pipe_pfe2relay[i][0]);
close(pipe_pfe2relay[i][1]);
}
diff --git a/usr.sbin/relayd/parse.y b/usr.sbin/relayd/parse.y
index f49ad1b11cc..e2f4420073e 100644
--- a/usr.sbin/relayd/parse.y
+++ b/usr.sbin/relayd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.38 2007/04/12 14:45:45 reyk Exp $ */
+/* $OpenBSD: parse.y,v 1.39 2007/05/26 19:58:49 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -1358,12 +1358,13 @@ top:
return (c);
}
-int
-parse_config(struct hoststated *x_conf, const char *filename, int opts)
+struct hoststated *
+parse_config(const char *filename, int opts)
{
struct sym *sym, *next;
- conf = x_conf;
+ if ((conf = calloc(1, sizeof(*conf))) == NULL)
+ return (NULL);
TAILQ_INIT(&conf->services);
TAILQ_INIT(&conf->tables);
@@ -1396,7 +1397,8 @@ parse_config(struct hoststated *x_conf, const char *filename, int opts)
if ((fin = fopen(filename, "r")) == NULL) {
warn("%s", filename);
- return (0);
+ free(conf);
+ return (NULL);
}
infile = filename;
setservent(1);
@@ -1450,11 +1452,11 @@ parse_config(struct hoststated *x_conf, const char *filename, int opts)
}
if (errors) {
- bzero(&conf, sizeof (*conf));
- return (-1);
+ free(conf);
+ return (NULL);
}
- return (0);
+ return (conf);
}
int
diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c
index 08efe112411..7af9476e231 100644
--- a/usr.sbin/relayd/pfe.c
+++ b/usr.sbin/relayd/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.21 2007/05/09 13:05:42 pyr Exp $ */
+/* $OpenBSD: pfe.c,v 1.22 2007/05/26 19:58:49 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -63,7 +63,7 @@ pfe_sig_handler(int sig, short event, void *arg)
pid_t
pfe(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
- int pipe_parent2relay[2], int pipe_pfe2hce[2],
+ int pipe_parent2relay[RELAY_MAXPROC][2], int pipe_pfe2hce[2],
int pipe_pfe2relay[RELAY_MAXPROC][2])
{
pid_t pid;
@@ -120,10 +120,11 @@ pfe(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
close(pipe_parent2pfe[0]);
close(pipe_parent2hce[0]);
close(pipe_parent2hce[1]);
- close(pipe_parent2relay[0]);
- close(pipe_parent2relay[1]);
- for (i = 0; i < env->prefork_relay; i++)
+ for (i = 0; i < env->prefork_relay; i++) {
+ close(pipe_parent2relay[i][0]);
+ close(pipe_parent2relay[i][1]);
close(pipe_pfe2relay[i][0]);
+ }
size = sizeof(struct imsgbuf);
if ((ibuf_hce = calloc(1, size)) == NULL ||
diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c
index dd56a6972eb..1289b33a566 100644
--- a/usr.sbin/relayd/relay.c
+++ b/usr.sbin/relayd/relay.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relay.c,v 1.27 2007/05/02 09:07:28 claudio Exp $ */
+/* $OpenBSD: relay.c,v 1.28 2007/05/26 19:58:49 pyr Exp $ */
/*
* Copyright (c) 2006, 2007 Reyk Floeter <reyk@openbsd.org>
@@ -140,7 +140,7 @@ relay_sig_handler(int sig, short event, void *arg)
pid_t
relay(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
- int pipe_parent2relay[2], int pipe_pfe2hce[2],
+ int pipe_parent2relay[RELAY_MAXPROC][2], int pipe_pfe2hce[2],
int pipe_pfe2relay[RELAY_MAXPROC][2])
{
pid_t pid;
@@ -210,20 +210,23 @@ relay(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
close(pipe_parent2hce[1]);
close(pipe_parent2pfe[0]);
close(pipe_parent2pfe[1]);
- close(pipe_parent2relay[0]);
for (i = 0; i < env->prefork_relay; i++) {
if (i == proc_id)
continue;
+ close(pipe_parent2relay[i][0]);
+ close(pipe_parent2relay[i][1]);
close(pipe_pfe2relay[i][0]);
close(pipe_pfe2relay[i][1]);
}
+ close(pipe_parent2relay[proc_id][1]);
close(pipe_pfe2relay[proc_id][1]);
if ((ibuf_pfe = calloc(1, sizeof(struct imsgbuf))) == NULL ||
(ibuf_main = calloc(1, sizeof(struct imsgbuf))) == NULL)
fatal("relay");
+ imsg_init(ibuf_main, pipe_parent2relay[proc_id][0],
+ relay_dispatch_parent);
imsg_init(ibuf_pfe, pipe_pfe2relay[proc_id][0], relay_dispatch_pfe);
- imsg_init(ibuf_main, pipe_parent2relay[1], relay_dispatch_parent);
ibuf_pfe->events = EV_READ;
event_set(&ibuf_pfe->ev, ibuf_pfe->fd, ibuf_pfe->events,
@@ -1933,6 +1936,7 @@ relay_dispatch_parent(int fd, short event, void * ptr)
}
imsg_free(&imsg);
}
+ imsg_event_add(ibuf);
}
SSL_CTX *
diff --git a/usr.sbin/relayd/relayd.c b/usr.sbin/relayd/relayd.c
index d7c43004a41..49af3c53ba7 100644
--- a/usr.sbin/relayd/relayd.c
+++ b/usr.sbin/relayd/relayd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.c,v 1.21 2007/03/17 22:54:49 reyk Exp $ */
+/* $OpenBSD: relayd.c,v 1.22 2007/05/26 19:58:49 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -45,11 +45,13 @@ void main_dispatch_pfe(int, short, void *);
void main_dispatch_hce(int, short, void *);
void main_dispatch_relay(int, short, void *);
int check_child(pid_t, const char *);
+int send_all(struct hoststated *, enum imsg_type,
+ void *, u_int16_t);
int pipe_parent2pfe[2];
int pipe_parent2hce[2];
-int pipe_parent2relay[2];
int pipe_pfe2hce[2];
+int pipe_parent2relay[RELAY_MAXPROC][2];
int pipe_pfe2relay[RELAY_MAXPROC][2];
struct imsgbuf *ibuf_pfe;
@@ -109,20 +111,20 @@ usage(void)
int
main(int argc, char *argv[])
{
- int c;
- int debug;
- u_int32_t opts;
- struct hoststated env;
- const char *conffile;
- struct event ev_sigint;
- struct event ev_sigterm;
- struct event ev_sigchld;
- struct event ev_sighup;
+ int c;
+ int debug;
+ u_int32_t opts;
+ struct hoststated *env;
+ const char *conffile;
+ struct event ev_sigint;
+ struct event ev_sigterm;
+ struct event ev_sigchld;
+ struct event ev_sighup;
+ struct imsgbuf *ibuf;
opts = 0;
debug = 0;
conffile = CONF_FILE;
- bzero(&env, sizeof (env));
for (;(c = getopt(argc, argv, "dD:nf:v")) != -1;) {
switch (c) {
@@ -150,15 +152,15 @@ main(int argc, char *argv[])
log_init(debug);
- if (parse_config(&env, conffile, opts))
+ if ((env = parse_config(conffile, opts)) == NULL)
exit(1);
- if (env.opts & HOSTSTATED_OPT_NOACTION) {
+ if (env->opts & HOSTSTATED_OPT_NOACTION) {
fprintf(stderr, "configuration OK\n");
exit(0);
}
if (debug)
- env.opts |= HOSTSTATED_OPT_LOGUPDATE;
+ env->opts |= HOSTSTATED_OPT_LOGUPDATE;
if (geteuid())
errx(1, "need root privileges");
@@ -180,43 +182,43 @@ main(int argc, char *argv[])
pipe_parent2hce) == -1)
fatal("socketpair");
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC,
- pipe_parent2relay) == -1)
- fatal("socketpair");
- if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC,
pipe_pfe2hce) == -1)
fatal("socketpair");
- for (c = 0; c < env.prefork_relay; c++) {
+ for (c = 0; c < env->prefork_relay; c++) {
+ if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC,
+ pipe_parent2relay[c]) == -1)
+ fatal("socketpair");
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC,
pipe_pfe2relay[c]) == -1)
fatal("socketpair");
session_socket_blockmode(pipe_pfe2relay[c][0], BM_NONBLOCK);
session_socket_blockmode(pipe_pfe2relay[c][1], BM_NONBLOCK);
+ session_socket_blockmode(pipe_parent2relay[c][0], BM_NONBLOCK);
+ session_socket_blockmode(pipe_parent2relay[c][1], BM_NONBLOCK);
}
session_socket_blockmode(pipe_parent2pfe[0], BM_NONBLOCK);
session_socket_blockmode(pipe_parent2pfe[1], BM_NONBLOCK);
session_socket_blockmode(pipe_parent2hce[0], BM_NONBLOCK);
session_socket_blockmode(pipe_parent2hce[1], BM_NONBLOCK);
- session_socket_blockmode(pipe_parent2relay[0], BM_NONBLOCK);
- session_socket_blockmode(pipe_parent2relay[1], BM_NONBLOCK);
session_socket_blockmode(pipe_pfe2hce[0], BM_NONBLOCK);
session_socket_blockmode(pipe_pfe2hce[1], BM_NONBLOCK);
- pfe_pid = pfe(&env, pipe_parent2pfe, pipe_parent2hce,
+ pfe_pid = pfe(env, pipe_parent2pfe, pipe_parent2hce,
pipe_parent2relay, pipe_pfe2hce, pipe_pfe2relay);
- hce_pid = hce(&env, pipe_parent2pfe, pipe_parent2hce,
+ hce_pid = hce(env, pipe_parent2pfe, pipe_parent2hce,
pipe_parent2relay, pipe_pfe2hce, pipe_pfe2relay);
- relay_pid = relay(&env, pipe_parent2pfe, pipe_parent2hce,
+ relay_pid = relay(env, pipe_parent2pfe, pipe_parent2hce,
pipe_parent2relay, pipe_pfe2hce, pipe_pfe2relay);
setproctitle("parent");
event_init();
- signal_set(&ev_sigint, SIGINT, main_sig_handler, &env);
- signal_set(&ev_sigterm, SIGTERM, main_sig_handler, &env);
- signal_set(&ev_sigchld, SIGCHLD, main_sig_handler, &env);
- signal_set(&ev_sighup, SIGHUP, main_sig_handler, &env);
+ signal_set(&ev_sigint, SIGINT, main_sig_handler, env);
+ signal_set(&ev_sigterm, SIGTERM, main_sig_handler, env);
+ signal_set(&ev_sigchld, SIGCHLD, main_sig_handler, env);
+ signal_set(&ev_sighup, SIGHUP, main_sig_handler, env);
signal_add(&ev_sigint, NULL);
signal_add(&ev_sigterm, NULL);
signal_add(&ev_sigchld, NULL);
@@ -225,22 +227,30 @@ main(int argc, char *argv[])
close(pipe_parent2pfe[1]);
close(pipe_parent2hce[1]);
- close(pipe_parent2relay[1]);
close(pipe_pfe2hce[0]);
close(pipe_pfe2hce[1]);
- for (c = 0; c < env.prefork_relay; c++) {
+ for (c = 0; c < env->prefork_relay; c++) {
close(pipe_pfe2relay[c][0]);
close(pipe_pfe2relay[c][1]);
+ close(pipe_parent2relay[c][0]);
}
if ((ibuf_pfe = calloc(1, sizeof(struct imsgbuf))) == NULL ||
(ibuf_hce = calloc(1, sizeof(struct imsgbuf))) == NULL ||
- (ibuf_relay = calloc(1, sizeof(struct imsgbuf))) == NULL)
+ (ibuf_relay = calloc(env->prefork_relay,
+ sizeof(struct imsgbuf))) == NULL)
fatal(NULL);
imsg_init(ibuf_pfe, pipe_parent2pfe[0], main_dispatch_pfe);
imsg_init(ibuf_hce, pipe_parent2hce[0], main_dispatch_hce);
- imsg_init(ibuf_relay, pipe_parent2relay[0], main_dispatch_relay);
+ for (c = 0; c < env->prefork_relay; c++) {
+ ibuf = &ibuf_relay[c];
+ imsg_init(ibuf, pipe_parent2relay[c][1], main_dispatch_relay);
+ ibuf->events = EV_READ;
+ event_set(&ibuf->ev, ibuf->fd, ibuf->events,
+ ibuf->handler, ibuf);
+ event_add(&ibuf->ev, NULL);
+ }
ibuf_pfe->events = EV_READ;
event_set(&ibuf_pfe->ev, ibuf_pfe->fd, ibuf_pfe->events,
@@ -252,13 +262,8 @@ main(int argc, char *argv[])
ibuf_hce->handler, ibuf_hce);
event_add(&ibuf_hce->ev, NULL);
- ibuf_relay->events = EV_READ;
- event_set(&ibuf_relay->ev, ibuf_relay->fd, ibuf_relay->events,
- ibuf_relay->handler, ibuf_relay);
- event_add(&ibuf_relay->ev, NULL);
-
- if (env.flags & F_DEMOTE)
- carp_demote_reset(env.demote_group, 0);
+ if (env->flags & F_DEMOTE)
+ carp_demote_reset(env->demote_group, 0);
event_dispatch();
@@ -311,6 +316,22 @@ check_child(pid_t pid, const char *pname)
return (0);
}
+int
+send_all(struct hoststated *env, enum imsg_type type, void *buf, u_int16_t len)
+{
+ int i;
+
+ if (imsg_compose(ibuf_pfe, type, 0, 0, buf, len) == -1)
+ return (-1);
+ if (imsg_compose(ibuf_hce, type, 0, 0, buf, len) == -1)
+ return (-1);
+ for (i = 0; i < env->prefork_relay; i++) {
+ if (imsg_compose(&ibuf_relay[i], type, 0, 0, buf, len) == -1)
+ return (-1);
+ }
+ return (0);
+}
+
void
imsg_event_add(struct imsgbuf *ibuf)
{
@@ -451,6 +472,7 @@ main_dispatch_relay(int fd, short event, void * ptr)
}
imsg_free(&imsg);
}
+ imsg_event_add(ibuf);
}
struct host *
diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h
index 46609cae438..72866aec5bf 100644
--- a/usr.sbin/relayd/relayd.h
+++ b/usr.sbin/relayd/relayd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.h,v 1.41 2007/04/12 14:45:45 reyk Exp $ */
+/* $OpenBSD: relayd.h,v 1.42 2007/05/26 19:58:49 pyr Exp $ */
/*
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -117,7 +117,9 @@ enum imsg_type {
IMSG_SYNC,
IMSG_NATLOOK,
IMSG_DEMOTE,
- IMSG_STATISTICS
+ IMSG_STATISTICS,
+ IMSG_RECONF, /* reconfiguration notifies */
+ IMSG_RECONF_END
};
struct imsg_hdr {
@@ -567,8 +569,8 @@ void session_socket_blockmode(int, enum blockmodes);
extern struct ctl_connlist ctl_conns;
/* parse.y */
-int parse_config(struct hoststated *, const char *, int);
-int cmdline_symset(char *);
+struct hoststated *parse_config(const char *, int);
+int cmdline_symset(char *);
/* log.c */
void log_init(int);
@@ -607,8 +609,8 @@ void imsg_free(struct imsg *);
void imsg_event_add(struct imsgbuf *); /* needs to be provided externally */
/* pfe.c */
-pid_t pfe(struct hoststated *, int [2], int [2], int [2], int [2],
- int [RELAY_MAXPROC][2]);
+pid_t pfe(struct hoststated *, int [2], int [2], int [RELAY_MAXPROC][2],
+ int [2], int [RELAY_MAXPROC][2]);
void show(struct ctl_conn *);
int enable_service(struct ctl_conn *, struct ctl_id *);
int enable_table(struct ctl_conn *, struct ctl_id *);
@@ -627,13 +629,13 @@ void flush_rulesets(struct hoststated *);
int natlook(struct hoststated *, struct ctl_natlook *);
/* hce.c */
-pid_t hce(struct hoststated *, int [2], int [2], int [2], int [2],
- int [RELAY_MAXPROC][2]);
+pid_t hce(struct hoststated *, int [2], int [2], int [RELAY_MAXPROC][2],
+ int [2], int [RELAY_MAXPROC][2]);
void hce_notify_done(struct host *, const char *);
/* relay.c */
-pid_t relay(struct hoststated *, int [2], int [2], int [2], int [2],
- int [RELAY_MAXPROC][2]);
+pid_t relay(struct hoststated *, int [2], int [2], int [RELAY_MAXPROC][2],
+ int [2], int [RELAY_MAXPROC][2]);
void relay_notify_done(struct host *, const char *);
RB_PROTOTYPE(proto_tree, protonode, nodes, relay_proto_cmp);