]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: fix processing of notifications on mgmt fe client 15421/head
authorIgor Ryzhov <iryzhov@nfware.com>
Fri, 23 Feb 2024 16:53:46 +0000 (18:53 +0200)
committerIgor Ryzhov <iryzhov@nfware.com>
Fri, 23 Feb 2024 16:53:46 +0000 (18:53 +0200)
Notifications are sent by mgmtd for each session of a client, so they
should be processed once per each session.

Also, add session_id parameter to an async_notification callback as all
other callbacks have this parameter.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
lib/mgmt_fe_client.c
lib/mgmt_fe_client.h

index bfdecedc4e1e7509aadf5083fa1c1e8cd6dab7f0..a107582bea07319a9cb2ad9ee77571e60fae6238 100644 (file)
@@ -510,14 +510,11 @@ static void fe_client_handle_native_msg(struct mgmt_fe_client *client,
        debug_fe_client("Got native message for session-id %" PRIu64,
                        msg->refer_id);
 
-       if (msg->code != MGMT_MSG_CODE_NOTIFY) {
-               session = mgmt_fe_find_session_by_session_id(client,
-                                                            msg->refer_id);
-               if (!session || !session->client) {
-                       log_err_fe_client("No session for received native msg session-id %" PRIu64,
-                                         msg->refer_id);
-                       return;
-               }
+       session = mgmt_fe_find_session_by_session_id(client, msg->refer_id);
+       if (!session || !session->client) {
+               log_err_fe_client("No session for received native msg session-id %" PRIu64,
+                                 msg->refer_id);
+               return;
        }
 
        switch (msg->code) {
@@ -558,6 +555,9 @@ static void fe_client_handle_native_msg(struct mgmt_fe_client *client,
                                                     tree_msg->partial_error);
                break;
        case MGMT_MSG_CODE_NOTIFY:
+               if (!session->client->cbs.async_notification)
+                       return;
+
                notify_msg = (typeof(notify_msg))msg;
                if (msg_len < sizeof(*notify_msg)) {
                        log_err_fe_client("Corrupt notify-data msg recv");
@@ -579,15 +579,13 @@ static void fe_client_handle_native_msg(struct mgmt_fe_client *client,
                                          notify_msg->result_type);
                        return;
                }
-               FOREACH_SESSION_IN_LIST (client, session) {
-                       if (!session->client->cbs.async_notification)
-                               continue;
 
-                       session->client->cbs
-                               .async_notification(client, client->user_data,
-                                                   session->client_id,
-                                                   session->user_ctx, data);
-               }
+               session->client->cbs.async_notification(client,
+                                                       client->user_data,
+                                                       session->client_id,
+                                                       msg->refer_id,
+                                                       session->user_ctx, data);
+
                if (notify_msg->result_type != LYD_JSON)
                        darr_free(data);
                break;
index 7af1270071394d4b33468c08bde8396f751e3c42..eee4594e17dcafecb68206aceccb27f5b492a71e 100644 (file)
@@ -117,7 +117,8 @@ struct mgmt_fe_client_cbs {
        /* Called with asynchronous notifications from backends */
        int (*async_notification)(struct mgmt_fe_client *client,
                                  uintptr_t user_data, uint64_t client_id,
-                                 uintptr_t session_ctx, const char *result);
+                                 uint64_t session_id, uintptr_t session_ctx,
+                                 const char *result);
 
        /* Called when new native error is returned */
        int (*error_notify)(struct mgmt_fe_client *client, uintptr_t user_data,