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 $
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
15 .TH NETLINK 7 2008-11-11 "Linux" "Linux Programmer's Manual"
18 .\"O netlink \- Communication between kernel and userspace (AF_NETLINK)
19 netlink \- カーネルとユーザー空間の通信 (AF_NETLINK)
23 .B #include <asm/types.h>
24 .B #include <sys/socket.h>
25 .B #include <linux/netlink.h>
27 .BI "netlink_socket = socket(AF_NETLINK, " socket_type ", " netlink_family );
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 はカーネルモジュールとユーザー空間のプロセス間で
41 netlink は、ユーザープロセスに対しては
42 標準的なソケットベースのインターフェースを、
43 カーネルモジュールにはカーネルの内部 API を提供する。
44 カーネル内部のインターフェースについてはこの man ページでは記述しない。
45 また、netlink キャラクタデバイスを用いた
46 obsolete な netlink インターフェースもあるが、これもこの文書では解説しない。
47 これは単に過去互換性のために用意されているものにすぎない。
49 .\"O Netlink is a datagram-oriented service.
54 .\"O are valid values for
55 .\"O .IR socket_type .
56 .\"O However, the netlink protocol does not distinguish between datagram
58 netlink はデータグラム指向のサービスである。
65 しかし netlink プロトコルはデータグラムと raw ソケットの区別をしない。
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:
71 は、通信するカーネルモジュールや netlink グループの選択に用いる。
72 現在割り当てられている netlink ファミリーは以下の通り。
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)).
81 (IPv4 と IPv6 両方の) ルーティングテーブル・
82 IP アドレス・リンクパラメータ・近傍設定 (neighbor setup)・
83 キューイングルール (queueing dicipline)・トラフィッククラス・
84 パケットのクラス分類の修正に用いることができるだろう
89 .\"O Messages from 1-wire subsystem.
90 単線 (1-wire) のサブシステムからのメッセージ。
93 .\"O Reserved for user-mode socket protocols.
94 ユーザーモードソケットプロトコルのために予約されている。
97 .\"O Transport IPv4 packets from netfilter to userspace.
101 IPv4 パケットを netfilter からユーザー空間へ転送する。
106 .\" FIXME More details on NETLINK_INET_DIAG needed.
107 .\"O INET socket monitoring.
111 Netfilter/iptables ULOG.
114 .\" FIXME More details on NETLINK_XFRM needed.
118 .\"O SELinux event notifications.
122 .\" FIXME More details on NETLINK_ISCSI needed.
126 .\" FIXME More details on NETLINK_AUDIT needed.
130 .B NETLINK_FIB_LOOKUP
131 .\" FIXME More details on NETLINK_FIB_LOOKUP needed.
132 .\"O Access to FIB lookup from userspace.
133 ユーザー空間から FIB ルックアップにアクセスする。
136 .\"O Kernel connector.
138 .\"O .I Documentation/connector/*
139 .\"O in the kernel source for further information.
142 .I Documentation/connector/*
146 .\" FIXME More details on NETLINK_NETFILTER needed.
147 .\"O Netfilter subsystem.
151 .\"O Transport IPv6 packets from netfilter to userspace.
155 IPv6 パケットを netfilter からユーザー空間へ転送する。
160 .\"O DECnet routing messages.
163 .B NETLINK_KOBJECT_UEVENT
164 .\" FIXME More details on NETLINK_KOBJECT_UEVENT needed.
165 .\"O Kernel messages to userspace.
169 .\"O Generic netlink family for simplified netlink usage.
170 netlink を簡単に使用するための一般的な netlink ファミリー。
172 .\"O Netlink messages consist of a byte stream with one or multiple
174 .\"O headers and associated payload.
175 netlink メッセージはバイトストリームからなり、
178 ヘッダと、それに対応するペイロード (payload) が含まれる。
179 .\"O The byte stream should only be accessed with the standard
184 .\"O for further information.
192 .\"O In multipart messages (multiple
194 .\"O headers with associated payload in one byte stream) the first and all
195 .\"O following headers have the
197 .\"O flag set, except for the last header which has the type
198 .\"O .BR NLMSG_DONE .
202 一つバイトストリームに含まれる) においては、
205 フラグがセットされる。ただし最後のヘッダだけは例外で、
211 .\"O the payload follows.
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 */
234 .\"O can be one of the standard message types:
236 .\"O message is to be ignored,
238 .\"O message signals an error and the payload contains an
242 .\"O message terminates a multipart message.
244 は標準のメッセージタイプのどれか一つである:
252 メッセージはマルチパートメッセージの終了を伝える。
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; /* エラーを起こしたメッセージのヘッダ */
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)
269 .\"O .BR NETLINK_ROUTE .
270 ある netlink ファミリーで指定できるメッセージタイプは、
271 通常もっと多い。これらに関しては適切な man ページを見てほしい。
278 .\"O Standard flag bits in
283 ---------------------------------
287 .\"O NLM_F_REQUEST:Must be set on all request messages.
289 .\"O The message is part of a multipart message terminated by
290 .\"O .BR NLMSG_DONE .
292 .\"O NLM_F_ACK:Request for an acknowledgment on success.
293 .\"O NLM_F_ECHO:Echo this request.
294 NLM_F_REQUEST:要求メッセージ全てでセットされなければならない。
296 このメッセージはマルチパートメッセージの一部である。
301 NLM_F_ACK:成功した場合の応答を要求する。
302 NLM_F_ECHO:この要求をエコーする。
305 .\"O Additional flag bits for GET requests
308 -------------------------------------
312 .\"O NLM_F_ROOT:Return the complete table instead of a single entry.
314 .\"O Return all entries matching criteria passed in message content.
315 .\"O Not implemented yet.
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:単一のエントリではなくテーブル全体を返す。
322 メッセージの内容で渡された基準 (criteria) にマッチする
326 NLM_F_ATOMIC:テーブルのアトミックなスナップショットを返す。
327 NLM_F_DUMP:便利なマクロ。(NLM_F_ROOT|NLM_F_MATCH) と同じ。
333 .\"O .B CAP_NET_ADMIN
334 .\"O capability or an effective UID of 0.
338 権限を持つか実効ユーザー ID が 0 でなければならない点に注意すること。
340 .\"O Additional flag bits for NEW requests
343 -------------------------------------
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:オブジェクトリストの最後に追加する。
360 .\"O are used to track messages.
366 .\"O shows the origin of the message.
369 .\"O Note that there isn't a 1:1 relationship between
371 .\"O and the PID of the process if the message originated from a netlink
373 メッセージが netlink ソケットで送信されている場合、
375 とプロセスの PID は 1:1 の関係ではない点に注意すること。
377 .\"O .B ADDRESS FORMATS
378 .\"O section for further information.
387 .\"O .\" FIXME Explain more about nlmsg_seq and nlmsg_pid.
388 .\"O are opaque to netlink core.
392 は netlink のコアには見えない (opaque)。
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
403 .\"O An acknowledgment is an
405 .\"O packet with the error field set to 0.
406 netlink はメッセージを行き先に届けるために最善を尽くすが、
407 メモリが足りなかったりエラーが起こったりすると
410 送信者は受信者に応答を要求することもできる。
416 パケットのエラーフィールドを 0 にしたものになる。
417 .\"O The application must generate acknowledgements for
418 .\"O received messages itself.
419 .\"O The kernel tries to send an
421 .\"O message for every failed packet.
422 アプリケーションは自分自身のメッセージを受けたときには、
427 .\"O A user process should follow this convention too.
428 ユーザープロセスはこの慣習にも従う必要がある。
430 .\"O However, reliable transmissions from kernel to user are impossible
432 しかし、どのような場合でもカーネルからユーザーへの
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
442 .\"O error returned by
443 .\"O .BR recvmsg (2))
444 .\"O and resynchronize.
449 エラーが返される) を検知して再び同期させるのは、
451 .\"O .SS Address Formats
455 .\"O structure describes a netlink client in user space or in the kernel.
458 .\"O can be either unicast (only sent to one peer) or sent to
459 .\"O netlink multicast groups
463 構造体はユーザー空間やカーネル空間で netlink クライアントを記述する。
465 はユニキャスト (単一の接続先にだけ送られる) にもできるし、
468 が 0 でない場合) にも送ることができる。
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; /* マルチキャストグループマスク */
486 .\"O is the unicast address of netlink socket.
487 .\"O It's always 0 if the destination is in the kernel.
489 は netlink ソケットのユニキャストアドレスである。
490 行き先がカーネルの場合は、常に 0 である。
491 .\"O For a userspace process,
493 .\"O is usually the PID of the process owning the destination socket.
496 は行き先のソケットを所有しているプロセスの PID である。
499 .\"O identifies a netlink socket, not a process.
502 はプロセスではなく netlink ソケットを同定する。
503 .\"O If a process owns several netlink
506 .\"O can only be equal to the process ID for at most one socket.
507 プロセスが複数の netlink ソケットを所有する場合、
509 は最大でも一つのソケットのプロセス ID としか等しくならない。
510 .\"O There are two ways to assign
512 .\"O to a netlink socket.
514 を netlink ソケットに割り当てる方法は 2 つある。
515 .\"O If the application sets
519 .\"O then it is up to the application to make sure that
528 が一意であることを確認するのはアプリケーションの責任となる。
529 .\"O If the application sets it to 0, the kernel takes care of assigning it.
532 を 0 に設定した場合、カーネルがこの値を割り当てる。
533 .\"O The kernel assigns the process ID to the first netlink socket the process
534 .\"O opens and assigns a unique
536 .\"O to every netlink socket that the process subsequently creates.
538 netlink ソケットに対してプロセス ID を割り当て、
539 それ以降にプロセスが作成した全ての netlink ソケットにも一意な
544 .\"O is a bit mask with every bit representing a netlink group number.
546 はビットマスクで、すべてのビットが netlink グループ番号を表す。
547 .\"O Each netlink family has a set of 32 multicast groups.
548 それぞれの netlink ファミリーは 32 のマルチキャストグループのセットを持つ。
551 .\"O is called on the socket, the
555 .\"O should be set to a bit mask of the groups which it wishes to listen to.
556 それぞれの netlink ファミリーは 32 のマルチキャストグループの
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
568 .\"O to a bit mask of the groups it wishes to send to when it calls
571 .\"O .BR connect (2).
572 デフォルトの値は 0 で、マルチキャストを一切受信しない。
576 によって、あるソケットからメッセージをマルチキャストしたいときは、
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.
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 とマルチキャストグループとに送り返すべきである。
592 .\"O The socket interface to netlink is a new feature of Linux 2.2.
593 netlink へのソケットインターフェースは Linux 2.2 の新機能である。
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 古いインターフェースに関してはここでは記述しない。
602 .\"O NETLINK_SELINUX appeared in Linux 2.6.4.
603 NETLINK_SELINUX は Linux 2.6.4 で登場した。
605 .\"O NETLINK_AUDIT appeared in Linux 2.6.6.
606 NETLINK_AUDIT は Linux 2.6.6 で登場した。
608 .\"O NETLINK_KOBJECT_UEVENT appeared in Linux 2.6.10.
609 NETLINK_KOBJECT_UEVENT は Linux 2.6.10 で登場した。
611 .\"O NETLINK_W1 and NETLINK_FIB_LOOKUP appeared in Linux 2.6.13.
612 NETLINK_W1, NETLINK_FIB_LOOKUP は Linux 2.6.13 で登場した。
614 .\"O NETLINK_INET_DIAG, NETLINK_CONNECTOR and NETLINK_NETFILTER appeared in
616 NETLINK_INET_DIAG, NETLINK_CONNECTOR, NETLINK_NETFILTER は
619 .\"O NETLINK_GENERIC and NETLINK_ISCSI appeared in Linux 2.6.15.
620 NETLINK_GENERIC, NETLINK_ISCSI は Linux 2.6.15 で登場した。
623 .\"O It is often better to use netlink via
627 .\"O than via the low-level kernel interface.
632 を通して netlink を利用するほうが良いことが多い。
634 .\"O This manual page is not complete.
639 .\"O The following example creates a
640 .\"O .B NETLINK_ROUTE
641 .\"O netlink socket which will listen to the
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.
648 (ネットワークインターフェースの create/delete/up/down イベント) と
649 .B RTMGRP_IPV4_IFADDR
650 (IPv4 アドレスの add/delete イベント) マルチキャストグループを listen する
656 struct sockaddr_nl sa;
658 memset(&sa, 0, sizeof(sa));
659 sa.nl_family = AF_NETLINK;
660 sa.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR;
662 fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
663 bind(fd, (struct sockaddr *) &sa, sizeof(sa));
667 .\"O The next example demonstrates how to send a netlink message to the
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 メッセージのシーケンス番号を正しく処理しなければならない点に注意すること。
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 };
683 msg = { (void *)&sa, sizeof(sa), &iov, 1, NULL, 0, 0 };
684 memset(&sa, 0, sizeof(sa));
685 sa.nl_family = AF_NETLINK;
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;
692 sendmsg(fd, &msg, 0);
696 .\"O And the last example is about reading netlink message.
697 最後は、netlink メッセージの読み込みの例である。
703 struct iovec iov = { buf, sizeof(buf) };
704 struct sockaddr_nl sa;
708 msg = { (void *)&sa, sizeof(sa), &iov, 1, NULL, 0, 0 };
709 len = recvmsg(fd, &msg, 0);
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)
718 if (nh\->nlmsg_type == NLMSG_ERROR)
719 .\"O /* Do some error handling. */
723 .\"O /* Continue with parsing payload. */
733 .BR capabilities (7),
736 .\"O ftp://ftp.inr.ac.ru/ip-routing/iproute2*
737 .\"O for information about libnetlink.
739 ftp://ftp.inr.ac.ru/ip-routing/iproute2*
741 .\"O http://people.suug.ch/~tgr/libnl/
742 .\"O for information about libnl.
744 http://people.suug.ch/~tgr/libnl/
746 RFC 3549 "Linux Netlink as an IP Services Protocol"