Commit Graph

493 Commits

Author SHA1 Message Date
Igor Ostapenko
74081dc2bc sys/netpfil/ipfw/ip_fw2.c: typo (Compatiblity)
https://bugs.freebsd.org/269753

PR:                      269753
Reported by:             Igor Ostapenko
Approved by:             doc, src (delphij, imp, zlei)
Differential revision:   https://reviews.freebsd.org/D38741
2023-05-05 01:23:08 +01:00
Boris Lytochkin
fc727ad63d ipfw: add [fw]mark implementation for ipfw
Packet Mark is an analogue to ipfw tags with O(1) lookup from mbuf while
regular tags require a single-linked list traversal.
Mark is a 32-bit number that can be looked up in a table
[with 'number' table-type], matched or compared with a number with optional
mask applied before comparison.
Having generic nature, Mark can be used in a variety of needs.
For example, it could be used as a security group: mark will hold a security
group id and represent a group of packet flows that shares same access
control policy.

Reviewed By: pauamma_gundo.com
Differential Revision: https://reviews.freebsd.org/D39555
MFC after:	1 month
2023-04-25 12:40:23 +00:00
Gleb Smirnoff
caf32b260a pfil: add pfil_mem_{in,out}() and retire pfil_run_hooks()
The 0b70e3e78b changed the original design of a single entry point
into pfil(9) chains providing separate functions for the filtering
points that always provide mbufs and know the direction of a flow.
The motivation was to reduce branching.  The logical continuation
would be to do the same for the filtering points that always provide
a memory pointer and retire the single entry point.

o Hooks now provide two functions: one for mbufs and optional for
  memory pointers.
o pfil_hook_args() has a new member and pfil_add_hook() has a
  requirement to zero out uninitialized data. Bump PFIL_VERSION.
o As it was before, a hook function for a memory pointer may realloc
  into an mbuf.  Such mbuf would be returned via a pointer that must
  be provided in argument.
o The only hook that supports memory pointers is ipfw:default-link.
  It is rewritten to provide two functions.
o All remaining uses of pfil_run_hooks() are converted to
  pfil_mem_in().
o Transparent union of pfil_packet_t and tricks to fix pointer
  alignment are retired. Internal pfil_realloc() reduces down to
  m_devget() and thus is retired, too.

Reviewed by:		mjg, ocochard
Differential revision:	https://reviews.freebsd.org/D37977
2023-02-14 10:02:49 -08:00
Justin Hibbits
3d0d5b21c9 IfAPI: Explicitly include <net/if_private.h> in netstack
Summary:
In preparation of making if_t completely opaque outside of the netstack,
explicitly include the header.  <net/if_var.h> will stop including the
header in the future.

Sponsored by:	Juniper Networks, Inc.
Reviewed by:	glebius, melifaro
Differential Revision: https://reviews.freebsd.org/D38200
2023-01-31 15:02:16 -05:00
Justin Hibbits
e81fcbece8 ipfw: Constify name argument for hash lookup
The name doesn't get modified, and it gets passed through to a hash
function that accepts only a const pointer.  Const it for correctness.

Sponsored by:	Juniper Networks, Inc.
2022-12-20 11:18:49 -05: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
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
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
Mateusz Guzik
2c1ac3d4d4 nat64: fix whitespace damage in callout calls
No functional changes.
2022-08-27 19:06:41 +00: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
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
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
c21cbaca2b dummynet: handle IPV6 layer 2 traffic
When pf sends layer 2 traffic into dummynet it still marks IPv6 with
IPFW_ARGS_IPV6 (which dummynet translates to PROTO_V6). That in turn
results in it not matching the 'DIR_IN | PROTO_LAYER2' case, and
triggering the 'bad switch' error message.

Add extra cases for LAYER2 | PROTO_IPV6.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-06-30 13:36:26 +02:00
Arseny Smalyuk
81cac3906e ipfw: add support radix tables and table lookup for MAC addresses
By analogy with IP address matching, add a way to use ipfw radix
tables for MAC matching. This is implemented using new ipfw table
with mac:radix type. Also there are src-mac and dst-mac lookup
commands added.

Usage example:
  ipfw table 1 create type mac
  ipfw table 1 add 11:22:33:44:55:66/48
  ipfw add skipto tablearg src-mac 'table(1)'
  ipfw add deny src-mac 'table(1, 100)'
  ipfw add deny lookup dst-mac 1

Note: sysctl net.link.ether.ipfw=1 should be set to enable ipfw
filtering on L2.

Reviewed by:	melifaro
Obtained from:	Yandex LLC
MFC after:	1 month
Relnotes:	yes
Sponsored by:	Yandex LLC
Differential Revision:	https://reviews.freebsd.org/D35103
2022-06-04 19:12:29 +03:00
Kristof Provost
12c542cd0e dummynet: do not store struct ifnet pointers
The dn_pkt_tag tag contained a struct ifnet pointer. If we persist that
across NET_EPOCH boundaries (as we did in dummynet) we risk panics if
the interface is removed between the packet being enqueued and it being
dequeued.

