How to identify if a node is a list vs a container in the confd_cs_node data structure?

After loading the schema of your YANG data model using either maapi_load_schemas() or confd_load_schemas() API call, you can walk through the confd_cs_node data structure to reconstruct your data model dynamically at run time. confd_cs_node contains a structure called info that is defined as “struct confd_cs_node_info”. The info.shallow_type field contains the primitive confd data types for the node, such as C_STR, CINT32, C_BOOL, etc… However, this info.shallow_type field is defined as C_XMLTAG for both container and list nodes. How do you tell them apart?

What you do is to resort to the info.keys field which is defined as a pointer to u_int32_t.  The info.keys field of a container node is NULL, whereas the info.keys field of a list node is a zero-terminated array of XML tags of the keys in the list.

Here’s some example code snippet to work with the confd_cs_node data structure:

Given the following YANG data model:

module notif {
  namespace "http://tail-f.com/ns/test/notif";
  prefix notif;

  container interfaces {
    list interface {
      key ifIndex;
      leaf ifIndex {
        type uint32;
      }
      leaf desc {
        type string;
      }
    }
  }
}

Following is code snippet for finding the confd_cs_node structure for the interfaces container node followed by the interface list node:

struct confd_cs_node *object = confd_cs_node_cd(NULL,"/interfaces");
//object->info.keys equals NULL
object = object->children;
//object->info.keys now points to the XML tag of the ifIndex key
1 Like