ip6_fib.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. #ifndef _IP6_FIB_H
  13. #define _IP6_FIB_H
  14. #ifdef __KERNEL__
  15. #include <linux/ipv6_route.h>
  16. #include <net/dst.h>
  17. #include <net/flow.h>
  18. #include <linux/rtnetlink.h>
  19. #include <linux/spinlock.h>
  20. struct rt6_info;
  21. struct fib6_node
  22. {
  23. struct fib6_node *parent;
  24. struct fib6_node *left;
  25. struct fib6_node *right;
  26. struct fib6_node *subtree;
  27. struct rt6_info *leaf;
  28. __u16 fn_bit; /* bit key */
  29. __u16 fn_flags;
  30. __u32 fn_sernum;
  31. };
  32. /*
  33. * routing information
  34. *
  35. */
  36. struct rt6key
  37. {
  38. struct in6_addr addr;
  39. int plen;
  40. };
  41. struct fib6_table;
  42. struct rt6_info
  43. {
  44. union {
  45. struct dst_entry dst;
  46. struct rt6_info *next;
  47. } u;
  48. struct inet6_dev *rt6i_idev;
  49. #define rt6i_dev u.dst.dev
  50. #define rt6i_nexthop u.dst.neighbour
  51. #define rt6i_expires u.dst.expires
  52. struct fib6_node *rt6i_node;
  53. struct in6_addr rt6i_gateway;
  54. u32 rt6i_flags;
  55. u32 rt6i_metric;
  56. atomic_t rt6i_ref;
  57. struct fib6_table *rt6i_table;
  58. struct rt6key rt6i_dst;
  59. struct rt6key rt6i_src;
  60. u8 rt6i_protocol;
  61. };
  62. struct fib6_walker_t
  63. {
  64. struct fib6_walker_t *prev, *next;
  65. struct fib6_node *root, *node;
  66. struct rt6_info *leaf;
  67. unsigned char state;
  68. unsigned char prune;
  69. int (*func)(struct fib6_walker_t *);
  70. void *args;
  71. };
  72. extern struct fib6_walker_t fib6_walker_list;
  73. extern rwlock_t fib6_walker_lock;
  74. static inline void fib6_walker_link(struct fib6_walker_t *w)
  75. {
  76. write_lock_bh(&fib6_walker_lock);
  77. w->next = fib6_walker_list.next;
  78. w->prev = &fib6_walker_list;
  79. w->next->prev = w;
  80. w->prev->next = w;
  81. write_unlock_bh(&fib6_walker_lock);
  82. }
  83. static inline void fib6_walker_unlink(struct fib6_walker_t *w)
  84. {
  85. write_lock_bh(&fib6_walker_lock);
  86. w->next->prev = w->prev;
  87. w->prev->next = w->next;
  88. w->prev = w->next = w;
  89. write_unlock_bh(&fib6_walker_lock);
  90. }
  91. struct rt6_statistics {
  92. __u32 fib_nodes;
  93. __u32 fib_route_nodes;
  94. __u32 fib_rt_alloc; /* permanent routes */
  95. __u32 fib_rt_entries; /* rt entries in table */
  96. __u32 fib_rt_cache; /* cache routes */
  97. __u32 fib_discarded_routes;
  98. };
  99. #define RTN_TL_ROOT 0x0001
  100. #define RTN_ROOT 0x0002 /* tree root node */
  101. #define RTN_RTINFO 0x0004 /* node with valid routing info */
  102. /*
  103. * priority levels (or metrics)
  104. *
  105. */
  106. #define RTPRI_FIREWALL 8 /* Firewall control information */
  107. #define RTPRI_FLOW 16 /* Flow based forwarding rules */
  108. #define RTPRI_KERN_CTL 32 /* Kernel control routes */
  109. #define RTPRI_USER_MIN 256 /* Mimimum user priority */
  110. #define RTPRI_USER_MAX 1024 /* Maximum user priority */
  111. #define RTPRI_KERN_DFLT 4096 /* Kernel default routes */
  112. #define MAX_FLOW_BACKTRACE 32
  113. typedef void (*f_pnode)(struct fib6_node *fn, void *);
  114. struct fib6_table {
  115. struct hlist_node tb6_hlist;
  116. u32 tb6_id;
  117. rwlock_t tb6_lock;
  118. struct fib6_node tb6_root;
  119. };
  120. #define RT6_TABLE_UNSPEC RT_TABLE_UNSPEC
  121. #define RT6_TABLE_MAIN RT_TABLE_MAIN
  122. #define RT6_TABLE_DFLT RT6_TABLE_MAIN
  123. #define RT6_TABLE_INFO RT6_TABLE_MAIN
  124. #define RT6_TABLE_PREFIX RT6_TABLE_MAIN
  125. #ifdef CONFIG_IPV6_MULTIPLE_TABLES
  126. #define FIB6_TABLE_MIN 1
  127. #define FIB6_TABLE_MAX RT_TABLE_MAX
  128. #define RT6_TABLE_LOCAL RT_TABLE_LOCAL
  129. #else
  130. #define FIB6_TABLE_MIN RT_TABLE_MAIN
  131. #define FIB6_TABLE_MAX FIB6_TABLE_MIN
  132. #define RT6_TABLE_LOCAL RT6_TABLE_MAIN
  133. #endif
  134. #define RT6_F_STRICT 1
  135. #define RT6_F_HAS_SADDR 2
  136. typedef struct rt6_info *(*pol_lookup_t)(struct fib6_table *,
  137. struct flowi *, int);
  138. /*
  139. * exported functions
  140. */
  141. extern struct fib6_table * fib6_get_table(u32 id);
  142. extern struct fib6_table * fib6_new_table(u32 id);
  143. extern struct dst_entry * fib6_rule_lookup(struct flowi *fl, int flags,
  144. pol_lookup_t lookup);
  145. extern struct fib6_node *fib6_lookup(struct fib6_node *root,
  146. struct in6_addr *daddr,
  147. struct in6_addr *saddr);
  148. struct fib6_node *fib6_locate(struct fib6_node *root,
  149. struct in6_addr *daddr, int dst_len,
  150. struct in6_addr *saddr, int src_len);
  151. extern void fib6_clean_tree(struct fib6_node *root,
  152. int (*func)(struct rt6_info *, void *arg),
  153. int prune, void *arg);
  154. extern void fib6_clean_all(int (*func)(struct rt6_info *, void *arg),
  155. int prune, void *arg);
  156. extern int fib6_walk(struct fib6_walker_t *w);
  157. extern int fib6_walk_continue(struct fib6_walker_t *w);
  158. extern int fib6_add(struct fib6_node *root,
  159. struct rt6_info *rt,
  160. struct nlmsghdr *nlh,
  161. void *rtattr,
  162. struct netlink_skb_parms *req);
  163. extern int fib6_del(struct rt6_info *rt,
  164. struct nlmsghdr *nlh,
  165. void *rtattr,
  166. struct netlink_skb_parms *req);
  167. extern void inet6_rt_notify(int event, struct rt6_info *rt,
  168. struct nlmsghdr *nlh,
  169. struct netlink_skb_parms *req);
  170. extern void fib6_run_gc(unsigned long dummy);
  171. extern void fib6_gc_cleanup(void);
  172. extern void fib6_init(void);
  173. extern void fib6_rules_init(void);
  174. extern void fib6_rules_cleanup(void);
  175. extern int fib6_rules_dump(struct sk_buff *,
  176. struct netlink_callback *);
  177. #endif
  178. #endif