confd: add support for setting phy-address on interfaces

- Override read-only flag in YANG model
 - Add support for setting custom MAC
 - Add support for restoring permanent/original MAC

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-09-21 16:34:48 +02:00
parent d5f9f1a73e
commit d0bb51e433
3 changed files with 43 additions and 1 deletions
+1 -1
View File
@@ -78,7 +78,7 @@ sysrepoctl -s $SEARCH \
-g wheel -p 0660 \
-i infix-ip@2023-04-24.yang -g wheel -p 0660 \
-i infix-if-type@2023-08-21.yang -g wheel -p 0660 \
-i infix-interfaces@2023-08-21.yang -g wheel -p 0660 \
-i infix-interfaces@2023-09-19.yang -g wheel -p 0660 \
-e vlan-filtering \
-i ieee802-dot1ab-lldp@2022-03-15.yang -g wheel -p 0660 \
-i infix-lldp@2023-08-23.yang -g wheel -p 0660 \
+31
View File
@@ -416,6 +416,36 @@ static int netdag_set_conf_addrs(FILE *ip, const char *ifname,
return 0;
}
static int netdag_gen_link_addr(FILE *ip, struct lyd_node *cif, struct lyd_node *dif)
{
const char *ifname = lydx_get_cattr(dif, "name");
const char *mac = NULL;
struct lyd_node *node;
char buf[32];
node = lydx_get_child(dif, "phys-address");
if (lydx_get_op(node) == LYDX_OP_DELETE) {
FILE *fp;
fp = popenf("r", "ethtool -P %s |awk '{print $3}'", ifname);
if (fp) {
if (fgets(buf, sizeof(buf), fp))
mac = chomp(buf);
pclose(fp);
}
} else {
mac = lyd_get_value(node);
}
if (!mac || !strlen(mac)) {
DEBUG("No change in %s phys-address, skipping ...", ifname);
return 0;
}
fprintf(ip, "link set %s address %s\n", ifname, mac);
return 0;
}
static int netdag_gen_ip_addrs(FILE *ip, const char *proto,
struct lyd_node *cif, struct lyd_node *dif)
{
@@ -1022,6 +1052,7 @@ static sr_error_t netdag_gen_iface(struct dagger *net,
}
/* Set Addresses */
err = err ? : netdag_gen_link_addr(ip, cif, dif);
err = err ? : netdag_gen_ip_addrs(ip, "ipv4", cif, dif);
err = err ? : netdag_gen_ip_addrs(ip, "ipv6", cif, dif);
if (err)
@@ -18,6 +18,11 @@ module infix-interfaces {
contact "kernelkit@googlegroups.com";
description "Linux bridge and lag extensions for ietf-interfaces.";
revision 2023-09-19 {
description "Add deviation to allow setting phys-address on links.";
reference "internal";
}
revision 2023-08-21 {
description "Move port augment to submodule for infix-if-bridge and
infix-if-lag (later) which reference it.
@@ -46,6 +51,12 @@ module infix-interfaces {
}
}
deviation "/if:interfaces/if:interface/if:phys-address" {
deviate replace {
config true;
}
}
deviation "/if:interfaces-state" {
deviate not-supported;
}