Re: [PATCH net-next 02/11] tools: ynl-gen: generate nested array policies

Asbjørn Sloth Tønnesen <[email protected]>
Newsgroups com.zx2c4.lists.wireguard,org.kernel.vger.linux-kernel,org.kernel.vger.netdev
Message-ID <[email protected]>
CC: Johannes

On 9/6/25 12:19 AM, Jacob Keller wrote:
> On 9/4/2025 3:01 PM, Asbjørn Sloth Tønnesen wrote:
>> This patch adds support for NLA_POLICY_NESTED_ARRAY() policies.
>>
>> Example spec (from future wireguard.yaml):
>> -
>>    name: wgpeer
>>    attributes:
>>      -
>>        name: allowedips
>>        type: indexed-array
>>        sub-type: nest
>>        nested-attributes: wgallowedip
>>
>> yields NLA_POLICY_NESTED_ARRAY(wireguard_wgallowedip_nl_policy).
>>
>> This doesn't change any currently generated code, as it isn't
>> used in any specs currently used for generating code.
>>
>> Signed-off-by: Asbjørn Sloth Tønnesen <[email protected]>
>> ---
> 
> Is this keyed of off the sub-type? Does you mean that all the existing
> uses of 'sub-type: nest' don't generate code today? Or that this
> _attr_policy implementation is not called yet?

Thanks for the reviews. Yeah, it is a careful wording, because we have
specs matching it, but there aren't any source files that triggers
ynl-gen to generate code based on those specs.

Therefore this patch, doesn't result in any code changes when running:
$ ./tools/net/ynl/ynl-regen.sh -f

Actually ynl-gen generates a fictive "{ .type = NLA_INDEXED_ARRAY, }"
policy, without this patch, leading to a build failure.

> I checked and we have quite a number of uses:
> 
>> $ rg 'sub-type: nest'
>> Documentation/netlink/specs/nlctrl.yaml
 >> [..]
>> Documentation/netlink/specs/tc.yaml
>> [..]
>> Documentation/netlink/specs/rt-link.yaml
>> [..]
>> Documentation/netlink/specs/nl80211.yaml
>> [..]

None of those currently have a generated netlink policy.

These are the netlink policies currently generated by ynl-gen:
$ git grep -h -B1 'YNL-GEN kernel source' | grep '^/\*[^ ]'
/*      Documentation/netlink/specs/dpll.yaml */
/*      Documentation/netlink/specs/ovpn.yaml */
/*      Documentation/netlink/specs/team.yaml */
/*      Documentation/netlink/specs/lockd.yaml */
/*      Documentation/netlink/specs/nfsd.yaml */
/*      Documentation/netlink/specs/netdev.yaml */
/*      Documentation/netlink/specs/devlink.yaml */
/*      Documentation/netlink/specs/handshake.yaml */
/*      Documentation/netlink/specs/fou.yaml */
/*      Documentation/netlink/specs/mptcp_pm.yaml */
/*      Documentation/netlink/specs/net_shaper.yaml */

Johannes introduced NLA_NESTED_ARRAY and the NLA_POLICY_NESTED_ARRAY()
macro in commit 1501d13596b9 for use in nl80211, and it's therefore
used in net/wireless/nl80211.c, but outside of that the macro is
only sparsely adopted (only by mac80211_hwsim.c and nf_tables_api.c).

Wireguard adopts the macro in this RFC patch:
https://lore.kernel.org/netdev/[email protected]/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.