OSDN Git Service

185533c5ec09d33d84f03993e8ec95884029f30a
[linuxjm/LDP_man-pages.git] / draft / man7 / netlink.7
1 '\" t
2 .\" Don't change the first line, it tells man that tbl is needed.
3 .\" This man page is Copyright (c) 1998 by Andi Kleen. Subject to the GPL.
4 .\" Based on the original comments from Alexey Kuznetsov
5 .\" $Id: netlink.7,v 1.8 2000/06/22 13:23:00 ak Exp $
6 .\"
7 .\" Japanese Version Copyright (c) 1999 NAKANO Takeo all rights reserved.
8 .\" Translated 1999-12-06 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
9 .\" Updated 2001-04-04 by Yuichi SATO <ysato@h4.dion.ne.jp>, catch up to LDP v1.35
10 .\" Updated 2006-06-23 by Yuichi SATO <ysato444@yahoo.co.jp>, catch up to LDP v2.29
11 .\"
12 .\"WORD         payload         ペイロード
13 .\"WORD         capability      権限
14 .\"
15 .TH NETLINK  7 2008-11-11 "Linux" "Linux Programmer's Manual"
16 .\"O .SH NAME
17 .SH 名前
18 .\"O netlink \- Communication between kernel and userspace (AF_NETLINK)
19 netlink \- カーネルとユーザー空間の通信 (AF_NETLINK)
20 .\"O .SH SYNOPSIS
21 .SH 書式
22 .nf
23 .B #include <asm/types.h>
24 .B #include <sys/socket.h>
25 .B #include <linux/netlink.h>
26
27 .BI "netlink_socket = socket(AF_NETLINK, " socket_type ", " netlink_family );
28 .fi
29 .\"O .SH DESCRIPTION
30 .SH 説明
31 .\"O Netlink is used to transfer information between kernel and
32 .\"O userspace processes.
33 .\"O It consists of a standard sockets-based interface for userspace
34 .\"O processes and an internal kernel API for kernel modules.
35 .\"O The internal kernel interface is not documented in this manual page.
36 .\"O There is also an obsolete netlink interface
37 .\"O via netlink character devices; this interface is not documented here
38 .\"O and is only provided for backward compatibility.
39 netlink はカーネルモジュールとユーザー空間のプロセス間で
40 情報をやりとりするために用いられる。
41 netlink は、ユーザープロセスに対しては
42 標準的なソケットベースのインターフェースを、
43 カーネルモジュールにはカーネルの内部 API を提供する。
44 カーネル内部のインターフェースについてはこの man ページでは記述しない。
45 また、netlink キャラクタデバイスを用いた
46 obsolete な netlink インターフェースもあるが、これもこの文書では解説しない。
47 これは単に過去互換性のために用意されているものにすぎない。
48
49 .\"O Netlink is a datagram-oriented service.
50 .\"O Both
51 .\"O .B SOCK_RAW
52 .\"O and
53 .\"O .B SOCK_DGRAM
54 .\"O are valid values for
55 .\"O .IR socket_type .
56 .\"O However, the netlink protocol does not distinguish between datagram
57 .\"O and raw sockets.
58 netlink はデータグラム指向のサービスである。
59 .I socket_type
60 には
61 .B SOCK_RAW
62
63 .B SOCK_DGRAM
64 の両方とも指定可能である。
65 しかし netlink プロトコルはデータグラムと raw ソケットの区別をしない。
66
67 .\"O .I netlink_family
68 .\"O selects the kernel module or netlink group to communicate with.
69 .\"O The currently assigned netlink families are:
70 .I netlink_family
71 は、通信するカーネルモジュールや netlink グループの選択に用いる。
72 現在割り当てられている netlink ファミリーは以下の通り。
73 .TP
74 .B NETLINK_ROUTE
75 .\"O Receives routing and link updates and may be used to modify the routing
76 .\"O tables (both IPv4 and IPv6), IP addresses, link parameters,
77 .\"O neighbor setups, queueing disciplines, traffic classes and
78 .\"O packet classifiers (see
79 .\"O .BR rtnetlink (7)).
80 ルーティングとリンクの更新を受信する。
81 (IPv4 と IPv6 両方の) ルーティングテーブル・
82 IP アドレス・リンクパラメータ・近傍設定 (neighbor setup)・
83 キューイングルール (queueing dicipline)・トラフィッククラス・
84 パケットのクラス分類の修正に用いることができるだろう
85 .RB ( rtnetlink (7)
86 を見よ)。
87 .TP
88 .B NETLINK_W1
89 .\"O Messages from 1-wire subsystem.
90 単線 (1-wire) のサブシステムからのメッセージ。
91 .TP
92 .B NETLINK_USERSOCK
93 .\"O Reserved for user-mode socket protocols.
94 ユーザーモードソケットプロトコルのために予約されている。
95 .TP
96 .B NETLINK_FIREWALL
97 .\"O Transport IPv4 packets from netfilter to userspace.
98 .\"O Used by
99 .\"O .I ip_queue
100 .\"O kernel module.
101 IPv4 パケットを netfilter からユーザー空間へ転送する。
102 .I ip_queue
103 カーネルモジュールで使用される。
104 .TP
105 .B NETLINK_INET_DIAG
106 .\" FIXME More details on NETLINK_INET_DIAG needed.
107 .\"O INET socket monitoring.
108 INET ソケットをモニタリングする。
109 .TP
110 .B NETLINK_NFLOG
111 Netfilter/iptables ULOG.
112 .TP
113 .B NETLINK_XFRM
114 .\" FIXME More details on NETLINK_XFRM needed.
115 IPsec.
116 .TP
117 .B NETLINK_SELINUX
118 .\"O SELinux event notifications.
119 SELinux のイベント通知。
120 .TP
121 .B NETLINK_ISCSI
122 .\" FIXME More details on NETLINK_ISCSI needed.
123 Open-iSCSI.
124 .TP
125 .B NETLINK_AUDIT
126 .\" FIXME More details on NETLINK_AUDIT needed.
127 .\"O Auditing.
128 監査 (audit) を行う。
129 .TP
130 .B NETLINK_FIB_LOOKUP
131 .\" FIXME More details on NETLINK_FIB_LOOKUP needed.
132 .\"O Access to FIB lookup from userspace.
133 ユーザー空間から FIB ルックアップにアクセスする。
134 .TP
135 .B NETLINK_CONNECTOR
136 .\"O Kernel connector.
137 .\"O See
138 .\"O .I Documentation/connector/*
139 .\"O in the kernel source for further information.
140 カーネルコネクタ。
141 より詳しい情報はカーネルソースの
142 .I Documentation/connector/*
143 を参照すること。
144 .TP
145 .B NETLINK_NETFILTER
146 .\" FIXME More details on NETLINK_NETFILTER needed.
147 .\"O Netfilter subsystem.
148 netfilter サブシステム。
149 .TP
150 .B NETLINK_IP6_FW
151 .\"O Transport IPv6 packets from netfilter to userspace.
152 .\"O Used by
153 .\"O .I ip6_queue
154 .\"O kernel module.
155 IPv6 パケットを netfilter からユーザー空間へ転送する。
156 .I ip6_queue
157 カーネルモジュールで使用される。
158 .TP
159 .B NETLINK_DNRTMSG
160 .\"O DECnet routing messages.
161 DECnet ルーティングメッセージ。
162 .TP
163 .B NETLINK_KOBJECT_UEVENT
164 .\" FIXME More details on NETLINK_KOBJECT_UEVENT needed.
165 .\"O Kernel messages to userspace.
166 ユーザー空間へのカーネルメッセージ
167 .TP
168 .B NETLINK_GENERIC
169 .\"O Generic netlink family for simplified netlink usage.
170 netlink を簡単に使用するための一般的な netlink ファミリー。
171 .PP
172 .\"O Netlink messages consist of a byte stream with one or multiple
173 .\"O .I nlmsghdr
174 .\"O headers and associated payload.
175 netlink メッセージはバイトストリームからなり、
176 一つ以上の
177 .I nlmsghdr
178 ヘッダと、それに対応するペイロード (payload) が含まれる。
179 .\"O The byte stream should only be accessed with the standard
180 .\"O .B NLMSG_*
181 .\"O macros.
182 .\"O See
183 .\"O .BR netlink (3)
184 .\"O for further information.
185 バイトストリームには、標準の
186 .B NLMSG_*
187 マクロによってのみアクセスすべきである。
188 より詳しい情報は
189 .BR netlink (3)
190 を見よ。
191
192 .\"O In multipart messages (multiple
193 .\"O .I nlmsghdr
194 .\"O headers with associated payload in one byte stream) the first and all
195 .\"O following headers have the
196 .\"O .B NLM_F_MULTI
197 .\"O flag set, except for the last header which has the type
198 .\"O .BR NLMSG_DONE .
199 マルチパートメッセージ (一つ以上の
200 .I nlmsghdr
201 ヘッダと、それに対応するペイロードが
202 一つバイトストリームに含まれる) においては、
203 先頭のヘッダ・後続のヘッダには
204 .B NLM_F_MULTI
205 フラグがセットされる。ただし最後のヘッダだけは例外で、
206 .B NLMSG_DONE
207 タイプとなる。
208
209 .\"O After each
210 .\"O .I nlmsghdr
211 .\"O the payload follows.
212 それぞれの
213 .B nlmsghdr
214 の後にはペイロードが続く。
215
216 .in +4n
217 .nf
218 struct nlmsghdr {
219 .\"O     __u32 nlmsg_len;    /* Length of message including header. */
220 .\"O     __u16 nlmsg_type;   /* Type of message content. */
221 .\"O     __u16 nlmsg_flags;  /* Additional flags. */
222 .\"O     __u32 nlmsg_seq;    /* Sequence number. */
223 .\"O     __u32 nlmsg_pid;    /* PID of the sending process. */
224     __u32 nlmsg_len;    /* ヘッダを含むメッセージの長さ */
225     __u16 nlmsg_type;   /* メッセージの内容のタイプ */
226     __u16 nlmsg_flags;  /* 追加フラグ */
227     __u32 nlmsg_seq;    /* シーケンス番号 */
228     __u32 nlmsg_pid;    /* 送信プロセスの PID */
229 };
230 .fi
231 .in
232
233 .\"O .I nlmsg_type
234 .\"O can be one of the standard message types:
235 .\"O .B NLMSG_NOOP
236 .\"O message is to be ignored,
237 .\"O .B NLMSG_ERROR
238 .\"O message signals an error and the payload contains an
239 .\"O .I nlmsgerr
240 .\"O structure,
241 .\"O .B NLMSG_DONE
242 .\"O message terminates a multipart message.
243 .I nlmsg_type
244 は標準のメッセージタイプのどれか一つである:
245 .B NLMSG_NOOP
246 メッセージは無視される。
247 .B NLMSG_ERROR
248 メッセージはエラーを示し、ペイロードには
249 .I nlmsgerr
250 構造体が入る。
251 .B NLMSG_DONE
252 メッセージはマルチパートメッセージの終了を伝える。
253
254 .in +4n
255 .nf
256 struct nlmsgerr {
257 .\"O     int error;        /* Negative errno or 0 for acknowledgements */
258 .\"O     struct nlmsghdr msg;  /* Message header that caused the error */
259     int error;        /* 負または 0 の errno は応答を表す */
260     struct nlmsghdr msg;  /* エラーを起こしたメッセージのヘッダ */
261 };
262 .fi
263 .in
264
265 .\"O A netlink family usually specifies more message types, see the
266 .\"O appropriate manual pages for that, for example,
267 .\"O .BR rtnetlink (7)
268 .\"O for
269 .\"O .BR NETLINK_ROUTE .
270 ある netlink ファミリーで指定できるメッセージタイプは、
271 通常もっと多い。これらに関しては適切な man ページを見てほしい。
272 たとえば
273 .B NETLINK_ROUTE
274 に関しては
275 .BR rtnetlink (7)
276 に書いてある。
277
278 .\"O Standard flag bits in
279 .\"O .I nlmsg_flags
280 .I nlmsg_flags
281 の標準フラグビット
282 .br
283 ---------------------------------
284 .TS
285 tab(:);
286 lB l.
287 .\"O NLM_F_REQUEST:Must be set on all request messages.
288 .\"O NLM_F_MULTI:T{
289 .\"O The message is part of a multipart message terminated by
290 .\"O .BR NLMSG_DONE .
291 .\"O T}
292 .\"O NLM_F_ACK:Request for an acknowledgment on success.
293 .\"O NLM_F_ECHO:Echo this request.
294 NLM_F_REQUEST:要求メッセージ全てでセットされなければならない。
295 NLM_F_MULTI:T{
296 このメッセージはマルチパートメッセージの一部である。
297 マルチパートメッセージは
298 .B NLMSG_DONE
299 で終端する。
300 T}
301 NLM_F_ACK:成功した場合の応答を要求する。
302 NLM_F_ECHO:この要求をエコーする。
303 .TE
304
305 .\"O Additional flag bits for GET requests
306 GET 要求における追加フラグビット
307 .br
308 -------------------------------------
309 .TS
310 tab(:);
311 lB l.
312 .\"O NLM_F_ROOT:Return the complete table instead of a single entry.
313 .\"O NLM_F_MATCH:T{
314 .\"O Return all entries matching criteria passed in message content.
315 .\"O Not implemented yet.
316 .\"O T}
317 .\" FIXME NLM_F_ATOMIC is not used any more?
318 .\"O NLM_F_ATOMIC:Return an atomic snapshot of the table.
319 .\"O NLM_F_DUMP:Convenience macro; equivalent to (NLM_F_ROOT|NLM_F_MATCH).
320 NLM_F_ROOT:単一のエントリではなくテーブル全体を返す。
321 NLM_F_MATCH:T{
322 メッセージの内容で渡された基準 (criteria) にマッチする
323 全てのエントリを返す。
324 まだ実装されていない。
325 T}
326 NLM_F_ATOMIC:テーブルのアトミックなスナップショットを返す。
327 NLM_F_DUMP:便利なマクロ。(NLM_F_ROOT|NLM_F_MATCH) と同じ。
328 .TE
329
330 .\"O Note that
331 .\"O .B NLM_F_ATOMIC
332 .\"O requires the
333 .\"O .B CAP_NET_ADMIN
334 .\"O capability or an effective UID of 0.
335 .B NLM_F_ATOMIC
336 を使う場合は、
337 .B CAP_NET_ADMIN
338 権限を持つか実効ユーザー ID が 0 でなければならない点に注意すること。
339
340 .\"O Additional flag bits for NEW requests
341 NEW 要求における追加フラグビット
342 .br
343 -------------------------------------
344 .TS
345 tab(:);
346 lB l.
347 .\"O NLM_F_REPLACE:Replace existing matching object.
348 .\"O NLM_F_EXCL:Don't replace if the object already exists.
349 .\"O NLM_F_CREATE:Create object if it doesn't already exist.
350 .\"O NLM_F_APPEND:Add to the end of the object list.
351 NLM_F_REPLACE:現存のオブジェクトを置換する。
352 NLM_F_EXCL:すでにオブジェクトがあったら置換しない。
353 NLM_F_CREATE:まだオブジェクトがなければ作成する。
354 NLM_F_APPEND:オブジェクトリストの最後に追加する。
355 .TE
356
357 .\"O .I nlmsg_seq
358 .\"O and
359 .\"O .I nlmsg_pid
360 .\"O are used to track messages.
361 .I nlmsg_seq
362
363 .I nlmsg_pid
364 はメッセージの追跡に使用される。
365 .\"O .I nlmsg_pid
366 .\"O shows the origin of the message.
367 .I nlmsg_pid
368 はメッセージの送信元を表す。
369 .\"O Note that there isn't a 1:1 relationship between
370 .\"O .I nlmsg_pid
371 .\"O and the PID of the process if the message originated from a netlink
372 .\"O socket.
373 メッセージが netlink ソケットで送信されている場合、
374 .I nlmsg_pid
375 とプロセスの PID は 1:1 の関係ではない点に注意すること。
376 .\"O See the
377 .\"O .B ADDRESS FORMATS
378 .\"O section for further information.
379 より詳しい情報は、
380 .RB 「 アドレスのフォーマット 」
381 のセクションを参照すること。
382
383 .\"O Both
384 .\"O .I nlmsg_seq
385 .\"O and
386 .\"O .I nlmsg_pid
387 .\"O .\" FIXME Explain more about nlmsg_seq and nlmsg_pid.
388 .\"O are opaque to netlink core.
389 .I nlmsg_seq
390
391 .I nlmsg_pid
392 は netlink のコアには見えない (opaque)。
393
394 .\"O Netlink is not a reliable protocol.
395 netlink は信頼性の高いプロトコルではない。
396 .\"O It tries its best to deliver a message to its destination(s),
397 .\"O but may drop messages when an out-of-memory condition or
398 .\"O other error occurs.
399 .\"O For reliable transfer the sender can request an
400 .\"O acknowledgement from the receiver by setting the
401 .\"O .B NLM_F_ACK
402 .\"O flag.
403 .\"O An acknowledgment is an
404 .\"O .B NLMSG_ERROR
405 .\"O packet with the error field set to 0.
406 netlink はメッセージを行き先に届けるために最善を尽くすが、
407 メモリが足りなかったりエラーが起こったりすると
408 メッセージを取りこぼすこともある。
409 信頼性の高い転送を行いたいときは、
410 送信者は受信者に応答を要求することもできる。
411 これには
412 .B NLM_F_ACK
413 フラグをセットする。
414 応答は
415 .B NLMSG_ERROR
416 パケットのエラーフィールドを 0 にしたものになる。
417 .\"O The application must generate acknowledgements for
418 .\"O received messages itself.
419 .\"O The kernel tries to send an
420 .\"O .B NLMSG_ERROR
421 .\"O message for every failed packet.
422 アプリケーションは自分自身のメッセージを受けたときには、
423 応答を生成しなければならない。
424 カーネルは失敗したパケットに対して、
425 .B NLMSG_ERROR
426 メッセージを送ろうとする。
427 .\"O A user process should follow this convention too.
428 ユーザープロセスはこの慣習にも従う必要がある。
429
430 .\"O However, reliable transmissions from kernel to user are impossible
431 .\"O in any case.
432 しかし、どのような場合でもカーネルからユーザーへの
433 信頼性の高い転送は不可能である。
434 .\"O The kernel can't send a netlink message if the socket buffer is full:
435 .\"O the message will be dropped and the kernel and the userspace process will
436 .\"O no longer have the same view of kernel state.
437 ソケットバッファが満杯の場合、カーネルは netlink メッセージを送信できない。
438 メッセージは取りこぼされて、カーネルとユーザー空間プロセスは、
439 カーネルの状態についての同じビューを持つことができなくなる。
440 .\"O It is up to the application to detect when this happens (via the
441 .\"O .B ENOBUFS
442 .\"O error returned by
443 .\"O .BR recvmsg (2))
444 .\"O and resynchronize.
445 これが起こったこと
446 .RB ( recvmsg (2)
447 によって
448 .B ENOBUFS
449 エラーが返される) を検知して再び同期させるのは、
450 アプリケーションの責任である。
451 .\"O .SS Address Formats
452 .SS アドレスのフォーマット
453 .\"O The
454 .\"O .I sockaddr_nl
455 .\"O structure describes a netlink client in user space or in the kernel.
456 .\"O A
457 .\"O .I sockaddr_nl
458 .\"O can be either unicast (only sent to one peer) or sent to
459 .\"O netlink multicast groups
460 .\"O .RI ( nl_groups
461 .\"O not equal 0).
462 .I sockaddr_nl
463 構造体はユーザー空間やカーネル空間で netlink クライアントを記述する。
464 .I sockaddr_nl
465 はユニキャスト (単一の接続先にだけ送られる) にもできるし、
466 netlink マルチキャストグループ
467 .RI ( nl_groups
468 が 0 でない場合) にも送ることができる。
469
470 .in +4n
471 .nf
472 struct sockaddr_nl {
473 .\"O     sa_family_t     nl_family;  /* AF_NETLINK */
474 .\"O     unsigned short  nl_pad;     /* Zero. */
475 .\"O     pid_t           nl_pid;     /* Process ID. */
476 .\"O     __u32           nl_groups;  /* Multicast groups mask. */
477     sa_family_t     nl_family;  /* AF_NETLINK */
478     unsigned short  nl_pad;     /* 0 である */
479     pid_t           nl_pid;     /* プロセス ID */
480     __u32           nl_groups;  /* マルチキャストグループマスク */
481 };
482 .fi
483 .in
484
485 .\"O .I nl_pid
486 .\"O is the unicast address of netlink socket.
487 .\"O It's always 0 if the destination is in the kernel.
488 .I nl_pid
489 は netlink ソケットのユニキャストアドレスである。
490 行き先がカーネルの場合は、常に 0 である。
491 .\"O For a userspace process,
492 .\"O .I nl_pid
493 .\"O is usually the PID of the process owning the destination socket.
494 ユーザー空間プロセスの場合、通常は
495 .I nl_pid
496 は行き先のソケットを所有しているプロセスの PID である。
497 .\"O However,
498 .\"O .I nl_pid
499 .\"O identifies a netlink socket, not a process.
500 ただし、
501 .I nl_pid
502 はプロセスではなく netlink ソケットを同定する。
503 .\"O If a process owns several netlink
504 .\"O sockets, then
505 .\"O .I nl_pid
506 .\"O can only be equal to the process ID for at most one socket.
507 プロセスが複数の netlink ソケットを所有する場合、
508 .I nl_pid
509 は最大でも一つのソケットのプロセス ID としか等しくならない。
510 .\"O There are two ways to assign
511 .\"O .I nl_pid
512 .\"O to a netlink socket.
513 .I nl_pid
514 を netlink ソケットに割り当てる方法は 2 つある。
515 .\"O If the application sets
516 .\"O .I nl_pid
517 .\"O before calling
518 .\"O .BR bind (2),
519 .\"O then it is up to the application to make sure that
520 .\"O .I nl_pid
521 .\"O is unique.
522 アプリケーションが
523 .BR bind (2)
524 を呼ぶ前に
525 .I nl_pid
526 を設定する場合、
527 .I nl_pid
528 が一意であることを確認するのはアプリケーションの責任となる。
529 .\"O If the application sets it to 0, the kernel takes care of assigning it.
530 アプリケーションが
531 .I nl_pid
532 を 0 に設定した場合、カーネルがこの値を割り当てる。
533 .\"O The kernel assigns the process ID to the first netlink socket the process
534 .\"O opens and assigns a unique
535 .\"O .I nl_pid
536 .\"O to every netlink socket that the process subsequently creates.
537 カーネルはプロセスが最初にオープンした
538 netlink ソケットに対してプロセス ID を割り当て、
539 それ以降にプロセスが作成した全ての netlink ソケットにも一意な
540 .I nl_pid
541 を割り当てる。
542
543 .\"O .I nl_groups
544 .\"O is a bit mask with every bit representing a netlink group number.
545 .I nl_groups
546 はビットマスクで、すべてのビットが netlink グループ番号を表す。
547 .\"O Each netlink family has a set of 32 multicast groups.
548 それぞれの netlink ファミリーは 32 のマルチキャストグループのセットを持つ。
549 .\"O When
550 .\"O .BR bind (2)
551 .\"O is called on the socket, the
552 .\"O .I nl_groups
553 .\"O field in the
554 .\"O .I sockaddr_nl
555 .\"O should be set to a bit mask of the groups which it wishes to listen to.
556 それぞれの netlink ファミリーは 32 のマルチキャストグループの
557 セットを持つ。
558 .BR bind (2)
559 がソケットに対して呼ばれると、
560 .I sockaddr_nl
561
562 .I nl_groups
563 フィールドには listen したいグループのビットマスクがセットされる。
564 .\"O The default value for this field is zero which means that no multicasts
565 .\"O will be received.
566 .\"O A socket may multicast messages to any of the multicast groups by setting
567 .\"O .I nl_groups
568 .\"O to a bit mask of the groups it wishes to send to when it calls
569 .\"O .BR sendmsg (2)
570 .\"O or does a
571 .\"O .BR connect (2).
572 デフォルトの値は 0 で、マルチキャストを一切受信しない。
573 .BR sendmsg (2)
574
575 .BR connect (2)
576 によって、あるソケットからメッセージをマルチキャストしたいときは、
577 .I nl_groups
578 に送信したいグループのビットマスクをセットすればよい。
579 .\"O Only processes with an effective UID of 0 or the
580 .\"O .B CAP_NET_ADMIN
581 .\"O capability may send or listen to a netlink multicast group.
582 実効ユーザー ID が 0 か、
583 .B CAP_NET_ADMIN
584 権限を持つユーザーのみが netlink マルチキャストグループに
585 送信したり、これを listen したりすることができる。
586 .\"O Any replies to a message received for a multicast group should be
587 .\"O sent back to the sending PID and the multicast group.
588 マルチキャストグループ向けメッセージを受信した場合、これ対する応答は
589 送り主の PID とマルチキャストグループとに送り返すべきである。
590 .\"O .SH VERSIONS
591 .SH バージョン
592 .\"O The socket interface to netlink is a new feature of Linux 2.2.
593 netlink へのソケットインターフェースは Linux 2.2 の新機能である。
594
595 .\"O Linux 2.0 supported a more primitive device-based netlink interface
596 .\"O (which is still available as a compatibility option).
597 .\"O This obsolete interface is not described here.
598 Linux 2.0 は、もっと原始的なデバイスベースの netlink インターフェースを
599 サポートしていた (これも互換性のために今でも使用できる)。
600 古いインターフェースに関してはここでは記述しない。
601
602 .\"O NETLINK_SELINUX appeared in Linux 2.6.4.
603 NETLINK_SELINUX は Linux 2.6.4 で登場した。
604
605 .\"O NETLINK_AUDIT appeared in Linux 2.6.6.
606 NETLINK_AUDIT は Linux 2.6.6 で登場した。
607
608 .\"O NETLINK_KOBJECT_UEVENT appeared in Linux 2.6.10.
609 NETLINK_KOBJECT_UEVENT は Linux 2.6.10 で登場した。
610
611 .\"O NETLINK_W1 and NETLINK_FIB_LOOKUP appeared in Linux 2.6.13.
612 NETLINK_W1, NETLINK_FIB_LOOKUP は Linux 2.6.13 で登場した。
613
614 .\"O NETLINK_INET_DIAG, NETLINK_CONNECTOR and NETLINK_NETFILTER appeared in
615 .\"O Linux 2.6.14.
616 NETLINK_INET_DIAG, NETLINK_CONNECTOR, NETLINK_NETFILTER は
617 Linux 2.6.14 で登場した。
618
619 .\"O NETLINK_GENERIC and NETLINK_ISCSI appeared in Linux 2.6.15.
620 NETLINK_GENERIC, NETLINK_ISCSI は Linux 2.6.15 で登場した。
621 .\"O .SH NOTES
622 .SH 注意
623 .\"O It is often better to use netlink via
624 .\"O .I libnetlink
625 .\"O or
626 .\"O .I libnl
627 .\"O than via the low-level kernel interface.
628 低レベルのカーネルインターフェースより、
629 .I libnetlink
630 または
631 .I libnl
632 を通して netlink を利用するほうが良いことが多い。
633 .\"O .SH BUGS
634 .\"O This manual page is not complete.
635 .SH バグ
636 この man ページは完成していない。
637 .\"O .SH EXAMPLE
638 .SH 例
639 .\"O The following example creates a
640 .\"O .B NETLINK_ROUTE
641 .\"O netlink socket which will listen to the
642 .\"O .B RTMGRP_LINK
643 .\"O (network interface create/delete/up/down events) and
644 .\"O .B RTMGRP_IPV4_IFADDR
645 .\"O (IPv4 addresses add/delete events) multicast groups.
646 以下の例では、
647 .B RTMGRP_LINK
648 (ネットワークインターフェースの create/delete/up/down イベント) と
649 .B RTMGRP_IPV4_IFADDR
650 (IPv4 アドレスの add/delete イベント) マルチキャストグループを listen する
651 .B NETLINK_ROUTE
652 netlink を作成している。
653
654 .in +4n
655 .nf
656 struct sockaddr_nl sa;
657
658 memset(&sa, 0, sizeof(sa));
659 sa.nl_family = AF_NETLINK;
660 sa.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR;
661
662 fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
663 bind(fd, (struct sockaddr *) &sa, sizeof(sa));
664 .fi
665 .in
666
667 .\"O The next example demonstrates how to send a netlink message to the
668 .\"O kernel (pid 0).
669 .\"O Note that application must take care of message sequence numbers
670 .\"O in order to reliably track acknowledgements.
671 次の例では、netlink メッセージをカーネル (pid 0) に送る方法を示している。
672 応答を追跡する際の信頼性を高めるために、アプリケーションが
673 メッセージのシーケンス番号を正しく処理しなければならない点に注意すること。
674
675 .in +4n
676 .nf
677 .\"O struct nlmsghdr *nh;    /* The nlmsghdr with payload to send. */
678 struct nlmsghdr *nh;    /* 送信する nlmsghdr とペイロード */
679 struct sockaddr_nl sa;
680 struct iovec iov = { (void *) nh, nh\->nlmsg_len };
681 struct msghdr msg;
682
683 msg = { (void *)&sa, sizeof(sa), &iov, 1, NULL, 0, 0 };
684 memset(&sa, 0, sizeof(sa));
685 sa.nl_family = AF_NETLINK;
686 nh\->nlmsg_pid = 0;
687 nh\->nlmsg_seq = ++sequence_number;
688 .\"O /* Request an ack from kernel by setting NLM_F_ACK. */
689 /* NLM_F_ACK を設定することで、カーネルに応答を要求する */
690 nh\->nlmsg_flags |= NLM_F_ACK;
691
692 sendmsg(fd, &msg, 0);
693 .fi
694 .in
695
696 .\"O And the last example is about reading netlink message.
697 最後は、netlink メッセージの読み込みの例である。
698
699 .in +4n
700 .nf
701 int len;
702 char buf[4096];
703 struct iovec iov = { buf, sizeof(buf) };
704 struct sockaddr_nl sa;
705 struct msghdr msg;
706 struct nlmsghdr *nh;
707
708 msg = { (void *)&sa, sizeof(sa), &iov, 1, NULL, 0, 0 };
709 len = recvmsg(fd, &msg, 0);
710
711 for (nh = (struct nlmsghdr *) buf; NLMSG_OK (nh, len);
712      nh = NLMSG_NEXT (nh, len)) {
713 .\"O     /* The end of multipart message. */
714     /* マルチパートメッセージの終わり */
715     if (nh\->nlmsg_type == NLMSG_DONE)
716         return;
717
718     if (nh\->nlmsg_type == NLMSG_ERROR)
719 .\"O         /* Do some error handling. */
720         /* 何らかのエラー処理を行う */
721     ...
722
723 .\"O     /* Continue with parsing payload. */
724     /* ペイロードの解析を続ける */
725     ...
726 }
727 .fi
728 .in
729 .\"O .SH SEE ALSO
730 .SH 関連項目
731 .BR cmsg (3),
732 .BR netlink (3),
733 .BR capabilities (7),
734 .BR rtnetlink (7)
735 .PP
736 .\"O ftp://ftp.inr.ac.ru/ip-routing/iproute2*
737 .\"O for information about libnetlink.
738 libnetlink に関する情報は
739 ftp://ftp.inr.ac.ru/ip-routing/iproute2*
740
741 .\"O http://people.suug.ch/~tgr/libnl/
742 .\"O for information about libnl.
743 libnl に関する情報は
744 http://people.suug.ch/~tgr/libnl/
745
746 RFC 3549 "Linux Netlink as an IP Services Protocol"