From: Felix Kaiser Date: Fri, 4 Oct 2019 06:18:30 +0000 (-0700) Subject: vici: Use unique names for CHILD_SAs in the child-updown event too X-Git-Tag: 5.8.2dr1~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c74ce91904b0c6d76683b76c430e4c8678f2e2a;p=thirdparty%2Fstrongswan.git vici: Use unique names for CHILD_SAs in the child-updown event too The unique names were introduced for the list-sas command in commit 04c0219e55d9338b6492548c073189bfd3d5431b. However, the child-updown event wasn't updated to match. Even though the documentation suggests that the section name of the CHILD_SAs are the same in both messages. The original name is already being returned in the "name" attribute, so it'll still be available. Example: >>> import vici, json >>> s = vici.Session() # First, for comparison, the list-sas command: >>> print(json.dumps(list(s.list_sas()), sort_keys=True, indent=4, separators=(',', ': '))) [ { "vti0": { "child-sas": { "vti0-1": { ... # A child-updown event before the change: >>> for x in s.listen(["child-updown"]): print(json.dumps(x, sort_keys=True, indent=4, separators=(',', ': '))) [ "child-updown", { "vti0": { "child-sas": { "vti0": { # <-- wrong: inconsistent with list-sas ... # A child-updown event after the change: >>> s = vici.Session() >>> for x in s.listen(["child-updown"]): print(json.dumps(x, sort_keys=True, indent=4, separators=(',', ': '))) [ "child-updown", { "vti0": { "child-sas": { "vti0-1": { # <-- fixed Closes strongswan/strongswan#153. --- diff --git a/src/libcharon/plugins/vici/vici_query.c b/src/libcharon/plugins/vici/vici_query.c index 16e3c8b1fc..346ffb548f 100644 --- a/src/libcharon/plugins/vici/vici_query.c +++ b/src/libcharon/plugins/vici/vici_query.c @@ -1716,6 +1716,7 @@ METHOD(listener_t, child_updown, bool, { vici_builder_t *b; time_t now; + char buf[BUF_LEN]; if (!this->dispatcher->has_event_listeners(this->dispatcher, "child-updown")) { @@ -1734,7 +1735,10 @@ METHOD(listener_t, child_updown, bool, list_ike(this, b, ike_sa, now); b->begin_section(b, "child-sas"); - b->begin_section(b, child_sa->get_name(child_sa)); + snprintf(buf, sizeof(buf), "%s-%u", child_sa->get_name(child_sa), + child_sa->get_unique_id(child_sa)); + + b->begin_section(b, buf); list_child(this, b, child_sa, now); b->end_section(b);