FreeBSD/src aeddee8sbin/pfctl parse.y pfctl.c, sbin/pfctl/tests pfctl_test.c pfctl_test_list.inc

pfctl: Split pool parsing into separate functions

The pf pools are used in NAT, route-to and af-to rules. Some parts of
code are duplicated between them. Create functions apply_redirspec(),
apply_nat_ports() and apply_rdr_ports() to handle the common tasks.

Simplify data structures used for pool parsing. Move the contents of
struct redirection to struct redirspec. Map all ways of parsing pools
directly onto struct redirspec. Name various forms of struct redirspect
to hint where they are used.

Remove struct redirspec *rroute from struct filter_opts, because
filter_opts is bzero()'ed after the route part of rule is parsed, and
thus can't be used.

Add tests to ensure that parsing and error messages behave as expected.
The tests have been written and tested with pfctl from before this
patch.


    [6 lines not shown]
DeltaFile
+260-309sbin/pfctl/parse.y
+162-32sbin/pfctl/tests/pfctl_test.c
+37-0sbin/pfctl/tests/pfctl_test_list.inc
+10-0sbin/pfctl/pfctl.c
+3-0sbin/pfctl/tests/files/pf1054.in
+1-1sbin/pfctl/tests/files/pf1026.ok
+473-34277 files not shown
+550-34483 files

FreeBSD/src c2346c3sbin/pfctl parse.y, share/man/man5 pf.conf.5

pf: support source-hash and random with tables and dynifs, not just pools

This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@

Obtained from:  OpenBSD, reyk <reyk at openbsd.org>, 252a05523f
Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+58-18tests/sys/netpfil/pf/nat64.sh
+62-12sys/netpfil/pf/pf_lb.c
+18-25sbin/pfctl/parse.y
+5-5share/man/man5/pf.conf.5
+5-0sys/netpfil/pf/pf.h
+148-605 files

FreeBSD/src 2514ac8sbin/pfctl parse.y

pfctl: Don't allow embedded nul characters in strings.

Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@

Obtained from:  OpenBSD, jsg <jsg at openbsd.org>, 41eef22fad
Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+3-0sbin/pfctl/parse.y
+3-01 files

FreeBSD/src cba525esbin/pfctl parse.y

pfctl: relax the cfg file secrecy check slightly to allow group readability

default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian

Obtained from:  OpenBSD, henning <henning at openbsd.org>, 7140c133f0
Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+2-2sbin/pfctl/parse.y
+2-21 files

FreeBSD/src a261457sbin/pfctl parse.y

pfctl: if_item can be "any" now

Allows things like:
        block out on $someif received-on any

to prevent packets to get forwarded to $someif.

Obtained from:  OpenBSD, henning <henning at openbsd.org>, 5984d04852
Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+9-0sbin/pfctl/parse.y
+9-01 files

FreeBSD/src 71594e3lib/libpfctl libpfctl.c libpfctl.h, sbin/pfctl parse.y pfctl_parser.c

pf: support "!received-on <interface>"

ok dlg benno

Obtained from:  OpenBSD, henning <henning at openbsd.org>, 7d0482a910
Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+4-2sbin/pfctl/parse.y
+2-1sbin/pfctl/pfctl_parser.c
+2-0lib/libpfctl/libpfctl.c
+1-0lib/libpfctl/libpfctl.h
+9-34 files

FreeBSD/src 7cef9d1sbin/pfctl pfctl_parser.c parse.y

pfctl: cache name/index mappings

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian

Obtained from:  OpenBSD, mikeb <mikeb at openbsd.org>, 918dda8655
Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+31-0sbin/pfctl/pfctl_parser.c
+4-4sbin/pfctl/parse.y
+2-0sbin/pfctl/pfctl_parser.h
+37-43 files

FreeBSD/src 491f5e3sbin/pfctl parse.y, share/man/man5 pf.conf.5

pf: add 'allow-related' to always allow SCTP multihome extra connections

