← Documents Documentation/userspace-api/netlink/netlink-raw.rst GitHub 원문 ↗

Linux 6.18.37 · 사용자 공간 API

raw Netlink family 명세 지원

raw Netlink family의 protocol 번호, 정적 multicast ID, selector 기반 sub-message와 중첩 구조체 명세를 설명합니다.

Source pathDocumentation/userspace-api/netlink/netlink-raw.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

netlink-raw.rst:1-194

sub-message는 wrapper payload를 selector 값에 따라 서로 다른 schema로 해석하는 기존 ABI 모델입니다. selector가 wire에서 먼저 나타나고 같은 nest 수준에 존재해야 한다는 순서·scope 조건을 parser가 반드시 검증해야 합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

netlink-raw compatibility level

1-19

이 문서는 `NETLINK_ROUTE`처럼 `netlink-raw` protocol specification을 사용하는 raw Netlink family에 필요한 추가 속성을 설명합니다.

`netlink-raw` schema는 `genetlink-legacy` schema를 확장하여 raw family의 protocol 번호와 multicast ID를 표현합니다. 또한 raw family가 사용하는 type별 sub-message 형식을 추가로 지원합니다.

netlink-raw 확장 범위
기반추가 기능
`genetlink-legacy`레거시 구조체, 배열, 방향별 ID 등 상속
protocol numbersocket을 열 때 사용할 raw Netlink protocol 번호
multicast ID정적으로 정의된 group 등록 값
sub-messageselector에 따라 달라지는 wrapper payload 형식

Generic Netlink 이전 ABI를 완전하게 기술하기 위한 추가 정보입니다.

.. SPDX-License-Identifier: BSD-3-Clause

======================================================
Netlink specification support for raw Netlink families
======================================================

This document describes the additional properties required by raw Netlink
families such as ``NETLINK_ROUTE`` which use the ``netlink-raw`` protocol
specification.

Specification
=============

The netlink-raw schema extends the :doc:`genetlink-legacy <genetlink-legacy>`
schema with properties that are needed to specify the protocol numbers and
multicast IDs used by raw netlink families. See :ref:`classic_netlink` for more
information. The raw netlink families also make use of type-specific
sub-messages.

protonum과 multicast group value

20-60

전역 `protonum`은 Netlink socket을 열 때 사용할 protocol 번호입니다. 예제 `rt-addr` 명세는 `protocol: netlink-raw`와 `protonum: 0`을 지정하여 `NETLINK_ROUTE` protocol의 일부임을 나타냅니다.

multicast group의 `value`는 group 등록에 사용할 ID를 명시합니다. Generic Netlink의 동적 group ID와 달리 raw family 명세에는 실제 숫자가 들어갑니다.

예제 multicast group
namevalue
`rtnlgrp-ipv4-ifaddr`5
`rtnlgrp-ipv6-ifaddr`9
`rtnlgrp-mctp-ifaddr`34

RTNL 주소 notification group의 정적 ID입니다.

Globals
-------

protonum
~~~~~~~~

The ``protonum`` property is used to specify the protocol number to use when
opening a netlink socket.

.. code-block:: yaml

  # SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)

  name: rt-addr
  protocol: netlink-raw
  protonum: 0             # part of the NETLINK_ROUTE protocol


Multicast group properties
--------------------------

value
~~~~~

The ``value`` property is used to specify the group ID to use for multicast
group registration.

.. code-block:: yaml

  mcast-groups:
    list:
      -
        name: rtnlgrp-ipv4-ifaddr
        value: 5
      -
        name: rtnlgrp-ipv6-ifaddr
        value: 9
      -
        name: rtnlgrp-mctp-ifaddr
        value: 34

wrapper attribute와 sub-message selector

61-128

`rt-link`와 traffic control 같은 raw family는 module별 정보를 운반하기 위해 attribute nesting을 추상화로 사용합니다. 바깥 message나 nest에는 core가 정의한 일반 attribute가 있고, wrapper attribute 안에는 driver, classifier, qdisc 등이 정의한 module별 payload가 들어갑니다.

module은 wrapper 내부 형식을 자유롭게 정할 수 있습니다. 고정 header나 Netlink attribute 또는 둘 모두를 포함할 수 있어 일반 Netlink message와 성질이 비슷하므로 이 wrapper payload를 sub-message라고 부릅니다.

sub-message 형식 선택
일반 attribute `kind`를 먼저 decode`data` attribute의 `type: sub-message` 확인`sub-message: linkinfo-data-msg` 정의 찾기`selector: kind` 값 `gre`를 format key로 사용`value: gre` 항목의 `linkinfo-gre-attrs`로 payload decode

먼저 해석한 selector attribute 값으로 payload schema를 고릅니다.

linkinfo-data-msg format
selector valueattribute-set
`bridge``linkinfo-bridge-attrs`
`gre``linkinfo-gre-attrs`
`geneve``linkinfo-geneve-attrs`

kind 값에 따라 독립 attribute space를 선택합니다.

Sub-messages
------------

Several raw netlink families such as
:ref:`rt-link<netlink-rt-link>` and
:ref:`tc<netlink-tc>` use attribute nesting as an
abstraction to carry module specific information.

