Commit Graph
472 Commits
Author SHA1 Message Date
Martin Willi dad99b5eea kernel-netlink: Fix GCC error about uninitialized variable use
get_replay_state() always returns a replay_state_len when returning a
replay state, but GCC doesn't know about that.
2015-04-08 11:13:04 +02:00
Tobias Brunner a3c2edb19c kernel-netlink: Copy current usage stats to new SA in update_sa()
This is needed to fix usage stats sent via RADIUS Accounting if clients
use MOBIKE or e.g. the kernel notifies us about a changed NAT mapping.
The upper layers won't expect the stats to get reset if only the IPs have
changed (and some kernel interface might actually allow such updates
without reset).

It also fixes traffic based lifetimes in such situations.

Fixes #799.
2015-03-25 12:00:20 +01:00
Martin Willi 942797a5b5 kernel-interface: Add a separate "update" flag to add_sa()
The current "inbound" flag is used for two purposes: To define the actual
direction of the SA, but also to determine the operation used for SA
installation. If an SPI has been allocated, an update operation is required
instead of an add.

While the inbound flag normally defines the kind of operation required, this
is not necessarily true in all cases. On the HA passive node, we install inbound
SAs without prior SPI allocation.
2015-03-09 18:18:20 +01:00
Tobias Brunner 96e6130537 kernel-pfkey: Add option to set receive buffer size of event socket
If many requests are sent to the kernel the events generated by these
requests may fill the receive buffer before the daemon is able to read
these messages.

Fixes #783.
2015-03-06 16:45:22 +01:00
Martin Willi 6b57790270 kernel-netlink: Respect kernel routing priorities for IKE routes
If a system uses routing metrics, we should honor them when doing (manual)
routing lookups for IKE. When enumerating routes, the kernel reports priorities
with the RTA_PRIORITY attribute, not RTA_METRICS. We prefer routes with a
lower priority value, and fall back to longest prefix match priorities if
the priority value is equal.
2015-03-03 13:42:41 +01:00
Martin Willi 751363275f attributes: Move the configuration attributes framework to libcharon 2015-02-20 13:34:55 +01:00
Martin Willi 82e4b83378 attr-sql: Move plugin to libcharon 2015-02-20 13:34:55 +01:00
Martin Willi c6c7f97a1d attr: Move plugin to libcharon 2015-02-20 13:34:54 +01:00
Martin Willi 6bfd1fbb71 resolve: Move plugin back to libcharon
Since pluto is gone, all existing users build upon libcharon.
2015-02-20 13:34:54 +01:00
Martin Willi b125839a1a kernel-interface: Raise mapping event with a proto/SPI/dst tuple 2015-02-20 13:34:51 +01:00
Martin Willi f81a949748 kernel-interface: Raise expires with a proto/SPI/dst tuple instead of reqid 2015-02-20 13:34:50 +01:00
Martin Willi 85b238887d child-sa: Replace reqid based marks by "unique" marks
As we now use the same reqid for multiple CHILD_SAs with the same selectors,
having marks based on the reqid makes not that much sense anymore. Instead we
use unique marks that use a custom identifier. This identifier is reused during
rekeying, keeping the marks constant for any rule relying on it (for example
installed by updown).

This also simplifies handling of reqid allocation, as we do not have to query
the marks that is not yet assigned for an unknown reqid.
2015-02-20 13:34:49 +01:00
Martin Willi cc08ce83f0 kernel-interface: Add reqid allocation and release functions
To reassign reqids where appropriate, we explicitly allocate or confirm them
centrally on the kernel-interface.

Currently the state is stored in the kernel-interface wrapper for all
backends, but we may add appropriate methods to each backend to implement
a custom reqid allocation logic, if required.
2015-02-20 13:34:49 +01:00
Martin Willi d05d85fe65 kernel-interface: Pass full list of traffic selectors to add_sa()
While we can handle the first selector only in BEET mode in kernel-netlink,
passing the full list gives the backend more flexibility how to handle this
information.
2015-02-20 13:34:47 +01:00
Martin Willi 6ad787ca54 kernel-pfkey: Don't update during add_sa(), but delete SPI allocation state 2015-02-20 13:34:47 +01:00
Martin Willi 2a1c9e20bd kernel-interface: Remove reqid parameter from get_spi/get_cpi() methods
The reqid is not strictly required, as we set the reqid with the update
call when installing the negotiated SA.

