From 0284e2ca5814500392e04986ce2fac4d4e90bff5 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Wed, 23 Oct 2024 18:22:02 +0200 Subject: [PATCH] confd: allow interface description as ifAlias This patch adds support for setting the free form description string as the interface alias. This can be read from /sys/class/net/*/ifalias, or using the 'ip link show' command. The ifalias is reported by SNMP and LLDP by default, and now also in the operational datastore. Linux supports 250 characters in ifalias, but the IF-MIB is restricted to 64 characters, so we add a local deviation to limit the type. Signed-off-by: Joachim Wiberg --- src/confd/src/ietf-interfaces.c | 4 ++++ src/confd/yang/confd.inc | 2 +- src/confd/yang/containers.inc | 2 +- src/confd/yang/infix-interfaces.yang | 20 ++++++++++++++++--- ....yang => infix-interfaces@2024-10-28.yang} | 0 src/statd/python/yanger/yanger.py | 3 +++ 6 files changed, 26 insertions(+), 5 deletions(-) rename src/confd/yang/{infix-interfaces@2024-10-14.yang => infix-interfaces@2024-10-28.yang} (100%) diff --git a/src/confd/src/ietf-interfaces.c b/src/confd/src/ietf-interfaces.c index e347f513..b65e09f3 100644 --- a/src/confd/src/ietf-interfaces.c +++ b/src/confd/src/ietf-interfaces.c @@ -1889,6 +1889,10 @@ static sr_error_t netdag_gen_iface(sr_session_ctx_t *session, struct dagger *net if (err) goto err_close_ip; + /* ifAlias, should skip for container-network types */ + attr = lydx_get_cattr(cif, "description"); + fprintf(ip, "link set alias \"%s\" dev %s\n", attr ?: "", ifname); + /* Bring interface back up, if enabled */ attr = lydx_get_cattr(cif, "enabled"); if (!attr || !strcmp(attr, "true")) diff --git a/src/confd/yang/confd.inc b/src/confd/yang/confd.inc index aa2de0f2..ea4fe93b 100644 --- a/src/confd/yang/confd.inc +++ b/src/confd/yang/confd.inc @@ -37,7 +37,7 @@ MODULES=( "ieee802-ethernet-interface@2019-06-21.yang" "infix-ethernet-interface@2024-02-27.yang" "infix-factory-default@2023-06-28.yang" - "infix-interfaces@2024-10-14.yang -e vlan-filtering" + "infix-interfaces@2024-10-28.yang -e vlan-filtering" # from rousette "ietf-restconf@2017-01-26.yang" diff --git a/src/confd/yang/containers.inc b/src/confd/yang/containers.inc index 3ac2d49a..af72dc83 100644 --- a/src/confd/yang/containers.inc +++ b/src/confd/yang/containers.inc @@ -1,6 +1,6 @@ # -*- sh -*- # REMEMBER TO UPDATE infix-interfaces ALSO IN confd.inc MODULES=( - "infix-interfaces@2024-10-14.yang -e vlan-filtering -e containers" + "infix-interfaces@2024-10-28.yang -e vlan-filtering -e containers" "infix-containers@2024-10-14.yang" ) diff --git a/src/confd/yang/infix-interfaces.yang b/src/confd/yang/infix-interfaces.yang index ccde9c86..b5c0bbd6 100644 --- a/src/confd/yang/infix-interfaces.yang +++ b/src/confd/yang/infix-interfaces.yang @@ -23,6 +23,11 @@ module infix-interfaces { contact "kernelkit@googlegroups.com"; description "Linux bridge and lag extensions for ietf-interfaces."; + revision 2024-10-28 { + description "Limit description to 64 chars, matching IF-MIB max."; + reference "internal"; + } + revision 2024-10-14 { description "Deviate link-up-down-trap-enable not-supported."; reference "internal"; @@ -84,6 +89,18 @@ module infix-interfaces { } } + deviation "/if:interfaces/if:interface/if:description" { + deviate replace { + type string { + length "0..64"; + } + } + } + + deviation "/if:interfaces/if:interface/if:link-up-down-trap-enable" { + deviate not-supported; + } + augment "/if:interfaces/if:interface" { description "Custom phys-address management, static or derived from chassis MAC."; @@ -114,7 +131,4 @@ module infix-interfaces { } } } - deviation "/if:interfaces/if:interface/if:link-up-down-trap-enable" { - deviate not-supported; - } } diff --git a/src/confd/yang/infix-interfaces@2024-10-14.yang b/src/confd/yang/infix-interfaces@2024-10-28.yang similarity index 100% rename from src/confd/yang/infix-interfaces@2024-10-14.yang rename to src/confd/yang/infix-interfaces@2024-10-28.yang diff --git a/src/statd/python/yanger/yanger.py b/src/statd/python/yanger/yanger.py index dc87dccc..1b965402 100755 --- a/src/statd/python/yanger/yanger.py +++ b/src/statd/python/yanger/yanger.py @@ -645,6 +645,9 @@ def add_ip_link(ifname, iface_in, iface_out): if 'ifindex' in iface_in: iface_out['if-index'] = iface_in['ifindex'] + if 'ifalias' in iface_in: + iface_out['description'] = iface_in['ifalias'] + if 'address' in iface_in: iface_out['phys-address'] = iface_in['address']