Conceptually it looks as follows::

    [OUTER NEST OR MESSAGE LEVEL]
      [GENERIC ATTR 1]
      [GENERIC ATTR 2]
      [GENERIC ATTR 3]
      [GENERIC ATTR - wrapper]
        [MODULE SPECIFIC ATTR 1]
        [MODULE SPECIFIC ATTR 2]

The ``GENERIC ATTRs`` at the outer level are defined in the core (or rt_link or
core TC), while specific drivers, TC classifiers, qdiscs etc. can carry their
own information wrapped in the ``GENERIC ATTR - wrapper``. Even though the
example above shows attributes nesting inside the wrapper, the modules generally
have full freedom to define the format of the nest. In practice the payload of
the wrapper attr has very similar characteristics to a netlink message. It may
contain a fixed header / structure, netlink attributes, or both. Because of
those shared characteristics we refer to the payload of the wrapper attribute as
a sub-message.

A sub-message attribute uses the value of another attribute as a selector key to
choose the right sub-message format. For example if the following attribute has
already been decoded:

.. code-block:: json

  { "kind": "gre" }

and we encounter the following attribute spec:

.. code-block:: yaml

  -
    name: data
    type: sub-message
    sub-message: linkinfo-data-msg
    selector: kind

Then we look for a sub-message definition called ``linkinfo-data-msg`` and use
the value of the ``kind`` attribute i.e. ``gre`` as the key to choose the
correct format for the sub-message:

.. code-block:: yaml

  sub-messages:
    name: linkinfo-data-msg
    formats:
      -
        value: bridge
        attribute-set: linkinfo-bridge-attrs
      -
        value: gre
        attribute-set: linkinfo-gre-attrs
      -
        value: geneve
        attribute-set: linkinfo-geneve-attrs

This would decode the attribute value as a sub-message with the attribute-set
called ``linkinfo-gre-attrs`` as the attribute space.

fixed-header 조합과 selector scope

129-161

sub-message는 선택적인 `fixed-header` 뒤에 `attribute-set`의 attribute 0개 이상을 둘 수 있습니다. `tc-options-msg` 예제의 `bfifo`는 고정 header만, `cake`는 attribute set만, `netem`은 둘 모두를 사용합니다.

tc-options-msg 조합
valuefixed-headerattribute-set
`bfifo``tc-fifo-qopt`없음
`cake`없음`tc-cake-attrs`
`netem``tc-netem-qopt``tc-netem-attrs`

동일한 sub-message 정의 안에서도 format마다 payload 구성이 다릅니다.

selector attribute는 이를 참조하는 sub-message attribute보다 Netlink message 안에서 먼저 나와야 합니다.

`kind`처럼 같은 이름의 attribute가 여러 nest 수준에 있으면 selector와 가장 가까운 값, 즉 명세상 selector와 같은 수준의 값을 사용합니다. 그 수준의 실제 message에 값이 없으면 바깥 값으로 대체하지 않고 오류입니다.

A sub-message can have an optional ``fixed-header`` followed by zero or more
attributes from an ``attribute-set``. For example the following
``tc-options-msg`` sub-message defines message formats that use a mixture of
``fixed-header``, ``attribute-set`` or both together:

.. code-block:: yaml

  sub-messages:
    -
      name: tc-options-msg
      formats:
        -
          value: bfifo
          fixed-header: tc-fifo-qopt
        -
          value: cake
          attribute-set: tc-cake-attrs
        -
          value: netem
          fixed-header: tc-netem-qopt
          attribute-set: tc-netem-attrs

Note that a selector attribute must appear in a netlink message before any
sub-message attributes that depend on it.

If an attribute such as ``kind`` is defined at more than one nest level, then a
sub-message selector will be resolved using the value 'closest' to the selector.
For example, if the same attribute name is defined in a nested ``attribute-set``
alongside a sub-message selector and also in a top level ``attribute-set``, then
the selector will be resolved using the value 'closest' to the selector. If the
value is not present in the message at the same level as defined in the spec
then this is an error.

중첩 구조체 정의

162-194

traffic control 등 많은 raw family는 구조체 안에 다른 구조체를 포함합니다. `netlink-raw` schema에서는 binary member의 `struct` 속성으로 다른 struct definition을 내장할 수 있습니다.

tc-tbf-qopt member
membertypeembedded struct
`rate``binary``tc-ratespec`
`peakrate``binary``tc-ratespec`
`limit``u32`없음
`buffer``u32`없음
`mtu``u32`없음

두 rate member는 같은 tc-ratespec 구조체를 중첩하고 나머지는 u32입니다.

이 방식은 wire 구조를 평평한 byte array로 취급하지 않고, 재사용 가능한 구조체 definition의 조합으로 정확히 표현합니다.

Nested struct definitions
-------------------------

Many raw netlink families such as :ref:`tc<netlink-tc>`
make use of nested struct definitions. The ``netlink-raw`` schema makes it
possible to embed a struct within a struct definition using the ``struct``
property. For example, the following struct definition embeds the
``tc-ratespec`` struct definition for both the ``rate`` and the ``peakrate``
members of ``struct tc-tbf-qopt``.

.. code-block:: yaml

  -
    name: tc-tbf-qopt
    type: struct
    members:
      -
        name: rate
        type: binary
        struct: tc-ratespec
      -
        name: peakrate
        type: binary
        struct: tc-ratespec
      -
        name: limit
        type: u32
      -
        name: buffer
        type: u32
      -
        name: mtu
        type: u32