]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* BGP routing information |
2 | Copyright (C) 1996, 97, 98, 99 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 | ||
21 | #include <zebra.h> | |
22 | ||
856ca177 | 23 | #include "lib/json.h" |
718e3744 | 24 | #include "prefix.h" |
25 | #include "linklist.h" | |
26 | #include "memory.h" | |
27 | #include "command.h" | |
28 | #include "stream.h" | |
29 | #include "filter.h" | |
718e3744 | 30 | #include "log.h" |
31 | #include "routemap.h" | |
32 | #include "buffer.h" | |
33 | #include "sockunion.h" | |
34 | #include "plist.h" | |
35 | #include "thread.h" | |
200df115 | 36 | #include "workqueue.h" |
3f9c7369 | 37 | #include "queue.h" |
6e919709 | 38 | #include "memory.h" |
718e3744 | 39 | |
40 | #include "bgpd/bgpd.h" | |
41 | #include "bgpd/bgp_table.h" | |
42 | #include "bgpd/bgp_route.h" | |
43 | #include "bgpd/bgp_attr.h" | |
44 | #include "bgpd/bgp_debug.h" | |
45 | #include "bgpd/bgp_aspath.h" | |
46 | #include "bgpd/bgp_regex.h" | |
47 | #include "bgpd/bgp_community.h" | |
48 | #include "bgpd/bgp_ecommunity.h" | |
49 | #include "bgpd/bgp_clist.h" | |
50 | #include "bgpd/bgp_packet.h" | |
51 | #include "bgpd/bgp_filter.h" | |
52 | #include "bgpd/bgp_fsm.h" | |
53 | #include "bgpd/bgp_mplsvpn.h" | |
54 | #include "bgpd/bgp_nexthop.h" | |
55 | #include "bgpd/bgp_damp.h" | |
56 | #include "bgpd/bgp_advertise.h" | |
57 | #include "bgpd/bgp_zebra.h" | |
0a486e5f | 58 | #include "bgpd/bgp_vty.h" |
96450faf | 59 | #include "bgpd/bgp_mpath.h" |
fc9a856f | 60 | #include "bgpd/bgp_nht.h" |
3f9c7369 | 61 | #include "bgpd/bgp_updgrp.h" |
8386ac43 | 62 | #include "bgpd/bgp_vty.h" |
718e3744 | 63 | |
65efcfce | 64 | #if ENABLE_BGP_VNC |
f8b6f499 LB |
65 | #include "bgpd/rfapi/rfapi_backend.h" |
66 | #include "bgpd/rfapi/vnc_import_bgp.h" | |
67 | #include "bgpd/rfapi/vnc_export_bgp.h" | |
65efcfce LB |
68 | #endif |
69 | ||
718e3744 | 70 | /* Extern from bgp_dump.c */ |
dde72586 SH |
71 | extern const char *bgp_origin_str[]; |
72 | extern const char *bgp_origin_long_str[]; | |
6b0655a2 | 73 | |
4125bb67 | 74 | struct bgp_node * |
fee0f4c6 | 75 | bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p, |
718e3744 | 76 | struct prefix_rd *prd) |
77 | { | |
78 | struct bgp_node *rn; | |
79 | struct bgp_node *prn = NULL; | |
da5b30f6 PJ |
80 | |
81 | assert (table); | |
82 | if (!table) | |
83 | return NULL; | |
84 | ||
587ff0fd | 85 | if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) |
718e3744 | 86 | { |
fee0f4c6 | 87 | prn = bgp_node_get (table, (struct prefix *) prd); |
718e3744 | 88 | |
89 | if (prn->info == NULL) | |
64e580a7 | 90 | prn->info = bgp_table_init (afi, safi); |
718e3744 | 91 | else |
92 | bgp_unlock_node (prn); | |
93 | table = prn->info; | |
94 | } | |
718e3744 | 95 | |
96 | rn = bgp_node_get (table, p); | |
97 | ||
587ff0fd | 98 | if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) |
718e3744 | 99 | rn->prn = prn; |
100 | ||
101 | return rn; | |
102 | } | |
6b0655a2 | 103 | |
fb982c25 PJ |
104 | /* Allocate bgp_info_extra */ |
105 | static struct bgp_info_extra * | |
106 | bgp_info_extra_new (void) | |
107 | { | |
108 | struct bgp_info_extra *new; | |
109 | new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra)); | |
110 | return new; | |
111 | } | |
112 | ||
113 | static void | |
114 | bgp_info_extra_free (struct bgp_info_extra **extra) | |
115 | { | |
116 | if (extra && *extra) | |
117 | { | |
118 | if ((*extra)->damp_info) | |
119 | bgp_damp_info_free ((*extra)->damp_info, 0); | |
120 | ||
121 | (*extra)->damp_info = NULL; | |
122 | ||
123 | XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra); | |
124 | ||
125 | *extra = NULL; | |
126 | } | |
127 | } | |
128 | ||
129 | /* Get bgp_info extra information for the given bgp_info, lazy allocated | |
130 | * if required. | |
131 | */ | |
132 | struct bgp_info_extra * | |
133 | bgp_info_extra_get (struct bgp_info *ri) | |
134 | { | |
135 | if (!ri->extra) | |
136 | ri->extra = bgp_info_extra_new(); | |
137 | return ri->extra; | |
138 | } | |
139 | ||
65efcfce LB |
140 | /* Allocate new bgp info structure. */ |
141 | struct bgp_info * | |
142 | bgp_info_new (void) | |
143 | { | |
144 | return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info)); | |
145 | } | |
146 | ||
718e3744 | 147 | /* Free bgp route information. */ |
200df115 | 148 | static void |
718e3744 | 149 | bgp_info_free (struct bgp_info *binfo) |
150 | { | |
151 | if (binfo->attr) | |
f6f434b2 | 152 | bgp_attr_unintern (&binfo->attr); |
fb018d25 DS |
153 | |
154 | bgp_unlink_nexthop(binfo); | |
fb982c25 | 155 | bgp_info_extra_free (&binfo->extra); |
de8d5dff | 156 | bgp_info_mpath_free (&binfo->mpath); |
718e3744 | 157 | |
200df115 | 158 | peer_unlock (binfo->peer); /* bgp_info peer reference */ |
159 | ||
718e3744 | 160 | XFREE (MTYPE_BGP_ROUTE, binfo); |
161 | } | |
162 | ||
200df115 | 163 | struct bgp_info * |
164 | bgp_info_lock (struct bgp_info *binfo) | |
165 | { | |
166 | binfo->lock++; | |
167 | return binfo; | |
168 | } | |
169 | ||
170 | struct bgp_info * | |
171 | bgp_info_unlock (struct bgp_info *binfo) | |
172 | { | |
173 | assert (binfo && binfo->lock > 0); | |
174 | binfo->lock--; | |
175 | ||
176 | if (binfo->lock == 0) | |
177 | { | |
178 | #if 0 | |
179 | zlog_debug ("%s: unlocked and freeing", __func__); | |
180 | zlog_backtrace (LOG_DEBUG); | |
181 | #endif | |
182 | bgp_info_free (binfo); | |
183 | return NULL; | |
184 | } | |
185 | ||
186 | #if 0 | |
187 | if (binfo->lock == 1) | |
188 | { | |
189 | zlog_debug ("%s: unlocked to 1", __func__); | |
190 | zlog_backtrace (LOG_DEBUG); | |
191 | } | |
192 | #endif | |
193 | ||
194 | return binfo; | |
195 | } | |
196 | ||
718e3744 | 197 | void |
198 | bgp_info_add (struct bgp_node *rn, struct bgp_info *ri) | |
199 | { | |
200 | struct bgp_info *top; | |
201 | ||
202 | top = rn->info; | |
200df115 | 203 | |
718e3744 | 204 | ri->next = rn->info; |
205 | ri->prev = NULL; | |
206 | if (top) | |
207 | top->prev = ri; | |
208 | rn->info = ri; | |
200df115 | 209 | |
210 | bgp_info_lock (ri); | |
211 | bgp_lock_node (rn); | |
212 | peer_lock (ri->peer); /* bgp_info peer reference */ | |
718e3744 | 213 | } |
214 | ||
b40d939b | 215 | /* Do the actual removal of info from RIB, for use by bgp_process |
216 | completion callback *only* */ | |
217 | static void | |
218 | bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri) | |
718e3744 | 219 | { |
220 | if (ri->next) | |
221 | ri->next->prev = ri->prev; | |
222 | if (ri->prev) | |
223 | ri->prev->next = ri->next; | |
224 | else | |
225 | rn->info = ri->next; | |
200df115 | 226 | |
de8d5dff | 227 | bgp_info_mpath_dequeue (ri); |
200df115 | 228 | bgp_info_unlock (ri); |
229 | bgp_unlock_node (rn); | |
718e3744 | 230 | } |
231 | ||
b40d939b | 232 | void |
233 | bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri) | |
234 | { | |
1a392d46 PJ |
235 | bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED); |
236 | /* set of previous already took care of pcount */ | |
b40d939b | 237 | UNSET_FLAG (ri->flags, BGP_INFO_VALID); |
238 | } | |
239 | ||
8d45210e AS |
240 | /* undo the effects of a previous call to bgp_info_delete; typically |
241 | called when a route is deleted and then quickly re-added before the | |
242 | deletion has been processed */ | |
65efcfce | 243 | void |
8d45210e AS |
244 | bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri) |
245 | { | |
246 | bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED); | |
247 | /* unset of previous already took care of pcount */ | |
248 | SET_FLAG (ri->flags, BGP_INFO_VALID); | |
249 | } | |
250 | ||
1a392d46 PJ |
251 | /* Adjust pcount as required */ |
252 | static void | |
253 | bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri) | |
254 | { | |
67174041 AS |
255 | struct bgp_table *table; |
256 | ||
257 | assert (rn && bgp_node_table (rn)); | |
6f58544d PJ |
258 | assert (ri && ri->peer && ri->peer->bgp); |
259 | ||
67174041 AS |
260 | table = bgp_node_table (rn); |
261 | ||
2a3d5731 | 262 | if (ri->peer == ri->peer->bgp->peer_self) |
1a392d46 PJ |
263 | return; |
264 | ||
80e0ad24 | 265 | if (!BGP_INFO_COUNTABLE (ri) |
1a392d46 PJ |
266 | && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED)) |
267 | { | |
268 | ||
269 | UNSET_FLAG (ri->flags, BGP_INFO_COUNTED); | |
270 | ||
271 | /* slight hack, but more robust against errors. */ | |
67174041 AS |
272 | if (ri->peer->pcount[table->afi][table->safi]) |
273 | ri->peer->pcount[table->afi][table->safi]--; | |
1a392d46 PJ |
274 | else |
275 | { | |
276 | zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s", | |
277 | __func__, ri->peer->host); | |
278 | zlog_backtrace (LOG_WARNING); | |
279 | zlog_warn ("%s: Please report to Quagga bugzilla", __func__); | |
280 | } | |
281 | } | |
80e0ad24 | 282 | else if (BGP_INFO_COUNTABLE (ri) |
1a392d46 PJ |
283 | && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED)) |
284 | { | |
285 | SET_FLAG (ri->flags, BGP_INFO_COUNTED); | |
67174041 | 286 | ri->peer->pcount[table->afi][table->safi]++; |
1a392d46 PJ |
287 | } |
288 | } | |
289 | ||
290 | ||
291 | /* Set/unset bgp_info flags, adjusting any other state as needed. | |
292 | * This is here primarily to keep prefix-count in check. | |
293 | */ | |
294 | void | |
295 | bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag) | |
296 | { | |
297 | SET_FLAG (ri->flags, flag); | |
298 | ||
80e0ad24 DS |
299 | /* early bath if we know it's not a flag that changes countability state */ |
300 | if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED)) | |
1a392d46 PJ |
301 | return; |
302 | ||
303 | bgp_pcount_adjust (rn, ri); | |
304 | } | |
305 | ||
306 | void | |
307 | bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag) | |
308 | { | |
309 | UNSET_FLAG (ri->flags, flag); | |
310 | ||
80e0ad24 DS |
311 | /* early bath if we know it's not a flag that changes countability state */ |
312 | if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED)) | |
1a392d46 PJ |
313 | return; |
314 | ||
315 | bgp_pcount_adjust (rn, ri); | |
316 | } | |
317 | ||
718e3744 | 318 | /* Get MED value. If MED value is missing and "bgp bestpath |
319 | missing-as-worst" is specified, treat it as the worst value. */ | |
94f2b392 | 320 | static u_int32_t |
718e3744 | 321 | bgp_med_value (struct attr *attr, struct bgp *bgp) |
322 | { | |
323 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)) | |
324 | return attr->med; | |
325 | else | |
326 | { | |
327 | if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST)) | |
3b424979 | 328 | return BGP_MED_MAX; |
718e3744 | 329 | else |
330 | return 0; | |
331 | } | |
332 | } | |
333 | ||
2ec1e66f DW |
334 | void |
335 | bgp_info_path_with_addpath_rx_str (struct bgp_info *ri, char *buf) | |
336 | { | |
337 | if (ri->addpath_rx_id) | |
338 | sprintf(buf, "path %s (addpath rxid %d)", ri->peer->host, ri->addpath_rx_id); | |
339 | else | |
340 | sprintf(buf, "path %s", ri->peer->host); | |
341 | } | |
342 | ||
9fbdd100 | 343 | /* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1. */ |
94f2b392 | 344 | static int |
96450faf | 345 | bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist, |
9fbdd100 | 346 | int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg, int debug, |
65efcfce | 347 | const char *pfx_buf) |
718e3744 | 348 | { |
8ff56318 JBD |
349 | struct attr *newattr, *existattr; |
350 | struct attr_extra *newattre, *existattre; | |
351 | bgp_peer_sort_t new_sort; | |
352 | bgp_peer_sort_t exist_sort; | |
718e3744 | 353 | u_int32_t new_pref; |
354 | u_int32_t exist_pref; | |
355 | u_int32_t new_med; | |
356 | u_int32_t exist_med; | |
8ff56318 JBD |
357 | u_int32_t new_weight; |
358 | u_int32_t exist_weight; | |
359 | uint32_t newm, existm; | |
718e3744 | 360 | struct in_addr new_id; |
361 | struct in_addr exist_id; | |
362 | int new_cluster; | |
363 | int exist_cluster; | |
8ff56318 JBD |
364 | int internal_as_route; |
365 | int confed_as_route; | |
718e3744 | 366 | int ret; |
2ec1e66f DW |
367 | char new_buf[PATH_ADDPATH_STR_BUFFER]; |
368 | char exist_buf[PATH_ADDPATH_STR_BUFFER]; | |
96450faf JB |
369 | |
370 | *paths_eq = 0; | |
718e3744 | 371 | |
372 | /* 0. Null check. */ | |
373 | if (new == NULL) | |
9fbdd100 DS |
374 | { |
375 | if (debug) | |
376 | zlog_debug("%s: new is NULL", pfx_buf); | |
377 | return 0; | |
378 | } | |
379 | ||
2ec1e66f DW |
380 | if (debug) |
381 | bgp_info_path_with_addpath_rx_str (new, new_buf); | |
382 | ||
718e3744 | 383 | if (exist == NULL) |
9fbdd100 DS |
384 | { |
385 | if (debug) | |
2ec1e66f | 386 | zlog_debug("%s: %s is the initial bestpath", pfx_buf, new_buf); |
9fbdd100 DS |
387 | return 1; |
388 | } | |
718e3744 | 389 | |
2ec1e66f | 390 | if (debug) |
a6086ad4 | 391 | { |
392 | bgp_info_path_with_addpath_rx_str (exist, exist_buf); | |
393 | zlog_debug("%s: Comparing %s flags 0x%x with %s flags 0x%x", | |
394 | pfx_buf, new_buf, new->flags, exist_buf, exist->flags); | |
395 | } | |
2ec1e66f | 396 | |
8ff56318 JBD |
397 | newattr = new->attr; |
398 | existattr = exist->attr; | |
399 | newattre = newattr->extra; | |
400 | existattre = existattr->extra; | |
401 | ||
718e3744 | 402 | /* 1. Weight check. */ |
8ff56318 JBD |
403 | new_weight = exist_weight = 0; |
404 | ||
405 | if (newattre) | |
406 | new_weight = newattre->weight; | |
407 | if (existattre) | |
408 | exist_weight = existattre->weight; | |
409 | ||
fb982c25 | 410 | if (new_weight > exist_weight) |
9fbdd100 DS |
411 | { |
412 | if (debug) | |
2ec1e66f DW |
413 | zlog_debug("%s: %s wins over %s due to weight %d > %d", |
414 | pfx_buf, new_buf, exist_buf, new_weight, exist_weight); | |
9fbdd100 DS |
415 | return 1; |
416 | } | |
417 | ||
fb982c25 | 418 | if (new_weight < exist_weight) |
9fbdd100 DS |
419 | { |
420 | if (debug) | |
2ec1e66f DW |
421 | zlog_debug("%s: %s loses to %s due to weight %d < %d", |
422 | pfx_buf, new_buf, exist_buf, new_weight, exist_weight); | |
9fbdd100 DS |
423 | return 0; |
424 | } | |
718e3744 | 425 | |
426 | /* 2. Local preference check. */ | |
8ff56318 JBD |
427 | new_pref = exist_pref = bgp->default_local_pref; |
428 | ||
429 | if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)) | |
430 | new_pref = newattr->local_pref; | |
431 | if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)) | |
432 | exist_pref = existattr->local_pref; | |
718e3744 | 433 | |
718e3744 | 434 | if (new_pref > exist_pref) |
9fbdd100 DS |
435 | { |
436 | if (debug) | |
2ec1e66f DW |
437 | zlog_debug("%s: %s wins over %s due to localpref %d > %d", |
438 | pfx_buf, new_buf, exist_buf, new_pref, exist_pref); | |
9fbdd100 DS |
439 | return 1; |
440 | } | |
441 | ||
718e3744 | 442 | if (new_pref < exist_pref) |
9fbdd100 DS |
443 | { |
444 | if (debug) | |
2ec1e66f DW |
445 | zlog_debug("%s: %s loses to %s due to localpref %d < %d", |
446 | pfx_buf, new_buf, exist_buf, new_pref, exist_pref); | |
9fbdd100 DS |
447 | return 0; |
448 | } | |
718e3744 | 449 | |
8ff56318 JBD |
450 | /* 3. Local route check. We prefer: |
451 | * - BGP_ROUTE_STATIC | |
452 | * - BGP_ROUTE_AGGREGATE | |
453 | * - BGP_ROUTE_REDISTRIBUTE | |
454 | */ | |
455 | if (! (new->sub_type == BGP_ROUTE_NORMAL)) | |
9fbdd100 DS |
456 | { |
457 | if (debug) | |
2ec1e66f DW |
458 | zlog_debug("%s: %s wins over %s due to preferred BGP_ROUTE type", |
459 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
460 | return 1; |
461 | } | |
462 | ||
8ff56318 | 463 | if (! (exist->sub_type == BGP_ROUTE_NORMAL)) |
9fbdd100 DS |
464 | { |
465 | if (debug) | |
2ec1e66f DW |
466 | zlog_debug("%s: %s loses to %s due to preferred BGP_ROUTE type", |
467 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
468 | return 0; |
469 | } | |
718e3744 | 470 | |
471 | /* 4. AS path length check. */ | |
472 | if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE)) | |
473 | { | |
8ff56318 JBD |
474 | int exist_hops = aspath_count_hops (existattr->aspath); |
475 | int exist_confeds = aspath_count_confeds (existattr->aspath); | |
fe69a505 | 476 | |
6811845b | 477 | if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED)) |
478 | { | |
fe69a505 | 479 | int aspath_hops; |
480 | ||
8ff56318 JBD |
481 | aspath_hops = aspath_count_hops (newattr->aspath); |
482 | aspath_hops += aspath_count_confeds (newattr->aspath); | |
fe69a505 | 483 | |
484 | if ( aspath_hops < (exist_hops + exist_confeds)) | |
9fbdd100 DS |
485 | { |
486 | if (debug) | |
2ec1e66f DW |
487 | zlog_debug("%s: %s wins over %s due to aspath (with confeds) hopcount %d < %d", |
488 | pfx_buf, new_buf, exist_buf, | |
9fbdd100 DS |
489 | aspath_hops, (exist_hops + exist_confeds)); |
490 | return 1; | |
491 | } | |
492 | ||
fe69a505 | 493 | if ( aspath_hops > (exist_hops + exist_confeds)) |
9fbdd100 DS |
494 | { |
495 | if (debug) | |
2ec1e66f DW |
496 | zlog_debug("%s: %s loses to %s due to aspath (with confeds) hopcount %d > %d", |
497 | pfx_buf, new_buf, exist_buf, | |
9fbdd100 DS |
498 | aspath_hops, (exist_hops + exist_confeds)); |
499 | return 0; | |
500 | } | |
6811845b | 501 | } |
502 | else | |
503 | { | |
8ff56318 | 504 | int newhops = aspath_count_hops (newattr->aspath); |
fe69a505 | 505 | |
506 | if (newhops < exist_hops) | |
9fbdd100 DS |
507 | { |
508 | if (debug) | |
2ec1e66f DW |
509 | zlog_debug("%s: %s wins over %s due to aspath hopcount %d < %d", |
510 | pfx_buf, new_buf, exist_buf, newhops, exist_hops); | |
9fbdd100 DS |
511 | return 1; |
512 | } | |
513 | ||
fe69a505 | 514 | if (newhops > exist_hops) |
9fbdd100 DS |
515 | { |
516 | if (debug) | |
2ec1e66f DW |
517 | zlog_debug("%s: %s loses to %s due to aspath hopcount %d > %d", |
518 | pfx_buf, new_buf, exist_buf, newhops, exist_hops); | |
9fbdd100 DS |
519 | return 0; |
520 | } | |
6811845b | 521 | } |
718e3744 | 522 | } |
523 | ||
524 | /* 5. Origin check. */ | |
8ff56318 | 525 | if (newattr->origin < existattr->origin) |
9fbdd100 DS |
526 | { |
527 | if (debug) | |
2ec1e66f DW |
528 | zlog_debug("%s: %s wins over %s due to ORIGIN %s < %s", |
529 | pfx_buf, new_buf, exist_buf, | |
9fbdd100 DS |
530 | bgp_origin_long_str[newattr->origin], |
531 | bgp_origin_long_str[existattr->origin]); | |
532 | return 1; | |
533 | } | |
534 | ||
8ff56318 | 535 | if (newattr->origin > existattr->origin) |
9fbdd100 DS |
536 | { |
537 | if (debug) | |
2ec1e66f DW |
538 | zlog_debug("%s: %s loses to %s due to ORIGIN %s > %s", |
539 | pfx_buf, new_buf, exist_buf, | |
9fbdd100 DS |
540 | bgp_origin_long_str[newattr->origin], |
541 | bgp_origin_long_str[existattr->origin]); | |
542 | return 0; | |
543 | } | |
718e3744 | 544 | |
545 | /* 6. MED check. */ | |
8ff56318 JBD |
546 | internal_as_route = (aspath_count_hops (newattr->aspath) == 0 |
547 | && aspath_count_hops (existattr->aspath) == 0); | |
548 | confed_as_route = (aspath_count_confeds (newattr->aspath) > 0 | |
549 | && aspath_count_confeds (existattr->aspath) > 0 | |
550 | && aspath_count_hops (newattr->aspath) == 0 | |
551 | && aspath_count_hops (existattr->aspath) == 0); | |
718e3744 | 552 | |
553 | if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED) | |
554 | || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED) | |
555 | && confed_as_route) | |
8ff56318 JBD |
556 | || aspath_cmp_left (newattr->aspath, existattr->aspath) |
557 | || aspath_cmp_left_confed (newattr->aspath, existattr->aspath) | |
718e3744 | 558 | || internal_as_route) |
559 | { | |
560 | new_med = bgp_med_value (new->attr, bgp); | |
561 | exist_med = bgp_med_value (exist->attr, bgp); | |
562 | ||
563 | if (new_med < exist_med) | |
9fbdd100 DS |
564 | { |
565 | if (debug) | |
2ec1e66f DW |
566 | zlog_debug("%s: %s wins over %s due to MED %d < %d", |
567 | pfx_buf, new_buf, exist_buf, new_med, exist_med); | |
9fbdd100 DS |
568 | return 1; |
569 | } | |
570 | ||
718e3744 | 571 | if (new_med > exist_med) |
9fbdd100 DS |
572 | { |
573 | if (debug) | |
2ec1e66f DW |
574 | zlog_debug("%s: %s loses to %s due to MED %d > %d", |
575 | pfx_buf, new_buf, exist_buf, new_med, exist_med); | |
9fbdd100 DS |
576 | return 0; |
577 | } | |
718e3744 | 578 | } |
579 | ||
580 | /* 7. Peer type check. */ | |
8ff56318 JBD |
581 | new_sort = new->peer->sort; |
582 | exist_sort = exist->peer->sort; | |
583 | ||
584 | if (new_sort == BGP_PEER_EBGP | |
585 | && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED)) | |
9fbdd100 DS |
586 | { |
587 | if (debug) | |
2ec1e66f DW |
588 | zlog_debug("%s: %s wins over %s due to eBGP peer > iBGP peer", |
589 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
590 | return 1; |
591 | } | |
592 | ||
8ff56318 JBD |
593 | if (exist_sort == BGP_PEER_EBGP |
594 | && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED)) | |
9fbdd100 DS |
595 | { |
596 | if (debug) | |
2ec1e66f DW |
597 | zlog_debug("%s: %s loses to %s due to iBGP peer < eBGP peer", |
598 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
599 | return 0; |
600 | } | |
718e3744 | 601 | |
602 | /* 8. IGP metric check. */ | |
8ff56318 JBD |
603 | newm = existm = 0; |
604 | ||
605 | if (new->extra) | |
606 | newm = new->extra->igpmetric; | |
607 | if (exist->extra) | |
608 | existm = exist->extra->igpmetric; | |
609 | ||
96450faf | 610 | if (newm < existm) |
9fbdd100 DS |
611 | { |
612 | if (debug) | |
2ec1e66f DW |
613 | zlog_debug("%s: %s wins over %s due to IGP metric %d < %d", |
614 | pfx_buf, new_buf, exist_buf, newm, existm); | |
9fbdd100 DS |
615 | ret = 1; |
616 | } | |
617 | ||
96450faf | 618 | if (newm > existm) |
9fbdd100 DS |
619 | { |
620 | if (debug) | |
2ec1e66f DW |
621 | zlog_debug("%s: %s loses to %s due to IGP metric %d > %d", |
622 | pfx_buf, new_buf, exist_buf, newm, existm); | |
9fbdd100 DS |
623 | ret = 0; |
624 | } | |
718e3744 | 625 | |
31a4638f | 626 | /* 9. Same IGP metric. Compare the cluster list length as |
5e242b0d DS |
627 | representative of IGP hops metric. Rewrite the metric value |
628 | pair (newm, existm) with the cluster list length. Prefer the | |
629 | path with smaller cluster list length. */ | |
630 | if (newm == existm) | |
631 | { | |
632 | if (peer_sort (new->peer) == BGP_PEER_IBGP | |
633 | && peer_sort (exist->peer) == BGP_PEER_IBGP | |
53a7a065 LB |
634 | && (mpath_cfg == NULL || |
635 | CHECK_FLAG (mpath_cfg->ibgp_flags, | |
636 | BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))) | |
5e242b0d DS |
637 | { |
638 | newm = BGP_CLUSTER_LIST_LENGTH(new->attr); | |
639 | existm = BGP_CLUSTER_LIST_LENGTH(exist->attr); | |
9fbdd100 | 640 | |
5e242b0d | 641 | if (newm < existm) |
9fbdd100 DS |
642 | { |
643 | if (debug) | |
2ec1e66f DW |
644 | zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d", |
645 | pfx_buf, new_buf, exist_buf, newm, existm); | |
9fbdd100 DS |
646 | ret = 1; |
647 | } | |
648 | ||
5e242b0d | 649 | if (newm > existm) |
9fbdd100 DS |
650 | { |
651 | if (debug) | |
2ec1e66f DW |
652 | zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d", |
653 | pfx_buf, new_buf, exist_buf, newm, existm); | |
9fbdd100 DS |
654 | ret = 0; |
655 | } | |
5e242b0d DS |
656 | } |
657 | } | |
658 | ||
31a4638f DS |
659 | /* 10. confed-external vs. confed-internal */ |
660 | if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)) | |
661 | { | |
662 | if (new_sort == BGP_PEER_CONFED && exist_sort == BGP_PEER_IBGP) | |
663 | { | |
664 | if (debug) | |
2ec1e66f DW |
665 | zlog_debug("%s: %s wins over %s due to confed-external peer > confed-internal peer", |
666 | pfx_buf, new_buf, exist_buf); | |
31a4638f DS |
667 | return 1; |
668 | } | |
669 | ||
670 | if (exist_sort == BGP_PEER_CONFED && new_sort == BGP_PEER_IBGP) | |
671 | { | |
672 | if (debug) | |
2ec1e66f DW |
673 | zlog_debug("%s: %s loses to %s due to confed-internal peer < confed-external peer", |
674 | pfx_buf, new_buf, exist_buf); | |
31a4638f DS |
675 | return 0; |
676 | } | |
677 | } | |
678 | ||
679 | /* 11. Maximum path check. */ | |
96450faf JB |
680 | if (newm == existm) |
681 | { | |
2fdd455c PM |
682 | if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) |
683 | { | |
684 | ||
685 | /* | |
686 | * For the two paths, all comparison steps till IGP metric | |
687 | * have succeeded - including AS_PATH hop count. Since 'bgp | |
688 | * bestpath as-path multipath-relax' knob is on, we don't need | |
689 | * an exact match of AS_PATH. Thus, mark the paths are equal. | |
690 | * That will trigger both these paths to get into the multipath | |
691 | * array. | |
692 | */ | |
693 | *paths_eq = 1; | |
9fbdd100 DS |
694 | |
695 | if (debug) | |
2ec1e66f DW |
696 | zlog_debug("%s: %s and %s are equal via multipath-relax", |
697 | pfx_buf, new_buf, exist_buf); | |
2fdd455c PM |
698 | } |
699 | else if (new->peer->sort == BGP_PEER_IBGP) | |
96450faf JB |
700 | { |
701 | if (aspath_cmp (new->attr->aspath, exist->attr->aspath)) | |
9fbdd100 DS |
702 | { |
703 | *paths_eq = 1; | |
704 | ||
705 | if (debug) | |
2ec1e66f DW |
706 | zlog_debug("%s: %s and %s are equal via matching aspaths", |
707 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 | 708 | } |
96450faf JB |
709 | } |
710 | else if (new->peer->as == exist->peer->as) | |
9fbdd100 DS |
711 | { |
712 | *paths_eq = 1; | |
713 | ||
714 | if (debug) | |
2ec1e66f DW |
715 | zlog_debug("%s: %s and %s are equal via same remote-as", |
716 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 | 717 | } |
96450faf JB |
718 | } |
719 | else | |
720 | { | |
721 | /* | |
722 | * TODO: If unequal cost ibgp multipath is enabled we can | |
723 | * mark the paths as equal here instead of returning | |
724 | */ | |
a6086ad4 | 725 | if (debug) |
726 | { | |
727 | if (ret == 1) | |
728 | zlog_debug("%s: %s wins over %s after IGP metric comparison", | |
729 | pfx_buf, new_buf, exist_buf); | |
730 | else | |
731 | zlog_debug("%s: %s loses to %s after IGP metric comparison", | |
732 | pfx_buf, new_buf, exist_buf); | |
733 | } | |
96450faf JB |
734 | return ret; |
735 | } | |
718e3744 | 736 | |
31a4638f | 737 | /* 12. If both paths are external, prefer the path that was received |
718e3744 | 738 | first (the oldest one). This step minimizes route-flap, since a |
739 | newer path won't displace an older one, even if it was the | |
740 | preferred route based on the additional decision criteria below. */ | |
741 | if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID) | |
8ff56318 JBD |
742 | && new_sort == BGP_PEER_EBGP |
743 | && exist_sort == BGP_PEER_EBGP) | |
718e3744 | 744 | { |
745 | if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED)) | |
9fbdd100 DS |
746 | { |
747 | if (debug) | |
2ec1e66f DW |
748 | zlog_debug("%s: %s wins over %s due to oldest external", |
749 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
750 | return 1; |
751 | } | |
752 | ||
718e3744 | 753 | if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED)) |
9fbdd100 DS |
754 | { |
755 | if (debug) | |
2ec1e66f DW |
756 | zlog_debug("%s: %s loses to %s due to oldest external", |
757 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
758 | return 0; |
759 | } | |
718e3744 | 760 | } |
761 | ||
31a4638f | 762 | /* 13. Router-ID comparision. */ |
0de5153c DS |
763 | /* If one of the paths is "stale", the corresponding peer router-id will |
764 | * be 0 and would always win over the other path. If originator id is | |
765 | * used for the comparision, it will decide which path is better. | |
766 | */ | |
8ff56318 JBD |
767 | if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) |
768 | new_id.s_addr = newattre->originator_id.s_addr; | |
718e3744 | 769 | else |
770 | new_id.s_addr = new->peer->remote_id.s_addr; | |
8ff56318 JBD |
771 | if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) |
772 | exist_id.s_addr = existattre->originator_id.s_addr; | |
718e3744 | 773 | else |
774 | exist_id.s_addr = exist->peer->remote_id.s_addr; | |
775 | ||
776 | if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr)) | |
9fbdd100 DS |
777 | { |
778 | if (debug) | |
2ec1e66f DW |
779 | zlog_debug("%s: %s wins over %s due to Router-ID comparison", |
780 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
781 | return 1; |
782 | } | |
783 | ||
718e3744 | 784 | if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr)) |
9fbdd100 DS |
785 | { |
786 | if (debug) | |
2ec1e66f DW |
787 | zlog_debug("%s: %s loses to %s due to Router-ID comparison", |
788 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
789 | return 0; |
790 | } | |
718e3744 | 791 | |
31a4638f | 792 | /* 14. Cluster length comparision. */ |
5e242b0d DS |
793 | new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr); |
794 | exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr); | |
718e3744 | 795 | |
796 | if (new_cluster < exist_cluster) | |
9fbdd100 DS |
797 | { |
798 | if (debug) | |
2ec1e66f DW |
799 | zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d", |
800 | pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster); | |
9fbdd100 DS |
801 | return 1; |
802 | } | |
803 | ||
718e3744 | 804 | if (new_cluster > exist_cluster) |
9fbdd100 DS |
805 | { |
806 | if (debug) | |
2ec1e66f DW |
807 | zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d", |
808 | pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster); | |
9fbdd100 DS |
809 | return 0; |
810 | } | |
718e3744 | 811 | |
31a4638f | 812 | /* 15. Neighbor address comparision. */ |
0de5153c DS |
813 | /* Do this only if neither path is "stale" as stale paths do not have |
814 | * valid peer information (as the connection may or may not be up). | |
815 | */ | |
816 | if (CHECK_FLAG (exist->flags, BGP_INFO_STALE)) | |
9fbdd100 DS |
817 | { |
818 | if (debug) | |
2ec1e66f DW |
819 | zlog_debug("%s: %s wins over %s due to latter path being STALE", |
820 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
821 | return 1; |
822 | } | |
823 | ||
0de5153c | 824 | if (CHECK_FLAG (new->flags, BGP_INFO_STALE)) |
9fbdd100 DS |
825 | { |
826 | if (debug) | |
2ec1e66f DW |
827 | zlog_debug("%s: %s loses to %s due to former path being STALE", |
828 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
829 | return 0; |
830 | } | |
0de5153c | 831 | |
43ed4fe5 TT |
832 | /* locally configured routes to advertise do not have su_remote */ |
833 | if (new->peer->su_remote == NULL) | |
834 | return 0; | |
835 | if (exist->peer->su_remote == NULL) | |
836 | return 1; | |
837 | ||
718e3744 | 838 | ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote); |
839 | ||
840 | if (ret == 1) | |
9fbdd100 DS |
841 | { |
842 | if (debug) | |
2ec1e66f DW |
843 | zlog_debug("%s: %s loses to %s due to Neighor IP comparison", |
844 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
845 | return 0; |
846 | } | |
847 | ||
718e3744 | 848 | if (ret == -1) |
9fbdd100 DS |
849 | { |
850 | if (debug) | |
2ec1e66f DW |
851 | zlog_debug("%s: %s wins over %s due to Neighor IP comparison", |
852 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
853 | return 1; |
854 | } | |
855 | ||
856 | if (debug) | |
2ec1e66f DW |
857 | zlog_debug("%s: %s wins over %s due to nothing left to compare", |
858 | pfx_buf, new_buf, exist_buf); | |
718e3744 | 859 | |
860 | return 1; | |
861 | } | |
862 | ||
65efcfce LB |
863 | /* Compare two bgp route entity. Return -1 if new is preferred, 1 if exist |
864 | * is preferred, or 0 if they are the same (usually will only occur if | |
865 | * multipath is enabled | |
866 | * This version is compatible with */ | |
867 | int | |
868 | bgp_info_cmp_compatible (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist, | |
869 | afi_t afi, safi_t safi) | |
870 | { | |
871 | int paths_eq; | |
65efcfce | 872 | int ret; |
53a7a065 | 873 | ret = bgp_info_cmp (bgp, new, exist, &paths_eq, NULL, 0, __func__); |
65efcfce LB |
874 | |
875 | if (paths_eq) | |
876 | ret = 0; | |
877 | else | |
878 | { | |
879 | if (ret == 1) | |
880 | ret = -1; | |
881 | else | |
882 | ret = 1; | |
883 | } | |
884 | return ret; | |
885 | } | |
886 | ||
94f2b392 | 887 | static enum filter_type |
718e3744 | 888 | bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr, |
889 | afi_t afi, safi_t safi) | |
890 | { | |
891 | struct bgp_filter *filter; | |
892 | ||
893 | filter = &peer->filter[afi][safi]; | |
894 | ||
650f76c2 PJ |
895 | #define FILTER_EXIST_WARN(F,f,filter) \ |
896 | if (BGP_DEBUG (update, UPDATE_IN) \ | |
897 | && !(F ## _IN (filter))) \ | |
16286195 | 898 | zlog_warn ("%s: Could not find configured input %s-list %s!", \ |
650f76c2 PJ |
899 | peer->host, #f, F ## _IN_NAME(filter)); |
900 | ||
901 | if (DISTRIBUTE_IN_NAME (filter)) { | |
902 | FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter); | |
903 | ||
718e3744 | 904 | if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY) |
905 | return FILTER_DENY; | |
650f76c2 | 906 | } |
718e3744 | 907 | |
650f76c2 PJ |
908 | if (PREFIX_LIST_IN_NAME (filter)) { |
909 | FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter); | |
910 | ||
718e3744 | 911 | if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY) |
912 | return FILTER_DENY; | |
650f76c2 | 913 | } |
718e3744 | 914 | |
650f76c2 PJ |
915 | if (FILTER_LIST_IN_NAME (filter)) { |
916 | FILTER_EXIST_WARN(FILTER_LIST, as, filter); | |
917 | ||
718e3744 | 918 | if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY) |
919 | return FILTER_DENY; | |
650f76c2 PJ |
920 | } |
921 | ||
718e3744 | 922 | return FILTER_PERMIT; |
650f76c2 | 923 | #undef FILTER_EXIST_WARN |
718e3744 | 924 | } |
925 | ||
94f2b392 | 926 | static enum filter_type |
718e3744 | 927 | bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr, |
928 | afi_t afi, safi_t safi) | |
929 | { | |
930 | struct bgp_filter *filter; | |
931 | ||
932 | filter = &peer->filter[afi][safi]; | |
933 | ||
650f76c2 PJ |
934 | #define FILTER_EXIST_WARN(F,f,filter) \ |
935 | if (BGP_DEBUG (update, UPDATE_OUT) \ | |
936 | && !(F ## _OUT (filter))) \ | |
16286195 | 937 | zlog_warn ("%s: Could not find configured output %s-list %s!", \ |
650f76c2 PJ |
938 | peer->host, #f, F ## _OUT_NAME(filter)); |
939 | ||
940 | if (DISTRIBUTE_OUT_NAME (filter)) { | |
941 | FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter); | |
942 | ||
718e3744 | 943 | if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY) |
944 | return FILTER_DENY; | |
650f76c2 | 945 | } |
718e3744 | 946 | |
650f76c2 PJ |
947 | if (PREFIX_LIST_OUT_NAME (filter)) { |
948 | FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter); | |
949 | ||
718e3744 | 950 | if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY) |
951 | return FILTER_DENY; | |
650f76c2 | 952 | } |
718e3744 | 953 | |
650f76c2 PJ |
954 | if (FILTER_LIST_OUT_NAME (filter)) { |
955 | FILTER_EXIST_WARN(FILTER_LIST, as, filter); | |
956 | ||
718e3744 | 957 | if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY) |
958 | return FILTER_DENY; | |
650f76c2 | 959 | } |
718e3744 | 960 | |
961 | return FILTER_PERMIT; | |
650f76c2 | 962 | #undef FILTER_EXIST_WARN |
718e3744 | 963 | } |
964 | ||
965 | /* If community attribute includes no_export then return 1. */ | |
94f2b392 | 966 | static int |
718e3744 | 967 | bgp_community_filter (struct peer *peer, struct attr *attr) |
968 | { | |
969 | if (attr->community) | |
970 | { | |
971 | /* NO_ADVERTISE check. */ | |
972 | if (community_include (attr->community, COMMUNITY_NO_ADVERTISE)) | |
973 | return 1; | |
974 | ||
975 | /* NO_EXPORT check. */ | |
6d85b15b | 976 | if (peer->sort == BGP_PEER_EBGP && |
718e3744 | 977 | community_include (attr->community, COMMUNITY_NO_EXPORT)) |
978 | return 1; | |
979 | ||
980 | /* NO_EXPORT_SUBCONFED check. */ | |
6d85b15b JBD |
981 | if (peer->sort == BGP_PEER_EBGP |
982 | || peer->sort == BGP_PEER_CONFED) | |
718e3744 | 983 | if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED)) |
984 | return 1; | |
985 | } | |
986 | return 0; | |
987 | } | |
988 | ||
989 | /* Route reflection loop check. */ | |
990 | static int | |
991 | bgp_cluster_filter (struct peer *peer, struct attr *attr) | |
992 | { | |
993 | struct in_addr cluster_id; | |
994 | ||
fb982c25 | 995 | if (attr->extra && attr->extra->cluster) |
718e3744 | 996 | { |
997 | if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID) | |
998 | cluster_id = peer->bgp->cluster_id; | |
999 | else | |
1000 | cluster_id = peer->bgp->router_id; | |
1001 | ||
fb982c25 | 1002 | if (cluster_loop_check (attr->extra->cluster, cluster_id)) |
718e3744 | 1003 | return 1; |
1004 | } | |
1005 | return 0; | |
1006 | } | |
6b0655a2 | 1007 | |
94f2b392 | 1008 | static int |
718e3744 | 1009 | bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr, |
ffd0c037 | 1010 | afi_t afi, safi_t safi, const char *rmap_name) |
718e3744 | 1011 | { |
1012 | struct bgp_filter *filter; | |
1013 | struct bgp_info info; | |
1014 | route_map_result_t ret; | |
0b16f239 | 1015 | struct route_map *rmap = NULL; |
718e3744 | 1016 | |
1017 | filter = &peer->filter[afi][safi]; | |
1018 | ||
1019 | /* Apply default weight value. */ | |
d93f7ffc DW |
1020 | if (peer->weight[afi][safi]) |
1021 | (bgp_attr_extra_get (attr))->weight = peer->weight[afi][safi]; | |
718e3744 | 1022 | |
0b16f239 DS |
1023 | if (rmap_name) |
1024 | { | |
1025 | rmap = route_map_lookup_by_name(rmap_name); | |
98a4a44e DS |
1026 | |
1027 | if (rmap == NULL) | |
1028 | return RMAP_DENY; | |
0b16f239 DS |
1029 | } |
1030 | else | |
1031 | { | |
1032 | if (ROUTE_MAP_IN_NAME(filter)) | |
98a4a44e DS |
1033 | { |
1034 | rmap = ROUTE_MAP_IN (filter); | |
1035 | ||
1036 | if (rmap == NULL) | |
1037 | return RMAP_DENY; | |
1038 | } | |
0b16f239 DS |
1039 | } |
1040 | ||
718e3744 | 1041 | /* Route map apply. */ |
0b16f239 | 1042 | if (rmap) |
718e3744 | 1043 | { |
1044 | /* Duplicate current value to new strucutre for modification. */ | |
1045 | info.peer = peer; | |
1046 | info.attr = attr; | |
1047 | ||
ac41b2a2 | 1048 | SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN); |
1049 | ||
718e3744 | 1050 | /* Apply BGP route map to the attribute. */ |
0b16f239 DS |
1051 | ret = route_map_apply (rmap, p, RMAP_BGP, &info); |
1052 | ||
1053 | peer->rmap_type = 0; | |
1054 | ||
1055 | if (ret == RMAP_DENYMATCH) | |
1056 | { | |
1057 | /* Free newly generated AS path and community by route-map. */ | |
1058 | bgp_attr_flush (attr); | |
1059 | return RMAP_DENY; | |
1060 | } | |
1061 | } | |
1062 | return RMAP_PERMIT; | |
1063 | } | |
1064 | ||
1065 | static int | |
1066 | bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr, | |
ffd0c037 | 1067 | afi_t afi, safi_t safi, const char *rmap_name) |
0b16f239 DS |
1068 | { |
1069 | struct bgp_filter *filter; | |
1070 | struct bgp_info info; | |
1071 | route_map_result_t ret; | |
1072 | struct route_map *rmap = NULL; | |
1073 | ||
1074 | filter = &peer->filter[afi][safi]; | |
1075 | ||
1076 | /* Apply default weight value. */ | |
d93f7ffc DW |
1077 | if (peer->weight[afi][safi]) |
1078 | (bgp_attr_extra_get (attr))->weight = peer->weight[afi][safi]; | |
0b16f239 DS |
1079 | |
1080 | if (rmap_name) | |
1081 | { | |
1082 | rmap = route_map_lookup_by_name(rmap_name); | |
98a4a44e DS |
1083 | |
1084 | if (rmap == NULL) | |
1085 | return RMAP_DENY; | |
0b16f239 DS |
1086 | } |
1087 | else | |
1088 | { | |
1089 | if (ROUTE_MAP_OUT_NAME(filter)) | |
98a4a44e DS |
1090 | { |
1091 | rmap = ROUTE_MAP_OUT (filter); | |
1092 | ||
1093 | if (rmap == NULL) | |
1094 | return RMAP_DENY; | |
1095 | } | |
0b16f239 DS |
1096 | } |
1097 | ||
1098 | /* Route map apply. */ | |
1099 | if (rmap) | |
1100 | { | |
1101 | /* Duplicate current value to new strucutre for modification. */ | |
1102 | info.peer = peer; | |
1103 | info.attr = attr; | |
1104 | ||
1105 | SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT); | |
1106 | ||
1107 | /* Apply BGP route map to the attribute. */ | |
1108 | ret = route_map_apply (rmap, p, RMAP_BGP, &info); | |
ac41b2a2 | 1109 | |
1110 | peer->rmap_type = 0; | |
1111 | ||
718e3744 | 1112 | if (ret == RMAP_DENYMATCH) |
c460e572 DL |
1113 | /* caller has multiple error paths with bgp_attr_flush() */ |
1114 | return RMAP_DENY; | |
718e3744 | 1115 | } |
1116 | return RMAP_PERMIT; | |
1117 | } | |
6b0655a2 | 1118 | |
5000f21c | 1119 | /* If this is an EBGP peer with remove-private-AS */ |
ffd0c037 | 1120 | static void |
5000f21c DS |
1121 | bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi, |
1122 | struct peer *peer, struct attr *attr) | |
1123 | { | |
1124 | if (peer->sort == BGP_PEER_EBGP && | |
88b8ed8d DW |
1125 | (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) || |
1126 | peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE) || | |
1127 | peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL) || | |
1128 | peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS))) | |
5000f21c DS |
1129 | { |
1130 | // Take action on the entire aspath | |
88b8ed8d DW |
1131 | if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) || |
1132 | peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) | |
5000f21c | 1133 | { |
88b8ed8d | 1134 | if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) |
5000f21c DS |
1135 | attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as); |
1136 | ||
1137 | // The entire aspath consists of private ASNs so create an empty aspath | |
1138 | else if (aspath_private_as_check (attr->aspath)) | |
1139 | attr->aspath = aspath_empty_get (); | |
1140 | ||
1141 | // There are some public and some private ASNs, remove the private ASNs | |
1142 | else | |
1143 | attr->aspath = aspath_remove_private_asns (attr->aspath); | |
1144 | } | |
1145 | ||
1146 | // 'all' was not specified so the entire aspath must be private ASNs | |
1147 | // for us to do anything | |
1148 | else if (aspath_private_as_check (attr->aspath)) | |
1149 | { | |
1150 | if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) | |
1151 | attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as); | |
1152 | else | |
1153 | attr->aspath = aspath_empty_get (); | |
1154 | } | |
1155 | } | |
1156 | } | |
1157 | ||
c7122e14 DS |
1158 | /* If this is an EBGP peer with as-override */ |
1159 | static void | |
1160 | bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi, | |
1161 | struct peer *peer, struct attr *attr) | |
1162 | { | |
1163 | if (peer->sort == BGP_PEER_EBGP && | |
1164 | peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) | |
1165 | { | |
1166 | if (aspath_single_asn_check (attr->aspath, peer->as)) | |
1167 | attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as); | |
1168 | } | |
1169 | } | |
1170 | ||
3f9c7369 DS |
1171 | static void |
1172 | subgroup_announce_reset_nhop (u_char family, struct attr *attr) | |
1173 | { | |
1174 | if (family == AF_INET) | |
1175 | attr->nexthop.s_addr = 0; | |
1176 | #ifdef HAVE_IPV6 | |
1177 | if (family == AF_INET6) | |
1178 | memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN); | |
1179 | #endif | |
1180 | } | |
1181 | ||
1182 | int | |
1183 | subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp, | |
1184 | struct prefix *p, struct attr *attr) | |
1185 | { | |
1186 | struct bgp_filter *filter; | |
1187 | struct peer *from; | |
1188 | struct peer *peer; | |
1189 | struct peer *onlypeer; | |
1190 | struct bgp *bgp; | |
1191 | struct attr *riattr; | |
1192 | struct peer_af *paf; | |
1193 | char buf[SU_ADDRSTRLEN]; | |
1194 | int ret; | |
1195 | int transparent; | |
1196 | int reflect; | |
1197 | afi_t afi; | |
1198 | safi_t safi; | |
65efcfce | 1199 | int samepeer_safe = 0; /* for synthetic mplsvpns routes */ |
3f9c7369 DS |
1200 | |
1201 | if (DISABLE_BGP_ANNOUNCE) | |
1202 | return 0; | |
1203 | ||
1204 | afi = SUBGRP_AFI(subgrp); | |
1205 | safi = SUBGRP_SAFI(subgrp); | |
1206 | peer = SUBGRP_PEER(subgrp); | |
1207 | onlypeer = NULL; | |
1208 | if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL)) | |
1209 | onlypeer = SUBGRP_PFIRST(subgrp)->peer; | |
1210 | ||
1211 | from = ri->peer; | |
1212 | filter = &peer->filter[afi][safi]; | |
1213 | bgp = SUBGRP_INST(subgrp); | |
1214 | riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr; | |
1215 | ||
65efcfce LB |
1216 | #if ENABLE_BGP_VNC |
1217 | if (((afi == AFI_IP) || (afi == AFI_IP6)) && (safi == SAFI_MPLS_VPN) && | |
1218 | ((ri->type == ZEBRA_ROUTE_BGP_DIRECT) || | |
1219 | (ri->type == ZEBRA_ROUTE_BGP_DIRECT_EXT))) { | |
1220 | ||
1221 | /* | |
1222 | * direct and direct_ext type routes originate internally even | |
1223 | * though they can have peer pointers that reference other systems | |
1224 | */ | |
1225 | char buf[BUFSIZ]; | |
1226 | prefix2str(p, buf, BUFSIZ); | |
1227 | zlog_debug("%s: pfx %s bgp_direct->vpn route peer safe", __func__, buf); | |
1228 | samepeer_safe = 1; | |
1229 | } | |
1230 | #endif | |
1231 | ||
adbac85e DW |
1232 | /* With addpath we may be asked to TX all kinds of paths so make sure |
1233 | * ri is valid */ | |
1234 | if (!CHECK_FLAG (ri->flags, BGP_INFO_VALID) || | |
1235 | CHECK_FLAG (ri->flags, BGP_INFO_HISTORY) || | |
1236 | CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)) | |
1237 | { | |
1238 | return 0; | |
1239 | } | |
1240 | ||
06370dac DW |
1241 | /* If this is not the bestpath then check to see if there is an enabled addpath |
1242 | * feature that requires us to advertise it */ | |
1243 | if (! CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) | |
1244 | { | |
1245 | if (! bgp_addpath_tx_path(peer, afi, safi, ri)) | |
1246 | { | |
1247 | return 0; | |
1248 | } | |
1249 | } | |
1250 | ||
3f9c7369 DS |
1251 | /* Aggregate-address suppress check. */ |
1252 | if (ri->extra && ri->extra->suppress) | |
1253 | if (! UNSUPPRESS_MAP_NAME (filter)) | |
1254 | { | |
1255 | return 0; | |
1256 | } | |
1257 | ||
3f9c7369 DS |
1258 | /* Do not send back route to sender. */ |
1259 | if (onlypeer && from == onlypeer) | |
1260 | { | |
1261 | return 0; | |
1262 | } | |
1263 | ||
4125bb67 DS |
1264 | /* Do not send the default route in the BGP table if the neighbor is |
1265 | * configured for default-originate */ | |
1266 | if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE)) | |
1267 | { | |
1268 | if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY) | |
1269 | return 0; | |
1270 | #ifdef HAVE_IPV6 | |
1271 | else if (p->family == AF_INET6 && p->prefixlen == 0) | |
1272 | return 0; | |
1273 | #endif /* HAVE_IPV6 */ | |
1274 | } | |
1275 | ||
3f9c7369 DS |
1276 | /* Transparency check. */ |
1277 | if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) | |
1278 | && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)) | |
1279 | transparent = 1; | |
1280 | else | |
1281 | transparent = 0; | |
1282 | ||
1283 | /* If community is not disabled check the no-export and local. */ | |
1284 | if (! transparent && bgp_community_filter (peer, riattr)) | |
1285 | { | |
1286 | if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) | |
1287 | zlog_debug ("subgrpannouncecheck: community filter check fail"); | |
1288 | return 0; | |
1289 | } | |
1290 | ||
1291 | /* If the attribute has originator-id and it is same as remote | |
1292 | peer's id. */ | |
1293 | if (onlypeer && | |
1294 | riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) && | |
1295 | (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id))) | |
1296 | { | |
1297 | if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) | |
1298 | zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as " | |
1299 | "remote router-id", | |
1300 | onlypeer->host, | |
1301 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
1302 | p->prefixlen); | |
1303 | return 0; | |
1304 | } | |
1305 | ||
1306 | /* ORF prefix-list filter check */ | |
1307 | if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV) | |
1308 | && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV) | |
1309 | || CHECK_FLAG (peer->af_cap[afi][safi], | |
1310 | PEER_CAP_ORF_PREFIX_SM_OLD_RCV))) | |
1311 | if (peer->orf_plist[afi][safi]) | |
1312 | { | |
1313 | if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY) | |
1314 | { | |
40d2700d DW |
1315 | if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) |
1316 | zlog_debug ("%s [Update:SEND] %s/%d is filtered via ORF", | |
1317 | peer->host, | |
1318 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
1319 | p->prefixlen); | |
3f9c7369 DS |
1320 | return 0; |
1321 | } | |
1322 | } | |
1323 | ||
1324 | /* Output filter check. */ | |
1325 | if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY) | |
1326 | { | |
1327 | if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) | |
1328 | zlog_debug ("%s [Update:SEND] %s/%d is filtered", | |
1329 | peer->host, | |
1330 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
1331 | p->prefixlen); | |
1332 | return 0; | |
1333 | } | |
1334 | ||
1335 | #ifdef BGP_SEND_ASPATH_CHECK | |
1336 | /* AS path loop check. */ | |
1337 | if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as)) | |
1338 | { | |
1339 | if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) | |
1340 | zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u " | |
1341 | "that is part of AS path.", | |
1342 | onlypeer->host, onlypeer->as); | |
1343 | return 0; | |
1344 | } | |
1345 | #endif /* BGP_SEND_ASPATH_CHECK */ | |
1346 | ||
1347 | /* If we're a CONFED we need to loop check the CONFED ID too */ | |
1348 | if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)) | |
1349 | { | |
1350 | if (aspath_loop_check(riattr->aspath, bgp->confed_id)) | |
1351 | { | |
1352 | if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) | |
1353 | zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u" | |
1354 | " is AS path.", | |
1355 | peer->host, | |
1356 | bgp->confed_id); | |
1357 | return 0; | |
1358 | } | |
1359 | } | |
1360 | ||
1361 | /* Route-Reflect check. */ | |
1362 | if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP) | |
1363 | reflect = 1; | |
1364 | else | |
1365 | reflect = 0; | |
1366 | ||
1367 | /* IBGP reflection check. */ | |
65efcfce | 1368 | if (reflect && !samepeer_safe) |
3f9c7369 DS |
1369 | { |
1370 | /* A route from a Client peer. */ | |
1371 | if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)) | |
1372 | { | |
1373 | /* Reflect to all the Non-Client peers and also to the | |
1374 | Client peers other than the originator. Originator check | |
1375 | is already done. So there is noting to do. */ | |
1376 | /* no bgp client-to-client reflection check. */ | |
1377 | if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT)) | |
1378 | if (CHECK_FLAG (peer->af_flags[afi][safi], | |
1379 | PEER_FLAG_REFLECTOR_CLIENT)) | |
1380 | return 0; | |
1381 | } | |
1382 | else | |
1383 | { | |
1384 | /* A route from a Non-client peer. Reflect to all other | |
1385 | clients. */ | |
1386 | if (! CHECK_FLAG (peer->af_flags[afi][safi], | |
1387 | PEER_FLAG_REFLECTOR_CLIENT)) | |
1388 | return 0; | |
1389 | } | |
1390 | } | |
1391 | ||
1392 | /* For modify attribute, copy it to temporary structure. */ | |
1393 | bgp_attr_dup (attr, riattr); | |
1394 | ||
1395 | /* If local-preference is not set. */ | |
1396 | if ((peer->sort == BGP_PEER_IBGP | |
1397 | || peer->sort == BGP_PEER_CONFED) | |
1398 | && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)))) | |
1399 | { | |
1400 | attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF); | |
1401 | attr->local_pref = bgp->default_local_pref; | |
1402 | } | |
1403 | ||
1404 | /* If originator-id is not set and the route is to be reflected, | |
1405 | set the originator id */ | |
1406 | if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)))) | |
1407 | { | |
1408 | attr->extra = bgp_attr_extra_get(attr); | |
1409 | IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id)); | |
1410 | SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID); | |
1411 | } | |
1412 | ||
1413 | /* Remove MED if its an EBGP peer - will get overwritten by route-maps */ | |
1414 | if (peer->sort == BGP_PEER_EBGP | |
1415 | && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)) | |
1416 | { | |
003c1ba0 | 1417 | if (from != bgp->peer_self && ! transparent |
3f9c7369 DS |
1418 | && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED)) |
1419 | attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)); | |
1420 | } | |
1421 | ||
1422 | /* Since the nexthop attribute can vary per peer, it is not explicitly set | |
1423 | * in announce check, only certain flags and length (or number of nexthops | |
1424 | * -- for IPv6/MP_REACH) are set here in order to guide the update formation | |
1425 | * code in setting the nexthop(s) on a per peer basis in reformat_peer(). | |
1426 | * Typically, the source nexthop in the attribute is preserved but in the | |
1427 | * scenarios where we know it will always be overwritten, we reset the | |
1428 | * nexthop to "0" in an attempt to achieve better Update packing. An | |
1429 | * example of this is when a prefix from each of 2 IBGP peers needs to be | |
1430 | * announced to an EBGP peer (and they have the same attributes barring | |
1431 | * their nexthop). | |
1432 | */ | |
1433 | if (reflect) | |
1434 | SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED); | |
1435 | ||
1436 | #ifdef HAVE_IPV6 | |
587ff0fd LB |
1437 | #define NEXTHOP_IS_V6 (\ |
1438 | (safi != SAFI_ENCAP && \ | |
1439 | (p->family == AF_INET6 || peer_cap_enhe(peer))) || \ | |
1440 | (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 16)) | |
1441 | ||
3811f1e2 DS |
1442 | /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if |
1443 | * the peer (group) is configured to receive link-local nexthop unchanged | |
1444 | * and it is available in the prefix OR we're not reflecting the route and | |
1445 | * the peer (group) to whom we're going to announce is on a shared network | |
003c1ba0 | 1446 | * and this is either a self-originated route or the peer is EBGP. |
3f9c7369 | 1447 | */ |
587ff0fd | 1448 | if (NEXTHOP_IS_V6) |
3f9c7369 | 1449 | { |
801a9bcc | 1450 | attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL; |
3811f1e2 DS |
1451 | if ((CHECK_FLAG (peer->af_flags[afi][safi], |
1452 | PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) && | |
1453 | IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) || | |
003c1ba0 | 1454 | (!reflect && peer->shared_network && |
1455 | (from == bgp->peer_self || peer->sort == BGP_PEER_EBGP))) | |
3f9c7369 | 1456 | { |
3811f1e2 | 1457 | attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL; |
3f9c7369 DS |
1458 | } |
1459 | ||
3811f1e2 DS |
1460 | /* Clear off link-local nexthop in source, whenever it is not needed to |
1461 | * ensure more prefixes share the same attribute for announcement. | |
3f9c7369 DS |
1462 | */ |
1463 | if (!(CHECK_FLAG (peer->af_flags[afi][safi], | |
1464 | PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED))) | |
1465 | memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN); | |
1466 | } | |
1467 | #endif /* HAVE_IPV6 */ | |
1468 | ||
1469 | bgp_peer_remove_private_as(bgp, afi, safi, peer, attr); | |
1470 | bgp_peer_as_override(bgp, afi, safi, peer, attr); | |
1471 | ||
1472 | /* Route map & unsuppress-map apply. */ | |
1473 | if (ROUTE_MAP_OUT_NAME (filter) | |
1474 | || (ri->extra && ri->extra->suppress) ) | |
1475 | { | |
1476 | struct bgp_info info; | |
1477 | struct attr dummy_attr; | |
1478 | struct attr_extra dummy_extra; | |
1479 | ||
1480 | dummy_attr.extra = &dummy_extra; | |
1481 | ||
1482 | info.peer = peer; | |
1483 | info.attr = attr; | |
316e074d DS |
1484 | /* don't confuse inbound and outbound setting */ |
1485 | RESET_FLAG(attr->rmap_change_flags); | |
3f9c7369 DS |
1486 | |
1487 | /* | |
1488 | * The route reflector is not allowed to modify the attributes | |
1489 | * of the reflected IBGP routes unless explicitly allowed. | |
1490 | */ | |
1491 | if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP) | |
1492 | && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) | |
1493 | { | |
1494 | bgp_attr_dup (&dummy_attr, attr); | |
1495 | info.attr = &dummy_attr; | |
1496 | } | |
1497 | ||
1498 | SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT); | |
1499 | ||
1500 | if (ri->extra && ri->extra->suppress) | |
1501 | ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info); | |
1502 | else | |
1503 | ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info); | |
1504 | ||
1505 | peer->rmap_type = 0; | |
1506 | ||
1507 | if (ret == RMAP_DENYMATCH) | |
1508 | { | |
1509 | bgp_attr_flush (attr); | |
1510 | return 0; | |
1511 | } | |
1512 | } | |
1513 | ||
1514 | /* After route-map has been applied, we check to see if the nexthop to | |
1515 | * be carried in the attribute (that is used for the announcement) can | |
1516 | * be cleared off or not. We do this in all cases where we would be | |
1517 | * setting the nexthop to "ourselves". For IPv6, we only need to consider | |
1518 | * the global nexthop here; the link-local nexthop would have been cleared | |
1519 | * already, and if not, it is required by the update formation code. | |
1520 | * Also see earlier comments in this function. | |
43fdf718 | 1521 | */ |
3811f1e2 DS |
1522 | /* |
1523 | * If route-map has performed some operation on the nexthop or the peer | |
1524 | * configuration says to pass it unchanged, we cannot reset the nexthop | |
1525 | * here, so only attempt to do it if these aren't true. Note that the | |
1526 | * route-map handler itself might have cleared the nexthop, if for example, | |
1527 | * it is configured as 'peer-address'. | |
3f9c7369 | 1528 | */ |
3811f1e2 DS |
1529 | if (!bgp_rmap_nhop_changed(attr->rmap_change_flags, |
1530 | riattr->rmap_change_flags) && | |
1531 | !transparent && | |
1532 | !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)) | |
3f9c7369 | 1533 | { |
3811f1e2 | 1534 | /* We can reset the nexthop, if setting (or forcing) it to 'self' */ |
88b8ed8d DW |
1535 | if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) || |
1536 | CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF)) | |
3f9c7369 DS |
1537 | { |
1538 | if (!reflect || | |
1539 | CHECK_FLAG (peer->af_flags[afi][safi], | |
43fdf718 | 1540 | PEER_FLAG_FORCE_NEXTHOP_SELF)) |
3811f1e2 DS |
1541 | subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? |
1542 | AF_INET6 : p->family), attr); | |
3f9c7369 DS |
1543 | } |
1544 | else if (peer->sort == BGP_PEER_EBGP) | |
1545 | { | |
3811f1e2 DS |
1546 | /* Can also reset the nexthop if announcing to EBGP, but only if |
1547 | * no peer in the subgroup is on a shared subnet. | |
1548 | * Note: 3rd party nexthop currently implemented for IPv4 only. | |
1549 | */ | |
3f9c7369 DS |
1550 | SUBGRP_FOREACH_PEER (subgrp, paf) |
1551 | { | |
1552 | if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer)) | |
1553 | break; | |
1554 | } | |
1555 | if (!paf) | |
8a92a8a0 | 1556 | subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr); |
3f9c7369 | 1557 | } |
003c1ba0 | 1558 | /* If IPv6/MP and nexthop does not have any override and happens to |
1559 | * be a link-local address, reset it so that we don't pass along the | |
1560 | * source's link-local IPv6 address to recipients who may not be on | |
1561 | * the same interface. | |
1562 | */ | |
1563 | if (p->family == AF_INET6 || peer_cap_enhe(peer)) | |
1564 | { | |
1565 | if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global)) | |
1566 | subgroup_announce_reset_nhop (AF_INET6, attr); | |
1567 | } | |
3f9c7369 DS |
1568 | } |
1569 | ||
1570 | return 1; | |
1571 | } | |
1572 | ||
fee0f4c6 | 1573 | struct bgp_info_pair |
1574 | { | |
1575 | struct bgp_info *old; | |
1576 | struct bgp_info *new; | |
1577 | }; | |
1578 | ||
94f2b392 | 1579 | static void |
96450faf JB |
1580 | bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, |
1581 | struct bgp_maxpaths_cfg *mpath_cfg, | |
1582 | struct bgp_info_pair *result) | |
718e3744 | 1583 | { |
718e3744 | 1584 | struct bgp_info *new_select; |
1585 | struct bgp_info *old_select; | |
fee0f4c6 | 1586 | struct bgp_info *ri; |
718e3744 | 1587 | struct bgp_info *ri1; |
1588 | struct bgp_info *ri2; | |
b40d939b | 1589 | struct bgp_info *nextri = NULL; |
9fbdd100 | 1590 | int paths_eq, do_mpath, debug; |
96450faf | 1591 | struct list mp_list; |
4690c7d7 | 1592 | char pfx_buf[PREFIX2STR_BUFFER]; |
2ec1e66f | 1593 | char path_buf[PATH_ADDPATH_STR_BUFFER]; |
96450faf JB |
1594 | |
1595 | bgp_mp_list_init (&mp_list); | |
99030da1 | 1596 | do_mpath = (mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1); |
96450faf | 1597 | |
9fbdd100 DS |
1598 | debug = bgp_debug_bestpath(&rn->p); |
1599 | ||
1600 | if (debug) | |
1601 | prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf)); | |
1602 | ||
718e3744 | 1603 | /* bgp deterministic-med */ |
1604 | new_select = NULL; | |
1605 | if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)) | |
06370dac DW |
1606 | { |
1607 | ||
1608 | /* Clear BGP_INFO_DMED_SELECTED for all paths */ | |
1609 | for (ri1 = rn->info; ri1; ri1 = ri1->next) | |
1610 | bgp_info_unset_flag (rn, ri1, BGP_INFO_DMED_SELECTED); | |
1611 | ||
1612 | for (ri1 = rn->info; ri1; ri1 = ri1->next) | |
1613 | { | |
1614 | if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK)) | |
1615 | continue; | |
1616 | if (BGP_INFO_HOLDDOWN (ri1)) | |
2fed8887 | 1617 | continue; |
06370dac DW |
1618 | if (ri1->peer && ri1->peer != bgp->peer_self) |
1619 | if (ri1->peer->status != Established) | |
1620 | continue; | |
718e3744 | 1621 | |
06370dac | 1622 | new_select = ri1; |
06370dac DW |
1623 | if (ri1->next) |
1624 | { | |
1625 | for (ri2 = ri1->next; ri2; ri2 = ri2->next) | |
1626 | { | |
1627 | if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK)) | |
1628 | continue; | |
1629 | if (BGP_INFO_HOLDDOWN (ri2)) | |
1630 | continue; | |
1631 | if (ri2->peer && | |
1632 | ri2->peer != bgp->peer_self && | |
1633 | !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT)) | |
1634 | if (ri2->peer->status != Established) | |
1635 | continue; | |
1636 | ||
1637 | if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath) | |
1638 | || aspath_cmp_left_confed (ri1->attr->aspath, | |
1639 | ri2->attr->aspath)) | |
1640 | { | |
06370dac DW |
1641 | if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq, |
1642 | mpath_cfg, debug, pfx_buf)) | |
1643 | { | |
1644 | bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED); | |
1645 | new_select = ri2; | |
1646 | } | |
1647 | ||
1648 | bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK); | |
1649 | } | |
1650 | } | |
1651 | } | |
1652 | bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK); | |
1653 | bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED); | |
718e3744 | 1654 | |
06370dac | 1655 | if (debug) |
2ec1e66f DW |
1656 | { |
1657 | bgp_info_path_with_addpath_rx_str (new_select, path_buf); | |
1658 | zlog_debug("%s: %s is the bestpath from AS %d", | |
aac9ef6c | 1659 | pfx_buf, path_buf, aspath_get_first_as(new_select->attr->aspath)); |
2ec1e66f | 1660 | } |
06370dac DW |
1661 | } |
1662 | } | |
718e3744 | 1663 | |
1664 | /* Check old selected route and new selected route. */ | |
1665 | old_select = NULL; | |
1666 | new_select = NULL; | |
b40d939b | 1667 | for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri) |
718e3744 | 1668 | { |
1669 | if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) | |
1670 | old_select = ri; | |
1671 | ||
1672 | if (BGP_INFO_HOLDDOWN (ri)) | |
b40d939b | 1673 | { |
1674 | /* reap REMOVED routes, if needs be | |
1675 | * selected route must stay for a while longer though | |
1676 | */ | |
1677 | if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED) | |
1678 | && (ri != old_select)) | |
1679 | bgp_info_reap (rn, ri); | |
1680 | ||
1681 | continue; | |
1682 | } | |
718e3744 | 1683 | |
2fed8887 DS |
1684 | if (ri->peer && |
1685 | ri->peer != bgp->peer_self && | |
1686 | !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT)) | |
1687 | if (ri->peer->status != Established) | |
1688 | continue; | |
1689 | ||
718e3744 | 1690 | if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED) |
1691 | && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED))) | |
1692 | { | |
1a392d46 | 1693 | bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK); |
718e3744 | 1694 | continue; |
1695 | } | |
06370dac | 1696 | |
1a392d46 | 1697 | bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK); |
718e3744 | 1698 | |
9fbdd100 | 1699 | if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf)) |
96450faf JB |
1700 | { |
1701 | new_select = ri; | |
96450faf | 1702 | } |
718e3744 | 1703 | } |
b40d939b | 1704 | |
f4eeff72 DS |
1705 | /* Now that we know which path is the bestpath see if any of the other paths |
1706 | * qualify as multipaths | |
1707 | */ | |
a6086ad4 | 1708 | if (debug) |
f4eeff72 | 1709 | { |
a6086ad4 | 1710 | if (new_select) |
1711 | bgp_info_path_with_addpath_rx_str (new_select, path_buf); | |
1712 | else | |
1713 | sprintf (path_buf, "NONE"); | |
1714 | zlog_debug("%s: After path selection, newbest is %s oldbest was %s", | |
1715 | pfx_buf, path_buf, | |
1716 | old_select ? old_select->peer->host : "NONE"); | |
1717 | } | |
9fbdd100 | 1718 | |
a6086ad4 | 1719 | if (do_mpath && new_select) |
1720 | { | |
f4eeff72 DS |
1721 | for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri) |
1722 | { | |
2ec1e66f DW |
1723 | |
1724 | if (debug) | |
1725 | bgp_info_path_with_addpath_rx_str (ri, path_buf); | |
1726 | ||
f4eeff72 DS |
1727 | if (ri == new_select) |
1728 | { | |
9fbdd100 | 1729 | if (debug) |
2ec1e66f DW |
1730 | zlog_debug("%s: %s is the bestpath, add to the multipath list", |
1731 | pfx_buf, path_buf); | |
3064bf43 | 1732 | bgp_mp_list_add (&mp_list, ri); |
f4eeff72 DS |
1733 | continue; |
1734 | } | |
1735 | ||
1736 | if (BGP_INFO_HOLDDOWN (ri)) | |
1737 | continue; | |
1738 | ||
1739 | if (ri->peer && | |
1740 | ri->peer != bgp->peer_self && | |
1741 | !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT)) | |
1742 | if (ri->peer->status != Established) | |
1743 | continue; | |
1744 | ||
7dc9d4e4 DW |
1745 | if (!bgp_info_nexthop_cmp (ri, new_select)) |
1746 | { | |
1747 | if (debug) | |
2ec1e66f DW |
1748 | zlog_debug("%s: %s has the same nexthop as the bestpath, skip it", |
1749 | pfx_buf, path_buf); | |
7dc9d4e4 DW |
1750 | continue; |
1751 | } | |
1752 | ||
9fbdd100 | 1753 | bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf); |
f4eeff72 DS |
1754 | |
1755 | if (paths_eq) | |
1756 | { | |
9fbdd100 | 1757 | if (debug) |
2ec1e66f DW |
1758 | zlog_debug("%s: %s is equivalent to the bestpath, add to the multipath list", |
1759 | pfx_buf, path_buf); | |
f4eeff72 DS |
1760 | bgp_mp_list_add (&mp_list, ri); |
1761 | } | |
1762 | } | |
1763 | } | |
fee0f4c6 | 1764 | |
b354c427 | 1765 | bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg); |
0b597ef0 | 1766 | bgp_info_mpath_aggregate_update (new_select, old_select); |
96450faf JB |
1767 | bgp_mp_list_clear (&mp_list); |
1768 | ||
1769 | result->old = old_select; | |
1770 | result->new = new_select; | |
1771 | ||
1772 | return; | |
fee0f4c6 | 1773 | } |
1774 | ||
3f9c7369 DS |
1775 | /* |
1776 | * A new route/change in bestpath of an existing route. Evaluate the path | |
1777 | * for advertisement to the subgroup. | |
1778 | */ | |
1779 | int | |
1780 | subgroup_process_announce_selected (struct update_subgroup *subgrp, | |
1781 | struct bgp_info *selected, | |
adbac85e DW |
1782 | struct bgp_node *rn, |
1783 | u_int32_t addpath_tx_id) | |
9eda90ce | 1784 | { |
fee0f4c6 | 1785 | struct prefix *p; |
3f9c7369 | 1786 | struct peer *onlypeer; |
558d1fec JBD |
1787 | struct attr attr; |
1788 | struct attr_extra extra; | |
3f9c7369 DS |
1789 | afi_t afi; |
1790 | safi_t safi; | |
fee0f4c6 | 1791 | |
1792 | p = &rn->p; | |
3f9c7369 DS |
1793 | afi = SUBGRP_AFI(subgrp); |
1794 | safi = SUBGRP_SAFI(subgrp); | |
1795 | onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ? | |
1796 | (SUBGRP_PFIRST(subgrp))->peer : NULL); | |
718e3744 | 1797 | |
9eda90ce | 1798 | /* First update is deferred until ORF or ROUTE-REFRESH is received */ |
3f9c7369 DS |
1799 | if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi], |
1800 | PEER_STATUS_ORF_WAIT_REFRESH)) | |
fee0f4c6 | 1801 | return 0; |
718e3744 | 1802 | |
bede7744 | 1803 | memset(&extra, 0, sizeof(struct attr_extra)); |
2a3d5731 | 1804 | /* It's initialized in bgp_announce_check() */ |
558d1fec JBD |
1805 | attr.extra = &extra; |
1806 | ||
2a3d5731 DW |
1807 | /* Announcement to the subgroup. If the route is filtered withdraw it. */ |
1808 | if (selected) | |
fee0f4c6 | 1809 | { |
2a3d5731 DW |
1810 | if (subgroup_announce_check(selected, subgrp, p, &attr)) |
1811 | bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected); | |
1812 | else | |
1813 | bgp_adj_out_unset_subgroup(rn, subgrp, 1, selected->addpath_tx_id); | |
1814 | } | |
adbac85e | 1815 | |
2a3d5731 DW |
1816 | /* If selected is NULL we must withdraw the path using addpath_tx_id */ |
1817 | else | |
1818 | { | |
1819 | bgp_adj_out_unset_subgroup(rn, subgrp, 1, addpath_tx_id); | |
fee0f4c6 | 1820 | } |
558d1fec | 1821 | |
fee0f4c6 | 1822 | return 0; |
200df115 | 1823 | } |
fee0f4c6 | 1824 | |
3064bf43 | 1825 | /* |
e1072051 | 1826 | * Clear IGP changed flag and attribute changed flag for a route (all paths). |
1827 | * This is called at the end of route processing. | |
3064bf43 | 1828 | */ |
1829 | static void | |
1830 | bgp_zebra_clear_route_change_flags (struct bgp_node *rn) | |
1831 | { | |
1832 | struct bgp_info *ri; | |
1833 | ||
1834 | for (ri = rn->info; ri; ri = ri->next) | |
1835 | { | |
1836 | if (BGP_INFO_HOLDDOWN (ri)) | |
1837 | continue; | |
1838 | UNSET_FLAG (ri->flags, BGP_INFO_IGP_CHANGED); | |
e1072051 | 1839 | UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED); |
3064bf43 | 1840 | } |
1841 | } | |
1842 | ||
1843 | /* | |
1844 | * Has the route changed from the RIB's perspective? This is invoked only | |
1845 | * if the route selection returns the same best route as earlier - to | |
1846 | * determine if we need to update zebra or not. | |
1847 | */ | |
1848 | static int | |
1849 | bgp_zebra_has_route_changed (struct bgp_node *rn, struct bgp_info *selected) | |
1850 | { | |
1851 | struct bgp_info *mpinfo; | |
1852 | ||
e1072051 | 1853 | /* If this is multipath, check all selected paths for any nexthop change or |
1854 | * attribute change. Some attribute changes (e.g., community) aren't of | |
1855 | * relevance to the RIB, but we'll update zebra to ensure we handle the | |
1856 | * case of BGP nexthop change. This is the behavior when the best path has | |
1857 | * an attribute change anyway. | |
1858 | */ | |
3064bf43 | 1859 | if (CHECK_FLAG (selected->flags, BGP_INFO_IGP_CHANGED) || |
1860 | CHECK_FLAG (selected->flags, BGP_INFO_MULTIPATH_CHG)) | |
1861 | return 1; | |
1862 | ||
1863 | /* If this is multipath, check all selected paths for any nexthop change */ | |
1864 | for (mpinfo = bgp_info_mpath_first (selected); mpinfo; | |
1865 | mpinfo = bgp_info_mpath_next (mpinfo)) | |
1866 | { | |
e1072051 | 1867 | if (CHECK_FLAG (mpinfo->flags, BGP_INFO_IGP_CHANGED) |
1868 | || CHECK_FLAG (mpinfo->flags, BGP_INFO_ATTR_CHANGED)) | |
3064bf43 | 1869 | return 1; |
1870 | } | |
1871 | ||
1872 | /* Nothing has changed from the RIB's perspective. */ | |
1873 | return 0; | |
1874 | } | |
1875 | ||
3f9c7369 | 1876 | struct bgp_process_queue |
fee0f4c6 | 1877 | { |
200df115 | 1878 | struct bgp *bgp; |
1879 | struct bgp_node *rn; | |
1880 | afi_t afi; | |
1881 | safi_t safi; | |
1882 | }; | |
1883 | ||
200df115 | 1884 | static wq_item_status |
0fb58d5d | 1885 | bgp_process_main (struct work_queue *wq, void *data) |
200df115 | 1886 | { |
0fb58d5d | 1887 | struct bgp_process_queue *pq = data; |
200df115 | 1888 | struct bgp *bgp = pq->bgp; |
1889 | struct bgp_node *rn = pq->rn; | |
1890 | afi_t afi = pq->afi; | |
1891 | safi_t safi = pq->safi; | |
1892 | struct prefix *p = &rn->p; | |
fee0f4c6 | 1893 | struct bgp_info *new_select; |
1894 | struct bgp_info *old_select; | |
1895 | struct bgp_info_pair old_and_new; | |
cb1faec9 DS |
1896 | |
1897 | /* Is it end of initial update? (after startup) */ | |
1898 | if (!rn) | |
1899 | { | |
4a16ae86 DS |
1900 | quagga_timestamp(3, bgp->update_delay_zebra_resume_time, |
1901 | sizeof(bgp->update_delay_zebra_resume_time)); | |
1902 | ||
1903 | bgp->main_zebra_update_hold = 0; | |
1904 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
1905 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) | |
1906 | { | |
1907 | bgp_zebra_announce_table(bgp, afi, safi); | |
1908 | } | |
1909 | bgp->main_peers_update_hold = 0; | |
1910 | ||
cb1faec9 DS |
1911 | bgp_start_routeadv(bgp); |
1912 | return WQ_SUCCESS; | |
1913 | } | |
1914 | ||
fee0f4c6 | 1915 | /* Best path selection. */ |
96450faf | 1916 | bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new); |
fee0f4c6 | 1917 | old_select = old_and_new.old; |
1918 | new_select = old_and_new.new; | |
1919 | ||
1920 | /* Nothing to do. */ | |
adbac85e DW |
1921 | if (old_select && old_select == new_select && |
1922 | !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR) && | |
1923 | !CHECK_FLAG(old_select->flags, BGP_INFO_ATTR_CHANGED) && | |
1924 | !bgp->addpath_tx_used[afi][safi]) | |
1925 | { | |
3064bf43 | 1926 | if (bgp_zebra_has_route_changed (rn, old_select)) |
65efcfce LB |
1927 | { |
1928 | #if ENABLE_BGP_VNC | |
1929 | vnc_import_bgp_add_route(bgp, p, old_select); | |
1930 | vnc_import_bgp_exterior_add_route(bgp, p, old_select); | |
1931 | #endif | |
1932 | bgp_zebra_announce (p, old_select, bgp, afi, safi); | |
1933 | } | |
adbac85e | 1934 | UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG); |
3064bf43 | 1935 | bgp_zebra_clear_route_change_flags (rn); |
adbac85e DW |
1936 | UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED); |
1937 | return WQ_SUCCESS; | |
fee0f4c6 | 1938 | } |
1939 | ||
8ad7271d DS |
1940 | /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */ |
1941 | UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR); | |
1942 | ||
3f9c7369 DS |
1943 | /* bestpath has changed; bump version */ |
1944 | if (old_select || new_select) | |
0de4848d DS |
1945 | { |
1946 | bgp_bump_version(rn); | |
1947 | ||
1948 | if (!bgp->t_rmap_def_originate_eval) | |
1949 | { | |
1950 | bgp_lock (bgp); | |
9229d914 | 1951 | THREAD_TIMER_ON(bm->master, bgp->t_rmap_def_originate_eval, |
0de4848d DS |
1952 | update_group_refresh_default_originate_route_map, |
1953 | bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER); | |
1954 | } | |
1955 | } | |
3f9c7369 | 1956 | |
338b3424 | 1957 | if (old_select) |
1a392d46 | 1958 | bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED); |
338b3424 | 1959 | if (new_select) |
1960 | { | |
1a392d46 PJ |
1961 | bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED); |
1962 | bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED); | |
8196f13d | 1963 | UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG); |
338b3424 | 1964 | } |
1965 | ||
65efcfce LB |
1966 | #if ENABLE_BGP_VNC |
1967 | if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) { | |
1968 | if (old_select != new_select) { | |
1969 | if (old_select) { | |
1970 | vnc_import_bgp_exterior_del_route(bgp, p, old_select); | |
1971 | vnc_import_bgp_del_route(bgp, p, old_select); | |
1972 | } | |
1973 | if (new_select) { | |
1974 | vnc_import_bgp_exterior_add_route(bgp, p, new_select); | |
1975 | vnc_import_bgp_add_route(bgp, p, new_select); | |
1976 | } | |
1977 | } | |
1978 | } | |
1979 | #endif | |
1980 | ||
3f9c7369 | 1981 | group_announce_route(bgp, afi, safi, rn, new_select); |
718e3744 | 1982 | |
1983 | /* FIB update. */ | |
ad4cbda1 | 1984 | if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && |
1985 | (bgp->inst_type != BGP_INSTANCE_TYPE_VIEW) && | |
1986 | !bgp_option_check (BGP_OPT_NO_FIB)) | |
718e3744 | 1987 | { |
1988 | if (new_select | |
1989 | && new_select->type == ZEBRA_ROUTE_BGP | |
f992e2a9 DS |
1990 | && (new_select->sub_type == BGP_ROUTE_NORMAL || |
1991 | new_select->sub_type == BGP_ROUTE_AGGREGATE)) | |
73ac8160 | 1992 | bgp_zebra_announce (p, new_select, bgp, afi, safi); |
718e3744 | 1993 | else |
1994 | { | |
1995 | /* Withdraw the route from the kernel. */ | |
1996 | if (old_select | |
1997 | && old_select->type == ZEBRA_ROUTE_BGP | |
f992e2a9 DS |
1998 | && (old_select->sub_type == BGP_ROUTE_NORMAL || |
1999 | old_select->sub_type == BGP_ROUTE_AGGREGATE)) | |
5a616c08 | 2000 | bgp_zebra_withdraw (p, old_select, safi); |
718e3744 | 2001 | } |
2002 | } | |
3064bf43 | 2003 | |
2004 | /* Clear any route change flags. */ | |
2005 | bgp_zebra_clear_route_change_flags (rn); | |
2006 | ||
adbac85e | 2007 | /* Reap old select bgp_info, if it has been removed */ |
b40d939b | 2008 | if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED)) |
2009 | bgp_info_reap (rn, old_select); | |
2010 | ||
200df115 | 2011 | UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED); |
2012 | return WQ_SUCCESS; | |
718e3744 | 2013 | } |
2014 | ||
200df115 | 2015 | static void |
0fb58d5d | 2016 | bgp_processq_del (struct work_queue *wq, void *data) |
200df115 | 2017 | { |
0fb58d5d | 2018 | struct bgp_process_queue *pq = data; |
cb1faec9 DS |
2019 | struct bgp_table *table; |
2020 | ||
228da428 | 2021 | bgp_unlock (pq->bgp); |
cb1faec9 DS |
2022 | if (pq->rn) |
2023 | { | |
2024 | table = bgp_node_table (pq->rn); | |
2025 | bgp_unlock_node (pq->rn); | |
2026 | bgp_table_unlock (table); | |
2027 | } | |
200df115 | 2028 | XFREE (MTYPE_BGP_PROCESS_QUEUE, pq); |
2029 | } | |
2030 | ||
f188f2c4 | 2031 | void |
200df115 | 2032 | bgp_process_queue_init (void) |
2033 | { | |
495f0b13 DS |
2034 | if (!bm->process_main_queue) |
2035 | { | |
2036 | bm->process_main_queue | |
87d4a781 | 2037 | = work_queue_new (bm->master, "process_main_queue"); |
495f0b13 | 2038 | |
2a3d5731 DW |
2039 | if ( !bm->process_main_queue) |
2040 | { | |
2041 | zlog_err ("%s: Failed to allocate work queue", __func__); | |
2042 | exit (1); | |
2043 | } | |
200df115 | 2044 | } |
2045 | ||
2046 | bm->process_main_queue->spec.workfunc = &bgp_process_main; | |
200df115 | 2047 | bm->process_main_queue->spec.del_item_data = &bgp_processq_del; |
838bbde0 PJ |
2048 | bm->process_main_queue->spec.max_retries = 0; |
2049 | bm->process_main_queue->spec.hold = 50; | |
d889623f DS |
2050 | /* Use a higher yield value of 50ms for main queue processing */ |
2051 | bm->process_main_queue->spec.yield = 50 * 1000L; | |
200df115 | 2052 | } |
2053 | ||
2054 | void | |
fee0f4c6 | 2055 | bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi) |
2056 | { | |
200df115 | 2057 | struct bgp_process_queue *pqnode; |
2058 | ||
2059 | /* already scheduled for processing? */ | |
2060 | if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED)) | |
2061 | return; | |
495f0b13 | 2062 | |
2a3d5731 | 2063 | if (bm->process_main_queue == NULL) |
2e02b9b2 DS |
2064 | bgp_process_queue_init (); |
2065 | ||
200df115 | 2066 | pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE, |
2067 | sizeof (struct bgp_process_queue)); | |
2068 | if (!pqnode) | |
2069 | return; | |
228da428 CC |
2070 | |
2071 | /* all unlocked in bgp_processq_del */ | |
67174041 | 2072 | bgp_table_lock (bgp_node_table (rn)); |
228da428 | 2073 | pqnode->rn = bgp_lock_node (rn); |
200df115 | 2074 | pqnode->bgp = bgp; |
228da428 | 2075 | bgp_lock (bgp); |
200df115 | 2076 | pqnode->afi = afi; |
2077 | pqnode->safi = safi; | |
2a3d5731 | 2078 | work_queue_add (bm->process_main_queue, pqnode); |
07ff4dc4 | 2079 | SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED); |
200df115 | 2080 | return; |
fee0f4c6 | 2081 | } |
0a486e5f | 2082 | |
cb1faec9 | 2083 | void |
2a3d5731 | 2084 | bgp_add_eoiu_mark (struct bgp *bgp) |
cb1faec9 DS |
2085 | { |
2086 | struct bgp_process_queue *pqnode; | |
2087 | ||
2a3d5731 | 2088 | if (bm->process_main_queue == NULL) |
2e02b9b2 DS |
2089 | bgp_process_queue_init (); |
2090 | ||
cb1faec9 DS |
2091 | pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE, |
2092 | sizeof (struct bgp_process_queue)); | |
2093 | if (!pqnode) | |
2094 | return; | |
2095 | ||
2096 | pqnode->rn = NULL; | |
2097 | pqnode->bgp = bgp; | |
2098 | bgp_lock (bgp); | |
2a3d5731 | 2099 | work_queue_add (bm->process_main_queue, pqnode); |
cb1faec9 DS |
2100 | } |
2101 | ||
94f2b392 | 2102 | static int |
0a486e5f | 2103 | bgp_maximum_prefix_restart_timer (struct thread *thread) |
2104 | { | |
2105 | struct peer *peer; | |
2106 | ||
2107 | peer = THREAD_ARG (thread); | |
2108 | peer->t_pmax_restart = NULL; | |
2109 | ||
16286195 | 2110 | if (bgp_debug_neighbor_events(peer)) |
0a486e5f | 2111 | zlog_debug ("%s Maximum-prefix restart timer expired, restore peering", |
2112 | peer->host); | |
2113 | ||
1ff9a340 | 2114 | peer_clear (peer, NULL); |
0a486e5f | 2115 | |
2116 | return 0; | |
2117 | } | |
2118 | ||
718e3744 | 2119 | int |
5228ad27 | 2120 | bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi, |
2121 | safi_t safi, int always) | |
718e3744 | 2122 | { |
e0701b79 | 2123 | if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) |
2124 | return 0; | |
2125 | ||
2126 | if (peer->pcount[afi][safi] > peer->pmax[afi][safi]) | |
718e3744 | 2127 | { |
e0701b79 | 2128 | if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT) |
2129 | && ! always) | |
2130 | return 0; | |
2131 | ||
16286195 DS |
2132 | zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, " |
2133 | "limit %ld", afi_safi_print (afi, safi), peer->host, | |
2134 | peer->pcount[afi][safi], peer->pmax[afi][safi]); | |
e0701b79 | 2135 | SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT); |
2136 | ||
2137 | if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING)) | |
2138 | return 0; | |
2139 | ||
2140 | { | |
5228ad27 | 2141 | u_int8_t ndata[7]; |
e0701b79 | 2142 | |
2143 | if (safi == SAFI_MPLS_VPN) | |
42e6d745 | 2144 | safi = SAFI_MPLS_LABELED_VPN; |
5228ad27 | 2145 | |
2146 | ndata[0] = (afi >> 8); | |
2147 | ndata[1] = afi; | |
2148 | ndata[2] = safi; | |
2149 | ndata[3] = (peer->pmax[afi][safi] >> 24); | |
2150 | ndata[4] = (peer->pmax[afi][safi] >> 16); | |
2151 | ndata[5] = (peer->pmax[afi][safi] >> 8); | |
2152 | ndata[6] = (peer->pmax[afi][safi]); | |
e0701b79 | 2153 | |
2154 | SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW); | |
2155 | bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE, | |
2156 | BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7); | |
2157 | } | |
0a486e5f | 2158 | |
f14e6fdb DS |
2159 | /* Dynamic peers will just close their connection. */ |
2160 | if (peer_dynamic_neighbor (peer)) | |
2161 | return 1; | |
2162 | ||
0a486e5f | 2163 | /* restart timer start */ |
2164 | if (peer->pmax_restart[afi][safi]) | |
2165 | { | |
2166 | peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60; | |
2167 | ||
16286195 | 2168 | if (bgp_debug_neighbor_events(peer)) |
0a486e5f | 2169 | zlog_debug ("%s Maximum-prefix restart timer started for %d secs", |
2170 | peer->host, peer->v_pmax_restart); | |
2171 | ||
2172 | BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer, | |
2173 | peer->v_pmax_restart); | |
2174 | } | |
2175 | ||
e0701b79 | 2176 | return 1; |
2177 | } | |
2178 | else | |
2179 | UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT); | |
2180 | ||
2181 | if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100)) | |
2182 | { | |
2183 | if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD) | |
2184 | && ! always) | |
2185 | return 0; | |
2186 | ||
16286195 DS |
2187 | zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld", |
2188 | afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi], | |
2189 | peer->pmax[afi][safi]); | |
e0701b79 | 2190 | SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD); |
718e3744 | 2191 | } |
e0701b79 | 2192 | else |
2193 | UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD); | |
718e3744 | 2194 | return 0; |
2195 | } | |
2196 | ||
b40d939b | 2197 | /* Unconditionally remove the route from the RIB, without taking |
2198 | * damping into consideration (eg, because the session went down) | |
2199 | */ | |
94f2b392 | 2200 | static void |
718e3744 | 2201 | bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer, |
2202 | afi_t afi, safi_t safi) | |
2203 | { | |
902212c3 | 2204 | bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi); |
2205 | ||
2206 | if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) | |
2207 | bgp_info_delete (rn, ri); /* keep historical info */ | |
2208 | ||
b40d939b | 2209 | bgp_process (peer->bgp, rn, afi, safi); |
718e3744 | 2210 | } |
2211 | ||
94f2b392 | 2212 | static void |
718e3744 | 2213 | bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer, |
65efcfce | 2214 | afi_t afi, safi_t safi, struct prefix_rd *prd) |
718e3744 | 2215 | { |
718e3744 | 2216 | int status = BGP_DAMP_NONE; |
2217 | ||
b40d939b | 2218 | /* apply dampening, if result is suppressed, we'll be retaining |
2219 | * the bgp_info in the RIB for historical reference. | |
2220 | */ | |
2221 | if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING) | |
6d85b15b | 2222 | && peer->sort == BGP_PEER_EBGP) |
b40d939b | 2223 | if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0)) |
2224 | == BGP_DAMP_SUPPRESSED) | |
902212c3 | 2225 | { |
902212c3 | 2226 | bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi); |
2227 | return; | |
2228 | } | |
65efcfce LB |
2229 | |
2230 | #if ENABLE_BGP_VNC | |
2231 | if (safi == SAFI_MPLS_VPN) { | |
2232 | struct bgp_node *prn = NULL; | |
2233 | struct bgp_table *table = NULL; | |
2234 | ||
2235 | prn = bgp_node_get(peer->bgp->rib[afi][safi], (struct prefix *) prd); | |
2236 | if (prn->info) { | |
2237 | table = (struct bgp_table *)(prn->info); | |
2238 | ||
2239 | vnc_import_bgp_del_vnc_host_route_mode_resolve_nve( | |
2240 | peer->bgp, | |
2241 | prd, | |
2242 | table, | |
2243 | &rn->p, | |
2244 | ri); | |
2245 | } | |
2246 | bgp_unlock_node(prn); | |
2247 | } | |
2248 | if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) { | |
2249 | if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) { | |
2250 | ||
2251 | vnc_import_bgp_del_route(peer->bgp, &rn->p, ri); | |
2252 | vnc_import_bgp_exterior_del_route(peer->bgp, &rn->p, ri); | |
2253 | } | |
2254 | } | |
2255 | #endif | |
902212c3 | 2256 | bgp_rib_remove (rn, ri, peer, afi, safi); |
718e3744 | 2257 | } |
2258 | ||
fb018d25 | 2259 | static struct bgp_info * |
7c8ff89e | 2260 | info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr, |
fb018d25 DS |
2261 | struct bgp_node *rn) |
2262 | { | |
2263 | struct bgp_info *new; | |
2264 | ||
2265 | /* Make new BGP info. */ | |
2266 | new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info)); | |
2267 | new->type = type; | |
7c8ff89e | 2268 | new->instance = instance; |
fb018d25 DS |
2269 | new->sub_type = sub_type; |
2270 | new->peer = peer; | |
2271 | new->attr = attr; | |
2272 | new->uptime = bgp_clock (); | |
2273 | new->net = rn; | |
adbac85e | 2274 | new->addpath_tx_id = ++peer->bgp->addpath_tx_id; |
fb018d25 DS |
2275 | return new; |
2276 | } | |
2277 | ||
94f2b392 | 2278 | static void |
2ec1e66f | 2279 | bgp_info_addpath_rx_str(u_int32_t addpath_id, char *buf) |
cd808e74 | 2280 | { |
2ec1e66f DW |
2281 | if (addpath_id) |
2282 | sprintf(buf, " with addpath ID %d", addpath_id); | |
cd808e74 DS |
2283 | } |
2284 | ||
2ec1e66f | 2285 | |
c265ee22 DS |
2286 | /* Check if received nexthop is valid or not. */ |
2287 | static int | |
6aeb9e78 | 2288 | bgp_update_martian_nexthop (struct bgp *bgp, afi_t afi, safi_t safi, struct attr *attr) |
c265ee22 DS |
2289 | { |
2290 | struct attr_extra *attre = attr->extra; | |
2291 | int ret = 0; | |
2292 | ||
2293 | /* Only validated for unicast and multicast currently. */ | |
2294 | if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST) | |
2295 | return 0; | |
2296 | ||
2297 | /* If NEXT_HOP is present, validate it. */ | |
2298 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP)) | |
2299 | { | |
2300 | if (attr->nexthop.s_addr == 0 || | |
2301 | IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) || | |
6aeb9e78 | 2302 | bgp_nexthop_self (bgp, attr)) |
c265ee22 DS |
2303 | ret = 1; |
2304 | } | |
2305 | ||
2306 | /* If MP_NEXTHOP is present, validate it. */ | |
2307 | /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop; | |
2308 | * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if | |
2309 | * it is not an IPv6 link-local address. | |
2310 | */ | |
2311 | if (attre && attre->mp_nexthop_len) | |
2312 | { | |
2313 | switch (attre->mp_nexthop_len) | |
2314 | { | |
2315 | case BGP_ATTR_NHLEN_IPV4: | |
2316 | case BGP_ATTR_NHLEN_VPNV4: | |
2317 | ret = (attre->mp_nexthop_global_in.s_addr == 0 || | |
2318 | IPV4_CLASS_DE (ntohl (attre->mp_nexthop_global_in.s_addr))); | |
2319 | break; | |
2320 | ||
2321 | #ifdef HAVE_IPV6 | |
2322 | case BGP_ATTR_NHLEN_IPV6_GLOBAL: | |
2323 | case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL: | |
cf6c0c08 | 2324 | case BGP_ATTR_NHLEN_VPNV6_GLOBAL: |
c265ee22 DS |
2325 | ret = (IN6_IS_ADDR_UNSPECIFIED(&attre->mp_nexthop_global) || |
2326 | IN6_IS_ADDR_LOOPBACK(&attre->mp_nexthop_global) || | |
2327 | IN6_IS_ADDR_MULTICAST(&attre->mp_nexthop_global)); | |
2328 | break; | |
2329 | #endif /* HAVE_IPV6 */ | |
2330 | ||
2331 | default: | |
2332 | ret = 1; | |
2333 | break; | |
2334 | } | |
2335 | } | |
2336 | ||
2337 | return ret; | |
2338 | } | |
2339 | ||
a7ee645d DS |
2340 | int |
2341 | bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id, | |
2342 | struct attr *attr, afi_t afi, safi_t safi, int type, | |
2343 | int sub_type, struct prefix_rd *prd, u_char *tag, | |
2344 | int soft_reconfig) | |
718e3744 | 2345 | { |
2346 | int ret; | |
2347 | int aspath_loop_count = 0; | |
2348 | struct bgp_node *rn; | |
2349 | struct bgp *bgp; | |
558d1fec JBD |
2350 | struct attr new_attr; |
2351 | struct attr_extra new_extra; | |
718e3744 | 2352 | struct attr *attr_new; |
2353 | struct bgp_info *ri; | |
2354 | struct bgp_info *new; | |
fd79ac91 | 2355 | const char *reason; |
718e3744 | 2356 | char buf[SU_ADDRSTRLEN]; |
cd808e74 | 2357 | char buf2[30]; |
fc9a856f | 2358 | int connected = 0; |
aac9ef6c | 2359 | int do_loop_check = 1; |
65efcfce LB |
2360 | #if ENABLE_BGP_VNC |
2361 | int vnc_implicit_withdraw = 0; | |
2362 | #endif | |
718e3744 | 2363 | |
f9a3a260 LB |
2364 | memset (&new_attr, 0, sizeof(struct attr)); |
2365 | memset (&new_extra, 0, sizeof(struct attr_extra)); | |
2366 | ||
718e3744 | 2367 | bgp = peer->bgp; |
fee0f4c6 | 2368 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd); |
fb982c25 | 2369 | |
718e3744 | 2370 | /* When peer's soft reconfiguration enabled. Record input packet in |
2371 | Adj-RIBs-In. */ | |
343aa822 JBD |
2372 | if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG) |
2373 | && peer != bgp->peer_self) | |
43143c8f | 2374 | bgp_adj_in_set (rn, peer, attr, addpath_id); |
718e3744 | 2375 | |
2376 | /* Check previously received route. */ | |
2377 | for (ri = rn->info; ri; ri = ri->next) | |
a82478b9 DS |
2378 | if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type && |
2379 | ri->addpath_rx_id == addpath_id) | |
718e3744 | 2380 | break; |
2381 | ||
2382 | /* AS path local-as loop check. */ | |
2383 | if (peer->change_local_as) | |
2384 | { | |
2385 | if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)) | |
2386 | aspath_loop_count = 1; | |
2387 | ||
2388 | if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count) | |
2389 | { | |
2390 | reason = "as-path contains our own AS;"; | |
2391 | goto filtered; | |
2392 | } | |
2393 | } | |
2394 | ||
aac9ef6c DW |
2395 | /* If the peer is configured for "allowas-in origin" and the last ASN in the |
2396 | * as-path is our ASN then we do not need to call aspath_loop_check | |
2397 | */ | |
2398 | if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN_ORIGIN)) | |
2399 | if (aspath_get_last_as(attr->aspath) == bgp->as) | |
2400 | do_loop_check = 0; | |
2401 | ||
718e3744 | 2402 | /* AS path loop check. */ |
aac9ef6c | 2403 | if (do_loop_check) |
718e3744 | 2404 | { |
aac9ef6c DW |
2405 | if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi] |
2406 | || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION) | |
2407 | && aspath_loop_check(attr->aspath, bgp->confed_id) > peer->allowas_in[afi][safi])) | |
2408 | { | |
2409 | reason = "as-path contains our own AS;"; | |
2410 | goto filtered; | |
2411 | } | |
718e3744 | 2412 | } |
2413 | ||
2414 | /* Route reflector originator ID check. */ | |
2415 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) | |
fb982c25 | 2416 | && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id)) |
718e3744 | 2417 | { |
2418 | reason = "originator is us;"; | |
2419 | goto filtered; | |
2420 | } | |
2421 | ||
2422 | /* Route reflector cluster ID check. */ | |
2423 | if (bgp_cluster_filter (peer, attr)) | |
2424 | { | |
2425 | reason = "reflected from the same cluster;"; | |
2426 | goto filtered; | |
2427 | } | |
2428 | ||
2429 | /* Apply incoming filter. */ | |
2430 | if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY) | |
2431 | { | |
2432 | reason = "filter;"; | |
2433 | goto filtered; | |
2434 | } | |
2435 | ||
558d1fec | 2436 | new_attr.extra = &new_extra; |
fb982c25 | 2437 | bgp_attr_dup (&new_attr, attr); |
718e3744 | 2438 | |
c460e572 DL |
2439 | /* Apply incoming route-map. |
2440 | * NB: new_attr may now contain newly allocated values from route-map "set" | |
2441 | * commands, so we need bgp_attr_flush in the error paths, until we intern | |
2442 | * the attr (which takes over the memory references) */ | |
0b16f239 | 2443 | if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY) |
718e3744 | 2444 | { |
2445 | reason = "route-map;"; | |
c460e572 | 2446 | bgp_attr_flush (&new_attr); |
718e3744 | 2447 | goto filtered; |
2448 | } | |
2449 | ||
c265ee22 | 2450 | /* next hop check. */ |
6aeb9e78 | 2451 | if (bgp_update_martian_nexthop (bgp, afi, safi, &new_attr)) |
718e3744 | 2452 | { |
c265ee22 DS |
2453 | reason = "martian or self next-hop;"; |
2454 | bgp_attr_flush (&new_attr); | |
2455 | goto filtered; | |
718e3744 | 2456 | } |
2457 | ||
2458 | attr_new = bgp_attr_intern (&new_attr); | |
2459 | ||
2460 | /* If the update is implicit withdraw. */ | |
2461 | if (ri) | |
2462 | { | |
65957886 | 2463 | ri->uptime = bgp_clock (); |
718e3744 | 2464 | |
2465 | /* Same attribute comes in. */ | |
16d2e241 PJ |
2466 | if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED) |
2467 | && attrhash_cmp (ri->attr, attr_new)) | |
718e3744 | 2468 | { |
718e3744 | 2469 | if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING) |
6d85b15b | 2470 | && peer->sort == BGP_PEER_EBGP |
718e3744 | 2471 | && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) |
2472 | { | |
3f9c7369 | 2473 | if (bgp_debug_update(peer, p, NULL, 1)) |
cd808e74 | 2474 | { |
2ec1e66f | 2475 | bgp_info_addpath_rx_str(addpath_id, buf2); |
cd808e74 | 2476 | zlog_debug ("%s rcvd %s/%d%s", |
16286195 DS |
2477 | peer->host, |
2478 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
cd808e74 DS |
2479 | p->prefixlen, buf2); |
2480 | } | |
718e3744 | 2481 | |
902212c3 | 2482 | if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED) |
2483 | { | |
2484 | bgp_aggregate_increment (bgp, p, ri, afi, safi); | |
2485 | bgp_process (bgp, rn, afi, safi); | |
2486 | } | |
718e3744 | 2487 | } |
16d2e241 | 2488 | else /* Duplicate - odd */ |
718e3744 | 2489 | { |
3f9c7369 | 2490 | if (bgp_debug_update(peer, p, NULL, 1)) |
16286195 DS |
2491 | { |
2492 | if (!peer->rcvd_attr_printed) | |
2493 | { | |
2494 | zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str); | |
2495 | peer->rcvd_attr_printed = 1; | |
2496 | } | |
2497 | ||
2ec1e66f | 2498 | bgp_info_addpath_rx_str(addpath_id, buf2); |
cd808e74 | 2499 | zlog_debug ("%s rcvd %s/%d%s...duplicate ignored", |
16286195 DS |
2500 | peer->host, |
2501 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
cd808e74 | 2502 | p->prefixlen, buf2); |
16286195 | 2503 | } |
93406d87 | 2504 | |
2505 | /* graceful restart STALE flag unset. */ | |
2506 | if (CHECK_FLAG (ri->flags, BGP_INFO_STALE)) | |
2507 | { | |
1a392d46 | 2508 | bgp_info_unset_flag (rn, ri, BGP_INFO_STALE); |
902212c3 | 2509 | bgp_process (bgp, rn, afi, safi); |
93406d87 | 2510 | } |
718e3744 | 2511 | } |
2512 | ||
2513 | bgp_unlock_node (rn); | |
f6f434b2 | 2514 | bgp_attr_unintern (&attr_new); |
558d1fec | 2515 | |
718e3744 | 2516 | return 0; |
2517 | } | |
2518 | ||
16d2e241 PJ |
2519 | /* Withdraw/Announce before we fully processed the withdraw */ |
2520 | if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)) | |
2521 | { | |
3f9c7369 | 2522 | if (bgp_debug_update(peer, p, NULL, 1)) |
cd808e74 | 2523 | { |
2ec1e66f | 2524 | bgp_info_addpath_rx_str(addpath_id, buf2); |
cd808e74 DS |
2525 | zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing", |
2526 | peer->host, | |
2527 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
2528 | p->prefixlen, buf2); | |
2529 | } | |
16d2e241 PJ |
2530 | bgp_info_restore (rn, ri); |
2531 | } | |
2532 | ||
718e3744 | 2533 | /* Received Logging. */ |
3f9c7369 | 2534 | if (bgp_debug_update(peer, p, NULL, 1)) |
cd808e74 | 2535 | { |
2ec1e66f | 2536 | bgp_info_addpath_rx_str(addpath_id, buf2); |
cd808e74 | 2537 | zlog_debug ("%s rcvd %s/%d%s", |
16286195 DS |
2538 | peer->host, |
2539 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
cd808e74 DS |
2540 | p->prefixlen, buf2); |
2541 | } | |
718e3744 | 2542 | |
93406d87 | 2543 | /* graceful restart STALE flag unset. */ |
2544 | if (CHECK_FLAG (ri->flags, BGP_INFO_STALE)) | |
1a392d46 | 2545 | bgp_info_unset_flag (rn, ri, BGP_INFO_STALE); |
93406d87 | 2546 | |
718e3744 | 2547 | /* The attribute is changed. */ |
1a392d46 | 2548 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
902212c3 | 2549 | |
2550 | /* implicit withdraw, decrement aggregate and pcount here. | |
2551 | * only if update is accepted, they'll increment below. | |
2552 | */ | |
902212c3 | 2553 | bgp_aggregate_decrement (bgp, p, ri, afi, safi); |
2554 | ||
718e3744 | 2555 | /* Update bgp route dampening information. */ |
2556 | if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING) | |
6d85b15b | 2557 | && peer->sort == BGP_PEER_EBGP) |
718e3744 | 2558 | { |
2559 | /* This is implicit withdraw so we should update dampening | |
2560 | information. */ | |
2561 | if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) | |
2562 | bgp_damp_withdraw (ri, rn, afi, safi, 1); | |
718e3744 | 2563 | } |
65efcfce LB |
2564 | #if ENABLE_BGP_VNC |
2565 | if (safi == SAFI_MPLS_VPN) { | |
2566 | struct bgp_node *prn = NULL; | |
2567 | struct bgp_table *table = NULL; | |
2568 | ||
2569 | prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd); | |
2570 | if (prn->info) { | |
2571 | table = (struct bgp_table *)(prn->info); | |
2572 | ||
2573 | vnc_import_bgp_del_vnc_host_route_mode_resolve_nve( | |
2574 | bgp, | |
2575 | prd, | |
2576 | table, | |
2577 | p, | |
2578 | ri); | |
2579 | } | |
2580 | bgp_unlock_node(prn); | |
2581 | } | |
2582 | if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) { | |
2583 | if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) { | |
2584 | /* | |
2585 | * Implicit withdraw case. | |
2586 | */ | |
2587 | ++vnc_implicit_withdraw; | |
2588 | vnc_import_bgp_del_route(bgp, p, ri); | |
2589 | vnc_import_bgp_exterior_del_route(bgp, p, ri); | |
2590 | } | |
2591 | } | |
2592 | #endif | |
718e3744 | 2593 | |
718e3744 | 2594 | /* Update to new attribute. */ |
f6f434b2 | 2595 | bgp_attr_unintern (&ri->attr); |
718e3744 | 2596 | ri->attr = attr_new; |
2597 | ||
2598 | /* Update MPLS tag. */ | |
2599 | if (safi == SAFI_MPLS_VPN) | |
fb982c25 | 2600 | memcpy ((bgp_info_extra_get (ri))->tag, tag, 3); |
718e3744 | 2601 | |
65efcfce LB |
2602 | #if ENABLE_BGP_VNC |
2603 | if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) | |
2604 | { | |
2605 | if (vnc_implicit_withdraw) | |
2606 | { | |
2607 | /* | |
2608 | * Add back the route with its new attributes (e.g., nexthop). | |
2609 | * The route is still selected, until the route selection | |
2610 | * queued by bgp_process actually runs. We have to make this | |
2611 | * update to the VNC side immediately to avoid racing against | |
2612 | * configuration changes (e.g., route-map changes) which | |
2613 | * trigger re-importation of the entire RIB. | |
2614 | */ | |
2615 | vnc_import_bgp_add_route(bgp, p, ri); | |
2616 | vnc_import_bgp_exterior_add_route(bgp, p, ri); | |
2617 | } | |
2618 | } | |
2619 | #endif | |
2620 | ||
718e3744 | 2621 | /* Update bgp route dampening information. */ |
2622 | if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING) | |
6d85b15b | 2623 | && peer->sort == BGP_PEER_EBGP) |
718e3744 | 2624 | { |
2625 | /* Now we do normal update dampening. */ | |
2626 | ret = bgp_damp_update (ri, rn, afi, safi); | |
2627 | if (ret == BGP_DAMP_SUPPRESSED) | |
2628 | { | |
2629 | bgp_unlock_node (rn); | |
2630 | return 0; | |
2631 | } | |
2632 | } | |
2633 | ||
2634 | /* Nexthop reachability check. */ | |
fc9a856f | 2635 | if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST) |
718e3744 | 2636 | { |
fc9a856f | 2637 | if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 && |
907f92c8 DS |
2638 | ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK) |
2639 | && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK)) | |
fc9a856f DS |
2640 | connected = 1; |
2641 | else | |
2642 | connected = 0; | |
2643 | ||
75aead62 | 2644 | if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected)) |
1a392d46 | 2645 | bgp_info_set_flag (rn, ri, BGP_INFO_VALID); |
718e3744 | 2646 | else |
fc9a856f DS |
2647 | { |
2648 | if (BGP_DEBUG(nht, NHT)) | |
2649 | { | |
2650 | char buf1[INET6_ADDRSTRLEN]; | |
2651 | inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN); | |
2652 | zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1); | |
2653 | } | |
2654 | bgp_info_unset_flag (rn, ri, BGP_INFO_VALID); | |
2655 | } | |
718e3744 | 2656 | } |
2657 | else | |
fc9a856f | 2658 | bgp_info_set_flag (rn, ri, BGP_INFO_VALID); |
718e3744 | 2659 | |
65efcfce LB |
2660 | #if ENABLE_BGP_VNC |
2661 | if (safi == SAFI_MPLS_VPN) | |
2662 | { | |
2663 | struct bgp_node *prn = NULL; | |
2664 | struct bgp_table *table = NULL; | |
2665 | ||
2666 | prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd); | |
2667 | if (prn->info) | |
2668 | { | |
2669 | table = (struct bgp_table *)(prn->info); | |
2670 | ||
2671 | vnc_import_bgp_add_vnc_host_route_mode_resolve_nve( | |
2672 | bgp, | |
2673 | prd, | |
2674 | table, | |
2675 | p, | |
2676 | ri); | |
2677 | } | |
2678 | bgp_unlock_node(prn); | |
2679 | } | |
2680 | #endif | |
2681 | ||
718e3744 | 2682 | /* Process change. */ |
2683 | bgp_aggregate_increment (bgp, p, ri, afi, safi); | |
2684 | ||
2685 | bgp_process (bgp, rn, afi, safi); | |
2686 | bgp_unlock_node (rn); | |
558d1fec | 2687 | |
718e3744 | 2688 | return 0; |
a82478b9 | 2689 | } // End of implicit withdraw |
718e3744 | 2690 | |
2691 | /* Received Logging. */ | |
3f9c7369 | 2692 | if (bgp_debug_update(peer, p, NULL, 1)) |
718e3744 | 2693 | { |
16286195 DS |
2694 | if (!peer->rcvd_attr_printed) |
2695 | { | |
2696 | zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str); | |
2697 | peer->rcvd_attr_printed = 1; | |
2698 | } | |
2699 | ||
2ec1e66f | 2700 | bgp_info_addpath_rx_str(addpath_id, buf2); |
cd808e74 | 2701 | zlog_debug ("%s rcvd %s/%d%s", |
16286195 DS |
2702 | peer->host, |
2703 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
cd808e74 | 2704 | p->prefixlen, buf2); |
718e3744 | 2705 | } |
2706 | ||
718e3744 | 2707 | /* Make new BGP info. */ |
7c8ff89e | 2708 | new = info_make(type, sub_type, 0, peer, attr_new, rn); |
718e3744 | 2709 | |
2710 | /* Update MPLS tag. */ | |
2711 | if (safi == SAFI_MPLS_VPN) | |
fb982c25 | 2712 | memcpy ((bgp_info_extra_get (new))->tag, tag, 3); |
718e3744 | 2713 | |
2714 | /* Nexthop reachability check. */ | |
fc9a856f DS |
2715 | if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST) |
2716 | { | |
2717 | if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 && | |
907f92c8 DS |
2718 | ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK) |
2719 | && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK)) | |
fc9a856f DS |
2720 | connected = 1; |
2721 | else | |
2722 | connected = 0; | |
2723 | ||
75aead62 | 2724 | if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected)) |
1a392d46 | 2725 | bgp_info_set_flag (rn, new, BGP_INFO_VALID); |
718e3744 | 2726 | else |
fc9a856f DS |
2727 | { |
2728 | if (BGP_DEBUG(nht, NHT)) | |
2729 | { | |
2730 | char buf1[INET6_ADDRSTRLEN]; | |
2731 | inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN); | |
2732 | zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1); | |
2733 | } | |
2734 | bgp_info_unset_flag (rn, new, BGP_INFO_VALID); | |
2735 | } | |
718e3744 | 2736 | } |
2737 | else | |
1a392d46 | 2738 | bgp_info_set_flag (rn, new, BGP_INFO_VALID); |
718e3744 | 2739 | |
a82478b9 DS |
2740 | /* Addpath ID */ |
2741 | new->addpath_rx_id = addpath_id; | |
a82478b9 | 2742 | |
902212c3 | 2743 | /* Increment prefix */ |
718e3744 | 2744 | bgp_aggregate_increment (bgp, p, new, afi, safi); |
2745 | ||
2746 | /* Register new BGP information. */ | |
2747 | bgp_info_add (rn, new); | |
200df115 | 2748 | |
2749 | /* route_node_get lock */ | |
2750 | bgp_unlock_node (rn); | |
558d1fec | 2751 | |
65efcfce LB |
2752 | #if ENABLE_BGP_VNC |
2753 | if (safi == SAFI_MPLS_VPN) | |
2754 | { | |
2755 | struct bgp_node *prn = NULL; | |
2756 | struct bgp_table *table = NULL; | |
2757 | ||
2758 | prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd); | |
2759 | if (prn->info) | |
2760 | { | |
2761 | table = (struct bgp_table *)(prn->info); | |
2762 | ||
2763 | vnc_import_bgp_add_vnc_host_route_mode_resolve_nve( | |
2764 | bgp, | |
2765 | prd, | |
2766 | table, | |
2767 | p, | |
2768 | new); | |
2769 | } | |
2770 | bgp_unlock_node(prn); | |
2771 | } | |
2772 | #endif | |
2773 | ||
718e3744 | 2774 | /* If maximum prefix count is configured and current prefix |
2775 | count exeed it. */ | |
e0701b79 | 2776 | if (bgp_maximum_prefix_overflow (peer, afi, safi, 0)) |
2777 | return -1; | |
718e3744 | 2778 | |
2779 | /* Process change. */ | |
2780 | bgp_process (bgp, rn, afi, safi); | |
2781 | ||
2782 | return 0; | |
2783 | ||
2784 | /* This BGP update is filtered. Log the reason then update BGP | |
2785 | entry. */ | |
2786 | filtered: | |
3f9c7369 | 2787 | if (bgp_debug_update(peer, p, NULL, 1)) |
16286195 DS |
2788 | { |
2789 | if (!peer->rcvd_attr_printed) | |
2790 | { | |
2791 | zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str); | |
2792 | peer->rcvd_attr_printed = 1; | |
2793 | } | |
2794 | ||
2ec1e66f | 2795 | bgp_info_addpath_rx_str(addpath_id, buf2); |
cd808e74 | 2796 | zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s", |
16286195 DS |
2797 | peer->host, |
2798 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
cd808e74 | 2799 | p->prefixlen, buf2, reason); |
16286195 | 2800 | } |
718e3744 | 2801 | |
2802 | if (ri) | |
b40d939b | 2803 | bgp_rib_remove (rn, ri, peer, afi, safi); |
718e3744 | 2804 | |
2805 | bgp_unlock_node (rn); | |
558d1fec | 2806 | |
718e3744 | 2807 | return 0; |
2808 | } | |
2809 | ||
2810 | int | |
a82478b9 DS |
2811 | bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id, |
2812 | struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type, | |
2813 | struct prefix_rd *prd, u_char *tag) | |
718e3744 | 2814 | { |
2815 | struct bgp *bgp; | |
2816 | char buf[SU_ADDRSTRLEN]; | |
cd808e74 | 2817 | char buf2[30]; |
718e3744 | 2818 | struct bgp_node *rn; |
2819 | struct bgp_info *ri; | |
2820 | ||
2821 | bgp = peer->bgp; | |
2822 | ||
718e3744 | 2823 | /* Lookup node. */ |
fee0f4c6 | 2824 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd); |
718e3744 | 2825 | |
2826 | /* If peer is soft reconfiguration enabled. Record input packet for | |
6b87f736 DL |
2827 | * further calculation. |
2828 | * | |
2829 | * Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all | |
2830 | * routes that are filtered. This tanks out Quagga RS pretty badly due to | |
2831 | * the iteration over all RS clients. | |
2832 | * Since we need to remove the entry from adj_in anyway, do that first and | |
2833 | * if there was no entry, we don't need to do anything more. | |
2834 | */ | |
718e3744 | 2835 | if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG) |
2836 | && peer != bgp->peer_self) | |
6b87f736 DL |
2837 | if (!bgp_adj_in_unset (rn, peer, addpath_id)) |
2838 | { | |
2839 | if (bgp_debug_update (peer, p, NULL, 1)) | |
2840 | zlog_debug ("%s withdrawing route %s/%d " | |
2841 | "not in adj-in", peer->host, | |
2842 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
2843 | p->prefixlen); | |
2844 | bgp_unlock_node (rn); | |
2845 | return 0; | |
2846 | } | |
718e3744 | 2847 | |
2848 | /* Lookup withdrawn route. */ | |
2849 | for (ri = rn->info; ri; ri = ri->next) | |
a82478b9 DS |
2850 | if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type && |
2851 | ri->addpath_rx_id == addpath_id) | |
718e3744 | 2852 | break; |
2853 | ||
cd808e74 DS |
2854 | /* Logging. */ |
2855 | if (bgp_debug_update(peer, p, NULL, 1)) | |
2856 | { | |
2ec1e66f | 2857 | bgp_info_addpath_rx_str(addpath_id, buf2); |
cd808e74 DS |
2858 | zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn", |
2859 | peer->host, | |
2860 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
2861 | p->prefixlen, buf2); | |
2862 | } | |
2863 | ||
718e3744 | 2864 | /* Withdraw specified route from routing table. */ |
2865 | if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) | |
65efcfce | 2866 | bgp_rib_withdraw (rn, ri, peer, afi, safi, prd); |
3f9c7369 | 2867 | else if (bgp_debug_update(peer, p, NULL, 1)) |
16286195 DS |
2868 | zlog_debug ("%s Can't find the route %s/%d", peer->host, |
2869 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
2870 | p->prefixlen); | |
718e3744 | 2871 | |
2872 | /* Unlock bgp_node_get() lock. */ | |
2873 | bgp_unlock_node (rn); | |
2874 | ||
2875 | return 0; | |
2876 | } | |
6b0655a2 | 2877 | |
718e3744 | 2878 | void |
2879 | bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw) | |
2880 | { | |
3f9c7369 DS |
2881 | struct update_subgroup *subgrp; |
2882 | subgrp = peer_subgroup(peer, afi, safi); | |
2883 | subgroup_default_originate(subgrp, withdraw); | |
2884 | } | |
6182d65b | 2885 | |
718e3744 | 2886 | |
3f9c7369 DS |
2887 | /* |
2888 | * bgp_stop_announce_route_timer | |
2889 | */ | |
2890 | void | |
2891 | bgp_stop_announce_route_timer (struct peer_af *paf) | |
2892 | { | |
2893 | if (!paf->t_announce_route) | |
2894 | return; | |
718e3744 | 2895 | |
3f9c7369 | 2896 | THREAD_TIMER_OFF (paf->t_announce_route); |
718e3744 | 2897 | } |
6b0655a2 | 2898 | |
3f9c7369 DS |
2899 | /* |
2900 | * bgp_announce_route_timer_expired | |
2901 | * | |
2902 | * Callback that is invoked when the route announcement timer for a | |
2903 | * peer_af expires. | |
2904 | */ | |
2905 | static int | |
2906 | bgp_announce_route_timer_expired (struct thread *t) | |
718e3744 | 2907 | { |
3f9c7369 DS |
2908 | struct peer_af *paf; |
2909 | struct peer *peer; | |
558d1fec | 2910 | |
3f9c7369 DS |
2911 | paf = THREAD_ARG (t); |
2912 | peer = paf->peer; | |
718e3744 | 2913 | |
3f9c7369 DS |
2914 | assert (paf->t_announce_route); |
2915 | paf->t_announce_route = NULL; | |
558d1fec | 2916 | |
3f9c7369 DS |
2917 | if (peer->status != Established) |
2918 | return 0; | |
2919 | ||
2920 | if (!peer->afc_nego[paf->afi][paf->safi]) | |
2921 | return 0; | |
2922 | ||
2923 | peer_af_announce_route (paf, 1); | |
2924 | return 0; | |
718e3744 | 2925 | } |
2926 | ||
3f9c7369 DS |
2927 | /* |
2928 | * bgp_announce_route | |
2929 | * | |
2930 | * *Triggers* announcement of routes of a given AFI/SAFI to a peer. | |
2931 | */ | |
718e3744 | 2932 | void |
2933 | bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi) | |
2934 | { | |
3f9c7369 DS |
2935 | struct peer_af *paf; |
2936 | struct update_subgroup *subgrp; | |
718e3744 | 2937 | |
3f9c7369 DS |
2938 | paf = peer_af_find (peer, afi, safi); |
2939 | if (!paf) | |
718e3744 | 2940 | return; |
3f9c7369 | 2941 | subgrp = PAF_SUBGRP(paf); |
718e3744 | 2942 | |
3f9c7369 DS |
2943 | /* |
2944 | * Ignore if subgroup doesn't exist (implies AF is not negotiated) | |
2945 | * or a refresh has already been triggered. | |
2946 | */ | |
2947 | if (!subgrp || paf->t_announce_route) | |
718e3744 | 2948 | return; |
2949 | ||
d889623f | 2950 | /* |
3f9c7369 DS |
2951 | * Start a timer to stagger/delay the announce. This serves |
2952 | * two purposes - announcement can potentially be combined for | |
2953 | * multiple peers and the announcement doesn't happen in the | |
2954 | * vty context. | |
d889623f | 2955 | */ |
9229d914 | 2956 | THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route, |
3f9c7369 DS |
2957 | bgp_announce_route_timer_expired, paf, |
2958 | (subgrp->peer_count == 1) ? | |
2959 | BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS : | |
2960 | BGP_ANNOUNCE_ROUTE_DELAY_MS); | |
2961 | } | |
2962 | ||
2963 | /* | |
2964 | * Announce routes from all AF tables to a peer. | |
2965 | * | |
2966 | * This should ONLY be called when there is a need to refresh the | |
2967 | * routes to the peer based on a policy change for this peer alone | |
2968 | * or a route refresh request received from the peer. | |
2969 | * The operation will result in splitting the peer from its existing | |
2970 | * subgroups and putting it in new subgroups. | |
2971 | */ | |
718e3744 | 2972 | void |
2973 | bgp_announce_route_all (struct peer *peer) | |
2974 | { | |
2975 | afi_t afi; | |
2976 | safi_t safi; | |
2977 | ||
2978 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
2979 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) | |
2980 | bgp_announce_route (peer, afi, safi); | |
2981 | } | |
6b0655a2 | 2982 | |
fee0f4c6 | 2983 | static void |
718e3744 | 2984 | bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi, |
8692c506 | 2985 | struct bgp_table *table, struct prefix_rd *prd) |
718e3744 | 2986 | { |
2987 | int ret; | |
2988 | struct bgp_node *rn; | |
2989 | struct bgp_adj_in *ain; | |
2990 | ||
2991 | if (! table) | |
2992 | table = peer->bgp->rib[afi][safi]; | |
2993 | ||
2994 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
2995 | for (ain = rn->adj_in; ain; ain = ain->next) | |
2996 | { | |
2997 | if (ain->peer == peer) | |
2998 | { | |
8692c506 | 2999 | struct bgp_info *ri = rn->info; |
d53d8fda | 3000 | u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL; |
8692c506 | 3001 | |
43143c8f | 3002 | ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr, |
a82478b9 | 3003 | afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, |
d53d8fda | 3004 | prd, tag, 1); |
8692c506 | 3005 | |
718e3744 | 3006 | if (ret < 0) |
3007 | { | |
3008 | bgp_unlock_node (rn); | |
3009 | return; | |
3010 | } | |
718e3744 | 3011 | } |
3012 | } | |
3013 | } | |
3014 | ||
3015 | void | |
3016 | bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi) | |
3017 | { | |
3018 | struct bgp_node *rn; | |
3019 | struct bgp_table *table; | |
3020 | ||
3021 | if (peer->status != Established) | |
3022 | return; | |
3023 | ||
587ff0fd | 3024 | if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP)) |
8692c506 | 3025 | bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL); |
718e3744 | 3026 | else |
3027 | for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn; | |
3028 | rn = bgp_route_next (rn)) | |
3029 | if ((table = rn->info) != NULL) | |
8692c506 JBD |
3030 | { |
3031 | struct prefix_rd prd; | |
3032 | prd.family = AF_UNSPEC; | |
3033 | prd.prefixlen = 64; | |
3034 | memcpy(&prd.val, rn->p.u.val, 8); | |
3035 | ||
3036 | bgp_soft_reconfig_table (peer, afi, safi, table, &prd); | |
3037 | } | |
718e3744 | 3038 | } |
6b0655a2 | 3039 | |
228da428 CC |
3040 | |
3041 | struct bgp_clear_node_queue | |
3042 | { | |
3043 | struct bgp_node *rn; | |
228da428 CC |
3044 | }; |
3045 | ||
200df115 | 3046 | static wq_item_status |
0fb58d5d | 3047 | bgp_clear_route_node (struct work_queue *wq, void *data) |
200df115 | 3048 | { |
228da428 CC |
3049 | struct bgp_clear_node_queue *cnq = data; |
3050 | struct bgp_node *rn = cnq->rn; | |
64e580a7 | 3051 | struct peer *peer = wq->spec.data; |
718e3744 | 3052 | struct bgp_info *ri; |
67174041 AS |
3053 | afi_t afi = bgp_node_table (rn)->afi; |
3054 | safi_t safi = bgp_node_table (rn)->safi; | |
200df115 | 3055 | |
64e580a7 | 3056 | assert (rn && peer); |
200df115 | 3057 | |
43143c8f DS |
3058 | /* It is possible that we have multiple paths for a prefix from a peer |
3059 | * if that peer is using AddPath. | |
3060 | */ | |
64e580a7 | 3061 | for (ri = rn->info; ri; ri = ri->next) |
2a3d5731 | 3062 | if (ri->peer == peer) |
200df115 | 3063 | { |
3064 | /* graceful restart STALE flag set. */ | |
64e580a7 PJ |
3065 | if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT) |
3066 | && peer->nsf[afi][safi] | |
200df115 | 3067 | && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE) |
1a392d46 PJ |
3068 | && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE)) |
3069 | bgp_info_set_flag (rn, ri, BGP_INFO_STALE); | |
200df115 | 3070 | else |
64e580a7 | 3071 | bgp_rib_remove (rn, ri, peer, afi, safi); |
200df115 | 3072 | } |
200df115 | 3073 | return WQ_SUCCESS; |
3074 | } | |
3075 | ||
3076 | static void | |
0fb58d5d | 3077 | bgp_clear_node_queue_del (struct work_queue *wq, void *data) |
200df115 | 3078 | { |
228da428 CC |
3079 | struct bgp_clear_node_queue *cnq = data; |
3080 | struct bgp_node *rn = cnq->rn; | |
67174041 | 3081 | struct bgp_table *table = bgp_node_table (rn); |
64e580a7 PJ |
3082 | |
3083 | bgp_unlock_node (rn); | |
228da428 CC |
3084 | bgp_table_unlock (table); |
3085 | XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq); | |
200df115 | 3086 | } |
3087 | ||
3088 | static void | |
94f2b392 | 3089 | bgp_clear_node_complete (struct work_queue *wq) |
200df115 | 3090 | { |
64e580a7 PJ |
3091 | struct peer *peer = wq->spec.data; |
3092 | ||
3e0c78ef | 3093 | /* Tickle FSM to start moving again */ |
ca058a30 | 3094 | BGP_EVENT_ADD (peer, Clearing_Completed); |
228da428 CC |
3095 | |
3096 | peer_unlock (peer); /* bgp_clear_route */ | |
200df115 | 3097 | } |
3098 | ||
3099 | static void | |
64e580a7 | 3100 | bgp_clear_node_queue_init (struct peer *peer) |
200df115 | 3101 | { |
a2943657 | 3102 | char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")]; |
64e580a7 | 3103 | |
a2943657 | 3104 | snprintf (wname, sizeof(wname), "clear %s", peer->host); |
64e580a7 PJ |
3105 | #undef CLEAR_QUEUE_NAME_LEN |
3106 | ||
87d4a781 | 3107 | if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL) |
200df115 | 3108 | { |
3109 | zlog_err ("%s: Failed to allocate work queue", __func__); | |
3110 | exit (1); | |
3111 | } | |
64e580a7 PJ |
3112 | peer->clear_node_queue->spec.hold = 10; |
3113 | peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node; | |
3114 | peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del; | |
3115 | peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete; | |
3116 | peer->clear_node_queue->spec.max_retries = 0; | |
3117 | ||
3118 | /* we only 'lock' this peer reference when the queue is actually active */ | |
3119 | peer->clear_node_queue->spec.data = peer; | |
200df115 | 3120 | } |
718e3744 | 3121 | |
200df115 | 3122 | static void |
3123 | bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi, | |
2a3d5731 | 3124 | struct bgp_table *table) |
200df115 | 3125 | { |
200df115 | 3126 | struct bgp_node *rn; |
0c6262ed | 3127 | int force = bm->process_main_queue ? 0 : 1; |
f2c31acb | 3128 | |
718e3744 | 3129 | if (! table) |
2a3d5731 | 3130 | table = peer->bgp->rib[afi][safi]; |
64e580a7 | 3131 | |
6cf159b9 | 3132 | /* If still no table => afi/safi isn't configured at all or smth. */ |
3133 | if (! table) | |
3134 | return; | |
65ca75e0 PJ |
3135 | |
3136 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
3137 | { | |
0c6262ed | 3138 | struct bgp_info *ri, *next; |
f2c31acb | 3139 | struct bgp_adj_in *ain; |
43143c8f | 3140 | struct bgp_adj_in *ain_next; |
f2c31acb PJ |
3141 | |
3142 | /* XXX:TODO: This is suboptimal, every non-empty route_node is | |
3143 | * queued for every clearing peer, regardless of whether it is | |
3144 | * relevant to the peer at hand. | |
3145 | * | |
3146 | * Overview: There are 3 different indices which need to be | |
3147 | * scrubbed, potentially, when a peer is removed: | |
3148 | * | |
3149 | * 1 peer's routes visible via the RIB (ie accepted routes) | |
3150 | * 2 peer's routes visible by the (optional) peer's adj-in index | |
3151 | * 3 other routes visible by the peer's adj-out index | |
3152 | * | |
3153 | * 3 there is no hurry in scrubbing, once the struct peer is | |
3154 | * removed from bgp->peer, we could just GC such deleted peer's | |
3155 | * adj-outs at our leisure. | |
3156 | * | |
3157 | * 1 and 2 must be 'scrubbed' in some way, at least made | |
3158 | * invisible via RIB index before peer session is allowed to be | |
3159 | * brought back up. So one needs to know when such a 'search' is | |
3160 | * complete. | |
3161 | * | |
3162 | * Ideally: | |
3163 | * | |
3164 | * - there'd be a single global queue or a single RIB walker | |
3165 | * - rather than tracking which route_nodes still need to be | |
3166 | * examined on a peer basis, we'd track which peers still | |
3167 | * aren't cleared | |
3168 | * | |
3169 | * Given that our per-peer prefix-counts now should be reliable, | |
3170 | * this may actually be achievable. It doesn't seem to be a huge | |
3171 | * problem at this time, | |
43143c8f DS |
3172 | * |
3173 | * It is possible that we have multiple paths for a prefix from a peer | |
3174 | * if that peer is using AddPath. | |
f2c31acb | 3175 | */ |
43143c8f DS |
3176 | ain = rn->adj_in; |
3177 | while (ain) | |
3178 | { | |
3179 | ain_next = ain->next; | |
3180 | ||
2a3d5731 | 3181 | if (ain->peer == peer) |
43143c8f DS |
3182 | { |
3183 | bgp_adj_in_remove (rn, ain); | |
3184 | bgp_unlock_node (rn); | |
3185 | } | |
3186 | ||
3187 | ain = ain_next; | |
3188 | } | |
3f9c7369 | 3189 | |
0c6262ed RW |
3190 | for (ri = rn->info; ri; ri = next) |
3191 | { | |
3192 | next = ri->next; | |
3193 | if (ri->peer != peer) | |
3194 | continue; | |
3195 | ||
3196 | if (force) | |
3197 | bgp_info_reap (rn, ri); | |
3198 | else | |
3199 | { | |
3200 | struct bgp_clear_node_queue *cnq; | |
3201 | ||
3202 | /* both unlocked in bgp_clear_node_queue_del */ | |
3203 | bgp_table_lock (bgp_node_table (rn)); | |
3204 | bgp_lock_node (rn); | |
3205 | cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE, | |
3206 | sizeof (struct bgp_clear_node_queue)); | |
3207 | cnq->rn = rn; | |
3208 | work_queue_add (peer->clear_node_queue, cnq); | |
3209 | break; | |
3210 | } | |
3211 | } | |
65ca75e0 PJ |
3212 | } |
3213 | return; | |
3214 | } | |
3215 | ||
3216 | void | |
2a3d5731 | 3217 | bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi) |
65ca75e0 PJ |
3218 | { |
3219 | struct bgp_node *rn; | |
3220 | struct bgp_table *table; | |
6cf159b9 | 3221 | |
64e580a7 PJ |
3222 | if (peer->clear_node_queue == NULL) |
3223 | bgp_clear_node_queue_init (peer); | |
200df115 | 3224 | |
ca058a30 PJ |
3225 | /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to |
3226 | * Idle until it receives a Clearing_Completed event. This protects | |
3227 | * against peers which flap faster than we can we clear, which could | |
3228 | * lead to: | |
64e580a7 PJ |
3229 | * |
3230 | * a) race with routes from the new session being installed before | |
3231 | * clear_route_node visits the node (to delete the route of that | |
3232 | * peer) | |
3233 | * b) resource exhaustion, clear_route_node likely leads to an entry | |
3234 | * on the process_main queue. Fast-flapping could cause that queue | |
3235 | * to grow and grow. | |
200df115 | 3236 | */ |
dc83d712 DS |
3237 | |
3238 | /* lock peer in assumption that clear-node-queue will get nodes; if so, | |
3239 | * the unlock will happen upon work-queue completion; other wise, the | |
3240 | * unlock happens at the end of this function. | |
3241 | */ | |
ca058a30 | 3242 | if (!peer->clear_node_queue->thread) |
dc83d712 | 3243 | peer_lock (peer); |
fee0f4c6 | 3244 | |
587ff0fd | 3245 | if (safi != SAFI_MPLS_VPN && safi != SAFI_ENCAP) |
2a3d5731 DW |
3246 | bgp_clear_route_table (peer, afi, safi, NULL); |
3247 | else | |
3248 | for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn; | |
3249 | rn = bgp_route_next (rn)) | |
3250 | if ((table = rn->info) != NULL) | |
3251 | bgp_clear_route_table (peer, afi, safi, table); | |
dc83d712 DS |
3252 | |
3253 | /* unlock if no nodes got added to the clear-node-queue. */ | |
65ca75e0 | 3254 | if (!peer->clear_node_queue->thread) |
dc83d712 DS |
3255 | peer_unlock (peer); |
3256 | ||
718e3744 | 3257 | } |
3258 | ||
3259 | void | |
3260 | bgp_clear_route_all (struct peer *peer) | |
3261 | { | |
3262 | afi_t afi; | |
3263 | safi_t safi; | |
3264 | ||
3265 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
3266 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) | |
2a3d5731 | 3267 | bgp_clear_route (peer, afi, safi); |
65efcfce LB |
3268 | |
3269 | #if ENABLE_BGP_VNC | |
3270 | rfapiProcessPeerDown(peer); | |
3271 | #endif | |
718e3744 | 3272 | } |
3273 | ||
3274 | void | |
3275 | bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi) | |
3276 | { | |
3277 | struct bgp_table *table; | |
3278 | struct bgp_node *rn; | |
3279 | struct bgp_adj_in *ain; | |
43143c8f | 3280 | struct bgp_adj_in *ain_next; |
718e3744 | 3281 | |
3282 | table = peer->bgp->rib[afi][safi]; | |
3283 | ||
43143c8f DS |
3284 | /* It is possible that we have multiple paths for a prefix from a peer |
3285 | * if that peer is using AddPath. | |
3286 | */ | |
718e3744 | 3287 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) |
43143c8f DS |
3288 | { |
3289 | ain = rn->adj_in; | |
3290 | ||
3291 | while (ain) | |
3292 | { | |
3293 | ain_next = ain->next; | |
3294 | ||
3295 | if (ain->peer == peer) | |
3296 | { | |
3297 | bgp_adj_in_remove (rn, ain); | |
3298 | bgp_unlock_node (rn); | |
3299 | } | |
3300 | ||
3301 | ain = ain_next; | |
3302 | } | |
3303 | } | |
718e3744 | 3304 | } |
93406d87 | 3305 | |
3306 | void | |
3307 | bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi) | |
3308 | { | |
3309 | struct bgp_node *rn; | |
3310 | struct bgp_info *ri; | |
3311 | struct bgp_table *table; | |
3312 | ||
3313 | table = peer->bgp->rib[afi][safi]; | |
3314 | ||
3315 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
3316 | { | |
3317 | for (ri = rn->info; ri; ri = ri->next) | |
3318 | if (ri->peer == peer) | |
3319 | { | |
3320 | if (CHECK_FLAG (ri->flags, BGP_INFO_STALE)) | |
3321 | bgp_rib_remove (rn, ri, peer, afi, safi); | |
3322 | break; | |
3323 | } | |
3324 | } | |
3325 | } | |
6b0655a2 | 3326 | |
bb86c601 LB |
3327 | static void |
3328 | bgp_cleanup_table(struct bgp_table *table, safi_t safi) | |
3329 | { | |
3330 | struct bgp_node *rn; | |
3331 | struct bgp_info *ri; | |
3332 | struct bgp_info *next; | |
3333 | ||
3334 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
3335 | for (ri = rn->info; ri; ri = next) | |
3336 | { | |
3337 | next = ri->next; | |
3338 | if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) | |
3339 | && ri->type == ZEBRA_ROUTE_BGP | |
3340 | && (ri->sub_type == BGP_ROUTE_NORMAL || | |
3341 | ri->sub_type == BGP_ROUTE_AGGREGATE)) | |
65efcfce LB |
3342 | { |
3343 | #if ENABLE_BGP_VNC | |
3344 | if (table->owner && table->owner->bgp) | |
3345 | vnc_import_bgp_del_route(table->owner->bgp, &rn->p, ri); | |
3346 | #endif | |
3347 | bgp_zebra_withdraw (&rn->p, ri, safi); | |
0c6262ed | 3348 | bgp_info_reap (rn, ri); |
65efcfce | 3349 | } |
bb86c601 LB |
3350 | } |
3351 | } | |
3352 | ||
718e3744 | 3353 | /* Delete all kernel routes. */ |
3354 | void | |
0c6262ed | 3355 | bgp_cleanup_routes (struct bgp *bgp) |
718e3744 | 3356 | { |
bb86c601 | 3357 | afi_t afi; |
718e3744 | 3358 | |
0c6262ed | 3359 | for (afi = AFI_IP; afi < AFI_MAX; ++afi) |
718e3744 | 3360 | { |
0c6262ed | 3361 | struct bgp_node *rn; |
bb86c601 | 3362 | |
0c6262ed | 3363 | bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST); |
bb86c601 | 3364 | |
0c6262ed RW |
3365 | /* |
3366 | * VPN and ENCAP tables are two-level (RD is top level) | |
3367 | */ | |
3368 | for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn; | |
3369 | rn = bgp_route_next (rn)) | |
3370 | { | |
3371 | if (rn->info) | |
587ff0fd | 3372 | { |
0c6262ed RW |
3373 | bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN); |
3374 | bgp_table_finish ((struct bgp_table **)&(rn->info)); | |
3375 | rn->info = NULL; | |
3376 | bgp_unlock_node(rn); | |
587ff0fd | 3377 | } |
0c6262ed | 3378 | } |
587ff0fd | 3379 | |
0c6262ed RW |
3380 | for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn; |
3381 | rn = bgp_route_next (rn)) | |
3382 | { | |
3383 | if (rn->info) | |
587ff0fd | 3384 | { |
0c6262ed RW |
3385 | bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP); |
3386 | bgp_table_finish ((struct bgp_table **)&(rn->info)); | |
3387 | rn->info = NULL; | |
3388 | bgp_unlock_node(rn); | |
587ff0fd | 3389 | } |
bb86c601 | 3390 | } |
718e3744 | 3391 | } |
3392 | } | |
3393 | ||
3394 | void | |
66e5cd87 | 3395 | bgp_reset (void) |
718e3744 | 3396 | { |
3397 | vty_reset (); | |
3398 | bgp_zclient_reset (); | |
3399 | access_list_reset (); | |
3400 | prefix_list_reset (); | |
3401 | } | |
6b0655a2 | 3402 | |
adbac85e DW |
3403 | static int |
3404 | bgp_addpath_encode_rx (struct peer *peer, afi_t afi, safi_t safi) | |
3405 | { | |
3406 | return (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) && | |
3407 | CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV)); | |
3408 | } | |
3409 | ||
718e3744 | 3410 | /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr |
3411 | value. */ | |
3412 | int | |
96e52474 PJ |
3413 | bgp_nlri_parse_ip (struct peer *peer, struct attr *attr, |
3414 | struct bgp_nlri *packet) | |
718e3744 | 3415 | { |
3416 | u_char *pnt; | |
3417 | u_char *lim; | |
3418 | struct prefix p; | |
3419 | int psize; | |
3420 | int ret; | |
a82478b9 DS |
3421 | afi_t afi; |
3422 | safi_t safi; | |
adbac85e | 3423 | int addpath_encoded; |
a82478b9 | 3424 | u_int32_t addpath_id; |
718e3744 | 3425 | |
3426 | /* Check peer status. */ | |
3427 | if (peer->status != Established) | |
3428 | return 0; | |
3429 | ||
3430 | pnt = packet->nlri; | |
3431 | lim = pnt + packet->length; | |
a82478b9 DS |
3432 | afi = packet->afi; |
3433 | safi = packet->safi; | |
3434 | addpath_id = 0; | |
adbac85e | 3435 | addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi); |
718e3744 | 3436 | |
ebd12e62 PJ |
3437 | /* RFC4771 6.3 The NLRI field in the UPDATE message is checked for |
3438 | syntactic validity. If the field is syntactically incorrect, | |
3439 | then the Error Subcode is set to Invalid Network Field. */ | |
718e3744 | 3440 | for (; pnt < lim; pnt += psize) |
3441 | { | |
3442 | /* Clear prefix structure. */ | |
3443 | memset (&p, 0, sizeof (struct prefix)); | |
3444 | ||
a82478b9 DS |
3445 | if (addpath_encoded) |
3446 | { | |
cd808e74 DS |
3447 | |
3448 | /* When packet overflow occurs return immediately. */ | |
3449 | if (pnt + BGP_ADDPATH_ID_LEN > lim) | |
3450 | return -1; | |
3451 | ||
a82478b9 DS |
3452 | addpath_id = ntohl(*((uint32_t*) pnt)); |
3453 | pnt += BGP_ADDPATH_ID_LEN; | |
3454 | } | |
3455 | ||
718e3744 | 3456 | /* Fetch prefix length. */ |
3457 | p.prefixlen = *pnt++; | |
ebd12e62 | 3458 | /* afi/safi validity already verified by caller, bgp_update_receive */ |
a82478b9 | 3459 | p.family = afi2family (afi); |
ebd12e62 PJ |
3460 | |
3461 | /* Prefix length check. */ | |
3462 | if (p.prefixlen > prefix_blen (&p) * 8) | |
3463 | { | |
3464 | zlog_err("%s [Error] Update packet error (wrong perfix length %d for afi %u)", | |
3465 | peer->host, p.prefixlen, packet->afi); | |
3466 | return -1; | |
3467 | } | |
718e3744 | 3468 | |
3469 | /* Packet size overflow check. */ | |
3470 | psize = PSIZE (p.prefixlen); | |
3471 | ||
3472 | /* When packet overflow occur return immediately. */ | |
3473 | if (pnt + psize > lim) | |
ebd12e62 PJ |
3474 | { |
3475 | zlog_err("%s [Error] Update packet error (prefix length %d overflows packet)", | |
3476 | peer->host, p.prefixlen); | |
3477 | return -1; | |
3478 | } | |
3479 | ||
3480 | /* Defensive coding, double-check the psize fits in a struct prefix */ | |
3481 | if (psize > (ssize_t) sizeof(p.u)) | |
3482 | { | |
3483 | zlog_err("%s [Error] Update packet error (prefix length %d too large for prefix storage %zu)", | |
3484 | peer->host, p.prefixlen, sizeof(p.u)); | |
3485 | return -1; | |
3486 | } | |
718e3744 | 3487 | |
3488 | /* Fetch prefix from NLRI packet. */ | |
3489 | memcpy (&p.u.prefix, pnt, psize); | |
3490 | ||
3491 | /* Check address. */ | |
a82478b9 | 3492 | if (afi == AFI_IP && safi == SAFI_UNICAST) |
718e3744 | 3493 | { |
3494 | if (IN_CLASSD (ntohl (p.u.prefix4.s_addr))) | |
3495 | { | |
ebd12e62 PJ |
3496 | /* From RFC4271 Section 6.3: |
3497 | * | |
3498 | * If a prefix in the NLRI field is semantically incorrect | |
3499 | * (e.g., an unexpected multicast IP address), an error SHOULD | |
3500 | * be logged locally, and the prefix SHOULD be ignored. | |
3501 | */ | |
3502 | zlog_err ("%s: IPv4 unicast NLRI is multicast address %s, ignoring", | |
3503 | peer->host, inet_ntoa (p.u.prefix4)); | |
3504 | continue; | |
718e3744 | 3505 | } |
3506 | } | |
3507 | ||
3508 | #ifdef HAVE_IPV6 | |
3509 | /* Check address. */ | |
a82478b9 | 3510 | if (afi == AFI_IP6 && safi == SAFI_UNICAST) |
718e3744 | 3511 | { |
3512 | if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6)) | |
3513 | { | |
3514 | char buf[BUFSIZ]; | |
3515 | ||
ebd12e62 PJ |
3516 | zlog_err ("%s: IPv6 unicast NLRI is link-local address %s, ignoring", |
3517 | peer->host, inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ)); | |
3518 | ||
3519 | continue; | |
3520 | } | |
3521 | if (IN6_IS_ADDR_MULTICAST (&p.u.prefix6)) | |
3522 | { | |
3523 | char buf[BUFSIZ]; | |
3524 | ||
3525 | zlog_err ("%s: IPv6 unicast NLRI is multicast address %s, ignoring", | |
3526 | peer->host, inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ)); | |
718e3744 | 3527 | |
3528 | continue; | |
3529 | } | |
3530 | } | |
3531 | #endif /* HAVE_IPV6 */ | |
3532 | ||
3533 | /* Normal process. */ | |
3534 | if (attr) | |
a82478b9 | 3535 | ret = bgp_update (peer, &p, addpath_id, attr, afi, safi, |
718e3744 | 3536 | ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0); |
3537 | else | |
a82478b9 | 3538 | ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi, |
718e3744 | 3539 | ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL); |
3540 | ||
3541 | /* Address family configuration mismatch or maximum-prefix count | |
3542 | overflow. */ | |
3543 | if (ret < 0) | |
3544 | return -1; | |
3545 | } | |
3546 | ||
3547 | /* Packet length consistency check. */ | |
3548 | if (pnt != lim) | |
718e3744 | 3549 | { |
ebd12e62 PJ |
3550 | zlog_err ("%s [Error] Update packet error (prefix length mismatch with total length)", |
3551 | peer->host); | |
718e3744 | 3552 | return -1; |
3553 | } | |
6b0655a2 | 3554 | |
ebd12e62 | 3555 | return 0; |
48a5452b PJ |
3556 | } |
3557 | ||
94f2b392 | 3558 | static struct bgp_static * |
66e5cd87 | 3559 | bgp_static_new (void) |
718e3744 | 3560 | { |
393deb9b | 3561 | return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static)); |
718e3744 | 3562 | } |
3563 | ||
94f2b392 | 3564 | static void |
718e3744 | 3565 | bgp_static_free (struct bgp_static *bgp_static) |
3566 | { | |
3567 | if (bgp_static->rmap.name) | |
6e919709 | 3568 | XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name); |
718e3744 | 3569 | XFREE (MTYPE_BGP_STATIC, bgp_static); |
3570 | } | |
3571 | ||
94f2b392 | 3572 | static void |
2a3d5731 DW |
3573 | bgp_static_update_main (struct bgp *bgp, struct prefix *p, |
3574 | struct bgp_static *bgp_static, afi_t afi, safi_t safi) | |
fee0f4c6 | 3575 | { |
3576 | struct bgp_node *rn; | |
3577 | struct bgp_info *ri; | |
2a3d5731 DW |
3578 | struct bgp_info *new; |
3579 | struct bgp_info info; | |
3580 | struct attr attr; | |
3581 | struct attr *attr_new; | |
3582 | int ret; | |
65efcfce LB |
3583 | #if ENABLE_BGP_VNC |
3584 | int vnc_implicit_withdraw = 0; | |
3585 | #endif | |
fee0f4c6 | 3586 | |
2a3d5731 DW |
3587 | assert (bgp_static); |
3588 | if (!bgp_static) | |
3589 | return; | |
dd8103a9 | 3590 | |
fee0f4c6 | 3591 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL); |
718e3744 | 3592 | |
3593 | bgp_attr_default_set (&attr, BGP_ORIGIN_IGP); | |
dd8103a9 PJ |
3594 | |
3595 | attr.nexthop = bgp_static->igpnexthop; | |
3596 | attr.med = bgp_static->igpmetric; | |
3597 | attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC); | |
718e3744 | 3598 | |
41367172 PJ |
3599 | if (bgp_static->atomic) |
3600 | attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE); | |
3601 | ||
718e3744 | 3602 | /* Apply route-map. */ |
3603 | if (bgp_static->rmap.name) | |
3604 | { | |
fb982c25 | 3605 | struct attr attr_tmp = attr; |
718e3744 | 3606 | info.peer = bgp->peer_self; |
286e1e71 | 3607 | info.attr = &attr_tmp; |
718e3744 | 3608 | |
fee0f4c6 | 3609 | SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK); |
3610 | ||
718e3744 | 3611 | ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info); |
286e1e71 | 3612 | |
fee0f4c6 | 3613 | bgp->peer_self->rmap_type = 0; |
3614 | ||
718e3744 | 3615 | if (ret == RMAP_DENYMATCH) |
3616 | { | |
3617 | /* Free uninterned attribute. */ | |
286e1e71 | 3618 | bgp_attr_flush (&attr_tmp); |
718e3744 | 3619 | |
3620 | /* Unintern original. */ | |
f6f434b2 | 3621 | aspath_unintern (&attr.aspath); |
fb982c25 | 3622 | bgp_attr_extra_free (&attr); |
718e3744 | 3623 | bgp_static_withdraw (bgp, p, afi, safi); |
3624 | return; | |
3625 | } | |
286e1e71 | 3626 | attr_new = bgp_attr_intern (&attr_tmp); |
718e3744 | 3627 | } |
286e1e71 | 3628 | else |
3629 | attr_new = bgp_attr_intern (&attr); | |
718e3744 | 3630 | |
3631 | for (ri = rn->info; ri; ri = ri->next) | |
3632 | if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP | |
3633 | && ri->sub_type == BGP_ROUTE_STATIC) | |
3634 | break; | |
3635 | ||
3636 | if (ri) | |
3637 | { | |
8d45210e | 3638 | if (attrhash_cmp (ri->attr, attr_new) && |
078430f6 DS |
3639 | !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) && |
3640 | !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS)) | |
718e3744 | 3641 | { |
3642 | bgp_unlock_node (rn); | |
f6f434b2 PJ |
3643 | bgp_attr_unintern (&attr_new); |
3644 | aspath_unintern (&attr.aspath); | |
fb982c25 | 3645 | bgp_attr_extra_free (&attr); |
718e3744 | 3646 | return; |
3647 | } | |
3648 | else | |
3649 | { | |
3650 | /* The attribute is changed. */ | |
1a392d46 | 3651 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
718e3744 | 3652 | |
3653 | /* Rewrite BGP route information. */ | |
8d45210e AS |
3654 | if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)) |
3655 | bgp_info_restore(rn, ri); | |
3656 | else | |
3657 | bgp_aggregate_decrement (bgp, p, ri, afi, safi); | |
65efcfce LB |
3658 | #if ENABLE_BGP_VNC |
3659 | if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) | |
3660 | { | |
3661 | if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) | |
3662 | { | |
3663 | /* | |
3664 | * Implicit withdraw case. | |
3665 | * We have to do this before ri is changed | |
3666 | */ | |
3667 | ++vnc_implicit_withdraw; | |
3668 | vnc_import_bgp_del_route(bgp, p, ri); | |
3669 | vnc_import_bgp_exterior_del_route(bgp, p, ri); | |
3670 | } | |
3671 | } | |
3672 | #endif | |
f6f434b2 | 3673 | bgp_attr_unintern (&ri->attr); |
718e3744 | 3674 | ri->attr = attr_new; |
65957886 | 3675 | ri->uptime = bgp_clock (); |
65efcfce LB |
3676 | #if ENABLE_BGP_VNC |
3677 | if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) | |
3678 | { | |
3679 | if (vnc_implicit_withdraw) | |
3680 | { | |
3681 | vnc_import_bgp_add_route(bgp, p, ri); | |
3682 | vnc_import_bgp_exterior_add_route(bgp, p, ri); | |
3683 | } | |
3684 | } | |
3685 | #endif | |
718e3744 | 3686 | |
fc9a856f DS |
3687 | /* Nexthop reachability check. */ |
3688 | if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK)) | |
3689 | { | |
75aead62 | 3690 | if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0)) |
fc9a856f DS |
3691 | bgp_info_set_flag (rn, ri, BGP_INFO_VALID); |
3692 | else | |
3693 | { | |
3694 | if (BGP_DEBUG(nht, NHT)) | |
3695 | { | |
3696 | char buf1[INET6_ADDRSTRLEN]; | |
078430f6 DS |
3697 | inet_ntop(p->family, &p->u.prefix, buf1, |
3698 | INET6_ADDRSTRLEN); | |
3699 | zlog_debug("%s(%s): Route not in table, not advertising", | |
3700 | __FUNCTION__, buf1); | |
fc9a856f DS |
3701 | } |
3702 | bgp_info_unset_flag (rn, ri, BGP_INFO_VALID); | |
3703 | } | |
3704 | } | |
078430f6 DS |
3705 | else |
3706 | { | |
3707 | /* Delete the NHT structure if any, if we're toggling between | |
3708 | * enabling/disabling import check. We deregister the route | |
3709 | * from NHT to avoid overloading NHT and the process interaction | |
3710 | */ | |
3711 | bgp_unlink_nexthop(ri); | |
3712 | bgp_info_set_flag (rn, ri, BGP_INFO_VALID); | |
3713 | } | |
718e3744 | 3714 | /* Process change. */ |
3715 | bgp_aggregate_increment (bgp, p, ri, afi, safi); | |
3716 | bgp_process (bgp, rn, afi, safi); | |
3717 | bgp_unlock_node (rn); | |
f6f434b2 | 3718 | aspath_unintern (&attr.aspath); |
fb982c25 | 3719 | bgp_attr_extra_free (&attr); |
718e3744 | 3720 | return; |
3721 | } | |
3722 | } | |
3723 | ||
3724 | /* Make new BGP info. */ | |
7c8ff89e | 3725 | new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new, |
fb018d25 | 3726 | rn); |
fc9a856f DS |
3727 | /* Nexthop reachability check. */ |
3728 | if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK)) | |
3729 | { | |
75aead62 | 3730 | if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0)) |
fc9a856f DS |
3731 | bgp_info_set_flag (rn, new, BGP_INFO_VALID); |
3732 | else | |
3733 | { | |
3734 | if (BGP_DEBUG(nht, NHT)) | |
3735 | { | |
3736 | char buf1[INET6_ADDRSTRLEN]; | |
078430f6 | 3737 | inet_ntop(p->family, &p->u.prefix, buf1, |
fc9a856f | 3738 | INET6_ADDRSTRLEN); |
078430f6 DS |
3739 | zlog_debug("%s(%s): Route not in table, not advertising", |
3740 | __FUNCTION__, buf1); | |
fc9a856f DS |
3741 | } |
3742 | bgp_info_unset_flag (rn, new, BGP_INFO_VALID); | |
3743 | } | |
3744 | } | |
3745 | else | |
078430f6 DS |
3746 | { |
3747 | /* Delete the NHT structure if any, if we're toggling between | |
3748 | * enabling/disabling import check. We deregister the route | |
3749 | * from NHT to avoid overloading NHT and the process interaction | |
3750 | */ | |
3751 | bgp_unlink_nexthop(new); | |
3752 | ||
3753 | bgp_info_set_flag (rn, new, BGP_INFO_VALID); | |
3754 | } | |
718e3744 | 3755 | |
3756 | /* Aggregate address increment. */ | |
3757 | bgp_aggregate_increment (bgp, p, new, afi, safi); | |
3758 | ||
3759 | /* Register new BGP information. */ | |
3760 | bgp_info_add (rn, new); | |
200df115 | 3761 | |
3762 | /* route_node_get lock */ | |
3763 | bgp_unlock_node (rn); | |
3764 | ||
718e3744 | 3765 | /* Process change. */ |
3766 | bgp_process (bgp, rn, afi, safi); | |
3767 | ||
3768 | /* Unintern original. */ | |
f6f434b2 | 3769 | aspath_unintern (&attr.aspath); |
fb982c25 | 3770 | bgp_attr_extra_free (&attr); |
718e3744 | 3771 | } |
3772 | ||
fee0f4c6 | 3773 | void |
3774 | bgp_static_update (struct bgp *bgp, struct prefix *p, | |
3775 | struct bgp_static *bgp_static, afi_t afi, safi_t safi) | |
3776 | { | |
fee0f4c6 | 3777 | bgp_static_update_main (bgp, p, bgp_static, afi, safi); |
fee0f4c6 | 3778 | } |
3779 | ||
718e3744 | 3780 | void |
3781 | bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi, | |
3782 | safi_t safi) | |
3783 | { | |
3784 | struct bgp_node *rn; | |
3785 | struct bgp_info *ri; | |
3786 | ||
fee0f4c6 | 3787 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL); |
718e3744 | 3788 | |
3789 | /* Check selected route and self inserted route. */ | |
3790 | for (ri = rn->info; ri; ri = ri->next) | |
3791 | if (ri->peer == bgp->peer_self | |
3792 | && ri->type == ZEBRA_ROUTE_BGP | |
3793 | && ri->sub_type == BGP_ROUTE_STATIC) | |
3794 | break; | |
3795 | ||
3796 | /* Withdraw static BGP route from routing table. */ | |
3797 | if (ri) | |
3798 | { | |
3799 | bgp_aggregate_decrement (bgp, p, ri, afi, safi); | |
fc9a856f | 3800 | bgp_unlink_nexthop(ri); |
718e3744 | 3801 | bgp_info_delete (rn, ri); |
1a392d46 | 3802 | bgp_process (bgp, rn, afi, safi); |
718e3744 | 3803 | } |
3804 | ||
3805 | /* Unlock bgp_node_lookup. */ | |
3806 | bgp_unlock_node (rn); | |
3807 | } | |
3808 | ||
137446f9 LB |
3809 | /* |
3810 | * Used for SAFI_MPLS_VPN and SAFI_ENCAP | |
3811 | */ | |
94f2b392 | 3812 | static void |
137446f9 LB |
3813 | bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi, |
3814 | safi_t safi, struct prefix_rd *prd, u_char *tag) | |
718e3744 | 3815 | { |
3816 | struct bgp_node *rn; | |
3817 | struct bgp_info *ri; | |
3818 | ||
fee0f4c6 | 3819 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd); |
718e3744 | 3820 | |
3821 | /* Check selected route and self inserted route. */ | |
3822 | for (ri = rn->info; ri; ri = ri->next) | |
3823 | if (ri->peer == bgp->peer_self | |
3824 | && ri->type == ZEBRA_ROUTE_BGP | |
3825 | && ri->sub_type == BGP_ROUTE_STATIC) | |
3826 | break; | |
3827 | ||
3828 | /* Withdraw static BGP route from routing table. */ | |
3829 | if (ri) | |
3830 | { | |
65efcfce LB |
3831 | #if ENABLE_BGP_VNC |
3832 | rfapiProcessWithdraw( | |
3833 | ri->peer, | |
3834 | NULL, | |
3835 | p, | |
3836 | prd, | |
3837 | ri->attr, | |
3838 | afi, | |
3839 | safi, | |
3840 | ri->type, | |
3841 | 1); /* Kill, since it is an administrative change */ | |
3842 | #endif | |
718e3744 | 3843 | bgp_aggregate_decrement (bgp, p, ri, afi, safi); |
718e3744 | 3844 | bgp_info_delete (rn, ri); |
1a392d46 | 3845 | bgp_process (bgp, rn, afi, safi); |
718e3744 | 3846 | } |
3847 | ||
3848 | /* Unlock bgp_node_lookup. */ | |
3849 | bgp_unlock_node (rn); | |
3850 | } | |
3851 | ||
137446f9 LB |
3852 | static void |
3853 | bgp_static_update_safi (struct bgp *bgp, struct prefix *p, | |
3854 | struct bgp_static *bgp_static, afi_t afi, safi_t safi) | |
3855 | { | |
3856 | struct bgp_node *rn; | |
3857 | struct bgp_info *new; | |
3858 | struct attr *attr_new; | |
3859 | struct attr attr = { 0 }; | |
3860 | struct bgp_info *ri; | |
65efcfce LB |
3861 | #if ENABLE_BGP_VNC |
3862 | u_int32_t label = 0; | |
3863 | #endif | |
137446f9 LB |
3864 | |
3865 | assert (bgp_static); | |
3866 | ||
3867 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd); | |
3868 | ||
3869 | bgp_attr_default_set (&attr, BGP_ORIGIN_IGP); | |
3870 | ||
3871 | attr.nexthop = bgp_static->igpnexthop; | |
3872 | attr.med = bgp_static->igpmetric; | |
3873 | attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC); | |
3874 | ||
3875 | /* Apply route-map. */ | |
3876 | if (bgp_static->rmap.name) | |
3877 | { | |
3878 | struct attr attr_tmp = attr; | |
3879 | struct bgp_info info; | |
3880 | int ret; | |
3881 | ||
3882 | info.peer = bgp->peer_self; | |
3883 | info.attr = &attr_tmp; | |
3884 | ||
3885 | SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK); | |
3886 | ||
3887 | ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info); | |
3888 | ||
3889 | bgp->peer_self->rmap_type = 0; | |
3890 | ||
3891 | if (ret == RMAP_DENYMATCH) | |
3892 | { | |
3893 | /* Free uninterned attribute. */ | |
3894 | bgp_attr_flush (&attr_tmp); | |
3895 | ||
3896 | /* Unintern original. */ | |
3897 | aspath_unintern (&attr.aspath); | |
3898 | bgp_attr_extra_free (&attr); | |
3899 | bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd, | |
3900 | bgp_static->tag); | |
3901 | return; | |
3902 | } | |
3903 | ||
3904 | attr_new = bgp_attr_intern (&attr_tmp); | |
3905 | } | |
3906 | else | |
3907 | { | |
3908 | attr_new = bgp_attr_intern (&attr); | |
3909 | } | |
3910 | ||
3911 | for (ri = rn->info; ri; ri = ri->next) | |
3912 | if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP | |
3913 | && ri->sub_type == BGP_ROUTE_STATIC) | |
3914 | break; | |
3915 | ||
3916 | if (ri) | |
3917 | { | |
3918 | if (attrhash_cmp (ri->attr, attr_new) && | |
3919 | !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)) | |
3920 | { | |
3921 | bgp_unlock_node (rn); | |
3922 | bgp_attr_unintern (&attr_new); | |
3923 | aspath_unintern (&attr.aspath); | |
3924 | bgp_attr_extra_free (&attr); | |
3925 | return; | |
3926 | } | |
3927 | else | |
3928 | { | |
3929 | /* The attribute is changed. */ | |
3930 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); | |
3931 | ||
3932 | /* Rewrite BGP route information. */ | |
3933 | if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)) | |
3934 | bgp_info_restore(rn, ri); | |
3935 | else | |
3936 | bgp_aggregate_decrement (bgp, p, ri, afi, safi); | |
3937 | bgp_attr_unintern (&ri->attr); | |
3938 | ri->attr = attr_new; | |
3939 | ri->uptime = bgp_clock (); | |
65efcfce LB |
3940 | #if ENABLE_BGP_VNC |
3941 | if (ri->extra) | |
3942 | label = decode_label (ri->extra->tag); | |
3943 | #endif | |
137446f9 LB |
3944 | |
3945 | /* Process change. */ | |
3946 | bgp_aggregate_increment (bgp, p, ri, afi, safi); | |
3947 | bgp_process (bgp, rn, afi, safi); | |
65efcfce LB |
3948 | #if ENABLE_BGP_VNC |
3949 | rfapiProcessUpdate(ri->peer, NULL, p, &bgp_static->prd, | |
3950 | ri->attr, afi, safi, | |
3951 | ri->type, ri->sub_type, &label); | |
3952 | #endif | |
137446f9 LB |
3953 | bgp_unlock_node (rn); |
3954 | aspath_unintern (&attr.aspath); | |
3955 | bgp_attr_extra_free (&attr); | |
3956 | return; | |
3957 | } | |
3958 | } | |
3959 | ||
3960 | ||
3961 | /* Make new BGP info. */ | |
3962 | new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new, | |
3963 | rn); | |
3964 | SET_FLAG (new->flags, BGP_INFO_VALID); | |
3965 | new->extra = bgp_info_extra_new(); | |
3966 | memcpy (new->extra->tag, bgp_static->tag, 3); | |
65efcfce LB |
3967 | #if ENABLE_BGP_VNC |
3968 | label = decode_label (bgp_static->tag); | |
3969 | #endif | |
137446f9 LB |
3970 | |
3971 | /* Aggregate address increment. */ | |
3972 | bgp_aggregate_increment (bgp, p, new, afi, safi); | |
3973 | ||
3974 | /* Register new BGP information. */ | |
3975 | bgp_info_add (rn, new); | |
3976 | ||
3977 | /* route_node_get lock */ | |
3978 | bgp_unlock_node (rn); | |
3979 | ||
3980 | /* Process change. */ | |
3981 | bgp_process (bgp, rn, afi, safi); | |
3982 | ||
65efcfce LB |
3983 | #if ENABLE_BGP_VNC |
3984 | rfapiProcessUpdate(new->peer, NULL, p, &bgp_static->prd, | |
3985 | new->attr, afi, safi, | |
3986 | new->type, new->sub_type, &label); | |
3987 | #endif | |
3988 | ||
137446f9 LB |
3989 | /* Unintern original. */ |
3990 | aspath_unintern (&attr.aspath); | |
3991 | bgp_attr_extra_free (&attr); | |
3992 | } | |
3993 | ||
718e3744 | 3994 | /* Configure static BGP network. When user don't run zebra, static |
3995 | route should be installed as valid. */ | |
94f2b392 | 3996 | static int |
fd79ac91 | 3997 | bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str, |
c8f3fe30 | 3998 | afi_t afi, safi_t safi, const char *rmap, int backdoor) |
718e3744 | 3999 | { |
4000 | int ret; | |
4001 | struct prefix p; | |
4002 | struct bgp_static *bgp_static; | |
4003 | struct bgp_node *rn; | |
41367172 | 4004 | u_char need_update = 0; |
718e3744 | 4005 | |
4006 | /* Convert IP prefix string to struct prefix. */ | |
4007 | ret = str2prefix (ip_str, &p); | |
4008 | if (! ret) | |
4009 | { | |
4010 | vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE); | |
4011 | return CMD_WARNING; | |
4012 | } | |
4013 | #ifdef HAVE_IPV6 | |
4014 | if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6)) | |
4015 | { | |
4016 | vty_out (vty, "%% Malformed prefix (link-local address)%s", | |
4017 | VTY_NEWLINE); | |
4018 | return CMD_WARNING; | |
4019 | } | |
4020 | #endif /* HAVE_IPV6 */ | |
4021 | ||
4022 | apply_mask (&p); | |
4023 | ||
4024 | /* Set BGP static route configuration. */ | |
4025 | rn = bgp_node_get (bgp->route[afi][safi], &p); | |
4026 | ||
4027 | if (rn->info) | |
4028 | { | |
4029 | /* Configuration change. */ | |
4030 | bgp_static = rn->info; | |
4031 | ||
4032 | /* Check previous routes are installed into BGP. */ | |
c8f3fe30 PJ |
4033 | if (bgp_static->valid && bgp_static->backdoor != backdoor) |
4034 | need_update = 1; | |
41367172 | 4035 | |
718e3744 | 4036 | bgp_static->backdoor = backdoor; |
41367172 | 4037 | |
718e3744 | 4038 | if (rmap) |
4039 | { | |
4040 | if (bgp_static->rmap.name) | |
6e919709 DS |
4041 | XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name); |
4042 | bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap); | |
718e3744 | 4043 | bgp_static->rmap.map = route_map_lookup_by_name (rmap); |
4044 | } | |
4045 | else | |
4046 | { | |
4047 | if (bgp_static->rmap.name) | |
6e919709 | 4048 | XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name); |
718e3744 | 4049 | bgp_static->rmap.name = NULL; |
4050 | bgp_static->rmap.map = NULL; | |
4051 | bgp_static->valid = 0; | |
4052 | } | |
4053 | bgp_unlock_node (rn); | |
4054 | } | |
4055 | else | |
4056 | { | |
4057 | /* New configuration. */ | |
4058 | bgp_static = bgp_static_new (); | |
4059 | bgp_static->backdoor = backdoor; | |
4060 | bgp_static->valid = 0; | |
4061 | bgp_static->igpmetric = 0; | |
4062 | bgp_static->igpnexthop.s_addr = 0; | |
41367172 | 4063 | |
718e3744 | 4064 | if (rmap) |
4065 | { | |
4066 | if (bgp_static->rmap.name) | |
6e919709 DS |
4067 | XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name); |
4068 | bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap); | |
718e3744 | 4069 | bgp_static->rmap.map = route_map_lookup_by_name (rmap); |
4070 | } | |
4071 | rn->info = bgp_static; | |
4072 | } | |
4073 | ||
fc9a856f DS |
4074 | bgp_static->valid = 1; |
4075 | if (need_update) | |
4076 | bgp_static_withdraw (bgp, &p, afi, safi); | |
718e3744 | 4077 | |
fc9a856f DS |
4078 | if (! bgp_static->backdoor) |
4079 | bgp_static_update (bgp, &p, bgp_static, afi, safi); | |
718e3744 | 4080 | |
4081 | return CMD_SUCCESS; | |
4082 | } | |
4083 | ||
4084 | /* Configure static BGP network. */ | |
94f2b392 | 4085 | static int |
fd79ac91 | 4086 | bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str, |
4c9641ba | 4087 | afi_t afi, safi_t safi) |
718e3744 | 4088 | { |
4089 | int ret; | |
4090 | struct prefix p; | |
4091 | struct bgp_static *bgp_static; | |
4092 | struct bgp_node *rn; | |
4093 | ||
4094 | /* Convert IP prefix string to struct prefix. */ | |
4095 | ret = str2prefix (ip_str, &p); | |
4096 | if (! ret) | |
4097 | { | |
4098 | vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE); | |
4099 | return CMD_WARNING; | |
4100 | } | |
4101 | #ifdef HAVE_IPV6 | |
4102 | if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6)) | |
4103 | { | |
4104 | vty_out (vty, "%% Malformed prefix (link-local address)%s", | |
4105 | VTY_NEWLINE); | |
4106 | return CMD_WARNING; | |
4107 | } | |
4108 | #endif /* HAVE_IPV6 */ | |
4109 | ||
4110 | apply_mask (&p); | |
4111 | ||
4112 | rn = bgp_node_lookup (bgp->route[afi][safi], &p); | |
4113 | if (! rn) | |
4114 | { | |
4115 | vty_out (vty, "%% Can't find specified static route configuration.%s", | |
4116 | VTY_NEWLINE); | |
4117 | return CMD_WARNING; | |
4118 | } | |
4119 | ||
4120 | bgp_static = rn->info; | |
41367172 | 4121 | |
718e3744 | 4122 | /* Update BGP RIB. */ |
4123 | if (! bgp_static->backdoor) | |
4124 | bgp_static_withdraw (bgp, &p, afi, safi); | |
4125 | ||
4126 | /* Clear configuration. */ | |
4127 | bgp_static_free (bgp_static); | |
4128 | rn->info = NULL; | |
4129 | bgp_unlock_node (rn); | |
4130 | bgp_unlock_node (rn); | |
4131 | ||
4132 | return CMD_SUCCESS; | |
4133 | } | |
4134 | ||
6aeb9e78 DS |
4135 | void |
4136 | bgp_static_add (struct bgp *bgp) | |
4137 | { | |
4138 | afi_t afi; | |
4139 | safi_t safi; | |
4140 | struct bgp_node *rn; | |
4141 | struct bgp_node *rm; | |
4142 | struct bgp_table *table; | |
4143 | struct bgp_static *bgp_static; | |
4144 | ||
4145 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
4146 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) | |
4147 | for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn)) | |
4148 | if (rn->info != NULL) | |
4149 | { | |
4150 | if (safi == SAFI_MPLS_VPN) | |
4151 | { | |
4152 | table = rn->info; | |
4153 | ||
4154 | for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm)) | |
4155 | { | |
4156 | bgp_static = rn->info; | |
137446f9 | 4157 | bgp_static_update_safi (bgp, &rm->p, bgp_static, afi, safi); |
6aeb9e78 DS |
4158 | } |
4159 | } | |
4160 | else | |
4161 | { | |
4162 | bgp_static_update (bgp, &rn->p, rn->info, afi, safi); | |
4163 | } | |
4164 | } | |
4165 | } | |
4166 | ||
718e3744 | 4167 | /* Called from bgp_delete(). Delete all static routes from the BGP |
4168 | instance. */ | |
4169 | void | |
4170 | bgp_static_delete (struct bgp *bgp) | |
4171 | { | |
4172 | afi_t afi; | |
4173 | safi_t safi; | |
4174 | struct bgp_node *rn; | |
4175 | struct bgp_node *rm; | |
4176 | struct bgp_table *table; | |
4177 | struct bgp_static *bgp_static; | |
4178 | ||
4179 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
4180 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) | |
4181 | for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn)) | |
4182 | if (rn->info != NULL) | |
4183 | { | |
587ff0fd | 4184 | if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) |
718e3744 | 4185 | { |
4186 | table = rn->info; | |
4187 | ||
4188 | for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm)) | |
4189 | { | |
4190 | bgp_static = rn->info; | |
137446f9 LB |
4191 | bgp_static_withdraw_safi (bgp, &rm->p, |
4192 | AFI_IP, safi, | |
718e3744 | 4193 | (struct prefix_rd *)&rn->p, |
4194 | bgp_static->tag); | |
4195 | bgp_static_free (bgp_static); | |
4196 | rn->info = NULL; | |
4197 | bgp_unlock_node (rn); | |
4198 | } | |
4199 | } | |
4200 | else | |
4201 | { | |
4202 | bgp_static = rn->info; | |
4203 | bgp_static_withdraw (bgp, &rn->p, afi, safi); | |
4204 | bgp_static_free (bgp_static); | |
4205 | rn->info = NULL; | |
4206 | bgp_unlock_node (rn); | |
4207 | } | |
4208 | } | |
4209 | } | |
4210 | ||
078430f6 DS |
4211 | void |
4212 | bgp_static_redo_import_check (struct bgp *bgp) | |
4213 | { | |
4214 | afi_t afi; | |
4215 | safi_t safi; | |
4216 | struct bgp_node *rn; | |
078430f6 DS |
4217 | struct bgp_static *bgp_static; |
4218 | ||
4219 | /* Use this flag to force reprocessing of the route */ | |
4220 | bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS); | |
4221 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
4222 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) | |
4223 | for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn)) | |
4224 | if (rn->info != NULL) | |
4225 | { | |
4226 | bgp_static = rn->info; | |
4227 | bgp_static_update (bgp, &rn->p, bgp_static, afi, safi); | |
4228 | } | |
4229 | bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS); | |
4230 | } | |
4231 | ||
ad4cbda1 | 4232 | static void |
4233 | bgp_purge_af_static_redist_routes (struct bgp *bgp, afi_t afi, safi_t safi) | |
4234 | { | |
4235 | struct bgp_table *table; | |
4236 | struct bgp_node *rn; | |
4237 | struct bgp_info *ri; | |
4238 | ||
4239 | table = bgp->rib[afi][safi]; | |
4240 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
4241 | { | |
4242 | for (ri = rn->info; ri; ri = ri->next) | |
4243 | { | |
4244 | if (ri->peer == bgp->peer_self && | |
4245 | ((ri->type == ZEBRA_ROUTE_BGP && | |
4246 | ri->sub_type == BGP_ROUTE_STATIC) || | |
4247 | (ri->type != ZEBRA_ROUTE_BGP && | |
4248 | ri->sub_type == BGP_ROUTE_REDISTRIBUTE))) | |
4249 | { | |
4250 | bgp_aggregate_decrement (bgp, &rn->p, ri, afi, safi); | |
4251 | bgp_unlink_nexthop(ri); | |
4252 | bgp_info_delete (rn, ri); | |
4253 | bgp_process (bgp, rn, afi, safi); | |
4254 | } | |
4255 | } | |
4256 | } | |
4257 | } | |
4258 | ||
4259 | /* | |
4260 | * Purge all networks and redistributed routes from routing table. | |
4261 | * Invoked upon the instance going down. | |
4262 | */ | |
4263 | void | |
4264 | bgp_purge_static_redist_routes (struct bgp *bgp) | |
4265 | { | |
4266 | afi_t afi; | |
4267 | safi_t safi; | |
4268 | ||
4269 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
4270 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) | |
4271 | bgp_purge_af_static_redist_routes (bgp, afi, safi); | |
4272 | } | |
4273 | ||
137446f9 LB |
4274 | /* |
4275 | * gpz 110624 | |
4276 | * Currently this is used to set static routes for VPN and ENCAP. | |
4277 | * I think it can probably be factored with bgp_static_set. | |
4278 | */ | |
718e3744 | 4279 | int |
137446f9 LB |
4280 | bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str, |
4281 | const char *rd_str, const char *tag_str, | |
4282 | const char *rmap_str) | |
718e3744 | 4283 | { |
4284 | int ret; | |
4285 | struct prefix p; | |
4286 | struct prefix_rd prd; | |
4287 | struct bgp *bgp; | |
4288 | struct bgp_node *prn; | |
4289 | struct bgp_node *rn; | |
4290 | struct bgp_table *table; | |
4291 | struct bgp_static *bgp_static; | |
4292 | u_char tag[3]; | |
4293 | ||
4294 | bgp = vty->index; | |
4295 | ||
4296 | ret = str2prefix (ip_str, &p); | |
4297 | if (! ret) | |
4298 | { | |
4299 | vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE); | |
4300 | return CMD_WARNING; | |
4301 | } | |
4302 | apply_mask (&p); | |
4303 | ||
4304 | ret = str2prefix_rd (rd_str, &prd); | |
4305 | if (! ret) | |
4306 | { | |
4307 | vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE); | |
4308 | return CMD_WARNING; | |
4309 | } | |
4310 | ||
4311 | ret = str2tag (tag_str, tag); | |
4312 | if (! ret) | |
4313 | { | |
4314 | vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE); | |
4315 | return CMD_WARNING; | |
4316 | } | |
4317 | ||
137446f9 | 4318 | prn = bgp_node_get (bgp->route[AFI_IP][safi], |
718e3744 | 4319 | (struct prefix *)&prd); |
4320 | if (prn->info == NULL) | |
137446f9 | 4321 | prn->info = bgp_table_init (AFI_IP, safi); |
718e3744 | 4322 | else |
4323 | bgp_unlock_node (prn); | |
4324 | table = prn->info; | |
4325 | ||
4326 | rn = bgp_node_get (table, &p); | |
4327 | ||
4328 | if (rn->info) | |
4329 | { | |
4330 | vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE); | |
4331 | bgp_unlock_node (rn); | |
4332 | } | |
4333 | else | |
4334 | { | |
4335 | /* New configuration. */ | |
4336 | bgp_static = bgp_static_new (); | |
137446f9 LB |
4337 | bgp_static->backdoor = 0; |
4338 | bgp_static->valid = 0; | |
4339 | bgp_static->igpmetric = 0; | |
4340 | bgp_static->igpnexthop.s_addr = 0; | |
4341 | memcpy(bgp_static->tag, tag, 3); | |
4342 | bgp_static->prd = prd; | |
4343 | ||
4344 | if (rmap_str) | |
4345 | { | |
4346 | if (bgp_static->rmap.name) | |
4347 | free (bgp_static->rmap.name); | |
4348 | bgp_static->rmap.name = strdup (rmap_str); | |
4349 | bgp_static->rmap.map = route_map_lookup_by_name (rmap_str); | |
4350 | } | |
718e3744 | 4351 | rn->info = bgp_static; |
4352 | ||
137446f9 LB |
4353 | bgp_static->valid = 1; |
4354 | bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi); | |
718e3744 | 4355 | } |
4356 | ||
4357 | return CMD_SUCCESS; | |
4358 | } | |
4359 | ||
4360 | /* Configure static BGP network. */ | |
4361 | int | |
137446f9 LB |
4362 | bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str, |
4363 | const char *rd_str, const char *tag_str) | |
718e3744 | 4364 | { |
4365 | int ret; | |
4366 | struct bgp *bgp; | |
4367 | struct prefix p; | |
4368 | struct prefix_rd prd; | |
4369 | struct bgp_node *prn; | |
4370 | struct bgp_node *rn; | |
4371 | struct bgp_table *table; | |
4372 | struct bgp_static *bgp_static; | |
4373 | u_char tag[3]; | |
4374 | ||
4375 | bgp = vty->index; | |
4376 | ||
4377 | /* Convert IP prefix string to struct prefix. */ | |
4378 | ret = str2prefix (ip_str, &p); | |
4379 | if (! ret) | |
4380 | { | |
4381 | vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE); | |
4382 | return CMD_WARNING; | |
4383 | } | |
4384 | apply_mask (&p); | |
4385 | ||
4386 | ret = str2prefix_rd (rd_str, &prd); | |
4387 | if (! ret) | |
4388 | { | |
4389 | vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE); | |
4390 | return CMD_WARNING; | |
4391 | } | |
4392 | ||
4393 | ret = str2tag (tag_str, tag); | |
4394 | if (! ret) | |
4395 | { | |
4396 | vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE); | |
4397 | return CMD_WARNING; | |
4398 | } | |
4399 | ||
137446f9 | 4400 | prn = bgp_node_get (bgp->route[AFI_IP][safi], |
718e3744 | 4401 | (struct prefix *)&prd); |
4402 | if (prn->info == NULL) | |
137446f9 | 4403 | prn->info = bgp_table_init (AFI_IP, safi); |
718e3744 | 4404 | else |
4405 | bgp_unlock_node (prn); | |
4406 | table = prn->info; | |
4407 | ||
4408 | rn = bgp_node_lookup (table, &p); | |
4409 | ||
4410 | if (rn) | |
4411 | { | |
137446f9 | 4412 | bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag); |
718e3744 | 4413 | |
4414 | bgp_static = rn->info; | |
4415 | bgp_static_free (bgp_static); | |
4416 | rn->info = NULL; | |
4417 | bgp_unlock_node (rn); | |
4418 | bgp_unlock_node (rn); | |
4419 | } | |
4420 | else | |
4421 | vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE); | |
4422 | ||
4423 | return CMD_SUCCESS; | |
4424 | } | |
6b0655a2 | 4425 | |
73ac8160 DS |
4426 | static int |
4427 | bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, | |
4428 | const char *rmap_name) | |
4429 | { | |
4430 | struct bgp_rmap *rmap; | |
4431 | ||
4432 | rmap = &bgp->table_map[afi][safi]; | |
4433 | if (rmap_name) | |
4434 | { | |
4435 | if (rmap->name) | |
6e919709 DS |
4436 | XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name); |
4437 | rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name); | |
73ac8160 DS |
4438 | rmap->map = route_map_lookup_by_name (rmap_name); |
4439 | } | |
4440 | else | |
4441 | { | |
4442 | if (rmap->name) | |
6e919709 | 4443 | XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name); |
73ac8160 DS |
4444 | rmap->name = NULL; |
4445 | rmap->map = NULL; | |
4446 | } | |
4447 | ||
4448 | bgp_zebra_announce_table(bgp, afi, safi); | |
4449 | ||
4450 | return CMD_SUCCESS; | |
4451 | } | |
4452 | ||
4453 | static int | |
4454 | bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, | |
4455 | const char *rmap_name) | |
4456 | { | |
4457 | struct bgp_rmap *rmap; | |
4458 | ||
4459 | rmap = &bgp->table_map[afi][safi]; | |
4460 | if (rmap->name) | |
6e919709 | 4461 | XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name); |
73ac8160 DS |
4462 | rmap->name = NULL; |
4463 | rmap->map = NULL; | |
4464 | ||
4465 | bgp_zebra_announce_table(bgp, afi, safi); | |
4466 | ||
4467 | return CMD_SUCCESS; | |
4468 | } | |
4469 | ||
4470 | int | |
4471 | bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi, | |
4472 | safi_t safi, int *write) | |
4473 | { | |
4474 | if (bgp->table_map[afi][safi].name) | |
4475 | { | |
4476 | bgp_config_write_family_header (vty, afi, safi, write); | |
0b960b4d | 4477 | vty_out (vty, " table-map %s%s", |
73ac8160 DS |
4478 | bgp->table_map[afi][safi].name, VTY_NEWLINE); |
4479 | } | |
4480 | ||
4481 | return 0; | |
4482 | } | |
4483 | ||
73ac8160 DS |
4484 | DEFUN (bgp_table_map, |
4485 | bgp_table_map_cmd, | |
4486 | "table-map WORD", | |
4487 | "BGP table to RIB route download filter\n" | |
4488 | "Name of the route map\n") | |
4489 | { | |
4490 | return bgp_table_map_set (vty, vty->index, | |
4491 | bgp_node_afi (vty), bgp_node_safi (vty), argv[0]); | |
4492 | } | |
4493 | DEFUN (no_bgp_table_map, | |
4494 | no_bgp_table_map_cmd, | |
4495 | "no table-map WORD", | |
4496 | "BGP table to RIB route download filter\n" | |
4497 | "Name of the route map\n") | |
4498 | { | |
4499 | return bgp_table_map_unset (vty, vty->index, | |
4500 | bgp_node_afi (vty), bgp_node_safi (vty), argv[0]); | |
4501 | } | |
4502 | ||
718e3744 | 4503 | DEFUN (bgp_network, |
4504 | bgp_network_cmd, | |
4505 | "network A.B.C.D/M", | |
4506 | "Specify a network to announce via BGP\n" | |
4507 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") | |
4508 | { | |
4509 | return bgp_static_set (vty, vty->index, argv[0], | |
c8f3fe30 | 4510 | AFI_IP, bgp_node_safi (vty), NULL, 0); |
718e3744 | 4511 | } |
4512 | ||
4513 | DEFUN (bgp_network_route_map, | |
4514 | bgp_network_route_map_cmd, | |
4515 | "network A.B.C.D/M route-map WORD", | |
4516 | "Specify a network to announce via BGP\n" | |
4517 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
4518 | "Route-map to modify the attributes\n" | |
4519 | "Name of the route map\n") | |
4520 | { | |
4521 | return bgp_static_set (vty, vty->index, argv[0], | |
c8f3fe30 | 4522 | AFI_IP, bgp_node_safi (vty), argv[1], 0); |
718e3744 | 4523 | } |
4524 | ||
4525 | DEFUN (bgp_network_backdoor, | |
4526 | bgp_network_backdoor_cmd, | |
4527 | "network A.B.C.D/M backdoor", | |
4528 | "Specify a network to announce via BGP\n" | |
4529 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
4530 | "Specify a BGP backdoor route\n") | |
4531 | { | |
41367172 | 4532 | return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, |
c8f3fe30 | 4533 | NULL, 1); |
718e3744 | 4534 | } |
4535 | ||
4536 | DEFUN (bgp_network_mask, | |
4537 | bgp_network_mask_cmd, | |
4538 | "network A.B.C.D mask A.B.C.D", | |
4539 | "Specify a network to announce via BGP\n" | |
4540 | "Network number\n" | |
4541 | "Network mask\n" | |
4542 | "Network mask\n") | |
4543 | { | |
4544 | int ret; | |
4545 | char prefix_str[BUFSIZ]; | |
41367172 | 4546 | |
718e3744 | 4547 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); |
4548 | if (! ret) | |
4549 | { | |
4550 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
4551 | return CMD_WARNING; | |
4552 | } | |
4553 | ||
4554 | return bgp_static_set (vty, vty->index, prefix_str, | |
c8f3fe30 | 4555 | AFI_IP, bgp_node_safi (vty), NULL, 0); |
718e3744 | 4556 | } |
4557 | ||
4558 | DEFUN (bgp_network_mask_route_map, | |
4559 | bgp_network_mask_route_map_cmd, | |
4560 | "network A.B.C.D mask A.B.C.D route-map WORD", | |
4561 | "Specify a network to announce via BGP\n" | |
4562 | "Network number\n" | |
4563 | "Network mask\n" | |
4564 | "Network mask\n" | |
4565 | "Route-map to modify the attributes\n" | |
4566 | "Name of the route map\n") | |
4567 | { | |
4568 | int ret; | |
4569 | char prefix_str[BUFSIZ]; | |
41367172 | 4570 | |
718e3744 | 4571 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); |
4572 | if (! ret) | |
4573 | { | |
4574 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
4575 | return CMD_WARNING; | |
4576 | } | |
4577 | ||
4578 | return bgp_static_set (vty, vty->index, prefix_str, | |
c8f3fe30 | 4579 | AFI_IP, bgp_node_safi (vty), argv[2], 0); |
718e3744 | 4580 | } |
4581 | ||
4582 | DEFUN (bgp_network_mask_backdoor, | |
4583 | bgp_network_mask_backdoor_cmd, | |
4584 | "network A.B.C.D mask A.B.C.D backdoor", | |
4585 | "Specify a network to announce via BGP\n" | |
4586 | "Network number\n" | |
4587 | "Network mask\n" | |
4588 | "Network mask\n" | |
4589 | "Specify a BGP backdoor route\n") | |
4590 | { | |
4591 | int ret; | |
4592 | char prefix_str[BUFSIZ]; | |
41367172 | 4593 | |
718e3744 | 4594 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); |
4595 | if (! ret) | |
4596 | { | |
4597 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
4598 | return CMD_WARNING; | |
4599 | } | |
4600 | ||
41367172 | 4601 | return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, |
c8f3fe30 | 4602 | NULL, 1); |
718e3744 | 4603 | } |
4604 | ||
4605 | DEFUN (bgp_network_mask_natural, | |
4606 | bgp_network_mask_natural_cmd, | |
4607 | "network A.B.C.D", | |
4608 | "Specify a network to announce via BGP\n" | |
4609 | "Network number\n") | |
4610 | { | |
4611 | int ret; | |
4612 | char prefix_str[BUFSIZ]; | |
4613 | ||
4614 | ret = netmask_str2prefix_str (argv[0], NULL, prefix_str); | |
4615 | if (! ret) | |
4616 | { | |
4617 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
4618 | return CMD_WARNING; | |
4619 | } | |
4620 | ||
4621 | return bgp_static_set (vty, vty->index, prefix_str, | |
c8f3fe30 | 4622 | AFI_IP, bgp_node_safi (vty), NULL, 0); |
718e3744 | 4623 | } |
4624 | ||
4625 | DEFUN (bgp_network_mask_natural_route_map, | |
4626 | bgp_network_mask_natural_route_map_cmd, | |
4627 | "network A.B.C.D route-map WORD", | |
4628 | "Specify a network to announce via BGP\n" | |
4629 | "Network number\n" | |
4630 | "Route-map to modify the attributes\n" | |
4631 | "Name of the route map\n") | |
4632 | { | |
4633 | int ret; | |
4634 | char prefix_str[BUFSIZ]; | |
4635 | ||
4636 | ret = netmask_str2prefix_str (argv[0], NULL, prefix_str); | |
4637 | if (! ret) | |
4638 | { | |
4639 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
4640 | return CMD_WARNING; | |
4641 | } | |
4642 | ||
4643 | return bgp_static_set (vty, vty->index, prefix_str, | |
c8f3fe30 | 4644 | AFI_IP, bgp_node_safi (vty), argv[1], 0); |
718e3744 | 4645 | } |
4646 | ||
4647 | DEFUN (bgp_network_mask_natural_backdoor, | |
4648 | bgp_network_mask_natural_backdoor_cmd, | |
4649 | "network A.B.C.D backdoor", | |
4650 | "Specify a network to announce via BGP\n" | |
4651 | "Network number\n" | |
4652 | "Specify a BGP backdoor route\n") | |
4653 | { | |
4654 | int ret; | |
4655 | char prefix_str[BUFSIZ]; | |
4656 | ||
4657 | ret = netmask_str2prefix_str (argv[0], NULL, prefix_str); | |
4658 | if (! ret) | |
4659 | { | |
4660 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
4661 | return CMD_WARNING; | |
4662 | } | |
4663 | ||
41367172 | 4664 | return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, |
c8f3fe30 | 4665 | NULL, 1); |
718e3744 | 4666 | } |
4667 | ||
4668 | DEFUN (no_bgp_network, | |
4669 | no_bgp_network_cmd, | |
4670 | "no network A.B.C.D/M", | |
4671 | NO_STR | |
4672 | "Specify a network to announce via BGP\n" | |
4673 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") | |
4674 | { | |
4675 | return bgp_static_unset (vty, vty->index, argv[0], AFI_IP, | |
4676 | bgp_node_safi (vty)); | |
4677 | } | |
4678 | ||
4679 | ALIAS (no_bgp_network, | |
4680 | no_bgp_network_route_map_cmd, | |
4681 | "no network A.B.C.D/M route-map WORD", | |
4682 | NO_STR | |
4683 | "Specify a network to announce via BGP\n" | |
4684 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
4685 | "Route-map to modify the attributes\n" | |
4686 | "Name of the route map\n") | |
4687 | ||
4688 | ALIAS (no_bgp_network, | |
4689 | no_bgp_network_backdoor_cmd, | |
4690 | "no network A.B.C.D/M backdoor", | |
4691 | NO_STR | |
4692 | "Specify a network to announce via BGP\n" | |
4693 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
4694 | "Specify a BGP backdoor route\n") | |
4695 | ||
4696 | DEFUN (no_bgp_network_mask, | |
4697 | no_bgp_network_mask_cmd, | |
4698 | "no network A.B.C.D mask A.B.C.D", | |
4699 | NO_STR | |
4700 | "Specify a network to announce via BGP\n" | |
4701 | "Network number\n" | |
4702 | "Network mask\n" | |
4703 | "Network mask\n") | |
4704 | { | |
4705 | int ret; | |
4706 | char prefix_str[BUFSIZ]; | |
4707 | ||
4708 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); | |
4709 | if (! ret) | |
4710 | { | |
4711 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
4712 | return CMD_WARNING; | |
4713 | } | |
4714 | ||
4715 | return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP, | |
4716 | bgp_node_safi (vty)); | |
4717 | } | |
4718 | ||
4719 | ALIAS (no_bgp_network_mask, | |
4720 | no_bgp_network_mask_route_map_cmd, | |
4721 | "no network A.B.C.D mask A.B.C.D route-map WORD", | |
4722 | NO_STR | |
4723 | "Specify a network to announce via BGP\n" | |
4724 | "Network number\n" | |
4725 | "Network mask\n" | |
4726 | "Network mask\n" | |
4727 | "Route-map to modify the attributes\n" | |
4728 | "Name of the route map\n") | |
4729 | ||
4730 | ALIAS (no_bgp_network_mask, | |
4731 | no_bgp_network_mask_backdoor_cmd, | |
4732 | "no network A.B.C.D mask A.B.C.D backdoor", | |
4733 | NO_STR | |
4734 | "Specify a network to announce via BGP\n" | |
4735 | "Network number\n" | |
4736 | "Network mask\n" | |
4737 | "Network mask\n" | |
4738 | "Specify a BGP backdoor route\n") | |
4739 | ||
4740 | DEFUN (no_bgp_network_mask_natural, | |
4741 | no_bgp_network_mask_natural_cmd, | |
4742 | "no network A.B.C.D", | |
4743 | NO_STR | |
4744 | "Specify a network to announce via BGP\n" | |
4745 | "Network number\n") | |
4746 | { | |
4747 | int ret; | |
4748 | char prefix_str[BUFSIZ]; | |
4749 | ||
4750 | ret = netmask_str2prefix_str (argv[0], NULL, prefix_str); | |
4751 | if (! ret) | |
4752 | { | |
4753 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
4754 | return CMD_WARNING; | |
4755 | } | |
4756 | ||
4757 | return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP, | |
4758 | bgp_node_safi (vty)); | |
4759 | } | |
4760 | ||
4761 | ALIAS (no_bgp_network_mask_natural, | |
4762 | no_bgp_network_mask_natural_route_map_cmd, | |
4763 | "no network A.B.C.D route-map WORD", | |
4764 | NO_STR | |
4765 | "Specify a network to announce via BGP\n" | |
4766 | "Network number\n" | |
4767 | "Route-map to modify the attributes\n" | |
4768 | "Name of the route map\n") | |
4769 | ||
4770 | ALIAS (no_bgp_network_mask_natural, | |
4771 | no_bgp_network_mask_natural_backdoor_cmd, | |
4772 | "no network A.B.C.D backdoor", | |
4773 | NO_STR | |
4774 | "Specify a network to announce via BGP\n" | |
4775 | "Network number\n" | |
4776 | "Specify a BGP backdoor route\n") | |
4777 | ||
4778 | #ifdef HAVE_IPV6 | |
4779 | DEFUN (ipv6_bgp_network, | |
4780 | ipv6_bgp_network_cmd, | |
4781 | "network X:X::X:X/M", | |
4782 | "Specify a network to announce via BGP\n" | |
4783 | "IPv6 prefix <network>/<length>\n") | |
4784 | { | |
73bfe0bd | 4785 | return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty), |
c8f3fe30 | 4786 | NULL, 0); |
718e3744 | 4787 | } |
4788 | ||
4789 | DEFUN (ipv6_bgp_network_route_map, | |
4790 | ipv6_bgp_network_route_map_cmd, | |
4791 | "network X:X::X:X/M route-map WORD", | |
4792 | "Specify a network to announce via BGP\n" | |
4793 | "IPv6 prefix <network>/<length>\n" | |
4794 | "Route-map to modify the attributes\n" | |
4795 | "Name of the route map\n") | |
4796 | { | |
4797 | return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, | |
c8f3fe30 | 4798 | bgp_node_safi (vty), argv[1], 0); |
718e3744 | 4799 | } |
4800 | ||
4801 | DEFUN (no_ipv6_bgp_network, | |
4802 | no_ipv6_bgp_network_cmd, | |
4803 | "no network X:X::X:X/M", | |
4804 | NO_STR | |
4805 | "Specify a network to announce via BGP\n" | |
4806 | "IPv6 prefix <network>/<length>\n") | |
4807 | { | |
73bfe0bd | 4808 | return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty)); |
718e3744 | 4809 | } |
4810 | ||
4811 | ALIAS (no_ipv6_bgp_network, | |
4812 | no_ipv6_bgp_network_route_map_cmd, | |
4813 | "no network X:X::X:X/M route-map WORD", | |
4814 | NO_STR | |
4815 | "Specify a network to announce via BGP\n" | |
4816 | "IPv6 prefix <network>/<length>\n" | |
4817 | "Route-map to modify the attributes\n" | |
4818 | "Name of the route map\n") | |
4819 | ||
4820 | ALIAS (ipv6_bgp_network, | |
4821 | old_ipv6_bgp_network_cmd, | |
4822 | "ipv6 bgp network X:X::X:X/M", | |
4823 | IPV6_STR | |
4824 | BGP_STR | |
4825 | "Specify a network to announce via BGP\n" | |
4826 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n") | |
4827 | ||
4828 | ALIAS (no_ipv6_bgp_network, | |
4829 | old_no_ipv6_bgp_network_cmd, | |
4830 | "no ipv6 bgp network X:X::X:X/M", | |
4831 | NO_STR | |
4832 | IPV6_STR | |
4833 | BGP_STR | |
4834 | "Specify a network to announce via BGP\n" | |
4835 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n") | |
4836 | #endif /* HAVE_IPV6 */ | |
c8f3fe30 | 4837 | |
718e3744 | 4838 | /* Aggreagete address: |
4839 | ||
4840 | advertise-map Set condition to advertise attribute | |
4841 | as-set Generate AS set path information | |
4842 | attribute-map Set attributes of aggregate | |
4843 | route-map Set parameters of aggregate | |
4844 | summary-only Filter more specific routes from updates | |
4845 | suppress-map Conditionally filter more specific routes from updates | |
4846 | <cr> | |
4847 | */ | |
4848 | struct bgp_aggregate | |
4849 | { | |
4850 | /* Summary-only flag. */ | |
4851 | u_char summary_only; | |
4852 | ||
4853 | /* AS set generation. */ | |
4854 | u_char as_set; | |
4855 | ||
4856 | /* Route-map for aggregated route. */ | |
4857 | struct route_map *map; | |
4858 | ||
4859 | /* Suppress-count. */ | |
4860 | unsigned long count; | |
4861 | ||
4862 | /* SAFI configuration. */ | |
4863 | safi_t safi; | |
4864 | }; | |
4865 | ||
94f2b392 | 4866 | static struct bgp_aggregate * |
66e5cd87 | 4867 | bgp_aggregate_new (void) |
718e3744 | 4868 | { |
393deb9b | 4869 | return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate)); |
718e3744 | 4870 | } |
4871 | ||
94f2b392 | 4872 | static void |
718e3744 | 4873 | bgp_aggregate_free (struct bgp_aggregate *aggregate) |
4874 | { | |
4875 | XFREE (MTYPE_BGP_AGGREGATE, aggregate); | |
4876 | } | |
4877 | ||
b5d58c32 | 4878 | /* Update an aggregate as routes are added/removed from the BGP table */ |
94f2b392 | 4879 | static void |
718e3744 | 4880 | bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew, |
4881 | afi_t afi, safi_t safi, struct bgp_info *del, | |
4882 | struct bgp_aggregate *aggregate) | |
4883 | { | |
4884 | struct bgp_table *table; | |
4885 | struct bgp_node *top; | |
4886 | struct bgp_node *rn; | |
4887 | u_char origin; | |
4888 | struct aspath *aspath = NULL; | |
4889 | struct aspath *asmerge = NULL; | |
4890 | struct community *community = NULL; | |
4891 | struct community *commerge = NULL; | |
ffd0c037 | 4892 | #if defined(AGGREGATE_NEXTHOP_CHECK) |
718e3744 | 4893 | struct in_addr nexthop; |
4894 | u_int32_t med = 0; | |
ffd0c037 | 4895 | #endif |
718e3744 | 4896 | struct bgp_info *ri; |
4897 | struct bgp_info *new; | |
4898 | int first = 1; | |
4899 | unsigned long match = 0; | |
42f7e184 | 4900 | u_char atomic_aggregate = 0; |
718e3744 | 4901 | |
4902 | /* Record adding route's nexthop and med. */ | |
ffd0c037 DS |
4903 | if (rinew) |
4904 | { | |
4905 | #if defined(AGGREGATE_NEXTHOP_CHECK) | |
4906 | nexthop = rinew->attr->nexthop; | |
4907 | med = rinew->attr->med; | |
4908 | #endif | |
4909 | } | |
718e3744 | 4910 | |
4911 | /* ORIGIN attribute: If at least one route among routes that are | |
4912 | aggregated has ORIGIN with the value INCOMPLETE, then the | |
4913 | aggregated route must have the ORIGIN attribute with the value | |
4914 | INCOMPLETE. Otherwise, if at least one route among routes that | |
4915 | are aggregated has ORIGIN with the value EGP, then the aggregated | |
4916 | route must have the origin attribute with the value EGP. In all | |
4917 | other case the value of the ORIGIN attribute of the aggregated | |
4918 | route is INTERNAL. */ | |
4919 | origin = BGP_ORIGIN_IGP; | |
4920 | ||
4921 | table = bgp->rib[afi][safi]; | |
4922 | ||
4923 | top = bgp_node_get (table, p); | |
4924 | for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top)) | |
4925 | if (rn->p.prefixlen > p->prefixlen) | |
4926 | { | |
4927 | match = 0; | |
4928 | ||
4929 | for (ri = rn->info; ri; ri = ri->next) | |
4930 | { | |
4931 | if (BGP_INFO_HOLDDOWN (ri)) | |
4932 | continue; | |
4933 | ||
4934 | if (del && ri == del) | |
4935 | continue; | |
4936 | ||
4937 | if (! rinew && first) | |
4938 | { | |
ffd0c037 | 4939 | #if defined(AGGREGATE_NEXTHOP_CHECK) |
718e3744 | 4940 | nexthop = ri->attr->nexthop; |
4941 | med = ri->attr->med; | |
ffd0c037 | 4942 | #endif |
718e3744 | 4943 | first = 0; |
4944 | } | |
4945 | ||
4946 | #ifdef AGGREGATE_NEXTHOP_CHECK | |
4947 | if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop) | |
4948 | || ri->attr->med != med) | |
4949 | { | |
4950 | if (aspath) | |
4951 | aspath_free (aspath); | |
4952 | if (community) | |
4953 | community_free (community); | |
4954 | bgp_unlock_node (rn); | |
4955 | bgp_unlock_node (top); | |
4956 | return; | |
4957 | } | |
4958 | #endif /* AGGREGATE_NEXTHOP_CHECK */ | |
4959 | ||
42f7e184 DS |
4960 | if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)) |
4961 | atomic_aggregate = 1; | |
4962 | ||
718e3744 | 4963 | if (ri->sub_type != BGP_ROUTE_AGGREGATE) |
4964 | { | |
4965 | if (aggregate->summary_only) | |
4966 | { | |
fb982c25 | 4967 | (bgp_info_extra_get (ri))->suppress++; |
1a392d46 | 4968 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
718e3744 | 4969 | match++; |
4970 | } | |
4971 | ||
4972 | aggregate->count++; | |
4973 | ||
b5d58c32 DS |
4974 | if (origin < ri->attr->origin) |
4975 | origin = ri->attr->origin; | |
4976 | ||
718e3744 | 4977 | if (aggregate->as_set) |
4978 | { | |
718e3744 | 4979 | if (aspath) |
4980 | { | |
4981 | asmerge = aspath_aggregate (aspath, ri->attr->aspath); | |
4982 | aspath_free (aspath); | |
4983 | aspath = asmerge; | |
4984 | } | |
4985 | else | |
4986 | aspath = aspath_dup (ri->attr->aspath); | |
4987 | ||
4988 | if (ri->attr->community) | |
4989 | { | |
4990 | if (community) | |
4991 | { | |
4992 | commerge = community_merge (community, | |
4993 | ri->attr->community); | |
4994 | community = community_uniq_sort (commerge); | |
4995 | community_free (commerge); | |
4996 | } | |
4997 | else | |
4998 | community = community_dup (ri->attr->community); | |
4999 | } | |
5000 | } | |
5001 | } | |
5002 | } | |
5003 | if (match) | |
5004 | bgp_process (bgp, rn, afi, safi); | |
5005 | } | |
5006 | bgp_unlock_node (top); | |
5007 | ||
5008 | if (rinew) | |
5009 | { | |
5010 | aggregate->count++; | |
5011 | ||
5012 | if (aggregate->summary_only) | |
fb982c25 | 5013 | (bgp_info_extra_get (rinew))->suppress++; |
718e3744 | 5014 | |
b5d58c32 DS |
5015 | if (origin < rinew->attr->origin) |
5016 | origin = rinew->attr->origin; | |
5017 | ||
718e3744 | 5018 | if (aggregate->as_set) |
5019 | { | |
718e3744 | 5020 | if (aspath) |
5021 | { | |
5022 | asmerge = aspath_aggregate (aspath, rinew->attr->aspath); | |
5023 | aspath_free (aspath); | |
5024 | aspath = asmerge; | |
5025 | } | |
5026 | else | |
5027 | aspath = aspath_dup (rinew->attr->aspath); | |
5028 | ||
5029 | if (rinew->attr->community) | |
5030 | { | |
5031 | if (community) | |
5032 | { | |
5033 | commerge = community_merge (community, | |
5034 | rinew->attr->community); | |
5035 | community = community_uniq_sort (commerge); | |
5036 | community_free (commerge); | |
5037 | } | |
5038 | else | |
5039 | community = community_dup (rinew->attr->community); | |
5040 | } | |
5041 | } | |
5042 | } | |
5043 | ||
5044 | if (aggregate->count > 0) | |
5045 | { | |
5046 | rn = bgp_node_get (table, p); | |
7c8ff89e | 5047 | new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self, |
fb018d25 | 5048 | bgp_attr_aggregate_intern(bgp, origin, aspath, community, |
42f7e184 DS |
5049 | aggregate->as_set, |
5050 | atomic_aggregate), rn); | |
718e3744 | 5051 | SET_FLAG (new->flags, BGP_INFO_VALID); |
718e3744 | 5052 | |
5053 | bgp_info_add (rn, new); | |
200df115 | 5054 | bgp_unlock_node (rn); |
718e3744 | 5055 | bgp_process (bgp, rn, afi, safi); |
5056 | } | |
5057 | else | |
5058 | { | |
5059 | if (aspath) | |
5060 | aspath_free (aspath); | |
5061 | if (community) | |
5062 | community_free (community); | |
5063 | } | |
5064 | } | |
5065 | ||
5066 | void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t, | |
5067 | struct bgp_aggregate *); | |
5068 | ||
5069 | void | |
5070 | bgp_aggregate_increment (struct bgp *bgp, struct prefix *p, | |
5071 | struct bgp_info *ri, afi_t afi, safi_t safi) | |
5072 | { | |
5073 | struct bgp_node *child; | |
5074 | struct bgp_node *rn; | |
5075 | struct bgp_aggregate *aggregate; | |
f018db83 | 5076 | struct bgp_table *table; |
718e3744 | 5077 | |
5078 | /* MPLS-VPN aggregation is not yet supported. */ | |
587ff0fd | 5079 | if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) |
718e3744 | 5080 | return; |
5081 | ||
f018db83 JBD |
5082 | table = bgp->aggregate[afi][safi]; |
5083 | ||
5084 | /* No aggregates configured. */ | |
67174041 | 5085 | if (bgp_table_top_nolock (table) == NULL) |
f018db83 JBD |
5086 | return; |
5087 | ||
718e3744 | 5088 | if (p->prefixlen == 0) |
5089 | return; | |
5090 | ||
5091 | if (BGP_INFO_HOLDDOWN (ri)) | |
5092 | return; | |
5093 | ||
bb782fb5 | 5094 | child = bgp_node_get (table, p); |
718e3744 | 5095 | |
5096 | /* Aggregate address configuration check. */ | |
67174041 | 5097 | for (rn = child; rn; rn = bgp_node_parent_nolock (rn)) |
718e3744 | 5098 | if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen) |
5099 | { | |
5100 | bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate); | |
286e1e71 | 5101 | bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate); |
718e3744 | 5102 | } |
5103 | bgp_unlock_node (child); | |
5104 | } | |
5105 | ||
5106 | void | |
5107 | bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p, | |
5108 | struct bgp_info *del, afi_t afi, safi_t safi) | |
5109 | { | |
5110 | struct bgp_node *child; | |
5111 | struct bgp_node *rn; | |
5112 | struct bgp_aggregate *aggregate; | |
f018db83 | 5113 | struct bgp_table *table; |
718e3744 | 5114 | |
5115 | /* MPLS-VPN aggregation is not yet supported. */ | |
587ff0fd | 5116 | if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) |
718e3744 | 5117 | return; |
5118 | ||
f018db83 JBD |
5119 | table = bgp->aggregate[afi][safi]; |
5120 | ||
5121 | /* No aggregates configured. */ | |
67174041 | 5122 | if (bgp_table_top_nolock (table) == NULL) |
f018db83 JBD |
5123 | return; |
5124 | ||
718e3744 | 5125 | if (p->prefixlen == 0) |
5126 | return; | |
5127 | ||
bb782fb5 | 5128 | child = bgp_node_get (table, p); |
718e3744 | 5129 | |
5130 | /* Aggregate address configuration check. */ | |
67174041 | 5131 | for (rn = child; rn; rn = bgp_node_parent_nolock (rn)) |
718e3744 | 5132 | if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen) |
5133 | { | |
5134 | bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate); | |
286e1e71 | 5135 | bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate); |
718e3744 | 5136 | } |
5137 | bgp_unlock_node (child); | |
5138 | } | |
5139 | ||
b5d58c32 | 5140 | /* Called via bgp_aggregate_set when the user configures aggregate-address */ |
94f2b392 | 5141 | static void |
718e3744 | 5142 | bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi, |
5143 | struct bgp_aggregate *aggregate) | |
5144 | { | |
5145 | struct bgp_table *table; | |
5146 | struct bgp_node *top; | |
5147 | struct bgp_node *rn; | |
5148 | struct bgp_info *new; | |
5149 | struct bgp_info *ri; | |
5150 | unsigned long match; | |
5151 | u_char origin = BGP_ORIGIN_IGP; | |
5152 | struct aspath *aspath = NULL; | |
5153 | struct aspath *asmerge = NULL; | |
5154 | struct community *community = NULL; | |
5155 | struct community *commerge = NULL; | |
42f7e184 | 5156 | u_char atomic_aggregate = 0; |
718e3744 | 5157 | |
5158 | table = bgp->rib[afi][safi]; | |
5159 | ||
5160 | /* Sanity check. */ | |
5161 | if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN) | |
5162 | return; | |
5163 | if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN) | |
5164 | return; | |
5165 | ||
5166 | /* If routes exists below this node, generate aggregate routes. */ | |
5167 | top = bgp_node_get (table, p); | |
5168 | for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top)) | |
5169 | if (rn->p.prefixlen > p->prefixlen) | |
5170 | { | |
5171 | match = 0; | |
5172 | ||
5173 | for (ri = rn->info; ri; ri = ri->next) | |
5174 | { | |
5175 | if (BGP_INFO_HOLDDOWN (ri)) | |
5176 | continue; | |
5177 | ||
42f7e184 DS |
5178 | if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)) |
5179 | atomic_aggregate = 1; | |
5180 | ||
718e3744 | 5181 | if (ri->sub_type != BGP_ROUTE_AGGREGATE) |
5182 | { | |
5183 | /* summary-only aggregate route suppress aggregated | |
5184 | route announcement. */ | |
5185 | if (aggregate->summary_only) | |
5186 | { | |
fb982c25 | 5187 | (bgp_info_extra_get (ri))->suppress++; |
1a392d46 | 5188 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
718e3744 | 5189 | match++; |
5190 | } | |
b5d58c32 DS |
5191 | |
5192 | /* If at least one route among routes that are aggregated has | |
5193 | * ORIGIN with the value INCOMPLETE, then the aggregated route | |
5194 | * MUST have the ORIGIN attribute with the value INCOMPLETE. | |
5195 | * Otherwise, if at least one route among routes that are | |
5196 | * aggregated has ORIGIN with the value EGP, then the aggregated | |
5197 | * route MUST have the ORIGIN attribute with the value EGP. | |
5198 | */ | |
5199 | if (origin < ri->attr->origin) | |
5200 | origin = ri->attr->origin; | |
5201 | ||
718e3744 | 5202 | /* as-set aggregate route generate origin, as path, |
5203 | community aggregation. */ | |
5204 | if (aggregate->as_set) | |
5205 | { | |
718e3744 | 5206 | if (aspath) |
5207 | { | |
5208 | asmerge = aspath_aggregate (aspath, ri->attr->aspath); | |
5209 | aspath_free (aspath); | |
5210 | aspath = asmerge; | |
5211 | } | |
5212 | else | |
5213 | aspath = aspath_dup (ri->attr->aspath); | |
5214 | ||
5215 | if (ri->attr->community) | |
5216 | { | |
5217 | if (community) | |
5218 | { | |
5219 | commerge = community_merge (community, | |
5220 | ri->attr->community); | |
5221 | community = community_uniq_sort (commerge); | |
5222 | community_free (commerge); | |
5223 | } | |
5224 | else | |
5225 | community = community_dup (ri->attr->community); | |
5226 | } | |
5227 | } | |
5228 | aggregate->count++; | |
5229 | } | |
5230 | } | |
5231 | ||
5232 | /* If this node is suppressed, process the change. */ | |
5233 | if (match) | |
5234 | bgp_process (bgp, rn, afi, safi); | |
5235 | } | |
5236 | bgp_unlock_node (top); | |
5237 | ||
5238 | /* Add aggregate route to BGP table. */ | |
5239 | if (aggregate->count) | |
5240 | { | |
5241 | rn = bgp_node_get (table, p); | |
7c8ff89e | 5242 | new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self, |
fb018d25 | 5243 | bgp_attr_aggregate_intern(bgp, origin, aspath, community, |
42f7e184 DS |
5244 | aggregate->as_set, |
5245 | atomic_aggregate), rn); | |
718e3744 | 5246 | SET_FLAG (new->flags, BGP_INFO_VALID); |
718e3744 | 5247 | |
5248 | bgp_info_add (rn, new); | |
200df115 | 5249 | bgp_unlock_node (rn); |
5250 | ||
718e3744 | 5251 | /* Process change. */ |
5252 | bgp_process (bgp, rn, afi, safi); | |
5253 | } | |
610f23cf DV |
5254 | else |
5255 | { | |
5256 | if (aspath) | |
5257 | aspath_free (aspath); | |
5258 | if (community) | |
5259 | community_free (community); | |
5260 | } | |
718e3744 | 5261 | } |
5262 | ||
5263 | void | |
5264 | bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi, | |
5265 | safi_t safi, struct bgp_aggregate *aggregate) | |
5266 | { | |
5267 | struct bgp_table *table; | |
5268 | struct bgp_node *top; | |
5269 | struct bgp_node *rn; | |
5270 | struct bgp_info *ri; | |
5271 | unsigned long match; | |
5272 | ||
5273 | table = bgp->rib[afi][safi]; | |
5274 | ||
5275 | if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN) | |
5276 | return; | |
5277 | if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN) | |
5278 | return; | |
5279 | ||
5280 | /* If routes exists below this node, generate aggregate routes. */ | |
5281 | top = bgp_node_get (table, p); | |
5282 | for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top)) | |
5283 | if (rn->p.prefixlen > p->prefixlen) | |
5284 | { | |
5285 | match = 0; | |
5286 | ||
5287 | for (ri = rn->info; ri; ri = ri->next) | |
5288 | { | |
5289 | if (BGP_INFO_HOLDDOWN (ri)) | |
5290 | continue; | |
5291 | ||
5292 | if (ri->sub_type != BGP_ROUTE_AGGREGATE) | |
5293 | { | |
fb982c25 | 5294 | if (aggregate->summary_only && ri->extra) |
718e3744 | 5295 | { |
fb982c25 | 5296 | ri->extra->suppress--; |
718e3744 | 5297 | |
fb982c25 | 5298 | if (ri->extra->suppress == 0) |
718e3744 | 5299 | { |
1a392d46 | 5300 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
718e3744 | 5301 | match++; |
5302 | } | |
5303 | } | |
5304 | aggregate->count--; | |
5305 | } | |
5306 | } | |
5307 | ||
fb982c25 | 5308 | /* If this node was suppressed, process the change. */ |
718e3744 | 5309 | if (match) |
5310 | bgp_process (bgp, rn, afi, safi); | |
5311 | } | |
5312 | bgp_unlock_node (top); | |
5313 | ||
5314 | /* Delete aggregate route from BGP table. */ | |
5315 | rn = bgp_node_get (table, p); | |
5316 | ||
5317 | for (ri = rn->info; ri; ri = ri->next) | |
5318 | if (ri->peer == bgp->peer_self | |
5319 | && ri->type == ZEBRA_ROUTE_BGP | |
5320 | && ri->sub_type == BGP_ROUTE_AGGREGATE) | |
5321 | break; | |
5322 | ||
5323 | /* Withdraw static BGP route from routing table. */ | |
5324 | if (ri) | |
5325 | { | |
718e3744 | 5326 | bgp_info_delete (rn, ri); |
1a392d46 | 5327 | bgp_process (bgp, rn, afi, safi); |
718e3744 | 5328 | } |
5329 | ||
5330 | /* Unlock bgp_node_lookup. */ | |
5331 | bgp_unlock_node (rn); | |
5332 | } | |
5333 | ||
5334 | /* Aggregate route attribute. */ | |
5335 | #define AGGREGATE_SUMMARY_ONLY 1 | |
5336 | #define AGGREGATE_AS_SET 1 | |
5337 | ||
94f2b392 | 5338 | static int |
f6269b4f RB |
5339 | bgp_aggregate_unset (struct vty *vty, const char *prefix_str, |
5340 | afi_t afi, safi_t safi) | |
718e3744 | 5341 | { |
5342 | int ret; | |
5343 | struct prefix p; | |
5344 | struct bgp_node *rn; | |
5345 | struct bgp *bgp; | |
5346 | struct bgp_aggregate *aggregate; | |
5347 | ||
5348 | /* Convert string to prefix structure. */ | |
5349 | ret = str2prefix (prefix_str, &p); | |
5350 | if (!ret) | |
5351 | { | |
5352 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); | |
5353 | return CMD_WARNING; | |
5354 | } | |
5355 | apply_mask (&p); | |
5356 | ||
5357 | /* Get BGP structure. */ | |
5358 | bgp = vty->index; | |
5359 | ||
5360 | /* Old configuration check. */ | |
f6269b4f RB |
5361 | rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p); |
5362 | if (! rn) | |
718e3744 | 5363 | { |
f6269b4f RB |
5364 | vty_out (vty, "%% There is no aggregate-address configuration.%s", |
5365 | VTY_NEWLINE); | |
718e3744 | 5366 | return CMD_WARNING; |
5367 | } | |
5368 | ||
f6269b4f RB |
5369 | aggregate = rn->info; |
5370 | if (aggregate->safi & SAFI_UNICAST) | |
5371 | bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate); | |
5372 | if (aggregate->safi & SAFI_MULTICAST) | |
5373 | bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate); | |
718e3744 | 5374 | |
f6269b4f RB |
5375 | /* Unlock aggregate address configuration. */ |
5376 | rn->info = NULL; | |
5377 | bgp_aggregate_free (aggregate); | |
5378 | bgp_unlock_node (rn); | |
5379 | bgp_unlock_node (rn); | |
718e3744 | 5380 | |
5381 | return CMD_SUCCESS; | |
5382 | } | |
5383 | ||
94f2b392 | 5384 | static int |
f6269b4f RB |
5385 | bgp_aggregate_set (struct vty *vty, const char *prefix_str, |
5386 | afi_t afi, safi_t safi, | |
5387 | u_char summary_only, u_char as_set) | |
718e3744 | 5388 | { |
5389 | int ret; | |
5390 | struct prefix p; | |
5391 | struct bgp_node *rn; | |
5392 | struct bgp *bgp; | |
5393 | struct bgp_aggregate *aggregate; | |
5394 | ||
5395 | /* Convert string to prefix structure. */ | |
5396 | ret = str2prefix (prefix_str, &p); | |
5397 | if (!ret) | |
5398 | { | |
5399 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); | |
5400 | return CMD_WARNING; | |
5401 | } | |
5402 | apply_mask (&p); | |
5403 | ||
5404 | /* Get BGP structure. */ | |
5405 | bgp = vty->index; | |
5406 | ||
5407 | /* Old configuration check. */ | |
f6269b4f RB |
5408 | rn = bgp_node_get (bgp->aggregate[afi][safi], &p); |
5409 | ||
5410 | if (rn->info) | |
718e3744 | 5411 | { |
f6269b4f | 5412 | vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE); |
368473f6 | 5413 | /* try to remove the old entry */ |
f6269b4f RB |
5414 | ret = bgp_aggregate_unset (vty, prefix_str, afi, safi); |
5415 | if (ret) | |
5416 | { | |
368473f6 RB |
5417 | vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE); |
5418 | bgp_unlock_node (rn); | |
f6269b4f RB |
5419 | return CMD_WARNING; |
5420 | } | |
718e3744 | 5421 | } |
5422 | ||
f6269b4f RB |
5423 | /* Make aggregate address structure. */ |
5424 | aggregate = bgp_aggregate_new (); | |
5425 | aggregate->summary_only = summary_only; | |
5426 | aggregate->as_set = as_set; | |
5427 | aggregate->safi = safi; | |
5428 | rn->info = aggregate; | |
718e3744 | 5429 | |
f6269b4f RB |
5430 | /* Aggregate address insert into BGP routing table. */ |
5431 | if (safi & SAFI_UNICAST) | |
5432 | bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate); | |
5433 | if (safi & SAFI_MULTICAST) | |
5434 | bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate); | |
718e3744 | 5435 | |
5436 | return CMD_SUCCESS; | |
5437 | } | |
5438 | ||
5439 | DEFUN (aggregate_address, | |
5440 | aggregate_address_cmd, | |
5441 | "aggregate-address A.B.C.D/M", | |
5442 | "Configure BGP aggregate entries\n" | |
5443 | "Aggregate prefix\n") | |
5444 | { | |
5445 | return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0); | |
5446 | } | |
5447 | ||
5448 | DEFUN (aggregate_address_mask, | |
5449 | aggregate_address_mask_cmd, | |
5450 | "aggregate-address A.B.C.D A.B.C.D", | |
5451 | "Configure BGP aggregate entries\n" | |
5452 | "Aggregate address\n" | |
5453 | "Aggregate mask\n") | |
5454 | { | |
5455 | int ret; | |
5456 | char prefix_str[BUFSIZ]; | |
5457 | ||
5458 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); | |
5459 | ||
5460 | if (! ret) | |
5461 | { | |
5462 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
5463 | return CMD_WARNING; | |
5464 | } | |
5465 | ||
5466 | return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty), | |
5467 | 0, 0); | |
5468 | } | |
5469 | ||
5470 | DEFUN (aggregate_address_summary_only, | |
5471 | aggregate_address_summary_only_cmd, | |
5472 | "aggregate-address A.B.C.D/M summary-only", | |
5473 | "Configure BGP aggregate entries\n" | |
5474 | "Aggregate prefix\n" | |
5475 | "Filter more specific routes from updates\n") | |
5476 | { | |
5477 | return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), | |
5478 | AGGREGATE_SUMMARY_ONLY, 0); | |
5479 | } | |
5480 | ||
5481 | DEFUN (aggregate_address_mask_summary_only, | |
5482 | aggregate_address_mask_summary_only_cmd, | |
5483 | "aggregate-address A.B.C.D A.B.C.D summary-only", | |
5484 | "Configure BGP aggregate entries\n" | |
5485 | "Aggregate address\n" | |
5486 | "Aggregate mask\n" | |
5487 | "Filter more specific routes from updates\n") | |
5488 | { | |
5489 | int ret; | |
5490 | char prefix_str[BUFSIZ]; | |
5491 | ||
5492 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); | |
5493 | ||
5494 | if (! ret) | |
5495 | { | |
5496 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
5497 | return CMD_WARNING; | |
5498 | } | |
5499 | ||
5500 | return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty), | |
5501 | AGGREGATE_SUMMARY_ONLY, 0); | |
5502 | } | |
5503 | ||
5504 | DEFUN (aggregate_address_as_set, | |
5505 | aggregate_address_as_set_cmd, | |
5506 | "aggregate-address A.B.C.D/M as-set", | |
5507 | "Configure BGP aggregate entries\n" | |
5508 | "Aggregate prefix\n" | |
5509 | "Generate AS set path information\n") | |
5510 | { | |
5511 | return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), | |
5512 | 0, AGGREGATE_AS_SET); | |
5513 | } | |
5514 | ||
5515 | DEFUN (aggregate_address_mask_as_set, | |
5516 | aggregate_address_mask_as_set_cmd, | |
5517 | "aggregate-address A.B.C.D A.B.C.D as-set", | |
5518 | "Configure BGP aggregate entries\n" | |
5519 | "Aggregate address\n" | |
5520 | "Aggregate mask\n" | |
5521 | "Generate AS set path information\n") | |
5522 | { | |
5523 | int ret; | |
5524 | char prefix_str[BUFSIZ]; | |
5525 | ||
5526 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); | |
5527 | ||
5528 | if (! ret) | |
5529 | { | |
5530 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
5531 | return CMD_WARNING; | |
5532 | } | |
5533 | ||
5534 | return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty), | |
5535 | 0, AGGREGATE_AS_SET); | |
5536 | } | |
5537 | ||
5538 | ||
5539 | DEFUN (aggregate_address_as_set_summary, | |
5540 | aggregate_address_as_set_summary_cmd, | |
5541 | "aggregate-address A.B.C.D/M as-set summary-only", | |
5542 | "Configure BGP aggregate entries\n" | |
5543 | "Aggregate prefix\n" | |
5544 | "Generate AS set path information\n" | |
5545 | "Filter more specific routes from updates\n") | |
5546 | { | |
5547 | return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), | |
5548 | AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET); | |
5549 | } | |
5550 | ||
5551 | ALIAS (aggregate_address_as_set_summary, | |
5552 | aggregate_address_summary_as_set_cmd, | |
5553 | "aggregate-address A.B.C.D/M summary-only as-set", | |
5554 | "Configure BGP aggregate entries\n" | |
5555 | "Aggregate prefix\n" | |
5556 | "Filter more specific routes from updates\n" | |
5557 | "Generate AS set path information\n") | |
5558 | ||
5559 | DEFUN (aggregate_address_mask_as_set_summary, | |
5560 | aggregate_address_mask_as_set_summary_cmd, | |
5561 | "aggregate-address A.B.C.D A.B.C.D as-set summary-only", | |
5562 | "Configure BGP aggregate entries\n" | |
5563 | "Aggregate address\n" | |
5564 | "Aggregate mask\n" | |
5565 | "Generate AS set path information\n" | |
5566 | "Filter more specific routes from updates\n") | |
5567 | { | |
5568 | int ret; | |
5569 | char prefix_str[BUFSIZ]; | |
5570 | ||
5571 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); | |
5572 | ||
5573 | if (! ret) | |
5574 | { | |
5575 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
5576 | return CMD_WARNING; | |
5577 | } | |
5578 | ||
5579 | return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty), | |
5580 | AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET); | |
5581 | } | |
5582 | ||
5583 | ALIAS (aggregate_address_mask_as_set_summary, | |
5584 | aggregate_address_mask_summary_as_set_cmd, | |
5585 | "aggregate-address A.B.C.D A.B.C.D summary-only as-set", | |
5586 | "Configure BGP aggregate entries\n" | |
5587 | "Aggregate address\n" | |
5588 | "Aggregate mask\n" | |
5589 | "Filter more specific routes from updates\n" | |
5590 | "Generate AS set path information\n") | |
5591 | ||
5592 | DEFUN (no_aggregate_address, | |
5593 | no_aggregate_address_cmd, | |
5594 | "no aggregate-address A.B.C.D/M", | |
5595 | NO_STR | |
5596 | "Configure BGP aggregate entries\n" | |
5597 | "Aggregate prefix\n") | |
5598 | { | |
5599 | return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty)); | |
5600 | } | |
5601 | ||
5602 | ALIAS (no_aggregate_address, | |
5603 | no_aggregate_address_summary_only_cmd, | |
5604 | "no aggregate-address A.B.C.D/M summary-only", | |
5605 | NO_STR | |
5606 | "Configure BGP aggregate entries\n" | |
5607 | "Aggregate prefix\n" | |
5608 | "Filter more specific routes from updates\n") | |
5609 | ||
5610 | ALIAS (no_aggregate_address, | |
5611 | no_aggregate_address_as_set_cmd, | |
5612 | "no aggregate-address A.B.C.D/M as-set", | |
5613 | NO_STR | |
5614 | "Configure BGP aggregate entries\n" | |
5615 | "Aggregate prefix\n" | |
5616 | "Generate AS set path information\n") | |
5617 | ||
5618 | ALIAS (no_aggregate_address, | |
5619 | no_aggregate_address_as_set_summary_cmd, | |
5620 | "no aggregate-address A.B.C.D/M as-set summary-only", | |
5621 | NO_STR | |
5622 | "Configure BGP aggregate entries\n" | |
5623 | "Aggregate prefix\n" | |
5624 | "Generate AS set path information\n" | |
5625 | "Filter more specific routes from updates\n") | |
5626 | ||
5627 | ALIAS (no_aggregate_address, | |
5628 | no_aggregate_address_summary_as_set_cmd, | |
5629 | "no aggregate-address A.B.C.D/M summary-only as-set", | |
5630 | NO_STR | |
5631 | "Configure BGP aggregate entries\n" | |
5632 | "Aggregate prefix\n" | |
5633 | "Filter more specific routes from updates\n" | |
5634 | "Generate AS set path information\n") | |
5635 | ||
5636 | DEFUN (no_aggregate_address_mask, | |
5637 | no_aggregate_address_mask_cmd, | |
5638 | "no aggregate-address A.B.C.D A.B.C.D", | |
5639 | NO_STR | |
5640 | "Configure BGP aggregate entries\n" | |
5641 | "Aggregate address\n" | |
5642 | "Aggregate mask\n") | |
5643 | { | |
5644 | int ret; | |
5645 | char prefix_str[BUFSIZ]; | |
5646 | ||
5647 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); | |
5648 | ||
5649 | if (! ret) | |
5650 | { | |
5651 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
5652 | return CMD_WARNING; | |
5653 | } | |
5654 | ||
5655 | return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty)); | |
5656 | } | |
5657 | ||
5658 | ALIAS (no_aggregate_address_mask, | |
5659 | no_aggregate_address_mask_summary_only_cmd, | |
5660 | "no aggregate-address A.B.C.D A.B.C.D summary-only", | |
5661 | NO_STR | |
5662 | "Configure BGP aggregate entries\n" | |
5663 | "Aggregate address\n" | |
5664 | "Aggregate mask\n" | |
5665 | "Filter more specific routes from updates\n") | |
5666 | ||
5667 | ALIAS (no_aggregate_address_mask, | |
5668 | no_aggregate_address_mask_as_set_cmd, | |
5669 | "no aggregate-address A.B.C.D A.B.C.D as-set", | |
5670 | NO_STR | |
5671 | "Configure BGP aggregate entries\n" | |
5672 | "Aggregate address\n" | |
5673 | "Aggregate mask\n" | |
5674 | "Generate AS set path information\n") | |
5675 | ||
5676 | ALIAS (no_aggregate_address_mask, | |
5677 | no_aggregate_address_mask_as_set_summary_cmd, | |
5678 | "no aggregate-address A.B.C.D A.B.C.D as-set summary-only", | |
5679 | NO_STR | |
5680 | "Configure BGP aggregate entries\n" | |
5681 | "Aggregate address\n" | |
5682 | "Aggregate mask\n" | |
5683 | "Generate AS set path information\n" | |
5684 | "Filter more specific routes from updates\n") | |
5685 | ||
5686 | ALIAS (no_aggregate_address_mask, | |
5687 | no_aggregate_address_mask_summary_as_set_cmd, | |
5688 | "no aggregate-address A.B.C.D A.B.C.D summary-only as-set", | |
5689 | NO_STR | |
5690 | "Configure BGP aggregate entries\n" | |
5691 | "Aggregate address\n" | |
5692 | "Aggregate mask\n" | |
5693 | "Filter more specific routes from updates\n" | |
5694 | "Generate AS set path information\n") | |
5695 | ||
5696 | #ifdef HAVE_IPV6 | |
5697 | DEFUN (ipv6_aggregate_address, | |
5698 | ipv6_aggregate_address_cmd, | |
5699 | "aggregate-address X:X::X:X/M", | |
5700 | "Configure BGP aggregate entries\n" | |
5701 | "Aggregate prefix\n") | |
5702 | { | |
5703 | return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0); | |
5704 | } | |
5705 | ||
5706 | DEFUN (ipv6_aggregate_address_summary_only, | |
5707 | ipv6_aggregate_address_summary_only_cmd, | |
5708 | "aggregate-address X:X::X:X/M summary-only", | |
5709 | "Configure BGP aggregate entries\n" | |
5710 | "Aggregate prefix\n" | |
5711 | "Filter more specific routes from updates\n") | |
5712 | { | |
5713 | return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, | |
5714 | AGGREGATE_SUMMARY_ONLY, 0); | |
5715 | } | |
5716 | ||
5717 | DEFUN (no_ipv6_aggregate_address, | |
5718 | no_ipv6_aggregate_address_cmd, | |
5719 | "no aggregate-address X:X::X:X/M", | |
5720 | NO_STR | |
5721 | "Configure BGP aggregate entries\n" | |
5722 | "Aggregate prefix\n") | |
5723 | { | |
5724 | return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST); | |
5725 | } | |
5726 | ||
5727 | DEFUN (no_ipv6_aggregate_address_summary_only, | |
5728 | no_ipv6_aggregate_address_summary_only_cmd, | |
5729 | "no aggregate-address X:X::X:X/M summary-only", | |
5730 | NO_STR | |
5731 | "Configure BGP aggregate entries\n" | |
5732 | "Aggregate prefix\n" | |
5733 | "Filter more specific routes from updates\n") | |
5734 | { | |
5735 | return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST); | |
5736 | } | |
5737 | ||
5738 | ALIAS (ipv6_aggregate_address, | |
5739 | old_ipv6_aggregate_address_cmd, | |
5740 | "ipv6 bgp aggregate-address X:X::X:X/M", | |
5741 | IPV6_STR | |
5742 | BGP_STR | |
5743 | "Configure BGP aggregate entries\n" | |
5744 | "Aggregate prefix\n") | |
5745 | ||
5746 | ALIAS (ipv6_aggregate_address_summary_only, | |
5747 | old_ipv6_aggregate_address_summary_only_cmd, | |
5748 | "ipv6 bgp aggregate-address X:X::X:X/M summary-only", | |
5749 | IPV6_STR | |
5750 | BGP_STR | |
5751 | "Configure BGP aggregate entries\n" | |
5752 | "Aggregate prefix\n" | |
5753 | "Filter more specific routes from updates\n") | |
5754 | ||
5755 | ALIAS (no_ipv6_aggregate_address, | |
5756 | old_no_ipv6_aggregate_address_cmd, | |
5757 | "no ipv6 bgp aggregate-address X:X::X:X/M", | |
5758 | NO_STR | |
5759 | IPV6_STR | |
5760 | BGP_STR | |
5761 | "Configure BGP aggregate entries\n" | |
5762 | "Aggregate prefix\n") | |
5763 | ||
5764 | ALIAS (no_ipv6_aggregate_address_summary_only, | |
5765 | old_no_ipv6_aggregate_address_summary_only_cmd, | |
5766 | "no ipv6 bgp aggregate-address X:X::X:X/M summary-only", | |
5767 | NO_STR | |
5768 | IPV6_STR | |
5769 | BGP_STR | |
5770 | "Configure BGP aggregate entries\n" | |
5771 | "Aggregate prefix\n" | |
5772 | "Filter more specific routes from updates\n") | |
5773 | #endif /* HAVE_IPV6 */ | |
6b0655a2 | 5774 | |
718e3744 | 5775 | /* Redistribute route treatment. */ |
5776 | void | |
6aeb9e78 | 5777 | bgp_redistribute_add (struct bgp *bgp, struct prefix *p, const struct in_addr *nexthop, |
bc413143 | 5778 | const struct in6_addr *nexthop6, unsigned int ifindex, |
dc9ffce8 | 5779 | u_int32_t metric, u_char type, u_short instance, route_tag_t tag) |
718e3744 | 5780 | { |
718e3744 | 5781 | struct bgp_info *new; |
5782 | struct bgp_info *bi; | |
5783 | struct bgp_info info; | |
5784 | struct bgp_node *bn; | |
e16a4133 | 5785 | struct attr attr; |
718e3744 | 5786 | struct attr *new_attr; |
5787 | afi_t afi; | |
5788 | int ret; | |
7c8ff89e | 5789 | struct bgp_redist *red; |
718e3744 | 5790 | |
5791 | /* Make default attribute. */ | |
5792 | bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE); | |
5793 | if (nexthop) | |
5794 | attr.nexthop = *nexthop; | |
bc413143 | 5795 | attr.nh_ifindex = ifindex; |
718e3744 | 5796 | |
f04a80a5 SH |
5797 | #ifdef HAVE_IPV6 |
5798 | if (nexthop6) | |
5799 | { | |
5800 | struct attr_extra *extra = bgp_attr_extra_get(&attr); | |
5801 | extra->mp_nexthop_global = *nexthop6; | |
801a9bcc | 5802 | extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL; |
f04a80a5 SH |
5803 | } |
5804 | #endif | |
5805 | ||
718e3744 | 5806 | attr.med = metric; |
5807 | attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC); | |
0d9551dc | 5808 | attr.extra->tag = tag; |
718e3744 | 5809 | |
6aeb9e78 DS |
5810 | afi = family2afi (p->family); |
5811 | ||
5812 | red = bgp_redist_lookup(bgp, afi, type, instance); | |
5813 | if (red) | |
718e3744 | 5814 | { |
6aeb9e78 DS |
5815 | struct attr attr_new; |
5816 | struct attr_extra extra_new; | |
718e3744 | 5817 | |
6aeb9e78 DS |
5818 | /* Copy attribute for modification. */ |
5819 | attr_new.extra = &extra_new; | |
5820 | bgp_attr_dup (&attr_new, &attr); | |
558d1fec | 5821 | |
6aeb9e78 DS |
5822 | if (red->redist_metric_flag) |
5823 | attr_new.med = red->redist_metric; | |
718e3744 | 5824 | |
6aeb9e78 DS |
5825 | /* Apply route-map. */ |
5826 | if (red->rmap.name) | |
5827 | { | |
5828 | info.peer = bgp->peer_self; | |
5829 | info.attr = &attr_new; | |
718e3744 | 5830 | |
6aeb9e78 | 5831 | SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE); |
718e3744 | 5832 | |
6aeb9e78 | 5833 | ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info); |
fee0f4c6 | 5834 | |
6aeb9e78 | 5835 | bgp->peer_self->rmap_type = 0; |
fee0f4c6 | 5836 | |
6aeb9e78 DS |
5837 | if (ret == RMAP_DENYMATCH) |
5838 | { | |
5839 | /* Free uninterned attribute. */ | |
5840 | bgp_attr_flush (&attr_new); | |
5841 | ||
5842 | /* Unintern original. */ | |
5843 | aspath_unintern (&attr.aspath); | |
5844 | bgp_attr_extra_free (&attr); | |
5845 | bgp_redistribute_delete (bgp, p, type, instance); | |
5846 | return; | |
5847 | } | |
5848 | } | |
fee0f4c6 | 5849 | |
6aeb9e78 DS |
5850 | bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], |
5851 | afi, SAFI_UNICAST, p, NULL); | |
718e3744 | 5852 | |
6aeb9e78 | 5853 | new_attr = bgp_attr_intern (&attr_new); |
558d1fec | 5854 | |
6aeb9e78 DS |
5855 | for (bi = bn->info; bi; bi = bi->next) |
5856 | if (bi->peer == bgp->peer_self | |
5857 | && bi->sub_type == BGP_ROUTE_REDISTRIBUTE) | |
5858 | break; | |
5859 | ||
5860 | if (bi) | |
5861 | { | |
5862 | /* Ensure the (source route) type is updated. */ | |
5863 | bi->type = type; | |
5864 | if (attrhash_cmp (bi->attr, new_attr) && | |
5865 | !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED)) | |
5866 | { | |
5867 | bgp_attr_unintern (&new_attr); | |
5868 | aspath_unintern (&attr.aspath); | |
5869 | bgp_attr_extra_free (&attr); | |
5870 | bgp_unlock_node (bn); | |
5871 | return; | |
5872 | } | |
5873 | else | |
5874 | { | |
5875 | /* The attribute is changed. */ | |
5876 | bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED); | |
718e3744 | 5877 | |
6aeb9e78 DS |
5878 | /* Rewrite BGP route information. */ |
5879 | if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED)) | |
5880 | bgp_info_restore(bn, bi); | |
5881 | else | |
5882 | bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST); | |
5883 | bgp_attr_unintern (&bi->attr); | |
5884 | bi->attr = new_attr; | |
5885 | bi->uptime = bgp_clock (); | |
5886 | ||
5887 | /* Process change. */ | |
5888 | bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST); | |
5889 | bgp_process (bgp, bn, afi, SAFI_UNICAST); | |
5890 | bgp_unlock_node (bn); | |
5891 | aspath_unintern (&attr.aspath); | |
5892 | bgp_attr_extra_free (&attr); | |
5893 | return; | |
5894 | } | |
5895 | } | |
718e3744 | 5896 | |
6aeb9e78 DS |
5897 | new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self, |
5898 | new_attr, bn); | |
5899 | SET_FLAG (new->flags, BGP_INFO_VALID); | |
5900 | ||
5901 | bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST); | |
5902 | bgp_info_add (bn, new); | |
5903 | bgp_unlock_node (bn); | |
5904 | bgp_process (bgp, bn, afi, SAFI_UNICAST); | |
718e3744 | 5905 | } |
5906 | ||
5907 | /* Unintern original. */ | |
f6f434b2 | 5908 | aspath_unintern (&attr.aspath); |
fb982c25 | 5909 | bgp_attr_extra_free (&attr); |
718e3744 | 5910 | } |
5911 | ||
5912 | void | |
6aeb9e78 | 5913 | bgp_redistribute_delete (struct bgp *bgp, struct prefix *p, u_char type, u_short instance) |
718e3744 | 5914 | { |
718e3744 | 5915 | afi_t afi; |
5916 | struct bgp_node *rn; | |
5917 | struct bgp_info *ri; | |
7c8ff89e | 5918 | struct bgp_redist *red; |
718e3744 | 5919 | |
6aeb9e78 | 5920 | afi = family2afi (p->family); |
718e3744 | 5921 | |
6aeb9e78 DS |
5922 | red = bgp_redist_lookup(bgp, afi, type, instance); |
5923 | if (red) | |
5924 | { | |
5925 | rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL); | |
718e3744 | 5926 | |
6aeb9e78 DS |
5927 | for (ri = rn->info; ri; ri = ri->next) |
5928 | if (ri->peer == bgp->peer_self | |
5929 | && ri->type == type) | |
5930 | break; | |
718e3744 | 5931 | |
6aeb9e78 DS |
5932 | if (ri) |
5933 | { | |
5934 | bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST); | |
5935 | bgp_info_delete (rn, ri); | |
5936 | bgp_process (bgp, rn, afi, SAFI_UNICAST); | |
5937 | } | |
5938 | bgp_unlock_node (rn); | |
718e3744 | 5939 | } |
5940 | } | |
5941 | ||
5942 | /* Withdraw specified route type's route. */ | |
5943 | void | |
7c8ff89e | 5944 | bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance) |
718e3744 | 5945 | { |
5946 | struct bgp_node *rn; | |
5947 | struct bgp_info *ri; | |
5948 | struct bgp_table *table; | |
5949 | ||
5950 | table = bgp->rib[afi][SAFI_UNICAST]; | |
5951 | ||
5952 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
5953 | { | |
5954 | for (ri = rn->info; ri; ri = ri->next) | |
5955 | if (ri->peer == bgp->peer_self | |
7c8ff89e DS |
5956 | && ri->type == type |
5957 | && ri->instance == instance) | |
718e3744 | 5958 | break; |
5959 | ||
5960 | if (ri) | |
5961 | { | |
5962 | bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST); | |
718e3744 | 5963 | bgp_info_delete (rn, ri); |
1a392d46 | 5964 | bgp_process (bgp, rn, afi, SAFI_UNICAST); |
718e3744 | 5965 | } |
5966 | } | |
5967 | } | |
6b0655a2 | 5968 | |
718e3744 | 5969 | /* Static function to display route. */ |
94f2b392 | 5970 | static void |
718e3744 | 5971 | route_vty_out_route (struct prefix *p, struct vty *vty) |
5972 | { | |
5973 | int len; | |
5974 | u_int32_t destination; | |
5975 | char buf[BUFSIZ]; | |
5976 | ||
5977 | if (p->family == AF_INET) | |
5978 | { | |
5979 | len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ)); | |
5980 | destination = ntohl (p->u.prefix4.s_addr); | |
5981 | ||
5982 | if ((IN_CLASSC (destination) && p->prefixlen == 24) | |
856ca177 MS |
5983 | || (IN_CLASSB (destination) && p->prefixlen == 16) |
5984 | || (IN_CLASSA (destination) && p->prefixlen == 8) | |
5985 | || p->u.prefix4.s_addr == 0) | |
5986 | { | |
5987 | /* When mask is natural, mask is not displayed. */ | |
5988 | } | |
718e3744 | 5989 | else |
856ca177 | 5990 | len += vty_out (vty, "/%d", p->prefixlen); |
718e3744 | 5991 | } |
5992 | else | |
5993 | len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), | |
5994 | p->prefixlen); | |
5995 | ||
5996 | len = 17 - len; | |
5997 | if (len < 1) | |
5998 | vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " "); | |
5999 | else | |
6000 | vty_out (vty, "%*s", len, " "); | |
6001 | } | |
6002 | ||
718e3744 | 6003 | enum bgp_display_type |
6004 | { | |
6005 | normal_list, | |
6006 | }; | |
6007 | ||
b40d939b | 6008 | /* Print the short form route status for a bgp_info */ |
6009 | static void | |
b05a1c8b DS |
6010 | route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo, |
6011 | json_object *json_path) | |
718e3744 | 6012 | { |
b05a1c8b DS |
6013 | if (json_path) |
6014 | { | |
b05a1c8b DS |
6015 | |
6016 | /* Route status display. */ | |
6017 | if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED)) | |
f1aa5d8a | 6018 | json_object_boolean_true_add(json_path, "removed"); |
b05a1c8b DS |
6019 | |
6020 | if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE)) | |
f1aa5d8a | 6021 | json_object_boolean_true_add(json_path, "stale"); |
b05a1c8b DS |
6022 | |
6023 | if (binfo->extra && binfo->extra->suppress) | |
f1aa5d8a | 6024 | json_object_boolean_true_add(json_path, "suppressed"); |
b05a1c8b DS |
6025 | |
6026 | if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) && | |
6027 | ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) | |
f1aa5d8a | 6028 | json_object_boolean_true_add(json_path, "valid"); |
b05a1c8b DS |
6029 | |
6030 | /* Selected */ | |
6031 | if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) | |
f1aa5d8a | 6032 | json_object_boolean_true_add(json_path, "history"); |
b05a1c8b DS |
6033 | |
6034 | if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)) | |
f1aa5d8a | 6035 | json_object_boolean_true_add(json_path, "damped"); |
b05a1c8b DS |
6036 | |
6037 | if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)) | |
f1aa5d8a | 6038 | json_object_boolean_true_add(json_path, "bestpath"); |
b05a1c8b DS |
6039 | |
6040 | if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH)) | |
f1aa5d8a | 6041 | json_object_boolean_true_add(json_path, "multipath"); |
b05a1c8b DS |
6042 | |
6043 | /* Internal route. */ | |
6044 | if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as)) | |
62d6dca0 | 6045 | json_object_string_add(json_path, "pathFrom", "internal"); |
b05a1c8b | 6046 | else |
62d6dca0 | 6047 | json_object_string_add(json_path, "pathFrom", "external"); |
b05a1c8b DS |
6048 | |
6049 | return; | |
6050 | } | |
6051 | ||
b40d939b | 6052 | /* Route status display. */ |
6053 | if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED)) | |
6054 | vty_out (vty, "R"); | |
6055 | else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE)) | |
93406d87 | 6056 | vty_out (vty, "S"); |
fb982c25 | 6057 | else if (binfo->extra && binfo->extra->suppress) |
718e3744 | 6058 | vty_out (vty, "s"); |
31eba040 DS |
6059 | else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) && |
6060 | ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) | |
718e3744 | 6061 | vty_out (vty, "*"); |
6062 | else | |
6063 | vty_out (vty, " "); | |
6064 | ||
6065 | /* Selected */ | |
6066 | if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) | |
6067 | vty_out (vty, "h"); | |
6068 | else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)) | |
6069 | vty_out (vty, "d"); | |
6070 | else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)) | |
6071 | vty_out (vty, ">"); | |
b366b518 BB |
6072 | else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH)) |
6073 | vty_out (vty, "="); | |
718e3744 | 6074 | else |
6075 | vty_out (vty, " "); | |
6076 | ||
6077 | /* Internal route. */ | |
b05a1c8b DS |
6078 | if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as)) |
6079 | vty_out (vty, "i"); | |
6080 | else | |
6081 | vty_out (vty, " "); | |
b40d939b | 6082 | } |
6083 | ||
6084 | /* called from terminal list command */ | |
6085 | void | |
6086 | route_vty_out (struct vty *vty, struct prefix *p, | |
b05a1c8b DS |
6087 | struct bgp_info *binfo, int display, safi_t safi, |
6088 | json_object *json_paths) | |
b40d939b | 6089 | { |
6090 | struct attr *attr; | |
f1aa5d8a DS |
6091 | json_object *json_path = NULL; |
6092 | json_object *json_nexthops = NULL; | |
6093 | json_object *json_nexthop_global = NULL; | |
6094 | json_object *json_nexthop_ll = NULL; | |
47fc97cc | 6095 | |
b05a1c8b DS |
6096 | if (json_paths) |
6097 | json_path = json_object_new_object(); | |
b05a1c8b DS |
6098 | |
6099 | /* short status lead text */ | |
6100 | route_vty_short_status_out (vty, binfo, json_path); | |
718e3744 | 6101 | |
b05a1c8b DS |
6102 | if (!json_paths) |
6103 | { | |
6104 | /* print prefix and mask */ | |
6105 | if (! display) | |
6106 | route_vty_out_route (p, vty); | |
6107 | else | |
6108 | vty_out (vty, "%*s", 17, " "); | |
6109 | } | |
47fc97cc | 6110 | |
718e3744 | 6111 | /* Print attribute */ |
6112 | attr = binfo->attr; | |
6113 | if (attr) | |
6114 | { | |
587ff0fd LB |
6115 | /* |
6116 | * For ENCAP routes, nexthop address family is not | |
6117 | * neccessarily the same as the prefix address family. | |
6118 | * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field | |
6119 | */ | |
6120 | if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN)) | |
6121 | { | |
6122 | if (attr->extra) | |
6123 | { | |
6124 | char buf[BUFSIZ]; | |
6125 | int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len); | |
b05a1c8b | 6126 | |
587ff0fd LB |
6127 | switch (af) |
6128 | { | |
6129 | case AF_INET: | |
6130 | vty_out (vty, "%s", inet_ntop(af, | |
6131 | &attr->extra->mp_nexthop_global_in, buf, BUFSIZ)); | |
6132 | break; | |
6133 | #if HAVE_IPV6 | |
6134 | case AF_INET6: | |
6135 | vty_out (vty, "%s", inet_ntop(af, | |
6136 | &attr->extra->mp_nexthop_global, buf, BUFSIZ)); | |
6137 | break; | |
6138 | #endif | |
6139 | default: | |
6140 | vty_out(vty, "?"); | |
6141 | break; | |
6142 | } | |
6143 | } | |
6144 | else | |
6145 | vty_out(vty, "?"); | |
6146 | } | |
b05a1c8b | 6147 | /* IPv4 Next Hop */ |
f81e127e | 6148 | else if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr)) |
718e3744 | 6149 | { |
b05a1c8b DS |
6150 | if (json_paths) |
6151 | { | |
f1aa5d8a DS |
6152 | json_nexthop_global = json_object_new_object(); |
6153 | ||
b05a1c8b | 6154 | if (safi == SAFI_MPLS_VPN) |
f1aa5d8a | 6155 | json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in)); |
b05a1c8b | 6156 | else |
f1aa5d8a DS |
6157 | json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop)); |
6158 | ||
6159 | json_object_string_add(json_nexthop_global, "afi", "ipv4"); | |
6160 | json_object_boolean_true_add(json_nexthop_global, "used"); | |
b05a1c8b DS |
6161 | } |
6162 | else | |
6163 | { | |
6164 | if (safi == SAFI_MPLS_VPN) | |
6165 | vty_out (vty, "%-16s", | |
6166 | inet_ntoa (attr->extra->mp_nexthop_global_in)); | |
6167 | else | |
6168 | vty_out (vty, "%-16s", inet_ntoa (attr->nexthop)); | |
6169 | } | |
718e3744 | 6170 | } |
161995ea | 6171 | |
b05a1c8b | 6172 | /* IPv6 Next Hop */ |
8a92a8a0 | 6173 | else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr)) |
718e3744 | 6174 | { |
6175 | int len; | |
6176 | char buf[BUFSIZ]; | |
6177 | ||
b05a1c8b DS |
6178 | if (json_paths) |
6179 | { | |
f1aa5d8a DS |
6180 | json_nexthop_global = json_object_new_object(); |
6181 | json_object_string_add(json_nexthop_global, "ip", | |
6182 | inet_ntop (AF_INET6, | |
6183 | &attr->extra->mp_nexthop_global, | |
6184 | buf, BUFSIZ)); | |
6185 | json_object_string_add(json_nexthop_global, "afi", "ipv6"); | |
6186 | json_object_string_add(json_nexthop_global, "scope", "global"); | |
6187 | ||
6188 | /* We display both LL & GL if both have been received */ | |
6189 | if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if)) | |
6190 | { | |
6191 | json_nexthop_ll = json_object_new_object(); | |
6192 | json_object_string_add(json_nexthop_ll, "ip", | |
6193 | inet_ntop (AF_INET6, | |
6194 | &attr->extra->mp_nexthop_local, | |
6195 | buf, BUFSIZ)); | |
6196 | json_object_string_add(json_nexthop_ll, "afi", "ipv6"); | |
6197 | json_object_string_add(json_nexthop_ll, "scope", "link-local"); | |
6198 | ||
161995ea DS |
6199 | if ((IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global, |
6200 | &attr->extra->mp_nexthop_local) != 0) && | |
6201 | !attr->extra->mp_nexthop_prefer_global) | |
f1aa5d8a DS |
6202 | json_object_boolean_true_add(json_nexthop_ll, "used"); |
6203 | else | |
6204 | json_object_boolean_true_add(json_nexthop_global, "used"); | |
6205 | } | |
6206 | else | |
6207 | json_object_boolean_true_add(json_nexthop_global, "used"); | |
b05a1c8b DS |
6208 | } |
6209 | else | |
6210 | { | |
161995ea DS |
6211 | /* Display LL if LL/Global both in table unless prefer-global is set */ |
6212 | if (((attr->extra->mp_nexthop_len == 32) && | |
6213 | !attr->extra->mp_nexthop_prefer_global) || | |
6214 | (binfo->peer->conf_if)) | |
433e8b67 DS |
6215 | { |
6216 | if (binfo->peer->conf_if) | |
6217 | { | |
6218 | len = vty_out (vty, "%s", | |
6219 | binfo->peer->conf_if); | |
6220 | len = 7 - len; /* len of IPv6 addr + max len of def ifname */ | |
6221 | ||
6222 | if (len < 1) | |
6223 | vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " "); | |
6224 | else | |
6225 | vty_out (vty, "%*s", len, " "); | |
6226 | } | |
6227 | else | |
6228 | { | |
6229 | len = vty_out (vty, "%s", | |
6230 | inet_ntop (AF_INET6, | |
6231 | &attr->extra->mp_nexthop_local, | |
6232 | buf, BUFSIZ)); | |
6233 | len = 16 - len; | |
6234 | ||
6235 | if (len < 1) | |
6236 | vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " "); | |
6237 | else | |
6238 | vty_out (vty, "%*s", len, " "); | |
6239 | } | |
6240 | } | |
6241 | else | |
6242 | { | |
6243 | len = vty_out (vty, "%s", | |
6244 | inet_ntop (AF_INET6, | |
6245 | &attr->extra->mp_nexthop_global, | |
6246 | buf, BUFSIZ)); | |
6247 | len = 16 - len; | |
6248 | ||
6249 | if (len < 1) | |
6250 | vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " "); | |
6251 | else | |
6252 | vty_out (vty, "%*s", len, " "); | |
6253 | } | |
b05a1c8b | 6254 | } |
718e3744 | 6255 | } |
718e3744 | 6256 | |
b05a1c8b | 6257 | /* MED/Metric */ |
718e3744 | 6258 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)) |
b05a1c8b | 6259 | if (json_paths) |
f1aa5d8a | 6260 | json_object_int_add(json_path, "med", attr->med); |
b05a1c8b | 6261 | else |
fa86975d | 6262 | vty_out (vty, "%10u", attr->med); |
718e3744 | 6263 | else |
b05a1c8b DS |
6264 | if (!json_paths) |
6265 | vty_out (vty, " "); | |
47fc97cc | 6266 | |
b05a1c8b | 6267 | /* Local Pref */ |
718e3744 | 6268 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)) |
b05a1c8b | 6269 | if (json_paths) |
f1aa5d8a | 6270 | json_object_int_add(json_path, "localpref", attr->local_pref); |
b05a1c8b | 6271 | else |
fa86975d | 6272 | vty_out (vty, "%7u", attr->local_pref); |
718e3744 | 6273 | else |
b05a1c8b DS |
6274 | if (!json_paths) |
6275 | vty_out (vty, " "); | |
718e3744 | 6276 | |
b05a1c8b DS |
6277 | if (json_paths) |
6278 | { | |
6279 | if (attr->extra) | |
f1aa5d8a | 6280 | json_object_int_add(json_path, "weight", attr->extra->weight); |
b05a1c8b | 6281 | else |
f1aa5d8a | 6282 | json_object_int_add(json_path, "weight", 0); |
b05a1c8b DS |
6283 | } |
6284 | else | |
6285 | vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0)); | |
47fc97cc | 6286 | |
39e871e6 ST |
6287 | if (json_paths) { |
6288 | char buf[BUFSIZ]; | |
6289 | json_object_string_add(json_path, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN)); | |
6290 | } | |
6291 | ||
b2518c1e PJ |
6292 | /* Print aspath */ |
6293 | if (attr->aspath) | |
b05a1c8b DS |
6294 | { |
6295 | if (json_paths) | |
f1aa5d8a | 6296 | json_object_string_add(json_path, "aspath", attr->aspath->str); |
b05a1c8b | 6297 | else |
f1aa5d8a | 6298 | aspath_print_vty (vty, "%s", attr->aspath, " "); |
b05a1c8b | 6299 | } |
47fc97cc | 6300 | |
b2518c1e | 6301 | /* Print origin */ |
b05a1c8b | 6302 | if (json_paths) |
f1aa5d8a | 6303 | json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]); |
b05a1c8b DS |
6304 | else |
6305 | vty_out (vty, "%s", bgp_origin_str[attr->origin]); | |
b2518c1e | 6306 | } |
856ca177 MS |
6307 | else |
6308 | { | |
6309 | if (json_paths) | |
6310 | json_object_string_add(json_path, "alert", "No attributes"); | |
6311 | else | |
6312 | vty_out (vty, "No attributes to print%s", VTY_NEWLINE); | |
6313 | } | |
b05a1c8b DS |
6314 | |
6315 | if (json_paths) | |
f1aa5d8a DS |
6316 | { |
6317 | if (json_nexthop_global || json_nexthop_ll) | |
6318 | { | |
6319 | json_nexthops = json_object_new_array(); | |
6320 | ||
6321 | if (json_nexthop_global) | |
6322 | json_object_array_add(json_nexthops, json_nexthop_global); | |
6323 | ||
6324 | if (json_nexthop_ll) | |
6325 | json_object_array_add(json_nexthops, json_nexthop_ll); | |
6326 | ||
6327 | json_object_object_add(json_path, "nexthops", json_nexthops); | |
6328 | } | |
6329 | ||
6330 | json_object_array_add(json_paths, json_path); | |
6331 | } | |
b05a1c8b | 6332 | else |
65efcfce LB |
6333 | { |
6334 | vty_out (vty, "%s", VTY_NEWLINE); | |
6335 | #if ENABLE_BGP_VNC | |
6336 | /* prints an additional line, indented, with VNC info, if present */ | |
61263032 | 6337 | if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) |
65efcfce LB |
6338 | rfapi_vty_out_vncinfo(vty, p, binfo, safi); |
6339 | #endif | |
6340 | } | |
718e3744 | 6341 | } |
6342 | ||
6343 | /* called from terminal list command */ | |
6344 | void | |
856ca177 MS |
6345 | route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi, |
6346 | u_char use_json, json_object *json_ar) | |
718e3744 | 6347 | { |
856ca177 MS |
6348 | json_object *json_status = NULL; |
6349 | json_object *json_net = NULL; | |
6350 | char buff[BUFSIZ]; | |
718e3744 | 6351 | /* Route status display. */ |
856ca177 MS |
6352 | if (use_json) |
6353 | { | |
6354 | json_status = json_object_new_object(); | |
6355 | json_net = json_object_new_object(); | |
6356 | } | |
6357 | else | |
6358 | { | |
6359 | vty_out (vty, "*"); | |
6360 | vty_out (vty, ">"); | |
6361 | vty_out (vty, " "); | |
6362 | } | |
718e3744 | 6363 | |
6364 | /* print prefix and mask */ | |
856ca177 MS |
6365 | if (use_json) |
6366 | json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ)); | |
6367 | else | |
6368 | route_vty_out_route (p, vty); | |
718e3744 | 6369 | |
6370 | /* Print attribute */ | |
6371 | if (attr) | |
6372 | { | |
856ca177 | 6373 | if (use_json) |
718e3744 | 6374 | { |
587ff0fd LB |
6375 | if (p->family == AF_INET && |
6376 | (safi == SAFI_MPLS_VPN || | |
6377 | safi == SAFI_ENCAP || | |
6378 | !BGP_ATTR_NEXTHOP_AFI_IP6(attr))) | |
856ca177 | 6379 | { |
587ff0fd | 6380 | if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) |
856ca177 MS |
6381 | json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in)); |
6382 | else | |
6383 | json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop)); | |
6384 | } | |
6385 | #ifdef HAVE_IPV6 | |
6386 | else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr)) | |
6387 | { | |
6388 | char buf[BUFSIZ]; | |
718e3744 | 6389 | |
856ca177 MS |
6390 | json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, |
6391 | buf, BUFSIZ)); | |
6392 | } | |
6393 | #endif /* HAVE_IPV6 */ | |
6394 | ||
6395 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)) | |
6396 | json_object_int_add(json_net, "metric", attr->med); | |
6397 | ||
6398 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)) | |
6399 | json_object_int_add(json_net, "localPref", attr->local_pref); | |
6400 | ||
6401 | if (attr->extra) | |
6402 | json_object_int_add(json_net, "weight", attr->extra->weight); | |
718e3744 | 6403 | else |
856ca177 MS |
6404 | json_object_int_add(json_net, "weight", 0); |
6405 | ||
6406 | /* Print aspath */ | |
6407 | if (attr->aspath) | |
6408 | json_object_string_add(json_net, "asPath", attr->aspath->str); | |
6409 | ||
6410 | /* Print origin */ | |
6411 | json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]); | |
718e3744 | 6412 | } |
856ca177 MS |
6413 | else |
6414 | { | |
587ff0fd LB |
6415 | if (p->family == AF_INET && |
6416 | (safi == SAFI_MPLS_VPN || | |
6417 | safi == SAFI_ENCAP || | |
6418 | !BGP_ATTR_NEXTHOP_AFI_IP6(attr))) | |
856ca177 | 6419 | { |
912e5234 LB |
6420 | if (attr->extra && |
6421 | (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)) | |
856ca177 MS |
6422 | vty_out (vty, "%-16s", |
6423 | inet_ntoa (attr->extra->mp_nexthop_global_in)); | |
6424 | else | |
6425 | vty_out (vty, "%-16s", inet_ntoa (attr->nexthop)); | |
6426 | } | |
6427 | #ifdef HAVE_IPV6 | |
6428 | else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr)) | |
6429 | { | |
6430 | int len; | |
6431 | char buf[BUFSIZ]; | |
912e5234 LB |
6432 | if (attr->extra) |
6433 | { | |
6434 | len = vty_out (vty, "%s", | |
6435 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, | |
6436 | buf, BUFSIZ)); | |
6437 | len = 16 - len; | |
6438 | } | |
6439 | else | |
6440 | len = 0; | |
856ca177 MS |
6441 | if (len < 1) |
6442 | vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " "); | |
6443 | else | |
6444 | vty_out (vty, "%*s", len, " "); | |
6445 | } | |
718e3744 | 6446 | #endif /* HAVE_IPV6 */ |
856ca177 | 6447 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)) |
fa86975d | 6448 | vty_out (vty, "%10u", attr->med); |
856ca177 MS |
6449 | else |
6450 | vty_out (vty, " "); | |
718e3744 | 6451 | |
856ca177 | 6452 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)) |
fa86975d | 6453 | vty_out (vty, "%7u", attr->local_pref); |
856ca177 MS |
6454 | else |
6455 | vty_out (vty, " "); | |
718e3744 | 6456 | |
856ca177 | 6457 | vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0)); |
718e3744 | 6458 | |
856ca177 MS |
6459 | /* Print aspath */ |
6460 | if (attr->aspath) | |
6461 | aspath_print_vty (vty, "%s", attr->aspath, " "); | |
718e3744 | 6462 | |
856ca177 MS |
6463 | /* Print origin */ |
6464 | vty_out (vty, "%s", bgp_origin_str[attr->origin]); | |
6465 | } | |
6466 | } | |
6467 | if (use_json) | |
6468 | { | |
6469 | json_object_boolean_true_add(json_status, "*"); | |
6470 | json_object_boolean_true_add(json_status, ">"); | |
6471 | json_object_object_add(json_net, "appliedStatusSymbols", json_status); | |
6472 | char buf_cut[BUFSIZ]; | |
6473 | json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net); | |
6474 | } | |
6475 | else | |
6476 | vty_out (vty, "%s", VTY_NEWLINE); | |
718e3744 | 6477 | } |
6478 | ||
5a646650 | 6479 | void |
718e3744 | 6480 | route_vty_out_tag (struct vty *vty, struct prefix *p, |
856ca177 | 6481 | struct bgp_info *binfo, int display, safi_t safi, json_object *json) |
718e3744 | 6482 | { |
856ca177 | 6483 | json_object *json_out = NULL; |
718e3744 | 6484 | struct attr *attr; |
718e3744 | 6485 | u_int32_t label = 0; |
fb982c25 PJ |
6486 | |
6487 | if (!binfo->extra) | |
6488 | return; | |
856ca177 MS |
6489 | |
6490 | if (json) | |
6491 | json_out = json_object_new_object(); | |
fb982c25 | 6492 | |
b40d939b | 6493 | /* short status lead text */ |
856ca177 | 6494 | route_vty_short_status_out (vty, binfo, json_out); |
b40d939b | 6495 | |
718e3744 | 6496 | /* print prefix and mask */ |
856ca177 MS |
6497 | if (json == NULL) |
6498 | { | |
6499 | if (! display) | |
6500 | route_vty_out_route (p, vty); | |
6501 | else | |
6502 | vty_out (vty, "%*s", 17, " "); | |
6503 | } | |
718e3744 | 6504 | |
6505 | /* Print attribute */ | |
6506 | attr = binfo->attr; | |
6507 | if (attr) | |
6508 | { | |
8a92a8a0 DS |
6509 | if (p->family == AF_INET |
6510 | && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr))) | |
718e3744 | 6511 | { |
587ff0fd | 6512 | if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) |
856ca177 MS |
6513 | { |
6514 | if (json) | |
6515 | json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in)); | |
6516 | else | |
6517 | vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in)); | |
6518 | } | |
718e3744 | 6519 | else |
856ca177 MS |
6520 | { |
6521 | if (json) | |
6522 | json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop)); | |
6523 | else | |
6524 | vty_out (vty, "%-16s", inet_ntoa (attr->nexthop)); | |
6525 | } | |
718e3744 | 6526 | } |
6527 | #ifdef HAVE_IPV6 | |
8a92a8a0 | 6528 | else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr)) |
718e3744 | 6529 | { |
fb982c25 | 6530 | assert (attr->extra); |
856ca177 MS |
6531 | char buf_a[BUFSIZ]; |
6532 | char buf_b[BUFSIZ]; | |
6533 | char buf_c[BUFSIZ]; | |
801a9bcc | 6534 | if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL) |
856ca177 MS |
6535 | { |
6536 | if (json) | |
6537 | json_object_string_add(json_out, "mpNexthopGlobalIn", | |
6538 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ)); | |
6539 | else | |
6540 | vty_out (vty, "%s", | |
6541 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, | |
6542 | buf_a, BUFSIZ)); | |
6543 | } | |
801a9bcc | 6544 | else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) |
856ca177 MS |
6545 | { |
6546 | if (json) | |
6547 | { | |
6548 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, | |
6549 | buf_a, BUFSIZ); | |
6550 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local, | |
6551 | buf_b, BUFSIZ); | |
6552 | sprintf(buf_c, "%s(%s)", buf_a, buf_b); | |
6553 | json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c); | |
6554 | } | |
6555 | else | |
6556 | vty_out (vty, "%s(%s)", | |
6557 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, | |
6558 | buf_a, BUFSIZ), | |
6559 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local, | |
6560 | buf_b, BUFSIZ)); | |
6561 | } | |
6562 | ||
718e3744 | 6563 | } |
6564 | #endif /* HAVE_IPV6 */ | |
6565 | } | |
6566 | ||
fb982c25 | 6567 | label = decode_label (binfo->extra->tag); |
718e3744 | 6568 | |
856ca177 MS |
6569 | if (json) |
6570 | { | |
6571 | if (label) | |
6572 | json_object_int_add(json_out, "notag", label); | |
6573 | json_object_array_add(json, json_out); | |
6574 | } | |
6575 | else | |
6576 | { | |
6577 | vty_out (vty, "notag/%d", label); | |
6578 | vty_out (vty, "%s", VTY_NEWLINE); | |
6579 | } | |
718e3744 | 6580 | } |
6581 | ||
6582 | /* dampening route */ | |
5a646650 | 6583 | static void |
856ca177 MS |
6584 | damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo, |
6585 | int display, safi_t safi, u_char use_json, json_object *json) | |
718e3744 | 6586 | { |
6587 | struct attr *attr; | |
718e3744 | 6588 | int len; |
50aef6f3 | 6589 | char timebuf[BGP_UPTIME_LEN]; |
718e3744 | 6590 | |
b40d939b | 6591 | /* short status lead text */ |
856ca177 | 6592 | route_vty_short_status_out (vty, binfo, json); |
b40d939b | 6593 | |
718e3744 | 6594 | /* print prefix and mask */ |
856ca177 MS |
6595 | if (!use_json) |
6596 | { | |
6597 | if (! display) | |
6598 | route_vty_out_route (p, vty); | |
6599 | else | |
6600 | vty_out (vty, "%*s", 17, " "); | |
6601 | } | |
718e3744 | 6602 | |
6603 | len = vty_out (vty, "%s", binfo->peer->host); | |
6604 | len = 17 - len; | |
6605 | if (len < 1) | |
856ca177 MS |
6606 | { |
6607 | if (!use_json) | |
6608 | vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " "); | |
6609 | } | |
718e3744 | 6610 | else |
856ca177 MS |
6611 | { |
6612 | if (use_json) | |
6613 | json_object_int_add(json, "peerHost", len); | |
6614 | else | |
6615 | vty_out (vty, "%*s", len, " "); | |
6616 | } | |
718e3744 | 6617 | |
856ca177 MS |
6618 | if (use_json) |
6619 | bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json); | |
6620 | else | |
6621 | vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json)); | |
718e3744 | 6622 | |
6623 | /* Print attribute */ | |
6624 | attr = binfo->attr; | |
6625 | if (attr) | |
6626 | { | |
6627 | /* Print aspath */ | |
6628 | if (attr->aspath) | |
856ca177 MS |
6629 | { |
6630 | if (use_json) | |
6631 | json_object_string_add(json, "asPath", attr->aspath->str); | |
6632 | else | |
6633 | aspath_print_vty (vty, "%s", attr->aspath, " "); | |
6634 | } | |
718e3744 | 6635 | |
6636 | /* Print origin */ | |
856ca177 MS |
6637 | if (use_json) |
6638 | json_object_string_add(json, "origin", bgp_origin_str[attr->origin]); | |
6639 | else | |
6640 | vty_out (vty, "%s", bgp_origin_str[attr->origin]); | |
718e3744 | 6641 | } |
856ca177 MS |
6642 | if (!use_json) |
6643 | vty_out (vty, "%s", VTY_NEWLINE); | |
718e3744 | 6644 | } |
6645 | ||
718e3744 | 6646 | /* flap route */ |
5a646650 | 6647 | static void |
856ca177 MS |
6648 | flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo, |
6649 | int display, safi_t safi, u_char use_json, json_object *json) | |
718e3744 | 6650 | { |
6651 | struct attr *attr; | |
6652 | struct bgp_damp_info *bdi; | |
718e3744 | 6653 | char timebuf[BGP_UPTIME_LEN]; |
6654 | int len; | |
fb982c25 PJ |
6655 | |
6656 | if (!binfo->extra) | |
6657 | return; | |
6658 | ||
6659 | bdi = binfo->extra->damp_info; | |
718e3744 | 6660 | |
b40d939b | 6661 | /* short status lead text */ |
856ca177 | 6662 | route_vty_short_status_out (vty, binfo, json); |
b40d939b | 6663 | |
718e3744 | 6664 | /* print prefix and mask */ |
856ca177 MS |
6665 | if (!use_json) |
6666 | { | |
6667 | if (! display) | |
6668 | route_vty_out_route (p, vty); | |
6669 | else | |
6670 | vty_out (vty, "%*s", 17, " "); | |
6671 | } | |
718e3744 | 6672 | |
6673 | len = vty_out (vty, "%s", binfo->peer->host); | |
6674 | len = 16 - len; | |
6675 | if (len < 1) | |
856ca177 MS |
6676 | { |
6677 | if (!use_json) | |
6678 | vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " "); | |
6679 | } | |
718e3744 | 6680 | else |
856ca177 MS |
6681 | { |
6682 | if (use_json) | |
6683 | json_object_int_add(json, "peerHost", len); | |
6684 | else | |
6685 | vty_out (vty, "%*s", len, " "); | |
6686 | } | |
718e3744 | 6687 | |
6688 | len = vty_out (vty, "%d", bdi->flap); | |
6689 | len = 5 - len; | |
6690 | if (len < 1) | |
856ca177 MS |
6691 | { |
6692 | if (!use_json) | |
6693 | vty_out (vty, " "); | |
6694 | } | |
718e3744 | 6695 | else |
856ca177 MS |
6696 | { |
6697 | if (use_json) | |
6698 | json_object_int_add(json, "bdiFlap", len); | |
6699 | else | |
6700 | vty_out (vty, "%*s", len, " "); | |
6701 | } | |
6702 | ||
6703 | if (use_json) | |
6704 | peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json); | |
6705 | else | |
6706 | vty_out (vty, "%s ", peer_uptime (bdi->start_time, | |
6707 | timebuf, BGP_UPTIME_LEN, 0, NULL)); | |
718e3744 | 6708 | |
6709 | if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED) | |
6710 | && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) | |
856ca177 MS |
6711 | { |
6712 | if (use_json) | |
6713 | bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json); | |
6714 | else | |
6715 | vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json)); | |
6716 | } | |
718e3744 | 6717 | else |
856ca177 MS |
6718 | { |
6719 | if (!use_json) | |
6720 | vty_out (vty, "%*s ", 8, " "); | |
6721 | } | |
718e3744 | 6722 | |
6723 | /* Print attribute */ | |
6724 | attr = binfo->attr; | |
6725 | if (attr) | |
6726 | { | |
6727 | /* Print aspath */ | |
6728 | if (attr->aspath) | |
856ca177 MS |
6729 | { |
6730 | if (use_json) | |
6731 | json_object_string_add(json, "asPath", attr->aspath->str); | |
6732 | else | |
6733 | aspath_print_vty (vty, "%s", attr->aspath, " "); | |
6734 | } | |
718e3744 | 6735 | |
6736 | /* Print origin */ | |
856ca177 MS |
6737 | if (use_json) |
6738 | json_object_string_add(json, "origin", bgp_origin_str[attr->origin]); | |
6739 | else | |
6740 | vty_out (vty, "%s", bgp_origin_str[attr->origin]); | |
718e3744 | 6741 | } |
856ca177 MS |
6742 | if (!use_json) |
6743 | vty_out (vty, "%s", VTY_NEWLINE); | |
718e3744 | 6744 | } |
6745 | ||
adbac85e DW |
6746 | static void |
6747 | route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first, | |
6748 | const char *header, json_object *json_adv_to) | |
6749 | { | |
6750 | char buf1[INET6_ADDRSTRLEN]; | |
6751 | json_object *json_peer = NULL; | |
6752 | ||
6753 | if (json_adv_to) | |
6754 | { | |
6755 | /* 'advertised-to' is a dictionary of peers we have advertised this | |
6756 | * prefix too. The key is the peer's IP or swpX, the value is the | |
6757 | * hostname if we know it and "" if not. | |
6758 | */ | |
6759 | json_peer = json_object_new_object(); | |
6760 | ||
6761 | if (peer->hostname) | |
6762 | json_object_string_add(json_peer, "hostname", peer->hostname); | |
6763 | ||
6764 | if (peer->conf_if) | |
6765 | json_object_object_add(json_adv_to, peer->conf_if, json_peer); | |
6766 | else | |
6767 | json_object_object_add(json_adv_to, | |
6768 | sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN), | |
6769 | json_peer); | |
6770 | } | |
6771 | else | |
6772 | { | |
6773 | if (*first) | |
6774 | { | |
6775 | vty_out (vty, "%s", header); | |
6776 | *first = 0; | |
6777 | } | |
6778 | ||
6779 | if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME)) | |
6780 | { | |
6781 | if (peer->conf_if) | |
6782 | vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if); | |
6783 | else | |
6784 | vty_out (vty, " %s(%s)", peer->hostname, | |
6785 | sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN)); | |
6786 | } | |
6787 | else | |
6788 | { | |
6789 | if (peer->conf_if) | |
6790 | vty_out (vty, " %s", peer->conf_if); | |
6791 | else | |
6792 | vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN)); | |
6793 | } | |
6794 | } | |
6795 | } | |
6796 | ||
94f2b392 | 6797 | static void |
718e3744 | 6798 | route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p, |
b05a1c8b DS |
6799 | struct bgp_info *binfo, afi_t afi, safi_t safi, |
6800 | json_object *json_paths) | |
718e3744 | 6801 | { |
6802 | char buf[INET6_ADDRSTRLEN]; | |
6803 | char buf1[BUFSIZ]; | |
6804 | struct attr *attr; | |
6805 | int sockunion_vty_out (struct vty *, union sockunion *); | |
30b00176 JK |
6806 | #ifdef HAVE_CLOCK_MONOTONIC |
6807 | time_t tbuf; | |
6808 | #endif | |
f1aa5d8a | 6809 | json_object *json_bestpath = NULL; |
ffd0c037 | 6810 | json_object *json_cluster_list = NULL; |
f1aa5d8a DS |
6811 | json_object *json_cluster_list_list = NULL; |
6812 | json_object *json_ext_community = NULL; | |
6813 | json_object *json_last_update = NULL; | |
6814 | json_object *json_nexthop_global = NULL; | |
6815 | json_object *json_nexthop_ll = NULL; | |
6816 | json_object *json_nexthops = NULL; | |
6817 | json_object *json_path = NULL; | |
6818 | json_object *json_peer = NULL; | |
6819 | json_object *json_string = NULL; | |
adbac85e DW |
6820 | json_object *json_adv_to = NULL; |
6821 | int first = 0; | |
6822 | struct listnode *node, *nnode; | |
6823 | struct peer *peer; | |
6824 | int addpath_capable; | |
6825 | int has_adj; | |
aac9ef6c | 6826 | unsigned int first_as; |
b05a1c8b DS |
6827 | |
6828 | if (json_paths) | |
6829 | { | |
6830 | json_path = json_object_new_object(); | |
f1aa5d8a DS |
6831 | json_peer = json_object_new_object(); |
6832 | json_nexthop_global = json_object_new_object(); | |
b05a1c8b DS |
6833 | } |
6834 | ||
718e3744 | 6835 | attr = binfo->attr; |
6836 | ||
6837 | if (attr) | |
6838 | { | |
6839 | /* Line1 display AS-path, Aggregator */ | |
6840 | if (attr->aspath) | |
6841 | { | |
f1aa5d8a DS |
6842 | if (json_paths) |
6843 | { | |
6844 | json_object_lock(attr->aspath->json); | |
6845 | json_object_object_add(json_path, "aspath", attr->aspath->json); | |
6846 | } | |
6847 | else | |
b05a1c8b | 6848 | { |
f1aa5d8a DS |
6849 | if (attr->aspath->segments) |
6850 | aspath_print_vty (vty, " %s", attr->aspath, ""); | |
b05a1c8b | 6851 | else |
f1aa5d8a | 6852 | vty_out (vty, " Local"); |
b05a1c8b | 6853 | } |
718e3744 | 6854 | } |
6855 | ||
b40d939b | 6856 | if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED)) |
b05a1c8b DS |
6857 | { |
6858 | if (json_paths) | |
f1aa5d8a | 6859 | json_object_boolean_true_add(json_path, "removed"); |
b05a1c8b DS |
6860 | else |
6861 | vty_out (vty, ", (removed)"); | |
6862 | } | |
6863 | ||
93406d87 | 6864 | if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE)) |
b05a1c8b DS |
6865 | { |
6866 | if (json_paths) | |
f1aa5d8a | 6867 | json_object_boolean_true_add(json_path, "stale"); |
b05a1c8b DS |
6868 | else |
6869 | vty_out (vty, ", (stale)"); | |
6870 | } | |
6871 | ||
93406d87 | 6872 | if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR))) |
b05a1c8b DS |
6873 | { |
6874 | if (json_paths) | |
6875 | { | |
62d6dca0 DS |
6876 | json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as); |
6877 | json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr)); | |
b05a1c8b DS |
6878 | } |
6879 | else | |
6880 | { | |
6881 | vty_out (vty, ", (aggregated by %u %s)", | |
6882 | attr->extra->aggregator_as, | |
6883 | inet_ntoa (attr->extra->aggregator_addr)); | |
6884 | } | |
6885 | } | |
6886 | ||
93406d87 | 6887 | if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)) |
b05a1c8b DS |
6888 | { |
6889 | if (json_paths) | |
62d6dca0 | 6890 | json_object_boolean_true_add(json_path, "rxedFromRrClient"); |
b05a1c8b DS |
6891 | else |
6892 | vty_out (vty, ", (Received from a RR-client)"); | |
6893 | } | |
6894 | ||
93406d87 | 6895 | if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)) |
b05a1c8b DS |
6896 | { |
6897 | if (json_paths) | |
62d6dca0 | 6898 | json_object_boolean_true_add(json_path, "rxedFromRsClient"); |
b05a1c8b DS |
6899 | else |
6900 | vty_out (vty, ", (Received from a RS-client)"); | |
6901 | } | |
6902 | ||
93406d87 | 6903 | if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) |
b05a1c8b DS |
6904 | { |
6905 | if (json_paths) | |
62d6dca0 | 6906 | json_object_boolean_true_add(json_path, "dampeningHistoryEntry"); |
b05a1c8b DS |
6907 | else |
6908 | vty_out (vty, ", (history entry)"); | |
6909 | } | |
93406d87 | 6910 | else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)) |
b05a1c8b DS |
6911 | { |
6912 | if (json_paths) | |
62d6dca0 | 6913 | json_object_boolean_true_add(json_path, "dampeningSuppressed"); |
b05a1c8b DS |
6914 | else |
6915 | vty_out (vty, ", (suppressed due to dampening)"); | |
6916 | } | |
6917 | ||
6918 | if (!json_paths) | |
6919 | vty_out (vty, "%s", VTY_NEWLINE); | |
718e3744 | 6920 | |
6921 | /* Line2 display Next-hop, Neighbor, Router-id */ | |
f1aa5d8a | 6922 | /* Display the nexthop */ |
587ff0fd LB |
6923 | if (p->family == AF_INET && |
6924 | (safi == SAFI_MPLS_VPN || | |
6925 | safi == SAFI_ENCAP || | |
6926 | !BGP_ATTR_NEXTHOP_AFI_IP6(attr))) | |
718e3744 | 6927 | { |
587ff0fd | 6928 | if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) |
b05a1c8b DS |
6929 | { |
6930 | if (json_paths) | |
f1aa5d8a | 6931 | json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in)); |
b05a1c8b DS |
6932 | else |
6933 | vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in)); | |
6934 | } | |
6935 | else | |
6936 | { | |
6937 | if (json_paths) | |
f1aa5d8a | 6938 | json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop)); |
b05a1c8b DS |
6939 | else |
6940 | vty_out (vty, " %s", inet_ntoa (attr->nexthop)); | |
6941 | } | |
6942 | ||
6943 | if (json_paths) | |
f1aa5d8a | 6944 | json_object_string_add(json_nexthop_global, "afi", "ipv4"); |
718e3744 | 6945 | } |
718e3744 | 6946 | else |
6947 | { | |
fb982c25 | 6948 | assert (attr->extra); |
b05a1c8b DS |
6949 | if (json_paths) |
6950 | { | |
f1aa5d8a DS |
6951 | json_object_string_add(json_nexthop_global, "ip", |
6952 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, | |
6953 | buf, INET6_ADDRSTRLEN)); | |
6954 | json_object_string_add(json_nexthop_global, "afi", "ipv6"); | |
6955 | json_object_string_add(json_nexthop_global, "scope", "global"); | |
b05a1c8b DS |
6956 | } |
6957 | else | |
6958 | { | |
6959 | vty_out (vty, " %s", | |
6960 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, | |
6961 | buf, INET6_ADDRSTRLEN)); | |
6962 | } | |
718e3744 | 6963 | } |
b05a1c8b | 6964 | |
f1aa5d8a DS |
6965 | /* Display the IGP cost or 'inaccessible' */ |
6966 | if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID)) | |
6967 | { | |
6968 | if (json_paths) | |
6969 | json_object_boolean_false_add(json_nexthop_global, "accessible"); | |
6970 | else | |
6971 | vty_out (vty, " (inaccessible)"); | |
6972 | } | |
6973 | else | |
6974 | { | |
6975 | if (binfo->extra && binfo->extra->igpmetric) | |
b05a1c8b DS |
6976 | { |
6977 | if (json_paths) | |
f1aa5d8a | 6978 | json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric); |
b05a1c8b | 6979 | else |
f1aa5d8a | 6980 | vty_out (vty, " (metric %u)", binfo->extra->igpmetric); |
b05a1c8b | 6981 | } |
f1aa5d8a DS |
6982 | |
6983 | /* IGP cost is 0, display this only for json */ | |
b05a1c8b DS |
6984 | else |
6985 | { | |
6986 | if (json_paths) | |
f1aa5d8a | 6987 | json_object_int_add(json_nexthop_global, "metric", 0); |
b05a1c8b DS |
6988 | } |
6989 | ||
6990 | if (json_paths) | |
f1aa5d8a DS |
6991 | json_object_boolean_true_add(json_nexthop_global, "accessible"); |
6992 | } | |
6993 | ||
6994 | /* Display peer "from" output */ | |
6995 | /* This path was originated locally */ | |
6996 | if (binfo->peer == bgp->peer_self) | |
718e3744 | 6997 | { |
f1aa5d8a DS |
6998 | |
6999 | if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr)) | |
b05a1c8b DS |
7000 | { |
7001 | if (json_paths) | |
62d6dca0 | 7002 | json_object_string_add(json_peer, "peerId", "0.0.0.0"); |
b05a1c8b | 7003 | else |
f1aa5d8a | 7004 | vty_out (vty, " from 0.0.0.0 "); |
b05a1c8b | 7005 | } |
f1aa5d8a | 7006 | else |
b05a1c8b DS |
7007 | { |
7008 | if (json_paths) | |
62d6dca0 | 7009 | json_object_string_add(json_peer, "peerId", "::"); |
b05a1c8b | 7010 | else |
f1aa5d8a | 7011 | vty_out (vty, " from :: "); |
b05a1c8b DS |
7012 | } |
7013 | ||
f1aa5d8a | 7014 | if (json_paths) |
62d6dca0 | 7015 | json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id)); |
b05a1c8b | 7016 | else |
f1aa5d8a DS |
7017 | vty_out (vty, "(%s)", inet_ntoa(bgp->router_id)); |
7018 | } | |
7019 | ||
7020 | /* We RXed this path from one of our peers */ | |
7021 | else | |
7022 | { | |
b05a1c8b DS |
7023 | |
7024 | if (json_paths) | |
7025 | { | |
62d6dca0 DS |
7026 | json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN)); |
7027 | json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ)); | |
f1aa5d8a | 7028 | |
04b6bdc0 DW |
7029 | if (binfo->peer->hostname) |
7030 | json_object_string_add(json_peer, "hostname", binfo->peer->hostname); | |
7031 | ||
7032 | if (binfo->peer->domainname) | |
7033 | json_object_string_add(json_peer, "domainname", binfo->peer->domainname); | |
7034 | ||
036a4e7d | 7035 | if (binfo->peer->conf_if) |
f1aa5d8a | 7036 | json_object_string_add(json_peer, "interface", binfo->peer->conf_if); |
b05a1c8b DS |
7037 | } |
7038 | else | |
7039 | { | |
036a4e7d | 7040 | if (binfo->peer->conf_if) |
04b6bdc0 DW |
7041 | { |
7042 | if (binfo->peer->hostname && | |
7043 | bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME)) | |
7044 | vty_out (vty, " from %s(%s)", binfo->peer->hostname, | |
7045 | binfo->peer->conf_if); | |
7046 | else | |
7047 | vty_out (vty, " from %s", binfo->peer->conf_if); | |
7048 | } | |
036a4e7d | 7049 | else |
04b6bdc0 DW |
7050 | { |
7051 | if (binfo->peer->hostname && | |
7052 | bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME)) | |
7053 | vty_out (vty, " from %s(%s)", binfo->peer->hostname, | |
7054 | binfo->peer->host); | |
7055 | else | |
7056 | vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN)); | |
7057 | } | |
b05a1c8b | 7058 | |
f1aa5d8a DS |
7059 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) |
7060 | vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id)); | |
7061 | else | |
7062 | vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ)); | |
b05a1c8b | 7063 | } |
718e3744 | 7064 | } |
b05a1c8b DS |
7065 | |
7066 | if (!json_paths) | |
7067 | vty_out (vty, "%s", VTY_NEWLINE); | |
718e3744 | 7068 | |
f1aa5d8a | 7069 | /* display the link-local nexthop */ |
801a9bcc | 7070 | if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) |
718e3744 | 7071 | { |
b05a1c8b DS |
7072 | if (json_paths) |
7073 | { | |
f1aa5d8a DS |
7074 | json_nexthop_ll = json_object_new_object(); |
7075 | json_object_string_add(json_nexthop_ll, "ip", | |
7076 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local, | |
7077 | buf, INET6_ADDRSTRLEN)); | |
7078 | json_object_string_add(json_nexthop_ll, "afi", "ipv6"); | |
7079 | json_object_string_add(json_nexthop_ll, "scope", "link-local"); | |
7080 | ||
7081 | json_object_boolean_true_add(json_nexthop_ll, "accessible"); | |
161995ea DS |
7082 | |
7083 | if (!attr->extra->mp_nexthop_prefer_global) | |
7084 | json_object_boolean_true_add(json_nexthop_ll, "used"); | |
7085 | else | |
7086 | json_object_boolean_true_add(json_nexthop_global, "used"); | |
b05a1c8b DS |
7087 | } |
7088 | else | |
7089 | { | |
161995ea DS |
7090 | vty_out (vty, " (%s) %s%s", |
7091 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local, | |
b05a1c8b | 7092 | buf, INET6_ADDRSTRLEN), |
161995ea DS |
7093 | attr->extra->mp_nexthop_prefer_global ? |
7094 | "(prefer-global)" : "(used)", | |
b05a1c8b DS |
7095 | VTY_NEWLINE); |
7096 | } | |
718e3744 | 7097 | } |
f1aa5d8a DS |
7098 | /* If we do not have a link-local nexthop then we must flag the global as "used" */ |
7099 | else | |
7100 | { | |
7101 | if (json_paths) | |
7102 | json_object_boolean_true_add(json_nexthop_global, "used"); | |
7103 | } | |
718e3744 | 7104 | |
0d9551dc | 7105 | /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */ |
b05a1c8b | 7106 | if (json_paths) |
f1aa5d8a | 7107 | json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]); |
b05a1c8b | 7108 | else |
f1aa5d8a | 7109 | vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]); |
718e3744 | 7110 | |
7111 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) | |
b05a1c8b DS |
7112 | { |
7113 | if (json_paths) | |
f1aa5d8a | 7114 | json_object_int_add(json_path, "med", attr->med); |
b05a1c8b | 7115 | else |
f1aa5d8a | 7116 | vty_out (vty, ", metric %u", attr->med); |
b05a1c8b | 7117 | } |
718e3744 | 7118 | |
7119 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)) | |
b05a1c8b DS |
7120 | { |
7121 | if (json_paths) | |
f1aa5d8a | 7122 | json_object_int_add(json_path, "localpref", attr->local_pref); |
b05a1c8b | 7123 | else |
f1aa5d8a | 7124 | vty_out (vty, ", localpref %u", attr->local_pref); |
b05a1c8b | 7125 | } |
718e3744 | 7126 | else |
b05a1c8b DS |
7127 | { |
7128 | if (json_paths) | |
f1aa5d8a | 7129 | json_object_int_add(json_path, "localpref", bgp->default_local_pref); |
b05a1c8b | 7130 | else |
f1aa5d8a | 7131 | vty_out (vty, ", localpref %u", bgp->default_local_pref); |
b05a1c8b | 7132 | } |
718e3744 | 7133 | |
fb982c25 | 7134 | if (attr->extra && attr->extra->weight != 0) |
b05a1c8b DS |
7135 | { |
7136 | if (json_paths) | |
f1aa5d8a | 7137 | json_object_int_add(json_path, "weight", attr->extra->weight); |
b05a1c8b | 7138 | else |
f1aa5d8a | 7139 | vty_out (vty, ", weight %u", attr->extra->weight); |
b05a1c8b | 7140 | } |
0d9551dc DS |
7141 | |
7142 | if (attr->extra && attr->extra->tag != 0) | |
b05a1c8b DS |
7143 | { |
7144 | if (json_paths) | |
f1aa5d8a | 7145 | json_object_int_add(json_path, "tag", attr->extra->tag); |
b05a1c8b | 7146 | else |
dc9ffce8 | 7147 | vty_out (vty, ", tag %"ROUTE_TAG_PRI, attr->extra->tag); |
b05a1c8b | 7148 | } |
718e3744 | 7149 | |
31eba040 | 7150 | if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID)) |
b05a1c8b DS |
7151 | { |
7152 | if (json_paths) | |
f1aa5d8a | 7153 | json_object_boolean_false_add(json_path, "valid"); |
b05a1c8b DS |
7154 | else |
7155 | vty_out (vty, ", invalid"); | |
7156 | } | |
31eba040 | 7157 | else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) |
b05a1c8b DS |
7158 | { |
7159 | if (json_paths) | |
f1aa5d8a | 7160 | json_object_boolean_true_add(json_path, "valid"); |
b05a1c8b DS |
7161 | else |
7162 | vty_out (vty, ", valid"); | |
7163 | } | |
718e3744 | 7164 | |
7165 | if (binfo->peer != bgp->peer_self) | |
7166 | { | |
f1aa5d8a | 7167 | if (binfo->peer->as == binfo->peer->local_as) |
b05a1c8b | 7168 | { |
66b199b2 DS |
7169 | if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)) |
7170 | { | |
7171 | if (json_paths) | |
f1aa5d8a | 7172 | json_object_string_add(json_peer, "type", "confed-internal"); |
66b199b2 | 7173 | else |
f1aa5d8a | 7174 | vty_out (vty, ", confed-internal"); |
66b199b2 | 7175 | } |
b05a1c8b | 7176 | else |
66b199b2 DS |
7177 | { |
7178 | if (json_paths) | |
f1aa5d8a | 7179 | json_object_string_add(json_peer, "type", "internal"); |
66b199b2 | 7180 | else |
f1aa5d8a | 7181 | vty_out (vty, ", internal"); |
66b199b2 | 7182 | } |
b05a1c8b | 7183 | } |
f1aa5d8a | 7184 | else |
b05a1c8b DS |
7185 | { |
7186 | if (bgp_confederation_peers_check(bgp, binfo->peer->as)) | |
7187 | { | |
7188 | if (json_paths) | |
f1aa5d8a | 7189 | json_object_string_add(json_peer, "type", "confed-external"); |
b05a1c8b | 7190 | else |
f1aa5d8a | 7191 | vty_out (vty, ", confed-external"); |
b05a1c8b DS |
7192 | } |
7193 | else | |
7194 | { | |
7195 | if (json_paths) | |
f1aa5d8a | 7196 | json_object_string_add(json_peer, "type", "external"); |
b05a1c8b | 7197 | else |
f1aa5d8a | 7198 | vty_out (vty, ", external"); |
b05a1c8b DS |
7199 | } |
7200 | } | |
718e3744 | 7201 | } |
7202 | else if (binfo->sub_type == BGP_ROUTE_AGGREGATE) | |
b05a1c8b DS |
7203 | { |
7204 | if (json_paths) | |
7205 | { | |
f1aa5d8a DS |
7206 | json_object_boolean_true_add(json_path, "aggregated"); |
7207 | json_object_boolean_true_add(json_path, "local"); | |
b05a1c8b DS |
7208 | } |
7209 | else | |
7210 | { | |
7211 | vty_out (vty, ", aggregated, local"); | |
7212 | } | |
7213 | } | |
718e3744 | 7214 | else if (binfo->type != ZEBRA_ROUTE_BGP) |
b05a1c8b DS |
7215 | { |
7216 | if (json_paths) | |
f1aa5d8a | 7217 | json_object_boolean_true_add(json_path, "sourced"); |
b05a1c8b DS |
7218 | else |
7219 | vty_out (vty, ", sourced"); | |
7220 | } | |
718e3744 | 7221 | else |
b05a1c8b DS |
7222 | { |
7223 | if (json_paths) | |
7224 | { | |
f1aa5d8a DS |
7225 | json_object_boolean_true_add(json_path, "sourced"); |
7226 | json_object_boolean_true_add(json_path, "local"); | |
b05a1c8b DS |
7227 | } |
7228 | else | |
7229 | { | |
7230 | vty_out (vty, ", sourced, local"); | |
7231 | } | |
7232 | } | |
718e3744 | 7233 | |
7234 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)) | |
b05a1c8b DS |
7235 | { |
7236 | if (json_paths) | |
62d6dca0 | 7237 | json_object_boolean_true_add(json_path, "atomicAggregate"); |
b05a1c8b DS |
7238 | else |
7239 | vty_out (vty, ", atomic-aggregate"); | |
7240 | } | |
718e3744 | 7241 | |
de8d5dff JB |
7242 | if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) || |
7243 | (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) && | |
7244 | bgp_info_mpath_count (binfo))) | |
b05a1c8b DS |
7245 | { |
7246 | if (json_paths) | |
f1aa5d8a | 7247 | json_object_boolean_true_add(json_path, "multipath"); |
b05a1c8b DS |
7248 | else |
7249 | vty_out (vty, ", multipath"); | |
7250 | } | |
de8d5dff | 7251 | |
06370dac DW |
7252 | // Mark the bestpath(s) |
7253 | if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED)) | |
7254 | { | |
aac9ef6c | 7255 | first_as = aspath_get_first_as(attr->aspath); |
06370dac DW |
7256 | |
7257 | if (json_paths) | |
7258 | { | |
7259 | if (!json_bestpath) | |
7260 | json_bestpath = json_object_new_object(); | |
7261 | json_object_int_add(json_bestpath, "bestpathFromAs", first_as); | |
7262 | } | |
7263 | else | |
7264 | { | |
7265 | if (first_as) | |
7266 | vty_out (vty, ", bestpath-from-AS %d", first_as); | |
7267 | else | |
7268 | vty_out (vty, ", bestpath-from-AS Local"); | |
7269 | } | |
7270 | } | |
7271 | ||
718e3744 | 7272 | if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)) |
b05a1c8b DS |
7273 | { |
7274 | if (json_paths) | |
f1aa5d8a | 7275 | { |
06370dac DW |
7276 | if (!json_bestpath) |
7277 | json_bestpath = json_object_new_object(); | |
f1aa5d8a | 7278 | json_object_boolean_true_add(json_bestpath, "overall"); |
f1aa5d8a | 7279 | } |
b05a1c8b DS |
7280 | else |
7281 | vty_out (vty, ", best"); | |
7282 | } | |
718e3744 | 7283 | |
06370dac DW |
7284 | if (json_bestpath) |
7285 | json_object_object_add(json_path, "bestpath", json_bestpath); | |
7286 | ||
b05a1c8b DS |
7287 | if (!json_paths) |
7288 | vty_out (vty, "%s", VTY_NEWLINE); | |
718e3744 | 7289 | |
7290 | /* Line 4 display Community */ | |
7291 | if (attr->community) | |
b05a1c8b DS |
7292 | { |
7293 | if (json_paths) | |
7294 | { | |
f1aa5d8a DS |
7295 | json_object_lock(attr->community->json); |
7296 | json_object_object_add(json_path, "community", attr->community->json); | |
b05a1c8b DS |
7297 | } |
7298 | else | |
7299 | { | |
7300 | vty_out (vty, " Community: %s%s", attr->community->str, | |
7301 | VTY_NEWLINE); | |
7302 | } | |
7303 | } | |
718e3744 | 7304 | |
7305 | /* Line 5 display Extended-community */ | |
7306 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)) | |
b05a1c8b DS |
7307 | { |
7308 | if (json_paths) | |
7309 | { | |
f1aa5d8a DS |
7310 | json_ext_community = json_object_new_object(); |
7311 | json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str); | |
62d6dca0 | 7312 | json_object_object_add(json_path, "extendedCommunity", json_ext_community); |
b05a1c8b DS |
7313 | } |
7314 | else | |
7315 | { | |
7316 | vty_out (vty, " Extended Community: %s%s", | |
7317 | attr->extra->ecommunity->str, VTY_NEWLINE); | |
7318 | } | |
7319 | } | |
7320 | ||
718e3744 | 7321 | /* Line 6 display Originator, Cluster-id */ |
7322 | if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) || | |
7323 | (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))) | |
7324 | { | |
fb982c25 | 7325 | assert (attr->extra); |
718e3744 | 7326 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) |
b05a1c8b DS |
7327 | { |
7328 | if (json_paths) | |
62d6dca0 | 7329 | json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id)); |
b05a1c8b | 7330 | else |
f1aa5d8a DS |
7331 | vty_out (vty, " Originator: %s", |
7332 | inet_ntoa (attr->extra->originator_id)); | |
b05a1c8b | 7333 | } |
718e3744 | 7334 | |
7335 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) | |
7336 | { | |
7337 | int i; | |
b05a1c8b DS |
7338 | |
7339 | if (json_paths) | |
7340 | { | |
f1aa5d8a DS |
7341 | json_cluster_list = json_object_new_object(); |
7342 | json_cluster_list_list = json_object_new_array(); | |
7343 | ||
b05a1c8b DS |
7344 | for (i = 0; i < attr->extra->cluster->length / 4; i++) |
7345 | { | |
7346 | json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i])); | |
f1aa5d8a | 7347 | json_object_array_add(json_cluster_list_list, json_string); |
b05a1c8b | 7348 | } |
f1aa5d8a DS |
7349 | |
7350 | /* struct cluster_list does not have "str" variable like | |
7351 | * aspath and community do. Add this someday if someone | |
7352 | * asks for it. | |
7353 | json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str); | |
7354 | */ | |
7355 | json_object_object_add(json_cluster_list, "list", json_cluster_list_list); | |
62d6dca0 | 7356 | json_object_object_add(json_path, "clusterList", json_cluster_list); |
b05a1c8b DS |
7357 | } |
7358 | else | |
7359 | { | |
7360 | vty_out (vty, ", Cluster list: "); | |
7361 | ||
7362 | for (i = 0; i < attr->extra->cluster->length / 4; i++) | |
7363 | { | |
7364 | vty_out (vty, "%s ", | |
7365 | inet_ntoa (attr->extra->cluster->list[i])); | |
7366 | } | |
7367 | } | |
718e3744 | 7368 | } |
b05a1c8b DS |
7369 | |
7370 | if (!json_paths) | |
7371 | vty_out (vty, "%s", VTY_NEWLINE); | |
718e3744 | 7372 | } |
b05a1c8b | 7373 | |
fb982c25 | 7374 | if (binfo->extra && binfo->extra->damp_info) |
b05a1c8b | 7375 | bgp_damp_info_vty (vty, binfo, json_path); |
718e3744 | 7376 | |
a82478b9 DS |
7377 | /* Line 7 display Addpath IDs */ |
7378 | if (binfo->addpath_rx_id || binfo->addpath_tx_id) | |
b05a1c8b DS |
7379 | { |
7380 | if (json_paths) | |
7381 | { | |
62d6dca0 DS |
7382 | json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id); |
7383 | json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id); | |
b05a1c8b DS |
7384 | } |
7385 | else | |
7386 | { | |
7387 | vty_out (vty, " AddPath ID: RX %u, TX %u%s", | |
7388 | binfo->addpath_rx_id, binfo->addpath_tx_id, | |
7389 | VTY_NEWLINE); | |
7390 | } | |
7391 | } | |
a82478b9 | 7392 | |
adbac85e DW |
7393 | /* If we used addpath to TX a non-bestpath we need to display |
7394 | * "Advertised to" on a path-by-path basis */ | |
7395 | if (bgp->addpath_tx_used[afi][safi]) | |
7396 | { | |
7397 | first = 1; | |
7398 | ||
7399 | for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) | |
7400 | { | |
7401 | addpath_capable = bgp_addpath_encode_tx (peer, afi, safi); | |
7402 | has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id); | |
7403 | ||
7404 | if ((addpath_capable && has_adj) || | |
7405 | (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))) | |
7406 | { | |
7407 | if (json_path && !json_adv_to) | |
7408 | json_adv_to = json_object_new_object(); | |
7409 | ||
7410 | route_vty_out_advertised_to(vty, peer, &first, | |
7411 | " Advertised to:", | |
7412 | json_adv_to); | |
7413 | } | |
7414 | } | |
7415 | ||
7416 | if (json_path) | |
7417 | { | |
7418 | if (json_adv_to) | |
7419 | { | |
7420 | json_object_object_add(json_path, "advertisedTo", json_adv_to); | |
7421 | } | |
7422 | } | |
7423 | else | |
7424 | { | |
7425 | if (!first) | |
7426 | { | |
7427 | vty_out (vty, "%s", VTY_NEWLINE); | |
7428 | } | |
7429 | } | |
7430 | } | |
7431 | ||
a82478b9 | 7432 | /* Line 8 display Uptime */ |
30b00176 JK |
7433 | #ifdef HAVE_CLOCK_MONOTONIC |
7434 | tbuf = time(NULL) - (bgp_clock() - binfo->uptime); | |
b05a1c8b | 7435 | if (json_paths) |
f1aa5d8a DS |
7436 | { |
7437 | json_last_update = json_object_new_object(); | |
7438 | json_object_int_add(json_last_update, "epoch", tbuf); | |
7439 | json_object_string_add(json_last_update, "string", ctime(&tbuf)); | |
62d6dca0 | 7440 | json_object_object_add(json_path, "lastUpdate", json_last_update); |
f1aa5d8a | 7441 | } |
b05a1c8b DS |
7442 | else |
7443 | vty_out (vty, " Last update: %s", ctime(&tbuf)); | |
30b00176 | 7444 | #else |
b05a1c8b | 7445 | if (json_paths) |
f1aa5d8a DS |
7446 | { |
7447 | json_last_update = json_object_new_object(); | |
7448 | json_object_int_add(json_last_update, "epoch", tbuf); | |
7449 | json_object_string_add(json_last_update, "string", ctime(&binfo->uptime)); | |
62d6dca0 | 7450 | json_object_object_add(json_path, "lastUpdate", json_last_update); |
f1aa5d8a | 7451 | } |
b05a1c8b DS |
7452 | else |
7453 | vty_out (vty, " Last update: %s", ctime(&binfo->uptime)); | |
30b00176 | 7454 | #endif /* HAVE_CLOCK_MONOTONIC */ |
718e3744 | 7455 | } |
b05a1c8b DS |
7456 | |
7457 | /* We've constructed the json object for this path, add it to the json | |
7458 | * array of paths | |
7459 | */ | |
7460 | if (json_paths) | |
f1aa5d8a DS |
7461 | { |
7462 | if (json_nexthop_global || json_nexthop_ll) | |
7463 | { | |
7464 | json_nexthops = json_object_new_array(); | |
7465 | ||
7466 | if (json_nexthop_global) | |
7467 | json_object_array_add(json_nexthops, json_nexthop_global); | |
7468 | ||
7469 | if (json_nexthop_ll) | |
7470 | json_object_array_add(json_nexthops, json_nexthop_ll); | |
7471 | ||
7472 | json_object_object_add(json_path, "nexthops", json_nexthops); | |
7473 | } | |
7474 | ||
7475 | json_object_object_add(json_path, "peer", json_peer); | |
7476 | json_object_array_add(json_paths, json_path); | |
7477 | } | |
b05a1c8b DS |
7478 | else |
7479 | vty_out (vty, "%s", VTY_NEWLINE); | |
b366b518 BB |
7480 | } |
7481 | ||
47fc97cc | 7482 | #define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s" |
718e3744 | 7483 | #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s" |
7484 | #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s" | |
7485 | ||
7486 | enum bgp_show_type | |
7487 | { | |
7488 | bgp_show_type_normal, | |
7489 | bgp_show_type_regexp, | |
7490 | bgp_show_type_prefix_list, | |
7491 | bgp_show_type_filter_list, | |
7492 | bgp_show_type_route_map, | |
7493 | bgp_show_type_neighbor, | |
7494 | bgp_show_type_cidr_only, | |
7495 | bgp_show_type_prefix_longer, | |
7496 | bgp_show_type_community_all, | |
7497 | bgp_show_type_community, | |
7498 | bgp_show_type_community_exact, | |
7499 | bgp_show_type_community_list, | |
7500 | bgp_show_type_community_list_exact, | |
7501 | bgp_show_type_flap_statistics, | |
7502 | bgp_show_type_flap_address, | |
7503 | bgp_show_type_flap_prefix, | |
7504 | bgp_show_type_flap_cidr_only, | |
7505 | bgp_show_type_flap_regexp, | |
7506 | bgp_show_type_flap_filter_list, | |
7507 | bgp_show_type_flap_prefix_list, | |
7508 | bgp_show_type_flap_prefix_longer, | |
7509 | bgp_show_type_flap_route_map, | |
7510 | bgp_show_type_flap_neighbor, | |
7511 | bgp_show_type_dampend_paths, | |
7512 | bgp_show_type_damp_neighbor | |
7513 | }; | |
7514 | ||
50ef26d4 | 7515 | static int |
7516 | bgp_show_prefix_list (struct vty *vty, const char *name, | |
7517 | const char *prefix_list_str, afi_t afi, | |
7518 | safi_t safi, enum bgp_show_type type); | |
7519 | static int | |
7520 | bgp_show_filter_list (struct vty *vty, const char *name, | |
7521 | const char *filter, afi_t afi, | |
7522 | safi_t safi, enum bgp_show_type type); | |
7523 | static int | |
7524 | bgp_show_route_map (struct vty *vty, const char *name, | |
7525 | const char *rmap_str, afi_t afi, | |
7526 | safi_t safi, enum bgp_show_type type); | |
7527 | static int | |
7528 | bgp_show_community_list (struct vty *vty, const char *name, | |
7529 | const char *com, int exact, | |
7530 | afi_t afi, safi_t safi); | |
7531 | static int | |
7532 | bgp_show_prefix_longer (struct vty *vty, const char *name, | |
7533 | const char *prefix, afi_t afi, | |
7534 | safi_t safi, enum bgp_show_type type); | |
7535 | ||
5a646650 | 7536 | static int |
31303c3e DS |
7537 | bgp_show_table (struct vty *vty, struct bgp *bgp, struct bgp_table *table, |
7538 | enum bgp_show_type type, void *output_arg, u_char use_json) | |
718e3744 | 7539 | { |
718e3744 | 7540 | struct bgp_info *ri; |
7541 | struct bgp_node *rn; | |
718e3744 | 7542 | int header = 1; |
718e3744 | 7543 | int display; |
5a646650 | 7544 | unsigned long output_count; |
18200902 | 7545 | unsigned long total_count; |
b05a1c8b DS |
7546 | struct prefix *p; |
7547 | char buf[BUFSIZ]; | |
7548 | char buf2[BUFSIZ]; | |
f1aa5d8a | 7549 | json_object *json_paths = NULL; |
31303c3e | 7550 | int first = 1; |
b05a1c8b DS |
7551 | |
7552 | if (use_json) | |
7553 | { | |
31303c3e DS |
7554 | vty_out (vty, "{ \"vrfId\": %d, \"vrfName\": \"%s\", \"tableVersion\": %" PRId64 ", \"routerId\": \"%s\", \"routes\": { ", |
7555 | bgp->vrf_id == VRF_UNKNOWN ? -1 : bgp->vrf_id, | |
7556 | bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ? "Default" : bgp->name, | |
7557 | table->version, inet_ntoa (bgp->router_id)); | |
7558 | json_paths = json_object_new_object(); | |
b05a1c8b | 7559 | } |
718e3744 | 7560 | |
7561 | /* This is first entry point, so reset total line. */ | |
5a646650 | 7562 | output_count = 0; |
18200902 | 7563 | total_count = 0; |
718e3744 | 7564 | |
718e3744 | 7565 | /* Start processing of routes. */ |
7566 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
7567 | if (rn->info != NULL) | |
7568 | { | |
856ca177 | 7569 | display = 0; |
31303c3e DS |
7570 | if (!first && use_json) |
7571 | { | |
7572 | vty_out (vty, ","); | |
7573 | } | |
b05a1c8b DS |
7574 | if (use_json) |
7575 | json_paths = json_object_new_array(); | |
7576 | else | |
7577 | json_paths = NULL; | |
7578 | ||
856ca177 MS |
7579 | for (ri = rn->info; ri; ri = ri->next) |
7580 | { | |
18200902 | 7581 | total_count++; |
856ca177 MS |
7582 | if (type == bgp_show_type_flap_statistics |
7583 | || type == bgp_show_type_flap_address | |
7584 | || type == bgp_show_type_flap_prefix | |
7585 | || type == bgp_show_type_flap_cidr_only | |
7586 | || type == bgp_show_type_flap_regexp | |
7587 | || type == bgp_show_type_flap_filter_list | |
7588 | || type == bgp_show_type_flap_prefix_list | |
7589 | || type == bgp_show_type_flap_prefix_longer | |
7590 | || type == bgp_show_type_flap_route_map | |
7591 | || type == bgp_show_type_flap_neighbor | |
7592 | || type == bgp_show_type_dampend_paths | |
7593 | || type == bgp_show_type_damp_neighbor) | |
7594 | { | |
7595 | if (!(ri->extra && ri->extra->damp_info)) | |
7596 | continue; | |
7597 | } | |
7598 | if (type == bgp_show_type_regexp | |
7599 | || type == bgp_show_type_flap_regexp) | |
7600 | { | |
7601 | regex_t *regex = output_arg; | |
718e3744 | 7602 | |
856ca177 MS |
7603 | if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH) |
7604 | continue; | |
7605 | } | |
7606 | if (type == bgp_show_type_prefix_list | |
7607 | || type == bgp_show_type_flap_prefix_list) | |
7608 | { | |
7609 | struct prefix_list *plist = output_arg; | |
718e3744 | 7610 | |
856ca177 MS |
7611 | if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT) |
7612 | continue; | |
7613 | } | |
7614 | if (type == bgp_show_type_filter_list | |
7615 | || type == bgp_show_type_flap_filter_list) | |
7616 | { | |
7617 | struct as_list *as_list = output_arg; | |
558d1fec | 7618 | |
856ca177 MS |
7619 | if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT) |
7620 | continue; | |
7621 | } | |
7622 | if (type == bgp_show_type_route_map | |
7623 | || type == bgp_show_type_flap_route_map) | |
7624 | { | |
7625 | struct route_map *rmap = output_arg; | |
7626 | struct bgp_info binfo; | |
7627 | struct attr dummy_attr; | |
7628 | struct attr_extra dummy_extra; | |
7629 | int ret; | |
718e3744 | 7630 | |
856ca177 MS |
7631 | dummy_attr.extra = &dummy_extra; |
7632 | bgp_attr_dup (&dummy_attr, ri->attr); | |
718e3744 | 7633 | |
856ca177 MS |
7634 | binfo.peer = ri->peer; |
7635 | binfo.attr = &dummy_attr; | |
718e3744 | 7636 | |
856ca177 MS |
7637 | ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo); |
7638 | if (ret == RMAP_DENYMATCH) | |
7639 | continue; | |
7640 | } | |
7641 | if (type == bgp_show_type_neighbor | |
7642 | || type == bgp_show_type_flap_neighbor | |
7643 | || type == bgp_show_type_damp_neighbor) | |
7644 | { | |
7645 | union sockunion *su = output_arg; | |
718e3744 | 7646 | |
856ca177 MS |
7647 | if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su)) |
7648 | continue; | |
7649 | } | |
7650 | if (type == bgp_show_type_cidr_only | |
7651 | || type == bgp_show_type_flap_cidr_only) | |
7652 | { | |
7653 | u_int32_t destination; | |
718e3744 | 7654 | |
856ca177 MS |
7655 | destination = ntohl (rn->p.u.prefix4.s_addr); |
7656 | if (IN_CLASSC (destination) && rn->p.prefixlen == 24) | |
7657 | continue; | |
7658 | if (IN_CLASSB (destination) && rn->p.prefixlen == 16) | |
7659 | continue; | |
7660 | if (IN_CLASSA (destination) && rn->p.prefixlen == 8) | |
7661 | continue; | |
7662 | } | |
7663 | if (type == bgp_show_type_prefix_longer | |
7664 | || type == bgp_show_type_flap_prefix_longer) | |
7665 | { | |
7666 | struct prefix *p = output_arg; | |
718e3744 | 7667 | |
856ca177 MS |
7668 | if (! prefix_match (p, &rn->p)) |
7669 | continue; | |
7670 | } | |
7671 | if (type == bgp_show_type_community_all) | |
7672 | { | |
7673 | if (! ri->attr->community) | |
7674 | continue; | |
7675 | } | |
7676 | if (type == bgp_show_type_community) | |
7677 | { | |
7678 | struct community *com = output_arg; | |
718e3744 | 7679 | |
856ca177 MS |
7680 | if (! ri->attr->community || |
7681 | ! community_match (ri->attr->community, com)) | |
7682 | continue; | |
7683 | } | |
7684 | if (type == bgp_show_type_community_exact) | |
7685 | { | |
7686 | struct community *com = output_arg; | |
718e3744 | 7687 | |
856ca177 MS |
7688 | if (! ri->attr->community || |
7689 | ! community_cmp (ri->attr->community, com)) | |
7690 | continue; | |
7691 | } | |
7692 | if (type == bgp_show_type_community_list) | |
7693 | { | |
7694 | struct community_list *list = output_arg; | |
718e3744 | 7695 | |
856ca177 MS |
7696 | if (! community_list_match (ri->attr->community, list)) |
7697 | continue; | |
7698 | } | |
7699 | if (type == bgp_show_type_community_list_exact) | |
7700 | { | |
7701 | struct community_list *list = output_arg; | |
718e3744 | 7702 | |
856ca177 MS |
7703 | if (! community_list_exact_match (ri->attr->community, list)) |
7704 | continue; | |
7705 | } | |
7706 | if (type == bgp_show_type_flap_address | |
7707 | || type == bgp_show_type_flap_prefix) | |
7708 | { | |
7709 | struct prefix *p = output_arg; | |
718e3744 | 7710 | |
856ca177 MS |
7711 | if (! prefix_match (&rn->p, p)) |
7712 | continue; | |
b05a1c8b | 7713 | |
856ca177 MS |
7714 | if (type == bgp_show_type_flap_prefix) |
7715 | if (p->prefixlen != rn->p.prefixlen) | |
7716 | continue; | |
7717 | } | |
7718 | if (type == bgp_show_type_dampend_paths | |
7719 | || type == bgp_show_type_damp_neighbor) | |
7720 | { | |
7721 | if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED) | |
7722 | || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) | |
7723 | continue; | |
7724 | } | |
7725 | ||
7726 | if (!use_json && header) | |
7727 | { | |
31303c3e | 7728 | vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE); |
856ca177 MS |
7729 | vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); |
7730 | vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); | |
7731 | if (type == bgp_show_type_dampend_paths | |
7732 | || type == bgp_show_type_damp_neighbor) | |
7733 | vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE); | |
7734 | else if (type == bgp_show_type_flap_statistics | |
7735 | || type == bgp_show_type_flap_address | |
7736 | || type == bgp_show_type_flap_prefix | |
7737 | || type == bgp_show_type_flap_cidr_only | |
7738 | || type == bgp_show_type_flap_regexp | |
7739 | || type == bgp_show_type_flap_filter_list | |
7740 | || type == bgp_show_type_flap_prefix_list | |
7741 | || type == bgp_show_type_flap_prefix_longer | |
7742 | || type == bgp_show_type_flap_route_map | |
7743 | || type == bgp_show_type_flap_neighbor) | |
7744 | vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE); | |
7745 | else | |
7746 | vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE); | |
7747 | header = 0; | |
7748 | } | |
7749 | ||
7750 | if (type == bgp_show_type_dampend_paths | |
7751 | || type == bgp_show_type_damp_neighbor) | |
7752 | damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths); | |
7753 | else if (type == bgp_show_type_flap_statistics | |
7754 | || type == bgp_show_type_flap_address | |
7755 | || type == bgp_show_type_flap_prefix | |
7756 | || type == bgp_show_type_flap_cidr_only | |
7757 | || type == bgp_show_type_flap_regexp | |
7758 | || type == bgp_show_type_flap_filter_list | |
7759 | || type == bgp_show_type_flap_prefix_list | |
7760 | || type == bgp_show_type_flap_prefix_longer | |
7761 | || type == bgp_show_type_flap_route_map | |
7762 | || type == bgp_show_type_flap_neighbor) | |
7763 | flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths); | |
7764 | else | |
7765 | route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths); | |
7766 | display++; | |
b05a1c8b DS |
7767 | } |
7768 | ||
856ca177 MS |
7769 | if (display) |
7770 | { | |
7771 | output_count++; | |
7772 | if (use_json) | |
7773 | { | |
7774 | p = &rn->p; | |
7775 | sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen); | |
31303c3e DS |
7776 | vty_out (vty, "\"%s\": ", buf2); |
7777 | vty_out (vty, "%s", json_object_to_json_string (json_paths)); | |
7778 | json_object_free (json_paths); | |
7779 | first = 0; | |
7780 | ||
856ca177 MS |
7781 | } |
7782 | } | |
9f689658 | 7783 | } |
718e3744 | 7784 | |
b05a1c8b | 7785 | if (use_json) |
718e3744 | 7786 | { |
31303c3e DS |
7787 | json_object_free (json_paths); |
7788 | vty_out (vty, " } }%s", VTY_NEWLINE); | |
718e3744 | 7789 | } |
7790 | else | |
b05a1c8b DS |
7791 | { |
7792 | /* No route is displayed */ | |
7793 | if (output_count == 0) | |
7794 | { | |
7795 | if (type == bgp_show_type_normal) | |
18200902 | 7796 | vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE); |
b05a1c8b DS |
7797 | } |
7798 | else | |
5c3cc3ae | 7799 | vty_out (vty, "%sDisplayed %ld routes and %ld total paths%s", |
18200902 | 7800 | VTY_NEWLINE, output_count, total_count, VTY_NEWLINE); |
b05a1c8b | 7801 | } |
718e3744 | 7802 | |
7803 | return CMD_SUCCESS; | |
7804 | } | |
7805 | ||
5a646650 | 7806 | static int |
fee0f4c6 | 7807 | bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, |
856ca177 | 7808 | enum bgp_show_type type, void *output_arg, u_char use_json) |
fee0f4c6 | 7809 | { |
7810 | struct bgp_table *table; | |
7811 | ||
856ca177 MS |
7812 | if (bgp == NULL) |
7813 | { | |
7814 | bgp = bgp_get_default (); | |
7815 | } | |
fee0f4c6 | 7816 | |
7817 | if (bgp == NULL) | |
7818 | { | |
856ca177 MS |
7819 | if (!use_json) |
7820 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); | |
fee0f4c6 | 7821 | return CMD_WARNING; |
7822 | } | |
7823 | ||
fee0f4c6 | 7824 | table = bgp->rib[afi][safi]; |
7825 | ||
31303c3e DS |
7826 | return bgp_show_table (vty, bgp, table, type, output_arg, |
7827 | use_json); | |
fee0f4c6 | 7828 | } |
7829 | ||
f186de26 | 7830 | static void |
7831 | bgp_show_all_instances_routes_vty (struct vty *vty, afi_t afi, safi_t safi, | |
7832 | u_char use_json) | |
7833 | { | |
7834 | struct listnode *node, *nnode; | |
7835 | struct bgp *bgp; | |
7836 | struct bgp_table *table; | |
9f689658 DD |
7837 | int is_first = 1; |
7838 | ||
7839 | if (use_json) | |
7840 | vty_out (vty, "{%s", VTY_NEWLINE); | |
f186de26 | 7841 | |
7842 | for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) | |
7843 | { | |
9f689658 DD |
7844 | if (use_json) |
7845 | { | |
9f689658 DD |
7846 | if (! is_first) |
7847 | vty_out (vty, ",%s", VTY_NEWLINE); | |
7848 | else | |
7849 | is_first = 0; | |
7850 | ||
7851 | vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) | |
7852 | ? "Default" : bgp->name); | |
7853 | } | |
7854 | else | |
7855 | { | |
7856 | vty_out (vty, "%sInstance %s:%s", | |
7857 | VTY_NEWLINE, | |
7858 | (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) | |
7859 | ? "Default" : bgp->name, | |
7860 | VTY_NEWLINE); | |
7861 | } | |
f186de26 | 7862 | table = bgp->rib[afi][safi]; |
31303c3e DS |
7863 | bgp_show_table (vty, bgp, table, |
7864 | bgp_show_type_normal, NULL, use_json); | |
9f689658 | 7865 | |
f186de26 | 7866 | } |
9f689658 DD |
7867 | |
7868 | if (use_json) | |
7869 | vty_out (vty, "}%s", VTY_NEWLINE); | |
f186de26 | 7870 | } |
7871 | ||
718e3744 | 7872 | /* Header of detailed BGP route information */ |
94f2b392 | 7873 | static void |
718e3744 | 7874 | route_vty_out_detail_header (struct vty *vty, struct bgp *bgp, |
7875 | struct bgp_node *rn, | |
b05a1c8b DS |
7876 | struct prefix_rd *prd, afi_t afi, safi_t safi, |
7877 | json_object *json) | |
718e3744 | 7878 | { |
7879 | struct bgp_info *ri; | |
7880 | struct prefix *p; | |
7881 | struct peer *peer; | |
1eb8ef25 | 7882 | struct listnode *node, *nnode; |
718e3744 | 7883 | char buf1[INET6_ADDRSTRLEN]; |
7884 | char buf2[INET6_ADDRSTRLEN]; | |
7885 | int count = 0; | |
7886 | int best = 0; | |
7887 | int suppress = 0; | |
7888 | int no_export = 0; | |
7889 | int no_advertise = 0; | |
7890 | int local_as = 0; | |
adbac85e | 7891 | int first = 1; |
ffd0c037 | 7892 | json_object *json_adv_to = NULL; |
718e3744 | 7893 | |
7894 | p = &rn->p; | |
b05a1c8b DS |
7895 | |
7896 | if (json) | |
7897 | { | |
f1aa5d8a DS |
7898 | json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN)); |
7899 | json_object_int_add(json, "prefixlen", p->prefixlen); | |
b05a1c8b DS |
7900 | } |
7901 | else | |
7902 | { | |
7903 | vty_out (vty, "BGP routing table entry for %s%s%s/%d%s", | |
587ff0fd | 7904 | ((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) ? |
b05a1c8b DS |
7905 | prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""), |
7906 | safi == SAFI_MPLS_VPN ? ":" : "", | |
7907 | inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN), | |
7908 | p->prefixlen, VTY_NEWLINE); | |
7909 | } | |
718e3744 | 7910 | |
7911 | for (ri = rn->info; ri; ri = ri->next) | |
7912 | { | |
7913 | count++; | |
7914 | if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) | |
7915 | { | |
7916 | best = count; | |
fb982c25 | 7917 | if (ri->extra && ri->extra->suppress) |
718e3744 | 7918 | suppress = 1; |
7919 | if (ri->attr->community != NULL) | |
7920 | { | |
7921 | if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE)) | |
7922 | no_advertise = 1; | |
7923 | if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT)) | |
7924 | no_export = 1; | |
7925 | if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS)) | |
7926 | local_as = 1; | |
7927 | } | |
7928 | } | |
7929 | } | |
7930 | ||
b05a1c8b | 7931 | if (!json) |
718e3744 | 7932 | { |
b05a1c8b DS |
7933 | vty_out (vty, "Paths: (%d available", count); |
7934 | if (best) | |
7935 | { | |
7936 | vty_out (vty, ", best #%d", best); | |
7937 | if (safi == SAFI_UNICAST) | |
46827ae9 DS |
7938 | vty_out (vty, ", table %s", |
7939 | (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) | |
7940 | ? "Default-IP-Routing-Table" : bgp->name); | |
b05a1c8b DS |
7941 | } |
7942 | else | |
7943 | vty_out (vty, ", no best path"); | |
7944 | ||
7945 | if (no_advertise) | |
7946 | vty_out (vty, ", not advertised to any peer"); | |
7947 | else if (no_export) | |
7948 | vty_out (vty, ", not advertised to EBGP peer"); | |
7949 | else if (local_as) | |
7950 | vty_out (vty, ", not advertised outside local AS"); | |
7951 | ||
7952 | if (suppress) | |
7953 | vty_out (vty, ", Advertisements suppressed by an aggregate."); | |
7954 | vty_out (vty, ")%s", VTY_NEWLINE); | |
718e3744 | 7955 | } |
718e3744 | 7956 | |
adbac85e DW |
7957 | /* If we are not using addpath then we can display Advertised to and that will |
7958 | * show what peers we advertised the bestpath to. If we are using addpath | |
7959 | * though then we must display Advertised to on a path-by-path basis. */ | |
7960 | if (!bgp->addpath_tx_used[afi][safi]) | |
718e3744 | 7961 | { |
adbac85e DW |
7962 | for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) |
7963 | { | |
7964 | if (bgp_adj_out_lookup (peer, rn, 0)) | |
b05a1c8b | 7965 | { |
adbac85e | 7966 | if (json && !json_adv_to) |
f1aa5d8a | 7967 | json_adv_to = json_object_new_object(); |
6410e93a | 7968 | |
adbac85e DW |
7969 | route_vty_out_advertised_to(vty, peer, &first, |
7970 | " Advertised to non peer-group peers:\n ", | |
7971 | json_adv_to); | |
b05a1c8b | 7972 | } |
adbac85e | 7973 | } |
036a4e7d | 7974 | |
adbac85e DW |
7975 | if (json) |
7976 | { | |
7977 | if (json_adv_to) | |
7978 | { | |
7979 | json_object_object_add(json, "advertisedTo", json_adv_to); | |
b05a1c8b | 7980 | } |
adbac85e DW |
7981 | } |
7982 | else | |
b05a1c8b | 7983 | { |
adbac85e DW |
7984 | if (first) |
7985 | vty_out (vty, " Not advertised to any peer"); | |
7986 | vty_out (vty, "%s", VTY_NEWLINE); | |
b05a1c8b DS |
7987 | } |
7988 | } | |
718e3744 | 7989 | } |
7990 | ||
7991 | /* Display specified route of BGP table. */ | |
94f2b392 | 7992 | static int |
fee0f4c6 | 7993 | bgp_show_route_in_table (struct vty *vty, struct bgp *bgp, |
fd79ac91 | 7994 | struct bgp_table *rib, const char *ip_str, |
7995 | afi_t afi, safi_t safi, struct prefix_rd *prd, | |
b05a1c8b DS |
7996 | int prefix_check, enum bgp_path_type pathtype, |
7997 | u_char use_json) | |
718e3744 | 7998 | { |
7999 | int ret; | |
8000 | int header; | |
8001 | int display = 0; | |
8002 | struct prefix match; | |
8003 | struct bgp_node *rn; | |
8004 | struct bgp_node *rm; | |
8005 | struct bgp_info *ri; | |
718e3744 | 8006 | struct bgp_table *table; |
f1aa5d8a DS |
8007 | json_object *json = NULL; |
8008 | json_object *json_paths = NULL; | |
718e3744 | 8009 | |
718e3744 | 8010 | /* Check IP address argument. */ |
8011 | ret = str2prefix (ip_str, &match); | |
8012 | if (! ret) | |
8013 | { | |
8014 | vty_out (vty, "address is malformed%s", VTY_NEWLINE); | |
8015 | return CMD_WARNING; | |
8016 | } | |
8017 | ||
8018 | match.family = afi2family (afi); | |
8019 | ||
b05a1c8b DS |
8020 | if (use_json) |
8021 | { | |
8022 | json = json_object_new_object(); | |
8023 | json_paths = json_object_new_array(); | |
8024 | } | |
b05a1c8b | 8025 | |
587ff0fd | 8026 | if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) |
718e3744 | 8027 | { |
fee0f4c6 | 8028 | for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn)) |
718e3744 | 8029 | { |
8030 | if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0) | |
8031 | continue; | |
8032 | ||
8033 | if ((table = rn->info) != NULL) | |
8034 | { | |
8035 | header = 1; | |
8036 | ||
8037 | if ((rm = bgp_node_match (table, &match)) != NULL) | |
8038 | { | |
8039 | if (prefix_check && rm->p.prefixlen != match.prefixlen) | |
6c88b44d CC |
8040 | { |
8041 | bgp_unlock_node (rm); | |
8042 | continue; | |
8043 | } | |
718e3744 | 8044 | |
8045 | for (ri = rm->info; ri; ri = ri->next) | |
8046 | { | |
8047 | if (header) | |
8048 | { | |
8049 | route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p, | |
587ff0fd | 8050 | AFI_IP, safi, json); |
718e3744 | 8051 | header = 0; |
8052 | } | |
8053 | display++; | |
4092b06c DS |
8054 | |
8055 | if (pathtype == BGP_PATH_ALL || | |
8056 | (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) || | |
8057 | (pathtype == BGP_PATH_MULTIPATH && | |
8058 | (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)))) | |
587ff0fd | 8059 | route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi, json_paths); |
718e3744 | 8060 | } |
6c88b44d CC |
8061 | |
8062 | bgp_unlock_node (rm); | |
718e3744 | 8063 | } |
8064 | } | |
8065 | } | |
8066 | } | |
8067 | else | |
8068 | { | |
8069 | header = 1; | |
8070 | ||
fee0f4c6 | 8071 | if ((rn = bgp_node_match (rib, &match)) != NULL) |
718e3744 | 8072 | { |
8073 | if (! prefix_check || rn->p.prefixlen == match.prefixlen) | |
8074 | { | |
8075 | for (ri = rn->info; ri; ri = ri->next) | |
8076 | { | |
8077 | if (header) | |
8078 | { | |
b05a1c8b | 8079 | route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json); |
718e3744 | 8080 | header = 0; |
8081 | } | |
8082 | display++; | |
4092b06c DS |
8083 | |
8084 | if (pathtype == BGP_PATH_ALL || | |
8085 | (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) || | |
8086 | (pathtype == BGP_PATH_MULTIPATH && | |
8087 | (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)))) | |
b05a1c8b | 8088 | route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths); |
718e3744 | 8089 | } |
8090 | } | |
6c88b44d CC |
8091 | |
8092 | bgp_unlock_node (rn); | |
718e3744 | 8093 | } |
8094 | } | |
8095 | ||
e5eee9af | 8096 | if (use_json) |
718e3744 | 8097 | { |
e5eee9af DS |
8098 | if (display) |
8099 | json_object_object_add(json, "paths", json_paths); | |
8100 | ||
2aac5767 | 8101 | vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE); |
f1aa5d8a | 8102 | json_object_free(json); |
b05a1c8b DS |
8103 | } |
8104 | else | |
8105 | { | |
e5eee9af | 8106 | if (!display) |
b05a1c8b DS |
8107 | { |
8108 | vty_out (vty, "%% Network not in table%s", VTY_NEWLINE); | |
8109 | return CMD_WARNING; | |
8110 | } | |
8111 | } | |
8112 | ||
718e3744 | 8113 | return CMD_SUCCESS; |
8114 | } | |
8115 | ||
fee0f4c6 | 8116 | /* Display specified route of Main RIB */ |
94f2b392 | 8117 | static int |
fd79ac91 | 8118 | bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str, |
fee0f4c6 | 8119 | afi_t afi, safi_t safi, struct prefix_rd *prd, |
b05a1c8b DS |
8120 | int prefix_check, enum bgp_path_type pathtype, |
8121 | u_char use_json) | |
fee0f4c6 | 8122 | { |
8123 | struct bgp *bgp; | |
8124 | ||
8125 | /* BGP structure lookup. */ | |
8126 | if (view_name) | |
8127 | { | |
8128 | bgp = bgp_lookup_by_name (view_name); | |
8129 | if (bgp == NULL) | |
8130 | { | |
6aeb9e78 | 8131 | vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE); |
fee0f4c6 | 8132 | return CMD_WARNING; |
8133 | } | |
8134 | } | |
8135 | else | |
8136 | { | |
8137 | bgp = bgp_get_default (); | |
8138 | if (bgp == NULL) | |
8139 | { | |
8140 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); | |
8141 | return CMD_WARNING; | |
8142 | } | |
8143 | } | |
8144 | ||
8145 | return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str, | |
b05a1c8b DS |
8146 | afi, safi, prd, prefix_check, pathtype, |
8147 | use_json); | |
fee0f4c6 | 8148 | } |
8149 | ||
718e3744 | 8150 | /* BGP route print out function. */ |
8151 | DEFUN (show_ip_bgp, | |
8152 | show_ip_bgp_cmd, | |
b05a1c8b | 8153 | "show ip bgp {json}", |
47fc97cc DS |
8154 | SHOW_STR |
8155 | IP_STR | |
b05a1c8b DS |
8156 | BGP_STR |
8157 | "JavaScript Object Notation\n") | |
47fc97cc | 8158 | { |
db7c8528 | 8159 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv)); |
718e3744 | 8160 | } |
8161 | ||
8162 | DEFUN (show_ip_bgp_ipv4, | |
8163 | show_ip_bgp_ipv4_cmd, | |
d02fbbdb | 8164 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" {json}", |
718e3744 | 8165 | SHOW_STR |
8166 | IP_STR | |
8167 | BGP_STR | |
8168 | "Address family\n" | |
d02fbbdb | 8169 | BGP_SAFI_HELP_STR |
b05a1c8b | 8170 | "JavaScript Object Notation\n") |
718e3744 | 8171 | { |
db7c8528 | 8172 | u_char uj = use_json(argc, argv); |
718e3744 | 8173 | |
ccbb332a LB |
8174 | return bgp_show (vty, NULL, AFI_IP, |
8175 | bgp_vty_safi_from_arg(argv[0]), | |
8176 | bgp_show_type_normal, NULL, uj); | |
718e3744 | 8177 | } |
8178 | ||
95cbbd2a ML |
8179 | ALIAS (show_ip_bgp_ipv4, |
8180 | show_bgp_ipv4_safi_cmd, | |
d02fbbdb | 8181 | "show bgp ipv4 "BGP_SAFI_CMD_STR" {json}", |
95cbbd2a ML |
8182 | SHOW_STR |
8183 | BGP_STR | |
8184 | "Address family\n" | |
d02fbbdb | 8185 | BGP_SAFI_HELP_STR |
b05a1c8b | 8186 | "JavaScript Object Notation\n") |
47fc97cc | 8187 | |
718e3744 | 8188 | DEFUN (show_ip_bgp_route, |
8189 | show_ip_bgp_route_cmd, | |
b05a1c8b | 8190 | "show ip bgp A.B.C.D {json}", |
718e3744 | 8191 | SHOW_STR |
8192 | IP_STR | |
8193 | BGP_STR | |
b05a1c8b DS |
8194 | "Network in the BGP routing table to display\n" |
8195 | "JavaScript Object Notation\n") | |
718e3744 | 8196 | { |
db7c8528 | 8197 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); |
4092b06c DS |
8198 | } |
8199 | ||
8200 | DEFUN (show_ip_bgp_route_pathtype, | |
8201 | show_ip_bgp_route_pathtype_cmd, | |
b05a1c8b | 8202 | "show ip bgp A.B.C.D (bestpath|multipath) {json}", |
4092b06c DS |
8203 | SHOW_STR |
8204 | IP_STR | |
8205 | BGP_STR | |
8206 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
8207 | "Display only the bestpath\n" | |
b05a1c8b DS |
8208 | "Display only multipaths\n" |
8209 | "JavaScript Object Notation\n") | |
4092b06c | 8210 | { |
db7c8528 | 8211 | u_char uj = use_json(argc, argv); |
b05a1c8b | 8212 | |
4092b06c | 8213 | if (strncmp (argv[1], "b", 1) == 0) |
db7c8528 | 8214 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj); |
4092b06c | 8215 | else |
db7c8528 | 8216 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj); |
4092b06c DS |
8217 | } |
8218 | ||
8219 | DEFUN (show_bgp_ipv4_safi_route_pathtype, | |
8220 | show_bgp_ipv4_safi_route_pathtype_cmd, | |
d02fbbdb | 8221 | "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D (bestpath|multipath) {json}", |
4092b06c DS |
8222 | SHOW_STR |
8223 | BGP_STR | |
d02fbbdb | 8224 | BGP_AFI_SAFI_HELP_STR |
4092b06c DS |
8225 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
8226 | "Display only the bestpath\n" | |
b05a1c8b DS |
8227 | "Display only multipaths\n" |
8228 | "JavaScript Object Notation\n") | |
4092b06c | 8229 | { |
db7c8528 | 8230 | u_char uj = use_json(argc, argv); |
b05a1c8b | 8231 | |
ccbb332a LB |
8232 | if (strncmp (argv[2], "b", 1) == 0) |
8233 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, | |
8234 | bgp_vty_safi_from_arg(argv[0]), | |
8235 | NULL, 0, BGP_PATH_BESTPATH, uj); | |
4092b06c | 8236 | else |
ccbb332a LB |
8237 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, |
8238 | bgp_vty_safi_from_arg(argv[0]), | |
8239 | NULL, 0, BGP_PATH_MULTIPATH, uj); | |
718e3744 | 8240 | } |
8241 | ||
e3e29b32 LB |
8242 | DEFUN (show_bgp_ipv4_prefix, |
8243 | show_bgp_ipv4_prefix_cmd, | |
8244 | "show bgp ipv4 A.B.C.D/M {json}", | |
8245 | SHOW_STR | |
8246 | BGP_STR | |
8247 | IP_STR | |
8248 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
8249 | JSON_STR) | |
8250 | { | |
8251 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc, argv)); | |
8252 | } | |
8253 | ||
8254 | DEFUN (show_bgp_ipv6_route, | |
8255 | show_bgp_ipv6_route_cmd, | |
847e983f | 8256 | "show bgp ipv6 X:X::X:X {json}", |
e3e29b32 LB |
8257 | SHOW_STR |
8258 | BGP_STR | |
8259 | "Address family\n" | |
8260 | "Network in the BGP routing table to display\n" | |
8261 | JSON_STR) | |
8262 | { | |
8263 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json (argc, argv)); | |
8264 | } | |
8265 | ||
8266 | DEFUN (show_bgp_ipv6_prefix, | |
8267 | show_bgp_ipv6_prefix_cmd, | |
8268 | "show bgp ipv6 X:X::X:X/M {json}", | |
8269 | SHOW_STR | |
8270 | BGP_STR | |
8271 | IP_STR | |
8272 | "IPv6 prefix <network>/<length>\n" | |
8273 | JSON_STR) | |
8274 | { | |
8275 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc,argv)); | |
8276 | } | |
8277 | ||
718e3744 | 8278 | DEFUN (show_ip_bgp_ipv4_route, |
8279 | show_ip_bgp_ipv4_route_cmd, | |
d02fbbdb | 8280 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D {json}", |
718e3744 | 8281 | SHOW_STR |
8282 | IP_STR | |
8283 | BGP_STR | |
d02fbbdb | 8284 | BGP_AFI_SAFI_HELP_STR |
b05a1c8b DS |
8285 | "Network in the BGP routing table to display\n" |
8286 | "JavaScript Object Notation\n") | |
718e3744 | 8287 | { |
db7c8528 | 8288 | u_char uj = use_json(argc, argv); |
b05a1c8b | 8289 | |
ccbb332a LB |
8290 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, |
8291 | bgp_vty_safi_from_arg(argv[0]), | |
8292 | NULL, 0, BGP_PATH_ALL, uj); | |
718e3744 | 8293 | } |
8294 | ||
95cbbd2a ML |
8295 | ALIAS (show_ip_bgp_ipv4_route, |
8296 | show_bgp_ipv4_safi_route_cmd, | |
d02fbbdb | 8297 | "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D {json}", |
95cbbd2a ML |
8298 | SHOW_STR |
8299 | BGP_STR | |
d02fbbdb | 8300 | BGP_AFI_SAFI_HELP_STR |
b05a1c8b DS |
8301 | "Network in the BGP routing table to display\n" |
8302 | "JavaScript Object Notation\n") | |
95cbbd2a | 8303 | |
ccbb332a LB |
8304 | DEFUN (show_bgp_ipv4_safi_rd_route, |
8305 | show_bgp_ipv4_safi_rd_route_cmd, | |
8306 | "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D {json}", | |
e3e29b32 LB |
8307 | SHOW_STR |
8308 | BGP_STR | |
8309 | "Address Family\n" | |
ccbb332a LB |
8310 | "Address Family Modifier\n" |
8311 | "Address Family Modifier\n" | |
8312 | "Display information for a route distinguisher\n" | |
8313 | "ENCAP Route Distinguisher\n" | |
8314 | "Network in the BGP routing table to display\n") | |
e3e29b32 | 8315 | { |
ccbb332a LB |
8316 | int ret; |
8317 | struct prefix_rd prd; | |
8318 | safi_t safi; | |
8319 | ||
8320 | if (bgp_parse_safi(argv[0], &safi)) { | |
8321 | vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE); | |
8322 | return CMD_WARNING; | |
8323 | } | |
8324 | ret = str2prefix_rd (argv[1], &prd); | |
8325 | if (! ret) | |
8326 | { | |
8327 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); | |
8328 | return CMD_WARNING; | |
8329 | } | |
8330 | return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0, BGP_PATH_ALL, use_json (argc, argv)); | |
e3e29b32 LB |
8331 | } |
8332 | ||
ccbb332a LB |
8333 | DEFUN (show_bgp_ipv6_safi_rd_route, |
8334 | show_bgp_ipv6_safi_rd_route_cmd, | |
8335 | "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X {json}", | |
e3e29b32 LB |
8336 | SHOW_STR |
8337 | BGP_STR | |
8338 | "Address Family\n" | |
ccbb332a LB |
8339 | "Address Family Modifier\n" |
8340 | "Address Family Modifier\n" | |
8341 | "Display information for a route distinguisher\n" | |
8342 | "ENCAP Route Distinguisher\n" | |
8343 | "Network in the BGP routing table to display\n") | |
e3e29b32 | 8344 | { |
ccbb332a LB |
8345 | int ret; |
8346 | struct prefix_rd prd; | |
8347 | safi_t safi; | |
8348 | ||
8349 | if (bgp_parse_safi(argv[0], &safi)) { | |
8350 | vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE); | |
8351 | return CMD_WARNING; | |
8352 | } | |
8353 | ret = str2prefix_rd (argv[1], &prd); | |
8354 | if (! ret) | |
8355 | { | |
8356 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); | |
8357 | return CMD_WARNING; | |
8358 | } | |
8359 | return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0, BGP_PATH_ALL, use_json (argc, argv)); | |
e3e29b32 LB |
8360 | } |
8361 | ||
ccbb332a LB |
8362 | |
8363 | DEFUN (show_bgp_ipv4_safi_rd_prefix, | |
8364 | show_bgp_ipv4_safi_rd_prefix_cmd, | |
8365 | "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}", | |
e3e29b32 LB |
8366 | SHOW_STR |
8367 | BGP_STR | |
ccbb332a LB |
8368 | "Address Family\n" |
8369 | "Address Family Modifier\n" | |
8370 | "Address Family Modifier\n" | |
e3e29b32 | 8371 | "Display information for a route distinguisher\n" |
ccbb332a LB |
8372 | "ENCAP Route Distinguisher\n" |
8373 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") | |
e3e29b32 LB |
8374 | { |
8375 | int ret; | |
8376 | struct prefix_rd prd; | |
ccbb332a | 8377 | safi_t safi; |
e3e29b32 | 8378 | |
ccbb332a LB |
8379 | if (bgp_parse_safi(argv[0], &safi)) { |
8380 | vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE); | |
8381 | return CMD_WARNING; | |
8382 | } | |
8383 | ||
8384 | ret = str2prefix_rd (argv[1], &prd); | |
e3e29b32 LB |
8385 | if (! ret) |
8386 | { | |
8387 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); | |
8388 | return CMD_WARNING; | |
8389 | } | |
ccbb332a | 8390 | return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1, BGP_PATH_ALL, use_json (argc, argv)); |
e3e29b32 LB |
8391 | } |
8392 | ||
ccbb332a LB |
8393 | DEFUN (show_bgp_ipv6_safi_rd_prefix, |
8394 | show_bgp_ipv6_safi_rd_prefix_cmd, | |
8395 | "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M {json}", | |
e3e29b32 LB |
8396 | SHOW_STR |
8397 | BGP_STR | |
8398 | "Address Family\n" | |
ccbb332a LB |
8399 | "Address Family Modifier\n" |
8400 | "Address Family Modifier\n" | |
e3e29b32 | 8401 | "Display information for a route distinguisher\n" |
ccbb332a LB |
8402 | "ENCAP Route Distinguisher\n" |
8403 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") | |
e3e29b32 LB |
8404 | { |
8405 | int ret; | |
8406 | struct prefix_rd prd; | |
ccbb332a | 8407 | safi_t safi; |
e3e29b32 | 8408 | |
ccbb332a LB |
8409 | if (bgp_parse_safi(argv[0], &safi)) { |
8410 | vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE); | |
8411 | return CMD_WARNING; | |
8412 | } | |
8413 | ||
8414 | ret = str2prefix_rd (argv[1], &prd); | |
e3e29b32 LB |
8415 | if (! ret) |
8416 | { | |
8417 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); | |
8418 | return CMD_WARNING; | |
8419 | } | |
ccbb332a | 8420 | return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1, BGP_PATH_ALL, use_json (argc, argv)); |
e3e29b32 | 8421 | } |
4092b06c | 8422 | |
718e3744 | 8423 | DEFUN (show_ip_bgp_prefix, |
8424 | show_ip_bgp_prefix_cmd, | |
b05a1c8b | 8425 | "show ip bgp A.B.C.D/M {json}", |
718e3744 | 8426 | SHOW_STR |
8427 | IP_STR | |
8428 | BGP_STR | |
b05a1c8b DS |
8429 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
8430 | "JavaScript Object Notation\n") | |
718e3744 | 8431 | { |
db7c8528 | 8432 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv)); |
4092b06c DS |
8433 | } |
8434 | ||
8435 | DEFUN (show_ip_bgp_prefix_pathtype, | |
8436 | show_ip_bgp_prefix_pathtype_cmd, | |
b05a1c8b | 8437 | "show ip bgp A.B.C.D/M (bestpath|multipath) {json}", |
4092b06c DS |
8438 | SHOW_STR |
8439 | IP_STR | |
8440 | BGP_STR | |
8441 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
8442 | "Display only the bestpath\n" | |
b05a1c8b DS |
8443 | "Display only multipaths\n" |
8444 | "JavaScript Object Notation\n") | |
4092b06c | 8445 | { |
db7c8528 | 8446 | u_char uj = use_json(argc, argv); |
4092b06c | 8447 | if (strncmp (argv[1], "b", 1) == 0) |
db7c8528 | 8448 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj); |
4092b06c | 8449 | else |
db7c8528 | 8450 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj); |
718e3744 | 8451 | } |
8452 | ||
8453 | DEFUN (show_ip_bgp_ipv4_prefix, | |
8454 | show_ip_bgp_ipv4_prefix_cmd, | |
d02fbbdb | 8455 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M {json}", |
718e3744 | 8456 | SHOW_STR |
8457 | IP_STR | |
8458 | BGP_STR | |
d02fbbdb | 8459 | BGP_AFI_SAFI_HELP_STR |
b05a1c8b DS |
8460 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
8461 | "JavaScript Object Notation\n") | |
718e3744 | 8462 | { |
db7c8528 | 8463 | u_char uj = use_json(argc, argv); |
b05a1c8b | 8464 | |
ccbb332a LB |
8465 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, |
8466 | bgp_vty_safi_from_arg(argv[0]), | |
8467 | NULL, 1, BGP_PATH_ALL, uj); | |
718e3744 | 8468 | } |
8469 | ||
95cbbd2a ML |
8470 | ALIAS (show_ip_bgp_ipv4_prefix, |
8471 | show_bgp_ipv4_safi_prefix_cmd, | |
d02fbbdb | 8472 | "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M {json}", |
95cbbd2a ML |
8473 | SHOW_STR |
8474 | BGP_STR | |
d02fbbdb | 8475 | BGP_AFI_SAFI_HELP_STR |
b05a1c8b DS |
8476 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
8477 | "JavaScript Object Notation\n") | |
95cbbd2a | 8478 | |
4092b06c DS |
8479 | DEFUN (show_ip_bgp_ipv4_prefix_pathtype, |
8480 | show_ip_bgp_ipv4_prefix_pathtype_cmd, | |
d02fbbdb | 8481 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M (bestpath|multipath) {json}", |
4092b06c DS |
8482 | SHOW_STR |
8483 | IP_STR | |
8484 | BGP_STR | |
d02fbbdb | 8485 | BGP_AFI_SAFI_HELP_STR |
4092b06c DS |
8486 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
8487 | "Display only the bestpath\n" | |
b05a1c8b DS |
8488 | "Display only multipaths\n" |
8489 | "JavaScript Object Notation\n") | |
4092b06c | 8490 | { |
db7c8528 | 8491 | u_char uj = use_json(argc, argv); |
b05a1c8b | 8492 | |
ccbb332a LB |
8493 | if (strncmp (argv[2], "b", 1) == 0) |
8494 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, | |
8495 | bgp_vty_safi_from_arg(argv[0]), | |
8496 | NULL, 1, BGP_PATH_BESTPATH, uj); | |
4092b06c | 8497 | else |
ccbb332a LB |
8498 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, |
8499 | bgp_vty_safi_from_arg(argv[0]), | |
8500 | NULL, 1, BGP_PATH_MULTIPATH, uj); | |
4092b06c DS |
8501 | } |
8502 | ||
8503 | ALIAS (show_ip_bgp_ipv4_prefix_pathtype, | |
8504 | show_bgp_ipv4_safi_prefix_pathtype_cmd, | |
d02fbbdb | 8505 | "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M (bestpath|multipath) {json}", |
4092b06c DS |
8506 | SHOW_STR |
8507 | BGP_STR | |
d02fbbdb | 8508 | BGP_AFI_SAFI_HELP_STR |
4092b06c DS |
8509 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
8510 | "Display only the bestpath\n" | |
b05a1c8b DS |
8511 | "Display only multipaths\n" |
8512 | "JavaScript Object Notation\n") | |
4092b06c | 8513 | |
718e3744 | 8514 | |
8515 | DEFUN (show_ip_bgp_view, | |
8386ac43 | 8516 | show_ip_bgp_instance_cmd, |
8517 | "show ip bgp " BGP_INSTANCE_CMD " {json}", | |
718e3744 | 8518 | SHOW_STR |
8519 | IP_STR | |
8520 | BGP_STR | |
8386ac43 | 8521 | BGP_INSTANCE_HELP_STR |
b05a1c8b | 8522 | "JavaScript Object Notation\n") |
718e3744 | 8523 | { |
bb46e94f | 8524 | struct bgp *bgp; |
8525 | ||
8526 | /* BGP structure lookup. */ | |
6aeb9e78 | 8527 | bgp = bgp_lookup_by_name (argv[1]); |
bb46e94f | 8528 | if (bgp == NULL) |
8529 | { | |
6aeb9e78 | 8530 | vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE); |
bb46e94f | 8531 | return CMD_WARNING; |
8532 | } | |
8533 | ||
db7c8528 | 8534 | return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv)); |
718e3744 | 8535 | } |
8536 | ||
f186de26 | 8537 | DEFUN (show_ip_bgp_instance_all, |
8538 | show_ip_bgp_instance_all_cmd, | |
8539 | "show ip bgp " BGP_INSTANCE_ALL_CMD " {json}", | |
8540 | SHOW_STR | |
8541 | IP_STR | |
8542 | BGP_STR | |
8543 | BGP_INSTANCE_ALL_HELP_STR | |
8544 | "JavaScript Object Notation\n") | |
8545 | { | |
8546 | u_char uj = use_json(argc, argv); | |
8547 | ||
8548 | bgp_show_all_instances_routes_vty (vty, AFI_IP, SAFI_UNICAST, uj); | |
8549 | return CMD_SUCCESS; | |
8550 | } | |
8551 | ||
8386ac43 | 8552 | DEFUN (show_ip_bgp_instance_route, |
8553 | show_ip_bgp_instance_route_cmd, | |
8554 | "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D {json}", | |
718e3744 | 8555 | SHOW_STR |
8556 | IP_STR | |
8557 | BGP_STR | |
8386ac43 | 8558 | BGP_INSTANCE_HELP_STR |
b05a1c8b DS |
8559 | "Network in the BGP routing table to display\n" |
8560 | "JavaScript Object Notation\n") | |
718e3744 | 8561 | { |
6aeb9e78 | 8562 | return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 8563 | } |
8564 | ||
8386ac43 | 8565 | DEFUN (show_ip_bgp_instance_route_pathtype, |
8566 | show_ip_bgp_instance_route_pathtype_cmd, | |
8567 | "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D (bestpath|multipath) {json}", | |
50ef26d4 | 8568 | SHOW_STR |
8569 | IP_STR | |
8570 | BGP_STR | |
8386ac43 | 8571 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 8572 | "Network in the BGP routing table to display\n" |
8573 | "Display only the bestpath\n" | |
8574 | "Display only multipaths\n" | |
8575 | "JavaScript Object Notation\n") | |
8576 | { | |
8577 | u_char uj = use_json(argc, argv); | |
8578 | ||
8579 | if (strncmp (argv[3], "b", 1) == 0) | |
8580 | return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj); | |
8581 | else | |
8582 | return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj); | |
8583 | } | |
8584 | ||
8386ac43 | 8585 | DEFUN (show_ip_bgp_instance_prefix, |
8586 | show_ip_bgp_instance_prefix_cmd, | |
8587 | "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M {json}", | |
718e3744 | 8588 | SHOW_STR |
8589 | IP_STR | |
8590 | BGP_STR | |
8386ac43 | 8591 | BGP_INSTANCE_HELP_STR |
b05a1c8b DS |
8592 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
8593 | "JavaScript Object Notation\n") | |
718e3744 | 8594 | { |
6aeb9e78 | 8595 | return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 8596 | } |
8597 | ||
8386ac43 | 8598 | DEFUN (show_ip_bgp_instance_prefix_pathtype, |
8599 | show_ip_bgp_instance_prefix_pathtype_cmd, | |
8600 | "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M (bestpath|multipath) {json}", | |
50ef26d4 | 8601 | SHOW_STR |
8602 | IP_STR | |
8603 | BGP_STR | |
8386ac43 | 8604 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 8605 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
8606 | "Display only the bestpath\n" | |
8607 | "Display only multipaths\n" | |
8608 | "JavaScript Object Notation\n") | |
8609 | { | |
8610 | u_char uj = use_json(argc, argv); | |
8611 | if (strncmp (argv[3], "b", 1) == 0) | |
8612 | return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj); | |
8613 | else | |
8614 | return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj); | |
8615 | } | |
8616 | ||
718e3744 | 8617 | #ifdef HAVE_IPV6 |
8618 | DEFUN (show_bgp, | |
8619 | show_bgp_cmd, | |
b05a1c8b | 8620 | "show bgp {json}", |
718e3744 | 8621 | SHOW_STR |
b05a1c8b DS |
8622 | BGP_STR |
8623 | "JavaScript Object Notation\n") | |
718e3744 | 8624 | { |
5a646650 | 8625 | return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, |
db7c8528 | 8626 | NULL, use_json(argc, argv)); |
718e3744 | 8627 | } |
8628 | ||
8629 | ALIAS (show_bgp, | |
8630 | show_bgp_ipv6_cmd, | |
b05a1c8b | 8631 | "show bgp ipv6 {json}", |
718e3744 | 8632 | SHOW_STR |
8633 | BGP_STR | |
b05a1c8b DS |
8634 | "Address family\n" |
8635 | "JavaScript Object Notation\n") | |
718e3744 | 8636 | |
95cbbd2a ML |
8637 | DEFUN (show_bgp_ipv6_safi, |
8638 | show_bgp_ipv6_safi_cmd, | |
d02fbbdb | 8639 | "show bgp ipv6 "BGP_SAFI_CMD_STR" {json}", |
95cbbd2a ML |
8640 | SHOW_STR |
8641 | BGP_STR | |
8642 | "Address family\n" | |
d02fbbdb | 8643 | BGP_SAFI_HELP_STR |
b05a1c8b | 8644 | "JavaScript Object Notation\n") |
47fc97cc | 8645 | { |
db7c8528 | 8646 | u_char uj = use_json(argc, argv); |
47fc97cc | 8647 | |
ccbb332a LB |
8648 | return bgp_show (vty, NULL, AFI_IP6, |
8649 | bgp_vty_safi_from_arg(argv[0]), | |
8650 | bgp_show_type_normal, NULL, uj); | |
95cbbd2a ML |
8651 | } |
8652 | ||
47e9b292 DW |
8653 | static void |
8654 | bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty) | |
8655 | { | |
8656 | vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our" | |
8657 | " next release%sPlese use 'show bgp ipv6' instead%s%s", | |
8658 | VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE); | |
8659 | } | |
8660 | ||
718e3744 | 8661 | /* old command */ |
8662 | DEFUN (show_ipv6_bgp, | |
8663 | show_ipv6_bgp_cmd, | |
b05a1c8b | 8664 | "show ipv6 bgp {json}", |
718e3744 | 8665 | SHOW_STR |
8666 | IP_STR | |
b05a1c8b DS |
8667 | BGP_STR |
8668 | "JavaScript Object Notation\n") | |
718e3744 | 8669 | { |
47e9b292 | 8670 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
5a646650 | 8671 | return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, |
db7c8528 | 8672 | NULL, use_json(argc, argv)); |
718e3744 | 8673 | } |
8674 | ||
8675 | DEFUN (show_bgp_route, | |
8676 | show_bgp_route_cmd, | |
b05a1c8b | 8677 | "show bgp X:X::X:X {json}", |
718e3744 | 8678 | SHOW_STR |
8679 | BGP_STR | |
b05a1c8b DS |
8680 | "Network in the BGP routing table to display\n" |
8681 | "JavaScript Object Notation\n") | |
718e3744 | 8682 | { |
db7c8528 | 8683 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 8684 | } |
8685 | ||
95cbbd2a ML |
8686 | DEFUN (show_bgp_ipv6_safi_route, |
8687 | show_bgp_ipv6_safi_route_cmd, | |
d02fbbdb | 8688 | "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X {json}", |
95cbbd2a ML |
8689 | SHOW_STR |
8690 | BGP_STR | |
d02fbbdb | 8691 | BGP_AFI_SAFI_HELP_STR |
b05a1c8b DS |
8692 | "Network in the BGP routing table to display\n" |
8693 | "JavaScript Object Notation\n") | |
95cbbd2a | 8694 | { |
db7c8528 | 8695 | u_char uj = use_json(argc, argv); |
95cbbd2a | 8696 | |
ccbb332a LB |
8697 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, |
8698 | bgp_vty_safi_from_arg(argv[0]), | |
8699 | NULL, 0, BGP_PATH_ALL, uj); | |
4092b06c DS |
8700 | } |
8701 | ||
8702 | DEFUN (show_bgp_route_pathtype, | |
8703 | show_bgp_route_pathtype_cmd, | |
b05a1c8b | 8704 | "show bgp X:X::X:X (bestpath|multipath) {json}", |
4092b06c DS |
8705 | SHOW_STR |
8706 | BGP_STR | |
8707 | "Network in the BGP routing table to display\n" | |
8708 | "Display only the bestpath\n" | |
b05a1c8b DS |
8709 | "Display only multipaths\n" |
8710 | "JavaScript Object Notation\n") | |
4092b06c | 8711 | { |
db7c8528 | 8712 | u_char uj = use_json(argc, argv); |
4092b06c | 8713 | if (strncmp (argv[1], "b", 1) == 0) |
db7c8528 | 8714 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj); |
4092b06c | 8715 | else |
db7c8528 | 8716 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj); |
4092b06c DS |
8717 | } |
8718 | ||
8719 | ALIAS (show_bgp_route_pathtype, | |
8720 | show_bgp_ipv6_route_pathtype_cmd, | |
b05a1c8b | 8721 | "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}", |
4092b06c DS |
8722 | SHOW_STR |
8723 | BGP_STR | |
8724 | "Address family\n" | |
8725 | "Network in the BGP routing table to display\n" | |
8726 | "Display only the bestpath\n" | |
b05a1c8b DS |
8727 | "Display only multipaths\n" |
8728 | "JavaScript Object Notation\n") | |
4092b06c DS |
8729 | |
8730 | DEFUN (show_bgp_ipv6_safi_route_pathtype, | |
8731 | show_bgp_ipv6_safi_route_pathtype_cmd, | |
d02fbbdb | 8732 | "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X (bestpath|multipath) {json}", |
4092b06c DS |
8733 | SHOW_STR |
8734 | BGP_STR | |
d02fbbdb | 8735 | BGP_AFI_SAFI_HELP_STR |
4092b06c DS |
8736 | "Network in the BGP routing table to display\n" |
8737 | "Display only the bestpath\n" | |
b05a1c8b DS |
8738 | "Display only multipaths\n" |
8739 | "JavaScript Object Notation\n") | |
4092b06c | 8740 | { |
db7c8528 | 8741 | u_char uj = use_json(argc, argv); |
ccbb332a LB |
8742 | if (strncmp (argv[2], "b", 1) == 0) |
8743 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, | |
8744 | bgp_vty_safi_from_arg(argv[0]), | |
8745 | NULL, 0, BGP_PATH_BESTPATH, uj); | |
4092b06c | 8746 | else |
ccbb332a LB |
8747 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, |
8748 | bgp_vty_safi_from_arg(argv[0]), | |
8749 | NULL, 0, BGP_PATH_MULTIPATH, uj); | |
95cbbd2a ML |
8750 | } |
8751 | ||
718e3744 | 8752 | /* old command */ |
8753 | DEFUN (show_ipv6_bgp_route, | |
8754 | show_ipv6_bgp_route_cmd, | |
b05a1c8b | 8755 | "show ipv6 bgp X:X::X:X {json}", |
718e3744 | 8756 | SHOW_STR |
8757 | IP_STR | |
8758 | BGP_STR | |
b05a1c8b DS |
8759 | "Network in the BGP routing table to display\n" |
8760 | "JavaScript Object Notation\n") | |
718e3744 | 8761 | { |
47e9b292 | 8762 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
db7c8528 | 8763 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 8764 | } |
8765 | ||
8766 | DEFUN (show_bgp_prefix, | |
8767 | show_bgp_prefix_cmd, | |
b05a1c8b | 8768 | "show bgp X:X::X:X/M {json}", |
718e3744 | 8769 | SHOW_STR |
8770 | BGP_STR | |
b05a1c8b DS |
8771 | "IPv6 prefix <network>/<length>\n" |
8772 | "JavaScript Object Notation\n") | |
718e3744 | 8773 | { |
db7c8528 | 8774 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 8775 | } |
8776 | ||
95cbbd2a ML |
8777 | DEFUN (show_bgp_ipv6_safi_prefix, |
8778 | show_bgp_ipv6_safi_prefix_cmd, | |
d02fbbdb | 8779 | "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X/M {json}", |
95cbbd2a ML |
8780 | SHOW_STR |
8781 | BGP_STR | |
d02fbbdb | 8782 | BGP_AFI_SAFI_HELP_STR |
b05a1c8b DS |
8783 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n" |
8784 | "JavaScript Object Notation\n") | |
95cbbd2a | 8785 | { |
db7c8528 | 8786 | u_char uj = use_json(argc, argv); |
95cbbd2a | 8787 | |
ccbb332a LB |
8788 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, |
8789 | bgp_vty_safi_from_arg(argv[0]), | |
8790 | NULL, 1, BGP_PATH_ALL, uj); | |
4092b06c DS |
8791 | } |
8792 | ||
8793 | DEFUN (show_bgp_prefix_pathtype, | |
8794 | show_bgp_prefix_pathtype_cmd, | |
b05a1c8b | 8795 | "show bgp X:X::X:X/M (bestpath|multipath) {json}", |
4092b06c DS |
8796 | SHOW_STR |
8797 | BGP_STR | |
8798 | "IPv6 prefix <network>/<length>\n" | |
8799 | "Display only the bestpath\n" | |
b05a1c8b DS |
8800 | "Display only multipaths\n" |
8801 | "JavaScript Object Notation\n") | |
4092b06c | 8802 | { |
db7c8528 | 8803 | u_char uj = use_json(argc, argv); |
4092b06c | 8804 | if (strncmp (argv[1], "b", 1) == 0) |
db7c8528 | 8805 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj); |
4092b06c | 8806 | else |
db7c8528 | 8807 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj); |
4092b06c DS |
8808 | } |
8809 | ||
8810 | ALIAS (show_bgp_prefix_pathtype, | |
8811 | show_bgp_ipv6_prefix_pathtype_cmd, | |
b05a1c8b | 8812 | "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}", |
4092b06c DS |
8813 | SHOW_STR |
8814 | BGP_STR | |
8815 | "Address family\n" | |
8816 | "IPv6 prefix <network>/<length>\n" | |
8817 | "Display only the bestpath\n" | |
b05a1c8b DS |
8818 | "Display only multipaths\n" |
8819 | "JavaScript Object Notation\n") | |
4092b06c DS |
8820 | |
8821 | DEFUN (show_bgp_ipv6_safi_prefix_pathtype, | |
8822 | show_bgp_ipv6_safi_prefix_pathtype_cmd, | |
d02fbbdb | 8823 | "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X/M (bestpath|multipath) {json}", |
4092b06c DS |
8824 | SHOW_STR |
8825 | BGP_STR | |
d02fbbdb | 8826 | BGP_AFI_SAFI_HELP_STR |
4092b06c DS |
8827 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n" |
8828 | "Display only the bestpath\n" | |
b05a1c8b DS |
8829 | "Display only multipaths\n" |
8830 | "JavaScript Object Notation\n") | |
4092b06c | 8831 | { |
db7c8528 | 8832 | u_char uj = use_json(argc, argv); |
ccbb332a LB |
8833 | if (strncmp (argv[2], "b", 1) == 0) |
8834 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, | |
8835 | bgp_vty_safi_from_arg(argv[0]), | |
8836 | NULL, 1, BGP_PATH_BESTPATH, uj); | |
4092b06c | 8837 | else |
ccbb332a LB |
8838 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, |
8839 | bgp_vty_safi_from_arg(argv[0]), NULL, 1, BGP_PATH_MULTIPATH, uj); | |
95cbbd2a ML |
8840 | } |
8841 | ||
718e3744 | 8842 | /* old command */ |
8843 | DEFUN (show_ipv6_bgp_prefix, | |
8844 | show_ipv6_bgp_prefix_cmd, | |
b05a1c8b | 8845 | "show ipv6 bgp X:X::X:X/M {json}", |
718e3744 | 8846 | SHOW_STR |
8847 | IP_STR | |
8848 | BGP_STR | |
b05a1c8b DS |
8849 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n" |
8850 | "JavaScript Object Notation\n") | |
718e3744 | 8851 | { |
47e9b292 | 8852 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
db7c8528 | 8853 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 8854 | } |
8855 | ||
bb46e94f | 8856 | DEFUN (show_bgp_view, |
8386ac43 | 8857 | show_bgp_instance_cmd, |
8858 | "show bgp " BGP_INSTANCE_CMD " {json}", | |
bb46e94f | 8859 | SHOW_STR |
8860 | BGP_STR | |
8386ac43 | 8861 | BGP_INSTANCE_HELP_STR |
b05a1c8b | 8862 | "JavaScript Object Notation\n") |
bb46e94f | 8863 | { |
8864 | struct bgp *bgp; | |
8865 | ||
8866 | /* BGP structure lookup. */ | |
6aeb9e78 | 8867 | bgp = bgp_lookup_by_name (argv[1]); |
bb46e94f | 8868 | if (bgp == NULL) |
db7c8528 | 8869 | { |
6aeb9e78 | 8870 | vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE); |
db7c8528 DS |
8871 | return CMD_WARNING; |
8872 | } | |
8873 | ||
8874 | return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv)); | |
bb46e94f | 8875 | } |
8876 | ||
f186de26 | 8877 | DEFUN (show_bgp_instance_all, |
8878 | show_bgp_instance_all_cmd, | |
8879 | "show bgp " BGP_INSTANCE_ALL_CMD " {json}", | |
8880 | SHOW_STR | |
8881 | BGP_STR | |
8882 | BGP_INSTANCE_ALL_HELP_STR | |
8883 | "JavaScript Object Notation\n") | |
8884 | { | |
8885 | u_char uj = use_json(argc, argv); | |
8886 | ||
8887 | bgp_show_all_instances_routes_vty (vty, AFI_IP6, SAFI_UNICAST, uj); | |
8888 | return CMD_SUCCESS; | |
8889 | } | |
8890 | ||
bb46e94f | 8891 | ALIAS (show_bgp_view, |
8386ac43 | 8892 | show_bgp_instance_ipv6_cmd, |
8893 | "show bgp " BGP_INSTANCE_CMD " ipv6 {json}", | |
bb46e94f | 8894 | SHOW_STR |
8895 | BGP_STR | |
8386ac43 | 8896 | BGP_INSTANCE_HELP_STR |
b05a1c8b DS |
8897 | "Address family\n" |
8898 | "JavaScript Object Notation\n") | |
bb46e94f | 8899 | |
8386ac43 | 8900 | DEFUN (show_bgp_instance_route, |
8901 | show_bgp_instance_route_cmd, | |
8902 | "show bgp " BGP_INSTANCE_CMD " X:X::X:X {json}", | |
bb46e94f | 8903 | SHOW_STR |
8904 | BGP_STR | |
8386ac43 | 8905 | BGP_INSTANCE_HELP_STR |
b05a1c8b DS |
8906 | "Network in the BGP routing table to display\n" |
8907 | "JavaScript Object Notation\n") | |
bb46e94f | 8908 | { |
6aeb9e78 | 8909 | return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); |
bb46e94f | 8910 | } |
8911 | ||
8386ac43 | 8912 | ALIAS (show_bgp_instance_route, |
8913 | show_bgp_instance_ipv6_route_cmd, | |
8914 | "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X {json}", | |
bb46e94f | 8915 | SHOW_STR |
8916 | BGP_STR | |
8386ac43 | 8917 | BGP_INSTANCE_HELP_STR |
bb46e94f | 8918 | "Address family\n" |
b05a1c8b DS |
8919 | "Network in the BGP routing table to display\n" |
8920 | "JavaScript Object Notation\n") | |
bb46e94f | 8921 | |
8386ac43 | 8922 | DEFUN (show_bgp_instance_route_pathtype, |
8923 | show_bgp_instance_route_pathtype_cmd, | |
8924 | "show bgp " BGP_INSTANCE_CMD " X:X::X:X (bestpath|multipath) {json}", | |
50ef26d4 | 8925 | SHOW_STR |
8926 | BGP_STR | |
8386ac43 | 8927 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 8928 | "Network in the BGP routing table to display\n" |
8929 | "Display only the bestpath\n" | |
8930 | "Display only multipaths\n" | |
8931 | "JavaScript Object Notation\n") | |
8932 | { | |
8933 | u_char uj = use_json(argc, argv); | |
8934 | if (strncmp (argv[3], "b", 1) == 0) | |
8935 | return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj); | |
8936 | else | |
8937 | return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj); | |
8938 | } | |
8939 | ||
8386ac43 | 8940 | ALIAS (show_bgp_instance_route_pathtype, |
8941 | show_bgp_instance_ipv6_route_pathtype_cmd, | |
8942 | "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X (bestpath|multipath) {json}", | |
50ef26d4 | 8943 | SHOW_STR |
8944 | BGP_STR | |
8386ac43 | 8945 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 8946 | "Address family\n" |
8947 | "Network in the BGP routing table to display\n" | |
8948 | "Display only the bestpath\n" | |
8949 | "Display only multipaths\n" | |
8950 | "JavaScript Object Notation\n") | |
8951 | ||
8386ac43 | 8952 | DEFUN (show_bgp_instance_prefix, |
8953 | show_bgp_instance_prefix_cmd, | |
8954 | "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M {json}", | |
bb46e94f | 8955 | SHOW_STR |
8956 | BGP_STR | |
8386ac43 | 8957 | BGP_INSTANCE_HELP_STR |
b05a1c8b DS |
8958 | "IPv6 prefix <network>/<length>\n" |
8959 | "JavaScript Object Notation\n") | |
bb46e94f | 8960 | { |
6aeb9e78 | 8961 | return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv)); |
bb46e94f | 8962 | } |
8963 | ||
8386ac43 | 8964 | ALIAS (show_bgp_instance_prefix, |
8965 | show_bgp_instance_ipv6_prefix_cmd, | |
8966 | "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M {json}", | |
bb46e94f | 8967 | SHOW_STR |
8968 | BGP_STR | |
8386ac43 | 8969 | BGP_INSTANCE_HELP_STR |
bb46e94f | 8970 | "Address family\n" |
b05a1c8b DS |
8971 | "IPv6 prefix <network>/<length>\n" |
8972 | "JavaScript Object Notation\n") | |
bb46e94f | 8973 | |
8386ac43 | 8974 | DEFUN (show_bgp_instance_prefix_pathtype, |
8975 | show_bgp_instance_prefix_pathtype_cmd, | |
8976 | "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M (bestpath|multipath) {json}", | |
50ef26d4 | 8977 | SHOW_STR |
8978 | BGP_STR | |
8386ac43 | 8979 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 8980 | "IPv6 prefix <network>/<length>\n" |
8981 | "Display only the bestpath\n" | |
8982 | "Display only multipaths\n" | |
8983 | "JavaScript Object Notation\n") | |
8984 | { | |
8985 | u_char uj = use_json(argc, argv); | |
8986 | if (strncmp (argv[3], "b", 1) == 0) | |
8987 | return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj); | |
8988 | else | |
8989 | return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj); | |
8990 | } | |
8991 | ||
8386ac43 | 8992 | ALIAS (show_bgp_instance_prefix_pathtype, |
8993 | show_bgp_instance_ipv6_prefix_pathtype_cmd, | |
8994 | "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M (bestpath|multipath) {json}", | |
50ef26d4 | 8995 | SHOW_STR |
8996 | BGP_STR | |
8386ac43 | 8997 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 8998 | "Address family\n" |
8999 | "IPv6 prefix <network>/<length>\n" | |
9000 | "Display only the bestpath\n" | |
9001 | "Display only multipaths\n" | |
9002 | "JavaScript Object Notation\n") | |
9003 | ||
8386ac43 | 9004 | DEFUN (show_bgp_instance_prefix_list, |
9005 | show_bgp_instance_prefix_list_cmd, | |
9006 | "show bgp " BGP_INSTANCE_CMD " prefix-list WORD", | |
50ef26d4 | 9007 | SHOW_STR |
9008 | BGP_STR | |
8386ac43 | 9009 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 9010 | "Display routes conforming to the prefix-list\n" |
9011 | "IPv6 prefix-list name\n") | |
9012 | { | |
9013 | return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, | |
9014 | bgp_show_type_prefix_list); | |
9015 | } | |
9016 | ||
8386ac43 | 9017 | ALIAS (show_bgp_instance_prefix_list, |
9018 | show_bgp_instance_ipv6_prefix_list_cmd, | |
9019 | "show bgp " BGP_INSTANCE_CMD " ipv6 prefix-list WORD", | |
50ef26d4 | 9020 | SHOW_STR |
9021 | BGP_STR | |
8386ac43 | 9022 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 9023 | "Address family\n" |
9024 | "Display routes conforming to the prefix-list\n" | |
9025 | "IPv6 prefix-list name\n") | |
9026 | ||
8386ac43 | 9027 | DEFUN (show_bgp_instance_filter_list, |
9028 | show_bgp_instance_filter_list_cmd, | |
9029 | "show bgp " BGP_INSTANCE_CMD " filter-list WORD", | |
50ef26d4 | 9030 | SHOW_STR |
9031 | BGP_STR | |
8386ac43 | 9032 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 9033 | "Display routes conforming to the filter-list\n" |
9034 | "Regular expression access list name\n") | |
9035 | { | |
9036 | return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, | |
9037 | bgp_show_type_filter_list); | |
9038 | } | |
9039 | ||
8386ac43 | 9040 | ALIAS (show_bgp_instance_filter_list, |
9041 | show_bgp_instance_ipv6_filter_list_cmd, | |
9042 | "show bgp " BGP_INSTANCE_CMD " ipv6 filter-list WORD", | |
50ef26d4 | 9043 | SHOW_STR |
9044 | BGP_STR | |
8386ac43 | 9045 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 9046 | "Address family\n" |
9047 | "Display routes conforming to the filter-list\n" | |
9048 | "Regular expression access list name\n") | |
9049 | ||
8386ac43 | 9050 | DEFUN (show_bgp_instance_route_map, |
9051 | show_bgp_instance_route_map_cmd, | |
9052 | "show bgp " BGP_INSTANCE_CMD " route-map WORD", | |
50ef26d4 | 9053 | SHOW_STR |
9054 | BGP_STR | |
8386ac43 | 9055 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 9056 | "Display routes matching the route-map\n" |
9057 | "A route-map to match on\n") | |
9058 | { | |
9059 | return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, | |
9060 | bgp_show_type_route_map); | |
9061 | } | |
9062 | ||
8386ac43 | 9063 | ALIAS (show_bgp_instance_route_map, |
9064 | show_bgp_instance_ipv6_route_map_cmd, | |
9065 | "show bgp " BGP_INSTANCE_CMD " ipv6 route-map WORD", | |
50ef26d4 | 9066 | SHOW_STR |
9067 | BGP_STR | |
8386ac43 | 9068 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 9069 | "Address family\n" |
9070 | "Display routes matching the route-map\n" | |
9071 | "A route-map to match on\n") | |
9072 | ||
8386ac43 | 9073 | DEFUN (show_bgp_instance_community_list, |
9074 | show_bgp_instance_community_list_cmd, | |
9075 | "show bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)", | |
50ef26d4 | 9076 | SHOW_STR |
9077 | BGP_STR | |
8386ac43 | 9078 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 9079 | "Display routes matching the community-list\n" |
9080 | "community-list number\n" | |
9081 | "community-list name\n") | |
9082 | { | |
9083 | return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP6, SAFI_UNICAST); | |
9084 | } | |
9085 | ||
8386ac43 | 9086 | ALIAS (show_bgp_instance_community_list, |
9087 | show_bgp_instance_ipv6_community_list_cmd, | |
9088 | "show bgp " BGP_INSTANCE_CMD " ipv6 community-list (<1-500>|WORD)", | |
50ef26d4 | 9089 | SHOW_STR |
9090 | BGP_STR | |
8386ac43 | 9091 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 9092 | "Address family\n" |
9093 | "Display routes matching the community-list\n" | |
9094 | "community-list number\n" | |
9095 | "community-list name\n") | |
9096 | ||
8386ac43 | 9097 | DEFUN (show_bgp_instance_prefix_longer, |
9098 | show_bgp_instance_prefix_longer_cmd, | |
9099 | "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M longer-prefixes", | |
50ef26d4 | 9100 | SHOW_STR |
9101 | BGP_STR | |
8386ac43 | 9102 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 9103 | "IPv6 prefix <network>/<length>\n" |
9104 | "Display route and more specific routes\n") | |
9105 | { | |
9106 | return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, | |
9107 | bgp_show_type_prefix_longer); | |
9108 | } | |
9109 | ||
8386ac43 | 9110 | ALIAS (show_bgp_instance_prefix_longer, |
9111 | show_bgp_instance_ipv6_prefix_longer_cmd, | |
9112 | "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M longer-prefixes", | |
50ef26d4 | 9113 | SHOW_STR |
9114 | BGP_STR | |
8386ac43 | 9115 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 9116 | "Address family\n" |
9117 | "IPv6 prefix <network>/<length>\n" | |
9118 | "Display route and more specific routes\n") | |
9119 | ||
718e3744 | 9120 | /* old command */ |
9121 | DEFUN (show_ipv6_mbgp, | |
9122 | show_ipv6_mbgp_cmd, | |
b05a1c8b | 9123 | "show ipv6 mbgp {json}", |
718e3744 | 9124 | SHOW_STR |
9125 | IP_STR | |
b05a1c8b DS |
9126 | MBGP_STR |
9127 | "JavaScript Object Notation\n") | |
718e3744 | 9128 | { |
47e9b292 | 9129 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
5a646650 | 9130 | return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal, |
db7c8528 | 9131 | NULL, use_json(argc, argv)); |
718e3744 | 9132 | } |
9133 | ||
9134 | /* old command */ | |
9135 | DEFUN (show_ipv6_mbgp_route, | |
9136 | show_ipv6_mbgp_route_cmd, | |
b05a1c8b | 9137 | "show ipv6 mbgp X:X::X:X {json}", |
718e3744 | 9138 | SHOW_STR |
9139 | IP_STR | |
9140 | MBGP_STR | |
b05a1c8b DS |
9141 | "Network in the MBGP routing table to display\n" |
9142 | "JavaScript Object Notation\n") | |
718e3744 | 9143 | { |
47e9b292 | 9144 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
db7c8528 | 9145 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 9146 | } |
9147 | ||
9148 | /* old command */ | |
9149 | DEFUN (show_ipv6_mbgp_prefix, | |
9150 | show_ipv6_mbgp_prefix_cmd, | |
b05a1c8b | 9151 | "show ipv6 mbgp X:X::X:X/M {json}", |
718e3744 | 9152 | SHOW_STR |
9153 | IP_STR | |
9154 | MBGP_STR | |
b05a1c8b DS |
9155 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n" |
9156 | "JavaScript Object Notation\n") | |
718e3744 | 9157 | { |
47e9b292 | 9158 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
db7c8528 | 9159 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 9160 | } |
9161 | #endif | |
6b0655a2 | 9162 | |
718e3744 | 9163 | |
94f2b392 | 9164 | static int |
fd79ac91 | 9165 | bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi, |
718e3744 | 9166 | safi_t safi, enum bgp_show_type type) |
9167 | { | |
9168 | int i; | |
9169 | struct buffer *b; | |
9170 | char *regstr; | |
9171 | int first; | |
9172 | regex_t *regex; | |
5a646650 | 9173 | int rc; |
718e3744 | 9174 | |
9175 | first = 0; | |
9176 | b = buffer_new (1024); | |
9177 | for (i = 0; i < argc; i++) | |
9178 | { | |
9179 | if (first) | |
9180 | buffer_putc (b, ' '); | |
9181 | else | |
9182 | { | |
9183 | if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0)) | |
9184 | continue; | |
9185 | first = 1; | |
9186 | } | |
9187 | ||
9188 | buffer_putstr (b, argv[i]); | |
9189 | } | |
9190 | buffer_putc (b, '\0'); | |
9191 | ||
9192 | regstr = buffer_getstr (b); | |
9193 | buffer_free (b); | |
9194 | ||
9195 | regex = bgp_regcomp (regstr); | |
3b8b1855 | 9196 | XFREE(MTYPE_TMP, regstr); |
718e3744 | 9197 | if (! regex) |
9198 | { | |
9199 | vty_out (vty, "Can't compile regexp %s%s", argv[0], | |
9200 | VTY_NEWLINE); | |
9201 | return CMD_WARNING; | |
9202 | } | |
9203 | ||
b05a1c8b | 9204 | rc = bgp_show (vty, NULL, afi, safi, type, regex, 0); |
5a646650 | 9205 | bgp_regex_free (regex); |
9206 | return rc; | |
718e3744 | 9207 | } |
9208 | ||
9209 | DEFUN (show_ip_bgp_regexp, | |
9210 | show_ip_bgp_regexp_cmd, | |
9211 | "show ip bgp regexp .LINE", | |
9212 | SHOW_STR | |
9213 | IP_STR | |
9214 | BGP_STR | |
9215 | "Display routes matching the AS path regular expression\n" | |
9216 | "A regular-expression to match the BGP AS paths\n") | |
9217 | { | |
9218 | return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST, | |
9219 | bgp_show_type_regexp); | |
9220 | } | |
9221 | ||
9222 | DEFUN (show_ip_bgp_flap_regexp, | |
9223 | show_ip_bgp_flap_regexp_cmd, | |
9224 | "show ip bgp flap-statistics regexp .LINE", | |
9225 | SHOW_STR | |
9226 | IP_STR | |
9227 | BGP_STR | |
9228 | "Display flap statistics of routes\n" | |
9229 | "Display routes matching the AS path regular expression\n" | |
9230 | "A regular-expression to match the BGP AS paths\n") | |
9231 | { | |
9232 | return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST, | |
9233 | bgp_show_type_flap_regexp); | |
9234 | } | |
9235 | ||
81304aaf B |
9236 | ALIAS (show_ip_bgp_flap_regexp, |
9237 | show_ip_bgp_damp_flap_regexp_cmd, | |
9238 | "show ip bgp dampening flap-statistics regexp .LINE", | |
9239 | SHOW_STR | |
9240 | IP_STR | |
9241 | BGP_STR | |
9242 | "Display detailed information about dampening\n" | |
9243 | "Display flap statistics of routes\n" | |
9244 | "Display routes matching the AS path regular expression\n" | |
9245 | "A regular-expression to match the BGP AS paths\n") | |
9246 | ||
718e3744 | 9247 | DEFUN (show_ip_bgp_ipv4_regexp, |
9248 | show_ip_bgp_ipv4_regexp_cmd, | |
d02fbbdb | 9249 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" regexp .LINE", |
718e3744 | 9250 | SHOW_STR |
9251 | IP_STR | |
9252 | BGP_STR | |
9253 | "Address family\n" | |
d02fbbdb | 9254 | BGP_SAFI_HELP_STR |
718e3744 | 9255 | "Display routes matching the AS path regular expression\n" |
9256 | "A regular-expression to match the BGP AS paths\n") | |
9257 | { | |
d02fbbdb LB |
9258 | safi_t safi; |
9259 | safi = bgp_vty_safi_from_arg(argv[0]); | |
9260 | return bgp_show_regexp (vty, argc, argv, AFI_IP, safi, | |
9261 | bgp_show_type_regexp); | |
718e3744 | 9262 | } |
9263 | ||
9264 | #ifdef HAVE_IPV6 | |
9265 | DEFUN (show_bgp_regexp, | |
9266 | show_bgp_regexp_cmd, | |
9267 | "show bgp regexp .LINE", | |
9268 | SHOW_STR | |
9269 | BGP_STR | |
9270 | "Display routes matching the AS path regular expression\n" | |
9271 | "A regular-expression to match the BGP AS paths\n") | |
9272 | { | |
9273 | return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST, | |
9274 | bgp_show_type_regexp); | |
9275 | } | |
9276 | ||
9277 | ALIAS (show_bgp_regexp, | |
9278 | show_bgp_ipv6_regexp_cmd, | |
9279 | "show bgp ipv6 regexp .LINE", | |
9280 | SHOW_STR | |
9281 | BGP_STR | |
9282 | "Address family\n" | |
9283 | "Display routes matching the AS path regular expression\n" | |
9284 | "A regular-expression to match the BGP AS paths\n") | |
9285 | ||
9286 | /* old command */ | |
9287 | DEFUN (show_ipv6_bgp_regexp, | |
9288 | show_ipv6_bgp_regexp_cmd, | |
9289 | "show ipv6 bgp regexp .LINE", | |
9290 | SHOW_STR | |
9291 | IP_STR | |
9292 | BGP_STR | |
9293 | "Display routes matching the AS path regular expression\n" | |
9294 | "A regular-expression to match the BGP AS paths\n") | |
9295 | { | |
47e9b292 | 9296 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 9297 | return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST, |
9298 | bgp_show_type_regexp); | |
9299 | } | |
9300 | ||
9301 | /* old command */ | |
9302 | DEFUN (show_ipv6_mbgp_regexp, | |
9303 | show_ipv6_mbgp_regexp_cmd, | |
9304 | "show ipv6 mbgp regexp .LINE", | |
9305 | SHOW_STR | |
9306 | IP_STR | |
9307 | BGP_STR | |
9308 | "Display routes matching the AS path regular expression\n" | |
9309 | "A regular-expression to match the MBGP AS paths\n") | |
9310 | { | |
47e9b292 | 9311 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 9312 | return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST, |
9313 | bgp_show_type_regexp); | |
9314 | } | |
9315 | #endif /* HAVE_IPV6 */ | |
6b0655a2 | 9316 | |
94f2b392 | 9317 | static int |
50ef26d4 | 9318 | bgp_show_prefix_list (struct vty *vty, const char *name, |
9319 | const char *prefix_list_str, afi_t afi, | |
718e3744 | 9320 | safi_t safi, enum bgp_show_type type) |
9321 | { | |
9322 | struct prefix_list *plist; | |
50ef26d4 | 9323 | struct bgp *bgp = NULL; |
9324 | ||
9325 | if (name && !(bgp = bgp_lookup_by_name(name))) | |
9326 | { | |
9327 | vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE); | |
9328 | return CMD_WARNING; | |
9329 | } | |
718e3744 | 9330 | |
9331 | plist = prefix_list_lookup (afi, prefix_list_str); | |
9332 | if (plist == NULL) | |
9333 | { | |
9334 | vty_out (vty, "%% %s is not a valid prefix-list name%s", | |
9335 | prefix_list_str, VTY_NEWLINE); | |
9336 | return CMD_WARNING; | |
9337 | } | |
9338 | ||
50ef26d4 | 9339 | return bgp_show (vty, bgp, afi, safi, type, plist, 0); |
718e3744 | 9340 | } |
9341 | ||
9342 | DEFUN (show_ip_bgp_prefix_list, | |
9343 | show_ip_bgp_prefix_list_cmd, | |
9344 | "show ip bgp prefix-list WORD", | |
9345 | SHOW_STR | |
9346 | IP_STR | |
9347 | BGP_STR | |
9348 | "Display routes conforming to the prefix-list\n" | |
9349 | "IP prefix-list name\n") | |
9350 | { | |
50ef26d4 | 9351 | return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, |
9352 | bgp_show_type_prefix_list); | |
9353 | } | |
9354 | ||
8386ac43 | 9355 | DEFUN (show_ip_bgp_instance_prefix_list, |
9356 | show_ip_bgp_instance_prefix_list_cmd, | |
9357 | "show ip bgp " BGP_INSTANCE_CMD " prefix-list WORD", | |
50ef26d4 | 9358 | SHOW_STR |
9359 | IP_STR | |
9360 | BGP_STR | |
8386ac43 | 9361 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 9362 | "Display routes conforming to the prefix-list\n" |
9363 | "IP prefix-list name\n") | |
9364 | { | |
9365 | return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, | |
718e3744 | 9366 | bgp_show_type_prefix_list); |
9367 | } | |
9368 | ||
9369 | DEFUN (show_ip_bgp_flap_prefix_list, | |
9370 | show_ip_bgp_flap_prefix_list_cmd, | |
9371 | "show ip bgp flap-statistics prefix-list WORD", | |
9372 | SHOW_STR | |
9373 | IP_STR | |
9374 | BGP_STR | |
9375 | "Display flap statistics of routes\n" | |
9376 | "Display routes conforming to the prefix-list\n" | |
9377 | "IP prefix-list name\n") | |
9378 | { | |
50ef26d4 | 9379 | return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, |
718e3744 | 9380 | bgp_show_type_flap_prefix_list); |
9381 | } | |
9382 | ||
81304aaf B |
9383 | ALIAS (show_ip_bgp_flap_prefix_list, |
9384 | show_ip_bgp_damp_flap_prefix_list_cmd, | |
9385 | "show ip bgp dampening flap-statistics prefix-list WORD", | |
9386 | SHOW_STR | |
9387 | IP_STR | |
9388 | BGP_STR | |
9389 | "Display detailed information about dampening\n" | |
9390 | "Display flap statistics of routes\n" | |
9391 | "Display routes conforming to the prefix-list\n" | |
9392 | "IP prefix-list name\n") | |
9393 | ||
718e3744 | 9394 | DEFUN (show_ip_bgp_ipv4_prefix_list, |
9395 | show_ip_bgp_ipv4_prefix_list_cmd, | |
d02fbbdb | 9396 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" prefix-list WORD", |
718e3744 | 9397 | SHOW_STR |
9398 | IP_STR | |
9399 | BGP_STR | |
9400 | "Address family\n" | |
d02fbbdb | 9401 | BGP_SAFI_HELP_STR |
718e3744 | 9402 | "Display routes conforming to the prefix-list\n" |
9403 | "IP prefix-list name\n") | |
9404 | { | |
d02fbbdb LB |
9405 | safi_t safi; |
9406 | safi = bgp_vty_safi_from_arg(argv[0]); | |
9407 | return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, safi, | |
9408 | bgp_show_type_prefix_list); | |
718e3744 | 9409 | } |
9410 | ||
9411 | #ifdef HAVE_IPV6 | |
9412 | DEFUN (show_bgp_prefix_list, | |
9413 | show_bgp_prefix_list_cmd, | |
9414 | "show bgp prefix-list WORD", | |
9415 | SHOW_STR | |
9416 | BGP_STR | |
9417 | "Display routes conforming to the prefix-list\n" | |
9418 | "IPv6 prefix-list name\n") | |
9419 | { | |
50ef26d4 | 9420 | return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, |
718e3744 | 9421 | bgp_show_type_prefix_list); |
9422 | } | |
9423 | ||
9424 | ALIAS (show_bgp_prefix_list, | |
9425 | show_bgp_ipv6_prefix_list_cmd, | |
9426 | "show bgp ipv6 prefix-list WORD", | |
9427 | SHOW_STR | |
9428 | BGP_STR | |
9429 | "Address family\n" | |
9430 | "Display routes conforming to the prefix-list\n" | |
9431 | "IPv6 prefix-list name\n") | |
9432 | ||
9433 | /* old command */ | |
9434 | DEFUN (show_ipv6_bgp_prefix_list, | |
9435 | show_ipv6_bgp_prefix_list_cmd, | |
9436 | "show ipv6 bgp prefix-list WORD", | |
9437 | SHOW_STR | |
9438 | IPV6_STR | |
9439 | BGP_STR | |
9440 | "Display routes matching the prefix-list\n" | |
9441 | "IPv6 prefix-list name\n") | |
9442 | { | |
47e9b292 | 9443 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
50ef26d4 | 9444 | return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, |
718e3744 | 9445 | bgp_show_type_prefix_list); |
9446 | } | |
9447 | ||
9448 | /* old command */ | |
9449 | DEFUN (show_ipv6_mbgp_prefix_list, | |
9450 | show_ipv6_mbgp_prefix_list_cmd, | |
9451 | "show ipv6 mbgp prefix-list WORD", | |
9452 | SHOW_STR | |
9453 | IPV6_STR | |
9454 | MBGP_STR | |
9455 | "Display routes matching the prefix-list\n" | |
9456 | "IPv6 prefix-list name\n") | |
9457 | { | |
47e9b292 | 9458 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
50ef26d4 | 9459 | return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, |
718e3744 | 9460 | bgp_show_type_prefix_list); |
9461 | } | |
9462 | #endif /* HAVE_IPV6 */ | |
6b0655a2 | 9463 | |
94f2b392 | 9464 | static int |
50ef26d4 | 9465 | bgp_show_filter_list (struct vty *vty, const char *name, |
9466 | const char *filter, afi_t afi, | |
718e3744 | 9467 | safi_t safi, enum bgp_show_type type) |
9468 | { | |
9469 | struct as_list *as_list; | |
50ef26d4 | 9470 | struct bgp *bgp = NULL; |
9471 | ||
9472 | if (name && !(bgp = bgp_lookup_by_name(name))) | |
9473 | { | |
9474 | vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE); | |
9475 | return CMD_WARNING; | |
9476 | } | |
718e3744 | 9477 | |
9478 | as_list = as_list_lookup (filter); | |
9479 | if (as_list == NULL) | |
9480 | { | |
9481 | vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE); | |
9482 | return CMD_WARNING; | |
9483 | } | |
9484 | ||
50ef26d4 | 9485 | return bgp_show (vty, bgp, afi, safi, type, as_list, 0); |
718e3744 | 9486 | } |
9487 | ||
9488 | DEFUN (show_ip_bgp_filter_list, | |
9489 | show_ip_bgp_filter_list_cmd, | |
9490 | "show ip bgp filter-list WORD", | |
9491 | SHOW_STR | |
9492 | IP_STR | |
9493 | BGP_STR | |
9494 | "Display routes conforming to the filter-list\n" | |
9495 | "Regular expression access list name\n") | |
9496 | { | |
50ef26d4 | 9497 | return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, |
9498 | bgp_show_type_filter_list); | |
9499 | } | |
9500 | ||
8386ac43 | 9501 | DEFUN (show_ip_bgp_instance_filter_list, |
9502 | show_ip_bgp_instance_filter_list_cmd, | |
9503 | "show ip bgp " BGP_INSTANCE_CMD " filter-list WORD", | |
50ef26d4 | 9504 | SHOW_STR |
9505 | IP_STR | |
9506 | BGP_STR | |
8386ac43 | 9507 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 9508 | "Display routes conforming to the filter-list\n" |
9509 | "Regular expression access list name\n") | |
9510 | { | |
9511 | return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, | |
718e3744 | 9512 | bgp_show_type_filter_list); |
9513 | } | |
9514 | ||
9515 | DEFUN (show_ip_bgp_flap_filter_list, | |
9516 | show_ip_bgp_flap_filter_list_cmd, | |
9517 | "show ip bgp flap-statistics filter-list WORD", | |
9518 | SHOW_STR | |
9519 | IP_STR | |
9520 | BGP_STR | |
9521 | "Display flap statistics of routes\n" | |
9522 | "Display routes conforming to the filter-list\n" | |
9523 | "Regular expression access list name\n") | |
9524 | { | |
50ef26d4 | 9525 | return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, |
718e3744 | 9526 | bgp_show_type_flap_filter_list); |
9527 | } | |
9528 | ||
81304aaf B |
9529 | ALIAS (show_ip_bgp_flap_filter_list, |
9530 | show_ip_bgp_damp_flap_filter_list_cmd, | |
9531 | "show ip bgp dampening flap-statistics filter-list WORD", | |
9532 | SHOW_STR | |
9533 | IP_STR | |
9534 | BGP_STR | |
9535 | "Display detailed information about dampening\n" | |
9536 | "Display flap statistics of routes\n" | |
9537 | "Display routes conforming to the filter-list\n" | |
9538 | "Regular expression access list name\n") | |
9539 | ||
718e3744 | 9540 | DEFUN (show_ip_bgp_ipv4_filter_list, |
9541 | show_ip_bgp_ipv4_filter_list_cmd, | |
d02fbbdb | 9542 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" filter-list WORD", |
718e3744 | 9543 | SHOW_STR |
9544 | IP_STR | |
9545 | BGP_STR | |
9546 | "Address family\n" | |
d02fbbdb | 9547 | BGP_SAFI_HELP_STR |
718e3744 | 9548 | "Display routes conforming to the filter-list\n" |
9549 | "Regular expression access list name\n") | |
9550 | { | |
d02fbbdb LB |
9551 | safi_t safi; |
9552 | safi = bgp_vty_safi_from_arg(argv[0]); | |
9553 | return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, safi, | |
9554 | bgp_show_type_filter_list); | |
718e3744 | 9555 | } |
9556 | ||
9557 | #ifdef HAVE_IPV6 | |
9558 | DEFUN (show_bgp_filter_list, | |
9559 | show_bgp_filter_list_cmd, | |
9560 | "show bgp filter-list WORD", | |
9561 | SHOW_STR | |
9562 | BGP_STR | |
9563 | "Display routes conforming to the filter-list\n" | |
9564 | "Regular expression access list name\n") | |
9565 | { | |
50ef26d4 | 9566 | return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, |
718e3744 | 9567 | bgp_show_type_filter_list); |
9568 | } | |
9569 | ||
9570 | ALIAS (show_bgp_filter_list, | |
9571 | show_bgp_ipv6_filter_list_cmd, | |
9572 | "show bgp ipv6 filter-list WORD", | |
9573 | SHOW_STR | |
9574 | BGP_STR | |
9575 | "Address family\n" | |
9576 | "Display routes conforming to the filter-list\n" | |
9577 | "Regular expression access list name\n") | |
9578 | ||
9579 | /* old command */ | |
9580 | DEFUN (show_ipv6_bgp_filter_list, | |
9581 | show_ipv6_bgp_filter_list_cmd, | |
9582 | "show ipv6 bgp filter-list WORD", | |
9583 | SHOW_STR | |
9584 | IPV6_STR | |
9585 | BGP_STR | |
9586 | "Display routes conforming to the filter-list\n" | |
9587 | "Regular expression access list name\n") | |
9588 | { | |
47e9b292 | 9589 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
50ef26d4 | 9590 | return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, |
718e3744 | 9591 | bgp_show_type_filter_list); |
9592 | } | |
9593 | ||
9594 | /* old command */ | |
9595 | DEFUN (show_ipv6_mbgp_filter_list, | |
9596 | show_ipv6_mbgp_filter_list_cmd, | |
9597 | "show ipv6 mbgp filter-list WORD", | |
9598 | SHOW_STR | |
9599 | IPV6_STR | |
9600 | MBGP_STR | |
9601 | "Display routes conforming to the filter-list\n" | |
9602 | "Regular expression access list name\n") | |
9603 | { | |
47e9b292 | 9604 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
50ef26d4 | 9605 | return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, |
718e3744 | 9606 | bgp_show_type_filter_list); |
9607 | } | |
9608 | #endif /* HAVE_IPV6 */ | |
6b0655a2 | 9609 | |
81304aaf B |
9610 | DEFUN (show_ip_bgp_dampening_info, |
9611 | show_ip_bgp_dampening_params_cmd, | |
9612 | "show ip bgp dampening parameters", | |
9613 | SHOW_STR | |
9614 | IP_STR | |
9615 | BGP_STR | |
9616 | "Display detailed information about dampening\n" | |
9617 | "Display detail of configured dampening parameters\n") | |
9618 | { | |
9619 | return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST); | |
9620 | } | |
9621 | ||
58a90275 B |
9622 | |
9623 | DEFUN (show_ip_bgp_ipv4_dampening_parameters, | |
9624 | show_ip_bgp_ipv4_dampening_parameters_cmd, | |
d02fbbdb | 9625 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" dampening parameters", |
58a90275 B |
9626 | SHOW_STR |
9627 | IP_STR | |
9628 | BGP_STR | |
9629 | "Address family\n" | |
d02fbbdb | 9630 | BGP_SAFI_HELP_STR |
58a90275 B |
9631 | "Display detailed information about dampening\n" |
9632 | "Display detail of configured dampening parameters\n") | |
9633 | { | |
d02fbbdb LB |
9634 | safi_t safi; |
9635 | safi = bgp_vty_safi_from_arg(argv[0]); | |
9636 | return bgp_show_dampening_parameters (vty, AFI_IP, safi); | |
58a90275 B |
9637 | } |
9638 | ||
9639 | ||
9640 | DEFUN (show_ip_bgp_ipv4_dampening_flap_stats, | |
9641 | show_ip_bgp_ipv4_dampening_flap_stats_cmd, | |
d02fbbdb | 9642 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" dampening flap-statistics", |
58a90275 B |
9643 | SHOW_STR |
9644 | IP_STR | |
9645 | BGP_STR | |
9646 | "Address family\n" | |
d02fbbdb | 9647 | BGP_SAFI_HELP_STR |
58a90275 B |
9648 | "Display detailed information about dampening\n" |
9649 | "Display flap statistics of routes\n") | |
9650 | { | |
d02fbbdb LB |
9651 | safi_t safi; |
9652 | safi = bgp_vty_safi_from_arg(argv[0]); | |
9653 | return bgp_show (vty, NULL, AFI_IP, safi, | |
58a90275 | 9654 | bgp_show_type_flap_statistics, NULL, 0); |
58a90275 B |
9655 | } |
9656 | ||
9657 | DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths, | |
9658 | show_ip_bgp_ipv4_dampening_dampd_paths_cmd, | |
d02fbbdb | 9659 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" dampening dampened-paths", |
58a90275 B |
9660 | SHOW_STR |
9661 | IP_STR | |
9662 | BGP_STR | |
9663 | "Address family\n" | |
d02fbbdb | 9664 | BGP_SAFI_HELP_STR |
58a90275 B |
9665 | "Display detailed information about dampening\n" |
9666 | "Display paths suppressed due to dampening\n") | |
9667 | { | |
d02fbbdb LB |
9668 | safi_t safi; |
9669 | safi = bgp_vty_safi_from_arg(argv[0]); | |
9670 | return bgp_show (vty, NULL, AFI_IP, safi, | |
58a90275 | 9671 | bgp_show_type_dampend_paths, NULL, 0); |
58a90275 B |
9672 | } |
9673 | ||
94f2b392 | 9674 | static int |
50ef26d4 | 9675 | bgp_show_route_map (struct vty *vty, const char *name, |
9676 | const char *rmap_str, afi_t afi, | |
718e3744 | 9677 | safi_t safi, enum bgp_show_type type) |
9678 | { | |
9679 | struct route_map *rmap; | |
50ef26d4 | 9680 | struct bgp *bgp = NULL; |
9681 | ||
9682 | if (name && !(bgp = bgp_lookup_by_name(name))) | |
9683 | { | |
9684 | vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE); | |
9685 | return CMD_WARNING; | |
9686 | } | |
718e3744 | 9687 | |
9688 | rmap = route_map_lookup_by_name (rmap_str); | |
9689 | if (! rmap) | |
9690 | { | |
9691 | vty_out (vty, "%% %s is not a valid route-map name%s", | |
9692 | rmap_str, VTY_NEWLINE); | |
9693 | return CMD_WARNING; | |
9694 | } | |
9695 | ||
50ef26d4 | 9696 | return bgp_show (vty, bgp, afi, safi, type, rmap, 0); |
718e3744 | 9697 | } |
9698 | ||
9699 | DEFUN (show_ip_bgp_route_map, | |
9700 | show_ip_bgp_route_map_cmd, | |
9701 | "show ip bgp route-map WORD", | |
9702 | SHOW_STR | |
9703 | IP_STR | |
9704 | BGP_STR | |
9705 | "Display routes matching the route-map\n" | |
9706 | "A route-map to match on\n") | |
9707 | { | |
50ef26d4 | 9708 | return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, |
9709 | bgp_show_type_route_map); | |
9710 | } | |
9711 | ||
8386ac43 | 9712 | DEFUN (show_ip_bgp_instance_route_map, |
9713 | show_ip_bgp_instance_route_map_cmd, | |
9714 | "show ip bgp " BGP_INSTANCE_CMD " route-map WORD", | |
50ef26d4 | 9715 | SHOW_STR |
9716 | IP_STR | |
9717 | BGP_STR | |
8386ac43 | 9718 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 9719 | "Display routes matching the route-map\n" |
9720 | "A route-map to match on\n") | |
9721 | { | |
9722 | return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, | |
718e3744 | 9723 | bgp_show_type_route_map); |
9724 | } | |
9725 | ||
9726 | DEFUN (show_ip_bgp_flap_route_map, | |
9727 | show_ip_bgp_flap_route_map_cmd, | |
9728 | "show ip bgp flap-statistics route-map WORD", | |
9729 | SHOW_STR | |
9730 | IP_STR | |
9731 | BGP_STR | |
9732 | "Display flap statistics of routes\n" | |
9733 | "Display routes matching the route-map\n" | |
9734 | "A route-map to match on\n") | |
9735 | { | |
50ef26d4 | 9736 | return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, |
718e3744 | 9737 | bgp_show_type_flap_route_map); |
9738 | } | |
9739 | ||
81304aaf B |
9740 | ALIAS (show_ip_bgp_flap_route_map, |
9741 | show_ip_bgp_damp_flap_route_map_cmd, | |
9742 | "show ip bgp dampening flap-statistics route-map WORD", | |
9743 | SHOW_STR | |
9744 | IP_STR | |
9745 | BGP_STR | |
9746 | "Display detailed information about dampening\n" | |
9747 | "Display flap statistics of routes\n" | |
9748 | "Display routes matching the route-map\n" | |
9749 | "A route-map to match on\n") | |
9750 | ||
718e3744 | 9751 | DEFUN (show_ip_bgp_ipv4_route_map, |
9752 | show_ip_bgp_ipv4_route_map_cmd, | |
d02fbbdb | 9753 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" route-map WORD", |
718e3744 | 9754 | SHOW_STR |
9755 | IP_STR | |
9756 | BGP_STR | |
9757 | "Address family\n" | |
d02fbbdb | 9758 | BGP_SAFI_HELP_STR |
718e3744 | 9759 | "Display routes matching the route-map\n" |
9760 | "A route-map to match on\n") | |
9761 | { | |
d02fbbdb LB |
9762 | safi_t safi; |
9763 | safi = bgp_vty_safi_from_arg(argv[0]); | |
9764 | return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, safi, | |
9765 | bgp_show_type_route_map); | |
718e3744 | 9766 | } |
9767 | ||
9768 | DEFUN (show_bgp_route_map, | |
9769 | show_bgp_route_map_cmd, | |
9770 | "show bgp route-map WORD", | |
9771 | SHOW_STR | |
9772 | BGP_STR | |
9773 | "Display routes matching the route-map\n" | |
9774 | "A route-map to match on\n") | |
9775 | { | |
50ef26d4 | 9776 | return bgp_show_route_map (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, |
718e3744 | 9777 | bgp_show_type_route_map); |
9778 | } | |
9779 | ||
9780 | ALIAS (show_bgp_route_map, | |
9781 | show_bgp_ipv6_route_map_cmd, | |
9782 | "show bgp ipv6 route-map WORD", | |
9783 | SHOW_STR | |
9784 | BGP_STR | |
9785 | "Address family\n" | |
9786 | "Display routes matching the route-map\n" | |
9787 | "A route-map to match on\n") | |
6b0655a2 | 9788 | |
718e3744 | 9789 | DEFUN (show_ip_bgp_cidr_only, |
9790 | show_ip_bgp_cidr_only_cmd, | |
9791 | "show ip bgp cidr-only", | |
9792 | SHOW_STR | |
9793 | IP_STR | |
9794 | BGP_STR | |
9795 | "Display only routes with non-natural netmasks\n") | |
9796 | { | |
9797 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, | |
b05a1c8b | 9798 | bgp_show_type_cidr_only, NULL, 0); |
718e3744 | 9799 | } |
9800 | ||
9801 | DEFUN (show_ip_bgp_flap_cidr_only, | |
9802 | show_ip_bgp_flap_cidr_only_cmd, | |
9803 | "show ip bgp flap-statistics cidr-only", | |
9804 | SHOW_STR | |
9805 | IP_STR | |
9806 | BGP_STR | |
9807 | "Display flap statistics of routes\n" | |
9808 | "Display only routes with non-natural netmasks\n") | |
9809 | { | |
9810 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, | |
b05a1c8b | 9811 | bgp_show_type_flap_cidr_only, NULL, 0); |
718e3744 | 9812 | } |
9813 | ||
81304aaf B |
9814 | ALIAS (show_ip_bgp_flap_cidr_only, |
9815 | show_ip_bgp_damp_flap_cidr_only_cmd, | |
9816 | "show ip bgp dampening flap-statistics cidr-only", | |
9817 | SHOW_STR | |
9818 | IP_STR | |
9819 | BGP_STR | |
9820 | "Display detailed information about dampening\n" | |
9821 | "Display flap statistics of routes\n" | |
9822 | "Display only routes with non-natural netmasks\n") | |
9823 | ||
718e3744 | 9824 | DEFUN (show_ip_bgp_ipv4_cidr_only, |
9825 | show_ip_bgp_ipv4_cidr_only_cmd, | |
d02fbbdb | 9826 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" cidr-only", |
718e3744 | 9827 | SHOW_STR |
9828 | IP_STR | |
9829 | BGP_STR | |
9830 | "Address family\n" | |
d02fbbdb | 9831 | BGP_SAFI_HELP_STR |
718e3744 | 9832 | "Display only routes with non-natural netmasks\n") |
9833 | { | |
d02fbbdb LB |
9834 | safi_t safi; |
9835 | safi = bgp_vty_safi_from_arg(argv[0]); | |
9836 | return bgp_show (vty, NULL, AFI_IP, safi, | |
9837 | bgp_show_type_cidr_only, NULL, 0); | |
718e3744 | 9838 | } |
6b0655a2 | 9839 | |
718e3744 | 9840 | DEFUN (show_ip_bgp_community_all, |
9841 | show_ip_bgp_community_all_cmd, | |
9842 | "show ip bgp community", | |
9843 | SHOW_STR | |
9844 | IP_STR | |
9845 | BGP_STR | |
9846 | "Display routes matching the communities\n") | |
9847 | { | |
9848 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, | |
b05a1c8b | 9849 | bgp_show_type_community_all, NULL, 0); |
718e3744 | 9850 | } |
9851 | ||
9852 | DEFUN (show_ip_bgp_ipv4_community_all, | |
9853 | show_ip_bgp_ipv4_community_all_cmd, | |
d02fbbdb | 9854 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community", |
718e3744 | 9855 | SHOW_STR |
9856 | IP_STR | |
9857 | BGP_STR | |
9858 | "Address family\n" | |
d02fbbdb | 9859 | BGP_SAFI_HELP_STR |
718e3744 | 9860 | "Display routes matching the communities\n") |
9861 | { | |
d02fbbdb LB |
9862 | safi_t safi; |
9863 | safi = bgp_vty_safi_from_arg(argv[0]); | |
9864 | return bgp_show (vty, NULL, AFI_IP, safi, | |
9865 | bgp_show_type_community_all, NULL, 0); | |
718e3744 | 9866 | } |
9867 | ||
9868 | #ifdef HAVE_IPV6 | |
9869 | DEFUN (show_bgp_community_all, | |
9870 | show_bgp_community_all_cmd, | |
9871 | "show bgp community", | |
9872 | SHOW_STR | |
9873 | BGP_STR | |
9874 | "Display routes matching the communities\n") | |
9875 | { | |
9876 | return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, | |
b05a1c8b | 9877 | bgp_show_type_community_all, NULL, 0); |
718e3744 | 9878 | } |
9879 | ||
9880 | ALIAS (show_bgp_community_all, | |
9881 | show_bgp_ipv6_community_all_cmd, | |
9882 | "show bgp ipv6 community", | |
9883 | SHOW_STR | |
9884 | BGP_STR | |
9885 | "Address family\n" | |
9886 | "Display routes matching the communities\n") | |
9887 | ||
9888 | /* old command */ | |
9889 | DEFUN (show_ipv6_bgp_community_all, | |
9890 | show_ipv6_bgp_community_all_cmd, | |
9891 | "show ipv6 bgp community", | |
9892 | SHOW_STR | |
9893 | IPV6_STR | |
9894 | BGP_STR | |
9895 | "Display routes matching the communities\n") | |
9896 | { | |
47e9b292 | 9897 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 9898 | return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, |
b05a1c8b | 9899 | bgp_show_type_community_all, NULL, 0); |
718e3744 | 9900 | } |
9901 | ||
9902 | /* old command */ | |
9903 | DEFUN (show_ipv6_mbgp_community_all, | |
9904 | show_ipv6_mbgp_community_all_cmd, | |
9905 | "show ipv6 mbgp community", | |
9906 | SHOW_STR | |
9907 | IPV6_STR | |
9908 | MBGP_STR | |
9909 | "Display routes matching the communities\n") | |
9910 | { | |
47e9b292 | 9911 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 9912 | return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, |
b05a1c8b | 9913 | bgp_show_type_community_all, NULL, 0); |
718e3744 | 9914 | } |
9915 | #endif /* HAVE_IPV6 */ | |
6b0655a2 | 9916 | |
94f2b392 | 9917 | static int |
95cbbd2a ML |
9918 | bgp_show_community (struct vty *vty, const char *view_name, int argc, |
9919 | const char **argv, int exact, afi_t afi, safi_t safi) | |
718e3744 | 9920 | { |
9921 | struct community *com; | |
9922 | struct buffer *b; | |
95cbbd2a | 9923 | struct bgp *bgp; |
718e3744 | 9924 | int i; |
9925 | char *str; | |
9926 | int first = 0; | |
9927 | ||
95cbbd2a ML |
9928 | /* BGP structure lookup */ |
9929 | if (view_name) | |
9930 | { | |
9931 | bgp = bgp_lookup_by_name (view_name); | |
9932 | if (bgp == NULL) | |
9933 | { | |
6aeb9e78 | 9934 | vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE); |
95cbbd2a ML |
9935 | return CMD_WARNING; |
9936 | } | |
9937 | } | |
9938 | else | |
9939 | { | |
9940 | bgp = bgp_get_default (); | |
9941 | if (bgp == NULL) | |
9942 | { | |
9943 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); | |
9944 | return CMD_WARNING; | |
9945 | } | |
9946 | } | |
9947 | ||
718e3744 | 9948 | b = buffer_new (1024); |
9949 | for (i = 0; i < argc; i++) | |
9950 | { | |
9951 | if (first) | |
9952 | buffer_putc (b, ' '); | |
9953 | else | |
9954 | { | |
9955 | if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0)) | |
9956 | continue; | |
9957 | first = 1; | |
9958 | } | |
9959 | ||
9960 | buffer_putstr (b, argv[i]); | |
9961 | } | |
9962 | buffer_putc (b, '\0'); | |
9963 | ||
9964 | str = buffer_getstr (b); | |
9965 | buffer_free (b); | |
9966 | ||
9967 | com = community_str2com (str); | |
3b8b1855 | 9968 | XFREE (MTYPE_TMP, str); |
718e3744 | 9969 | if (! com) |
9970 | { | |
9971 | vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE); | |
9972 | return CMD_WARNING; | |
9973 | } | |
9974 | ||
95cbbd2a | 9975 | return bgp_show (vty, bgp, afi, safi, |
5a646650 | 9976 | (exact ? bgp_show_type_community_exact : |
b05a1c8b | 9977 | bgp_show_type_community), com, 0); |
718e3744 | 9978 | } |
9979 | ||
9980 | DEFUN (show_ip_bgp_community, | |
9981 | show_ip_bgp_community_cmd, | |
9982 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)", | |
9983 | SHOW_STR | |
9984 | IP_STR | |
9985 | BGP_STR | |
9986 | "Display routes matching the communities\n" | |
859d388e | 9987 | COMMUNITY_AANN_STR |
718e3744 | 9988 | "Do not send outside local AS (well-known community)\n" |
9989 | "Do not advertise to any peer (well-known community)\n" | |
9990 | "Do not export to next AS (well-known community)\n") | |
9991 | { | |
95cbbd2a | 9992 | return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST); |
718e3744 | 9993 | } |
9994 | ||
9995 | ALIAS (show_ip_bgp_community, | |
9996 | show_ip_bgp_community2_cmd, | |
9997 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
9998 | SHOW_STR | |
9999 | IP_STR | |
10000 | BGP_STR | |
10001 | "Display routes matching the communities\n" | |
859d388e | 10002 | COMMUNITY_AANN_STR |
718e3744 | 10003 | "Do not send outside local AS (well-known community)\n" |
10004 | "Do not advertise to any peer (well-known community)\n" | |
10005 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10006 | COMMUNITY_AANN_STR |
718e3744 | 10007 | "Do not send outside local AS (well-known community)\n" |
10008 | "Do not advertise to any peer (well-known community)\n" | |
10009 | "Do not export to next AS (well-known community)\n") | |
10010 | ||
10011 | ALIAS (show_ip_bgp_community, | |
10012 | show_ip_bgp_community3_cmd, | |
10013 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
10014 | SHOW_STR | |
10015 | IP_STR | |
10016 | BGP_STR | |
10017 | "Display routes matching the communities\n" | |
859d388e | 10018 | COMMUNITY_AANN_STR |
718e3744 | 10019 | "Do not send outside local AS (well-known community)\n" |
10020 | "Do not advertise to any peer (well-known community)\n" | |
10021 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10022 | COMMUNITY_AANN_STR |
718e3744 | 10023 | "Do not send outside local AS (well-known community)\n" |
10024 | "Do not advertise to any peer (well-known community)\n" | |
10025 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10026 | COMMUNITY_AANN_STR |
718e3744 | 10027 | "Do not send outside local AS (well-known community)\n" |
10028 | "Do not advertise to any peer (well-known community)\n" | |
10029 | "Do not export to next AS (well-known community)\n") | |
10030 | ||
10031 | ALIAS (show_ip_bgp_community, | |
10032 | show_ip_bgp_community4_cmd, | |
10033 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
10034 | SHOW_STR | |
10035 | IP_STR | |
10036 | BGP_STR | |
10037 | "Display routes matching the communities\n" | |
859d388e | 10038 | COMMUNITY_AANN_STR |
718e3744 | 10039 | "Do not send outside local AS (well-known community)\n" |
10040 | "Do not advertise to any peer (well-known community)\n" | |
10041 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10042 | COMMUNITY_AANN_STR |
718e3744 | 10043 | "Do not send outside local AS (well-known community)\n" |
10044 | "Do not advertise to any peer (well-known community)\n" | |
10045 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10046 | COMMUNITY_AANN_STR |
718e3744 | 10047 | "Do not send outside local AS (well-known community)\n" |
10048 | "Do not advertise to any peer (well-known community)\n" | |
10049 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10050 | COMMUNITY_AANN_STR |
718e3744 | 10051 | "Do not send outside local AS (well-known community)\n" |
10052 | "Do not advertise to any peer (well-known community)\n" | |
10053 | "Do not export to next AS (well-known community)\n") | |
10054 | ||
10055 | DEFUN (show_ip_bgp_ipv4_community, | |
10056 | show_ip_bgp_ipv4_community_cmd, | |
d02fbbdb | 10057 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export)", |
718e3744 | 10058 | SHOW_STR |
10059 | IP_STR | |
10060 | BGP_STR | |
10061 | "Address family\n" | |
d02fbbdb | 10062 | BGP_SAFI_HELP_STR |
718e3744 | 10063 | "Display routes matching the communities\n" |
859d388e | 10064 | COMMUNITY_AANN_STR |
718e3744 | 10065 | "Do not send outside local AS (well-known community)\n" |
10066 | "Do not advertise to any peer (well-known community)\n" | |
10067 | "Do not export to next AS (well-known community)\n") | |
10068 | { | |
d02fbbdb LB |
10069 | safi_t safi; |
10070 | safi = bgp_vty_safi_from_arg(argv[0]); | |
10071 | return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, safi); | |
718e3744 | 10072 | } |
10073 | ||
10074 | ALIAS (show_ip_bgp_ipv4_community, | |
10075 | show_ip_bgp_ipv4_community2_cmd, | |
d02fbbdb | 10076 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
718e3744 | 10077 | SHOW_STR |
10078 | IP_STR | |
10079 | BGP_STR | |
10080 | "Address family\n" | |
d02fbbdb | 10081 | BGP_SAFI_HELP_STR |
718e3744 | 10082 | "Display routes matching the communities\n" |
859d388e | 10083 | COMMUNITY_AANN_STR |
718e3744 | 10084 | "Do not send outside local AS (well-known community)\n" |
10085 | "Do not advertise to any peer (well-known community)\n" | |
10086 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10087 | COMMUNITY_AANN_STR |
718e3744 | 10088 | "Do not send outside local AS (well-known community)\n" |
10089 | "Do not advertise to any peer (well-known community)\n" | |
10090 | "Do not export to next AS (well-known community)\n") | |
10091 | ||
10092 | ALIAS (show_ip_bgp_ipv4_community, | |
10093 | show_ip_bgp_ipv4_community3_cmd, | |
d02fbbdb | 10094 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
718e3744 | 10095 | SHOW_STR |
10096 | IP_STR | |
10097 | BGP_STR | |
10098 | "Address family\n" | |
d02fbbdb | 10099 | BGP_SAFI_HELP_STR |
718e3744 | 10100 | "Display routes matching the communities\n" |
859d388e | 10101 | COMMUNITY_AANN_STR |
718e3744 | 10102 | "Do not send outside local AS (well-known community)\n" |
10103 | "Do not advertise to any peer (well-known community)\n" | |
10104 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10105 | COMMUNITY_AANN_STR |
718e3744 | 10106 | "Do not send outside local AS (well-known community)\n" |
10107 | "Do not advertise to any peer (well-known community)\n" | |
10108 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10109 | COMMUNITY_AANN_STR |
718e3744 | 10110 | "Do not send outside local AS (well-known community)\n" |
10111 | "Do not advertise to any peer (well-known community)\n" | |
10112 | "Do not export to next AS (well-known community)\n") | |
10113 | ||
10114 | ALIAS (show_ip_bgp_ipv4_community, | |
10115 | show_ip_bgp_ipv4_community4_cmd, | |
d02fbbdb | 10116 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
718e3744 | 10117 | SHOW_STR |
10118 | IP_STR | |
10119 | BGP_STR | |
10120 | "Address family\n" | |
d02fbbdb | 10121 | BGP_SAFI_HELP_STR |
718e3744 | 10122 | "Display routes matching the communities\n" |
859d388e | 10123 | COMMUNITY_AANN_STR |
718e3744 | 10124 | "Do not send outside local AS (well-known community)\n" |
10125 | "Do not advertise to any peer (well-known community)\n" | |
10126 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10127 | COMMUNITY_AANN_STR |
718e3744 | 10128 | "Do not send outside local AS (well-known community)\n" |
10129 | "Do not advertise to any peer (well-known community)\n" | |
10130 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10131 | COMMUNITY_AANN_STR |
718e3744 | 10132 | "Do not send outside local AS (well-known community)\n" |
10133 | "Do not advertise to any peer (well-known community)\n" | |
10134 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10135 | COMMUNITY_AANN_STR |
718e3744 | 10136 | "Do not send outside local AS (well-known community)\n" |
10137 | "Do not advertise to any peer (well-known community)\n" | |
10138 | "Do not export to next AS (well-known community)\n") | |
10139 | ||
8386ac43 | 10140 | DEFUN (show_bgp_instance_afi_safi_community_all, |
10141 | show_bgp_instance_afi_safi_community_all_cmd, | |
d02fbbdb | 10142 | "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community", |
95cbbd2a ML |
10143 | SHOW_STR |
10144 | BGP_STR | |
8386ac43 | 10145 | BGP_INSTANCE_HELP_STR |
d02fbbdb | 10146 | BGP_AFI_SAFI_HELP_STR |
2b00515a | 10147 | "Display routes matching the communities\n") |
95cbbd2a ML |
10148 | { |
10149 | int afi; | |
10150 | int safi; | |
10151 | struct bgp *bgp; | |
10152 | ||
10153 | /* BGP structure lookup. */ | |
6aeb9e78 | 10154 | bgp = bgp_lookup_by_name (argv[1]); |
95cbbd2a ML |
10155 | if (bgp == NULL) |
10156 | { | |
6aeb9e78 | 10157 | vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE); |
95cbbd2a ML |
10158 | return CMD_WARNING; |
10159 | } | |
10160 | ||
d02fbbdb LB |
10161 | afi = bgp_vty_safi_from_arg(argv[2]); |
10162 | safi = bgp_vty_safi_from_arg(argv[3]); | |
b05a1c8b | 10163 | return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0); |
95cbbd2a ML |
10164 | } |
10165 | ||
8386ac43 | 10166 | DEFUN (show_bgp_instance_afi_safi_community, |
10167 | show_bgp_instance_afi_safi_community_cmd, | |
d02fbbdb | 10168 | "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export)", |
95cbbd2a ML |
10169 | SHOW_STR |
10170 | BGP_STR | |
8386ac43 | 10171 | BGP_INSTANCE_HELP_STR |
95cbbd2a | 10172 | "Address family\n" |
95cbbd2a | 10173 | "Address family\n" |
95cbbd2a ML |
10174 | "Address family modifier\n" |
10175 | "Address family modifier\n" | |
10176 | "Display routes matching the communities\n" | |
859d388e | 10177 | COMMUNITY_AANN_STR |
95cbbd2a ML |
10178 | "Do not send outside local AS (well-known community)\n" |
10179 | "Do not advertise to any peer (well-known community)\n" | |
10180 | "Do not export to next AS (well-known community)\n") | |
10181 | { | |
10182 | int afi; | |
10183 | int safi; | |
10184 | ||
d02fbbdb LB |
10185 | afi = bgp_vty_safi_from_arg(argv[2]); |
10186 | safi = bgp_vty_safi_from_arg(argv[3]); | |
6aeb9e78 | 10187 | return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi); |
95cbbd2a ML |
10188 | } |
10189 | ||
8386ac43 | 10190 | ALIAS (show_bgp_instance_afi_safi_community, |
10191 | show_bgp_instance_afi_safi_community2_cmd, | |
d02fbbdb | 10192 | "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
95cbbd2a ML |
10193 | SHOW_STR |
10194 | BGP_STR | |
8386ac43 | 10195 | BGP_INSTANCE_HELP_STR |
95cbbd2a | 10196 | "Address family\n" |
95cbbd2a | 10197 | "Address family\n" |
95cbbd2a ML |
10198 | "Address family modifier\n" |
10199 | "Address family modifier\n" | |
10200 | "Display routes matching the communities\n" | |
859d388e | 10201 | COMMUNITY_AANN_STR |
95cbbd2a ML |
10202 | "Do not send outside local AS (well-known community)\n" |
10203 | "Do not advertise to any peer (well-known community)\n" | |
10204 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10205 | COMMUNITY_AANN_STR |
95cbbd2a ML |
10206 | "Do not send outside local AS (well-known community)\n" |
10207 | "Do not advertise to any peer (well-known community)\n" | |
10208 | "Do not export to next AS (well-known community)\n") | |
10209 | ||
8386ac43 | 10210 | ALIAS (show_bgp_instance_afi_safi_community, |
10211 | show_bgp_instance_afi_safi_community3_cmd, | |
d02fbbdb | 10212 | "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
95cbbd2a ML |
10213 | SHOW_STR |
10214 | BGP_STR | |
8386ac43 | 10215 | BGP_INSTANCE_HELP_STR |
95cbbd2a | 10216 | "Address family\n" |
95cbbd2a | 10217 | "Address family\n" |
95cbbd2a ML |
10218 | "Address family modifier\n" |
10219 | "Address family modifier\n" | |
10220 | "Display routes matching the communities\n" | |
859d388e | 10221 | COMMUNITY_AANN_STR |
95cbbd2a ML |
10222 | "Do not send outside local AS (well-known community)\n" |
10223 | "Do not advertise to any peer (well-known community)\n" | |
10224 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10225 | COMMUNITY_AANN_STR |
95cbbd2a ML |
10226 | "Do not send outside local AS (well-known community)\n" |
10227 | "Do not advertise to any peer (well-known community)\n" | |
10228 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10229 | COMMUNITY_AANN_STR |
95cbbd2a ML |
10230 | "Do not send outside local AS (well-known community)\n" |
10231 | "Do not advertise to any peer (well-known community)\n" | |
10232 | "Do not export to next AS (well-known community)\n") | |
10233 | ||
8386ac43 | 10234 | ALIAS (show_bgp_instance_afi_safi_community, |
10235 | show_bgp_instance_afi_safi_community4_cmd, | |
d02fbbdb | 10236 | "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
95cbbd2a ML |
10237 | SHOW_STR |
10238 | BGP_STR | |
8386ac43 | 10239 | BGP_INSTANCE_HELP_STR |
95cbbd2a | 10240 | "Address family\n" |
95cbbd2a | 10241 | "Address family\n" |
95cbbd2a ML |
10242 | "Address family modifier\n" |
10243 | "Address family modifier\n" | |
10244 | "Display routes matching the communities\n" | |
859d388e | 10245 | COMMUNITY_AANN_STR |
95cbbd2a ML |
10246 | "Do not send outside local AS (well-known community)\n" |
10247 | "Do not advertise to any peer (well-known community)\n" | |
10248 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10249 | COMMUNITY_AANN_STR |
95cbbd2a ML |
10250 | "Do not send outside local AS (well-known community)\n" |
10251 | "Do not advertise to any peer (well-known community)\n" | |
10252 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10253 | COMMUNITY_AANN_STR |
95cbbd2a ML |
10254 | "Do not send outside local AS (well-known community)\n" |
10255 | "Do not advertise to any peer (well-known community)\n" | |
10256 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10257 | COMMUNITY_AANN_STR |
95cbbd2a ML |
10258 | "Do not send outside local AS (well-known community)\n" |
10259 | "Do not advertise to any peer (well-known community)\n" | |
10260 | "Do not export to next AS (well-known community)\n") | |
10261 | ||
718e3744 | 10262 | DEFUN (show_ip_bgp_community_exact, |
10263 | show_ip_bgp_community_exact_cmd, | |
10264 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10265 | SHOW_STR | |
10266 | IP_STR | |
10267 | BGP_STR | |
10268 | "Display routes matching the communities\n" | |
859d388e | 10269 | COMMUNITY_AANN_STR |
718e3744 | 10270 | "Do not send outside local AS (well-known community)\n" |
10271 | "Do not advertise to any peer (well-known community)\n" | |
10272 | "Do not export to next AS (well-known community)\n" | |
10273 | "Exact match of the communities") | |
10274 | { | |
95cbbd2a | 10275 | return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST); |
718e3744 | 10276 | } |
10277 | ||
10278 | ALIAS (show_ip_bgp_community_exact, | |
10279 | show_ip_bgp_community2_exact_cmd, | |
10280 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10281 | SHOW_STR | |
10282 | IP_STR | |
10283 | BGP_STR | |
10284 | "Display routes matching the communities\n" | |
859d388e | 10285 | COMMUNITY_AANN_STR |
718e3744 | 10286 | "Do not send outside local AS (well-known community)\n" |
10287 | "Do not advertise to any peer (well-known community)\n" | |
10288 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10289 | COMMUNITY_AANN_STR |
718e3744 | 10290 | "Do not send outside local AS (well-known community)\n" |
10291 | "Do not advertise to any peer (well-known community)\n" | |
10292 | "Do not export to next AS (well-known community)\n" | |
10293 | "Exact match of the communities") | |
10294 | ||
10295 | ALIAS (show_ip_bgp_community_exact, | |
10296 | show_ip_bgp_community3_exact_cmd, | |
10297 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10298 | SHOW_STR | |
10299 | IP_STR | |
10300 | BGP_STR | |
10301 | "Display routes matching the communities\n" | |
859d388e | 10302 | COMMUNITY_AANN_STR |
718e3744 | 10303 | "Do not send outside local AS (well-known community)\n" |
10304 | "Do not advertise to any peer (well-known community)\n" | |
10305 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10306 | COMMUNITY_AANN_STR |
718e3744 | 10307 | "Do not send outside local AS (well-known community)\n" |
10308 | "Do not advertise to any peer (well-known community)\n" | |
10309 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10310 | COMMUNITY_AANN_STR |
718e3744 | 10311 | "Do not send outside local AS (well-known community)\n" |
10312 | "Do not advertise to any peer (well-known community)\n" | |
10313 | "Do not export to next AS (well-known community)\n" | |
10314 | "Exact match of the communities") | |
10315 | ||
10316 | ALIAS (show_ip_bgp_community_exact, | |
10317 | show_ip_bgp_community4_exact_cmd, | |
10318 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10319 | SHOW_STR | |
10320 | IP_STR | |
10321 | BGP_STR | |
10322 | "Display routes matching the communities\n" | |
859d388e | 10323 | COMMUNITY_AANN_STR |
718e3744 | 10324 | "Do not send outside local AS (well-known community)\n" |
10325 | "Do not advertise to any peer (well-known community)\n" | |
10326 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10327 | COMMUNITY_AANN_STR |
718e3744 | 10328 | "Do not send outside local AS (well-known community)\n" |
10329 | "Do not advertise to any peer (well-known community)\n" | |
10330 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10331 | COMMUNITY_AANN_STR |
718e3744 | 10332 | "Do not send outside local AS (well-known community)\n" |
10333 | "Do not advertise to any peer (well-known community)\n" | |
10334 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10335 | COMMUNITY_AANN_STR |
718e3744 | 10336 | "Do not send outside local AS (well-known community)\n" |
10337 | "Do not advertise to any peer (well-known community)\n" | |
10338 | "Do not export to next AS (well-known community)\n" | |
10339 | "Exact match of the communities") | |
10340 | ||
10341 | DEFUN (show_ip_bgp_ipv4_community_exact, | |
10342 | show_ip_bgp_ipv4_community_exact_cmd, | |
d02fbbdb | 10343 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) exact-match", |
718e3744 | 10344 | SHOW_STR |
10345 | IP_STR | |
10346 | BGP_STR | |
10347 | "Address family\n" | |
d02fbbdb | 10348 | BGP_SAFI_HELP_STR |
718e3744 | 10349 | "Display routes matching the communities\n" |
859d388e | 10350 | COMMUNITY_AANN_STR |
718e3744 | 10351 | "Do not send outside local AS (well-known community)\n" |
10352 | "Do not advertise to any peer (well-known community)\n" | |
10353 | "Do not export to next AS (well-known community)\n" | |
10354 | "Exact match of the communities") | |
10355 | { | |
d02fbbdb LB |
10356 | safi_t safi; |
10357 | safi = bgp_vty_safi_from_arg(argv[0]); | |
10358 | return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, safi); | |
718e3744 | 10359 | } |
10360 | ||
10361 | ALIAS (show_ip_bgp_ipv4_community_exact, | |
10362 | show_ip_bgp_ipv4_community2_exact_cmd, | |
d02fbbdb | 10363 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", |
718e3744 | 10364 | SHOW_STR |
10365 | IP_STR | |
10366 | BGP_STR | |
10367 | "Address family\n" | |
d02fbbdb | 10368 | BGP_SAFI_HELP_STR |
718e3744 | 10369 | "Display routes matching the communities\n" |
859d388e | 10370 | COMMUNITY_AANN_STR |
718e3744 | 10371 | "Do not send outside local AS (well-known community)\n" |
10372 | "Do not advertise to any peer (well-known community)\n" | |
10373 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10374 | COMMUNITY_AANN_STR |
718e3744 | 10375 | "Do not send outside local AS (well-known community)\n" |
10376 | "Do not advertise to any peer (well-known community)\n" | |
10377 | "Do not export to next AS (well-known community)\n" | |
10378 | "Exact match of the communities") | |
10379 | ||
10380 | ALIAS (show_ip_bgp_ipv4_community_exact, | |
10381 | show_ip_bgp_ipv4_community3_exact_cmd, | |
d02fbbdb | 10382 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", |
718e3744 | 10383 | SHOW_STR |
10384 | IP_STR | |
10385 | BGP_STR | |
10386 | "Address family\n" | |
d02fbbdb | 10387 | BGP_SAFI_HELP_STR |
718e3744 | 10388 | "Display routes matching the communities\n" |
859d388e | 10389 | COMMUNITY_AANN_STR |
718e3744 | 10390 | "Do not send outside local AS (well-known community)\n" |
10391 | "Do not advertise to any peer (well-known community)\n" | |
10392 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10393 | COMMUNITY_AANN_STR |
718e3744 | 10394 | "Do not send outside local AS (well-known community)\n" |
10395 | "Do not advertise to any peer (well-known community)\n" | |
10396 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10397 | COMMUNITY_AANN_STR |
718e3744 | 10398 | "Do not send outside local AS (well-known community)\n" |
10399 | "Do not advertise to any peer (well-known community)\n" | |
10400 | "Do not export to next AS (well-known community)\n" | |
10401 | "Exact match of the communities") | |
10402 | ||
10403 | ALIAS (show_ip_bgp_ipv4_community_exact, | |
10404 | show_ip_bgp_ipv4_community4_exact_cmd, | |
d02fbbdb | 10405 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", |
718e3744 | 10406 | SHOW_STR |
10407 | IP_STR | |
10408 | BGP_STR | |
10409 | "Address family\n" | |
d02fbbdb | 10410 | BGP_SAFI_HELP_STR |
718e3744 | 10411 | "Display routes matching the communities\n" |
859d388e | 10412 | COMMUNITY_AANN_STR |
718e3744 | 10413 | "Do not send outside local AS (well-known community)\n" |
10414 | "Do not advertise to any peer (well-known community)\n" | |
10415 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10416 | COMMUNITY_AANN_STR |
718e3744 | 10417 | "Do not send outside local AS (well-known community)\n" |
10418 | "Do not advertise to any peer (well-known community)\n" | |
10419 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10420 | COMMUNITY_AANN_STR |
718e3744 | 10421 | "Do not send outside local AS (well-known community)\n" |
10422 | "Do not advertise to any peer (well-known community)\n" | |
10423 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10424 | COMMUNITY_AANN_STR |
718e3744 | 10425 | "Do not send outside local AS (well-known community)\n" |
10426 | "Do not advertise to any peer (well-known community)\n" | |
10427 | "Do not export to next AS (well-known community)\n" | |
10428 | "Exact match of the communities") | |
10429 | ||
10430 | #ifdef HAVE_IPV6 | |
10431 | DEFUN (show_bgp_community, | |
10432 | show_bgp_community_cmd, | |
10433 | "show bgp community (AA:NN|local-AS|no-advertise|no-export)", | |
10434 | SHOW_STR | |
10435 | BGP_STR | |
10436 | "Display routes matching the communities\n" | |
859d388e | 10437 | COMMUNITY_AANN_STR |
718e3744 | 10438 | "Do not send outside local AS (well-known community)\n" |
10439 | "Do not advertise to any peer (well-known community)\n" | |
10440 | "Do not export to next AS (well-known community)\n") | |
10441 | { | |
95cbbd2a | 10442 | return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST); |
718e3744 | 10443 | } |
10444 | ||
10445 | ALIAS (show_bgp_community, | |
10446 | show_bgp_ipv6_community_cmd, | |
10447 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)", | |
10448 | SHOW_STR | |
10449 | BGP_STR | |
10450 | "Address family\n" | |
10451 | "Display routes matching the communities\n" | |
859d388e | 10452 | COMMUNITY_AANN_STR |
718e3744 | 10453 | "Do not send outside local AS (well-known community)\n" |
10454 | "Do not advertise to any peer (well-known community)\n" | |
10455 | "Do not export to next AS (well-known community)\n") | |
10456 | ||
10457 | ALIAS (show_bgp_community, | |
10458 | show_bgp_community2_cmd, | |
10459 | "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
10460 | SHOW_STR | |
10461 | BGP_STR | |
10462 | "Display routes matching the communities\n" | |
859d388e | 10463 | COMMUNITY_AANN_STR |
718e3744 | 10464 | "Do not send outside local AS (well-known community)\n" |
10465 | "Do not advertise to any peer (well-known community)\n" | |
10466 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10467 | COMMUNITY_AANN_STR |
718e3744 | 10468 | "Do not send outside local AS (well-known community)\n" |
10469 | "Do not advertise to any peer (well-known community)\n" | |
10470 | "Do not export to next AS (well-known community)\n") | |
10471 | ||
10472 | ALIAS (show_bgp_community, | |
10473 | show_bgp_ipv6_community2_cmd, | |
10474 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
10475 | SHOW_STR | |
10476 | BGP_STR | |
10477 | "Address family\n" | |
10478 | "Display routes matching the communities\n" | |
859d388e | 10479 | COMMUNITY_AANN_STR |
718e3744 | 10480 | "Do not send outside local AS (well-known community)\n" |
10481 | "Do not advertise to any peer (well-known community)\n" | |
10482 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10483 | COMMUNITY_AANN_STR |
718e3744 | 10484 | "Do not send outside local AS (well-known community)\n" |
10485 | "Do not advertise to any peer (well-known community)\n" | |
10486 | "Do not export to next AS (well-known community)\n") | |
10487 | ||
10488 | ALIAS (show_bgp_community, | |
10489 | show_bgp_community3_cmd, | |
10490 | "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
10491 | SHOW_STR | |
10492 | BGP_STR | |
10493 | "Display routes matching the communities\n" | |
859d388e | 10494 | COMMUNITY_AANN_STR |
718e3744 | 10495 | "Do not send outside local AS (well-known community)\n" |
10496 | "Do not advertise to any peer (well-known community)\n" | |
10497 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10498 | COMMUNITY_AANN_STR |
718e3744 | 10499 | "Do not send outside local AS (well-known community)\n" |
10500 | "Do not advertise to any peer (well-known community)\n" | |
10501 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10502 | COMMUNITY_AANN_STR |
718e3744 | 10503 | "Do not send outside local AS (well-known community)\n" |
10504 | "Do not advertise to any peer (well-known community)\n" | |
10505 | "Do not export to next AS (well-known community)\n") | |
10506 | ||
10507 | ALIAS (show_bgp_community, | |
10508 | show_bgp_ipv6_community3_cmd, | |
10509 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
10510 | SHOW_STR | |
10511 | BGP_STR | |
10512 | "Address family\n" | |
10513 | "Display routes matching the communities\n" | |
859d388e | 10514 | COMMUNITY_AANN_STR |
718e3744 | 10515 | "Do not send outside local AS (well-known community)\n" |
10516 | "Do not advertise to any peer (well-known community)\n" | |
10517 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10518 | COMMUNITY_AANN_STR |
718e3744 | 10519 | "Do not send outside local AS (well-known community)\n" |
10520 | "Do not advertise to any peer (well-known community)\n" | |
10521 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10522 | COMMUNITY_AANN_STR |
718e3744 | 10523 | "Do not send outside local AS (well-known community)\n" |
10524 | "Do not advertise to any peer (well-known community)\n" | |
10525 | "Do not export to next AS (well-known community)\n") | |
10526 | ||
10527 | ALIAS (show_bgp_community, | |
10528 | show_bgp_community4_cmd, | |
10529 | "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
10530 | SHOW_STR | |
10531 | BGP_STR | |
10532 | "Display routes matching the communities\n" | |
859d388e | 10533 | COMMUNITY_AANN_STR |
718e3744 | 10534 | "Do not send outside local AS (well-known community)\n" |
10535 | "Do not advertise to any peer (well-known community)\n" | |
10536 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10537 | COMMUNITY_AANN_STR |
718e3744 | 10538 | "Do not send outside local AS (well-known community)\n" |
10539 | "Do not advertise to any peer (well-known community)\n" | |
10540 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10541 | COMMUNITY_AANN_STR |
718e3744 | 10542 | "Do not send outside local AS (well-known community)\n" |
10543 | "Do not advertise to any peer (well-known community)\n" | |
10544 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10545 | COMMUNITY_AANN_STR |
718e3744 | 10546 | "Do not send outside local AS (well-known community)\n" |
10547 | "Do not advertise to any peer (well-known community)\n" | |
10548 | "Do not export to next AS (well-known community)\n") | |
10549 | ||
10550 | ALIAS (show_bgp_community, | |
10551 | show_bgp_ipv6_community4_cmd, | |
10552 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
10553 | SHOW_STR | |
10554 | BGP_STR | |
10555 | "Address family\n" | |
10556 | "Display routes matching the communities\n" | |
859d388e | 10557 | COMMUNITY_AANN_STR |
718e3744 | 10558 | "Do not send outside local AS (well-known community)\n" |
10559 | "Do not advertise to any peer (well-known community)\n" | |
10560 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10561 | COMMUNITY_AANN_STR |
718e3744 | 10562 | "Do not send outside local AS (well-known community)\n" |
10563 | "Do not advertise to any peer (well-known community)\n" | |
10564 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10565 | COMMUNITY_AANN_STR |
718e3744 | 10566 | "Do not send outside local AS (well-known community)\n" |
10567 | "Do not advertise to any peer (well-known community)\n" | |
10568 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10569 | COMMUNITY_AANN_STR |
718e3744 | 10570 | "Do not send outside local AS (well-known community)\n" |
10571 | "Do not advertise to any peer (well-known community)\n" | |
10572 | "Do not export to next AS (well-known community)\n") | |
10573 | ||
10574 | /* old command */ | |
10575 | DEFUN (show_ipv6_bgp_community, | |
10576 | show_ipv6_bgp_community_cmd, | |
10577 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)", | |
10578 | SHOW_STR | |
10579 | IPV6_STR | |
10580 | BGP_STR | |
10581 | "Display routes matching the communities\n" | |
859d388e | 10582 | COMMUNITY_AANN_STR |
718e3744 | 10583 | "Do not send outside local AS (well-known community)\n" |
10584 | "Do not advertise to any peer (well-known community)\n" | |
10585 | "Do not export to next AS (well-known community)\n") | |
10586 | { | |
47e9b292 | 10587 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
95cbbd2a | 10588 | return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST); |
718e3744 | 10589 | } |
10590 | ||
10591 | /* old command */ | |
10592 | ALIAS (show_ipv6_bgp_community, | |
10593 | show_ipv6_bgp_community2_cmd, | |
10594 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
10595 | SHOW_STR | |
10596 | IPV6_STR | |
10597 | BGP_STR | |
10598 | "Display routes matching the communities\n" | |
859d388e | 10599 | COMMUNITY_AANN_STR |
718e3744 | 10600 | "Do not send outside local AS (well-known community)\n" |
10601 | "Do not advertise to any peer (well-known community)\n" | |
10602 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10603 | COMMUNITY_AANN_STR |
718e3744 | 10604 | "Do not send outside local AS (well-known community)\n" |
10605 | "Do not advertise to any peer (well-known community)\n" | |
10606 | "Do not export to next AS (well-known community)\n") | |
10607 | ||
10608 | /* old command */ | |
10609 | ALIAS (show_ipv6_bgp_community, | |
10610 | show_ipv6_bgp_community3_cmd, | |
10611 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
10612 | SHOW_STR | |
10613 | IPV6_STR | |
10614 | BGP_STR | |
10615 | "Display routes matching the communities\n" | |
859d388e | 10616 | COMMUNITY_AANN_STR |
718e3744 | 10617 | "Do not send outside local AS (well-known community)\n" |
10618 | "Do not advertise to any peer (well-known community)\n" | |
10619 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10620 | COMMUNITY_AANN_STR |
718e3744 | 10621 | "Do not send outside local AS (well-known community)\n" |
10622 | "Do not advertise to any peer (well-known community)\n" | |
10623 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10624 | COMMUNITY_AANN_STR |
718e3744 | 10625 | "Do not send outside local AS (well-known community)\n" |
10626 | "Do not advertise to any peer (well-known community)\n" | |
10627 | "Do not export to next AS (well-known community)\n") | |
10628 | ||
10629 | /* old command */ | |
10630 | ALIAS (show_ipv6_bgp_community, | |
10631 | show_ipv6_bgp_community4_cmd, | |
10632 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
10633 | SHOW_STR | |
10634 | IPV6_STR | |
10635 | BGP_STR | |
10636 | "Display routes matching the communities\n" | |
859d388e | 10637 | COMMUNITY_AANN_STR |
718e3744 | 10638 | "Do not send outside local AS (well-known community)\n" |
10639 | "Do not advertise to any peer (well-known community)\n" | |
10640 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10641 | COMMUNITY_AANN_STR |
718e3744 | 10642 | "Do not send outside local AS (well-known community)\n" |
10643 | "Do not advertise to any peer (well-known community)\n" | |
10644 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10645 | COMMUNITY_AANN_STR |
718e3744 | 10646 | "Do not send outside local AS (well-known community)\n" |
10647 | "Do not advertise to any peer (well-known community)\n" | |
10648 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10649 | COMMUNITY_AANN_STR |
718e3744 | 10650 | "Do not send outside local AS (well-known community)\n" |
10651 | "Do not advertise to any peer (well-known community)\n" | |
10652 | "Do not export to next AS (well-known community)\n") | |
10653 | ||
10654 | DEFUN (show_bgp_community_exact, | |
10655 | show_bgp_community_exact_cmd, | |
10656 | "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10657 | SHOW_STR | |
10658 | BGP_STR | |
10659 | "Display routes matching the communities\n" | |
859d388e | 10660 | COMMUNITY_AANN_STR |
718e3744 | 10661 | "Do not send outside local AS (well-known community)\n" |
10662 | "Do not advertise to any peer (well-known community)\n" | |
10663 | "Do not export to next AS (well-known community)\n" | |
10664 | "Exact match of the communities") | |
10665 | { | |
95cbbd2a | 10666 | return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST); |
718e3744 | 10667 | } |
10668 | ||
10669 | ALIAS (show_bgp_community_exact, | |
10670 | show_bgp_ipv6_community_exact_cmd, | |
10671 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10672 | SHOW_STR | |
10673 | BGP_STR | |
10674 | "Address family\n" | |
10675 | "Display routes matching the communities\n" | |
859d388e | 10676 | COMMUNITY_AANN_STR |
718e3744 | 10677 | "Do not send outside local AS (well-known community)\n" |
10678 | "Do not advertise to any peer (well-known community)\n" | |
10679 | "Do not export to next AS (well-known community)\n" | |
10680 | "Exact match of the communities") | |
10681 | ||
10682 | ALIAS (show_bgp_community_exact, | |
10683 | show_bgp_community2_exact_cmd, | |
10684 | "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10685 | SHOW_STR | |
10686 | BGP_STR | |
10687 | "Display routes matching the communities\n" | |
859d388e | 10688 | COMMUNITY_AANN_STR |
718e3744 | 10689 | "Do not send outside local AS (well-known community)\n" |
10690 | "Do not advertise to any peer (well-known community)\n" | |
10691 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10692 | COMMUNITY_AANN_STR |
718e3744 | 10693 | "Do not send outside local AS (well-known community)\n" |
10694 | "Do not advertise to any peer (well-known community)\n" | |
10695 | "Do not export to next AS (well-known community)\n" | |
10696 | "Exact match of the communities") | |
10697 | ||
10698 | ALIAS (show_bgp_community_exact, | |
10699 | show_bgp_ipv6_community2_exact_cmd, | |
10700 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10701 | SHOW_STR | |
10702 | BGP_STR | |
10703 | "Address family\n" | |
10704 | "Display routes matching the communities\n" | |
859d388e | 10705 | COMMUNITY_AANN_STR |
718e3744 | 10706 | "Do not send outside local AS (well-known community)\n" |
10707 | "Do not advertise to any peer (well-known community)\n" | |
10708 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10709 | COMMUNITY_AANN_STR |
718e3744 | 10710 | "Do not send outside local AS (well-known community)\n" |
10711 | "Do not advertise to any peer (well-known community)\n" | |
10712 | "Do not export to next AS (well-known community)\n" | |
10713 | "Exact match of the communities") | |
10714 | ||
10715 | ALIAS (show_bgp_community_exact, | |
10716 | show_bgp_community3_exact_cmd, | |
10717 | "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10718 | SHOW_STR | |
10719 | BGP_STR | |
10720 | "Display routes matching the communities\n" | |
859d388e | 10721 | COMMUNITY_AANN_STR |
718e3744 | 10722 | "Do not send outside local AS (well-known community)\n" |
10723 | "Do not advertise to any peer (well-known community)\n" | |
10724 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10725 | COMMUNITY_AANN_STR |
718e3744 | 10726 | "Do not send outside local AS (well-known community)\n" |
10727 | "Do not advertise to any peer (well-known community)\n" | |
10728 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10729 | COMMUNITY_AANN_STR |
718e3744 | 10730 | "Do not send outside local AS (well-known community)\n" |
10731 | "Do not advertise to any peer (well-known community)\n" | |
10732 | "Do not export to next AS (well-known community)\n" | |
10733 | "Exact match of the communities") | |
10734 | ||
10735 | ALIAS (show_bgp_community_exact, | |
10736 | show_bgp_ipv6_community3_exact_cmd, | |
10737 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10738 | SHOW_STR | |
10739 | BGP_STR | |
10740 | "Address family\n" | |
10741 | "Display routes matching the communities\n" | |
859d388e | 10742 | COMMUNITY_AANN_STR |
718e3744 | 10743 | "Do not send outside local AS (well-known community)\n" |
10744 | "Do not advertise to any peer (well-known community)\n" | |
10745 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10746 | COMMUNITY_AANN_STR |
718e3744 | 10747 | "Do not send outside local AS (well-known community)\n" |
10748 | "Do not advertise to any peer (well-known community)\n" | |
10749 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10750 | COMMUNITY_AANN_STR |
718e3744 | 10751 | "Do not send outside local AS (well-known community)\n" |
10752 | "Do not advertise to any peer (well-known community)\n" | |
10753 | "Do not export to next AS (well-known community)\n" | |
10754 | "Exact match of the communities") | |
10755 | ||
10756 | ALIAS (show_bgp_community_exact, | |
10757 | show_bgp_community4_exact_cmd, | |
10758 | "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10759 | SHOW_STR | |
10760 | BGP_STR | |
10761 | "Display routes matching the communities\n" | |
859d388e | 10762 | COMMUNITY_AANN_STR |
718e3744 | 10763 | "Do not send outside local AS (well-known community)\n" |
10764 | "Do not advertise to any peer (well-known community)\n" | |
10765 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10766 | COMMUNITY_AANN_STR |
718e3744 | 10767 | "Do not send outside local AS (well-known community)\n" |
10768 | "Do not advertise to any peer (well-known community)\n" | |
10769 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10770 | COMMUNITY_AANN_STR |
718e3744 | 10771 | "Do not send outside local AS (well-known community)\n" |
10772 | "Do not advertise to any peer (well-known community)\n" | |
10773 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10774 | COMMUNITY_AANN_STR |
718e3744 | 10775 | "Do not send outside local AS (well-known community)\n" |
10776 | "Do not advertise to any peer (well-known community)\n" | |
10777 | "Do not export to next AS (well-known community)\n" | |
10778 | "Exact match of the communities") | |
10779 | ||
10780 | ALIAS (show_bgp_community_exact, | |
10781 | show_bgp_ipv6_community4_exact_cmd, | |
10782 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10783 | SHOW_STR | |
10784 | BGP_STR | |
10785 | "Address family\n" | |
10786 | "Display routes matching the communities\n" | |
859d388e | 10787 | COMMUNITY_AANN_STR |
718e3744 | 10788 | "Do not send outside local AS (well-known community)\n" |
10789 | "Do not advertise to any peer (well-known community)\n" | |
10790 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10791 | COMMUNITY_AANN_STR |
718e3744 | 10792 | "Do not send outside local AS (well-known community)\n" |
10793 | "Do not advertise to any peer (well-known community)\n" | |
10794 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10795 | COMMUNITY_AANN_STR |
718e3744 | 10796 | "Do not send outside local AS (well-known community)\n" |
10797 | "Do not advertise to any peer (well-known community)\n" | |
10798 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10799 | COMMUNITY_AANN_STR |
718e3744 | 10800 | "Do not send outside local AS (well-known community)\n" |
10801 | "Do not advertise to any peer (well-known community)\n" | |
10802 | "Do not export to next AS (well-known community)\n" | |
10803 | "Exact match of the communities") | |
10804 | ||
10805 | /* old command */ | |
10806 | DEFUN (show_ipv6_bgp_community_exact, | |
10807 | show_ipv6_bgp_community_exact_cmd, | |
10808 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10809 | SHOW_STR | |
10810 | IPV6_STR | |
10811 | BGP_STR | |
10812 | "Display routes matching the communities\n" | |
859d388e | 10813 | COMMUNITY_AANN_STR |
718e3744 | 10814 | "Do not send outside local AS (well-known community)\n" |
10815 | "Do not advertise to any peer (well-known community)\n" | |
10816 | "Do not export to next AS (well-known community)\n" | |
10817 | "Exact match of the communities") | |
10818 | { | |
47e9b292 | 10819 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
95cbbd2a | 10820 | return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST); |
718e3744 | 10821 | } |
10822 | ||
10823 | /* old command */ | |
10824 | ALIAS (show_ipv6_bgp_community_exact, | |
10825 | show_ipv6_bgp_community2_exact_cmd, | |
10826 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10827 | SHOW_STR | |
10828 | IPV6_STR | |
10829 | BGP_STR | |
10830 | "Display routes matching the communities\n" | |
859d388e | 10831 | COMMUNITY_AANN_STR |
718e3744 | 10832 | "Do not send outside local AS (well-known community)\n" |
10833 | "Do not advertise to any peer (well-known community)\n" | |
10834 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10835 | COMMUNITY_AANN_STR |
718e3744 | 10836 | "Do not send outside local AS (well-known community)\n" |
10837 | "Do not advertise to any peer (well-known community)\n" | |
10838 | "Do not export to next AS (well-known community)\n" | |
10839 | "Exact match of the communities") | |
10840 | ||
10841 | /* old command */ | |
10842 | ALIAS (show_ipv6_bgp_community_exact, | |
10843 | show_ipv6_bgp_community3_exact_cmd, | |
10844 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10845 | SHOW_STR | |
10846 | IPV6_STR | |
10847 | BGP_STR | |
10848 | "Display routes matching the communities\n" | |
859d388e | 10849 | COMMUNITY_AANN_STR |
718e3744 | 10850 | "Do not send outside local AS (well-known community)\n" |
10851 | "Do not advertise to any peer (well-known community)\n" | |
10852 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10853 | COMMUNITY_AANN_STR |
718e3744 | 10854 | "Do not send outside local AS (well-known community)\n" |
10855 | "Do not advertise to any peer (well-known community)\n" | |
10856 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10857 | COMMUNITY_AANN_STR |
718e3744 | 10858 | "Do not send outside local AS (well-known community)\n" |
10859 | "Do not advertise to any peer (well-known community)\n" | |
10860 | "Do not export to next AS (well-known community)\n" | |
10861 | "Exact match of the communities") | |
10862 | ||
10863 | /* old command */ | |
10864 | ALIAS (show_ipv6_bgp_community_exact, | |
10865 | show_ipv6_bgp_community4_exact_cmd, | |
10866 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10867 | SHOW_STR | |
10868 | IPV6_STR | |
10869 | BGP_STR | |
10870 | "Display routes matching the communities\n" | |
859d388e | 10871 | COMMUNITY_AANN_STR |
718e3744 | 10872 | "Do not send outside local AS (well-known community)\n" |
10873 | "Do not advertise to any peer (well-known community)\n" | |
10874 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10875 | COMMUNITY_AANN_STR |
718e3744 | 10876 | "Do not send outside local AS (well-known community)\n" |
10877 | "Do not advertise to any peer (well-known community)\n" | |
10878 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10879 | COMMUNITY_AANN_STR |
718e3744 | 10880 | "Do not send outside local AS (well-known community)\n" |
10881 | "Do not advertise to any peer (well-known community)\n" | |
10882 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10883 | COMMUNITY_AANN_STR |
718e3744 | 10884 | "Do not send outside local AS (well-known community)\n" |
10885 | "Do not advertise to any peer (well-known community)\n" | |
10886 | "Do not export to next AS (well-known community)\n" | |
10887 | "Exact match of the communities") | |
10888 | ||
10889 | /* old command */ | |
10890 | DEFUN (show_ipv6_mbgp_community, | |
10891 | show_ipv6_mbgp_community_cmd, | |
10892 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)", | |
10893 | SHOW_STR | |
10894 | IPV6_STR | |
10895 | MBGP_STR | |
10896 | "Display routes matching the communities\n" | |
859d388e | 10897 | COMMUNITY_AANN_STR |
718e3744 | 10898 | "Do not send outside local AS (well-known community)\n" |
10899 | "Do not advertise to any peer (well-known community)\n" | |
10900 | "Do not export to next AS (well-known community)\n") | |
10901 | { | |
47e9b292 | 10902 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
95cbbd2a | 10903 | return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST); |
718e3744 | 10904 | } |
10905 | ||
10906 | /* old command */ | |
10907 | ALIAS (show_ipv6_mbgp_community, | |
10908 | show_ipv6_mbgp_community2_cmd, | |
10909 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
10910 | SHOW_STR | |
10911 | IPV6_STR | |
10912 | MBGP_STR | |
10913 | "Display routes matching the communities\n" | |
859d388e | 10914 | COMMUNITY_AANN_STR |
718e3744 | 10915 | "Do not send outside local AS (well-known community)\n" |
10916 | "Do not advertise to any peer (well-known community)\n" | |
10917 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10918 | COMMUNITY_AANN_STR |
718e3744 | 10919 | "Do not send outside local AS (well-known community)\n" |
10920 | "Do not advertise to any peer (well-known community)\n" | |
10921 | "Do not export to next AS (well-known community)\n") | |
10922 | ||
10923 | /* old command */ | |
10924 | ALIAS (show_ipv6_mbgp_community, | |
10925 | show_ipv6_mbgp_community3_cmd, | |
10926 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
10927 | SHOW_STR | |
10928 | IPV6_STR | |
10929 | MBGP_STR | |
10930 | "Display routes matching the communities\n" | |
859d388e | 10931 | COMMUNITY_AANN_STR |
718e3744 | 10932 | "Do not send outside local AS (well-known community)\n" |
10933 | "Do not advertise to any peer (well-known community)\n" | |
10934 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10935 | COMMUNITY_AANN_STR |
718e3744 | 10936 | "Do not send outside local AS (well-known community)\n" |
10937 | "Do not advertise to any peer (well-known community)\n" | |
10938 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10939 | COMMUNITY_AANN_STR |
718e3744 | 10940 | "Do not send outside local AS (well-known community)\n" |
10941 | "Do not advertise to any peer (well-known community)\n" | |
10942 | "Do not export to next AS (well-known community)\n") | |
10943 | ||
10944 | /* old command */ | |
10945 | ALIAS (show_ipv6_mbgp_community, | |
10946 | show_ipv6_mbgp_community4_cmd, | |
10947 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
10948 | SHOW_STR | |
10949 | IPV6_STR | |
10950 | MBGP_STR | |
10951 | "Display routes matching the communities\n" | |
859d388e | 10952 | COMMUNITY_AANN_STR |
718e3744 | 10953 | "Do not send outside local AS (well-known community)\n" |
10954 | "Do not advertise to any peer (well-known community)\n" | |
10955 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10956 | COMMUNITY_AANN_STR |
718e3744 | 10957 | "Do not send outside local AS (well-known community)\n" |
10958 | "Do not advertise to any peer (well-known community)\n" | |
10959 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10960 | COMMUNITY_AANN_STR |
718e3744 | 10961 | "Do not send outside local AS (well-known community)\n" |
10962 | "Do not advertise to any peer (well-known community)\n" | |
10963 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10964 | COMMUNITY_AANN_STR |
718e3744 | 10965 | "Do not send outside local AS (well-known community)\n" |
10966 | "Do not advertise to any peer (well-known community)\n" | |
10967 | "Do not export to next AS (well-known community)\n") | |
10968 | ||
10969 | /* old command */ | |
10970 | DEFUN (show_ipv6_mbgp_community_exact, | |
10971 | show_ipv6_mbgp_community_exact_cmd, | |
10972 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10973 | SHOW_STR | |
10974 | IPV6_STR | |
10975 | MBGP_STR | |
10976 | "Display routes matching the communities\n" | |
859d388e | 10977 | COMMUNITY_AANN_STR |
718e3744 | 10978 | "Do not send outside local AS (well-known community)\n" |
10979 | "Do not advertise to any peer (well-known community)\n" | |
10980 | "Do not export to next AS (well-known community)\n" | |
10981 | "Exact match of the communities") | |
10982 | { | |
47e9b292 | 10983 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
95cbbd2a | 10984 | return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST); |
718e3744 | 10985 | } |
10986 | ||
10987 | /* old command */ | |
10988 | ALIAS (show_ipv6_mbgp_community_exact, | |
10989 | show_ipv6_mbgp_community2_exact_cmd, | |
10990 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10991 | SHOW_STR | |
10992 | IPV6_STR | |
10993 | MBGP_STR | |
10994 | "Display routes matching the communities\n" | |
859d388e | 10995 | COMMUNITY_AANN_STR |
718e3744 | 10996 | "Do not send outside local AS (well-known community)\n" |
10997 | "Do not advertise to any peer (well-known community)\n" | |
10998 | "Do not export to next AS (well-known community)\n" | |
859d388e | 10999 | COMMUNITY_AANN_STR |
718e3744 | 11000 | "Do not send outside local AS (well-known community)\n" |
11001 | "Do not advertise to any peer (well-known community)\n" | |
11002 | "Do not export to next AS (well-known community)\n" | |
11003 | "Exact match of the communities") | |
11004 | ||
11005 | /* old command */ | |
11006 | ALIAS (show_ipv6_mbgp_community_exact, | |
11007 | show_ipv6_mbgp_community3_exact_cmd, | |
11008 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
11009 | SHOW_STR | |
11010 | IPV6_STR | |
11011 | MBGP_STR | |
11012 | "Display routes matching the communities\n" | |
859d388e | 11013 | COMMUNITY_AANN_STR |
718e3744 | 11014 | "Do not send outside local AS (well-known community)\n" |
11015 | "Do not advertise to any peer (well-known community)\n" | |
11016 | "Do not export to next AS (well-known community)\n" | |
859d388e | 11017 | COMMUNITY_AANN_STR |
718e3744 | 11018 | "Do not send outside local AS (well-known community)\n" |
11019 | "Do not advertise to any peer (well-known community)\n" | |
11020 | "Do not export to next AS (well-known community)\n" | |
859d388e | 11021 | COMMUNITY_AANN_STR |
718e3744 | 11022 | "Do not send outside local AS (well-known community)\n" |
11023 | "Do not advertise to any peer (well-known community)\n" | |
11024 | "Do not export to next AS (well-known community)\n" | |
11025 | "Exact match of the communities") | |
11026 | ||
11027 | /* old command */ | |
11028 | ALIAS (show_ipv6_mbgp_community_exact, | |
11029 | show_ipv6_mbgp_community4_exact_cmd, | |
11030 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
11031 | SHOW_STR | |
11032 | IPV6_STR | |
11033 | MBGP_STR | |
11034 | "Display routes matching the communities\n" | |
859d388e | 11035 | COMMUNITY_AANN_STR |
718e3744 | 11036 | "Do not send outside local AS (well-known community)\n" |
11037 | "Do not advertise to any peer (well-known community)\n" | |
11038 | "Do not export to next AS (well-known community)\n" | |
859d388e | 11039 | COMMUNITY_AANN_STR |
718e3744 | 11040 | "Do not send outside local AS (well-known community)\n" |
11041 | "Do not advertise to any peer (well-known community)\n" | |
11042 | "Do not export to next AS (well-known community)\n" | |
859d388e | 11043 | COMMUNITY_AANN_STR |
718e3744 | 11044 | "Do not send outside local AS (well-known community)\n" |
11045 | "Do not advertise to any peer (well-known community)\n" | |
11046 | "Do not export to next AS (well-known community)\n" | |
859d388e | 11047 | COMMUNITY_AANN_STR |
718e3744 | 11048 | "Do not send outside local AS (well-known community)\n" |
11049 | "Do not advertise to any peer (well-known community)\n" | |
11050 | "Do not export to next AS (well-known community)\n" | |
11051 | "Exact match of the communities") | |
11052 | #endif /* HAVE_IPV6 */ | |
6b0655a2 | 11053 | |
94f2b392 | 11054 | static int |
50ef26d4 | 11055 | bgp_show_community_list (struct vty *vty, const char *name, |
11056 | const char *com, int exact, | |
4c9641ba | 11057 | afi_t afi, safi_t safi) |
718e3744 | 11058 | { |
11059 | struct community_list *list; | |
50ef26d4 | 11060 | struct bgp *bgp = NULL; |
11061 | ||
11062 | if (name && !(bgp = bgp_lookup_by_name(name))) | |
11063 | { | |
11064 | vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE); | |
11065 | return CMD_WARNING; | |
11066 | } | |
718e3744 | 11067 | |
fee6e4e4 | 11068 | list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER); |
718e3744 | 11069 | if (list == NULL) |
11070 | { | |
11071 | vty_out (vty, "%% %s is not a valid community-list name%s", com, | |
11072 | VTY_NEWLINE); | |
11073 | return CMD_WARNING; | |
11074 | } | |
11075 | ||
50ef26d4 | 11076 | return bgp_show (vty, bgp, afi, safi, |
5a646650 | 11077 | (exact ? bgp_show_type_community_list_exact : |
b05a1c8b | 11078 | bgp_show_type_community_list), list, 0); |
718e3744 | 11079 | } |
11080 | ||
11081 | DEFUN (show_ip_bgp_community_list, | |
11082 | show_ip_bgp_community_list_cmd, | |
fee6e4e4 | 11083 | "show ip bgp community-list (<1-500>|WORD)", |
718e3744 | 11084 | SHOW_STR |
11085 | IP_STR | |
11086 | BGP_STR | |
11087 | "Display routes matching the community-list\n" | |
fee6e4e4 | 11088 | "community-list number\n" |
718e3744 | 11089 | "community-list name\n") |
11090 | { | |
50ef26d4 | 11091 | return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP, SAFI_UNICAST); |
11092 | } | |
11093 | ||
8386ac43 | 11094 | DEFUN (show_ip_bgp_instance_community_list, |
11095 | show_ip_bgp_instance_community_list_cmd, | |
11096 | "show ip bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)", | |
50ef26d4 | 11097 | SHOW_STR |
11098 | IP_STR | |
11099 | BGP_STR | |
8386ac43 | 11100 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 11101 | "Display routes matching the community-list\n" |
11102 | "community-list number\n" | |
11103 | "community-list name\n") | |
11104 | { | |
11105 | return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP, SAFI_UNICAST); | |
718e3744 | 11106 | } |
11107 | ||
11108 | DEFUN (show_ip_bgp_ipv4_community_list, | |
11109 | show_ip_bgp_ipv4_community_list_cmd, | |
d02fbbdb | 11110 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community-list (<1-500>|WORD)", |
718e3744 | 11111 | SHOW_STR |
11112 | IP_STR | |
11113 | BGP_STR | |
11114 | "Address family\n" | |
d02fbbdb | 11115 | BGP_SAFI_HELP_STR |
718e3744 | 11116 | "Display routes matching the community-list\n" |
fee6e4e4 | 11117 | "community-list number\n" |
718e3744 | 11118 | "community-list name\n") |
11119 | { | |
d02fbbdb LB |
11120 | safi_t safi; |
11121 | safi = bgp_vty_safi_from_arg(argv[0]); | |
11122 | return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, safi); | |
718e3744 | 11123 | } |
11124 | ||
11125 | DEFUN (show_ip_bgp_community_list_exact, | |
11126 | show_ip_bgp_community_list_exact_cmd, | |
fee6e4e4 | 11127 | "show ip bgp community-list (<1-500>|WORD) exact-match", |
718e3744 | 11128 | SHOW_STR |
11129 | IP_STR | |
11130 | BGP_STR | |
11131 | "Display routes matching the community-list\n" | |
fee6e4e4 | 11132 | "community-list number\n" |
718e3744 | 11133 | "community-list name\n" |
11134 | "Exact match of the communities\n") | |
11135 | { | |
50ef26d4 | 11136 | return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP, SAFI_UNICAST); |
718e3744 | 11137 | } |
11138 | ||
11139 | DEFUN (show_ip_bgp_ipv4_community_list_exact, | |
11140 | show_ip_bgp_ipv4_community_list_exact_cmd, | |
d02fbbdb | 11141 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community-list (<1-500>|WORD) exact-match", |
718e3744 | 11142 | SHOW_STR |
11143 | IP_STR | |
11144 | BGP_STR | |
11145 | "Address family\n" | |
d02fbbdb | 11146 | BGP_SAFI_HELP_STR |
718e3744 | 11147 | "Display routes matching the community-list\n" |
fee6e4e4 | 11148 | "community-list number\n" |
718e3744 | 11149 | "community-list name\n" |
11150 | "Exact match of the communities\n") | |
11151 | { | |
d02fbbdb LB |
11152 | safi_t safi; |
11153 | safi = bgp_vty_safi_from_arg(argv[0]); | |
11154 | return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, safi); | |
718e3744 | 11155 | } |
11156 | ||
11157 | #ifdef HAVE_IPV6 | |
11158 | DEFUN (show_bgp_community_list, | |
11159 | show_bgp_community_list_cmd, | |
fee6e4e4 | 11160 | "show bgp community-list (<1-500>|WORD)", |
718e3744 | 11161 | SHOW_STR |
11162 | BGP_STR | |
11163 | "Display routes matching the community-list\n" | |
fee6e4e4 | 11164 | "community-list number\n" |
718e3744 | 11165 | "community-list name\n") |
11166 | { | |
50ef26d4 | 11167 | return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST); |
718e3744 | 11168 | } |
11169 | ||
11170 | ALIAS (show_bgp_community_list, | |
11171 | show_bgp_ipv6_community_list_cmd, | |
fee6e4e4 | 11172 | "show bgp ipv6 community-list (<1-500>|WORD)", |
718e3744 | 11173 | SHOW_STR |
11174 | BGP_STR | |
11175 | "Address family\n" | |
11176 | "Display routes matching the community-list\n" | |
fee6e4e4 | 11177 | "community-list number\n" |
e8e1946e | 11178 | "community-list name\n") |
718e3744 | 11179 | |
11180 | /* old command */ | |
11181 | DEFUN (show_ipv6_bgp_community_list, | |
11182 | show_ipv6_bgp_community_list_cmd, | |
11183 | "show ipv6 bgp community-list WORD", | |
11184 | SHOW_STR | |
11185 | IPV6_STR | |
11186 | BGP_STR | |
11187 | "Display routes matching the community-list\n" | |
11188 | "community-list name\n") | |
11189 | { | |
47e9b292 | 11190 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
50ef26d4 | 11191 | return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST); |
718e3744 | 11192 | } |
11193 | ||
11194 | /* old command */ | |
11195 | DEFUN (show_ipv6_mbgp_community_list, | |
11196 | show_ipv6_mbgp_community_list_cmd, | |
11197 | "show ipv6 mbgp community-list WORD", | |
11198 | SHOW_STR | |
11199 | IPV6_STR | |
11200 | MBGP_STR | |
11201 | "Display routes matching the community-list\n" | |
11202 | "community-list name\n") | |
11203 | { | |
47e9b292 | 11204 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
50ef26d4 | 11205 | return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_MULTICAST); |
718e3744 | 11206 | } |
11207 | ||
11208 | DEFUN (show_bgp_community_list_exact, | |
11209 | show_bgp_community_list_exact_cmd, | |
fee6e4e4 | 11210 | "show bgp community-list (<1-500>|WORD) exact-match", |
718e3744 | 11211 | SHOW_STR |
11212 | BGP_STR | |
11213 | "Display routes matching the community-list\n" | |
fee6e4e4 | 11214 | "community-list number\n" |
718e3744 | 11215 | "community-list name\n" |
11216 | "Exact match of the communities\n") | |
11217 | { | |
50ef26d4 | 11218 | return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST); |
718e3744 | 11219 | } |
11220 | ||
11221 | ALIAS (show_bgp_community_list_exact, | |
11222 | show_bgp_ipv6_community_list_exact_cmd, | |
fee6e4e4 | 11223 | "show bgp ipv6 community-list (<1-500>|WORD) exact-match", |
718e3744 | 11224 | SHOW_STR |
11225 | BGP_STR | |
11226 | "Address family\n" | |
11227 | "Display routes matching the community-list\n" | |
fee6e4e4 | 11228 | "community-list number\n" |
718e3744 | 11229 | "community-list name\n" |
11230 | "Exact match of the communities\n") | |
11231 | ||
11232 | /* old command */ | |
11233 | DEFUN (show_ipv6_bgp_community_list_exact, | |
11234 | show_ipv6_bgp_community_list_exact_cmd, | |
11235 | "show ipv6 bgp community-list WORD exact-match", | |
11236 | SHOW_STR | |
11237 | IPV6_STR | |
11238 | BGP_STR | |
11239 | "Display routes matching the community-list\n" | |
11240 | "community-list name\n" | |
11241 | "Exact match of the communities\n") | |
11242 | { | |
47e9b292 | 11243 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
50ef26d4 | 11244 | return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST); |
718e3744 | 11245 | } |
11246 | ||
11247 | /* old command */ | |
11248 | DEFUN (show_ipv6_mbgp_community_list_exact, | |
11249 | show_ipv6_mbgp_community_list_exact_cmd, | |
11250 | "show ipv6 mbgp community-list WORD exact-match", | |
11251 | SHOW_STR | |
11252 | IPV6_STR | |
11253 | MBGP_STR | |
11254 | "Display routes matching the community-list\n" | |
11255 | "community-list name\n" | |
11256 | "Exact match of the communities\n") | |
11257 | { | |
47e9b292 | 11258 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
50ef26d4 | 11259 | return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_MULTICAST); |
718e3744 | 11260 | } |
11261 | #endif /* HAVE_IPV6 */ | |
6b0655a2 | 11262 | |
94f2b392 | 11263 | static int |
50ef26d4 | 11264 | bgp_show_prefix_longer (struct vty *vty, const char *name, |
11265 | const char *prefix, afi_t afi, | |
718e3744 | 11266 | safi_t safi, enum bgp_show_type type) |
11267 | { | |
11268 | int ret; | |
11269 | struct prefix *p; | |
50ef26d4 | 11270 | struct bgp *bgp = NULL; |
11271 | ||
11272 | if (name && !(bgp = bgp_lookup_by_name(name))) | |
11273 | { | |
11274 | vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE); | |
11275 | return CMD_WARNING; | |
11276 | } | |
718e3744 | 11277 | |
11278 | p = prefix_new(); | |
11279 | ||
11280 | ret = str2prefix (prefix, p); | |
11281 | if (! ret) | |
11282 | { | |
11283 | vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE); | |
11284 | return CMD_WARNING; | |
11285 | } | |
11286 | ||
50ef26d4 | 11287 | ret = bgp_show (vty, bgp, afi, safi, type, p, 0); |
5a646650 | 11288 | prefix_free(p); |
11289 | return ret; | |
718e3744 | 11290 | } |
11291 | ||
11292 | DEFUN (show_ip_bgp_prefix_longer, | |
11293 | show_ip_bgp_prefix_longer_cmd, | |
11294 | "show ip bgp A.B.C.D/M longer-prefixes", | |
11295 | SHOW_STR | |
11296 | IP_STR | |
11297 | BGP_STR | |
11298 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
11299 | "Display route and more specific routes\n") | |
11300 | { | |
50ef26d4 | 11301 | return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, |
11302 | bgp_show_type_prefix_longer); | |
11303 | } | |
11304 | ||
8386ac43 | 11305 | DEFUN (show_ip_bgp_instance_prefix_longer, |
11306 | show_ip_bgp_instance_prefix_longer_cmd, | |
11307 | "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M longer-prefixes", | |
50ef26d4 | 11308 | SHOW_STR |
11309 | IP_STR | |
11310 | BGP_STR | |
8386ac43 | 11311 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 11312 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
11313 | "Display route and more specific routes\n") | |
11314 | { | |
11315 | return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, | |
718e3744 | 11316 | bgp_show_type_prefix_longer); |
11317 | } | |
11318 | ||
11319 | DEFUN (show_ip_bgp_flap_prefix_longer, | |
11320 | show_ip_bgp_flap_prefix_longer_cmd, | |
11321 | "show ip bgp flap-statistics A.B.C.D/M longer-prefixes", | |
11322 | SHOW_STR | |
11323 | IP_STR | |
11324 | BGP_STR | |
11325 | "Display flap statistics of routes\n" | |
11326 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
11327 | "Display route and more specific routes\n") | |
11328 | { | |
50ef26d4 | 11329 | return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, |
718e3744 | 11330 | bgp_show_type_flap_prefix_longer); |
11331 | } | |
11332 | ||
81304aaf B |
11333 | ALIAS (show_ip_bgp_flap_prefix_longer, |
11334 | show_ip_bgp_damp_flap_prefix_longer_cmd, | |
11335 | "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes", | |
11336 | SHOW_STR | |
11337 | IP_STR | |
11338 | BGP_STR | |
11339 | "Display detailed information about dampening\n" | |
11340 | "Display flap statistics of routes\n" | |
11341 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
11342 | "Display route and more specific routes\n") | |
11343 | ||
718e3744 | 11344 | DEFUN (show_ip_bgp_ipv4_prefix_longer, |
11345 | show_ip_bgp_ipv4_prefix_longer_cmd, | |
d02fbbdb | 11346 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M longer-prefixes", |
718e3744 | 11347 | SHOW_STR |
11348 | IP_STR | |
11349 | BGP_STR | |
11350 | "Address family\n" | |
d02fbbdb | 11351 | BGP_SAFI_HELP_STR |
718e3744 | 11352 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
11353 | "Display route and more specific routes\n") | |
11354 | { | |
d02fbbdb LB |
11355 | safi_t safi; |
11356 | safi = bgp_vty_safi_from_arg(argv[0]); | |
11357 | return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, safi, | |
11358 | bgp_show_type_prefix_longer); | |
718e3744 | 11359 | } |
11360 | ||
11361 | DEFUN (show_ip_bgp_flap_address, | |
11362 | show_ip_bgp_flap_address_cmd, | |
11363 | "show ip bgp flap-statistics A.B.C.D", | |
11364 | SHOW_STR | |
11365 | IP_STR | |
11366 | BGP_STR | |
11367 | "Display flap statistics of routes\n" | |
11368 | "Network in the BGP routing table to display\n") | |
11369 | { | |
50ef26d4 | 11370 | return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, |
718e3744 | 11371 | bgp_show_type_flap_address); |
11372 | } | |
11373 | ||
81304aaf B |
11374 | ALIAS (show_ip_bgp_flap_address, |
11375 | show_ip_bgp_damp_flap_address_cmd, | |
11376 | "show ip bgp dampening flap-statistics A.B.C.D", | |
11377 | SHOW_STR | |
11378 | IP_STR | |
11379 | BGP_STR | |
11380 | "Display detailed information about dampening\n" | |
11381 | "Display flap statistics of routes\n" | |
11382 | "Network in the BGP routing table to display\n") | |
11383 | ||
718e3744 | 11384 | DEFUN (show_ip_bgp_flap_prefix, |
11385 | show_ip_bgp_flap_prefix_cmd, | |
11386 | "show ip bgp flap-statistics A.B.C.D/M", | |
11387 | SHOW_STR | |
11388 | IP_STR | |
11389 | BGP_STR | |
11390 | "Display flap statistics of routes\n" | |
11391 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") | |
11392 | { | |
50ef26d4 | 11393 | return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, |
718e3744 | 11394 | bgp_show_type_flap_prefix); |
11395 | } | |
81304aaf B |
11396 | |
11397 | ALIAS (show_ip_bgp_flap_prefix, | |
11398 | show_ip_bgp_damp_flap_prefix_cmd, | |
11399 | "show ip bgp dampening flap-statistics A.B.C.D/M", | |
11400 | SHOW_STR | |
11401 | IP_STR | |
11402 | BGP_STR | |
11403 | "Display detailed information about dampening\n" | |
11404 | "Display flap statistics of routes\n" | |
11405 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") | |
11406 | ||
718e3744 | 11407 | #ifdef HAVE_IPV6 |
11408 | DEFUN (show_bgp_prefix_longer, | |
11409 | show_bgp_prefix_longer_cmd, | |
11410 | "show bgp X:X::X:X/M longer-prefixes", | |
11411 | SHOW_STR | |
11412 | BGP_STR | |
11413 | "IPv6 prefix <network>/<length>\n" | |
11414 | "Display route and more specific routes\n") | |
11415 | { | |
50ef26d4 | 11416 | return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, |
718e3744 | 11417 | bgp_show_type_prefix_longer); |
11418 | } | |
11419 | ||
11420 | ALIAS (show_bgp_prefix_longer, | |
11421 | show_bgp_ipv6_prefix_longer_cmd, | |
11422 | "show bgp ipv6 X:X::X:X/M longer-prefixes", | |
11423 | SHOW_STR | |
11424 | BGP_STR | |
11425 | "Address family\n" | |
11426 | "IPv6 prefix <network>/<length>\n" | |
11427 | "Display route and more specific routes\n") | |
11428 | ||
11429 | /* old command */ | |
11430 | DEFUN (show_ipv6_bgp_prefix_longer, | |
11431 | show_ipv6_bgp_prefix_longer_cmd, | |
11432 | "show ipv6 bgp X:X::X:X/M longer-prefixes", | |
11433 | SHOW_STR | |
11434 | IPV6_STR | |
11435 | BGP_STR | |
11436 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n" | |
11437 | "Display route and more specific routes\n") | |
11438 | { | |
47e9b292 | 11439 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
50ef26d4 | 11440 | return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, |
718e3744 | 11441 | bgp_show_type_prefix_longer); |
11442 | } | |
11443 | ||
11444 | /* old command */ | |
11445 | DEFUN (show_ipv6_mbgp_prefix_longer, | |
11446 | show_ipv6_mbgp_prefix_longer_cmd, | |
11447 | "show ipv6 mbgp X:X::X:X/M longer-prefixes", | |
11448 | SHOW_STR | |
11449 | IPV6_STR | |
11450 | MBGP_STR | |
11451 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n" | |
11452 | "Display route and more specific routes\n") | |
11453 | { | |
47e9b292 | 11454 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
50ef26d4 | 11455 | return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, |
718e3744 | 11456 | bgp_show_type_prefix_longer); |
11457 | } | |
11458 | #endif /* HAVE_IPV6 */ | |
bb46e94f | 11459 | |
94f2b392 | 11460 | static struct peer * |
fd79ac91 | 11461 | peer_lookup_in_view (struct vty *vty, const char *view_name, |
856ca177 | 11462 | const char *ip_str, u_char use_json) |
bb46e94f | 11463 | { |
11464 | int ret; | |
11465 | struct bgp *bgp; | |
11466 | struct peer *peer; | |
11467 | union sockunion su; | |
11468 | ||
11469 | /* BGP structure lookup. */ | |
11470 | if (view_name) | |
11471 | { | |
11472 | bgp = bgp_lookup_by_name (view_name); | |
11473 | if (! bgp) | |
11474 | { | |
856ca177 MS |
11475 | if (use_json) |
11476 | { | |
11477 | json_object *json_no = NULL; | |
11478 | json_no = json_object_new_object(); | |
11479 | json_object_string_add(json_no, "warning", "Can't find BGP view"); | |
11480 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
11481 | json_object_free(json_no); | |
11482 | } | |
11483 | else | |
6aeb9e78 | 11484 | vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE); |
bb46e94f | 11485 | return NULL; |
11486 | } | |
11487 | } | |
5228ad27 | 11488 | else |
bb46e94f | 11489 | { |
11490 | bgp = bgp_get_default (); | |
11491 | if (! bgp) | |
11492 | { | |
856ca177 MS |
11493 | if (use_json) |
11494 | { | |
11495 | json_object *json_no = NULL; | |
11496 | json_no = json_object_new_object(); | |
11497 | json_object_string_add(json_no, "warning", "No BGP process configured"); | |
11498 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
11499 | json_object_free(json_no); | |
11500 | } | |
11501 | else | |
11502 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); | |
bb46e94f | 11503 | return NULL; |
11504 | } | |
11505 | } | |
11506 | ||
11507 | /* Get peer sockunion. */ | |
11508 | ret = str2sockunion (ip_str, &su); | |
11509 | if (ret < 0) | |
11510 | { | |
a80beece DS |
11511 | peer = peer_lookup_by_conf_if (bgp, ip_str); |
11512 | if (!peer) | |
11513 | { | |
04b6bdc0 DW |
11514 | peer = peer_lookup_by_hostname(bgp, ip_str); |
11515 | ||
11516 | if (!peer) | |
856ca177 | 11517 | { |
04b6bdc0 DW |
11518 | if (use_json) |
11519 | { | |
11520 | json_object *json_no = NULL; | |
11521 | json_no = json_object_new_object(); | |
11522 | json_object_string_add(json_no, "malformedAddressOrName", ip_str); | |
11523 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
11524 | json_object_free(json_no); | |
11525 | } | |
11526 | else | |
11527 | vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE); | |
11528 | return NULL; | |
856ca177 | 11529 | } |
a80beece DS |
11530 | } |
11531 | return peer; | |
bb46e94f | 11532 | } |
11533 | ||
11534 | /* Peer structure lookup. */ | |
11535 | peer = peer_lookup (bgp, &su); | |
11536 | if (! peer) | |
11537 | { | |
856ca177 MS |
11538 | if (use_json) |
11539 | { | |
11540 | json_object *json_no = NULL; | |
11541 | json_no = json_object_new_object(); | |
11542 | json_object_string_add(json_no, "warning","No such neighbor"); | |
11543 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
11544 | json_object_free(json_no); | |
11545 | } | |
11546 | else | |
11547 | vty_out (vty, "No such neighbor%s", VTY_NEWLINE); | |
bb46e94f | 11548 | return NULL; |
11549 | } | |
11550 | ||
11551 | return peer; | |
11552 | } | |
6b0655a2 | 11553 | |
2815e61f PJ |
11554 | enum bgp_stats |
11555 | { | |
11556 | BGP_STATS_MAXBITLEN = 0, | |
11557 | BGP_STATS_RIB, | |
11558 | BGP_STATS_PREFIXES, | |
11559 | BGP_STATS_TOTPLEN, | |
11560 | BGP_STATS_UNAGGREGATEABLE, | |
11561 | BGP_STATS_MAX_AGGREGATEABLE, | |
11562 | BGP_STATS_AGGREGATES, | |
11563 | BGP_STATS_SPACE, | |
11564 | BGP_STATS_ASPATH_COUNT, | |
11565 | BGP_STATS_ASPATH_MAXHOPS, | |
11566 | BGP_STATS_ASPATH_TOTHOPS, | |
11567 | BGP_STATS_ASPATH_MAXSIZE, | |
11568 | BGP_STATS_ASPATH_TOTSIZE, | |
11569 | BGP_STATS_ASN_HIGHEST, | |
11570 | BGP_STATS_MAX, | |
11571 | }; | |
11572 | ||
11573 | static const char *table_stats_strs[] = | |
11574 | { | |
11575 | [BGP_STATS_PREFIXES] = "Total Prefixes", | |
11576 | [BGP_STATS_TOTPLEN] = "Average prefix length", | |
11577 | [BGP_STATS_RIB] = "Total Advertisements", | |
11578 | [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes", | |
11579 | [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes", | |
11580 | [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements", | |
11581 | [BGP_STATS_SPACE] = "Address space advertised", | |
11582 | [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths", | |
11583 | [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)", | |
11584 | [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)", | |
11585 | [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)", | |
11586 | [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)", | |
11587 | [BGP_STATS_ASN_HIGHEST] = "Highest public ASN", | |
11588 | [BGP_STATS_MAX] = NULL, | |
11589 | }; | |
11590 | ||
11591 | struct bgp_table_stats | |
11592 | { | |
11593 | struct bgp_table *table; | |
11594 | unsigned long long counts[BGP_STATS_MAX]; | |
11595 | }; | |
11596 | ||
11597 | #if 0 | |
11598 | #define TALLY_SIGFIG 100000 | |
11599 | static unsigned long | |
11600 | ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval) | |
11601 | { | |
11602 | unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG); | |
11603 | unsigned long res = (newtot * TALLY_SIGFIG) / count; | |
11604 | unsigned long ret = newtot / count; | |
11605 | ||
11606 | if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2)) | |
11607 | return ret + 1; | |
11608 | else | |
11609 | return ret; | |
11610 | } | |
11611 | #endif | |
11612 | ||
11613 | static int | |
11614 | bgp_table_stats_walker (struct thread *t) | |
11615 | { | |
11616 | struct bgp_node *rn; | |
11617 | struct bgp_node *top; | |
11618 | struct bgp_table_stats *ts = THREAD_ARG (t); | |
11619 | unsigned int space = 0; | |
11620 | ||
53d9f67a PJ |
11621 | if (!(top = bgp_table_top (ts->table))) |
11622 | return 0; | |
2815e61f PJ |
11623 | |
11624 | switch (top->p.family) | |
11625 | { | |
11626 | case AF_INET: | |
11627 | space = IPV4_MAX_BITLEN; | |
11628 | break; | |
11629 | case AF_INET6: | |
11630 | space = IPV6_MAX_BITLEN; | |
11631 | break; | |
11632 | } | |
11633 | ||
11634 | ts->counts[BGP_STATS_MAXBITLEN] = space; | |
11635 | ||
11636 | for (rn = top; rn; rn = bgp_route_next (rn)) | |
11637 | { | |
11638 | struct bgp_info *ri; | |
67174041 | 11639 | struct bgp_node *prn = bgp_node_parent_nolock (rn); |
2815e61f PJ |
11640 | unsigned int rinum = 0; |
11641 | ||
11642 | if (rn == top) | |
11643 | continue; | |
11644 | ||
11645 | if (!rn->info) | |
11646 | continue; | |
11647 | ||
11648 | ts->counts[BGP_STATS_PREFIXES]++; | |
11649 | ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen; | |
11650 | ||
11651 | #if 0 | |
11652 | ts->counts[BGP_STATS_AVGPLEN] | |
11653 | = ravg_tally (ts->counts[BGP_STATS_PREFIXES], | |
11654 | ts->counts[BGP_STATS_AVGPLEN], | |
11655 | rn->p.prefixlen); | |
11656 | #endif | |
11657 | ||
11658 | /* check if the prefix is included by any other announcements */ | |
11659 | while (prn && !prn->info) | |
67174041 | 11660 | prn = bgp_node_parent_nolock (prn); |
2815e61f PJ |
11661 | |
11662 | if (prn == NULL || prn == top) | |
8383a9bd PJ |
11663 | { |
11664 | ts->counts[BGP_STATS_UNAGGREGATEABLE]++; | |
11665 | /* announced address space */ | |
11666 | if (space) | |
11667 | ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen); | |
11668 | } | |
2815e61f PJ |
11669 | else if (prn->info) |
11670 | ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++; | |
11671 | ||
2815e61f PJ |
11672 | for (ri = rn->info; ri; ri = ri->next) |
11673 | { | |
11674 | rinum++; | |
11675 | ts->counts[BGP_STATS_RIB]++; | |
11676 | ||
11677 | if (ri->attr && | |
11678 | (CHECK_FLAG (ri->attr->flag, | |
11679 | ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE)))) | |
11680 | ts->counts[BGP_STATS_AGGREGATES]++; | |
11681 | ||
11682 | /* as-path stats */ | |
11683 | if (ri->attr && ri->attr->aspath) | |
11684 | { | |
11685 | unsigned int hops = aspath_count_hops (ri->attr->aspath); | |
11686 | unsigned int size = aspath_size (ri->attr->aspath); | |
11687 | as_t highest = aspath_highest (ri->attr->aspath); | |
11688 | ||
11689 | ts->counts[BGP_STATS_ASPATH_COUNT]++; | |
11690 | ||
11691 | if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS]) | |
11692 | ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops; | |
11693 | ||
11694 | if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE]) | |
11695 | ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size; | |
11696 | ||
11697 | ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops; | |
11698 | ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size; | |
11699 | #if 0 | |
11700 | ts->counts[BGP_STATS_ASPATH_AVGHOPS] | |
11701 | = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT], | |
11702 | ts->counts[BGP_STATS_ASPATH_AVGHOPS], | |
11703 | hops); | |
11704 | ts->counts[BGP_STATS_ASPATH_AVGSIZE] | |
11705 | = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT], | |
11706 | ts->counts[BGP_STATS_ASPATH_AVGSIZE], | |
11707 | size); | |
11708 | #endif | |
11709 | if (highest > ts->counts[BGP_STATS_ASN_HIGHEST]) | |
11710 | ts->counts[BGP_STATS_ASN_HIGHEST] = highest; | |
11711 | } | |
11712 | } | |
11713 | } | |
11714 | return 0; | |
11715 | } | |
11716 | ||
11717 | static int | |
11718 | bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi) | |
11719 | { | |
11720 | struct bgp_table_stats ts; | |
11721 | unsigned int i; | |
11722 | ||
11723 | if (!bgp->rib[afi][safi]) | |
11724 | { | |
18200902 | 11725 | vty_out (vty, "%% No RIB exists for the AFI(%d)/SAFI(%d)%s", |
06da0daf | 11726 | afi, safi, VTY_NEWLINE); |
2815e61f PJ |
11727 | return CMD_WARNING; |
11728 | } | |
11729 | ||
11730 | memset (&ts, 0, sizeof (ts)); | |
11731 | ts.table = bgp->rib[afi][safi]; | |
87d4a781 | 11732 | thread_execute (bm->master, bgp_table_stats_walker, &ts, 0); |
bb46e94f | 11733 | |
2815e61f PJ |
11734 | vty_out (vty, "BGP %s RIB statistics%s%s", |
11735 | afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE); | |
11736 | ||
11737 | for (i = 0; i < BGP_STATS_MAX; i++) | |
11738 | { | |
11739 | if (!table_stats_strs[i]) | |
11740 | continue; | |
11741 | ||
11742 | switch (i) | |
11743 | { | |
11744 | #if 0 | |
11745 | case BGP_STATS_ASPATH_AVGHOPS: | |
11746 | case BGP_STATS_ASPATH_AVGSIZE: | |
11747 | case BGP_STATS_AVGPLEN: | |
11748 | vty_out (vty, "%-30s: ", table_stats_strs[i]); | |
11749 | vty_out (vty, "%12.2f", | |
11750 | (float)ts.counts[i] / (float)TALLY_SIGFIG); | |
11751 | break; | |
11752 | #endif | |
11753 | case BGP_STATS_ASPATH_TOTHOPS: | |
11754 | case BGP_STATS_ASPATH_TOTSIZE: | |
11755 | vty_out (vty, "%-30s: ", table_stats_strs[i]); | |
11756 | vty_out (vty, "%12.2f", | |
11757 | ts.counts[i] ? | |
11758 | (float)ts.counts[i] / | |
11759 | (float)ts.counts[BGP_STATS_ASPATH_COUNT] | |
11760 | : 0); | |
11761 | break; | |
11762 | case BGP_STATS_TOTPLEN: | |
11763 | vty_out (vty, "%-30s: ", table_stats_strs[i]); | |
11764 | vty_out (vty, "%12.2f", | |
11765 | ts.counts[i] ? | |
11766 | (float)ts.counts[i] / | |
11767 | (float)ts.counts[BGP_STATS_PREFIXES] | |
11768 | : 0); | |
11769 | break; | |
11770 | case BGP_STATS_SPACE: | |
11771 | vty_out (vty, "%-30s: ", table_stats_strs[i]); | |
11772 | vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE); | |
11773 | if (ts.counts[BGP_STATS_MAXBITLEN] < 9) | |
11774 | break; | |
30a2231a | 11775 | vty_out (vty, "%30s: ", "%% announced "); |
2815e61f PJ |
11776 | vty_out (vty, "%12.2f%s", |
11777 | 100 * (float)ts.counts[BGP_STATS_SPACE] / | |
56395af7 | 11778 | (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]), |
2815e61f PJ |
11779 | VTY_NEWLINE); |
11780 | vty_out (vty, "%30s: ", "/8 equivalent "); | |
11781 | vty_out (vty, "%12.2f%s", | |
11782 | (float)ts.counts[BGP_STATS_SPACE] / | |
11783 | (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)), | |
11784 | VTY_NEWLINE); | |
11785 | if (ts.counts[BGP_STATS_MAXBITLEN] < 25) | |
11786 | break; | |
11787 | vty_out (vty, "%30s: ", "/24 equivalent "); | |
11788 | vty_out (vty, "%12.2f", | |
11789 | (float)ts.counts[BGP_STATS_SPACE] / | |
11790 | (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24))); | |
11791 | break; | |
11792 | default: | |
11793 | vty_out (vty, "%-30s: ", table_stats_strs[i]); | |
11794 | vty_out (vty, "%12llu", ts.counts[i]); | |
11795 | } | |
11796 | ||
11797 | vty_out (vty, "%s", VTY_NEWLINE); | |
11798 | } | |
11799 | return CMD_SUCCESS; | |
11800 | } | |
11801 | ||
11802 | static int | |
11803 | bgp_table_stats_vty (struct vty *vty, const char *name, | |
11804 | const char *afi_str, const char *safi_str) | |
11805 | { | |
11806 | struct bgp *bgp; | |
11807 | afi_t afi; | |
11808 | safi_t safi; | |
11809 | ||
11810 | if (name) | |
11811 | bgp = bgp_lookup_by_name (name); | |
11812 | else | |
11813 | bgp = bgp_get_default (); | |
11814 | ||
11815 | if (!bgp) | |
11816 | { | |
18200902 | 11817 | vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE); |
2815e61f PJ |
11818 | return CMD_WARNING; |
11819 | } | |
d02fbbdb LB |
11820 | afi = bgp_vty_afi_from_arg(afi_str); |
11821 | if (afi == AFI_MAX) | |
2815e61f | 11822 | { |
587ff0fd | 11823 | vty_out (vty, "%% Invalid address family \"%s\"%s", |
2815e61f PJ |
11824 | afi_str, VTY_NEWLINE); |
11825 | return CMD_WARNING; | |
11826 | } | |
d02fbbdb LB |
11827 | safi = bgp_vty_safi_from_arg(safi_str); |
11828 | if (safi == SAFI_MAX) | |
11829 | { | |
11830 | vty_out (vty, "%% Invalid subsequent address family %s%s", | |
11831 | safi_str, VTY_NEWLINE); | |
11832 | return CMD_WARNING; | |
11833 | } | |
2815e61f | 11834 | |
2815e61f PJ |
11835 | return bgp_table_stats (vty, bgp, afi, safi); |
11836 | } | |
11837 | ||
11838 | DEFUN (show_bgp_statistics, | |
11839 | show_bgp_statistics_cmd, | |
d02fbbdb | 11840 | "show bgp "BGP_AFI_SAFI_CMD_STR" statistics", |
2815e61f PJ |
11841 | SHOW_STR |
11842 | BGP_STR | |
d02fbbdb | 11843 | BGP_INSTANCE_HELP_STR |
2815e61f PJ |
11844 | "BGP RIB advertisement statistics\n") |
11845 | { | |
11846 | return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]); | |
11847 | } | |
11848 | ||
2815e61f PJ |
11849 | DEFUN (show_bgp_statistics_view, |
11850 | show_bgp_statistics_view_cmd, | |
d02fbbdb | 11851 | "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" statistics", |
2815e61f PJ |
11852 | SHOW_STR |
11853 | BGP_STR | |
8386ac43 | 11854 | BGP_INSTANCE_HELP_STR |
d02fbbdb | 11855 | BGP_AFI_SAFI_HELP_STR |
2815e61f PJ |
11856 | "BGP RIB advertisement statistics\n") |
11857 | { | |
6aeb9e78 | 11858 | return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]); |
2815e61f PJ |
11859 | } |
11860 | ||
ff7924f6 PJ |
11861 | enum bgp_pcounts |
11862 | { | |
11863 | PCOUNT_ADJ_IN = 0, | |
11864 | PCOUNT_DAMPED, | |
11865 | PCOUNT_REMOVED, | |
11866 | PCOUNT_HISTORY, | |
11867 | PCOUNT_STALE, | |
11868 | PCOUNT_VALID, | |
11869 | PCOUNT_ALL, | |
11870 | PCOUNT_COUNTED, | |
11871 | PCOUNT_PFCNT, /* the figure we display to users */ | |
11872 | PCOUNT_MAX, | |
11873 | }; | |
11874 | ||
11875 | static const char *pcount_strs[] = | |
11876 | { | |
11877 | [PCOUNT_ADJ_IN] = "Adj-in", | |
11878 | [PCOUNT_DAMPED] = "Damped", | |
11879 | [PCOUNT_REMOVED] = "Removed", | |
11880 | [PCOUNT_HISTORY] = "History", | |
11881 | [PCOUNT_STALE] = "Stale", | |
11882 | [PCOUNT_VALID] = "Valid", | |
11883 | [PCOUNT_ALL] = "All RIB", | |
11884 | [PCOUNT_COUNTED] = "PfxCt counted", | |
11885 | [PCOUNT_PFCNT] = "Useable", | |
11886 | [PCOUNT_MAX] = NULL, | |
11887 | }; | |
11888 | ||
2815e61f PJ |
11889 | struct peer_pcounts |
11890 | { | |
11891 | unsigned int count[PCOUNT_MAX]; | |
11892 | const struct peer *peer; | |
11893 | const struct bgp_table *table; | |
11894 | }; | |
11895 | ||
ff7924f6 | 11896 | static int |
2815e61f | 11897 | bgp_peer_count_walker (struct thread *t) |
ff7924f6 PJ |
11898 | { |
11899 | struct bgp_node *rn; | |
2815e61f PJ |
11900 | struct peer_pcounts *pc = THREAD_ARG (t); |
11901 | const struct peer *peer = pc->peer; | |
ff7924f6 | 11902 | |
2815e61f | 11903 | for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn)) |
ff7924f6 PJ |
11904 | { |
11905 | struct bgp_adj_in *ain; | |
2815e61f | 11906 | struct bgp_info *ri; |
ff7924f6 PJ |
11907 | |
11908 | for (ain = rn->adj_in; ain; ain = ain->next) | |
11909 | if (ain->peer == peer) | |
2815e61f | 11910 | pc->count[PCOUNT_ADJ_IN]++; |
ff7924f6 | 11911 | |
ff7924f6 PJ |
11912 | for (ri = rn->info; ri; ri = ri->next) |
11913 | { | |
11914 | char buf[SU_ADDRSTRLEN]; | |
11915 | ||
11916 | if (ri->peer != peer) | |
11917 | continue; | |
11918 | ||
2815e61f | 11919 | pc->count[PCOUNT_ALL]++; |
ff7924f6 PJ |
11920 | |
11921 | if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)) | |
2815e61f | 11922 | pc->count[PCOUNT_DAMPED]++; |
ff7924f6 | 11923 | if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) |
2815e61f | 11924 | pc->count[PCOUNT_HISTORY]++; |
ff7924f6 | 11925 | if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)) |
2815e61f | 11926 | pc->count[PCOUNT_REMOVED]++; |
ff7924f6 | 11927 | if (CHECK_FLAG (ri->flags, BGP_INFO_STALE)) |
2815e61f | 11928 | pc->count[PCOUNT_STALE]++; |
ff7924f6 | 11929 | if (CHECK_FLAG (ri->flags, BGP_INFO_VALID)) |
2815e61f | 11930 | pc->count[PCOUNT_VALID]++; |
1a392d46 | 11931 | if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE)) |
2815e61f | 11932 | pc->count[PCOUNT_PFCNT]++; |
ff7924f6 PJ |
11933 | |
11934 | if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED)) | |
11935 | { | |
2815e61f | 11936 | pc->count[PCOUNT_COUNTED]++; |
1a392d46 | 11937 | if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE)) |
16286195 | 11938 | zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x", |
ff7924f6 PJ |
11939 | peer->host, |
11940 | inet_ntop(rn->p.family, &rn->p.u.prefix, | |
11941 | buf, SU_ADDRSTRLEN), | |
11942 | rn->p.prefixlen, | |
11943 | ri->flags); | |
11944 | } | |
11945 | else | |
11946 | { | |
1a392d46 | 11947 | if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE)) |
16286195 | 11948 | zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x", |
ff7924f6 PJ |
11949 | peer->host, |
11950 | inet_ntop(rn->p.family, &rn->p.u.prefix, | |
11951 | buf, SU_ADDRSTRLEN), | |
11952 | rn->p.prefixlen, | |
11953 | ri->flags); | |
11954 | } | |
11955 | } | |
11956 | } | |
2815e61f PJ |
11957 | return 0; |
11958 | } | |
ff7924f6 | 11959 | |
2815e61f | 11960 | static int |
856ca177 | 11961 | bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json) |
2815e61f PJ |
11962 | { |
11963 | struct peer_pcounts pcounts = { .peer = peer }; | |
11964 | unsigned int i; | |
856ca177 MS |
11965 | json_object *json = NULL; |
11966 | json_object *json_loop = NULL; | |
11967 | ||
11968 | if (use_json) | |
11969 | { | |
11970 | json = json_object_new_object(); | |
11971 | json_loop = json_object_new_object(); | |
11972 | } | |
2815e61f PJ |
11973 | |
11974 | if (!peer || !peer->bgp || !peer->afc[afi][safi] | |
11975 | || !peer->bgp->rib[afi][safi]) | |
11976 | { | |
856ca177 MS |
11977 | if (use_json) |
11978 | { | |
11979 | json_object_string_add(json, "warning", "No such neighbor or address family"); | |
2aac5767 | 11980 | vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE); |
856ca177 MS |
11981 | json_object_free(json); |
11982 | } | |
11983 | else | |
11984 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); | |
11985 | ||
2815e61f PJ |
11986 | return CMD_WARNING; |
11987 | } | |
11988 | ||
11989 | memset (&pcounts, 0, sizeof(pcounts)); | |
11990 | pcounts.peer = peer; | |
11991 | pcounts.table = peer->bgp->rib[afi][safi]; | |
11992 | ||
11993 | /* in-place call via thread subsystem so as to record execution time | |
856ca177 MS |
11994 | * * stats for the thread-walk (i.e. ensure this can't be blamed on |
11995 | * * on just vty_read()). | |
11996 | * */ | |
87d4a781 | 11997 | thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0); |
6410e93a | 11998 | |
856ca177 MS |
11999 | if (use_json) |
12000 | { | |
12001 | json_object_string_add(json, "prefixCountsFor", peer->host); | |
12002 | json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi)); | |
12003 | json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]); | |
12004 | ||
12005 | for (i = 0; i < PCOUNT_MAX; i++) | |
12006 | json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]); | |
ff7924f6 | 12007 | |
856ca177 | 12008 | json_object_object_add(json, "ribTableWalkCounters", json_loop); |
ff7924f6 | 12009 | |
856ca177 MS |
12010 | if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi]) |
12011 | { | |
12012 | json_object_string_add(json, "pfxctDriftFor", peer->host); | |
12013 | json_object_string_add(json, "recommended", "Please report this bug, with the above command output"); | |
12014 | } | |
2aac5767 | 12015 | vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE); |
856ca177 MS |
12016 | json_object_free(json); |
12017 | } | |
12018 | else | |
ff7924f6 | 12019 | { |
04b6bdc0 DW |
12020 | |
12021 | if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME)) | |
12022 | { | |
12023 | vty_out (vty, "Prefix counts for %s/%s, %s%s", | |
12024 | peer->hostname, peer->host, afi_safi_print (afi, safi), | |
12025 | VTY_NEWLINE); | |
12026 | } | |
12027 | else | |
12028 | { | |
12029 | vty_out (vty, "Prefix counts for %s, %s%s", | |
12030 | peer->host, afi_safi_print (afi, safi), VTY_NEWLINE); | |
12031 | } | |
12032 | ||
856ca177 MS |
12033 | vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE); |
12034 | vty_out (vty, "%sCounts from RIB table walk:%s%s", | |
12035 | VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE); | |
12036 | ||
12037 | for (i = 0; i < PCOUNT_MAX; i++) | |
12038 | vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE); | |
12039 | ||
12040 | if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi]) | |
12041 | { | |
12042 | vty_out (vty, "%s [pcount] PfxCt drift!%s", | |
12043 | peer->host, VTY_NEWLINE); | |
12044 | vty_out (vty, "Please report this bug, with the above command output%s", | |
12045 | VTY_NEWLINE); | |
12046 | } | |
ff7924f6 PJ |
12047 | } |
12048 | ||
12049 | return CMD_SUCCESS; | |
12050 | } | |
12051 | ||
12052 | DEFUN (show_ip_bgp_neighbor_prefix_counts, | |
12053 | show_ip_bgp_neighbor_prefix_counts_cmd, | |
856ca177 | 12054 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}", |
ff7924f6 PJ |
12055 | SHOW_STR |
12056 | IP_STR | |
12057 | BGP_STR | |
12058 | "Detailed information on TCP and BGP neighbor connections\n" | |
12059 | "Neighbor to display information about\n" | |
12060 | "Neighbor to display information about\n" | |
a80beece | 12061 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12062 | "Display detailed prefix count information\n" |
12063 | "JavaScript Object Notation\n") | |
ff7924f6 PJ |
12064 | { |
12065 | struct peer *peer; | |
db7c8528 | 12066 | u_char uj = use_json(argc, argv); |
ff7924f6 | 12067 | |
db7c8528 | 12068 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
ff7924f6 PJ |
12069 | if (! peer) |
12070 | return CMD_WARNING; | |
12071 | ||
db7c8528 | 12072 | return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj); |
ff7924f6 PJ |
12073 | } |
12074 | ||
8386ac43 | 12075 | DEFUN (show_ip_bgp_instance_neighbor_prefix_counts, |
12076 | show_ip_bgp_instance_neighbor_prefix_counts_cmd, | |
12077 | "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}", | |
50ef26d4 | 12078 | SHOW_STR |
12079 | IP_STR | |
12080 | BGP_STR | |
8386ac43 | 12081 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 12082 | "Detailed information on TCP and BGP neighbor connections\n" |
12083 | "Neighbor to display information about\n" | |
12084 | "Neighbor to display information about\n" | |
12085 | "Neighbor on bgp configured interface\n" | |
12086 | "Display detailed prefix count information\n" | |
12087 | "JavaScript Object Notation\n") | |
12088 | { | |
12089 | struct peer *peer; | |
12090 | u_char uj = use_json(argc, argv); | |
12091 | ||
12092 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); | |
12093 | if (! peer) | |
12094 | return CMD_WARNING; | |
12095 | ||
12096 | return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj); | |
12097 | } | |
12098 | ||
ff7924f6 PJ |
12099 | DEFUN (show_bgp_ipv6_neighbor_prefix_counts, |
12100 | show_bgp_ipv6_neighbor_prefix_counts_cmd, | |
856ca177 | 12101 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}", |
ff7924f6 PJ |
12102 | SHOW_STR |
12103 | BGP_STR | |
12104 | "Address family\n" | |
12105 | "Detailed information on TCP and BGP neighbor connections\n" | |
12106 | "Neighbor to display information about\n" | |
12107 | "Neighbor to display information about\n" | |
a80beece | 12108 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12109 | "Display detailed prefix count information\n" |
12110 | "JavaScript Object Notation\n") | |
ff7924f6 PJ |
12111 | { |
12112 | struct peer *peer; | |
db7c8528 | 12113 | u_char uj = use_json(argc, argv); |
856ca177 | 12114 | |
db7c8528 | 12115 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
ff7924f6 PJ |
12116 | if (! peer) |
12117 | return CMD_WARNING; | |
12118 | ||
db7c8528 | 12119 | return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj); |
ff7924f6 PJ |
12120 | } |
12121 | ||
8386ac43 | 12122 | DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts, |
12123 | show_bgp_instance_ipv6_neighbor_prefix_counts_cmd, | |
12124 | "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}", | |
50ef26d4 | 12125 | SHOW_STR |
12126 | BGP_STR | |
8386ac43 | 12127 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 12128 | "Address family\n" |
12129 | "Detailed information on TCP and BGP neighbor connections\n" | |
12130 | "Neighbor to display information about\n" | |
12131 | "Neighbor to display information about\n" | |
12132 | "Neighbor on bgp configured interface\n" | |
12133 | "Display detailed prefix count information\n" | |
12134 | "JavaScript Object Notation\n") | |
12135 | { | |
12136 | struct peer *peer; | |
12137 | u_char uj = use_json(argc, argv); | |
12138 | ||
12139 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); | |
12140 | if (! peer) | |
12141 | return CMD_WARNING; | |
12142 | ||
12143 | return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj); | |
12144 | } | |
12145 | ||
ff7924f6 PJ |
12146 | DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts, |
12147 | show_ip_bgp_ipv4_neighbor_prefix_counts_cmd, | |
d02fbbdb | 12148 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}", |
ff7924f6 PJ |
12149 | SHOW_STR |
12150 | IP_STR | |
12151 | BGP_STR | |
12152 | "Address family\n" | |
d02fbbdb | 12153 | BGP_SAFI_HELP_STR |
ff7924f6 PJ |
12154 | "Detailed information on TCP and BGP neighbor connections\n" |
12155 | "Neighbor to display information about\n" | |
12156 | "Neighbor to display information about\n" | |
a80beece | 12157 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12158 | "Display detailed prefix count information\n" |
12159 | "JavaScript Object Notation\n") | |
ff7924f6 PJ |
12160 | { |
12161 | struct peer *peer; | |
db7c8528 | 12162 | u_char uj = use_json(argc, argv); |
ff7924f6 | 12163 | |
db7c8528 | 12164 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
ff7924f6 PJ |
12165 | if (! peer) |
12166 | return CMD_WARNING; | |
12167 | ||
d02fbbdb LB |
12168 | safi_t safi; |
12169 | safi = bgp_vty_safi_from_arg(argv[0]); | |
12170 | return bgp_peer_counts (vty, peer, AFI_IP, safi, uj); | |
ff7924f6 PJ |
12171 | } |
12172 | ||
94f2b392 | 12173 | static void |
718e3744 | 12174 | show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, |
856ca177 | 12175 | int in, const char *rmap_name, u_char use_json, json_object *json) |
718e3744 | 12176 | { |
12177 | struct bgp_table *table; | |
12178 | struct bgp_adj_in *ain; | |
12179 | struct bgp_adj_out *adj; | |
12180 | unsigned long output_count; | |
0b16f239 | 12181 | unsigned long filtered_count; |
718e3744 | 12182 | struct bgp_node *rn; |
12183 | int header1 = 1; | |
12184 | struct bgp *bgp; | |
12185 | int header2 = 1; | |
0b16f239 DS |
12186 | struct attr attr; |
12187 | struct attr_extra extra; | |
12188 | int ret; | |
840fced9 | 12189 | struct update_subgroup *subgrp; |
856ca177 MS |
12190 | json_object *json_scode = NULL; |
12191 | json_object *json_ocode = NULL; | |
12192 | json_object *json_ar = NULL; | |
adbac85e | 12193 | struct peer_af *paf; |
856ca177 MS |
12194 | |
12195 | if (use_json) | |
12196 | { | |
12197 | json_scode = json_object_new_object(); | |
12198 | json_ocode = json_object_new_object(); | |
12199 | json_ar = json_object_new_object(); | |
12200 | ||
12201 | json_object_string_add(json_scode, "suppressed", "s"); | |
12202 | json_object_string_add(json_scode, "damped", "d"); | |
12203 | json_object_string_add(json_scode, "history", "h"); | |
12204 | json_object_string_add(json_scode, "valid", "*"); | |
12205 | json_object_string_add(json_scode, "best", ">"); | |
12206 | json_object_string_add(json_scode, "multipath", "="); | |
12207 | json_object_string_add(json_scode, "internal", "i"); | |
12208 | json_object_string_add(json_scode, "ribFailure", "r"); | |
12209 | json_object_string_add(json_scode, "stale", "S"); | |
12210 | json_object_string_add(json_scode, "removed", "R"); | |
12211 | ||
12212 | json_object_string_add(json_ocode, "igp", "i"); | |
12213 | json_object_string_add(json_ocode, "egp", "e"); | |
12214 | json_object_string_add(json_ocode, "incomplete", "?"); | |
12215 | } | |
718e3744 | 12216 | |
bb46e94f | 12217 | bgp = peer->bgp; |
718e3744 | 12218 | |
12219 | if (! bgp) | |
856ca177 MS |
12220 | { |
12221 | if (use_json) | |
12222 | { | |
12223 | json_object_string_add(json, "alert", "no BGP"); | |
2aac5767 | 12224 | vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE); |
856ca177 MS |
12225 | json_object_free(json); |
12226 | } | |
12227 | else | |
12228 | vty_out (vty, "%% No bgp%s", VTY_NEWLINE); | |
12229 | return; | |
12230 | } | |
718e3744 | 12231 | |
12232 | table = bgp->rib[afi][safi]; | |
12233 | ||
0b16f239 | 12234 | output_count = filtered_count = 0; |
840fced9 | 12235 | subgrp = peer_subgroup(peer, afi, safi); |
47fc97cc | 12236 | |
840fced9 | 12237 | if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE)) |
718e3744 | 12238 | { |
856ca177 MS |
12239 | if (use_json) |
12240 | { | |
12241 | json_object_int_add(json, "bgpTableVersion", table->version); | |
12242 | json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id)); | |
12243 | json_object_object_add(json, "bgpStatusCodes", json_scode); | |
12244 | json_object_object_add(json, "bgpOriginCodes", json_ocode); | |
12245 | json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0"); | |
12246 | } | |
12247 | else | |
12248 | { | |
12249 | vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE); | |
12250 | vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); | |
12251 | vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); | |
718e3744 | 12252 | |
856ca177 MS |
12253 | vty_out (vty, "Originating default network 0.0.0.0%s%s", |
12254 | VTY_NEWLINE, VTY_NEWLINE); | |
12255 | } | |
718e3744 | 12256 | header1 = 0; |
12257 | } | |
12258 | ||
0b16f239 | 12259 | attr.extra = &extra; |
718e3744 | 12260 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) |
856ca177 MS |
12261 | { |
12262 | if (in) | |
12263 | { | |
12264 | for (ain = rn->adj_in; ain; ain = ain->next) | |
12265 | { | |
12266 | if (ain->peer == peer) | |
12267 | { | |
12268 | if (header1) | |
12269 | { | |
12270 | if (use_json) | |
12271 | { | |
12272 | json_object_int_add(json, "bgpTableVersion", 0); | |
12273 | json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id)); | |
12274 | json_object_object_add(json, "bgpStatusCodes", json_scode); | |
12275 | json_object_object_add(json, "bgpOriginCodes", json_ocode); | |
12276 | } | |
12277 | else | |
12278 | { | |
12279 | vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE); | |
12280 | vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); | |
12281 | vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); | |
12282 | } | |
12283 | header1 = 0; | |
12284 | } | |
12285 | if (header2) | |
12286 | { | |
12287 | if (!use_json) | |
12288 | vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE); | |
12289 | header2 = 0; | |
12290 | } | |
12291 | if (ain->attr) | |
12292 | { | |
12293 | bgp_attr_dup(&attr, ain->attr); | |
12294 | if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY) | |
12295 | { | |
12296 | route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar); | |
12297 | output_count++; | |
12298 | } | |
12299 | else | |
12300 | filtered_count++; | |
12301 | } | |
12302 | } | |
12303 | } | |
12304 | } | |
12305 | else | |
12306 | { | |
adbac85e DW |
12307 | for (adj = rn->adj_out; adj; adj = adj->next) |
12308 | SUBGRP_FOREACH_PEER(adj->subgroup, paf) | |
12309 | if (paf->peer == peer) | |
856ca177 | 12310 | { |
adbac85e | 12311 | if (header1) |
856ca177 | 12312 | { |
adbac85e DW |
12313 | if (use_json) |
12314 | { | |
12315 | json_object_int_add(json, "bgpTableVersion", table->version); | |
12316 | json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id)); | |
12317 | json_object_object_add(json, "bgpStatusCodes", json_scode); | |
12318 | json_object_object_add(json, "bgpOriginCodes", json_ocode); | |
12319 | } | |
12320 | else | |
12321 | { | |
12322 | vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, | |
12323 | inet_ntoa (bgp->router_id), VTY_NEWLINE); | |
12324 | vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); | |
12325 | vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); | |
12326 | } | |
12327 | header1 = 0; | |
856ca177 | 12328 | } |
adbac85e DW |
12329 | |
12330 | if (header2) | |
856ca177 | 12331 | { |
adbac85e DW |
12332 | if (!use_json) |
12333 | vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE); | |
12334 | header2 = 0; | |
856ca177 | 12335 | } |
adbac85e DW |
12336 | |
12337 | if (adj->attr) | |
856ca177 | 12338 | { |
adbac85e DW |
12339 | bgp_attr_dup(&attr, adj->attr); |
12340 | ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name); | |
12341 | if (ret != RMAP_DENY) | |
12342 | { | |
12343 | route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar); | |
12344 | output_count++; | |
12345 | } | |
12346 | else | |
12347 | filtered_count++; | |
856ca177 | 12348 | } |
856ca177 | 12349 | } |
856ca177 MS |
12350 | } |
12351 | } | |
12352 | if (use_json) | |
12353 | json_object_object_add(json, "advertisedRoutes", json_ar); | |
47fc97cc | 12354 | |
718e3744 | 12355 | if (output_count != 0) |
856ca177 MS |
12356 | { |
12357 | if (use_json) | |
12358 | json_object_int_add(json, "totalPrefixCounter", output_count); | |
12359 | else | |
12360 | vty_out (vty, "%sTotal number of prefixes %ld%s", | |
12361 | VTY_NEWLINE, output_count, VTY_NEWLINE); | |
12362 | } | |
12363 | if (use_json) | |
12364 | { | |
2aac5767 | 12365 | vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE); |
856ca177 MS |
12366 | json_object_free(json); |
12367 | } | |
12368 | ||
718e3744 | 12369 | } |
12370 | ||
94f2b392 | 12371 | static int |
47fc97cc | 12372 | peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, |
856ca177 MS |
12373 | int in, const char *rmap_name, u_char use_json) |
12374 | { | |
12375 | json_object *json = NULL; | |
12376 | ||
12377 | if (use_json) | |
12378 | json = json_object_new_object(); | |
12379 | ||
12380 | if (!peer || !peer->afc[afi][safi]) | |
718e3744 | 12381 | { |
856ca177 MS |
12382 | if (use_json) |
12383 | { | |
12384 | json_object_string_add(json, "warning", "No such neighbor or address family"); | |
2aac5767 | 12385 | vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE); |
856ca177 MS |
12386 | json_object_free(json); |
12387 | } | |
12388 | else | |
12389 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); | |
12390 | ||
718e3744 | 12391 | return CMD_WARNING; |
12392 | } | |
12393 | ||
856ca177 | 12394 | if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)) |
718e3744 | 12395 | { |
856ca177 MS |
12396 | if (use_json) |
12397 | { | |
12398 | json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled"); | |
2aac5767 | 12399 | vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE); |
856ca177 MS |
12400 | json_object_free(json); |
12401 | } | |
12402 | else | |
12403 | vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE); | |
12404 | ||
718e3744 | 12405 | return CMD_WARNING; |
12406 | } | |
12407 | ||
856ca177 | 12408 | show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json); |
718e3744 | 12409 | |
12410 | return CMD_SUCCESS; | |
12411 | } | |
12412 | ||
8386ac43 | 12413 | DEFUN (show_ip_bgp_instance_neighbor_advertised_route, |
12414 | show_ip_bgp_instance_neighbor_advertised_route_cmd, | |
12415 | "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", | |
718e3744 | 12416 | SHOW_STR |
12417 | IP_STR | |
12418 | BGP_STR | |
8386ac43 | 12419 | BGP_INSTANCE_HELP_STR |
718e3744 | 12420 | "Detailed information on TCP and BGP neighbor connections\n" |
12421 | "Neighbor to display information about\n" | |
12422 | "Neighbor to display information about\n" | |
856ca177 MS |
12423 | "Display the routes advertised to a BGP neighbor\n" |
12424 | "JavaScript Object Notation\n") | |
718e3744 | 12425 | { |
bb46e94f | 12426 | struct peer *peer; |
db7c8528 | 12427 | u_char uj = use_json(argc, argv); |
856ca177 | 12428 | |
6aeb9e78 DS |
12429 | if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) |
12430 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); | |
2a71e9ce | 12431 | else |
6aeb9e78 | 12432 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
2a71e9ce | 12433 | |
bb46e94f | 12434 | if (! peer) |
12435 | return CMD_WARNING; | |
0b16f239 | 12436 | |
db7c8528 | 12437 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj); |
718e3744 | 12438 | } |
12439 | ||
0b16f239 | 12440 | DEFUN (show_ip_bgp_neighbor_advertised_route, |
2a71e9ce | 12441 | show_ip_bgp_neighbor_advertised_route_cmd, |
856ca177 | 12442 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", |
2a71e9ce TP |
12443 | SHOW_STR |
12444 | IP_STR | |
12445 | BGP_STR | |
12446 | "Detailed information on TCP and BGP neighbor connections\n" | |
12447 | "Neighbor to display information about\n" | |
12448 | "Neighbor to display information about\n" | |
a80beece | 12449 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12450 | "Display the routes advertised to a BGP neighbor\n" |
12451 | "JavaScript Object Notation\n") | |
2a71e9ce | 12452 | |
0b16f239 DS |
12453 | { |
12454 | struct peer *peer; | |
ffd0c037 | 12455 | const char *rmap_name = NULL; |
db7c8528 | 12456 | u_char uj = use_json(argc, argv); |
0b16f239 | 12457 | |
db7c8528 | 12458 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
0b16f239 DS |
12459 | |
12460 | if (! peer) | |
12461 | return CMD_WARNING; | |
12462 | ||
856ca177 MS |
12463 | if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0) |
12464 | || (argc == 3)) | |
0b16f239 DS |
12465 | rmap_name = argv[1]; |
12466 | ||
db7c8528 | 12467 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj); |
0b16f239 DS |
12468 | } |
12469 | ||
12470 | ALIAS (show_ip_bgp_neighbor_advertised_route, | |
12471 | show_ip_bgp_neighbor_advertised_route_rmap_cmd, | |
856ca177 | 12472 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}", |
0b16f239 DS |
12473 | SHOW_STR |
12474 | IP_STR | |
12475 | BGP_STR | |
12476 | "Detailed information on TCP and BGP neighbor connections\n" | |
12477 | "Neighbor to display information about\n" | |
12478 | "Neighbor to display information about\n" | |
12479 | "Neighbor on bgp configured interface\n" | |
856ca177 MS |
12480 | "Display the routes advertised to a BGP neighbor\n" |
12481 | "JavaScript Object Notation\n") | |
0b16f239 | 12482 | |
8386ac43 | 12483 | ALIAS (show_ip_bgp_instance_neighbor_advertised_route, |
12484 | show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd, | |
12485 | "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}", | |
50ef26d4 | 12486 | SHOW_STR |
12487 | IP_STR | |
12488 | BGP_STR | |
8386ac43 | 12489 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 12490 | "Detailed information on TCP and BGP neighbor connections\n" |
12491 | "Neighbor to display information about\n" | |
12492 | "Neighbor to display information about\n" | |
12493 | "Neighbor on bgp configured interface\n" | |
12494 | "Display the routes advertised to a BGP neighbor\n" | |
12495 | "JavaScript Object Notation\n") | |
718e3744 | 12496 | DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route, |
12497 | show_ip_bgp_ipv4_neighbor_advertised_route_cmd, | |
d02fbbdb | 12498 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", |
718e3744 | 12499 | SHOW_STR |
12500 | IP_STR | |
12501 | BGP_STR | |
12502 | "Address family\n" | |
d02fbbdb | 12503 | BGP_SAFI_HELP_STR |
718e3744 | 12504 | "Detailed information on TCP and BGP neighbor connections\n" |
12505 | "Neighbor to display information about\n" | |
12506 | "Neighbor to display information about\n" | |
a80beece | 12507 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12508 | "Display the routes advertised to a BGP neighbor\n" |
12509 | "JavaScript Object Notation\n") | |
718e3744 | 12510 | { |
bb46e94f | 12511 | struct peer *peer; |
ffd0c037 | 12512 | const char *rmap_name = NULL; |
d02fbbdb LB |
12513 | safi_t safi; |
12514 | ||
db7c8528 | 12515 | u_char uj = use_json(argc, argv); |
856ca177 | 12516 | |
db7c8528 | 12517 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
bb46e94f | 12518 | if (! peer) |
12519 | return CMD_WARNING; | |
12520 | ||
856ca177 | 12521 | if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) |
0b16f239 DS |
12522 | rmap_name = argv[2]; |
12523 | ||
d02fbbdb LB |
12524 | safi = bgp_vty_safi_from_arg(argv[0]); |
12525 | return peer_adj_routes (vty, peer, AFI_IP, safi, 0, rmap_name, uj); | |
718e3744 | 12526 | } |
12527 | ||
0b16f239 DS |
12528 | ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route, |
12529 | show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd, | |
d02fbbdb | 12530 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}", |
0b16f239 DS |
12531 | SHOW_STR |
12532 | IP_STR | |
12533 | BGP_STR | |
12534 | "Address family\n" | |
d02fbbdb | 12535 | BGP_SAFI_HELP_STR |
0b16f239 DS |
12536 | "Detailed information on TCP and BGP neighbor connections\n" |
12537 | "Neighbor to display information about\n" | |
12538 | "Neighbor to display information about\n" | |
12539 | "Neighbor on bgp configured interface\n" | |
12540 | "Display the routes advertised to a BGP neighbor\n" | |
856ca177 MS |
12541 | "Route-map to control what is displayed\n" |
12542 | "JavaScript Object Notation\n") | |
0b16f239 | 12543 | |
718e3744 | 12544 | #ifdef HAVE_IPV6 |
8386ac43 | 12545 | DEFUN (show_bgp_instance_neighbor_advertised_route, |
12546 | show_bgp_instance_neighbor_advertised_route_cmd, | |
12547 | "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", | |
718e3744 | 12548 | SHOW_STR |
12549 | BGP_STR | |
8386ac43 | 12550 | BGP_INSTANCE_HELP_STR |
718e3744 | 12551 | "Detailed information on TCP and BGP neighbor connections\n" |
12552 | "Neighbor to display information about\n" | |
12553 | "Neighbor to display information about\n" | |
a80beece | 12554 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12555 | "Display the routes advertised to a BGP neighbor\n" |
12556 | "JavaScript Object Notation\n") | |
718e3744 | 12557 | { |
bb46e94f | 12558 | struct peer *peer; |
db7c8528 | 12559 | u_char uj = use_json(argc, argv); |
856ca177 | 12560 | |
6aeb9e78 DS |
12561 | if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) |
12562 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); | |
bb46e94f | 12563 | else |
6aeb9e78 | 12564 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
bb46e94f | 12565 | |
12566 | if (! peer) | |
0b16f239 | 12567 | return CMD_WARNING; |
bb46e94f | 12568 | |
db7c8528 | 12569 | return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj); |
47fc97cc DS |
12570 | } |
12571 | ||
8386ac43 | 12572 | ALIAS (show_bgp_instance_neighbor_advertised_route, |
12573 | show_bgp_instance_ipv6_neighbor_advertised_route_cmd, | |
12574 | "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", | |
0b16f239 DS |
12575 | SHOW_STR |
12576 | BGP_STR | |
8386ac43 | 12577 | BGP_INSTANCE_HELP_STR |
0b16f239 DS |
12578 | "Address family\n" |
12579 | "Detailed information on TCP and BGP neighbor connections\n" | |
12580 | "Neighbor to display information about\n" | |
12581 | "Neighbor to display information about\n" | |
12582 | "Neighbor on bgp configured interface\n" | |
856ca177 MS |
12583 | "Display the routes advertised to a BGP neighbor\n" |
12584 | "JavaScript Object Notation\n") | |
0b16f239 | 12585 | |
0b16f239 DS |
12586 | DEFUN (show_bgp_neighbor_advertised_route, |
12587 | show_bgp_neighbor_advertised_route_cmd, | |
856ca177 | 12588 | "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", |
bb46e94f | 12589 | SHOW_STR |
12590 | BGP_STR | |
bb46e94f | 12591 | "Detailed information on TCP and BGP neighbor connections\n" |
12592 | "Neighbor to display information about\n" | |
12593 | "Neighbor to display information about\n" | |
a80beece | 12594 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12595 | "Display the routes advertised to a BGP neighbor\n" |
12596 | "JavaScript Object Notation\n") | |
0b16f239 | 12597 | |
bb46e94f | 12598 | { |
12599 | struct peer *peer; | |
ffd0c037 | 12600 | const char *rmap_name = NULL; |
db7c8528 | 12601 | u_char uj = use_json(argc, argv); |
bb46e94f | 12602 | |
db7c8528 | 12603 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
856ca177 MS |
12604 | |
12605 | if (!peer) | |
bb46e94f | 12606 | return CMD_WARNING; |
12607 | ||
856ca177 | 12608 | if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)) |
0b16f239 DS |
12609 | rmap_name = argv[1]; |
12610 | ||
db7c8528 | 12611 | return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj); |
718e3744 | 12612 | } |
12613 | ||
0b16f239 DS |
12614 | ALIAS (show_bgp_neighbor_advertised_route, |
12615 | show_bgp_ipv6_neighbor_advertised_route_cmd, | |
856ca177 | 12616 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", |
718e3744 | 12617 | SHOW_STR |
12618 | BGP_STR | |
12619 | "Address family\n" | |
12620 | "Detailed information on TCP and BGP neighbor connections\n" | |
12621 | "Neighbor to display information about\n" | |
12622 | "Neighbor to display information about\n" | |
a80beece | 12623 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12624 | "Display the routes advertised to a BGP neighbor\n" |
12625 | "JavaScript Object Notation\n") | |
718e3744 | 12626 | |
12627 | /* old command */ | |
0b16f239 | 12628 | ALIAS (show_bgp_neighbor_advertised_route, |
718e3744 | 12629 | ipv6_bgp_neighbor_advertised_route_cmd, |
856ca177 | 12630 | "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", |
718e3744 | 12631 | SHOW_STR |
12632 | IPV6_STR | |
12633 | BGP_STR | |
12634 | "Detailed information on TCP and BGP neighbor connections\n" | |
12635 | "Neighbor to display information about\n" | |
12636 | "Neighbor to display information about\n" | |
a80beece | 12637 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12638 | "Display the routes advertised to a BGP neighbor\n" |
12639 | "JavaScript Object Notation\n") | |
bb46e94f | 12640 | |
718e3744 | 12641 | /* old command */ |
12642 | DEFUN (ipv6_mbgp_neighbor_advertised_route, | |
12643 | ipv6_mbgp_neighbor_advertised_route_cmd, | |
856ca177 | 12644 | "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", |
718e3744 | 12645 | SHOW_STR |
12646 | IPV6_STR | |
12647 | MBGP_STR | |
12648 | "Detailed information on TCP and BGP neighbor connections\n" | |
12649 | "Neighbor to display information about\n" | |
12650 | "Neighbor to display information about\n" | |
a80beece DS |
12651 | "Neighbor on bgp configured interface\n" |
12652 | "Neighbor on bgp configured interface\n" | |
856ca177 MS |
12653 | "Display the routes advertised to a BGP neighbor\n" |
12654 | "JavaScript Object Notation\n") | |
718e3744 | 12655 | { |
bb46e94f | 12656 | struct peer *peer; |
db7c8528 | 12657 | u_char uj = use_json(argc, argv); |
856ca177 | 12658 | |
db7c8528 | 12659 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
bb46e94f | 12660 | if (! peer) |
856ca177 | 12661 | return CMD_WARNING; |
bb46e94f | 12662 | |
47e9b292 | 12663 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
db7c8528 | 12664 | return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj); |
718e3744 | 12665 | } |
12666 | #endif /* HAVE_IPV6 */ | |
6b0655a2 | 12667 | |
8386ac43 | 12668 | DEFUN (show_bgp_instance_neighbor_received_routes, |
12669 | show_bgp_instance_neighbor_received_routes_cmd, | |
12670 | "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", | |
0b16f239 DS |
12671 | SHOW_STR |
12672 | BGP_STR | |
8386ac43 | 12673 | BGP_INSTANCE_HELP_STR |
0b16f239 DS |
12674 | "Detailed information on TCP and BGP neighbor connections\n" |
12675 | "Neighbor to display information about\n" | |
12676 | "Neighbor to display information about\n" | |
12677 | "Neighbor on bgp configured interface\n" | |
856ca177 MS |
12678 | "Display the received routes from neighbor\n" |
12679 | "JavaScript Object Notation\n") | |
0b16f239 DS |
12680 | { |
12681 | struct peer *peer; | |
db7c8528 | 12682 | u_char uj = use_json(argc, argv); |
856ca177 | 12683 | |
50ef26d4 | 12684 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); |
0b16f239 DS |
12685 | if (! peer) |
12686 | return CMD_WARNING; | |
12687 | ||
db7c8528 | 12688 | return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj); |
0b16f239 DS |
12689 | } |
12690 | ||
8386ac43 | 12691 | DEFUN (show_ip_bgp_instance_neighbor_received_routes, |
12692 | show_ip_bgp_instance_neighbor_received_routes_cmd, | |
12693 | "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", | |
718e3744 | 12694 | SHOW_STR |
12695 | IP_STR | |
12696 | BGP_STR | |
8386ac43 | 12697 | BGP_INSTANCE_HELP_STR |
718e3744 | 12698 | "Detailed information on TCP and BGP neighbor connections\n" |
12699 | "Neighbor to display information about\n" | |
12700 | "Neighbor to display information about\n" | |
a80beece | 12701 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12702 | "Display the received routes from neighbor\n" |
12703 | "JavaScript Object Notation\n") | |
718e3744 | 12704 | { |
bb46e94f | 12705 | struct peer *peer; |
db7c8528 | 12706 | u_char uj = use_json(argc, argv); |
856ca177 | 12707 | |
50ef26d4 | 12708 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); |
bb46e94f | 12709 | if (! peer) |
12710 | return CMD_WARNING; | |
12711 | ||
db7c8528 | 12712 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj); |
718e3744 | 12713 | } |
12714 | ||
8386ac43 | 12715 | ALIAS (show_bgp_instance_neighbor_received_routes, |
12716 | show_bgp_instance_ipv6_neighbor_received_routes_cmd, | |
12717 | "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", | |
0b16f239 DS |
12718 | SHOW_STR |
12719 | BGP_STR | |
8386ac43 | 12720 | BGP_INSTANCE_HELP_STR |
0b16f239 DS |
12721 | "Address family\n" |
12722 | "Detailed information on TCP and BGP neighbor connections\n" | |
12723 | "Neighbor to display information about\n" | |
12724 | "Neighbor to display information about\n" | |
12725 | "Neighbor on bgp configured interface\n" | |
856ca177 MS |
12726 | "Display the received routes from neighbor\n" |
12727 | "JavaScript Object Notation\n") | |
0b16f239 DS |
12728 | |
12729 | DEFUN (show_ip_bgp_neighbor_received_routes, | |
2a71e9ce | 12730 | show_ip_bgp_neighbor_received_routes_cmd, |
856ca177 | 12731 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", |
2a71e9ce TP |
12732 | SHOW_STR |
12733 | IP_STR | |
12734 | BGP_STR | |
12735 | "Detailed information on TCP and BGP neighbor connections\n" | |
12736 | "Neighbor to display information about\n" | |
12737 | "Neighbor to display information about\n" | |
a80beece | 12738 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12739 | "Display the received routes from neighbor\n" |
12740 | "JavaScript Object Notation\n") | |
2a71e9ce | 12741 | |
0b16f239 DS |
12742 | { |
12743 | struct peer *peer; | |
ffd0c037 | 12744 | const char *rmap_name = NULL; |
db7c8528 | 12745 | u_char uj = use_json(argc, argv); |
0b16f239 | 12746 | |
db7c8528 | 12747 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
0b16f239 DS |
12748 | |
12749 | if (! peer) | |
12750 | return CMD_WARNING; | |
12751 | ||
856ca177 | 12752 | if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)) |
0b16f239 DS |
12753 | rmap_name = argv[1]; |
12754 | ||
db7c8528 | 12755 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj); |
0b16f239 DS |
12756 | } |
12757 | ||
12758 | ALIAS (show_ip_bgp_neighbor_received_routes, | |
12759 | show_ip_bgp_neighbor_received_routes_rmap_cmd, | |
856ca177 | 12760 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}", |
0b16f239 DS |
12761 | SHOW_STR |
12762 | IP_STR | |
12763 | BGP_STR | |
12764 | "Detailed information on TCP and BGP neighbor connections\n" | |
12765 | "Neighbor to display information about\n" | |
12766 | "Neighbor to display information about\n" | |
12767 | "Neighbor on bgp configured interface\n" | |
856ca177 MS |
12768 | "Display the received routes from neighbor\n" |
12769 | "JavaScript Object Notation\n") | |
0b16f239 | 12770 | |
8386ac43 | 12771 | ALIAS (show_ip_bgp_instance_neighbor_received_routes, |
12772 | show_ip_bgp_instance_neighbor_received_routes_rmap_cmd, | |
12773 | "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}", | |
50ef26d4 | 12774 | SHOW_STR |
12775 | IP_STR | |
12776 | BGP_STR | |
8386ac43 | 12777 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 12778 | "Detailed information on TCP and BGP neighbor connections\n" |
12779 | "Neighbor to display information about\n" | |
12780 | "Neighbor to display information about\n" | |
12781 | "Neighbor on bgp configured interface\n" | |
12782 | "Display the received routes from neighbor\n" | |
12783 | "JavaScript Object Notation\n") | |
12784 | ||
718e3744 | 12785 | DEFUN (show_ip_bgp_ipv4_neighbor_received_routes, |
12786 | show_ip_bgp_ipv4_neighbor_received_routes_cmd, | |
d02fbbdb | 12787 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", |
718e3744 | 12788 | SHOW_STR |
12789 | IP_STR | |
12790 | BGP_STR | |
12791 | "Address family\n" | |
d02fbbdb | 12792 | BGP_SAFI_HELP_STR |
718e3744 | 12793 | "Detailed information on TCP and BGP neighbor connections\n" |
12794 | "Neighbor to display information about\n" | |
12795 | "Neighbor to display information about\n" | |
a80beece | 12796 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12797 | "Display the received routes from neighbor\n" |
12798 | "JavaScript Object Notation\n") | |
718e3744 | 12799 | { |
bb46e94f | 12800 | struct peer *peer; |
ffd0c037 | 12801 | const char *rmap_name = NULL; |
d02fbbdb | 12802 | safi_t safi; |
db7c8528 | 12803 | u_char uj = use_json(argc, argv); |
bb46e94f | 12804 | |
db7c8528 | 12805 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
bb46e94f | 12806 | if (! peer) |
12807 | return CMD_WARNING; | |
0b16f239 | 12808 | |
856ca177 | 12809 | if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) |
0b16f239 DS |
12810 | rmap_name = argv[2]; |
12811 | ||
d02fbbdb LB |
12812 | safi = bgp_vty_safi_from_arg(argv[0]); |
12813 | return peer_adj_routes (vty, peer, AFI_IP, safi, 1, rmap_name, uj); | |
718e3744 | 12814 | } |
12815 | ||
0b16f239 DS |
12816 | ALIAS (show_ip_bgp_ipv4_neighbor_received_routes, |
12817 | show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd, | |
d02fbbdb | 12818 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}", |
0b16f239 DS |
12819 | SHOW_STR |
12820 | IP_STR | |
12821 | BGP_STR | |
12822 | "Address family\n" | |
d02fbbdb | 12823 | BGP_SAFI_HELP_STR |
0b16f239 DS |
12824 | "Detailed information on TCP and BGP neighbor connections\n" |
12825 | "Neighbor to display information about\n" | |
12826 | "Neighbor to display information about\n" | |
12827 | "Neighbor on bgp configured interface\n" | |
856ca177 MS |
12828 | "Display the received routes from neighbor\n" |
12829 | "JavaScript Object Notation\n") | |
0b16f239 | 12830 | |
8386ac43 | 12831 | DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes, |
12832 | show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd, | |
d02fbbdb | 12833 | "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}", |
95cbbd2a ML |
12834 | SHOW_STR |
12835 | BGP_STR | |
8386ac43 | 12836 | BGP_INSTANCE_HELP_STR |
d02fbbdb | 12837 | BGP_AFI_SAFI_HELP_STR |
95cbbd2a ML |
12838 | "Detailed information on TCP and BGP neighbor connections\n" |
12839 | "Neighbor to display information about\n" | |
12840 | "Neighbor to display information about\n" | |
a80beece | 12841 | "Neighbor on bgp configured interface\n" |
95cbbd2a | 12842 | "Display the advertised routes to neighbor\n" |
856ca177 MS |
12843 | "Display the received routes from neighbor\n" |
12844 | "JavaScript Object Notation\n") | |
95cbbd2a ML |
12845 | { |
12846 | int afi; | |
12847 | int safi; | |
12848 | int in; | |
12849 | struct peer *peer; | |
db7c8528 | 12850 | u_char uj = use_json(argc, argv); |
856ca177 | 12851 | |
6aeb9e78 | 12852 | peer = peer_lookup_in_view (vty, argv[1], argv[4], uj); |
95cbbd2a ML |
12853 | |
12854 | if (! peer) | |
12855 | return CMD_WARNING; | |
12856 | ||
d02fbbdb LB |
12857 | afi = bgp_vty_safi_from_arg(argv[2]); |
12858 | safi = bgp_vty_safi_from_arg(argv[3]); | |
6aeb9e78 | 12859 | in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0; |
95cbbd2a | 12860 | |
db7c8528 | 12861 | return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj); |
95cbbd2a ML |
12862 | } |
12863 | ||
718e3744 | 12864 | DEFUN (show_ip_bgp_neighbor_received_prefix_filter, |
12865 | show_ip_bgp_neighbor_received_prefix_filter_cmd, | |
856ca177 | 12866 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}", |
718e3744 | 12867 | SHOW_STR |
12868 | IP_STR | |
12869 | BGP_STR | |
12870 | "Detailed information on TCP and BGP neighbor connections\n" | |
12871 | "Neighbor to display information about\n" | |
12872 | "Neighbor to display information about\n" | |
a80beece | 12873 | "Neighbor on bgp configured interface\n" |
718e3744 | 12874 | "Display information received from a BGP neighbor\n" |
856ca177 MS |
12875 | "Display the prefixlist filter\n" |
12876 | "JavaScript Object Notation\n") | |
718e3744 | 12877 | { |
12878 | char name[BUFSIZ]; | |
c63b83fe | 12879 | union sockunion su; |
718e3744 | 12880 | struct peer *peer; |
c63b83fe | 12881 | int count, ret; |
db7c8528 | 12882 | u_char uj = use_json(argc, argv); |
718e3744 | 12883 | |
c63b83fe JBD |
12884 | ret = str2sockunion (argv[0], &su); |
12885 | if (ret < 0) | |
12886 | { | |
a80beece | 12887 | peer = peer_lookup_by_conf_if (NULL, argv[0]); |
856ca177 | 12888 | if (! peer) |
a80beece | 12889 | { |
db7c8528 | 12890 | if (uj) |
856ca177 MS |
12891 | { |
12892 | json_object *json_no = NULL; | |
12893 | json_object *json_sub = NULL; | |
12894 | json_no = json_object_new_object(); | |
12895 | json_sub = json_object_new_object(); | |
12896 | json_object_string_add(json_no, "warning", "Malformed address or name"); | |
12897 | json_object_string_add(json_sub, "warningCause", argv[0]); | |
12898 | json_object_object_add(json_no, "detail", json_sub); | |
12899 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
12900 | json_object_free(json_no); | |
12901 | } | |
12902 | else | |
12903 | vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE); | |
a80beece DS |
12904 | return CMD_WARNING; |
12905 | } | |
12906 | } | |
12907 | else | |
12908 | { | |
12909 | peer = peer_lookup (NULL, &su); | |
12910 | if (! peer) | |
856ca177 | 12911 | { |
db7c8528 | 12912 | if (uj) |
856ca177 MS |
12913 | { |
12914 | json_object *json_no = NULL; | |
12915 | json_no = json_object_new_object(); | |
12916 | json_object_string_add(json_no, "warning", "Peer not found"); | |
12917 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
12918 | json_object_free(json_no); | |
12919 | } | |
12920 | else | |
12921 | vty_out (vty, "No peer%s", VTY_NEWLINE); | |
12922 | return CMD_WARNING; | |
12923 | } | |
c63b83fe | 12924 | } |
718e3744 | 12925 | |
12926 | sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST); | |
db7c8528 | 12927 | count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj); |
718e3744 | 12928 | if (count) |
12929 | { | |
db7c8528 | 12930 | if (!uj) |
856ca177 | 12931 | vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE); |
db7c8528 | 12932 | prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj); |
856ca177 MS |
12933 | } |
12934 | else | |
12935 | { | |
db7c8528 | 12936 | if (uj) |
856ca177 MS |
12937 | { |
12938 | json_object *json_no = NULL; | |
12939 | json_no = json_object_new_object(); | |
12940 | json_object_boolean_true_add(json_no, "noFuntionalOutput"); | |
12941 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
12942 | json_object_free(json_no); | |
12943 | } | |
12944 | else | |
12945 | vty_out (vty, "No functional output%s", VTY_NEWLINE); | |
718e3744 | 12946 | } |
12947 | ||
12948 | return CMD_SUCCESS; | |
12949 | } | |
12950 | ||
12951 | DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter, | |
12952 | show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd, | |
d02fbbdb | 12953 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}", |
718e3744 | 12954 | SHOW_STR |
12955 | IP_STR | |
12956 | BGP_STR | |
12957 | "Address family\n" | |
d02fbbdb | 12958 | BGP_SAFI_HELP_STR |
718e3744 | 12959 | "Detailed information on TCP and BGP neighbor connections\n" |
12960 | "Neighbor to display information about\n" | |
12961 | "Neighbor to display information about\n" | |
a80beece | 12962 | "Neighbor on bgp configured interface\n" |
718e3744 | 12963 | "Display information received from a BGP neighbor\n" |
856ca177 MS |
12964 | "Display the prefixlist filter\n" |
12965 | "JavaScript Object Notation\n") | |
718e3744 | 12966 | { |
12967 | char name[BUFSIZ]; | |
c63b83fe | 12968 | union sockunion su; |
718e3744 | 12969 | struct peer *peer; |
c63b83fe | 12970 | int count, ret; |
db7c8528 | 12971 | u_char uj = use_json(argc, argv); |
718e3744 | 12972 | |
c63b83fe JBD |
12973 | ret = str2sockunion (argv[1], &su); |
12974 | if (ret < 0) | |
12975 | { | |
a80beece | 12976 | peer = peer_lookup_by_conf_if (NULL, argv[1]); |
856ca177 | 12977 | if (! peer) |
a80beece | 12978 | { |
db7c8528 | 12979 | if (uj) |
856ca177 MS |
12980 | { |
12981 | json_object *json_no = NULL; | |
12982 | json_object *json_sub = NULL; | |
12983 | json_no = json_object_new_object(); | |
12984 | json_sub = json_object_new_object(); | |
12985 | json_object_string_add(json_no, "warning", "Malformed address or name"); | |
12986 | json_object_string_add(json_sub, "warningCause", argv[1]); | |
12987 | json_object_object_add(json_no, "detail", json_sub); | |
12988 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
12989 | json_object_free(json_no); | |
12990 | } | |
12991 | else | |
12992 | vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE); | |
a80beece DS |
12993 | return CMD_WARNING; |
12994 | } | |
12995 | } | |
12996 | else | |
12997 | { | |
12998 | peer = peer_lookup (NULL, &su); | |
12999 | if (! peer) | |
856ca177 | 13000 | { |
db7c8528 | 13001 | if (uj) |
856ca177 MS |
13002 | { |
13003 | json_object *json_no = NULL; | |
13004 | json_no = json_object_new_object(); | |
13005 | json_object_string_add(json_no, "warning", "Peer not found"); | |
13006 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
13007 | json_object_free(json_no); | |
13008 | } | |
13009 | else | |
13010 | vty_out (vty, "No peer%s", VTY_NEWLINE); | |
13011 | return CMD_WARNING; | |
13012 | } | |
c63b83fe | 13013 | } |
718e3744 | 13014 | |
718e3744 | 13015 | { |
d02fbbdb LB |
13016 | safi_t safi; |
13017 | safi = bgp_vty_safi_from_arg(argv[0]); | |
13018 | sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi); | |
db7c8528 | 13019 | count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj); |
718e3744 | 13020 | if (count) |
856ca177 | 13021 | { |
db7c8528 | 13022 | if (!uj) |
d02fbbdb LB |
13023 | vty_out (vty, "Address family: %s%s", |
13024 | afi_safi_print (AFI_IP, safi), VTY_NEWLINE); | |
db7c8528 | 13025 | prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj); |
856ca177 MS |
13026 | } |
13027 | else | |
13028 | { | |
db7c8528 | 13029 | if (uj) |
856ca177 MS |
13030 | { |
13031 | json_object *json_no = NULL; | |
13032 | json_no = json_object_new_object(); | |
13033 | json_object_boolean_true_add(json_no, "noFuntionalOutput"); | |
13034 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
13035 | json_object_free(json_no); | |
13036 | } | |
13037 | else | |
13038 | vty_out (vty, "No functional output%s", VTY_NEWLINE); | |
13039 | } | |
718e3744 | 13040 | } |
13041 | ||
13042 | return CMD_SUCCESS; | |
13043 | } | |
718e3744 | 13044 | #ifdef HAVE_IPV6 |
50ef26d4 | 13045 | DEFUN (show_bgp_neighbor_received_routes, |
718e3744 | 13046 | show_bgp_neighbor_received_routes_cmd, |
856ca177 | 13047 | "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", |
718e3744 | 13048 | SHOW_STR |
13049 | BGP_STR | |
13050 | "Detailed information on TCP and BGP neighbor connections\n" | |
13051 | "Neighbor to display information about\n" | |
13052 | "Neighbor to display information about\n" | |
a80beece | 13053 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13054 | "Display the received routes from neighbor\n" |
13055 | "JavaScript Object Notation\n") | |
50ef26d4 | 13056 | { |
13057 | struct peer *peer; | |
13058 | const char *rmap_name = NULL; | |
13059 | u_char uj = use_json(argc, argv); | |
718e3744 | 13060 | |
50ef26d4 | 13061 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
13062 | ||
13063 | if (! peer) | |
13064 | return CMD_WARNING; | |
13065 | ||
13066 | if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)) | |
13067 | rmap_name = argv[1]; | |
13068 | ||
13069 | return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, rmap_name, uj); | |
13070 | } | |
13071 | ||
13072 | ALIAS (show_bgp_neighbor_received_routes, | |
718e3744 | 13073 | show_bgp_ipv6_neighbor_received_routes_cmd, |
856ca177 | 13074 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", |
0b16f239 DS |
13075 | SHOW_STR |
13076 | BGP_STR | |
13077 | "Address family\n" | |
13078 | "Detailed information on TCP and BGP neighbor connections\n" | |
13079 | "Neighbor to display information about\n" | |
13080 | "Neighbor to display information about\n" | |
13081 | "Neighbor on bgp configured interface\n" | |
856ca177 MS |
13082 | "Display the received routes from neighbor\n" |
13083 | "JavaScript Object Notation\n") | |
0b16f239 | 13084 | |
718e3744 | 13085 | DEFUN (show_bgp_neighbor_received_prefix_filter, |
13086 | show_bgp_neighbor_received_prefix_filter_cmd, | |
856ca177 | 13087 | "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}", |
718e3744 | 13088 | SHOW_STR |
13089 | BGP_STR | |
13090 | "Detailed information on TCP and BGP neighbor connections\n" | |
13091 | "Neighbor to display information about\n" | |
13092 | "Neighbor to display information about\n" | |
a80beece | 13093 | "Neighbor on bgp configured interface\n" |
718e3744 | 13094 | "Display information received from a BGP neighbor\n" |
856ca177 MS |
13095 | "Display the prefixlist filter\n" |
13096 | "JavaScript Object Notation\n") | |
718e3744 | 13097 | { |
13098 | char name[BUFSIZ]; | |
c63b83fe | 13099 | union sockunion su; |
718e3744 | 13100 | struct peer *peer; |
c63b83fe | 13101 | int count, ret; |
db7c8528 | 13102 | u_char uj = use_json(argc, argv); |
718e3744 | 13103 | |
c63b83fe JBD |
13104 | ret = str2sockunion (argv[0], &su); |
13105 | if (ret < 0) | |
13106 | { | |
a80beece | 13107 | peer = peer_lookup_by_conf_if (NULL, argv[0]); |
856ca177 | 13108 | if (! peer) |
a80beece | 13109 | { |
db7c8528 | 13110 | if (uj) |
856ca177 MS |
13111 | { |
13112 | json_object *json_no = NULL; | |
13113 | json_object *json_sub = NULL; | |
13114 | json_no = json_object_new_object(); | |
13115 | json_sub = json_object_new_object(); | |
13116 | json_object_string_add(json_no, "warning", "Malformed address or name"); | |
13117 | json_object_string_add(json_sub, "warningCause", argv[0]); | |
13118 | json_object_object_add(json_no, "detail", json_sub); | |
13119 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
13120 | json_object_free(json_no); | |
13121 | } | |
13122 | else | |
13123 | vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE); | |
a80beece DS |
13124 | return CMD_WARNING; |
13125 | } | |
13126 | } | |
13127 | else | |
13128 | { | |
13129 | peer = peer_lookup (NULL, &su); | |
13130 | if (! peer) | |
856ca177 | 13131 | { |
db7c8528 | 13132 | if (uj) |
856ca177 MS |
13133 | { |
13134 | json_object *json_no = NULL; | |
13135 | json_no = json_object_new_object(); | |
13136 | json_object_string_add(json_no, "warning", "No Peer"); | |
13137 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
13138 | json_object_free(json_no); | |
13139 | } | |
13140 | else | |
13141 | vty_out (vty, "No peer%s", VTY_NEWLINE); | |
13142 | return CMD_WARNING; | |
13143 | } | |
c63b83fe | 13144 | } |
718e3744 | 13145 | |
13146 | sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST); | |
db7c8528 | 13147 | count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj); |
718e3744 | 13148 | if (count) |
13149 | { | |
db7c8528 | 13150 | if (!uj) |
856ca177 | 13151 | vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE); |
db7c8528 | 13152 | prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj); |
856ca177 MS |
13153 | } |
13154 | else | |
13155 | { | |
db7c8528 | 13156 | if (uj) |
856ca177 MS |
13157 | { |
13158 | json_object *json_no = NULL; | |
13159 | json_no = json_object_new_object(); | |
13160 | json_object_boolean_true_add(json_no, "noFuntionalOutput"); | |
13161 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
13162 | json_object_free(json_no); | |
13163 | } | |
13164 | else | |
13165 | vty_out (vty, "No functional output%s", VTY_NEWLINE); | |
718e3744 | 13166 | } |
13167 | ||
13168 | return CMD_SUCCESS; | |
13169 | } | |
13170 | ||
13171 | ALIAS (show_bgp_neighbor_received_prefix_filter, | |
13172 | show_bgp_ipv6_neighbor_received_prefix_filter_cmd, | |
856ca177 | 13173 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}", |
718e3744 | 13174 | SHOW_STR |
13175 | BGP_STR | |
13176 | "Address family\n" | |
13177 | "Detailed information on TCP and BGP neighbor connections\n" | |
13178 | "Neighbor to display information about\n" | |
13179 | "Neighbor to display information about\n" | |
a80beece | 13180 | "Neighbor on bgp configured interface\n" |
718e3744 | 13181 | "Display information received from a BGP neighbor\n" |
856ca177 MS |
13182 | "Display the prefixlist filter\n" |
13183 | "JavaScript Object Notation\n") | |
718e3744 | 13184 | |
13185 | /* old command */ | |
50ef26d4 | 13186 | ALIAS (show_bgp_neighbor_received_routes, |
718e3744 | 13187 | ipv6_bgp_neighbor_received_routes_cmd, |
856ca177 | 13188 | "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", |
718e3744 | 13189 | SHOW_STR |
13190 | IPV6_STR | |
13191 | BGP_STR | |
13192 | "Detailed information on TCP and BGP neighbor connections\n" | |
13193 | "Neighbor to display information about\n" | |
13194 | "Neighbor to display information about\n" | |
a80beece | 13195 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13196 | "Display the received routes from neighbor\n" |
13197 | "JavaScript Object Notation\n") | |
718e3744 | 13198 | |
13199 | /* old command */ | |
13200 | DEFUN (ipv6_mbgp_neighbor_received_routes, | |
13201 | ipv6_mbgp_neighbor_received_routes_cmd, | |
856ca177 | 13202 | "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", |
718e3744 | 13203 | SHOW_STR |
13204 | IPV6_STR | |
13205 | MBGP_STR | |
13206 | "Detailed information on TCP and BGP neighbor connections\n" | |
13207 | "Neighbor to display information about\n" | |
13208 | "Neighbor to display information about\n" | |
a80beece | 13209 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13210 | "Display the received routes from neighbor\n" |
13211 | "JavaScript Object Notation\n") | |
718e3744 | 13212 | { |
bb46e94f | 13213 | struct peer *peer; |
db7c8528 | 13214 | u_char uj = use_json(argc, argv); |
bb46e94f | 13215 | |
db7c8528 | 13216 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
bb46e94f | 13217 | if (! peer) |
13218 | return CMD_WARNING; | |
13219 | ||
47e9b292 | 13220 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
db7c8528 | 13221 | return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj); |
bb46e94f | 13222 | } |
13223 | ||
8386ac43 | 13224 | DEFUN (show_bgp_instance_neighbor_received_prefix_filter, |
13225 | show_bgp_instance_neighbor_received_prefix_filter_cmd, | |
13226 | "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}", | |
bb46e94f | 13227 | SHOW_STR |
13228 | BGP_STR | |
8386ac43 | 13229 | BGP_INSTANCE_HELP_STR |
bb46e94f | 13230 | "Detailed information on TCP and BGP neighbor connections\n" |
13231 | "Neighbor to display information about\n" | |
13232 | "Neighbor to display information about\n" | |
a80beece | 13233 | "Neighbor on bgp configured interface\n" |
bb46e94f | 13234 | "Display information received from a BGP neighbor\n" |
856ca177 MS |
13235 | "Display the prefixlist filter\n" |
13236 | "JavaScript Object Notation\n") | |
bb46e94f | 13237 | { |
13238 | char name[BUFSIZ]; | |
c63b83fe | 13239 | union sockunion su; |
bb46e94f | 13240 | struct peer *peer; |
13241 | struct bgp *bgp; | |
c63b83fe | 13242 | int count, ret; |
db7c8528 | 13243 | u_char uj = use_json(argc, argv); |
bb46e94f | 13244 | |
13245 | /* BGP structure lookup. */ | |
6aeb9e78 | 13246 | bgp = bgp_lookup_by_name (argv[1]); |
bb46e94f | 13247 | if (bgp == NULL) |
856ca177 | 13248 | { |
db7c8528 | 13249 | if (uj) |
856ca177 MS |
13250 | { |
13251 | json_object *json_no = NULL; | |
13252 | json_no = json_object_new_object(); | |
13253 | json_object_string_add(json_no, "warning", "Can't find BGP view"); | |
13254 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
13255 | json_object_free(json_no); | |
13256 | } | |
13257 | else | |
6aeb9e78 | 13258 | vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE); |
856ca177 MS |
13259 | return CMD_WARNING; |
13260 | } | |
13261 | ||
6aeb9e78 | 13262 | ret = str2sockunion (argv[2], &su); |
c63b83fe JBD |
13263 | if (ret < 0) |
13264 | { | |
6aeb9e78 | 13265 | peer = peer_lookup_by_conf_if (bgp, argv[2]); |
856ca177 | 13266 | if (! peer) |
a80beece | 13267 | { |
db7c8528 | 13268 | if (uj) |
856ca177 MS |
13269 | { |
13270 | json_object *json_no = NULL; | |
13271 | json_object *json_sub = NULL; | |
13272 | json_no = json_object_new_object(); | |
13273 | json_sub = json_object_new_object(); | |
13274 | json_object_string_add(json_no, "warning", "Malformed address or name"); | |
6aeb9e78 | 13275 | json_object_string_add(json_sub, "warningCause", argv[2]); |
856ca177 MS |
13276 | json_object_object_add(json_no, "detail", json_sub); |
13277 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
13278 | json_object_free(json_no); | |
13279 | } | |
13280 | else | |
6aeb9e78 | 13281 | vty_out (vty, "%% Malformed address or name: %s%s", argv[2], VTY_NEWLINE); |
a80beece DS |
13282 | return CMD_WARNING; |
13283 | } | |
13284 | } | |
13285 | else | |
13286 | { | |
13287 | peer = peer_lookup (bgp, &su); | |
13288 | if (! peer) | |
856ca177 | 13289 | { |
db7c8528 | 13290 | if (uj) |
856ca177 MS |
13291 | { |
13292 | json_object *json_no = NULL; | |
13293 | json_no = json_object_new_object(); | |
13294 | json_object_boolean_true_add(json_no, "noPeer"); | |
13295 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
13296 | json_object_free(json_no); | |
13297 | } | |
13298 | else | |
13299 | vty_out (vty, "No peer%s", VTY_NEWLINE); | |
13300 | return CMD_WARNING; | |
13301 | } | |
13302 | ||
c63b83fe | 13303 | } |
bb46e94f | 13304 | |
13305 | sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST); | |
db7c8528 | 13306 | count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj); |
bb46e94f | 13307 | if (count) |
13308 | { | |
db7c8528 | 13309 | if (!uj) |
856ca177 | 13310 | vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE); |
db7c8528 | 13311 | prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj); |
bb46e94f | 13312 | } |
13313 | ||
13314 | return CMD_SUCCESS; | |
718e3744 | 13315 | } |
8386ac43 | 13316 | ALIAS (show_bgp_instance_neighbor_received_prefix_filter, |
13317 | show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd, | |
13318 | "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}", | |
bb46e94f | 13319 | SHOW_STR |
13320 | BGP_STR | |
8386ac43 | 13321 | BGP_INSTANCE_HELP_STR |
bb46e94f | 13322 | "Address family\n" |
13323 | "Detailed information on TCP and BGP neighbor connections\n" | |
13324 | "Neighbor to display information about\n" | |
13325 | "Neighbor to display information about\n" | |
a80beece | 13326 | "Neighbor on bgp configured interface\n" |
bb46e94f | 13327 | "Display information received from a BGP neighbor\n" |
856ca177 MS |
13328 | "Display the prefixlist filter\n" |
13329 | "JavaScript Object NOtation\n") | |
718e3744 | 13330 | #endif /* HAVE_IPV6 */ |
6b0655a2 | 13331 | |
94f2b392 | 13332 | static int |
bb46e94f | 13333 | bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi, |
856ca177 | 13334 | safi_t safi, enum bgp_show_type type, u_char use_json) |
718e3744 | 13335 | { |
718e3744 | 13336 | if (! peer || ! peer->afc[afi][safi]) |
13337 | { | |
856ca177 MS |
13338 | if (use_json) |
13339 | { | |
13340 | json_object *json_no = NULL; | |
13341 | json_no = json_object_new_object(); | |
13342 | json_object_string_add(json_no, "warning", "No such neighbor or address family"); | |
13343 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
13344 | json_object_free(json_no); | |
13345 | } | |
13346 | else | |
13347 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); | |
718e3744 | 13348 | return CMD_WARNING; |
13349 | } | |
47fc97cc | 13350 | |
856ca177 | 13351 | return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json); |
718e3744 | 13352 | } |
13353 | ||
13354 | DEFUN (show_ip_bgp_neighbor_routes, | |
13355 | show_ip_bgp_neighbor_routes_cmd, | |
856ca177 | 13356 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", |
718e3744 | 13357 | SHOW_STR |
13358 | IP_STR | |
13359 | BGP_STR | |
13360 | "Detailed information on TCP and BGP neighbor connections\n" | |
13361 | "Neighbor to display information about\n" | |
13362 | "Neighbor to display information about\n" | |
a80beece | 13363 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13364 | "Display routes learned from neighbor\n" |
13365 | "JavaScript Object Notation\n") | |
718e3744 | 13366 | { |
bb46e94f | 13367 | struct peer *peer; |
db7c8528 | 13368 | u_char uj = use_json(argc, argv); |
856ca177 | 13369 | |
db7c8528 | 13370 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
bb46e94f | 13371 | if (! peer) |
13372 | return CMD_WARNING; | |
13373 | ||
13374 | return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST, | |
db7c8528 | 13375 | bgp_show_type_neighbor, uj); |
718e3744 | 13376 | } |
13377 | ||
8386ac43 | 13378 | DEFUN (show_ip_bgp_instance_neighbor_routes, |
13379 | show_ip_bgp_instance_neighbor_routes_cmd, | |
13380 | "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", | |
50ef26d4 | 13381 | SHOW_STR |
13382 | IP_STR | |
13383 | BGP_STR | |
8386ac43 | 13384 | BGP_INSTANCE_HELP_STR |
50ef26d4 | 13385 | "Detailed information on TCP and BGP neighbor connections\n" |
13386 | "Neighbor to display information about\n" | |
13387 | "Neighbor to display information about\n" | |
13388 | "Neighbor on bgp configured interface\n" | |
13389 | "Display routes learned from neighbor\n" | |
13390 | "JavaScript Object Notation\n") | |
13391 | { | |
13392 | struct peer *peer; | |
13393 | u_char uj = use_json(argc, argv); | |
13394 | ||
13395 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); | |
13396 | if (! peer) | |
13397 | return CMD_WARNING; | |
13398 | ||
13399 | return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST, | |
13400 | bgp_show_type_neighbor, uj); | |
13401 | } | |
13402 | ||
718e3744 | 13403 | DEFUN (show_ip_bgp_neighbor_flap, |
13404 | show_ip_bgp_neighbor_flap_cmd, | |
856ca177 | 13405 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}", |
718e3744 | 13406 | SHOW_STR |
13407 | IP_STR | |
13408 | BGP_STR | |
13409 | "Detailed information on TCP and BGP neighbor connections\n" | |
13410 | "Neighbor to display information about\n" | |
13411 | "Neighbor to display information about\n" | |
a80beece | 13412 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13413 | "Display flap statistics of the routes learned from neighbor\n" |
13414 | "JavaScript Object Notation\n") | |
718e3744 | 13415 | { |
bb46e94f | 13416 | struct peer *peer; |
db7c8528 | 13417 | u_char uj = use_json(argc, argv); |
856ca177 | 13418 | |
db7c8528 | 13419 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
bb46e94f | 13420 | if (! peer) |
13421 | return CMD_WARNING; | |
13422 | ||
13423 | return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST, | |
db7c8528 | 13424 | bgp_show_type_flap_neighbor, uj); |
718e3744 | 13425 | } |
13426 | ||
13427 | DEFUN (show_ip_bgp_neighbor_damp, | |
13428 | show_ip_bgp_neighbor_damp_cmd, | |
856ca177 | 13429 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}", |
718e3744 | 13430 | SHOW_STR |
13431 | IP_STR | |
13432 | BGP_STR | |
13433 | "Detailed information on TCP and BGP neighbor connections\n" | |
13434 | "Neighbor to display information about\n" | |
13435 | "Neighbor to display information about\n" | |
a80beece | 13436 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13437 | "Display the dampened routes received from neighbor\n" |
13438 | "JavaScript Object Notation\n") | |
718e3744 | 13439 | { |
bb46e94f | 13440 | struct peer *peer; |
db7c8528 | 13441 | u_char uj = use_json(argc, argv); |
856ca177 | 13442 | |
db7c8528 | 13443 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
bb46e94f | 13444 | if (! peer) |
13445 | return CMD_WARNING; | |
13446 | ||
13447 | return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST, | |
db7c8528 | 13448 | bgp_show_type_damp_neighbor, uj); |
718e3744 | 13449 | } |
13450 | ||
13451 | DEFUN (show_ip_bgp_ipv4_neighbor_routes, | |
13452 | show_ip_bgp_ipv4_neighbor_routes_cmd, | |
d02fbbdb | 13453 | "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", |
718e3744 | 13454 | SHOW_STR |
13455 | IP_STR | |
13456 | BGP_STR | |
13457 | "Address family\n" | |
d02fbbdb | 13458 | BGP_SAFI_HELP_STR |
718e3744 | 13459 | "Detailed information on TCP and BGP neighbor connections\n" |
13460 | "Neighbor to display information about\n" | |
13461 | "Neighbor to display information about\n" | |
a80beece | 13462 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13463 | "Display routes learned from neighbor\n" |
13464 | "JavaScript Object Notation\n") | |
718e3744 | 13465 | { |
bb46e94f | 13466 | struct peer *peer; |
d02fbbdb | 13467 | safi_t safi; |
db7c8528 | 13468 | u_char uj = use_json(argc, argv); |
bb46e94f | 13469 | |
db7c8528 | 13470 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
bb46e94f | 13471 | if (! peer) |
13472 | return CMD_WARNING; | |
13473 | ||
d02fbbdb LB |
13474 | safi = bgp_vty_safi_from_arg(argv[0]); |
13475 | return bgp_show_neighbor_route (vty, peer, AFI_IP, safi, | |
13476 | bgp_show_type_neighbor, uj); | |
718e3744 | 13477 | } |
bb46e94f | 13478 | |
2a3d5731 | 13479 | #ifdef HAVE_IPV6 |
8386ac43 | 13480 | DEFUN (show_bgp_instance_neighbor_routes, |
13481 | show_bgp_instance_neighbor_routes_cmd, | |
13482 | "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", | |
fee0f4c6 | 13483 | SHOW_STR |
fee0f4c6 | 13484 | BGP_STR |
8386ac43 | 13485 | BGP_INSTANCE_HELP_STR |
2a3d5731 DW |
13486 | "Detailed information on TCP and BGP neighbor connections\n" |
13487 | "Neighbor to display information about\n" | |
13488 | "Neighbor to display information about\n" | |
13489 | "Neighbor on bgp configured interface\n" | |
13490 | "Display routes learned from neighbor\n" | |
13491 | "JavaScript Object Notation\n") | |
fee0f4c6 | 13492 | { |
fee0f4c6 | 13493 | struct peer *peer; |
db7c8528 | 13494 | u_char uj = use_json(argc, argv); |
fee0f4c6 | 13495 | |
50ef26d4 | 13496 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); |
fee0f4c6 | 13497 | if (! peer) |
13498 | return CMD_WARNING; | |
13499 | ||
2a3d5731 | 13500 | return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST, |
db7c8528 | 13501 | bgp_show_type_neighbor, uj); |
fee0f4c6 | 13502 | } |
13503 | ||
8386ac43 | 13504 | ALIAS (show_bgp_instance_neighbor_routes, |
13505 | show_bgp_instance_ipv6_neighbor_routes_cmd, | |
13506 | "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", | |
fee0f4c6 | 13507 | SHOW_STR |
fee0f4c6 | 13508 | BGP_STR |
8386ac43 | 13509 | BGP_INSTANCE_HELP_STR |
2a3d5731 DW |
13510 | "Address family\n" |
13511 | "Detailed information on TCP and BGP neighbor connections\n" | |
13512 | "Neighbor to display information about\n" | |
13513 | "Neighbor to display information about\n" | |
13514 | "Neighbor on bgp configured interface\n" | |
13515 | "Display routes learned from neighbor\n" | |
13516 | "JavaScript Object Notation\n") | |
fee0f4c6 | 13517 | |
8386ac43 | 13518 | DEFUN (show_bgp_instance_neighbor_damp, |
13519 | show_bgp_instance_neighbor_damp_cmd, | |
13520 | "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}", | |
fee0f4c6 | 13521 | SHOW_STR |
fee0f4c6 | 13522 | BGP_STR |
8386ac43 | 13523 | BGP_INSTANCE_HELP_STR |
2a3d5731 DW |
13524 | "Detailed information on TCP and BGP neighbor connections\n" |
13525 | "Neighbor to display information about\n" | |
13526 | "Neighbor to display information about\n" | |
13527 | "Neighbor on bgp configured interface\n" | |
13528 | "Display the dampened routes received from neighbor\n" | |
13529 | "JavaScript Object Notation\n") | |
bb46e94f | 13530 | { |
13531 | struct peer *peer; | |
db7c8528 | 13532 | u_char uj = use_json(argc, argv); |
856ca177 | 13533 | |
6aeb9e78 DS |
13534 | if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0) |
13535 | || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) | |
13536 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); | |
bb46e94f | 13537 | else |
6aeb9e78 | 13538 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
bb46e94f | 13539 | |
13540 | if (! peer) | |
13541 | return CMD_WARNING; | |
13542 | ||
13543 | return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST, | |
db7c8528 | 13544 | bgp_show_type_damp_neighbor, uj); |
bb46e94f | 13545 | } |
13546 | ||
8386ac43 | 13547 | ALIAS (show_bgp_instance_neighbor_damp, |
13548 | show_bgp_instance_ipv6_neighbor_damp_cmd, | |
13549 | "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}", | |
bb46e94f | 13550 | SHOW_STR |
13551 | BGP_STR | |
8386ac43 | 13552 | BGP_INSTANCE_HELP_STR |
bb46e94f | 13553 | "Address family\n" |
13554 | "Detailed information on TCP and BGP neighbor connections\n" | |
13555 | "Neighbor to display information about\n" | |
13556 | "Neighbor to display information about\n" | |
a80beece | 13557 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13558 | "Display the dampened routes received from neighbor\n" |
13559 | "JavaScript Object Notation\n") | |
bb46e94f | 13560 | |
8386ac43 | 13561 | DEFUN (show_bgp_instance_neighbor_flap, |
13562 | show_bgp_instance_neighbor_flap_cmd, | |
13563 | "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}", | |
bb46e94f | 13564 | SHOW_STR |
13565 | BGP_STR | |
8386ac43 | 13566 | BGP_INSTANCE_HELP_STR |
bb46e94f | 13567 | "Detailed information on TCP and BGP neighbor connections\n" |
13568 | "Neighbor to display information about\n" | |
13569 | "Neighbor to display information about\n" | |
a80beece | 13570 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13571 | "Display flap statistics of the routes learned from neighbor\n" |
13572 | "JavaScript Object Notation\n") | |
bb46e94f | 13573 | { |
13574 | struct peer *peer; | |
db7c8528 | 13575 | u_char uj = use_json(argc, argv); |
856ca177 | 13576 | |
6aeb9e78 DS |
13577 | if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0) |
13578 | || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) | |
13579 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); | |
bb46e94f | 13580 | else |
6aeb9e78 | 13581 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
bb46e94f | 13582 | |
13583 | if (! peer) | |
13584 | return CMD_WARNING; | |
13585 | ||
13586 | return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST, | |
db7c8528 | 13587 | bgp_show_type_flap_neighbor, uj); |
bb46e94f | 13588 | } |
13589 | ||
8386ac43 | 13590 | ALIAS (show_bgp_instance_neighbor_flap, |
13591 | show_bgp_instance_ipv6_neighbor_flap_cmd, | |
13592 | "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}", | |
bb46e94f | 13593 | SHOW_STR |
13594 | BGP_STR | |
8386ac43 | 13595 | BGP_INSTANCE_HELP_STR |
bb46e94f | 13596 | "Address family\n" |
13597 | "Detailed information on TCP and BGP neighbor connections\n" | |
13598 | "Neighbor to display information about\n" | |
13599 | "Neighbor to display information about\n" | |
a80beece | 13600 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13601 | "Display flap statistics of the routes learned from neighbor\n" |
13602 | "JavaScript Object Notation\n") | |
bb46e94f | 13603 | |
50ef26d4 | 13604 | DEFUN (show_bgp_neighbor_routes, |
bb46e94f | 13605 | show_bgp_neighbor_routes_cmd, |
856ca177 | 13606 | "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", |
bb46e94f | 13607 | SHOW_STR |
13608 | BGP_STR | |
13609 | "Detailed information on TCP and BGP neighbor connections\n" | |
13610 | "Neighbor to display information about\n" | |
13611 | "Neighbor to display information about\n" | |
a80beece | 13612 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13613 | "Display routes learned from neighbor\n" |
13614 | "JavaScript Object Notation\n") | |
50ef26d4 | 13615 | { |
13616 | struct peer *peer; | |
13617 | u_char uj = use_json(argc, argv); | |
bb46e94f | 13618 | |
50ef26d4 | 13619 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
13620 | if (! peer) | |
13621 | return CMD_WARNING; | |
bb46e94f | 13622 | |
50ef26d4 | 13623 | return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST, |
13624 | bgp_show_type_neighbor, uj); | |
13625 | } | |
13626 | ||
13627 | ||
13628 | ALIAS (show_bgp_neighbor_routes, | |
718e3744 | 13629 | show_bgp_ipv6_neighbor_routes_cmd, |
856ca177 | 13630 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", |
718e3744 | 13631 | SHOW_STR |
13632 | BGP_STR | |
13633 | "Address family\n" | |
13634 | "Detailed information on TCP and BGP neighbor connections\n" | |
13635 | "Neighbor to display information about\n" | |
13636 | "Neighbor to display information about\n" | |
a80beece | 13637 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13638 | "Display routes learned from neighbor\n" |
13639 | "JavaScript Object Notation\n") | |
718e3744 | 13640 | |
13641 | /* old command */ | |
50ef26d4 | 13642 | ALIAS (show_bgp_neighbor_routes, |
718e3744 | 13643 | ipv6_bgp_neighbor_routes_cmd, |
856ca177 | 13644 | "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", |
718e3744 | 13645 | SHOW_STR |
13646 | IPV6_STR | |
13647 | BGP_STR | |
13648 | "Detailed information on TCP and BGP neighbor connections\n" | |
13649 | "Neighbor to display information about\n" | |
13650 | "Neighbor to display information about\n" | |
a80beece | 13651 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13652 | "Display routes learned from neighbor\n" |
13653 | "JavaScript Object Notation\n") | |
718e3744 | 13654 | |
13655 | /* old command */ | |
13656 | DEFUN (ipv6_mbgp_neighbor_routes, | |
13657 | ipv6_mbgp_neighbor_routes_cmd, | |
856ca177 | 13658 | "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", |
718e3744 | 13659 | SHOW_STR |
13660 | IPV6_STR | |
13661 | MBGP_STR | |
13662 | "Detailed information on TCP and BGP neighbor connections\n" | |
13663 | "Neighbor to display information about\n" | |
13664 | "Neighbor to display information about\n" | |
a80beece | 13665 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13666 | "Display routes learned from neighbor\n" |
13667 | "JavaScript Object Notation\n") | |
718e3744 | 13668 | { |
bb46e94f | 13669 | struct peer *peer; |
db7c8528 | 13670 | u_char uj = use_json(argc, argv); |
bb46e94f | 13671 | |
db7c8528 | 13672 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
bb46e94f | 13673 | if (! peer) |
13674 | return CMD_WARNING; | |
13675 | ||
47e9b292 | 13676 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
bb46e94f | 13677 | return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST, |
db7c8528 | 13678 | bgp_show_type_neighbor, uj); |
718e3744 | 13679 | } |
bb46e94f | 13680 | |
8386ac43 | 13681 | ALIAS (show_bgp_instance_neighbor_flap, |
bb46e94f | 13682 | show_bgp_neighbor_flap_cmd, |
856ca177 | 13683 | "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}", |
bb46e94f | 13684 | SHOW_STR |
13685 | BGP_STR | |
13686 | "Detailed information on TCP and BGP neighbor connections\n" | |
13687 | "Neighbor to display information about\n" | |
13688 | "Neighbor to display information about\n" | |
a80beece | 13689 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13690 | "Display flap statistics of the routes learned from neighbor\n" |
13691 | "JavaScript Object Notation\n") | |
bb46e94f | 13692 | |
8386ac43 | 13693 | ALIAS (show_bgp_instance_neighbor_flap, |
bb46e94f | 13694 | show_bgp_ipv6_neighbor_flap_cmd, |
856ca177 | 13695 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}", |
bb46e94f | 13696 | SHOW_STR |
13697 | BGP_STR | |
13698 | "Address family\n" | |
13699 | "Detailed information on TCP and BGP neighbor connections\n" | |
13700 | "Neighbor to display information about\n" | |
13701 | "Neighbor to display information about\n" | |
a80beece | 13702 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13703 | "Display flap statistics of the routes learned from neighbor\n" |
13704 | "JavaScript Object Notation\n") | |
bb46e94f | 13705 | |
8386ac43 | 13706 | ALIAS (show_bgp_instance_neighbor_damp, |
bb46e94f | 13707 | show_bgp_neighbor_damp_cmd, |
856ca177 | 13708 | "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}", |
bb46e94f | 13709 | SHOW_STR |
13710 | BGP_STR | |
13711 | "Detailed information on TCP and BGP neighbor connections\n" | |
13712 | "Neighbor to display information about\n" | |
13713 | "Neighbor to display information about\n" | |
a80beece | 13714 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13715 | "Display the dampened routes received from neighbor\n" |
13716 | "JavaScript Object Notation\n") | |
bb46e94f | 13717 | |
8386ac43 | 13718 | ALIAS (show_bgp_instance_neighbor_damp, |
bb46e94f | 13719 | show_bgp_ipv6_neighbor_damp_cmd, |
856ca177 | 13720 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}", |
bb46e94f | 13721 | SHOW_STR |
13722 | BGP_STR | |
13723 | "Address family\n" | |
13724 | "Detailed information on TCP and BGP neighbor connections\n" | |
13725 | "Neighbor to display information about\n" | |
13726 | "Neighbor to display information about\n" | |
a80beece | 13727 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
13728 | "Display the dampened routes received from neighbor\n" |
13729 | "JavaScript Object Notation\n") | |
fee0f4c6 | 13730 | |
718e3744 | 13731 | #endif /* HAVE_IPV6 */ |
6b0655a2 | 13732 | |
734b349e | 13733 | struct bgp_table *bgp_distance_table[AFI_MAX][SAFI_MAX]; |
718e3744 | 13734 | |
13735 | struct bgp_distance | |
13736 | { | |
13737 | /* Distance value for the IP source prefix. */ | |
13738 | u_char distance; | |
13739 | ||
13740 | /* Name of the access-list to be matched. */ | |
13741 | char *access_list; | |
13742 | }; | |
13743 | ||
94f2b392 | 13744 | static struct bgp_distance * |
66e5cd87 | 13745 | bgp_distance_new (void) |
718e3744 | 13746 | { |
393deb9b | 13747 | return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance)); |
718e3744 | 13748 | } |
13749 | ||
94f2b392 | 13750 | static void |
718e3744 | 13751 | bgp_distance_free (struct bgp_distance *bdistance) |
13752 | { | |
13753 | XFREE (MTYPE_BGP_DISTANCE, bdistance); | |
13754 | } | |
13755 | ||
94f2b392 | 13756 | static int |
fd79ac91 | 13757 | bgp_distance_set (struct vty *vty, const char *distance_str, |
13758 | const char *ip_str, const char *access_list_str) | |
718e3744 | 13759 | { |
13760 | int ret; | |
734b349e MZ |
13761 | afi_t afi; |
13762 | safi_t safi; | |
13763 | struct prefix p; | |
718e3744 | 13764 | u_char distance; |
13765 | struct bgp_node *rn; | |
13766 | struct bgp_distance *bdistance; | |
13767 | ||
734b349e MZ |
13768 | afi = bgp_node_afi (vty); |
13769 | safi = bgp_node_safi (vty); | |
13770 | ||
13771 | ret = str2prefix (ip_str, &p); | |
718e3744 | 13772 | if (ret == 0) |
13773 | { | |
13774 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); | |
13775 | return CMD_WARNING; | |
13776 | } | |
13777 | ||
13778 | distance = atoi (distance_str); | |
13779 | ||
13780 | /* Get BGP distance node. */ | |
734b349e | 13781 | rn = bgp_node_get (bgp_distance_table[afi][safi], (struct prefix *) &p); |
718e3744 | 13782 | if (rn->info) |
13783 | { | |
13784 | bdistance = rn->info; | |
13785 | bgp_unlock_node (rn); | |
13786 | } | |
13787 | else | |
13788 | { | |
13789 | bdistance = bgp_distance_new (); | |
13790 | rn->info = bdistance; | |
13791 | } | |
13792 | ||
13793 | /* Set distance value. */ | |
13794 | bdistance->distance = distance; | |
13795 | ||
13796 | /* Reset access-list configuration. */ | |
13797 | if (bdistance->access_list) | |
13798 | { | |
6e919709 | 13799 | XFREE(MTYPE_AS_LIST, bdistance->access_list); |
718e3744 | 13800 | bdistance->access_list = NULL; |
13801 | } | |
13802 | if (access_list_str) | |
6e919709 | 13803 | bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str); |
718e3744 | 13804 | |
13805 | return CMD_SUCCESS; | |
13806 | } | |
13807 | ||
94f2b392 | 13808 | static int |
fd79ac91 | 13809 | bgp_distance_unset (struct vty *vty, const char *distance_str, |
13810 | const char *ip_str, const char *access_list_str) | |
718e3744 | 13811 | { |
13812 | int ret; | |
734b349e MZ |
13813 | afi_t afi; |
13814 | safi_t safi; | |
13815 | struct prefix p; | |
1f9a9fff | 13816 | int distance; |
718e3744 | 13817 | struct bgp_node *rn; |
13818 | struct bgp_distance *bdistance; | |
13819 | ||
734b349e MZ |
13820 | afi = bgp_node_afi (vty); |
13821 | safi = bgp_node_safi (vty); | |
13822 | ||
13823 | ret = str2prefix (ip_str, &p); | |
718e3744 | 13824 | if (ret == 0) |
13825 | { | |
13826 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); | |
13827 | return CMD_WARNING; | |
13828 | } | |
13829 | ||
734b349e | 13830 | rn = bgp_node_lookup (bgp_distance_table[afi][safi], (struct prefix *)&p); |
718e3744 | 13831 | if (! rn) |
13832 | { | |
13833 | vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE); | |
13834 | return CMD_WARNING; | |
13835 | } | |
13836 | ||
13837 | bdistance = rn->info; | |
1f9a9fff PJ |
13838 | distance = atoi(distance_str); |
13839 | ||
13840 | if (bdistance->distance != distance) | |
13841 | { | |
13842 | vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE); | |
13843 | return CMD_WARNING; | |
13844 | } | |
718e3744 | 13845 | |
13846 | if (bdistance->access_list) | |
6e919709 | 13847 | XFREE(MTYPE_AS_LIST, bdistance->access_list); |
718e3744 | 13848 | bgp_distance_free (bdistance); |
13849 | ||
13850 | rn->info = NULL; | |
13851 | bgp_unlock_node (rn); | |
13852 | bgp_unlock_node (rn); | |
13853 | ||
13854 | return CMD_SUCCESS; | |
13855 | } | |
13856 | ||
718e3744 | 13857 | /* Apply BGP information to distance method. */ |
13858 | u_char | |
734b349e MZ |
13859 | bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, afi_t afi, |
13860 | safi_t safi, struct bgp *bgp) | |
718e3744 | 13861 | { |
13862 | struct bgp_node *rn; | |
734b349e | 13863 | struct prefix q; |
718e3744 | 13864 | struct peer *peer; |
13865 | struct bgp_distance *bdistance; | |
13866 | struct access_list *alist; | |
13867 | struct bgp_static *bgp_static; | |
13868 | ||
13869 | if (! bgp) | |
13870 | return 0; | |
13871 | ||
718e3744 | 13872 | peer = rinfo->peer; |
13873 | ||
718e3744 | 13874 | /* Check source address. */ |
734b349e MZ |
13875 | sockunion2hostprefix (&peer->su, &q); |
13876 | rn = bgp_node_match (bgp_distance_table[afi][safi], &q); | |
718e3744 | 13877 | if (rn) |
13878 | { | |
13879 | bdistance = rn->info; | |
13880 | bgp_unlock_node (rn); | |
13881 | ||
13882 | if (bdistance->access_list) | |
13883 | { | |
734b349e | 13884 | alist = access_list_lookup (afi, bdistance->access_list); |
718e3744 | 13885 | if (alist && access_list_apply (alist, p) == FILTER_PERMIT) |
13886 | return bdistance->distance; | |
13887 | } | |
13888 | else | |
13889 | return bdistance->distance; | |
13890 | } | |
13891 | ||
13892 | /* Backdoor check. */ | |
734b349e | 13893 | rn = bgp_node_lookup (bgp->route[afi][safi], p); |
718e3744 | 13894 | if (rn) |
13895 | { | |
13896 | bgp_static = rn->info; | |
13897 | bgp_unlock_node (rn); | |
13898 | ||
13899 | if (bgp_static->backdoor) | |
13900 | { | |
734b349e MZ |
13901 | if (bgp->distance_local[afi][safi]) |
13902 | return bgp->distance_local[afi][safi]; | |
718e3744 | 13903 | else |
13904 | return ZEBRA_IBGP_DISTANCE_DEFAULT; | |
13905 | } | |
13906 | } | |
13907 | ||
6d85b15b | 13908 | if (peer->sort == BGP_PEER_EBGP) |
718e3744 | 13909 | { |
734b349e MZ |
13910 | if (bgp->distance_ebgp[afi][safi]) |
13911 | return bgp->distance_ebgp[afi][safi]; | |
718e3744 | 13912 | return ZEBRA_EBGP_DISTANCE_DEFAULT; |
13913 | } | |
13914 | else | |
13915 | { | |
734b349e MZ |
13916 | if (bgp->distance_ibgp[afi][safi]) |
13917 | return bgp->distance_ibgp[afi][safi]; | |
718e3744 | 13918 | return ZEBRA_IBGP_DISTANCE_DEFAULT; |
13919 | } | |
13920 | } | |
13921 | ||
13922 | DEFUN (bgp_distance, | |
13923 | bgp_distance_cmd, | |
13924 | "distance bgp <1-255> <1-255> <1-255>", | |
13925 | "Define an administrative distance\n" | |
13926 | "BGP distance\n" | |
13927 | "Distance for routes external to the AS\n" | |
13928 | "Distance for routes internal to the AS\n" | |
13929 | "Distance for local routes\n") | |
13930 | { | |
13931 | struct bgp *bgp; | |
734b349e MZ |
13932 | afi_t afi; |
13933 | safi_t safi; | |
718e3744 | 13934 | |
13935 | bgp = vty->index; | |
734b349e MZ |
13936 | afi = bgp_node_afi (vty); |
13937 | safi = bgp_node_safi (vty); | |
718e3744 | 13938 | |
734b349e MZ |
13939 | bgp->distance_ebgp[afi][safi] = atoi (argv[0]); |
13940 | bgp->distance_ibgp[afi][safi] = atoi (argv[1]); | |
13941 | bgp->distance_local[afi][safi] = atoi (argv[2]); | |
718e3744 | 13942 | return CMD_SUCCESS; |
13943 | } | |
13944 | ||
13945 | DEFUN (no_bgp_distance, | |
13946 | no_bgp_distance_cmd, | |
13947 | "no distance bgp <1-255> <1-255> <1-255>", | |
13948 | NO_STR | |
13949 | "Define an administrative distance\n" | |
13950 | "BGP distance\n" | |
13951 | "Distance for routes external to the AS\n" | |
13952 | "Distance for routes internal to the AS\n" | |
13953 | "Distance for local routes\n") | |
13954 | { | |
13955 | struct bgp *bgp; | |
734b349e MZ |
13956 | afi_t afi; |
13957 | safi_t safi; | |
718e3744 | 13958 | |
13959 | bgp = vty->index; | |
734b349e MZ |
13960 | afi = bgp_node_afi (vty); |
13961 | safi = bgp_node_safi (vty); | |
718e3744 | 13962 | |
734b349e MZ |
13963 | bgp->distance_ebgp[afi][safi] = 0; |
13964 | bgp->distance_ibgp[afi][safi] = 0; | |
13965 | bgp->distance_local[afi][safi] = 0; | |
718e3744 | 13966 | return CMD_SUCCESS; |
13967 | } | |
13968 | ||
13969 | ALIAS (no_bgp_distance, | |
13970 | no_bgp_distance2_cmd, | |
13971 | "no distance bgp", | |
13972 | NO_STR | |
13973 | "Define an administrative distance\n" | |
13974 | "BGP distance\n") | |
13975 | ||
13976 | DEFUN (bgp_distance_source, | |
13977 | bgp_distance_source_cmd, | |
13978 | "distance <1-255> A.B.C.D/M", | |
13979 | "Define an administrative distance\n" | |
13980 | "Administrative distance\n" | |
13981 | "IP source prefix\n") | |
13982 | { | |
13983 | bgp_distance_set (vty, argv[0], argv[1], NULL); | |
13984 | return CMD_SUCCESS; | |
13985 | } | |
13986 | ||
13987 | DEFUN (no_bgp_distance_source, | |
13988 | no_bgp_distance_source_cmd, | |
13989 | "no distance <1-255> A.B.C.D/M", | |
13990 | NO_STR | |
13991 | "Define an administrative distance\n" | |
13992 | "Administrative distance\n" | |
13993 | "IP source prefix\n") | |
13994 | { | |
13995 | bgp_distance_unset (vty, argv[0], argv[1], NULL); | |
13996 | return CMD_SUCCESS; | |
13997 | } | |
13998 | ||
13999 | DEFUN (bgp_distance_source_access_list, | |
14000 | bgp_distance_source_access_list_cmd, | |
14001 | "distance <1-255> A.B.C.D/M WORD", | |
14002 | "Define an administrative distance\n" | |
14003 | "Administrative distance\n" | |
14004 | "IP source prefix\n" | |
14005 | "Access list name\n") | |
14006 | { | |
14007 | bgp_distance_set (vty, argv[0], argv[1], argv[2]); | |
14008 | return CMD_SUCCESS; | |
14009 | } | |
14010 | ||
14011 | DEFUN (no_bgp_distance_source_access_list, | |
14012 | no_bgp_distance_source_access_list_cmd, | |
14013 | "no distance <1-255> A.B.C.D/M WORD", | |
14014 | NO_STR | |
14015 | "Define an administrative distance\n" | |
14016 | "Administrative distance\n" | |
14017 | "IP source prefix\n" | |
14018 | "Access list name\n") | |
14019 | { | |
14020 | bgp_distance_unset (vty, argv[0], argv[1], argv[2]); | |
14021 | return CMD_SUCCESS; | |
14022 | } | |
6b0655a2 | 14023 | |
734b349e MZ |
14024 | DEFUN (ipv6_bgp_distance_source, |
14025 | ipv6_bgp_distance_source_cmd, | |
14026 | "distance <1-255> X:X::X:X/M", | |
14027 | "Define an administrative distance\n" | |
14028 | "Administrative distance\n" | |
14029 | "IP source prefix\n") | |
14030 | { | |
14031 | bgp_distance_set (vty, argv[0], argv[1], NULL); | |
14032 | return CMD_SUCCESS; | |
14033 | } | |
14034 | ||
14035 | DEFUN (no_ipv6_bgp_distance_source, | |
14036 | no_ipv6_bgp_distance_source_cmd, | |
14037 | "no distance <1-255> X:X::X:X/M", | |
14038 | NO_STR | |
14039 | "Define an administrative distance\n" | |
14040 | "Administrative distance\n" | |
14041 | "IP source prefix\n") | |
14042 | { | |
14043 | bgp_distance_unset (vty, argv[0], argv[1], NULL); | |
14044 | return CMD_SUCCESS; | |
14045 | } | |
14046 | ||
14047 | DEFUN (ipv6_bgp_distance_source_access_list, | |
14048 | ipv6_bgp_distance_source_access_list_cmd, | |
14049 | "distance <1-255> X:X::X:X/M WORD", | |
14050 | "Define an administrative distance\n" | |
14051 | "Administrative distance\n" | |
14052 | "IP source prefix\n" | |
14053 | "Access list name\n") | |
14054 | { | |
14055 | bgp_distance_set (vty, argv[0], argv[1], argv[2]); | |
14056 | return CMD_SUCCESS; | |
14057 | } | |
14058 | ||
14059 | DEFUN (no_ipv6_bgp_distance_source_access_list, | |
14060 | no_ipv6_bgp_distance_source_access_list_cmd, | |
14061 | "no distance <1-255> X:X::X:X/M WORD", | |
14062 | NO_STR | |
14063 | "Define an administrative distance\n" | |
14064 | "Administrative distance\n" | |
14065 | "IP source prefix\n" | |
14066 | "Access list name\n") | |
14067 | { | |
14068 | bgp_distance_unset (vty, argv[0], argv[1], argv[2]); | |
14069 | return CMD_SUCCESS; | |
14070 | } | |
14071 | ||
718e3744 | 14072 | DEFUN (bgp_damp_set, |
14073 | bgp_damp_set_cmd, | |
14074 | "bgp dampening <1-45> <1-20000> <1-20000> <1-255>", | |
14075 | "BGP Specific commands\n" | |
14076 | "Enable route-flap dampening\n" | |
14077 | "Half-life time for the penalty\n" | |
14078 | "Value to start reusing a route\n" | |
14079 | "Value to start suppressing a route\n" | |
14080 | "Maximum duration to suppress a stable route\n") | |
14081 | { | |
14082 | struct bgp *bgp; | |
14083 | int half = DEFAULT_HALF_LIFE * 60; | |
14084 | int reuse = DEFAULT_REUSE; | |
14085 | int suppress = DEFAULT_SUPPRESS; | |
14086 | int max = 4 * half; | |
14087 | ||
14088 | if (argc == 4) | |
14089 | { | |
14090 | half = atoi (argv[0]) * 60; | |
14091 | reuse = atoi (argv[1]); | |
14092 | suppress = atoi (argv[2]); | |
14093 | max = atoi (argv[3]) * 60; | |
14094 | } | |
14095 | else if (argc == 1) | |
14096 | { | |
14097 | half = atoi (argv[0]) * 60; | |
14098 | max = 4 * half; | |
14099 | } | |
14100 | ||
14101 | bgp = vty->index; | |
7ebe9748 B |
14102 | |
14103 | if (suppress < reuse) | |
14104 | { | |
14105 | vty_out (vty, "Suppress value cannot be less than reuse value %s", | |
14106 | VTY_NEWLINE); | |
14107 | return 0; | |
14108 | } | |
14109 | ||
718e3744 | 14110 | return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty), |
14111 | half, reuse, suppress, max); | |
14112 | } | |
14113 | ||
14114 | ALIAS (bgp_damp_set, | |
14115 | bgp_damp_set2_cmd, | |
14116 | "bgp dampening <1-45>", | |
14117 | "BGP Specific commands\n" | |
14118 | "Enable route-flap dampening\n" | |
14119 | "Half-life time for the penalty\n") | |
14120 | ||
14121 | ALIAS (bgp_damp_set, | |
14122 | bgp_damp_set3_cmd, | |
14123 | "bgp dampening", | |
14124 | "BGP Specific commands\n" | |
14125 | "Enable route-flap dampening\n") | |
14126 | ||
14127 | DEFUN (bgp_damp_unset, | |
14128 | bgp_damp_unset_cmd, | |
14129 | "no bgp dampening", | |
14130 | NO_STR | |
14131 | "BGP Specific commands\n" | |
14132 | "Enable route-flap dampening\n") | |
14133 | { | |
14134 | struct bgp *bgp; | |
14135 | ||
14136 | bgp = vty->index; | |
14137 | return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty)); | |
14138 | } | |
14139 | ||
14140 | ALIAS (bgp_damp_unset, | |
14141 | bgp_damp_unset2_cmd, | |
14142 | "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>", | |
14143 | NO_STR | |
14144 | "BGP Specific commands\n" | |
14145 | "Enable route-flap dampening\n" | |
14146 | "Half-life time for the penalty\n" | |
14147 | "Value to start reusing a route\n" | |
14148 | "Value to start suppressing a route\n" | |
14149 | "Maximum duration to suppress a stable route\n") | |
14150 | ||
813d4307 DW |
14151 | ALIAS (bgp_damp_unset, |
14152 | bgp_damp_unset3_cmd, | |
14153 | "no bgp dampening <1-45>", | |
14154 | NO_STR | |
14155 | "BGP Specific commands\n" | |
14156 | "Enable route-flap dampening\n" | |
14157 | "Half-life time for the penalty\n") | |
14158 | ||
718e3744 | 14159 | DEFUN (show_ip_bgp_dampened_paths, |
14160 | show_ip_bgp_dampened_paths_cmd, | |
14161 | "show ip bgp dampened-paths", | |
14162 | SHOW_STR | |
14163 | IP_STR | |
14164 | BGP_STR | |
14165 | "Display paths suppressed due to dampening\n") | |
14166 | { | |
5a646650 | 14167 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths, |
b05a1c8b | 14168 | NULL, 0); |
718e3744 | 14169 | } |
14170 | ||
81304aaf B |
14171 | ALIAS (show_ip_bgp_dampened_paths, |
14172 | show_ip_bgp_damp_dampened_paths_cmd, | |
14173 | "show ip bgp dampening dampened-paths", | |
14174 | SHOW_STR | |
14175 | IP_STR | |
14176 | BGP_STR | |
14177 | "Display detailed information about dampening\n" | |
14178 | "Display paths suppressed due to dampening\n") | |
14179 | ||
718e3744 | 14180 | DEFUN (show_ip_bgp_flap_statistics, |
14181 | show_ip_bgp_flap_statistics_cmd, | |
14182 | "show ip bgp flap-statistics", | |
14183 | SHOW_STR | |
14184 | IP_STR | |
14185 | BGP_STR | |
14186 | "Display flap statistics of routes\n") | |
14187 | { | |
5a646650 | 14188 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, |
b05a1c8b | 14189 | bgp_show_type_flap_statistics, NULL, 0); |
718e3744 | 14190 | } |
6b0655a2 | 14191 | |
81304aaf B |
14192 | ALIAS (show_ip_bgp_flap_statistics, |
14193 | show_ip_bgp_damp_flap_statistics_cmd, | |
14194 | "show ip bgp dampening flap-statistics", | |
14195 | SHOW_STR | |
14196 | IP_STR | |
14197 | BGP_STR | |
14198 | "Display detailed information about dampening\n" | |
14199 | "Display flap statistics of routes\n") | |
14200 | ||
718e3744 | 14201 | /* Display specified route of BGP table. */ |
94f2b392 | 14202 | static int |
fd79ac91 | 14203 | bgp_clear_damp_route (struct vty *vty, const char *view_name, |
14204 | const char *ip_str, afi_t afi, safi_t safi, | |
14205 | struct prefix_rd *prd, int prefix_check) | |
718e3744 | 14206 | { |
14207 | int ret; | |
14208 | struct prefix match; | |
14209 | struct bgp_node *rn; | |
14210 | struct bgp_node *rm; | |
14211 | struct bgp_info *ri; | |
14212 | struct bgp_info *ri_temp; | |
14213 | struct bgp *bgp; | |
14214 | struct bgp_table *table; | |
14215 | ||
14216 | /* BGP structure lookup. */ | |
14217 | if (view_name) | |
14218 | { | |
14219 | bgp = bgp_lookup_by_name (view_name); | |
14220 | if (bgp == NULL) | |
14221 | { | |
6aeb9e78 | 14222 | vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE); |
718e3744 | 14223 | return CMD_WARNING; |
14224 | } | |
14225 | } | |
14226 | else | |
14227 | { | |
14228 | bgp = bgp_get_default (); | |
14229 | if (bgp == NULL) | |
14230 | { | |
14231 | vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE); | |
14232 | return CMD_WARNING; | |
14233 | } | |
14234 | } | |
14235 | ||
14236 | /* Check IP address argument. */ | |
14237 | ret = str2prefix (ip_str, &match); | |
14238 | if (! ret) | |
14239 | { | |
14240 | vty_out (vty, "%% address is malformed%s", VTY_NEWLINE); | |
14241 | return CMD_WARNING; | |
14242 | } | |
14243 | ||
14244 | match.family = afi2family (afi); | |
14245 | ||
587ff0fd | 14246 | if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) |
718e3744 | 14247 | { |
587ff0fd | 14248 | for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn)) |
718e3744 | 14249 | { |
14250 | if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0) | |
14251 | continue; | |
14252 | ||
14253 | if ((table = rn->info) != NULL) | |
14254 | if ((rm = bgp_node_match (table, &match)) != NULL) | |
6c88b44d CC |
14255 | { |
14256 | if (! prefix_check || rm->p.prefixlen == match.prefixlen) | |
14257 | { | |
14258 | ri = rm->info; | |
14259 | while (ri) | |
14260 | { | |
14261 | if (ri->extra && ri->extra->damp_info) | |
14262 | { | |
14263 | ri_temp = ri->next; | |
14264 | bgp_damp_info_free (ri->extra->damp_info, 1); | |
14265 | ri = ri_temp; | |
14266 | } | |
14267 | else | |
14268 | ri = ri->next; | |
14269 | } | |
14270 | } | |
14271 | ||
14272 | bgp_unlock_node (rm); | |
14273 | } | |
718e3744 | 14274 | } |
14275 | } | |
14276 | else | |
14277 | { | |
14278 | if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL) | |
6c88b44d CC |
14279 | { |
14280 | if (! prefix_check || rn->p.prefixlen == match.prefixlen) | |
14281 | { | |
14282 | ri = rn->info; | |
14283 | while (ri) | |
14284 | { | |
14285 | if (ri->extra && ri->extra->damp_info) | |
14286 | { | |
14287 | ri_temp = ri->next; | |
14288 | bgp_damp_info_free (ri->extra->damp_info, 1); | |
14289 | ri = ri_temp; | |
14290 | } | |
14291 | else | |
14292 | ri = ri->next; | |
14293 | } | |
14294 | } | |
14295 | ||
14296 | bgp_unlock_node (rn); | |
14297 | } | |
718e3744 | 14298 | } |
14299 | ||
14300 | return CMD_SUCCESS; | |
14301 | } | |
14302 | ||
14303 | DEFUN (clear_ip_bgp_dampening, | |
14304 | clear_ip_bgp_dampening_cmd, | |
14305 | "clear ip bgp dampening", | |
14306 | CLEAR_STR | |
14307 | IP_STR | |
14308 | BGP_STR | |
14309 | "Clear route flap dampening information\n") | |
14310 | { | |
14311 | bgp_damp_info_clean (); | |
14312 | return CMD_SUCCESS; | |
14313 | } | |
14314 | ||
14315 | DEFUN (clear_ip_bgp_dampening_prefix, | |
14316 | clear_ip_bgp_dampening_prefix_cmd, | |
14317 | "clear ip bgp dampening A.B.C.D/M", | |
14318 | CLEAR_STR | |
14319 | IP_STR | |
14320 | BGP_STR | |
14321 | "Clear route flap dampening information\n" | |
14322 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") | |
14323 | { | |
14324 | return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP, | |
14325 | SAFI_UNICAST, NULL, 1); | |
14326 | } | |
14327 | ||
14328 | DEFUN (clear_ip_bgp_dampening_address, | |
14329 | clear_ip_bgp_dampening_address_cmd, | |
14330 | "clear ip bgp dampening A.B.C.D", | |
14331 | CLEAR_STR | |
14332 | IP_STR | |
14333 | BGP_STR | |
14334 | "Clear route flap dampening information\n" | |
14335 | "Network to clear damping information\n") | |
14336 | { | |
14337 | return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP, | |
14338 | SAFI_UNICAST, NULL, 0); | |
14339 | } | |
14340 | ||
14341 | DEFUN (clear_ip_bgp_dampening_address_mask, | |
14342 | clear_ip_bgp_dampening_address_mask_cmd, | |
14343 | "clear ip bgp dampening A.B.C.D A.B.C.D", | |
14344 | CLEAR_STR | |
14345 | IP_STR | |
14346 | BGP_STR | |
14347 | "Clear route flap dampening information\n" | |
14348 | "Network to clear damping information\n" | |
14349 | "Network mask\n") | |
14350 | { | |
14351 | int ret; | |
14352 | char prefix_str[BUFSIZ]; | |
14353 | ||
14354 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); | |
14355 | if (! ret) | |
14356 | { | |
14357 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
14358 | return CMD_WARNING; | |
14359 | } | |
14360 | ||
14361 | return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP, | |
14362 | SAFI_UNICAST, NULL, 0); | |
14363 | } | |
6b0655a2 | 14364 | |
587ff0fd | 14365 | /* also used for encap safi */ |
94f2b392 | 14366 | static int |
718e3744 | 14367 | bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp, |
14368 | afi_t afi, safi_t safi, int *write) | |
14369 | { | |
14370 | struct bgp_node *prn; | |
14371 | struct bgp_node *rn; | |
14372 | struct bgp_table *table; | |
14373 | struct prefix *p; | |
14374 | struct prefix_rd *prd; | |
14375 | struct bgp_static *bgp_static; | |
14376 | u_int32_t label; | |
14377 | char buf[SU_ADDRSTRLEN]; | |
14378 | char rdbuf[RD_ADDRSTRLEN]; | |
14379 | ||
14380 | /* Network configuration. */ | |
14381 | for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn)) | |
14382 | if ((table = prn->info) != NULL) | |
14383 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
14384 | if ((bgp_static = rn->info) != NULL) | |
14385 | { | |
14386 | p = &rn->p; | |
14387 | prd = (struct prefix_rd *) &prn->p; | |
14388 | ||
14389 | /* "address-family" display. */ | |
14390 | bgp_config_write_family_header (vty, afi, safi, write); | |
14391 | ||
14392 | /* "network" configuration display. */ | |
14393 | prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN); | |
14394 | label = decode_label (bgp_static->tag); | |
14395 | ||
0b960b4d | 14396 | vty_out (vty, " network %s/%d rd %s tag %d", |
718e3744 | 14397 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
14398 | p->prefixlen, | |
14399 | rdbuf, label); | |
14400 | vty_out (vty, "%s", VTY_NEWLINE); | |
14401 | } | |
14402 | return 0; | |
14403 | } | |
14404 | ||
14405 | /* Configuration of static route announcement and aggregate | |
14406 | information. */ | |
14407 | int | |
14408 | bgp_config_write_network (struct vty *vty, struct bgp *bgp, | |
14409 | afi_t afi, safi_t safi, int *write) | |
14410 | { | |
14411 | struct bgp_node *rn; | |
14412 | struct prefix *p; | |
14413 | struct bgp_static *bgp_static; | |
14414 | struct bgp_aggregate *bgp_aggregate; | |
14415 | char buf[SU_ADDRSTRLEN]; | |
14416 | ||
587ff0fd | 14417 | if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))) |
718e3744 | 14418 | return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write); |
14419 | ||
14420 | /* Network configuration. */ | |
14421 | for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn)) | |
14422 | if ((bgp_static = rn->info) != NULL) | |
14423 | { | |
14424 | p = &rn->p; | |
14425 | ||
14426 | /* "address-family" display. */ | |
14427 | bgp_config_write_family_header (vty, afi, safi, write); | |
14428 | ||
14429 | /* "network" configuration display. */ | |
14430 | if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP) | |
14431 | { | |
14432 | u_int32_t destination; | |
14433 | struct in_addr netmask; | |
14434 | ||
14435 | destination = ntohl (p->u.prefix4.s_addr); | |
14436 | masklen2ip (p->prefixlen, &netmask); | |
0b960b4d | 14437 | vty_out (vty, " network %s", |
718e3744 | 14438 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN)); |
14439 | ||
14440 | if ((IN_CLASSC (destination) && p->prefixlen == 24) | |
14441 | || (IN_CLASSB (destination) && p->prefixlen == 16) | |
14442 | || (IN_CLASSA (destination) && p->prefixlen == 8) | |
14443 | || p->u.prefix4.s_addr == 0) | |
14444 | { | |
14445 | /* Natural mask is not display. */ | |
14446 | } | |
14447 | else | |
14448 | vty_out (vty, " mask %s", inet_ntoa (netmask)); | |
14449 | } | |
14450 | else | |
14451 | { | |
0b960b4d | 14452 | vty_out (vty, " network %s/%d", |
718e3744 | 14453 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
14454 | p->prefixlen); | |
14455 | } | |
14456 | ||
14457 | if (bgp_static->rmap.name) | |
14458 | vty_out (vty, " route-map %s", bgp_static->rmap.name); | |
41367172 PJ |
14459 | else |
14460 | { | |
14461 | if (bgp_static->backdoor) | |
14462 | vty_out (vty, " backdoor"); | |
41367172 | 14463 | } |
718e3744 | 14464 | |
14465 | vty_out (vty, "%s", VTY_NEWLINE); | |
14466 | } | |
14467 | ||
14468 | /* Aggregate-address configuration. */ | |
14469 | for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn)) | |
14470 | if ((bgp_aggregate = rn->info) != NULL) | |
14471 | { | |
14472 | p = &rn->p; | |
14473 | ||
14474 | /* "address-family" display. */ | |
14475 | bgp_config_write_family_header (vty, afi, safi, write); | |
14476 | ||
14477 | if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP) | |
14478 | { | |
14479 | struct in_addr netmask; | |
14480 | ||
14481 | masklen2ip (p->prefixlen, &netmask); | |
0b960b4d | 14482 | vty_out (vty, " aggregate-address %s %s", |
718e3744 | 14483 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
14484 | inet_ntoa (netmask)); | |
14485 | } | |
14486 | else | |
14487 | { | |
0b960b4d | 14488 | vty_out (vty, " aggregate-address %s/%d", |
718e3744 | 14489 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
14490 | p->prefixlen); | |
14491 | } | |
14492 | ||
14493 | if (bgp_aggregate->as_set) | |
14494 | vty_out (vty, " as-set"); | |
14495 | ||
14496 | if (bgp_aggregate->summary_only) | |
14497 | vty_out (vty, " summary-only"); | |
14498 | ||
14499 | vty_out (vty, "%s", VTY_NEWLINE); | |
14500 | } | |
14501 | ||
14502 | return 0; | |
14503 | } | |
14504 | ||
14505 | int | |
734b349e MZ |
14506 | bgp_config_write_distance (struct vty *vty, struct bgp *bgp, afi_t afi, |
14507 | safi_t safi, int *write) | |
718e3744 | 14508 | { |
14509 | struct bgp_node *rn; | |
14510 | struct bgp_distance *bdistance; | |
14511 | ||
14512 | /* Distance configuration. */ | |
734b349e MZ |
14513 | if (bgp->distance_ebgp[afi][safi] |
14514 | && bgp->distance_ibgp[afi][safi] | |
14515 | && bgp->distance_local[afi][safi] | |
14516 | && (bgp->distance_ebgp[afi][safi] != ZEBRA_EBGP_DISTANCE_DEFAULT | |
14517 | || bgp->distance_ibgp[afi][safi] != ZEBRA_IBGP_DISTANCE_DEFAULT | |
14518 | || bgp->distance_local[afi][safi] != ZEBRA_IBGP_DISTANCE_DEFAULT)) | |
14519 | { | |
14520 | bgp_config_write_family_header (vty, afi, safi, write); | |
14521 | vty_out (vty, " distance bgp %d %d %d%s", | |
14522 | bgp->distance_ebgp[afi][safi], bgp->distance_ibgp[afi][safi], | |
14523 | bgp->distance_local[afi][safi], VTY_NEWLINE); | |
14524 | } | |
14525 | ||
14526 | for (rn = bgp_table_top (bgp_distance_table[afi][safi]); rn; | |
14527 | rn = bgp_route_next (rn)) | |
718e3744 | 14528 | if ((bdistance = rn->info) != NULL) |
14529 | { | |
734b349e MZ |
14530 | char buf[PREFIX_STRLEN]; |
14531 | ||
14532 | bgp_config_write_family_header (vty, afi, safi, write); | |
14533 | vty_out (vty, " distance %d %s %s%s", bdistance->distance, | |
14534 | prefix2str (&rn->p, buf, sizeof (buf)), | |
718e3744 | 14535 | bdistance->access_list ? bdistance->access_list : "", |
14536 | VTY_NEWLINE); | |
14537 | } | |
14538 | ||
734b349e | 14539 | return *write; |
718e3744 | 14540 | } |
14541 | ||
14542 | /* Allocate routing table structure and install commands. */ | |
14543 | void | |
66e5cd87 | 14544 | bgp_route_init (void) |
718e3744 | 14545 | { |
734b349e MZ |
14546 | afi_t afi; |
14547 | safi_t safi; | |
14548 | ||
718e3744 | 14549 | /* Init BGP distance table. */ |
734b349e MZ |
14550 | for (afi = AFI_IP; afi < AFI_MAX; afi++) |
14551 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) | |
14552 | bgp_distance_table[afi][safi] = bgp_table_init (afi, safi); | |
718e3744 | 14553 | |
14554 | /* IPv4 BGP commands. */ | |
73ac8160 | 14555 | install_element (BGP_NODE, &bgp_table_map_cmd); |
718e3744 | 14556 | install_element (BGP_NODE, &bgp_network_cmd); |
14557 | install_element (BGP_NODE, &bgp_network_mask_cmd); | |
14558 | install_element (BGP_NODE, &bgp_network_mask_natural_cmd); | |
14559 | install_element (BGP_NODE, &bgp_network_route_map_cmd); | |
14560 | install_element (BGP_NODE, &bgp_network_mask_route_map_cmd); | |
14561 | install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd); | |
14562 | install_element (BGP_NODE, &bgp_network_backdoor_cmd); | |
14563 | install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd); | |
14564 | install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd); | |
73ac8160 | 14565 | install_element (BGP_NODE, &no_bgp_table_map_cmd); |
718e3744 | 14566 | install_element (BGP_NODE, &no_bgp_network_cmd); |
14567 | install_element (BGP_NODE, &no_bgp_network_mask_cmd); | |
14568 | install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd); | |
14569 | install_element (BGP_NODE, &no_bgp_network_route_map_cmd); | |
14570 | install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd); | |
14571 | install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd); | |
14572 | install_element (BGP_NODE, &no_bgp_network_backdoor_cmd); | |
14573 | install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd); | |
14574 | install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd); | |
14575 | ||
14576 | install_element (BGP_NODE, &aggregate_address_cmd); | |
14577 | install_element (BGP_NODE, &aggregate_address_mask_cmd); | |
14578 | install_element (BGP_NODE, &aggregate_address_summary_only_cmd); | |
14579 | install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd); | |
14580 | install_element (BGP_NODE, &aggregate_address_as_set_cmd); | |
14581 | install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd); | |
14582 | install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd); | |
14583 | install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd); | |
14584 | install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd); | |
14585 | install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd); | |
14586 | install_element (BGP_NODE, &no_aggregate_address_cmd); | |
14587 | install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd); | |
14588 | install_element (BGP_NODE, &no_aggregate_address_as_set_cmd); | |
14589 | install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd); | |
14590 | install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd); | |
14591 | install_element (BGP_NODE, &no_aggregate_address_mask_cmd); | |
14592 | install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd); | |
14593 | install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd); | |
14594 | install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd); | |
14595 | install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd); | |
14596 | ||
14597 | /* IPv4 unicast configuration. */ | |
73ac8160 | 14598 | install_element (BGP_IPV4_NODE, &bgp_table_map_cmd); |
718e3744 | 14599 | install_element (BGP_IPV4_NODE, &bgp_network_cmd); |
14600 | install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd); | |
14601 | install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd); | |
14602 | install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd); | |
14603 | install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd); | |
14604 | install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd); | |
73ac8160 | 14605 | install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd); |
c8f3fe30 | 14606 | install_element (BGP_IPV4_NODE, &no_bgp_network_cmd); |
718e3744 | 14607 | install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd); |
14608 | install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd); | |
14609 | install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd); | |
14610 | install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd); | |
14611 | install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd); | |
c8f3fe30 | 14612 | |
718e3744 | 14613 | install_element (BGP_IPV4_NODE, &aggregate_address_cmd); |
14614 | install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd); | |
14615 | install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd); | |
14616 | install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd); | |
14617 | install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd); | |
14618 | install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd); | |
14619 | install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd); | |
14620 | install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd); | |
14621 | install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd); | |
14622 | install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd); | |
14623 | install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd); | |
14624 | install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd); | |
14625 | install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd); | |
14626 | install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd); | |
14627 | install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd); | |
14628 | install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd); | |
14629 | install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd); | |
14630 | install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd); | |
14631 | install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd); | |
14632 | install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd); | |
14633 | ||
14634 | /* IPv4 multicast configuration. */ | |
73ac8160 | 14635 | install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd); |
718e3744 | 14636 | install_element (BGP_IPV4M_NODE, &bgp_network_cmd); |
14637 | install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd); | |
14638 | install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd); | |
14639 | install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd); | |
14640 | install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd); | |
14641 | install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd); | |
73ac8160 | 14642 | install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd); |
718e3744 | 14643 | install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd); |
14644 | install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd); | |
14645 | install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd); | |
14646 | install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd); | |
14647 | install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd); | |
14648 | install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd); | |
14649 | install_element (BGP_IPV4M_NODE, &aggregate_address_cmd); | |
14650 | install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd); | |
14651 | install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd); | |
14652 | install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd); | |
14653 | install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd); | |
14654 | install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd); | |
14655 | install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd); | |
14656 | install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd); | |
14657 | install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd); | |
14658 | install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd); | |
14659 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd); | |
14660 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd); | |
14661 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd); | |
14662 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd); | |
14663 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd); | |
14664 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd); | |
14665 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd); | |
14666 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd); | |
14667 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd); | |
14668 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd); | |
14669 | ||
14670 | install_element (VIEW_NODE, &show_ip_bgp_cmd); | |
8386ac43 | 14671 | install_element (VIEW_NODE, &show_ip_bgp_instance_cmd); |
f186de26 | 14672 | install_element (VIEW_NODE, &show_ip_bgp_instance_all_cmd); |
718e3744 | 14673 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd); |
95cbbd2a | 14674 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd); |
718e3744 | 14675 | install_element (VIEW_NODE, &show_ip_bgp_route_cmd); |
8386ac43 | 14676 | install_element (VIEW_NODE, &show_ip_bgp_instance_route_cmd); |
4092b06c | 14677 | install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd); |
8386ac43 | 14678 | install_element (VIEW_NODE, &show_ip_bgp_instance_route_pathtype_cmd); |
4092b06c | 14679 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd); |
718e3744 | 14680 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd); |
95cbbd2a | 14681 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd); |
718e3744 | 14682 | install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd); |
8386ac43 | 14683 | install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd); |
718e3744 | 14684 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd); |
4092b06c DS |
14685 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd); |
14686 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd); | |
95cbbd2a | 14687 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd); |
4092b06c | 14688 | install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd); |
8386ac43 | 14689 | install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd); |
50ef26d4 | 14690 | |
718e3744 | 14691 | install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd); |
14692 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd); | |
14693 | install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd); | |
8386ac43 | 14694 | install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_list_cmd); |
718e3744 | 14695 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd); |
14696 | install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd); | |
8386ac43 | 14697 | install_element (VIEW_NODE, &show_ip_bgp_instance_filter_list_cmd); |
718e3744 | 14698 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd); |
14699 | install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd); | |
8386ac43 | 14700 | install_element (VIEW_NODE, &show_ip_bgp_instance_route_map_cmd); |
718e3744 | 14701 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd); |
14702 | install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd); | |
14703 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd); | |
14704 | install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd); | |
14705 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd); | |
14706 | install_element (VIEW_NODE, &show_ip_bgp_community_cmd); | |
14707 | install_element (VIEW_NODE, &show_ip_bgp_community2_cmd); | |
14708 | install_element (VIEW_NODE, &show_ip_bgp_community3_cmd); | |
14709 | install_element (VIEW_NODE, &show_ip_bgp_community4_cmd); | |
14710 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd); | |
14711 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd); | |
14712 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd); | |
14713 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd); | |
8386ac43 | 14714 | install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_all_cmd); |
14715 | install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_cmd); | |
14716 | install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community2_cmd); | |
14717 | install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community3_cmd); | |
14718 | install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community4_cmd); | |
718e3744 | 14719 | install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd); |
14720 | install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd); | |
14721 | install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd); | |
14722 | install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd); | |
14723 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd); | |
14724 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd); | |
14725 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd); | |
14726 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd); | |
14727 | install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd); | |
8386ac43 | 14728 | install_element (VIEW_NODE, &show_ip_bgp_instance_community_list_cmd); |
718e3744 | 14729 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd); |
14730 | install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd); | |
14731 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd); | |
14732 | install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd); | |
8386ac43 | 14733 | install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_longer_cmd); |
718e3744 | 14734 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd); |
14735 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd); | |
8386ac43 | 14736 | install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd); |
0b16f239 | 14737 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd); |
8386ac43 | 14738 | install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd); |
718e3744 | 14739 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd); |
0b16f239 | 14740 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd); |
718e3744 | 14741 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd); |
8386ac43 | 14742 | install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd); |
0b16f239 | 14743 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd); |
8386ac43 | 14744 | install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd); |
718e3744 | 14745 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd); |
0b16f239 | 14746 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd); |
8386ac43 | 14747 | install_element (VIEW_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd); |
718e3744 | 14748 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd); |
8386ac43 | 14749 | install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_routes_cmd); |
718e3744 | 14750 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd); |
14751 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd); | |
14752 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd); | |
81304aaf | 14753 | install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd); |
58a90275 | 14754 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd); |
718e3744 | 14755 | install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd); |
58a90275 B |
14756 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd); |
14757 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd); | |
81304aaf | 14758 | install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd); |
718e3744 | 14759 | install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd); |
81304aaf | 14760 | install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd); |
718e3744 | 14761 | install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd); |
81304aaf | 14762 | install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd); |
718e3744 | 14763 | install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd); |
14764 | install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd); | |
81304aaf | 14765 | install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd); |
718e3744 | 14766 | install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd); |
14767 | install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd); | |
81304aaf | 14768 | install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd); |
718e3744 | 14769 | install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd); |
81304aaf | 14770 | install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd); |
718e3744 | 14771 | install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd); |
81304aaf | 14772 | install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd); |
718e3744 | 14773 | install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd); |
81304aaf | 14774 | install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd); |
718e3744 | 14775 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd); |
14776 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd); | |
14777 | ||
e3e29b32 | 14778 | install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd); |
ccbb332a LB |
14779 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd); |
14780 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd); | |
14781 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd); | |
14782 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd); | |
e3e29b32 | 14783 | |
718e3744 | 14784 | /* BGP dampening clear commands */ |
14785 | install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd); | |
14786 | install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd); | |
14787 | install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd); | |
14788 | install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd); | |
14789 | ||
ff7924f6 PJ |
14790 | /* prefix count */ |
14791 | install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd); | |
8386ac43 | 14792 | install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd); |
ff7924f6 | 14793 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd); |
718e3744 | 14794 | #ifdef HAVE_IPV6 |
ff7924f6 | 14795 | install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd); |
8386ac43 | 14796 | install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd); |
ff7924f6 | 14797 | |
718e3744 | 14798 | /* New config IPv6 BGP commands. */ |
73ac8160 | 14799 | install_element (BGP_IPV6_NODE, &bgp_table_map_cmd); |
718e3744 | 14800 | install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd); |
14801 | install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd); | |
73ac8160 | 14802 | install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd); |
718e3744 | 14803 | install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd); |
14804 | install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd); | |
14805 | ||
14806 | install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd); | |
14807 | install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd); | |
14808 | install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd); | |
14809 | install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd); | |
73bfe0bd B |
14810 | |
14811 | install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd); | |
14812 | install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd); | |
718e3744 | 14813 | |
14814 | /* Old config IPv6 BGP commands. */ | |
14815 | install_element (BGP_NODE, &old_ipv6_bgp_network_cmd); | |
14816 | install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd); | |
14817 | ||
14818 | install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd); | |
14819 | install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd); | |
14820 | install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd); | |
14821 | install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd); | |
14822 | ||
14823 | install_element (VIEW_NODE, &show_bgp_cmd); | |
14824 | install_element (VIEW_NODE, &show_bgp_ipv6_cmd); | |
95cbbd2a | 14825 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd); |
718e3744 | 14826 | install_element (VIEW_NODE, &show_bgp_route_cmd); |
14827 | install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd); | |
95cbbd2a | 14828 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd); |
4092b06c DS |
14829 | install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd); |
14830 | install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd); | |
14831 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd); | |
718e3744 | 14832 | install_element (VIEW_NODE, &show_bgp_prefix_cmd); |
14833 | install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd); | |
95cbbd2a | 14834 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd); |
4092b06c DS |
14835 | install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd); |
14836 | install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd); | |
14837 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd); | |
718e3744 | 14838 | install_element (VIEW_NODE, &show_bgp_regexp_cmd); |
14839 | install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd); | |
14840 | install_element (VIEW_NODE, &show_bgp_prefix_list_cmd); | |
14841 | install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd); | |
14842 | install_element (VIEW_NODE, &show_bgp_filter_list_cmd); | |
14843 | install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd); | |
14844 | install_element (VIEW_NODE, &show_bgp_route_map_cmd); | |
14845 | install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd); | |
14846 | install_element (VIEW_NODE, &show_bgp_community_all_cmd); | |
14847 | install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd); | |
14848 | install_element (VIEW_NODE, &show_bgp_community_cmd); | |
14849 | install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd); | |
14850 | install_element (VIEW_NODE, &show_bgp_community2_cmd); | |
14851 | install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd); | |
14852 | install_element (VIEW_NODE, &show_bgp_community3_cmd); | |
14853 | install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd); | |
14854 | install_element (VIEW_NODE, &show_bgp_community4_cmd); | |
14855 | install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd); | |
14856 | install_element (VIEW_NODE, &show_bgp_community_exact_cmd); | |
14857 | install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd); | |
14858 | install_element (VIEW_NODE, &show_bgp_community2_exact_cmd); | |
14859 | install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd); | |
14860 | install_element (VIEW_NODE, &show_bgp_community3_exact_cmd); | |
14861 | install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd); | |
14862 | install_element (VIEW_NODE, &show_bgp_community4_exact_cmd); | |
14863 | install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd); | |
14864 | install_element (VIEW_NODE, &show_bgp_community_list_cmd); | |
14865 | install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd); | |
14866 | install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd); | |
14867 | install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd); | |
14868 | install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd); | |
14869 | install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd); | |
14870 | install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd); | |
14871 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd); | |
14872 | install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd); | |
14873 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd); | |
14874 | install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd); | |
14875 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd); | |
14876 | install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd); | |
14877 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd); | |
bb46e94f | 14878 | install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd); |
14879 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd); | |
14880 | install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd); | |
14881 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd); | |
8386ac43 | 14882 | install_element (VIEW_NODE, &show_bgp_instance_cmd); |
f186de26 | 14883 | install_element (VIEW_NODE, &show_bgp_instance_all_cmd); |
8386ac43 | 14884 | install_element (VIEW_NODE, &show_bgp_instance_ipv6_cmd); |
14885 | install_element (VIEW_NODE, &show_bgp_instance_route_cmd); | |
14886 | install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_cmd); | |
14887 | install_element (VIEW_NODE, &show_bgp_instance_route_pathtype_cmd); | |
14888 | install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd); | |
14889 | install_element (VIEW_NODE, &show_bgp_instance_prefix_cmd); | |
14890 | install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_cmd); | |
14891 | install_element (VIEW_NODE, &show_bgp_instance_prefix_pathtype_cmd); | |
14892 | install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd); | |
14893 | install_element (VIEW_NODE, &show_bgp_instance_prefix_list_cmd); | |
14894 | install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_list_cmd); | |
14895 | install_element (VIEW_NODE, &show_bgp_instance_filter_list_cmd); | |
14896 | install_element (VIEW_NODE, &show_bgp_instance_ipv6_filter_list_cmd); | |
14897 | install_element (VIEW_NODE, &show_bgp_instance_route_map_cmd); | |
14898 | install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_map_cmd); | |
14899 | install_element (VIEW_NODE, &show_bgp_instance_community_list_cmd); | |
14900 | install_element (VIEW_NODE, &show_bgp_instance_ipv6_community_list_cmd); | |
14901 | install_element (VIEW_NODE, &show_bgp_instance_prefix_longer_cmd); | |
14902 | install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd); | |
14903 | install_element (VIEW_NODE, &show_bgp_instance_neighbor_advertised_route_cmd); | |
14904 | install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd); | |
14905 | install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_routes_cmd); | |
14906 | install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd); | |
14907 | install_element (VIEW_NODE, &show_bgp_instance_neighbor_routes_cmd); | |
14908 | install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd); | |
14909 | install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd); | |
14910 | install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd); | |
14911 | install_element (VIEW_NODE, &show_bgp_instance_neighbor_flap_cmd); | |
14912 | install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd); | |
14913 | install_element (VIEW_NODE, &show_bgp_instance_neighbor_damp_cmd); | |
14914 | install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd); | |
718e3744 | 14915 | |
2815e61f PJ |
14916 | /* Statistics */ |
14917 | install_element (ENABLE_NODE, &show_bgp_statistics_cmd); | |
587ff0fd | 14918 | //install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd); |
2815e61f | 14919 | install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd); |
587ff0fd | 14920 | //install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd); |
2815e61f | 14921 | |
718e3744 | 14922 | /* old command */ |
14923 | install_element (VIEW_NODE, &show_ipv6_bgp_cmd); | |
14924 | install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd); | |
14925 | install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd); | |
14926 | install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd); | |
14927 | install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd); | |
14928 | install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd); | |
14929 | install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd); | |
14930 | install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd); | |
14931 | install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd); | |
14932 | install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd); | |
14933 | install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd); | |
14934 | install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd); | |
14935 | install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd); | |
14936 | install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd); | |
14937 | install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd); | |
14938 | install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd); | |
14939 | install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd); | |
14940 | install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd); | |
14941 | install_element (VIEW_NODE, &show_ipv6_mbgp_cmd); | |
14942 | install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd); | |
14943 | install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd); | |
14944 | install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd); | |
14945 | install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd); | |
14946 | install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd); | |
14947 | install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd); | |
14948 | install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd); | |
14949 | install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd); | |
14950 | install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd); | |
14951 | install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd); | |
14952 | install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd); | |
14953 | install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd); | |
14954 | install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd); | |
14955 | install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd); | |
14956 | install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd); | |
14957 | install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd); | |
14958 | install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd); | |
bb46e94f | 14959 | |
718e3744 | 14960 | /* old command */ |
14961 | install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd); | |
718e3744 | 14962 | install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd); |
718e3744 | 14963 | |
14964 | /* old command */ | |
14965 | install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd); | |
718e3744 | 14966 | install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd); |
718e3744 | 14967 | |
14968 | /* old command */ | |
14969 | install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd); | |
718e3744 | 14970 | install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd); |
718e3744 | 14971 | #endif /* HAVE_IPV6 */ |
14972 | ||
14973 | install_element (BGP_NODE, &bgp_distance_cmd); | |
14974 | install_element (BGP_NODE, &no_bgp_distance_cmd); | |
14975 | install_element (BGP_NODE, &no_bgp_distance2_cmd); | |
14976 | install_element (BGP_NODE, &bgp_distance_source_cmd); | |
14977 | install_element (BGP_NODE, &no_bgp_distance_source_cmd); | |
14978 | install_element (BGP_NODE, &bgp_distance_source_access_list_cmd); | |
14979 | install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd); | |
734b349e MZ |
14980 | install_element (BGP_IPV4_NODE, &bgp_distance_cmd); |
14981 | install_element (BGP_IPV4_NODE, &no_bgp_distance_cmd); | |
14982 | install_element (BGP_IPV4_NODE, &no_bgp_distance2_cmd); | |
14983 | install_element (BGP_IPV4_NODE, &bgp_distance_source_cmd); | |
14984 | install_element (BGP_IPV4_NODE, &no_bgp_distance_source_cmd); | |
14985 | install_element (BGP_IPV4_NODE, &bgp_distance_source_access_list_cmd); | |
14986 | install_element (BGP_IPV4_NODE, &no_bgp_distance_source_access_list_cmd); | |
14987 | install_element (BGP_IPV4M_NODE, &bgp_distance_cmd); | |
14988 | install_element (BGP_IPV4M_NODE, &no_bgp_distance_cmd); | |
14989 | install_element (BGP_IPV4M_NODE, &no_bgp_distance2_cmd); | |
14990 | install_element (BGP_IPV4M_NODE, &bgp_distance_source_cmd); | |
14991 | install_element (BGP_IPV4M_NODE, &no_bgp_distance_source_cmd); | |
14992 | install_element (BGP_IPV4M_NODE, &bgp_distance_source_access_list_cmd); | |
14993 | install_element (BGP_IPV4M_NODE, &no_bgp_distance_source_access_list_cmd); | |
14994 | install_element (BGP_IPV6_NODE, &bgp_distance_cmd); | |
14995 | install_element (BGP_IPV6_NODE, &no_bgp_distance_cmd); | |
14996 | install_element (BGP_IPV6_NODE, &no_bgp_distance2_cmd); | |
14997 | install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_cmd); | |
14998 | install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_cmd); | |
14999 | install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_access_list_cmd); | |
15000 | install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_access_list_cmd); | |
15001 | install_element (BGP_IPV6M_NODE, &bgp_distance_cmd); | |
15002 | install_element (BGP_IPV6M_NODE, &no_bgp_distance_cmd); | |
15003 | install_element (BGP_IPV6M_NODE, &no_bgp_distance2_cmd); | |
15004 | install_element (BGP_IPV6M_NODE, &ipv6_bgp_distance_source_cmd); | |
15005 | install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_distance_source_cmd); | |
15006 | install_element (BGP_IPV6M_NODE, &ipv6_bgp_distance_source_access_list_cmd); | |
15007 | install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_distance_source_access_list_cmd); | |
718e3744 | 15008 | |
15009 | install_element (BGP_NODE, &bgp_damp_set_cmd); | |
15010 | install_element (BGP_NODE, &bgp_damp_set2_cmd); | |
15011 | install_element (BGP_NODE, &bgp_damp_set3_cmd); | |
15012 | install_element (BGP_NODE, &bgp_damp_unset_cmd); | |
15013 | install_element (BGP_NODE, &bgp_damp_unset2_cmd); | |
813d4307 | 15014 | install_element (BGP_NODE, &bgp_damp_unset3_cmd); |
718e3744 | 15015 | install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd); |
15016 | install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd); | |
15017 | install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd); | |
15018 | install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd); | |
15019 | install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd); | |
813d4307 | 15020 | install_element (BGP_IPV4_NODE, &bgp_damp_unset3_cmd); |
5c9e5a8d B |
15021 | |
15022 | /* IPv4 Multicast Mode */ | |
15023 | install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd); | |
15024 | install_element (BGP_IPV4M_NODE, &bgp_damp_set2_cmd); | |
15025 | install_element (BGP_IPV4M_NODE, &bgp_damp_set3_cmd); | |
15026 | install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd); | |
15027 | install_element (BGP_IPV4M_NODE, &bgp_damp_unset2_cmd); | |
718e3744 | 15028 | } |
228da428 CC |
15029 | |
15030 | void | |
15031 | bgp_route_finish (void) | |
15032 | { | |
734b349e MZ |
15033 | afi_t afi; |
15034 | safi_t safi; | |
15035 | ||
15036 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
15037 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) | |
15038 | { | |
15039 | bgp_table_unlock (bgp_distance_table[afi][safi]); | |
15040 | bgp_distance_table[afi][safi] = NULL; | |
15041 | } | |
228da428 | 15042 | } |