confd: new helper function, get all l3 interfaces

Used by infix-firewall.c when figuring out interfaces that are not
explicitly assigned to any zone.  Placing them in the default zone

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2025-10-10 12:57:22 +02:00
parent d1f7abcc3e
commit c4ac9e44a7
2 changed files with 67 additions and 0 deletions
+66
View File
@@ -908,6 +908,72 @@ cleanup:
return err;
}
int ietf_interfaces_get_all_l3(const struct lyd_node *tree, char ***ifaces)
{
struct lyd_node *interfaces, *cif;
char **names = NULL;
size_t capacity = 0;
size_t num = 0;
const char *ifname;
if (!tree || !ifaces)
return -EINVAL;
*ifaces = NULL;
interfaces = lydx_get_descendant((struct lyd_node *)tree, "interfaces", "interface", NULL);
if (!interfaces) {
*ifaces = calloc(1, sizeof(char *));
return *ifaces ? 0 : -ENOMEM;
}
LYX_LIST_FOR_EACH(interfaces, cif, "interface") {
ifname = lydx_get_cattr(cif, "name");
if (!ifname)
continue;
if (is_member_port(cif))
continue;
if (iftype_from_iface(cif) == IFT_LO)
continue;
if (lydx_get_child(cif, "container-network"))
continue;
if (num + 1 >= capacity) {
capacity = capacity ? capacity * 2 : 8;
char **new_names = realloc(names, capacity * sizeof(char *));
if (!new_names) {
for (size_t i = 0; i < num; i++)
free(names[i]);
free(names);
return -ENOMEM;
}
names = new_names;
}
names[num] = strdup(ifname);
if (!names[num]) {
for (size_t i = 0; i < num; i++)
free(names[i]);
free(names);
return -ENOMEM;
}
num++;
}
if (num == 0) {
*ifaces = calloc(1, sizeof(char *));
return *ifaces ? 0 : -ENOMEM;
}
names[num] = NULL;
*ifaces = names;
return 0;
}
int ietf_interfaces_init(struct confd *confd)
{
int rc;
+1
View File
@@ -102,6 +102,7 @@ int netdag_gen_ethtool(struct dagger *net, struct lyd_node *cif, struct lyd_node
/* ietf-interfaces.c */
const char *get_chassis_addr(void);
int link_gen_address(struct lyd_node *cif, FILE *ip);
int ietf_interfaces_get_all_l3(const struct lyd_node *tree, char ***ifaces);
/* ietf-ip.c */
int netdag_gen_ipv6_autoconf(struct dagger *net, struct lyd_node *cif,