Thread View: muc.lists.freebsd.hackers
2 messages
2 total messages
Started by Vadim Goncharov
Mon, 19 Oct 2026 23:47
Re: improvements to PF macros
Author: Vadim Goncharov
Date: Mon, 19 Oct 2026 23:47
Date: Mon, 19 Oct 2026 23:47
70 lines
8656 bytes
8656 bytes
On Thu, 8 Oct 2026 21:00:33 +0000
Robert Austen <robert.austen@willowglensystems.com> wrote:
> I've been working with PF under freebsd for a few months, and have noticed a
> recurring theme in the forums, that the macros in PF could be improved.
>
> I notice that it is often difficult to define one macro in terms of
> another, and just addressing that item alone would help write cleaner
> simpler rules.
I'm not using pf, just soming from Lex/Yacc side, because changing syntax
can establish a precedent for "downstream" projects: at $job I am doing custom
firewall-like thing, with some syntax parts borrowed from FreeBSD firewalls,
and I think I am not the only where "@" is already got used for other things.
What about, say, "$$" ?
[...]
> this change allows a macro to be defined in terms of an existing macro,
> using the '@' to refer to that existing macro by name, rather than expanding
> the macro out and causing the eventual 'syntax error' response that often
> results.
>
> this allows using one macro within another
> set_ext_tag = "tag \"from_outside\""
> is_int_tag = "tagged \"from_inside\""
>
> combined_tags = @set_ext_tag @is_int_tag
>
> this results in $combined_tags expanding to:
> tag "from_outside" tagged "from_inside"
I do not understand this example - man page close to beginning shows:
ext_if = "kue0"
all_ifs = "{" $ext_if lo0 "}"
pass out on $ext_if from any to any
what your example achieves what's not covered already?
> [...]
> the existing grammar for varstring inserts a space, which is not always
> helpful, so the second change. this change adds the '+' operator to
> explicitly concat two strings together (either or both could be a macro),
> which allows the following
>
> subnet = "192.168.0."
> client = @subnet + "206"
>
>
> this results in $client expanding to:
> 192.168.0.206
This looks like an overkill for simple task - e.g. in Shell, you do not need
separate strings concatenation operator - you just concatenate them, e.g.
inside quotes. So your real problem seems to be the statement
Macros are not expanded inside quotes.
from manpage. This can't be changed literally without breaking backwards
compatibility, but `man sh` can serve as inspiration, and may be `man make`,
too. For example, what about syntax like $'' inside which macros are expanded?
Or $() in make-style? Can this actuallt solve BOTH of your problems?..
--
WBR, @nuclight
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Re: improvements to PF macros
Author: Robert Austen
Date: Tue, 20 Oct 2026 00:19
Date: Tue, 20 Oct 2026 00:19
373 lines
24131 bytes
24131 bytes
--_000_YT6PR01MB10996CE6653FF0214D2D97DA8EF672YT6PR01MB10996CA_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
________________________________
From: Vadim Goncharov <vadimnuclight@gmail.com>
Sent: October 19, 2026 5:47 PM
To: Robert Austen <robert.austen@willowglensystems.com>
Cc: current@freebsd.org <current@freebsd.org>; hackers@freebsd.org <hackers=
@freebsd.org>
Subject: Re: improvements to PF macros
[You don't often get email from vadimnuclight@gmail.com. Learn why this is =
important at https://aka.ms/LearnAboutSenderIdentification ]
On Thu, 8 Oct 2026 21:00:33 +0000
Robert Austen <robert.austen@willowglensystems.com> wrote:
> I've been working with PF under freebsd for a few months, and have notice=
d a
> recurring theme in the forums, that the macros in PF could be improved.
>
> I notice that it is often difficult to define one macro in terms of
> another, and just addressing that item alone would help write cleaner
> simpler rules.
I'm not using pf, just soming from Lex/Yacc side, because changing syntax
can establish a precedent for "downstream" projects: at $job I am doing cus=
tom
firewall-like thing, with some syntax parts borrowed from FreeBSD firewalls=
,
and I think I am not the only where "@" is already got used for other thing=
s.
What about, say, "$$" ?
because '$' is used in the yylex part of the pfctl parser, it's probably th=
e more difficult
operator to use. Certainly requires a lot more code. One could use a token =
in the
form of a string, eg. VAR and do it that way.
I don't believe I've seen anything that uses '@'. Historically the '@' was=
used
in assembler to retrieve what a pointer points at, so it seemed a good fit.
Besides., the '@' only appears in the varstring and numberstring grammars,
and no where else, so it's only meant to allow macros to be manipulated
in a basic way.
Do you have an example where '@' is being used inside of the pf.conf syntax=
?
I don't see any.
[...]
> this change allows a macro to be defined in terms of an existing macro,
> using the '@' to refer to that existing macro by name, rather than expand=
ing
> the macro out and causing the eventual 'syntax error' response that often
> results.
>
> this allows using one macro within another
> set_ext_tag =3D "tag \"from_outside\""
> is_int_tag =3D "tagged \"from_inside\""
>
> combined_tags =3D @set_ext_tag @is_int_tag
>
> this results in $combined_tags expanding to:
> tag "from_outside" tagged "from_inside"
I do not understand this example - man page close to beginning shows:
ext_if =3D "kue0"
all_ifs =3D "{" $ext_if lo0 "}"
pass out on $ext_if from any to any
what your example achieves what's not covered already?
Not at all.
Try making a macro from an existing macro that has a tag, or label.
The quotes are very difficult to requote, because of the way the $macro
is expanded by the yylex. Rather than totally changing the macro expansion,
looking up the macro from the symget function and using that value
(rather than expanding the macro and having to reparse it) makes for a
simple way to define macros in terms of other macros.
The '+' allows concat things that seem easy, but don't work, like adding
a final quad to a dot quad address, such as
myIP =3D 192.168.0.$myValue
because the syntax requires a space
myIP =3D 192.168.0. $myValue
and then you get a space in the middle of your macro, which is not what any=
one wants.
that's why I added the '+', to do a proper (c++) concat, without the annoyi=
ng space.
> [...]
> the existing grammar for varstring inserts a space, which is not always
> helpful, so the second change. this change adds the '+' operator to
> explicitly concat two strings together (either or both could be a macro),
> which allows the following
>
> subnet =3D "192.168.0."
> client =3D @subnet + "206"
>
>
> this results in $client expanding to:
> 192.168.0.206
This looks like an overkill for simple task - e.g. in Shell, you do not nee=
d
separate strings concatenation operator - you just concatenate them, e.g.
inside quotes. So your real problem seems to be the statement
Macros are not expanded inside quotes.
from manpage. This can't be changed literally without breaking backwards
compatibility, but `man sh` can serve as inspiration, and may be `man make`=
,
too. For example, what about syntax like $'' inside which macros are expand=
ed?
Or $() in make-style? Can this actuallt solve BOTH of your problems?..
exactly, that's why I propose these two simple changes to the macro definit=
ion
grammar (and only to those), rather than breaking everything.
Robert
--
WBR, @nuclight
--_000_YT6PR01MB10996CE6653FF0214D2D97DA8EF672YT6PR01MB10996CA_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
1">
<style type=3D"text/css" style=3D"display:none;"> P {margin-top:0;margin-bo=
ttom:0;} </style>
</head>
<body dir=3D"ltr">
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c=
olor: rgb(0, 0, 0);">
<br>
</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<hr style=3D"display: inline-block; width: 98%;">
<div id=3D"divRplyFwdMsg">
<div style=3D"direction: ltr; font-family: Calibri, sans-serif; font-size: =
11pt; color: rgb(0, 0, 0);">
<b>From:</b> Vadim Goncharov <vadimnuclight@gmail.com><br>
<b>Sent:</b> October 19, 2026 5:47 PM<br>
<b>To:</b> Robert Austen <robert.austen@willowglensystems.com><br>
<b>Cc:</b> current@freebsd.org <current@freebsd.org>; hackers@freebsd=
.org <hackers@freebsd.org><br>
<b>Subject:</b> Re: improvements to PF macros</div>
<div style=3D"direction: ltr;"> </div>
</div>
<div style=3D"font-size: 11pt;">[You don't often get email from vadimnuclig=
ht@gmail.com. Learn why this is important at
<a href=3D"https://aka.ms/LearnAboutSenderIdentification" id=3D"OWA6c54a9e6=
-9216-d120-8aff-61e11b21bea1" class=3D"OWAAutoLink" data-auth=3D"NotApplica=
ble">
https://aka.ms/LearnAboutSenderIdentification</a> ]<br>
<br>
On Thu, 8 Oct 2026 21:00:33 +0000<br>
Robert Austen <robert.austen@willowglensystems.com> wrote:<br>
<br>
> I've been working with PF under freebsd for a few months, and have not=
iced a<br>
> recurring theme in the forums, that the macros in PF could be improved=
.<br>
><br>
> I notice that it is often difficult to define one macro in terms of<br=
>
> another, and just addressing that item alone would help write cleaner<=
br>
> simpler rules.<br>
<br>
I'm not using pf, just soming from Lex/Yacc side, because changing syntax<b=
r>
can establish a precedent for "downstream" projects: at $job I am=
doing custom<br>
firewall-like thing, with some syntax parts borrowed from FreeBSD firewalls=
,<br>
and I think I am not the only where "@" is already got used for o=
ther things.<br>
What about, say, "$$" ?</div>
<div style=3D"font-size: 11pt;"><br>
</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">because '$' is use=
d in the yylex part of the pfctl parser, it's probably the more difficult</=
div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">operator to use. C=
ertainly requires a lot more code. One could use a token in the</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 11pt; c=
olor: rgb(0, 0, 0);">
form of a string, eg. VAR and do it that way.</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;"><br>
</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">I don't believe I'=
ve seen anything that uses '@'. Historically the '@' was used </=
div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">in assembler to re=
trieve what a pointer points at, so it seemed a good fit.</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 11pt; c=
olor: rgb(0, 0, 0);">
Besides., the '@' only appears in the varstring and numberstring grammars,<=
/div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 11pt; c=
olor: rgb(0, 0, 0);">
and no where else, so it's only meant to allow macros to be manipulated</di=
v>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 11pt; c=
olor: rgb(0, 0, 0);">
in a basic way.</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;"><br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 11pt; c=
olor: rgb(0, 0, 0);">
Do you have an example where '@' is being used inside of the pf.conf syntax=
?</div>
<div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo=
nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 11pt; c=
olor: rgb(0, 0, 0);">
I don't see any.</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;"><br>
<br>
[...]<br>
> this change allows a macro to be defined in terms of an existing macro=
,<br>
> using the '@' to refer to that existing macro by name, rather than exp=
anding<br>
> the macro out and causing the eventual 'syntax error' response that of=
ten<br>
> results.<br>
><br>
> this allows using one macro within another<br>
> set_ext_tag =3D "tag \"from_outside\""<br>
> is_int_tag =3D "tagged \"from_inside\""<br>
><br>
> combined_tags =3D @set_ext_tag @is_int_tag<br>
><br>
> this results in $combined_tags expanding to:<br>
>  =
; &n=
bsp; tag "from_o=
utside" tagged "from_inside"<br>
<br>
I do not understand this example - man page close to beginning shows:<br>
<br>
ext_if =3D &qu=
ot;kue0"<br>
all_ifs =3D &q=
uot;{" $ext_if lo0 "}"<br>
pass out on $e=
xt_if from any to any<br>
<br>
what your example achieves what's not covered already?</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;"><br>
</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;"><br>
</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">Not at all.</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">Try making a macro=
from an existing macro that has a tag, or label.</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">The quotes are ver=
y difficult to requote, because of the way the $macro</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">is expanded by the=
yylex. Rather than totally changing the macro expansion,</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">looking up the mac=
ro from the symget function and using that value </div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">(rather than expan=
ding the macro and having to reparse it) makes for a </div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">simple way to defi=
ne macros in terms of other macros.</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;"><br>
</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">The '+' allows con=
cat things that seem easy, but don't work, like adding</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">a final quad to a =
dot quad address, such as</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">myIP =3D 192.168.0=
.$myValue</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;"><br>
</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">because the syntax=
requires a space</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt; color: rgb(0, 0, 0)=
;">myIP =3D 192.168.0. $myValue</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;"><br>
</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">and then you get a=
space in the middle of your macro, which is not what anyone wants.</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">that's why I added=
the '+', to do a proper (c++) concat, without the annoying space.<br>
<br>
> [...]<br>
> the existing grammar for varstring inserts a space, which is not alway=
s<br>
> helpful, so the second change. this change adds the '+' operator to<br=
>
> explicitly concat two strings together (either or both could be a macr=
o),<br>
> which allows the following<br>
><br>
> subnet =3D "192.168.0."<br>
> client =3D @subnet + "206"<br>
><br>
><br>
> this results in $client expanding to:<br>
>  =
; 192.168=
.0.206<br>
<br>
This looks like an overkill for simple task - e.g. in Shell, you do not nee=
d<br>
separate strings concatenation operator - you just concatenate them, e.g.<b=
r>
inside quotes. So your real problem seems to be the statement<br>
<br>
Macros are not expanded inside quotes.<br>
<br>
from manpage. This can't be changed literally without breaking backwards<br=
>
compatibility, but `man sh` can serve as inspiration, and may be `man make`=
,<br>
too. For example, what about syntax like $'' inside which macros are expand=
ed?<br>
Or $() in make-style? Can this actuallt solve BOTH of your problems?..</div=
>
<div class=3D"elementToProof" style=3D"font-size: 11pt;"><br>
</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;"><br>
</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">exactly, that's wh=
y I propose these two simple changes to the macro definition</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">grammar (and only =
to those), rather than breaking everything.</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;"><br>
</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;">Robert</div>
<div class=3D"elementToProof" style=3D"font-size: 11pt;"><br>
<br>
--<br>
WBR, @nuclight</div>
</body>
</html>
--_000_YT6PR01MB10996CE6653FF0214D2D97DA8EF672YT6PR01MB10996CA_--
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads