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
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              Linux 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  se‐
116              quence  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  im‐
151                                plemented)
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  be‐
165              tween multiple routing daemons.  See <linux/rtnetlink.h> for the
166              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  lo‐
172                                  cal 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 rtnex‐
233              thop 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
239                                                      linux/rtnetlink.h) */
240                      unsigned char  rtnh_hops;    /* Nexthop priority */
241                      int            rtnh_ifindex; /* Interface index for this
242                                                      nexthop */
243                  }
244
245              There exist a bunch of RTNH_* macros similar to  RTA_*  and  NL‐
246              HDR_* macros useful to handle these structures.
247
248                  struct rtvia {
249                      unsigned short rtvia_family;
250                      unsigned char  rtvia_addr[0];
251                  };
252
253              rtvia_addr is the address, rtvia_family is its family type.
254
255              RTA_PREF     may    contain    values    ICMPV6_ROUTER_PREF_LOW,
256              ICMPV6_ROUTER_PREF_MEDIUM, and  ICMPV6_ROUTER_PREF_HIGH  defined
257              incw <linux/icmpv6.h>.
258
259              RTA_ENCAP_TYPE  may  contain  values LWTUNNEL_ENCAP_MPLS, LWTUN‐
260              NEL_ENCAP_IP, LWTUNNEL_ENCAP_ILA, or LWTUNNEL_ENCAP_IP6  defined
261              in <linux/lwtunnel.h>.
262
263              Fill these values in!
264
265       RTM_NEWNEIGH, RTM_DELNEIGH, RTM_GETNEIGH
266              Add, remove, or receive information about a neighbor table entry
267              (e.g., an ARP entry).  The message contains an ndmsg structure.
268
269              struct ndmsg {
270                  unsigned char ndm_family;
271                  int           ndm_ifindex;  /* Interface index */
272                  __u16         ndm_state;    /* State */
273                  __u8          ndm_flags;    /* Flags */
274                  __u8          ndm_type;
275              };
276
277              struct nda_cacheinfo {
278                  __u32         ndm_confirmed;
279                  __u32         ndm_used;
280                  __u32         ndm_updated;
281                  __u32         ndm_refcnt;
282              };
283
284              ndm_state is a bit mask of the following states:
285
286              NUD_INCOMPLETE   a currently resolving cache entry
287              NUD_REACHABLE    a confirmed working cache entry
288              NUD_STALE        an expired cache entry
289              NUD_DELAY        an entry waiting for a timer
290              NUD_PROBE        a cache entry that is currently reprobed
291              NUD_FAILED       an invalid cache entry
292              NUD_NOARP        a device with no destination cache
293              NUD_PERMANENT    a static entry
294
295              Valid ndm_flags are:
296
297              NTF_PROXY    a proxy arp entry
298              NTF_ROUTER   an IPv6 router
299
300              The rtattr struct has the following meanings  for  the  rta_type
301              field:
302
303              NDA_UNSPEC      unknown type
304              NDA_DST         a neighbor cache n/w layer destination address
305              NDA_LLADDR      a neighbor cache link layer address
306              NDA_CACHEINFO   cache statistics
307
308              If the rta_type field is NDA_CACHEINFO, then a struct nda_cache‐
309              info header follows.
310
311       RTM_NEWRULE, RTM_DELRULE, RTM_GETRULE
312              Add, delete, or retrieve a routing rule.  Carries a struct rtmsg
313
314       RTM_NEWQDISC, RTM_DELQDISC, RTM_GETQDISC
315              Add, remove, or get a queueing discipline.  The message contains
316              a struct tcmsg and may be followed by a series of attributes.
317
318              struct tcmsg {
319                  unsigned char    tcm_family;
320                  int              tcm_ifindex;   /* interface index */
321                  __u32            tcm_handle;    /* Qdisc handle */
322                  __u32            tcm_parent;    /* Parent qdisc */
323                  __u32            tcm_info;
324              };
325
326                                        Attributes
327              rta_type     Value type           Description
328              ────────────────────────────────────────────────────────────────
329              TCA_UNSPEC   -                    unspecified
330              TCA_KIND     asciiz string        Name of queueing discipline
331              TCA_OPTIONS  byte sequence        Qdisc-specific options follow
332              TCA_STATS    struct tc_stats      Qdisc statistics
333              TCA_XSTATS   qdisc-specific       Module-specific statistics
334              TCA_RATE     struct tc_estimator  Rate limit
335
336              In  addition, various other qdisc-module-specific attributes are
337              allowed.  For  more  information  see  the  appropriate  include
338              files.
339
340       RTM_NEWTCLASS, RTM_DELTCLASS, RTM_GETTCLASS
341              Add,  remove,  or get a traffic class.  These messages contain a
342              struct tcmsg as described above.
343
344       RTM_NEWTFILTER, RTM_DELTFILTER, RTM_GETTFILTER
345              Add, remove, or receive  information  about  a  traffic  filter.
346              These messages contain a struct tcmsg as described above.
347

VERSIONS

349       rtnetlink is a new feature of Linux 2.2.
350

BUGS

352       This manual page is incomplete.
353

SEE ALSO

355       cmsg(3), rtnetlink(3), ip(7), netlink(7)
356
357
358
359Linux man-pages 6.04              2022-12-15                      rtnetlink(7)
Impressum