Skip to content

Commit

Permalink
Merge pull request #4990 from qlyoung/yang-iface-operdata
Browse files Browse the repository at this point in the history
lib: add oper data cbs for ifaces
  • Loading branch information
rwestphal authored Sep 18, 2019
2 parents 7947599 + f88647e commit 312fbe4
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions lib/if.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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,
},
},
{
Expand Down

0 comments on commit 312fbe4

Please sign in to comment.