If we don't need a reqid at this stage, we can later allocate the reqid in
the kernel backend once the SA parameters have been fully negotaited. This
allows us to assign the same reqid for the same selectors to avoid conflicts
on backends this is necessary.
2015-02-20 13:34:32 +01:00
Martin Willi 6fa203b8d4 kernel-pfroute: If a new interface appears, slightly delay address enumeration
On OS X 10.10, when installing a virtual IP on a tun device, there is a chance
that a RTM_IFANNOUNCE is sent before the IP is ready on that link when calling
getifaddrs(). As we don't get an RTM_NEWADDR event either, that race lets us
miss the virtual IP install event, failing the add_ip() call.
2014-12-16 17:22:28 +01:00
Tobias Brunner 3000f6aada Fixed some typos, courtesy of codespell 2014-12-15 17:11:14 +01:00
Tobias Brunner d21b01462e kernel-pfkey: Fix replay window size on FreeBSD and Mac OS X
The FreeBSD and Mac OS X kernels interpret sadb_sa_replay as the size of the
replay window in bytes.  Linux on the other hand does the same for PF_KEY it
does for XFRM so sadb_sa_replay denotes the number of packets/bits in the
window.  Similarly, the window size on Linux is limited to 32 by the four
byte default bitmap used for IPsec SAs (may only be changed with
XFRMA_REPLAY_ESN_VAL), which is not the case on the other platforms.
2014-12-15 16:09:15 +01:00
Martin Willi 50bb81425e kernel-netlink: Optionally ignore errors resulting from response message loss
As some backends over unreliable transport do not cache response messages,
retransmissions due the loss of responses perform the operation again. Add an
option to ignore some errors arising from such duplicate operations.

Note: This approach can't distinguish between real EXIST/NOTFOUND errors
and packet failures, and therefore is a source of race conditions and can't
detect any of these errors actually happening. Therefore that behavior is
disabled by default, and can be enabled with the ignore_retransmit_errors
strongswan.conf option.

To properly distinguish between real and retransmission errors, a Netlink
backend should implement retransmission detection using sequence numbers.
2014-11-21 10:55:45 +01:00
Martin Willi 8925abbec4 kernel-netlink: Add an option to enforce using XFRM_MSG_UPDPOLICY 2014-11-21 10:55:45 +01:00
Martin Willi 3065081c3e kernel-netlink: Fallback to UDP if detecting socket protocol fails
getsockopt(SO_PROTOCOL) is not supported before 2.6.32. Default to UDP if
either the SO_PROTOCOL define is missing or the syscall fails.
2014-11-21 10:55:45 +01:00
Martin Willi 87888f9926 kernel-netlink: Alternatively support global port based IKE bypass policies
The socket based IKE bypass policies are usually superior, but not supported
on all networking stacks. The port based variant uses global policies for the
UDP ports we have IKE sockets for.
2014-11-21 10:55:45 +01:00
Martin Willi 6c58fabe29 kernel-netlink: Add options to enable parallel Netlink queries explicitly
As under vanilla Linux the kernel can't handle parallel dump queries and returns
EBUSY, it makes not much sense to use them. Disable parallel queries by default
to basically restore original behavior, improving performance.
2014-11-21 10:55:45 +01:00
Martin Willi 9b43dddff4 kernel-netlink: Release lock while doing Netlink NEW/DELADDR operations
Besides that it can improve throughput, it avoids a deadlock situation. If
all threads are busy, watcher will invoke the FD notification for NEWADDR
events itself. If the lock is held, it gets locked up. As watcher is not
dispatching anymore, it can't signal Netlink socket send() completion, and
the send() operation does not return and keeps the lock.
2014-11-21 10:55:45 +01:00
Martin Willi 4b41ea956c kernel-netlink: Add non-dumping variants of echo and stress tests 2014-11-21 10:55:45 +01:00
Martin Willi adb930ed4f kernel-netlink: Add test cases for successful and timing out retransmissions 2014-11-21 10:55:45 +01:00
Martin Willi 553be051b7 kernel-netlink: Add a compile-time hook to simulate request message loss 2014-11-21 10:55:45 +01:00
Martin Willi 15dc61757c kernel-netlink: Implement configurable Netlink request retransmission 2014-11-21 10:55:45 +01:00
Martin Willi aa762bed7b kernel-netlink: Add a stress test with several threads doing Netlink exchanges 2014-11-21 10:55:45 +01:00
Martin Willi 84f6853c42 kernel-netlink: Retry netlink query while kernel returns EBUSY
If the kernel can't execute a Netlink query because a different query is already
active, it returns EBUSY. As this can happen now as we support parallel queries,
retry on this error condition.
2014-11-21 10:55:45 +01:00
Martin Willi 3c7193f114 kernel-netlink: Support parallel Netlink queries
Instead of locking the socket exclusively to wait for replies, use watcher
to wait for and read in responses asynchronously. This allows multiple parallel
Netlink queries, which can significantly improve performance if the kernel
Netlink layer has longer latencies and supports parallel queries.

