aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuraj Lutter <otis@FreeBSD.org>2024-07-25 08:07:50 +0000
committerKristof Provost <kp@FreeBSD.org>2024-08-08 05:42:58 +0000
commit053500aa93017f8d8096a9625491ae1e335a356e (patch)
tree9859a5e2ab7355725157871d5c66128987266238
parentf702110bc4bcc593b38674ec6e4fadf6c4626432 (diff)
pfctl: Allow a semicolon (;) as a comment
To make parsing of, for example, Spamhaus' drop.txt and similar files that contains semicolons as comments, allow them also in file-based tables. Reviewed by: kp MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D46088 (cherry picked from commit a8a95277363be2c92b3c06bd9cd1a32d1c6c6ecd)
-rw-r--r--sbin/pfctl/pfctl.84
-rw-r--r--sbin/pfctl/pfctl_radix.c4
-rw-r--r--sbin/pfctl/tests/files/pf1020.in3
-rw-r--r--sbin/pfctl/tests/files/pf1020.include4
-rw-r--r--sbin/pfctl/tests/files/pf1020.ok2
-rw-r--r--sbin/pfctl/tests/pfctl_test_list.inc1
6 files changed, 15 insertions, 3 deletions
diff --git a/sbin/pfctl/pfctl.8 b/sbin/pfctl/pfctl.8
index 41a8ec8b4340..196ce0f1766f 100644
--- a/sbin/pfctl/pfctl.8
+++ b/sbin/pfctl/pfctl.8
@@ -24,7 +24,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd October 3, 2016
+.Dd July 23, 2024
.Dt PFCTL 8
.Os
.Sh NAME
@@ -518,6 +518,8 @@ line and/or in an unformatted text file, using the
flag.
Comments starting with a
.Sq #
+or
+.Sq \;
are allowed in the text file.
With these commands, the
.Fl v
diff --git a/sbin/pfctl/pfctl_radix.c b/sbin/pfctl/pfctl_radix.c
index d33f091d8b69..1e93a8972d9e 100644
--- a/sbin/pfctl/pfctl_radix.c
+++ b/sbin/pfctl/pfctl_radix.c
@@ -535,8 +535,8 @@ pfr_next_token(char buf[BUF_SIZE], FILE *fp)
/* skip spaces */
while (isspace(next_ch) && !feof(fp))
next_ch = fgetc(fp);
- /* remove from '#' until end of line */
- if (next_ch == '#')
+ /* remove from '#' or ';' until end of line */
+ if (next_ch == '#' || next_ch == ';')
while (!feof(fp)) {
next_ch = fgetc(fp);
if (next_ch == '\n')
diff --git a/sbin/pfctl/tests/files/pf1020.in b/sbin/pfctl/tests/files/pf1020.in
new file mode 100644
index 000000000000..7f98df69bd04
--- /dev/null
+++ b/sbin/pfctl/tests/files/pf1020.in
@@ -0,0 +1,3 @@
+table <tabl1> file "./pf1020.include"
+
+block from <tabl1>
diff --git a/sbin/pfctl/tests/files/pf1020.include b/sbin/pfctl/tests/files/pf1020.include
new file mode 100644
index 000000000000..3fca07f64bfa
--- /dev/null
+++ b/sbin/pfctl/tests/files/pf1020.include
@@ -0,0 +1,4 @@
+; comment1
+# comment2
+1.0.0.1/32 ; comment1
+2.0.0.2/32 # comment2
diff --git a/sbin/pfctl/tests/files/pf1020.ok b/sbin/pfctl/tests/files/pf1020.ok
new file mode 100644
index 000000000000..16073b3d6987
--- /dev/null
+++ b/sbin/pfctl/tests/files/pf1020.ok
@@ -0,0 +1,2 @@
+table <tabl1> file "./pf1020.include"
+block drop from <tabl1> to any
diff --git a/sbin/pfctl/tests/pfctl_test_list.inc b/sbin/pfctl/tests/pfctl_test_list.inc
index b73bcf2522b7..2565a119cc6a 100644
--- a/sbin/pfctl/tests/pfctl_test_list.inc
+++ b/sbin/pfctl/tests/pfctl_test_list.inc
@@ -117,3 +117,4 @@ PFCTL_TEST(1005, "PR 231323")
PFCTL_TEST(1006, "pfctl crashes with certain fairq configurations")
PFCTL_TEST(1010, "POM_STICKYADDRESS test")
PFCTL_TEST(1018, "Test dynamic address mask")
+PFCTL_TEST(1020, "Test hashmark and semicolon comment")