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