Skip to content

Commit

Permalink
Merge pull request #15421 from idryzhov/fix-fe-client-notify
Browse files Browse the repository at this point in the history
lib: fix processing of notifications on mgmt fe client
  • Loading branch information
choppsv1 authored Feb 23, 2024
2 parents eae228c + 13359c5 commit 81db169
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
30 changes: 14 additions & 16 deletions lib/mgmt_fe_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion lib/mgmt_fe_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 81db169

Please sign in to comment.