summaryrefslogtreecommitdiff
path: root/mgmtd
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2024-01-29 22:50:26 +0200
committerIgor Ryzhov <iryzhov@nfware.com>2024-01-31 02:20:13 +0200
commit4317c8ffa6675c9f91b710c7c75739706e1edfef (patch)
treecac992fbf82d4f96cb323a2f4746c9c870dec17d /mgmtd
parente2caf64ef76ba2191d01962ef65a89990530992e (diff)
mgmtd: add support for with-defaults parameter to get-data
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Diffstat (limited to 'mgmtd')
-rw-r--r--mgmtd/mgmt_fe_adapter.c33
-rw-r--r--mgmtd/mgmt_fe_adapter.h12
-rw-r--r--mgmtd/mgmt_main.c13
-rw-r--r--mgmtd/mgmt_txn.c7
-rw-r--r--mgmtd/mgmt_txn.h5
-rw-r--r--mgmtd/mgmt_vty.c18
-rw-r--r--mgmtd/subdir.am3
7 files changed, 73 insertions, 18 deletions
diff --git a/mgmtd/mgmt_fe_adapter.c b/mgmtd/mgmt_fe_adapter.c
index 95f925d307..acf77f552b 100644
--- a/mgmtd/mgmt_fe_adapter.c
+++ b/mgmtd/mgmt_fe_adapter.c
@@ -1080,7 +1080,7 @@ mgmt_fe_adapter_handle_msg(struct mgmt_fe_client_adapter *adapter,
*/
static int fe_adapter_send_tree_data(struct mgmt_fe_session_ctx *session,
uint64_t req_id, bool short_circuit_ok,
- uint8_t result_type,
+ uint8_t result_type, uint32_t wd_options,
const struct lyd_node *tree,
int partial_error)
@@ -1105,8 +1105,7 @@ static int fe_adapter_send_tree_data(struct mgmt_fe_session_ctx *session,
darrp = mgmt_msg_native_get_darrp(msg);
ret = yang_print_tree_append(darrp, tree, result_type,
- (LYD_PRINT_WD_EXPLICIT |
- LYD_PRINT_WITHSIBLINGS));
+ (wd_options | LYD_PRINT_WITHSIBLINGS));
if (ret != LY_SUCCESS) {
MGMTD_FE_ADAPTER_ERR("Error building get-tree result for client %s session-id %" PRIu64
" req-id %" PRIu64
@@ -1147,6 +1146,7 @@ static void fe_adapter_handle_get_data(struct mgmt_fe_session_ctx *session,
char *xpath_resolved = NULL;
uint64_t req_id = msg->req_id;
uint64_t clients;
+ uint32_t wd_options;
bool simple_xpath;
LY_ERR err;
int ret;
@@ -1171,6 +1171,25 @@ static void fe_adapter_handle_get_data(struct mgmt_fe_session_ctx *session,
goto done;
}
+ switch (msg->defaults) {
+ case GET_DATA_DEFAULTS_EXPLICIT:
+ wd_options = LYD_PRINT_WD_EXPLICIT;
+ break;
+ case GET_DATA_DEFAULTS_TRIM:
+ wd_options = LYD_PRINT_WD_TRIM;
+ break;
+ case GET_DATA_DEFAULTS_ALL:
+ wd_options = LYD_PRINT_WD_ALL;
+ break;
+ case GET_DATA_DEFAULTS_ALL_ADD_TAG:
+ wd_options = LYD_PRINT_WD_IMPL_TAG;
+ break;
+ default:
+ fe_adapter_send_error(session, req_id, false, -EINVAL,
+ "Invalid defaults value %u for session-id: %" PRIu64,
+ msg->defaults, session->session_id);
+ goto done;
+ }
err = yang_resolve_snode_xpath(ly_native_ctx, msg->xpath, &snodes,
&simple_xpath);
@@ -1190,7 +1209,7 @@ static void fe_adapter_handle_get_data(struct mgmt_fe_session_ctx *session,
session->session_id);
fe_adapter_send_tree_data(session, req_id, false,
- msg->result_type, NULL, 0);
+ msg->result_type, wd_options, NULL, 0);
goto done;
}
@@ -1210,7 +1229,7 @@ static void fe_adapter_handle_get_data(struct mgmt_fe_session_ctx *session,
/* Create a GET-TREE request under the transaction */
ret = mgmt_txn_send_get_tree_oper(session->txn_id, req_id, clients,
msg->result_type, msg->flags,
- simple_xpath, msg->xpath);
+ wd_options, simple_xpath, msg->xpath);
if (ret) {
/* destroy the just created txn */
mgmt_destroy_txn(&session->txn_id);
@@ -1469,6 +1488,7 @@ int mgmt_fe_send_get_reply(uint64_t session_id, uint64_t txn_id,
int mgmt_fe_adapter_send_tree_data(uint64_t session_id, uint64_t txn_id,
uint64_t req_id, LYD_FORMAT result_type,
+ uint32_t wd_options,
const struct lyd_node *tree,
int partial_error, bool short_circuit_ok)
{
@@ -1480,7 +1500,8 @@ int mgmt_fe_adapter_send_tree_data(uint64_t session_id, uint64_t txn_id,
return -1;
ret = fe_adapter_send_tree_data(session, req_id, short_circuit_ok,
- result_type, tree, partial_error);
+ result_type, wd_options, tree,
+ partial_error);
mgmt_destroy_txn(&session->txn_id);
diff --git a/mgmtd/mgmt_fe_adapter.h b/mgmtd/mgmt_fe_adapter.h
index 09d64415bc..2150f864d9 100644
--- a/mgmtd/mgmt_fe_adapter.h
+++ b/mgmtd/mgmt_fe_adapter.h
@@ -148,6 +148,7 @@ extern int mgmt_fe_send_get_reply(uint64_t session_id, uint64_t txn_id,
* txn_id: the txn_id this data pertains to
* req_id: the req id for the get_tree message
* result_type: the format of the result data.
+ * wd_options: with-defaults options.
* tree: the results.
* partial_error: if there were errors while gather results.
* short_circuit_ok: True if OK to short-circuit the call.
@@ -156,12 +157,11 @@ extern int mgmt_fe_send_get_reply(uint64_t session_id, uint64_t txn_id,
* the return value from the underlying send function.
*
*/
-extern int mgmt_fe_adapter_send_tree_data(uint64_t session_id, uint64_t txn_id,
- uint64_t req_id,
- LYD_FORMAT result_type,
- const struct lyd_node *tree,
- int partial_error,
- bool short_circuit_ok);
+extern int
+mgmt_fe_adapter_send_tree_data(uint64_t session_id, uint64_t txn_id,
+ uint64_t req_id, LYD_FORMAT result_type,
+ uint32_t wd_options, const struct lyd_node *tree,
+ int partial_error, bool short_circuit_ok);
/**
* Send an error back to the FE client using native messaging.
diff --git a/mgmtd/mgmt_main.c b/mgmtd/mgmt_main.c
index 6dbd1f2e52..5be849b63c 100644
--- a/mgmtd/mgmt_main.c
+++ b/mgmtd/mgmt_main.c
@@ -145,6 +145,16 @@ extern const struct frr_yang_module_info frr_staticd_cli_info;
#endif
/*
+ * These are modules that are only needed by mgmtd and hence not included into
+ * the lib and backend daemons.
+ */
+const struct frr_yang_module_info ietf_netconf_with_defaults_info = {
+ .name = "ietf-netconf-with-defaults",
+ .ignore_cfg_cbs = true,
+ .nodes = { { .xpath = NULL } },
+};
+
+/*
* These are stub info structs that are used to load the modules used by backend
* clients into mgmtd. The modules are used by libyang in order to support
* parsing binary data returns from the backend.
@@ -167,6 +177,9 @@ static const struct frr_yang_module_info *const mgmt_yang_modules[] = {
&frr_vrf_info,
&frr_affinity_map_cli_info,
+ /* mgmtd-only modules */
+ &ietf_netconf_with_defaults_info,
+
/*
* YANG module info used by backend clients get added here.
*/
diff --git a/mgmtd/mgmt_txn.c b/mgmtd/mgmt_txn.c
index 7f88524e85..926b1574a1 100644
--- a/mgmtd/mgmt_txn.c
+++ b/mgmtd/mgmt_txn.c
@@ -175,6 +175,7 @@ struct txn_req_get_tree {
uint64_t recv_clients; /* Bitmask of clients recv reply from */
int32_t partial_error; /* an error while gather results */
uint8_t result_type; /* LYD_FORMAT for results */
+ uint8_t wd_options; /* LYD_PRINT_WD_* flags for results */
uint8_t exact; /* if exact node is requested */
uint8_t simple_xpath; /* if xpath is simple */
struct lyd_node *client_results; /* result tree from clients */
@@ -1282,6 +1283,7 @@ static int txn_get_tree_data_done(struct mgmt_txn_ctx *txn,
txn->txn_id,
txn_req->req_id,
get_tree->result_type,
+ get_tree->wd_options,
result,
get_tree->partial_error,
false);
@@ -2340,8 +2342,8 @@ int mgmt_txn_send_get_req(uint64_t txn_id, uint64_t req_id,
*/
int mgmt_txn_send_get_tree_oper(uint64_t txn_id, uint64_t req_id,
uint64_t clients, LYD_FORMAT result_type,
- uint8_t flags, bool simple_xpath,
- const char *xpath)
+ uint8_t flags, uint32_t wd_options,
+ bool simple_xpath, const char *xpath)
{
struct mgmt_msg_get_tree *msg;
struct mgmt_txn_ctx *txn;
@@ -2359,6 +2361,7 @@ int mgmt_txn_send_get_tree_oper(uint64_t txn_id, uint64_t req_id,
txn_req = mgmt_txn_req_alloc(txn, req_id, MGMTD_TXN_PROC_GETTREE);
get_tree = txn_req->req.get_tree;
get_tree->result_type = result_type;
+ get_tree->wd_options = wd_options;
get_tree->exact = CHECK_FLAG(flags, GET_DATA_FLAG_EXACT);
get_tree->simple_xpath = simple_xpath;
get_tree->xpath = XSTRDUP(MTYPE_MGMTD_XPATH, xpath);
diff --git a/mgmtd/mgmt_txn.h b/mgmtd/mgmt_txn.h
index 02b2baa95f..ad2e38fb0f 100644
--- a/mgmtd/mgmt_txn.h
+++ b/mgmtd/mgmt_txn.h
@@ -204,6 +204,7 @@ extern int mgmt_txn_send_get_req(uint64_t txn_id, uint64_t req_id,
* clients: Bitmask of clients to send get-tree to.
* result_type: LYD_FORMAT result format.
* flags: option flags for the request.
+ * wd_options: LYD_PRINT_WD_* flags for the result.
* simple_xpath: true if xpath is simple (only key predicates).
* xpath: The xpath to get the tree from.
*
@@ -212,8 +213,8 @@ extern int mgmt_txn_send_get_req(uint64_t txn_id, uint64_t req_id,
*/
extern int mgmt_txn_send_get_tree_oper(uint64_t txn_id, uint64_t req_id,
uint64_t clients, LYD_FORMAT result_type,
- uint8_t flags, bool simple_xpath,
- const char *xpath);
+ uint8_t flags, uint32_t wd_options,
+ bool simple_xpath, const char *xpath);
/*
* Notifiy backend adapter on connection.
diff --git a/mgmtd/mgmt_vty.c b/mgmtd/mgmt_vty.c
index 7135bc5547..7c9c3c6fe0 100644
--- a/mgmtd/mgmt_vty.c
+++ b/mgmtd/mgmt_vty.c
@@ -258,7 +258,7 @@ DEFPY(show_mgmt_get_config, show_mgmt_get_config_cmd,
}
DEFPY(show_mgmt_get_data, show_mgmt_get_data_cmd,
- "show mgmt get-data WORD$path [with-config|only-config]$content [exact]$exact [json|xml]$fmt",
+ "show mgmt get-data WORD$path [with-config|only-config]$content [exact]$exact [with-defaults <trim|all-tag|all>$wd] [json|xml]$fmt",
SHOW_STR
MGMTD_STR
"Get a data from the operational datastore\n"
@@ -266,6 +266,10 @@ DEFPY(show_mgmt_get_data, show_mgmt_get_data_cmd,
"Include \"config true\" data\n"
"Get only \"config true\" data\n"
"Get exact node instead of the whole data tree\n"
+ "Configure 'with-defaults' mode per RFC 6243 (\"explicit\" mode by default)\n"
+ "Use \"trim\" mode\n"
+ "Use \"report-all-tagged\" mode\n"
+ "Use \"report-all\" mode\n"
"JSON output format\n"
"XML output format\n")
{
@@ -273,6 +277,7 @@ DEFPY(show_mgmt_get_data, show_mgmt_get_data_cmd,
int plen = strlen(path);
char *xpath = NULL;
uint8_t flags = content ? GET_DATA_FLAG_CONFIG : GET_DATA_FLAG_STATE;
+ uint8_t defaults = GET_DATA_DEFAULTS_EXPLICIT;
if (content && content[0] == 'w')
flags |= GET_DATA_FLAG_STATE;
@@ -280,6 +285,15 @@ DEFPY(show_mgmt_get_data, show_mgmt_get_data_cmd,
if (exact)
flags |= GET_DATA_FLAG_EXACT;
+ if (wd) {
+ if (wd[0] == 't')
+ defaults = GET_DATA_DEFAULTS_TRIM;
+ else if (wd[3] == '-')
+ defaults = GET_DATA_DEFAULTS_ALL_ADD_TAG;
+ else
+ defaults = GET_DATA_DEFAULTS_ALL;
+ }
+
/* get rid of extraneous trailing slash-* or single '/' unless root */
if (plen > 2 && ((path[plen - 2] == '/' && path[plen - 1] == '*') ||
(path[plen - 2] != '/' && path[plen - 1] == '/'))) {
@@ -289,7 +303,7 @@ DEFPY(show_mgmt_get_data, show_mgmt_get_data_cmd,
path = xpath;
}
- vty_mgmt_send_get_data_req(vty, format, flags, path);
+ vty_mgmt_send_get_data_req(vty, format, flags, defaults, path);
if (xpath)
XFREE(MTYPE_TMP, xpath);
diff --git a/mgmtd/subdir.am b/mgmtd/subdir.am
index fa8025c0e2..0af64dc0be 100644
--- a/mgmtd/subdir.am
+++ b/mgmtd/subdir.am
@@ -61,6 +61,9 @@ mgmtd_mgmtd_SOURCES = \
# end
nodist_mgmtd_mgmtd_SOURCES = \
yang/frr-zebra.yang.c \
+ yang/ietf/ietf-netconf-acm.yang.c \
+ yang/ietf/ietf-netconf.yang.c \
+ yang/ietf/ietf-netconf-with-defaults.yang.c \
# nothing
mgmtd_mgmtd_CFLAGS = $(AM_CFLAGS) -I ./
mgmtd_mgmtd_LDADD = mgmtd/libmgmtd.a lib/libfrr.la $(LIBCAP) $(LIBM) $(LIBYANG_LIBS) $(UST_LIBS)