Hi all
While I was experimenting with nested (inline) anchors in PF, I found some behaviour that I have no explanation for. The following simple pf.conf is somewhat similar in structure to an example given in pf.conf(5) within the section discussing the use of inline anchors. All testing was done on a releng/11.2 amd64 machine.
When this ruleset is loaded,
Using
Notice the error message when
Now the following pf.conf is identical to the one used above but uses a normal non-inline anchor for an2:
After loading it and populating the an2 anchor using
However in contrast to before, now both time and daytime ports are reachable from a remote machine, just as one would expect. Also flushing the rules from anchor an2 by means of
Any ideas as to why the nested inline anchor is not behaving as one would expect or whether this could possibly be a bug are highly appreciated.
While I was experimenting with nested (inline) anchors in PF, I found some behaviour that I have no explanation for. The following simple pf.conf is somewhat similar in structure to an example given in pf.conf(5) within the section discussing the use of inline anchors. All testing was done on a releng/11.2 amd64 machine.
Code:
ext_if="re0"
set loginterface $ext_if
set skip on lo0
scrub in all
block log
pass quick inet proto icmp
pass quick inet6 proto icmp6
anchor "an1" in on $ext_if {
pass quick inet proto tcp to port time
anchor "an2" {
pass quick inet proto tcp to port daytime
}
}
pass out quick on $ext_if
pfctl -a '*' -sr
shows the following:
Code:
scrub in all fragment reassemble
block drop log all
pass quick inet proto icmp all keep state
pass quick inet6 proto ipv6-icmp all keep state
anchor "an1" in on re0 all {
pass quick inet proto tcp from any to any port = time flags S/SA keep state
anchor "an2" all {
pass quick inet proto tcp from any to any port = daytime flags S/SA keep state
}
}
pass out quick on re0 all flags S/SA keep state
telnet
from a remote machine I can successfully connect to the time port, but connections to the daytime port are blocked by PF although the rule in anchor an2 should allow them through. Another strange thing happens when I now flush the rules from anchor an2 using pfctl -a "an1/an2" -Fr
and then display the active rules again using pfctl -a '*' -sr
:
Code:
scrub in all fragment reassemble
block drop log all
pass quick inet proto icmp all keep state
pass quick inet6 proto ipv6-icmp all keep state
anchor "an1" in on re0 all {
pass quick inet proto tcp from any to any port = time flags S/SA keep state
anchor "an2" all {
pfctl: DIOCGETRULES: Invalid argument
}
}
pass out quick on re0 all flags S/SA keep state
pfctl
tries to read the rules from anchor an2. When I now populate the anchor an2 again by using echo "pass quick inet proto tcp to port daytime" | pfctl -a "an1/an2" -f -
the output of pfctl -a '*' -sr
looks exactly as it did after initially loading the pf.conf but connections to the daytime port are still blocked by PF.Now the following pf.conf is identical to the one used above but uses a normal non-inline anchor for an2:
Code:
ext_if="re0"
set loginterface $ext_if
set skip on lo0
scrub in all
block log
pass quick inet proto icmp
pass quick inet6 proto icmp6
anchor "an1" in on $ext_if {
pass quick inet proto tcp to port time
anchor "an2"
}
pass out quick on $ext_if
echo "pass quick inet proto tcp to port daytime" | pfctl -a "an1/an2" -f -
the output of pfctl -a '*' -sr
looks pretty much the same as it did before:
Code:
scrub in all fragment reassemble
block drop log all
pass quick inet proto icmp all keep state
pass quick inet6 proto ipv6-icmp all keep state
anchor "an1" in on re0 all {
pass quick inet proto tcp from any to any port = time flags S/SA keep state
anchor "an2" all {
pass quick inet proto tcp from any to any port = daytime flags S/SA keep state
}
}
pass out quick on re0 all flags S/SA keep state
pfctl -a "an1/an2" -Fr
and then displaying the ruleset with pfctl -a '*' -sr
does NOT yield the ioctl error message as it did with the inlined an2 anchor.Any ideas as to why the nested inline anchor is not behaving as one would expect or whether this could possibly be a bug are highly appreciated.