Allow users to choose to allow permitted SCTP connections to set up additional
multihomed connections regardless of the ruleset. That is, allow an already
established connection to set up flows that would otherwise be disallowed.

In case of if-bound connections we initially set the extra associations to
be floating, because we don't know what path they'll be taking when they're
created. Once we see the first traffic we can bind them.

MFC after:      2 weeks
Sponsored by:   Orange Business Services
Differential Revision:  https://reviews.freebsd.org/D48453

(cherry picked from commit e4f2733df8c9d2fd0c5e8fdc8bec002bf39811f3)
DeltaFile
+76-0tests/sys/netpfil/pf/sctp.py
+34-3sys/netpfil/pf/pf.c
+20-2sbin/pfctl/parse.y
+5-1share/man/man5/pf.conf.5
+1-0sys/net/pfvar.h
+1-0sys/netpfil/pf/pf.h
+137-66 files

FreeBSD/src 7a372bdsbin/pfctl parse.y pfctl_parser.c, sbin/pfctl/tests/files pf1027.ok pf1027.in

pf: make reply-to work with nat64

Just like route-to reply-to is problematic when used in combination with nat64.

In the normal (i.e. without nat64) flow we return immediately from pf_route().
However, with nat64 we need to continue and do a route lookup. In that case
we should not make the extra pf_test(PF_OUT) call to remain similar to the
non-nat64 flow.

We also have to fix the interface binding. We can only bind to the interface
after we've done the route lookup, not before.

Add a funcional test case, and a test for pfctl's rule printing.

Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+54-34sys/netpfil/pf/pf.c
+45-0tests/sys/netpfil/pf/nat64.sh
+2-2sbin/pfctl/parse.y
+2-1sbin/pfctl/pfctl_parser.c
+1-0sbin/pfctl/tests/files/pf1027.ok
+1-0sbin/pfctl/tests/files/pf1027.in
+105-371 files not shown
+106-377 files

FreeBSD/src ca0e693sbin/pfctl parse.y pfctl_parser.c, sbin/pfctl/tests pfctl_test_list.inc

pf: cope with route-to on af-to rules

af-to uses pf_route() and pf_route6(), which caused issues when af-to and
route-to were combined in a single rule.
Extend the relevant functions to cope with this and add test cases.

Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+47-0tests/sys/netpfil/pf/nat64.sh
+24-2sys/netpfil/pf/pf.c
+9-1sbin/pfctl/parse.y
+2-1sbin/pfctl/pfctl_parser.c
+1-0sbin/pfctl/tests/pfctl_test_list.inc
+1-0sbin/pfctl/tests/files/pf1026.ok
+84-41 files not shown
+85-47 files

FreeBSD/src 0972294sbin/pfctl parse.y pfctl.c, sys/netpfil/pf pf_ioctl.c pf.c

pf: add a dedicated pf pool for route options

As suggested by henning.
Which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@

Obtained from:  OpenBSD, jsg <jsg at openbsd.org>, 7fa5c09028
Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+57-38sbin/pfctl/parse.y
+41-12sys/netpfil/pf/pf_ioctl.c
+16-0sbin/pfctl/pfctl.c
+9-2sys/netpfil/pf/pf.c
+7-1sys/netpfil/pf/if_pfsync.c
+7-0sbin/pfctl/pfctl_optimize.c
+137-537 files not shown
+147-5513 files

FreeBSD/src 899e797sbin/pfctl parse.y, sbin/pfctl/tests pfctl_test_list.inc

pfctl: allow an implicit address family for af-to rules

If the address family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6" there.
OK henning@ mikeb@

Obtained from:  OpenBSD, bluhm <bluhm at openbsd.org>, ff33038bc1
Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+5-12sbin/pfctl/parse.y
+1-0sbin/pfctl/tests/files/pf1025.in
+1-0sbin/pfctl/tests/files/pf1025.ok
+1-0sbin/pfctl/tests/pfctl_test_list.inc
+8-124 files