For vanilla Linux, parallel queries don't make much sense, as it usually returns
EBUSY for the relevant dump requests. This requires a retry, and in the end
makes queries more expensive under high load.

Instead of checking the Netlink message sequence number to detect multi-part
messages, this code now relies on the NLM_F_MULTI flag to detect them. This
has previously been avoided (by 1d51abb7). It is unclear if the flag did not
work correctly on very old Linux kernels, or if the flag was not used
appropriately by strongSwan. The flag seems to work just fine back to 2.6.18,
which is a kernel still in use by RedHat/CentOS 5.
2014-11-21 10:55:45 +01:00
Martin Willi 02794456a9 kernel-netlink: Add a simple send message test querying available links 2014-11-21 10:55:44 +01:00
Martin Willi f572b38816 kernel-netlink: Add a stub for a test-runner 2014-11-21 10:55:44 +01:00
Tobias Brunner 8ab1b29da4 mem-pool: Fix potential memory leak and lost leases when reassigning leases
If no offline leases are available for the current client and assigning online
leases is disabled, and if all IPs of the pool have already been assigned to
clients we look for offline leases that previously were assigned to other
clients.

In case the current client has online leases the previous code would
replace the existing mapping entry and besides resulting in a memory leak
the online leases would be lost forever (even if the client later releases
the addresses).  If this happens repeatedly the number of available addresses
would decrease even though the total number of online and offline leases seen
in `ipsec leases` would indicate that there are free addresses available.

Fixes #764.
2014-11-11 19:00:02 +01:00
Tobias Brunner bbe3070aa2 mem-pool: Add basic unit tests 2014-10-30 12:32:44 +01:00
Tobias Brunner 385d4486ba libhydra: Add test runner 2014-10-30 12:32:44 +01:00
Tobias Brunner 9d2a3554e5 mem-pool: Correctly ignore first and last addresses of subnets and adjust size
Previously one more than the first and last address was ignored.
And if the base address is not the network ID of the subnet we
should not skip it.  But we should adjust the size as it does not
represent the actual number of IP addresses assignable.
2014-10-30 12:32:44 +01:00
Martin Willi 4e37bdbf57 kernel-pfroute: Check for RTM_IFANNOUNCE availability
This message is not available on OS X.
2014-10-14 16:33:10 +02:00
Martin Willi 12c0bde689 kernel-netlink: Define and use rtnetlink message types 2014-09-24 11:19:59 +02:00
Martin Willi c94e93a7ab kernel-netlink: Pass protocol specific enum names to socket constructor
This avoid the hard dependency on enum names, and makes kernel_netlink_shared
independent of kernel_netlink_ipsec.
2014-09-24 11:19:59 +02:00
Martin Willi 5957e76b38 kernel-netlink: Clean up socket initialization, handle 0 as valid socket fd 2014-09-24 11:19:59 +02:00
Martin Willi 4c3aca273f kernel-netlink: Clean up response buffer management 2014-09-24 11:19:59 +02:00
Martin Willi de11d34abb kernel-netlink: Use recv() instead of recvfrom()
As we are not interested in the returned address, there is really no need
in passing that argument.
2014-09-24 11:19:59 +02:00
Martin Willi 4c438cf099 kernel-netlink: Avoid casting the NLMSG_DATA() return value
There is really no need for doing so, and it makes the code just unreadable.
2014-09-24 11:19:59 +02:00
Martin Willi 0404a29bfe kernel-netlink: Define netlink buffer as an union having a netlink header
This allows us to streamline the netlink buffers, and avoid extensive
casting.
2014-09-24 11:19:58 +02:00
Martin Willi 68da3bad57 settings: Use strongswan.conf used during library initialization for reload
Since 4b670a20 we require an explicit strongswan.conf to re-load configurations.
However, the define was missing in the build, breaking SIGHUP based config
reloading.

Fixes #651.
2014-09-22 13:40:39 +02:00
Tobias Brunner 90e6675a65 kernel-netlink: Optionally install protocol and ports on transport mode SAs 2014-09-12 10:45:50 +02:00
Tobias Brunner 47a0e289d9 kernel-netlink: Add global option to configure MSS-clamping on installed routes 2014-09-12 10:13:30 +02:00
Tobias Brunner c1adf7e0c4 kernel-netlink: Add global option to set MTU on installed routes 2014-09-12 10:13:30 +02:00