]> Git Repo - linux.git/blob - Documentation/userspace-api/netlink/specs.rst
sfc: support TC decap rules matching on enc_src_port
[linux.git] / Documentation / userspace-api / netlink / specs.rst
1 .. SPDX-License-Identifier: BSD-3-Clause
2
3 =========================================
4 Netlink protocol specifications (in YAML)
5 =========================================
6
7 Netlink protocol specifications are complete, machine readable descriptions of
8 Netlink protocols written in YAML. The goal of the specifications is to allow
9 separating Netlink parsing from user space logic and minimize the amount of
10 hand written Netlink code for each new family, command, attribute.
11 Netlink specs should be complete and not depend on any other spec
12 or C header file, making it easy to use in languages which can't include
13 kernel headers directly.
14
15 Internally kernel uses the YAML specs to generate:
16
17  - the C uAPI header
18  - documentation of the protocol as a ReST file
19  - policy tables for input attribute validation
20  - operation tables
21
22 YAML specifications can be found under ``Documentation/netlink/specs/``
23
24 This document describes details of the schema.
25 See :doc:`intro-specs` for a practical starting guide.
26
27 All specs must be licensed under
28 ``((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)``
29 to allow for easy adoption in user space code.
30
31 Compatibility levels
32 ====================
33
34 There are four schema levels for Netlink specs, from the simplest used
35 by new families to the most complex covering all the quirks of the old ones.
36 Each next level inherits the attributes of the previous level, meaning that
37 user capable of parsing more complex ``genetlink`` schemas is also compatible
38 with simpler ones. The levels are:
39
40  - ``genetlink`` - most streamlined, should be used by all new families
41  - ``genetlink-c`` - superset of ``genetlink`` with extra attributes allowing
42    customization of define and enum type and value names; this schema should
43    be equivalent to ``genetlink`` for all implementations which don't interact
44    directly with C uAPI headers
45  - ``genetlink-legacy`` - Generic Netlink catch all schema supporting quirks of
46    all old genetlink families, strange attribute formats, binary structures etc.
47  - ``netlink-raw`` - catch all schema supporting pre-Generic Netlink protocols
48    such as ``NETLINK_ROUTE``
49
50 The definition of the schemas (in ``jsonschema``) can be found
51 under ``Documentation/netlink/``.
52
53 Schema structure
54 ================
55
56 YAML schema has the following conceptual sections:
57
58  - globals
59  - definitions
60  - attributes
61  - operations
62  - multicast groups
63
64 Most properties in the schema accept (or in fact require) a ``doc``
65 sub-property documenting the defined object.
66
67 The following sections describe the properties of the most modern ``genetlink``
68 schema. See the documentation of :doc:`genetlink-c <c-code-gen>`
69 for information on how C names are derived from name properties.
70
71 genetlink
72 =========
73
74 Globals
75 -------
76
77 Attributes listed directly at the root level of the spec file.
78
79 name
80 ~~~~
81
82 Name of the family. Name identifies the family in a unique way, since
83 the Family IDs are allocated dynamically.
84
85 version
86 ~~~~~~~
87
88 Generic Netlink family version, default is 1.
89
90 protocol
91 ~~~~~~~~
92
93 The schema level, default is ``genetlink``, which is the only value
94 allowed for new ``genetlink`` families.
95
96 definitions
97 -----------
98
99 Array of type and constant definitions.
100
101 name
102 ~~~~
103
104 Name of the type / constant.
105
106 type
107 ~~~~
108
109 One of the following types:
110
111  - const - a single, standalone constant
112  - enum - defines an integer enumeration, with values for each entry
113    incrementing by 1, (e.g. 0, 1, 2, 3)
114  - flags - defines an integer enumeration, with values for each entry
115    occupying a bit, starting from bit 0, (e.g. 1, 2, 4, 8)
116
117 value
118 ~~~~~
119
120 The value for the ``const``.
121
122 value-start
123 ~~~~~~~~~~~
124
125 The first value for ``enum`` and ``flags``, allows overriding the default
126 start value of ``0`` (for ``enum``) and starting bit (for ``flags``).
127 For ``flags`` ``value-start`` selects the starting bit, not the shifted value.
128
129 Sparse enumerations are not supported.
130
131 entries
132 ~~~~~~~
133
134 Array of names of the entries for ``enum`` and ``flags``.
135
136 header
137 ~~~~~~
138
139 For C-compatible languages, header which already defines this value.
140 In case the definition is shared by multiple families (e.g. ``IFNAMSIZ``)
141 code generators for C-compatible languages may prefer to add an appropriate
142 include instead of rendering a new definition.
143
144 attribute-sets
145 --------------
146
147 This property contains information about netlink attributes of the family.
148 All families have at least one attribute set, most have multiple.
149 ``attribute-sets`` is an array, with each entry describing a single set.
150
151 Note that the spec is "flattened" and is not meant to visually resemble
152 the format of the netlink messages (unlike certain ad-hoc documentation
153 formats seen in kernel comments). In the spec subordinate attribute sets
154 are not defined inline as a nest, but defined in a separate attribute set
155 referred to with a ``nested-attributes`` property of the container.
156
157 Spec may also contain fractional sets - sets which contain a ``subset-of``
158 property. Such sets describe a section of a full set, allowing narrowing down
159 which attributes are allowed in a nest or refining the validation criteria.
160 Fractional sets can only be used in nests. They are not rendered to the uAPI
161 in any fashion.
162
163 name
164 ~~~~
165
166 Uniquely identifies the attribute set, operations and nested attributes
167 refer to the sets by the ``name``.
168
169 subset-of
170 ~~~~~~~~~
171
172 Re-defines a portion of another set (a fractional set).
173 Allows narrowing down fields and changing validation criteria
174 or even types of attributes depending on the nest in which they
175 are contained. The ``value`` of each attribute in the fractional
176 set is implicitly the same as in the main set.
177
178 attributes
179 ~~~~~~~~~~
180
181 List of attributes in the set.
182
183 Attribute properties
184 --------------------
185
186 name
187 ~~~~
188
189 Identifies the attribute, unique within the set.
190
191 type
192 ~~~~
193
194 Netlink attribute type, see :ref:`attr_types`.
195
196 .. _assign_val:
197
198 value
199 ~~~~~
200
201 Numerical attribute ID, used in serialized Netlink messages.
202 The ``value`` property can be skipped, in which case the attribute ID
203 will be the value of the previous attribute plus one (recursively)
204 and ``1`` for the first attribute in the attribute set.
205
206 Attributes (and operations) use ``1`` as the default value for the first
207 entry (unlike enums in definitions which start from ``0``) because
208 entry ``0`` is almost always reserved as undefined. Spec can explicitly
209 set value to ``0`` if needed.
210
211 Note that the ``value`` of an attribute is defined only in its main set
212 (not in subsets).
213
214 enum
215 ~~~~
216
217 For integer types specifies that values in the attribute belong
218 to an ``enum`` or ``flags`` from the ``definitions`` section.
219
220 enum-as-flags
221 ~~~~~~~~~~~~~
222
223 Treat ``enum`` as ``flags`` regardless of its type in ``definitions``.
224 When both ``enum`` and ``flags`` forms are needed ``definitions`` should
225 contain an ``enum`` and attributes which need the ``flags`` form should
226 use this attribute.
227
228 nested-attributes
229 ~~~~~~~~~~~~~~~~~
230
231 Identifies the attribute space for attributes nested within given attribute.
232 Only valid for complex attributes which may have sub-attributes.
233
234 multi-attr (arrays)
235 ~~~~~~~~~~~~~~~~~~~
236
237 Boolean property signifying that the attribute may be present multiple times.
238 Allowing an attribute to repeat is the recommended way of implementing arrays
239 (no extra nesting).
240
241 byte-order
242 ~~~~~~~~~~
243
244 For integer types specifies attribute byte order - ``little-endian``
245 or ``big-endian``.
246
247 checks
248 ~~~~~~
249
250 Input validation constraints used by the kernel. User space should query
251 the policy of the running kernel using Generic Netlink introspection,
252 rather than depend on what is specified in the spec file.
253
254 The validation policy in the kernel is formed by combining the type
255 definition (``type`` and ``nested-attributes``) and the ``checks``.
256
257 sub-type
258 ~~~~~~~~
259
260 Legacy families have special ways of expressing arrays. ``sub-type`` can be
261 used to define the type of array members in case array members are not
262 fully defined as attributes (in a bona fide attribute space). For instance
263 a C array of u32 values can be specified with ``type: binary`` and
264 ``sub-type: u32``. Binary types and legacy array formats are described in
265 more detail in :doc:`genetlink-legacy`.
266
267 operations
268 ----------
269
270 This section describes messages passed between the kernel and the user space.
271 There are three types of entries in this section - operations, notifications
272 and events.
273
274 Operations describe the most common request - response communication. User
275 sends a request and kernel replies. Each operation may contain any combination
276 of the two modes familiar to netlink users - ``do`` and ``dump``.
277 ``do`` and ``dump`` in turn contain a combination of ``request`` and
278 ``response`` properties. If no explicit message with attributes is passed
279 in a given direction (e.g. a ``dump`` which does not accept filter, or a ``do``
280 of a SET operation to which the kernel responds with just the netlink error
281 code) ``request`` or ``response`` section can be skipped.
282 ``request`` and ``response`` sections list the attributes allowed in a message.
283 The list contains only the names of attributes from a set referred
284 to by the ``attribute-set`` property.
285
286 Notifications and events both refer to the asynchronous messages sent by
287 the kernel to members of a multicast group. The difference between the
288 two is that a notification shares its contents with a GET operation
289 (the name of the GET operation is specified in the ``notify`` property).
290 This arrangement is commonly used for notifications about
291 objects where the notification carries the full object definition.
292
293 Events are more focused and carry only a subset of information rather than full
294 object state (a made up example would be a link state change event with just
295 the interface name and the new link state). Events contain the ``event``
296 property. Events are considered less idiomatic for netlink and notifications
297 should be preferred.
298
299 list
300 ~~~~
301
302 The only property of ``operations`` for ``genetlink``, holds the list of
303 operations, notifications etc.
304
305 Operation properties
306 --------------------
307
308 name
309 ~~~~
310
311 Identifies the operation.
312
313 value
314 ~~~~~
315
316 Numerical message ID, used in serialized Netlink messages.
317 The same enumeration rules are applied as to
318 :ref:`attribute values<assign_val>`.
319
320 attribute-set
321 ~~~~~~~~~~~~~
322
323 Specifies the attribute set contained within the message.
324
325 do
326 ~~~
327
328 Specification for the ``doit`` request. Should contain ``request``, ``reply``
329 or both of these properties, each holding a :ref:`attr_list`.
330
331 dump
332 ~~~~
333
334 Specification for the ``dumpit`` request. Should contain ``request``, ``reply``
335 or both of these properties, each holding a :ref:`attr_list`.
336
337 notify
338 ~~~~~~
339
340 Designates the message as a notification. Contains the name of the operation
341 (possibly the same as the operation holding this property) which shares
342 the contents with the notification (``do``).
343
344 event
345 ~~~~~
346
347 Specification of attributes in the event, holds a :ref:`attr_list`.
348 ``event`` property is mutually exclusive with ``notify``.
349
350 mcgrp
351 ~~~~~
352
353 Used with ``event`` and ``notify``, specifies which multicast group
354 message belongs to.
355
356 .. _attr_list:
357
358 Message attribute list
359 ----------------------
360
361 ``request``, ``reply`` and ``event`` properties have a single ``attributes``
362 property which holds the list of attribute names.
363
364 Messages can also define ``pre`` and ``post`` properties which will be rendered
365 as ``pre_doit`` and ``post_doit`` calls in the kernel (these properties should
366 be ignored by user space).
367
368 mcast-groups
369 ------------
370
371 This section lists the multicast groups of the family.
372
373 list
374 ~~~~
375
376 The only property of ``mcast-groups`` for ``genetlink``, holds the list
377 of groups.
378
379 Multicast group properties
380 --------------------------
381
382 name
383 ~~~~
384
385 Uniquely identifies the multicast group in the family. Similarly to
386 Family ID, Multicast Group ID needs to be resolved at runtime, based
387 on the name.
388
389 .. _attr_types:
390
391 Attribute types
392 ===============
393
394 This section describes the attribute types supported by the ``genetlink``
395 compatibility level. Refer to documentation of different levels for additional
396 attribute types.
397
398 Scalar integer types
399 --------------------
400
401 Fixed-width integer types:
402 ``u8``, ``u16``, ``u32``, ``u64``, ``s8``, ``s16``, ``s32``, ``s64``.
403
404 Note that types smaller than 32 bit should be avoided as using them
405 does not save any memory in Netlink messages (due to alignment).
406 See :ref:`pad_type` for padding of 64 bit attributes.
407
408 The payload of the attribute is the integer in host order unless ``byte-order``
409 specifies otherwise.
410
411 .. _pad_type:
412
413 pad
414 ---
415
416 Special attribute type used for padding attributes which require alignment
417 bigger than standard 4B alignment required by netlink (e.g. 64 bit integers).
418 There can only be a single attribute of the ``pad`` type in any attribute set
419 and it should be automatically used for padding when needed.
420
421 flag
422 ----
423
424 Attribute with no payload, its presence is the entire information.
425
426 binary
427 ------
428
429 Raw binary data attribute, the contents are opaque to generic code.
430
431 string
432 ------
433
434 Character string. Unless ``checks`` has ``unterminated-ok`` set to ``true``
435 the string is required to be null terminated.
436 ``max-len`` in ``checks`` indicates the longest possible string,
437 if not present the length of the string is unbounded.
438
439 Note that ``max-len`` does not count the terminating character.
440
441 nest
442 ----
443
444 Attribute containing other (nested) attributes.
445 ``nested-attributes`` specifies which attribute set is used inside.
This page took 0.056244 seconds and 4 git commands to generate.