]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: afi-safi identity to value apis
authorChirag Shah <chirag@cumulusnetworks.com>
Tue, 12 May 2020 21:09:57 +0000 (14:09 -0700)
committerChirag Shah <chirag@cumulusnetworks.com>
Tue, 12 May 2020 21:31:37 +0000 (14:31 -0700)
Helper APIs to convert afi-safi identity to values.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
zebra/zebra_nb.c
zebra/zebra_nb.h

index aad60aac6a598663c5b771738be82069b26642bc..25b8b44ec93f3954943943d449e44755cf93a346 100644 (file)
 #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",
index b880dea35781eafccbe80515adb46106ae1f749a..15350eb53bf19ea44ee866001580044a1a70f702 100644 (file)
@@ -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);