]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospfd: fix ospf nssa command
authorChirag Shah <chirag@cumulusnetworks.com>
Sat, 7 Oct 2017 20:26:13 +0000 (13:26 -0700)
committerChirag Shah <chirag@cumulusnetworks.com>
Mon, 16 Oct 2017 17:02:05 +0000 (10:02 -0700)
-Fix ordering of nssa command with translate options
and no-summary option.
Just like ospf stub no-summary keep the order order
of nssa no-summary.
- Fix NSSA options.
- Avoid displaying translate-candiate (default) option
in running-config.

cumulus(config-router)# area 2.2.2.2 nssa
  <cr>
  no-summary           Do not inject inter-area routes into nssa
  translate-always     Configure NSSA-ABR to always translate
  translate-candidate  Configure NSSA-ABR for translate election (default)
  translate-never      Configure NSSA-ABR to never translate

Running-config output:
router ospf
 area 2.2.2.2 nssa translate-always
 area 2.2.2.2 nssa no-summary

Ticket:CM-8312

Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
ospfd/ospf_vty.c
ospfd/ospfd.c
ospfd/ospfd.h

index f53efa4355fc06244c2609ff8c4671bdea7b3891..70e0da1158922996a0b1824ed937a31716bc7ca2 100644 (file)
@@ -1470,7 +1470,8 @@ DEFUN (no_ospf_area_stub_no_summary,
 }
 
 static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc,
-                                     struct cmd_token **argv, int nosum)
+                                     struct cmd_token **argv, int cfg_nosum,
+                                     int nosum)
 {
        VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
        struct in_addr area_id;
@@ -1502,30 +1503,18 @@ static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc,
                                                   OSPF_NSSA_ROLE_CANDIDATE);
        }
 
-       if (nosum)
-               ospf_area_no_summary_set(ospf, area_id);
-       else
-               ospf_area_no_summary_unset(ospf, area_id);
+       if (cfg_nosum) {
+               if (nosum)
+                       ospf_area_no_summary_set(ospf, area_id);
+               else
+                       ospf_area_no_summary_unset(ospf, area_id);
+       }
 
        ospf_schedule_abr_task(ospf);
 
        return CMD_SUCCESS;
 }
 
