Commit Graph

1047 Commits

Author SHA1 Message Date
Cy Schubert
1ffab636da ipfilter: Document count_mask_bits() arguments
Document arguments input to count_mask_bits().

MFC after:	3 days
2022-11-15 13:11:16 -08:00
Kristof Provost
48767d8734 pfsync: fix memory leak
The recent refactoring to prepare for pfsync over IPv6 introduced a
memory leak.
If we don't have a sync peer configured we return early (without sending
out a packet), but failed to free the newly allocated packet.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-11-15 12:13:11 +01:00
Dag-Erling Smørgrav
1854fb8fd8 ipfw: Spell PFIL_PASS correctly.
Sponsored by:	Netapp
Sponsored by:	Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D37375
2022-11-14 12:20:19 +01:00
Kristof Provost
26b9e1f07f dummynet: fix codel
Serialize rcvif when enqueing packets for codel. We already tried to
restore the serialized rcvif in fq_codel_extract_head(), but that
doesn't work when we fail to serialize it first, so we ended up dropping
all packets passed through codel.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D37318
2022-11-11 11:53:31 +01:00
Luiz Amaral
813c5b75e6 pfsync: prepare code to accommodate AF_INET6 family
Work is ongoing to add support for pfsync over IPv6. This required some
changes to allow for differentiating between the two families in a more
generic way.

This patch converts the relevant ioctls to using nvlists, making future
extensions (such as supporting IPv6 addresses) easier.

Sponsored by:	InnoGames GmbH
Differential Revision:	https://reviews.freebsd.org/D36277
2022-11-09 21:06:07 +01:00
Richard Scheffenegger
0b00b80149 ipfw: Have NAT steal the TH_RES1 bit, instead of the TH_AE bit
The NAT module use of the tcphdr.th_x2 field now collides with the
use of this TCP header flag as AccECN (AE) bit. Use the topmost
bit instead to allow negotiation of AccECN across a NAT device.

Event:			IETF 115 Hackathon
Reviewed By:		#transport, tuexen
MFC after:		3 days
Sponsored by:		NetApp, Inc.
Differential Revision:	https://reviews.freebsd.org/D37300
2022-11-09 11:19:19 +01:00
Elliott Mitchell
21cc0918c7 sys: Nuke double-semicolons
A distinct number of double-semicolons have ended up in FreeBSD.  Take a
pass at getting rid of many of these harmless typos.

Reviewed by: emaste, rrs
Pull Request: https://github.com/freebsd/freebsd-src/pull/609
Differential Revision: https://reviews.freebsd.org/D31716
2022-11-02 09:34:20 -06:00
Kristof Provost
8a8af94240 pf: bridge-to
Allow pf (l2) to be used to redirect ethernet packets to a different
interface.

The intended use case is to send 802.1x challenges out to a side
interface, to enable AT&T links to function with pfSense as a gateway,
rather than the AT&T provided hardware.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D37193
2022-11-02 15:45:23 +01:00
Kristof Provost
444a77ca85 pf: expose syncookie active/inactive status
When syncookies are in adaptive mode they may be active or inactive.
Expose this status to users.

Suggested by:	Guido van Rooij
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-10-31 18:14:09 +01:00
Gordon Bergling
558ec54da3 netpfil: Fix two typos in source code comments
- s/missmatch/mismatch/

MFC after:	3 days
2022-10-25 04:32:59 +02:00
Kristof Provost
b37707bb39 pf: fix LINT-NOINET6 build 2022-10-15 10:02:35 +02:00
Kristof Provost
a974702e27 pf: apply the network stack's ICMP rate limiting to ICMP errors sent by pf
PR:		266477
Event:		Aberdeen Hackathon 2022
Differential Revision:	https://reviews.freebsd.org/D36903
2022-10-14 10:36:16 +02:00
Kristof Provost
133935d26f pf: atomically increment state ids
Rather than using a per-cpu state counter, and adding in the CPU id we
can atomically increment the number.
This has the advantage of removing the assumption that the CPU ID fits
in 8 bits.

