1RTNETLINK(7)               Linux Programmer's Manual              RTNETLINK(7)
2
3
4

NAME

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

VERSIONS

348       rtnetlink is a new feature of Linux 2.2.
349

BUGS

351       This manual page is incomplete.
352

SEE ALSO

354       cmsg(3), rtnetlink(3), ip(7), netlink(7)
355

COLOPHON

357       This  page  is  part of release 5.07 of the Linux man-pages project.  A
358       description of the project, information about reporting bugs,  and  the
359       latest     version     of     this    page,    can    be    found    at
360       https://www.kernel.org/doc/man-pages/.
361
362
363
364Linux                             2020-06-09                      RTNETLINK(7)
Impressum