netlink-raw.rst 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. .. SPDX-License-Identifier: BSD-3-Clause
  2. ======================================================
  3. Netlink specification support for raw Netlink families
  4. ======================================================
  5. This document describes the additional properties required by raw Netlink
  6. families such as ``NETLINK_ROUTE`` which use the ``netlink-raw`` protocol
  7. specification.
  8. Specification
  9. =============
  10. The netlink-raw schema extends the :doc:`genetlink-legacy <genetlink-legacy>`
  11. schema with properties that are needed to specify the protocol numbers and
  12. multicast IDs used by raw netlink families. See :ref:`classic_netlink` for more
  13. information. The raw netlink families also make use of type-specific
  14. sub-messages.
  15. Globals
  16. -------
  17. protonum
  18. ~~~~~~~~
  19. The ``protonum`` property is used to specify the protocol number to use when
  20. opening a netlink socket.
  21. .. code-block:: yaml
  22. # SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
  23. name: rt-addr
  24. protocol: netlink-raw
  25. protonum: 0 # part of the NETLINK_ROUTE protocol
  26. Multicast group properties
  27. --------------------------
  28. value
  29. ~~~~~
  30. The ``value`` property is used to specify the group ID to use for multicast
  31. group registration.
  32. .. code-block:: yaml
  33. mcast-groups:
  34. list:
  35. -
  36. name: rtnlgrp-ipv4-ifaddr
  37. value: 5
  38. -
  39. name: rtnlgrp-ipv6-ifaddr
  40. value: 9
  41. -
  42. name: rtnlgrp-mctp-ifaddr
  43. value: 34
  44. Sub-messages
  45. ------------
  46. Several raw netlink families such as
  47. :ref:`rt-link<netlink-rt-link>` and
  48. :ref:`tc<netlink-tc>` use attribute nesting as an
  49. abstraction to carry module specific information.
  50. Conceptually it looks as follows::
  51. [OUTER NEST OR MESSAGE LEVEL]
  52. [GENERIC ATTR 1]
  53. [GENERIC ATTR 2]
  54. [GENERIC ATTR 3]
  55. [GENERIC ATTR - wrapper]
  56. [MODULE SPECIFIC ATTR 1]
  57. [MODULE SPECIFIC ATTR 2]
  58. The ``GENERIC ATTRs`` at the outer level are defined in the core (or rt_link or
  59. core TC), while specific drivers, TC classifiers, qdiscs etc. can carry their
  60. own information wrapped in the ``GENERIC ATTR - wrapper``. Even though the
  61. example above shows attributes nesting inside the wrapper, the modules generally
  62. have full freedom to define the format of the nest. In practice the payload of
  63. the wrapper attr has very similar characteristics to a netlink message. It may
  64. contain a fixed header / structure, netlink attributes, or both. Because of
  65. those shared characteristics we refer to the payload of the wrapper attribute as
  66. a sub-message.
  67. A sub-message attribute uses the value of another attribute as a selector key to
  68. choose the right sub-message format. For example if the following attribute has
  69. already been decoded:
  70. .. code-block:: json
  71. { "kind": "gre" }
  72. and we encounter the following attribute spec:
  73. .. code-block:: yaml
  74. -
  75. name: data
  76. type: sub-message
  77. sub-message: linkinfo-data-msg
  78. selector: kind
  79. Then we look for a sub-message definition called ``linkinfo-data-msg`` and use
  80. the value of the ``kind`` attribute i.e. ``gre`` as the key to choose the
  81. correct format for the sub-message:
  82. .. code-block:: yaml
  83. sub-messages:
  84. name: linkinfo-data-msg
  85. formats:
  86. -
  87. value: bridge
  88. attribute-set: linkinfo-bridge-attrs
  89. -
  90. value: gre
  91. attribute-set: linkinfo-gre-attrs
  92. -
  93. value: geneve
  94. attribute-set: linkinfo-geneve-attrs
  95. This would decode the attribute value as a sub-message with the attribute-set
  96. called ``linkinfo-gre-attrs`` as the attribute space.
  97. A sub-message can have an optional ``fixed-header`` followed by zero or more
  98. attributes from an ``attribute-set``. For example the following
  99. ``tc-options-msg`` sub-message defines message formats that use a mixture of
  100. ``fixed-header``, ``attribute-set`` or both together:
  101. .. code-block:: yaml
  102. sub-messages:
  103. -
  104. name: tc-options-msg
  105. formats:
  106. -
  107. value: bfifo
  108. fixed-header: tc-fifo-qopt
  109. -
  110. value: cake
  111. attribute-set: tc-cake-attrs
  112. -
  113. value: netem
  114. fixed-header: tc-netem-qopt
  115. attribute-set: tc-netem-attrs
  116. Note that a selector attribute must appear in a netlink message before any
  117. sub-message attributes that depend on it.
  118. If an attribute such as ``kind`` is defined at more than one nest level, then a
  119. sub-message selector will be resolved using the value 'closest' to the selector.
  120. For example, if the same attribute name is defined in a nested ``attribute-set``
  121. alongside a sub-message selector and also in a top level ``attribute-set``, then
  122. the selector will be resolved using the value 'closest' to the selector. If the
  123. value is not present in the message at the same level as defined in the spec
  124. then this is an error.
  125. Nested struct definitions
  126. -------------------------
  127. Many raw netlink families such as :ref:`tc<netlink-tc>`
  128. make use of nested struct definitions. The ``netlink-raw`` schema makes it
  129. possible to embed a struct within a struct definition using the ``struct``
  130. property. For example, the following struct definition embeds the
  131. ``tc-ratespec`` struct definition for both the ``rate`` and the ``peakrate``
  132. members of ``struct tc-tbf-qopt``.
  133. .. code-block:: yaml
  134. -
  135. name: tc-tbf-qopt
  136. type: struct
  137. members:
  138. -
  139. name: rate
  140. type: binary
  141. struct: tc-ratespec
  142. -
  143. name: peakrate
  144. type: binary
  145. struct: tc-ratespec
  146. -
  147. name: limit
  148. type: u32
  149. -
  150. name: buffer
  151. type: u32
  152. -
  153. name: mtu
  154. type: u32