Subject: Re: [PATCH v2 1/2][next] UAPI: ethtool: Use __struct_group() in struct ethtool_link_settings

From: Kees Cook <[email-masked]>
Date: Thu, 12 Dec 2024 09:29:02 -0800

On Mon, Dec 09, 2024 at 04:39:38PM -0800, Christopher Ferris wrote:
> By the way, there are some places where __struct_group is used in other
> uapi headers, the only difference is that the TAG field of the macro is
> left empty. That compiles fine when used in C++ code.

Does this fix the C++ inclusion for you?

diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h
index 2c32080416b5..aeff841c528d 100644
--- a/include/uapi/linux/pkt_cls.h
+++ b/include/uapi/linux/pkt_cls.h
@@ -245,20 +245,27 @@ struct tc_u32_key {
 	int		offmask;
 };
 
+#define tc_u32_sel_hdr_members			\
+	unsigned char		flags;		\
+	unsigned char		offshift;	\
+	unsigned char		nkeys;		\
+	__be16			offmask;	\
+	__u16			off;		\
+	short			offoff;		\
+	short			hoff;
+
+struct tc_u32_sel_hdr {
+	tc_u32_sel_hdr_members
+};
+
 struct tc_u32_sel {
-	/* New members MUST be added within the __struct_group() macro below. */
-	__struct_group(tc_u32_sel_hdr, hdr, /* no attrs */,
-		unsigned char		flags;
-		unsigned char		offshift;
-		unsigned char		nkeys;
-
-		__be16			offmask;
-		__u16			off;
-		short			offoff;
-
-		short			hoff;
-		__be32			hmask;
-	);
+	/* Open-coded struct_group() to avoid C++ errors. */
+	union {
+		struct tc_u32_sel_hdr hdr;
+		struct {
+			tc_u32_sel_hdr_members
+		};
+	};
 	struct tc_u32_key	keys[];
 };

-- 
Kees Cook