ip6_fib.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 rt6_info
  42. {
  43. union {
  44. struct dst_entry dst;
  45. struct rt6_info *next;
  46. } u;
  47. struct inet6_dev *rt6i_idev;
  48. #define rt6i_dev u.dst.dev
  49. #define rt6i_nexthop u.dst.neighbour
  50. #define rt6i_expires u.dst.expires
  51. struct fib6_node *rt6i_node;
  52. struct in6_addr rt6i_gateway;
  53. u32 rt6i_flags;
  54. u32 rt6i_metric;
  55. atomic_t rt6i_ref;
  56. struct rt6key rt6i_dst;
  57. struct rt6key rt6i_src;
  58. u8 rt6i_protocol;
  59. };
  60. struct fib6_walker_t
  61. {
  62. struct fib6_walker_t *prev, *next;
  63. struct fib6_node *root, *node;
  64. struct rt6_info *leaf;
  65. unsigned char state;
  66. unsigned char prune;
  67. int (*func)(struct fib6_walker_t *);
  68. void *args;
  69. };
  70. extern struct fib6_walker_t fib6_walker_list;
  71. extern rwlock_t fib6_walker_lock;
  72. static inline void fib6_walker_link(struct fib6_walker_t *w)
  73. {
  74. write_lock_bh(&fib6_walker_lock);
  75. w->next = fib6_walker_list.next;
  76. w->prev = &fib6_walker_list;
  77. w->next->prev = w;
  78. w->prev->next = w;
  79. write_unlock_bh(&fib6_walker_lock);
  80. }
  81. static inline void fib6_walker_unlink(struct fib6_walker_t *w)
  82. {
  83. write_lock_bh(&fib6_walker_lock);
  84. w->next->prev = w->prev;
  85. w->prev->next = w->next;
  86. w->prev = w->next = w;
  87. write_unlock_bh(&fib6_walker_lock);
  88. }
  89. struct rt6_statistics {
  90. __u32 fib_nodes;
  91. __u32 fib_route_nodes;
  92. __u32 fib_rt_alloc; /* permanent routes */
  93. __u32 fib_rt_entries; /* rt entries in table */
  94. __u32 fib_rt_cache; /* cache routes */
  95. __u32 fib_discarded_routes;
  96. };
  97. #define RTN_TL_ROOT 0x0001
  98. #define RTN_ROOT 0x0002 /* tree root node */
  99. #define RTN_RTINFO 0x0004 /* node with valid routing info */
  100. /*
  101. * priority levels (or metrics)
  102. *
  103. */
  104. #define RTPRI_FIREWALL 8 /* Firewall control information */
  105. #define RTPRI_FLOW 16 /* Flow based forwarding rules */
  106. #define RTPRI_KERN_CTL 32 /* Kernel control routes */
  107. #define RTPRI_USER_MIN 256 /* Mimimum user priority */
  108. #define RTPRI_USER_MAX 1024 /* Maximum user priority */
  109. #define RTPRI_KERN_DFLT 4096 /* Kernel default routes */
  110. #define MAX_FLOW_BACKTRACE 32
  111. typedef void (*f_pnode)(struct fib6_node *fn, void *);
  112. extern struct fib6_node ip6_routing_table;
  113. /*
  114. * exported functions
  115. */
  116. extern struct fib6_node *fib6_lookup(struct fib6_node *root,
  117. struct in6_addr *daddr,
  118. struct in6_addr *saddr);
  119. struct fib6_node *fib6_locate(struct fib6_node *root,
  120. struct in6_addr *daddr, int dst_len,
  121. struct in6_addr *saddr, int src_len);
  122. extern void fib6_clean_tree(struct fib6_node *root,
  123. int (*func)(struct rt6_info *, void *arg),
  124. int prune, void *arg);
  125. extern int fib6_walk(struct fib6_walker_t *w);
  126. extern int fib6_walk_continue(struct fib6_walker_t *w);
  127. extern int fib6_add(struct fib6_node *root,
  128. struct rt6_info *rt,
  129. struct nlmsghdr *nlh,
  130. void *rtattr,
  131. struct netlink_skb_parms *req);
  132. extern int fib6_del(struct rt6_info *rt,
  133. struct nlmsghdr *nlh,
  134. void *rtattr,
  135. struct netlink_skb_parms *req);
  136. extern void inet6_rt_notify(int event, struct rt6_info *rt,
  137. struct nlmsghdr *nlh,
  138. struct netlink_skb_parms *req);
  139. extern void fib6_run_gc(unsigned long dummy);
  140. extern void fib6_gc_cleanup(void);
  141. extern void fib6_init(void);
  142. #endif
  143. #endif