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 + 3) & ~3) - 1)
96 #define RTM_NR_MSGTYPES (RTM_MAX + 1 - RTM_BASE)
97 #define RTM_NR_FAMILIES (RTM_NR_MSGTYPES >> 2)
98 #define RTM_FAM(cmd) (((cmd) - RTM_BASE) >> 2)
101 Generic structure for encapsulation of optional route information.
102 It is reminiscent of sockaddr, but with sa_family replaced
108 unsigned short rta_len
;
109 unsigned short rta_type
;
112 /* Macros to handle rtattributes */
114 #define RTA_ALIGNTO 4
115 #define RTA_ALIGN(len) ( ((len)+RTA_ALIGNTO-1) & ~(RTA_ALIGNTO-1) )
116 #define RTA_OK(rta,len) ((len) >= (int)sizeof(struct rtattr) && \
117 (rta)->rta_len >= sizeof(struct rtattr) && \
118 (rta)->rta_len <= (len))
119 #define RTA_NEXT(rta,attrlen) ((attrlen) -= RTA_ALIGN((rta)->rta_len), \
120 (struct rtattr*)(((char*)(rta)) + RTA_ALIGN((rta)->rta_len)))
121 #define RTA_LENGTH(len) (RTA_ALIGN(sizeof(struct rtattr)) + (len))
122 #define RTA_SPACE(len) RTA_ALIGN(RTA_LENGTH(len))
123 #define RTA_DATA(rta) ((void*)(((char*)(rta)) + RTA_LENGTH(0)))
124 #define RTA_PAYLOAD(rta) ((int)((rta)->rta_len) - RTA_LENGTH(0))
129 /******************************************************************************
130 * Definitions used in routing table administration.
135 unsigned char rtm_family
;
136 unsigned char rtm_dst_len
;
137 unsigned char rtm_src_len
;
138 unsigned char rtm_tos
;
140 unsigned char rtm_table
; /* Routing table id */
141 unsigned char rtm_protocol
; /* Routing protocol; see below */
142 unsigned char rtm_scope
; /* See below */
143 unsigned char rtm_type
; /* See below */
153 RTN_UNICAST
, /* Gateway or direct route */
154 RTN_LOCAL
, /* Accept locally */
155 RTN_BROADCAST
, /* Accept locally as broadcast,
157 RTN_ANYCAST
, /* Accept locally as broadcast,
158 but send as unicast */
159 RTN_MULTICAST
, /* Multicast route */
160 RTN_BLACKHOLE
, /* Drop */
161 RTN_UNREACHABLE
, /* Destination is unreachable */
162 RTN_PROHIBIT
, /* Administratively prohibited */
163 RTN_THROW
, /* Not in this table */
164 RTN_NAT
, /* Translate this address */
165 RTN_XRESOLVE
, /* Use external resolver */
169 #define RTN_MAX (__RTN_MAX - 1)
174 #define RTPROT_UNSPEC 0
175 #define RTPROT_REDIRECT 1 /* Route installed by ICMP redirects;
176 not used by current IPv4 */
177 #define RTPROT_KERNEL 2 /* Route installed by kernel */
178 #define RTPROT_BOOT 3 /* Route installed during boot */
179 #define RTPROT_STATIC 4 /* Route installed by administrator */
181 /* Values of protocol >= RTPROT_STATIC are not interpreted by kernel;
182 they are just passed from user and back as is.
183 It will be used by hypothetical multiple routing daemons.
184 Note that protocol values should be standardized in order to
188 #define RTPROT_GATED 8 /* Apparently, GateD */
189 #define RTPROT_RA 9 /* RDISC/ND router advertisements */
190 #define RTPROT_MRT 10 /* Merit MRT */
191 #define RTPROT_ZEBRA 11 /* Zebra */
192 #define RTPROT_BIRD 12 /* BIRD */
193 #define RTPROT_DNROUTED 13 /* DECnet routing daemon */
194 #define RTPROT_XORP 14 /* XORP */
198 Really it is not scope, but sort of distance to the destination.
199 NOWHERE are reserved for not existing destinations, HOST is our
200 local addresses, LINK are destinations, located on directly attached
201 link and UNIVERSE is everywhere in the Universe.
203 Intermediate values are also possible f.e. interior routes
204 could be assigned a value between UNIVERSE and LINK.
210 /* User defined values */
219 #define RTM_F_NOTIFY 0x100 /* Notify user of route change */
220 #define RTM_F_CLONED 0x200 /* This route is cloned */
221 #define RTM_F_EQUALIZE 0x400 /* Multipath equalizer: NI */
222 #define RTM_F_PREFIX 0x800 /* Prefix addresses */
224 /* Reserved table identifiers */
229 /* User defined values */
230 RT_TABLE_DEFAULT
=253,
235 #define RT_TABLE_MAX (__RT_TABLE_MAX - 1)
239 /* Routing message attributes */
261 #define RTA_MAX (__RTA_MAX - 1)
263 #define RTM_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))))
264 #define RTM_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct rtmsg))
266 /* RTM_MULTIPATH --- array of struct rtnexthop.
268 * "struct rtnexthop" describes all necessary nexthop information,
269 * i.e. parameters of path to a destination via this nexthop.
271 * At the moment it is impossible to set different prefsrc, mtu, window
272 * and rtt for different paths from multipath.
277 unsigned short rtnh_len
;
278 unsigned char rtnh_flags
;
279 unsigned char rtnh_hops
;
285 #define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
286 #define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
287 #define RTNH_F_ONLINK 4 /* Gateway is forced on link */
289 /* Macros to handle hexthops */
291 #define RTNH_ALIGNTO 4
292 #define RTNH_ALIGN(len) ( ((len)+RTNH_ALIGNTO-1) & ~(RTNH_ALIGNTO-1) )
293 #define RTNH_OK(rtnh,len) ((rtnh)->rtnh_len >= sizeof(struct rtnexthop) && \
294 ((int)(rtnh)->rtnh_len) <= (len))
295 #define RTNH_NEXT(rtnh) ((struct rtnexthop*)(((char*)(rtnh)) + RTNH_ALIGN((rtnh)->rtnh_len)))
296 #define RTNH_LENGTH(len) (RTNH_ALIGN(sizeof(struct rtnexthop)) + (len))
297 #define RTNH_SPACE(len) RTNH_ALIGN(RTNH_LENGTH(len))
298 #define RTNH_DATA(rtnh) ((struct rtattr*)(((char*)(rtnh)) + RTNH_LENGTH(0)))
310 #define RTNETLINK_HAVE_PEERINFO 1
316 /* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
321 #define RTAX_UNSPEC RTAX_UNSPEC
323 #define RTAX_LOCK RTAX_LOCK
325 #define RTAX_MTU RTAX_MTU
327 #define RTAX_WINDOW RTAX_WINDOW
329 #define RTAX_RTT RTAX_RTT
331 #define RTAX_RTTVAR RTAX_RTTVAR
333 #define RTAX_SSTHRESH RTAX_SSTHRESH
335 #define RTAX_CWND RTAX_CWND
337 #define RTAX_ADVMSS RTAX_ADVMSS
339 #define RTAX_REORDERING RTAX_REORDERING
341 #define RTAX_HOPLIMIT RTAX_HOPLIMIT
343 #define RTAX_INITCWND RTAX_INITCWND
345 #define RTAX_FEATURES RTAX_FEATURES
349 #define RTAX_MAX (__RTAX_MAX - 1)
351 #define RTAX_FEATURE_ECN 0x00000001
352 #define RTAX_FEATURE_SACK 0x00000002
353 #define RTAX_FEATURE_TIMESTAMP 0x00000004
354 #define RTAX_FEATURE_ALLFRAG 0x00000008
377 /*********************************************************
383 unsigned char ifa_family
;
384 unsigned char ifa_prefixlen
; /* The prefix length */
385 unsigned char ifa_flags
; /* Flags */
386 unsigned char ifa_scope
; /* See above */
387 int ifa_index
; /* Link index */
403 #define IFA_MAX (__IFA_MAX - 1)
407 #define IFA_F_SECONDARY 0x01
408 #define IFA_F_TEMPORARY IFA_F_SECONDARY
410 #define IFA_F_DEPRECATED 0x20
411 #define IFA_F_TENTATIVE 0x40
412 #define IFA_F_PERMANENT 0x80
418 __u32 cstamp
; /* created timestamp, hundredths of seconds */
419 __u32 tstamp
; /* updated timestamp, hundredths of seconds */
423 #define IFA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
424 #define IFA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifaddrmsg))
428 IFA_ADDRESS is prefix address, rather than local interface address.
429 It makes no difference for normally configured broadcast interfaces,
430 but for point-to-point IFA_ADDRESS is DESTINATION address,
431 local address is supplied in IFA_LOCAL attribute.
434 /**************************************************************
435 * Neighbour discovery.
440 unsigned char ndm_family
;
441 unsigned char ndm_pad1
;
442 unsigned short ndm_pad2
;
443 int ndm_ifindex
; /* Link index */
459 #define NDA_MAX (__NDA_MAX - 1)
461 #define NDA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
462 #define NDA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ndmsg))
465 * Neighbor Cache Entry Flags
468 #define NTF_PROXY 0x08 /* == ATF_PUBL */
469 #define NTF_ROUTER 0x80
472 * Neighbor Cache Entry States.
475 #define NUD_INCOMPLETE 0x01
476 #define NUD_REACHABLE 0x02
477 #define NUD_STALE 0x04
478 #define NUD_DELAY 0x08
479 #define NUD_PROBE 0x10
480 #define NUD_FAILED 0x20
483 #define NUD_NOARP 0x40
484 #define NUD_PERMANENT 0x80
485 #define NUD_NONE 0x00
497 * General form of address family dependent message.
502 unsigned char rtgen_family
;
505 /*****************************************************************
506 * Link layer specific messages.
510 * passes link level specific information, not dependent
511 * on network protocol.
516 unsigned char ifi_family
;
517 unsigned char __ifi_pad
;
518 unsigned short ifi_type
; /* ARPHRD_* */
519 int ifi_index
; /* Link index */
520 unsigned ifi_flags
; /* IFF_* flags */
521 unsigned ifi_change
; /* IFF_* change mask */
524 /********************************************************************
530 unsigned char prefix_family
;
532 unsigned char prefix_type
;
533 unsigned char prefix_len
;
534 unsigned char prefix_flags
;
545 #define PREFIX_MAX (__PREFIX_MAX - 1)
547 struct prefix_cacheinfo
549 __u32 preferred_time
;
553 /* The struct should be in sync with struct net_device_stats */
554 struct rtnl_link_stats
556 __u32 rx_packets
; /* total packets received */
557 __u32 tx_packets
; /* total packets transmitted */
558 __u32 rx_bytes
; /* total bytes received */
559 __u32 tx_bytes
; /* total bytes transmitted */
560 __u32 rx_errors
; /* bad packets received */
561 __u32 tx_errors
; /* packet transmit problems */
562 __u32 rx_dropped
; /* no space in linux buffers */
563 __u32 tx_dropped
; /* no space available in linux */
564 __u32 multicast
; /* multicast packets received */
567 /* detailed rx_errors: */
568 __u32 rx_length_errors
;
569 __u32 rx_over_errors
; /* receiver ring buff overflow */
570 __u32 rx_crc_errors
; /* recved pkt with crc error */
571 __u32 rx_frame_errors
; /* recv'd frame alignment error */
572 __u32 rx_fifo_errors
; /* recv'r fifo overrun */
573 __u32 rx_missed_errors
; /* receiver missed packet */
575 /* detailed tx_errors */
576 __u32 tx_aborted_errors
;
577 __u32 tx_carrier_errors
;
578 __u32 tx_fifo_errors
;
579 __u32 tx_heartbeat_errors
;
580 __u32 tx_window_errors
;
587 /* The struct should be in sync with struct ifmap */
588 struct rtnl_link_ifmap
609 #define IFLA_COST IFLA_COST
611 #define IFLA_PRIORITY IFLA_PRIORITY
613 #define IFLA_MASTER IFLA_MASTER
614 IFLA_WIRELESS
, /* Wireless Extension event - see wireless.h */
615 #define IFLA_WIRELESS IFLA_WIRELESS
616 IFLA_PROTINFO
, /* Protocol specific information for a link */
617 #define IFLA_PROTINFO IFLA_PROTINFO
619 #define IFLA_TXQLEN IFLA_TXQLEN
621 #define IFLA_MAP IFLA_MAP
623 #define IFLA_WEIGHT IFLA_WEIGHT
628 #define IFLA_MAX (__IFLA_MAX - 1)
630 #define IFLA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
631 #define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
638 IFF_LOOPBACK, IFF_BROADCAST and IFF_POINTOPOINT are
639 more not changeable by user. They describe link media
640 characteristics and set by device driver.
643 - Combination IFF_BROADCAST|IFF_POINTOPOINT is invalid
644 - If neither of these three flags are set;
645 the interface is NBMA.
647 - IFF_MULTICAST does not mean anything special:
648 multicasts can be used on all not-NBMA links.
649 IFF_MULTICAST means that this media uses special encapsulation
650 for multicast frames. Apparently, all IFF_POINTOPOINT and
651 IFF_BROADCAST devices are able to use multicasts too.
655 For usual devices it is equal ifi_index.
656 If it is a "virtual interface" (f.e. tunnel), ifi_link
657 can point to real physical interface (f.e. for bandwidth calculations),
658 or maybe 0, what means, that real media is unknown (usual
659 for IPIP tunnels, when route to endpoint is allowed to change)
662 /* Subtype attributes for IFLA_PROTINFO */
666 IFLA_INET6_FLAGS
, /* link flags */
667 IFLA_INET6_CONF
, /* sysctl parameters */
668 IFLA_INET6_STATS
, /* statistics */
669 IFLA_INET6_MCAST
, /* MC things. What of them? */
670 IFLA_INET6_CACHEINFO
, /* time values and max reasm size */
674 #define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
676 struct ifla_cacheinfo
679 __u32 tstamp
; /* ipv6InterfaceTable updated timestamp */
680 __u32 reachable_time
;
684 /*****************************************************************
685 * Traffic control messages.
690 unsigned char tcm_family
;
691 unsigned char tcm__pad1
;
692 unsigned short tcm__pad2
;
712 #define TCA_MAX (__TCA_MAX - 1)
714 #define TCA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcmsg))))
715 #define TCA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcmsg))
718 /* RTnetlink multicast groups */
720 #define RTMGRP_LINK 1
721 #define RTMGRP_NOTIFY 2
722 #define RTMGRP_NEIGH 4
725 #define RTMGRP_IPV4_IFADDR 0x10
726 #define RTMGRP_IPV4_MROUTE 0x20
727 #define RTMGRP_IPV4_ROUTE 0x40
729 #define RTMGRP_IPV6_IFADDR 0x100
730 #define RTMGRP_IPV6_MROUTE 0x200
731 #define RTMGRP_IPV6_ROUTE 0x400
732 #define RTMGRP_IPV6_IFINFO 0x800
734 #define RTMGRP_DECnet_IFADDR 0x1000
735 #define RTMGRP_DECnet_ROUTE 0x4000
737 #define RTMGRP_IPV6_PREFIX 0x20000
739 /* TC action piece */
742 unsigned char tca_family
;
743 unsigned char tca__pad1
;
744 unsigned short tca__pad2
;
746 #define TA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcamsg))))
747 #define TA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcamsg))
748 #define TCA_ACT_TAB 1 /* attr type must be >=1 */
751 /* End of information exported to user level */
755 #include <linux/config.h>
757 extern size_t rtattr_strlcpy(char *dest
, const struct rtattr
*rta
, size_t size
);
758 static __inline__
int rtattr_strcmp(const struct rtattr
*rta
, const char *str
)
760 int len
= strlen(str
) + 1;
761 return len
> rta
->rta_len
|| memcmp(RTA_DATA(rta
), str
, len
);
764 extern int rtattr_parse(struct rtattr
*tb
[], int maxattr
, struct rtattr
*rta
, int len
);
766 #define rtattr_parse_nested(tb, max, rta) \
767 rtattr_parse((tb), (max), RTA_DATA((rta)), RTA_PAYLOAD((rta)))
769 extern struct sock
*rtnl
;
771 struct rtnetlink_link
773 int (*doit
)(struct sk_buff
*, struct nlmsghdr
*, void *attr
);
774 int (*dumpit
)(struct sk_buff
*, struct netlink_callback
*cb
);
777 extern struct rtnetlink_link
* rtnetlink_links
[NPROTO
];
778 extern int rtnetlink_send(struct sk_buff
*skb
, u32 pid
, u32 group
, int echo
);
779 extern int rtnetlink_put_metrics(struct sk_buff
*skb
, u32
*metrics
);
781 extern void __rta_fill(struct sk_buff
*skb
, int attrtype
, int attrlen
, const void *data
);
783 #define RTA_PUT(skb, attrtype, attrlen, data) \
784 ({ if (unlikely(skb_tailroom(skb) < (int)RTA_SPACE(attrlen))) \
785 goto rtattr_failure; \
786 __rta_fill(skb, attrtype, attrlen, data); })
788 #define RTA_PUT_NOHDR(skb, attrlen, data) \
789 ({ if (unlikely(skb_tailroom(skb) < (int)(attrlen))) \
790 goto rtattr_failure; \
791 memcpy(skb_put(skb, RTA_ALIGN(attrlen)), data, attrlen); })
793 static inline struct rtattr
*
794 __rta_reserve(struct sk_buff
*skb
, int attrtype
, int attrlen
)
797 int size
= RTA_LENGTH(attrlen
);
799 rta
= (struct rtattr
*)skb_put(skb
, RTA_ALIGN(size
));
800 rta
->rta_type
= attrtype
;
805 #define __RTA_PUT(skb, attrtype, attrlen) \
806 ({ if (unlikely(skb_tailroom(skb) < (int)RTA_SPACE(attrlen))) \
807 goto rtattr_failure; \
808 __rta_reserve(skb, attrtype, attrlen); })
810 extern void rtmsg_ifinfo(int type
, struct net_device
*dev
, unsigned change
);
812 extern struct semaphore rtnl_sem
;
814 #define rtnl_shlock() down(&rtnl_sem)
815 #define rtnl_shlock_nowait() down_trylock(&rtnl_sem)
817 #define rtnl_shunlock() do { up(&rtnl_sem); \
818 if (rtnl && rtnl->sk_receive_queue.qlen) \
819 rtnl->sk_data_ready(rtnl, 0); \
822 extern void rtnl_lock(void);
823 extern int rtnl_lock_interruptible(void);
824 extern void rtnl_unlock(void);
825 extern void rtnetlink_init(void);
827 #define ASSERT_RTNL() do { \
828 if (unlikely(down_trylock(&rtnl_sem) == 0)) { \
830 printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \
831 __FILE__, __LINE__); \
836 #define BUG_TRAP(x) do { \
837 if (unlikely(!(x))) { \
838 printk(KERN_ERR "KERNEL: assertion (%s) failed at %s (%d)\n", \
839 #x, __FILE__ , __LINE__); \
843 #endif /* __KERNEL__ */
846 #endif /* __LINUX_RTNETLINK_H */