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
[-- Attachment #1 --] > On Nov 19, 2023, at 6:20 AM, Mina Galić <freebsd@igalic.co> wrote: > > 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-init/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… but we don't know what it was renamed from, and this only works for *real* interfaces, not for cloned devices, or epairs. > > 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/5496745b394f9b7b9eaf57fd619330d484ce2da8/cloudinit/util.py#L2073-L2105 > > 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 ? > > Kind regards, > > Mina Galić > Best regards, Zhenlei [-- Attachment #2 --] <html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Nov 19, 2023, at 6:20 AM, Mina Galić <<a href="mailto:freebsd@igalic.co" class="">freebsd@igalic.co</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hi folks,<br class=""><br class="">Linux has an "easy" way of telling if an interface has been renamed.<br class="">See cloud-init's is_renamed function: <a href="https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9eaf57fd619330d484ce2da8/cloudinit/net/__init__.py#L338-L350" class="">https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9eaf57fd619330d484ce2da8/cloudinit/net/__init__.py#L338-L350</a><br class="">This code reads /sys/class/net/<netif>/name_assign_type and if that is 3 or 4, it's been renamed.<br class=""><br class="">I can't even think of an sensible way of replicating that.<br class="">I can only think of terrible / wrong way of finding it out:<br class=""><br class="">dmesg | grep "changing name to '<new-netif>'"<br class=""><br class="">a less terrible method would be to check for, say:<br class=""><br class="">sysctl dev.<new-netif>.0.%driver<br class=""><br class="">if that fails, we probably have a renamed interface… 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=""><br class="">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="https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9eaf57fd619330d484ce2da8/cloudinit/util.py#L2073-L2105" class="">https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9eaf57fd619330d484ce2da8/cloudinit/util.py#L2073-L2105</a><br class=""><br class="">Looking forward to reading your ideas.<br class=""></div></div></blockquote><div><br class=""></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="https://reviews.freebsd.org/D28247" class="">https://reviews.freebsd.org/D28247</a> to get the device name (physical ones) but it is not perfect and not completed.</div><div><br class=""></div><div>So may I ask why you need to know if a network interface was renamed ?</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">Kind regards,<br class=""><br class="">Mina Galić<br class=""><br class=""></div></div></blockquote></div><br class=""><div class=""> <div>Best regards,</div><div>Zhenlei</div> </div> <br class=""></body></html>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E5F5F61E-3827-404A-A46F-BBCF45A29A82>
