Debian Codegraph @

upstream/debian-unstable/man7/rtnetlink.7

raw
1 '\" t
2 .\" Copyright 1999, Andi Kleen <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-1-para
6 .\"
7 .TH rtnetlink 7 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 rtnetlink \- Linux routing socket
10 .SH SYNOPSIS
11 .nf
12 .B #include <asm/types.h>
13 .B #include <linux/if_link.h>
14 .B #include <linux/netlink.h>
15 .B #include <linux/rtnetlink.h>
16 .B #include <sys/socket.h>
17 .P
18 .BI "rtnetlink_socket = socket(AF_NETLINK, int " socket_type ", NETLINK_ROUTE);"
19 .fi
20 .SH DESCRIPTION
21 Rtnetlink allows the kernel's routing tables to be read and altered.
22 It is used within the kernel to communicate between
23 various subsystems, though this usage is not documented here, and for
24 communication with user-space programs.
25 Network routes, IP addresses, link parameters, neighbor setups, queueing
26 disciplines, traffic classes and packet classifiers may all be controlled
27 through
28 .B NETLINK_ROUTE
29 sockets.
30 It is based on netlink messages;
31 see
32 .BR netlink (7)
33 for more information.
34 .\" FIXME . ? all these macros could be moved to rtnetlink(3)
35 .SS Routing attributes
36 Some rtnetlink messages have optional attributes after the initial header:
37 .P
38 .in +4n
39 .EX
40 struct rtattr {
41 unsigned short rta_len; /* Length of option */
42 unsigned short rta_type; /* Type of option */
43 /* Data follows */
44 };
45 .EE
46 .in
47 .P
48 These attributes should be manipulated using only the RTA_* macros
49 or libnetlink, see
50 .BR rtnetlink (3).
51 .SS Messages
52 Rtnetlink consists of these message types
53 (in addition to standard netlink messages):
54 .TP
55 .B RTM_NEWLINK
56 .TQ
57 .B RTM_DELLINK
58 .TQ
59 .B RTM_GETLINK
60 Create, remove, or get information about a specific network interface.
61 These messages contain an
62 .I ifinfomsg
63 structure followed by a series of
64 .I rtattr
65 structures.
66 .IP
67 .EX
68 struct ifinfomsg {
69 unsigned char ifi_family; /* AF_UNSPEC */
70 unsigned short ifi_type; /* Device type */
71 int ifi_index; /* Interface index */
72 unsigned int ifi_flags; /* Device flags */
73 unsigned int ifi_change; /* change mask */
74 };
75 .EE
76 .IP
77 .\" FIXME Document ifinfomsg.ifi_type
78 .I ifi_flags
79 contains the device flags, see
80 .BR netdevice (7);
81 .I ifi_index
82 is the unique interface index
83 (since Linux 3.7, it is possible to feed a nonzero value with the
84 .B RTM_NEWLINK
85 message, thus creating a link with the given
86 .IR ifindex );
87 .I ifi_change
88 is a mask specifying which bits of
89 .I ifi_flags
90 should be applied to the device.
91 .TS
92 tab(:);
93 c s s
94 lb l l.
95 Routing attributes
96 rta_type:Value type:Description
97 _
98 IFLA_UNSPEC:-:unspecified
99 IFLA_ADDRESS:hardware address:interface L2 address
100 IFLA_BROADCAST:hardware address:L2 broadcast address
101 IFLA_IFNAME:asciiz string:Device name
102 IFLA_MTU:unsigned int:MTU of the device
103 IFLA_LINK:int:Link type
104 IFLA_QDISC:asciiz string:Queueing discipline
105 IFLA_STATS:T{
106 see below
107 T}:Interface Statistics
108 IFLA_PERM_ADDRESS:hardware address:T{
109 hardware address provided by device (since Linux 5.5)
110 T}
111 .TE
112 .IP
113 The value type for
114 .B IFLA_STATS
115 is
116 .I struct rtnl_link_stats
117 .RI ( "struct net_device_stats"
118 in Linux 2.4 and earlier).
119 .TP
120 .B RTM_NEWADDR
121 .TQ
122 .B RTM_DELADDR
123 .TQ
124 .B RTM_GETADDR
125 Add, remove, or receive information about an IP address associated with
126 an interface.
127 In Linux 2.2, an interface can carry multiple IP addresses,
128 this replaces the alias device concept in Linux 2.0.
129 In Linux 2.2, these messages
130 support IPv4 and IPv6 addresses.
131 They contain an
132 .I ifaddrmsg
133 structure, optionally followed by
134 .I rtattr
135 routing attributes.
136 .IP
137 .EX
138 struct ifaddrmsg {
139 unsigned char ifa_family; /* Address type */
140 unsigned char ifa_prefixlen; /* Prefixlength of address */
141 unsigned char ifa_flags; /* Address flags */
142 unsigned char ifa_scope; /* Address scope */
143 unsigned int ifa_index; /* Interface index */
144 };
145 .EE
146 .IP
147 .I ifa_family
148 is the address family type (currently
149 .B AF_INET
150 or
151 .BR AF_INET6 ),
152 .I ifa_prefixlen
153 is the length of the address mask of the address if defined for the
154 family (like for IPv4),
155 .I ifa_scope
156 is the address scope,
157 .I ifa_index
158 is the interface index of the interface the address is associated with.
159 .I ifa_flags
160 is a flag word of
161 .B IFA_F_SECONDARY
162 for secondary address (old alias interface),
163 .B IFA_F_PERMANENT
164 for a permanent address set by the user and other undocumented flags.
165 .TS
166 tab(:);
167 c s s
168 lb l l.
169 Attributes
170 rta_type:Value type:Description
171 _
172 IFA_UNSPEC:-:unspecified
173 IFA_ADDRESS:raw protocol address:interface address
174 IFA_LOCAL:raw protocol address:local address
175 IFA_LABEL:asciiz string:name of the interface
176 IFA_BROADCAST:raw protocol address:broadcast address
177 IFA_ANYCAST:raw protocol address:anycast address
178 IFA_CACHEINFO:struct ifa_cacheinfo:Address information
179 .TE
180 .IP
181 .EX
182 struct ifa_cacheinfo {
183 __u32 ifa_prefered; // Preferred lifetime remaining, in seconds
184 __u32 ifa_valid; // Valid lifetime remaining, in seconds
185 __u32 cstamp; // Creation timestamp, in centiseconds
186 __u32 tstamp; // Update timestamp, in centiseconds
187 };
188 .EE
189 .IP
190 .I ifa_valid
191 cannot be zero, and
192 .I ifa_prefered
193 cannot be greater than
194 .IR ifa_valid .
195 A value of
196 .B UINT32_MAX
197 represents an infinite lifetime.
198 .TP
199 .B RTM_NEWROUTE
200 .TQ
201 .B RTM_DELROUTE
202 .TQ
203 .B RTM_GETROUTE
204 Create, remove, or receive information about a network route.
205 These messages contain an
206 .I rtmsg
207 structure with an optional sequence of
208 .I rtattr
209 structures following.
210 For
211 .BR RTM_GETROUTE ,
212 setting
213 .I rtm_dst_len
214 and
215 .I rtm_src_len
216 to 0 means you get all entries for the specified routing table.
217 For the other fields, except
218 .I rtm_table
219 and
220 .IR rtm_protocol ,
221 0 is the wildcard.
222 .IP
223 .EX
224 struct rtmsg {
225 unsigned char rtm_family; /* Address family of route */
226 unsigned char rtm_dst_len; /* Length of destination */
227 unsigned char rtm_src_len; /* Length of source */
228 unsigned char rtm_tos; /* TOS filter */
229 unsigned char rtm_table; /* Routing table ID;
230 see RTA_TABLE below */
231 unsigned char rtm_protocol; /* Routing protocol; see below */
232 unsigned char rtm_scope; /* See below */
233 unsigned char rtm_type; /* See below */
234 \&
235 unsigned int rtm_flags;
236 };
237 .EE
238 .TS
239 tab(:);
240 lb l.
241 rtm_type:Route type
242 _
243 RTN_UNSPEC:unknown route
244 RTN_UNICAST:a gateway or direct route
245 RTN_LOCAL:a local interface route
246 RTN_BROADCAST:T{
247 a local broadcast route (sent as a broadcast)
248 T}
249 RTN_ANYCAST:T{
250 a local broadcast route (sent as a unicast)
251 T}
252 RTN_MULTICAST:a multicast route
253 RTN_BLACKHOLE:a packet dropping route
254 RTN_UNREACHABLE:an unreachable destination
255 RTN_PROHIBIT:a packet rejection route
256 RTN_THROW:continue routing lookup in another table
257 RTN_NAT:a network address translation rule
258 RTN_XRESOLVE:T{
259 refer to an external resolver (not implemented)
260 T}
261 .TE
262 .TS
263 tab(:);
264 lb l.
265 rtm_protocol:Route origin
266 _
267 RTPROT_UNSPEC:unknown
268 RTPROT_REDIRECT:T{
269 by an ICMP redirect (currently unused)
270 T}
271 RTPROT_KERNEL:by the kernel
272 RTPROT_BOOT:during boot
273 RTPROT_STATIC:by the administrator
274 .TE
275 .IP
276 Values larger than
277 .B RTPROT_STATIC
278 are not interpreted by the kernel, they are just for user information.
279 They may be used to tag the source of a routing information or to
280 distinguish between multiple routing daemons.
281 See
282 .I <linux/rtnetlink.h>
283 for the routing daemon identifiers which are already assigned.
284 .IP
285 .I rtm_scope
286 is the distance to the destination:
287 .TS
288 tab(:);
289 lb l.
290 RT_SCOPE_UNIVERSE:global route
291 RT_SCOPE_SITE:T{
292 interior route in the local autonomous system
293 T}
294 RT_SCOPE_LINK:route on this link
295 RT_SCOPE_HOST:route on the local host
296 RT_SCOPE_NOWHERE:destination doesn't exist
297 .TE
298 .IP
299 The values between
300 .B RT_SCOPE_UNIVERSE
301 and
302 .B RT_SCOPE_SITE
303 are available to the user.
304 .IP
305 The
306 .I rtm_flags
307 have the following meanings:
308 .TS
309 tab(:);
310 lb l.
311 RTM_F_NOTIFY:T{
312 if the route changes, notify the user via rtnetlink
313 T}
314 RTM_F_CLONED:route is cloned from another route
315 RTM_F_EQUALIZE:a multipath equalizer (not yet implemented)
316 .TE
317 .IP
318 .I rtm_table
319 specifies the routing table
320 .TS
321 tab(:);
322 lb l.
323 RT_TABLE_UNSPEC:an unspecified routing table
324 RT_TABLE_DEFAULT:the default table
325 RT_TABLE_MAIN:the main table
326 RT_TABLE_LOCAL:the local table
327 .TE
328 .IP
329 The user may assign arbitrary values between
330 .B RT_TABLE_UNSPEC
331 and
332 .BR RT_TABLE_DEFAULT .
333 .\" Keep table on same page
334 .bp +1
335 .TS
336 tab(:);
337 c s s
338 lb2 l2 l.
339 Attributes
340 rta_type:Value type:Description
341 _
342 RTA_UNSPEC:-:ignored
343 RTA_DST:protocol address:Route destination address
344 RTA_SRC:protocol address:Route source address
345 RTA_IIF:int:Input interface index
346 RTA_OIF:int:Output interface index
347 RTA_GATEWAY:protocol address:The gateway of the route
348 RTA_PRIORITY:int:Priority of route
349 RTA_PREFSRC:protocol address:Preferred source address
350 RTA_METRICS::T{
351 Route metrics
352 .br
353 (see below).
354 T}
355 RTA_MULTIPATH::T{
356 Multipath nexthop data
357 .br
358 (see below).
359 T}
360 RTA_PROTOINFO::No longer used
361 RTA_FLOW:int:Route realm
362 RTA_CACHEINFO:struct rta_cacheinfo:(see linux/rtnetlink.h)
363 RTA_SESSION::No longer used
364 RTA_MP_ALGO::No longer used
365 RTA_TABLE:int:T{
366 Routing table ID;
367 if set,
368 .br
369 rtm_table is ignored
370 T}
371 RTA_MARK:int:
372 RTA_MFC_STATS:struct rta_mfc_stats:(see linux/rtnetlink.h)
373 RTA_VIA:struct rtvia:T{
374 Gateway in different AF
375 (see below)
376 T}
377 RTA_NEWDST:protocol address:T{
378 Change packet
379 destination address
380 T}
381 RTA_PREF:char:T{
382 RFC4191 IPv6 router
383 preference (see below)
384 T}
385 RTA_ENCAP_TYPE:short:T{
386 Encapsulation type for
387 .br
388 lwtunnels (see below)
389 T}
390 RTA_ENCAP::Defined by RTA_ENCAP_TYPE
391 RTA_EXPIRES:int:T{
392 Expire time for IPv6
393 routes (in seconds)
394 T}
395 .TE
396 .IP
397 .B RTA_METRICS
398 contains an array of
399 .I struct rtattr
400 with their corresponding attributes:
401 .RS
402 .IP
403 .TS
404 tab(:);
405 c s s
406 lb l lx.
407 Attributes
408 rta_type:Value type:Description
409 _
410 RTAX_UNSPEC:-:unspecified
411 RTAX_LOCK:__u32:T{
412 Bit field indicating which RTAX_* attributes are locked.
413 T}
414 RTAX_MTU:__u32:T{
415 Maximum Transmission Unit for this route.
416 T}
417 RTAX_WINDOW:__u32:T{
418 Maximum size of the receive window for this route.
419 T}
420 RTAX_RTT:__u32:T{
421 Estimated round-trip time for this route.
422 T}
423 RTAX_RTTVAR:__u32:T{
424 Estimated round-trip time variation for this route.
425 T}
426 RTAX_SSTHRESH:__u32:T{
427 Slow start threshold to use for this route.
428 T}
429 RTAX_CWND:__u32:T{
430 Maximum size of the congestion window for this route.
431 T}
432 RTAX_ADVMSS:__u32:T{
433 Maximum Segment Size to advertise for this route.
434 T}
435 RTAX_REORDERING:__u32:T{
436 Initial reordering level of packets for this route.
437 T}
438 RTAX_HOPLIMIT:__u32:T{
439 Hop limit (TTL) to use for this route.
440 T}
441 RTAX_INITCWND:__u32:T{
442 Initial congestion window to use for this route.
443 T}
444 RTAX_FEATURES:__u32:T{
445 Features to enable for this route specifically.
446 T}
447 RTAX_RTO_MIN:__u32:T{
448 Minimum Retransmission TimeOut to use for this route.
449 T}
450 RTAX_INITRWND:__u32:T{
451 Initial size of the receive window for this route.
452 T}
453 RTAX_QUICKACK:__u32:T{
454 Use quick ack for this route.
455 T}
456 RTAX_CC_ALGO:asciiz string:T{
457 Congestion Control algorithm to use for this route.
458 T}
459 RTAX_FASTOPEN_NO_COOKIE:__u32:T{
460 Allow TCP Fast Open without cookie.
461 T}
462 .TE
463 .RE
464 .IP
465 Metrics that are locked with
466 .B RTAX_LOCK
467 take precedence over the values normally used by the kernel
468 (computed or assigned by a sysctl or setsockopt(2)).
469 Therefore, some metrics, like
470 .BR RTAX_RTO_MIN ,
471 have no effect unless their bit is set in
472 .BR RTAX_LOCK .
473 .IP
474 .B RTA_MULTIPATH
475 contains several packed instances of
476 .I struct rtnexthop
477 together with nested RTAs
478 .RB ( RTA_GATEWAY ):
479 .IP
480 .in +4n
481 .EX
482 struct rtnexthop {
483 unsigned short rtnh_len; /* Length of struct + length
484 of RTAs */
485 unsigned char rtnh_flags; /* Flags (see
486 linux/rtnetlink.h) */
487 unsigned char rtnh_hops; /* Nexthop priority */
488 int rtnh_ifindex; /* Interface index for this
489 nexthop */
490 }
491 .EE
492 .in
493 .IP
494 There exist a bunch of
495 .B RTNH_*
496 macros similar to
497 .B RTA_*
498 and
499 .B NLHDR_*
500 macros
501 useful to handle these structures.
502 .IP
503 .in +4n
504 .EX
505 struct rtvia {
506 unsigned short rtvia_family;
507 unsigned char rtvia_addr[0];
508 };
509 .EE
510 .in
511 .IP
512 .I rtvia_addr
513 is the address,
514 .I rtvia_family
515 is its family type.
516 .IP
517 .B RTA_PREF
518 may contain values
519 .BR ICMPV6_ROUTER_PREF_LOW ,
520 .BR ICMPV6_ROUTER_PREF_MEDIUM ,
521 and
522 .B ICMPV6_ROUTER_PREF_HIGH
523 defined incw
524 .IR <linux/icmpv6.h> .
525 .IP
526 .B RTA_ENCAP_TYPE
527 may contain values
528 .BR LWTUNNEL_ENCAP_MPLS ,
529 .BR LWTUNNEL_ENCAP_IP ,
530 .BR LWTUNNEL_ENCAP_ILA ,
531 or
532 .B LWTUNNEL_ENCAP_IP6
533 defined in
534 .IR <linux/lwtunnel.h> .
535 .IP
536 .B Fill these values in!
537 .TP
538 .B RTM_NEWNEIGH
539 .TQ
540 .B RTM_DELNEIGH
541 .TQ
542 .B RTM_GETNEIGH
543 Add, remove, or receive information about a neighbor table
544 entry (e.g., an ARP entry).
545 The message contains an
546 .I ndmsg
547 structure.
548 .IP
549 .EX
550 struct ndmsg {
551 unsigned char ndm_family;
552 int ndm_ifindex; /* Interface index */
553 __u16 ndm_state; /* State */
554 __u8 ndm_flags; /* Flags */
555 __u8 ndm_type;
556 };
557 \&
558 struct nda_cacheinfo {
559 __u32 ndm_confirmed;
560 __u32 ndm_used;
561 __u32 ndm_updated;
562 __u32 ndm_refcnt;
563 };
564 .EE
565 .IP
566 .I ndm_state
567 is a bit mask of the following states:
568 .TS
569 tab(:);
570 lb l.
571 NUD_INCOMPLETE:a currently resolving cache entry
572 NUD_REACHABLE:a confirmed working cache entry
573 NUD_STALE:an expired cache entry
574 NUD_DELAY:an entry waiting for a timer
575 NUD_PROBE:a cache entry that is currently reprobed
576 NUD_FAILED:an invalid cache entry
577 NUD_NOARP:a device with no destination cache
578 NUD_PERMANENT:a static entry
579 .TE
580 .IP
581 Valid
582 .I ndm_flags
583 are:
584 .TS
585 tab(:);
586 lb l.
587 NTF_PROXY:a proxy arp entry
588 NTF_ROUTER:an IPv6 router
589 .TE
590 .IP
591 .\" FIXME .
592 .\" document the members of the struct better
593 The
594 .I rtattr
595 struct has the following meanings for the
596 .I rta_type
597 field:
598 .TS
599 tab(:);
600 lb l.
601 NDA_UNSPEC:unknown type
602 NDA_DST:a neighbor cache n/w layer destination address
603 NDA_LLADDR:a neighbor cache link layer address
604 NDA_CACHEINFO:cache statistics
605 .TE
606 .IP
607 If the
608 .I rta_type
609 field is
610 .BR NDA_CACHEINFO ,
611 then a
612 .I struct nda_cacheinfo
613 header follows.
614 .TP
615 .B RTM_NEWRULE
616 .TQ
617 .B RTM_DELRULE
618 .TQ
619 .B RTM_GETRULE
620 Add, delete, or retrieve a routing rule.
621 Carries a
622 .I struct rtmsg
623 .TP
624 .B RTM_NEWQDISC
625 .TQ
626 .B RTM_DELQDISC
627 .TQ
628 .B RTM_GETQDISC
629 Add, remove, or get a queueing discipline.
630 The message contains a
631 .I struct tcmsg
632 and may be followed by a series of
633 attributes.
634 .IP
635 .EX
636 struct tcmsg {
637 unsigned char tcm_family;
638 int tcm_ifindex; /* interface index */
639 __u32 tcm_handle; /* Qdisc handle */
640 __u32 tcm_parent; /* Parent qdisc */
641 __u32 tcm_info;
642 };
643 .EE
644 .TS
645 tab(:);
646 c s s
647 lb2 l2 l.
648 Attributes
649 rta_type:Value type:Description
650 _
651 TCA_UNSPEC:-:unspecified
652 TCA_KIND:asciiz string:Name of queueing discipline
653 TCA_OPTIONS:byte sequence:Qdisc-specific options follow
654 TCA_STATS:struct tc_stats:Qdisc statistics
655 TCA_XSTATS:qdisc-specific:Module-specific statistics
656 TCA_RATE:struct tc_estimator:Rate limit
657 .TE
658 .IP
659 In addition, various other qdisc-module-specific attributes are allowed.
660 For more information see the appropriate include files.
661 .TP
662 .B RTM_NEWTCLASS
663 .TQ
664 .B RTM_DELTCLASS
665 .TQ
666 .B RTM_GETTCLASS
667 Add, remove, or get a traffic class.
668 These messages contain a
669 .I struct tcmsg
670 as described above.
671 .TP
672 .B RTM_NEWTFILTER
673 .TQ
674 .B RTM_DELTFILTER
675 .TQ
676 .B RTM_GETTFILTER
677 Add, remove, or receive information about a traffic filter.
678 These messages contain a
679 .I struct tcmsg
680 as described above.
681 .SH VERSIONS
682 .B rtnetlink
683 is a new feature of Linux 2.2.
684 .SH BUGS
685 This manual page is incomplete.
686 .SH SEE ALSO
687 .BR cmsg (3),
688 .BR rtnetlink (3),
689 .BR ip (7),
690 .BR netlink (7)