Convert the pointer into an index/generation pair and restore it when
the packet is taken out of the queue.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D35256
2022-05-20 14:49:30 +02:00
Gleb Smirnoff
8ef7beb29e dummynet: use m_rcvif_serialize/restore when queueing packets
This fixed panic with interface being removed while packet
was sitting on a queue.  This allows to pass all dummynet
tests including forthcoming dummynet:ipfw_interface_removal
and dummynet:pf_interface_removal and demonstrates use of
m_rcvif_serialize() and m_rcvif_restore().

Reviewed by:		kp
Differential revision:	https://reviews.freebsd.org/D33267

(cherry picked from commit 165746f4e4)
2022-05-05 14:38:07 -04:00
Marko Zec
894c574ed2 Revert "dummynet: use m_rcvif_serialize/restore when queueing packets"
This reverts commit 165746f4e4.

Obtained from: github.com/glebius/FreeBSD/commits/backout-ifindex
2022-05-03 19:11:40 +02:00
John Baldwin
3320ca1205 ipfw: icmp6_type is only used for INET6. 2022-04-13 16:08:21 -07:00
Andrey V. Elsukov
4763c0aa68 ipfw: fix matching and setting DSCP value for IPv6
Matching for DSCP codes has used incorrect bits. Use IPV6_DSCP()
macro for matching opcodes to fix this. Also this leads to always
use value from a mbuf instead of cached value.

Previously different opcodes have used both cached in f_id value
and stored in the mbuf, and it did not always work after setdscp
action, since cached value was not updated.

Update IPv6 flowid value cached in the f_id.flow_id6 when we do
modification of DSCP value in O_SETDSCP opcode, it may be used by
external modules.

Also added logging support for O_SETDSCP opcode.

Reviewed by:	kp
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D34807
2022-04-11 13:13:49 +03:00
Gordon Bergling
647baadf3c netpfil: Fix a typo in a source code comment
- s/maintance/maintenance/

MFC after:	3 days
2022-04-09 09:13:46 +02:00
Gordon Bergling
f70fc4377f netpfil: Fix two typo in source code comments
- s/measurment/measurement/

While here, also fix some whitespace issues.

MFC after:	3 days
2022-04-02 14:18:11 +02:00
Kristof Provost
3f3e4f3c74 dummynet: don't use per-vnet locks to protect global data.
The ref_count counter is global (i.e. not per-vnet) so we can't use a
per-vnet lock to protect it. Moreover, in callouts curvnet is not set,
so we'd end up panicing when trying to use DN_BH_WLOCK().

Instead we use the global sched_lock, which is already used when
evaluating ref_count (in unload_dn_aqm()).

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D34059
2022-02-07 22:59:46 +01:00
Kristof Provost
9dac026822 dummynet: dn_dequeue() may return NULL
If there are no more entries, or if we fail to restore the rcvif of a
queued mbuf dn_dequeue() can return NULL.
Cope with this.

Reviewed by:	glebius
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D34078
2022-01-28 23:09:08 +01:00
Gleb Smirnoff
165746f4e4 dummynet: use m_rcvif_serialize/restore when queueing packets
This fixed panic with interface being removed while packet
was sitting on a queue.  This allows to pass all dummynet
tests including forthcoming dummynet:ipfw_interface_removal
and dummynet:pf_interface_removal and demonstrates use of
m_rcvif_serialize() and m_rcvif_restore().

Reviewed by:		kp
Differential revision:	https://reviews.freebsd.org/D33267
2022-01-26 21:58:50 -08:00
Mateusz Guzik
60a28b0916 ipfw: plug set-but-not-used vars
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2021-12-18 13:21:03 +00:00
Franco Fichtner
1de20ebc46 dummynet: drop unused definitions
Reviewed by:	kp
Differential Revision:	https://reviews.freebsd.org/D33429
2021-12-14 13:01:15 +01:00
Mark Johnston
1c732c8591 dummynet: Fix socket option length validation for IP_DUMMYNET3
The socket option handler tries to ensure that the option length is no
larger than some reasonable maximum, and no smaller than sizeof(struct
dn_id).  But the loaded option length is stored in an int, which is
converted to an unsigned integer for the comparison with a size_t, so
negative values are not caught and instead get passed to malloc().

Change the code to use a size_t for the buffer size.

Reviewed by:	kp
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33133
2021-11-29 13:57:24 -05:00
Mark Johnston
d5ea04ee7b dummynet: Avoid an out-of-bounds read in do_config()
do_config() processes a buffer of variable-length dummynet commands.
The loop which processes this buffer loads the fixed-length header
before checking whether there are any bytes left to read, so it performs
a 4-byte read past the end of the buffer before terminating.

