Re: [PATCH net-next v3 08/11] tools: ynl: add sample for wireguard
From: Asbjørn Sloth Tønnesen
Date: Tue Nov 18 2025 - 12:16:47 EST
On 11/18/25 3:20 PM, Jason A. Donenfeld wrote:
On Wed, Nov 05, 2025 at 06:32:17PM +0000, Asbjørn Sloth Tønnesen wrote:
+CFLAGS_wireguard:=$(call get_hdr_inc,_LINUX_WIREGUARD_H,wireguard.h) \
+ -D _WG_UAPI_WIREGUARD_H # alternate pre-YNL guard
I don't totally grok what's going on here. As I understand it, this
makefile creates `wireguard-user.h` in the generated/ include path,
which has all the various netlink wrapper declarations. And then this
also references, somehow, include/uapi/linux/wireguard.h, for the constants.
For some reason, you're then defining _WG_UAPI_WIREGUARD_H here, so that
wireguard.h from /usr/include doesn't clash. But also, why would it?
Isn't this just a matter of placing $(src)/include/uapi earlier in the
include file path?
The aim is to use the generated in-tree header, while avoiding making a
copy, and avoiding the system header.
As an example then in tools/net/ynl/generated/Makefile:
%-user.o: %-user.c %-user.h
@echo -e "\tCC $@"
@$(COMPILE.c) $(CFLAGS_$*) -o $@ $<
Where for the "wireguard-user.o" target, then "$(CFLAGS_$*)" expands to
"$CFLAGS_wireguard".
CFLAGS_wireguard has two parts the normal one similar to the other families,
and a transitional extra guard.
The header guard in the old UAPI header is "_WG_UAPI_WIREGUARD_H".
The header guard in the new UAPI header in-tree is "_UAPI_LINUX_WIREGUARD_H".
The header guard in the new UAPI header in-system is "_LINUX_WIREGUARD_H".
Linux uapi headers are installed using scripts/headers_install.sh, which
transforms the headers slightly, one of these transformations is to alter
the header guard, stripping the _UAPI in the beginning of the guard.
So "get_hdr_inc=-D$(1) -include $(UAPI_PATH)/linux/$(2)" does:
1) Defines the in-system guard
2) Includes the in-tree header
The purpose of defining the in-system guard is disable the include in
the code, as it's header guard is already defined.
I added the extra transitional define of the old UAPI guard, so that
it also works on systems with the old header installed in /usr.
This extra line can be removed in a few releases, when we don't care
about compiling these tools on a system with the old header installed.