Event:		Aberdeen Hackathon 2022
Reviewed by:	mjg
Differential Revision:	https://reviews.freebsd.org/D36915
2022-10-08 18:27:29 +02:00
Kristof Provost
1d090028d3 pf: use time_to for timestamps
Use time_t rather than uint32_t to represent the timestamps. That means
we have 64 bits rather than 32 on all platforms except i386, avoiding
the Y2K38 issues on most platforms.

Reviewed by:	Zhenlei Huang
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D36837
2022-10-05 17:52:27 +02:00
John Baldwin
9c4f7e8234 ipfilter: Cast uintmax_t values to size_t when adding to a pointer.
GCC warns about the mismatched sizes on 32-bit platforms where
uintmax_t is larger in size than a pointer.

Reviewed by:	imp, cy
Differential Revision:	https://reviews.freebsd.org/D36753
2022-09-28 13:58:34 -07:00
Kristof Provost
0044bd90f2 pf: fix memory leak retrieving Ethernet rules
Remember to free the nvlist we've added to our main nvlist.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-09-27 15:28:37 +02:00
Alexander V. Chernikov
91ebcbe02a if_clone: migrate some consumers to the new KPI.
Convert most of the cloner customers who require custom params
 to the new if_clone KPI.

Reviewed by:	kp
Differential Revision:	https://reviews.freebsd.org/D36636
MFC after:	2 weeks
2022-09-22 12:30:09 +00:00
Gordon Bergling
d53555d63b netpfil: Fix some typos in source code comments
- s/paramter/parameter/
- s/paramters/parameters/

MFC after:	3 days
2022-09-15 10:24:00 +02:00
Mateusz Guzik
e5d08f4729 pf: remove pf_bcmp_state_key
Clang 14 performs the optimisation on its own, thus the custom code is
no longer needed.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-09-09 17:16:58 +00:00
Mateusz Guzik
6b94546a7e pf: partially depessimize pf_match_translation
Reviewed by:	kp
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-09-09 17:03:55 +00:00
Cy Schubert
1f7a710ab3 ipfilter: Remove unused ioctl
The SIOCSTAT1 ioctl is only used in ip_auth and is unused in ip_state.
The ip_state version was likely added to support a new statistic yet
to be developed in ipfstat(8) or for some sample userspace application
(similar in fashion to the sample provided for authentication rules).
There is no need to report individual state hash table bucket lengths
to any future userspace application.

If needed for any future debugging purposes a DTrace probe would be a
better vehicle.

This unused ioctl in ip_stat results in a panic.

PR:		266124
Reported by:	Robert Morris <rtm@lcs.mit.edu>
MFC after:	3 days
2022-09-06 19:57:05 -07:00
Cy Schubert
3e81ef62f9 ipfilter: Remove IPL_SELECT
IPL_SELECT was used for HP-UX >= 11.11 only. Remove this de trop code.

MFC after:	3 days
2022-09-06 19:56:35 -07:00
Mateusz Guzik
69ce6ae21a pf: make pfsync_state_import appease an assert in pf_free_state
The newly created state failed to be inserted anywhere. This follows
other places.

Reviewed by:	kp
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-09-06 15:00:46 +00:00
Mateusz Guzik
9503043f6e pf: stop using PFIL_FWD
It is only there to check if the packet was reassembled,
relevant if we are forwarding. But if the packet originated
locally it could not have been reassembled, thus the flag is
redundant.

Reviewed by:	kp
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-09-05 13:06:12 +00:00
Gordon Bergling
4d89e2018c netpfil: Correct some typos in source code comments
- s/occured/occurred/
- s/the the/the/

MFC after:	3 days
2022-09-04 12:46:05 +02:00
Gordon Bergling
fd2235ffdc netpfil: Fix a typo in a source code comment
- s/intergers/integers/

While here, fix some whitespace issues.

MFC after:	3 days
2022-09-03 19:18:54 +02:00
Kristof Provost
6ab80e7275 pf: do not block new Ethernet rules for in-progress transactions
Make Ethernet rule addition behave just like L3 rules, in that we now
allow ongoing transaction to be interrupted, rather than rejecting a new
one.

The result of that is that we can no longer end up in a state where a
transaction failed, but was not rolled back, blocking us from setting
new rules.

