-/* $OpenBSD: relay.c,v 1.235 2017/11/28 01:24:22 claudio Exp $ */
+/* $OpenBSD: relay.c,v 1.236 2017/11/28 01:51:47 claudio Exp $ */
/*
* Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
(*proto->close)(con);
free(con->se_priv);
- if (con->se_in.bev != NULL)
- bufferevent_free(con->se_in.bev);
- if (con->se_in.output != NULL)
- evbuffer_free(con->se_in.output);
- if (con->se_in.tls != NULL)
- tls_close(con->se_in.tls);
- tls_free(con->se_in.tls);
- tls_free(con->se_in.tls_ctx);
- tls_config_free(con->se_in.tls_cfg);
- free(con->se_in.tlscert);
- if (con->se_in.s != -1) {
- close(con->se_in.s);
+
+ if (relay_reset_event(&con->se_in)) {
if (con->se_out.s == -1) {
/*
* the output was never connected,
__func__, relay_inflight);
}
}
+ if (con->se_in.output != NULL)
+ evbuffer_free(con->se_in.output);
- if (con->se_out.bev != NULL)
- bufferevent_free(con->se_out.bev);
- if (con->se_out.output != NULL)
- evbuffer_free(con->se_out.output);
- if (con->se_out.tls != NULL)
- tls_close(con->se_out.tls);
- tls_free(con->se_out.tls);
- tls_free(con->se_out.tls_ctx);
- tls_config_free(con->se_out.tls_cfg);
- free(con->se_out.tlscert);
- if (con->se_out.s != -1) {
- close(con->se_out.s);
-
+ if (relay_reset_event(&con->se_out)) {
/* Some file descriptors are available again. */
if (evtimer_pending(&rlay->rl_evt, NULL)) {
evtimer_del(&rlay->rl_evt);
event_add(&rlay->rl_ev, NULL);
}
}
- con->se_out.state = STATE_INIT;
+ if (con->se_out.output != NULL)
+ evbuffer_free(con->se_out.output);
if (con->se_log != NULL)
evbuffer_free(con->se_log);
relay_sessions--;
}
+int
+relay_reset_event(struct ctl_relay_event *cre)
+{
+ int rv = 0;
+
+ DPRINTF("%s: state %d dir %d", __func__, cre->state, cre->dir);
+
+ if (cre->bev != NULL)
+ bufferevent_free(cre->bev);
+ if (cre->tls != NULL)
+ tls_close(cre->tls);
+ tls_free(cre->tls);
+ tls_free(cre->tls_ctx);
+ tls_config_free(cre->tls_cfg);
+ free(cre->tlscert);
+ if (cre->s != -1) {
+ close(cre->s);
+ rv = 1;
+ }
+ cre->state = STATE_DONE;
+ cre->bev = NULL;
+ cre->tls = NULL;
+ cre->tls_cfg = NULL;
+ cre->tlscert = NULL;
+ cre->s = -1;
+
+ return (rv);
+}
+
int
relay_dispatch_pfe(int fd, struct privsep_proc *p, struct imsg *imsg)
{
-/* $OpenBSD: relayd.h,v 1.246 2017/11/28 01:24:22 claudio Exp $ */
+/* $OpenBSD: relayd.h,v 1.247 2017/11/28 01:51:47 claudio Exp $ */
/*
* Copyright (c) 2006 - 2016 Reyk Floeter <reyk@openbsd.org>
STATE_INIT,
STATE_PENDING,
STATE_PRECONNECT,
- STATE_CONNECTED
+ STATE_CONNECTED,
+ STATE_DONE
};
struct ctl_relay_event {
char *relay_load_fd(int, off_t *);
int relay_load_certfiles(struct relay *);
void relay_close(struct rsession *, const char *);
+int relay_reset_event(struct ctl_relay_event *);
void relay_natlook(int, short, void *);
void relay_session(struct rsession *);
int relay_from_table(struct rsession *);