rib.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * Routing Information Base header
  3. * Copyright (C) 1997 Kunihiro Ishiguro
  4. *
  5. * This file is part of GNU Zebra.
  6. *
  7. * GNU Zebra is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2, or (at your option) any
  10. * later version.
  11. *
  12. * GNU Zebra is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  19. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  20. * 02111-1307, USA.
  21. */
  22. #ifndef _ZEBRA_RIB_H
  23. #define _ZEBRA_RIB_H
  24. #define DISTANCE_INFINITY 255
  25. /* Routing information base. */
  26. struct rib
  27. {
  28. /* Link list. */
  29. struct rib *next;
  30. struct rib *prev;
  31. /* Type fo this route. */
  32. int type;
  33. /* Which routing table */
  34. int table;
  35. /* Distance. */
  36. u_char distance;
  37. /* Flags of this route. This flag's definition is in lib/zebra.h
  38. ZEBRA_FLAG_* */
  39. u_char flags;
  40. /* Metric */
  41. u_int32_t metric;
  42. /* Uptime. */
  43. time_t uptime;
  44. /* Refrence count. */
  45. unsigned long refcnt;
  46. /* Nexthop information. */
  47. u_char nexthop_num;
  48. u_char nexthop_active_num;
  49. u_char nexthop_fib_num;
  50. struct nexthop *nexthop;
  51. };
  52. /* Static route information. */
  53. struct static_ipv4
  54. {
  55. /* For linked list. */
  56. struct static_ipv4 *prev;
  57. struct static_ipv4 *next;
  58. /* Administrative distance. */
  59. u_char distance;
  60. /* Flag for this static route's type. */
  61. u_char type;
  62. #define STATIC_IPV4_GATEWAY 1
  63. #define STATIC_IPV4_IFNAME 2
  64. #define STATIC_IPV4_BLACKHOLE 3
  65. /* Nexthop value. */
  66. union
  67. {
  68. struct in_addr ipv4;
  69. char *ifname;
  70. } gate;
  71. /* bit flags */
  72. u_char flags;
  73. /*
  74. see ZEBRA_FLAG_REJECT
  75. ZEBRA_FLAG_BLACKHOLE
  76. */
  77. };
  78. #ifdef HAVE_IPV6
  79. /* Static route information. */
  80. struct static_ipv6
  81. {
  82. /* For linked list. */
  83. struct static_ipv6 *prev;
  84. struct static_ipv6 *next;
  85. /* Administrative distance. */
  86. u_char distance;
  87. /* Flag for this static route's type. */
  88. u_char type;
  89. #define STATIC_IPV6_GATEWAY 1
  90. #define STATIC_IPV6_GATEWAY_IFNAME 2
  91. #define STATIC_IPV6_IFNAME 3
  92. /* Nexthop value. */
  93. struct in6_addr ipv6;
  94. char *ifname;
  95. /* bit flags */
  96. u_char flags;
  97. /*
  98. see ZEBRA_FLAG_REJECT
  99. ZEBRA_FLAG_BLACKHOLE
  100. */
  101. };
  102. #endif /* HAVE_IPV6 */
  103. enum nexthop_types_t
  104. {
  105. NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */
  106. NEXTHOP_TYPE_IFNAME, /* Interface route. */
  107. NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */
  108. NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */
  109. NEXTHOP_TYPE_IPV4_IFNAME, /* IPv4 nexthop with ifname. */
  110. NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */
  111. NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */
  112. NEXTHOP_TYPE_IPV6_IFNAME, /* IPv6 nexthop with ifname. */
  113. NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */
  114. };
  115. /* Nexthop structure. */
  116. struct nexthop
  117. {
  118. struct nexthop *next;
  119. struct nexthop *prev;
  120. enum nexthop_types_t type;
  121. u_char flags;
  122. #define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
  123. #define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
  124. #define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
  125. /* Interface index. */
  126. unsigned int ifindex;
  127. char *ifname;
  128. /* Nexthop address or interface name. */
  129. union
  130. {
  131. struct in_addr ipv4;
  132. #ifdef HAVE_IPV6
  133. struct in6_addr ipv6;
  134. #endif /* HAVE_IPV6*/
  135. } gate;
  136. /* Recursive lookup nexthop. */
  137. u_char rtype;
  138. unsigned int rifindex;
  139. union
  140. {
  141. struct in_addr ipv4;
  142. #ifdef HAVE_IPV6
  143. struct in6_addr ipv6;
  144. #endif /* HAVE_IPV6 */
  145. } rgate;
  146. struct nexthop *indirect;
  147. };
  148. /* Routing table instance. */
  149. struct vrf
  150. {
  151. /* Identifier. This is same as routing table vector index. */
  152. u_int32_t id;
  153. /* Routing table name. */
  154. char *name;
  155. /* Description. */
  156. char *desc;
  157. /* FIB identifier. */
  158. u_char fib_id;
  159. /* Routing table. */
  160. struct route_table *table[AFI_MAX][SAFI_MAX];
  161. /* Static route configuration. */
  162. struct route_table *stable[AFI_MAX][SAFI_MAX];
  163. };
  164. struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
  165. struct nexthop *nexthop_ifname_add (struct rib *, char *);
  166. struct nexthop *nexthop_blackhole_add (struct rib *);
  167. struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *);
  168. #ifdef HAVE_IPV6
  169. struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
  170. #endif /* HAVE_IPV6 */
  171. struct vrf *vrf_lookup (u_int32_t);
  172. struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id);
  173. struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id);
  174. int
  175. rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
  176. struct in_addr *gate, unsigned int ifindex, u_int32_t vrf_id,
  177. u_int32_t, u_char);
  178. int
  179. rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *);
  180. int
  181. rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
  182. struct in_addr *gate, unsigned int ifindex, u_int32_t);
  183. struct rib *
  184. rib_match_ipv4 (struct in_addr);
  185. struct rib *
  186. rib_lookup_ipv4 (struct prefix_ipv4 *);
  187. void rib_update ();
  188. void rib_sweep_route ();
  189. void rib_close ();
  190. void rib_init ();
  191. int
  192. static_add_ipv4 (struct prefix *p, struct in_addr *gate, char *ifname,
  193. u_char flags, u_char distance, u_int32_t vrf_id);
  194. int
  195. static_delete_ipv4 (struct prefix *p, struct in_addr *gate, char *ifname,
  196. u_char distance, u_int32_t vrf_id);
  197. #ifdef HAVE_IPV6
  198. int
  199. rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
  200. struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id);
  201. int
  202. rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
  203. struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id);
  204. struct rib *rib_lookup_ipv6 (struct in6_addr *);
  205. struct rib *rib_match_ipv6 (struct in6_addr *);
  206. extern struct route_table *rib_table_ipv6;
  207. int
  208. static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
  209. char *ifname, u_char flags, u_char distance, u_int32_t vrf_id);
  210. int
  211. static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
  212. char *ifname, u_char distance, u_int32_t vrf_id);
  213. #endif /* HAVE_IPV6 */
  214. #endif /*_ZEBRA_RIB_H */