Hello misc@, Filter writers, please read below carefully.
Part 2 of the adding loglevel support to filters is to keep them up to date with the loglevel of smtpd. The reasoning is that sending lines to smtpd, only to get discarded there is pointless use of cpu cycles. The problem here is that we need to deviate from the current config sending semantics. Right now smtpd broadcasts its config at startup and closes with a config|ready. After this no updates are send. This diff would allow a config update to be send at any point when smtpctl changes the loglevel/filter tracing. The phrasing in smtpd-filters.7 leaves room for this behaviour, but I can imagine not everyone interprets the text this way. I've talked with kirill@ about this and he thinks that restarting the filters might be a safer option, but I think the logistical changes needed to achieve this, including the scenario where a mail transfer is in progress when the loglevel change is made are too much and I expect the diff below is unlikely to break existing filters, but right now I'm not certain. What are people's opinions on this change? martijn@ diff acdf9909bf270b4d19c207f705c0e1bef68c8cc1 113783995d872c9321aad6b7a4017b20a89d9c1c commit - acdf9909bf270b4d19c207f705c0e1bef68c8cc1 commit + 113783995d872c9321aad6b7a4017b20a89d9c1c blob - 6b08adde4f558aa96d67233b20d869b9deb58e35 blob + db58a8b9b6abe0fb1eb03e864808ae5b9b9bc9ed --- usr.sbin/smtpd/lka.c +++ usr.sbin/smtpd/lka.c @@ -318,6 +318,7 @@ lka_imsg(struct mproc *p, struct imsg *imsg) m_get_int(&m, &v); m_end(&m); log_trace_verbose(v); + lka_proc_setverbose(NULL); return; case IMSG_CTL_PROFILE: blob - cbd8657110f1cac373d7964c20b9fca57fc17ec1 blob + c8c6ee91b10bb6c7be8c8a4f4133baac0a8ce856 --- usr.sbin/smtpd/lka_filter.c +++ usr.sbin/smtpd/lka_filter.c @@ -201,6 +201,7 @@ lka_proc_config(struct processor_instance *pi) io_printf(pi->io, "config|subsystem|smtp-out\n"); io_printf(pi->io, "config|admd|%s\n", env->sc_admd != NULL ? env->sc_admd : env->sc_hostname); + lka_proc_setverbose(pi); io_printf(pi->io, "config|ready\n"); } @@ -252,6 +253,27 @@ lka_proc_get_io(const char *name) return processor->io; } +void +lka_proc_setverbose(struct processor_instance *pi) +{ + void *iter = NULL; + const char *level = NULL; + + if (tracing & TRACE_DEBUG) + level = "verbose"; + else + level = "brief"; + + if (pi != NULL) + io_printf(pi->io, "config|loglevel|%s%s\n", level, + tracing & TRACE_FILTERS ? "|trace" : ""); + else { + while (dict_iter(&processors, &iter, NULL, (void **)&pi)) + io_printf(pi->io, "config|loglevel|%s%s\n", level, + tracing & TRACE_FILTERS ? "|trace" : ""); + } +} + static void processor_register(const char *name, const char *line) { blob - d5636b55abfd4bc86cd865851f4b9aa0cb9f2759 blob + 7996a74a4a161a799b579800eb18d6c5399463b0 --- usr.sbin/smtpd/smtpd-filters.7 +++ usr.sbin/smtpd/smtpd-filters.7 @@ -179,12 +179,14 @@ The list is meant to be ignored by .Nm that do not require it and consumed gracefully by filters that do. .Pp -There are currently three keys: +There are currently six keys: .Bd -literal -offset indent config|smtpd-version|7.5.0 config|protocol|0.7 config|smtp-session-timeout|300 config|subsystem|smtp-in +config|admd|mail.opensmtpd.org +config|loglevel|verbose|trace .Ed .Pp When @@ -193,6 +195,12 @@ has sent all configuration keys, it emits the followin .Bd -literal -offset indent config|ready .Ed +.Pp +loglevel can have a value of brief or verbose and may have an optional trace +argument if the filters trace is enabled. +The loglevel can be send after config|ready if the loglevel or tracing is +changed via +.Xr smtpctl 8 . .Sh REPORT EVENTS There is currently only one subsystem supported in the API: smtp-in. blob - a5f06c0f3629e0d04bee081350c4e75fc0ae3ce9 blob + 79a6ed0aa46a0507a7b61d12133f0a33ad3c9c9a --- usr.sbin/smtpd/smtpd.h +++ usr.sbin/smtpd/smtpd.h @@ -1353,10 +1353,12 @@ int lka(void); /* lka_proc.c */ +struct processor_instance; int lka_proc_ready(void); void lka_proc_forked(const char *, uint32_t, int); void lka_proc_errfd(const char *, int); struct io *lka_proc_get_io(const char *); +void lka_proc_setverbose(struct processor_instance *); /* lka_report.c */