Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

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