1rtnetlink(7)           Miscellaneous Information Manual           rtnetlink(7)
2
3
4

NAME

6       rtnetlink - Linux routing socket
7

SYNOPSIS

9       #include <asm/types.h>
10       #include <linux/netlink.h>
11       #include <linux/rtnetlink.h>
12       #include <sys/socket.h>
13
14       rtnetlink_socket = socket(AF_NETLINK, int socket_type, NETLINK_ROUTE);
15

DESCRIPTION

17       Rtnetlink  allows  the  kernel's routing tables to be read and altered.
18       It is used within the kernel to communicate between various subsystems,
19       though  this  usage  is not documented here, and for communication with
20       user-space programs.  Network routes, IP  addresses,  link  parameters,
21       neighbor setups, queueing disciplines, traffic classes and packet clas‐
22       sifiers may all be controlled through  NETLINK_ROUTE  sockets.   It  is
23       based on netlink messages; see netlink(7) for more information.
24
25   Routing attributes
26       Some  rtnetlink  messages  have  optional  attributes after the initial
27       header:
28
29           struct rtattr {
30               unsigned short rta_len;    /* Length of option */
31               unsigned short rta_type;   /* Type of option */
32               /* Data follows */
33           };
34
35       These attributes should be manipulated using only the RTA_*  macros  or
36       libnetlink, see rtnetlink(3).
37
38   Messages
39       Rtnetlink  consists  of  these  message  types (in addition to standard
40       netlink messages):
41
42       RTM_NEWLINK, RTM_DELLINK, RTM_GETLINK
43              Create, remove, or get information about a specific network  in‐
44              terface.  These messages contain an ifinfomsg structure followed
45              by a series of rtattr structures.
46
47              struct ifinfomsg {
48                  unsigned char  ifi_family; /* AF_UNSPEC */
49                  unsigned short ifi_type;   /* Device type */
50                  int            ifi_index;  /* Interface index */
51                  unsigned int   ifi_flags;  /* Device flags  */
52                  unsigned int   ifi_change; /* change mask */
53              };
54
55              ifi_flags contains the device flags, see netdevice(7); ifi_index
56              is  the  unique interface index (since Linux 3.7, it is possible
57              to feed a nonzero value with the RTM_NEWLINK message, thus  cre‐
58              ating a link with the given ifindex); ifi_change is reserved for
59              future use and should be always set to 0xFFFFFFFF.
60
61                                  Routing attributes
62              rta_type            Value type         Description
63              ────────────────────────────────────────────────────────────
64              IFLA_UNSPEC         -                  unspecified
65              IFLA_ADDRESS        hardware address   interface L2 address
66
67              IFLA_BROADCAST      hardware address   L2 broadcast address
68              IFLA_IFNAME         asciiz string      Device name
69              IFLA_MTU            unsigned int       MTU of the device
70              IFLA_LINK           int                Link type
71              IFLA_QDISC          asciiz string      Queueing discipline
72              IFLA_STATS          see below          Interface Statistics
73              IFLA_PERM_ADDRESS   hardware address   hardware     address
74                                                     provided  by  device
75                                                     (since Linux 5.5)
76
77              The value type for IFLA_STATS is struct rtnl_link_stats  (struct
78              net_device_stats in Linux 2.4 and earlier).
79
80       RTM_NEWADDR, RTM_DELADDR, RTM_GETADDR
81              Add,  remove, or receive information about an IP address associ‐
82              ated with an interface.  In Linux 2.2, an  interface  can  carry
83              multiple IP addresses, this replaces the alias device concept in
84              Linux 2.0.  In Linux 2.2, these messages support IPv4  and  IPv6
85              addresses.  They contain an ifaddrmsg structure, optionally fol‐
86              lowed by rtattr routing attributes.
87
88              struct ifaddrmsg {
89                  unsigned char ifa_family;    /* Address type */
90                  unsigned char ifa_prefixlen; /* Prefixlength of address */
91                  unsigned char ifa_flags;     /* Address flags */
92                  unsigned char ifa_scope;     /* Address scope */
93                  unsigned int  ifa_index;     /* Interface index */
94              };
95
96              ifa_family is the address  family  type  (currently  AF_INET  or
97              AF_INET6),  ifa_prefixlen  is  the length of the address mask of
98              the address if defined for the family (like for IPv4), ifa_scope
99              is  the  address  scope, ifa_index is the interface index of the
100              interface the address is associated with.  ifa_flags is  a  flag
101              word  of IFA_F_SECONDARY for secondary address (old alias inter‐
102              face), IFA_F_PERMANENT for a permanent address set by  the  user
103              and other undocumented flags.
104
105                                       Attributes
106              rta_type        Value type             Description
107              ─────────────────────────────────────────────────────────────
108              IFA_UNSPEC      -                      unspecified
109              IFA_ADDRESS     raw protocol address   interface address
110              IFA_LOCAL       raw protocol address   local address
111              IFA_LABEL       asciiz string          name of the interface
112              IFA_BROADCAST   raw protocol address   broadcast address
113              IFA_ANYCAST     raw protocol address   anycast address
114              IFA_CACHEINFO   struct ifa_cacheinfo   Address information
115
116       RTM_NEWROUTE, RTM_DELROUTE, RTM_GETROUTE
117              Create,  remove,  or  receive information about a network route.
118              These messages contain an rtmsg structure with an  optional  se‐
119              quence  of  rtattr structures following.  For RTM_GETROUTE, set‐
120              ting rtm_dst_len and rtm_src_len to 0 means you get all  entries
121              for  the  specified routing table.  For the other fields, except
122              rtm_table and rtm_protocol, 0 is the wildcard.
123
124              struct rtmsg {
125                  unsigned char rtm_family;   /* Address family of route */
126                  unsigned char rtm_dst_len;  /* Length of destination */
127                  unsigned char rtm_src_len;  /* Length of source */
128                  unsigned char rtm_tos;      /* TOS filter */
129                  unsigned char rtm_table;    /* Routing table ID;
130                                                 see RTA_TABLE below */
131                  unsigned char rtm_protocol; /* Routing protocol; see below */
132                  unsigned char rtm_scope;    /* See below */
133                  unsigned char rtm_type;     /* See below */
134
135                  unsigned int  rtm_flags;
136              };
137
138              rtm_type          Route type
139              ───────────────────────────────────────────────────────────
140              RTN_UNSPEC        unknown route
141              RTN_UNICAST       a gateway or direct route
142              RTN_LOCAL         a local interface route
143              RTN_BROADCAST     a  local  broadcast  route  (sent  as  a
144                                broadcast)
145              RTN_ANYCAST       a  local broadcast route (sent as a uni‐
146                                cast)
147              RTN_MULTICAST     a multicast route
148              RTN_BLACKHOLE     a packet dropping route
149              RTN_UNREACHABLE   an unreachable destination
150              RTN_PROHIBIT      a packet rejection route
151              RTN_THROW         continue routing lookup in another table
152              RTN_NAT           a network address translation rule
153              RTN_XRESOLVE      refer to an external resolver  (not  im‐
154                                plemented)
155
156              rtm_protocol      Route origin
157              ─────────────────────────────────────────────
158              RTPROT_UNSPEC     unknown
159              RTPROT_REDIRECT   by  an ICMP redirect (cur‐
160                                rently unused)
161              RTPROT_KERNEL     by the kernel
162              RTPROT_BOOT       during boot
163              RTPROT_STATIC     by the administrator
164
165              Values larger than RTPROT_STATIC are not interpreted by the ker‐
166              nel,  they  are  just for user information.  They may be used to
167              tag the source of a routing information or  to  distinguish  be‐
168              tween multiple routing daemons.  See <linux/rtnetlink.h> for the
169              routing daemon identifiers which are already assigned.
170
171              rtm_scope is the distance to the destination:
172
173              RT_SCOPE_UNIVERSE   global route
174              RT_SCOPE_SITE       interior route in the  lo‐
175                                  cal autonomous system
176              RT_SCOPE_LINK       route on this link
177              RT_SCOPE_HOST       route on the local host
178              RT_SCOPE_NOWHERE    destination doesn't exist
179
180              The  values  between  RT_SCOPE_UNIVERSE  and  RT_SCOPE_SITE  are
181              available to the user.
182
183              The rtm_flags have the following meanings:
184
185              RTM_F_NOTIFY     if the route changes, notify the  user  via
186                               rtnetlink
187              RTM_F_CLONED     route is cloned from another route
188              RTM_F_EQUALIZE   a multipath equalizer (not yet implemented)
189
190              rtm_table specifies the routing table
191
192              RT_TABLE_UNSPEC    an unspecified routing table
193              RT_TABLE_DEFAULT   the default table
194              RT_TABLE_MAIN      the main table
195              RT_TABLE_LOCAL     the local table
196
197              The user may assign arbitrary values between RT_TABLE_UNSPEC and
198              RT_TABLE_DEFAULT.
199                                        Attributes
200              rta_type        Value type            Description
201              ────────────────────────────────────────────────────────────────
202              RTA_UNSPEC      -                     ignored
203              RTA_DST         protocol address      Route destination address
204              RTA_SRC         protocol address      Route source address
205              RTA_IIF         int                   Input interface index
206              RTA_OIF         int                   Output interface index
207              RTA_GATEWAY     protocol address      The gateway of the route
208              RTA_PRIORITY    int                   Priority of route
209              RTA_PREFSRC     protocol address      Preferred source address
210              RTA_METRICS     int                   Route metric
211              RTA_MULTIPATH                         Multipath nexthop data br
212                                                    (see below).
213              RTA_PROTOINFO                         No longer used
214              RTA_FLOW        int                   Route realm
215              RTA_CACHEINFO   struct rta_cacheinfo  (see linux/rtnetlink.h)
216              RTA_SESSION                           No longer used
217              RTA_MP_ALGO                           No longer used
218              RTA_TABLE       int                   Routing table ID; if set,
219                                                    rtm_table is ignored
220              RTA_MARK        int
221              RTA_MFC_STATS   struct rta_mfc_stats  (see linux/rtnetlink.h)
222              RTA_VIA         struct rtvia          Gateway  in  different AF
223                                                    (see below)
224              RTA_NEWDST      protocol address      Change packet destination
225                                                    address
226              RTA_PREF        char                  RFC4191 IPv6 router pref‐
227                                                    erence (see below)
228              RTA_ENCAP_TYPE  short                 Encapsulation type for
229                                                    lwtunnels (see below)
230              RTA_ENCAP                             Defined by RTA_ENCAP_TYPE
231              RTA_EXPIRES     int                   Expire  time   for   IPv6
232                                                    routes (in seconds)
233              RTA_MULTIPATH contains several packed instances of struct rtnex‐
234              thop together with nested RTAs (RTA_GATEWAY):
235
236                  struct rtnexthop {
237                      unsigned short rtnh_len;     /* Length of struct + length
238                                                      of RTAs */
239                      unsigned char  rtnh_flags;   /* Flags (see
240                                                      linux/rtnetlink.h) */
241                      unsigned char  rtnh_hops;    /* Nexthop priority */
242                      int            rtnh_ifindex; /* Interface index for this
243                                                      nexthop */
244                  }
245
246              There exist a bunch of RTNH_* macros similar to  RTA_*  and  NL‐
247              HDR_* macros useful to handle these structures.
248
249                  struct rtvia {
250                      unsigned short rtvia_family;
251                      unsigned char  rtvia_addr[0];
252                  };
253
254              rtvia_addr is the address, rtvia_family is its family type.
255
256              RTA_PREF     may    contain    values    ICMPV6_ROUTER_PREF_LOW,
257              ICMPV6_ROUTER_PREF_MEDIUM, and  ICMPV6_ROUTER_PREF_HIGH  defined
258              incw <linux/icmpv6.h>.
259
260              RTA_ENCAP_TYPE  may  contain  values LWTUNNEL_ENCAP_MPLS, LWTUN‐
261              NEL_ENCAP_IP, LWTUNNEL_ENCAP_ILA, or LWTUNNEL_ENCAP_IP6  defined
262              in <linux/lwtunnel.h>.
263
264              Fill these values in!
265
266       RTM_NEWNEIGH, RTM_DELNEIGH, RTM_GETNEIGH
267              Add, remove, or receive information about a neighbor table entry
268              (e.g., an ARP entry).  The message contains an ndmsg structure.
269
270              struct ndmsg {
271                  unsigned char ndm_family;
272                  int           ndm_ifindex;  /* Interface index */
273                  __u16         ndm_state;    /* State */
274                  __u8          ndm_flags;    /* Flags */
275                  __u8          ndm_type;
276              };
277
278              struct nda_cacheinfo {
279                  __u32         ndm_confirmed;
280                  __u32         ndm_used;
281                  __u32         ndm_updated;
282                  __u32         ndm_refcnt;
283              };
284
285              ndm_state is a bit mask of the following states:
286
287              NUD_INCOMPLETE   a currently resolving cache entry
288
289              NUD_REACHABLE    a confirmed working cache entry
290              NUD_STALE        an expired cache entry
291              NUD_DELAY        an entry waiting for a timer
292              NUD_PROBE        a cache entry that is currently reprobed
293
294              NUD_FAILED       an invalid cache entry
295              NUD_NOARP        a device with no destination cache
296              NUD_PERMANENT    a static entry
297
298              Valid ndm_flags are:
299
300              NTF_PROXY    a proxy arp entry
301              NTF_ROUTER   an IPv6 router
302
303              The rtattr struct has the following meanings  for  the  rta_type
304              field:
305
306              NDA_UNSPEC      unknown type
307              NDA_DST         a neighbor cache n/w layer destination address
308
309              NDA_LLADDR      a neighbor cache link layer address
310              NDA_CACHEINFO   cache statistics
311
312              If the rta_type field is NDA_CACHEINFO, then a struct nda_cache‐
313              info header follows.
314
315       RTM_NEWRULE, RTM_DELRULE, RTM_GETRULE
316              Add, delete, or retrieve a routing rule.  Carries a struct rtmsg
317
318       RTM_NEWQDISC, RTM_DELQDISC, RTM_GETQDISC
319              Add, remove, or get a queueing discipline.  The message contains
320              a struct tcmsg and may be followed by a series of attributes.
321
322              struct tcmsg {
323                  unsigned char    tcm_family;
324                  int              tcm_ifindex;   /* interface index */
325                  __u32            tcm_handle;    /* Qdisc handle */
326                  __u32            tcm_parent;    /* Parent qdisc */
327                  __u32            tcm_info;
328              };
329
330                                        Attributes
331              rta_type     Value type           Description
332              ────────────────────────────────────────────────────────────────
333              TCA_UNSPEC   -                    unspecified
334
335              TCA_KIND     asciiz string        Name of queueing discipline
336              TCA_OPTIONS  byte sequence        Qdisc-specific options follow
337              TCA_STATS    struct tc_stats      Qdisc statistics
338              TCA_XSTATS   qdisc-specific       Module-specific statistics
339              TCA_RATE     struct tc_estimator  Rate limit
340
341              In  addition, various other qdisc-module-specific attributes are
342              allowed.  For  more  information  see  the  appropriate  include
343              files.
344
345       RTM_NEWTCLASS, RTM_DELTCLASS, RTM_GETTCLASS
346              Add,  remove,  or get a traffic class.  These messages contain a
347              struct tcmsg as described above.
348
349       RTM_NEWTFILTER, RTM_DELTFILTER, RTM_GETTFILTER
350              Add, remove, or receive  information  about  a  traffic  filter.
351              These messages contain a struct tcmsg as described above.
352

VERSIONS

354       rtnetlink is a new feature of Linux 2.2.
355

BUGS

357       This manual page is incomplete.
358

SEE ALSO

360       cmsg(3), rtnetlink(3), ip(7), netlink(7)
361
362
363
364Linux man-pages 6.05              2023-07-15                      rtnetlink(7)
Impressum