]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib, mgmtd: add separate get-data request for the frontend
authorIgor Ryzhov <iryzhov@nfware.com>
Sat, 13 Jan 2024 20:34:17 +0000 (22:34 +0200)
committerIgor Ryzhov <iryzhov@nfware.com>
Sun, 14 Jan 2024 18:00:22 +0000 (20:00 +0200)
Currently it's the same as get-tree request for the backend, but it is
going to be expanded in the following commits.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
lib/mgmt_fe_client.c
lib/mgmt_fe_client.h
lib/mgmt_msg_native.c
lib/mgmt_msg_native.h
lib/vty.c
lib/vty.h
mgmtd/mgmt_fe_adapter.c
mgmtd/mgmt_vty.c

index 0bea66300449e43fa2ebf2da635f35b0fdf1b4d4..16559c61031affa091014f979b41f990dc42d6a0 100644 (file)
@@ -306,25 +306,25 @@ int mgmt_fe_send_regnotify_req(struct mgmt_fe_client *client,
 }
 
 /*
- * Send get-tree request.
+ * Send get-data request.
  */
-int mgmt_fe_send_get_tree_req(struct mgmt_fe_client *client,
+int mgmt_fe_send_get_data_req(struct mgmt_fe_client *client,
                              uint64_t session_id, uint64_t req_id,
                              LYD_FORMAT result_type, const char *xpath)
 {
-       struct mgmt_msg_get_tree *msg;
+       struct mgmt_msg_get_data *msg;
        size_t xplen = strlen(xpath);
        int ret;
 
-       msg = mgmt_msg_native_alloc_msg(struct mgmt_msg_get_tree, xplen + 1,
-                                       MTYPE_MSG_NATIVE_GET_TREE);
+       msg = mgmt_msg_native_alloc_msg(struct mgmt_msg_get_data, xplen + 1,
+                                       MTYPE_MSG_NATIVE_GET_DATA);
        msg->refer_id = session_id;
        msg->req_id = req_id;
-       msg->code = MGMT_MSG_CODE_GET_TREE;
+       msg->code = MGMT_MSG_CODE_GET_DATA;
        msg->result_type = result_type;
        strlcpy(msg->xpath, xpath, xplen + 1);
 
-       MGMTD_FE_CLIENT_DBG("Sending GET_TREE_REQ session-id %" PRIu64
+       MGMTD_FE_CLIENT_DBG("Sending GET_DATA_REQ session-id %" PRIu64
                            " req-id %" PRIu64 " xpath: %s",
                            session_id, req_id, xpath);
 
index f3292d18fda147f1d2950d40357dfcccf96133a4..95e73ca5947880271ca70ee9b6d08c38861c89ec 100644 (file)
@@ -367,7 +367,7 @@ extern int mgmt_fe_send_regnotify_req(struct mgmt_fe_client *client,
                                      int num_reqs);
 
 /*
- * Send GET-TREE to MGMTD daemon.
+ * Send GET-DATA to MGMTD daemon.
  *
  * client
  *    Client object.
@@ -387,7 +387,7 @@ extern int mgmt_fe_send_regnotify_req(struct mgmt_fe_client *client,
  * Returns:
  *    0 on success, otherwise msg_conn_send_msg() return values.
  */
-extern int mgmt_fe_send_get_tree_req(struct mgmt_fe_client *client,
+extern int mgmt_fe_send_get_data_req(struct mgmt_fe_client *client,
                                     uint64_t session_id, uint64_t req_id,
                                     LYD_FORMAT result_type, const char *xpath);
 
index b6dc126d49c83329a4152f697867612fdafec58d..a9b26718dbfe998ec3228099e1a0f0f0404781ce 100644 (file)
@@ -13,6 +13,7 @@ DEFINE_MTYPE(MSG_NATIVE, MSG_NATIVE_MSG, "native mgmt msg");
 DEFINE_MTYPE(MSG_NATIVE, MSG_NATIVE_ERROR, "native error msg");
 DEFINE_MTYPE(MSG_NATIVE, MSG_NATIVE_GET_TREE, "native get tree msg");
 DEFINE_MTYPE(MSG_NATIVE, MSG_NATIVE_TREE_DATA, "native tree data msg");
+DEFINE_MTYPE(MSG_NATIVE, MSG_NATIVE_GET_DATA, "native get data msg");
 
 int vmgmt_msg_native_send_error(struct msg_conn *conn, uint64_t sess_or_txn_id,
                                uint64_t req_id, bool short_circuit_ok,
index 3f6283025c3e29c46745fff37f2c3df35675d037..93ff6f012c92ba6e309d218edc05d60ad28efc56 100644 (file)
@@ -142,6 +142,7 @@ DECLARE_MTYPE(MSG_NATIVE_MSG);
 DECLARE_MTYPE(MSG_NATIVE_ERROR);
 DECLARE_MTYPE(MSG_NATIVE_GET_TREE);
 DECLARE_MTYPE(MSG_NATIVE_TREE_DATA);
+DECLARE_MTYPE(MSG_NATIVE_GET_DATA);
 
 /*
  * Native message codes
@@ -149,6 +150,7 @@ DECLARE_MTYPE(MSG_NATIVE_TREE_DATA);
 #define MGMT_MSG_CODE_ERROR    0
 #define MGMT_MSG_CODE_GET_TREE 1
 #define MGMT_MSG_CODE_TREE_DATA 2
+#define MGMT_MSG_CODE_GET_DATA 3
 
 /**
  * struct mgmt_msg_header - Header common to all native messages.
@@ -193,7 +195,7 @@ _Static_assert(sizeof(struct mgmt_msg_error) ==
               "Size mismatch");
 
 /**
- * struct mgmt_msg_get_tree - Message carrying xpath query request.
+ * struct mgmt_msg_get_tree - backend oper data request.
  *
  * @result_type: ``LYD_FORMAT`` for the returned result.
  * @xpath: the query for the data to return.
@@ -231,6 +233,23 @@ _Static_assert(sizeof(struct mgmt_msg_tree_data) ==
                       offsetof(struct mgmt_msg_tree_data, result),
               "Size mismatch");
 
+/**
+ * struct mgmt_msg_get_data - frontend get-data request.
+ *
+ * @result_type: ``LYD_FORMAT`` for the returned result.
+ * @xpath: the query for the data to return.
+ */
+struct mgmt_msg_get_data {
+       struct mgmt_msg_header;
+       uint8_t result_type;
+       uint8_t resv2[7];
+
+       alignas(8) char xpath[];
+};
+_Static_assert(sizeof(struct mgmt_msg_get_data) ==
+                      offsetof(struct mgmt_msg_get_data, xpath),
+              "Size mismatch");
+
 #define MGMT_MSG_VALIDATE_NUL_TERM(msgp, len)                                  \
        ((len) >= sizeof(*msg) + 1 && ((char *)msgp)[(len)-1] == 0)
 
index 5f9f0dc2435b52a85e8ea6b7678ebb0597a4e3f2..f1b7d621b7203c3032218ea6f96adce21a809603 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -4105,23 +4105,23 @@ int vty_mgmt_send_get_req(struct vty *vty, bool is_config,
        return 0;
 }
 
-int vty_mgmt_send_get_tree_req(struct vty *vty, LYD_FORMAT result_type,
+int vty_mgmt_send_get_data_req(struct vty *vty, LYD_FORMAT result_type,
                               const char *xpath)
 {
        LYD_FORMAT intern_format = result_type;
 
        vty->mgmt_req_id++;
 
-       if (mgmt_fe_send_get_tree_req(mgmt_fe_client, vty->mgmt_session_id,
+       if (mgmt_fe_send_get_data_req(mgmt_fe_client, vty->mgmt_session_id,
                                      vty->mgmt_req_id, intern_format, xpath)) {
-               zlog_err("Failed to send GET-TREE to MGMTD session-id: %" PRIu64
+               zlog_err("Failed to send GET-DATA to MGMTD session-id: %" PRIu64
                         " req-id %" PRIu64 ".",
                         vty->mgmt_session_id, vty->mgmt_req_id);
-               vty_out(vty, "Failed to send GET-TREE to MGMTD!\n");
+               vty_out(vty, "Failed to send GET-DATA to MGMTD!\n");
                return -1;
        }
 
-       vty->mgmt_req_pending_cmd = "MESSAGE_GET_TREE_REQ";
+       vty->mgmt_req_pending_cmd = "MESSAGE_GET_DATA_REQ";
        vty->mgmt_req_pending_data = result_type;
 
        return 0;
index 5866eccde04ca59fe77dc1b93ed25ed18f65ab62..044e6433d17707dbc4e6700326e7ab43a9be90bc 100644 (file)
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -420,7 +420,7 @@ extern int vty_mgmt_send_commit_config(struct vty *vty, bool validate_only,
 extern int vty_mgmt_send_get_req(struct vty *vty, bool is_config,
                                 Mgmtd__DatastoreId datastore,
                                 const char **xpath_list, int num_req);
-extern int vty_mgmt_send_get_tree_req(struct vty *vty, LYD_FORMAT result_type,
+extern int vty_mgmt_send_get_data_req(struct vty *vty, LYD_FORMAT result_type,
                                      const char *xpath);
 extern int vty_mgmt_send_lockds_req(struct vty *vty, Mgmtd__DatastoreId ds_id,
                                    bool lock, bool scok);
index a69d27fc5c58b3a1b738b2366b81f8d673645201..6527677d3185485b011bed93dc1cd03a73dfcf8b 100644 (file)
@@ -1132,15 +1132,15 @@ done:
 }
 
 /**
- * fe_adapter_handle_get_tree() - Handle a get-tree message from a FE client.
+ * fe_adapter_handle_get_data() - Handle a get-tree message from a FE client.
  * @session: the client session.
  * @msg_raw: the message data.
  * @msg_len: the length of the message data.
  */
-static void fe_adapter_handle_get_tree(struct mgmt_fe_session_ctx *session,
+static void fe_adapter_handle_get_data(struct mgmt_fe_session_ctx *session,
                                       void *__msg, size_t msg_len)
 {
-       struct mgmt_msg_get_tree *msg = __msg;
+       struct mgmt_msg_get_data *msg = __msg;
        struct lysc_node **snodes = NULL;
        char *xpath_resolved = NULL;
        uint64_t req_id = msg->req_id;
@@ -1149,7 +1149,7 @@ static void fe_adapter_handle_get_tree(struct mgmt_fe_session_ctx *session,
        LY_ERR err;
        int ret;
 
-       MGMTD_FE_ADAPTER_DBG("Received get-tree request from client %s for session-id %" PRIu64
+       MGMTD_FE_ADAPTER_DBG("Received get-data request from client %s for session-id %" PRIu64
                             " req-id %" PRIu64,
                             session->adapter->name, session->session_id,
                             msg->req_id);
@@ -1238,8 +1238,8 @@ static void fe_adapter_handle_native_msg(struct mgmt_fe_client_adapter *adapter,
        assert(session->adapter == adapter);
 
        switch (msg->code) {
-       case MGMT_MSG_CODE_GET_TREE:
-               fe_adapter_handle_get_tree(session, msg, msg_len);
+       case MGMT_MSG_CODE_GET_DATA:
+               fe_adapter_handle_get_data(session, msg, msg_len);
                break;
        default:
                MGMTD_FE_ADAPTER_ERR("unknown native message session-id %" PRIu64
index 2591930e4a8981000131724f56eb634f0576ebe0..98e55788b4358795af52515cd3f9d5ebe05df7d9 100644 (file)
@@ -272,7 +272,7 @@ DEFPY(show_mgmt_get_data, show_mgmt_get_data_cmd,
                path = xpath;
        }
 
-       vty_mgmt_send_get_tree_req(vty, format, path);
+       vty_mgmt_send_get_data_req(vty, format, path);
 
        if (xpath)
                XFREE(MTYPE_TMP, xpath);