Skip to content

Commit

Permalink
introduce smtp 'timeout' reporting event to notify filters that a tim…
Browse files Browse the repository at this point in the history
…eout

occured during the smtp session
  • Loading branch information
poolpOrg committed Jan 5, 2019
1 parent 275804a commit 760deba
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
11 changes: 10 additions & 1 deletion usr.sbin/smtpd/lka.c
@@ -1,4 +1,4 @@
/* $OpenBSD: lka.c,v 1.232 2018/12/28 11:40:29 eric Exp $ */
/* $OpenBSD: lka.c,v 1.233 2019/01/05 09:43:39 gilles Exp $ */

/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
Expand Down Expand Up @@ -529,6 +529,15 @@ lka_imsg(struct mproc *p, struct imsg *imsg)
filter_phase, filter_response, filter_param);
return;

case IMSG_REPORT_SMTP_TIMEOUT:
m_msg(&m, imsg);
m_get_string(&m, &direction);
m_get_timeval(&m, &tv);
m_get_id(&m, &reqid);
m_end(&m);

lka_report_smtp_timeout(direction, &tv, reqid);
return;

case IMSG_FILTER_SMTP_PROTOCOL:
m_msg(&m, imsg);
Expand Down
12 changes: 11 additions & 1 deletion usr.sbin/smtpd/lka_report.c
@@ -1,4 +1,4 @@
/* $OpenBSD: lka_report.c,v 1.16 2018/12/21 14:33:52 gilles Exp $ */
/* $OpenBSD: lka_report.c,v 1.17 2019/01/05 09:43:39 gilles Exp $ */

/*
* Copyright (c) 2018 Gilles Chehade <gilles@poolp.org>
Expand Down Expand Up @@ -66,6 +66,8 @@ static struct smtp_events {
{ "protocol-server" },

{ "filter-response" },

{ "timeout" },
};


Expand Down Expand Up @@ -408,3 +410,11 @@ lka_report_smtp_filter_response(const char *direction, struct timeval *tv, uint6
"%016"PRIx64"|%s|%s%s%s\n",
reqid, phase_name, response_name, param ? "|" : "", param ? param : "");
}

void
lka_report_smtp_timeout(const char *direction, struct timeval *tv, uint64_t reqid)
{
report_smtp_broadcast(reqid, direction, tv, "timeout",
"%016"PRIx64"\n",
reqid);
}
16 changes: 15 additions & 1 deletion usr.sbin/smtpd/report_smtp.c
@@ -1,4 +1,4 @@
/* $OpenBSD: report_smtp.c,v 1.3 2018/12/13 17:08:10 gilles Exp $ */
/* $OpenBSD: report_smtp.c,v 1.4 2019/01/05 09:43:39 gilles Exp $ */

/*
* Copyright (c) 2018 Gilles Chehade <gilles@poolp.org>
Expand Down Expand Up @@ -265,3 +265,17 @@ report_smtp_filter_response(const char *direction, uint64_t qid, int phase, int
m_add_string(p_lka, param);
m_close(p_lka);
}

void
report_smtp_timeout(const char *direction, uint64_t qid)
{
struct timeval tv;

gettimeofday(&tv, NULL);

m_create(p_lka, IMSG_REPORT_SMTP_TIMEOUT, 0, 0, -1);
m_add_string(p_lka, direction);
m_add_timeval(p_lka, &tv);
m_add_id(p_lka, qid);
m_close(p_lka);
}
3 changes: 2 additions & 1 deletion usr.sbin/smtpd/smtp_session.c
@@ -1,4 +1,4 @@
/* $OpenBSD: smtp_session.c,v 1.386 2019/01/05 08:38:41 gilles Exp $ */
/* $OpenBSD: smtp_session.c,v 1.387 2019/01/05 09:43:39 gilles Exp $ */

/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
Expand Down Expand Up @@ -1148,6 +1148,7 @@ smtp_io(struct io *io, int evt, void *arg)
log_info("%016"PRIx64" smtp disconnected "
"reason=timeout",
s->id);
report_smtp_timeout("smtp-in", s->id);
smtp_free(s, "timeout");
break;

Expand Down
8 changes: 6 additions & 2 deletions usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
/* $OpenBSD: smtpd.h,v 1.615 2018/12/28 15:09:28 eric Exp $ */
/* $OpenBSD: smtpd.h,v 1.616 2019/01/05 09:43:39 gilles Exp $ */

/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
Expand Down Expand Up @@ -52,7 +52,8 @@
#define SMTPD_SOCKET "/var/run/smtpd.sock"
#define SMTPD_NAME "OpenSMTPD"
#define SMTPD_VERSION "6.4.0"
#define SMTPD_SESSION_TIMEOUT 300
//#define SMTPD_SESSION_TIMEOUT 300
#define SMTPD_SESSION_TIMEOUT 30
#define SMTPD_BACKLOG 5

#define PATH_SMTPCTL "/usr/sbin/smtpctl"
Expand Down Expand Up @@ -319,6 +320,7 @@ enum imsg_type {
IMSG_REPORT_SMTP_PROTOCOL_CLIENT,
IMSG_REPORT_SMTP_PROTOCOL_SERVER,
IMSG_REPORT_SMTP_FILTER_RESPONSE,
IMSG_REPORT_SMTP_TIMEOUT,

IMSG_FILTER_SMTP_BEGIN,
IMSG_FILTER_SMTP_END,
Expand Down Expand Up @@ -1356,6 +1358,7 @@ void lka_report_smtp_protocol_client(const char *, struct timeval *, uint64_t, c
void lka_report_smtp_protocol_server(const char *, struct timeval *, uint64_t, const char *);
void lka_report_smtp_filter_response(const char *, struct timeval *, uint64_t,
int, int, const char *);
void lka_report_smtp_timeout(const char *, struct timeval *, uint64_t);


/* lka_filter.c */
Expand Down Expand Up @@ -1521,6 +1524,7 @@ void report_smtp_tx_rollback(const char *, uint64_t, uint32_t);
void report_smtp_protocol_client(const char *, uint64_t, const char *);
void report_smtp_protocol_server(const char *, uint64_t, const char *);
void report_smtp_filter_response(const char *, uint64_t, int, int, const char *);
void report_smtp_timeout(const char *, uint64_t);


/* ruleset.c */
Expand Down

0 comments on commit 760deba

Please sign in to comment.