Restructure the loop to avoid this.

Reported by:	Jenkins (KASAN job)
Reviewed by:	kp
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33132
2021-11-29 13:57:24 -05:00
Mark Johnston
44775b163b netinet: Remove unneeded mb_unmapped_to_ext() calls
in_cksum_skip() now handles unmapped mbufs on platforms where they're
permitted.

Reviewed by:	glebius, jhb
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33097
2021-11-24 13:31:16 -05:00
Gleb Smirnoff
0dff875fa9 ipfw: remove unnecessary TCP related includes 2021-11-18 00:54:28 -08:00
Kristof Provost
76c5eecc34 pf: Introduce ridentifier
Allow users to set a number on rules which will be exposed as part of
the pflog header.
The intent behind this is to allow users to correlate rules across
updates (remember that pf rules continue to exist and match existing
states, even if they're removed from the active ruleset) and pflog.

Obtained from:	pfSense
MFC after:	3 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D32750
2021-11-05 09:39:56 +01:00
Kristof Provost
63b3c1c770 pf: support dummynet
Allow pf to use dummynet pipes and queues.

We re-use the currently unused IPFW_IS_DUMMYNET flag to allow dummynet
to tell us that a packet is being re-injected after being delayed. This
is needed to avoid endlessly looping the packet between pf and dummynet.

MFC after:	2 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D31904
2021-09-24 11:41:25 +02:00
Kristof Provost
8160a0f62b dummynet: Does not depend on ipfw
Allow the dummynet module to be loaded without ipfw, as a first step
towards making pf use it for packet scheduling.

Reviewed by:	donner
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D31903
2021-09-24 11:41:25 +02:00
Kristof Provost
415e81d5d9 dummynet: remove unused definitions
No functional change.

MFC after:	2 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D31806
2021-09-08 17:18:00 +02:00
Andrey V. Elsukov
da3a09d894 ipfw_nat64: fix direct output mode
In nat64_find_route[46] handle NHF_GATEWAY flag and use destination
address from next hop to do link layer address lookup.

PR:		255928
Reviewed by:	melifaro
Obtained from:	Yandex LLC
MFC after:	1 week
Sponsored by:	Yandex LLC
Differential Revision:	https://reviews.freebsd.org/D31680
2021-08-26 13:48:23 +03:00
Luiz Otavio O Souza
20ffd88ed5 ipfw: use unsigned int for dummynet bandwidth
This allows the maximum value of 4294967295 (~4Gb/s) instead of previous
value of 2147483647 (~2Gb/s).

Reviewed by:	np, scottl
Obtained from:	pfSense
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D31582
2021-08-19 10:48:53 +02:00
Andrey V. Elsukov
322e5efda8 ipfw: fix possible data race between jump cache reading and updating.
Jump cache is used to reduce the cost of rule lookup for O_SKIPTO and
O_CALLRETURN actions. It uses rules chain id to check correctness of
cached value. But due to the possible race, there is the chance that
one thread can read invalid value. In some cases this can lead to out
of bounds access and panic.

Use thread fence operations to constrain the reordering of accesses.
Also rename jump_fast and jump_linear functions to jump_cached and
jump_lookup_pos respectively.

Submitted by:	Arseny Smalyuk
Reviewed by:	melifaro
Obtained from:	Yandex LLC
MFC after:	1 week
Sponsored by:	Yandex LLC
Differential Revision:	https://reviews.freebsd.org/D31484
2021-08-17 11:08:28 +03:00
Luiz Otavio O Souza
c5dd8bac0b dummynet: reduce console spam
Only print this warning when boot verbose is enabled.
This can get pretty annoying (and useless) in some systems.

Reviewed by:	kp
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2021-07-08 20:25:05 +02:00
Kristof Provost
8f76eebce4 dummynet: fix sysctls
The sysctl nodes which use V_dn_cfg must be marked as CTLFLAG_VNET so
that we use the correct per-vnet offset

PR:		256819
Reviewed by:	donner
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D30974
2021-07-01 21:34:08 +02:00
Mark Johnston
bc6a2267ff ipfw: Update the pfil mbuf pointer in ipfw_check_frame()
ipfw_chk() might call m_pullup() and thus can change the mbuf chain
head.  In this case, the new chain head has to be returned to the pfil
hook caller, otherwise the pfil hook caller is left with a dangling
pointer.

Note that this affects only the link-layer hooks installed when the
net.link.ether.ipfw sysctl is set to 1.

PR:		256439, 254015, 255069, 255104
Fixes:		f355cb3e6
Reviewed by:	ae
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D30764
2021-06-16 09:46:56 -04:00
Kristof Provost
1b2dbe37fa dummynet: free(NULL, M_DUMMYNET); is safe
There's no need to check pointers for NULL before free()ing them.

No functional change.

MFC after:	2 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D30382
2021-06-03 09:02:53 +02:00