From b0d36ca51dd2b8b7fbfdb3e1f017679f45603ddc Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 21 Sep 2023 15:38:40 +0200 Subject: [PATCH] confd: recreate interfaces which do not have permaddr Only physical interfaces have a permanent link address. So in order to restore the default MAC generated by the kernel for interfaces such as bridges, veth pairs, VLAN interfaces, and link aggregates, we recreate them. This patch adds support for checking if the phys-address attribute has been deleted from bridge, vlan, and veth interfaces. The netdag_must_del() function has been refactorored slightly so each interface type is responsible for returning true if its condiitions are satisfied. Signed-off-by: Joachim Wiberg --- src/confd/src/ietf-interfaces.c | 50 +++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/src/confd/src/ietf-interfaces.c b/src/confd/src/ietf-interfaces.c index e0651a49..4cd6c1d7 100644 --- a/src/confd/src/ietf-interfaces.c +++ b/src/confd/src/ietf-interfaces.c @@ -943,21 +943,49 @@ static int netdag_gen_afspec_set(struct dagger *net, struct lyd_node *dif, return -ENOSYS; } +static bool is_phys_addr_deleted(struct lyd_node *dif) +{ + struct lyd_node *node; + + node = lydx_get_child(dif, "phys-address"); + if (node && lydx_get_op(node) == LYDX_OP_DELETE) + return true; + + return false; +} + static bool netdag_must_del(struct lyd_node *dif, struct lyd_node *cif) { const char *iftype = lydx_get_cattr(cif, "type"); - if (!strcmp(iftype, "infix-if-type:bridge")) - return 0; - if (!strcmp(iftype, "infix-if-type:vlan")) - return lydx_get_cattr(dif, "parent-interface") || - lydx_get_descendant(lyd_child(dif), - "encapsulation", - "dot1q-vlan", - "outer-tag", - NULL); - if (!strcmp(iftype, "infix-if-type:veth")) - return lydx_get_descendant(lyd_child(dif), "peer", NULL); + if (!strcmp(iftype, "infix-if-type:bridge")) { + if (is_phys_addr_deleted(dif)) + return true; + } else if (!strcmp(iftype, "infix-if-type:vlan")) { + if (is_phys_addr_deleted(dif)) + return true; + + if (lydx_get_cattr(dif, "parent-interface") || + lydx_get_descendant(lyd_child(dif), + "encapsulation", + "dot1q-vlan", + "outer-tag", + NULL)) + return true; + } else if (!strcmp(iftype, "infix-if-type:veth")) { + if (is_phys_addr_deleted(dif)) + return true; + + if (lydx_get_descendant(lyd_child(dif), "peer", NULL)) + return true; +/* + } else if (!strcmp(iftype, "infix-if-type:lag")) { + if (is_phys_addr_deleted(dif)) + return true; + + ... REMEMBER WHEN ADDING BOND SUPPORT ... +*/ + } return false; }