git: 5c32488de0bb - main - linux(4): Add a counterpart to linux_ifflags

From: Dmitry Chagin <dchagin_at_FreeBSD.org>
Date: Sat, 04 Mar 2023 09:26:58 UTC
The branch main has been updated by dchagin:

URL: https://cgit.FreeBSD.org/src/commit/?id=5c32488de0bbd9f7b52e3ff8be8ca2facc3169ba

commit 5c32488de0bbd9f7b52e3ff8be8ca2facc3169ba
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2023-03-04 09:26:48 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2023-03-04 09:26:48 +0000

    linux(4): Add a counterpart to linux_ifflags
    
    For further use in linux_ioctl_socket add bsd_to_linux_ifflags() which
    accepts FreeBSD interface flags and translate it to Linux if flags.
    
    Reviewed by:            melifaro
    Differential Revision:  https://reviews.freebsd.org/D38873
---
 sys/compat/linux/linux.c        | 13 ++++++++++---
 sys/compat/linux/linux_common.h |  1 +
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/sys/compat/linux/linux.c b/sys/compat/linux/linux.c
index 53a874ebfab7..252645cf2ae5 100644
--- a/sys/compat/linux/linux.c
+++ b/sys/compat/linux/linux.c
@@ -434,10 +434,17 @@ ifname_linux_to_bsd(struct thread *td, const char *lxname, char *bsdname)
 unsigned short
 linux_ifflags(struct ifnet *ifp)
 {
-	unsigned short fl, flags;
+	unsigned short flags;
+
+	flags = if_getflags(ifp) | if_getdrvflags(ifp);
+	return (bsd_to_linux_ifflags(flags));
+}
+
+unsigned short
+bsd_to_linux_ifflags(int fl)
+{
+	unsigned short flags = 0;
 
-	fl = (if_getflags(ifp) | if_getdrvflags(ifp)) & 0xffff;
-	flags = 0;
 	if (fl & IFF_UP)
 		flags |= LINUX_IFF_UP;
 	if (fl & IFF_BROADCAST)
diff --git a/sys/compat/linux/linux_common.h b/sys/compat/linux/linux_common.h
index 3392f55672f3..94ff5e49b57a 100644
--- a/sys/compat/linux/linux_common.h
+++ b/sys/compat/linux/linux_common.h
@@ -39,6 +39,7 @@ int	ifname_linux_to_bsd(struct thread *, const char *, char *);
 unsigned short	linux_ifflags(struct ifnet *);
 int		linux_ifhwaddr(struct ifnet *ifp, struct l_sockaddr *lsa);
 
+unsigned short	bsd_to_linux_ifflags(int);
 int		linux_to_bsd_domain(int domain);
 int		bsd_to_linux_domain(int domain);
 int		bsd_to_linux_sockaddr(const struct sockaddr *sa,