From d48ef099db433a5d0be9d1584af346e015e84991 Mon Sep 17 00:00:00 2001 From: harios_niral Date: Wed, 5 May 2021 23:19:01 +0300 Subject: [PATCH] ospf6d: add vty support for multiple vrfs Co-authored-by: Kaushik Nath Signed-off-by: harios_niral --- ospf6d/ospf6_area.c | 194 ++++--- ospf6d/ospf6_asbr.c | 71 +-- ospf6d/ospf6_interface.c | 279 ++++++---- ospf6d/ospf6_neighbor.c | 108 ++-- ospf6d/ospf6_top.c | 263 ++++++---- ospf6d/ospf6d.c | 1053 ++++++++++++++++++++++++-------------- ospf6d/ospf6d.h | 12 +- vtysh/vtysh.c | 4 +- 8 files changed, 1276 insertions(+), 708 deletions(-) diff --git a/ospf6d/ospf6_area.c b/ospf6d/ospf6_area.c index 6bf61b4804..c38ce09a27 100644 --- a/ospf6d/ospf6_area.c +++ b/ospf6d/ospf6_area.c @@ -851,34 +851,21 @@ DEFUN (no_area_export_list, return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_spf_tree, - show_ipv6_ospf6_spf_tree_cmd, - "show ipv6 ospf6 spf tree [json]", - SHOW_STR - IP6_STR - OSPF6_STR - "Shortest Path First calculation\n" - "Show SPF tree\n" - JSON_STR) +static int ipv6_ospf6_spf_tree_common(struct vty *vty, struct ospf6 *ospf6, + bool uj) { struct listnode *node; struct ospf6_area *oa; + struct prefix prefix; struct ospf6_vertex *root; struct ospf6_route *route; - struct prefix prefix; - struct ospf6 *ospf6; json_object *json = NULL; json_object *json_area = NULL; json_object *json_head = NULL; - bool uj = use_json(argc, argv); - - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); if (uj) json = json_object_new_object(); ospf6_linkstate_prefix(ospf6->router_id, htonl(0), &prefix); - for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) { if (uj) { json_area = json_object_new_object(); @@ -918,35 +905,47 @@ DEFUN (show_ipv6_ospf6_spf_tree, return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_area_spf_tree, - show_ipv6_ospf6_area_spf_tree_cmd, - "show ipv6 ospf6 area A.B.C.D spf tree", - SHOW_STR - IP6_STR - OSPF6_STR - OSPF6_AREA_STR - OSPF6_AREA_ID_STR - "Shortest Path First calculation\n" - "Show SPF tree\n") +DEFUN(show_ipv6_ospf6_spf_tree, show_ipv6_ospf6_spf_tree_cmd, + "show ipv6 ospf6 [vrf ] spf tree [json]", + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Shortest Path First calculation\n" + "Show SPF tree\n" JSON_STR) { - int idx_ipv4 = 4; - uint32_t area_id; - struct ospf6_area *oa; - struct ospf6_vertex *root; - struct ospf6_route *route; - struct prefix prefix; + struct listnode *node; struct ospf6 *ospf6; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + bool uj = use_json(argc, argv); - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ipv6_ospf6_spf_tree_common(vty, ospf6, uj); + if (!all_vrf) + break; + } + } + + return CMD_SUCCESS; +} + +static int show_ospf6_area_spf_tree_common(struct vty *vty, + struct cmd_token **argv, + struct ospf6 *ospf6, + uint32_t area_id, int idx_ipv4) +{ - OSPF6_CMD_CHECK_RUNNING(ospf6); + struct ospf6_area *oa; + struct prefix prefix; + struct ospf6_vertex *root; + struct ospf6_route *route; ospf6_linkstate_prefix(ospf6->router_id, htonl(0), &prefix); - if (inet_pton(AF_INET, argv[idx_ipv4]->arg, &area_id) != 1) { - vty_out(vty, "Malformed Area-ID: %s\n", argv[idx_ipv4]->arg); - return CMD_SUCCESS; - } oa = ospf6_area_lookup(area_id, ospf6); if (oa == NULL) { vty_out(vty, "No such Area: %s\n", argv[idx_ipv4]->arg); @@ -965,41 +964,55 @@ DEFUN (show_ipv6_ospf6_area_spf_tree, return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_simulate_spf_tree_root, - show_ipv6_ospf6_simulate_spf_tree_root_cmd, - "show ipv6 ospf6 simulate spf-tree A.B.C.D area A.B.C.D", - SHOW_STR - IP6_STR - OSPF6_STR - "Shortest Path First calculation\n" - "Show SPF tree\n" - "Specify root's router-id to calculate another router's SPF tree\n" - "OSPF6 area parameters\n" - OSPF6_AREA_ID_STR) +DEFUN(show_ipv6_ospf6_area_spf_tree, show_ipv6_ospf6_area_spf_tree_cmd, + "show ipv6 ospf6 [vrf ] area A.B.C.D spf tree", + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" OSPF6_AREA_STR OSPF6_AREA_ID_STR + "Shortest Path First calculation\n" + "Show SPF tree\n") { - int idx_ipv4 = 5; - int idx_ipv4_2 = 7; + int idx_ipv4 = 4; uint32_t area_id; + struct ospf6 *ospf6; + struct listnode *node; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) + idx_ipv4 += 2; + + if (inet_pton(AF_INET, argv[idx_ipv4]->arg, &area_id) != 1) { + vty_out(vty, "Malformed Area-ID: %s\n", argv[idx_ipv4]->arg); + return CMD_SUCCESS; + } + + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + show_ospf6_area_spf_tree_common(vty, argv, ospf6, + area_id, idx_ipv4); + if (!all_vrf) + break; + } + } + + return CMD_SUCCESS; +} + +static int +show_ospf6_simulate_spf_tree_commen(struct vty *vty, struct cmd_token **argv, + struct ospf6 *ospf6, uint32_t router_id, + uint32_t area_id, struct prefix prefix, + int idx_ipv4, int idx_ipv4_2) +{ struct ospf6_area *oa; struct ospf6_vertex *root; struct ospf6_route *route; - struct prefix prefix; - uint32_t router_id; struct ospf6_route_table *spf_table; unsigned char tmp_debug_ospf6_spf = 0; - struct ospf6 *ospf6; - - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - - OSPF6_CMD_CHECK_RUNNING(ospf6); - inet_pton(AF_INET, argv[idx_ipv4]->arg, &router_id); - ospf6_linkstate_prefix(router_id, htonl(0), &prefix); - - if (inet_pton(AF_INET, argv[idx_ipv4_2]->arg, &area_id) != 1) { - vty_out(vty, "Malformed Area-ID: %s\n", argv[idx_ipv4_2]->arg); - return CMD_SUCCESS; - } oa = ospf6_area_lookup(area_id, ospf6); if (oa == NULL) { vty_out(vty, "No such Area: %s\n", argv[idx_ipv4_2]->arg); @@ -1029,6 +1042,54 @@ DEFUN (show_ipv6_ospf6_simulate_spf_tree_root, return CMD_SUCCESS; } +DEFUN(show_ipv6_ospf6_simulate_spf_tree_root, + show_ipv6_ospf6_simulate_spf_tree_root_cmd, + "show ipv6 ospf6 [vrf ] simulate spf-tree A.B.C.D area A.B.C.D", + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Shortest Path First calculation\n" + "Show SPF tree\n" + "Specify root's router-id to calculate another router's SPF tree\n" + "OSPF6 area parameters\n" OSPF6_AREA_ID_STR) +{ + int idx_ipv4 = 5; + int idx_ipv4_2 = 7; + uint32_t area_id; + struct prefix prefix; + uint32_t router_id; + struct ospf6 *ospf6; + struct listnode *node; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) { + idx_ipv4 += 2; + idx_ipv4_2 += 2; + } + inet_pton(AF_INET, argv[idx_ipv4]->arg, &router_id); + ospf6_linkstate_prefix(router_id, htonl(0), &prefix); + + if (inet_pton(AF_INET, argv[idx_ipv4_2]->arg, &area_id) != 1) { + vty_out(vty, "Malformed Area-ID: %s\n", argv[idx_ipv4_2]->arg); + return CMD_SUCCESS; + } + + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + show_ospf6_simulate_spf_tree_commen( + vty, argv, ospf6, router_id, area_id, prefix, + idx_ipv4, idx_ipv4_2); + if (!all_vrf) + break; + } + } + + return CMD_SUCCESS; +} + DEFUN (ospf6_area_stub, ospf6_area_stub_cmd, "area stub", @@ -1158,8 +1219,9 @@ void ospf6_area_interface_delete(struct ospf6_interface *oi) if (!om6->ospf6) return; - for (ALL_LIST_ELEMENTS(om6->ospf6, node, nnode, ospf6)) + for (ALL_LIST_ELEMENTS(om6->ospf6, node, nnode, ospf6)) { for (ALL_LIST_ELEMENTS(ospf6->area_list, node, nnode, oa)) if (listnode_lookup(oa->if_list, oi)) listnode_delete(oa->if_list, oi); + } } diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index ffd6dc22c3..c37d89bcb8 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -41,6 +41,7 @@ #include "ospf6_spf.h" #include "ospf6_top.h" +#include "ospf6d.h" #include "ospf6_area.h" #include "ospf6_interface.h" #include "ospf6_neighbor.h" @@ -1397,7 +1398,7 @@ DEFUN (ospf6_redistribute, struct ospf6_redist *red; VTY_DECLVAR_CONTEXT(ospf6, ospf6); - OSPF6_CMD_CHECK_RUNNING(ospf6); + char *proto = argv[argc - 1]->text; type = proto_redistnum(AFI_IP6, proto); if (type < 0) @@ -1427,7 +1428,6 @@ DEFUN (ospf6_redistribute_routemap, struct ospf6_redist *red; VTY_DECLVAR_CONTEXT(ospf6, ospf6); - OSPF6_CMD_CHECK_RUNNING(ospf6); char *proto = argv[idx_protocol]->text; type = proto_redistnum(AFI_IP6, proto); @@ -1460,8 +1460,6 @@ DEFUN (no_ospf6_redistribute, VTY_DECLVAR_CONTEXT(ospf6, ospf6); - OSPF6_CMD_CHECK_RUNNING(ospf6); - char *proto = argv[idx_protocol]->text; type = proto_redistnum(AFI_IP6, proto); if (type < 0) @@ -1639,8 +1637,6 @@ DEFPY (ospf6_default_route_originate, int cur_originate = ospf6->default_originate; - OSPF6_CMD_CHECK_RUNNING(ospf6); - red = ospf6_redist_add(ospf6, DEFAULT_ROUTE, 0); if (always != NULL) @@ -1696,8 +1692,6 @@ DEFPY (no_ospf6_default_information_originate, VTY_DECLVAR_CONTEXT(ospf6, ospf6); - OSPF6_CMD_CHECK_RUNNING(ospf6); - red = ospf6_redist_lookup(ospf6, DEFAULT_ROUTE, 0); if (!red) return CMD_SUCCESS; @@ -2215,46 +2209,61 @@ static void ospf6_asbr_external_route_show(struct vty *vty, forwarding); } -DEFUN (show_ipv6_ospf6_redistribute, - show_ipv6_ospf6_redistribute_cmd, - "show ipv6 ospf6 redistribute [json]", - SHOW_STR - IP6_STR - OSPF6_STR - "redistributing External information\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_redistribute, show_ipv6_ospf6_redistribute_cmd, + "show ipv6 ospf6 [vrf ] redistribute [json]", + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "redistributing External information\n" JSON_STR) { struct ospf6_route *route; struct ospf6 *ospf6 = NULL; json_object *json = NULL; bool uj = use_json(argc, argv); + struct listnode *node; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + json_object *json_array_routes = NULL; json_object *json_array_redistribute = NULL; - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); if (uj) { json = json_object_new_object(); json_array_routes = json_object_new_array(); json_array_redistribute = json_object_new_array(); } - ospf6_redistribute_show_config(vty, ospf6, json_array_redistribute, - json, uj); - for (route = ospf6_route_head(ospf6->external_table); route; - route = ospf6_route_next(route)) { - ospf6_asbr_external_route_show(vty, route, json_array_routes, - uj); - } + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf + || ((ospf6->name == NULL && vrf_name == NULL) + || (ospf6->name && vrf_name + && strcmp(ospf6->name, vrf_name) == 0))) { + ospf6_redistribute_show_config( + vty, ospf6, json_array_redistribute, json, uj); + + for (route = ospf6_route_head(ospf6->external_table); + route; route = ospf6_route_next(route)) { + ospf6_asbr_external_route_show( + vty, route, json_array_routes, uj); + } - if (uj) { - json_object_object_add(json, "routes", json_array_routes); - vty_out(vty, "%s\n", - json_object_to_json_string_ext( - json, JSON_C_TO_STRING_PRETTY)); - json_object_free(json); + if (uj) { + json_object_object_add(json, "routes", + json_array_routes); + vty_out(vty, "%s\n", + json_object_to_json_string_ext( + json, JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + } + + if (!all_vrf) + break; + } } + return CMD_SUCCESS; } diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index f3af8b308f..02c8c99d9c 100644 --- a/ospf6d/ospf6_interface.c +++ b/ospf6d/ospf6_interface.c @@ -1175,19 +1175,13 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, return 0; } -/* show interface */ -DEFUN(show_ipv6_ospf6_interface, - show_ipv6_ospf6_interface_ifname_cmd, - "show ipv6 ospf6 interface [IFNAME] [json]", - SHOW_STR - IP6_STR - OSPF6_STR - INTERFACE_STR - IFNAME_STR - JSON_STR) +static int show_ospf6_interface_common(struct vty *vty, vrf_id_t vrf_id, + int argc, struct cmd_token **argv, + int idx_ifname, int intf_idx, + int json_idx) { - struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); - int idx_ifname = 4; + + struct vrf *vrf = vrf_lookup_by_id(vrf_id); struct interface *ifp; json_object *json; json_object *json_int; @@ -1195,9 +1189,8 @@ DEFUN(show_ipv6_ospf6_interface, if (uj) { json = json_object_new_object(); - if (argc == 6) { - ifp = if_lookup_by_name(argv[idx_ifname]->arg, - VRF_DEFAULT); + if (argc == json_idx) { + ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); json_int = json_object_new_object(); if (ifp == NULL) { json_object_string_add(json, "noSuchInterface", @@ -1224,9 +1217,8 @@ DEFUN(show_ipv6_ospf6_interface, json, JSON_C_TO_STRING_PRETTY)); json_object_free(json); } else { - if (argc == 5) { - ifp = if_lookup_by_name(argv[idx_ifname]->arg, - VRF_DEFAULT); + if (argc == intf_idx) { + ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); if (ifp == NULL) { vty_out(vty, "No such Interface: %s\n", argv[idx_ifname]->arg); @@ -1238,6 +1230,42 @@ DEFUN(show_ipv6_ospf6_interface, ospf6_interface_show(vty, ifp, NULL, uj); } } + return CMD_SUCCESS; +} + +/* show interface */ +DEFUN(show_ipv6_ospf6_interface, show_ipv6_ospf6_interface_ifname_cmd, + "show ipv6 ospf6 [vrf ] interface [IFNAME] [json]", + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" INTERFACE_STR IFNAME_STR JSON_STR) +{ + int idx_ifname = 4; + int intf_idx = 5; + int json_idx = 6; + struct listnode *node; + struct ospf6 *ospf6; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) { + idx_ifname += 2; + intf_idx += 2; + json_idx += 2; + } + + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + show_ospf6_interface_common(vty, ospf6->vrf_id, argc, + argv, idx_ifname, intf_idx, + json_idx); + + if (!all_vrf) + break; + } + } return CMD_SUCCESS; } @@ -1245,7 +1273,7 @@ DEFUN(show_ipv6_ospf6_interface, static int ospf6_interface_show_traffic(struct vty *vty, struct interface *intf_ifp, int display_once, json_object *json, - bool use_json) + bool use_json, vrf_id_t vrf_id) { struct interface *ifp; struct vrf *vrf = NULL; @@ -1255,7 +1283,7 @@ static int ospf6_interface_show_traffic(struct vty *vty, if (intf_ifp) vrf = vrf_lookup_by_id(intf_ifp->vrf_id); else - vrf = vrf_lookup_by_id(VRF_DEFAULT); + vrf = vrf_lookup_by_id(vrf_id); if (!display_once && !use_json) { vty_out(vty, "\n"); @@ -1356,17 +1384,9 @@ static int ospf6_interface_show_traffic(struct vty *vty, return CMD_SUCCESS; } -/* show interface */ -DEFUN(show_ipv6_ospf6_interface_traffic, - show_ipv6_ospf6_interface_traffic_cmd, - "show ipv6 ospf6 interface traffic [IFNAME] [json]", - SHOW_STR - IP6_STR - OSPF6_STR - INTERFACE_STR - "Protocol Packet counters\n" - IFNAME_STR - JSON_STR) +static int ospf6_interface_show_traffic_common(struct vty *vty, int argc, + struct cmd_token **argv, + vrf_id_t vrf_id) { int idx_ifname = 0; int display_once = 0; @@ -1380,7 +1400,7 @@ DEFUN(show_ipv6_ospf6_interface_traffic, if (argv_find(argv, argc, "IFNAME", &idx_ifname)) { intf_name = argv[idx_ifname]->arg; - ifp = if_lookup_by_name(intf_name, VRF_DEFAULT); + ifp = if_lookup_by_name(intf_name, vrf_id); if (uj) { if (ifp == NULL) { json_object_string_add(json, "status", @@ -1420,7 +1440,7 @@ DEFUN(show_ipv6_ospf6_interface_traffic, } } - ospf6_interface_show_traffic(vty, ifp, display_once, json, uj); + ospf6_interface_show_traffic(vty, ifp, display_once, json, uj, vrf_id); if (uj) { vty_out(vty, "%s\n", @@ -1429,94 +1449,148 @@ DEFUN(show_ipv6_ospf6_interface_traffic, json_object_free(json); } + return CMD_SUCCESS; +} + +/* show interface */ +DEFUN(show_ipv6_ospf6_interface_traffic, show_ipv6_ospf6_interface_traffic_cmd, + "show ipv6 ospf6 [vrf ] interface traffic [IFNAME] [json]", + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" INTERFACE_STR + "Protocol Packet counters\n" IFNAME_STR JSON_STR) +{ + struct ospf6 *ospf6; + struct listnode *node; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_interface_show_traffic_common(vty, argc, argv, + ospf6->vrf_id); + + if (!all_vrf) + break; + } + } return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_interface_ifname_prefix, - show_ipv6_ospf6_interface_ifname_prefix_cmd, - "show ipv6 ospf6 interface IFNAME prefix\ +DEFUN(show_ipv6_ospf6_interface_ifname_prefix, + show_ipv6_ospf6_interface_ifname_prefix_cmd, + "show ipv6 ospf6 [vrf ] interface IFNAME prefix\ [<\ detail\ | []\ >] [json]", - SHOW_STR - IP6_STR - OSPF6_STR - INTERFACE_STR - IFNAME_STR - "Display connected prefixes to advertise\n" - "Display details of the prefixes\n" - OSPF6_ROUTE_ADDRESS_STR - OSPF6_ROUTE_PREFIX_STR - OSPF6_ROUTE_MATCH_STR - "Display details of the prefixes\n" - JSON_STR) + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" INTERFACE_STR IFNAME_STR + "Display connected prefixes to advertise\n" + "Display details of the prefixes\n" OSPF6_ROUTE_ADDRESS_STR + OSPF6_ROUTE_PREFIX_STR OSPF6_ROUTE_MATCH_STR + "Display details of the prefixes\n" JSON_STR) { int idx_ifname = 4; int idx_prefix = 6; - struct interface *ifp; struct ospf6_interface *oi; bool uj = use_json(argc, argv); - ifp = if_lookup_by_name(argv[idx_ifname]->arg, VRF_DEFAULT); - if (ifp == NULL) { - vty_out(vty, "No such Interface: %s\n", argv[idx_ifname]->arg); - return CMD_WARNING; + struct ospf6 *ospf6; + struct listnode *node; + struct interface *ifp; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) { + idx_ifname += 2; + idx_prefix += 2; } - oi = ifp->info; - if (oi == NULL) { - vty_out(vty, "OSPFv3 is not enabled on %s\n", - argv[idx_ifname]->arg); - return CMD_WARNING; - } + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ifp = if_lookup_by_name(argv[idx_ifname]->arg, + ospf6->vrf_id); + if (ifp == NULL) { + vty_out(vty, "No such Interface: %s\n", + argv[idx_ifname]->arg); + return CMD_WARNING; + } - if (CHECK_FLAG(oi->flag, OSPF6_INTERFACE_DISABLE)) { - vty_out(vty, "Interface %s not attached to area\n", - argv[idx_ifname]->arg); - return CMD_WARNING; - } + oi = ifp->info; + if (oi == NULL + || CHECK_FLAG(oi->flag, OSPF6_INTERFACE_DISABLE)) { + vty_out(vty, + "Interface %s not attached to area\n", + argv[idx_ifname]->arg); + return CMD_WARNING; + } + + ospf6_route_table_show(vty, idx_prefix, argc, argv, + oi->route_connected, uj); - ospf6_route_table_show(vty, idx_prefix, argc, argv, oi->route_connected, - uj); + if (!all_vrf) + break; + } + } return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_interface_prefix, - show_ipv6_ospf6_interface_prefix_cmd, - "show ipv6 ospf6 interface prefix\ +DEFUN(show_ipv6_ospf6_interface_prefix, show_ipv6_ospf6_interface_prefix_cmd, + "show ipv6 ospf6 [vrf ] interface prefix\ [<\ detail\ | []\ >] [json]", - SHOW_STR - IP6_STR - OSPF6_STR - INTERFACE_STR - "Display connected prefixes to advertise\n" - "Display details of the prefixes\n" - OSPF6_ROUTE_ADDRESS_STR - OSPF6_ROUTE_PREFIX_STR - OSPF6_ROUTE_MATCH_STR - "Display details of the prefixes\n" - JSON_STR) + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" INTERFACE_STR + "Display connected prefixes to advertise\n" + "Display details of the prefixes\n" OSPF6_ROUTE_ADDRESS_STR + OSPF6_ROUTE_PREFIX_STR OSPF6_ROUTE_MATCH_STR + "Display details of the prefixes\n" JSON_STR) { - struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); + struct vrf *vrf = NULL; int idx_prefix = 5; struct ospf6_interface *oi; struct interface *ifp; bool uj = use_json(argc, argv); - - FOR_ALL_INTERFACES (vrf, ifp) { - oi = (struct ospf6_interface *)ifp->info; - if (oi == NULL || CHECK_FLAG(oi->flag, OSPF6_INTERFACE_DISABLE)) - continue; - - ospf6_route_table_show(vty, idx_prefix, argc, argv, - oi->route_connected, uj); + struct listnode *node; + struct ospf6 *ospf6; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) + idx_prefix += 2; + + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + vrf = vrf_lookup_by_id(ospf6->vrf_id); + FOR_ALL_INTERFACES (vrf, ifp) { + oi = (struct ospf6_interface *)ifp->info; + if (oi == NULL + || CHECK_FLAG(oi->flag, + OSPF6_INTERFACE_DISABLE)) + continue; + + ospf6_route_table_show(vty, idx_prefix, argc, + argv, + oi->route_connected, uj); + } + if (!all_vrf) + break; + } } return CMD_SUCCESS; @@ -2211,9 +2285,8 @@ DEFUN (no_ipv6_ospf6_network, return CMD_SUCCESS; } -static int config_write_ospf6_interface(struct vty *vty) +static int config_write_ospf6_interface(struct vty *vty, struct vrf *vrf) { - struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct ospf6_interface *oi; struct interface *ifp; @@ -2222,7 +2295,11 @@ static int config_write_ospf6_interface(struct vty *vty) if (oi == NULL) continue; - vty_frame(vty, "interface %s\n", oi->interface->name); + if (vrf->vrf_id == VRF_DEFAULT) + vty_frame(vty, "interface %s\n", oi->interface->name); + else + vty_frame(vty, "interface %s vrf %s\n", + oi->interface->name, vrf->name); if (ifp->desc) vty_out(vty, " description %s\n", ifp->desc); @@ -2277,13 +2354,27 @@ static int config_write_ospf6_interface(struct vty *vty) return 0; } -static int config_write_ospf6_interface(struct vty *vty); +/* Configuration write function for ospfd. */ +static int config_write_interface(struct vty *vty) +{ + int write = 0; + struct vrf *vrf = NULL; + + /* Display all VRF aware OSPF interface configuration */ + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { + write += config_write_ospf6_interface(vty, vrf); + } + + return write; +} + +static int config_write_ospf6_interface(struct vty *vty, struct vrf *vrf); static struct cmd_node interface_node = { .name = "interface", .node = INTERFACE_NODE, .parent_node = CONFIG_NODE, .prompt = "%s(config-if)# ", - .config_write = config_write_ospf6_interface, + .config_write = config_write_interface, }; static int ospf6_ifp_create(struct interface *ifp) diff --git a/ospf6d/ospf6_neighbor.c b/ospf6d/ospf6_neighbor.c index b35d8bf975..9323da8be3 100644 --- a/ospf6d/ospf6_neighbor.c +++ b/ospf6d/ospf6_neighbor.c @@ -969,35 +969,24 @@ static void ospf6_neighbor_show_detail(struct vty *vty, } } -DEFUN (show_ipv6_ospf6_neighbor, - show_ipv6_ospf6_neighbor_cmd, - "show ipv6 ospf6 neighbor [] [json]", - SHOW_STR - IP6_STR - OSPF6_STR - "Neighbor list\n" - "Display details\n" - "Display DR choices\n" - JSON_STR) +static void ospf6_neighbor_show_detail_common(struct vty *vty, int argc, + struct cmd_token **argv, + struct ospf6 *ospf6, int idx_type, + int detail_idx, int json_idx) { - int idx_type = 4; struct ospf6_neighbor *on; struct ospf6_interface *oi; struct ospf6_area *oa; struct listnode *i, *j, *k; - struct ospf6 *ospf6; json_object *json = NULL; json_object *json_array = NULL; bool uj = use_json(argc, argv); void (*showfunc)(struct vty *, struct ospf6_neighbor *, json_object *json, bool use_json); - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - - OSPF6_CMD_CHECK_RUNNING(ospf6); showfunc = ospf6_neighbor_show; - if ((uj && argc == 6) || (!uj && argc == 5)) { + if ((uj && argc == detail_idx) || (!uj && argc == json_idx)) { if (!strncmp(argv[idx_type]->arg, "de", 2)) showfunc = ospf6_neighbor_show_detail; else if (!strncmp(argv[idx_type]->arg, "dr", 2)) @@ -1037,21 +1026,50 @@ DEFUN (show_ipv6_ospf6_neighbor, json, JSON_C_TO_STRING_PRETTY)); json_object_free(json); } - return CMD_SUCCESS; } +DEFUN(show_ipv6_ospf6_neighbor, show_ipv6_ospf6_neighbor_cmd, + "show ipv6 ospf6 [vrf ] neighbor [] [json]", + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Neighbor list\n" + "Display details\n" + "Display DR choices\n" JSON_STR) +{ + int idx_type = 4; + int detail_idx = 5; + int json_idx = 6; + struct ospf6 *ospf6; + struct listnode *node; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) { + idx_type += 2; + detail_idx += 2; + json_idx += 2; + } + + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_neighbor_show_detail_common(vty, argc, argv, + ospf6, idx_type, + detail_idx, json_idx); + if (!all_vrf) + break; + } + } -DEFUN (show_ipv6_ospf6_neighbor_one, - show_ipv6_ospf6_neighbor_one_cmd, - "show ipv6 ospf6 neighbor A.B.C.D [json]", - SHOW_STR - IP6_STR - OSPF6_STR - "Neighbor list\n" - "Specify Router-ID as IPv4 address notation\n" - JSON_STR) + return CMD_SUCCESS; +} + +static int ospf6_neighbor_show_common(struct vty *vty, int argc, + struct cmd_token **argv, + struct ospf6 *ospf6, int idx_ipv4) { - int idx_ipv4 = 4; struct ospf6_neighbor *on; struct ospf6_interface *oi; struct ospf6_area *oa; @@ -1059,12 +1077,9 @@ DEFUN (show_ipv6_ospf6_neighbor_one, void (*showfunc)(struct vty *, struct ospf6_neighbor *, json_object *json, bool use_json); uint32_t router_id; - struct ospf6 *ospf6; json_object *json = NULL; bool uj = use_json(argc, argv); - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); showfunc = ospf6_neighbor_show_detail; if (uj) json = json_object_new_object(); @@ -1088,6 +1103,39 @@ DEFUN (show_ipv6_ospf6_neighbor_one, json, JSON_C_TO_STRING_PRETTY)); json_object_free(json); } + + return CMD_SUCCESS; +} + +DEFUN(show_ipv6_ospf6_neighbor_one, show_ipv6_ospf6_neighbor_one_cmd, + "show ipv6 ospf6 [vrf ] neighbor A.B.C.D [json]", + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Neighbor list\n" + "Specify Router-ID as IPv4 address notation\n" JSON_STR) +{ + int idx_ipv4 = 4; + struct ospf6 *ospf6; + struct listnode *node; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) + idx_ipv4 += 2; + + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_neighbor_show_common(vty, argc, argv, ospf6, + idx_ipv4); + + if (!all_vrf) + break; + } + } + return CMD_SUCCESS; } diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c index 5d26c513f6..3ab0f1fbb6 100644 --- a/ospf6d/ospf6_top.c +++ b/ospf6d/ospf6_top.c @@ -539,17 +539,20 @@ void ospf6_router_id_update(struct ospf6 *ospf6) } /* start ospf6 */ -DEFUN_NOSH (router_ospf6, - router_ospf6_cmd, - "router ospf6", - ROUTER_STR - OSPF6_STR) +DEFUN_NOSH(router_ospf6, router_ospf6_cmd, "router ospf6 [vrf NAME]", + ROUTER_STR OSPF6_STR VRF_CMD_HELP_STR) { struct ospf6 *ospf6; + const char *vrf_name = VRF_DEFAULT_NAME; + int idx_vrf = 0; - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); + if (argv_find(argv, argc, "vrf", &idx_vrf)) { + vrf_name = argv[idx_vrf + 1]->arg; + } + + ospf6 = ospf6_lookup_by_vrf_name(vrf_name); if (ospf6 == NULL) - ospf6 = ospf6_instance_create(VRF_DEFAULT_NAME); + ospf6 = ospf6_instance_create(vrf_name); /* set current ospf point. */ VTY_PUSH_CONTEXT(OSPF6_NODE, ospf6); @@ -558,16 +561,18 @@ DEFUN_NOSH (router_ospf6, } /* stop ospf6 */ -DEFUN (no_router_ospf6, - no_router_ospf6_cmd, - "no router ospf6", - NO_STR - ROUTER_STR - OSPF6_STR) +DEFUN(no_router_ospf6, no_router_ospf6_cmd, "no router ospf6 [vrf NAME]", + NO_STR ROUTER_STR OSPF6_STR VRF_CMD_HELP_STR) { struct ospf6 *ospf6; + const char *vrf_name = VRF_DEFAULT_NAME; + int idx_vrf = 0; - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); + if (argv_find(argv, argc, "vrf", &idx_vrf)) { + vrf_name = argv[idx_vrf + 1]->arg; + } + + ospf6 = ospf6_lookup_by_vrf_name(vrf_name); if (ospf6 == NULL) vty_out(vty, "OSPFv3 is not configured\n"); else { @@ -838,16 +843,19 @@ DEFUN (ospf6_interface_area, "OSPF6 area ID in decimal notation\n" ) { + VTY_DECLVAR_CONTEXT(ospf6, ospf6); int idx_ifname = 1; int idx_ipv4 = 3; struct ospf6_area *oa; struct ospf6_interface *oi; struct interface *ifp; + vrf_id_t vrf_id = VRF_DEFAULT; - VTY_DECLVAR_CONTEXT(ospf6, ospf6); + if (ospf6->vrf_id != VRF_UNKNOWN) + vrf_id = ospf6->vrf_id; /* find/create ospf6 interface */ - ifp = if_get_by_name(argv[idx_ifname]->arg, VRF_DEFAULT); + ifp = if_get_by_name(argv[idx_ifname]->arg, vrf_id); oi = (struct ospf6_interface *)ifp->info; if (oi == NULL) oi = ospf6_interface_create(ifp); @@ -891,14 +899,21 @@ DEFUN (no_ospf6_interface_area, "OSPF6 area ID in decimal notation\n" ) { + VTY_DECLVAR_CONTEXT(ospf6, ospf6); int idx_ifname = 2; int idx_ipv4 = 4; struct ospf6_interface *oi; struct ospf6_area *oa; struct interface *ifp; uint32_t area_id; + vrf_id_t vrf_id = VRF_DEFAULT; + + if (ospf6->vrf_id != VRF_UNKNOWN) + vrf_id = ospf6->vrf_id; + + /* find/create ospf6 interface */ + ifp = if_get_by_name(argv[idx_ifname]->arg, vrf_id); - ifp = if_lookup_by_name(argv[idx_ifname]->arg, VRF_DEFAULT); if (ifp == NULL) { vty_out(vty, "No such interface %s\n", argv[idx_ifname]->arg); return CMD_SUCCESS; @@ -1297,124 +1312,180 @@ DEFUN(show_ipv6_ospf6_vrfs, show_ipv6_ospf6_vrfs_cmd, } /* show top level structures */ -DEFUN(show_ipv6_ospf6, - show_ipv6_ospf6_cmd, - "show ipv6 ospf6 [json]", - SHOW_STR - IP6_STR - OSPF6_STR - JSON_STR) +DEFUN(show_ipv6_ospf6, show_ipv6_ospf6_cmd, + "show ipv6 ospf6 [vrf ] [json]", + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR "All VRFs\n" JSON_STR) { struct ospf6 *ospf6; + struct listnode *node; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + bool uj = use_json(argc, argv); json_object *json = NULL; - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); - if (uj) - json = json_object_new_object(); + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + if (uj) + json = json_object_new_object(); + ospf6_show(vty, ospf6, json, uj); - ospf6_show(vty, ospf6, json, uj); + if (!all_vrf) + break; + } + } if (uj) json_object_free(json); + return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_route, - show_ipv6_ospf6_route_cmd, - "show ipv6 ospf6 route [] [json]", - SHOW_STR - IP6_STR - OSPF6_STR - ROUTE_STR - "Display Intra-Area routes\n" - "Display Inter-Area routes\n" - "Display Type-1 External routes\n" - "Display Type-2 External routes\n" - "Specify IPv6 address\n" - "Specify IPv6 prefix\n" - "Detailed information\n" - "Summary of route table\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_route, show_ipv6_ospf6_route_cmd, + "show ipv6 ospf6 [vrf ] route [] [json]", + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" ROUTE_STR + "Display Intra-Area routes\n" + "Display Inter-Area routes\n" + "Display Type-1 External routes\n" + "Display Type-2 External routes\n" + "Specify IPv6 address\n" + "Specify IPv6 prefix\n" + "Detailed information\n" + "Summary of route table\n" JSON_STR) { struct ospf6 *ospf6; + struct listnode *node; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + int idx_arg_start = 4; bool uj = use_json(argc, argv); - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) + idx_arg_start += 2; + + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_route_table_show(vty, idx_arg_start, argc, argv, + ospf6->route_table, uj); + + if (!all_vrf) + break; + } + } - ospf6_route_table_show(vty, 4, argc, argv, ospf6->route_table, uj); return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_route_match, - show_ipv6_ospf6_route_match_cmd, - "show ipv6 ospf6 route X:X::X:X/M [json]", - SHOW_STR - IP6_STR - OSPF6_STR - ROUTE_STR - "Specify IPv6 prefix\n" - "Display routes which match the specified route\n" - "Display routes longer than the specified route\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_route_match, show_ipv6_ospf6_route_match_cmd, + "show ipv6 ospf6 [vrf ] route X:X::X:X/M [json]", + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" ROUTE_STR + "Specify IPv6 prefix\n" + "Display routes which match the specified route\n" + "Display routes longer than the specified route\n" JSON_STR) { struct ospf6 *ospf6; + struct listnode *node; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + int idx_start_arg = 4; bool uj = use_json(argc, argv); - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) + idx_start_arg += 2; + + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_route_table_show(vty, idx_start_arg, argc, argv, + ospf6->route_table, uj); + + if (!all_vrf) + break; + } + } - ospf6_route_table_show(vty, 4, argc, argv, ospf6->route_table, uj); return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_route_match_detail, - show_ipv6_ospf6_route_match_detail_cmd, - "show ipv6 ospf6 route X:X::X:X/M match detail [json]", - SHOW_STR - IP6_STR - OSPF6_STR - ROUTE_STR - "Specify IPv6 prefix\n" - "Display routes which match the specified route\n" - "Detailed information\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_route_match_detail, + show_ipv6_ospf6_route_match_detail_cmd, + "show ipv6 ospf6 [vrf ] route X:X::X:X/M match detail [json]", + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" ROUTE_STR + "Specify IPv6 prefix\n" + "Display routes which match the specified route\n" + "Detailed information\n" JSON_STR) { struct ospf6 *ospf6; + struct listnode *node; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + int idx_start_arg = 4; bool uj = use_json(argc, argv); - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) + idx_start_arg += 2; + + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_route_table_show(vty, idx_start_arg, argc, argv, + ospf6->route_table, uj); + + if (!all_vrf) + break; + } + } - ospf6_route_table_show(vty, 4, argc, argv, ospf6->route_table, uj); return CMD_SUCCESS; } - -DEFUN (show_ipv6_ospf6_route_type_detail, - show_ipv6_ospf6_route_type_detail_cmd, - "show ipv6 ospf6 route detail [json]", - SHOW_STR - IP6_STR - OSPF6_STR - ROUTE_STR - "Display Intra-Area routes\n" - "Display Inter-Area routes\n" - "Display Type-1 External routes\n" - "Display Type-2 External routes\n" - "Detailed information\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_route_type_detail, show_ipv6_ospf6_route_type_detail_cmd, + "show ipv6 ospf6 [vrf ] route detail [json]", + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" ROUTE_STR + "Display Intra-Area routes\n" + "Display Inter-Area routes\n" + "Display Type-1 External routes\n" + "Display Type-2 External routes\n" + "Detailed information\n" JSON_STR) { struct ospf6 *ospf6; + struct listnode *node; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + int idx_start_arg = 4; bool uj = use_json(argc, argv); - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) + idx_start_arg += 2; + + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_route_table_show(vty, idx_start_arg, argc, argv, + ospf6->route_table, uj); + + if (!all_vrf) + break; + } + } - ospf6_route_table_show(vty, 4, argc, argv, ospf6->route_table, uj); return CMD_SUCCESS; } @@ -1471,7 +1542,11 @@ static int config_write_ospf6(struct vty *vty) return CMD_SUCCESS; for (ALL_LIST_ELEMENTS(om6->ospf6, node, nnode, ospf6)) { - vty_out(vty, "router ospf6\n"); + if (ospf6->name && strcmp(ospf6->name, VRF_DEFAULT_NAME)) + vty_out(vty, "router ospf6 vrf %s\n", ospf6->name); + else + vty_out(vty, "router ospf6\n"); + if (ospf6->router_id_static != 0) vty_out(vty, " ospf6 router-id %pI4\n", &ospf6->router_id_static); diff --git a/ospf6d/ospf6d.c b/ospf6d/ospf6d.c index 91d427c78c..a2f27ec3b2 100644 --- a/ospf6d/ospf6d.c +++ b/ospf6d/ospf6d.c @@ -388,161 +388,190 @@ static void ospf6_lsdb_type_show_wrapper(struct vty *vty, vty_out(vty, "\n"); } -DEFUN (show_ipv6_ospf6_database, - show_ipv6_ospf6_database_cmd, - "show ipv6 ospf6 database [] [json]", - SHOW_STR - IPV6_STR - OSPF6_STR - "Display Link state database\n" - "Display details of LSAs\n" - "Dump LSAs\n" - "Display LSA's internal information\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_database, show_ipv6_ospf6_database_cmd, + "show ipv6 ospf6 [vrf ] database [] [json]", + SHOW_STR IPV6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Display Link state database\n" + "Display details of LSAs\n" + "Dump LSAs\n" + "Display LSA's internal information\n" JSON_STR) { - int idx_level = 4; int level; - bool uj = use_json(argc, argv); + int idx_level = 4; + struct listnode *node; struct ospf6 *ospf6; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + bool uj = use_json(argc, argv); - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) + idx_level += 2; level = parse_show_level(idx_level, argc, argv); - ospf6_lsdb_show_wrapper(vty, level, NULL, NULL, NULL, uj, ospf6); + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_lsdb_show_wrapper(vty, level, NULL, NULL, NULL, + uj, ospf6); + if (!all_vrf) + break; + } + } + return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_database_type, show_ipv6_ospf6_database_type_cmd, - "show ipv6 ospf6 database [] [json]", - SHOW_STR - IPV6_STR - OSPF6_STR - "Display Link state database\n" - "Display Router LSAs\n" - "Display Network LSAs\n" - "Display Inter-Area-Prefix LSAs\n" - "Display Inter-Area-Router LSAs\n" - "Display As-External LSAs\n" - "Display Group-Membership LSAs\n" - "Display Type-7 LSAs\n" - "Display Link LSAs\n" - "Display Intra-Area-Prefix LSAs\n" - "Display details of LSAs\n" - "Dump LSAs\n" - "Display LSA's internal information\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_database_type, show_ipv6_ospf6_database_type_cmd, + "show ipv6 ospf6 [vrf ] database [] [json]", + SHOW_STR IPV6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Display Link state database\n" + "Display Router LSAs\n" + "Display Network LSAs\n" + "Display Inter-Area-Prefix LSAs\n" + "Display Inter-Area-Router LSAs\n" + "Display As-External LSAs\n" + "Display Group-Membership LSAs\n" + "Display Type-7 LSAs\n" + "Display Link LSAs\n" + "Display Intra-Area-Prefix LSAs\n" + "Display details of LSAs\n" + "Dump LSAs\n" + "Display LSA's internal information\n" JSON_STR) { int idx_lsa = 4; int idx_level = 5; int level; - uint16_t type = 0; bool uj = use_json(argc, argv); + struct listnode *node; struct ospf6 *ospf6; - - - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); + uint16_t type = 0; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) { + idx_lsa += 2; + idx_level += 2; + } type = parse_type_spec(idx_lsa, argc, argv); level = parse_show_level(idx_level, argc, argv); - ospf6_lsdb_type_show_wrapper(vty, level, &type, NULL, NULL, uj, ospf6); + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_lsdb_type_show_wrapper(vty, level, &type, NULL, + NULL, uj, ospf6); + if (!all_vrf) + break; + } + } + return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_database_id, - show_ipv6_ospf6_database_id_cmd, - "show ipv6 ospf6 database <*|linkstate-id> A.B.C.D [] [json]", - SHOW_STR - IPV6_STR - OSPF6_STR - "Display Link state database\n" - "Any Link state Type\n" - "Search by Link state ID\n" - "Specify Link state ID as IPv4 address notation\n" - "Display details of LSAs\n" - "Dump LSAs\n" - "Display LSA's internal information\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_database_id, show_ipv6_ospf6_database_id_cmd, + "show ipv6 ospf6 [vrf ] database <*|linkstate-id> A.B.C.D [] [json]", + SHOW_STR IPV6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Display Link state database\n" + "Any Link state Type\n" + "Search by Link state ID\n" + "Specify Link state ID as IPv4 address notation\n" + "Display details of LSAs\n" + "Dump LSAs\n" + "Display LSA's internal information\n" JSON_STR) { int idx_ipv4 = 5; int idx_level = 6; int level; - uint32_t id = 0; bool uj = use_json(argc, argv); + struct listnode *node; struct ospf6 *ospf6; + uint32_t id = 0; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; - - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); - + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); if (argv[idx_ipv4]->type == IPV4_TKN) inet_pton(AF_INET, argv[idx_ipv4]->arg, &id); level = parse_show_level(idx_level, argc, argv); - ospf6_lsdb_show_wrapper(vty, level, NULL, &id, NULL, uj, ospf6); + + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_lsdb_show_wrapper(vty, level, NULL, &id, NULL, uj, + ospf6); + if (!all_vrf) + break; + } + } return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_database_router, - show_ipv6_ospf6_database_router_cmd, - "show ipv6 ospf6 database <*|adv-router> * A.B.C.D [json]", - SHOW_STR - IPV6_STR - OSPF6_STR - "Display Link state database\n" - "Any Link state Type\n" - "Search by Advertising Router\n" - "Any Link state ID\n" - "Specify Advertising Router as IPv4 address notation\n" - "Display details of LSAs\n" - "Dump LSAs\n" - "Display LSA's internal information\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_database_router, show_ipv6_ospf6_database_router_cmd, + "show ipv6 ospf6 [vrf ] database <*|adv-router> * A.B.C.D [json]", + SHOW_STR IPV6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Display Link state database\n" + "Any Link state Type\n" + "Search by Advertising Router\n" + "Any Link state ID\n" + "Specify Advertising Router as IPv4 address notation\n" + "Display details of LSAs\n" + "Dump LSAs\n" + "Display LSA's internal information\n" JSON_STR) { int idx_ipv4 = 6; int idx_level = 7; int level; + struct listnode *node; + struct ospf6 *ospf6; uint32_t adv_router = 0; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; bool uj = use_json(argc, argv); - struct ospf6 *ospf6; + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) { + idx_ipv4 += 2; + idx_level += 2; + } - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); inet_pton(AF_INET, argv[idx_ipv4]->arg, &adv_router); level = parse_show_level(idx_level, argc, argv); - ospf6_lsdb_show_wrapper(vty, level, NULL, NULL, &adv_router, uj, ospf6); + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_lsdb_show_wrapper(vty, level, NULL, NULL, + &adv_router, uj, ospf6); + if (!all_vrf) + break; + } + } + return CMD_SUCCESS; } -DEFUN_HIDDEN (show_ipv6_ospf6_database_aggr_router, - show_ipv6_ospf6_database_aggr_router_cmd, - "show ipv6 ospf6 database aggr adv-router A.B.C.D", - SHOW_STR - IPV6_STR - OSPF6_STR - "Display Link state database\n" - "Aggregated Router LSA\n" - "Search by Advertising Router\n" - "Specify Advertising Router as IPv4 address notation\n") +static int ipv6_ospf6_database_aggr_router_common(struct vty *vty, + uint32_t adv_router, + struct ospf6 *ospf6) { int level = OSPF6_LSDB_SHOW_LEVEL_DETAIL; uint16_t type = htons(OSPF6_LSTYPE_ROUTER); - int idx_ipv4 = 6; struct listnode *i; - struct ospf6 *ospf6; struct ospf6_area *oa; struct ospf6_lsdb *lsdb; - uint32_t adv_router = 0; - - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); - - inet_pton(AF_INET, argv[idx_ipv4]->arg, &adv_router); for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) { if (adv_router == ospf6->router_id) @@ -561,225 +590,338 @@ DEFUN_HIDDEN (show_ipv6_ospf6_database_aggr_router, } vty_out(vty, "\n"); + return CMD_SUCCESS; +} + +DEFUN_HIDDEN( + show_ipv6_ospf6_database_aggr_router, + show_ipv6_ospf6_database_aggr_router_cmd, + "show ipv6 ospf6 [vrf ] database aggr adv-router A.B.C.D", + SHOW_STR IPV6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Display Link state database\n" + "Aggregated Router LSA\n" + "Search by Advertising Router\n" + "Specify Advertising Router as IPv4 address notation\n") +{ + int idx_ipv4 = 6; + struct listnode *node; + struct ospf6 *ospf6; + uint32_t adv_router = 0; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) + idx_ipv4 += 2; + + inet_pton(AF_INET, argv[idx_ipv4]->arg, &adv_router); + + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ipv6_ospf6_database_aggr_router_common(vty, adv_router, + ospf6); + + if (!all_vrf) + break; + } + } return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_database_type_id, - show_ipv6_ospf6_database_type_id_cmd, - "show ipv6 ospf6 database linkstate-id A.B.C.D [] [json]", - SHOW_STR - IPV6_STR - OSPF6_STR - "Display Link state database\n" - "Display Router LSAs\n" - "Display Network LSAs\n" - "Display Inter-Area-Prefix LSAs\n" - "Display Inter-Area-Router LSAs\n" - "Display As-External LSAs\n" - "Display Group-Membership LSAs\n" - "Display Type-7 LSAs\n" - "Display Link LSAs\n" - "Display Intra-Area-Prefix LSAs\n" - "Search by Link state ID\n" - "Specify Link state ID as IPv4 address notation\n" - "Display details of LSAs\n" - "Dump LSAs\n" - "Display LSA's internal information\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_database_type_id, show_ipv6_ospf6_database_type_id_cmd, + "show ipv6 ospf6 [vrf ] database linkstate-id A.B.C.D [] [json]", + SHOW_STR IPV6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Display Link state database\n" + "Display Router LSAs\n" + "Display Network LSAs\n" + "Display Inter-Area-Prefix LSAs\n" + "Display Inter-Area-Router LSAs\n" + "Display As-External LSAs\n" + "Display Group-Membership LSAs\n" + "Display Type-7 LSAs\n" + "Display Link LSAs\n" + "Display Intra-Area-Prefix LSAs\n" + "Search by Link state ID\n" + "Specify Link state ID as IPv4 address notation\n" + "Display details of LSAs\n" + "Dump LSAs\n" + "Display LSA's internal information\n" JSON_STR) { int idx_lsa = 4; int idx_ipv4 = 6; int idx_level = 7; int level; - uint16_t type = 0; - uint32_t id = 0; bool uj = use_json(argc, argv); + struct listnode *node; struct ospf6 *ospf6; - - - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); + uint16_t type = 0; + uint32_t id = 0; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) { + idx_lsa += 2; + idx_ipv4 += 2; + idx_level += 2; + } type = parse_type_spec(idx_lsa, argc, argv); inet_pton(AF_INET, argv[idx_ipv4]->arg, &id); level = parse_show_level(idx_level, argc, argv); - ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, NULL, uj, ospf6); + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, + NULL, uj, ospf6); + if (!all_vrf) + break; + } + } + return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_database_type_router, - show_ipv6_ospf6_database_type_router_cmd, - "show ipv6 ospf6 database <*|adv-router> A.B.C.D [] [json]", - SHOW_STR - IPV6_STR - OSPF6_STR - "Display Link state database\n" - "Display Router LSAs\n" - "Display Network LSAs\n" - "Display Inter-Area-Prefix LSAs\n" - "Display Inter-Area-Router LSAs\n" - "Display As-External LSAs\n" - "Display Group-Membership LSAs\n" - "Display Type-7 LSAs\n" - "Display Link LSAs\n" - "Display Intra-Area-Prefix LSAs\n" - "Any Link state ID\n" - "Search by Advertising Router\n" - "Specify Advertising Router as IPv4 address notation\n" - "Display details of LSAs\n" - "Dump LSAs\n" - "Display LSA's internal information\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_database_type_router, + show_ipv6_ospf6_database_type_router_cmd, + "show ipv6 ospf6 [vrf ] database <*|adv-router> A.B.C.D [] [json]", + SHOW_STR IPV6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Display Link state database\n" + "Display Router LSAs\n" + "Display Network LSAs\n" + "Display Inter-Area-Prefix LSAs\n" + "Display Inter-Area-Router LSAs\n" + "Display As-External LSAs\n" + "Display Group-Membership LSAs\n" + "Display Type-7 LSAs\n" + "Display Link LSAs\n" + "Display Intra-Area-Prefix LSAs\n" + "Any Link state ID\n" + "Search by Advertising Router\n" + "Specify Advertising Router as IPv4 address notation\n" + "Display details of LSAs\n" + "Dump LSAs\n" + "Display LSA's internal information\n" JSON_STR) { int idx_lsa = 4; int idx_ipv4 = 6; int idx_level = 7; int level; - uint16_t type = 0; - uint32_t adv_router = 0; bool uj = use_json(argc, argv); + struct listnode *node; struct ospf6 *ospf6; + uint16_t type = 0; + uint32_t adv_router = 0; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) { + idx_lsa += 2; + idx_ipv4 += 2; + idx_level += 2; + } - - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); type = parse_type_spec(idx_lsa, argc, argv); inet_pton(AF_INET, argv[idx_ipv4]->arg, &adv_router); level = parse_show_level(idx_level, argc, argv); - ospf6_lsdb_type_show_wrapper(vty, level, &type, NULL, &adv_router, uj, - ospf6); + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_lsdb_type_show_wrapper(vty, level, &type, NULL, + &adv_router, uj, ospf6); + + if (!all_vrf) + break; + } + } + return CMD_SUCCESS; } - -DEFUN (show_ipv6_ospf6_database_id_router, - show_ipv6_ospf6_database_id_router_cmd, - "show ipv6 ospf6 database * A.B.C.D A.B.C.D [] [json]", - SHOW_STR - IPV6_STR - OSPF6_STR - "Display Link state database\n" - "Any Link state Type\n" - "Specify Link state ID as IPv4 address notation\n" - "Specify Advertising Router as IPv4 address notation\n" - "Display details of LSAs\n" - "Dump LSAs\n" - "Display LSA's internal information\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_database_id_router, + show_ipv6_ospf6_database_id_router_cmd, + "show ipv6 ospf6 [vrf ] database * A.B.C.D A.B.C.D [] [json]", + SHOW_STR IPV6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Display Link state database\n" + "Any Link state Type\n" + "Specify Link state ID as IPv4 address notation\n" + "Specify Advertising Router as IPv4 address notation\n" + "Display details of LSAs\n" + "Dump LSAs\n" + "Display LSA's internal information\n" JSON_STR) { int idx_ls_id = 5; int idx_adv_rtr = 6; int idx_level = 7; int level; - uint32_t id = 0; - uint32_t adv_router = 0; bool uj = use_json(argc, argv); + struct listnode *node; struct ospf6 *ospf6; + uint32_t id = 0; + uint32_t adv_router = 0; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) { + idx_ls_id += 2; + idx_adv_rtr += 2; + idx_level += 2; + } - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); inet_pton(AF_INET, argv[idx_ls_id]->arg, &id); inet_pton(AF_INET, argv[idx_adv_rtr]->arg, &adv_router); level = parse_show_level(idx_level, argc, argv); - ospf6_lsdb_show_wrapper(vty, level, NULL, &id, &adv_router, uj, ospf6); + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_lsdb_show_wrapper(vty, level, NULL, &id, + &adv_router, uj, ospf6); + if (!all_vrf) + break; + } + } + return CMD_SUCCESS; } - -DEFUN (show_ipv6_ospf6_database_adv_router_linkstate_id, - show_ipv6_ospf6_database_adv_router_linkstate_id_cmd, - "show ipv6 ospf6 database adv-router A.B.C.D linkstate-id A.B.C.D [] [json]", - SHOW_STR - IPV6_STR - OSPF6_STR - "Display Link state database\n" - "Search by Advertising Router\n" - "Specify Advertising Router as IPv4 address notation\n" - "Search by Link state ID\n" - "Specify Link state ID as IPv4 address notation\n" - "Display details of LSAs\n" - "Dump LSAs\n" - "Display LSA's internal information\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_database_adv_router_linkstate_id, + show_ipv6_ospf6_database_adv_router_linkstate_id_cmd, + "show ipv6 ospf6 [vrf ] database adv-router A.B.C.D linkstate-id A.B.C.D [] [json]", + SHOW_STR IPV6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Display Link state database\n" + "Search by Advertising Router\n" + "Specify Advertising Router as IPv4 address notation\n" + "Search by Link state ID\n" + "Specify Link state ID as IPv4 address notation\n" + "Display details of LSAs\n" + "Dump LSAs\n" + "Display LSA's internal information\n" JSON_STR) { int idx_adv_rtr = 5; int idx_ls_id = 7; int idx_level = 8; int level; - uint32_t id = 0; - uint32_t adv_router = 0; bool uj = use_json(argc, argv); + struct listnode *node; struct ospf6 *ospf6; + uint32_t id = 0; + uint32_t adv_router = 0; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) { + idx_adv_rtr += 2; + idx_ls_id += 2; + idx_level += 2; + } inet_pton(AF_INET, argv[idx_adv_rtr]->arg, &adv_router); inet_pton(AF_INET, argv[idx_ls_id]->arg, &id); level = parse_show_level(idx_level, argc, argv); - ospf6_lsdb_show_wrapper(vty, level, NULL, &id, &adv_router, uj, ospf6); + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_lsdb_type_show_wrapper(vty, level, NULL, &id, + &adv_router, uj, ospf6); + + if (!all_vrf) + break; + } + } + return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_database_type_id_router, - show_ipv6_ospf6_database_type_id_router_cmd, - "show ipv6 ospf6 database A.B.C.D A.B.C.D [] [json]", - SHOW_STR - IPV6_STR - OSPF6_STR - "Display Link state database\n" - "Display Router LSAs\n" - "Display Network LSAs\n" - "Display Inter-Area-Prefix LSAs\n" - "Display Inter-Area-Router LSAs\n" - "Display As-External LSAs\n" - "Display Group-Membership LSAs\n" - "Display Type-7 LSAs\n" - "Display Link LSAs\n" - "Display Intra-Area-Prefix LSAs\n" - "Specify Link state ID as IPv4 address notation\n" - "Specify Advertising Router as IPv4 address notation\n" - "Dump LSAs\n" - "Display LSA's internal information\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_database_type_id_router, + show_ipv6_ospf6_database_type_id_router_cmd, + "show ipv6 ospf6 [vrf ] database A.B.C.D A.B.C.D [] [json]", + SHOW_STR IPV6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Display Link state database\n" + "Display Router LSAs\n" + "Display Network LSAs\n" + "Display Inter-Area-Prefix LSAs\n" + "Display Inter-Area-Router LSAs\n" + "Display As-External LSAs\n" + "Display Group-Membership LSAs\n" + "Display Type-7 LSAs\n" + "Display Link LSAs\n" + "Display Intra-Area-Prefix LSAs\n" + "Specify Link state ID as IPv4 address notation\n" + "Specify Advertising Router as IPv4 address notation\n" + "Dump LSAs\n" + "Display LSA's internal information\n" JSON_STR) { int idx_lsa = 4; int idx_ls_id = 5; int idx_adv_rtr = 6; int idx_level = 7; int level; + bool uj = use_json(argc, argv); + struct listnode *node; + struct ospf6 *ospf6; uint16_t type = 0; uint32_t id = 0; uint32_t adv_router = 0; - bool uj = use_json(argc, argv); - struct ospf6 *ospf6; - - - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) { + idx_lsa += 2; + idx_ls_id += 2; + idx_adv_rtr += 2; + idx_level += 2; + } type = parse_type_spec(idx_lsa, argc, argv); inet_pton(AF_INET, argv[idx_ls_id]->arg, &id); inet_pton(AF_INET, argv[idx_adv_rtr]->arg, &adv_router); level = parse_show_level(idx_level, argc, argv); - ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, &adv_router, uj, - ospf6); + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, + &adv_router, uj, ospf6); + + if (!all_vrf) + break; + } + } + return CMD_SUCCESS; } DEFUN (show_ipv6_ospf6_database_type_adv_router_linkstate_id, show_ipv6_ospf6_database_type_adv_router_linkstate_id_cmd, - "show ipv6 ospf6 database adv-router A.B.C.D linkstate-id A.B.C.D [] [json]", + "show ipv6 ospf6 [vrf ] database adv-router A.B.C.D linkstate-id A.B.C.D [] [json]", SHOW_STR IPV6_STR OSPF6_STR + VRF_CMD_HELP_STR + "All VRFs\n" "Display Link state database\n" "Display Router LSAs\n" "Display Network LSAs\n" @@ -803,208 +945,278 @@ DEFUN (show_ipv6_ospf6_database_type_adv_router_linkstate_id, int idx_ls_id = 8; int idx_level = 9; int level; + bool uj = use_json(argc, argv); + struct listnode *node; + struct ospf6 *ospf6; uint16_t type = 0; uint32_t id = 0; uint32_t adv_router = 0; - bool uj = use_json(argc, argv); - struct ospf6 *ospf6; - - - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) { + idx_lsa += 2; + idx_adv_rtr += 2; + idx_ls_id += 2; + idx_level += 2; + } type = parse_type_spec(idx_lsa, argc, argv); inet_pton(AF_INET, argv[idx_adv_rtr]->arg, &adv_router); inet_pton(AF_INET, argv[idx_ls_id]->arg, &id); level = parse_show_level(idx_level, argc, argv); - ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, &adv_router, uj, - ospf6); + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, + &adv_router, uj, ospf6); + + if (!all_vrf) + break; + } + } + return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_database_self_originated, - show_ipv6_ospf6_database_self_originated_cmd, - "show ipv6 ospf6 database self-originated [] [json]", - SHOW_STR - IPV6_STR - OSPF6_STR - "Display Link state database\n" - "Display Self-originated LSAs\n" - "Display details of LSAs\n" - "Dump LSAs\n" - "Display LSA's internal information\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_database_self_originated, + show_ipv6_ospf6_database_self_originated_cmd, + "show ipv6 ospf6 [vrf ] database self-originated [] [json]", + SHOW_STR IPV6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Display Link state database\n" + "Display Self-originated LSAs\n" + "Display details of LSAs\n" + "Dump LSAs\n" + "Display LSA's internal information\n" JSON_STR) { int idx_level = 5; int level; + struct listnode *node; + struct ospf6 *ospf6; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; uint32_t adv_router = 0; bool uj = use_json(argc, argv); - struct ospf6 *ospf6; - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) + idx_level += 2; + level = parse_show_level(idx_level, argc, argv); - adv_router = ospf6->router_id; - ospf6_lsdb_show_wrapper(vty, level, NULL, NULL, &adv_router, uj, ospf6); + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + adv_router = ospf6->router_id; + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + ospf6_lsdb_show_wrapper(vty, level, NULL, NULL, + &adv_router, uj, ospf6); + + if (!all_vrf) + break; + } + } + return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_database_type_self_originated, - show_ipv6_ospf6_database_type_self_originated_cmd, - "show ipv6 ospf6 database self-originated [] [json]", - SHOW_STR - IPV6_STR - OSPF6_STR - "Display Link state database\n" - "Display Router LSAs\n" - "Display Network LSAs\n" - "Display Inter-Area-Prefix LSAs\n" - "Display Inter-Area-Router LSAs\n" - "Display As-External LSAs\n" - "Display Group-Membership LSAs\n" - "Display Type-7 LSAs\n" - "Display Link LSAs\n" - "Display Intra-Area-Prefix LSAs\n" - "Display Self-originated LSAs\n" - "Display details of LSAs\n" - "Dump LSAs\n" - "Display LSA's internal information\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_database_type_self_originated, + show_ipv6_ospf6_database_type_self_originated_cmd, + "show ipv6 ospf6 [vrf ] database self-originated [] [json]", + SHOW_STR IPV6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Display Link state database\n" + "Display Router LSAs\n" + "Display Network LSAs\n" + "Display Inter-Area-Prefix LSAs\n" + "Display Inter-Area-Router LSAs\n" + "Display As-External LSAs\n" + "Display Group-Membership LSAs\n" + "Display Type-7 LSAs\n" + "Display Link LSAs\n" + "Display Intra-Area-Prefix LSAs\n" + "Display Self-originated LSAs\n" + "Display details of LSAs\n" + "Dump LSAs\n" + "Display LSA's internal information\n" JSON_STR) { int idx_lsa = 4; int idx_level = 6; int level; + struct listnode *node; + struct ospf6 *ospf6; uint16_t type = 0; uint32_t adv_router = 0; bool uj = use_json(argc, argv); - struct ospf6 *ospf6; - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) { + idx_lsa += 2; + idx_level += 2; + } + type = parse_type_spec(idx_lsa, argc, argv); level = parse_show_level(idx_level, argc, argv); - adv_router = ospf6->router_id; + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + adv_router = ospf6->router_id; + ospf6_lsdb_type_show_wrapper(vty, level, &type, NULL, + &adv_router, uj, ospf6); + + if (!all_vrf) + break; + } + } - ospf6_lsdb_type_show_wrapper(vty, level, &type, NULL, &adv_router, uj, - ospf6); return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_database_type_self_originated_linkstate_id, - show_ipv6_ospf6_database_type_self_originated_linkstate_id_cmd, - "show ipv6 ospf6 database self-originated linkstate-id A.B.C.D [] [json]", - SHOW_STR - IPV6_STR - OSPF6_STR - "Display Link state database\n" - "Display Router LSAs\n" - "Display Network LSAs\n" - "Display Inter-Area-Prefix LSAs\n" - "Display Inter-Area-Router LSAs\n" - "Display As-External LSAs\n" - "Display Group-Membership LSAs\n" - "Display Type-7 LSAs\n" - "Display Link LSAs\n" - "Display Intra-Area-Prefix LSAs\n" - "Display Self-originated LSAs\n" - "Search by Link state ID\n" - "Specify Link state ID as IPv4 address notation\n" - "Display details of LSAs\n" - "Dump LSAs\n" - "Display LSA's internal information\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_database_type_self_originated_linkstate_id, + show_ipv6_ospf6_database_type_self_originated_linkstate_id_cmd, + "show ipv6 ospf6 [vrf ] database self-originated linkstate-id A.B.C.D [] [json]", + SHOW_STR IPV6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Display Link state database\n" + "Display Router LSAs\n" + "Display Network LSAs\n" + "Display Inter-Area-Prefix LSAs\n" + "Display Inter-Area-Router LSAs\n" + "Display As-External LSAs\n" + "Display Group-Membership LSAs\n" + "Display Type-7 LSAs\n" + "Display Link LSAs\n" + "Display Intra-Area-Prefix LSAs\n" + "Display Self-originated LSAs\n" + "Search by Link state ID\n" + "Specify Link state ID as IPv4 address notation\n" + "Display details of LSAs\n" + "Dump LSAs\n" + "Display LSA's internal information\n" JSON_STR) { int idx_lsa = 4; int idx_ls_id = 7; int idx_level = 8; int level; + bool uj = use_json(argc, argv); + struct listnode *node; + struct ospf6 *ospf6; uint16_t type = 0; uint32_t adv_router = 0; uint32_t id = 0; - bool uj = use_json(argc, argv); - struct ospf6 *ospf6; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) { + idx_lsa += 2; + idx_ls_id += 2; + idx_level += 2; + } + - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); type = parse_type_spec(idx_lsa, argc, argv); inet_pton(AF_INET, argv[idx_ls_id]->arg, &id); level = parse_show_level(idx_level, argc, argv); - adv_router = ospf6->router_id; - ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, &adv_router, uj, - ospf6); + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + adv_router = ospf6->router_id; + ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, + &adv_router, uj, ospf6); + + if (!all_vrf) + break; + } + } + return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_database_type_id_self_originated, - show_ipv6_ospf6_database_type_id_self_originated_cmd, - "show ipv6 ospf6 database A.B.C.D self-originated [] [json]", - SHOW_STR - IPV6_STR - OSPF6_STR - "Display Link state database\n" - "Display Router LSAs\n" - "Display Network LSAs\n" - "Display Inter-Area-Prefix LSAs\n" - "Display Inter-Area-Router LSAs\n" - "Display As-External LSAs\n" - "Display Group-Membership LSAs\n" - "Display Type-7 LSAs\n" - "Display Link LSAs\n" - "Display Intra-Area-Prefix LSAs\n" - "Specify Link state ID as IPv4 address notation\n" - "Display Self-originated LSAs\n" - "Display details of LSAs\n" - "Dump LSAs\n" - "Display LSA's internal information\n" - JSON_STR) +DEFUN(show_ipv6_ospf6_database_type_id_self_originated, + show_ipv6_ospf6_database_type_id_self_originated_cmd, + "show ipv6 ospf6 [vrf ] database A.B.C.D self-originated [] [json]", + SHOW_STR IPV6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Display Link state database\n" + "Display Router LSAs\n" + "Display Network LSAs\n" + "Display Inter-Area-Prefix LSAs\n" + "Display Inter-Area-Router LSAs\n" + "Display As-External LSAs\n" + "Display Group-Membership LSAs\n" + "Display Type-7 LSAs\n" + "Display Link LSAs\n" + "Display Intra-Area-Prefix LSAs\n" + "Specify Link state ID as IPv4 address notation\n" + "Display Self-originated LSAs\n" + "Display details of LSAs\n" + "Dump LSAs\n" + "Display LSA's internal information\n" JSON_STR) { int idx_lsa = 4; int idx_ls_id = 5; int idx_level = 7; int level; + bool uj = use_json(argc, argv); + struct listnode *node; + struct ospf6 *ospf6; uint16_t type = 0; uint32_t adv_router = 0; uint32_t id = 0; - bool uj = use_json(argc, argv); - struct ospf6 *ospf6; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) { + idx_lsa += 2; + idx_ls_id += 2; + idx_level += 2; + } - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); type = parse_type_spec(idx_lsa, argc, argv); inet_pton(AF_INET, argv[idx_ls_id]->arg, &id); level = parse_show_level(idx_level, argc, argv); - adv_router = ospf6->router_id; - ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, &adv_router, uj, - ospf6); + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + adv_router = ospf6->router_id; + ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, + &adv_router, uj, ospf6); + + if (!all_vrf) + break; + } + } + return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_border_routers, - show_ipv6_ospf6_border_routers_cmd, - "show ipv6 ospf6 border-routers []", - SHOW_STR - IP6_STR - OSPF6_STR - "Display routing table for ABR and ASBR\n" - "Router ID\n" - "Show detailed output\n") +static int show_ospf6_border_routers_common(struct vty *vty, int argc, + struct cmd_token **argv, + struct ospf6 *ospf6, int idx_ipv4, + int idx_argc) { - int idx_ipv4 = 4; uint32_t adv_router; struct ospf6_route *ro; struct prefix prefix; - struct ospf6 *ospf6 = NULL; - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); - if (argc == 5) { + if (argc == idx_argc) { if (strmatch(argv[idx_ipv4]->text, "detail")) { for (ro = ospf6_route_head(ospf6->brouter_table); ro; ro = ospf6_route_next(ro)) @@ -1017,7 +1229,7 @@ DEFUN (show_ipv6_ospf6_border_routers, if (!ro) { vty_out(vty, "No Route found for Router ID: %s\n", - argv[4]->arg); + argv[idx_ipv4]->arg); return CMD_SUCCESS; } @@ -1035,62 +1247,125 @@ DEFUN (show_ipv6_ospf6_border_routers, return CMD_SUCCESS; } +DEFUN(show_ipv6_ospf6_border_routers, show_ipv6_ospf6_border_routers_cmd, + "show ipv6 ospf6 [vrf ] border-routers []", + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Display routing table for ABR and ASBR\n" + "Router ID\n" + "Show detailed output\n") +{ + int idx_ipv4 = 4; + struct ospf6 *ospf6 = NULL; + struct listnode *node; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + int idx_argc = 5; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) { + idx_argc += 2; + idx_ipv4 += 2; + } -DEFUN (show_ipv6_ospf6_linkstate, - show_ipv6_ospf6_linkstate_cmd, - "show ipv6 ospf6 linkstate ", - SHOW_STR - IP6_STR - OSPF6_STR - "Display linkstate routing table\n" - "Display Router Entry\n" - "Specify Router ID as IPv4 address notation\n" - "Display Network Entry\n" - "Specify Router ID as IPv4 address notation\n" - "Specify Link state ID as IPv4 address notation\n") + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + show_ospf6_border_routers_common(vty, argc, argv, ospf6, + idx_ipv4, idx_argc); + + if (!all_vrf) + break; + } + } + + return CMD_SUCCESS; +} + + +DEFUN(show_ipv6_ospf6_linkstate, show_ipv6_ospf6_linkstate_cmd, + "show ipv6 ospf6 [vrf ] linkstate ", + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Display linkstate routing table\n" + "Display Router Entry\n" + "Specify Router ID as IPv4 address notation\n" + "Display Network Entry\n" + "Specify Router ID as IPv4 address notation\n" + "Specify Link state ID as IPv4 address notation\n") { int idx_ipv4 = 5; - struct listnode *node; + struct listnode *node, *nnode; struct ospf6_area *oa; struct ospf6 *ospf6 = NULL; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) + idx_ipv4 += 2; + + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, nnode, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) { + vty_out(vty, + "\n SPF Result in Area %s\n\n", + oa->name); + ospf6_linkstate_table_show(vty, idx_ipv4, argc, + argv, oa->spf_table); + } + vty_out(vty, "\n"); - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); - for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) { - vty_out(vty, "\n SPF Result in Area %s\n\n", oa->name); - ospf6_linkstate_table_show(vty, idx_ipv4, argc, argv, - oa->spf_table); + if (!all_vrf) + break; + } } - vty_out(vty, "\n"); return CMD_SUCCESS; } -DEFUN (show_ipv6_ospf6_linkstate_detail, - show_ipv6_ospf6_linkstate_detail_cmd, - "show ipv6 ospf6 linkstate detail", - SHOW_STR - IP6_STR - OSPF6_STR - "Display linkstate routing table\n" - "Display detailed information\n") +DEFUN(show_ipv6_ospf6_linkstate_detail, show_ipv6_ospf6_linkstate_detail_cmd, + "show ipv6 ospf6 [vrf ] linkstate detail", + SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR + "All VRFs\n" + "Display linkstate routing table\n" + "Display detailed information\n") { int idx_detail = 4; struct listnode *node; struct ospf6_area *oa; struct ospf6 *ospf6 = NULL; + const char *vrf_name = NULL; + bool all_vrf = false; + int idx_vrf = 0; + - ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME); - OSPF6_CMD_CHECK_RUNNING(ospf6); + OSPF6_CMD_CHECK_RUNNING(); + OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (idx_vrf > 0) + idx_detail += 2; - for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) { - vty_out(vty, "\n SPF Result in Area %s\n\n", oa->name); - ospf6_linkstate_table_show(vty, idx_detail, argc, argv, - oa->spf_table); + for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { + if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { + for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) { + vty_out(vty, + "\n SPF Result in Area %s\n\n", + oa->name); + ospf6_linkstate_table_show(vty, idx_detail, + argc, argv, + oa->spf_table); + } + vty_out(vty, "\n"); + + if (!all_vrf) + break; + } } - vty_out(vty, "\n"); return CMD_SUCCESS; } diff --git a/ospf6d/ospf6d.h b/ospf6d/ospf6d.h index dfac57aa2f..e054803df3 100644 --- a/ospf6d/ospf6d.h +++ b/ospf6d/ospf6d.h @@ -89,13 +89,21 @@ extern struct thread_master *master; #define OSPF6_ROUTER_ID_STR "Specify Router-ID\n" #define OSPF6_LS_ID_STR "Specify Link State ID\n" -#define OSPF6_CMD_CHECK_RUNNING(ospf6) \ - if (ospf6 == NULL) { \ +#define OSPF6_CMD_CHECK_RUNNING() \ + if (om6->ospf6 == NULL) { \ vty_out(vty, "OSPFv3 is not running\n"); \ return CMD_SUCCESS; \ } #define IS_OSPF6_ASBR(O) ((O)->flag & OSPF6_FLAG_ASBR) +#define OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \ + if (argv_find(argv, argc, "vrf", &idx_vrf)) { \ + vrf_name = argv[idx_vrf + 1]->arg; \ + all_vrf = strmatch(vrf_name, "all"); \ + } else { \ + vrf_name = VRF_DEFAULT_NAME; \ + } + extern struct zebra_privs_t ospf6d_privs; /* Function Prototypes */ diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index a1417430ec..336bd44a49 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -1976,8 +1976,8 @@ DEFUNSH(VTYSH_BABELD, router_babel, router_babel_cmd, "router babel", #endif /* HAVE_BABELD */ #ifdef HAVE_OSPF6D -DEFUNSH(VTYSH_OSPF6D, router_ospf6, router_ospf6_cmd, "router ospf6", - ROUTER_STR OSPF6_STR) +DEFUNSH(VTYSH_OSPF6D, router_ospf6, router_ospf6_cmd, "router ospf6 [vrf NAME]", + ROUTER_STR OSPF6_STR VRF_CMD_HELP_STR) { vty->node = OSPF6_NODE; return CMD_SUCCESS; -- 2.39.5