Skip to content

Commit c02b1bc

Browse files
committed
1. Print candidate-config and running-config in mgmt_txn_prepare_config
2. Print dnode xpath around dnode_create 3. Add mutex lock in lyd_new_path 4. Find dnode for xpath having RM_SET_SRC with value 10.1.0.32 and cache it, then check the same dnode in mgmt_txn_prepare_config
1 parent 3fbd709 commit c02b1bc

File tree

5 files changed

+178
-1
lines changed

5 files changed

+178
-1
lines changed

lib/northbound.c

+25
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* Renato Westphal
55
*/
66

7+
#include <stdlib.h>
8+
#include <unistd.h>
9+
#include <sys/mman.h>
710
#include <zebra.h>
811

912
#include "darr.h"
@@ -683,6 +686,10 @@ void nb_config_diff(const struct nb_config *config1,
683686
lyd_free_all(diff);
684687
}
685688

689+
#define __dbg(fmt, ...) \
690+
zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__)
691+
692+
struct lyd_node *rm_set_src_node;
686693
static int dnode_create(struct nb_config *candidate, const char *xpath,
687694
const char *value, uint32_t options,
688695
struct lyd_node **new_dnode)
@@ -692,6 +699,17 @@ static int dnode_create(struct nb_config *candidate, const char *xpath,
692699

693700
err = lyd_new_path(candidate->dnode, ly_native_ctx, xpath, value,
694701
options, &dnode);
702+
if (dnode) {
703+
__dbg("frr_debug_sonic_create: dnode %p, xpath %s, value %s", dnode, xpath, value);
704+
char *xpath = lyd_path(dnode, LYD_PATH_STD, NULL, 0);
705+
if (xpath &&
706+
!strcmp("/frr-route-map:lib/route-map[name='RM_SET_SRC']/entry[sequence='10']/set-action[action='frr-zebra-route-map:src-address']/rmap-set-action/frr-zebra-route-map:ipv4-src-address", xpath)) {
707+
mprotect(dnode->schema, sizeof(dnode->schema), PROT_READ);
708+
rm_set_src_node = dnode;
709+
free(xpath);
710+
}
711+
}
712+
695713
if (err) {
696714
flog_warn(EC_LIB_LIBYANG, "%s: lyd_new_path(%s) failed: %d",
697715
__func__, xpath, err);
@@ -858,6 +876,7 @@ void nb_candidate_edit_config_changes(struct nb_config *candidate_config,
858876
if (xpath_base == NULL)
859877
xpath_base = "";
860878

879+
__dbg("frr_debug_sonic: num_cfg_changes: '%u'", num_cfg_changes);
861880
/* Edit candidate configuration. */
862881
for (size_t i = 0; i < num_cfg_changes; i++) {
863882
struct nb_cfg_change *change = &cfg_changes[i];
@@ -875,6 +894,7 @@ void nb_candidate_edit_config_changes(struct nb_config *candidate_config,
875894
change_xpath++; /* skip '.' */
876895
}
877896
strlcat(xpath, change_xpath, sizeof(xpath));
897+
__dbg("frr_debug_sonic: XPath: '%s'", xpath);
878898

879899
/* Find the northbound node associated to the data path. */
880900
nb_node = nb_node_find(xpath);
@@ -890,13 +910,15 @@ void nb_candidate_edit_config_changes(struct nb_config *candidate_config,
890910
if (error)
891911
*error = true;
892912
}
913+
__dbg("frr_debug_sonic: XPath: '%s', nb_node NULL", xpath);
893914
continue;
894915
}
895916
/* Find if the node to be edited is not a key node */
896917
if (!nb_is_operation_allowed(nb_node, change->operation)) {
897918
zlog_err(" Xpath %s points to key node", xpath);
898919
if (error)
899920
*error = true;
921+
__dbg("frr_debug_sonic: XPath: '%s', nb_is_operation_allowed NULL", xpath);
900922
break;
901923
}
902924

@@ -910,6 +932,8 @@ void nb_candidate_edit_config_changes(struct nb_config *candidate_config,
910932
* Ignore "not found" errors when editing the candidate
911933
* configuration.
912934
*/
935+
__dbg("frr_debug_sonic: XPath: '%s', value '%s', operation %u", xpath,
936+
value, change->operation);
913937
ret = nb_candidate_edit(candidate_config, nb_node,
914938
change->operation, xpath, NULL, data);
915939
yang_data_free(data);
@@ -921,6 +945,7 @@ void nb_candidate_edit_config_changes(struct nb_config *candidate_config,
921945
xpath);
922946
if (error)
923947
*error = true;
948+
__dbg("frr_debug_sonic: XPath: '%s', nb_candidate_edit NULL", xpath);
924949
continue;
925950
}
926951
}

lib/vty.c

+2
Original file line numberDiff line numberDiff line change
@@ -2845,6 +2845,8 @@ bool vty_read_config(struct nb_config *config, const char *config_file,
28452845
{
28462846
FILE *confp;
28472847

2848+
zlog_err("vty_read_config: frr_debug_sonic: config file: %s, config_default_dir %s ",
2849+
config_file, config_default_dir);
28482850
confp = vty_open_config(config_file, config_default_dir);
28492851
if (!confp)
28502852
return false;

lib/yang.c

+22
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "northbound.h"
1515

1616
#include "lib/config_paths.h"
17+
#include "zlog.h"
1718

1819
DEFINE_MTYPE_STATIC(LIB, YANG_MODULE, "YANG module");
1920
DEFINE_MTYPE_STATIC(LIB, YANG_DATA, "YANG data structure");
@@ -1343,3 +1344,24 @@ const char *yang_ly_strvecode(LY_VECODE vecode)
13431344
}
13441345
#endif
13451346
}
1347+
1348+
void debug_lyd_free_tree(struct lyd_node *dnode)
1349+
{
1350+
1351+
zlog_err("%s: ERROR: frr_debug_sonic_free: dnode %p", __func__, dnode);
1352+
#undef lyd_free_tree
1353+
lyd_free_tree(dnode);
1354+
}
1355+
1356+
static pthread_mutex_t candidate_edit_lock = PTHREAD_MUTEX_INITIALIZER;
1357+
LY_ERR debug_lyd_new_path(struct lyd_node *parent, const struct ly_ctx
1358+
*ctx, const char *path, const char *value,
1359+
uint32_t options, struct lyd_node **node)
1360+
{
1361+
LY_ERR err;
1362+
pthread_mutex_lock(&candidate_edit_lock);
1363+
#undef lyd_new_path
1364+
err = lyd_new_path(parent, ctx, path, value, options, node);
1365+
pthread_mutex_unlock(&candidate_edit_lock);
1366+
return err;
1367+
}

lib/yang.h

+10
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,16 @@ extern LY_ERR yang_lyd_new_list(struct lyd_node_inner *parent,
801801
struct lyd_node **nodes);
802802
extern LY_ERR yang_lyd_trim_xpath(struct lyd_node **rootp, const char *xpath);
803803

804+
#define lyd_free_tree debug_lyd_free_tree
805+
806+
extern void debug_lyd_free_tree(struct lyd_node *dnode);
807+
808+
#define lyd_new_path debug_lyd_new_path
809+
810+
extern LY_ERR debug_lyd_new_path(struct lyd_node *parent, const struct ly_ctx
811+
*ctx, const char *path, const char *value,
812+
uint32_t options, struct lyd_node **node);
813+
804814
#ifdef __cplusplus
805815
}
806816
#endif

mgmtd/mgmt_txn.c

+119-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "mgmtd/mgmt.h"
1717
#include "mgmtd/mgmt_memory.h"
1818
#include "mgmtd/mgmt_txn.h"
19+
#include "libyang/libyang.h"
1920

2021
#define __dbg(fmt, ...) \
2122
DEBUGD(&mgmt_debug_txn, "TXN: %s: " fmt, __func__, ##__VA_ARGS__)
@@ -945,10 +946,112 @@ static int mgmt_txn_create_config_batches(struct mgmt_txn_req *txn_req,
945946
return 0;
946947
}
947948

949+
950+
static void mgmt_print_nb_config_cbs(const char *prefix, struct nb_config_cbs *cfg_chgs)
951+
{
952+
struct nb_config_cb *cb, *nxt;
953+
struct nb_config_change *chg;
954+
char *xpath;
955+
956+
if (!cfg_chgs) {
957+
__dbg("%s: nb_config_cbs is NULL", prefix);
958+
return;
959+
}
960+
961+
__dbg("%s: nb_config_cbs structure: %p", prefix, cfg_chgs);
962+
963+
if (RB_EMPTY(nb_config_cbs, cfg_chgs)) {
964+
__dbg("%s: nb_config_cbs is empty", prefix);
965+
return;
966+
}
967+
968+
RB_FOREACH_SAFE (cb, nb_config_cbs, cfg_chgs, nxt) {
969+
chg = (struct nb_config_change *)cb;
970+
971+
__dbg("%s: Change operation: %d", prefix, chg->cb.operation);
972+
__dbg("%s: Change nb_node: %p", prefix, chg->cb.nb_node);
973+
if (chg->cb.nb_node) {
974+
__dbg("%s: Change nb_node schema: %s", prefix, chg->cb.nb_node->snode->name);
975+
__dbg("%s: Change nb_node module: %s", prefix, chg->cb.nb_node->snode->module->name);
976+
}
977+
978+
__dbg("%s: Change dnode: %p", prefix, chg->cb.dnode);
979+
if (chg->cb.dnode) {
980+
__dbg("%s: Change dnode schema: %s", prefix, chg->cb.dnode->schema->name);
981+
__dbg("%s: Change dnode module: %s", prefix, chg->cb.dnode->schema->module->name);
982+
__dbg("%s: Change dnode type: %d", prefix, chg->cb.dnode->schema->nodetype);
983+
984+
xpath = lyd_path(chg->cb.dnode, LYD_PATH_STD, NULL, 0);
985+
if (xpath) {
986+
__dbg("%s: Change dnode xpath: %s", prefix, xpath);
987+
if (chg->cb.dnode->schema->nodetype & LYD_NODE_TERM) {
988+
const char *value = lyd_get_value(chg->cb.dnode);
989+
__dbg("%s: Change dnode value: %s", prefix, value ? value : "NULL");
990+
}
991+
free(xpath);
992+
}
993+
}
994+
}
995+
}
996+
997+
static void mgmt_print_nb_config(const char *prefix, struct nb_config *nb_config)
998+
{
999+
struct lyd_node *dnode;
1000+
struct lyd_node *root, *child;
1001+
const char *value;
1002+
char *xpath;
1003+
1004+
if (!nb_config) {
1005+
__dbg("%s: nb_config is NULL", prefix);
1006+
return;
1007+
}
1008+
1009+
__dbg("%s: nb_config structure: %p", prefix, nb_config);
1010+
__dbg("%s: nb_config dnode: %p", prefix, nb_config->dnode);
1011+
1012+
if (!nb_config->dnode) {
1013+
__dbg("%s: nb_config dnode is NULL", prefix);
1014+
return;
1015+
}
1016+
1017+
__dbg("%s: nb_config dnode schema: %s", prefix, nb_config->dnode->schema->name);
1018+
__dbg("%s: nb_config dnode module: %s", prefix, nb_config->dnode->schema->module->name);
1019+
__dbg("%s: nb_config dnode type: %d", prefix, nb_config->dnode->schema->nodetype);
1020+
1021+
/* Print the root node */
1022+
xpath = lyd_path(nb_config->dnode, LYD_PATH_STD, NULL, 0);
1023+
if (xpath) {
1024+
__dbg("%s: Root node xpath: %s", prefix, xpath);
1025+
free(xpath);
1026+
}
1027+
1028+
/* Print all child nodes */
1029+
LY_LIST_FOR (nb_config->dnode, root) {
1030+
LYD_TREE_DFS_BEGIN (root, child) {
1031+
xpath = lyd_path(child, LYD_PATH_STD, NULL, 0);
1032+
if (xpath) {
1033+
__dbg("%s: Child node %p xpath: %s", prefix, child, xpath);
1034+
//__dbg("%s: Child node schema: %s", prefix, child->schema->name);
1035+
//__dbg("%s: Child node module: %s", prefix, child->schema->module->name);
1036+
//__dbg("%s: Child node type: %d", prefix, child->schema->nodetype);
1037+
1038+
if (child->schema->nodetype & LYD_NODE_TERM) {
1039+
value = lyd_get_value(child);
1040+
__dbg("%s: Child node value: %s", prefix, value ? value : "NULL");
1041+
}
1042+
1043+
free(xpath);
1044+
}
1045+
LYD_TREE_DFS_END(root, child);
1046+
}
1047+
}
1048+
}
1049+
1050+
extern struct lyd_node *rm_set_src_node;
9481051
static int mgmt_txn_prepare_config(struct mgmt_txn_ctx *txn)
9491052
{
9501053
struct nb_context nb_ctx;
951-
struct nb_config *nb_config;
1054+
struct nb_config *nb_config, *dst_nb_config;
9521055
struct nb_config_cbs changes;
9531056
struct nb_config_cbs *cfg_chgs = NULL;
9541057
int ret;
@@ -1013,6 +1116,17 @@ static int mgmt_txn_prepare_config(struct mgmt_txn_ctx *txn)
10131116
goto mgmt_txn_prepare_config_done;
10141117
}
10151118

1119+
if (rm_set_src_node) {
1120+
char *xpath = lyd_path(rm_set_src_node, LYD_PATH_STD, NULL, 0);
1121+
__dbg("frr_debug_sonic: dnode %p, xpath %s", rm_set_src_node, xpath);
1122+
__dbg("frr_debug_sonic: node schema: %s", rm_set_src_node->schema->name);
1123+
__dbg("frr_debug_sonic: node module: %s", rm_set_src_node->schema->module->name);
1124+
free(xpath);
1125+
}
1126+
else {
1127+
__dbg("frr_debug_sonic: rm_set_src_node is NULL");
1128+
}
1129+
mgmt_print_nb_config("frr_debug_sonic: SET_CFG src", nb_config);
10161130
/*
10171131
* Validate YANG contents of the source DS and get the diff
10181132
* between source and destination DS contents.
@@ -1029,13 +1143,17 @@ static int mgmt_txn_prepare_config(struct mgmt_txn_ctx *txn)
10291143
ret = -1;
10301144
goto mgmt_txn_prepare_config_done;
10311145
}
1146+
dst_nb_config = mgmt_ds_get_nb_config(
1147+
txn->commit_cfg_req->req.commit_cfg.dst_ds_ctx);
1148+
mgmt_print_nb_config("frr_debug_sonic: SET_CFG dst", dst_nb_config);
10321149

10331150
nb_config_diff(mgmt_ds_get_nb_config(txn->commit_cfg_req->req.commit_cfg
10341151
.dst_ds_ctx),
10351152
nb_config, &changes);
10361153
cfg_chgs = &changes;
10371154
del_cfg_chgs = true;
10381155

1156+
mgmt_print_nb_config_cbs("frr_debug_sonic: CONFIG_CHANGES", cfg_chgs);
10391157
if (RB_EMPTY(nb_config_cbs, cfg_chgs)) {
10401158
/*
10411159
* This means there's no changes to commit whatsoever

0 commit comments

Comments
 (0)