It's safe to assume there's no pending epoch callback for cleanup here,
because we've explicitly called it before hitting pf_begin_eth().

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-08-27 22:25:01 +02:00
Mateusz Guzik
2c1ac3d4d4 nat64: fix whitespace damage in callout calls
No functional changes.
2022-08-27 19:06:41 +00:00
Luiz Amaral
485be9798a pfsync: replace struct pfsync_pkt with int flags
Get rid of struct pfsync_pkt. It was used to store data on the stack to
pass to all the submessage handlers, but only the flags part of it was
ever used. Just pass the flags directly instead.

Reviewed by:		kp
Obtained from:		OpenBSD
Sponsored by:		InnoGames GmbH
Differential Revision:	https://reviews.freebsd.org/D36294
2022-08-22 23:46:50 +02:00
Ed Maste
6b598e263b pf: Reduce diffs against OpenBSD in pf_if.c
Use memset instead of bzero, memcpy instead of bcopy, and add some
optional {}s.

Reviewed by:	kp
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D36267
2022-08-20 11:52:05 -04:00
Kristof Provost
c780d3ad7b pf: clear ethernet rules prior to shutdown
Ethernet rule cleanup is postponed to an epoch callback. Ensure it's
been called before we remove the entire vnet, or we risk the rules still
getting hit after we've freed the uma zone, i.e. a use-after-free.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-08-19 14:53:09 +02:00
Gleb Smirnoff
78b1fc05b2 protosw: separate pr_input and pr_ctlinput out of protosw
The protosw KPI historically has implemented two quite orthogonal
things: protocols that implement a certain kind of socket, and
protocols that are IPv4/IPv6 protocol.  These two things do not
make one-to-one correspondence. The pr_input and pr_ctlinput methods
were utilized only in IP protocols.  This strange duality required
IP protocols that doesn't have a socket to declare protosw, e.g.
carp(4).  On the other hand developers of socket protocols thought
that they need to define pr_input/pr_ctlinput always, which lead to
strange dead code, e.g. div_input() or sdp_ctlinput().

With this change pr_input and pr_ctlinput as part of protosw disappear
and IPv4/IPv6 get their private single level protocol switch table
ip_protox[] and ip6_protox[] respectively, pointing at array of
ipproto_input_t functions.  The pr_ctlinput that was used for
control input coming from the network (ICMP, ICMPv6) is now represented
by ip_ctlprotox[] and ip6_ctlprotox[].

ipproto_register() becomes the only official way to register in the
table.  Those protocols that were always static and unlikely anybody
is interested in making them loadable, are now registered by ip_init(),
ip6_init().  An IP protocol that considers itself unloadable shall
register itself within its own private SYSINIT().

Reviewed by:		tuexen, melifaro
Differential revision:	https://reviews.freebsd.org/D36157
2022-08-17 11:50:31 -07:00
Gleb Smirnoff
05b9737f10 ipfw: make it possible to specify MTU for "unreach needfrag" action
Reviewed by:		ae, pauamma
Differential revision:	https://reviews.freebsd.org/D36140
2022-08-17 08:24:11 -07:00
Gleb Smirnoff
8c77967ecc protosw: retire pr_output method
The only place to execute this method was raw_usend(). Only those
protocols that used raw socket were able to actually enter that method.
All pr_output assignments being deleted by this commit were a dead code
for many years.

Reviewed by:		melifaro
Differential revision:	https://reviews.freebsd.org/D36126
2022-08-11 09:19:37 -07:00
Zhenlei Huang
150486f6a9 Introduce and use the NET_EPOCH_DRAIN_CALLBACKS() macro
Reviewed by:	melifao, kp
Differential Revision:	https://reviews.freebsd.org/D35968
2022-07-29 21:21:10 +02:00
Dimitry Andric
766f3c8032 Adjust function definitions in if_pfsync.c to avoid clang 15 warnings
With clang 15, the following -Werror warnings are produced:

    sys/netpfil/pf/if_pfsync.c:2439:21: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    pfsync_pointers_init()
                        ^
                         void
    sys/netpfil/pf/if_pfsync.c:2453:23: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    pfsync_pointers_uninit()
                          ^
                           void
    sys/netpfil/pf/if_pfsync.c:2503:12: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    pfsync_init()
               ^
                void
    sys/netpfil/pf/if_pfsync.c:2524:14: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    pfsync_uninit()
                 ^
                  void

