Commit Graph

45 Commits

Author SHA1 Message Date
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 66e9165bc6 kernel-netlink: Return outbound interface in get_nexthop() 2016-06-10 13:54:18 +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 fee991c259 kernel-netlink: Check proper watcher state in parallel mode
After adding the read callback the state is WATCHER_QUEUED and it is
switched to WATCHER_RUNNING only later by an asynchronous job. This means
that a thread that sent a Netlink message shortly after registration
might see the state as WATCHER_QUEUED.  If it then tries to read the
response and the watcher thread is quicker to actually read the message
from the socket, it could block on recv() while still holding the lock.
And the asynchronous job that actually read the message and tries to queue
it will block while trying to acquire the lock, so we'd end up in a deadlock.

This is probably mostly a problem in the unit tests.
2016-05-06 16:00:32 +02:00
Tobias Brunner 3f4cc30b19 kernel-netlink: Order routes by prefix before comparing priority/metric
Metrics are basically defined to order routes with equal prefix, so ordering
routes by metric first makes not much sense as that could prefer totally
unspecific routes over very specific ones.

For instance, the previous code did break installation of routes for
passthrough policies with two routes like these in the main routing table:

  default via 192.168.2.1 dev eth0 proto static
  192.168.2.0/24 dev eth0 proto kernel scope link src 192.168.2.10 metric 1

Because the default route has no metric set (0) it was used, instead of the
more specific other one, to determine src and next hop when installing a route
for a passthrough policy for 192.168.2.0/24.  Therefore, the installed route
in table 220 did then incorrectly redirect all local traffic to "next hop"
192.168.2.1.

The same issue occurred when determining the source address while
installing trap policies.

Fixes 6b57790270 ("kernel-netlink: Respect kernel routing priorities for IKE routes").
Fixes #1416.
2016-05-06 15:48:45 +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
Andreas Steffen d3af3b799f Extended IPsec kernel policy scheme
The kernel policy now considers src and dst port masks as well as
restictions to a given network interface. The base priority is
100'000 for passthrough shunts, 200'000 for IPsec policies,
300'000 for IPsec policy traps and 400'000 for fallback drop shunts.
The values 1..30'000 can be used for manually set priorities.
2016-04-09 16:51:02 +02:00
Andreas Steffen c26e4330e7 Implemented IPsec policies restricted to given network interface 2016-04-09 16:51:02 +02:00
Andreas Steffen 7f57c4f9fb Support manually-set IPsec policy priorities 2016-04-09 16:51:01 +02:00
Tobias Brunner 83312ee5e4 kernel-netlink: Prefer policies with reqid over those without
This allows two CHILD_SAs with reversed subnets to install two FWD
policies each.  Since the outbound policy won't have a reqid set we will
end up with the two inbound FWD policies installed in the kernel, with
the correct templates to allow decrypted traffic.
2016-04-09 16:51:00 +02:00
Tobias Brunner f7e9e6a3fd kernel-netlink: Only associate templates with inbound FWD policies
We can't set a template on the outbound FWD policy (or we'd have to make
it optional).  Because if the traffic does not come from another (matching)
IPsec tunnel it would get dropped due to the template mismatch.
2016-04-09 16:51:00 +02:00
Tobias Brunner c4387e991a kernel-netlink: Associate routes with IN policies instead of FWD policies
This allows us to install more than one FWD policy.  We already do this
in the kernel-pfkey plugin (there the original reason was that not all
kernels support FWD policies).
2016-04-09 16:50:59 +02:00
Tobias Brunner 89da06ace9 kernel: Use structs to pass information to the kernel-ipsec interface 2016-04-09 16:50:59 +02:00
Andreas Steffen b12c53ce77 Use standard unsigned integer types 2016-03-24 18:52:48 +01:00
Tobias Brunner 0ed9430d10 kernel-netlink: Fix lookup of next hops for destinations with prefix
References #1347.
2016-03-21 12:14:59 +01:00
Andreas Steffen 6abae81f86 Implemented port ranges in kernel_netlink interface 2016-03-04 09:52:34 +01:00
Tobias Brunner 8394ea2a42 libhydra: Move kernel interface to libcharon
This moves hydra->kernel_interface to charon->kernel.
2016-03-03 17:36:11 +01:00
Tobias Brunner dec9e1957f libhydra: Move all kernel plugins to libcharon 2016-03-03 17:36:11 +01:00
Tobias Brunner 062a602216 Moved all kernel plugins to libhydra. 2010-09-02 19:01:26 +02:00
Tobias Brunner f6659688ab Refer to kernel interface via hydra and not charon. 2010-09-02 19:01:25 +02:00
Tobias Brunner 9f166d9ac2 Removed references to protocol_id_t from kernel interface.
Instead we use the actual IP protocol identifier (the conversion now happens in
child_sa_t and kernel_handler_t).
2010-09-02 19:01:25 +02:00
Tobias Brunner ba26508d05 Moved roam job creation to kernel event handler. 2010-09-02 19:01:25 +02:00
Tobias Brunner 61e8e73206 Refer to scheduler via hydra and not charon. 2010-09-02 19:01:24 +02:00
Tobias Brunner 4e258e63c3 Moved migrate job creation to kernel event handler. 2010-09-02 19:01:24 +02:00
Tobias Brunner 01563352e8 Moved update SA job creation to kernel event handler. 2010-09-02 19:01:24 +02:00
Tobias Brunner a22853b302 Moved delete/rekey CHILD_SA job creation to kernel event handler. 2010-09-02 19:01:24 +02:00
Tobias Brunner 81f6ec276b Moved acquire job creation to kernel event handler. 2010-09-02 19:01:23 +02:00
Tobias Brunner 211943be23 Some whitespace and code style fixes. 2010-09-02 19:01:23 +02:00
Tobias Brunner c5f7146b17 Refer to processor via hydra and not charon. 2010-09-02 19:01:22 +02:00
Martin Willi ba31fe1fd6 Use a seperate section for each nested struct member in INIT macro 2010-08-18 12:15:03 +02:00
Andreas Steffen ee26c537d7 support of xfrm marks for IKEv2 2010-07-02 23:46:09 +02:00
Martin Willi 89bf11d204 Respect line with in Makefile.am's, other cosmetics 2010-03-25 14:54:56 +01:00
Tobias Brunner 58f86d0f0f Changed all usages of lib->attributes to hydra->attributes. 2010-03-24 18:54:26 +01:00
Tobias Brunner bd3f8ea30b Convert charon into libcharon. 2010-03-19 13:34:52 +01:00
Tobias Brunner 08c5572602 Moving charon to libcharon. 2010-03-19 13:34:52 +01:00