1 # The Versatile IKE Control Interface (VICI) protocol #
3 The vici plugin implements the server side of an IPC protocol to configure,
4 monitor and control the IKE daemon charon. It uses request/response and event
5 messages to communicate over a reliable stream based transport.
7 ## Transport protocol ##
9 To provide the service, the plugin opens a listening socket using a reliable,
10 stream based transport. charon relies on the different stream service
11 abstractions provided by libstrongswan, such as TCP and UNIX sockets.
13 A client connects to this service to access functionality. It may send an
14 arbitrary number of packets over the connection before closing it.
16 To exchange data, the transport protocol is segmented into byte sequences.
17 Each byte sequence is prefixed by a 32-bit length header in network order,
18 followed by the data. The maximum segment length is currently limited to 512KB
19 of data, and the length field contains the length of the data only, not
20 including the length field itself.
22 The order of byte sequences must be strict, byte sequences must arrive in the
27 Within the byte sequences defined by the transport layer, both the client
28 and the server can exchange packets. The type of packet defines its structure
29 and purpose. The packet type is a 8-bit identifier, and is the first byte
30 in a transport layer byte sequence. The length of the packet is given by the
33 While a packet type may define the format of the wrapped data freely, currently
34 all types either contain a name, a message or both. The following packet types
35 are currently defined:
37 * _CMD_REQUEST = 0_: A named request message
38 * _CMD_RESPONSE = 1_: An unnamed response message for a request
39 * _CMD_UNKNOWN = 2_: An unnamed response if requested command is unknown
40 * _EVENT_REGISTER = 3_: A named event registration request
41 * _EVENT_UNREGISTER = 4_: A named event deregistration request
42 * _EVENT_CONFIRM = 5_: An unnamed response for successful event (de-)registration
43 * _EVENT_UNKNOWN = 6_: A unnamed response if event (de-)registration failed
44 * _EVENT = 7_: A named event message
46 For packets having a named type, after the packet type an 8-bit length header
47 of the name follows, indicating the string length in bytes of the name tag, not
48 including the length field itself. The name is an ASCII string that is not
51 The rest of the packet forms the exchanged message, the length is determined
52 by the transport byte sequence length, subtracting the packet type and
53 the optional name tag in some messages.
57 Commands are currently always requested by the client. The server replies with
58 a response, or with a CMD_UNKNOWN failure message to let the client know
59 that it does not have a handler for such a command. There is no sequence number
60 to associate responses to requests, so only one command can be active at
61 a time on a single connection.
65 To receive event messages, the client explicitly registers for events by name,
66 and also unregisters if it does not want to receive events of the named kind
67 anymore. The server confirms event registration using EVENT_CONFIRM, or
68 indicates that there is no such event source with EVENT_UNKNOWN.
70 Events may get raised at any time while registered, even during an active
71 request command. This mechanism is used to feed continuous data during a request,
76 The defined packet types optionally wrap a message with additional data.
77 Messages are currently used in CMD_REQUEST/CMD_RESPONSE, and in EVENT packets.
78 A message uses a hierarchial tree of sections. Each section (or the implicit
79 root section) contains an arbitrary set of key/value pairs, lists and
80 sub-sections. The length of a message is not part of the message itself, but
81 the wrapping layer, usually calculated from the transport byte sequence length.
83 The message encoding consists of a sequence of elements. Each element starts
84 with the element type, optionally followed by an element name and/or an element
85 value. Currently the following message element types are defined:
87 * _SECTION_START = 1_: Begin a new section having a name
88 * _SECTION_END = 2_: End a previously started section
89 * _KEY_VALUE = 3_: Define a value for a named key in the current section
90 * _LIST_START = 4_: Begin a named list for list items
91 * _LIST_ITEM = 5_: Define an unnamed item value in the current list
92 * _LIST_END = 6_: End a previously started list
94 Types are encoded as 8-bit values. Types having a name (SECTION_START,
95 KEY_VALUE and LIST_START) have an ASCII string following the type, which itself
96 uses an 8-bit length header. The string must not be null-terminated, the string
97 length does not include the length field itself.
99 Types having a value (KEY_VALUE and LIST_ITEM) have a raw blob sequence,
100 prefixed with a 16-bit network order length. The blob follows the type or the
101 name tag if available, the length defined by the length field does not include
102 the length field itself.
104 The interpretation of any value is not defined by the message format; it can
105 take arbitrary blobs. The application may specify types for specific keys, such
106 as strings or integer representations. The vici plugin currently uses
107 non-null terminated strings as values only; numbers get encoded as strings.
111 Sections may be opened in the implicit root section, or any previously section.
112 They can be nested to arbitrary levels. A SECTION_END marker always closes
113 the last opened section; SECTION_START and SECTION_END items must be balanced
118 Key/Value pair elements may appear in the implicit root section or any explicit
119 sub-section at any level. Key names must be unique in the current section, use
120 lists to define multiple values for a key. Key/values may not appear in lists,
121 use a sub-section instead.
125 Lists may appear at the same locations as Key/Values, and may not be nested.
126 Only a single list may be opened at the same time, and all lists must be closed
127 in valid messages. After opening a list, only list items may appear before the
128 list closing element. Empty lists are allowed, list items may appear within
131 ### Encoding example ###
133 Consider the following structure using pseudo-markup for this example:
140 list1 = [ item1, item2 ]
143 The example above reprensents a valid tree structure, that gets encoded as
144 the following C array:
148 3, 4,'k','e','y','1', 0,6,'v','a','l','u','e','1',
150 1, 8,'s','e','c','t','i','o','n','1',
152 1, 11,'s','u','b','-','s','e','c','t','i','o','n',
154 3, 4,'k','e','y','2', 0,6,'v','a','l','u','e','2',
155 /* sub-section end */
158 4, 5, 'l','i','s','t','1',
160 5, 0,5,'i','t','e','m','1',
162 5, 0,5,'i','t','e','m','2',
169 ## Client-initiated commands ##
171 Based on the packet layer, VICI implements commands requested by the client
172 and responded to by the server using named _CMD_REQUEST_ and _CMD_RESPONSE_
173 packets wrapping messages. The request message may contain command arguments,
174 the response message the reply.
176 Some commands use response streaming, that is, a request triggers a series of
177 events to consecutively stream data to the client before the response message
178 completes the stream. A client must register for the appropriate event to
179 receive the stream, and unregister after the response has been received.
181 The following client issued commands with the appropriate command input and
182 output messages are currently defined:
186 Returns daemon and system specific version information.
189 daemon = <IKE daemon name>
190 version = <strongSwan version>
191 sysname = <operating system name>
192 release = <operating system release>
193 machine = <hardware identifier>
198 Returns IKE daemon statistics and load information.
202 running = <relative uptime in human-readable form>
203 since = <absolute startup time>
206 total = <total number of worker threads>
207 idle = <worker threads currently idle>
209 critical = <threads processing "critical" priority jobs>
210 high = <threads processing "high" priority jobs>
211 medium = <threads processing "medium" priority jobs>
212 low = <threads processing "low" priority jobs>
216 critical = <jobs queued with "critical" priority>
217 high = <jobs queued with "high" priority>
218 medium = <jobs queued with "medium" priority>
219 low = <jobs queued with "low" priority>
221 scheduled = <number of jobs scheduled for timed execution>
223 total = <total number of IKE_SAs active>
224 half-open = <number of IKE_SAs in half-open state>
227 <names of loaded plugins>
229 mem = { # available if built with leak-detective or on Windows
230 total = <total heap memory usage in bytes>
231 allocs = <total heap allocation blocks>
232 <heap-name>* = { # on Windows only
233 total = <heap memory usage in bytes by this heap>
234 allocs = <allocated blocks for this heap>
237 mallinfo = { # available with mallinfo() support
238 sbrk = <non-mmaped space available>
239 mmap = <mmaped space available>
240 used = <total number of bytes used>
241 free = <available but unused bytes>
245 ### reload-settings() ###
247 Reloads _strongswan.conf_ settings and all plugins supporting configuration
251 success = <yes or no>
252 errmsg = <error string on failure>
257 Initiates an SA while streaming _control-log_ events.
260 child = <CHILD_SA configuration name to initiate>
261 ike = <optional IKE_SA configuraiton name to find child under>
262 timeout = <timeout in ms before returning>
263 init-limits = <whether limits may prevent initiating the CHILD_SA>
264 loglevel = <loglevel to issue "control-log" events for>
266 success = <yes or no>
267 errmsg = <error string on failure or timeout>
270 The default timeout of 0 waits indefinitely for a result, and a timeout value
271 of -1 returns a result immediately.
275 Terminates an SA while streaming _control-log_ events.
278 child = <terminate a CHILD_SA by configuration name>
279 ike = <terminate an IKE_SA by configuration name>
280 child_id = <terminate a CHILD_SA by its reqid>
281 ike_id = <terminate an IKE_SA by its unique id>
282 timeout = <timeout in ms before returning>
283 loglevel = <loglevel to issue "control-log" events for>
285 success = <yes or no>
286 errmsg = <error string on failure or timeout>
289 The default timeout of 0 waits indefinitely for a result, and a timeout value
290 of -1 returns a result immediately.
294 Install a trap, drop or bypass policy defined by a CHILD_SA config.
297 child = <CHILD_SA configuration name to install>
298 ike = <optional IKE_SA configuraiton name to find child under>
300 success = <yes or no>
301 errmsg = <error string on failure>
306 Uninstall a trap, drop or bypass policy defined by a CHILD_SA config.
309 child = <CHILD_SA configuration name to install>
311 success = <yes or no>
312 errmsg = <error string on failure>
317 Lists currently active IKE_SAs and associated CHILD_SAs by streaming _list-sa_
321 noblock = <use non-blocking mode if key is set>
322 ike = <filter listed IKE_SAs by its name>
323 ike_id = <filter listed IKE_SA by its unique id>
325 # completes after streaming list-sa events
328 ### list-policies() ###
330 List currently installed trap, drop and bypass policies by streaming
331 _list-policy_ events.
334 drop = <set to yes to list drop policies>
335 pass = <set to yes to list bypass policies>
336 trap = <set to yes to list trap policies>
337 child = <filter by CHILD_SA configuration name>
339 # completes after streaming list-sa events
344 List currently loaded connections by streaming _list-conn_ events. This
345 call includes all connections known by the daemon, not only those loaded
349 ike = <list connections matching a given configuration name only>
351 # completes after streaming list-conn events
356 Return a list of connection names loaded exclusively over vici, not including
357 connections found in other backends.
361 <list of connection names>
367 List currently loaded certificates by streaming _list-cert_ events. This
368 call includes all certificates known by the daemon, not only those loaded
372 type = <certificate type to filter for, X509|X509_AC|X509_CRL|
373 OCSP_RESPONSE|PUBKEY or ANY>
374 flag = <X.509 certificate flag to filter for, NONE|CA|AA|OCSP or ANY>
375 subject = <set to list only certificates having subject>
377 # completes after streaming list-cert events
380 ### list-authorities() ###
382 List currently loaded certification authority information by streaming
383 _list-authority_ events.
386 name = <list certification authority of a given name>
388 # completes after streaming list-authority events
391 ### get-authorities() ###
393 Return a list of currently loaded certification authority names.
397 <list of certification authority names>
403 Load a single connection definition into the daemon. An existing connection
404 with the same name gets updated or replaced.
407 <IKE_SA config name> = {
408 # IKE configuration parameters with authentication and CHILD_SA
409 # subsections. Refer to swanctl.conf(5) for details.
411 success = <yes or no>
412 errmsg = <error string on failure>
416 ### unload-conn() ###
418 Unload a previously loaded connection definition by name.
421 name = <IKE_SA config name>
423 success = <yes or no>
424 errmsg = <error string on failure>
429 Load a certificate into the daemon.
432 type = <certificate type, X509|X509_AC|X509_CRL>
433 flag = <X.509 certificate flag, NONE|CA|AA|OCSP>
434 data = <PEM or DER encoded certificate data>
436 success = <yes or no>
437 errmsg = <error string on failure>
442 Load a private key into the daemon.
445 type = <private key type, RSA|ECDSA>
446 data = <PEM or DER encoded key data>
448 success = <yes or no>
449 errmsg = <error string on failure>
452 ### load-shared() ###
454 Load a shared IKE PSK, EAP or XAuth secret into the daemon.
457 type = <private key type, IKE|EAP|XAUTH>
458 data = <raw shared key data>
460 <list of shared key owner identities>
463 success = <yes or no>
464 errmsg = <error string on failure>
467 ### clear-creds() ###
469 Clear all loaded certificate, private key and shared key credentials. This
470 affects only credentials loaded over vici, but additionally flushes the
474 success = <yes or no>
475 errmsg = <error string on failure>
478 ### load-authority() ###
480 Load a single certification authority definition into the daemon. An existing
481 authority with the same name gets replaced.
484 <certification authority name> = {
485 # certification authority parameters
486 # refer to swanctl.conf(5) for details.
488 success = <yes or no>
489 errmsg = <error string on failure>
493 ### unload-authority() ###
495 Unload a previously loaded certification authority definition by name.
498 name = <certification authority name>
500 success = <yes or no>
501 errmsg = <error string on failure>
506 Load an in-memory virtual IP and configuration attribute pool. Existing
507 pools with the same name get updated, if possible.
511 addrs = <subnet of virtual IP pool addresses>
512 <attribute type>* = [
513 # attribute type is one of address, dns, nbns, dhcp, netmask,
514 # server, subnet, split_include, split_exclude or a numerical
515 # attribute type identifier.
516 <list of attributes for type>
520 success = <yes or no>
521 errmsg = <error string on failure>
524 ### unload-pool() ###
526 Unload a previously loaded virtual IP and configuration attribute pool.
527 Unloading fails for pools with leases currently online.
530 name = <virtual IP address pool to delete>
532 success = <yes or no>
533 errmsg = <error string on failure>
538 List the currently loaded pools.
541 leases = <set to yes to include leases>
544 base = <virtual IP pool base address>
545 size = <total number of addresses in the pool>
546 online = <number of leases online>
547 offline = <number of leases offline>
549 <zero-based index>* = {
550 address = <IP address>
551 identity = <assigned identity>
552 status = <online|offline>
558 ### get-algorithms() ###
560 List currently loaded algorithms and their implementation.
564 <algorithm> = <plugin providing the implementation>
568 ## Server-issued events ##
570 Based on the packet layer, the vici plugin raises event messages using named
571 EVENT packets wrapping messages. The message contains event details.
575 The _log_ event is issued to registered clients for each debug log message.
576 This event is not associated with a command.
579 group = <subsystem identifier for debug message>
580 level = <log level, 0-4>
581 thread = <numerical thread identifier issuing the log message>
582 ikesa-name = <name of IKE_SA, if log is associated with any>
583 ikesa-uniqued = <unique identifier of IKE_A, if log associated with any>
584 msg = <log message text>
589 The _control-log_ event is issued for log events during active _initiate_ or
590 _terminate_ commands. It is issued only to clients currently having such
594 group = <subsystem identifier for debug message>
595 level = <log level, 0-4>
596 ikesa-name = <name of IKE_SA, if log associated with any>
597 ikesa-uniqued = <unique identifier of IKE_A, if log associated with any>
598 msg = <log message text>
603 The _list-sa_ event is issued to stream IKE_SAs during an active _list-sas_
607 <IKE_SA config name> = {
608 uniqueid = <IKE_SA unique identifier>
609 version = <IKE version, 1 or 2>
610 state = <IKE_SA state name>
611 local-host = <local IKE endpoint address>
612 local-id = <local IKE identity>
613 remote-host = <remote IKE endpoint address>
614 remote-id = <remote IKE identity>
615 remote-xauth-id = <remote XAuth identity, if XAuth-authenticated>
616 remote-eap-id = <remote EAP identity, if EAP-authenticated>
617 initiator = <yes, if initiator of IKE_SA>
618 initiator-spi = <hex encoded initiator SPI / cookie>
619 responder-spi = <hex encoded responder SPI / cookie>
620 nat-local = <yes, if local endpoint is behind a NAT>
621 nat-remote = <yes, if remote endpoint is behind a NAT>
622 nat-fake = <yes, if NAT situation has been faked as responder>
623 nat-any = <yes, if any endpoint is behind a NAT (also if faked)>
624 encr-alg = <IKE encryption algorithm string>
625 encr-keysize = <key size for encr-alg, if applicable>
626 integ-alg = <IKE integrity algorithm string>
627 integ-keysize = <key size for encr-alg, if applicable>
628 prf-alg = <IKE pseudo random function string>
629 dh-group = <IKE Diffie-Hellman group string>
630 established = <seconds the IKE_SA has been established>
631 rekey-time = <seconds before IKE_SA gets rekeyed>
632 reauth-time = <seconds before IKE_SA gets re-authenticated>
634 <list of virtual IPs assigned by the remote peer, installed locally>
637 <list of virtual IPs assigned to the remote peer>
640 <list of currently queued tasks for execution>
643 <list of tasks currently initiating actively>
646 <list of tasks currently handling passively>
650 uniqueid = <unique CHILD_SA identifier>
651 reqid = <reqid of CHILD_SA>
652 state = <state string of CHILD_SA>
653 mode = <IPsec mode, tunnel|transport|beet>
654 protocol = <IPsec protocol AH|ESP>
655 encap = <yes if using UDP encapsulation>
656 spi-in = <hex encoded inbound SPI>
657 spi-out = <hex encoded outbound SPI>
658 cpi-in = <hex encoded inbound CPI, if using compression>
659 cpi-out = <hex encoded outbound CPI, if using compression>
660 encr-alg = <ESP encryption algorithm name, if any>
661 encr-keysize = <ESP encryption key size, if applicable>
662 integ-alg = <ESP or AH integrity algorithm name, if any>
663 integ-keysize = <ESP or AH integrity key size, if applicable>
664 prf-alg = <CHILD_SA pseudo random function name>
665 dh-group = <CHILD_SA PFS rekeying DH group name, if any>
666 esn = <1 if using extended sequence numbers>
667 bytes-in = <number of input bytes processed>
668 packets-in = <number of input packets processed>
669 use-in = <seconds since last inbound packet, if any>
670 bytes-out = <number of output bytes processed>
671 packets-out = <number of output packets processed>
672 use-out = <seconds since last outbound packet, if any>
673 rekey-time = <seconds before CHILD_SA gets rekeyed>
674 life-time = <seconds before CHILD_SA expires>
675 install-time = <seconds the CHILD_SA has been installed>
677 <list of local traffic selectors>
680 <list of remote traffic selectors>
689 The _list-policy_ event is issued to stream installed policies during an active
690 _list-policies_ command.
693 <child-sa-config-name> = {
694 mode = <policy mode, tunnel|transport|pass|drop>
696 <list of local traffic selectors>
699 <list of remote traffic selectors>
706 The _list-conn_ event is issued to stream loaded connection during an active
707 _list-conns_ command.
710 <IKE_SA connection name> = {
712 <list of valid local IKE endpoint addresses>
715 <list of valid remote IKE endpoint addresses>
717 version = <IKE version as string, IKEv1|IKEv2 or 0 for any>
719 local*, remote* = { # multiple local and remote auth sections
720 class = <authentication type>
721 eap-type = <EAP type to authenticate if when using EAP>
722 eap-vendor = <EAP vendor for type, if any>
723 xauth = <xauth backend name>
724 revocation = <revocation policy>
726 aaa_id = <AAA authentication backend identity>
727 eap_id = <EAP identity for authentication>
728 xauth_id = <XAuth username for authentication>
730 <group membership required to use connection>
733 <certificates allowed for authentication>
736 <CA certificates allowed for authentication>
740 <CHILD_SA config name>* = {
743 <list of local traffic selectors>
746 <list of remote traffic selectors>
755 The _list-cert_ event is issued to stream loaded certificates during an active
756 _list-certs_ command.
759 type = <certificate type, X509|X509_AC|X509_CRL|OCSP_RESPONSE|PUBKEY>
760 flag = <X.509 certificate flag, NONE|CA|AA|OCSP>
761 has_privkey = <set if a private key for the certificate is available>
762 data = <ASN1 encoded certificate data>
763 subject = <subject string if defined and certificate type is PUBKEY>
764 not-before = <time string if defined and certificate type is PUBKEY>
765 not-after = <time string if defined and certificate type is PUBKEY>
768 ### list-authority ###
770 The _list-authority_ event is issued to stream loaded certification authority
771 information during an active_list-authorities_ command.
774 <certification authority name> = {
775 cacert = <subject distinguished name of CA certificate>
777 <CRL URI (http, ldap or file)>
782 cert_uri_base = <base URI for download of hash-and-URL certificates>
788 The _ike-updown_ event is issued when an IKE_SA is established or terminated.
791 up = <set if up event>
792 <IKE_SA config name> = {
793 <same data as in the list-sas event, but without child-sas section>
799 The _ike-rekey_ event is issued when an IKE_SA is rekeyed.
802 <IKE_SA config name> = {
804 <same data as in the list-sas event, but without child-sas section>
807 <same data as in the list-sas event, but without child-sas section>
814 The _child-updown_ event is issued when a CHILD_SA is established or terminated.
817 up = <set if up event>
818 <IKE_SA config name> = {
819 <same data as in the list-sas event, but with only the affected
820 CHILD_SA in the child-sas section>
826 The _child-rekey_ event is issued when a CHILD_SA is rekeyed.
829 <IKE_SA config name> = {
830 <same data as in the list-sas event, but with the child-sas section
835 <same data as in the list-sas event>
838 <same data as in the list-sas event>
845 # libvici C client library #
847 libvici is the reference implementation of a C client library implementing
848 the vici protocol. It builds upon libstrongswan, but provides a stable API
849 to implement client applications in the C programming language. libvici uses
850 the libstrongswan thread pool to deliver event messages asynchronously.
852 ## Connecting to the daemon ##
854 This example shows how to connect to the daemon using the default URI, and
855 then perform proper cleanup:
863 int main(int argc, char *argv[])
869 conn = vici_connect(NULL);
873 vici_disconnect(conn);
878 fprintf(stderr, "connecting failed: %s\n", strerror(errno));
884 ## A simple client request ##
886 In the following example, a simple _version_ request is issued to the daemon
887 and the result is printed:
889 int get_version(vici_conn_t *conn)
895 req = vici_begin("version");
896 res = vici_submit(req, conn);
899 printf("%s %s (%s, %s, %s)\n",
900 vici_find_str(res, "", "daemon"),
901 vici_find_str(res, "", "version"),
902 vici_find_str(res, "", "sysname"),
903 vici_find_str(res, "", "release"),
904 vici_find_str(res, "", "machine"));
910 fprintf(stderr, "version request failed: %s\n", strerror(errno));
915 ## A request with event streaming and callback parsing ##
917 In this more advanced example, the _list-conns_ command is used to stream
918 loaded connections with the _list-conn_ event. The event message is parsed
919 with a simple callback to print the connection name:
921 int conn_cb(void *null, vici_res_t *res, char *name)
923 printf("%s\n", name);
927 void list_cb(void *null, char *name, vici_res_t *res)
929 if (vici_parse_cb(res, conn_cb, NULL, NULL, NULL) != 0)
931 fprintf(stderr, "parsing failed: %s\n", strerror(errno));
935 int list_conns(vici_conn_t *conn)
941 if (vici_register(conn, "list-conn", list_cb, NULL) == 0)
943 req = vici_begin("list-conns");
944 res = vici_submit(req, conn);
952 fprintf(stderr, "request failed: %s\n", strerror(errno));
954 vici_register(conn, "list-conn", NULL, NULL);
959 fprintf(stderr, "registration failed: %s\n", strerror(errno));
964 ## API documentation ##
966 More information about the libvici API is available in the _libvici.h_ header
967 file or the generated Doxygen documentation.
971 The _vici ruby gem_ is a pure ruby implementation of the VICI protocol to
972 implement client applications. It is provided in the _ruby_ subdirectory, and
973 gets built and installed if strongSwan has been _./configure_'d with
974 _--enable-vici_ and _--enable-ruby-gems_.
976 The _Connection_ class from the _Vici_ module provides the high level interface,
977 the underlying classes are usually not required to build ruby applications
978 using VICI. The _Connection_ class provides methods for the supported VICI
979 commands and an event listening mechanism.
981 To represent the VICI message data tree, the gem converts the binary encoding
982 to ruby data types. The _Connection_ class takes and returns ruby objects for
983 the exchanged message data:
984 * Sections get encoded as Hash, containing other sections as Hash, or
985 * Key/Values, where the values are Strings as Hash values
986 * Lists get encoded as Arrays with String values
987 Non-String values that are not a Hash nor an Array get converted with .to_s
990 ## Connecting to the daemon ##
992 To create a connection to the daemon, a socket can be passed to the
993 _Connection_ constructor. If none is passed, a default Unix socket at
994 _/var/run/charon.vici_ is used:
999 v = Vici::Connection.new(UNIXSocket.new("/var/run/charon.vici"))
1001 ## A simple client request ##
1003 An example to print the daemon version information is as simple as:
1006 puts "%s %s (%s, %s, %s)" % [
1007 x["daemon"], x["version"], x["sysname"], x["release"], x["machine"]
1010 ## A request with closure invocation ##
1012 The _Connection_ class takes care of event streaming by invoking a closure
1013 for each event. The following example lists all loaded connections using the
1014 _list-conns_ command and implicitly the _list-conn_ event:
1016 v.list_conns { |conn|
1017 conn.each { |key, value|
1022 ## API documentation ##
1024 For more details about the ruby gem refer to the comments in the gem source
1025 code or the generated documentation.
1029 The _vici Python egg_ is a pure Python implementation of the VICI protocol to
1030 implement client applications. It is provided in the _python_ subdirectory, and
1031 gets built and installed if strongSwan has been _./configure_'d with
1032 _--enable-vici_ and _--enable-python-eggs_.
1034 The _vici_ module provides a _Session()_ constructor for a high level interface,
1035 the underlying classes are usually not required to build Python applications
1036 using VICI. The _Session_ class provides methods for the supported VICI
1039 To represent the VICI message data tree, the library converts the binary
1040 encoding to Python data types. The _Session_ class takes and returns Python
1041 objects for the exchanged message data:
1042 * Sections get encoded as OrderedDict, containing other sections, or
1043 * Key/Values, where the values are strings as dictionary values
1044 * Lists get encoded as Python Lists with string values
1045 Values that do not conform to Python dict or list get converted to strings using
1048 ## Connecting to the daemon ##
1050 To create a connection to the daemon, a socket can be passed to the _Session_
1051 constructor. If none is passed, a default Unix socket at _/var/run/charon.vici_
1057 s = socket.socket(socket.AF_UNIX)
1058 s.connect("/var/run/charon.vici")
1061 ## A simple client request ##
1063 An example to print the daemon version information is as simple as:
1067 print "{daemon} {version} ({sysname}, {release}, {machine})".format(**ver)
1069 ## A request with response iteration ##
1071 The _Session_ class returns an iterable Python generator for streamed events to
1072 continuously stream objects to the caller. The following example lists all
1073 loaded connections using the _list-conns_ command and implicitly the _list-conn_
1076 for conn in v.list_conns():
1080 Please note that if the returned generator is not iterated completely, it must
1081 be closed using _close()_. This is implicitly done when breaking from a loop,
1082 but an explicit call may be required when directly iterating the generator with
1085 ## Sorting in dictionaries ##
1087 In VICI, in some message trees the order of objects in dictionary matters. In
1088 contrast to ruby Hashes, Python dictionaries do not preserve order of added
1089 objects. It is therefore recommended to use OrderedDicts instead of the default
1090 dictionaries. Objects returned by the library use OrderedDicts.
1092 ## API documentation ##
1094 For more details about the Python egg refer to the comments in the Python source
1097 # Vici::Session Perl CPAN module #
1099 The _Vici::Session Perl CPAN module_ is a pure Perl implementation of the VICI
1100 protocol to implement client applications. It is provided in the _perl_
1101 subdirectory, and gets built and installed if strongSwan has been
1102 _./configure_'d with_--enable-vici_ and _--enable-perl-cpan_.
1104 The _Vici::Session_ module provides a _new()_ constructor for a high level
1105 interface, the underlying _Vici::Packet_ and _Vici::Transport_ classes are
1106 usually not required to build Perl applications using VICI. The _Vici::Session_
1107 class provides methods for the supported VICI commands. The auxiliare
1108 _Vici::Message_ class is used to encode configuration parameters sent to
1109 the daemon and decode data returned by the daemon.
1111 ## Connecting to the daemon ##
1113 use IO::Socket::UNIX;
1117 my $socket = IO::Socket::UNIX->new(
1118 Type => SOCK_STREAM,
1119 Peer => '/var/run/charon.vici',
1120 ) or die "Vici socket: $!";
1122 my $session = Vici::Session->new($socket);
1124 ## A simple client request ##
1126 An example to print the daemon version information is as simple as:
1128 my $version = $session->version()->hash();
1130 foreach my $key ('daemon', 'version', 'sysname', 'release', 'machine' ) {
1131 print $version->{$key}, " ";
1134 The _Vici::Session_ methods are explained in the perl/Vici-Session/README.pod