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