]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_route.c
bgpd: cleanup vty bgp_node_afi/safi utils
[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 }
161995ea 5876
b05a1c8b 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
161995ea
DS
5904 if ((IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global,
5905 &attr->extra->mp_nexthop_local) != 0) &&
5906 !attr->extra->mp_nexthop_prefer_global)
f1aa5d8a
DS
5907 json_object_boolean_true_add(json_nexthop_ll, "used");
5908 else
5909 json_object_boolean_true_add(json_nexthop_global, "used");
5910 }
5911 else
5912 json_object_boolean_true_add(json_nexthop_global, "used");
b05a1c8b
DS
5913 }
5914 else
5915 {
161995ea
DS
5916 /* Display LL if LL/Global both in table unless prefer-global is set */
5917 if (((attr->extra->mp_nexthop_len == 32) &&
5918 !attr->extra->mp_nexthop_prefer_global) ||
5919 (binfo->peer->conf_if))
433e8b67
DS
5920 {
5921 if (binfo->peer->conf_if)
5922 {
5923 len = vty_out (vty, "%s",
5924 binfo->peer->conf_if);
5925 len = 7 - len; /* len of IPv6 addr + max len of def ifname */
5926
5927 if (len < 1)
5928 vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " ");
5929 else
5930 vty_out (vty, "%*s", len, " ");
5931 }
5932 else
5933 {
5934 len = vty_out (vty, "%s",
5935 inet_ntop (AF_INET6,
5936 &attr->extra->mp_nexthop_local,
5937 buf, BUFSIZ));
5938 len = 16 - len;
5939
5940 if (len < 1)
5941 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5942 else
5943 vty_out (vty, "%*s", len, " ");
5944 }
5945 }
5946 else
5947 {
5948 len = vty_out (vty, "%s",
5949 inet_ntop (AF_INET6,
5950 &attr->extra->mp_nexthop_global,
5951 buf, BUFSIZ));
5952 len = 16 - len;
5953
5954 if (len < 1)
5955 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5956 else
5957 vty_out (vty, "%*s", len, " ");
5958 }
b05a1c8b 5959 }
718e3744 5960 }
718e3744 5961
b05a1c8b 5962 /* MED/Metric */
718e3744 5963 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b 5964 if (json_paths)
f1aa5d8a 5965 json_object_int_add(json_path, "med", attr->med);
b05a1c8b
DS
5966 else
5967 vty_out (vty, "%10u", attr->med);
718e3744 5968 else
b05a1c8b
DS
5969 if (!json_paths)
5970 vty_out (vty, " ");
47fc97cc 5971
b05a1c8b 5972 /* Local Pref */
718e3744 5973 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
b05a1c8b 5974 if (json_paths)
f1aa5d8a 5975 json_object_int_add(json_path, "localpref", attr->local_pref);
b05a1c8b
DS
5976 else
5977 vty_out (vty, "%7u", attr->local_pref);
718e3744 5978 else
b05a1c8b
DS
5979 if (!json_paths)
5980 vty_out (vty, " ");
718e3744 5981
b05a1c8b
DS
5982 if (json_paths)
5983 {
5984 if (attr->extra)
f1aa5d8a 5985 json_object_int_add(json_path, "weight", attr->extra->weight);
b05a1c8b 5986 else
f1aa5d8a 5987 json_object_int_add(json_path, "weight", 0);
b05a1c8b
DS
5988 }
5989 else
5990 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
47fc97cc 5991
39e871e6
ST
5992 if (json_paths) {
5993 char buf[BUFSIZ];
5994 json_object_string_add(json_path, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
5995 }
5996
b2518c1e
PJ
5997 /* Print aspath */
5998 if (attr->aspath)
b05a1c8b
DS
5999 {
6000 if (json_paths)
f1aa5d8a 6001 json_object_string_add(json_path, "aspath", attr->aspath->str);
b05a1c8b 6002 else
f1aa5d8a 6003 aspath_print_vty (vty, "%s", attr->aspath, " ");
b05a1c8b 6004 }
47fc97cc 6005
b2518c1e 6006 /* Print origin */
b05a1c8b 6007 if (json_paths)
f1aa5d8a 6008 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
b05a1c8b
DS
6009 else
6010 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 6011 }
856ca177
MS
6012 else
6013 {
6014 if (json_paths)
6015 json_object_string_add(json_path, "alert", "No attributes");
6016 else
6017 vty_out (vty, "No attributes to print%s", VTY_NEWLINE);
6018 }
b05a1c8b
DS
6019
6020 if (json_paths)
f1aa5d8a
DS
6021 {
6022 if (json_nexthop_global || json_nexthop_ll)
6023 {
6024 json_nexthops = json_object_new_array();
6025
6026 if (json_nexthop_global)
6027 json_object_array_add(json_nexthops, json_nexthop_global);
6028
6029 if (json_nexthop_ll)
6030 json_object_array_add(json_nexthops, json_nexthop_ll);
6031
6032 json_object_object_add(json_path, "nexthops", json_nexthops);
6033 }
6034
6035 json_object_array_add(json_paths, json_path);
6036 }
b05a1c8b
DS
6037 else
6038 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6039}
6040
6041/* called from terminal list command */
6042void
856ca177
MS
6043route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi,
6044 u_char use_json, json_object *json_ar)
718e3744 6045{
856ca177
MS
6046 json_object *json_status = NULL;
6047 json_object *json_net = NULL;
6048 char buff[BUFSIZ];
718e3744 6049 /* Route status display. */
856ca177
MS
6050 if (use_json)
6051 {
6052 json_status = json_object_new_object();
6053 json_net = json_object_new_object();
6054 }
6055 else
6056 {
6057 vty_out (vty, "*");
6058 vty_out (vty, ">");
6059 vty_out (vty, " ");
6060 }
718e3744 6061
6062 /* print prefix and mask */
856ca177
MS
6063 if (use_json)
6064 json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ));
6065 else
6066 route_vty_out_route (p, vty);
718e3744 6067
6068 /* Print attribute */
6069 if (attr)
6070 {
856ca177 6071 if (use_json)
718e3744 6072 {
587ff0fd
LB
6073 if (p->family == AF_INET &&
6074 (safi == SAFI_MPLS_VPN ||
6075 safi == SAFI_ENCAP ||
6076 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
856ca177 6077 {
587ff0fd 6078 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
856ca177
MS
6079 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in));
6080 else
6081 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop));
6082 }
6083#ifdef HAVE_IPV6
6084 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6085 {
6086 char buf[BUFSIZ];
718e3744 6087
856ca177
MS
6088 json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6089 buf, BUFSIZ));
6090 }
6091#endif /* HAVE_IPV6 */
6092
6093 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6094 json_object_int_add(json_net, "metric", attr->med);
6095
6096 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6097 json_object_int_add(json_net, "localPref", attr->local_pref);
6098
6099 if (attr->extra)
6100 json_object_int_add(json_net, "weight", attr->extra->weight);
718e3744 6101 else
856ca177
MS
6102 json_object_int_add(json_net, "weight", 0);
6103
6104 /* Print aspath */
6105 if (attr->aspath)
6106 json_object_string_add(json_net, "asPath", attr->aspath->str);
6107
6108 /* Print origin */
6109 json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]);
718e3744 6110 }
856ca177
MS
6111 else
6112 {
587ff0fd
LB
6113 if (p->family == AF_INET &&
6114 (safi == SAFI_MPLS_VPN ||
6115 safi == SAFI_ENCAP ||
6116 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
856ca177 6117 {
587ff0fd 6118 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
856ca177
MS
6119 vty_out (vty, "%-16s",
6120 inet_ntoa (attr->extra->mp_nexthop_global_in));
6121 else
6122 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6123 }
6124#ifdef HAVE_IPV6
6125 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6126 {
6127 int len;
6128 char buf[BUFSIZ];
6129
6130 assert (attr->extra);
6131
6132 len = vty_out (vty, "%s",
6133 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6134 buf, BUFSIZ));
6135 len = 16 - len;
6136 if (len < 1)
6137 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6138 else
6139 vty_out (vty, "%*s", len, " ");
6140 }
718e3744 6141#endif /* HAVE_IPV6 */
856ca177
MS
6142 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6143 vty_out (vty, "%10u", attr->med);
6144 else
6145 vty_out (vty, " ");
718e3744 6146
856ca177
MS
6147 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6148 vty_out (vty, "%7u", attr->local_pref);
6149 else
6150 vty_out (vty, " ");
718e3744 6151
856ca177 6152 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
718e3744 6153
856ca177
MS
6154 /* Print aspath */
6155 if (attr->aspath)
6156 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 6157
856ca177
MS
6158 /* Print origin */
6159 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6160 }
6161 }
6162 if (use_json)
6163 {
6164 json_object_boolean_true_add(json_status, "*");
6165 json_object_boolean_true_add(json_status, ">");
6166 json_object_object_add(json_net, "appliedStatusSymbols", json_status);
6167 char buf_cut[BUFSIZ];
6168 json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net);
6169 }
6170 else
6171 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6172}
6173
5a646650 6174void
718e3744 6175route_vty_out_tag (struct vty *vty, struct prefix *p,
856ca177 6176 struct bgp_info *binfo, int display, safi_t safi, json_object *json)
718e3744 6177{
856ca177 6178 json_object *json_out = NULL;
718e3744 6179 struct attr *attr;
718e3744 6180 u_int32_t label = 0;
fb982c25
PJ
6181
6182 if (!binfo->extra)
6183 return;
856ca177
MS
6184
6185 if (json)
6186 json_out = json_object_new_object();
fb982c25 6187
b40d939b 6188 /* short status lead text */
856ca177 6189 route_vty_short_status_out (vty, binfo, json_out);
b40d939b 6190
718e3744 6191 /* print prefix and mask */
856ca177
MS
6192 if (json == NULL)
6193 {
6194 if (! display)
6195 route_vty_out_route (p, vty);
6196 else
6197 vty_out (vty, "%*s", 17, " ");
6198 }
718e3744 6199
6200 /* Print attribute */
6201 attr = binfo->attr;
6202 if (attr)
6203 {
8a92a8a0
DS
6204 if (p->family == AF_INET
6205 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 6206 {
587ff0fd 6207 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
856ca177
MS
6208 {
6209 if (json)
6210 json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in));
6211 else
6212 vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6213 }
718e3744 6214 else
856ca177
MS
6215 {
6216 if (json)
6217 json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop));
6218 else
6219 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6220 }
718e3744 6221 }
6222#ifdef HAVE_IPV6
8a92a8a0 6223 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
718e3744 6224 {
fb982c25 6225 assert (attr->extra);
856ca177
MS
6226 char buf_a[BUFSIZ];
6227 char buf_b[BUFSIZ];
6228 char buf_c[BUFSIZ];
801a9bcc 6229 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
856ca177
MS
6230 {
6231 if (json)
6232 json_object_string_add(json_out, "mpNexthopGlobalIn",
6233 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ));
6234 else
6235 vty_out (vty, "%s",
6236 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6237 buf_a, BUFSIZ));
6238 }
801a9bcc 6239 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
856ca177
MS
6240 {
6241 if (json)
6242 {
6243 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6244 buf_a, BUFSIZ);
6245 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6246 buf_b, BUFSIZ);
6247 sprintf(buf_c, "%s(%s)", buf_a, buf_b);
6248 json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c);
6249 }
6250 else
6251 vty_out (vty, "%s(%s)",
6252 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6253 buf_a, BUFSIZ),
6254 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6255 buf_b, BUFSIZ));
6256 }
6257
718e3744 6258 }
6259#endif /* HAVE_IPV6 */
6260 }
6261
fb982c25 6262 label = decode_label (binfo->extra->tag);
718e3744 6263
856ca177
MS
6264 if (json)
6265 {
6266 if (label)
6267 json_object_int_add(json_out, "notag", label);
6268 json_object_array_add(json, json_out);
6269 }
6270 else
6271 {
6272 vty_out (vty, "notag/%d", label);
6273 vty_out (vty, "%s", VTY_NEWLINE);
6274 }
718e3744 6275}
6276
6277/* dampening route */
5a646650 6278static void
856ca177
MS
6279damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6280 int display, safi_t safi, u_char use_json, json_object *json)
718e3744 6281{
6282 struct attr *attr;
718e3744 6283 int len;
50aef6f3 6284 char timebuf[BGP_UPTIME_LEN];
718e3744 6285
b40d939b 6286 /* short status lead text */
856ca177 6287 route_vty_short_status_out (vty, binfo, json);
b40d939b 6288
718e3744 6289 /* print prefix and mask */
856ca177
MS
6290 if (!use_json)
6291 {
6292 if (! display)
6293 route_vty_out_route (p, vty);
6294 else
6295 vty_out (vty, "%*s", 17, " ");
6296 }
718e3744 6297
6298 len = vty_out (vty, "%s", binfo->peer->host);
6299 len = 17 - len;
6300 if (len < 1)
856ca177
MS
6301 {
6302 if (!use_json)
6303 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6304 }
718e3744 6305 else
856ca177
MS
6306 {
6307 if (use_json)
6308 json_object_int_add(json, "peerHost", len);
6309 else
6310 vty_out (vty, "%*s", len, " ");
6311 }
718e3744 6312
856ca177
MS
6313 if (use_json)
6314 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6315 else
6316 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
718e3744 6317
6318 /* Print attribute */
6319 attr = binfo->attr;
6320 if (attr)
6321 {
6322 /* Print aspath */
6323 if (attr->aspath)
856ca177
MS
6324 {
6325 if (use_json)
6326 json_object_string_add(json, "asPath", attr->aspath->str);
6327 else
6328 aspath_print_vty (vty, "%s", attr->aspath, " ");
6329 }
718e3744 6330
6331 /* Print origin */
856ca177
MS
6332 if (use_json)
6333 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6334 else
6335 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 6336 }
856ca177
MS
6337 if (!use_json)
6338 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6339}
6340
718e3744 6341/* flap route */
5a646650 6342static void
856ca177
MS
6343flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6344 int display, safi_t safi, u_char use_json, json_object *json)
718e3744 6345{
6346 struct attr *attr;
6347 struct bgp_damp_info *bdi;
718e3744 6348 char timebuf[BGP_UPTIME_LEN];
6349 int len;
fb982c25
PJ
6350
6351 if (!binfo->extra)
6352 return;
6353
6354 bdi = binfo->extra->damp_info;
718e3744 6355
b40d939b 6356 /* short status lead text */
856ca177 6357 route_vty_short_status_out (vty, binfo, json);
b40d939b 6358
718e3744 6359 /* print prefix and mask */
856ca177
MS
6360 if (!use_json)
6361 {
6362 if (! display)
6363 route_vty_out_route (p, vty);
6364 else
6365 vty_out (vty, "%*s", 17, " ");
6366 }
718e3744 6367
6368 len = vty_out (vty, "%s", binfo->peer->host);
6369 len = 16 - len;
6370 if (len < 1)
856ca177
MS
6371 {
6372 if (!use_json)
6373 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6374 }
718e3744 6375 else
856ca177
MS
6376 {
6377 if (use_json)
6378 json_object_int_add(json, "peerHost", len);
6379 else
6380 vty_out (vty, "%*s", len, " ");
6381 }
718e3744 6382
6383 len = vty_out (vty, "%d", bdi->flap);
6384 len = 5 - len;
6385 if (len < 1)
856ca177
MS
6386 {
6387 if (!use_json)
6388 vty_out (vty, " ");
6389 }
718e3744 6390 else
856ca177
MS
6391 {
6392 if (use_json)
6393 json_object_int_add(json, "bdiFlap", len);
6394 else
6395 vty_out (vty, "%*s", len, " ");
6396 }
6397
6398 if (use_json)
6399 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json);
6400 else
6401 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6402 timebuf, BGP_UPTIME_LEN, 0, NULL));
718e3744 6403
6404 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6405 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
856ca177
MS
6406 {
6407 if (use_json)
6408 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6409 else
6410 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6411 }
718e3744 6412 else
856ca177
MS
6413 {
6414 if (!use_json)
6415 vty_out (vty, "%*s ", 8, " ");
6416 }
718e3744 6417
6418 /* Print attribute */
6419 attr = binfo->attr;
6420 if (attr)
6421 {
6422 /* Print aspath */
6423 if (attr->aspath)
856ca177
MS
6424 {
6425 if (use_json)
6426 json_object_string_add(json, "asPath", attr->aspath->str);
6427 else
6428 aspath_print_vty (vty, "%s", attr->aspath, " ");
6429 }
718e3744 6430
6431 /* Print origin */
856ca177
MS
6432 if (use_json)
6433 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6434 else
6435 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 6436 }
856ca177
MS
6437 if (!use_json)
6438 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6439}
6440
adbac85e
DW
6441static void
6442route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first,
6443 const char *header, json_object *json_adv_to)
6444{
6445 char buf1[INET6_ADDRSTRLEN];
6446 json_object *json_peer = NULL;
6447
6448 if (json_adv_to)
6449 {
6450 /* 'advertised-to' is a dictionary of peers we have advertised this
6451 * prefix too. The key is the peer's IP or swpX, the value is the
6452 * hostname if we know it and "" if not.
6453 */
6454 json_peer = json_object_new_object();
6455
6456 if (peer->hostname)
6457 json_object_string_add(json_peer, "hostname", peer->hostname);
6458
6459 if (peer->conf_if)
6460 json_object_object_add(json_adv_to, peer->conf_if, json_peer);
6461 else
6462 json_object_object_add(json_adv_to,
6463 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN),
6464 json_peer);
6465 }
6466 else
6467 {
6468 if (*first)
6469 {
6470 vty_out (vty, "%s", header);
6471 *first = 0;
6472 }
6473
6474 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6475 {
6476 if (peer->conf_if)
6477 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
6478 else
6479 vty_out (vty, " %s(%s)", peer->hostname,
6480 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6481 }
6482 else
6483 {
6484 if (peer->conf_if)
6485 vty_out (vty, " %s", peer->conf_if);
6486 else
6487 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6488 }
6489 }
6490}
6491
94f2b392 6492static void
718e3744 6493route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
b05a1c8b
DS
6494 struct bgp_info *binfo, afi_t afi, safi_t safi,
6495 json_object *json_paths)
718e3744 6496{
6497 char buf[INET6_ADDRSTRLEN];
6498 char buf1[BUFSIZ];
6499 struct attr *attr;
6500 int sockunion_vty_out (struct vty *, union sockunion *);
30b00176
JK
6501#ifdef HAVE_CLOCK_MONOTONIC
6502 time_t tbuf;
6503#endif
f1aa5d8a 6504 json_object *json_bestpath = NULL;
ffd0c037 6505 json_object *json_cluster_list = NULL;
f1aa5d8a
DS
6506 json_object *json_cluster_list_list = NULL;
6507 json_object *json_ext_community = NULL;
6508 json_object *json_last_update = NULL;
6509 json_object *json_nexthop_global = NULL;
6510 json_object *json_nexthop_ll = NULL;
6511 json_object *json_nexthops = NULL;
6512 json_object *json_path = NULL;
6513 json_object *json_peer = NULL;
6514 json_object *json_string = NULL;
adbac85e
DW
6515 json_object *json_adv_to = NULL;
6516 int first = 0;
6517 struct listnode *node, *nnode;
6518 struct peer *peer;
6519 int addpath_capable;
6520 int has_adj;
06370dac 6521 int first_as;
b05a1c8b
DS
6522
6523 if (json_paths)
6524 {
6525 json_path = json_object_new_object();
f1aa5d8a
DS
6526 json_peer = json_object_new_object();
6527 json_nexthop_global = json_object_new_object();
b05a1c8b
DS
6528 }
6529
718e3744 6530 attr = binfo->attr;
6531
6532 if (attr)
6533 {
6534 /* Line1 display AS-path, Aggregator */
6535 if (attr->aspath)
6536 {
f1aa5d8a
DS
6537 if (json_paths)
6538 {
6539 json_object_lock(attr->aspath->json);
6540 json_object_object_add(json_path, "aspath", attr->aspath->json);
6541 }
6542 else
b05a1c8b 6543 {
f1aa5d8a
DS
6544 if (attr->aspath->segments)
6545 aspath_print_vty (vty, " %s", attr->aspath, "");
b05a1c8b 6546 else
f1aa5d8a 6547 vty_out (vty, " Local");
b05a1c8b 6548 }
718e3744 6549 }
6550
b40d939b 6551 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
b05a1c8b
DS
6552 {
6553 if (json_paths)
f1aa5d8a 6554 json_object_boolean_true_add(json_path, "removed");
b05a1c8b
DS
6555 else
6556 vty_out (vty, ", (removed)");
6557 }
6558
93406d87 6559 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
b05a1c8b
DS
6560 {
6561 if (json_paths)
f1aa5d8a 6562 json_object_boolean_true_add(json_path, "stale");
b05a1c8b
DS
6563 else
6564 vty_out (vty, ", (stale)");
6565 }
6566
93406d87 6567 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
b05a1c8b
DS
6568 {
6569 if (json_paths)
6570 {
62d6dca0
DS
6571 json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as);
6572 json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr));
b05a1c8b
DS
6573 }
6574 else
6575 {
6576 vty_out (vty, ", (aggregated by %u %s)",
6577 attr->extra->aggregator_as,
6578 inet_ntoa (attr->extra->aggregator_addr));
6579 }
6580 }
6581
93406d87 6582 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
b05a1c8b
DS
6583 {
6584 if (json_paths)
62d6dca0 6585 json_object_boolean_true_add(json_path, "rxedFromRrClient");
b05a1c8b
DS
6586 else
6587 vty_out (vty, ", (Received from a RR-client)");
6588 }
6589
93406d87 6590 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
b05a1c8b
DS
6591 {
6592 if (json_paths)
62d6dca0 6593 json_object_boolean_true_add(json_path, "rxedFromRsClient");
b05a1c8b
DS
6594 else
6595 vty_out (vty, ", (Received from a RS-client)");
6596 }
6597
93406d87 6598 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
6599 {
6600 if (json_paths)
62d6dca0 6601 json_object_boolean_true_add(json_path, "dampeningHistoryEntry");
b05a1c8b
DS
6602 else
6603 vty_out (vty, ", (history entry)");
6604 }
93406d87 6605 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
b05a1c8b
DS
6606 {
6607 if (json_paths)
62d6dca0 6608 json_object_boolean_true_add(json_path, "dampeningSuppressed");
b05a1c8b
DS
6609 else
6610 vty_out (vty, ", (suppressed due to dampening)");
6611 }
6612
6613 if (!json_paths)
6614 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6615
6616 /* Line2 display Next-hop, Neighbor, Router-id */
f1aa5d8a 6617 /* Display the nexthop */
587ff0fd
LB
6618 if (p->family == AF_INET &&
6619 (safi == SAFI_MPLS_VPN ||
6620 safi == SAFI_ENCAP ||
6621 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 6622 {
587ff0fd 6623 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
b05a1c8b
DS
6624 {
6625 if (json_paths)
f1aa5d8a 6626 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
b05a1c8b
DS
6627 else
6628 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6629 }
6630 else
6631 {
6632 if (json_paths)
f1aa5d8a 6633 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
b05a1c8b
DS
6634 else
6635 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
6636 }
6637
6638 if (json_paths)
f1aa5d8a 6639 json_object_string_add(json_nexthop_global, "afi", "ipv4");
718e3744 6640 }
718e3744 6641 else
6642 {
fb982c25 6643 assert (attr->extra);
b05a1c8b
DS
6644 if (json_paths)
6645 {
f1aa5d8a
DS
6646 json_object_string_add(json_nexthop_global, "ip",
6647 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6648 buf, INET6_ADDRSTRLEN));
6649 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6650 json_object_string_add(json_nexthop_global, "scope", "global");
b05a1c8b
DS
6651 }
6652 else
6653 {
6654 vty_out (vty, " %s",
6655 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6656 buf, INET6_ADDRSTRLEN));
6657 }
718e3744 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
f1aa5d8a 6764 /* display the link-local nexthop */
801a9bcc 6765 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
718e3744 6766 {
b05a1c8b
DS
6767 if (json_paths)
6768 {
f1aa5d8a
DS
6769 json_nexthop_ll = json_object_new_object();
6770 json_object_string_add(json_nexthop_ll, "ip",
6771 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6772 buf, INET6_ADDRSTRLEN));
6773 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
6774 json_object_string_add(json_nexthop_ll, "scope", "link-local");
6775
6776 json_object_boolean_true_add(json_nexthop_ll, "accessible");
161995ea
DS
6777
6778 if (!attr->extra->mp_nexthop_prefer_global)
6779 json_object_boolean_true_add(json_nexthop_ll, "used");
6780 else
6781 json_object_boolean_true_add(json_nexthop_global, "used");
b05a1c8b
DS
6782 }
6783 else
6784 {
161995ea
DS
6785 vty_out (vty, " (%s) %s%s",
6786 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
b05a1c8b 6787 buf, INET6_ADDRSTRLEN),
161995ea
DS
6788 attr->extra->mp_nexthop_prefer_global ?
6789 "(prefer-global)" : "(used)",
b05a1c8b
DS
6790 VTY_NEWLINE);
6791 }
718e3744 6792 }
f1aa5d8a
DS
6793 /* If we do not have a link-local nexthop then we must flag the global as "used" */
6794 else
6795 {
6796 if (json_paths)
6797 json_object_boolean_true_add(json_nexthop_global, "used");
6798 }
718e3744 6799
0d9551dc 6800 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
b05a1c8b 6801 if (json_paths)
f1aa5d8a 6802 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
b05a1c8b 6803 else
f1aa5d8a 6804 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
718e3744 6805
6806 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b
DS
6807 {
6808 if (json_paths)
f1aa5d8a 6809 json_object_int_add(json_path, "med", attr->med);
b05a1c8b 6810 else
f1aa5d8a 6811 vty_out (vty, ", metric %u", attr->med);
b05a1c8b 6812 }
718e3744 6813
6814 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
b05a1c8b
DS
6815 {
6816 if (json_paths)
f1aa5d8a 6817 json_object_int_add(json_path, "localpref", attr->local_pref);
b05a1c8b 6818 else
f1aa5d8a 6819 vty_out (vty, ", localpref %u", attr->local_pref);
b05a1c8b 6820 }
718e3744 6821 else
b05a1c8b
DS
6822 {
6823 if (json_paths)
f1aa5d8a 6824 json_object_int_add(json_path, "localpref", bgp->default_local_pref);
b05a1c8b 6825 else
f1aa5d8a 6826 vty_out (vty, ", localpref %u", bgp->default_local_pref);
b05a1c8b 6827 }
718e3744 6828
fb982c25 6829 if (attr->extra && attr->extra->weight != 0)
b05a1c8b
DS
6830 {
6831 if (json_paths)
f1aa5d8a 6832 json_object_int_add(json_path, "weight", attr->extra->weight);
b05a1c8b 6833 else
f1aa5d8a 6834 vty_out (vty, ", weight %u", attr->extra->weight);
b05a1c8b 6835 }
0d9551dc
DS
6836
6837 if (attr->extra && attr->extra->tag != 0)
b05a1c8b
DS
6838 {
6839 if (json_paths)
f1aa5d8a 6840 json_object_int_add(json_path, "tag", attr->extra->tag);
b05a1c8b 6841 else
f1aa5d8a 6842 vty_out (vty, ", tag %d", attr->extra->tag);
b05a1c8b 6843 }
718e3744 6844
31eba040 6845 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
b05a1c8b
DS
6846 {
6847 if (json_paths)
f1aa5d8a 6848 json_object_boolean_false_add(json_path, "valid");
b05a1c8b
DS
6849 else
6850 vty_out (vty, ", invalid");
6851 }
31eba040 6852 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
6853 {
6854 if (json_paths)
f1aa5d8a 6855 json_object_boolean_true_add(json_path, "valid");
b05a1c8b
DS
6856 else
6857 vty_out (vty, ", valid");
6858 }
718e3744 6859
6860 if (binfo->peer != bgp->peer_self)
6861 {
f1aa5d8a 6862 if (binfo->peer->as == binfo->peer->local_as)
b05a1c8b 6863 {
66b199b2
DS
6864 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
6865 {
6866 if (json_paths)
f1aa5d8a 6867 json_object_string_add(json_peer, "type", "confed-internal");
66b199b2 6868 else
f1aa5d8a 6869 vty_out (vty, ", confed-internal");
66b199b2 6870 }
b05a1c8b 6871 else
66b199b2
DS
6872 {
6873 if (json_paths)
f1aa5d8a 6874 json_object_string_add(json_peer, "type", "internal");
66b199b2 6875 else
f1aa5d8a 6876 vty_out (vty, ", internal");
66b199b2 6877 }
b05a1c8b 6878 }
f1aa5d8a 6879 else
b05a1c8b
DS
6880 {
6881 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
6882 {
6883 if (json_paths)
f1aa5d8a 6884 json_object_string_add(json_peer, "type", "confed-external");
b05a1c8b 6885 else
f1aa5d8a 6886 vty_out (vty, ", confed-external");
b05a1c8b
DS
6887 }
6888 else
6889 {
6890 if (json_paths)
f1aa5d8a 6891 json_object_string_add(json_peer, "type", "external");
b05a1c8b 6892 else
f1aa5d8a 6893 vty_out (vty, ", external");
b05a1c8b
DS
6894 }
6895 }
718e3744 6896 }
6897 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
b05a1c8b
DS
6898 {
6899 if (json_paths)
6900 {
f1aa5d8a
DS
6901 json_object_boolean_true_add(json_path, "aggregated");
6902 json_object_boolean_true_add(json_path, "local");
b05a1c8b
DS
6903 }
6904 else
6905 {
6906 vty_out (vty, ", aggregated, local");
6907 }
6908 }
718e3744 6909 else if (binfo->type != ZEBRA_ROUTE_BGP)
b05a1c8b
DS
6910 {
6911 if (json_paths)
f1aa5d8a 6912 json_object_boolean_true_add(json_path, "sourced");
b05a1c8b
DS
6913 else
6914 vty_out (vty, ", sourced");
6915 }
718e3744 6916 else
b05a1c8b
DS
6917 {
6918 if (json_paths)
6919 {
f1aa5d8a
DS
6920 json_object_boolean_true_add(json_path, "sourced");
6921 json_object_boolean_true_add(json_path, "local");
b05a1c8b
DS
6922 }
6923 else
6924 {
6925 vty_out (vty, ", sourced, local");
6926 }
6927 }
718e3744 6928
6929 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
b05a1c8b
DS
6930 {
6931 if (json_paths)
62d6dca0 6932 json_object_boolean_true_add(json_path, "atomicAggregate");
b05a1c8b
DS
6933 else
6934 vty_out (vty, ", atomic-aggregate");
6935 }
718e3744 6936
de8d5dff
JB
6937 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6938 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6939 bgp_info_mpath_count (binfo)))
b05a1c8b
DS
6940 {
6941 if (json_paths)
f1aa5d8a 6942 json_object_boolean_true_add(json_path, "multipath");
b05a1c8b
DS
6943 else
6944 vty_out (vty, ", multipath");
6945 }
de8d5dff 6946
06370dac
DW
6947 // Mark the bestpath(s)
6948 if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED))
6949 {
6950 first_as = aspath_get_firstas(attr->aspath);
6951
6952 if (json_paths)
6953 {
6954 if (!json_bestpath)
6955 json_bestpath = json_object_new_object();
6956 json_object_int_add(json_bestpath, "bestpathFromAs", first_as);
6957 }
6958 else
6959 {
6960 if (first_as)
6961 vty_out (vty, ", bestpath-from-AS %d", first_as);
6962 else
6963 vty_out (vty, ", bestpath-from-AS Local");
6964 }
6965 }
6966
718e3744 6967 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
b05a1c8b
DS
6968 {
6969 if (json_paths)
f1aa5d8a 6970 {
06370dac
DW
6971 if (!json_bestpath)
6972 json_bestpath = json_object_new_object();
f1aa5d8a 6973 json_object_boolean_true_add(json_bestpath, "overall");
f1aa5d8a 6974 }
b05a1c8b
DS
6975 else
6976 vty_out (vty, ", best");
6977 }
718e3744 6978
06370dac
DW
6979 if (json_bestpath)
6980 json_object_object_add(json_path, "bestpath", json_bestpath);
6981
b05a1c8b
DS
6982 if (!json_paths)
6983 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6984
6985 /* Line 4 display Community */
6986 if (attr->community)
b05a1c8b
DS
6987 {
6988 if (json_paths)
6989 {
f1aa5d8a
DS
6990 json_object_lock(attr->community->json);
6991 json_object_object_add(json_path, "community", attr->community->json);
b05a1c8b
DS
6992 }
6993 else
6994 {
6995 vty_out (vty, " Community: %s%s", attr->community->str,
6996 VTY_NEWLINE);
6997 }
6998 }
718e3744 6999
7000 /* Line 5 display Extended-community */
7001 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
b05a1c8b
DS
7002 {
7003 if (json_paths)
7004 {
f1aa5d8a
DS
7005 json_ext_community = json_object_new_object();
7006 json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str);
62d6dca0 7007 json_object_object_add(json_path, "extendedCommunity", json_ext_community);
b05a1c8b
DS
7008 }
7009 else
7010 {
7011 vty_out (vty, " Extended Community: %s%s",
7012 attr->extra->ecommunity->str, VTY_NEWLINE);
7013 }
7014 }
7015
718e3744 7016 /* Line 6 display Originator, Cluster-id */
7017 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
7018 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
7019 {
fb982c25 7020 assert (attr->extra);
718e3744 7021 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
b05a1c8b
DS
7022 {
7023 if (json_paths)
62d6dca0 7024 json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id));
b05a1c8b 7025 else
f1aa5d8a
DS
7026 vty_out (vty, " Originator: %s",
7027 inet_ntoa (attr->extra->originator_id));
b05a1c8b 7028 }
718e3744 7029
7030 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
7031 {
7032 int i;
b05a1c8b
DS
7033
7034 if (json_paths)
7035 {
f1aa5d8a
DS
7036 json_cluster_list = json_object_new_object();
7037 json_cluster_list_list = json_object_new_array();
7038
b05a1c8b
DS
7039 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7040 {
7041 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
f1aa5d8a 7042 json_object_array_add(json_cluster_list_list, json_string);
b05a1c8b 7043 }
f1aa5d8a
DS
7044
7045 /* struct cluster_list does not have "str" variable like
7046 * aspath and community do. Add this someday if someone
7047 * asks for it.
7048 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
7049 */
7050 json_object_object_add(json_cluster_list, "list", json_cluster_list_list);
62d6dca0 7051 json_object_object_add(json_path, "clusterList", json_cluster_list);
b05a1c8b
DS
7052 }
7053 else
7054 {
7055 vty_out (vty, ", Cluster list: ");
7056
7057 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7058 {
7059 vty_out (vty, "%s ",
7060 inet_ntoa (attr->extra->cluster->list[i]));
7061 }
7062 }
718e3744 7063 }
b05a1c8b
DS
7064
7065 if (!json_paths)
7066 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7067 }
b05a1c8b 7068
fb982c25 7069 if (binfo->extra && binfo->extra->damp_info)
b05a1c8b 7070 bgp_damp_info_vty (vty, binfo, json_path);
718e3744 7071
a82478b9
DS
7072 /* Line 7 display Addpath IDs */
7073 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
b05a1c8b
DS
7074 {
7075 if (json_paths)
7076 {
62d6dca0
DS
7077 json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id);
7078 json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id);
b05a1c8b
DS
7079 }
7080 else
7081 {
7082 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
7083 binfo->addpath_rx_id, binfo->addpath_tx_id,
7084 VTY_NEWLINE);
7085 }
7086 }
a82478b9 7087
adbac85e
DW
7088 /* If we used addpath to TX a non-bestpath we need to display
7089 * "Advertised to" on a path-by-path basis */
7090 if (bgp->addpath_tx_used[afi][safi])
7091 {
7092 first = 1;
7093
7094 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7095 {
7096 addpath_capable = bgp_addpath_encode_tx (peer, afi, safi);
7097 has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id);
7098
7099 if ((addpath_capable && has_adj) ||
7100 (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)))
7101 {
7102 if (json_path && !json_adv_to)
7103 json_adv_to = json_object_new_object();
7104
7105 route_vty_out_advertised_to(vty, peer, &first,
7106 " Advertised to:",
7107 json_adv_to);
7108 }
7109 }
7110
7111 if (json_path)
7112 {
7113 if (json_adv_to)
7114 {
7115 json_object_object_add(json_path, "advertisedTo", json_adv_to);
7116 }
7117 }
7118 else
7119 {
7120 if (!first)
7121 {
7122 vty_out (vty, "%s", VTY_NEWLINE);
7123 }
7124 }
7125 }
7126
a82478b9 7127 /* Line 8 display Uptime */
30b00176
JK
7128#ifdef HAVE_CLOCK_MONOTONIC
7129 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
b05a1c8b 7130 if (json_paths)
f1aa5d8a
DS
7131 {
7132 json_last_update = json_object_new_object();
7133 json_object_int_add(json_last_update, "epoch", tbuf);
7134 json_object_string_add(json_last_update, "string", ctime(&tbuf));
62d6dca0 7135 json_object_object_add(json_path, "lastUpdate", json_last_update);
f1aa5d8a 7136 }
b05a1c8b
DS
7137 else
7138 vty_out (vty, " Last update: %s", ctime(&tbuf));
30b00176 7139#else
b05a1c8b 7140 if (json_paths)
f1aa5d8a
DS
7141 {
7142 json_last_update = json_object_new_object();
7143 json_object_int_add(json_last_update, "epoch", tbuf);
7144 json_object_string_add(json_last_update, "string", ctime(&binfo->uptime));
62d6dca0 7145 json_object_object_add(json_path, "lastUpdate", json_last_update);
f1aa5d8a 7146 }
b05a1c8b
DS
7147 else
7148 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
30b00176 7149#endif /* HAVE_CLOCK_MONOTONIC */
718e3744 7150 }
b05a1c8b
DS
7151
7152 /* We've constructed the json object for this path, add it to the json
7153 * array of paths
7154 */
7155 if (json_paths)
f1aa5d8a
DS
7156 {
7157 if (json_nexthop_global || json_nexthop_ll)
7158 {
7159 json_nexthops = json_object_new_array();
7160
7161 if (json_nexthop_global)
7162 json_object_array_add(json_nexthops, json_nexthop_global);
7163
7164 if (json_nexthop_ll)
7165 json_object_array_add(json_nexthops, json_nexthop_ll);
7166
7167 json_object_object_add(json_path, "nexthops", json_nexthops);
7168 }
7169
7170 json_object_object_add(json_path, "peer", json_peer);
7171 json_object_array_add(json_paths, json_path);
7172 }
b05a1c8b
DS
7173 else
7174 vty_out (vty, "%s", VTY_NEWLINE);
b366b518
BB
7175}
7176
47fc97cc 7177#define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
718e3744 7178#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7179#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7180
7181enum bgp_show_type
7182{
7183 bgp_show_type_normal,
7184 bgp_show_type_regexp,
7185 bgp_show_type_prefix_list,
7186 bgp_show_type_filter_list,
7187 bgp_show_type_route_map,
7188 bgp_show_type_neighbor,
7189 bgp_show_type_cidr_only,
7190 bgp_show_type_prefix_longer,
7191 bgp_show_type_community_all,
7192 bgp_show_type_community,
7193 bgp_show_type_community_exact,
7194 bgp_show_type_community_list,
7195 bgp_show_type_community_list_exact,
7196 bgp_show_type_flap_statistics,
7197 bgp_show_type_flap_address,
7198 bgp_show_type_flap_prefix,
7199 bgp_show_type_flap_cidr_only,
7200 bgp_show_type_flap_regexp,
7201 bgp_show_type_flap_filter_list,
7202 bgp_show_type_flap_prefix_list,
7203 bgp_show_type_flap_prefix_longer,
7204 bgp_show_type_flap_route_map,
7205 bgp_show_type_flap_neighbor,
7206 bgp_show_type_dampend_paths,
7207 bgp_show_type_damp_neighbor
7208};
7209
50ef26d4 7210static int
7211bgp_show_prefix_list (struct vty *vty, const char *name,
7212 const char *prefix_list_str, afi_t afi,
7213 safi_t safi, enum bgp_show_type type);
7214static int
7215bgp_show_filter_list (struct vty *vty, const char *name,
7216 const char *filter, afi_t afi,
7217 safi_t safi, enum bgp_show_type type);
7218static int
7219bgp_show_route_map (struct vty *vty, const char *name,
7220 const char *rmap_str, afi_t afi,
7221 safi_t safi, enum bgp_show_type type);
7222static int
7223bgp_show_community_list (struct vty *vty, const char *name,
7224 const char *com, int exact,
7225 afi_t afi, safi_t safi);
7226static int
7227bgp_show_prefix_longer (struct vty *vty, const char *name,
7228 const char *prefix, afi_t afi,
7229 safi_t safi, enum bgp_show_type type);
7230
5a646650 7231static int
9f689658
DD
7232bgp_show_table (struct vty *vty, struct bgp_table *table,
7233 struct in_addr *router_id, enum bgp_show_type type,
7234 void *output_arg, u_char use_json, json_object *json)
718e3744 7235{
718e3744 7236 struct bgp_info *ri;
7237 struct bgp_node *rn;
718e3744 7238 int header = 1;
718e3744 7239 int display;
5a646650 7240 unsigned long output_count;
b05a1c8b
DS
7241 struct prefix *p;
7242 char buf[BUFSIZ];
7243 char buf2[BUFSIZ];
f1aa5d8a
DS
7244 json_object *json_paths = NULL;
7245 json_object *json_routes = NULL;
b05a1c8b
DS
7246
7247 if (use_json)
7248 {
9f689658
DD
7249 if (json == NULL)
7250 json = json_object_new_object();
7251
62d6dca0
DS
7252 json_object_int_add(json, "tableVersion", table->version);
7253 json_object_string_add(json, "routerId", inet_ntoa (*router_id));
b05a1c8b
DS
7254 json_routes = json_object_new_object();
7255 }
718e3744 7256
7257 /* This is first entry point, so reset total line. */
5a646650 7258 output_count = 0;
718e3744 7259
718e3744 7260 /* Start processing of routes. */
7261 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7262 if (rn->info != NULL)
7263 {
856ca177 7264 display = 0;
718e3744 7265
b05a1c8b
DS
7266 if (use_json)
7267 json_paths = json_object_new_array();
7268 else
7269 json_paths = NULL;
7270
856ca177
MS
7271 for (ri = rn->info; ri; ri = ri->next)
7272 {
7273 if (type == bgp_show_type_flap_statistics
7274 || type == bgp_show_type_flap_address
7275 || type == bgp_show_type_flap_prefix
7276 || type == bgp_show_type_flap_cidr_only
7277 || type == bgp_show_type_flap_regexp
7278 || type == bgp_show_type_flap_filter_list
7279 || type == bgp_show_type_flap_prefix_list
7280 || type == bgp_show_type_flap_prefix_longer
7281 || type == bgp_show_type_flap_route_map
7282 || type == bgp_show_type_flap_neighbor
7283 || type == bgp_show_type_dampend_paths
7284 || type == bgp_show_type_damp_neighbor)
7285 {
7286 if (!(ri->extra && ri->extra->damp_info))
7287 continue;
7288 }
7289 if (type == bgp_show_type_regexp
7290 || type == bgp_show_type_flap_regexp)
7291 {
7292 regex_t *regex = output_arg;
718e3744 7293
856ca177
MS
7294 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7295 continue;
7296 }
7297 if (type == bgp_show_type_prefix_list
7298 || type == bgp_show_type_flap_prefix_list)
7299 {
7300 struct prefix_list *plist = output_arg;
718e3744 7301
856ca177
MS
7302 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7303 continue;
7304 }
7305 if (type == bgp_show_type_filter_list
7306 || type == bgp_show_type_flap_filter_list)
7307 {
7308 struct as_list *as_list = output_arg;
558d1fec 7309
856ca177
MS
7310 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7311 continue;
7312 }
7313 if (type == bgp_show_type_route_map
7314 || type == bgp_show_type_flap_route_map)
7315 {
7316 struct route_map *rmap = output_arg;
7317 struct bgp_info binfo;
7318 struct attr dummy_attr;
7319 struct attr_extra dummy_extra;
7320 int ret;
718e3744 7321
856ca177
MS
7322 dummy_attr.extra = &dummy_extra;
7323 bgp_attr_dup (&dummy_attr, ri->attr);
718e3744 7324
856ca177
MS
7325 binfo.peer = ri->peer;
7326 binfo.attr = &dummy_attr;
718e3744 7327
856ca177
MS
7328 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
7329 if (ret == RMAP_DENYMATCH)
7330 continue;
7331 }
7332 if (type == bgp_show_type_neighbor
7333 || type == bgp_show_type_flap_neighbor
7334 || type == bgp_show_type_damp_neighbor)
7335 {
7336 union sockunion *su = output_arg;
718e3744 7337
856ca177
MS
7338 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7339 continue;
7340 }
7341 if (type == bgp_show_type_cidr_only
7342 || type == bgp_show_type_flap_cidr_only)
7343 {
7344 u_int32_t destination;
718e3744 7345
856ca177
MS
7346 destination = ntohl (rn->p.u.prefix4.s_addr);
7347 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7348 continue;
7349 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7350 continue;
7351 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7352 continue;
7353 }
7354 if (type == bgp_show_type_prefix_longer
7355 || type == bgp_show_type_flap_prefix_longer)
7356 {
7357 struct prefix *p = output_arg;
718e3744 7358
856ca177
MS
7359 if (! prefix_match (p, &rn->p))
7360 continue;
7361 }
7362 if (type == bgp_show_type_community_all)
7363 {
7364 if (! ri->attr->community)
7365 continue;
7366 }
7367 if (type == bgp_show_type_community)
7368 {
7369 struct community *com = output_arg;
718e3744 7370
856ca177
MS
7371 if (! ri->attr->community ||
7372 ! community_match (ri->attr->community, com))
7373 continue;
7374 }
7375 if (type == bgp_show_type_community_exact)
7376 {
7377 struct community *com = output_arg;
718e3744 7378
856ca177
MS
7379 if (! ri->attr->community ||
7380 ! community_cmp (ri->attr->community, com))
7381 continue;
7382 }
7383 if (type == bgp_show_type_community_list)
7384 {
7385 struct community_list *list = output_arg;
718e3744 7386
856ca177
MS
7387 if (! community_list_match (ri->attr->community, list))
7388 continue;
7389 }
7390 if (type == bgp_show_type_community_list_exact)
7391 {
7392 struct community_list *list = output_arg;
718e3744 7393
856ca177
MS
7394 if (! community_list_exact_match (ri->attr->community, list))
7395 continue;
7396 }
7397 if (type == bgp_show_type_flap_address
7398 || type == bgp_show_type_flap_prefix)
7399 {
7400 struct prefix *p = output_arg;
718e3744 7401
856ca177
MS
7402 if (! prefix_match (&rn->p, p))
7403 continue;
b05a1c8b 7404
856ca177
MS
7405 if (type == bgp_show_type_flap_prefix)
7406 if (p->prefixlen != rn->p.prefixlen)
7407 continue;
7408 }
7409 if (type == bgp_show_type_dampend_paths
7410 || type == bgp_show_type_damp_neighbor)
7411 {
7412 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7413 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7414 continue;
7415 }
7416
7417 if (!use_json && header)
7418 {
7419 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (*router_id), VTY_NEWLINE);
7420 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7421 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7422 if (type == bgp_show_type_dampend_paths
7423 || type == bgp_show_type_damp_neighbor)
7424 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7425 else if (type == bgp_show_type_flap_statistics
7426 || type == bgp_show_type_flap_address
7427 || type == bgp_show_type_flap_prefix
7428 || type == bgp_show_type_flap_cidr_only
7429 || type == bgp_show_type_flap_regexp
7430 || type == bgp_show_type_flap_filter_list
7431 || type == bgp_show_type_flap_prefix_list
7432 || type == bgp_show_type_flap_prefix_longer
7433 || type == bgp_show_type_flap_route_map
7434 || type == bgp_show_type_flap_neighbor)
7435 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7436 else
7437 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7438 header = 0;
7439 }
7440
7441 if (type == bgp_show_type_dampend_paths
7442 || type == bgp_show_type_damp_neighbor)
7443 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7444 else if (type == bgp_show_type_flap_statistics
7445 || type == bgp_show_type_flap_address
7446 || type == bgp_show_type_flap_prefix
7447 || type == bgp_show_type_flap_cidr_only
7448 || type == bgp_show_type_flap_regexp
7449 || type == bgp_show_type_flap_filter_list
7450 || type == bgp_show_type_flap_prefix_list
7451 || type == bgp_show_type_flap_prefix_longer
7452 || type == bgp_show_type_flap_route_map
7453 || type == bgp_show_type_flap_neighbor)
7454 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7455 else
7456 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
7457 display++;
b05a1c8b
DS
7458 }
7459
856ca177
MS
7460 if (display)
7461 {
7462 output_count++;
7463 if (use_json)
7464 {
7465 p = &rn->p;
7466 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
7467 json_object_object_add(json_routes, buf2, json_paths);
7468 }
7469 }
9f689658 7470 }
718e3744 7471
b05a1c8b 7472 if (use_json)
718e3744 7473 {
d1d16a96 7474 json_object_object_add(json, "routes", json_routes);
b05a1c8b 7475 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
f1aa5d8a 7476 json_object_free(json);
718e3744 7477 }
7478 else
b05a1c8b
DS
7479 {
7480 /* No route is displayed */
7481 if (output_count == 0)
7482 {
7483 if (type == bgp_show_type_normal)
856ca177 7484 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
b05a1c8b
DS
7485 }
7486 else
7487 vty_out (vty, "%sTotal number of prefixes %ld%s",
856ca177 7488 VTY_NEWLINE, output_count, VTY_NEWLINE);
b05a1c8b 7489 }
718e3744 7490
7491 return CMD_SUCCESS;
7492}
7493
5a646650 7494static int
fee0f4c6 7495bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
856ca177 7496 enum bgp_show_type type, void *output_arg, u_char use_json)
fee0f4c6 7497{
7498 struct bgp_table *table;
7499
856ca177
MS
7500 if (bgp == NULL)
7501 {
7502 bgp = bgp_get_default ();
7503 }
fee0f4c6 7504
7505 if (bgp == NULL)
7506 {
856ca177
MS
7507 if (!use_json)
7508 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
fee0f4c6 7509 return CMD_WARNING;
7510 }
7511
fee0f4c6 7512 table = bgp->rib[afi][safi];
7513
9f689658
DD
7514 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg,
7515 use_json, NULL);
fee0f4c6 7516}
7517
f186de26 7518static void
7519bgp_show_all_instances_routes_vty (struct vty *vty, afi_t afi, safi_t safi,
7520 u_char use_json)
7521{
7522 struct listnode *node, *nnode;
7523 struct bgp *bgp;
7524 struct bgp_table *table;
9f689658
DD
7525 json_object *json = NULL;
7526 int is_first = 1;
7527
7528 if (use_json)
7529 vty_out (vty, "{%s", VTY_NEWLINE);
f186de26 7530
7531 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
7532 {
9f689658
DD
7533 if (use_json)
7534 {
7535 if (!(json = json_object_new_object()))
7536 {
7537 zlog_err("Unable to allocate memory for JSON object");
7538 vty_out (vty,
7539 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}%s",
7540 VTY_NEWLINE);
7541 return;
7542 }
7543 json_object_int_add(json, "vrfId",
7544 (bgp->vrf_id == VRF_UNKNOWN)
7545 ? -1 : bgp->vrf_id);
7546 json_object_string_add(json, "vrfName",
7547 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7548 ? "Default" : bgp->name);
7549 if (! is_first)
7550 vty_out (vty, ",%s", VTY_NEWLINE);
7551 else
7552 is_first = 0;
7553
7554 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7555 ? "Default" : bgp->name);
7556 }
7557 else
7558 {
7559 vty_out (vty, "%sInstance %s:%s",
7560 VTY_NEWLINE,
7561 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7562 ? "Default" : bgp->name,
7563 VTY_NEWLINE);
7564 }
f186de26 7565 table = bgp->rib[afi][safi];
7566 bgp_show_table (vty, table, &bgp->router_id,
9f689658
DD
7567 bgp_show_type_normal, NULL, use_json, json);
7568
f186de26 7569 }
9f689658
DD
7570
7571 if (use_json)
7572 vty_out (vty, "}%s", VTY_NEWLINE);
f186de26 7573}
7574
718e3744 7575/* Header of detailed BGP route information */
94f2b392 7576static void
718e3744 7577route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7578 struct bgp_node *rn,
b05a1c8b
DS
7579 struct prefix_rd *prd, afi_t afi, safi_t safi,
7580 json_object *json)
718e3744 7581{
7582 struct bgp_info *ri;
7583 struct prefix *p;
7584 struct peer *peer;
1eb8ef25 7585 struct listnode *node, *nnode;
718e3744 7586 char buf1[INET6_ADDRSTRLEN];
7587 char buf2[INET6_ADDRSTRLEN];
7588 int count = 0;
7589 int best = 0;
7590 int suppress = 0;
7591 int no_export = 0;
7592 int no_advertise = 0;
7593 int local_as = 0;
adbac85e 7594 int first = 1;
ffd0c037 7595 json_object *json_adv_to = NULL;
718e3744 7596
7597 p = &rn->p;
b05a1c8b
DS
7598
7599 if (json)
7600 {
f1aa5d8a
DS
7601 json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7602 json_object_int_add(json, "prefixlen", p->prefixlen);
b05a1c8b
DS
7603 }
7604 else
7605 {
7606 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
587ff0fd 7607 ((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) ?
b05a1c8b
DS
7608 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7609 safi == SAFI_MPLS_VPN ? ":" : "",
7610 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7611 p->prefixlen, VTY_NEWLINE);
7612 }
718e3744 7613
7614 for (ri = rn->info; ri; ri = ri->next)
7615 {
7616 count++;
7617 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7618 {
7619 best = count;
fb982c25 7620 if (ri->extra && ri->extra->suppress)
718e3744 7621 suppress = 1;
7622 if (ri->attr->community != NULL)
7623 {
7624 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7625 no_advertise = 1;
7626 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7627 no_export = 1;
7628 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7629 local_as = 1;
7630 }
7631 }
7632 }
7633
b05a1c8b 7634 if (!json)
718e3744 7635 {
b05a1c8b
DS
7636 vty_out (vty, "Paths: (%d available", count);
7637 if (best)
7638 {
7639 vty_out (vty, ", best #%d", best);
7640 if (safi == SAFI_UNICAST)
46827ae9
DS
7641 vty_out (vty, ", table %s",
7642 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7643 ? "Default-IP-Routing-Table" : bgp->name);
b05a1c8b
DS
7644 }
7645 else
7646 vty_out (vty, ", no best path");
7647
7648 if (no_advertise)
7649 vty_out (vty, ", not advertised to any peer");
7650 else if (no_export)
7651 vty_out (vty, ", not advertised to EBGP peer");
7652 else if (local_as)
7653 vty_out (vty, ", not advertised outside local AS");
7654
7655 if (suppress)
7656 vty_out (vty, ", Advertisements suppressed by an aggregate.");
7657 vty_out (vty, ")%s", VTY_NEWLINE);
718e3744 7658 }
718e3744 7659
adbac85e
DW
7660 /* If we are not using addpath then we can display Advertised to and that will
7661 * show what peers we advertised the bestpath to. If we are using addpath
7662 * though then we must display Advertised to on a path-by-path basis. */
7663 if (!bgp->addpath_tx_used[afi][safi])
718e3744 7664 {
adbac85e
DW
7665 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7666 {
7667 if (bgp_adj_out_lookup (peer, rn, 0))
b05a1c8b 7668 {
adbac85e 7669 if (json && !json_adv_to)
f1aa5d8a 7670 json_adv_to = json_object_new_object();
6410e93a 7671
adbac85e
DW
7672 route_vty_out_advertised_to(vty, peer, &first,
7673 " Advertised to non peer-group peers:\n ",
7674 json_adv_to);
b05a1c8b 7675 }
adbac85e 7676 }
036a4e7d 7677
adbac85e
DW
7678 if (json)
7679 {
7680 if (json_adv_to)
7681 {
7682 json_object_object_add(json, "advertisedTo", json_adv_to);
b05a1c8b 7683 }
adbac85e
DW
7684 }
7685 else
b05a1c8b 7686 {
adbac85e
DW
7687 if (first)
7688 vty_out (vty, " Not advertised to any peer");
7689 vty_out (vty, "%s", VTY_NEWLINE);
b05a1c8b
DS
7690 }
7691 }
718e3744 7692}
7693
7694/* Display specified route of BGP table. */
94f2b392 7695static int
fee0f4c6 7696bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
fd79ac91 7697 struct bgp_table *rib, const char *ip_str,
7698 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
7699 int prefix_check, enum bgp_path_type pathtype,
7700 u_char use_json)
718e3744 7701{
7702 int ret;
7703 int header;
7704 int display = 0;
7705 struct prefix match;
7706 struct bgp_node *rn;
7707 struct bgp_node *rm;
7708 struct bgp_info *ri;
718e3744 7709 struct bgp_table *table;
f1aa5d8a
DS
7710 json_object *json = NULL;
7711 json_object *json_paths = NULL;
718e3744 7712
718e3744 7713 /* Check IP address argument. */
7714 ret = str2prefix (ip_str, &match);
7715 if (! ret)
7716 {
7717 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
7718 return CMD_WARNING;
7719 }
7720
7721 match.family = afi2family (afi);
7722
b05a1c8b
DS
7723 if (use_json)
7724 {
7725 json = json_object_new_object();
7726 json_paths = json_object_new_array();
7727 }
b05a1c8b 7728
587ff0fd 7729 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
718e3744 7730 {
fee0f4c6 7731 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
718e3744 7732 {
7733 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
7734 continue;
7735
7736 if ((table = rn->info) != NULL)
7737 {
7738 header = 1;
7739
7740 if ((rm = bgp_node_match (table, &match)) != NULL)
7741 {
7742 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6c88b44d
CC
7743 {
7744 bgp_unlock_node (rm);
7745 continue;
7746 }
718e3744 7747
7748 for (ri = rm->info; ri; ri = ri->next)
7749 {
7750 if (header)
7751 {
7752 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
587ff0fd 7753 AFI_IP, safi, json);
718e3744 7754 header = 0;
7755 }
7756 display++;
4092b06c
DS
7757
7758 if (pathtype == BGP_PATH_ALL ||
7759 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7760 (pathtype == BGP_PATH_MULTIPATH &&
7761 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
587ff0fd 7762 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi, json_paths);
718e3744 7763 }
6c88b44d
CC
7764
7765 bgp_unlock_node (rm);
718e3744 7766 }
7767 }
7768 }
7769 }
7770 else
7771 {
7772 header = 1;
7773
fee0f4c6 7774 if ((rn = bgp_node_match (rib, &match)) != NULL)
718e3744 7775 {
7776 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
7777 {
7778 for (ri = rn->info; ri; ri = ri->next)
7779 {
7780 if (header)
7781 {
b05a1c8b 7782 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
718e3744 7783 header = 0;
7784 }
7785 display++;
4092b06c
DS
7786
7787 if (pathtype == BGP_PATH_ALL ||
7788 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7789 (pathtype == BGP_PATH_MULTIPATH &&
7790 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
b05a1c8b 7791 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
718e3744 7792 }
7793 }
6c88b44d
CC
7794
7795 bgp_unlock_node (rn);
718e3744 7796 }
7797 }
7798
e5eee9af 7799 if (use_json)
718e3744 7800 {
e5eee9af
DS
7801 if (display)
7802 json_object_object_add(json, "paths", json_paths);
7803
7804 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
f1aa5d8a 7805 json_object_free(json);
b05a1c8b
DS
7806 }
7807 else
7808 {
e5eee9af 7809 if (!display)
b05a1c8b
DS
7810 {
7811 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
7812 return CMD_WARNING;
7813 }
7814 }
7815
718e3744 7816 return CMD_SUCCESS;
7817}
7818
fee0f4c6 7819/* Display specified route of Main RIB */
94f2b392 7820static int
fd79ac91 7821bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
fee0f4c6 7822 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
7823 int prefix_check, enum bgp_path_type pathtype,
7824 u_char use_json)
fee0f4c6 7825{
7826 struct bgp *bgp;
7827
7828 /* BGP structure lookup. */
7829 if (view_name)
7830 {
7831 bgp = bgp_lookup_by_name (view_name);
7832 if (bgp == NULL)
7833 {
6aeb9e78 7834 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
fee0f4c6 7835 return CMD_WARNING;
7836 }
7837 }
7838 else
7839 {
7840 bgp = bgp_get_default ();
7841 if (bgp == NULL)
7842 {
7843 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7844 return CMD_WARNING;
7845 }
7846 }
7847
7848 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
b05a1c8b
DS
7849 afi, safi, prd, prefix_check, pathtype,
7850 use_json);
fee0f4c6 7851}
7852
718e3744 7853/* BGP route print out function. */
7854DEFUN (show_ip_bgp,
7855 show_ip_bgp_cmd,
b05a1c8b 7856 "show ip bgp {json}",
47fc97cc
DS
7857 SHOW_STR
7858 IP_STR
b05a1c8b
DS
7859 BGP_STR
7860 "JavaScript Object Notation\n")
47fc97cc 7861{
db7c8528 7862 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
718e3744 7863}
7864
7865DEFUN (show_ip_bgp_ipv4,
7866 show_ip_bgp_ipv4_cmd,
b05a1c8b 7867 "show ip bgp ipv4 (unicast|multicast) {json}",
718e3744 7868 SHOW_STR
7869 IP_STR
7870 BGP_STR
7871 "Address family\n"
7872 "Address Family modifier\n"
b05a1c8b
DS
7873 "Address Family modifier\n"
7874 "JavaScript Object Notation\n")
718e3744 7875{
db7c8528 7876 u_char uj = use_json(argc, argv);
b05a1c8b 7877
718e3744 7878 if (strncmp (argv[0], "m", 1) == 0)
5a646650 7879 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
db7c8528 7880 NULL, uj);
718e3744 7881
db7c8528 7882 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
718e3744 7883}
7884
95cbbd2a
ML
7885ALIAS (show_ip_bgp_ipv4,
7886 show_bgp_ipv4_safi_cmd,
b05a1c8b 7887 "show bgp ipv4 (unicast|multicast) {json}",
95cbbd2a
ML
7888 SHOW_STR
7889 BGP_STR
7890 "Address family\n"
7891 "Address Family modifier\n"
47fc97cc 7892 "Address Family modifier\n"
b05a1c8b 7893 "JavaScript Object Notation\n")
47fc97cc 7894
718e3744 7895DEFUN (show_ip_bgp_route,
7896 show_ip_bgp_route_cmd,
b05a1c8b 7897 "show ip bgp A.B.C.D {json}",
718e3744 7898 SHOW_STR
7899 IP_STR
7900 BGP_STR
b05a1c8b
DS
7901 "Network in the BGP routing table to display\n"
7902 "JavaScript Object Notation\n")
718e3744 7903{
db7c8528 7904 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
4092b06c
DS
7905}
7906
7907DEFUN (show_ip_bgp_route_pathtype,
7908 show_ip_bgp_route_pathtype_cmd,
b05a1c8b 7909 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
4092b06c
DS
7910 SHOW_STR
7911 IP_STR
7912 BGP_STR
7913 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7914 "Display only the bestpath\n"
b05a1c8b
DS
7915 "Display only multipaths\n"
7916 "JavaScript Object Notation\n")
4092b06c 7917{
db7c8528 7918 u_char uj = use_json(argc, argv);
b05a1c8b 7919
4092b06c 7920 if (strncmp (argv[1], "b", 1) == 0)
db7c8528 7921 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 7922 else
db7c8528 7923 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
7924}
7925
7926DEFUN (show_bgp_ipv4_safi_route_pathtype,
7927 show_bgp_ipv4_safi_route_pathtype_cmd,
b05a1c8b 7928 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath) {json}",
4092b06c
DS
7929 SHOW_STR
7930 BGP_STR
7931 "Address family\n"
7932 "Address Family modifier\n"
7933 "Address Family modifier\n"
7934 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7935 "Display only the bestpath\n"
b05a1c8b
DS
7936 "Display only multipaths\n"
7937 "JavaScript Object Notation\n")
4092b06c 7938{
db7c8528 7939 u_char uj = use_json(argc, argv);
b05a1c8b 7940
4092b06c
DS
7941 if (strncmp (argv[0], "m", 1) == 0)
7942 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 7943 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 7944 else
db7c8528 7945 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
7946 else
7947 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 7948 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 7949 else
db7c8528 7950 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
718e3744 7951}
7952
7953DEFUN (show_ip_bgp_ipv4_route,
7954 show_ip_bgp_ipv4_route_cmd,
b05a1c8b 7955 "show ip bgp ipv4 (unicast|multicast) A.B.C.D {json}",
718e3744 7956 SHOW_STR
7957 IP_STR
7958 BGP_STR
7959 "Address family\n"
7960 "Address Family modifier\n"
7961 "Address Family modifier\n"
b05a1c8b
DS
7962 "Network in the BGP routing table to display\n"
7963 "JavaScript Object Notation\n")
718e3744 7964{
db7c8528 7965 u_char uj = use_json(argc, argv);
b05a1c8b 7966
718e3744 7967 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 7968 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
718e3744 7969
db7c8528 7970 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
718e3744 7971}
7972
95cbbd2a
ML
7973ALIAS (show_ip_bgp_ipv4_route,
7974 show_bgp_ipv4_safi_route_cmd,
b05a1c8b 7975 "show bgp ipv4 (unicast|multicast) A.B.C.D {json}",
95cbbd2a
ML
7976 SHOW_STR
7977 BGP_STR
7978 "Address family\n"
7979 "Address Family modifier\n"
7980 "Address Family modifier\n"
b05a1c8b
DS
7981 "Network in the BGP routing table to display\n"
7982 "JavaScript Object Notation\n")
95cbbd2a 7983
718e3744 7984DEFUN (show_ip_bgp_vpnv4_all_route,
7985 show_ip_bgp_vpnv4_all_route_cmd,
b05a1c8b 7986 "show ip bgp vpnv4 all A.B.C.D {json}",
718e3744 7987 SHOW_STR
7988 IP_STR
7989 BGP_STR
7990 "Display VPNv4 NLRI specific information\n"
7991 "Display information about all VPNv4 NLRIs\n"
b05a1c8b
DS
7992 "Network in the BGP routing table to display\n"
7993 "JavaScript Object Notation\n")
718e3744 7994{
db7c8528 7995 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 7996}
7997
4092b06c 7998
718e3744 7999DEFUN (show_ip_bgp_vpnv4_rd_route,
8000 show_ip_bgp_vpnv4_rd_route_cmd,
b05a1c8b 8001 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
718e3744 8002 SHOW_STR
8003 IP_STR
8004 BGP_STR
8005 "Display VPNv4 NLRI specific information\n"
8006 "Display information for a route distinguisher\n"
8007 "VPN Route Distinguisher\n"
b05a1c8b
DS
8008 "Network in the BGP routing table to display\n"
8009 "JavaScript Object Notation\n")
718e3744 8010{
8011 int ret;
8012 struct prefix_rd prd;
db7c8528 8013 u_char uj= use_json(argc, argv);
718e3744 8014
8015 ret = str2prefix_rd (argv[0], &prd);
8016 if (! ret)
8017 {
8018 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8019 return CMD_WARNING;
8020 }
db7c8528 8021 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, uj);
718e3744 8022}
8023
8024DEFUN (show_ip_bgp_prefix,
8025 show_ip_bgp_prefix_cmd,
b05a1c8b 8026 "show ip bgp A.B.C.D/M {json}",
718e3744 8027 SHOW_STR
8028 IP_STR
8029 BGP_STR
b05a1c8b
DS
8030 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8031 "JavaScript Object Notation\n")
718e3744 8032{
db7c8528 8033 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
4092b06c
DS
8034}
8035
8036DEFUN (show_ip_bgp_prefix_pathtype,
8037 show_ip_bgp_prefix_pathtype_cmd,
b05a1c8b 8038 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8039 SHOW_STR
8040 IP_STR
8041 BGP_STR
8042 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8043 "Display only the bestpath\n"
b05a1c8b
DS
8044 "Display only multipaths\n"
8045 "JavaScript Object Notation\n")
4092b06c 8046{
db7c8528 8047 u_char uj = use_json(argc, argv);
4092b06c 8048 if (strncmp (argv[1], "b", 1) == 0)
db7c8528 8049 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8050 else
db7c8528 8051 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
718e3744 8052}
8053
8054DEFUN (show_ip_bgp_ipv4_prefix,
8055 show_ip_bgp_ipv4_prefix_cmd,
b05a1c8b 8056 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
718e3744 8057 SHOW_STR
8058 IP_STR
8059 BGP_STR
8060 "Address family\n"
8061 "Address Family modifier\n"
8062 "Address Family modifier\n"
b05a1c8b
DS
8063 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8064 "JavaScript Object Notation\n")
718e3744 8065{
db7c8528 8066 u_char uj = use_json(argc, argv);
b05a1c8b 8067
718e3744 8068 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 8069 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
718e3744 8070
db7c8528 8071 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
718e3744 8072}
8073
95cbbd2a
ML
8074ALIAS (show_ip_bgp_ipv4_prefix,
8075 show_bgp_ipv4_safi_prefix_cmd,
b05a1c8b 8076 "show bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
95cbbd2a
ML
8077 SHOW_STR
8078 BGP_STR
8079 "Address family\n"
8080 "Address Family modifier\n"
8081 "Address Family modifier\n"
b05a1c8b
DS
8082 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8083 "JavaScript Object Notation\n")
95cbbd2a 8084
4092b06c
DS
8085DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
8086 show_ip_bgp_ipv4_prefix_pathtype_cmd,
b05a1c8b 8087 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8088 SHOW_STR
8089 IP_STR
8090 BGP_STR
8091 "Address family\n"
8092 "Address Family modifier\n"
8093 "Address Family modifier\n"
8094 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8095 "Display only the bestpath\n"
b05a1c8b
DS
8096 "Display only multipaths\n"
8097 "JavaScript Object Notation\n")
4092b06c 8098{
db7c8528 8099 u_char uj = use_json(argc, argv);
b05a1c8b 8100
4092b06c
DS
8101 if (strncmp (argv[0], "m", 1) == 0)
8102 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 8103 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8104 else
db7c8528 8105 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8106 else
8107 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 8108 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8109 else
db7c8528 8110 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8111}
8112
8113ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
8114 show_bgp_ipv4_safi_prefix_pathtype_cmd,
b05a1c8b 8115 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8116 SHOW_STR
8117 BGP_STR
8118 "Address family\n"
8119 "Address Family modifier\n"
8120 "Address Family modifier\n"
8121 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8122 "Display only the bestpath\n"
b05a1c8b
DS
8123 "Display only multipaths\n"
8124 "JavaScript Object Notation\n")
4092b06c 8125
718e3744 8126DEFUN (show_ip_bgp_vpnv4_all_prefix,
8127 show_ip_bgp_vpnv4_all_prefix_cmd,
b05a1c8b 8128 "show ip bgp vpnv4 all A.B.C.D/M {json}",
718e3744 8129 SHOW_STR
8130 IP_STR
8131 BGP_STR
8132 "Display VPNv4 NLRI specific information\n"
8133 "Display information about all VPNv4 NLRIs\n"
b05a1c8b
DS
8134 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8135 "JavaScript Object Notation\n")
718e3744 8136{
db7c8528 8137 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8138}
8139
8140DEFUN (show_ip_bgp_vpnv4_rd_prefix,
8141 show_ip_bgp_vpnv4_rd_prefix_cmd,
b05a1c8b 8142 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
718e3744 8143 SHOW_STR
8144 IP_STR
8145 BGP_STR
8146 "Display VPNv4 NLRI specific information\n"
8147 "Display information for a route distinguisher\n"
8148 "VPN Route Distinguisher\n"
b05a1c8b
DS
8149 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8150 "JavaScript Object Notation\n")
718e3744 8151{
8152 int ret;
8153 struct prefix_rd prd;
8154
8155 ret = str2prefix_rd (argv[0], &prd);
8156 if (! ret)
8157 {
8158 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8159 return CMD_WARNING;
8160 }
db7c8528 8161 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8162}
8163
8164DEFUN (show_ip_bgp_view,
8386ac43 8165 show_ip_bgp_instance_cmd,
8166 "show ip bgp " BGP_INSTANCE_CMD " {json}",
718e3744 8167 SHOW_STR
8168 IP_STR
8169 BGP_STR
8386ac43 8170 BGP_INSTANCE_HELP_STR
b05a1c8b 8171 "JavaScript Object Notation\n")
718e3744 8172{
bb46e94f 8173 struct bgp *bgp;
8174
8175 /* BGP structure lookup. */
6aeb9e78 8176 bgp = bgp_lookup_by_name (argv[1]);
bb46e94f 8177 if (bgp == NULL)
8178 {
6aeb9e78 8179 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
bb46e94f 8180 return CMD_WARNING;
8181 }
8182
db7c8528 8183 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
718e3744 8184}
8185
f186de26 8186DEFUN (show_ip_bgp_instance_all,
8187 show_ip_bgp_instance_all_cmd,
8188 "show ip bgp " BGP_INSTANCE_ALL_CMD " {json}",
8189 SHOW_STR
8190 IP_STR
8191 BGP_STR
8192 BGP_INSTANCE_ALL_HELP_STR
8193 "JavaScript Object Notation\n")
8194{
8195 u_char uj = use_json(argc, argv);
8196
8197 bgp_show_all_instances_routes_vty (vty, AFI_IP, SAFI_UNICAST, uj);
8198 return CMD_SUCCESS;
8199}
8200
8386ac43 8201DEFUN (show_ip_bgp_instance_route,
8202 show_ip_bgp_instance_route_cmd,
8203 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D {json}",
718e3744 8204 SHOW_STR
8205 IP_STR
8206 BGP_STR
8386ac43 8207 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8208 "Network in the BGP routing table to display\n"
8209 "JavaScript Object Notation\n")
718e3744 8210{
6aeb9e78 8211 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8212}
8213
8386ac43 8214DEFUN (show_ip_bgp_instance_route_pathtype,
8215 show_ip_bgp_instance_route_pathtype_cmd,
8216 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D (bestpath|multipath) {json}",
50ef26d4 8217 SHOW_STR
8218 IP_STR
8219 BGP_STR
8386ac43 8220 BGP_INSTANCE_HELP_STR
50ef26d4 8221 "Network in the BGP routing table to display\n"
8222 "Display only the bestpath\n"
8223 "Display only multipaths\n"
8224 "JavaScript Object Notation\n")
8225{
8226 u_char uj = use_json(argc, argv);
8227
8228 if (strncmp (argv[3], "b", 1) == 0)
8229 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8230 else
8231 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8232}
8233
8386ac43 8234DEFUN (show_ip_bgp_instance_prefix,
8235 show_ip_bgp_instance_prefix_cmd,
8236 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M {json}",
718e3744 8237 SHOW_STR
8238 IP_STR
8239 BGP_STR
8386ac43 8240 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8241 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8242 "JavaScript Object Notation\n")
718e3744 8243{
6aeb9e78 8244 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8245}
8246
8386ac43 8247DEFUN (show_ip_bgp_instance_prefix_pathtype,
8248 show_ip_bgp_instance_prefix_pathtype_cmd,
8249 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M (bestpath|multipath) {json}",
50ef26d4 8250 SHOW_STR
8251 IP_STR
8252 BGP_STR
8386ac43 8253 BGP_INSTANCE_HELP_STR
50ef26d4 8254 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8255 "Display only the bestpath\n"
8256 "Display only multipaths\n"
8257 "JavaScript Object Notation\n")
8258{
8259 u_char uj = use_json(argc, argv);
8260 if (strncmp (argv[3], "b", 1) == 0)
8261 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8262 else
8263 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8264}
8265
718e3744 8266#ifdef HAVE_IPV6
8267DEFUN (show_bgp,
8268 show_bgp_cmd,
b05a1c8b 8269 "show bgp {json}",
718e3744 8270 SHOW_STR
b05a1c8b
DS
8271 BGP_STR
8272 "JavaScript Object Notation\n")
718e3744 8273{
5a646650 8274 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
db7c8528 8275 NULL, use_json(argc, argv));
718e3744 8276}
8277
8278ALIAS (show_bgp,
8279 show_bgp_ipv6_cmd,
b05a1c8b 8280 "show bgp ipv6 {json}",
718e3744 8281 SHOW_STR
8282 BGP_STR
b05a1c8b
DS
8283 "Address family\n"
8284 "JavaScript Object Notation\n")
718e3744 8285
95cbbd2a
ML
8286DEFUN (show_bgp_ipv6_safi,
8287 show_bgp_ipv6_safi_cmd,
b05a1c8b 8288 "show bgp ipv6 (unicast|multicast) {json}",
95cbbd2a
ML
8289 SHOW_STR
8290 BGP_STR
8291 "Address family\n"
8292 "Address Family modifier\n"
47fc97cc 8293 "Address Family modifier\n"
b05a1c8b 8294 "JavaScript Object Notation\n")
47fc97cc 8295{
db7c8528 8296 u_char uj = use_json(argc, argv);
47fc97cc
DS
8297 if (strncmp (argv[0], "m", 1) == 0)
8298 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
db7c8528 8299 NULL, uj);
47fc97cc 8300
db7c8528 8301 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
95cbbd2a
ML
8302}
8303
47e9b292
DW
8304static void
8305bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty)
8306{
8307 vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our"
8308 " next release%sPlese use 'show bgp ipv6' instead%s%s",
8309 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8310}
8311
718e3744 8312/* old command */
8313DEFUN (show_ipv6_bgp,
8314 show_ipv6_bgp_cmd,
b05a1c8b 8315 "show ipv6 bgp {json}",
718e3744 8316 SHOW_STR
8317 IP_STR
b05a1c8b
DS
8318 BGP_STR
8319 "JavaScript Object Notation\n")
718e3744 8320{
47e9b292 8321 bgp_show_ipv6_bgp_deprecate_warning(vty);
5a646650 8322 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
db7c8528 8323 NULL, use_json(argc, argv));
718e3744 8324}
8325
8326DEFUN (show_bgp_route,
8327 show_bgp_route_cmd,
b05a1c8b 8328 "show bgp X:X::X:X {json}",
718e3744 8329 SHOW_STR
8330 BGP_STR
b05a1c8b
DS
8331 "Network in the BGP routing table to display\n"
8332 "JavaScript Object Notation\n")
718e3744 8333{
db7c8528 8334 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8335}
8336
8337ALIAS (show_bgp_route,
8338 show_bgp_ipv6_route_cmd,
b05a1c8b 8339 "show bgp ipv6 X:X::X:X {json}",
718e3744 8340 SHOW_STR
8341 BGP_STR
8342 "Address family\n"
b05a1c8b
DS
8343 "Network in the BGP routing table to display\n"
8344 "JavaScript Object Notation\n")
718e3744 8345
95cbbd2a
ML
8346DEFUN (show_bgp_ipv6_safi_route,
8347 show_bgp_ipv6_safi_route_cmd,
b05a1c8b 8348 "show bgp ipv6 (unicast|multicast) X:X::X:X {json}",
95cbbd2a
ML
8349 SHOW_STR
8350 BGP_STR
8351 "Address family\n"
8352 "Address Family modifier\n"
8353 "Address Family modifier\n"
b05a1c8b
DS
8354 "Network in the BGP routing table to display\n"
8355 "JavaScript Object Notation\n")
95cbbd2a 8356{
db7c8528 8357 u_char uj = use_json(argc, argv);
95cbbd2a 8358 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 8359 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
95cbbd2a 8360
db7c8528 8361 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
4092b06c
DS
8362}
8363
8364DEFUN (show_bgp_route_pathtype,
8365 show_bgp_route_pathtype_cmd,
b05a1c8b 8366 "show bgp X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8367 SHOW_STR
8368 BGP_STR
8369 "Network in the BGP routing table to display\n"
8370 "Display only the bestpath\n"
b05a1c8b
DS
8371 "Display only multipaths\n"
8372 "JavaScript Object Notation\n")
4092b06c 8373{
db7c8528 8374 u_char uj = use_json(argc, argv);
4092b06c 8375 if (strncmp (argv[1], "b", 1) == 0)
db7c8528 8376 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 8377 else
db7c8528 8378 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8379}
8380
8381ALIAS (show_bgp_route_pathtype,
8382 show_bgp_ipv6_route_pathtype_cmd,
b05a1c8b 8383 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8384 SHOW_STR
8385 BGP_STR
8386 "Address family\n"
8387 "Network in the BGP routing table to display\n"
8388 "Display only the bestpath\n"
b05a1c8b
DS
8389 "Display only multipaths\n"
8390 "JavaScript Object Notation\n")
4092b06c
DS
8391
8392DEFUN (show_bgp_ipv6_safi_route_pathtype,
8393 show_bgp_ipv6_safi_route_pathtype_cmd,
b05a1c8b 8394 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8395 SHOW_STR
8396 BGP_STR
8397 "Address family\n"
8398 "Address Family modifier\n"
8399 "Address Family modifier\n"
8400 "Network in the BGP routing table to display\n"
8401 "Display only the bestpath\n"
b05a1c8b
DS
8402 "Display only multipaths\n"
8403 "JavaScript Object Notation\n")
4092b06c 8404{
db7c8528 8405 u_char uj = use_json(argc, argv);
4092b06c
DS
8406 if (strncmp (argv[0], "m", 1) == 0)
8407 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 8408 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 8409 else
db7c8528 8410 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8411 else
8412 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 8413 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 8414 else
db7c8528 8415 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
95cbbd2a
ML
8416}
8417
718e3744 8418/* old command */
8419DEFUN (show_ipv6_bgp_route,
8420 show_ipv6_bgp_route_cmd,
b05a1c8b 8421 "show ipv6 bgp X:X::X:X {json}",
718e3744 8422 SHOW_STR
8423 IP_STR
8424 BGP_STR
b05a1c8b
DS
8425 "Network in the BGP routing table to display\n"
8426 "JavaScript Object Notation\n")
718e3744 8427{
47e9b292 8428 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 8429 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8430}
8431
8432DEFUN (show_bgp_prefix,
8433 show_bgp_prefix_cmd,
b05a1c8b 8434 "show bgp X:X::X:X/M {json}",
718e3744 8435 SHOW_STR
8436 BGP_STR
b05a1c8b
DS
8437 "IPv6 prefix <network>/<length>\n"
8438 "JavaScript Object Notation\n")
718e3744 8439{
db7c8528 8440 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8441}
8442
8443ALIAS (show_bgp_prefix,
8444 show_bgp_ipv6_prefix_cmd,
b05a1c8b 8445 "show bgp ipv6 X:X::X:X/M {json}",
718e3744 8446 SHOW_STR
8447 BGP_STR
8448 "Address family\n"
b05a1c8b
DS
8449 "IPv6 prefix <network>/<length>\n"
8450 "JavaScript Object Notation\n")
718e3744 8451
95cbbd2a
ML
8452DEFUN (show_bgp_ipv6_safi_prefix,
8453 show_bgp_ipv6_safi_prefix_cmd,
b05a1c8b 8454 "show bgp ipv6 (unicast|multicast) X:X::X:X/M {json}",
95cbbd2a
ML
8455 SHOW_STR
8456 BGP_STR
8457 "Address family\n"
8458 "Address Family modifier\n"
8459 "Address Family modifier\n"
b05a1c8b
DS
8460 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8461 "JavaScript Object Notation\n")
95cbbd2a 8462{
db7c8528 8463 u_char uj = use_json(argc, argv);
95cbbd2a 8464 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 8465 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
95cbbd2a 8466
db7c8528 8467 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
4092b06c
DS
8468}
8469
8470DEFUN (show_bgp_prefix_pathtype,
8471 show_bgp_prefix_pathtype_cmd,
b05a1c8b 8472 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8473 SHOW_STR
8474 BGP_STR
8475 "IPv6 prefix <network>/<length>\n"
8476 "Display only the bestpath\n"
b05a1c8b
DS
8477 "Display only multipaths\n"
8478 "JavaScript Object Notation\n")
4092b06c 8479{
db7c8528 8480 u_char uj = use_json(argc, argv);
4092b06c 8481 if (strncmp (argv[1], "b", 1) == 0)
db7c8528 8482 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8483 else
db7c8528 8484 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8485}
8486
8487ALIAS (show_bgp_prefix_pathtype,
8488 show_bgp_ipv6_prefix_pathtype_cmd,
b05a1c8b 8489 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8490 SHOW_STR
8491 BGP_STR
8492 "Address family\n"
8493 "IPv6 prefix <network>/<length>\n"
8494 "Display only the bestpath\n"
b05a1c8b
DS
8495 "Display only multipaths\n"
8496 "JavaScript Object Notation\n")
4092b06c
DS
8497
8498DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8499 show_bgp_ipv6_safi_prefix_pathtype_cmd,
b05a1c8b 8500 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8501 SHOW_STR
8502 BGP_STR
8503 "Address family\n"
8504 "Address Family modifier\n"
8505 "Address Family modifier\n"
8506 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8507 "Display only the bestpath\n"
b05a1c8b
DS
8508 "Display only multipaths\n"
8509 "JavaScript Object Notation\n")
4092b06c 8510{
db7c8528 8511 u_char uj = use_json(argc, argv);
4092b06c
DS
8512 if (strncmp (argv[0], "m", 1) == 0)
8513 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 8514 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8515 else
db7c8528 8516 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8517 else
8518 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 8519 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8520 else
db7c8528 8521 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
95cbbd2a
ML
8522}
8523
718e3744 8524/* old command */
8525DEFUN (show_ipv6_bgp_prefix,
8526 show_ipv6_bgp_prefix_cmd,
b05a1c8b 8527 "show ipv6 bgp X:X::X:X/M {json}",
718e3744 8528 SHOW_STR
8529 IP_STR
8530 BGP_STR
b05a1c8b
DS
8531 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8532 "JavaScript Object Notation\n")
718e3744 8533{
47e9b292 8534 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 8535 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8536}
8537
bb46e94f 8538DEFUN (show_bgp_view,
8386ac43 8539 show_bgp_instance_cmd,
8540 "show bgp " BGP_INSTANCE_CMD " {json}",
bb46e94f 8541 SHOW_STR
8542 BGP_STR
8386ac43 8543 BGP_INSTANCE_HELP_STR
b05a1c8b 8544 "JavaScript Object Notation\n")
bb46e94f 8545{
8546 struct bgp *bgp;
8547
8548 /* BGP structure lookup. */
6aeb9e78 8549 bgp = bgp_lookup_by_name (argv[1]);
bb46e94f 8550 if (bgp == NULL)
db7c8528 8551 {
6aeb9e78 8552 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
db7c8528
DS
8553 return CMD_WARNING;
8554 }
8555
8556 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
bb46e94f 8557}
8558
f186de26 8559DEFUN (show_bgp_instance_all,
8560 show_bgp_instance_all_cmd,
8561 "show bgp " BGP_INSTANCE_ALL_CMD " {json}",
8562 SHOW_STR
8563 BGP_STR
8564 BGP_INSTANCE_ALL_HELP_STR
8565 "JavaScript Object Notation\n")
8566{
8567 u_char uj = use_json(argc, argv);
8568
8569 bgp_show_all_instances_routes_vty (vty, AFI_IP6, SAFI_UNICAST, uj);
8570 return CMD_SUCCESS;
8571}
8572
bb46e94f 8573ALIAS (show_bgp_view,
8386ac43 8574 show_bgp_instance_ipv6_cmd,
8575 "show bgp " BGP_INSTANCE_CMD " ipv6 {json}",
bb46e94f 8576 SHOW_STR
8577 BGP_STR
8386ac43 8578 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8579 "Address family\n"
8580 "JavaScript Object Notation\n")
bb46e94f 8581
8386ac43 8582DEFUN (show_bgp_instance_route,
8583 show_bgp_instance_route_cmd,
8584 "show bgp " BGP_INSTANCE_CMD " X:X::X:X {json}",
bb46e94f 8585 SHOW_STR
8586 BGP_STR
8386ac43 8587 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8588 "Network in the BGP routing table to display\n"
8589 "JavaScript Object Notation\n")
bb46e94f 8590{
6aeb9e78 8591 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
bb46e94f 8592}
8593
8386ac43 8594ALIAS (show_bgp_instance_route,
8595 show_bgp_instance_ipv6_route_cmd,
8596 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X {json}",
bb46e94f 8597 SHOW_STR
8598 BGP_STR
8386ac43 8599 BGP_INSTANCE_HELP_STR
bb46e94f 8600 "Address family\n"
b05a1c8b
DS
8601 "Network in the BGP routing table to display\n"
8602 "JavaScript Object Notation\n")
bb46e94f 8603
8386ac43 8604DEFUN (show_bgp_instance_route_pathtype,
8605 show_bgp_instance_route_pathtype_cmd,
8606 "show bgp " BGP_INSTANCE_CMD " X:X::X:X (bestpath|multipath) {json}",
50ef26d4 8607 SHOW_STR
8608 BGP_STR
8386ac43 8609 BGP_INSTANCE_HELP_STR
50ef26d4 8610 "Network in the BGP routing table to display\n"
8611 "Display only the bestpath\n"
8612 "Display only multipaths\n"
8613 "JavaScript Object Notation\n")
8614{
8615 u_char uj = use_json(argc, argv);
8616 if (strncmp (argv[3], "b", 1) == 0)
8617 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8618 else
8619 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8620}
8621
8386ac43 8622ALIAS (show_bgp_instance_route_pathtype,
8623 show_bgp_instance_ipv6_route_pathtype_cmd,
8624 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X (bestpath|multipath) {json}",
50ef26d4 8625 SHOW_STR
8626 BGP_STR
8386ac43 8627 BGP_INSTANCE_HELP_STR
50ef26d4 8628 "Address family\n"
8629 "Network in the BGP routing table to display\n"
8630 "Display only the bestpath\n"
8631 "Display only multipaths\n"
8632 "JavaScript Object Notation\n")
8633
8386ac43 8634DEFUN (show_bgp_instance_prefix,
8635 show_bgp_instance_prefix_cmd,
8636 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M {json}",
bb46e94f 8637 SHOW_STR
8638 BGP_STR
8386ac43 8639 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8640 "IPv6 prefix <network>/<length>\n"
8641 "JavaScript Object Notation\n")
bb46e94f 8642{
6aeb9e78 8643 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
bb46e94f 8644}
8645
8386ac43 8646ALIAS (show_bgp_instance_prefix,
8647 show_bgp_instance_ipv6_prefix_cmd,
8648 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M {json}",
bb46e94f 8649 SHOW_STR
8650 BGP_STR
8386ac43 8651 BGP_INSTANCE_HELP_STR
bb46e94f 8652 "Address family\n"
b05a1c8b
DS
8653 "IPv6 prefix <network>/<length>\n"
8654 "JavaScript Object Notation\n")
bb46e94f 8655
8386ac43 8656DEFUN (show_bgp_instance_prefix_pathtype,
8657 show_bgp_instance_prefix_pathtype_cmd,
8658 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M (bestpath|multipath) {json}",
50ef26d4 8659 SHOW_STR
8660 BGP_STR
8386ac43 8661 BGP_INSTANCE_HELP_STR
50ef26d4 8662 "IPv6 prefix <network>/<length>\n"
8663 "Display only the bestpath\n"
8664 "Display only multipaths\n"
8665 "JavaScript Object Notation\n")
8666{
8667 u_char uj = use_json(argc, argv);
8668 if (strncmp (argv[3], "b", 1) == 0)
8669 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8670 else
8671 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8672}
8673
8386ac43 8674ALIAS (show_bgp_instance_prefix_pathtype,
8675 show_bgp_instance_ipv6_prefix_pathtype_cmd,
8676 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M (bestpath|multipath) {json}",
50ef26d4 8677 SHOW_STR
8678 BGP_STR
8386ac43 8679 BGP_INSTANCE_HELP_STR
50ef26d4 8680 "Address family\n"
8681 "IPv6 prefix <network>/<length>\n"
8682 "Display only the bestpath\n"
8683 "Display only multipaths\n"
8684 "JavaScript Object Notation\n")
8685
8386ac43 8686DEFUN (show_bgp_instance_prefix_list,
8687 show_bgp_instance_prefix_list_cmd,
8688 "show bgp " BGP_INSTANCE_CMD " prefix-list WORD",
50ef26d4 8689 SHOW_STR
8690 BGP_STR
8386ac43 8691 BGP_INSTANCE_HELP_STR
50ef26d4 8692 "Display routes conforming to the prefix-list\n"
8693 "IPv6 prefix-list name\n")
8694{
8695 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8696 bgp_show_type_prefix_list);
8697}
8698
8386ac43 8699ALIAS (show_bgp_instance_prefix_list,
8700 show_bgp_instance_ipv6_prefix_list_cmd,
8701 "show bgp " BGP_INSTANCE_CMD " ipv6 prefix-list WORD",
50ef26d4 8702 SHOW_STR
8703 BGP_STR
8386ac43 8704 BGP_INSTANCE_HELP_STR
50ef26d4 8705 "Address family\n"
8706 "Display routes conforming to the prefix-list\n"
8707 "IPv6 prefix-list name\n")
8708
8386ac43 8709DEFUN (show_bgp_instance_filter_list,
8710 show_bgp_instance_filter_list_cmd,
8711 "show bgp " BGP_INSTANCE_CMD " filter-list WORD",
50ef26d4 8712 SHOW_STR
8713 BGP_STR
8386ac43 8714 BGP_INSTANCE_HELP_STR
50ef26d4 8715 "Display routes conforming to the filter-list\n"
8716 "Regular expression access list name\n")
8717{
8718 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8719 bgp_show_type_filter_list);
8720}
8721
8386ac43 8722ALIAS (show_bgp_instance_filter_list,
8723 show_bgp_instance_ipv6_filter_list_cmd,
8724 "show bgp " BGP_INSTANCE_CMD " ipv6 filter-list WORD",
50ef26d4 8725 SHOW_STR
8726 BGP_STR
8386ac43 8727 BGP_INSTANCE_HELP_STR
50ef26d4 8728 "Address family\n"
8729 "Display routes conforming to the filter-list\n"
8730 "Regular expression access list name\n")
8731
8386ac43 8732DEFUN (show_bgp_instance_route_map,
8733 show_bgp_instance_route_map_cmd,
8734 "show bgp " BGP_INSTANCE_CMD " route-map WORD",
50ef26d4 8735 SHOW_STR
8736 BGP_STR
8386ac43 8737 BGP_INSTANCE_HELP_STR
50ef26d4 8738 "Display routes matching the route-map\n"
8739 "A route-map to match on\n")
8740{
8741 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8742 bgp_show_type_route_map);
8743}
8744
8386ac43 8745ALIAS (show_bgp_instance_route_map,
8746 show_bgp_instance_ipv6_route_map_cmd,
8747 "show bgp " BGP_INSTANCE_CMD " ipv6 route-map WORD",
50ef26d4 8748 SHOW_STR
8749 BGP_STR
8386ac43 8750 BGP_INSTANCE_HELP_STR
50ef26d4 8751 "Address family\n"
8752 "Display routes matching the route-map\n"
8753 "A route-map to match on\n")
8754
8386ac43 8755DEFUN (show_bgp_instance_community_list,
8756 show_bgp_instance_community_list_cmd,
8757 "show bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
50ef26d4 8758 SHOW_STR
8759 BGP_STR
8386ac43 8760 BGP_INSTANCE_HELP_STR
50ef26d4 8761 "Display routes matching the community-list\n"
8762 "community-list number\n"
8763 "community-list name\n")
8764{
8765 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP6, SAFI_UNICAST);
8766}
8767
8386ac43 8768ALIAS (show_bgp_instance_community_list,
8769 show_bgp_instance_ipv6_community_list_cmd,
8770 "show bgp " BGP_INSTANCE_CMD " ipv6 community-list (<1-500>|WORD)",
50ef26d4 8771 SHOW_STR
8772 BGP_STR
8386ac43 8773 BGP_INSTANCE_HELP_STR
50ef26d4 8774 "Address family\n"
8775 "Display routes matching the community-list\n"
8776 "community-list number\n"
8777 "community-list name\n")
8778
8386ac43 8779DEFUN (show_bgp_instance_prefix_longer,
8780 show_bgp_instance_prefix_longer_cmd,
8781 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M longer-prefixes",
50ef26d4 8782 SHOW_STR
8783 BGP_STR
8386ac43 8784 BGP_INSTANCE_HELP_STR
50ef26d4 8785 "IPv6 prefix <network>/<length>\n"
8786 "Display route and more specific routes\n")
8787{
8788 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8789 bgp_show_type_prefix_longer);
8790}
8791
8386ac43 8792ALIAS (show_bgp_instance_prefix_longer,
8793 show_bgp_instance_ipv6_prefix_longer_cmd,
8794 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M longer-prefixes",
50ef26d4 8795 SHOW_STR
8796 BGP_STR
8386ac43 8797 BGP_INSTANCE_HELP_STR
50ef26d4 8798 "Address family\n"
8799 "IPv6 prefix <network>/<length>\n"
8800 "Display route and more specific routes\n")
8801
718e3744 8802/* old command */
8803DEFUN (show_ipv6_mbgp,
8804 show_ipv6_mbgp_cmd,
b05a1c8b 8805 "show ipv6 mbgp {json}",
718e3744 8806 SHOW_STR
8807 IP_STR
b05a1c8b
DS
8808 MBGP_STR
8809 "JavaScript Object Notation\n")
718e3744 8810{
47e9b292 8811 bgp_show_ipv6_bgp_deprecate_warning(vty);
5a646650 8812 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
db7c8528 8813 NULL, use_json(argc, argv));
718e3744 8814}
8815
8816/* old command */
8817DEFUN (show_ipv6_mbgp_route,
8818 show_ipv6_mbgp_route_cmd,
b05a1c8b 8819 "show ipv6 mbgp X:X::X:X {json}",
718e3744 8820 SHOW_STR
8821 IP_STR
8822 MBGP_STR
b05a1c8b
DS
8823 "Network in the MBGP routing table to display\n"
8824 "JavaScript Object Notation\n")
718e3744 8825{
47e9b292 8826 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 8827 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8828}
8829
8830/* old command */
8831DEFUN (show_ipv6_mbgp_prefix,
8832 show_ipv6_mbgp_prefix_cmd,
b05a1c8b 8833 "show ipv6 mbgp X:X::X:X/M {json}",
718e3744 8834 SHOW_STR
8835 IP_STR
8836 MBGP_STR
b05a1c8b
DS
8837 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8838 "JavaScript Object Notation\n")
718e3744 8839{
47e9b292 8840 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 8841 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8842}
8843#endif
6b0655a2 8844
718e3744 8845
94f2b392 8846static int
fd79ac91 8847bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
718e3744 8848 safi_t safi, enum bgp_show_type type)
8849{
8850 int i;
8851 struct buffer *b;
8852 char *regstr;
8853 int first;
8854 regex_t *regex;
5a646650 8855 int rc;
718e3744 8856
8857 first = 0;
8858 b = buffer_new (1024);
8859 for (i = 0; i < argc; i++)
8860 {
8861 if (first)
8862 buffer_putc (b, ' ');
8863 else
8864 {
8865 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8866 continue;
8867 first = 1;
8868 }
8869
8870 buffer_putstr (b, argv[i]);
8871 }
8872 buffer_putc (b, '\0');
8873
8874 regstr = buffer_getstr (b);
8875 buffer_free (b);
8876
8877 regex = bgp_regcomp (regstr);
3b8b1855 8878 XFREE(MTYPE_TMP, regstr);
718e3744 8879 if (! regex)
8880 {
8881 vty_out (vty, "Can't compile regexp %s%s", argv[0],
8882 VTY_NEWLINE);
8883 return CMD_WARNING;
8884 }
8885
b05a1c8b 8886 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
5a646650 8887 bgp_regex_free (regex);
8888 return rc;
718e3744 8889}
8890
8891DEFUN (show_ip_bgp_regexp,
8892 show_ip_bgp_regexp_cmd,
8893 "show ip bgp regexp .LINE",
8894 SHOW_STR
8895 IP_STR
8896 BGP_STR
8897 "Display routes matching the AS path regular expression\n"
8898 "A regular-expression to match the BGP AS paths\n")
8899{
8900 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8901 bgp_show_type_regexp);
8902}
8903
8904DEFUN (show_ip_bgp_flap_regexp,
8905 show_ip_bgp_flap_regexp_cmd,
8906 "show ip bgp flap-statistics regexp .LINE",
8907 SHOW_STR
8908 IP_STR
8909 BGP_STR
8910 "Display flap statistics of routes\n"
8911 "Display routes matching the AS path regular expression\n"
8912 "A regular-expression to match the BGP AS paths\n")
8913{
8914 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8915 bgp_show_type_flap_regexp);
8916}
8917
81304aaf
B
8918ALIAS (show_ip_bgp_flap_regexp,
8919 show_ip_bgp_damp_flap_regexp_cmd,
8920 "show ip bgp dampening flap-statistics regexp .LINE",
8921 SHOW_STR
8922 IP_STR
8923 BGP_STR
8924 "Display detailed information about dampening\n"
8925 "Display flap statistics of routes\n"
8926 "Display routes matching the AS path regular expression\n"
8927 "A regular-expression to match the BGP AS paths\n")
8928
718e3744 8929DEFUN (show_ip_bgp_ipv4_regexp,
8930 show_ip_bgp_ipv4_regexp_cmd,
8931 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
8932 SHOW_STR
8933 IP_STR
8934 BGP_STR
8935 "Address family\n"
8936 "Address Family modifier\n"
8937 "Address Family modifier\n"
8938 "Display routes matching the AS path regular expression\n"
8939 "A regular-expression to match the BGP AS paths\n")
8940{
8941 if (strncmp (argv[0], "m", 1) == 0)
8942 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
8943 bgp_show_type_regexp);
8944
8945 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8946 bgp_show_type_regexp);
8947}
8948
8949#ifdef HAVE_IPV6
8950DEFUN (show_bgp_regexp,
8951 show_bgp_regexp_cmd,
8952 "show bgp regexp .LINE",
8953 SHOW_STR
8954 BGP_STR
8955 "Display routes matching the AS path regular expression\n"
8956 "A regular-expression to match the BGP AS paths\n")
8957{
8958 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8959 bgp_show_type_regexp);
8960}
8961
8962ALIAS (show_bgp_regexp,
8963 show_bgp_ipv6_regexp_cmd,
8964 "show bgp ipv6 regexp .LINE",
8965 SHOW_STR
8966 BGP_STR
8967 "Address family\n"
8968 "Display routes matching the AS path regular expression\n"
8969 "A regular-expression to match the BGP AS paths\n")
8970
8971/* old command */
8972DEFUN (show_ipv6_bgp_regexp,
8973 show_ipv6_bgp_regexp_cmd,
8974 "show ipv6 bgp regexp .LINE",
8975 SHOW_STR
8976 IP_STR
8977 BGP_STR
8978 "Display routes matching the AS path regular expression\n"
8979 "A regular-expression to match the BGP AS paths\n")
8980{
47e9b292 8981 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 8982 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8983 bgp_show_type_regexp);
8984}
8985
8986/* old command */
8987DEFUN (show_ipv6_mbgp_regexp,
8988 show_ipv6_mbgp_regexp_cmd,
8989 "show ipv6 mbgp regexp .LINE",
8990 SHOW_STR
8991 IP_STR
8992 BGP_STR
8993 "Display routes matching the AS path regular expression\n"
8994 "A regular-expression to match the MBGP AS paths\n")
8995{
47e9b292 8996 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 8997 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
8998 bgp_show_type_regexp);
8999}
9000#endif /* HAVE_IPV6 */
6b0655a2 9001
94f2b392 9002static int
50ef26d4 9003bgp_show_prefix_list (struct vty *vty, const char *name,
9004 const char *prefix_list_str, afi_t afi,
718e3744 9005 safi_t safi, enum bgp_show_type type)
9006{
9007 struct prefix_list *plist;
50ef26d4 9008 struct bgp *bgp = NULL;
9009
9010 if (name && !(bgp = bgp_lookup_by_name(name)))
9011 {
9012 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9013 return CMD_WARNING;
9014 }
718e3744 9015
9016 plist = prefix_list_lookup (afi, prefix_list_str);
9017 if (plist == NULL)
9018 {
9019 vty_out (vty, "%% %s is not a valid prefix-list name%s",
9020 prefix_list_str, VTY_NEWLINE);
9021 return CMD_WARNING;
9022 }
9023
50ef26d4 9024 return bgp_show (vty, bgp, afi, safi, type, plist, 0);
718e3744 9025}
9026
9027DEFUN (show_ip_bgp_prefix_list,
9028 show_ip_bgp_prefix_list_cmd,
9029 "show ip bgp prefix-list WORD",
9030 SHOW_STR
9031 IP_STR
9032 BGP_STR
9033 "Display routes conforming to the prefix-list\n"
9034 "IP prefix-list name\n")
9035{
50ef26d4 9036 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9037 bgp_show_type_prefix_list);
9038}
9039
8386ac43 9040DEFUN (show_ip_bgp_instance_prefix_list,
9041 show_ip_bgp_instance_prefix_list_cmd,
9042 "show ip bgp " BGP_INSTANCE_CMD " prefix-list WORD",
50ef26d4 9043 SHOW_STR
9044 IP_STR
9045 BGP_STR
8386ac43 9046 BGP_INSTANCE_HELP_STR
50ef26d4 9047 "Display routes conforming to the prefix-list\n"
9048 "IP prefix-list name\n")
9049{
9050 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
718e3744 9051 bgp_show_type_prefix_list);
9052}
9053
9054DEFUN (show_ip_bgp_flap_prefix_list,
9055 show_ip_bgp_flap_prefix_list_cmd,
9056 "show ip bgp flap-statistics prefix-list WORD",
9057 SHOW_STR
9058 IP_STR
9059 BGP_STR
9060 "Display flap statistics of routes\n"
9061 "Display routes conforming to the prefix-list\n"
9062 "IP prefix-list name\n")
9063{
50ef26d4 9064 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 9065 bgp_show_type_flap_prefix_list);
9066}
9067
81304aaf
B
9068ALIAS (show_ip_bgp_flap_prefix_list,
9069 show_ip_bgp_damp_flap_prefix_list_cmd,
9070 "show ip bgp dampening flap-statistics prefix-list WORD",
9071 SHOW_STR
9072 IP_STR
9073 BGP_STR
9074 "Display detailed information about dampening\n"
9075 "Display flap statistics of routes\n"
9076 "Display routes conforming to the prefix-list\n"
9077 "IP prefix-list name\n")
9078
718e3744 9079DEFUN (show_ip_bgp_ipv4_prefix_list,
9080 show_ip_bgp_ipv4_prefix_list_cmd,
9081 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
9082 SHOW_STR
9083 IP_STR
9084 BGP_STR
9085 "Address family\n"
9086 "Address Family modifier\n"
9087 "Address Family modifier\n"
9088 "Display routes conforming to the prefix-list\n"
9089 "IP prefix-list name\n")
9090{
9091 if (strncmp (argv[0], "m", 1) == 0)
50ef26d4 9092 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
718e3744 9093 bgp_show_type_prefix_list);
9094
50ef26d4 9095 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
718e3744 9096 bgp_show_type_prefix_list);
9097}
9098
9099#ifdef HAVE_IPV6
9100DEFUN (show_bgp_prefix_list,
9101 show_bgp_prefix_list_cmd,
9102 "show bgp prefix-list WORD",
9103 SHOW_STR
9104 BGP_STR
9105 "Display routes conforming to the prefix-list\n"
9106 "IPv6 prefix-list name\n")
9107{
50ef26d4 9108 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 9109 bgp_show_type_prefix_list);
9110}
9111
9112ALIAS (show_bgp_prefix_list,
9113 show_bgp_ipv6_prefix_list_cmd,
9114 "show bgp ipv6 prefix-list WORD",
9115 SHOW_STR
9116 BGP_STR
9117 "Address family\n"
9118 "Display routes conforming to the prefix-list\n"
9119 "IPv6 prefix-list name\n")
9120
9121/* old command */
9122DEFUN (show_ipv6_bgp_prefix_list,
9123 show_ipv6_bgp_prefix_list_cmd,
9124 "show ipv6 bgp prefix-list WORD",
9125 SHOW_STR
9126 IPV6_STR
9127 BGP_STR
9128 "Display routes matching the prefix-list\n"
9129 "IPv6 prefix-list name\n")
9130{
47e9b292 9131 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 9132 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 9133 bgp_show_type_prefix_list);
9134}
9135
9136/* old command */
9137DEFUN (show_ipv6_mbgp_prefix_list,
9138 show_ipv6_mbgp_prefix_list_cmd,
9139 "show ipv6 mbgp prefix-list WORD",
9140 SHOW_STR
9141 IPV6_STR
9142 MBGP_STR
9143 "Display routes matching the prefix-list\n"
9144 "IPv6 prefix-list name\n")
9145{
47e9b292 9146 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 9147 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
718e3744 9148 bgp_show_type_prefix_list);
9149}
9150#endif /* HAVE_IPV6 */
6b0655a2 9151
94f2b392 9152static int
50ef26d4 9153bgp_show_filter_list (struct vty *vty, const char *name,
9154 const char *filter, afi_t afi,
718e3744 9155 safi_t safi, enum bgp_show_type type)
9156{
9157 struct as_list *as_list;
50ef26d4 9158 struct bgp *bgp = NULL;
9159
9160 if (name && !(bgp = bgp_lookup_by_name(name)))
9161 {
9162 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9163 return CMD_WARNING;
9164 }
718e3744 9165
9166 as_list = as_list_lookup (filter);
9167 if (as_list == NULL)
9168 {
9169 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
9170 return CMD_WARNING;
9171 }
9172
50ef26d4 9173 return bgp_show (vty, bgp, afi, safi, type, as_list, 0);
718e3744 9174}
9175
9176DEFUN (show_ip_bgp_filter_list,
9177 show_ip_bgp_filter_list_cmd,
9178 "show ip bgp filter-list WORD",
9179 SHOW_STR
9180 IP_STR
9181 BGP_STR
9182 "Display routes conforming to the filter-list\n"
9183 "Regular expression access list name\n")
9184{
50ef26d4 9185 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9186 bgp_show_type_filter_list);
9187}
9188
8386ac43 9189DEFUN (show_ip_bgp_instance_filter_list,
9190 show_ip_bgp_instance_filter_list_cmd,
9191 "show ip bgp " BGP_INSTANCE_CMD " filter-list WORD",
50ef26d4 9192 SHOW_STR
9193 IP_STR
9194 BGP_STR
8386ac43 9195 BGP_INSTANCE_HELP_STR
50ef26d4 9196 "Display routes conforming to the filter-list\n"
9197 "Regular expression access list name\n")
9198{
9199 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
718e3744 9200 bgp_show_type_filter_list);
9201}
9202
9203DEFUN (show_ip_bgp_flap_filter_list,
9204 show_ip_bgp_flap_filter_list_cmd,
9205 "show ip bgp flap-statistics filter-list WORD",
9206 SHOW_STR
9207 IP_STR
9208 BGP_STR
9209 "Display flap statistics of routes\n"
9210 "Display routes conforming to the filter-list\n"
9211 "Regular expression access list name\n")
9212{
50ef26d4 9213 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 9214 bgp_show_type_flap_filter_list);
9215}
9216
81304aaf
B
9217ALIAS (show_ip_bgp_flap_filter_list,
9218 show_ip_bgp_damp_flap_filter_list_cmd,
9219 "show ip bgp dampening flap-statistics filter-list WORD",
9220 SHOW_STR
9221 IP_STR
9222 BGP_STR
9223 "Display detailed information about dampening\n"
9224 "Display flap statistics of routes\n"
9225 "Display routes conforming to the filter-list\n"
9226 "Regular expression access list name\n")
9227
718e3744 9228DEFUN (show_ip_bgp_ipv4_filter_list,
9229 show_ip_bgp_ipv4_filter_list_cmd,
9230 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
9231 SHOW_STR
9232 IP_STR
9233 BGP_STR
9234 "Address family\n"
9235 "Address Family modifier\n"
9236 "Address Family modifier\n"
9237 "Display routes conforming to the filter-list\n"
9238 "Regular expression access list name\n")
9239{
9240 if (strncmp (argv[0], "m", 1) == 0)
50ef26d4 9241 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
718e3744 9242 bgp_show_type_filter_list);
9243
50ef26d4 9244 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
718e3744 9245 bgp_show_type_filter_list);
9246}
9247
9248#ifdef HAVE_IPV6
9249DEFUN (show_bgp_filter_list,
9250 show_bgp_filter_list_cmd,
9251 "show bgp filter-list WORD",
9252 SHOW_STR
9253 BGP_STR
9254 "Display routes conforming to the filter-list\n"
9255 "Regular expression access list name\n")
9256{
50ef26d4 9257 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 9258 bgp_show_type_filter_list);
9259}
9260
9261ALIAS (show_bgp_filter_list,
9262 show_bgp_ipv6_filter_list_cmd,
9263 "show bgp ipv6 filter-list WORD",
9264 SHOW_STR
9265 BGP_STR
9266 "Address family\n"
9267 "Display routes conforming to the filter-list\n"
9268 "Regular expression access list name\n")
9269
9270/* old command */
9271DEFUN (show_ipv6_bgp_filter_list,
9272 show_ipv6_bgp_filter_list_cmd,
9273 "show ipv6 bgp filter-list WORD",
9274 SHOW_STR
9275 IPV6_STR
9276 BGP_STR
9277 "Display routes conforming to the filter-list\n"
9278 "Regular expression access list name\n")
9279{
47e9b292 9280 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 9281 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 9282 bgp_show_type_filter_list);
9283}
9284
9285/* old command */
9286DEFUN (show_ipv6_mbgp_filter_list,
9287 show_ipv6_mbgp_filter_list_cmd,
9288 "show ipv6 mbgp filter-list WORD",
9289 SHOW_STR
9290 IPV6_STR
9291 MBGP_STR
9292 "Display routes conforming to the filter-list\n"
9293 "Regular expression access list name\n")
9294{
47e9b292 9295 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 9296 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
718e3744 9297 bgp_show_type_filter_list);
9298}
9299#endif /* HAVE_IPV6 */
6b0655a2 9300
81304aaf
B
9301DEFUN (show_ip_bgp_dampening_info,
9302 show_ip_bgp_dampening_params_cmd,
9303 "show ip bgp dampening parameters",
9304 SHOW_STR
9305 IP_STR
9306 BGP_STR
9307 "Display detailed information about dampening\n"
9308 "Display detail of configured dampening parameters\n")
9309{
9310 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
9311}
9312
94f2b392 9313static int
50ef26d4 9314bgp_show_route_map (struct vty *vty, const char *name,
9315 const char *rmap_str, afi_t afi,
718e3744 9316 safi_t safi, enum bgp_show_type type)
9317{
9318 struct route_map *rmap;
50ef26d4 9319 struct bgp *bgp = NULL;
9320
9321 if (name && !(bgp = bgp_lookup_by_name(name)))
9322 {
9323 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9324 return CMD_WARNING;
9325 }
718e3744 9326
9327 rmap = route_map_lookup_by_name (rmap_str);
9328 if (! rmap)
9329 {
9330 vty_out (vty, "%% %s is not a valid route-map name%s",
9331 rmap_str, VTY_NEWLINE);
9332 return CMD_WARNING;
9333 }
9334
50ef26d4 9335 return bgp_show (vty, bgp, afi, safi, type, rmap, 0);
718e3744 9336}
9337
9338DEFUN (show_ip_bgp_route_map,
9339 show_ip_bgp_route_map_cmd,
9340 "show ip bgp route-map WORD",
9341 SHOW_STR
9342 IP_STR
9343 BGP_STR
9344 "Display routes matching the route-map\n"
9345 "A route-map to match on\n")
9346{
50ef26d4 9347 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9348 bgp_show_type_route_map);
9349}
9350
8386ac43 9351DEFUN (show_ip_bgp_instance_route_map,
9352 show_ip_bgp_instance_route_map_cmd,
9353 "show ip bgp " BGP_INSTANCE_CMD " route-map WORD",
50ef26d4 9354 SHOW_STR
9355 IP_STR
9356 BGP_STR
8386ac43 9357 BGP_INSTANCE_HELP_STR
50ef26d4 9358 "Display routes matching the route-map\n"
9359 "A route-map to match on\n")
9360{
9361 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
718e3744 9362 bgp_show_type_route_map);
9363}
9364
9365DEFUN (show_ip_bgp_flap_route_map,
9366 show_ip_bgp_flap_route_map_cmd,
9367 "show ip bgp flap-statistics route-map WORD",
9368 SHOW_STR
9369 IP_STR
9370 BGP_STR
9371 "Display flap statistics of routes\n"
9372 "Display routes matching the route-map\n"
9373 "A route-map to match on\n")
9374{
50ef26d4 9375 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 9376 bgp_show_type_flap_route_map);
9377}
9378
81304aaf
B
9379ALIAS (show_ip_bgp_flap_route_map,
9380 show_ip_bgp_damp_flap_route_map_cmd,
9381 "show ip bgp dampening flap-statistics route-map WORD",
9382 SHOW_STR
9383 IP_STR
9384 BGP_STR
9385 "Display detailed information about dampening\n"
9386 "Display flap statistics of routes\n"
9387 "Display routes matching the route-map\n"
9388 "A route-map to match on\n")
9389
718e3744 9390DEFUN (show_ip_bgp_ipv4_route_map,
9391 show_ip_bgp_ipv4_route_map_cmd,
9392 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
9393 SHOW_STR
9394 IP_STR
9395 BGP_STR
9396 "Address family\n"
9397 "Address Family modifier\n"
9398 "Address Family modifier\n"
9399 "Display routes matching the route-map\n"
9400 "A route-map to match on\n")
9401{
9402 if (strncmp (argv[0], "m", 1) == 0)
50ef26d4 9403 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
718e3744 9404 bgp_show_type_route_map);
9405
50ef26d4 9406 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
718e3744 9407 bgp_show_type_route_map);
9408}
9409
9410DEFUN (show_bgp_route_map,
9411 show_bgp_route_map_cmd,
9412 "show bgp route-map WORD",
9413 SHOW_STR
9414 BGP_STR
9415 "Display routes matching the route-map\n"
9416 "A route-map to match on\n")
9417{
50ef26d4 9418 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 9419 bgp_show_type_route_map);
9420}
9421
9422ALIAS (show_bgp_route_map,
9423 show_bgp_ipv6_route_map_cmd,
9424 "show bgp ipv6 route-map WORD",
9425 SHOW_STR
9426 BGP_STR
9427 "Address family\n"
9428 "Display routes matching the route-map\n"
9429 "A route-map to match on\n")
6b0655a2 9430
718e3744 9431DEFUN (show_ip_bgp_cidr_only,
9432 show_ip_bgp_cidr_only_cmd,
9433 "show ip bgp cidr-only",
9434 SHOW_STR
9435 IP_STR
9436 BGP_STR
9437 "Display only routes with non-natural netmasks\n")
9438{
9439 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9440 bgp_show_type_cidr_only, NULL, 0);
718e3744 9441}
9442
9443DEFUN (show_ip_bgp_flap_cidr_only,
9444 show_ip_bgp_flap_cidr_only_cmd,
9445 "show ip bgp flap-statistics cidr-only",
9446 SHOW_STR
9447 IP_STR
9448 BGP_STR
9449 "Display flap statistics of routes\n"
9450 "Display only routes with non-natural netmasks\n")
9451{
9452 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9453 bgp_show_type_flap_cidr_only, NULL, 0);
718e3744 9454}
9455
81304aaf
B
9456ALIAS (show_ip_bgp_flap_cidr_only,
9457 show_ip_bgp_damp_flap_cidr_only_cmd,
9458 "show ip bgp dampening flap-statistics cidr-only",
9459 SHOW_STR
9460 IP_STR
9461 BGP_STR
9462 "Display detailed information about dampening\n"
9463 "Display flap statistics of routes\n"
9464 "Display only routes with non-natural netmasks\n")
9465
718e3744 9466DEFUN (show_ip_bgp_ipv4_cidr_only,
9467 show_ip_bgp_ipv4_cidr_only_cmd,
9468 "show ip bgp ipv4 (unicast|multicast) cidr-only",
9469 SHOW_STR
9470 IP_STR
9471 BGP_STR
9472 "Address family\n"
9473 "Address Family modifier\n"
9474 "Address Family modifier\n"
9475 "Display only routes with non-natural netmasks\n")
9476{
9477 if (strncmp (argv[0], "m", 1) == 0)
9478 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
b05a1c8b 9479 bgp_show_type_cidr_only, NULL, 0);
718e3744 9480
9481 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9482 bgp_show_type_cidr_only, NULL, 0);
718e3744 9483}
6b0655a2 9484
718e3744 9485DEFUN (show_ip_bgp_community_all,
9486 show_ip_bgp_community_all_cmd,
9487 "show ip bgp community",
9488 SHOW_STR
9489 IP_STR
9490 BGP_STR
9491 "Display routes matching the communities\n")
9492{
9493 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9494 bgp_show_type_community_all, NULL, 0);
718e3744 9495}
9496
9497DEFUN (show_ip_bgp_ipv4_community_all,
9498 show_ip_bgp_ipv4_community_all_cmd,
9499 "show ip bgp ipv4 (unicast|multicast) community",
9500 SHOW_STR
9501 IP_STR
9502 BGP_STR
9503 "Address family\n"
9504 "Address Family modifier\n"
9505 "Address Family modifier\n"
9506 "Display routes matching the communities\n")
9507{
9508 if (strncmp (argv[0], "m", 1) == 0)
9509 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
b05a1c8b 9510 bgp_show_type_community_all, NULL, 0);
718e3744 9511
9512 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9513 bgp_show_type_community_all, NULL, 0);
718e3744 9514}
9515
9516#ifdef HAVE_IPV6
9517DEFUN (show_bgp_community_all,
9518 show_bgp_community_all_cmd,
9519 "show bgp community",
9520 SHOW_STR
9521 BGP_STR
9522 "Display routes matching the communities\n")
9523{
9524 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 9525 bgp_show_type_community_all, NULL, 0);
718e3744 9526}
9527
9528ALIAS (show_bgp_community_all,
9529 show_bgp_ipv6_community_all_cmd,
9530 "show bgp ipv6 community",
9531 SHOW_STR
9532 BGP_STR
9533 "Address family\n"
9534 "Display routes matching the communities\n")
9535
9536/* old command */
9537DEFUN (show_ipv6_bgp_community_all,
9538 show_ipv6_bgp_community_all_cmd,
9539 "show ipv6 bgp community",
9540 SHOW_STR
9541 IPV6_STR
9542 BGP_STR
9543 "Display routes matching the communities\n")
9544{
47e9b292 9545 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 9546 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 9547 bgp_show_type_community_all, NULL, 0);
718e3744 9548}
9549
9550/* old command */
9551DEFUN (show_ipv6_mbgp_community_all,
9552 show_ipv6_mbgp_community_all_cmd,
9553 "show ipv6 mbgp community",
9554 SHOW_STR
9555 IPV6_STR
9556 MBGP_STR
9557 "Display routes matching the communities\n")
9558{
47e9b292 9559 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 9560 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
b05a1c8b 9561 bgp_show_type_community_all, NULL, 0);
718e3744 9562}
9563#endif /* HAVE_IPV6 */
6b0655a2 9564
94f2b392 9565static int
95cbbd2a
ML
9566bgp_show_community (struct vty *vty, const char *view_name, int argc,
9567 const char **argv, int exact, afi_t afi, safi_t safi)
718e3744 9568{
9569 struct community *com;
9570 struct buffer *b;
95cbbd2a 9571 struct bgp *bgp;
718e3744 9572 int i;
9573 char *str;
9574 int first = 0;
9575
95cbbd2a
ML
9576 /* BGP structure lookup */
9577 if (view_name)
9578 {
9579 bgp = bgp_lookup_by_name (view_name);
9580 if (bgp == NULL)
9581 {
6aeb9e78 9582 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
95cbbd2a
ML
9583 return CMD_WARNING;
9584 }
9585 }
9586 else
9587 {
9588 bgp = bgp_get_default ();
9589 if (bgp == NULL)
9590 {
9591 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9592 return CMD_WARNING;
9593 }
9594 }
9595
718e3744 9596 b = buffer_new (1024);
9597 for (i = 0; i < argc; i++)
9598 {
9599 if (first)
9600 buffer_putc (b, ' ');
9601 else
9602 {
9603 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9604 continue;
9605 first = 1;
9606 }
9607
9608 buffer_putstr (b, argv[i]);
9609 }
9610 buffer_putc (b, '\0');
9611
9612 str = buffer_getstr (b);
9613 buffer_free (b);
9614
9615 com = community_str2com (str);
3b8b1855 9616 XFREE (MTYPE_TMP, str);
718e3744 9617 if (! com)
9618 {
9619 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9620 return CMD_WARNING;
9621 }
9622
95cbbd2a 9623 return bgp_show (vty, bgp, afi, safi,
5a646650 9624 (exact ? bgp_show_type_community_exact :
b05a1c8b 9625 bgp_show_type_community), com, 0);
718e3744 9626}
9627
9628DEFUN (show_ip_bgp_community,
9629 show_ip_bgp_community_cmd,
9630 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9631 SHOW_STR
9632 IP_STR
9633 BGP_STR
9634 "Display routes matching the communities\n"
859d388e 9635 COMMUNITY_AANN_STR
718e3744 9636 "Do not send outside local AS (well-known community)\n"
9637 "Do not advertise to any peer (well-known community)\n"
9638 "Do not export to next AS (well-known community)\n")
9639{
95cbbd2a 9640 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 9641}
9642
9643ALIAS (show_ip_bgp_community,
9644 show_ip_bgp_community2_cmd,
9645 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9646 SHOW_STR
9647 IP_STR
9648 BGP_STR
9649 "Display routes matching the communities\n"
859d388e 9650 COMMUNITY_AANN_STR
718e3744 9651 "Do not send outside local AS (well-known community)\n"
9652 "Do not advertise to any peer (well-known community)\n"
9653 "Do not export to next AS (well-known community)\n"
859d388e 9654 COMMUNITY_AANN_STR
718e3744 9655 "Do not send outside local AS (well-known community)\n"
9656 "Do not advertise to any peer (well-known community)\n"
9657 "Do not export to next AS (well-known community)\n")
9658
9659ALIAS (show_ip_bgp_community,
9660 show_ip_bgp_community3_cmd,
9661 "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)",
9662 SHOW_STR
9663 IP_STR
9664 BGP_STR
9665 "Display routes matching the communities\n"
859d388e 9666 COMMUNITY_AANN_STR
718e3744 9667 "Do not send outside local AS (well-known community)\n"
9668 "Do not advertise to any peer (well-known community)\n"
9669 "Do not export to next AS (well-known community)\n"
859d388e 9670 COMMUNITY_AANN_STR
718e3744 9671 "Do not send outside local AS (well-known community)\n"
9672 "Do not advertise to any peer (well-known community)\n"
9673 "Do not export to next AS (well-known community)\n"
859d388e 9674 COMMUNITY_AANN_STR
718e3744 9675 "Do not send outside local AS (well-known community)\n"
9676 "Do not advertise to any peer (well-known community)\n"
9677 "Do not export to next AS (well-known community)\n")
9678
9679ALIAS (show_ip_bgp_community,
9680 show_ip_bgp_community4_cmd,
9681 "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)",
9682 SHOW_STR
9683 IP_STR
9684 BGP_STR
9685 "Display routes matching the communities\n"
859d388e 9686 COMMUNITY_AANN_STR
718e3744 9687 "Do not send outside local AS (well-known community)\n"
9688 "Do not advertise to any peer (well-known community)\n"
9689 "Do not export to next AS (well-known community)\n"
859d388e 9690 COMMUNITY_AANN_STR
718e3744 9691 "Do not send outside local AS (well-known community)\n"
9692 "Do not advertise to any peer (well-known community)\n"
9693 "Do not export to next AS (well-known community)\n"
859d388e 9694 COMMUNITY_AANN_STR
718e3744 9695 "Do not send outside local AS (well-known community)\n"
9696 "Do not advertise to any peer (well-known community)\n"
9697 "Do not export to next AS (well-known community)\n"
859d388e 9698 COMMUNITY_AANN_STR
718e3744 9699 "Do not send outside local AS (well-known community)\n"
9700 "Do not advertise to any peer (well-known community)\n"
9701 "Do not export to next AS (well-known community)\n")
9702
9703DEFUN (show_ip_bgp_ipv4_community,
9704 show_ip_bgp_ipv4_community_cmd,
9705 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9706 SHOW_STR
9707 IP_STR
9708 BGP_STR
9709 "Address family\n"
9710 "Address Family modifier\n"
9711 "Address Family modifier\n"
9712 "Display routes matching the communities\n"
859d388e 9713 COMMUNITY_AANN_STR
718e3744 9714 "Do not send outside local AS (well-known community)\n"
9715 "Do not advertise to any peer (well-known community)\n"
9716 "Do not export to next AS (well-known community)\n")
9717{
9718 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 9719 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
718e3744 9720
95cbbd2a 9721 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 9722}
9723
9724ALIAS (show_ip_bgp_ipv4_community,
9725 show_ip_bgp_ipv4_community2_cmd,
9726 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9727 SHOW_STR
9728 IP_STR
9729 BGP_STR
9730 "Address family\n"
9731 "Address Family modifier\n"
9732 "Address Family modifier\n"
9733 "Display routes matching the communities\n"
859d388e 9734 COMMUNITY_AANN_STR
718e3744 9735 "Do not send outside local AS (well-known community)\n"
9736 "Do not advertise to any peer (well-known community)\n"
9737 "Do not export to next AS (well-known community)\n"
859d388e 9738 COMMUNITY_AANN_STR
718e3744 9739 "Do not send outside local AS (well-known community)\n"
9740 "Do not advertise to any peer (well-known community)\n"
9741 "Do not export to next AS (well-known community)\n")
9742
9743ALIAS (show_ip_bgp_ipv4_community,
9744 show_ip_bgp_ipv4_community3_cmd,
9745 "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)",
9746 SHOW_STR
9747 IP_STR
9748 BGP_STR
9749 "Address family\n"
9750 "Address Family modifier\n"
9751 "Address Family modifier\n"
9752 "Display routes matching the communities\n"
859d388e 9753 COMMUNITY_AANN_STR
718e3744 9754 "Do not send outside local AS (well-known community)\n"
9755 "Do not advertise to any peer (well-known community)\n"
9756 "Do not export to next AS (well-known community)\n"
859d388e 9757 COMMUNITY_AANN_STR
718e3744 9758 "Do not send outside local AS (well-known community)\n"
9759 "Do not advertise to any peer (well-known community)\n"
9760 "Do not export to next AS (well-known community)\n"
859d388e 9761 COMMUNITY_AANN_STR
718e3744 9762 "Do not send outside local AS (well-known community)\n"
9763 "Do not advertise to any peer (well-known community)\n"
9764 "Do not export to next AS (well-known community)\n")
9765
9766ALIAS (show_ip_bgp_ipv4_community,
9767 show_ip_bgp_ipv4_community4_cmd,
9768 "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)",
9769 SHOW_STR
9770 IP_STR
9771 BGP_STR
9772 "Address family\n"
9773 "Address Family modifier\n"
9774 "Address Family modifier\n"
9775 "Display routes matching the communities\n"
859d388e 9776 COMMUNITY_AANN_STR
718e3744 9777 "Do not send outside local AS (well-known community)\n"
9778 "Do not advertise to any peer (well-known community)\n"
9779 "Do not export to next AS (well-known community)\n"
859d388e 9780 COMMUNITY_AANN_STR
718e3744 9781 "Do not send outside local AS (well-known community)\n"
9782 "Do not advertise to any peer (well-known community)\n"
9783 "Do not export to next AS (well-known community)\n"
859d388e 9784 COMMUNITY_AANN_STR
718e3744 9785 "Do not send outside local AS (well-known community)\n"
9786 "Do not advertise to any peer (well-known community)\n"
9787 "Do not export to next AS (well-known community)\n"
859d388e 9788 COMMUNITY_AANN_STR
718e3744 9789 "Do not send outside local AS (well-known community)\n"
9790 "Do not advertise to any peer (well-known community)\n"
9791 "Do not export to next AS (well-known community)\n")
9792
8386ac43 9793DEFUN (show_bgp_instance_afi_safi_community_all,
9794 show_bgp_instance_afi_safi_community_all_cmd,
8386ac43 9795 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community",
95cbbd2a
ML
9796 SHOW_STR
9797 BGP_STR
8386ac43 9798 BGP_INSTANCE_HELP_STR
95cbbd2a 9799 "Address family\n"
95cbbd2a 9800 "Address family\n"
95cbbd2a
ML
9801 "Address Family modifier\n"
9802 "Address Family modifier\n"
2b00515a 9803 "Display routes matching the communities\n")
95cbbd2a
ML
9804{
9805 int afi;
9806 int safi;
9807 struct bgp *bgp;
9808
9809 /* BGP structure lookup. */
6aeb9e78 9810 bgp = bgp_lookup_by_name (argv[1]);
95cbbd2a
ML
9811 if (bgp == NULL)
9812 {
6aeb9e78 9813 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
95cbbd2a
ML
9814 return CMD_WARNING;
9815 }
9816
6aeb9e78
DS
9817 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9818 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
b05a1c8b 9819 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
95cbbd2a
ML
9820}
9821
8386ac43 9822DEFUN (show_bgp_instance_afi_safi_community,
9823 show_bgp_instance_afi_safi_community_cmd,
8386ac43 9824 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
95cbbd2a
ML
9825 SHOW_STR
9826 BGP_STR
8386ac43 9827 BGP_INSTANCE_HELP_STR
95cbbd2a 9828 "Address family\n"
95cbbd2a 9829 "Address family\n"
95cbbd2a
ML
9830 "Address family modifier\n"
9831 "Address family modifier\n"
9832 "Display routes matching the communities\n"
859d388e 9833 COMMUNITY_AANN_STR
95cbbd2a
ML
9834 "Do not send outside local AS (well-known community)\n"
9835 "Do not advertise to any peer (well-known community)\n"
9836 "Do not export to next AS (well-known community)\n")
9837{
9838 int afi;
9839 int safi;
9840
6aeb9e78
DS
9841 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9842 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9843 return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi);
95cbbd2a
ML
9844}
9845
8386ac43 9846ALIAS (show_bgp_instance_afi_safi_community,
9847 show_bgp_instance_afi_safi_community2_cmd,
8386ac43 9848 "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
9849 SHOW_STR
9850 BGP_STR
8386ac43 9851 BGP_INSTANCE_HELP_STR
95cbbd2a 9852 "Address family\n"
95cbbd2a 9853 "Address family\n"
95cbbd2a
ML
9854 "Address family modifier\n"
9855 "Address family modifier\n"
9856 "Display routes matching the communities\n"
859d388e 9857 COMMUNITY_AANN_STR
95cbbd2a
ML
9858 "Do not send outside local AS (well-known community)\n"
9859 "Do not advertise to any peer (well-known community)\n"
9860 "Do not export to next AS (well-known community)\n"
859d388e 9861 COMMUNITY_AANN_STR
95cbbd2a
ML
9862 "Do not send outside local AS (well-known community)\n"
9863 "Do not advertise to any peer (well-known community)\n"
9864 "Do not export to next AS (well-known community)\n")
9865
8386ac43 9866ALIAS (show_bgp_instance_afi_safi_community,
9867 show_bgp_instance_afi_safi_community3_cmd,
8386ac43 9868 "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
9869 SHOW_STR
9870 BGP_STR
8386ac43 9871 BGP_INSTANCE_HELP_STR
95cbbd2a 9872 "Address family\n"
95cbbd2a 9873 "Address family\n"
95cbbd2a
ML
9874 "Address family modifier\n"
9875 "Address family modifier\n"
9876 "Display routes matching the communities\n"
859d388e 9877 COMMUNITY_AANN_STR
95cbbd2a
ML
9878 "Do not send outside local AS (well-known community)\n"
9879 "Do not advertise to any peer (well-known community)\n"
9880 "Do not export to next AS (well-known community)\n"
859d388e 9881 COMMUNITY_AANN_STR
95cbbd2a
ML
9882 "Do not send outside local AS (well-known community)\n"
9883 "Do not advertise to any peer (well-known community)\n"
9884 "Do not export to next AS (well-known community)\n"
859d388e 9885 COMMUNITY_AANN_STR
95cbbd2a
ML
9886 "Do not send outside local AS (well-known community)\n"
9887 "Do not advertise to any peer (well-known community)\n"
9888 "Do not export to next AS (well-known community)\n")
9889
8386ac43 9890ALIAS (show_bgp_instance_afi_safi_community,
9891 show_bgp_instance_afi_safi_community4_cmd,
8386ac43 9892 "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
9893 SHOW_STR
9894 BGP_STR
8386ac43 9895 BGP_INSTANCE_HELP_STR
95cbbd2a 9896 "Address family\n"
95cbbd2a 9897 "Address family\n"
95cbbd2a
ML
9898 "Address family modifier\n"
9899 "Address family modifier\n"
9900 "Display routes matching the communities\n"
859d388e 9901 COMMUNITY_AANN_STR
95cbbd2a
ML
9902 "Do not send outside local AS (well-known community)\n"
9903 "Do not advertise to any peer (well-known community)\n"
9904 "Do not export to next AS (well-known community)\n"
859d388e 9905 COMMUNITY_AANN_STR
95cbbd2a
ML
9906 "Do not send outside local AS (well-known community)\n"
9907 "Do not advertise to any peer (well-known community)\n"
9908 "Do not export to next AS (well-known community)\n"
859d388e 9909 COMMUNITY_AANN_STR
95cbbd2a
ML
9910 "Do not send outside local AS (well-known community)\n"
9911 "Do not advertise to any peer (well-known community)\n"
9912 "Do not export to next AS (well-known community)\n"
859d388e 9913 COMMUNITY_AANN_STR
95cbbd2a
ML
9914 "Do not send outside local AS (well-known community)\n"
9915 "Do not advertise to any peer (well-known community)\n"
9916 "Do not export to next AS (well-known community)\n")
9917
718e3744 9918DEFUN (show_ip_bgp_community_exact,
9919 show_ip_bgp_community_exact_cmd,
9920 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9921 SHOW_STR
9922 IP_STR
9923 BGP_STR
9924 "Display routes matching the communities\n"
859d388e 9925 COMMUNITY_AANN_STR
718e3744 9926 "Do not send outside local AS (well-known community)\n"
9927 "Do not advertise to any peer (well-known community)\n"
9928 "Do not export to next AS (well-known community)\n"
9929 "Exact match of the communities")
9930{
95cbbd2a 9931 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 9932}
9933
9934ALIAS (show_ip_bgp_community_exact,
9935 show_ip_bgp_community2_exact_cmd,
9936 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9937 SHOW_STR
9938 IP_STR
9939 BGP_STR
9940 "Display routes matching the communities\n"
859d388e 9941 COMMUNITY_AANN_STR
718e3744 9942 "Do not send outside local AS (well-known community)\n"
9943 "Do not advertise to any peer (well-known community)\n"
9944 "Do not export to next AS (well-known community)\n"
859d388e 9945 COMMUNITY_AANN_STR
718e3744 9946 "Do not send outside local AS (well-known community)\n"
9947 "Do not advertise to any peer (well-known community)\n"
9948 "Do not export to next AS (well-known community)\n"
9949 "Exact match of the communities")
9950
9951ALIAS (show_ip_bgp_community_exact,
9952 show_ip_bgp_community3_exact_cmd,
9953 "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",
9954 SHOW_STR
9955 IP_STR
9956 BGP_STR
9957 "Display routes matching the communities\n"
859d388e 9958 COMMUNITY_AANN_STR
718e3744 9959 "Do not send outside local AS (well-known community)\n"
9960 "Do not advertise to any peer (well-known community)\n"
9961 "Do not export to next AS (well-known community)\n"
859d388e 9962 COMMUNITY_AANN_STR
718e3744 9963 "Do not send outside local AS (well-known community)\n"
9964 "Do not advertise to any peer (well-known community)\n"
9965 "Do not export to next AS (well-known community)\n"
859d388e 9966 COMMUNITY_AANN_STR
718e3744 9967 "Do not send outside local AS (well-known community)\n"
9968 "Do not advertise to any peer (well-known community)\n"
9969 "Do not export to next AS (well-known community)\n"
9970 "Exact match of the communities")
9971
9972ALIAS (show_ip_bgp_community_exact,
9973 show_ip_bgp_community4_exact_cmd,
9974 "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",
9975 SHOW_STR
9976 IP_STR
9977 BGP_STR
9978 "Display routes matching the communities\n"
859d388e 9979 COMMUNITY_AANN_STR
718e3744 9980 "Do not send outside local AS (well-known community)\n"
9981 "Do not advertise to any peer (well-known community)\n"
9982 "Do not export to next AS (well-known community)\n"
859d388e 9983 COMMUNITY_AANN_STR
718e3744 9984 "Do not send outside local AS (well-known community)\n"
9985 "Do not advertise to any peer (well-known community)\n"
9986 "Do not export to next AS (well-known community)\n"
859d388e 9987 COMMUNITY_AANN_STR
718e3744 9988 "Do not send outside local AS (well-known community)\n"
9989 "Do not advertise to any peer (well-known community)\n"
9990 "Do not export to next AS (well-known community)\n"
859d388e 9991 COMMUNITY_AANN_STR
718e3744 9992 "Do not send outside local AS (well-known community)\n"
9993 "Do not advertise to any peer (well-known community)\n"
9994 "Do not export to next AS (well-known community)\n"
9995 "Exact match of the communities")
9996
9997DEFUN (show_ip_bgp_ipv4_community_exact,
9998 show_ip_bgp_ipv4_community_exact_cmd,
9999 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10000 SHOW_STR
10001 IP_STR
10002 BGP_STR
10003 "Address family\n"
10004 "Address Family modifier\n"
10005 "Address Family modifier\n"
10006 "Display routes matching the communities\n"
859d388e 10007 COMMUNITY_AANN_STR
718e3744 10008 "Do not send outside local AS (well-known community)\n"
10009 "Do not advertise to any peer (well-known community)\n"
10010 "Do not export to next AS (well-known community)\n"
10011 "Exact match of the communities")
10012{
10013 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 10014 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
718e3744 10015
95cbbd2a 10016 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 10017}
10018
10019ALIAS (show_ip_bgp_ipv4_community_exact,
10020 show_ip_bgp_ipv4_community2_exact_cmd,
10021 "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",
10022 SHOW_STR
10023 IP_STR
10024 BGP_STR
10025 "Address family\n"
10026 "Address Family modifier\n"
10027 "Address Family modifier\n"
10028 "Display routes matching the communities\n"
859d388e 10029 COMMUNITY_AANN_STR
718e3744 10030 "Do not send outside local AS (well-known community)\n"
10031 "Do not advertise to any peer (well-known community)\n"
10032 "Do not export to next AS (well-known community)\n"
859d388e 10033 COMMUNITY_AANN_STR
718e3744 10034 "Do not send outside local AS (well-known community)\n"
10035 "Do not advertise to any peer (well-known community)\n"
10036 "Do not export to next AS (well-known community)\n"
10037 "Exact match of the communities")
10038
10039ALIAS (show_ip_bgp_ipv4_community_exact,
10040 show_ip_bgp_ipv4_community3_exact_cmd,
10041 "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",
10042 SHOW_STR
10043 IP_STR
10044 BGP_STR
10045 "Address family\n"
10046 "Address Family modifier\n"
10047 "Address Family modifier\n"
10048 "Display routes matching the communities\n"
859d388e 10049 COMMUNITY_AANN_STR
718e3744 10050 "Do not send outside local AS (well-known community)\n"
10051 "Do not advertise to any peer (well-known community)\n"
10052 "Do not export to next AS (well-known community)\n"
859d388e 10053 COMMUNITY_AANN_STR
718e3744 10054 "Do not send outside local AS (well-known community)\n"
10055 "Do not advertise to any peer (well-known community)\n"
10056 "Do not export to next AS (well-known community)\n"
859d388e 10057 COMMUNITY_AANN_STR
718e3744 10058 "Do not send outside local AS (well-known community)\n"
10059 "Do not advertise to any peer (well-known community)\n"
10060 "Do not export to next AS (well-known community)\n"
10061 "Exact match of the communities")
10062
10063ALIAS (show_ip_bgp_ipv4_community_exact,
10064 show_ip_bgp_ipv4_community4_exact_cmd,
10065 "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",
10066 SHOW_STR
10067 IP_STR
10068 BGP_STR
10069 "Address family\n"
10070 "Address Family modifier\n"
10071 "Address Family modifier\n"
10072 "Display routes matching the communities\n"
859d388e 10073 COMMUNITY_AANN_STR
718e3744 10074 "Do not send outside local AS (well-known community)\n"
10075 "Do not advertise to any peer (well-known community)\n"
10076 "Do not export to next AS (well-known community)\n"
859d388e 10077 COMMUNITY_AANN_STR
718e3744 10078 "Do not send outside local AS (well-known community)\n"
10079 "Do not advertise to any peer (well-known community)\n"
10080 "Do not export to next AS (well-known community)\n"
859d388e 10081 COMMUNITY_AANN_STR
718e3744 10082 "Do not send outside local AS (well-known community)\n"
10083 "Do not advertise to any peer (well-known community)\n"
10084 "Do not export to next AS (well-known community)\n"
859d388e 10085 COMMUNITY_AANN_STR
718e3744 10086 "Do not send outside local AS (well-known community)\n"
10087 "Do not advertise to any peer (well-known community)\n"
10088 "Do not export to next AS (well-known community)\n"
10089 "Exact match of the communities")
10090
10091#ifdef HAVE_IPV6
10092DEFUN (show_bgp_community,
10093 show_bgp_community_cmd,
10094 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
10095 SHOW_STR
10096 BGP_STR
10097 "Display routes matching the communities\n"
859d388e 10098 COMMUNITY_AANN_STR
718e3744 10099 "Do not send outside local AS (well-known community)\n"
10100 "Do not advertise to any peer (well-known community)\n"
10101 "Do not export to next AS (well-known community)\n")
10102{
95cbbd2a 10103 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 10104}
10105
10106ALIAS (show_bgp_community,
10107 show_bgp_ipv6_community_cmd,
10108 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
10109 SHOW_STR
10110 BGP_STR
10111 "Address family\n"
10112 "Display routes matching the communities\n"
859d388e 10113 COMMUNITY_AANN_STR
718e3744 10114 "Do not send outside local AS (well-known community)\n"
10115 "Do not advertise to any peer (well-known community)\n"
10116 "Do not export to next AS (well-known community)\n")
10117
10118ALIAS (show_bgp_community,
10119 show_bgp_community2_cmd,
10120 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10121 SHOW_STR
10122 BGP_STR
10123 "Display routes matching the communities\n"
859d388e 10124 COMMUNITY_AANN_STR
718e3744 10125 "Do not send outside local AS (well-known community)\n"
10126 "Do not advertise to any peer (well-known community)\n"
10127 "Do not export to next AS (well-known community)\n"
859d388e 10128 COMMUNITY_AANN_STR
718e3744 10129 "Do not send outside local AS (well-known community)\n"
10130 "Do not advertise to any peer (well-known community)\n"
10131 "Do not export to next AS (well-known community)\n")
10132
10133ALIAS (show_bgp_community,
10134 show_bgp_ipv6_community2_cmd,
10135 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10136 SHOW_STR
10137 BGP_STR
10138 "Address family\n"
10139 "Display routes matching the communities\n"
859d388e 10140 COMMUNITY_AANN_STR
718e3744 10141 "Do not send outside local AS (well-known community)\n"
10142 "Do not advertise to any peer (well-known community)\n"
10143 "Do not export to next AS (well-known community)\n"
859d388e 10144 COMMUNITY_AANN_STR
718e3744 10145 "Do not send outside local AS (well-known community)\n"
10146 "Do not advertise to any peer (well-known community)\n"
10147 "Do not export to next AS (well-known community)\n")
10148
10149ALIAS (show_bgp_community,
10150 show_bgp_community3_cmd,
10151 "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)",
10152 SHOW_STR
10153 BGP_STR
10154 "Display routes matching the communities\n"
859d388e 10155 COMMUNITY_AANN_STR
718e3744 10156 "Do not send outside local AS (well-known community)\n"
10157 "Do not advertise to any peer (well-known community)\n"
10158 "Do not export to next AS (well-known community)\n"
859d388e 10159 COMMUNITY_AANN_STR
718e3744 10160 "Do not send outside local AS (well-known community)\n"
10161 "Do not advertise to any peer (well-known community)\n"
10162 "Do not export to next AS (well-known community)\n"
859d388e 10163 COMMUNITY_AANN_STR
718e3744 10164 "Do not send outside local AS (well-known community)\n"
10165 "Do not advertise to any peer (well-known community)\n"
10166 "Do not export to next AS (well-known community)\n")
10167
10168ALIAS (show_bgp_community,
10169 show_bgp_ipv6_community3_cmd,
10170 "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)",
10171 SHOW_STR
10172 BGP_STR
10173 "Address family\n"
10174 "Display routes matching the communities\n"
859d388e 10175 COMMUNITY_AANN_STR
718e3744 10176 "Do not send outside local AS (well-known community)\n"
10177 "Do not advertise to any peer (well-known community)\n"
10178 "Do not export to next AS (well-known community)\n"
859d388e 10179 COMMUNITY_AANN_STR
718e3744 10180 "Do not send outside local AS (well-known community)\n"
10181 "Do not advertise to any peer (well-known community)\n"
10182 "Do not export to next AS (well-known community)\n"
859d388e 10183 COMMUNITY_AANN_STR
718e3744 10184 "Do not send outside local AS (well-known community)\n"
10185 "Do not advertise to any peer (well-known community)\n"
10186 "Do not export to next AS (well-known community)\n")
10187
10188ALIAS (show_bgp_community,
10189 show_bgp_community4_cmd,
10190 "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)",
10191 SHOW_STR
10192 BGP_STR
10193 "Display routes matching the communities\n"
859d388e 10194 COMMUNITY_AANN_STR
718e3744 10195 "Do not send outside local AS (well-known community)\n"
10196 "Do not advertise to any peer (well-known community)\n"
10197 "Do not export to next AS (well-known community)\n"
859d388e 10198 COMMUNITY_AANN_STR
718e3744 10199 "Do not send outside local AS (well-known community)\n"
10200 "Do not advertise to any peer (well-known community)\n"
10201 "Do not export to next AS (well-known community)\n"
859d388e 10202 COMMUNITY_AANN_STR
718e3744 10203 "Do not send outside local AS (well-known community)\n"
10204 "Do not advertise to any peer (well-known community)\n"
10205 "Do not export to next AS (well-known community)\n"
859d388e 10206 COMMUNITY_AANN_STR
718e3744 10207 "Do not send outside local AS (well-known community)\n"
10208 "Do not advertise to any peer (well-known community)\n"
10209 "Do not export to next AS (well-known community)\n")
10210
10211ALIAS (show_bgp_community,
10212 show_bgp_ipv6_community4_cmd,
10213 "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)",
10214 SHOW_STR
10215 BGP_STR
10216 "Address family\n"
10217 "Display routes matching the communities\n"
859d388e 10218 COMMUNITY_AANN_STR
718e3744 10219 "Do not send outside local AS (well-known community)\n"
10220 "Do not advertise to any peer (well-known community)\n"
10221 "Do not export to next AS (well-known community)\n"
859d388e 10222 COMMUNITY_AANN_STR
718e3744 10223 "Do not send outside local AS (well-known community)\n"
10224 "Do not advertise to any peer (well-known community)\n"
10225 "Do not export to next AS (well-known community)\n"
859d388e 10226 COMMUNITY_AANN_STR
718e3744 10227 "Do not send outside local AS (well-known community)\n"
10228 "Do not advertise to any peer (well-known community)\n"
10229 "Do not export to next AS (well-known community)\n"
859d388e 10230 COMMUNITY_AANN_STR
718e3744 10231 "Do not send outside local AS (well-known community)\n"
10232 "Do not advertise to any peer (well-known community)\n"
10233 "Do not export to next AS (well-known community)\n")
10234
10235/* old command */
10236DEFUN (show_ipv6_bgp_community,
10237 show_ipv6_bgp_community_cmd,
10238 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
10239 SHOW_STR
10240 IPV6_STR
10241 BGP_STR
10242 "Display routes matching the communities\n"
859d388e 10243 COMMUNITY_AANN_STR
718e3744 10244 "Do not send outside local AS (well-known community)\n"
10245 "Do not advertise to any peer (well-known community)\n"
10246 "Do not export to next AS (well-known community)\n")
10247{
47e9b292 10248 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 10249 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 10250}
10251
10252/* old command */
10253ALIAS (show_ipv6_bgp_community,
10254 show_ipv6_bgp_community2_cmd,
10255 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10256 SHOW_STR
10257 IPV6_STR
10258 BGP_STR
10259 "Display routes matching the communities\n"
859d388e 10260 COMMUNITY_AANN_STR
718e3744 10261 "Do not send outside local AS (well-known community)\n"
10262 "Do not advertise to any peer (well-known community)\n"
10263 "Do not export to next AS (well-known community)\n"
859d388e 10264 COMMUNITY_AANN_STR
718e3744 10265 "Do not send outside local AS (well-known community)\n"
10266 "Do not advertise to any peer (well-known community)\n"
10267 "Do not export to next AS (well-known community)\n")
10268
10269/* old command */
10270ALIAS (show_ipv6_bgp_community,
10271 show_ipv6_bgp_community3_cmd,
10272 "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)",
10273 SHOW_STR
10274 IPV6_STR
10275 BGP_STR
10276 "Display routes matching the communities\n"
859d388e 10277 COMMUNITY_AANN_STR
718e3744 10278 "Do not send outside local AS (well-known community)\n"
10279 "Do not advertise to any peer (well-known community)\n"
10280 "Do not export to next AS (well-known community)\n"
859d388e 10281 COMMUNITY_AANN_STR
718e3744 10282 "Do not send outside local AS (well-known community)\n"
10283 "Do not advertise to any peer (well-known community)\n"
10284 "Do not export to next AS (well-known community)\n"
859d388e 10285 COMMUNITY_AANN_STR
718e3744 10286 "Do not send outside local AS (well-known community)\n"
10287 "Do not advertise to any peer (well-known community)\n"
10288 "Do not export to next AS (well-known community)\n")
10289
10290/* old command */
10291ALIAS (show_ipv6_bgp_community,
10292 show_ipv6_bgp_community4_cmd,
10293 "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)",
10294 SHOW_STR
10295 IPV6_STR
10296 BGP_STR
10297 "Display routes matching the communities\n"
859d388e 10298 COMMUNITY_AANN_STR
718e3744 10299 "Do not send outside local AS (well-known community)\n"
10300 "Do not advertise to any peer (well-known community)\n"
10301 "Do not export to next AS (well-known community)\n"
859d388e 10302 COMMUNITY_AANN_STR
718e3744 10303 "Do not send outside local AS (well-known community)\n"
10304 "Do not advertise to any peer (well-known community)\n"
10305 "Do not export to next AS (well-known community)\n"
859d388e 10306 COMMUNITY_AANN_STR
718e3744 10307 "Do not send outside local AS (well-known community)\n"
10308 "Do not advertise to any peer (well-known community)\n"
10309 "Do not export to next AS (well-known community)\n"
859d388e 10310 COMMUNITY_AANN_STR
718e3744 10311 "Do not send outside local AS (well-known community)\n"
10312 "Do not advertise to any peer (well-known community)\n"
10313 "Do not export to next AS (well-known community)\n")
10314
10315DEFUN (show_bgp_community_exact,
10316 show_bgp_community_exact_cmd,
10317 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10318 SHOW_STR
10319 BGP_STR
10320 "Display routes matching the communities\n"
859d388e 10321 COMMUNITY_AANN_STR
718e3744 10322 "Do not send outside local AS (well-known community)\n"
10323 "Do not advertise to any peer (well-known community)\n"
10324 "Do not export to next AS (well-known community)\n"
10325 "Exact match of the communities")
10326{
95cbbd2a 10327 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 10328}
10329
10330ALIAS (show_bgp_community_exact,
10331 show_bgp_ipv6_community_exact_cmd,
10332 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10333 SHOW_STR
10334 BGP_STR
10335 "Address family\n"
10336 "Display routes matching the communities\n"
859d388e 10337 COMMUNITY_AANN_STR
718e3744 10338 "Do not send outside local AS (well-known community)\n"
10339 "Do not advertise to any peer (well-known community)\n"
10340 "Do not export to next AS (well-known community)\n"
10341 "Exact match of the communities")
10342
10343ALIAS (show_bgp_community_exact,
10344 show_bgp_community2_exact_cmd,
10345 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10346 SHOW_STR
10347 BGP_STR
10348 "Display routes matching the communities\n"
859d388e 10349 COMMUNITY_AANN_STR
718e3744 10350 "Do not send outside local AS (well-known community)\n"
10351 "Do not advertise to any peer (well-known community)\n"
10352 "Do not export to next AS (well-known community)\n"
859d388e 10353 COMMUNITY_AANN_STR
718e3744 10354 "Do not send outside local AS (well-known community)\n"
10355 "Do not advertise to any peer (well-known community)\n"
10356 "Do not export to next AS (well-known community)\n"
10357 "Exact match of the communities")
10358
10359ALIAS (show_bgp_community_exact,
10360 show_bgp_ipv6_community2_exact_cmd,
10361 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10362 SHOW_STR
10363 BGP_STR
10364 "Address family\n"
10365 "Display routes matching the communities\n"
859d388e 10366 COMMUNITY_AANN_STR
718e3744 10367 "Do not send outside local AS (well-known community)\n"
10368 "Do not advertise to any peer (well-known community)\n"
10369 "Do not export to next AS (well-known community)\n"
859d388e 10370 COMMUNITY_AANN_STR
718e3744 10371 "Do not send outside local AS (well-known community)\n"
10372 "Do not advertise to any peer (well-known community)\n"
10373 "Do not export to next AS (well-known community)\n"
10374 "Exact match of the communities")
10375
10376ALIAS (show_bgp_community_exact,
10377 show_bgp_community3_exact_cmd,
10378 "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",
10379 SHOW_STR
10380 BGP_STR
10381 "Display routes matching the communities\n"
859d388e 10382 COMMUNITY_AANN_STR
718e3744 10383 "Do not send outside local AS (well-known community)\n"
10384 "Do not advertise to any peer (well-known community)\n"
10385 "Do not export to next AS (well-known community)\n"
859d388e 10386 COMMUNITY_AANN_STR
718e3744 10387 "Do not send outside local AS (well-known community)\n"
10388 "Do not advertise to any peer (well-known community)\n"
10389 "Do not export to next AS (well-known community)\n"
859d388e 10390 COMMUNITY_AANN_STR
718e3744 10391 "Do not send outside local AS (well-known community)\n"
10392 "Do not advertise to any peer (well-known community)\n"
10393 "Do not export to next AS (well-known community)\n"
10394 "Exact match of the communities")
10395
10396ALIAS (show_bgp_community_exact,
10397 show_bgp_ipv6_community3_exact_cmd,
10398 "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",
10399 SHOW_STR
10400 BGP_STR
10401 "Address family\n"
10402 "Display routes matching the communities\n"
859d388e 10403 COMMUNITY_AANN_STR
718e3744 10404 "Do not send outside local AS (well-known community)\n"
10405 "Do not advertise to any peer (well-known community)\n"
10406 "Do not export to next AS (well-known community)\n"
859d388e 10407 COMMUNITY_AANN_STR
718e3744 10408 "Do not send outside local AS (well-known community)\n"
10409 "Do not advertise to any peer (well-known community)\n"
10410 "Do not export to next AS (well-known community)\n"
859d388e 10411 COMMUNITY_AANN_STR
718e3744 10412 "Do not send outside local AS (well-known community)\n"
10413 "Do not advertise to any peer (well-known community)\n"
10414 "Do not export to next AS (well-known community)\n"
10415 "Exact match of the communities")
10416
10417ALIAS (show_bgp_community_exact,
10418 show_bgp_community4_exact_cmd,
10419 "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",
10420 SHOW_STR
10421 BGP_STR
10422 "Display routes matching the communities\n"
859d388e 10423 COMMUNITY_AANN_STR
718e3744 10424 "Do not send outside local AS (well-known community)\n"
10425 "Do not advertise to any peer (well-known community)\n"
10426 "Do not export to next AS (well-known community)\n"
859d388e 10427 COMMUNITY_AANN_STR
718e3744 10428 "Do not send outside local AS (well-known community)\n"
10429 "Do not advertise to any peer (well-known community)\n"
10430 "Do not export to next AS (well-known community)\n"
859d388e 10431 COMMUNITY_AANN_STR
718e3744 10432 "Do not send outside local AS (well-known community)\n"
10433 "Do not advertise to any peer (well-known community)\n"
10434 "Do not export to next AS (well-known community)\n"
859d388e 10435 COMMUNITY_AANN_STR
718e3744 10436 "Do not send outside local AS (well-known community)\n"
10437 "Do not advertise to any peer (well-known community)\n"
10438 "Do not export to next AS (well-known community)\n"
10439 "Exact match of the communities")
10440
10441ALIAS (show_bgp_community_exact,
10442 show_bgp_ipv6_community4_exact_cmd,
10443 "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",
10444 SHOW_STR
10445 BGP_STR
10446 "Address family\n"
10447 "Display routes matching the communities\n"
859d388e 10448 COMMUNITY_AANN_STR
718e3744 10449 "Do not send outside local AS (well-known community)\n"
10450 "Do not advertise to any peer (well-known community)\n"
10451 "Do not export to next AS (well-known community)\n"
859d388e 10452 COMMUNITY_AANN_STR
718e3744 10453 "Do not send outside local AS (well-known community)\n"
10454 "Do not advertise to any peer (well-known community)\n"
10455 "Do not export to next AS (well-known community)\n"
859d388e 10456 COMMUNITY_AANN_STR
718e3744 10457 "Do not send outside local AS (well-known community)\n"
10458 "Do not advertise to any peer (well-known community)\n"
10459 "Do not export to next AS (well-known community)\n"
859d388e 10460 COMMUNITY_AANN_STR
718e3744 10461 "Do not send outside local AS (well-known community)\n"
10462 "Do not advertise to any peer (well-known community)\n"
10463 "Do not export to next AS (well-known community)\n"
10464 "Exact match of the communities")
10465
10466/* old command */
10467DEFUN (show_ipv6_bgp_community_exact,
10468 show_ipv6_bgp_community_exact_cmd,
10469 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10470 SHOW_STR
10471 IPV6_STR
10472 BGP_STR
10473 "Display routes matching the communities\n"
859d388e 10474 COMMUNITY_AANN_STR
718e3744 10475 "Do not send outside local AS (well-known community)\n"
10476 "Do not advertise to any peer (well-known community)\n"
10477 "Do not export to next AS (well-known community)\n"
10478 "Exact match of the communities")
10479{
47e9b292 10480 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 10481 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 10482}
10483
10484/* old command */
10485ALIAS (show_ipv6_bgp_community_exact,
10486 show_ipv6_bgp_community2_exact_cmd,
10487 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10488 SHOW_STR
10489 IPV6_STR
10490 BGP_STR
10491 "Display routes matching the communities\n"
859d388e 10492 COMMUNITY_AANN_STR
718e3744 10493 "Do not send outside local AS (well-known community)\n"
10494 "Do not advertise to any peer (well-known community)\n"
10495 "Do not export to next AS (well-known community)\n"
859d388e 10496 COMMUNITY_AANN_STR
718e3744 10497 "Do not send outside local AS (well-known community)\n"
10498 "Do not advertise to any peer (well-known community)\n"
10499 "Do not export to next AS (well-known community)\n"
10500 "Exact match of the communities")
10501
10502/* old command */
10503ALIAS (show_ipv6_bgp_community_exact,
10504 show_ipv6_bgp_community3_exact_cmd,
10505 "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",
10506 SHOW_STR
10507 IPV6_STR
10508 BGP_STR
10509 "Display routes matching the communities\n"
859d388e 10510 COMMUNITY_AANN_STR
718e3744 10511 "Do not send outside local AS (well-known community)\n"
10512 "Do not advertise to any peer (well-known community)\n"
10513 "Do not export to next AS (well-known community)\n"
859d388e 10514 COMMUNITY_AANN_STR
718e3744 10515 "Do not send outside local AS (well-known community)\n"
10516 "Do not advertise to any peer (well-known community)\n"
10517 "Do not export to next AS (well-known community)\n"
859d388e 10518 COMMUNITY_AANN_STR
718e3744 10519 "Do not send outside local AS (well-known community)\n"
10520 "Do not advertise to any peer (well-known community)\n"
10521 "Do not export to next AS (well-known community)\n"
10522 "Exact match of the communities")
10523
10524/* old command */
10525ALIAS (show_ipv6_bgp_community_exact,
10526 show_ipv6_bgp_community4_exact_cmd,
10527 "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",
10528 SHOW_STR
10529 IPV6_STR
10530 BGP_STR
10531 "Display routes matching the communities\n"
859d388e 10532 COMMUNITY_AANN_STR
718e3744 10533 "Do not send outside local AS (well-known community)\n"
10534 "Do not advertise to any peer (well-known community)\n"
10535 "Do not export to next AS (well-known community)\n"
859d388e 10536 COMMUNITY_AANN_STR
718e3744 10537 "Do not send outside local AS (well-known community)\n"
10538 "Do not advertise to any peer (well-known community)\n"
10539 "Do not export to next AS (well-known community)\n"
859d388e 10540 COMMUNITY_AANN_STR
718e3744 10541 "Do not send outside local AS (well-known community)\n"
10542 "Do not advertise to any peer (well-known community)\n"
10543 "Do not export to next AS (well-known community)\n"
859d388e 10544 COMMUNITY_AANN_STR
718e3744 10545 "Do not send outside local AS (well-known community)\n"
10546 "Do not advertise to any peer (well-known community)\n"
10547 "Do not export to next AS (well-known community)\n"
10548 "Exact match of the communities")
10549
10550/* old command */
10551DEFUN (show_ipv6_mbgp_community,
10552 show_ipv6_mbgp_community_cmd,
10553 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10554 SHOW_STR
10555 IPV6_STR
10556 MBGP_STR
10557 "Display routes matching the communities\n"
859d388e 10558 COMMUNITY_AANN_STR
718e3744 10559 "Do not send outside local AS (well-known community)\n"
10560 "Do not advertise to any peer (well-known community)\n"
10561 "Do not export to next AS (well-known community)\n")
10562{
47e9b292 10563 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 10564 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
718e3744 10565}
10566
10567/* old command */
10568ALIAS (show_ipv6_mbgp_community,
10569 show_ipv6_mbgp_community2_cmd,
10570 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10571 SHOW_STR
10572 IPV6_STR
10573 MBGP_STR
10574 "Display routes matching the communities\n"
859d388e 10575 COMMUNITY_AANN_STR
718e3744 10576 "Do not send outside local AS (well-known community)\n"
10577 "Do not advertise to any peer (well-known community)\n"
10578 "Do not export to next AS (well-known community)\n"
859d388e 10579 COMMUNITY_AANN_STR
718e3744 10580 "Do not send outside local AS (well-known community)\n"
10581 "Do not advertise to any peer (well-known community)\n"
10582 "Do not export to next AS (well-known community)\n")
10583
10584/* old command */
10585ALIAS (show_ipv6_mbgp_community,
10586 show_ipv6_mbgp_community3_cmd,
10587 "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)",
10588 SHOW_STR
10589 IPV6_STR
10590 MBGP_STR
10591 "Display routes matching the communities\n"
859d388e 10592 COMMUNITY_AANN_STR
718e3744 10593 "Do not send outside local AS (well-known community)\n"
10594 "Do not advertise to any peer (well-known community)\n"
10595 "Do not export to next AS (well-known community)\n"
859d388e 10596 COMMUNITY_AANN_STR
718e3744 10597 "Do not send outside local AS (well-known community)\n"
10598 "Do not advertise to any peer (well-known community)\n"
10599 "Do not export to next AS (well-known community)\n"
859d388e 10600 COMMUNITY_AANN_STR
718e3744 10601 "Do not send outside local AS (well-known community)\n"
10602 "Do not advertise to any peer (well-known community)\n"
10603 "Do not export to next AS (well-known community)\n")
10604
10605/* old command */
10606ALIAS (show_ipv6_mbgp_community,
10607 show_ipv6_mbgp_community4_cmd,
10608 "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)",
10609 SHOW_STR
10610 IPV6_STR
10611 MBGP_STR
10612 "Display routes matching the communities\n"
859d388e 10613 COMMUNITY_AANN_STR
718e3744 10614 "Do not send outside local AS (well-known community)\n"
10615 "Do not advertise to any peer (well-known community)\n"
10616 "Do not export to next AS (well-known community)\n"
859d388e 10617 COMMUNITY_AANN_STR
718e3744 10618 "Do not send outside local AS (well-known community)\n"
10619 "Do not advertise to any peer (well-known community)\n"
10620 "Do not export to next AS (well-known community)\n"
859d388e 10621 COMMUNITY_AANN_STR
718e3744 10622 "Do not send outside local AS (well-known community)\n"
10623 "Do not advertise to any peer (well-known community)\n"
10624 "Do not export to next AS (well-known community)\n"
859d388e 10625 COMMUNITY_AANN_STR
718e3744 10626 "Do not send outside local AS (well-known community)\n"
10627 "Do not advertise to any peer (well-known community)\n"
10628 "Do not export to next AS (well-known community)\n")
10629
10630/* old command */
10631DEFUN (show_ipv6_mbgp_community_exact,
10632 show_ipv6_mbgp_community_exact_cmd,
10633 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10634 SHOW_STR
10635 IPV6_STR
10636 MBGP_STR
10637 "Display routes matching the communities\n"
859d388e 10638 COMMUNITY_AANN_STR
718e3744 10639 "Do not send outside local AS (well-known community)\n"
10640 "Do not advertise to any peer (well-known community)\n"
10641 "Do not export to next AS (well-known community)\n"
10642 "Exact match of the communities")
10643{
47e9b292 10644 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 10645 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
718e3744 10646}
10647
10648/* old command */
10649ALIAS (show_ipv6_mbgp_community_exact,
10650 show_ipv6_mbgp_community2_exact_cmd,
10651 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10652 SHOW_STR
10653 IPV6_STR
10654 MBGP_STR
10655 "Display routes matching the communities\n"
859d388e 10656 COMMUNITY_AANN_STR
718e3744 10657 "Do not send outside local AS (well-known community)\n"
10658 "Do not advertise to any peer (well-known community)\n"
10659 "Do not export to next AS (well-known community)\n"
859d388e 10660 COMMUNITY_AANN_STR
718e3744 10661 "Do not send outside local AS (well-known community)\n"
10662 "Do not advertise to any peer (well-known community)\n"
10663 "Do not export to next AS (well-known community)\n"
10664 "Exact match of the communities")
10665
10666/* old command */
10667ALIAS (show_ipv6_mbgp_community_exact,
10668 show_ipv6_mbgp_community3_exact_cmd,
10669 "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",
10670 SHOW_STR
10671 IPV6_STR
10672 MBGP_STR
10673 "Display routes matching the communities\n"
859d388e 10674 COMMUNITY_AANN_STR
718e3744 10675 "Do not send outside local AS (well-known community)\n"
10676 "Do not advertise to any peer (well-known community)\n"
10677 "Do not export to next AS (well-known community)\n"
859d388e 10678 COMMUNITY_AANN_STR
718e3744 10679 "Do not send outside local AS (well-known community)\n"
10680 "Do not advertise to any peer (well-known community)\n"
10681 "Do not export to next AS (well-known community)\n"
859d388e 10682 COMMUNITY_AANN_STR
718e3744 10683 "Do not send outside local AS (well-known community)\n"
10684 "Do not advertise to any peer (well-known community)\n"
10685 "Do not export to next AS (well-known community)\n"
10686 "Exact match of the communities")
10687
10688/* old command */
10689ALIAS (show_ipv6_mbgp_community_exact,
10690 show_ipv6_mbgp_community4_exact_cmd,
10691 "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",
10692 SHOW_STR
10693 IPV6_STR
10694 MBGP_STR
10695 "Display routes matching the communities\n"
859d388e 10696 COMMUNITY_AANN_STR
718e3744 10697 "Do not send outside local AS (well-known community)\n"
10698 "Do not advertise to any peer (well-known community)\n"
10699 "Do not export to next AS (well-known community)\n"
859d388e 10700 COMMUNITY_AANN_STR
718e3744 10701 "Do not send outside local AS (well-known community)\n"
10702 "Do not advertise to any peer (well-known community)\n"
10703 "Do not export to next AS (well-known community)\n"
859d388e 10704 COMMUNITY_AANN_STR
718e3744 10705 "Do not send outside local AS (well-known community)\n"
10706 "Do not advertise to any peer (well-known community)\n"
10707 "Do not export to next AS (well-known community)\n"
859d388e 10708 COMMUNITY_AANN_STR
718e3744 10709 "Do not send outside local AS (well-known community)\n"
10710 "Do not advertise to any peer (well-known community)\n"
10711 "Do not export to next AS (well-known community)\n"
10712 "Exact match of the communities")
10713#endif /* HAVE_IPV6 */
6b0655a2 10714
94f2b392 10715static int
50ef26d4 10716bgp_show_community_list (struct vty *vty, const char *name,
10717 const char *com, int exact,
4c9641ba 10718 afi_t afi, safi_t safi)
718e3744 10719{
10720 struct community_list *list;
50ef26d4 10721 struct bgp *bgp = NULL;
10722
10723 if (name && !(bgp = bgp_lookup_by_name(name)))
10724 {
10725 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
10726 return CMD_WARNING;
10727 }
718e3744 10728
fee6e4e4 10729 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
718e3744 10730 if (list == NULL)
10731 {
10732 vty_out (vty, "%% %s is not a valid community-list name%s", com,
10733 VTY_NEWLINE);
10734 return CMD_WARNING;
10735 }
10736
50ef26d4 10737 return bgp_show (vty, bgp, afi, safi,
5a646650 10738 (exact ? bgp_show_type_community_list_exact :
b05a1c8b 10739 bgp_show_type_community_list), list, 0);
718e3744 10740}
10741
10742DEFUN (show_ip_bgp_community_list,
10743 show_ip_bgp_community_list_cmd,
fee6e4e4 10744 "show ip bgp community-list (<1-500>|WORD)",
718e3744 10745 SHOW_STR
10746 IP_STR
10747 BGP_STR
10748 "Display routes matching the community-list\n"
fee6e4e4 10749 "community-list number\n"
718e3744 10750 "community-list name\n")
10751{
50ef26d4 10752 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP, SAFI_UNICAST);
10753}
10754
8386ac43 10755DEFUN (show_ip_bgp_instance_community_list,
10756 show_ip_bgp_instance_community_list_cmd,
10757 "show ip bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
50ef26d4 10758 SHOW_STR
10759 IP_STR
10760 BGP_STR
8386ac43 10761 BGP_INSTANCE_HELP_STR
50ef26d4 10762 "Display routes matching the community-list\n"
10763 "community-list number\n"
10764 "community-list name\n")
10765{
10766 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP, SAFI_UNICAST);
718e3744 10767}
10768
10769DEFUN (show_ip_bgp_ipv4_community_list,
10770 show_ip_bgp_ipv4_community_list_cmd,
fee6e4e4 10771 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
718e3744 10772 SHOW_STR
10773 IP_STR
10774 BGP_STR
10775 "Address family\n"
10776 "Address Family modifier\n"
10777 "Address Family modifier\n"
10778 "Display routes matching the community-list\n"
fee6e4e4 10779 "community-list number\n"
718e3744 10780 "community-list name\n")
10781{
10782 if (strncmp (argv[0], "m", 1) == 0)
50ef26d4 10783 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_MULTICAST);
718e3744 10784
50ef26d4 10785 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_UNICAST);
718e3744 10786}
10787
10788DEFUN (show_ip_bgp_community_list_exact,
10789 show_ip_bgp_community_list_exact_cmd,
fee6e4e4 10790 "show ip bgp community-list (<1-500>|WORD) exact-match",
718e3744 10791 SHOW_STR
10792 IP_STR
10793 BGP_STR
10794 "Display routes matching the community-list\n"
fee6e4e4 10795 "community-list number\n"
718e3744 10796 "community-list name\n"
10797 "Exact match of the communities\n")
10798{
50ef26d4 10799 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP, SAFI_UNICAST);
718e3744 10800}
10801
10802DEFUN (show_ip_bgp_ipv4_community_list_exact,
10803 show_ip_bgp_ipv4_community_list_exact_cmd,
fee6e4e4 10804 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
718e3744 10805 SHOW_STR
10806 IP_STR
10807 BGP_STR
10808 "Address family\n"
10809 "Address Family modifier\n"
10810 "Address Family modifier\n"
10811 "Display routes matching the community-list\n"
fee6e4e4 10812 "community-list number\n"
718e3744 10813 "community-list name\n"
10814 "Exact match of the communities\n")
10815{
10816 if (strncmp (argv[0], "m", 1) == 0)
50ef26d4 10817 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_MULTICAST);
718e3744 10818
50ef26d4 10819 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_UNICAST);
718e3744 10820}
10821
10822#ifdef HAVE_IPV6
10823DEFUN (show_bgp_community_list,
10824 show_bgp_community_list_cmd,
fee6e4e4 10825 "show bgp community-list (<1-500>|WORD)",
718e3744 10826 SHOW_STR
10827 BGP_STR
10828 "Display routes matching the community-list\n"
fee6e4e4 10829 "community-list number\n"
718e3744 10830 "community-list name\n")
10831{
50ef26d4 10832 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
718e3744 10833}
10834
10835ALIAS (show_bgp_community_list,
10836 show_bgp_ipv6_community_list_cmd,
fee6e4e4 10837 "show bgp ipv6 community-list (<1-500>|WORD)",
718e3744 10838 SHOW_STR
10839 BGP_STR
10840 "Address family\n"
10841 "Display routes matching the community-list\n"
fee6e4e4 10842 "community-list number\n"
e8e1946e 10843 "community-list name\n")
718e3744 10844
10845/* old command */
10846DEFUN (show_ipv6_bgp_community_list,
10847 show_ipv6_bgp_community_list_cmd,
10848 "show ipv6 bgp community-list WORD",
10849 SHOW_STR
10850 IPV6_STR
10851 BGP_STR
10852 "Display routes matching the community-list\n"
10853 "community-list name\n")
10854{
47e9b292 10855 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 10856 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
718e3744 10857}
10858
10859/* old command */
10860DEFUN (show_ipv6_mbgp_community_list,
10861 show_ipv6_mbgp_community_list_cmd,
10862 "show ipv6 mbgp community-list WORD",
10863 SHOW_STR
10864 IPV6_STR
10865 MBGP_STR
10866 "Display routes matching the community-list\n"
10867 "community-list name\n")
10868{
47e9b292 10869 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 10870 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
718e3744 10871}
10872
10873DEFUN (show_bgp_community_list_exact,
10874 show_bgp_community_list_exact_cmd,
fee6e4e4 10875 "show bgp community-list (<1-500>|WORD) exact-match",
718e3744 10876 SHOW_STR
10877 BGP_STR
10878 "Display routes matching the community-list\n"
fee6e4e4 10879 "community-list number\n"
718e3744 10880 "community-list name\n"
10881 "Exact match of the communities\n")
10882{
50ef26d4 10883 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
718e3744 10884}
10885
10886ALIAS (show_bgp_community_list_exact,
10887 show_bgp_ipv6_community_list_exact_cmd,
fee6e4e4 10888 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
718e3744 10889 SHOW_STR
10890 BGP_STR
10891 "Address family\n"
10892 "Display routes matching the community-list\n"
fee6e4e4 10893 "community-list number\n"
718e3744 10894 "community-list name\n"
10895 "Exact match of the communities\n")
10896
10897/* old command */
10898DEFUN (show_ipv6_bgp_community_list_exact,
10899 show_ipv6_bgp_community_list_exact_cmd,
10900 "show ipv6 bgp community-list WORD exact-match",
10901 SHOW_STR
10902 IPV6_STR
10903 BGP_STR
10904 "Display routes matching the community-list\n"
10905 "community-list name\n"
10906 "Exact match of the communities\n")
10907{
47e9b292 10908 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 10909 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
718e3744 10910}
10911
10912/* old command */
10913DEFUN (show_ipv6_mbgp_community_list_exact,
10914 show_ipv6_mbgp_community_list_exact_cmd,
10915 "show ipv6 mbgp community-list WORD exact-match",
10916 SHOW_STR
10917 IPV6_STR
10918 MBGP_STR
10919 "Display routes matching the community-list\n"
10920 "community-list name\n"
10921 "Exact match of the communities\n")
10922{
47e9b292 10923 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 10924 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
718e3744 10925}
10926#endif /* HAVE_IPV6 */
6b0655a2 10927
94f2b392 10928static int
50ef26d4 10929bgp_show_prefix_longer (struct vty *vty, const char *name,
10930 const char *prefix, afi_t afi,
718e3744 10931 safi_t safi, enum bgp_show_type type)
10932{
10933 int ret;
10934 struct prefix *p;
50ef26d4 10935 struct bgp *bgp = NULL;
10936
10937 if (name && !(bgp = bgp_lookup_by_name(name)))
10938 {
10939 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
10940 return CMD_WARNING;
10941 }
718e3744 10942
10943 p = prefix_new();
10944
10945 ret = str2prefix (prefix, p);
10946 if (! ret)
10947 {
10948 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
10949 return CMD_WARNING;
10950 }
10951
50ef26d4 10952 ret = bgp_show (vty, bgp, afi, safi, type, p, 0);
5a646650 10953 prefix_free(p);
10954 return ret;
718e3744 10955}
10956
10957DEFUN (show_ip_bgp_prefix_longer,
10958 show_ip_bgp_prefix_longer_cmd,
10959 "show ip bgp A.B.C.D/M longer-prefixes",
10960 SHOW_STR
10961 IP_STR
10962 BGP_STR
10963 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10964 "Display route and more specific routes\n")
10965{
50ef26d4 10966 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
10967 bgp_show_type_prefix_longer);
10968}
10969
8386ac43 10970DEFUN (show_ip_bgp_instance_prefix_longer,
10971 show_ip_bgp_instance_prefix_longer_cmd,
10972 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M longer-prefixes",
50ef26d4 10973 SHOW_STR
10974 IP_STR
10975 BGP_STR
8386ac43 10976 BGP_INSTANCE_HELP_STR
50ef26d4 10977 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10978 "Display route and more specific routes\n")
10979{
10980 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
718e3744 10981 bgp_show_type_prefix_longer);
10982}
10983
10984DEFUN (show_ip_bgp_flap_prefix_longer,
10985 show_ip_bgp_flap_prefix_longer_cmd,
10986 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
10987 SHOW_STR
10988 IP_STR
10989 BGP_STR
10990 "Display flap statistics of routes\n"
10991 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10992 "Display route and more specific routes\n")
10993{
50ef26d4 10994 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 10995 bgp_show_type_flap_prefix_longer);
10996}
10997
81304aaf
B
10998ALIAS (show_ip_bgp_flap_prefix_longer,
10999 show_ip_bgp_damp_flap_prefix_longer_cmd,
11000 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11001 SHOW_STR
11002 IP_STR
11003 BGP_STR
11004 "Display detailed information about dampening\n"
11005 "Display flap statistics of routes\n"
11006 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11007 "Display route and more specific routes\n")
11008
718e3744 11009DEFUN (show_ip_bgp_ipv4_prefix_longer,
11010 show_ip_bgp_ipv4_prefix_longer_cmd,
11011 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11012 SHOW_STR
11013 IP_STR
11014 BGP_STR
11015 "Address family\n"
11016 "Address Family modifier\n"
11017 "Address Family modifier\n"
11018 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11019 "Display route and more specific routes\n")
11020{
11021 if (strncmp (argv[0], "m", 1) == 0)
50ef26d4 11022 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
718e3744 11023 bgp_show_type_prefix_longer);
11024
50ef26d4 11025 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
718e3744 11026 bgp_show_type_prefix_longer);
11027}
11028
11029DEFUN (show_ip_bgp_flap_address,
11030 show_ip_bgp_flap_address_cmd,
11031 "show ip bgp flap-statistics A.B.C.D",
11032 SHOW_STR
11033 IP_STR
11034 BGP_STR
11035 "Display flap statistics of routes\n"
11036 "Network in the BGP routing table to display\n")
11037{
50ef26d4 11038 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 11039 bgp_show_type_flap_address);
11040}
11041
81304aaf
B
11042ALIAS (show_ip_bgp_flap_address,
11043 show_ip_bgp_damp_flap_address_cmd,
11044 "show ip bgp dampening flap-statistics A.B.C.D",
11045 SHOW_STR
11046 IP_STR
11047 BGP_STR
11048 "Display detailed information about dampening\n"
11049 "Display flap statistics of routes\n"
11050 "Network in the BGP routing table to display\n")
11051
718e3744 11052DEFUN (show_ip_bgp_flap_prefix,
11053 show_ip_bgp_flap_prefix_cmd,
11054 "show ip bgp flap-statistics A.B.C.D/M",
11055 SHOW_STR
11056 IP_STR
11057 BGP_STR
11058 "Display flap statistics of routes\n"
11059 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11060{
50ef26d4 11061 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 11062 bgp_show_type_flap_prefix);
11063}
81304aaf
B
11064
11065ALIAS (show_ip_bgp_flap_prefix,
11066 show_ip_bgp_damp_flap_prefix_cmd,
11067 "show ip bgp dampening flap-statistics A.B.C.D/M",
11068 SHOW_STR
11069 IP_STR
11070 BGP_STR
11071 "Display detailed information about dampening\n"
11072 "Display flap statistics of routes\n"
11073 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11074
718e3744 11075#ifdef HAVE_IPV6
11076DEFUN (show_bgp_prefix_longer,
11077 show_bgp_prefix_longer_cmd,
11078 "show bgp X:X::X:X/M longer-prefixes",
11079 SHOW_STR
11080 BGP_STR
11081 "IPv6 prefix <network>/<length>\n"
11082 "Display route and more specific routes\n")
11083{
50ef26d4 11084 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 11085 bgp_show_type_prefix_longer);
11086}
11087
11088ALIAS (show_bgp_prefix_longer,
11089 show_bgp_ipv6_prefix_longer_cmd,
11090 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11091 SHOW_STR
11092 BGP_STR
11093 "Address family\n"
11094 "IPv6 prefix <network>/<length>\n"
11095 "Display route and more specific routes\n")
11096
11097/* old command */
11098DEFUN (show_ipv6_bgp_prefix_longer,
11099 show_ipv6_bgp_prefix_longer_cmd,
11100 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11101 SHOW_STR
11102 IPV6_STR
11103 BGP_STR
11104 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11105 "Display route and more specific routes\n")
11106{
47e9b292 11107 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 11108 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 11109 bgp_show_type_prefix_longer);
11110}
11111
11112/* old command */
11113DEFUN (show_ipv6_mbgp_prefix_longer,
11114 show_ipv6_mbgp_prefix_longer_cmd,
11115 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11116 SHOW_STR
11117 IPV6_STR
11118 MBGP_STR
11119 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11120 "Display route and more specific routes\n")
11121{
47e9b292 11122 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 11123 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
718e3744 11124 bgp_show_type_prefix_longer);
11125}
11126#endif /* HAVE_IPV6 */
bb46e94f 11127
94f2b392 11128static struct peer *
fd79ac91 11129peer_lookup_in_view (struct vty *vty, const char *view_name,
856ca177 11130 const char *ip_str, u_char use_json)
bb46e94f 11131{
11132 int ret;
11133 struct bgp *bgp;
11134 struct peer *peer;
11135 union sockunion su;
11136
11137 /* BGP structure lookup. */
11138 if (view_name)
11139 {
11140 bgp = bgp_lookup_by_name (view_name);
11141 if (! bgp)
11142 {
856ca177
MS
11143 if (use_json)
11144 {
11145 json_object *json_no = NULL;
11146 json_no = json_object_new_object();
11147 json_object_string_add(json_no, "warning", "Can't find BGP view");
11148 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11149 json_object_free(json_no);
11150 }
11151 else
6aeb9e78 11152 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
bb46e94f 11153 return NULL;
11154 }
11155 }
5228ad27 11156 else
bb46e94f 11157 {
11158 bgp = bgp_get_default ();
11159 if (! bgp)
11160 {
856ca177
MS
11161 if (use_json)
11162 {
11163 json_object *json_no = NULL;
11164 json_no = json_object_new_object();
11165 json_object_string_add(json_no, "warning", "No BGP process configured");
11166 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11167 json_object_free(json_no);
11168 }
11169 else
11170 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
bb46e94f 11171 return NULL;
11172 }
11173 }
11174
11175 /* Get peer sockunion. */
11176 ret = str2sockunion (ip_str, &su);
11177 if (ret < 0)
11178 {
a80beece
DS
11179 peer = peer_lookup_by_conf_if (bgp, ip_str);
11180 if (!peer)
11181 {
04b6bdc0
DW
11182 peer = peer_lookup_by_hostname(bgp, ip_str);
11183
11184 if (!peer)
856ca177 11185 {
04b6bdc0
DW
11186 if (use_json)
11187 {
11188 json_object *json_no = NULL;
11189 json_no = json_object_new_object();
11190 json_object_string_add(json_no, "malformedAddressOrName", ip_str);
11191 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11192 json_object_free(json_no);
11193 }
11194 else
11195 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
11196 return NULL;
856ca177 11197 }
a80beece
DS
11198 }
11199 return peer;
bb46e94f 11200 }
11201
11202 /* Peer structure lookup. */
11203 peer = peer_lookup (bgp, &su);
11204 if (! peer)
11205 {
856ca177
MS
11206 if (use_json)
11207 {
11208 json_object *json_no = NULL;
11209 json_no = json_object_new_object();
11210 json_object_string_add(json_no, "warning","No such neighbor");
11211 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11212 json_object_free(json_no);
11213 }
11214 else
11215 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
bb46e94f 11216 return NULL;
11217 }
11218
11219 return peer;
11220}
6b0655a2 11221
2815e61f
PJ
11222enum bgp_stats
11223{
11224 BGP_STATS_MAXBITLEN = 0,
11225 BGP_STATS_RIB,
11226 BGP_STATS_PREFIXES,
11227 BGP_STATS_TOTPLEN,
11228 BGP_STATS_UNAGGREGATEABLE,
11229 BGP_STATS_MAX_AGGREGATEABLE,
11230 BGP_STATS_AGGREGATES,
11231 BGP_STATS_SPACE,
11232 BGP_STATS_ASPATH_COUNT,
11233 BGP_STATS_ASPATH_MAXHOPS,
11234 BGP_STATS_ASPATH_TOTHOPS,
11235 BGP_STATS_ASPATH_MAXSIZE,
11236 BGP_STATS_ASPATH_TOTSIZE,
11237 BGP_STATS_ASN_HIGHEST,
11238 BGP_STATS_MAX,
11239};
11240
11241static const char *table_stats_strs[] =
11242{
11243 [BGP_STATS_PREFIXES] = "Total Prefixes",
11244 [BGP_STATS_TOTPLEN] = "Average prefix length",
11245 [BGP_STATS_RIB] = "Total Advertisements",
11246 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11247 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11248 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11249 [BGP_STATS_SPACE] = "Address space advertised",
11250 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11251 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11252 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11253 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11254 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11255 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11256 [BGP_STATS_MAX] = NULL,
11257};
11258
11259struct bgp_table_stats
11260{
11261 struct bgp_table *table;
11262 unsigned long long counts[BGP_STATS_MAX];
11263};
11264
11265#if 0
11266#define TALLY_SIGFIG 100000
11267static unsigned long
11268ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11269{
11270 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11271 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11272 unsigned long ret = newtot / count;
11273
11274 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11275 return ret + 1;
11276 else
11277 return ret;
11278}
11279#endif
11280
11281static int
11282bgp_table_stats_walker (struct thread *t)
11283{
11284 struct bgp_node *rn;
11285 struct bgp_node *top;
11286 struct bgp_table_stats *ts = THREAD_ARG (t);
11287 unsigned int space = 0;
11288
53d9f67a
PJ
11289 if (!(top = bgp_table_top (ts->table)))
11290 return 0;
2815e61f
PJ
11291
11292 switch (top->p.family)
11293 {
11294 case AF_INET:
11295 space = IPV4_MAX_BITLEN;
11296 break;
11297 case AF_INET6:
11298 space = IPV6_MAX_BITLEN;
11299 break;
11300 }
11301
11302 ts->counts[BGP_STATS_MAXBITLEN] = space;
11303
11304 for (rn = top; rn; rn = bgp_route_next (rn))
11305 {
11306 struct bgp_info *ri;
67174041 11307 struct bgp_node *prn = bgp_node_parent_nolock (rn);
2815e61f
PJ
11308 unsigned int rinum = 0;
11309
11310 if (rn == top)
11311 continue;
11312
11313 if (!rn->info)
11314 continue;
11315
11316 ts->counts[BGP_STATS_PREFIXES]++;
11317 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11318
11319#if 0
11320 ts->counts[BGP_STATS_AVGPLEN]
11321 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11322 ts->counts[BGP_STATS_AVGPLEN],
11323 rn->p.prefixlen);
11324#endif
11325
11326 /* check if the prefix is included by any other announcements */
11327 while (prn && !prn->info)
67174041 11328 prn = bgp_node_parent_nolock (prn);
2815e61f
PJ
11329
11330 if (prn == NULL || prn == top)
8383a9bd
PJ
11331 {
11332 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11333 /* announced address space */
11334 if (space)
11335 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11336 }
2815e61f
PJ
11337 else if (prn->info)
11338 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11339
2815e61f
PJ
11340 for (ri = rn->info; ri; ri = ri->next)
11341 {
11342 rinum++;
11343 ts->counts[BGP_STATS_RIB]++;
11344
11345 if (ri->attr &&
11346 (CHECK_FLAG (ri->attr->flag,
11347 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11348 ts->counts[BGP_STATS_AGGREGATES]++;
11349
11350 /* as-path stats */
11351 if (ri->attr && ri->attr->aspath)
11352 {
11353 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11354 unsigned int size = aspath_size (ri->attr->aspath);
11355 as_t highest = aspath_highest (ri->attr->aspath);
11356
11357 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11358
11359 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11360 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11361
11362 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11363 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11364
11365 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11366 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11367#if 0
11368 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11369 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11370 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11371 hops);
11372 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11373 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11374 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11375 size);
11376#endif
11377 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11378 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11379 }
11380 }
11381 }
11382 return 0;
11383}
11384
11385static int
11386bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11387{
11388 struct bgp_table_stats ts;
11389 unsigned int i;
11390
11391 if (!bgp->rib[afi][safi])
11392 {
06da0daf
DS
11393 vty_out (vty, "%% No RIB exist's for the AFI(%d)/SAFI(%d)%s",
11394 afi, safi, VTY_NEWLINE);
2815e61f
PJ
11395 return CMD_WARNING;
11396 }
11397
11398 memset (&ts, 0, sizeof (ts));
11399 ts.table = bgp->rib[afi][safi];
87d4a781 11400 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
bb46e94f 11401
2815e61f
PJ
11402 vty_out (vty, "BGP %s RIB statistics%s%s",
11403 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11404
11405 for (i = 0; i < BGP_STATS_MAX; i++)
11406 {
11407 if (!table_stats_strs[i])
11408 continue;
11409
11410 switch (i)
11411 {
11412#if 0
11413 case BGP_STATS_ASPATH_AVGHOPS:
11414 case BGP_STATS_ASPATH_AVGSIZE:
11415 case BGP_STATS_AVGPLEN:
11416 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11417 vty_out (vty, "%12.2f",
11418 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11419 break;
11420#endif
11421 case BGP_STATS_ASPATH_TOTHOPS:
11422 case BGP_STATS_ASPATH_TOTSIZE:
11423 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11424 vty_out (vty, "%12.2f",
11425 ts.counts[i] ?
11426 (float)ts.counts[i] /
11427 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11428 : 0);
11429 break;
11430 case BGP_STATS_TOTPLEN:
11431 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11432 vty_out (vty, "%12.2f",
11433 ts.counts[i] ?
11434 (float)ts.counts[i] /
11435 (float)ts.counts[BGP_STATS_PREFIXES]
11436 : 0);
11437 break;
11438 case BGP_STATS_SPACE:
11439 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11440 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11441 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11442 break;
30a2231a 11443 vty_out (vty, "%30s: ", "%% announced ");
2815e61f
PJ
11444 vty_out (vty, "%12.2f%s",
11445 100 * (float)ts.counts[BGP_STATS_SPACE] /
56395af7 11446 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
2815e61f
PJ
11447 VTY_NEWLINE);
11448 vty_out (vty, "%30s: ", "/8 equivalent ");
11449 vty_out (vty, "%12.2f%s",
11450 (float)ts.counts[BGP_STATS_SPACE] /
11451 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11452 VTY_NEWLINE);
11453 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11454 break;
11455 vty_out (vty, "%30s: ", "/24 equivalent ");
11456 vty_out (vty, "%12.2f",
11457 (float)ts.counts[BGP_STATS_SPACE] /
11458 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11459 break;
11460 default:
11461 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11462 vty_out (vty, "%12llu", ts.counts[i]);
11463 }
11464
11465 vty_out (vty, "%s", VTY_NEWLINE);
11466 }
11467 return CMD_SUCCESS;
11468}
11469
11470static int
11471bgp_table_stats_vty (struct vty *vty, const char *name,
11472 const char *afi_str, const char *safi_str)
11473{
11474 struct bgp *bgp;
11475 afi_t afi;
11476 safi_t safi;
11477
11478 if (name)
11479 bgp = bgp_lookup_by_name (name);
11480 else
11481 bgp = bgp_get_default ();
11482
11483 if (!bgp)
11484 {
11485 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
11486 return CMD_WARNING;
11487 }
11488 if (strncmp (afi_str, "ipv", 3) == 0)
11489 {
11490 if (strncmp (afi_str, "ipv4", 4) == 0)
11491 afi = AFI_IP;
11492 else if (strncmp (afi_str, "ipv6", 4) == 0)
11493 afi = AFI_IP6;
11494 else
11495 {
11496 vty_out (vty, "%% Invalid address family %s%s",
11497 afi_str, VTY_NEWLINE);
11498 return CMD_WARNING;
11499 }
11500 if (strncmp (safi_str, "m", 1) == 0)
11501 safi = SAFI_MULTICAST;
11502 else if (strncmp (safi_str, "u", 1) == 0)
11503 safi = SAFI_UNICAST;
587ff0fd
LB
11504 else if (strncmp (safi_str, "e", 1) == 0)
11505 safi = SAFI_ENCAP;
42e6d745 11506 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
06da0daf 11507 safi = SAFI_MPLS_VPN;
2815e61f
PJ
11508 else
11509 {
11510 vty_out (vty, "%% Invalid subsequent address family %s%s",
11511 safi_str, VTY_NEWLINE);
587ff0fd
LB
11512 return CMD_WARNING;
11513 }
2815e61f
PJ
11514 }
11515 else
11516 {
587ff0fd 11517 vty_out (vty, "%% Invalid address family \"%s\"%s",
2815e61f
PJ
11518 afi_str, VTY_NEWLINE);
11519 return CMD_WARNING;
11520 }
11521
2815e61f
PJ
11522 return bgp_table_stats (vty, bgp, afi, safi);
11523}
11524
11525DEFUN (show_bgp_statistics,
11526 show_bgp_statistics_cmd,
587ff0fd 11527 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
2815e61f
PJ
11528 SHOW_STR
11529 BGP_STR
11530 "Address family\n"
11531 "Address family\n"
11532 "Address Family modifier\n"
11533 "Address Family modifier\n"
587ff0fd
LB
11534 "Address Family modifier\n"
11535 "Address Family modifier\n"
2815e61f
PJ
11536 "BGP RIB advertisement statistics\n")
11537{
11538 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11539}
11540
2815e61f
PJ
11541DEFUN (show_bgp_statistics_view,
11542 show_bgp_statistics_view_cmd,
587ff0fd 11543 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast|vpn|encap) statistics",
2815e61f
PJ
11544 SHOW_STR
11545 BGP_STR
8386ac43 11546 BGP_INSTANCE_HELP_STR
2815e61f
PJ
11547 "Address family\n"
11548 "Address family\n"
11549 "Address Family modifier\n"
11550 "Address Family modifier\n"
587ff0fd
LB
11551 "Address Family modifier\n"
11552 "Address Family modifier\n"
2815e61f
PJ
11553 "BGP RIB advertisement statistics\n")
11554{
6aeb9e78 11555 return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]);
2815e61f
PJ
11556}
11557
ff7924f6
PJ
11558enum bgp_pcounts
11559{
11560 PCOUNT_ADJ_IN = 0,
11561 PCOUNT_DAMPED,
11562 PCOUNT_REMOVED,
11563 PCOUNT_HISTORY,
11564 PCOUNT_STALE,
11565 PCOUNT_VALID,
11566 PCOUNT_ALL,
11567 PCOUNT_COUNTED,
11568 PCOUNT_PFCNT, /* the figure we display to users */
11569 PCOUNT_MAX,
11570};
11571
11572static const char *pcount_strs[] =
11573{
11574 [PCOUNT_ADJ_IN] = "Adj-in",
11575 [PCOUNT_DAMPED] = "Damped",
11576 [PCOUNT_REMOVED] = "Removed",
11577 [PCOUNT_HISTORY] = "History",
11578 [PCOUNT_STALE] = "Stale",
11579 [PCOUNT_VALID] = "Valid",
11580 [PCOUNT_ALL] = "All RIB",
11581 [PCOUNT_COUNTED] = "PfxCt counted",
11582 [PCOUNT_PFCNT] = "Useable",
11583 [PCOUNT_MAX] = NULL,
11584};
11585
2815e61f
PJ
11586struct peer_pcounts
11587{
11588 unsigned int count[PCOUNT_MAX];
11589 const struct peer *peer;
11590 const struct bgp_table *table;
11591};
11592
ff7924f6 11593static int
2815e61f 11594bgp_peer_count_walker (struct thread *t)
ff7924f6
PJ
11595{
11596 struct bgp_node *rn;
2815e61f
PJ
11597 struct peer_pcounts *pc = THREAD_ARG (t);
11598 const struct peer *peer = pc->peer;
ff7924f6 11599
2815e61f 11600 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
ff7924f6
PJ
11601 {
11602 struct bgp_adj_in *ain;
2815e61f 11603 struct bgp_info *ri;
ff7924f6
PJ
11604
11605 for (ain = rn->adj_in; ain; ain = ain->next)
11606 if (ain->peer == peer)
2815e61f 11607 pc->count[PCOUNT_ADJ_IN]++;
ff7924f6 11608
ff7924f6
PJ
11609 for (ri = rn->info; ri; ri = ri->next)
11610 {
11611 char buf[SU_ADDRSTRLEN];
11612
11613 if (ri->peer != peer)
11614 continue;
11615
2815e61f 11616 pc->count[PCOUNT_ALL]++;
ff7924f6
PJ
11617
11618 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
2815e61f 11619 pc->count[PCOUNT_DAMPED]++;
ff7924f6 11620 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2815e61f 11621 pc->count[PCOUNT_HISTORY]++;
ff7924f6 11622 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
2815e61f 11623 pc->count[PCOUNT_REMOVED]++;
ff7924f6 11624 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2815e61f 11625 pc->count[PCOUNT_STALE]++;
ff7924f6 11626 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
2815e61f 11627 pc->count[PCOUNT_VALID]++;
1a392d46 11628 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2815e61f 11629 pc->count[PCOUNT_PFCNT]++;
ff7924f6
PJ
11630
11631 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
11632 {
2815e61f 11633 pc->count[PCOUNT_COUNTED]++;
1a392d46 11634 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 11635 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
ff7924f6
PJ
11636 peer->host,
11637 inet_ntop(rn->p.family, &rn->p.u.prefix,
11638 buf, SU_ADDRSTRLEN),
11639 rn->p.prefixlen,
11640 ri->flags);
11641 }
11642 else
11643 {
1a392d46 11644 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 11645 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
ff7924f6
PJ
11646 peer->host,
11647 inet_ntop(rn->p.family, &rn->p.u.prefix,
11648 buf, SU_ADDRSTRLEN),
11649 rn->p.prefixlen,
11650 ri->flags);
11651 }
11652 }
11653 }
2815e61f
PJ
11654 return 0;
11655}
ff7924f6 11656
2815e61f 11657static int
856ca177 11658bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json)
2815e61f
PJ
11659{
11660 struct peer_pcounts pcounts = { .peer = peer };
11661 unsigned int i;
856ca177
MS
11662 json_object *json = NULL;
11663 json_object *json_loop = NULL;
11664
11665 if (use_json)
11666 {
11667 json = json_object_new_object();
11668 json_loop = json_object_new_object();
11669 }
2815e61f
PJ
11670
11671 if (!peer || !peer->bgp || !peer->afc[afi][safi]
11672 || !peer->bgp->rib[afi][safi])
11673 {
856ca177
MS
11674 if (use_json)
11675 {
11676 json_object_string_add(json, "warning", "No such neighbor or address family");
11677 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11678 json_object_free(json);
11679 }
11680 else
11681 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11682
2815e61f
PJ
11683 return CMD_WARNING;
11684 }
11685
11686 memset (&pcounts, 0, sizeof(pcounts));
11687 pcounts.peer = peer;
11688 pcounts.table = peer->bgp->rib[afi][safi];
11689
11690 /* in-place call via thread subsystem so as to record execution time
856ca177
MS
11691 * * stats for the thread-walk (i.e. ensure this can't be blamed on
11692 * * on just vty_read()).
11693 * */
87d4a781 11694 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
6410e93a 11695
856ca177
MS
11696 if (use_json)
11697 {
11698 json_object_string_add(json, "prefixCountsFor", peer->host);
11699 json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi));
11700 json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]);
11701
11702 for (i = 0; i < PCOUNT_MAX; i++)
11703 json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]);
ff7924f6 11704
856ca177 11705 json_object_object_add(json, "ribTableWalkCounters", json_loop);
ff7924f6 11706
856ca177
MS
11707 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
11708 {
11709 json_object_string_add(json, "pfxctDriftFor", peer->host);
11710 json_object_string_add(json, "recommended", "Please report this bug, with the above command output");
11711 }
11712 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11713 json_object_free(json);
11714 }
11715 else
ff7924f6 11716 {
04b6bdc0
DW
11717
11718 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
11719 {
11720 vty_out (vty, "Prefix counts for %s/%s, %s%s",
11721 peer->hostname, peer->host, afi_safi_print (afi, safi),
11722 VTY_NEWLINE);
11723 }
11724 else
11725 {
11726 vty_out (vty, "Prefix counts for %s, %s%s",
11727 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
11728 }
11729
856ca177
MS
11730 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
11731 vty_out (vty, "%sCounts from RIB table walk:%s%s",
11732 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
11733
11734 for (i = 0; i < PCOUNT_MAX; i++)
11735 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
11736
11737 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
11738 {
11739 vty_out (vty, "%s [pcount] PfxCt drift!%s",
11740 peer->host, VTY_NEWLINE);
11741 vty_out (vty, "Please report this bug, with the above command output%s",
11742 VTY_NEWLINE);
11743 }
ff7924f6
PJ
11744 }
11745
11746 return CMD_SUCCESS;
11747}
11748
11749DEFUN (show_ip_bgp_neighbor_prefix_counts,
11750 show_ip_bgp_neighbor_prefix_counts_cmd,
856ca177 11751 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
11752 SHOW_STR
11753 IP_STR
11754 BGP_STR
11755 "Detailed information on TCP and BGP neighbor connections\n"
11756 "Neighbor to display information about\n"
11757 "Neighbor to display information about\n"
a80beece 11758 "Neighbor on bgp configured interface\n"
856ca177
MS
11759 "Display detailed prefix count information\n"
11760 "JavaScript Object Notation\n")
ff7924f6
PJ
11761{
11762 struct peer *peer;
db7c8528 11763 u_char uj = use_json(argc, argv);
ff7924f6 11764
db7c8528 11765 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
ff7924f6
PJ
11766 if (! peer)
11767 return CMD_WARNING;
11768
db7c8528 11769 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
ff7924f6
PJ
11770}
11771
8386ac43 11772DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
11773 show_ip_bgp_instance_neighbor_prefix_counts_cmd,
11774 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
50ef26d4 11775 SHOW_STR
11776 IP_STR
11777 BGP_STR
8386ac43 11778 BGP_INSTANCE_HELP_STR
50ef26d4 11779 "Detailed information on TCP and BGP neighbor connections\n"
11780 "Neighbor to display information about\n"
11781 "Neighbor to display information about\n"
11782 "Neighbor on bgp configured interface\n"
11783 "Display detailed prefix count information\n"
11784 "JavaScript Object Notation\n")
11785{
11786 struct peer *peer;
11787 u_char uj = use_json(argc, argv);
11788
11789 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
11790 if (! peer)
11791 return CMD_WARNING;
11792
11793 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
11794}
11795
ff7924f6
PJ
11796DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
11797 show_bgp_ipv6_neighbor_prefix_counts_cmd,
856ca177 11798 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
11799 SHOW_STR
11800 BGP_STR
11801 "Address family\n"
11802 "Detailed information on TCP and BGP neighbor connections\n"
11803 "Neighbor to display information about\n"
11804 "Neighbor to display information about\n"
a80beece 11805 "Neighbor on bgp configured interface\n"
856ca177
MS
11806 "Display detailed prefix count information\n"
11807 "JavaScript Object Notation\n")
ff7924f6
PJ
11808{
11809 struct peer *peer;
db7c8528 11810 u_char uj = use_json(argc, argv);
856ca177 11811
db7c8528 11812 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
ff7924f6
PJ
11813 if (! peer)
11814 return CMD_WARNING;
11815
db7c8528 11816 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
ff7924f6
PJ
11817}
11818
8386ac43 11819DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts,
11820 show_bgp_instance_ipv6_neighbor_prefix_counts_cmd,
11821 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
50ef26d4 11822 SHOW_STR
11823 BGP_STR
8386ac43 11824 BGP_INSTANCE_HELP_STR
50ef26d4 11825 "Address family\n"
11826 "Detailed information on TCP and BGP neighbor connections\n"
11827 "Neighbor to display information about\n"
11828 "Neighbor to display information about\n"
11829 "Neighbor on bgp configured interface\n"
11830 "Display detailed prefix count information\n"
11831 "JavaScript Object Notation\n")
11832{
11833 struct peer *peer;
11834 u_char uj = use_json(argc, argv);
11835
11836 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
11837 if (! peer)
11838 return CMD_WARNING;
11839
11840 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
11841}
11842
ff7924f6
PJ
11843DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
11844 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
856ca177 11845 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
11846 SHOW_STR
11847 IP_STR
11848 BGP_STR
11849 "Address family\n"
11850 "Address Family modifier\n"
11851 "Address Family modifier\n"
11852 "Detailed information on TCP and BGP neighbor connections\n"
11853 "Neighbor to display information about\n"
11854 "Neighbor to display information about\n"
a80beece 11855 "Neighbor on bgp configured interface\n"
856ca177
MS
11856 "Display detailed prefix count information\n"
11857 "JavaScript Object Notation\n")
ff7924f6
PJ
11858{
11859 struct peer *peer;
db7c8528 11860 u_char uj = use_json(argc, argv);
ff7924f6 11861
db7c8528 11862 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
ff7924f6
PJ
11863 if (! peer)
11864 return CMD_WARNING;
11865
11866 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 11867 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST, uj);
ff7924f6 11868
db7c8528 11869 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
ff7924f6
PJ
11870}
11871
11872DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
11873 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
856ca177 11874 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
11875 SHOW_STR
11876 IP_STR
11877 BGP_STR
11878 "Address family\n"
11879 "Address Family modifier\n"
11880 "Address Family modifier\n"
11881 "Detailed information on TCP and BGP neighbor connections\n"
11882 "Neighbor to display information about\n"
11883 "Neighbor to display information about\n"
a80beece 11884 "Neighbor on bgp configured interface\n"
856ca177
MS
11885 "Display detailed prefix count information\n"
11886 "JavaScript Object Notation\n")
ff7924f6
PJ
11887{
11888 struct peer *peer;
db7c8528 11889 u_char uj = use_json(argc, argv);
856ca177 11890
db7c8528 11891 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
ff7924f6
PJ
11892 if (! peer)
11893 return CMD_WARNING;
11894
db7c8528 11895 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN, uj);
ff7924f6
PJ
11896}
11897
94f2b392 11898static void
718e3744 11899show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
856ca177 11900 int in, const char *rmap_name, u_char use_json, json_object *json)
718e3744 11901{
11902 struct bgp_table *table;
11903 struct bgp_adj_in *ain;
11904 struct bgp_adj_out *adj;
11905 unsigned long output_count;
0b16f239 11906 unsigned long filtered_count;
718e3744 11907 struct bgp_node *rn;
11908 int header1 = 1;
11909 struct bgp *bgp;
11910 int header2 = 1;
0b16f239
DS
11911 struct attr attr;
11912 struct attr_extra extra;
11913 int ret;
840fced9 11914 struct update_subgroup *subgrp;
856ca177
MS
11915 json_object *json_scode = NULL;
11916 json_object *json_ocode = NULL;
11917 json_object *json_ar = NULL;
adbac85e 11918 struct peer_af *paf;
856ca177
MS
11919
11920 if (use_json)
11921 {
11922 json_scode = json_object_new_object();
11923 json_ocode = json_object_new_object();
11924 json_ar = json_object_new_object();
11925
11926 json_object_string_add(json_scode, "suppressed", "s");
11927 json_object_string_add(json_scode, "damped", "d");
11928 json_object_string_add(json_scode, "history", "h");
11929 json_object_string_add(json_scode, "valid", "*");
11930 json_object_string_add(json_scode, "best", ">");
11931 json_object_string_add(json_scode, "multipath", "=");
11932 json_object_string_add(json_scode, "internal", "i");
11933 json_object_string_add(json_scode, "ribFailure", "r");
11934 json_object_string_add(json_scode, "stale", "S");
11935 json_object_string_add(json_scode, "removed", "R");
11936
11937 json_object_string_add(json_ocode, "igp", "i");
11938 json_object_string_add(json_ocode, "egp", "e");
11939 json_object_string_add(json_ocode, "incomplete", "?");
11940 }
718e3744 11941
bb46e94f 11942 bgp = peer->bgp;
718e3744 11943
11944 if (! bgp)
856ca177
MS
11945 {
11946 if (use_json)
11947 {
11948 json_object_string_add(json, "alert", "no BGP");
11949 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11950 json_object_free(json);
11951 }
11952 else
11953 vty_out (vty, "%% No bgp%s", VTY_NEWLINE);
11954 return;
11955 }
718e3744 11956
11957 table = bgp->rib[afi][safi];
11958
0b16f239 11959 output_count = filtered_count = 0;
840fced9 11960 subgrp = peer_subgroup(peer, afi, safi);
47fc97cc 11961
840fced9 11962 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
718e3744 11963 {
856ca177
MS
11964 if (use_json)
11965 {
11966 json_object_int_add(json, "bgpTableVersion", table->version);
11967 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
11968 json_object_object_add(json, "bgpStatusCodes", json_scode);
11969 json_object_object_add(json, "bgpOriginCodes", json_ocode);
11970 json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0");
11971 }
11972 else
11973 {
11974 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
11975 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11976 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 11977
856ca177
MS
11978 vty_out (vty, "Originating default network 0.0.0.0%s%s",
11979 VTY_NEWLINE, VTY_NEWLINE);
11980 }
718e3744 11981 header1 = 0;
11982 }
11983
0b16f239 11984 attr.extra = &extra;
718e3744 11985 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
856ca177
MS
11986 {
11987 if (in)
11988 {
11989 for (ain = rn->adj_in; ain; ain = ain->next)
11990 {
11991 if (ain->peer == peer)
11992 {
11993 if (header1)
11994 {
11995 if (use_json)
11996 {
11997 json_object_int_add(json, "bgpTableVersion", 0);
11998 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
11999 json_object_object_add(json, "bgpStatusCodes", json_scode);
12000 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12001 }
12002 else
12003 {
12004 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
12005 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12006 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12007 }
12008 header1 = 0;
12009 }
12010 if (header2)
12011 {
12012 if (!use_json)
12013 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12014 header2 = 0;
12015 }
12016 if (ain->attr)
12017 {
12018 bgp_attr_dup(&attr, ain->attr);
12019 if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY)
12020 {
12021 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12022 output_count++;
12023 }
12024 else
12025 filtered_count++;
12026 }
12027 }
12028 }
12029 }
12030 else
12031 {
adbac85e
DW
12032 for (adj = rn->adj_out; adj; adj = adj->next)
12033 SUBGRP_FOREACH_PEER(adj->subgroup, paf)
12034 if (paf->peer == peer)
856ca177 12035 {
adbac85e 12036 if (header1)
856ca177 12037 {
adbac85e
DW
12038 if (use_json)
12039 {
12040 json_object_int_add(json, "bgpTableVersion", table->version);
12041 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12042 json_object_object_add(json, "bgpStatusCodes", json_scode);
12043 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12044 }
12045 else
12046 {
12047 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version,
12048 inet_ntoa (bgp->router_id), VTY_NEWLINE);
12049 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12050 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12051 }
12052 header1 = 0;
856ca177 12053 }
adbac85e
DW
12054
12055 if (header2)
856ca177 12056 {
adbac85e
DW
12057 if (!use_json)
12058 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12059 header2 = 0;
856ca177 12060 }
adbac85e
DW
12061
12062 if (adj->attr)
856ca177 12063 {
adbac85e
DW
12064 bgp_attr_dup(&attr, adj->attr);
12065 ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name);
12066 if (ret != RMAP_DENY)
12067 {
12068 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12069 output_count++;
12070 }
12071 else
12072 filtered_count++;
856ca177 12073 }
856ca177 12074 }
856ca177
MS
12075 }
12076 }
12077 if (use_json)
12078 json_object_object_add(json, "advertisedRoutes", json_ar);
47fc97cc 12079
718e3744 12080 if (output_count != 0)
856ca177
MS
12081 {
12082 if (use_json)
12083 json_object_int_add(json, "totalPrefixCounter", output_count);
12084 else
12085 vty_out (vty, "%sTotal number of prefixes %ld%s",
12086 VTY_NEWLINE, output_count, VTY_NEWLINE);
12087 }
12088 if (use_json)
12089 {
12090 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12091 json_object_free(json);
12092 }
12093
718e3744 12094}
12095
94f2b392 12096static int
47fc97cc 12097peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
856ca177
MS
12098 int in, const char *rmap_name, u_char use_json)
12099{
12100 json_object *json = NULL;
12101
12102 if (use_json)
12103 json = json_object_new_object();
12104
12105 if (!peer || !peer->afc[afi][safi])
718e3744 12106 {
856ca177
MS
12107 if (use_json)
12108 {
12109 json_object_string_add(json, "warning", "No such neighbor or address family");
12110 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12111 json_object_free(json);
12112 }
12113 else
12114 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12115
718e3744 12116 return CMD_WARNING;
12117 }
12118
856ca177 12119 if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
718e3744 12120 {
856ca177
MS
12121 if (use_json)
12122 {
12123 json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
12124 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12125 json_object_free(json);
12126 }
12127 else
12128 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE);
12129
718e3744 12130 return CMD_WARNING;
12131 }
12132
856ca177 12133 show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json);
718e3744 12134
12135 return CMD_SUCCESS;
12136}
12137
8386ac43 12138DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
12139 show_ip_bgp_instance_neighbor_advertised_route_cmd,
12140 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12141 SHOW_STR
12142 IP_STR
12143 BGP_STR
8386ac43 12144 BGP_INSTANCE_HELP_STR
718e3744 12145 "Detailed information on TCP and BGP neighbor connections\n"
12146 "Neighbor to display information about\n"
12147 "Neighbor to display information about\n"
856ca177
MS
12148 "Display the routes advertised to a BGP neighbor\n"
12149 "JavaScript Object Notation\n")
718e3744 12150{
bb46e94f 12151 struct peer *peer;
db7c8528 12152 u_char uj = use_json(argc, argv);
856ca177 12153
6aeb9e78
DS
12154 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12155 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
2a71e9ce 12156 else
6aeb9e78 12157 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
2a71e9ce 12158
bb46e94f 12159 if (! peer)
12160 return CMD_WARNING;
0b16f239 12161
db7c8528 12162 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj);
718e3744 12163}
12164
0b16f239 12165DEFUN (show_ip_bgp_neighbor_advertised_route,
2a71e9ce 12166 show_ip_bgp_neighbor_advertised_route_cmd,
856ca177 12167 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
2a71e9ce
TP
12168 SHOW_STR
12169 IP_STR
12170 BGP_STR
12171 "Detailed information on TCP and BGP neighbor connections\n"
12172 "Neighbor to display information about\n"
12173 "Neighbor to display information about\n"
a80beece 12174 "Neighbor on bgp configured interface\n"
856ca177
MS
12175 "Display the routes advertised to a BGP neighbor\n"
12176 "JavaScript Object Notation\n")
2a71e9ce 12177
0b16f239
DS
12178{
12179 struct peer *peer;
ffd0c037 12180 const char *rmap_name = NULL;
db7c8528 12181 u_char uj = use_json(argc, argv);
0b16f239 12182
db7c8528 12183 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
0b16f239
DS
12184
12185 if (! peer)
12186 return CMD_WARNING;
12187
856ca177
MS
12188 if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)
12189 || (argc == 3))
0b16f239
DS
12190 rmap_name = argv[1];
12191
db7c8528 12192 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
0b16f239
DS
12193}
12194
12195ALIAS (show_ip_bgp_neighbor_advertised_route,
12196 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
856ca177 12197 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
0b16f239
DS
12198 SHOW_STR
12199 IP_STR
12200 BGP_STR
12201 "Detailed information on TCP and BGP neighbor connections\n"
12202 "Neighbor to display information about\n"
12203 "Neighbor to display information about\n"
12204 "Neighbor on bgp configured interface\n"
856ca177
MS
12205 "Display the routes advertised to a BGP neighbor\n"
12206 "JavaScript Object Notation\n")
0b16f239 12207
8386ac43 12208ALIAS (show_ip_bgp_instance_neighbor_advertised_route,
12209 show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd,
12210 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
50ef26d4 12211 SHOW_STR
12212 IP_STR
12213 BGP_STR
8386ac43 12214 BGP_INSTANCE_HELP_STR
50ef26d4 12215 "Detailed information on TCP and BGP neighbor connections\n"
12216 "Neighbor to display information about\n"
12217 "Neighbor to display information about\n"
12218 "Neighbor on bgp configured interface\n"
12219 "Display the routes advertised to a BGP neighbor\n"
12220 "JavaScript Object Notation\n")
718e3744 12221DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12222 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
856ca177 12223 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12224 SHOW_STR
12225 IP_STR
12226 BGP_STR
12227 "Address family\n"
12228 "Address Family modifier\n"
12229 "Address Family modifier\n"
12230 "Detailed information on TCP and BGP neighbor connections\n"
12231 "Neighbor to display information about\n"
12232 "Neighbor to display information about\n"
a80beece 12233 "Neighbor on bgp configured interface\n"
856ca177
MS
12234 "Display the routes advertised to a BGP neighbor\n"
12235 "JavaScript Object Notation\n")
718e3744 12236{
bb46e94f 12237 struct peer *peer;
ffd0c037 12238 const char *rmap_name = NULL;
db7c8528 12239 u_char uj = use_json(argc, argv);
856ca177 12240
db7c8528 12241 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 12242 if (! peer)
12243 return CMD_WARNING;
12244
856ca177 12245 if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
0b16f239
DS
12246 rmap_name = argv[2];
12247
718e3744 12248 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 12249 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name, uj);
856ca177 12250 else
db7c8528 12251 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
718e3744 12252}
12253
0b16f239
DS
12254ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
12255 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
856ca177 12256 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
0b16f239
DS
12257 SHOW_STR
12258 IP_STR
12259 BGP_STR
12260 "Address family\n"
12261 "Address Family modifier\n"
12262 "Address Family modifier\n"
12263 "Detailed information on TCP and BGP neighbor connections\n"
12264 "Neighbor to display information about\n"
12265 "Neighbor to display information about\n"
12266 "Neighbor on bgp configured interface\n"
12267 "Display the routes advertised to a BGP neighbor\n"
856ca177
MS
12268 "Route-map to control what is displayed\n"
12269 "JavaScript Object Notation\n")
0b16f239 12270
718e3744 12271#ifdef HAVE_IPV6
8386ac43 12272DEFUN (show_bgp_instance_neighbor_advertised_route,
12273 show_bgp_instance_neighbor_advertised_route_cmd,
12274 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12275 SHOW_STR
12276 BGP_STR
8386ac43 12277 BGP_INSTANCE_HELP_STR
718e3744 12278 "Detailed information on TCP and BGP neighbor connections\n"
12279 "Neighbor to display information about\n"
12280 "Neighbor to display information about\n"
a80beece 12281 "Neighbor on bgp configured interface\n"
856ca177
MS
12282 "Display the routes advertised to a BGP neighbor\n"
12283 "JavaScript Object Notation\n")
718e3744 12284{
bb46e94f 12285 struct peer *peer;
db7c8528 12286 u_char uj = use_json(argc, argv);
856ca177 12287
6aeb9e78
DS
12288 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12289 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
bb46e94f 12290 else
6aeb9e78 12291 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 12292
12293 if (! peer)
0b16f239 12294 return CMD_WARNING;
bb46e94f 12295
db7c8528 12296 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj);
47fc97cc
DS
12297}
12298
8386ac43 12299ALIAS (show_bgp_instance_neighbor_advertised_route,
12300 show_bgp_instance_ipv6_neighbor_advertised_route_cmd,
12301 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
0b16f239
DS
12302 SHOW_STR
12303 BGP_STR
8386ac43 12304 BGP_INSTANCE_HELP_STR
0b16f239
DS
12305 "Address family\n"
12306 "Detailed information on TCP and BGP neighbor connections\n"
12307 "Neighbor to display information about\n"
12308 "Neighbor to display information about\n"
12309 "Neighbor on bgp configured interface\n"
856ca177
MS
12310 "Display the routes advertised to a BGP neighbor\n"
12311 "JavaScript Object Notation\n")
0b16f239 12312
0b16f239
DS
12313DEFUN (show_bgp_neighbor_advertised_route,
12314 show_bgp_neighbor_advertised_route_cmd,
856ca177 12315 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
bb46e94f 12316 SHOW_STR
12317 BGP_STR
bb46e94f 12318 "Detailed information on TCP and BGP neighbor connections\n"
12319 "Neighbor to display information about\n"
12320 "Neighbor to display information about\n"
a80beece 12321 "Neighbor on bgp configured interface\n"
856ca177
MS
12322 "Display the routes advertised to a BGP neighbor\n"
12323 "JavaScript Object Notation\n")
0b16f239 12324
bb46e94f 12325{
12326 struct peer *peer;
ffd0c037 12327 const char *rmap_name = NULL;
db7c8528 12328 u_char uj = use_json(argc, argv);
bb46e94f 12329
db7c8528 12330 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
856ca177
MS
12331
12332 if (!peer)
bb46e94f 12333 return CMD_WARNING;
12334
856ca177 12335 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
0b16f239
DS
12336 rmap_name = argv[1];
12337
db7c8528 12338 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj);
718e3744 12339}
12340
0b16f239
DS
12341ALIAS (show_bgp_neighbor_advertised_route,
12342 show_bgp_ipv6_neighbor_advertised_route_cmd,
856ca177 12343 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12344 SHOW_STR
12345 BGP_STR
12346 "Address family\n"
12347 "Detailed information on TCP and BGP neighbor connections\n"
12348 "Neighbor to display information about\n"
12349 "Neighbor to display information about\n"
a80beece 12350 "Neighbor on bgp configured interface\n"
856ca177
MS
12351 "Display the routes advertised to a BGP neighbor\n"
12352 "JavaScript Object Notation\n")
718e3744 12353
12354/* old command */
0b16f239 12355ALIAS (show_bgp_neighbor_advertised_route,
718e3744 12356 ipv6_bgp_neighbor_advertised_route_cmd,
856ca177 12357 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12358 SHOW_STR
12359 IPV6_STR
12360 BGP_STR
12361 "Detailed information on TCP and BGP neighbor connections\n"
12362 "Neighbor to display information about\n"
12363 "Neighbor to display information about\n"
a80beece 12364 "Neighbor on bgp configured interface\n"
856ca177
MS
12365 "Display the routes advertised to a BGP neighbor\n"
12366 "JavaScript Object Notation\n")
bb46e94f 12367
718e3744 12368/* old command */
12369DEFUN (ipv6_mbgp_neighbor_advertised_route,
12370 ipv6_mbgp_neighbor_advertised_route_cmd,
856ca177 12371 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12372 SHOW_STR
12373 IPV6_STR
12374 MBGP_STR
12375 "Detailed information on TCP and BGP neighbor connections\n"
12376 "Neighbor to display information about\n"
12377 "Neighbor to display information about\n"
a80beece
DS
12378 "Neighbor on bgp configured interface\n"
12379 "Neighbor on bgp configured interface\n"
856ca177
MS
12380 "Display the routes advertised to a BGP neighbor\n"
12381 "JavaScript Object Notation\n")
718e3744 12382{
bb46e94f 12383 struct peer *peer;
db7c8528 12384 u_char uj = use_json(argc, argv);
856ca177 12385
db7c8528 12386 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 12387 if (! peer)
856ca177 12388 return CMD_WARNING;
bb46e94f 12389
47e9b292 12390 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 12391 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj);
718e3744 12392}
12393#endif /* HAVE_IPV6 */
6b0655a2 12394
8386ac43 12395DEFUN (show_bgp_instance_neighbor_received_routes,
12396 show_bgp_instance_neighbor_received_routes_cmd,
12397 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
0b16f239
DS
12398 SHOW_STR
12399 BGP_STR
8386ac43 12400 BGP_INSTANCE_HELP_STR
0b16f239
DS
12401 "Detailed information on TCP and BGP neighbor connections\n"
12402 "Neighbor to display information about\n"
12403 "Neighbor to display information about\n"
12404 "Neighbor on bgp configured interface\n"
856ca177
MS
12405 "Display the received routes from neighbor\n"
12406 "JavaScript Object Notation\n")
0b16f239
DS
12407{
12408 struct peer *peer;
db7c8528 12409 u_char uj = use_json(argc, argv);
856ca177 12410
50ef26d4 12411 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
0b16f239
DS
12412 if (! peer)
12413 return CMD_WARNING;
12414
db7c8528 12415 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj);
0b16f239
DS
12416}
12417
8386ac43 12418DEFUN (show_ip_bgp_instance_neighbor_received_routes,
12419 show_ip_bgp_instance_neighbor_received_routes_cmd,
12420 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 12421 SHOW_STR
12422 IP_STR
12423 BGP_STR
8386ac43 12424 BGP_INSTANCE_HELP_STR
718e3744 12425 "Detailed information on TCP and BGP neighbor connections\n"
12426 "Neighbor to display information about\n"
12427 "Neighbor to display information about\n"
a80beece 12428 "Neighbor on bgp configured interface\n"
856ca177
MS
12429 "Display the received routes from neighbor\n"
12430 "JavaScript Object Notation\n")
718e3744 12431{
bb46e94f 12432 struct peer *peer;
db7c8528 12433 u_char uj = use_json(argc, argv);
856ca177 12434
50ef26d4 12435 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
bb46e94f 12436 if (! peer)
12437 return CMD_WARNING;
12438
db7c8528 12439 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj);
718e3744 12440}
12441
8386ac43 12442ALIAS (show_bgp_instance_neighbor_received_routes,
12443 show_bgp_instance_ipv6_neighbor_received_routes_cmd,
12444 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
0b16f239
DS
12445 SHOW_STR
12446 BGP_STR
8386ac43 12447 BGP_INSTANCE_HELP_STR
0b16f239
DS
12448 "Address family\n"
12449 "Detailed information on TCP and BGP neighbor connections\n"
12450 "Neighbor to display information about\n"
12451 "Neighbor to display information about\n"
12452 "Neighbor on bgp configured interface\n"
856ca177
MS
12453 "Display the received routes from neighbor\n"
12454 "JavaScript Object Notation\n")
0b16f239
DS
12455
12456DEFUN (show_ip_bgp_neighbor_received_routes,
2a71e9ce 12457 show_ip_bgp_neighbor_received_routes_cmd,
856ca177 12458 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
2a71e9ce
TP
12459 SHOW_STR
12460 IP_STR
12461 BGP_STR
12462 "Detailed information on TCP and BGP neighbor connections\n"
12463 "Neighbor to display information about\n"
12464 "Neighbor to display information about\n"
a80beece 12465 "Neighbor on bgp configured interface\n"
856ca177
MS
12466 "Display the received routes from neighbor\n"
12467 "JavaScript Object Notation\n")
2a71e9ce 12468
0b16f239
DS
12469{
12470 struct peer *peer;
ffd0c037 12471 const char *rmap_name = NULL;
db7c8528 12472 u_char uj = use_json(argc, argv);
0b16f239 12473
db7c8528 12474 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
0b16f239
DS
12475
12476 if (! peer)
12477 return CMD_WARNING;
12478
856ca177 12479 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
0b16f239
DS
12480 rmap_name = argv[1];
12481
db7c8528 12482 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
0b16f239
DS
12483}
12484
12485ALIAS (show_ip_bgp_neighbor_received_routes,
12486 show_ip_bgp_neighbor_received_routes_rmap_cmd,
856ca177 12487 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
0b16f239
DS
12488 SHOW_STR
12489 IP_STR
12490 BGP_STR
12491 "Detailed information on TCP and BGP neighbor connections\n"
12492 "Neighbor to display information about\n"
12493 "Neighbor to display information about\n"
12494 "Neighbor on bgp configured interface\n"
856ca177
MS
12495 "Display the received routes from neighbor\n"
12496 "JavaScript Object Notation\n")
0b16f239 12497
8386ac43 12498ALIAS (show_ip_bgp_instance_neighbor_received_routes,
12499 show_ip_bgp_instance_neighbor_received_routes_rmap_cmd,
12500 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
50ef26d4 12501 SHOW_STR
12502 IP_STR
12503 BGP_STR
8386ac43 12504 BGP_INSTANCE_HELP_STR
50ef26d4 12505 "Detailed information on TCP and BGP neighbor connections\n"
12506 "Neighbor to display information about\n"
12507 "Neighbor to display information about\n"
12508 "Neighbor on bgp configured interface\n"
12509 "Display the received routes from neighbor\n"
12510 "JavaScript Object Notation\n")
12511
718e3744 12512DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12513 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
856ca177 12514 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 12515 SHOW_STR
12516 IP_STR
12517 BGP_STR
12518 "Address family\n"
12519 "Address Family modifier\n"
12520 "Address Family modifier\n"
12521 "Detailed information on TCP and BGP neighbor connections\n"
12522 "Neighbor to display information about\n"
12523 "Neighbor to display information about\n"
a80beece 12524 "Neighbor on bgp configured interface\n"
856ca177
MS
12525 "Display the received routes from neighbor\n"
12526 "JavaScript Object Notation\n")
718e3744 12527{
bb46e94f 12528 struct peer *peer;
ffd0c037 12529 const char *rmap_name = NULL;
db7c8528 12530 u_char uj = use_json(argc, argv);
bb46e94f 12531
db7c8528 12532 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 12533 if (! peer)
12534 return CMD_WARNING;
0b16f239 12535
856ca177 12536 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
0b16f239
DS
12537 rmap_name = argv[2];
12538
718e3744 12539 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 12540 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name, uj);
856ca177 12541 else
db7c8528 12542 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
718e3744 12543}
12544
0b16f239
DS
12545ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
12546 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
856ca177 12547 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
0b16f239
DS
12548 SHOW_STR
12549 IP_STR
12550 BGP_STR
12551 "Address family\n"
12552 "Address Family modifier\n"
12553 "Address Family modifier\n"
12554 "Detailed information on TCP and BGP neighbor connections\n"
12555 "Neighbor to display information about\n"
12556 "Neighbor to display information about\n"
12557 "Neighbor on bgp configured interface\n"
856ca177
MS
12558 "Display the received routes from neighbor\n"
12559 "JavaScript Object Notation\n")
0b16f239 12560
8386ac43 12561DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes,
12562 show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd,
8386ac43 12563 "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
12564 SHOW_STR
12565 BGP_STR
8386ac43 12566 BGP_INSTANCE_HELP_STR
95cbbd2a 12567 "Address family\n"
95cbbd2a 12568 "Address family\n"
95cbbd2a
ML
12569 "Address family modifier\n"
12570 "Address family modifier\n"
12571 "Detailed information on TCP and BGP neighbor connections\n"
12572 "Neighbor to display information about\n"
12573 "Neighbor to display information about\n"
a80beece 12574 "Neighbor on bgp configured interface\n"
95cbbd2a 12575 "Display the advertised routes to neighbor\n"
856ca177
MS
12576 "Display the received routes from neighbor\n"
12577 "JavaScript Object Notation\n")
95cbbd2a
ML
12578{
12579 int afi;
12580 int safi;
12581 int in;
12582 struct peer *peer;
db7c8528 12583 u_char uj = use_json(argc, argv);
856ca177 12584
6aeb9e78 12585 peer = peer_lookup_in_view (vty, argv[1], argv[4], uj);
95cbbd2a
ML
12586
12587 if (! peer)
12588 return CMD_WARNING;
12589
6aeb9e78
DS
12590 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
12591 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12592 in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0;
95cbbd2a 12593
db7c8528 12594 return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj);
95cbbd2a
ML
12595}
12596
718e3744 12597DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12598 show_ip_bgp_neighbor_received_prefix_filter_cmd,
856ca177 12599 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 12600 SHOW_STR
12601 IP_STR
12602 BGP_STR
12603 "Detailed information on TCP and BGP neighbor connections\n"
12604 "Neighbor to display information about\n"
12605 "Neighbor to display information about\n"
a80beece 12606 "Neighbor on bgp configured interface\n"
718e3744 12607 "Display information received from a BGP neighbor\n"
856ca177
MS
12608 "Display the prefixlist filter\n"
12609 "JavaScript Object Notation\n")
718e3744 12610{
12611 char name[BUFSIZ];
c63b83fe 12612 union sockunion su;
718e3744 12613 struct peer *peer;
c63b83fe 12614 int count, ret;
db7c8528 12615 u_char uj = use_json(argc, argv);
718e3744 12616
c63b83fe
JBD
12617 ret = str2sockunion (argv[0], &su);
12618 if (ret < 0)
12619 {
a80beece 12620 peer = peer_lookup_by_conf_if (NULL, argv[0]);
856ca177 12621 if (! peer)
a80beece 12622 {
db7c8528 12623 if (uj)
856ca177
MS
12624 {
12625 json_object *json_no = NULL;
12626 json_object *json_sub = NULL;
12627 json_no = json_object_new_object();
12628 json_sub = json_object_new_object();
12629 json_object_string_add(json_no, "warning", "Malformed address or name");
12630 json_object_string_add(json_sub, "warningCause", argv[0]);
12631 json_object_object_add(json_no, "detail", json_sub);
12632 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12633 json_object_free(json_no);
12634 }
12635 else
12636 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
a80beece
DS
12637 return CMD_WARNING;
12638 }
12639 }
12640 else
12641 {
12642 peer = peer_lookup (NULL, &su);
12643 if (! peer)
856ca177 12644 {
db7c8528 12645 if (uj)
856ca177
MS
12646 {
12647 json_object *json_no = NULL;
12648 json_no = json_object_new_object();
12649 json_object_string_add(json_no, "warning", "Peer not found");
12650 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12651 json_object_free(json_no);
12652 }
12653 else
12654 vty_out (vty, "No peer%s", VTY_NEWLINE);
12655 return CMD_WARNING;
12656 }
c63b83fe 12657 }
718e3744 12658
12659 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
db7c8528 12660 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
718e3744 12661 if (count)
12662 {
db7c8528 12663 if (!uj)
856ca177 12664 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
db7c8528 12665 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
856ca177
MS
12666 }
12667 else
12668 {
db7c8528 12669 if (uj)
856ca177
MS
12670 {
12671 json_object *json_no = NULL;
12672 json_no = json_object_new_object();
12673 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12674 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12675 json_object_free(json_no);
12676 }
12677 else
12678 vty_out (vty, "No functional output%s", VTY_NEWLINE);
718e3744 12679 }
12680
12681 return CMD_SUCCESS;
12682}
12683
12684DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
12685 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
856ca177 12686 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 12687 SHOW_STR
12688 IP_STR
12689 BGP_STR
12690 "Address family\n"
12691 "Address Family modifier\n"
12692 "Address Family modifier\n"
12693 "Detailed information on TCP and BGP neighbor connections\n"
12694 "Neighbor to display information about\n"
12695 "Neighbor to display information about\n"
a80beece 12696 "Neighbor on bgp configured interface\n"
718e3744 12697 "Display information received from a BGP neighbor\n"
856ca177
MS
12698 "Display the prefixlist filter\n"
12699 "JavaScript Object Notation\n")
718e3744 12700{
12701 char name[BUFSIZ];
c63b83fe 12702 union sockunion su;
718e3744 12703 struct peer *peer;
c63b83fe 12704 int count, ret;
db7c8528 12705 u_char uj = use_json(argc, argv);
718e3744 12706
c63b83fe
JBD
12707 ret = str2sockunion (argv[1], &su);
12708 if (ret < 0)
12709 {
a80beece 12710 peer = peer_lookup_by_conf_if (NULL, argv[1]);
856ca177 12711 if (! peer)
a80beece 12712 {
db7c8528 12713 if (uj)
856ca177
MS
12714 {
12715 json_object *json_no = NULL;
12716 json_object *json_sub = NULL;
12717 json_no = json_object_new_object();
12718 json_sub = json_object_new_object();
12719 json_object_string_add(json_no, "warning", "Malformed address or name");
12720 json_object_string_add(json_sub, "warningCause", argv[1]);
12721 json_object_object_add(json_no, "detail", json_sub);
12722 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12723 json_object_free(json_no);
12724 }
12725 else
12726 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
a80beece
DS
12727 return CMD_WARNING;
12728 }
12729 }
12730 else
12731 {
12732 peer = peer_lookup (NULL, &su);
12733 if (! peer)
856ca177 12734 {
db7c8528 12735 if (uj)
856ca177
MS
12736 {
12737 json_object *json_no = NULL;
12738 json_no = json_object_new_object();
12739 json_object_string_add(json_no, "warning", "Peer not found");
12740 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12741 json_object_free(json_no);
12742 }
12743 else
12744 vty_out (vty, "No peer%s", VTY_NEWLINE);
12745 return CMD_WARNING;
12746 }
c63b83fe 12747 }
718e3744 12748
12749 if (strncmp (argv[0], "m", 1) == 0)
12750 {
12751 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
db7c8528 12752 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
718e3744 12753 if (count)
856ca177 12754 {
db7c8528 12755 if (!uj)
856ca177 12756 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
db7c8528 12757 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
856ca177
MS
12758 }
12759 else
12760 {
db7c8528 12761 if (uj)
856ca177
MS
12762 {
12763 json_object *json_no = NULL;
12764 json_no = json_object_new_object();
12765 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12766 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12767 json_object_free(json_no);
12768 }
12769 else
12770 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12771 }
718e3744 12772 }
12773 else
12774 {
12775 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
db7c8528 12776 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
718e3744 12777 if (count)
856ca177 12778 {
db7c8528 12779 if (!uj)
856ca177 12780 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
db7c8528 12781 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
856ca177
MS
12782 }
12783 else
12784 {
db7c8528 12785 if (uj)
856ca177
MS
12786 {
12787 json_object *json_no = NULL;
12788 json_no = json_object_new_object();
12789 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12790 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12791 json_object_free(json_no);
12792 }
12793 else
12794 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12795 }
718e3744 12796 }
12797
12798 return CMD_SUCCESS;
12799}
718e3744 12800#ifdef HAVE_IPV6
50ef26d4 12801DEFUN (show_bgp_neighbor_received_routes,
718e3744 12802 show_bgp_neighbor_received_routes_cmd,
856ca177 12803 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 12804 SHOW_STR
12805 BGP_STR
12806 "Detailed information on TCP and BGP neighbor connections\n"
12807 "Neighbor to display information about\n"
12808 "Neighbor to display information about\n"
a80beece 12809 "Neighbor on bgp configured interface\n"
856ca177
MS
12810 "Display the received routes from neighbor\n"
12811 "JavaScript Object Notation\n")
50ef26d4 12812{
12813 struct peer *peer;
12814 const char *rmap_name = NULL;
12815 u_char uj = use_json(argc, argv);
718e3744 12816
50ef26d4 12817 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12818
12819 if (! peer)
12820 return CMD_WARNING;
12821
12822 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12823 rmap_name = argv[1];
12824
12825 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, rmap_name, uj);
12826}
12827
12828ALIAS (show_bgp_neighbor_received_routes,
718e3744 12829 show_bgp_ipv6_neighbor_received_routes_cmd,
856ca177 12830 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
0b16f239
DS
12831 SHOW_STR
12832 BGP_STR
12833 "Address family\n"
12834 "Detailed information on TCP and BGP neighbor connections\n"
12835 "Neighbor to display information about\n"
12836 "Neighbor to display information about\n"
12837 "Neighbor on bgp configured interface\n"
856ca177
MS
12838 "Display the received routes from neighbor\n"
12839 "JavaScript Object Notation\n")
0b16f239 12840
718e3744 12841DEFUN (show_bgp_neighbor_received_prefix_filter,
12842 show_bgp_neighbor_received_prefix_filter_cmd,
856ca177 12843 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 12844 SHOW_STR
12845 BGP_STR
12846 "Detailed information on TCP and BGP neighbor connections\n"
12847 "Neighbor to display information about\n"
12848 "Neighbor to display information about\n"
a80beece 12849 "Neighbor on bgp configured interface\n"
718e3744 12850 "Display information received from a BGP neighbor\n"
856ca177
MS
12851 "Display the prefixlist filter\n"
12852 "JavaScript Object Notation\n")
718e3744 12853{
12854 char name[BUFSIZ];
c63b83fe 12855 union sockunion su;
718e3744 12856 struct peer *peer;
c63b83fe 12857 int count, ret;
db7c8528 12858 u_char uj = use_json(argc, argv);
718e3744 12859
c63b83fe
JBD
12860 ret = str2sockunion (argv[0], &su);
12861 if (ret < 0)
12862 {
a80beece 12863 peer = peer_lookup_by_conf_if (NULL, argv[0]);
856ca177 12864 if (! peer)
a80beece 12865 {
db7c8528 12866 if (uj)
856ca177
MS
12867 {
12868 json_object *json_no = NULL;
12869 json_object *json_sub = NULL;
12870 json_no = json_object_new_object();
12871 json_sub = json_object_new_object();
12872 json_object_string_add(json_no, "warning", "Malformed address or name");
12873 json_object_string_add(json_sub, "warningCause", argv[0]);
12874 json_object_object_add(json_no, "detail", json_sub);
12875 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12876 json_object_free(json_no);
12877 }
12878 else
12879 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
a80beece
DS
12880 return CMD_WARNING;
12881 }
12882 }
12883 else
12884 {
12885 peer = peer_lookup (NULL, &su);
12886 if (! peer)
856ca177 12887 {
db7c8528 12888 if (uj)
856ca177
MS
12889 {
12890 json_object *json_no = NULL;
12891 json_no = json_object_new_object();
12892 json_object_string_add(json_no, "warning", "No Peer");
12893 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12894 json_object_free(json_no);
12895 }
12896 else
12897 vty_out (vty, "No peer%s", VTY_NEWLINE);
12898 return CMD_WARNING;
12899 }
c63b83fe 12900 }
718e3744 12901
12902 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
db7c8528 12903 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
718e3744 12904 if (count)
12905 {
db7c8528 12906 if (!uj)
856ca177 12907 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
db7c8528 12908 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
856ca177
MS
12909 }
12910 else
12911 {
db7c8528 12912 if (uj)
856ca177
MS
12913 {
12914 json_object *json_no = NULL;
12915 json_no = json_object_new_object();
12916 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12917 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12918 json_object_free(json_no);
12919 }
12920 else
12921 vty_out (vty, "No functional output%s", VTY_NEWLINE);
718e3744 12922 }
12923
12924 return CMD_SUCCESS;
12925}
12926
12927ALIAS (show_bgp_neighbor_received_prefix_filter,
12928 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
856ca177 12929 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 12930 SHOW_STR
12931 BGP_STR
12932 "Address family\n"
12933 "Detailed information on TCP and BGP neighbor connections\n"
12934 "Neighbor to display information about\n"
12935 "Neighbor to display information about\n"
a80beece 12936 "Neighbor on bgp configured interface\n"
718e3744 12937 "Display information received from a BGP neighbor\n"
856ca177
MS
12938 "Display the prefixlist filter\n"
12939 "JavaScript Object Notation\n")
718e3744 12940
12941/* old command */
50ef26d4 12942ALIAS (show_bgp_neighbor_received_routes,
718e3744 12943 ipv6_bgp_neighbor_received_routes_cmd,
856ca177 12944 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 12945 SHOW_STR
12946 IPV6_STR
12947 BGP_STR
12948 "Detailed information on TCP and BGP neighbor connections\n"
12949 "Neighbor to display information about\n"
12950 "Neighbor to display information about\n"
a80beece 12951 "Neighbor on bgp configured interface\n"
856ca177
MS
12952 "Display the received routes from neighbor\n"
12953 "JavaScript Object Notation\n")
718e3744 12954
12955/* old command */
12956DEFUN (ipv6_mbgp_neighbor_received_routes,
12957 ipv6_mbgp_neighbor_received_routes_cmd,
856ca177 12958 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 12959 SHOW_STR
12960 IPV6_STR
12961 MBGP_STR
12962 "Detailed information on TCP and BGP neighbor connections\n"
12963 "Neighbor to display information about\n"
12964 "Neighbor to display information about\n"
a80beece 12965 "Neighbor on bgp configured interface\n"
856ca177
MS
12966 "Display the received routes from neighbor\n"
12967 "JavaScript Object Notation\n")
718e3744 12968{
bb46e94f 12969 struct peer *peer;
db7c8528 12970 u_char uj = use_json(argc, argv);
bb46e94f 12971
db7c8528 12972 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 12973 if (! peer)
12974 return CMD_WARNING;
12975
47e9b292 12976 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 12977 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj);
bb46e94f 12978}
12979
8386ac43 12980DEFUN (show_bgp_instance_neighbor_received_prefix_filter,
12981 show_bgp_instance_neighbor_received_prefix_filter_cmd,
12982 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
bb46e94f 12983 SHOW_STR
12984 BGP_STR
8386ac43 12985 BGP_INSTANCE_HELP_STR
bb46e94f 12986 "Detailed information on TCP and BGP neighbor connections\n"
12987 "Neighbor to display information about\n"
12988 "Neighbor to display information about\n"
a80beece 12989 "Neighbor on bgp configured interface\n"
bb46e94f 12990 "Display information received from a BGP neighbor\n"
856ca177
MS
12991 "Display the prefixlist filter\n"
12992 "JavaScript Object Notation\n")
bb46e94f 12993{
12994 char name[BUFSIZ];
c63b83fe 12995 union sockunion su;
bb46e94f 12996 struct peer *peer;
12997 struct bgp *bgp;
c63b83fe 12998 int count, ret;
db7c8528 12999 u_char uj = use_json(argc, argv);
bb46e94f 13000
13001 /* BGP structure lookup. */
6aeb9e78 13002 bgp = bgp_lookup_by_name (argv[1]);
bb46e94f 13003 if (bgp == NULL)
856ca177 13004 {
db7c8528 13005 if (uj)
856ca177
MS
13006 {
13007 json_object *json_no = NULL;
13008 json_no = json_object_new_object();
13009 json_object_string_add(json_no, "warning", "Can't find BGP view");
13010 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13011 json_object_free(json_no);
13012 }
13013 else
6aeb9e78 13014 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
856ca177
MS
13015 return CMD_WARNING;
13016 }
13017
6aeb9e78 13018 ret = str2sockunion (argv[2], &su);
c63b83fe
JBD
13019 if (ret < 0)
13020 {
6aeb9e78 13021 peer = peer_lookup_by_conf_if (bgp, argv[2]);
856ca177 13022 if (! peer)
a80beece 13023 {
db7c8528 13024 if (uj)
856ca177
MS
13025 {
13026 json_object *json_no = NULL;
13027 json_object *json_sub = NULL;
13028 json_no = json_object_new_object();
13029 json_sub = json_object_new_object();
13030 json_object_string_add(json_no, "warning", "Malformed address or name");
6aeb9e78 13031 json_object_string_add(json_sub, "warningCause", argv[2]);
856ca177
MS
13032 json_object_object_add(json_no, "detail", json_sub);
13033 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13034 json_object_free(json_no);
13035 }
13036 else
6aeb9e78 13037 vty_out (vty, "%% Malformed address or name: %s%s", argv[2], VTY_NEWLINE);
a80beece
DS
13038 return CMD_WARNING;
13039 }
13040 }
13041 else
13042 {
13043 peer = peer_lookup (bgp, &su);
13044 if (! peer)
856ca177 13045 {
db7c8528 13046 if (uj)
856ca177
MS
13047 {
13048 json_object *json_no = NULL;
13049 json_no = json_object_new_object();
13050 json_object_boolean_true_add(json_no, "noPeer");
13051 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13052 json_object_free(json_no);
13053 }
13054 else
13055 vty_out (vty, "No peer%s", VTY_NEWLINE);
13056 return CMD_WARNING;
13057 }
13058
c63b83fe 13059 }
bb46e94f 13060
13061 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
db7c8528 13062 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
bb46e94f 13063 if (count)
13064 {
db7c8528 13065 if (!uj)
856ca177 13066 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
db7c8528 13067 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
bb46e94f 13068 }
13069
13070 return CMD_SUCCESS;
718e3744 13071}
8386ac43 13072ALIAS (show_bgp_instance_neighbor_received_prefix_filter,
13073 show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd,
13074 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
bb46e94f 13075 SHOW_STR
13076 BGP_STR
8386ac43 13077 BGP_INSTANCE_HELP_STR
bb46e94f 13078 "Address family\n"
13079 "Detailed information on TCP and BGP neighbor connections\n"
13080 "Neighbor to display information about\n"
13081 "Neighbor to display information about\n"
a80beece 13082 "Neighbor on bgp configured interface\n"
bb46e94f 13083 "Display information received from a BGP neighbor\n"
856ca177
MS
13084 "Display the prefixlist filter\n"
13085 "JavaScript Object NOtation\n")
718e3744 13086#endif /* HAVE_IPV6 */
6b0655a2 13087
94f2b392 13088static int
bb46e94f 13089bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
856ca177 13090 safi_t safi, enum bgp_show_type type, u_char use_json)
718e3744 13091{
718e3744 13092 if (! peer || ! peer->afc[afi][safi])
13093 {
856ca177
MS
13094 if (use_json)
13095 {
13096 json_object *json_no = NULL;
13097 json_no = json_object_new_object();
13098 json_object_string_add(json_no, "warning", "No such neighbor or address family");
13099 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13100 json_object_free(json_no);
13101 }
13102 else
13103 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
718e3744 13104 return CMD_WARNING;
13105 }
47fc97cc 13106
856ca177 13107 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json);
718e3744 13108}
13109
13110DEFUN (show_ip_bgp_neighbor_routes,
13111 show_ip_bgp_neighbor_routes_cmd,
856ca177 13112 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13113 SHOW_STR
13114 IP_STR
13115 BGP_STR
13116 "Detailed information on TCP and BGP neighbor connections\n"
13117 "Neighbor to display information about\n"
13118 "Neighbor to display information about\n"
a80beece 13119 "Neighbor on bgp configured interface\n"
856ca177
MS
13120 "Display routes learned from neighbor\n"
13121 "JavaScript Object Notation\n")
718e3744 13122{
bb46e94f 13123 struct peer *peer;
db7c8528 13124 u_char uj = use_json(argc, argv);
856ca177 13125
db7c8528 13126 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 13127 if (! peer)
13128 return CMD_WARNING;
13129
13130 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 13131 bgp_show_type_neighbor, uj);
718e3744 13132}
13133
8386ac43 13134DEFUN (show_ip_bgp_instance_neighbor_routes,
13135 show_ip_bgp_instance_neighbor_routes_cmd,
13136 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
50ef26d4 13137 SHOW_STR
13138 IP_STR
13139 BGP_STR
8386ac43 13140 BGP_INSTANCE_HELP_STR
50ef26d4 13141 "Detailed information on TCP and BGP neighbor connections\n"
13142 "Neighbor to display information about\n"
13143 "Neighbor to display information about\n"
13144 "Neighbor on bgp configured interface\n"
13145 "Display routes learned from neighbor\n"
13146 "JavaScript Object Notation\n")
13147{
13148 struct peer *peer;
13149 u_char uj = use_json(argc, argv);
13150
13151 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13152 if (! peer)
13153 return CMD_WARNING;
13154
13155 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13156 bgp_show_type_neighbor, uj);
13157}
13158
718e3744 13159DEFUN (show_ip_bgp_neighbor_flap,
13160 show_ip_bgp_neighbor_flap_cmd,
856ca177 13161 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
718e3744 13162 SHOW_STR
13163 IP_STR
13164 BGP_STR
13165 "Detailed information on TCP and BGP neighbor connections\n"
13166 "Neighbor to display information about\n"
13167 "Neighbor to display information about\n"
a80beece 13168 "Neighbor on bgp configured interface\n"
856ca177
MS
13169 "Display flap statistics of the routes learned from neighbor\n"
13170 "JavaScript Object Notation\n")
718e3744 13171{
bb46e94f 13172 struct peer *peer;
db7c8528 13173 u_char uj = use_json(argc, argv);
856ca177 13174
db7c8528 13175 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 13176 if (! peer)
13177 return CMD_WARNING;
13178
13179 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 13180 bgp_show_type_flap_neighbor, uj);
718e3744 13181}
13182
13183DEFUN (show_ip_bgp_neighbor_damp,
13184 show_ip_bgp_neighbor_damp_cmd,
856ca177 13185 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
718e3744 13186 SHOW_STR
13187 IP_STR
13188 BGP_STR
13189 "Detailed information on TCP and BGP neighbor connections\n"
13190 "Neighbor to display information about\n"
13191 "Neighbor to display information about\n"
a80beece 13192 "Neighbor on bgp configured interface\n"
856ca177
MS
13193 "Display the dampened routes received from neighbor\n"
13194 "JavaScript Object Notation\n")
718e3744 13195{
bb46e94f 13196 struct peer *peer;
db7c8528 13197 u_char uj = use_json(argc, argv);
856ca177 13198
db7c8528 13199 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 13200 if (! peer)
13201 return CMD_WARNING;
13202
13203 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 13204 bgp_show_type_damp_neighbor, uj);
718e3744 13205}
13206
13207DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13208 show_ip_bgp_ipv4_neighbor_routes_cmd,
856ca177 13209 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13210 SHOW_STR
13211 IP_STR
13212 BGP_STR
13213 "Address family\n"
13214 "Address Family modifier\n"
13215 "Address Family modifier\n"
13216 "Detailed information on TCP and BGP neighbor connections\n"
13217 "Neighbor to display information about\n"
13218 "Neighbor to display information about\n"
a80beece 13219 "Neighbor on bgp configured interface\n"
856ca177
MS
13220 "Display routes learned from neighbor\n"
13221 "JavaScript Object Notation\n")
718e3744 13222{
bb46e94f 13223 struct peer *peer;
db7c8528 13224 u_char uj = use_json(argc, argv);
bb46e94f 13225
db7c8528 13226 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 13227 if (! peer)
13228 return CMD_WARNING;
13229
718e3744 13230 if (strncmp (argv[0], "m", 1) == 0)
bb46e94f 13231 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
db7c8528 13232 bgp_show_type_neighbor, uj);
718e3744 13233
bb46e94f 13234 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 13235 bgp_show_type_neighbor, uj);
718e3744 13236}
bb46e94f 13237
2a3d5731 13238#ifdef HAVE_IPV6
8386ac43 13239DEFUN (show_bgp_instance_neighbor_routes,
13240 show_bgp_instance_neighbor_routes_cmd,
13241 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
fee0f4c6 13242 SHOW_STR
fee0f4c6 13243 BGP_STR
8386ac43 13244 BGP_INSTANCE_HELP_STR
2a3d5731
DW
13245 "Detailed information on TCP and BGP neighbor connections\n"
13246 "Neighbor to display information about\n"
13247 "Neighbor to display information about\n"
13248 "Neighbor on bgp configured interface\n"
13249 "Display routes learned from neighbor\n"
13250 "JavaScript Object Notation\n")
fee0f4c6 13251{
fee0f4c6 13252 struct peer *peer;
db7c8528 13253 u_char uj = use_json(argc, argv);
fee0f4c6 13254
50ef26d4 13255 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
fee0f4c6 13256 if (! peer)
13257 return CMD_WARNING;
13258
2a3d5731 13259 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
db7c8528 13260 bgp_show_type_neighbor, uj);
fee0f4c6 13261}
13262
8386ac43 13263ALIAS (show_bgp_instance_neighbor_routes,
13264 show_bgp_instance_ipv6_neighbor_routes_cmd,
13265 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
fee0f4c6 13266 SHOW_STR
fee0f4c6 13267 BGP_STR
8386ac43 13268 BGP_INSTANCE_HELP_STR
2a3d5731
DW
13269 "Address family\n"
13270 "Detailed information on TCP and BGP neighbor connections\n"
13271 "Neighbor to display information about\n"
13272 "Neighbor to display information about\n"
13273 "Neighbor on bgp configured interface\n"
13274 "Display routes learned from neighbor\n"
13275 "JavaScript Object Notation\n")
fee0f4c6 13276
8386ac43 13277DEFUN (show_bgp_instance_neighbor_damp,
13278 show_bgp_instance_neighbor_damp_cmd,
13279 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
fee0f4c6 13280 SHOW_STR
fee0f4c6 13281 BGP_STR
8386ac43 13282 BGP_INSTANCE_HELP_STR
2a3d5731
DW
13283 "Detailed information on TCP and BGP neighbor connections\n"
13284 "Neighbor to display information about\n"
13285 "Neighbor to display information about\n"
13286 "Neighbor on bgp configured interface\n"
13287 "Display the dampened routes received from neighbor\n"
13288 "JavaScript Object Notation\n")
bb46e94f 13289{
13290 struct peer *peer;
db7c8528 13291 u_char uj = use_json(argc, argv);
856ca177 13292
6aeb9e78
DS
13293 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13294 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13295 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
bb46e94f 13296 else
6aeb9e78 13297 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 13298
13299 if (! peer)
13300 return CMD_WARNING;
13301
13302 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
db7c8528 13303 bgp_show_type_damp_neighbor, uj);
bb46e94f 13304}
13305
8386ac43 13306ALIAS (show_bgp_instance_neighbor_damp,
13307 show_bgp_instance_ipv6_neighbor_damp_cmd,
13308 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
bb46e94f 13309 SHOW_STR
13310 BGP_STR
8386ac43 13311 BGP_INSTANCE_HELP_STR
bb46e94f 13312 "Address family\n"
13313 "Detailed information on TCP and BGP neighbor connections\n"
13314 "Neighbor to display information about\n"
13315 "Neighbor to display information about\n"
a80beece 13316 "Neighbor on bgp configured interface\n"
856ca177
MS
13317 "Display the dampened routes received from neighbor\n"
13318 "JavaScript Object Notation\n")
bb46e94f 13319
8386ac43 13320DEFUN (show_bgp_instance_neighbor_flap,
13321 show_bgp_instance_neighbor_flap_cmd,
13322 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 13323 SHOW_STR
13324 BGP_STR
8386ac43 13325 BGP_INSTANCE_HELP_STR
bb46e94f 13326 "Detailed information on TCP and BGP neighbor connections\n"
13327 "Neighbor to display information about\n"
13328 "Neighbor to display information about\n"
a80beece 13329 "Neighbor on bgp configured interface\n"
856ca177
MS
13330 "Display flap statistics of the routes learned from neighbor\n"
13331 "JavaScript Object Notation\n")
bb46e94f 13332{
13333 struct peer *peer;
db7c8528 13334 u_char uj = use_json(argc, argv);
856ca177 13335
6aeb9e78
DS
13336 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13337 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13338 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
bb46e94f 13339 else
6aeb9e78 13340 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 13341
13342 if (! peer)
13343 return CMD_WARNING;
13344
13345 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
db7c8528 13346 bgp_show_type_flap_neighbor, uj);
bb46e94f 13347}
13348
8386ac43 13349ALIAS (show_bgp_instance_neighbor_flap,
13350 show_bgp_instance_ipv6_neighbor_flap_cmd,
13351 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 13352 SHOW_STR
13353 BGP_STR
8386ac43 13354 BGP_INSTANCE_HELP_STR
bb46e94f 13355 "Address family\n"
13356 "Detailed information on TCP and BGP neighbor connections\n"
13357 "Neighbor to display information about\n"
13358 "Neighbor to display information about\n"
a80beece 13359 "Neighbor on bgp configured interface\n"
856ca177
MS
13360 "Display flap statistics of the routes learned from neighbor\n"
13361 "JavaScript Object Notation\n")
bb46e94f 13362
50ef26d4 13363DEFUN (show_bgp_neighbor_routes,
bb46e94f 13364 show_bgp_neighbor_routes_cmd,
856ca177 13365 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
bb46e94f 13366 SHOW_STR
13367 BGP_STR
13368 "Detailed information on TCP and BGP neighbor connections\n"
13369 "Neighbor to display information about\n"
13370 "Neighbor to display information about\n"
a80beece 13371 "Neighbor on bgp configured interface\n"
856ca177
MS
13372 "Display routes learned from neighbor\n"
13373 "JavaScript Object Notation\n")
50ef26d4 13374{
13375 struct peer *peer;
13376 u_char uj = use_json(argc, argv);
bb46e94f 13377
50ef26d4 13378 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13379 if (! peer)
13380 return CMD_WARNING;
bb46e94f 13381
50ef26d4 13382 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13383 bgp_show_type_neighbor, uj);
13384}
13385
13386
13387ALIAS (show_bgp_neighbor_routes,
718e3744 13388 show_bgp_ipv6_neighbor_routes_cmd,
856ca177 13389 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13390 SHOW_STR
13391 BGP_STR
13392 "Address family\n"
13393 "Detailed information on TCP and BGP neighbor connections\n"
13394 "Neighbor to display information about\n"
13395 "Neighbor to display information about\n"
a80beece 13396 "Neighbor on bgp configured interface\n"
856ca177
MS
13397 "Display routes learned from neighbor\n"
13398 "JavaScript Object Notation\n")
718e3744 13399
13400/* old command */
50ef26d4 13401ALIAS (show_bgp_neighbor_routes,
718e3744 13402 ipv6_bgp_neighbor_routes_cmd,
856ca177 13403 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13404 SHOW_STR
13405 IPV6_STR
13406 BGP_STR
13407 "Detailed information on TCP and BGP neighbor connections\n"
13408 "Neighbor to display information about\n"
13409 "Neighbor to display information about\n"
a80beece 13410 "Neighbor on bgp configured interface\n"
856ca177
MS
13411 "Display routes learned from neighbor\n"
13412 "JavaScript Object Notation\n")
718e3744 13413
13414/* old command */
13415DEFUN (ipv6_mbgp_neighbor_routes,
13416 ipv6_mbgp_neighbor_routes_cmd,
856ca177 13417 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13418 SHOW_STR
13419 IPV6_STR
13420 MBGP_STR
13421 "Detailed information on TCP and BGP neighbor connections\n"
13422 "Neighbor to display information about\n"
13423 "Neighbor to display information about\n"
a80beece 13424 "Neighbor on bgp configured interface\n"
856ca177
MS
13425 "Display routes learned from neighbor\n"
13426 "JavaScript Object Notation\n")
718e3744 13427{
bb46e94f 13428 struct peer *peer;
db7c8528 13429 u_char uj = use_json(argc, argv);
bb46e94f 13430
db7c8528 13431 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 13432 if (! peer)
13433 return CMD_WARNING;
13434
47e9b292 13435 bgp_show_ipv6_bgp_deprecate_warning(vty);
bb46e94f 13436 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
db7c8528 13437 bgp_show_type_neighbor, uj);
718e3744 13438}
bb46e94f 13439
8386ac43 13440ALIAS (show_bgp_instance_neighbor_flap,
bb46e94f 13441 show_bgp_neighbor_flap_cmd,
856ca177 13442 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 13443 SHOW_STR
13444 BGP_STR
13445 "Detailed information on TCP and BGP neighbor connections\n"
13446 "Neighbor to display information about\n"
13447 "Neighbor to display information about\n"
a80beece 13448 "Neighbor on bgp configured interface\n"
856ca177
MS
13449 "Display flap statistics of the routes learned from neighbor\n"
13450 "JavaScript Object Notation\n")
bb46e94f 13451
8386ac43 13452ALIAS (show_bgp_instance_neighbor_flap,
bb46e94f 13453 show_bgp_ipv6_neighbor_flap_cmd,
856ca177 13454 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 13455 SHOW_STR
13456 BGP_STR
13457 "Address family\n"
13458 "Detailed information on TCP and BGP neighbor connections\n"
13459 "Neighbor to display information about\n"
13460 "Neighbor to display information about\n"
a80beece 13461 "Neighbor on bgp configured interface\n"
856ca177
MS
13462 "Display flap statistics of the routes learned from neighbor\n"
13463 "JavaScript Object Notation\n")
bb46e94f 13464
8386ac43 13465ALIAS (show_bgp_instance_neighbor_damp,
bb46e94f 13466 show_bgp_neighbor_damp_cmd,
856ca177 13467 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
bb46e94f 13468 SHOW_STR
13469 BGP_STR
13470 "Detailed information on TCP and BGP neighbor connections\n"
13471 "Neighbor to display information about\n"
13472 "Neighbor to display information about\n"
a80beece 13473 "Neighbor on bgp configured interface\n"
856ca177
MS
13474 "Display the dampened routes received from neighbor\n"
13475 "JavaScript Object Notation\n")
bb46e94f 13476
8386ac43 13477ALIAS (show_bgp_instance_neighbor_damp,
bb46e94f 13478 show_bgp_ipv6_neighbor_damp_cmd,
856ca177 13479 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
bb46e94f 13480 SHOW_STR
13481 BGP_STR
13482 "Address family\n"
13483 "Detailed information on TCP and BGP neighbor connections\n"
13484 "Neighbor to display information about\n"
13485 "Neighbor to display information about\n"
a80beece 13486 "Neighbor on bgp configured interface\n"
856ca177
MS
13487 "Display the dampened routes received from neighbor\n"
13488 "JavaScript Object Notation\n")
fee0f4c6 13489
718e3744 13490#endif /* HAVE_IPV6 */
6b0655a2 13491
718e3744 13492struct bgp_table *bgp_distance_table;
13493
13494struct bgp_distance
13495{
13496 /* Distance value for the IP source prefix. */
13497 u_char distance;
13498
13499 /* Name of the access-list to be matched. */
13500 char *access_list;
13501};
13502
94f2b392 13503static struct bgp_distance *
66e5cd87 13504bgp_distance_new (void)
718e3744 13505{
393deb9b 13506 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
718e3744 13507}
13508
94f2b392 13509static void
718e3744 13510bgp_distance_free (struct bgp_distance *bdistance)
13511{
13512 XFREE (MTYPE_BGP_DISTANCE, bdistance);
13513}
13514
94f2b392 13515static int
fd79ac91 13516bgp_distance_set (struct vty *vty, const char *distance_str,
13517 const char *ip_str, const char *access_list_str)
718e3744 13518{
13519 int ret;
13520 struct prefix_ipv4 p;
13521 u_char distance;
13522 struct bgp_node *rn;
13523 struct bgp_distance *bdistance;
13524
13525 ret = str2prefix_ipv4 (ip_str, &p);
13526 if (ret == 0)
13527 {
13528 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13529 return CMD_WARNING;
13530 }
13531
13532 distance = atoi (distance_str);
13533
13534 /* Get BGP distance node. */
13535 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
13536 if (rn->info)
13537 {
13538 bdistance = rn->info;
13539 bgp_unlock_node (rn);
13540 }
13541 else
13542 {
13543 bdistance = bgp_distance_new ();
13544 rn->info = bdistance;
13545 }
13546
13547 /* Set distance value. */
13548 bdistance->distance = distance;
13549
13550 /* Reset access-list configuration. */
13551 if (bdistance->access_list)
13552 {
6e919709 13553 XFREE(MTYPE_AS_LIST, bdistance->access_list);
718e3744 13554 bdistance->access_list = NULL;
13555 }
13556 if (access_list_str)
6e919709 13557 bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str);
718e3744 13558
13559 return CMD_SUCCESS;
13560}
13561
94f2b392 13562static int
fd79ac91 13563bgp_distance_unset (struct vty *vty, const char *distance_str,
13564 const char *ip_str, const char *access_list_str)
718e3744 13565{
13566 int ret;
1f9a9fff 13567 int distance;
718e3744 13568 struct prefix_ipv4 p;
718e3744 13569 struct bgp_node *rn;
13570 struct bgp_distance *bdistance;
13571
13572 ret = str2prefix_ipv4 (ip_str, &p);
13573 if (ret == 0)
13574 {
13575 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13576 return CMD_WARNING;
13577 }
13578
718e3744 13579 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
13580 if (! rn)
13581 {
13582 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
13583 return CMD_WARNING;
13584 }
13585
13586 bdistance = rn->info;
1f9a9fff
PJ
13587 distance = atoi(distance_str);
13588
13589 if (bdistance->distance != distance)
13590 {
13591 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
13592 return CMD_WARNING;
13593 }
718e3744 13594
13595 if (bdistance->access_list)
6e919709 13596 XFREE(MTYPE_AS_LIST, bdistance->access_list);
718e3744 13597 bgp_distance_free (bdistance);
13598
13599 rn->info = NULL;
13600 bgp_unlock_node (rn);
13601 bgp_unlock_node (rn);
13602
13603 return CMD_SUCCESS;
13604}
13605
718e3744 13606/* Apply BGP information to distance method. */
13607u_char
13608bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
13609{
13610 struct bgp_node *rn;
13611 struct prefix_ipv4 q;
13612 struct peer *peer;
13613 struct bgp_distance *bdistance;
13614 struct access_list *alist;
13615 struct bgp_static *bgp_static;
13616
13617 if (! bgp)
13618 return 0;
13619
13620 if (p->family != AF_INET)
13621 return 0;
13622
13623 peer = rinfo->peer;
13624
13625 if (peer->su.sa.sa_family != AF_INET)
13626 return 0;
13627
13628 memset (&q, 0, sizeof (struct prefix_ipv4));
13629 q.family = AF_INET;
13630 q.prefix = peer->su.sin.sin_addr;
13631 q.prefixlen = IPV4_MAX_BITLEN;
13632
13633 /* Check source address. */
13634 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
13635 if (rn)
13636 {
13637 bdistance = rn->info;
13638 bgp_unlock_node (rn);
13639
13640 if (bdistance->access_list)
13641 {
13642 alist = access_list_lookup (AFI_IP, bdistance->access_list);
13643 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
13644 return bdistance->distance;
13645 }
13646 else
13647 return bdistance->distance;
13648 }
13649
13650 /* Backdoor check. */
13651 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
13652 if (rn)
13653 {
13654 bgp_static = rn->info;
13655 bgp_unlock_node (rn);
13656
13657 if (bgp_static->backdoor)
13658 {
13659 if (bgp->distance_local)
13660 return bgp->distance_local;
13661 else
13662 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13663 }
13664 }
13665
6d85b15b 13666 if (peer->sort == BGP_PEER_EBGP)
718e3744 13667 {
13668 if (bgp->distance_ebgp)
13669 return bgp->distance_ebgp;
13670 return ZEBRA_EBGP_DISTANCE_DEFAULT;
13671 }
13672 else
13673 {
13674 if (bgp->distance_ibgp)
13675 return bgp->distance_ibgp;
13676 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13677 }
13678}
13679
13680DEFUN (bgp_distance,
13681 bgp_distance_cmd,
13682 "distance bgp <1-255> <1-255> <1-255>",
13683 "Define an administrative distance\n"
13684 "BGP distance\n"
13685 "Distance for routes external to the AS\n"
13686 "Distance for routes internal to the AS\n"
13687 "Distance for local routes\n")
13688{
13689 struct bgp *bgp;
13690
13691 bgp = vty->index;
13692
13693 bgp->distance_ebgp = atoi (argv[0]);
13694 bgp->distance_ibgp = atoi (argv[1]);
13695 bgp->distance_local = atoi (argv[2]);
13696 return CMD_SUCCESS;
13697}
13698
13699DEFUN (no_bgp_distance,
13700 no_bgp_distance_cmd,
13701 "no distance bgp <1-255> <1-255> <1-255>",
13702 NO_STR
13703 "Define an administrative distance\n"
13704 "BGP distance\n"
13705 "Distance for routes external to the AS\n"
13706 "Distance for routes internal to the AS\n"
13707 "Distance for local routes\n")
13708{
13709 struct bgp *bgp;
13710
13711 bgp = vty->index;
13712
13713 bgp->distance_ebgp= 0;
13714 bgp->distance_ibgp = 0;
13715 bgp->distance_local = 0;
13716 return CMD_SUCCESS;
13717}
13718
13719ALIAS (no_bgp_distance,
13720 no_bgp_distance2_cmd,
13721 "no distance bgp",
13722 NO_STR
13723 "Define an administrative distance\n"
13724 "BGP distance\n")
13725
13726DEFUN (bgp_distance_source,
13727 bgp_distance_source_cmd,
13728 "distance <1-255> A.B.C.D/M",
13729 "Define an administrative distance\n"
13730 "Administrative distance\n"
13731 "IP source prefix\n")
13732{
13733 bgp_distance_set (vty, argv[0], argv[1], NULL);
13734 return CMD_SUCCESS;
13735}
13736
13737DEFUN (no_bgp_distance_source,
13738 no_bgp_distance_source_cmd,
13739 "no distance <1-255> A.B.C.D/M",
13740 NO_STR
13741 "Define an administrative distance\n"
13742 "Administrative distance\n"
13743 "IP source prefix\n")
13744{
13745 bgp_distance_unset (vty, argv[0], argv[1], NULL);
13746 return CMD_SUCCESS;
13747}
13748
13749DEFUN (bgp_distance_source_access_list,
13750 bgp_distance_source_access_list_cmd,
13751 "distance <1-255> A.B.C.D/M WORD",
13752 "Define an administrative distance\n"
13753 "Administrative distance\n"
13754 "IP source prefix\n"
13755 "Access list name\n")
13756{
13757 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
13758 return CMD_SUCCESS;
13759}
13760
13761DEFUN (no_bgp_distance_source_access_list,
13762 no_bgp_distance_source_access_list_cmd,
13763 "no distance <1-255> A.B.C.D/M WORD",
13764 NO_STR
13765 "Define an administrative distance\n"
13766 "Administrative distance\n"
13767 "IP source prefix\n"
13768 "Access list name\n")
13769{
13770 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
13771 return CMD_SUCCESS;
13772}
6b0655a2 13773
718e3744 13774DEFUN (bgp_damp_set,
13775 bgp_damp_set_cmd,
13776 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13777 "BGP Specific commands\n"
13778 "Enable route-flap dampening\n"
13779 "Half-life time for the penalty\n"
13780 "Value to start reusing a route\n"
13781 "Value to start suppressing a route\n"
13782 "Maximum duration to suppress a stable route\n")
13783{
13784 struct bgp *bgp;
13785 int half = DEFAULT_HALF_LIFE * 60;
13786 int reuse = DEFAULT_REUSE;
13787 int suppress = DEFAULT_SUPPRESS;
13788 int max = 4 * half;
13789
13790 if (argc == 4)
13791 {
13792 half = atoi (argv[0]) * 60;
13793 reuse = atoi (argv[1]);
13794 suppress = atoi (argv[2]);
13795 max = atoi (argv[3]) * 60;
13796 }
13797 else if (argc == 1)
13798 {
13799 half = atoi (argv[0]) * 60;
13800 max = 4 * half;
13801 }
13802
13803 bgp = vty->index;
7ebe9748
B
13804
13805 if (suppress < reuse)
13806 {
13807 vty_out (vty, "Suppress value cannot be less than reuse value %s",
13808 VTY_NEWLINE);
13809 return 0;
13810 }
13811
718e3744 13812 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
13813 half, reuse, suppress, max);
13814}
13815
13816ALIAS (bgp_damp_set,
13817 bgp_damp_set2_cmd,
13818 "bgp dampening <1-45>",
13819 "BGP Specific commands\n"
13820 "Enable route-flap dampening\n"
13821 "Half-life time for the penalty\n")
13822
13823ALIAS (bgp_damp_set,
13824 bgp_damp_set3_cmd,
13825 "bgp dampening",
13826 "BGP Specific commands\n"
13827 "Enable route-flap dampening\n")
13828
13829DEFUN (bgp_damp_unset,
13830 bgp_damp_unset_cmd,
13831 "no bgp dampening",
13832 NO_STR
13833 "BGP Specific commands\n"
13834 "Enable route-flap dampening\n")
13835{
13836 struct bgp *bgp;
13837
13838 bgp = vty->index;
13839 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
13840}
13841
13842ALIAS (bgp_damp_unset,
13843 bgp_damp_unset2_cmd,
13844 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13845 NO_STR
13846 "BGP Specific commands\n"
13847 "Enable route-flap dampening\n"
13848 "Half-life time for the penalty\n"
13849 "Value to start reusing a route\n"
13850 "Value to start suppressing a route\n"
13851 "Maximum duration to suppress a stable route\n")
13852
813d4307
DW
13853ALIAS (bgp_damp_unset,
13854 bgp_damp_unset3_cmd,
13855 "no bgp dampening <1-45>",
13856 NO_STR
13857 "BGP Specific commands\n"
13858 "Enable route-flap dampening\n"
13859 "Half-life time for the penalty\n")
13860
718e3744 13861DEFUN (show_ip_bgp_dampened_paths,
13862 show_ip_bgp_dampened_paths_cmd,
13863 "show ip bgp dampened-paths",
13864 SHOW_STR
13865 IP_STR
13866 BGP_STR
13867 "Display paths suppressed due to dampening\n")
13868{
5a646650 13869 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
b05a1c8b 13870 NULL, 0);
718e3744 13871}
13872
81304aaf
B
13873ALIAS (show_ip_bgp_dampened_paths,
13874 show_ip_bgp_damp_dampened_paths_cmd,
13875 "show ip bgp dampening dampened-paths",
13876 SHOW_STR
13877 IP_STR
13878 BGP_STR
13879 "Display detailed information about dampening\n"
13880 "Display paths suppressed due to dampening\n")
13881
718e3744 13882DEFUN (show_ip_bgp_flap_statistics,
13883 show_ip_bgp_flap_statistics_cmd,
13884 "show ip bgp flap-statistics",
13885 SHOW_STR
13886 IP_STR
13887 BGP_STR
13888 "Display flap statistics of routes\n")
13889{
5a646650 13890 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 13891 bgp_show_type_flap_statistics, NULL, 0);
718e3744 13892}
6b0655a2 13893
81304aaf
B
13894ALIAS (show_ip_bgp_flap_statistics,
13895 show_ip_bgp_damp_flap_statistics_cmd,
13896 "show ip bgp dampening flap-statistics",
13897 SHOW_STR
13898 IP_STR
13899 BGP_STR
13900 "Display detailed information about dampening\n"
13901 "Display flap statistics of routes\n")
13902
718e3744 13903/* Display specified route of BGP table. */
94f2b392 13904static int
fd79ac91 13905bgp_clear_damp_route (struct vty *vty, const char *view_name,
13906 const char *ip_str, afi_t afi, safi_t safi,
13907 struct prefix_rd *prd, int prefix_check)
718e3744 13908{
13909 int ret;
13910 struct prefix match;
13911 struct bgp_node *rn;
13912 struct bgp_node *rm;
13913 struct bgp_info *ri;
13914 struct bgp_info *ri_temp;
13915 struct bgp *bgp;
13916 struct bgp_table *table;
13917
13918 /* BGP structure lookup. */
13919 if (view_name)
13920 {
13921 bgp = bgp_lookup_by_name (view_name);
13922 if (bgp == NULL)
13923 {
6aeb9e78 13924 vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
718e3744 13925 return CMD_WARNING;
13926 }
13927 }
13928 else
13929 {
13930 bgp = bgp_get_default ();
13931 if (bgp == NULL)
13932 {
13933 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
13934 return CMD_WARNING;
13935 }
13936 }
13937
13938 /* Check IP address argument. */
13939 ret = str2prefix (ip_str, &match);
13940 if (! ret)
13941 {
13942 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
13943 return CMD_WARNING;
13944 }
13945
13946 match.family = afi2family (afi);
13947
587ff0fd 13948 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 13949 {
587ff0fd 13950 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
718e3744 13951 {
13952 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
13953 continue;
13954
13955 if ((table = rn->info) != NULL)
13956 if ((rm = bgp_node_match (table, &match)) != NULL)
6c88b44d
CC
13957 {
13958 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
13959 {
13960 ri = rm->info;
13961 while (ri)
13962 {
13963 if (ri->extra && ri->extra->damp_info)
13964 {
13965 ri_temp = ri->next;
13966 bgp_damp_info_free (ri->extra->damp_info, 1);
13967 ri = ri_temp;
13968 }
13969 else
13970 ri = ri->next;
13971 }
13972 }
13973
13974 bgp_unlock_node (rm);
13975 }
718e3744 13976 }
13977 }
13978 else
13979 {
13980 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
6c88b44d
CC
13981 {
13982 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
13983 {
13984 ri = rn->info;
13985 while (ri)
13986 {
13987 if (ri->extra && ri->extra->damp_info)
13988 {
13989 ri_temp = ri->next;
13990 bgp_damp_info_free (ri->extra->damp_info, 1);
13991 ri = ri_temp;
13992 }
13993 else
13994 ri = ri->next;
13995 }
13996 }
13997
13998 bgp_unlock_node (rn);
13999 }
718e3744 14000 }
14001
14002 return CMD_SUCCESS;
14003}
14004
14005DEFUN (clear_ip_bgp_dampening,
14006 clear_ip_bgp_dampening_cmd,
14007 "clear ip bgp dampening",
14008 CLEAR_STR
14009 IP_STR
14010 BGP_STR
14011 "Clear route flap dampening information\n")
14012{
14013 bgp_damp_info_clean ();
14014 return CMD_SUCCESS;
14015}
14016
14017DEFUN (clear_ip_bgp_dampening_prefix,
14018 clear_ip_bgp_dampening_prefix_cmd,
14019 "clear ip bgp dampening A.B.C.D/M",
14020 CLEAR_STR
14021 IP_STR
14022 BGP_STR
14023 "Clear route flap dampening information\n"
14024 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14025{
14026 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14027 SAFI_UNICAST, NULL, 1);
14028}
14029
14030DEFUN (clear_ip_bgp_dampening_address,
14031 clear_ip_bgp_dampening_address_cmd,
14032 "clear ip bgp dampening A.B.C.D",
14033 CLEAR_STR
14034 IP_STR
14035 BGP_STR
14036 "Clear route flap dampening information\n"
14037 "Network to clear damping information\n")
14038{
14039 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14040 SAFI_UNICAST, NULL, 0);
14041}
14042
14043DEFUN (clear_ip_bgp_dampening_address_mask,
14044 clear_ip_bgp_dampening_address_mask_cmd,
14045 "clear ip bgp dampening A.B.C.D A.B.C.D",
14046 CLEAR_STR
14047 IP_STR
14048 BGP_STR
14049 "Clear route flap dampening information\n"
14050 "Network to clear damping information\n"
14051 "Network mask\n")
14052{
14053 int ret;
14054 char prefix_str[BUFSIZ];
14055
14056 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
14057 if (! ret)
14058 {
14059 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
14060 return CMD_WARNING;
14061 }
14062
14063 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
14064 SAFI_UNICAST, NULL, 0);
14065}
6b0655a2 14066
587ff0fd 14067/* also used for encap safi */
94f2b392 14068static int
718e3744 14069bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
14070 afi_t afi, safi_t safi, int *write)
14071{
14072 struct bgp_node *prn;
14073 struct bgp_node *rn;
14074 struct bgp_table *table;
14075 struct prefix *p;
14076 struct prefix_rd *prd;
14077 struct bgp_static *bgp_static;
14078 u_int32_t label;
14079 char buf[SU_ADDRSTRLEN];
14080 char rdbuf[RD_ADDRSTRLEN];
14081
14082 /* Network configuration. */
14083 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
14084 if ((table = prn->info) != NULL)
14085 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
14086 if ((bgp_static = rn->info) != NULL)
14087 {
14088 p = &rn->p;
14089 prd = (struct prefix_rd *) &prn->p;
14090
14091 /* "address-family" display. */
14092 bgp_config_write_family_header (vty, afi, safi, write);
14093
14094 /* "network" configuration display. */
14095 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
14096 label = decode_label (bgp_static->tag);
14097
0b960b4d 14098 vty_out (vty, " network %s/%d rd %s tag %d",
718e3744 14099 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14100 p->prefixlen,
14101 rdbuf, label);
14102 vty_out (vty, "%s", VTY_NEWLINE);
14103 }
14104 return 0;
14105}
14106
14107/* Configuration of static route announcement and aggregate
14108 information. */
14109int
14110bgp_config_write_network (struct vty *vty, struct bgp *bgp,
14111 afi_t afi, safi_t safi, int *write)
14112{
14113 struct bgp_node *rn;
14114 struct prefix *p;
14115 struct bgp_static *bgp_static;
14116 struct bgp_aggregate *bgp_aggregate;
14117 char buf[SU_ADDRSTRLEN];
14118
587ff0fd 14119 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
718e3744 14120 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
14121
14122 /* Network configuration. */
14123 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
14124 if ((bgp_static = rn->info) != NULL)
14125 {
14126 p = &rn->p;
14127
14128 /* "address-family" display. */
14129 bgp_config_write_family_header (vty, afi, safi, write);
14130
14131 /* "network" configuration display. */
14132 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14133 {
14134 u_int32_t destination;
14135 struct in_addr netmask;
14136
14137 destination = ntohl (p->u.prefix4.s_addr);
14138 masklen2ip (p->prefixlen, &netmask);
0b960b4d 14139 vty_out (vty, " network %s",
718e3744 14140 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
14141
14142 if ((IN_CLASSC (destination) && p->prefixlen == 24)
14143 || (IN_CLASSB (destination) && p->prefixlen == 16)
14144 || (IN_CLASSA (destination) && p->prefixlen == 8)
14145 || p->u.prefix4.s_addr == 0)
14146 {
14147 /* Natural mask is not display. */
14148 }
14149 else
14150 vty_out (vty, " mask %s", inet_ntoa (netmask));
14151 }
14152 else
14153 {
0b960b4d 14154 vty_out (vty, " network %s/%d",
718e3744 14155 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14156 p->prefixlen);
14157 }
14158
14159 if (bgp_static->rmap.name)
14160 vty_out (vty, " route-map %s", bgp_static->rmap.name);
41367172
PJ
14161 else
14162 {
14163 if (bgp_static->backdoor)
14164 vty_out (vty, " backdoor");
41367172 14165 }
718e3744 14166
14167 vty_out (vty, "%s", VTY_NEWLINE);
14168 }
14169
14170 /* Aggregate-address configuration. */
14171 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
14172 if ((bgp_aggregate = rn->info) != NULL)
14173 {
14174 p = &rn->p;
14175
14176 /* "address-family" display. */
14177 bgp_config_write_family_header (vty, afi, safi, write);
14178
14179 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14180 {
14181 struct in_addr netmask;
14182
14183 masklen2ip (p->prefixlen, &netmask);
0b960b4d 14184 vty_out (vty, " aggregate-address %s %s",
718e3744 14185 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14186 inet_ntoa (netmask));
14187 }
14188 else
14189 {
0b960b4d 14190 vty_out (vty, " aggregate-address %s/%d",
718e3744 14191 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14192 p->prefixlen);
14193 }
14194
14195 if (bgp_aggregate->as_set)
14196 vty_out (vty, " as-set");
14197
14198 if (bgp_aggregate->summary_only)
14199 vty_out (vty, " summary-only");
14200
14201 vty_out (vty, "%s", VTY_NEWLINE);
14202 }
14203
14204 return 0;
14205}
14206
14207int
14208bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
14209{
14210 struct bgp_node *rn;
14211 struct bgp_distance *bdistance;
14212
14213 /* Distance configuration. */
14214 if (bgp->distance_ebgp
14215 && bgp->distance_ibgp
14216 && bgp->distance_local
14217 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
14218 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
14219 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
14220 vty_out (vty, " distance bgp %d %d %d%s",
14221 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
14222 VTY_NEWLINE);
14223
14224 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
14225 if ((bdistance = rn->info) != NULL)
14226 {
14227 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
14228 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
14229 bdistance->access_list ? bdistance->access_list : "",
14230 VTY_NEWLINE);
14231 }
14232
14233 return 0;
14234}
14235
14236/* Allocate routing table structure and install commands. */
14237void
66e5cd87 14238bgp_route_init (void)
718e3744 14239{
14240 /* Init BGP distance table. */
64e580a7 14241 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
718e3744 14242
14243 /* IPv4 BGP commands. */
73ac8160 14244 install_element (BGP_NODE, &bgp_table_map_cmd);
718e3744 14245 install_element (BGP_NODE, &bgp_network_cmd);
14246 install_element (BGP_NODE, &bgp_network_mask_cmd);
14247 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
14248 install_element (BGP_NODE, &bgp_network_route_map_cmd);
14249 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
14250 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
14251 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
14252 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
14253 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
73ac8160 14254 install_element (BGP_NODE, &no_bgp_table_map_cmd);
718e3744 14255 install_element (BGP_NODE, &no_bgp_network_cmd);
14256 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
14257 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
14258 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
14259 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
14260 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14261 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
14262 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
14263 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
14264
14265 install_element (BGP_NODE, &aggregate_address_cmd);
14266 install_element (BGP_NODE, &aggregate_address_mask_cmd);
14267 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
14268 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
14269 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
14270 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
14271 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
14272 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
14273 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
14274 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
14275 install_element (BGP_NODE, &no_aggregate_address_cmd);
14276 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
14277 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
14278 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
14279 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
14280 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
14281 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
14282 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
14283 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14284 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14285
14286 /* IPv4 unicast configuration. */
73ac8160 14287 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
718e3744 14288 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
14289 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
14290 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
14291 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
14292 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
14293 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 14294 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
c8f3fe30 14295 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
718e3744 14296 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
14297 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
14298 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
14299 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
14300 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
c8f3fe30 14301
718e3744 14302 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
14303 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
14304 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
14305 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
14306 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
14307 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
14308 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
14309 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
14310 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
14311 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
14312 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
14313 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
14314 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
14315 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
14316 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
14317 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
14318 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
14319 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
14320 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14321 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14322
14323 /* IPv4 multicast configuration. */
73ac8160 14324 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
718e3744 14325 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
14326 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
14327 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
14328 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
14329 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
14330 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 14331 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
718e3744 14332 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
14333 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
14334 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
14335 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
14336 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
14337 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14338 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
14339 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
14340 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
14341 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
14342 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
14343 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
14344 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
14345 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
14346 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
14347 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
14348 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
14349 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
14350 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
14351 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
14352 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
14353 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
14354 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
14355 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
14356 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14357 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14358
14359 install_element (VIEW_NODE, &show_ip_bgp_cmd);
8386ac43 14360 install_element (VIEW_NODE, &show_ip_bgp_instance_cmd);
f186de26 14361 install_element (VIEW_NODE, &show_ip_bgp_instance_all_cmd);
718e3744 14362 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 14363 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
718e3744 14364 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
8386ac43 14365 install_element (VIEW_NODE, &show_ip_bgp_instance_route_cmd);
4092b06c 14366 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
8386ac43 14367 install_element (VIEW_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
4092b06c 14368 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 14369 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 14370 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 14371 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14372 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14373 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
8386ac43 14374 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd);
718e3744 14375 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
14376 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14377 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 14378 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 14379 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
8386ac43 14380 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
718e3744 14381 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14382 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
50ef26d4 14383
718e3744 14384 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
14385 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14386 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
8386ac43 14387 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_list_cmd);
718e3744 14388 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14389 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
8386ac43 14390 install_element (VIEW_NODE, &show_ip_bgp_instance_filter_list_cmd);
718e3744 14391 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14392 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
8386ac43 14393 install_element (VIEW_NODE, &show_ip_bgp_instance_route_map_cmd);
718e3744 14394 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14395 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
14396 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14397 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
14398 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14399 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
14400 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
14401 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
14402 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
14403 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
14404 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
14405 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
14406 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
8386ac43 14407 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14408 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_cmd);
14409 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14410 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14411 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community4_cmd);
718e3744 14412 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
14413 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
14414 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
14415 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
14416 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14417 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14418 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14419 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14420 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
8386ac43 14421 install_element (VIEW_NODE, &show_ip_bgp_instance_community_list_cmd);
718e3744 14422 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14423 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
14424 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14425 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
8386ac43 14426 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
718e3744 14427 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14428 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
8386ac43 14429 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
0b16f239 14430 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
8386ac43 14431 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
718e3744 14432 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
0b16f239 14433 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
718e3744 14434 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
8386ac43 14435 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
0b16f239 14436 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
8386ac43 14437 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
718e3744 14438 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
0b16f239 14439 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
8386ac43 14440 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 14441 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
8386ac43 14442 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
718e3744 14443 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14444 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14445 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
81304aaf 14446 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
718e3744 14447 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
81304aaf 14448 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
718e3744 14449 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
81304aaf 14450 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
718e3744 14451 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
81304aaf 14452 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
718e3744 14453 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
14454 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
81304aaf 14455 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
718e3744 14456 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
14457 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
81304aaf 14458 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
718e3744 14459 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
81304aaf 14460 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
718e3744 14461 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
81304aaf 14462 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
718e3744 14463 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
81304aaf 14464 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
718e3744 14465 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
14466 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
62687ff1
PJ
14467
14468 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
14469 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
8386ac43 14470 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_cmd);
4092b06c 14471 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
8386ac43 14472 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
4092b06c 14473 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
62687ff1 14474 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 14475 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
62687ff1
PJ
14476 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14477 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
8386ac43 14478 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_cmd);
62687ff1 14479 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
14480 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14481 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 14482 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 14483 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
8386ac43 14484 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
62687ff1
PJ
14485 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14486 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
8386ac43 14487 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_cmd);
14488 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_cmd);
62687ff1
PJ
14489 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
14490 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
14491 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
14492 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
14493 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
14494 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
14495 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
14496 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
8386ac43 14497 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14498 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community_cmd);
14499 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14500 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14501 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community4_cmd);
62687ff1
PJ
14502 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
14503 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
14504 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
14505 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
14506 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14507 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14508 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14509 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
718e3744 14510
14511 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
8386ac43 14512 install_element (ENABLE_NODE, &show_ip_bgp_instance_cmd);
f186de26 14513 install_element (ENABLE_NODE, &show_ip_bgp_instance_all_cmd);
718e3744 14514 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 14515 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
718e3744 14516 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
8386ac43 14517 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_cmd);
4092b06c 14518 install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd);
8386ac43 14519 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
4092b06c 14520 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 14521 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 14522 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 14523 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14524 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14525 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
8386ac43 14526 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_cmd);
718e3744 14527 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
14528 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14529 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 14530 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 14531 install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd);
8386ac43 14532 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
718e3744 14533 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14534 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
50ef26d4 14535
718e3744 14536 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
14537 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14538 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
8386ac43 14539 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_list_cmd);
718e3744 14540 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14541 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
8386ac43 14542 install_element (ENABLE_NODE, &show_ip_bgp_instance_filter_list_cmd);
718e3744 14543 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14544 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
8386ac43 14545 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_map_cmd);
718e3744 14546 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14547 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
14548 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14549 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
14550 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14551 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
14552 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
14553 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
14554 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
14555 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
14556 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
14557 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
14558 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
8386ac43 14559 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14560 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community_cmd);
14561 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14562 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14563 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community4_cmd);
718e3744 14564 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
14565 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
14566 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
14567 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
14568 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14569 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14570 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14571 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14572 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
8386ac43 14573 install_element (ENABLE_NODE, &show_ip_bgp_instance_community_list_cmd);
718e3744 14574 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14575 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
14576 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14577 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
8386ac43 14578 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
718e3744 14579 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14580 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
8386ac43 14581 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
0b16f239 14582 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
8386ac43 14583 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
718e3744 14584 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
0b16f239 14585 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
718e3744 14586 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
8386ac43 14587 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
0b16f239 14588 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
8386ac43 14589 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
718e3744 14590 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
0b16f239 14591 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
8386ac43 14592 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 14593 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
8386ac43 14594 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
718e3744 14595 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14596 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14597 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
81304aaf 14598 install_element (ENABLE_NODE, &show_ip_bgp_dampening_params_cmd);
718e3744 14599 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
81304aaf 14600 install_element (ENABLE_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
718e3744 14601 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
81304aaf 14602 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
718e3744 14603 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
81304aaf 14604 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_address_cmd);
718e3744 14605 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
14606 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
81304aaf 14607 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
718e3744 14608 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
81304aaf 14609 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_regexp_cmd);
718e3744 14610 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
81304aaf 14611 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
718e3744 14612 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
81304aaf
B
14613 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
14614 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
718e3744 14615 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
81304aaf 14616 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
718e3744 14617 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
81304aaf 14618 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
718e3744 14619 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
14620 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
14621
14622 /* BGP dampening clear commands */
14623 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
14624 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
14625 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
14626 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
14627
ff7924f6
PJ
14628 /* prefix count */
14629 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
8386ac43 14630 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd);
ff7924f6
PJ
14631 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
14632 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
718e3744 14633#ifdef HAVE_IPV6
ff7924f6 14634 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
8386ac43 14635 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd);
ff7924f6 14636
718e3744 14637 /* New config IPv6 BGP commands. */
73ac8160 14638 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
718e3744 14639 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
14640 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
73ac8160 14641 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
718e3744 14642 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
14643 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
14644
14645 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
14646 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
14647 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
14648 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
73bfe0bd
B
14649
14650 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
14651 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
718e3744 14652
14653 /* Old config IPv6 BGP commands. */
14654 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
14655 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
14656
14657 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
14658 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
14659 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
14660 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
14661
14662 install_element (VIEW_NODE, &show_bgp_cmd);
14663 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 14664 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 14665 install_element (VIEW_NODE, &show_bgp_route_cmd);
14666 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 14667 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
14668 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
14669 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14670 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 14671 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
14672 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 14673 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c
DS
14674 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
14675 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14676 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 14677 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
14678 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
14679 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
14680 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
14681 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
14682 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
14683 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
14684 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
14685 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
14686 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
14687 install_element (VIEW_NODE, &show_bgp_community_cmd);
14688 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
14689 install_element (VIEW_NODE, &show_bgp_community2_cmd);
14690 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
14691 install_element (VIEW_NODE, &show_bgp_community3_cmd);
14692 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
14693 install_element (VIEW_NODE, &show_bgp_community4_cmd);
14694 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
14695 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
14696 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
14697 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
14698 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
14699 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
14700 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
14701 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
14702 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
14703 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
14704 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
14705 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
14706 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14707 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
14708 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14709 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
14710 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14711 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
14712 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14713 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
14714 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14715 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14716 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 14717 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
14718 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14719 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
14720 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
8386ac43 14721 install_element (VIEW_NODE, &show_bgp_instance_cmd);
f186de26 14722 install_element (VIEW_NODE, &show_bgp_instance_all_cmd);
8386ac43 14723 install_element (VIEW_NODE, &show_bgp_instance_ipv6_cmd);
14724 install_element (VIEW_NODE, &show_bgp_instance_route_cmd);
14725 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_cmd);
14726 install_element (VIEW_NODE, &show_bgp_instance_route_pathtype_cmd);
14727 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14728 install_element (VIEW_NODE, &show_bgp_instance_prefix_cmd);
14729 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14730 install_element (VIEW_NODE, &show_bgp_instance_prefix_pathtype_cmd);
14731 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
14732 install_element (VIEW_NODE, &show_bgp_instance_prefix_list_cmd);
14733 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
14734 install_element (VIEW_NODE, &show_bgp_instance_filter_list_cmd);
14735 install_element (VIEW_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
14736 install_element (VIEW_NODE, &show_bgp_instance_route_map_cmd);
14737 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_map_cmd);
14738 install_element (VIEW_NODE, &show_bgp_instance_community_list_cmd);
14739 install_element (VIEW_NODE, &show_bgp_instance_ipv6_community_list_cmd);
14740 install_element (VIEW_NODE, &show_bgp_instance_prefix_longer_cmd);
14741 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
14742 install_element (VIEW_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
14743 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
14744 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
14745 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
14746 install_element (VIEW_NODE, &show_bgp_instance_neighbor_routes_cmd);
14747 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
14748 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14749 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14750 install_element (VIEW_NODE, &show_bgp_instance_neighbor_flap_cmd);
14751 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
14752 install_element (VIEW_NODE, &show_bgp_instance_neighbor_damp_cmd);
14753 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
62687ff1
PJ
14754
14755 /* Restricted:
14756 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
14757 */
14758 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
14759 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 14760 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
14761 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
14762 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14763 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
62687ff1
PJ
14764 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
14765 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 14766 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c
DS
14767 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
14768 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14769 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
62687ff1
PJ
14770 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
14771 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
14772 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
14773 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
14774 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
14775 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
14776 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
14777 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
14778 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
14779 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
14780 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
14781 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
14782 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
14783 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
14784 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
14785 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
8386ac43 14786 install_element (RESTRICTED_NODE, &show_bgp_instance_route_cmd);
14787 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_route_cmd);
14788 install_element (RESTRICTED_NODE, &show_bgp_instance_route_pathtype_cmd);
14789 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14790 install_element (RESTRICTED_NODE, &show_bgp_instance_prefix_cmd);
14791 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14792 install_element (RESTRICTED_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14793 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
718e3744 14794
14795 install_element (ENABLE_NODE, &show_bgp_cmd);
14796 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 14797 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 14798 install_element (ENABLE_NODE, &show_bgp_route_cmd);
14799 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 14800 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
14801 install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd);
14802 install_element (ENABLE_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14803 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 14804 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
4092b06c
DS
14805 install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd);
14806 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14807 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 14808 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 14809 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
718e3744 14810 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
14811 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
14812 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
14813 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
14814 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
14815 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
14816 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
14817 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
14818 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
14819 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
14820 install_element (ENABLE_NODE, &show_bgp_community_cmd);
14821 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
14822 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
14823 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
14824 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
14825 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
14826 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
14827 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
14828 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
14829 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
14830 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
14831 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
14832 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
14833 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
14834 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
14835 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
14836 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
14837 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
14838 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
14839 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14840 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
14841 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14842 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
14843 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14844 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
14845 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14846 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
14847 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14848 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14849 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 14850 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
14851 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14852 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
14853 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
8386ac43 14854 install_element (ENABLE_NODE, &show_bgp_instance_cmd);
f186de26 14855 install_element (ENABLE_NODE, &show_bgp_instance_all_cmd);
8386ac43 14856 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_cmd);
14857 install_element (ENABLE_NODE, &show_bgp_instance_route_cmd);
14858 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_cmd);
14859 install_element (ENABLE_NODE, &show_bgp_instance_route_pathtype_cmd);
14860 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14861 install_element (ENABLE_NODE, &show_bgp_instance_prefix_cmd);
14862 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14863 install_element (ENABLE_NODE, &show_bgp_instance_prefix_pathtype_cmd);
14864 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
14865 install_element (ENABLE_NODE, &show_bgp_instance_prefix_list_cmd);
14866 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
14867 install_element (ENABLE_NODE, &show_bgp_instance_filter_list_cmd);
14868 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
14869 install_element (ENABLE_NODE, &show_bgp_instance_route_map_cmd);
14870 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_map_cmd);
14871 install_element (ENABLE_NODE, &show_bgp_instance_community_list_cmd);
14872 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_community_list_cmd);
14873 install_element (ENABLE_NODE, &show_bgp_instance_prefix_longer_cmd);
14874 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
14875 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
14876 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
14877 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
14878 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
14879 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_routes_cmd);
14880 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
14881 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14882 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14883 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_flap_cmd);
14884 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
14885 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_damp_cmd);
14886 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
50ef26d4 14887
2815e61f
PJ
14888 /* Statistics */
14889 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
587ff0fd 14890 //install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
2815e61f 14891 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
587ff0fd 14892 //install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
2815e61f 14893
718e3744 14894 /* old command */
14895 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
14896 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
14897 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
14898 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
14899 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
14900 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
14901 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
14902 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
14903 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
14904 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
14905 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
14906 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
14907 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
14908 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
14909 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
14910 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
14911 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14912 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14913 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
14914 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
14915 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
14916 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
14917 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14918 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
14919 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
14920 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
14921 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
14922 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
14923 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
14924 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
14925 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14926 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14927 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
14928 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
14929 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
14930 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
bb46e94f 14931
718e3744 14932 /* old command */
14933 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
14934 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
14935 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
14936 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
14937 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
14938 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
14939 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
14940 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
14941 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
14942 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
14943 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
14944 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
14945 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
14946 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
14947 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
14948 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
14949 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14950 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14951 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
14952 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
14953 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
14954 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
14955 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14956 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
14957 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
14958 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
14959 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
14960 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
14961 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
14962 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
14963 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14964 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14965 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
14966 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
14967 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
14968 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
14969
14970 /* old command */
14971 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14972 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14973 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14974 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14975
14976 /* old command */
14977 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14978 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14979 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14980 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14981
14982 /* old command */
14983 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
14984 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
14985 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14986 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14987#endif /* HAVE_IPV6 */
14988
14989 install_element (BGP_NODE, &bgp_distance_cmd);
14990 install_element (BGP_NODE, &no_bgp_distance_cmd);
14991 install_element (BGP_NODE, &no_bgp_distance2_cmd);
14992 install_element (BGP_NODE, &bgp_distance_source_cmd);
14993 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
14994 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
14995 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
14996
14997 install_element (BGP_NODE, &bgp_damp_set_cmd);
14998 install_element (BGP_NODE, &bgp_damp_set2_cmd);
14999 install_element (BGP_NODE, &bgp_damp_set3_cmd);
15000 install_element (BGP_NODE, &bgp_damp_unset_cmd);
15001 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
813d4307 15002 install_element (BGP_NODE, &bgp_damp_unset3_cmd);
718e3744 15003 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
15004 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
15005 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
15006 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
15007 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
813d4307 15008 install_element (BGP_IPV4_NODE, &bgp_damp_unset3_cmd);
718e3744 15009}
228da428
CC
15010
15011void
15012bgp_route_finish (void)
15013{
15014 bgp_table_unlock (bgp_distance_table);
15015 bgp_distance_table = NULL;
15016}