1RTNETLINK(7) Linux Programmer's Manual RTNETLINK(7)
2
3
4
6 rtnetlink, NETLINK_ROUTE - Linux IPv4 routing socket
7
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
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 only manipulated using 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, ifi_change is reserved for future
57 use and should be always set to 0xFFFFFFFF.
58
59 Routing attributes
60 rta_type value type description
61 ──────────────────────────────────────────────────────────────
62 IFLA_UNSPEC - unspecified.
63 IFLA_ADDRESS hardware address interface L2 address
64 IFLA_BROADCAST hardware address L2 broadcast address.
65 IFLA_IFNAME asciiz string Device name.
66
67 IFLA_MTU unsigned int MTU of the device.
68 IFLA_LINK int Link type.
69 IFLA_QDISC asciiz string Queueing discipline.
70 IFLA_STATS see below Interface Statistics.
71
72 The value type for IFLA_STATS is struct net_device_stats.
73
74 RTM_NEWADDR, RTM_DELADDR, RTM_GETADDR
75 Add, remove or receive information about an IP address associ‐
76 ated with an interface. In Linux 2.2 an interface can carry
77 multiple IP addresses, this replaces the alias device concept in
78 2.0. In Linux 2.2 these messages support IPv4 and IPv6
79 addresses. They contain an ifaddrmsg structure, optionally fol‐
80 lowed by rtaddr routing attributes.
81
82 struct ifaddrmsg {
83 unsigned char ifa_family; /* Address type */
84 unsigned char ifa_prefixlen; /* Prefixlength of address */
85 unsigned char ifa_flags; /* Address flags */
86 unsigned char ifa_scope; /* Address scope */
87 int ifa_index; /* Interface index */
88 };
89
90 ifa_family is the address family type (currently AF_INET or
91 AF_INET6), ifa_prefixlen is the length of the address mask of
92 the address if defined for the family (like for IPv4), ifa_scope
93 is the address scope, ifa_index is the interface index of the
94 interface the address is associated with. ifa_flags is a flag
95 word of IFA_F_SECONDARY for secondary address (old alias inter‐
96 face), IFA_F_PERMANENT for a permanent address set by the user
97 and other undocumented flags.
98
99 Attributes
100 rta_type value type description
101 ─────────────────────────────────────────────────────────────
102 IFA_UNSPEC - unspecified.
103 IFA_ADDRESS raw protocol address interface address
104 IFA_LOCAL raw protocol address local address
105 IFA_LABEL asciiz string name of the interface
106 IFA_BROADCAST raw protocol address broadcast address.
107 IFA_ANYCAST raw protocol address anycast address
108 IFA_CACHEINFO struct ifa_cacheinfo Address information.
109
110 RTM_NEWROUTE, RTM_DELROUTE, RTM_GETROUTE
111 Create, remove or receive information about a network route.
112 These messages contain an rtmsg structure with an optional
113 sequence of rtattr structures following. For RTM_GETROUTE set‐
114 ting rtm_dst_len and rtm_src_len to 0 means you get all entries
115 for the specified routing table. For the other fields except
116 rtm_table and rtm_protocol 0 is the wildcard.
117
118 struct rtmsg {
119 unsigned char rtm_family; /* Address family of route */
120 unsigned char rtm_dst_len; /* Length of destination */
121 unsigned char rtm_src_len; /* Length of source */
122 unsigned char rtm_tos; /* TOS filter */
123
124 unsigned char rtm_table; /* Routing table ID */
125 unsigned char rtm_protocol; /* Routing protocol; see below */
126 unsigned char rtm_scope; /* See below */
127 unsigned char rtm_type; /* See below */
128
129 unsigned int rtm_flags;
130 };
131
132
133 rtm_type Route type
134 ───────────────────────────────────────────────────────────
135 RTN_UNSPEC unknown route
136 RTN_UNICAST a gateway or direct route
137 RTN_LOCAL a local interface route
138 RTN_BROADCAST a local broadcast route (sent as a
139 broadcast)
140 RTN_ANYCAST a local broadcast route (sent as a uni‐
141 cast)
142 RTN_MULTICAST a multicast route
143 RTN_BLACKHOLE a packet dropping route
144 RTN_UNREACHABLE an unreachable destination
145 RTN_PROHIBIT a packet rejection route
146 RTN_THROW continue routing lookup in another table
147 RTN_NAT a network address translation rule
148 RTN_XRESOLVE refer to an external resolver (not
149 implemented)
150
151 rtm_protocol Route origin.
152 ─────────────────────────────────────────────
153 RTPROT_UNSPEC unknown
154 RTPROT_REDIRECT by an ICMP redirect (cur‐
155 rently unused)
156 RTPROT_KERNEL by the kernel
157 RTPROT_BOOT during boot
158 RTPROT_STATIC by the administrator
159
160 Values larger than RTPROT_STATIC are not interpreted by the ker‐
161 nel, they are just for user information. They may be used to
162 tag the source of a routing information or to distinguish
163 between multiple routing daemons. See <linux/rtnetlink.h> for
164 the routing daemon identifiers which are already assigned.
165
166 rtm_scope is the distance to the destination:
167
168 RT_SCOPE_UNIVERSE global route
169 RT_SCOPE_SITE interior route in the
170 local autonomous system
171 RT_SCOPE_LINK route on this link
172 RT_SCOPE_HOST route on the local host
173 RT_SCOPE_NOWHERE destination doesn't exist
174
175 The values between RT_SCOPE_UNIVERSE and RT_SCOPE_SITE are
176 available to the user.
177
178 The rtm_flags have the following meanings:
179
180 RTM_F_NOTIFY if the route changes, notify the user via
181 rtnetlink
182 RTM_F_CLONED route is cloned from another route
183 RTM_F_EQUALIZE a multipath equalizer (not yet implemented)
184
185 rtm_table specifies the routing table
186
187 RT_TABLE_UNSPEC an unspecified routing table
188 RT_TABLE_DEFAULT the default table
189 RT_TABLE_MAIN the main table
190 RT_TABLE_LOCAL the local table
191
192 The user may assign arbitrary values between RT_TABLE_UNSPEC and
193 RT_TABLE_DEFAULT.
194
195 Attributes
196 rta_type value type description
197 ──────────────────────────────────────────────────────────────
198
199 RTA_UNSPEC - ignored.
200 RTA_DST protocol address Route destination address.
201 RTA_SRC protocol address Route source address.
202 RTA_IIF int Input interface index.
203 RTA_OIF int Output interface index.
204 RTA_GATEWAY protocol address The gateway of the route
205 RTA_PRIORITY int Priority of route.
206 RTA_PREFSRC
207 RTA_METRICS int Route metric
208 RTA_MULTIPATH
209 RTA_PROTOINFO
210 RTA_FLOW
211 RTA_CACHEINFO
212
213 Fill these values in!
214
215 RTM_NEWNEIGH, RTM_DELNEIGH, RTM_GETNEIGH
216 Add, remove or receive information about a neighbor table entry
217 (e.g., an ARP entry). The message contains an ndmsg structure.
218
219 struct ndmsg {
220 unsigned char ndm_family;
221 int ndm_ifindex; /* Interface index */
222 __u16 ndm_state; /* State */
223 __u8 ndm_flags; /* Flags */
224 __u8 ndm_type;
225 };
226
227 struct nda_cacheinfo {
228 __u32 ndm_confirmed;
229 __u32 ndm_used;
230 __u32 ndm_updated;
231 __u32 ndm_refcnt;
232 };
233
234 ndm_state is a bit mask of the following states:
235
236 NUD_INCOMPLETE a currently resolving cache entry
237 NUD_REACHABLE a confirmed working cache entry
238 NUD_STALE an expired cache entry
239 NUD_DELAY an entry waiting for a timer
240 NUD_PROBE a cache entry that is currently reprobed
241 NUD_FAILED an invalid cache entry
242 NUD_NOARP a device with no destination cache
243 NUD_PERMANENT a static entry
244
245 Valid ndm_flags are:
246
247 NTF_PROXY a proxy arp entry
248 NTF_ROUTER an IPv6 router
249
250 The rtaddr struct has the following meanings for the rta_type
251 field:
252
253 NDA_UNSPEC unknown type
254 NDA_DST a neighbor cache n/w layer destination address
255 NDA_LLADDR a neighbor cache link layer address
256 NDA_CACHEINFO cache statistics.
257
258 If the rta_type field is NDA_CACHEINFO then a struct nda_cache‐
259 info header follows
260
261 RTM_NEWRULE, RTM_DELRULE, RTM_GETRULE
262 Add, delete or retrieve a routing rule. Carries a struct rtmsg
263
264 RTM_NEWQDISC, RTM_DELQDISC, RTM_GETQDISC
265 Add, remove or get a queueing discipline. The message contains
266 a struct tcmsg and may be followed by a series of attributes.
267
268 struct tcmsg {
269 unsigned char tcm_family;
270 int tcm_ifindex; /* interface index */
271 __u32 tcm_handle; /* Qdisc handle */
272 __u32 tcm_parent; /* Parent qdisc */
273 __u32 tcm_info;
274 };
275
276 Attributes
277 rta_type value type Description
278 ──────────────────────────────────────────────────────────────────
279 TCA_UNSPEC - unspecified
280 TCA_KIND asciiz string Name of queueing discipline
281 TCA_OPTIONS byte sequence Qdisc-specific options follow
282 TCA_STATS struct tc_stats Qdisc statistics.
283 TCA_XSTATS qdisc specific Module-specific statistics.
284 TCA_RATE struct tc_estimator Rate limit.
285
286 In addition various other qdisc module specific attributes are
287 allowed. For more information see the appropriate include
288 files.
289
290 RTM_NEWTCLASS, RTM_DELTCLASS, RTM_GETTCLASS
291 Add, remove or get a traffic class. These messages contain a
292 struct tcmsg as described above.
293
294 RTM_NEWTFILTER, RTM_DELTFILTER, RTM_GETTFILTER
295 Add, remove or receive information about a traffic filter.
296 These messages contain a struct tcmsg as described above.
297
299 rtnetlink is a new feature of Linux 2.2.
300
302 This manual page is incomplete.
303
305 cmsg(3), rtnetlink(3), ip(7), netlink(7)
306
308 This page is part of release 3.22 of the Linux man-pages project. A
309 description of the project, and information about reporting bugs, can
310 be found at http://www.kernel.org/doc/man-pages/.
311
312
313
314Linux 2008-08-08 RTNETLINK(7)