Commit Graph
108 Commits
Author SHA1 Message Date
Tobias Brunner e175abaf89 include: Add XFRM mode and attributes for IP-TFS 2025-05-28 16:37:46 +02:00
Tobias Brunner d83fbe82e4 kernel-netlink: Suppress NAT mapping updates for per-CPU SAs
As we set the remote port to 0, we'd get a mapping change message with
every packet. Setting the threshold avoids all kernel messages after the
first, which we suppress explicitly as well.
2025-05-28 16:35:27 +02:00
Tobias Brunner a950ca3ec2 kernel-netlink: Forward CPU ID from acquires 2025-05-28 16:35:27 +02:00
Tobias Brunner d6eed3979b kernel-interface: Optionally pass CPU ID for which an acquire was triggered 2025-05-28 16:35:27 +02:00
Tobias Brunner bdfcfea1f2 kernel-netlink: Add support to enable per-CPU acquires on policies 2025-05-28 16:35:26 +02:00
Tobias Brunner 53be94d06c kernel-netlink: Add support to set CPU ID on SA 2025-05-28 16:35:26 +02:00
Tobias Brunner aa1322aed5 include: Add XFRM identifiers for per-CPU SAs/acquires 2025-05-28 16:35:26 +02:00
Tobias Brunner b024b7e9a6 kernel-netlink: Add support for acquire sequence numbers
Note that while PF_KEYv2 also uses sequence numbers to identify acquires,
which we currently don't use correctly by the way, it does not include
information about the packet that triggered an acquire.  What we receive
in src and dst, and currently forward as traffic selectors, are actually
the designated endpoints of the SA. So especially in tunnel mode this is
useless to do narrowing on the responder (these addresses might not even
match the configured TS).
2025-05-28 10:01:19 +02:00
Tobias Brunner 57e74f64b3 kernel-netlink: Enable UDP GRO
This enables GRO offload for inbound ESP-in-UDP packets if the
esp4|6_offload modules are loaded.  Note that inbound ESP or ESP-in-UDP
packets won't be visible on layer 3 in Netfilter or tcpdump.
2025-04-14 11:39:44 +02:00
Tobias Brunner 22eded1da4 kernel-netlink: Set replay window 0 if kernel supports SA direction attribute
The kernel now allows a 0 replay window with ESN for SAs that are
explicitly tagged as outbound SAs.  But not just that, it actually
rejects outbound SAs with replay windows > 0.  So we add a version check
to control the replay window size.  Note that adding the attribute
unconditionally would be fine even for older kernels, but if somebody
backports the direction patches, the installation of outbound SAs might
fail if the replay window is not adjusted accordingly.
2024-08-07 14:41:28 +02:00
Tobias Brunner 661f6bd0ad kernel-netlink: Add SA direction attribute 2024-08-07 14:41:28 +02:00
Tobias Brunner 2601fabbb4 kernel-netlink: Only disable DF-flag copying on outbound SAs
This will cause errors on inbound SAs if the SA direction attribute is
used.
2024-08-07 14:41:28 +02:00
Tobias Brunner dc8fa1b3e8 kernel-netlink: Add missing names for XFRM message types and attributes 2024-08-07 14:41:28 +02:00
Tobias Brunner 1f5aa8017f Revert "kernel-netlink: Never use XFRMA_REPLAY_ESN_VAL to configure zero replay windows"
This reverts commit 8b9b11919d.

Since ESN was negotiated via proposal, just configuring the SA without
ESN won't work as the ICV will be incorrect if the peer enabled ESN
on its SA.  While the Linux kernel currently doesn't support disabling
replay protection for SAs that use ESN, this at least gets users an
explicit error not just dropped packets, and it will automatically work
if the kernel supports this combination at some point.

References strongswan/strongswan#2117
2024-02-23 18:00:32 +01:00
Tobias Brunner 14bd0bc743 Fixed some typos, courtesy of codespell 2023-11-14 10:11:16 +01:00
Tobias Brunner 3cb8434367 kernel-netlink: Don't add replay state twice when updating SAs
The kernel includes the XFRMA_REPLAY_ESN_VAL attribute when dumping
SAs since it was added with 2.6.39.  So we basically added this attribute
twice to the message sent to the kernel, potentially exceeding the
message buffer if the window size is large.

The XFRMA_REPLAY_VAL attribute is only dumped since 3.19, so that might
still be relevant (Google seems to maintain a 3.18 kernel) and since we
have to query the current lifetime stats anyway, we can just avoid adding
this attribute twice.

