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. struct fib6_node *subtree;
  45. struct rt6_info *leaf;
  46. __u16 fn_bit; /* bit key */
  47. __u16 fn_flags;
  48. __u32 fn_sernum;
  49. };
  50. #ifndef CONFIG_IPV6_SUBTREES
  51. #define FIB6_SUBTREE(fn) NULL
  52. #else
  53. #define FIB6_SUBTREE(fn) ((fn)->subtree)
  54. #endif
  55. /*
  56. * routing information
  57. *
  58. */
  59. struct rt6key
  60. {
  61. struct in6_addr addr;
  62. int plen;
  63. };
  64. struct fib6_table;
  65. struct rt6_info
  66. {
  67. union {
  68. struct dst_entry dst;
  69. struct rt6_info *next;
  70. } u;
  71. struct inet6_dev *rt6i_idev;
  72. #define rt6i_dev u.dst.dev
  73. #define rt6i_nexthop u.dst.neighbour
  74. #define rt6i_expires u.dst.expires
  75. struct fib6_node *rt6i_node;
  76. struct in6_addr rt6i_gateway;
  77. u32 rt6i_flags;
  78. u32 rt6i_metric;
  79. atomic_t rt6i_ref;
  80. struct fib6_table *rt6i_table;
  81. struct rt6key rt6i_dst;
  82. struct rt6key rt6i_src;
  83. u8 rt6i_protocol;
  84. };
  85. static inline struct inet6_dev *ip6_dst_idev(struct dst_entry *dst)
  86. {
  87. return ((struct rt6_info *)dst)->rt6i_idev;
  88. }
  89. struct fib6_walker_t
  90. {
  91. struct fib6_walker_t *prev, *next;
  92. struct fib6_node *root, *node;
  93. struct rt6_info *leaf;
  94. unsigned char state;
  95. unsigned char prune;
  96. int (*func)(struct fib6_walker_t *);
  97. void *args;
  98. };
  99. struct rt6_statistics {
  100. __u32 fib_nodes;
  101. __u32 fib_route_nodes;
  102. __u32 fib_rt_alloc; /* permanent routes */
  103. __u32 fib_rt_entries; /* rt entries in table */
  104. __u32 fib_rt_cache; /* cache routes */
  105. __u32 fib_discarded_routes;
  106. };
  107. #define RTN_TL_ROOT 0x0001
  108. #define RTN_ROOT 0x0002 /* tree root node */
  109. #define RTN_RTINFO 0x0004 /* node with valid routing info */
  110. /*
  111. * priority levels (or metrics)
  112. *
  113. */
  114. #define RTPRI_FIREWALL 8 /* Firewall control information */
  115. #define RTPRI_FLOW 16 /* Flow based forwarding rules */
  116. #define RTPRI_KERN_CTL 32 /* Kernel control routes */
  117. #define RTPRI_USER_MIN 256 /* Mimimum user priority */
  118. #define RTPRI_USER_MAX 1024 /* Maximum user priority */
  119. #define RTPRI_KERN_DFLT 4096 /* Kernel default routes */
  120. #define MAX_FLOW_BACKTRACE 32
  121. typedef void (*f_pnode)(struct fib6_node *fn, void *);
  122. struct fib6_table {
  123. struct hlist_node tb6_hlist;
  124. u32 tb6_id;
  125. rwlock_t tb6_lock;
  126. struct fib6_node tb6_root;
  127. };
  128. #define RT6_TABLE_UNSPEC RT_TABLE_UNSPEC
  129. #define RT6_TABLE_MAIN RT_TABLE_MAIN
  130. #define RT6_TABLE_DFLT RT6_TABLE_MAIN
  131. #define RT6_TABLE_INFO RT6_TABLE_MAIN
  132. #define RT6_TABLE_PREFIX RT6_TABLE_MAIN
  133. #ifdef CONFIG_IPV6_MULTIPLE_TABLES
  134. #define FIB6_TABLE_MIN 1
  135. #define FIB6_TABLE_MAX RT_TABLE_MAX
  136. #define RT6_TABLE_LOCAL RT_TABLE_LOCAL
  137. #else
  138. #define FIB6_TABLE_MIN RT_TABLE_MAIN
  139. #define FIB6_TABLE_MAX FIB6_TABLE_MIN
  140. #define RT6_TABLE_LOCAL RT6_TABLE_MAIN
  141. #endif
  142. typedef struct rt6_info *(*pol_lookup_t)(struct fib6_table *,
  143. struct flowi *, int);
  144. /*
  145. * exported functions
  146. */
  147. extern struct fib6_table * fib6_get_table(u32 id);
  148. extern struct fib6_table * fib6_new_table(u32 id);
  149. extern struct dst_entry * fib6_rule_lookup(struct flowi *fl, int flags,
  150. pol_lookup_t lookup);
  151. extern struct fib6_node *fib6_lookup(struct fib6_node *root,
  152. struct in6_addr *daddr,
  153. struct in6_addr *saddr);
  154. struct fib6_node *fib6_locate(struct fib6_node *root,
  155. struct in6_addr *daddr, int dst_len,
  156. struct in6_addr *saddr, int src_len);
  157. extern void fib6_clean_all(int (*func)(struct rt6_info *, void *arg),
  158. int prune, void *arg);
  159. extern int fib6_add(struct fib6_node *root,
  160. struct rt6_info *rt,
  161. struct nl_info *info);
  162. extern int fib6_del(struct rt6_info *rt,
  163. struct nl_info *info);
  164. extern void inet6_rt_notify(int event, struct rt6_info *rt,
  165. struct nl_info *info);
  166. extern void fib6_run_gc(unsigned long dummy);
  167. extern void fib6_gc_cleanup(void);
  168. extern void fib6_init(void);
  169. extern void fib6_rules_init(void);
  170. extern void fib6_rules_cleanup(void);
  171. extern int fib6_rules_dump(struct sk_buff *,
  172. struct netlink_callback *);
  173. #endif
  174. #endif