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 <richard@bit42.se>
This commit is contained in:
Richard Alpe
2023-10-17 18:17:59 +02:00
committed by Joachim Wiberg
parent 1654773bc6
commit 5639e5bdd4
3 changed files with 42 additions and 0 deletions
+35
View File
@@ -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
View File
@@ -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
View File
@@ -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");