FreeBSD/src 5cb08fdsbin/pfctl pfctl_optimize.c pfctl.c

pfctl: improve NAT pool handling

Ensure we always free the NAT pool (as well as the rdr pool) and actually handle
it in the optimiser.

Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+12-1sbin/pfctl/pfctl_optimize.c
+5-0sbin/pfctl/pfctl.c
+1-0sbin/pfctl/parse.y
+18-13 files

FreeBSD/src 096efebcontrib/pf/ftp-proxy filter.c, contrib/pf/tftp-proxy filter.c

pfctl: follow rpool -> rdr rename

In e11dacbf8484adc7bbb61b20fee3ab8385745925 the redirect pool was renamed from
rpool to rdr. It included backwards compatibility support for libpfctl users,
but didn't fully implement the rename in our own code.

Do so now. No functional change.

Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+40-40sbin/pfctl/parse.y
+13-13sbin/pfctl/pfctl_optimize.c
+9-9sbin/pfctl/pfctl.c
+3-3contrib/pf/tftp-proxy/filter.c
+3-3contrib/pf/ftp-proxy/filter.c
+3-3sbin/pfctl/pfctl_parser.c
+71-716 files

FreeBSD/src e4f2733sbin/pfctl parse.y, share/man/man5 pf.conf.5

pf: add 'allow-related' to always allow SCTP multihome extra connections

Allow users to choose to allow permitted SCTP connections to set up additional
multihomed connections regardless of the ruleset. That is, allow an already
established connection to set up flows that would otherwise be disallowed.

In case of if-bound connections we initially set the extra associations to
be floating, because we don't know what path they'll be taking when they're
created. Once we see the first traffic we can bind them.

MFC after:      2 weeks
Sponsored by:   Orange Business Services
Differential Revision:  https://reviews.freebsd.org/D48453
DeltaFile
+76-0tests/sys/netpfil/pf/sctp.py
+24-0sys/netpfil/pf/pf.c
+19-2sbin/pfctl/parse.y
+5-1share/man/man5/pf.conf.5
+1-0sys/netpfil/pf/pf.h
+1-0sys/net/pfvar.h
+126-36 files

FreeBSD/src 0d68985sbin/pfctl parse.y pfctl_optimize.c

pfctl: unbreak rule optimizer

ok henning, looks

Obtained from:  OpenBSD, mikeb <mikeb at openbsd.org>, 4a16887b1b
Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+1-1sbin/pfctl/parse.y
+1-0sbin/pfctl/pfctl_optimize.c
+2-12 files

FreeBSD/src f88019esbin/pfctl parse.y pfctl_parser.c, sys/netpfil/pf pf.c pf.h

pf: fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule.  essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault

Obtained from:  OpenBSD, mikeb <mikeb at openbsd.org>, fc302162c0
Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+21-15sbin/pfctl/parse.y
+2-2sys/netpfil/pf/pf.c
+1-1sbin/pfctl/pfctl_parser.c
+1-0sys/netpfil/pf/pf.h
+25-184 files

FreeBSD/src 4aafc73sbin/pfctl pfctl.c parse.y

pfctl: pfctl_set_hostid always returns 0

Don't pretend otherwise and make it a void function instead.

ok dlg

Obtained from:  OpenBSD, mcbride <mcbride at openbsd.org>, 9ac6101ff7
Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+2-4sbin/pfctl/pfctl.c
+1-4sbin/pfctl/parse.y
+1-1sbin/pfctl/pfctl_parser.h
+4-93 files

FreeBSD/src e0dcc51sbin/pfctl parse.y, tests/sys/netpfil/pf nat64.sh

pfctl: do not allow af-to tables without round-robin

Tables can only be used as a redirspec (i.e. in pf_map_addr()) in round-robin mode.
Enforce this for af-to tables as well.

