Commit Graph
442 Commits
Author SHA1 Message Date
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
Tobias Brunner f80093e2ee kernel-pfroute: Delete interfaces on RTM_IFANNOUNCE/IFAN_DEPARTURE events
We actually never deleted cached interfaces.  So if the kernel reuses
interface indices events for newly created interfaces could have been
associated with interface objects of deactivated and deleted interfaces.

Since we also didn't update the interface name when such an interface
got reactivated we ended up using the old name e.g. to install routes.

A trigger for this was the deletion and recreation of TUN devices during
reauthentication of SAs that use virtual IPs.
2014-09-09 10:56:15 +02:00
Tobias Brunner 25fcbab678 kernel-pfkey: Report packet counts of IPsec SAs
Seems that packet counts can be retrieved after all. At least the Linux
and FreeBSD kernels treat the number of allocations as number of packets.
We actually installed packet limits in that field already.
2014-09-09 10:56:15 +02:00
Tobias Brunner 52ba4f6bf4 kernel-pfroute: Fix kernel response handling
The condvar is signaled for every handled message received from the
kernel not only for replies (this changed with 2a2d7a4dc8).  This may
cause segfaults because this->reply is not set when the waiting thread is
woken due to an IP address change.

Since this->reply is only set when it is actually the expected reply (and
only one request is sent at a time, thanks to c9a323c1d9) we only have
to make sure the reply is there (and clear it once we handled it).

Using separate condvars could also be an option in the future.
2014-08-19 14:03:00 +02:00
Martin Willi 839951097c kernel-netlink: Rename algorithm identifier from cast128 to cast5
Even if the XFRM identifier was named cast128 in the kernel before 2.6.31, it
actually never worked, because there is no such crypto algorithm.

The identifier has been changed to cast5 in
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=245acb87
to make it work, so we should use that.

Fixes #633.
2014-07-04 10:18:12 +02:00
Tobias Brunner f22add05f6 kernel-pfkey: Use address in TS to determine interface for shunt routes 2014-06-26 18:13:17 +02:00
Tobias Brunner 60f5fb2318 kernel-pfkey: Use subnet and prefix when determining nexthop for shunt policy routes
This is basically the same as 88f125f560.
2014-06-26 18:13:09 +02:00
Tobias Brunner b451303a6c kernel-pfkey: Install routes for shunt policies 2014-06-26 18:12:05 +02:00
Tobias Brunner cd6b2af33e kernel-netlink: Cast IPv6 address blobs to the proper type
On Android these macros are defined as functions.
2014-06-24 15:53:25 +02:00
Tobias Brunner 90854d289f kernel-netlink: Install virtual IPv6 addresses as deprecated
This should prevent the kernel's IPv6 source address selection algorithm
from using this address unless it is forced to by our source route.
This is helpful if split tunneling is used.

Fixes #598.
2014-06-20 16:10:40 +02:00
Tobias Brunner 88f125f560 kernel-netlink: Pass prefix when looking up next hop for shunt policies 2014-06-19 14:33:40 +02:00
Tobias Brunner de7cb6de65 kernel-netlink: Add support for destination prefix when determining next hop 2014-06-19 14:33:40 +02:00
Tobias Brunner c005073d0b kernel-interface: Add destination prefix to get_nexthop()
This allows to determine the next hop to reach a subnet, for instance, when
installing routes for shunt policies.
2014-06-19 14:33:40 +02:00
Tobias Brunner 77b6a145a0 kernel-pfkey: Add support for new policy priority class 2014-06-19 14:20:33 +02:00
Tobias Brunner f1675e4e29 kernel-netlink: Add support for new policy priority class 2014-06-19 14:20:33 +02:00
Tobias Brunner 566d1a90cd Remove kernel-klips plugin 2014-06-19 14:20:33 +02:00
Tobias Brunner 3bf98189d7 kernel-netlink: Follow RFC 6724 when selecting IPv6 source addresses
Instead of using the first address we find on an interface we should
consider properties like an address' scope or whether it is temporary
or public.

Fixes #543.
2014-06-19 14:16:41 +02:00
Martin Willi 8b9b11919d kernel-netlink: Never use XFRMA_REPLAY_ESN_VAL to configure zero replay windows
Trying to disable replay windows using the ESN attribute fails with EINVAL.
Use non-ESN legacy format to disable replay windows, even if ESN has been
negotiated over IKE.
2014-06-18 15:04:57 +02:00
Martin Willi 823ce4a37f kernel-pfkey: Support connection specific replay window sizes up to 32 packets 2014-06-17 16:41:30 +02:00
Martin Willi 44098fbaca kernel-netlink: Support connection specific replay window sizes 2014-06-17 16:41:30 +02:00
Martin Willi 30c009c2fe kernel-interface: Add a replay_window parameter to add_sa() 2014-06-17 16:41:30 +02:00
Martin Willi 7452adfad3 kernel-interface: Add a flag to indicate no policy updates required 2014-06-04 16:32:07 +02:00
Martin Willi 4163421f91 plugins: Don't link with -rdynamic on Windows 2014-06-04 15:53:02 +02:00
Martin Willi 4189cd2f03 windows: Link libhydra against Winsock2 2014-06-04 15:53:00 +02:00
Tobias Brunner 403ad5dd85 pfkey: Always include stdint.h
On some systems (e.g. on Debian/kFreeBSD) that header is required when
including ipsec.h, on Linux we require it too when including pfkeyv2.h,
so to simplify things we just always include it.
2014-05-19 14:53:24 +02:00
Martin Willi 9ee8b3b41f enum: Don't directly include enum.h
To allow enum.h to depend on utils.h definitions, avoid its direct inclusion.
Instead include utils.h, which includes enum.h as well.
2014-05-16 15:42:07 +02:00
Martin Willi 6eff96f543 kernel-klips: Pass a pointer to a properly sized integer for algorithm lookup 2014-05-16 15:42:07 +02:00
Francois ten Krooden 6afa7761a5 kernel-pfkey: Added IPComp support
- get_cpi function was implemented to retrieve a CPI from the kernel.
- add_sa/update_sa/del_sa were updated to accommodate for IPComp SA.
- Updated add_policy_internal to update the SPD to support IPComp.
2014-04-24 17:36:17 +02:00
Tobias Brunner 8d34e55375 attr: Don't shift the 32-bit netmask by 32
This is undefined behavior as per the C99 standard (sentence 1185):

 "If the value of the right operand is negative or is greater or equal
  to the width of the promoted left operand, the behavior is undefined."

Apparently shifts may be done modulo the width on some platforms so
a shift by 32 would not shift at all.
2014-04-09 17:09:55 +02:00
Tobias Brunner 7522fcffd2 kernel-pfroute: Let get_nexthop() default to destination address 2014-03-31 14:32:44 +02:00
Tobias Brunner 505a69eba4 attr: Silently skip over load option 2014-02-12 14:34:34 +01:00