Many pages: Document fixed-width types with ISO C naming
[man-pages.git] / man7 / rtnetlink.7
blob21d5f9220537d5bed08018425f9d6fdbbc0ad3f4
1 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
2 .\"
3 .\" %%%LICENSE_START(VERBATIM_ONE_PARA)
4 .\" Permission is granted to distribute possibly modified copies
5 .\" of this page provided the header is included verbatim,
6 .\" and in case of nontrivial modification author and date
7 .\" of the modification is added to the header.
8 .\" %%%LICENSE_END
9 .\"
10 .\" Based on the original comments from Alexey Kuznetsov, written with
11 .\" help from Matthew Wilcox.
12 .\" $Id: rtnetlink.7,v 1.8 2000/01/22 01:55:04 freitag Exp $
13 .\"
14 .TH RTNETLINK  7 2021-03-22 "Linux man-pages (unreleased)"
15 .SH NAME
16 rtnetlink \- Linux routing socket
17 .SH SYNOPSIS
18 .nf
19 .B #include <asm/types.h>
20 .B #include <linux/netlink.h>
21 .B #include <linux/rtnetlink.h>
22 .B #include <sys/socket.h>
23 .PP
24 .BI "rtnetlink_socket = socket(AF_NETLINK, int " socket_type ", NETLINK_ROUTE);"
25 .fi
26 .SH DESCRIPTION
27 Rtnetlink allows the kernel's routing tables to be read and altered.
28 It is used within the kernel to communicate between
29 various subsystems, though this usage is not documented here, and for
30 communication with user-space programs.
31 Network routes, IP addresses, link parameters, neighbor setups, queueing
32 disciplines, traffic classes and packet classifiers may all be controlled
33 through
34 .B NETLINK_ROUTE
35 sockets.
36 It is based on netlink messages; see
37 .BR netlink (7)
38 for more information.
39 .\" FIXME . ? all these macros could be moved to rtnetlink(3)
40 .SS Routing attributes
41 Some rtnetlink messages have optional attributes after the initial header:
42 .PP
43 .in +4n
44 .EX
45 struct rtattr {
46     unsigned short rta_len;    /* Length of option */
47     unsigned short rta_type;   /* Type of option */
48     /* Data follows */
50 .EE
51 .in
52 .PP
53 These attributes should be manipulated using only the RTA_* macros
54 or libnetlink, see
55 .BR rtnetlink (3).
56 .SS Messages
57 Rtnetlink consists of these message types
58 (in addition to standard netlink messages):
59 .TP
60 .BR RTM_NEWLINK ", " RTM_DELLINK ", " RTM_GETLINK
61 Create, remove, or get information about a specific network interface.
62 These messages contain an
63 .I ifinfomsg
64 structure followed by a series of
65 .I rtattr
66 structures.
67 .IP
68 .EX
69 struct ifinfomsg {
70     unsigned char  ifi_family; /* AF_UNSPEC */
71     unsigned short ifi_type;   /* Device type */
72     int            ifi_index;  /* Interface index */
73     unsigned int   ifi_flags;  /* Device flags  */
74     unsigned int   ifi_change; /* change mask */
76 .EE
77 .IP
78 .\" FIXME Document ifinfomsg.ifi_type
79 .I ifi_flags
80 contains the device flags, see
81 .BR netdevice (7);
82 .I ifi_index
83 is the unique interface index
84 (since Linux 3.7, it is possible to feed a nonzero value with the
85 .B RTM_NEWLINK
86 message, thus creating a link with the given
87 .IR ifindex );
88 .I ifi_change
89 is reserved for future use and should be always set to 0xFFFFFFFF.
90 .TS
91 tab(:);
92 c s s
93 lb l l.
94 Routing attributes
95 rta_type:Value type:Description
97 IFLA_UNSPEC:-:unspecified
98 IFLA_ADDRESS:hardware address:interface L2 address
99 IFLA_BROADCAST:hardware address:L2 broadcast address
100 IFLA_IFNAME:asciiz string:Device name
101 IFLA_MTU:unsigned int:MTU of the device
102 IFLA_LINK:int:Link type
103 IFLA_QDISC:asciiz string:Queueing discipline
104 IFLA_STATS:T{
105 see below
106 T}:Interface Statistics
109 The value type for
110 .B IFLA_STATS
112 .I struct rtnl_link_stats
113 .RI ( "struct net_device_stats"
114 in Linux 2.4 and earlier).
116 .BR RTM_NEWADDR ", " RTM_DELADDR ", " RTM_GETADDR
117 Add, remove, or receive information about an IP address associated with
118 an interface.
119 In Linux 2.2, an interface can carry multiple IP addresses,
120 this replaces the alias device concept in 2.0.
121 In Linux 2.2, these messages
122 support IPv4 and IPv6 addresses.
123 They contain an
124 .I ifaddrmsg
125 structure, optionally followed by
126 .I rtattr
127 routing attributes.
130 struct ifaddrmsg {
131     unsigned char ifa_family;    /* Address type */
132     unsigned char ifa_prefixlen; /* Prefixlength of address */
133     unsigned char ifa_flags;     /* Address flags */
134     unsigned char ifa_scope;     /* Address scope */
135     unsigned int  ifa_index;     /* Interface index */
139 .I ifa_family
140 is the address family type (currently
141 .B AF_INET
143 .BR AF_INET6 ),
144 .I ifa_prefixlen
145 is the length of the address mask of the address if defined for the
146 family (like for IPv4),
147 .I ifa_scope
148 is the address scope,
149 .I ifa_index
150 is the interface index of the interface the address is associated with.
151 .I ifa_flags
152 is a flag word of
153 .B IFA_F_SECONDARY
154 for secondary address (old alias interface),
155 .B IFA_F_PERMANENT
156 for a permanent address set by the user and other undocumented flags.
158 tab(:);
159 c s s
160 lb l l.
161 Attributes
162 rta_type:Value type:Description
164 IFA_UNSPEC:-:unspecified
165 IFA_ADDRESS:raw protocol address:interface address
166 IFA_LOCAL:raw protocol address:local address
167 IFA_LABEL:asciiz string:name of the interface
168 IFA_BROADCAST:raw protocol address:broadcast address
169 IFA_ANYCAST:raw protocol address:anycast address
170 IFA_CACHEINFO:struct ifa_cacheinfo:Address information
172 .\" FIXME Document struct ifa_cacheinfo
174 .BR RTM_NEWROUTE ", " RTM_DELROUTE ", " RTM_GETROUTE
175 Create, remove, or receive information about a network route.
176 These messages contain an
177 .I rtmsg
178 structure with an optional sequence of
179 .I rtattr
180 structures following.
182 .BR RTM_GETROUTE ,
183 setting
184 .I rtm_dst_len
186 .I rtm_src_len
187 to 0 means you get all entries for the specified routing table.
188 For the other fields, except
189 .I rtm_table
191 .IR rtm_protocol ,
192 0 is the wildcard.
195 struct rtmsg {
196     unsigned char rtm_family;   /* Address family of route */
197     unsigned char rtm_dst_len;  /* Length of destination */
198     unsigned char rtm_src_len;  /* Length of source */
199     unsigned char rtm_tos;      /* TOS filter */
200     unsigned char rtm_table;    /* Routing table ID;
201                                    see RTA_TABLE below */
202     unsigned char rtm_protocol; /* Routing protocol; see below */
203     unsigned char rtm_scope;    /* See below */
204     unsigned char rtm_type;     /* See below */
206     unsigned int  rtm_flags;
210 tab(:);
211 lb l.
212 rtm_type:Route type
214 RTN_UNSPEC:unknown route
215 RTN_UNICAST:a gateway or direct route
216 RTN_LOCAL:a local interface route
217 RTN_BROADCAST:T{
218 a local broadcast route (sent as a broadcast)
220 RTN_ANYCAST:T{
221 a local broadcast route (sent as a unicast)
223 RTN_MULTICAST:a multicast route
224 RTN_BLACKHOLE:a packet dropping route
225 RTN_UNREACHABLE:an unreachable destination
226 RTN_PROHIBIT:a packet rejection route
227 RTN_THROW:continue routing lookup in another table
228 RTN_NAT:a network address translation rule
229 RTN_XRESOLVE:T{
230 refer to an external resolver (not implemented)
234 tab(:);
235 lb l.
236 rtm_protocol:Route origin
238 RTPROT_UNSPEC:unknown
239 RTPROT_REDIRECT:T{
240 by an ICMP redirect (currently unused)
242 RTPROT_KERNEL:by the kernel
243 RTPROT_BOOT:during boot
244 RTPROT_STATIC:by the administrator
246 .sp 1
247 Values larger than
248 .B RTPROT_STATIC
249 are not interpreted by the kernel, they are just for user information.
250 They may be used to tag the source of a routing information or to
251 distinguish between multiple routing daemons.
253 .I <linux/rtnetlink.h>
254 for the routing daemon identifiers which are already assigned.
256 .I rtm_scope
257 is the distance to the destination:
259 tab(:);
260 lb l.
261 RT_SCOPE_UNIVERSE:global route
262 RT_SCOPE_SITE:T{
263 interior route in the local autonomous system
265 RT_SCOPE_LINK:route on this link
266 RT_SCOPE_HOST:route on the local host
267 RT_SCOPE_NOWHERE:destination doesn't exist
269 .sp 1
270 The values between
271 .B RT_SCOPE_UNIVERSE
273 .B RT_SCOPE_SITE
274 are available to the user.
277 .I rtm_flags
278 have the following meanings:
280 tab(:);
281 lb l.
282 RTM_F_NOTIFY:T{
283 if the route changes, notify the user via rtnetlink
285 RTM_F_CLONED:route is cloned from another route
286 RTM_F_EQUALIZE:a multipath equalizer (not yet implemented)
288 .sp 1
289 .I rtm_table
290 specifies the routing table
292 tab(:);
293 lb l.
294 RT_TABLE_UNSPEC:an unspecified routing table
295 RT_TABLE_DEFAULT:the default table
296 RT_TABLE_MAIN:the main table
297 RT_TABLE_LOCAL:the local table
299 .sp 1
300 The user may assign arbitrary values between
301 .B RT_TABLE_UNSPEC
303 .BR RT_TABLE_DEFAULT .
304 .\" Keep table on same page
305 .bp +1
307 tab(:);
308 c s s
309 lb2 l2 l.
310 Attributes
311 rta_type:Value type:Description
313 RTA_UNSPEC:-:ignored
314 RTA_DST:protocol address:Route destination address
315 RTA_SRC:protocol address:Route source address
316 RTA_IIF:int:Input interface index
317 RTA_OIF:int:Output interface index
318 RTA_GATEWAY:protocol address:The gateway of the route
319 RTA_PRIORITY:int:Priority of route
320 RTA_PREFSRC:protocol address:Preferred source address
321 RTA_METRICS:int:Route metric
322 RTA_MULTIPATH::T{
323 Multipath nexthop data
325 (see below).
327 RTA_PROTOINFO::No longer used
328 RTA_FLOW:int:Route realm
329 RTA_CACHEINFO:struct rta_cacheinfo:(see linux/rtnetlink.h)
330 RTA_SESSION::No longer used
331 RTA_MP_ALGO::No longer used
332 RTA_TABLE:int:T{
333 Routing table ID; if set,
335 rtm_table is ignored
337 RTA_MARK:int:
338 RTA_MFC_STATS:struct rta_mfc_stats:(see linux/rtnetlink.h)
339 RTA_VIA:struct rtvia:T{
340 Gateway in different AF
341 (see below)
343 RTA_NEWDST:protocol address:T{
344 Change packet
345 destination address
347 RTA_PREF:char:T{
348 RFC4191 IPv6 router
349 preference (see below)
351 RTA_ENCAP_TYPE:short:T{
352 Encapsulation type for
354 lwtunnels (see below)
356 RTA_ENCAP::Defined by RTA_ENCAP_TYPE
357 RTA_EXPIRES:int:T{
358 Expire time for IPv6
359 routes (in seconds)
363 .B RTA_MULTIPATH
364 contains several packed instances of
365 .I struct rtnexthop
366 together with nested RTAs
367 .RB ( RTA_GATEWAY ):
369 .in +4n
371 struct rtnexthop {
372     unsigned short rtnh_len;     /* Length of struct + length
373                                     of RTAs */
374     unsigned char  rtnh_flags;   /* Flags (see
375                                     linux/rtnetlink.h) */
376     unsigned char  rtnh_hops;    /* Nexthop priority */
377     int            rtnh_ifindex; /* Interface index for this
378                                     nexthop */
383 There exist a bunch of
384 .B RTNH_*
385 macros similar to
386 .B RTA_*
388 .B NLHDR_*
389 macros
390 useful to handle these structures.
392 .in +4n
394 struct rtvia {
395     unsigned short rtvia_family;
396     unsigned char  rtvia_addr[0];
401 .I rtvia_addr
402 is the address,
403 .I rtvia_family
404 is its family type.
406 .B RTA_PREF
407 may contain values
408 .BR ICMPV6_ROUTER_PREF_LOW ,
409 .BR ICMPV6_ROUTER_PREF_MEDIUM ,
411 .B ICMPV6_ROUTER_PREF_HIGH
412 defined incw
413 .IR <linux/icmpv6.h> .
415 .B RTA_ENCAP_TYPE
416 may contain values
417 .BR LWTUNNEL_ENCAP_MPLS ,
418 .BR LWTUNNEL_ENCAP_IP ,
419 .BR LWTUNNEL_ENCAP_ILA ,
421 .B LWTUNNEL_ENCAP_IP6
422 defined in
423 .IR <linux/lwtunnel.h> .
425 .B Fill these values in!
427 .BR RTM_NEWNEIGH ", " RTM_DELNEIGH  ", " RTM_GETNEIGH
428 Add, remove, or receive information about a neighbor table
429 entry (e.g., an ARP entry).
430 The message contains an
431 .I ndmsg
432 structure.
435 struct ndmsg {
436     unsigned char ndm_family;
437     int           ndm_ifindex;  /* Interface index */
438     uint16_t      ndm_state;    /* State */
439     uint8_t       ndm_flags;    /* Flags */
440     uint8_t       ndm_type;
443 struct nda_cacheinfo {
444     uint32_t      ndm_confirmed;
445     uint32_t      ndm_used;
446     uint32_t      ndm_updated;
447     uint32_t      ndm_refcnt;
451 .I ndm_state
452 is a bit mask of the following states:
454 tab(:);
455 lb l.
456 NUD_INCOMPLETE:a currently resolving cache entry
457 NUD_REACHABLE:a confirmed working cache entry
458 NUD_STALE:an expired cache entry
459 NUD_DELAY:an entry waiting for a timer
460 NUD_PROBE:a cache entry that is currently reprobed
461 NUD_FAILED:an invalid cache entry
462 NUD_NOARP:a device with no destination cache
463 NUD_PERMANENT:a static entry
465 .sp 1
466 Valid
467 .I ndm_flags
468 are:
470 tab(:);
471 lb l.
472 NTF_PROXY:a proxy arp entry
473 NTF_ROUTER:an IPv6 router
475 .sp 1
476 .\" FIXME .
477 .\" document the members of the struct better
479 .I rtattr
480 struct has the following meanings for the
481 .I rta_type
482 field:
484 tab(:);
485 lb l.
486 NDA_UNSPEC:unknown type
487 NDA_DST:a neighbor cache n/w layer destination address
488 NDA_LLADDR:a neighbor cache link layer address
489 NDA_CACHEINFO:cache statistics
491 .sp 1
492 If the
493 .I rta_type
494 field is
495 .BR NDA_CACHEINFO ,
496 then a
497 .I struct nda_cacheinfo
498 header follows.
500 .BR RTM_NEWRULE ", " RTM_DELRULE ", " RTM_GETRULE
501 Add, delete, or retrieve a routing rule.
502 Carries a
503 .I struct rtmsg
505 .BR RTM_NEWQDISC ", " RTM_DELQDISC ", " RTM_GETQDISC
506 Add, remove, or get a queueing discipline.
507 The message contains a
508 .I struct tcmsg
509 and may be followed by a series of
510 attributes.
513 struct tcmsg {
514     unsigned char    tcm_family;
515     int              tcm_ifindex;   /* interface index */
516     uint32_t         tcm_handle;    /* Qdisc handle */
517     uint32_t         tcm_parent;    /* Parent qdisc */
518     uint32_t         tcm_info;
522 tab(:);
523 c s s
524 lb2 l2 l.
525 Attributes
526 rta_type:Value type:Description
528 TCA_UNSPEC:-:unspecified
529 TCA_KIND:asciiz string:Name of queueing discipline
530 TCA_OPTIONS:byte sequence:Qdisc-specific options follow
531 TCA_STATS:struct tc_stats:Qdisc statistics
532 TCA_XSTATS:qdisc-specific:Module-specific statistics
533 TCA_RATE:struct tc_estimator:Rate limit
535 .sp 1
536 In addition, various other qdisc-module-specific attributes are allowed.
537 For more information see the appropriate include files.
539 .BR RTM_NEWTCLASS ", " RTM_DELTCLASS ", " RTM_GETTCLASS
540 Add, remove, or get a traffic class.
541 These messages contain a
542 .I struct tcmsg
543 as described above.
545 .BR RTM_NEWTFILTER ", " RTM_DELTFILTER ", " RTM_GETTFILTER
546 Add, remove, or receive information about a traffic filter.
547 These messages contain a
548 .I struct tcmsg
549 as described above.
550 .SH VERSIONS
551 .B rtnetlink
552 is a new feature of Linux 2.2.
553 .SH BUGS
554 This manual page is incomplete.
555 .SH SEE ALSO
556 .BR cmsg (3),
557 .BR rtnetlink (3),
558 .BR ip (7),
559 .BR netlink (7)