git: a927409ce820 - main - linux(4): Rename struct l_ifreq members names to avoid conflicts with FreeBSD

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

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

commit a927409ce820909c344b8f1323285fd01046cc4f
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2023-03-04 09:11:38 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2023-03-04 09:11:38 +0000

    linux(4): Rename struct l_ifreq members names to avoid conflicts with FreeBSD
    
    For now we are using mixed names to access struct ifreq members, some
    of Linux (ifr_name, ifr_ifindex), others of FreeBSD. To avoid conflicts
    switch to use FreeBSD names.
    
    Reviewed by:            jhibbits
    Differential Revision:  https://reviews.freebsd.org/D38792
---
 sys/compat/linux/linux_ioctl.c  |  2 +-
 sys/compat/linux/linux_socket.c | 10 ++++++++++
 sys/compat/linux/linux_socket.h | 17 ++++++++++-------
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/sys/compat/linux/linux_ioctl.c b/sys/compat/linux/linux_ioctl.c
index 8551ba180aa4..9f1fdd3a6671 100644
--- a/sys/compat/linux/linux_ioctl.c
+++ b/sys/compat/linux/linux_ioctl.c
@@ -2097,7 +2097,7 @@ linux_ioctl_ifname(struct thread *td, struct l_ifreq *uifr)
 	error = copyin(uifr, &ifr, sizeof(ifr));
 	if (error != 0)
 		return (error);
-	ret = ifname_bsd_to_linux_idx(ifr.ifr_ifindex, ifr.ifr_name,
+	ret = ifname_bsd_to_linux_idx(ifr.ifr_index, ifr.ifr_name,
 	    LINUX_IFNAMSIZ);
 	if (ret > 0)
 		return (copyout(&ifr, uifr, sizeof(ifr)));
diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c
index a3a8cc6733c1..3748c1bedd3c 100644
--- a/sys/compat/linux/linux_socket.c
+++ b/sys/compat/linux/linux_socket.c
@@ -72,6 +72,16 @@ __FBSDID("$FreeBSD$");
 #include <compat/linux/linux_time.h>
 #include <compat/linux/linux_util.h>
 
+_Static_assert(offsetof(struct l_ifreq, ifr_ifru) ==
+    offsetof(struct ifreq, ifr_ifru),
+    "Linux ifreq members names should be equal to FreeeBSD");
+_Static_assert(offsetof(struct l_ifreq, ifr_index) ==
+    offsetof(struct ifreq, ifr_index),
+    "Linux ifreq members names should be equal to FreeeBSD");
+_Static_assert(offsetof(struct l_ifreq, ifr_name) ==
+    offsetof(struct ifreq, ifr_name),
+    "Linux ifreq members names should be equal to FreeeBSD");
+
 #define	SECURITY_CONTEXT_STRING	"unconfined"
 
 static int linux_sendmsg_common(struct thread *, l_int, struct l_msghdr *,
diff --git a/sys/compat/linux/linux_socket.h b/sys/compat/linux/linux_socket.h
index 9b332a7a9b86..ab9ab2100a96 100644
--- a/sys/compat/linux/linux_socket.h
+++ b/sys/compat/linux/linux_socket.h
@@ -336,11 +336,13 @@ struct l_ifmap {
 	/* 3 bytes spare */
 };
 
+/*
+ * Careful changing the declaration of this structure.
+ * To use FreeBSD names to access the struct l_ifreq members the
+ * member names of struct l_ifreq should be equal to the FreeBSD.
+ */
 struct l_ifreq {
-	union {
-		char	ifrn_name[LINUX_IFNAMSIZ];
-	} ifr_ifrn;
-
+	char	ifr_name[LINUX_IFNAMSIZ];
 	union {
 		struct l_sockaddr	ifru_addr;
 		struct l_sockaddr	ifru_dstaddr;
@@ -348,7 +350,7 @@ struct l_ifreq {
 		struct l_sockaddr	ifru_netmask;
 		struct l_sockaddr	ifru_hwaddr;
 		l_short		ifru_flags[1];
-		l_int		ifru_ivalue;
+		l_int		ifru_index;
 		l_int		ifru_mtu;
 		struct l_ifmap	ifru_map;
 		char		ifru_slave[LINUX_IFNAMSIZ];
@@ -357,8 +359,9 @@ struct l_ifreq {
 	} ifr_ifru;
 };
 
-#define	ifr_name	ifr_ifrn.ifrn_name	/* Interface name */
+/*
+ * Define here members which are not exists in the FreeBSD struct ifreq.
+ */
 #define	ifr_hwaddr	ifr_ifru.ifru_hwaddr	/* MAC address */
-#define	ifr_ifindex	ifr_ifru.ifru_ivalue	/* Interface index */
 
 #endif /* _LINUX_SOCKET_H_ */