forked from Mirror/frr
lib: staticd: vtysh: apply frrbot style requirements
Signed-off-by: Christian Hopps <chopps@labn.net>
This commit is contained in:
parent
1401ee8bf7
commit
39c329bbd1
|
@ -242,8 +242,8 @@ DEFUN_NOSH(end_config, end_config_cmd, "XFRR_end_configuration",
|
||||||
ret = nb_cli_pending_commit_check(vty);
|
ret = nb_cli_pending_commit_check(vty);
|
||||||
|
|
||||||
zlog_info("Configuration Read in Took: %s", readin_time_str);
|
zlog_info("Configuration Read in Took: %s", readin_time_str);
|
||||||
zlog_debug("%s: VTY:%p, pending SET-CFG: %u",
|
zlog_debug("%s: VTY:%p, pending SET-CFG: %u", __func__, vty,
|
||||||
__func__, vty, (uint32_t)vty->mgmt_num_pending_setcfg);
|
(uint32_t)vty->mgmt_num_pending_setcfg);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If (and only if) we have sent any CLI config commands to MGMTd
|
* If (and only if) we have sent any CLI config commands to MGMTd
|
||||||
|
|
|
@ -846,8 +846,8 @@ void nb_candidate_edit_config_changes(
|
||||||
|
|
||||||
/* Handle relative XPaths. */
|
/* Handle relative XPaths. */
|
||||||
memset(xpath, 0, sizeof(xpath));
|
memset(xpath, 0, sizeof(xpath));
|
||||||
if (xpath_index > 0
|
if (xpath_index > 0 &&
|
||||||
&& (xpath_base[0] == '.' || change->xpath[0] == '.'))
|
(xpath_base[0] == '.' || change->xpath[0] == '.'))
|
||||||
strlcpy(xpath, curr_xpath, sizeof(xpath));
|
strlcpy(xpath, curr_xpath, sizeof(xpath));
|
||||||
if (xpath_base[0]) {
|
if (xpath_base[0]) {
|
||||||
if (xpath_base[0] == '.')
|
if (xpath_base[0] == '.')
|
||||||
|
@ -947,9 +947,9 @@ int nb_candidate_validate_yang(struct nb_config *candidate, bool no_state,
|
||||||
char *errmsg, size_t errmsg_len)
|
char *errmsg, size_t errmsg_len)
|
||||||
{
|
{
|
||||||
if (lyd_validate_all(&candidate->dnode, ly_native_ctx,
|
if (lyd_validate_all(&candidate->dnode, ly_native_ctx,
|
||||||
no_state ? LYD_VALIDATE_NO_STATE :
|
no_state ? LYD_VALIDATE_NO_STATE
|
||||||
LYD_VALIDATE_PRESENT, NULL)
|
: LYD_VALIDATE_PRESENT,
|
||||||
!= 0) {
|
NULL) != 0) {
|
||||||
yang_print_errors(ly_native_ctx, errmsg, errmsg_len);
|
yang_print_errors(ly_native_ctx, errmsg, errmsg_len);
|
||||||
return NB_ERR_VALIDATION;
|
return NB_ERR_VALIDATION;
|
||||||
}
|
}
|
||||||
|
@ -1005,8 +1005,7 @@ int nb_candidate_diff_and_validate_yang(struct nb_context *context,
|
||||||
char *errmsg, size_t errmsg_len)
|
char *errmsg, size_t errmsg_len)
|
||||||
{
|
{
|
||||||
if (nb_candidate_validate_yang(candidate, true, errmsg,
|
if (nb_candidate_validate_yang(candidate, true, errmsg,
|
||||||
sizeof(errmsg_len))
|
sizeof(errmsg_len)) != NB_OK)
|
||||||
!= NB_OK)
|
|
||||||
return NB_ERR_VALIDATION;
|
return NB_ERR_VALIDATION;
|
||||||
|
|
||||||
RB_INIT(nb_config_cbs, changes);
|
RB_INIT(nb_config_cbs, changes);
|
||||||
|
@ -1043,9 +1042,9 @@ int nb_candidate_commit_prepare(struct nb_context context,
|
||||||
{
|
{
|
||||||
struct nb_config_cbs changes;
|
struct nb_config_cbs changes;
|
||||||
|
|
||||||
if (!skip_validate
|
if (!skip_validate &&
|
||||||
&& nb_candidate_validate_yang(candidate, true, errmsg, errmsg_len)
|
nb_candidate_validate_yang(candidate, true, errmsg, errmsg_len) !=
|
||||||
!= NB_OK) {
|
NB_OK) {
|
||||||
flog_warn(EC_LIB_NB_CANDIDATE_INVALID,
|
flog_warn(EC_LIB_NB_CANDIDATE_INVALID,
|
||||||
"%s: failed to validate candidate configuration",
|
"%s: failed to validate candidate configuration",
|
||||||
__func__);
|
__func__);
|
||||||
|
@ -1061,10 +1060,9 @@ int nb_candidate_commit_prepare(struct nb_context context,
|
||||||
return NB_ERR_NO_CHANGES;
|
return NB_ERR_NO_CHANGES;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skip_validate
|
if (!skip_validate &&
|
||||||
&& nb_candidate_validate_code(&context, candidate, &changes, errmsg,
|
nb_candidate_validate_code(&context, candidate, &changes, errmsg,
|
||||||
errmsg_len)
|
errmsg_len) != NB_OK) {
|
||||||
!= NB_OK) {
|
|
||||||
flog_warn(EC_LIB_NB_CANDIDATE_INVALID,
|
flog_warn(EC_LIB_NB_CANDIDATE_INVALID,
|
||||||
"%s: failed to validate candidate configuration",
|
"%s: failed to validate candidate configuration",
|
||||||
__func__);
|
__func__);
|
||||||
|
|
|
@ -50,8 +50,8 @@ struct nb_yang_xpath {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NB_YANG_XPATH_KEY(__xpath, __indx1, __indx2) \
|
#define NB_YANG_XPATH_KEY(__xpath, __indx1, __indx2) \
|
||||||
((__xpath->num_tags > __indx1) \
|
((__xpath->num_tags > __indx1) && \
|
||||||
&& (__xpath->tags[__indx1].num_keys > __indx2) \
|
(__xpath->tags[__indx1].num_keys > __indx2) \
|
||||||
? &__xpath->tags[__indx1].keys[__indx2] \
|
? &__xpath->tags[__indx1].keys[__indx2] \
|
||||||
: NULL)
|
: NULL)
|
||||||
|
|
||||||
|
@ -1006,8 +1006,9 @@ extern void nb_config_diff(const struct nb_config *reference,
|
||||||
* Returns:
|
* Returns:
|
||||||
* NB_OK on success, NB_ERR_VALIDATION otherwise
|
* NB_OK on success, NB_ERR_VALIDATION otherwise
|
||||||
*/
|
*/
|
||||||
extern int nb_candidate_validate_yang(struct nb_config *candidate, bool no_state,
|
extern int nb_candidate_validate_yang(struct nb_config *candidate,
|
||||||
char *errmsg, size_t errmsg_len);
|
bool no_state, char *errmsg,
|
||||||
|
size_t errmsg_len);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform code-level validation using the northbound callbacks.
|
* Perform code-level validation using the northbound callbacks.
|
||||||
|
|
38
lib/vty.c
38
lib/vty.c
|
@ -1627,10 +1627,9 @@ struct vty *vty_new(void)
|
||||||
|
|
||||||
if (mgmt_lib_hndl) {
|
if (mgmt_lib_hndl) {
|
||||||
new->mgmt_client_id = mgmt_client_id_next++;
|
new->mgmt_client_id = mgmt_client_id_next++;
|
||||||
if (mgmt_fe_create_client_session(mgmt_lib_hndl,
|
if (mgmt_fe_create_client_session(
|
||||||
new->mgmt_client_id,
|
mgmt_lib_hndl, new->mgmt_client_id,
|
||||||
(uintptr_t)new)
|
(uintptr_t) new) != MGMTD_SUCCESS)
|
||||||
!= MGMTD_SUCCESS)
|
|
||||||
zlog_err(
|
zlog_err(
|
||||||
"Failed to open a MGMTD Frontend session for VTY session %p!!",
|
"Failed to open a MGMTD Frontend session for VTY session %p!!",
|
||||||
new);
|
new);
|
||||||
|
@ -2697,8 +2696,7 @@ int vty_config_enter(struct vty *vty, bool private_config, bool exclusive)
|
||||||
if (vty_mgmt_fe_enabled()) {
|
if (vty_mgmt_fe_enabled()) {
|
||||||
if (!mgmt_candidate_ds_wr_locked) {
|
if (!mgmt_candidate_ds_wr_locked) {
|
||||||
if (vty_mgmt_send_lockds_req(vty, MGMTD_DS_CANDIDATE,
|
if (vty_mgmt_send_lockds_req(vty, MGMTD_DS_CANDIDATE,
|
||||||
true)
|
true) != 0) {
|
||||||
!= 0) {
|
|
||||||
vty_out(vty, "Not able to lock candidate DS\n");
|
vty_out(vty, "Not able to lock candidate DS\n");
|
||||||
return CMD_WARNING;
|
return CMD_WARNING;
|
||||||
}
|
}
|
||||||
|
@ -2763,10 +2761,10 @@ int vty_config_node_exit(struct vty *vty)
|
||||||
{
|
{
|
||||||
vty->xpath_index = 0;
|
vty->xpath_index = 0;
|
||||||
|
|
||||||
if (vty_mgmt_fe_enabled() && mgmt_candidate_ds_wr_locked
|
if (vty_mgmt_fe_enabled() && mgmt_candidate_ds_wr_locked &&
|
||||||
&& vty->mgmt_locked_candidate_ds) {
|
vty->mgmt_locked_candidate_ds) {
|
||||||
if (vty_mgmt_send_lockds_req(vty, MGMTD_DS_CANDIDATE, false)
|
if (vty_mgmt_send_lockds_req(vty, MGMTD_DS_CANDIDATE, false) !=
|
||||||
!= 0) {
|
0) {
|
||||||
vty_out(vty, "Not able to unlock candidate DS\n");
|
vty_out(vty, "Not able to unlock candidate DS\n");
|
||||||
return CMD_WARNING;
|
return CMD_WARNING;
|
||||||
}
|
}
|
||||||
|
@ -3363,8 +3361,8 @@ static void vty_mgmt_set_config_result_notified(
|
||||||
static void vty_mgmt_commit_config_result_notified(
|
static void vty_mgmt_commit_config_result_notified(
|
||||||
uintptr_t lib_hndl, uintptr_t usr_data, uint64_t client_id,
|
uintptr_t lib_hndl, uintptr_t usr_data, uint64_t client_id,
|
||||||
uintptr_t session_id, uintptr_t session_ctx, uint64_t req_id,
|
uintptr_t session_id, uintptr_t session_ctx, uint64_t req_id,
|
||||||
bool success, Mgmtd__DatastoreId src_ds_id, Mgmtd__DatastoreId dst_ds_id,
|
bool success, Mgmtd__DatastoreId src_ds_id,
|
||||||
bool validate_only, char *errmsg_if_any)
|
Mgmtd__DatastoreId dst_ds_id, bool validate_only, char *errmsg_if_any)
|
||||||
{
|
{
|
||||||
struct vty *vty;
|
struct vty *vty;
|
||||||
|
|
||||||
|
@ -3436,18 +3434,15 @@ static struct mgmt_fe_client_params client_params = {
|
||||||
.client_connect_notify = vty_mgmt_server_connected,
|
.client_connect_notify = vty_mgmt_server_connected,
|
||||||
.client_session_notify = vty_mgmt_session_created,
|
.client_session_notify = vty_mgmt_session_created,
|
||||||
.lock_ds_notify = vty_mgmt_ds_lock_notified,
|
.lock_ds_notify = vty_mgmt_ds_lock_notified,
|
||||||
.set_config_notify =
|
.set_config_notify = vty_mgmt_set_config_result_notified,
|
||||||
vty_mgmt_set_config_result_notified,
|
.commit_config_notify = vty_mgmt_commit_config_result_notified,
|
||||||
.commit_config_notify =
|
|
||||||
vty_mgmt_commit_config_result_notified,
|
|
||||||
.get_data_notify = vty_mgmt_get_data_result_notified,
|
.get_data_notify = vty_mgmt_get_data_result_notified,
|
||||||
};
|
};
|
||||||
|
|
||||||
void vty_init_mgmt_fe(void)
|
void vty_init_mgmt_fe(void)
|
||||||
{
|
{
|
||||||
if (!vty_master) {
|
if (!vty_master) {
|
||||||
zlog_err(
|
zlog_err("Always call vty_mgmt_init_fe() after vty_init()!!");
|
||||||
"Always call vty_mgmt_init_fe() after vty_init()!!");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3547,12 +3542,11 @@ int vty_mgmt_send_config_data(struct vty *vty)
|
||||||
|
|
||||||
vty->mgmt_req_id++;
|
vty->mgmt_req_id++;
|
||||||
implicit_commit = vty_needs_implicit_commit(vty);
|
implicit_commit = vty_needs_implicit_commit(vty);
|
||||||
if (cnt
|
if (cnt && mgmt_fe_set_config_data(
|
||||||
&& mgmt_fe_set_config_data(
|
|
||||||
mgmt_lib_hndl, vty->mgmt_session_id,
|
mgmt_lib_hndl, vty->mgmt_session_id,
|
||||||
vty->mgmt_req_id, MGMTD_DS_CANDIDATE, cfgreq,
|
vty->mgmt_req_id, MGMTD_DS_CANDIDATE, cfgreq,
|
||||||
cnt, implicit_commit, MGMTD_DS_RUNNING)
|
cnt, implicit_commit,
|
||||||
!= MGMTD_SUCCESS) {
|
MGMTD_DS_RUNNING) != MGMTD_SUCCESS) {
|
||||||
zlog_err("Failed to send %d Config Xpaths to MGMTD!!",
|
zlog_err("Failed to send %d Config Xpaths to MGMTD!!",
|
||||||
(int)indx);
|
(int)indx);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -392,7 +392,8 @@ extern bool vty_mgmt_fe_enabled(void);
|
||||||
extern int vty_mgmt_send_config_data(struct vty *vty);
|
extern int vty_mgmt_send_config_data(struct vty *vty);
|
||||||
extern int vty_mgmt_send_commit_config(struct vty *vty, bool validate_only,
|
extern int vty_mgmt_send_commit_config(struct vty *vty, bool validate_only,
|
||||||
bool abort);
|
bool abort);
|
||||||
extern int vty_mgmt_send_get_config(struct vty *vty, Mgmtd__DatastoreId datastore,
|
extern int vty_mgmt_send_get_config(struct vty *vty,
|
||||||
|
Mgmtd__DatastoreId datastore,
|
||||||
const char **xpath_list, int num_req);
|
const char **xpath_list, int num_req);
|
||||||
extern int vty_mgmt_send_get_data(struct vty *vty, Mgmtd__DatastoreId datastore,
|
extern int vty_mgmt_send_get_data(struct vty *vty, Mgmtd__DatastoreId datastore,
|
||||||
const char **xpath_list, int num_req);
|
const char **xpath_list, int num_req);
|
||||||
|
@ -403,8 +404,7 @@ extern void vty_mgmt_resume_response(struct vty *vty, bool success);
|
||||||
static inline bool vty_needs_implicit_commit(struct vty *vty)
|
static inline bool vty_needs_implicit_commit(struct vty *vty)
|
||||||
{
|
{
|
||||||
return (frr_get_cli_mode() == FRR_CLI_CLASSIC
|
return (frr_get_cli_mode() == FRR_CLI_CLASSIC
|
||||||
? ((vty->pending_allowed
|
? ((vty->pending_allowed || vty->no_implicit_commit)
|
||||||
|| vty->no_implicit_commit)
|
|
||||||
? false
|
? false
|
||||||
: true)
|
: true)
|
||||||
: false);
|
: false);
|
||||||
|
|
|
@ -285,9 +285,10 @@ static int static_route_nb_run(struct vty *vty, struct static_route_args *args)
|
||||||
nb_cli_enqueue_change(vty, ab_xpath,
|
nb_cli_enqueue_change(vty, ab_xpath,
|
||||||
NB_OP_MODIFY, "false");
|
NB_OP_MODIFY, "false");
|
||||||
}
|
}
|
||||||
if (type == STATIC_IPV4_GATEWAY || type == STATIC_IPV6_GATEWAY
|
if (type == STATIC_IPV4_GATEWAY ||
|
||||||
|| type == STATIC_IPV4_GATEWAY_IFNAME
|
type == STATIC_IPV6_GATEWAY ||
|
||||||
|| type == STATIC_IPV6_GATEWAY_IFNAME) {
|
type == STATIC_IPV4_GATEWAY_IFNAME ||
|
||||||
|
type == STATIC_IPV6_GATEWAY_IFNAME) {
|
||||||
strlcpy(ab_xpath, xpath_nexthop, sizeof(ab_xpath));
|
strlcpy(ab_xpath, xpath_nexthop, sizeof(ab_xpath));
|
||||||
strlcat(ab_xpath, FRR_STATIC_ROUTE_NH_COLOR_XPATH,
|
strlcat(ab_xpath, FRR_STATIC_ROUTE_NH_COLOR_XPATH,
|
||||||
sizeof(ab_xpath));
|
sizeof(ab_xpath));
|
||||||
|
@ -369,36 +370,34 @@ static int static_route_nb_run(struct vty *vty, struct static_route_args *args)
|
||||||
} else {
|
} else {
|
||||||
if (args->source) {
|
if (args->source) {
|
||||||
if (args->distance)
|
if (args->distance)
|
||||||
snprintf(
|
snprintf(ab_xpath, sizeof(ab_xpath),
|
||||||
ab_xpath, sizeof(ab_xpath),
|
|
||||||
FRR_DEL_S_ROUTE_SRC_NH_KEY_XPATH,
|
FRR_DEL_S_ROUTE_SRC_NH_KEY_XPATH,
|
||||||
"frr-staticd:staticd", "staticd", args->vrf,
|
"frr-staticd:staticd", "staticd",
|
||||||
buf_prefix,
|
args->vrf, buf_prefix,
|
||||||
yang_afi_safi_value2identity(args->afi,
|
yang_afi_safi_value2identity(
|
||||||
args->safi),
|
args->afi, args->safi),
|
||||||
buf_src_prefix, table_id, distance,
|
buf_src_prefix, table_id, distance,
|
||||||
buf_nh_type, args->nexthop_vrf, buf_gate_str,
|
buf_nh_type, args->nexthop_vrf,
|
||||||
args->interface_name);
|
buf_gate_str, args->interface_name);
|
||||||
else
|
else
|
||||||
snprintf(
|
snprintf(
|
||||||
ab_xpath, sizeof(ab_xpath),
|
ab_xpath, sizeof(ab_xpath),
|
||||||
FRR_DEL_S_ROUTE_SRC_NH_KEY_NO_DISTANCE_XPATH,
|
FRR_DEL_S_ROUTE_SRC_NH_KEY_NO_DISTANCE_XPATH,
|
||||||
"frr-staticd:staticd", "staticd", args->vrf,
|
"frr-staticd:staticd", "staticd",
|
||||||
buf_prefix,
|
args->vrf, buf_prefix,
|
||||||
yang_afi_safi_value2identity(args->afi,
|
yang_afi_safi_value2identity(
|
||||||
args->safi),
|
args->afi, args->safi),
|
||||||
buf_src_prefix, table_id, buf_nh_type,
|
buf_src_prefix, table_id, buf_nh_type,
|
||||||
args->nexthop_vrf, buf_gate_str,
|
args->nexthop_vrf, buf_gate_str,
|
||||||
args->interface_name);
|
args->interface_name);
|
||||||
} else {
|
} else {
|
||||||
if (args->distance)
|
if (args->distance)
|
||||||
snprintf(
|
snprintf(ab_xpath, sizeof(ab_xpath),
|
||||||
ab_xpath, sizeof(ab_xpath),
|
|
||||||
FRR_DEL_S_ROUTE_NH_KEY_XPATH,
|
FRR_DEL_S_ROUTE_NH_KEY_XPATH,
|
||||||
"frr-staticd:staticd", "staticd",
|
"frr-staticd:staticd", "staticd",
|
||||||
args->vrf, buf_prefix,
|
args->vrf, buf_prefix,
|
||||||
yang_afi_safi_value2identity(args->afi,
|
yang_afi_safi_value2identity(
|
||||||
args->safi),
|
args->afi, args->safi),
|
||||||
table_id, distance, buf_nh_type,
|
table_id, distance, buf_nh_type,
|
||||||
args->nexthop_vrf, buf_gate_str,
|
args->nexthop_vrf, buf_gate_str,
|
||||||
args->interface_name);
|
args->interface_name);
|
||||||
|
@ -408,10 +407,11 @@ static int static_route_nb_run(struct vty *vty, struct static_route_args *args)
|
||||||
FRR_DEL_S_ROUTE_NH_KEY_NO_DISTANCE_XPATH,
|
FRR_DEL_S_ROUTE_NH_KEY_NO_DISTANCE_XPATH,
|
||||||
"frr-staticd:staticd", "staticd",
|
"frr-staticd:staticd", "staticd",
|
||||||
args->vrf, buf_prefix,
|
args->vrf, buf_prefix,
|
||||||
yang_afi_safi_value2identity(args->afi,
|
yang_afi_safi_value2identity(
|
||||||
args->safi),
|
args->afi, args->safi),
|
||||||
table_id, buf_nh_type, args->nexthop_vrf,
|
table_id, buf_nh_type,
|
||||||
buf_gate_str, args->interface_name);
|
args->nexthop_vrf, buf_gate_str,
|
||||||
|
args->interface_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
dnode = yang_dnode_get(vty->candidate_config->dnode, ab_xpath);
|
dnode = yang_dnode_get(vty->candidate_config->dnode, ab_xpath);
|
||||||
|
|
Loading…
Reference in a new issue