]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ripd: retrofit the 'default-information' command to the new northbound model
authorRenato Westphal <renato@opensourcerouting.org>
Wed, 9 May 2018 04:34:58 +0000 (01:34 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Sat, 27 Oct 2018 18:16:12 +0000 (16:16 -0200)
Trivial conversion.

'rip->default_information_route_map' was removed since it wasn't being
used anywhere.

'rip->default_information' was removed too because it was being used only
to display the running configuration and thus is not necessary anymore.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ripd/rip_cli.c
ripd/rip_cli.h
ripd/rip_northbound.c
ripd/rip_zebra.c
ripd/ripd.c
ripd/ripd.h

index e3b15047b20f48f47855ab72b345e4cab4969d0c..9193c089a84da07ecd89111563123279bf9f8b35 100644 (file)
@@ -114,10 +114,42 @@ void cli_show_rip_allow_ecmp(struct vty *vty, struct lyd_node *dnode,
        vty_out(vty, " allow-ecmp\n");
 }
 
+/*
+ * XPath: /frr-ripd:ripd/instance/default-information-originate
+ */
+DEFPY (rip_default_information_originate,
+       rip_default_information_originate_cmd,
+       "[no] default-information originate",
+       NO_STR
+       "Control distribution of default route\n"
+       "Distribute a default route\n")
+{
+       struct cli_config_change changes[] = {
+               {
+                       .xpath = "./default-information-originate",
+                       .operation = NB_OP_MODIFY,
+                       .value = no ? "false" : "true",
+               },
+       };
+
+       return nb_cli_cfg_change(vty, NULL, changes, array_size(changes));
+}
+
+void cli_show_rip_default_information_originate(struct vty *vty,
+                                               struct lyd_node *dnode,
+                                               bool show_defaults)
+{
+       if (!yang_dnode_get_bool(dnode, NULL))
+               vty_out(vty, " no");
+
+       vty_out(vty, " default-information originate\n");
+}
+
 void rip_cli_init(void)
 {
        install_element(CONFIG_NODE, &router_rip_cmd);
        install_element(CONFIG_NODE, &no_router_rip_cmd);
 
        install_element(RIP_NODE, &rip_allow_ecmp_cmd);
+       install_element(RIP_NODE, &rip_default_information_originate_cmd);
 }
index 259a78d8ec15587c9c33d41d461a4fc08d2086d2..d63f02dd96d51f8be244b1302fcdc1033bbd6bf6 100644 (file)
@@ -25,5 +25,8 @@ extern void cli_show_router_rip(struct vty *vty, struct lyd_node *dnode,
                                bool show_defaults);
 extern void cli_show_rip_allow_ecmp(struct vty *vty, struct lyd_node *dnode,
                                    bool show_defaults);
+extern void cli_show_rip_default_information_originate(struct vty *vty,
+                                                      struct lyd_node *dnode,
+                                                      bool show_defaults);
 
 #endif /* _FRR_RIP_CLI_H_ */
index 76b154d309e2c8ff73122b4e4c1a540cc7d5919f..884e2a83d105dc5ac9de974a301453574d7e2094 100644 (file)
@@ -99,7 +99,28 @@ ripd_instance_default_information_originate_modify(enum nb_event event,
                                                   const struct lyd_node *dnode,
                                                   union nb_resource *resource)
 {
-       /* TODO: implement me. */
+       bool default_information;
+       struct prefix_ipv4 p;
+
+       if (event != NB_EV_APPLY)
+               return NB_OK;
+
+       default_information = yang_dnode_get_bool(dnode, NULL);
+
+       memset(&p, 0, sizeof(struct prefix_ipv4));
+       p.family = AF_INET;
+       if (default_information) {
+               struct nexthop nh;
+
+               memset(&nh, 0, sizeof(nh));
+               nh.type = NEXTHOP_TYPE_IPV4;
+               rip_redistribute_add(ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p,
+                                    &nh, 0, 0, 0);
+       } else {
+               rip_redistribute_delete(ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p,
+                                       0);
+       }
+
        return NB_OK;
 }
 
@@ -733,6 +754,7 @@ const struct frr_yang_module_info frr_ripd_info = {
                {
                        .xpath = "/frr-ripd:ripd/instance/default-information-originate",
                        .cbs.modify = ripd_instance_default_information_originate_modify,
+                       .cbs.cli_show = cli_show_rip_default_information_originate,
                },
                {
                        .xpath = "/frr-ripd:ripd/instance/default-metric",
index 29b2f88172d44c9971e94a7e7c55e7c552b7f985..1d0290daf9bf15e9e145a948439bb047f5c21c11 100644 (file)
@@ -493,55 +493,6 @@ DEFUN (no_rip_redistribute_type_metric_routemap,
        return CMD_WARNING_CONFIG_FAILED;
 }
 
-/* Default information originate. */
-
-DEFUN (rip_default_information_originate,
-       rip_default_information_originate_cmd,
-       "default-information originate",
-       "Control distribution of default route\n"
-       "Distribute a default route\n")
-{
-       struct prefix_ipv4 p;
-       struct nexthop nh;
-
-       if (!rip->default_information) {
-               memset(&p, 0, sizeof(struct prefix_ipv4));
-               memset(&nh, 0, sizeof(nh));
-
-               p.family = AF_INET;
-               nh.type = NEXTHOP_TYPE_IPV4;
-
-               rip->default_information = 1;
-
-               rip_redistribute_add(ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p,
-                                    &nh, 0, 0, 0);
-       }
-
-       return CMD_SUCCESS;
-}
-
-DEFUN (no_rip_default_information_originate,
-       no_rip_default_information_originate_cmd,
-       "no default-information originate",
-       NO_STR
-       "Control distribution of default route\n"
-       "Distribute a default route\n")
-{
-       struct prefix_ipv4 p;
-
-       if (rip->default_information) {
-               memset(&p, 0, sizeof(struct prefix_ipv4));
-               p.family = AF_INET;
-
-               rip->default_information = 0;
-
-               rip_redistribute_delete(ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p,
-                                       0);
-       }
-
-       return CMD_SUCCESS;
-}
-
 int config_write_rip_redistribute(struct vty *vty, int config_mode)
 {
        int i;
@@ -612,8 +563,6 @@ void rip_zclient_init(struct thread_master *master)
        install_element(RIP_NODE, &no_rip_redistribute_type_metric_cmd);
        install_element(RIP_NODE,
                        &no_rip_redistribute_type_metric_routemap_cmd);
-       install_element(RIP_NODE, &rip_default_information_originate_cmd);
-       install_element(RIP_NODE, &no_rip_default_information_originate_cmd);
 }
 
 void rip_zclient_stop(void)
index ca2bad6de15ebcb1c264f8d4cf1652348b406ea7..7dfabc623d2514027e3cbd8edff7087200fffc07 100644 (file)
@@ -3605,17 +3605,6 @@ static int config_write_rip(struct vty *vty)
                                rip->update_time, rip->timeout_time,
                                rip->garbage_time);
 
-               /* Default information configuration. */
-               if (rip->default_information) {
-                       if (rip->default_information_route_map)
-                               vty_out(vty,
-                                       " default-information originate route-map %s\n",
-                                       rip->default_information_route_map);
-                       else
-                               vty_out(vty,
-                                       " default-information originate\n");
-               }
-
                /* Redistribute configuration. */
                config_write_rip_redistribute(vty, 1);
 
@@ -3807,10 +3796,6 @@ void rip_clean(void)
                                route_unlock_node(rp);
                        }
 
-               /* Redistribute related clear. */
-               if (rip->default_information_route_map)
-                       free(rip->default_information_route_map);
-
                for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
                        if (rip->route_map[i].name)
                                free(rip->route_map[i].name);
index 68b302e87843c08b0c743999903e4e69ec05c24e..c2e39f1a71af594e5071953a0a18d491c9de8e56 100644 (file)
@@ -142,10 +142,6 @@ struct rip {
        /* RIP default metric. */
        int default_metric;
 
-       /* RIP default-information originate. */
-       uint8_t default_information;
-       char *default_information_route_map;
-
        /* RIP default distance. */
        uint8_t distance;
        struct route_table *distance_table;