OSDN Git Service

21d2a80e4fd2edd8a2e4ebcc43d1f513d29ac1a7
[linuxjm/LDP_man-pages.git] / original / man7 / rtnetlink.7
1 '\" t
2 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
3 .\"
4 .\" %%%LICENSE_START(VERBATIM_ONE_PARA)
5 .\" Permission is granted to distribute possibly modified copies
6 .\" of this page provided the header is included verbatim,
7 .\" and in case of nontrivial modification author and date
8 .\" of the modification is added to the header.
9 .\" %%%LICENSE_END
10 .\"
11 .\" Based on the original comments from Alexey Kuznetsov, written with
12 .\" help from Matthew Wilcox.
13 .\" $Id: rtnetlink.7,v 1.8 2000/01/22 01:55:04 freitag Exp $
14 .\"
15 .TH RTNETLINK  7 2013-03-05 "Linux" "Linux Programmer's Manual"
16 .SH NAME
17 rtnetlink \- Linux IPv4 routing socket
18 .SH SYNOPSIS
19 .B #include <asm/types.h>
20 .br
21 .B #include <linux/netlink.h>
22 .br
23 .B #include <linux/rtnetlink.h>
24 .br
25 .B #include <sys/socket.h>
26 .sp
27 .BI "rtnetlink_socket = socket(AF_NETLINK, int " socket_type ", NETLINK_ROUTE);"
28 .SH DESCRIPTION
29 Rtnetlink allows the kernel's routing tables to be read and altered.
30 It is used within the kernel to communicate between
31 various subsystems, though this usage is not documented here, and for
32 communication with user-space programs.
33 Network routes, IP addresses, link parameters, neighbor setups, queueing
34 disciplines, traffic classes and packet classifiers may all be controlled
35 through
36 .B NETLINK_ROUTE
37 sockets.
38 It is based on netlink messages; see
39 .BR netlink (7)
40 for more information.
41 .\" FIXME ? all these macros could be moved to rtnetlink(3)
42 .SS Routing attributes
43 Some rtnetlink messages have optional attributes after the initial header:
44
45 .in +4n
46 .nf
47 struct rtattr {
48     unsigned short rta_len;    /* Length of option */
49     unsigned short rta_type;   /* Type of option */
50     /* Data follows */
51 };
52 .fi
53 .in
54
55 These attributes should be only manipulated using the RTA_* macros
56 or libnetlink, see
57 .BR rtnetlink (3).
58 .SS Messages
59 Rtnetlink consists of these message types
60 (in addition to standard netlink messages):
61 .TP
62 .BR RTM_NEWLINK ", " RTM_DELLINK ", " RTM_GETLINK
63 Create, remove or get information about a specific network interface.
64 These messages contain an
65 .I ifinfomsg
66 structure followed by a series of
67 .I rtattr
68 structures.
69
70 .nf
71 struct ifinfomsg {
72     unsigned char  ifi_family; /* AF_UNSPEC */
73     unsigned short ifi_type;   /* Device type */
74     int            ifi_index;  /* Interface index */
75     unsigned int   ifi_flags;  /* Device flags  */
76     unsigned int   ifi_change; /* change mask */
77 };
78 .fi
79
80 .\" FIXME ifi_type
81 .I ifi_flags
82 contains the device flags, see
83 .BR netdevice (7);
84 .I ifi_index
85 is the unique interface index
86 (since Linux 3.7, it is possible to feed a nonzero value with the
87 .B RTM_NEWLINK
88 message, thus creating a link with the given
89 .IR ifindex );
90 .I ifi_change
91 is reserved for future use and should be always set to 0xFFFFFFFF.
92 .na
93 .TS
94 tab(:);
95 c s s
96 l l l.
97 Routing attributes
98 rta_type:value type:description
99 _
100 IFLA_UNSPEC:-:unspecified.
101 IFLA_ADDRESS:hardware address:interface L2 address
102 IFLA_BROADCAST:hardware address:L2 broadcast address.
103 IFLA_IFNAME:asciiz string:Device name.
104 IFLA_MTU:unsigned int:MTU of the device.
105 IFLA_LINK:int:Link type.
106 IFLA_QDISC:asciiz string:Queueing discipline.
107 IFLA_STATS:T{
108 see below
109 T}:Interface Statistics.
110 .TE
111 .ad
112 .sp
113 The value type for
114 .B IFLA_STATS
115 is
116 .IR "struct rtnl_link_stats"
117 .RI ( "struct net_device_stats"
118 in Linux 2.4 and earlier).
119 .TP
120 .BR RTM_NEWADDR ", " RTM_DELADDR ", " RTM_GETADDR
121 Add, remove or receive information about an IP address associated with
122 an interface.
123 In Linux 2.2, an interface can carry multiple IP addresses,
124 this replaces the alias device concept in 2.0.
125 In Linux 2.2, these messages
126 support IPv4 and IPv6 addresses.
127 They contain an
128 .I ifaddrmsg
129 structure, optionally followed by
130 .I rtattr
131 routing attributes.
132
133 .nf
134 struct ifaddrmsg {
135     unsigned char ifa_family;    /* Address type */
136     unsigned char ifa_prefixlen; /* Prefixlength of address */
137     unsigned char ifa_flags;     /* Address flags */
138     unsigned char ifa_scope;     /* Address scope */
139     int           ifa_index;     /* Interface index */
140 };
141 .fi
142
143 .I ifa_family
144 is the address family type (currently
145 .B AF_INET
146 or
147 .BR AF_INET6 ),
148 .I ifa_prefixlen
149 is the length of the address mask of the address if defined for the
150 family (like for IPv4),
151 .I ifa_scope
152 is the address scope,
153 .I ifa_index
154 is the interface index of the interface the address is associated with.
155 .I ifa_flags
156 is a flag word of
157 .B IFA_F_SECONDARY
158 for secondary address (old alias interface),
159 .B IFA_F_PERMANENT
160 for a permanent address set by the user and other undocumented flags.
161 .TS
162 tab(:);
163 c s s
164 l l l.
165 Attributes
166 rta_type:value type:description
167 _
168 IFA_UNSPEC:-:unspecified.
169 IFA_ADDRESS:raw protocol address:interface address
170 IFA_LOCAL:raw protocol address:local address
171 IFA_LABEL:asciiz string:name of the interface
172 IFA_BROADCAST:raw protocol address:broadcast address.
173 IFA_ANYCAST:raw protocol address:anycast address
174 IFA_CACHEINFO:struct ifa_cacheinfo:Address information.
175 .TE
176 .\" FIXME struct ifa_cacheinfo
177 .TP
178 .BR RTM_NEWROUTE ", " RTM_DELROUTE ", " RTM_GETROUTE
179 Create, remove or receive information about a network route.
180 These messages contain an
181 .I rtmsg
182 structure with an optional sequence of
183 .I rtattr
184 structures following.
185 For
186 .BR RTM_GETROUTE ,
187 setting
188 .I rtm_dst_len
189 and
190 .I rtm_src_len
191 to 0 means you get all entries for the specified routing table.
192 For the other fields, except
193 .I rtm_table
194 and
195 .IR rtm_protocol ,
196 0 is the wildcard.
197
198 .nf
199 struct rtmsg {
200     unsigned char rtm_family;   /* Address family of route */
201     unsigned char rtm_dst_len;  /* Length of destination */
202     unsigned char rtm_src_len;  /* Length of source */
203     unsigned char rtm_tos;      /* TOS filter */
204
205     unsigned char rtm_table;    /* Routing table ID */
206     unsigned char rtm_protocol; /* Routing protocol; see below */
207     unsigned char rtm_scope;    /* See below */
208     unsigned char rtm_type;     /* See below */
209
210     unsigned int  rtm_flags;
211 };
212 .fi
213 .na
214 .TS
215 tab(:);
216 l l.
217 rtm_type:Route type
218 _
219 RTN_UNSPEC:unknown route
220 RTN_UNICAST:a gateway or direct route
221 RTN_LOCAL:a local interface route
222 RTN_BROADCAST:T{
223 a local broadcast route (sent as a broadcast)
224 T}
225 RTN_ANYCAST:T{
226 a local broadcast route (sent as a unicast)
227 T}
228 RTN_MULTICAST:a multicast route
229 RTN_BLACKHOLE:a packet dropping route
230 RTN_UNREACHABLE:an unreachable destination
231 RTN_PROHIBIT:a packet rejection route
232 RTN_THROW:continue routing lookup in another table
233 RTN_NAT:a network address translation rule
234 RTN_XRESOLVE:T{
235 refer to an external resolver (not implemented)
236 T}
237 .TE
238 .ad
239 .na
240 .TS
241 tab(:);
242 l l.
243 rtm_protocol:Route origin.
244 _
245 RTPROT_UNSPEC:unknown
246 RTPROT_REDIRECT:T{
247 by an ICMP redirect (currently unused)
248 T}
249 RTPROT_KERNEL:by the kernel
250 RTPROT_BOOT:during boot
251 RTPROT_STATIC:by the administrator
252 .TE
253 .ad
254
255 Values larger than
256 .B RTPROT_STATIC
257 are not interpreted by the kernel, they are just for user information.
258 They may be used to tag the source of a routing information or to
259 distinguish between multiple routing daemons.
260 See
261 .I <linux/rtnetlink.h>
262 for the routing daemon identifiers which are already assigned.
263
264 .I rtm_scope
265 is the distance to the destination:
266 .na
267 .TS
268 tab(:);
269 l l.
270 RT_SCOPE_UNIVERSE:global route
271 RT_SCOPE_SITE:T{
272 interior route in the local autonomous system
273 T}
274 RT_SCOPE_LINK:route on this link
275 RT_SCOPE_HOST:route on the local host
276 RT_SCOPE_NOWHERE:destination doesn't exist
277 .TE
278 .ad
279
280 The values between
281 .B RT_SCOPE_UNIVERSE
282 and
283 .B RT_SCOPE_SITE
284 are available to the user.
285
286 The
287 .I rtm_flags
288 have the following meanings:
289 .na
290 .TS
291 tab(:);
292 l l.
293 RTM_F_NOTIFY:T{
294 if the route changes, notify the user via rtnetlink
295 T}
296 RTM_F_CLONED:route is cloned from another route
297 RTM_F_EQUALIZE:a multipath equalizer (not yet implemented)
298 .TE
299 .ad
300
301 .I rtm_table
302 specifies the routing table
303 .TS
304 tab(:);
305 l l.
306 RT_TABLE_UNSPEC:an unspecified routing table
307 RT_TABLE_DEFAULT:the default table
308 RT_TABLE_MAIN:the main table
309 RT_TABLE_LOCAL:the local table
310 .TE
311
312 The user may assign arbitrary values between
313 .B RT_TABLE_UNSPEC
314 and
315 .BR RT_TABLE_DEFAULT .
316 .\" Keep table on same page
317 .bp +1
318 .TS
319 tab(:);
320 c s s
321 l l l.
322 Attributes
323 rta_type:value type:description
324 _
325 RTA_UNSPEC:-:ignored.
326 RTA_DST:protocol address:Route destination address.
327 RTA_SRC:protocol address:Route source address.
328 RTA_IIF:int:Input interface index.
329 RTA_OIF:int:Output interface index.
330 RTA_GATEWAY:protocol address:The gateway of the route
331 RTA_PRIORITY:int:Priority of route.
332 RTA_PREFSRC::
333 RTA_METRICS:int:Route metric
334 RTA_MULTIPATH::
335 RTA_PROTOINFO::
336 RTA_FLOW::
337 RTA_CACHEINFO::
338 .TE
339
340 .B Fill these values in!
341 .TP
342 .BR RTM_NEWNEIGH ", " RTM_DELNEIGH  ", " RTM_GETNEIGH
343 Add, remove or receive information about a neighbor table
344 entry (e.g., an ARP entry).
345 The message contains an
346 .I ndmsg
347 structure.
348
349 .nf
350 struct ndmsg {
351     unsigned char ndm_family;
352     int           ndm_ifindex;  /* Interface index */
353     __u16         ndm_state;    /* State */
354     __u8          ndm_flags;    /* Flags */
355     __u8          ndm_type;
356 };
357
358 struct nda_cacheinfo {
359     __u32         ndm_confirmed;
360     __u32         ndm_used;
361     __u32         ndm_updated;
362     __u32         ndm_refcnt;
363 };
364 .fi
365
366 .I ndm_state
367 is a bit mask of the following states:
368 .TS
369 tab(:);
370 l l.
371 NUD_INCOMPLETE:a currently resolving cache entry
372 NUD_REACHABLE:a confirmed working cache entry
373 NUD_STALE:an expired cache entry
374 NUD_DELAY:an entry waiting for a timer
375 NUD_PROBE:a cache entry that is currently reprobed
376 NUD_FAILED:an invalid cache entry
377 NUD_NOARP:a device with no destination cache
378 NUD_PERMANENT:a static entry
379 .TE
380
381 Valid
382 .I ndm_flags
383 are:
384 .TS
385 tab(:);
386 l l.
387 NTF_PROXY:a proxy arp entry
388 NTF_ROUTER:an IPv6 router
389 .TE
390
391 .\" FIXME
392 .\" document the members of the struct better
393 The
394 .I rtattr
395 struct has the following meanings for the
396 .I rta_type
397 field:
398 .TS
399 tab(:);
400 l l.
401 NDA_UNSPEC:unknown type
402 NDA_DST:a neighbor cache n/w layer destination address
403 NDA_LLADDR:a neighbor cache link layer address
404 NDA_CACHEINFO:cache statistics.
405 .TE
406
407 If the
408 .I rta_type
409 field is
410 .B NDA_CACHEINFO
411 then a
412 .I struct nda_cacheinfo
413 header follows
414 .TP
415 .BR RTM_NEWRULE ", " RTM_DELRULE ", " RTM_GETRULE
416 Add, delete or retrieve a routing rule.
417 Carries a
418 .I struct rtmsg
419 .TP
420 .BR RTM_NEWQDISC ", " RTM_DELQDISC ", " RTM_GETQDISC
421 Add, remove or get a queueing discipline.
422 The message contains a
423 .I struct tcmsg
424 and may be followed by a series of
425 attributes.
426
427 .nf
428 struct tcmsg {
429     unsigned char    tcm_family;
430     int              tcm_ifindex;   /* interface index */
431     __u32            tcm_handle;    /* Qdisc handle */
432     __u32            tcm_parent;    /* Parent qdisc */
433     __u32            tcm_info;
434 };
435 .fi
436 .TS
437 tab(:);
438 c s s
439 l2 l2 l.
440 Attributes
441 rta_type:value type:Description
442 _
443 TCA_UNSPEC:-:unspecified
444 TCA_KIND:asciiz string:Name of queueing discipline
445 TCA_OPTIONS:byte sequence:Qdisc-specific options follow
446 TCA_STATS:struct tc_stats:Qdisc statistics.
447 TCA_XSTATS:qdisc specific:Module-specific statistics.
448 TCA_RATE:struct tc_estimator:Rate limit.
449 .TE
450
451 In addition various other qdisc module specific attributes are allowed.
452 For more information see the appropriate include files.
453 .TP
454 .BR RTM_NEWTCLASS ", " RTM_DELTCLASS ", " RTM_GETTCLASS
455 Add, remove or get a traffic class.
456 These messages contain a
457 .I struct tcmsg
458 as described above.
459 .TP
460 .BR RTM_NEWTFILTER ", " RTM_DELTFILTER ", " RTM_GETTFILTER
461 Add, remove or receive information about a traffic filter.
462 These messages contain a
463 .I struct tcmsg
464 as described above.
465 .SH VERSIONS
466 .B rtnetlink
467 is a new feature of Linux 2.2.
468 .SH BUGS
469 This manual page is incomplete.
470 .SH SEE ALSO
471 .BR cmsg (3),
472 .BR rtnetlink (3),
473 .BR ip (7),
474 .BR netlink (7)