From nobody Mon Mar 28 15:26:03 2022 X-Original-To: dev-commits-src-branches@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 414921A31A7D; Mon, 28 Mar 2022 15:26:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KRxNq5K9jz3QJM; Mon, 28 Mar 2022 15:26:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648481164; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IkDg82d5Io/zvQRt0C90N41cey0wo94dlYDkJX/8pjo=; b=tf71QCCCOcgIupKG5hnC8mFh6PyJ55kzPN8GL3TY3YUFf3TCBdxqCBiU+PlQN1VKiuoQD9 WOtrru2Jpci3bHILJp8L6fdlL080JLqED0EHGgu27aZiRBdrMLLNorw7L9ODZPbMPrNTDL x6URDhiYZ86jv3GFawDl8GiSOZFjVDAcExmwlO1svumcicn0sZlyrvwm0QBpgil17Z7+uL UgVFrmS/8zWUJm/Ass4fQfHLdTOf4oRe7BZoqCNua/k1rNI07irWhW7+s4UNs7mvUBqhuF 66ujQUgWRY+FQvfVszAo6SGgkvEbePegnkqNhu1uDr4nGSkWwi/k3ztVAAbUUA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7C2C543CB; Mon, 28 Mar 2022 15:26:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 22SFQ3sH086968; Mon, 28 Mar 2022 15:26:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22SFQ3aR086967; Mon, 28 Mar 2022 15:26:03 GMT (envelope-from git) Date: Mon, 28 Mar 2022 15:26:03 GMT Message-Id: <202203281526.22SFQ3aR086967@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 9b42da2b339c - releng/13.1 - linux: add sysctl to pass untranslated interface names List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.1 X-Git-Reftype: branch X-Git-Commit: 9b42da2b339c7245fb9768ac7f26df61d2af4e51 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648481164; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IkDg82d5Io/zvQRt0C90N41cey0wo94dlYDkJX/8pjo=; b=YBW3jj+Td5/0VuQGelJRhC9CtLez7k1Dm8GAkjnxoveXkExWEE/90ZGljhQTGWSnJYUTTx 1BycFvjxeMCwiMdSDbLjtWx1EE99urKeB5Czim4r8mZXhKKTS1B1WW1Sr2fVbOwvXsc/z0 otGP/HrO6fTZy0bbga8SlswRfWIrQKYoQgxk3ErAUp7RIeNpADoJP2UA7PBkc94CS+SNGo kj6Eq27KkIpMBVTiZKPdpNbtqiFOhqvl/ALthXl5puEdCM8FvkCEkyfaR0DNQEdOOxyQOS Jw47HOI2eI5q+3HfMxGvZTELvXPyJTyqoFuPBkIggJiwl7W1p9iB/IMRxU9OqA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648481164; a=rsa-sha256; cv=none; b=UyHfLSBB6aqIXQLcIEkpqXnI8CmhSzryDMdJM7PTxf0uKJ5tYz18mcXSbh/F3yI2VI2MGQ XX9LBiP43tUL+M7wtzZ8xx7QH6Zbbc9JOTkLV3J0cbvhgyZluVjjCUp1lLFSLEsZcBU1m5 YWisUNTDQbgKs8GvG8SCT6PJ2NnHRHmnYl52gNGsWWulb1DTDS80Byh+nErHfVM/wgma9I DYTM1aQwQ4WwZ3rp96MQEIBfGIIzFsE8NR0z9MUTJ1Q22yH5cxeML2i2LxUfy5HNTEEY6g Kamqs2v7wU+aagBTVqQ4IHIXxCRa5A21FrjT/PivAd6N1W1u+hEw3VRE5Wcvfg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch releng/13.1 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=9b42da2b339c7245fb9768ac7f26df61d2af4e51 commit 9b42da2b339c7245fb9768ac7f26df61d2af4e51 Author: Alexander V. Chernikov AuthorDate: 2022-01-08 15:41:53 +0000 Commit: Alexander V. Chernikov CommitDate: 2022-03-28 15:25:20 +0000 linux: add sysctl to pass untranslated interface names Reviewed by: kib Approved by: re(gjb) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D33792 (cherry picked from commit 1f70a85b4cbc3ad19cec4a390e8754e54815be85) (cherry picked from commit c7655e1f3671a9ce7d963cb577b4548173469053) --- sys/compat/linprocfs/linprocfs.c | 9 ++------- sys/compat/linux/linux.h | 6 ------ sys/compat/linux/linux_ioctl.c | 4 ++-- sys/compat/linux/linux_util.c | 15 +++++++++++++++ sys/compat/linux/linux_util.h | 9 +++++++++ sys/modules/linux_common/Makefile | 1 + 6 files changed, 29 insertions(+), 15 deletions(-) diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c index a363644da744..27acd7d651a7 100644 --- a/sys/compat/linprocfs/linprocfs.c +++ b/sys/compat/linprocfs/linprocfs.c @@ -1414,11 +1414,6 @@ linprocfs_doprocmem(PFS_FILL_ARGS) return (error); } -/* - * Criteria for interface name translation - */ -#define IFP_IS_ETH(ifp) (ifp->if_type == IFT_ETHER) - static int linux_ifname(struct ifnet *ifp, char *buffer, size_t buflen) { @@ -1428,7 +1423,7 @@ linux_ifname(struct ifnet *ifp, char *buffer, size_t buflen) IFNET_RLOCK_ASSERT(); /* Short-circuit non ethernet interfaces */ - if (!IFP_IS_ETH(ifp)) + if (linux_use_real_ifname(ifp)) return (strlcpy(buffer, ifp->if_xname, buflen)); /* Determine the (relative) unit number for ethernet interfaces */ @@ -1436,7 +1431,7 @@ linux_ifname(struct ifnet *ifp, char *buffer, size_t buflen) CK_STAILQ_FOREACH(ifscan, &V_ifnet, if_link) { if (ifscan == ifp) return (snprintf(buffer, buflen, "eth%d", ethno)); - if (IFP_IS_ETH(ifscan)) + if (!linux_use_real_ifname(ifscan)) ethno++; } diff --git a/sys/compat/linux/linux.h b/sys/compat/linux/linux.h index 18eafa88a432..ba7a96e1aa79 100644 --- a/sys/compat/linux/linux.h +++ b/sys/compat/linux/linux.h @@ -34,12 +34,6 @@ #define LINUX_IFHWADDRLEN 6 #define LINUX_IFNAMSIZ 16 -/* - * Criteria for interface name translation - */ -#define IFP_IS_ETH(ifp) (ifp->if_type == IFT_ETHER) -#define IFP_IS_LOOP(ifp) (ifp->if_type == IFT_LOOP) - struct l_sockaddr { unsigned short sa_family; char sa_data[14]; diff --git a/sys/compat/linux/linux_ioctl.c b/sys/compat/linux/linux_ioctl.c index 101a52698a0a..cd89c16cad64 100644 --- a/sys/compat/linux/linux_ioctl.c +++ b/sys/compat/linux/linux_ioctl.c @@ -2121,7 +2121,7 @@ linux_ioctl_ifname(struct thread *td, struct l_ifreq *uifr) error = ENODEV; CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) { if (ifr.ifr_ifindex == index) { - if (IFP_IS_ETH(ifp)) + if (!linux_use_real_ifname(ifp)) snprintf(ifr.ifr_name, LINUX_IFNAMSIZ, "eth%d", ethno); else @@ -2130,7 +2130,7 @@ linux_ioctl_ifname(struct thread *td, struct l_ifreq *uifr) error = 0; break; } - if (IFP_IS_ETH(ifp)) + if (!linux_use_real_ifname(ifp)) ethno++; index++; } diff --git a/sys/compat/linux/linux_util.c b/sys/compat/linux/linux_util.c index 8e5462636705..86266fd3178f 100644 --- a/sys/compat/linux/linux_util.c +++ b/sys/compat/linux/linux_util.c @@ -52,6 +52,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include +#include + #include #include @@ -86,6 +90,11 @@ SYSCTL_STRING(_compat_linux, OID_AUTO, emul_path, CTLFLAG_RWTUN, linux_emul_path, sizeof(linux_emul_path), "Linux runtime environment path"); +static bool use_real_ifnames = false; +SYSCTL_BOOL(_compat_linux, OID_AUTO, use_real_ifnames, CTLFLAG_RWTUN, + &use_real_ifnames, 0, + "Use FreeBSD interface names instead of generating ethN aliases"); + /* * Search an alternate path before passing pathname arguments on to * system calls. Useful for keeping a separate 'emulation tree'. @@ -319,3 +328,9 @@ linux_device_unregister_handler(struct linux_device_handler *d) return (EINVAL); } + +bool +linux_use_real_ifname(const struct ifnet *ifp) +{ + return (use_real_ifnames || !IFP_IS_ETH(ifp)); +} diff --git a/sys/compat/linux/linux_util.h b/sys/compat/linux/linux_util.h index 436d4313abc8..681c03c625e4 100644 --- a/sys/compat/linux/linux_util.h +++ b/sys/compat/linux/linux_util.h @@ -127,6 +127,15 @@ int linux_vn_get_major_minor(const struct vnode *vn, int *major, int *minor); char *linux_get_char_devices(void); void linux_free_get_char_devices(char *string); +/* + * Criteria for interface name translation + */ +#define IFP_IS_ETH(ifp) ((ifp)->if_type == IFT_ETHER) +#define IFP_IS_LOOP(ifp) ((ifp)->if_type == IFT_LOOP) + +struct ifnet; +bool linux_use_real_ifname(const struct ifnet *ifp); + #if defined(KTR) #define KTR_LINUX KTR_SUBSYS diff --git a/sys/modules/linux_common/Makefile b/sys/modules/linux_common/Makefile index 9197ba9454bc..1815714e9202 100644 --- a/sys/modules/linux_common/Makefile +++ b/sys/modules/linux_common/Makefile @@ -11,6 +11,7 @@ EXPORT_SYMS= EXPORT_SYMS+= linux_emul_path EXPORT_SYMS+= linux_get_osname EXPORT_SYMS+= linux_get_osrelease +EXPORT_SYMS+= linux_use_real_ifname .if !defined(KERNBUILDDIR) .warning Building Linuxulator outside of a kernel does not make sense