ip6_fib.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 <net/dst.h>
  17. #include <net/flow.h>
  18. #include <linux/rtnetlink.h>
  19. #include <linux/spinlock.h>
  20. struct rt6_info;
  21. struct fib6_node
  22. {
  23. struct fib6_node *parent;
  24. struct fib6_node *left;
  25. struct fib6_node *right;
  26. struct fib6_node *subtree;
  27. struct rt6_info *leaf;
  28. __u16 fn_bit; /* bit key */
  29. __u16 fn_flags;
  30. __u32 fn_sernum;
  31. };
  32. /*
  33. * routing information
  34. *
  35. */
  36. struct rt6key
  37. {
  38. struct in6_addr addr;
  39. int plen;
  40. };
  41. struct fib6_table;
  42. struct rt6_info
  43. {
  44. union {
  45. struct dst_entry dst;
  46. struct rt6_info *next;
  47. } u;
  48. struct inet6_dev *rt6i_idev;
  49. #define rt6i_dev u.dst.dev
  50. #define rt6i_nexthop u.dst.neighbour
  51. #define rt6i_expires u.dst.expires
  52. struct fib6_node *rt6i_node;
  53. struct in6_addr rt6i_gateway;
  54. u32 rt6i_flags;
  55. u32 rt6i_metric;
  56. atomic_t rt6i_ref;
  57. struct fib6_table *rt6i_table;
  58. struct rt6key rt6i_dst;
  59. struct rt6key rt6i_src;
  60. u8 rt6i_protocol;
  61. };
  62. struct fib6_walker_t
  63. {
  64. struct fib6_walker_t *prev, *next;
  65. struct fib6_node *root, *node;
  66. struct rt6_info *leaf;
  67. unsigned char state;
  68. unsigned char prune;
  69. int (*func)(struct fib6_walker_t *);
  70. void *args;
  71. };
  72. struct rt6_statistics {
  73. __u32 fib_nodes;
  74. __u32 fib_route_nodes;
  75. __u32 fib_rt_alloc; /* permanent routes */
  76. __u32 fib_rt_entries; /* rt entries in table */
  77. __u32 fib_rt_cache; /* cache routes */
  78. __u32 fib_discarded_routes;
  79. };
  80. #define RTN_TL_ROOT 0x0001
  81. #define RTN_ROOT 0x0002 /* tree root node */
  82. #define RTN_RTINFO 0x0004 /* node with valid routing info */
  83. /*
  84. * priority levels (or metrics)
  85. *
  86. */
  87. #define RTPRI_FIREWALL 8 /* Firewall control information */
  88. #define RTPRI_FLOW 16 /* Flow based forwarding rules */
  89. #define RTPRI_KERN_CTL 32 /* Kernel control routes */
  90. #define RTPRI_USER_MIN 256 /* Mimimum user priority */
  91. #define RTPRI_USER_MAX 1024 /* Maximum user priority */
  92. #define RTPRI_KERN_DFLT 4096 /* Kernel default routes */
  93. #define MAX_FLOW_BACKTRACE 32
  94. typedef void (*f_pnode)(struct fib6_node *fn, void *);
  95. struct fib6_table {
  96. struct hlist_node tb6_hlist;
  97. u32 tb6_id;
  98. rwlock_t tb6_lock;
  99. struct fib6_node tb6_root;
  100. };
  101. #define RT6_TABLE_UNSPEC RT_TABLE_UNSPEC
  102. #define RT6_TABLE_MAIN RT_TABLE_MAIN
  103. #define RT6_TABLE_DFLT RT6_TABLE_MAIN
  104. #define RT6_TABLE_INFO RT6_TABLE_MAIN
  105. #define RT6_TABLE_PREFIX RT6_TABLE_MAIN
  106. #ifdef CONFIG_IPV6_MULTIPLE_TABLES
  107. #define FIB6_TABLE_MIN 1
  108. #define FIB6_TABLE_MAX RT_TABLE_MAX
  109. #define RT6_TABLE_LOCAL RT_TABLE_LOCAL
  110. #else
  111. #define FIB6_TABLE_MIN RT_TABLE_MAIN
  112. #define FIB6_TABLE_MAX FIB6_TABLE_MIN
  113. #define RT6_TABLE_LOCAL RT6_TABLE_MAIN
  114. #endif
  115. #define RT6_F_STRICT 1
  116. #define RT6_F_HAS_SADDR 2
  117. typedef struct rt6_info *(*pol_lookup_t)(struct fib6_table *,
  118. struct flowi *, int);
  119. /*
  120. * exported functions
  121. */
  122. extern struct fib6_table * fib6_get_table(u32 id);
  123. extern struct fib6_table * fib6_new_table(u32 id);
  124. extern struct dst_entry * fib6_rule_lookup(struct flowi *fl, int flags,
  125. pol_lookup_t lookup);
  126. extern struct fib6_node *fib6_lookup(struct fib6_node *root,
  127. struct in6_addr *daddr,
  128. struct in6_addr *saddr);
  129. struct fib6_node *fib6_locate(struct fib6_node *root,
  130. struct in6_addr *daddr, int dst_len,
  131. struct in6_addr *saddr, int src_len);
  132. extern void fib6_clean_all(int (*func)(struct rt6_info *, void *arg),
  133. int prune, void *arg);
  134. extern int fib6_add(struct fib6_node *root,
  135. struct rt6_info *rt,
  136. struct nlmsghdr *nlh,
  137. void *rtattr,
  138. struct netlink_skb_parms *req);
  139. extern int fib6_del(struct rt6_info *rt,
  140. struct nlmsghdr *nlh,
  141. void *rtattr,
  142. struct netlink_skb_parms *req);
  143. extern void inet6_rt_notify(int event, struct rt6_info *rt,
  144. struct nlmsghdr *nlh,
  145. struct netlink_skb_parms *req);
  146. extern void fib6_run_gc(unsigned long dummy);
  147. extern void fib6_gc_cleanup(void);
  148. extern void fib6_init(void);
  149. extern void fib6_rules_init(void);
  150. extern void fib6_rules_cleanup(void);
  151. extern int fib6_rules_dump(struct sk_buff *,
  152. struct netlink_callback *);
  153. #endif
  154. #endif