xref: /linux/Documentation/netlink/genetlink-c.yaml (revision 7681a4f58fb9c338d6dfe1181607f84c793d77de)
1# SPDX-License-Identifier: GPL-2.0
2%YAML 1.2
3---
4$id: http://kernel.org/schemas/netlink/genetlink-c.yaml#
5$schema: https://json-schema.org/draft-07/schema
6
7# Common defines
8$defs:
9  uint:
10    type: integer
11    minimum: 0
12  len-or-define:
13    type: [ string, integer ]
14    pattern: ^[0-9A-Za-z_]+( - 1)?$
15    minimum: 0
16
17# Schema for specs
18title: Protocol
19description: Specification of a genetlink protocol
20type: object
21required: [ name, doc, attribute-sets, operations ]
22additionalProperties: False
23properties:
24  name:
25    description: Name of the genetlink family.
26    type: string
27  doc:
28    type: string
29  version:
30    description: Generic Netlink family version. Default is 1.
31    type: integer
32    minimum: 1
33  protocol:
34    description: Schema compatibility level. Default is "genetlink".
35    enum: [ genetlink, genetlink-c ]
36  # Start genetlink-c
37  uapi-header:
38    description: Path to the uAPI header, default is linux/${family-name}.h
39    type: string
40  c-family-name:
41    description: Name of the define for the family name.
42    type: string
43  c-version-name:
44    description: Name of the define for the verion of the family.
45    type: string
46  max-by-define:
47    description: Makes the number of attributes and commands be specified by a define, not an enum value.
48    type: boolean
49  # End genetlink-c
50
51  definitions:
52    description: List of type and constant definitions (enums, flags, defines).
53    type: array
54    items:
55      type: object
56      required: [ type, name ]
57      additionalProperties: False
58      properties:
59        name:
60          type: string
61        header:
62          description: For C-compatible languages, header which already defines this value.
63          type: string
64        type:
65          enum: [ const, enum, flags ]
66        doc:
67          type: string
68        # For const
69        value:
70          description: For const - the value.
71          type: [ string, integer ]
72        # For enum and flags
73        value-start:
74          description: For enum or flags the literal initializer for the first value.
75          type: [ string, integer ]
76        entries:
77          description: For enum or flags array of values.
78          type: array
79          items:
80            oneOf:
81              - type: string
82              - type: object
83                required: [ name ]
84                additionalProperties: False
85                properties:
86                  name:
87                    type: string
88                  value:
89                    type: integer
90                  doc:
91                    type: string
92        render-max:
93          description: Render the max members for this enum.
94          type: boolean
95        # Start genetlink-c
96        enum-name:
97          description: Name for enum, if empty no name will be used.
98          type: [ string, "null" ]
99        name-prefix:
100          description: For enum the prefix of the values, optional.
101          type: string
102        # End genetlink-c
103
104  attribute-sets:
105    description: Definition of attribute spaces for this family.
106    type: array
107    items:
108      description: Definition of a single attribute space.
109      type: object
110      required: [ name, attributes ]
111      additionalProperties: False
112      properties:
113        name:
114          description: |
115            Name used when referring to this space in other definitions, not used outside of the spec.
116          type: string
117        name-prefix:
118          description: |
119            Prefix for the C enum name of the attributes. Default family[name]-set[name]-a-
120          type: string
121        enum-name:
122          description: Name for the enum type of the attribute.
123          type: string
124        doc:
125          description: Documentation of the space.
126          type: string
127        subset-of:
128          description: |
129            Name of another space which this is a logical part of. Sub-spaces can be used to define
130            a limited group of attributes which are used in a nest.
131          type: string
132        # Start genetlink-c
133        attr-cnt-name:
134          description: The explicit name for constant holding the count of attributes (last attr + 1).
135          type: string
136        attr-max-name:
137          description: The explicit name for last member of attribute enum.
138          type: string
139        # End genetlink-c
140        attributes:
141          description: List of attributes in the space.
142          type: array
143          items:
144            type: object
145            required: [ name, type ]
146            additionalProperties: False
147            properties:
148              name:
149                type: string
150              type: &attr-type
151                enum: [ unused, pad, flag, binary, u8, u16, u32, u64, s32, s64,
152                        string, nest, array-nest, nest-type-value ]
153              doc:
154                description: Documentation of the attribute.
155                type: string
156              value:
157                description: Value for the enum item representing this attribute in the uAPI.
158                $ref: '#/$defs/uint'
159              type-value:
160                description: Name of the value extracted from the type of a nest-type-value attribute.
161                type: array
162                items:
163                  type: string
164              byte-order:
165                enum: [ little-endian, big-endian ]
166              multi-attr:
167                type: boolean
168              nested-attributes:
169                description: Name of the space (sub-space) used inside the attribute.
170                type: string
171              enum:
172                description: Name of the enum type used for the attribute.
173                type: string
174              enum-as-flags:
175                description: |
176                  Treat the enum as flags. In most cases enum is either used as flags or as values.
177                  Sometimes, however, both forms are necessary, in which case header contains the enum
178                  form while specific attributes may request to convert the values into a bitfield.
179                type: boolean
180              checks:
181                description: Kernel input validation.
182                type: object
183                additionalProperties: False
184                properties:
185                  flags-mask:
186                    description: Name of the flags constant on which to base mask (unsigned scalar types only).
187                    type: string
188                  min:
189                    description: Min value for an integer attribute.
190                    type: integer
191                  min-len:
192                    description: Min length for a binary attribute.
193                    $ref: '#/$defs/len-or-define'
194                  max-len:
195                    description: Max length for a string or a binary attribute.
196                    $ref: '#/$defs/len-or-define'
197              sub-type: *attr-type
198
199      # Make sure name-prefix does not appear in subsets (subsets inherit naming)
200      dependencies:
201        name-prefix:
202          not:
203            required: [ subset-of ]
204        subset-of:
205          not:
206            required: [ name-prefix ]
207
208  operations:
209    description: Operations supported by the protocol.
210    type: object
211    required: [ list ]
212    additionalProperties: False
213    properties:
214      enum-model:
215        description: |
216          The model of assigning values to the operations.
217          "unified" is the recommended model where all message types belong
218          to a single enum.
219          "directional" has the messages sent to the kernel and from the kernel
220          enumerated separately.
221          "notify-split" has the notifications and request-response types in
222          different enums.
223        enum: [ unified, directional, notify-split ]
224      name-prefix:
225        description: |
226          Prefix for the C enum name of the command. The name is formed by concatenating
227          the prefix with the upper case name of the command, with dashes replaced by underscores.
228        type: string
229      enum-name:
230        description: Name for the enum type with commands.
231        type: string
232      async-prefix:
233        description: Same as name-prefix but used to render notifications and events to separate enum.
234        type: string
235      async-enum:
236        description: Name for the enum type with notifications/events.
237        type: string
238      list:
239        description: List of commands
240        type: array
241        items:
242          type: object
243          additionalProperties: False
244          required: [ name, doc ]
245          properties:
246            name:
247              description: Name of the operation, also defining its C enum value in uAPI.
248              type: string
249            doc:
250              description: Documentation for the command.
251              type: string
252            value:
253              description: Value for the enum in the uAPI.
254              $ref: '#/$defs/uint'
255            attribute-set:
256              description: |
257                Attribute space from which attributes directly in the requests and replies
258                to this command are defined.
259              type: string
260            flags: &cmd_flags
261              description: Command flags.
262              type: array
263              items:
264                enum: [ admin-perm ]
265            dont-validate:
266              description: Kernel attribute validation flags.
267              type: array
268              items:
269                enum: [ strict, dump ]
270            do: &subop-type
271              description: Main command handler.
272              type: object
273              additionalProperties: False
274              properties:
275                request: &subop-attr-list
276                  description: Definition of the request message for a given command.
277                  type: object
278                  additionalProperties: False
279                  properties:
280                    attributes:
281                      description: |
282                        Names of attributes from the attribute-set (not full attribute
283                        definitions, just names).
284                      type: array
285                      items:
286                        type: string
287                reply: *subop-attr-list
288                pre:
289                  description: Hook for a function to run before the main callback (pre_doit or start).
290                  type: string
291                post:
292                  description: Hook for a function to run after the main callback (post_doit or done).
293                  type: string
294            dump: *subop-type
295            notify:
296              description: Name of the command sharing the reply type with this notification.
297              type: string
298            event:
299              type: object
300              additionalProperties: False
301              properties:
302                attributes:
303                  description: Explicit list of the attributes for the notification.
304                  type: array
305                  items:
306                    type: string
307            mcgrp:
308              description: Name of the multicast group generating given notification.
309              type: string
310  mcast-groups:
311    description: List of multicast groups.
312    type: object
313    required: [ list ]
314    additionalProperties: False
315    properties:
316      list:
317        description: List of groups.
318        type: array
319        items:
320          type: object
321          required: [ name ]
322          additionalProperties: False
323          properties:
324            name:
325              description: |
326                The name for the group, used to form the define and the value of the define.
327              type: string
328            # Start genetlink-c
329            c-define-name:
330              description: Override for the name of the define in C uAPI.
331              type: string
332            # End genetlink-c
333            flags: *cmd_flags
334