~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/include/linux/rtnetlink.h

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #ifndef __LINUX_RTNETLINK_H
  2 #define __LINUX_RTNETLINK_H
  3 
  4 #include <linux/netlink.h>
  5 
  6 #define RTNL_DEBUG 1
  7 
  8 
  9 /****
 10  *              Routing/neighbour discovery messages.
 11  ****/
 12 
 13 /* Types of messages */
 14 
 15 #define RTM_BASE        0x10
 16 
 17 #define RTM_NEWLINK     (RTM_BASE+0)
 18 #define RTM_DELLINK     (RTM_BASE+1)
 19 #define RTM_GETLINK     (RTM_BASE+2)
 20 
 21 #define RTM_NEWADDR     (RTM_BASE+4)
 22 #define RTM_DELADDR     (RTM_BASE+5)
 23 #define RTM_GETADDR     (RTM_BASE+6)
 24 
 25 #define RTM_NEWROUTE    (RTM_BASE+8)
 26 #define RTM_DELROUTE    (RTM_BASE+9)
 27 #define RTM_GETROUTE    (RTM_BASE+10)
 28 
 29 #define RTM_NEWNEIGH    (RTM_BASE+12)
 30 #define RTM_DELNEIGH    (RTM_BASE+13)
 31 #define RTM_GETNEIGH    (RTM_BASE+14)
 32 
 33 #define RTM_NEWRULE     (RTM_BASE+16)
 34 #define RTM_DELRULE     (RTM_BASE+17)
 35 #define RTM_GETRULE     (RTM_BASE+18)
 36 
 37 #define RTM_NEWQDISC    (RTM_BASE+20)
 38 #define RTM_DELQDISC    (RTM_BASE+21)
 39 #define RTM_GETQDISC    (RTM_BASE+22)
 40 
 41 #define RTM_NEWTCLASS   (RTM_BASE+24)
 42 #define RTM_DELTCLASS   (RTM_BASE+25)
 43 #define RTM_GETTCLASS   (RTM_BASE+26)
 44 
 45 #define RTM_NEWTFILTER  (RTM_BASE+28)
 46 #define RTM_DELTFILTER  (RTM_BASE+29)
 47 #define RTM_GETTFILTER  (RTM_BASE+30)
 48 
 49 #define RTM_MAX         (RTM_BASE+31)
 50 
 51 /* 
 52    Generic structure for encapsulation optional route information.
 53    It is reminiscent of sockaddr, but with sa_family replaced
 54    with attribute type.
 55  */
 56 
 57 struct rtattr
 58 {
 59         unsigned short  rta_len;
 60         unsigned short  rta_type;
 61 };
 62 
 63 /* Macros to handle rtattributes */
 64 
 65 #define RTA_ALIGNTO     4
 66 #define RTA_ALIGN(len) ( ((len)+RTA_ALIGNTO-1) & ~(RTA_ALIGNTO-1) )
 67 #define RTA_OK(rta,len) ((len) > 0 && (rta)->rta_len >= sizeof(struct rtattr) && \
 68                          (rta)->rta_len <= (len))
 69 #define RTA_NEXT(rta,attrlen)   ((attrlen) -= RTA_ALIGN((rta)->rta_len), \
 70                                  (struct rtattr*)(((char*)(rta)) + RTA_ALIGN((rta)->rta_len)))
 71 #define RTA_LENGTH(len) (RTA_ALIGN(sizeof(struct rtattr)) + (len))
 72 #define RTA_SPACE(len)  RTA_ALIGN(RTA_LENGTH(len))
 73 #define RTA_DATA(rta)   ((void*)(((char*)(rta)) + RTA_LENGTH(0)))
 74 #define RTA_PAYLOAD(rta) ((int)((rta)->rta_len) - RTA_LENGTH(0))
 75 
 76 
 77 
 78 
 79 /******************************************************************************
 80  *              Definitions used in routing table administation.
 81  ****/
 82 
 83 struct rtmsg
 84 {
 85         unsigned char           rtm_family;
 86         unsigned char           rtm_dst_len;
 87         unsigned char           rtm_src_len;
 88         unsigned char           rtm_tos;
 89 
 90         unsigned char           rtm_table;      /* Routing table id */
 91         unsigned char           rtm_protocol;   /* Routing protocol; see below  */
 92         unsigned char           rtm_scope;      /* See below */ 
 93         unsigned char           rtm_type;       /* See below    */
 94 
 95         unsigned                rtm_flags;
 96 };
 97 
 98 /* rtm_type */
 99 