Closes strongswan/strongswan#1967
2023-11-13 12:36:57 +01:00
Tobias Brunner d0ef504614 kernel-netlink: Fix build with DEBUG_LEVEL < 2 2023-05-08 17:32:18 +02:00
Tobias Brunner 04486507b2 kernel-netlink: Add an option to install routes for SAs with XFRM interfaces
Since these might conflict with IKE traffic, this requires special care.
One option is to install bypass policies for the peer, which install
appropriate (throw) routes.  However, that won't work if the traffic to
the gateway itself should be protected, in particular, for host-to-host
tunnels.  So an alternative is to set a mark for the IKE socket and then
exclude that traffic from table 220 via the kernel-netlink plugin's
fwmark option.
2023-02-22 13:37:45 +01:00
Tobias Brunner e1ff1eefcf kernel-netlink: Add manager for XFRM interfaces
The manager will allow charon-nm to create XFRM interfaces if supported
by the kernel instead of creating an unused dummy TUN interface.

The xfrmi tool is mostly obsolete nowadays as iproute2 supports creating
XFRM interfaces since 5.1.0 (2019-05).  Older Debians don't ship that and
early versions didn't list the interface IDs.  So there might still be
some uses for this tool.
2023-02-22 13:37:45 +01:00
Tobias Brunner e21290ec30 kernel-netlink: Read last use time from SA if possible
Since 6.2 the Linux kernel updates the last use time per SA.  In
previous releases the attribute was only updated and reported for
specific outbound IPv6 SAs.

Using this reduces the number of kernel queries per CHILD_SA: for DPDs
from two policy queries (IN/FWD) to a single query of the inbound SA,
and for status reports the three policy queries (IN/FWD/OUT) can be
omitted and only the two SAs have to be queried.  For NAT keepalives the
number of queries doesn't change but a policy query (OUT) is replaced by
a query for the outbound SA.

While we could use the existence of the attribute as indicator for its
support, we don't know this until we queried an SA.  By using a version
check we can announce the feature from the start.
2023-02-22 13:20:10 +01:00
Tobias Brunner 15c6360145 kernel-netlink: Offload bypass policies for IKE ports on interfaces
While this uses the same mechanism, it's not necessary to explicitly
enable port_bypass, the regular socket policies work fine to bypass any
software policies.
2023-02-16 14:45:57 +01:00
Tobias Brunner 77a5c9514c kernel-netlink: Use event socket wrapper for XFRM and networking events 2023-02-16 13:25:35 +01:00
Tobias Brunner d7ccb44354 kernel-netlink: Always register for events
The starter-specific code path isn't necessary anymore since
d8fdd1018e ("starter: Don't flush SAs in the kernel").
2023-02-16 13:25:35 +01:00
Tobias Brunner 68ccb1930c kernel-netlink: Fallback to configured interface when HW offloading policies
This allows offloading bypass and drop policies to a specific interface
by configuring `interface` and `hw_offload=packet` (`auto` works too).
2023-02-16 13:25:34 +01:00
Tobias Brunner 55719d7de5 kernel-netlink: Add support for full packet and policy HW offloading 2023-02-16 13:25:34 +01:00
Tobias Brunner 7988aea7d8 kernel-netlink: Log extended ACK error/warning messages
With newer kernels (basic support for extended ACKs is there since 4.12
but some messages for XFRM were only added with 6.1) this gives more
detailed error messages to the user than e.g. a generic EINVAL or ENOSYS
error would.

Also enabled omitting the request payload in NLMSG_ERROR messages.
2022-12-21 16:21:49 +01:00
Noel Kuntze cf16556248 kernel-netlink: Increase debug level of the "querying [...]" log messages
When watching the output of `swanctl -l` during debugging, the debug
messages in query_sa/policy() cause a lot of noise in the logs (level 2
for DBG_KNL still has actually useful information that we want to see
in the logs) and they're not very useful.

Compared to the messages in the functions above, the ones in update_sa()
and get_replay_state() are not seen often. But since there already is a
log message on level 2 in update_sa(), they're kinda redundant.

Closes strongswan/strongswan#1271
2022-09-16 16:40:06 +02:00
Tobias Brunner eab9cd8661 kernel-netlink: Fix compiler warnings with strncpy()
Normally, GCC sees that we terminate the destination with a zero byte.
However, when using `-fsanitize=address`, there seems to be additional
instrumentation code after strncpy() so GCC produces warnings like
these:

