PageRenderTime 40ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/include/net/ip6_fib.h

https://github.com/mdombroski/linux-2.6
C Header | 321 lines | 228 code | 61 blank | 32 comment | 10 complexity | 6bc3f0e272f0c3d5c8bf87c23188400e MD5 | raw file
Possible License(s): GPL-2.0
  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. #include <linux/ipv6_route.h>
  15. #include <linux/rtnetlink.h>
  16. #include <linux/spinlock.h>
  17. #include <net/dst.h>
  18. #include <net/flow.h>
  19. #include <net/netlink.h>
  20. #include <net/inetpeer.h>
  21. #ifdef CONFIG_IPV6_MULTIPLE_TABLES
  22. #define FIB6_TABLE_HASHSZ 256
  23. #else
  24. #define FIB6_TABLE_HASHSZ 1
  25. #endif
  26. struct rt6_info;
  27. struct fib6_config {
  28. u32 fc_table;
  29. u32 fc_metric;
  30. int fc_dst_len;
  31. int fc_src_len;
  32. int fc_ifindex;
  33. u32 fc_flags;
  34. u32 fc_protocol;
  35. struct in6_addr fc_dst;
  36. struct in6_addr fc_src;
  37. struct in6_addr fc_prefsrc;
  38. struct in6_addr fc_gateway;
  39. unsigned long fc_expires;
  40. struct nlattr *fc_mx;
  41. int fc_mx_len;
  42. struct nl_info fc_nlinfo;
  43. };
  44. struct fib6_node {
  45. struct fib6_node *parent;
  46. struct fib6_node *left;
  47. struct fib6_node *right;
  48. #ifdef CONFIG_IPV6_SUBTREES
  49. struct fib6_node *subtree;
  50. #endif
  51. struct rt6_info *leaf;
  52. __u16 fn_bit; /* bit key */
  53. __u16 fn_flags;
  54. __u32 fn_sernum;
  55. struct rt6_info *rr_ptr;
  56. };
  57. #ifndef CONFIG_IPV6_SUBTREES
  58. #define FIB6_SUBTREE(fn) NULL
  59. #else
  60. #define FIB6_SUBTREE(fn) ((fn)->subtree)
  61. #endif
  62. /*
  63. * routing information
  64. *
  65. */
  66. struct rt6key {
  67. struct in6_addr addr;
  68. int plen;
  69. };
  70. struct fib6_table;
  71. struct rt6_info {
  72. struct dst_entry dst;
  73. struct neighbour *n;
  74. /*
  75. * Tail elements of dst_entry (__refcnt etc.)
  76. * and these elements (rarely used in hot path) are in
  77. * the same cache line.
  78. */
  79. struct fib6_table *rt6i_table;
  80. struct fib6_node *rt6i_node;
  81. struct in6_addr rt6i_gateway;
  82. atomic_t rt6i_ref;
  83. /* These are in a separate cache line. */
  84. struct rt6key rt6i_dst ____cacheline_aligned_in_smp;
  85. u32 rt6i_flags;
  86. struct rt6key rt6i_src;
  87. struct rt6key rt6i_prefsrc;
  88. u32 rt6i_metric;
  89. u32 rt6i_peer_genid;
  90. struct inet6_dev *rt6i_idev;
  91. unsigned long _rt6i_peer;
  92. #ifdef CONFIG_XFRM
  93. u32 rt6i_flow_cache_genid;
  94. #endif
  95. /* more non-fragment space at head required */
  96. unsigned short rt6i_nfheader_len;
  97. u8 rt6i_protocol;
  98. };
  99. static inline struct inet_peer *rt6_peer_ptr(struct rt6_info *rt)
  100. {
  101. return inetpeer_ptr(rt->_rt6i_peer);
  102. }
  103. static inline bool rt6_has_peer(struct rt6_info *rt)
  104. {
  105. return inetpeer_ptr_is_peer(rt->_rt6i_peer);
  106. }
  107. static inline void __rt6_set_peer(struct rt6_info *rt, struct inet_peer *peer)
  108. {
  109. __inetpeer_ptr_set_peer(&rt->_rt6i_peer, peer);
  110. }
  111. static inline bool rt6_set_peer(struct rt6_info *rt, struct inet_peer *peer)
  112. {
  113. return inetpeer_ptr_set_peer(&rt->_rt6i_peer, peer);
  114. }
  115. static inline void rt6_init_peer(struct rt6_info *rt, struct inet_peer_base *base)
  116. {
  117. inetpeer_init_ptr(&rt->_rt6i_peer, base);
  118. }
  119. static inline void rt6_transfer_peer(struct rt6_info *rt, struct rt6_info *ort)
  120. {
  121. inetpeer_transfer_peer(&rt->_rt6i_peer, &ort->_rt6i_peer);
  122. }
  123. static inline struct inet6_dev *ip6_dst_idev(struct dst_entry *dst)
  124. {
  125. return ((struct rt6_info *)dst)->rt6i_idev;
  126. }
  127. static inline void rt6_clean_expires(struct rt6_info *rt)
  128. {
  129. if (!(rt->rt6i_flags & RTF_EXPIRES) && rt->dst.from)
  130. dst_release(rt->dst.from);
  131. rt->rt6i_flags &= ~RTF_EXPIRES;
  132. rt->dst.from = NULL;
  133. }
  134. static inline void rt6_set_expires(struct rt6_info *rt, unsigned long expires)
  135. {
  136. if (!(rt->rt6i_flags & RTF_EXPIRES) && rt->dst.from)
  137. dst_release(rt->dst.from);
  138. rt->rt6i_flags |= RTF_EXPIRES;
  139. rt->dst.expires = expires;
  140. }
  141. static inline void rt6_update_expires(struct rt6_info *rt, int timeout)
  142. {
  143. if (!(rt->rt6i_flags & RTF_EXPIRES)) {
  144. if (rt->dst.from)
  145. dst_release(rt->dst.from);
  146. /* dst_set_expires relies on expires == 0
  147. * if it has not been set previously.
  148. */
  149. rt->dst.expires = 0;
  150. }
  151. dst_set_expires(&rt->dst, timeout);
  152. rt->rt6i_flags |= RTF_EXPIRES;
  153. }
  154. static inline void rt6_set_from(struct rt6_info *rt, struct rt6_info *from)
  155. {
  156. struct dst_entry *new = (struct dst_entry *) from;
  157. if (!(rt->rt6i_flags & RTF_EXPIRES) && rt->dst.from) {
  158. if (new == rt->dst.from)
  159. return;
  160. dst_release(rt->dst.from);
  161. }
  162. rt->rt6i_flags &= ~RTF_EXPIRES;
  163. rt->dst.from = new;
  164. dst_hold(new);
  165. }
  166. struct fib6_walker_t {
  167. struct list_head lh;
  168. struct fib6_node *root, *node;
  169. struct rt6_info *leaf;
  170. unsigned char state;
  171. unsigned char prune;
  172. unsigned int skip;
  173. unsigned int count;
  174. int (*func)(struct fib6_walker_t *);
  175. void *args;
  176. };
  177. struct rt6_statistics {
  178. __u32 fib_nodes;
  179. __u32 fib_route_nodes;
  180. __u32 fib_rt_alloc; /* permanent routes */
  181. __u32 fib_rt_entries; /* rt entries in table */
  182. __u32 fib_rt_cache; /* cache routes */
  183. __u32 fib_discarded_routes;
  184. };
  185. #define RTN_TL_ROOT 0x0001
  186. #define RTN_ROOT 0x0002 /* tree root node */
  187. #define RTN_RTINFO 0x0004 /* node with valid routing info */
  188. /*
  189. * priority levels (or metrics)
  190. *
  191. */
  192. struct fib6_table {
  193. struct hlist_node tb6_hlist;
  194. u32 tb6_id;
  195. rwlock_t tb6_lock;
  196. struct fib6_node tb6_root;
  197. struct inet_peer_base tb6_peers;
  198. };
  199. #define RT6_TABLE_UNSPEC RT_TABLE_UNSPEC
  200. #define RT6_TABLE_MAIN RT_TABLE_MAIN
  201. #define RT6_TABLE_DFLT RT6_TABLE_MAIN
  202. #define RT6_TABLE_INFO RT6_TABLE_MAIN
  203. #define RT6_TABLE_PREFIX RT6_TABLE_MAIN
  204. #ifdef CONFIG_IPV6_MULTIPLE_TABLES
  205. #define FIB6_TABLE_MIN 1
  206. #define FIB6_TABLE_MAX RT_TABLE_MAX
  207. #define RT6_TABLE_LOCAL RT_TABLE_LOCAL
  208. #else
  209. #define FIB6_TABLE_MIN RT_TABLE_MAIN
  210. #define FIB6_TABLE_MAX FIB6_TABLE_MIN
  211. #define RT6_TABLE_LOCAL RT6_TABLE_MAIN
  212. #endif
  213. typedef struct rt6_info *(*pol_lookup_t)(struct net *,
  214. struct fib6_table *,
  215. struct flowi6 *, int);
  216. /*
  217. * exported functions
  218. */
  219. extern struct fib6_table *fib6_get_table(struct net *net, u32 id);
  220. extern struct fib6_table *fib6_new_table(struct net *net, u32 id);
  221. extern struct dst_entry *fib6_rule_lookup(struct net *net,
  222. struct flowi6 *fl6, int flags,
  223. pol_lookup_t lookup);
  224. extern struct fib6_node *fib6_lookup(struct fib6_node *root,
  225. const struct in6_addr *daddr,
  226. const struct in6_addr *saddr);
  227. struct fib6_node *fib6_locate(struct fib6_node *root,
  228. const struct in6_addr *daddr, int dst_len,
  229. const struct in6_addr *saddr, int src_len);
  230. extern void fib6_clean_all_ro(struct net *net,
  231. int (*func)(struct rt6_info *, void *arg),
  232. int prune, void *arg);
  233. extern void fib6_clean_all(struct net *net,
  234. int (*func)(struct rt6_info *, void *arg),
  235. int prune, void *arg);
  236. extern int fib6_add(struct fib6_node *root,
  237. struct rt6_info *rt,
  238. struct nl_info *info);
  239. extern int fib6_del(struct rt6_info *rt,
  240. struct nl_info *info);
  241. extern void inet6_rt_notify(int event, struct rt6_info *rt,
  242. struct nl_info *info);
  243. extern void fib6_run_gc(unsigned long expires,
  244. struct net *net);
  245. extern void fib6_gc_cleanup(void);
  246. extern int fib6_init(void);
  247. #ifdef CONFIG_IPV6_MULTIPLE_TABLES
  248. extern int fib6_rules_init(void);
  249. extern void fib6_rules_cleanup(void);
  250. #else
  251. static inline int fib6_rules_init(void)
  252. {
  253. return 0;
  254. }
  255. static inline void fib6_rules_cleanup(void)
  256. {
  257. return ;
  258. }
  259. #endif
  260. #endif