public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH ifupdown2 3/5] d/patches: set interface alias through netlink instead of sysfs
Date: Fri, 22 Aug 2025 14:27:50 +0200	[thread overview]
Message-ID: <20250822122754.842281-4-c.heiss@proxmox.com> (raw)
In-Reply-To: <20250822122754.842281-1-c.heiss@proxmox.com>

The sysfs-based methods do not handle altnames at all. Instead, get/set
ifalias through netlink directly, which also has transparent altname
support, and is a more robust way in general.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 ...et-interface-alias-through-netlink-i.patch | 130 ++++++++++++++++++
 debian/patches/series                         |   1 +
 2 files changed, 131 insertions(+)
 create mode 100644 debian/patches/pve/0013-addons-nlcache-set-interface-alias-through-netlink-i.patch

diff --git a/debian/patches/pve/0013-addons-nlcache-set-interface-alias-through-netlink-i.patch b/debian/patches/pve/0013-addons-nlcache-set-interface-alias-through-netlink-i.patch
new file mode 100644
index 0000000..6b06963
--- /dev/null
+++ b/debian/patches/pve/0013-addons-nlcache-set-interface-alias-through-netlink-i.patch
@@ -0,0 +1,130 @@
+From 5451c4052a350ee941af4f8237a16334240a3a45 Mon Sep 17 00:00:00 2001
+From: Christoph Heiss <c.heiss@proxmox.com>
+Date: Wed, 20 Aug 2025 14:03:30 +0200
+Subject: [PATCH] addons, nlcache: set interface alias through netlink instead
+ of sysfs
+
+Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
+---
+ ifupdown2/addons/address.py |  4 ++--
+ ifupdown2/lib/nlcache.py    | 41 +++++++++++++++++++++++++++++++++++++
+ ifupdown2/lib/sysfs.py      | 22 --------------------
+ 3 files changed, 43 insertions(+), 24 deletions(-)
+
+diff --git a/ifupdown2/addons/address.py b/ifupdown2/addons/address.py
+index 25270c3..377b419 100644
+--- a/ifupdown2/addons/address.py
++++ b/ifupdown2/addons/address.py
+@@ -1196,7 +1196,7 @@ class address(AddonWithIpBlackList, moduleBase):
+         #
+         # alias
+         #
+-        self.sysfs.link_set_alias(ifaceobj.name, ifaceobj.get_attr_value_first("alias"))
++        self.netlink.link_set_alias(ifaceobj.name, ifaceobj.get_attr_value_first("alias"))
+ 
+         self._sysctl_config(ifaceobj)
+ 
+@@ -1400,7 +1400,7 @@ class address(AddonWithIpBlackList, moduleBase):
+             if not ifaceobj.link_kind:
+                 alias = ifaceobj.get_attr_value_first("alias")
+                 if alias:
+-                    self.sysfs.link_set_alias(ifaceobj.name, None)  # None to reset alias.
++                    self.netlink.link_set_alias(ifaceobj.name, None)  # None to reset alias.
+ 
+             # XXX hwaddress reset cannot happen because we dont know last
+             # address.
+diff --git a/ifupdown2/lib/nlcache.py b/ifupdown2/lib/nlcache.py
+index a36e610..3f79f71 100644
+--- a/ifupdown2/lib/nlcache.py
++++ b/ifupdown2/lib/nlcache.py
+@@ -409,6 +409,18 @@ class _NetlinkCache:
+         except Exception:
+             pass
+ 
++    def override_link_alias(self, ifname, alias):
++        """
++        Manually override link alias in the cache and ignore any failures
++        :param ifname: Name of the interface to update
++        :param alias: New interface alias
++        """
++        try:
++            with self._cache_lock:
++                self._link_cache[ifname].attributes[Link.IFLA_IFALIAS].value = alias
++        except Exception:
++            pass
++
+     def override_cache_unslave_link(self, slave, master):
+         """
+         Manually update the cache unslaving SLAVE from MASTER
+@@ -3335,6 +3347,35 @@ class NetlinkListenerWithCache(nllistener.NetlinkManagerWithListener, BaseObject
+         except Exception as e:
+             raise Exception(f'{ifname}: netlink: failed to set mtu to {mtu}: {str(e)}')
+ 
++    """
++    Sets the alias of the given link, updating the cache on success.
++
++    :param ifname: Name of the interface to update
++    :param alias: New alias to set for the interface.
++    :return: True if the operation was successful
++    """
++    def link_set_alias(self, ifname, alias):
++        if self.cache.get_link_alias(ifname) == alias:
++            # no need to update
++            return
++
++        self.logger.info(f'{ifname}: netlink: ip link set dev {ifname} alias {alias}')
++
++        debug = RTM_SETLINK in self.debug
++        try:
++            link = Link(RTM_SETLINK, debug, use_color=self.use_color)
++            link.flags = NLM_F_REPLACE | NLM_F_REQUEST | NLM_F_ACK
++            link.body = struct.pack('Bxxxiii', socket.AF_UNSPEC, 0, 0, 0)
++            link.add_attribute(Link.IFLA_IFNAME, ifname)
++            link.add_attribute(Link.IFLA_IFALIAS, alias or '') # empty string removes alias
++            link.build_message(next(self.sequence), self.pid)
++            result = self.tx_nlpacket_get_response_with_error(link)
++            self.cache.override_link_alias(ifname, alias)
++
++            return result
++        except Exception as e:
++            raise Exception(f'{ifname}: netlink: failed to set alias to {alias}: {str(e)}')
++
+     ############################################################################
+     # ADDRESS
+     ############################################################################
+diff --git a/ifupdown2/lib/sysfs.py b/ifupdown2/lib/sysfs.py
+index 3ac678d..fb1e405 100644
+--- a/ifupdown2/lib/sysfs.py
++++ b/ifupdown2/lib/sysfs.py
+@@ -106,28 +106,6 @@ class __Sysfs(IO, Requirements):
+         """
+         return self.read_file_oneline("/sys/class/net/%s/address" % ifname)
+ 
+-    #
+-    # ALIAS
+-    #
+-
+-    def link_set_alias(self, ifname, alias):
+-        cached_alias = self.cache.get_link_alias(ifname)
+-
+-        if cached_alias == alias:
+-            return
+-
+-        if not alias:
+-            alias = "\n"
+-
+-        if self.write_to_file("/sys/class/net/%s/ifalias" % ifname, alias):
+-            pass # self.cache.override_link_mtu(ifname, mtu_int)
+-
+-    def link_set_alias_dry_run(self, ifname, alias):
+-        # we can remove the cache check in DRYRUN mode
+-        if not alias:
+-            alias = ""
+-        self.write_to_file("/sys/class/net/%s/ifalias" % ifname, alias)
+-
+     ############################################################################
+     # BRIDGE
+     ############################################################################
+-- 
+2.50.1
+
diff --git a/debian/patches/series b/debian/patches/series
index e8aa870..1945ba9 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -10,5 +10,6 @@ pve/0009-gvgeb-fix-python-interpreter-shebang.patch
 pve/0010-main-ignore-dpkg-files-when-running-hook-scripts.patch
 pve/0011-nlmanager-addons-add-transparent-support-interface-a.patch
 pve/0012-addons-nlcache-set-interface-mtu-through-netlink-ins.patch
