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