Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 19 Nov 2023 09:15:04 +0800
From:      Zhenlei Huang <zlei@FreeBSD.org>
To:        =?utf-8?Q?Mina_Gali=C4=87?= <freebsd@igalic.co>
Cc:        "freebsd-net@freebsd.org" <freebsd-net@freebsd.org>
Subject:   Re: How to tell if a network interface was renamed (and from what)
Message-ID:  <E5F5F61E-3827-404A-A46F-BBCF45A29A82@FreeBSD.org>
In-Reply-To: <pdHC0ObBkAbx2HfFIhWYaB5-dmQDEUzNTWvVVJAuJV7FWdWWeSwybVFD-uyBUxPlqDRpAW7D1aAZsbrTxEj9kqsq7ESgO41srPmS-PcXGqw=@igalic.co>
References:  <pdHC0ObBkAbx2HfFIhWYaB5-dmQDEUzNTWvVVJAuJV7FWdWWeSwybVFD-uyBUxPlqDRpAW7D1aAZsbrTxEj9kqsq7ESgO41srPmS-PcXGqw=@igalic.co>

next in thread | previous in thread | raw e-mail | index | archive | help

--Apple-Mail=_6FD7852A-BC35-4FE3-97EE-B65056ABE9B5
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8



> On Nov 19, 2023, at 6:20 AM, Mina Gali=C4=87 <freebsd@igalic.co> =
wrote:
>=20
> Hi folks,
>=20
> 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-init/blob/5496745b394f9b7b9eaf57fd61933=
0d484ce2da8/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.
>=20
> I can't even think of an sensible way of replicating that.
> I can only think of terrible / wrong way of finding it out:
>=20
> dmesg | grep "changing name to '<new-netif>'"
>=20
> a less terrible method would be to check for, say:
>=20
> sysctl dev.<new-netif>.0.%driver
>=20
> if that fails, we probably have a renamed interface=E2=80=A6 but we =
don't know what it was renamed from, and this only works for *real* =
interfaces, not for cloned devices, or epairs.
>=20
> Now, ignoring my terrible hacky attempts at command line tooling, I =
would also 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 boottime): =
https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9eaf57fd61933=
0d484ce2da8/cloudinit/util.py#L2073-L2105
>=20
> Looking forward to reading your ideas.

FreeBSD currently does not preserve the old ( original ) name of =
interfaces if it is renamed ( either physical or cloned ones ).
While there's an attempt https://reviews.freebsd.org/D28247 =
<https://reviews.freebsd.org/D28247>;  to get the device name (physical =
ones) but it is not perfect and not completed.

So may I ask why you need to know if a network interface was renamed ?

>=20
> Kind regards,
>=20
> Mina Gali=C4=87
>=20

Best regards,
Zhenlei


--Apple-Mail=_6FD7852A-BC35-4FE3-97EE-B65056ABE9B5
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; =
charset=3Dutf-8"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: after-white-space;" class=3D""><br =
class=3D""><div><br class=3D""><blockquote type=3D"cite" class=3D""><div =
class=3D"">On Nov 19, 2023, at 6:20 AM, Mina Gali=C4=87 &lt;<a =
href=3D"mailto:freebsd@igalic.co" class=3D"">freebsd@igalic.co</a>&gt; =
wrote:</div><br class=3D"Apple-interchange-newline"><div class=3D""><div =
class=3D"">Hi folks,<br class=3D""><br class=3D"">Linux has an "easy" =
way of telling if an interface has been renamed.<br class=3D"">See =
cloud-init's is_renamed function: <a =
href=3D"https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9eaf5=
7fd619330d484ce2da8/cloudinit/net/__init__.py#L338-L350" =
class=3D"">https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9e=
af57fd619330d484ce2da8/cloudinit/net/__init__.py#L338-L350</a><br =
class=3D"">This code reads /sys/class/net/&lt;netif&gt;/name_assign_type =
and if that is 3 or 4, it's been renamed.<br class=3D""><br class=3D"">I =
can't even think of an sensible way of replicating that.<br class=3D"">I =
can only think of terrible / wrong way of finding it out:<br =
class=3D""><br class=3D"">dmesg | grep "changing name to =
'&lt;new-netif&gt;'"<br class=3D""><br class=3D"">a less terrible method =
would be to check for, say:<br class=3D""><br class=3D"">sysctl =
dev.&lt;new-netif&gt;.0.%driver<br class=3D""><br class=3D"">if that =
fails, we probably have a renamed interface=E2=80=A6 but we don't know =
what it was renamed from, and this only works for *real* interfaces, not =
for cloned devices, or epairs.<br class=3D""><br class=3D"">Now, =
ignoring my terrible hacky attempts at command line tooling, I would =
also 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 boottime): <a =
href=3D"https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9eaf5=
7fd619330d484ce2da8/cloudinit/util.py#L2073-L2105" =
class=3D"">https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9e=
af57fd619330d484ce2da8/cloudinit/util.py#L2073-L2105</a><br class=3D""><br=
 class=3D"">Looking forward to reading your ideas.<br =
class=3D""></div></div></blockquote><div><br class=3D""></div><div>FreeBSD=
 currently does not preserve the old ( original ) name of interfaces if =
it is renamed ( either physical or cloned ones ).</div><div>While =
there's an attempt <a href=3D"https://reviews.freebsd.org/D28247" =
class=3D"">https://reviews.freebsd.org/D28247</a>; &nbsp;to get the =
device name (physical ones) but it is not perfect and not =
completed.</div><div><br class=3D""></div><div>So may I ask why you need =
to know if a network interface was renamed ?</div><br =
class=3D""><blockquote type=3D"cite" class=3D""><div class=3D""><div =
class=3D""><br class=3D"">Kind regards,<br class=3D""><br class=3D"">Mina =
Gali=C4=87<br class=3D""><br class=3D""></div></div></blockquote></div><br=
 class=3D""><div class=3D"">
<div>Best regards,</div><div>Zhenlei</div>

</div>
<br class=3D""></body></html>=

--Apple-Mail=_6FD7852A-BC35-4FE3-97EE-B65056ABE9B5--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E5F5F61E-3827-404A-A46F-BBCF45A29A82>