]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
vici: Expose ike-update event
authorTobias Brunner <tobias@strongswan.org>
Thu, 22 Oct 2020 17:12:39 +0000 (19:12 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 18 Jan 2021 10:34:40 +0000 (11:34 +0100)
src/libcharon/plugins/vici/README.md
src/libcharon/plugins/vici/vici_query.c

index cf2e7482eb927fa79ba6ea2a8ace8f918e3bf225..11c6e8166536861009b8a1601a32d8456c515274 100644 (file)
@@ -976,6 +976,22 @@ The _ike-rekey_ event is issued when an IKE_SA is rekeyed.
                }
        }
 
+### ike-update ###
+
+The _ike-update_ event is issued when the local or remote endpoint address of an
+IKE_SA is about to change (at least one address/port is different).
+
+       {
+               local-host = <new/current local IKE endpoint address>
+               local-port = <new/current local IKE endpoint port>
+               remote-host = <new/current remote IKE endpoint address>
+               remote-port = <new/current remote IKE endpoint port>
+               <IKE_SA config name> = {
+                       <same data as in the list-sas event, but without child-sas section
+                        and listing the old addresses/ports>
+               }
+       }
+
 ### child-updown ###
 
 The _child-updown_ event is issued when a CHILD_SA is established or terminated.
index ad07ff12d04748c7b207a67fff685bc2bf731c3c..fb65b14472c5193def00483e734d630dfbb88bb1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2017 Tobias Brunner
+ * Copyright (C) 2015-2020 Tobias Brunner
  * Copyright (C) 2015-2018 Andreas Steffen
  * HSR Hochschule fuer Technik Rapperswil
  *
@@ -510,6 +510,7 @@ CALLBACK(list_sas, vici_message_t*,
        bool bl;
        char buf[BUF_LEN];
 
+
        bl = request->get_str(request, NULL, "noblock") == NULL;
        ike = request->get_str(request, NULL, "ike");
        ike_id = request->get_int(request, 0, "ike-id");
@@ -1683,6 +1684,7 @@ static void manage_commands(private_vici_query_t *this, bool reg)
        this->dispatcher->manage_event(this->dispatcher, "list-cert", reg);
        this->dispatcher->manage_event(this->dispatcher, "ike-updown", reg);
        this->dispatcher->manage_event(this->dispatcher, "ike-rekey", reg);
+       this->dispatcher->manage_event(this->dispatcher, "ike-update", reg);
        this->dispatcher->manage_event(this->dispatcher, "child-updown", reg);
        this->dispatcher->manage_event(this->dispatcher, "child-rekey", reg);
        manage_command(this, "list-sas", list_sas, reg);
@@ -1755,6 +1757,36 @@ METHOD(listener_t, ike_rekey, bool,
        return TRUE;
 }
 
+METHOD(listener_t, ike_update, bool,
+       private_vici_query_t *this, ike_sa_t *ike_sa, host_t *local, host_t *remote)
+{
+       vici_builder_t *b;
+       time_t now;
+
+       if (!this->dispatcher->has_event_listeners(this->dispatcher, "ike-update"))
+       {
+               return TRUE;
+       }
+
+       now = time_monotonic(NULL);
+
+       b = vici_builder_create();
+
+       b->add_kv(b, "local-host", "%H", local);
+       b->add_kv(b, "local-port", "%d", local->get_port(local));
+       b->add_kv(b, "remote-host", "%H", remote);
+       b->add_kv(b, "remote-port", "%d", remote->get_port(remote));
+
+       b->begin_section(b, ike_sa->get_name(ike_sa));
+       list_ike(this, b, ike_sa, now);
+       b->end_section(b);
+
+       this->dispatcher->raise_event(this->dispatcher,
+                                                                 "ike-update", 0, b->finalize(b));
+
+       return TRUE;
+}
+
 METHOD(listener_t, child_updown, bool,
        private_vici_query_t *this, ike_sa_t *ike_sa, child_sa_t *child_sa, bool up)
 {
@@ -1853,6 +1885,7 @@ vici_query_t *vici_query_create(vici_dispatcher_t *dispatcher)
                        .listener = {
                                .ike_updown = _ike_updown,
                                .ike_rekey = _ike_rekey,
+                               .ike_update = _ike_update,
                                .child_updown = _child_updown,
                                .child_rekey = _child_rekey,
                        },