This is because pfsync_pointers_init(), pfsync_pointers_uninit(),
pfsync_init(), and pfsync_uninit() are declared with (void) argument
lists, but defined with empty argument lists. Make the definitions match
the declarations.

MFC after:	3 days
2022-07-25 20:53:53 +02:00
Dimitry Andric
fb48e99850 Fix unused variable warning in if_pfsync.c
With clang 15, the following -Werror warning is produced:

    sys/netpfil/pf/if_pfsync.c:2153:9: error: variable 'sent' set but not used [-Werror,-Wunused-but-set-variable]
            int i, sent = 0;
                   ^

The 'sent' variable was used in the for loop later in the
pfsync_bulk_update() function, but refactoring in 4fc65bcbe3 got rid
of it. Remove the variable since it no longer serves any purpose.

MFC after:	3 days
2022-07-25 20:53:48 +02:00
Dimitry Andric
503b5870c0 Adjust function definitions in pf.c to avoid clang 15 warnings
With clang 15, the following -Werror warnings are produced:

    sys/netpfil/pf/pf.c:985:19: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    pf_mtag_initialize()
                      ^
                       void
    sys/netpfil/pf/pf.c:995:14: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    pf_initialize()
                 ^
                  void
    sys/netpfil/pf/pf.c:1089:16: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    pf_mtag_cleanup()
                   ^
                    void
    sys/netpfil/pf/pf.c:1096:11: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    pf_cleanup()
              ^
               void
    sys/netpfil/pf/pf.c:1989:27: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    pf_purge_expired_src_nodes()
                              ^
                               void
    sys/netpfil/pf/pf.c:2174:24: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    pf_purge_unlinked_rules()
                           ^
                            void

This is because pf_mtag_initialize(), pf_initialize(),
pf_mtag_cleanup(), pf_cleanup(), pf_purge_expired_src_nodes(), and
pf_purge_unlinked_rules() are declared with (void) argument lists, but
defined with empty argument lists. Make the definitions match the
declarations.

MFC after:	3 days
2022-07-25 20:02:31 +02:00
Dimitry Andric
1eea6b9097 Adjust ipfw_iface_{init,destroy}() definitions to avoid clang 15 warning
With clang 15, the following -Werror warnings are produced:

    sys/netpfil/ipfw/ip_fw_iface.c:206:16: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    ipfw_iface_init()
                   ^
                    void
    sys/netpfil/ipfw/ip_fw_iface.c:219:19: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    ipfw_iface_destroy()
                      ^
                       void

This is because ipfw_iface_init() and ipfw_iface_destroy() are declared
with (void) argument lists, but defined with empty argument lists. Make
the definitions match the declarations.

MFC after:	3 days
2022-07-21 21:38:17 +02:00
Dimitry Andric
4100dc46c7 Adjust iface_khandler_deregister() definition to avoid clang 15 warning
With clang 15, the following -Werror warning is produced:

    sys/netpfil/ipfw/ip_fw_iface.c:159:26: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    iface_khandler_deregister()
                             ^
                              void

This is because iface_khandler_deregister() is declared with a (void)
argument list, but defined with an empty argument list. Make the
definition match the declaration.

MFC after:	3 days
2022-07-21 21:38:04 +02:00
Dimitry Andric
d62830c5e4 Adjust ipfw_{init,destroy}_sopt_handler() definitions to avoid clang 15 warning
With clang 15, the following -Werror warning are produced:

    sys/netpfil/ipfw/ip_fw_sockopt.c:3477:23: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    ipfw_init_sopt_handler()
                          ^
                           void
    sys/netpfil/ipfw/ip_fw_sockopt.c:3485:26: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    ipfw_destroy_sopt_handler()
                             ^
                              void

This is because ipfw_init_sopt_handler() and ipfw_destroy_sopt_handler()
are declared with (void) argument lists, but defined with empty argument
lists. Make the definitions match the declarations.

MFC after:	3 days
2022-07-21 21:30:40 +02:00
Dimitry Andric
edf1e1f78d Adjust iface_khandler_register() definition to avoid clang 15 warning
With clang 15, the following -Werror warning is produced:

    sys/netpfil/ipfw/ip_fw_iface.c:128:24: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    iface_khandler_register()
                           ^
                            void

