Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statd: add interface type to operational data #91

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/statd/statd.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,67 @@ static int ly_add_ip_link_stat(const struct ly_ctx *ctx, struct lyd_node **paren
return SR_ERR_SYS;
}

static const char *get_yang_link_type(char *xpath, json_t *iface)
{
json_t *j_type;
const char *type;

j_type = json_object_get(iface, "link_type");
if (!json_is_string(j_type)) {
ERROR("Expected a JSON string for 'link_type'");
/* This will throw a YANG / ly error */
return "";
}

type = json_string_value(j_type);

if (strcmp(type, "ether") == 0) {
const char *kind;
json_t *j_val;

j_val = json_object_get(iface, "linkinfo");
if (!j_val)
return "iana-if-type:ethernetCsmacd";

j_val = json_object_get(j_val, "info_kind");
if (!j_val)
return "iana-if-type:ethernetCsmacd";

if (!json_is_string(j_val)) {
ERROR("Expected a JSON string for 'info_kind'");
return "iana-if-type:other";
}
kind = json_string_value(j_val);

if (strcmp(kind, "veth") == 0)
return "infix-if-type:veth";
if (strcmp(kind, "vlan") == 0)
return "iana-if-type:l2vlan";
if (strcmp(kind, "bridge") == 0)
return "iana-if-type:bridge";

/**
* We could return ethernetCsmacd here, but it might hide some
* special type that we actually want to explicitly identify.
*/
ERROR("Unable to determine info_kind for \"%s\"", xpath);

return "iana-if-type:other";
}

if (strcmp(type, "loopback") == 0)
return "iana-if-type:softwareLoopback";

ERROR("Unable to determine iana-if-type for \"%s\"", xpath);

return "iana-if-type:other";
}

static int ly_add_ip_link_data(const struct ly_ctx *ctx, struct lyd_node **parent,
char *xpath, json_t *iface)
{
const char *val;
const char *type;
json_t *j_val;
int err;

Expand Down Expand Up @@ -286,6 +343,13 @@ static int ly_add_ip_link_data(const struct ly_ctx *ctx, struct lyd_node **paren
return err;
}

type = get_yang_link_type(xpath, iface);
err = lydx_new_path(ctx, parent, xpath, "type", type);
if (err) {
ERROR("Error, adding 'type' to data tree, libyang error %d", err);
return SR_ERR_LY;
}

return SR_ERR_OK;
}

Expand Down