bgp_route.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /* BGP routing information base
  2. Copyright (C) 1996, 97, 98, 2000 Kunihiro Ishiguro
  3. This file is part of GNU Zebra.
  4. GNU Zebra is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. GNU Zebra is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Zebra; see the file COPYING. If not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. 02111-1307, USA. */
  16. #ifndef _QUAGGA_BGP_ROUTE_H
  17. #define _QUAGGA_BGP_ROUTE_H
  18. #include "queue.h"
  19. #include "bgp_table.h"
  20. struct bgp_nexthop_cache;
  21. /* Ancillary information to struct bgp_info,
  22. * used for uncommonly used data (aggregation, MPLS, etc.)
  23. * and lazily allocated to save memory.
  24. */
  25. struct bgp_info_extra
  26. {
  27. /* Pointer to dampening structure. */
  28. struct bgp_damp_info *damp_info;
  29. /* This route is suppressed with aggregation. */
  30. int suppress;
  31. /* Nexthop reachability check. */
  32. u_int32_t igpmetric;
  33. /* MPLS label. */
  34. u_char tag[3];
  35. };
  36. struct bgp_info
  37. {
  38. /* For linked list. */
  39. struct bgp_info *next;
  40. struct bgp_info *prev;
  41. /* For nexthop linked list */
  42. LIST_ENTRY(bgp_info) nh_thread;
  43. /* Back pointer to the prefix node */
  44. struct bgp_node *net;
  45. /* Back pointer to the nexthop structure */
  46. struct bgp_nexthop_cache *nexthop;
  47. /* Peer structure. */
  48. struct peer *peer;
  49. /* Attribute structure. */
  50. struct attr *attr;
  51. /* Extra information */
  52. struct bgp_info_extra *extra;
  53. /* Multipath information */
  54. struct bgp_info_mpath *mpath;
  55. /* Uptime. */
  56. time_t uptime;
  57. /* reference count */
  58. int lock;
  59. /* BGP information status. */
  60. u_int16_t flags;
  61. #define BGP_INFO_IGP_CHANGED (1 << 0)
  62. #define BGP_INFO_DAMPED (1 << 1)
  63. #define BGP_INFO_HISTORY (1 << 2)
  64. #define BGP_INFO_SELECTED (1 << 3)
  65. #define BGP_INFO_VALID (1 << 4)
  66. #define BGP_INFO_ATTR_CHANGED (1 << 5)
  67. #define BGP_INFO_DMED_CHECK (1 << 6)
  68. #define BGP_INFO_DMED_SELECTED (1 << 7)
  69. #define BGP_INFO_STALE (1 << 8)
  70. #define BGP_INFO_REMOVED (1 << 9)
  71. #define BGP_INFO_COUNTED (1 << 10)
  72. #define BGP_INFO_MULTIPATH (1 << 11)
  73. #define BGP_INFO_MULTIPATH_CHG (1 << 12)
  74. /* BGP route type. This can be static, RIP, OSPF, BGP etc. */
  75. u_char type;
  76. /* When above type is BGP. This sub type specify BGP sub type
  77. information. */
  78. u_char sub_type;
  79. #define BGP_ROUTE_NORMAL 0
  80. #define BGP_ROUTE_STATIC 1
  81. #define BGP_ROUTE_AGGREGATE 2
  82. #define BGP_ROUTE_REDISTRIBUTE 3
  83. };
  84. /* BGP static route configuration. */
  85. struct bgp_static
  86. {
  87. /* Backdoor configuration. */
  88. int backdoor;
  89. /* Import check status. */
  90. u_char valid;
  91. /* IGP metric. */
  92. u_int32_t igpmetric;
  93. /* IGP nexthop. */
  94. struct in_addr igpnexthop;
  95. /* Atomic set reference count (ie cause of pathlimit) */
  96. u_int32_t atomic;
  97. /* BGP redistribute route-map. */
  98. struct
  99. {
  100. char *name;
  101. struct route_map *map;
  102. } rmap;
  103. /* Route Distinguisher */
  104. struct prefix_rd prd;
  105. /* MPLS label. */
  106. u_char tag[3];
  107. };
  108. #define BGP_INFO_COUNTABLE(BI) \
  109. (! CHECK_FLAG ((BI)->flags, BGP_INFO_HISTORY) \
  110. && ! CHECK_FLAG ((BI)->flags, BGP_INFO_REMOVED))
  111. /* Flags which indicate a route is unuseable in some form */
  112. #define BGP_INFO_UNUSEABLE \
  113. (BGP_INFO_HISTORY|BGP_INFO_DAMPED|BGP_INFO_REMOVED)
  114. /* Macro to check BGP information is alive or not. Sadly,
  115. * not equivalent to just checking previous, because of the
  116. * sense of the additional VALID flag.
  117. */
  118. #define BGP_INFO_HOLDDOWN(BI) \
  119. (! CHECK_FLAG ((BI)->flags, BGP_INFO_VALID) \
  120. || CHECK_FLAG ((BI)->flags, BGP_INFO_UNUSEABLE))
  121. #define DISTRIBUTE_IN_NAME(F) ((F)->dlist[FILTER_IN].name)
  122. #define DISTRIBUTE_IN(F) ((F)->dlist[FILTER_IN].alist)
  123. #define DISTRIBUTE_OUT_NAME(F) ((F)->dlist[FILTER_OUT].name)
  124. #define DISTRIBUTE_OUT(F) ((F)->dlist[FILTER_OUT].alist)
  125. #define PREFIX_LIST_IN_NAME(F) ((F)->plist[FILTER_IN].name)
  126. #define PREFIX_LIST_IN(F) ((F)->plist[FILTER_IN].plist)
  127. #define PREFIX_LIST_OUT_NAME(F) ((F)->plist[FILTER_OUT].name)
  128. #define PREFIX_LIST_OUT(F) ((F)->plist[FILTER_OUT].plist)
  129. #define FILTER_LIST_IN_NAME(F) ((F)->aslist[FILTER_IN].name)
  130. #define FILTER_LIST_IN(F) ((F)->aslist[FILTER_IN].aslist)
  131. #define FILTER_LIST_OUT_NAME(F) ((F)->aslist[FILTER_OUT].name)
  132. #define FILTER_LIST_OUT(F) ((F)->aslist[FILTER_OUT].aslist)
  133. #define ROUTE_MAP_IN_NAME(F) ((F)->map[RMAP_IN].name)
  134. #define ROUTE_MAP_IN(F) ((F)->map[RMAP_IN].map)
  135. #define ROUTE_MAP_OUT_NAME(F) ((F)->map[RMAP_OUT].name)
  136. #define ROUTE_MAP_OUT(F) ((F)->map[RMAP_OUT].map)
  137. #define ROUTE_MAP_IMPORT_NAME(F) ((F)->map[RMAP_IMPORT].name)
  138. #define ROUTE_MAP_IMPORT(F) ((F)->map[RMAP_IMPORT].map)
  139. #define ROUTE_MAP_EXPORT_NAME(F) ((F)->map[RMAP_EXPORT].name)
  140. #define ROUTE_MAP_EXPORT(F) ((F)->map[RMAP_EXPORT].map)
  141. #define UNSUPPRESS_MAP_NAME(F) ((F)->usmap.name)
  142. #define UNSUPPRESS_MAP(F) ((F)->usmap.map)
  143. enum bgp_clear_route_type
  144. {
  145. BGP_CLEAR_ROUTE_NORMAL,
  146. BGP_CLEAR_ROUTE_MY_RSCLIENT
  147. };
  148. enum bgp_path_type
  149. {
  150. BGP_PATH_ALL,
  151. BGP_PATH_BESTPATH,
  152. BGP_PATH_MULTIPATH
  153. };
  154. /* Prototypes. */
  155. extern void bgp_route_init (void);
  156. extern void bgp_route_finish (void);
  157. extern void bgp_cleanup_routes (void);
  158. extern void bgp_announce_route (struct peer *, afi_t, safi_t);
  159. extern void bgp_announce_route_all (struct peer *);
  160. extern void bgp_default_originate (struct peer *, afi_t, safi_t, int);
  161. extern void bgp_soft_reconfig_in (struct peer *, afi_t, safi_t);
  162. extern void bgp_soft_reconfig_rsclient (struct peer *, afi_t, safi_t);
  163. extern void bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi);
  164. extern void bgp_clear_route (struct peer *, afi_t, safi_t,
  165. enum bgp_clear_route_type);
  166. extern void bgp_clear_route_all (struct peer *);
  167. extern void bgp_clear_adj_in (struct peer *, afi_t, safi_t);
  168. extern void bgp_clear_stale_route (struct peer *, afi_t, safi_t);
  169. extern struct bgp_info *bgp_info_lock (struct bgp_info *);
  170. extern struct bgp_info *bgp_info_unlock (struct bgp_info *);
  171. extern void bgp_info_add (struct bgp_node *rn, struct bgp_info *ri);
  172. extern void bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri);
  173. extern struct bgp_info_extra *bgp_info_extra_get (struct bgp_info *);
  174. extern void bgp_info_set_flag (struct bgp_node *, struct bgp_info *, u_int32_t);
  175. extern void bgp_info_unset_flag (struct bgp_node *, struct bgp_info *, u_int32_t);
  176. extern int bgp_nlri_parse_ip (struct peer *, struct attr *, struct bgp_nlri *);
  177. extern int bgp_maximum_prefix_overflow (struct peer *, afi_t, safi_t, int);
  178. extern void bgp_redistribute_add (struct prefix *, const struct in_addr *,
  179. const struct in6_addr *,
  180. u_int32_t, u_char, route_tag_t);
  181. extern void bgp_redistribute_delete (struct prefix *, u_char);
  182. extern void bgp_redistribute_withdraw (struct bgp *, afi_t, int);
  183. extern void bgp_static_delete (struct bgp *);
  184. extern void bgp_static_update (struct bgp *, struct prefix *, struct bgp_static *,
  185. afi_t, safi_t);
  186. extern void bgp_static_withdraw (struct bgp *, struct prefix *, afi_t, safi_t);
  187. extern int bgp_static_set_safi (safi_t safi, struct vty *vty, const char *,
  188. const char *, const char *, const char *);
  189. extern int bgp_static_unset_safi (safi_t safi, struct vty *, const char *,
  190. const char *, const char *);
  191. /* this is primarily for MPLS-VPN */
  192. extern int bgp_update (struct peer *, struct prefix *, struct attr *,
  193. afi_t, safi_t, int, int, struct prefix_rd *,
  194. u_char *, int);
  195. extern int bgp_withdraw (struct peer *, struct prefix *, struct attr *,
  196. afi_t, safi_t, int, int, struct prefix_rd *, u_char *);
  197. /* for bgp_nexthop and bgp_damp */
  198. extern void bgp_process (struct bgp *, struct bgp_node *, afi_t, safi_t);
  199. extern int bgp_config_write_network (struct vty *, struct bgp *, afi_t, safi_t, int *);
  200. extern int bgp_config_write_distance (struct vty *, struct bgp *, afi_t, safi_t, int *);
  201. extern void bgp_aggregate_increment (struct bgp *, struct prefix *, struct bgp_info *,
  202. afi_t, safi_t);
  203. extern void bgp_aggregate_decrement (struct bgp *, struct prefix *, struct bgp_info *,
  204. afi_t, safi_t);
  205. extern u_char bgp_distance_apply (struct prefix *, struct bgp_info *, struct bgp *);
  206. extern u_char ipv6_bgp_distance_apply (struct prefix *, struct bgp_info *, struct bgp *);
  207. extern afi_t bgp_node_afi (struct vty *);
  208. extern safi_t bgp_node_safi (struct vty *);
  209. extern void route_vty_out (struct vty *, struct prefix *, struct bgp_info *, int, safi_t);
  210. extern void route_vty_out_tag (struct vty *, struct prefix *, struct bgp_info *, int, safi_t);
  211. extern void route_vty_out_tmp (struct vty *, struct prefix *, struct attr *, safi_t);
  212. extern void bgp_peer_clear_node_queue_drain_immediate (struct peer *peer);
  213. extern void bgp_process_queues_drain_immediate (void);
  214. #endif /* _QUAGGA_BGP_ROUTE_H */