]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_route.c
Merge branch 'cmaster-next' of ssh://stash.cumulusnetworks.com:7999/quag/quagga into...
[mirror_frr.git] / bgpd / bgp_route.c
CommitLineData
718e3744 1/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-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"
30#include "str.h"
31#include "log.h"
32#include "routemap.h"
33#include "buffer.h"
34#include "sockunion.h"
35#include "plist.h"
36#include "thread.h"
200df115 37#include "workqueue.h"
3f9c7369 38#include "queue.h"
6e919709 39#include "memory.h"
718e3744 40
41#include "bgpd/bgpd.h"
42#include "bgpd/bgp_table.h"
43#include "bgpd/bgp_route.h"
44#include "bgpd/bgp_attr.h"
45#include "bgpd/bgp_debug.h"
46#include "bgpd/bgp_aspath.h"
47#include "bgpd/bgp_regex.h"
48#include "bgpd/bgp_community.h"
49#include "bgpd/bgp_ecommunity.h"
50#include "bgpd/bgp_clist.h"
51#include "bgpd/bgp_packet.h"
52#include "bgpd/bgp_filter.h"
53#include "bgpd/bgp_fsm.h"
54#include "bgpd/bgp_mplsvpn.h"
55#include "bgpd/bgp_nexthop.h"
56#include "bgpd/bgp_damp.h"
57#include "bgpd/bgp_advertise.h"
58#include "bgpd/bgp_zebra.h"
0a486e5f 59#include "bgpd/bgp_vty.h"
96450faf 60#include "bgpd/bgp_mpath.h"
fc9a856f 61#include "bgpd/bgp_nht.h"
3f9c7369 62#include "bgpd/bgp_updgrp.h"
8386ac43 63#include "bgpd/bgp_vty.h"
718e3744 64
65/* Extern from bgp_dump.c */
dde72586
SH
66extern const char *bgp_origin_str[];
67extern const char *bgp_origin_long_str[];
6b0655a2 68
4125bb67 69struct bgp_node *
fee0f4c6 70bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
718e3744 71 struct prefix_rd *prd)
72{
73 struct bgp_node *rn;
74 struct bgp_node *prn = NULL;
da5b30f6
PJ
75
76 assert (table);
77 if (!table)
78 return NULL;
79
587ff0fd 80 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 81 {
fee0f4c6 82 prn = bgp_node_get (table, (struct prefix *) prd);
718e3744 83
84 if (prn->info == NULL)
64e580a7 85 prn->info = bgp_table_init (afi, safi);
718e3744 86 else
87 bgp_unlock_node (prn);
88 table = prn->info;
89 }
718e3744 90
91 rn = bgp_node_get (table, p);
92
587ff0fd 93 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 94 rn->prn = prn;
95
96 return rn;
97}
6b0655a2 98
fb982c25
PJ
99/* Allocate bgp_info_extra */
100static struct bgp_info_extra *
101bgp_info_extra_new (void)
102{
103 struct bgp_info_extra *new;
104 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
105 return new;
106}
107
108static void
109bgp_info_extra_free (struct bgp_info_extra **extra)
110{
111 if (extra && *extra)
112 {
113 if ((*extra)->damp_info)
114 bgp_damp_info_free ((*extra)->damp_info, 0);
115
116 (*extra)->damp_info = NULL;
117
118 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
119
120 *extra = NULL;
121 }
122}
123
124/* Get bgp_info extra information for the given bgp_info, lazy allocated
125 * if required.
126 */
127struct bgp_info_extra *
128bgp_info_extra_get (struct bgp_info *ri)
129{
130 if (!ri->extra)
131 ri->extra = bgp_info_extra_new();
132 return ri->extra;
133}
134
718e3744 135/* Free bgp route information. */
200df115 136static void
718e3744 137bgp_info_free (struct bgp_info *binfo)
138{
139 if (binfo->attr)
f6f434b2 140 bgp_attr_unintern (&binfo->attr);
fb018d25
DS
141
142 bgp_unlink_nexthop(binfo);
fb982c25 143 bgp_info_extra_free (&binfo->extra);
de8d5dff 144 bgp_info_mpath_free (&binfo->mpath);
718e3744 145
200df115 146 peer_unlock (binfo->peer); /* bgp_info peer reference */
147
718e3744 148 XFREE (MTYPE_BGP_ROUTE, binfo);
149}
150
200df115 151struct bgp_info *
152bgp_info_lock (struct bgp_info *binfo)
153{
154 binfo->lock++;
155 return binfo;
156}
157
158struct bgp_info *
159bgp_info_unlock (struct bgp_info *binfo)
160{
161 assert (binfo && binfo->lock > 0);
162 binfo->lock--;
163
164 if (binfo->lock == 0)
165 {
166#if 0
167 zlog_debug ("%s: unlocked and freeing", __func__);
168 zlog_backtrace (LOG_DEBUG);
169#endif
170 bgp_info_free (binfo);
171 return NULL;
172 }
173
174#if 0
175 if (binfo->lock == 1)
176 {
177 zlog_debug ("%s: unlocked to 1", __func__);
178 zlog_backtrace (LOG_DEBUG);
179 }
180#endif
181
182 return binfo;
183}
184
718e3744 185void
186bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
187{
188 struct bgp_info *top;
189
190 top = rn->info;
200df115 191
718e3744 192 ri->next = rn->info;
193 ri->prev = NULL;
194 if (top)
195 top->prev = ri;
196 rn->info = ri;
200df115 197
198 bgp_info_lock (ri);
199 bgp_lock_node (rn);
200 peer_lock (ri->peer); /* bgp_info peer reference */
718e3744 201}
202
b40d939b 203/* Do the actual removal of info from RIB, for use by bgp_process
204 completion callback *only* */
205static void
206bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
718e3744 207{
208 if (ri->next)
209 ri->next->prev = ri->prev;
210 if (ri->prev)
211 ri->prev->next = ri->next;
212 else
213 rn->info = ri->next;
200df115 214
de8d5dff 215 bgp_info_mpath_dequeue (ri);
200df115 216 bgp_info_unlock (ri);
217 bgp_unlock_node (rn);
718e3744 218}
219
b40d939b 220void
221bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
222{
1a392d46
PJ
223 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
224 /* set of previous already took care of pcount */
b40d939b 225 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
226}
227
8d45210e
AS
228/* undo the effects of a previous call to bgp_info_delete; typically
229 called when a route is deleted and then quickly re-added before the
230 deletion has been processed */
231static void
232bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
233{
234 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
235 /* unset of previous already took care of pcount */
236 SET_FLAG (ri->flags, BGP_INFO_VALID);
237}
238
1a392d46
PJ
239/* Adjust pcount as required */
240static void
241bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
242{
67174041
AS
243 struct bgp_table *table;
244
245 assert (rn && bgp_node_table (rn));
6f58544d
PJ
246 assert (ri && ri->peer && ri->peer->bgp);
247
67174041
AS
248 table = bgp_node_table (rn);
249
2a3d5731 250 if (ri->peer == ri->peer->bgp->peer_self)
1a392d46
PJ
251 return;
252
80e0ad24 253 if (!BGP_INFO_COUNTABLE (ri)
1a392d46
PJ
254 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
255 {
256
257 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
258
259 /* slight hack, but more robust against errors. */
67174041
AS
260 if (ri->peer->pcount[table->afi][table->safi])
261 ri->peer->pcount[table->afi][table->safi]--;
1a392d46
PJ
262 else
263 {
264 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
265 __func__, ri->peer->host);
266 zlog_backtrace (LOG_WARNING);
267 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
268 }
269 }
80e0ad24 270 else if (BGP_INFO_COUNTABLE (ri)
1a392d46
PJ
271 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
272 {
273 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
67174041 274 ri->peer->pcount[table->afi][table->safi]++;
1a392d46
PJ
275 }
276}
277
278
279/* Set/unset bgp_info flags, adjusting any other state as needed.
280 * This is here primarily to keep prefix-count in check.
281 */
282void
283bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
284{
285 SET_FLAG (ri->flags, flag);
286
80e0ad24
DS
287 /* early bath if we know it's not a flag that changes countability state */
288 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
1a392d46
PJ
289 return;
290
291 bgp_pcount_adjust (rn, ri);
292}
293
294void
295bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
296{
297 UNSET_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
718e3744 306/* Get MED value. If MED value is missing and "bgp bestpath
307 missing-as-worst" is specified, treat it as the worst value. */
94f2b392 308static u_int32_t
718e3744 309bgp_med_value (struct attr *attr, struct bgp *bgp)
310{
311 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
312 return attr->med;
313 else
314 {
315 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
3b424979 316 return BGP_MED_MAX;
718e3744 317 else
318 return 0;
319 }
320}
321
2ec1e66f
DW
322void
323bgp_info_path_with_addpath_rx_str (struct bgp_info *ri, char *buf)
324{
325 if (ri->addpath_rx_id)
326 sprintf(buf, "path %s (addpath rxid %d)", ri->peer->host, ri->addpath_rx_id);
327 else
328 sprintf(buf, "path %s", ri->peer->host);
329}
330
9fbdd100 331/* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1. */
94f2b392 332static int
96450faf 333bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
9fbdd100
DS
334 int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg, int debug,
335 char *pfx_buf)
718e3744 336{
8ff56318
JBD
337 struct attr *newattr, *existattr;
338 struct attr_extra *newattre, *existattre;
339 bgp_peer_sort_t new_sort;
340 bgp_peer_sort_t exist_sort;
718e3744 341 u_int32_t new_pref;
342 u_int32_t exist_pref;
343 u_int32_t new_med;
344 u_int32_t exist_med;
8ff56318
JBD
345 u_int32_t new_weight;
346 u_int32_t exist_weight;
347 uint32_t newm, existm;
718e3744 348 struct in_addr new_id;
349 struct in_addr exist_id;
350 int new_cluster;
351 int exist_cluster;
8ff56318
JBD
352 int internal_as_route;
353 int confed_as_route;
718e3744 354 int ret;
2ec1e66f
DW
355 char new_buf[PATH_ADDPATH_STR_BUFFER];
356 char exist_buf[PATH_ADDPATH_STR_BUFFER];
96450faf
JB
357
358 *paths_eq = 0;
718e3744 359
360 /* 0. Null check. */
361 if (new == NULL)
9fbdd100
DS
362 {
363 if (debug)
364 zlog_debug("%s: new is NULL", pfx_buf);
365 return 0;
366 }
367
2ec1e66f
DW
368 if (debug)
369 bgp_info_path_with_addpath_rx_str (new, new_buf);
370
718e3744 371 if (exist == NULL)
9fbdd100
DS
372 {
373 if (debug)
2ec1e66f 374 zlog_debug("%s: %s is the initial bestpath", pfx_buf, new_buf);
9fbdd100
DS
375 return 1;
376 }
718e3744 377
2ec1e66f
DW
378 if (debug)
379 bgp_info_path_with_addpath_rx_str (exist, exist_buf);
380
8ff56318
JBD
381 newattr = new->attr;
382 existattr = exist->attr;
383 newattre = newattr->extra;
384 existattre = existattr->extra;
385
718e3744 386 /* 1. Weight check. */
8ff56318
JBD
387 new_weight = exist_weight = 0;
388
389 if (newattre)
390 new_weight = newattre->weight;
391 if (existattre)
392 exist_weight = existattre->weight;
393
fb982c25 394 if (new_weight > exist_weight)
9fbdd100
DS
395 {
396 if (debug)
2ec1e66f
DW
397 zlog_debug("%s: %s wins over %s due to weight %d > %d",
398 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
9fbdd100
DS
399 return 1;
400 }
401
fb982c25 402 if (new_weight < exist_weight)
9fbdd100
DS
403 {
404 if (debug)
2ec1e66f
DW
405 zlog_debug("%s: %s loses to %s due to weight %d < %d",
406 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
9fbdd100
DS
407 return 0;
408 }
718e3744 409
410 /* 2. Local preference check. */
8ff56318
JBD
411 new_pref = exist_pref = bgp->default_local_pref;
412
413 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
414 new_pref = newattr->local_pref;
415 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
416 exist_pref = existattr->local_pref;
718e3744 417
718e3744 418 if (new_pref > exist_pref)
9fbdd100
DS
419 {
420 if (debug)
2ec1e66f
DW
421 zlog_debug("%s: %s wins over %s due to localpref %d > %d",
422 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
9fbdd100
DS
423 return 1;
424 }
425
718e3744 426 if (new_pref < exist_pref)
9fbdd100
DS
427 {
428 if (debug)
2ec1e66f
DW
429 zlog_debug("%s: %s loses to %s due to localpref %d < %d",
430 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
9fbdd100
DS
431 return 0;
432 }
718e3744 433
8ff56318
JBD
434 /* 3. Local route check. We prefer:
435 * - BGP_ROUTE_STATIC
436 * - BGP_ROUTE_AGGREGATE
437 * - BGP_ROUTE_REDISTRIBUTE
438 */
439 if (! (new->sub_type == BGP_ROUTE_NORMAL))
9fbdd100
DS
440 {
441 if (debug)
2ec1e66f
DW
442 zlog_debug("%s: %s wins over %s due to preferred BGP_ROUTE type",
443 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
444 return 1;
445 }
446
8ff56318 447 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
9fbdd100
DS
448 {
449 if (debug)
2ec1e66f
DW
450 zlog_debug("%s: %s loses to %s due to preferred BGP_ROUTE type",
451 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
452 return 0;
453 }
718e3744 454
455 /* 4. AS path length check. */
456 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
457 {
8ff56318
JBD
458 int exist_hops = aspath_count_hops (existattr->aspath);
459 int exist_confeds = aspath_count_confeds (existattr->aspath);
fe69a505 460
6811845b 461 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
462 {
fe69a505 463 int aspath_hops;
464
8ff56318
JBD
465 aspath_hops = aspath_count_hops (newattr->aspath);
466 aspath_hops += aspath_count_confeds (newattr->aspath);
fe69a505 467
468 if ( aspath_hops < (exist_hops + exist_confeds))
9fbdd100
DS
469 {
470 if (debug)
2ec1e66f
DW
471 zlog_debug("%s: %s wins over %s due to aspath (with confeds) hopcount %d < %d",
472 pfx_buf, new_buf, exist_buf,
9fbdd100
DS
473 aspath_hops, (exist_hops + exist_confeds));
474 return 1;
475 }
476
fe69a505 477 if ( aspath_hops > (exist_hops + exist_confeds))
9fbdd100
DS
478 {
479 if (debug)
2ec1e66f
DW
480 zlog_debug("%s: %s loses to %s due to aspath (with confeds) hopcount %d > %d",
481 pfx_buf, new_buf, exist_buf,
9fbdd100
DS
482 aspath_hops, (exist_hops + exist_confeds));
483 return 0;
484 }
6811845b 485 }
486 else
487 {
8ff56318 488 int newhops = aspath_count_hops (newattr->aspath);
fe69a505 489
490 if (newhops < exist_hops)
9fbdd100
DS
491 {
492 if (debug)
2ec1e66f
DW
493 zlog_debug("%s: %s wins over %s due to aspath hopcount %d < %d",
494 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
9fbdd100
DS
495 return 1;
496 }
497
fe69a505 498 if (newhops > exist_hops)
9fbdd100
DS
499 {
500 if (debug)
2ec1e66f
DW
501 zlog_debug("%s: %s loses to %s due to aspath hopcount %d > %d",
502 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
9fbdd100
DS
503 return 0;
504 }
6811845b 505 }
718e3744 506 }
507
508 /* 5. Origin check. */
8ff56318 509 if (newattr->origin < existattr->origin)
9fbdd100
DS
510 {
511 if (debug)
2ec1e66f
DW
512 zlog_debug("%s: %s wins over %s due to ORIGIN %s < %s",
513 pfx_buf, new_buf, exist_buf,
9fbdd100
DS
514 bgp_origin_long_str[newattr->origin],
515 bgp_origin_long_str[existattr->origin]);
516 return 1;
517 }
518
8ff56318 519 if (newattr->origin > existattr->origin)
9fbdd100
DS
520 {
521 if (debug)
2ec1e66f
DW
522 zlog_debug("%s: %s loses to %s due to ORIGIN %s > %s",
523 pfx_buf, new_buf, exist_buf,
9fbdd100
DS
524 bgp_origin_long_str[newattr->origin],
525 bgp_origin_long_str[existattr->origin]);
526 return 0;
527 }
718e3744 528
529 /* 6. MED check. */
8ff56318
JBD
530 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
531 && aspath_count_hops (existattr->aspath) == 0);
532 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
533 && aspath_count_confeds (existattr->aspath) > 0
534 && aspath_count_hops (newattr->aspath) == 0
535 && aspath_count_hops (existattr->aspath) == 0);
718e3744 536
537 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
538 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
539 && confed_as_route)
8ff56318
JBD
540 || aspath_cmp_left (newattr->aspath, existattr->aspath)
541 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
718e3744 542 || internal_as_route)
543 {
544 new_med = bgp_med_value (new->attr, bgp);
545 exist_med = bgp_med_value (exist->attr, bgp);
546
547 if (new_med < exist_med)
9fbdd100
DS
548 {
549 if (debug)
2ec1e66f
DW
550 zlog_debug("%s: %s wins over %s due to MED %d < %d",
551 pfx_buf, new_buf, exist_buf, new_med, exist_med);
9fbdd100
DS
552 return 1;
553 }
554
718e3744 555 if (new_med > exist_med)
9fbdd100
DS
556 {
557 if (debug)
2ec1e66f
DW
558 zlog_debug("%s: %s loses to %s due to MED %d > %d",
559 pfx_buf, new_buf, exist_buf, new_med, exist_med);
9fbdd100
DS
560 return 0;
561 }
718e3744 562 }
563
564 /* 7. Peer type check. */
8ff56318
JBD
565 new_sort = new->peer->sort;
566 exist_sort = exist->peer->sort;
567
568 if (new_sort == BGP_PEER_EBGP
569 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
9fbdd100
DS
570 {
571 if (debug)
2ec1e66f
DW
572 zlog_debug("%s: %s wins over %s due to eBGP peer > iBGP peer",
573 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
574 return 1;
575 }
576
8ff56318
JBD
577 if (exist_sort == BGP_PEER_EBGP
578 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
9fbdd100
DS
579 {
580 if (debug)
2ec1e66f
DW
581 zlog_debug("%s: %s loses to %s due to iBGP peer < eBGP peer",
582 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
583 return 0;
584 }
718e3744 585
586 /* 8. IGP metric check. */
8ff56318
JBD
587 newm = existm = 0;
588
589 if (new->extra)
590 newm = new->extra->igpmetric;
591 if (exist->extra)
592 existm = exist->extra->igpmetric;
593
96450faf 594 if (newm < existm)
9fbdd100
DS
595 {
596 if (debug)
2ec1e66f
DW
597 zlog_debug("%s: %s wins over %s due to IGP metric %d < %d",
598 pfx_buf, new_buf, exist_buf, newm, existm);
9fbdd100
DS
599 ret = 1;
600 }
601
96450faf 602 if (newm > existm)
9fbdd100
DS
603 {
604 if (debug)
2ec1e66f
DW
605 zlog_debug("%s: %s loses to %s due to IGP metric %d > %d",
606 pfx_buf, new_buf, exist_buf, newm, existm);
9fbdd100
DS
607 ret = 0;
608 }
718e3744 609
31a4638f 610 /* 9. Same IGP metric. Compare the cluster list length as
5e242b0d
DS
611 representative of IGP hops metric. Rewrite the metric value
612 pair (newm, existm) with the cluster list length. Prefer the
613 path with smaller cluster list length. */
614 if (newm == existm)
615 {
616 if (peer_sort (new->peer) == BGP_PEER_IBGP
617 && peer_sort (exist->peer) == BGP_PEER_IBGP
618 && CHECK_FLAG (mpath_cfg->ibgp_flags,
619 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
620 {
621 newm = BGP_CLUSTER_LIST_LENGTH(new->attr);
622 existm = BGP_CLUSTER_LIST_LENGTH(exist->attr);
9fbdd100 623
5e242b0d 624 if (newm < existm)
9fbdd100
DS
625 {
626 if (debug)
2ec1e66f
DW
627 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
628 pfx_buf, new_buf, exist_buf, newm, existm);
9fbdd100
DS
629 ret = 1;
630 }
631
5e242b0d 632 if (newm > existm)
9fbdd100
DS
633 {
634 if (debug)
2ec1e66f
DW
635 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
636 pfx_buf, new_buf, exist_buf, newm, existm);
9fbdd100
DS
637 ret = 0;
638 }
5e242b0d
DS
639 }
640 }
641
31a4638f
DS
642 /* 10. confed-external vs. confed-internal */
643 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
644 {
645 if (new_sort == BGP_PEER_CONFED && exist_sort == BGP_PEER_IBGP)
646 {
647 if (debug)
2ec1e66f
DW
648 zlog_debug("%s: %s wins over %s due to confed-external peer > confed-internal peer",
649 pfx_buf, new_buf, exist_buf);
31a4638f
DS
650 return 1;
651 }
652
653 if (exist_sort == BGP_PEER_CONFED && new_sort == BGP_PEER_IBGP)
654 {
655 if (debug)
2ec1e66f
DW
656 zlog_debug("%s: %s loses to %s due to confed-internal peer < confed-external peer",
657 pfx_buf, new_buf, exist_buf);
31a4638f
DS
658 return 0;
659 }
660 }
661
662 /* 11. Maximum path check. */
96450faf
JB
663 if (newm == existm)
664 {
2fdd455c
PM
665 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
666 {
667
668 /*
669 * For the two paths, all comparison steps till IGP metric
670 * have succeeded - including AS_PATH hop count. Since 'bgp
671 * bestpath as-path multipath-relax' knob is on, we don't need
672 * an exact match of AS_PATH. Thus, mark the paths are equal.
673 * That will trigger both these paths to get into the multipath
674 * array.
675 */
676 *paths_eq = 1;
9fbdd100
DS
677
678 if (debug)
2ec1e66f
DW
679 zlog_debug("%s: %s and %s are equal via multipath-relax",
680 pfx_buf, new_buf, exist_buf);
2fdd455c
PM
681 }
682 else if (new->peer->sort == BGP_PEER_IBGP)
96450faf
JB
683 {
684 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
9fbdd100
DS
685 {
686 *paths_eq = 1;
687
688 if (debug)
2ec1e66f
DW
689 zlog_debug("%s: %s and %s are equal via matching aspaths",
690 pfx_buf, new_buf, exist_buf);
9fbdd100 691 }
96450faf
JB
692 }
693 else if (new->peer->as == exist->peer->as)
9fbdd100
DS
694 {
695 *paths_eq = 1;
696
697 if (debug)
2ec1e66f
DW
698 zlog_debug("%s: %s and %s are equal via same remote-as",
699 pfx_buf, new_buf, exist_buf);
9fbdd100 700 }
96450faf
JB
701 }
702 else
703 {
704 /*
705 * TODO: If unequal cost ibgp multipath is enabled we can
706 * mark the paths as equal here instead of returning
707 */
708 return ret;
709 }
718e3744 710
31a4638f 711 /* 12. If both paths are external, prefer the path that was received
718e3744 712 first (the oldest one). This step minimizes route-flap, since a
713 newer path won't displace an older one, even if it was the
714 preferred route based on the additional decision criteria below. */
715 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
8ff56318
JBD
716 && new_sort == BGP_PEER_EBGP
717 && exist_sort == BGP_PEER_EBGP)
718e3744 718 {
719 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
9fbdd100
DS
720 {
721 if (debug)
2ec1e66f
DW
722 zlog_debug("%s: %s wins over %s due to oldest external",
723 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
724 return 1;
725 }
726
718e3744 727 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
9fbdd100
DS
728 {
729 if (debug)
2ec1e66f
DW
730 zlog_debug("%s: %s loses to %s due to oldest external",
731 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
732 return 0;
733 }
718e3744 734 }
735
31a4638f 736 /* 13. Router-ID comparision. */
0de5153c
DS
737 /* If one of the paths is "stale", the corresponding peer router-id will
738 * be 0 and would always win over the other path. If originator id is
739 * used for the comparision, it will decide which path is better.
740 */
8ff56318
JBD
741 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
742 new_id.s_addr = newattre->originator_id.s_addr;
718e3744 743 else
744 new_id.s_addr = new->peer->remote_id.s_addr;
8ff56318
JBD
745 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
746 exist_id.s_addr = existattre->originator_id.s_addr;
718e3744 747 else
748 exist_id.s_addr = exist->peer->remote_id.s_addr;
749
750 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
9fbdd100
DS
751 {
752 if (debug)
2ec1e66f
DW
753 zlog_debug("%s: %s wins over %s due to Router-ID comparison",
754 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
755 return 1;
756 }
757
718e3744 758 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
9fbdd100
DS
759 {
760 if (debug)
2ec1e66f
DW
761 zlog_debug("%s: %s loses to %s due to Router-ID comparison",
762 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
763 return 0;
764 }
718e3744 765
31a4638f 766 /* 14. Cluster length comparision. */
5e242b0d
DS
767 new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
768 exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
718e3744 769
770 if (new_cluster < exist_cluster)
9fbdd100
DS
771 {
772 if (debug)
2ec1e66f
DW
773 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
774 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
9fbdd100
DS
775 return 1;
776 }
777
718e3744 778 if (new_cluster > exist_cluster)
9fbdd100
DS
779 {
780 if (debug)
2ec1e66f
DW
781 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
782 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
9fbdd100
DS
783 return 0;
784 }
718e3744 785
31a4638f 786 /* 15. Neighbor address comparision. */
0de5153c
DS
787 /* Do this only if neither path is "stale" as stale paths do not have
788 * valid peer information (as the connection may or may not be up).
789 */
790 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
9fbdd100
DS
791 {
792 if (debug)
2ec1e66f
DW
793 zlog_debug("%s: %s wins over %s due to latter path being STALE",
794 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
795 return 1;
796 }
797
0de5153c 798 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
9fbdd100
DS
799 {
800 if (debug)
2ec1e66f
DW
801 zlog_debug("%s: %s loses to %s due to former path being STALE",
802 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
803 return 0;
804 }
0de5153c 805
43ed4fe5
TT
806 /* locally configured routes to advertise do not have su_remote */
807 if (new->peer->su_remote == NULL)
808 return 0;
809 if (exist->peer->su_remote == NULL)
810 return 1;
811
718e3744 812 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
813
814 if (ret == 1)
9fbdd100
DS
815 {
816 if (debug)
2ec1e66f
DW
817 zlog_debug("%s: %s loses to %s due to Neighor IP comparison",
818 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
819 return 0;
820 }
821
718e3744 822 if (ret == -1)
9fbdd100
DS
823 {
824 if (debug)
2ec1e66f
DW
825 zlog_debug("%s: %s wins over %s due to Neighor IP comparison",
826 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
827 return 1;
828 }
829
830 if (debug)
2ec1e66f
DW
831 zlog_debug("%s: %s wins over %s due to nothing left to compare",
832 pfx_buf, new_buf, exist_buf);
718e3744 833
834 return 1;
835}
836
94f2b392 837static enum filter_type
718e3744 838bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
839 afi_t afi, safi_t safi)
840{
841 struct bgp_filter *filter;
842
843 filter = &peer->filter[afi][safi];
844
650f76c2
PJ
845#define FILTER_EXIST_WARN(F,f,filter) \
846 if (BGP_DEBUG (update, UPDATE_IN) \
847 && !(F ## _IN (filter))) \
16286195 848 zlog_warn ("%s: Could not find configured input %s-list %s!", \
650f76c2
PJ
849 peer->host, #f, F ## _IN_NAME(filter));
850
851 if (DISTRIBUTE_IN_NAME (filter)) {
852 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
853
718e3744 854 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
855 return FILTER_DENY;
650f76c2 856 }
718e3744 857
650f76c2
PJ
858 if (PREFIX_LIST_IN_NAME (filter)) {
859 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
860
718e3744 861 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
862 return FILTER_DENY;
650f76c2 863 }
718e3744 864
650f76c2
PJ
865 if (FILTER_LIST_IN_NAME (filter)) {
866 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
867
718e3744 868 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
869 return FILTER_DENY;
650f76c2
PJ
870 }
871
718e3744 872 return FILTER_PERMIT;
650f76c2 873#undef FILTER_EXIST_WARN
718e3744 874}
875
94f2b392 876static enum filter_type
718e3744 877bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
878 afi_t afi, safi_t safi)
879{
880 struct bgp_filter *filter;
881
882 filter = &peer->filter[afi][safi];
883
650f76c2
PJ
884#define FILTER_EXIST_WARN(F,f,filter) \
885 if (BGP_DEBUG (update, UPDATE_OUT) \
886 && !(F ## _OUT (filter))) \
16286195 887 zlog_warn ("%s: Could not find configured output %s-list %s!", \
650f76c2
PJ
888 peer->host, #f, F ## _OUT_NAME(filter));
889
890 if (DISTRIBUTE_OUT_NAME (filter)) {
891 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
892
718e3744 893 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
894 return FILTER_DENY;
650f76c2 895 }
718e3744 896
650f76c2
PJ
897 if (PREFIX_LIST_OUT_NAME (filter)) {
898 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
899
718e3744 900 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
901 return FILTER_DENY;
650f76c2 902 }
718e3744 903
650f76c2
PJ
904 if (FILTER_LIST_OUT_NAME (filter)) {
905 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
906
718e3744 907 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
908 return FILTER_DENY;
650f76c2 909 }
718e3744 910
911 return FILTER_PERMIT;
650f76c2 912#undef FILTER_EXIST_WARN
718e3744 913}
914
915/* If community attribute includes no_export then return 1. */
94f2b392 916static int
718e3744 917bgp_community_filter (struct peer *peer, struct attr *attr)
918{
919 if (attr->community)
920 {
921 /* NO_ADVERTISE check. */
922 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
923 return 1;
924
925 /* NO_EXPORT check. */
6d85b15b 926 if (peer->sort == BGP_PEER_EBGP &&
718e3744 927 community_include (attr->community, COMMUNITY_NO_EXPORT))
928 return 1;
929
930 /* NO_EXPORT_SUBCONFED check. */
6d85b15b
JBD
931 if (peer->sort == BGP_PEER_EBGP
932 || peer->sort == BGP_PEER_CONFED)
718e3744 933 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
934 return 1;
935 }
936 return 0;
937}
938
939/* Route reflection loop check. */
940static int
941bgp_cluster_filter (struct peer *peer, struct attr *attr)
942{
943 struct in_addr cluster_id;
944
fb982c25 945 if (attr->extra && attr->extra->cluster)
718e3744 946 {
947 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
948 cluster_id = peer->bgp->cluster_id;
949 else
950 cluster_id = peer->bgp->router_id;
951
fb982c25 952 if (cluster_loop_check (attr->extra->cluster, cluster_id))
718e3744 953 return 1;
954 }
955 return 0;
956}
6b0655a2 957
94f2b392 958static int
718e3744 959bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
ffd0c037 960 afi_t afi, safi_t safi, const char *rmap_name)
718e3744 961{
962 struct bgp_filter *filter;
963 struct bgp_info info;
964 route_map_result_t ret;
0b16f239 965 struct route_map *rmap = NULL;
718e3744 966
967 filter = &peer->filter[afi][safi];
968
969 /* Apply default weight value. */
fb982c25
PJ
970 if (peer->weight)
971 (bgp_attr_extra_get (attr))->weight = peer->weight;
718e3744 972
0b16f239
DS
973 if (rmap_name)
974 {
975 rmap = route_map_lookup_by_name(rmap_name);
98a4a44e
DS
976
977 if (rmap == NULL)
978 return RMAP_DENY;
0b16f239
DS
979 }
980 else
981 {
982 if (ROUTE_MAP_IN_NAME(filter))
98a4a44e
DS
983 {
984 rmap = ROUTE_MAP_IN (filter);
985
986 if (rmap == NULL)
987 return RMAP_DENY;
988 }
0b16f239
DS
989 }
990
718e3744 991 /* Route map apply. */
0b16f239 992 if (rmap)
718e3744 993 {
994 /* Duplicate current value to new strucutre for modification. */
995 info.peer = peer;
996 info.attr = attr;
997
ac41b2a2 998 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
999
718e3744 1000 /* Apply BGP route map to the attribute. */
0b16f239
DS
1001 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1002
1003 peer->rmap_type = 0;
1004
1005 if (ret == RMAP_DENYMATCH)
1006 {
1007 /* Free newly generated AS path and community by route-map. */
1008 bgp_attr_flush (attr);
1009 return RMAP_DENY;
1010 }
1011 }
1012 return RMAP_PERMIT;
1013}
1014
1015static int
1016bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
ffd0c037 1017 afi_t afi, safi_t safi, const char *rmap_name)
0b16f239
DS
1018{
1019 struct bgp_filter *filter;
1020 struct bgp_info info;
1021 route_map_result_t ret;
1022 struct route_map *rmap = NULL;
1023
1024 filter = &peer->filter[afi][safi];
1025
1026 /* Apply default weight value. */
1027 if (peer->weight)
1028 (bgp_attr_extra_get (attr))->weight = peer->weight;
1029
1030 if (rmap_name)
1031 {
1032 rmap = route_map_lookup_by_name(rmap_name);
98a4a44e
DS
1033
1034 if (rmap == NULL)
1035 return RMAP_DENY;
0b16f239
DS
1036 }
1037 else
1038 {
1039 if (ROUTE_MAP_OUT_NAME(filter))
98a4a44e
DS
1040 {
1041 rmap = ROUTE_MAP_OUT (filter);
1042
1043 if (rmap == NULL)
1044 return RMAP_DENY;
1045 }
0b16f239
DS
1046 }
1047
1048 /* Route map apply. */
1049 if (rmap)
1050 {
1051 /* Duplicate current value to new strucutre for modification. */
1052 info.peer = peer;
1053 info.attr = attr;
1054
1055 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1056
1057 /* Apply BGP route map to the attribute. */
1058 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
ac41b2a2 1059
1060 peer->rmap_type = 0;
1061
718e3744 1062 if (ret == RMAP_DENYMATCH)
c460e572
DL
1063 /* caller has multiple error paths with bgp_attr_flush() */
1064 return RMAP_DENY;
718e3744 1065 }
1066 return RMAP_PERMIT;
1067}
6b0655a2 1068
5000f21c 1069/* If this is an EBGP peer with remove-private-AS */
ffd0c037 1070static void
5000f21c
DS
1071bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
1072 struct peer *peer, struct attr *attr)
1073{
1074 if (peer->sort == BGP_PEER_EBGP &&
88b8ed8d
DW
1075 (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1076 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE) ||
1077 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL) ||
1078 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)))
5000f21c
DS
1079 {
1080 // Take action on the entire aspath
88b8ed8d
DW
1081 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1082 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
5000f21c 1083 {
88b8ed8d 1084 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
5000f21c
DS
1085 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1086
1087 // The entire aspath consists of private ASNs so create an empty aspath
1088 else if (aspath_private_as_check (attr->aspath))
1089 attr->aspath = aspath_empty_get ();
1090
1091 // There are some public and some private ASNs, remove the private ASNs
1092 else
1093 attr->aspath = aspath_remove_private_asns (attr->aspath);
1094 }
1095
1096 // 'all' was not specified so the entire aspath must be private ASNs
1097 // for us to do anything
1098 else if (aspath_private_as_check (attr->aspath))
1099 {
1100 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
1101 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1102 else
1103 attr->aspath = aspath_empty_get ();
1104 }
1105 }
1106}
1107
c7122e14
DS
1108/* If this is an EBGP peer with as-override */
1109static void
1110bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
1111 struct peer *peer, struct attr *attr)
1112{
1113 if (peer->sort == BGP_PEER_EBGP &&
1114 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
1115 {
1116 if (aspath_single_asn_check (attr->aspath, peer->as))
1117 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
1118 }
1119}
1120
3f9c7369
DS
1121static void
1122subgroup_announce_reset_nhop (u_char family, struct attr *attr)
1123{
1124 if (family == AF_INET)
1125 attr->nexthop.s_addr = 0;
1126#ifdef HAVE_IPV6
1127 if (family == AF_INET6)
1128 memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
1129#endif
1130}
1131
1132int
1133subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp,
1134 struct prefix *p, struct attr *attr)
1135{
1136 struct bgp_filter *filter;
1137 struct peer *from;
1138 struct peer *peer;
1139 struct peer *onlypeer;
1140 struct bgp *bgp;
1141 struct attr *riattr;
1142 struct peer_af *paf;
1143 char buf[SU_ADDRSTRLEN];
1144 int ret;
1145 int transparent;
1146 int reflect;
1147 afi_t afi;
1148 safi_t safi;
1149
1150 if (DISABLE_BGP_ANNOUNCE)
1151 return 0;
1152
1153 afi = SUBGRP_AFI(subgrp);
1154 safi = SUBGRP_SAFI(subgrp);
1155 peer = SUBGRP_PEER(subgrp);
1156 onlypeer = NULL;
1157 if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL))
1158 onlypeer = SUBGRP_PFIRST(subgrp)->peer;
1159
1160 from = ri->peer;
1161 filter = &peer->filter[afi][safi];
1162 bgp = SUBGRP_INST(subgrp);
1163 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1164
adbac85e
DW
1165 /* With addpath we may be asked to TX all kinds of paths so make sure
1166 * ri is valid */
1167 if (!CHECK_FLAG (ri->flags, BGP_INFO_VALID) ||
1168 CHECK_FLAG (ri->flags, BGP_INFO_HISTORY) ||
1169 CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
1170 {
1171 return 0;
1172 }
1173
06370dac
DW
1174 /* If this is not the bestpath then check to see if there is an enabled addpath
1175 * feature that requires us to advertise it */
1176 if (! CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1177 {
1178 if (! bgp_addpath_tx_path(peer, afi, safi, ri))
1179 {
1180 return 0;
1181 }
1182 }
1183
3f9c7369
DS
1184 /* Aggregate-address suppress check. */
1185 if (ri->extra && ri->extra->suppress)
1186 if (! UNSUPPRESS_MAP_NAME (filter))
1187 {
1188 return 0;
1189 }
1190
3f9c7369
DS
1191 /* Do not send back route to sender. */
1192 if (onlypeer && from == onlypeer)
1193 {
1194 return 0;
1195 }
1196
4125bb67
DS
1197 /* Do not send the default route in the BGP table if the neighbor is
1198 * configured for default-originate */
1199 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
1200 {
1201 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1202 return 0;
1203#ifdef HAVE_IPV6
1204 else if (p->family == AF_INET6 && p->prefixlen == 0)
1205 return 0;
1206#endif /* HAVE_IPV6 */
1207 }
1208
3f9c7369
DS
1209 /* Transparency check. */
1210 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1211 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1212 transparent = 1;
1213 else
1214 transparent = 0;
1215
1216 /* If community is not disabled check the no-export and local. */
1217 if (! transparent && bgp_community_filter (peer, riattr))
1218 {
1219 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1220 zlog_debug ("subgrpannouncecheck: community filter check fail");
1221 return 0;
1222 }
1223
1224 /* If the attribute has originator-id and it is same as remote
1225 peer's id. */
1226 if (onlypeer &&
1227 riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) &&
1228 (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id)))
1229 {
1230 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1231 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as "
1232 "remote router-id",
1233 onlypeer->host,
1234 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1235 p->prefixlen);
1236 return 0;
1237 }
1238
1239 /* ORF prefix-list filter check */
1240 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1241 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1242 || CHECK_FLAG (peer->af_cap[afi][safi],
1243 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1244 if (peer->orf_plist[afi][safi])
1245 {
1246 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1247 {
40d2700d
DW
1248 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1249 zlog_debug ("%s [Update:SEND] %s/%d is filtered via ORF",
1250 peer->host,
1251 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1252 p->prefixlen);
3f9c7369
DS
1253 return 0;
1254 }
1255 }
1256
1257 /* Output filter check. */
1258 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1259 {
1260 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1261 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1262 peer->host,
1263 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1264 p->prefixlen);
1265 return 0;
1266 }
1267
1268#ifdef BGP_SEND_ASPATH_CHECK
1269 /* AS path loop check. */
1270 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
1271 {
1272 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1273 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1274 "that is part of AS path.",
1275 onlypeer->host, onlypeer->as);
1276 return 0;
1277 }
1278#endif /* BGP_SEND_ASPATH_CHECK */
1279
1280 /* If we're a CONFED we need to loop check the CONFED ID too */
1281 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1282 {
1283 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1284 {
1285 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1286 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u"
1287 " is AS path.",
1288 peer->host,
1289 bgp->confed_id);
1290 return 0;
1291 }
1292 }
1293
1294 /* Route-Reflect check. */
1295 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1296 reflect = 1;
1297 else
1298 reflect = 0;
1299
1300 /* IBGP reflection check. */
1301 if (reflect)
1302 {
1303 /* A route from a Client peer. */
1304 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1305 {
1306 /* Reflect to all the Non-Client peers and also to the
1307 Client peers other than the originator. Originator check
1308 is already done. So there is noting to do. */
1309 /* no bgp client-to-client reflection check. */
1310 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1311 if (CHECK_FLAG (peer->af_flags[afi][safi],
1312 PEER_FLAG_REFLECTOR_CLIENT))
1313 return 0;
1314 }
1315 else
1316 {
1317 /* A route from a Non-client peer. Reflect to all other
1318 clients. */
1319 if (! CHECK_FLAG (peer->af_flags[afi][safi],
1320 PEER_FLAG_REFLECTOR_CLIENT))
1321 return 0;
1322 }
1323 }
1324
1325 /* For modify attribute, copy it to temporary structure. */
1326 bgp_attr_dup (attr, riattr);
1327
1328 /* If local-preference is not set. */
1329 if ((peer->sort == BGP_PEER_IBGP
1330 || peer->sort == BGP_PEER_CONFED)
1331 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1332 {
1333 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1334 attr->local_pref = bgp->default_local_pref;
1335 }
1336
1337 /* If originator-id is not set and the route is to be reflected,
1338 set the originator id */
1339 if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1340 {
1341 attr->extra = bgp_attr_extra_get(attr);
1342 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1343 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1344 }
1345
1346 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1347 if (peer->sort == BGP_PEER_EBGP
1348 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1349 {
003c1ba0 1350 if (from != bgp->peer_self && ! transparent
3f9c7369
DS
1351 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1352 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1353 }
1354
1355 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1356 * in announce check, only certain flags and length (or number of nexthops
1357 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1358 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1359 * Typically, the source nexthop in the attribute is preserved but in the
1360 * scenarios where we know it will always be overwritten, we reset the
1361 * nexthop to "0" in an attempt to achieve better Update packing. An
1362 * example of this is when a prefix from each of 2 IBGP peers needs to be
1363 * announced to an EBGP peer (and they have the same attributes barring
1364 * their nexthop).
1365 */
1366 if (reflect)
1367 SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
1368
1369#ifdef HAVE_IPV6
587ff0fd
LB
1370#define NEXTHOP_IS_V6 (\
1371 (safi != SAFI_ENCAP && \
1372 (p->family == AF_INET6 || peer_cap_enhe(peer))) || \
1373 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 16))
1374
3811f1e2
DS
1375 /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if
1376 * the peer (group) is configured to receive link-local nexthop unchanged
1377 * and it is available in the prefix OR we're not reflecting the route and
1378 * the peer (group) to whom we're going to announce is on a shared network
003c1ba0 1379 * and this is either a self-originated route or the peer is EBGP.
3f9c7369 1380 */
587ff0fd 1381 if (NEXTHOP_IS_V6)
3f9c7369 1382 {
801a9bcc 1383 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
3811f1e2
DS
1384 if ((CHECK_FLAG (peer->af_flags[afi][safi],
1385 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1386 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) ||
003c1ba0 1387 (!reflect && peer->shared_network &&
1388 (from == bgp->peer_self || peer->sort == BGP_PEER_EBGP)))
3f9c7369 1389 {
3811f1e2 1390 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
3f9c7369
DS
1391 }
1392
3811f1e2
DS
1393 /* Clear off link-local nexthop in source, whenever it is not needed to
1394 * ensure more prefixes share the same attribute for announcement.
3f9c7369
DS
1395 */
1396 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1397 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1398 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1399 }
1400#endif /* HAVE_IPV6 */
1401
1402 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1403 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1404
1405 /* Route map & unsuppress-map apply. */
1406 if (ROUTE_MAP_OUT_NAME (filter)
1407 || (ri->extra && ri->extra->suppress) )
1408 {
1409 struct bgp_info info;
1410 struct attr dummy_attr;
1411 struct attr_extra dummy_extra;
1412
1413 dummy_attr.extra = &dummy_extra;
1414
1415 info.peer = peer;
1416 info.attr = attr;
316e074d
DS
1417 /* don't confuse inbound and outbound setting */
1418 RESET_FLAG(attr->rmap_change_flags);
3f9c7369
DS
1419
1420 /*
1421 * The route reflector is not allowed to modify the attributes
1422 * of the reflected IBGP routes unless explicitly allowed.
1423 */
1424 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1425 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1426 {
1427 bgp_attr_dup (&dummy_attr, attr);
1428 info.attr = &dummy_attr;
1429 }
1430
1431 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1432
1433 if (ri->extra && ri->extra->suppress)
1434 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1435 else
1436 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1437
1438 peer->rmap_type = 0;
1439
1440 if (ret == RMAP_DENYMATCH)
1441 {
1442 bgp_attr_flush (attr);
1443 return 0;
1444 }
1445 }
1446
1447 /* After route-map has been applied, we check to see if the nexthop to
1448 * be carried in the attribute (that is used for the announcement) can
1449 * be cleared off or not. We do this in all cases where we would be
1450 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1451 * the global nexthop here; the link-local nexthop would have been cleared
1452 * already, and if not, it is required by the update formation code.
1453 * Also see earlier comments in this function.
43fdf718 1454 */
3811f1e2
DS
1455 /*
1456 * If route-map has performed some operation on the nexthop or the peer
1457 * configuration says to pass it unchanged, we cannot reset the nexthop
1458 * here, so only attempt to do it if these aren't true. Note that the
1459 * route-map handler itself might have cleared the nexthop, if for example,
1460 * it is configured as 'peer-address'.
3f9c7369 1461 */
3811f1e2
DS
1462 if (!bgp_rmap_nhop_changed(attr->rmap_change_flags,
1463 riattr->rmap_change_flags) &&
1464 !transparent &&
1465 !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
3f9c7369 1466 {
3811f1e2 1467 /* We can reset the nexthop, if setting (or forcing) it to 'self' */
88b8ed8d
DW
1468 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
1469 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
3f9c7369
DS
1470 {
1471 if (!reflect ||
1472 CHECK_FLAG (peer->af_flags[afi][safi],
43fdf718 1473 PEER_FLAG_FORCE_NEXTHOP_SELF))
3811f1e2
DS
1474 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ?
1475 AF_INET6 : p->family), attr);
3f9c7369
DS
1476 }
1477 else if (peer->sort == BGP_PEER_EBGP)
1478 {
3811f1e2
DS
1479 /* Can also reset the nexthop if announcing to EBGP, but only if
1480 * no peer in the subgroup is on a shared subnet.
1481 * Note: 3rd party nexthop currently implemented for IPv4 only.
1482 */
3f9c7369
DS
1483 SUBGRP_FOREACH_PEER (subgrp, paf)
1484 {
1485 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1486 break;
1487 }
1488 if (!paf)
8a92a8a0 1489 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr);
3f9c7369 1490 }
003c1ba0 1491 /* If IPv6/MP and nexthop does not have any override and happens to
1492 * be a link-local address, reset it so that we don't pass along the
1493 * source's link-local IPv6 address to recipients who may not be on
1494 * the same interface.
1495 */
1496 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1497 {
1498 if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global))
1499 subgroup_announce_reset_nhop (AF_INET6, attr);
1500 }
3f9c7369
DS
1501 }
1502
1503 return 1;
1504}
1505
fee0f4c6 1506struct bgp_info_pair
1507{
1508 struct bgp_info *old;
1509 struct bgp_info *new;
1510};
1511
94f2b392 1512static void
96450faf
JB
1513bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1514 struct bgp_maxpaths_cfg *mpath_cfg,
1515 struct bgp_info_pair *result)
718e3744 1516{
718e3744 1517 struct bgp_info *new_select;
1518 struct bgp_info *old_select;
fee0f4c6 1519 struct bgp_info *ri;
718e3744 1520 struct bgp_info *ri1;
1521 struct bgp_info *ri2;
b40d939b 1522 struct bgp_info *nextri = NULL;
9fbdd100 1523 int paths_eq, do_mpath, debug;
96450faf 1524 struct list mp_list;
4690c7d7 1525 char pfx_buf[PREFIX2STR_BUFFER];
2ec1e66f 1526 char path_buf[PATH_ADDPATH_STR_BUFFER];
96450faf
JB
1527
1528 bgp_mp_list_init (&mp_list);
99030da1 1529 do_mpath = (mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1);
96450faf 1530
9fbdd100
DS
1531 debug = bgp_debug_bestpath(&rn->p);
1532
1533 if (debug)
1534 prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf));
1535
718e3744 1536 /* bgp deterministic-med */
1537 new_select = NULL;
1538 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
06370dac
DW
1539 {
1540
1541 /* Clear BGP_INFO_DMED_SELECTED for all paths */
1542 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1543 bgp_info_unset_flag (rn, ri1, BGP_INFO_DMED_SELECTED);
1544
1545 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1546 {
1547 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1548 continue;
1549 if (BGP_INFO_HOLDDOWN (ri1))
2fed8887 1550 continue;
06370dac
DW
1551 if (ri1->peer && ri1->peer != bgp->peer_self)
1552 if (ri1->peer->status != Established)
1553 continue;
718e3744 1554
06370dac 1555 new_select = ri1;
06370dac
DW
1556 if (ri1->next)
1557 {
1558 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1559 {
1560 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1561 continue;
1562 if (BGP_INFO_HOLDDOWN (ri2))
1563 continue;
1564 if (ri2->peer &&
1565 ri2->peer != bgp->peer_self &&
1566 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1567 if (ri2->peer->status != Established)
1568 continue;
1569
1570 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1571 || aspath_cmp_left_confed (ri1->attr->aspath,
1572 ri2->attr->aspath))
1573 {
06370dac
DW
1574 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
1575 mpath_cfg, debug, pfx_buf))
1576 {
1577 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1578 new_select = ri2;
1579 }
1580
1581 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1582 }
1583 }
1584 }
1585 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1586 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
718e3744 1587
06370dac 1588 if (debug)
2ec1e66f
DW
1589 {
1590 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1591 zlog_debug("%s: %s is the bestpath from AS %d",
1592 pfx_buf, path_buf, aspath_get_firstas(new_select->attr->aspath));
1593 }
06370dac
DW
1594 }
1595 }
718e3744 1596
1597 /* Check old selected route and new selected route. */
1598 old_select = NULL;
1599 new_select = NULL;
b40d939b 1600 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
718e3744 1601 {
1602 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1603 old_select = ri;
1604
1605 if (BGP_INFO_HOLDDOWN (ri))
b40d939b 1606 {
1607 /* reap REMOVED routes, if needs be
1608 * selected route must stay for a while longer though
1609 */
1610 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1611 && (ri != old_select))
1612 bgp_info_reap (rn, ri);
1613
1614 continue;
1615 }
718e3744 1616
2fed8887
DS
1617 if (ri->peer &&
1618 ri->peer != bgp->peer_self &&
1619 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1620 if (ri->peer->status != Established)
1621 continue;
1622
718e3744 1623 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1624 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1625 {
1a392d46 1626 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
718e3744 1627 continue;
1628 }
06370dac 1629
1a392d46 1630 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
718e3744 1631
9fbdd100 1632 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
96450faf
JB
1633 {
1634 new_select = ri;
96450faf 1635 }
718e3744 1636 }
b40d939b 1637
f4eeff72
DS
1638 /* Now that we know which path is the bestpath see if any of the other paths
1639 * qualify as multipaths
1640 */
1641 if (do_mpath && new_select)
1642 {
9fbdd100 1643 if (debug)
2ec1e66f
DW
1644 {
1645 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1646 zlog_debug("%s: %s is the bestpath, now find multipaths", pfx_buf, path_buf);
1647 }
9fbdd100 1648
f4eeff72
DS
1649 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1650 {
2ec1e66f
DW
1651
1652 if (debug)
1653 bgp_info_path_with_addpath_rx_str (ri, path_buf);
1654
f4eeff72
DS
1655 if (ri == new_select)
1656 {
9fbdd100 1657 if (debug)
2ec1e66f
DW
1658 zlog_debug("%s: %s is the bestpath, add to the multipath list",
1659 pfx_buf, path_buf);
f4eeff72
DS
1660 bgp_mp_list_add (&mp_list, ri);
1661 continue;
1662 }
1663
1664 if (BGP_INFO_HOLDDOWN (ri))
1665 continue;
1666
1667 if (ri->peer &&
1668 ri->peer != bgp->peer_self &&
1669 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1670 if (ri->peer->status != Established)
1671 continue;
1672
7dc9d4e4
DW
1673 if (!bgp_info_nexthop_cmp (ri, new_select))
1674 {
1675 if (debug)
2ec1e66f
DW
1676 zlog_debug("%s: %s has the same nexthop as the bestpath, skip it",
1677 pfx_buf, path_buf);
7dc9d4e4
DW
1678 continue;
1679 }
1680
9fbdd100 1681 bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
f4eeff72
DS
1682
1683 if (paths_eq)
1684 {
9fbdd100 1685 if (debug)
2ec1e66f
DW
1686 zlog_debug("%s: %s is equivalent to the bestpath, add to the multipath list",
1687 pfx_buf, path_buf);
f4eeff72
DS
1688 bgp_mp_list_add (&mp_list, ri);
1689 }
1690 }
1691 }
fee0f4c6 1692
b354c427 1693 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
0b597ef0 1694 bgp_info_mpath_aggregate_update (new_select, old_select);
96450faf
JB
1695 bgp_mp_list_clear (&mp_list);
1696
1697 result->old = old_select;
1698 result->new = new_select;
1699
1700 return;
fee0f4c6 1701}
1702
3f9c7369
DS
1703/*
1704 * A new route/change in bestpath of an existing route. Evaluate the path
1705 * for advertisement to the subgroup.
1706 */
1707int
1708subgroup_process_announce_selected (struct update_subgroup *subgrp,
1709 struct bgp_info *selected,
adbac85e
DW
1710 struct bgp_node *rn,
1711 u_int32_t addpath_tx_id)
9eda90ce 1712{
fee0f4c6 1713 struct prefix *p;
3f9c7369 1714 struct peer *onlypeer;
558d1fec
JBD
1715 struct attr attr;
1716 struct attr_extra extra;
3f9c7369
DS
1717 afi_t afi;
1718 safi_t safi;
fee0f4c6 1719
1720 p = &rn->p;
3f9c7369
DS
1721 afi = SUBGRP_AFI(subgrp);
1722 safi = SUBGRP_SAFI(subgrp);
1723 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1724 (SUBGRP_PFIRST(subgrp))->peer : NULL);
718e3744 1725
9eda90ce 1726 /* First update is deferred until ORF or ROUTE-REFRESH is received */
3f9c7369
DS
1727 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
1728 PEER_STATUS_ORF_WAIT_REFRESH))
fee0f4c6 1729 return 0;
718e3744 1730
2a3d5731 1731 /* It's initialized in bgp_announce_check() */
558d1fec
JBD
1732 attr.extra = &extra;
1733
2a3d5731
DW
1734 /* Announcement to the subgroup. If the route is filtered withdraw it. */
1735 if (selected)
fee0f4c6 1736 {
2a3d5731
DW
1737 if (subgroup_announce_check(selected, subgrp, p, &attr))
1738 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
1739 else
1740 bgp_adj_out_unset_subgroup(rn, subgrp, 1, selected->addpath_tx_id);
1741 }
adbac85e 1742
2a3d5731
DW
1743 /* If selected is NULL we must withdraw the path using addpath_tx_id */
1744 else
1745 {
1746 bgp_adj_out_unset_subgroup(rn, subgrp, 1, addpath_tx_id);
fee0f4c6 1747 }
558d1fec 1748
fee0f4c6 1749 return 0;
200df115 1750}
fee0f4c6 1751
3f9c7369 1752struct bgp_process_queue
fee0f4c6 1753{
200df115 1754 struct bgp *bgp;
1755 struct bgp_node *rn;
1756 afi_t afi;
1757 safi_t safi;
1758};
1759
200df115 1760static wq_item_status
0fb58d5d 1761bgp_process_main (struct work_queue *wq, void *data)
200df115 1762{
0fb58d5d 1763 struct bgp_process_queue *pq = data;
200df115 1764 struct bgp *bgp = pq->bgp;
1765 struct bgp_node *rn = pq->rn;
1766 afi_t afi = pq->afi;
1767 safi_t safi = pq->safi;
1768 struct prefix *p = &rn->p;
fee0f4c6 1769 struct bgp_info *new_select;
1770 struct bgp_info *old_select;
1771 struct bgp_info_pair old_and_new;
cb1faec9
DS
1772
1773 /* Is it end of initial update? (after startup) */
1774 if (!rn)
1775 {
4a16ae86
DS
1776 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1777 sizeof(bgp->update_delay_zebra_resume_time));
1778
1779 bgp->main_zebra_update_hold = 0;
1780 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1781 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1782 {
1783 bgp_zebra_announce_table(bgp, afi, safi);
1784 }
1785 bgp->main_peers_update_hold = 0;
1786
cb1faec9
DS
1787 bgp_start_routeadv(bgp);
1788 return WQ_SUCCESS;
1789 }
1790
fee0f4c6 1791 /* Best path selection. */
96450faf 1792 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 1793 old_select = old_and_new.old;
1794 new_select = old_and_new.new;
1795
1796 /* Nothing to do. */
adbac85e
DW
1797 if (old_select && old_select == new_select &&
1798 !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR) &&
1799 !CHECK_FLAG(old_select->flags, BGP_INFO_ATTR_CHANGED) &&
1800 !bgp->addpath_tx_used[afi][safi])
1801 {
1802 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1803 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
1804 bgp_zebra_announce (p, old_select, bgp, afi, safi);
200df115 1805
adbac85e
DW
1806 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
1807 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1808 return WQ_SUCCESS;
fee0f4c6 1809 }
1810
8ad7271d
DS
1811 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1812 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1813
3f9c7369
DS
1814 /* bestpath has changed; bump version */
1815 if (old_select || new_select)
0de4848d
DS
1816 {
1817 bgp_bump_version(rn);
1818
1819 if (!bgp->t_rmap_def_originate_eval)
1820 {
1821 bgp_lock (bgp);
9229d914 1822 THREAD_TIMER_ON(bm->master, bgp->t_rmap_def_originate_eval,
0de4848d
DS
1823 update_group_refresh_default_originate_route_map,
1824 bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER);
1825 }
1826 }
3f9c7369 1827
338b3424 1828 if (old_select)
1a392d46 1829 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
338b3424 1830 if (new_select)
1831 {
1a392d46
PJ
1832 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1833 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 1834 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
338b3424 1835 }
1836
3f9c7369 1837 group_announce_route(bgp, afi, safi, rn, new_select);
718e3744 1838
1839 /* FIB update. */
ad4cbda1 1840 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) &&
1841 (bgp->inst_type != BGP_INSTANCE_TYPE_VIEW) &&
1842 !bgp_option_check (BGP_OPT_NO_FIB))
718e3744 1843 {
1844 if (new_select
1845 && new_select->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
1846 && (new_select->sub_type == BGP_ROUTE_NORMAL ||
1847 new_select->sub_type == BGP_ROUTE_AGGREGATE))
73ac8160 1848 bgp_zebra_announce (p, new_select, bgp, afi, safi);
718e3744 1849 else
1850 {
1851 /* Withdraw the route from the kernel. */
1852 if (old_select
1853 && old_select->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
1854 && (old_select->sub_type == BGP_ROUTE_NORMAL ||
1855 old_select->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 1856 bgp_zebra_withdraw (p, old_select, safi);
718e3744 1857 }
1858 }
b40d939b 1859
adbac85e 1860 /* Reap old select bgp_info, if it has been removed */
b40d939b 1861 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1862 bgp_info_reap (rn, old_select);
1863
200df115 1864 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1865 return WQ_SUCCESS;
718e3744 1866}
1867
200df115 1868static void
0fb58d5d 1869bgp_processq_del (struct work_queue *wq, void *data)
200df115 1870{
0fb58d5d 1871 struct bgp_process_queue *pq = data;
cb1faec9
DS
1872 struct bgp_table *table;
1873
228da428 1874 bgp_unlock (pq->bgp);
cb1faec9
DS
1875 if (pq->rn)
1876 {
1877 table = bgp_node_table (pq->rn);
1878 bgp_unlock_node (pq->rn);
1879 bgp_table_unlock (table);
1880 }
200df115 1881 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1882}
1883
f188f2c4 1884void
200df115 1885bgp_process_queue_init (void)
1886{
495f0b13
DS
1887 if (!bm->process_main_queue)
1888 {
1889 bm->process_main_queue
87d4a781 1890 = work_queue_new (bm->master, "process_main_queue");
495f0b13 1891
2a3d5731
DW
1892 if ( !bm->process_main_queue)
1893 {
1894 zlog_err ("%s: Failed to allocate work queue", __func__);
1895 exit (1);
1896 }
200df115 1897 }
1898
1899 bm->process_main_queue->spec.workfunc = &bgp_process_main;
200df115 1900 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
838bbde0
PJ
1901 bm->process_main_queue->spec.max_retries = 0;
1902 bm->process_main_queue->spec.hold = 50;
d889623f
DS
1903 /* Use a higher yield value of 50ms for main queue processing */
1904 bm->process_main_queue->spec.yield = 50 * 1000L;
200df115 1905}
1906
1907void
fee0f4c6 1908bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1909{
200df115 1910 struct bgp_process_queue *pqnode;
1911
1912 /* already scheduled for processing? */
1913 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1914 return;
495f0b13 1915
2a3d5731 1916 if (bm->process_main_queue == NULL)
2e02b9b2
DS
1917 bgp_process_queue_init ();
1918
200df115 1919 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1920 sizeof (struct bgp_process_queue));
1921 if (!pqnode)
1922 return;
228da428
CC
1923
1924 /* all unlocked in bgp_processq_del */
67174041 1925 bgp_table_lock (bgp_node_table (rn));
228da428 1926 pqnode->rn = bgp_lock_node (rn);
200df115 1927 pqnode->bgp = bgp;
228da428 1928 bgp_lock (bgp);
200df115 1929 pqnode->afi = afi;
1930 pqnode->safi = safi;
2a3d5731 1931 work_queue_add (bm->process_main_queue, pqnode);
07ff4dc4 1932 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
200df115 1933 return;
fee0f4c6 1934}
0a486e5f 1935
cb1faec9 1936void
2a3d5731 1937bgp_add_eoiu_mark (struct bgp *bgp)
cb1faec9
DS
1938{
1939 struct bgp_process_queue *pqnode;
1940
2a3d5731 1941 if (bm->process_main_queue == NULL)
2e02b9b2
DS
1942 bgp_process_queue_init ();
1943
cb1faec9
DS
1944 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1945 sizeof (struct bgp_process_queue));
1946 if (!pqnode)
1947 return;
1948
1949 pqnode->rn = NULL;
1950 pqnode->bgp = bgp;
1951 bgp_lock (bgp);
2a3d5731 1952 work_queue_add (bm->process_main_queue, pqnode);
cb1faec9
DS
1953}
1954
94f2b392 1955static int
0a486e5f 1956bgp_maximum_prefix_restart_timer (struct thread *thread)
1957{
1958 struct peer *peer;
1959
1960 peer = THREAD_ARG (thread);
1961 peer->t_pmax_restart = NULL;
1962
16286195 1963 if (bgp_debug_neighbor_events(peer))
0a486e5f 1964 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1965 peer->host);
1966
1ff9a340 1967 peer_clear (peer, NULL);
0a486e5f 1968
1969 return 0;
1970}
1971
718e3744 1972int
5228ad27 1973bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1974 safi_t safi, int always)
718e3744 1975{
e0701b79 1976 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1977 return 0;
1978
1979 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
718e3744 1980 {
e0701b79 1981 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1982 && ! always)
1983 return 0;
1984
16286195
DS
1985 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1986 "limit %ld", afi_safi_print (afi, safi), peer->host,
1987 peer->pcount[afi][safi], peer->pmax[afi][safi]);
e0701b79 1988 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1989
1990 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1991 return 0;
1992
1993 {
5228ad27 1994 u_int8_t ndata[7];
e0701b79 1995
1996 if (safi == SAFI_MPLS_VPN)
42e6d745 1997 safi = SAFI_MPLS_LABELED_VPN;
5228ad27 1998
1999 ndata[0] = (afi >> 8);
2000 ndata[1] = afi;
2001 ndata[2] = safi;
2002 ndata[3] = (peer->pmax[afi][safi] >> 24);
2003 ndata[4] = (peer->pmax[afi][safi] >> 16);
2004 ndata[5] = (peer->pmax[afi][safi] >> 8);
2005 ndata[6] = (peer->pmax[afi][safi]);
e0701b79 2006
2007 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
2008 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
2009 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
2010 }
0a486e5f 2011
f14e6fdb
DS
2012 /* Dynamic peers will just close their connection. */
2013 if (peer_dynamic_neighbor (peer))
2014 return 1;
2015
0a486e5f 2016 /* restart timer start */
2017 if (peer->pmax_restart[afi][safi])
2018 {
2019 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
2020
16286195 2021 if (bgp_debug_neighbor_events(peer))
0a486e5f 2022 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2023 peer->host, peer->v_pmax_restart);
2024
2025 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2026 peer->v_pmax_restart);
2027 }
2028
e0701b79 2029 return 1;
2030 }
2031 else
2032 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2033
2034 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2035 {
2036 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2037 && ! always)
2038 return 0;
2039
16286195
DS
2040 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2041 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2042 peer->pmax[afi][safi]);
e0701b79 2043 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2044 }
e0701b79 2045 else
2046 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2047 return 0;
2048}
2049
b40d939b 2050/* Unconditionally remove the route from the RIB, without taking
2051 * damping into consideration (eg, because the session went down)
2052 */
94f2b392 2053static void
718e3744 2054bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2055 afi_t afi, safi_t safi)
2056{
902212c3 2057 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2058
2059 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2060 bgp_info_delete (rn, ri); /* keep historical info */
2061
b40d939b 2062 bgp_process (peer->bgp, rn, afi, safi);
718e3744 2063}
2064
94f2b392 2065static void
718e3744 2066bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
b40d939b 2067 afi_t afi, safi_t safi)
718e3744 2068{
718e3744 2069 int status = BGP_DAMP_NONE;
2070
b40d939b 2071 /* apply dampening, if result is suppressed, we'll be retaining
2072 * the bgp_info in the RIB for historical reference.
2073 */
2074 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2075 && peer->sort == BGP_PEER_EBGP)
b40d939b 2076 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2077 == BGP_DAMP_SUPPRESSED)
902212c3 2078 {
902212c3 2079 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2080 return;
2081 }
2082
2083 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 2084}
2085
fb018d25 2086static struct bgp_info *
7c8ff89e 2087info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
fb018d25
DS
2088 struct bgp_node *rn)
2089{
2090 struct bgp_info *new;
2091
2092 /* Make new BGP info. */
2093 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2094 new->type = type;
7c8ff89e 2095 new->instance = instance;
fb018d25
DS
2096 new->sub_type = sub_type;
2097 new->peer = peer;
2098 new->attr = attr;
2099 new->uptime = bgp_clock ();
2100 new->net = rn;
adbac85e 2101 new->addpath_tx_id = ++peer->bgp->addpath_tx_id;
fb018d25
DS
2102 return new;
2103}
2104
94f2b392 2105static void
2ec1e66f 2106bgp_info_addpath_rx_str(u_int32_t addpath_id, char *buf)
cd808e74 2107{
2ec1e66f
DW
2108 if (addpath_id)
2109 sprintf(buf, " with addpath ID %d", addpath_id);
cd808e74
DS
2110}
2111
2ec1e66f 2112
c265ee22
DS
2113/* Check if received nexthop is valid or not. */
2114static int
6aeb9e78 2115bgp_update_martian_nexthop (struct bgp *bgp, afi_t afi, safi_t safi, struct attr *attr)
c265ee22
DS
2116{
2117 struct attr_extra *attre = attr->extra;
2118 int ret = 0;
2119
2120 /* Only validated for unicast and multicast currently. */
2121 if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST)
2122 return 0;
2123
2124 /* If NEXT_HOP is present, validate it. */
2125 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP))
2126 {
2127 if (attr->nexthop.s_addr == 0 ||
2128 IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) ||
6aeb9e78 2129 bgp_nexthop_self (bgp, attr))
c265ee22
DS
2130 ret = 1;
2131 }
2132
2133 /* If MP_NEXTHOP is present, validate it. */
2134 /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop;
2135 * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if
2136 * it is not an IPv6 link-local address.
2137 */
2138 if (attre && attre->mp_nexthop_len)
2139 {
2140 switch (attre->mp_nexthop_len)
2141 {
2142 case BGP_ATTR_NHLEN_IPV4:
2143 case BGP_ATTR_NHLEN_VPNV4:
2144 ret = (attre->mp_nexthop_global_in.s_addr == 0 ||
2145 IPV4_CLASS_DE (ntohl (attre->mp_nexthop_global_in.s_addr)));
2146 break;
2147
2148#ifdef HAVE_IPV6
2149 case BGP_ATTR_NHLEN_IPV6_GLOBAL:
2150 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
2151 ret = (IN6_IS_ADDR_UNSPECIFIED(&attre->mp_nexthop_global) ||
2152 IN6_IS_ADDR_LOOPBACK(&attre->mp_nexthop_global) ||
2153 IN6_IS_ADDR_MULTICAST(&attre->mp_nexthop_global));
2154 break;
2155#endif /* HAVE_IPV6 */
2156
2157 default:
2158 ret = 1;
2159 break;
2160 }
2161 }
2162
2163 return ret;
2164}
2165
a7ee645d
DS
2166int
2167bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2168 struct attr *attr, afi_t afi, safi_t safi, int type,
2169 int sub_type, struct prefix_rd *prd, u_char *tag,
2170 int soft_reconfig)
718e3744 2171{
2172 int ret;
2173 int aspath_loop_count = 0;
2174 struct bgp_node *rn;
2175 struct bgp *bgp;
558d1fec
JBD
2176 struct attr new_attr;
2177 struct attr_extra new_extra;
718e3744 2178 struct attr *attr_new;
2179 struct bgp_info *ri;
2180 struct bgp_info *new;
fd79ac91 2181 const char *reason;
718e3744 2182 char buf[SU_ADDRSTRLEN];
cd808e74 2183 char buf2[30];
fc9a856f 2184 int connected = 0;
718e3744 2185
2186 bgp = peer->bgp;
fee0f4c6 2187 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
fb982c25 2188
718e3744 2189 /* When peer's soft reconfiguration enabled. Record input packet in
2190 Adj-RIBs-In. */
343aa822
JBD
2191 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2192 && peer != bgp->peer_self)
43143c8f 2193 bgp_adj_in_set (rn, peer, attr, addpath_id);
718e3744 2194
2195 /* Check previously received route. */
2196 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
2197 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2198 ri->addpath_rx_id == addpath_id)
718e3744 2199 break;
2200
2201 /* AS path local-as loop check. */
2202 if (peer->change_local_as)
2203 {
2204 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2205 aspath_loop_count = 1;
2206
2207 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2208 {
2209 reason = "as-path contains our own AS;";
2210 goto filtered;
2211 }
2212 }
2213
2214 /* AS path loop check. */
2215 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2216 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2217 && aspath_loop_check(attr->aspath, bgp->confed_id)
2218 > peer->allowas_in[afi][safi]))
2219 {
2220 reason = "as-path contains our own AS;";
2221 goto filtered;
2222 }
2223
2224 /* Route reflector originator ID check. */
2225 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 2226 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
718e3744 2227 {
2228 reason = "originator is us;";
2229 goto filtered;
2230 }
2231
2232 /* Route reflector cluster ID check. */
2233 if (bgp_cluster_filter (peer, attr))
2234 {
2235 reason = "reflected from the same cluster;";
2236 goto filtered;
2237 }
2238
2239 /* Apply incoming filter. */
2240 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2241 {
2242 reason = "filter;";
2243 goto filtered;
2244 }
2245
558d1fec 2246 new_attr.extra = &new_extra;
fb982c25 2247 bgp_attr_dup (&new_attr, attr);
718e3744 2248
c460e572
DL
2249 /* Apply incoming route-map.
2250 * NB: new_attr may now contain newly allocated values from route-map "set"
2251 * commands, so we need bgp_attr_flush in the error paths, until we intern
2252 * the attr (which takes over the memory references) */
0b16f239 2253 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
718e3744 2254 {
2255 reason = "route-map;";
c460e572 2256 bgp_attr_flush (&new_attr);
718e3744 2257 goto filtered;
2258 }
2259
c265ee22 2260 /* next hop check. */
6aeb9e78 2261 if (bgp_update_martian_nexthop (bgp, afi, safi, &new_attr))
718e3744 2262 {
c265ee22
DS
2263 reason = "martian or self next-hop;";
2264 bgp_attr_flush (&new_attr);
2265 goto filtered;
718e3744 2266 }
2267
2268 attr_new = bgp_attr_intern (&new_attr);
2269
2270 /* If the update is implicit withdraw. */
2271 if (ri)
2272 {
65957886 2273 ri->uptime = bgp_clock ();
718e3744 2274
2275 /* Same attribute comes in. */
16d2e241
PJ
2276 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2277 && attrhash_cmp (ri->attr, attr_new))
718e3744 2278 {
718e3744 2279 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2280 && peer->sort == BGP_PEER_EBGP
718e3744 2281 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2282 {
3f9c7369 2283 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74 2284 {
2ec1e66f 2285 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74 2286 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2287 peer->host,
2288 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74
DS
2289 p->prefixlen, buf2);
2290 }
718e3744 2291
902212c3 2292 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2293 {
2294 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2295 bgp_process (bgp, rn, afi, safi);
2296 }
718e3744 2297 }
16d2e241 2298 else /* Duplicate - odd */
718e3744 2299 {
3f9c7369 2300 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2301 {
2302 if (!peer->rcvd_attr_printed)
2303 {
2304 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2305 peer->rcvd_attr_printed = 1;
2306 }
2307
2ec1e66f 2308 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74 2309 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
16286195
DS
2310 peer->host,
2311 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2312 p->prefixlen, buf2);
16286195 2313 }
93406d87 2314
2315 /* graceful restart STALE flag unset. */
2316 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2317 {
1a392d46 2318 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
902212c3 2319 bgp_process (bgp, rn, afi, safi);
93406d87 2320 }
718e3744 2321 }
2322
2323 bgp_unlock_node (rn);
f6f434b2 2324 bgp_attr_unintern (&attr_new);
558d1fec 2325
718e3744 2326 return 0;
2327 }
2328
16d2e241
PJ
2329 /* Withdraw/Announce before we fully processed the withdraw */
2330 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2331 {
3f9c7369 2332 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74 2333 {
2ec1e66f 2334 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74
DS
2335 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
2336 peer->host,
2337 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2338 p->prefixlen, buf2);
2339 }
16d2e241
PJ
2340 bgp_info_restore (rn, ri);
2341 }
2342
718e3744 2343 /* Received Logging. */
3f9c7369 2344 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74 2345 {
2ec1e66f 2346 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74 2347 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2348 peer->host,
2349 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74
DS
2350 p->prefixlen, buf2);
2351 }
718e3744 2352
93406d87 2353 /* graceful restart STALE flag unset. */
2354 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1a392d46 2355 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
93406d87 2356
718e3744 2357 /* The attribute is changed. */
1a392d46 2358 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
902212c3 2359
2360 /* implicit withdraw, decrement aggregate and pcount here.
2361 * only if update is accepted, they'll increment below.
2362 */
902212c3 2363 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2364
718e3744 2365 /* Update bgp route dampening information. */
2366 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2367 && peer->sort == BGP_PEER_EBGP)
718e3744 2368 {
2369 /* This is implicit withdraw so we should update dampening
2370 information. */
2371 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2372 bgp_damp_withdraw (ri, rn, afi, safi, 1);
718e3744 2373 }
2374
718e3744 2375 /* Update to new attribute. */
f6f434b2 2376 bgp_attr_unintern (&ri->attr);
718e3744 2377 ri->attr = attr_new;
2378
2379 /* Update MPLS tag. */
2380 if (safi == SAFI_MPLS_VPN)
fb982c25 2381 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
718e3744 2382
2383 /* Update bgp route dampening information. */
2384 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2385 && peer->sort == BGP_PEER_EBGP)
718e3744 2386 {
2387 /* Now we do normal update dampening. */
2388 ret = bgp_damp_update (ri, rn, afi, safi);
2389 if (ret == BGP_DAMP_SUPPRESSED)
2390 {
2391 bgp_unlock_node (rn);
2392 return 0;
2393 }
2394 }
2395
2396 /* Nexthop reachability check. */
fc9a856f 2397 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
718e3744 2398 {
fc9a856f 2399 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
907f92c8
DS
2400 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2401 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
fc9a856f
DS
2402 connected = 1;
2403 else
2404 connected = 0;
2405
75aead62 2406 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
1a392d46 2407 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 2408 else
fc9a856f
DS
2409 {
2410 if (BGP_DEBUG(nht, NHT))
2411 {
2412 char buf1[INET6_ADDRSTRLEN];
2413 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2414 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2415 }
2416 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2417 }
718e3744 2418 }
2419 else
fc9a856f 2420 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 2421
2422 /* Process change. */
2423 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2424
2425 bgp_process (bgp, rn, afi, safi);
2426 bgp_unlock_node (rn);
558d1fec 2427
718e3744 2428 return 0;
a82478b9 2429 } // End of implicit withdraw
718e3744 2430
2431 /* Received Logging. */
3f9c7369 2432 if (bgp_debug_update(peer, p, NULL, 1))
718e3744 2433 {
16286195
DS
2434 if (!peer->rcvd_attr_printed)
2435 {
2436 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2437 peer->rcvd_attr_printed = 1;
2438 }
2439
2ec1e66f 2440 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74 2441 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2442 peer->host,
2443 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2444 p->prefixlen, buf2);
718e3744 2445 }
2446
718e3744 2447 /* Make new BGP info. */
7c8ff89e 2448 new = info_make(type, sub_type, 0, peer, attr_new, rn);
718e3744 2449
2450 /* Update MPLS tag. */
2451 if (safi == SAFI_MPLS_VPN)
fb982c25 2452 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
718e3744 2453
2454 /* Nexthop reachability check. */
fc9a856f
DS
2455 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2456 {
2457 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
907f92c8
DS
2458 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2459 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
fc9a856f
DS
2460 connected = 1;
2461 else
2462 connected = 0;
2463
75aead62 2464 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
1a392d46 2465 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 2466 else
fc9a856f
DS
2467 {
2468 if (BGP_DEBUG(nht, NHT))
2469 {
2470 char buf1[INET6_ADDRSTRLEN];
2471 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2472 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2473 }
2474 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2475 }
718e3744 2476 }
2477 else
1a392d46 2478 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 2479
a82478b9
DS
2480 /* Addpath ID */
2481 new->addpath_rx_id = addpath_id;
a82478b9 2482
902212c3 2483 /* Increment prefix */
718e3744 2484 bgp_aggregate_increment (bgp, p, new, afi, safi);
2485
2486 /* Register new BGP information. */
2487 bgp_info_add (rn, new);
200df115 2488
2489 /* route_node_get lock */
2490 bgp_unlock_node (rn);
558d1fec 2491
718e3744 2492 /* If maximum prefix count is configured and current prefix
2493 count exeed it. */
e0701b79 2494 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2495 return -1;
718e3744 2496
2497 /* Process change. */
2498 bgp_process (bgp, rn, afi, safi);
2499
2500 return 0;
2501
2502 /* This BGP update is filtered. Log the reason then update BGP
2503 entry. */
2504 filtered:
3f9c7369 2505 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2506 {
2507 if (!peer->rcvd_attr_printed)
2508 {
2509 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2510 peer->rcvd_attr_printed = 1;
2511 }
2512
2ec1e66f 2513 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74 2514 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
16286195
DS
2515 peer->host,
2516 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2517 p->prefixlen, buf2, reason);
16286195 2518 }
718e3744 2519
2520 if (ri)
b40d939b 2521 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 2522
2523 bgp_unlock_node (rn);
558d1fec 2524
718e3744 2525 return 0;
2526}
2527
2528int
a82478b9
DS
2529bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2530 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2531 struct prefix_rd *prd, u_char *tag)
718e3744 2532{
2533 struct bgp *bgp;
2534 char buf[SU_ADDRSTRLEN];
cd808e74 2535 char buf2[30];
718e3744 2536 struct bgp_node *rn;
2537 struct bgp_info *ri;
2538
2539 bgp = peer->bgp;
2540
718e3744 2541 /* Lookup node. */
fee0f4c6 2542 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 2543
2544 /* If peer is soft reconfiguration enabled. Record input packet for
6b87f736
DL
2545 * further calculation.
2546 *
2547 * Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2548 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2549 * the iteration over all RS clients.
2550 * Since we need to remove the entry from adj_in anyway, do that first and
2551 * if there was no entry, we don't need to do anything more.
2552 */
718e3744 2553 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2554 && peer != bgp->peer_self)
6b87f736
DL
2555 if (!bgp_adj_in_unset (rn, peer, addpath_id))
2556 {
2557 if (bgp_debug_update (peer, p, NULL, 1))
2558 zlog_debug ("%s withdrawing route %s/%d "
2559 "not in adj-in", peer->host,
2560 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2561 p->prefixlen);
2562 bgp_unlock_node (rn);
2563 return 0;
2564 }
718e3744 2565
2566 /* Lookup withdrawn route. */
2567 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
2568 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2569 ri->addpath_rx_id == addpath_id)
718e3744 2570 break;
2571
cd808e74
DS
2572 /* Logging. */
2573 if (bgp_debug_update(peer, p, NULL, 1))
2574 {
2ec1e66f 2575 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74
DS
2576 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
2577 peer->host,
2578 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2579 p->prefixlen, buf2);
2580 }
2581
718e3744 2582 /* Withdraw specified route from routing table. */
2583 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
b40d939b 2584 bgp_rib_withdraw (rn, ri, peer, afi, safi);
3f9c7369 2585 else if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2586 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2587 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2588 p->prefixlen);
718e3744 2589
2590 /* Unlock bgp_node_get() lock. */
2591 bgp_unlock_node (rn);
2592
2593 return 0;
2594}
6b0655a2 2595
718e3744 2596void
2597bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2598{
3f9c7369
DS
2599 struct update_subgroup *subgrp;
2600 subgrp = peer_subgroup(peer, afi, safi);
2601 subgroup_default_originate(subgrp, withdraw);
2602}
6182d65b 2603
718e3744 2604
3f9c7369
DS
2605/*
2606 * bgp_stop_announce_route_timer
2607 */
2608void
2609bgp_stop_announce_route_timer (struct peer_af *paf)
2610{
2611 if (!paf->t_announce_route)
2612 return;
718e3744 2613
3f9c7369 2614 THREAD_TIMER_OFF (paf->t_announce_route);
718e3744 2615}
6b0655a2 2616
3f9c7369
DS
2617/*
2618 * bgp_announce_route_timer_expired
2619 *
2620 * Callback that is invoked when the route announcement timer for a
2621 * peer_af expires.
2622 */
2623static int
2624bgp_announce_route_timer_expired (struct thread *t)
718e3744 2625{
3f9c7369
DS
2626 struct peer_af *paf;
2627 struct peer *peer;
558d1fec 2628
3f9c7369
DS
2629 paf = THREAD_ARG (t);
2630 peer = paf->peer;
718e3744 2631
3f9c7369
DS
2632 assert (paf->t_announce_route);
2633 paf->t_announce_route = NULL;
558d1fec 2634
3f9c7369
DS
2635 if (peer->status != Established)
2636 return 0;
2637
2638 if (!peer->afc_nego[paf->afi][paf->safi])
2639 return 0;
2640
2641 peer_af_announce_route (paf, 1);
2642 return 0;
718e3744 2643}
2644
3f9c7369
DS
2645/*
2646 * bgp_announce_route
2647 *
2648 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
2649 */
718e3744 2650void
2651bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2652{
3f9c7369
DS
2653 struct peer_af *paf;
2654 struct update_subgroup *subgrp;
718e3744 2655
3f9c7369
DS
2656 paf = peer_af_find (peer, afi, safi);
2657 if (!paf)
718e3744 2658 return;
3f9c7369 2659 subgrp = PAF_SUBGRP(paf);
718e3744 2660
3f9c7369
DS
2661 /*
2662 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
2663 * or a refresh has already been triggered.
2664 */
2665 if (!subgrp || paf->t_announce_route)
718e3744 2666 return;
2667
d889623f 2668 /*
3f9c7369
DS
2669 * Start a timer to stagger/delay the announce. This serves
2670 * two purposes - announcement can potentially be combined for
2671 * multiple peers and the announcement doesn't happen in the
2672 * vty context.
d889623f 2673 */
9229d914 2674 THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route,
3f9c7369
DS
2675 bgp_announce_route_timer_expired, paf,
2676 (subgrp->peer_count == 1) ?
2677 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
2678 BGP_ANNOUNCE_ROUTE_DELAY_MS);
2679}
2680
2681/*
2682 * Announce routes from all AF tables to a peer.
2683 *
2684 * This should ONLY be called when there is a need to refresh the
2685 * routes to the peer based on a policy change for this peer alone
2686 * or a route refresh request received from the peer.
2687 * The operation will result in splitting the peer from its existing
2688 * subgroups and putting it in new subgroups.
2689 */
718e3744 2690void
2691bgp_announce_route_all (struct peer *peer)
2692{
2693 afi_t afi;
2694 safi_t safi;
2695
2696 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2697 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2698 bgp_announce_route (peer, afi, safi);
2699}
6b0655a2 2700
fee0f4c6 2701static void
718e3744 2702bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
8692c506 2703 struct bgp_table *table, struct prefix_rd *prd)
718e3744 2704{
2705 int ret;
2706 struct bgp_node *rn;
2707 struct bgp_adj_in *ain;
2708
2709 if (! table)
2710 table = peer->bgp->rib[afi][safi];
2711
2712 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2713 for (ain = rn->adj_in; ain; ain = ain->next)
2714 {
2715 if (ain->peer == peer)
2716 {
8692c506 2717 struct bgp_info *ri = rn->info;
d53d8fda 2718 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 2719
43143c8f 2720 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
a82478b9 2721 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
d53d8fda 2722 prd, tag, 1);
8692c506 2723
718e3744 2724 if (ret < 0)
2725 {
2726 bgp_unlock_node (rn);
2727 return;
2728 }
718e3744 2729 }
2730 }
2731}
2732
2733void
2734bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2735{
2736 struct bgp_node *rn;
2737 struct bgp_table *table;
2738
2739 if (peer->status != Established)
2740 return;
2741
587ff0fd 2742 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
8692c506 2743 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
718e3744 2744 else
2745 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2746 rn = bgp_route_next (rn))
2747 if ((table = rn->info) != NULL)
8692c506
JBD
2748 {
2749 struct prefix_rd prd;
2750 prd.family = AF_UNSPEC;
2751 prd.prefixlen = 64;
2752 memcpy(&prd.val, rn->p.u.val, 8);
2753
2754 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2755 }
718e3744 2756}
6b0655a2 2757
228da428
CC
2758
2759struct bgp_clear_node_queue
2760{
2761 struct bgp_node *rn;
228da428
CC
2762};
2763
200df115 2764static wq_item_status
0fb58d5d 2765bgp_clear_route_node (struct work_queue *wq, void *data)
200df115 2766{
228da428
CC
2767 struct bgp_clear_node_queue *cnq = data;
2768 struct bgp_node *rn = cnq->rn;
64e580a7 2769 struct peer *peer = wq->spec.data;
718e3744 2770 struct bgp_info *ri;
67174041
AS
2771 afi_t afi = bgp_node_table (rn)->afi;
2772 safi_t safi = bgp_node_table (rn)->safi;
200df115 2773
64e580a7 2774 assert (rn && peer);
200df115 2775
43143c8f
DS
2776 /* It is possible that we have multiple paths for a prefix from a peer
2777 * if that peer is using AddPath.
2778 */
64e580a7 2779 for (ri = rn->info; ri; ri = ri->next)
2a3d5731 2780 if (ri->peer == peer)
200df115 2781 {
2782 /* graceful restart STALE flag set. */
64e580a7
PJ
2783 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2784 && peer->nsf[afi][safi]
200df115 2785 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
1a392d46
PJ
2786 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2787 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
200df115 2788 else
64e580a7 2789 bgp_rib_remove (rn, ri, peer, afi, safi);
200df115 2790 }
200df115 2791 return WQ_SUCCESS;
2792}
2793
2794static void
0fb58d5d 2795bgp_clear_node_queue_del (struct work_queue *wq, void *data)
200df115 2796{
228da428
CC
2797 struct bgp_clear_node_queue *cnq = data;
2798 struct bgp_node *rn = cnq->rn;
67174041 2799 struct bgp_table *table = bgp_node_table (rn);
64e580a7
PJ
2800
2801 bgp_unlock_node (rn);
228da428
CC
2802 bgp_table_unlock (table);
2803 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
200df115 2804}
2805
2806static void
94f2b392 2807bgp_clear_node_complete (struct work_queue *wq)
200df115 2808{
64e580a7
PJ
2809 struct peer *peer = wq->spec.data;
2810
3e0c78ef 2811 /* Tickle FSM to start moving again */
ca058a30 2812 BGP_EVENT_ADD (peer, Clearing_Completed);
228da428
CC
2813
2814 peer_unlock (peer); /* bgp_clear_route */
200df115 2815}
2816
2817static void
64e580a7 2818bgp_clear_node_queue_init (struct peer *peer)
200df115 2819{
a2943657 2820 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
64e580a7 2821
a2943657 2822 snprintf (wname, sizeof(wname), "clear %s", peer->host);
64e580a7
PJ
2823#undef CLEAR_QUEUE_NAME_LEN
2824
87d4a781 2825 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
200df115 2826 {
2827 zlog_err ("%s: Failed to allocate work queue", __func__);
2828 exit (1);
2829 }
64e580a7
PJ
2830 peer->clear_node_queue->spec.hold = 10;
2831 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2832 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2833 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2834 peer->clear_node_queue->spec.max_retries = 0;
2835
2836 /* we only 'lock' this peer reference when the queue is actually active */
2837 peer->clear_node_queue->spec.data = peer;
200df115 2838}
718e3744 2839
200df115 2840static void
2841bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
2a3d5731 2842 struct bgp_table *table)
200df115 2843{
200df115 2844 struct bgp_node *rn;
2845
f2c31acb 2846
718e3744 2847 if (! table)
2a3d5731 2848 table = peer->bgp->rib[afi][safi];
64e580a7 2849
6cf159b9 2850 /* If still no table => afi/safi isn't configured at all or smth. */
2851 if (! table)
2852 return;
65ca75e0
PJ
2853
2854 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2855 {
f2c31acb
PJ
2856 struct bgp_info *ri;
2857 struct bgp_adj_in *ain;
43143c8f 2858 struct bgp_adj_in *ain_next;
f2c31acb
PJ
2859
2860 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2861 * queued for every clearing peer, regardless of whether it is
2862 * relevant to the peer at hand.
2863 *
2864 * Overview: There are 3 different indices which need to be
2865 * scrubbed, potentially, when a peer is removed:
2866 *
2867 * 1 peer's routes visible via the RIB (ie accepted routes)
2868 * 2 peer's routes visible by the (optional) peer's adj-in index
2869 * 3 other routes visible by the peer's adj-out index
2870 *
2871 * 3 there is no hurry in scrubbing, once the struct peer is
2872 * removed from bgp->peer, we could just GC such deleted peer's
2873 * adj-outs at our leisure.
2874 *
2875 * 1 and 2 must be 'scrubbed' in some way, at least made
2876 * invisible via RIB index before peer session is allowed to be
2877 * brought back up. So one needs to know when such a 'search' is
2878 * complete.
2879 *
2880 * Ideally:
2881 *
2882 * - there'd be a single global queue or a single RIB walker
2883 * - rather than tracking which route_nodes still need to be
2884 * examined on a peer basis, we'd track which peers still
2885 * aren't cleared
2886 *
2887 * Given that our per-peer prefix-counts now should be reliable,
2888 * this may actually be achievable. It doesn't seem to be a huge
2889 * problem at this time,
43143c8f
DS
2890 *
2891 * It is possible that we have multiple paths for a prefix from a peer
2892 * if that peer is using AddPath.
f2c31acb 2893 */
43143c8f
DS
2894 ain = rn->adj_in;
2895 while (ain)
2896 {
2897 ain_next = ain->next;
2898
2a3d5731 2899 if (ain->peer == peer)
43143c8f
DS
2900 {
2901 bgp_adj_in_remove (rn, ain);
2902 bgp_unlock_node (rn);
2903 }
2904
2905 ain = ain_next;
2906 }
3f9c7369 2907
f2c31acb 2908 for (ri = rn->info; ri; ri = ri->next)
2a3d5731 2909 if (ri->peer == peer)
f2c31acb 2910 {
228da428
CC
2911 struct bgp_clear_node_queue *cnq;
2912
2913 /* both unlocked in bgp_clear_node_queue_del */
67174041 2914 bgp_table_lock (bgp_node_table (rn));
228da428
CC
2915 bgp_lock_node (rn);
2916 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2917 sizeof (struct bgp_clear_node_queue));
2918 cnq->rn = rn;
228da428
CC
2919 work_queue_add (peer->clear_node_queue, cnq);
2920 break;
f2c31acb 2921 }
65ca75e0
PJ
2922 }
2923 return;
2924}
2925
2926void
2a3d5731 2927bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
65ca75e0
PJ
2928{
2929 struct bgp_node *rn;
2930 struct bgp_table *table;
6cf159b9 2931
64e580a7
PJ
2932 if (peer->clear_node_queue == NULL)
2933 bgp_clear_node_queue_init (peer);
200df115 2934
ca058a30
PJ
2935 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2936 * Idle until it receives a Clearing_Completed event. This protects
2937 * against peers which flap faster than we can we clear, which could
2938 * lead to:
64e580a7
PJ
2939 *
2940 * a) race with routes from the new session being installed before
2941 * clear_route_node visits the node (to delete the route of that
2942 * peer)
2943 * b) resource exhaustion, clear_route_node likely leads to an entry
2944 * on the process_main queue. Fast-flapping could cause that queue
2945 * to grow and grow.
200df115 2946 */
dc83d712
DS
2947
2948 /* lock peer in assumption that clear-node-queue will get nodes; if so,
2949 * the unlock will happen upon work-queue completion; other wise, the
2950 * unlock happens at the end of this function.
2951 */
ca058a30 2952 if (!peer->clear_node_queue->thread)
dc83d712 2953 peer_lock (peer);
fee0f4c6 2954
587ff0fd 2955 if (safi != SAFI_MPLS_VPN && safi != SAFI_ENCAP)
2a3d5731
DW
2956 bgp_clear_route_table (peer, afi, safi, NULL);
2957 else
2958 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2959 rn = bgp_route_next (rn))
2960 if ((table = rn->info) != NULL)
2961 bgp_clear_route_table (peer, afi, safi, table);
dc83d712
DS
2962
2963 /* unlock if no nodes got added to the clear-node-queue. */
65ca75e0 2964 if (!peer->clear_node_queue->thread)
dc83d712
DS
2965 peer_unlock (peer);
2966
718e3744 2967}
2968
2969void
2970bgp_clear_route_all (struct peer *peer)
2971{
2972 afi_t afi;
2973 safi_t safi;
2974
2975 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2976 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2a3d5731 2977 bgp_clear_route (peer, afi, safi);
718e3744 2978}
2979
2980void
2981bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2982{
2983 struct bgp_table *table;
2984 struct bgp_node *rn;
2985 struct bgp_adj_in *ain;
43143c8f 2986 struct bgp_adj_in *ain_next;
718e3744 2987
2988 table = peer->bgp->rib[afi][safi];
2989
43143c8f
DS
2990 /* It is possible that we have multiple paths for a prefix from a peer
2991 * if that peer is using AddPath.
2992 */
718e3744 2993 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
43143c8f
DS
2994 {
2995 ain = rn->adj_in;
2996
2997 while (ain)
2998 {
2999 ain_next = ain->next;
3000
3001 if (ain->peer == peer)
3002 {
3003 bgp_adj_in_remove (rn, ain);
3004 bgp_unlock_node (rn);
3005 }
3006
3007 ain = ain_next;
3008 }
3009 }
718e3744 3010}
93406d87 3011
3012void
3013bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3014{
3015 struct bgp_node *rn;
3016 struct bgp_info *ri;
3017 struct bgp_table *table;
3018
3019 table = peer->bgp->rib[afi][safi];
3020
3021 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3022 {
3023 for (ri = rn->info; ri; ri = ri->next)
3024 if (ri->peer == peer)
3025 {
3026 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3027 bgp_rib_remove (rn, ri, peer, afi, safi);
3028 break;
3029 }
3030 }
3031}
6b0655a2 3032
bb86c601
LB
3033static void
3034bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3035{
3036 struct bgp_node *rn;
3037 struct bgp_info *ri;
3038 struct bgp_info *next;
3039
3040 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3041 for (ri = rn->info; ri; ri = next)
3042 {
3043 next = ri->next;
3044 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3045 && ri->type == ZEBRA_ROUTE_BGP
3046 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3047 ri->sub_type == BGP_ROUTE_AGGREGATE))
3048 bgp_zebra_withdraw (&rn->p, ri, safi);
3049 }
3050}
3051
718e3744 3052/* Delete all kernel routes. */
3053void
66e5cd87 3054bgp_cleanup_routes (void)
718e3744 3055{
3056 struct bgp *bgp;
1eb8ef25 3057 struct listnode *node, *nnode;
bb86c601 3058 afi_t afi;
718e3744 3059
1eb8ef25 3060 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 3061 {
bb86c601
LB
3062 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3063 {
3064 struct bgp_node *rn;
3065
3066 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
3067
3068 /*
3069 * VPN and ENCAP tables are two-level (RD is top level)
3070 */
3071 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3072 rn = bgp_route_next (rn))
587ff0fd
LB
3073 {
3074 if (rn->info)
bb86c601 3075 {
587ff0fd
LB
3076 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3077 bgp_table_finish ((struct bgp_table **)&(rn->info));
3078 rn->info = NULL;
3079 bgp_unlock_node(rn);
bb86c601 3080 }
587ff0fd
LB
3081 }
3082
3083 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3084 rn = bgp_route_next (rn))
3085 {
3086 if (rn->info)
3087 {
3088 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3089 bgp_table_finish ((struct bgp_table **)&(rn->info));
3090 rn->info = NULL;
3091 bgp_unlock_node(rn);
3092 }
3093 }
bb86c601 3094 }
718e3744 3095 }
3096}
3097
3098void
66e5cd87 3099bgp_reset (void)
718e3744 3100{
3101 vty_reset ();
3102 bgp_zclient_reset ();
3103 access_list_reset ();
3104 prefix_list_reset ();
3105}
6b0655a2 3106
adbac85e
DW
3107static int
3108bgp_addpath_encode_rx (struct peer *peer, afi_t afi, safi_t safi)
3109{
3110 return (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3111 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3112}
3113
718e3744 3114/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3115 value. */
3116int
3117bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3118{
3119 u_char *pnt;
3120 u_char *lim;
3121 struct prefix p;
3122 int psize;
3123 int ret;
a82478b9
DS
3124 afi_t afi;
3125 safi_t safi;
adbac85e 3126 int addpath_encoded;
a82478b9 3127 u_int32_t addpath_id;
718e3744 3128
3129 /* Check peer status. */
3130 if (peer->status != Established)
3131 return 0;
3132
3133 pnt = packet->nlri;
3134 lim = pnt + packet->length;
a82478b9
DS
3135 afi = packet->afi;
3136 safi = packet->safi;
3137 addpath_id = 0;
adbac85e 3138 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
718e3744 3139
3140 for (; pnt < lim; pnt += psize)
3141 {
3142 /* Clear prefix structure. */
3143 memset (&p, 0, sizeof (struct prefix));
3144
a82478b9
DS
3145 if (addpath_encoded)
3146 {
cd808e74
DS
3147
3148 /* When packet overflow occurs return immediately. */
3149 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3150 return -1;
3151
a82478b9
DS
3152 addpath_id = ntohl(*((uint32_t*) pnt));
3153 pnt += BGP_ADDPATH_ID_LEN;
3154 }
3155
718e3744 3156 /* Fetch prefix length. */
3157 p.prefixlen = *pnt++;
a82478b9 3158 p.family = afi2family (afi);
718e3744 3159
3160 /* Already checked in nlri_sanity_check(). We do double check
3161 here. */
a82478b9
DS
3162 if ((afi == AFI_IP && p.prefixlen > 32)
3163 || (afi == AFI_IP6 && p.prefixlen > 128))
718e3744 3164 return -1;
3165
3166 /* Packet size overflow check. */
3167 psize = PSIZE (p.prefixlen);
3168
3169 /* When packet overflow occur return immediately. */
3170 if (pnt + psize > lim)
3171 return -1;
3172
3173 /* Fetch prefix from NLRI packet. */
3174 memcpy (&p.u.prefix, pnt, psize);
3175
3176 /* Check address. */
a82478b9 3177 if (afi == AFI_IP && safi == SAFI_UNICAST)
718e3744 3178 {
3179 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3180 {
f5ba3874 3181 /*
3182 * From draft-ietf-idr-bgp4-22, Section 6.3:
3183 * If a BGP router receives an UPDATE message with a
3184 * semantically incorrect NLRI field, in which a prefix is
3185 * semantically incorrect (eg. an unexpected multicast IP
3186 * address), it should ignore the prefix.
3187 */
16286195
DS
3188 zlog_err ("IPv4 unicast NLRI is multicast address %s",
3189 inet_ntoa (p.u.prefix4));
f5ba3874 3190
718e3744 3191 return -1;
3192 }
3193 }
3194
3195#ifdef HAVE_IPV6
3196 /* Check address. */
a82478b9 3197 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
718e3744 3198 {
3199 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3200 {
3201 char buf[BUFSIZ];
3202
16286195
DS
3203 zlog_warn ("IPv6 link-local NLRI received %s ignore this NLRI",
3204 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
718e3744 3205
3206 continue;
3207 }
3208 }
3209#endif /* HAVE_IPV6 */
3210
3211 /* Normal process. */
3212 if (attr)
a82478b9 3213 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
718e3744 3214 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3215 else
a82478b9 3216 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
718e3744 3217 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3218
3219 /* Address family configuration mismatch or maximum-prefix count
3220 overflow. */
3221 if (ret < 0)
3222 return -1;
3223 }
3224
3225 /* Packet length consistency check. */
3226 if (pnt != lim)
3227 return -1;
3228
3229 return 0;
3230}
3231
3232/* NLRI encode syntax check routine. */
3233int
a82478b9 3234bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi, u_char *pnt,
d889623f 3235 bgp_size_t length, int *numpfx)
718e3744 3236{
3237 u_char *end;
3238 u_char prefixlen;
3239 int psize;
adbac85e 3240 int addpath_encoded;
718e3744 3241
d889623f 3242 *numpfx = 0;
718e3744 3243 end = pnt + length;
adbac85e 3244 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
a82478b9 3245
718e3744 3246 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3247 syntactic validity. If the field is syntactically incorrect,
3248 then the Error Subcode is set to Invalid Network Field. */
3249
3250 while (pnt < end)
3251 {
587ff0fd 3252 int badlength;
cd808e74 3253
a82478b9
DS
3254 /* If the NLRI is encoded using addpath then the first 4 bytes are
3255 * the addpath ID. */
3256 if (addpath_encoded)
cd808e74
DS
3257 {
3258 if (pnt + BGP_ADDPATH_ID_LEN > end)
3259 {
3260 zlog_err ("%s [Error] Update packet error"
3261 " (prefix data addpath overflow)",
3262 peer->host);
3263 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3264 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3265 return -1;
3266 }
3267 pnt += BGP_ADDPATH_ID_LEN;
3268 }
a82478b9 3269
718e3744 3270 prefixlen = *pnt++;
3271
3272 /* Prefix length check. */
587ff0fd
LB
3273 badlength = 0;
3274 if (safi == SAFI_ENCAP) {
3275 if (prefixlen > 128)
3276 badlength = 1;
3277 } else {
3278 if ((afi == AFI_IP && prefixlen > 32) ||
3279 (afi == AFI_IP6 && prefixlen > 128)) {
3280
3281 badlength = 1;
3282 }
3283 }
3284 if (badlength)
718e3744 3285 {
16286195 3286 zlog_err ("%s [Error] Update packet error (wrong prefix length %d)",
718e3744 3287 peer->host, prefixlen);
3288 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3289 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3290 return -1;
3291 }
3292
3293 /* Packet size overflow check. */
3294 psize = PSIZE (prefixlen);
3295
3296 if (pnt + psize > end)
3297 {
16286195 3298 zlog_err ("%s [Error] Update packet error"
718e3744 3299 " (prefix data overflow prefix size is %d)",
3300 peer->host, psize);
3301 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3302 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3303 return -1;
3304 }
3305
3306 pnt += psize;
d889623f 3307 (*numpfx)++;
718e3744 3308 }
3309
3310 /* Packet length consistency check. */
3311 if (pnt != end)
3312 {
16286195 3313 zlog_err ("%s [Error] Update packet error"
718e3744 3314 " (prefix length mismatch with total length)",
3315 peer->host);
3316 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3317 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3318 return -1;
3319 }
3320 return 0;
3321}
6b0655a2 3322
94f2b392 3323static struct bgp_static *
66e5cd87 3324bgp_static_new (void)
718e3744 3325{
393deb9b 3326 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
718e3744 3327}
3328
94f2b392 3329static void
718e3744 3330bgp_static_free (struct bgp_static *bgp_static)
3331{
3332 if (bgp_static->rmap.name)
6e919709 3333 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
718e3744 3334 XFREE (MTYPE_BGP_STATIC, bgp_static);
3335}
3336
94f2b392 3337static void
2a3d5731
DW
3338bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3339 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
fee0f4c6 3340{
3341 struct bgp_node *rn;
3342 struct bgp_info *ri;
2a3d5731
DW
3343 struct bgp_info *new;
3344 struct bgp_info info;
3345 struct attr attr;
3346 struct attr *attr_new;
3347 int ret;
fee0f4c6 3348
2a3d5731
DW
3349 assert (bgp_static);
3350 if (!bgp_static)
3351 return;
dd8103a9 3352
fee0f4c6 3353 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 3354
3355 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
dd8103a9
PJ
3356
3357 attr.nexthop = bgp_static->igpnexthop;
3358 attr.med = bgp_static->igpmetric;
3359 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
718e3744 3360
41367172
PJ
3361 if (bgp_static->atomic)
3362 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3363
718e3744 3364 /* Apply route-map. */
3365 if (bgp_static->rmap.name)
3366 {
fb982c25 3367 struct attr attr_tmp = attr;
718e3744 3368 info.peer = bgp->peer_self;
286e1e71 3369 info.attr = &attr_tmp;
718e3744 3370
fee0f4c6 3371 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3372
718e3744 3373 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
286e1e71 3374
fee0f4c6 3375 bgp->peer_self->rmap_type = 0;
3376
718e3744 3377 if (ret == RMAP_DENYMATCH)
3378 {
3379 /* Free uninterned attribute. */
286e1e71 3380 bgp_attr_flush (&attr_tmp);
718e3744 3381
3382 /* Unintern original. */
f6f434b2 3383 aspath_unintern (&attr.aspath);
fb982c25 3384 bgp_attr_extra_free (&attr);
718e3744 3385 bgp_static_withdraw (bgp, p, afi, safi);
3386 return;
3387 }
286e1e71 3388 attr_new = bgp_attr_intern (&attr_tmp);
718e3744 3389 }
286e1e71 3390 else
3391 attr_new = bgp_attr_intern (&attr);
718e3744 3392
3393 for (ri = rn->info; ri; ri = ri->next)
3394 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3395 && ri->sub_type == BGP_ROUTE_STATIC)
3396 break;
3397
3398 if (ri)
3399 {
8d45210e 3400 if (attrhash_cmp (ri->attr, attr_new) &&
078430f6
DS
3401 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
3402 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
718e3744 3403 {
3404 bgp_unlock_node (rn);
f6f434b2
PJ
3405 bgp_attr_unintern (&attr_new);
3406 aspath_unintern (&attr.aspath);
fb982c25 3407 bgp_attr_extra_free (&attr);
718e3744 3408 return;
3409 }
3410 else
3411 {
3412 /* The attribute is changed. */
1a392d46 3413 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 3414
3415 /* Rewrite BGP route information. */
8d45210e
AS
3416 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3417 bgp_info_restore(rn, ri);
3418 else
3419 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
f6f434b2 3420 bgp_attr_unintern (&ri->attr);
718e3744 3421 ri->attr = attr_new;
65957886 3422 ri->uptime = bgp_clock ();
718e3744 3423
fc9a856f
DS
3424 /* Nexthop reachability check. */
3425 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3426 {
75aead62 3427 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
fc9a856f
DS
3428 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3429 else
3430 {
3431 if (BGP_DEBUG(nht, NHT))
3432 {
3433 char buf1[INET6_ADDRSTRLEN];
078430f6
DS
3434 inet_ntop(p->family, &p->u.prefix, buf1,
3435 INET6_ADDRSTRLEN);
3436 zlog_debug("%s(%s): Route not in table, not advertising",
3437 __FUNCTION__, buf1);
fc9a856f
DS
3438 }
3439 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3440 }
3441 }
078430f6
DS
3442 else
3443 {
3444 /* Delete the NHT structure if any, if we're toggling between
3445 * enabling/disabling import check. We deregister the route
3446 * from NHT to avoid overloading NHT and the process interaction
3447 */
3448 bgp_unlink_nexthop(ri);
3449 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3450 }
718e3744 3451 /* Process change. */
3452 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3453 bgp_process (bgp, rn, afi, safi);
3454 bgp_unlock_node (rn);
f6f434b2 3455 aspath_unintern (&attr.aspath);
fb982c25 3456 bgp_attr_extra_free (&attr);
718e3744 3457 return;
3458 }
3459 }
3460
3461 /* Make new BGP info. */
7c8ff89e 3462 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
fb018d25 3463 rn);
fc9a856f
DS
3464 /* Nexthop reachability check. */
3465 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3466 {
75aead62 3467 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
fc9a856f
DS
3468 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3469 else
3470 {
3471 if (BGP_DEBUG(nht, NHT))
3472 {
3473 char buf1[INET6_ADDRSTRLEN];
078430f6 3474 inet_ntop(p->family, &p->u.prefix, buf1,
fc9a856f 3475 INET6_ADDRSTRLEN);
078430f6
DS
3476 zlog_debug("%s(%s): Route not in table, not advertising",
3477 __FUNCTION__, buf1);
fc9a856f
DS
3478 }
3479 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3480 }
3481 }
3482 else
078430f6
DS
3483 {
3484 /* Delete the NHT structure if any, if we're toggling between
3485 * enabling/disabling import check. We deregister the route
3486 * from NHT to avoid overloading NHT and the process interaction
3487 */
3488 bgp_unlink_nexthop(new);
3489
3490 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3491 }
718e3744 3492
3493 /* Aggregate address increment. */
3494 bgp_aggregate_increment (bgp, p, new, afi, safi);
3495
3496 /* Register new BGP information. */
3497 bgp_info_add (rn, new);
200df115 3498
3499 /* route_node_get lock */
3500 bgp_unlock_node (rn);
3501
718e3744 3502 /* Process change. */
3503 bgp_process (bgp, rn, afi, safi);
3504
3505 /* Unintern original. */
f6f434b2 3506 aspath_unintern (&attr.aspath);
fb982c25 3507 bgp_attr_extra_free (&attr);
718e3744 3508}
3509
fee0f4c6 3510void
3511bgp_static_update (struct bgp *bgp, struct prefix *p,
3512 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3513{
fee0f4c6 3514 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
fee0f4c6 3515}
3516
718e3744 3517void
3518bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3519 safi_t safi)
3520{
3521 struct bgp_node *rn;
3522 struct bgp_info *ri;
3523
fee0f4c6 3524 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 3525
3526 /* Check selected route and self inserted route. */
3527 for (ri = rn->info; ri; ri = ri->next)
3528 if (ri->peer == bgp->peer_self
3529 && ri->type == ZEBRA_ROUTE_BGP
3530 && ri->sub_type == BGP_ROUTE_STATIC)
3531 break;
3532
3533 /* Withdraw static BGP route from routing table. */
3534 if (ri)
3535 {
3536 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
fc9a856f 3537 bgp_unlink_nexthop(ri);
718e3744 3538 bgp_info_delete (rn, ri);
1a392d46 3539 bgp_process (bgp, rn, afi, safi);
718e3744 3540 }
3541
3542 /* Unlock bgp_node_lookup. */
3543 bgp_unlock_node (rn);
3544}
3545
137446f9
LB
3546/*
3547 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3548 */
94f2b392 3549static void
137446f9
LB
3550bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3551 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 3552{
3553 struct bgp_node *rn;
3554 struct bgp_info *ri;
3555
fee0f4c6 3556 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 3557
3558 /* Check selected route and self inserted route. */
3559 for (ri = rn->info; ri; ri = ri->next)
3560 if (ri->peer == bgp->peer_self
3561 && ri->type == ZEBRA_ROUTE_BGP
3562 && ri->sub_type == BGP_ROUTE_STATIC)
3563 break;
3564
3565 /* Withdraw static BGP route from routing table. */
3566 if (ri)
3567 {
3568 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
718e3744 3569 bgp_info_delete (rn, ri);
1a392d46 3570 bgp_process (bgp, rn, afi, safi);
718e3744 3571 }
3572
3573 /* Unlock bgp_node_lookup. */
3574 bgp_unlock_node (rn);
3575}
3576
137446f9
LB
3577static void
3578bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3579 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3580{
3581 struct bgp_node *rn;
3582 struct bgp_info *new;
3583 struct attr *attr_new;
3584 struct attr attr = { 0 };
3585 struct bgp_info *ri;
3586
3587 assert (bgp_static);
3588
3589 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3590
3591 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3592
3593 attr.nexthop = bgp_static->igpnexthop;
3594 attr.med = bgp_static->igpmetric;
3595 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3596
3597 /* Apply route-map. */
3598 if (bgp_static->rmap.name)
3599 {
3600 struct attr attr_tmp = attr;
3601 struct bgp_info info;
3602 int ret;
3603
3604 info.peer = bgp->peer_self;
3605 info.attr = &attr_tmp;
3606
3607 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3608
3609 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3610
3611 bgp->peer_self->rmap_type = 0;
3612
3613 if (ret == RMAP_DENYMATCH)
3614 {
3615 /* Free uninterned attribute. */
3616 bgp_attr_flush (&attr_tmp);
3617
3618 /* Unintern original. */
3619 aspath_unintern (&attr.aspath);
3620 bgp_attr_extra_free (&attr);
3621 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3622 bgp_static->tag);
3623 return;
3624 }
3625
3626 attr_new = bgp_attr_intern (&attr_tmp);
3627 }
3628 else
3629 {
3630 attr_new = bgp_attr_intern (&attr);
3631 }
3632
3633 for (ri = rn->info; ri; ri = ri->next)
3634 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3635 && ri->sub_type == BGP_ROUTE_STATIC)
3636 break;
3637
3638 if (ri)
3639 {
3640 if (attrhash_cmp (ri->attr, attr_new) &&
3641 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3642 {
3643 bgp_unlock_node (rn);
3644 bgp_attr_unintern (&attr_new);
3645 aspath_unintern (&attr.aspath);
3646 bgp_attr_extra_free (&attr);
3647 return;
3648 }
3649 else
3650 {
3651 /* The attribute is changed. */
3652 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3653
3654 /* Rewrite BGP route information. */
3655 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3656 bgp_info_restore(rn, ri);
3657 else
3658 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3659 bgp_attr_unintern (&ri->attr);
3660 ri->attr = attr_new;
3661 ri->uptime = bgp_clock ();
3662
3663 /* Process change. */
3664 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3665 bgp_process (bgp, rn, afi, safi);
3666 bgp_unlock_node (rn);
3667 aspath_unintern (&attr.aspath);
3668 bgp_attr_extra_free (&attr);
3669 return;
3670 }
3671 }
3672
3673
3674 /* Make new BGP info. */
3675 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
3676 rn);
3677 SET_FLAG (new->flags, BGP_INFO_VALID);
3678 new->extra = bgp_info_extra_new();
3679 memcpy (new->extra->tag, bgp_static->tag, 3);
3680
3681 /* Aggregate address increment. */
3682 bgp_aggregate_increment (bgp, p, new, afi, safi);
3683
3684 /* Register new BGP information. */
3685 bgp_info_add (rn, new);
3686
3687 /* route_node_get lock */
3688 bgp_unlock_node (rn);
3689
3690 /* Process change. */
3691 bgp_process (bgp, rn, afi, safi);
3692
3693 /* Unintern original. */
3694 aspath_unintern (&attr.aspath);
3695 bgp_attr_extra_free (&attr);
3696}
3697
718e3744 3698/* Configure static BGP network. When user don't run zebra, static
3699 route should be installed as valid. */
94f2b392 3700static int
fd79ac91 3701bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
c8f3fe30 3702 afi_t afi, safi_t safi, const char *rmap, int backdoor)
718e3744 3703{
3704 int ret;
3705 struct prefix p;
3706 struct bgp_static *bgp_static;
3707 struct bgp_node *rn;
41367172 3708 u_char need_update = 0;
718e3744 3709
3710 /* Convert IP prefix string to struct prefix. */
3711 ret = str2prefix (ip_str, &p);
3712 if (! ret)
3713 {
3714 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3715 return CMD_WARNING;
3716 }
3717#ifdef HAVE_IPV6
3718 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3719 {
3720 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3721 VTY_NEWLINE);
3722 return CMD_WARNING;
3723 }
3724#endif /* HAVE_IPV6 */
3725
3726 apply_mask (&p);
3727
3728 /* Set BGP static route configuration. */
3729 rn = bgp_node_get (bgp->route[afi][safi], &p);
3730
3731 if (rn->info)
3732 {
3733 /* Configuration change. */
3734 bgp_static = rn->info;
3735
3736 /* Check previous routes are installed into BGP. */
c8f3fe30
PJ
3737 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3738 need_update = 1;
41367172 3739
718e3744 3740 bgp_static->backdoor = backdoor;
41367172 3741
718e3744 3742 if (rmap)
3743 {
3744 if (bgp_static->rmap.name)
6e919709
DS
3745 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3746 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
718e3744 3747 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3748 }
3749 else
3750 {
3751 if (bgp_static->rmap.name)
6e919709 3752 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
718e3744 3753 bgp_static->rmap.name = NULL;
3754 bgp_static->rmap.map = NULL;
3755 bgp_static->valid = 0;
3756 }
3757 bgp_unlock_node (rn);
3758 }
3759 else
3760 {
3761 /* New configuration. */
3762 bgp_static = bgp_static_new ();
3763 bgp_static->backdoor = backdoor;
3764 bgp_static->valid = 0;
3765 bgp_static->igpmetric = 0;
3766 bgp_static->igpnexthop.s_addr = 0;
41367172 3767
718e3744 3768 if (rmap)
3769 {
3770 if (bgp_static->rmap.name)
6e919709
DS
3771 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3772 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
718e3744 3773 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3774 }
3775 rn->info = bgp_static;
3776 }
3777
fc9a856f
DS
3778 bgp_static->valid = 1;
3779 if (need_update)
3780 bgp_static_withdraw (bgp, &p, afi, safi);
718e3744 3781
fc9a856f
DS
3782 if (! bgp_static->backdoor)
3783 bgp_static_update (bgp, &p, bgp_static, afi, safi);
718e3744 3784
3785 return CMD_SUCCESS;
3786}
3787
3788/* Configure static BGP network. */
94f2b392 3789static int
fd79ac91 3790bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4c9641ba 3791 afi_t afi, safi_t safi)
718e3744 3792{
3793 int ret;
3794 struct prefix p;
3795 struct bgp_static *bgp_static;
3796 struct bgp_node *rn;
3797
3798 /* Convert IP prefix string to struct prefix. */
3799 ret = str2prefix (ip_str, &p);
3800 if (! ret)
3801 {
3802 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3803 return CMD_WARNING;
3804 }
3805#ifdef HAVE_IPV6
3806 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3807 {
3808 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3809 VTY_NEWLINE);
3810 return CMD_WARNING;
3811 }
3812#endif /* HAVE_IPV6 */
3813
3814 apply_mask (&p);
3815
3816 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3817 if (! rn)
3818 {
3819 vty_out (vty, "%% Can't find specified static route configuration.%s",
3820 VTY_NEWLINE);
3821 return CMD_WARNING;
3822 }
3823
3824 bgp_static = rn->info;
41367172 3825
718e3744 3826 /* Update BGP RIB. */
3827 if (! bgp_static->backdoor)
3828 bgp_static_withdraw (bgp, &p, afi, safi);
3829
3830 /* Clear configuration. */
3831 bgp_static_free (bgp_static);
3832 rn->info = NULL;
3833 bgp_unlock_node (rn);
3834 bgp_unlock_node (rn);
3835
3836 return CMD_SUCCESS;
3837}
3838
6aeb9e78
DS
3839void
3840bgp_static_add (struct bgp *bgp)
3841{
3842 afi_t afi;
3843 safi_t safi;
3844 struct bgp_node *rn;
3845 struct bgp_node *rm;
3846 struct bgp_table *table;
3847 struct bgp_static *bgp_static;
3848
3849 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3850 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3851 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3852 if (rn->info != NULL)
3853 {
3854 if (safi == SAFI_MPLS_VPN)
3855 {
3856 table = rn->info;
3857
3858 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3859 {
3860 bgp_static = rn->info;
137446f9 3861 bgp_static_update_safi (bgp, &rm->p, bgp_static, afi, safi);
6aeb9e78
DS
3862 }
3863 }
3864 else
3865 {
3866 bgp_static_update (bgp, &rn->p, rn->info, afi, safi);
3867 }
3868 }
3869}
3870
718e3744 3871/* Called from bgp_delete(). Delete all static routes from the BGP
3872 instance. */
3873void
3874bgp_static_delete (struct bgp *bgp)
3875{
3876 afi_t afi;
3877 safi_t safi;
3878 struct bgp_node *rn;
3879 struct bgp_node *rm;
3880 struct bgp_table *table;
3881 struct bgp_static *bgp_static;
3882
3883 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3884 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3885 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3886 if (rn->info != NULL)
3887 {
587ff0fd 3888 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 3889 {
3890 table = rn->info;
3891
3892 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3893 {
3894 bgp_static = rn->info;
137446f9
LB
3895 bgp_static_withdraw_safi (bgp, &rm->p,
3896 AFI_IP, safi,
718e3744 3897 (struct prefix_rd *)&rn->p,
3898 bgp_static->tag);
3899 bgp_static_free (bgp_static);
3900 rn->info = NULL;
3901 bgp_unlock_node (rn);
3902 }
3903 }
3904 else
3905 {
3906 bgp_static = rn->info;
3907 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3908 bgp_static_free (bgp_static);
3909 rn->info = NULL;
3910 bgp_unlock_node (rn);
3911 }
3912 }
3913}
3914
078430f6
DS
3915void
3916bgp_static_redo_import_check (struct bgp *bgp)
3917{
3918 afi_t afi;
3919 safi_t safi;
3920 struct bgp_node *rn;
078430f6
DS
3921 struct bgp_static *bgp_static;
3922
3923 /* Use this flag to force reprocessing of the route */
3924 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
3925 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3926 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3927 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3928 if (rn->info != NULL)
3929 {
3930 bgp_static = rn->info;
3931 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
3932 }
3933 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
3934}
3935
ad4cbda1 3936static void
3937bgp_purge_af_static_redist_routes (struct bgp *bgp, afi_t afi, safi_t safi)
3938{
3939 struct bgp_table *table;
3940 struct bgp_node *rn;
3941 struct bgp_info *ri;
3942
3943 table = bgp->rib[afi][safi];
3944 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3945 {
3946 for (ri = rn->info; ri; ri = ri->next)
3947 {
3948 if (ri->peer == bgp->peer_self &&
3949 ((ri->type == ZEBRA_ROUTE_BGP &&
3950 ri->sub_type == BGP_ROUTE_STATIC) ||
3951 (ri->type != ZEBRA_ROUTE_BGP &&
3952 ri->sub_type == BGP_ROUTE_REDISTRIBUTE)))
3953 {
3954 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, safi);
3955 bgp_unlink_nexthop(ri);
3956 bgp_info_delete (rn, ri);
3957 bgp_process (bgp, rn, afi, safi);
3958 }
3959 }
3960 }
3961}
3962
3963/*
3964 * Purge all networks and redistributed routes from routing table.
3965 * Invoked upon the instance going down.
3966 */
3967void
3968bgp_purge_static_redist_routes (struct bgp *bgp)
3969{
3970 afi_t afi;
3971 safi_t safi;
3972
3973 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3974 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3975 bgp_purge_af_static_redist_routes (bgp, afi, safi);
3976}
3977
137446f9
LB
3978/*
3979 * gpz 110624
3980 * Currently this is used to set static routes for VPN and ENCAP.
3981 * I think it can probably be factored with bgp_static_set.
3982 */
718e3744 3983int
137446f9
LB
3984bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
3985 const char *rd_str, const char *tag_str,
3986 const char *rmap_str)
718e3744 3987{
3988 int ret;
3989 struct prefix p;
3990 struct prefix_rd prd;
3991 struct bgp *bgp;
3992 struct bgp_node *prn;
3993 struct bgp_node *rn;
3994 struct bgp_table *table;
3995 struct bgp_static *bgp_static;
3996 u_char tag[3];
3997
3998 bgp = vty->index;
3999
4000 ret = str2prefix (ip_str, &p);
4001 if (! ret)
4002 {
4003 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4004 return CMD_WARNING;
4005 }
4006 apply_mask (&p);
4007
4008 ret = str2prefix_rd (rd_str, &prd);
4009 if (! ret)
4010 {
4011 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4012 return CMD_WARNING;
4013 }
4014
4015 ret = str2tag (tag_str, tag);
4016 if (! ret)
4017 {
4018 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4019 return CMD_WARNING;
4020 }
4021
137446f9 4022 prn = bgp_node_get (bgp->route[AFI_IP][safi],
718e3744 4023 (struct prefix *)&prd);
4024 if (prn->info == NULL)
137446f9 4025 prn->info = bgp_table_init (AFI_IP, safi);
718e3744 4026 else
4027 bgp_unlock_node (prn);
4028 table = prn->info;
4029
4030 rn = bgp_node_get (table, &p);
4031
4032 if (rn->info)
4033 {
4034 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4035 bgp_unlock_node (rn);
4036 }
4037 else
4038 {
4039 /* New configuration. */
4040 bgp_static = bgp_static_new ();
137446f9
LB
4041 bgp_static->backdoor = 0;
4042 bgp_static->valid = 0;
4043 bgp_static->igpmetric = 0;
4044 bgp_static->igpnexthop.s_addr = 0;
4045 memcpy(bgp_static->tag, tag, 3);
4046 bgp_static->prd = prd;
4047
4048 if (rmap_str)
4049 {
4050 if (bgp_static->rmap.name)
4051 free (bgp_static->rmap.name);
4052 bgp_static->rmap.name = strdup (rmap_str);
4053 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4054 }
718e3744 4055 rn->info = bgp_static;
4056
137446f9
LB
4057 bgp_static->valid = 1;
4058 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
718e3744 4059 }
4060
4061 return CMD_SUCCESS;
4062}
4063
4064/* Configure static BGP network. */
4065int
137446f9
LB
4066bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4067 const char *rd_str, const char *tag_str)
718e3744 4068{
4069 int ret;
4070 struct bgp *bgp;
4071 struct prefix p;
4072 struct prefix_rd prd;
4073 struct bgp_node *prn;
4074 struct bgp_node *rn;
4075 struct bgp_table *table;
4076 struct bgp_static *bgp_static;
4077 u_char tag[3];
4078
4079 bgp = vty->index;
4080
4081 /* Convert IP prefix string to struct prefix. */
4082 ret = str2prefix (ip_str, &p);
4083 if (! ret)
4084 {
4085 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4086 return CMD_WARNING;
4087 }
4088 apply_mask (&p);
4089
4090 ret = str2prefix_rd (rd_str, &prd);
4091 if (! ret)
4092 {
4093 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4094 return CMD_WARNING;
4095 }
4096
4097 ret = str2tag (tag_str, tag);
4098 if (! ret)
4099 {
4100 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4101 return CMD_WARNING;
4102 }
4103
137446f9 4104 prn = bgp_node_get (bgp->route[AFI_IP][safi],
718e3744 4105 (struct prefix *)&prd);
4106 if (prn->info == NULL)
137446f9 4107 prn->info = bgp_table_init (AFI_IP, safi);
718e3744 4108 else
4109 bgp_unlock_node (prn);
4110 table = prn->info;
4111
4112 rn = bgp_node_lookup (table, &p);
4113
4114 if (rn)
4115 {
137446f9 4116 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
718e3744 4117
4118 bgp_static = rn->info;
4119 bgp_static_free (bgp_static);
4120 rn->info = NULL;
4121 bgp_unlock_node (rn);
4122 bgp_unlock_node (rn);
4123 }
4124 else
4125 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4126
4127 return CMD_SUCCESS;
4128}
6b0655a2 4129
73ac8160
DS
4130static int
4131bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4132 const char *rmap_name)
4133{
4134 struct bgp_rmap *rmap;
4135
4136 rmap = &bgp->table_map[afi][safi];
4137 if (rmap_name)
4138 {
4139 if (rmap->name)
6e919709
DS
4140 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4141 rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name);
73ac8160
DS
4142 rmap->map = route_map_lookup_by_name (rmap_name);
4143 }
4144 else
4145 {
4146 if (rmap->name)
6e919709 4147 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
73ac8160
DS
4148 rmap->name = NULL;
4149 rmap->map = NULL;
4150 }
4151
4152 bgp_zebra_announce_table(bgp, afi, safi);
4153
4154 return CMD_SUCCESS;
4155}
4156
4157static int
4158bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4159 const char *rmap_name)
4160{
4161 struct bgp_rmap *rmap;
4162
4163 rmap = &bgp->table_map[afi][safi];
4164 if (rmap->name)
6e919709 4165 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
73ac8160
DS
4166 rmap->name = NULL;
4167 rmap->map = NULL;
4168
4169 bgp_zebra_announce_table(bgp, afi, safi);
4170
4171 return CMD_SUCCESS;
4172}
4173
4174int
4175bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4176 safi_t safi, int *write)
4177{
4178 if (bgp->table_map[afi][safi].name)
4179 {
4180 bgp_config_write_family_header (vty, afi, safi, write);
0b960b4d 4181 vty_out (vty, " table-map %s%s",
73ac8160
DS
4182 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4183 }
4184
4185 return 0;
4186}
4187
4188
4189DEFUN (bgp_table_map,
4190 bgp_table_map_cmd,
4191 "table-map WORD",
4192 "BGP table to RIB route download filter\n"
4193 "Name of the route map\n")
4194{
4195 return bgp_table_map_set (vty, vty->index,
4196 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4197}
4198DEFUN (no_bgp_table_map,
4199 no_bgp_table_map_cmd,
4200 "no table-map WORD",
4201 "BGP table to RIB route download filter\n"
4202 "Name of the route map\n")
4203{
4204 return bgp_table_map_unset (vty, vty->index,
4205 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4206}
4207
718e3744 4208DEFUN (bgp_network,
4209 bgp_network_cmd,
4210 "network A.B.C.D/M",
4211 "Specify a network to announce via BGP\n"
4212 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4213{
4214 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 4215 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4216}
4217
4218DEFUN (bgp_network_route_map,
4219 bgp_network_route_map_cmd,
4220 "network A.B.C.D/M route-map WORD",
4221 "Specify a network to announce via BGP\n"
4222 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4223 "Route-map to modify the attributes\n"
4224 "Name of the route map\n")
4225{
4226 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 4227 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 4228}
4229
4230DEFUN (bgp_network_backdoor,
4231 bgp_network_backdoor_cmd,
4232 "network A.B.C.D/M backdoor",
4233 "Specify a network to announce via BGP\n"
4234 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4235 "Specify a BGP backdoor route\n")
4236{
41367172 4237 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
c8f3fe30 4238 NULL, 1);
718e3744 4239}
4240
4241DEFUN (bgp_network_mask,
4242 bgp_network_mask_cmd,
4243 "network A.B.C.D mask A.B.C.D",
4244 "Specify a network to announce via BGP\n"
4245 "Network number\n"
4246 "Network mask\n"
4247 "Network mask\n")
4248{
4249 int ret;
4250 char prefix_str[BUFSIZ];
41367172 4251
718e3744 4252 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4253 if (! ret)
4254 {
4255 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4256 return CMD_WARNING;
4257 }
4258
4259 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4260 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4261}
4262
4263DEFUN (bgp_network_mask_route_map,
4264 bgp_network_mask_route_map_cmd,
4265 "network A.B.C.D mask A.B.C.D route-map WORD",
4266 "Specify a network to announce via BGP\n"
4267 "Network number\n"
4268 "Network mask\n"
4269 "Network mask\n"
4270 "Route-map to modify the attributes\n"
4271 "Name of the route map\n")
4272{
4273 int ret;
4274 char prefix_str[BUFSIZ];
41367172 4275
718e3744 4276 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4277 if (! ret)
4278 {
4279 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4280 return CMD_WARNING;
4281 }
4282
4283 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4284 AFI_IP, bgp_node_safi (vty), argv[2], 0);
718e3744 4285}
4286
4287DEFUN (bgp_network_mask_backdoor,
4288 bgp_network_mask_backdoor_cmd,
4289 "network A.B.C.D mask A.B.C.D backdoor",
4290 "Specify a network to announce via BGP\n"
4291 "Network number\n"
4292 "Network mask\n"
4293 "Network mask\n"
4294 "Specify a BGP backdoor route\n")
4295{
4296 int ret;
4297 char prefix_str[BUFSIZ];
41367172 4298
718e3744 4299 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4300 if (! ret)
4301 {
4302 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4303 return CMD_WARNING;
4304 }
4305
41367172 4306 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 4307 NULL, 1);
718e3744 4308}
4309
4310DEFUN (bgp_network_mask_natural,
4311 bgp_network_mask_natural_cmd,
4312 "network A.B.C.D",
4313 "Specify a network to announce via BGP\n"
4314 "Network number\n")
4315{
4316 int ret;
4317 char prefix_str[BUFSIZ];
4318
4319 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4320 if (! ret)
4321 {
4322 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4323 return CMD_WARNING;
4324 }
4325
4326 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4327 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4328}
4329
4330DEFUN (bgp_network_mask_natural_route_map,
4331 bgp_network_mask_natural_route_map_cmd,
4332 "network A.B.C.D route-map WORD",
4333 "Specify a network to announce via BGP\n"
4334 "Network number\n"
4335 "Route-map to modify the attributes\n"
4336 "Name of the route map\n")
4337{
4338 int ret;
4339 char prefix_str[BUFSIZ];
4340
4341 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4342 if (! ret)
4343 {
4344 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4345 return CMD_WARNING;
4346 }
4347
4348 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4349 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 4350}
4351
4352DEFUN (bgp_network_mask_natural_backdoor,
4353 bgp_network_mask_natural_backdoor_cmd,
4354 "network A.B.C.D backdoor",
4355 "Specify a network to announce via BGP\n"
4356 "Network number\n"
4357 "Specify a BGP backdoor route\n")
4358{
4359 int ret;
4360 char prefix_str[BUFSIZ];
4361
4362 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4363 if (! ret)
4364 {
4365 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4366 return CMD_WARNING;
4367 }
4368
41367172 4369 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 4370 NULL, 1);
718e3744 4371}
4372
4373DEFUN (no_bgp_network,
4374 no_bgp_network_cmd,
4375 "no network A.B.C.D/M",
4376 NO_STR
4377 "Specify a network to announce via BGP\n"
4378 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4379{
4380 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4381 bgp_node_safi (vty));
4382}
4383
4384ALIAS (no_bgp_network,
4385 no_bgp_network_route_map_cmd,
4386 "no network A.B.C.D/M route-map WORD",
4387 NO_STR
4388 "Specify a network to announce via BGP\n"
4389 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4390 "Route-map to modify the attributes\n"
4391 "Name of the route map\n")
4392
4393ALIAS (no_bgp_network,
4394 no_bgp_network_backdoor_cmd,
4395 "no network A.B.C.D/M backdoor",
4396 NO_STR
4397 "Specify a network to announce via BGP\n"
4398 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4399 "Specify a BGP backdoor route\n")
4400
4401DEFUN (no_bgp_network_mask,
4402 no_bgp_network_mask_cmd,
4403 "no network A.B.C.D mask A.B.C.D",
4404 NO_STR
4405 "Specify a network to announce via BGP\n"
4406 "Network number\n"
4407 "Network mask\n"
4408 "Network mask\n")
4409{
4410 int ret;
4411 char prefix_str[BUFSIZ];
4412
4413 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4414 if (! ret)
4415 {
4416 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4417 return CMD_WARNING;
4418 }
4419
4420 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4421 bgp_node_safi (vty));
4422}
4423
4424ALIAS (no_bgp_network_mask,
4425 no_bgp_network_mask_route_map_cmd,
4426 "no network A.B.C.D mask A.B.C.D route-map WORD",
4427 NO_STR
4428 "Specify a network to announce via BGP\n"
4429 "Network number\n"
4430 "Network mask\n"
4431 "Network mask\n"
4432 "Route-map to modify the attributes\n"
4433 "Name of the route map\n")
4434
4435ALIAS (no_bgp_network_mask,
4436 no_bgp_network_mask_backdoor_cmd,
4437 "no network A.B.C.D mask A.B.C.D backdoor",
4438 NO_STR
4439 "Specify a network to announce via BGP\n"
4440 "Network number\n"
4441 "Network mask\n"
4442 "Network mask\n"
4443 "Specify a BGP backdoor route\n")
4444
4445DEFUN (no_bgp_network_mask_natural,
4446 no_bgp_network_mask_natural_cmd,
4447 "no network A.B.C.D",
4448 NO_STR
4449 "Specify a network to announce via BGP\n"
4450 "Network number\n")
4451{
4452 int ret;
4453 char prefix_str[BUFSIZ];
4454
4455 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4456 if (! ret)
4457 {
4458 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4459 return CMD_WARNING;
4460 }
4461
4462 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4463 bgp_node_safi (vty));
4464}
4465
4466ALIAS (no_bgp_network_mask_natural,
4467 no_bgp_network_mask_natural_route_map_cmd,
4468 "no network A.B.C.D route-map WORD",
4469 NO_STR
4470 "Specify a network to announce via BGP\n"
4471 "Network number\n"
4472 "Route-map to modify the attributes\n"
4473 "Name of the route map\n")
4474
4475ALIAS (no_bgp_network_mask_natural,
4476 no_bgp_network_mask_natural_backdoor_cmd,
4477 "no network A.B.C.D backdoor",
4478 NO_STR
4479 "Specify a network to announce via BGP\n"
4480 "Network number\n"
4481 "Specify a BGP backdoor route\n")
4482
4483#ifdef HAVE_IPV6
4484DEFUN (ipv6_bgp_network,
4485 ipv6_bgp_network_cmd,
4486 "network X:X::X:X/M",
4487 "Specify a network to announce via BGP\n"
4488 "IPv6 prefix <network>/<length>\n")
4489{
73bfe0bd 4490 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
c8f3fe30 4491 NULL, 0);
718e3744 4492}
4493
4494DEFUN (ipv6_bgp_network_route_map,
4495 ipv6_bgp_network_route_map_cmd,
4496 "network X:X::X:X/M route-map WORD",
4497 "Specify a network to announce via BGP\n"
4498 "IPv6 prefix <network>/<length>\n"
4499 "Route-map to modify the attributes\n"
4500 "Name of the route map\n")
4501{
4502 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
c8f3fe30 4503 bgp_node_safi (vty), argv[1], 0);
718e3744 4504}
4505
4506DEFUN (no_ipv6_bgp_network,
4507 no_ipv6_bgp_network_cmd,
4508 "no network X:X::X:X/M",
4509 NO_STR
4510 "Specify a network to announce via BGP\n"
4511 "IPv6 prefix <network>/<length>\n")
4512{
73bfe0bd 4513 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
718e3744 4514}
4515
4516ALIAS (no_ipv6_bgp_network,
4517 no_ipv6_bgp_network_route_map_cmd,
4518 "no network X:X::X:X/M route-map WORD",
4519 NO_STR
4520 "Specify a network to announce via BGP\n"
4521 "IPv6 prefix <network>/<length>\n"
4522 "Route-map to modify the attributes\n"
4523 "Name of the route map\n")
4524
4525ALIAS (ipv6_bgp_network,
4526 old_ipv6_bgp_network_cmd,
4527 "ipv6 bgp network X:X::X:X/M",
4528 IPV6_STR
4529 BGP_STR
4530 "Specify a network to announce via BGP\n"
4531 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4532
4533ALIAS (no_ipv6_bgp_network,
4534 old_no_ipv6_bgp_network_cmd,
4535 "no ipv6 bgp network X:X::X:X/M",
4536 NO_STR
4537 IPV6_STR
4538 BGP_STR
4539 "Specify a network to announce via BGP\n"
4540 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4541#endif /* HAVE_IPV6 */
c8f3fe30 4542
718e3744 4543/* Aggreagete address:
4544
4545 advertise-map Set condition to advertise attribute
4546 as-set Generate AS set path information
4547 attribute-map Set attributes of aggregate
4548 route-map Set parameters of aggregate
4549 summary-only Filter more specific routes from updates
4550 suppress-map Conditionally filter more specific routes from updates
4551 <cr>
4552 */
4553struct bgp_aggregate
4554{
4555 /* Summary-only flag. */
4556 u_char summary_only;
4557
4558 /* AS set generation. */
4559 u_char as_set;
4560
4561 /* Route-map for aggregated route. */
4562 struct route_map *map;
4563
4564 /* Suppress-count. */
4565 unsigned long count;
4566
4567 /* SAFI configuration. */
4568 safi_t safi;
4569};
4570
94f2b392 4571static struct bgp_aggregate *
66e5cd87 4572bgp_aggregate_new (void)
718e3744 4573{
393deb9b 4574 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
718e3744 4575}
4576
94f2b392 4577static void
718e3744 4578bgp_aggregate_free (struct bgp_aggregate *aggregate)
4579{
4580 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4581}
4582
b5d58c32 4583/* Update an aggregate as routes are added/removed from the BGP table */
94f2b392 4584static void
718e3744 4585bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4586 afi_t afi, safi_t safi, struct bgp_info *del,
4587 struct bgp_aggregate *aggregate)
4588{
4589 struct bgp_table *table;
4590 struct bgp_node *top;
4591 struct bgp_node *rn;
4592 u_char origin;
4593 struct aspath *aspath = NULL;
4594 struct aspath *asmerge = NULL;
4595 struct community *community = NULL;
4596 struct community *commerge = NULL;
ffd0c037 4597#if defined(AGGREGATE_NEXTHOP_CHECK)
718e3744 4598 struct in_addr nexthop;
4599 u_int32_t med = 0;
ffd0c037 4600#endif
718e3744 4601 struct bgp_info *ri;
4602 struct bgp_info *new;
4603 int first = 1;
4604 unsigned long match = 0;
42f7e184 4605 u_char atomic_aggregate = 0;
718e3744 4606
4607 /* Record adding route's nexthop and med. */
ffd0c037
DS
4608 if (rinew)
4609 {
4610#if defined(AGGREGATE_NEXTHOP_CHECK)
4611 nexthop = rinew->attr->nexthop;
4612 med = rinew->attr->med;
4613#endif
4614 }
718e3744 4615
4616 /* ORIGIN attribute: If at least one route among routes that are
4617 aggregated has ORIGIN with the value INCOMPLETE, then the
4618 aggregated route must have the ORIGIN attribute with the value
4619 INCOMPLETE. Otherwise, if at least one route among routes that
4620 are aggregated has ORIGIN with the value EGP, then the aggregated
4621 route must have the origin attribute with the value EGP. In all
4622 other case the value of the ORIGIN attribute of the aggregated
4623 route is INTERNAL. */
4624 origin = BGP_ORIGIN_IGP;
4625
4626 table = bgp->rib[afi][safi];
4627
4628 top = bgp_node_get (table, p);
4629 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4630 if (rn->p.prefixlen > p->prefixlen)
4631 {
4632 match = 0;
4633
4634 for (ri = rn->info; ri; ri = ri->next)
4635 {
4636 if (BGP_INFO_HOLDDOWN (ri))
4637 continue;
4638
4639 if (del && ri == del)
4640 continue;
4641
4642 if (! rinew && first)
4643 {
ffd0c037 4644#if defined(AGGREGATE_NEXTHOP_CHECK)
718e3744 4645 nexthop = ri->attr->nexthop;
4646 med = ri->attr->med;
ffd0c037 4647#endif
718e3744 4648 first = 0;
4649 }
4650
4651#ifdef AGGREGATE_NEXTHOP_CHECK
4652 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4653 || ri->attr->med != med)
4654 {
4655 if (aspath)
4656 aspath_free (aspath);
4657 if (community)
4658 community_free (community);
4659 bgp_unlock_node (rn);
4660 bgp_unlock_node (top);
4661 return;
4662 }
4663#endif /* AGGREGATE_NEXTHOP_CHECK */
4664
42f7e184
DS
4665 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4666 atomic_aggregate = 1;
4667
718e3744 4668 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4669 {
4670 if (aggregate->summary_only)
4671 {
fb982c25 4672 (bgp_info_extra_get (ri))->suppress++;
1a392d46 4673 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4674 match++;
4675 }
4676
4677 aggregate->count++;
4678
b5d58c32
DS
4679 if (origin < ri->attr->origin)
4680 origin = ri->attr->origin;
4681
718e3744 4682 if (aggregate->as_set)
4683 {
718e3744 4684 if (aspath)
4685 {
4686 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4687 aspath_free (aspath);
4688 aspath = asmerge;
4689 }
4690 else
4691 aspath = aspath_dup (ri->attr->aspath);
4692
4693 if (ri->attr->community)
4694 {
4695 if (community)
4696 {
4697 commerge = community_merge (community,
4698 ri->attr->community);
4699 community = community_uniq_sort (commerge);
4700 community_free (commerge);
4701 }
4702 else
4703 community = community_dup (ri->attr->community);
4704 }
4705 }
4706 }
4707 }
4708 if (match)
4709 bgp_process (bgp, rn, afi, safi);
4710 }
4711 bgp_unlock_node (top);
4712
4713 if (rinew)
4714 {
4715 aggregate->count++;
4716
4717 if (aggregate->summary_only)
fb982c25 4718 (bgp_info_extra_get (rinew))->suppress++;
718e3744 4719
b5d58c32
DS
4720 if (origin < rinew->attr->origin)
4721 origin = rinew->attr->origin;
4722
718e3744 4723 if (aggregate->as_set)
4724 {
718e3744 4725 if (aspath)
4726 {
4727 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4728 aspath_free (aspath);
4729 aspath = asmerge;
4730 }
4731 else
4732 aspath = aspath_dup (rinew->attr->aspath);
4733
4734 if (rinew->attr->community)
4735 {
4736 if (community)
4737 {
4738 commerge = community_merge (community,
4739 rinew->attr->community);
4740 community = community_uniq_sort (commerge);
4741 community_free (commerge);
4742 }
4743 else
4744 community = community_dup (rinew->attr->community);
4745 }
4746 }
4747 }
4748
4749 if (aggregate->count > 0)
4750 {
4751 rn = bgp_node_get (table, p);
7c8ff89e 4752 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 4753 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
4754 aggregate->as_set,
4755 atomic_aggregate), rn);
718e3744 4756 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 4757
4758 bgp_info_add (rn, new);
200df115 4759 bgp_unlock_node (rn);
718e3744 4760 bgp_process (bgp, rn, afi, safi);
4761 }
4762 else
4763 {
4764 if (aspath)
4765 aspath_free (aspath);
4766 if (community)
4767 community_free (community);
4768 }
4769}
4770
4771void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4772 struct bgp_aggregate *);
4773
4774void
4775bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4776 struct bgp_info *ri, afi_t afi, safi_t safi)
4777{
4778 struct bgp_node *child;
4779 struct bgp_node *rn;
4780 struct bgp_aggregate *aggregate;
f018db83 4781 struct bgp_table *table;
718e3744 4782
4783 /* MPLS-VPN aggregation is not yet supported. */
587ff0fd 4784 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 4785 return;
4786
f018db83
JBD
4787 table = bgp->aggregate[afi][safi];
4788
4789 /* No aggregates configured. */
67174041 4790 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
4791 return;
4792
718e3744 4793 if (p->prefixlen == 0)
4794 return;
4795
4796 if (BGP_INFO_HOLDDOWN (ri))
4797 return;
4798
bb782fb5 4799 child = bgp_node_get (table, p);
718e3744 4800
4801 /* Aggregate address configuration check. */
67174041 4802 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 4803 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4804 {
4805 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 4806 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
718e3744 4807 }
4808 bgp_unlock_node (child);
4809}
4810
4811void
4812bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4813 struct bgp_info *del, afi_t afi, safi_t safi)
4814{
4815 struct bgp_node *child;
4816 struct bgp_node *rn;
4817 struct bgp_aggregate *aggregate;
f018db83 4818 struct bgp_table *table;
718e3744 4819
4820 /* MPLS-VPN aggregation is not yet supported. */
587ff0fd 4821 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 4822 return;
4823
f018db83
JBD
4824 table = bgp->aggregate[afi][safi];
4825
4826 /* No aggregates configured. */
67174041 4827 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
4828 return;
4829
718e3744 4830 if (p->prefixlen == 0)
4831 return;
4832
bb782fb5 4833 child = bgp_node_get (table, p);
718e3744 4834
4835 /* Aggregate address configuration check. */
67174041 4836 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 4837 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4838 {
4839 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 4840 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
718e3744 4841 }
4842 bgp_unlock_node (child);
4843}
4844
b5d58c32 4845/* Called via bgp_aggregate_set when the user configures aggregate-address */
94f2b392 4846static void
718e3744 4847bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4848 struct bgp_aggregate *aggregate)
4849{
4850 struct bgp_table *table;
4851 struct bgp_node *top;
4852 struct bgp_node *rn;
4853 struct bgp_info *new;
4854 struct bgp_info *ri;
4855 unsigned long match;
4856 u_char origin = BGP_ORIGIN_IGP;
4857 struct aspath *aspath = NULL;
4858 struct aspath *asmerge = NULL;
4859 struct community *community = NULL;
4860 struct community *commerge = NULL;
42f7e184 4861 u_char atomic_aggregate = 0;
718e3744 4862
4863 table = bgp->rib[afi][safi];
4864
4865 /* Sanity check. */
4866 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4867 return;
4868 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4869 return;
4870
4871 /* If routes exists below this node, generate aggregate routes. */
4872 top = bgp_node_get (table, p);
4873 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4874 if (rn->p.prefixlen > p->prefixlen)
4875 {
4876 match = 0;
4877
4878 for (ri = rn->info; ri; ri = ri->next)
4879 {
4880 if (BGP_INFO_HOLDDOWN (ri))
4881 continue;
4882
42f7e184
DS
4883 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4884 atomic_aggregate = 1;
4885
718e3744 4886 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4887 {
4888 /* summary-only aggregate route suppress aggregated
4889 route announcement. */
4890 if (aggregate->summary_only)
4891 {
fb982c25 4892 (bgp_info_extra_get (ri))->suppress++;
1a392d46 4893 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4894 match++;
4895 }
b5d58c32
DS
4896
4897 /* If at least one route among routes that are aggregated has
4898 * ORIGIN with the value INCOMPLETE, then the aggregated route
4899 * MUST have the ORIGIN attribute with the value INCOMPLETE.
4900 * Otherwise, if at least one route among routes that are
4901 * aggregated has ORIGIN with the value EGP, then the aggregated
4902 * route MUST have the ORIGIN attribute with the value EGP.
4903 */
4904 if (origin < ri->attr->origin)
4905 origin = ri->attr->origin;
4906
718e3744 4907 /* as-set aggregate route generate origin, as path,
4908 community aggregation. */
4909 if (aggregate->as_set)
4910 {
718e3744 4911 if (aspath)
4912 {
4913 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4914 aspath_free (aspath);
4915 aspath = asmerge;
4916 }
4917 else
4918 aspath = aspath_dup (ri->attr->aspath);
4919
4920 if (ri->attr->community)
4921 {
4922 if (community)
4923 {
4924 commerge = community_merge (community,
4925 ri->attr->community);
4926 community = community_uniq_sort (commerge);
4927 community_free (commerge);
4928 }
4929 else
4930 community = community_dup (ri->attr->community);
4931 }
4932 }
4933 aggregate->count++;
4934 }
4935 }
4936
4937 /* If this node is suppressed, process the change. */
4938 if (match)
4939 bgp_process (bgp, rn, afi, safi);
4940 }
4941 bgp_unlock_node (top);
4942
4943 /* Add aggregate route to BGP table. */
4944 if (aggregate->count)
4945 {
4946 rn = bgp_node_get (table, p);
7c8ff89e 4947 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 4948 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
4949 aggregate->as_set,
4950 atomic_aggregate), rn);
718e3744 4951 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 4952
4953 bgp_info_add (rn, new);
200df115 4954 bgp_unlock_node (rn);
4955
718e3744 4956 /* Process change. */
4957 bgp_process (bgp, rn, afi, safi);
4958 }
610f23cf
DV
4959 else
4960 {
4961 if (aspath)
4962 aspath_free (aspath);
4963 if (community)
4964 community_free (community);
4965 }
718e3744 4966}
4967
4968void
4969bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4970 safi_t safi, struct bgp_aggregate *aggregate)
4971{
4972 struct bgp_table *table;
4973 struct bgp_node *top;
4974 struct bgp_node *rn;
4975 struct bgp_info *ri;
4976 unsigned long match;
4977
4978 table = bgp->rib[afi][safi];
4979
4980 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4981 return;
4982 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4983 return;
4984
4985 /* If routes exists below this node, generate aggregate routes. */
4986 top = bgp_node_get (table, p);
4987 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4988 if (rn->p.prefixlen > p->prefixlen)
4989 {
4990 match = 0;
4991
4992 for (ri = rn->info; ri; ri = ri->next)
4993 {
4994 if (BGP_INFO_HOLDDOWN (ri))
4995 continue;
4996
4997 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4998 {
fb982c25 4999 if (aggregate->summary_only && ri->extra)
718e3744 5000 {
fb982c25 5001 ri->extra->suppress--;
718e3744 5002
fb982c25 5003 if (ri->extra->suppress == 0)
718e3744 5004 {
1a392d46 5005 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5006 match++;
5007 }
5008 }
5009 aggregate->count--;
5010 }
5011 }
5012
fb982c25 5013 /* If this node was suppressed, process the change. */
718e3744 5014 if (match)
5015 bgp_process (bgp, rn, afi, safi);
5016 }
5017 bgp_unlock_node (top);
5018
5019 /* Delete aggregate route from BGP table. */
5020 rn = bgp_node_get (table, p);
5021
5022 for (ri = rn->info; ri; ri = ri->next)
5023 if (ri->peer == bgp->peer_self
5024 && ri->type == ZEBRA_ROUTE_BGP
5025 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5026 break;
5027
5028 /* Withdraw static BGP route from routing table. */
5029 if (ri)
5030 {
718e3744 5031 bgp_info_delete (rn, ri);
1a392d46 5032 bgp_process (bgp, rn, afi, safi);
718e3744 5033 }
5034
5035 /* Unlock bgp_node_lookup. */
5036 bgp_unlock_node (rn);
5037}
5038
5039/* Aggregate route attribute. */
5040#define AGGREGATE_SUMMARY_ONLY 1
5041#define AGGREGATE_AS_SET 1
5042
94f2b392 5043static int
f6269b4f
RB
5044bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5045 afi_t afi, safi_t safi)
718e3744 5046{
5047 int ret;
5048 struct prefix p;
5049 struct bgp_node *rn;
5050 struct bgp *bgp;
5051 struct bgp_aggregate *aggregate;
5052
5053 /* Convert string to prefix structure. */
5054 ret = str2prefix (prefix_str, &p);
5055 if (!ret)
5056 {
5057 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5058 return CMD_WARNING;
5059 }
5060 apply_mask (&p);
5061
5062 /* Get BGP structure. */
5063 bgp = vty->index;
5064
5065 /* Old configuration check. */
f6269b4f
RB
5066 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5067 if (! rn)
718e3744 5068 {
f6269b4f
RB
5069 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5070 VTY_NEWLINE);
718e3744 5071 return CMD_WARNING;
5072 }
5073
f6269b4f
RB
5074 aggregate = rn->info;
5075 if (aggregate->safi & SAFI_UNICAST)
5076 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5077 if (aggregate->safi & SAFI_MULTICAST)
5078 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 5079
f6269b4f
RB
5080 /* Unlock aggregate address configuration. */
5081 rn->info = NULL;
5082 bgp_aggregate_free (aggregate);
5083 bgp_unlock_node (rn);
5084 bgp_unlock_node (rn);
718e3744 5085
5086 return CMD_SUCCESS;
5087}
5088
94f2b392 5089static int
f6269b4f
RB
5090bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5091 afi_t afi, safi_t safi,
5092 u_char summary_only, u_char as_set)
718e3744 5093{
5094 int ret;
5095 struct prefix p;
5096 struct bgp_node *rn;
5097 struct bgp *bgp;
5098 struct bgp_aggregate *aggregate;
5099
5100 /* Convert string to prefix structure. */
5101 ret = str2prefix (prefix_str, &p);
5102 if (!ret)
5103 {
5104 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5105 return CMD_WARNING;
5106 }
5107 apply_mask (&p);
5108
5109 /* Get BGP structure. */
5110 bgp = vty->index;
5111
5112 /* Old configuration check. */
f6269b4f
RB
5113 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5114
5115 if (rn->info)
718e3744 5116 {
f6269b4f 5117 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
368473f6 5118 /* try to remove the old entry */
f6269b4f
RB
5119 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5120 if (ret)
5121 {
368473f6
RB
5122 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5123 bgp_unlock_node (rn);
f6269b4f
RB
5124 return CMD_WARNING;
5125 }
718e3744 5126 }
5127
f6269b4f
RB
5128 /* Make aggregate address structure. */
5129 aggregate = bgp_aggregate_new ();
5130 aggregate->summary_only = summary_only;
5131 aggregate->as_set = as_set;
5132 aggregate->safi = safi;
5133 rn->info = aggregate;
718e3744 5134
f6269b4f
RB
5135 /* Aggregate address insert into BGP routing table. */
5136 if (safi & SAFI_UNICAST)
5137 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5138 if (safi & SAFI_MULTICAST)
5139 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 5140
5141 return CMD_SUCCESS;
5142}
5143
5144DEFUN (aggregate_address,
5145 aggregate_address_cmd,
5146 "aggregate-address A.B.C.D/M",
5147 "Configure BGP aggregate entries\n"
5148 "Aggregate prefix\n")
5149{
5150 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5151}
5152
5153DEFUN (aggregate_address_mask,
5154 aggregate_address_mask_cmd,
5155 "aggregate-address A.B.C.D A.B.C.D",
5156 "Configure BGP aggregate entries\n"
5157 "Aggregate address\n"
5158 "Aggregate mask\n")
5159{
5160 int ret;
5161 char prefix_str[BUFSIZ];
5162
5163 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5164
5165 if (! ret)
5166 {
5167 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5168 return CMD_WARNING;
5169 }
5170
5171 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5172 0, 0);
5173}
5174
5175DEFUN (aggregate_address_summary_only,
5176 aggregate_address_summary_only_cmd,
5177 "aggregate-address A.B.C.D/M summary-only",
5178 "Configure BGP aggregate entries\n"
5179 "Aggregate prefix\n"
5180 "Filter more specific routes from updates\n")
5181{
5182 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5183 AGGREGATE_SUMMARY_ONLY, 0);
5184}
5185
5186DEFUN (aggregate_address_mask_summary_only,
5187 aggregate_address_mask_summary_only_cmd,
5188 "aggregate-address A.B.C.D A.B.C.D summary-only",
5189 "Configure BGP aggregate entries\n"
5190 "Aggregate address\n"
5191 "Aggregate mask\n"
5192 "Filter more specific routes from updates\n")
5193{
5194 int ret;
5195 char prefix_str[BUFSIZ];
5196
5197 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5198
5199 if (! ret)
5200 {
5201 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5202 return CMD_WARNING;
5203 }
5204
5205 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5206 AGGREGATE_SUMMARY_ONLY, 0);
5207}
5208
5209DEFUN (aggregate_address_as_set,
5210 aggregate_address_as_set_cmd,
5211 "aggregate-address A.B.C.D/M as-set",
5212 "Configure BGP aggregate entries\n"
5213 "Aggregate prefix\n"
5214 "Generate AS set path information\n")
5215{
5216 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5217 0, AGGREGATE_AS_SET);
5218}
5219
5220DEFUN (aggregate_address_mask_as_set,
5221 aggregate_address_mask_as_set_cmd,
5222 "aggregate-address A.B.C.D A.B.C.D as-set",
5223 "Configure BGP aggregate entries\n"
5224 "Aggregate address\n"
5225 "Aggregate mask\n"
5226 "Generate AS set path information\n")
5227{
5228 int ret;
5229 char prefix_str[BUFSIZ];
5230
5231 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5232
5233 if (! ret)
5234 {
5235 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5236 return CMD_WARNING;
5237 }
5238
5239 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5240 0, AGGREGATE_AS_SET);
5241}
5242
5243
5244DEFUN (aggregate_address_as_set_summary,
5245 aggregate_address_as_set_summary_cmd,
5246 "aggregate-address A.B.C.D/M as-set summary-only",
5247 "Configure BGP aggregate entries\n"
5248 "Aggregate prefix\n"
5249 "Generate AS set path information\n"
5250 "Filter more specific routes from updates\n")
5251{
5252 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5253 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5254}
5255
5256ALIAS (aggregate_address_as_set_summary,
5257 aggregate_address_summary_as_set_cmd,
5258 "aggregate-address A.B.C.D/M summary-only as-set",
5259 "Configure BGP aggregate entries\n"
5260 "Aggregate prefix\n"
5261 "Filter more specific routes from updates\n"
5262 "Generate AS set path information\n")
5263
5264DEFUN (aggregate_address_mask_as_set_summary,
5265 aggregate_address_mask_as_set_summary_cmd,
5266 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5267 "Configure BGP aggregate entries\n"
5268 "Aggregate address\n"
5269 "Aggregate mask\n"
5270 "Generate AS set path information\n"
5271 "Filter more specific routes from updates\n")
5272{
5273 int ret;
5274 char prefix_str[BUFSIZ];
5275
5276 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5277
5278 if (! ret)
5279 {
5280 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5281 return CMD_WARNING;
5282 }
5283
5284 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5285 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5286}
5287
5288ALIAS (aggregate_address_mask_as_set_summary,
5289 aggregate_address_mask_summary_as_set_cmd,
5290 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5291 "Configure BGP aggregate entries\n"
5292 "Aggregate address\n"
5293 "Aggregate mask\n"
5294 "Filter more specific routes from updates\n"
5295 "Generate AS set path information\n")
5296
5297DEFUN (no_aggregate_address,
5298 no_aggregate_address_cmd,
5299 "no aggregate-address A.B.C.D/M",
5300 NO_STR
5301 "Configure BGP aggregate entries\n"
5302 "Aggregate prefix\n")
5303{
5304 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5305}
5306
5307ALIAS (no_aggregate_address,
5308 no_aggregate_address_summary_only_cmd,
5309 "no aggregate-address A.B.C.D/M summary-only",
5310 NO_STR
5311 "Configure BGP aggregate entries\n"
5312 "Aggregate prefix\n"
5313 "Filter more specific routes from updates\n")
5314
5315ALIAS (no_aggregate_address,
5316 no_aggregate_address_as_set_cmd,
5317 "no aggregate-address A.B.C.D/M as-set",
5318 NO_STR
5319 "Configure BGP aggregate entries\n"
5320 "Aggregate prefix\n"
5321 "Generate AS set path information\n")
5322
5323ALIAS (no_aggregate_address,
5324 no_aggregate_address_as_set_summary_cmd,
5325 "no aggregate-address A.B.C.D/M as-set summary-only",
5326 NO_STR
5327 "Configure BGP aggregate entries\n"
5328 "Aggregate prefix\n"
5329 "Generate AS set path information\n"
5330 "Filter more specific routes from updates\n")
5331
5332ALIAS (no_aggregate_address,
5333 no_aggregate_address_summary_as_set_cmd,
5334 "no aggregate-address A.B.C.D/M summary-only as-set",
5335 NO_STR
5336 "Configure BGP aggregate entries\n"
5337 "Aggregate prefix\n"
5338 "Filter more specific routes from updates\n"
5339 "Generate AS set path information\n")
5340
5341DEFUN (no_aggregate_address_mask,
5342 no_aggregate_address_mask_cmd,
5343 "no aggregate-address A.B.C.D A.B.C.D",
5344 NO_STR
5345 "Configure BGP aggregate entries\n"
5346 "Aggregate address\n"
5347 "Aggregate mask\n")
5348{
5349 int ret;
5350 char prefix_str[BUFSIZ];
5351
5352 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5353
5354 if (! ret)
5355 {
5356 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5357 return CMD_WARNING;
5358 }
5359
5360 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5361}
5362
5363ALIAS (no_aggregate_address_mask,
5364 no_aggregate_address_mask_summary_only_cmd,
5365 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5366 NO_STR
5367 "Configure BGP aggregate entries\n"
5368 "Aggregate address\n"
5369 "Aggregate mask\n"
5370 "Filter more specific routes from updates\n")
5371
5372ALIAS (no_aggregate_address_mask,
5373 no_aggregate_address_mask_as_set_cmd,
5374 "no aggregate-address A.B.C.D A.B.C.D as-set",
5375 NO_STR
5376 "Configure BGP aggregate entries\n"
5377 "Aggregate address\n"
5378 "Aggregate mask\n"
5379 "Generate AS set path information\n")
5380
5381ALIAS (no_aggregate_address_mask,
5382 no_aggregate_address_mask_as_set_summary_cmd,
5383 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5384 NO_STR
5385 "Configure BGP aggregate entries\n"
5386 "Aggregate address\n"
5387 "Aggregate mask\n"
5388 "Generate AS set path information\n"
5389 "Filter more specific routes from updates\n")
5390
5391ALIAS (no_aggregate_address_mask,
5392 no_aggregate_address_mask_summary_as_set_cmd,
5393 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5394 NO_STR
5395 "Configure BGP aggregate entries\n"
5396 "Aggregate address\n"
5397 "Aggregate mask\n"
5398 "Filter more specific routes from updates\n"
5399 "Generate AS set path information\n")
5400
5401#ifdef HAVE_IPV6
5402DEFUN (ipv6_aggregate_address,
5403 ipv6_aggregate_address_cmd,
5404 "aggregate-address X:X::X:X/M",
5405 "Configure BGP aggregate entries\n"
5406 "Aggregate prefix\n")
5407{
5408 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5409}
5410
5411DEFUN (ipv6_aggregate_address_summary_only,
5412 ipv6_aggregate_address_summary_only_cmd,
5413 "aggregate-address X:X::X:X/M summary-only",
5414 "Configure BGP aggregate entries\n"
5415 "Aggregate prefix\n"
5416 "Filter more specific routes from updates\n")
5417{
5418 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5419 AGGREGATE_SUMMARY_ONLY, 0);
5420}
5421
5422DEFUN (no_ipv6_aggregate_address,
5423 no_ipv6_aggregate_address_cmd,
5424 "no aggregate-address X:X::X:X/M",
5425 NO_STR
5426 "Configure BGP aggregate entries\n"
5427 "Aggregate prefix\n")
5428{
5429 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5430}
5431
5432DEFUN (no_ipv6_aggregate_address_summary_only,
5433 no_ipv6_aggregate_address_summary_only_cmd,
5434 "no aggregate-address X:X::X:X/M summary-only",
5435 NO_STR
5436 "Configure BGP aggregate entries\n"
5437 "Aggregate prefix\n"
5438 "Filter more specific routes from updates\n")
5439{
5440 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5441}
5442
5443ALIAS (ipv6_aggregate_address,
5444 old_ipv6_aggregate_address_cmd,
5445 "ipv6 bgp aggregate-address X:X::X:X/M",
5446 IPV6_STR
5447 BGP_STR
5448 "Configure BGP aggregate entries\n"
5449 "Aggregate prefix\n")
5450
5451ALIAS (ipv6_aggregate_address_summary_only,
5452 old_ipv6_aggregate_address_summary_only_cmd,
5453 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5454 IPV6_STR
5455 BGP_STR
5456 "Configure BGP aggregate entries\n"
5457 "Aggregate prefix\n"
5458 "Filter more specific routes from updates\n")
5459
5460ALIAS (no_ipv6_aggregate_address,
5461 old_no_ipv6_aggregate_address_cmd,
5462 "no ipv6 bgp aggregate-address X:X::X:X/M",
5463 NO_STR
5464 IPV6_STR
5465 BGP_STR
5466 "Configure BGP aggregate entries\n"
5467 "Aggregate prefix\n")
5468
5469ALIAS (no_ipv6_aggregate_address_summary_only,
5470 old_no_ipv6_aggregate_address_summary_only_cmd,
5471 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5472 NO_STR
5473 IPV6_STR
5474 BGP_STR
5475 "Configure BGP aggregate entries\n"
5476 "Aggregate prefix\n"
5477 "Filter more specific routes from updates\n")
5478#endif /* HAVE_IPV6 */
6b0655a2 5479
718e3744 5480/* Redistribute route treatment. */
5481void
6aeb9e78 5482bgp_redistribute_add (struct bgp *bgp, struct prefix *p, const struct in_addr *nexthop,
bc413143 5483 const struct in6_addr *nexthop6, unsigned int ifindex,
7c8ff89e 5484 u_int32_t metric, u_char type, u_short instance, u_short tag)
718e3744 5485{
718e3744 5486 struct bgp_info *new;
5487 struct bgp_info *bi;
5488 struct bgp_info info;
5489 struct bgp_node *bn;
e16a4133 5490 struct attr attr;
718e3744 5491 struct attr *new_attr;
5492 afi_t afi;
5493 int ret;
7c8ff89e 5494 struct bgp_redist *red;
718e3744 5495
5496 /* Make default attribute. */
5497 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5498 if (nexthop)
5499 attr.nexthop = *nexthop;
bc413143 5500 attr.nh_ifindex = ifindex;
718e3744 5501
f04a80a5
SH
5502#ifdef HAVE_IPV6
5503 if (nexthop6)
5504 {
5505 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5506 extra->mp_nexthop_global = *nexthop6;
801a9bcc 5507 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
f04a80a5
SH
5508 }
5509#endif
5510
718e3744 5511 attr.med = metric;
5512 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
0d9551dc 5513 attr.extra->tag = tag;
718e3744 5514
6aeb9e78
DS
5515 afi = family2afi (p->family);
5516
5517 red = bgp_redist_lookup(bgp, afi, type, instance);
5518 if (red)
718e3744 5519 {
6aeb9e78
DS
5520 struct attr attr_new;
5521 struct attr_extra extra_new;
718e3744 5522
6aeb9e78
DS
5523 /* Copy attribute for modification. */
5524 attr_new.extra = &extra_new;
5525 bgp_attr_dup (&attr_new, &attr);
558d1fec 5526
6aeb9e78
DS
5527 if (red->redist_metric_flag)
5528 attr_new.med = red->redist_metric;
718e3744 5529
6aeb9e78
DS
5530 /* Apply route-map. */
5531 if (red->rmap.name)
5532 {
5533 info.peer = bgp->peer_self;
5534 info.attr = &attr_new;
718e3744 5535
6aeb9e78 5536 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
718e3744 5537
6aeb9e78 5538 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
fee0f4c6 5539
6aeb9e78 5540 bgp->peer_self->rmap_type = 0;
fee0f4c6 5541
6aeb9e78
DS
5542 if (ret == RMAP_DENYMATCH)
5543 {
5544 /* Free uninterned attribute. */
5545 bgp_attr_flush (&attr_new);
5546
5547 /* Unintern original. */
5548 aspath_unintern (&attr.aspath);
5549 bgp_attr_extra_free (&attr);
5550 bgp_redistribute_delete (bgp, p, type, instance);
5551 return;
5552 }
5553 }
fee0f4c6 5554
6aeb9e78
DS
5555 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5556 afi, SAFI_UNICAST, p, NULL);
718e3744 5557
6aeb9e78 5558 new_attr = bgp_attr_intern (&attr_new);
558d1fec 5559
6aeb9e78
DS
5560 for (bi = bn->info; bi; bi = bi->next)
5561 if (bi->peer == bgp->peer_self
5562 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5563 break;
5564
5565 if (bi)
5566 {
5567 /* Ensure the (source route) type is updated. */
5568 bi->type = type;
5569 if (attrhash_cmp (bi->attr, new_attr) &&
5570 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5571 {
5572 bgp_attr_unintern (&new_attr);
5573 aspath_unintern (&attr.aspath);
5574 bgp_attr_extra_free (&attr);
5575 bgp_unlock_node (bn);
5576 return;
5577 }
5578 else
5579 {
5580 /* The attribute is changed. */
5581 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
718e3744 5582
6aeb9e78
DS
5583 /* Rewrite BGP route information. */
5584 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5585 bgp_info_restore(bn, bi);
5586 else
5587 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5588 bgp_attr_unintern (&bi->attr);
5589 bi->attr = new_attr;
5590 bi->uptime = bgp_clock ();
5591
5592 /* Process change. */
5593 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5594 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5595 bgp_unlock_node (bn);
5596 aspath_unintern (&attr.aspath);
5597 bgp_attr_extra_free (&attr);
5598 return;
5599 }
5600 }
718e3744 5601
6aeb9e78
DS
5602 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
5603 new_attr, bn);
5604 SET_FLAG (new->flags, BGP_INFO_VALID);
5605
5606 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5607 bgp_info_add (bn, new);
5608 bgp_unlock_node (bn);
5609 bgp_process (bgp, bn, afi, SAFI_UNICAST);
718e3744 5610 }
5611
5612 /* Unintern original. */
f6f434b2 5613 aspath_unintern (&attr.aspath);
fb982c25 5614 bgp_attr_extra_free (&attr);
718e3744 5615}
5616
5617void
6aeb9e78 5618bgp_redistribute_delete (struct bgp *bgp, struct prefix *p, u_char type, u_short instance)
718e3744 5619{
718e3744 5620 afi_t afi;
5621 struct bgp_node *rn;
5622 struct bgp_info *ri;
7c8ff89e 5623 struct bgp_redist *red;
718e3744 5624
6aeb9e78 5625 afi = family2afi (p->family);
718e3744 5626
6aeb9e78
DS
5627 red = bgp_redist_lookup(bgp, afi, type, instance);
5628 if (red)
5629 {
5630 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
718e3744 5631
6aeb9e78
DS
5632 for (ri = rn->info; ri; ri = ri->next)
5633 if (ri->peer == bgp->peer_self
5634 && ri->type == type)
5635 break;
718e3744 5636
6aeb9e78
DS
5637 if (ri)
5638 {
5639 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5640 bgp_info_delete (rn, ri);
5641 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5642 }
5643 bgp_unlock_node (rn);
718e3744 5644 }
5645}
5646
5647/* Withdraw specified route type's route. */
5648void
7c8ff89e 5649bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
718e3744 5650{
5651 struct bgp_node *rn;
5652 struct bgp_info *ri;
5653 struct bgp_table *table;
5654
5655 table = bgp->rib[afi][SAFI_UNICAST];
5656
5657 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5658 {
5659 for (ri = rn->info; ri; ri = ri->next)
5660 if (ri->peer == bgp->peer_self
7c8ff89e
DS
5661 && ri->type == type
5662 && ri->instance == instance)
718e3744 5663 break;
5664
5665 if (ri)
5666 {
5667 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
718e3744 5668 bgp_info_delete (rn, ri);
1a392d46 5669 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 5670 }
5671 }
5672}
6b0655a2 5673
718e3744 5674/* Static function to display route. */
94f2b392 5675static void
718e3744 5676route_vty_out_route (struct prefix *p, struct vty *vty)
5677{
5678 int len;
5679 u_int32_t destination;
5680 char buf[BUFSIZ];
5681
5682 if (p->family == AF_INET)
5683 {
5684 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5685 destination = ntohl (p->u.prefix4.s_addr);
5686
5687 if ((IN_CLASSC (destination) && p->prefixlen == 24)
856ca177
MS
5688 || (IN_CLASSB (destination) && p->prefixlen == 16)
5689 || (IN_CLASSA (destination) && p->prefixlen == 8)
5690 || p->u.prefix4.s_addr == 0)
5691 {
5692 /* When mask is natural, mask is not displayed. */
5693 }
718e3744 5694 else
856ca177 5695 len += vty_out (vty, "/%d", p->prefixlen);
718e3744 5696 }
5697 else
5698 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5699 p->prefixlen);
5700
5701 len = 17 - len;
5702 if (len < 1)
5703 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5704 else
5705 vty_out (vty, "%*s", len, " ");
5706}
5707
718e3744 5708enum bgp_display_type
5709{
5710 normal_list,
5711};
5712
b40d939b 5713/* Print the short form route status for a bgp_info */
5714static void
b05a1c8b
DS
5715route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
5716 json_object *json_path)
718e3744 5717{
b05a1c8b
DS
5718 if (json_path)
5719 {
b05a1c8b
DS
5720
5721 /* Route status display. */
5722 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
f1aa5d8a 5723 json_object_boolean_true_add(json_path, "removed");
b05a1c8b
DS
5724
5725 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
f1aa5d8a 5726 json_object_boolean_true_add(json_path, "stale");
b05a1c8b
DS
5727
5728 if (binfo->extra && binfo->extra->suppress)
f1aa5d8a 5729 json_object_boolean_true_add(json_path, "suppressed");
b05a1c8b
DS
5730
5731 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5732 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
f1aa5d8a 5733 json_object_boolean_true_add(json_path, "valid");
b05a1c8b
DS
5734
5735 /* Selected */
5736 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
f1aa5d8a 5737 json_object_boolean_true_add(json_path, "history");
b05a1c8b
DS
5738
5739 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
f1aa5d8a 5740 json_object_boolean_true_add(json_path, "damped");
b05a1c8b
DS
5741
5742 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
f1aa5d8a 5743 json_object_boolean_true_add(json_path, "bestpath");
b05a1c8b
DS
5744
5745 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
f1aa5d8a 5746 json_object_boolean_true_add(json_path, "multipath");
b05a1c8b
DS
5747
5748 /* Internal route. */
5749 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
62d6dca0 5750 json_object_string_add(json_path, "pathFrom", "internal");
b05a1c8b 5751 else
62d6dca0 5752 json_object_string_add(json_path, "pathFrom", "external");
b05a1c8b
DS
5753
5754 return;
5755 }
5756
b40d939b 5757 /* Route status display. */
5758 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5759 vty_out (vty, "R");
5760 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
93406d87 5761 vty_out (vty, "S");
fb982c25 5762 else if (binfo->extra && binfo->extra->suppress)
718e3744 5763 vty_out (vty, "s");
31eba040
DS
5764 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5765 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
718e3744 5766 vty_out (vty, "*");
5767 else
5768 vty_out (vty, " ");
5769
5770 /* Selected */
5771 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5772 vty_out (vty, "h");
5773 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5774 vty_out (vty, "d");
5775 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5776 vty_out (vty, ">");
b366b518
BB
5777 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5778 vty_out (vty, "=");
718e3744 5779 else
5780 vty_out (vty, " ");
5781
5782 /* Internal route. */
b05a1c8b
DS
5783 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5784 vty_out (vty, "i");
5785 else
5786 vty_out (vty, " ");
b40d939b 5787}
5788
5789/* called from terminal list command */
5790void
5791route_vty_out (struct vty *vty, struct prefix *p,
b05a1c8b
DS
5792 struct bgp_info *binfo, int display, safi_t safi,
5793 json_object *json_paths)
b40d939b 5794{
5795 struct attr *attr;
f1aa5d8a
DS
5796 json_object *json_path = NULL;
5797 json_object *json_nexthops = NULL;
5798 json_object *json_nexthop_global = NULL;
5799 json_object *json_nexthop_ll = NULL;
47fc97cc 5800
b05a1c8b
DS
5801 if (json_paths)
5802 json_path = json_object_new_object();
b05a1c8b
DS
5803
5804 /* short status lead text */
5805 route_vty_short_status_out (vty, binfo, json_path);
718e3744 5806
b05a1c8b
DS
5807 if (!json_paths)
5808 {
5809 /* print prefix and mask */
5810 if (! display)
5811 route_vty_out_route (p, vty);
5812 else
5813 vty_out (vty, "%*s", 17, " ");
5814 }
47fc97cc 5815
718e3744 5816 /* Print attribute */
5817 attr = binfo->attr;
5818 if (attr)
5819 {
587ff0fd
LB
5820 /*
5821 * For ENCAP routes, nexthop address family is not
5822 * neccessarily the same as the prefix address family.
5823 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
5824 */
5825 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN))
5826 {
5827 if (attr->extra)
5828 {
5829 char buf[BUFSIZ];
5830 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
b05a1c8b 5831
587ff0fd
LB
5832 switch (af)
5833 {
5834 case AF_INET:
5835 vty_out (vty, "%s", inet_ntop(af,
5836 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
5837 break;
5838#if HAVE_IPV6
5839 case AF_INET6:
5840 vty_out (vty, "%s", inet_ntop(af,
5841 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
5842 break;
5843#endif
5844 default:
5845 vty_out(vty, "?");
5846 break;
5847 }
5848 }
5849 else
5850 vty_out(vty, "?");
5851 }
b05a1c8b 5852 /* IPv4 Next Hop */
587ff0fd 5853 else if (p->family == AF_INET || !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
718e3744 5854 {
b05a1c8b
DS
5855 if (json_paths)
5856 {
f1aa5d8a
DS
5857 json_nexthop_global = json_object_new_object();
5858
b05a1c8b 5859 if (safi == SAFI_MPLS_VPN)
f1aa5d8a 5860 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
b05a1c8b 5861 else
f1aa5d8a
DS
5862 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
5863
5864 json_object_string_add(json_nexthop_global, "afi", "ipv4");
5865 json_object_boolean_true_add(json_nexthop_global, "used");
b05a1c8b
DS
5866 }
5867 else
5868 {
5869 if (safi == SAFI_MPLS_VPN)
5870 vty_out (vty, "%-16s",
5871 inet_ntoa (attr->extra->mp_nexthop_global_in));
5872 else
5873 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5874 }
718e3744 5875 }
b05a1c8b
DS
5876#ifdef HAVE_IPV6
5877 /* IPv6 Next Hop */
8a92a8a0 5878 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
718e3744 5879 {
5880 int len;
5881 char buf[BUFSIZ];
5882
b05a1c8b
DS
5883 if (json_paths)
5884 {
f1aa5d8a
DS
5885 json_nexthop_global = json_object_new_object();
5886 json_object_string_add(json_nexthop_global, "ip",
5887 inet_ntop (AF_INET6,
5888 &attr->extra->mp_nexthop_global,
5889 buf, BUFSIZ));
5890 json_object_string_add(json_nexthop_global, "afi", "ipv6");
5891 json_object_string_add(json_nexthop_global, "scope", "global");
5892
5893 /* We display both LL & GL if both have been received */
5894 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
5895 {
5896 json_nexthop_ll = json_object_new_object();
5897 json_object_string_add(json_nexthop_ll, "ip",
5898 inet_ntop (AF_INET6,
5899 &attr->extra->mp_nexthop_local,
5900 buf, BUFSIZ));
5901 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
5902 json_object_string_add(json_nexthop_ll, "scope", "link-local");
5903
5904 if (IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global,
5905 &attr->extra->mp_nexthop_local) != 0)
5906 json_object_boolean_true_add(json_nexthop_ll, "used");
5907 else
5908 json_object_boolean_true_add(json_nexthop_global, "used");
5909 }
5910 else
5911 json_object_boolean_true_add(json_nexthop_global, "used");
b05a1c8b
DS
5912 }
5913 else
5914 {
433e8b67
DS
5915 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
5916 {
5917 if (binfo->peer->conf_if)
5918 {
5919 len = vty_out (vty, "%s",
5920 binfo->peer->conf_if);
5921 len = 7 - len; /* len of IPv6 addr + max len of def ifname */
5922
5923 if (len < 1)
5924 vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " ");
5925 else
5926 vty_out (vty, "%*s", len, " ");
5927 }
5928 else
5929 {
5930 len = vty_out (vty, "%s",
5931 inet_ntop (AF_INET6,
5932 &attr->extra->mp_nexthop_local,
5933 buf, BUFSIZ));
5934 len = 16 - len;
5935
5936 if (len < 1)
5937 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5938 else
5939 vty_out (vty, "%*s", len, " ");
5940 }
5941 }
5942 else
5943 {
5944 len = vty_out (vty, "%s",
5945 inet_ntop (AF_INET6,
5946 &attr->extra->mp_nexthop_global,
5947 buf, BUFSIZ));
5948 len = 16 - len;
5949
5950 if (len < 1)
5951 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5952 else
5953 vty_out (vty, "%*s", len, " ");
5954 }
b05a1c8b 5955 }
718e3744 5956 }
5957#endif /* HAVE_IPV6 */
5958
b05a1c8b 5959 /* MED/Metric */
718e3744 5960 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b 5961 if (json_paths)
f1aa5d8a 5962 json_object_int_add(json_path, "med", attr->med);
b05a1c8b
DS
5963 else
5964 vty_out (vty, "%10u", attr->med);
718e3744 5965 else
b05a1c8b
DS
5966 if (!json_paths)
5967 vty_out (vty, " ");
47fc97cc 5968
b05a1c8b 5969 /* Local Pref */
718e3744 5970 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
b05a1c8b 5971 if (json_paths)
f1aa5d8a 5972 json_object_int_add(json_path, "localpref", attr->local_pref);
b05a1c8b
DS
5973 else
5974 vty_out (vty, "%7u", attr->local_pref);
718e3744 5975 else
b05a1c8b
DS
5976 if (!json_paths)
5977 vty_out (vty, " ");
718e3744 5978
b05a1c8b
DS
5979 if (json_paths)
5980 {
5981 if (attr->extra)
f1aa5d8a 5982 json_object_int_add(json_path, "weight", attr->extra->weight);
b05a1c8b 5983 else
f1aa5d8a 5984 json_object_int_add(json_path, "weight", 0);
b05a1c8b
DS
5985 }
5986 else
5987 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
47fc97cc 5988
39e871e6
ST
5989 if (json_paths) {
5990 char buf[BUFSIZ];
5991 json_object_string_add(json_path, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
5992 }
5993
b2518c1e
PJ
5994 /* Print aspath */
5995 if (attr->aspath)
b05a1c8b
DS
5996 {
5997 if (json_paths)
f1aa5d8a 5998 json_object_string_add(json_path, "aspath", attr->aspath->str);
b05a1c8b 5999 else
f1aa5d8a 6000 aspath_print_vty (vty, "%s", attr->aspath, " ");
b05a1c8b 6001 }
47fc97cc 6002
b2518c1e 6003 /* Print origin */
b05a1c8b 6004 if (json_paths)
f1aa5d8a 6005 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
b05a1c8b
DS
6006 else
6007 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 6008 }
856ca177
MS
6009 else
6010 {
6011 if (json_paths)
6012 json_object_string_add(json_path, "alert", "No attributes");
6013 else
6014 vty_out (vty, "No attributes to print%s", VTY_NEWLINE);
6015 }
b05a1c8b
DS
6016
6017 if (json_paths)
f1aa5d8a
DS
6018 {
6019 if (json_nexthop_global || json_nexthop_ll)
6020 {
6021 json_nexthops = json_object_new_array();
6022
6023 if (json_nexthop_global)
6024 json_object_array_add(json_nexthops, json_nexthop_global);
6025
6026 if (json_nexthop_ll)
6027 json_object_array_add(json_nexthops, json_nexthop_ll);
6028
6029 json_object_object_add(json_path, "nexthops", json_nexthops);
6030 }
6031
6032 json_object_array_add(json_paths, json_path);
6033 }
b05a1c8b
DS
6034 else
6035 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6036}
6037
6038/* called from terminal list command */
6039void
856ca177
MS
6040route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi,
6041 u_char use_json, json_object *json_ar)
718e3744 6042{
856ca177
MS
6043 json_object *json_status = NULL;
6044 json_object *json_net = NULL;
6045 char buff[BUFSIZ];
718e3744 6046 /* Route status display. */
856ca177
MS
6047 if (use_json)
6048 {
6049 json_status = json_object_new_object();
6050 json_net = json_object_new_object();
6051 }
6052 else
6053 {
6054 vty_out (vty, "*");
6055 vty_out (vty, ">");
6056 vty_out (vty, " ");
6057 }
718e3744 6058
6059 /* print prefix and mask */
856ca177
MS
6060 if (use_json)
6061 json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ));
6062 else
6063 route_vty_out_route (p, vty);
718e3744 6064
6065 /* Print attribute */
6066 if (attr)
6067 {
856ca177 6068 if (use_json)
718e3744 6069 {
587ff0fd
LB
6070 if (p->family == AF_INET &&
6071 (safi == SAFI_MPLS_VPN ||
6072 safi == SAFI_ENCAP ||
6073 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
856ca177 6074 {
587ff0fd 6075 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
856ca177
MS
6076 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in));
6077 else
6078 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop));
6079 }
6080#ifdef HAVE_IPV6
6081 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6082 {
6083 char buf[BUFSIZ];
718e3744 6084
856ca177
MS
6085 json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6086 buf, BUFSIZ));
6087 }
6088#endif /* HAVE_IPV6 */
6089
6090 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6091 json_object_int_add(json_net, "metric", attr->med);
6092
6093 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6094 json_object_int_add(json_net, "localPref", attr->local_pref);
6095
6096 if (attr->extra)
6097 json_object_int_add(json_net, "weight", attr->extra->weight);
718e3744 6098 else
856ca177
MS
6099 json_object_int_add(json_net, "weight", 0);
6100
6101 /* Print aspath */
6102 if (attr->aspath)
6103 json_object_string_add(json_net, "asPath", attr->aspath->str);
6104
6105 /* Print origin */
6106 json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]);
718e3744 6107 }
856ca177
MS
6108 else
6109 {
587ff0fd
LB
6110 if (p->family == AF_INET &&
6111 (safi == SAFI_MPLS_VPN ||
6112 safi == SAFI_ENCAP ||
6113 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
856ca177 6114 {
587ff0fd 6115 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
856ca177
MS
6116 vty_out (vty, "%-16s",
6117 inet_ntoa (attr->extra->mp_nexthop_global_in));
6118 else
6119 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6120 }
6121#ifdef HAVE_IPV6
6122 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6123 {
6124 int len;
6125 char buf[BUFSIZ];
6126
6127 assert (attr->extra);
6128
6129 len = vty_out (vty, "%s",
6130 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6131 buf, BUFSIZ));
6132 len = 16 - len;
6133 if (len < 1)
6134 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6135 else
6136 vty_out (vty, "%*s", len, " ");
6137 }
718e3744 6138#endif /* HAVE_IPV6 */
856ca177
MS
6139 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6140 vty_out (vty, "%10u", attr->med);
6141 else
6142 vty_out (vty, " ");
718e3744 6143
856ca177
MS
6144 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6145 vty_out (vty, "%7u", attr->local_pref);
6146 else
6147 vty_out (vty, " ");
718e3744 6148
856ca177 6149 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
718e3744 6150
856ca177
MS
6151 /* Print aspath */
6152 if (attr->aspath)
6153 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 6154
856ca177
MS
6155 /* Print origin */
6156 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6157 }
6158 }
6159 if (use_json)
6160 {
6161 json_object_boolean_true_add(json_status, "*");
6162 json_object_boolean_true_add(json_status, ">");
6163 json_object_object_add(json_net, "appliedStatusSymbols", json_status);
6164 char buf_cut[BUFSIZ];
6165 json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net);
6166 }
6167 else
6168 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6169}
6170
5a646650 6171void
718e3744 6172route_vty_out_tag (struct vty *vty, struct prefix *p,
856ca177 6173 struct bgp_info *binfo, int display, safi_t safi, json_object *json)
718e3744 6174{
856ca177 6175 json_object *json_out = NULL;
718e3744 6176 struct attr *attr;
718e3744 6177 u_int32_t label = 0;
fb982c25
PJ
6178
6179 if (!binfo->extra)
6180 return;
856ca177
MS
6181
6182 if (json)
6183 json_out = json_object_new_object();
fb982c25 6184
b40d939b 6185 /* short status lead text */
856ca177 6186 route_vty_short_status_out (vty, binfo, json_out);
b40d939b 6187
718e3744 6188 /* print prefix and mask */
856ca177
MS
6189 if (json == NULL)
6190 {
6191 if (! display)
6192 route_vty_out_route (p, vty);
6193 else
6194 vty_out (vty, "%*s", 17, " ");
6195 }
718e3744 6196
6197 /* Print attribute */
6198 attr = binfo->attr;
6199 if (attr)
6200 {
8a92a8a0
DS
6201 if (p->family == AF_INET
6202 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 6203 {
587ff0fd 6204 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
856ca177
MS
6205 {
6206 if (json)
6207 json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in));
6208 else
6209 vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6210 }
718e3744 6211 else
856ca177
MS
6212 {
6213 if (json)
6214 json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop));
6215 else
6216 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6217 }
718e3744 6218 }
6219#ifdef HAVE_IPV6
8a92a8a0 6220 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
718e3744 6221 {
fb982c25 6222 assert (attr->extra);
856ca177
MS
6223 char buf_a[BUFSIZ];
6224 char buf_b[BUFSIZ];
6225 char buf_c[BUFSIZ];
801a9bcc 6226 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
856ca177
MS
6227 {
6228 if (json)
6229 json_object_string_add(json_out, "mpNexthopGlobalIn",
6230 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ));
6231 else
6232 vty_out (vty, "%s",
6233 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6234 buf_a, BUFSIZ));
6235 }
801a9bcc 6236 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
856ca177
MS
6237 {
6238 if (json)
6239 {
6240 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6241 buf_a, BUFSIZ);
6242 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6243 buf_b, BUFSIZ);
6244 sprintf(buf_c, "%s(%s)", buf_a, buf_b);
6245 json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c);
6246 }
6247 else
6248 vty_out (vty, "%s(%s)",
6249 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6250 buf_a, BUFSIZ),
6251 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6252 buf_b, BUFSIZ));
6253 }
6254
718e3744 6255 }
6256#endif /* HAVE_IPV6 */
6257 }
6258
fb982c25 6259 label = decode_label (binfo->extra->tag);
718e3744 6260
856ca177
MS
6261 if (json)
6262 {
6263 if (label)
6264 json_object_int_add(json_out, "notag", label);
6265 json_object_array_add(json, json_out);
6266 }
6267 else
6268 {
6269 vty_out (vty, "notag/%d", label);
6270 vty_out (vty, "%s", VTY_NEWLINE);
6271 }
718e3744 6272}
6273
6274/* dampening route */
5a646650 6275static void
856ca177
MS
6276damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6277 int display, safi_t safi, u_char use_json, json_object *json)
718e3744 6278{
6279 struct attr *attr;
718e3744 6280 int len;
50aef6f3 6281 char timebuf[BGP_UPTIME_LEN];
718e3744 6282
b40d939b 6283 /* short status lead text */
856ca177 6284 route_vty_short_status_out (vty, binfo, json);
b40d939b 6285
718e3744 6286 /* print prefix and mask */
856ca177
MS
6287 if (!use_json)
6288 {
6289 if (! display)
6290 route_vty_out_route (p, vty);
6291 else
6292 vty_out (vty, "%*s", 17, " ");
6293 }
718e3744 6294
6295 len = vty_out (vty, "%s", binfo->peer->host);
6296 len = 17 - len;
6297 if (len < 1)
856ca177
MS
6298 {
6299 if (!use_json)
6300 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6301 }
718e3744 6302 else
856ca177
MS
6303 {
6304 if (use_json)
6305 json_object_int_add(json, "peerHost", len);
6306 else
6307 vty_out (vty, "%*s", len, " ");
6308 }
718e3744 6309
856ca177
MS
6310 if (use_json)
6311 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6312 else
6313 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
718e3744 6314
6315 /* Print attribute */
6316 attr = binfo->attr;
6317 if (attr)
6318 {
6319 /* Print aspath */
6320 if (attr->aspath)
856ca177
MS
6321 {
6322 if (use_json)
6323 json_object_string_add(json, "asPath", attr->aspath->str);
6324 else
6325 aspath_print_vty (vty, "%s", attr->aspath, " ");
6326 }
718e3744 6327
6328 /* Print origin */
856ca177
MS
6329 if (use_json)
6330 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6331 else
6332 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 6333 }
856ca177
MS
6334 if (!use_json)
6335 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6336}
6337
718e3744 6338/* flap route */
5a646650 6339static void
856ca177
MS
6340flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6341 int display, safi_t safi, u_char use_json, json_object *json)
718e3744 6342{
6343 struct attr *attr;
6344 struct bgp_damp_info *bdi;
718e3744 6345 char timebuf[BGP_UPTIME_LEN];
6346 int len;
fb982c25
PJ
6347
6348 if (!binfo->extra)
6349 return;
6350
6351 bdi = binfo->extra->damp_info;
718e3744 6352
b40d939b 6353 /* short status lead text */
856ca177 6354 route_vty_short_status_out (vty, binfo, json);
b40d939b 6355
718e3744 6356 /* print prefix and mask */
856ca177
MS
6357 if (!use_json)
6358 {
6359 if (! display)
6360 route_vty_out_route (p, vty);
6361 else
6362 vty_out (vty, "%*s", 17, " ");
6363 }
718e3744 6364
6365 len = vty_out (vty, "%s", binfo->peer->host);
6366 len = 16 - len;
6367 if (len < 1)
856ca177
MS
6368 {
6369 if (!use_json)
6370 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6371 }
718e3744 6372 else
856ca177
MS
6373 {
6374 if (use_json)
6375 json_object_int_add(json, "peerHost", len);
6376 else
6377 vty_out (vty, "%*s", len, " ");
6378 }
718e3744 6379
6380 len = vty_out (vty, "%d", bdi->flap);
6381 len = 5 - len;
6382 if (len < 1)
856ca177
MS
6383 {
6384 if (!use_json)
6385 vty_out (vty, " ");
6386 }
718e3744 6387 else
856ca177
MS
6388 {
6389 if (use_json)
6390 json_object_int_add(json, "bdiFlap", len);
6391 else
6392 vty_out (vty, "%*s", len, " ");
6393 }
6394
6395 if (use_json)
6396 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json);
6397 else
6398 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6399 timebuf, BGP_UPTIME_LEN, 0, NULL));
718e3744 6400
6401 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6402 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
856ca177
MS
6403 {
6404 if (use_json)
6405 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6406 else
6407 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6408 }
718e3744 6409 else
856ca177
MS
6410 {
6411 if (!use_json)
6412 vty_out (vty, "%*s ", 8, " ");
6413 }
718e3744 6414
6415 /* Print attribute */
6416 attr = binfo->attr;
6417 if (attr)
6418 {
6419 /* Print aspath */
6420 if (attr->aspath)
856ca177
MS
6421 {
6422 if (use_json)
6423 json_object_string_add(json, "asPath", attr->aspath->str);
6424 else
6425 aspath_print_vty (vty, "%s", attr->aspath, " ");
6426 }
718e3744 6427
6428 /* Print origin */
856ca177
MS
6429 if (use_json)
6430 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6431 else
6432 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 6433 }
856ca177
MS
6434 if (!use_json)
6435 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6436}
6437
adbac85e
DW
6438static void
6439route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first,
6440 const char *header, json_object *json_adv_to)
6441{
6442 char buf1[INET6_ADDRSTRLEN];
6443 json_object *json_peer = NULL;
6444
6445 if (json_adv_to)
6446 {
6447 /* 'advertised-to' is a dictionary of peers we have advertised this
6448 * prefix too. The key is the peer's IP or swpX, the value is the
6449 * hostname if we know it and "" if not.
6450 */
6451 json_peer = json_object_new_object();
6452
6453 if (peer->hostname)
6454 json_object_string_add(json_peer, "hostname", peer->hostname);
6455
6456 if (peer->conf_if)
6457 json_object_object_add(json_adv_to, peer->conf_if, json_peer);
6458 else
6459 json_object_object_add(json_adv_to,
6460 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN),
6461 json_peer);
6462 }
6463 else
6464 {
6465 if (*first)
6466 {
6467 vty_out (vty, "%s", header);
6468 *first = 0;
6469 }
6470
6471 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6472 {
6473 if (peer->conf_if)
6474 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
6475 else
6476 vty_out (vty, " %s(%s)", peer->hostname,
6477 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6478 }
6479 else
6480 {
6481 if (peer->conf_if)
6482 vty_out (vty, " %s", peer->conf_if);
6483 else
6484 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6485 }
6486 }
6487}
6488
94f2b392 6489static void
718e3744 6490route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
b05a1c8b
DS
6491 struct bgp_info *binfo, afi_t afi, safi_t safi,
6492 json_object *json_paths)
718e3744 6493{
6494 char buf[INET6_ADDRSTRLEN];
6495 char buf1[BUFSIZ];
6496 struct attr *attr;
6497 int sockunion_vty_out (struct vty *, union sockunion *);
30b00176
JK
6498#ifdef HAVE_CLOCK_MONOTONIC
6499 time_t tbuf;
6500#endif
f1aa5d8a 6501 json_object *json_bestpath = NULL;
ffd0c037 6502 json_object *json_cluster_list = NULL;
f1aa5d8a
DS
6503 json_object *json_cluster_list_list = NULL;
6504 json_object *json_ext_community = NULL;
6505 json_object *json_last_update = NULL;
6506 json_object *json_nexthop_global = NULL;
6507 json_object *json_nexthop_ll = NULL;
6508 json_object *json_nexthops = NULL;
6509 json_object *json_path = NULL;
6510 json_object *json_peer = NULL;
6511 json_object *json_string = NULL;
adbac85e
DW
6512 json_object *json_adv_to = NULL;
6513 int first = 0;
6514 struct listnode *node, *nnode;
6515 struct peer *peer;
6516 int addpath_capable;
6517 int has_adj;
06370dac 6518 int first_as;
b05a1c8b
DS
6519
6520 if (json_paths)
6521 {
6522 json_path = json_object_new_object();
f1aa5d8a
DS
6523 json_peer = json_object_new_object();
6524 json_nexthop_global = json_object_new_object();
b05a1c8b
DS
6525 }
6526
718e3744 6527 attr = binfo->attr;
6528
6529 if (attr)
6530 {
6531 /* Line1 display AS-path, Aggregator */
6532 if (attr->aspath)
6533 {
f1aa5d8a
DS
6534 if (json_paths)
6535 {
6536 json_object_lock(attr->aspath->json);
6537 json_object_object_add(json_path, "aspath", attr->aspath->json);
6538 }
6539 else
b05a1c8b 6540 {
f1aa5d8a
DS
6541 if (attr->aspath->segments)
6542 aspath_print_vty (vty, " %s", attr->aspath, "");
b05a1c8b 6543 else
f1aa5d8a 6544 vty_out (vty, " Local");
b05a1c8b 6545 }
718e3744 6546 }
6547
b40d939b 6548 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
b05a1c8b
DS
6549 {
6550 if (json_paths)
f1aa5d8a 6551 json_object_boolean_true_add(json_path, "removed");
b05a1c8b
DS
6552 else
6553 vty_out (vty, ", (removed)");
6554 }
6555
93406d87 6556 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
b05a1c8b
DS
6557 {
6558 if (json_paths)
f1aa5d8a 6559 json_object_boolean_true_add(json_path, "stale");
b05a1c8b
DS
6560 else
6561 vty_out (vty, ", (stale)");
6562 }
6563
93406d87 6564 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
b05a1c8b
DS
6565 {
6566 if (json_paths)
6567 {
62d6dca0
DS
6568 json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as);
6569 json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr));
b05a1c8b
DS
6570 }
6571 else
6572 {
6573 vty_out (vty, ", (aggregated by %u %s)",
6574 attr->extra->aggregator_as,
6575 inet_ntoa (attr->extra->aggregator_addr));
6576 }
6577 }
6578
93406d87 6579 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
b05a1c8b
DS
6580 {
6581 if (json_paths)
62d6dca0 6582 json_object_boolean_true_add(json_path, "rxedFromRrClient");
b05a1c8b
DS
6583 else
6584 vty_out (vty, ", (Received from a RR-client)");
6585 }
6586
93406d87 6587 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
b05a1c8b
DS
6588 {
6589 if (json_paths)
62d6dca0 6590 json_object_boolean_true_add(json_path, "rxedFromRsClient");
b05a1c8b
DS
6591 else
6592 vty_out (vty, ", (Received from a RS-client)");
6593 }
6594
93406d87 6595 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
6596 {
6597 if (json_paths)
62d6dca0 6598 json_object_boolean_true_add(json_path, "dampeningHistoryEntry");
b05a1c8b
DS
6599 else
6600 vty_out (vty, ", (history entry)");
6601 }
93406d87 6602 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
b05a1c8b
DS
6603 {
6604 if (json_paths)
62d6dca0 6605 json_object_boolean_true_add(json_path, "dampeningSuppressed");
b05a1c8b
DS
6606 else
6607 vty_out (vty, ", (suppressed due to dampening)");
6608 }
6609
6610 if (!json_paths)
6611 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6612
6613 /* Line2 display Next-hop, Neighbor, Router-id */
f1aa5d8a 6614 /* Display the nexthop */
587ff0fd
LB
6615 if (p->family == AF_INET &&
6616 (safi == SAFI_MPLS_VPN ||
6617 safi == SAFI_ENCAP ||
6618 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 6619 {
587ff0fd 6620 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
b05a1c8b
DS
6621 {
6622 if (json_paths)
f1aa5d8a 6623 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
b05a1c8b
DS
6624 else
6625 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6626 }
6627 else
6628 {
6629 if (json_paths)
f1aa5d8a 6630 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
b05a1c8b
DS
6631 else
6632 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
6633 }
6634
6635 if (json_paths)
f1aa5d8a 6636 json_object_string_add(json_nexthop_global, "afi", "ipv4");
718e3744 6637 }
6638#ifdef HAVE_IPV6
6639 else
6640 {
fb982c25 6641 assert (attr->extra);
b05a1c8b
DS
6642 if (json_paths)
6643 {
f1aa5d8a
DS
6644 json_object_string_add(json_nexthop_global, "ip",
6645 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6646 buf, INET6_ADDRSTRLEN));
6647 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6648 json_object_string_add(json_nexthop_global, "scope", "global");
b05a1c8b
DS
6649 }
6650 else
6651 {
6652 vty_out (vty, " %s",
6653 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6654 buf, INET6_ADDRSTRLEN));
6655 }
718e3744 6656 }
6657#endif /* HAVE_IPV6 */
6658
b05a1c8b 6659
f1aa5d8a
DS
6660 /* Display the IGP cost or 'inaccessible' */
6661 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6662 {
6663 if (json_paths)
6664 json_object_boolean_false_add(json_nexthop_global, "accessible");
6665 else
6666 vty_out (vty, " (inaccessible)");
6667 }
6668 else
6669 {
6670 if (binfo->extra && binfo->extra->igpmetric)
b05a1c8b
DS
6671 {
6672 if (json_paths)
f1aa5d8a 6673 json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric);
b05a1c8b 6674 else
f1aa5d8a 6675 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
b05a1c8b 6676 }
f1aa5d8a
DS
6677
6678 /* IGP cost is 0, display this only for json */
b05a1c8b
DS
6679 else
6680 {
6681 if (json_paths)
f1aa5d8a 6682 json_object_int_add(json_nexthop_global, "metric", 0);
b05a1c8b
DS
6683 }
6684
6685 if (json_paths)
f1aa5d8a
DS
6686 json_object_boolean_true_add(json_nexthop_global, "accessible");
6687 }
6688
6689 /* Display peer "from" output */
6690 /* This path was originated locally */
6691 if (binfo->peer == bgp->peer_self)
718e3744 6692 {
f1aa5d8a
DS
6693
6694 if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
b05a1c8b
DS
6695 {
6696 if (json_paths)
62d6dca0 6697 json_object_string_add(json_peer, "peerId", "0.0.0.0");
b05a1c8b 6698 else
f1aa5d8a 6699 vty_out (vty, " from 0.0.0.0 ");
b05a1c8b 6700 }
f1aa5d8a 6701 else
b05a1c8b
DS
6702 {
6703 if (json_paths)
62d6dca0 6704 json_object_string_add(json_peer, "peerId", "::");
b05a1c8b 6705 else
f1aa5d8a 6706 vty_out (vty, " from :: ");
b05a1c8b
DS
6707 }
6708
f1aa5d8a 6709 if (json_paths)
62d6dca0 6710 json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id));
b05a1c8b 6711 else
f1aa5d8a
DS
6712 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6713 }
6714
6715 /* We RXed this path from one of our peers */
6716 else
6717 {
b05a1c8b
DS
6718
6719 if (json_paths)
6720 {
62d6dca0
DS
6721 json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6722 json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
f1aa5d8a 6723
04b6bdc0
DW
6724 if (binfo->peer->hostname)
6725 json_object_string_add(json_peer, "hostname", binfo->peer->hostname);
6726
6727 if (binfo->peer->domainname)
6728 json_object_string_add(json_peer, "domainname", binfo->peer->domainname);
6729
036a4e7d 6730 if (binfo->peer->conf_if)
f1aa5d8a 6731 json_object_string_add(json_peer, "interface", binfo->peer->conf_if);
b05a1c8b
DS
6732 }
6733 else
6734 {
036a4e7d 6735 if (binfo->peer->conf_if)
04b6bdc0
DW
6736 {
6737 if (binfo->peer->hostname &&
6738 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6739 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
6740 binfo->peer->conf_if);
6741 else
6742 vty_out (vty, " from %s", binfo->peer->conf_if);
6743 }
036a4e7d 6744 else
04b6bdc0
DW
6745 {
6746 if (binfo->peer->hostname &&
6747 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6748 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
6749 binfo->peer->host);
6750 else
6751 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6752 }
b05a1c8b 6753
f1aa5d8a
DS
6754 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6755 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
6756 else
6757 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
b05a1c8b 6758 }
718e3744 6759 }
b05a1c8b
DS
6760
6761 if (!json_paths)
6762 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6763
6764#ifdef HAVE_IPV6
f1aa5d8a 6765 /* display the link-local nexthop */
801a9bcc 6766 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
718e3744 6767 {
b05a1c8b
DS
6768 if (json_paths)
6769 {
f1aa5d8a
DS
6770 json_nexthop_ll = json_object_new_object();
6771 json_object_string_add(json_nexthop_ll, "ip",
6772 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6773 buf, INET6_ADDRSTRLEN));
6774 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
6775 json_object_string_add(json_nexthop_ll, "scope", "link-local");
6776
6777 json_object_boolean_true_add(json_nexthop_ll, "accessible");
6778 json_object_boolean_true_add(json_nexthop_ll, "used");
b05a1c8b
DS
6779 }
6780 else
6781 {
356b3294 6782 vty_out (vty, " (%s) (used)%s",
b05a1c8b
DS
6783 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6784 buf, INET6_ADDRSTRLEN),
6785 VTY_NEWLINE);
6786 }
718e3744 6787 }
f1aa5d8a
DS
6788 /* If we do not have a link-local nexthop then we must flag the global as "used" */
6789 else
6790 {
6791 if (json_paths)
6792 json_object_boolean_true_add(json_nexthop_global, "used");
6793 }
718e3744 6794#endif /* HAVE_IPV6 */
6795
0d9551dc 6796 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
b05a1c8b 6797 if (json_paths)
f1aa5d8a 6798 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
b05a1c8b 6799 else
f1aa5d8a 6800 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
718e3744 6801
6802 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b
DS
6803 {
6804 if (json_paths)
f1aa5d8a 6805 json_object_int_add(json_path, "med", attr->med);
b05a1c8b 6806 else
f1aa5d8a 6807 vty_out (vty, ", metric %u", attr->med);
b05a1c8b 6808 }
718e3744 6809
6810 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
b05a1c8b
DS
6811 {
6812 if (json_paths)
f1aa5d8a 6813 json_object_int_add(json_path, "localpref", attr->local_pref);
b05a1c8b 6814 else
f1aa5d8a 6815 vty_out (vty, ", localpref %u", attr->local_pref);
b05a1c8b 6816 }
718e3744 6817 else
b05a1c8b
DS
6818 {
6819 if (json_paths)
f1aa5d8a 6820 json_object_int_add(json_path, "localpref", bgp->default_local_pref);
b05a1c8b 6821 else
f1aa5d8a 6822 vty_out (vty, ", localpref %u", bgp->default_local_pref);
b05a1c8b 6823 }
718e3744 6824
fb982c25 6825 if (attr->extra && attr->extra->weight != 0)
b05a1c8b
DS
6826 {
6827 if (json_paths)
f1aa5d8a 6828 json_object_int_add(json_path, "weight", attr->extra->weight);
b05a1c8b 6829 else
f1aa5d8a 6830 vty_out (vty, ", weight %u", attr->extra->weight);
b05a1c8b 6831 }
0d9551dc
DS
6832
6833 if (attr->extra && attr->extra->tag != 0)
b05a1c8b
DS
6834 {
6835 if (json_paths)
f1aa5d8a 6836 json_object_int_add(json_path, "tag", attr->extra->tag);
b05a1c8b 6837 else
f1aa5d8a 6838 vty_out (vty, ", tag %d", attr->extra->tag);
b05a1c8b 6839 }
718e3744 6840
31eba040 6841 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
b05a1c8b
DS
6842 {
6843 if (json_paths)
f1aa5d8a 6844 json_object_boolean_false_add(json_path, "valid");
b05a1c8b
DS
6845 else
6846 vty_out (vty, ", invalid");
6847 }
31eba040 6848 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
6849 {
6850 if (json_paths)
f1aa5d8a 6851 json_object_boolean_true_add(json_path, "valid");
b05a1c8b
DS
6852 else
6853 vty_out (vty, ", valid");
6854 }
718e3744 6855
6856 if (binfo->peer != bgp->peer_self)
6857 {
f1aa5d8a 6858 if (binfo->peer->as == binfo->peer->local_as)
b05a1c8b 6859 {
66b199b2
DS
6860 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
6861 {
6862 if (json_paths)
f1aa5d8a 6863 json_object_string_add(json_peer, "type", "confed-internal");
66b199b2 6864 else
f1aa5d8a 6865 vty_out (vty, ", confed-internal");
66b199b2 6866 }
b05a1c8b 6867 else
66b199b2
DS
6868 {
6869 if (json_paths)
f1aa5d8a 6870 json_object_string_add(json_peer, "type", "internal");
66b199b2 6871 else
f1aa5d8a 6872 vty_out (vty, ", internal");
66b199b2 6873 }
b05a1c8b 6874 }
f1aa5d8a 6875 else
b05a1c8b
DS
6876 {
6877 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
6878 {
6879 if (json_paths)
f1aa5d8a 6880 json_object_string_add(json_peer, "type", "confed-external");
b05a1c8b 6881 else
f1aa5d8a 6882 vty_out (vty, ", confed-external");
b05a1c8b
DS
6883 }
6884 else
6885 {
6886 if (json_paths)
f1aa5d8a 6887 json_object_string_add(json_peer, "type", "external");
b05a1c8b 6888 else
f1aa5d8a 6889 vty_out (vty, ", external");
b05a1c8b
DS
6890 }
6891 }
718e3744 6892 }
6893 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
b05a1c8b
DS
6894 {
6895 if (json_paths)
6896 {
f1aa5d8a
DS
6897 json_object_boolean_true_add(json_path, "aggregated");
6898 json_object_boolean_true_add(json_path, "local");
b05a1c8b
DS
6899 }
6900 else
6901 {
6902 vty_out (vty, ", aggregated, local");
6903 }
6904 }
718e3744 6905 else if (binfo->type != ZEBRA_ROUTE_BGP)
b05a1c8b
DS
6906 {
6907 if (json_paths)
f1aa5d8a 6908 json_object_boolean_true_add(json_path, "sourced");
b05a1c8b
DS
6909 else
6910 vty_out (vty, ", sourced");
6911 }
718e3744 6912 else
b05a1c8b
DS
6913 {
6914 if (json_paths)
6915 {
f1aa5d8a
DS
6916 json_object_boolean_true_add(json_path, "sourced");
6917 json_object_boolean_true_add(json_path, "local");
b05a1c8b
DS
6918 }
6919 else
6920 {
6921 vty_out (vty, ", sourced, local");
6922 }
6923 }
718e3744 6924
6925 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
b05a1c8b
DS
6926 {
6927 if (json_paths)
62d6dca0 6928 json_object_boolean_true_add(json_path, "atomicAggregate");
b05a1c8b
DS
6929 else
6930 vty_out (vty, ", atomic-aggregate");
6931 }
718e3744 6932
de8d5dff
JB
6933 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6934 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6935 bgp_info_mpath_count (binfo)))
b05a1c8b
DS
6936 {
6937 if (json_paths)
f1aa5d8a 6938 json_object_boolean_true_add(json_path, "multipath");
b05a1c8b
DS
6939 else
6940 vty_out (vty, ", multipath");
6941 }
de8d5dff 6942
06370dac
DW
6943 // Mark the bestpath(s)
6944 if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED))
6945 {
6946 first_as = aspath_get_firstas(attr->aspath);
6947
6948 if (json_paths)
6949 {
6950 if (!json_bestpath)
6951 json_bestpath = json_object_new_object();
6952 json_object_int_add(json_bestpath, "bestpathFromAs", first_as);
6953 }
6954 else
6955 {
6956 if (first_as)
6957 vty_out (vty, ", bestpath-from-AS %d", first_as);
6958 else
6959 vty_out (vty, ", bestpath-from-AS Local");
6960 }
6961 }
6962
718e3744 6963 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
b05a1c8b
DS
6964 {
6965 if (json_paths)
f1aa5d8a 6966 {
06370dac
DW
6967 if (!json_bestpath)
6968 json_bestpath = json_object_new_object();
f1aa5d8a 6969 json_object_boolean_true_add(json_bestpath, "overall");
f1aa5d8a 6970 }
b05a1c8b
DS
6971 else
6972 vty_out (vty, ", best");
6973 }
718e3744 6974
06370dac
DW
6975 if (json_bestpath)
6976 json_object_object_add(json_path, "bestpath", json_bestpath);
6977
b05a1c8b
DS
6978 if (!json_paths)
6979 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6980
6981 /* Line 4 display Community */
6982 if (attr->community)
b05a1c8b
DS
6983 {
6984 if (json_paths)
6985 {
f1aa5d8a
DS
6986 json_object_lock(attr->community->json);
6987 json_object_object_add(json_path, "community", attr->community->json);
b05a1c8b
DS
6988 }
6989 else
6990 {
6991 vty_out (vty, " Community: %s%s", attr->community->str,
6992 VTY_NEWLINE);
6993 }
6994 }
718e3744 6995
6996 /* Line 5 display Extended-community */
6997 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
b05a1c8b
DS
6998 {
6999 if (json_paths)
7000 {
f1aa5d8a
DS
7001 json_ext_community = json_object_new_object();
7002 json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str);
62d6dca0 7003 json_object_object_add(json_path, "extendedCommunity", json_ext_community);
b05a1c8b
DS
7004 }
7005 else
7006 {
7007 vty_out (vty, " Extended Community: %s%s",
7008 attr->extra->ecommunity->str, VTY_NEWLINE);
7009 }
7010 }
7011
718e3744 7012 /* Line 6 display Originator, Cluster-id */
7013 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
7014 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
7015 {
fb982c25 7016 assert (attr->extra);
718e3744 7017 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
b05a1c8b
DS
7018 {
7019 if (json_paths)
62d6dca0 7020 json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id));
b05a1c8b 7021 else
f1aa5d8a
DS
7022 vty_out (vty, " Originator: %s",
7023 inet_ntoa (attr->extra->originator_id));
b05a1c8b 7024 }
718e3744 7025
7026 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
7027 {
7028 int i;
b05a1c8b
DS
7029
7030 if (json_paths)
7031 {
f1aa5d8a
DS
7032 json_cluster_list = json_object_new_object();
7033 json_cluster_list_list = json_object_new_array();
7034
b05a1c8b
DS
7035 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7036 {
7037 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
f1aa5d8a 7038 json_object_array_add(json_cluster_list_list, json_string);
b05a1c8b 7039 }
f1aa5d8a
DS
7040
7041 /* struct cluster_list does not have "str" variable like
7042 * aspath and community do. Add this someday if someone
7043 * asks for it.
7044 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
7045 */
7046 json_object_object_add(json_cluster_list, "list", json_cluster_list_list);
62d6dca0 7047 json_object_object_add(json_path, "clusterList", json_cluster_list);
b05a1c8b
DS
7048 }
7049 else
7050 {
7051 vty_out (vty, ", Cluster list: ");
7052
7053 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7054 {
7055 vty_out (vty, "%s ",
7056 inet_ntoa (attr->extra->cluster->list[i]));
7057 }
7058 }
718e3744 7059 }
b05a1c8b
DS
7060
7061 if (!json_paths)
7062 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7063 }
b05a1c8b 7064
fb982c25 7065 if (binfo->extra && binfo->extra->damp_info)
b05a1c8b 7066 bgp_damp_info_vty (vty, binfo, json_path);
718e3744 7067
a82478b9
DS
7068 /* Line 7 display Addpath IDs */
7069 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
b05a1c8b
DS
7070 {
7071 if (json_paths)
7072 {
62d6dca0
DS
7073 json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id);
7074 json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id);
b05a1c8b
DS
7075 }
7076 else
7077 {
7078 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
7079 binfo->addpath_rx_id, binfo->addpath_tx_id,
7080 VTY_NEWLINE);
7081 }
7082 }
a82478b9 7083
adbac85e
DW
7084 /* If we used addpath to TX a non-bestpath we need to display
7085 * "Advertised to" on a path-by-path basis */
7086 if (bgp->addpath_tx_used[afi][safi])
7087 {
7088 first = 1;
7089
7090 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7091 {
7092 addpath_capable = bgp_addpath_encode_tx (peer, afi, safi);
7093 has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id);
7094
7095 if ((addpath_capable && has_adj) ||
7096 (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)))
7097 {
7098 if (json_path && !json_adv_to)
7099 json_adv_to = json_object_new_object();
7100
7101 route_vty_out_advertised_to(vty, peer, &first,
7102 " Advertised to:",
7103 json_adv_to);
7104 }
7105 }
7106
7107 if (json_path)
7108 {
7109 if (json_adv_to)
7110 {
7111 json_object_object_add(json_path, "advertisedTo", json_adv_to);
7112 }
7113 }
7114 else
7115 {
7116 if (!first)
7117 {
7118 vty_out (vty, "%s", VTY_NEWLINE);
7119 }
7120 }
7121 }
7122
a82478b9 7123 /* Line 8 display Uptime */
30b00176
JK
7124#ifdef HAVE_CLOCK_MONOTONIC
7125 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
b05a1c8b 7126 if (json_paths)
f1aa5d8a
DS
7127 {
7128 json_last_update = json_object_new_object();
7129 json_object_int_add(json_last_update, "epoch", tbuf);
7130 json_object_string_add(json_last_update, "string", ctime(&tbuf));
62d6dca0 7131 json_object_object_add(json_path, "lastUpdate", json_last_update);
f1aa5d8a 7132 }
b05a1c8b
DS
7133 else
7134 vty_out (vty, " Last update: %s", ctime(&tbuf));
30b00176 7135#else
b05a1c8b 7136 if (json_paths)
f1aa5d8a
DS
7137 {
7138 json_last_update = json_object_new_object();
7139 json_object_int_add(json_last_update, "epoch", tbuf);
7140 json_object_string_add(json_last_update, "string", ctime(&binfo->uptime));
62d6dca0 7141 json_object_object_add(json_path, "lastUpdate", json_last_update);
f1aa5d8a 7142 }
b05a1c8b
DS
7143 else
7144 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
30b00176 7145#endif /* HAVE_CLOCK_MONOTONIC */
718e3744 7146 }
b05a1c8b
DS
7147
7148 /* We've constructed the json object for this path, add it to the json
7149 * array of paths
7150 */
7151 if (json_paths)
f1aa5d8a
DS
7152 {
7153 if (json_nexthop_global || json_nexthop_ll)
7154 {
7155 json_nexthops = json_object_new_array();
7156
7157 if (json_nexthop_global)
7158 json_object_array_add(json_nexthops, json_nexthop_global);
7159
7160 if (json_nexthop_ll)
7161 json_object_array_add(json_nexthops, json_nexthop_ll);
7162
7163 json_object_object_add(json_path, "nexthops", json_nexthops);
7164 }
7165
7166 json_object_object_add(json_path, "peer", json_peer);
7167 json_object_array_add(json_paths, json_path);
7168 }
b05a1c8b
DS
7169 else
7170 vty_out (vty, "%s", VTY_NEWLINE);
b366b518
BB
7171}
7172
47fc97cc 7173#define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
718e3744 7174#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7175#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7176
7177enum bgp_show_type
7178{
7179 bgp_show_type_normal,
7180 bgp_show_type_regexp,
7181 bgp_show_type_prefix_list,
7182 bgp_show_type_filter_list,
7183 bgp_show_type_route_map,
7184 bgp_show_type_neighbor,
7185 bgp_show_type_cidr_only,
7186 bgp_show_type_prefix_longer,
7187 bgp_show_type_community_all,
7188 bgp_show_type_community,
7189 bgp_show_type_community_exact,
7190 bgp_show_type_community_list,
7191 bgp_show_type_community_list_exact,
7192 bgp_show_type_flap_statistics,
7193 bgp_show_type_flap_address,
7194 bgp_show_type_flap_prefix,
7195 bgp_show_type_flap_cidr_only,
7196 bgp_show_type_flap_regexp,
7197 bgp_show_type_flap_filter_list,
7198 bgp_show_type_flap_prefix_list,
7199 bgp_show_type_flap_prefix_longer,
7200 bgp_show_type_flap_route_map,
7201 bgp_show_type_flap_neighbor,
7202 bgp_show_type_dampend_paths,
7203 bgp_show_type_damp_neighbor
7204};
7205
50ef26d4 7206static int
7207bgp_show_prefix_list (struct vty *vty, const char *name,
7208 const char *prefix_list_str, afi_t afi,
7209 safi_t safi, enum bgp_show_type type);
7210static int
7211bgp_show_filter_list (struct vty *vty, const char *name,
7212 const char *filter, afi_t afi,
7213 safi_t safi, enum bgp_show_type type);
7214static int
7215bgp_show_route_map (struct vty *vty, const char *name,
7216 const char *rmap_str, afi_t afi,
7217 safi_t safi, enum bgp_show_type type);
7218static int
7219bgp_show_community_list (struct vty *vty, const char *name,
7220 const char *com, int exact,
7221 afi_t afi, safi_t safi);
7222static int
7223bgp_show_prefix_longer (struct vty *vty, const char *name,
7224 const char *prefix, afi_t afi,
7225 safi_t safi, enum bgp_show_type type);
7226
5a646650 7227static int
9f689658
DD
7228bgp_show_table (struct vty *vty, struct bgp_table *table,
7229 struct in_addr *router_id, enum bgp_show_type type,
7230 void *output_arg, u_char use_json, json_object *json)
718e3744 7231{
718e3744 7232 struct bgp_info *ri;
7233 struct bgp_node *rn;
718e3744 7234 int header = 1;
718e3744 7235 int display;
5a646650 7236 unsigned long output_count;
b05a1c8b
DS
7237 struct prefix *p;
7238 char buf[BUFSIZ];
7239 char buf2[BUFSIZ];
f1aa5d8a
DS
7240 json_object *json_paths = NULL;
7241 json_object *json_routes = NULL;
b05a1c8b
DS
7242
7243 if (use_json)
7244 {
9f689658
DD
7245 if (json == NULL)
7246 json = json_object_new_object();
7247
62d6dca0
DS
7248 json_object_int_add(json, "tableVersion", table->version);
7249 json_object_string_add(json, "routerId", inet_ntoa (*router_id));
b05a1c8b
DS
7250 json_routes = json_object_new_object();
7251 }
718e3744 7252
7253 /* This is first entry point, so reset total line. */
5a646650 7254 output_count = 0;
718e3744 7255
718e3744 7256 /* Start processing of routes. */
7257 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7258 if (rn->info != NULL)
7259 {
856ca177 7260 display = 0;
718e3744 7261
b05a1c8b
DS
7262 if (use_json)
7263 json_paths = json_object_new_array();
7264 else
7265 json_paths = NULL;
7266
856ca177
MS
7267 for (ri = rn->info; ri; ri = ri->next)
7268 {
7269 if (type == bgp_show_type_flap_statistics
7270 || type == bgp_show_type_flap_address
7271 || type == bgp_show_type_flap_prefix
7272 || type == bgp_show_type_flap_cidr_only
7273 || type == bgp_show_type_flap_regexp
7274 || type == bgp_show_type_flap_filter_list
7275 || type == bgp_show_type_flap_prefix_list
7276 || type == bgp_show_type_flap_prefix_longer
7277 || type == bgp_show_type_flap_route_map
7278 || type == bgp_show_type_flap_neighbor
7279 || type == bgp_show_type_dampend_paths
7280 || type == bgp_show_type_damp_neighbor)
7281 {
7282 if (!(ri->extra && ri->extra->damp_info))
7283 continue;
7284 }
7285 if (type == bgp_show_type_regexp
7286 || type == bgp_show_type_flap_regexp)
7287 {
7288 regex_t *regex = output_arg;
718e3744 7289
856ca177
MS
7290 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7291 continue;
7292 }
7293 if (type == bgp_show_type_prefix_list
7294 || type == bgp_show_type_flap_prefix_list)
7295 {
7296 struct prefix_list *plist = output_arg;
718e3744 7297
856ca177
MS
7298 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7299 continue;
7300 }
7301 if (type == bgp_show_type_filter_list
7302 || type == bgp_show_type_flap_filter_list)
7303 {
7304 struct as_list *as_list = output_arg;
558d1fec 7305
856ca177
MS
7306 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7307 continue;
7308 }
7309 if (type == bgp_show_type_route_map
7310 || type == bgp_show_type_flap_route_map)
7311 {
7312 struct route_map *rmap = output_arg;
7313 struct bgp_info binfo;
7314 struct attr dummy_attr;
7315 struct attr_extra dummy_extra;
7316 int ret;
718e3744 7317
856ca177
MS
7318 dummy_attr.extra = &dummy_extra;
7319 bgp_attr_dup (&dummy_attr, ri->attr);
718e3744 7320
856ca177
MS
7321 binfo.peer = ri->peer;
7322 binfo.attr = &dummy_attr;
718e3744 7323
856ca177
MS
7324 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
7325 if (ret == RMAP_DENYMATCH)
7326 continue;
7327 }
7328 if (type == bgp_show_type_neighbor
7329 || type == bgp_show_type_flap_neighbor
7330 || type == bgp_show_type_damp_neighbor)
7331 {
7332 union sockunion *su = output_arg;
718e3744 7333
856ca177
MS
7334 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7335 continue;
7336 }
7337 if (type == bgp_show_type_cidr_only
7338 || type == bgp_show_type_flap_cidr_only)
7339 {
7340 u_int32_t destination;
718e3744 7341
856ca177
MS
7342 destination = ntohl (rn->p.u.prefix4.s_addr);
7343 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7344 continue;
7345 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7346 continue;
7347 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7348 continue;
7349 }
7350 if (type == bgp_show_type_prefix_longer
7351 || type == bgp_show_type_flap_prefix_longer)
7352 {
7353 struct prefix *p = output_arg;
718e3744 7354
856ca177
MS
7355 if (! prefix_match (p, &rn->p))
7356 continue;
7357 }
7358 if (type == bgp_show_type_community_all)
7359 {
7360 if (! ri->attr->community)
7361 continue;
7362 }
7363 if (type == bgp_show_type_community)
7364 {
7365 struct community *com = output_arg;
718e3744 7366
856ca177
MS
7367 if (! ri->attr->community ||
7368 ! community_match (ri->attr->community, com))
7369 continue;
7370 }
7371 if (type == bgp_show_type_community_exact)
7372 {
7373 struct community *com = output_arg;
718e3744 7374
856ca177
MS
7375 if (! ri->attr->community ||
7376 ! community_cmp (ri->attr->community, com))
7377 continue;
7378 }
7379 if (type == bgp_show_type_community_list)
7380 {
7381 struct community_list *list = output_arg;
718e3744 7382
856ca177
MS
7383 if (! community_list_match (ri->attr->community, list))
7384 continue;
7385 }
7386 if (type == bgp_show_type_community_list_exact)
7387 {
7388 struct community_list *list = output_arg;
718e3744 7389
856ca177
MS
7390 if (! community_list_exact_match (ri->attr->community, list))
7391 continue;
7392 }
7393 if (type == bgp_show_type_flap_address
7394 || type == bgp_show_type_flap_prefix)
7395 {
7396 struct prefix *p = output_arg;
718e3744 7397
856ca177
MS
7398 if (! prefix_match (&rn->p, p))
7399 continue;
b05a1c8b 7400
856ca177
MS
7401 if (type == bgp_show_type_flap_prefix)
7402 if (p->prefixlen != rn->p.prefixlen)
7403 continue;
7404 }
7405 if (type == bgp_show_type_dampend_paths
7406 || type == bgp_show_type_damp_neighbor)
7407 {
7408 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7409 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7410 continue;
7411 }
7412
7413 if (!use_json && header)
7414 {
7415 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (*router_id), VTY_NEWLINE);
7416 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7417 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7418 if (type == bgp_show_type_dampend_paths
7419 || type == bgp_show_type_damp_neighbor)
7420 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7421 else if (type == bgp_show_type_flap_statistics
7422 || type == bgp_show_type_flap_address
7423 || type == bgp_show_type_flap_prefix
7424 || type == bgp_show_type_flap_cidr_only
7425 || type == bgp_show_type_flap_regexp
7426 || type == bgp_show_type_flap_filter_list
7427 || type == bgp_show_type_flap_prefix_list
7428 || type == bgp_show_type_flap_prefix_longer
7429 || type == bgp_show_type_flap_route_map
7430 || type == bgp_show_type_flap_neighbor)
7431 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7432 else
7433 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7434 header = 0;
7435 }
7436
7437 if (type == bgp_show_type_dampend_paths
7438 || type == bgp_show_type_damp_neighbor)
7439 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7440 else if (type == bgp_show_type_flap_statistics
7441 || type == bgp_show_type_flap_address
7442 || type == bgp_show_type_flap_prefix
7443 || type == bgp_show_type_flap_cidr_only
7444 || type == bgp_show_type_flap_regexp
7445 || type == bgp_show_type_flap_filter_list
7446 || type == bgp_show_type_flap_prefix_list
7447 || type == bgp_show_type_flap_prefix_longer
7448 || type == bgp_show_type_flap_route_map
7449 || type == bgp_show_type_flap_neighbor)
7450 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7451 else
7452 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
7453 display++;
b05a1c8b
DS
7454 }
7455
856ca177
MS
7456 if (display)
7457 {
7458 output_count++;
7459 if (use_json)
7460 {
7461 p = &rn->p;
7462 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
7463 json_object_object_add(json_routes, buf2, json_paths);
7464 }
7465 }
9f689658 7466 }
718e3744 7467
b05a1c8b 7468 if (use_json)
718e3744 7469 {
d1d16a96 7470 json_object_object_add(json, "routes", json_routes);
b05a1c8b 7471 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
f1aa5d8a 7472 json_object_free(json);
718e3744 7473 }
7474 else
b05a1c8b
DS
7475 {
7476 /* No route is displayed */
7477 if (output_count == 0)
7478 {
7479 if (type == bgp_show_type_normal)
856ca177 7480 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
b05a1c8b
DS
7481 }
7482 else
7483 vty_out (vty, "%sTotal number of prefixes %ld%s",
856ca177 7484 VTY_NEWLINE, output_count, VTY_NEWLINE);
b05a1c8b 7485 }
718e3744 7486
7487 return CMD_SUCCESS;
7488}
7489
5a646650 7490static int
fee0f4c6 7491bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
856ca177 7492 enum bgp_show_type type, void *output_arg, u_char use_json)
fee0f4c6 7493{
7494 struct bgp_table *table;
7495
856ca177
MS
7496 if (bgp == NULL)
7497 {
7498 bgp = bgp_get_default ();
7499 }
fee0f4c6 7500
7501 if (bgp == NULL)
7502 {
856ca177
MS
7503 if (!use_json)
7504 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
fee0f4c6 7505 return CMD_WARNING;
7506 }
7507
fee0f4c6 7508 table = bgp->rib[afi][safi];
7509
9f689658
DD
7510 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg,
7511 use_json, NULL);
fee0f4c6 7512}
7513
f186de26 7514static void
7515bgp_show_all_instances_routes_vty (struct vty *vty, afi_t afi, safi_t safi,
7516 u_char use_json)
7517{
7518 struct listnode *node, *nnode;
7519 struct bgp *bgp;
7520 struct bgp_table *table;
9f689658
DD
7521 json_object *json = NULL;
7522 int is_first = 1;
7523
7524 if (use_json)
7525 vty_out (vty, "{%s", VTY_NEWLINE);
f186de26 7526
7527 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
7528 {
9f689658
DD
7529 if (use_json)
7530 {
7531 if (!(json = json_object_new_object()))
7532 {
7533 zlog_err("Unable to allocate memory for JSON object");
7534 vty_out (vty,
7535 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}%s",
7536 VTY_NEWLINE);
7537 return;
7538 }
7539 json_object_int_add(json, "vrfId",
7540 (bgp->vrf_id == VRF_UNKNOWN)
7541 ? -1 : bgp->vrf_id);
7542 json_object_string_add(json, "vrfName",
7543 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7544 ? "Default" : bgp->name);
7545 if (! is_first)
7546 vty_out (vty, ",%s", VTY_NEWLINE);
7547 else
7548 is_first = 0;
7549
7550 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7551 ? "Default" : bgp->name);
7552 }
7553 else
7554 {
7555 vty_out (vty, "%sInstance %s:%s",
7556 VTY_NEWLINE,
7557 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7558 ? "Default" : bgp->name,
7559 VTY_NEWLINE);
7560 }
f186de26 7561 table = bgp->rib[afi][safi];
7562 bgp_show_table (vty, table, &bgp->router_id,
9f689658
DD
7563 bgp_show_type_normal, NULL, use_json, json);
7564
f186de26 7565 }
9f689658
DD
7566
7567 if (use_json)
7568 vty_out (vty, "}%s", VTY_NEWLINE);
f186de26 7569}
7570
718e3744 7571/* Header of detailed BGP route information */
94f2b392 7572static void
718e3744 7573route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7574 struct bgp_node *rn,
b05a1c8b
DS
7575 struct prefix_rd *prd, afi_t afi, safi_t safi,
7576 json_object *json)
718e3744 7577{
7578 struct bgp_info *ri;
7579 struct prefix *p;
7580 struct peer *peer;
1eb8ef25 7581 struct listnode *node, *nnode;
718e3744 7582 char buf1[INET6_ADDRSTRLEN];
7583 char buf2[INET6_ADDRSTRLEN];
7584 int count = 0;
7585 int best = 0;
7586 int suppress = 0;
7587 int no_export = 0;
7588 int no_advertise = 0;
7589 int local_as = 0;
adbac85e 7590 int first = 1;
ffd0c037 7591 json_object *json_adv_to = NULL;
718e3744 7592
7593 p = &rn->p;
b05a1c8b
DS
7594
7595 if (json)
7596 {
f1aa5d8a
DS
7597 json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7598 json_object_int_add(json, "prefixlen", p->prefixlen);
b05a1c8b
DS
7599 }
7600 else
7601 {
7602 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
587ff0fd 7603 ((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) ?
b05a1c8b
DS
7604 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7605 safi == SAFI_MPLS_VPN ? ":" : "",
7606 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7607 p->prefixlen, VTY_NEWLINE);
7608 }
718e3744 7609
7610 for (ri = rn->info; ri; ri = ri->next)
7611 {
7612 count++;
7613 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7614 {
7615 best = count;
fb982c25 7616 if (ri->extra && ri->extra->suppress)
718e3744 7617 suppress = 1;
7618 if (ri->attr->community != NULL)
7619 {
7620 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7621 no_advertise = 1;
7622 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7623 no_export = 1;
7624 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7625 local_as = 1;
7626 }
7627 }
7628 }
7629
b05a1c8b 7630 if (!json)
718e3744 7631 {
b05a1c8b
DS
7632 vty_out (vty, "Paths: (%d available", count);
7633 if (best)
7634 {
7635 vty_out (vty, ", best #%d", best);
7636 if (safi == SAFI_UNICAST)
7637 vty_out (vty, ", table Default-IP-Routing-Table");
7638 }
7639 else
7640 vty_out (vty, ", no best path");
7641
7642 if (no_advertise)
7643 vty_out (vty, ", not advertised to any peer");
7644 else if (no_export)
7645 vty_out (vty, ", not advertised to EBGP peer");
7646 else if (local_as)
7647 vty_out (vty, ", not advertised outside local AS");
7648
7649 if (suppress)
7650 vty_out (vty, ", Advertisements suppressed by an aggregate.");
7651 vty_out (vty, ")%s", VTY_NEWLINE);
718e3744 7652 }
718e3744 7653
adbac85e
DW
7654 /* If we are not using addpath then we can display Advertised to and that will
7655 * show what peers we advertised the bestpath to. If we are using addpath
7656 * though then we must display Advertised to on a path-by-path basis. */
7657 if (!bgp->addpath_tx_used[afi][safi])
718e3744 7658 {
adbac85e
DW
7659 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7660 {
7661 if (bgp_adj_out_lookup (peer, rn, 0))
b05a1c8b 7662 {
adbac85e 7663 if (json && !json_adv_to)
f1aa5d8a 7664 json_adv_to = json_object_new_object();
6410e93a 7665
adbac85e
DW
7666 route_vty_out_advertised_to(vty, peer, &first,
7667 " Advertised to non peer-group peers:\n ",
7668 json_adv_to);
b05a1c8b 7669 }
adbac85e 7670 }
036a4e7d 7671
adbac85e
DW
7672 if (json)
7673 {
7674 if (json_adv_to)
7675 {
7676 json_object_object_add(json, "advertisedTo", json_adv_to);
b05a1c8b 7677 }
adbac85e
DW
7678 }
7679 else
b05a1c8b 7680 {
adbac85e
DW
7681 if (first)
7682 vty_out (vty, " Not advertised to any peer");
7683 vty_out (vty, "%s", VTY_NEWLINE);
b05a1c8b
DS
7684 }
7685 }
718e3744 7686}
7687
7688/* Display specified route of BGP table. */
94f2b392 7689static int
fee0f4c6 7690bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
fd79ac91 7691 struct bgp_table *rib, const char *ip_str,
7692 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
7693 int prefix_check, enum bgp_path_type pathtype,
7694 u_char use_json)
718e3744 7695{
7696 int ret;
7697 int header;
7698 int display = 0;
7699 struct prefix match;
7700 struct bgp_node *rn;
7701 struct bgp_node *rm;
7702 struct bgp_info *ri;
718e3744 7703 struct bgp_table *table;
f1aa5d8a
DS
7704 json_object *json = NULL;
7705 json_object *json_paths = NULL;
718e3744 7706
718e3744 7707 /* Check IP address argument. */
7708 ret = str2prefix (ip_str, &match);
7709 if (! ret)
7710 {
7711 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
7712 return CMD_WARNING;
7713 }
7714
7715 match.family = afi2family (afi);
7716
b05a1c8b
DS
7717 if (use_json)
7718 {
7719 json = json_object_new_object();
7720 json_paths = json_object_new_array();
7721 }
b05a1c8b 7722
587ff0fd 7723 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
718e3744 7724 {
fee0f4c6 7725 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
718e3744 7726 {
7727 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
7728 continue;
7729
7730 if ((table = rn->info) != NULL)
7731 {
7732 header = 1;
7733
7734 if ((rm = bgp_node_match (table, &match)) != NULL)
7735 {
7736 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6c88b44d
CC
7737 {
7738 bgp_unlock_node (rm);
7739 continue;
7740 }
718e3744 7741
7742 for (ri = rm->info; ri; ri = ri->next)
7743 {
7744 if (header)
7745 {
7746 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
587ff0fd 7747 AFI_IP, safi, json);
718e3744 7748 header = 0;
7749 }
7750 display++;
4092b06c
DS
7751
7752 if (pathtype == BGP_PATH_ALL ||
7753 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7754 (pathtype == BGP_PATH_MULTIPATH &&
7755 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
587ff0fd 7756 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi, json_paths);
718e3744 7757 }
6c88b44d
CC
7758
7759 bgp_unlock_node (rm);
718e3744 7760 }
7761 }
7762 }
7763 }
7764 else
7765 {
7766 header = 1;
7767
fee0f4c6 7768 if ((rn = bgp_node_match (rib, &match)) != NULL)
718e3744 7769 {
7770 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
7771 {
7772 for (ri = rn->info; ri; ri = ri->next)
7773 {
7774 if (header)
7775 {
b05a1c8b 7776 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
718e3744 7777 header = 0;
7778 }
7779 display++;
4092b06c
DS
7780
7781 if (pathtype == BGP_PATH_ALL ||
7782 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7783 (pathtype == BGP_PATH_MULTIPATH &&
7784 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
b05a1c8b 7785 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
718e3744 7786 }
7787 }
6c88b44d
CC
7788
7789 bgp_unlock_node (rn);
718e3744 7790 }
7791 }
7792
e5eee9af 7793 if (use_json)
718e3744 7794 {
e5eee9af
DS
7795 if (display)
7796 json_object_object_add(json, "paths", json_paths);
7797
7798 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
f1aa5d8a 7799 json_object_free(json);
b05a1c8b
DS
7800 }
7801 else
7802 {
e5eee9af 7803 if (!display)
b05a1c8b
DS
7804 {
7805 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
7806 return CMD_WARNING;
7807 }
7808 }
7809
718e3744 7810 return CMD_SUCCESS;
7811}
7812
fee0f4c6 7813/* Display specified route of Main RIB */
94f2b392 7814static int
fd79ac91 7815bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
fee0f4c6 7816 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
7817 int prefix_check, enum bgp_path_type pathtype,
7818 u_char use_json)
fee0f4c6 7819{
7820 struct bgp *bgp;
7821
7822 /* BGP structure lookup. */
7823 if (view_name)
7824 {
7825 bgp = bgp_lookup_by_name (view_name);
7826 if (bgp == NULL)
7827 {
6aeb9e78 7828 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
fee0f4c6 7829 return CMD_WARNING;
7830 }
7831 }
7832 else
7833 {
7834 bgp = bgp_get_default ();
7835 if (bgp == NULL)
7836 {
7837 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7838 return CMD_WARNING;
7839 }
7840 }
7841
7842 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
b05a1c8b
DS
7843 afi, safi, prd, prefix_check, pathtype,
7844 use_json);
fee0f4c6 7845}
7846
718e3744 7847/* BGP route print out function. */
7848DEFUN (show_ip_bgp,
7849 show_ip_bgp_cmd,
b05a1c8b 7850 "show ip bgp {json}",
47fc97cc
DS
7851 SHOW_STR
7852 IP_STR
b05a1c8b
DS
7853 BGP_STR
7854 "JavaScript Object Notation\n")
47fc97cc 7855{
db7c8528 7856 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
718e3744 7857}
7858
7859DEFUN (show_ip_bgp_ipv4,
7860 show_ip_bgp_ipv4_cmd,
b05a1c8b 7861 "show ip bgp ipv4 (unicast|multicast) {json}",
718e3744 7862 SHOW_STR
7863 IP_STR
7864 BGP_STR
7865 "Address family\n"
7866 "Address Family modifier\n"
b05a1c8b
DS
7867 "Address Family modifier\n"
7868 "JavaScript Object Notation\n")
718e3744 7869{
db7c8528 7870 u_char uj = use_json(argc, argv);
b05a1c8b 7871
718e3744 7872 if (strncmp (argv[0], "m", 1) == 0)
5a646650 7873 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
db7c8528 7874 NULL, uj);
718e3744 7875
db7c8528 7876 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
718e3744 7877}
7878
95cbbd2a
ML
7879ALIAS (show_ip_bgp_ipv4,
7880 show_bgp_ipv4_safi_cmd,
b05a1c8b 7881 "show bgp ipv4 (unicast|multicast) {json}",
95cbbd2a
ML
7882 SHOW_STR
7883 BGP_STR
7884 "Address family\n"
7885 "Address Family modifier\n"
47fc97cc 7886 "Address Family modifier\n"
b05a1c8b 7887 "JavaScript Object Notation\n")
47fc97cc 7888
718e3744 7889DEFUN (show_ip_bgp_route,
7890 show_ip_bgp_route_cmd,
b05a1c8b 7891 "show ip bgp A.B.C.D {json}",
718e3744 7892 SHOW_STR
7893 IP_STR
7894 BGP_STR
b05a1c8b
DS
7895 "Network in the BGP routing table to display\n"
7896 "JavaScript Object Notation\n")
718e3744 7897{
db7c8528 7898 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
4092b06c
DS
7899}
7900
7901DEFUN (show_ip_bgp_route_pathtype,
7902 show_ip_bgp_route_pathtype_cmd,
b05a1c8b 7903 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
4092b06c
DS
7904 SHOW_STR
7905 IP_STR
7906 BGP_STR
7907 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7908 "Display only the bestpath\n"
b05a1c8b
DS
7909 "Display only multipaths\n"
7910 "JavaScript Object Notation\n")
4092b06c 7911{
db7c8528 7912 u_char uj = use_json(argc, argv);
b05a1c8b 7913
4092b06c 7914 if (strncmp (argv[1], "b", 1) == 0)
db7c8528 7915 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 7916 else
db7c8528 7917 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
7918}
7919
7920DEFUN (show_bgp_ipv4_safi_route_pathtype,
7921 show_bgp_ipv4_safi_route_pathtype_cmd,
b05a1c8b 7922 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath) {json}",
4092b06c
DS
7923 SHOW_STR
7924 BGP_STR
7925 "Address family\n"
7926 "Address Family modifier\n"
7927 "Address Family modifier\n"
7928 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7929 "Display only the bestpath\n"
b05a1c8b
DS
7930 "Display only multipaths\n"
7931 "JavaScript Object Notation\n")
4092b06c 7932{
db7c8528 7933 u_char uj = use_json(argc, argv);
b05a1c8b 7934
4092b06c
DS
7935 if (strncmp (argv[0], "m", 1) == 0)
7936 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 7937 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 7938 else
db7c8528 7939 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
7940 else
7941 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 7942 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 7943 else
db7c8528 7944 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
718e3744 7945}
7946
7947DEFUN (show_ip_bgp_ipv4_route,
7948 show_ip_bgp_ipv4_route_cmd,
b05a1c8b 7949 "show ip bgp ipv4 (unicast|multicast) A.B.C.D {json}",
718e3744 7950 SHOW_STR
7951 IP_STR
7952 BGP_STR
7953 "Address family\n"
7954 "Address Family modifier\n"
7955 "Address Family modifier\n"
b05a1c8b
DS
7956 "Network in the BGP routing table to display\n"
7957 "JavaScript Object Notation\n")
718e3744 7958{
db7c8528 7959 u_char uj = use_json(argc, argv);
b05a1c8b 7960
718e3744 7961 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 7962 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
718e3744 7963
db7c8528 7964 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
718e3744 7965}
7966
95cbbd2a
ML
7967ALIAS (show_ip_bgp_ipv4_route,
7968 show_bgp_ipv4_safi_route_cmd,
b05a1c8b 7969 "show bgp ipv4 (unicast|multicast) A.B.C.D {json}",
95cbbd2a
ML
7970 SHOW_STR
7971 BGP_STR
7972 "Address family\n"
7973 "Address Family modifier\n"
7974 "Address Family modifier\n"
b05a1c8b
DS
7975 "Network in the BGP routing table to display\n"
7976 "JavaScript Object Notation\n")
95cbbd2a 7977
718e3744 7978DEFUN (show_ip_bgp_vpnv4_all_route,
7979 show_ip_bgp_vpnv4_all_route_cmd,
b05a1c8b 7980 "show ip bgp vpnv4 all A.B.C.D {json}",
718e3744 7981 SHOW_STR
7982 IP_STR
7983 BGP_STR
7984 "Display VPNv4 NLRI specific information\n"
7985 "Display information about all VPNv4 NLRIs\n"
b05a1c8b
DS
7986 "Network in the BGP routing table to display\n"
7987 "JavaScript Object Notation\n")
718e3744 7988{
db7c8528 7989 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 7990}
7991
4092b06c 7992
718e3744 7993DEFUN (show_ip_bgp_vpnv4_rd_route,
7994 show_ip_bgp_vpnv4_rd_route_cmd,
b05a1c8b 7995 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
718e3744 7996 SHOW_STR
7997 IP_STR
7998 BGP_STR
7999 "Display VPNv4 NLRI specific information\n"
8000 "Display information for a route distinguisher\n"
8001 "VPN Route Distinguisher\n"
b05a1c8b
DS
8002 "Network in the BGP routing table to display\n"
8003 "JavaScript Object Notation\n")
718e3744 8004{
8005 int ret;
8006 struct prefix_rd prd;
db7c8528 8007 u_char uj= use_json(argc, argv);
718e3744 8008
8009 ret = str2prefix_rd (argv[0], &prd);
8010 if (! ret)
8011 {
8012 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8013 return CMD_WARNING;
8014 }
db7c8528 8015 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, uj);
718e3744 8016}
8017
8018DEFUN (show_ip_bgp_prefix,
8019 show_ip_bgp_prefix_cmd,
b05a1c8b 8020 "show ip bgp A.B.C.D/M {json}",
718e3744 8021 SHOW_STR
8022 IP_STR
8023 BGP_STR
b05a1c8b
DS
8024 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8025 "JavaScript Object Notation\n")
718e3744 8026{
db7c8528 8027 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
4092b06c
DS
8028}
8029
8030DEFUN (show_ip_bgp_prefix_pathtype,
8031 show_ip_bgp_prefix_pathtype_cmd,
b05a1c8b 8032 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8033 SHOW_STR
8034 IP_STR
8035 BGP_STR
8036 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8037 "Display only the bestpath\n"
b05a1c8b
DS
8038 "Display only multipaths\n"
8039 "JavaScript Object Notation\n")
4092b06c 8040{
db7c8528 8041 u_char uj = use_json(argc, argv);
4092b06c 8042 if (strncmp (argv[1], "b", 1) == 0)
db7c8528 8043 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8044 else
db7c8528 8045 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
718e3744 8046}
8047
8048DEFUN (show_ip_bgp_ipv4_prefix,
8049 show_ip_bgp_ipv4_prefix_cmd,
b05a1c8b 8050 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
718e3744 8051 SHOW_STR
8052 IP_STR
8053 BGP_STR
8054 "Address family\n"
8055 "Address Family modifier\n"
8056 "Address Family modifier\n"
b05a1c8b
DS
8057 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8058 "JavaScript Object Notation\n")
718e3744 8059{
db7c8528 8060 u_char uj = use_json(argc, argv);
b05a1c8b 8061
718e3744 8062 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 8063 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
718e3744 8064
db7c8528 8065 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
718e3744 8066}
8067
95cbbd2a
ML
8068ALIAS (show_ip_bgp_ipv4_prefix,
8069 show_bgp_ipv4_safi_prefix_cmd,
b05a1c8b 8070 "show bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
95cbbd2a
ML
8071 SHOW_STR
8072 BGP_STR
8073 "Address family\n"
8074 "Address Family modifier\n"
8075 "Address Family modifier\n"
b05a1c8b
DS
8076 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8077 "JavaScript Object Notation\n")
95cbbd2a 8078
4092b06c
DS
8079DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
8080 show_ip_bgp_ipv4_prefix_pathtype_cmd,
b05a1c8b 8081 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8082 SHOW_STR
8083 IP_STR
8084 BGP_STR
8085 "Address family\n"
8086 "Address Family modifier\n"
8087 "Address Family modifier\n"
8088 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8089 "Display only the bestpath\n"
b05a1c8b
DS
8090 "Display only multipaths\n"
8091 "JavaScript Object Notation\n")
4092b06c 8092{
db7c8528 8093 u_char uj = use_json(argc, argv);
b05a1c8b 8094
4092b06c
DS
8095 if (strncmp (argv[0], "m", 1) == 0)
8096 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 8097 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8098 else
db7c8528 8099 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8100 else
8101 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 8102 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8103 else
db7c8528 8104 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8105}
8106
8107ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
8108 show_bgp_ipv4_safi_prefix_pathtype_cmd,
b05a1c8b 8109 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8110 SHOW_STR
8111 BGP_STR
8112 "Address family\n"
8113 "Address Family modifier\n"
8114 "Address Family modifier\n"
8115 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8116 "Display only the bestpath\n"
b05a1c8b
DS
8117 "Display only multipaths\n"
8118 "JavaScript Object Notation\n")
4092b06c 8119
718e3744 8120DEFUN (show_ip_bgp_vpnv4_all_prefix,
8121 show_ip_bgp_vpnv4_all_prefix_cmd,
b05a1c8b 8122 "show ip bgp vpnv4 all A.B.C.D/M {json}",
718e3744 8123 SHOW_STR
8124 IP_STR
8125 BGP_STR
8126 "Display VPNv4 NLRI specific information\n"
8127 "Display information about all VPNv4 NLRIs\n"
b05a1c8b
DS
8128 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8129 "JavaScript Object Notation\n")
718e3744 8130{
db7c8528 8131 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8132}
8133
8134DEFUN (show_ip_bgp_vpnv4_rd_prefix,
8135 show_ip_bgp_vpnv4_rd_prefix_cmd,
b05a1c8b 8136 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
718e3744 8137 SHOW_STR
8138 IP_STR
8139 BGP_STR
8140 "Display VPNv4 NLRI specific information\n"
8141 "Display information for a route distinguisher\n"
8142 "VPN Route Distinguisher\n"
b05a1c8b
DS
8143 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8144 "JavaScript Object Notation\n")
718e3744 8145{
8146 int ret;
8147 struct prefix_rd prd;
8148
8149 ret = str2prefix_rd (argv[0], &prd);
8150 if (! ret)
8151 {
8152 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8153 return CMD_WARNING;
8154 }
db7c8528 8155 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8156}
8157
8158DEFUN (show_ip_bgp_view,
8386ac43 8159 show_ip_bgp_instance_cmd,
8160 "show ip bgp " BGP_INSTANCE_CMD " {json}",
718e3744 8161 SHOW_STR
8162 IP_STR
8163 BGP_STR
8386ac43 8164 BGP_INSTANCE_HELP_STR
b05a1c8b 8165 "JavaScript Object Notation\n")
718e3744 8166{
bb46e94f 8167 struct bgp *bgp;
8168
8169 /* BGP structure lookup. */
6aeb9e78 8170 bgp = bgp_lookup_by_name (argv[1]);
bb46e94f 8171 if (bgp == NULL)
8172 {
6aeb9e78 8173 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
bb46e94f 8174 return CMD_WARNING;
8175 }
8176
db7c8528 8177 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
718e3744 8178}
8179
f186de26 8180DEFUN (show_ip_bgp_instance_all,
8181 show_ip_bgp_instance_all_cmd,
8182 "show ip bgp " BGP_INSTANCE_ALL_CMD " {json}",
8183 SHOW_STR
8184 IP_STR
8185 BGP_STR
8186 BGP_INSTANCE_ALL_HELP_STR
8187 "JavaScript Object Notation\n")
8188{
8189 u_char uj = use_json(argc, argv);
8190
8191 bgp_show_all_instances_routes_vty (vty, AFI_IP, SAFI_UNICAST, uj);
8192 return CMD_SUCCESS;
8193}
8194
8386ac43 8195DEFUN (show_ip_bgp_instance_route,
8196 show_ip_bgp_instance_route_cmd,
8197 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D {json}",
718e3744 8198 SHOW_STR
8199 IP_STR
8200 BGP_STR
8386ac43 8201 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8202 "Network in the BGP routing table to display\n"
8203 "JavaScript Object Notation\n")
718e3744 8204{
6aeb9e78 8205 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8206}
8207
8386ac43 8208DEFUN (show_ip_bgp_instance_route_pathtype,
8209 show_ip_bgp_instance_route_pathtype_cmd,
8210 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D (bestpath|multipath) {json}",
50ef26d4 8211 SHOW_STR
8212 IP_STR
8213 BGP_STR
8386ac43 8214 BGP_INSTANCE_HELP_STR
50ef26d4 8215 "Network in the BGP routing table to display\n"
8216 "Display only the bestpath\n"
8217 "Display only multipaths\n"
8218 "JavaScript Object Notation\n")
8219{
8220 u_char uj = use_json(argc, argv);
8221
8222 if (strncmp (argv[3], "b", 1) == 0)
8223 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8224 else
8225 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8226}
8227
8386ac43 8228DEFUN (show_ip_bgp_instance_prefix,
8229 show_ip_bgp_instance_prefix_cmd,
8230 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M {json}",
718e3744 8231 SHOW_STR
8232 IP_STR
8233 BGP_STR
8386ac43 8234 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8235 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8236 "JavaScript Object Notation\n")
718e3744 8237{
6aeb9e78 8238 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8239}
8240
8386ac43 8241DEFUN (show_ip_bgp_instance_prefix_pathtype,
8242 show_ip_bgp_instance_prefix_pathtype_cmd,
8243 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M (bestpath|multipath) {json}",
50ef26d4 8244 SHOW_STR
8245 IP_STR
8246 BGP_STR
8386ac43 8247 BGP_INSTANCE_HELP_STR
50ef26d4 8248 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8249 "Display only the bestpath\n"
8250 "Display only multipaths\n"
8251 "JavaScript Object Notation\n")
8252{
8253 u_char uj = use_json(argc, argv);
8254 if (strncmp (argv[3], "b", 1) == 0)
8255 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8256 else
8257 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8258}
8259
718e3744 8260#ifdef HAVE_IPV6
8261DEFUN (show_bgp,
8262 show_bgp_cmd,
b05a1c8b 8263 "show bgp {json}",
718e3744 8264 SHOW_STR
b05a1c8b
DS
8265 BGP_STR
8266 "JavaScript Object Notation\n")
718e3744 8267{
5a646650 8268 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
db7c8528 8269 NULL, use_json(argc, argv));
718e3744 8270}
8271
8272ALIAS (show_bgp,
8273 show_bgp_ipv6_cmd,
b05a1c8b 8274 "show bgp ipv6 {json}",
718e3744 8275 SHOW_STR
8276 BGP_STR
b05a1c8b
DS
8277 "Address family\n"
8278 "JavaScript Object Notation\n")
718e3744 8279
95cbbd2a
ML
8280DEFUN (show_bgp_ipv6_safi,
8281 show_bgp_ipv6_safi_cmd,
b05a1c8b 8282 "show bgp ipv6 (unicast|multicast) {json}",
95cbbd2a
ML
8283 SHOW_STR
8284 BGP_STR
8285 "Address family\n"
8286 "Address Family modifier\n"
47fc97cc 8287 "Address Family modifier\n"
b05a1c8b 8288 "JavaScript Object Notation\n")
47fc97cc 8289{
db7c8528 8290 u_char uj = use_json(argc, argv);
47fc97cc
DS
8291 if (strncmp (argv[0], "m", 1) == 0)
8292 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
db7c8528 8293 NULL, uj);
47fc97cc 8294
db7c8528 8295 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
95cbbd2a
ML
8296}
8297
47e9b292
DW
8298static void
8299bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty)
8300{
8301 vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our"
8302 " next release%sPlese use 'show bgp ipv6' instead%s%s",
8303 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8304}
8305
718e3744 8306/* old command */
8307DEFUN (show_ipv6_bgp,
8308 show_ipv6_bgp_cmd,
b05a1c8b 8309 "show ipv6 bgp {json}",
718e3744 8310 SHOW_STR
8311 IP_STR
b05a1c8b
DS
8312 BGP_STR
8313 "JavaScript Object Notation\n")
718e3744 8314{
47e9b292 8315 bgp_show_ipv6_bgp_deprecate_warning(vty);
5a646650 8316 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
db7c8528 8317 NULL, use_json(argc, argv));
718e3744 8318}
8319
8320DEFUN (show_bgp_route,
8321 show_bgp_route_cmd,
b05a1c8b 8322 "show bgp X:X::X:X {json}",
718e3744 8323 SHOW_STR
8324 BGP_STR
b05a1c8b
DS
8325 "Network in the BGP routing table to display\n"
8326 "JavaScript Object Notation\n")
718e3744 8327{
db7c8528 8328 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8329}
8330
8331ALIAS (show_bgp_route,
8332 show_bgp_ipv6_route_cmd,
b05a1c8b 8333 "show bgp ipv6 X:X::X:X {json}",
718e3744 8334 SHOW_STR
8335 BGP_STR
8336 "Address family\n"
b05a1c8b
DS
8337 "Network in the BGP routing table to display\n"
8338 "JavaScript Object Notation\n")
718e3744 8339
95cbbd2a
ML
8340DEFUN (show_bgp_ipv6_safi_route,
8341 show_bgp_ipv6_safi_route_cmd,
b05a1c8b 8342 "show bgp ipv6 (unicast|multicast) X:X::X:X {json}",
95cbbd2a
ML
8343 SHOW_STR
8344 BGP_STR
8345 "Address family\n"
8346 "Address Family modifier\n"
8347 "Address Family modifier\n"
b05a1c8b
DS
8348 "Network in the BGP routing table to display\n"
8349 "JavaScript Object Notation\n")
95cbbd2a 8350{
db7c8528 8351 u_char uj = use_json(argc, argv);
95cbbd2a 8352 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 8353 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
95cbbd2a 8354
db7c8528 8355 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
4092b06c
DS
8356}
8357
8358DEFUN (show_bgp_route_pathtype,
8359 show_bgp_route_pathtype_cmd,
b05a1c8b 8360 "show bgp X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8361 SHOW_STR
8362 BGP_STR
8363 "Network in the BGP routing table to display\n"
8364 "Display only the bestpath\n"
b05a1c8b
DS
8365 "Display only multipaths\n"
8366 "JavaScript Object Notation\n")
4092b06c 8367{
db7c8528 8368 u_char uj = use_json(argc, argv);
4092b06c 8369 if (strncmp (argv[1], "b", 1) == 0)
db7c8528 8370 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 8371 else
db7c8528 8372 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8373}
8374
8375ALIAS (show_bgp_route_pathtype,
8376 show_bgp_ipv6_route_pathtype_cmd,
b05a1c8b 8377 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8378 SHOW_STR
8379 BGP_STR
8380 "Address family\n"
8381 "Network in the BGP routing table to display\n"
8382 "Display only the bestpath\n"
b05a1c8b
DS
8383 "Display only multipaths\n"
8384 "JavaScript Object Notation\n")
4092b06c
DS
8385
8386DEFUN (show_bgp_ipv6_safi_route_pathtype,
8387 show_bgp_ipv6_safi_route_pathtype_cmd,
b05a1c8b 8388 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8389 SHOW_STR
8390 BGP_STR
8391 "Address family\n"
8392 "Address Family modifier\n"
8393 "Address Family modifier\n"
8394 "Network in the BGP routing table to display\n"
8395 "Display only the bestpath\n"
b05a1c8b
DS
8396 "Display only multipaths\n"
8397 "JavaScript Object Notation\n")
4092b06c 8398{
db7c8528 8399 u_char uj = use_json(argc, argv);
4092b06c
DS
8400 if (strncmp (argv[0], "m", 1) == 0)
8401 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 8402 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 8403 else
db7c8528 8404 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8405 else
8406 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 8407 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 8408 else
db7c8528 8409 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
95cbbd2a
ML
8410}
8411
718e3744 8412/* old command */
8413DEFUN (show_ipv6_bgp_route,
8414 show_ipv6_bgp_route_cmd,
b05a1c8b 8415 "show ipv6 bgp X:X::X:X {json}",
718e3744 8416 SHOW_STR
8417 IP_STR
8418 BGP_STR
b05a1c8b
DS
8419 "Network in the BGP routing table to display\n"
8420 "JavaScript Object Notation\n")
718e3744 8421{
47e9b292 8422 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 8423 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8424}
8425
8426DEFUN (show_bgp_prefix,
8427 show_bgp_prefix_cmd,
b05a1c8b 8428 "show bgp X:X::X:X/M {json}",
718e3744 8429 SHOW_STR
8430 BGP_STR
b05a1c8b
DS
8431 "IPv6 prefix <network>/<length>\n"
8432 "JavaScript Object Notation\n")
718e3744 8433{
db7c8528 8434 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8435}
8436
8437ALIAS (show_bgp_prefix,
8438 show_bgp_ipv6_prefix_cmd,
b05a1c8b 8439 "show bgp ipv6 X:X::X:X/M {json}",
718e3744 8440 SHOW_STR
8441 BGP_STR
8442 "Address family\n"
b05a1c8b
DS
8443 "IPv6 prefix <network>/<length>\n"
8444 "JavaScript Object Notation\n")
718e3744 8445
95cbbd2a
ML
8446DEFUN (show_bgp_ipv6_safi_prefix,
8447 show_bgp_ipv6_safi_prefix_cmd,
b05a1c8b 8448 "show bgp ipv6 (unicast|multicast) X:X::X:X/M {json}",
95cbbd2a
ML
8449 SHOW_STR
8450 BGP_STR
8451 "Address family\n"
8452 "Address Family modifier\n"
8453 "Address Family modifier\n"
b05a1c8b
DS
8454 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8455 "JavaScript Object Notation\n")
95cbbd2a 8456{
db7c8528 8457 u_char uj = use_json(argc, argv);
95cbbd2a 8458 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 8459 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
95cbbd2a 8460
db7c8528 8461 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
4092b06c
DS
8462}
8463
8464DEFUN (show_bgp_prefix_pathtype,
8465 show_bgp_prefix_pathtype_cmd,
b05a1c8b 8466 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8467 SHOW_STR
8468 BGP_STR
8469 "IPv6 prefix <network>/<length>\n"
8470 "Display only the bestpath\n"
b05a1c8b
DS
8471 "Display only multipaths\n"
8472 "JavaScript Object Notation\n")
4092b06c 8473{
db7c8528 8474 u_char uj = use_json(argc, argv);
4092b06c 8475 if (strncmp (argv[1], "b", 1) == 0)
db7c8528 8476 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8477 else
db7c8528 8478 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8479}
8480
8481ALIAS (show_bgp_prefix_pathtype,
8482 show_bgp_ipv6_prefix_pathtype_cmd,
b05a1c8b 8483 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8484 SHOW_STR
8485 BGP_STR
8486 "Address family\n"
8487 "IPv6 prefix <network>/<length>\n"
8488 "Display only the bestpath\n"
b05a1c8b
DS
8489 "Display only multipaths\n"
8490 "JavaScript Object Notation\n")
4092b06c
DS
8491
8492DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8493 show_bgp_ipv6_safi_prefix_pathtype_cmd,
b05a1c8b 8494 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8495 SHOW_STR
8496 BGP_STR
8497 "Address family\n"
8498 "Address Family modifier\n"
8499 "Address Family modifier\n"
8500 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8501 "Display only the bestpath\n"
b05a1c8b
DS
8502 "Display only multipaths\n"
8503 "JavaScript Object Notation\n")
4092b06c 8504{
db7c8528 8505 u_char uj = use_json(argc, argv);
4092b06c
DS
8506 if (strncmp (argv[0], "m", 1) == 0)
8507 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 8508 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8509 else
db7c8528 8510 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8511 else
8512 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 8513 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8514 else
db7c8528 8515 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
95cbbd2a
ML
8516}
8517
718e3744 8518/* old command */
8519DEFUN (show_ipv6_bgp_prefix,
8520 show_ipv6_bgp_prefix_cmd,
b05a1c8b 8521 "show ipv6 bgp X:X::X:X/M {json}",
718e3744 8522 SHOW_STR
8523 IP_STR
8524 BGP_STR
b05a1c8b
DS
8525 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8526 "JavaScript Object Notation\n")
718e3744 8527{
47e9b292 8528 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 8529 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8530}
8531
bb46e94f 8532DEFUN (show_bgp_view,
8386ac43 8533 show_bgp_instance_cmd,
8534 "show bgp " BGP_INSTANCE_CMD " {json}",
bb46e94f 8535 SHOW_STR
8536 BGP_STR
8386ac43 8537 BGP_INSTANCE_HELP_STR
b05a1c8b 8538 "JavaScript Object Notation\n")
bb46e94f 8539{
8540 struct bgp *bgp;
8541
8542 /* BGP structure lookup. */
6aeb9e78 8543 bgp = bgp_lookup_by_name (argv[1]);
bb46e94f 8544 if (bgp == NULL)
db7c8528 8545 {
6aeb9e78 8546 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
db7c8528
DS
8547 return CMD_WARNING;
8548 }
8549
8550 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
bb46e94f 8551}
8552
f186de26 8553DEFUN (show_bgp_instance_all,
8554 show_bgp_instance_all_cmd,
8555 "show bgp " BGP_INSTANCE_ALL_CMD " {json}",
8556 SHOW_STR
8557 BGP_STR
8558 BGP_INSTANCE_ALL_HELP_STR
8559 "JavaScript Object Notation\n")
8560{
8561 u_char uj = use_json(argc, argv);
8562
8563 bgp_show_all_instances_routes_vty (vty, AFI_IP6, SAFI_UNICAST, uj);
8564 return CMD_SUCCESS;
8565}
8566
bb46e94f 8567ALIAS (show_bgp_view,
8386ac43 8568 show_bgp_instance_ipv6_cmd,
8569 "show bgp " BGP_INSTANCE_CMD " ipv6 {json}",
bb46e94f 8570 SHOW_STR
8571 BGP_STR
8386ac43 8572 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8573 "Address family\n"
8574 "JavaScript Object Notation\n")
bb46e94f 8575
8386ac43 8576DEFUN (show_bgp_instance_route,
8577 show_bgp_instance_route_cmd,
8578 "show bgp " BGP_INSTANCE_CMD " X:X::X:X {json}",
bb46e94f 8579 SHOW_STR
8580 BGP_STR
8386ac43 8581 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8582 "Network in the BGP routing table to display\n"
8583 "JavaScript Object Notation\n")
bb46e94f 8584{
6aeb9e78 8585 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
bb46e94f 8586}
8587
8386ac43 8588ALIAS (show_bgp_instance_route,
8589 show_bgp_instance_ipv6_route_cmd,
8590 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X {json}",
bb46e94f 8591 SHOW_STR
8592 BGP_STR
8386ac43 8593 BGP_INSTANCE_HELP_STR
bb46e94f 8594 "Address family\n"
b05a1c8b
DS
8595 "Network in the BGP routing table to display\n"
8596 "JavaScript Object Notation\n")
bb46e94f 8597
8386ac43 8598DEFUN (show_bgp_instance_route_pathtype,
8599 show_bgp_instance_route_pathtype_cmd,
8600 "show bgp " BGP_INSTANCE_CMD " X:X::X:X (bestpath|multipath) {json}",
50ef26d4 8601 SHOW_STR
8602 BGP_STR
8386ac43 8603 BGP_INSTANCE_HELP_STR
50ef26d4 8604 "Network in the BGP routing table to display\n"
8605 "Display only the bestpath\n"
8606 "Display only multipaths\n"
8607 "JavaScript Object Notation\n")
8608{
8609 u_char uj = use_json(argc, argv);
8610 if (strncmp (argv[3], "b", 1) == 0)
8611 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8612 else
8613 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8614}
8615
8386ac43 8616ALIAS (show_bgp_instance_route_pathtype,
8617 show_bgp_instance_ipv6_route_pathtype_cmd,
8618 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X (bestpath|multipath) {json}",
50ef26d4 8619 SHOW_STR
8620 BGP_STR
8386ac43 8621 BGP_INSTANCE_HELP_STR
50ef26d4 8622 "Address family\n"
8623 "Network in the BGP routing table to display\n"
8624 "Display only the bestpath\n"
8625 "Display only multipaths\n"
8626 "JavaScript Object Notation\n")
8627
8386ac43 8628DEFUN (show_bgp_instance_prefix,
8629 show_bgp_instance_prefix_cmd,
8630 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M {json}",
bb46e94f 8631 SHOW_STR
8632 BGP_STR
8386ac43 8633 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8634 "IPv6 prefix <network>/<length>\n"
8635 "JavaScript Object Notation\n")
bb46e94f 8636{
6aeb9e78 8637 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
bb46e94f 8638}
8639
8386ac43 8640ALIAS (show_bgp_instance_prefix,
8641 show_bgp_instance_ipv6_prefix_cmd,
8642 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M {json}",
bb46e94f 8643 SHOW_STR
8644 BGP_STR
8386ac43 8645 BGP_INSTANCE_HELP_STR
bb46e94f 8646 "Address family\n"
b05a1c8b
DS
8647 "IPv6 prefix <network>/<length>\n"
8648 "JavaScript Object Notation\n")
bb46e94f 8649
8386ac43 8650DEFUN (show_bgp_instance_prefix_pathtype,
8651 show_bgp_instance_prefix_pathtype_cmd,
8652 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M (bestpath|multipath) {json}",
50ef26d4 8653 SHOW_STR
8654 BGP_STR
8386ac43 8655 BGP_INSTANCE_HELP_STR
50ef26d4 8656 "IPv6 prefix <network>/<length>\n"
8657 "Display only the bestpath\n"
8658 "Display only multipaths\n"
8659 "JavaScript Object Notation\n")
8660{
8661 u_char uj = use_json(argc, argv);
8662 if (strncmp (argv[3], "b", 1) == 0)
8663 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8664 else
8665 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8666}
8667
8386ac43 8668ALIAS (show_bgp_instance_prefix_pathtype,
8669 show_bgp_instance_ipv6_prefix_pathtype_cmd,
8670 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M (bestpath|multipath) {json}",
50ef26d4 8671 SHOW_STR
8672 BGP_STR
8386ac43 8673 BGP_INSTANCE_HELP_STR
50ef26d4 8674 "Address family\n"
8675 "IPv6 prefix <network>/<length>\n"
8676 "Display only the bestpath\n"
8677 "Display only multipaths\n"
8678 "JavaScript Object Notation\n")
8679
8386ac43 8680DEFUN (show_bgp_instance_prefix_list,
8681 show_bgp_instance_prefix_list_cmd,
8682 "show bgp " BGP_INSTANCE_CMD " prefix-list WORD",
50ef26d4 8683 SHOW_STR
8684 BGP_STR
8386ac43 8685 BGP_INSTANCE_HELP_STR
50ef26d4 8686 "Display routes conforming to the prefix-list\n"
8687 "IPv6 prefix-list name\n")
8688{
8689 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8690 bgp_show_type_prefix_list);
8691}
8692
8386ac43 8693ALIAS (show_bgp_instance_prefix_list,
8694 show_bgp_instance_ipv6_prefix_list_cmd,
8695 "show bgp " BGP_INSTANCE_CMD " ipv6 prefix-list WORD",
50ef26d4 8696 SHOW_STR
8697 BGP_STR
8386ac43 8698 BGP_INSTANCE_HELP_STR
50ef26d4 8699 "Address family\n"
8700 "Display routes conforming to the prefix-list\n"
8701 "IPv6 prefix-list name\n")
8702
8386ac43 8703DEFUN (show_bgp_instance_filter_list,
8704 show_bgp_instance_filter_list_cmd,
8705 "show bgp " BGP_INSTANCE_CMD " filter-list WORD",
50ef26d4 8706 SHOW_STR
8707 BGP_STR
8386ac43 8708 BGP_INSTANCE_HELP_STR
50ef26d4 8709 "Display routes conforming to the filter-list\n"
8710 "Regular expression access list name\n")
8711{
8712 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8713 bgp_show_type_filter_list);
8714}
8715
8386ac43 8716ALIAS (show_bgp_instance_filter_list,
8717 show_bgp_instance_ipv6_filter_list_cmd,
8718 "show bgp " BGP_INSTANCE_CMD " ipv6 filter-list WORD",
50ef26d4 8719 SHOW_STR
8720 BGP_STR
8386ac43 8721 BGP_INSTANCE_HELP_STR
50ef26d4 8722 "Address family\n"
8723 "Display routes conforming to the filter-list\n"
8724 "Regular expression access list name\n")
8725
8386ac43 8726DEFUN (show_bgp_instance_route_map,
8727 show_bgp_instance_route_map_cmd,
8728 "show bgp " BGP_INSTANCE_CMD " route-map WORD",
50ef26d4 8729 SHOW_STR
8730 BGP_STR
8386ac43 8731 BGP_INSTANCE_HELP_STR
50ef26d4 8732 "Display routes matching the route-map\n"
8733 "A route-map to match on\n")
8734{
8735 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8736 bgp_show_type_route_map);
8737}
8738
8386ac43 8739ALIAS (show_bgp_instance_route_map,
8740 show_bgp_instance_ipv6_route_map_cmd,
8741 "show bgp " BGP_INSTANCE_CMD " ipv6 route-map WORD",
50ef26d4 8742 SHOW_STR
8743 BGP_STR
8386ac43 8744 BGP_INSTANCE_HELP_STR
50ef26d4 8745 "Address family\n"
8746 "Display routes matching the route-map\n"
8747 "A route-map to match on\n")
8748
8386ac43 8749DEFUN (show_bgp_instance_community_list,
8750 show_bgp_instance_community_list_cmd,
8751 "show bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
50ef26d4 8752 SHOW_STR
8753 BGP_STR
8386ac43 8754 BGP_INSTANCE_HELP_STR
50ef26d4 8755 "Display routes matching the community-list\n"
8756 "community-list number\n"
8757 "community-list name\n")
8758{
8759 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP6, SAFI_UNICAST);
8760}
8761
8386ac43 8762ALIAS (show_bgp_instance_community_list,
8763 show_bgp_instance_ipv6_community_list_cmd,
8764 "show bgp " BGP_INSTANCE_CMD " ipv6 community-list (<1-500>|WORD)",
50ef26d4 8765 SHOW_STR
8766 BGP_STR
8386ac43 8767 BGP_INSTANCE_HELP_STR
50ef26d4 8768 "Address family\n"
8769 "Display routes matching the community-list\n"
8770 "community-list number\n"
8771 "community-list name\n")
8772
8386ac43 8773DEFUN (show_bgp_instance_prefix_longer,
8774 show_bgp_instance_prefix_longer_cmd,
8775 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M longer-prefixes",
50ef26d4 8776 SHOW_STR
8777 BGP_STR
8386ac43 8778 BGP_INSTANCE_HELP_STR
50ef26d4 8779 "IPv6 prefix <network>/<length>\n"
8780 "Display route and more specific routes\n")
8781{
8782 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8783 bgp_show_type_prefix_longer);
8784}
8785
8386ac43 8786ALIAS (show_bgp_instance_prefix_longer,
8787 show_bgp_instance_ipv6_prefix_longer_cmd,
8788 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M longer-prefixes",
50ef26d4 8789 SHOW_STR
8790 BGP_STR
8386ac43 8791 BGP_INSTANCE_HELP_STR
50ef26d4 8792 "Address family\n"
8793 "IPv6 prefix <network>/<length>\n"
8794 "Display route and more specific routes\n")
8795
718e3744 8796/* old command */
8797DEFUN (show_ipv6_mbgp,
8798 show_ipv6_mbgp_cmd,
b05a1c8b 8799 "show ipv6 mbgp {json}",
718e3744 8800 SHOW_STR
8801 IP_STR
b05a1c8b
DS
8802 MBGP_STR
8803 "JavaScript Object Notation\n")
718e3744 8804{
47e9b292 8805 bgp_show_ipv6_bgp_deprecate_warning(vty);
5a646650 8806 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
db7c8528 8807 NULL, use_json(argc, argv));
718e3744 8808}
8809
8810/* old command */
8811DEFUN (show_ipv6_mbgp_route,
8812 show_ipv6_mbgp_route_cmd,
b05a1c8b 8813 "show ipv6 mbgp X:X::X:X {json}",
718e3744 8814 SHOW_STR
8815 IP_STR
8816 MBGP_STR
b05a1c8b
DS
8817 "Network in the MBGP routing table to display\n"
8818 "JavaScript Object Notation\n")
718e3744 8819{
47e9b292 8820 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 8821 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8822}
8823
8824/* old command */
8825DEFUN (show_ipv6_mbgp_prefix,
8826 show_ipv6_mbgp_prefix_cmd,
b05a1c8b 8827 "show ipv6 mbgp X:X::X:X/M {json}",
718e3744 8828 SHOW_STR
8829 IP_STR
8830 MBGP_STR
b05a1c8b
DS
8831 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8832 "JavaScript Object Notation\n")
718e3744 8833{
47e9b292 8834 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 8835 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8836}
8837#endif
6b0655a2 8838
718e3744 8839
94f2b392 8840static int
fd79ac91 8841bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
718e3744 8842 safi_t safi, enum bgp_show_type type)
8843{
8844 int i;
8845 struct buffer *b;
8846 char *regstr;
8847 int first;
8848 regex_t *regex;
5a646650 8849 int rc;
718e3744 8850
8851 first = 0;
8852 b = buffer_new (1024);
8853 for (i = 0; i < argc; i++)
8854 {
8855 if (first)
8856 buffer_putc (b, ' ');
8857 else
8858 {
8859 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8860 continue;
8861 first = 1;
8862 }
8863
8864 buffer_putstr (b, argv[i]);
8865 }
8866 buffer_putc (b, '\0');
8867
8868 regstr = buffer_getstr (b);
8869 buffer_free (b);
8870
8871 regex = bgp_regcomp (regstr);
3b8b1855 8872 XFREE(MTYPE_TMP, regstr);
718e3744 8873 if (! regex)
8874 {
8875 vty_out (vty, "Can't compile regexp %s%s", argv[0],
8876 VTY_NEWLINE);
8877 return CMD_WARNING;
8878 }
8879
b05a1c8b 8880 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
5a646650 8881 bgp_regex_free (regex);
8882 return rc;
718e3744 8883}
8884
8885DEFUN (show_ip_bgp_regexp,
8886 show_ip_bgp_regexp_cmd,
8887 "show ip bgp regexp .LINE",
8888 SHOW_STR
8889 IP_STR
8890 BGP_STR
8891 "Display routes matching the AS path regular expression\n"
8892 "A regular-expression to match the BGP AS paths\n")
8893{
8894 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8895 bgp_show_type_regexp);
8896}
8897
8898DEFUN (show_ip_bgp_flap_regexp,
8899 show_ip_bgp_flap_regexp_cmd,
8900 "show ip bgp flap-statistics regexp .LINE",
8901 SHOW_STR
8902 IP_STR
8903 BGP_STR
8904 "Display flap statistics of routes\n"
8905 "Display routes matching the AS path regular expression\n"
8906 "A regular-expression to match the BGP AS paths\n")
8907{
8908 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8909 bgp_show_type_flap_regexp);
8910}
8911
81304aaf
B
8912ALIAS (show_ip_bgp_flap_regexp,
8913 show_ip_bgp_damp_flap_regexp_cmd,
8914 "show ip bgp dampening flap-statistics regexp .LINE",
8915 SHOW_STR
8916 IP_STR
8917 BGP_STR
8918 "Display detailed information about dampening\n"
8919 "Display flap statistics of routes\n"
8920 "Display routes matching the AS path regular expression\n"
8921 "A regular-expression to match the BGP AS paths\n")
8922
718e3744 8923DEFUN (show_ip_bgp_ipv4_regexp,
8924 show_ip_bgp_ipv4_regexp_cmd,
8925 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
8926 SHOW_STR
8927 IP_STR
8928 BGP_STR
8929 "Address family\n"
8930 "Address Family modifier\n"
8931 "Address Family modifier\n"
8932 "Display routes matching the AS path regular expression\n"
8933 "A regular-expression to match the BGP AS paths\n")
8934{
8935 if (strncmp (argv[0], "m", 1) == 0)
8936 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
8937 bgp_show_type_regexp);
8938
8939 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8940 bgp_show_type_regexp);
8941}
8942
8943#ifdef HAVE_IPV6
8944DEFUN (show_bgp_regexp,
8945 show_bgp_regexp_cmd,
8946 "show bgp regexp .LINE",
8947 SHOW_STR
8948 BGP_STR
8949 "Display routes matching the AS path regular expression\n"
8950 "A regular-expression to match the BGP AS paths\n")
8951{
8952 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8953 bgp_show_type_regexp);
8954}
8955
8956ALIAS (show_bgp_regexp,
8957 show_bgp_ipv6_regexp_cmd,
8958 "show bgp ipv6 regexp .LINE",
8959 SHOW_STR
8960 BGP_STR
8961 "Address family\n"
8962 "Display routes matching the AS path regular expression\n"
8963 "A regular-expression to match the BGP AS paths\n")
8964
8965/* old command */
8966DEFUN (show_ipv6_bgp_regexp,
8967 show_ipv6_bgp_regexp_cmd,
8968 "show ipv6 bgp regexp .LINE",
8969 SHOW_STR
8970 IP_STR
8971 BGP_STR
8972 "Display routes matching the AS path regular expression\n"
8973 "A regular-expression to match the BGP AS paths\n")
8974{
47e9b292 8975 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 8976 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8977 bgp_show_type_regexp);
8978}
8979
8980/* old command */
8981DEFUN (show_ipv6_mbgp_regexp,
8982 show_ipv6_mbgp_regexp_cmd,
8983 "show ipv6 mbgp regexp .LINE",
8984 SHOW_STR
8985 IP_STR
8986 BGP_STR
8987 "Display routes matching the AS path regular expression\n"
8988 "A regular-expression to match the MBGP AS paths\n")
8989{
47e9b292 8990 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 8991 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
8992 bgp_show_type_regexp);
8993}
8994#endif /* HAVE_IPV6 */
6b0655a2 8995
94f2b392 8996static int
50ef26d4 8997bgp_show_prefix_list (struct vty *vty, const char *name,
8998 const char *prefix_list_str, afi_t afi,
718e3744 8999 safi_t safi, enum bgp_show_type type)
9000{
9001 struct prefix_list *plist;
50ef26d4 9002 struct bgp *bgp = NULL;
9003
9004 if (name && !(bgp = bgp_lookup_by_name(name)))
9005 {
9006 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9007 return CMD_WARNING;
9008 }
718e3744 9009
9010 plist = prefix_list_lookup (afi, prefix_list_str);
9011 if (plist == NULL)
9012 {
9013 vty_out (vty, "%% %s is not a valid prefix-list name%s",
9014 prefix_list_str, VTY_NEWLINE);
9015 return CMD_WARNING;
9016 }
9017
50ef26d4 9018 return bgp_show (vty, bgp, afi, safi, type, plist, 0);
718e3744 9019}
9020
9021DEFUN (show_ip_bgp_prefix_list,
9022 show_ip_bgp_prefix_list_cmd,
9023 "show ip bgp prefix-list WORD",
9024 SHOW_STR
9025 IP_STR
9026 BGP_STR
9027 "Display routes conforming to the prefix-list\n"
9028 "IP prefix-list name\n")
9029{
50ef26d4 9030 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9031 bgp_show_type_prefix_list);
9032}
9033
8386ac43 9034DEFUN (show_ip_bgp_instance_prefix_list,
9035 show_ip_bgp_instance_prefix_list_cmd,
9036 "show ip bgp " BGP_INSTANCE_CMD " prefix-list WORD",
50ef26d4 9037 SHOW_STR
9038 IP_STR
9039 BGP_STR
8386ac43 9040 BGP_INSTANCE_HELP_STR
50ef26d4 9041 "Display routes conforming to the prefix-list\n"
9042 "IP prefix-list name\n")
9043{
9044 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
718e3744 9045 bgp_show_type_prefix_list);
9046}
9047
9048DEFUN (show_ip_bgp_flap_prefix_list,
9049 show_ip_bgp_flap_prefix_list_cmd,
9050 "show ip bgp flap-statistics prefix-list WORD",
9051 SHOW_STR
9052 IP_STR
9053 BGP_STR
9054 "Display flap statistics of routes\n"
9055 "Display routes conforming to the prefix-list\n"
9056 "IP prefix-list name\n")
9057{
50ef26d4 9058 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 9059 bgp_show_type_flap_prefix_list);
9060}
9061
81304aaf
B
9062ALIAS (show_ip_bgp_flap_prefix_list,
9063 show_ip_bgp_damp_flap_prefix_list_cmd,
9064 "show ip bgp dampening flap-statistics prefix-list WORD",
9065 SHOW_STR
9066 IP_STR
9067 BGP_STR
9068 "Display detailed information about dampening\n"
9069 "Display flap statistics of routes\n"
9070 "Display routes conforming to the prefix-list\n"
9071 "IP prefix-list name\n")
9072
718e3744 9073DEFUN (show_ip_bgp_ipv4_prefix_list,
9074 show_ip_bgp_ipv4_prefix_list_cmd,
9075 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
9076 SHOW_STR
9077 IP_STR
9078 BGP_STR
9079 "Address family\n"
9080 "Address Family modifier\n"
9081 "Address Family modifier\n"
9082 "Display routes conforming to the prefix-list\n"
9083 "IP prefix-list name\n")
9084{
9085 if (strncmp (argv[0], "m", 1) == 0)
50ef26d4 9086 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
718e3744 9087 bgp_show_type_prefix_list);
9088
50ef26d4 9089 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
718e3744 9090 bgp_show_type_prefix_list);
9091}
9092
9093#ifdef HAVE_IPV6
9094DEFUN (show_bgp_prefix_list,
9095 show_bgp_prefix_list_cmd,
9096 "show bgp prefix-list WORD",
9097 SHOW_STR
9098 BGP_STR
9099 "Display routes conforming to the prefix-list\n"
9100 "IPv6 prefix-list name\n")
9101{
50ef26d4 9102 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 9103 bgp_show_type_prefix_list);
9104}
9105
9106ALIAS (show_bgp_prefix_list,
9107 show_bgp_ipv6_prefix_list_cmd,
9108 "show bgp ipv6 prefix-list WORD",
9109 SHOW_STR
9110 BGP_STR
9111 "Address family\n"
9112 "Display routes conforming to the prefix-list\n"
9113 "IPv6 prefix-list name\n")
9114
9115/* old command */
9116DEFUN (show_ipv6_bgp_prefix_list,
9117 show_ipv6_bgp_prefix_list_cmd,
9118 "show ipv6 bgp prefix-list WORD",
9119 SHOW_STR
9120 IPV6_STR
9121 BGP_STR
9122 "Display routes matching the prefix-list\n"
9123 "IPv6 prefix-list name\n")
9124{
47e9b292 9125 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 9126 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 9127 bgp_show_type_prefix_list);
9128}
9129
9130/* old command */
9131DEFUN (show_ipv6_mbgp_prefix_list,
9132 show_ipv6_mbgp_prefix_list_cmd,
9133 "show ipv6 mbgp prefix-list WORD",
9134 SHOW_STR
9135 IPV6_STR
9136 MBGP_STR
9137 "Display routes matching the prefix-list\n"
9138 "IPv6 prefix-list name\n")
9139{
47e9b292 9140 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 9141 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
718e3744 9142 bgp_show_type_prefix_list);
9143}
9144#endif /* HAVE_IPV6 */
6b0655a2 9145
94f2b392 9146static int
50ef26d4 9147bgp_show_filter_list (struct vty *vty, const char *name,
9148 const char *filter, afi_t afi,
718e3744 9149 safi_t safi, enum bgp_show_type type)
9150{
9151 struct as_list *as_list;
50ef26d4 9152 struct bgp *bgp = NULL;
9153
9154 if (name && !(bgp = bgp_lookup_by_name(name)))
9155 {
9156 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9157 return CMD_WARNING;
9158 }
718e3744 9159
9160 as_list = as_list_lookup (filter);
9161 if (as_list == NULL)
9162 {
9163 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
9164 return CMD_WARNING;
9165 }
9166
50ef26d4 9167 return bgp_show (vty, bgp, afi, safi, type, as_list, 0);
718e3744 9168}
9169
9170DEFUN (show_ip_bgp_filter_list,
9171 show_ip_bgp_filter_list_cmd,
9172 "show ip bgp filter-list WORD",
9173 SHOW_STR
9174 IP_STR
9175 BGP_STR
9176 "Display routes conforming to the filter-list\n"
9177 "Regular expression access list name\n")
9178{
50ef26d4 9179 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9180 bgp_show_type_filter_list);
9181}
9182
8386ac43 9183DEFUN (show_ip_bgp_instance_filter_list,
9184 show_ip_bgp_instance_filter_list_cmd,
9185 "show ip bgp " BGP_INSTANCE_CMD " filter-list WORD",
50ef26d4 9186 SHOW_STR
9187 IP_STR
9188 BGP_STR
8386ac43 9189 BGP_INSTANCE_HELP_STR
50ef26d4 9190 "Display routes conforming to the filter-list\n"
9191 "Regular expression access list name\n")
9192{
9193 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
718e3744 9194 bgp_show_type_filter_list);
9195}
9196
9197DEFUN (show_ip_bgp_flap_filter_list,
9198 show_ip_bgp_flap_filter_list_cmd,
9199 "show ip bgp flap-statistics filter-list WORD",
9200 SHOW_STR
9201 IP_STR
9202 BGP_STR
9203 "Display flap statistics of routes\n"
9204 "Display routes conforming to the filter-list\n"
9205 "Regular expression access list name\n")
9206{
50ef26d4 9207 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 9208 bgp_show_type_flap_filter_list);
9209}
9210
81304aaf
B
9211ALIAS (show_ip_bgp_flap_filter_list,
9212 show_ip_bgp_damp_flap_filter_list_cmd,
9213 "show ip bgp dampening flap-statistics filter-list WORD",
9214 SHOW_STR
9215 IP_STR
9216 BGP_STR
9217 "Display detailed information about dampening\n"
9218 "Display flap statistics of routes\n"
9219 "Display routes conforming to the filter-list\n"
9220 "Regular expression access list name\n")
9221
718e3744 9222DEFUN (show_ip_bgp_ipv4_filter_list,
9223 show_ip_bgp_ipv4_filter_list_cmd,
9224 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
9225 SHOW_STR
9226 IP_STR
9227 BGP_STR
9228 "Address family\n"
9229 "Address Family modifier\n"
9230 "Address Family modifier\n"
9231 "Display routes conforming to the filter-list\n"
9232 "Regular expression access list name\n")
9233{
9234 if (strncmp (argv[0], "m", 1) == 0)
50ef26d4 9235 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
718e3744 9236 bgp_show_type_filter_list);
9237
50ef26d4 9238 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
718e3744 9239 bgp_show_type_filter_list);
9240}
9241
9242#ifdef HAVE_IPV6
9243DEFUN (show_bgp_filter_list,
9244 show_bgp_filter_list_cmd,
9245 "show bgp filter-list WORD",
9246 SHOW_STR
9247 BGP_STR
9248 "Display routes conforming to the filter-list\n"
9249 "Regular expression access list name\n")
9250{
50ef26d4 9251 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 9252 bgp_show_type_filter_list);
9253}
9254
9255ALIAS (show_bgp_filter_list,
9256 show_bgp_ipv6_filter_list_cmd,
9257 "show bgp ipv6 filter-list WORD",
9258 SHOW_STR
9259 BGP_STR
9260 "Address family\n"
9261 "Display routes conforming to the filter-list\n"
9262 "Regular expression access list name\n")
9263
9264/* old command */
9265DEFUN (show_ipv6_bgp_filter_list,
9266 show_ipv6_bgp_filter_list_cmd,
9267 "show ipv6 bgp filter-list WORD",
9268 SHOW_STR
9269 IPV6_STR
9270 BGP_STR
9271 "Display routes conforming to the filter-list\n"
9272 "Regular expression access list name\n")
9273{
47e9b292 9274 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 9275 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 9276 bgp_show_type_filter_list);
9277}
9278
9279/* old command */
9280DEFUN (show_ipv6_mbgp_filter_list,
9281 show_ipv6_mbgp_filter_list_cmd,
9282 "show ipv6 mbgp filter-list WORD",
9283 SHOW_STR
9284 IPV6_STR
9285 MBGP_STR
9286 "Display routes conforming to the filter-list\n"
9287 "Regular expression access list name\n")
9288{
47e9b292 9289 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 9290 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
718e3744 9291 bgp_show_type_filter_list);
9292}
9293#endif /* HAVE_IPV6 */
6b0655a2 9294
81304aaf
B
9295DEFUN (show_ip_bgp_dampening_info,
9296 show_ip_bgp_dampening_params_cmd,
9297 "show ip bgp dampening parameters",
9298 SHOW_STR
9299 IP_STR
9300 BGP_STR
9301 "Display detailed information about dampening\n"
9302 "Display detail of configured dampening parameters\n")
9303{
9304 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
9305}
9306
94f2b392 9307static int
50ef26d4 9308bgp_show_route_map (struct vty *vty, const char *name,
9309 const char *rmap_str, afi_t afi,
718e3744 9310 safi_t safi, enum bgp_show_type type)
9311{
9312 struct route_map *rmap;
50ef26d4 9313 struct bgp *bgp = NULL;
9314
9315 if (name && !(bgp = bgp_lookup_by_name(name)))
9316 {
9317 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9318 return CMD_WARNING;
9319 }
718e3744 9320
9321 rmap = route_map_lookup_by_name (rmap_str);
9322 if (! rmap)
9323 {
9324 vty_out (vty, "%% %s is not a valid route-map name%s",
9325 rmap_str, VTY_NEWLINE);
9326 return CMD_WARNING;
9327 }
9328
50ef26d4 9329 return bgp_show (vty, bgp, afi, safi, type, rmap, 0);
718e3744 9330}
9331
9332DEFUN (show_ip_bgp_route_map,
9333 show_ip_bgp_route_map_cmd,
9334 "show ip bgp route-map WORD",
9335 SHOW_STR
9336 IP_STR
9337 BGP_STR
9338 "Display routes matching the route-map\n"
9339 "A route-map to match on\n")
9340{
50ef26d4 9341 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9342 bgp_show_type_route_map);
9343}
9344
8386ac43 9345DEFUN (show_ip_bgp_instance_route_map,
9346 show_ip_bgp_instance_route_map_cmd,
9347 "show ip bgp " BGP_INSTANCE_CMD " route-map WORD",
50ef26d4 9348 SHOW_STR
9349 IP_STR
9350 BGP_STR
8386ac43 9351 BGP_INSTANCE_HELP_STR
50ef26d4 9352 "Display routes matching the route-map\n"
9353 "A route-map to match on\n")
9354{
9355 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
718e3744 9356 bgp_show_type_route_map);
9357}
9358
9359DEFUN (show_ip_bgp_flap_route_map,
9360 show_ip_bgp_flap_route_map_cmd,
9361 "show ip bgp flap-statistics route-map WORD",
9362 SHOW_STR
9363 IP_STR
9364 BGP_STR
9365 "Display flap statistics of routes\n"
9366 "Display routes matching the route-map\n"
9367 "A route-map to match on\n")
9368{
50ef26d4 9369 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 9370 bgp_show_type_flap_route_map);
9371}
9372
81304aaf
B
9373ALIAS (show_ip_bgp_flap_route_map,
9374 show_ip_bgp_damp_flap_route_map_cmd,
9375 "show ip bgp dampening flap-statistics route-map WORD",
9376 SHOW_STR
9377 IP_STR
9378 BGP_STR
9379 "Display detailed information about dampening\n"
9380 "Display flap statistics of routes\n"
9381 "Display routes matching the route-map\n"
9382 "A route-map to match on\n")
9383
718e3744 9384DEFUN (show_ip_bgp_ipv4_route_map,
9385 show_ip_bgp_ipv4_route_map_cmd,
9386 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
9387 SHOW_STR
9388 IP_STR
9389 BGP_STR
9390 "Address family\n"
9391 "Address Family modifier\n"
9392 "Address Family modifier\n"
9393 "Display routes matching the route-map\n"
9394 "A route-map to match on\n")
9395{
9396 if (strncmp (argv[0], "m", 1) == 0)
50ef26d4 9397 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
718e3744 9398 bgp_show_type_route_map);
9399
50ef26d4 9400 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
718e3744 9401 bgp_show_type_route_map);
9402}
9403
9404DEFUN (show_bgp_route_map,
9405 show_bgp_route_map_cmd,
9406 "show bgp route-map WORD",
9407 SHOW_STR
9408 BGP_STR
9409 "Display routes matching the route-map\n"
9410 "A route-map to match on\n")
9411{
50ef26d4 9412 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 9413 bgp_show_type_route_map);
9414}
9415
9416ALIAS (show_bgp_route_map,
9417 show_bgp_ipv6_route_map_cmd,
9418 "show bgp ipv6 route-map WORD",
9419 SHOW_STR
9420 BGP_STR
9421 "Address family\n"
9422 "Display routes matching the route-map\n"
9423 "A route-map to match on\n")
6b0655a2 9424
718e3744 9425DEFUN (show_ip_bgp_cidr_only,
9426 show_ip_bgp_cidr_only_cmd,
9427 "show ip bgp cidr-only",
9428 SHOW_STR
9429 IP_STR
9430 BGP_STR
9431 "Display only routes with non-natural netmasks\n")
9432{
9433 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9434 bgp_show_type_cidr_only, NULL, 0);
718e3744 9435}
9436
9437DEFUN (show_ip_bgp_flap_cidr_only,
9438 show_ip_bgp_flap_cidr_only_cmd,
9439 "show ip bgp flap-statistics cidr-only",
9440 SHOW_STR
9441 IP_STR
9442 BGP_STR
9443 "Display flap statistics of routes\n"
9444 "Display only routes with non-natural netmasks\n")
9445{
9446 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9447 bgp_show_type_flap_cidr_only, NULL, 0);
718e3744 9448}
9449
81304aaf
B
9450ALIAS (show_ip_bgp_flap_cidr_only,
9451 show_ip_bgp_damp_flap_cidr_only_cmd,
9452 "show ip bgp dampening flap-statistics cidr-only",
9453 SHOW_STR
9454 IP_STR
9455 BGP_STR
9456 "Display detailed information about dampening\n"
9457 "Display flap statistics of routes\n"
9458 "Display only routes with non-natural netmasks\n")
9459
718e3744 9460DEFUN (show_ip_bgp_ipv4_cidr_only,
9461 show_ip_bgp_ipv4_cidr_only_cmd,
9462 "show ip bgp ipv4 (unicast|multicast) cidr-only",
9463 SHOW_STR
9464 IP_STR
9465 BGP_STR
9466 "Address family\n"
9467 "Address Family modifier\n"
9468 "Address Family modifier\n"
9469 "Display only routes with non-natural netmasks\n")
9470{
9471 if (strncmp (argv[0], "m", 1) == 0)
9472 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
b05a1c8b 9473 bgp_show_type_cidr_only, NULL, 0);
718e3744 9474
9475 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9476 bgp_show_type_cidr_only, NULL, 0);
718e3744 9477}
6b0655a2 9478
718e3744 9479DEFUN (show_ip_bgp_community_all,
9480 show_ip_bgp_community_all_cmd,
9481 "show ip bgp community",
9482 SHOW_STR
9483 IP_STR
9484 BGP_STR
9485 "Display routes matching the communities\n")
9486{
9487 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9488 bgp_show_type_community_all, NULL, 0);
718e3744 9489}
9490
9491DEFUN (show_ip_bgp_ipv4_community_all,
9492 show_ip_bgp_ipv4_community_all_cmd,
9493 "show ip bgp ipv4 (unicast|multicast) community",
9494 SHOW_STR
9495 IP_STR
9496 BGP_STR
9497 "Address family\n"
9498 "Address Family modifier\n"
9499 "Address Family modifier\n"
9500 "Display routes matching the communities\n")
9501{
9502 if (strncmp (argv[0], "m", 1) == 0)
9503 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
b05a1c8b 9504 bgp_show_type_community_all, NULL, 0);
718e3744 9505
9506 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9507 bgp_show_type_community_all, NULL, 0);
718e3744 9508}
9509
9510#ifdef HAVE_IPV6
9511DEFUN (show_bgp_community_all,
9512 show_bgp_community_all_cmd,
9513 "show bgp community",
9514 SHOW_STR
9515 BGP_STR
9516 "Display routes matching the communities\n")
9517{
9518 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 9519 bgp_show_type_community_all, NULL, 0);
718e3744 9520}
9521
9522ALIAS (show_bgp_community_all,
9523 show_bgp_ipv6_community_all_cmd,
9524 "show bgp ipv6 community",
9525 SHOW_STR
9526 BGP_STR
9527 "Address family\n"
9528 "Display routes matching the communities\n")
9529
9530/* old command */
9531DEFUN (show_ipv6_bgp_community_all,
9532 show_ipv6_bgp_community_all_cmd,
9533 "show ipv6 bgp community",
9534 SHOW_STR
9535 IPV6_STR
9536 BGP_STR
9537 "Display routes matching the communities\n")
9538{
47e9b292 9539 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 9540 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 9541 bgp_show_type_community_all, NULL, 0);
718e3744 9542}
9543
9544/* old command */
9545DEFUN (show_ipv6_mbgp_community_all,
9546 show_ipv6_mbgp_community_all_cmd,
9547 "show ipv6 mbgp community",
9548 SHOW_STR
9549 IPV6_STR
9550 MBGP_STR
9551 "Display routes matching the communities\n")
9552{
47e9b292 9553 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 9554 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
b05a1c8b 9555 bgp_show_type_community_all, NULL, 0);
718e3744 9556}
9557#endif /* HAVE_IPV6 */
6b0655a2 9558
94f2b392 9559static int
95cbbd2a
ML
9560bgp_show_community (struct vty *vty, const char *view_name, int argc,
9561 const char **argv, int exact, afi_t afi, safi_t safi)
718e3744 9562{
9563 struct community *com;
9564 struct buffer *b;
95cbbd2a 9565 struct bgp *bgp;
718e3744 9566 int i;
9567 char *str;
9568 int first = 0;
9569
95cbbd2a
ML
9570 /* BGP structure lookup */
9571 if (view_name)
9572 {
9573 bgp = bgp_lookup_by_name (view_name);
9574 if (bgp == NULL)
9575 {
6aeb9e78 9576 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
95cbbd2a
ML
9577 return CMD_WARNING;
9578 }
9579 }
9580 else
9581 {
9582 bgp = bgp_get_default ();
9583 if (bgp == NULL)
9584 {
9585 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9586 return CMD_WARNING;
9587 }
9588 }
9589
718e3744 9590 b = buffer_new (1024);
9591 for (i = 0; i < argc; i++)
9592 {
9593 if (first)
9594 buffer_putc (b, ' ');
9595 else
9596 {
9597 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9598 continue;
9599 first = 1;
9600 }
9601
9602 buffer_putstr (b, argv[i]);
9603 }
9604 buffer_putc (b, '\0');
9605
9606 str = buffer_getstr (b);
9607 buffer_free (b);
9608
9609 com = community_str2com (str);
3b8b1855 9610 XFREE (MTYPE_TMP, str);
718e3744 9611 if (! com)
9612 {
9613 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9614 return CMD_WARNING;
9615 }
9616
95cbbd2a 9617 return bgp_show (vty, bgp, afi, safi,
5a646650 9618 (exact ? bgp_show_type_community_exact :
b05a1c8b 9619 bgp_show_type_community), com, 0);
718e3744 9620}
9621
9622DEFUN (show_ip_bgp_community,
9623 show_ip_bgp_community_cmd,
9624 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9625 SHOW_STR
9626 IP_STR
9627 BGP_STR
9628 "Display routes matching the communities\n"
859d388e 9629 COMMUNITY_AANN_STR
718e3744 9630 "Do not send outside local AS (well-known community)\n"
9631 "Do not advertise to any peer (well-known community)\n"
9632 "Do not export to next AS (well-known community)\n")
9633{
95cbbd2a 9634 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 9635}
9636
9637ALIAS (show_ip_bgp_community,
9638 show_ip_bgp_community2_cmd,
9639 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9640 SHOW_STR
9641 IP_STR
9642 BGP_STR
9643 "Display routes matching the communities\n"
859d388e 9644 COMMUNITY_AANN_STR
718e3744 9645 "Do not send outside local AS (well-known community)\n"
9646 "Do not advertise to any peer (well-known community)\n"
9647 "Do not export to next AS (well-known community)\n"
859d388e 9648 COMMUNITY_AANN_STR
718e3744 9649 "Do not send outside local AS (well-known community)\n"
9650 "Do not advertise to any peer (well-known community)\n"
9651 "Do not export to next AS (well-known community)\n")
9652
9653ALIAS (show_ip_bgp_community,
9654 show_ip_bgp_community3_cmd,
9655 "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)",
9656 SHOW_STR
9657 IP_STR
9658 BGP_STR
9659 "Display routes matching the communities\n"
859d388e 9660 COMMUNITY_AANN_STR
718e3744 9661 "Do not send outside local AS (well-known community)\n"
9662 "Do not advertise to any peer (well-known community)\n"
9663 "Do not export to next AS (well-known community)\n"
859d388e 9664 COMMUNITY_AANN_STR
718e3744 9665 "Do not send outside local AS (well-known community)\n"
9666 "Do not advertise to any peer (well-known community)\n"
9667 "Do not export to next AS (well-known community)\n"
859d388e 9668 COMMUNITY_AANN_STR
718e3744 9669 "Do not send outside local AS (well-known community)\n"
9670 "Do not advertise to any peer (well-known community)\n"
9671 "Do not export to next AS (well-known community)\n")
9672
9673ALIAS (show_ip_bgp_community,
9674 show_ip_bgp_community4_cmd,
9675 "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)",
9676 SHOW_STR
9677 IP_STR
9678 BGP_STR
9679 "Display routes matching the communities\n"
859d388e 9680 COMMUNITY_AANN_STR
718e3744 9681 "Do not send outside local AS (well-known community)\n"
9682 "Do not advertise to any peer (well-known community)\n"
9683 "Do not export to next AS (well-known community)\n"
859d388e 9684 COMMUNITY_AANN_STR
718e3744 9685 "Do not send outside local AS (well-known community)\n"
9686 "Do not advertise to any peer (well-known community)\n"
9687 "Do not export to next AS (well-known community)\n"
859d388e 9688 COMMUNITY_AANN_STR
718e3744 9689 "Do not send outside local AS (well-known community)\n"
9690 "Do not advertise to any peer (well-known community)\n"
9691 "Do not export to next AS (well-known community)\n"
859d388e 9692 COMMUNITY_AANN_STR
718e3744 9693 "Do not send outside local AS (well-known community)\n"
9694 "Do not advertise to any peer (well-known community)\n"
9695 "Do not export to next AS (well-known community)\n")
9696
9697DEFUN (show_ip_bgp_ipv4_community,
9698 show_ip_bgp_ipv4_community_cmd,
9699 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9700 SHOW_STR
9701 IP_STR
9702 BGP_STR
9703 "Address family\n"
9704 "Address Family modifier\n"
9705 "Address Family modifier\n"
9706 "Display routes matching the communities\n"
859d388e 9707 COMMUNITY_AANN_STR
718e3744 9708 "Do not send outside local AS (well-known community)\n"
9709 "Do not advertise to any peer (well-known community)\n"
9710 "Do not export to next AS (well-known community)\n")
9711{
9712 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 9713 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
718e3744 9714
95cbbd2a 9715 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 9716}
9717
9718ALIAS (show_ip_bgp_ipv4_community,
9719 show_ip_bgp_ipv4_community2_cmd,
9720 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9721 SHOW_STR
9722 IP_STR
9723 BGP_STR
9724 "Address family\n"
9725 "Address Family modifier\n"
9726 "Address Family modifier\n"
9727 "Display routes matching the communities\n"
859d388e 9728 COMMUNITY_AANN_STR
718e3744 9729 "Do not send outside local AS (well-known community)\n"
9730 "Do not advertise to any peer (well-known community)\n"
9731 "Do not export to next AS (well-known community)\n"
859d388e 9732 COMMUNITY_AANN_STR
718e3744 9733 "Do not send outside local AS (well-known community)\n"
9734 "Do not advertise to any peer (well-known community)\n"
9735 "Do not export to next AS (well-known community)\n")
9736
9737ALIAS (show_ip_bgp_ipv4_community,
9738 show_ip_bgp_ipv4_community3_cmd,
9739 "show ip bgp ipv4 (unicast|multicast) 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)",
9740 SHOW_STR
9741 IP_STR
9742 BGP_STR
9743 "Address family\n"
9744 "Address Family modifier\n"
9745 "Address Family modifier\n"
9746 "Display routes matching the communities\n"
859d388e 9747 COMMUNITY_AANN_STR
718e3744 9748 "Do not send outside local AS (well-known community)\n"
9749 "Do not advertise to any peer (well-known community)\n"
9750 "Do not export to next AS (well-known community)\n"
859d388e 9751 COMMUNITY_AANN_STR
718e3744 9752 "Do not send outside local AS (well-known community)\n"
9753 "Do not advertise to any peer (well-known community)\n"
9754 "Do not export to next AS (well-known community)\n"
859d388e 9755 COMMUNITY_AANN_STR
718e3744 9756 "Do not send outside local AS (well-known community)\n"
9757 "Do not advertise to any peer (well-known community)\n"
9758 "Do not export to next AS (well-known community)\n")
9759
9760ALIAS (show_ip_bgp_ipv4_community,
9761 show_ip_bgp_ipv4_community4_cmd,
9762 "show ip bgp ipv4 (unicast|multicast) 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)",
9763 SHOW_STR
9764 IP_STR
9765 BGP_STR
9766 "Address family\n"
9767 "Address Family modifier\n"
9768 "Address Family modifier\n"
9769 "Display routes matching the communities\n"
859d388e 9770 COMMUNITY_AANN_STR
718e3744 9771 "Do not send outside local AS (well-known community)\n"
9772 "Do not advertise to any peer (well-known community)\n"
9773 "Do not export to next AS (well-known community)\n"
859d388e 9774 COMMUNITY_AANN_STR
718e3744 9775 "Do not send outside local AS (well-known community)\n"
9776 "Do not advertise to any peer (well-known community)\n"
9777 "Do not export to next AS (well-known community)\n"
859d388e 9778 COMMUNITY_AANN_STR
718e3744 9779 "Do not send outside local AS (well-known community)\n"
9780 "Do not advertise to any peer (well-known community)\n"
9781 "Do not export to next AS (well-known community)\n"
859d388e 9782 COMMUNITY_AANN_STR
718e3744 9783 "Do not send outside local AS (well-known community)\n"
9784 "Do not advertise to any peer (well-known community)\n"
9785 "Do not export to next AS (well-known community)\n")
9786
8386ac43 9787DEFUN (show_bgp_instance_afi_safi_community_all,
9788 show_bgp_instance_afi_safi_community_all_cmd,
8386ac43 9789 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community",
95cbbd2a
ML
9790 SHOW_STR
9791 BGP_STR
8386ac43 9792 BGP_INSTANCE_HELP_STR
95cbbd2a 9793 "Address family\n"
95cbbd2a 9794 "Address family\n"
95cbbd2a
ML
9795 "Address Family modifier\n"
9796 "Address Family modifier\n"
2b00515a 9797 "Display routes matching the communities\n")
95cbbd2a
ML
9798{
9799 int afi;
9800 int safi;
9801 struct bgp *bgp;
9802
9803 /* BGP structure lookup. */
6aeb9e78 9804 bgp = bgp_lookup_by_name (argv[1]);
95cbbd2a
ML
9805 if (bgp == NULL)
9806 {
6aeb9e78 9807 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
95cbbd2a
ML
9808 return CMD_WARNING;
9809 }
9810
6aeb9e78
DS
9811 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9812 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
b05a1c8b 9813 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
95cbbd2a
ML
9814}
9815
8386ac43 9816DEFUN (show_bgp_instance_afi_safi_community,
9817 show_bgp_instance_afi_safi_community_cmd,
8386ac43 9818 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
95cbbd2a
ML
9819 SHOW_STR
9820 BGP_STR
8386ac43 9821 BGP_INSTANCE_HELP_STR
95cbbd2a 9822 "Address family\n"
95cbbd2a 9823 "Address family\n"
95cbbd2a
ML
9824 "Address family modifier\n"
9825 "Address family modifier\n"
9826 "Display routes matching the communities\n"
859d388e 9827 COMMUNITY_AANN_STR
95cbbd2a
ML
9828 "Do not send outside local AS (well-known community)\n"
9829 "Do not advertise to any peer (well-known community)\n"
9830 "Do not export to next AS (well-known community)\n")
9831{
9832 int afi;
9833 int safi;
9834
6aeb9e78
DS
9835 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9836 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9837 return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi);
95cbbd2a
ML
9838}
9839
8386ac43 9840ALIAS (show_bgp_instance_afi_safi_community,
9841 show_bgp_instance_afi_safi_community2_cmd,
8386ac43 9842 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
95cbbd2a
ML
9843 SHOW_STR
9844 BGP_STR
8386ac43 9845 BGP_INSTANCE_HELP_STR
95cbbd2a 9846 "Address family\n"
95cbbd2a 9847 "Address family\n"
95cbbd2a
ML
9848 "Address family modifier\n"
9849 "Address family modifier\n"
9850 "Display routes matching the communities\n"
859d388e 9851 COMMUNITY_AANN_STR
95cbbd2a
ML
9852 "Do not send outside local AS (well-known community)\n"
9853 "Do not advertise to any peer (well-known community)\n"
9854 "Do not export to next AS (well-known community)\n"
859d388e 9855 COMMUNITY_AANN_STR
95cbbd2a
ML
9856 "Do not send outside local AS (well-known community)\n"
9857 "Do not advertise to any peer (well-known community)\n"
9858 "Do not export to next AS (well-known community)\n")
9859
8386ac43 9860ALIAS (show_bgp_instance_afi_safi_community,
9861 show_bgp_instance_afi_safi_community3_cmd,
8386ac43 9862 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) 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
9863 SHOW_STR
9864 BGP_STR
8386ac43 9865 BGP_INSTANCE_HELP_STR
95cbbd2a 9866 "Address family\n"
95cbbd2a 9867 "Address family\n"
95cbbd2a
ML
9868 "Address family modifier\n"
9869 "Address family modifier\n"
9870 "Display routes matching the communities\n"
859d388e 9871 COMMUNITY_AANN_STR
95cbbd2a
ML
9872 "Do not send outside local AS (well-known community)\n"
9873 "Do not advertise to any peer (well-known community)\n"
9874 "Do not export to next AS (well-known community)\n"
859d388e 9875 COMMUNITY_AANN_STR
95cbbd2a
ML
9876 "Do not send outside local AS (well-known community)\n"
9877 "Do not advertise to any peer (well-known community)\n"
9878 "Do not export to next AS (well-known community)\n"
859d388e 9879 COMMUNITY_AANN_STR
95cbbd2a
ML
9880 "Do not send outside local AS (well-known community)\n"
9881 "Do not advertise to any peer (well-known community)\n"
9882 "Do not export to next AS (well-known community)\n")
9883
8386ac43 9884ALIAS (show_bgp_instance_afi_safi_community,
9885 show_bgp_instance_afi_safi_community4_cmd,
8386ac43 9886 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) 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
9887 SHOW_STR
9888 BGP_STR
8386ac43 9889 BGP_INSTANCE_HELP_STR
95cbbd2a 9890 "Address family\n"
95cbbd2a 9891 "Address family\n"
95cbbd2a
ML
9892 "Address family modifier\n"
9893 "Address family modifier\n"
9894 "Display routes matching the communities\n"
859d388e 9895 COMMUNITY_AANN_STR
95cbbd2a
ML
9896 "Do not send outside local AS (well-known community)\n"
9897 "Do not advertise to any peer (well-known community)\n"
9898 "Do not export to next AS (well-known community)\n"
859d388e 9899 COMMUNITY_AANN_STR
95cbbd2a
ML
9900 "Do not send outside local AS (well-known community)\n"
9901 "Do not advertise to any peer (well-known community)\n"
9902 "Do not export to next AS (well-known community)\n"
859d388e 9903 COMMUNITY_AANN_STR
95cbbd2a
ML
9904 "Do not send outside local AS (well-known community)\n"
9905 "Do not advertise to any peer (well-known community)\n"
9906 "Do not export to next AS (well-known community)\n"
859d388e 9907 COMMUNITY_AANN_STR
95cbbd2a
ML
9908 "Do not send outside local AS (well-known community)\n"
9909 "Do not advertise to any peer (well-known community)\n"
9910 "Do not export to next AS (well-known community)\n")
9911
718e3744 9912DEFUN (show_ip_bgp_community_exact,
9913 show_ip_bgp_community_exact_cmd,
9914 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9915 SHOW_STR
9916 IP_STR
9917 BGP_STR
9918 "Display routes matching the communities\n"
859d388e 9919 COMMUNITY_AANN_STR
718e3744 9920 "Do not send outside local AS (well-known community)\n"
9921 "Do not advertise to any peer (well-known community)\n"
9922 "Do not export to next AS (well-known community)\n"
9923 "Exact match of the communities")
9924{
95cbbd2a 9925 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 9926}
9927
9928ALIAS (show_ip_bgp_community_exact,
9929 show_ip_bgp_community2_exact_cmd,
9930 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9931 SHOW_STR
9932 IP_STR
9933 BGP_STR
9934 "Display routes matching the communities\n"
859d388e 9935 COMMUNITY_AANN_STR
718e3744 9936 "Do not send outside local AS (well-known community)\n"
9937 "Do not advertise to any peer (well-known community)\n"
9938 "Do not export to next AS (well-known community)\n"
859d388e 9939 COMMUNITY_AANN_STR
718e3744 9940 "Do not send outside local AS (well-known community)\n"
9941 "Do not advertise to any peer (well-known community)\n"
9942 "Do not export to next AS (well-known community)\n"
9943 "Exact match of the communities")
9944
9945ALIAS (show_ip_bgp_community_exact,
9946 show_ip_bgp_community3_exact_cmd,
9947 "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",
9948 SHOW_STR
9949 IP_STR
9950 BGP_STR
9951 "Display routes matching the communities\n"
859d388e 9952 COMMUNITY_AANN_STR
718e3744 9953 "Do not send outside local AS (well-known community)\n"
9954 "Do not advertise to any peer (well-known community)\n"
9955 "Do not export to next AS (well-known community)\n"
859d388e 9956 COMMUNITY_AANN_STR
718e3744 9957 "Do not send outside local AS (well-known community)\n"
9958 "Do not advertise to any peer (well-known community)\n"
9959 "Do not export to next AS (well-known community)\n"
859d388e 9960 COMMUNITY_AANN_STR
718e3744 9961 "Do not send outside local AS (well-known community)\n"
9962 "Do not advertise to any peer (well-known community)\n"
9963 "Do not export to next AS (well-known community)\n"
9964 "Exact match of the communities")
9965
9966ALIAS (show_ip_bgp_community_exact,
9967 show_ip_bgp_community4_exact_cmd,
9968 "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",
9969 SHOW_STR
9970 IP_STR
9971 BGP_STR
9972 "Display routes matching the communities\n"
859d388e 9973 COMMUNITY_AANN_STR
718e3744 9974 "Do not send outside local AS (well-known community)\n"
9975 "Do not advertise to any peer (well-known community)\n"
9976 "Do not export to next AS (well-known community)\n"
859d388e 9977 COMMUNITY_AANN_STR
718e3744 9978 "Do not send outside local AS (well-known community)\n"
9979 "Do not advertise to any peer (well-known community)\n"
9980 "Do not export to next AS (well-known community)\n"
859d388e 9981 COMMUNITY_AANN_STR
718e3744 9982 "Do not send outside local AS (well-known community)\n"
9983 "Do not advertise to any peer (well-known community)\n"
9984 "Do not export to next AS (well-known community)\n"
859d388e 9985 COMMUNITY_AANN_STR
718e3744 9986 "Do not send outside local AS (well-known community)\n"
9987 "Do not advertise to any peer (well-known community)\n"
9988 "Do not export to next AS (well-known community)\n"
9989 "Exact match of the communities")
9990
9991DEFUN (show_ip_bgp_ipv4_community_exact,
9992 show_ip_bgp_ipv4_community_exact_cmd,
9993 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9994 SHOW_STR
9995 IP_STR
9996 BGP_STR
9997 "Address family\n"
9998 "Address Family modifier\n"
9999 "Address Family modifier\n"
10000 "Display routes matching the communities\n"
859d388e 10001 COMMUNITY_AANN_STR
718e3744 10002 "Do not send outside local AS (well-known community)\n"
10003 "Do not advertise to any peer (well-known community)\n"
10004 "Do not export to next AS (well-known community)\n"
10005 "Exact match of the communities")
10006{
10007 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 10008 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
718e3744 10009
95cbbd2a 10010 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 10011}
10012
10013ALIAS (show_ip_bgp_ipv4_community_exact,
10014 show_ip_bgp_ipv4_community2_exact_cmd,
10015 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10016 SHOW_STR
10017 IP_STR
10018 BGP_STR
10019 "Address family\n"
10020 "Address Family modifier\n"
10021 "Address Family modifier\n"
10022 "Display routes matching the communities\n"
859d388e 10023 COMMUNITY_AANN_STR
718e3744 10024 "Do not send outside local AS (well-known community)\n"
10025 "Do not advertise to any peer (well-known community)\n"
10026 "Do not export to next AS (well-known community)\n"
859d388e 10027 COMMUNITY_AANN_STR
718e3744 10028 "Do not send outside local AS (well-known community)\n"
10029 "Do not advertise to any peer (well-known community)\n"
10030 "Do not export to next AS (well-known community)\n"
10031 "Exact match of the communities")
10032
10033ALIAS (show_ip_bgp_ipv4_community_exact,
10034 show_ip_bgp_ipv4_community3_exact_cmd,
10035 "show ip bgp ipv4 (unicast|multicast) 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",
10036 SHOW_STR
10037 IP_STR
10038 BGP_STR
10039 "Address family\n"
10040 "Address Family modifier\n"
10041 "Address Family modifier\n"
10042 "Display routes matching the communities\n"
859d388e 10043 COMMUNITY_AANN_STR
718e3744 10044 "Do not send outside local AS (well-known community)\n"
10045 "Do not advertise to any peer (well-known community)\n"
10046 "Do not export to next AS (well-known community)\n"
859d388e 10047 COMMUNITY_AANN_STR
718e3744 10048 "Do not send outside local AS (well-known community)\n"
10049 "Do not advertise to any peer (well-known community)\n"
10050 "Do not export to next AS (well-known community)\n"
859d388e 10051 COMMUNITY_AANN_STR
718e3744 10052 "Do not send outside local AS (well-known community)\n"
10053 "Do not advertise to any peer (well-known community)\n"
10054 "Do not export to next AS (well-known community)\n"
10055 "Exact match of the communities")
10056
10057ALIAS (show_ip_bgp_ipv4_community_exact,
10058 show_ip_bgp_ipv4_community4_exact_cmd,
10059 "show ip bgp ipv4 (unicast|multicast) 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",
10060 SHOW_STR
10061 IP_STR
10062 BGP_STR
10063 "Address family\n"
10064 "Address Family modifier\n"
10065 "Address Family modifier\n"
10066 "Display routes matching the communities\n"
859d388e 10067 COMMUNITY_AANN_STR
718e3744 10068 "Do not send outside local AS (well-known community)\n"
10069 "Do not advertise to any peer (well-known community)\n"
10070 "Do not export to next AS (well-known community)\n"
859d388e 10071 COMMUNITY_AANN_STR
718e3744 10072 "Do not send outside local AS (well-known community)\n"
10073 "Do not advertise to any peer (well-known community)\n"
10074 "Do not export to next AS (well-known community)\n"
859d388e 10075 COMMUNITY_AANN_STR
718e3744 10076 "Do not send outside local AS (well-known community)\n"
10077 "Do not advertise to any peer (well-known community)\n"
10078 "Do not export to next AS (well-known community)\n"
859d388e 10079 COMMUNITY_AANN_STR
718e3744 10080 "Do not send outside local AS (well-known community)\n"
10081 "Do not advertise to any peer (well-known community)\n"
10082 "Do not export to next AS (well-known community)\n"
10083 "Exact match of the communities")
10084
10085#ifdef HAVE_IPV6
10086DEFUN (show_bgp_community,
10087 show_bgp_community_cmd,
10088 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
10089 SHOW_STR
10090 BGP_STR
10091 "Display routes matching the communities\n"
859d388e 10092 COMMUNITY_AANN_STR
718e3744 10093 "Do not send outside local AS (well-known community)\n"
10094 "Do not advertise to any peer (well-known community)\n"
10095 "Do not export to next AS (well-known community)\n")
10096{
95cbbd2a 10097 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 10098}
10099
10100ALIAS (show_bgp_community,
10101 show_bgp_ipv6_community_cmd,
10102 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
10103 SHOW_STR
10104 BGP_STR
10105 "Address family\n"
10106 "Display routes matching the communities\n"
859d388e 10107 COMMUNITY_AANN_STR
718e3744 10108 "Do not send outside local AS (well-known community)\n"
10109 "Do not advertise to any peer (well-known community)\n"
10110 "Do not export to next AS (well-known community)\n")
10111
10112ALIAS (show_bgp_community,
10113 show_bgp_community2_cmd,
10114 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10115 SHOW_STR
10116 BGP_STR
10117 "Display routes matching the communities\n"
859d388e 10118 COMMUNITY_AANN_STR
718e3744 10119 "Do not send outside local AS (well-known community)\n"
10120 "Do not advertise to any peer (well-known community)\n"
10121 "Do not export to next AS (well-known community)\n"
859d388e 10122 COMMUNITY_AANN_STR
718e3744 10123 "Do not send outside local AS (well-known community)\n"
10124 "Do not advertise to any peer (well-known community)\n"
10125 "Do not export to next AS (well-known community)\n")
10126
10127ALIAS (show_bgp_community,
10128 show_bgp_ipv6_community2_cmd,
10129 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10130 SHOW_STR
10131 BGP_STR
10132 "Address family\n"
10133 "Display routes matching the communities\n"
859d388e 10134 COMMUNITY_AANN_STR
718e3744 10135 "Do not send outside local AS (well-known community)\n"
10136 "Do not advertise to any peer (well-known community)\n"
10137 "Do not export to next AS (well-known community)\n"
859d388e 10138 COMMUNITY_AANN_STR
718e3744 10139 "Do not send outside local AS (well-known community)\n"
10140 "Do not advertise to any peer (well-known community)\n"
10141 "Do not export to next AS (well-known community)\n")
10142
10143ALIAS (show_bgp_community,
10144 show_bgp_community3_cmd,
10145 "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)",
10146 SHOW_STR
10147 BGP_STR
10148 "Display routes matching the communities\n"
859d388e 10149 COMMUNITY_AANN_STR
718e3744 10150 "Do not send outside local AS (well-known community)\n"
10151 "Do not advertise to any peer (well-known community)\n"
10152 "Do not export to next AS (well-known community)\n"
859d388e 10153 COMMUNITY_AANN_STR
718e3744 10154 "Do not send outside local AS (well-known community)\n"
10155 "Do not advertise to any peer (well-known community)\n"
10156 "Do not export to next AS (well-known community)\n"
859d388e 10157 COMMUNITY_AANN_STR
718e3744 10158 "Do not send outside local AS (well-known community)\n"
10159 "Do not advertise to any peer (well-known community)\n"
10160 "Do not export to next AS (well-known community)\n")
10161
10162ALIAS (show_bgp_community,
10163 show_bgp_ipv6_community3_cmd,
10164 "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)",
10165 SHOW_STR
10166 BGP_STR
10167 "Address family\n"
10168 "Display routes matching the communities\n"
859d388e 10169 COMMUNITY_AANN_STR
718e3744 10170 "Do not send outside local AS (well-known community)\n"
10171 "Do not advertise to any peer (well-known community)\n"
10172 "Do not export to next AS (well-known community)\n"
859d388e 10173 COMMUNITY_AANN_STR
718e3744 10174 "Do not send outside local AS (well-known community)\n"
10175 "Do not advertise to any peer (well-known community)\n"
10176 "Do not export to next AS (well-known community)\n"
859d388e 10177 COMMUNITY_AANN_STR
718e3744 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
10182ALIAS (show_bgp_community,
10183 show_bgp_community4_cmd,
10184 "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)",
10185 SHOW_STR
10186 BGP_STR
10187 "Display routes matching the communities\n"
859d388e 10188 COMMUNITY_AANN_STR
718e3744 10189 "Do not send outside local AS (well-known community)\n"
10190 "Do not advertise to any peer (well-known community)\n"
10191 "Do not export to next AS (well-known community)\n"
859d388e 10192 COMMUNITY_AANN_STR
718e3744 10193 "Do not send outside local AS (well-known community)\n"
10194 "Do not advertise to any peer (well-known community)\n"
10195 "Do not export to next AS (well-known community)\n"
859d388e 10196 COMMUNITY_AANN_STR
718e3744 10197 "Do not send outside local AS (well-known community)\n"
10198 "Do not advertise to any peer (well-known community)\n"
10199 "Do not export to next AS (well-known community)\n"
859d388e 10200 COMMUNITY_AANN_STR
718e3744 10201 "Do not send outside local AS (well-known community)\n"
10202 "Do not advertise to any peer (well-known community)\n"
10203 "Do not export to next AS (well-known community)\n")
10204
10205ALIAS (show_bgp_community,
10206 show_bgp_ipv6_community4_cmd,
10207 "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)",
10208 SHOW_STR
10209 BGP_STR
10210 "Address family\n"
10211 "Display routes matching the communities\n"
859d388e 10212 COMMUNITY_AANN_STR
718e3744 10213 "Do not send outside local AS (well-known community)\n"
10214 "Do not advertise to any peer (well-known community)\n"
10215 "Do not export to next AS (well-known community)\n"
859d388e 10216 COMMUNITY_AANN_STR
718e3744 10217 "Do not send outside local AS (well-known community)\n"
10218 "Do not advertise to any peer (well-known community)\n"
10219 "Do not export to next AS (well-known community)\n"
859d388e 10220 COMMUNITY_AANN_STR
718e3744 10221 "Do not send outside local AS (well-known community)\n"
10222 "Do not advertise to any peer (well-known community)\n"
10223 "Do not export to next AS (well-known community)\n"
859d388e 10224 COMMUNITY_AANN_STR
718e3744 10225 "Do not send outside local AS (well-known community)\n"
10226 "Do not advertise to any peer (well-known community)\n"
10227 "Do not export to next AS (well-known community)\n")
10228
10229/* old command */
10230DEFUN (show_ipv6_bgp_community,
10231 show_ipv6_bgp_community_cmd,
10232 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
10233 SHOW_STR
10234 IPV6_STR
10235 BGP_STR
10236 "Display routes matching the communities\n"
859d388e 10237 COMMUNITY_AANN_STR
718e3744 10238 "Do not send outside local AS (well-known community)\n"
10239 "Do not advertise to any peer (well-known community)\n"
10240 "Do not export to next AS (well-known community)\n")
10241{
47e9b292 10242 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 10243 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 10244}
10245
10246/* old command */
10247ALIAS (show_ipv6_bgp_community,
10248 show_ipv6_bgp_community2_cmd,
10249 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10250 SHOW_STR
10251 IPV6_STR
10252 BGP_STR
10253 "Display routes matching the communities\n"
859d388e 10254 COMMUNITY_AANN_STR
718e3744 10255 "Do not send outside local AS (well-known community)\n"
10256 "Do not advertise to any peer (well-known community)\n"
10257 "Do not export to next AS (well-known community)\n"
859d388e 10258 COMMUNITY_AANN_STR
718e3744 10259 "Do not send outside local AS (well-known community)\n"
10260 "Do not advertise to any peer (well-known community)\n"
10261 "Do not export to next AS (well-known community)\n")
10262
10263/* old command */
10264ALIAS (show_ipv6_bgp_community,
10265 show_ipv6_bgp_community3_cmd,
10266 "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)",
10267 SHOW_STR
10268 IPV6_STR
10269 BGP_STR
10270 "Display routes matching the communities\n"
859d388e 10271 COMMUNITY_AANN_STR
718e3744 10272 "Do not send outside local AS (well-known community)\n"
10273 "Do not advertise to any peer (well-known community)\n"
10274 "Do not export to next AS (well-known community)\n"
859d388e 10275 COMMUNITY_AANN_STR
718e3744 10276 "Do not send outside local AS (well-known community)\n"
10277 "Do not advertise to any peer (well-known community)\n"
10278 "Do not export to next AS (well-known community)\n"
859d388e 10279 COMMUNITY_AANN_STR
718e3744 10280 "Do not send outside local AS (well-known community)\n"
10281 "Do not advertise to any peer (well-known community)\n"
10282 "Do not export to next AS (well-known community)\n")
10283
10284/* old command */
10285ALIAS (show_ipv6_bgp_community,
10286 show_ipv6_bgp_community4_cmd,
10287 "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)",
10288 SHOW_STR
10289 IPV6_STR
10290 BGP_STR
10291 "Display routes matching the communities\n"
859d388e 10292 COMMUNITY_AANN_STR
718e3744 10293 "Do not send outside local AS (well-known community)\n"
10294 "Do not advertise to any peer (well-known community)\n"
10295 "Do not export to next AS (well-known community)\n"
859d388e 10296 COMMUNITY_AANN_STR
718e3744 10297 "Do not send outside local AS (well-known community)\n"
10298 "Do not advertise to any peer (well-known community)\n"
10299 "Do not export to next AS (well-known community)\n"
859d388e 10300 COMMUNITY_AANN_STR
718e3744 10301 "Do not send outside local AS (well-known community)\n"
10302 "Do not advertise to any peer (well-known community)\n"
10303 "Do not export to next AS (well-known community)\n"
859d388e 10304 COMMUNITY_AANN_STR
718e3744 10305 "Do not send outside local AS (well-known community)\n"
10306 "Do not advertise to any peer (well-known community)\n"
10307 "Do not export to next AS (well-known community)\n")
10308
10309DEFUN (show_bgp_community_exact,
10310 show_bgp_community_exact_cmd,
10311 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10312 SHOW_STR
10313 BGP_STR
10314 "Display routes matching the communities\n"
859d388e 10315 COMMUNITY_AANN_STR
718e3744 10316 "Do not send outside local AS (well-known community)\n"
10317 "Do not advertise to any peer (well-known community)\n"
10318 "Do not export to next AS (well-known community)\n"
10319 "Exact match of the communities")
10320{
95cbbd2a 10321 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 10322}
10323
10324ALIAS (show_bgp_community_exact,
10325 show_bgp_ipv6_community_exact_cmd,
10326 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10327 SHOW_STR
10328 BGP_STR
10329 "Address family\n"
10330 "Display routes matching the communities\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"
10335 "Exact match of the communities")
10336
10337ALIAS (show_bgp_community_exact,
10338 show_bgp_community2_exact_cmd,
10339 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10340 SHOW_STR
10341 BGP_STR
10342 "Display routes matching the communities\n"
859d388e 10343 COMMUNITY_AANN_STR
718e3744 10344 "Do not send outside local AS (well-known community)\n"
10345 "Do not advertise to any peer (well-known community)\n"
10346 "Do not export to next AS (well-known community)\n"
859d388e 10347 COMMUNITY_AANN_STR
718e3744 10348 "Do not send outside local AS (well-known community)\n"
10349 "Do not advertise to any peer (well-known community)\n"
10350 "Do not export to next AS (well-known community)\n"
10351 "Exact match of the communities")
10352
10353ALIAS (show_bgp_community_exact,
10354 show_bgp_ipv6_community2_exact_cmd,
10355 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10356 SHOW_STR
10357 BGP_STR
10358 "Address family\n"
10359 "Display routes matching the communities\n"
859d388e 10360 COMMUNITY_AANN_STR
718e3744 10361 "Do not send outside local AS (well-known community)\n"
10362 "Do not advertise to any peer (well-known community)\n"
10363 "Do not export to next AS (well-known community)\n"
859d388e 10364 COMMUNITY_AANN_STR
718e3744 10365 "Do not send outside local AS (well-known community)\n"
10366 "Do not advertise to any peer (well-known community)\n"
10367 "Do not export to next AS (well-known community)\n"
10368 "Exact match of the communities")
10369
10370ALIAS (show_bgp_community_exact,
10371 show_bgp_community3_exact_cmd,
10372 "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",
10373 SHOW_STR
10374 BGP_STR
10375 "Display routes matching the communities\n"
859d388e 10376 COMMUNITY_AANN_STR
718e3744 10377 "Do not send outside local AS (well-known community)\n"
10378 "Do not advertise to any peer (well-known community)\n"
10379 "Do not export to next AS (well-known community)\n"
859d388e 10380 COMMUNITY_AANN_STR
718e3744 10381 "Do not send outside local AS (well-known community)\n"
10382 "Do not advertise to any peer (well-known community)\n"
10383 "Do not export to next AS (well-known community)\n"
859d388e 10384 COMMUNITY_AANN_STR
718e3744 10385 "Do not send outside local AS (well-known community)\n"
10386 "Do not advertise to any peer (well-known community)\n"
10387 "Do not export to next AS (well-known community)\n"
10388 "Exact match of the communities")
10389
10390ALIAS (show_bgp_community_exact,
10391 show_bgp_ipv6_community3_exact_cmd,
10392 "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",
10393 SHOW_STR
10394 BGP_STR
10395 "Address family\n"
10396 "Display routes matching the communities\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"
859d388e 10401 COMMUNITY_AANN_STR
718e3744 10402 "Do not send outside local AS (well-known community)\n"
10403 "Do not advertise to any peer (well-known community)\n"
10404 "Do not export to next AS (well-known community)\n"
859d388e 10405 COMMUNITY_AANN_STR
718e3744 10406 "Do not send outside local AS (well-known community)\n"
10407 "Do not advertise to any peer (well-known community)\n"
10408 "Do not export to next AS (well-known community)\n"
10409 "Exact match of the communities")
10410
10411ALIAS (show_bgp_community_exact,
10412 show_bgp_community4_exact_cmd,
10413 "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",
10414 SHOW_STR
10415 BGP_STR
10416 "Display routes matching the communities\n"
859d388e 10417 COMMUNITY_AANN_STR
718e3744 10418 "Do not send outside local AS (well-known community)\n"
10419 "Do not advertise to any peer (well-known community)\n"
10420 "Do not export to next AS (well-known community)\n"
859d388e 10421 COMMUNITY_AANN_STR
718e3744 10422 "Do not send outside local AS (well-known community)\n"
10423 "Do not advertise to any peer (well-known community)\n"
10424 "Do not export to next AS (well-known community)\n"
859d388e 10425 COMMUNITY_AANN_STR
718e3744 10426 "Do not send outside local AS (well-known community)\n"
10427 "Do not advertise to any peer (well-known community)\n"
10428 "Do not export to next AS (well-known community)\n"
859d388e 10429 COMMUNITY_AANN_STR
718e3744 10430 "Do not send outside local AS (well-known community)\n"
10431 "Do not advertise to any peer (well-known community)\n"
10432 "Do not export to next AS (well-known community)\n"
10433 "Exact match of the communities")
10434
10435ALIAS (show_bgp_community_exact,
10436 show_bgp_ipv6_community4_exact_cmd,
10437 "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",
10438 SHOW_STR
10439 BGP_STR
10440 "Address family\n"
10441 "Display routes matching the communities\n"
859d388e 10442 COMMUNITY_AANN_STR
718e3744 10443 "Do not send outside local AS (well-known community)\n"
10444 "Do not advertise to any peer (well-known community)\n"
10445 "Do not export to next AS (well-known community)\n"
859d388e 10446 COMMUNITY_AANN_STR
718e3744 10447 "Do not send outside local AS (well-known community)\n"
10448 "Do not advertise to any peer (well-known community)\n"
10449 "Do not export to next AS (well-known community)\n"
859d388e 10450 COMMUNITY_AANN_STR
718e3744 10451 "Do not send outside local AS (well-known community)\n"
10452 "Do not advertise to any peer (well-known community)\n"
10453 "Do not export to next AS (well-known community)\n"
859d388e 10454 COMMUNITY_AANN_STR
718e3744 10455 "Do not send outside local AS (well-known community)\n"
10456 "Do not advertise to any peer (well-known community)\n"
10457 "Do not export to next AS (well-known community)\n"
10458 "Exact match of the communities")
10459
10460/* old command */
10461DEFUN (show_ipv6_bgp_community_exact,
10462 show_ipv6_bgp_community_exact_cmd,
10463 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10464 SHOW_STR
10465 IPV6_STR
10466 BGP_STR
10467 "Display routes matching the communities\n"
859d388e 10468 COMMUNITY_AANN_STR
718e3744 10469 "Do not send outside local AS (well-known community)\n"
10470 "Do not advertise to any peer (well-known community)\n"
10471 "Do not export to next AS (well-known community)\n"
10472 "Exact match of the communities")
10473{
47e9b292 10474 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 10475 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 10476}
10477
10478/* old command */
10479ALIAS (show_ipv6_bgp_community_exact,
10480 show_ipv6_bgp_community2_exact_cmd,
10481 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10482 SHOW_STR
10483 IPV6_STR
10484 BGP_STR
10485 "Display routes matching the communities\n"
859d388e 10486 COMMUNITY_AANN_STR
718e3744 10487 "Do not send outside local AS (well-known community)\n"
10488 "Do not advertise to any peer (well-known community)\n"
10489 "Do not export to next AS (well-known community)\n"
859d388e 10490 COMMUNITY_AANN_STR
718e3744 10491 "Do not send outside local AS (well-known community)\n"
10492 "Do not advertise to any peer (well-known community)\n"
10493 "Do not export to next AS (well-known community)\n"
10494 "Exact match of the communities")
10495
10496/* old command */
10497ALIAS (show_ipv6_bgp_community_exact,
10498 show_ipv6_bgp_community3_exact_cmd,
10499 "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",
10500 SHOW_STR
10501 IPV6_STR
10502 BGP_STR
10503 "Display routes matching the communities\n"
859d388e 10504 COMMUNITY_AANN_STR
718e3744 10505 "Do not send outside local AS (well-known community)\n"
10506 "Do not advertise to any peer (well-known community)\n"
10507 "Do not export to next AS (well-known community)\n"
859d388e 10508 COMMUNITY_AANN_STR
718e3744 10509 "Do not send outside local AS (well-known community)\n"
10510 "Do not advertise to any peer (well-known community)\n"
10511 "Do not export to next AS (well-known community)\n"
859d388e 10512 COMMUNITY_AANN_STR
718e3744 10513 "Do not send outside local AS (well-known community)\n"
10514 "Do not advertise to any peer (well-known community)\n"
10515 "Do not export to next AS (well-known community)\n"
10516 "Exact match of the communities")
10517
10518/* old command */
10519ALIAS (show_ipv6_bgp_community_exact,
10520 show_ipv6_bgp_community4_exact_cmd,
10521 "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",
10522 SHOW_STR
10523 IPV6_STR
10524 BGP_STR
10525 "Display routes matching the communities\n"
859d388e 10526 COMMUNITY_AANN_STR
718e3744 10527 "Do not send outside local AS (well-known community)\n"
10528 "Do not advertise to any peer (well-known community)\n"
10529 "Do not export to next AS (well-known community)\n"
859d388e 10530 COMMUNITY_AANN_STR
718e3744 10531 "Do not send outside local AS (well-known community)\n"
10532 "Do not advertise to any peer (well-known community)\n"
10533 "Do not export to next AS (well-known community)\n"
859d388e 10534 COMMUNITY_AANN_STR
718e3744 10535 "Do not send outside local AS (well-known community)\n"
10536 "Do not advertise to any peer (well-known community)\n"
10537 "Do not export to next AS (well-known community)\n"
859d388e 10538 COMMUNITY_AANN_STR
718e3744 10539 "Do not send outside local AS (well-known community)\n"
10540 "Do not advertise to any peer (well-known community)\n"
10541 "Do not export to next AS (well-known community)\n"
10542 "Exact match of the communities")
10543
10544/* old command */
10545DEFUN (show_ipv6_mbgp_community,
10546 show_ipv6_mbgp_community_cmd,
10547 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10548 SHOW_STR
10549 IPV6_STR
10550 MBGP_STR
10551 "Display routes matching the communities\n"
859d388e 10552 COMMUNITY_AANN_STR
718e3744 10553 "Do not send outside local AS (well-known community)\n"
10554 "Do not advertise to any peer (well-known community)\n"
10555 "Do not export to next AS (well-known community)\n")
10556{
47e9b292 10557 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 10558 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
718e3744 10559}
10560
10561/* old command */
10562ALIAS (show_ipv6_mbgp_community,
10563 show_ipv6_mbgp_community2_cmd,
10564 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10565 SHOW_STR
10566 IPV6_STR
10567 MBGP_STR
10568 "Display routes matching the communities\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"
859d388e 10573 COMMUNITY_AANN_STR
718e3744 10574 "Do not send outside local AS (well-known community)\n"
10575 "Do not advertise to any peer (well-known community)\n"
10576 "Do not export to next AS (well-known community)\n")
10577
10578/* old command */
10579ALIAS (show_ipv6_mbgp_community,
10580 show_ipv6_mbgp_community3_cmd,
10581 "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)",
10582 SHOW_STR
10583 IPV6_STR
10584 MBGP_STR
10585 "Display routes matching the communities\n"
859d388e 10586 COMMUNITY_AANN_STR
718e3744 10587 "Do not send outside local AS (well-known community)\n"
10588 "Do not advertise to any peer (well-known community)\n"
10589 "Do not export to next AS (well-known community)\n"
859d388e 10590 COMMUNITY_AANN_STR
718e3744 10591 "Do not send outside local AS (well-known community)\n"
10592 "Do not advertise to any peer (well-known community)\n"
10593 "Do not export to next AS (well-known community)\n"
859d388e 10594 COMMUNITY_AANN_STR
718e3744 10595 "Do not send outside local AS (well-known community)\n"
10596 "Do not advertise to any peer (well-known community)\n"
10597 "Do not export to next AS (well-known community)\n")
10598
10599/* old command */
10600ALIAS (show_ipv6_mbgp_community,
10601 show_ipv6_mbgp_community4_cmd,
10602 "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)",
10603 SHOW_STR
10604 IPV6_STR
10605 MBGP_STR
10606 "Display routes matching the communities\n"
859d388e 10607 COMMUNITY_AANN_STR
718e3744 10608 "Do not send outside local AS (well-known community)\n"
10609 "Do not advertise to any peer (well-known community)\n"
10610 "Do not export to next AS (well-known community)\n"
859d388e 10611 COMMUNITY_AANN_STR
718e3744 10612 "Do not send outside local AS (well-known community)\n"
10613 "Do not advertise to any peer (well-known community)\n"
10614 "Do not export to next AS (well-known community)\n"
859d388e 10615 COMMUNITY_AANN_STR
718e3744 10616 "Do not send outside local AS (well-known community)\n"
10617 "Do not advertise to any peer (well-known community)\n"
10618 "Do not export to next AS (well-known community)\n"
859d388e 10619 COMMUNITY_AANN_STR
718e3744 10620 "Do not send outside local AS (well-known community)\n"
10621 "Do not advertise to any peer (well-known community)\n"
10622 "Do not export to next AS (well-known community)\n")
10623
10624/* old command */
10625DEFUN (show_ipv6_mbgp_community_exact,
10626 show_ipv6_mbgp_community_exact_cmd,
10627 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10628 SHOW_STR
10629 IPV6_STR
10630 MBGP_STR
10631 "Display routes matching the communities\n"
859d388e 10632 COMMUNITY_AANN_STR
718e3744 10633 "Do not send outside local AS (well-known community)\n"
10634 "Do not advertise to any peer (well-known community)\n"
10635 "Do not export to next AS (well-known community)\n"
10636 "Exact match of the communities")
10637{
47e9b292 10638 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 10639 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
718e3744 10640}
10641
10642/* old command */
10643ALIAS (show_ipv6_mbgp_community_exact,
10644 show_ipv6_mbgp_community2_exact_cmd,
10645 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10646 SHOW_STR
10647 IPV6_STR
10648 MBGP_STR
10649 "Display routes matching the communities\n"
859d388e 10650 COMMUNITY_AANN_STR
718e3744 10651 "Do not send outside local AS (well-known community)\n"
10652 "Do not advertise to any peer (well-known community)\n"
10653 "Do not export to next AS (well-known community)\n"
859d388e 10654 COMMUNITY_AANN_STR
718e3744 10655 "Do not send outside local AS (well-known community)\n"
10656 "Do not advertise to any peer (well-known community)\n"
10657 "Do not export to next AS (well-known community)\n"
10658 "Exact match of the communities")
10659
10660/* old command */
10661ALIAS (show_ipv6_mbgp_community_exact,
10662 show_ipv6_mbgp_community3_exact_cmd,
10663 "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",
10664 SHOW_STR
10665 IPV6_STR
10666 MBGP_STR
10667 "Display routes matching the communities\n"
859d388e 10668 COMMUNITY_AANN_STR
718e3744 10669 "Do not send outside local AS (well-known community)\n"
10670 "Do not advertise to any peer (well-known community)\n"
10671 "Do not export to next AS (well-known community)\n"
859d388e 10672 COMMUNITY_AANN_STR
718e3744 10673 "Do not send outside local AS (well-known community)\n"
10674 "Do not advertise to any peer (well-known community)\n"
10675 "Do not export to next AS (well-known community)\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/* old command */
10683ALIAS (show_ipv6_mbgp_community_exact,
10684 show_ipv6_mbgp_community4_exact_cmd,
10685 "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",
10686 SHOW_STR
10687 IPV6_STR
10688 MBGP_STR
10689 "Display routes matching the communities\n"
859d388e 10690 COMMUNITY_AANN_STR
718e3744 10691 "Do not send outside local AS (well-known community)\n"
10692 "Do not advertise to any peer (well-known community)\n"
10693 "Do not export to next AS (well-known community)\n"
859d388e 10694 COMMUNITY_AANN_STR
718e3744 10695 "Do not send outside local AS (well-known community)\n"
10696 "Do not advertise to any peer (well-known community)\n"
10697 "Do not export to next AS (well-known community)\n"
859d388e 10698 COMMUNITY_AANN_STR
718e3744 10699 "Do not send outside local AS (well-known community)\n"
10700 "Do not advertise to any peer (well-known community)\n"
10701 "Do not export to next AS (well-known community)\n"
859d388e 10702 COMMUNITY_AANN_STR
718e3744 10703 "Do not send outside local AS (well-known community)\n"
10704 "Do not advertise to any peer (well-known community)\n"
10705 "Do not export to next AS (well-known community)\n"
10706 "Exact match of the communities")
10707#endif /* HAVE_IPV6 */
6b0655a2 10708
94f2b392 10709static int
50ef26d4 10710bgp_show_community_list (struct vty *vty, const char *name,
10711 const char *com, int exact,
4c9641ba 10712 afi_t afi, safi_t safi)
718e3744 10713{
10714 struct community_list *list;
50ef26d4 10715 struct bgp *bgp = NULL;
10716
10717 if (name && !(bgp = bgp_lookup_by_name(name)))
10718 {
10719 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
10720 return CMD_WARNING;
10721 }
718e3744 10722
fee6e4e4 10723 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
718e3744 10724 if (list == NULL)
10725 {
10726 vty_out (vty, "%% %s is not a valid community-list name%s", com,
10727 VTY_NEWLINE);
10728 return CMD_WARNING;
10729 }
10730
50ef26d4 10731 return bgp_show (vty, bgp, afi, safi,
5a646650 10732 (exact ? bgp_show_type_community_list_exact :
b05a1c8b 10733 bgp_show_type_community_list), list, 0);
718e3744 10734}
10735
10736DEFUN (show_ip_bgp_community_list,
10737 show_ip_bgp_community_list_cmd,
fee6e4e4 10738 "show ip bgp community-list (<1-500>|WORD)",
718e3744 10739 SHOW_STR
10740 IP_STR
10741 BGP_STR
10742 "Display routes matching the community-list\n"
fee6e4e4 10743 "community-list number\n"
718e3744 10744 "community-list name\n")
10745{
50ef26d4 10746 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP, SAFI_UNICAST);
10747}
10748
8386ac43 10749DEFUN (show_ip_bgp_instance_community_list,
10750 show_ip_bgp_instance_community_list_cmd,
10751 "show ip bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
50ef26d4 10752 SHOW_STR
10753 IP_STR
10754 BGP_STR
8386ac43 10755 BGP_INSTANCE_HELP_STR
50ef26d4 10756 "Display routes matching the community-list\n"
10757 "community-list number\n"
10758 "community-list name\n")
10759{
10760 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP, SAFI_UNICAST);
718e3744 10761}
10762
10763DEFUN (show_ip_bgp_ipv4_community_list,
10764 show_ip_bgp_ipv4_community_list_cmd,
fee6e4e4 10765 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
718e3744 10766 SHOW_STR
10767 IP_STR
10768 BGP_STR
10769 "Address family\n"
10770 "Address Family modifier\n"
10771 "Address Family modifier\n"
10772 "Display routes matching the community-list\n"
fee6e4e4 10773 "community-list number\n"
718e3744 10774 "community-list name\n")
10775{
10776 if (strncmp (argv[0], "m", 1) == 0)
50ef26d4 10777 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_MULTICAST);
718e3744 10778
50ef26d4 10779 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_UNICAST);
718e3744 10780}
10781
10782DEFUN (show_ip_bgp_community_list_exact,
10783 show_ip_bgp_community_list_exact_cmd,
fee6e4e4 10784 "show ip bgp community-list (<1-500>|WORD) exact-match",
718e3744 10785 SHOW_STR
10786 IP_STR
10787 BGP_STR
10788 "Display routes matching the community-list\n"
fee6e4e4 10789 "community-list number\n"
718e3744 10790 "community-list name\n"
10791 "Exact match of the communities\n")
10792{
50ef26d4 10793 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP, SAFI_UNICAST);
718e3744 10794}
10795
10796DEFUN (show_ip_bgp_ipv4_community_list_exact,
10797 show_ip_bgp_ipv4_community_list_exact_cmd,
fee6e4e4 10798 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
718e3744 10799 SHOW_STR
10800 IP_STR
10801 BGP_STR
10802 "Address family\n"
10803 "Address Family modifier\n"
10804 "Address Family modifier\n"
10805 "Display routes matching the community-list\n"
fee6e4e4 10806 "community-list number\n"
718e3744 10807 "community-list name\n"
10808 "Exact match of the communities\n")
10809{
10810 if (strncmp (argv[0], "m", 1) == 0)
50ef26d4 10811 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_MULTICAST);
718e3744 10812
50ef26d4 10813 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_UNICAST);
718e3744 10814}
10815
10816#ifdef HAVE_IPV6
10817DEFUN (show_bgp_community_list,
10818 show_bgp_community_list_cmd,
fee6e4e4 10819 "show bgp community-list (<1-500>|WORD)",
718e3744 10820 SHOW_STR
10821 BGP_STR
10822 "Display routes matching the community-list\n"
fee6e4e4 10823 "community-list number\n"
718e3744 10824 "community-list name\n")
10825{
50ef26d4 10826 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
718e3744 10827}
10828
10829ALIAS (show_bgp_community_list,
10830 show_bgp_ipv6_community_list_cmd,
fee6e4e4 10831 "show bgp ipv6 community-list (<1-500>|WORD)",
718e3744 10832 SHOW_STR
10833 BGP_STR
10834 "Address family\n"
10835 "Display routes matching the community-list\n"
fee6e4e4 10836 "community-list number\n"
e8e1946e 10837 "community-list name\n")
718e3744 10838
10839/* old command */
10840DEFUN (show_ipv6_bgp_community_list,
10841 show_ipv6_bgp_community_list_cmd,
10842 "show ipv6 bgp community-list WORD",
10843 SHOW_STR
10844 IPV6_STR
10845 BGP_STR
10846 "Display routes matching the community-list\n"
10847 "community-list name\n")
10848{
47e9b292 10849 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 10850 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
718e3744 10851}
10852
10853/* old command */
10854DEFUN (show_ipv6_mbgp_community_list,
10855 show_ipv6_mbgp_community_list_cmd,
10856 "show ipv6 mbgp community-list WORD",
10857 SHOW_STR
10858 IPV6_STR
10859 MBGP_STR
10860 "Display routes matching the community-list\n"
10861 "community-list name\n")
10862{
47e9b292 10863 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 10864 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
718e3744 10865}
10866
10867DEFUN (show_bgp_community_list_exact,
10868 show_bgp_community_list_exact_cmd,
fee6e4e4 10869 "show bgp community-list (<1-500>|WORD) exact-match",
718e3744 10870 SHOW_STR
10871 BGP_STR
10872 "Display routes matching the community-list\n"
fee6e4e4 10873 "community-list number\n"
718e3744 10874 "community-list name\n"
10875 "Exact match of the communities\n")
10876{
50ef26d4 10877 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
718e3744 10878}
10879
10880ALIAS (show_bgp_community_list_exact,
10881 show_bgp_ipv6_community_list_exact_cmd,
fee6e4e4 10882 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
718e3744 10883 SHOW_STR
10884 BGP_STR
10885 "Address family\n"
10886 "Display routes matching the community-list\n"
fee6e4e4 10887 "community-list number\n"
718e3744 10888 "community-list name\n"
10889 "Exact match of the communities\n")
10890
10891/* old command */
10892DEFUN (show_ipv6_bgp_community_list_exact,
10893 show_ipv6_bgp_community_list_exact_cmd,
10894 "show ipv6 bgp community-list WORD exact-match",
10895 SHOW_STR
10896 IPV6_STR
10897 BGP_STR
10898 "Display routes matching the community-list\n"
10899 "community-list name\n"
10900 "Exact match of the communities\n")
10901{
47e9b292 10902 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 10903 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
718e3744 10904}
10905
10906/* old command */
10907DEFUN (show_ipv6_mbgp_community_list_exact,
10908 show_ipv6_mbgp_community_list_exact_cmd,
10909 "show ipv6 mbgp community-list WORD exact-match",
10910 SHOW_STR
10911 IPV6_STR
10912 MBGP_STR
10913 "Display routes matching the community-list\n"
10914 "community-list name\n"
10915 "Exact match of the communities\n")
10916{
47e9b292 10917 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 10918 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
718e3744 10919}
10920#endif /* HAVE_IPV6 */
6b0655a2 10921
94f2b392 10922static int
50ef26d4 10923bgp_show_prefix_longer (struct vty *vty, const char *name,
10924 const char *prefix, afi_t afi,
718e3744 10925 safi_t safi, enum bgp_show_type type)
10926{
10927 int ret;
10928 struct prefix *p;
50ef26d4 10929 struct bgp *bgp = NULL;
10930
10931 if (name && !(bgp = bgp_lookup_by_name(name)))
10932 {
10933 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
10934 return CMD_WARNING;
10935 }
718e3744 10936
10937 p = prefix_new();
10938
10939 ret = str2prefix (prefix, p);
10940 if (! ret)
10941 {
10942 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
10943 return CMD_WARNING;
10944 }
10945
50ef26d4 10946 ret = bgp_show (vty, bgp, afi, safi, type, p, 0);
5a646650 10947 prefix_free(p);
10948 return ret;
718e3744 10949}
10950
10951DEFUN (show_ip_bgp_prefix_longer,
10952 show_ip_bgp_prefix_longer_cmd,
10953 "show ip bgp A.B.C.D/M longer-prefixes",
10954 SHOW_STR
10955 IP_STR
10956 BGP_STR
10957 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10958 "Display route and more specific routes\n")
10959{
50ef26d4 10960 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
10961 bgp_show_type_prefix_longer);
10962}
10963
8386ac43 10964DEFUN (show_ip_bgp_instance_prefix_longer,
10965 show_ip_bgp_instance_prefix_longer_cmd,
10966 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M longer-prefixes",
50ef26d4 10967 SHOW_STR
10968 IP_STR
10969 BGP_STR
8386ac43 10970 BGP_INSTANCE_HELP_STR
50ef26d4 10971 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10972 "Display route and more specific routes\n")
10973{
10974 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
718e3744 10975 bgp_show_type_prefix_longer);
10976}
10977
10978DEFUN (show_ip_bgp_flap_prefix_longer,
10979 show_ip_bgp_flap_prefix_longer_cmd,
10980 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
10981 SHOW_STR
10982 IP_STR
10983 BGP_STR
10984 "Display flap statistics of routes\n"
10985 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10986 "Display route and more specific routes\n")
10987{
50ef26d4 10988 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 10989 bgp_show_type_flap_prefix_longer);
10990}
10991
81304aaf
B
10992ALIAS (show_ip_bgp_flap_prefix_longer,
10993 show_ip_bgp_damp_flap_prefix_longer_cmd,
10994 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
10995 SHOW_STR
10996 IP_STR
10997 BGP_STR
10998 "Display detailed information about dampening\n"
10999 "Display flap statistics of routes\n"
11000 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11001 "Display route and more specific routes\n")
11002
718e3744 11003DEFUN (show_ip_bgp_ipv4_prefix_longer,
11004 show_ip_bgp_ipv4_prefix_longer_cmd,
11005 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11006 SHOW_STR
11007 IP_STR
11008 BGP_STR
11009 "Address family\n"
11010 "Address Family modifier\n"
11011 "Address Family modifier\n"
11012 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11013 "Display route and more specific routes\n")
11014{
11015 if (strncmp (argv[0], "m", 1) == 0)
50ef26d4 11016 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
718e3744 11017 bgp_show_type_prefix_longer);
11018
50ef26d4 11019 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
718e3744 11020 bgp_show_type_prefix_longer);
11021}
11022
11023DEFUN (show_ip_bgp_flap_address,
11024 show_ip_bgp_flap_address_cmd,
11025 "show ip bgp flap-statistics A.B.C.D",
11026 SHOW_STR
11027 IP_STR
11028 BGP_STR
11029 "Display flap statistics of routes\n"
11030 "Network in the BGP routing table to display\n")
11031{
50ef26d4 11032 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 11033 bgp_show_type_flap_address);
11034}
11035
81304aaf
B
11036ALIAS (show_ip_bgp_flap_address,
11037 show_ip_bgp_damp_flap_address_cmd,
11038 "show ip bgp dampening flap-statistics A.B.C.D",
11039 SHOW_STR
11040 IP_STR
11041 BGP_STR
11042 "Display detailed information about dampening\n"
11043 "Display flap statistics of routes\n"
11044 "Network in the BGP routing table to display\n")
11045
718e3744 11046DEFUN (show_ip_bgp_flap_prefix,
11047 show_ip_bgp_flap_prefix_cmd,
11048 "show ip bgp flap-statistics A.B.C.D/M",
11049 SHOW_STR
11050 IP_STR
11051 BGP_STR
11052 "Display flap statistics of routes\n"
11053 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11054{
50ef26d4 11055 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 11056 bgp_show_type_flap_prefix);
11057}
81304aaf
B
11058
11059ALIAS (show_ip_bgp_flap_prefix,
11060 show_ip_bgp_damp_flap_prefix_cmd,
11061 "show ip bgp dampening flap-statistics A.B.C.D/M",
11062 SHOW_STR
11063 IP_STR
11064 BGP_STR
11065 "Display detailed information about dampening\n"
11066 "Display flap statistics of routes\n"
11067 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11068
718e3744 11069#ifdef HAVE_IPV6
11070DEFUN (show_bgp_prefix_longer,
11071 show_bgp_prefix_longer_cmd,
11072 "show bgp X:X::X:X/M longer-prefixes",
11073 SHOW_STR
11074 BGP_STR
11075 "IPv6 prefix <network>/<length>\n"
11076 "Display route and more specific routes\n")
11077{
50ef26d4 11078 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 11079 bgp_show_type_prefix_longer);
11080}
11081
11082ALIAS (show_bgp_prefix_longer,
11083 show_bgp_ipv6_prefix_longer_cmd,
11084 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11085 SHOW_STR
11086 BGP_STR
11087 "Address family\n"
11088 "IPv6 prefix <network>/<length>\n"
11089 "Display route and more specific routes\n")
11090
11091/* old command */
11092DEFUN (show_ipv6_bgp_prefix_longer,
11093 show_ipv6_bgp_prefix_longer_cmd,
11094 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11095 SHOW_STR
11096 IPV6_STR
11097 BGP_STR
11098 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11099 "Display route and more specific routes\n")
11100{
47e9b292 11101 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 11102 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 11103 bgp_show_type_prefix_longer);
11104}
11105
11106/* old command */
11107DEFUN (show_ipv6_mbgp_prefix_longer,
11108 show_ipv6_mbgp_prefix_longer_cmd,
11109 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11110 SHOW_STR
11111 IPV6_STR
11112 MBGP_STR
11113 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11114 "Display route and more specific routes\n")
11115{
47e9b292 11116 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 11117 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
718e3744 11118 bgp_show_type_prefix_longer);
11119}
11120#endif /* HAVE_IPV6 */
bb46e94f 11121
94f2b392 11122static struct peer *
fd79ac91 11123peer_lookup_in_view (struct vty *vty, const char *view_name,
856ca177 11124 const char *ip_str, u_char use_json)
bb46e94f 11125{
11126 int ret;
11127 struct bgp *bgp;
11128 struct peer *peer;
11129 union sockunion su;
11130
11131 /* BGP structure lookup. */
11132 if (view_name)
11133 {
11134 bgp = bgp_lookup_by_name (view_name);
11135 if (! bgp)
11136 {
856ca177
MS
11137 if (use_json)
11138 {
11139 json_object *json_no = NULL;
11140 json_no = json_object_new_object();
11141 json_object_string_add(json_no, "warning", "Can't find BGP view");
11142 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11143 json_object_free(json_no);
11144 }
11145 else
6aeb9e78 11146 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
bb46e94f 11147 return NULL;
11148 }
11149 }
5228ad27 11150 else
bb46e94f 11151 {
11152 bgp = bgp_get_default ();
11153 if (! bgp)
11154 {
856ca177
MS
11155 if (use_json)
11156 {
11157 json_object *json_no = NULL;
11158 json_no = json_object_new_object();
11159 json_object_string_add(json_no, "warning", "No BGP process configured");
11160 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11161 json_object_free(json_no);
11162 }
11163 else
11164 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
bb46e94f 11165 return NULL;
11166 }
11167 }
11168
11169 /* Get peer sockunion. */
11170 ret = str2sockunion (ip_str, &su);
11171 if (ret < 0)
11172 {
a80beece
DS
11173 peer = peer_lookup_by_conf_if (bgp, ip_str);
11174 if (!peer)
11175 {
04b6bdc0
DW
11176 peer = peer_lookup_by_hostname(bgp, ip_str);
11177
11178 if (!peer)
856ca177 11179 {
04b6bdc0
DW
11180 if (use_json)
11181 {
11182 json_object *json_no = NULL;
11183 json_no = json_object_new_object();
11184 json_object_string_add(json_no, "malformedAddressOrName", ip_str);
11185 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11186 json_object_free(json_no);
11187 }
11188 else
11189 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
11190 return NULL;
856ca177 11191 }
a80beece
DS
11192 }
11193 return peer;
bb46e94f 11194 }
11195
11196 /* Peer structure lookup. */
11197 peer = peer_lookup (bgp, &su);
11198 if (! peer)
11199 {
856ca177
MS
11200 if (use_json)
11201 {
11202 json_object *json_no = NULL;
11203 json_no = json_object_new_object();
11204 json_object_string_add(json_no, "warning","No such neighbor");
11205 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11206 json_object_free(json_no);
11207 }
11208 else
11209 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
bb46e94f 11210 return NULL;
11211 }
11212
11213 return peer;
11214}
6b0655a2 11215
2815e61f
PJ
11216enum bgp_stats
11217{
11218 BGP_STATS_MAXBITLEN = 0,
11219 BGP_STATS_RIB,
11220 BGP_STATS_PREFIXES,
11221 BGP_STATS_TOTPLEN,
11222 BGP_STATS_UNAGGREGATEABLE,
11223 BGP_STATS_MAX_AGGREGATEABLE,
11224 BGP_STATS_AGGREGATES,
11225 BGP_STATS_SPACE,
11226 BGP_STATS_ASPATH_COUNT,
11227 BGP_STATS_ASPATH_MAXHOPS,
11228 BGP_STATS_ASPATH_TOTHOPS,
11229 BGP_STATS_ASPATH_MAXSIZE,
11230 BGP_STATS_ASPATH_TOTSIZE,
11231 BGP_STATS_ASN_HIGHEST,
11232 BGP_STATS_MAX,
11233};
11234
11235static const char *table_stats_strs[] =
11236{
11237 [BGP_STATS_PREFIXES] = "Total Prefixes",
11238 [BGP_STATS_TOTPLEN] = "Average prefix length",
11239 [BGP_STATS_RIB] = "Total Advertisements",
11240 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11241 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11242 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11243 [BGP_STATS_SPACE] = "Address space advertised",
11244 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11245 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11246 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11247 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11248 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11249 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11250 [BGP_STATS_MAX] = NULL,
11251};
11252
11253struct bgp_table_stats
11254{
11255 struct bgp_table *table;
11256 unsigned long long counts[BGP_STATS_MAX];
11257};
11258
11259#if 0
11260#define TALLY_SIGFIG 100000
11261static unsigned long
11262ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11263{
11264 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11265 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11266 unsigned long ret = newtot / count;
11267
11268 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11269 return ret + 1;
11270 else
11271 return ret;
11272}
11273#endif
11274
11275static int
11276bgp_table_stats_walker (struct thread *t)
11277{
11278 struct bgp_node *rn;
11279 struct bgp_node *top;
11280 struct bgp_table_stats *ts = THREAD_ARG (t);
11281 unsigned int space = 0;
11282
53d9f67a
PJ
11283 if (!(top = bgp_table_top (ts->table)))
11284 return 0;
2815e61f
PJ
11285
11286 switch (top->p.family)
11287 {
11288 case AF_INET:
11289 space = IPV4_MAX_BITLEN;
11290 break;
11291 case AF_INET6:
11292 space = IPV6_MAX_BITLEN;
11293 break;
11294 }
11295
11296 ts->counts[BGP_STATS_MAXBITLEN] = space;
11297
11298 for (rn = top; rn; rn = bgp_route_next (rn))
11299 {
11300 struct bgp_info *ri;
67174041 11301 struct bgp_node *prn = bgp_node_parent_nolock (rn);
2815e61f
PJ
11302 unsigned int rinum = 0;
11303
11304 if (rn == top)
11305 continue;
11306
11307 if (!rn->info)
11308 continue;
11309
11310 ts->counts[BGP_STATS_PREFIXES]++;
11311 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11312
11313#if 0
11314 ts->counts[BGP_STATS_AVGPLEN]
11315 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11316 ts->counts[BGP_STATS_AVGPLEN],
11317 rn->p.prefixlen);
11318#endif
11319
11320 /* check if the prefix is included by any other announcements */
11321 while (prn && !prn->info)
67174041 11322 prn = bgp_node_parent_nolock (prn);
2815e61f
PJ
11323
11324 if (prn == NULL || prn == top)
8383a9bd
PJ
11325 {
11326 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11327 /* announced address space */
11328 if (space)
11329 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11330 }
2815e61f
PJ
11331 else if (prn->info)
11332 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11333
2815e61f
PJ
11334 for (ri = rn->info; ri; ri = ri->next)
11335 {
11336 rinum++;
11337 ts->counts[BGP_STATS_RIB]++;
11338
11339 if (ri->attr &&
11340 (CHECK_FLAG (ri->attr->flag,
11341 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11342 ts->counts[BGP_STATS_AGGREGATES]++;
11343
11344 /* as-path stats */
11345 if (ri->attr && ri->attr->aspath)
11346 {
11347 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11348 unsigned int size = aspath_size (ri->attr->aspath);
11349 as_t highest = aspath_highest (ri->attr->aspath);
11350
11351 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11352
11353 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11354 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11355
11356 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11357 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11358
11359 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11360 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11361#if 0
11362 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11363 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11364 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11365 hops);
11366 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11367 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11368 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11369 size);
11370#endif
11371 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11372 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11373 }
11374 }
11375 }
11376 return 0;
11377}
11378
11379static int
11380bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11381{
11382 struct bgp_table_stats ts;
11383 unsigned int i;
11384
11385 if (!bgp->rib[afi][safi])
11386 {
06da0daf
DS
11387 vty_out (vty, "%% No RIB exist's for the AFI(%d)/SAFI(%d)%s",
11388 afi, safi, VTY_NEWLINE);
2815e61f
PJ
11389 return CMD_WARNING;
11390 }
11391
11392 memset (&ts, 0, sizeof (ts));
11393 ts.table = bgp->rib[afi][safi];
87d4a781 11394 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
bb46e94f 11395
2815e61f
PJ
11396 vty_out (vty, "BGP %s RIB statistics%s%s",
11397 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11398
11399 for (i = 0; i < BGP_STATS_MAX; i++)
11400 {
11401 if (!table_stats_strs[i])
11402 continue;
11403
11404 switch (i)
11405 {
11406#if 0
11407 case BGP_STATS_ASPATH_AVGHOPS:
11408 case BGP_STATS_ASPATH_AVGSIZE:
11409 case BGP_STATS_AVGPLEN:
11410 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11411 vty_out (vty, "%12.2f",
11412 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11413 break;
11414#endif
11415 case BGP_STATS_ASPATH_TOTHOPS:
11416 case BGP_STATS_ASPATH_TOTSIZE:
11417 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11418 vty_out (vty, "%12.2f",
11419 ts.counts[i] ?
11420 (float)ts.counts[i] /
11421 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11422 : 0);
11423 break;
11424 case BGP_STATS_TOTPLEN:
11425 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11426 vty_out (vty, "%12.2f",
11427 ts.counts[i] ?
11428 (float)ts.counts[i] /
11429 (float)ts.counts[BGP_STATS_PREFIXES]
11430 : 0);
11431 break;
11432 case BGP_STATS_SPACE:
11433 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11434 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11435 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11436 break;
30a2231a 11437 vty_out (vty, "%30s: ", "%% announced ");
2815e61f
PJ
11438 vty_out (vty, "%12.2f%s",
11439 100 * (float)ts.counts[BGP_STATS_SPACE] /
56395af7 11440 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
2815e61f
PJ
11441 VTY_NEWLINE);
11442 vty_out (vty, "%30s: ", "/8 equivalent ");
11443 vty_out (vty, "%12.2f%s",
11444 (float)ts.counts[BGP_STATS_SPACE] /
11445 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11446 VTY_NEWLINE);
11447 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11448 break;
11449 vty_out (vty, "%30s: ", "/24 equivalent ");
11450 vty_out (vty, "%12.2f",
11451 (float)ts.counts[BGP_STATS_SPACE] /
11452 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11453 break;
11454 default:
11455 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11456 vty_out (vty, "%12llu", ts.counts[i]);
11457 }
11458
11459 vty_out (vty, "%s", VTY_NEWLINE);
11460 }
11461 return CMD_SUCCESS;
11462}
11463
11464static int
11465bgp_table_stats_vty (struct vty *vty, const char *name,
11466 const char *afi_str, const char *safi_str)
11467{
11468 struct bgp *bgp;
11469 afi_t afi;
11470 safi_t safi;
11471
11472 if (name)
11473 bgp = bgp_lookup_by_name (name);
11474 else
11475 bgp = bgp_get_default ();
11476
11477 if (!bgp)
11478 {
11479 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
11480 return CMD_WARNING;
11481 }
11482 if (strncmp (afi_str, "ipv", 3) == 0)
11483 {
11484 if (strncmp (afi_str, "ipv4", 4) == 0)
11485 afi = AFI_IP;
11486 else if (strncmp (afi_str, "ipv6", 4) == 0)
11487 afi = AFI_IP6;
11488 else
11489 {
11490 vty_out (vty, "%% Invalid address family %s%s",
11491 afi_str, VTY_NEWLINE);
11492 return CMD_WARNING;
11493 }
11494 if (strncmp (safi_str, "m", 1) == 0)
11495 safi = SAFI_MULTICAST;
11496 else if (strncmp (safi_str, "u", 1) == 0)
11497 safi = SAFI_UNICAST;
587ff0fd
LB
11498 else if (strncmp (safi_str, "e", 1) == 0)
11499 safi = SAFI_ENCAP;
42e6d745 11500 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
06da0daf 11501 safi = SAFI_MPLS_VPN;
2815e61f
PJ
11502 else
11503 {
11504 vty_out (vty, "%% Invalid subsequent address family %s%s",
11505 safi_str, VTY_NEWLINE);
587ff0fd
LB
11506 return CMD_WARNING;
11507 }
2815e61f
PJ
11508 }
11509 else
11510 {
587ff0fd 11511 vty_out (vty, "%% Invalid address family \"%s\"%s",
2815e61f
PJ
11512 afi_str, VTY_NEWLINE);
11513 return CMD_WARNING;
11514 }
11515
2815e61f
PJ
11516 return bgp_table_stats (vty, bgp, afi, safi);
11517}
11518
11519DEFUN (show_bgp_statistics,
11520 show_bgp_statistics_cmd,
587ff0fd 11521 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
2815e61f
PJ
11522 SHOW_STR
11523 BGP_STR
11524 "Address family\n"
11525 "Address family\n"
11526 "Address Family modifier\n"
11527 "Address Family modifier\n"
587ff0fd
LB
11528 "Address Family modifier\n"
11529 "Address Family modifier\n"
2815e61f
PJ
11530 "BGP RIB advertisement statistics\n")
11531{
11532 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11533}
11534
2815e61f
PJ
11535DEFUN (show_bgp_statistics_view,
11536 show_bgp_statistics_view_cmd,
587ff0fd 11537 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast|vpn|encap) statistics",
2815e61f
PJ
11538 SHOW_STR
11539 BGP_STR
8386ac43 11540 BGP_INSTANCE_HELP_STR
2815e61f
PJ
11541 "Address family\n"
11542 "Address family\n"
11543 "Address Family modifier\n"
11544 "Address Family modifier\n"
587ff0fd
LB
11545 "Address Family modifier\n"
11546 "Address Family modifier\n"
2815e61f
PJ
11547 "BGP RIB advertisement statistics\n")
11548{
6aeb9e78 11549 return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]);
2815e61f
PJ
11550}
11551
ff7924f6
PJ
11552enum bgp_pcounts
11553{
11554 PCOUNT_ADJ_IN = 0,
11555 PCOUNT_DAMPED,
11556 PCOUNT_REMOVED,
11557 PCOUNT_HISTORY,
11558 PCOUNT_STALE,
11559 PCOUNT_VALID,
11560 PCOUNT_ALL,
11561 PCOUNT_COUNTED,
11562 PCOUNT_PFCNT, /* the figure we display to users */
11563 PCOUNT_MAX,
11564};
11565
11566static const char *pcount_strs[] =
11567{
11568 [PCOUNT_ADJ_IN] = "Adj-in",
11569 [PCOUNT_DAMPED] = "Damped",
11570 [PCOUNT_REMOVED] = "Removed",
11571 [PCOUNT_HISTORY] = "History",
11572 [PCOUNT_STALE] = "Stale",
11573 [PCOUNT_VALID] = "Valid",
11574 [PCOUNT_ALL] = "All RIB",
11575 [PCOUNT_COUNTED] = "PfxCt counted",
11576 [PCOUNT_PFCNT] = "Useable",
11577 [PCOUNT_MAX] = NULL,
11578};
11579
2815e61f
PJ
11580struct peer_pcounts
11581{
11582 unsigned int count[PCOUNT_MAX];
11583 const struct peer *peer;
11584 const struct bgp_table *table;
11585};
11586
ff7924f6 11587static int
2815e61f 11588bgp_peer_count_walker (struct thread *t)
ff7924f6
PJ
11589{
11590 struct bgp_node *rn;
2815e61f
PJ
11591 struct peer_pcounts *pc = THREAD_ARG (t);
11592 const struct peer *peer = pc->peer;
ff7924f6 11593
2815e61f 11594 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
ff7924f6
PJ
11595 {
11596 struct bgp_adj_in *ain;
2815e61f 11597 struct bgp_info *ri;
ff7924f6
PJ
11598
11599 for (ain = rn->adj_in; ain; ain = ain->next)
11600 if (ain->peer == peer)
2815e61f 11601 pc->count[PCOUNT_ADJ_IN]++;
ff7924f6 11602
ff7924f6
PJ
11603 for (ri = rn->info; ri; ri = ri->next)
11604 {
11605 char buf[SU_ADDRSTRLEN];
11606
11607 if (ri->peer != peer)
11608 continue;
11609
2815e61f 11610 pc->count[PCOUNT_ALL]++;
ff7924f6
PJ
11611
11612 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
2815e61f 11613 pc->count[PCOUNT_DAMPED]++;
ff7924f6 11614 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2815e61f 11615 pc->count[PCOUNT_HISTORY]++;
ff7924f6 11616 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
2815e61f 11617 pc->count[PCOUNT_REMOVED]++;
ff7924f6 11618 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2815e61f 11619 pc->count[PCOUNT_STALE]++;
ff7924f6 11620 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
2815e61f 11621 pc->count[PCOUNT_VALID]++;
1a392d46 11622 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2815e61f 11623 pc->count[PCOUNT_PFCNT]++;
ff7924f6
PJ
11624
11625 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
11626 {
2815e61f 11627 pc->count[PCOUNT_COUNTED]++;
1a392d46 11628 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 11629 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
ff7924f6
PJ
11630 peer->host,
11631 inet_ntop(rn->p.family, &rn->p.u.prefix,
11632 buf, SU_ADDRSTRLEN),
11633 rn->p.prefixlen,
11634 ri->flags);
11635 }
11636 else
11637 {
1a392d46 11638 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 11639 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
ff7924f6
PJ
11640 peer->host,
11641 inet_ntop(rn->p.family, &rn->p.u.prefix,
11642 buf, SU_ADDRSTRLEN),
11643 rn->p.prefixlen,
11644 ri->flags);
11645 }
11646 }
11647 }
2815e61f
PJ
11648 return 0;
11649}
ff7924f6 11650
2815e61f 11651static int
856ca177 11652bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json)
2815e61f
PJ
11653{
11654 struct peer_pcounts pcounts = { .peer = peer };
11655 unsigned int i;
856ca177
MS
11656 json_object *json = NULL;
11657 json_object *json_loop = NULL;
11658
11659 if (use_json)
11660 {
11661 json = json_object_new_object();
11662 json_loop = json_object_new_object();
11663 }
2815e61f
PJ
11664
11665 if (!peer || !peer->bgp || !peer->afc[afi][safi]
11666 || !peer->bgp->rib[afi][safi])
11667 {
856ca177
MS
11668 if (use_json)
11669 {
11670 json_object_string_add(json, "warning", "No such neighbor or address family");
11671 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11672 json_object_free(json);
11673 }
11674 else
11675 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11676
2815e61f
PJ
11677 return CMD_WARNING;
11678 }
11679
11680 memset (&pcounts, 0, sizeof(pcounts));
11681 pcounts.peer = peer;
11682 pcounts.table = peer->bgp->rib[afi][safi];
11683
11684 /* in-place call via thread subsystem so as to record execution time
856ca177
MS
11685 * * stats for the thread-walk (i.e. ensure this can't be blamed on
11686 * * on just vty_read()).
11687 * */
87d4a781 11688 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
6410e93a 11689
856ca177
MS
11690 if (use_json)
11691 {
11692 json_object_string_add(json, "prefixCountsFor", peer->host);
11693 json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi));
11694 json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]);
11695
11696 for (i = 0; i < PCOUNT_MAX; i++)
11697 json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]);
ff7924f6 11698
856ca177 11699 json_object_object_add(json, "ribTableWalkCounters", json_loop);
ff7924f6 11700
856ca177
MS
11701 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
11702 {
11703 json_object_string_add(json, "pfxctDriftFor", peer->host);
11704 json_object_string_add(json, "recommended", "Please report this bug, with the above command output");
11705 }
11706 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11707 json_object_free(json);
11708 }
11709 else
ff7924f6 11710 {
04b6bdc0
DW
11711
11712 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
11713 {
11714 vty_out (vty, "Prefix counts for %s/%s, %s%s",
11715 peer->hostname, peer->host, afi_safi_print (afi, safi),
11716 VTY_NEWLINE);
11717 }
11718 else
11719 {
11720 vty_out (vty, "Prefix counts for %s, %s%s",
11721 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
11722 }
11723
856ca177
MS
11724 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
11725 vty_out (vty, "%sCounts from RIB table walk:%s%s",
11726 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
11727
11728 for (i = 0; i < PCOUNT_MAX; i++)
11729 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
11730
11731 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
11732 {
11733 vty_out (vty, "%s [pcount] PfxCt drift!%s",
11734 peer->host, VTY_NEWLINE);
11735 vty_out (vty, "Please report this bug, with the above command output%s",
11736 VTY_NEWLINE);
11737 }
ff7924f6
PJ
11738 }
11739
11740 return CMD_SUCCESS;
11741}
11742
11743DEFUN (show_ip_bgp_neighbor_prefix_counts,
11744 show_ip_bgp_neighbor_prefix_counts_cmd,
856ca177 11745 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
11746 SHOW_STR
11747 IP_STR
11748 BGP_STR
11749 "Detailed information on TCP and BGP neighbor connections\n"
11750 "Neighbor to display information about\n"
11751 "Neighbor to display information about\n"
a80beece 11752 "Neighbor on bgp configured interface\n"
856ca177
MS
11753 "Display detailed prefix count information\n"
11754 "JavaScript Object Notation\n")
ff7924f6
PJ
11755{
11756 struct peer *peer;
db7c8528 11757 u_char uj = use_json(argc, argv);
ff7924f6 11758
db7c8528 11759 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
ff7924f6
PJ
11760 if (! peer)
11761 return CMD_WARNING;
11762
db7c8528 11763 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
ff7924f6
PJ
11764}
11765
8386ac43 11766DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
11767 show_ip_bgp_instance_neighbor_prefix_counts_cmd,
11768 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
50ef26d4 11769 SHOW_STR
11770 IP_STR
11771 BGP_STR
8386ac43 11772 BGP_INSTANCE_HELP_STR
50ef26d4 11773 "Detailed information on TCP and BGP neighbor connections\n"
11774 "Neighbor to display information about\n"
11775 "Neighbor to display information about\n"
11776 "Neighbor on bgp configured interface\n"
11777 "Display detailed prefix count information\n"
11778 "JavaScript Object Notation\n")
11779{
11780 struct peer *peer;
11781 u_char uj = use_json(argc, argv);
11782
11783 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
11784 if (! peer)
11785 return CMD_WARNING;
11786
11787 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
11788}
11789
ff7924f6
PJ
11790DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
11791 show_bgp_ipv6_neighbor_prefix_counts_cmd,
856ca177 11792 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
11793 SHOW_STR
11794 BGP_STR
11795 "Address family\n"
11796 "Detailed information on TCP and BGP neighbor connections\n"
11797 "Neighbor to display information about\n"
11798 "Neighbor to display information about\n"
a80beece 11799 "Neighbor on bgp configured interface\n"
856ca177
MS
11800 "Display detailed prefix count information\n"
11801 "JavaScript Object Notation\n")
ff7924f6
PJ
11802{
11803 struct peer *peer;
db7c8528 11804 u_char uj = use_json(argc, argv);
856ca177 11805
db7c8528 11806 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
ff7924f6
PJ
11807 if (! peer)
11808 return CMD_WARNING;
11809
db7c8528 11810 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
ff7924f6
PJ
11811}
11812
8386ac43 11813DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts,
11814 show_bgp_instance_ipv6_neighbor_prefix_counts_cmd,
11815 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
50ef26d4 11816 SHOW_STR
11817 BGP_STR
8386ac43 11818 BGP_INSTANCE_HELP_STR
50ef26d4 11819 "Address family\n"
11820 "Detailed information on TCP and BGP neighbor connections\n"
11821 "Neighbor to display information about\n"
11822 "Neighbor to display information about\n"
11823 "Neighbor on bgp configured interface\n"
11824 "Display detailed prefix count information\n"
11825 "JavaScript Object Notation\n")
11826{
11827 struct peer *peer;
11828 u_char uj = use_json(argc, argv);
11829
11830 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
11831 if (! peer)
11832 return CMD_WARNING;
11833
11834 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
11835}
11836
ff7924f6
PJ
11837DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
11838 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
856ca177 11839 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
11840 SHOW_STR
11841 IP_STR
11842 BGP_STR
11843 "Address family\n"
11844 "Address Family modifier\n"
11845 "Address Family modifier\n"
11846 "Detailed information on TCP and BGP neighbor connections\n"
11847 "Neighbor to display information about\n"
11848 "Neighbor to display information about\n"
a80beece 11849 "Neighbor on bgp configured interface\n"
856ca177
MS
11850 "Display detailed prefix count information\n"
11851 "JavaScript Object Notation\n")
ff7924f6
PJ
11852{
11853 struct peer *peer;
db7c8528 11854 u_char uj = use_json(argc, argv);
ff7924f6 11855
db7c8528 11856 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
ff7924f6
PJ
11857 if (! peer)
11858 return CMD_WARNING;
11859
11860 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 11861 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST, uj);
ff7924f6 11862
db7c8528 11863 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
ff7924f6
PJ
11864}
11865
11866DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
11867 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
856ca177 11868 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
11869 SHOW_STR
11870 IP_STR
11871 BGP_STR
11872 "Address family\n"
11873 "Address Family modifier\n"
11874 "Address Family modifier\n"
11875 "Detailed information on TCP and BGP neighbor connections\n"
11876 "Neighbor to display information about\n"
11877 "Neighbor to display information about\n"
a80beece 11878 "Neighbor on bgp configured interface\n"
856ca177
MS
11879 "Display detailed prefix count information\n"
11880 "JavaScript Object Notation\n")
ff7924f6
PJ
11881{
11882 struct peer *peer;
db7c8528 11883 u_char uj = use_json(argc, argv);
856ca177 11884
db7c8528 11885 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
ff7924f6
PJ
11886 if (! peer)
11887 return CMD_WARNING;
11888
db7c8528 11889 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN, uj);
ff7924f6
PJ
11890}
11891
94f2b392 11892static void
718e3744 11893show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
856ca177 11894 int in, const char *rmap_name, u_char use_json, json_object *json)
718e3744 11895{
11896 struct bgp_table *table;
11897 struct bgp_adj_in *ain;
11898 struct bgp_adj_out *adj;
11899 unsigned long output_count;
0b16f239 11900 unsigned long filtered_count;
718e3744 11901 struct bgp_node *rn;
11902 int header1 = 1;
11903 struct bgp *bgp;
11904 int header2 = 1;
0b16f239
DS
11905 struct attr attr;
11906 struct attr_extra extra;
11907 int ret;
840fced9 11908 struct update_subgroup *subgrp;
856ca177
MS
11909 json_object *json_scode = NULL;
11910 json_object *json_ocode = NULL;
11911 json_object *json_ar = NULL;
adbac85e 11912 struct peer_af *paf;
856ca177
MS
11913
11914 if (use_json)
11915 {
11916 json_scode = json_object_new_object();
11917 json_ocode = json_object_new_object();
11918 json_ar = json_object_new_object();
11919
11920 json_object_string_add(json_scode, "suppressed", "s");
11921 json_object_string_add(json_scode, "damped", "d");
11922 json_object_string_add(json_scode, "history", "h");
11923 json_object_string_add(json_scode, "valid", "*");
11924 json_object_string_add(json_scode, "best", ">");
11925 json_object_string_add(json_scode, "multipath", "=");
11926 json_object_string_add(json_scode, "internal", "i");
11927 json_object_string_add(json_scode, "ribFailure", "r");
11928 json_object_string_add(json_scode, "stale", "S");
11929 json_object_string_add(json_scode, "removed", "R");
11930
11931 json_object_string_add(json_ocode, "igp", "i");
11932 json_object_string_add(json_ocode, "egp", "e");
11933 json_object_string_add(json_ocode, "incomplete", "?");
11934 }
718e3744 11935
bb46e94f 11936 bgp = peer->bgp;
718e3744 11937
11938 if (! bgp)
856ca177
MS
11939 {
11940 if (use_json)
11941 {
11942 json_object_string_add(json, "alert", "no BGP");
11943 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11944 json_object_free(json);
11945 }
11946 else
11947 vty_out (vty, "%% No bgp%s", VTY_NEWLINE);
11948 return;
11949 }
718e3744 11950
11951 table = bgp->rib[afi][safi];
11952
0b16f239 11953 output_count = filtered_count = 0;
840fced9 11954 subgrp = peer_subgroup(peer, afi, safi);
47fc97cc 11955
840fced9 11956 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
718e3744 11957 {
856ca177
MS
11958 if (use_json)
11959 {
11960 json_object_int_add(json, "bgpTableVersion", table->version);
11961 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
11962 json_object_object_add(json, "bgpStatusCodes", json_scode);
11963 json_object_object_add(json, "bgpOriginCodes", json_ocode);
11964 json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0");
11965 }
11966 else
11967 {
11968 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
11969 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11970 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 11971
856ca177
MS
11972 vty_out (vty, "Originating default network 0.0.0.0%s%s",
11973 VTY_NEWLINE, VTY_NEWLINE);
11974 }
718e3744 11975 header1 = 0;
11976 }
11977
0b16f239 11978 attr.extra = &extra;
718e3744 11979 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
856ca177
MS
11980 {
11981 if (in)
11982 {
11983 for (ain = rn->adj_in; ain; ain = ain->next)
11984 {
11985 if (ain->peer == peer)
11986 {
11987 if (header1)
11988 {
11989 if (use_json)
11990 {
11991 json_object_int_add(json, "bgpTableVersion", 0);
11992 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
11993 json_object_object_add(json, "bgpStatusCodes", json_scode);
11994 json_object_object_add(json, "bgpOriginCodes", json_ocode);
11995 }
11996 else
11997 {
11998 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
11999 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12000 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12001 }
12002 header1 = 0;
12003 }
12004 if (header2)
12005 {
12006 if (!use_json)
12007 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12008 header2 = 0;
12009 }
12010 if (ain->attr)
12011 {
12012 bgp_attr_dup(&attr, ain->attr);
12013 if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY)
12014 {
12015 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12016 output_count++;
12017 }
12018 else
12019 filtered_count++;
12020 }
12021 }
12022 }
12023 }
12024 else
12025 {
adbac85e
DW
12026 for (adj = rn->adj_out; adj; adj = adj->next)
12027 SUBGRP_FOREACH_PEER(adj->subgroup, paf)
12028 if (paf->peer == peer)
856ca177 12029 {
adbac85e 12030 if (header1)
856ca177 12031 {
adbac85e
DW
12032 if (use_json)
12033 {
12034 json_object_int_add(json, "bgpTableVersion", table->version);
12035 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12036 json_object_object_add(json, "bgpStatusCodes", json_scode);
12037 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12038 }
12039 else
12040 {
12041 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version,
12042 inet_ntoa (bgp->router_id), VTY_NEWLINE);
12043 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12044 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12045 }
12046 header1 = 0;
856ca177 12047 }
adbac85e
DW
12048
12049 if (header2)
856ca177 12050 {
adbac85e
DW
12051 if (!use_json)
12052 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12053 header2 = 0;
856ca177 12054 }
adbac85e
DW
12055
12056 if (adj->attr)
856ca177 12057 {
adbac85e
DW
12058 bgp_attr_dup(&attr, adj->attr);
12059 ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name);
12060 if (ret != RMAP_DENY)
12061 {
12062 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12063 output_count++;
12064 }
12065 else
12066 filtered_count++;
856ca177 12067 }
856ca177 12068 }
856ca177
MS
12069 }
12070 }
12071 if (use_json)
12072 json_object_object_add(json, "advertisedRoutes", json_ar);
47fc97cc 12073
718e3744 12074 if (output_count != 0)
856ca177
MS
12075 {
12076 if (use_json)
12077 json_object_int_add(json, "totalPrefixCounter", output_count);
12078 else
12079 vty_out (vty, "%sTotal number of prefixes %ld%s",
12080 VTY_NEWLINE, output_count, VTY_NEWLINE);
12081 }
12082 if (use_json)
12083 {
12084 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12085 json_object_free(json);
12086 }
12087
718e3744 12088}
12089
94f2b392 12090static int
47fc97cc 12091peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
856ca177
MS
12092 int in, const char *rmap_name, u_char use_json)
12093{
12094 json_object *json = NULL;
12095
12096 if (use_json)
12097 json = json_object_new_object();
12098
12099 if (!peer || !peer->afc[afi][safi])
718e3744 12100 {
856ca177
MS
12101 if (use_json)
12102 {
12103 json_object_string_add(json, "warning", "No such neighbor or address family");
12104 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12105 json_object_free(json);
12106 }
12107 else
12108 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12109
718e3744 12110 return CMD_WARNING;
12111 }
12112
856ca177 12113 if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
718e3744 12114 {
856ca177
MS
12115 if (use_json)
12116 {
12117 json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
12118 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12119 json_object_free(json);
12120 }
12121 else
12122 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE);
12123
718e3744 12124 return CMD_WARNING;
12125 }
12126
856ca177 12127 show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json);
718e3744 12128
12129 return CMD_SUCCESS;
12130}
12131
8386ac43 12132DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
12133 show_ip_bgp_instance_neighbor_advertised_route_cmd,
12134 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12135 SHOW_STR
12136 IP_STR
12137 BGP_STR
8386ac43 12138 BGP_INSTANCE_HELP_STR
718e3744 12139 "Detailed information on TCP and BGP neighbor connections\n"
12140 "Neighbor to display information about\n"
12141 "Neighbor to display information about\n"
856ca177
MS
12142 "Display the routes advertised to a BGP neighbor\n"
12143 "JavaScript Object Notation\n")
718e3744 12144{
bb46e94f 12145 struct peer *peer;
db7c8528 12146 u_char uj = use_json(argc, argv);
856ca177 12147
6aeb9e78
DS
12148 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12149 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
2a71e9ce 12150 else
6aeb9e78 12151 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
2a71e9ce 12152
bb46e94f 12153 if (! peer)
12154 return CMD_WARNING;
0b16f239 12155
db7c8528 12156 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj);
718e3744 12157}
12158
0b16f239 12159DEFUN (show_ip_bgp_neighbor_advertised_route,
2a71e9ce 12160 show_ip_bgp_neighbor_advertised_route_cmd,
856ca177 12161 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
2a71e9ce
TP
12162 SHOW_STR
12163 IP_STR
12164 BGP_STR
12165 "Detailed information on TCP and BGP neighbor connections\n"
12166 "Neighbor to display information about\n"
12167 "Neighbor to display information about\n"
a80beece 12168 "Neighbor on bgp configured interface\n"
856ca177
MS
12169 "Display the routes advertised to a BGP neighbor\n"
12170 "JavaScript Object Notation\n")
2a71e9ce 12171
0b16f239
DS
12172{
12173 struct peer *peer;
ffd0c037 12174 const char *rmap_name = NULL;
db7c8528 12175 u_char uj = use_json(argc, argv);
0b16f239 12176
db7c8528 12177 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
0b16f239
DS
12178
12179 if (! peer)
12180 return CMD_WARNING;
12181
856ca177
MS
12182 if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)
12183 || (argc == 3))
0b16f239
DS
12184 rmap_name = argv[1];
12185
db7c8528 12186 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
0b16f239
DS
12187}
12188
12189ALIAS (show_ip_bgp_neighbor_advertised_route,
12190 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
856ca177 12191 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
0b16f239
DS
12192 SHOW_STR
12193 IP_STR
12194 BGP_STR
12195 "Detailed information on TCP and BGP neighbor connections\n"
12196 "Neighbor to display information about\n"
12197 "Neighbor to display information about\n"
12198 "Neighbor on bgp configured interface\n"
856ca177
MS
12199 "Display the routes advertised to a BGP neighbor\n"
12200 "JavaScript Object Notation\n")
0b16f239 12201
8386ac43 12202ALIAS (show_ip_bgp_instance_neighbor_advertised_route,
12203 show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd,
12204 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
50ef26d4 12205 SHOW_STR
12206 IP_STR
12207 BGP_STR
8386ac43 12208 BGP_INSTANCE_HELP_STR
50ef26d4 12209 "Detailed information on TCP and BGP neighbor connections\n"
12210 "Neighbor to display information about\n"
12211 "Neighbor to display information about\n"
12212 "Neighbor on bgp configured interface\n"
12213 "Display the routes advertised to a BGP neighbor\n"
12214 "JavaScript Object Notation\n")
718e3744 12215DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12216 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
856ca177 12217 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12218 SHOW_STR
12219 IP_STR
12220 BGP_STR
12221 "Address family\n"
12222 "Address Family modifier\n"
12223 "Address Family modifier\n"
12224 "Detailed information on TCP and BGP neighbor connections\n"
12225 "Neighbor to display information about\n"
12226 "Neighbor to display information about\n"
a80beece 12227 "Neighbor on bgp configured interface\n"
856ca177
MS
12228 "Display the routes advertised to a BGP neighbor\n"
12229 "JavaScript Object Notation\n")
718e3744 12230{
bb46e94f 12231 struct peer *peer;
ffd0c037 12232 const char *rmap_name = NULL;
db7c8528 12233 u_char uj = use_json(argc, argv);
856ca177 12234
db7c8528 12235 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 12236 if (! peer)
12237 return CMD_WARNING;
12238
856ca177 12239 if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
0b16f239
DS
12240 rmap_name = argv[2];
12241
718e3744 12242 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 12243 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name, uj);
856ca177 12244 else
db7c8528 12245 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
718e3744 12246}
12247
0b16f239
DS
12248ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
12249 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
856ca177 12250 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
0b16f239
DS
12251 SHOW_STR
12252 IP_STR
12253 BGP_STR
12254 "Address family\n"
12255 "Address Family modifier\n"
12256 "Address Family modifier\n"
12257 "Detailed information on TCP and BGP neighbor connections\n"
12258 "Neighbor to display information about\n"
12259 "Neighbor to display information about\n"
12260 "Neighbor on bgp configured interface\n"
12261 "Display the routes advertised to a BGP neighbor\n"
856ca177
MS
12262 "Route-map to control what is displayed\n"
12263 "JavaScript Object Notation\n")
0b16f239 12264
718e3744 12265#ifdef HAVE_IPV6
8386ac43 12266DEFUN (show_bgp_instance_neighbor_advertised_route,
12267 show_bgp_instance_neighbor_advertised_route_cmd,
12268 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12269 SHOW_STR
12270 BGP_STR
8386ac43 12271 BGP_INSTANCE_HELP_STR
718e3744 12272 "Detailed information on TCP and BGP neighbor connections\n"
12273 "Neighbor to display information about\n"
12274 "Neighbor to display information about\n"
a80beece 12275 "Neighbor on bgp configured interface\n"
856ca177
MS
12276 "Display the routes advertised to a BGP neighbor\n"
12277 "JavaScript Object Notation\n")
718e3744 12278{
bb46e94f 12279 struct peer *peer;
db7c8528 12280 u_char uj = use_json(argc, argv);
856ca177 12281
6aeb9e78
DS
12282 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12283 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
bb46e94f 12284 else
6aeb9e78 12285 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 12286
12287 if (! peer)
0b16f239 12288 return CMD_WARNING;
bb46e94f 12289
db7c8528 12290 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj);
47fc97cc
DS
12291}
12292
8386ac43 12293ALIAS (show_bgp_instance_neighbor_advertised_route,
12294 show_bgp_instance_ipv6_neighbor_advertised_route_cmd,
12295 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
0b16f239
DS
12296 SHOW_STR
12297 BGP_STR
8386ac43 12298 BGP_INSTANCE_HELP_STR
0b16f239
DS
12299 "Address family\n"
12300 "Detailed information on TCP and BGP neighbor connections\n"
12301 "Neighbor to display information about\n"
12302 "Neighbor to display information about\n"
12303 "Neighbor on bgp configured interface\n"
856ca177
MS
12304 "Display the routes advertised to a BGP neighbor\n"
12305 "JavaScript Object Notation\n")
0b16f239 12306
0b16f239
DS
12307DEFUN (show_bgp_neighbor_advertised_route,
12308 show_bgp_neighbor_advertised_route_cmd,
856ca177 12309 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
bb46e94f 12310 SHOW_STR
12311 BGP_STR
bb46e94f 12312 "Detailed information on TCP and BGP neighbor connections\n"
12313 "Neighbor to display information about\n"
12314 "Neighbor to display information about\n"
a80beece 12315 "Neighbor on bgp configured interface\n"
856ca177
MS
12316 "Display the routes advertised to a BGP neighbor\n"
12317 "JavaScript Object Notation\n")
0b16f239 12318
bb46e94f 12319{
12320 struct peer *peer;
ffd0c037 12321 const char *rmap_name = NULL;
db7c8528 12322 u_char uj = use_json(argc, argv);
bb46e94f 12323
db7c8528 12324 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
856ca177
MS
12325
12326 if (!peer)
bb46e94f 12327 return CMD_WARNING;
12328
856ca177 12329 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
0b16f239
DS
12330 rmap_name = argv[1];
12331
db7c8528 12332 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj);
718e3744 12333}
12334
0b16f239
DS
12335ALIAS (show_bgp_neighbor_advertised_route,
12336 show_bgp_ipv6_neighbor_advertised_route_cmd,
856ca177 12337 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12338 SHOW_STR
12339 BGP_STR
12340 "Address family\n"
12341 "Detailed information on TCP and BGP neighbor connections\n"
12342 "Neighbor to display information about\n"
12343 "Neighbor to display information about\n"
a80beece 12344 "Neighbor on bgp configured interface\n"
856ca177
MS
12345 "Display the routes advertised to a BGP neighbor\n"
12346 "JavaScript Object Notation\n")
718e3744 12347
12348/* old command */
0b16f239 12349ALIAS (show_bgp_neighbor_advertised_route,
718e3744 12350 ipv6_bgp_neighbor_advertised_route_cmd,
856ca177 12351 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12352 SHOW_STR
12353 IPV6_STR
12354 BGP_STR
12355 "Detailed information on TCP and BGP neighbor connections\n"
12356 "Neighbor to display information about\n"
12357 "Neighbor to display information about\n"
a80beece 12358 "Neighbor on bgp configured interface\n"
856ca177
MS
12359 "Display the routes advertised to a BGP neighbor\n"
12360 "JavaScript Object Notation\n")
bb46e94f 12361
718e3744 12362/* old command */
12363DEFUN (ipv6_mbgp_neighbor_advertised_route,
12364 ipv6_mbgp_neighbor_advertised_route_cmd,
856ca177 12365 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12366 SHOW_STR
12367 IPV6_STR
12368 MBGP_STR
12369 "Detailed information on TCP and BGP neighbor connections\n"
12370 "Neighbor to display information about\n"
12371 "Neighbor to display information about\n"
a80beece
DS
12372 "Neighbor on bgp configured interface\n"
12373 "Neighbor on bgp configured interface\n"
856ca177
MS
12374 "Display the routes advertised to a BGP neighbor\n"
12375 "JavaScript Object Notation\n")
718e3744 12376{
bb46e94f 12377 struct peer *peer;
db7c8528 12378 u_char uj = use_json(argc, argv);
856ca177 12379
db7c8528 12380 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 12381 if (! peer)
856ca177 12382 return CMD_WARNING;
bb46e94f 12383
47e9b292 12384 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 12385 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj);
718e3744 12386}
12387#endif /* HAVE_IPV6 */
6b0655a2 12388
8386ac43 12389DEFUN (show_bgp_instance_neighbor_received_routes,
12390 show_bgp_instance_neighbor_received_routes_cmd,
12391 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
0b16f239
DS
12392 SHOW_STR
12393 BGP_STR
8386ac43 12394 BGP_INSTANCE_HELP_STR
0b16f239
DS
12395 "Detailed information on TCP and BGP neighbor connections\n"
12396 "Neighbor to display information about\n"
12397 "Neighbor to display information about\n"
12398 "Neighbor on bgp configured interface\n"
856ca177
MS
12399 "Display the received routes from neighbor\n"
12400 "JavaScript Object Notation\n")
0b16f239
DS
12401{
12402 struct peer *peer;
db7c8528 12403 u_char uj = use_json(argc, argv);
856ca177 12404
50ef26d4 12405 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
0b16f239
DS
12406 if (! peer)
12407 return CMD_WARNING;
12408
db7c8528 12409 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj);
0b16f239
DS
12410}
12411
8386ac43 12412DEFUN (show_ip_bgp_instance_neighbor_received_routes,
12413 show_ip_bgp_instance_neighbor_received_routes_cmd,
12414 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 12415 SHOW_STR
12416 IP_STR
12417 BGP_STR
8386ac43 12418 BGP_INSTANCE_HELP_STR
718e3744 12419 "Detailed information on TCP and BGP neighbor connections\n"
12420 "Neighbor to display information about\n"
12421 "Neighbor to display information about\n"
a80beece 12422 "Neighbor on bgp configured interface\n"
856ca177
MS
12423 "Display the received routes from 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
50ef26d4 12429 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
bb46e94f 12430 if (! peer)
12431 return CMD_WARNING;
12432
db7c8528 12433 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj);
718e3744 12434}
12435
8386ac43 12436ALIAS (show_bgp_instance_neighbor_received_routes,
12437 show_bgp_instance_ipv6_neighbor_received_routes_cmd,
12438 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
0b16f239
DS
12439 SHOW_STR
12440 BGP_STR
8386ac43 12441 BGP_INSTANCE_HELP_STR
0b16f239
DS
12442 "Address family\n"
12443 "Detailed information on TCP and BGP neighbor connections\n"
12444 "Neighbor to display information about\n"
12445 "Neighbor to display information about\n"
12446 "Neighbor on bgp configured interface\n"
856ca177
MS
12447 "Display the received routes from neighbor\n"
12448 "JavaScript Object Notation\n")
0b16f239
DS
12449
12450DEFUN (show_ip_bgp_neighbor_received_routes,
2a71e9ce 12451 show_ip_bgp_neighbor_received_routes_cmd,
856ca177 12452 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
2a71e9ce
TP
12453 SHOW_STR
12454 IP_STR
12455 BGP_STR
12456 "Detailed information on TCP and BGP neighbor connections\n"
12457 "Neighbor to display information about\n"
12458 "Neighbor to display information about\n"
a80beece 12459 "Neighbor on bgp configured interface\n"
856ca177
MS
12460 "Display the received routes from neighbor\n"
12461 "JavaScript Object Notation\n")
2a71e9ce 12462
0b16f239
DS
12463{
12464 struct peer *peer;
ffd0c037 12465 const char *rmap_name = NULL;
db7c8528 12466 u_char uj = use_json(argc, argv);
0b16f239 12467
db7c8528 12468 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
0b16f239
DS
12469
12470 if (! peer)
12471 return CMD_WARNING;
12472
856ca177 12473 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
0b16f239
DS
12474 rmap_name = argv[1];
12475
db7c8528 12476 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
0b16f239
DS
12477}
12478
12479ALIAS (show_ip_bgp_neighbor_received_routes,
12480 show_ip_bgp_neighbor_received_routes_rmap_cmd,
856ca177 12481 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
0b16f239
DS
12482 SHOW_STR
12483 IP_STR
12484 BGP_STR
12485 "Detailed information on TCP and BGP neighbor connections\n"
12486 "Neighbor to display information about\n"
12487 "Neighbor to display information about\n"
12488 "Neighbor on bgp configured interface\n"
856ca177
MS
12489 "Display the received routes from neighbor\n"
12490 "JavaScript Object Notation\n")
0b16f239 12491
8386ac43 12492ALIAS (show_ip_bgp_instance_neighbor_received_routes,
12493 show_ip_bgp_instance_neighbor_received_routes_rmap_cmd,
12494 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
50ef26d4 12495 SHOW_STR
12496 IP_STR
12497 BGP_STR
8386ac43 12498 BGP_INSTANCE_HELP_STR
50ef26d4 12499 "Detailed information on TCP and BGP neighbor connections\n"
12500 "Neighbor to display information about\n"
12501 "Neighbor to display information about\n"
12502 "Neighbor on bgp configured interface\n"
12503 "Display the received routes from neighbor\n"
12504 "JavaScript Object Notation\n")
12505
718e3744 12506DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12507 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
856ca177 12508 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 12509 SHOW_STR
12510 IP_STR
12511 BGP_STR
12512 "Address family\n"
12513 "Address Family modifier\n"
12514 "Address Family modifier\n"
12515 "Detailed information on TCP and BGP neighbor connections\n"
12516 "Neighbor to display information about\n"
12517 "Neighbor to display information about\n"
a80beece 12518 "Neighbor on bgp configured interface\n"
856ca177
MS
12519 "Display the received routes from neighbor\n"
12520 "JavaScript Object Notation\n")
718e3744 12521{
bb46e94f 12522 struct peer *peer;
ffd0c037 12523 const char *rmap_name = NULL;
db7c8528 12524 u_char uj = use_json(argc, argv);
bb46e94f 12525
db7c8528 12526 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 12527 if (! peer)
12528 return CMD_WARNING;
0b16f239 12529
856ca177 12530 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
0b16f239
DS
12531 rmap_name = argv[2];
12532
718e3744 12533 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 12534 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name, uj);
856ca177 12535 else
db7c8528 12536 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
718e3744 12537}
12538
0b16f239
DS
12539ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
12540 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
856ca177 12541 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
0b16f239
DS
12542 SHOW_STR
12543 IP_STR
12544 BGP_STR
12545 "Address family\n"
12546 "Address Family modifier\n"
12547 "Address Family modifier\n"
12548 "Detailed information on TCP and BGP neighbor connections\n"
12549 "Neighbor to display information about\n"
12550 "Neighbor to display information about\n"
12551 "Neighbor on bgp configured interface\n"
856ca177
MS
12552 "Display the received routes from neighbor\n"
12553 "JavaScript Object Notation\n")
0b16f239 12554
8386ac43 12555DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes,
12556 show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd,
8386ac43 12557 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
95cbbd2a
ML
12558 SHOW_STR
12559 BGP_STR
8386ac43 12560 BGP_INSTANCE_HELP_STR
95cbbd2a 12561 "Address family\n"
95cbbd2a 12562 "Address family\n"
95cbbd2a
ML
12563 "Address family modifier\n"
12564 "Address family modifier\n"
12565 "Detailed information on TCP and BGP neighbor connections\n"
12566 "Neighbor to display information about\n"
12567 "Neighbor to display information about\n"
a80beece 12568 "Neighbor on bgp configured interface\n"
95cbbd2a 12569 "Display the advertised routes to neighbor\n"
856ca177
MS
12570 "Display the received routes from neighbor\n"
12571 "JavaScript Object Notation\n")
95cbbd2a
ML
12572{
12573 int afi;
12574 int safi;
12575 int in;
12576 struct peer *peer;
db7c8528 12577 u_char uj = use_json(argc, argv);
856ca177 12578
6aeb9e78 12579 peer = peer_lookup_in_view (vty, argv[1], argv[4], uj);
95cbbd2a
ML
12580
12581 if (! peer)
12582 return CMD_WARNING;
12583
6aeb9e78
DS
12584 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
12585 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12586 in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0;
95cbbd2a 12587
db7c8528 12588 return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj);
95cbbd2a
ML
12589}
12590
718e3744 12591DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12592 show_ip_bgp_neighbor_received_prefix_filter_cmd,
856ca177 12593 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 12594 SHOW_STR
12595 IP_STR
12596 BGP_STR
12597 "Detailed information on TCP and BGP neighbor connections\n"
12598 "Neighbor to display information about\n"
12599 "Neighbor to display information about\n"
a80beece 12600 "Neighbor on bgp configured interface\n"
718e3744 12601 "Display information received from a BGP neighbor\n"
856ca177
MS
12602 "Display the prefixlist filter\n"
12603 "JavaScript Object Notation\n")
718e3744 12604{
12605 char name[BUFSIZ];
c63b83fe 12606 union sockunion su;
718e3744 12607 struct peer *peer;
c63b83fe 12608 int count, ret;
db7c8528 12609 u_char uj = use_json(argc, argv);
718e3744 12610
c63b83fe
JBD
12611 ret = str2sockunion (argv[0], &su);
12612 if (ret < 0)
12613 {
a80beece 12614 peer = peer_lookup_by_conf_if (NULL, argv[0]);
856ca177 12615 if (! peer)
a80beece 12616 {
db7c8528 12617 if (uj)
856ca177
MS
12618 {
12619 json_object *json_no = NULL;
12620 json_object *json_sub = NULL;
12621 json_no = json_object_new_object();
12622 json_sub = json_object_new_object();
12623 json_object_string_add(json_no, "warning", "Malformed address or name");
12624 json_object_string_add(json_sub, "warningCause", argv[0]);
12625 json_object_object_add(json_no, "detail", json_sub);
12626 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12627 json_object_free(json_no);
12628 }
12629 else
12630 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
a80beece
DS
12631 return CMD_WARNING;
12632 }
12633 }
12634 else
12635 {
12636 peer = peer_lookup (NULL, &su);
12637 if (! peer)
856ca177 12638 {
db7c8528 12639 if (uj)
856ca177
MS
12640 {
12641 json_object *json_no = NULL;
12642 json_no = json_object_new_object();
12643 json_object_string_add(json_no, "warning", "Peer not found");
12644 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12645 json_object_free(json_no);
12646 }
12647 else
12648 vty_out (vty, "No peer%s", VTY_NEWLINE);
12649 return CMD_WARNING;
12650 }
c63b83fe 12651 }
718e3744 12652
12653 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
db7c8528 12654 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
718e3744 12655 if (count)
12656 {
db7c8528 12657 if (!uj)
856ca177 12658 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
db7c8528 12659 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
856ca177
MS
12660 }
12661 else
12662 {
db7c8528 12663 if (uj)
856ca177
MS
12664 {
12665 json_object *json_no = NULL;
12666 json_no = json_object_new_object();
12667 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12668 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12669 json_object_free(json_no);
12670 }
12671 else
12672 vty_out (vty, "No functional output%s", VTY_NEWLINE);
718e3744 12673 }
12674
12675 return CMD_SUCCESS;
12676}
12677
12678DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
12679 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
856ca177 12680 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 12681 SHOW_STR
12682 IP_STR
12683 BGP_STR
12684 "Address family\n"
12685 "Address Family modifier\n"
12686 "Address Family modifier\n"
12687 "Detailed information on TCP and BGP neighbor connections\n"
12688 "Neighbor to display information about\n"
12689 "Neighbor to display information about\n"
a80beece 12690 "Neighbor on bgp configured interface\n"
718e3744 12691 "Display information received from a BGP neighbor\n"
856ca177
MS
12692 "Display the prefixlist filter\n"
12693 "JavaScript Object Notation\n")
718e3744 12694{
12695 char name[BUFSIZ];
c63b83fe 12696 union sockunion su;
718e3744 12697 struct peer *peer;
c63b83fe 12698 int count, ret;
db7c8528 12699 u_char uj = use_json(argc, argv);
718e3744 12700
c63b83fe
JBD
12701 ret = str2sockunion (argv[1], &su);
12702 if (ret < 0)
12703 {
a80beece 12704 peer = peer_lookup_by_conf_if (NULL, argv[1]);
856ca177 12705 if (! peer)
a80beece 12706 {
db7c8528 12707 if (uj)
856ca177
MS
12708 {
12709 json_object *json_no = NULL;
12710 json_object *json_sub = NULL;
12711 json_no = json_object_new_object();
12712 json_sub = json_object_new_object();
12713 json_object_string_add(json_no, "warning", "Malformed address or name");
12714 json_object_string_add(json_sub, "warningCause", argv[1]);
12715 json_object_object_add(json_no, "detail", json_sub);
12716 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12717 json_object_free(json_no);
12718 }
12719 else
12720 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
a80beece
DS
12721 return CMD_WARNING;
12722 }
12723 }
12724 else
12725 {
12726 peer = peer_lookup (NULL, &su);
12727 if (! peer)
856ca177 12728 {
db7c8528 12729 if (uj)
856ca177
MS
12730 {
12731 json_object *json_no = NULL;
12732 json_no = json_object_new_object();
12733 json_object_string_add(json_no, "warning", "Peer not found");
12734 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12735 json_object_free(json_no);
12736 }
12737 else
12738 vty_out (vty, "No peer%s", VTY_NEWLINE);
12739 return CMD_WARNING;
12740 }
c63b83fe 12741 }
718e3744 12742
12743 if (strncmp (argv[0], "m", 1) == 0)
12744 {
12745 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
db7c8528 12746 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
718e3744 12747 if (count)
856ca177 12748 {
db7c8528 12749 if (!uj)
856ca177 12750 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
db7c8528 12751 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
856ca177
MS
12752 }
12753 else
12754 {
db7c8528 12755 if (uj)
856ca177
MS
12756 {
12757 json_object *json_no = NULL;
12758 json_no = json_object_new_object();
12759 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12760 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12761 json_object_free(json_no);
12762 }
12763 else
12764 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12765 }
718e3744 12766 }
12767 else
12768 {
12769 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
db7c8528 12770 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
718e3744 12771 if (count)
856ca177 12772 {
db7c8528 12773 if (!uj)
856ca177 12774 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
db7c8528 12775 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
856ca177
MS
12776 }
12777 else
12778 {
db7c8528 12779 if (uj)
856ca177
MS
12780 {
12781 json_object *json_no = NULL;
12782 json_no = json_object_new_object();
12783 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12784 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12785 json_object_free(json_no);
12786 }
12787 else
12788 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12789 }
718e3744 12790 }
12791
12792 return CMD_SUCCESS;
12793}
718e3744 12794#ifdef HAVE_IPV6
50ef26d4 12795DEFUN (show_bgp_neighbor_received_routes,
718e3744 12796 show_bgp_neighbor_received_routes_cmd,
856ca177 12797 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 12798 SHOW_STR
12799 BGP_STR
12800 "Detailed information on TCP and BGP neighbor connections\n"
12801 "Neighbor to display information about\n"
12802 "Neighbor to display information about\n"
a80beece 12803 "Neighbor on bgp configured interface\n"
856ca177
MS
12804 "Display the received routes from neighbor\n"
12805 "JavaScript Object Notation\n")
50ef26d4 12806{
12807 struct peer *peer;
12808 const char *rmap_name = NULL;
12809 u_char uj = use_json(argc, argv);
718e3744 12810
50ef26d4 12811 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12812
12813 if (! peer)
12814 return CMD_WARNING;
12815
12816 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12817 rmap_name = argv[1];
12818
12819 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, rmap_name, uj);
12820}
12821
12822ALIAS (show_bgp_neighbor_received_routes,
718e3744 12823 show_bgp_ipv6_neighbor_received_routes_cmd,
856ca177 12824 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
0b16f239
DS
12825 SHOW_STR
12826 BGP_STR
12827 "Address family\n"
12828 "Detailed information on TCP and BGP neighbor connections\n"
12829 "Neighbor to display information about\n"
12830 "Neighbor to display information about\n"
12831 "Neighbor on bgp configured interface\n"
856ca177
MS
12832 "Display the received routes from neighbor\n"
12833 "JavaScript Object Notation\n")
0b16f239 12834
718e3744 12835DEFUN (show_bgp_neighbor_received_prefix_filter,
12836 show_bgp_neighbor_received_prefix_filter_cmd,
856ca177 12837 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 12838 SHOW_STR
12839 BGP_STR
12840 "Detailed information on TCP and BGP neighbor connections\n"
12841 "Neighbor to display information about\n"
12842 "Neighbor to display information about\n"
a80beece 12843 "Neighbor on bgp configured interface\n"
718e3744 12844 "Display information received from a BGP neighbor\n"
856ca177
MS
12845 "Display the prefixlist filter\n"
12846 "JavaScript Object Notation\n")
718e3744 12847{
12848 char name[BUFSIZ];
c63b83fe 12849 union sockunion su;
718e3744 12850 struct peer *peer;
c63b83fe 12851 int count, ret;
db7c8528 12852 u_char uj = use_json(argc, argv);
718e3744 12853
c63b83fe
JBD
12854 ret = str2sockunion (argv[0], &su);
12855 if (ret < 0)
12856 {
a80beece 12857 peer = peer_lookup_by_conf_if (NULL, argv[0]);
856ca177 12858 if (! peer)
a80beece 12859 {
db7c8528 12860 if (uj)
856ca177
MS
12861 {
12862 json_object *json_no = NULL;
12863 json_object *json_sub = NULL;
12864 json_no = json_object_new_object();
12865 json_sub = json_object_new_object();
12866 json_object_string_add(json_no, "warning", "Malformed address or name");
12867 json_object_string_add(json_sub, "warningCause", argv[0]);
12868 json_object_object_add(json_no, "detail", json_sub);
12869 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12870 json_object_free(json_no);
12871 }
12872 else
12873 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
a80beece
DS
12874 return CMD_WARNING;
12875 }
12876 }
12877 else
12878 {
12879 peer = peer_lookup (NULL, &su);
12880 if (! peer)
856ca177 12881 {
db7c8528 12882 if (uj)
856ca177
MS
12883 {
12884 json_object *json_no = NULL;
12885 json_no = json_object_new_object();
12886 json_object_string_add(json_no, "warning", "No Peer");
12887 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12888 json_object_free(json_no);
12889 }
12890 else
12891 vty_out (vty, "No peer%s", VTY_NEWLINE);
12892 return CMD_WARNING;
12893 }
c63b83fe 12894 }
718e3744 12895
12896 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
db7c8528 12897 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
718e3744 12898 if (count)
12899 {
db7c8528 12900 if (!uj)
856ca177 12901 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
db7c8528 12902 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
856ca177
MS
12903 }
12904 else
12905 {
db7c8528 12906 if (uj)
856ca177
MS
12907 {
12908 json_object *json_no = NULL;
12909 json_no = json_object_new_object();
12910 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12911 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12912 json_object_free(json_no);
12913 }
12914 else
12915 vty_out (vty, "No functional output%s", VTY_NEWLINE);
718e3744 12916 }
12917
12918 return CMD_SUCCESS;
12919}
12920
12921ALIAS (show_bgp_neighbor_received_prefix_filter,
12922 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
856ca177 12923 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 12924 SHOW_STR
12925 BGP_STR
12926 "Address family\n"
12927 "Detailed information on TCP and BGP neighbor connections\n"
12928 "Neighbor to display information about\n"
12929 "Neighbor to display information about\n"
a80beece 12930 "Neighbor on bgp configured interface\n"
718e3744 12931 "Display information received from a BGP neighbor\n"
856ca177
MS
12932 "Display the prefixlist filter\n"
12933 "JavaScript Object Notation\n")
718e3744 12934
12935/* old command */
50ef26d4 12936ALIAS (show_bgp_neighbor_received_routes,
718e3744 12937 ipv6_bgp_neighbor_received_routes_cmd,
856ca177 12938 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 12939 SHOW_STR
12940 IPV6_STR
12941 BGP_STR
12942 "Detailed information on TCP and BGP neighbor connections\n"
12943 "Neighbor to display information about\n"
12944 "Neighbor to display information about\n"
a80beece 12945 "Neighbor on bgp configured interface\n"
856ca177
MS
12946 "Display the received routes from neighbor\n"
12947 "JavaScript Object Notation\n")
718e3744 12948
12949/* old command */
12950DEFUN (ipv6_mbgp_neighbor_received_routes,
12951 ipv6_mbgp_neighbor_received_routes_cmd,
856ca177 12952 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 12953 SHOW_STR
12954 IPV6_STR
12955 MBGP_STR
12956 "Detailed information on TCP and BGP neighbor connections\n"
12957 "Neighbor to display information about\n"
12958 "Neighbor to display information about\n"
a80beece 12959 "Neighbor on bgp configured interface\n"
856ca177
MS
12960 "Display the received routes from neighbor\n"
12961 "JavaScript Object Notation\n")
718e3744 12962{
bb46e94f 12963 struct peer *peer;
db7c8528 12964 u_char uj = use_json(argc, argv);
bb46e94f 12965
db7c8528 12966 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 12967 if (! peer)
12968 return CMD_WARNING;
12969
47e9b292 12970 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 12971 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj);
bb46e94f 12972}
12973
8386ac43 12974DEFUN (show_bgp_instance_neighbor_received_prefix_filter,
12975 show_bgp_instance_neighbor_received_prefix_filter_cmd,
12976 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
bb46e94f 12977 SHOW_STR
12978 BGP_STR
8386ac43 12979 BGP_INSTANCE_HELP_STR
bb46e94f 12980 "Detailed information on TCP and BGP neighbor connections\n"
12981 "Neighbor to display information about\n"
12982 "Neighbor to display information about\n"
a80beece 12983 "Neighbor on bgp configured interface\n"
bb46e94f 12984 "Display information received from a BGP neighbor\n"
856ca177
MS
12985 "Display the prefixlist filter\n"
12986 "JavaScript Object Notation\n")
bb46e94f 12987{
12988 char name[BUFSIZ];
c63b83fe 12989 union sockunion su;
bb46e94f 12990 struct peer *peer;
12991 struct bgp *bgp;
c63b83fe 12992 int count, ret;
db7c8528 12993 u_char uj = use_json(argc, argv);
bb46e94f 12994
12995 /* BGP structure lookup. */
6aeb9e78 12996 bgp = bgp_lookup_by_name (argv[1]);
bb46e94f 12997 if (bgp == NULL)
856ca177 12998 {
db7c8528 12999 if (uj)
856ca177
MS
13000 {
13001 json_object *json_no = NULL;
13002 json_no = json_object_new_object();
13003 json_object_string_add(json_no, "warning", "Can't find BGP view");
13004 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13005 json_object_free(json_no);
13006 }
13007 else
6aeb9e78 13008 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
856ca177
MS
13009 return CMD_WARNING;
13010 }
13011
6aeb9e78 13012 ret = str2sockunion (argv[2], &su);
c63b83fe
JBD
13013 if (ret < 0)
13014 {
6aeb9e78 13015 peer = peer_lookup_by_conf_if (bgp, argv[2]);
856ca177 13016 if (! peer)
a80beece 13017 {
db7c8528 13018 if (uj)
856ca177
MS
13019 {
13020 json_object *json_no = NULL;
13021 json_object *json_sub = NULL;
13022 json_no = json_object_new_object();
13023 json_sub = json_object_new_object();
13024 json_object_string_add(json_no, "warning", "Malformed address or name");
6aeb9e78 13025 json_object_string_add(json_sub, "warningCause", argv[2]);
856ca177
MS
13026 json_object_object_add(json_no, "detail", json_sub);
13027 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13028 json_object_free(json_no);
13029 }
13030 else
6aeb9e78 13031 vty_out (vty, "%% Malformed address or name: %s%s", argv[2], VTY_NEWLINE);
a80beece
DS
13032 return CMD_WARNING;
13033 }
13034 }
13035 else
13036 {
13037 peer = peer_lookup (bgp, &su);
13038 if (! peer)
856ca177 13039 {
db7c8528 13040 if (uj)
856ca177
MS
13041 {
13042 json_object *json_no = NULL;
13043 json_no = json_object_new_object();
13044 json_object_boolean_true_add(json_no, "noPeer");
13045 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13046 json_object_free(json_no);
13047 }
13048 else
13049 vty_out (vty, "No peer%s", VTY_NEWLINE);
13050 return CMD_WARNING;
13051 }
13052
c63b83fe 13053 }
bb46e94f 13054
13055 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
db7c8528 13056 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
bb46e94f 13057 if (count)
13058 {
db7c8528 13059 if (!uj)
856ca177 13060 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
db7c8528 13061 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
bb46e94f 13062 }
13063
13064 return CMD_SUCCESS;
718e3744 13065}
8386ac43 13066ALIAS (show_bgp_instance_neighbor_received_prefix_filter,
13067 show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd,
13068 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
bb46e94f 13069 SHOW_STR
13070 BGP_STR
8386ac43 13071 BGP_INSTANCE_HELP_STR
bb46e94f 13072 "Address family\n"
13073 "Detailed information on TCP and BGP neighbor connections\n"
13074 "Neighbor to display information about\n"
13075 "Neighbor to display information about\n"
a80beece 13076 "Neighbor on bgp configured interface\n"
bb46e94f 13077 "Display information received from a BGP neighbor\n"
856ca177
MS
13078 "Display the prefixlist filter\n"
13079 "JavaScript Object NOtation\n")
718e3744 13080#endif /* HAVE_IPV6 */
6b0655a2 13081
94f2b392 13082static int
bb46e94f 13083bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
856ca177 13084 safi_t safi, enum bgp_show_type type, u_char use_json)
718e3744 13085{
718e3744 13086 if (! peer || ! peer->afc[afi][safi])
13087 {
856ca177
MS
13088 if (use_json)
13089 {
13090 json_object *json_no = NULL;
13091 json_no = json_object_new_object();
13092 json_object_string_add(json_no, "warning", "No such neighbor or address family");
13093 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13094 json_object_free(json_no);
13095 }
13096 else
13097 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
718e3744 13098 return CMD_WARNING;
13099 }
47fc97cc 13100
856ca177 13101 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json);
718e3744 13102}
13103
13104DEFUN (show_ip_bgp_neighbor_routes,
13105 show_ip_bgp_neighbor_routes_cmd,
856ca177 13106 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13107 SHOW_STR
13108 IP_STR
13109 BGP_STR
13110 "Detailed information on TCP and BGP neighbor connections\n"
13111 "Neighbor to display information about\n"
13112 "Neighbor to display information about\n"
a80beece 13113 "Neighbor on bgp configured interface\n"
856ca177
MS
13114 "Display routes learned from neighbor\n"
13115 "JavaScript Object Notation\n")
718e3744 13116{
bb46e94f 13117 struct peer *peer;
db7c8528 13118 u_char uj = use_json(argc, argv);
856ca177 13119
db7c8528 13120 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 13121 if (! peer)
13122 return CMD_WARNING;
13123
13124 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 13125 bgp_show_type_neighbor, uj);
718e3744 13126}
13127
8386ac43 13128DEFUN (show_ip_bgp_instance_neighbor_routes,
13129 show_ip_bgp_instance_neighbor_routes_cmd,
13130 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
50ef26d4 13131 SHOW_STR
13132 IP_STR
13133 BGP_STR
8386ac43 13134 BGP_INSTANCE_HELP_STR
50ef26d4 13135 "Detailed information on TCP and BGP neighbor connections\n"
13136 "Neighbor to display information about\n"
13137 "Neighbor to display information about\n"
13138 "Neighbor on bgp configured interface\n"
13139 "Display routes learned from neighbor\n"
13140 "JavaScript Object Notation\n")
13141{
13142 struct peer *peer;
13143 u_char uj = use_json(argc, argv);
13144
13145 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13146 if (! peer)
13147 return CMD_WARNING;
13148
13149 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13150 bgp_show_type_neighbor, uj);
13151}
13152
718e3744 13153DEFUN (show_ip_bgp_neighbor_flap,
13154 show_ip_bgp_neighbor_flap_cmd,
856ca177 13155 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
718e3744 13156 SHOW_STR
13157 IP_STR
13158 BGP_STR
13159 "Detailed information on TCP and BGP neighbor connections\n"
13160 "Neighbor to display information about\n"
13161 "Neighbor to display information about\n"
a80beece 13162 "Neighbor on bgp configured interface\n"
856ca177
MS
13163 "Display flap statistics of the routes learned from neighbor\n"
13164 "JavaScript Object Notation\n")
718e3744 13165{
bb46e94f 13166 struct peer *peer;
db7c8528 13167 u_char uj = use_json(argc, argv);
856ca177 13168
db7c8528 13169 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 13170 if (! peer)
13171 return CMD_WARNING;
13172
13173 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 13174 bgp_show_type_flap_neighbor, uj);
718e3744 13175}
13176
13177DEFUN (show_ip_bgp_neighbor_damp,
13178 show_ip_bgp_neighbor_damp_cmd,
856ca177 13179 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
718e3744 13180 SHOW_STR
13181 IP_STR
13182 BGP_STR
13183 "Detailed information on TCP and BGP neighbor connections\n"
13184 "Neighbor to display information about\n"
13185 "Neighbor to display information about\n"
a80beece 13186 "Neighbor on bgp configured interface\n"
856ca177
MS
13187 "Display the dampened routes received from neighbor\n"
13188 "JavaScript Object Notation\n")
718e3744 13189{
bb46e94f 13190 struct peer *peer;
db7c8528 13191 u_char uj = use_json(argc, argv);
856ca177 13192
db7c8528 13193 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 13194 if (! peer)
13195 return CMD_WARNING;
13196
13197 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 13198 bgp_show_type_damp_neighbor, uj);
718e3744 13199}
13200
13201DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13202 show_ip_bgp_ipv4_neighbor_routes_cmd,
856ca177 13203 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13204 SHOW_STR
13205 IP_STR
13206 BGP_STR
13207 "Address family\n"
13208 "Address Family modifier\n"
13209 "Address Family modifier\n"
13210 "Detailed information on TCP and BGP neighbor connections\n"
13211 "Neighbor to display information about\n"
13212 "Neighbor to display information about\n"
a80beece 13213 "Neighbor on bgp configured interface\n"
856ca177
MS
13214 "Display routes learned from neighbor\n"
13215 "JavaScript Object Notation\n")
718e3744 13216{
bb46e94f 13217 struct peer *peer;
db7c8528 13218 u_char uj = use_json(argc, argv);
bb46e94f 13219
db7c8528 13220 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 13221 if (! peer)
13222 return CMD_WARNING;
13223
718e3744 13224 if (strncmp (argv[0], "m", 1) == 0)
bb46e94f 13225 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
db7c8528 13226 bgp_show_type_neighbor, uj);
718e3744 13227
bb46e94f 13228 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 13229 bgp_show_type_neighbor, uj);
718e3744 13230}
bb46e94f 13231
2a3d5731 13232#ifdef HAVE_IPV6
8386ac43 13233DEFUN (show_bgp_instance_neighbor_routes,
13234 show_bgp_instance_neighbor_routes_cmd,
13235 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
fee0f4c6 13236 SHOW_STR
fee0f4c6 13237 BGP_STR
8386ac43 13238 BGP_INSTANCE_HELP_STR
2a3d5731
DW
13239 "Detailed information on TCP and BGP neighbor connections\n"
13240 "Neighbor to display information about\n"
13241 "Neighbor to display information about\n"
13242 "Neighbor on bgp configured interface\n"
13243 "Display routes learned from neighbor\n"
13244 "JavaScript Object Notation\n")
fee0f4c6 13245{
fee0f4c6 13246 struct peer *peer;
db7c8528 13247 u_char uj = use_json(argc, argv);
fee0f4c6 13248
50ef26d4 13249 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
fee0f4c6 13250 if (! peer)
13251 return CMD_WARNING;
13252
2a3d5731 13253 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
db7c8528 13254 bgp_show_type_neighbor, uj);
fee0f4c6 13255}
13256
8386ac43 13257ALIAS (show_bgp_instance_neighbor_routes,
13258 show_bgp_instance_ipv6_neighbor_routes_cmd,
13259 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
fee0f4c6 13260 SHOW_STR
fee0f4c6 13261 BGP_STR
8386ac43 13262 BGP_INSTANCE_HELP_STR
2a3d5731
DW
13263 "Address family\n"
13264 "Detailed information on TCP and BGP neighbor connections\n"
13265 "Neighbor to display information about\n"
13266 "Neighbor to display information about\n"
13267 "Neighbor on bgp configured interface\n"
13268 "Display routes learned from neighbor\n"
13269 "JavaScript Object Notation\n")
fee0f4c6 13270
8386ac43 13271DEFUN (show_bgp_instance_neighbor_damp,
13272 show_bgp_instance_neighbor_damp_cmd,
13273 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
fee0f4c6 13274 SHOW_STR
fee0f4c6 13275 BGP_STR
8386ac43 13276 BGP_INSTANCE_HELP_STR
2a3d5731
DW
13277 "Detailed information on TCP and BGP neighbor connections\n"
13278 "Neighbor to display information about\n"
13279 "Neighbor to display information about\n"
13280 "Neighbor on bgp configured interface\n"
13281 "Display the dampened routes received from neighbor\n"
13282 "JavaScript Object Notation\n")
bb46e94f 13283{
13284 struct peer *peer;
db7c8528 13285 u_char uj = use_json(argc, argv);
856ca177 13286
6aeb9e78
DS
13287 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13288 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13289 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
bb46e94f 13290 else
6aeb9e78 13291 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 13292
13293 if (! peer)
13294 return CMD_WARNING;
13295
13296 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
db7c8528 13297 bgp_show_type_damp_neighbor, uj);
bb46e94f 13298}
13299
8386ac43 13300ALIAS (show_bgp_instance_neighbor_damp,
13301 show_bgp_instance_ipv6_neighbor_damp_cmd,
13302 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
bb46e94f 13303 SHOW_STR
13304 BGP_STR
8386ac43 13305 BGP_INSTANCE_HELP_STR
bb46e94f 13306 "Address family\n"
13307 "Detailed information on TCP and BGP neighbor connections\n"
13308 "Neighbor to display information about\n"
13309 "Neighbor to display information about\n"
a80beece 13310 "Neighbor on bgp configured interface\n"
856ca177
MS
13311 "Display the dampened routes received from neighbor\n"
13312 "JavaScript Object Notation\n")
bb46e94f 13313
8386ac43 13314DEFUN (show_bgp_instance_neighbor_flap,
13315 show_bgp_instance_neighbor_flap_cmd,
13316 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 13317 SHOW_STR
13318 BGP_STR
8386ac43 13319 BGP_INSTANCE_HELP_STR
bb46e94f 13320 "Detailed information on TCP and BGP neighbor connections\n"
13321 "Neighbor to display information about\n"
13322 "Neighbor to display information about\n"
a80beece 13323 "Neighbor on bgp configured interface\n"
856ca177
MS
13324 "Display flap statistics of the routes learned from neighbor\n"
13325 "JavaScript Object Notation\n")
bb46e94f 13326{
13327 struct peer *peer;
db7c8528 13328 u_char uj = use_json(argc, argv);
856ca177 13329
6aeb9e78
DS
13330 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13331 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13332 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
bb46e94f 13333 else
6aeb9e78 13334 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 13335
13336 if (! peer)
13337 return CMD_WARNING;
13338
13339 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
db7c8528 13340 bgp_show_type_flap_neighbor, uj);
bb46e94f 13341}
13342
8386ac43 13343ALIAS (show_bgp_instance_neighbor_flap,
13344 show_bgp_instance_ipv6_neighbor_flap_cmd,
13345 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 13346 SHOW_STR
13347 BGP_STR
8386ac43 13348 BGP_INSTANCE_HELP_STR
bb46e94f 13349 "Address family\n"
13350 "Detailed information on TCP and BGP neighbor connections\n"
13351 "Neighbor to display information about\n"
13352 "Neighbor to display information about\n"
a80beece 13353 "Neighbor on bgp configured interface\n"
856ca177
MS
13354 "Display flap statistics of the routes learned from neighbor\n"
13355 "JavaScript Object Notation\n")
bb46e94f 13356
50ef26d4 13357DEFUN (show_bgp_neighbor_routes,
bb46e94f 13358 show_bgp_neighbor_routes_cmd,
856ca177 13359 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
bb46e94f 13360 SHOW_STR
13361 BGP_STR
13362 "Detailed information on TCP and BGP neighbor connections\n"
13363 "Neighbor to display information about\n"
13364 "Neighbor to display information about\n"
a80beece 13365 "Neighbor on bgp configured interface\n"
856ca177
MS
13366 "Display routes learned from neighbor\n"
13367 "JavaScript Object Notation\n")
50ef26d4 13368{
13369 struct peer *peer;
13370 u_char uj = use_json(argc, argv);
bb46e94f 13371
50ef26d4 13372 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13373 if (! peer)
13374 return CMD_WARNING;
bb46e94f 13375
50ef26d4 13376 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13377 bgp_show_type_neighbor, uj);
13378}
13379
13380
13381ALIAS (show_bgp_neighbor_routes,
718e3744 13382 show_bgp_ipv6_neighbor_routes_cmd,
856ca177 13383 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13384 SHOW_STR
13385 BGP_STR
13386 "Address family\n"
13387 "Detailed information on TCP and BGP neighbor connections\n"
13388 "Neighbor to display information about\n"
13389 "Neighbor to display information about\n"
a80beece 13390 "Neighbor on bgp configured interface\n"
856ca177
MS
13391 "Display routes learned from neighbor\n"
13392 "JavaScript Object Notation\n")
718e3744 13393
13394/* old command */
50ef26d4 13395ALIAS (show_bgp_neighbor_routes,
718e3744 13396 ipv6_bgp_neighbor_routes_cmd,
856ca177 13397 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13398 SHOW_STR
13399 IPV6_STR
13400 BGP_STR
13401 "Detailed information on TCP and BGP neighbor connections\n"
13402 "Neighbor to display information about\n"
13403 "Neighbor to display information about\n"
a80beece 13404 "Neighbor on bgp configured interface\n"
856ca177
MS
13405 "Display routes learned from neighbor\n"
13406 "JavaScript Object Notation\n")
718e3744 13407
13408/* old command */
13409DEFUN (ipv6_mbgp_neighbor_routes,
13410 ipv6_mbgp_neighbor_routes_cmd,
856ca177 13411 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13412 SHOW_STR
13413 IPV6_STR
13414 MBGP_STR
13415 "Detailed information on TCP and BGP neighbor connections\n"
13416 "Neighbor to display information about\n"
13417 "Neighbor to display information about\n"
a80beece 13418 "Neighbor on bgp configured interface\n"
856ca177
MS
13419 "Display routes learned from neighbor\n"
13420 "JavaScript Object Notation\n")
718e3744 13421{
bb46e94f 13422 struct peer *peer;
db7c8528 13423 u_char uj = use_json(argc, argv);
bb46e94f 13424
db7c8528 13425 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 13426 if (! peer)
13427 return CMD_WARNING;
13428
47e9b292 13429 bgp_show_ipv6_bgp_deprecate_warning(vty);
bb46e94f 13430 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
db7c8528 13431 bgp_show_type_neighbor, uj);
718e3744 13432}
bb46e94f 13433
8386ac43 13434ALIAS (show_bgp_instance_neighbor_flap,
bb46e94f 13435 show_bgp_neighbor_flap_cmd,
856ca177 13436 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 13437 SHOW_STR
13438 BGP_STR
13439 "Detailed information on TCP and BGP neighbor connections\n"
13440 "Neighbor to display information about\n"
13441 "Neighbor to display information about\n"
a80beece 13442 "Neighbor on bgp configured interface\n"
856ca177
MS
13443 "Display flap statistics of the routes learned from neighbor\n"
13444 "JavaScript Object Notation\n")
bb46e94f 13445
8386ac43 13446ALIAS (show_bgp_instance_neighbor_flap,
bb46e94f 13447 show_bgp_ipv6_neighbor_flap_cmd,
856ca177 13448 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 13449 SHOW_STR
13450 BGP_STR
13451 "Address family\n"
13452 "Detailed information on TCP and BGP neighbor connections\n"
13453 "Neighbor to display information about\n"
13454 "Neighbor to display information about\n"
a80beece 13455 "Neighbor on bgp configured interface\n"
856ca177
MS
13456 "Display flap statistics of the routes learned from neighbor\n"
13457 "JavaScript Object Notation\n")
bb46e94f 13458
8386ac43 13459ALIAS (show_bgp_instance_neighbor_damp,
bb46e94f 13460 show_bgp_neighbor_damp_cmd,
856ca177 13461 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
bb46e94f 13462 SHOW_STR
13463 BGP_STR
13464 "Detailed information on TCP and BGP neighbor connections\n"
13465 "Neighbor to display information about\n"
13466 "Neighbor to display information about\n"
a80beece 13467 "Neighbor on bgp configured interface\n"
856ca177
MS
13468 "Display the dampened routes received from neighbor\n"
13469 "JavaScript Object Notation\n")
bb46e94f 13470
8386ac43 13471ALIAS (show_bgp_instance_neighbor_damp,
bb46e94f 13472 show_bgp_ipv6_neighbor_damp_cmd,
856ca177 13473 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
bb46e94f 13474 SHOW_STR
13475 BGP_STR
13476 "Address family\n"
13477 "Detailed information on TCP and BGP neighbor connections\n"
13478 "Neighbor to display information about\n"
13479 "Neighbor to display information about\n"
a80beece 13480 "Neighbor on bgp configured interface\n"
856ca177
MS
13481 "Display the dampened routes received from neighbor\n"
13482 "JavaScript Object Notation\n")
fee0f4c6 13483
718e3744 13484#endif /* HAVE_IPV6 */
6b0655a2 13485
718e3744 13486struct bgp_table *bgp_distance_table;
13487
13488struct bgp_distance
13489{
13490 /* Distance value for the IP source prefix. */
13491 u_char distance;
13492
13493 /* Name of the access-list to be matched. */
13494 char *access_list;
13495};
13496
94f2b392 13497static struct bgp_distance *
66e5cd87 13498bgp_distance_new (void)
718e3744 13499{
393deb9b 13500 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
718e3744 13501}
13502
94f2b392 13503static void
718e3744 13504bgp_distance_free (struct bgp_distance *bdistance)
13505{
13506 XFREE (MTYPE_BGP_DISTANCE, bdistance);
13507}
13508
94f2b392 13509static int
fd79ac91 13510bgp_distance_set (struct vty *vty, const char *distance_str,
13511 const char *ip_str, const char *access_list_str)
718e3744 13512{
13513 int ret;
13514 struct prefix_ipv4 p;
13515 u_char distance;
13516 struct bgp_node *rn;
13517 struct bgp_distance *bdistance;
13518
13519 ret = str2prefix_ipv4 (ip_str, &p);
13520 if (ret == 0)
13521 {
13522 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13523 return CMD_WARNING;
13524 }
13525
13526 distance = atoi (distance_str);
13527
13528 /* Get BGP distance node. */
13529 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
13530 if (rn->info)
13531 {
13532 bdistance = rn->info;
13533 bgp_unlock_node (rn);
13534 }
13535 else
13536 {
13537 bdistance = bgp_distance_new ();
13538 rn->info = bdistance;
13539 }
13540
13541 /* Set distance value. */
13542 bdistance->distance = distance;
13543
13544 /* Reset access-list configuration. */
13545 if (bdistance->access_list)
13546 {
6e919709 13547 XFREE(MTYPE_AS_LIST, bdistance->access_list);
718e3744 13548 bdistance->access_list = NULL;
13549 }
13550 if (access_list_str)
6e919709 13551 bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str);
718e3744 13552
13553 return CMD_SUCCESS;
13554}
13555
94f2b392 13556static int
fd79ac91 13557bgp_distance_unset (struct vty *vty, const char *distance_str,
13558 const char *ip_str, const char *access_list_str)
718e3744 13559{
13560 int ret;
1f9a9fff 13561 int distance;
718e3744 13562 struct prefix_ipv4 p;
718e3744 13563 struct bgp_node *rn;
13564 struct bgp_distance *bdistance;
13565
13566 ret = str2prefix_ipv4 (ip_str, &p);
13567 if (ret == 0)
13568 {
13569 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13570 return CMD_WARNING;
13571 }
13572
718e3744 13573 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
13574 if (! rn)
13575 {
13576 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
13577 return CMD_WARNING;
13578 }
13579
13580 bdistance = rn->info;
1f9a9fff
PJ
13581 distance = atoi(distance_str);
13582
13583 if (bdistance->distance != distance)
13584 {
13585 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
13586 return CMD_WARNING;
13587 }
718e3744 13588
13589 if (bdistance->access_list)
6e919709 13590 XFREE(MTYPE_AS_LIST, bdistance->access_list);
718e3744 13591 bgp_distance_free (bdistance);
13592
13593 rn->info = NULL;
13594 bgp_unlock_node (rn);
13595 bgp_unlock_node (rn);
13596
13597 return CMD_SUCCESS;
13598}
13599
718e3744 13600/* Apply BGP information to distance method. */
13601u_char
13602bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
13603{
13604 struct bgp_node *rn;
13605 struct prefix_ipv4 q;
13606 struct peer *peer;
13607 struct bgp_distance *bdistance;
13608 struct access_list *alist;
13609 struct bgp_static *bgp_static;
13610
13611 if (! bgp)
13612 return 0;
13613
13614 if (p->family != AF_INET)
13615 return 0;
13616
13617 peer = rinfo->peer;
13618
13619 if (peer->su.sa.sa_family != AF_INET)
13620 return 0;
13621
13622 memset (&q, 0, sizeof (struct prefix_ipv4));
13623 q.family = AF_INET;
13624 q.prefix = peer->su.sin.sin_addr;
13625 q.prefixlen = IPV4_MAX_BITLEN;
13626
13627 /* Check source address. */
13628 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
13629 if (rn)
13630 {
13631 bdistance = rn->info;
13632 bgp_unlock_node (rn);
13633
13634 if (bdistance->access_list)
13635 {
13636 alist = access_list_lookup (AFI_IP, bdistance->access_list);
13637 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
13638 return bdistance->distance;
13639 }
13640 else
13641 return bdistance->distance;
13642 }
13643
13644 /* Backdoor check. */
13645 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
13646 if (rn)
13647 {
13648 bgp_static = rn->info;
13649 bgp_unlock_node (rn);
13650
13651 if (bgp_static->backdoor)
13652 {
13653 if (bgp->distance_local)
13654 return bgp->distance_local;
13655 else
13656 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13657 }
13658 }
13659
6d85b15b 13660 if (peer->sort == BGP_PEER_EBGP)
718e3744 13661 {
13662 if (bgp->distance_ebgp)
13663 return bgp->distance_ebgp;
13664 return ZEBRA_EBGP_DISTANCE_DEFAULT;
13665 }
13666 else
13667 {
13668 if (bgp->distance_ibgp)
13669 return bgp->distance_ibgp;
13670 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13671 }
13672}
13673
13674DEFUN (bgp_distance,
13675 bgp_distance_cmd,
13676 "distance bgp <1-255> <1-255> <1-255>",
13677 "Define an administrative distance\n"
13678 "BGP distance\n"
13679 "Distance for routes external to the AS\n"
13680 "Distance for routes internal to the AS\n"
13681 "Distance for local routes\n")
13682{
13683 struct bgp *bgp;
13684
13685 bgp = vty->index;
13686
13687 bgp->distance_ebgp = atoi (argv[0]);
13688 bgp->distance_ibgp = atoi (argv[1]);
13689 bgp->distance_local = atoi (argv[2]);
13690 return CMD_SUCCESS;
13691}
13692
13693DEFUN (no_bgp_distance,
13694 no_bgp_distance_cmd,
13695 "no distance bgp <1-255> <1-255> <1-255>",
13696 NO_STR
13697 "Define an administrative distance\n"
13698 "BGP distance\n"
13699 "Distance for routes external to the AS\n"
13700 "Distance for routes internal to the AS\n"
13701 "Distance for local routes\n")
13702{
13703 struct bgp *bgp;
13704
13705 bgp = vty->index;
13706
13707 bgp->distance_ebgp= 0;
13708 bgp->distance_ibgp = 0;
13709 bgp->distance_local = 0;
13710 return CMD_SUCCESS;
13711}
13712
13713ALIAS (no_bgp_distance,
13714 no_bgp_distance2_cmd,
13715 "no distance bgp",
13716 NO_STR
13717 "Define an administrative distance\n"
13718 "BGP distance\n")
13719
13720DEFUN (bgp_distance_source,
13721 bgp_distance_source_cmd,
13722 "distance <1-255> A.B.C.D/M",
13723 "Define an administrative distance\n"
13724 "Administrative distance\n"
13725 "IP source prefix\n")
13726{
13727 bgp_distance_set (vty, argv[0], argv[1], NULL);
13728 return CMD_SUCCESS;
13729}
13730
13731DEFUN (no_bgp_distance_source,
13732 no_bgp_distance_source_cmd,
13733 "no distance <1-255> A.B.C.D/M",
13734 NO_STR
13735 "Define an administrative distance\n"
13736 "Administrative distance\n"
13737 "IP source prefix\n")
13738{
13739 bgp_distance_unset (vty, argv[0], argv[1], NULL);
13740 return CMD_SUCCESS;
13741}
13742
13743DEFUN (bgp_distance_source_access_list,
13744 bgp_distance_source_access_list_cmd,
13745 "distance <1-255> A.B.C.D/M WORD",
13746 "Define an administrative distance\n"
13747 "Administrative distance\n"
13748 "IP source prefix\n"
13749 "Access list name\n")
13750{
13751 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
13752 return CMD_SUCCESS;
13753}
13754
13755DEFUN (no_bgp_distance_source_access_list,
13756 no_bgp_distance_source_access_list_cmd,
13757 "no distance <1-255> A.B.C.D/M WORD",
13758 NO_STR
13759 "Define an administrative distance\n"
13760 "Administrative distance\n"
13761 "IP source prefix\n"
13762 "Access list name\n")
13763{
13764 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
13765 return CMD_SUCCESS;
13766}
6b0655a2 13767
718e3744 13768DEFUN (bgp_damp_set,
13769 bgp_damp_set_cmd,
13770 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13771 "BGP Specific commands\n"
13772 "Enable route-flap dampening\n"
13773 "Half-life time for the penalty\n"
13774 "Value to start reusing a route\n"
13775 "Value to start suppressing a route\n"
13776 "Maximum duration to suppress a stable route\n")
13777{
13778 struct bgp *bgp;
13779 int half = DEFAULT_HALF_LIFE * 60;
13780 int reuse = DEFAULT_REUSE;
13781 int suppress = DEFAULT_SUPPRESS;
13782 int max = 4 * half;
13783
13784 if (argc == 4)
13785 {
13786 half = atoi (argv[0]) * 60;
13787 reuse = atoi (argv[1]);
13788 suppress = atoi (argv[2]);
13789 max = atoi (argv[3]) * 60;
13790 }
13791 else if (argc == 1)
13792 {
13793 half = atoi (argv[0]) * 60;
13794 max = 4 * half;
13795 }
13796
13797 bgp = vty->index;
7ebe9748
B
13798
13799 if (suppress < reuse)
13800 {
13801 vty_out (vty, "Suppress value cannot be less than reuse value %s",
13802 VTY_NEWLINE);
13803 return 0;
13804 }
13805
718e3744 13806 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
13807 half, reuse, suppress, max);
13808}
13809
13810ALIAS (bgp_damp_set,
13811 bgp_damp_set2_cmd,
13812 "bgp dampening <1-45>",
13813 "BGP Specific commands\n"
13814 "Enable route-flap dampening\n"
13815 "Half-life time for the penalty\n")
13816
13817ALIAS (bgp_damp_set,
13818 bgp_damp_set3_cmd,
13819 "bgp dampening",
13820 "BGP Specific commands\n"
13821 "Enable route-flap dampening\n")
13822
13823DEFUN (bgp_damp_unset,
13824 bgp_damp_unset_cmd,
13825 "no bgp dampening",
13826 NO_STR
13827 "BGP Specific commands\n"
13828 "Enable route-flap dampening\n")
13829{
13830 struct bgp *bgp;
13831
13832 bgp = vty->index;
13833 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
13834}
13835
13836ALIAS (bgp_damp_unset,
13837 bgp_damp_unset2_cmd,
13838 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13839 NO_STR
13840 "BGP Specific commands\n"
13841 "Enable route-flap dampening\n"
13842 "Half-life time for the penalty\n"
13843 "Value to start reusing a route\n"
13844 "Value to start suppressing a route\n"
13845 "Maximum duration to suppress a stable route\n")
13846
813d4307
DW
13847ALIAS (bgp_damp_unset,
13848 bgp_damp_unset3_cmd,
13849 "no bgp dampening <1-45>",
13850 NO_STR
13851 "BGP Specific commands\n"
13852 "Enable route-flap dampening\n"
13853 "Half-life time for the penalty\n")
13854
718e3744 13855DEFUN (show_ip_bgp_dampened_paths,
13856 show_ip_bgp_dampened_paths_cmd,
13857 "show ip bgp dampened-paths",
13858 SHOW_STR
13859 IP_STR
13860 BGP_STR
13861 "Display paths suppressed due to dampening\n")
13862{
5a646650 13863 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
b05a1c8b 13864 NULL, 0);
718e3744 13865}
13866
81304aaf
B
13867ALIAS (show_ip_bgp_dampened_paths,
13868 show_ip_bgp_damp_dampened_paths_cmd,
13869 "show ip bgp dampening dampened-paths",
13870 SHOW_STR
13871 IP_STR
13872 BGP_STR
13873 "Display detailed information about dampening\n"
13874 "Display paths suppressed due to dampening\n")
13875
718e3744 13876DEFUN (show_ip_bgp_flap_statistics,
13877 show_ip_bgp_flap_statistics_cmd,
13878 "show ip bgp flap-statistics",
13879 SHOW_STR
13880 IP_STR
13881 BGP_STR
13882 "Display flap statistics of routes\n")
13883{
5a646650 13884 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 13885 bgp_show_type_flap_statistics, NULL, 0);
718e3744 13886}
6b0655a2 13887
81304aaf
B
13888ALIAS (show_ip_bgp_flap_statistics,
13889 show_ip_bgp_damp_flap_statistics_cmd,
13890 "show ip bgp dampening flap-statistics",
13891 SHOW_STR
13892 IP_STR
13893 BGP_STR
13894 "Display detailed information about dampening\n"
13895 "Display flap statistics of routes\n")
13896
718e3744 13897/* Display specified route of BGP table. */
94f2b392 13898static int
fd79ac91 13899bgp_clear_damp_route (struct vty *vty, const char *view_name,
13900 const char *ip_str, afi_t afi, safi_t safi,
13901 struct prefix_rd *prd, int prefix_check)
718e3744 13902{
13903 int ret;
13904 struct prefix match;
13905 struct bgp_node *rn;
13906 struct bgp_node *rm;
13907 struct bgp_info *ri;
13908 struct bgp_info *ri_temp;
13909 struct bgp *bgp;
13910 struct bgp_table *table;
13911
13912 /* BGP structure lookup. */
13913 if (view_name)
13914 {
13915 bgp = bgp_lookup_by_name (view_name);
13916 if (bgp == NULL)
13917 {
6aeb9e78 13918 vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
718e3744 13919 return CMD_WARNING;
13920 }
13921 }
13922 else
13923 {
13924 bgp = bgp_get_default ();
13925 if (bgp == NULL)
13926 {
13927 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
13928 return CMD_WARNING;
13929 }
13930 }
13931
13932 /* Check IP address argument. */
13933 ret = str2prefix (ip_str, &match);
13934 if (! ret)
13935 {
13936 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
13937 return CMD_WARNING;
13938 }
13939
13940 match.family = afi2family (afi);
13941
587ff0fd 13942 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 13943 {
587ff0fd 13944 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
718e3744 13945 {
13946 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
13947 continue;
13948
13949 if ((table = rn->info) != NULL)
13950 if ((rm = bgp_node_match (table, &match)) != NULL)
6c88b44d
CC
13951 {
13952 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
13953 {
13954 ri = rm->info;
13955 while (ri)
13956 {
13957 if (ri->extra && ri->extra->damp_info)
13958 {
13959 ri_temp = ri->next;
13960 bgp_damp_info_free (ri->extra->damp_info, 1);
13961 ri = ri_temp;
13962 }
13963 else
13964 ri = ri->next;
13965 }
13966 }
13967
13968 bgp_unlock_node (rm);
13969 }
718e3744 13970 }
13971 }
13972 else
13973 {
13974 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
6c88b44d
CC
13975 {
13976 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
13977 {
13978 ri = rn->info;
13979 while (ri)
13980 {
13981 if (ri->extra && ri->extra->damp_info)
13982 {
13983 ri_temp = ri->next;
13984 bgp_damp_info_free (ri->extra->damp_info, 1);
13985 ri = ri_temp;
13986 }
13987 else
13988 ri = ri->next;
13989 }
13990 }
13991
13992 bgp_unlock_node (rn);
13993 }
718e3744 13994 }
13995
13996 return CMD_SUCCESS;
13997}
13998
13999DEFUN (clear_ip_bgp_dampening,
14000 clear_ip_bgp_dampening_cmd,
14001 "clear ip bgp dampening",
14002 CLEAR_STR
14003 IP_STR
14004 BGP_STR
14005 "Clear route flap dampening information\n")
14006{
14007 bgp_damp_info_clean ();
14008 return CMD_SUCCESS;
14009}
14010
14011DEFUN (clear_ip_bgp_dampening_prefix,
14012 clear_ip_bgp_dampening_prefix_cmd,
14013 "clear ip bgp dampening A.B.C.D/M",
14014 CLEAR_STR
14015 IP_STR
14016 BGP_STR
14017 "Clear route flap dampening information\n"
14018 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14019{
14020 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14021 SAFI_UNICAST, NULL, 1);
14022}
14023
14024DEFUN (clear_ip_bgp_dampening_address,
14025 clear_ip_bgp_dampening_address_cmd,
14026 "clear ip bgp dampening A.B.C.D",
14027 CLEAR_STR
14028 IP_STR
14029 BGP_STR
14030 "Clear route flap dampening information\n"
14031 "Network to clear damping information\n")
14032{
14033 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14034 SAFI_UNICAST, NULL, 0);
14035}
14036
14037DEFUN (clear_ip_bgp_dampening_address_mask,
14038 clear_ip_bgp_dampening_address_mask_cmd,
14039 "clear ip bgp dampening A.B.C.D A.B.C.D",
14040 CLEAR_STR
14041 IP_STR
14042 BGP_STR
14043 "Clear route flap dampening information\n"
14044 "Network to clear damping information\n"
14045 "Network mask\n")
14046{
14047 int ret;
14048 char prefix_str[BUFSIZ];
14049
14050 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
14051 if (! ret)
14052 {
14053 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
14054 return CMD_WARNING;
14055 }
14056
14057 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
14058 SAFI_UNICAST, NULL, 0);
14059}
6b0655a2 14060
587ff0fd 14061/* also used for encap safi */
94f2b392 14062static int
718e3744 14063bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
14064 afi_t afi, safi_t safi, int *write)
14065{
14066 struct bgp_node *prn;
14067 struct bgp_node *rn;
14068 struct bgp_table *table;
14069 struct prefix *p;
14070 struct prefix_rd *prd;
14071 struct bgp_static *bgp_static;
14072 u_int32_t label;
14073 char buf[SU_ADDRSTRLEN];
14074 char rdbuf[RD_ADDRSTRLEN];
14075
14076 /* Network configuration. */
14077 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
14078 if ((table = prn->info) != NULL)
14079 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
14080 if ((bgp_static = rn->info) != NULL)
14081 {
14082 p = &rn->p;
14083 prd = (struct prefix_rd *) &prn->p;
14084
14085 /* "address-family" display. */
14086 bgp_config_write_family_header (vty, afi, safi, write);
14087
14088 /* "network" configuration display. */
14089 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
14090 label = decode_label (bgp_static->tag);
14091
0b960b4d 14092 vty_out (vty, " network %s/%d rd %s tag %d",
718e3744 14093 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14094 p->prefixlen,
14095 rdbuf, label);
14096 vty_out (vty, "%s", VTY_NEWLINE);
14097 }
14098 return 0;
14099}
14100
14101/* Configuration of static route announcement and aggregate
14102 information. */
14103int
14104bgp_config_write_network (struct vty *vty, struct bgp *bgp,
14105 afi_t afi, safi_t safi, int *write)
14106{
14107 struct bgp_node *rn;
14108 struct prefix *p;
14109 struct bgp_static *bgp_static;
14110 struct bgp_aggregate *bgp_aggregate;
14111 char buf[SU_ADDRSTRLEN];
14112
587ff0fd 14113 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
718e3744 14114 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
14115
14116 /* Network configuration. */
14117 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
14118 if ((bgp_static = rn->info) != NULL)
14119 {
14120 p = &rn->p;
14121
14122 /* "address-family" display. */
14123 bgp_config_write_family_header (vty, afi, safi, write);
14124
14125 /* "network" configuration display. */
14126 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14127 {
14128 u_int32_t destination;
14129 struct in_addr netmask;
14130
14131 destination = ntohl (p->u.prefix4.s_addr);
14132 masklen2ip (p->prefixlen, &netmask);
0b960b4d 14133 vty_out (vty, " network %s",
718e3744 14134 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
14135
14136 if ((IN_CLASSC (destination) && p->prefixlen == 24)
14137 || (IN_CLASSB (destination) && p->prefixlen == 16)
14138 || (IN_CLASSA (destination) && p->prefixlen == 8)
14139 || p->u.prefix4.s_addr == 0)
14140 {
14141 /* Natural mask is not display. */
14142 }
14143 else
14144 vty_out (vty, " mask %s", inet_ntoa (netmask));
14145 }
14146 else
14147 {
0b960b4d 14148 vty_out (vty, " network %s/%d",
718e3744 14149 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14150 p->prefixlen);
14151 }
14152
14153 if (bgp_static->rmap.name)
14154 vty_out (vty, " route-map %s", bgp_static->rmap.name);
41367172
PJ
14155 else
14156 {
14157 if (bgp_static->backdoor)
14158 vty_out (vty, " backdoor");
41367172 14159 }
718e3744 14160
14161 vty_out (vty, "%s", VTY_NEWLINE);
14162 }
14163
14164 /* Aggregate-address configuration. */
14165 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
14166 if ((bgp_aggregate = rn->info) != NULL)
14167 {
14168 p = &rn->p;
14169
14170 /* "address-family" display. */
14171 bgp_config_write_family_header (vty, afi, safi, write);
14172
14173 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14174 {
14175 struct in_addr netmask;
14176
14177 masklen2ip (p->prefixlen, &netmask);
0b960b4d 14178 vty_out (vty, " aggregate-address %s %s",
718e3744 14179 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14180 inet_ntoa (netmask));
14181 }
14182 else
14183 {
0b960b4d 14184 vty_out (vty, " aggregate-address %s/%d",
718e3744 14185 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14186 p->prefixlen);
14187 }
14188
14189 if (bgp_aggregate->as_set)
14190 vty_out (vty, " as-set");
14191
14192 if (bgp_aggregate->summary_only)
14193 vty_out (vty, " summary-only");
14194
14195 vty_out (vty, "%s", VTY_NEWLINE);
14196 }
14197
14198 return 0;
14199}
14200
14201int
14202bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
14203{
14204 struct bgp_node *rn;
14205 struct bgp_distance *bdistance;
14206
14207 /* Distance configuration. */
14208 if (bgp->distance_ebgp
14209 && bgp->distance_ibgp
14210 && bgp->distance_local
14211 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
14212 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
14213 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
14214 vty_out (vty, " distance bgp %d %d %d%s",
14215 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
14216 VTY_NEWLINE);
14217
14218 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
14219 if ((bdistance = rn->info) != NULL)
14220 {
14221 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
14222 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
14223 bdistance->access_list ? bdistance->access_list : "",
14224 VTY_NEWLINE);
14225 }
14226
14227 return 0;
14228}
14229
14230/* Allocate routing table structure and install commands. */
14231void
66e5cd87 14232bgp_route_init (void)
718e3744 14233{
14234 /* Init BGP distance table. */
64e580a7 14235 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
718e3744 14236
14237 /* IPv4 BGP commands. */
73ac8160 14238 install_element (BGP_NODE, &bgp_table_map_cmd);
718e3744 14239 install_element (BGP_NODE, &bgp_network_cmd);
14240 install_element (BGP_NODE, &bgp_network_mask_cmd);
14241 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
14242 install_element (BGP_NODE, &bgp_network_route_map_cmd);
14243 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
14244 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
14245 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
14246 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
14247 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
73ac8160 14248 install_element (BGP_NODE, &no_bgp_table_map_cmd);
718e3744 14249 install_element (BGP_NODE, &no_bgp_network_cmd);
14250 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
14251 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
14252 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
14253 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
14254 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14255 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
14256 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
14257 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
14258
14259 install_element (BGP_NODE, &aggregate_address_cmd);
14260 install_element (BGP_NODE, &aggregate_address_mask_cmd);
14261 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
14262 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
14263 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
14264 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
14265 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
14266 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
14267 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
14268 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
14269 install_element (BGP_NODE, &no_aggregate_address_cmd);
14270 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
14271 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
14272 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
14273 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
14274 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
14275 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
14276 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
14277 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14278 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14279
14280 /* IPv4 unicast configuration. */
73ac8160 14281 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
718e3744 14282 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
14283 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
14284 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
14285 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
14286 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
14287 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 14288 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
c8f3fe30 14289 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
718e3744 14290 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
14291 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
14292 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
14293 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
14294 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
c8f3fe30 14295
718e3744 14296 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
14297 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
14298 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
14299 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
14300 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
14301 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
14302 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
14303 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
14304 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
14305 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
14306 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
14307 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
14308 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
14309 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
14310 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
14311 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
14312 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
14313 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
14314 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14315 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14316
14317 /* IPv4 multicast configuration. */
73ac8160 14318 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
718e3744 14319 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
14320 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
14321 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
14322 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
14323 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
14324 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 14325 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
718e3744 14326 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
14327 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
14328 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
14329 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
14330 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
14331 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14332 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
14333 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
14334 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
14335 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
14336 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
14337 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
14338 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
14339 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
14340 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
14341 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
14342 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
14343 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
14344 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
14345 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
14346 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
14347 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
14348 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
14349 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
14350 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14351 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14352
14353 install_element (VIEW_NODE, &show_ip_bgp_cmd);
8386ac43 14354 install_element (VIEW_NODE, &show_ip_bgp_instance_cmd);
f186de26 14355 install_element (VIEW_NODE, &show_ip_bgp_instance_all_cmd);
718e3744 14356 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 14357 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
718e3744 14358 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
8386ac43 14359 install_element (VIEW_NODE, &show_ip_bgp_instance_route_cmd);
4092b06c 14360 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
8386ac43 14361 install_element (VIEW_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
4092b06c 14362 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 14363 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 14364 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 14365 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14366 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14367 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
8386ac43 14368 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd);
718e3744 14369 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
14370 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14371 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 14372 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 14373 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
8386ac43 14374 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
718e3744 14375 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14376 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
50ef26d4 14377
718e3744 14378 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
14379 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14380 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
8386ac43 14381 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_list_cmd);
718e3744 14382 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14383 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
8386ac43 14384 install_element (VIEW_NODE, &show_ip_bgp_instance_filter_list_cmd);
718e3744 14385 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14386 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
8386ac43 14387 install_element (VIEW_NODE, &show_ip_bgp_instance_route_map_cmd);
718e3744 14388 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14389 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
14390 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14391 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
14392 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14393 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
14394 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
14395 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
14396 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
14397 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
14398 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
14399 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
14400 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
8386ac43 14401 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14402 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_cmd);
14403 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14404 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14405 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community4_cmd);
718e3744 14406 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
14407 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
14408 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
14409 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
14410 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14411 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14412 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14413 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14414 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
8386ac43 14415 install_element (VIEW_NODE, &show_ip_bgp_instance_community_list_cmd);
718e3744 14416 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14417 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
14418 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14419 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
8386ac43 14420 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
718e3744 14421 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14422 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
8386ac43 14423 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
0b16f239 14424 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
8386ac43 14425 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
718e3744 14426 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
0b16f239 14427 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
718e3744 14428 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
8386ac43 14429 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
0b16f239 14430 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
8386ac43 14431 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
718e3744 14432 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
0b16f239 14433 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
8386ac43 14434 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 14435 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
8386ac43 14436 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
718e3744 14437 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14438 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14439 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
81304aaf 14440 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
718e3744 14441 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
81304aaf 14442 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
718e3744 14443 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
81304aaf 14444 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
718e3744 14445 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
81304aaf 14446 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
718e3744 14447 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
14448 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
81304aaf 14449 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
718e3744 14450 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
14451 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
81304aaf 14452 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
718e3744 14453 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
81304aaf 14454 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
718e3744 14455 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
81304aaf 14456 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
718e3744 14457 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
81304aaf 14458 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
718e3744 14459 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
14460 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
62687ff1
PJ
14461
14462 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
14463 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
8386ac43 14464 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_cmd);
4092b06c 14465 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
8386ac43 14466 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
4092b06c 14467 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
62687ff1 14468 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 14469 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
62687ff1
PJ
14470 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14471 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
8386ac43 14472 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_cmd);
62687ff1 14473 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
14474 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14475 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 14476 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 14477 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
8386ac43 14478 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
62687ff1
PJ
14479 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14480 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
8386ac43 14481 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_cmd);
14482 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_cmd);
62687ff1
PJ
14483 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
14484 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
14485 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
14486 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
14487 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
14488 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
14489 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
14490 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
8386ac43 14491 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14492 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community_cmd);
14493 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14494 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14495 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community4_cmd);
62687ff1
PJ
14496 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
14497 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
14498 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
14499 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
14500 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14501 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14502 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14503 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
718e3744 14504
14505 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
8386ac43 14506 install_element (ENABLE_NODE, &show_ip_bgp_instance_cmd);
f186de26 14507 install_element (ENABLE_NODE, &show_ip_bgp_instance_all_cmd);
718e3744 14508 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 14509 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
718e3744 14510 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
8386ac43 14511 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_cmd);
4092b06c 14512 install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd);
8386ac43 14513 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
4092b06c 14514 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 14515 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 14516 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 14517 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14518 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14519 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
8386ac43 14520 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_cmd);
718e3744 14521 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
14522 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14523 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 14524 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 14525 install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd);
8386ac43 14526 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
718e3744 14527 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14528 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
50ef26d4 14529
718e3744 14530 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
14531 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14532 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
8386ac43 14533 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_list_cmd);
718e3744 14534 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14535 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
8386ac43 14536 install_element (ENABLE_NODE, &show_ip_bgp_instance_filter_list_cmd);
718e3744 14537 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14538 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
8386ac43 14539 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_map_cmd);
718e3744 14540 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14541 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
14542 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14543 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
14544 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14545 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
14546 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
14547 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
14548 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
14549 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
14550 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
14551 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
14552 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
8386ac43 14553 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14554 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community_cmd);
14555 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14556 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14557 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community4_cmd);
718e3744 14558 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
14559 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
14560 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
14561 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
14562 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14563 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14564 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14565 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14566 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
8386ac43 14567 install_element (ENABLE_NODE, &show_ip_bgp_instance_community_list_cmd);
718e3744 14568 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14569 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
14570 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14571 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
8386ac43 14572 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
718e3744 14573 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14574 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
8386ac43 14575 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
0b16f239 14576 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
8386ac43 14577 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
718e3744 14578 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
0b16f239 14579 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
718e3744 14580 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
8386ac43 14581 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
0b16f239 14582 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
8386ac43 14583 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
718e3744 14584 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
0b16f239 14585 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
8386ac43 14586 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 14587 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
8386ac43 14588 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
718e3744 14589 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14590 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14591 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
81304aaf 14592 install_element (ENABLE_NODE, &show_ip_bgp_dampening_params_cmd);
718e3744 14593 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
81304aaf 14594 install_element (ENABLE_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
718e3744 14595 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
81304aaf 14596 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
718e3744 14597 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
81304aaf 14598 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_address_cmd);
718e3744 14599 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
14600 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
81304aaf 14601 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
718e3744 14602 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
81304aaf 14603 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_regexp_cmd);
718e3744 14604 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
81304aaf 14605 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
718e3744 14606 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
81304aaf
B
14607 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
14608 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
718e3744 14609 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
81304aaf 14610 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
718e3744 14611 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
81304aaf 14612 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
718e3744 14613 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
14614 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
14615
14616 /* BGP dampening clear commands */
14617 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
14618 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
14619 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
14620 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
14621
ff7924f6
PJ
14622 /* prefix count */
14623 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
8386ac43 14624 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd);
ff7924f6
PJ
14625 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
14626 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
718e3744 14627#ifdef HAVE_IPV6
ff7924f6 14628 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
8386ac43 14629 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd);
ff7924f6 14630
718e3744 14631 /* New config IPv6 BGP commands. */
73ac8160 14632 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
718e3744 14633 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
14634 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
73ac8160 14635 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
718e3744 14636 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
14637 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
14638
14639 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
14640 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
14641 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
14642 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
73bfe0bd
B
14643
14644 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
14645 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
718e3744 14646
14647 /* Old config IPv6 BGP commands. */
14648 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
14649 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
14650
14651 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
14652 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
14653 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
14654 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
14655
14656 install_element (VIEW_NODE, &show_bgp_cmd);
14657 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 14658 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 14659 install_element (VIEW_NODE, &show_bgp_route_cmd);
14660 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 14661 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
14662 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
14663 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14664 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 14665 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
14666 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 14667 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c
DS
14668 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
14669 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14670 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 14671 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
14672 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
14673 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
14674 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
14675 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
14676 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
14677 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
14678 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
14679 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
14680 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
14681 install_element (VIEW_NODE, &show_bgp_community_cmd);
14682 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
14683 install_element (VIEW_NODE, &show_bgp_community2_cmd);
14684 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
14685 install_element (VIEW_NODE, &show_bgp_community3_cmd);
14686 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
14687 install_element (VIEW_NODE, &show_bgp_community4_cmd);
14688 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
14689 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
14690 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
14691 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
14692 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
14693 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
14694 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
14695 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
14696 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
14697 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
14698 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
14699 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
14700 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14701 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
14702 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14703 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
14704 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14705 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
14706 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14707 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
14708 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14709 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14710 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 14711 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
14712 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14713 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
14714 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
8386ac43 14715 install_element (VIEW_NODE, &show_bgp_instance_cmd);
f186de26 14716 install_element (VIEW_NODE, &show_bgp_instance_all_cmd);
8386ac43 14717 install_element (VIEW_NODE, &show_bgp_instance_ipv6_cmd);
14718 install_element (VIEW_NODE, &show_bgp_instance_route_cmd);
14719 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_cmd);
14720 install_element (VIEW_NODE, &show_bgp_instance_route_pathtype_cmd);
14721 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14722 install_element (VIEW_NODE, &show_bgp_instance_prefix_cmd);
14723 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14724 install_element (VIEW_NODE, &show_bgp_instance_prefix_pathtype_cmd);
14725 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
14726 install_element (VIEW_NODE, &show_bgp_instance_prefix_list_cmd);
14727 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
14728 install_element (VIEW_NODE, &show_bgp_instance_filter_list_cmd);
14729 install_element (VIEW_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
14730 install_element (VIEW_NODE, &show_bgp_instance_route_map_cmd);
14731 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_map_cmd);
14732 install_element (VIEW_NODE, &show_bgp_instance_community_list_cmd);
14733 install_element (VIEW_NODE, &show_bgp_instance_ipv6_community_list_cmd);
14734 install_element (VIEW_NODE, &show_bgp_instance_prefix_longer_cmd);
14735 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
14736 install_element (VIEW_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
14737 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
14738 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
14739 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
14740 install_element (VIEW_NODE, &show_bgp_instance_neighbor_routes_cmd);
14741 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
14742 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14743 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14744 install_element (VIEW_NODE, &show_bgp_instance_neighbor_flap_cmd);
14745 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
14746 install_element (VIEW_NODE, &show_bgp_instance_neighbor_damp_cmd);
14747 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
62687ff1
PJ
14748
14749 /* Restricted:
14750 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
14751 */
14752 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
14753 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 14754 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
14755 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
14756 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14757 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
62687ff1
PJ
14758 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
14759 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 14760 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c
DS
14761 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
14762 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14763 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
62687ff1
PJ
14764 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
14765 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
14766 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
14767 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
14768 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
14769 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
14770 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
14771 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
14772 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
14773 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
14774 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
14775 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
14776 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
14777 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
14778 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
14779 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
8386ac43 14780 install_element (RESTRICTED_NODE, &show_bgp_instance_route_cmd);
14781 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_route_cmd);
14782 install_element (RESTRICTED_NODE, &show_bgp_instance_route_pathtype_cmd);
14783 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14784 install_element (RESTRICTED_NODE, &show_bgp_instance_prefix_cmd);
14785 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14786 install_element (RESTRICTED_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14787 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
718e3744 14788
14789 install_element (ENABLE_NODE, &show_bgp_cmd);
14790 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 14791 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 14792 install_element (ENABLE_NODE, &show_bgp_route_cmd);
14793 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 14794 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
14795 install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd);
14796 install_element (ENABLE_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14797 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 14798 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
4092b06c
DS
14799 install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd);
14800 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14801 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 14802 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 14803 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
718e3744 14804 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
14805 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
14806 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
14807 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
14808 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
14809 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
14810 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
14811 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
14812 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
14813 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
14814 install_element (ENABLE_NODE, &show_bgp_community_cmd);
14815 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
14816 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
14817 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
14818 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
14819 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
14820 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
14821 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
14822 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
14823 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
14824 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
14825 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
14826 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
14827 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
14828 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
14829 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
14830 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
14831 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
14832 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
14833 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14834 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
14835 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14836 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
14837 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14838 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
14839 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14840 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
14841 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14842 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14843 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 14844 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
14845 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14846 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
14847 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
8386ac43 14848 install_element (ENABLE_NODE, &show_bgp_instance_cmd);
f186de26 14849 install_element (ENABLE_NODE, &show_bgp_instance_all_cmd);
8386ac43 14850 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_cmd);
14851 install_element (ENABLE_NODE, &show_bgp_instance_route_cmd);
14852 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_cmd);
14853 install_element (ENABLE_NODE, &show_bgp_instance_route_pathtype_cmd);
14854 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14855 install_element (ENABLE_NODE, &show_bgp_instance_prefix_cmd);
14856 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14857 install_element (ENABLE_NODE, &show_bgp_instance_prefix_pathtype_cmd);
14858 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
14859 install_element (ENABLE_NODE, &show_bgp_instance_prefix_list_cmd);
14860 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
14861 install_element (ENABLE_NODE, &show_bgp_instance_filter_list_cmd);
14862 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
14863 install_element (ENABLE_NODE, &show_bgp_instance_route_map_cmd);
14864 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_map_cmd);
14865 install_element (ENABLE_NODE, &show_bgp_instance_community_list_cmd);
14866 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_community_list_cmd);
14867 install_element (ENABLE_NODE, &show_bgp_instance_prefix_longer_cmd);
14868 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
14869 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
14870 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
14871 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
14872 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
14873 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_routes_cmd);
14874 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
14875 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14876 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14877 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_flap_cmd);
14878 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
14879 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_damp_cmd);
14880 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
50ef26d4 14881
2815e61f
PJ
14882 /* Statistics */
14883 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
587ff0fd 14884 //install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
2815e61f 14885 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
587ff0fd 14886 //install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
2815e61f 14887
718e3744 14888 /* old command */
14889 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
14890 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
14891 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
14892 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
14893 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
14894 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
14895 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
14896 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
14897 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
14898 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
14899 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
14900 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
14901 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
14902 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
14903 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
14904 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
14905 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14906 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14907 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
14908 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
14909 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
14910 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
14911 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14912 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
14913 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
14914 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
14915 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
14916 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
14917 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
14918 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
14919 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14920 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14921 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
14922 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
14923 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
14924 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
bb46e94f 14925
718e3744 14926 /* old command */
14927 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
14928 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
14929 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
14930 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
14931 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
14932 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
14933 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
14934 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
14935 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
14936 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
14937 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
14938 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
14939 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
14940 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
14941 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
14942 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
14943 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14944 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14945 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
14946 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
14947 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
14948 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
14949 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14950 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
14951 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
14952 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
14953 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
14954 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
14955 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
14956 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
14957 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14958 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14959 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
14960 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
14961 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
14962 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
14963
14964 /* old command */
14965 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14966 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14967 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14968 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14969
14970 /* old command */
14971 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14972 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14973 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14974 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14975
14976 /* old command */
14977 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
14978 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
14979 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14980 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14981#endif /* HAVE_IPV6 */
14982
14983 install_element (BGP_NODE, &bgp_distance_cmd);
14984 install_element (BGP_NODE, &no_bgp_distance_cmd);
14985 install_element (BGP_NODE, &no_bgp_distance2_cmd);
14986 install_element (BGP_NODE, &bgp_distance_source_cmd);
14987 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
14988 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
14989 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
14990
14991 install_element (BGP_NODE, &bgp_damp_set_cmd);
14992 install_element (BGP_NODE, &bgp_damp_set2_cmd);
14993 install_element (BGP_NODE, &bgp_damp_set3_cmd);
14994 install_element (BGP_NODE, &bgp_damp_unset_cmd);
14995 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
813d4307 14996 install_element (BGP_NODE, &bgp_damp_unset3_cmd);
718e3744 14997 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
14998 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
14999 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
15000 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
15001 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
813d4307 15002 install_element (BGP_IPV4_NODE, &bgp_damp_unset3_cmd);
718e3744 15003}
228da428
CC
15004
15005void
15006bgp_route_finish (void)
15007{
15008 bgp_table_unlock (bgp_distance_table);
15009 bgp_distance_table = NULL;
15010}