Commit Graph

223 Commits

Author SHA1 Message Date
Tobias Brunner 74270c8c86 vici: Don't report memory usage via leak-detective
This slowed down the `swanctl --stats` calls in the test scenarios
significantly, with not much added value.
2015-12-11 18:26:53 +01:00
Martin Willi 1a8a420c1c vici: Fix documentation about the initiate/terminate timeout 2015-12-07 10:28:45 +01:00
Martin Willi eaca77d03e vici: Honor an optionally passed IKE configuration name in initiate/install
If two IKE configurations have CHILD configurations with the same name,
we have no control about the CHILD_SA that actually gets controlled. The
new "ike" parameter specifies the peer config name to find the "child" config
under.
2015-12-07 10:28:45 +01:00
Martin Willi 5e79ae2d65 vici: Support completely asynchronous initiating and termination
In some situations the vici client is not interested in waiting for a
timeout at all, so don't register a logging callback if the timeout argument
is negative.
2015-12-07 10:28:45 +01:00
Martin Willi 1db918c4f8 vici: Use an empty local auth round if none given
While it hardly makes sense to use none for negotiated SAs, it actually does
when installing shunt policies.
2015-12-07 10:05:07 +01:00
Martin Willi b26ba1b4a4 vici: Limit start action undoing to IKE_SAs using the base peer config name
If two peer configs use the same child config names, potentailly delete
the wrong CHILD_SA. Check the peer config name as well to avoid that.
2015-12-07 10:05:07 +01:00
Martin Willi 23b1f71372 vici: Close empty IKE_SAs after undoing CHILD_SA start actions 2015-12-07 10:05:07 +01:00
Martin Willi 2facf18833 vici: Use value based array to store CHILD_SA ids during restart
The previous approach stored a pointer to a volatile stack variable, which
works for a single ID, but not for multiple.
2015-12-07 10:05:07 +01:00
Martin Willi f3b2d4a9d8 vici: Undo start actions when unloading configs 2015-12-07 10:05:07 +01:00
Tobias Brunner 63a778a25d vici: Fix clean-local target for Perl bindings if they were not built
This is called when running `make distclean` (or indirectly via `make
distcheck`).
2015-12-04 12:10:57 +01:00
Andreas Steffen 7d24aa0624 Extended and refactored vici perl implementation 2015-12-01 14:52:43 +01:00
Andreas Steffen a17b6d469c Built the CPAN file structure for the Vici::Session perl module 2015-12-01 14:52:43 +01:00
Andreas Steffen a101bce862 Implement vici Perl binding 2015-12-01 14:52:43 +01:00
Tobias Brunner de34defcd0 vici: Add get-algorithms command to query loaded algorithms and implementations 2015-11-30 10:55:55 +01:00
Tobias Brunner 176c24b8e1 vici: Attribute certificates are not trusted 2015-11-12 14:45:43 +01:00
Tobias Brunner e5e352e631 vici: Properly add CRLs to the credential set
add_crl() ensures that old CLRs are not stored in the credential set.
2015-11-12 14:45:42 +01:00
Tobias Brunner f4641f9e45 vici: Add option to query leases of pools
We could later perhaps add filter parameters similar to those of the
`ipsec leases` command (pool name/virtual IP).
2015-11-10 10:43:25 +01:00
Tobias Brunner bdb8b76515 vici: Return local and remote virtual IPs when listing SAs 2015-11-10 10:43:24 +01:00
Tobias Brunner 04f22cdabc vici: Add NAT information when listing IKE_SAs
The `nat-local` and `nat-remote` keys contain information on the NAT
status of the local and remote IKE endpoints, respectively.  If a
responder did not detect a NAT but is configured to fake a NAT situation
this is indicated by `nat-fake` (if an initiator fakes a NAT situation
`nat-local` is set).  If any NAT is detected or faked `nat-any` is set.