100 enum
101 {
102         RTN_UNSPEC,
103         RTN_UNICAST,            /* Gateway or direct route      */
104         RTN_LOCAL,              /* Accept locally               */
105         RTN_BROADCAST,          /* Accept locally as broadcast,
106                                    send as broadcast */
107         RTN_ANYCAST,            /* Accept locally as broadcast,
108                                    but send as unicast */
109         RTN_MULTICAST,          /* Multicast route              */
110         RTN_BLACKHOLE,          /* Drop                         */
111         RTN_UNREACHABLE,        /* Destination is unreachable   */
112         RTN_PROHIBIT,           /* Administratively prohibited  */
113         RTN_THROW,              /* Not in this table            */
114         RTN_NAT,                /* Translate this address       */
115         RTN_XRESOLVE,           /* Use external resolver        */
116 };
117 
118 #define RTN_MAX RTN_XRESOLVE
119 
120 
121 /* rtm_protocol */
122 
123 #define RTPROT_UNSPEC   0
124 #define RTPROT_REDIRECT 1       /* Route installed by ICMP redirects;
125                                    not used by current IPv4 */
126 #define RTPROT_KERNEL   2       /* Route installed by kernel            */
127 #define RTPROT_BOOT     3       /* Route installed during boot          */
128 #define RTPROT_STATIC   4       /* Route installed by administrator     */
129 
130 /* Values of protocol >= RTPROT_STATIC are not interpreted by kernel;
131    they just passed from user and back as is.
132    It will be used by hypothetical multiple routing daemons.
133    Note that protocol values should be standardized in order to
134    avoid conflicts.
135  */
136 
137 #define RTPROT_GATED    8       /* Apparently, GateD */
138 #define RTPROT_RA       9       /* RDISC/ND router advertisments */
139 #define RTPROT_MRT      10      /* Merit MRT */
140 #define RTPROT_ZEBRA    11      /* Zebra */
141 #define RTPROT_BIRD     12      /* BIRD */
142 #define RTPROT_DNROUTED 13      /* DECnet routing daemon */
143 
144 /* rtm_scope
145 
146    Really it is not scope, but sort of distance to the destination.
147    NOWHERE are reserved for not existing destinations, HOST is our
148    local addresses, LINK are destinations, located on directly attached
149    link and UNIVERSE is everywhere in the Universe.
150 
151    Intermediate values are also possible f.e. interior routes
152    could be assigned a value between UNIVERSE and LINK.
153 */
154 
155 enum rt_scope_t
156 {
157         RT_SCOPE_UNIVERSE=0,
158 /* User defined values  */
159         RT_SCOPE_SITE=200,
160         RT_SCOPE_LINK=253,
161         RT_SCOPE_HOST=254,
162         RT_SCOPE_NOWHERE=255
163 };
164 
165 /* rtm_flags */
166 
167 #define RTM_F_NOTIFY            0x100   /* Notify user of route change  */
168 #define RTM_F_CLONED            0x200   /* This route is cloned         */
169 #define RTM_F_EQUALIZE          0x400   /* Multipath equalizer: NI      */
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 };
203 
204 #define RTA_MAX RTA_CACHEINFO
205 
206 #define RTM_RTA(r)  ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))))
207 #define RTM_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct rtmsg))
208 
209 /* RTM_MULTIPATH --- array of struct rtnexthop.
210  *
211  * "struct rtnexthop" describres all necessary nexthop information,
212  * i.e. parameters of path to a destination via this nextop.
213  *
214  * At the moment it is impossible to set different prefsrc, mtu, window
215  * and rtt for different paths from multipath.
216  */
217 
218 struct rtnexthop
219 {
220         unsigned short          rtnh_len;
221         unsigned char           rtnh_flags;
222         unsigned char           rtnh_hops;
223         int                     rtnh_ifindex;
224 };
225 
226 /* rtnh_flags */
227 
228 #define RTNH_F_DEAD             1       /* Nexthop is dead (used by multipath)  */
229 #define RTNH_F_PERVASIVE        2       /* Do recursive gateway lookup  */
230 #define RTNH_F_ONLINK           4       /* Gateway is forced on link    */
231 
232 /* Macros to handle hexthops */
233 
234 #define RTNH_ALIGNTO    4
235 #define RTNH_ALIGN(len) ( ((len)+RTNH_ALIGNTO-1) & ~(RTNH_ALIGNTO-1) )
236 #define RTNH_OK(rtnh,len) ((rtnh)->rtnh_len >= sizeof(struct rtnexthop) && \
237                            ((int)(rtnh)->rtnh_len) <= (len))
238 #define RTNH_NEXT(rtnh) ((struct rtnexthop*)(((char*)(rtnh)) + RTNH_ALIGN((rtnh)->rtnh_len)))
239 #define RTNH_LENGTH(len) (RTNH_ALIGN(sizeof(struct rtnexthop)) + (len))
240 #define RTNH_SPACE(len) RTNH_ALIGN(RTNH_LENGTH(len))
241 #define RTNH_DATA(rtnh)   ((struct rtattr*)(((char*)(rtnh)) + RTNH_LENGTH(0)))
242 
243 /* RTM_CACHEINFO */
244 
245 struct rta_cacheinfo
246 {
247         __u32   rta_clntref;
248         __u32   rta_lastuse;
249         __s32   rta_expires;
250         __u32   rta_error;
251         __u32   rta_used;
252 
253 #define RTNETLINK_HAVE_PEERINFO 1
254         __u32   rta_id;
255         __u32   rta_ts;
256         __u32   rta_tsage;
257 };
258 
259 /* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
260 
261 enum
262 {
263         RTAX_UNSPEC,
264 #define RTAX_UNSPEC RTAX_UNSPEC
265         RTAX_LOCK,
266 #define RTAX_LOCK RTAX_LOCK
267         RTAX_MTU,
268 #define RTAX_MTU RTAX_MTU
269         RTAX_WINDOW,
270 #define RTAX_WINDOW RTAX_WINDOW
271         RTAX_RTT,
272 #define RTAX_RTT RTAX_RTT
273         RTAX_RTTVAR,
274 #define RTAX_RTTVAR RTAX_RTTVAR
275         RTAX_SSTHRESH,
276 #define RTAX_SSTHRESH RTAX_SSTHRESH
277         RTAX_CWND,
278 #define RTAX_CWND RTAX_CWND
279         RTAX_ADVMSS,
280 #define RTAX_ADVMSS RTAX_ADVMSS
281         RTAX_REORDERING,
282 #define RTAX_REORDERING RTAX_REORDERING
283 };
284 
285 #define RTAX_MAX RTAX_REORDERING
286 
287 
288 
289 /*********************************************************
290  *              Interface address.
291  ****/
292 
293 struct ifaddrmsg
294 {
295         unsigned char   ifa_family;
296         unsigned char   ifa_prefixlen;  /* The prefix length            */
297         unsigned char   ifa_flags;      /* Flags                        */
298         unsigned char   ifa_scope;      /* See above                    */
299         int             ifa_index;      /* Link index                   */
300 };
301 
302 enum
303 {
304         IFA_UNSPEC,
305         IFA_ADDRESS,
306         IFA_LOCAL,
307         IFA_LABEL,
308         IFA_BROADCAST,
309         IFA_ANYCAST,
310         IFA_CACHEINFO
311 };
312 
313 #define IFA_MAX IFA_CACHEINFO
314 
315 /* ifa_flags */
316 
317 #define IFA_F_SECONDARY         0x01
318 
319 #define IFA_F_DEPRECATED        0x20
320 #define IFA_F_TENTATIVE         0x40
321 #define IFA_F_PERMANENT         0x80
322 
323 struct ifa_cacheinfo
324 {
325         __s32   ifa_prefered;
326         __s32   ifa_valid;
327 };
328 
329 
330 #define IFA_RTA(r)  ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
331 #define IFA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifaddrmsg))
332 
333 /*
334    Important comment:
335    IFA_ADDRESS is prefix address, rather than local interface address.
336    It makes no difference for normally configured broadcast interfaces,
337    but for point-to-point IFA_ADDRESS is DESTINATION address,
338    local address is supplied in IFA_LOCAL attribute.
339  */
340 
341 /**************************************************************
342  *              Neighbour discovery.
343  ****/
344 
345 struct ndmsg
346 {
347         unsigned char   ndm_family;
348         unsigned char   ndm_pad1;
349         unsigned short  ndm_pad2;
350         int             ndm_ifindex;    /* Link index                   */
351         __u16           ndm_state;
352         __u8            ndm_flags;
353         __u8            ndm_type;
354 };
355 
356 enum
357 {
358         NDA_UNSPEC,
359         NDA_DST,
360         NDA_LLADDR,
361         NDA_CACHEINFO
362 };
363 
364 #define NDA_MAX NDA_CACHEINFO
365 
366 #define NDA_RTA(r)  ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
367 #define NDA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ndmsg))
368 
369 /*
370  *      Neighbor Cache Entry Flags
371  */
372 
373 #define NTF_PROXY       0x08    /* == ATF_PUBL */
374 #define NTF_ROUTER      0x80
375 
376 /*
377  *      Neighbor Cache Entry States.
378  */
379 
380 #define NUD_INCOMPLETE  0x01
381 #define NUD_REACHABLE   0x02
382 #define NUD_STALE       0x04
383 #define NUD_DELAY       0x08
384 #define NUD_PROBE       0x10
385 #define NUD_FAILED      0x20
386 
387 /* Dummy states */
388 #define NUD_NOARP       0x40
389 #define NUD_PERMANENT   0x80
390 #define NUD_NONE        0x00
391 
392 
393 struct nda_cacheinfo
394 {
395         __u32           ndm_confirmed;
396         __u32           ndm_used;
397         __u32           ndm_updated;
398         __u32           ndm_refcnt;
399 };
400 
401 /****
402  *              General form of address family dependent message.
403  ****/
404 
405 struct rtgenmsg
406 {
407         unsigned char           rtgen_family;
408 };
409 
410 /*****************************************************************
411  *              Link layer specific messages.
412  ****/
413 
414 /* struct ifinfomsg
415  * passes link level specific information, not dependent
416  * on network protocol.
417  */
418 
419 struct ifinfomsg
420 {
421         unsigned char   ifi_family;
422         unsigned char   __ifi_pad;
423         unsigned short  ifi_type;               /* ARPHRD_* */
424         int             ifi_index;              /* Link index   */
425         unsigned        ifi_flags;              /* IFF_* flags  */
426         unsigned        ifi_change;             /* IFF_* change mask */
427 };
428 
429 enum
430 {
431         IFLA_UNSPEC,
432         IFLA_ADDRESS,
433         IFLA_BROADCAST,
434         IFLA_IFNAME,
435         IFLA_MTU,
436         IFLA_LINK,
437         IFLA_QDISC,
438         IFLA_STATS,
439         IFLA_COST,
440 #define IFLA_COST IFLA_COST
441         IFLA_PRIORITY,
442 #define IFLA_PRIORITY IFLA_PRIORITY
443         IFLA_MASTER
444 #define IFLA_MASTER IFLA_MASTER
445 };
446 
447 
448 #define IFLA_MAX IFLA_MASTER
449 
450 #define IFLA_RTA(r)  ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
451 #define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
452 
453 /* ifi_flags.
454 
455    IFF_* flags.
456 
457    The only change is:
458    IFF_LOOPBACK, IFF_BROADCAST and IFF_POINTOPOINT are
459    more not changeable by user. They describe link media
460    characteristics and set by device driver.
461 
462    Comments:
463    - Combination IFF_BROADCAST|IFF_POINTOPOINT is invalid
464    - If neiher of these three flags are set;
465      the interface is NBMA.
466 
467    - IFF_MULTICAST does not mean anything special:
468    multicasts can be used on all not-NBMA links.
469    IFF_MULTICAST means that this media uses special encapsulation
470    for multicast frames. Apparently, all IFF_POINTOPOINT and
471    IFF_BROADCAST devices are able to use multicasts too.
472  */
473 
474 /* IFLA_LINK.
475    For usual devices it is equal ifi_index.
476    If it is a "virtual interface" (f.e. tunnel), ifi_link
477    can point to real physical interface (f.e. for bandwidth calculations),
478    or maybe 0, what means, that real media is unknown (usual
479    for IPIP tunnels, when route to endpoint is allowed to change)
480  */
481 
482 /*****************************************************************
483  *              Traffic control messages.
484  ****/
485 
486 struct tcmsg
487 {
488         unsigned char   tcm_family;
489         unsigned char   tcm__pad1;
490         unsigned short  tcm__pad2;
491         int             tcm_ifindex;
492         __u32           tcm_handle;
493         __u32           tcm_parent;
494         __u32           tcm_info;
495 };
496 
497 enum
498 {
499         TCA_UNSPEC,
500         TCA_KIND,
501         TCA_OPTIONS,
502         TCA_STATS,
503         TCA_XSTATS,
504         TCA_RATE,
505 };
506 
507 #define TCA_MAX TCA_RATE
508 
509 #define TCA_RTA(r)  ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcmsg))))
510 #define TCA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcmsg))
511 
512 
513 /* SUMMARY: maximal rtattr understood by kernel */
514 
515 #define RTATTR_MAX              RTA_MAX
516 
517 /* RTnetlink multicast groups */
518 
519 #define RTMGRP_LINK             1
520 #define RTMGRP_NOTIFY           2
521 #define RTMGRP_NEIGH            4
522 #define RTMGRP_TC               8
523 
524 #define RTMGRP_IPV4_IFADDR      0x10
525 #define RTMGRP_IPV4_MROUTE      0x20
526 #define RTMGRP_IPV4_ROUTE       0x40
527 
528 #define RTMGRP_IPV6_IFADDR      0x100
529 #define RTMGRP_IPV6_MROUTE      0x200
530 #define RTMGRP_IPV6_ROUTE       0x400
531 
532 #define RTMGRP_DECnet_IFADDR    0x1000
533 #define RTMGRP_DECnet_ROUTE     0x4000
534 
535 /* End of information exported to user level */
536 
537 #ifdef __KERNEL__
538 
539 #include <linux/config.h>
540 
541 extern __inline__ int rtattr_strcmp(struct rtattr *rta, char *str)
542 {
543         int len = strlen(str) + 1;
544         return len > rta->rta_len || memcmp(RTA_DATA(rta), str, len);
545 }
546 
547 extern int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len);
548 
549 #ifdef CONFIG_RTNETLINK
550 extern struct sock *rtnl;
551 
552 struct rtnetlink_link
553 {
554         int (*doit)(struct sk_buff *, struct nlmsghdr*, void *attr);
555         int (*dumpit)(struct sk_buff *, struct netlink_callback *cb);
556 };
557 
558 extern struct rtnetlink_link * rtnetlink_links[NPROTO];
559 extern int rtnetlink_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb);
560 extern int rtnetlink_send(struct sk_buff *skb, u32 pid, u32 group, int echo);
561 extern int rtnetlink_put_metrics(struct sk_buff *skb, unsigned *metrics);
562 
563 extern void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data);
564 
565 #define RTA_PUT(skb, attrtype, attrlen, data) \
566 ({ if (skb_tailroom(skb) < (int)RTA_SPACE(attrlen)) goto rtattr_failure; \
567    __rta_fill(skb, attrtype, attrlen, data); })
568 
569 extern void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change);
570 
571 #else
572 
573 #define rtmsg_ifinfo(a,b,c) do { } while (0)
574 
575 #endif
576 
577 extern struct semaphore rtnl_sem;
578 
579 #define rtnl_exlock()           do { } while(0)
580 #define rtnl_exunlock()         do { } while(0)
581 #define rtnl_exlock_nowait()    (0)
582 
583 #define rtnl_shlock()           down(&rtnl_sem)
584 #define rtnl_shlock_nowait()    down_trylock(&rtnl_sem)
585 
586 #ifndef CONFIG_RTNETLINK
587 #define rtnl_shunlock() up(&rtnl_sem)
588 #else
589 #define rtnl_shunlock() do { up(&rtnl_sem); \
590                              if (rtnl && rtnl->receive_queue.qlen) \
591                                      rtnl->data_ready(rtnl, 0); \
592                         } while(0)
593 #endif
594 
595 extern void rtnl_lock(void);
596 extern void rtnl_unlock(void);
597 extern void rtnetlink_init(void);
598 
599 #define ASSERT_RTNL() do { if (down_trylock(&rtnl_sem) == 0)  { up(&rtnl_sem); \
600 printk("RTNL: assertion failed at " __FILE__ "(%d):" __FUNCTION__ "\n", __LINE__); } \
601                    } while(0);
602 #define BUG_TRAP(x) if (!(x)) { printk("KERNEL: assertion (" #x ") failed at " __FILE__ "(%d):" __FUNCTION__ "\n", __LINE__); }
603 
604 
605 #endif /* __KERNEL__ */
606 
607 
608 #endif  /* __LINUX_RTNETLINK_H */
609 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.