ip6_fib.h 4.8 KB

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