Closes strongswan/strongswan#16.
2015-11-09 11:55:51 +01:00
Tobias Brunner c605a96d7f Fix some Doxygen issues 2015-08-27 12:03:11 +02:00
Tobias Brunner 735f929ca7 ike: Only consider number of half-open SAs as responder when deciding whether COOKIEs are sent 2015-08-27 11:18:51 +02:00
Evan Broder 78ed330099 vici: Handle closed sockets in the Ruby gem
From recvfrom(2) (which UDPSocket#recv backs into):

  The return value will be 0 when the peer has performed an orderly
  shutdown.

(i.e. it will return an empty string)

Previously in this scenario, Vici::Transport#recv_all would spin
forever trying to pull more data off the socket. I'm not entirely
clear what happened that caused strongSwan to shutdown the socket, but
it probably should not cause vici Ruby apps to spin.

Closes strongswan/strongswan#13.
2015-08-24 11:24:05 +02:00
Tobias Brunner 256e666d22 vici: Optionally check limits when initiating connections
If the init-limits parameter is set (disabled by default) init limits
will be checked and might prevent new SAs from getting initiated.
2015-08-21 18:21:13 +02:00
Tobias Brunner b9d7319fb3 vici: Add get_bool() convenience getter for VICI messages 2015-08-21 18:21:13 +02:00
Tobias Brunner ff0abde9ed controller: Optionally adhere to init limits also when initiating IKE_SAs 2015-08-21 18:21:13 +02:00
Tobias Brunner 9322e5b398 vici: Add option to disable policy installation for CHILD_SAs 2015-08-17 12:01:36 +02:00
Tobias Brunner b3d91cc64e vici: Add listen methods to receive arbitrary events in Python library 2015-08-17 11:12:18 +02:00
Tobias Brunner cf4cefee42 vici: Move event (un-)registration to a helper method in Python library
Also make sure events are unregistered in case of exceptions in
streamed_request().
2015-08-17 11:12:17 +02:00
Tobias Brunner 65ac0851c0 vici: Add ike/child-rekey events 2015-08-17 11:12:17 +02:00
Tobias Brunner 7f21363ee5 vici: Document the ike/child-updown events 2015-08-17 11:12:17 +02:00
Tobias Brunner 22842cce0d vici: Don't include a child-sas section in ike-updown event
This makes it clearer that only the data concerning the IKE_SA is
transmitted (there could be CHILD_SAs e.g. during IKEv1
reauthentication).
2015-08-17 11:12:17 +02:00
Tobias Brunner 085b8f4fb0 vici: Explicitly notify listeners of the type of ike/child-updown event 2015-08-17 11:12:12 +02:00
Tobias Brunner 6967948241 Initialize variables that some compilers seem to warn about 2015-08-13 15:12:38 +02:00
Andreas Steffen 63d370387d vici: Certification Authority support added.
CDP and OCSP URIs for a one or multiple certification authorities
can be added via the VICI interface. swanctl allows to read
definitions from a new authorities section.
2015-07-21 13:02:30 +02:00
Andreas Steffen e194349148 vici: Compute rekey_bytes and rekey_packets if life_bytes and life_packets are defined 2015-07-20 21:34:09 +02:00
Martin Willi 856ea64129 vici: Asynchronize debug logging
The vici logger uses the listener_t.log() callback to raise vici events.

When doing so, it holds the bus lock as reader while acquiring the vici socket
mutex (1). If at the same time the vici socket enables a writer, that thread
tries to lock the watcher mutex (2). The watcher thread uses debugging while
holding the lock, i.e. acquires the bus read lock (3).

(1) bus.rlock -> vici.lock!
(2) vici.lock -> watcher.lock!
(3) watcher.lock -> bus.rlock!

This all actually would resolve just fine, as we have a shared read lock on the
bus. However, under Windows we seem to have a strict writer preference when
acquiring the rwlock (4). This results in blocking read locks until any pending
write lock can be fulfilled, and makes the constellation deadlock. The relevant
threads are:

Thread (1)
6  0x71313d25 in wait_ at threading/windows/mutex.c:137
7  0x7054c8a2 in find_entry at vici_socket.c:201
8  0x7054d690 in send_ at vici_socket.c:624
9  0x7054f6c1 in send_op at vici_dispatcher.c:119
10 0x705502c1 in raise_event at vici_dispatcher.c:469
12 0x704c3878 in log_cb at bus/bus.c:332
13 0x712c7c3a in invoke_function at collections/linked_list.c:414
14 0x704c3a63 in vlog at bus/bus.c:400
15 0x704c3b36 in log_ at bus/bus.c:430
18 0x70508f1f in process_response at sa/ikev2/task_manager_v2.c:664
20 0x704f5430 in process_message at sa/ike_sa.c:1369
21 0x704e3823 in execute at processing/jobs/process_message_job.c:74
22 0x712e629f in process_job at processing/processor.c:235

Thread (2)
4  0x71313b61 in lock at threading/windows/mutex.c:66
5  0x712e81fd in add at processing/watcher.c:441
6  0x712e1ab9 in add_watcher at networking/streams/stream.c:213
7  0x712e1b4d in on_write at networking/streams/stream.c:237
8  0x7054d606 in _cb_enable_writer at vici_socket.c:609
9  0x712e5e34 in execute at processing/jobs/callback_job.c:77
10 0x712e629f in process_job at processing/processor.c:235

Thread (3)
3  0x71313f38 in read_lock at threading/windows/rwlock.c:74
4  0x704c3971 in vlog at bus/bus.c:373
5  0x704cc156 in dbg_bus at daemon.c:126
6  0x712e7bf9 in watch at processing/watcher.c:316
7  0x712e5e34 in execute at processing/jobs/callback_job.c:77
8  0x712e629f in process_job at processing/processor.c:235

Thread (4)
3  0x71313f70 in write_lock at threading/windows/rwlock.c:82
4  0x704c378b in remove_logger at bus/bus.c:290
5  0x704cb284 in listener_unregister at control/controller.c:166
6  0x713136cd in thread_cleanup_pop at threading/windows/thread.c:558
8  0x704cb94e in initiate at control/controller.c:435
9  0x70553996 in _cb_initiate at vici_control.c:187
12 0x7054d200 in _cb_process_queue at vici_socket.c:508
13 0x712e5e34 in execute at processing/jobs/callback_job.c:77
14 0x712e629f in process_job at processing/processor.c:235

To avoid such a situation, we dissolve the (1) lock sequence. It's actually
never good practice to acquire shared locks during bus hooks, as it is
problematic if we raise bus events while holding the lock. We do so by
raising vici events for log message asynchronously, but of curse must keep
log order as is using a synchronized queue.
2015-07-12 13:57:48 +02:00
Tobias Brunner e94aae83d3 vici: Explicitly disable --user-install when installing Ruby Gem
Only one of `--user-install` and `--install-dir` may be set and if
`--user-install` is the default on a system installation will fail
unless we disable it explicitly.

Fixes #914.
2015-05-21 17:22:11 +02:00
Tobias Brunner f16f792e17 vici: Make installation of Ruby Gem and Python Egg optional
Installing them might not work well when building distro packages (e.g.
with DESTDIR installs).  It might be easier to install them later with a
script in the distro package.

When building from source on the local system it could still be useful to
install the packages directly, which can be enabled with separate configure
options.

The main problem with DESTDIR installations of the Python Egg is that
easy_install creates or modifies a file called easy-install.pth in the
installation directory.  So it's not actually possible to simply copy
the results in DESTDIR over to the actual system as that file would have
to be merged with any existing one.

Fixes #914.
2015-05-21 17:22:01 +02:00
Tobias Brunner 5a817407bc vici: Support out-of-tree build of Python Egg
We also don't require setup.py to exist during cleanup, as e.g. with
make distcheck the source directory is not writable when the build directory
is cleaned, so setup.py can't be created (to just get removed again anyway
if VICI and the Python Eggs haven't been enabled previously).
2015-05-21 17:19:09 +02:00
Timo Teräs 17d3435693 vici: Default to certificate subject for identity
If id is not specified and certificate authentication is used, use the
certificate subject name as identity. Simplifies configuration as in most cases
this is the right thing to do.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
2015-05-04 13:42:51 +02:00
Timo Teräs a7e4a2d6c2 vici: Add support for ike_sa and child_sa updown notifications
Useful for monitoring and management purposes.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
2015-05-04 13:38:39 +02:00
Timo Teräs 8d96f90a79 vici: Add function to test if an event should be generated
Useful to avoid generating vici messages if they are not needed and their
generation is heavy operation.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
2015-05-04 13:35:18 +02:00
Martin Willi f17861dca9 vici: Relicense libvici.h under MIT
libvici currently relies on libstrongswan, and therefore is bound to the GPLv2.
But to allow alternatively licensed reimplementations without copyleft based
on the same interface, we liberate the header.
2015-04-14 17:42:53 +02:00
Martin Willi d20be3fa28 vici: Defer read/write error reporting after connection entry has been released
If a vici client registered for (control-)log events, but a vici read/write
operation fails, this may result in a deadlock. The attempt to write to the
bus results in a vici log message, which in turn tries to acquire the lock
for the entry currently held.

While a recursive lock could help as well for a single thread, there is still
a risk of inter-thread races if there is more than one thread listening for
events and/or having read/write errors.

We instead log to a local buffer, and write to the bus not before the connection
entry has been released. Additionally, we mark the connection entry as unusable
to avoid writing to the failed socket again, potentially triggering an error
loop.
2015-04-13 15:08:10 +02:00
Tobias Brunner 70728eb1b6 child-sa: Add a new state to track rekeyed IKEv1 CHILD_SAs
This is needed to handle DELETEs properly, which was previously done via
CHILD_REKEYING, which we don't use anymore since 5c6a62ceb6 as it prevents
reauthentication.
2015-03-25 12:00:20 +01:00
Björn Schuberg 2e74aa0a91 vici: Add support for python 3 2015-03-18 13:59:15 +01:00
Martin Willi c7e3c5943f vici: Execute python tests during "check" if py.test is available 2015-03-18 13:59:15 +01:00
Björn Schuberg c193b5947a vici: Add test of Packet layer in python library 2015-03-18 13:59:15 +01:00
Björn Schuberg 9b97029a5f vici: Add test of Message (de)serialization in python library 2015-03-18 13:59:15 +01:00
Martin Willi b5d17e55d7 vici: Evaluate Python streamed command results, and raise CommandException 2015-03-18 13:59:14 +01:00
Martin Willi 90c5b48c96 vici: Catch Python GeneratorExit to properly cancel streamed event iteration 2015-03-18 13:59:14 +01:00
Martin Willi 288b654173 vici: Fall back to heap buffer when vararg printing on stack fails
This avoids failures when building log event messages including larger hexdumps.
2015-03-18 13:59:14 +01:00
Martin Willi a47e431ba9 vici: Return a Python generator instead of a list for streamed responses
In addition that it may reduce memory usage and improve performance for large
responses, it returns immediate results. This is important for longer lasting
commands, such as initiate/terminate, where immediate log feedback is preferable
when interactively calling such commands.
2015-03-18 13:59:14 +01:00
Martin Willi 90e16837ba vici: Raise a Python CommandException instead of returning a CommandResult 2015-03-18 13:59:14 +01:00
Martin Willi 871cffa141 vici: Add initial Python egg documentation to README 2015-03-18 13:59:14 +01:00
Martin Willi 305023a27d vici: Use OrderedDict to handle vici responses in Python library
The default Python dictionaries are unordered, but order is important for some
vici trees (for example the order of authentication rounds).
2015-03-18 13:59:14 +01:00
Martin Willi 94bb26fae3 vici: Return authentication rounds with unique names
To simplify handling of authentication rounds in dictionaries/hashtables on the
client side, we assign unique names to each authentication round when listing
connection.
2015-03-18 13:59:14 +01:00
Martin Willi d1ad65f7b2 vici: Rebuild ruby gem on source file changes 2015-03-18 13:59:14 +01:00
Martin Willi fb8b119cfa vici: Use default Unix vici socket if none passed to ruby constructor
While we currently have a static path instead of one generated with Autotools,
this at least is congruent to what we have in the Python library.
2015-03-18 13:59:14 +01:00
Martin Willi 61fb10c8cf vici: Support non-Unix sockets for vici connections using Python 2015-03-18 13:59:14 +01:00
Martin Willi 358793389a vici: Add python egg setuptools building and installation using easy_install
An uninstall target is currently not supported, as there is no trivial way with
either plain setuptools or with easy_install. pip would probably be the best
choice, but we currently don't depend on it.
2015-03-18 13:59:14 +01:00
Martin Willi 1e2ec9f96a vici: Generate a version specific setup.py for setuptools installation 2015-03-18 13:59:14 +01:00
Martin Willi 2c8c52c4e2 vici: Include python package in distribution 2015-03-18 13:59:14 +01:00
Björn Schuberg 163e15a571 vici: Add python package MIT license 2015-03-18 13:59:13 +01:00
Björn Schuberg b269c1a89a vici: Expose Session as a top-level symbol in python package 2015-03-18 13:59:13 +01:00
Björn Schuberg 6a31a0f60c vici: Introduce main API Session class in python package 2015-03-18 13:59:13 +01:00
Björn Schuberg 8c089cddef vici: Add a python vici command execution handler 2015-03-18 13:59:13 +01:00
Björn Schuberg b26e142863 vici: Add vici python protocol handler 2015-03-18 13:59:13 +01:00
Tobias Brunner 6d41927b42 vici: Use %u to print stats returned by mallinfo(3)
Fixes #886.
2015-03-13 15:26:01 +01:00
Martin Willi 1549a98493 vici: Don't use a default rand_time larger than half of rekey/reauth_time 2015-03-03 13:49:14 +01:00
Martin Willi f6511e36b5 vici: If a IKE reauth_time is configured, disable the default rekey_time 2015-03-03 13:49:14 +01:00
Martin Willi 1151c9922a vici: Support ruby gem out-of-tree builds
Referencing $(srcdir) in the gemspec is not really an option, as "gem build"
includes the full path in the gem, so we need to build in $(srcdir). As there
does not seem to be a way to control the output of "gem build", we manually
move the gem to $(builddir) in OOT builds.
2015-02-27 11:44:20 +01:00
Martin Willi 22e6a06b8c mem-pool: Pass the remote IKE address, to re-acquire() an address during reauth
With make-before-break IKEv2 re-authentication, virtual IP addresses must be
assigned overlapping to the same peer. With the remote IKE address, the backend
can detect re-authentication attempts by comparing the remote host address and
port. This allows proper reassignment of the virtual IP if it is re-requested.

This change removes the mem-pool.reassign_online option, as it is obsolete now.
IPs get automatically reassigned if a peer re-requests the same address, and
additionally connects from the same address and port.
2015-02-20 13:34:57 +01:00
Martin Willi bc9ded9dbf attribute-provider: Pass full IKE_SA to provider backends 2015-02-20 13:34:56 +01:00
Martin Willi 751363275f attributes: Move the configuration attributes framework to libcharon 2015-02-20 13:34:55 +01:00
Martin Willi 971a91685d controller: Use the CHILD_SA unique_id to terminate CHILD_SAs 2015-02-20 13:34:50 +01:00
Martin Willi adc1885bf7 vici: Include the CHILD_SA unique ID in list-sa event 2015-02-20 13:34:50 +01:00
Martin Willi c8992ea6d2 vici: Fix ruby gem author email 2015-01-22 15:00:45 +01:00
Martin Willi 96df0a0ebd vici: Fix README example encoding element type values, off by one
While we fixed the wrong values in the description with d39e04b5, the example
values are still off by one.

Fixes #828.
2015-01-21 09:31:24 +01:00
Martin Willi 6855b8b36b vici: Use silent builder destroy function in vici_free_req() 2014-12-12 10:23:59 +01:00
Martin Willi c04ee43af7 vici: Add a destroy method to builder, allowing cancellation without error
When cancelling a builder, finalize throws an error which we might prefer
to avoid.
2014-12-12 10:23:59 +01:00
Martin Willi b164cc8e15 vici: Make sure to send/recv all requested bytes over socket
As the underlying C functions, send/recv on ruby sockets are not guaranteed
to send/recv all requested bytes. Use wrapper functions to make sure we get
all bytes needed.
2014-12-04 10:42:22 +01:00
Tobias Brunner 5e92534313 vici: Add support for address range definitions of pools 2014-10-30 12:32:45 +01:00
Martin Willi bdfbecb3e6 vici: Return default value for get_int() if message value is empty string
This is the behavior of some strtol() implementations, and it makes sense,
so force it.
2014-10-14 16:33:10 +02:00
Tobias Brunner 283229bcb7 vici: Add vici.gemspec.in and vici.rb to distribution 2014-10-14 11:26:41 +02:00
Martin Willi d4d85135c5 vici: Cancel processor before calling library_deinit()
For non-direct libstrongswan users, the deinitialization segfaults because
of the missing worker thread cancellation.
2014-10-10 11:42:18 +02:00
Martin Willi 3db58e837c vici: Reduce debug level during thread spawning
We want to avoid libvici users to get a cluttered stderr for no real error.
2014-10-10 11:42:18 +02:00
Martin Willi 046b547a37 vici: Don't include-depend on libstrongswan for boolean types
As we want to avoid the libstrongswan include dependencies for libvici, avoid
the use of the bool type. Unfortunately this change may break the ABI for
vici_dump(). As this function is mostly for debugging purposes, we do it
nonetheless; my apologies if somebody already relies on the ABI stability of
that function.
2014-10-10 11:42:18 +02:00
Martin Willi 6f55149335 vici: Document the ruby gem and add some simple examples 2014-10-10 11:42:18 +02:00
Martin Willi dccb2c6eba vici: Add some simple libvici examples to the README 2014-10-10 11:42:18 +02:00
Martin Willi 56f17733c9 vici: Document the available vici command and event messages 2014-10-10 11:42:18 +02:00
Martin Willi f684be6583 vici: Use "gem"-assisted vici ruby gem building and installation 2014-10-10 11:42:17 +02:00
Martin Willi 1038d96537 vici: Add a ruby gem providing a native vici interface 2014-10-10 11:42:17 +02:00
Martin Willi 94d9398202 vici: Return a success result for the clear-creds command
Even if the command actually can't fail, this looks more aligned to similar
commands.
2014-10-10 11:42:17 +02:00
Martin Willi d39e04b557 vici: Fix message encoding type values in documentation 2014-10-10 11:42:17 +02:00
Martin Willi 455e213cb0 vici: Add a command to reload strongswan.conf 2014-09-22 13:44:27 +02:00
Tobias Brunner 3b16c2b55d libvici: Add missing argument to Doxygen comment 2014-06-30 13:16:16 +02:00
Tobias Brunner ed01c1afff Fixed some typos 2014-06-30 13:16:16 +02:00
Tobias Brunner 8661c56d38 vici: Install libvici in ipseclibdir like we do with other libraries 2014-06-19 14:42:07 +02:00
Martin Willi 5885ec2a27 vici: Support memory stats without leak-detective on Windows 2014-06-17 17:55:45 +02:00