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
This commit is contained in:
Juraj Lutter 2024-07-25 10:07:50 +02:00 committed by Kristof Provost
parent 4d8c65b466
commit a8a9527736
6 changed files with 15 additions and 3 deletions

View File

@ -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 20, 2023
.Dd July 23, 2024
.Dt PFCTL 8
.Os
.Sh NAME
@ -531,6 +531,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

View File

@ -534,8 +534,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')

View File

@ -0,0 +1,3 @@
table <tabl1> file "./pf1020.include"
block from <tabl1>

View File

@ -0,0 +1,4 @@
; comment1
# comment2
1.0.0.1/32 ; comment1
2.0.0.2/32 # comment2

View File

@ -0,0 +1,2 @@
table <tabl1> file "./pf1020.include"
block drop from <tabl1> to any

View File

@ -128,3 +128,4 @@ PFCTL_TEST(1016, "Ethernet rule with ridentifier and one label")
PFCTL_TEST(1017, "Ethernet rule with ridentifier and several labels")
PFCTL_TEST(1018, "Test dynamic address mask")
PFCTL_TEST(1019, "Test pflow option")
PFCTL_TEST(1020, "Test hashmark and semicolon comment")