summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/hoststated/control.c5
-rw-r--r--usr.sbin/hoststated/hoststated.h5
-rw-r--r--usr.sbin/hoststated/pfe.c54
-rw-r--r--usr.sbin/hoststated/relay.c21
-rw-r--r--usr.sbin/relayd/control.c5
-rw-r--r--usr.sbin/relayd/pfe.c54
-rw-r--r--usr.sbin/relayd/relay.c21
-rw-r--r--usr.sbin/relayd/relayd.h5
8 files changed, 162 insertions, 8 deletions
diff --git a/usr.sbin/hoststated/control.c b/usr.sbin/hoststated/control.c
index e9a664735f1..08094fe9547 100644
--- a/usr.sbin/hoststated/control.c
+++ b/usr.sbin/hoststated/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.17 2007/06/12 15:16:10 msf Exp $ */
+/* $OpenBSD: control.c,v 1.18 2007/09/07 08:20:24 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -225,6 +225,9 @@ control_dispatch_imsg(int fd, short event, void *arg)
case IMSG_CTL_SHOW_SUM:
show(c);
break;
+ case IMSG_CTL_SESSION:
+ show_sessions(c);
+ break;
case IMSG_CTL_SERVICE_DISABLE:
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
diff --git a/usr.sbin/hoststated/hoststated.h b/usr.sbin/hoststated/hoststated.h
index f62e31a6de9..7853098d0c8 100644
--- a/usr.sbin/hoststated/hoststated.h
+++ b/usr.sbin/hoststated/hoststated.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: hoststated.h,v 1.58 2007/09/07 07:59:18 reyk Exp $ */
+/* $OpenBSD: hoststated.h,v 1.59 2007/09/07 08:20:24 reyk Exp $ */
/*
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -105,6 +105,7 @@ enum imsg_type {
IMSG_CTL_TABLE,
IMSG_CTL_HOST,
IMSG_CTL_RELAY,
+ IMSG_CTL_SESSION,
IMSG_CTL_TABLE_CHANGED,
IMSG_CTL_PULL_RULESET,
IMSG_CTL_PUSH_RULESET,
@@ -389,6 +390,7 @@ TAILQ_HEAD(servicelist, service);
struct session {
objid_t id;
+ objid_t relayid;
struct ctl_relay_event in;
struct ctl_relay_event out;
u_int32_t outkey;
@@ -669,6 +671,7 @@ int imsg_get_fd(struct imsgbuf *);
pid_t pfe(struct hoststated *, int [2], int [2], int [RELAY_MAXPROC][2],
int [2], int [RELAY_MAXPROC][2]);
void show(struct ctl_conn *);
+void show_sessions(struct ctl_conn *);
int enable_service(struct ctl_conn *, struct ctl_id *);
int enable_table(struct ctl_conn *, struct ctl_id *);
int enable_host(struct ctl_conn *, struct ctl_id *);
diff --git a/usr.sbin/hoststated/pfe.c b/usr.sbin/hoststated/pfe.c
index 0381c6c98f7..4b5c29090ae 100644
--- a/usr.sbin/hoststated/pfe.c
+++ b/usr.sbin/hoststated/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.33 2007/06/19 13:06:00 pyr Exp $ */
+/* $OpenBSD: pfe.c,v 1.34 2007/09/07 08:20:24 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -553,6 +553,58 @@ show(struct ctl_conn *c)
imsg_compose(&c->ibuf, IMSG_CTL_END, 0, 0, -1, NULL, 0);
}
+void
+show_sessions(struct ctl_conn *c)
+{
+ int n, proc, done;
+ struct imsg imsg;
+
+ for (proc = 0; proc < env->prefork_relay; proc++) {
+ /*
+ * Request all the running sessions from the process
+ */
+ imsg_compose(&ibuf_relay[proc],
+ IMSG_CTL_SESSION, 0, 0, -1, NULL, 0);
+ while (ibuf_relay[proc].w.queued)
+ if (msgbuf_write(&ibuf_relay[proc].w) < 0)
+ fatalx("write error");
+
+ /*
+ * Wait for the reply and forward the messages to the
+ * control connection.
+ */
+ done = 0;
+ while (!done) {
+ do {
+ if ((n = imsg_read(&ibuf_relay[proc])) == -1)
+ fatalx("imsg_read error");
+ } while (n == -2); /* handle non-blocking I/O */
+ while (!done) {
+ if ((n = imsg_get(&ibuf_relay[proc],
+ &imsg)) == -1)
+ fatalx("imsg_get error");
+ if (n == 0)
+ break;
+ switch (imsg.hdr.type) {
+ case IMSG_CTL_SESSION:
+ imsg_compose(&c->ibuf,
+ IMSG_CTL_SESSION, proc, 0, -1,
+ imsg.data, sizeof(struct session));
+ break;
+ case IMSG_CTL_END:
+ done = 1;
+ break;
+ default:
+ fatalx("wrong message for session");
+ break;
+ }
+ imsg_free(&imsg);
+ }
+ }
+ }
+
+ imsg_compose(&c->ibuf, IMSG_CTL_END, 0, 0, -1, NULL, 0);
+}
int
disable_service(struct ctl_conn *c, struct ctl_id *id)
diff --git a/usr.sbin/hoststated/relay.c b/usr.sbin/hoststated/relay.c
index de11078ec59..6769cdfb705 100644
--- a/usr.sbin/hoststated/relay.c
+++ b/usr.sbin/hoststated/relay.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relay.c,v 1.41 2007/09/06 19:55:45 reyk Exp $ */
+/* $OpenBSD: relay.c,v 1.42 2007/09/07 08:20:24 reyk Exp $ */
/*
* Copyright (c) 2006, 2007 Reyk Floeter <reyk@openbsd.org>
@@ -1467,6 +1467,7 @@ relay_accept(int fd, short sig, void *arg)
con->out.con = con;
con->relay = rlay;
con->id = ++relay_conid;
+ con->relayid = rlay->conf.id;
con->outkey = rlay->dstkey;
con->in.tree = &proto->request_tree;
con->out.tree = &proto->response_tree;
@@ -1477,6 +1478,15 @@ relay_accept(int fd, short sig, void *arg)
goto err;
bcopy(&con->tv_start, &con->tv_last, sizeof(con->tv_last));
bcopy(&ss, &con->in.ss, sizeof(con->in.ss));
+ con->out.port = rlay->conf.dstport;
+ switch (ss.ss_family) {
+ case AF_INET:
+ con->in.port = ((struct sockaddr_in *)&ss)->sin_port;
+ break;
+ case AF_INET6:
+ con->in.port = ((struct sockaddr_in6 *)&ss)->sin6_port;
+ break;
+ }
relay_sessions++;
SPLAY_INSERT(session_tree, &rlay->sessions, con);
@@ -1783,6 +1793,7 @@ relay_dispatch_pfe(int fd, short event, void *ptr)
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
+ struct relay *rlay;
struct session *con;
struct ctl_natlook cnl;
struct timeval tv;
@@ -1885,6 +1896,14 @@ relay_dispatch_pfe(int fd, short event, void *ptr)
bzero(&tv, sizeof(tv));
evtimer_add(&con->ev, &tv);
break;
+ case IMSG_CTL_SESSION:
+ TAILQ_FOREACH(rlay, &env->relays, entry)
+ SPLAY_FOREACH(con, session_tree,
+ &rlay->sessions)
+ imsg_compose(ibuf, IMSG_CTL_SESSION,
+ 0, 0, -1, con, sizeof(*con));
+ imsg_compose(ibuf, IMSG_CTL_END, 0, 0, -1, NULL, 0);
+ break;
default:
log_debug("relay_dispatch_msg: unexpected imsg %d",
imsg.hdr.type);
diff --git a/usr.sbin/relayd/control.c b/usr.sbin/relayd/control.c
index e9a664735f1..08094fe9547 100644
--- a/usr.sbin/relayd/control.c
+++ b/usr.sbin/relayd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.17 2007/06/12 15:16:10 msf Exp $ */
+/* $OpenBSD: control.c,v 1.18 2007/09/07 08:20:24 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -225,6 +225,9 @@ control_dispatch_imsg(int fd, short event, void *arg)
case IMSG_CTL_SHOW_SUM:
show(c);
break;
+ case IMSG_CTL_SESSION:
+ show_sessions(c);
+ break;
case IMSG_CTL_SERVICE_DISABLE:
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c
index 0381c6c98f7..4b5c29090ae 100644
--- a/usr.sbin/relayd/pfe.c
+++ b/usr.sbin/relayd/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.33 2007/06/19 13:06:00 pyr Exp $ */
+/* $OpenBSD: pfe.c,v 1.34 2007/09/07 08:20:24 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -553,6 +553,58 @@ show(struct ctl_conn *c)
imsg_compose(&c->ibuf, IMSG_CTL_END, 0, 0, -1, NULL, 0);
}
+void
+show_sessions(struct ctl_conn *c)
+{
+ int n, proc, done;
+ struct imsg imsg;
+
+ for (proc = 0; proc < env->prefork_relay; proc++) {
+ /*
+ * Request all the running sessions from the process
+ */
+ imsg_compose(&ibuf_relay[proc],
+ IMSG_CTL_SESSION, 0, 0, -1, NULL, 0);
+ while (ibuf_relay[proc].w.queued)
+ if (msgbuf_write(&ibuf_relay[proc].w) < 0)
+ fatalx("write error");
+
+ /*
+ * Wait for the reply and forward the messages to the
+ * control connection.
+ */
+ done = 0;
+ while (!done) {
+ do {
+ if ((n = imsg_read(&ibuf_relay[proc])) == -1)
+ fatalx("imsg_read error");
+ } while (n == -2); /* handle non-blocking I/O */
+ while (!done) {
+ if ((n = imsg_get(&ibuf_relay[proc],
+ &imsg)) == -1)
+ fatalx("imsg_get error");
+ if (n == 0)
+ break;
+ switch (imsg.hdr.type) {
+ case IMSG_CTL_SESSION:
+ imsg_compose(&c->ibuf,
+ IMSG_CTL_SESSION, proc, 0, -1,
+ imsg.data, sizeof(struct session));
+ break;
+ case IMSG_CTL_END:
+ done = 1;
+ break;
+ default:
+ fatalx("wrong message for session");
+ break;
+ }
+ imsg_free(&imsg);
+ }
+ }
+ }
+
+ imsg_compose(&c->ibuf, IMSG_CTL_END, 0, 0, -1, NULL, 0);
+}
int
disable_service(struct ctl_conn *c, struct ctl_id *id)
diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c
index de11078ec59..6769cdfb705 100644
--- a/usr.sbin/relayd/relay.c
+++ b/usr.sbin/relayd/relay.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relay.c,v 1.41 2007/09/06 19:55:45 reyk Exp $ */
+/* $OpenBSD: relay.c,v 1.42 2007/09/07 08:20:24 reyk Exp $ */
/*
* Copyright (c) 2006, 2007 Reyk Floeter <reyk@openbsd.org>
@@ -1467,6 +1467,7 @@ relay_accept(int fd, short sig, void *arg)
con->out.con = con;
con->relay = rlay;
con->id = ++relay_conid;
+ con->relayid = rlay->conf.id;
con->outkey = rlay->dstkey;
con->in.tree = &proto->request_tree;
con->out.tree = &proto->response_tree;
@@ -1477,6 +1478,15 @@ relay_accept(int fd, short sig, void *arg)
goto err;
bcopy(&con->tv_start, &con->tv_last, sizeof(con->tv_last));
bcopy(&ss, &con->in.ss, sizeof(con->in.ss));
+ con->out.port = rlay->conf.dstport;
+ switch (ss.ss_family) {
+ case AF_INET:
+ con->in.port = ((struct sockaddr_in *)&ss)->sin_port;
+ break;
+ case AF_INET6:
+ con->in.port = ((struct sockaddr_in6 *)&ss)->sin6_port;
+ break;
+ }
relay_sessions++;
SPLAY_INSERT(session_tree, &rlay->sessions, con);
@@ -1783,6 +1793,7 @@ relay_dispatch_pfe(int fd, short event, void *ptr)
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
+ struct relay *rlay;
struct session *con;
struct ctl_natlook cnl;
struct timeval tv;
@@ -1885,6 +1896,14 @@ relay_dispatch_pfe(int fd, short event, void *ptr)
bzero(&tv, sizeof(tv));
evtimer_add(&con->ev, &tv);
break;
+ case IMSG_CTL_SESSION:
+ TAILQ_FOREACH(rlay, &env->relays, entry)
+ SPLAY_FOREACH(con, session_tree,
+ &rlay->sessions)
+ imsg_compose(ibuf, IMSG_CTL_SESSION,
+ 0, 0, -1, con, sizeof(*con));
+ imsg_compose(ibuf, IMSG_CTL_END, 0, 0, -1, NULL, 0);
+ break;
default:
log_debug("relay_dispatch_msg: unexpected imsg %d",
imsg.hdr.type);
diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h
index 9682ca5a55a..cd22d7bf4cd 100644
--- a/usr.sbin/relayd/relayd.h
+++ b/usr.sbin/relayd/relayd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.h,v 1.58 2007/09/07 07:59:18 reyk Exp $ */
+/* $OpenBSD: relayd.h,v 1.59 2007/09/07 08:20:24 reyk Exp $ */
/*
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -105,6 +105,7 @@ enum imsg_type {
IMSG_CTL_TABLE,
IMSG_CTL_HOST,
IMSG_CTL_RELAY,
+ IMSG_CTL_SESSION,
IMSG_CTL_TABLE_CHANGED,
IMSG_CTL_PULL_RULESET,
IMSG_CTL_PUSH_RULESET,
@@ -389,6 +390,7 @@ TAILQ_HEAD(servicelist, service);
struct session {
objid_t id;
+ objid_t relayid;
struct ctl_relay_event in;
struct ctl_relay_event out;
u_int32_t outkey;
@@ -669,6 +671,7 @@ int imsg_get_fd(struct imsgbuf *);
pid_t pfe(struct hoststated *, int [2], int [2], int [RELAY_MAXPROC][2],
int [2], int [RELAY_MAXPROC][2]);
void show(struct ctl_conn *);
+void show_sessions(struct ctl_conn *);
int enable_service(struct ctl_conn *, struct ctl_id *);
int enable_table(struct ctl_conn *, struct ctl_id *);
int enable_host(struct ctl_conn *, struct ctl_id *);