diff --git a/yang/frr-zebra.yang b/yang/frr-zebra.yang index 0997a268e75c..4aeba1412903 100644 --- a/yang/frr-zebra.yang +++ b/yang/frr-zebra.yang @@ -632,45 +632,44 @@ module frr-zebra { "RIBs supported by FRR."; list rib { key "afi-safi-name table-id"; - leaf table-id { - type uint32; - description - "Routing Table id (default id - 254)."; - } - leaf afi-safi-name { type identityref { base afi-safi-type; } - mandatory true; description "AFI, SAFI name."; } + leaf table-id { + type uint32; + description + "Routing Table id (default id - 254)."; + } + list route { key "prefix"; config false; leaf prefix { - type inet:ip-prefix; - description - "The route's prefix."; + type inet:ip-prefix; + description + "The route's prefix."; } + list route-entry { key "protocol"; leaf protocol { - type frr-route-types:frr-route-types-v4; - //TODO: Use unified route types done in PR 5183 when it is merged. - //type frr-route-types:frr-route-types; - description - "The protocol owning the route."; + type frr-route-types:frr-route-types; + description + "The protocol owning the route."; } leaf instance { type uint16; must "../protocol = \"ospf\""; description - "Retrieve routes from a specific OSPF instance."; + "Retrieve routes from a specific OSPF instance."; } + uses route-common; } } @@ -2070,10 +2069,12 @@ module frr-zebra { augment "/frr-vrf:lib/frr-vrf:vrf" { description "Extends VRF model with Zebra-related parameters."; - uses ribs; + container zebra { + uses ribs; + } } - augment "/frr-vrf:lib/frr-vrf:vrf/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop" { + augment "/frr-vrf:lib/frr-vrf:vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop" { uses frr-nh:frr-nexthop-operational; } diff --git a/zebra/rib.h b/zebra/rib.h index 1667f1790966..0b4455038712 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -251,12 +251,22 @@ DECLARE_LIST(re_list, struct route_entry, next); (re) && ((next) = re_list_next(&((dest)->routes), (re)), 1); \ (re) = (next)) +#define RE_DEST_FIRST_ROUTE(dest, re) \ + ((re) = (dest) ? re_list_first(&((dest)->routes)) : NULL) + +#define RE_DEST_NEXT_ROUTE(dest, re) \ + ((re) = (dest) ? re_list_next(&((dest)->routes), (re)) : NULL) + #define RNODE_FOREACH_RE(rn, re) \ RE_DEST_FOREACH_ROUTE (rib_dest_from_rnode(rn), re) #define RNODE_FOREACH_RE_SAFE(rn, re, next) \ RE_DEST_FOREACH_ROUTE_SAFE (rib_dest_from_rnode(rn), re, next) +#define RNODE_FIRST_RE(rn, re) RE_DEST_FIRST_ROUTE(rib_dest_from_rnode(rn), re) + +#define RNODE_NEXT_RE(rn, re) RE_DEST_NEXT_ROUTE(rib_dest_from_rnode(rn), re) + #if defined(HAVE_RTADV) /* Structure which hold status of router advertisement. */ struct rtadv { diff --git a/zebra/zebra_nb.c b/zebra/zebra_nb.c index 1f3468d6dcb4..25b8b44ec93f 100644 --- a/zebra/zebra_nb.c +++ b/zebra/zebra_nb.c @@ -22,6 +22,40 @@ #include "libfrr.h" #include "zebra_nb.h" +const char *zebra_afi_safi_value2identity(afi_t afi, safi_t safi) +{ + if (afi == AFI_IP && safi == SAFI_UNICAST) + return "ipv4-unicast"; + if (afi == AFI_IP6 && safi == SAFI_UNICAST) + return "ipv6-unicast"; + if (afi == AFI_IP && safi == SAFI_MULTICAST) + return "ipv4-multicast"; + if (afi == AFI_IP6 && safi == SAFI_MULTICAST) + return "ipv6-multicast"; + + return " "; +} + +void zebra_afi_safi_identity2value(const char *key, afi_t *afi, safi_t *safi) +{ + if (strmatch(key, "frr-zebra:ipv4-unicast")) { + *afi = AFI_IP; + *safi = SAFI_UNICAST; + } else if (strmatch(key, "frr-zebra:ipv6-unicast")) { + *afi = AFI_IP6; + *safi = SAFI_UNICAST; + } else if (strmatch(key, "frr-zebra:ipv4-multicast")) { + *afi = AFI_IP; + *safi = SAFI_MULTICAST; + } else if (strmatch(key, "frr-zebra:ipv6-multicast")) { + *afi = AFI_IP6; + *safi = SAFI_MULTICAST; + } else { + *afi = AFI_UNSPEC; + *safi = SAFI_UNSPEC; + } +} + /* clang-format off */ const struct frr_yang_module_info frr_zebra_info = { .name = "frr-zebra", @@ -420,221 +454,221 @@ const struct frr_yang_module_info frr_zebra_info = { } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib", .cbs = { - .create = lib_vrf_ribs_rib_create, - .destroy = lib_vrf_ribs_rib_destroy, - .get_next = lib_vrf_ribs_rib_get_next, - .get_keys = lib_vrf_ribs_rib_get_keys, - .lookup_entry = lib_vrf_ribs_rib_lookup_entry, + .create = lib_vrf_zebra_ribs_rib_create, + .destroy = lib_vrf_zebra_ribs_rib_destroy, + .get_next = lib_vrf_zebra_ribs_rib_get_next, + .get_keys = lib_vrf_zebra_ribs_rib_get_keys, + .lookup_entry = lib_vrf_zebra_ribs_rib_lookup_entry, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route", .cbs = { - .get_next = lib_vrf_ribs_rib_route_get_next, - .get_keys = lib_vrf_ribs_rib_route_get_keys, - .lookup_entry = lib_vrf_ribs_rib_route_lookup_entry, + .get_next = lib_vrf_zebra_ribs_rib_route_get_next, + .get_keys = lib_vrf_zebra_ribs_rib_route_get_keys, + .lookup_entry = lib_vrf_zebra_ribs_rib_route_lookup_entry, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/prefix", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/prefix", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_prefix_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_prefix_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry", .cbs = { - .get_next = lib_vrf_ribs_rib_route_route_entry_get_next, - .get_keys = lib_vrf_ribs_rib_route_route_entry_get_keys, - .lookup_entry = lib_vrf_ribs_rib_route_route_entry_lookup_entry, + .get_next = lib_vrf_zebra_ribs_rib_route_route_entry_get_next, + .get_keys = lib_vrf_zebra_ribs_rib_route_route_entry_get_keys, + .lookup_entry = lib_vrf_zebra_ribs_rib_route_route_entry_lookup_entry, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/protocol", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/protocol", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_protocol_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_protocol_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/instance", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/instance", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_instance_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_instance_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/distance", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/distance", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_distance_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_distance_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/metric", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/metric", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_metric_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_metric_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/tag", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/tag", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_tag_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_tag_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/selected", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/selected", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_selected_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_selected_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/installed", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/installed", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_installed_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_installed_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/failed", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/failed", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_failed_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_failed_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/queued", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/queued", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_queued_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_queued_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/internal-flags", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/internal-flags", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_internal_flags_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_internal_flags_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/internal-status", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/internal-status", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_internal_status_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_internal_status_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/uptime", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/uptime", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_uptime_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_uptime_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group", .cbs = { - .get_next = lib_vrf_ribs_rib_route_route_entry_nexthop_group_get_next, - .get_keys = lib_vrf_ribs_rib_route_route_entry_nexthop_group_get_keys, - .lookup_entry = lib_vrf_ribs_rib_route_route_entry_nexthop_group_lookup_entry, + .get_next = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_get_next, + .get_keys = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_get_keys, + .lookup_entry = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_lookup_entry, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/name", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/name", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_nexthop_group_name_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_name_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop", .cbs = { - .get_next = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_get_next, - .get_keys = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_get_keys, - .lookup_entry = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_lookup_entry, + .get_next = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_get_next, + .get_keys = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_get_keys, + .lookup_entry = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_lookup_entry, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/nh-type", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/nh-type", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_nh_type_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_nh_type_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/vrf", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/vrf", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_vrf_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_vrf_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/gateway", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/gateway", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_gateway_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_gateway_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/interface", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/interface", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_interface_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_interface_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/bh-type", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/bh-type", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_bh_type_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_bh_type_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/onlink", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/onlink", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_onlink_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_onlink_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry", .cbs = { - .get_next = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_get_next, - .get_keys = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_get_keys, - .lookup_entry = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_lookup_entry, + .get_next = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_get_next, + .get_keys = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_get_keys, + .lookup_entry = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_lookup_entry, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry/id", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry/id", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_id_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_id_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry/label", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry/label", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_label_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_label_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry/ttl", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry/ttl", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry/traffic-class", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry/traffic-class", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/duplicate", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/duplicate", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_duplicate_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_duplicate_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/recursive", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/recursive", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_recursive_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_recursive_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/active", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/active", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_active_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_active_get_elem, } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/fib", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/fib", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_fib_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_fib_get_elem, } }, { @@ -680,9 +714,9 @@ const struct frr_yang_module_info frr_zebra_info = { } }, { - .xpath = "/frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/weight", + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/weight", .cbs = { - .get_elem = lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_weight_get_elem, + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_weight_get_elem, } }, { diff --git a/zebra/zebra_nb.h b/zebra/zebra_nb.h index 09a9edff99a4..15350eb53bf1 100644 --- a/zebra/zebra_nb.h +++ b/zebra/zebra_nb.h @@ -26,6 +26,10 @@ extern "C" { extern const struct frr_yang_module_info frr_zebra_info; +/* helper functions */ +const char *zebra_afi_safi_value2identity(afi_t afi, safi_t safi); +void zebra_afi_safi_identity2value(const char *key, afi_t *afi, safi_t *safi); + /* prototypes */ int get_route_information_rpc(struct nb_cb_rpc_args *args); int get_v6_mroute_info_rpc(struct nb_cb_rpc_args *args); @@ -155,165 +159,172 @@ struct yang_data *lib_interface_zebra_state_remote_vtep_get_elem( struct nb_cb_get_elem_args *args); struct yang_data *lib_interface_zebra_state_mcast_group_get_elem( struct nb_cb_get_elem_args *args); -int lib_vrf_ribs_rib_create(struct nb_cb_create_args *args); -int lib_vrf_ribs_rib_destroy(struct nb_cb_destroy_args *args); -const void *lib_vrf_ribs_rib_get_next(struct nb_cb_get_next_args *args); -int lib_vrf_ribs_rib_get_keys(struct nb_cb_get_keys_args *args); -const void *lib_vrf_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args); -const void *lib_vrf_ribs_rib_route_get_next(struct nb_cb_get_next_args *args); -int lib_vrf_ribs_rib_route_get_keys(struct nb_cb_get_keys_args *args); +int lib_vrf_zebra_ribs_rib_create(struct nb_cb_create_args *args); +int lib_vrf_zebra_ribs_rib_destroy(struct nb_cb_destroy_args *args); +const void *lib_vrf_zebra_ribs_rib_get_next(struct nb_cb_get_next_args *args); +int lib_vrf_zebra_ribs_rib_get_keys(struct nb_cb_get_keys_args *args); const void * -lib_vrf_ribs_rib_route_lookup_entry(struct nb_cb_lookup_entry_args *args); -struct yang_data * -lib_vrf_ribs_rib_route_prefix_get_elem(struct nb_cb_get_elem_args *args); -struct yang_data * -lib_vrf_ribs_rib_route_protocol_get_elem(struct nb_cb_get_elem_args *args); -struct yang_data * -lib_vrf_ribs_rib_route_protocol_v6_get_elem(struct nb_cb_get_elem_args *args); -struct yang_data * -lib_vrf_ribs_rib_route_vrf_get_elem(struct nb_cb_get_elem_args *args); -struct yang_data * -lib_vrf_ribs_rib_route_distance_get_elem(struct nb_cb_get_elem_args *args); +lib_vrf_zebra_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args); +const void * +lib_vrf_zebra_ribs_rib_route_get_next(struct nb_cb_get_next_args *args); +int lib_vrf_zebra_ribs_rib_route_get_keys(struct nb_cb_get_keys_args *args); +const void * +lib_vrf_zebra_ribs_rib_route_lookup_entry(struct nb_cb_lookup_entry_args *args); struct yang_data * -lib_vrf_ribs_rib_route_metric_get_elem(struct nb_cb_get_elem_args *args); +lib_vrf_zebra_ribs_rib_route_prefix_get_elem(struct nb_cb_get_elem_args *args); +struct yang_data *lib_vrf_zebra_ribs_rib_route_protocol_get_elem( + struct nb_cb_get_elem_args *args); +struct yang_data *lib_vrf_zebra_ribs_rib_route_protocol_v6_get_elem( + struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_tag_get_elem(struct nb_cb_get_elem_args *args); +lib_vrf_zebra_ribs_rib_route_vrf_get_elem(struct nb_cb_get_elem_args *args); +struct yang_data *lib_vrf_zebra_ribs_rib_route_distance_get_elem( + struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_selected_get_elem(struct nb_cb_get_elem_args *args); +lib_vrf_zebra_ribs_rib_route_metric_get_elem(struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_installed_get_elem(struct nb_cb_get_elem_args *args); +lib_vrf_zebra_ribs_rib_route_tag_get_elem(struct nb_cb_get_elem_args *args); +struct yang_data *lib_vrf_zebra_ribs_rib_route_selected_get_elem( + struct nb_cb_get_elem_args *args); +struct yang_data *lib_vrf_zebra_ribs_rib_route_installed_get_elem( + struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_failed_get_elem(struct nb_cb_get_elem_args *args); +lib_vrf_zebra_ribs_rib_route_failed_get_elem(struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_queued_get_elem(struct nb_cb_get_elem_args *args); -struct yang_data *lib_vrf_ribs_rib_route_internal_flags_get_elem( +lib_vrf_zebra_ribs_rib_route_queued_get_elem(struct nb_cb_get_elem_args *args); +struct yang_data *lib_vrf_zebra_ribs_rib_route_internal_flags_get_elem( struct nb_cb_get_elem_args *args); -struct yang_data *lib_vrf_ribs_rib_route_internal_status_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_internal_status_get_elem( struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_uptime_get_elem(struct nb_cb_get_elem_args *args); -const void * -lib_vrf_ribs_rib_route_nexthop_group_get_next(struct nb_cb_get_next_args *args); -int lib_vrf_ribs_rib_route_nexthop_group_get_keys( +lib_vrf_zebra_ribs_rib_route_uptime_get_elem(struct nb_cb_get_elem_args *args); +const void *lib_vrf_zebra_ribs_rib_route_nexthop_group_get_next( + struct nb_cb_get_next_args *args); +int lib_vrf_zebra_ribs_rib_route_nexthop_group_get_keys( struct nb_cb_get_keys_args *args); -const void *lib_vrf_ribs_rib_route_nexthop_group_lookup_entry( +const void *lib_vrf_zebra_ribs_rib_route_nexthop_group_lookup_entry( struct nb_cb_lookup_entry_args *args); -struct yang_data *lib_vrf_ribs_rib_route_nexthop_group_name_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_nexthop_group_name_get_elem( struct nb_cb_get_elem_args *args); -const void *lib_vrf_ribs_rib_route_nexthop_group_frr_nexthops_nexthop_get_next( +const void * +lib_vrf_zebra_ribs_rib_route_nexthop_group_frr_nexthops_nexthop_get_next( struct nb_cb_get_next_args *args); -int lib_vrf_ribs_rib_route_nexthop_group_frr_nexthops_nexthop_get_keys( +int lib_vrf_zebra_ribs_rib_route_nexthop_group_frr_nexthops_nexthop_get_keys( struct nb_cb_get_keys_args *args); -int lib_vrf_ribs_rib_create(struct nb_cb_create_args *args); -int lib_vrf_ribs_rib_destroy(struct nb_cb_destroy_args *args); -const void *lib_vrf_ribs_rib_get_next(struct nb_cb_get_next_args *args); -int lib_vrf_ribs_rib_get_keys(struct nb_cb_get_keys_args *args); -const void *lib_vrf_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args); -const void *lib_vrf_ribs_rib_route_get_next(struct nb_cb_get_next_args *args); -int lib_vrf_ribs_rib_route_get_keys(struct nb_cb_get_keys_args *args); +int lib_vrf_zebra_ribs_rib_create(struct nb_cb_create_args *args); +int lib_vrf_zebra_ribs_rib_destroy(struct nb_cb_destroy_args *args); +const void *lib_vrf_zebra_ribs_rib_get_next(struct nb_cb_get_next_args *args); +int lib_vrf_zebra_ribs_rib_get_keys(struct nb_cb_get_keys_args *args); const void * -lib_vrf_ribs_rib_route_lookup_entry(struct nb_cb_lookup_entry_args *args); -struct yang_data * -lib_vrf_ribs_rib_route_prefix_get_elem(struct nb_cb_get_elem_args *args); +lib_vrf_zebra_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args); const void * -lib_vrf_ribs_rib_route_route_entry_get_next(struct nb_cb_get_next_args *args); -int lib_vrf_ribs_rib_route_route_entry_get_keys( +lib_vrf_zebra_ribs_rib_route_get_next(struct nb_cb_get_next_args *args); +int lib_vrf_zebra_ribs_rib_route_get_keys(struct nb_cb_get_keys_args *args); +const void * +lib_vrf_zebra_ribs_rib_route_lookup_entry(struct nb_cb_lookup_entry_args *args); +struct yang_data * +lib_vrf_zebra_ribs_rib_route_prefix_get_elem(struct nb_cb_get_elem_args *args); +const void *lib_vrf_zebra_ribs_rib_route_route_entry_get_next( + struct nb_cb_get_next_args *args); +int lib_vrf_zebra_ribs_rib_route_route_entry_get_keys( struct nb_cb_get_keys_args *args); -const void *lib_vrf_ribs_rib_route_route_entry_lookup_entry( +const void *lib_vrf_zebra_ribs_rib_route_route_entry_lookup_entry( struct nb_cb_lookup_entry_args *args); -struct yang_data *lib_vrf_ribs_rib_route_route_entry_protocol_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_protocol_get_elem( struct nb_cb_get_elem_args *args); -struct yang_data *lib_vrf_ribs_rib_route_route_entry_instance_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_instance_get_elem( struct nb_cb_get_elem_args *args); -struct yang_data *lib_vrf_ribs_rib_route_route_entry_distance_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_distance_get_elem( struct nb_cb_get_elem_args *args); -struct yang_data *lib_vrf_ribs_rib_route_route_entry_metric_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_metric_get_elem( struct nb_cb_get_elem_args *args); -struct yang_data *lib_vrf_ribs_rib_route_route_entry_tag_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_tag_get_elem( struct nb_cb_get_elem_args *args); -struct yang_data *lib_vrf_ribs_rib_route_route_entry_selected_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_selected_get_elem( struct nb_cb_get_elem_args *args); -struct yang_data *lib_vrf_ribs_rib_route_route_entry_installed_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_installed_get_elem( struct nb_cb_get_elem_args *args); -struct yang_data *lib_vrf_ribs_rib_route_route_entry_failed_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_failed_get_elem( struct nb_cb_get_elem_args *args); -struct yang_data *lib_vrf_ribs_rib_route_route_entry_queued_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_queued_get_elem( struct nb_cb_get_elem_args *args); -struct yang_data *lib_vrf_ribs_rib_route_route_entry_internal_flags_get_elem( +struct yang_data * +lib_vrf_zebra_ribs_rib_route_route_entry_internal_flags_get_elem( struct nb_cb_get_elem_args *args); -struct yang_data *lib_vrf_ribs_rib_route_route_entry_internal_status_get_elem( +struct yang_data * +lib_vrf_zebra_ribs_rib_route_route_entry_internal_status_get_elem( struct nb_cb_get_elem_args *args); -struct yang_data *lib_vrf_ribs_rib_route_route_entry_uptime_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_uptime_get_elem( struct nb_cb_get_elem_args *args); -const void *lib_vrf_ribs_rib_route_route_entry_nexthop_group_get_next( +const void *lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_get_next( struct nb_cb_get_next_args *args); -int lib_vrf_ribs_rib_route_route_entry_nexthop_group_get_keys( +int lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_get_keys( struct nb_cb_get_keys_args *args); -const void *lib_vrf_ribs_rib_route_route_entry_nexthop_group_lookup_entry( +const void *lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_lookup_entry( struct nb_cb_lookup_entry_args *args); struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_name_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_name_get_elem( struct nb_cb_get_elem_args *args); const void * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_get_next( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_get_next( struct nb_cb_get_next_args *args); -int lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_get_keys( +int lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_get_keys( struct nb_cb_get_keys_args *args); const void * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_lookup_entry( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_lookup_entry( struct nb_cb_lookup_entry_args *args); struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_nh_type_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_nh_type_get_elem( struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_vrf_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_vrf_get_elem( struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_gateway_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_gateway_get_elem( struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_interface_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_interface_get_elem( struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_bh_type_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_bh_type_get_elem( struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_onlink_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_onlink_get_elem( struct nb_cb_get_elem_args *args); const void * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_get_next( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_get_next( struct nb_cb_get_next_args *args); -int lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_get_keys( +int lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_get_keys( struct nb_cb_get_keys_args *args); const void * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_lookup_entry( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_lookup_entry( struct nb_cb_lookup_entry_args *args); struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_id_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_id_get_elem( struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_label_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_label_get_elem( struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_get_elem( struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_get_elem( struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_duplicate_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_duplicate_get_elem( struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_recursive_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_recursive_get_elem( struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_active_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_active_get_elem( struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_fib_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_fib_get_elem( struct nb_cb_get_elem_args *args); struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_weight_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_weight_get_elem( struct nb_cb_get_elem_args *args); #ifdef __cplusplus diff --git a/zebra/zebra_nb_config.c b/zebra/zebra_nb_config.c index dbe265da8c2d..5b87a18a068c 100644 --- a/zebra/zebra_nb_config.c +++ b/zebra/zebra_nb_config.c @@ -29,6 +29,8 @@ #include "zebra_nb.h" #include "zebra/interface.h" #include "zebra/connected.h" +#include "zebra/zebra_router.h" +#include "zebra/debug.h" /* * XPath: /frr-zebra:zebra/mcast-rpf-lookup @@ -1216,32 +1218,56 @@ int lib_interface_zebra_bandwidth_destroy(struct nb_cb_destroy_args *args) } /* - * XPath: /frr-vrf:lib/vrf/frr-zebra:ribs/rib + * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib */ -int lib_vrf_ribs_rib_create(struct nb_cb_create_args *args) +int lib_vrf_zebra_ribs_rib_create(struct nb_cb_create_args *args) { + struct vrf *vrf; + afi_t afi; + safi_t safi; + struct zebra_vrf *zvrf; + struct zebra_router_table *zrt; + uint32_t table_id; + const char *afi_safi_name; + + vrf = nb_running_get_entry(args->dnode, NULL, false); + zvrf = vrf_info_lookup(vrf->vrf_id); + table_id = yang_dnode_get_uint32(args->dnode, "./table-id"); + if (!table_id) + table_id = zvrf->table_id; + + afi_safi_name = yang_dnode_get_string(args->dnode, "./afi-safi-name"); + zebra_afi_safi_identity2value(afi_safi_name, &afi, &safi); + + zrt = zebra_router_find_zrt(zvrf, table_id, afi, safi); + switch (args->event) { case NB_EV_VALIDATE: + if (!zrt) { + zlog_debug("%s: vrf %s table is not found.", __func__, + vrf->name); + return NB_ERR_VALIDATION; + } + break; case NB_EV_PREPARE: case NB_EV_ABORT: + break; case NB_EV_APPLY: - /* TODO: implement me. */ + + nb_running_set_entry(args->dnode, zrt); + break; } return NB_OK; } -int lib_vrf_ribs_rib_destroy(struct nb_cb_destroy_args *args) +int lib_vrf_zebra_ribs_rib_destroy(struct nb_cb_destroy_args *args) { - switch (args->event) { - case NB_EV_VALIDATE: - case NB_EV_PREPARE: - case NB_EV_ABORT: - case NB_EV_APPLY: - /* TODO: implement me. */ - break; - } + if (args->event != NB_EV_APPLY) + return NB_OK; + + nb_running_unset_entry(args->dnode); return NB_OK; } diff --git a/zebra/zebra_nb_state.c b/zebra/zebra_nb_state.c index 09c76e6022fd..415c0d3f6d3b 100644 --- a/zebra/zebra_nb_state.c +++ b/zebra/zebra_nb_state.c @@ -22,6 +22,9 @@ #include "libfrr.h" #include "zebra_nb.h" #include "zebra/interface.h" +#include "zebra/zebra_router.h" +#include "zebra/debug.h" +#include "printfrr.h" /* * XPath: /frr-interface:lib/interface/frr-zebra:zebra/state/up-count @@ -147,218 +150,366 @@ lib_interface_zebra_state_mcast_group_get_elem(struct nb_cb_get_elem_args *args) return yang_data_new_ipv4(args->xpath, &vxlan_info->mcast_grp); } -const void *lib_vrf_ribs_rib_get_next(struct nb_cb_get_next_args *args) +const void *lib_vrf_zebra_ribs_rib_get_next(struct nb_cb_get_next_args *args) { - /* TODO: implement me. */ - return NULL; + struct vrf *vrf = (struct vrf *)args->parent_list_entry; + struct zebra_router_table *zrt = + (struct zebra_router_table *)args->list_entry; + + struct zebra_vrf *zvrf; + afi_t afi; + safi_t safi; + + zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id); + + if (args->list_entry == NULL) { + afi = AFI_IP; + safi = SAFI_UNICAST; + + zrt = zebra_router_find_zrt(zvrf, zvrf->table_id, afi, safi); + if (zrt == NULL) + return NULL; + } else { + zrt = RB_NEXT(zebra_router_table_head, zrt); + /* vrf_id/ns_id do not match, only walk for the given VRF */ + while (zrt && zrt->ns_id != zvrf->zns->ns_id) + zrt = RB_NEXT(zebra_router_table_head, zrt); + } + + return zrt; } -int lib_vrf_ribs_rib_get_keys(struct nb_cb_get_keys_args *args) +int lib_vrf_zebra_ribs_rib_get_keys(struct nb_cb_get_keys_args *args) { - /* TODO: implement me. */ + const struct zebra_router_table *zrt = args->list_entry; + + args->keys->num = 2; + + snprintfrr(args->keys->key[0], sizeof(args->keys->key[0]), "%s:%s", + "frr-zebra", + zebra_afi_safi_value2identity(zrt->afi, zrt->safi)); + snprintfrr(args->keys->key[1], sizeof(args->keys->key[1]), "%" PRIu32, + zrt->tableid); + return NB_OK; } -const void *lib_vrf_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args) +const void * +lib_vrf_zebra_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args) { - /* TODO: implement me. */ - return NULL; + struct vrf *vrf = (struct vrf *)args->parent_list_entry; + struct zebra_vrf *zvrf; + afi_t afi; + safi_t safi; + uint32_t table_id = 0; + + zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id); + + zebra_afi_safi_identity2value(args->keys->key[0], &afi, &safi); + table_id = yang_str2uint32(args->keys->key[1]); + /* table_id 0 assume vrf's table_id. */ + if (!table_id) + table_id = zvrf->table_id; + + return zebra_router_find_zrt(zvrf, table_id, afi, safi); } /* - * XPath: /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route + * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route */ -const void *lib_vrf_ribs_rib_route_get_next(struct nb_cb_get_next_args *args) +const void * +lib_vrf_zebra_ribs_rib_route_get_next(struct nb_cb_get_next_args *args) { - /* TODO: implement me. */ - return NULL; + const struct zebra_router_table *zrt = args->parent_list_entry; + const struct route_node *rn = args->list_entry; + + if (args->list_entry == NULL) + rn = route_top(zrt->table); + else + rn = srcdest_route_next((struct route_node *)rn); + + return rn; } -int lib_vrf_ribs_rib_route_get_keys(struct nb_cb_get_keys_args *args) +int lib_vrf_zebra_ribs_rib_route_get_keys(struct nb_cb_get_keys_args *args) { - /* TODO: implement me. */ + const struct route_node *rn = args->list_entry; + + args->keys->num = 1; + prefix2str(&rn->p, args->keys->key[0], sizeof(args->keys->key[0])); + return NB_OK; } const void * -lib_vrf_ribs_rib_route_lookup_entry(struct nb_cb_lookup_entry_args *args) +lib_vrf_zebra_ribs_rib_route_lookup_entry(struct nb_cb_lookup_entry_args *args) { - /* TODO: implement me. */ - return NULL; + const struct zebra_router_table *zrt = args->parent_list_entry; + struct prefix p; + struct route_node *rn; + + yang_str2prefix(args->keys->key[0], &p); + + rn = route_node_lookup(zrt->table, &p); + + if (!rn) + return NULL; + + route_unlock_node(rn); + + return rn; } /* - * XPath: /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/prefix + * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/prefix */ struct yang_data * -lib_vrf_ribs_rib_route_prefix_get_elem(struct nb_cb_get_elem_args *args) +lib_vrf_zebra_ribs_rib_route_prefix_get_elem(struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ - return NULL; + const struct route_node *rn = args->list_entry; + + return yang_data_new_prefix(args->xpath, &rn->p); } /* - * XPath: /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry + * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry */ -const void * -lib_vrf_ribs_rib_route_route_entry_get_next(struct nb_cb_get_next_args *args) +const void *lib_vrf_zebra_ribs_rib_route_route_entry_get_next( + struct nb_cb_get_next_args *args) { - /* TODO: implement me. */ - return NULL; + struct route_entry *re = (struct route_entry *)args->list_entry; + struct route_node *rn = (struct route_node *)args->parent_list_entry; + + if (args->list_entry == NULL) + RNODE_FIRST_RE(rn, re); + else + RNODE_NEXT_RE(rn, re); + + return re; } -int lib_vrf_ribs_rib_route_route_entry_get_keys( +int lib_vrf_zebra_ribs_rib_route_route_entry_get_keys( struct nb_cb_get_keys_args *args) { - /* TODO: implement me. */ + struct route_entry *re = (struct route_entry *)args->list_entry; + + args->keys->num = 1; + + strlcpy(args->keys->key[0], zebra_route_string(re->type), + sizeof(args->keys->key[0])); + return NB_OK; } -const void *lib_vrf_ribs_rib_route_route_entry_lookup_entry( +const void *lib_vrf_zebra_ribs_rib_route_route_entry_lookup_entry( struct nb_cb_lookup_entry_args *args) { - /* TODO: implement me. */ + struct route_node *rn = (struct route_node *)args->parent_list_entry; + struct route_entry *re = NULL; + int proto_type = 0; + afi_t afi; + + afi = family2afi(rn->p.family); + proto_type = proto_redistnum(afi, args->keys->key[0]); + + RNODE_FOREACH_RE (rn, re) { + if (proto_type == re->type) + return re; + } + return NULL; } /* - * XPath: /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/protocol + * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/protocol */ -struct yang_data *lib_vrf_ribs_rib_route_route_entry_protocol_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_protocol_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ - return NULL; + struct route_entry *re = (struct route_entry *)args->list_entry; + + return yang_data_new_enum(args->xpath, re->type); } /* - * XPath: /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/instance + * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/instance */ -struct yang_data *lib_vrf_ribs_rib_route_route_entry_instance_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_instance_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ + struct route_entry *re = (struct route_entry *)args->list_entry; + + if (re->instance) + return yang_data_new_uint16(args->xpath, re->instance); + return NULL; } /* - * XPath: /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/distance + * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/distance */ -struct yang_data *lib_vrf_ribs_rib_route_route_entry_distance_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_distance_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ - return NULL; + struct route_entry *re = (struct route_entry *)args->list_entry; + + return yang_data_new_uint8(args->xpath, re->distance); } /* - * XPath: /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/metric + * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/metric */ -struct yang_data *lib_vrf_ribs_rib_route_route_entry_metric_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_metric_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ - return NULL; + struct route_entry *re = (struct route_entry *)args->list_entry; + + return yang_data_new_uint32(args->xpath, re->metric); } /* - * XPath: /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/tag + * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/tag */ -struct yang_data *lib_vrf_ribs_rib_route_route_entry_tag_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_tag_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ + struct route_entry *re = (struct route_entry *)args->list_entry; + + if (re->tag) + return yang_data_new_uint32(args->xpath, re->tag); + return NULL; } /* - * XPath: /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/selected + * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/selected */ -struct yang_data *lib_vrf_ribs_rib_route_route_entry_selected_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_selected_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ + struct route_entry *re = (struct route_entry *)args->list_entry; + + if (CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED)) + return yang_data_new_empty(args->xpath); + return NULL; } /* - * XPath: /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/installed + * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/installed */ -struct yang_data *lib_vrf_ribs_rib_route_route_entry_installed_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_installed_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ + struct route_entry *re = (struct route_entry *)args->list_entry; + + if (CHECK_FLAG(re->status, ROUTE_ENTRY_INSTALLED)) + return yang_data_new_empty(args->xpath); + return NULL; } /* - * XPath: /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/failed + * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/failed */ -struct yang_data *lib_vrf_ribs_rib_route_route_entry_failed_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_failed_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ + struct route_entry *re = (struct route_entry *)args->list_entry; + + if (CHECK_FLAG(re->status, ROUTE_ENTRY_FAILED)) + return yang_data_new_empty(args->xpath); + return NULL; } /* - * XPath: /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/queued + * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/queued */ -struct yang_data *lib_vrf_ribs_rib_route_route_entry_queued_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_queued_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ + struct route_entry *re = (struct route_entry *)args->list_entry; + + if (CHECK_FLAG(re->status, ROUTE_ENTRY_QUEUED)) + return yang_data_new_empty(args->xpath); + return NULL; } /* - * XPath: /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/internal-flags + * XPath: + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/internal-flags */ -struct yang_data *lib_vrf_ribs_rib_route_route_entry_internal_flags_get_elem( +struct yang_data * +lib_vrf_zebra_ribs_rib_route_route_entry_internal_flags_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ + struct route_entry *re = (struct route_entry *)args->list_entry; + + if (re->flags) + return yang_data_new_int32(args->xpath, re->flags); + return NULL; } /* - * XPath: /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/internal-status + * XPath: + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/internal-status */ -struct yang_data *lib_vrf_ribs_rib_route_route_entry_internal_status_get_elem( +struct yang_data * +lib_vrf_zebra_ribs_rib_route_route_entry_internal_status_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ + struct route_entry *re = (struct route_entry *)args->list_entry; + + if (re->status) + return yang_data_new_int32(args->xpath, re->status); + return NULL; } /* - * XPath: /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/uptime + * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/uptime */ -struct yang_data *lib_vrf_ribs_rib_route_route_entry_uptime_get_elem( +struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_uptime_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ - return NULL; + struct route_entry *re = (struct route_entry *)args->list_entry; + + return yang_data_new_date_and_time(args->xpath, re->uptime); } /* - * XPath: /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group + * XPath: + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group */ -const void *lib_vrf_ribs_rib_route_route_entry_nexthop_group_get_next( +const void *lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_get_next( struct nb_cb_get_next_args *args) { - /* TODO: implement me. */ + struct route_entry *re = (struct route_entry *)args->parent_list_entry; + struct nhg_hash_entry *nhe = (struct nhg_hash_entry *)args->list_entry; + + if (args->list_entry == NULL) { + nhe = re->nhe; + return nhe; + } return NULL; } -int lib_vrf_ribs_rib_route_route_entry_nexthop_group_get_keys( +int lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_get_keys( struct nb_cb_get_keys_args *args) { - /* TODO: implement me. */ + struct nhg_hash_entry *nhe = (struct nhg_hash_entry *)args->list_entry; + + args->keys->num = 1; + snprintfrr(args->keys->key[0], sizeof(args->keys->key[0]), "%" PRIu32, + nhe->id); + return NB_OK; } -const void *lib_vrf_ribs_rib_route_route_entry_nexthop_group_lookup_entry( +const void *lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_lookup_entry( struct nb_cb_lookup_entry_args *args) { /* TODO: implement me. */ @@ -367,37 +518,103 @@ const void *lib_vrf_ribs_rib_route_route_entry_nexthop_group_lookup_entry( /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/name + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/name */ struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_name_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_name_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ - return NULL; + struct nhg_hash_entry *nhe = (struct nhg_hash_entry *)args->list_entry; + char name[20] = {'\0'}; + + snprintfrr(name, sizeof(name), "%" PRIu32, nhe->id); + + return yang_data_new_string(args->xpath, name); } /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop */ const void * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_get_next( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_get_next( struct nb_cb_get_next_args *args) { - /* TODO: implement me. */ - return NULL; + struct nexthop *nexthop = (struct nexthop *)args->list_entry; + struct nhg_hash_entry *nhe = + (struct nhg_hash_entry *)args->parent_list_entry; + + if (args->list_entry == NULL) + nexthop = nhe->nhg.nexthop; + else + nexthop = nexthop_next(nexthop); + + return nexthop; } -int lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_get_keys( +int lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_get_keys( struct nb_cb_get_keys_args *args) { - /* TODO: implement me. */ + struct nexthop *nexthop = (struct nexthop *)args->list_entry; + + args->keys->num = 3; + + strlcpy(args->keys->key[0], yang_nexthop_type2str(nexthop->type), + sizeof(args->keys->key[0])); + + switch (nexthop->type) { + case NEXTHOP_TYPE_IPV4: + case NEXTHOP_TYPE_IPV4_IFINDEX: + snprintfrr(args->keys->key[1], sizeof(args->keys->key[1]), + "%pI4", &nexthop->gate.ipv4); + if (nexthop->ifindex) + strlcpy(args->keys->key[2], + ifindex2ifname(nexthop->ifindex, + nexthop->vrf_id), + sizeof(args->keys->key[2])); + else + /* no ifindex */ + strlcpy(args->keys->key[2], " ", + sizeof(args->keys->key[2])); + + break; + case NEXTHOP_TYPE_IPV6: + case NEXTHOP_TYPE_IPV6_IFINDEX: + snprintfrr(args->keys->key[1], sizeof(args->keys->key[1]), + "%pI6", &nexthop->gate.ipv6); + + if (nexthop->ifindex) + strlcpy(args->keys->key[2], + ifindex2ifname(nexthop->ifindex, + nexthop->vrf_id), + sizeof(args->keys->key[2])); + else + /* no ifindex */ + strlcpy(args->keys->key[2], " ", + sizeof(args->keys->key[2])); + + break; + case NEXTHOP_TYPE_IFINDEX: + strlcpy(args->keys->key[1], "", sizeof(args->keys->key[1])); + strlcpy(args->keys->key[2], + ifindex2ifname(nexthop->ifindex, nexthop->vrf_id), + sizeof(args->keys->key[2])); + + break; + case NEXTHOP_TYPE_BLACKHOLE: + /* Gateway IP */ + strlcpy(args->keys->key[1], "", sizeof(args->keys->key[1])); + strlcpy(args->keys->key[2], " ", sizeof(args->keys->key[2])); + break; + default: + break; + } + return NB_OK; } const void * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_lookup_entry( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_lookup_entry( struct nb_cb_lookup_entry_args *args) { /* TODO: implement me. */ @@ -406,89 +623,166 @@ lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_lookup_ent /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/nh-type + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/nh-type */ struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_nh_type_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_nh_type_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ + struct nexthop *nexthop = (struct nexthop *)args->list_entry; + + switch (nexthop->type) { + case NEXTHOP_TYPE_IFINDEX: + return yang_data_new_string(args->xpath, "ifindex"); + break; + case NEXTHOP_TYPE_IPV4: + return yang_data_new_string(args->xpath, "ip4"); + break; + case NEXTHOP_TYPE_IPV4_IFINDEX: + return yang_data_new_string(args->xpath, "ip4-ifindex"); + break; + case NEXTHOP_TYPE_IPV6: + return yang_data_new_string(args->xpath, "ip6"); + break; + case NEXTHOP_TYPE_IPV6_IFINDEX: + return yang_data_new_string(args->xpath, "ip6-ifindex"); + break; + default: + break; + } + return NULL; } /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/vrf + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/vrf */ struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_vrf_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_vrf_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ - return NULL; + struct nexthop *nexthop = (struct nexthop *)args->list_entry; + + return yang_data_new_string(args->xpath, + vrf_id_to_name(nexthop->vrf_id)); } /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/gateway + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/gateway */ struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_gateway_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_gateway_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ - return NULL; + struct nexthop *nexthop = (struct nexthop *)args->list_entry; + struct ipaddr addr; + + switch (nexthop->type) { + case NEXTHOP_TYPE_IPV4: + case NEXTHOP_TYPE_IPV4_IFINDEX: + addr.ipa_type = IPADDR_V4; + memcpy(&addr.ipaddr_v4, &(nexthop->gate.ipv4), + sizeof(struct in_addr)); + break; + case NEXTHOP_TYPE_IPV6: + case NEXTHOP_TYPE_IPV6_IFINDEX: + addr.ipa_type = IPADDR_V6; + memcpy(&addr.ipaddr_v6, &(nexthop->gate.ipv6), + sizeof(struct in6_addr)); + break; + case NEXTHOP_TYPE_BLACKHOLE: + case NEXTHOP_TYPE_IFINDEX: + /* No addr here */ + return yang_data_new_string(args->xpath, ""); + break; + default: + break; + } + + return yang_data_new_ip(args->xpath, &addr); } /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/interface + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/interface */ struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_interface_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_interface_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ + struct nexthop *nexthop = (struct nexthop *)args->list_entry; + + if (nexthop->ifindex) + yang_data_new_string( + args->xpath, + ifindex2ifname(nexthop->ifindex, nexthop->vrf_id)); + return NULL; } /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/bh-type + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/bh-type */ struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_bh_type_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_bh_type_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ - return NULL; + struct nexthop *nexthop = (struct nexthop *)args->list_entry; + const char *type_str = ""; + + if (nexthop->type != NEXTHOP_TYPE_BLACKHOLE) + return NULL; + + switch (nexthop->bh_type) { + case BLACKHOLE_NULL: + type_str = "null"; + break; + case BLACKHOLE_REJECT: + type_str = "reject"; + break; + case BLACKHOLE_ADMINPROHIB: + type_str = "prohibited"; + break; + case BLACKHOLE_UNSPEC: + type_str = "unspec"; + break; + } + + return yang_data_new_string(args->xpath, type_str); } /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/onlink + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/onlink */ struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_onlink_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_onlink_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ + struct nexthop *nexthop = (struct nexthop *)args->list_entry; + + if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK)) + return yang_data_new_bool(args->xpath, true); + return NULL; } /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry */ const void * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_get_next( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_get_next( struct nb_cb_get_next_args *args) { /* TODO: implement me. */ return NULL; } -int lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_get_keys( +int lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_get_keys( struct nb_cb_get_keys_args *args) { /* TODO: implement me. */ @@ -496,7 +790,7 @@ int lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_l } const void * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_lookup_entry( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_lookup_entry( struct nb_cb_lookup_entry_args *args) { /* TODO: implement me. */ @@ -505,10 +799,10 @@ lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry/id + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry/id */ struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_id_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_id_get_elem( struct nb_cb_get_elem_args *args) { /* TODO: implement me. */ @@ -517,10 +811,10 @@ lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry/label + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry/label */ struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_label_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_label_get_elem( struct nb_cb_get_elem_args *args) { /* TODO: implement me. */ @@ -529,10 +823,10 @@ lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry/ttl + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry/ttl */ struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_get_elem( struct nb_cb_get_elem_args *args) { /* TODO: implement me. */ @@ -541,10 +835,10 @@ lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry/traffic-class + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/mpls-label-stack/entry/traffic-class */ struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_get_elem( struct nb_cb_get_elem_args *args) { /* TODO: implement me. */ @@ -553,60 +847,80 @@ lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_mpls_label /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/duplicate + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/duplicate */ struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_duplicate_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_duplicate_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ + struct nexthop *nexthop = (struct nexthop *)args->list_entry; + + if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_DUPLICATE)) + return yang_data_new_empty(args->xpath); + return NULL; } /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/recursive + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/recursive */ struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_recursive_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_recursive_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ + struct nexthop *nexthop = (struct nexthop *)args->list_entry; + + if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) + return yang_data_new_empty(args->xpath); + return NULL; } /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/active + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/active */ struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_active_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_active_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ + struct nexthop *nexthop = (struct nexthop *)args->list_entry; + + if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE)) + return yang_data_new_empty(args->xpath); + return NULL; } /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/fib + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/fib */ struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_fib_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_fib_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ + struct nexthop *nexthop = (struct nexthop *)args->list_entry; + + if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB)) + return yang_data_new_empty(args->xpath); + return NULL; } /* * XPath: - * /frr-vrf:lib/vrf/frr-zebra:ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/weight + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/frr-nexthops/nexthop/weight */ struct yang_data * -lib_vrf_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_weight_get_elem( +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_frr_nexthops_nexthop_weight_get_elem( struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ + struct nexthop *nexthop = (struct nexthop *)args->list_entry; + + if (nexthop->weight) + return yang_data_new_uint8(args->xpath, nexthop->weight); + return NULL; } diff --git a/zebra/zebra_router.c b/zebra/zebra_router.c index ab426ae60396..61fef8779f40 100644 --- a/zebra/zebra_router.c +++ b/zebra/zebra_router.c @@ -66,6 +66,22 @@ zebra_router_table_entry_compare(const struct zebra_router_table *e1, return (e1->safi - e2->safi); } +struct zebra_router_table *zebra_router_find_zrt(struct zebra_vrf *zvrf, + uint32_t tableid, afi_t afi, + safi_t safi) +{ + struct zebra_router_table finder; + struct zebra_router_table *zrt; + + memset(&finder, 0, sizeof(finder)); + finder.afi = afi; + finder.safi = safi; + finder.tableid = tableid; + finder.ns_id = zvrf->zns->ns_id; + zrt = RB_FIND(zebra_router_table_head, &zrouter.tables, &finder); + + return zrt; +} struct route_table *zebra_router_find_table(struct zebra_vrf *zvrf, uint32_t tableid, afi_t afi, diff --git a/zebra/zebra_router.h b/zebra/zebra_router.h index 773e5a64152c..863c5fa71caf 100644 --- a/zebra/zebra_router.h +++ b/zebra/zebra_router.h @@ -186,6 +186,9 @@ extern void zebra_router_init(void); extern void zebra_router_cleanup(void); extern void zebra_router_terminate(void); +extern struct zebra_router_table *zebra_router_find_zrt(struct zebra_vrf *zvrf, + uint32_t tableid, + afi_t afi, safi_t safi); extern struct route_table *zebra_router_find_table(struct zebra_vrf *zvrf, uint32_t tableid, afi_t afi, safi_t safi);