ip6_fib.h 4.7 KB

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