]>
Commit | Line | Data |
---|---|---|
718e3744 | 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 | ||
00d252cb | 21 | #ifndef _QUAGGA_BGP_ROUTE_H |
22 | #define _QUAGGA_BGP_ROUTE_H | |
23 | ||
b05a1c8b | 24 | #include <json/json.h> |
fb018d25 | 25 | #include "queue.h" |
200df115 | 26 | #include "bgp_table.h" |
27 | ||
fb018d25 DS |
28 | struct bgp_nexthop_cache; |
29 | ||
3f9c7369 DS |
30 | #define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\ |
31 | "h history, * valid, > best, = multipath,%s"\ | |
32 | " i internal, r RIB-failure, S Stale, R Removed%s" | |
33 | #define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s" | |
34 | #define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s" | |
35 | ||
fb982c25 PJ |
36 | /* Ancillary information to struct bgp_info, |
37 | * used for uncommonly used data (aggregation, MPLS, etc.) | |
38 | * and lazily allocated to save memory. | |
39 | */ | |
40 | struct bgp_info_extra | |
41 | { | |
42 | /* Pointer to dampening structure. */ | |
43 | struct bgp_damp_info *damp_info; | |
44 | ||
45 | /* This route is suppressed with aggregation. */ | |
46 | int suppress; | |
47 | ||
48 | /* Nexthop reachability check. */ | |
49 | u_int32_t igpmetric; | |
50 | ||
51 | /* MPLS label. */ | |
52 | u_char tag[3]; | |
53 | }; | |
54 | ||
718e3744 | 55 | struct bgp_info |
56 | { | |
57 | /* For linked list. */ | |
58 | struct bgp_info *next; | |
59 | struct bgp_info *prev; | |
fb018d25 DS |
60 | |
61 | /* For nexthop linked list */ | |
62 | LIST_ENTRY(bgp_info) nh_thread; | |
63 | ||
64 | /* Back pointer to the prefix node */ | |
65 | struct bgp_node *net; | |
66 | ||
67 | /* Back pointer to the nexthop structure */ | |
68 | struct bgp_nexthop_cache *nexthop; | |
69 | ||
cbdfbaa5 PJ |
70 | /* Peer structure. */ |
71 | struct peer *peer; | |
72 | ||
73 | /* Attribute structure. */ | |
74 | struct attr *attr; | |
fb982c25 PJ |
75 | |
76 | /* Extra information */ | |
77 | struct bgp_info_extra *extra; | |
78 | ||
de8d5dff JB |
79 | |
80 | /* Multipath information */ | |
81 | struct bgp_info_mpath *mpath; | |
82 | ||
cbdfbaa5 PJ |
83 | /* Uptime. */ |
84 | time_t uptime; | |
85 | ||
200df115 | 86 | /* reference count */ |
228da428 | 87 | int lock; |
200df115 | 88 | |
718e3744 | 89 | /* BGP information status. */ |
93406d87 | 90 | u_int16_t flags; |
718e3744 | 91 | #define BGP_INFO_IGP_CHANGED (1 << 0) |
92 | #define BGP_INFO_DAMPED (1 << 1) | |
93 | #define BGP_INFO_HISTORY (1 << 2) | |
94 | #define BGP_INFO_SELECTED (1 << 3) | |
95 | #define BGP_INFO_VALID (1 << 4) | |
96 | #define BGP_INFO_ATTR_CHANGED (1 << 5) | |
97 | #define BGP_INFO_DMED_CHECK (1 << 6) | |
98 | #define BGP_INFO_DMED_SELECTED (1 << 7) | |
93406d87 | 99 | #define BGP_INFO_STALE (1 << 8) |
b40d939b | 100 | #define BGP_INFO_REMOVED (1 << 9) |
902212c3 | 101 | #define BGP_INFO_COUNTED (1 << 10) |
de8d5dff JB |
102 | #define BGP_INFO_MULTIPATH (1 << 11) |
103 | #define BGP_INFO_MULTIPATH_CHG (1 << 12) | |
718e3744 | 104 | |
cbdfbaa5 PJ |
105 | /* BGP route type. This can be static, RIP, OSPF, BGP etc. */ |
106 | u_char type; | |
107 | ||
108 | /* When above type is BGP. This sub type specify BGP sub type | |
109 | information. */ | |
110 | u_char sub_type; | |
111 | #define BGP_ROUTE_NORMAL 0 | |
112 | #define BGP_ROUTE_STATIC 1 | |
113 | #define BGP_ROUTE_AGGREGATE 2 | |
114 | #define BGP_ROUTE_REDISTRIBUTE 3 | |
7c8ff89e DS |
115 | |
116 | u_short instance; | |
117 | ||
a82478b9 DS |
118 | /* Addpath identifiers */ |
119 | u_int32_t addpath_rx_id; | |
120 | u_int32_t addpath_tx_id; | |
121 | ||
718e3744 | 122 | }; |
123 | ||
124 | /* BGP static route configuration. */ | |
125 | struct bgp_static | |
126 | { | |
127 | /* Backdoor configuration. */ | |
128 | int backdoor; | |
129 | ||
130 | /* Import check status. */ | |
131 | u_char valid; | |
132 | ||
133 | /* IGP metric. */ | |
134 | u_int32_t igpmetric; | |
135 | ||
136 | /* IGP nexthop. */ | |
137 | struct in_addr igpnexthop; | |
138 | ||
41367172 PJ |
139 | /* Atomic set reference count (ie cause of pathlimit) */ |
140 | u_int32_t atomic; | |
141 | ||
718e3744 | 142 | /* BGP redistribute route-map. */ |
143 | struct | |
144 | { | |
145 | char *name; | |
146 | struct route_map *map; | |
147 | } rmap; | |
148 | ||
149 | /* MPLS label. */ | |
150 | u_char tag[3]; | |
151 | }; | |
152 | ||
80e0ad24 DS |
153 | #define BGP_INFO_COUNTABLE(BI) \ |
154 | (! CHECK_FLAG ((BI)->flags, BGP_INFO_HISTORY) \ | |
155 | && ! CHECK_FLAG ((BI)->flags, BGP_INFO_REMOVED)) | |
156 | ||
1a392d46 PJ |
157 | /* Flags which indicate a route is unuseable in some form */ |
158 | #define BGP_INFO_UNUSEABLE \ | |
159 | (BGP_INFO_HISTORY|BGP_INFO_DAMPED|BGP_INFO_REMOVED) | |
160 | /* Macro to check BGP information is alive or not. Sadly, | |
161 | * not equivalent to just checking previous, because of the | |
162 | * sense of the additional VALID flag. | |
163 | */ | |
164 | #define BGP_INFO_HOLDDOWN(BI) \ | |
165 | (! CHECK_FLAG ((BI)->flags, BGP_INFO_VALID) \ | |
166 | || CHECK_FLAG ((BI)->flags, BGP_INFO_UNUSEABLE)) | |
167 | ||
718e3744 | 168 | #define DISTRIBUTE_IN_NAME(F) ((F)->dlist[FILTER_IN].name) |
169 | #define DISTRIBUTE_IN(F) ((F)->dlist[FILTER_IN].alist) | |
170 | #define DISTRIBUTE_OUT_NAME(F) ((F)->dlist[FILTER_OUT].name) | |
171 | #define DISTRIBUTE_OUT(F) ((F)->dlist[FILTER_OUT].alist) | |
172 | ||
173 | #define PREFIX_LIST_IN_NAME(F) ((F)->plist[FILTER_IN].name) | |
174 | #define PREFIX_LIST_IN(F) ((F)->plist[FILTER_IN].plist) | |
175 | #define PREFIX_LIST_OUT_NAME(F) ((F)->plist[FILTER_OUT].name) | |
176 | #define PREFIX_LIST_OUT(F) ((F)->plist[FILTER_OUT].plist) | |
177 | ||
178 | #define FILTER_LIST_IN_NAME(F) ((F)->aslist[FILTER_IN].name) | |
179 | #define FILTER_LIST_IN(F) ((F)->aslist[FILTER_IN].aslist) | |
180 | #define FILTER_LIST_OUT_NAME(F) ((F)->aslist[FILTER_OUT].name) | |
181 | #define FILTER_LIST_OUT(F) ((F)->aslist[FILTER_OUT].aslist) | |
182 | ||
fee0f4c6 | 183 | #define ROUTE_MAP_IN_NAME(F) ((F)->map[RMAP_IN].name) |
184 | #define ROUTE_MAP_IN(F) ((F)->map[RMAP_IN].map) | |
185 | #define ROUTE_MAP_OUT_NAME(F) ((F)->map[RMAP_OUT].name) | |
186 | #define ROUTE_MAP_OUT(F) ((F)->map[RMAP_OUT].map) | |
187 | ||
188 | #define ROUTE_MAP_IMPORT_NAME(F) ((F)->map[RMAP_IMPORT].name) | |
189 | #define ROUTE_MAP_IMPORT(F) ((F)->map[RMAP_IMPORT].map) | |
190 | #define ROUTE_MAP_EXPORT_NAME(F) ((F)->map[RMAP_EXPORT].name) | |
191 | #define ROUTE_MAP_EXPORT(F) ((F)->map[RMAP_EXPORT].map) | |
718e3744 | 192 | |
193 | #define UNSUPPRESS_MAP_NAME(F) ((F)->usmap.name) | |
194 | #define UNSUPPRESS_MAP(F) ((F)->usmap.map) | |
195 | ||
228da428 CC |
196 | enum bgp_clear_route_type |
197 | { | |
198 | BGP_CLEAR_ROUTE_NORMAL, | |
199 | BGP_CLEAR_ROUTE_MY_RSCLIENT | |
200 | }; | |
201 | ||
4092b06c DS |
202 | enum bgp_path_type |
203 | { | |
204 | BGP_PATH_ALL, | |
205 | BGP_PATH_BESTPATH, | |
206 | BGP_PATH_MULTIPATH | |
207 | }; | |
208 | ||
3f9c7369 DS |
209 | static inline void |
210 | bgp_bump_version (struct bgp_node *node) | |
211 | { | |
212 | node->version = bgp_table_next_version(bgp_node_table(node)); | |
213 | } | |
214 | ||
718e3744 | 215 | /* Prototypes. */ |
f188f2c4 | 216 | extern void bgp_process_queue_init (void); |
94f2b392 | 217 | extern void bgp_route_init (void); |
228da428 | 218 | extern void bgp_route_finish (void); |
94f2b392 | 219 | extern void bgp_cleanup_routes (void); |
220 | extern void bgp_announce_route (struct peer *, afi_t, safi_t); | |
3f9c7369 | 221 | extern void bgp_stop_announce_route_timer(struct peer_af *paf); |
94f2b392 | 222 | extern void bgp_announce_route_all (struct peer *); |
223 | extern void bgp_default_originate (struct peer *, afi_t, safi_t, int); | |
224 | extern void bgp_soft_reconfig_in (struct peer *, afi_t, safi_t); | |
225 | extern void bgp_soft_reconfig_rsclient (struct peer *, afi_t, safi_t); | |
226 | extern void bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi); | |
228da428 CC |
227 | extern void bgp_clear_route (struct peer *, afi_t, safi_t, |
228 | enum bgp_clear_route_type); | |
94f2b392 | 229 | extern void bgp_clear_route_all (struct peer *); |
230 | extern void bgp_clear_adj_in (struct peer *, afi_t, safi_t); | |
231 | extern void bgp_clear_stale_route (struct peer *, afi_t, safi_t); | |
718e3744 | 232 | |
200df115 | 233 | extern struct bgp_info *bgp_info_lock (struct bgp_info *); |
234 | extern struct bgp_info *bgp_info_unlock (struct bgp_info *); | |
235 | extern void bgp_info_add (struct bgp_node *rn, struct bgp_info *ri); | |
236 | extern void bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri); | |
fb982c25 | 237 | extern struct bgp_info_extra *bgp_info_extra_get (struct bgp_info *); |
1a392d46 PJ |
238 | extern void bgp_info_set_flag (struct bgp_node *, struct bgp_info *, u_int32_t); |
239 | extern void bgp_info_unset_flag (struct bgp_node *, struct bgp_info *, u_int32_t); | |
200df115 | 240 | |
a82478b9 | 241 | extern int bgp_nlri_sanity_check (struct peer *, int, safi_t, u_char *, bgp_size_t, int *); |
94f2b392 | 242 | extern int bgp_nlri_parse (struct peer *, struct attr *, struct bgp_nlri *); |
718e3744 | 243 | |
94f2b392 | 244 | extern int bgp_maximum_prefix_overflow (struct peer *, afi_t, safi_t, int); |
718e3744 | 245 | |
f04a80a5 | 246 | extern void bgp_redistribute_add (struct prefix *, const struct in_addr *, |
bc413143 | 247 | const struct in6_addr *, unsigned int ifindex, |
7c8ff89e DS |
248 | u_int32_t, u_char, u_short, u_short); |
249 | extern void bgp_redistribute_delete (struct prefix *, u_char, u_short); | |
250 | extern void bgp_redistribute_withdraw (struct bgp *, afi_t, int, u_short); | |
718e3744 | 251 | |
94f2b392 | 252 | extern void bgp_static_delete (struct bgp *); |
078430f6 | 253 | extern void bgp_static_redo_import_check (struct bgp *); |
94f2b392 | 254 | extern void bgp_static_update (struct bgp *, struct prefix *, struct bgp_static *, |
718e3744 | 255 | afi_t, safi_t); |
94f2b392 | 256 | extern void bgp_static_withdraw (struct bgp *, struct prefix *, afi_t, safi_t); |
718e3744 | 257 | |
94f2b392 | 258 | extern int bgp_static_set_vpnv4 (struct vty *vty, const char *, |
fd79ac91 | 259 | const char *, const char *); |
718e3744 | 260 | |
94f2b392 | 261 | extern int bgp_static_unset_vpnv4 (struct vty *, const char *, |
fd79ac91 | 262 | const char *, const char *); |
718e3744 | 263 | |
94f2b392 | 264 | /* this is primarily for MPLS-VPN */ |
a82478b9 | 265 | extern int bgp_update (struct peer *, struct prefix *, u_int32_t, struct attr *, |
94f2b392 | 266 | afi_t, safi_t, int, int, struct prefix_rd *, |
267 | u_char *, int); | |
a82478b9 | 268 | extern int bgp_withdraw (struct peer *, struct prefix *, u_int32_t, struct attr *, |
94f2b392 | 269 | afi_t, safi_t, int, int, struct prefix_rd *, u_char *); |
718e3744 | 270 | |
94f2b392 | 271 | /* for bgp_nexthop and bgp_damp */ |
272 | extern void bgp_process (struct bgp *, struct bgp_node *, afi_t, safi_t); | |
cb1faec9 DS |
273 | |
274 | /* | |
275 | * Add an end-of-initial-update marker to the process queue. This is just a | |
276 | * queue element with NULL bgp node. | |
277 | */ | |
278 | extern void bgp_add_eoiu_mark (struct bgp *, bgp_table_t); | |
73ac8160 DS |
279 | extern int bgp_config_write_table_map (struct vty *, struct bgp *, afi_t, safi_t, |
280 | int *); | |
94f2b392 | 281 | extern int bgp_config_write_network (struct vty *, struct bgp *, afi_t, safi_t, int *); |
282 | extern int bgp_config_write_distance (struct vty *, struct bgp *); | |
283 | ||
284 | extern void bgp_aggregate_increment (struct bgp *, struct prefix *, struct bgp_info *, | |
718e3744 | 285 | afi_t, safi_t); |
94f2b392 | 286 | extern void bgp_aggregate_decrement (struct bgp *, struct prefix *, struct bgp_info *, |
718e3744 | 287 | afi_t, safi_t); |
288 | ||
94f2b392 | 289 | extern u_char bgp_distance_apply (struct prefix *, struct bgp_info *, struct bgp *); |
718e3744 | 290 | |
94f2b392 | 291 | extern afi_t bgp_node_afi (struct vty *); |
292 | extern safi_t bgp_node_safi (struct vty *); | |
5a646650 | 293 | |
b05a1c8b | 294 | extern void route_vty_out (struct vty *, struct prefix *, struct bgp_info *, int, safi_t, json_object *); |
94f2b392 | 295 | extern void route_vty_out_tag (struct vty *, struct prefix *, struct bgp_info *, int, safi_t); |
b05a1c8b | 296 | extern void route_vty_out_tmp (struct vty *, struct prefix *, struct attr *, safi_t); |
00d252cb | 297 | |
3f9c7369 DS |
298 | extern int |
299 | subgroup_process_announce_selected (struct update_subgroup *subgrp, | |
300 | struct bgp_info *selected, | |
301 | struct bgp_node *rn); | |
302 | ||
303 | extern int subgroup_announce_check(struct bgp_info *ri, | |
304 | struct update_subgroup *subgrp, | |
305 | struct prefix *p, struct attr *attr); | |
306 | ||
00d252cb | 307 | #endif /* _QUAGGA_BGP_ROUTE_H */ |