]> git.puffer.fish Git - matthieu/frr.git/commitdiff
pathd: rework config printing code
authorIgor Ryzhov <iryzhov@nfware.com>
Thu, 5 Aug 2021 20:54:22 +0000 (23:54 +0300)
committerIgor Ryzhov <iryzhov@nfware.com>
Mon, 23 Aug 2021 19:08:20 +0000 (22:08 +0300)
Instead of setting a config_write callback for each node, set a single
callback and print all config from there. It is necessary for the
following work on explicit "exit" command in every node.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
pathd/path_cli.c
pathd/path_pcep_cli.c
pathd/pathd.h

index d517d75e47d5d64c03a5bdaa89a4732cad516a8c..68baa61fa99a27e67dd48969c1dc8d2d1abbb11e 100644 (file)
@@ -45,9 +45,6 @@
 
 
 static int config_write_segment_routing(struct vty *vty);
-static int config_write_traffic_eng(struct vty *vty);
-static int config_write_segment_lists(struct vty *vty);
-static int config_write_sr_policies(struct vty *vty);
 static int segment_list_has_src_dst(
        struct vty *vty, char *xpath, long index, const char *index_str,
        struct in_addr adj_src_ipv4, struct in_addr adj_dst_ipv4,
@@ -63,6 +60,8 @@ static int segment_list_has_prefix(
 
 DEFINE_MTYPE_STATIC(PATHD, PATH_CLI, "Client");
 
+DEFINE_HOOK(pathd_srte_config_write, (struct vty *vty), (vty));
+
 /* Vty node structures. */
 static struct cmd_node segment_routing_node = {
        .name = "segment-routing",
@@ -77,7 +76,6 @@ static struct cmd_node sr_traffic_eng_node = {
        .node = SR_TRAFFIC_ENG_NODE,
        .parent_node = SEGMENT_ROUTING_NODE,
        .prompt = "%s(config-sr-te)# ",
-       .config_write = config_write_traffic_eng,
 };
 
 static struct cmd_node srte_segment_list_node = {
@@ -85,7 +83,6 @@ static struct cmd_node srte_segment_list_node = {
        .node = SR_SEGMENT_LIST_NODE,
        .parent_node = SR_TRAFFIC_ENG_NODE,
        .prompt = "%s(config-sr-te-segment-list)# ",
-       .config_write = config_write_segment_lists,
 };
 
 static struct cmd_node srte_policy_node = {
@@ -93,7 +90,6 @@ static struct cmd_node srte_policy_node = {
        .node = SR_POLICY_NODE,
        .parent_node = SR_TRAFFIC_ENG_NODE,
        .prompt = "%s(config-sr-te-policy)# ",
-       .config_write = config_write_sr_policies,
 };
 
 static struct cmd_node srte_candidate_dyn_node = {
@@ -1249,29 +1245,17 @@ static int config_write_dnode(const struct lyd_node *dnode, void *arg)
 int config_write_segment_routing(struct vty *vty)
 {
        vty_out(vty, "segment-routing\n");
-       return 1;
-}
-
-int config_write_traffic_eng(struct vty *vty)
-{
        vty_out(vty, " traffic-eng\n");
+
        path_ted_config_write(vty);
-       return 1;
-}
 
-int config_write_segment_lists(struct vty *vty)
-{
        yang_dnode_iterate(config_write_dnode, vty, running_config->dnode,
                           "/frr-pathd:pathd/srte/segment-list");
-
-       return 1;
-}
-
-int config_write_sr_policies(struct vty *vty)
-{
        yang_dnode_iterate(config_write_dnode, vty, running_config->dnode,
                           "/frr-pathd:pathd/srte/policy");
 
+       hook_call(pathd_srte_config_write, vty);
+
        return 1;
 }
 
index db5f256a8643d41645b947f86f9ddb90f7697b83..e602fd22df37be06c11949563fb00ee31d230879 100644 (file)
@@ -175,7 +175,6 @@ static struct cmd_node pcep_node = {
        .name = "srte pcep",
        .node = PCEP_NODE,
        .parent_node = SR_TRAFFIC_ENG_NODE,
-       .config_write = pcep_cli_pcep_config_write,
        .prompt = "%s(config-sr-te-pcep)# "
 };
 
@@ -183,7 +182,6 @@ static struct cmd_node pcep_pcc_node = {
        .name = "srte pcep pcc",
        .node = PCEP_PCC_NODE,
        .parent_node = PCEP_NODE,
-       .config_write = pcep_cli_pcc_config_write,
        .prompt = "%s(config-sr-te-pcep-pcc)# "
 };
 
@@ -191,7 +189,6 @@ static struct cmd_node pcep_pce_node = {
        .name = "srte pcep pce",
        .node = PCEP_PCE_NODE,
        .parent_node = PCEP_NODE,
-       .config_write = pcep_cli_pce_config_write,
        .prompt = "%s(config-sr-te-pcep-pce)# "
 };
 
@@ -199,7 +196,6 @@ static struct cmd_node pcep_pce_config_node = {
        .name = "srte pcep pce-config",
        .node = PCEP_PCE_CONFIG_NODE,
        .parent_node = PCEP_NODE,
-       .config_write = pcep_cli_pcep_pce_config_write,
        .prompt = "%s(pce-sr-te-pcep-pce-config)# "
 };
 
@@ -1444,6 +1440,9 @@ int pcep_cli_debug_set_all(uint32_t flags, bool set)
 int pcep_cli_pcep_config_write(struct vty *vty)
 {
        vty_out(vty, "  pcep\n");
+       pcep_cli_pcep_pce_config_write(vty);
+       pcep_cli_pce_config_write(vty);
+       pcep_cli_pcc_config_write(vty);
        return 1;
 }
 
@@ -1999,6 +1998,7 @@ DEFPY(pcep_cli_clear_srte_pcep_session,
 
 void pcep_cli_init(void)
 {
+       hook_register(pathd_srte_config_write, pcep_cli_pcep_config_write);
        hook_register(nb_client_debug_config_write,
                      pcep_cli_debug_config_write);
        hook_register(nb_client_debug_set_all, pcep_cli_debug_set_all);
index f790a0e3c909e908dbb2ba056830e9c811a5e6ac..81d7aa91054adfb9769ed651f4bd84bed400c1de 100644 (file)
@@ -34,6 +34,8 @@
 
 DECLARE_MGROUP(PATHD);
 
+DECLARE_HOOK(pathd_srte_config_write, (struct vty *vty), (vty));
+
 enum srte_protocol_origin {
        SRTE_ORIGIN_UNDEFINED = 0,
        SRTE_ORIGIN_PCEP = 1,