From 919b8f94b314029daf619a8583be448293856b5a Mon Sep 17 00:00:00 2001 From: Zhiyuan Wan Date: Mon, 3 Apr 2023 16:21:15 +0800 Subject: [PATCH] ospfd: Support show intra-area network type in 'show ip ospf route' command User can now use 'show ip ospf route detail' command to distinguish intra-area stub network and transit network. Transit network will be displayed as 'N T prefix ...'. NOTICE: Json output format has been changed, intra-area transit networks will have a new attribute 'transit' and value is 'true'. And 'adv' (means advertise router) change to 'advertisedRouter'. Example output: bsp-debianrt-exp1# show ip ospf route detail Codes: N - network T - transitive IA - inter-area E - external route D - destination R - router ============ OSPF network routing table ============ N T 10.0.0.0/24 [32] area: 0.0.0.0 via 192.168.124.67, ens192 adv 10.0.0.5 N 10.0.30.0/24 [33] area: 0.0.0.0 via 192.168.124.67, ens192 adv 10.0.0.5 ... Signed-off-by: Zhiyuan Wan --- doc/user/ospfd.rst | 4 ++-- ospfd/ospf_route.c | 2 ++ ospfd/ospf_route.h | 2 ++ ospfd/ospf_vty.c | 20 +++++++++++++++----- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/doc/user/ospfd.rst b/doc/user/ospfd.rst index 9491c5e42f..4e30ef2aec 100644 --- a/doc/user/ospfd.rst +++ b/doc/user/ospfd.rst @@ -887,8 +887,8 @@ Showing Information .. clicmd:: show ip ospf route [detail] [json] Show the OSPF routing table, as determined by the most recent SPF - calculation. If detail is specified, each routing item's - advertiser will be show up. + calculation. When detail option is used, it shows more information + to the CLI like advertising router ID for each route, etc. .. clicmd:: show ip ospf [vrf ] border-routers [json] diff --git a/ospfd/ospf_route.c b/ospfd/ospf_route.c index e32e06e7a4..3ffa7c0bb1 100644 --- a/ospfd/ospf_route.c +++ b/ospfd/ospf_route.c @@ -48,6 +48,7 @@ struct ospf_route *ospf_route_new(void) new->paths = list_new(); new->paths->del = (void (*)(void *))ospf_path_free; + new->u.std.transit = false; return new; } @@ -500,6 +501,7 @@ void ospf_intra_add_transit(struct route_table *rt, struct vertex *v, or->cost = v->distance; or->type = OSPF_DESTINATION_NETWORK; or->u.std.origin = (struct lsa_header *)lsa; + or->u.std.transit = true; ospf_route_copy_nexthops_from_vertex(area, or, v); diff --git a/ospfd/ospf_route.h b/ospfd/ospf_route.h index 7639a0049e..44e80216d7 100644 --- a/ospfd/ospf_route.h +++ b/ospfd/ospf_route.h @@ -69,6 +69,8 @@ struct route_standard { /* */ uint8_t flags; /* From router-LSA */ + + bool transit; /* Transit network or not */ }; struct route_external { diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 0438bbcdf8..a23802719b 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -10792,15 +10792,17 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, if (json) { json_object_string_add(json_route, "routeType", "N"); + json_object_boolean_add(json_route, "transit", + or->u.std.transit); json_object_int_add(json_route, "cost", or->cost); json_object_string_addf(json_route, "area", "%pI4", &or->u.std.area_id); } else { - vty_out(vty, "N %-18s [%d] area: %pI4\n", - buf1, or->cost, - &or->u.std.area_id); + vty_out(vty, "N %s %-18s [%d] area: %pI4\n", + or->u.std.transit && detail ? "T" : " ", + buf1, or->cost, &or->u.std.area_id); } break; default: @@ -10859,7 +10861,8 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, ospf->vrf_id)); json_object_string_addf( json_nexthop, - "adv", "%pI4", + "advertisedRouter", + "%pI4", &path->adv_router); } else { vty_out(vty, @@ -11134,7 +11137,8 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, path->ifindex, ospf->vrf_id)); json_object_string_addf( - json_nexthop, "adv", + json_nexthop, + "advertisedRouter", "%pI4", &path->adv_router); } else { @@ -11464,6 +11468,12 @@ static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, return CMD_SUCCESS; } + if (detail && json == NULL) { + vty_out(vty, "Codes: N - network T - transitive\n"); + vty_out(vty, " IA - inter-area E - external route\n"); + vty_out(vty, " D - destination R - router\n\n"); + } + /* Show Network routes. */ show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf, detail);