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_NEWNEIGHTBL RTM_NEWNEIGHTBL
95 #define RTM_GETNEIGHTBL RTM_GETNEIGHTBL
97 #define RTM_SETNEIGHTBL RTM_SETNEIGHTBL
100 #define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1)
103 #define RTM_NR_MSGTYPES (RTM_MAX + 1 - RTM_BASE)
104 #define RTM_NR_FAMILIES (RTM_NR_MSGTYPES >> 2)
105 #define RTM_FAM(cmd) (((cmd) - RTM_BASE) >> 2)
108 Generic structure for encapsulation of optional route information.
109 It is reminiscent of sockaddr, but with sa_family replaced
115 unsigned short rta_len;
116 unsigned short rta_type;
119 /* Macros to handle rtattributes */
121 #define RTA_ALIGNTO 4
122 #define RTA_ALIGN(len) ( ((len)+RTA_ALIGNTO-1) & ~(RTA_ALIGNTO-1) )
123 #define RTA_OK(rta,len) ((len) >= (int)sizeof(struct rtattr) && \
124 (rta)->rta_len >= sizeof(struct rtattr) && \
125 (rta)->rta_len <= (len))
126 #define RTA_NEXT(rta,attrlen) ((attrlen) -= RTA_ALIGN((rta)->rta_len), \
127 (struct rtattr*)(((char*)(rta)) + RTA_ALIGN((rta)->rta_len)))
128 #define RTA_LENGTH(len) (RTA_ALIGN(sizeof(struct rtattr)) + (len))
129 #define RTA_SPACE(len) RTA_ALIGN(RTA_LENGTH(len))
130 #define RTA_DATA(rta) ((void*)(((char*)(rta)) + RTA_LENGTH(0)))
131 #define RTA_PAYLOAD(rta) ((int)((rta)->rta_len) - RTA_LENGTH(0))
136 /******************************************************************************
137 * Definitions used in routing table administration.
142 unsigned char rtm_family;
143 unsigned char rtm_dst_len;
144 unsigned char rtm_src_len;
145 unsigned char rtm_tos;
147 unsigned char rtm_table; /* Routing table id */
148 unsigned char rtm_protocol; /* Routing protocol; see below */
149 unsigned char rtm_scope; /* See below */
150 unsigned char rtm_type; /* See below */
160 RTN_UNICAST, /* Gateway or direct route */
161 RTN_LOCAL, /* Accept locally */
162 RTN_BROADCAST, /* Accept locally as broadcast,
164 RTN_ANYCAST, /* Accept locally as broadcast,
165 but send as unicast */
166 RTN_MULTICAST, /* Multicast route */
167 RTN_BLACKHOLE, /* Drop */
168 RTN_UNREACHABLE, /* Destination is unreachable */
169 RTN_PROHIBIT, /* Administratively prohibited */
170 RTN_THROW, /* Not in this table */
171 RTN_NAT, /* Translate this address */
172 RTN_XRESOLVE, /* Use external resolver */
176 #define RTN_MAX (__RTN_MAX - 1)
181 #define RTPROT_UNSPEC 0
182 #define RTPROT_REDIRECT 1 /* Route installed by ICMP redirects;
183 not used by current IPv4 */
184 #define RTPROT_KERNEL 2 /* Route installed by kernel */
185 #define RTPROT_BOOT 3 /* Route installed during boot */
186 #define RTPROT_STATIC 4 /* Route installed by administrator */
188 /* Values of protocol >= RTPROT_STATIC are not interpreted by kernel;
189 they are just passed from user and back as is.
190 It will be used by hypothetical multiple routing daemons.
191 Note that protocol values should be standardized in order to
195 #define RTPROT_GATED 8 /* Apparently, GateD */
196 #define RTPROT_RA 9 /* RDISC/ND router advertisements */
197 #define RTPROT_MRT 10 /* Merit MRT */
198 #define RTPROT_ZEBRA 11 /* Zebra */
199 #define RTPROT_BIRD 12 /* BIRD */
200 #define RTPROT_DNROUTED 13 /* DECnet routing daemon */
201 #define RTPROT_XORP 14 /* XORP */
205 Really it is not scope, but sort of distance to the destination.
206 NOWHERE are reserved for not existing destinations, HOST is our
207 local addresses, LINK are destinations, located on directly attached
208 link and UNIVERSE is everywhere in the Universe.
210 Intermediate values are also possible f.e. interior routes
211 could be assigned a value between UNIVERSE and LINK.
217 /* User defined values */
226 #define RTM_F_NOTIFY 0x100 /* Notify user of route change */
227 #define RTM_F_CLONED 0x200 /* This route is cloned */
228 #define RTM_F_EQUALIZE 0x400 /* Multipath equalizer: NI */
229 #define RTM_F_PREFIX 0x800 /* Prefix addresses */
231 /* Reserved table identifiers */
236 /* User defined values */
237 RT_TABLE_DEFAULT=253,
242 #define RT_TABLE_MAX (__RT_TABLE_MAX - 1)
246 /* Routing message attributes */
268 #define RTA_MAX (__RTA_MAX - 1)
270 #define RTM_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))))
271 #define RTM_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct rtmsg))
273 /* RTM_MULTIPATH --- array of struct rtnexthop.
275 * "struct rtnexthop" describes all necessary nexthop information,
276 * i.e. parameters of path to a destination via this nexthop.
278 * At the moment it is impossible to set different prefsrc, mtu, window
279 * and rtt for different paths from multipath.
284 unsigned short rtnh_len;
285 unsigned char rtnh_flags;
286 unsigned char rtnh_hops;
292 #define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
293 #define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
294 #define RTNH_F_ONLINK 4 /* Gateway is forced on link */
296 /* Macros to handle hexthops */
298 #define RTNH_ALIGNTO 4
299 #define RTNH_ALIGN(len) ( ((len)+RTNH_ALIGNTO-1) & ~(RTNH_ALIGNTO-1) )
300 #define RTNH_OK(rtnh,len) ((rtnh)->rtnh_len >= sizeof(struct rtnexthop) && \
301 ((int)(rtnh)->rtnh_len) <= (len))
302 #define RTNH_NEXT(rtnh) ((struct rtnexthop*)(((char*)(rtnh)) + RTNH_ALIGN((rtnh)->rtnh_len)))
303 #define RTNH_LENGTH(len) (RTNH_ALIGN(sizeof(struct rtnexthop)) + (len))
304 #define RTNH_SPACE(len) RTNH_ALIGN(RTNH_LENGTH(len))
305 #define RTNH_DATA(rtnh) ((struct rtattr*)(((char*)(rtnh)) + RTNH_LENGTH(0)))
317 #define RTNETLINK_HAVE_PEERINFO 1
323 /* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
328 #define RTAX_UNSPEC RTAX_UNSPEC
330 #define RTAX_LOCK RTAX_LOCK
332 #define RTAX_MTU RTAX_MTU
334 #define RTAX_WINDOW RTAX_WINDOW
336 #define RTAX_RTT RTAX_RTT
338 #define RTAX_RTTVAR RTAX_RTTVAR
340 #define RTAX_SSTHRESH RTAX_SSTHRESH
342 #define RTAX_CWND RTAX_CWND
344 #define RTAX_ADVMSS RTAX_ADVMSS
346 #define RTAX_REORDERING RTAX_REORDERING
348 #define RTAX_HOPLIMIT RTAX_HOPLIMIT
350 #define RTAX_INITCWND RTAX_INITCWND
352 #define RTAX_FEATURES RTAX_FEATURES
356 #define RTAX_MAX (__RTAX_MAX - 1)
358 #define RTAX_FEATURE_ECN 0x00000001
359 #define RTAX_FEATURE_SACK 0x00000002
360 #define RTAX_FEATURE_TIMESTAMP 0x00000004
361 #define RTAX_FEATURE_ALLFRAG 0x00000008
386 /*********************************************************
392 unsigned char ifa_family;
393 unsigned char ifa_prefixlen; /* The prefix length */
394 unsigned char ifa_flags; /* Flags */
395 unsigned char ifa_scope; /* See above */
396 int ifa_index; /* Link index */
412 #define IFA_MAX (__IFA_MAX - 1)
416 #define IFA_F_SECONDARY 0x01
417 #define IFA_F_TEMPORARY IFA_F_SECONDARY
419 #define IFA_F_DEPRECATED 0x20
420 #define IFA_F_TENTATIVE 0x40
421 #define IFA_F_PERMANENT 0x80
427 __u32 cstamp; /* created timestamp, hundredths of seconds */
428 __u32 tstamp; /* updated timestamp, hundredths of seconds */
432 #define IFA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
433 #define IFA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifaddrmsg))
437 IFA_ADDRESS is prefix address, rather than local interface address.
438 It makes no difference for normally configured broadcast interfaces,
439 but for point-to-point IFA_ADDRESS is DESTINATION address,
440 local address is supplied in IFA_LOCAL attribute.
443 /**************************************************************
444 * Neighbour discovery.
449 unsigned char ndm_family;
450 unsigned char ndm_pad1;
451 unsigned short ndm_pad2;
452 int ndm_ifindex; /* Link index */
468 #define NDA_MAX (__NDA_MAX - 1)
470 #define NDA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
471 #define NDA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ndmsg))
474 * Neighbor Cache Entry Flags
477 #define NTF_PROXY 0x08 /* == ATF_PUBL */
478 #define NTF_ROUTER 0x80
481 * Neighbor Cache Entry States.
484 #define NUD_INCOMPLETE 0x01
485 #define NUD_REACHABLE 0x02
486 #define NUD_STALE 0x04
487 #define NUD_DELAY 0x08
488 #define NUD_PROBE 0x10
489 #define NUD_FAILED 0x20
492 #define NUD_NOARP 0x40
493 #define NUD_PERMANENT 0x80
494 #define NUD_NONE 0x00
506 /*****************************************************************
507 * Neighbour tables specific messages.
509 * To retrieve the neighbour tables send RTM_GETNEIGHTBL with the
510 * NLM_F_DUMP flag set. Every neighbour table configuration is
511 * spread over multiple messages to avoid running into message
512 * size limits on systems with many interfaces. The first message
513 * in the sequence transports all not device specific data such as
514 * statistics, configuration, and the default parameter set.
515 * This message is followed by 0..n messages carrying device
516 * specific parameter sets.
517 * Although the ordering should be sufficient, NDTA_NAME can be
518 * used to identify sequences. The initial message can be identified
519 * by checking for NDTA_CONFIG. The device specific messages do
520 * not contain this TLV but have NDTPA_IFINDEX set to the
521 * corresponding interface index.
523 * To change neighbour table attributes, send RTM_SETNEIGHTBL
524 * with NDTA_NAME set. Changeable attribute include NDTA_THRESH[1-3],
525 * NDTA_GC_INTERVAL, and all TLVs in NDTA_PARMS unless marked
526 * otherwise. Device specific parameter sets can be changed by
527 * setting NDTPA_IFINDEX to the interface index of the corresponding
535 __u64 ndts_hash_grows;
536 __u64 ndts_res_failed;
539 __u64 ndts_rcv_probes_mcast;
540 __u64 ndts_rcv_probes_ucast;
541 __u64 ndts_periodic_gc_runs;
542 __u64 ndts_forced_gc_runs;
547 NDTPA_IFINDEX, /* u32, unchangeable */
548 NDTPA_REFCNT, /* u32, read-only */
549 NDTPA_REACHABLE_TIME, /* u64, read-only, msecs */
550 NDTPA_BASE_REACHABLE_TIME, /* u64, msecs */
551 NDTPA_RETRANS_TIME, /* u64, msecs */
552 NDTPA_GC_STALETIME, /* u64, msecs */
553 NDTPA_DELAY_PROBE_TIME, /* u64, msecs */
554 NDTPA_QUEUE_LEN, /* u32 */
555 NDTPA_APP_PROBES, /* u32 */
556 NDTPA_UCAST_PROBES, /* u32 */
557 NDTPA_MCAST_PROBES, /* u32 */
558 NDTPA_ANYCAST_DELAY, /* u64, msecs */
559 NDTPA_PROXY_DELAY, /* u64, msecs */
560 NDTPA_PROXY_QLEN, /* u32 */
561 NDTPA_LOCKTIME, /* u64, msecs */
564 #define NDTPA_MAX (__NDTPA_MAX - 1)
576 __u16 ndtc_entry_size;
578 __u32 ndtc_last_flush; /* delta to now in msecs */
579 __u32 ndtc_last_rand; /* delta to now in msecs */
581 __u32 ndtc_hash_mask;
582 __u32 ndtc_hash_chain_gc;
583 __u32 ndtc_proxy_qlen;
588 NDTA_NAME, /* char *, unchangeable */
589 NDTA_THRESH1, /* u32 */
590 NDTA_THRESH2, /* u32 */
591 NDTA_THRESH3, /* u32 */
592 NDTA_CONFIG, /* struct ndt_config, read-only */
593 NDTA_PARMS, /* nested TLV NDTPA_* */
594 NDTA_STATS, /* struct ndt_stats, read-only */
595 NDTA_GC_INTERVAL, /* u64, msecs */
598 #define NDTA_MAX (__NDTA_MAX - 1)
600 #define NDTA_RTA(r) ((struct rtattr*)(((char*)(r)) + \
601 NLMSG_ALIGN(sizeof(struct ndtmsg))))
602 #define NDTA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ndtmsg))
606 * General form of address family dependent message.
611 unsigned char rtgen_family;
614 /*****************************************************************
615 * Link layer specific messages.
619 * passes link level specific information, not dependent
620 * on network protocol.
625 unsigned char ifi_family;
626 unsigned char __ifi_pad;
627 unsigned short ifi_type; /* ARPHRD_* */
628 int ifi_index; /* Link index */
629 unsigned ifi_flags; /* IFF_* flags */
630 unsigned ifi_change; /* IFF_* change mask */
633 /********************************************************************
639 unsigned char prefix_family;
640 unsigned char prefix_pad1;
641 unsigned short prefix_pad2;
643 unsigned char prefix_type;
644 unsigned char prefix_len;
645 unsigned char prefix_flags;
646 unsigned char prefix_pad3;
657 #define PREFIX_MAX (__PREFIX_MAX - 1)
659 struct prefix_cacheinfo
661 __u32 preferred_time;
665 /* The struct should be in sync with struct net_device_stats */
666 struct rtnl_link_stats
668 __u32 rx_packets; /* total packets received */
669 __u32 tx_packets; /* total packets transmitted */
670 __u32 rx_bytes; /* total bytes received */
671 __u32 tx_bytes; /* total bytes transmitted */
672 __u32 rx_errors; /* bad packets received */
673 __u32 tx_errors; /* packet transmit problems */
674 __u32 rx_dropped; /* no space in linux buffers */
675 __u32 tx_dropped; /* no space available in linux */
676 __u32 multicast; /* multicast packets received */
679 /* detailed rx_errors: */
680 __u32 rx_length_errors;
681 __u32 rx_over_errors; /* receiver ring buff overflow */
682 __u32 rx_crc_errors; /* recved pkt with crc error */
683 __u32 rx_frame_errors; /* recv'd frame alignment error */
684 __u32 rx_fifo_errors; /* recv'r fifo overrun */
685 __u32 rx_missed_errors; /* receiver missed packet */
687 /* detailed tx_errors */
688 __u32 tx_aborted_errors;
689 __u32 tx_carrier_errors;
690 __u32 tx_fifo_errors;
691 __u32 tx_heartbeat_errors;
692 __u32 tx_window_errors;
699 /* The struct should be in sync with struct ifmap */
700 struct rtnl_link_ifmap
721 #define IFLA_COST IFLA_COST
723 #define IFLA_PRIORITY IFLA_PRIORITY
725 #define IFLA_MASTER IFLA_MASTER
726 IFLA_WIRELESS, /* Wireless Extension event - see wireless.h */
727 #define IFLA_WIRELESS IFLA_WIRELESS
728 IFLA_PROTINFO, /* Protocol specific information for a link */
729 #define IFLA_PROTINFO IFLA_PROTINFO
731 #define IFLA_TXQLEN IFLA_TXQLEN
733 #define IFLA_MAP IFLA_MAP
735 #define IFLA_WEIGHT IFLA_WEIGHT
740 #define IFLA_MAX (__IFLA_MAX - 1)
742 #define IFLA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
743 #define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
750 IFF_LOOPBACK, IFF_BROADCAST and IFF_POINTOPOINT are
751 more not changeable by user. They describe link media
752 characteristics and set by device driver.
755 - Combination IFF_BROADCAST|IFF_POINTOPOINT is invalid
756 - If neither of these three flags are set;
757 the interface is NBMA.
759 - IFF_MULTICAST does not mean anything special:
760 multicasts can be used on all not-NBMA links.
761 IFF_MULTICAST means that this media uses special encapsulation
762 for multicast frames. Apparently, all IFF_POINTOPOINT and
763 IFF_BROADCAST devices are able to use multicasts too.
767 For usual devices it is equal ifi_index.
768 If it is a "virtual interface" (f.e. tunnel), ifi_link
769 can point to real physical interface (f.e. for bandwidth calculations),
770 or maybe 0, what means, that real media is unknown (usual
771 for IPIP tunnels, when route to endpoint is allowed to change)
774 /* Subtype attributes for IFLA_PROTINFO */
778 IFLA_INET6_FLAGS, /* link flags */
779 IFLA_INET6_CONF, /* sysctl parameters */
780 IFLA_INET6_STATS, /* statistics */
781 IFLA_INET6_MCAST, /* MC things. What of them? */
782 IFLA_INET6_CACHEINFO, /* time values and max reasm size */
786 #define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
788 struct ifla_cacheinfo
791 __u32 tstamp; /* ipv6InterfaceTable updated timestamp */
792 __u32 reachable_time;
796 /*****************************************************************
797 * Traffic control messages.
802 unsigned char tcm_family;
803 unsigned char tcm__pad1;
804 unsigned short tcm__pad2;
824 #define TCA_MAX (__TCA_MAX - 1)
826 #define TCA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcmsg))))
827 #define TCA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcmsg))
830 /* RTnetlink multicast groups - backwards compatibility for userspace */
831 #define RTMGRP_LINK 1
832 #define RTMGRP_NOTIFY 2
833 #define RTMGRP_NEIGH 4
836 #define RTMGRP_IPV4_IFADDR 0x10
837 #define RTMGRP_IPV4_MROUTE 0x20
838 #define RTMGRP_IPV4_ROUTE 0x40
840 #define RTMGRP_IPV6_IFADDR 0x100
841 #define RTMGRP_IPV6_MROUTE 0x200
842 #define RTMGRP_IPV6_ROUTE 0x400
843 #define RTMGRP_IPV6_IFINFO 0x800
845 #define RTMGRP_DECnet_IFADDR 0x1000
846 #define RTMGRP_DECnet_ROUTE 0x4000
848 #define RTMGRP_IPV6_PREFIX 0x20000
851 /* RTnetlink multicast groups */
852 enum rtnetlink_groups {
854 #define RTNLGRP_NONE RTNLGRP_NONE
856 #define RTNLGRP_LINK RTNLGRP_LINK
858 #define RTNLGRP_NOTIFY RTNLGRP_NOTIFY
860 #define RTNLGRP_NEIGH RTNLGRP_NEIGH
862 #define RTNLGRP_TC RTNLGRP_TC
864 #define RTNLGRP_IPV4_IFADDR RTNLGRP_IPV4_IFADDR
866 #define RTNLGRP_IPV4_MROUTE RTNLGRP_IPV4_MROUTE
868 #define RTNLGRP_IPV4_ROUTE RTNLGRP_IPV4_ROUTE
871 #define RTNLGRP_IPV6_IFADDR RTNLGRP_IPV6_IFADDR
873 #define RTNLGRP_IPV6_MROUTE RTNLGRP_IPV6_MROUTE
875 #define RTNLGRP_IPV6_ROUTE RTNLGRP_IPV6_ROUTE
877 #define RTNLGRP_IPV6_IFINFO RTNLGRP_IPV6_IFINFO
878 RTNLGRP_DECnet_IFADDR,
879 #define RTNLGRP_DECnet_IFADDR RTNLGRP_DECnet_IFADDR
881 RTNLGRP_DECnet_ROUTE,
882 #define RTNLGRP_DECnet_ROUTE RTNLGRP_DECnet_ROUTE
886 #define RTNLGRP_IPV6_PREFIX RTNLGRP_IPV6_PREFIX
889 #define RTNLGRP_MAX (__RTNLGRP_MAX - 1)
891 /* TC action piece */
894 unsigned char tca_family;
895 unsigned char tca__pad1;
896 unsigned short tca__pad2;
898 #define TA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcamsg))))
899 #define TA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcamsg))
900 #define TCA_ACT_TAB 1 /* attr type must be >=1 */
903 /* End of information exported to user level */
907 #include <linux/config.h>
909 extern size_t rtattr_strlcpy(char *dest, const struct rtattr *rta, size_t size);
910 static __inline__ int rtattr_strcmp(const struct rtattr *rta, const char *str)
912 int len = strlen(str) + 1;
913 return len > rta->rta_len || memcmp(RTA_DATA(rta), str, len);
916 extern int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len);
918 #define rtattr_parse_nested(tb, max, rta) \
919 rtattr_parse((tb), (max), RTA_DATA((rta)), RTA_PAYLOAD((rta)))
921 extern struct sock *rtnl;
923 struct rtnetlink_link
925 int (*doit)(struct sk_buff *, struct nlmsghdr*, void *attr);
926 int (*dumpit)(struct sk_buff *, struct netlink_callback *cb);
929 extern struct rtnetlink_link * rtnetlink_links[NPROTO];
930 extern int rtnetlink_send(struct sk_buff *skb, u32 pid, u32 group, int echo);
931 extern int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics);
933 extern void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data);
935 #define RTA_PUT(skb, attrtype, attrlen, data) \
936 ({ if (unlikely(skb_tailroom(skb) < (int)RTA_SPACE(attrlen))) \
937 goto rtattr_failure; \
938 __rta_fill(skb, attrtype, attrlen, data); })
940 #define RTA_APPEND(skb, attrlen, data) \
941 ({ if (unlikely(skb_tailroom(skb) < (int)(attrlen))) \
942 goto rtattr_failure; \
943 memcpy(skb_put(skb, attrlen), data, attrlen); })
945 #define RTA_PUT_NOHDR(skb, attrlen, data) \
946 ({ RTA_APPEND(skb, RTA_ALIGN(attrlen), data); \
947 memset(skb->tail - (RTA_ALIGN(attrlen) - attrlen), 0, \
948 RTA_ALIGN(attrlen) - attrlen); })
950 #define RTA_PUT_U8(skb, attrtype, value) \
951 ({ u8 _tmp = (value); \
952 RTA_PUT(skb, attrtype, sizeof(u8), &_tmp); })
954 #define RTA_PUT_U16(skb, attrtype, value) \
955 ({ u16 _tmp = (value); \
956 RTA_PUT(skb, attrtype, sizeof(u16), &_tmp); })
958 #define RTA_PUT_U32(skb, attrtype, value) \
959 ({ u32 _tmp = (value); \
960 RTA_PUT(skb, attrtype, sizeof(u32), &_tmp); })
962 #define RTA_PUT_U64(skb, attrtype, value) \
963 ({ u64 _tmp = (value); \
964 RTA_PUT(skb, attrtype, sizeof(u64), &_tmp); })
966 #define RTA_PUT_SECS(skb, attrtype, value) \
967 RTA_PUT_U64(skb, attrtype, (value) / HZ)
969 #define RTA_PUT_MSECS(skb, attrtype, value) \
970 RTA_PUT_U64(skb, attrtype, jiffies_to_msecs(value))
972 #define RTA_PUT_STRING(skb, attrtype, value) \
973 RTA_PUT(skb, attrtype, strlen(value) + 1, value)
975 #define RTA_PUT_FLAG(skb, attrtype) \
976 RTA_PUT(skb, attrtype, 0, NULL);
978 #define RTA_NEST(skb, type) \
979 ({ struct rtattr *__start = (struct rtattr *) (skb)->tail; \
980 RTA_PUT(skb, type, 0, NULL); \
983 #define RTA_NEST_END(skb, start) \
984 ({ (start)->rta_len = ((skb)->tail - (unsigned char *) (start)); \
987 #define RTA_NEST_CANCEL(skb, start) \
989 skb_trim(skb, (unsigned char *) (start) - (skb)->data); \
992 #define RTA_GET_U8(rta) \
993 ({ if (!rta || RTA_PAYLOAD(rta) < sizeof(u8)) \
994 goto rtattr_failure; \
995 *(u8 *) RTA_DATA(rta); })
997 #define RTA_GET_U16(rta) \
998 ({ if (!rta || RTA_PAYLOAD(rta) < sizeof(u16)) \
999 goto rtattr_failure; \
1000 *(u16 *) RTA_DATA(rta); })
1002 #define RTA_GET_U32(rta) \
1003 ({ if (!rta || RTA_PAYLOAD(rta) < sizeof(u32)) \
1004 goto rtattr_failure; \
1005 *(u32 *) RTA_DATA(rta); })
1007 #define RTA_GET_U64(rta) \
1009 if (!rta || RTA_PAYLOAD(rta) < sizeof(u64)) \
1010 goto rtattr_failure; \
1011 memcpy(&_tmp, RTA_DATA(rta), sizeof(_tmp)); \
1014 #define RTA_GET_FLAG(rta) (!!(rta))
1016 #define RTA_GET_SECS(rta) ((unsigned long) RTA_GET_U64(rta) * HZ)
1017 #define RTA_GET_MSECS(rta) (msecs_to_jiffies((unsigned long) RTA_GET_U64(rta)))
1019 static inline struct rtattr *
1020 __rta_reserve(struct sk_buff *skb, int attrtype, int attrlen)
1023 int size = RTA_LENGTH(attrlen);
1025 rta = (struct rtattr*)skb_put(skb, RTA_ALIGN(size));
1026 rta->rta_type = attrtype;
1027 rta->rta_len = size;
1028 memset(RTA_DATA(rta) + attrlen, 0, RTA_ALIGN(size) - size);
1032 #define __RTA_PUT(skb, attrtype, attrlen) \
1033 ({ if (unlikely(skb_tailroom(skb) < (int)RTA_SPACE(attrlen))) \
1034 goto rtattr_failure; \
1035 __rta_reserve(skb, attrtype, attrlen); })
1037 extern void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change);
1039 extern struct semaphore rtnl_sem;
1041 #define rtnl_shlock() down(&rtnl_sem)
1042 #define rtnl_shlock_nowait() down_trylock(&rtnl_sem)
1044 #define rtnl_shunlock() do { up(&rtnl_sem); \
1045 if (rtnl && rtnl->sk_receive_queue.qlen) \
1046 rtnl->sk_data_ready(rtnl, 0); \
1049 extern void rtnl_lock(void);
1050 extern int rtnl_lock_interruptible(void);
1051 extern void rtnl_unlock(void);
1052 extern void rtnetlink_init(void);
1054 #define ASSERT_RTNL() do { \
1055 if (unlikely(down_trylock(&rtnl_sem) == 0)) { \
1057 printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \
1058 __FILE__, __LINE__); \
1063 #define BUG_TRAP(x) do { \
1064 if (unlikely(!(x))) { \
1065 printk(KERN_ERR "KERNEL: assertion (%s) failed at %s (%d)\n", \
1066 #x, __FILE__ , __LINE__); \
1070 #endif /* __KERNEL__ */
1073 #endif /* __LINUX_RTNETLINK_H */