]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: add oper data cbs for ifaces
authorQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 12 Sep 2019 21:35:04 +0000 (21:35 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Wed, 18 Sep 2019 19:42:47 +0000 (19:42 +0000)
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/if.c

index a3e63136677d6d82c0fc8b6119cb334032c1c297..1e34ff4b847c47a899b91409fbb9aa5caaebec98 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -1457,6 +1457,60 @@ static int lib_interface_destroy(enum nb_event event,
        return NB_OK;
 }
 
+/*
+ * XPath: /frr-interface:lib/interface
+ */
+static const void *lib_interface_get_next(const void *parent_list_entry,
+                                         const void *list_entry)
+{
+       struct vrf *vrf;
+       struct interface *pif = (struct interface *)list_entry;
+
+       if (list_entry == NULL) {
+               vrf = RB_MIN(vrf_name_head, &vrfs_by_name);
+               assert(vrf);
+               pif = RB_MIN(if_name_head, &vrf->ifaces_by_name);
+       } else {
+               vrf = vrf_lookup_by_id(pif->vrf_id);
+               pif = RB_NEXT(if_name_head, pif);
+               /* if no more interfaces, switch to next vrf */
+               while (pif == NULL) {
+                       vrf = RB_NEXT(vrf_name_head, vrf);
+                       if (!vrf)
+                               return NULL;
+                       pif = RB_MIN(if_name_head, &vrf->ifaces_by_name);
+               }
+       }
+
+       return pif;
+}
+
+static int lib_interface_get_keys(const void *list_entry,
+                                 struct yang_list_keys *keys)
+{
+       const struct interface *ifp = list_entry;
+
+       struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id);
+
+       assert(vrf);
+
+       keys->num = 2;
+       strlcpy(keys->key[0], ifp->name, sizeof(keys->key[0]));
+       strlcpy(keys->key[1], vrf->name, sizeof(keys->key[1]));
+
+       return NB_OK;
+}
+
+static const void *lib_interface_lookup_entry(const void *parent_list_entry,
+                                             const struct yang_list_keys *keys)
+{
+       const char *ifname = keys->key[0];
+       const char *vrfname = keys->key[1];
+       struct vrf *vrf = vrf_lookup_by_name(vrfname);
+
+       return if_lookup_by_name(ifname, vrf->vrf_id);
+}
+
 /*
  * XPath: /frr-interface:lib/interface/description
  */
@@ -1502,6 +1556,9 @@ const struct frr_yang_module_info frr_interface_info = {
                                .create = lib_interface_create,
                                .destroy = lib_interface_destroy,
                                .cli_show = cli_show_interface,
+                               .get_next = lib_interface_get_next,
+                               .get_keys = lib_interface_get_keys,
+                               .lookup_entry = lib_interface_lookup_entry,
                        },
                },
                {