Commit graph

275 commits

Author SHA1 Message Date
Kristof Provost 025df3e6a0 pf tests: test keepcounters when we exceed 32 bits
Ensure that we correctly transfer byte counts if the value exceeds what can be
stored in a single 32-bit counter.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-06-21 13:49:17 +02:00
Kristof Provost d9ab899931 pf: migrate DIOCGETLIMIT/DIOCSETLIMIT to netlink
Event:		Kitchener-Waterloo Hackathon 202406
2024-06-07 20:59:02 +02:00
Kristof Provost 8ed5170c66 pf tests: test setting and retrieving timeout values 2024-06-06 20:46:19 +02:00
Kristof Provost 480ad40553 vnet tests: check for if_bridge.ko
A number of tests create a bridge, but did not check if if_bridge.ko is loaded.

We usually get away with that, because `ifconfig bridge create` autoloads the
module, but if we run the tests in a jail (e.g. because of kyua's upcoming
execenv.jail.params feature) we can't load the module and these tests can fail.

Check if the module is loaded, skip the test if it is not.

Reviewed by:	markj
MFC after:	1 week
Event:		Kitchener-Waterloo Hackathon 202406
Differential Revision:	https://reviews.freebsd.org/D45487
2024-06-04 22:16:56 +02:00
Kristof Provost 2144e31d8f netpfil tests: make the pls tests more robust
Give them more time to hit the expected loss numbers.
We see occasional failures during CI runs. This makes that less likely.

MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-06-04 14:59:59 +02:00
Kristof Provost 1c5b886e11 pf tests: make ether:dummynet test a little more robust
Allow slightly more bandwidth, but cause ping to give up sooner.

MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-06-04 14:59:59 +02:00
Kristof Provost cce6951755 pf tests: basic debug level test
Set & retrieve the debug level.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-06-04 14:59:59 +02:00
Kristof Provost a9d7ff4e5e pf tests: basic status get/clear test
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-06-04 14:59:58 +02:00
Kristof Provost 8b28ec3861 pf tests: test longer anchor names
PR:		279225
MFC after:	3 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-05-28 22:29:38 +02:00
Kristof Provost bf8988187f pf tests: fix REQUIRED_MODULES typo
This ensures we don't try to run the nat66 tests if pf is not loaded.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-05-03 09:51:37 +02:00
Kristof Provost a983cea4e9 pf: fix reply-to after rdr and dummynet
If we redirect a packet to localhost and it gets dummynet'd it may be
re-injected later (e.g. when delayed) which means it will be passed
through ip_input() again. ip_input() will then reject the packet because
it's directed to the loopback address, but did not arrive on a loopback
interface.

Fix this by having pf set the rcvif to V_iflo if we redirect to
loopback.

See also:	https://redmine.pfsense.org/issues/15363
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-03-28 17:06:01 +01:00
Gleb Smirnoff 75d15e893b netpfil tests: disable ICMPv6 rate limiting in the test jail
The dummynet test uses flood ping as source of traffic, so the rate
limiting of ICMP replies broke the test.

Fixes:	32aeee8ce7
2024-03-24 19:54:34 -07:00
Kristof Provost 470a2b3346 pf: convert DIOCSETSTATUSIF to netlink
While here also add a basic test case for it.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D44368
2024-03-19 16:30:08 +01:00
Kristof Provost c6f1116357 pf: fix dummynet + route-to
Ensure that we pick the correct dummynet pipe (i.e. forward vs. reverse
direction) when applying route-to.

We mark the processing as outbound so that dummynet will re-inject in
the correct phase of processing after it's done with the packet, but
that will cause us to pick the wrong pipe number. Reverse them so that
the incorrect decision ends up picking the correct pipe.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D44366
2024-03-19 16:29:29 +01:00
Kristof Provost 0ea0c02655 pf: avoid passing through dummynet multiple times
In some setups we end up with multiple states created for a single
packet, which in turn can mean we run the packet through dummynet
multiple times. That's not expected or intended. Mark each packet when
it goes through dummynet, and do not pass packet through dummynet if
they're marked as having already passed through.

