2 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
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.
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 $
15 .TH RTNETLINK 7 2020-02-09 "Linux" "Linux Programmer's Manual"
17 rtnetlink \- Linux IPv4 routing socket
19 .B #include <asm/types.h>
21 .B #include <linux/netlink.h>
23 .B #include <linux/rtnetlink.h>
25 .B #include <sys/socket.h>
27 .BI "rtnetlink_socket = socket(AF_NETLINK, int " socket_type ", NETLINK_ROUTE);"
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
38 It is based on netlink messages; see
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:
48 unsigned short rta_len; /* Length of option */
49 unsigned short rta_type; /* Type of option */
55 These attributes should be manipulated using only the RTA_* macros
59 Rtnetlink consists of these message types
60 (in addition to standard netlink messages):
62 .BR RTM_NEWLINK ", " RTM_DELLINK ", " RTM_GETLINK
63 Create, remove or get information about a specific network interface.
64 These messages contain an
66 structure followed by a series of
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 */
80 .\" FIXME Document ifinfomsg.ifi_type
82 contains the device flags, see
85 is the unique interface index
86 (since Linux 3.7, it is possible to feed a nonzero value with the
88 message, thus creating a link with the given
91 is reserved for future use and should be always set to 0xFFFFFFFF.
97 rta_type:value type:description
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.
108 T}:Interface Statistics.
114 .IR "struct rtnl_link_stats"
115 .RI ( "struct net_device_stats"
116 in Linux 2.4 and earlier).
118 .BR RTM_NEWADDR ", " RTM_DELADDR ", " RTM_GETADDR
119 Add, remove or receive information about an IP address associated with
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.
127 structure, optionally followed by
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 */
142 is the address family type (currently
147 is the length of the address mask of the address if defined for the
148 family (like for IPv4),
150 is the address scope,
152 is the interface index of the interface the address is associated with.
156 for secondary address (old alias interface),
158 for a permanent address set by the user and other undocumented flags.
164 rta_type:value type:description
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.
174 .\" FIXME Document struct ifa_cacheinfo
176 .BR RTM_NEWROUTE ", " RTM_DELROUTE ", " RTM_GETROUTE
177 Create, remove or receive information about a network route.
178 These messages contain an
180 structure with an optional sequence of
182 structures following.
189 to 0 means you get all entries for the specified routing table.
190 For the other fields, except
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 unsigned char rtm_table; /* Routing table ID;
203 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 */
208 unsigned int rtm_flags;
216 RTN_UNSPEC:unknown route
217 RTN_UNICAST:a gateway or direct route
218 RTN_LOCAL:a local interface route
220 a local broadcast route (sent as a broadcast)
223 a local broadcast route (sent as a unicast)
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
232 refer to an external resolver (not implemented)
238 rtm_protocol:Route origin.
240 RTPROT_UNSPEC:unknown
242 by an ICMP redirect (currently unused)
244 RTPROT_KERNEL:by the kernel
245 RTPROT_BOOT:during boot
246 RTPROT_STATIC:by the administrator
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.
255 .I <linux/rtnetlink.h>
256 for the routing daemon identifiers which are already assigned.
259 is the distance to the destination:
263 RT_SCOPE_UNIVERSE:global route
265 interior route in the local autonomous system
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
276 are available to the user.
280 have the following meanings:
285 if the route changes, notify the user via rtnetlink
287 RTM_F_CLONED:route is cloned from another route
288 RTM_F_EQUALIZE:a multipath equalizer (not yet implemented)
292 specifies the routing table
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
302 The user may assign arbitrary values between
305 .BR RT_TABLE_DEFAULT .
306 .\" Keep table on same page
313 rta_type:value type:description
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
325 Multipath nexthop data
329 RTA_PROTOINFO::No longer used
330 RTA_FLOW:int:Route realm
331 RTA_CACHEINFO:struct rta_cacheinfo:(see linux/rtnetlink.h)
332 RTA_SESSION::No longer used
333 RTA_MP_ALGO::No longer used
335 Routing table ID; if set,
340 RTA_MFC_STATS:struct rta_mfc_stats:(see linux/rtnetlink.h)
341 RTA_VIA:struct rtvia:T{
342 Gateway in different AF
345 RTA_NEWDST:protocol address:T{
351 preference (see below)
353 RTA_ENCAP_TYPE:short:T{
354 Encapsulation type for
356 lwtunnels (see below)
358 RTA_ENCAP::Defined by RTA_ENCAP_TYPE
366 contains several packed instances of
368 together with nested RTAs
374 unsigned short rtnh_len; /* Length of struct + length
376 unsigned char rtnh_flags; /* Flags (see linux/rtnetlink.h) */
377 unsigned char rtnh_hops; /* Nexthop priority */
378 int rtnh_ifindex; /* Interface index for this
384 There exist a bunch of RTNH_* macros similar to RTA_* and NLHDR_* macros
385 useful to handle these structures.
391 unsigned short rtvia_family;
392 unsigned char rtvia_addr[0];
403 may contain values ICMPV6_ROUTER_PREF_LOW,
404 ICMPV6_ROUTER_PREF_MEDIUM and
405 ICMPV6_ROUTER_PREF_HIGH defined in <linux/icmpv6.h>
409 LWTUNNEL_ENCAP_MPLS, LWTUNNEL_ENCAP_IP,
410 LWTUNNEL_ENCAP_ILA or LWTUNNEL_ENCAP_IP6
411 defined in <linux/lwtunnel.h>.
413 .B Fill these values in!
415 .BR RTM_NEWNEIGH ", " RTM_DELNEIGH ", " RTM_GETNEIGH
416 Add, remove or receive information about a neighbor table
417 entry (e.g., an ARP entry).
418 The message contains an
424 unsigned char ndm_family;
425 int ndm_ifindex; /* Interface index */
426 __u16 ndm_state; /* State */
427 __u8 ndm_flags; /* Flags */
431 struct nda_cacheinfo {
440 is a bit mask of the following states:
444 NUD_INCOMPLETE:a currently resolving cache entry
445 NUD_REACHABLE:a confirmed working cache entry
446 NUD_STALE:an expired cache entry
447 NUD_DELAY:an entry waiting for a timer
448 NUD_PROBE:a cache entry that is currently reprobed
449 NUD_FAILED:an invalid cache entry
450 NUD_NOARP:a device with no destination cache
451 NUD_PERMANENT:a static entry
460 NTF_PROXY:a proxy arp entry
461 NTF_ROUTER:an IPv6 router
465 .\" document the members of the struct better
468 struct has the following meanings for the
474 NDA_UNSPEC:unknown type
475 NDA_DST:a neighbor cache n/w layer destination address
476 NDA_LLADDR:a neighbor cache link layer address
477 NDA_CACHEINFO:cache statistics.
485 .I struct nda_cacheinfo
488 .BR RTM_NEWRULE ", " RTM_DELRULE ", " RTM_GETRULE
489 Add, delete or retrieve a routing rule.
493 .BR RTM_NEWQDISC ", " RTM_DELQDISC ", " RTM_GETQDISC
494 Add, remove or get a queueing discipline.
495 The message contains a
497 and may be followed by a series of
502 unsigned char tcm_family;
503 int tcm_ifindex; /* interface index */
504 __u32 tcm_handle; /* Qdisc handle */
505 __u32 tcm_parent; /* Parent qdisc */
514 rta_type:value type:Description
516 TCA_UNSPEC:-:unspecified
517 TCA_KIND:asciiz string:Name of queueing discipline
518 TCA_OPTIONS:byte sequence:Qdisc-specific options follow
519 TCA_STATS:struct tc_stats:Qdisc statistics.
520 TCA_XSTATS:qdisc-specific:Module-specific statistics.
521 TCA_RATE:struct tc_estimator:Rate limit.
524 In addition, various other qdisc-module-specific attributes are allowed.
525 For more information see the appropriate include files.
527 .BR RTM_NEWTCLASS ", " RTM_DELTCLASS ", " RTM_GETTCLASS
528 Add, remove or get a traffic class.
529 These messages contain a
533 .BR RTM_NEWTFILTER ", " RTM_DELTFILTER ", " RTM_GETTFILTER
534 Add, remove or receive information about a traffic filter.
535 These messages contain a
540 is a new feature of Linux 2.2.
542 This manual page is incomplete.