diff options
| author | Igor Ryzhov <iryzhov@nfware.com> | 2024-02-10 00:58:49 +0200 | 
|---|---|---|
| committer | Igor Ryzhov <iryzhov@nfware.com> | 2024-02-10 01:00:24 +0200 | 
| commit | d94f80fbc4347cbbf5ee6ecbdf3682329db832dc (patch) | |
| tree | dab7de197df1ae57c726701d24e8eaeb918a2a00 /lib/mgmt_be_client.c | |
| parent | 75d3e4336855c2631f0a7bbecb1548ef8a7a9fb7 (diff) | |
lib, mgmtd: fix processing of yang notifications
Current code assumes that notification is always sent in stripped JSON
format and therefore notification xpath starts at the third symbol of
notification data. Assuming JSON is more or less fine, because this
representation is internal to FRR, but the assumption about the xpath is
wrong, because it won't work for not top-level notifications. YANG
allows to define notification as a child for some data node deep into
the tree and in this case notification data contains not only the
notification node itself, but also all its parents.
To fix the issue, parse the notification data and get its xpath from its
schema node.
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Diffstat (limited to 'lib/mgmt_be_client.c')
| -rw-r--r-- | lib/mgmt_be_client.c | 14 | 
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/mgmt_be_client.c b/lib/mgmt_be_client.c index 6530022db8..e2a720acb7 100644 --- a/lib/mgmt_be_client.c +++ b/lib/mgmt_be_client.c @@ -964,13 +964,21 @@ static void be_client_handle_notify(struct mgmt_be_client *client, void *msgbuf,  {  	struct mgmt_msg_notify_data *notif_msg = msgbuf;  	struct mgmt_be_client_notification_cb *cb; -	const char *notif; +	char notif[XPATH_MAXLEN]; +	struct lyd_node *dnode; +	LY_ERR err;  	uint i;  	debug_be_client("Received notification for client %s", client->name); -	/* "{\"modname:notification-name\": ...}" */ -	notif = (const char *)notif_msg->result + 2; +	err = yang_parse_notification(notif_msg->result_type, +				      (char *)notif_msg->result, &dnode); +	if (err) +		return; + +	lysc_path(dnode->schema, LYSC_PATH_DATA, notif, sizeof(notif)); + +	lyd_free_all(dnode);  	for (i = 0; i < client->cbs.nnotify_cbs; i++) {  		cb = &client->cbs.notify_cbs[i];  | 