See also:	https://redmine.pfsense.org/issues/14854
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D44365
2024-03-19 16:29:29 +01:00
Kristof Provost fb995824b9 pf tests: IPv6 versions of the route-to/reply-to if-bound tests
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-03-01 09:39:44 +01:00
Kristof Provost 6460322a0a pf: support if-bound with reply-to
On reply-to we don't know what interface to bind to when we create
the state. Create any reply-to state as floating, but bind to the
appropriate interface once we're handling the reply.

See also:	https://redmine.pfsense.org/issues/15220
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-03-01 09:39:43 +01:00
Kristof Provost 9566d92726 pf: fix packet-to-big for route-to as well
When we handle a packet via route-to (i.e. pf_route6()) we still need to
verify the MTU. However, we only run that check in the forwarding case.

Set the PFIL_FWD tag when running the pf_test6(PF_OUT) check from
pf_route6(). We are in fact forwarding, so should call the test function
as such. This will cause us to run the MTU check, and generate an ICMP6
packet-too-big error when required.

See also:	54c62e3e5d
See also:	f1c0030bb0
See also:	https://redmine.pfsense.org/issues/14290
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-02-27 14:38:38 +01:00
Tom Jones 3db693f7da pf: Correct SPDX identifier
Pointed out by: Mike Karels <karels@FreeBSD.org>
2024-02-23 15:58:38 +00:00
Tom Jones b9870ba93e pf: Add a TCP rdr test on IPv6
Reviewed by:    kp
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision: https://reviews.freebsd.org/D42105
2024-02-23 13:47:35 +00:00
Kristof Provost b8ef285f6c pf: ensure dummynet gets the correct direction after route-to
If we apply a route-to to an inbound packet pf_route() may hand that
packet over to dummynet. Dummynet may then delay the packet, and later
re-inject it. This re-injection (in dummynet_send()) needs to know
if the packet was inbound or outbound, to call the correct path for
continued processing.

That's done based on the pf_pdesc we pass along (through
pf_dummynet_route() and pf_pdesc_to_dnflow()). In the case of pf_route()
on inbound packets that may be wrong, because we're called in the input
path, and didn't update pf_pdesc->dir.

This can manifest in issues with fragmented packets. For example, a
fragmented packet will be re-fragmented in pf_route(), and if dummynet
makes different decisions for some of the fragments (that is, it delays
some and allows others to pass through directly) this will break.

The packets that pass through dummynet without delay will be transmitted
correctly (through the ifp->if_output() call in pf_route()), but
the delayed packets will be re-injected in the input path (and not
the output path, as they should be). These packets will pass through
pf_test(PF_IN) as they're tagged PF_MTAG_FLAG_DUMMYNET. However,
this tag is then removed and the packet will be routed and enter
pf_test(PF_OUT) where pf_reassemble() will hold them indefinitely
(as some fragments have been transmitted directly, and will never hit
pf_test(PF_OUT)).

The fix is simple: we must update pf_pfdesc->dir to PF_OUT before we
pass the packet to dummynet.

See also:	https://redmine.pfsense.org/issues/15156
Reviewed by:	rcm
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-02-02 17:55:16 +01:00
Kristof Provost 31828075e4 pf: bind route-to states to their route-to interface
When we route-to the state should be bound to the route-to interface,
not the default route interface. However, we should only do so for
outbound traffic, because inbound traffic should bind on the arriving
interface, not the one we eventually transmit on.

Explicitly check for this in BOUND_IFACE().