Add a test case to verify.

Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+23-0tests/sys/netpfil/pf/nat64.sh
+11-3sbin/pfctl/parse.y
+34-32 files

FreeBSD/src aa69fdflib/libpfctl libpfctl.c libpfctl.h, sbin/pfctl parse.y pfctl.c

pfctl: change for af-to / NAT64 support.

The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@

Obtained from:  OpenBSD, claudio <claudio at openbsd.org>, 0cde32ce3f
Sponsored by:   Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D47790
DeltaFile
+152-38sbin/pfctl/parse.y
+26-12sbin/pfctl/pfctl.c
+13-7sbin/pfctl/pf_print_state.c
+16-3sbin/pfctl/pfctl_parser.c
+10-3lib/libpfctl/libpfctl.c
+5-2lib/libpfctl/libpfctl.h
+222-653 files not shown
+225-659 files

FreeBSD/src 6562157sbin/pfctl parse.y

pfctl: avoid possible SIGSEGV when wrong tos option

Obtained from:  OpenBSD, haesbaert <haesbaert at openbsd.org>, 934eaac797
Sponsored by:   Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D46933
DeltaFile
+1-1sbin/pfctl/parse.y
+1-11 files

FreeBSD/src 288bec2sbin/pfctl parse.y pfctl_optimize.c, sbin/pfctl/tests/files pf0004.ok

pf: fold pf_test_fragment() into pf_test_rule()

Reduces code and fixes a bunch of bugs with fragment handling not being in sync
with the rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus

Note that while this changes the order of src addr/src port/dst addr/dst port
skips this doesn't actually affect the kernel/userspace ABI. The kernel always
recalculates skip steps. As a result we have to fix one of the pfctl parser
tests. Note that this is an order change that does not affect what packets are
acceppted or dropped.

Obtained from:  OpenBSD, mcbride <mcbride at openbsd.org>, 04c69899a7
Sponsored by:   Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D46705
DeltaFile
+180-272sys/netpfil/pf/pf.c
+12-12sbin/pfctl/tests/files/pf0004.ok
+2-2sbin/pfctl/parse.y
+2-2sys/netpfil/pf/pf.h
+1-1sbin/pfctl/pfctl_optimize.c
+2-0sys/net/pfvar.h
+199-2896 files

FreeBSD/src f3ab00csbin/pfctl parse.y pfctl_parser.c, share/man/man5 pf.conf.5

pf: add a new log opt PF_LOG_MATCHES

forces logging on all subsequent matching rules
new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many

Obtained from:  OpenBSD, henning <henning at openbsd.org>, 1603e01ae4
Obtained from:  OpenBSD, henning <henning at openbsd.org>, f496e91672
Obtained from:  OpenBSD, henning <henning at openbsd.org>, 07481a9fee
Sponsored by:   Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D46588
DeltaFile
+6-2sys/netpfil/pf/pf.c
+3-1sbin/pfctl/parse.y
+3-1share/man/man5/pf.conf.5
+2-0sbin/pfctl/pfctl_parser.c
+1-0sys/netpfil/pf/pf.h
+15-45 files

FreeBSD/src 80eb861sbin/pfctl parse.y

pfctl: lex <=, >=, and != into a single token

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto

Reviewed by:    zlei
Obtained from:  OpenBSD, deraadt <deraadt at openbsd.org>, e6e3ecf338
Sponsored by:   Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D46582
DeltaFile
+14-6sbin/pfctl/parse.y
+14-61 files

FreeBSD/src 637d81csbin/pfctl parse.y pfctl_parser.h

pfctl: fix incorrect optimization

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1.  How long this bug has
been with us is unclear.
ok guenther mcbride

Obtained from:  OpenBSD, deraadt <deraadt at openbsd.org>, e3b4bc25a0
Sponsored by:   Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D46580
DeltaFile
+11-3sbin/pfctl/parse.y
+2-0sbin/pfctl/pfctl_parser.h
+13-32 files

