Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Nov 2023 22:20:07 +0000
From:      =?utf-8?Q?Mina_Gali=C4=87?= <freebsd@igalic.co>
To:        "freebsd-net@freebsd.org" <freebsd-net@freebsd.org>
Subject:   How to tell if a network interface was renamed (and from what)
Message-ID:  <pdHC0ObBkAbx2HfFIhWYaB5-dmQDEUzNTWvVVJAuJV7FWdWWeSwybVFD-uyBUxPlqDRpAW7D1aAZsbrTxEj9kqsq7ESgO41srPmS-PcXGqw=@igalic.co>

next in thread | raw e-mail | index | archive | help
Hi folks,

Linux has an "easy" way of telling if an interface has been renamed.
See cloud-init's is_renamed function: https://github.com/canonical/cloud-in=
it/blob/5496745b394f9b7b9eaf57fd619330d484ce2da8/cloudinit/net/__init__.py#=
L338-L350
This code reads /sys/class/net/<netif>/name_assign_type and if that is 3 or=
 4, it's been renamed.

I can't even think of an sensible way of replicating that.
I can only think of terrible / wrong way of finding it out:

dmesg | grep "changing name to '<new-netif>'"

a less terrible method would be to check for, say:

sysctl dev.<new-netif>.0.%driver

if that fails, we probably have a renamed interface=E2=80=A6 but we don't k=
now what it was renamed from, and this only works for *real* interfaces, no=
t for cloned devices, or epairs.

Now, ignoring my terrible hacky attempts at command line tooling, I would a=
lso happily accept a solution in C, which is fairly easily accessible from =
Python, and which we already use to figure out the uptime (or rather, the b=
oottime): https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9eaf=
57fd619330d484ce2da8/cloudinit/util.py#L2073-L2105

Looking forward to reading your ideas.

Kind regards,

Mina Gali=C4=87



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?pdHC0ObBkAbx2HfFIhWYaB5-dmQDEUzNTWvVVJAuJV7FWdWWeSwybVFD-uyBUxPlqDRpAW7D1aAZsbrTxEj9kqsq7ESgO41srPmS-PcXGqw=>