Commit Graph

72 Commits

Author SHA1 Message Date
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 Kuntze 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
Tobias Brunner c5b94b2483 kernel-netlink: Use larger buffer for event messages 2018-08-31 12:15:12 +02:00
Tobias Brunner c993eaf9d1 kernel: Add option to control DS field behavior 2018-08-29 11:36:04 +02:00
Tobias Brunner dc8b015d78 kernel: Add options to control DF and ECN header bits/fields via XFRM
The options control whether the DF and ECN header bits/fields are copied
from the unencrypted packets to the encrypted packets in tunnel mode (DF only
for IPv4), and for ECN whether the same is done for inbound packets.

Note: This implementation only works with Linux/Netlink/XFRM.

Based on a patch by Markus Sattler.
2018-08-29 11:36:04 +02:00
Tobias Brunner d837d0b339 kernel-netlink: Use strncpy to copy interface name when configuring HW offload 2018-05-23 20:25:49 +02:00
Tobias Brunner ee26f7156f kernel-netlink: Cleanup and fix some HW offload code issues
Besides some style issues there were some incorrect allocations
for ethtool requests.
2018-03-21 10:29:57 +01:00
Adi Nissim 338cc5812e kernel-netlink: Add new automatic hw_offload mode
Until now there were 2 hw_offload modes: no/yes
* hw_offload = no  : Configure the SA without HW offload.
* hw_offload = yes : Configure the SA with HW offload.
                     In this case, if the device does not support
                     offloading, SA creation will fail.

This commit introduces a new mode: hw_offload = auto
----------------------------------------------------
If the device and kernel support HW offload, configure
the SA with HW offload, but do not fail SA creation otherwise.

Signed-off-by: Adi Nissim <adin@mellanox.com>
Reviewed-by: Aviv Heller <avivh@mellanox.com>
2018-03-21 10:28:44 +01:00
Tobias Brunner e1803a208a kernel-netlink: Add strings for newer XFRM attribute types 2017-10-06 16:41:09 +02:00
Tobias Brunner 2699c8387a kernel-netlink: Set SPI on outbound policy
This should cause the right SA to get used if there are multiple outbound
SAs and the policies are installed properly.
2017-08-07 10:44:05 +02:00
Tobias Brunner 8a2e4d4a8b linked-list: Change interface of callback for invoke_function()
This avoids the unportable five pointer hack.
2017-05-26 13:56:44 +02:00
Tobias Brunner 70855696ad kernel-netlink: Use total retransmit timeout as acquire timeout
By using the total retransmit timeout, modifications of timeout settings
automatically reflect on the value of xfrm_acq_expires.  If set, the
value of xfrm_acq_expires configured by the user takes precedence over
the calculated value.
2017-05-23 18:05:58 +02:00
Thomas Egerer d140b3bd3f kernel-netlink: Try to add new inbound SA if update fails
When establishing a traffic-triggered CHILD_SA involves the setup of an
IKE_SA more than one exchange is required. As a result the temporary
acquire state may have expired -- even if the acquire expiration
(xfrm_acq_expires) time is set properly (165 by default).  The expire
message sent by the kernel is not processed in charon since no trap can
be found by the trap manager.
A possible solution could be to track allocated SPIs.  But since this is
a corner case and the tracking introduces quite a bit of overhead, it
seems much more sensible to add a new state if the update of a state
fails with NOT_FOUND.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2017-05-23 17:58:51 +02:00
Tobias Brunner 48ea655016 kernel-netlink: Update hardware offload attribute when SAs are updated 2017-05-23 16:58:06 +02:00
Tobias Brunner 0b5dfaeb5c kernel-netlink: Base SA update on correct message in multi-message response 2017-05-23 16:58:06 +02:00
Tobias Brunner d42948fc05 kernel-netlink: Enable hardware offloading if configured for an SA 2017-05-23 16:51:03 +02:00
Tobias Brunner 6d86d0f516 kernel: Make range of SPIs for IPsec SAs configurable 2017-03-02 08:52:56 +01:00
Tobias Brunner 0e9d6c4605 kernel-netlink: Use the same priority range for trap and regular policies
While trap and regular policies now often look the same (mainly because
reqids are kept constant) trap policies still need to have a lower priority
than regular policies to handle unroute/route correctly if e.g. IPComp
is used or the mode changes.  But if we use a completely different
priority range that's lower than that of regular policies it is not possible
to install overlapping trap policies.  By differentiating trap from
regular policies via the priority's LSB this issue is avoided while
still maintaining the proper ordering of trap and regular policies.

