From 5639e5bdd4cbf6c2a33956318e3c320cf8160e8e Mon Sep 17 00:00:00 2001 From: Richard Alpe Date: Mon, 16 Oct 2023 12:35:37 +0200 Subject: [PATCH] statd: ignore interfaces with group = internal Don't add any info about interfaces which has "group" = "internal" to the operational datastore. Signed-off-by: Richard Alpe --- src/statd/iface-ip-link.c | 35 +++++++++++++++++++++++++++++++++++ src/statd/iface-ip-link.h | 1 + src/statd/statd.c | 6 ++++++ 3 files changed, 42 insertions(+) diff --git a/src/statd/iface-ip-link.c b/src/statd/iface-ip-link.c index 99ba078b..05ebf501 100644 --- a/src/statd/iface-ip-link.c +++ b/src/statd/iface-ip-link.c @@ -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; +} diff --git a/src/statd/iface-ip-link.h b/src/statd/iface-ip-link.h index 5ea074e7..f575467a 100644 --- a/src/statd/iface-ip-link.h +++ b/src/statd/iface-ip-link.h @@ -3,6 +3,7 @@ #include +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 diff --git a/src/statd/statd.c b/src/statd/statd.c index 15b2aea2..d0dcbbf0 100644 --- a/src/statd/statd.c +++ b/src/statd/statd.c @@ -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");