We must also extend pf_find_state(), because subsequent packets within
the established state will attempt to match the original interface, not
the route-to interface.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D43589
2024-01-29 14:10:26 +01:00
Kristof Provost 63a5fe8343 pflow: limit to no more than 128 flow exporters
While there are no inherent limits to the number of exporters we're
likely to scale rather badly to very large numbers. There's also no
obvious use case for more than a handful. Limit to 128 exporters to
prevent foot-shooting.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-01-22 18:02:10 +01:00
Kristof Provost 484e977f24 pflow: observation domain is an unsigned integer
Ensure we print it as such, rather than as a signed integer, as that
would lead to confusion.

Reported by:	Jim Pingle <jimp@netgate.com>
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-01-22 18:02:10 +01:00
Kristof Provost 57c50d6b36 pf tests: test ICMP6 packet too big with binat
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D43500
2024-01-22 13:49:56 +01:00
Kristof Provost d086b9f77c pf tests: test per-rule pflow
Test that we can enable pflow on a per-rule basis.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-01-16 09:45:55 +01:00
Kristof Provost c4d97a9487 pf tests: test pflow NAT state information
pflow(4) now also exports NAT session creation/destruction information.
Test that this works as expected.

While here improve the parsing of ipfix (i.e. pflowproto 10) a bit, and
check more information for the existing state information exports.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D43117
2024-01-16 09:45:55 +01:00
Kristof Provost 34276498fa pf tests: verify pflow over IPv6
Test that we can send netflow information over IPv6.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D43115
2024-01-16 09:45:55 +01:00
Kristof Provost 85b71dcfc9 pflow: allow observation domain to be configured
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D43113
2024-01-16 09:45:54 +01:00
Kristof Provost 6bd36d1cf4 pf tests: pflow functionality test
Test that we actually send netflow messages when configured to do so.
We do not yet inspect the generated netflow messages.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D43111
2024-01-16 09:45:54 +01:00
Kristof Provost fb0c74685f pf tests: initial pflow test case
Basic creation, validation and cleanup test for the new pflow interface.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D43109
2024-01-16 09:45:54 +01:00
Kristof Provost 3f9a6e0b85 pf tests: dummynet + nat fragmentation test
Ensure that we do the right thing when we reassemble fragmented packet
and send it through a dummynet pipe.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-01-15 14:02:02 +01:00
Kristof Provost 24c0058a9b pf tests: test reassembly with dummynet
Ensure that if we pass packets through a dummynet pipe we still
reassemble as expected.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-01-15 14:02:02 +01:00
Kristof Provost 32df0124f4 pf tests: ensure that pflog shows malformed packets as blocked, not passed
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-01-04 23:08:08 +01:00
Richard Scheffenegger 31cf66d755 dummynet: add simple gilbert-elliott channel model
Have a simple Gilbert-Elliott channel model in
dummynet to mimick correlated loss behavior of
realistic environments. This allows simpler testing
of burst-loss environments.

Reviewed By:           tuexen, kp, pauamma_gundo.com, #manpages
Sponsored by:          NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D42980
2023-12-17 13:20:45 +01:00
Kristof Provost 8fab83d2c5 pf tests: fix typos in the abort_v6 test case head / cleanup function name
MFC after:	1 week
2023-12-14 10:23:41 +01:00
Kristof Provost 4c84c69ba3 pf tests: test that we validate sequence numbers on TCP RST
MFC after:	3 days
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-12-05 21:03:49 +01:00
Kristof Provost 1d723c1e56 pf tests: test recursive printing of labels
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-11-27 21:37:33 +01:00
Igor Ostapenko b453e3f755 pf tests: fix name and description of divert-to cases
Reflect the correct order of events for dummynet+ipdivert.
2023-11-20 12:30:18 +01:00
Kristof Provost 0fe663b2a8 pf: always create multihomed states as floating
When we create a new state for multihomed sctp connections (i.e.
based on INIT/INIT_ACK or ASCONF parameters) we cannot know what
interfaces we'll be seeing that traffic on. Make those states floating,
irrespective of state policy.