-DEFUN (ospf_area_nssa_translate_no_summary,
-       ospf_area_nssa_translate_no_summary_cmd,
-       "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always> no-summary",
-       "OSPF area parameters\n"
-       "OSPF area ID in IP address format\n"
-       "OSPF area ID as a decimal value\n"
-       "Configure OSPF area as nssa\n"
-       "Configure NSSA-ABR for translate election (default)\n"
-       "Configure NSSA-ABR to never translate\n"
-       "Configure NSSA-ABR to always translate\n"
-       "Do not inject inter-area routes into nssa\n")
-{
-       return ospf_area_nssa_cmd_handler(vty, argc, argv, 1);
-}
 
 DEFUN (ospf_area_nssa_translate,
        ospf_area_nssa_translate_cmd,
@@ -1538,7 +1527,7 @@ DEFUN (ospf_area_nssa_translate,
        "Configure NSSA-ABR to never translate\n"
        "Configure NSSA-ABR to always translate\n")
 {
-       return ospf_area_nssa_cmd_handler(vty, argc, argv, 0);
+       return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0);
 }
 
 DEFUN (ospf_area_nssa,
@@ -1549,7 +1538,7 @@ DEFUN (ospf_area_nssa,
        "OSPF area ID as a decimal value\n"
        "Configure OSPF area as nssa\n")
 {
-       return ospf_area_nssa_cmd_handler(vty, argc, argv, 0);
+       return ospf_area_nssa_cmd_handler(vty, argc, argv, 1, 0);
 }
 
 DEFUN (ospf_area_nssa_no_summary,
@@ -1561,12 +1550,54 @@ DEFUN (ospf_area_nssa_no_summary,
        "Configure OSPF area as nssa\n"
        "Do not inject inter-area routes into nssa\n")
 {
-       return ospf_area_nssa_cmd_handler(vty, argc, argv, 1);
+       int idx_ipv4_number = 1;
+       struct in_addr area_id;
+       int format;
+
+       VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
+       VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format,
+                                  argv[idx_ipv4_number]->arg);
+
+       ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
+                                    format);
+       ospf_area_nssa_no_summary_set(ospf, area_id);
+
+       ospf_schedule_abr_task(ospf);
+
+       return CMD_SUCCESS;
+}
+
+DEFUN (no_ospf_area_nssa_no_summary,
+       no_ospf_area_nssa_no_summary_cmd,
+       "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
+       NO_STR
+       "OSPF area parameters\n"
+       "OSPF area ID in IP address format\n"
+       "OSPF area ID as a decimal value\n"
+       "Configure OSPF area as nssa\n"
+       "Do not inject inter-area routes into nssa\n")
+{
+       int idx_ipv4_number = 2;
+       struct in_addr area_id;
+       int format;
+
+       VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
+
+       VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format,
+                                  argv[idx_ipv4_number]->arg);
+
+       ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
+                                    format);
+       ospf_area_no_summary_unset(ospf, area_id);
+
+       ospf_schedule_abr_task(ospf);
+
+       return CMD_SUCCESS;
 }
 
 DEFUN (no_ospf_area_nssa,
        no_ospf_area_nssa_cmd,
-       "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always> [no-summary]]",
+       "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
        NO_STR
        "OSPF area parameters\n"
        "OSPF area ID in IP address format\n"
@@ -1574,8 +1605,7 @@ DEFUN (no_ospf_area_nssa,
        "Configure OSPF area as nssa\n"
        "Configure NSSA-ABR for translate election (default)\n"
        "Configure NSSA-ABR to never translate\n"
-       "Configure NSSA-ABR to always translate\n"
-       "Do not inject inter-area routes into nssa\n")
+       "Configure NSSA-ABR to always translate\n")
 {
        VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
        int idx_ipv4_number = 2;
@@ -1585,8 +1615,7 @@ DEFUN (no_ospf_area_nssa,
        VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format,
                                   argv[idx_ipv4_number]->arg);
 
-       ospf_area_nssa_unset(ospf, area_id);
-       ospf_area_no_summary_unset(ospf, area_id);
+       ospf_area_nssa_unset(ospf, area_id, argc);
 
        ospf_schedule_abr_task(ospf);
 
@@ -8985,28 +9014,30 @@ static int config_write_ospf_area(struct vty *vty, struct ospf *ospf)
 
                if ((area->external_routing == OSPF_AREA_STUB)
                    || (area->external_routing == OSPF_AREA_NSSA)) {
-                       if (area->external_routing == OSPF_AREA_STUB)
+                       if (area->external_routing == OSPF_AREA_STUB) {
                                vty_out(vty, " area %s stub", buf);
-                       else if (area->external_routing == OSPF_AREA_NSSA) {
-                               vty_out(vty, " area %s nssa", buf);
+                               if (area->no_summary)
+                                       vty_out(vty, " no-summary\n");
+                               vty_out(vty, "\n");
+                       } else if (area->external_routing == OSPF_AREA_NSSA) {
                                switch (area->NSSATranslatorRole) {
                                case OSPF_NSSA_ROLE_NEVER:
-                                       vty_out(vty, " translate-never");
+                                       vty_out(vty,
+                                               " area %s nssa translate-never\n",
+                                               buf);
                                        break;
                                case OSPF_NSSA_ROLE_ALWAYS:
-                                       vty_out(vty, " translate-always");
+                                       vty_out(vty,
+                                               " area %s nssa translate-always\n",
+                                               buf);
                                        break;
-                               case OSPF_NSSA_ROLE_CANDIDATE:
-                               default:
-                                       vty_out(vty, " translate-candidate");
                                }
+                               if (area->no_summary)
+                                       vty_out(vty,
+                                               " area %s nssa no-summary\n",
+                                               buf);
                        }
 
-                       if (area->no_summary)
-                               vty_out(vty, " no-summary");
-
-                       vty_out(vty, "\n");
-
                        if (area->default_cost != 1)
                                vty_out(vty, " area %s default-cost %d\n", buf,
                                        area->default_cost);
@@ -9721,9 +9752,9 @@ void ospf_vty_init(void)
 
        /* "area nssa" commands. */
        install_element(OSPF_NODE, &ospf_area_nssa_cmd);
-       install_element(OSPF_NODE, &ospf_area_nssa_translate_no_summary_cmd);
        install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd);
        install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd);
+       install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd);
        install_element(OSPF_NODE, &no_ospf_area_nssa_cmd);
 
        install_element(OSPF_NODE, &ospf_area_default_cost_cmd);
