diff options
author | 2018-12-09 16:37:51 +0000 | |
---|---|---|
committer | 2018-12-09 16:37:51 +0000 | |
commit | 486f188e41b76564339c3f67b8e24ef12079f1f5 (patch) | |
tree | d17505348232f7a3dc1974d7c8351ea19cd8eeac | |
parent | when doing the rDNS lookup, require getnameinfo to return a hostname not an (diff) | |
download | wireguard-openbsd-486f188e41b76564339c3f67b8e24ef12079f1f5.tar.xz wireguard-openbsd-486f188e41b76564339c3f67b8e24ef12079f1f5.zip |
add client and listener address, as well as client rDNS and FCrDNS lookup
result to the filter_session structure upon filter session allocation. it
will allow me to simplify all filter hooks.
-rw-r--r-- | usr.sbin/smtpd/lka.c | 8 | ||||
-rw-r--r-- | usr.sbin/smtpd/lka_filter.c | 22 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtp_session.c | 6 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 4 |
4 files changed, 33 insertions, 7 deletions
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c index 24141e24407..a06d07f9ad6 100644 --- a/usr.sbin/smtpd/lka.c +++ b/usr.sbin/smtpd/lka.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka.c,v 1.219 2018/12/07 08:05:59 eric Exp $ */ +/* $OpenBSD: lka.c,v 1.220 2018/12/09 16:37:51 gilles Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -670,9 +670,13 @@ lka_imsg(struct mproc *p, struct imsg *imsg) case IMSG_SMTP_FILTER_BEGIN: m_msg(&m, imsg); m_get_id(&m, &reqid); + m_get_sockaddr(&m, (struct sockaddr *)&ss_src); + m_get_sockaddr(&m, (struct sockaddr *)&ss_dest); + m_get_string(&m, &rdns); + m_get_int(&m, &fcrdns); m_end(&m); - lka_filter_begin(reqid); + lka_filter_begin(reqid, &ss_src, &ss_dest, rdns, fcrdns); return; case IMSG_SMTP_FILTER_END: diff --git a/usr.sbin/smtpd/lka_filter.c b/usr.sbin/smtpd/lka_filter.c index 7f68929598f..d94b659a88a 100644 --- a/usr.sbin/smtpd/lka_filter.c +++ b/usr.sbin/smtpd/lka_filter.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka_filter.c,v 1.7 2018/12/06 13:57:06 gilles Exp $ */ +/* $OpenBSD: lka_filter.c,v 1.8 2018/12/09 16:37:51 gilles Exp $ */ /* * Copyright (c) 2018 Gilles Chehade <gilles@poolp.org> @@ -82,10 +82,19 @@ static int inited; struct filter_session { uint64_t id; struct io *io; + + struct sockaddr_storage ss_src; + struct sockaddr_storage ss_dest; + char *rdns; + int fcrdns; }; void -lka_filter_begin(uint64_t reqid) +lka_filter_begin(uint64_t reqid, + const struct sockaddr_storage *ss_src, + const struct sockaddr_storage *ss_dest, + const char *rdns, + int fcrdns) { struct filter_session *fs; @@ -96,6 +105,10 @@ lka_filter_begin(uint64_t reqid) fs = xcalloc(1, sizeof (struct filter_session)); fs->id = reqid; + fs->ss_src = *ss_src; + fs->ss_dest = *ss_dest; + fs->rdns = xstrdup(rdns); + fs->fcrdns = fcrdns; tree_xset(&sessions, fs->id, fs); } @@ -105,6 +118,7 @@ lka_filter_end(uint64_t reqid) struct filter_session *fs; fs = tree_xpop(&sessions, reqid); + free(fs->rdns); free(fs); } @@ -454,6 +468,10 @@ filter_exec_notimpl(uint64_t reqid, struct filter_rule *rule, const char *hostna static int filter_exec_connected(uint64_t reqid, struct filter_rule *rule, const char *hostname, const char *param) { + struct filter_session *fs; + + fs = tree_xget(&sessions, reqid); + if (filter_check_table(rule, K_NETADDR, param) || filter_check_regex(rule, param) || filter_check_rdns_connected(rule, hostname)) diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c index 63cb9e23896..761c94f658b 100644 --- a/usr.sbin/smtpd/smtp_session.c +++ b/usr.sbin/smtpd/smtp_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtp_session.c,v 1.363 2018/12/09 15:26:03 gilles Exp $ */ +/* $OpenBSD: smtp_session.c,v 1.364 2018/12/09 16:37:51 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -1604,6 +1604,10 @@ smtp_filter_begin(struct smtp_session *s) m_create(p_lka, IMSG_SMTP_FILTER_BEGIN, 0, 0, -1); m_add_id(p_lka, s->id); + m_add_sockaddr(p_lka, (struct sockaddr *)&s->ss); + m_add_sockaddr(p_lka, (struct sockaddr *)&s->listener->ss); + m_add_string(p_lka, s->hostname); + m_add_int(p_lka, s->fcrdns); m_close(p_lka); } diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index eda1aee11c5..1c87484dfd3 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.582 2018/12/08 08:01:15 sunil Exp $ */ +/* $OpenBSD: smtpd.h,v 1.583 2018/12/09 16:37:51 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -1344,7 +1344,7 @@ void lka_report_smtp_protocol_server(const char *, time_t, uint64_t, const char /* lka_filter.c */ -void lka_filter_begin(uint64_t); +void lka_filter_begin(uint64_t, const struct sockaddr_storage *, const struct sockaddr_storage *, const char *, int); void lka_filter_end(uint64_t); void lka_filter_protocol(uint64_t, enum filter_phase, const char *, const char *); void lka_filter_data_begin(uint64_t); |