1 #ifndef __LINUX_RTNETLINK_H
2 #define __LINUX_RTNETLINK_H
3
4 #include <linux/netlink.h>
5
6 #define RTNL_DEBUG 1
7
8
9 /****
10 * Routing/neighbour discovery messages.
11 ****/
12
13 /* Types of messages */
14
15 #define RTM_BASE 0x10
16
17 #define RTM_NEWLINK (RTM_BASE+0)
18 #define RTM_DELLINK (RTM_BASE+1)
19 #define RTM_GETLINK (RTM_BASE+2)
20
21 #define RTM_NEWADDR (RTM_BASE+4)
22 #define RTM_DELADDR (RTM_BASE+5)
23 #define RTM_GETADDR (RTM_BASE+6)
24
25 #define RTM_NEWROUTE (RTM_BASE+8)
26 #define RTM_DELROUTE (RTM_BASE+9)
27 #define RTM_GETROUTE (RTM_BASE+10)
28
29 #define RTM_NEWNEIGH (RTM_BASE+12)
30 #define RTM_DELNEIGH (RTM_BASE+13)
31 #define RTM_GETNEIGH (RTM_BASE+14)
32
33 #define RTM_NEWRULE (RTM_BASE+16)
34 #define RTM_DELRULE (RTM_BASE+17)
35 #define RTM_GETRULE (RTM_BASE+18)
36
37 #define RTM_NEWQDISC (RTM_BASE+20)
38 #define RTM_DELQDISC (RTM_BASE+21)
39 #define RTM_GETQDISC (RTM_BASE+22)
40
41 #define RTM_NEWTCLASS (RTM_BASE+24)
42 #define RTM_DELTCLASS (RTM_BASE+25)
43 #define RTM_GETTCLASS (RTM_BASE+26)
44
45 #define RTM_NEWTFILTER (RTM_BASE+28)
46 #define RTM_DELTFILTER (RTM_BASE+29)
47 #define RTM_GETTFILTER (RTM_BASE+30)
48
49 #define RTM_MAX (RTM_BASE+31)
50
51 /*
52 Generic structure for encapsulation of optional route information.
53 It is reminiscent of sockaddr, but with sa_family replaced
54 with attribute type.
55 */
56
57 struct rtattr
58 {
59 unsigned short rta_len;
60 unsigned short rta_type;
61 };
62
63 /* Macros to handle rtattributes */
64
65 #define RTA_ALIGNTO 4
66 #define RTA_ALIGN(len) ( ((len)+RTA_ALIGNTO-1) & ~(RTA_ALIGNTO-1) )
67 #define RTA_OK(rta,len) ((len) >= (int)sizeof(struct rtattr) && \
68 (rta)->rta_len >= sizeof(struct rtattr) && \
69 (rta)->rta_len <= (len))
70 #define RTA_NEXT(rta,attrlen) ((attrlen) -= RTA_ALIGN((rta)->rta_len), \
71 (struct rtattr*)(((char*)(rta)) + RTA_ALIGN((rta)->rta_len)))
72 #define RTA_LENGTH(len) (RTA_ALIGN(sizeof(struct rtattr)) + (len))
73 #define RTA_SPACE(len) RTA_ALIGN(RTA_LENGTH(len))
74 #define RTA_DATA(rta) ((void*)(((char*)(rta)) + RTA_LENGTH(0)))
75 #define RTA_PAYLOAD(rta) ((int)((rta)->rta_len) - RTA_LENGTH(0))
76
77
78
79
80 /******************************************************************************
81 * Definitions used in routing table administration.
82 ****/
83
84 struct rtmsg
85 {
86 unsigned char rtm_family;
87 unsigned char rtm_dst_len;
88 unsigned char rtm_src_len;
89 unsigned char rtm_tos;
90
91 unsigned char rtm_table; /* Routing table id */
92 unsigned char rtm_protocol; /* Routing protocol; see below */
93 unsigned char rtm_scope; /* See below */
94 unsigned char rtm_type; /* See below */
95
96 unsigned rtm_flags;
97 };
98
99 /* rtm_type */
100
101 enum
102 {
103 RTN_UNSPEC,
104 RTN_UNICAST, /* Gateway or direct route */
105 RTN_LOCAL, /* Accept locally */
106 RTN_BROADCAST, /* Accept locally as broadcast,
107 send as broadcast */
108 RTN_ANYCAST, /* Accept locally as broadcast,
109 but send as unicast */
110 RTN_MULTICAST, /* Multicast route */
111 RTN_BLACKHOLE, /* Drop */
112 RTN_UNREACHABLE, /* Destination is unreachable */
113 RTN_PROHIBIT, /* Administratively prohibited */
114 RTN_THROW, /* Not in this table */
115 RTN_NAT, /* Translate this address */
116 RTN_XRESOLVE, /* Use external resolver */
117 __RTN_MAX
118 };
119
120 #define RTN_MAX (__RTN_MAX - 1)
121
122
123 /* rtm_protocol */
124
125 #define RTPROT_UNSPEC 0
126 #define RTPROT_REDIRECT 1 /* Route installed by ICMP redirects;
127 not used by current IPv4 */
128 #define RTPROT_KERNEL 2 /* Route installed by kernel */
129 #define RTPROT_BOOT 3 /* Route installed during boot */
130 #define RTPROT_STATIC 4 /* Route installed by administrator */
131
132 /* Values of protocol >= RTPROT_STATIC are not interpreted by kernel;
133 they are just passed from user and back as is.
134 It will be used by hypothetical multiple routing daemons.
135 Note that protocol values should be standardized in order to
136 avoid conflicts.
137 */
138
139 #define RTPROT_GATED 8 /* Apparently, GateD */
140 #define RTPROT_RA 9 /* RDISC/ND router advertisements */
141 #define RTPROT_MRT 10 /* Merit MRT */
142 #define RTPROT_ZEBRA 11 /* Zebra */
143 #define RTPROT_BIRD 12 /* BIRD */
144 #define RTPROT_DNROUTED 13 /* DECnet routing daemon */
145 #define RTPROT_XORP 14 /* XORP */
146
147 /* rtm_scope
148
149 Really it is not scope, but sort of distance to the destination.
150 NOWHERE are reserved for not existing destinations, HOST is our
151 local addresses, LINK are destinations, located on directly attached
152 link and UNIVERSE is everywhere in the Universe.
153
154 Intermediate values are also possible f.e. interior routes
155 could be assigned a value between UNIVERSE and LINK.
156 */
157
158 enum rt_scope_t
159 {
160 RT_SCOPE_UNIVERSE=0,
161 /* User defined values */
162 RT_SCOPE_SITE=200,
163 RT_SCOPE_LINK=253,
164 RT_SCOPE_HOST=254,
165 RT_SCOPE_NOWHERE=255
166 };
167
168 /* rtm_flags */
169
170 #define RTM_F_NOTIFY 0x100 /* Notify user of route change */
171 #define RTM_F_CLONED 0x200 /* This route is cloned */
172 #define RTM_F_EQUALIZE 0x400 /* Multipath equalizer: NI */
173 #define RTM_F_PREFIX 0x800 /* Prefix addresses */
174
175 /* Reserved table identifiers */
176
177 enum rt_class_t
178 {
179 RT_TABLE_UNSPEC=0,
180 /* User defined values */
181 RT_TABLE_DEFAULT=253,
182 RT_TABLE_MAIN=254,
183 RT_TABLE_LOCAL=255,
184 __RT_TABLE_MAX
185 };
186 #define RT_TABLE_MAX (__RT_TABLE_MAX - 1)
187
188
189
190 /* Routing message attributes */
191
192 enum rtattr_type_t
193 {
194 RTA_UNSPEC,
195 RTA_DST,
196 RTA_SRC,
197 RTA_IIF,
198 RTA_OIF,
199 RTA_GATEWAY,
200 RTA_PRIORITY,
201 RTA_PREFSRC,
202 RTA_METRICS,
203 RTA_MULTIPATH,
204 RTA_PROTOINFO,
205 RTA_FLOW,
206 RTA_CACHEINFO,
207 __RTA_MAX
208 };
209
210 #define RTA_MAX (__RTA_MAX - 1)
211
212 #define RTM_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))))
213 #define RTM_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct rtmsg))
214
215 /* RTM_MULTIPATH --- array of struct rtnexthop.
216 *
217 * "struct rtnexthop" describes all necessary nexthop information,
218 * i.e. parameters of path to a destination via this nexthop.
219 *
220 * At the moment it is impossible to set different prefsrc, mtu, window
221 * and rtt for different paths from multipath.
222 */
223
224 struct rtnexthop
225 {
226 unsigned short rtnh_len;
227 unsigned char rtnh_flags;
228 unsigned char rtnh_hops;
229 int rtnh_ifindex;
230 };
231
232 /* rtnh_flags */
233
234 #define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
235 #define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
236 #define RTNH_F_ONLINK 4 /* Gateway is forced on link */
237
238 /* Macros to handle hexthops */
239
240 #define RTNH_ALIGNTO 4
241 #define RTNH_ALIGN(len) ( ((len)+RTNH_ALIGNTO-1) & ~(RTNH_ALIGNTO-1) )
242 #define RTNH_OK(rtnh,len) ((rtnh)->rtnh_len >= sizeof(struct rtnexthop) && \
243 ((int)(rtnh)->rtnh_len) <= (len))
244 #define RTNH_NEXT(rtnh) ((struct rtnexthop*)(((char*)(rtnh)) + RTNH_ALIGN((rtnh)->rtnh_len)))
245 #define RTNH_LENGTH(len) (RTNH_ALIGN(sizeof(struct rtnexthop)) + (len))
246 #define RTNH_SPACE(len) RTNH_ALIGN(RTNH_LENGTH(len))
247 #define RTNH_DATA(rtnh) ((struct rtattr*)(((char*)(rtnh)) + RTNH_LENGTH(0)))
248
249 /* RTM_CACHEINFO */
250
251 struct rta_cacheinfo
252 {
253 __u32 rta_clntref;
254 __u32 rta_lastuse;
255 __s32 rta_expires;
256 __u32 rta_error;
257 __u32 rta_used;
258
259 #define RTNETLINK_HAVE_PEERINFO 1
260 __u32 rta_id;
261 __u32 rta_ts;
262 __u32 rta_tsage;
263 };
264
265 /* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
266
267 enum
268 {
269 RTAX_UNSPEC,
270 #define RTAX_UNSPEC RTAX_UNSPEC
271 RTAX_LOCK,
272 #define RTAX_LOCK RTAX_LOCK
273 RTAX_MTU,
274 #define RTAX_MTU RTAX_MTU
275 RTAX_WINDOW,
276 #define RTAX_WINDOW RTAX_WINDOW
277 RTAX_RTT,
278 #define RTAX_RTT RTAX_RTT
279 RTAX_RTTVAR,
280 #define RTAX_RTTVAR RTAX_RTTVAR
281 RTAX_SSTHRESH,
282 #define RTAX_SSTHRESH RTAX_SSTHRESH
283 RTAX_CWND,
284 #define RTAX_CWND RTAX_CWND
285 RTAX_ADVMSS,
286 #define RTAX_ADVMSS RTAX_ADVMSS
287 RTAX_REORDERING,
288 #define RTAX_REORDERING RTAX_REORDERING
289 __RTAX_MAX
290 };
291
292 #define RTAX_MAX (__RTAX_MAX - 1)
293
294
295
296 /*********************************************************
297 * Interface address.
298 ****/
299
300 struct ifaddrmsg
301 {
302 unsigned char ifa_family;
303 unsigned char ifa_prefixlen; /* The prefix length */
304 unsigned char ifa_flags; /* Flags */
305 unsigned char ifa_scope; /* See above */
306 int ifa_index; /* Link index */
307 };
308
309 enum
310 {
311 IFA_UNSPEC,
312 IFA_ADDRESS,
313 IFA_LOCAL,
314 IFA_LABEL,
315 IFA_BROADCAST,
316 IFA_ANYCAST,
317 IFA_CACHEINFO,
318 __IFA_MAX
319 };
320
321 #define IFA_MAX (__IFA_MAX - 1)
322
323 /* ifa_flags */
324
325 #define IFA_F_SECONDARY 0x01
326
327 #define IFA_F_DEPRECATED 0x20
328 #define IFA_F_TENTATIVE 0x40
329 #define IFA_F_PERMANENT 0x80
330
331 struct ifa_cacheinfo
332 {
333 __s32 ifa_prefered;
334 __s32 ifa_valid;
335 };
336
337
338 #define IFA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
339 #define IFA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifaddrmsg))
340
341 /*
342 Important comment:
343 IFA_ADDRESS is prefix address, rather than local interface address.
344 It makes no difference for normally configured broadcast interfaces,
345 but for point-to-point IFA_ADDRESS is DESTINATION address,
346 local address is supplied in IFA_LOCAL attribute.
347 */
348
349 /**************************************************************
350 * Neighbour discovery.
351 ****/
352
353 struct ndmsg
354 {
355 unsigned char ndm_family;
356 unsigned char ndm_pad1;
357 unsigned short ndm_pad2;
358 int ndm_ifindex; /* Link index */
359 __u16 ndm_state;
360 __u8 ndm_flags;
361 __u8 ndm_type;
362 };
363
364 enum
365 {
366 NDA_UNSPEC,
367 NDA_DST,
368 NDA_LLADDR,
369 NDA_CACHEINFO,
370 __NDA_MAX
371 };
372
373 #define NDA_MAX (__NDA_MAX - 1)
374
375 #define NDA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
376 #define NDA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ndmsg))
377
378 /*
379 * Neighbor Cache Entry Flags
380 */
381
382 #define NTF_PROXY 0x08 /* == ATF_PUBL */
383 #define NTF_ROUTER 0x80
384
385 /*
386 * Neighbor Cache Entry States.
387 */
388
389 #define NUD_INCOMPLETE 0x01
390 #define NUD_REACHABLE 0x02
391 #define NUD_STALE 0x04
392 #define NUD_DELAY 0x08
393 #define NUD_PROBE 0x10
394 #define NUD_FAILED 0x20
395
396 /* Dummy states */
397 #define NUD_NOARP 0x40
398 #define NUD_PERMANENT 0x80
399 #define NUD_NONE 0x00
400
401
402 struct nda_cacheinfo
403 {
404 __u32 ndm_confirmed;
405 __u32 ndm_used;
406 __u32 ndm_updated;
407 __u32 ndm_refcnt;
408 };
409
410 /****
411 * General form of address family dependent message.
412 ****/
413
414 struct rtgenmsg
415 {
416 unsigned char rtgen_family;
417 };
418
419 /*****************************************************************
420 * Link layer specific messages.
421 ****/
422
423 /* struct ifinfomsg
424 * passes link level specific information, not dependent
425 * on network protocol.
426 */
427
428 struct ifinfomsg
429 {
430 unsigned char ifi_family;
431 unsigned char __ifi_pad;
432 unsigned short ifi_type; /* ARPHRD_* */
433 int ifi_index; /* Link index */
434 unsigned ifi_flags; /* IFF_* flags */
435 unsigned ifi_change; /* IFF_* change mask */
436 };
437
438 enum
439 {
440 IFLA_UNSPEC,
441 IFLA_ADDRESS,
442 IFLA_BROADCAST,
443 IFLA_IFNAME,
444 IFLA_MTU,
445 IFLA_LINK,
446 IFLA_QDISC,
447 IFLA_STATS,
448 IFLA_COST,
449 #define IFLA_COST IFLA_COST
450 IFLA_PRIORITY,
451 #define IFLA_PRIORITY IFLA_PRIORITY
452 IFLA_MASTER,
453 #define IFLA_MASTER IFLA_MASTER
454 IFLA_WIRELESS, /* Wireless Extension event - see wireless.h */
455 #define IFLA_WIRELESS IFLA_WIRELESS
456 IFLA_PROTINFO, /* Protocol specific information for a link */
457 #define IFLA_PROTINFO IFLA_PROTINFO
458 __IFLA_MAX
459 };
460
461
462 #define IFLA_MAX (__IFLA_MAX - 1)
463
464 #define IFLA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
465 #define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
466
467 /* ifi_flags.
468
469 IFF_* flags.
470
471 The only change is:
472 IFF_LOOPBACK, IFF_BROADCAST and IFF_POINTOPOINT are
473 more not changeable by user. They describe link media
474 characteristics and set by device driver.
475
476 Comments:
477 - Combination IFF_BROADCAST|IFF_POINTOPOINT is invalid
478 - If neither of these three flags are set;
479 the interface is NBMA.
480
481 - IFF_MULTICAST does not mean anything special:
482 multicasts can be used on all not-NBMA links.
483 IFF_MULTICAST means that this media uses special encapsulation
484 for multicast frames. Apparently, all IFF_POINTOPOINT and
485 IFF_BROADCAST devices are able to use multicasts too.
486 */
487
488 /* IFLA_LINK.
489 For usual devices it is equal ifi_index.
490 If it is a "virtual interface" (f.e. tunnel), ifi_link
491 can point to real physical interface (f.e. for bandwidth calculations),
492 or maybe 0, what means, that real media is unknown (usual
493 for IPIP tunnels, when route to endpoint is allowed to change)
494 */
495
496 /* Subtype attributes for IFLA_PROTINFO */
497 enum
498 {
499 IFLA_INET6_UNSPEC,
500 IFLA_INET6_FLAGS, /* link flags */
501 IFLA_INET6_CONF, /* sysctl parameters */
502 IFLA_INET6_STATS, /* statistics */
503 IFLA_INET6_MCAST, /* MC things. What of them? */
504 __IFLA_INET6_MAX
505 };
506
507 #define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
508
509 /*****************************************************************
510 * Traffic control messages.
511 ****/
512
513 struct tcmsg
514 {
515 unsigned char tcm_family;
516 unsigned char tcm__pad1;
517 unsigned short tcm__pad2;
518 int tcm_ifindex;
519 __u32 tcm_handle;
520 __u32 tcm_parent;
521 __u32 tcm_info;
522 };
523
524 enum
525 {
526 TCA_UNSPEC,
527 TCA_KIND,
528 TCA_OPTIONS,
529 TCA_STATS,
530 TCA_XSTATS,
531 TCA_RATE,
532 __TCA_MAX
533 };
534
535 #define TCA_MAX (__TCA_MAX - 1)
536
537 #define TCA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcmsg))))
538 #define TCA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcmsg))
539
540
541 /* SUMMARY: maximal rtattr understood by kernel */
542
543 #define RTATTR_MAX RTA_MAX
544
545 /* RTnetlink multicast groups */
546
547 #define RTMGRP_LINK 1
548 #define RTMGRP_NOTIFY 2
549 #define RTMGRP_NEIGH 4
550 #define RTMGRP_TC 8
551
552 #define RTMGRP_IPV4_IFADDR 0x10
553 #define RTMGRP_IPV4_MROUTE 0x20
554 #define RTMGRP_IPV4_ROUTE 0x40
555
556 #define RTMGRP_IPV6_IFADDR 0x100
557 #define RTMGRP_IPV6_MROUTE 0x200
558 #define RTMGRP_IPV6_ROUTE 0x400
559
560 #define RTMGRP_DECnet_IFADDR 0x1000
561 #define RTMGRP_DECnet_ROUTE 0x4000
562
563 /* End of information exported to user level */
564
565 #ifdef __KERNEL__
566
567 #include <linux/config.h>
568
rtattr_strcmp(struct rtattr * rta,char * str)569 static __inline__ int rtattr_strcmp(struct rtattr *rta, char *str)
570 {
571 int len = strlen(str) + 1;
572 return len > rta->rta_len || memcmp(RTA_DATA(rta), str, len);
573 }
574
575 extern int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len);
576
577 extern struct sock *rtnl;
578
579 struct rtnetlink_link
580 {
581 int (*doit)(struct sk_buff *, struct nlmsghdr*, void *attr);
582 int (*dumpit)(struct sk_buff *, struct netlink_callback *cb);
583 };
584
585 extern struct rtnetlink_link * rtnetlink_links[NPROTO];
586 extern int rtnetlink_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb);
587 extern int rtnetlink_send(struct sk_buff *skb, u32 pid, u32 group, int echo);
588 extern int rtnetlink_put_metrics(struct sk_buff *skb, unsigned *metrics);
589
590 extern void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data);
591
592 #define RTA_PUT(skb, attrtype, attrlen, data) \
593 ({ if (skb_tailroom(skb) < (int)RTA_SPACE(attrlen)) goto rtattr_failure; \
594 __rta_fill(skb, attrtype, attrlen, data); })
595
596 extern void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change);
597
598 extern struct semaphore rtnl_sem;
599
600 #define rtnl_exlock() do { } while(0)
601 #define rtnl_exunlock() do { } while(0)
602 #define rtnl_exlock_nowait() (0)
603
604 #define rtnl_shlock() down(&rtnl_sem)
605 #define rtnl_shlock_nowait() down_trylock(&rtnl_sem)
606
607 #define rtnl_shunlock() do { up(&rtnl_sem); \
608 if (rtnl && rtnl->receive_queue.qlen) \
609 rtnl->data_ready(rtnl, 0); \
610 } while(0)
611
612 extern void rtnl_lock(void);
613 extern void rtnl_unlock(void);
614 extern void rtnetlink_init(void);
615
616 #define ASSERT_RTNL() do { if (down_trylock(&rtnl_sem) == 0) { up(&rtnl_sem); \
617 printk("RTNL: assertion failed at " __FILE__ "(%d)\n", __LINE__); } \
618 } while(0)
619 #define BUG_TRAP(x) if (!(x)) { printk("KERNEL: assertion (" #x ") failed at " __FILE__ "(%d)\n", __LINE__); }
620
621
622 #endif /* __KERNEL__ */
623
624
625 #endif /* __LINUX_RTNETLINK_H */
626