diff options
Diffstat (limited to 'usr.sbin/relayd')
-rw-r--r-- | usr.sbin/relayd/hce.c | 3 | ||||
-rw-r--r-- | usr.sbin/relayd/pfe.c | 3 | ||||
-rw-r--r-- | usr.sbin/relayd/relay.c | 3 | ||||
-rw-r--r-- | usr.sbin/relayd/relayd.c | 82 | ||||
-rw-r--r-- | usr.sbin/relayd/relayd.h | 9 |
5 files changed, 95 insertions, 5 deletions
diff --git a/usr.sbin/relayd/hce.c b/usr.sbin/relayd/hce.c index 8ae3c42110d..0110dfe7d22 100644 --- a/usr.sbin/relayd/hce.c +++ b/usr.sbin/relayd/hce.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hce.c,v 1.20 2007/05/27 20:53:10 pyr Exp $ */ +/* $OpenBSD: hce.c,v 1.21 2007/05/28 22:11:33 pyr Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -85,6 +85,7 @@ hce(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2], } env = x_env; + purge_config(env, PURGE_SERVICES|PURGE_RELAYS|PURGE_PROTOS); if ((pw = getpwnam(HOSTSTATED_USER)) == NULL) fatal("hce: getpwnam"); diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c index 738ffc1952c..a60f06c6b56 100644 --- a/usr.sbin/relayd/pfe.c +++ b/usr.sbin/relayd/pfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfe.c,v 1.23 2007/05/27 20:53:10 pyr Exp $ */ +/* $OpenBSD: pfe.c,v 1.24 2007/05/28 22:11:33 pyr Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -84,6 +84,7 @@ pfe(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2], } env = x_env; + purge_config(env, PURGE_PROTOS); if (control_init() == -1) fatalx("pfe: control socket setup failed"); diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c index 8b5fa3b1906..5d05950523e 100644 --- a/usr.sbin/relayd/relay.c +++ b/usr.sbin/relayd/relay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay.c,v 1.29 2007/05/27 20:53:10 pyr Exp $ */ +/* $OpenBSD: relay.c,v 1.30 2007/05/28 22:11:33 pyr Exp $ */ /* * Copyright (c) 2006, 2007 Reyk Floeter <reyk@openbsd.org> @@ -159,6 +159,7 @@ relay(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2], } env = x_env; + purge_config(env, PURGE_SERVICES); /* Need root privileges for relay initialization */ relay_privinit(); diff --git a/usr.sbin/relayd/relayd.c b/usr.sbin/relayd/relayd.c index cb444015483..a9743252d37 100644 --- a/usr.sbin/relayd/relayd.c +++ b/usr.sbin/relayd/relayd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relayd.c,v 1.23 2007/05/27 20:53:10 pyr Exp $ */ +/* $OpenBSD: relayd.c,v 1.24 2007/05/28 22:11:33 pyr Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -333,6 +333,86 @@ send_all(struct hoststated *env, enum imsg_type type, void *buf, u_int16_t len) } void +purge_config(struct hoststated *env, u_int8_t what) +{ + struct table *table; + struct host *host; + struct service *service; + struct address *virt; + struct protocol *proto; + struct protonode *pnode; + struct relay *rly; + + if (what & PURGE_SERVICES) { + while ((service = TAILQ_FIRST(&env->services)) != NULL) { + TAILQ_REMOVE(&env->services, service, entry); + while ((virt = TAILQ_FIRST(&service->virts)) != NULL) { + TAILQ_REMOVE(&service->virts, virt, entry); + free(virt); + } + free(service); + } + } + + if (what & PURGE_RELAYS) { + while ((rly = TAILQ_FIRST(&env->relays)) != NULL) { + TAILQ_REMOVE(&env->relays, rly, entry); + if (rly->bev != NULL) + bufferevent_free(rly->bev); + if (rly->dstbev != NULL) + bufferevent_free(rly->dstbev); + if (rly->ctx != NULL) + SSL_CTX_free(rly->ctx); + free(rly); + } + } + + if (what & PURGE_PROTOS) { + while ((proto = TAILQ_FIRST(&env->protos)) != NULL) { + TAILQ_REMOVE(&env->protos, proto, entry); + if (proto == &env->proto_default) + continue; + while ((pnode = RB_ROOT(&proto->request_tree)) + != NULL) { + RB_REMOVE(proto_tree, &proto->request_tree, + pnode); + if (pnode->key != NULL) + free(pnode->key); + if (pnode->value != NULL) + free(pnode->value); + free(pnode); + } + while ((pnode = RB_ROOT(&proto->response_tree)) + != NULL) { + RB_REMOVE(proto_tree, &proto->response_tree, + pnode); + if (pnode->key != NULL) + free(pnode->key); + if (pnode->value != NULL) + free(pnode->value); + free(pnode); + } + free(proto); + } + } + + if (what & PURGE_TABLES) { + while ((table = TAILQ_FIRST(&env->tables)) != NULL) { + TAILQ_REMOVE(&env->tables, table, entry); + while ((host = TAILQ_FIRST(&table->hosts)) != NULL) { + TAILQ_REMOVE(&table->hosts, host, entry); + free(host); + } + if (table->sendbuf != NULL) + free(table->sendbuf); + if (table->ssl_ctx != NULL) + SSL_CTX_free(table->ssl_ctx); + free(table); + } + } +} + +void imsg_event_add(struct imsgbuf *ibuf) { ibuf->events = EV_READ; diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h index e1abb411607..e62c7e2599d 100644 --- a/usr.sbin/relayd/relayd.h +++ b/usr.sbin/relayd/relayd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: relayd.h,v 1.44 2007/05/28 17:37:16 pyr Exp $ */ +/* $OpenBSD: relayd.h,v 1.45 2007/05/28 22:11:33 pyr Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -48,6 +48,12 @@ #define READ_BUF_SIZE 65535 #define ICMP_BUF_SIZE 64 +#define PURGE_TABLES 0x01 +#define PURGE_SERVICES 0x02 +#define PURGE_RELAYS 0x04 +#define PURGE_PROTOS 0x08 +#define PURGE_EVERYTHING 0xff + /* buffer */ struct buf { TAILQ_ENTRY(buf) entry; @@ -683,6 +689,7 @@ struct relay *relay_find(struct hoststated *, objid_t); struct session *session_find(struct hoststated *, objid_t); struct relay *relay_findbyname(struct hoststated *, const char *); int expand_string(char *, size_t, const char *, const char *); +void purge_config(struct hoststated *, u_int8_t); /* carp.c */ int carp_demote_init(char *, int); |