* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / include / linux / rtnetlink.h
blobce30d85ef234920edb81cd818de9a0cd60252e13
1 #ifndef __LINUX_RTNETLINK_H
2 #define __LINUX_RTNETLINK_H
4 #include <linux/config.h>
5 #include <linux/netlink.h>
7 #define RTNL_DEBUG 1
10 /****
11 * Routing/neighbour discovery messages.
12 ****/
14 /* Types of messages */
16 #define RTM_BASE 0x10
18 #define RTM_NEWLINK (RTM_BASE+0)
19 #define RTM_DELLINK (RTM_BASE+1)
20 #define RTM_GETLINK (RTM_BASE+2)
22 #define RTM_NEWADDR (RTM_BASE+4)
23 #define RTM_DELADDR (RTM_BASE+5)
24 #define RTM_GETADDR (RTM_BASE+6)
26 #define RTM_NEWROUTE (RTM_BASE+8)
27 #define RTM_DELROUTE (RTM_BASE+9)
28 #define RTM_GETROUTE (RTM_BASE+10)
30 #define RTM_NEWNEIGH (RTM_BASE+12)
31 #define RTM_DELNEIGH (RTM_BASE+13)
32 #define RTM_GETNEIGH (RTM_BASE+14)
34 #define RTM_NEWRULE (RTM_BASE+16)
35 #define RTM_DELRULE (RTM_BASE+17)
36 #define RTM_GETRULE (RTM_BASE+18)
38 #define RTM_NEWQDISC (RTM_BASE+20)
39 #define RTM_DELQDISC (RTM_BASE+21)
40 #define RTM_GETQDISC (RTM_BASE+22)
42 #define RTM_NEWTCLASS (RTM_BASE+24)
43 #define RTM_DELTCLASS (RTM_BASE+25)
44 #define RTM_GETTCLASS (RTM_BASE+26)
46 #define RTM_NEWTFILTER (RTM_BASE+28)
47 #define RTM_DELTFILTER (RTM_BASE+29)
48 #define RTM_GETTFILTER (RTM_BASE+30)
50 #define RTM_MAX (RTM_BASE+31)
52 /*
53 Generic structure for encapsulation optional route information.
54 It is reminiscent of sockaddr, but with sa_family replaced
55 with attribute type.
58 struct rtattr
60 unsigned short rta_len;
61 unsigned short rta_type;
64 /* Macros to handle rtattributes */
66 #define RTA_ALIGNTO 4
67 #define RTA_ALIGN(len) ( ((len)+RTA_ALIGNTO-1) & ~(RTA_ALIGNTO-1) )
68 #define RTA_OK(rta,len) ((len) > 0 && (rta)->rta_len >= sizeof(struct rtattr) && \
69 (rta)->rta_len <= (len))
70 #define RTA_NEXT(rta,attrlen) ((attrlen) -= RTA_ALIGN((rta)->rta_len), \
71 (struct rtattr*)(((char*)(rta)) + RTA_ALIGN((rta)->rta_len)))
72 #define RTA_LENGTH(len) (RTA_ALIGN(sizeof(struct rtattr)) + (len))
73 #define RTA_SPACE(len) RTA_ALIGN(RTA_LENGTH(len))
74 #define RTA_DATA(rta) ((void*)(((char*)(rta)) + RTA_LENGTH(0)))
75 #define RTA_PAYLOAD(rta) ((int)((rta)->rta_len) - RTA_LENGTH(0))
80 /******************************************************************************
81 * Definitions used in routing table administation.
82 ****/
84 struct rtmsg
86 unsigned char rtm_family;
87 unsigned char rtm_dst_len;
88 unsigned char rtm_src_len;
89 unsigned char rtm_tos;
91 unsigned char rtm_table; /* Routing table id */
92 unsigned char rtm_protocol; /* Routing protocol; see below */
93 unsigned char rtm_scope; /* See below */
94 unsigned char rtm_type; /* See below */
96 unsigned rtm_flags;
99 /* rtm_type */
101 enum
103 RTN_UNSPEC,
104 RTN_UNICAST, /* Gateway or direct route */
105 RTN_LOCAL, /* Accept locally */
106 RTN_BROADCAST, /* Accept locally as broadcast,
107 send as broadcast */
108 RTN_ANYCAST, /* Accept locally as broadcast,
109 but send as unicast */
110 RTN_MULTICAST, /* Multicast route */
111 RTN_BLACKHOLE, /* Drop */
112 RTN_UNREACHABLE, /* Destination is unreachable */
113 RTN_PROHIBIT, /* Administratively prohibited */
114 RTN_THROW, /* Not in this table */
115 RTN_NAT, /* Translate this address */
116 RTN_XRESOLVE, /* Use external resolver */
119 #define RTN_MAX RTN_XRESOLVE
122 /* rtm_protocol */
124 #define RTPROT_UNSPEC 0
125 #define RTPROT_REDIRECT 1 /* Route installed by ICMP redirects;
126 not used by current IPv4 */
127 #define RTPROT_KERNEL 2 /* Route installed by kernel */
128 #define RTPROT_BOOT 3 /* Route installed during boot */
129 #define RTPROT_STATIC 4 /* Route installed by administrator */
131 /* Values of protocol >= RTPROT_STATIC are not interpreted by kernel;
132 they just passed from user and back as is.
133 It will be used by hypothetical multiple routing daemons.
134 Note that protocol values should be standardized in order to
135 avoid conflicts.
138 #define RTPROT_GATED 8 /* Apparently, GateD */
139 #define RTPROT_RA 9 /* RDISC/ND router advertisments */
140 #define RTPROT_MRT 10 /* Merit MRT */
141 #define RTPROT_ZEBRA 11 /* Zebra */
142 #define RTPROT_BIRD 12 /* BIRD */
144 /* rtm_scope
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.
151 Intermediate values are also possible f.e. interior routes
152 could be assigned a value between UNIVERSE and LINK.
155 enum rt_scope_t
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
165 /* rtm_flags */
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 */
171 /* Reserved table identifiers */
173 enum rt_class_t
175 RT_TABLE_UNSPEC=0,
176 /* User defined values */
177 RT_TABLE_DEFAULT=253,
178 RT_TABLE_MAIN=254,
179 RT_TABLE_LOCAL=255
181 #define RT_TABLE_MAX RT_TABLE_LOCAL
185 /* Routing message attributes */
187 enum rtattr_type_t
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
204 #define RTA_MAX RTA_CACHEINFO
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))
209 /* RTM_MULTIPATH --- array of struct rtnexthop.
211 * "struct rtnexthop" describres all necessary nexthop information,
212 * i.e. parameters of path to a destination via this nextop.
214 * At the moment it is impossible to set different prefsrc, mtu, window
215 * and rtt for different paths from multipath.
218 struct rtnexthop
220 unsigned short rtnh_len;
221 unsigned char rtnh_flags;
222 unsigned char rtnh_hops;
223 int rtnh_ifindex;
226 /* rtnh_flags */
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 */
232 /* Macros to handle hexthops */
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)))
243 /* RTM_CACHEINFO */
245 struct rta_cacheinfo
247 __u32 rta_clntref;
248 __u32 rta_lastuse;
249 __s32 rta_expires;
250 __u32 rta_error;
251 __u32 rta_used;
254 /* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
256 enum
258 RTAX_UNSPEC,
259 #define RTAX_UNSPEC RTAX_UNSPEC
260 RTAX_LOCK,
261 #define RTAX_LOCK RTAX_LOCK
262 RTAX_MTU,
263 #define RTAX_MTU RTAX_MTU
264 RTAX_WINDOW,
265 #define RTAX_WINDOW RTAX_WINDOW
266 RTAX_RTT,
267 #define RTAX_RTT RTAX_RTT
268 RTAX_RTTVAR,
269 #define RTAX_RTTVAR RTAX_RTTVAR
270 RTAX_SSTHRESH,
271 #define RTAX_SSTHRESH RTAX_SSTHRESH
272 RTAX_CWND,
273 #define RTAX_CWND RTAX_CWND
274 RTAX_ADVMSS,
275 #define RTAX_ADVMSS RTAX_ADVMSS
278 #define RTAX_MAX RTAX_ADVMSS
282 /*********************************************************
283 * Interface address.
284 ****/
286 struct ifaddrmsg
288 unsigned char ifa_family;
289 unsigned char ifa_prefixlen; /* The prefix length */
290 unsigned char ifa_flags; /* Flags */
291 unsigned char ifa_scope; /* See above */
292 int ifa_index; /* Link index */
295 enum
297 IFA_UNSPEC,
298 IFA_ADDRESS,
299 IFA_LOCAL,
300 IFA_LABEL,
301 IFA_BROADCAST,
302 IFA_ANYCAST,
303 IFA_CACHEINFO
306 #define IFA_MAX IFA_CACHEINFO
308 /* ifa_flags */
310 #define IFA_F_SECONDARY 0x01
312 #define IFA_F_DEPRECATED 0x20
313 #define IFA_F_TENTATIVE 0x40
314 #define IFA_F_PERMANENT 0x80
316 struct ifa_cacheinfo
318 __s32 ifa_prefered;
319 __s32 ifa_valid;
323 #define IFA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
324 #define IFA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifaddrmsg))
327 Important comment:
328 IFA_ADDRESS is prefix address, rather than local interface address.
329 It makes no difference for normally configured broadcast interfaces,
330 but for point-to-point IFA_ADDRESS is DESTINATION address,
331 local address is supplied in IFA_LOCAL attribute.
334 /**************************************************************
335 * Neighbour discovery.
336 ****/
338 struct ndmsg
340 unsigned char ndm_family;
341 unsigned char ndm_pad1;
342 unsigned short ndm_pad2;
343 int ndm_ifindex; /* Link index */
344 __u16 ndm_state;
345 __u8 ndm_flags;
346 __u8 ndm_type;
349 enum
351 NDA_UNSPEC,
352 NDA_DST,
353 NDA_LLADDR,
354 NDA_CACHEINFO
357 #define NDA_MAX NDA_CACHEINFO
359 #define NDA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
360 #define NDA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ndmsg))
363 * Neighbor Cache Entry Flags
366 #define NTF_PROXY 0x08 /* == ATF_PUBL */
367 #define NTF_ROUTER 0x80
370 * Neighbor Cache Entry States.
373 #define NUD_INCOMPLETE 0x01
374 #define NUD_REACHABLE 0x02
375 #define NUD_STALE 0x04
376 #define NUD_DELAY 0x08
377 #define NUD_PROBE 0x10
378 #define NUD_FAILED 0x20
380 /* Dummy states */
381 #define NUD_NOARP 0x40
382 #define NUD_PERMANENT 0x80
383 #define NUD_NONE 0x00
386 struct nda_cacheinfo
388 __u32 ndm_confirmed;
389 __u32 ndm_used;
390 __u32 ndm_updated;
391 __u32 ndm_refcnt;
394 /****
395 * General form of address family dependent message.
396 ****/
398 struct rtgenmsg
400 unsigned char rtgen_family;
403 /*****************************************************************
404 * Link layer specific messages.
405 ****/
407 /* struct ifinfomsg
408 * passes link level specific information, not dependent
409 * on network protocol.
412 struct ifinfomsg
414 unsigned char ifi_family;
415 unsigned char __ifi_pad;
416 unsigned short ifi_type; /* ARPHRD_* */
417 int ifi_index; /* Link index */
418 unsigned ifi_flags; /* IFF_* flags */
419 unsigned ifi_change; /* IFF_* change mask */
422 enum
424 IFLA_UNSPEC,
425 IFLA_ADDRESS,
426 IFLA_BROADCAST,
427 IFLA_IFNAME,
428 IFLA_MTU,
429 IFLA_LINK,
430 IFLA_QDISC,
431 IFLA_STATS,
432 IFLA_COST,
433 IFLA_PRIORITY
437 #define IFLA_MAX IFLA_STATS
439 #define IFLA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
440 #define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
442 /* ifi_flags.
444 IFF_* flags.
446 The only change is:
447 IFF_LOOPBACK, IFF_BROADCAST and IFF_POINTOPOINT are
448 more not changeable by user. They describe link media
449 characteristics and set by device driver.
451 Comments:
452 - Combination IFF_BROADCAST|IFF_POINTOPOINT is invalid
453 - If neiher of these three flags are set;
454 the interface is NBMA.
456 - IFF_MULTICAST does not mean anything special:
457 multicasts can be used on all not-NBMA links.
458 IFF_MULTICAST means that this media uses special encapsulation
459 for multicast frames. Apparently, all IFF_POINTOPOINT and
460 IFF_BROADCAST devices are able to use multicasts too.
463 /* ifi_link.
464 For usual devices it is equal ifi_index.
465 If it is a "virtual interface" (f.e. tunnel), ifi_link
466 can point to real physical interface (f.e. for bandwidth calculations),
467 or maybe 0, what means, that real media is unknown (usual
468 for IPIP tunnels, when route to endpoint is allowed to change)
471 /*****************************************************************
472 * Traffic control messages.
473 ****/
475 struct tcmsg
477 unsigned char tcm_family;
478 unsigned char tcm__pad1;
479 unsigned short tcm__pad2;
480 int tcm_ifindex;
481 __u32 tcm_handle;
482 __u32 tcm_parent;
483 __u32 tcm_info;
486 enum
488 TCA_UNSPEC,
489 TCA_KIND,
490 TCA_OPTIONS,
491 TCA_STATS,
492 TCA_XSTATS,
493 TCA_RATE,
496 #define TCA_MAX TCA_RATE
498 #define TCA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcmsg))))
499 #define TCA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcmsg))
502 /* SUMMARY: maximal rtattr understood by kernel */
504 #define RTATTR_MAX RTA_MAX
506 /* RTnetlink multicast groups */
508 #define RTMGRP_LINK 1
509 #define RTMGRP_NOTIFY 2
510 #define RTMGRP_NEIGH 4
511 #define RTMGRP_TC 8
513 #define RTMGRP_IPV4_IFADDR 0x10
514 #define RTMGRP_IPV4_MROUTE 0x20
515 #define RTMGRP_IPV4_ROUTE 0x40
517 #define RTMGRP_IPV6_IFADDR 0x100
518 #define RTMGRP_IPV6_MROUTE 0x200
519 #define RTMGRP_IPV6_ROUTE 0x400
521 #define RTMGRP_DECnet_IFADDR 0x1000
522 #define RTMGRP_DECnet_ROUTE 0x4000
524 /* End of information exported to user level */
526 #ifdef __KERNEL__
528 extern __inline__ int rtattr_strcmp(struct rtattr *rta, char *str)
530 int len = strlen(str) + 1;
531 return len > rta->rta_len || memcmp(RTA_DATA(rta), str, len);
534 extern int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len);
536 #ifdef CONFIG_RTNETLINK
537 extern struct sock *rtnl;
539 struct rtnetlink_link
541 int (*doit)(struct sk_buff *, struct nlmsghdr*, void *attr);
542 int (*dumpit)(struct sk_buff *, struct netlink_callback *cb);
545 extern struct rtnetlink_link * rtnetlink_links[NPROTO];
546 extern int rtnetlink_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb);
547 extern int rtnetlink_send(struct sk_buff *skb, u32 pid, u32 group, int echo);
548 extern int rtnetlink_put_metrics(struct sk_buff *skb, unsigned *metrics);
550 extern void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data);
552 #define RTA_PUT(skb, attrtype, attrlen, data) \
553 ({ if (skb_tailroom(skb) < (int)RTA_SPACE(attrlen)) goto rtattr_failure; \
554 __rta_fill(skb, attrtype, attrlen, data); })
555 #endif
557 extern struct semaphore rtnl_sem;
559 #define rtnl_exlock() do { } while(0)
560 #define rtnl_exunlock() do { } while(0)
561 #define rtnl_exlock_nowait() (0)
563 #define rtnl_shlock() down(&rtnl_sem)
564 #define rtnl_shlock_nowait() down_trylock(&rtnl_sem)
566 #ifndef CONFIG_RTNETLINK
567 #define rtnl_shunlock() up(&rtnl_sem)
568 #else
569 #define rtnl_shunlock() do { up(&rtnl_sem); \
570 if (rtnl && rtnl->receive_queue.qlen) \
571 rtnl->data_ready(rtnl, 0); \
572 } while(0)
573 #endif
575 extern void rtnl_lock(void);
576 extern void rtnl_unlock(void);
577 extern void rtnetlink_init(void);
579 #define ASSERT_RTNL() do { if (down_trylock(&rtnl_sem) == 0) { up(&rtnl_sem); \
580 printk("RTNL: assertion failed at " __FILE__ "(%d):" __FUNCTION__ "\n", __LINE__); } \
581 } while(0);
582 #define BUG_TRAP(x) if (!(x)) { printk("KERNEL: assertion (" #x ") failed at " __FILE__ "(%d):" __FUNCTION__ "\n", __LINE__); }
585 #endif /* __KERNEL__ */
588 #endif /* __LINUX_RTNETLINK_H */