xref: /linux/Documentation/netlink/netlink-raw.yaml (revision 04317b129e4eb5c6f4a58bb899b2019c1545320b)
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/netlink-raw.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 raw netlink protocol
20type: object
21required: [ name, doc, attribute-sets, operations ]
22additionalProperties: False
23properties:
24  name:
25    description: Name of the netlink family.
26    type: string
27  doc:
28    type: string
29  protocol:
30    description: Schema compatibility level.
31    enum: [ netlink-raw ] # Trim
32  # Start netlink-raw
33  protonum:
34    description: Protocol number to use for netlink-raw
35    type: integer
36  # End netlink-raw
37  uapi-header:
38    description: Path to the uAPI header, default is linux/${family-name}.h
39    type: string
40  # Start genetlink-c
41  c-family-name:
42    description: Name of the define for the family name.
43    type: string
44  c-version-name:
45    description: Name of the define for the version of the family.
46    type: string
47  max-by-define:
48    description: Makes the number of attributes and commands be specified by a define, not an enum value.
49    type: boolean
50  # End genetlink-c
51  # Start genetlink-legacy
52  kernel-policy:
53    description: |
54      Defines if the input policy in the kernel is global, per-operation, or split per operation type.
55      Default is split.
56    enum: [ split, per-op, global ]
57  # End genetlink-legacy
58
59  definitions:
60    description: List of type and constant definitions (enums, flags, defines).
61    type: array
62    items:
63      type: object
64      required: [ type, name ]
65      additionalProperties: False
66      properties:
67        name:
68          type: string
69        header:
70          description: For C-compatible languages, header which already defines this value.
71          type: string
72        type:
73          enum: [ const, enum, flags, struct ] # Trim
74        doc:
75          type: string
76        # For const
77        value:
78          description: For const - the value.
79          type: [ string, integer ]
80        # For enum and flags
81        value-start:
82          description: For enum or flags the literal initializer for the first value.
83          type: [ string, integer ]
84        entries:
85          description: For enum or flags array of values.
86          type: array
87          items:
88            oneOf:
89              - type: string
90              - type: object
91                required: [ name ]
92                additionalProperties: False
93                properties:
94                  name:
95                    type: string
96                  value:
97                    type: integer
98                  doc:
99                    type: string
100        render-max:
101          description: Render the max members for this enum.
102          type: boolean
103        # Start genetlink-c
104        enum-name:
105          description: Name for enum, if empty no name will be used.
106          type: [ string, "null" ]
107        name-prefix:
108          description: For enum the prefix of the values, optional.
109          type: string
110        # End genetlink-c
111        # Start genetlink-legacy
112        members:
113          description: List of struct members. Only scalars and strings members allowed.
114          type: array
115          items:
116            type: object
117            required: [ name, type ]
118            additionalProperties: False
119            properties:
120              name:
121                type: string
122              type:
123                description: The netlink attribute type
124                enum: [ u8, u16, u32, u64, s8, s16, s32, s64, string, binary ]
125              len:
126                $ref: '#/$defs/len-or-define'
127              byte-order:
128                enum: [ little-endian, big-endian ]
129              doc:
130                description: Documentation for the struct member attribute.
131                type: string
132              enum:
133                description: Name of the enum type used for the attribute.
134                type: string
135              enum-as-flags:
136                description: |
137                  Treat the enum as flags. In most cases enum is either used as flags or as values.
138                  Sometimes, however, both forms are necessary, in which case header contains the enum
139                  form while specific attributes may request to convert the values into a bitfield.
140                type: boolean
141              display-hint: &display-hint
142                description: |
143                  Optional format indicator that is intended only for choosing
144                  the right formatting mechanism when displaying values of this
145                  type.
146                enum: [ hex, mac, fddi, ipv4, ipv6, uuid ]
147        # End genetlink-legacy
148
149  attribute-sets:
150    description: Definition of attribute spaces for this family.
151    type: array
152    items:
153      description: Definition of a single attribute space.
154      type: object
155      required: [ name, attributes ]
156      additionalProperties: False
157      properties:
158        name:
159          description: |
160            Name used when referring to this space in other definitions, not used outside of the spec.
161          type: string
162        name-prefix:
163          description: |
164            Prefix for the C enum name of the attributes. Default family[name]-set[name]-a-
165          type: string
166        enum-name:
167          description: Name for the enum type of the attribute.
168          type: string
169        doc:
170          description: Documentation of the space.
171          type: string
172        subset-of:
173          description: |
174            Name of another space which this is a logical part of. Sub-spaces can be used to define
175            a limited group of attributes which are used in a nest.
176          type: string
177        # Start genetlink-c
178        attr-cnt-name:
179          description: The explicit name for constant holding the count of attributes (last attr + 1).
180          type: string
181        attr-max-name:
182          description: The explicit name for last member of attribute enum.
183          type: string
184        # End genetlink-c
185        attributes:
186          description: List of attributes in the space.
187          type: array
188          items:
189            type: object
190            required: [ name ]
191            additionalProperties: False
192            properties:
193              name:
194                type: string
195              type: &attr-type
196                description: The netlink attribute type
197                enum: [ unused, pad, flag, binary, u8, u16, u32, u64, s32, s64,
198                        string, nest, array-nest, nest-type-value ]
199              doc:
200                description: Documentation of the attribute.
201                type: string
202              value:
203                description: Value for the enum item representing this attribute in the uAPI.
204                $ref: '#/$defs/uint'
205              type-value:
206                description: Name of the value extracted from the type of a nest-type-value attribute.
207                type: array
208                items:
209                  type: string
210              byte-order:
211                enum: [ little-endian, big-endian ]
212              multi-attr:
213                type: boolean
214              nested-attributes:
215                description: Name of the space (sub-space) used inside the attribute.
216                type: string
217              enum:
218                description: Name of the enum type used for the attribute.
219                type: string
220              enum-as-flags:
221                description: |
222                  Treat the enum as flags. In most cases enum is either used as flags or as values.
223                  Sometimes, however, both forms are necessary, in which case header contains the enum
224                  form while specific attributes may request to convert the values into a bitfield.
225                type: boolean
226              checks:
227                description: Kernel input validation.
228                type: object
229                additionalProperties: False
230                properties:
231                  flags-mask:
232                    description: Name of the flags constant on which to base mask (unsigned scalar types only).
233                    type: string
234                  min:
235                    description: Min value for an integer attribute.
236                    type: integer
237                  min-len:
238                    description: Min length for a binary attribute.
239                    $ref: '#/$defs/len-or-define'
240                  max-len:
241                    description: Max length for a string or a binary attribute.
242                    $ref: '#/$defs/len-or-define'
243              sub-type: *attr-type
244              display-hint: *display-hint
245              # Start genetlink-c
246              name-prefix:
247                type: string
248              # End genetlink-c
249              # Start genetlink-legacy
250              struct:
251                description: Name of the struct type used for the attribute.
252                type: string
253              # End genetlink-legacy
254
255      # Make sure name-prefix does not appear in subsets (subsets inherit naming)
256      dependencies:
257        name-prefix:
258          not:
259            required: [ subset-of ]
260        subset-of:
261          not:
262            required: [ name-prefix ]
263
264      # type property is only required if not in subset definition
265      if:
266        properties:
267          subset-of:
268            not:
269              type: string
270      then:
271        properties:
272          attributes:
273            items:
274              required: [ type ]
275
276  operations:
277    description: Operations supported by the protocol.
278    type: object
279    required: [ list ]
280    additionalProperties: False
281    properties:
282      enum-model:
283        description: |
284          The model of assigning values to the operations.
285          "unified" is the recommended model where all message types belong
286          to a single enum.
287          "directional" has the messages sent to the kernel and from the kernel
288          enumerated separately.
289        enum: [ unified, directional ] # Trim
290      name-prefix:
291        description: |
292          Prefix for the C enum name of the command. The name is formed by concatenating
293          the prefix with the upper case name of the command, with dashes replaced by underscores.
294        type: string
295      enum-name:
296        description: Name for the enum type with commands.
297        type: string
298      async-prefix:
299        description: Same as name-prefix but used to render notifications and events to separate enum.
300        type: string
301      async-enum:
302        description: Name for the enum type with notifications/events.
303        type: string
304      # Start genetlink-legacy
305      fixed-header: &fixed-header
306        description: |
307          Name of the structure defining the optional fixed-length protocol
308          header. This header is placed in a message after the netlink and
309          genetlink headers and before any attributes.
310        type: string
311      # End genetlink-legacy
312      list:
313        description: List of commands
314        type: array
315        items:
316          type: object
317          additionalProperties: False
318          required: [ name, doc ]
319          properties:
320            name:
321              description: Name of the operation, also defining its C enum value in uAPI.
322              type: string
323            doc:
324              description: Documentation for the command.
325              type: string
326            value:
327              description: Value for the enum in the uAPI.
328              $ref: '#/$defs/uint'
329            attribute-set:
330              description: |
331                Attribute space from which attributes directly in the requests and replies
332                to this command are defined.
333              type: string
334            flags: &cmd_flags
335              description: Command flags.
336              type: array
337              items:
338                enum: [ admin-perm ]
339            dont-validate:
340              description: Kernel attribute validation flags.
341              type: array
342              items:
343                enum: [ strict, dump ]
344            # Start genetlink-legacy
345            fixed-header: *fixed-header
346            # End genetlink-legacy
347            do: &subop-type
348              description: Main command handler.
349              type: object
350              additionalProperties: False
351              properties:
352                request: &subop-attr-list
353                  description: Definition of the request message for a given command.
354                  type: object
355                  additionalProperties: False
356                  properties:
357                    attributes:
358                      description: |
359                        Names of attributes from the attribute-set (not full attribute
360                        definitions, just names).
361                      type: array
362                      items:
363                        type: string
364                    # Start genetlink-legacy
365                    value:
366                      description: |
367                        ID of this message if value for request and response differ,
368                        i.e. requests and responses have different message enums.
369                      $ref: '#/$defs/uint'
370                    # End genetlink-legacy
371                reply: *subop-attr-list
372                pre:
373                  description: Hook for a function to run before the main callback (pre_doit or start).
374                  type: string
375                post:
376                  description: Hook for a function to run after the main callback (post_doit or done).
377                  type: string
378            dump: *subop-type
379            notify:
380              description: Name of the command sharing the reply type with this notification.
381              type: string
382            event:
383              type: object
384              additionalProperties: False
385              properties:
386                attributes:
387                  description: Explicit list of the attributes for the notification.
388                  type: array
389                  items:
390                    type: string
391            mcgrp:
392              description: Name of the multicast group generating given notification.
393              type: string
394  mcast-groups:
395    description: List of multicast groups.
396    type: object
397    required: [ list ]
398    additionalProperties: False
399    properties:
400      list:
401        description: List of groups.
402        type: array
403        items:
404          type: object
405          required: [ name ]
406          additionalProperties: False
407          properties:
408            name:
409              description: |
410                The name for the group, used to form the define and the value of the define.
411              type: string
412            # Start genetlink-c
413            c-define-name:
414              description: Override for the name of the define in C uAPI.
415              type: string
416            # End genetlink-c
417            flags: *cmd_flags
418            # Start netlink-raw
419            value:
420              description: Value of the netlink multicast group in the uAPI.
421              type: integer
422            # End netlink-raw
423