ip6_fib.h 4.8 KB

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