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