Skip to content

Commit

Permalink
statd: ignore interfaces with group = internal
Browse files Browse the repository at this point in the history
Don't add any info about interfaces which has "group" = "internal" to
the operational datastore.

Signed-off-by: Richard Alpe <richard@bit42.se>
  • Loading branch information
rical committed Oct 17, 2023
1 parent 57f7742 commit 4d27e0d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/statd/iface-ip-link.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,38 @@ int ly_add_ip_link(const struct ly_ctx *ctx, struct lyd_node **parent, char *ifn
return SR_ERR_OK;
}

/* Returns 1 if the group is "group", 0 if it's not and -1 on error */
int ip_link_check_group(char *ifname, const char *group)
{
json_t *j_iface;
json_t *j_root;
json_t *j_val;

j_root = json_get_ip_link(ifname);
if (!j_root) {
ERROR("Error, parsing ip-link JSON");
return -1;
}
if (json_array_size(j_root) != 1) {
ERROR("Error, expected JSON array of single iface");
json_decref(j_root);
return -1;
}

j_iface = json_array_get(j_root, 0);

j_val = json_object_get(j_iface, "group");
if (!json_is_string(j_val)) {
ERROR("Error, expected a JSON string for 'group'");
json_decref(j_root);
return -1;
}
if (strcmp(json_string_value(j_val), group) == 0) {
json_decref(j_root);
return 1;
}

json_decref(j_root);

return 0;
}
1 change: 1 addition & 0 deletions src/statd/iface-ip-link.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <srx/lyx.h>

int ip_link_check_group(char *ifname, const char *group);
int ly_add_ip_link(const struct ly_ctx *ctx, struct lyd_node **parent, char *ifname);

#endif
6 changes: 6 additions & 0 deletions src/statd/statd.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ static int sr_ifaces_cb(sr_session_ctx_t *session, uint32_t, const char *path,
return SR_ERR_INTERNAL;
}

/* Skip internal interfaces (such as dsa0) */
if (ip_link_check_group(sub->ifname, "internal") == 1) {
err = SR_ERR_OK;
goto out;
}

err = ly_add_ip_link(ctx, parent, sub->ifname);
if (err) {
ERROR("Error, adding ip link info");
Expand Down

0 comments on commit 4d27e0d

Please sign in to comment.