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
12 .\"WORD payload ¥Ú¥¤¥í¡¼¥É
13 .\"WORD capability ¸¢¸Â
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 backwards compatibility.
39 netlink ¤Ï¥«¡¼¥Í¥ë¥â¥¸¥å¡¼¥ë¤È¥æ¡¼¥¶¡¼¶õ´Ö¤Î¥×¥í¥»¥¹´Ö¤Ç
40 ¾ðÊó¤ò¤ä¤ê¤È¤ê¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤ë¡£
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 ¤Ï¥Ç¡¼¥¿¥°¥é¥à»Ø¸þ¤Î¥µ¡¼¥Ó¥¹¤Ç¤¢¤ë¡£
64 ¤ÎξÊý¤È¤â»ØÄê²Äǽ¤Ç¤¢¤ë¡£
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)).
80 ¥ë¡¼¥Æ¥£¥ó¥°¤È¥ê¥ó¥¯¤Î¹¹¿·¤ò¼õ¿®¤¹¤ë¡£
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 ¤«¤é¥æ¡¼¥¶¡¼¶õ´Ö¤ØžÁ÷¤¹¤ë¡£
103 ¥«¡¼¥Í¥ë¥â¥¸¥å¡¼¥ë¤Ç»ÈÍѤµ¤ì¤ë¡£
106 .\" FIXME More details on NETLINK_INET_DIAG needed.
107 .\"O INET socket monitoring.
108 INET ¥½¥±¥Ã¥È¤ò¥â¥Ë¥¿¥ê¥ó¥°¤¹¤ë¡£
111 Netfilter/iptables ULOG.
114 .\" FIXME More details on NETLINK_XFRM needed.
118 .\"O SELinux event notifications.
119 SELinux ¤Î¥¤¥Ù¥ó¥ÈÄÌÃΡ£
122 .\" FIXME More details on NETLINK_ISCSI needed.
126 .\" FIXME More details on NETLINK_AUDIT needed.
128 ´Æºº (audit) ¤ò¹Ô¤¦¡£
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.
141 ¤è¤ê¾Ü¤·¤¤¾ðÊó¤Ï¥«¡¼¥Í¥ë¥½¡¼¥¹¤Î
142 .I Documentation/connector/*
146 .\" FIXME More details on NETLINK_NETFILTER needed.
147 .\"O Netfilter subsystem.
148 netfilter ¥µ¥Ö¥·¥¹¥Æ¥à¡£
151 .\"O Transport IPv6 packets from netfilter to userspace.
155 IPv6 ¥Ñ¥±¥Ã¥È¤ò netfilter ¤«¤é¥æ¡¼¥¶¡¼¶õ´Ö¤ØžÁ÷¤¹¤ë¡£
157 ¥«¡¼¥Í¥ë¥â¥¸¥å¡¼¥ë¤Ç»ÈÍѤµ¤ì¤ë¡£
160 .\"O DECnet routing messages.
161 DECnet ¥ë¡¼¥Æ¥£¥ó¥°¥á¥Ã¥»¡¼¥¸¡£
163 .B NETLINK_KOBJECT_UEVENT
164 .\" FIXME More details on NETLINK_KOBJECT_UEVENT needed.
165 .\"O Kernel messages to userspace.
166 ¥æ¡¼¥¶¡¼¶õ´Ö¤Ø¤Î¥«¡¼¥Í¥ë¥á¥Ã¥»¡¼¥¸
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.
185 ¥Ð¥¤¥È¥¹¥È¥ê¡¼¥à¤Ë¤Ï¡¢É¸½à¤Î
187 ¥Þ¥¯¥í¤Ë¤è¤Ã¤Æ¤Î¤ß¥¢¥¯¥»¥¹¤¹¤Ù¤¤Ç¤¢¤ë¡£
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 .
199 ¥Þ¥ë¥Á¥Ñ¡¼¥È¥á¥Ã¥»¡¼¥¸ (°ì¤Ä°Ê¾å¤Î
201 ¥Ø¥Ã¥À¤È¡¢¤½¤ì¤ËÂбþ¤¹¤ë¥Ú¥¤¥í¡¼¥É¤¬
202 °ì¤Ä¥Ð¥¤¥È¥¹¥È¥ê¡¼¥à¤Ë´Þ¤Þ¤ì¤ë) ¤Ë¤ª¤¤¤Æ¤Ï¡¢
203 ÀèƬ¤Î¥Ø¥Ã¥À¡¦¸å³¤Î¥Ø¥Ã¥À¤Ë¤Ï
205 ¥Õ¥é¥°¤¬¥»¥Ã¥È¤µ¤ì¤ë¡£¤¿¤À¤·ºÇ¸å¤Î¥Ø¥Ã¥À¤À¤±¤ÏÎã³°¤Ç¡¢
211 .\"O the payload follows.
214 ¤Î¸å¤Ë¤Ï¥Ú¥¤¥í¡¼¥É¤¬Â³¤¯¡£
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 ¤Ïɸ½à¤Î¥á¥Ã¥»¡¼¥¸¥¿¥¤¥×¤Î¤É¤ì¤«°ì¤Ä¤Ç¤¢¤ë:
246 ¥á¥Ã¥»¡¼¥¸¤Ï̵»ë¤µ¤ì¤ë¡£
248 ¥á¥Ã¥»¡¼¥¸¤Ï¥¨¥é¡¼¤ò¼¨¤·¡¢¥Ú¥¤¥í¡¼¥É¤Ë¤Ï
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 ¤³¤Î¥á¥Ã¥»¡¼¥¸¤Ï¥Þ¥ë¥Á¥Ñ¡¼¥È¥á¥Ã¥»¡¼¥¸¤Î°ìÉô¤Ç¤¢¤ë¡£
297 ¥Þ¥ë¥Á¥Ñ¡¼¥È¥á¥Ã¥»¡¼¥¸¤Ï
301 NLM_F_ACK:À®¸ù¤·¤¿¾ì¹ç¤Î±þÅú¤òÍ׵᤹¤ë¡£
302 NLM_F_ECHO:¤³¤ÎÍ×µá¤ò¥¨¥³¡¼¤¹¤ë¡£
305 .\"O Additional flag bits for GET requests
306 GET Í×µá¤Ë¤ª¤±¤ëÄɲåե饰¥Ó¥Ã¥È
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) ¤Ë¥Þ¥Ã¥Á¤¹¤ë
323 Á´¤Æ¤Î¥¨¥ó¥È¥ê¤òÊÖ¤¹¡£
324 ¤Þ¤À¼ÂÁõ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
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
341 NEW Í×µá¤Ë¤ª¤±¤ëÄɲåե饰¥Ó¥Ã¥È
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.
364 ¤Ï¥á¥Ã¥»¡¼¥¸¤ÎÄÉÀפ˻ÈÍѤµ¤ì¤ë¡£
366 .\"O shows the origin of the message.
368 ¤Ï¥á¥Ã¥»¡¼¥¸¤ÎÁ÷¿®¸µ¤òɽ¤¹¡£
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.
380 .RB ¡Ö ¥¢¥É¥ì¥¹¤Î¥Õ¥©¡¼¥Þ¥Ã¥È ¡×
381 ¤Î¥»¥¯¥·¥ç¥ó¤ò»²¾È¤¹¤ë¤³¤È¡£
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 ¥á¥â¥ê¤¬Â¤ê¤Ê¤«¤Ã¤¿¤ê¥¨¥é¡¼¤¬µ¯¤³¤Ã¤¿¤ê¤¹¤ë¤È
408 ¥á¥Ã¥»¡¼¥¸¤ò¼è¤ê¤³¤Ü¤¹¤³¤È¤â¤¢¤ë¡£
409 ¿®ÍêÀ¤Î¹â¤¤Å¾Á÷¤ò¹Ô¤¤¤¿¤¤¤È¤¤Ï¡¢
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 ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¼«Ê¬¼«¿È¤Î¥á¥Ã¥»¡¼¥¸¤ò¼õ¤±¤¿¤È¤¤Ë¤Ï¡¢
423 ±þÅú¤òÀ¸À®¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
424 ¥«¡¼¥Í¥ë¤Ï¼ºÇÔ¤·¤¿¥Ñ¥±¥Ã¥È¤ËÂФ·¤Æ¡¢
426 ¥á¥Ã¥»¡¼¥¸¤òÁ÷¤í¤¦¤È¤¹¤ë¡£
427 .\"O A user process should follow this convention too.
428 ¥æ¡¼¥¶¡¼¥×¥í¥»¥¹¤Ï¤³¤Î´·½¬¤Ë¤â½¾¤¦É¬Íפ¬¤¢¤ë¡£
430 .\"O However, reliable transmissions from kernel to user are impossible
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
442 .\"O error returned by
443 .\"O .BR recvmsg (2))
444 .\"O and resynchronize.
449 ¥¨¥é¡¼¤¬ÊÖ¤µ¤ì¤ë) ¤ò¸¡ÃΤ·¤ÆºÆ¤ÓƱ´ü¤µ¤»¤ë¤Î¤Ï¡¢
450 ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ÎÀÕǤ¤Ç¤¢¤ë¡£
451 .\"O .SS Address Formats
452 .SS ¥¢¥É¥ì¥¹¤Î¥Õ¥©¡¼¥Þ¥Ã¥È
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 ¤Ï¥æ¥Ë¥¥ã¥¹¥È (ñ°ì¤ÎÀܳÀè¤Ë¤À¤±Á÷¤é¤ì¤ë) ¤Ë¤â¤Ç¤¤ë¤·¡¢
466 netlink ¥Þ¥ë¥Á¥¥ã¥¹¥È¥°¥ë¡¼¥×
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.
494 ¥æ¡¼¥¶¡¼¶õ´Ö¥×¥í¥»¥¹¤Î¾ì¹ç¡¢Ä̾ï¤Ï
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.
537 ¥«¡¼¥Í¥ë¤Ï¥×¥í¥»¥¹¤¬ºÇ½é¤Ë¥ª¡¼¥×¥ó¤·¤¿
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 ¤Î¥Þ¥ë¥Á¥¥ã¥¹¥È¥°¥ë¡¼¥×¤Î
559 ¤¬¥½¥±¥Ã¥È¤ËÂФ·¤Æ¸Æ¤Ð¤ì¤ë¤È¡¢
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.
582 ¼Â¸ú¥æ¡¼¥¶¡¼ ID ¤¬ 0 ¤«¡¢
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 ¤Ï
617 Linux 2.6.14 ¤ÇÅо줷¤¿¡£
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.
628 Äã¥ì¥Ù¥ë¤Î¥«¡¼¥Í¥ë¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤è¤ê¡¢
632 ¤òÄ̤·¤Æ netlink ¤òÍøÍѤ¹¤ë¤Û¤¦¤¬Îɤ¤¤³¤È¤¬Â¿¤¤¡£
634 .\"O This manual page is not complete.
636 ¤³¤Î man ¥Ú¡¼¥¸¤Ï´°À®¤·¤Æ¤¤¤Ê¤¤¡£
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 ¤¹¤ë
652 netlink ¤òºîÀ®¤·¤Æ¤¤¤ë¡£
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. */
720 /* ²¿¤é¤«¤Î¥¨¥é¡¼½èÍý¤ò¹Ô¤¦ */
723 .\"O /* Continue with parsing payload. */
724 /* ¥Ú¥¤¥í¡¼¥É¤Î²òÀϤò³¤±¤ë */
733 .BR capabilities (7),
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*
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"