ip6_fib.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. struct fib6_table *rt6i_table;
  83. struct rt6key rt6i_dst;
  84. struct rt6key rt6i_src;
  85. u8 rt6i_protocol;
  86. #ifdef CONFIG_XFRM
  87. u32 rt6i_flow_cache_genid;
  88. #endif
  89. };
  90. static inline struct inet6_dev *ip6_dst_idev(struct dst_entry *dst)
  91. {
  92. return ((struct rt6_info *)dst)->rt6i_idev;
  93. }
  94. struct fib6_walker_t
  95. {
  96. struct fib6_walker_t *prev, *next;
  97. struct fib6_node *root, *node;
  98. struct rt6_info *leaf;
  99. unsigned char state;
  100. unsigned char prune;
  101. int (*func)(struct fib6_walker_t *);
  102. void *args;
  103. };
  104. struct rt6_statistics {
  105. __u32 fib_nodes;
  106. __u32 fib_route_nodes;
  107. __u32 fib_rt_alloc; /* permanent routes */
  108. __u32 fib_rt_entries; /* rt entries in table */
  109. __u32 fib_rt_cache; /* cache routes */
  110. __u32 fib_discarded_routes;
  111. };
  112. #define RTN_TL_ROOT 0x0001
  113. #define RTN_ROOT 0x0002 /* tree root node */
  114. #define RTN_RTINFO 0x0004 /* node with valid routing info */
  115. /*
  116. * priority levels (or metrics)
  117. *
  118. */
  119. #define RTPRI_FIREWALL 8 /* Firewall control information */
  120. #define RTPRI_FLOW 16 /* Flow based forwarding rules */
  121. #define RTPRI_KERN_CTL 32 /* Kernel control routes */
  122. #define RTPRI_USER_MIN 256 /* Mimimum user priority */
  123. #define RTPRI_USER_MAX 1024 /* Maximum user priority */
  124. #define RTPRI_KERN_DFLT 4096 /* Kernel default routes */
  125. #define MAX_FLOW_BACKTRACE 32
  126. typedef void (*f_pnode)(struct fib6_node *fn, void *);
  127. struct fib6_table {
  128. struct hlist_node tb6_hlist;
  129. u32 tb6_id;
  130. rwlock_t tb6_lock;
  131. struct fib6_node tb6_root;
  132. };
  133. #define RT6_TABLE_UNSPEC RT_TABLE_UNSPEC
  134. #define RT6_TABLE_MAIN RT_TABLE_MAIN
  135. #define RT6_TABLE_DFLT RT6_TABLE_MAIN
  136. #define RT6_TABLE_INFO RT6_TABLE_MAIN
  137. #define RT6_TABLE_PREFIX RT6_TABLE_MAIN
  138. #ifdef CONFIG_IPV6_MULTIPLE_TABLES
  139. #define FIB6_TABLE_MIN 1
  140. #define FIB6_TABLE_MAX RT_TABLE_MAX
  141. #define RT6_TABLE_LOCAL RT_TABLE_LOCAL
  142. #else
  143. #define FIB6_TABLE_MIN RT_TABLE_MAIN
  144. #define FIB6_TABLE_MAX FIB6_TABLE_MIN
  145. #define RT6_TABLE_LOCAL RT6_TABLE_MAIN
  146. #endif
  147. typedef struct rt6_info *(*pol_lookup_t)(struct fib6_table *,
  148. struct flowi *, int);
  149. /*
  150. * exported functions
  151. */
  152. extern struct fib6_table * fib6_get_table(u32 id);
  153. extern struct fib6_table * fib6_new_table(u32 id);
  154. extern struct dst_entry * fib6_rule_lookup(struct flowi *fl, int flags,
  155. pol_lookup_t lookup);
  156. extern struct fib6_node *fib6_lookup(struct fib6_node *root,
  157. struct in6_addr *daddr,
  158. struct in6_addr *saddr);
  159. struct fib6_node *fib6_locate(struct fib6_node *root,
  160. struct in6_addr *daddr, int dst_len,
  161. struct in6_addr *saddr, int src_len);
  162. extern void fib6_clean_all(int (*func)(struct rt6_info *, void *arg),
  163. int prune, void *arg);
  164. extern int fib6_add(struct fib6_node *root,
  165. struct rt6_info *rt,
  166. struct nl_info *info);
  167. extern int fib6_del(struct rt6_info *rt,
  168. struct nl_info *info);
  169. extern void inet6_rt_notify(int event, struct rt6_info *rt,
  170. struct nl_info *info);
  171. extern void fib6_run_gc(unsigned long dummy);
  172. extern void fib6_gc_cleanup(void);
  173. extern void fib6_init(void);
  174. extern void fib6_rules_init(void);
  175. extern void fib6_rules_cleanup(void);
  176. #endif
  177. #endif