MFC after:	1 week
Sponsored by:	Orange Business Services
2023-11-17 23:33:43 +01:00
Igor Ostapenko fe3bb40b9e pf: fix dummynet + ipdivert use case
Dummynet re-injects an mbuf with MTAG_IPFW_RULE added, and the same mtag
is used by divert(4) as parameters for packet diversion.

If according to pf rule set a packet should go through dummynet first
and through ipdivert after then mentioned mtag must be removed after
dummynet not to make ipdivert think that this is its input parameters.

At the very beginning ipfw consumes this mtag what means the same
behavior with tag clearing after dummynet.

And after fabf705f4b pf passes parameters to ipdivert using its
personal MTAG_PF_DIVERT mtag.

PR:		274850
Reviewed by:	kp
Differential Revision:	https://reviews.freebsd.org/D42609
2023-11-17 17:06:16 +01:00
Kristof Provost 483d5c4075 pf tests: ensure that we generate all permutations for SCTP multihome
The initial multihome implementation was a little simplistic, and failed
to create all of the required states. Given a client with IP 1 and 2 and
a server with IP 3 and 4 we end up creating states for 1 - 3 and 2 - 3,
as well as 3 - 1 and 4 - 1, but not for 2 - 4.

Check for this.

MFC after:	1 week
Sponsored by:	Orange Business Services
Differential Revision:	https://reviews.freebsd.org/D42362
2023-10-31 16:03:22 +01:00
Stephen J. Kiernan 5e3190f700 dirdeps: Update Makefile.depend* files with empty contents
Some Makefile.depend* files were committed with no contents or empty
DIRDEPS list, but they should have DIRDEPS with some contents.
2023-10-29 17:01:04 -04:00
Kajetan Staszkiewicz ede5d4ff5b pf: Fix packet reassembly
Don't drop fragmented packets when reassembly is disabled, they can be
matched by rules with "fragment" keyword. Ensure that presence of scrub
rules forces old behaviour.

Reviewed by:	kp
Sponsored by:	InnoGames GmbH
Differential Revision:	https://reviews.freebsd.org/D42355
2023-10-26 15:25:44 +02:00
Kajetan Staszkiewicz d7c9de2d68 pf tests: Add option to send fragmented packets
Add option to send fragmented packets and to properly sniff them by
reassembling them by the sniffer itself.

Reviewed by:	kp
Sponsored by:	InnoGames GmbH
Differential Revision:	https://reviews.freebsd.org/D42354
2023-10-26 15:25:20 +02:00
Kristof Provost 501b7fbd75 pf tests: add a test for killing states by NAT address
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D42313
2023-10-23 16:37:05 +02:00
Igor Ostapenko fabf705f4b pf: fix pf divert-to loop
Resolved conflict between ipfw and pf if both are used and pf wants to
do divert(4) by having separate mtags for pf and ipfw.

Also fix the incorrect 'rulenum' check, which caused the reported loop.

While here add a few test cases to ensure that divert-to works as
expected, even if ipfw is loaded.

divert(4)
PR:		272770
MFC after:	3 weeks
Reviewed by:	kp
Differential Revision:	https://reviews.freebsd.org/D42142
2023-10-19 12:12:15 +02:00
Kristof Provost 81647eb60e pf: implement start/stop calls via netlink
Implement equivalents to DIOCSTART and DIOCSTOP in netlink. Provide a
libpfctl implementation and add a basic test case, mostly to verify that
we still return the same errors as before the conversion

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D42145
2023-10-13 09:53:22 +02:00
Kristof Provost a7191e5d7b pf: add a way to list creator ids
Allow userspace to retrieve a list of distinct creator ids for the
current states.

This is used by pfSense, and used to require dumping all states to
userspace. It's rather inefficient to export a (potentially extremely
large) state table to obtain a handful (typically 2) of 32-bit integers.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D42092
2023-10-10 11:48:21 +02:00
Brad Davis 7bf5f682c0 Improve the pf nat exhaustion test by checking the reply from the echo server
Event:	Oslo Hackathon
Approved by:	kp
2023-10-06 09:19:51 -06:00