diff options
author | harios_niral <hari@niralnetworks.com> | 2021-05-05 22:19:01 +0200 |
---|---|---|
committer | Igor Ryzhov <iryzhov@nfware.com> | 2021-05-06 09:54:31 +0200 |
commit | d48ef099db433a5d0be9d1584af346e015e84991 (patch) | |
tree | 327ed47e64e01eab8db0bd17b86ed6da7fbefcb7 /ospf6d/ospf6_top.c | |
parent | ospf6d: add internal support for multiple vrfs (diff) | |
download | frr-d48ef099db433a5d0be9d1584af346e015e84991.tar.xz frr-d48ef099db433a5d0be9d1584af346e015e84991.zip |
ospf6d: add vty support for multiple vrfs
Co-authored-by: Kaushik Nath <kaushiknath.null@gmail.com>
Signed-off-by: harios_niral <hari@niralnetworks.com>
Diffstat (limited to 'ospf6d/ospf6_top.c')
-rw-r--r-- | ospf6d/ospf6_top.c | 263 |
1 files changed, 169 insertions, 94 deletions
diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c index 5d26c513f..3ab0f1fbb 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 <NAME|all>] [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 [<intra-area|inter-area|external-1|external-2|X:X::X:X|X:X::X:X/M|detail|summary>] [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 <NAME|all>] route [<intra-area|inter-area|external-1|external-2|X:X::X:X|X:X::X:X/M|detail|summary>] [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 <match|longer> [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 <NAME|all>] route X:X::X:X/M <match|longer> [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 <NAME|all>] 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 <intra-area|inter-area|external-1|external-2> 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 <NAME|all>] route <intra-area|inter-area|external-1|external-2> 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); |