diff options
Diffstat (limited to 'zebra/zebra_vty.c')
| -rw-r--r-- | zebra/zebra_vty.c | 220 |
1 files changed, 145 insertions, 75 deletions
diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index b6d0b26125..6785151705 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -54,6 +54,7 @@ #include "zebra/zebra_vxlan_private.h" #include "zebra/zebra_pbr.h" #include "zebra/zebra_nhg.h" +#include "zebra/zebra_evpn_mh.h" #include "zebra/interface.h" #include "northbound_cli.h" #include "zebra/zebra_nb.h" @@ -61,12 +62,19 @@ extern int allow_delete; +/* context to manage dumps in multiple tables or vrfs */ +struct route_show_ctx { + bool multi; /* dump multiple tables or vrf */ + bool header_done; /* common header already displayed */ +}; + static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, safi_t safi, bool use_fib, bool use_json, route_tag_t tag, const struct prefix *longer_prefix_p, bool supernets_only, int type, - unsigned short ospf_instance_id, uint32_t tableid); + unsigned short ospf_instance_id, uint32_t tableid, + struct route_show_ctx *ctx); static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, int mcast, bool use_fib, bool show_ng); static void vty_show_ip_route_summary(struct vty *vty, @@ -140,8 +148,12 @@ DEFUN (show_ip_rpf, JSON_STR) { bool uj = use_json(argc, argv); + struct route_show_ctx ctx = { + .multi = false, + }; + return do_show_ip_route(vty, VRF_DEFAULT_NAME, AFI_IP, SAFI_MULTICAST, - false, uj, 0, NULL, false, 0, 0, 0); + false, uj, 0, NULL, false, 0, 0, 0, &ctx); } DEFUN (show_ip_rpf_addr, @@ -192,6 +204,14 @@ static char re_status_output_char(const struct route_entry *re, star_p = true; } + if (zrouter.asic_offloaded + && CHECK_FLAG(re->flags, ZEBRA_FLAG_TRAPPED)) + return 't'; + + if (zrouter.asic_offloaded + && !CHECK_FLAG(re->flags, ZEBRA_FLAG_OFFLOADED)) + return 'o'; + if (star_p) return '*'; else @@ -331,15 +351,8 @@ static void show_nexthop_detail_helper(struct vty *vty, } if ((re->vrf_id != nexthop->vrf_id) - && (nexthop->type != NEXTHOP_TYPE_BLACKHOLE)) { - struct vrf *vrf = - vrf_lookup_by_id(nexthop->vrf_id); - - if (vrf) - vty_out(vty, "(vrf %s)", vrf->name); - else - vty_out(vty, "(vrf UNKNOWN)"); - } + && (nexthop->type != NEXTHOP_TYPE_BLACKHOLE)) + vty_out(vty, "(vrf %s)", vrf_id_to_name(nexthop->vrf_id)); if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_DUPLICATE)) vty_out(vty, " (duplicate nexthop removed)"); @@ -537,15 +550,9 @@ static void show_route_nexthop_helper(struct vty *vty, break; } - if ((re == NULL || (nexthop->vrf_id != re->vrf_id)) && - (nexthop->type != NEXTHOP_TYPE_BLACKHOLE)) { - struct vrf *vrf = vrf_lookup_by_id(nexthop->vrf_id); - - if (vrf) - vty_out(vty, " (vrf %s)", vrf->name); - else - vty_out(vty, " (vrf UNKNOWN)"); - } + if ((re == NULL || (nexthop->vrf_id != re->vrf_id)) + && (nexthop->type != NEXTHOP_TYPE_BLACKHOLE)) + vty_out(vty, " (vrf %s)", vrf_id_to_name(nexthop->vrf_id)); if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE)) vty_out(vty, " inactive"); @@ -609,7 +616,6 @@ static void show_nexthop_json_helper(json_object *json_nexthop, const struct route_entry *re) { char buf[SRCDEST2STR_BUFFER]; - struct vrf *vrf = NULL; json_object *json_labels = NULL; json_object *json_backups = NULL; int i; @@ -703,11 +709,10 @@ static void show_nexthop_json_helper(json_object *json_nexthop, } if ((nexthop->vrf_id != re->vrf_id) - && (nexthop->type != NEXTHOP_TYPE_BLACKHOLE)) { - vrf = vrf_lookup_by_id(nexthop->vrf_id); + && (nexthop->type != NEXTHOP_TYPE_BLACKHOLE)) json_object_string_add(json_nexthop, "vrf", - vrf->name); - } + vrf_id_to_name(nexthop->vrf_id)); + if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_DUPLICATE)) json_object_boolean_true_add(json_nexthop, "duplicate"); @@ -802,7 +807,6 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, json_object *json_nexthop = NULL; json_object *json_route = NULL; time_t uptime; - const struct vrf *vrf = NULL; const rib_dest_t *dest = rib_dest_from_rnode(rn); const struct nexthop_group *nhg; char up_str[MONOTIME_STRLEN]; @@ -835,13 +839,10 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, json_object_int_add(json_route, "instance", re->instance); - if (re->vrf_id) { - json_object_int_add(json_route, "vrfId", re->vrf_id); - vrf = vrf_lookup_by_id(re->vrf_id); - json_object_string_add(json_route, "vrfName", - vrf->name); + json_object_int_add(json_route, "vrfId", re->vrf_id); + json_object_string_add(json_route, "vrfName", + vrf_id_to_name(re->vrf_id)); - } if (CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED)) json_object_boolean_true_add(json_route, "selected"); @@ -862,6 +863,12 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, if (CHECK_FLAG(re->status, ROUTE_ENTRY_QUEUED)) json_object_boolean_true_add(json_route, "queued"); + if (CHECK_FLAG(re->flags, ZEBRA_FLAG_TRAPPED)) + json_object_boolean_true_add(json_route, "trapped"); + + if (CHECK_FLAG(re->flags, ZEBRA_FLAG_OFFLOADED)) + json_object_boolean_true_add(json_route, "offloaded"); + if (re->tag) json_object_int_add(json_route, "tag", re->tag); @@ -1038,7 +1045,7 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, const struct prefix *longer_prefix_p, bool supernets_only, int type, unsigned short ospf_instance_id, bool use_json, - uint32_t tableid) + uint32_t tableid, struct route_show_ctx *ctx) { struct route_node *rn; struct route_entry *re; @@ -1049,6 +1056,17 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, uint32_t addr; char buf[BUFSIZ]; + /* + * ctx->multi indicates if we are dumping multiple tables or vrfs. + * if set: + * => display the common header at most once + * => add newline at each call except first + * => always display the VRF and table + * else: + * => display the common header if at least one entry is found + * => display the VRF and table if specific + */ + if (use_json) json = json_object_new_object(); @@ -1092,23 +1110,30 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, if (use_json) { if (!json_prefix) json_prefix = json_object_new_array(); - } else { - if (first) { + } else if (first) { + if (!ctx->header_done) { if (afi == AFI_IP) vty_out(vty, SHOW_ROUTE_V4_HEADER); else vty_out(vty, SHOW_ROUTE_V6_HEADER); - - if (tableid && tableid != RT_TABLE_MAIN) - vty_out(vty, "\nVRF %s table %u:\n", - zvrf_name(zvrf), tableid); - else if (zvrf_id(zvrf) != VRF_DEFAULT) - vty_out(vty, "\nVRF %s:\n", + } + if (ctx->multi && ctx->header_done) + vty_out(vty, "\n"); + if (ctx->multi || zvrf_id(zvrf) != VRF_DEFAULT + || tableid) { + if (!tableid) + vty_out(vty, "VRF %s:\n", zvrf_name(zvrf)); - first = 0; + else + vty_out(vty, + "VRF %s table %u:\n", + zvrf_name(zvrf), + tableid); } + ctx->header_done = true; + first = 0; } vty_show_ip_route(vty, rn, re, json_prefix, use_fib); @@ -1133,7 +1158,8 @@ static void do_show_ip_route_all(struct vty *vty, struct zebra_vrf *zvrf, route_tag_t tag, const struct prefix *longer_prefix_p, bool supernets_only, int type, - unsigned short ospf_instance_id) + unsigned short ospf_instance_id, + struct route_show_ctx *ctx) { struct zebra_router_table *zrt; struct rib_table_info *info; @@ -1148,11 +1174,10 @@ static void do_show_ip_route_all(struct vty *vty, struct zebra_vrf *zvrf, zrt->safi != SAFI_UNICAST) continue; - do_show_ip_route(vty, zvrf_name(zvrf), afi, - SAFI_UNICAST, use_fib, use_json, - tag, longer_prefix_p, - supernets_only, type, - ospf_instance_id, zrt->tableid); + do_show_ip_route(vty, zvrf_name(zvrf), afi, SAFI_UNICAST, + use_fib, use_json, tag, longer_prefix_p, + supernets_only, type, ospf_instance_id, + zrt->tableid, ctx); } } @@ -1161,7 +1186,8 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, route_tag_t tag, const struct prefix *longer_prefix_p, bool supernets_only, int type, - unsigned short ospf_instance_id, uint32_t tableid) + unsigned short ospf_instance_id, uint32_t tableid, + struct route_show_ctx *ctx) { struct route_table *table; struct zebra_vrf *zvrf = NULL; @@ -1194,7 +1220,7 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, do_show_route_helper(vty, zvrf, table, afi, use_fib, tag, longer_prefix_p, supernets_only, type, - ospf_instance_id, use_json, tableid); + ospf_instance_id, use_json, tableid, ctx); return CMD_SUCCESS; } @@ -1272,21 +1298,11 @@ static void show_nexthop_group_out(struct vty *vty, struct nhg_hash_entry *nhe) { struct nexthop *nexthop = NULL; struct nhg_connected *rb_node_dep = NULL; - struct vrf *nhe_vrf = vrf_lookup_by_id(nhe->vrf_id); struct nexthop_group *backup_nhg; - vty_out(vty, "ID: %u\n", nhe->id); + vty_out(vty, "ID: %u (%s)\n", nhe->id, zebra_route_string(nhe->type)); vty_out(vty, " RefCnt: %d\n", nhe->refcnt); - - if (nhe_vrf) - vty_out(vty, " VRF: %s AFI: %s\n", nhe_vrf->name, - afi2str(nhe->afi)); - else - vty_out(vty, " VRF: UNKNOWN AFI: %s\n", - afi2str(nhe->afi)); - - if (CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_UNHASHABLE)) - vty_out(vty, " Duplicate - from kernel not hashable\n"); + vty_out(vty, " VRF: %s\n", vrf_id_to_name(nhe->vrf_id)); if (CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_VALID)) { vty_out(vty, " Valid"); @@ -1550,6 +1566,17 @@ DEFPY_HIDDEN(nexthop_group_use_enable, return CMD_SUCCESS; } +DEFPY_HIDDEN(proto_nexthop_group_only, proto_nexthop_group_only_cmd, + "[no] zebra nexthop proto only", + NO_STR ZEBRA_STR + "Nexthop configuration\n" + "Configure exclusive use of proto nexthops\n" + "Only use proto nexthops\n") +{ + zebra_nhg_set_proto_nexthops_only(!no); + return CMD_SUCCESS; +} + DEFUN (no_ip_nht_default_route, no_ip_nht_default_route_cmd, "no ip nht resolve-via-default", @@ -1671,6 +1698,9 @@ DEFPY (show_route, struct vrf *vrf; int type = 0; struct zebra_vrf *zvrf; + struct route_show_ctx ctx = { + .multi = vrf_all || table_all, + }; if (!vrf_is_backend_netns()) { if ((vrf_all || vrf_name) && (table || table_all)) { @@ -1698,17 +1728,18 @@ DEFPY (show_route, continue; if (table_all) - do_show_ip_route_all(vty, zvrf, afi, - !!fib, !!json, - tag, prefix_str ? prefix : NULL, + do_show_ip_route_all(vty, zvrf, afi, !!fib, + !!json, tag, + prefix_str ? prefix : NULL, !!supernets_only, type, - ospf_instance_id); + ospf_instance_id, &ctx); else do_show_ip_route(vty, zvrf_name(zvrf), afi, - SAFI_UNICAST, !!fib, !!json, tag, + SAFI_UNICAST, !!fib, !!json, + tag, prefix_str ? prefix : NULL, !!supernets_only, type, - ospf_instance_id, table); + ospf_instance_id, table, &ctx); } } else { vrf_id_t vrf_id = VRF_DEFAULT; @@ -1722,15 +1753,16 @@ DEFPY (show_route, return CMD_SUCCESS; if (table_all) - do_show_ip_route_all(vty, zvrf, afi, - !!fib, !!json, - tag, prefix_str ? prefix : NULL, + do_show_ip_route_all(vty, zvrf, afi, !!fib, !!json, tag, + prefix_str ? prefix : NULL, !!supernets_only, type, - ospf_instance_id); + ospf_instance_id, &ctx); else - do_show_ip_route(vty, vrf->name, afi, SAFI_UNICAST, !!fib, - !!json, tag, prefix_str ? prefix : NULL, - !!supernets_only, type, ospf_instance_id, table); + do_show_ip_route(vty, vrf->name, afi, SAFI_UNICAST, + !!fib, !!json, tag, + prefix_str ? prefix : NULL, + !!supernets_only, type, + ospf_instance_id, table, &ctx); } return CMD_SUCCESS; @@ -2346,6 +2378,33 @@ DEFUN (show_vrf, return CMD_SUCCESS; } +DEFPY (evpn_mh_mac_holdtime, + evpn_mh_mac_holdtime_cmd, + "[no$no] evpn mh mac-holdtime (0-86400)$duration", + NO_STR + "EVPN\n" + "Multihoming\n" + "MAC hold time\n" + "Duration in seconds\n") +{ + return zebra_evpn_mh_mac_holdtime_update(vty, duration, + no ? true : false); +} + +DEFPY (evpn_mh_neigh_holdtime, + evpn_mh_neigh_holdtime_cmd, + "[no$no] evpn mh neigh-holdtime (0-86400)$duration", + NO_STR + "EVPN\n" + "Multihoming\n" + "Neighbor entry hold time\n" + "Duration in seconds\n") +{ + + return zebra_evpn_mh_neigh_holdtime_update(vty, duration, + no ? true : false); +} + DEFUN (default_vrf_vni_mapping, default_vrf_vni_mapping_cmd, "vni " CMD_VNI_RANGE "[prefix-routes-only]", @@ -3394,10 +3453,15 @@ static int config_write_protocol(struct vty *vty) /* Include dataplane info */ dplane_config_write_helper(vty); + zebra_evpn_mh_config_write(vty); + /* Include nexthop-group config */ if (!zebra_nhg_kernel_nexthops_enabled()) vty_out(vty, "no zebra nexthop kernel enable\n"); + if (zebra_nhg_proto_nexthops_only()) + vty_out(vty, "zebra nexthop proto only\n"); + #ifdef HAVE_NETLINK /* Include netlink info */ netlink_config_write_helper(vty); @@ -3414,6 +3478,9 @@ DEFUN (show_zebra, { struct vrf *vrf; + if (zrouter.asic_offloaded) + vty_out(vty, "Asic Offload is being used\n"); + vty_out(vty, " Route Route Neighbor LSP LSP\n"); vty_out(vty, @@ -3829,6 +3896,7 @@ void zebra_vty_init(void) install_element(CONFIG_NODE, &zebra_packet_process_cmd); install_element(CONFIG_NODE, &no_zebra_packet_process_cmd); install_element(CONFIG_NODE, &nexthop_group_use_enable_cmd); + install_element(CONFIG_NODE, &proto_nexthop_group_only_cmd); install_element(VIEW_NODE, &show_nexthop_group_cmd); install_element(VIEW_NODE, &show_interface_nexthop_group_cmd); @@ -3890,6 +3958,8 @@ void zebra_vty_init(void) install_element(VIEW_NODE, &show_pbr_ipset_cmd); install_element(VIEW_NODE, &show_pbr_iptable_cmd); + install_element(CONFIG_NODE, &evpn_mh_mac_holdtime_cmd); + install_element(CONFIG_NODE, &evpn_mh_neigh_holdtime_cmd); install_element(CONFIG_NODE, &default_vrf_vni_mapping_cmd); install_element(CONFIG_NODE, &no_default_vrf_vni_mapping_cmd); install_element(VRF_NODE, &vrf_vni_mapping_cmd); |