This is because iface_khandler_register() is declared with a (void)
argument list, but defined with an empty argument list. Make the
definition match the declaration.

MFC after:	3 days
2022-07-21 21:30:35 +02:00
Dimitry Andric
62030bb853 Adjust ipfw_{init,destroy}_*() definitions to avoid clang 15 warning
With clang 15, the following -Werror warnings are produced:

    sys/netpfil/ipfw/ip_fw_sockopt.c:187:19: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    ipfw_init_counters()
                      ^
                       void
    sys/netpfil/ipfw/ip_fw_sockopt.c:196:22: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    ipfw_destroy_counters()
                         ^
                          void
    sys/netpfil/ipfw/ip_fw_sockopt.c:3241:23: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    ipfw_init_obj_rewriter()
                          ^
                           void
    sys/netpfil/ipfw/ip_fw_sockopt.c:3249:26: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    ipfw_destroy_obj_rewriter()
                             ^
                              void

This is because ipfw_init_counters(), ipfw_destroy_counters(),
ipfw_init_obj_rewriter(), and ipfw_destroy_obj_rewriter() are declared
with (void) argument lists, but defined with empty argument lists. Make
the definitions match the declarations.

MFC after:	3 days
2022-07-21 21:30:29 +02:00
Dimitry Andric
5c329f0a4d Suppress unused variable warning in ip_dummynet.c
With clang 15, the following -Werror warning is produced:

    sys/netpfil/ipfw/ip_dummynet.c:802:6: error: variable 'n' set but not used [-Werror,-Wunused-but-set-variable]
            int n = 0; /* only for stats */
                ^

Here, 'n' is a variable that is only used when debugging. Mark the
variable as potentially unused, to suppress the warning.

MFC after:	3 days
2022-07-20 17:13:49 +02:00
Kristof Provost
16899291de dummynet: check for ifp on all PROTO_LAYER2 packets
When we extended the switch statement to allow for PROTO_LAYER2 |
PROTO_IPV6 in c21cbaca2b we didn't extend the check for a non-NULL
struct ifnet pointer.
Happily the only PROTO_IPV6 case is pf's layer 2 support, which always
provides one.

Reported by:	Coverity (CID 1490459)
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-07-11 22:07:11 +02:00
Cy Schubert
c47db49ba4 ipfilter: Support only jails in VNET
Jails without VNET have complete access to the ipfilter rules, NAT,
pools and logs. This is insecure. Only allow jails to manipulate
ipfilter rules, NAT tables and ippools if the jail has its own VNET.
Otherwise a jail can affect the global system.

This patch brings ipfilter in line with ipfw's support of VNET jails and
non-support of non-VNET jails.

MFC after:	1 week
2022-07-07 07:53:45 -07:00
Kristof Provost
cbb019b831 dummynet: fix ip_dn_vnet_init() / dummynet_task() race
If dummynet_task() is run on a vnet where dummynet is still initialising
(i.e. still running ip_dn_vnet_init()) we can attempt to use an
uninitialised mutex.

We can use the existing init_done field to check if the per-vnet
V_dn_cfg is fully set up, if we ensure that it's only set to 1 when
we've done all of the init work.

Reported by:	Alfredo Dal'Ava Júnior <alfredo@freebsd.org>
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D35716
2022-07-05 18:59:00 +02:00
Kristof Provost
ba3b6b938d pf: handle dummynet for non-IP packets
Do not panic if we try to dummynet an Ethernet packet that's not IPv4 or
IPv6. Simply give it to dummynet.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-07-01 14:31:57 +02:00
Mark Johnston
333670372f pf: Make sure that pfi_update_status() always zeros counters
pfi_update_status() can return early if the status interface doesn't
exist.  But in this case pf_getstatus() was copying uninitialized stack
memory into the output nvlist.

Reported by:	Jenkins (KMSAN job)
Reviewed by:	kp
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35659
2022-06-30 10:31:26 -04:00
Mark Johnston
bc83b35922 pf: Ensure that pfiio_name is always nul terminated
Reported by:	syzkaller
Reviewed by:	kp
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35660
2022-06-30 10:31:26 -04:00