From 3e13cb831047f79f4297003905b4bb6ead9406fa Mon Sep 17 00:00:00 2001 From: anlan_cs Date: Mon, 7 Feb 2022 21:25:28 +0800 Subject: [PATCH] ospfd: fix loss of mixed form in "range" command Currently "range" command can only accept `cost` or `substitute` individually, and `show running` will mix them. So need make it accept mixed form with both of them, otherwise configuration file in mixed form will fail to start. Signed-off-by: anlan_cs (cherry picked from commit ec88a72a375bc3a228cf2752b03e5aa22d8ef206) --- ospfd/ospf_vty.c | 53 +++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index da80b0ab59..a5bb6ae46b 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -652,20 +652,22 @@ DEFUN (ospf_area_range, DEFUN (ospf_area_range_cost, ospf_area_range_cost_cmd, - "area range A.B.C.D/M cost (0-16777215)", + "area range A.B.C.D/M {cost (0-16777215)|substitute A.B.C.D/M}", "OSPF area parameters\n" "OSPF area ID in IP address format\n" "OSPF area ID as a decimal value\n" "Summarize routes matching address/mask (border routers only)\n" "Area range prefix\n" "User specified metric for this range\n" - "Advertised metric for this range\n") + "Advertised metric for this range\n" + "Announce area range as another prefix\n" + "Network prefix to be announced instead of range\n") { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); int idx_ipv4_number = 1; int idx_ipv4_prefixlen = 3; - int idx_cost = 5; - struct prefix_ipv4 p; + int idx = 4; + struct prefix_ipv4 p, s; struct in_addr area_id; int format; uint32_t cost; @@ -677,8 +679,16 @@ DEFUN (ospf_area_range_cost, ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), format); - cost = strtoul(argv[idx_cost]->arg, NULL, 10); - ospf_area_range_cost_set(ospf, area_id, &p, cost); + if (argv_find(argv, argc, "cost", &idx)) { + cost = strtoul(argv[idx + 1]->arg, NULL, 10); + ospf_area_range_cost_set(ospf, area_id, &p, cost); + } + + idx = 4; + if (argv_find(argv, argc, "substitute", &idx)) { + str2prefix_ipv4(argv[idx + 1]->arg, &s); + ospf_area_range_substitute_set(ospf, area_id, &p, &s); + } return CMD_SUCCESS; } @@ -742,36 +752,6 @@ DEFUN (no_ospf_area_range, return CMD_SUCCESS; } -DEFUN (ospf_area_range_substitute, - ospf_area_range_substitute_cmd, - "area range A.B.C.D/M substitute A.B.C.D/M", - "OSPF area parameters\n" - "OSPF area ID in IP address format\n" - "OSPF area ID as a decimal value\n" - "Summarize routes matching address/mask (border routers only)\n" - "Area range prefix\n" - "Announce area range as another prefix\n" - "Network prefix to be announced instead of range\n") -{ - VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); - int idx_ipv4_number = 1; - int idx_ipv4_prefixlen = 3; - int idx_ipv4_prefixlen_2 = 5; - struct prefix_ipv4 p, s; - struct in_addr area_id; - int format; - - VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); - str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); - str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); - - ospf_area_range_substitute_set(ospf, area_id, &p, &s); - ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), - format); - - return CMD_SUCCESS; -} - DEFUN (no_ospf_area_range_substitute, no_ospf_area_range_substitute_cmd, "no area range A.B.C.D/M substitute A.B.C.D/M", @@ -12769,7 +12749,6 @@ void ospf_vty_init(void) install_element(OSPF_NODE, &ospf_area_range_cost_cmd); install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd); install_element(OSPF_NODE, &no_ospf_area_range_cmd); - install_element(OSPF_NODE, &ospf_area_range_substitute_cmd); install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd); /* "area virtual-link" commands. */