diff options
author | Donald Sharp <donaldsharp72@gmail.com> | 2025-01-07 19:15:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-07 19:15:40 +0100 |
commit | 0a52c233d366b6c97bafe941cbee37890fab7e93 (patch) | |
tree | 06802aac3d88c6e5d9bb8fd4cdddb8500bb7952c /lib | |
parent | Merge pull request #17783 from LabNConsulting/chopps/new-oper-get-callback (diff) | |
parent | tests: fe-client: only pick mgmtd FE notify selectors once (diff) | |
download | frr-0a52c233d366b6c97bafe941cbee37890fab7e93.tar.xz frr-0a52c233d366b6c97bafe941cbee37890fab7e93.zip |
Merge pull request #17782 from LabNConsulting/chopps/new-notify-msg-fmt
New YANG notify msg fmt
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mgmt_be_client.c | 92 | ||||
-rw-r--r-- | lib/mgmt_be_client.h | 16 | ||||
-rw-r--r-- | lib/mgmt_msg_native.h | 13 |
3 files changed, 99 insertions, 22 deletions
diff --git a/lib/mgmt_be_client.c b/lib/mgmt_be_client.c index f03006ad0..05949fd62 100644 --- a/lib/mgmt_be_client.c +++ b/lib/mgmt_be_client.c @@ -312,11 +312,11 @@ static int be_client_send_error(struct mgmt_be_client *client, uint64_t txn_id, return ret; } -static int mgmt_be_send_notification(void *__be_client, const char *xpath, - const struct lyd_node *tree) +static int __send_notification(struct mgmt_be_client *client, const char *xpath, + const struct lyd_node *tree, uint8_t op) { - struct mgmt_be_client *client = __be_client; struct mgmt_msg_notify_data *msg = NULL; + // LYD_FORMAT format = LYD_LYB; LYD_FORMAT format = LYD_JSON; uint8_t **darrp; LY_ERR err; @@ -324,37 +324,91 @@ static int mgmt_be_send_notification(void *__be_client, const char *xpath, assert(tree); - debug_be_client("%s: sending YANG notification: %s", __func__, - tree->schema->name); + debug_be_client("%s: sending %sYANG %snotification: %s", __func__, + op == NOTIFY_OP_DS_DELETE ? "delete " + : op == NOTIFY_OP_DS_REPLACE ? "replace " + : op == NOTIFY_OP_DS_PATCH ? "patch " + : "", + op == NOTIFY_OP_NOTIFICATION ? "" : "DS ", xpath ?: tree->schema->name); /* * Allocate a message and append the data to it using `format` */ - msg = mgmt_msg_native_alloc_msg(struct mgmt_msg_notify_data, 0, - MTYPE_MSG_NATIVE_NOTIFY); + msg = mgmt_msg_native_alloc_msg(struct mgmt_msg_notify_data, 0, MTYPE_MSG_NATIVE_NOTIFY); msg->code = MGMT_MSG_CODE_NOTIFY; msg->result_type = format; + msg->op = op; mgmt_msg_native_xpath_encode(msg, xpath); - darrp = mgmt_msg_native_get_darrp(msg); - err = yang_print_tree_append(darrp, tree, format, - (LYD_PRINT_SHRINK | LYD_PRINT_WD_EXPLICIT | - LYD_PRINT_WITHSIBLINGS)); - if (err) { - flog_err(EC_LIB_LIBYANG, - "%s: error creating notification data: %s", __func__, - ly_strerrcode(err)); - ret = 1; - goto done; + if (tree) { + darrp = mgmt_msg_native_get_darrp(msg); + err = yang_print_tree_append(darrp, tree, format, + (LYD_PRINT_SHRINK | LYD_PRINT_WD_EXPLICIT | + LYD_PRINT_WITHSIBLINGS)); + if (err) { + flog_err(EC_LIB_LIBYANG, "%s: error creating notification data: %s", + __func__, ly_strerrcode(err)); + ret = 1; + goto done; + } } - (void)be_client_send_native_msg(client, msg, - mgmt_msg_native_get_msg_len(msg), false); + ret = be_client_send_native_msg(client, msg, mgmt_msg_native_get_msg_len(msg), false); done: mgmt_msg_native_free_msg(msg); return ret; } +/** + * mgmt_be_send_ds_delete_notification() - Send DS notification to mgmtd + */ +int mgmt_be_send_ds_delete_notification(const char *path) +{ + if (!__be_client) { + debug_be_client("%s: No mgmtd connection for DS delete notification: %s", __func__, + path); + return 1; + } + return __send_notification(__be_client, path, NULL, NOTIFY_OP_DS_DELETE); +} + +/** + * mgmt_be_send_ds_patch_notification() - Send a YANG patch DS notification to mgmtd + */ +int mgmt_be_send_ds_patch_notification(const char *path, const struct lyd_node *patch) +{ + if (!__be_client) { + debug_be_client("%s: No mgmtd connection for DS delete notification: %s", __func__, + path); + return 1; + } + return __send_notification(__be_client, path, patch, NOTIFY_OP_DS_PATCH); +} + +/** + * mgmt_be_send_ds_replace_notification() - Send a replace DS notification to mgmtd + */ +int mgmt_be_send_ds_replace_notification(const char *path, const struct lyd_node *tree) +{ + if (!__be_client) { + debug_be_client("%s: No mgmtd connection for DS delete notification: %s", __func__, + path); + return 1; + } + return __send_notification(__be_client, path, tree, NOTIFY_OP_DS_REPLACE); +} + +/** + * mgmt_be_send_notification() - Send notification to mgmtd + * + * This function is attached to the northbound notification hook. + */ +static int mgmt_be_send_notification(void *__client, const char *path, const struct lyd_node *tree) +{ + __send_notification(__client, path, tree, NOTIFY_OP_NOTIFICATION); + return 0; +} + static int mgmt_be_send_txn_reply(struct mgmt_be_client *client_ctx, uint64_t txn_id, bool create) { diff --git a/lib/mgmt_be_client.h b/lib/mgmt_be_client.h index 6ed8c2a39..a3e3896d5 100644 --- a/lib/mgmt_be_client.h +++ b/lib/mgmt_be_client.h @@ -112,6 +112,22 @@ extern struct mgmt_be_client * mgmt_be_client_create(const char *name, struct mgmt_be_client_cbs *cbs, uintptr_t user_data, struct event_loop *event_loop); + +/** + * mgmt_be_send_ds_delete_notification() - Send a datastore delete notification. + */ +extern int mgmt_be_send_ds_delete_notification(const char *path); + +/** + * mgmt_be_send_ds_patch_notification() - Send a datastore YANG patch notification. + */ +extern int mgmt_be_send_ds_patch_notification(const char *path, const struct lyd_node *tree); + +/** + * mgmt_be_send_ds_replace_notification() - Send a datastore replace notification. + */ +extern int mgmt_be_send_ds_replace_notification(const char *path, const struct lyd_node *tree); + /* * Initialize library vty (adds debug support). * diff --git a/lib/mgmt_msg_native.h b/lib/mgmt_msg_native.h index 587a00280..4076977a2 100644 --- a/lib/mgmt_msg_native.h +++ b/lib/mgmt_msg_native.h @@ -323,22 +323,29 @@ _Static_assert(sizeof(struct mgmt_msg_get_data) == offsetof(struct mgmt_msg_get_data, xpath), "Size mismatch"); + +#define NOTIFY_OP_NOTIFICATION 0 +#define NOTIFY_OP_DS_REPLACE 1 +#define NOTIFY_OP_DS_DELETE 2 +#define NOTIFY_OP_DS_PATCH 3 + /** * struct mgmt_msg_notify_data - Message carrying notification data. * * @result_type: ``LYD_FORMAT`` for format of the @result value. * @data: The xpath string of the notification followed by the tree data in * @result_type format. + * @op: notify operation type. */ struct mgmt_msg_notify_data { struct mgmt_msg_header; uint8_t result_type; - uint8_t resv2[7]; + uint8_t op; + uint8_t resv2[6]; alignas(8) char data[]; }; -_Static_assert(sizeof(struct mgmt_msg_notify_data) == - offsetof(struct mgmt_msg_notify_data, data), +_Static_assert(sizeof(struct mgmt_msg_notify_data) == offsetof(struct mgmt_msg_notify_data, data), "Size mismatch"); #define EDIT_FLAG_IMPLICIT_LOCK 0x01 |