Fixes #1243.
2017-02-08 10:36:38 +01:00
Tobias Brunner 6606393b8c kernel-netlink: Fix spacing in log message when policy is unchanged 2017-02-08 10:36:37 +01:00
Tobias Brunner 965daa1df3 kernel-netlink: Use correct 4 byte alignment for AH with IPv4
By default, the kernel incorrectly uses an 8 byte alignment, which is
mandatory for IPv6 but prohibited for IPv4.  For many algorithms this
doesn't matter but that's not the case for HMAC_SHA2_256_128.
Since 2.6.39 the kernel can be explicitly configured to use a 4 byte
alignment.
2017-01-25 17:51:35 +01:00
Thomas Egerer 7085ca68d6 kernel-netlink: Return const pointer from lookup_algorithm()
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2017-01-23 18:53:58 +01:00
Tobias Brunner 564a199674 kernel-netlink: Add support for AES-CMAC-96 (RFC 4494)
The kernel apparently supports this since 3.10.
2016-12-12 11:43:06 +01:00
Tobias Brunner 33d3ffde25 kernel-netlink: Pass zero mark to kernel if mask is set
The kernel will apply the mask to the mark on the packet and then
compare it to the configured mark.  So to match only unmarked packets we
have to be able to set 0/0xffffffff.
2016-09-30 15:35:32 +02:00
Tobias Brunner ac9759a532 kernel-netlink: Support configuring XFRM policy hashing thresholds
If the number of flows over a gateway exceeds the flow cache size of the Linux
kernel, policy lookup gets very expensive. Policies covering more than a single
address don't get hash-indexed by default, which results in wasting most of
the cycles in xfrm_policy_lookup_bytype() and its xfrm_policy_match() use.
Starting with several hundred policies the overhead gets inacceptable.

Starting with Linux 3.18, Linux can hash the first n-bit of a policy subnet
to perform indexed lookup. With correctly chosen netbits, this can completely
eliminate the performance impact of policy lookups, freeing the resources
for ESP crypto.

WARNING: Due to a bug in kernels 3.19 through 4.7, the kernel crashes with a
NULL pointer dereference if a socket policy is installed while hash thresholds
are changed.  And because the hashtable rebuild triggered by the threshold
change that causes this is scheduled it might also happen if the socket
policies are seemingly installed after setting the thresholds.
The fix for this bug - 6916fb3b10b3 ("xfrm: Ignore socket policies when
rebuilding hash tables") - is included since 4.8 (and might get backported).
As a workaround `charon.plugins.kernel-netlink.port_bypass` may be enabled
to replace the socket policies that allow IKE traffic with port specific
bypass policies.
2016-09-30 14:54:52 +02:00
Tobias Brunner 175d78df60 kernel-netlink: Update cached reqid when updating policies 2016-09-28 17:55:01 +02:00
Tobias Brunner 4082821964 kernel-netlink: Don't set replay window for outbound SAs
It's not necessary and might waste memory.  However, if ESN is used we set
the window to 1 as the kernel rejects the attribute otherwise.
2016-06-17 18:46:33 +02:00
Tobias Brunner aea3c1052e kernel-netlink: Install routes with OUT policies
This is the direction we actually need routes in and makes the code
easier to read.
2016-06-10 15:25:09 +02:00
Tobias Brunner e7369a9dc5 kernel-netlink: Don't install routes for drop policies and if protocol/ports are in the selector
We don't need them for drop policies and they might even mess with other
routes we install.  Routes for policies with protocol/ports in the
selector will always be too broad and might conflict with other routes
we install.
2016-06-10 14:01:36 +02:00
Tobias Brunner d1f8628420 kernel-netlink: Also use interface returned by get_nexthop() for IPsec policies 2016-06-10 13:57:27 +02:00
Tobias Brunner 4ba5ea407b kernel-netlink: Use interface to next hop for shunt policies
Using the source address to determine the interface is not correct for
net-to-net shunts between two interfaces on which the host has IP addresses
for each subnet.
2016-06-10 13:57:27 +02:00
Tobias Brunner 99a57aa5ee kernel-net: Let get_nexthop() return an optional interface name
The returned name should be the interface over which the destination
address/net is reachable.
2016-06-10 13:54:18 +02:00
Tobias Brunner ebeaac1f2b kernel-netlink: Let only a single thread work on a specific policy
Other threads are free to add/update/delete other policies.

This tries to prevent race conditions caused by releasing the mutex while
sending messages to the kernel.  For instance, if break-before-make
reauthentication is used and one thread on the responder is delayed in
deleting the policies that another thread is concurrently adding for the
new SA.  This could have resulted in no policies being installed
eventually.

Fixes #1400.
2016-06-10 10:45:35 +02:00
Tobias Brunner 471b907613 kernel-netlink: Add priority and refcount to policy log 2016-06-10 10:34:09 +02:00
Tobias Brunner 25178f4594 kernel-netlink: Consistently print mark in log messages only if set 2016-06-10 10:34:09 +02:00
Tobias Brunner a0178fe26e kernel-netlink: Provide error information for Netlink sockets
#1467.
2016-06-10 10:34:09 +02:00
Tobias Brunner fc21465c66 kernel-netlink: Allow definition of a custom priority calculation function 2016-06-10 10:33:17 +02:00
Tobias Brunner 87ed9a5ffb kernel-netlink: Use ipsec_sa_cfg_equals() and compare marks properly 2016-06-08 16:12:52 +02:00
Tobias Brunner 869f4e90b1 kernel-netlink: Order policies with equal priorities by their automatic priority
This allows using manual priorities for traps, which have a lower
base priority than the resulting IPsec policies.  This could otherwise
be problematic if, for example, swanctl --install/uninstall is used while
an SA is established combined with e.g. IPComp, where the trap policy does
not look the same as the IPsec policy (which is now otherwise often the case
as the reqids stay the same).

It also orders policies by selector size if manual priorities are configured
and narrowing occurs.
2016-04-15 10:39:00 +02:00