ip6_fib.h 4.9 KB

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