FreeBSD/src 2339eadlib/libpfctl libpfctl.c, sbin/pfctl parse.y pfctl_parser.c

pf: allow filtering on the receive interface

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

  pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf

Obtained from:  OpenBSD, dlg <dlg at openbsd.org>, 95b4320893
Sponsored by:   Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D46577
DeltaFile
+25-12sbin/pfctl/parse.y
+24-0sys/netpfil/pf/pf.c
+14-1sys/netpfil/pf/pf_ioctl.c
+3-0sys/netpfil/pf/pf_nl.c
+2-0sbin/pfctl/pfctl_parser.c
+2-0lib/libpfctl/libpfctl.c
+70-133 files not shown
+74-139 files

FreeBSD/src 390dc36sbin/pfctl parse.y, share/man/man5 pf.conf.5

pf: Add support for endpoint independent NAT bindings for UDP

With Endpoint Independent NAT bindings for UDP flows from a NATed source
address are always mapped to the same ip:port pair on the NAT router.
This allows a client to connect to multiple external servers while
appearing as the same host and enables NAT traversal without requiring
the client to use a middlebox traversal protocol such as STUN or TURN.

Introduce the 'endpoint-independent' option to NAT rules to allow
configuration of endpoint independent without effecting existing
deployments.

This change satisfies REQ 1 and 3 of RFC 4787 also known as 'full cone'
NAT.

Using Endpoint Independent NAT changes NAT exhaustion behaviour it does
not introduce any additional security considerations compared to other
forms of NAT.


    [7 lines not shown]
DeltaFile
+190-5sys/netpfil/pf/pf.c
+134-0tests/sys/netpfil/pf/nat.sh
+85-19sys/netpfil/pf/pf_lb.c
+48-1sys/net/pfvar.h
+11-1sbin/pfctl/parse.y
+11-1share/man/man5/pf.conf.5
+479-275 files not shown
+489-2811 files

FreeBSD/src 788f194sbin/pfctl parse.y, sys/netpfil/pf pf_ioctl.c

pf: 'sticky-address' requires 'keep state'

When route_to() processes a packet without state, pf_map_addr() is called for
each packet. Pf_map_addr() will search for a source node and will find none
since those are created only in pf_create_state(). Thus sticky address,
even though requested in rule definition, will never work.

Raise an error when a stateless filter rule uses sticky address to avoid
confusion and to keep ruleset limitations in sync with what the pf code
really does.

Reviewed by:    kp
Differential Revision:  https://reviews.freebsd.org/D46310
DeltaFile
+5-0sys/netpfil/pf/pf_ioctl.c
+4-0sbin/pfctl/parse.y
+9-02 files

FreeBSD/src d9ab899lib/libpfctl libpfctl.c, sbin/pfctl pfctl.c

pf: migrate DIOCGETLIMIT/DIOCSETLIMIT to netlink

Event:          Kitchener-Waterloo Hackathon 202406
DeltaFile
+85-3lib/libpfctl/libpfctl.c
+76-0sys/netpfil/pf/pf_nl.c
+66-0tests/sys/netpfil/pf/limits.sh
+37-19sys/netpfil/pf/pf_ioctl.c
+6-13sbin/pfctl/pfctl.c
+6-8usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c
+276-436 files not shown
+291-4512 files

FreeBSD/src 30bad75lib/libpfctl libpfctl.c, sbin/pfctl pfctl.c parse.y

pf: convert DIOCGETTIMEOUT/DIOCSETTIMEOUT to netlink
DeltaFile
+84-0lib/libpfctl/libpfctl.c
+76-0sys/netpfil/pf/pf_nl.c
+43-22sys/netpfil/pf/pf_ioctl.c
+6-13sbin/pfctl/pfctl.c
+8-0sys/netpfil/pf/pf_nl.h
+2-2sbin/pfctl/parse.y
+219-373 files not shown
+224-389 files