Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
smtpd: allow braces for `listen' options
To:
tech@openbsd.org
Date:
Sun, 13 Oct 2024 23:43:48 +0200

Download raw body.

Thread
We currently require to list all the options for `listen' in a single
line, so it's custom to see config like this:

	listen on all tls \
		pki mx.example.org \
		pki mx.example.com \
		auth <auth> \
		filter "whatnot"

(or worse, all on a single physical line)

This has the annoying consequence of breaking comments, since they would
extend to the end of the (logical) line.  And it's also a bit ugly.

So, why don't allow for brances to group the options?  IMHO this reads
better and is easier to write/maintain for newbies as well as well as
for seasoned users:

	listen on all {
		tls # now with comments!
		pki mx.example.org
		pki mx.example.com
		auth <auth>
		filter "whatnot"
	}

These will be optional, as well as the newlines between the options.

I'm intentionally not breaking the grammar; previous configurations will
continue to work as they do today.  I'm just adding a couple of rules to
handle the braces and the optional newlines (which are only valid inside
the braces)

(the example on the manpage didn't really need the braces, but I wanted
to also show them off a bit in the EXAMPLE section.)

thoughs?


diff /usr/src
commit - d5a0147d3554fff24ce29b178fea01ec089ce0f8
path + /usr/src
blob - b4cf1f21ddb02dce7a4911285e33eebfcf517067
file + usr.sbin/smtpd/parse.y
--- usr.sbin/smtpd/parse.y
+++ usr.sbin/smtpd/parse.y
@@ -2496,7 +2496,7 @@ listener_type	: socket_listener
 		| if_listener
 		;
 
-socket_listener	: SOCKET sock_listen {
+socket_listener	: SOCKET sock_listen_l {
 			if (conf->sc_sock_listener) {
 				yyerror("socket listener already configured");
 				YYERROR;
@@ -2505,21 +2505,36 @@ socket_listener	: SOCKET sock_listen {
 		}
 		;
 
-if_listener	: STRING if_listen {
+if_listener	: STRING if_listen_l {
 			listen_opts.ifx = $1;
 			create_if_listener(&listen_opts);
 		}
 		;
 
-sock_listen	: opt_sock_listen sock_listen
+sock_listen_l	: '{' optnl sock_listen_nl '}'
+		| sock_listen
+		;
+
+sock_listen_nl	: sock_listen_nl opt_sock_listen optnl
 		| /* empty */
 		;
 
-if_listen	: opt_if_listen if_listen
+sock_listen	: sock_listen opt_sock_listen
 		| /* empty */
 		;
 
+if_listen_l	: '{' optnl if_listen_nl '}'
+		| if_listen
+		;
 
+if_listen_nl	: if_listen_nl opt_if_listen optnl
+		| /* empty */
+		;
+
+if_listen	: if_listen opt_if_listen
+		| /* empty */
+		;
+
 listen		: LISTEN {
 			memset(&listen_opts, 0, sizeof listen_opts);
 			listen_opts.family = AF_UNSPEC;
blob - 3d73b5a064776c1f63bd1eb0366af23f19955078
file + usr.sbin/smtpd/smtpd.conf.5
--- usr.sbin/smtpd/smtpd.conf.5
+++ usr.sbin/smtpd/smtpd.conf.5
@@ -442,6 +442,7 @@ which can be either
 or
 .Cm inet6 .
 .Pp
+Multiple options may be specified within curly braces.
 The
 .Ar options
 are as follows:
@@ -568,6 +569,7 @@ Listen for incoming SMTP connections on the Unix domai
 .Pa /var/run/smtpd.sock .
 This is done by default, even if the directive is absent.
 .Pp
+Multiple options may be specified within curly braces.
 The
 .Ar options
 are as follows:
@@ -1267,7 +1269,11 @@ pki mail.example.com key "/etc/ssl/private/mail.exampl
 table aliases file:/etc/mail/aliases
 
 listen on lo0
-listen on egress tls pki mail.example.com auth
+listen on egress {
+	tls
+	pki mail.example.com
+	auth
+}
 
 action mda_with_aliases mda "/path/to/mda \-f \-" alias <aliases>
 action mda_without_aliases mda "/path/to/mda \-f \-"