Skip to content

Commit

Permalink
lib: northbound cli show/cmd functions must not modify data nodes
Browse files Browse the repository at this point in the history
To ensure this, add a const modifier to functions' arguments. Would be
great do this initially and avoid this large code change, but better
late than never.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
  • Loading branch information
idryzhov committed Oct 13, 2021
1 parent d7374bd commit 2560505
Show file tree
Hide file tree
Showing 24 changed files with 534 additions and 394 deletions.
48 changes: 24 additions & 24 deletions bfdd/bfdd_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ DEFUN_YANG(
}

void bfd_cli_show_header(struct vty *vty,
struct lyd_node *dnode __attribute__((__unused__)),
const struct lyd_node *dnode
__attribute__((__unused__)),
bool show_defaults __attribute__((__unused__)))
{
vty_out(vty, "!\nbfd\n");
}

void bfd_cli_show_header_end(struct vty *vty,
struct lyd_node *dnode __attribute__((__unused__)))
void bfd_cli_show_header_end(struct vty *vty, const struct lyd_node *dnode
__attribute__((__unused__)))
{
vty_out(vty, "exit\n");
vty_out(vty, "!\n");
Expand Down Expand Up @@ -230,7 +231,7 @@ DEFPY_YANG(
return nb_cli_apply_changes(vty, NULL);
}

static void _bfd_cli_show_peer(struct vty *vty, struct lyd_node *dnode,
static void _bfd_cli_show_peer(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults __attribute__((__unused__)),
bool mhop)
{
Expand Down Expand Up @@ -259,22 +260,20 @@ static void _bfd_cli_show_peer(struct vty *vty, struct lyd_node *dnode,
vty_out(vty, "\n");
}

void bfd_cli_show_single_hop_peer(struct vty *vty,
struct lyd_node *dnode,
void bfd_cli_show_single_hop_peer(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults)
{
_bfd_cli_show_peer(vty, dnode, show_defaults, false);
}

void bfd_cli_show_multi_hop_peer(struct vty *vty,
struct lyd_node *dnode,
bool show_defaults)
void bfd_cli_show_multi_hop_peer(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults)
{
_bfd_cli_show_peer(vty, dnode, show_defaults, true);
}

void bfd_cli_show_peer_end(struct vty *vty,
struct lyd_node *dnode __attribute__((__unused__)))
void bfd_cli_show_peer_end(struct vty *vty, const struct lyd_node *dnode
__attribute__((__unused__)))
{
vty_out(vty, " exit\n");
vty_out(vty, " !\n");
Expand All @@ -291,7 +290,7 @@ DEFPY_YANG(
return nb_cli_apply_changes(vty, NULL);
}

void bfd_cli_show_shutdown(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_show_shutdown(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults)
{
vty_out(vty, " %sshutdown\n",
Expand All @@ -309,7 +308,7 @@ DEFPY_YANG(
return nb_cli_apply_changes(vty, NULL);
}

void bfd_cli_show_passive(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_show_passive(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults)
{
vty_out(vty, " %spassive-mode\n",
Expand Down Expand Up @@ -347,7 +346,7 @@ DEFPY_YANG(
return nb_cli_apply_changes(vty, NULL);
}

void bfd_cli_show_minimum_ttl(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_show_minimum_ttl(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults)
{
vty_out(vty, " minimum-ttl %s\n", yang_dnode_get_string(dnode, NULL));
Expand All @@ -364,7 +363,7 @@ DEFPY_YANG(
return nb_cli_apply_changes(vty, NULL);
}

void bfd_cli_show_mult(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_show_mult(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults)
{
vty_out(vty, " detect-multiplier %s\n",
Expand All @@ -386,7 +385,7 @@ DEFPY_YANG(
return nb_cli_apply_changes(vty, NULL);
}

void bfd_cli_show_rx(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_show_rx(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults)
{
uint32_t value = yang_dnode_get_uint32(dnode, NULL);
Expand All @@ -409,7 +408,7 @@ DEFPY_YANG(
return nb_cli_apply_changes(vty, NULL);
}

void bfd_cli_show_tx(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_show_tx(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults)
{
uint32_t value = yang_dnode_get_uint32(dnode, NULL);
Expand Down Expand Up @@ -437,8 +436,8 @@ DEFPY_YANG(
return nb_cli_apply_changes(vty, NULL);
}

void bfd_cli_show_echo(struct vty *vty, struct lyd_node *dnode,
bool show_defaults)
void bfd_cli_show_echo(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults)
{
vty_out(vty, " %secho-mode\n",
yang_dnode_get_bool(dnode, NULL) ? "" : "no ");
Expand Down Expand Up @@ -487,8 +486,8 @@ DEFPY_YANG(
return nb_cli_apply_changes(vty, NULL);
}

void bfd_cli_show_desired_echo_transmission_interval(struct vty *vty,
struct lyd_node *dnode, bool show_defaults)
void bfd_cli_show_desired_echo_transmission_interval(
struct vty *vty, const struct lyd_node *dnode, bool show_defaults)
{
uint32_t value = yang_dnode_get_uint32(dnode, NULL);

Expand Down Expand Up @@ -522,7 +521,8 @@ DEFPY_YANG(
}

void bfd_cli_show_required_echo_receive_interval(struct vty *vty,
struct lyd_node *dnode, bool show_defaults)
const struct lyd_node *dnode,
bool show_defaults)
{
uint32_t value = yang_dnode_get_uint32(dnode, NULL);

Expand Down Expand Up @@ -573,7 +573,7 @@ DEFPY_YANG(no_bfd_profile, no_bfd_profile_cmd,
return nb_cli_apply_changes(vty, NULL);
}

void bfd_cli_show_profile(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_show_profile(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults)
{
vty_out(vty, " profile %s\n", yang_dnode_get_string(dnode, "./name"));
Expand Down Expand Up @@ -654,7 +654,7 @@ DEFPY_YANG(bfd_peer_profile, bfd_peer_profile_cmd,
return nb_cli_apply_changes(vty, NULL);
}

void bfd_cli_peer_profile_show(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_peer_profile_show(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults)
{
vty_out(vty, " profile %s\n", yang_dnode_get_string(dnode, NULL));
Expand Down
35 changes: 18 additions & 17 deletions bfdd/bfdd_nb.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,35 +195,36 @@ bfdd_bfd_sessions_multi_hop_stats_echo_packet_output_count_get_elem(
struct nb_cb_get_elem_args *args);

/* Optional 'cli_show' callbacks. */
void bfd_cli_show_header(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_show_header(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_header_end(struct vty *vty, struct lyd_node *dnode);
void bfd_cli_show_single_hop_peer(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_show_header_end(struct vty *vty, const struct lyd_node *dnode);
void bfd_cli_show_single_hop_peer(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_multi_hop_peer(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_show_multi_hop_peer(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_peer_end(struct vty *vty, struct lyd_node *dnode);
void bfd_cli_show_mult(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_show_peer_end(struct vty *vty, const struct lyd_node *dnode);
void bfd_cli_show_mult(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_tx(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_show_tx(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_rx(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_show_rx(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_shutdown(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_show_shutdown(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_echo(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_show_echo(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_desired_echo_transmission_interval(
struct vty *vty, struct lyd_node *dnode, bool show_defaults);
void bfd_cli_show_required_echo_receive_interval(
struct vty *vty, struct lyd_node *dnode, bool show_defaults);
void bfd_cli_show_profile(struct vty *vty, struct lyd_node *dnode,
struct vty *vty, const struct lyd_node *dnode, bool show_defaults);
void bfd_cli_show_required_echo_receive_interval(struct vty *vty,
const struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_profile(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_peer_profile_show(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_peer_profile_show(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_passive(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_show_passive(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_minimum_ttl(struct vty *vty, struct lyd_node *dnode,
void bfd_cli_show_minimum_ttl(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults);

#endif /* _FRR_BFDD_NB_H_ */
Loading

0 comments on commit 2560505

Please sign in to comment.