1 #ifndef __LINUX_RTNETLINK_H
2 #define __LINUX_RTNETLINK_H
4 #include <linux/netlink.h>
7 * Routing/neighbour discovery messages.
10 /* Types of messages */
14 #define RTM_BASE RTM_BASE
17 #define RTM_NEWLINK RTM_NEWLINK
19 #define RTM_DELLINK RTM_DELLINK
21 #define RTM_GETLINK RTM_GETLINK
23 #define RTM_SETLINK RTM_SETLINK
26 #define RTM_NEWADDR RTM_NEWADDR
28 #define RTM_DELADDR RTM_DELADDR
30 #define RTM_GETADDR RTM_GETADDR
33 #define RTM_NEWROUTE RTM_NEWROUTE
35 #define RTM_DELROUTE RTM_DELROUTE
37 #define RTM_GETROUTE RTM_GETROUTE
40 #define RTM_NEWNEIGH RTM_NEWNEIGH
42 #define RTM_DELNEIGH RTM_DELNEIGH
44 #define RTM_GETNEIGH RTM_GETNEIGH
47 #define RTM_NEWRULE RTM_NEWRULE
49 #define RTM_DELRULE RTM_DELRULE
51 #define RTM_GETRULE RTM_GETRULE
54 #define RTM_NEWQDISC RTM_NEWQDISC
56 #define RTM_DELQDISC RTM_DELQDISC
58 #define RTM_GETQDISC RTM_GETQDISC
61 #define RTM_NEWTCLASS RTM_NEWTCLASS
63 #define RTM_DELTCLASS RTM_DELTCLASS
65 #define RTM_GETTCLASS RTM_GETTCLASS
68 #define RTM_NEWTFILTER RTM_NEWTFILTER
70 #define RTM_DELTFILTER RTM_DELTFILTER
72 #define RTM_GETTFILTER RTM_GETTFILTER
75 #define RTM_NEWACTION RTM_NEWACTION
77 #define RTM_DELACTION RTM_DELACTION
79 #define RTM_GETACTION RTM_GETACTION
82 #define RTM_NEWPREFIX RTM_NEWPREFIX
84 #define RTM_GETPREFIX RTM_GETPREFIX
86 RTM_GETMULTICAST = 58,
87 #define RTM_GETMULTICAST RTM_GETMULTICAST
90 #define RTM_GETANYCAST RTM_GETANYCAST
93 #define RTM_MAX RTM_MAX
97 Generic structure for encapsulation of optional route information.
98 It is reminiscent of sockaddr, but with sa_family replaced
104 unsigned short rta_len;
105 unsigned short rta_type;
108 /* Macros to handle rtattributes */
110 #define RTA_ALIGNTO 4
111 #define RTA_ALIGN(len) ( ((len)+RTA_ALIGNTO-1) & ~(RTA_ALIGNTO-1) )
112 #define RTA_OK(rta,len) ((len) >= (int)sizeof(struct rtattr) && \
113 (rta)->rta_len >= sizeof(struct rtattr) && \
114 (rta)->rta_len <= (len))
115 #define RTA_NEXT(rta,attrlen) ((attrlen) -= RTA_ALIGN((rta)->rta_len), \
116 (struct rtattr*)(((char*)(rta)) + RTA_ALIGN((rta)->rta_len)))
117 #define RTA_LENGTH(len) (RTA_ALIGN(sizeof(struct rtattr)) + (len))
118 #define RTA_SPACE(len) RTA_ALIGN(RTA_LENGTH(len))
119 #define RTA_DATA(rta) ((void*)(((char*)(rta)) + RTA_LENGTH(0)))
120 #define RTA_PAYLOAD(rta) ((int)((rta)->rta_len) - RTA_LENGTH(0))
125 /******************************************************************************
126 * Definitions used in routing table administration.
131 unsigned char rtm_family;
132 unsigned char rtm_dst_len;
133 unsigned char rtm_src_len;
134 unsigned char rtm_tos;
136 unsigned char rtm_table; /* Routing table id */
137 unsigned char rtm_protocol; /* Routing protocol; see below */
138 unsigned char rtm_scope; /* See below */
139 unsigned char rtm_type; /* See below */
149 RTN_UNICAST, /* Gateway or direct route */
150 RTN_LOCAL, /* Accept locally */
151 RTN_BROADCAST, /* Accept locally as broadcast,
153 RTN_ANYCAST, /* Accept locally as broadcast,
154 but send as unicast */
155 RTN_MULTICAST, /* Multicast route */
156 RTN_BLACKHOLE, /* Drop */
157 RTN_UNREACHABLE, /* Destination is unreachable */
158 RTN_PROHIBIT, /* Administratively prohibited */
159 RTN_THROW, /* Not in this table */
160 RTN_NAT, /* Translate this address */
161 RTN_XRESOLVE, /* Use external resolver */
165 #define RTN_MAX (__RTN_MAX - 1)
170 #define RTPROT_UNSPEC 0
171 #define RTPROT_REDIRECT 1 /* Route installed by ICMP redirects;
172 not used by current IPv4 */
173 #define RTPROT_KERNEL 2 /* Route installed by kernel */
174 #define RTPROT_BOOT 3 /* Route installed during boot */
175 #define RTPROT_STATIC 4 /* Route installed by administrator */
177 /* Values of protocol >= RTPROT_STATIC are not interpreted by kernel;
178 they are just passed from user and back as is.
179 It will be used by hypothetical multiple routing daemons.
180 Note that protocol values should be standardized in order to
184 #define RTPROT_GATED 8 /* Apparently, GateD */
185 #define RTPROT_RA 9 /* RDISC/ND router advertisements */
186 #define RTPROT_MRT 10 /* Merit MRT */
187 #define RTPROT_ZEBRA 11 /* Zebra */
188 #define RTPROT_BIRD 12 /* BIRD */
189 #define RTPROT_DNROUTED 13 /* DECnet routing daemon */
190 #define RTPROT_XORP 14 /* XORP */
194 Really it is not scope, but sort of distance to the destination.
195 NOWHERE are reserved for not existing destinations, HOST is our
196 local addresses, LINK are destinations, located on directly attached
197 link and UNIVERSE is everywhere in the Universe.
199 Intermediate values are also possible f.e. interior routes
200 could be assigned a value between UNIVERSE and LINK.
206 /* User defined values */
215 #define RTM_F_NOTIFY 0x100 /* Notify user of route change */
216 #define RTM_F_CLONED 0x200 /* This route is cloned */
217 #define RTM_F_EQUALIZE 0x400 /* Multipath equalizer: NI */
218 #define RTM_F_PREFIX 0x800 /* Prefix addresses */
220 /* Reserved table identifiers */
225 /* User defined values */
226 RT_TABLE_DEFAULT=253,
231 #define RT_TABLE_MAX (__RT_TABLE_MAX - 1)
235 /* Routing message attributes */
257 #define RTA_MAX (__RTA_MAX - 1)
259 #define RTM_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))))
260 #define RTM_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct rtmsg))
262 /* RTM_MULTIPATH --- array of struct rtnexthop.
264 * "struct rtnexthop" describes all necessary nexthop information,
265 * i.e. parameters of path to a destination via this nexthop.
267 * At the moment it is impossible to set different prefsrc, mtu, window
268 * and rtt for different paths from multipath.
273 unsigned short rtnh_len;
274 unsigned char rtnh_flags;
275 unsigned char rtnh_hops;
281 #define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
282 #define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
283 #define RTNH_F_ONLINK 4 /* Gateway is forced on link */
285 /* Macros to handle hexthops */
287 #define RTNH_ALIGNTO 4
288 #define RTNH_ALIGN(len) ( ((len)+RTNH_ALIGNTO-1) & ~(RTNH_ALIGNTO-1) )
289 #define RTNH_OK(rtnh,len) ((rtnh)->rtnh_len >= sizeof(struct rtnexthop) && \
290 ((int)(rtnh)->rtnh_len) <= (len))
291 #define RTNH_NEXT(rtnh) ((struct rtnexthop*)(((char*)(rtnh)) + RTNH_ALIGN((rtnh)->rtnh_len)))
292 #define RTNH_LENGTH(len) (RTNH_ALIGN(sizeof(struct rtnexthop)) + (len))
293 #define RTNH_SPACE(len) RTNH_ALIGN(RTNH_LENGTH(len))
294 #define RTNH_DATA(rtnh) ((struct rtattr*)(((char*)(rtnh)) + RTNH_LENGTH(0)))
306 #define RTNETLINK_HAVE_PEERINFO 1
312 /* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
317 #define RTAX_UNSPEC RTAX_UNSPEC
319 #define RTAX_LOCK RTAX_LOCK
321 #define RTAX_MTU RTAX_MTU
323 #define RTAX_WINDOW RTAX_WINDOW
325 #define RTAX_RTT RTAX_RTT
327 #define RTAX_RTTVAR RTAX_RTTVAR
329 #define RTAX_SSTHRESH RTAX_SSTHRESH
331 #define RTAX_CWND RTAX_CWND
333 #define RTAX_ADVMSS RTAX_ADVMSS
335 #define RTAX_REORDERING RTAX_REORDERING
337 #define RTAX_HOPLIMIT RTAX_HOPLIMIT
339 #define RTAX_INITCWND RTAX_INITCWND
341 #define RTAX_FEATURES RTAX_FEATURES
345 #define RTAX_MAX (__RTAX_MAX - 1)
347 #define RTAX_FEATURE_ECN 0x00000001
348 #define RTAX_FEATURE_SACK 0x00000002
349 #define RTAX_FEATURE_TIMESTAMP 0x00000004
350 #define RTAX_FEATURE_ALLFRAG 0x00000008
373 /*********************************************************
379 unsigned char ifa_family;
380 unsigned char ifa_prefixlen; /* The prefix length */
381 unsigned char ifa_flags; /* Flags */
382 unsigned char ifa_scope; /* See above */
383 int ifa_index; /* Link index */
399 #define IFA_MAX (__IFA_MAX - 1)
403 #define IFA_F_SECONDARY 0x01
404 #define IFA_F_TEMPORARY IFA_F_SECONDARY
406 #define IFA_F_DEPRECATED 0x20
407 #define IFA_F_TENTATIVE 0x40
408 #define IFA_F_PERMANENT 0x80
414 __u32 cstamp; /* created timestamp, hundredths of seconds */
415 __u32 tstamp; /* updated timestamp, hundredths of seconds */
419 #define IFA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
420 #define IFA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifaddrmsg))
424 IFA_ADDRESS is prefix address, rather than local interface address.
425 It makes no difference for normally configured broadcast interfaces,
426 but for point-to-point IFA_ADDRESS is DESTINATION address,
427 local address is supplied in IFA_LOCAL attribute.
430 /**************************************************************
431 * Neighbour discovery.
436 unsigned char ndm_family;
437 unsigned char ndm_pad1;
438 unsigned short ndm_pad2;
439 int ndm_ifindex; /* Link index */
455 #define NDA_MAX (__NDA_MAX - 1)
457 #define NDA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
458 #define NDA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ndmsg))
461 * Neighbor Cache Entry Flags
464 #define NTF_PROXY 0x08 /* == ATF_PUBL */
465 #define NTF_ROUTER 0x80
468 * Neighbor Cache Entry States.
471 #define NUD_INCOMPLETE 0x01
472 #define NUD_REACHABLE 0x02
473 #define NUD_STALE 0x04
474 #define NUD_DELAY 0x08
475 #define NUD_PROBE 0x10
476 #define NUD_FAILED 0x20
479 #define NUD_NOARP 0x40
480 #define NUD_PERMANENT 0x80
481 #define NUD_NONE 0x00
493 * General form of address family dependent message.
498 unsigned char rtgen_family;
501 /*****************************************************************
502 * Link layer specific messages.
506 * passes link level specific information, not dependent
507 * on network protocol.
512 unsigned char ifi_family;
513 unsigned char __ifi_pad;
514 unsigned short ifi_type; /* ARPHRD_* */
515 int ifi_index; /* Link index */
516 unsigned ifi_flags; /* IFF_* flags */
517 unsigned ifi_change; /* IFF_* change mask */
520 /********************************************************************
526 unsigned char prefix_family;
528 unsigned char prefix_type;
529 unsigned char prefix_len;
530 unsigned char prefix_flags;
541 #define PREFIX_MAX (__PREFIX_MAX - 1)
543 struct prefix_cacheinfo
545 __u32 preferred_time;
549 /* The struct should be in sync with struct net_device_stats */
550 struct rtnl_link_stats
552 __u32 rx_packets; /* total packets received */
553 __u32 tx_packets; /* total packets transmitted */
554 __u32 rx_bytes; /* total bytes received */
555 __u32 tx_bytes; /* total bytes transmitted */
556 __u32 rx_errors; /* bad packets received */
557 __u32 tx_errors; /* packet transmit problems */
558 __u32 rx_dropped; /* no space in linux buffers */
559 __u32 tx_dropped; /* no space available in linux */
560 __u32 multicast; /* multicast packets received */
563 /* detailed rx_errors: */
564 __u32 rx_length_errors;
565 __u32 rx_over_errors; /* receiver ring buff overflow */
566 __u32 rx_crc_errors; /* recved pkt with crc error */
567 __u32 rx_frame_errors; /* recv'd frame alignment error */
568 __u32 rx_fifo_errors; /* recv'r fifo overrun */
569 __u32 rx_missed_errors; /* receiver missed packet */
571 /* detailed tx_errors */
572 __u32 tx_aborted_errors;
573 __u32 tx_carrier_errors;
574 __u32 tx_fifo_errors;
575 __u32 tx_heartbeat_errors;
576 __u32 tx_window_errors;
583 /* The struct should be in sync with struct ifmap */
584 struct rtnl_link_ifmap
605 #define IFLA_COST IFLA_COST
607 #define IFLA_PRIORITY IFLA_PRIORITY
609 #define IFLA_MASTER IFLA_MASTER
610 IFLA_WIRELESS, /* Wireless Extension event - see wireless.h */
611 #define IFLA_WIRELESS IFLA_WIRELESS
612 IFLA_PROTINFO, /* Protocol specific information for a link */
613 #define IFLA_PROTINFO IFLA_PROTINFO
615 #define IFLA_TXQLEN IFLA_TXQLEN
617 #define IFLA_MAP IFLA_MAP
619 #define IFLA_WEIGHT IFLA_WEIGHT
624 #define IFLA_MAX (__IFLA_MAX - 1)
626 #define IFLA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
627 #define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
634 IFF_LOOPBACK, IFF_BROADCAST and IFF_POINTOPOINT are
635 more not changeable by user. They describe link media
636 characteristics and set by device driver.
639 - Combination IFF_BROADCAST|IFF_POINTOPOINT is invalid
640 - If neither of these three flags are set;
641 the interface is NBMA.
643 - IFF_MULTICAST does not mean anything special:
644 multicasts can be used on all not-NBMA links.
645 IFF_MULTICAST means that this media uses special encapsulation
646 for multicast frames. Apparently, all IFF_POINTOPOINT and
647 IFF_BROADCAST devices are able to use multicasts too.
651 For usual devices it is equal ifi_index.
652 If it is a "virtual interface" (f.e. tunnel), ifi_link
653 can point to real physical interface (f.e. for bandwidth calculations),
654 or maybe 0, what means, that real media is unknown (usual
655 for IPIP tunnels, when route to endpoint is allowed to change)
658 /* Subtype attributes for IFLA_PROTINFO */
662 IFLA_INET6_FLAGS, /* link flags */
663 IFLA_INET6_CONF, /* sysctl parameters */
664 IFLA_INET6_STATS, /* statistics */
665 IFLA_INET6_MCAST, /* MC things. What of them? */
666 IFLA_INET6_CACHEINFO, /* time values and max reasm size */
670 #define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
672 struct ifla_cacheinfo
675 __u32 tstamp; /* ipv6InterfaceTable updated timestamp */
676 __u32 reachable_time;
680 /*****************************************************************
681 * Traffic control messages.
686 unsigned char tcm_family;
687 unsigned char tcm__pad1;
688 unsigned short tcm__pad2;
708 #define TCA_MAX (__TCA_MAX - 1)
710 #define TCA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcmsg))))
711 #define TCA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcmsg))
714 /* RTnetlink multicast groups */
716 #define RTMGRP_LINK 1
717 #define RTMGRP_NOTIFY 2
718 #define RTMGRP_NEIGH 4
721 #define RTMGRP_IPV4_IFADDR 0x10
722 #define RTMGRP_IPV4_MROUTE 0x20
723 #define RTMGRP_IPV4_ROUTE 0x40
725 #define RTMGRP_IPV6_IFADDR 0x100
726 #define RTMGRP_IPV6_MROUTE 0x200
727 #define RTMGRP_IPV6_ROUTE 0x400
728 #define RTMGRP_IPV6_IFINFO 0x800
730 #define RTMGRP_DECnet_IFADDR 0x1000
731 #define RTMGRP_DECnet_ROUTE 0x4000
733 #define RTMGRP_IPV6_PREFIX 0x20000
735 /* TC action piece */
738 unsigned char tca_family;
739 unsigned char tca__pad1;
740 unsigned short tca__pad2;
742 #define TA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcamsg))))
743 #define TA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcamsg))
744 #define TCA_ACT_TAB 1 /* attr type must be >=1 */
747 /* End of information exported to user level */
751 #include <linux/config.h>
753 extern size_t rtattr_strlcpy(char *dest, const struct rtattr *rta, size_t size);
754 static __inline__ int rtattr_strcmp(const struct rtattr *rta, const char *str)
756 int len = strlen(str) + 1;
757 return len > rta->rta_len || memcmp(RTA_DATA(rta), str, len);
760 extern int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len);
762 #define rtattr_parse_nested(tb, max, rta) \
763 rtattr_parse((tb), (max), RTA_DATA((rta)), RTA_PAYLOAD((rta)))
765 extern struct sock *rtnl;
767 struct rtnetlink_link
769 int (*doit)(struct sk_buff *, struct nlmsghdr*, void *attr);
770 int (*dumpit)(struct sk_buff *, struct netlink_callback *cb);
773 extern struct rtnetlink_link * rtnetlink_links[NPROTO];
774 extern int rtnetlink_send(struct sk_buff *skb, u32 pid, u32 group, int echo);
775 extern int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics);
777 extern void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data);
779 #define RTA_PUT(skb, attrtype, attrlen, data) \
780 ({ if (unlikely(skb_tailroom(skb) < (int)RTA_SPACE(attrlen))) \
781 goto rtattr_failure; \
782 __rta_fill(skb, attrtype, attrlen, data); })
784 #define RTA_PUT_NOHDR(skb, attrlen, data) \
785 ({ if (unlikely(skb_tailroom(skb) < (int)(attrlen))) \
786 goto rtattr_failure; \
787 memcpy(skb_put(skb, RTA_ALIGN(attrlen)), data, attrlen); })
789 static inline struct rtattr *
790 __rta_reserve(struct sk_buff *skb, int attrtype, int attrlen)
793 int size = RTA_LENGTH(attrlen);
795 rta = (struct rtattr*)skb_put(skb, RTA_ALIGN(size));
796 rta->rta_type = attrtype;
801 #define __RTA_PUT(skb, attrtype, attrlen) \
802 ({ if (unlikely(skb_tailroom(skb) < (int)RTA_SPACE(attrlen))) \
803 goto rtattr_failure; \
804 __rta_reserve(skb, attrtype, attrlen); })
806 extern void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change);
808 extern struct semaphore rtnl_sem;
810 #define rtnl_shlock() down(&rtnl_sem)
811 #define rtnl_shlock_nowait() down_trylock(&rtnl_sem)
813 #define rtnl_shunlock() do { up(&rtnl_sem); \
814 if (rtnl && rtnl->sk_receive_queue.qlen) \
815 rtnl->sk_data_ready(rtnl, 0); \
818 extern void rtnl_lock(void);
819 extern int rtnl_lock_interruptible(void);
820 extern void rtnl_unlock(void);
821 extern void rtnetlink_init(void);
823 #define ASSERT_RTNL() do { \
824 if (unlikely(down_trylock(&rtnl_sem) == 0)) { \
826 printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \
827 __FILE__, __LINE__); \
832 #define BUG_TRAP(x) do { \
833 if (unlikely(!(x))) { \
834 printk(KERN_ERR "KERNEL: assertion (%s) failed at %s (%d)\n", \
835 #x, __FILE__ , __LINE__); \
839 #endif /* __KERNEL__ */
842 #endif /* __LINUX_RTNETLINK_H */