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