Skip to content

Commit

Permalink
Make 'no ip route x.x.x.x/y ...' commands work with CMGD infra.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pushpasis Sarkar committed Aug 17, 2021
1 parent e0f0c84 commit 54e39de
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 29 deletions.
6 changes: 6 additions & 0 deletions cmgd/cmgd_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ int cmgd_db_init(struct cmgd_master *cm)
candidate.config_db = true;
candidate.db_id = CMGD_DB_CANDIDATE;

/*
* Redirect lib/vty candidate-config database to the global candidate
* config Db on the CMGD process.
*/
vty_cmgd_candidate_config = candidate.root.cfg_root;

oper.root.dnode_root = yang_dnode_new(ly_native_ctx, true);
oper.config_db = false;
oper.db_id = CMGD_DB_OPERATIONAL;
Expand Down
10 changes: 9 additions & 1 deletion lib/vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ enum event {
#endif /* VTYSH */
};

struct nb_config *vty_cmgd_candidate_config = NULL;

static cmgd_lib_hndl_t cmgd_lib_hndl = 0;
static bool cmgd_frntnd_connected = false;

Expand Down Expand Up @@ -2640,7 +2642,13 @@ int vty_config_enter(struct vty *vty, bool private_config, bool exclusive)
vty_out(vty,
"Warning: uncommitted changes will be discarded on exit.\n\n");
} else {
vty->candidate_config = vty_shared_candidate_config;
/*
* NOTE: On the CMGD daemon we point the VTY candidate DB to
* the global CMGD candidate DB. Else we point to the VTY
* Shared Candidate Config.
*/
vty->candidate_config = vty_cmgd_candidate_config ?
vty_cmgd_candidate_config : vty_shared_candidate_config;
if (frr_get_cli_mode() == FRR_CLI_TRANSACTIONAL)
vty->candidate_config_base =
nb_config_dup(running_config);
Expand Down
2 changes: 2 additions & 0 deletions lib/vty.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ struct vty_arg {
#define IS_DIRECTORY_SEP(c) ((c) == DIRECTORY_SEP)
#endif

extern struct nb_config *vty_cmgd_candidate_config;

/* Prototypes. */
extern void vty_init(struct thread_master *, bool do_command_logging);
extern void vty_init_vtysh(void);
Expand Down
64 changes: 36 additions & 28 deletions staticd/static_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,23 +310,42 @@ static int static_route_leak(struct vty *vty, const char *svrf,
}
ret = NB_APPLY_CLI_COMMANDS(vty, xpath_prefix);
} else {
#ifndef INCLUDE_CMGD_CMDDEFS_ONLY
if (src_str)
snprintf(ab_xpath, sizeof(ab_xpath),
FRR_DEL_S_ROUTE_SRC_NH_KEY_NO_DISTANCE_XPATH,
"frr-staticd:staticd", "staticd", svrf,
buf_prefix,
yang_afi_safi_value2identity(afi, safi),
buf_src_prefix, table_id, buf_nh_type, nh_svrf,
buf_gate_str, ifname);
else
snprintf(ab_xpath, sizeof(ab_xpath),
FRR_DEL_S_ROUTE_NH_KEY_NO_DISTANCE_XPATH,
"frr-staticd:staticd", "staticd", svrf,
buf_prefix,
yang_afi_safi_value2identity(afi, safi),
table_id, buf_nh_type, nh_svrf, buf_gate_str,
ifname);
if (src_str) {
if (distance_str)
snprintf(ab_xpath, sizeof(ab_xpath),
FRR_DEL_S_ROUTE_SRC_NH_KEY_XPATH,
"frr-staticd:staticd", "staticd", svrf,
buf_prefix,
yang_afi_safi_value2identity(afi, safi),
buf_src_prefix, table_id, distance,
buf_nh_type, nh_svrf, buf_gate_str,
ifname);
else
snprintf(ab_xpath, sizeof(ab_xpath),
FRR_DEL_S_ROUTE_SRC_NH_KEY_NO_DISTANCE_XPATH,
"frr-staticd:staticd", "staticd", svrf,
buf_prefix,
yang_afi_safi_value2identity(afi, safi),
buf_src_prefix, table_id, buf_nh_type, nh_svrf,
buf_gate_str, ifname);
} else {
if (distance_str)
snprintf(ab_xpath, sizeof(ab_xpath),
FRR_DEL_S_ROUTE_NH_KEY_XPATH,
"frr-staticd:staticd", "staticd", svrf,
buf_prefix,
yang_afi_safi_value2identity(afi, safi),
table_id, distance, buf_nh_type, nh_svrf,
buf_gate_str, ifname);
else
snprintf(ab_xpath, sizeof(ab_xpath),
FRR_DEL_S_ROUTE_NH_KEY_NO_DISTANCE_XPATH,
"frr-staticd:staticd", "staticd", svrf,
buf_prefix,
yang_afi_safi_value2identity(afi, safi),
table_id, buf_nh_type, nh_svrf, buf_gate_str,
ifname);
}

dnode = yang_dnode_get(vty->candidate_config->dnode, ab_xpath);
if (!dnode) {
Expand All @@ -337,17 +356,6 @@ static int static_route_leak(struct vty *vty, const char *svrf,
dnode = yang_get_subtree_with_no_sibling(dnode);
assert(dnode);
yang_dnode_get_path(dnode, ab_xpath, XPATH_MAXLEN);
#else /* ifndef INCLUDE_CMGD_CMDDEFS_ONLY */
/*
* TODO: Right now deletes the entire route. Need to handle
* delete of specific route attributes.
*/
snprintf(ab_xpath, sizeof(ab_xpath),
FRR_STATIC_ROUTE_INFO_XPATH,
"frr-staticd:staticd", "staticd", svrf,
buf_prefix,
yang_afi_safi_value2identity(afi, safi));
#endif /* ifndef INCLUDE_CMGD_CMDDEFS_ONLY */

NB_ENQEUE_CLI_COMMAND(vty, ab_xpath, NB_OP_DESTROY, NULL);
ret = NB_APPLY_CLI_COMMANDS(vty, ab_xpath);
Expand Down

0 comments on commit 54e39de

Please sign in to comment.