When `render-max` is set for an enum, then it generates either
(`__$pfx-MAX` and `$pfx-MAX`) or (`$pfx-MASK` for flags).
The count definition `__$pfx-MAX` can already be overridden via
`enum-cnt-name` in the spec.
This patch adds a new `enum-max-name` attribute which can be used
to override the names for either `$pfx-MAX` or `$pfx-MASK`.
The existing `enum-cnt-name` is only described for the genetlink-c
and genetlink-legacy protocols, so I have only added `enum-max-name`
for those protocols.
This doesn't change the generated output.
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
---
Alternatively `enum-max-name` should be added to all protocols, so
that genetlink families can also choose to eg. have these private
variables prefixed with "__". As NETDEV_XDP_ACT_MASK leaked into
xdp-tools [v1.4.0..v1.5.7], then if we want to change the default
names[1], then we would still need to be able to use an override
to keep the current NETDEV_XDP_ACT_MASK name in the netdev family.
[1] https://lore.kernel.org/netdev/20230614211715.01940bbd@kernel.org/
---
Documentation/netlink/genetlink-c.yaml | 3 +++
Documentation/netlink/genetlink-legacy.yaml | 3 +++
Documentation/userspace-api/netlink/c-code-gen.rst | 7 +++++--
tools/net/ynl/pyynl/ynl_gen_c.py | 6 ++++--
4 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/Documentation/netlink/genetlink-c.yaml b/Documentation/netlink/genetlink-c.yaml
index 5a234e9b5fa2e..755b24fb0c319 100644
--- a/Documentation/netlink/genetlink-c.yaml
+++ b/Documentation/netlink/genetlink-c.yaml
@@ -110,6 +110,9 @@ properties:
enum-cnt-name:
description: Name of the render-max counter enum entry.
type: string
+ enum-max-name:
+ description: Name of the render-max max or mask enum entry.
+ type: string
# End genetlink-c
attribute-sets:
diff --git a/Documentation/netlink/genetlink-legacy.yaml b/Documentation/netlink/genetlink-legacy.yaml
index 66fb8653a3442..ad4d69be6294e 100644
--- a/Documentation/netlink/genetlink-legacy.yaml
+++ b/Documentation/netlink/genetlink-legacy.yaml
@@ -124,6 +124,9 @@ properties:
enum-cnt-name:
description: Name of the render-max counter enum entry.
type: string
+ enum-max-name:
+ description: Name of the render-max max or mask enum entry.
+ type: string
# End genetlink-c
# Start genetlink-legacy
members:
diff --git a/Documentation/userspace-api/netlink/c-code-gen.rst b/Documentation/userspace-api/netlink/c-code-gen.rst
index 46415e6d646d2..413a56424012a 100644
--- a/Documentation/userspace-api/netlink/c-code-gen.rst
+++ b/Documentation/userspace-api/netlink/c-code-gen.rst
@@ -57,8 +57,11 @@ portion of the entry name.
Boolean ``render-max`` controls creation of the max values
(which are enabled by default for attribute enums). These max
-values are named ``__$pfx-MAX`` and ``$pfx-MAX``. The name
-of the first value can be overridden via ``enum-cnt-name`` property.
+values are named ``__$pfx-MAX`` and ``$pfx-MAX``, and can be
+overwritten via the properties ``enum-cnt-name`` and
+``enum-max-name`` respectively.
+For flags ``render-max`` will generate a mask with all flags set,
+which by default will be named ``$pfx-MASK``.
Attributes
==========
diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
index 5e1c702143d86..a1a0b559b431b 100755
--- a/tools/net/ynl/pyynl/ynl_gen_c.py
+++ b/tools/net/ynl/pyynl/ynl_gen_c.py
@@ -1067,8 +1067,10 @@ class EnumSet(SpecEnumSet):
self.value_pfx = yaml.get('name-prefix', f"{family.ident_name}-{yaml['name']}-")
self.header = yaml.get('header', None)
self.enum_cnt_name = yaml.get('enum-cnt-name', f'--{self.value_pfx}max')
- suffix = yaml['type'] == 'flags' and 'mask' or 'max'
- self.enum_max_name = f'{self.value_pfx}{suffix}'
+ self.enum_max_name = yaml.get('enum-max-name', None)
+ if not self.enum_max_name:
+ suffix = yaml['type'] == 'flags' and 'mask' or 'max'
+ self.enum_max_name = f'{self.value_pfx}{suffix}'
super().__init__(family, yaml)
--
2.51.0