From nobody Sun Nov 19 01:15:04 2023 X-Original-To: freebsd-net@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SXt3j2GBTz50xxY for ; Sun, 19 Nov 2023 01:15:13 +0000 (UTC) (envelope-from zlei@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SXt3h5h8Tz3STr; Sun, 19 Nov 2023 01:15:12 +0000 (UTC) (envelope-from zlei@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700356512; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=w8Fy1jlVzkHpvHe/F4SRF4Ujwd+GONCOPAlLu7Voh1k=; b=Gg5PdI7WDT7qsNSUQTq+po9gWFEexRzzgO2Ra7MnrZT2g4R/atnCuwBcNlVaNs5RKxqb4Z XgvNruEztwlWy3W0HwnZbtDo+9FgblsGmNkdV0GrUmRkHV4RWe9n4eBkLwM6JVFKk7ukoJ EXv+qsAjOGrr1xba9CN1FHIIhicL3T/OViAclLT/L0pUuYPCkik/nN5E5+CUVkX1A3tWEi 50tZL29nBE3zGB06RSkk3KBeQJA7oG7X4ZiOP0txx6AQNZccYIyt5+F/C8o9snlKLz9XuQ O18AJaJ+Q9Q1y9wSDHV0aPVW7J+MRSvl7UFvT2uAPJixkYeyI9wuekC5LY18HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700356512; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=w8Fy1jlVzkHpvHe/F4SRF4Ujwd+GONCOPAlLu7Voh1k=; b=DsWQCEYcFQiTMqq3r4YdWNkyb69ktS36ql2HiapRF5ktvGoEIsW657F+TYzuH3MA5NlnU/ pL2sGNbpQvB06ixuaruGNIDG1r7RH2vhMh2ApTgvuOWLh4dIJ4jF+RfQifAUlj42aCMFYM kk3uYFj6hMMj+y4AOyY8TLpGwOHaXuy0Gt+vairZkFzShqzx5mhPfKJzMwncNHQndZrgVj g2hTtBkxKQDLL+g11xiovjmKtQrGeCglNc0HySeORSAL3yGdTQgAQXIzLFlAxrRnuvbbwP JumM3kd9OOswCjaMha0uMfnsLpfxESnm56vW7B2Mh+ZDlhyok305i/OFJq8FBg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1700356512; a=rsa-sha256; cv=none; b=Rptjoi4u5pYeINxjjQkBH4TimhsEL4FtTO5uRts9enFllgf/LG45cSfHrCYNkske0Uny8U k4lmyE9nnYvkUd7valtQeyEhx4eA7H8bVwbXF7Y6VwtKwX79Hlg2DMLMpHlnpZhyFPDHPk YmLYWNTvDCiRMvtCLhLW/fp0mcM7cbi4vYY00i4Xun3DmA7L23IyWYZ40Mrlz/fys4jdB8 bg0cnM+sYX364ftqOgWfigsaSP5h99fuDf76olL1BCeExvB6m0nSV2eQyVn5DZTM9B+HDZ aDZMf3CoXBWPaljskOTdUn32J6XH/tiaA4UAMXIf6rQiP+t9U9no9y+yzztzkA== Received: from smtpclient.apple (ns1.oxydns.net [45.32.91.63]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: zlei/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 4SXt3g5ZL3z168s; Sun, 19 Nov 2023 01:15:11 +0000 (UTC) (envelope-from zlei@FreeBSD.org) From: Zhenlei Huang Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_6FD7852A-BC35-4FE3-97EE-B65056ABE9B5" List-Id: Networking and TCP/IP with FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-net List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-net@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.4\)) Subject: Re: How to tell if a network interface was renamed (and from what) Date: Sun, 19 Nov 2023 09:15:04 +0800 In-Reply-To: Cc: "freebsd-net@freebsd.org" To: =?utf-8?Q?Mina_Gali=C4=87?= References: X-Mailer: Apple Mail (2.3696.120.41.1.4) --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 = 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//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 ''" >=20 > a less terrible method would be to check for, say: >=20 > sysctl dev..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 = 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

On Nov 19, 2023, at 6:20 AM, Mina Gali=C4=87 <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/5496745b394f9b7b9e= af57fd619330d484ce2da8/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 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/5496745b394f9b7b9e= af57fd619330d484ce2da8/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  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=C4=87

Best regards,
Zhenlei

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