summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Yves Ritschard <pyr@cvs.openbsd.org>2007-05-29 00:21:11 +0000
committerPierre-Yves Ritschard <pyr@cvs.openbsd.org>2007-05-29 00:21:11 +0000
commit3a6280ede9c3d810e07d583d2dd32bb660be6295 (patch)
treef86c12b4bb5163f82b5da09a87bc3368df2fb49d
parentc5f0f50dae49c13e66ed1ad97606a14435d0c1d9 (diff)
move struct relay to the runtime + config scheme.
this time around, include hoststatectl changes too.
-rw-r--r--usr.sbin/hoststatectl/hoststatectl.c6
-rw-r--r--usr.sbin/hoststated/hoststated.c6
-rw-r--r--usr.sbin/hoststated/hoststated.h30
-rw-r--r--usr.sbin/hoststated/parse.y90
-rw-r--r--usr.sbin/hoststated/relay.c99
-rw-r--r--usr.sbin/relayctl/relayctl.c6
-rw-r--r--usr.sbin/relayd/parse.y90
-rw-r--r--usr.sbin/relayd/relay.c99
-rw-r--r--usr.sbin/relayd/relayd.c6
-rw-r--r--usr.sbin/relayd/relayd.h30
10 files changed, 248 insertions, 214 deletions
diff --git a/usr.sbin/hoststatectl/hoststatectl.c b/usr.sbin/hoststatectl/hoststatectl.c
index d2cb50a5671..7b5c539b144 100644
--- a/usr.sbin/hoststatectl/hoststatectl.c
+++ b/usr.sbin/hoststatectl/hoststatectl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hoststatectl.c,v 1.17 2007/05/28 00:04:47 pyr Exp $ */
+/* $OpenBSD: hoststatectl.c,v 1.18 2007/05/29 00:21:10 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -343,8 +343,8 @@ show_summary_msg(struct imsg *imsg, int type)
break;
rlay = imsg->data;
printf("relay\t%4u\t%-24s\t%-7s\t%s\n",
- rlay->id, rlay->name, "",
- print_relay_status(rlay->flags));
+ rlay->conf.id, rlay->conf.name, "",
+ print_relay_status(rlay->conf.flags));
break;
case IMSG_CTL_STATISTICS:
if (type != SHOW_RELAYS)
diff --git a/usr.sbin/hoststated/hoststated.c b/usr.sbin/hoststated/hoststated.c
index dc716cad08d..07d90212c22 100644
--- a/usr.sbin/hoststated/hoststated.c
+++ b/usr.sbin/hoststated/hoststated.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hoststated.c,v 1.24 2007/05/28 22:11:33 pyr Exp $ */
+/* $OpenBSD: hoststated.c,v 1.25 2007/05/29 00:21:10 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -596,7 +596,7 @@ relay_find(struct hoststated *env, objid_t id)
struct relay *rlay;
TAILQ_FOREACH(rlay, &env->relays, entry)
- if (rlay->id == id)
+ if (rlay->conf.id == id)
return (rlay);
return (NULL);
}
@@ -655,7 +655,7 @@ relay_findbyname(struct hoststated *env, const char *name)
struct relay *rlay;
TAILQ_FOREACH(rlay, &env->relays, entry)
- if (strcmp(rlay->name, name) == 0)
+ if (strcmp(rlay->conf.name, name) == 0)
return (rlay);
return (NULL);
}
diff --git a/usr.sbin/hoststated/hoststated.h b/usr.sbin/hoststated/hoststated.h
index 568dff7c18b..a7b4ee77358 100644
--- a/usr.sbin/hoststated/hoststated.h
+++ b/usr.sbin/hoststated/hoststated.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: hoststated.h,v 1.45 2007/05/28 22:11:33 pyr Exp $ */
+/* $OpenBSD: hoststated.h,v 1.46 2007/05/29 00:21:10 pyr Exp $ */
/*
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -469,38 +469,44 @@ struct protocol {
};
TAILQ_HEAD(protolist, protocol);
-struct relay {
+struct relay_config {
objid_t id;
u_int16_t flags;
- int up;
- struct protocol *proto;
+ objid_t proto;
char name[MAXHOSTNAMELEN];
- int s;
in_port_t port;
+ in_port_t dstport;
+ int dstmode;
+ int dstcheck;
+ int dstretry;
+ objid_t dsttable;
struct sockaddr_storage ss;
+ struct sockaddr_storage dstss;
+ struct timeval timeout;
+};
+
+struct relay {
+ TAILQ_ENTRY(relay) entry;
+ struct relay_config conf;
+ int up;
+ struct protocol *proto;
+ int s;
struct bufferevent *bev;
int dsts;
- in_port_t dstport;
- struct sockaddr_storage dstss;
struct bufferevent *dstbev;
struct table *dsttable;
u_int32_t dstkey;
struct host *dsthost[RELAY_MAXHOSTS];
int dstnhosts;
- int dstmode;
- int dstcheck;
- int dstretry;
struct event ev;
- struct timeval timeout;
SSL_CTX *ctx;
struct ctl_stats stats[RELAY_MAXPROC + 1];
struct sessionlist sessions;
- TAILQ_ENTRY(relay) entry;
};
TAILQ_HEAD(relaylist, relay);
diff --git a/usr.sbin/hoststated/parse.y b/usr.sbin/hoststated/parse.y
index f824af3dea4..d970d01e43f 100644
--- a/usr.sbin/hoststated/parse.y
+++ b/usr.sbin/hoststated/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.42 2007/05/28 17:37:16 pyr Exp $ */
+/* $OpenBSD: parse.y,v 1.43 2007/05/29 00:21:10 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -830,7 +830,7 @@ relay : RELAY STRING {
struct relay *r;
TAILQ_FOREACH(r, &conf->relays, entry)
- if (!strcmp(r->name, $2))
+ if (!strcmp(r->conf.name, $2))
break;
if (r != NULL) {
yyerror("relay %s defined twice", $2);
@@ -840,37 +840,40 @@ relay : RELAY STRING {
if ((r = calloc(1, sizeof (*r))) == NULL)
fatal("out of memory");
- if (strlcpy(r->name, $2, sizeof(r->name)) >=
- sizeof(r->name)) {
+ if (strlcpy(r->conf.name, $2, sizeof(r->conf.name)) >=
+ sizeof(r->conf.name)) {
yyerror("relay name truncated");
YYERROR;
}
free($2);
- r->id = last_relay_id++;
- r->timeout.tv_sec = RELAY_TIMEOUT;
+ r->conf.id = last_relay_id++;
+ r->conf.timeout.tv_sec = RELAY_TIMEOUT;
r->proto = NULL;
- r->dsttable = NULL;
- r->dstretry = 0;
+ r->conf.proto = EMPTY_ID;
+ r->conf.dsttable = EMPTY_ID;
+ r->conf.dstretry = 0;
if (last_relay_id == INT_MAX) {
yyerror("too many relays defined");
YYERROR;
}
rlay = r;
} '{' optnl relayopts_l '}' {
- if (rlay->ss.ss_family == AF_UNSPEC) {
+ if (rlay->conf.ss.ss_family == AF_UNSPEC) {
yyerror("relay %s has no listener",
- rlay->name);
+ rlay->conf.name);
YYERROR;
}
- if ((rlay->flags & F_NATLOOK) == 0 &&
- rlay->dstss.ss_family == AF_UNSPEC &&
- rlay->dsttable == NULL) {
+ if ((rlay->conf.flags & F_NATLOOK) == 0 &&
+ rlay->conf.dstss.ss_family == AF_UNSPEC &&
+ rlay->conf.dsttable == EMPTY_ID) {
yyerror("relay %s has no target, service, "
- "or table", rlay->name);
+ "or table", rlay->conf.name);
YYERROR;
}
- if (rlay->proto == NULL)
+ if (rlay->conf.proto == EMPTY_ID) {
rlay->proto = &conf->proto_default;
+ rlay->conf.proto = conf->proto_default.id;
+ }
conf->relaycount++;
TAILQ_INIT(&rlay->sessions);
TAILQ_INSERT_HEAD(&conf->relays, rlay, entry);
@@ -885,9 +888,9 @@ relayoptsl : LISTEN ON STRING port optssl {
struct addresslist al;
struct address *h;
- if (rlay->ss.ss_family != AF_UNSPEC) {
+ if (rlay->conf.ss.ss_family != AF_UNSPEC) {
yyerror("relay %s listener already specified",
- rlay->name);
+ rlay->conf.name);
YYERROR;
}
@@ -899,10 +902,10 @@ relayoptsl : LISTEN ON STRING port optssl {
}
free($3);
h = TAILQ_FIRST(&al);
- bcopy(&h->ss, &rlay->ss, sizeof(rlay->ss));
- rlay->port = h->port;
+ bcopy(&h->ss, &rlay->conf.ss, sizeof(rlay->conf.ss));
+ rlay->conf.port = h->port;
if ($5) {
- rlay->flags |= F_SSL;
+ rlay->conf.flags |= F_SSL;
conf->flags |= F_SSL;
}
}
@@ -910,9 +913,9 @@ relayoptsl : LISTEN ON STRING port optssl {
struct addresslist al;
struct address *h;
- if (rlay->dstss.ss_family != AF_UNSPEC) {
+ if (rlay->conf.dstss.ss_family != AF_UNSPEC) {
yyerror("relay %s target or service already "
- "specified", rlay->name);
+ "specified", rlay->conf.name);
free($3);
YYERROR;
}
@@ -925,48 +928,52 @@ relayoptsl : LISTEN ON STRING port optssl {
}
free($3);
h = TAILQ_FIRST(&al);
- bcopy(&h->ss, &rlay->dstss, sizeof(rlay->dstss));
- rlay->dstport = h->port;
- rlay->dstretry = $5;
+ bcopy(&h->ss, &rlay->conf.dstss,
+ sizeof(rlay->conf.dstss));
+ rlay->conf.dstport = h->port;
+ rlay->conf.dstretry = $5;
}
| SERVICE STRING retry {
struct service *svc;
struct address *h;
- if (rlay->dstss.ss_family != AF_UNSPEC) {
+ if (rlay->conf.dstss.ss_family != AF_UNSPEC) {
yyerror("relay %s target or service already "
- "specified", rlay->name);
+ "specified", rlay->conf.name);
free($2);
YYERROR;
}
if ((svc = service_findbyname(conf, $2)) == NULL) {
yyerror("relay %s for unknown service %s",
- rlay->name, $2);
+ rlay->conf.name, $2);
free($2);
YYERROR;
}
free($2);
h = TAILQ_FIRST(&svc->virts);
- bcopy(&h->ss, &rlay->dstss, sizeof(rlay->dstss));
- rlay->dstport = h->port;
- rlay->dstretry = $3;
+ bcopy(&h->ss, &rlay->conf.dstss,
+ sizeof(rlay->conf.dstss));
+ rlay->conf.dstport = h->port;
+ rlay->conf.dstretry = $3;
}
| TABLE STRING dstport dstmode docheck {
struct table *tb;
- rlay->dstport = $3;
- if (rlay->dstport == 0)
- rlay->dstport = rlay->port;
+ rlay->conf.dstport = $3;
+ if (rlay->conf.dstport == 0)
+ rlay->conf.dstport = rlay->conf.port;
- if ((tb = table_inherit($2, rlay->dstport)) == NULL) {
+ if ((tb = table_inherit($2, rlay->conf.dstport)) ==
+ NULL) {
free($2);
YYERROR;
}
free($2);
+ rlay->conf.dsttable = tb->conf.id;
rlay->dsttable = tb;
- rlay->dstmode = $4;
- rlay->dstcheck = $5;
+ rlay->conf.dstmode = $4;
+ rlay->conf.dstcheck = $5;
rlay->dsttable->conf.flags |= F_USED;
}
| PROTO STRING {
@@ -981,15 +988,16 @@ relayoptsl : LISTEN ON STRING port optssl {
YYERROR;
}
p->flags |= F_USED;
+ rlay->conf.proto = p->id;
rlay->proto = p;
free($2);
}
| NAT LOOKUP retry {
- rlay->flags |= F_NATLOOK;
- rlay->dstretry = $3;
+ rlay->conf.flags |= F_NATLOOK;
+ rlay->conf.dstretry = $3;
}
- | TIMEOUT number { rlay->timeout.tv_sec = $2; }
- | DISABLE { rlay->flags |= F_DISABLE; }
+ | TIMEOUT number { rlay->conf.timeout.tv_sec = $2; }
+ | DISABLE { rlay->conf.flags |= F_DISABLE; }
;
dstmode : /* empty */ { $$ = RELAY_DSTMODE_DEFAULT; }
diff --git a/usr.sbin/hoststated/relay.c b/usr.sbin/hoststated/relay.c
index 5d05950523e..88a2a84e292 100644
--- a/usr.sbin/hoststated/relay.c
+++ b/usr.sbin/hoststated/relay.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relay.c,v 1.30 2007/05/28 22:11:33 pyr Exp $ */
+/* $OpenBSD: relay.c,v 1.31 2007/05/29 00:21:10 pyr Exp $ */
/*
* Copyright (c) 2006, 2007 Reyk Floeter <reyk@openbsd.org>
@@ -254,7 +254,7 @@ relay_shutdown(void)
struct relay *rlay;
TAILQ_FOREACH(rlay, &env->relays, entry) {
- if (rlay->flags & F_DISABLE)
+ if (rlay->conf.flags & F_DISABLE)
continue;
close(rlay->s);
while ((con = TAILQ_FIRST(&rlay->sessions)) != NULL)
@@ -359,17 +359,17 @@ relay_privinit(void)
ssl_init(env);
TAILQ_FOREACH(rlay, &env->relays, entry) {
- log_debug("relay_init: adding relay %s", rlay->name);
+ log_debug("relay_init: adding relay %s", rlay->conf.name);
if (debug)
relay_protodebug(rlay);
- if ((rlay->flags & F_SSL) &&
+ if ((rlay->conf.flags & F_SSL) &&
(rlay->ctx = relay_ssl_ctx_create(rlay)) == NULL)
fatal("relay_launch: failed to create SSL context");
- if ((rlay->s = relay_socket_listen(&rlay->ss, rlay->port,
- rlay->proto)) == -1)
+ if ((rlay->s = relay_socket_listen(&rlay->conf.ss,
+ rlay->conf.port, rlay->proto)) == -1)
fatal("relay_launch: failed to listen");
}
}
@@ -383,14 +383,14 @@ relay_init(void)
TAILQ_FOREACH(rlay, &env->relays, entry) {
if (rlay->dsttable != NULL) {
- switch (rlay->dstmode) {
+ switch (rlay->conf.dstmode) {
case RELAY_DSTMODE_ROUNDROBIN:
rlay->dstkey = 0;
break;
case RELAY_DSTMODE_LOADBALANCE:
case RELAY_DSTMODE_HASH:
rlay->dstkey =
- hash32_str(rlay->name, HASHINIT);
+ hash32_str(rlay->conf.name, HASHINIT);
rlay->dstkey =
hash32_str(rlay->dsttable->conf.name,
rlay->dstkey);
@@ -405,7 +405,7 @@ relay_init(void)
}
log_info("adding %d hosts from table %s%s",
rlay->dstnhosts, rlay->dsttable->conf.name,
- rlay->dstcheck ? "" : " (no check)");
+ rlay->conf.dstcheck ? "" : " (no check)");
}
}
@@ -459,7 +459,7 @@ relay_statistics(int fd, short events, void *arg)
if (resetday)
cur->last_day = 0;
- crs.id = rlay->id;
+ crs.id = rlay->conf.id;
crs.proc = proc_id;
imsg_compose(ibuf_pfe, IMSG_STATISTICS, 0, 0,
&crs, sizeof(crs));
@@ -468,7 +468,7 @@ relay_statistics(int fd, short events, void *arg)
con != NULL; con = next_con) {
next_con = TAILQ_NEXT(con, entry);
timersub(&tv_now, &con->tv_last, &tv);
- if (timercmp(&tv, &rlay->timeout, >=))
+ if (timercmp(&tv, &rlay->conf.timeout, >=))
relay_close(con, "hard timeout");
}
}
@@ -485,7 +485,7 @@ relay_launch(void)
struct relay *rlay;
TAILQ_FOREACH(rlay, &env->relays, entry) {
- log_debug("relay_launch: running relay %s", rlay->name);
+ log_debug("relay_launch: running relay %s", rlay->conf.name);
rlay->up = HOST_UP;
@@ -680,7 +680,7 @@ relay_connected(int fd, short sig, void *arg)
con->out.bev = bev;
bufferevent_settimeout(bev,
- rlay->timeout.tv_sec, rlay->timeout.tv_sec);
+ rlay->conf.timeout.tv_sec, rlay->conf.timeout.tv_sec);
bufferevent_enable(bev, EV_READ|EV_WRITE);
}
@@ -723,11 +723,11 @@ relay_input(struct session *con)
}
/* Initialize the SSL wrapper */
- if ((rlay->flags & F_SSL) && con->in.ssl != NULL)
+ if ((rlay->conf.flags & F_SSL) && con->in.ssl != NULL)
relay_ssl_connected(&con->in);
bufferevent_settimeout(con->in.bev,
- rlay->timeout.tv_sec, rlay->timeout.tv_sec);
+ rlay->conf.timeout.tv_sec, rlay->conf.timeout.tv_sec);
bufferevent_enable(con->in.bev, EV_READ|EV_WRITE);
}
@@ -792,21 +792,23 @@ relay_expand_http(struct ctl_relay_event *cre, char *val, char *buf, size_t len)
}
if (strstr(val, "$SERVER_") != NULL) {
if (strstr(val, "$SERVER_ADDR") != NULL) {
- if (relay_host(&rlay->ss, ibuf, sizeof(ibuf)) == NULL)
+ if (relay_host(&rlay->conf.ss,
+ ibuf, sizeof(ibuf)) == NULL)
return (NULL);
if (expand_string(buf, len,
"$SERVER_ADDR", ibuf) != 0)
return (NULL);
}
if (strstr(val, "$SERVER_PORT") != NULL) {
- snprintf(ibuf, sizeof(ibuf), "%u", ntohs(rlay->port));
+ snprintf(ibuf, sizeof(ibuf), "%u",
+ ntohs(rlay->conf.port));
if (expand_string(buf, len,
"$SERVER_PORT", ibuf) != 0)
return (NULL);
}
}
if (strstr(val, "$TIMEOUT") != NULL) {
- snprintf(ibuf, sizeof(ibuf), "%lu", rlay->timeout.tv_sec);
+ snprintf(ibuf, sizeof(ibuf), "%lu", rlay->conf.timeout.tv_sec);
if (expand_string(buf, len, "$TIMEOUT", ibuf) != 0)
return (NULL);
}
@@ -1464,7 +1466,8 @@ relay_accept(int fd, short sig, void *arg)
if ((s = accept(fd, (struct sockaddr *)&ss, (socklen_t *)&slen)) == -1)
return;
- if (relay_sessions >= RELAY_MAX_SESSIONS || rlay->flags & F_DISABLE)
+ if (relay_sessions >= RELAY_MAX_SESSIONS ||
+ rlay->conf.flags & F_DISABLE)
goto err;
if ((con = (struct session *)
@@ -1486,7 +1489,7 @@ relay_accept(int fd, short sig, void *arg)
con->out.tree = &proto->response_tree;
con->in.dir = RELAY_DIR_REQUEST;
con->out.dir = RELAY_DIR_RESPONSE;
- con->retry = rlay->dstretry;
+ con->retry = rlay->conf.dstretry;
if (gettimeofday(&con->tv_start, NULL))
goto err;
bcopy(&con->tv_start, &con->tv_last, sizeof(con->tv_last));
@@ -1506,7 +1509,7 @@ relay_accept(int fd, short sig, void *arg)
return;
}
- if (rlay->flags & F_NATLOOK) {
+ if (rlay->conf.flags & F_NATLOOK) {
if ((cnl = (struct ctl_natlook *)
calloc(1, sizeof(struct ctl_natlook))) == NULL)
goto err;
@@ -1518,19 +1521,19 @@ relay_accept(int fd, short sig, void *arg)
/* Increment the per-relay session counter */
rlay->stats[proc_id].last++;
- if (rlay->flags & F_NATLOOK && cnl != NULL) {
+ if (rlay->conf.flags & F_NATLOOK && cnl != NULL) {
con->cnl = cnl;;
bzero(cnl, sizeof(*cnl));
cnl->in = -1;
cnl->id = con->id;
cnl->proc = proc_id;
bcopy(&con->in.ss, &cnl->src, sizeof(cnl->src));
- bcopy(&rlay->ss, &cnl->dst, sizeof(cnl->dst));
+ bcopy(&rlay->conf.ss, &cnl->dst, sizeof(cnl->dst));
imsg_compose(ibuf_pfe, IMSG_NATLOOK, 0, 0, cnl, sizeof(*cnl));
/* Schedule timeout */
evtimer_set(&con->ev, relay_natlook, con);
- bcopy(&rlay->timeout, &tv, sizeof(tv));
+ bcopy(&rlay->conf.timeout, &tv, sizeof(tv));
evtimer_add(&con->ev, &tv);
return;
}
@@ -1573,12 +1576,12 @@ relay_from_table(struct session *con)
u_int32_t p = con->outkey;
int idx = 0;
- if (rlay->dstcheck && !table->up) {
+ if (rlay->conf.dstcheck && !table->up) {
log_debug("relay_from_table: no active hosts");
return (-1);
}
- switch (rlay->dstmode) {
+ switch (rlay->conf.dstmode) {
case RELAY_DSTMODE_ROUNDROBIN:
if ((int)rlay->dstkey >= rlay->dstnhosts)
rlay->dstkey = 0;
@@ -1588,8 +1591,8 @@ relay_from_table(struct session *con)
p = relay_hash_addr(&con->in.ss, p);
/* FALLTHROUGH */
case RELAY_DSTMODE_HASH:
- p = relay_hash_addr(&rlay->ss, p);
- p = hash32_buf(&rlay->port, sizeof(rlay->port), p);
+ p = relay_hash_addr(&rlay->conf.ss, p);
+ p = hash32_buf(&rlay->conf.port, sizeof(rlay->conf.port), p);
if ((idx = p % rlay->dstnhosts) >= RELAY_MAXHOSTS)
return (-1);
}
@@ -1598,13 +1601,13 @@ relay_from_table(struct session *con)
host->conf.name, p, idx);
while (host != NULL) {
DPRINTF("relay_from_table: host %s", host->conf.name);
- if (!rlay->dstcheck || host->up == HOST_UP)
+ if (!rlay->conf.dstcheck || host->up == HOST_UP)
goto found;
host = TAILQ_NEXT(host, entry);
}
TAILQ_FOREACH(host, &rlay->dsttable->hosts, entry) {
DPRINTF("relay_from_table: next host %s", host->conf.name);
- if (!rlay->dstcheck || host->up == HOST_UP)
+ if (!rlay->conf.dstcheck || host->up == HOST_UP)
goto found;
}
@@ -1630,7 +1633,7 @@ relay_natlook(int fd, short event, void *arg)
fatalx("invalid NAT lookup");
if (con->out.ss.ss_family == AF_UNSPEC && cnl->in == -1 &&
- rlay->dstss.ss_family == AF_UNSPEC && rlay->dsttable == NULL) {
+ rlay->conf.dstss.ss_family == AF_UNSPEC && rlay->dsttable == NULL) {
relay_close(con, "session NAT lookup failed");
return;
}
@@ -1649,15 +1652,15 @@ relay_session(struct session *con)
{
struct relay *rlay = (struct relay *)con->relay;
- if (bcmp(&rlay->ss, &con->out.ss, sizeof(con->out.ss)) == 0 &&
- con->out.port == rlay->port) {
+ if (bcmp(&rlay->conf.ss, &con->out.ss, sizeof(con->out.ss)) == 0 &&
+ con->out.port == rlay->conf.port) {
log_debug("relay_session: session %d: looping",
con->id);
relay_close(con, "session aborted");
return;
}
- if ((rlay->flags & F_SSL) && (con->in.ssl == NULL)) {
+ if ((rlay->conf.flags & F_SSL) && (con->in.ssl == NULL)) {
relay_ssl_transaction(con);
return;
}
@@ -1682,8 +1685,8 @@ relay_connect(struct session *con)
if (relay_from_table(con) != 0)
return (-1);
} else if (con->out.ss.ss_family == AF_UNSPEC) {
- bcopy(&rlay->dstss, &con->out.ss, sizeof(con->out.ss));
- con->out.port = rlay->dstport;
+ bcopy(&rlay->conf.dstss, &con->out.ss, sizeof(con->out.ss));
+ con->out.port = rlay->conf.dstport;
}
retry:
@@ -1734,7 +1737,7 @@ relay_close(struct session *con, const char *msg)
evbuffer_add_printf(con->log, "\r\n") != -1)
ptr = evbuffer_readline(con->log);
log_info("relay %s, session %d (%d active), %s -> %s:%d, "
- "%s%s%s", rlay->name, con->id, relay_sessions,
+ "%s%s%s", rlay->conf.name, con->id, relay_sessions,
ibuf, obuf, ntohs(con->out.port), msg,
ptr == NULL ? "" : ",", ptr == NULL ? "" : ptr);
if (ptr != NULL)
@@ -1955,7 +1958,7 @@ relay_ssl_ctx_create(struct relay *rlay)
goto err;
/* Modify session timeout and cache size*/
- SSL_CTX_set_timeout(ctx, rlay->timeout.tv_sec);
+ SSL_CTX_set_timeout(ctx, rlay->conf.timeout.tv_sec);
if (proto->cache < -1) {
SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF);
} else if (proto->cache >= -1) {
@@ -1983,7 +1986,7 @@ relay_ssl_ctx_create(struct relay *rlay)
if (!SSL_CTX_set_cipher_list(ctx, ciphers))
goto err;
- if (relay_host(&rlay->ss, hbuf, sizeof(hbuf)) == NULL)
+ if (relay_host(&rlay->conf.ss, hbuf, sizeof(hbuf)) == NULL)
goto err;
/* Load the certificate */
@@ -2006,8 +2009,8 @@ relay_ssl_ctx_create(struct relay *rlay)
goto err;
/* Set session context to the local relay name */
- if (!SSL_CTX_set_session_id_context(ctx, rlay->name,
- strlen(rlay->name)))
+ if (!SSL_CTX_set_session_id_context(ctx, rlay->conf.name,
+ strlen(rlay->conf.name)))
goto err;
return (ctx);
@@ -2015,7 +2018,7 @@ relay_ssl_ctx_create(struct relay *rlay)
err:
if (ctx != NULL)
SSL_CTX_free(ctx);
- ssl_error(rlay->name, "relay_ssl_ctx_create");
+ ssl_error(rlay->conf.name, "relay_ssl_ctx_create");
return (NULL);
}
@@ -2044,7 +2047,7 @@ relay_ssl_transaction(struct session *con)
err:
if (ssl != NULL)
SSL_free(ssl);
- ssl_error(rlay->name, "relay_ssl_transaction");
+ ssl_error(rlay->conf.name, "relay_ssl_transaction");
}
void
@@ -2082,7 +2085,7 @@ relay_ssl_accept(int fd, short event, void *arg)
}
/* FALLTHROUGH */
default:
- ssl_error(rlay->name, "relay_ssl_accept");
+ ssl_error(rlay->conf.name, "relay_ssl_accept");
relay_close(con, "SSL accept error");
return;
}
@@ -2091,10 +2094,10 @@ relay_ssl_accept(int fd, short event, void *arg)
#ifdef DEBUG
log_info("relay %s, session %d established (%d active)",
- rlay->name, con->id, relay_sessions);
+ rlay->conf.name, con->id, relay_sessions);
#else
log_debug("relay %s, session %d established (%d active)",
- rlay->name, con->id, relay_sessions);
+ rlay->conf.name, con->id, relay_sessions);
#endif
relay_session(con);
return;
@@ -2157,7 +2160,7 @@ relay_ssl_readcb(int fd, short event, void *arg)
if (ret == 0)
what |= EVBUFFER_EOF;
else {
- ssl_error(rlay->name, "relay_ssl_readcb");
+ ssl_error(rlay->conf.name, "relay_ssl_readcb");
what |= EVBUFFER_ERROR;
}
goto err;
@@ -2236,7 +2239,7 @@ relay_ssl_writecb(int fd, short event, void *arg)
if (ret == 0)
what |= EVBUFFER_EOF;
else {
- ssl_error(rlay->name,
+ ssl_error(rlay->conf.name,
"relay_ssl_writecb");
what |= EVBUFFER_ERROR;
}
diff --git a/usr.sbin/relayctl/relayctl.c b/usr.sbin/relayctl/relayctl.c
index 276c466c4f8..d2e8f0b37fe 100644
--- a/usr.sbin/relayctl/relayctl.c
+++ b/usr.sbin/relayctl/relayctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayctl.c,v 1.17 2007/05/28 00:04:47 pyr Exp $ */
+/* $OpenBSD: relayctl.c,v 1.18 2007/05/29 00:21:10 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -343,8 +343,8 @@ show_summary_msg(struct imsg *imsg, int type)
break;
rlay = imsg->data;
printf("relay\t%4u\t%-24s\t%-7s\t%s\n",
- rlay->id, rlay->name, "",
- print_relay_status(rlay->flags));
+ rlay->conf.id, rlay->conf.name, "",
+ print_relay_status(rlay->conf.flags));
break;
case IMSG_CTL_STATISTICS:
if (type != SHOW_RELAYS)
diff --git a/usr.sbin/relayd/parse.y b/usr.sbin/relayd/parse.y
index f824af3dea4..d970d01e43f 100644
--- a/usr.sbin/relayd/parse.y
+++ b/usr.sbin/relayd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.42 2007/05/28 17:37:16 pyr Exp $ */
+/* $OpenBSD: parse.y,v 1.43 2007/05/29 00:21:10 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -830,7 +830,7 @@ relay : RELAY STRING {
struct relay *r;
TAILQ_FOREACH(r, &conf->relays, entry)
- if (!strcmp(r->name, $2))
+ if (!strcmp(r->conf.name, $2))
break;
if (r != NULL) {
yyerror("relay %s defined twice", $2);
@@ -840,37 +840,40 @@ relay : RELAY STRING {
if ((r = calloc(1, sizeof (*r))) == NULL)
fatal("out of memory");
- if (strlcpy(r->name, $2, sizeof(r->name)) >=
- sizeof(r->name)) {
+ if (strlcpy(r->conf.name, $2, sizeof(r->conf.name)) >=
+ sizeof(r->conf.name)) {
yyerror("relay name truncated");
YYERROR;
}
free($2);
- r->id = last_relay_id++;
- r->timeout.tv_sec = RELAY_TIMEOUT;
+ r->conf.id = last_relay_id++;
+ r->conf.timeout.tv_sec = RELAY_TIMEOUT;
r->proto = NULL;
- r->dsttable = NULL;
- r->dstretry = 0;
+ r->conf.proto = EMPTY_ID;
+ r->conf.dsttable = EMPTY_ID;
+ r->conf.dstretry = 0;
if (last_relay_id == INT_MAX) {
yyerror("too many relays defined");
YYERROR;
}
rlay = r;
} '{' optnl relayopts_l '}' {
- if (rlay->ss.ss_family == AF_UNSPEC) {
+ if (rlay->conf.ss.ss_family == AF_UNSPEC) {
yyerror("relay %s has no listener",
- rlay->name);
+ rlay->conf.name);
YYERROR;
}
- if ((rlay->flags & F_NATLOOK) == 0 &&
- rlay->dstss.ss_family == AF_UNSPEC &&
- rlay->dsttable == NULL) {
+ if ((rlay->conf.flags & F_NATLOOK) == 0 &&
+ rlay->conf.dstss.ss_family == AF_UNSPEC &&
+ rlay->conf.dsttable == EMPTY_ID) {
yyerror("relay %s has no target, service, "
- "or table", rlay->name);
+ "or table", rlay->conf.name);
YYERROR;
}
- if (rlay->proto == NULL)
+ if (rlay->conf.proto == EMPTY_ID) {
rlay->proto = &conf->proto_default;
+ rlay->conf.proto = conf->proto_default.id;
+ }
conf->relaycount++;
TAILQ_INIT(&rlay->sessions);
TAILQ_INSERT_HEAD(&conf->relays, rlay, entry);
@@ -885,9 +888,9 @@ relayoptsl : LISTEN ON STRING port optssl {
struct addresslist al;
struct address *h;
- if (rlay->ss.ss_family != AF_UNSPEC) {
+ if (rlay->conf.ss.ss_family != AF_UNSPEC) {
yyerror("relay %s listener already specified",
- rlay->name);
+ rlay->conf.name);
YYERROR;
}
@@ -899,10 +902,10 @@ relayoptsl : LISTEN ON STRING port optssl {
}
free($3);
h = TAILQ_FIRST(&al);
- bcopy(&h->ss, &rlay->ss, sizeof(rlay->ss));
- rlay->port = h->port;
+ bcopy(&h->ss, &rlay->conf.ss, sizeof(rlay->conf.ss));
+ rlay->conf.port = h->port;
if ($5) {
- rlay->flags |= F_SSL;
+ rlay->conf.flags |= F_SSL;
conf->flags |= F_SSL;
}
}
@@ -910,9 +913,9 @@ relayoptsl : LISTEN ON STRING port optssl {
struct addresslist al;
struct address *h;
- if (rlay->dstss.ss_family != AF_UNSPEC) {
+ if (rlay->conf.dstss.ss_family != AF_UNSPEC) {
yyerror("relay %s target or service already "
- "specified", rlay->name);
+ "specified", rlay->conf.name);
free($3);
YYERROR;
}
@@ -925,48 +928,52 @@ relayoptsl : LISTEN ON STRING port optssl {
}
free($3);
h = TAILQ_FIRST(&al);
- bcopy(&h->ss, &rlay->dstss, sizeof(rlay->dstss));
- rlay->dstport = h->port;
- rlay->dstretry = $5;
+ bcopy(&h->ss, &rlay->conf.dstss,
+ sizeof(rlay->conf.dstss));
+ rlay->conf.dstport = h->port;
+ rlay->conf.dstretry = $5;
}
| SERVICE STRING retry {
struct service *svc;
struct address *h;
- if (rlay->dstss.ss_family != AF_UNSPEC) {
+ if (rlay->conf.dstss.ss_family != AF_UNSPEC) {
yyerror("relay %s target or service already "
- "specified", rlay->name);
+ "specified", rlay->conf.name);
free($2);
YYERROR;
}
if ((svc = service_findbyname(conf, $2)) == NULL) {
yyerror("relay %s for unknown service %s",
- rlay->name, $2);
+ rlay->conf.name, $2);
free($2);
YYERROR;
}
free($2);
h = TAILQ_FIRST(&svc->virts);
- bcopy(&h->ss, &rlay->dstss, sizeof(rlay->dstss));
- rlay->dstport = h->port;
- rlay->dstretry = $3;
+ bcopy(&h->ss, &rlay->conf.dstss,
+ sizeof(rlay->conf.dstss));
+ rlay->conf.dstport = h->port;
+ rlay->conf.dstretry = $3;
}
| TABLE STRING dstport dstmode docheck {
struct table *tb;
- rlay->dstport = $3;
- if (rlay->dstport == 0)
- rlay->dstport = rlay->port;
+ rlay->conf.dstport = $3;
+ if (rlay->conf.dstport == 0)
+ rlay->conf.dstport = rlay->conf.port;
- if ((tb = table_inherit($2, rlay->dstport)) == NULL) {
+ if ((tb = table_inherit($2, rlay->conf.dstport)) ==
+ NULL) {
free($2);
YYERROR;
}
free($2);
+ rlay->conf.dsttable = tb->conf.id;
rlay->dsttable = tb;
- rlay->dstmode = $4;
- rlay->dstcheck = $5;
+ rlay->conf.dstmode = $4;
+ rlay->conf.dstcheck = $5;
rlay->dsttable->conf.flags |= F_USED;
}
| PROTO STRING {
@@ -981,15 +988,16 @@ relayoptsl : LISTEN ON STRING port optssl {
YYERROR;
}
p->flags |= F_USED;
+ rlay->conf.proto = p->id;
rlay->proto = p;
free($2);
}
| NAT LOOKUP retry {
- rlay->flags |= F_NATLOOK;
- rlay->dstretry = $3;
+ rlay->conf.flags |= F_NATLOOK;
+ rlay->conf.dstretry = $3;
}
- | TIMEOUT number { rlay->timeout.tv_sec = $2; }
- | DISABLE { rlay->flags |= F_DISABLE; }
+ | TIMEOUT number { rlay->conf.timeout.tv_sec = $2; }
+ | DISABLE { rlay->conf.flags |= F_DISABLE; }
;
dstmode : /* empty */ { $$ = RELAY_DSTMODE_DEFAULT; }
diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c
index 5d05950523e..88a2a84e292 100644
--- a/usr.sbin/relayd/relay.c
+++ b/usr.sbin/relayd/relay.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relay.c,v 1.30 2007/05/28 22:11:33 pyr Exp $ */
+/* $OpenBSD: relay.c,v 1.31 2007/05/29 00:21:10 pyr Exp $ */
/*
* Copyright (c) 2006, 2007 Reyk Floeter <reyk@openbsd.org>
@@ -254,7 +254,7 @@ relay_shutdown(void)
struct relay *rlay;
TAILQ_FOREACH(rlay, &env->relays, entry) {
- if (rlay->flags & F_DISABLE)
+ if (rlay->conf.flags & F_DISABLE)
continue;
close(rlay->s);
while ((con = TAILQ_FIRST(&rlay->sessions)) != NULL)
@@ -359,17 +359,17 @@ relay_privinit(void)
ssl_init(env);
TAILQ_FOREACH(rlay, &env->relays, entry) {
- log_debug("relay_init: adding relay %s", rlay->name);
+ log_debug("relay_init: adding relay %s", rlay->conf.name);
if (debug)
relay_protodebug(rlay);
- if ((rlay->flags & F_SSL) &&
+ if ((rlay->conf.flags & F_SSL) &&
(rlay->ctx = relay_ssl_ctx_create(rlay)) == NULL)
fatal("relay_launch: failed to create SSL context");
- if ((rlay->s = relay_socket_listen(&rlay->ss, rlay->port,
- rlay->proto)) == -1)
+ if ((rlay->s = relay_socket_listen(&rlay->conf.ss,
+ rlay->conf.port, rlay->proto)) == -1)
fatal("relay_launch: failed to listen");
}
}
@@ -383,14 +383,14 @@ relay_init(void)
TAILQ_FOREACH(rlay, &env->relays, entry) {
if (rlay->dsttable != NULL) {
- switch (rlay->dstmode) {
+ switch (rlay->conf.dstmode) {
case RELAY_DSTMODE_ROUNDROBIN:
rlay->dstkey = 0;
break;
case RELAY_DSTMODE_LOADBALANCE:
case RELAY_DSTMODE_HASH:
rlay->dstkey =
- hash32_str(rlay->name, HASHINIT);
+ hash32_str(rlay->conf.name, HASHINIT);
rlay->dstkey =
hash32_str(rlay->dsttable->conf.name,
rlay->dstkey);
@@ -405,7 +405,7 @@ relay_init(void)
}
log_info("adding %d hosts from table %s%s",
rlay->dstnhosts, rlay->dsttable->conf.name,
- rlay->dstcheck ? "" : " (no check)");
+ rlay->conf.dstcheck ? "" : " (no check)");
}
}
@@ -459,7 +459,7 @@ relay_statistics(int fd, short events, void *arg)
if (resetday)
cur->last_day = 0;
- crs.id = rlay->id;
+ crs.id = rlay->conf.id;
crs.proc = proc_id;
imsg_compose(ibuf_pfe, IMSG_STATISTICS, 0, 0,
&crs, sizeof(crs));
@@ -468,7 +468,7 @@ relay_statistics(int fd, short events, void *arg)
con != NULL; con = next_con) {
next_con = TAILQ_NEXT(con, entry);
timersub(&tv_now, &con->tv_last, &tv);
- if (timercmp(&tv, &rlay->timeout, >=))
+ if (timercmp(&tv, &rlay->conf.timeout, >=))
relay_close(con, "hard timeout");
}
}
@@ -485,7 +485,7 @@ relay_launch(void)
struct relay *rlay;
TAILQ_FOREACH(rlay, &env->relays, entry) {
- log_debug("relay_launch: running relay %s", rlay->name);
+ log_debug("relay_launch: running relay %s", rlay->conf.name);
rlay->up = HOST_UP;
@@ -680,7 +680,7 @@ relay_connected(int fd, short sig, void *arg)
con->out.bev = bev;
bufferevent_settimeout(bev,
- rlay->timeout.tv_sec, rlay->timeout.tv_sec);
+ rlay->conf.timeout.tv_sec, rlay->conf.timeout.tv_sec);
bufferevent_enable(bev, EV_READ|EV_WRITE);
}
@@ -723,11 +723,11 @@ relay_input(struct session *con)
}
/* Initialize the SSL wrapper */
- if ((rlay->flags & F_SSL) && con->in.ssl != NULL)
+ if ((rlay->conf.flags & F_SSL) && con->in.ssl != NULL)
relay_ssl_connected(&con->in);
bufferevent_settimeout(con->in.bev,
- rlay->timeout.tv_sec, rlay->timeout.tv_sec);
+ rlay->conf.timeout.tv_sec, rlay->conf.timeout.tv_sec);
bufferevent_enable(con->in.bev, EV_READ|EV_WRITE);
}
@@ -792,21 +792,23 @@ relay_expand_http(struct ctl_relay_event *cre, char *val, char *buf, size_t len)
}
if (strstr(val, "$SERVER_") != NULL) {
if (strstr(val, "$SERVER_ADDR") != NULL) {
- if (relay_host(&rlay->ss, ibuf, sizeof(ibuf)) == NULL)
+ if (relay_host(&rlay->conf.ss,
+ ibuf, sizeof(ibuf)) == NULL)
return (NULL);
if (expand_string(buf, len,
"$SERVER_ADDR", ibuf) != 0)
return (NULL);
}
if (strstr(val, "$SERVER_PORT") != NULL) {
- snprintf(ibuf, sizeof(ibuf), "%u", ntohs(rlay->port));
+ snprintf(ibuf, sizeof(ibuf), "%u",
+ ntohs(rlay->conf.port));
if (expand_string(buf, len,
"$SERVER_PORT", ibuf) != 0)
return (NULL);
}
}
if (strstr(val, "$TIMEOUT") != NULL) {
- snprintf(ibuf, sizeof(ibuf), "%lu", rlay->timeout.tv_sec);
+ snprintf(ibuf, sizeof(ibuf), "%lu", rlay->conf.timeout.tv_sec);
if (expand_string(buf, len, "$TIMEOUT", ibuf) != 0)
return (NULL);
}
@@ -1464,7 +1466,8 @@ relay_accept(int fd, short sig, void *arg)
if ((s = accept(fd, (struct sockaddr *)&ss, (socklen_t *)&slen)) == -1)
return;
- if (relay_sessions >= RELAY_MAX_SESSIONS || rlay->flags & F_DISABLE)
+ if (relay_sessions >= RELAY_MAX_SESSIONS ||
+ rlay->conf.flags & F_DISABLE)
goto err;
if ((con = (struct session *)
@@ -1486,7 +1489,7 @@ relay_accept(int fd, short sig, void *arg)
con->out.tree = &proto->response_tree;
con->in.dir = RELAY_DIR_REQUEST;
con->out.dir = RELAY_DIR_RESPONSE;
- con->retry = rlay->dstretry;
+ con->retry = rlay->conf.dstretry;
if (gettimeofday(&con->tv_start, NULL))
goto err;
bcopy(&con->tv_start, &con->tv_last, sizeof(con->tv_last));
@@ -1506,7 +1509,7 @@ relay_accept(int fd, short sig, void *arg)
return;
}
- if (rlay->flags & F_NATLOOK) {
+ if (rlay->conf.flags & F_NATLOOK) {
if ((cnl = (struct ctl_natlook *)
calloc(1, sizeof(struct ctl_natlook))) == NULL)
goto err;
@@ -1518,19 +1521,19 @@ relay_accept(int fd, short sig, void *arg)
/* Increment the per-relay session counter */
rlay->stats[proc_id].last++;
- if (rlay->flags & F_NATLOOK && cnl != NULL) {
+ if (rlay->conf.flags & F_NATLOOK && cnl != NULL) {
con->cnl = cnl;;
bzero(cnl, sizeof(*cnl));
cnl->in = -1;
cnl->id = con->id;
cnl->proc = proc_id;
bcopy(&con->in.ss, &cnl->src, sizeof(cnl->src));
- bcopy(&rlay->ss, &cnl->dst, sizeof(cnl->dst));
+ bcopy(&rlay->conf.ss, &cnl->dst, sizeof(cnl->dst));
imsg_compose(ibuf_pfe, IMSG_NATLOOK, 0, 0, cnl, sizeof(*cnl));
/* Schedule timeout */
evtimer_set(&con->ev, relay_natlook, con);
- bcopy(&rlay->timeout, &tv, sizeof(tv));
+ bcopy(&rlay->conf.timeout, &tv, sizeof(tv));
evtimer_add(&con->ev, &tv);
return;
}
@@ -1573,12 +1576,12 @@ relay_from_table(struct session *con)
u_int32_t p = con->outkey;
int idx = 0;
- if (rlay->dstcheck && !table->up) {
+ if (rlay->conf.dstcheck && !table->up) {
log_debug("relay_from_table: no active hosts");
return (-1);
}
- switch (rlay->dstmode) {
+ switch (rlay->conf.dstmode) {
case RELAY_DSTMODE_ROUNDROBIN:
if ((int)rlay->dstkey >= rlay->dstnhosts)
rlay->dstkey = 0;
@@ -1588,8 +1591,8 @@ relay_from_table(struct session *con)
p = relay_hash_addr(&con->in.ss, p);
/* FALLTHROUGH */
case RELAY_DSTMODE_HASH:
- p = relay_hash_addr(&rlay->ss, p);
- p = hash32_buf(&rlay->port, sizeof(rlay->port), p);
+ p = relay_hash_addr(&rlay->conf.ss, p);
+ p = hash32_buf(&rlay->conf.port, sizeof(rlay->conf.port), p);
if ((idx = p % rlay->dstnhosts) >= RELAY_MAXHOSTS)
return (-1);
}
@@ -1598,13 +1601,13 @@ relay_from_table(struct session *con)
host->conf.name, p, idx);
while (host != NULL) {
DPRINTF("relay_from_table: host %s", host->conf.name);
- if (!rlay->dstcheck || host->up == HOST_UP)
+ if (!rlay->conf.dstcheck || host->up == HOST_UP)
goto found;
host = TAILQ_NEXT(host, entry);
}
TAILQ_FOREACH(host, &rlay->dsttable->hosts, entry) {
DPRINTF("relay_from_table: next host %s", host->conf.name);
- if (!rlay->dstcheck || host->up == HOST_UP)
+ if (!rlay->conf.dstcheck || host->up == HOST_UP)
goto found;
}
@@ -1630,7 +1633,7 @@ relay_natlook(int fd, short event, void *arg)
fatalx("invalid NAT lookup");
if (con->out.ss.ss_family == AF_UNSPEC && cnl->in == -1 &&
- rlay->dstss.ss_family == AF_UNSPEC && rlay->dsttable == NULL) {
+ rlay->conf.dstss.ss_family == AF_UNSPEC && rlay->dsttable == NULL) {
relay_close(con, "session NAT lookup failed");
return;
}
@@ -1649,15 +1652,15 @@ relay_session(struct session *con)
{
struct relay *rlay = (struct relay *)con->relay;
- if (bcmp(&rlay->ss, &con->out.ss, sizeof(con->out.ss)) == 0 &&
- con->out.port == rlay->port) {
+ if (bcmp(&rlay->conf.ss, &con->out.ss, sizeof(con->out.ss)) == 0 &&
+ con->out.port == rlay->conf.port) {
log_debug("relay_session: session %d: looping",
con->id);
relay_close(con, "session aborted");
return;
}
- if ((rlay->flags & F_SSL) && (con->in.ssl == NULL)) {
+ if ((rlay->conf.flags & F_SSL) && (con->in.ssl == NULL)) {
relay_ssl_transaction(con);
return;
}
@@ -1682,8 +1685,8 @@ relay_connect(struct session *con)
if (relay_from_table(con) != 0)
return (-1);
} else if (con->out.ss.ss_family == AF_UNSPEC) {
- bcopy(&rlay->dstss, &con->out.ss, sizeof(con->out.ss));
- con->out.port = rlay->dstport;
+ bcopy(&rlay->conf.dstss, &con->out.ss, sizeof(con->out.ss));
+ con->out.port = rlay->conf.dstport;
}
retry:
@@ -1734,7 +1737,7 @@ relay_close(struct session *con, const char *msg)
evbuffer_add_printf(con->log, "\r\n") != -1)
ptr = evbuffer_readline(con->log);
log_info("relay %s, session %d (%d active), %s -> %s:%d, "
- "%s%s%s", rlay->name, con->id, relay_sessions,
+ "%s%s%s", rlay->conf.name, con->id, relay_sessions,
ibuf, obuf, ntohs(con->out.port), msg,
ptr == NULL ? "" : ",", ptr == NULL ? "" : ptr);
if (ptr != NULL)
@@ -1955,7 +1958,7 @@ relay_ssl_ctx_create(struct relay *rlay)
goto err;
/* Modify session timeout and cache size*/
- SSL_CTX_set_timeout(ctx, rlay->timeout.tv_sec);
+ SSL_CTX_set_timeout(ctx, rlay->conf.timeout.tv_sec);
if (proto->cache < -1) {
SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF);
} else if (proto->cache >= -1) {
@@ -1983,7 +1986,7 @@ relay_ssl_ctx_create(struct relay *rlay)
if (!SSL_CTX_set_cipher_list(ctx, ciphers))
goto err;
- if (relay_host(&rlay->ss, hbuf, sizeof(hbuf)) == NULL)
+ if (relay_host(&rlay->conf.ss, hbuf, sizeof(hbuf)) == NULL)
goto err;
/* Load the certificate */
@@ -2006,8 +2009,8 @@ relay_ssl_ctx_create(struct relay *rlay)
goto err;
/* Set session context to the local relay name */
- if (!SSL_CTX_set_session_id_context(ctx, rlay->name,
- strlen(rlay->name)))
+ if (!SSL_CTX_set_session_id_context(ctx, rlay->conf.name,
+ strlen(rlay->conf.name)))
goto err;
return (ctx);
@@ -2015,7 +2018,7 @@ relay_ssl_ctx_create(struct relay *rlay)
err:
if (ctx != NULL)
SSL_CTX_free(ctx);
- ssl_error(rlay->name, "relay_ssl_ctx_create");
+ ssl_error(rlay->conf.name, "relay_ssl_ctx_create");
return (NULL);
}
@@ -2044,7 +2047,7 @@ relay_ssl_transaction(struct session *con)
err:
if (ssl != NULL)
SSL_free(ssl);
- ssl_error(rlay->name, "relay_ssl_transaction");
+ ssl_error(rlay->conf.name, "relay_ssl_transaction");
}
void
@@ -2082,7 +2085,7 @@ relay_ssl_accept(int fd, short event, void *arg)
}
/* FALLTHROUGH */
default:
- ssl_error(rlay->name, "relay_ssl_accept");
+ ssl_error(rlay->conf.name, "relay_ssl_accept");
relay_close(con, "SSL accept error");
return;
}
@@ -2091,10 +2094,10 @@ relay_ssl_accept(int fd, short event, void *arg)
#ifdef DEBUG
log_info("relay %s, session %d established (%d active)",
- rlay->name, con->id, relay_sessions);
+ rlay->conf.name, con->id, relay_sessions);
#else
log_debug("relay %s, session %d established (%d active)",
- rlay->name, con->id, relay_sessions);
+ rlay->conf.name, con->id, relay_sessions);
#endif
relay_session(con);
return;
@@ -2157,7 +2160,7 @@ relay_ssl_readcb(int fd, short event, void *arg)
if (ret == 0)
what |= EVBUFFER_EOF;
else {
- ssl_error(rlay->name, "relay_ssl_readcb");
+ ssl_error(rlay->conf.name, "relay_ssl_readcb");
what |= EVBUFFER_ERROR;
}
goto err;
@@ -2236,7 +2239,7 @@ relay_ssl_writecb(int fd, short event, void *arg)
if (ret == 0)
what |= EVBUFFER_EOF;
else {
- ssl_error(rlay->name,
+ ssl_error(rlay->conf.name,
"relay_ssl_writecb");
what |= EVBUFFER_ERROR;
}
diff --git a/usr.sbin/relayd/relayd.c b/usr.sbin/relayd/relayd.c
index a9743252d37..94a938c74ea 100644
--- a/usr.sbin/relayd/relayd.c
+++ b/usr.sbin/relayd/relayd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.c,v 1.24 2007/05/28 22:11:33 pyr Exp $ */
+/* $OpenBSD: relayd.c,v 1.25 2007/05/29 00:21:10 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -596,7 +596,7 @@ relay_find(struct hoststated *env, objid_t id)
struct relay *rlay;
TAILQ_FOREACH(rlay, &env->relays, entry)
- if (rlay->id == id)
+ if (rlay->conf.id == id)
return (rlay);
return (NULL);
}
@@ -655,7 +655,7 @@ relay_findbyname(struct hoststated *env, const char *name)
struct relay *rlay;
TAILQ_FOREACH(rlay, &env->relays, entry)
- if (strcmp(rlay->name, name) == 0)
+ if (strcmp(rlay->conf.name, name) == 0)
return (rlay);
return (NULL);
}
diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h
index e62c7e2599d..ed67b456dcc 100644
--- a/usr.sbin/relayd/relayd.h
+++ b/usr.sbin/relayd/relayd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.h,v 1.45 2007/05/28 22:11:33 pyr Exp $ */
+/* $OpenBSD: relayd.h,v 1.46 2007/05/29 00:21:10 pyr Exp $ */
/*
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -469,38 +469,44 @@ struct protocol {
};
TAILQ_HEAD(protolist, protocol);
-struct relay {
+struct relay_config {
objid_t id;
u_int16_t flags;
- int up;
- struct protocol *proto;
+ objid_t proto;
char name[MAXHOSTNAMELEN];
- int s;
in_port_t port;
+ in_port_t dstport;
+ int dstmode;
+ int dstcheck;
+ int dstretry;
+ objid_t dsttable;
struct sockaddr_storage ss;
+ struct sockaddr_storage dstss;
+ struct timeval timeout;
+};
+
+struct relay {
+ TAILQ_ENTRY(relay) entry;
+ struct relay_config conf;
+ int up;
+ struct protocol *proto;
+ int s;
struct bufferevent *bev;
int dsts;
- in_port_t dstport;
- struct sockaddr_storage dstss;
struct bufferevent *dstbev;
struct table *dsttable;
u_int32_t dstkey;
struct host *dsthost[RELAY_MAXHOSTS];
int dstnhosts;
- int dstmode;
- int dstcheck;
- int dstretry;
struct event ev;
- struct timeval timeout;
SSL_CTX *ctx;
struct ctl_stats stats[RELAY_MAXPROC + 1];
struct sessionlist sessions;
- TAILQ_ENTRY(relay) entry;
};
TAILQ_HEAD(relaylist, relay);