patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / include / net / ip6_fib.h
1 /*
2  *      Linux INET6 implementation 
3  *
4  *      Authors:
5  *      Pedro Roque             <roque@di.fc.ul.pt>     
6  *
7  *      This program is free software; you can redistribute it and/or
8  *      modify it under the terms of the GNU General Public License
9  *      as published by the Free Software Foundation; either version
10  *      2 of the License, or (at your option) any later version.
11  */
12
13 #ifndef _IP6_FIB_H
14 #define _IP6_FIB_H
15
16 #ifdef __KERNEL__
17
18 #include <linux/ipv6_route.h>
19
20 #include <net/dst.h>
21 #include <net/flow.h>
22 #include <linux/rtnetlink.h>
23
24 struct rt6_info;
25
26 struct fib6_node
27 {
28         struct fib6_node        *parent;
29         struct fib6_node        *left;
30         struct fib6_node        *right;
31
32         struct fib6_node        *subtree;
33
34         struct rt6_info         *leaf;
35
36         __u16                   fn_bit;         /* bit key */
37         __u16                   fn_flags;
38         __u32                   fn_sernum;
39 };
40
41
42 /*
43  *      routing information
44  *
45  */
46
47 struct rt6key
48 {
49         struct in6_addr addr;
50         int             plen;
51 };
52
53 struct rt6_info
54 {
55         union {
56                 struct dst_entry        dst;
57                 struct rt6_info         *next;
58         } u;
59
60         struct inet6_dev                *rt6i_idev;
61
62 #define rt6i_dev                        u.dst.dev
63 #define rt6i_nexthop                    u.dst.neighbour
64 #define rt6i_expires                    u.dst.expires
65
66         struct fib6_node                *rt6i_node;
67
68         struct in6_addr                 rt6i_gateway;
69         
70         u32                             rt6i_flags;
71         u32                             rt6i_metric;
72         atomic_t                        rt6i_ref;
73
74         struct rt6key                   rt6i_dst;
75         struct rt6key                   rt6i_src;
76
77         u8                              rt6i_protocol;
78 };
79
80 struct fib6_walker_t
81 {
82         struct fib6_walker_t *prev, *next;
83         struct fib6_node *root, *node;
84         struct rt6_info *leaf;
85         unsigned char state;
86         unsigned char prune;
87         int (*func)(struct fib6_walker_t *);
88         void *args;
89 };
90
91 extern struct fib6_walker_t fib6_walker_list;
92 extern rwlock_t fib6_walker_lock;
93
94 static inline void fib6_walker_link(struct fib6_walker_t *w)
95 {
96         write_lock_bh(&fib6_walker_lock);
97         w->next = fib6_walker_list.next;
98         w->prev = &fib6_walker_list;
99         w->next->prev = w;
100         w->prev->next = w;
101         write_unlock_bh(&fib6_walker_lock);
102 }
103
104 static inline void fib6_walker_unlink(struct fib6_walker_t *w)
105 {
106         write_lock_bh(&fib6_walker_lock);
107         w->next->prev = w->prev;
108         w->prev->next = w->next;
109         w->prev = w->next = w;
110         write_unlock_bh(&fib6_walker_lock);
111 }
112
113 struct rt6_statistics {
114         __u32           fib_nodes;
115         __u32           fib_route_nodes;
116         __u32           fib_rt_alloc;           /* permanent routes     */
117         __u32           fib_rt_entries;         /* rt entries in table  */
118         __u32           fib_rt_cache;           /* cache routes         */
119         __u32           fib_discarded_routes;
120 };
121
122 #define RTN_TL_ROOT     0x0001
123 #define RTN_ROOT        0x0002          /* tree root node               */
124 #define RTN_RTINFO      0x0004          /* node with valid routing info */
125
126 /*
127  *      priority levels (or metrics)
128  *
129  */
130
131 #define RTPRI_FIREWALL  8               /* Firewall control information */
132 #define RTPRI_FLOW      16              /* Flow based forwarding rules  */
133 #define RTPRI_KERN_CTL  32              /* Kernel control routes        */
134
135 #define RTPRI_USER_MIN  256             /* Mimimum user priority        */
136 #define RTPRI_USER_MAX  1024            /* Maximum user priority        */
137
138 #define RTPRI_KERN_DFLT 4096            /* Kernel default routes        */
139
140 #define MAX_FLOW_BACKTRACE      32
141
142
143 typedef void                    (*f_pnode)(struct fib6_node *fn, void *);
144
145 extern struct fib6_node         ip6_routing_table;
146
147 /*
148  *      exported functions
149  */
150
151 extern struct fib6_node         *fib6_lookup(struct fib6_node *root,
152                                              struct in6_addr *daddr,
153                                              struct in6_addr *saddr);
154
155 struct fib6_node                *fib6_locate(struct fib6_node *root,
156                                              struct in6_addr *daddr, int dst_len,
157                                              struct in6_addr *saddr, int src_len);
158
159 extern void                     fib6_clean_tree(struct fib6_node *root,
160                                                 int (*func)(struct rt6_info *, void *arg),
161                                                 int prune, void *arg);
162
163 extern int                      fib6_walk(struct fib6_walker_t *w);
164 extern int                      fib6_walk_continue(struct fib6_walker_t *w);
165
166 extern int                      fib6_add(struct fib6_node *root,
167                                          struct rt6_info *rt,
168                                          struct nlmsghdr *nlh,
169                                          void *rtattr);
170
171 extern int                      fib6_del(struct rt6_info *rt,
172                                          struct nlmsghdr *nlh,
173                                          void *rtattr);
174
175 extern void                     inet6_rt_notify(int event, struct rt6_info *rt,
176                                                 struct nlmsghdr *nlh);
177
178 extern void                     fib6_run_gc(unsigned long dummy);
179
180 extern void                     fib6_gc_cleanup(void);
181
182 extern void                     fib6_init(void);
183 #endif
184 #endif