+pve/0013-addons-nlcache-set-interface-alias-through-netlink-i.patch
 upstream/0001-add-ipv6-slaac-support-inet6-auto-accept_ra.patch
 upstream/0001-use-raw-strings-for-regex-to-fix-backslash-interpret.patch
-- 
2.50.1



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  parent reply	other threads:[~2025-08-22 12:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-22 12:27 [pve-devel] [PATCH ifupdown2 0/5] d/patches: improve altname support Christoph Heiss
2025-08-22 12:27 ` [pve-devel] [PATCH ifupdown2 1/5] d/patches: altname support: add translation in some more places Christoph Heiss
2025-08-22 12:27 ` [pve-devel] [PATCH ifupdown2 2/5] d/patches: set interface mtu through netlink instead of sysfs Christoph Heiss
2025-08-22 12:27 ` Christoph Heiss [this message]
2025-08-22 12:27 ` [pve-devel] [PATCH ifupdown2 4/5] d/patches: ipv6 slaac: properly decode IPv6 devconf attributes Christoph Heiss
2025-08-22 12:27 ` [pve-devel] [PATCH ifupdown2 5/5] d/patches: read ipv6 devconf `disable_ipv6` attribute through netlink Christoph Heiss
2025-08-26 22:33 ` [pve-devel] applied-series: [PATCH ifupdown2 0/5] d/patches: improve altname support Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250822122754.842281-4-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal