cleanup
[linux-2.4.21-pre4.git] / include / net2 / 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 #define rt6i_dev                        u.dst.dev
61 #define rt6i_nexthop                    u.dst.neighbour
62 #define rt6i_expires                    u.dst.expires
63
64         struct fib6_node                *rt6i_node;
65
66         struct in6_addr                 rt6i_gateway;
67         
68         u32                             rt6i_flags;
69         u32                             rt6i_metric;
70         u8                              rt6i_hoplimit;
71         atomic_t                        rt6i_ref;
72
73         union {
74                 struct flow_rule        *rt6iu_flowr;
75                 struct flow_filter      *rt6iu_filter;
76         } flow_u;
77
78 #define rt6i_flowr                      flow_u.rt6iu_flowr
79 #define rt6i_filter                     flow_u.rt6iu_filter
80
81         struct rt6key                   rt6i_dst;
82         struct rt6key                   rt6i_src;
83 };
84
85 struct fib6_walker_t
86 {
87         struct fib6_walker_t *prev, *next;
88         struct fib6_node *root, *node;
89         struct rt6_info *leaf;
90         unsigned char state;
91         unsigned char prune;
92         int (*func)(struct fib6_walker_t *);
93         void *args;
94 };
95
96 extern struct fib6_walker_t fib6_walker_list;
97 extern rwlock_t fib6_walker_lock;
98
99 static inline void fib6_walker_link(struct fib6_walker_t *w)
100 {
101         write_lock_bh(&fib6_walker_lock);
102         w->next = fib6_walker_list.next;
103         w->prev = &fib6_walker_list;
104         w->next->prev = w;
105         w->prev->next = w;
106         write_unlock_bh(&fib6_walker_lock);
107 }
108
109 static inline void fib6_walker_unlink(struct fib6_walker_t *w)
110 {
111         write_lock_bh(&fib6_walker_lock);
112         w->next->prev = w->prev;
113         w->prev->next = w->next;
114         w->prev = w->next = w;
115         write_unlock_bh(&fib6_walker_lock);
116 }
117
118 struct rt6_statistics {
119         __u32           fib_nodes;
120         __u32           fib_route_nodes;
121         __u32           fib_rt_alloc;           /* permanet routes      */
122         __u32           fib_rt_entries;         /* rt entries in table  */
123         __u32           fib_rt_cache;           /* cache routes         */
124 };
125
126 #define RTN_TL_ROOT     0x0001
127 #define RTN_ROOT        0x0002          /* tree root node               */
128 #define RTN_RTINFO      0x0004          /* node with valid routing info */
129
130 /*
131  *      priority levels (or metrics)
132  *
133  */
134
135 #define RTPRI_FIREWALL  8               /* Firewall control information */
136 #define RTPRI_FLOW      16              /* Flow based forwarding rules  */
137 #define RTPRI_KERN_CTL  32              /* Kernel control routes        */
138
139 #define RTPRI_USER_MIN  256             /* Mimimum user priority        */
140 #define RTPRI_USER_MAX  1024            /* Maximum user priority        */
141
142 #define RTPRI_KERN_DFLT 4096            /* Kernel default routes        */
143
144 #define MAX_FLOW_BACKTRACE      32
145
146
147 typedef void                    (*f_pnode)(struct fib6_node *fn, void *);
148
149 extern struct fib6_node         ip6_routing_table;
150
151 /*
152  *      exported functions
153  */
154
155 extern struct fib6_node         *fib6_lookup(struct fib6_node *root,
156                                              struct in6_addr *daddr,
157                                              struct in6_addr *saddr);
158
159 struct fib6_node                *fib6_locate(struct fib6_node *root,
160                                              struct in6_addr *daddr, int dst_len,
161                                              struct in6_addr *saddr, int src_len);
162
163 extern void                     fib6_clean_tree(struct fib6_node *root,
164                                                 int (*func)(struct rt6_info *, void *arg),
165                                                 int prune, void *arg);
166
167 extern int                      fib6_walk(struct fib6_walker_t *w);
168 extern int                      fib6_walk_continue(struct fib6_walker_t *w);
169
170 extern int                      fib6_add(struct fib6_node *root,
171                                          struct rt6_info *rt);
172
173 extern int                      fib6_del(struct rt6_info *rt);
174
175 extern void                     inet6_rt_notify(int event, struct rt6_info *rt);
176
177 extern void                     fib6_run_gc(unsigned long dummy);
178
179 extern void                     fib6_gc_cleanup(void);
180
181 extern void                     fib6_init(void);
182 #endif
183 #endif