index 9e1cf811604b6e587be7770d3b4db52899b412db..8ee32289c175dc20a3361f3452e35b4d5c99f6a8 100644 (file)
@@ -1493,7 +1493,7 @@ int ospf_area_no_summary_unset(struct ospf *ospf, struct in_addr area_id)
        return 1;
 }
 
-int ospf_area_nssa_set(struct ospf *ospf, struct in_addr area_id)
+int ospf_area_nssa_no_summary_set(struct ospf *ospf, struct in_addr area_id)
 {
        struct ospf_area *area;
 
@@ -1504,18 +1504,37 @@ int ospf_area_nssa_set(struct ospf *ospf, struct in_addr area_id)
        if (area->external_routing != OSPF_AREA_NSSA) {
                ospf_area_type_set(area, OSPF_AREA_NSSA);
                ospf->anyNSSA++;
+               area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
        }
 
-       /* set NSSA area defaults */
-       area->no_summary = 0;
-       area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
-       area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
-       area->NSSATranslatorStabilityInterval = OSPF_NSSA_TRANS_STABLE_DEFAULT;
+       ospf_area_no_summary_set(ospf, area_id);
 
        return 1;
 }
 
-int ospf_area_nssa_unset(struct ospf *ospf, struct in_addr area_id)
+int ospf_area_nssa_set(struct ospf *ospf, struct in_addr area_id)
+{
+       struct ospf_area *area;
+
+       area = ospf_area_get(ospf, area_id);
+       if (ospf_area_vlink_count(ospf, area))
+               return 0;
+
+       if (area->external_routing != OSPF_AREA_NSSA) {
+               ospf_area_type_set(area, OSPF_AREA_NSSA);
+               ospf->anyNSSA++;
+
+               /* set NSSA area defaults */
+               area->no_summary = 0;
+               area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
+               area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
+               area->NSSATranslatorStabilityInterval =
+                       OSPF_NSSA_TRANS_STABLE_DEFAULT;
+       }
+       return 1;
+}
+
+int ospf_area_nssa_unset(struct ospf *ospf, struct in_addr area_id, int argc)
 {
        struct ospf_area *area;
 
@@ -1523,9 +1542,18 @@ int ospf_area_nssa_unset(struct ospf *ospf, struct in_addr area_id)
        if (area == NULL)
                return 0;
 
-       if (area->external_routing == OSPF_AREA_NSSA) {
+       /* argc < 5 -> 'no area x nssa' */
+       if (argc < 5 && area->external_routing == OSPF_AREA_NSSA) {
                ospf->anyNSSA--;
+               /* set NSSA area defaults */
+               area->no_summary = 0;
+               area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
+               area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
+               area->NSSATranslatorStabilityInterval =
+                       OSPF_NSSA_TRANS_STABLE_DEFAULT;
                ospf_area_type_set(area, OSPF_AREA_DEFAULT);
+       } else {
+               area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
        }
 
        ospf_area_check_free(ospf, area_id);
index 01147c20040aa6b9c931958551b547cc696714ec..4b0ebc8eb84d63d0d77ad30dff8b88d065b48e09 100644 (file)
@@ -524,7 +524,7 @@ extern int ospf_area_stub_unset(struct ospf *, struct in_addr);
 extern int ospf_area_no_summary_set(struct ospf *, struct in_addr);
 extern int ospf_area_no_summary_unset(struct ospf *, struct in_addr);
 extern int ospf_area_nssa_set(struct ospf *, struct in_addr);
-extern int ospf_area_nssa_unset(struct ospf *, struct in_addr);
+extern int ospf_area_nssa_unset(struct ospf *, struct in_addr, int);
 extern int ospf_area_nssa_translator_role_set(struct ospf *, struct in_addr,
                                              int);
 extern int ospf_area_export_list_set(struct ospf *, struct ospf_area *,
@@ -574,4 +574,6 @@ extern void ospf_vrf_terminate(void);
 extern void ospf_vrf_link(struct ospf *ospf, struct vrf *vrf);
 extern void ospf_vrf_unlink(struct ospf *ospf, struct vrf *vrf);
 const char *ospf_vrf_id_to_name(vrf_id_t vrf_id);
+int ospf_area_nssa_no_summary_set(struct ospf *, struct in_addr);
+
 #endif /* _ZEBRA_OSPFD_H */