Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | #include <linux/spinlock.h> |
| 24 | |
| 25 | struct rt6_info; |
| 26 | |
| 27 | struct fib6_node |
| 28 | { |
| 29 | struct fib6_node *parent; |
| 30 | struct fib6_node *left; |
| 31 | struct fib6_node *right; |
| 32 | |
| 33 | struct fib6_node *subtree; |
| 34 | |
| 35 | struct rt6_info *leaf; |
| 36 | |
| 37 | __u16 fn_bit; /* bit key */ |
| 38 | __u16 fn_flags; |
| 39 | __u32 fn_sernum; |
| 40 | }; |
| 41 | |
| 42 | |
| 43 | /* |
| 44 | * routing information |
| 45 | * |
| 46 | */ |
| 47 | |
| 48 | struct rt6key |
| 49 | { |
| 50 | struct in6_addr addr; |
| 51 | int plen; |
| 52 | }; |
| 53 | |
Thomas Graf | c71099a | 2006-08-04 23:20:06 -0700 | [diff] [blame] | 54 | struct fib6_table; |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | struct rt6_info |
| 57 | { |
| 58 | union { |
| 59 | struct dst_entry dst; |
| 60 | struct rt6_info *next; |
| 61 | } u; |
| 62 | |
| 63 | struct inet6_dev *rt6i_idev; |
| 64 | |
| 65 | #define rt6i_dev u.dst.dev |
| 66 | #define rt6i_nexthop u.dst.neighbour |
| 67 | #define rt6i_expires u.dst.expires |
| 68 | |
| 69 | struct fib6_node *rt6i_node; |
| 70 | |
| 71 | struct in6_addr rt6i_gateway; |
| 72 | |
| 73 | u32 rt6i_flags; |
| 74 | u32 rt6i_metric; |
| 75 | atomic_t rt6i_ref; |
Thomas Graf | c71099a | 2006-08-04 23:20:06 -0700 | [diff] [blame] | 76 | struct fib6_table *rt6i_table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | struct rt6key rt6i_dst; |
| 79 | struct rt6key rt6i_src; |
| 80 | |
| 81 | u8 rt6i_protocol; |
| 82 | }; |
| 83 | |
| 84 | struct fib6_walker_t |
| 85 | { |
| 86 | struct fib6_walker_t *prev, *next; |
| 87 | struct fib6_node *root, *node; |
| 88 | struct rt6_info *leaf; |
| 89 | unsigned char state; |
| 90 | unsigned char prune; |
| 91 | int (*func)(struct fib6_walker_t *); |
| 92 | void *args; |
| 93 | }; |
| 94 | |
| 95 | extern struct fib6_walker_t fib6_walker_list; |
| 96 | extern rwlock_t fib6_walker_lock; |
| 97 | |
| 98 | static inline void fib6_walker_link(struct fib6_walker_t *w) |
| 99 | { |
| 100 | write_lock_bh(&fib6_walker_lock); |
| 101 | w->next = fib6_walker_list.next; |
| 102 | w->prev = &fib6_walker_list; |
| 103 | w->next->prev = w; |
| 104 | w->prev->next = w; |
| 105 | write_unlock_bh(&fib6_walker_lock); |
| 106 | } |
| 107 | |
| 108 | static inline void fib6_walker_unlink(struct fib6_walker_t *w) |
| 109 | { |
| 110 | write_lock_bh(&fib6_walker_lock); |
| 111 | w->next->prev = w->prev; |
| 112 | w->prev->next = w->next; |
| 113 | w->prev = w->next = w; |
| 114 | write_unlock_bh(&fib6_walker_lock); |
| 115 | } |
| 116 | |
| 117 | struct rt6_statistics { |
| 118 | __u32 fib_nodes; |
| 119 | __u32 fib_route_nodes; |
| 120 | __u32 fib_rt_alloc; /* permanent routes */ |
| 121 | __u32 fib_rt_entries; /* rt entries in table */ |
| 122 | __u32 fib_rt_cache; /* cache routes */ |
| 123 | __u32 fib_discarded_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 | |
Thomas Graf | c71099a | 2006-08-04 23:20:06 -0700 | [diff] [blame] | 149 | struct fib6_table { |
| 150 | struct hlist_node tb6_hlist; |
| 151 | u32 tb6_id; |
| 152 | rwlock_t tb6_lock; |
| 153 | struct fib6_node tb6_root; |
| 154 | }; |
| 155 | |
| 156 | #define RT6_TABLE_UNSPEC RT_TABLE_UNSPEC |
| 157 | #define RT6_TABLE_MAIN RT_TABLE_MAIN |
Thomas Graf | c71099a | 2006-08-04 23:20:06 -0700 | [diff] [blame] | 158 | #define RT6_TABLE_DFLT RT6_TABLE_MAIN |
| 159 | #define RT6_TABLE_INFO RT6_TABLE_MAIN |
| 160 | #define RT6_TABLE_PREFIX RT6_TABLE_MAIN |
| 161 | |
| 162 | #ifdef CONFIG_IPV6_MULTIPLE_TABLES |
| 163 | #define FIB6_TABLE_MIN 1 |
| 164 | #define FIB6_TABLE_MAX RT_TABLE_MAX |
Thomas Graf | 101367c | 2006-08-04 03:39:02 -0700 | [diff] [blame^] | 165 | #define RT6_TABLE_LOCAL RT_TABLE_LOCAL |
Thomas Graf | c71099a | 2006-08-04 23:20:06 -0700 | [diff] [blame] | 166 | #else |
| 167 | #define FIB6_TABLE_MIN RT_TABLE_MAIN |
| 168 | #define FIB6_TABLE_MAX FIB6_TABLE_MIN |
Thomas Graf | 101367c | 2006-08-04 03:39:02 -0700 | [diff] [blame^] | 169 | #define RT6_TABLE_LOCAL RT6_TABLE_MAIN |
Thomas Graf | c71099a | 2006-08-04 23:20:06 -0700 | [diff] [blame] | 170 | #endif |
| 171 | |
| 172 | #define RT6_F_STRICT 1 |
| 173 | #define RT6_F_HAS_SADDR 2 |
| 174 | |
| 175 | typedef struct rt6_info *(*pol_lookup_t)(struct fib6_table *, |
| 176 | struct flowi *, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | /* |
| 179 | * exported functions |
| 180 | */ |
| 181 | |
Thomas Graf | c71099a | 2006-08-04 23:20:06 -0700 | [diff] [blame] | 182 | extern struct fib6_table * fib6_get_table(u32 id); |
| 183 | extern struct fib6_table * fib6_new_table(u32 id); |
| 184 | extern struct dst_entry * fib6_rule_lookup(struct flowi *fl, int flags, |
| 185 | pol_lookup_t lookup); |
| 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | extern struct fib6_node *fib6_lookup(struct fib6_node *root, |
| 188 | struct in6_addr *daddr, |
| 189 | struct in6_addr *saddr); |
| 190 | |
| 191 | struct fib6_node *fib6_locate(struct fib6_node *root, |
| 192 | struct in6_addr *daddr, int dst_len, |
| 193 | struct in6_addr *saddr, int src_len); |
| 194 | |
| 195 | extern void fib6_clean_tree(struct fib6_node *root, |
| 196 | int (*func)(struct rt6_info *, void *arg), |
| 197 | int prune, void *arg); |
| 198 | |
Thomas Graf | c71099a | 2006-08-04 23:20:06 -0700 | [diff] [blame] | 199 | extern void fib6_clean_all(int (*func)(struct rt6_info *, void *arg), |
| 200 | int prune, void *arg); |
| 201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | extern int fib6_walk(struct fib6_walker_t *w); |
| 203 | extern int fib6_walk_continue(struct fib6_walker_t *w); |
| 204 | |
| 205 | extern int fib6_add(struct fib6_node *root, |
| 206 | struct rt6_info *rt, |
| 207 | struct nlmsghdr *nlh, |
Jamal Hadi Salim | 0d51aa8 | 2005-06-21 13:51:04 -0700 | [diff] [blame] | 208 | void *rtattr, |
| 209 | struct netlink_skb_parms *req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
| 211 | extern int fib6_del(struct rt6_info *rt, |
| 212 | struct nlmsghdr *nlh, |
Jamal Hadi Salim | 0d51aa8 | 2005-06-21 13:51:04 -0700 | [diff] [blame] | 213 | void *rtattr, |
| 214 | struct netlink_skb_parms *req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
| 216 | extern void inet6_rt_notify(int event, struct rt6_info *rt, |
Jamal Hadi Salim | 0d51aa8 | 2005-06-21 13:51:04 -0700 | [diff] [blame] | 217 | struct nlmsghdr *nlh, |
| 218 | struct netlink_skb_parms *req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | extern void fib6_run_gc(unsigned long dummy); |
| 221 | |
| 222 | extern void fib6_gc_cleanup(void); |
| 223 | |
| 224 | extern void fib6_init(void); |
Thomas Graf | 101367c | 2006-08-04 03:39:02 -0700 | [diff] [blame^] | 225 | |
| 226 | extern void fib6_rules_init(void); |
| 227 | extern void fib6_rules_cleanup(void); |
| 228 | extern int fib6_rules_dump(struct sk_buff *, |
| 229 | struct netlink_callback *); |
| 230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | #endif |
| 232 | #endif |