ip6_fib.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 <linux/rtnetlink.h>
  17. #include <linux/spinlock.h>
  18. #include <net/dst.h>
  19. #include <net/flow.h>
  20. #include <net/netlink.h>
  21. #ifdef CONFIG_IPV6_MULTIPLE_TABLES
  22. #define FIB6_TABLE_HASHSZ 256
  23. #else
  24. #define FIB6_TABLE_HASHSZ 1
  25. #endif
  26. struct rt6_info;
  27. struct fib6_config
  28. {
  29. u32 fc_table;
  30. u32 fc_metric;
  31. int fc_dst_len;
  32. int fc_src_len;
  33. int fc_ifindex;
  34. u32 fc_flags;
  35. u32 fc_protocol;
  36. struct in6_addr fc_dst;
  37. struct in6_addr fc_src;
  38. struct in6_addr fc_gateway;
  39. unsigned long fc_expires;
  40. struct nlattr *fc_mx;
  41. int fc_mx_len;
  42. struct nl_info fc_nlinfo;
  43. };
  44. struct fib6_node
  45. {
  46. struct fib6_node *parent;
  47. struct fib6_node *left;
  48. struct fib6_node *right;
  49. #ifdef CONFIG_IPV6_SUBTREES
  50. struct fib6_node *subtree;
  51. #endif
  52. struct rt6_info *leaf;
  53. __u16 fn_bit; /* bit key */
  54. __u16 fn_flags;
  55. __u32 fn_sernum;
  56. struct rt6_info *rr_ptr;
  57. };
  58. #ifndef CONFIG_IPV6_SUBTREES
  59. #define FIB6_SUBTREE(fn) NULL
  60. #else
  61. #define FIB6_SUBTREE(fn) ((fn)->subtree)
  62. #endif
  63. /*
  64. * routing information
  65. *
  66. */
  67. struct rt6key
  68. {
  69. struct in6_addr addr;
  70. int plen;
  71. };
  72. struct fib6_table;
  73. struct rt6_info
  74. {
  75. union {
  76. struct dst_entry dst;
  77. } u;
  78. struct inet6_dev *rt6i_idev;
  79. #define rt6i_dev u.dst.dev
  80. #define rt6i_nexthop u.dst.neighbour
  81. #define rt6i_expires u.dst.expires
  82. struct fib6_node *rt6i_node;
  83. struct in6_addr rt6i_gateway;
  84. u32 rt6i_flags;
  85. u32 rt6i_metric;
  86. atomic_t rt6i_ref;
  87. /* more non-fragment space at head required */
  88. unsigned short rt6i_nfheader_len;
  89. u8 rt6i_protocol;
  90. struct fib6_table *rt6i_table;
  91. struct rt6key rt6i_dst;
  92. #ifdef CONFIG_XFRM
  93. u32 rt6i_flow_cache_genid;
  94. #endif
  95. struct rt6key rt6i_src;
  96. };
  97. static inline struct inet6_dev *ip6_dst_idev(struct dst_entry *dst)
  98. {
  99. return ((struct rt6_info *)dst)->rt6i_idev;
  100. }
  101. struct fib6_walker_t
  102. {
  103. struct fib6_walker_t *prev, *next;
  104. struct fib6_node *root, *node;
  105. struct rt6_info *leaf;
  106. unsigned char state;
  107. unsigned char prune;
  108. int (*func)(struct fib6_walker_t *);
  109. void *args;
  110. };
  111. struct rt6_statistics {
  112. __u32 fib_nodes;
  113. __u32 fib_route_nodes;
  114. __u32 fib_rt_alloc; /* permanent routes */
  115. __u32 fib_rt_entries; /* rt entries in table */
  116. __u32 fib_rt_cache; /* cache routes */
  117. __u32 fib_discarded_routes;
  118. };
  119. #define RTN_TL_ROOT 0x0001
  120. #define RTN_ROOT 0x0002 /* tree root node */
  121. #define RTN_RTINFO 0x0004 /* node with valid routing info */
  122. /*
  123. * priority levels (or metrics)
  124. *
  125. */
  126. struct fib6_table {
  127. struct hlist_node tb6_hlist;
  128. u32 tb6_id;
  129. rwlock_t tb6_lock;
  130. struct fib6_node tb6_root;
  131. };
  132. #define RT6_TABLE_UNSPEC RT_TABLE_UNSPEC
  133. #define RT6_TABLE_MAIN RT_TABLE_MAIN
  134. #define RT6_TABLE_DFLT RT6_TABLE_MAIN
  135. #define RT6_TABLE_INFO RT6_TABLE_MAIN
  136. #define RT6_TABLE_PREFIX RT6_TABLE_MAIN
  137. #ifdef CONFIG_IPV6_MULTIPLE_TABLES
  138. #define FIB6_TABLE_MIN 1
  139. #define FIB6_TABLE_MAX RT_TABLE_MAX
  140. #define RT6_TABLE_LOCAL RT_TABLE_LOCAL
  141. #else
  142. #define FIB6_TABLE_MIN RT_TABLE_MAIN
  143. #define FIB6_TABLE_MAX FIB6_TABLE_MIN
  144. #define RT6_TABLE_LOCAL RT6_TABLE_MAIN
  145. #endif
  146. typedef struct rt6_info *(*pol_lookup_t)(struct net *,
  147. struct fib6_table *,
  148. struct flowi *, int);
  149. /*
  150. * exported functions
  151. */
  152. extern struct fib6_table *fib6_get_table(struct net *net, u32 id);
  153. extern struct fib6_table *fib6_new_table(struct net *net, u32 id);
  154. extern struct dst_entry *fib6_rule_lookup(struct net *net,
  155. struct flowi *fl, int flags,
  156. pol_lookup_t lookup);
  157. extern struct fib6_node *fib6_lookup(struct fib6_node *root,
  158. struct in6_addr *daddr,
  159. struct in6_addr *saddr);
  160. struct fib6_node *fib6_locate(struct fib6_node *root,
  161. struct in6_addr *daddr, int dst_len,
  162. struct in6_addr *saddr, int src_len);
  163. extern void fib6_clean_all(struct net *net,
  164. int (*func)(struct rt6_info *, void *arg),
  165. int prune, void *arg);
  166. extern int fib6_add(struct fib6_node *root,
  167. struct rt6_info *rt,
  168. struct nl_info *info);
  169. extern int fib6_del(struct rt6_info *rt,
  170. struct nl_info *info);
  171. extern void inet6_rt_notify(int event, struct rt6_info *rt,
  172. struct nl_info *info);
  173. extern void fib6_run_gc(unsigned long expires,
  174. struct net *net);
  175. extern void fib6_gc_cleanup(void);
  176. extern int fib6_init(void);
  177. #ifdef CONFIG_IPV6_MULTIPLE_TABLES
  178. extern int fib6_rules_init(void);
  179. extern void fib6_rules_cleanup(void);
  180. #else
  181. static inline int fib6_rules_init(void)
  182. {
  183. return 0;
  184. }
  185. static inline void fib6_rules_cleanup(void)
  186. {
  187. return ;
  188. }
  189. #endif
  190. #endif
  191. #endif