diff options
author | Alexander V. Chernikov <melifaro@FreeBSD.org> | 2022-01-08 15:41:53 +0000 |
---|---|---|
committer | Alexander V. Chernikov <melifaro@FreeBSD.org> | 2022-03-28 08:49:23 +0000 |
commit | c7655e1f3671a9ce7d963cb577b4548173469053 (patch) | |
tree | 794bc0576b3692e88d02d7bc14f95947aad61ea7 /sys/compat | |
parent | 0b6161db7eff92a37bc6d410ff9c9d5c3ac6f443 (diff) |
linux: add sysctl to pass untranslated interface names
Reviewed by: kib
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D33792
(cherry picked from commit 1f70a85b4cbc3ad19cec4a390e8754e54815be85)
Diffstat (limited to 'sys/compat')
-rw-r--r-- | sys/compat/linprocfs/linprocfs.c | 9 | ||||
-rw-r--r-- | sys/compat/linux/linux.h | 6 | ||||
-rw-r--r-- | sys/compat/linux/linux_ioctl.c | 4 | ||||
-rw-r--r-- | sys/compat/linux/linux_util.c | 15 | ||||
-rw-r--r-- | sys/compat/linux/linux_util.h | 9 |
5 files changed, 28 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 <sys/systm.h> #include <sys/vnode.h> +#include <net/if.h> +#include <net/if_var.h> +#include <net/if_types.h> + #include <machine/stdarg.h> #include <compat/linux/linux_dtrace.h> @@ -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 |