1 #ifndef __LINUX_RTNETLINK_H
2 #define __LINUX_RTNETLINK_H
4 #include <linux/netlink.h>
5 #include <linux/if_link.h>
6 #include <linux/if_addr.h>
7 #include <linux/neighbour.h>
10 * Routing/neighbour discovery messages.
13 /* Types of messages */
17 #define RTM_BASE RTM_BASE
20 #define RTM_NEWLINK RTM_NEWLINK
22 #define RTM_DELLINK RTM_DELLINK
24 #define RTM_GETLINK RTM_GETLINK
26 #define RTM_SETLINK RTM_SETLINK
29 #define RTM_NEWADDR RTM_NEWADDR
31 #define RTM_DELADDR RTM_DELADDR
33 #define RTM_GETADDR RTM_GETADDR
36 #define RTM_NEWROUTE RTM_NEWROUTE
38 #define RTM_DELROUTE RTM_DELROUTE
40 #define RTM_GETROUTE RTM_GETROUTE
43 #define RTM_NEWNEIGH RTM_NEWNEIGH
45 #define RTM_DELNEIGH RTM_DELNEIGH
47 #define RTM_GETNEIGH RTM_GETNEIGH
50 #define RTM_NEWRULE RTM_NEWRULE
52 #define RTM_DELRULE RTM_DELRULE
54 #define RTM_GETRULE RTM_GETRULE
57 #define RTM_NEWQDISC RTM_NEWQDISC
59 #define RTM_DELQDISC RTM_DELQDISC
61 #define RTM_GETQDISC RTM_GETQDISC
64 #define RTM_NEWTCLASS RTM_NEWTCLASS
66 #define RTM_DELTCLASS RTM_DELTCLASS
68 #define RTM_GETTCLASS RTM_GETTCLASS
71 #define RTM_NEWTFILTER RTM_NEWTFILTER
73 #define RTM_DELTFILTER RTM_DELTFILTER
75 #define RTM_GETTFILTER RTM_GETTFILTER
78 #define RTM_NEWACTION RTM_NEWACTION
80 #define RTM_DELACTION RTM_DELACTION
82 #define RTM_GETACTION RTM_GETACTION
85 #define RTM_NEWPREFIX RTM_NEWPREFIX
87 RTM_GETMULTICAST = 58,
88 #define RTM_GETMULTICAST RTM_GETMULTICAST
91 #define RTM_GETANYCAST RTM_GETANYCAST
94 #define RTM_NEWNEIGHTBL RTM_NEWNEIGHTBL
96 #define RTM_GETNEIGHTBL RTM_GETNEIGHTBL
98 #define RTM_SETNEIGHTBL RTM_SETNEIGHTBL
101 #define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1)
104 #define RTM_NR_MSGTYPES (RTM_MAX + 1 - RTM_BASE)
105 #define RTM_NR_FAMILIES (RTM_NR_MSGTYPES >> 2)
106 #define RTM_FAM(cmd) (((cmd) - RTM_BASE) >> 2)
109 Generic structure for encapsulation of optional route information.
110 It is reminiscent of sockaddr, but with sa_family replaced
116 unsigned short rta_len;
117 unsigned short rta_type;
120 /* Macros to handle rtattributes */
122 #define RTA_ALIGNTO 4
123 #define RTA_ALIGN(len) ( ((len)+RTA_ALIGNTO-1) & ~(RTA_ALIGNTO-1) )
124 #define RTA_OK(rta,len) ((len) >= (int)sizeof(struct rtattr) && \
125 (rta)->rta_len >= sizeof(struct rtattr) && \
126 (rta)->rta_len <= (len))
127 #define RTA_NEXT(rta,attrlen) ((attrlen) -= RTA_ALIGN((rta)->rta_len), \
128 (struct rtattr*)(((char*)(rta)) + RTA_ALIGN((rta)->rta_len)))
129 #define RTA_LENGTH(len) (RTA_ALIGN(sizeof(struct rtattr)) + (len))
130 #define RTA_SPACE(len) RTA_ALIGN(RTA_LENGTH(len))
131 #define RTA_DATA(rta) ((void*)(((char*)(rta)) + RTA_LENGTH(0)))
132 #define RTA_PAYLOAD(rta) ((int)((rta)->rta_len) - RTA_LENGTH(0))
137 /******************************************************************************
138 * Definitions used in routing table administration.
143 unsigned char rtm_family;
144 unsigned char rtm_dst_len;
145 unsigned char rtm_src_len;
146 unsigned char rtm_tos;
148 unsigned char rtm_table; /* Routing table id */
149 unsigned char rtm_protocol; /* Routing protocol; see below */
150 unsigned char rtm_scope; /* See below */
151 unsigned char rtm_type; /* See below */
161 RTN_UNICAST, /* Gateway or direct route */
162 RTN_LOCAL, /* Accept locally */
163 RTN_BROADCAST, /* Accept locally as broadcast,
165 RTN_ANYCAST, /* Accept locally as broadcast,
166 but send as unicast */
167 RTN_MULTICAST, /* Multicast route */
168 RTN_BLACKHOLE, /* Drop */
169 RTN_UNREACHABLE, /* Destination is unreachable */
170 RTN_PROHIBIT, /* Administratively prohibited */
171 RTN_THROW, /* Not in this table */
172 RTN_NAT, /* Translate this address */
173 RTN_XRESOLVE, /* Use external resolver */
177 #define RTN_MAX (__RTN_MAX - 1)
182 #define RTPROT_UNSPEC 0
183 #define RTPROT_REDIRECT 1 /* Route installed by ICMP redirects;
184 not used by current IPv4 */
185 #define RTPROT_KERNEL 2 /* Route installed by kernel */
186 #define RTPROT_BOOT 3 /* Route installed during boot */
187 #define RTPROT_STATIC 4 /* Route installed by administrator */
189 /* Values of protocol >= RTPROT_STATIC are not interpreted by kernel;
190 they are just passed from user and back as is.
191 It will be used by hypothetical multiple routing daemons.
192 Note that protocol values should be standardized in order to
196 #define RTPROT_GATED 8 /* Apparently, GateD */
197 #define RTPROT_RA 9 /* RDISC/ND router advertisements */
198 #define RTPROT_MRT 10 /* Merit MRT */
199 #define RTPROT_ZEBRA 11 /* Zebra */
200 #define RTPROT_BIRD 12 /* BIRD */
201 #define RTPROT_DNROUTED 13 /* DECnet routing daemon */
202 #define RTPROT_XORP 14 /* XORP */
203 #define RTPROT_NTK 15 /* Netsukuku */
207 Really it is not scope, but sort of distance to the destination.
208 NOWHERE are reserved for not existing destinations, HOST is our
209 local addresses, LINK are destinations, located on directly attached
210 link and UNIVERSE is everywhere in the Universe.
212 Intermediate values are also possible f.e. interior routes
213 could be assigned a value between UNIVERSE and LINK.
219 /* User defined values */
228 #define RTM_F_NOTIFY 0x100 /* Notify user of route change */
229 #define RTM_F_CLONED 0x200 /* This route is cloned */
230 #define RTM_F_EQUALIZE 0x400 /* Multipath equalizer: NI */
231 #define RTM_F_PREFIX 0x800 /* Prefix addresses */
233 /* Reserved table identifiers */
238 /* User defined values */
239 RT_TABLE_DEFAULT=253,
242 RT_TABLE_MAX=0xFFFFFFFF
246 /* Routing message attributes */
264 RTA_MP_ALGO, /* no longer used */
269 #define RTA_MAX (__RTA_MAX - 1)
271 #define RTM_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))))
272 #define RTM_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct rtmsg))
274 /* RTM_MULTIPATH --- array of struct rtnexthop.
276 * "struct rtnexthop" describes all necessary nexthop information,
277 * i.e. parameters of path to a destination via this nexthop.
279 * At the moment it is impossible to set different prefsrc, mtu, window
280 * and rtt for different paths from multipath.
285 unsigned short rtnh_len;
286 unsigned char rtnh_flags;
287 unsigned char rtnh_hops;
293 #define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
294 #define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
295 #define RTNH_F_ONLINK 4 /* Gateway is forced on link */
297 /* Macros to handle hexthops */
299 #define RTNH_ALIGNTO 4
300 #define RTNH_ALIGN(len) ( ((len)+RTNH_ALIGNTO-1) & ~(RTNH_ALIGNTO-1) )
301 #define RTNH_OK(rtnh,len) ((rtnh)->rtnh_len >= sizeof(struct rtnexthop) && \
302 ((int)(rtnh)->rtnh_len) <= (len))
303 #define RTNH_NEXT(rtnh) ((struct rtnexthop*)(((char*)(rtnh)) + RTNH_ALIGN((rtnh)->rtnh_len)))
304 #define RTNH_LENGTH(len) (RTNH_ALIGN(sizeof(struct rtnexthop)) + (len))
305 #define RTNH_SPACE(len) RTNH_ALIGN(RTNH_LENGTH(len))
306 #define RTNH_DATA(rtnh) ((struct rtattr*)(((char*)(rtnh)) + RTNH_LENGTH(0)))
318 #define RTNETLINK_HAVE_PEERINFO 1
324 /* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
329 #define RTAX_UNSPEC RTAX_UNSPEC
331 #define RTAX_LOCK RTAX_LOCK
333 #define RTAX_MTU RTAX_MTU
335 #define RTAX_WINDOW RTAX_WINDOW
337 #define RTAX_RTT RTAX_RTT
339 #define RTAX_RTTVAR RTAX_RTTVAR
341 #define RTAX_SSTHRESH RTAX_SSTHRESH
343 #define RTAX_CWND RTAX_CWND
345 #define RTAX_ADVMSS RTAX_ADVMSS
347 #define RTAX_REORDERING RTAX_REORDERING
349 #define RTAX_HOPLIMIT RTAX_HOPLIMIT
351 #define RTAX_INITCWND RTAX_INITCWND
353 #define RTAX_FEATURES RTAX_FEATURES
355 #define RTAX_RTO_MIN RTAX_RTO_MIN
359 #define RTAX_MAX (__RTAX_MAX - 1)
361 #define RTAX_FEATURE_ECN 0x00000001
362 #define RTAX_FEATURE_SACK 0x00000002
363 #define RTAX_FEATURE_TIMESTAMP 0x00000004
364 #define RTAX_FEATURE_ALLFRAG 0x00000008
389 * General form of address family dependent message.
394 unsigned char rtgen_family;
397 /*****************************************************************
398 * Link layer specific messages.
402 * passes link level specific information, not dependent
403 * on network protocol.
408 unsigned char ifi_family;
409 unsigned char __ifi_pad;
410 unsigned short ifi_type; /* ARPHRD_* */
411 int ifi_index; /* Link index */
412 unsigned ifi_flags; /* IFF_* flags */
413 unsigned ifi_change; /* IFF_* change mask */
416 /********************************************************************
422 unsigned char prefix_family;
423 unsigned char prefix_pad1;
424 unsigned short prefix_pad2;
426 unsigned char prefix_type;
427 unsigned char prefix_len;
428 unsigned char prefix_flags;
429 unsigned char prefix_pad3;
440 #define PREFIX_MAX (__PREFIX_MAX - 1)
442 struct prefix_cacheinfo
444 __u32 preferred_time;
449 /*****************************************************************
450 * Traffic control messages.
455 unsigned char tcm_family;
456 unsigned char tcm__pad1;
457 unsigned short tcm__pad2;
477 #define TCA_MAX (__TCA_MAX - 1)
479 #define TCA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcmsg))))
480 #define TCA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcmsg))
483 /* RTnetlink multicast groups - backwards compatibility for userspace */
484 #define RTMGRP_LINK 1
485 #define RTMGRP_NOTIFY 2
486 #define RTMGRP_NEIGH 4
489 #define RTMGRP_IPV4_IFADDR 0x10
490 #define RTMGRP_IPV4_MROUTE 0x20
491 #define RTMGRP_IPV4_ROUTE 0x40
492 #define RTMGRP_IPV4_RULE 0x80
494 #define RTMGRP_IPV6_IFADDR 0x100
495 #define RTMGRP_IPV6_MROUTE 0x200
496 #define RTMGRP_IPV6_ROUTE 0x400
497 #define RTMGRP_IPV6_IFINFO 0x800
499 #define RTMGRP_DECnet_IFADDR 0x1000
500 #define RTMGRP_DECnet_ROUTE 0x4000
502 #define RTMGRP_IPV6_PREFIX 0x20000
505 /* RTnetlink multicast groups */
506 enum rtnetlink_groups {
508 #define RTNLGRP_NONE RTNLGRP_NONE
510 #define RTNLGRP_LINK RTNLGRP_LINK
512 #define RTNLGRP_NOTIFY RTNLGRP_NOTIFY
514 #define RTNLGRP_NEIGH RTNLGRP_NEIGH
516 #define RTNLGRP_TC RTNLGRP_TC
518 #define RTNLGRP_IPV4_IFADDR RTNLGRP_IPV4_IFADDR
520 #define RTNLGRP_IPV4_MROUTE RTNLGRP_IPV4_MROUTE
522 #define RTNLGRP_IPV4_ROUTE RTNLGRP_IPV4_ROUTE
524 #define RTNLGRP_IPV4_RULE RTNLGRP_IPV4_RULE
526 #define RTNLGRP_IPV6_IFADDR RTNLGRP_IPV6_IFADDR
528 #define RTNLGRP_IPV6_MROUTE RTNLGRP_IPV6_MROUTE
530 #define RTNLGRP_IPV6_ROUTE RTNLGRP_IPV6_ROUTE
532 #define RTNLGRP_IPV6_IFINFO RTNLGRP_IPV6_IFINFO
533 RTNLGRP_DECnet_IFADDR,
534 #define RTNLGRP_DECnet_IFADDR RTNLGRP_DECnet_IFADDR
536 RTNLGRP_DECnet_ROUTE,
537 #define RTNLGRP_DECnet_ROUTE RTNLGRP_DECnet_ROUTE
539 #define RTNLGRP_DECnet_RULE RTNLGRP_DECnet_RULE
542 #define RTNLGRP_IPV6_PREFIX RTNLGRP_IPV6_PREFIX
544 #define RTNLGRP_IPV6_RULE RTNLGRP_IPV6_RULE
547 #define RTNLGRP_MAX (__RTNLGRP_MAX - 1)
549 /* TC action piece */
552 unsigned char tca_family;
553 unsigned char tca__pad1;
554 unsigned short tca__pad2;
556 #define TA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcamsg))))
557 #define TA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcamsg))
558 #define TCA_ACT_TAB 1 /* attr type must be >=1 */
561 /* End of information exported to user level */
565 #include <linux/mutex.h>
567 extern size_t rtattr_strlcpy(char *dest, const struct rtattr *rta, size_t size);
568 static __inline__ int rtattr_strcmp(const struct rtattr *rta, const char *str)
570 int len = strlen(str) + 1;
571 return len > rta->rta_len || memcmp(RTA_DATA(rta), str, len);
574 extern int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len);
575 extern int __rtattr_parse_nested_compat(struct rtattr *tb[], int maxattr,
576 struct rtattr *rta, int len);
578 #define rtattr_parse_nested(tb, max, rta) \
579 rtattr_parse((tb), (max), RTA_DATA((rta)), RTA_PAYLOAD((rta)))
581 #define rtattr_parse_nested_compat(tb, max, rta, data, len) \
582 ({ data = RTA_PAYLOAD(rta) >= len ? RTA_DATA(rta) : NULL; \
583 __rtattr_parse_nested_compat(tb, max, rta, len); })
585 extern int rtnetlink_send(struct sk_buff *skb, u32 pid, u32 group, int echo);
586 extern int rtnl_unicast(struct sk_buff *skb, u32 pid);
587 extern int rtnl_notify(struct sk_buff *skb, u32 pid, u32 group,
588 struct nlmsghdr *nlh, gfp_t flags);
589 extern void rtnl_set_sk_err(u32 group, int error);
590 extern int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics);
591 extern int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst,
592 u32 id, u32 ts, u32 tsage, long expires,
595 extern void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data);
597 #define RTA_PUT(skb, attrtype, attrlen, data) \
598 ({ if (unlikely(skb_tailroom(skb) < (int)RTA_SPACE(attrlen))) \
599 goto rtattr_failure; \
600 __rta_fill(skb, attrtype, attrlen, data); })
602 #define RTA_APPEND(skb, attrlen, data) \
603 ({ if (unlikely(skb_tailroom(skb) < (int)(attrlen))) \
604 goto rtattr_failure; \
605 memcpy(skb_put(skb, attrlen), data, attrlen); })
607 #define RTA_PUT_NOHDR(skb, attrlen, data) \
608 ({ RTA_APPEND(skb, RTA_ALIGN(attrlen), data); \
609 memset(skb_tail_pointer(skb) - (RTA_ALIGN(attrlen) - attrlen), 0, \
610 RTA_ALIGN(attrlen) - attrlen); })
612 #define RTA_PUT_U8(skb, attrtype, value) \
613 ({ u8 _tmp = (value); \
614 RTA_PUT(skb, attrtype, sizeof(u8), &_tmp); })
616 #define RTA_PUT_U16(skb, attrtype, value) \
617 ({ u16 _tmp = (value); \
618 RTA_PUT(skb, attrtype, sizeof(u16), &_tmp); })
620 #define RTA_PUT_U32(skb, attrtype, value) \
621 ({ u32 _tmp = (value); \
622 RTA_PUT(skb, attrtype, sizeof(u32), &_tmp); })
624 #define RTA_PUT_U64(skb, attrtype, value) \
625 ({ u64 _tmp = (value); \
626 RTA_PUT(skb, attrtype, sizeof(u64), &_tmp); })
628 #define RTA_PUT_SECS(skb, attrtype, value) \
629 RTA_PUT_U64(skb, attrtype, (value) / HZ)
631 #define RTA_PUT_MSECS(skb, attrtype, value) \
632 RTA_PUT_U64(skb, attrtype, jiffies_to_msecs(value))
634 #define RTA_PUT_STRING(skb, attrtype, value) \
635 RTA_PUT(skb, attrtype, strlen(value) + 1, value)
637 #define RTA_PUT_FLAG(skb, attrtype) \
638 RTA_PUT(skb, attrtype, 0, NULL);
640 #define RTA_NEST(skb, type) \
641 ({ struct rtattr *__start = (struct rtattr *)skb_tail_pointer(skb); \
642 RTA_PUT(skb, type, 0, NULL); \
645 #define RTA_NEST_END(skb, start) \
646 ({ (start)->rta_len = skb_tail_pointer(skb) - (unsigned char *)(start); \
649 #define RTA_NEST_COMPAT(skb, type, attrlen, data) \
650 ({ struct rtattr *__start = (struct rtattr *)skb_tail_pointer(skb); \
651 RTA_PUT(skb, type, attrlen, data); \
652 RTA_NEST(skb, type); \
655 #define RTA_NEST_COMPAT_END(skb, start) \
656 ({ struct rtattr *__nest = (void *)(start) + NLMSG_ALIGN((start)->rta_len); \
657 (start)->rta_len = skb_tail_pointer(skb) - (unsigned char *)(start); \
658 RTA_NEST_END(skb, __nest); \
661 #define RTA_NEST_CANCEL(skb, start) \
663 skb_trim(skb, (unsigned char *) (start) - (skb)->data); \
666 #define RTA_GET_U8(rta) \
667 ({ if (!rta || RTA_PAYLOAD(rta) < sizeof(u8)) \
668 goto rtattr_failure; \
669 *(u8 *) RTA_DATA(rta); })
671 #define RTA_GET_U16(rta) \
672 ({ if (!rta || RTA_PAYLOAD(rta) < sizeof(u16)) \
673 goto rtattr_failure; \
674 *(u16 *) RTA_DATA(rta); })
676 #define RTA_GET_U32(rta) \
677 ({ if (!rta || RTA_PAYLOAD(rta) < sizeof(u32)) \
678 goto rtattr_failure; \
679 *(u32 *) RTA_DATA(rta); })
681 #define RTA_GET_U64(rta) \
683 if (!rta || RTA_PAYLOAD(rta) < sizeof(u64)) \
684 goto rtattr_failure; \
685 memcpy(&_tmp, RTA_DATA(rta), sizeof(_tmp)); \
688 #define RTA_GET_FLAG(rta) (!!(rta))
690 #define RTA_GET_SECS(rta) ((unsigned long) RTA_GET_U64(rta) * HZ)
691 #define RTA_GET_MSECS(rta) (msecs_to_jiffies((unsigned long) RTA_GET_U64(rta)))
693 static inline struct rtattr *
694 __rta_reserve(struct sk_buff *skb, int attrtype, int attrlen)
697 int size = RTA_LENGTH(attrlen);
699 rta = (struct rtattr*)skb_put(skb, RTA_ALIGN(size));
700 rta->rta_type = attrtype;
702 memset(RTA_DATA(rta) + attrlen, 0, RTA_ALIGN(size) - size);
706 #define __RTA_PUT(skb, attrtype, attrlen) \
707 ({ if (unlikely(skb_tailroom(skb) < (int)RTA_SPACE(attrlen))) \
708 goto rtattr_failure; \
709 __rta_reserve(skb, attrtype, attrlen); })
711 extern void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change);
713 /* RTNL is used as a global lock for all changes to network configuration */
714 extern void rtnl_lock(void);
715 extern void rtnl_unlock(void);
716 extern int rtnl_trylock(void);
718 extern void rtnetlink_init(void);
719 extern void __rtnl_unlock(void);
721 #define ASSERT_RTNL() do { \
722 if (unlikely(rtnl_trylock())) { \
724 printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \
725 __FILE__, __LINE__); \
730 #define BUG_TRAP(x) do { \
731 if (unlikely(!(x))) { \
732 printk(KERN_ERR "KERNEL: assertion (%s) failed at %s (%d)\n", \
733 #x, __FILE__ , __LINE__); \
737 static inline u32 rtm_get_table(struct rtattr **rta, u8 table)
739 return RTA_GET_U32(rta[RTA_TABLE-1]);
744 #endif /* __KERNEL__ */
747 #endif /* __LINUX_RTNETLINK_H */