]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man7/rtnetlink.7
rtnetlink.7: Add missing RTA_* attributes
[thirdparty/man-pages.git] / 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 2020-02-09 "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 .PP
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 .PP
45 .in +4n
46 .EX
47 struct rtattr {
48 unsigned short rta_len; /* Length of option */
49 unsigned short rta_type; /* Type of option */
50 /* Data follows */
51 };
52 .EE
53 .in
54 .PP
55 These attributes should be manipulated using only 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 .IP
70 .EX
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 .EE
79 .IP
80 .\" FIXME Document ifinfomsg.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 .TS
93 tab(:);
94 c s s
95 l l l.
96 Routing attributes
97 rta_type:value type:description
98 _
99 IFLA_UNSPEC:-:unspecified.
100 IFLA_ADDRESS:hardware address:interface L2 address
101 IFLA_BROADCAST:hardware address:L2 broadcast address.
102 IFLA_IFNAME:asciiz string:Device name.
103 IFLA_MTU:unsigned int:MTU of the device.
104 IFLA_LINK:int:Link type.
105 IFLA_QDISC:asciiz string:Queueing discipline.
106 IFLA_STATS:T{
107 see below
108 T}:Interface Statistics.
109 .TE
110 .PP
111 The value type for
112 .B IFLA_STATS
113 is
114 .IR "struct rtnl_link_stats"
115 .RI ( "struct net_device_stats"
116 in Linux 2.4 and earlier).
117 .TP
118 .BR RTM_NEWADDR ", " RTM_DELADDR ", " RTM_GETADDR
119 Add, remove or receive information about an IP address associated with
120 an interface.
121 In Linux 2.2, an interface can carry multiple IP addresses,
122 this replaces the alias device concept in 2.0.
123 In Linux 2.2, these messages
124 support IPv4 and IPv6 addresses.
125 They contain an
126 .I ifaddrmsg
127 structure, optionally followed by
128 .I rtattr
129 routing attributes.
130 .IP
131 .EX
132 struct ifaddrmsg {
133 unsigned char ifa_family; /* Address type */
134 unsigned char ifa_prefixlen; /* Prefixlength of address */
135 unsigned char ifa_flags; /* Address flags */
136 unsigned char ifa_scope; /* Address scope */
137 unsigned int ifa_index; /* Interface index */
138 };
139 .EE
140 .IP
141 .I ifa_family
142 is the address family type (currently
143 .B AF_INET
144 or
145 .BR AF_INET6 ),
146 .I ifa_prefixlen
147 is the length of the address mask of the address if defined for the
148 family (like for IPv4),
149 .I ifa_scope
150 is the address scope,
151 .I ifa_index
152 is the interface index of the interface the address is associated with.
153 .I ifa_flags
154 is a flag word of
155 .B IFA_F_SECONDARY
156 for secondary address (old alias interface),
157 .B IFA_F_PERMANENT
158 for a permanent address set by the user and other undocumented flags.
159 .TS
160 tab(:);
161 c s s
162 l l l.
163 Attributes
164 rta_type:value type:description
165 _
166 IFA_UNSPEC:-:unspecified.
167 IFA_ADDRESS:raw protocol address:interface address
168 IFA_LOCAL:raw protocol address:local address
169 IFA_LABEL:asciiz string:name of the interface
170 IFA_BROADCAST:raw protocol address:broadcast address.
171 IFA_ANYCAST:raw protocol address:anycast address
172 IFA_CACHEINFO:struct ifa_cacheinfo:Address information.
173 .TE
174 .\" FIXME Document struct ifa_cacheinfo
175 .TP
176 .BR RTM_NEWROUTE ", " RTM_DELROUTE ", " RTM_GETROUTE
177 Create, remove or receive information about a network route.
178 These messages contain an
179 .I rtmsg
180 structure with an optional sequence of
181 .I rtattr
182 structures following.
183 For
184 .BR RTM_GETROUTE ,
185 setting
186 .I rtm_dst_len
187 and
188 .I rtm_src_len
189 to 0 means you get all entries for the specified routing table.
190 For the other fields, except
191 .I rtm_table
192 and
193 .IR rtm_protocol ,
194 0 is the wildcard.
195 .IP
196 .EX
197 struct rtmsg {
198 unsigned char rtm_family; /* Address family of route */
199 unsigned char rtm_dst_len; /* Length of destination */
200 unsigned char rtm_src_len; /* Length of source */
201 unsigned char rtm_tos; /* TOS filter */
202
203 unsigned char rtm_table; /* Routing table ID; see RTA_TABLE below */
204 unsigned char rtm_protocol; /* Routing protocol; see below */
205 unsigned char rtm_scope; /* See below */
206 unsigned char rtm_type; /* See below */
207
208 unsigned int rtm_flags;
209 };
210 .EE
211 .TS
212 tab(:);
213 l l.
214 rtm_type:Route type
215 _
216 RTN_UNSPEC:unknown route
217 RTN_UNICAST:a gateway or direct route
218 RTN_LOCAL:a local interface route
219 RTN_BROADCAST:T{
220 a local broadcast route (sent as a broadcast)
221 T}
222 RTN_ANYCAST:T{
223 a local broadcast route (sent as a unicast)
224 T}
225 RTN_MULTICAST:a multicast route
226 RTN_BLACKHOLE:a packet dropping route
227 RTN_UNREACHABLE:an unreachable destination
228 RTN_PROHIBIT:a packet rejection route
229 RTN_THROW:continue routing lookup in another table
230 RTN_NAT:a network address translation rule
231 RTN_XRESOLVE:T{
232 refer to an external resolver (not implemented)
233 T}
234 .TE
235 .TS
236 tab(:);
237 l l.
238 rtm_protocol:Route origin.
239 _
240 RTPROT_UNSPEC:unknown
241 RTPROT_REDIRECT:T{
242 by an ICMP redirect (currently unused)
243 T}
244 RTPROT_KERNEL:by the kernel
245 RTPROT_BOOT:during boot
246 RTPROT_STATIC:by the administrator
247 .TE
248 .sp 1
249 Values larger than
250 .B RTPROT_STATIC
251 are not interpreted by the kernel, they are just for user information.
252 They may be used to tag the source of a routing information or to
253 distinguish between multiple routing daemons.
254 See
255 .I <linux/rtnetlink.h>
256 for the routing daemon identifiers which are already assigned.
257 .IP
258 .I rtm_scope
259 is the distance to the destination:
260 .TS
261 tab(:);
262 l l.
263 RT_SCOPE_UNIVERSE:global route
264 RT_SCOPE_SITE:T{
265 interior route in the local autonomous system
266 T}
267 RT_SCOPE_LINK:route on this link
268 RT_SCOPE_HOST:route on the local host
269 RT_SCOPE_NOWHERE:destination doesn't exist
270 .TE
271 .sp 1
272 The values between
273 .B RT_SCOPE_UNIVERSE
274 and
275 .B RT_SCOPE_SITE
276 are available to the user.
277 .IP
278 The
279 .I rtm_flags
280 have the following meanings:
281 .TS
282 tab(:);
283 l l.
284 RTM_F_NOTIFY:T{
285 if the route changes, notify the user via rtnetlink
286 T}
287 RTM_F_CLONED:route is cloned from another route
288 RTM_F_EQUALIZE:a multipath equalizer (not yet implemented)
289 .TE
290 .sp 1
291 .I rtm_table
292 specifies the routing table
293 .TS
294 tab(:);
295 l l.
296 RT_TABLE_UNSPEC:an unspecified routing table
297 RT_TABLE_DEFAULT:the default table
298 RT_TABLE_MAIN:the main table
299 RT_TABLE_LOCAL:the local table
300 .TE
301 .sp 1
302 The user may assign arbitrary values between
303 .B RT_TABLE_UNSPEC
304 and
305 .BR RT_TABLE_DEFAULT .
306 .\" Keep table on same page
307 .bp +1
308 .TS
309 tab(:);
310 c s s
311 l l l.
312 Attributes
313 rta_type:value type:description
314 _
315 RTA_UNSPEC:-:ignored.
316 RTA_DST:protocol address:Route destination address.
317 RTA_SRC:protocol address:Route source address.
318 RTA_IIF:int:Input interface index.
319 RTA_OIF:int:Output interface index.
320 RTA_GATEWAY:protocol address:The gateway of the route
321 RTA_PRIORITY:int:Priority of route.
322 RTA_PREFSRC:protocol address:Preferred source address.
323 RTA_METRICS:int:Route metric
324 RTA_MULTIPATH::Multipath nexthop data (see below).
325 RTA_PROTOINFO::No longer used
326 RTA_FLOW:int:Route realm
327 RTA_CACHEINFO:struct rta_cacheinfo:(see linux/rtnetlink.h)
328 RTA_SESSION::No longer used
329 RTA_MP_ALGO::No longer used
330 RTA_TABLE:int:Routing table ID; if set, rtm_table is ignored.
331 RTA_MARK:int:
332 RTA_MFC_STATS:struct rta_mfc_stats:(see linux/rtnetlink.h)
333 RTA_VIA:struct rtvia:Gateway in different AF (see below).
334 RTA_NEWDST:protocol address:Change packet destination address.
335 RTA_PREF:char:RFC4191 IPv6 router preference (see below).
336 RTA_ENCAP_TYPE:short:Encapsulation type for lwtunnels (see below).
337 RTA_ENCAP::Defined by RTA_ENCAP_TYPE.
338 RTA_EXPIRES:int:Expire time for IPv6 routes (in seconds).
339 .TE
340 .I RTA_MULTIPATH
341 contains several packed instances of
342 .I struct rtnexthop
343 together with nested RTA's (RTA_GATEWAY)
344
345 .nf
346 struct rtnexthop {
347 unsigned short rtnh_len; /* Length of struct + length of RTA's
348 unsigned char rtnh_flags; /* Flags (see linux/rtnetlink.h) */
349 unsigned char rtnh_hops; /* Nexthop priority */
350 int rtnh_ifindex; /* Interface index for this nexthop */
351 }
352
353 There exist a bunch of RTNH_* macros similar to RTA_* and NLHDR_* macros
354 useful to handle these structures.
355
356 .nf
357 struct rtvia {
358 unsigned short rtvia_family;
359 unsigned char rtvia_addr[0];
360 };
361 .fi
362
363 .I rtvia_addr
364 is the address,
365 .I rtvia_family
366 is its family type.
367
368 .I RTA_PREF
369 may contain values ICMPV6_ROUTER_PREF_LOW,
370 ICMPV6_ROUTER_PREF_MEDIUM and
371 ICMPV6_ROUTER_PREF_HIGH defined in <linux/icmpv6.h>
372
373 .I RTA_ENCAP_TYPE
374 may contain values LWTUNNEL_ENCAP_MPLS, LWTUNNEL_ENCAP_IP, LWTUNNEL_ENCAP_ILA or LWTUNNEL_ENCAP_IP6
375 defined in <linux/lwtunnel.h>
376 .sp 1
377 .B Fill these values in!
378 .TP
379 .BR RTM_NEWNEIGH ", " RTM_DELNEIGH ", " RTM_GETNEIGH
380 Add, remove or receive information about a neighbor table
381 entry (e.g., an ARP entry).
382 The message contains an
383 .I ndmsg
384 structure.
385 .IP
386 .EX
387 struct ndmsg {
388 unsigned char ndm_family;
389 int ndm_ifindex; /* Interface index */
390 __u16 ndm_state; /* State */
391 __u8 ndm_flags; /* Flags */
392 __u8 ndm_type;
393 };
394
395 struct nda_cacheinfo {
396 __u32 ndm_confirmed;
397 __u32 ndm_used;
398 __u32 ndm_updated;
399 __u32 ndm_refcnt;
400 };
401 .EE
402 .IP
403 .I ndm_state
404 is a bit mask of the following states:
405 .TS
406 tab(:);
407 l l.
408 NUD_INCOMPLETE:a currently resolving cache entry
409 NUD_REACHABLE:a confirmed working cache entry
410 NUD_STALE:an expired cache entry
411 NUD_DELAY:an entry waiting for a timer
412 NUD_PROBE:a cache entry that is currently reprobed
413 NUD_FAILED:an invalid cache entry
414 NUD_NOARP:a device with no destination cache
415 NUD_PERMANENT:a static entry
416 .TE
417 .sp 1
418 Valid
419 .I ndm_flags
420 are:
421 .TS
422 tab(:);
423 l l.
424 NTF_PROXY:a proxy arp entry
425 NTF_ROUTER:an IPv6 router
426 .TE
427 .sp 1
428 .\" FIXME .
429 .\" document the members of the struct better
430 The
431 .I rtattr
432 struct has the following meanings for the
433 .I rta_type
434 field:
435 .TS
436 tab(:);
437 l l.
438 NDA_UNSPEC:unknown type
439 NDA_DST:a neighbor cache n/w layer destination address
440 NDA_LLADDR:a neighbor cache link layer address
441 NDA_CACHEINFO:cache statistics.
442 .TE
443 .sp 1
444 If the
445 .I rta_type
446 field is
447 .BR NDA_CACHEINFO ,
448 then a
449 .I struct nda_cacheinfo
450 header follows
451 .TP
452 .BR RTM_NEWRULE ", " RTM_DELRULE ", " RTM_GETRULE
453 Add, delete or retrieve a routing rule.
454 Carries a
455 .I struct rtmsg
456 .TP
457 .BR RTM_NEWQDISC ", " RTM_DELQDISC ", " RTM_GETQDISC
458 Add, remove or get a queueing discipline.
459 The message contains a
460 .I struct tcmsg
461 and may be followed by a series of
462 attributes.
463 .IP
464 .EX
465 struct tcmsg {
466 unsigned char tcm_family;
467 int tcm_ifindex; /* interface index */
468 __u32 tcm_handle; /* Qdisc handle */
469 __u32 tcm_parent; /* Parent qdisc */
470 __u32 tcm_info;
471 };
472 .EE
473 .TS
474 tab(:);
475 c s s
476 l2 l2 l.
477 Attributes
478 rta_type:value type:Description
479 _
480 TCA_UNSPEC:-:unspecified
481 TCA_KIND:asciiz string:Name of queueing discipline
482 TCA_OPTIONS:byte sequence:Qdisc-specific options follow
483 TCA_STATS:struct tc_stats:Qdisc statistics.
484 TCA_XSTATS:qdisc-specific:Module-specific statistics.
485 TCA_RATE:struct tc_estimator:Rate limit.
486 .TE
487 .sp 1
488 In addition, various other qdisc-module-specific attributes are allowed.
489 For more information see the appropriate include files.
490 .TP
491 .BR RTM_NEWTCLASS ", " RTM_DELTCLASS ", " RTM_GETTCLASS
492 Add, remove or get a traffic class.
493 These messages contain a
494 .I struct tcmsg
495 as described above.
496 .TP
497 .BR RTM_NEWTFILTER ", " RTM_DELTFILTER ", " RTM_GETTFILTER
498 Add, remove or receive information about a traffic filter.
499 These messages contain a
500 .I struct tcmsg
501 as described above.
502 .SH VERSIONS
503 .B rtnetlink
504 is a new feature of Linux 2.2.
505 .SH BUGS
506 This manual page is incomplete.
507 .SH SEE ALSO
508 .BR cmsg (3),
509 .BR rtnetlink (3),
510 .BR ip (7),
511 .BR netlink (7)