xref: /linux/Documentation/netlink/netlink-raw.yaml (revision ea23fbd2a8f7dadfa9cd9b9d73f3b8a69eec0671)
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                  exact-len:
244                    description: Exact length for a string or a binary attribute.
245                    $ref: '#/$defs/len-or-define'
246              sub-type: *attr-type
247              display-hint: *display-hint
248              # Start genetlink-c
249              name-prefix:
250                type: string
251              # End genetlink-c
252              # Start genetlink-legacy
253              struct:
254                description: Name of the struct type used for the attribute.
255                type: string
256              # End genetlink-legacy
257
258      # Make sure name-prefix does not appear in subsets (subsets inherit naming)
259      dependencies:
260        name-prefix:
261          not:
262            required: [ subset-of ]
263        subset-of:
264          not:
265            required: [ name-prefix ]
266
267      # type property is only required if not in subset definition
268      if:
269        properties:
270          subset-of:
271            not:
272              type: string
273      then:
274        properties:
275          attributes:
276            items:
277              required: [ type ]
278
279  operations:
280    description: Operations supported by the protocol.
281    type: object
282    required: [ list ]
283    additionalProperties: False
284    properties:
285      enum-model:
286        description: |
287          The model of assigning values to the operations.
288          "unified" is the recommended model where all message types belong
289          to a single enum.
290          "directional" has the messages sent to the kernel and from the kernel
291          enumerated separately.
292        enum: [ unified, directional ] # Trim
293      name-prefix:
294        description: |
295          Prefix for the C enum name of the command. The name is formed by concatenating
296          the prefix with the upper case name of the command, with dashes replaced by underscores.
297        type: string
298      enum-name:
299        description: Name for the enum type with commands.
300        type: string
301      async-prefix:
302        description: Same as name-prefix but used to render notifications and events to separate enum.
303        type: string
304      async-enum:
305        description: Name for the enum type with notifications/events.
306        type: string
307      # Start genetlink-legacy
308      fixed-header: &fixed-header
309        description: |
310          Name of the structure defining the optional fixed-length protocol
311          header. This header is placed in a message after the netlink and
312          genetlink headers and before any attributes.
313        type: string
314      # End genetlink-legacy
315      list:
316        description: List of commands
317        type: array
318        items:
319          type: object
320          additionalProperties: False
321          required: [ name, doc ]
322          properties:
323            name:
324              description: Name of the operation, also defining its C enum value in uAPI.
325              type: string
326            doc:
327              description: Documentation for the command.
328              type: string
329            value:
330              description: Value for the enum in the uAPI.
331              $ref: '#/$defs/uint'
332            attribute-set:
333              description: |
334                Attribute space from which attributes directly in the requests and replies
335                to this command are defined.
336              type: string
337            flags: &cmd_flags
338              description: Command flags.
339              type: array
340              items:
341                enum: [ admin-perm ]
342            dont-validate:
343              description: Kernel attribute validation flags.
344              type: array
345              items:
346                enum: [ strict, dump ]
347            # Start genetlink-legacy
348            fixed-header: *fixed-header
349            # End genetlink-legacy
350            do: &subop-type
351              description: Main command handler.
352              type: object
353              additionalProperties: False
354              properties:
355                request: &subop-attr-list
356                  description: Definition of the request message for a given command.
357                  type: object
358                  additionalProperties: False
359                  properties:
360                    attributes:
361                      description: |
362                        Names of attributes from the attribute-set (not full attribute
363                        definitions, just names).
364                      type: array
365                      items:
366                        type: string
367                    # Start genetlink-legacy
368                    value:
369                      description: |
370                        ID of this message if value for request and response differ,
371                        i.e. requests and responses have different message enums.
372                      $ref: '#/$defs/uint'
373                    # End genetlink-legacy
374                reply: *subop-attr-list
375                pre:
376                  description: Hook for a function to run before the main callback (pre_doit or start).
377                  type: string
378                post:
379                  description: Hook for a function to run after the main callback (post_doit or done).
380                  type: string
381            dump: *subop-type
382            notify:
383              description: Name of the command sharing the reply type with this notification.
384              type: string
385            event:
386              type: object
387              additionalProperties: False
388              properties:
389                attributes:
390                  description: Explicit list of the attributes for the notification.
391                  type: array
392                  items:
393                    type: string
394            mcgrp:
395              description: Name of the multicast group generating given notification.
396              type: string
397  mcast-groups:
398    description: List of multicast groups.
399    type: object
400    required: [ list ]
401    additionalProperties: False
402    properties:
403      list:
404        description: List of groups.
405        type: array
406        items:
407          type: object
408          required: [ name ]
409          additionalProperties: False
410          properties:
411            name:
412              description: |
413                The name for the group, used to form the define and the value of the define.
414              type: string
415            # Start genetlink-c
416            c-define-name:
417              description: Override for the name of the define in C uAPI.
418              type: string
419            # End genetlink-c
420            flags: *cmd_flags
421            # Start netlink-raw
422            value:
423              description: Value of the netlink multicast group in the uAPI.
424              type: integer
425            # End netlink-raw
426