‘__builtin_strncpy’ specified bound 16 equals destination size [-Wstringop-truncation]
2022-09-15 12:16:12 +02:00
Tobias Brunner 19ef2aec15 Update copyright headers after acquisition by secunet 2022-06-28 10:22:56 +02:00
Tobias Brunner f52e565ad3 kernel-netlink: Forward labels from acquires 2022-04-14 18:42:01 +02:00
Tobias Brunner 96ecc39cd0 kernel-netlink: Allow reqid updates for policies again
This was originally added with 1551d8b13d ("kernel-netlink: reject
policy refcount if the reqid differs").  Since then we added code to
allocate constant reqids for the same TS, which pretty much avoids the
previous issues.

However, the reqid might have to be changed due to MOBIKE updates. And
because reqids are allocated for a complete set of traffic selectors and
not individual pairs, this can create a problem with drop policies as
those will use the old reqid (they are installed with the same priority,
reqid etc. to replace the actual IPsec policies), while unmodified
replacement policies will use the new one.  A similar issue exists for
CHILD_SAs with SELinux contexts as those all use duplicate policies (same
generic label) but can't all be updated concurrently.
2022-04-14 18:42:01 +02:00
Tobias Brunner 1b3af3e37d kernel-interface: Add support to change the reqid in update_sa() 2022-04-14 18:42:01 +02:00
Tobias Brunner bf0542c4e1 kernel-netlink: Add support for optional security label on SAs and policies 2022-04-14 18:42:01 +02:00
Tobias Brunner 3b699c720f kernel-listener: Use a struct to pass data from acquires 2022-04-14 18:42:01 +02:00
Tobias Brunner 9983326b20 kernel-netlink: Read protocol of acquire not from template
If a policy with IPComp template triggers an acquire, we get two, one for
an IPComp, one for ESP/AH SA.  However, the triggering template of the trap
policy (where we get the reqid from), will be the same in both acquires,
IPComp, which we ignore, so no acquire was actually forwarded.
2022-04-14 18:42:01 +02:00
Leon Romanovsky 012e4cd902 kernel-netlink: Remove unimplemented XFRM_OFFLOAD_IPV6 flag
The XFRM_OFFLOAD_IPV6 flag was never implemented in the kernel and there
are no plans to do so.

Kernel patch: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7c76ecd9c99b6e9a771d813ab1aa7fa428b3ade1

Closes strongswan/strongswan#916
2022-03-14 15:48:21 +01:00
Tobias Brunner 1c4e134f26 kernel-netlink: Initialize ifreq structs when detecting offload capability 2021-08-11 15:35:52 +02:00
Michał Skalski c632aa7b31 kernel-netlink: Add support for full-length HMAC-SHA2 algorithms 2021-02-23 17:28:46 +01:00
Tobias Brunner dfd261d2de kernel-netlink: Extract shared route handling code in net/ipsec 2020-03-10 10:30:39 +01:00
Tobias Brunner e23708bdf3 kernel-netlink: Don't require an interface name for passthrough policies 2020-03-10 10:26:42 +01:00
Tobias Brunner b0b6bd2470 kernel-netlink: Allow blank source address in routes for passthrough policies 2020-03-10 10:25:19 +01:00
Noel KuntzeandTobias Brunner 09f4bccfea kernel-netlink: Implement passthrough type routes and use them on Linux
Enables us to ignore any future kernel features for routes unless
we actually need to consider them for the source IP routes.

Also enables us to actually really skip IPsec processing for those networks
(because even the routes don't touch those packets). It's more what
users expect.

Co-authored-by: Tobias Brunner <tobias@strongswan.org>
2020-03-10 10:20:58 +01:00
Tobias Brunner a3166c8188 kernel-netlink: Use correct config option name for HW offloading check
Fixes: a605452c03 ("kernel-netlink: Check for offloading support in constructor")
2019-12-13 17:20:51 +01:00
Tobias Brunner c81a8a8f36 kernel-netlink: Properly compare routes for policies without gateway/netxhop
This happened when installing a duplicate bypass policy for a locally
connected subnet.  The destructor and the kernel-net part already
handle this correctly.
2019-12-06 10:28:13 +01:00
Thomas Egerer a605452c03 kernel-netlink: Check for offloading support in constructor
This avoids races that could potentially occur when doing the check during
SA installation.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2019-11-26 11:00:28 +01:00
Tobias Brunner 801a5d3133 kernel-netlink: Don't install routes for CHILD_SAs with interface ID 2019-04-04 09:31:38 +02:00
Tobias Brunner b32c3ce8fe kernel-netlink: Make interface ID configurable on SAs and policies 2019-04-03 12:00:08 +02:00
Tobias Brunner c7f579fa17 kernel-netlink: Fix compilation on old kernels (< 2.6.39) 2019-01-24 10:55:24 +01:00
Tobias Brunner a9b9450c54 kernel-netlink: Update SA selector if it contains changed IP address(es) 2018-11-22 11:22:58 +01:00
Tobias Brunner 9cee688f78 kernel-netlink: Add support for setting mark/mask an SA should apply to processed traffic 2018-08-31 12:24:30 +02:00