Page MenuHomeFreeBSD

pfctl: Allow a semicolon (;) as a comment
ClosedPublic

Authored by otis on Jul 23 2024, 1:12 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Sep 26, 11:19 AM
Unknown Object (File)
Sun, Sep 22, 9:21 PM
Unknown Object (File)
Sat, Sep 21, 5:52 AM
Unknown Object (File)
Sat, Sep 21, 5:50 AM
Unknown Object (File)
Sun, Sep 15, 9:14 PM
Unknown Object (File)
Fri, Sep 13, 12:05 PM
Unknown Object (File)
Fri, Sep 13, 7:35 AM
Unknown Object (File)
Tue, Sep 3, 8:09 AM
Subscribers

Details

Summary

To make parsing of, for example, Spamhaus' drop.txt and similar
files that contains semicolons as comments, allow them also
in file-based tables.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

otis requested review of this revision.Jul 23 2024, 1:12 PM

I'm not opposed to this, but I believe it's incomplete. This will only accept ';' as a comment in table files. It won't work for lines in the main pf.conf.

I've not tested it, but I think you also need this:

diff --git a/sbin/pfctl/parse.y b/sbin/pfctl/parse.y
index d07a3fdc188e..e652c27f1acf 100644
--- a/sbin/pfctl/parse.y
+++ b/sbin/pfctl/parse.y
@@ -6530,7 +6530,7 @@ top:
                ; /* nothing */

        yylval.lineno = file->lineno;
-       if (c == '#')
+       if (c == '#' || c == ';')
                while ((c = lgetc(0)) != '\n' && c != EOF)
                        ; /* nothing */
        if (c == '$' && parsebuf == NULL) {

Can you add a test case or two in /usr/src/sbin/pfctl/tests to validate that this does the right thing?

In D46088#1050559, @kp wrote:

I'm not opposed to this, but I believe it's incomplete. This will only accept ';' as a comment in table files. It won't work for lines in the main pf.conf.

I've considered also this possibility (and looked into parser.y) but decided to not do it, eventually. But I might do it as well.

I've not tested it, but I think you also need this:

diff --git a/sbin/pfctl/parse.y b/sbin/pfctl/parse.y
index d07a3fdc188e..e652c27f1acf 100644
--- a/sbin/pfctl/parse.y
+++ b/sbin/pfctl/parse.y
@@ -6530,7 +6530,7 @@ top:
                ; /* nothing */

        yylval.lineno = file->lineno;
-       if (c == '#')
+       if (c == '#' || c == ';')
                while ((c = lgetc(0)) != '\n' && c != EOF)
                        ; /* nothing */
        if (c == '$' && parsebuf == NULL) {

Can you add a test case or two in /usr/src/sbin/pfctl/tests to validate that this does the right thing?

Yes, I was already looking into the test suite and will surely add those tests.

In D46088#1050559, @kp wrote:

I'm not opposed to this, but I believe it's incomplete. This will only accept ';' as a comment in table files. It won't work for lines in the main pf.conf.

I've considered also this possibility (and looked into parser.y) but decided to not do it, eventually. But I might do it as well.

I had assumed that the man page change you made was about the general case, but it appears to be only about address files, so we could actually do this without misleading users. I think the ideal would be to do both, but if there's a test case for this we can do this now and consider extending it to the general case later.

This revision was not accepted when it landed; it landed in state Needs Review.Jul 25 2024, 1:10 PM
Closed by commit rGa8a95277363b: pfctl: Allow a semicolon (;) as a comment (authored by otis, committed by kp). · Explain Why
This revision was automatically updated to reflect the committed changes.