Re: [PATCH net-next 3/6] tools: ynl-gen: use uapi mask definition in NLA_POLICY_MASK
From: Jakub Kicinski
Date: Tue Oct 14 2025 - 15:32:03 EST
On Tue, 14 Oct 2025 17:29:30 +0000 Asbjørn Sloth Tønnesen wrote:
> On 10/14/25 12:59 AM, Jakub Kicinski wrote:
> > On Mon, 13 Oct 2025 16:50:00 +0000 Asbjørn Sloth Tønnesen wrote:
> >> Currently when generating policies using NLA_POLICY_MASK(), then
> >> we emit a pre-computed decimal mask.
> >>
> >> When render-max is set, then we can re-use the mask definition,
> >> that has been generated in the uapi header.
> >
> > This will encourage people to render masks in uAPI which just pollutes
> > the uAPI files.
>
> It might, but is that a problem, given that most flag-sets are rather small?
Problem is a strong word. But if the choice is having a constant in
auto-generated code, or pointless, cargo-cult'ed mask values in the
uAPI headers - I choose the former.
> Example from include/uapi/linux/wireguard.h:
> > enum wgpeer_flag {
> > WGPEER_F_REMOVE_ME = 1U << 0,
> > WGPEER_F_REPLACE_ALLOWEDIPS = 1U << 1,
> > WGPEER_F_UPDATE_ONLY = 1U << 2,
> > __WGPEER_F_ALL = WGPEER_F_REMOVE_ME | WGPEER_F_REPLACE_ALLOWEDIPS |
> > WGPEER_F_UPDATE_ONLY
> > };
>
> I agree that a private "WGPEER_F_ALL" would be pollution, but "__WGPEER_F_ALL"
> is less likely to accidentally be used by user-space.
>
> I get why Jason likes having the __WGPEER_F_ALL in a place where it is easy
> to review that it has contains all flags, and why he don't like a policy like
> NLA_POLICY_MASK(.., 0x7).
>
> We could do the mask definition in the kernel code, like many handwritten
> netlink families does, but we still need to keep NETDEV_XDP_ACT_MASK in
> netdev.h or remove it's YNL-GEN header for some time.
It's a transitional problem. People coming from hand-crafted code feel
like they need a human-readable mask. 6mo later once they are
comfortable with YNL codegen they won't care. But, sadly, at that point
it is too late to delete stuff from the uAPI header.