]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_route.c
Quagga: prefix2str fixup
[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"
718e3744 63
64/* Extern from bgp_dump.c */
dde72586
SH
65extern const char *bgp_origin_str[];
66extern const char *bgp_origin_long_str[];
6b0655a2 67
4125bb67 68struct bgp_node *
fee0f4c6 69bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
718e3744 70 struct prefix_rd *prd)
71{
72 struct bgp_node *rn;
73 struct bgp_node *prn = NULL;
da5b30f6
PJ
74
75 assert (table);
76 if (!table)
77 return NULL;
78
718e3744 79 if (safi == SAFI_MPLS_VPN)
80 {
fee0f4c6 81 prn = bgp_node_get (table, (struct prefix *) prd);
718e3744 82
83 if (prn->info == NULL)
64e580a7 84 prn->info = bgp_table_init (afi, safi);
718e3744 85 else
86 bgp_unlock_node (prn);
87 table = prn->info;
88 }
718e3744 89
90 rn = bgp_node_get (table, p);
91
92 if (safi == SAFI_MPLS_VPN)
93 rn->prn = prn;
94
95 return rn;
96}
6b0655a2 97
fb982c25
PJ
98/* Allocate bgp_info_extra */
99static struct bgp_info_extra *
100bgp_info_extra_new (void)
101{
102 struct bgp_info_extra *new;
103 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
104 return new;
105}
106
107static void
108bgp_info_extra_free (struct bgp_info_extra **extra)
109{
110 if (extra && *extra)
111 {
112 if ((*extra)->damp_info)
113 bgp_damp_info_free ((*extra)->damp_info, 0);
114
115 (*extra)->damp_info = NULL;
116
117 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
118
119 *extra = NULL;
120 }
121}
122
123/* Get bgp_info extra information for the given bgp_info, lazy allocated
124 * if required.
125 */
126struct bgp_info_extra *
127bgp_info_extra_get (struct bgp_info *ri)
128{
129 if (!ri->extra)
130 ri->extra = bgp_info_extra_new();
131 return ri->extra;
132}
133
718e3744 134/* Free bgp route information. */
200df115 135static void
718e3744 136bgp_info_free (struct bgp_info *binfo)
137{
138 if (binfo->attr)
f6f434b2 139 bgp_attr_unintern (&binfo->attr);
fb018d25
DS
140
141 bgp_unlink_nexthop(binfo);
fb982c25 142 bgp_info_extra_free (&binfo->extra);
de8d5dff 143 bgp_info_mpath_free (&binfo->mpath);
718e3744 144
200df115 145 peer_unlock (binfo->peer); /* bgp_info peer reference */
146
718e3744 147 XFREE (MTYPE_BGP_ROUTE, binfo);
148}
149
200df115 150struct bgp_info *
151bgp_info_lock (struct bgp_info *binfo)
152{
153 binfo->lock++;
154 return binfo;
155}
156
157struct bgp_info *
158bgp_info_unlock (struct bgp_info *binfo)
159{
160 assert (binfo && binfo->lock > 0);
161 binfo->lock--;
162
163 if (binfo->lock == 0)
164 {
165#if 0
166 zlog_debug ("%s: unlocked and freeing", __func__);
167 zlog_backtrace (LOG_DEBUG);
168#endif
169 bgp_info_free (binfo);
170 return NULL;
171 }
172
173#if 0
174 if (binfo->lock == 1)
175 {
176 zlog_debug ("%s: unlocked to 1", __func__);
177 zlog_backtrace (LOG_DEBUG);
178 }
179#endif
180
181 return binfo;
182}
183
718e3744 184void
185bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
186{
187 struct bgp_info *top;
188
189 top = rn->info;
200df115 190
718e3744 191 ri->next = rn->info;
192 ri->prev = NULL;
193 if (top)
194 top->prev = ri;
195 rn->info = ri;
200df115 196
197 bgp_info_lock (ri);
198 bgp_lock_node (rn);
199 peer_lock (ri->peer); /* bgp_info peer reference */
718e3744 200}
201
b40d939b 202/* Do the actual removal of info from RIB, for use by bgp_process
203 completion callback *only* */
204static void
205bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
718e3744 206{
207 if (ri->next)
208 ri->next->prev = ri->prev;
209 if (ri->prev)
210 ri->prev->next = ri->next;
211 else
212 rn->info = ri->next;
200df115 213
de8d5dff 214 bgp_info_mpath_dequeue (ri);
200df115 215 bgp_info_unlock (ri);
216 bgp_unlock_node (rn);
718e3744 217}
218
b40d939b 219void
220bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
221{
1a392d46
PJ
222 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
223 /* set of previous already took care of pcount */
b40d939b 224 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
225}
226
8d45210e
AS
227/* undo the effects of a previous call to bgp_info_delete; typically
228 called when a route is deleted and then quickly re-added before the
229 deletion has been processed */
230static void
231bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
232{
233 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
234 /* unset of previous already took care of pcount */
235 SET_FLAG (ri->flags, BGP_INFO_VALID);
236}
237
1a392d46
PJ
238/* Adjust pcount as required */
239static void
240bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
241{
67174041
AS
242 struct bgp_table *table;
243
244 assert (rn && bgp_node_table (rn));
6f58544d
PJ
245 assert (ri && ri->peer && ri->peer->bgp);
246
67174041
AS
247 table = bgp_node_table (rn);
248
2a3d5731 249 if (ri->peer == ri->peer->bgp->peer_self)
1a392d46
PJ
250 return;
251
80e0ad24 252 if (!BGP_INFO_COUNTABLE (ri)
1a392d46
PJ
253 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
254 {
255
256 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
257
258 /* slight hack, but more robust against errors. */
67174041
AS
259 if (ri->peer->pcount[table->afi][table->safi])
260 ri->peer->pcount[table->afi][table->safi]--;
1a392d46
PJ
261 else
262 {
263 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
264 __func__, ri->peer->host);
265 zlog_backtrace (LOG_WARNING);
266 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
267 }
268 }
80e0ad24 269 else if (BGP_INFO_COUNTABLE (ri)
1a392d46
PJ
270 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
271 {
272 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
67174041 273 ri->peer->pcount[table->afi][table->safi]++;
1a392d46
PJ
274 }
275}
276
277
278/* Set/unset bgp_info flags, adjusting any other state as needed.
279 * This is here primarily to keep prefix-count in check.
280 */
281void
282bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
283{
284 SET_FLAG (ri->flags, flag);
285
80e0ad24
DS
286 /* early bath if we know it's not a flag that changes countability state */
287 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
1a392d46
PJ
288 return;
289
290 bgp_pcount_adjust (rn, ri);
291}
292
293void
294bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
295{
296 UNSET_FLAG (ri->flags, flag);
297
80e0ad24
DS
298 /* early bath if we know it's not a flag that changes countability state */
299 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
1a392d46
PJ
300 return;
301
302 bgp_pcount_adjust (rn, ri);
303}
304
718e3744 305/* Get MED value. If MED value is missing and "bgp bestpath
306 missing-as-worst" is specified, treat it as the worst value. */
94f2b392 307static u_int32_t
718e3744 308bgp_med_value (struct attr *attr, struct bgp *bgp)
309{
310 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
311 return attr->med;
312 else
313 {
314 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
3b424979 315 return BGP_MED_MAX;
718e3744 316 else
317 return 0;
318 }
319}
320
9fbdd100 321/* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1. */
94f2b392 322static int
96450faf 323bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
9fbdd100
DS
324 int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg, int debug,
325 char *pfx_buf)
718e3744 326{
8ff56318
JBD
327 struct attr *newattr, *existattr;
328 struct attr_extra *newattre, *existattre;
329 bgp_peer_sort_t new_sort;
330 bgp_peer_sort_t exist_sort;
718e3744 331 u_int32_t new_pref;
332 u_int32_t exist_pref;
333 u_int32_t new_med;
334 u_int32_t exist_med;
8ff56318
JBD
335 u_int32_t new_weight;
336 u_int32_t exist_weight;
337 uint32_t newm, existm;
718e3744 338 struct in_addr new_id;
339 struct in_addr exist_id;
340 int new_cluster;
341 int exist_cluster;
8ff56318
JBD
342 int internal_as_route;
343 int confed_as_route;
718e3744 344 int ret;
96450faf
JB
345
346 *paths_eq = 0;
718e3744 347
348 /* 0. Null check. */
349 if (new == NULL)
9fbdd100
DS
350 {
351 if (debug)
352 zlog_debug("%s: new is NULL", pfx_buf);
353 return 0;
354 }
355
718e3744 356 if (exist == NULL)
9fbdd100
DS
357 {
358 if (debug)
359 zlog_debug("%s: path %s is the initial bestpath",
360 pfx_buf, new->peer->host);
361 return 1;
362 }
718e3744 363
8ff56318
JBD
364 newattr = new->attr;
365 existattr = exist->attr;
366 newattre = newattr->extra;
367 existattre = existattr->extra;
368
718e3744 369 /* 1. Weight check. */
8ff56318
JBD
370 new_weight = exist_weight = 0;
371
372 if (newattre)
373 new_weight = newattre->weight;
374 if (existattre)
375 exist_weight = existattre->weight;
376
fb982c25 377 if (new_weight > exist_weight)
9fbdd100
DS
378 {
379 if (debug)
380 zlog_debug("%s: path %s wins over path %s due to weight %d > %d",
381 pfx_buf, new->peer->host, exist->peer->host, new_weight,
382 exist_weight);
383 return 1;
384 }
385
fb982c25 386 if (new_weight < exist_weight)
9fbdd100
DS
387 {
388 if (debug)
389 zlog_debug("%s: path %s loses to path %s due to weight %d < %d",
390 pfx_buf, new->peer->host, exist->peer->host, new_weight,
391 exist_weight);
392 return 0;
393 }
718e3744 394
395 /* 2. Local preference check. */
8ff56318
JBD
396 new_pref = exist_pref = bgp->default_local_pref;
397
398 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
399 new_pref = newattr->local_pref;
400 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
401 exist_pref = existattr->local_pref;
718e3744 402
718e3744 403 if (new_pref > exist_pref)
9fbdd100
DS
404 {
405 if (debug)
406 zlog_debug("%s: path %s wins over path %s due to localpref %d > %d",
407 pfx_buf, new->peer->host, exist->peer->host, new_pref,
408 exist_pref);
409 return 1;
410 }
411
718e3744 412 if (new_pref < exist_pref)
9fbdd100
DS
413 {
414 if (debug)
415 zlog_debug("%s: path %s loses to path %s due to localpref %d < %d",
416 pfx_buf, new->peer->host, exist->peer->host, new_pref,
417 exist_pref);
418 return 0;
419 }
718e3744 420
8ff56318
JBD
421 /* 3. Local route check. We prefer:
422 * - BGP_ROUTE_STATIC
423 * - BGP_ROUTE_AGGREGATE
424 * - BGP_ROUTE_REDISTRIBUTE
425 */
426 if (! (new->sub_type == BGP_ROUTE_NORMAL))
9fbdd100
DS
427 {
428 if (debug)
429 zlog_debug("%s: path %s wins over path %s due to preferred BGP_ROUTE type",
430 pfx_buf, new->peer->host, exist->peer->host);
431 return 1;
432 }
433
8ff56318 434 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
9fbdd100
DS
435 {
436 if (debug)
437 zlog_debug("%s: path %s loses to path %s due to preferred BGP_ROUTE type",
438 pfx_buf, new->peer->host, exist->peer->host);
439 return 0;
440 }
718e3744 441
442 /* 4. AS path length check. */
443 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
444 {
8ff56318
JBD
445 int exist_hops = aspath_count_hops (existattr->aspath);
446 int exist_confeds = aspath_count_confeds (existattr->aspath);
fe69a505 447
6811845b 448 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
449 {
fe69a505 450 int aspath_hops;
451
8ff56318
JBD
452 aspath_hops = aspath_count_hops (newattr->aspath);
453 aspath_hops += aspath_count_confeds (newattr->aspath);
fe69a505 454
455 if ( aspath_hops < (exist_hops + exist_confeds))
9fbdd100
DS
456 {
457 if (debug)
458 zlog_debug("%s: path %s wins over path %s due to aspath (with confeds) hopcount %d < %d",
459 pfx_buf, new->peer->host, exist->peer->host,
460 aspath_hops, (exist_hops + exist_confeds));
461 return 1;
462 }
463
fe69a505 464 if ( aspath_hops > (exist_hops + exist_confeds))
9fbdd100
DS
465 {
466 if (debug)
467 zlog_debug("%s: path %s loses to path %s due to aspath (with confeds) hopcount %d > %d",
468 pfx_buf, new->peer->host, exist->peer->host,
469 aspath_hops, (exist_hops + exist_confeds));
470 return 0;
471 }
6811845b 472 }
473 else
474 {
8ff56318 475 int newhops = aspath_count_hops (newattr->aspath);
fe69a505 476
477 if (newhops < exist_hops)
9fbdd100
DS
478 {
479 if (debug)
480 zlog_debug("%s: path %s wins over path %s due to aspath hopcount %d < %d",
481 pfx_buf, new->peer->host, exist->peer->host,
482 newhops, exist_hops);
483 return 1;
484 }
485
fe69a505 486 if (newhops > exist_hops)
9fbdd100
DS
487 {
488 if (debug)
489 zlog_debug("%s: path %s loses to path %s due to aspath hopcount %d > %d",
490 pfx_buf, new->peer->host, exist->peer->host,
491 newhops, exist_hops);
492 return 0;
493 }
6811845b 494 }
718e3744 495 }
496
497 /* 5. Origin check. */
8ff56318 498 if (newattr->origin < existattr->origin)
9fbdd100
DS
499 {
500 if (debug)
501 zlog_debug("%s: path %s wins over path %s due to ORIGIN %s < %s",
502 pfx_buf, new->peer->host, exist->peer->host,
503 bgp_origin_long_str[newattr->origin],
504 bgp_origin_long_str[existattr->origin]);
505 return 1;
506 }
507
8ff56318 508 if (newattr->origin > existattr->origin)
9fbdd100
DS
509 {
510 if (debug)
511 zlog_debug("%s: path %s loses to path %s due to ORIGIN %s > %s",
512 pfx_buf, new->peer->host, exist->peer->host,
513 bgp_origin_long_str[newattr->origin],
514 bgp_origin_long_str[existattr->origin]);
515 return 0;
516 }
718e3744 517
518 /* 6. MED check. */
8ff56318
JBD
519 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
520 && aspath_count_hops (existattr->aspath) == 0);
521 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
522 && aspath_count_confeds (existattr->aspath) > 0
523 && aspath_count_hops (newattr->aspath) == 0
524 && aspath_count_hops (existattr->aspath) == 0);
718e3744 525
526 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
527 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
528 && confed_as_route)
8ff56318
JBD
529 || aspath_cmp_left (newattr->aspath, existattr->aspath)
530 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
718e3744 531 || internal_as_route)
532 {
533 new_med = bgp_med_value (new->attr, bgp);
534 exist_med = bgp_med_value (exist->attr, bgp);
535
536 if (new_med < exist_med)
9fbdd100
DS
537 {
538 if (debug)
539 zlog_debug("%s: path %s wins over path %s due to MED %d < %d",
540 pfx_buf, new->peer->host, exist->peer->host, new_med,
541 exist_med);
542 return 1;
543 }
544
718e3744 545 if (new_med > exist_med)
9fbdd100
DS
546 {
547 if (debug)
548 zlog_debug("%s: path %s loses to path %s due to MED %d > %d",
549 pfx_buf, new->peer->host, exist->peer->host, new_med,
550 exist_med);
551 return 0;
552 }
718e3744 553 }
554
555 /* 7. Peer type check. */
8ff56318
JBD
556 new_sort = new->peer->sort;
557 exist_sort = exist->peer->sort;
558
559 if (new_sort == BGP_PEER_EBGP
560 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
9fbdd100
DS
561 {
562 if (debug)
31a4638f 563 zlog_debug("%s: path %s wins over path %s due to eBGP peer > iBGP peer",
9fbdd100
DS
564 pfx_buf, new->peer->host, exist->peer->host);
565 return 1;
566 }
567
8ff56318
JBD
568 if (exist_sort == BGP_PEER_EBGP
569 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
9fbdd100
DS
570 {
571 if (debug)
31a4638f 572 zlog_debug("%s: path %s loses to path %s due to iBGP peer < eBGP peer",
9fbdd100
DS
573 pfx_buf, new->peer->host, exist->peer->host);
574 return 0;
575 }
718e3744 576
577 /* 8. IGP metric check. */
8ff56318
JBD
578 newm = existm = 0;
579
580 if (new->extra)
581 newm = new->extra->igpmetric;
582 if (exist->extra)
583 existm = exist->extra->igpmetric;
584
96450faf 585 if (newm < existm)
9fbdd100
DS
586 {
587 if (debug)
588 zlog_debug("%s: path %s wins over path %s due to IGP metric %d < %d",
589 pfx_buf, new->peer->host, exist->peer->host, newm, existm);
590 ret = 1;
591 }
592
96450faf 593 if (newm > existm)
9fbdd100
DS
594 {
595 if (debug)
596 zlog_debug("%s: path %s loses to path %s due to IGP metric %d > %d",
597 pfx_buf, new->peer->host, exist->peer->host, newm, existm);
598 ret = 0;
599 }
718e3744 600
31a4638f 601 /* 9. Same IGP metric. Compare the cluster list length as
5e242b0d
DS
602 representative of IGP hops metric. Rewrite the metric value
603 pair (newm, existm) with the cluster list length. Prefer the
604 path with smaller cluster list length. */
605 if (newm == existm)
606 {
607 if (peer_sort (new->peer) == BGP_PEER_IBGP
608 && peer_sort (exist->peer) == BGP_PEER_IBGP
609 && CHECK_FLAG (mpath_cfg->ibgp_flags,
610 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
611 {
612 newm = BGP_CLUSTER_LIST_LENGTH(new->attr);
613 existm = BGP_CLUSTER_LIST_LENGTH(exist->attr);
9fbdd100 614
5e242b0d 615 if (newm < existm)
9fbdd100
DS
616 {
617 if (debug)
618 zlog_debug("%s: path %s wins over path %s due to CLUSTER_LIST length %d < %d",
619 pfx_buf, new->peer->host, exist->peer->host, newm,
620 existm);
621 ret = 1;
622 }
623
5e242b0d 624 if (newm > existm)
9fbdd100
DS
625 {
626 if (debug)
627 zlog_debug("%s: path %s loses to path %s due to CLUSTER_LIST length %d > %d",
628 pfx_buf, new->peer->host, exist->peer->host, newm,
629 existm);
630 ret = 0;
631 }
5e242b0d
DS
632 }
633 }
634
31a4638f
DS
635 /* 10. confed-external vs. confed-internal */
636 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
637 {
638 if (new_sort == BGP_PEER_CONFED && exist_sort == BGP_PEER_IBGP)
639 {
640 if (debug)
641 zlog_debug("%s: path %s wins over path %s due to confed-external peer > confed-internal peer",
642 pfx_buf, new->peer->host, exist->peer->host);
643 return 1;
644 }
645
646 if (exist_sort == BGP_PEER_CONFED && new_sort == BGP_PEER_IBGP)
647 {
648 if (debug)
649 zlog_debug("%s: path %s loses to path %s due to confed-internal peer < confed-external peer",
650 pfx_buf, new->peer->host, exist->peer->host);
651 return 0;
652 }
653 }
654
655 /* 11. Maximum path check. */
96450faf
JB
656 if (newm == existm)
657 {
2fdd455c
PM
658 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
659 {
660
661 /*
662 * For the two paths, all comparison steps till IGP metric
663 * have succeeded - including AS_PATH hop count. Since 'bgp
664 * bestpath as-path multipath-relax' knob is on, we don't need
665 * an exact match of AS_PATH. Thus, mark the paths are equal.
666 * That will trigger both these paths to get into the multipath
667 * array.
668 */
669 *paths_eq = 1;
9fbdd100
DS
670
671 if (debug)
672 zlog_debug("%s: path %s and path %s are equal via multipath-relax",
673 pfx_buf, new->peer->host, exist->peer->host);
2fdd455c
PM
674 }
675 else if (new->peer->sort == BGP_PEER_IBGP)
96450faf
JB
676 {
677 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
9fbdd100
DS
678 {
679 *paths_eq = 1;
680
681 if (debug)
682 zlog_debug("%s: path %s and path %s are equal via matching aspaths",
683 pfx_buf, new->peer->host, exist->peer->host);
684 }
96450faf
JB
685 }
686 else if (new->peer->as == exist->peer->as)
9fbdd100
DS
687 {
688 *paths_eq = 1;
689
690 if (debug)
691 zlog_debug("%s: path %s and path %s are equal via same remote-as",
692 pfx_buf, new->peer->host, exist->peer->host);
693 }
96450faf
JB
694 }
695 else
696 {
697 /*
698 * TODO: If unequal cost ibgp multipath is enabled we can
699 * mark the paths as equal here instead of returning
700 */
701 return ret;
702 }
718e3744 703
31a4638f 704 /* 12. If both paths are external, prefer the path that was received
718e3744 705 first (the oldest one). This step minimizes route-flap, since a
706 newer path won't displace an older one, even if it was the
707 preferred route based on the additional decision criteria below. */
708 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
8ff56318
JBD
709 && new_sort == BGP_PEER_EBGP
710 && exist_sort == BGP_PEER_EBGP)
718e3744 711 {
712 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
9fbdd100
DS
713 {
714 if (debug)
715 zlog_debug("%s: path %s wins over path %s due to oldest external",
716 pfx_buf, new->peer->host, exist->peer->host);
717 return 1;
718 }
719
718e3744 720 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
9fbdd100
DS
721 {
722 if (debug)
723 zlog_debug("%s: path %s loses to path %s due to oldest external",
724 pfx_buf, new->peer->host, exist->peer->host);
725 return 0;
726 }
718e3744 727 }
728
31a4638f 729 /* 13. Router-ID comparision. */
0de5153c
DS
730 /* If one of the paths is "stale", the corresponding peer router-id will
731 * be 0 and would always win over the other path. If originator id is
732 * used for the comparision, it will decide which path is better.
733 */
8ff56318
JBD
734 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
735 new_id.s_addr = newattre->originator_id.s_addr;
718e3744 736 else
737 new_id.s_addr = new->peer->remote_id.s_addr;
8ff56318
JBD
738 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
739 exist_id.s_addr = existattre->originator_id.s_addr;
718e3744 740 else
741 exist_id.s_addr = exist->peer->remote_id.s_addr;
742
743 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
9fbdd100
DS
744 {
745 if (debug)
746 zlog_debug("%s: path %s wins over path %s due to Router-ID comparison",
747 pfx_buf, new->peer->host, exist->peer->host);
748 return 1;
749 }
750
718e3744 751 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
9fbdd100
DS
752 {
753 if (debug)
754 zlog_debug("%s: path %s loses to path %s due to Router-ID comparison",
755 pfx_buf, new->peer->host, exist->peer->host);
756 return 0;
757 }
718e3744 758
31a4638f 759 /* 14. Cluster length comparision. */
5e242b0d
DS
760 new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
761 exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
718e3744 762
763 if (new_cluster < exist_cluster)
9fbdd100
DS
764 {
765 if (debug)
766 zlog_debug("%s: path %s wins over path %s due to CLUSTER_LIST length %d < %d",
767 pfx_buf, new->peer->host, exist->peer->host, new_cluster,
768 exist_cluster);
769 return 1;
770 }
771
718e3744 772 if (new_cluster > exist_cluster)
9fbdd100
DS
773 {
774 if (debug)
775 zlog_debug("%s: path %s loses to path %s due to CLUSTER_LIST length %d > %d",
776 pfx_buf, new->peer->host, exist->peer->host, new_cluster,
777 exist_cluster);
778 return 0;
779 }
718e3744 780
31a4638f 781 /* 15. Neighbor address comparision. */
0de5153c
DS
782 /* Do this only if neither path is "stale" as stale paths do not have
783 * valid peer information (as the connection may or may not be up).
784 */
785 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
9fbdd100
DS
786 {
787 if (debug)
788 zlog_debug("%s: path %s wins over path %s due to latter path being STALE",
789 pfx_buf, new->peer->host, exist->peer->host);
790 return 1;
791 }
792
0de5153c 793 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
9fbdd100
DS
794 {
795 if (debug)
796 zlog_debug("%s: path %s loses to path %s due to former path being STALE",
797 pfx_buf, new->peer->host, exist->peer->host);
798 return 0;
799 }
0de5153c 800
718e3744 801 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
802
803 if (ret == 1)
9fbdd100
DS
804 {
805 if (debug)
806 zlog_debug("%s: path %s loses to path %s due to Neighor IP comparison",
807 pfx_buf, new->peer->host, exist->peer->host);
808 return 0;
809 }
810
718e3744 811 if (ret == -1)
9fbdd100
DS
812 {
813 if (debug)
814 zlog_debug("%s: path %s wins over path %s due to Neighor IP comparison",
815 pfx_buf, new->peer->host, exist->peer->host);
816 return 1;
817 }
818
819 if (debug)
820 zlog_debug("%s: path %s wins over path %s due to nothing left to compare",
821 pfx_buf, new->peer->host, exist->peer->host);
718e3744 822
823 return 1;
824}
825
94f2b392 826static enum filter_type
718e3744 827bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
828 afi_t afi, safi_t safi)
829{
830 struct bgp_filter *filter;
831
832 filter = &peer->filter[afi][safi];
833
650f76c2
PJ
834#define FILTER_EXIST_WARN(F,f,filter) \
835 if (BGP_DEBUG (update, UPDATE_IN) \
836 && !(F ## _IN (filter))) \
16286195 837 zlog_warn ("%s: Could not find configured input %s-list %s!", \
650f76c2
PJ
838 peer->host, #f, F ## _IN_NAME(filter));
839
840 if (DISTRIBUTE_IN_NAME (filter)) {
841 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
842
718e3744 843 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
844 return FILTER_DENY;
650f76c2 845 }
718e3744 846
650f76c2
PJ
847 if (PREFIX_LIST_IN_NAME (filter)) {
848 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
849
718e3744 850 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
851 return FILTER_DENY;
650f76c2 852 }
718e3744 853
650f76c2
PJ
854 if (FILTER_LIST_IN_NAME (filter)) {
855 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
856
718e3744 857 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
858 return FILTER_DENY;
650f76c2
PJ
859 }
860
718e3744 861 return FILTER_PERMIT;
650f76c2 862#undef FILTER_EXIST_WARN
718e3744 863}
864
94f2b392 865static enum filter_type
718e3744 866bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
867 afi_t afi, safi_t safi)
868{
869 struct bgp_filter *filter;
870
871 filter = &peer->filter[afi][safi];
872
650f76c2
PJ
873#define FILTER_EXIST_WARN(F,f,filter) \
874 if (BGP_DEBUG (update, UPDATE_OUT) \
875 && !(F ## _OUT (filter))) \
16286195 876 zlog_warn ("%s: Could not find configured output %s-list %s!", \
650f76c2
PJ
877 peer->host, #f, F ## _OUT_NAME(filter));
878
879 if (DISTRIBUTE_OUT_NAME (filter)) {
880 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
881
718e3744 882 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
883 return FILTER_DENY;
650f76c2 884 }
718e3744 885
650f76c2
PJ
886 if (PREFIX_LIST_OUT_NAME (filter)) {
887 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
888
718e3744 889 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
890 return FILTER_DENY;
650f76c2 891 }
718e3744 892
650f76c2
PJ
893 if (FILTER_LIST_OUT_NAME (filter)) {
894 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
895
718e3744 896 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
897 return FILTER_DENY;
650f76c2 898 }
718e3744 899
900 return FILTER_PERMIT;
650f76c2 901#undef FILTER_EXIST_WARN
718e3744 902}
903
904/* If community attribute includes no_export then return 1. */
94f2b392 905static int
718e3744 906bgp_community_filter (struct peer *peer, struct attr *attr)
907{
908 if (attr->community)
909 {
910 /* NO_ADVERTISE check. */
911 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
912 return 1;
913
914 /* NO_EXPORT check. */
6d85b15b 915 if (peer->sort == BGP_PEER_EBGP &&
718e3744 916 community_include (attr->community, COMMUNITY_NO_EXPORT))
917 return 1;
918
919 /* NO_EXPORT_SUBCONFED check. */
6d85b15b
JBD
920 if (peer->sort == BGP_PEER_EBGP
921 || peer->sort == BGP_PEER_CONFED)
718e3744 922 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
923 return 1;
924 }
925 return 0;
926}
927
928/* Route reflection loop check. */
929static int
930bgp_cluster_filter (struct peer *peer, struct attr *attr)
931{
932 struct in_addr cluster_id;
933
fb982c25 934 if (attr->extra && attr->extra->cluster)
718e3744 935 {
936 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
937 cluster_id = peer->bgp->cluster_id;
938 else
939 cluster_id = peer->bgp->router_id;
940
fb982c25 941 if (cluster_loop_check (attr->extra->cluster, cluster_id))
718e3744 942 return 1;
943 }
944 return 0;
945}
6b0655a2 946
94f2b392 947static int
718e3744 948bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
ffd0c037 949 afi_t afi, safi_t safi, const char *rmap_name)
718e3744 950{
951 struct bgp_filter *filter;
952 struct bgp_info info;
953 route_map_result_t ret;
0b16f239 954 struct route_map *rmap = NULL;
718e3744 955
956 filter = &peer->filter[afi][safi];
957
958 /* Apply default weight value. */
fb982c25
PJ
959 if (peer->weight)
960 (bgp_attr_extra_get (attr))->weight = peer->weight;
718e3744 961
0b16f239
DS
962 if (rmap_name)
963 {
964 rmap = route_map_lookup_by_name(rmap_name);
98a4a44e
DS
965
966 if (rmap == NULL)
967 return RMAP_DENY;
0b16f239
DS
968 }
969 else
970 {
971 if (ROUTE_MAP_IN_NAME(filter))
98a4a44e
DS
972 {
973 rmap = ROUTE_MAP_IN (filter);
974
975 if (rmap == NULL)
976 return RMAP_DENY;
977 }
0b16f239
DS
978 }
979
718e3744 980 /* Route map apply. */
0b16f239 981 if (rmap)
718e3744 982 {
983 /* Duplicate current value to new strucutre for modification. */
984 info.peer = peer;
985 info.attr = attr;
986
ac41b2a2 987 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
988
718e3744 989 /* Apply BGP route map to the attribute. */
0b16f239
DS
990 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
991
992 peer->rmap_type = 0;
993
994 if (ret == RMAP_DENYMATCH)
995 {
996 /* Free newly generated AS path and community by route-map. */
997 bgp_attr_flush (attr);
998 return RMAP_DENY;
999 }
1000 }
1001 return RMAP_PERMIT;
1002}
1003
1004static int
1005bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
ffd0c037 1006 afi_t afi, safi_t safi, const char *rmap_name)
0b16f239
DS
1007{
1008 struct bgp_filter *filter;
1009 struct bgp_info info;
1010 route_map_result_t ret;
1011 struct route_map *rmap = NULL;
1012
1013 filter = &peer->filter[afi][safi];
1014
1015 /* Apply default weight value. */
1016 if (peer->weight)
1017 (bgp_attr_extra_get (attr))->weight = peer->weight;
1018
1019 if (rmap_name)
1020 {
1021 rmap = route_map_lookup_by_name(rmap_name);
98a4a44e
DS
1022
1023 if (rmap == NULL)
1024 return RMAP_DENY;
0b16f239
DS
1025 }
1026 else
1027 {
1028 if (ROUTE_MAP_OUT_NAME(filter))
98a4a44e
DS
1029 {
1030 rmap = ROUTE_MAP_OUT (filter);
1031
1032 if (rmap == NULL)
1033 return RMAP_DENY;
1034 }
0b16f239
DS
1035 }
1036
1037 /* Route map apply. */
1038 if (rmap)
1039 {
1040 /* Duplicate current value to new strucutre for modification. */
1041 info.peer = peer;
1042 info.attr = attr;
1043
1044 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1045
1046 /* Apply BGP route map to the attribute. */
1047 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
ac41b2a2 1048
1049 peer->rmap_type = 0;
1050
718e3744 1051 if (ret == RMAP_DENYMATCH)
c460e572
DL
1052 /* caller has multiple error paths with bgp_attr_flush() */
1053 return RMAP_DENY;
718e3744 1054 }
1055 return RMAP_PERMIT;
1056}
6b0655a2 1057
5000f21c 1058/* If this is an EBGP peer with remove-private-AS */
ffd0c037 1059static void
5000f21c
DS
1060bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
1061 struct peer *peer, struct attr *attr)
1062{
1063 if (peer->sort == BGP_PEER_EBGP &&
88b8ed8d
DW
1064 (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1065 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE) ||
1066 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL) ||
1067 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)))
5000f21c
DS
1068 {
1069 // Take action on the entire aspath
88b8ed8d
DW
1070 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1071 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
5000f21c 1072 {
88b8ed8d 1073 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
5000f21c
DS
1074 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1075
1076 // The entire aspath consists of private ASNs so create an empty aspath
1077 else if (aspath_private_as_check (attr->aspath))
1078 attr->aspath = aspath_empty_get ();
1079
1080 // There are some public and some private ASNs, remove the private ASNs
1081 else
1082 attr->aspath = aspath_remove_private_asns (attr->aspath);
1083 }
1084
1085 // 'all' was not specified so the entire aspath must be private ASNs
1086 // for us to do anything
1087 else if (aspath_private_as_check (attr->aspath))
1088 {
1089 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
1090 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1091 else
1092 attr->aspath = aspath_empty_get ();
1093 }
1094 }
1095}
1096
c7122e14
DS
1097/* If this is an EBGP peer with as-override */
1098static void
1099bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
1100 struct peer *peer, struct attr *attr)
1101{
1102 if (peer->sort == BGP_PEER_EBGP &&
1103 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
1104 {
1105 if (aspath_single_asn_check (attr->aspath, peer->as))
1106 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
1107 }
1108}
1109
3f9c7369
DS
1110static void
1111subgroup_announce_reset_nhop (u_char family, struct attr *attr)
1112{
1113 if (family == AF_INET)
1114 attr->nexthop.s_addr = 0;
1115#ifdef HAVE_IPV6
1116 if (family == AF_INET6)
1117 memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
1118#endif
1119}
1120
1121int
1122subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp,
1123 struct prefix *p, struct attr *attr)
1124{
1125 struct bgp_filter *filter;
1126 struct peer *from;
1127 struct peer *peer;
1128 struct peer *onlypeer;
1129 struct bgp *bgp;
1130 struct attr *riattr;
1131 struct peer_af *paf;
1132 char buf[SU_ADDRSTRLEN];
1133 int ret;
1134 int transparent;
1135 int reflect;
1136 afi_t afi;
1137 safi_t safi;
1138
1139 if (DISABLE_BGP_ANNOUNCE)
1140 return 0;
1141
1142 afi = SUBGRP_AFI(subgrp);
1143 safi = SUBGRP_SAFI(subgrp);
1144 peer = SUBGRP_PEER(subgrp);
1145 onlypeer = NULL;
1146 if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL))
1147 onlypeer = SUBGRP_PFIRST(subgrp)->peer;
1148
1149 from = ri->peer;
1150 filter = &peer->filter[afi][safi];
1151 bgp = SUBGRP_INST(subgrp);
1152 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1153
adbac85e
DW
1154 /* With addpath we may be asked to TX all kinds of paths so make sure
1155 * ri is valid */
1156 if (!CHECK_FLAG (ri->flags, BGP_INFO_VALID) ||
1157 CHECK_FLAG (ri->flags, BGP_INFO_HISTORY) ||
1158 CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
1159 {
1160 return 0;
1161 }
1162
06370dac
DW
1163 /* If this is not the bestpath then check to see if there is an enabled addpath
1164 * feature that requires us to advertise it */
1165 if (! CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1166 {
1167 if (! bgp_addpath_tx_path(peer, afi, safi, ri))
1168 {
1169 return 0;
1170 }
1171 }
1172
3f9c7369
DS
1173 /* Aggregate-address suppress check. */
1174 if (ri->extra && ri->extra->suppress)
1175 if (! UNSUPPRESS_MAP_NAME (filter))
1176 {
1177 return 0;
1178 }
1179
3f9c7369
DS
1180 /* Do not send back route to sender. */
1181 if (onlypeer && from == onlypeer)
1182 {
1183 return 0;
1184 }
1185
4125bb67
DS
1186 /* Do not send the default route in the BGP table if the neighbor is
1187 * configured for default-originate */
1188 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
1189 {
1190 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1191 return 0;
1192#ifdef HAVE_IPV6
1193 else if (p->family == AF_INET6 && p->prefixlen == 0)
1194 return 0;
1195#endif /* HAVE_IPV6 */
1196 }
1197
3f9c7369
DS
1198 /* Transparency check. */
1199 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1200 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1201 transparent = 1;
1202 else
1203 transparent = 0;
1204
1205 /* If community is not disabled check the no-export and local. */
1206 if (! transparent && bgp_community_filter (peer, riattr))
1207 {
1208 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1209 zlog_debug ("subgrpannouncecheck: community filter check fail");
1210 return 0;
1211 }
1212
1213 /* If the attribute has originator-id and it is same as remote
1214 peer's id. */
1215 if (onlypeer &&
1216 riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) &&
1217 (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id)))
1218 {
1219 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1220 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as "
1221 "remote router-id",
1222 onlypeer->host,
1223 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1224 p->prefixlen);
1225 return 0;
1226 }
1227
1228 /* ORF prefix-list filter check */
1229 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1230 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1231 || CHECK_FLAG (peer->af_cap[afi][safi],
1232 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1233 if (peer->orf_plist[afi][safi])
1234 {
1235 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1236 {
40d2700d
DW
1237 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1238 zlog_debug ("%s [Update:SEND] %s/%d is filtered via ORF",
1239 peer->host,
1240 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1241 p->prefixlen);
3f9c7369
DS
1242 return 0;
1243 }
1244 }
1245
1246 /* Output filter check. */
1247 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1248 {
1249 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1250 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1251 peer->host,
1252 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1253 p->prefixlen);
1254 return 0;
1255 }
1256
1257#ifdef BGP_SEND_ASPATH_CHECK
1258 /* AS path loop check. */
1259 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
1260 {
1261 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1262 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1263 "that is part of AS path.",
1264 onlypeer->host, onlypeer->as);
1265 return 0;
1266 }
1267#endif /* BGP_SEND_ASPATH_CHECK */
1268
1269 /* If we're a CONFED we need to loop check the CONFED ID too */
1270 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1271 {
1272 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1273 {
1274 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1275 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u"
1276 " is AS path.",
1277 peer->host,
1278 bgp->confed_id);
1279 return 0;
1280 }
1281 }
1282
1283 /* Route-Reflect check. */
1284 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1285 reflect = 1;
1286 else
1287 reflect = 0;
1288
1289 /* IBGP reflection check. */
1290 if (reflect)
1291 {
1292 /* A route from a Client peer. */
1293 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1294 {
1295 /* Reflect to all the Non-Client peers and also to the
1296 Client peers other than the originator. Originator check
1297 is already done. So there is noting to do. */
1298 /* no bgp client-to-client reflection check. */
1299 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1300 if (CHECK_FLAG (peer->af_flags[afi][safi],
1301 PEER_FLAG_REFLECTOR_CLIENT))
1302 return 0;
1303 }
1304 else
1305 {
1306 /* A route from a Non-client peer. Reflect to all other
1307 clients. */
1308 if (! CHECK_FLAG (peer->af_flags[afi][safi],
1309 PEER_FLAG_REFLECTOR_CLIENT))
1310 return 0;
1311 }
1312 }
1313
1314 /* For modify attribute, copy it to temporary structure. */
1315 bgp_attr_dup (attr, riattr);
1316
1317 /* If local-preference is not set. */
1318 if ((peer->sort == BGP_PEER_IBGP
1319 || peer->sort == BGP_PEER_CONFED)
1320 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1321 {
1322 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1323 attr->local_pref = bgp->default_local_pref;
1324 }
1325
1326 /* If originator-id is not set and the route is to be reflected,
1327 set the originator id */
1328 if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1329 {
1330 attr->extra = bgp_attr_extra_get(attr);
1331 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1332 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1333 }
1334
1335 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1336 if (peer->sort == BGP_PEER_EBGP
1337 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1338 {
003c1ba0 1339 if (from != bgp->peer_self && ! transparent
3f9c7369
DS
1340 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1341 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1342 }
1343
1344 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1345 * in announce check, only certain flags and length (or number of nexthops
1346 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1347 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1348 * Typically, the source nexthop in the attribute is preserved but in the
1349 * scenarios where we know it will always be overwritten, we reset the
1350 * nexthop to "0" in an attempt to achieve better Update packing. An
1351 * example of this is when a prefix from each of 2 IBGP peers needs to be
1352 * announced to an EBGP peer (and they have the same attributes barring
1353 * their nexthop).
1354 */
1355 if (reflect)
1356 SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
1357
1358#ifdef HAVE_IPV6
3811f1e2
DS
1359 /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if
1360 * the peer (group) is configured to receive link-local nexthop unchanged
1361 * and it is available in the prefix OR we're not reflecting the route and
1362 * the peer (group) to whom we're going to announce is on a shared network
003c1ba0 1363 * and this is either a self-originated route or the peer is EBGP.
3f9c7369 1364 */
8a92a8a0 1365 if (p->family == AF_INET6 || peer_cap_enhe(peer))
3f9c7369 1366 {
801a9bcc 1367 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
3811f1e2
DS
1368 if ((CHECK_FLAG (peer->af_flags[afi][safi],
1369 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1370 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) ||
003c1ba0 1371 (!reflect && peer->shared_network &&
1372 (from == bgp->peer_self || peer->sort == BGP_PEER_EBGP)))
3f9c7369 1373 {
3811f1e2 1374 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
3f9c7369
DS
1375 }
1376
3811f1e2
DS
1377 /* Clear off link-local nexthop in source, whenever it is not needed to
1378 * ensure more prefixes share the same attribute for announcement.
3f9c7369
DS
1379 */
1380 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1381 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1382 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1383 }
1384#endif /* HAVE_IPV6 */
1385
1386 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1387 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1388
1389 /* Route map & unsuppress-map apply. */
1390 if (ROUTE_MAP_OUT_NAME (filter)
1391 || (ri->extra && ri->extra->suppress) )
1392 {
1393 struct bgp_info info;
1394 struct attr dummy_attr;
1395 struct attr_extra dummy_extra;
1396
1397 dummy_attr.extra = &dummy_extra;
1398
1399 info.peer = peer;
1400 info.attr = attr;
316e074d
DS
1401 /* don't confuse inbound and outbound setting */
1402 RESET_FLAG(attr->rmap_change_flags);
3f9c7369
DS
1403
1404 /*
1405 * The route reflector is not allowed to modify the attributes
1406 * of the reflected IBGP routes unless explicitly allowed.
1407 */
1408 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1409 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1410 {
1411 bgp_attr_dup (&dummy_attr, attr);
1412 info.attr = &dummy_attr;
1413 }
1414
1415 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1416
1417 if (ri->extra && ri->extra->suppress)
1418 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1419 else
1420 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1421
1422 peer->rmap_type = 0;
1423
1424 if (ret == RMAP_DENYMATCH)
1425 {
1426 bgp_attr_flush (attr);
1427 return 0;
1428 }
1429 }
1430
1431 /* After route-map has been applied, we check to see if the nexthop to
1432 * be carried in the attribute (that is used for the announcement) can
1433 * be cleared off or not. We do this in all cases where we would be
1434 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1435 * the global nexthop here; the link-local nexthop would have been cleared
1436 * already, and if not, it is required by the update formation code.
1437 * Also see earlier comments in this function.
43fdf718 1438 */
3811f1e2
DS
1439 /*
1440 * If route-map has performed some operation on the nexthop or the peer
1441 * configuration says to pass it unchanged, we cannot reset the nexthop
1442 * here, so only attempt to do it if these aren't true. Note that the
1443 * route-map handler itself might have cleared the nexthop, if for example,
1444 * it is configured as 'peer-address'.
3f9c7369 1445 */
3811f1e2
DS
1446 if (!bgp_rmap_nhop_changed(attr->rmap_change_flags,
1447 riattr->rmap_change_flags) &&
1448 !transparent &&
1449 !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
3f9c7369 1450 {
3811f1e2 1451 /* We can reset the nexthop, if setting (or forcing) it to 'self' */
88b8ed8d
DW
1452 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
1453 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
3f9c7369
DS
1454 {
1455 if (!reflect ||
1456 CHECK_FLAG (peer->af_flags[afi][safi],
43fdf718 1457 PEER_FLAG_FORCE_NEXTHOP_SELF))
3811f1e2
DS
1458 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ?
1459 AF_INET6 : p->family), attr);
3f9c7369
DS
1460 }
1461 else if (peer->sort == BGP_PEER_EBGP)
1462 {
3811f1e2
DS
1463 /* Can also reset the nexthop if announcing to EBGP, but only if
1464 * no peer in the subgroup is on a shared subnet.
1465 * Note: 3rd party nexthop currently implemented for IPv4 only.
1466 */
3f9c7369
DS
1467 SUBGRP_FOREACH_PEER (subgrp, paf)
1468 {
1469 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1470 break;
1471 }
1472 if (!paf)
8a92a8a0 1473 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr);
3f9c7369 1474 }
003c1ba0 1475 /* If IPv6/MP and nexthop does not have any override and happens to
1476 * be a link-local address, reset it so that we don't pass along the
1477 * source's link-local IPv6 address to recipients who may not be on
1478 * the same interface.
1479 */
1480 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1481 {
1482 if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global))
1483 subgroup_announce_reset_nhop (AF_INET6, attr);
1484 }
3f9c7369
DS
1485 }
1486
1487 return 1;
1488}
1489
fee0f4c6 1490struct bgp_info_pair
1491{
1492 struct bgp_info *old;
1493 struct bgp_info *new;
1494};
1495
94f2b392 1496static void
96450faf
JB
1497bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1498 struct bgp_maxpaths_cfg *mpath_cfg,
1499 struct bgp_info_pair *result)
718e3744 1500{
718e3744 1501 struct bgp_info *new_select;
1502 struct bgp_info *old_select;
fee0f4c6 1503 struct bgp_info *ri;
718e3744 1504 struct bgp_info *ri1;
1505 struct bgp_info *ri2;
b40d939b 1506 struct bgp_info *nextri = NULL;
9fbdd100 1507 int paths_eq, do_mpath, debug;
96450faf 1508 struct list mp_list;
4690c7d7 1509 char pfx_buf[PREFIX2STR_BUFFER];
96450faf
JB
1510
1511 bgp_mp_list_init (&mp_list);
99030da1 1512 do_mpath = (mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1);
96450faf 1513
9fbdd100
DS
1514 debug = bgp_debug_bestpath(&rn->p);
1515
1516 if (debug)
1517 prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf));
1518
718e3744 1519 /* bgp deterministic-med */
1520 new_select = NULL;
1521 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
06370dac
DW
1522 {
1523
1524 /* Clear BGP_INFO_DMED_SELECTED for all paths */
1525 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1526 bgp_info_unset_flag (rn, ri1, BGP_INFO_DMED_SELECTED);
1527
1528 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1529 {
1530 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1531 continue;
1532 if (BGP_INFO_HOLDDOWN (ri1))
2fed8887 1533 continue;
06370dac
DW
1534 if (ri1->peer && ri1->peer != bgp->peer_self)
1535 if (ri1->peer->status != Established)
1536 continue;
718e3744 1537
06370dac
DW
1538 new_select = ri1;
1539 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
1540 if (ri1->next)
1541 {
1542 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1543 {
1544 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1545 continue;
1546 if (BGP_INFO_HOLDDOWN (ri2))
1547 continue;
1548 if (ri2->peer &&
1549 ri2->peer != bgp->peer_self &&
1550 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1551 if (ri2->peer->status != Established)
1552 continue;
1553
1554 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1555 || aspath_cmp_left_confed (ri1->attr->aspath,
1556 ri2->attr->aspath))
1557 {
1558 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1559 old_select = ri2;
1560 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
1561 mpath_cfg, debug, pfx_buf))
1562 {
1563 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1564 new_select = ri2;
1565 }
1566
1567 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1568 }
1569 }
1570 }
1571 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1572 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
718e3744 1573
06370dac
DW
1574 if (debug)
1575 zlog_debug("%s: path %s is the bestpath from AS %d",
1576 pfx_buf, new_select->peer->host,
1577 aspath_get_firstas(new_select->attr->aspath));
1578 }
1579 }
718e3744 1580
1581 /* Check old selected route and new selected route. */
1582 old_select = NULL;
1583 new_select = NULL;
b40d939b 1584 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
718e3744 1585 {
1586 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1587 old_select = ri;
1588
1589 if (BGP_INFO_HOLDDOWN (ri))
b40d939b 1590 {
1591 /* reap REMOVED routes, if needs be
1592 * selected route must stay for a while longer though
1593 */
1594 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1595 && (ri != old_select))
1596 bgp_info_reap (rn, ri);
1597
1598 continue;
1599 }
718e3744 1600
2fed8887
DS
1601 if (ri->peer &&
1602 ri->peer != bgp->peer_self &&
1603 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1604 if (ri->peer->status != Established)
1605 continue;
1606
718e3744 1607 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1608 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1609 {
1a392d46 1610 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
718e3744 1611 continue;
1612 }
06370dac 1613
1a392d46 1614 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
718e3744 1615
9fbdd100 1616 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
96450faf
JB
1617 {
1618 new_select = ri;
96450faf 1619 }
718e3744 1620 }
b40d939b 1621
f4eeff72
DS
1622 /* Now that we know which path is the bestpath see if any of the other paths
1623 * qualify as multipaths
1624 */
1625 if (do_mpath && new_select)
1626 {
9fbdd100
DS
1627 if (debug)
1628 zlog_debug("%s: path %s is the bestpath, now find multipaths",
1629 pfx_buf, new_select->peer->host);
1630
f4eeff72
DS
1631 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1632 {
1633 if (ri == new_select)
1634 {
9fbdd100
DS
1635 if (debug)
1636 zlog_debug("%s: path %s is the bestpath, add to the multipath list",
1637 pfx_buf, ri->peer->host);
f4eeff72
DS
1638 bgp_mp_list_add (&mp_list, ri);
1639 continue;
1640 }
1641
1642 if (BGP_INFO_HOLDDOWN (ri))
1643 continue;
1644
1645 if (ri->peer &&
1646 ri->peer != bgp->peer_self &&
1647 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1648 if (ri->peer->status != Established)
1649 continue;
1650
7dc9d4e4
DW
1651 if (!bgp_info_nexthop_cmp (ri, new_select))
1652 {
1653 if (debug)
1654 zlog_debug("%s: path %s has the same nexthop as the bestpath, skip it",
1655 pfx_buf, ri->peer->host);
1656 continue;
1657 }
1658
9fbdd100 1659 bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
f4eeff72
DS
1660
1661 if (paths_eq)
1662 {
9fbdd100 1663 if (debug)
7dc9d4e4 1664 zlog_debug("%s: path %s is equivalent to the bestpath, add to the multipath list",
9fbdd100 1665 pfx_buf, ri->peer->host);
f4eeff72
DS
1666 bgp_mp_list_add (&mp_list, ri);
1667 }
1668 }
1669 }
fee0f4c6 1670
b354c427 1671 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
0b597ef0 1672 bgp_info_mpath_aggregate_update (new_select, old_select);
96450faf
JB
1673 bgp_mp_list_clear (&mp_list);
1674
1675 result->old = old_select;
1676 result->new = new_select;
1677
1678 return;
fee0f4c6 1679}
1680
3f9c7369
DS
1681/*
1682 * A new route/change in bestpath of an existing route. Evaluate the path
1683 * for advertisement to the subgroup.
1684 */
1685int
1686subgroup_process_announce_selected (struct update_subgroup *subgrp,
1687 struct bgp_info *selected,
adbac85e
DW
1688 struct bgp_node *rn,
1689 u_int32_t addpath_tx_id)
9eda90ce 1690{
fee0f4c6 1691 struct prefix *p;
3f9c7369 1692 struct peer *onlypeer;
558d1fec
JBD
1693 struct attr attr;
1694 struct attr_extra extra;
3f9c7369
DS
1695 afi_t afi;
1696 safi_t safi;
fee0f4c6 1697
1698 p = &rn->p;
3f9c7369
DS
1699 afi = SUBGRP_AFI(subgrp);
1700 safi = SUBGRP_SAFI(subgrp);
1701 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1702 (SUBGRP_PFIRST(subgrp))->peer : NULL);
718e3744 1703
9eda90ce 1704 /* First update is deferred until ORF or ROUTE-REFRESH is received */
3f9c7369
DS
1705 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
1706 PEER_STATUS_ORF_WAIT_REFRESH))
fee0f4c6 1707 return 0;
718e3744 1708
2a3d5731 1709 /* It's initialized in bgp_announce_check() */
558d1fec
JBD
1710 attr.extra = &extra;
1711
2a3d5731
DW
1712 /* Announcement to the subgroup. If the route is filtered withdraw it. */
1713 if (selected)
fee0f4c6 1714 {
2a3d5731
DW
1715 if (subgroup_announce_check(selected, subgrp, p, &attr))
1716 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
1717 else
1718 bgp_adj_out_unset_subgroup(rn, subgrp, 1, selected->addpath_tx_id);
1719 }
adbac85e 1720
2a3d5731
DW
1721 /* If selected is NULL we must withdraw the path using addpath_tx_id */
1722 else
1723 {
1724 bgp_adj_out_unset_subgroup(rn, subgrp, 1, addpath_tx_id);
fee0f4c6 1725 }
558d1fec 1726
fee0f4c6 1727 return 0;
200df115 1728}
fee0f4c6 1729
3f9c7369 1730struct bgp_process_queue
fee0f4c6 1731{
200df115 1732 struct bgp *bgp;
1733 struct bgp_node *rn;
1734 afi_t afi;
1735 safi_t safi;
1736};
1737
200df115 1738static wq_item_status
0fb58d5d 1739bgp_process_main (struct work_queue *wq, void *data)
200df115 1740{
0fb58d5d 1741 struct bgp_process_queue *pq = data;
200df115 1742 struct bgp *bgp = pq->bgp;
1743 struct bgp_node *rn = pq->rn;
1744 afi_t afi = pq->afi;
1745 safi_t safi = pq->safi;
1746 struct prefix *p = &rn->p;
fee0f4c6 1747 struct bgp_info *new_select;
1748 struct bgp_info *old_select;
1749 struct bgp_info_pair old_and_new;
cb1faec9
DS
1750
1751 /* Is it end of initial update? (after startup) */
1752 if (!rn)
1753 {
4a16ae86
DS
1754 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1755 sizeof(bgp->update_delay_zebra_resume_time));
1756
1757 bgp->main_zebra_update_hold = 0;
1758 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1759 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1760 {
1761 bgp_zebra_announce_table(bgp, afi, safi);
1762 }
1763 bgp->main_peers_update_hold = 0;
1764
cb1faec9
DS
1765 bgp_start_routeadv(bgp);
1766 return WQ_SUCCESS;
1767 }
1768
fee0f4c6 1769 /* Best path selection. */
96450faf 1770 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 1771 old_select = old_and_new.old;
1772 new_select = old_and_new.new;
1773
1774 /* Nothing to do. */
adbac85e
DW
1775 if (old_select && old_select == new_select &&
1776 !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR) &&
1777 !CHECK_FLAG(old_select->flags, BGP_INFO_ATTR_CHANGED) &&
1778 !bgp->addpath_tx_used[afi][safi])
1779 {
1780 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1781 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
1782 bgp_zebra_announce (p, old_select, bgp, afi, safi);
200df115 1783
adbac85e
DW
1784 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
1785 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1786 return WQ_SUCCESS;
fee0f4c6 1787 }
1788
8ad7271d
DS
1789 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1790 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1791
3f9c7369
DS
1792 /* bestpath has changed; bump version */
1793 if (old_select || new_select)
0de4848d
DS
1794 {
1795 bgp_bump_version(rn);
1796
1797 if (!bgp->t_rmap_def_originate_eval)
1798 {
1799 bgp_lock (bgp);
9229d914 1800 THREAD_TIMER_ON(bm->master, bgp->t_rmap_def_originate_eval,
0de4848d
DS
1801 update_group_refresh_default_originate_route_map,
1802 bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER);
1803 }
1804 }
3f9c7369 1805
338b3424 1806 if (old_select)
1a392d46 1807 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
338b3424 1808 if (new_select)
1809 {
1a392d46
PJ
1810 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1811 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 1812 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
338b3424 1813 }
1814
3f9c7369 1815 group_announce_route(bgp, afi, safi, rn, new_select);
718e3744 1816
1817 /* FIB update. */
5a616c08
B
1818 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1819 ! bgp_option_check (BGP_OPT_NO_FIB)))
718e3744 1820 {
1821 if (new_select
1822 && new_select->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
1823 && (new_select->sub_type == BGP_ROUTE_NORMAL ||
1824 new_select->sub_type == BGP_ROUTE_AGGREGATE))
73ac8160 1825 bgp_zebra_announce (p, new_select, bgp, afi, safi);
718e3744 1826 else
1827 {
1828 /* Withdraw the route from the kernel. */
1829 if (old_select
1830 && old_select->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
1831 && (old_select->sub_type == BGP_ROUTE_NORMAL ||
1832 old_select->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 1833 bgp_zebra_withdraw (p, old_select, safi);
718e3744 1834 }
1835 }
b40d939b 1836
adbac85e 1837 /* Reap old select bgp_info, if it has been removed */
b40d939b 1838 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1839 bgp_info_reap (rn, old_select);
1840
200df115 1841 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1842 return WQ_SUCCESS;
718e3744 1843}
1844
200df115 1845static void
0fb58d5d 1846bgp_processq_del (struct work_queue *wq, void *data)
200df115 1847{
0fb58d5d 1848 struct bgp_process_queue *pq = data;
cb1faec9
DS
1849 struct bgp_table *table;
1850
228da428 1851 bgp_unlock (pq->bgp);
cb1faec9
DS
1852 if (pq->rn)
1853 {
1854 table = bgp_node_table (pq->rn);
1855 bgp_unlock_node (pq->rn);
1856 bgp_table_unlock (table);
1857 }
200df115 1858 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1859}
1860
f188f2c4 1861void
200df115 1862bgp_process_queue_init (void)
1863{
495f0b13
DS
1864 if (!bm->process_main_queue)
1865 {
1866 bm->process_main_queue
87d4a781 1867 = work_queue_new (bm->master, "process_main_queue");
495f0b13 1868
2a3d5731
DW
1869 if ( !bm->process_main_queue)
1870 {
1871 zlog_err ("%s: Failed to allocate work queue", __func__);
1872 exit (1);
1873 }
200df115 1874 }
1875
1876 bm->process_main_queue->spec.workfunc = &bgp_process_main;
200df115 1877 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
838bbde0
PJ
1878 bm->process_main_queue->spec.max_retries = 0;
1879 bm->process_main_queue->spec.hold = 50;
d889623f
DS
1880 /* Use a higher yield value of 50ms for main queue processing */
1881 bm->process_main_queue->spec.yield = 50 * 1000L;
200df115 1882}
1883
1884void
fee0f4c6 1885bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1886{
200df115 1887 struct bgp_process_queue *pqnode;
1888
1889 /* already scheduled for processing? */
1890 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1891 return;
495f0b13 1892
2a3d5731 1893 if (bm->process_main_queue == NULL)
2e02b9b2
DS
1894 bgp_process_queue_init ();
1895
200df115 1896 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1897 sizeof (struct bgp_process_queue));
1898 if (!pqnode)
1899 return;
228da428
CC
1900
1901 /* all unlocked in bgp_processq_del */
67174041 1902 bgp_table_lock (bgp_node_table (rn));
228da428 1903 pqnode->rn = bgp_lock_node (rn);
200df115 1904 pqnode->bgp = bgp;
228da428 1905 bgp_lock (bgp);
200df115 1906 pqnode->afi = afi;
1907 pqnode->safi = safi;
2a3d5731 1908 work_queue_add (bm->process_main_queue, pqnode);
07ff4dc4 1909 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
200df115 1910 return;
fee0f4c6 1911}
0a486e5f 1912
cb1faec9 1913void
2a3d5731 1914bgp_add_eoiu_mark (struct bgp *bgp)
cb1faec9
DS
1915{
1916 struct bgp_process_queue *pqnode;
1917
2a3d5731 1918 if (bm->process_main_queue == NULL)
2e02b9b2
DS
1919 bgp_process_queue_init ();
1920
cb1faec9
DS
1921 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1922 sizeof (struct bgp_process_queue));
1923 if (!pqnode)
1924 return;
1925
1926 pqnode->rn = NULL;
1927 pqnode->bgp = bgp;
1928 bgp_lock (bgp);
2a3d5731 1929 work_queue_add (bm->process_main_queue, pqnode);
cb1faec9
DS
1930}
1931
94f2b392 1932static int
0a486e5f 1933bgp_maximum_prefix_restart_timer (struct thread *thread)
1934{
1935 struct peer *peer;
1936
1937 peer = THREAD_ARG (thread);
1938 peer->t_pmax_restart = NULL;
1939
16286195 1940 if (bgp_debug_neighbor_events(peer))
0a486e5f 1941 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1942 peer->host);
1943
1ff9a340 1944 peer_clear (peer, NULL);
0a486e5f 1945
1946 return 0;
1947}
1948
718e3744 1949int
5228ad27 1950bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1951 safi_t safi, int always)
718e3744 1952{
e0701b79 1953 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1954 return 0;
1955
1956 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
718e3744 1957 {
e0701b79 1958 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1959 && ! always)
1960 return 0;
1961
16286195
DS
1962 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1963 "limit %ld", afi_safi_print (afi, safi), peer->host,
1964 peer->pcount[afi][safi], peer->pmax[afi][safi]);
e0701b79 1965 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1966
1967 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1968 return 0;
1969
1970 {
5228ad27 1971 u_int8_t ndata[7];
e0701b79 1972
1973 if (safi == SAFI_MPLS_VPN)
42e6d745 1974 safi = SAFI_MPLS_LABELED_VPN;
5228ad27 1975
1976 ndata[0] = (afi >> 8);
1977 ndata[1] = afi;
1978 ndata[2] = safi;
1979 ndata[3] = (peer->pmax[afi][safi] >> 24);
1980 ndata[4] = (peer->pmax[afi][safi] >> 16);
1981 ndata[5] = (peer->pmax[afi][safi] >> 8);
1982 ndata[6] = (peer->pmax[afi][safi]);
e0701b79 1983
1984 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1985 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1986 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1987 }
0a486e5f 1988
f14e6fdb
DS
1989 /* Dynamic peers will just close their connection. */
1990 if (peer_dynamic_neighbor (peer))
1991 return 1;
1992
0a486e5f 1993 /* restart timer start */
1994 if (peer->pmax_restart[afi][safi])
1995 {
1996 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1997
16286195 1998 if (bgp_debug_neighbor_events(peer))
0a486e5f 1999 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2000 peer->host, peer->v_pmax_restart);
2001
2002 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2003 peer->v_pmax_restart);
2004 }
2005
e0701b79 2006 return 1;
2007 }
2008 else
2009 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2010
2011 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2012 {
2013 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2014 && ! always)
2015 return 0;
2016
16286195
DS
2017 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2018 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2019 peer->pmax[afi][safi]);
e0701b79 2020 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2021 }
e0701b79 2022 else
2023 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2024 return 0;
2025}
2026
b40d939b 2027/* Unconditionally remove the route from the RIB, without taking
2028 * damping into consideration (eg, because the session went down)
2029 */
94f2b392 2030static void
718e3744 2031bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2032 afi_t afi, safi_t safi)
2033{
902212c3 2034 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2035
2036 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2037 bgp_info_delete (rn, ri); /* keep historical info */
2038
b40d939b 2039 bgp_process (peer->bgp, rn, afi, safi);
718e3744 2040}
2041
94f2b392 2042static void
718e3744 2043bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
b40d939b 2044 afi_t afi, safi_t safi)
718e3744 2045{
718e3744 2046 int status = BGP_DAMP_NONE;
2047
b40d939b 2048 /* apply dampening, if result is suppressed, we'll be retaining
2049 * the bgp_info in the RIB for historical reference.
2050 */
2051 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2052 && peer->sort == BGP_PEER_EBGP)
b40d939b 2053 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2054 == BGP_DAMP_SUPPRESSED)
902212c3 2055 {
902212c3 2056 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2057 return;
2058 }
2059
2060 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 2061}
2062
fb018d25 2063static struct bgp_info *
7c8ff89e 2064info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
fb018d25
DS
2065 struct bgp_node *rn)
2066{
2067 struct bgp_info *new;
2068
2069 /* Make new BGP info. */
2070 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2071 new->type = type;
7c8ff89e 2072 new->instance = instance;
fb018d25
DS
2073 new->sub_type = sub_type;
2074 new->peer = peer;
2075 new->attr = attr;
2076 new->uptime = bgp_clock ();
2077 new->net = rn;
adbac85e 2078 new->addpath_tx_id = ++peer->bgp->addpath_tx_id;
fb018d25
DS
2079 return new;
2080}
2081
94f2b392 2082static void
cd808e74
DS
2083bgp_info_addpath_rx_str(struct bgp_info *ri, char *buf)
2084{
2085 if (ri && ri->addpath_rx_id)
2086 sprintf(buf, " with addpath ID %d", ri->addpath_rx_id);
cd808e74
DS
2087}
2088
c265ee22
DS
2089/* Check if received nexthop is valid or not. */
2090static int
2091bgp_update_martian_nexthop (afi_t afi, safi_t safi, struct attr *attr)
2092{
2093 struct attr_extra *attre = attr->extra;
2094 int ret = 0;
2095
2096 /* Only validated for unicast and multicast currently. */
2097 if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST)
2098 return 0;
2099
2100 /* If NEXT_HOP is present, validate it. */
2101 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP))
2102 {
2103 if (attr->nexthop.s_addr == 0 ||
2104 IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) ||
2105 bgp_nexthop_self (attr))
2106 ret = 1;
2107 }
2108
2109 /* If MP_NEXTHOP is present, validate it. */
2110 /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop;
2111 * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if
2112 * it is not an IPv6 link-local address.
2113 */
2114 if (attre && attre->mp_nexthop_len)
2115 {
2116 switch (attre->mp_nexthop_len)
2117 {
2118 case BGP_ATTR_NHLEN_IPV4:
2119 case BGP_ATTR_NHLEN_VPNV4:
2120 ret = (attre->mp_nexthop_global_in.s_addr == 0 ||
2121 IPV4_CLASS_DE (ntohl (attre->mp_nexthop_global_in.s_addr)));
2122 break;
2123
2124#ifdef HAVE_IPV6
2125 case BGP_ATTR_NHLEN_IPV6_GLOBAL:
2126 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
2127 ret = (IN6_IS_ADDR_UNSPECIFIED(&attre->mp_nexthop_global) ||
2128 IN6_IS_ADDR_LOOPBACK(&attre->mp_nexthop_global) ||
2129 IN6_IS_ADDR_MULTICAST(&attre->mp_nexthop_global));
2130 break;
2131#endif /* HAVE_IPV6 */
2132
2133 default:
2134 ret = 1;
2135 break;
2136 }
2137 }
2138
2139 return ret;
2140}
2141
94f2b392 2142static int
a82478b9
DS
2143bgp_update_main (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2144 struct attr *attr, afi_t afi, safi_t safi, int type,
2145 int sub_type, struct prefix_rd *prd, u_char *tag,
2146 int soft_reconfig)
718e3744 2147{
2148 int ret;
2149 int aspath_loop_count = 0;
2150 struct bgp_node *rn;
2151 struct bgp *bgp;
558d1fec
JBD
2152 struct attr new_attr;
2153 struct attr_extra new_extra;
718e3744 2154 struct attr *attr_new;
2155 struct bgp_info *ri;
2156 struct bgp_info *new;
fd79ac91 2157 const char *reason;
718e3744 2158 char buf[SU_ADDRSTRLEN];
cd808e74 2159 char buf2[30];
fc9a856f 2160 int connected = 0;
718e3744 2161
2162 bgp = peer->bgp;
fee0f4c6 2163 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
fb982c25 2164
718e3744 2165 /* When peer's soft reconfiguration enabled. Record input packet in
2166 Adj-RIBs-In. */
343aa822
JBD
2167 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2168 && peer != bgp->peer_self)
43143c8f 2169 bgp_adj_in_set (rn, peer, attr, addpath_id);
718e3744 2170
2171 /* Check previously received route. */
2172 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
2173 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2174 ri->addpath_rx_id == addpath_id)
718e3744 2175 break;
2176
2177 /* AS path local-as loop check. */
2178 if (peer->change_local_as)
2179 {
2180 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2181 aspath_loop_count = 1;
2182
2183 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2184 {
2185 reason = "as-path contains our own AS;";
2186 goto filtered;
2187 }
2188 }
2189
2190 /* AS path loop check. */
2191 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2192 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2193 && aspath_loop_check(attr->aspath, bgp->confed_id)
2194 > peer->allowas_in[afi][safi]))
2195 {
2196 reason = "as-path contains our own AS;";
2197 goto filtered;
2198 }
2199
2200 /* Route reflector originator ID check. */
2201 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 2202 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
718e3744 2203 {
2204 reason = "originator is us;";
2205 goto filtered;
2206 }
2207
2208 /* Route reflector cluster ID check. */
2209 if (bgp_cluster_filter (peer, attr))
2210 {
2211 reason = "reflected from the same cluster;";
2212 goto filtered;
2213 }
2214
2215 /* Apply incoming filter. */
2216 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2217 {
2218 reason = "filter;";
2219 goto filtered;
2220 }
2221
558d1fec 2222 new_attr.extra = &new_extra;
fb982c25 2223 bgp_attr_dup (&new_attr, attr);
718e3744 2224
c460e572
DL
2225 /* Apply incoming route-map.
2226 * NB: new_attr may now contain newly allocated values from route-map "set"
2227 * commands, so we need bgp_attr_flush in the error paths, until we intern
2228 * the attr (which takes over the memory references) */
0b16f239 2229 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
718e3744 2230 {
2231 reason = "route-map;";
c460e572 2232 bgp_attr_flush (&new_attr);
718e3744 2233 goto filtered;
2234 }
2235
c265ee22
DS
2236 /* next hop check. */
2237 if (bgp_update_martian_nexthop (afi, safi, &new_attr))
718e3744 2238 {
c265ee22
DS
2239 reason = "martian or self next-hop;";
2240 bgp_attr_flush (&new_attr);
2241 goto filtered;
718e3744 2242 }
2243
2244 attr_new = bgp_attr_intern (&new_attr);
2245
2246 /* If the update is implicit withdraw. */
2247 if (ri)
2248 {
65957886 2249 ri->uptime = bgp_clock ();
718e3744 2250
2251 /* Same attribute comes in. */
16d2e241
PJ
2252 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2253 && attrhash_cmp (ri->attr, attr_new))
718e3744 2254 {
718e3744 2255 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2256 && peer->sort == BGP_PEER_EBGP
718e3744 2257 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2258 {
3f9c7369 2259 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2260 {
2261 bgp_info_addpath_rx_str(ri, buf2);
2262 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2263 peer->host,
2264 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74
DS
2265 p->prefixlen, buf2);
2266 }
718e3744 2267
902212c3 2268 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2269 {
2270 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2271 bgp_process (bgp, rn, afi, safi);
2272 }
718e3744 2273 }
16d2e241 2274 else /* Duplicate - odd */
718e3744 2275 {
3f9c7369 2276 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2277 {
2278 if (!peer->rcvd_attr_printed)
2279 {
2280 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2281 peer->rcvd_attr_printed = 1;
2282 }
2283
cd808e74
DS
2284 bgp_info_addpath_rx_str(ri, buf2);
2285 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
16286195
DS
2286 peer->host,
2287 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2288 p->prefixlen, buf2);
16286195 2289 }
93406d87 2290
2291 /* graceful restart STALE flag unset. */
2292 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2293 {
1a392d46 2294 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
902212c3 2295 bgp_process (bgp, rn, afi, safi);
93406d87 2296 }
718e3744 2297 }
2298
2299 bgp_unlock_node (rn);
f6f434b2 2300 bgp_attr_unintern (&attr_new);
558d1fec 2301
718e3744 2302 return 0;
2303 }
2304
16d2e241
PJ
2305 /* Withdraw/Announce before we fully processed the withdraw */
2306 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2307 {
3f9c7369 2308 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2309 {
2310 bgp_info_addpath_rx_str(ri, buf2);
2311 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
2312 peer->host,
2313 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2314 p->prefixlen, buf2);
2315 }
16d2e241
PJ
2316 bgp_info_restore (rn, ri);
2317 }
2318
718e3744 2319 /* Received Logging. */
3f9c7369 2320 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2321 {
2322 bgp_info_addpath_rx_str(ri, buf2);
2323 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2324 peer->host,
2325 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74
DS
2326 p->prefixlen, buf2);
2327 }
718e3744 2328
93406d87 2329 /* graceful restart STALE flag unset. */
2330 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1a392d46 2331 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
93406d87 2332
718e3744 2333 /* The attribute is changed. */
1a392d46 2334 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
902212c3 2335
2336 /* implicit withdraw, decrement aggregate and pcount here.
2337 * only if update is accepted, they'll increment below.
2338 */
902212c3 2339 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2340
718e3744 2341 /* Update bgp route dampening information. */
2342 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2343 && peer->sort == BGP_PEER_EBGP)
718e3744 2344 {
2345 /* This is implicit withdraw so we should update dampening
2346 information. */
2347 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2348 bgp_damp_withdraw (ri, rn, afi, safi, 1);
718e3744 2349 }
2350
718e3744 2351 /* Update to new attribute. */
f6f434b2 2352 bgp_attr_unintern (&ri->attr);
718e3744 2353 ri->attr = attr_new;
2354
2355 /* Update MPLS tag. */
2356 if (safi == SAFI_MPLS_VPN)
fb982c25 2357 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
718e3744 2358
2359 /* Update bgp route dampening information. */
2360 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2361 && peer->sort == BGP_PEER_EBGP)
718e3744 2362 {
2363 /* Now we do normal update dampening. */
2364 ret = bgp_damp_update (ri, rn, afi, safi);
2365 if (ret == BGP_DAMP_SUPPRESSED)
2366 {
2367 bgp_unlock_node (rn);
2368 return 0;
2369 }
2370 }
2371
2372 /* Nexthop reachability check. */
fc9a856f 2373 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
718e3744 2374 {
fc9a856f 2375 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
907f92c8
DS
2376 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2377 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
fc9a856f
DS
2378 connected = 1;
2379 else
2380 connected = 0;
2381
75aead62 2382 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
1a392d46 2383 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 2384 else
fc9a856f
DS
2385 {
2386 if (BGP_DEBUG(nht, NHT))
2387 {
2388 char buf1[INET6_ADDRSTRLEN];
2389 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2390 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2391 }
2392 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2393 }
718e3744 2394 }
2395 else
fc9a856f 2396 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 2397
2398 /* Process change. */
2399 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2400
2401 bgp_process (bgp, rn, afi, safi);
2402 bgp_unlock_node (rn);
558d1fec 2403
718e3744 2404 return 0;
a82478b9 2405 } // End of implicit withdraw
718e3744 2406
2407 /* Received Logging. */
3f9c7369 2408 if (bgp_debug_update(peer, p, NULL, 1))
718e3744 2409 {
16286195
DS
2410 if (!peer->rcvd_attr_printed)
2411 {
2412 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2413 peer->rcvd_attr_printed = 1;
2414 }
2415
cd808e74
DS
2416 bgp_info_addpath_rx_str(ri, buf2);
2417 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2418 peer->host,
2419 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2420 p->prefixlen, buf2);
718e3744 2421 }
2422
718e3744 2423 /* Make new BGP info. */
7c8ff89e 2424 new = info_make(type, sub_type, 0, peer, attr_new, rn);
718e3744 2425
2426 /* Update MPLS tag. */
2427 if (safi == SAFI_MPLS_VPN)
fb982c25 2428 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
718e3744 2429
2430 /* Nexthop reachability check. */
fc9a856f
DS
2431 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2432 {
2433 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
907f92c8
DS
2434 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2435 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
fc9a856f
DS
2436 connected = 1;
2437 else
2438 connected = 0;
2439
75aead62 2440 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
1a392d46 2441 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 2442 else
fc9a856f
DS
2443 {
2444 if (BGP_DEBUG(nht, NHT))
2445 {
2446 char buf1[INET6_ADDRSTRLEN];
2447 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2448 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2449 }
2450 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2451 }
718e3744 2452 }
2453 else
1a392d46 2454 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 2455
a82478b9
DS
2456 /* Addpath ID */
2457 new->addpath_rx_id = addpath_id;
a82478b9 2458
902212c3 2459 /* Increment prefix */
718e3744 2460 bgp_aggregate_increment (bgp, p, new, afi, safi);
2461
2462 /* Register new BGP information. */
2463 bgp_info_add (rn, new);
200df115 2464
2465 /* route_node_get lock */
2466 bgp_unlock_node (rn);
558d1fec 2467
718e3744 2468 /* If maximum prefix count is configured and current prefix
2469 count exeed it. */
e0701b79 2470 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2471 return -1;
718e3744 2472
2473 /* Process change. */
2474 bgp_process (bgp, rn, afi, safi);
2475
2476 return 0;
2477
2478 /* This BGP update is filtered. Log the reason then update BGP
2479 entry. */
2480 filtered:
3f9c7369 2481 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2482 {
2483 if (!peer->rcvd_attr_printed)
2484 {
2485 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2486 peer->rcvd_attr_printed = 1;
2487 }
2488
cd808e74
DS
2489 bgp_info_addpath_rx_str(ri, buf2);
2490 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
16286195
DS
2491 peer->host,
2492 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2493 p->prefixlen, buf2, reason);
16286195 2494 }
718e3744 2495
2496 if (ri)
b40d939b 2497 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 2498
2499 bgp_unlock_node (rn);
558d1fec 2500
718e3744 2501 return 0;
2502}
2503
fee0f4c6 2504int
a82478b9
DS
2505bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2506 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
fee0f4c6 2507 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2508{
2a3d5731
DW
2509 return bgp_update_main (peer, p, addpath_id, attr, afi, safi, type, sub_type,
2510 prd, tag, soft_reconfig);
fee0f4c6 2511}
2512
718e3744 2513int
a82478b9
DS
2514bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2515 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2516 struct prefix_rd *prd, u_char *tag)
718e3744 2517{
2518 struct bgp *bgp;
2519 char buf[SU_ADDRSTRLEN];
cd808e74 2520 char buf2[30];
718e3744 2521 struct bgp_node *rn;
2522 struct bgp_info *ri;
2523
2524 bgp = peer->bgp;
2525
718e3744 2526 /* Lookup node. */
fee0f4c6 2527 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 2528
2529 /* If peer is soft reconfiguration enabled. Record input packet for
2530 further calculation. */
2531 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2532 && peer != bgp->peer_self)
43143c8f 2533 bgp_adj_in_unset (rn, peer, addpath_id);
718e3744 2534
2535 /* Lookup withdrawn route. */
2536 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
2537 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2538 ri->addpath_rx_id == addpath_id)
718e3744 2539 break;
2540
cd808e74
DS
2541 /* Logging. */
2542 if (bgp_debug_update(peer, p, NULL, 1))
2543 {
2544 bgp_info_addpath_rx_str(ri, buf2);
2545 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
2546 peer->host,
2547 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2548 p->prefixlen, buf2);
2549 }
2550
718e3744 2551 /* Withdraw specified route from routing table. */
2552 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
b40d939b 2553 bgp_rib_withdraw (rn, ri, peer, afi, safi);
3f9c7369 2554 else if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2555 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2556 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2557 p->prefixlen);
718e3744 2558
2559 /* Unlock bgp_node_get() lock. */
2560 bgp_unlock_node (rn);
2561
2562 return 0;
2563}
6b0655a2 2564
718e3744 2565void
2566bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2567{
3f9c7369
DS
2568 struct update_subgroup *subgrp;
2569 subgrp = peer_subgroup(peer, afi, safi);
2570 subgroup_default_originate(subgrp, withdraw);
2571}
6182d65b 2572
718e3744 2573
3f9c7369
DS
2574/*
2575 * bgp_stop_announce_route_timer
2576 */
2577void
2578bgp_stop_announce_route_timer (struct peer_af *paf)
2579{
2580 if (!paf->t_announce_route)
2581 return;
718e3744 2582
3f9c7369 2583 THREAD_TIMER_OFF (paf->t_announce_route);
718e3744 2584}
6b0655a2 2585
3f9c7369
DS
2586/*
2587 * bgp_announce_route_timer_expired
2588 *
2589 * Callback that is invoked when the route announcement timer for a
2590 * peer_af expires.
2591 */
2592static int
2593bgp_announce_route_timer_expired (struct thread *t)
718e3744 2594{
3f9c7369
DS
2595 struct peer_af *paf;
2596 struct peer *peer;
558d1fec 2597
718e3744 2598
3f9c7369
DS
2599 paf = THREAD_ARG (t);
2600 peer = paf->peer;
718e3744 2601
3f9c7369
DS
2602 assert (paf->t_announce_route);
2603 paf->t_announce_route = NULL;
558d1fec 2604
3f9c7369
DS
2605 if (peer->status != Established)
2606 return 0;
2607
2608 if (!peer->afc_nego[paf->afi][paf->safi])
2609 return 0;
2610
2611 peer_af_announce_route (paf, 1);
2612 return 0;
718e3744 2613}
2614
3f9c7369
DS
2615/*
2616 * bgp_announce_route
2617 *
2618 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
2619 */
718e3744 2620void
2621bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2622{
3f9c7369
DS
2623 struct peer_af *paf;
2624 struct update_subgroup *subgrp;
718e3744 2625
3f9c7369
DS
2626 paf = peer_af_find (peer, afi, safi);
2627 if (!paf)
718e3744 2628 return;
3f9c7369 2629 subgrp = PAF_SUBGRP(paf);
718e3744 2630
3f9c7369
DS
2631 /*
2632 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
2633 * or a refresh has already been triggered.
2634 */
2635 if (!subgrp || paf->t_announce_route)
718e3744 2636 return;
2637
d889623f 2638 /*
3f9c7369
DS
2639 * Start a timer to stagger/delay the announce. This serves
2640 * two purposes - announcement can potentially be combined for
2641 * multiple peers and the announcement doesn't happen in the
2642 * vty context.
d889623f 2643 */
9229d914 2644 THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route,
3f9c7369
DS
2645 bgp_announce_route_timer_expired, paf,
2646 (subgrp->peer_count == 1) ?
2647 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
2648 BGP_ANNOUNCE_ROUTE_DELAY_MS);
2649}
2650
2651/*
2652 * Announce routes from all AF tables to a peer.
2653 *
2654 * This should ONLY be called when there is a need to refresh the
2655 * routes to the peer based on a policy change for this peer alone
2656 * or a route refresh request received from the peer.
2657 * The operation will result in splitting the peer from its existing
2658 * subgroups and putting it in new subgroups.
2659 */
718e3744 2660void
2661bgp_announce_route_all (struct peer *peer)
2662{
2663 afi_t afi;
2664 safi_t safi;
2665
2666 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2667 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2668 bgp_announce_route (peer, afi, safi);
2669}
6b0655a2 2670
fee0f4c6 2671static void
718e3744 2672bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
8692c506 2673 struct bgp_table *table, struct prefix_rd *prd)
718e3744 2674{
2675 int ret;
2676 struct bgp_node *rn;
2677 struct bgp_adj_in *ain;
2678
2679 if (! table)
2680 table = peer->bgp->rib[afi][safi];
2681
2682 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2683 for (ain = rn->adj_in; ain; ain = ain->next)
2684 {
2685 if (ain->peer == peer)
2686 {
8692c506 2687 struct bgp_info *ri = rn->info;
d53d8fda 2688 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 2689
43143c8f 2690 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
a82478b9 2691 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
d53d8fda 2692 prd, tag, 1);
8692c506 2693
718e3744 2694 if (ret < 0)
2695 {
2696 bgp_unlock_node (rn);
2697 return;
2698 }
718e3744 2699 }
2700 }
2701}
2702
2703void
2704bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2705{
2706 struct bgp_node *rn;
2707 struct bgp_table *table;
2708
2709 if (peer->status != Established)
2710 return;
2711
2712 if (safi != SAFI_MPLS_VPN)
8692c506 2713 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
718e3744 2714 else
2715 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2716 rn = bgp_route_next (rn))
2717 if ((table = rn->info) != NULL)
8692c506
JBD
2718 {
2719 struct prefix_rd prd;
2720 prd.family = AF_UNSPEC;
2721 prd.prefixlen = 64;
2722 memcpy(&prd.val, rn->p.u.val, 8);
2723
2724 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2725 }
718e3744 2726}
6b0655a2 2727
228da428
CC
2728
2729struct bgp_clear_node_queue
2730{
2731 struct bgp_node *rn;
228da428
CC
2732};
2733
200df115 2734static wq_item_status
0fb58d5d 2735bgp_clear_route_node (struct work_queue *wq, void *data)
200df115 2736{
228da428
CC
2737 struct bgp_clear_node_queue *cnq = data;
2738 struct bgp_node *rn = cnq->rn;
64e580a7 2739 struct peer *peer = wq->spec.data;
718e3744 2740 struct bgp_info *ri;
67174041
AS
2741 afi_t afi = bgp_node_table (rn)->afi;
2742 safi_t safi = bgp_node_table (rn)->safi;
200df115 2743
64e580a7 2744 assert (rn && peer);
200df115 2745
43143c8f
DS
2746 /* It is possible that we have multiple paths for a prefix from a peer
2747 * if that peer is using AddPath.
2748 */
64e580a7 2749 for (ri = rn->info; ri; ri = ri->next)
2a3d5731 2750 if (ri->peer == peer)
200df115 2751 {
2752 /* graceful restart STALE flag set. */
64e580a7
PJ
2753 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2754 && peer->nsf[afi][safi]
200df115 2755 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
1a392d46
PJ
2756 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2757 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
200df115 2758 else
64e580a7 2759 bgp_rib_remove (rn, ri, peer, afi, safi);
200df115 2760 }
200df115 2761 return WQ_SUCCESS;
2762}
2763
2764static void
0fb58d5d 2765bgp_clear_node_queue_del (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;
67174041 2769 struct bgp_table *table = bgp_node_table (rn);
64e580a7
PJ
2770
2771 bgp_unlock_node (rn);
228da428
CC
2772 bgp_table_unlock (table);
2773 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
200df115 2774}
2775
2776static void
94f2b392 2777bgp_clear_node_complete (struct work_queue *wq)
200df115 2778{
64e580a7
PJ
2779 struct peer *peer = wq->spec.data;
2780
3e0c78ef 2781 /* Tickle FSM to start moving again */
ca058a30 2782 BGP_EVENT_ADD (peer, Clearing_Completed);
228da428
CC
2783
2784 peer_unlock (peer); /* bgp_clear_route */
200df115 2785}
2786
2787static void
64e580a7 2788bgp_clear_node_queue_init (struct peer *peer)
200df115 2789{
a2943657 2790 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
64e580a7 2791
a2943657 2792 snprintf (wname, sizeof(wname), "clear %s", peer->host);
64e580a7
PJ
2793#undef CLEAR_QUEUE_NAME_LEN
2794
87d4a781 2795 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
200df115 2796 {
2797 zlog_err ("%s: Failed to allocate work queue", __func__);
2798 exit (1);
2799 }
64e580a7
PJ
2800 peer->clear_node_queue->spec.hold = 10;
2801 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2802 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2803 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2804 peer->clear_node_queue->spec.max_retries = 0;
2805
2806 /* we only 'lock' this peer reference when the queue is actually active */
2807 peer->clear_node_queue->spec.data = peer;
200df115 2808}
718e3744 2809
200df115 2810static void
2811bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
2a3d5731 2812 struct bgp_table *table)
200df115 2813{
200df115 2814 struct bgp_node *rn;
2815
f2c31acb 2816
718e3744 2817 if (! table)
2a3d5731 2818 table = peer->bgp->rib[afi][safi];
64e580a7 2819
6cf159b9 2820 /* If still no table => afi/safi isn't configured at all or smth. */
2821 if (! table)
2822 return;
65ca75e0
PJ
2823
2824 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2825 {
f2c31acb
PJ
2826 struct bgp_info *ri;
2827 struct bgp_adj_in *ain;
43143c8f 2828 struct bgp_adj_in *ain_next;
f2c31acb
PJ
2829
2830 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2831 * queued for every clearing peer, regardless of whether it is
2832 * relevant to the peer at hand.
2833 *
2834 * Overview: There are 3 different indices which need to be
2835 * scrubbed, potentially, when a peer is removed:
2836 *
2837 * 1 peer's routes visible via the RIB (ie accepted routes)
2838 * 2 peer's routes visible by the (optional) peer's adj-in index
2839 * 3 other routes visible by the peer's adj-out index
2840 *
2841 * 3 there is no hurry in scrubbing, once the struct peer is
2842 * removed from bgp->peer, we could just GC such deleted peer's
2843 * adj-outs at our leisure.
2844 *
2845 * 1 and 2 must be 'scrubbed' in some way, at least made
2846 * invisible via RIB index before peer session is allowed to be
2847 * brought back up. So one needs to know when such a 'search' is
2848 * complete.
2849 *
2850 * Ideally:
2851 *
2852 * - there'd be a single global queue or a single RIB walker
2853 * - rather than tracking which route_nodes still need to be
2854 * examined on a peer basis, we'd track which peers still
2855 * aren't cleared
2856 *
2857 * Given that our per-peer prefix-counts now should be reliable,
2858 * this may actually be achievable. It doesn't seem to be a huge
2859 * problem at this time,
43143c8f
DS
2860 *
2861 * It is possible that we have multiple paths for a prefix from a peer
2862 * if that peer is using AddPath.
f2c31acb 2863 */
43143c8f
DS
2864 ain = rn->adj_in;
2865 while (ain)
2866 {
2867 ain_next = ain->next;
2868
2a3d5731 2869 if (ain->peer == peer)
43143c8f
DS
2870 {
2871 bgp_adj_in_remove (rn, ain);
2872 bgp_unlock_node (rn);
2873 }
2874
2875 ain = ain_next;
2876 }
3f9c7369 2877
f2c31acb 2878 for (ri = rn->info; ri; ri = ri->next)
2a3d5731 2879 if (ri->peer == peer)
f2c31acb 2880 {
228da428
CC
2881 struct bgp_clear_node_queue *cnq;
2882
2883 /* both unlocked in bgp_clear_node_queue_del */
67174041 2884 bgp_table_lock (bgp_node_table (rn));
228da428
CC
2885 bgp_lock_node (rn);
2886 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2887 sizeof (struct bgp_clear_node_queue));
2888 cnq->rn = rn;
228da428
CC
2889 work_queue_add (peer->clear_node_queue, cnq);
2890 break;
f2c31acb 2891 }
65ca75e0
PJ
2892 }
2893 return;
2894}
2895
2896void
2a3d5731 2897bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
65ca75e0
PJ
2898{
2899 struct bgp_node *rn;
2900 struct bgp_table *table;
6cf159b9 2901
64e580a7
PJ
2902 if (peer->clear_node_queue == NULL)
2903 bgp_clear_node_queue_init (peer);
200df115 2904
ca058a30
PJ
2905 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2906 * Idle until it receives a Clearing_Completed event. This protects
2907 * against peers which flap faster than we can we clear, which could
2908 * lead to:
64e580a7
PJ
2909 *
2910 * a) race with routes from the new session being installed before
2911 * clear_route_node visits the node (to delete the route of that
2912 * peer)
2913 * b) resource exhaustion, clear_route_node likely leads to an entry
2914 * on the process_main queue. Fast-flapping could cause that queue
2915 * to grow and grow.
200df115 2916 */
dc83d712
DS
2917
2918 /* lock peer in assumption that clear-node-queue will get nodes; if so,
2919 * the unlock will happen upon work-queue completion; other wise, the
2920 * unlock happens at the end of this function.
2921 */
ca058a30 2922 if (!peer->clear_node_queue->thread)
dc83d712 2923 peer_lock (peer);
fee0f4c6 2924
2a3d5731
DW
2925 if (safi != SAFI_MPLS_VPN)
2926 bgp_clear_route_table (peer, afi, safi, NULL);
2927 else
2928 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2929 rn = bgp_route_next (rn))
2930 if ((table = rn->info) != NULL)
2931 bgp_clear_route_table (peer, afi, safi, table);
dc83d712
DS
2932
2933 /* unlock if no nodes got added to the clear-node-queue. */
65ca75e0 2934 if (!peer->clear_node_queue->thread)
dc83d712
DS
2935 peer_unlock (peer);
2936
718e3744 2937}
2938
2939void
2940bgp_clear_route_all (struct peer *peer)
2941{
2942 afi_t afi;
2943 safi_t safi;
2944
2945 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2946 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2a3d5731 2947 bgp_clear_route (peer, afi, safi);
718e3744 2948}
2949
2950void
2951bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2952{
2953 struct bgp_table *table;
2954 struct bgp_node *rn;
2955 struct bgp_adj_in *ain;
43143c8f 2956 struct bgp_adj_in *ain_next;
718e3744 2957
2958 table = peer->bgp->rib[afi][safi];
2959
43143c8f
DS
2960 /* It is possible that we have multiple paths for a prefix from a peer
2961 * if that peer is using AddPath.
2962 */
718e3744 2963 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
43143c8f
DS
2964 {
2965 ain = rn->adj_in;
2966
2967 while (ain)
2968 {
2969 ain_next = ain->next;
2970
2971 if (ain->peer == peer)
2972 {
2973 bgp_adj_in_remove (rn, ain);
2974 bgp_unlock_node (rn);
2975 }
2976
2977 ain = ain_next;
2978 }
2979 }
718e3744 2980}
93406d87 2981
2982void
2983bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2984{
2985 struct bgp_node *rn;
2986 struct bgp_info *ri;
2987 struct bgp_table *table;
2988
2989 table = peer->bgp->rib[afi][safi];
2990
2991 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2992 {
2993 for (ri = rn->info; ri; ri = ri->next)
2994 if (ri->peer == peer)
2995 {
2996 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2997 bgp_rib_remove (rn, ri, peer, afi, safi);
2998 break;
2999 }
3000 }
3001}
6b0655a2 3002
718e3744 3003/* Delete all kernel routes. */
3004void
66e5cd87 3005bgp_cleanup_routes (void)
718e3744 3006{
3007 struct bgp *bgp;
1eb8ef25 3008 struct listnode *node, *nnode;
718e3744 3009 struct bgp_node *rn;
3010 struct bgp_table *table;
3011 struct bgp_info *ri;
3012
1eb8ef25 3013 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 3014 {
3015 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3016
3017 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3018 for (ri = rn->info; ri; ri = ri->next)
3019 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3020 && ri->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
3021 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3022 ri->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 3023 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
718e3744 3024
3025 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3026
3027 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3028 for (ri = rn->info; ri; ri = ri->next)
3029 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3030 && ri->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
3031 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3032 ri->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 3033 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
718e3744 3034 }
3035}
3036
3037void
66e5cd87 3038bgp_reset (void)
718e3744 3039{
3040 vty_reset ();
3041 bgp_zclient_reset ();
3042 access_list_reset ();
3043 prefix_list_reset ();
3044}
6b0655a2 3045
adbac85e
DW
3046static int
3047bgp_addpath_encode_rx (struct peer *peer, afi_t afi, safi_t safi)
3048{
3049 return (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3050 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3051}
3052
718e3744 3053/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3054 value. */
3055int
3056bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3057{
3058 u_char *pnt;
3059 u_char *lim;
3060 struct prefix p;
3061 int psize;
3062 int ret;
a82478b9
DS
3063 afi_t afi;
3064 safi_t safi;
adbac85e 3065 int addpath_encoded;
a82478b9 3066 u_int32_t addpath_id;
718e3744 3067
3068 /* Check peer status. */
3069 if (peer->status != Established)
3070 return 0;
3071
3072 pnt = packet->nlri;
3073 lim = pnt + packet->length;
a82478b9
DS
3074 afi = packet->afi;
3075 safi = packet->safi;
3076 addpath_id = 0;
adbac85e 3077 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
718e3744 3078
3079 for (; pnt < lim; pnt += psize)
3080 {
3081 /* Clear prefix structure. */
3082 memset (&p, 0, sizeof (struct prefix));
3083
a82478b9
DS
3084 if (addpath_encoded)
3085 {
cd808e74
DS
3086
3087 /* When packet overflow occurs return immediately. */
3088 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3089 return -1;
3090
a82478b9
DS
3091 addpath_id = ntohl(*((uint32_t*) pnt));
3092 pnt += BGP_ADDPATH_ID_LEN;
3093 }
3094
718e3744 3095 /* Fetch prefix length. */
3096 p.prefixlen = *pnt++;
a82478b9 3097 p.family = afi2family (afi);
718e3744 3098
3099 /* Already checked in nlri_sanity_check(). We do double check
3100 here. */
a82478b9
DS
3101 if ((afi == AFI_IP && p.prefixlen > 32)
3102 || (afi == AFI_IP6 && p.prefixlen > 128))
718e3744 3103 return -1;
3104
3105 /* Packet size overflow check. */
3106 psize = PSIZE (p.prefixlen);
3107
3108 /* When packet overflow occur return immediately. */
3109 if (pnt + psize > lim)
3110 return -1;
3111
3112 /* Fetch prefix from NLRI packet. */
3113 memcpy (&p.u.prefix, pnt, psize);
3114
3115 /* Check address. */
a82478b9 3116 if (afi == AFI_IP && safi == SAFI_UNICAST)
718e3744 3117 {
3118 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3119 {
f5ba3874 3120 /*
3121 * From draft-ietf-idr-bgp4-22, Section 6.3:
3122 * If a BGP router receives an UPDATE message with a
3123 * semantically incorrect NLRI field, in which a prefix is
3124 * semantically incorrect (eg. an unexpected multicast IP
3125 * address), it should ignore the prefix.
3126 */
16286195
DS
3127 zlog_err ("IPv4 unicast NLRI is multicast address %s",
3128 inet_ntoa (p.u.prefix4));
f5ba3874 3129
718e3744 3130 return -1;
3131 }
3132 }
3133
3134#ifdef HAVE_IPV6
3135 /* Check address. */
a82478b9 3136 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
718e3744 3137 {
3138 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3139 {
3140 char buf[BUFSIZ];
3141
16286195
DS
3142 zlog_warn ("IPv6 link-local NLRI received %s ignore this NLRI",
3143 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
718e3744 3144
3145 continue;
3146 }
3147 }
3148#endif /* HAVE_IPV6 */
3149
3150 /* Normal process. */
3151 if (attr)
a82478b9 3152 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
718e3744 3153 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3154 else
a82478b9 3155 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
718e3744 3156 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3157
3158 /* Address family configuration mismatch or maximum-prefix count
3159 overflow. */
3160 if (ret < 0)
3161 return -1;
3162 }
3163
3164 /* Packet length consistency check. */
3165 if (pnt != lim)
3166 return -1;
3167
3168 return 0;
3169}
3170
3171/* NLRI encode syntax check routine. */
3172int
a82478b9 3173bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi, u_char *pnt,
d889623f 3174 bgp_size_t length, int *numpfx)
718e3744 3175{
3176 u_char *end;
3177 u_char prefixlen;
3178 int psize;
adbac85e 3179 int addpath_encoded;
718e3744 3180
d889623f 3181 *numpfx = 0;
718e3744 3182 end = pnt + length;
adbac85e 3183 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
a82478b9 3184
718e3744 3185 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3186 syntactic validity. If the field is syntactically incorrect,
3187 then the Error Subcode is set to Invalid Network Field. */
3188
3189 while (pnt < end)
3190 {
cd808e74 3191
a82478b9
DS
3192 /* If the NLRI is encoded using addpath then the first 4 bytes are
3193 * the addpath ID. */
3194 if (addpath_encoded)
cd808e74
DS
3195 {
3196 if (pnt + BGP_ADDPATH_ID_LEN > end)
3197 {
3198 zlog_err ("%s [Error] Update packet error"
3199 " (prefix data addpath overflow)",
3200 peer->host);
3201 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3202 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3203 return -1;
3204 }
3205 pnt += BGP_ADDPATH_ID_LEN;
3206 }
a82478b9 3207
718e3744 3208 prefixlen = *pnt++;
3209
3210 /* Prefix length check. */
3211 if ((afi == AFI_IP && prefixlen > 32)
3212 || (afi == AFI_IP6 && prefixlen > 128))
3213 {
16286195 3214 zlog_err ("%s [Error] Update packet error (wrong prefix length %d)",
718e3744 3215 peer->host, prefixlen);
3216 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3217 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3218 return -1;
3219 }
3220
3221 /* Packet size overflow check. */
3222 psize = PSIZE (prefixlen);
3223
3224 if (pnt + psize > end)
3225 {
16286195 3226 zlog_err ("%s [Error] Update packet error"
718e3744 3227 " (prefix data overflow prefix size is %d)",
3228 peer->host, psize);
3229 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3230 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3231 return -1;
3232 }
3233
3234 pnt += psize;
d889623f 3235 (*numpfx)++;
718e3744 3236 }
3237
3238 /* Packet length consistency check. */
3239 if (pnt != end)
3240 {
16286195 3241 zlog_err ("%s [Error] Update packet error"
718e3744 3242 " (prefix length mismatch with total length)",
3243 peer->host);
3244 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3245 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3246 return -1;
3247 }
3248 return 0;
3249}
6b0655a2 3250
94f2b392 3251static struct bgp_static *
66e5cd87 3252bgp_static_new (void)
718e3744 3253{
393deb9b 3254 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
718e3744 3255}
3256
94f2b392 3257static void
718e3744 3258bgp_static_free (struct bgp_static *bgp_static)
3259{
3260 if (bgp_static->rmap.name)
6e919709 3261 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
718e3744 3262 XFREE (MTYPE_BGP_STATIC, bgp_static);
3263}
3264
94f2b392 3265static void
2a3d5731
DW
3266bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3267 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
fee0f4c6 3268{
3269 struct bgp_node *rn;
3270 struct bgp_info *ri;
2a3d5731
DW
3271 struct bgp_info *new;
3272 struct bgp_info info;
3273 struct attr attr;
3274 struct attr *attr_new;
3275 int ret;
fee0f4c6 3276
2a3d5731
DW
3277 assert (bgp_static);
3278 if (!bgp_static)
3279 return;
dd8103a9 3280
fee0f4c6 3281 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 3282
3283 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
dd8103a9
PJ
3284
3285 attr.nexthop = bgp_static->igpnexthop;
3286 attr.med = bgp_static->igpmetric;
3287 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
718e3744 3288
41367172
PJ
3289 if (bgp_static->atomic)
3290 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3291
718e3744 3292 /* Apply route-map. */
3293 if (bgp_static->rmap.name)
3294 {
fb982c25 3295 struct attr attr_tmp = attr;
718e3744 3296 info.peer = bgp->peer_self;
286e1e71 3297 info.attr = &attr_tmp;
718e3744 3298
fee0f4c6 3299 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3300
718e3744 3301 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
286e1e71 3302
fee0f4c6 3303 bgp->peer_self->rmap_type = 0;
3304
718e3744 3305 if (ret == RMAP_DENYMATCH)
3306 {
3307 /* Free uninterned attribute. */
286e1e71 3308 bgp_attr_flush (&attr_tmp);
718e3744 3309
3310 /* Unintern original. */
f6f434b2 3311 aspath_unintern (&attr.aspath);
fb982c25 3312 bgp_attr_extra_free (&attr);
718e3744 3313 bgp_static_withdraw (bgp, p, afi, safi);
3314 return;
3315 }
286e1e71 3316 attr_new = bgp_attr_intern (&attr_tmp);
718e3744 3317 }
286e1e71 3318 else
3319 attr_new = bgp_attr_intern (&attr);
718e3744 3320
3321 for (ri = rn->info; ri; ri = ri->next)
3322 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3323 && ri->sub_type == BGP_ROUTE_STATIC)
3324 break;
3325
3326 if (ri)
3327 {
8d45210e 3328 if (attrhash_cmp (ri->attr, attr_new) &&
078430f6
DS
3329 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
3330 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
718e3744 3331 {
3332 bgp_unlock_node (rn);
f6f434b2
PJ
3333 bgp_attr_unintern (&attr_new);
3334 aspath_unintern (&attr.aspath);
fb982c25 3335 bgp_attr_extra_free (&attr);
718e3744 3336 return;
3337 }
3338 else
3339 {
3340 /* The attribute is changed. */
1a392d46 3341 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 3342
3343 /* Rewrite BGP route information. */
8d45210e
AS
3344 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3345 bgp_info_restore(rn, ri);
3346 else
3347 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
f6f434b2 3348 bgp_attr_unintern (&ri->attr);
718e3744 3349 ri->attr = attr_new;
65957886 3350 ri->uptime = bgp_clock ();
718e3744 3351
fc9a856f
DS
3352 /* Nexthop reachability check. */
3353 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3354 {
75aead62 3355 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
fc9a856f
DS
3356 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3357 else
3358 {
3359 if (BGP_DEBUG(nht, NHT))
3360 {
3361 char buf1[INET6_ADDRSTRLEN];
078430f6
DS
3362 inet_ntop(p->family, &p->u.prefix, buf1,
3363 INET6_ADDRSTRLEN);
3364 zlog_debug("%s(%s): Route not in table, not advertising",
3365 __FUNCTION__, buf1);
fc9a856f
DS
3366 }
3367 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3368 }
3369 }
078430f6
DS
3370 else
3371 {
3372 /* Delete the NHT structure if any, if we're toggling between
3373 * enabling/disabling import check. We deregister the route
3374 * from NHT to avoid overloading NHT and the process interaction
3375 */
3376 bgp_unlink_nexthop(ri);
3377 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3378 }
718e3744 3379 /* Process change. */
3380 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3381 bgp_process (bgp, rn, afi, safi);
3382 bgp_unlock_node (rn);
f6f434b2 3383 aspath_unintern (&attr.aspath);
fb982c25 3384 bgp_attr_extra_free (&attr);
718e3744 3385 return;
3386 }
3387 }
3388
3389 /* Make new BGP info. */
7c8ff89e 3390 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
fb018d25 3391 rn);
fc9a856f
DS
3392 /* Nexthop reachability check. */
3393 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3394 {
75aead62 3395 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
fc9a856f
DS
3396 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3397 else
3398 {
3399 if (BGP_DEBUG(nht, NHT))
3400 {
3401 char buf1[INET6_ADDRSTRLEN];
078430f6 3402 inet_ntop(p->family, &p->u.prefix, buf1,
fc9a856f 3403 INET6_ADDRSTRLEN);
078430f6
DS
3404 zlog_debug("%s(%s): Route not in table, not advertising",
3405 __FUNCTION__, buf1);
fc9a856f
DS
3406 }
3407 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3408 }
3409 }
3410 else
078430f6
DS
3411 {
3412 /* Delete the NHT structure if any, if we're toggling between
3413 * enabling/disabling import check. We deregister the route
3414 * from NHT to avoid overloading NHT and the process interaction
3415 */
3416 bgp_unlink_nexthop(new);
3417
3418 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3419 }
718e3744 3420
3421 /* Aggregate address increment. */
3422 bgp_aggregate_increment (bgp, p, new, afi, safi);
3423
3424 /* Register new BGP information. */
3425 bgp_info_add (rn, new);
200df115 3426
3427 /* route_node_get lock */
3428 bgp_unlock_node (rn);
3429
718e3744 3430 /* Process change. */
3431 bgp_process (bgp, rn, afi, safi);
3432
3433 /* Unintern original. */
f6f434b2 3434 aspath_unintern (&attr.aspath);
fb982c25 3435 bgp_attr_extra_free (&attr);
718e3744 3436}
3437
fee0f4c6 3438void
3439bgp_static_update (struct bgp *bgp, struct prefix *p,
3440 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3441{
fee0f4c6 3442 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
fee0f4c6 3443}
3444
94f2b392 3445static void
4c9641ba
ML
3446bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3447 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 3448{
3449 struct bgp_node *rn;
3450 struct bgp_info *new;
fb982c25 3451
fee0f4c6 3452 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 3453
3454 /* Make new BGP info. */
7c8ff89e 3455 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
fb018d25
DS
3456 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
3457
718e3744 3458 SET_FLAG (new->flags, BGP_INFO_VALID);
fb982c25
PJ
3459 new->extra = bgp_info_extra_new();
3460 memcpy (new->extra->tag, tag, 3);
718e3744 3461
3462 /* Aggregate address increment. */
200df115 3463 bgp_aggregate_increment (bgp, p, new, afi, safi);
718e3744 3464
3465 /* Register new BGP information. */
200df115 3466 bgp_info_add (rn, new);
718e3744 3467
200df115 3468 /* route_node_get lock */
3469 bgp_unlock_node (rn);
3470
718e3744 3471 /* Process change. */
3472 bgp_process (bgp, rn, afi, safi);
3473}
3474
3475void
3476bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3477 safi_t safi)
3478{
3479 struct bgp_node *rn;
3480 struct bgp_info *ri;
3481
fee0f4c6 3482 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 3483
3484 /* Check selected route and self inserted route. */
3485 for (ri = rn->info; ri; ri = ri->next)
3486 if (ri->peer == bgp->peer_self
3487 && ri->type == ZEBRA_ROUTE_BGP
3488 && ri->sub_type == BGP_ROUTE_STATIC)
3489 break;
3490
3491 /* Withdraw static BGP route from routing table. */
3492 if (ri)
3493 {
3494 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
fc9a856f 3495 bgp_unlink_nexthop(ri);
718e3744 3496 bgp_info_delete (rn, ri);
1a392d46 3497 bgp_process (bgp, rn, afi, safi);
718e3744 3498 }
3499
3500 /* Unlock bgp_node_lookup. */
3501 bgp_unlock_node (rn);
3502}
3503
94f2b392 3504static void
4c9641ba
ML
3505bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3506 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 3507{
3508 struct bgp_node *rn;
3509 struct bgp_info *ri;
3510
fee0f4c6 3511 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 3512
3513 /* Check selected route and self inserted route. */
3514 for (ri = rn->info; ri; ri = ri->next)
3515 if (ri->peer == bgp->peer_self
3516 && ri->type == ZEBRA_ROUTE_BGP
3517 && ri->sub_type == BGP_ROUTE_STATIC)
3518 break;
3519
3520 /* Withdraw static BGP route from routing table. */
3521 if (ri)
3522 {
3523 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
718e3744 3524 bgp_info_delete (rn, ri);
1a392d46 3525 bgp_process (bgp, rn, afi, safi);
718e3744 3526 }
3527
3528 /* Unlock bgp_node_lookup. */
3529 bgp_unlock_node (rn);
3530}
3531
3532/* Configure static BGP network. When user don't run zebra, static
3533 route should be installed as valid. */
94f2b392 3534static int
fd79ac91 3535bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
c8f3fe30 3536 afi_t afi, safi_t safi, const char *rmap, int backdoor)
718e3744 3537{
3538 int ret;
3539 struct prefix p;
3540 struct bgp_static *bgp_static;
3541 struct bgp_node *rn;
41367172 3542 u_char need_update = 0;
718e3744 3543
3544 /* Convert IP prefix string to struct prefix. */
3545 ret = str2prefix (ip_str, &p);
3546 if (! ret)
3547 {
3548 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3549 return CMD_WARNING;
3550 }
3551#ifdef HAVE_IPV6
3552 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3553 {
3554 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3555 VTY_NEWLINE);
3556 return CMD_WARNING;
3557 }
3558#endif /* HAVE_IPV6 */
3559
3560 apply_mask (&p);
3561
3562 /* Set BGP static route configuration. */
3563 rn = bgp_node_get (bgp->route[afi][safi], &p);
3564
3565 if (rn->info)
3566 {
3567 /* Configuration change. */
3568 bgp_static = rn->info;
3569
3570 /* Check previous routes are installed into BGP. */
c8f3fe30
PJ
3571 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3572 need_update = 1;
41367172 3573
718e3744 3574 bgp_static->backdoor = backdoor;
41367172 3575
718e3744 3576 if (rmap)
3577 {
3578 if (bgp_static->rmap.name)
6e919709
DS
3579 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3580 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
718e3744 3581 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3582 }
3583 else
3584 {
3585 if (bgp_static->rmap.name)
6e919709 3586 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
718e3744 3587 bgp_static->rmap.name = NULL;
3588 bgp_static->rmap.map = NULL;
3589 bgp_static->valid = 0;
3590 }
3591 bgp_unlock_node (rn);
3592 }
3593 else
3594 {
3595 /* New configuration. */
3596 bgp_static = bgp_static_new ();
3597 bgp_static->backdoor = backdoor;
3598 bgp_static->valid = 0;
3599 bgp_static->igpmetric = 0;
3600 bgp_static->igpnexthop.s_addr = 0;
41367172 3601
718e3744 3602 if (rmap)
3603 {
3604 if (bgp_static->rmap.name)
6e919709
DS
3605 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3606 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
718e3744 3607 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3608 }
3609 rn->info = bgp_static;
3610 }
3611
fc9a856f
DS
3612 bgp_static->valid = 1;
3613 if (need_update)
3614 bgp_static_withdraw (bgp, &p, afi, safi);
718e3744 3615
fc9a856f
DS
3616 if (! bgp_static->backdoor)
3617 bgp_static_update (bgp, &p, bgp_static, afi, safi);
718e3744 3618
3619 return CMD_SUCCESS;
3620}
3621
3622/* Configure static BGP network. */
94f2b392 3623static int
fd79ac91 3624bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4c9641ba 3625 afi_t afi, safi_t safi)
718e3744 3626{
3627 int ret;
3628 struct prefix p;
3629 struct bgp_static *bgp_static;
3630 struct bgp_node *rn;
3631
3632 /* Convert IP prefix string to struct prefix. */
3633 ret = str2prefix (ip_str, &p);
3634 if (! ret)
3635 {
3636 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3637 return CMD_WARNING;
3638 }
3639#ifdef HAVE_IPV6
3640 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3641 {
3642 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3643 VTY_NEWLINE);
3644 return CMD_WARNING;
3645 }
3646#endif /* HAVE_IPV6 */
3647
3648 apply_mask (&p);
3649
3650 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3651 if (! rn)
3652 {
3653 vty_out (vty, "%% Can't find specified static route configuration.%s",
3654 VTY_NEWLINE);
3655 return CMD_WARNING;
3656 }
3657
3658 bgp_static = rn->info;
41367172 3659
718e3744 3660 /* Update BGP RIB. */
3661 if (! bgp_static->backdoor)
3662 bgp_static_withdraw (bgp, &p, afi, safi);
3663
3664 /* Clear configuration. */
3665 bgp_static_free (bgp_static);
3666 rn->info = NULL;
3667 bgp_unlock_node (rn);
3668 bgp_unlock_node (rn);
3669
3670 return CMD_SUCCESS;
3671}
3672
3673/* Called from bgp_delete(). Delete all static routes from the BGP
3674 instance. */
3675void
3676bgp_static_delete (struct bgp *bgp)
3677{
3678 afi_t afi;
3679 safi_t safi;
3680 struct bgp_node *rn;
3681 struct bgp_node *rm;
3682 struct bgp_table *table;
3683 struct bgp_static *bgp_static;
3684
3685 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3686 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3687 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3688 if (rn->info != NULL)
3689 {
3690 if (safi == SAFI_MPLS_VPN)
3691 {
3692 table = rn->info;
3693
3694 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3695 {
3696 bgp_static = rn->info;
3697 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3698 AFI_IP, SAFI_MPLS_VPN,
3699 (struct prefix_rd *)&rn->p,
3700 bgp_static->tag);
3701 bgp_static_free (bgp_static);
3702 rn->info = NULL;
3703 bgp_unlock_node (rn);
3704 }
3705 }
3706 else
3707 {
3708 bgp_static = rn->info;
3709 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3710 bgp_static_free (bgp_static);
3711 rn->info = NULL;
3712 bgp_unlock_node (rn);
3713 }
3714 }
3715}
3716
078430f6
DS
3717void
3718bgp_static_redo_import_check (struct bgp *bgp)
3719{
3720 afi_t afi;
3721 safi_t safi;
3722 struct bgp_node *rn;
078430f6
DS
3723 struct bgp_static *bgp_static;
3724
3725 /* Use this flag to force reprocessing of the route */
3726 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
3727 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3728 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3729 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3730 if (rn->info != NULL)
3731 {
3732 bgp_static = rn->info;
3733 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
3734 }
3735 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
3736}
3737
718e3744 3738int
fd79ac91 3739bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3740 const char *tag_str)
718e3744 3741{
3742 int ret;
3743 struct prefix p;
3744 struct prefix_rd prd;
3745 struct bgp *bgp;
3746 struct bgp_node *prn;
3747 struct bgp_node *rn;
3748 struct bgp_table *table;
3749 struct bgp_static *bgp_static;
3750 u_char tag[3];
3751
3752 bgp = vty->index;
3753
3754 ret = str2prefix (ip_str, &p);
3755 if (! ret)
3756 {
3757 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3758 return CMD_WARNING;
3759 }
3760 apply_mask (&p);
3761
3762 ret = str2prefix_rd (rd_str, &prd);
3763 if (! ret)
3764 {
3765 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3766 return CMD_WARNING;
3767 }
3768
3769 ret = str2tag (tag_str, tag);
3770 if (! ret)
3771 {
3772 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3773 return CMD_WARNING;
3774 }
3775
3776 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3777 (struct prefix *)&prd);
3778 if (prn->info == NULL)
64e580a7 3779 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
718e3744 3780 else
3781 bgp_unlock_node (prn);
3782 table = prn->info;
3783
3784 rn = bgp_node_get (table, &p);
3785
3786 if (rn->info)
3787 {
3788 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3789 bgp_unlock_node (rn);
3790 }
3791 else
3792 {
3793 /* New configuration. */
3794 bgp_static = bgp_static_new ();
3795 bgp_static->valid = 1;
3796 memcpy (bgp_static->tag, tag, 3);
3797 rn->info = bgp_static;
3798
3799 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3800 }
3801
3802 return CMD_SUCCESS;
3803}
3804
3805/* Configure static BGP network. */
3806int
fd79ac91 3807bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3808 const char *rd_str, const char *tag_str)
718e3744 3809{
3810 int ret;
3811 struct bgp *bgp;
3812 struct prefix p;
3813 struct prefix_rd prd;
3814 struct bgp_node *prn;
3815 struct bgp_node *rn;
3816 struct bgp_table *table;
3817 struct bgp_static *bgp_static;
3818 u_char tag[3];
3819
3820 bgp = vty->index;
3821
3822 /* Convert IP prefix string to struct prefix. */
3823 ret = str2prefix (ip_str, &p);
3824 if (! ret)
3825 {
3826 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3827 return CMD_WARNING;
3828 }
3829 apply_mask (&p);
3830
3831 ret = str2prefix_rd (rd_str, &prd);
3832 if (! ret)
3833 {
3834 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3835 return CMD_WARNING;
3836 }
3837
3838 ret = str2tag (tag_str, tag);
3839 if (! ret)
3840 {
3841 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3842 return CMD_WARNING;
3843 }
3844
3845 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3846 (struct prefix *)&prd);
3847 if (prn->info == NULL)
64e580a7 3848 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
718e3744 3849 else
3850 bgp_unlock_node (prn);
3851 table = prn->info;
3852
3853 rn = bgp_node_lookup (table, &p);
3854
3855 if (rn)
3856 {
3857 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3858
3859 bgp_static = rn->info;
3860 bgp_static_free (bgp_static);
3861 rn->info = NULL;
3862 bgp_unlock_node (rn);
3863 bgp_unlock_node (rn);
3864 }
3865 else
3866 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3867
3868 return CMD_SUCCESS;
3869}
6b0655a2 3870
73ac8160
DS
3871static int
3872bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
3873 const char *rmap_name)
3874{
3875 struct bgp_rmap *rmap;
3876
3877 rmap = &bgp->table_map[afi][safi];
3878 if (rmap_name)
3879 {
3880 if (rmap->name)
6e919709
DS
3881 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
3882 rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name);
73ac8160
DS
3883 rmap->map = route_map_lookup_by_name (rmap_name);
3884 }
3885 else
3886 {
3887 if (rmap->name)
6e919709 3888 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
73ac8160
DS
3889 rmap->name = NULL;
3890 rmap->map = NULL;
3891 }
3892
3893 bgp_zebra_announce_table(bgp, afi, safi);
3894
3895 return CMD_SUCCESS;
3896}
3897
3898static int
3899bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
3900 const char *rmap_name)
3901{
3902 struct bgp_rmap *rmap;
3903
3904 rmap = &bgp->table_map[afi][safi];
3905 if (rmap->name)
6e919709 3906 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
73ac8160
DS
3907 rmap->name = NULL;
3908 rmap->map = NULL;
3909
3910 bgp_zebra_announce_table(bgp, afi, safi);
3911
3912 return CMD_SUCCESS;
3913}
3914
3915int
3916bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
3917 safi_t safi, int *write)
3918{
3919 if (bgp->table_map[afi][safi].name)
3920 {
3921 bgp_config_write_family_header (vty, afi, safi, write);
0b960b4d 3922 vty_out (vty, " table-map %s%s",
73ac8160
DS
3923 bgp->table_map[afi][safi].name, VTY_NEWLINE);
3924 }
3925
3926 return 0;
3927}
3928
3929
3930DEFUN (bgp_table_map,
3931 bgp_table_map_cmd,
3932 "table-map WORD",
3933 "BGP table to RIB route download filter\n"
3934 "Name of the route map\n")
3935{
3936 return bgp_table_map_set (vty, vty->index,
3937 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
3938}
3939DEFUN (no_bgp_table_map,
3940 no_bgp_table_map_cmd,
3941 "no table-map WORD",
3942 "BGP table to RIB route download filter\n"
3943 "Name of the route map\n")
3944{
3945 return bgp_table_map_unset (vty, vty->index,
3946 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
3947}
3948
718e3744 3949DEFUN (bgp_network,
3950 bgp_network_cmd,
3951 "network A.B.C.D/M",
3952 "Specify a network to announce via BGP\n"
3953 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3954{
3955 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 3956 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 3957}
3958
3959DEFUN (bgp_network_route_map,
3960 bgp_network_route_map_cmd,
3961 "network A.B.C.D/M route-map WORD",
3962 "Specify a network to announce via BGP\n"
3963 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3964 "Route-map to modify the attributes\n"
3965 "Name of the route map\n")
3966{
3967 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 3968 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 3969}
3970
3971DEFUN (bgp_network_backdoor,
3972 bgp_network_backdoor_cmd,
3973 "network A.B.C.D/M backdoor",
3974 "Specify a network to announce via BGP\n"
3975 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3976 "Specify a BGP backdoor route\n")
3977{
41367172 3978 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
c8f3fe30 3979 NULL, 1);
718e3744 3980}
3981
3982DEFUN (bgp_network_mask,
3983 bgp_network_mask_cmd,
3984 "network A.B.C.D mask A.B.C.D",
3985 "Specify a network to announce via BGP\n"
3986 "Network number\n"
3987 "Network mask\n"
3988 "Network mask\n")
3989{
3990 int ret;
3991 char prefix_str[BUFSIZ];
41367172 3992
718e3744 3993 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3994 if (! ret)
3995 {
3996 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3997 return CMD_WARNING;
3998 }
3999
4000 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4001 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4002}
4003
4004DEFUN (bgp_network_mask_route_map,
4005 bgp_network_mask_route_map_cmd,
4006 "network A.B.C.D mask A.B.C.D route-map WORD",
4007 "Specify a network to announce via BGP\n"
4008 "Network number\n"
4009 "Network mask\n"
4010 "Network mask\n"
4011 "Route-map to modify the attributes\n"
4012 "Name of the route map\n")
4013{
4014 int ret;
4015 char prefix_str[BUFSIZ];
41367172 4016
718e3744 4017 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4018 if (! ret)
4019 {
4020 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4021 return CMD_WARNING;
4022 }
4023
4024 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4025 AFI_IP, bgp_node_safi (vty), argv[2], 0);
718e3744 4026}
4027
4028DEFUN (bgp_network_mask_backdoor,
4029 bgp_network_mask_backdoor_cmd,
4030 "network A.B.C.D mask A.B.C.D backdoor",
4031 "Specify a network to announce via BGP\n"
4032 "Network number\n"
4033 "Network mask\n"
4034 "Network mask\n"
4035 "Specify a BGP backdoor route\n")
4036{
4037 int ret;
4038 char prefix_str[BUFSIZ];
41367172 4039
718e3744 4040 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4041 if (! ret)
4042 {
4043 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4044 return CMD_WARNING;
4045 }
4046
41367172 4047 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 4048 NULL, 1);
718e3744 4049}
4050
4051DEFUN (bgp_network_mask_natural,
4052 bgp_network_mask_natural_cmd,
4053 "network A.B.C.D",
4054 "Specify a network to announce via BGP\n"
4055 "Network number\n")
4056{
4057 int ret;
4058 char prefix_str[BUFSIZ];
4059
4060 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4061 if (! ret)
4062 {
4063 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4064 return CMD_WARNING;
4065 }
4066
4067 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4068 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4069}
4070
4071DEFUN (bgp_network_mask_natural_route_map,
4072 bgp_network_mask_natural_route_map_cmd,
4073 "network A.B.C.D route-map WORD",
4074 "Specify a network to announce via BGP\n"
4075 "Network number\n"
4076 "Route-map to modify the attributes\n"
4077 "Name of the route map\n")
4078{
4079 int ret;
4080 char prefix_str[BUFSIZ];
4081
4082 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4083 if (! ret)
4084 {
4085 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4086 return CMD_WARNING;
4087 }
4088
4089 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4090 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 4091}
4092
4093DEFUN (bgp_network_mask_natural_backdoor,
4094 bgp_network_mask_natural_backdoor_cmd,
4095 "network A.B.C.D backdoor",
4096 "Specify a network to announce via BGP\n"
4097 "Network number\n"
4098 "Specify a BGP backdoor route\n")
4099{
4100 int ret;
4101 char prefix_str[BUFSIZ];
4102
4103 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4104 if (! ret)
4105 {
4106 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4107 return CMD_WARNING;
4108 }
4109
41367172 4110 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 4111 NULL, 1);
718e3744 4112}
4113
4114DEFUN (no_bgp_network,
4115 no_bgp_network_cmd,
4116 "no network A.B.C.D/M",
4117 NO_STR
4118 "Specify a network to announce via BGP\n"
4119 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4120{
4121 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4122 bgp_node_safi (vty));
4123}
4124
4125ALIAS (no_bgp_network,
4126 no_bgp_network_route_map_cmd,
4127 "no network A.B.C.D/M route-map WORD",
4128 NO_STR
4129 "Specify a network to announce via BGP\n"
4130 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4131 "Route-map to modify the attributes\n"
4132 "Name of the route map\n")
4133
4134ALIAS (no_bgp_network,
4135 no_bgp_network_backdoor_cmd,
4136 "no network A.B.C.D/M backdoor",
4137 NO_STR
4138 "Specify a network to announce via BGP\n"
4139 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4140 "Specify a BGP backdoor route\n")
4141
4142DEFUN (no_bgp_network_mask,
4143 no_bgp_network_mask_cmd,
4144 "no network A.B.C.D mask A.B.C.D",
4145 NO_STR
4146 "Specify a network to announce via BGP\n"
4147 "Network number\n"
4148 "Network mask\n"
4149 "Network mask\n")
4150{
4151 int ret;
4152 char prefix_str[BUFSIZ];
4153
4154 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4155 if (! ret)
4156 {
4157 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4158 return CMD_WARNING;
4159 }
4160
4161 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4162 bgp_node_safi (vty));
4163}
4164
4165ALIAS (no_bgp_network_mask,
4166 no_bgp_network_mask_route_map_cmd,
4167 "no network A.B.C.D mask A.B.C.D route-map WORD",
4168 NO_STR
4169 "Specify a network to announce via BGP\n"
4170 "Network number\n"
4171 "Network mask\n"
4172 "Network mask\n"
4173 "Route-map to modify the attributes\n"
4174 "Name of the route map\n")
4175
4176ALIAS (no_bgp_network_mask,
4177 no_bgp_network_mask_backdoor_cmd,
4178 "no network A.B.C.D mask A.B.C.D backdoor",
4179 NO_STR
4180 "Specify a network to announce via BGP\n"
4181 "Network number\n"
4182 "Network mask\n"
4183 "Network mask\n"
4184 "Specify a BGP backdoor route\n")
4185
4186DEFUN (no_bgp_network_mask_natural,
4187 no_bgp_network_mask_natural_cmd,
4188 "no network A.B.C.D",
4189 NO_STR
4190 "Specify a network to announce via BGP\n"
4191 "Network number\n")
4192{
4193 int ret;
4194 char prefix_str[BUFSIZ];
4195
4196 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4197 if (! ret)
4198 {
4199 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4200 return CMD_WARNING;
4201 }
4202
4203 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4204 bgp_node_safi (vty));
4205}
4206
4207ALIAS (no_bgp_network_mask_natural,
4208 no_bgp_network_mask_natural_route_map_cmd,
4209 "no network A.B.C.D route-map WORD",
4210 NO_STR
4211 "Specify a network to announce via BGP\n"
4212 "Network number\n"
4213 "Route-map to modify the attributes\n"
4214 "Name of the route map\n")
4215
4216ALIAS (no_bgp_network_mask_natural,
4217 no_bgp_network_mask_natural_backdoor_cmd,
4218 "no network A.B.C.D backdoor",
4219 NO_STR
4220 "Specify a network to announce via BGP\n"
4221 "Network number\n"
4222 "Specify a BGP backdoor route\n")
4223
4224#ifdef HAVE_IPV6
4225DEFUN (ipv6_bgp_network,
4226 ipv6_bgp_network_cmd,
4227 "network X:X::X:X/M",
4228 "Specify a network to announce via BGP\n"
4229 "IPv6 prefix <network>/<length>\n")
4230{
73bfe0bd 4231 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
c8f3fe30 4232 NULL, 0);
718e3744 4233}
4234
4235DEFUN (ipv6_bgp_network_route_map,
4236 ipv6_bgp_network_route_map_cmd,
4237 "network X:X::X:X/M route-map WORD",
4238 "Specify a network to announce via BGP\n"
4239 "IPv6 prefix <network>/<length>\n"
4240 "Route-map to modify the attributes\n"
4241 "Name of the route map\n")
4242{
4243 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
c8f3fe30 4244 bgp_node_safi (vty), argv[1], 0);
718e3744 4245}
4246
4247DEFUN (no_ipv6_bgp_network,
4248 no_ipv6_bgp_network_cmd,
4249 "no network X:X::X:X/M",
4250 NO_STR
4251 "Specify a network to announce via BGP\n"
4252 "IPv6 prefix <network>/<length>\n")
4253{
73bfe0bd 4254 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
718e3744 4255}
4256
4257ALIAS (no_ipv6_bgp_network,
4258 no_ipv6_bgp_network_route_map_cmd,
4259 "no network X:X::X:X/M route-map WORD",
4260 NO_STR
4261 "Specify a network to announce via BGP\n"
4262 "IPv6 prefix <network>/<length>\n"
4263 "Route-map to modify the attributes\n"
4264 "Name of the route map\n")
4265
4266ALIAS (ipv6_bgp_network,
4267 old_ipv6_bgp_network_cmd,
4268 "ipv6 bgp network X:X::X:X/M",
4269 IPV6_STR
4270 BGP_STR
4271 "Specify a network to announce via BGP\n"
4272 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4273
4274ALIAS (no_ipv6_bgp_network,
4275 old_no_ipv6_bgp_network_cmd,
4276 "no ipv6 bgp network X:X::X:X/M",
4277 NO_STR
4278 IPV6_STR
4279 BGP_STR
4280 "Specify a network to announce via BGP\n"
4281 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4282#endif /* HAVE_IPV6 */
c8f3fe30 4283
718e3744 4284/* Aggreagete address:
4285
4286 advertise-map Set condition to advertise attribute
4287 as-set Generate AS set path information
4288 attribute-map Set attributes of aggregate
4289 route-map Set parameters of aggregate
4290 summary-only Filter more specific routes from updates
4291 suppress-map Conditionally filter more specific routes from updates
4292 <cr>
4293 */
4294struct bgp_aggregate
4295{
4296 /* Summary-only flag. */
4297 u_char summary_only;
4298
4299 /* AS set generation. */
4300 u_char as_set;
4301
4302 /* Route-map for aggregated route. */
4303 struct route_map *map;
4304
4305 /* Suppress-count. */
4306 unsigned long count;
4307
4308 /* SAFI configuration. */
4309 safi_t safi;
4310};
4311
94f2b392 4312static struct bgp_aggregate *
66e5cd87 4313bgp_aggregate_new (void)
718e3744 4314{
393deb9b 4315 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
718e3744 4316}
4317
94f2b392 4318static void
718e3744 4319bgp_aggregate_free (struct bgp_aggregate *aggregate)
4320{
4321 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4322}
4323
b5d58c32 4324/* Update an aggregate as routes are added/removed from the BGP table */
94f2b392 4325static void
718e3744 4326bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4327 afi_t afi, safi_t safi, struct bgp_info *del,
4328 struct bgp_aggregate *aggregate)
4329{
4330 struct bgp_table *table;
4331 struct bgp_node *top;
4332 struct bgp_node *rn;
4333 u_char origin;
4334 struct aspath *aspath = NULL;
4335 struct aspath *asmerge = NULL;
4336 struct community *community = NULL;
4337 struct community *commerge = NULL;
ffd0c037 4338#if defined(AGGREGATE_NEXTHOP_CHECK)
718e3744 4339 struct in_addr nexthop;
4340 u_int32_t med = 0;
ffd0c037 4341#endif
718e3744 4342 struct bgp_info *ri;
4343 struct bgp_info *new;
4344 int first = 1;
4345 unsigned long match = 0;
42f7e184 4346 u_char atomic_aggregate = 0;
718e3744 4347
4348 /* Record adding route's nexthop and med. */
ffd0c037
DS
4349 if (rinew)
4350 {
4351#if defined(AGGREGATE_NEXTHOP_CHECK)
4352 nexthop = rinew->attr->nexthop;
4353 med = rinew->attr->med;
4354#endif
4355 }
718e3744 4356
4357 /* ORIGIN attribute: If at least one route among routes that are
4358 aggregated has ORIGIN with the value INCOMPLETE, then the
4359 aggregated route must have the ORIGIN attribute with the value
4360 INCOMPLETE. Otherwise, if at least one route among routes that
4361 are aggregated has ORIGIN with the value EGP, then the aggregated
4362 route must have the origin attribute with the value EGP. In all
4363 other case the value of the ORIGIN attribute of the aggregated
4364 route is INTERNAL. */
4365 origin = BGP_ORIGIN_IGP;
4366
4367 table = bgp->rib[afi][safi];
4368
4369 top = bgp_node_get (table, p);
4370 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4371 if (rn->p.prefixlen > p->prefixlen)
4372 {
4373 match = 0;
4374
4375 for (ri = rn->info; ri; ri = ri->next)
4376 {
4377 if (BGP_INFO_HOLDDOWN (ri))
4378 continue;
4379
4380 if (del && ri == del)
4381 continue;
4382
4383 if (! rinew && first)
4384 {
ffd0c037 4385#if defined(AGGREGATE_NEXTHOP_CHECK)
718e3744 4386 nexthop = ri->attr->nexthop;
4387 med = ri->attr->med;
ffd0c037 4388#endif
718e3744 4389 first = 0;
4390 }
4391
4392#ifdef AGGREGATE_NEXTHOP_CHECK
4393 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4394 || ri->attr->med != med)
4395 {
4396 if (aspath)
4397 aspath_free (aspath);
4398 if (community)
4399 community_free (community);
4400 bgp_unlock_node (rn);
4401 bgp_unlock_node (top);
4402 return;
4403 }
4404#endif /* AGGREGATE_NEXTHOP_CHECK */
4405
42f7e184
DS
4406 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4407 atomic_aggregate = 1;
4408
718e3744 4409 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4410 {
4411 if (aggregate->summary_only)
4412 {
fb982c25 4413 (bgp_info_extra_get (ri))->suppress++;
1a392d46 4414 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4415 match++;
4416 }
4417
4418 aggregate->count++;
4419
b5d58c32
DS
4420 if (origin < ri->attr->origin)
4421 origin = ri->attr->origin;
4422
718e3744 4423 if (aggregate->as_set)
4424 {
718e3744 4425 if (aspath)
4426 {
4427 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4428 aspath_free (aspath);
4429 aspath = asmerge;
4430 }
4431 else
4432 aspath = aspath_dup (ri->attr->aspath);
4433
4434 if (ri->attr->community)
4435 {
4436 if (community)
4437 {
4438 commerge = community_merge (community,
4439 ri->attr->community);
4440 community = community_uniq_sort (commerge);
4441 community_free (commerge);
4442 }
4443 else
4444 community = community_dup (ri->attr->community);
4445 }
4446 }
4447 }
4448 }
4449 if (match)
4450 bgp_process (bgp, rn, afi, safi);
4451 }
4452 bgp_unlock_node (top);
4453
4454 if (rinew)
4455 {
4456 aggregate->count++;
4457
4458 if (aggregate->summary_only)
fb982c25 4459 (bgp_info_extra_get (rinew))->suppress++;
718e3744 4460
b5d58c32
DS
4461 if (origin < rinew->attr->origin)
4462 origin = rinew->attr->origin;
4463
718e3744 4464 if (aggregate->as_set)
4465 {
718e3744 4466 if (aspath)
4467 {
4468 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4469 aspath_free (aspath);
4470 aspath = asmerge;
4471 }
4472 else
4473 aspath = aspath_dup (rinew->attr->aspath);
4474
4475 if (rinew->attr->community)
4476 {
4477 if (community)
4478 {
4479 commerge = community_merge (community,
4480 rinew->attr->community);
4481 community = community_uniq_sort (commerge);
4482 community_free (commerge);
4483 }
4484 else
4485 community = community_dup (rinew->attr->community);
4486 }
4487 }
4488 }
4489
4490 if (aggregate->count > 0)
4491 {
4492 rn = bgp_node_get (table, p);
7c8ff89e 4493 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 4494 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
4495 aggregate->as_set,
4496 atomic_aggregate), rn);
718e3744 4497 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 4498
4499 bgp_info_add (rn, new);
200df115 4500 bgp_unlock_node (rn);
718e3744 4501 bgp_process (bgp, rn, afi, safi);
4502 }
4503 else
4504 {
4505 if (aspath)
4506 aspath_free (aspath);
4507 if (community)
4508 community_free (community);
4509 }
4510}
4511
4512void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4513 struct bgp_aggregate *);
4514
4515void
4516bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4517 struct bgp_info *ri, afi_t afi, safi_t safi)
4518{
4519 struct bgp_node *child;
4520 struct bgp_node *rn;
4521 struct bgp_aggregate *aggregate;
f018db83 4522 struct bgp_table *table;
718e3744 4523
4524 /* MPLS-VPN aggregation is not yet supported. */
4525 if (safi == SAFI_MPLS_VPN)
4526 return;
4527
f018db83
JBD
4528 table = bgp->aggregate[afi][safi];
4529
4530 /* No aggregates configured. */
67174041 4531 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
4532 return;
4533
718e3744 4534 if (p->prefixlen == 0)
4535 return;
4536
4537 if (BGP_INFO_HOLDDOWN (ri))
4538 return;
4539
bb782fb5 4540 child = bgp_node_get (table, p);
718e3744 4541
4542 /* Aggregate address configuration check. */
67174041 4543 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 4544 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4545 {
4546 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 4547 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
718e3744 4548 }
4549 bgp_unlock_node (child);
4550}
4551
4552void
4553bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4554 struct bgp_info *del, afi_t afi, safi_t safi)
4555{
4556 struct bgp_node *child;
4557 struct bgp_node *rn;
4558 struct bgp_aggregate *aggregate;
f018db83 4559 struct bgp_table *table;
718e3744 4560
4561 /* MPLS-VPN aggregation is not yet supported. */
4562 if (safi == SAFI_MPLS_VPN)
4563 return;
4564
f018db83
JBD
4565 table = bgp->aggregate[afi][safi];
4566
4567 /* No aggregates configured. */
67174041 4568 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
4569 return;
4570
718e3744 4571 if (p->prefixlen == 0)
4572 return;
4573
bb782fb5 4574 child = bgp_node_get (table, p);
718e3744 4575
4576 /* Aggregate address configuration check. */
67174041 4577 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 4578 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4579 {
4580 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 4581 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
718e3744 4582 }
4583 bgp_unlock_node (child);
4584}
4585
b5d58c32 4586/* Called via bgp_aggregate_set when the user configures aggregate-address */
94f2b392 4587static void
718e3744 4588bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4589 struct bgp_aggregate *aggregate)
4590{
4591 struct bgp_table *table;
4592 struct bgp_node *top;
4593 struct bgp_node *rn;
4594 struct bgp_info *new;
4595 struct bgp_info *ri;
4596 unsigned long match;
4597 u_char origin = BGP_ORIGIN_IGP;
4598 struct aspath *aspath = NULL;
4599 struct aspath *asmerge = NULL;
4600 struct community *community = NULL;
4601 struct community *commerge = NULL;
42f7e184 4602 u_char atomic_aggregate = 0;
718e3744 4603
4604 table = bgp->rib[afi][safi];
4605
4606 /* Sanity check. */
4607 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4608 return;
4609 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4610 return;
4611
4612 /* If routes exists below this node, generate aggregate routes. */
4613 top = bgp_node_get (table, p);
4614 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4615 if (rn->p.prefixlen > p->prefixlen)
4616 {
4617 match = 0;
4618
4619 for (ri = rn->info; ri; ri = ri->next)
4620 {
4621 if (BGP_INFO_HOLDDOWN (ri))
4622 continue;
4623
42f7e184
DS
4624 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4625 atomic_aggregate = 1;
4626
718e3744 4627 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4628 {
4629 /* summary-only aggregate route suppress aggregated
4630 route announcement. */
4631 if (aggregate->summary_only)
4632 {
fb982c25 4633 (bgp_info_extra_get (ri))->suppress++;
1a392d46 4634 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4635 match++;
4636 }
b5d58c32
DS
4637
4638 /* If at least one route among routes that are aggregated has
4639 * ORIGIN with the value INCOMPLETE, then the aggregated route
4640 * MUST have the ORIGIN attribute with the value INCOMPLETE.
4641 * Otherwise, if at least one route among routes that are
4642 * aggregated has ORIGIN with the value EGP, then the aggregated
4643 * route MUST have the ORIGIN attribute with the value EGP.
4644 */
4645 if (origin < ri->attr->origin)
4646 origin = ri->attr->origin;
4647
718e3744 4648 /* as-set aggregate route generate origin, as path,
4649 community aggregation. */
4650 if (aggregate->as_set)
4651 {
718e3744 4652 if (aspath)
4653 {
4654 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4655 aspath_free (aspath);
4656 aspath = asmerge;
4657 }
4658 else
4659 aspath = aspath_dup (ri->attr->aspath);
4660
4661 if (ri->attr->community)
4662 {
4663 if (community)
4664 {
4665 commerge = community_merge (community,
4666 ri->attr->community);
4667 community = community_uniq_sort (commerge);
4668 community_free (commerge);
4669 }
4670 else
4671 community = community_dup (ri->attr->community);
4672 }
4673 }
4674 aggregate->count++;
4675 }
4676 }
4677
4678 /* If this node is suppressed, process the change. */
4679 if (match)
4680 bgp_process (bgp, rn, afi, safi);
4681 }
4682 bgp_unlock_node (top);
4683
4684 /* Add aggregate route to BGP table. */
4685 if (aggregate->count)
4686 {
4687 rn = bgp_node_get (table, p);
7c8ff89e 4688 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 4689 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
4690 aggregate->as_set,
4691 atomic_aggregate), rn);
718e3744 4692 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 4693
4694 bgp_info_add (rn, new);
200df115 4695 bgp_unlock_node (rn);
4696
718e3744 4697 /* Process change. */
4698 bgp_process (bgp, rn, afi, safi);
4699 }
610f23cf
DV
4700 else
4701 {
4702 if (aspath)
4703 aspath_free (aspath);
4704 if (community)
4705 community_free (community);
4706 }
718e3744 4707}
4708
4709void
4710bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4711 safi_t safi, struct bgp_aggregate *aggregate)
4712{
4713 struct bgp_table *table;
4714 struct bgp_node *top;
4715 struct bgp_node *rn;
4716 struct bgp_info *ri;
4717 unsigned long match;
4718
4719 table = bgp->rib[afi][safi];
4720
4721 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4722 return;
4723 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4724 return;
4725
4726 /* If routes exists below this node, generate aggregate routes. */
4727 top = bgp_node_get (table, p);
4728 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4729 if (rn->p.prefixlen > p->prefixlen)
4730 {
4731 match = 0;
4732
4733 for (ri = rn->info; ri; ri = ri->next)
4734 {
4735 if (BGP_INFO_HOLDDOWN (ri))
4736 continue;
4737
4738 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4739 {
fb982c25 4740 if (aggregate->summary_only && ri->extra)
718e3744 4741 {
fb982c25 4742 ri->extra->suppress--;
718e3744 4743
fb982c25 4744 if (ri->extra->suppress == 0)
718e3744 4745 {
1a392d46 4746 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4747 match++;
4748 }
4749 }
4750 aggregate->count--;
4751 }
4752 }
4753
fb982c25 4754 /* If this node was suppressed, process the change. */
718e3744 4755 if (match)
4756 bgp_process (bgp, rn, afi, safi);
4757 }
4758 bgp_unlock_node (top);
4759
4760 /* Delete aggregate route from BGP table. */
4761 rn = bgp_node_get (table, p);
4762
4763 for (ri = rn->info; ri; ri = ri->next)
4764 if (ri->peer == bgp->peer_self
4765 && ri->type == ZEBRA_ROUTE_BGP
4766 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4767 break;
4768
4769 /* Withdraw static BGP route from routing table. */
4770 if (ri)
4771 {
718e3744 4772 bgp_info_delete (rn, ri);
1a392d46 4773 bgp_process (bgp, rn, afi, safi);
718e3744 4774 }
4775
4776 /* Unlock bgp_node_lookup. */
4777 bgp_unlock_node (rn);
4778}
4779
4780/* Aggregate route attribute. */
4781#define AGGREGATE_SUMMARY_ONLY 1
4782#define AGGREGATE_AS_SET 1
4783
94f2b392 4784static int
f6269b4f
RB
4785bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4786 afi_t afi, safi_t safi)
718e3744 4787{
4788 int ret;
4789 struct prefix p;
4790 struct bgp_node *rn;
4791 struct bgp *bgp;
4792 struct bgp_aggregate *aggregate;
4793
4794 /* Convert string to prefix structure. */
4795 ret = str2prefix (prefix_str, &p);
4796 if (!ret)
4797 {
4798 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4799 return CMD_WARNING;
4800 }
4801 apply_mask (&p);
4802
4803 /* Get BGP structure. */
4804 bgp = vty->index;
4805
4806 /* Old configuration check. */
f6269b4f
RB
4807 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4808 if (! rn)
718e3744 4809 {
f6269b4f
RB
4810 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4811 VTY_NEWLINE);
718e3744 4812 return CMD_WARNING;
4813 }
4814
f6269b4f
RB
4815 aggregate = rn->info;
4816 if (aggregate->safi & SAFI_UNICAST)
4817 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4818 if (aggregate->safi & SAFI_MULTICAST)
4819 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 4820
f6269b4f
RB
4821 /* Unlock aggregate address configuration. */
4822 rn->info = NULL;
4823 bgp_aggregate_free (aggregate);
4824 bgp_unlock_node (rn);
4825 bgp_unlock_node (rn);
718e3744 4826
4827 return CMD_SUCCESS;
4828}
4829
94f2b392 4830static int
f6269b4f
RB
4831bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4832 afi_t afi, safi_t safi,
4833 u_char summary_only, u_char as_set)
718e3744 4834{
4835 int ret;
4836 struct prefix p;
4837 struct bgp_node *rn;
4838 struct bgp *bgp;
4839 struct bgp_aggregate *aggregate;
4840
4841 /* Convert string to prefix structure. */
4842 ret = str2prefix (prefix_str, &p);
4843 if (!ret)
4844 {
4845 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4846 return CMD_WARNING;
4847 }
4848 apply_mask (&p);
4849
4850 /* Get BGP structure. */
4851 bgp = vty->index;
4852
4853 /* Old configuration check. */
f6269b4f
RB
4854 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4855
4856 if (rn->info)
718e3744 4857 {
f6269b4f 4858 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
368473f6 4859 /* try to remove the old entry */
f6269b4f
RB
4860 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4861 if (ret)
4862 {
368473f6
RB
4863 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4864 bgp_unlock_node (rn);
f6269b4f
RB
4865 return CMD_WARNING;
4866 }
718e3744 4867 }
4868
f6269b4f
RB
4869 /* Make aggregate address structure. */
4870 aggregate = bgp_aggregate_new ();
4871 aggregate->summary_only = summary_only;
4872 aggregate->as_set = as_set;
4873 aggregate->safi = safi;
4874 rn->info = aggregate;
718e3744 4875
f6269b4f
RB
4876 /* Aggregate address insert into BGP routing table. */
4877 if (safi & SAFI_UNICAST)
4878 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4879 if (safi & SAFI_MULTICAST)
4880 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 4881
4882 return CMD_SUCCESS;
4883}
4884
4885DEFUN (aggregate_address,
4886 aggregate_address_cmd,
4887 "aggregate-address A.B.C.D/M",
4888 "Configure BGP aggregate entries\n"
4889 "Aggregate prefix\n")
4890{
4891 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4892}
4893
4894DEFUN (aggregate_address_mask,
4895 aggregate_address_mask_cmd,
4896 "aggregate-address A.B.C.D A.B.C.D",
4897 "Configure BGP aggregate entries\n"
4898 "Aggregate address\n"
4899 "Aggregate mask\n")
4900{
4901 int ret;
4902 char prefix_str[BUFSIZ];
4903
4904 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4905
4906 if (! ret)
4907 {
4908 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4909 return CMD_WARNING;
4910 }
4911
4912 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4913 0, 0);
4914}
4915
4916DEFUN (aggregate_address_summary_only,
4917 aggregate_address_summary_only_cmd,
4918 "aggregate-address A.B.C.D/M summary-only",
4919 "Configure BGP aggregate entries\n"
4920 "Aggregate prefix\n"
4921 "Filter more specific routes from updates\n")
4922{
4923 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4924 AGGREGATE_SUMMARY_ONLY, 0);
4925}
4926
4927DEFUN (aggregate_address_mask_summary_only,
4928 aggregate_address_mask_summary_only_cmd,
4929 "aggregate-address A.B.C.D A.B.C.D summary-only",
4930 "Configure BGP aggregate entries\n"
4931 "Aggregate address\n"
4932 "Aggregate mask\n"
4933 "Filter more specific routes from updates\n")
4934{
4935 int ret;
4936 char prefix_str[BUFSIZ];
4937
4938 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4939
4940 if (! ret)
4941 {
4942 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4943 return CMD_WARNING;
4944 }
4945
4946 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4947 AGGREGATE_SUMMARY_ONLY, 0);
4948}
4949
4950DEFUN (aggregate_address_as_set,
4951 aggregate_address_as_set_cmd,
4952 "aggregate-address A.B.C.D/M as-set",
4953 "Configure BGP aggregate entries\n"
4954 "Aggregate prefix\n"
4955 "Generate AS set path information\n")
4956{
4957 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4958 0, AGGREGATE_AS_SET);
4959}
4960
4961DEFUN (aggregate_address_mask_as_set,
4962 aggregate_address_mask_as_set_cmd,
4963 "aggregate-address A.B.C.D A.B.C.D as-set",
4964 "Configure BGP aggregate entries\n"
4965 "Aggregate address\n"
4966 "Aggregate mask\n"
4967 "Generate AS set path information\n")
4968{
4969 int ret;
4970 char prefix_str[BUFSIZ];
4971
4972 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4973
4974 if (! ret)
4975 {
4976 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4977 return CMD_WARNING;
4978 }
4979
4980 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4981 0, AGGREGATE_AS_SET);
4982}
4983
4984
4985DEFUN (aggregate_address_as_set_summary,
4986 aggregate_address_as_set_summary_cmd,
4987 "aggregate-address A.B.C.D/M as-set summary-only",
4988 "Configure BGP aggregate entries\n"
4989 "Aggregate prefix\n"
4990 "Generate AS set path information\n"
4991 "Filter more specific routes from updates\n")
4992{
4993 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4994 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4995}
4996
4997ALIAS (aggregate_address_as_set_summary,
4998 aggregate_address_summary_as_set_cmd,
4999 "aggregate-address A.B.C.D/M summary-only as-set",
5000 "Configure BGP aggregate entries\n"
5001 "Aggregate prefix\n"
5002 "Filter more specific routes from updates\n"
5003 "Generate AS set path information\n")
5004
5005DEFUN (aggregate_address_mask_as_set_summary,
5006 aggregate_address_mask_as_set_summary_cmd,
5007 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5008 "Configure BGP aggregate entries\n"
5009 "Aggregate address\n"
5010 "Aggregate mask\n"
5011 "Generate AS set path information\n"
5012 "Filter more specific routes from updates\n")
5013{
5014 int ret;
5015 char prefix_str[BUFSIZ];
5016
5017 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5018
5019 if (! ret)
5020 {
5021 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5022 return CMD_WARNING;
5023 }
5024
5025 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5026 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5027}
5028
5029ALIAS (aggregate_address_mask_as_set_summary,
5030 aggregate_address_mask_summary_as_set_cmd,
5031 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5032 "Configure BGP aggregate entries\n"
5033 "Aggregate address\n"
5034 "Aggregate mask\n"
5035 "Filter more specific routes from updates\n"
5036 "Generate AS set path information\n")
5037
5038DEFUN (no_aggregate_address,
5039 no_aggregate_address_cmd,
5040 "no aggregate-address A.B.C.D/M",
5041 NO_STR
5042 "Configure BGP aggregate entries\n"
5043 "Aggregate prefix\n")
5044{
5045 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5046}
5047
5048ALIAS (no_aggregate_address,
5049 no_aggregate_address_summary_only_cmd,
5050 "no aggregate-address A.B.C.D/M summary-only",
5051 NO_STR
5052 "Configure BGP aggregate entries\n"
5053 "Aggregate prefix\n"
5054 "Filter more specific routes from updates\n")
5055
5056ALIAS (no_aggregate_address,
5057 no_aggregate_address_as_set_cmd,
5058 "no aggregate-address A.B.C.D/M as-set",
5059 NO_STR
5060 "Configure BGP aggregate entries\n"
5061 "Aggregate prefix\n"
5062 "Generate AS set path information\n")
5063
5064ALIAS (no_aggregate_address,
5065 no_aggregate_address_as_set_summary_cmd,
5066 "no aggregate-address A.B.C.D/M as-set summary-only",
5067 NO_STR
5068 "Configure BGP aggregate entries\n"
5069 "Aggregate prefix\n"
5070 "Generate AS set path information\n"
5071 "Filter more specific routes from updates\n")
5072
5073ALIAS (no_aggregate_address,
5074 no_aggregate_address_summary_as_set_cmd,
5075 "no aggregate-address A.B.C.D/M summary-only as-set",
5076 NO_STR
5077 "Configure BGP aggregate entries\n"
5078 "Aggregate prefix\n"
5079 "Filter more specific routes from updates\n"
5080 "Generate AS set path information\n")
5081
5082DEFUN (no_aggregate_address_mask,
5083 no_aggregate_address_mask_cmd,
5084 "no aggregate-address A.B.C.D A.B.C.D",
5085 NO_STR
5086 "Configure BGP aggregate entries\n"
5087 "Aggregate address\n"
5088 "Aggregate mask\n")
5089{
5090 int ret;
5091 char prefix_str[BUFSIZ];
5092
5093 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5094
5095 if (! ret)
5096 {
5097 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5098 return CMD_WARNING;
5099 }
5100
5101 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5102}
5103
5104ALIAS (no_aggregate_address_mask,
5105 no_aggregate_address_mask_summary_only_cmd,
5106 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5107 NO_STR
5108 "Configure BGP aggregate entries\n"
5109 "Aggregate address\n"
5110 "Aggregate mask\n"
5111 "Filter more specific routes from updates\n")
5112
5113ALIAS (no_aggregate_address_mask,
5114 no_aggregate_address_mask_as_set_cmd,
5115 "no aggregate-address A.B.C.D A.B.C.D as-set",
5116 NO_STR
5117 "Configure BGP aggregate entries\n"
5118 "Aggregate address\n"
5119 "Aggregate mask\n"
5120 "Generate AS set path information\n")
5121
5122ALIAS (no_aggregate_address_mask,
5123 no_aggregate_address_mask_as_set_summary_cmd,
5124 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5125 NO_STR
5126 "Configure BGP aggregate entries\n"
5127 "Aggregate address\n"
5128 "Aggregate mask\n"
5129 "Generate AS set path information\n"
5130 "Filter more specific routes from updates\n")
5131
5132ALIAS (no_aggregate_address_mask,
5133 no_aggregate_address_mask_summary_as_set_cmd,
5134 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5135 NO_STR
5136 "Configure BGP aggregate entries\n"
5137 "Aggregate address\n"
5138 "Aggregate mask\n"
5139 "Filter more specific routes from updates\n"
5140 "Generate AS set path information\n")
5141
5142#ifdef HAVE_IPV6
5143DEFUN (ipv6_aggregate_address,
5144 ipv6_aggregate_address_cmd,
5145 "aggregate-address X:X::X:X/M",
5146 "Configure BGP aggregate entries\n"
5147 "Aggregate prefix\n")
5148{
5149 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5150}
5151
5152DEFUN (ipv6_aggregate_address_summary_only,
5153 ipv6_aggregate_address_summary_only_cmd,
5154 "aggregate-address X:X::X:X/M summary-only",
5155 "Configure BGP aggregate entries\n"
5156 "Aggregate prefix\n"
5157 "Filter more specific routes from updates\n")
5158{
5159 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5160 AGGREGATE_SUMMARY_ONLY, 0);
5161}
5162
5163DEFUN (no_ipv6_aggregate_address,
5164 no_ipv6_aggregate_address_cmd,
5165 "no aggregate-address X:X::X:X/M",
5166 NO_STR
5167 "Configure BGP aggregate entries\n"
5168 "Aggregate prefix\n")
5169{
5170 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5171}
5172
5173DEFUN (no_ipv6_aggregate_address_summary_only,
5174 no_ipv6_aggregate_address_summary_only_cmd,
5175 "no aggregate-address X:X::X:X/M summary-only",
5176 NO_STR
5177 "Configure BGP aggregate entries\n"
5178 "Aggregate prefix\n"
5179 "Filter more specific routes from updates\n")
5180{
5181 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5182}
5183
5184ALIAS (ipv6_aggregate_address,
5185 old_ipv6_aggregate_address_cmd,
5186 "ipv6 bgp aggregate-address X:X::X:X/M",
5187 IPV6_STR
5188 BGP_STR
5189 "Configure BGP aggregate entries\n"
5190 "Aggregate prefix\n")
5191
5192ALIAS (ipv6_aggregate_address_summary_only,
5193 old_ipv6_aggregate_address_summary_only_cmd,
5194 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5195 IPV6_STR
5196 BGP_STR
5197 "Configure BGP aggregate entries\n"
5198 "Aggregate prefix\n"
5199 "Filter more specific routes from updates\n")
5200
5201ALIAS (no_ipv6_aggregate_address,
5202 old_no_ipv6_aggregate_address_cmd,
5203 "no ipv6 bgp aggregate-address X:X::X:X/M",
5204 NO_STR
5205 IPV6_STR
5206 BGP_STR
5207 "Configure BGP aggregate entries\n"
5208 "Aggregate prefix\n")
5209
5210ALIAS (no_ipv6_aggregate_address_summary_only,
5211 old_no_ipv6_aggregate_address_summary_only_cmd,
5212 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5213 NO_STR
5214 IPV6_STR
5215 BGP_STR
5216 "Configure BGP aggregate entries\n"
5217 "Aggregate prefix\n"
5218 "Filter more specific routes from updates\n")
5219#endif /* HAVE_IPV6 */
6b0655a2 5220
718e3744 5221/* Redistribute route treatment. */
5222void
f04a80a5 5223bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
bc413143 5224 const struct in6_addr *nexthop6, unsigned int ifindex,
7c8ff89e 5225 u_int32_t metric, u_char type, u_short instance, u_short tag)
718e3744 5226{
5227 struct bgp *bgp;
1eb8ef25 5228 struct listnode *node, *nnode;
718e3744 5229 struct bgp_info *new;
5230 struct bgp_info *bi;
5231 struct bgp_info info;
5232 struct bgp_node *bn;
e16a4133 5233 struct attr attr;
718e3744 5234 struct attr *new_attr;
5235 afi_t afi;
5236 int ret;
7c8ff89e 5237 struct bgp_redist *red;
718e3744 5238
5239 /* Make default attribute. */
5240 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5241 if (nexthop)
5242 attr.nexthop = *nexthop;
bc413143 5243 attr.nh_ifindex = ifindex;
718e3744 5244
f04a80a5
SH
5245#ifdef HAVE_IPV6
5246 if (nexthop6)
5247 {
5248 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5249 extra->mp_nexthop_global = *nexthop6;
801a9bcc 5250 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
f04a80a5
SH
5251 }
5252#endif
5253
718e3744 5254 attr.med = metric;
5255 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
0d9551dc 5256 attr.extra->tag = tag;
718e3744 5257
1eb8ef25 5258 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 5259 {
5260 afi = family2afi (p->family);
5261
7c8ff89e
DS
5262 red = bgp_redist_lookup(bgp, afi, type, instance);
5263 if (red)
718e3744 5264 {
558d1fec
JBD
5265 struct attr attr_new;
5266 struct attr_extra extra_new;
5267
718e3744 5268 /* Copy attribute for modification. */
558d1fec 5269 attr_new.extra = &extra_new;
fb982c25 5270 bgp_attr_dup (&attr_new, &attr);
718e3744 5271
7c8ff89e
DS
5272 if (red->redist_metric_flag)
5273 attr_new.med = red->redist_metric;
718e3744 5274
5275 /* Apply route-map. */
91e89998 5276 if (red->rmap.name)
718e3744 5277 {
5278 info.peer = bgp->peer_self;
5279 info.attr = &attr_new;
5280
fee0f4c6 5281 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5282
7c8ff89e 5283 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
fee0f4c6 5284
5285 bgp->peer_self->rmap_type = 0;
5286
718e3744 5287 if (ret == RMAP_DENYMATCH)
5288 {
5289 /* Free uninterned attribute. */
5290 bgp_attr_flush (&attr_new);
558d1fec 5291
718e3744 5292 /* Unintern original. */
f6f434b2 5293 aspath_unintern (&attr.aspath);
fb982c25 5294 bgp_attr_extra_free (&attr);
7c8ff89e 5295 bgp_redistribute_delete (p, type, instance);
718e3744 5296 return;
5297 }
5298 }
5299
fb982c25
PJ
5300 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5301 afi, SAFI_UNICAST, p, NULL);
5302
718e3744 5303 new_attr = bgp_attr_intern (&attr_new);
558d1fec 5304
718e3744 5305 for (bi = bn->info; bi; bi = bi->next)
5306 if (bi->peer == bgp->peer_self
5307 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5308 break;
5309
5310 if (bi)
5311 {
1844fdbd 5312 /* Ensure the (source route) type is updated. */
5313 bi->type = type;
8d45210e
AS
5314 if (attrhash_cmp (bi->attr, new_attr) &&
5315 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
718e3744 5316 {
f6f434b2
PJ
5317 bgp_attr_unintern (&new_attr);
5318 aspath_unintern (&attr.aspath);
fb982c25 5319 bgp_attr_extra_free (&attr);
718e3744 5320 bgp_unlock_node (bn);
5321 return;
5322 }
5323 else
5324 {
5325 /* The attribute is changed. */
1a392d46 5326 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
718e3744 5327
5328 /* Rewrite BGP route information. */
8d45210e
AS
5329 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5330 bgp_info_restore(bn, bi);
5331 else
5332 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
f6f434b2 5333 bgp_attr_unintern (&bi->attr);
718e3744 5334 bi->attr = new_attr;
65957886 5335 bi->uptime = bgp_clock ();
718e3744 5336
5337 /* Process change. */
5338 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5339 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5340 bgp_unlock_node (bn);
f6f434b2 5341 aspath_unintern (&attr.aspath);
fb982c25 5342 bgp_attr_extra_free (&attr);
718e3744 5343 return;
fb018d25 5344 }
718e3744 5345 }
5346
7c8ff89e 5347 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
fb018d25 5348 new_attr, bn);
718e3744 5349 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 5350
5351 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5352 bgp_info_add (bn, new);
200df115 5353 bgp_unlock_node (bn);
718e3744 5354 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5355 }
5356 }
5357
5358 /* Unintern original. */
f6f434b2 5359 aspath_unintern (&attr.aspath);
fb982c25 5360 bgp_attr_extra_free (&attr);
718e3744 5361}
5362
5363void
7c8ff89e 5364bgp_redistribute_delete (struct prefix *p, u_char type, u_short instance)
718e3744 5365{
5366 struct bgp *bgp;
1eb8ef25 5367 struct listnode *node, *nnode;
718e3744 5368 afi_t afi;
5369 struct bgp_node *rn;
5370 struct bgp_info *ri;
7c8ff89e 5371 struct bgp_redist *red;
718e3744 5372
1eb8ef25 5373 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 5374 {
5375 afi = family2afi (p->family);
5376
7c8ff89e
DS
5377 red = bgp_redist_lookup(bgp, afi, type, instance);
5378 if (red)
718e3744 5379 {
fee0f4c6 5380 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
718e3744 5381
5382 for (ri = rn->info; ri; ri = ri->next)
5383 if (ri->peer == bgp->peer_self
5384 && ri->type == type)
5385 break;
5386
5387 if (ri)
5388 {
5389 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
718e3744 5390 bgp_info_delete (rn, ri);
1a392d46 5391 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 5392 }
5393 bgp_unlock_node (rn);
5394 }
5395 }
5396}
5397
5398/* Withdraw specified route type's route. */
5399void
7c8ff89e 5400bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
718e3744 5401{
5402 struct bgp_node *rn;
5403 struct bgp_info *ri;
5404 struct bgp_table *table;
5405
5406 table = bgp->rib[afi][SAFI_UNICAST];
5407
5408 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5409 {
5410 for (ri = rn->info; ri; ri = ri->next)
5411 if (ri->peer == bgp->peer_self
7c8ff89e
DS
5412 && ri->type == type
5413 && ri->instance == instance)
718e3744 5414 break;
5415
5416 if (ri)
5417 {
5418 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
718e3744 5419 bgp_info_delete (rn, ri);
1a392d46 5420 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 5421 }
5422 }
5423}
6b0655a2 5424
718e3744 5425/* Static function to display route. */
94f2b392 5426static void
718e3744 5427route_vty_out_route (struct prefix *p, struct vty *vty)
5428{
5429 int len;
5430 u_int32_t destination;
5431 char buf[BUFSIZ];
5432
5433 if (p->family == AF_INET)
5434 {
5435 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5436 destination = ntohl (p->u.prefix4.s_addr);
5437
5438 if ((IN_CLASSC (destination) && p->prefixlen == 24)
856ca177
MS
5439 || (IN_CLASSB (destination) && p->prefixlen == 16)
5440 || (IN_CLASSA (destination) && p->prefixlen == 8)
5441 || p->u.prefix4.s_addr == 0)
5442 {
5443 /* When mask is natural, mask is not displayed. */
5444 }
718e3744 5445 else
856ca177 5446 len += vty_out (vty, "/%d", p->prefixlen);
718e3744 5447 }
5448 else
5449 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5450 p->prefixlen);
5451
5452 len = 17 - len;
5453 if (len < 1)
5454 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5455 else
5456 vty_out (vty, "%*s", len, " ");
5457}
5458
718e3744 5459enum bgp_display_type
5460{
5461 normal_list,
5462};
5463
b40d939b 5464/* Print the short form route status for a bgp_info */
5465static void
b05a1c8b
DS
5466route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
5467 json_object *json_path)
718e3744 5468{
b05a1c8b
DS
5469 if (json_path)
5470 {
b05a1c8b
DS
5471
5472 /* Route status display. */
5473 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
f1aa5d8a 5474 json_object_boolean_true_add(json_path, "removed");
b05a1c8b
DS
5475
5476 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
f1aa5d8a 5477 json_object_boolean_true_add(json_path, "stale");
b05a1c8b
DS
5478
5479 if (binfo->extra && binfo->extra->suppress)
f1aa5d8a 5480 json_object_boolean_true_add(json_path, "suppressed");
b05a1c8b
DS
5481
5482 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5483 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
f1aa5d8a 5484 json_object_boolean_true_add(json_path, "valid");
b05a1c8b
DS
5485
5486 /* Selected */
5487 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
f1aa5d8a 5488 json_object_boolean_true_add(json_path, "history");
b05a1c8b
DS
5489
5490 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
f1aa5d8a 5491 json_object_boolean_true_add(json_path, "damped");
b05a1c8b
DS
5492
5493 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
f1aa5d8a 5494 json_object_boolean_true_add(json_path, "bestpath");
b05a1c8b
DS
5495
5496 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
f1aa5d8a 5497 json_object_boolean_true_add(json_path, "multipath");
b05a1c8b
DS
5498
5499 /* Internal route. */
5500 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
62d6dca0 5501 json_object_string_add(json_path, "pathFrom", "internal");
b05a1c8b 5502 else
62d6dca0 5503 json_object_string_add(json_path, "pathFrom", "external");
b05a1c8b
DS
5504
5505 return;
5506 }
5507
b40d939b 5508 /* Route status display. */
5509 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5510 vty_out (vty, "R");
5511 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
93406d87 5512 vty_out (vty, "S");
fb982c25 5513 else if (binfo->extra && binfo->extra->suppress)
718e3744 5514 vty_out (vty, "s");
31eba040
DS
5515 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5516 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
718e3744 5517 vty_out (vty, "*");
5518 else
5519 vty_out (vty, " ");
5520
5521 /* Selected */
5522 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5523 vty_out (vty, "h");
5524 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5525 vty_out (vty, "d");
5526 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5527 vty_out (vty, ">");
b366b518
BB
5528 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5529 vty_out (vty, "=");
718e3744 5530 else
5531 vty_out (vty, " ");
5532
5533 /* Internal route. */
b05a1c8b
DS
5534 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5535 vty_out (vty, "i");
5536 else
5537 vty_out (vty, " ");
b40d939b 5538}
5539
5540/* called from terminal list command */
5541void
5542route_vty_out (struct vty *vty, struct prefix *p,
b05a1c8b
DS
5543 struct bgp_info *binfo, int display, safi_t safi,
5544 json_object *json_paths)
b40d939b 5545{
5546 struct attr *attr;
f1aa5d8a
DS
5547 json_object *json_path = NULL;
5548 json_object *json_nexthops = NULL;
5549 json_object *json_nexthop_global = NULL;
5550 json_object *json_nexthop_ll = NULL;
47fc97cc 5551
b05a1c8b
DS
5552 if (json_paths)
5553 json_path = json_object_new_object();
b05a1c8b
DS
5554
5555 /* short status lead text */
5556 route_vty_short_status_out (vty, binfo, json_path);
718e3744 5557
b05a1c8b
DS
5558 if (!json_paths)
5559 {
5560 /* print prefix and mask */
5561 if (! display)
5562 route_vty_out_route (p, vty);
5563 else
5564 vty_out (vty, "%*s", 17, " ");
5565 }
47fc97cc 5566
718e3744 5567 /* Print attribute */
5568 attr = binfo->attr;
5569 if (attr)
5570 {
b05a1c8b
DS
5571
5572 /* IPv4 Next Hop */
8a92a8a0
DS
5573 if (p->family == AF_INET
5574 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 5575 {
b05a1c8b
DS
5576 if (json_paths)
5577 {
f1aa5d8a
DS
5578 json_nexthop_global = json_object_new_object();
5579
b05a1c8b 5580 if (safi == SAFI_MPLS_VPN)
f1aa5d8a 5581 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
b05a1c8b 5582 else
f1aa5d8a
DS
5583 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
5584
5585 json_object_string_add(json_nexthop_global, "afi", "ipv4");
5586 json_object_boolean_true_add(json_nexthop_global, "used");
b05a1c8b
DS
5587 }
5588 else
5589 {
5590 if (safi == SAFI_MPLS_VPN)
5591 vty_out (vty, "%-16s",
5592 inet_ntoa (attr->extra->mp_nexthop_global_in));
5593 else
5594 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5595 }
718e3744 5596 }
b05a1c8b
DS
5597
5598#ifdef HAVE_IPV6
5599 /* IPv6 Next Hop */
8a92a8a0 5600 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
718e3744 5601 {
5602 int len;
5603 char buf[BUFSIZ];
5604
b05a1c8b
DS
5605 if (json_paths)
5606 {
f1aa5d8a
DS
5607 json_nexthop_global = json_object_new_object();
5608 json_object_string_add(json_nexthop_global, "ip",
5609 inet_ntop (AF_INET6,
5610 &attr->extra->mp_nexthop_global,
5611 buf, BUFSIZ));
5612 json_object_string_add(json_nexthop_global, "afi", "ipv6");
5613 json_object_string_add(json_nexthop_global, "scope", "global");
5614
5615 /* We display both LL & GL if both have been received */
5616 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
5617 {
5618 json_nexthop_ll = json_object_new_object();
5619 json_object_string_add(json_nexthop_ll, "ip",
5620 inet_ntop (AF_INET6,
5621 &attr->extra->mp_nexthop_local,
5622 buf, BUFSIZ));
5623 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
5624 json_object_string_add(json_nexthop_ll, "scope", "link-local");
5625
5626 if (IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global,
5627 &attr->extra->mp_nexthop_local) != 0)
5628 json_object_boolean_true_add(json_nexthop_ll, "used");
5629 else
5630 json_object_boolean_true_add(json_nexthop_global, "used");
5631 }
5632 else
5633 json_object_boolean_true_add(json_nexthop_global, "used");
b05a1c8b
DS
5634 }
5635 else
5636 {
433e8b67
DS
5637 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
5638 {
5639 if (binfo->peer->conf_if)
5640 {
5641 len = vty_out (vty, "%s",
5642 binfo->peer->conf_if);
5643 len = 7 - len; /* len of IPv6 addr + max len of def ifname */
5644
5645 if (len < 1)
5646 vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " ");
5647 else
5648 vty_out (vty, "%*s", len, " ");
5649 }
5650 else
5651 {
5652 len = vty_out (vty, "%s",
5653 inet_ntop (AF_INET6,
5654 &attr->extra->mp_nexthop_local,
5655 buf, BUFSIZ));
5656 len = 16 - len;
5657
5658 if (len < 1)
5659 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5660 else
5661 vty_out (vty, "%*s", len, " ");
5662 }
5663 }
5664 else
5665 {
5666 len = vty_out (vty, "%s",
5667 inet_ntop (AF_INET6,
5668 &attr->extra->mp_nexthop_global,
5669 buf, BUFSIZ));
5670 len = 16 - len;
5671
5672 if (len < 1)
5673 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5674 else
5675 vty_out (vty, "%*s", len, " ");
5676 }
b05a1c8b 5677 }
718e3744 5678 }
5679#endif /* HAVE_IPV6 */
5680
b05a1c8b 5681 /* MED/Metric */
718e3744 5682 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b 5683 if (json_paths)
f1aa5d8a 5684 json_object_int_add(json_path, "med", attr->med);
b05a1c8b
DS
5685 else
5686 vty_out (vty, "%10u", attr->med);
718e3744 5687 else
b05a1c8b
DS
5688 if (!json_paths)
5689 vty_out (vty, " ");
47fc97cc 5690
b05a1c8b 5691 /* Local Pref */
718e3744 5692 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
b05a1c8b 5693 if (json_paths)
f1aa5d8a 5694 json_object_int_add(json_path, "localpref", attr->local_pref);
b05a1c8b
DS
5695 else
5696 vty_out (vty, "%7u", attr->local_pref);
718e3744 5697 else
b05a1c8b
DS
5698 if (!json_paths)
5699 vty_out (vty, " ");
718e3744 5700
b05a1c8b
DS
5701 if (json_paths)
5702 {
5703 if (attr->extra)
f1aa5d8a 5704 json_object_int_add(json_path, "weight", attr->extra->weight);
b05a1c8b 5705 else
f1aa5d8a 5706 json_object_int_add(json_path, "weight", 0);
b05a1c8b
DS
5707 }
5708 else
5709 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
47fc97cc 5710
b2518c1e
PJ
5711 /* Print aspath */
5712 if (attr->aspath)
b05a1c8b
DS
5713 {
5714 if (json_paths)
f1aa5d8a 5715 json_object_string_add(json_path, "aspath", attr->aspath->str);
b05a1c8b 5716 else
f1aa5d8a 5717 aspath_print_vty (vty, "%s", attr->aspath, " ");
b05a1c8b 5718 }
47fc97cc 5719
b2518c1e 5720 /* Print origin */
b05a1c8b 5721 if (json_paths)
f1aa5d8a 5722 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
b05a1c8b
DS
5723 else
5724 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 5725 }
856ca177
MS
5726 else
5727 {
5728 if (json_paths)
5729 json_object_string_add(json_path, "alert", "No attributes");
5730 else
5731 vty_out (vty, "No attributes to print%s", VTY_NEWLINE);
5732 }
b05a1c8b
DS
5733
5734 if (json_paths)
f1aa5d8a
DS
5735 {
5736 if (json_nexthop_global || json_nexthop_ll)
5737 {
5738 json_nexthops = json_object_new_array();
5739
5740 if (json_nexthop_global)
5741 json_object_array_add(json_nexthops, json_nexthop_global);
5742
5743 if (json_nexthop_ll)
5744 json_object_array_add(json_nexthops, json_nexthop_ll);
5745
5746 json_object_object_add(json_path, "nexthops", json_nexthops);
5747 }
5748
5749 json_object_array_add(json_paths, json_path);
5750 }
b05a1c8b
DS
5751 else
5752 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 5753}
5754
5755/* called from terminal list command */
5756void
856ca177
MS
5757route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi,
5758 u_char use_json, json_object *json_ar)
718e3744 5759{
856ca177
MS
5760 json_object *json_status = NULL;
5761 json_object *json_net = NULL;
5762 char buff[BUFSIZ];
718e3744 5763 /* Route status display. */
856ca177
MS
5764 if (use_json)
5765 {
5766 json_status = json_object_new_object();
5767 json_net = json_object_new_object();
5768 }
5769 else
5770 {
5771 vty_out (vty, "*");
5772 vty_out (vty, ">");
5773 vty_out (vty, " ");
5774 }
718e3744 5775
5776 /* print prefix and mask */
856ca177
MS
5777 if (use_json)
5778 json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ));
5779 else
5780 route_vty_out_route (p, vty);
718e3744 5781
5782 /* Print attribute */
5783 if (attr)
5784 {
856ca177 5785 if (use_json)
718e3744 5786 {
856ca177
MS
5787 if (p->family == AF_INET && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
5788 {
5789 if (safi == SAFI_MPLS_VPN)
5790 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in));
5791 else
5792 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop));
5793 }
5794#ifdef HAVE_IPV6
5795 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
5796 {
5797 char buf[BUFSIZ];
718e3744 5798
856ca177
MS
5799 json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5800 buf, BUFSIZ));
5801 }
5802#endif /* HAVE_IPV6 */
5803
5804 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5805 json_object_int_add(json_net, "metric", attr->med);
5806
5807 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5808 json_object_int_add(json_net, "localPref", attr->local_pref);
5809
5810 if (attr->extra)
5811 json_object_int_add(json_net, "weight", attr->extra->weight);
718e3744 5812 else
856ca177
MS
5813 json_object_int_add(json_net, "weight", 0);
5814
5815 /* Print aspath */
5816 if (attr->aspath)
5817 json_object_string_add(json_net, "asPath", attr->aspath->str);
5818
5819 /* Print origin */
5820 json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]);
718e3744 5821 }
856ca177
MS
5822 else
5823 {
5824 if (p->family == AF_INET && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
5825 {
5826 if (safi == SAFI_MPLS_VPN)
5827 vty_out (vty, "%-16s",
5828 inet_ntoa (attr->extra->mp_nexthop_global_in));
5829 else
5830 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5831 }
5832#ifdef HAVE_IPV6
5833 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
5834 {
5835 int len;
5836 char buf[BUFSIZ];
5837
5838 assert (attr->extra);
5839
5840 len = vty_out (vty, "%s",
5841 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5842 buf, BUFSIZ));
5843 len = 16 - len;
5844 if (len < 1)
5845 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5846 else
5847 vty_out (vty, "%*s", len, " ");
5848 }
718e3744 5849#endif /* HAVE_IPV6 */
856ca177
MS
5850 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5851 vty_out (vty, "%10u", attr->med);
5852 else
5853 vty_out (vty, " ");
718e3744 5854
856ca177
MS
5855 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5856 vty_out (vty, "%7u", attr->local_pref);
5857 else
5858 vty_out (vty, " ");
718e3744 5859
856ca177 5860 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
718e3744 5861
856ca177
MS
5862 /* Print aspath */
5863 if (attr->aspath)
5864 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 5865
856ca177
MS
5866 /* Print origin */
5867 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5868 }
5869 }
5870 if (use_json)
5871 {
5872 json_object_boolean_true_add(json_status, "*");
5873 json_object_boolean_true_add(json_status, ">");
5874 json_object_object_add(json_net, "appliedStatusSymbols", json_status);
5875 char buf_cut[BUFSIZ];
5876 json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net);
5877 }
5878 else
5879 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 5880}
5881
5a646650 5882void
718e3744 5883route_vty_out_tag (struct vty *vty, struct prefix *p,
856ca177 5884 struct bgp_info *binfo, int display, safi_t safi, json_object *json)
718e3744 5885{
856ca177 5886 json_object *json_out = NULL;
718e3744 5887 struct attr *attr;
718e3744 5888 u_int32_t label = 0;
fb982c25
PJ
5889
5890 if (!binfo->extra)
5891 return;
856ca177
MS
5892
5893 if (json)
5894 json_out = json_object_new_object();
fb982c25 5895
b40d939b 5896 /* short status lead text */
856ca177 5897 route_vty_short_status_out (vty, binfo, json_out);
b40d939b 5898
718e3744 5899 /* print prefix and mask */
856ca177
MS
5900 if (json == NULL)
5901 {
5902 if (! display)
5903 route_vty_out_route (p, vty);
5904 else
5905 vty_out (vty, "%*s", 17, " ");
5906 }
718e3744 5907
5908 /* Print attribute */
5909 attr = binfo->attr;
5910 if (attr)
5911 {
8a92a8a0
DS
5912 if (p->family == AF_INET
5913 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 5914 {
5915 if (safi == SAFI_MPLS_VPN)
856ca177
MS
5916 {
5917 if (json)
5918 json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in));
5919 else
5920 vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in));
5921 }
718e3744 5922 else
856ca177
MS
5923 {
5924 if (json)
5925 json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop));
5926 else
5927 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5928 }
718e3744 5929 }
5930#ifdef HAVE_IPV6
8a92a8a0 5931 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
718e3744 5932 {
fb982c25 5933 assert (attr->extra);
856ca177
MS
5934 char buf_a[BUFSIZ];
5935 char buf_b[BUFSIZ];
5936 char buf_c[BUFSIZ];
801a9bcc 5937 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
856ca177
MS
5938 {
5939 if (json)
5940 json_object_string_add(json_out, "mpNexthopGlobalIn",
5941 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ));
5942 else
5943 vty_out (vty, "%s",
5944 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5945 buf_a, BUFSIZ));
5946 }
801a9bcc 5947 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
856ca177
MS
5948 {
5949 if (json)
5950 {
5951 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5952 buf_a, BUFSIZ);
5953 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5954 buf_b, BUFSIZ);
5955 sprintf(buf_c, "%s(%s)", buf_a, buf_b);
5956 json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c);
5957 }
5958 else
5959 vty_out (vty, "%s(%s)",
5960 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5961 buf_a, BUFSIZ),
5962 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5963 buf_b, BUFSIZ));
5964 }
5965
718e3744 5966 }
5967#endif /* HAVE_IPV6 */
5968 }
5969
fb982c25 5970 label = decode_label (binfo->extra->tag);
718e3744 5971
856ca177
MS
5972 if (json)
5973 {
5974 if (label)
5975 json_object_int_add(json_out, "notag", label);
5976 json_object_array_add(json, json_out);
5977 }
5978 else
5979 {
5980 vty_out (vty, "notag/%d", label);
5981 vty_out (vty, "%s", VTY_NEWLINE);
5982 }
718e3744 5983}
5984
5985/* dampening route */
5a646650 5986static void
856ca177
MS
5987damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
5988 int display, safi_t safi, u_char use_json, json_object *json)
718e3744 5989{
5990 struct attr *attr;
718e3744 5991 int len;
50aef6f3 5992 char timebuf[BGP_UPTIME_LEN];
718e3744 5993
b40d939b 5994 /* short status lead text */
856ca177 5995 route_vty_short_status_out (vty, binfo, json);
b40d939b 5996
718e3744 5997 /* print prefix and mask */
856ca177
MS
5998 if (!use_json)
5999 {
6000 if (! display)
6001 route_vty_out_route (p, vty);
6002 else
6003 vty_out (vty, "%*s", 17, " ");
6004 }
718e3744 6005
6006 len = vty_out (vty, "%s", binfo->peer->host);
6007 len = 17 - len;
6008 if (len < 1)
856ca177
MS
6009 {
6010 if (!use_json)
6011 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6012 }
718e3744 6013 else
856ca177
MS
6014 {
6015 if (use_json)
6016 json_object_int_add(json, "peerHost", len);
6017 else
6018 vty_out (vty, "%*s", len, " ");
6019 }
718e3744 6020
856ca177
MS
6021 if (use_json)
6022 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6023 else
6024 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
718e3744 6025
6026 /* Print attribute */
6027 attr = binfo->attr;
6028 if (attr)
6029 {
6030 /* Print aspath */
6031 if (attr->aspath)
856ca177
MS
6032 {
6033 if (use_json)
6034 json_object_string_add(json, "asPath", attr->aspath->str);
6035 else
6036 aspath_print_vty (vty, "%s", attr->aspath, " ");
6037 }
718e3744 6038
6039 /* Print origin */
856ca177
MS
6040 if (use_json)
6041 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6042 else
6043 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 6044 }
856ca177
MS
6045 if (!use_json)
6046 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6047}
6048
718e3744 6049/* flap route */
5a646650 6050static void
856ca177
MS
6051flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6052 int display, safi_t safi, u_char use_json, json_object *json)
718e3744 6053{
6054 struct attr *attr;
6055 struct bgp_damp_info *bdi;
718e3744 6056 char timebuf[BGP_UPTIME_LEN];
6057 int len;
fb982c25
PJ
6058
6059 if (!binfo->extra)
6060 return;
6061
6062 bdi = binfo->extra->damp_info;
718e3744 6063
b40d939b 6064 /* short status lead text */
856ca177 6065 route_vty_short_status_out (vty, binfo, json);
b40d939b 6066
718e3744 6067 /* print prefix and mask */
856ca177
MS
6068 if (!use_json)
6069 {
6070 if (! display)
6071 route_vty_out_route (p, vty);
6072 else
6073 vty_out (vty, "%*s", 17, " ");
6074 }
718e3744 6075
6076 len = vty_out (vty, "%s", binfo->peer->host);
6077 len = 16 - len;
6078 if (len < 1)
856ca177
MS
6079 {
6080 if (!use_json)
6081 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6082 }
718e3744 6083 else
856ca177
MS
6084 {
6085 if (use_json)
6086 json_object_int_add(json, "peerHost", len);
6087 else
6088 vty_out (vty, "%*s", len, " ");
6089 }
718e3744 6090
6091 len = vty_out (vty, "%d", bdi->flap);
6092 len = 5 - len;
6093 if (len < 1)
856ca177
MS
6094 {
6095 if (!use_json)
6096 vty_out (vty, " ");
6097 }
718e3744 6098 else
856ca177
MS
6099 {
6100 if (use_json)
6101 json_object_int_add(json, "bdiFlap", len);
6102 else
6103 vty_out (vty, "%*s", len, " ");
6104 }
6105
6106 if (use_json)
6107 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json);
6108 else
6109 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6110 timebuf, BGP_UPTIME_LEN, 0, NULL));
718e3744 6111
6112 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6113 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
856ca177
MS
6114 {
6115 if (use_json)
6116 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6117 else
6118 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6119 }
718e3744 6120 else
856ca177
MS
6121 {
6122 if (!use_json)
6123 vty_out (vty, "%*s ", 8, " ");
6124 }
718e3744 6125
6126 /* Print attribute */
6127 attr = binfo->attr;
6128 if (attr)
6129 {
6130 /* Print aspath */
6131 if (attr->aspath)
856ca177
MS
6132 {
6133 if (use_json)
6134 json_object_string_add(json, "asPath", attr->aspath->str);
6135 else
6136 aspath_print_vty (vty, "%s", attr->aspath, " ");
6137 }
718e3744 6138
6139 /* Print origin */
856ca177
MS
6140 if (use_json)
6141 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6142 else
6143 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 6144 }
856ca177
MS
6145 if (!use_json)
6146 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6147}
6148
adbac85e
DW
6149static void
6150route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first,
6151 const char *header, json_object *json_adv_to)
6152{
6153 char buf1[INET6_ADDRSTRLEN];
6154 json_object *json_peer = NULL;
6155
6156 if (json_adv_to)
6157 {
6158 /* 'advertised-to' is a dictionary of peers we have advertised this
6159 * prefix too. The key is the peer's IP or swpX, the value is the
6160 * hostname if we know it and "" if not.
6161 */
6162 json_peer = json_object_new_object();
6163
6164 if (peer->hostname)
6165 json_object_string_add(json_peer, "hostname", peer->hostname);
6166
6167 if (peer->conf_if)
6168 json_object_object_add(json_adv_to, peer->conf_if, json_peer);
6169 else
6170 json_object_object_add(json_adv_to,
6171 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN),
6172 json_peer);
6173 }
6174 else
6175 {
6176 if (*first)
6177 {
6178 vty_out (vty, "%s", header);
6179 *first = 0;
6180 }
6181
6182 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6183 {
6184 if (peer->conf_if)
6185 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
6186 else
6187 vty_out (vty, " %s(%s)", peer->hostname,
6188 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6189 }
6190 else
6191 {
6192 if (peer->conf_if)
6193 vty_out (vty, " %s", peer->conf_if);
6194 else
6195 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6196 }
6197 }
6198}
6199
94f2b392 6200static void
718e3744 6201route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
b05a1c8b
DS
6202 struct bgp_info *binfo, afi_t afi, safi_t safi,
6203 json_object *json_paths)
718e3744 6204{
6205 char buf[INET6_ADDRSTRLEN];
6206 char buf1[BUFSIZ];
6207 struct attr *attr;
6208 int sockunion_vty_out (struct vty *, union sockunion *);
30b00176
JK
6209#ifdef HAVE_CLOCK_MONOTONIC
6210 time_t tbuf;
6211#endif
f1aa5d8a 6212 json_object *json_bestpath = NULL;
ffd0c037 6213 json_object *json_cluster_list = NULL;
f1aa5d8a
DS
6214 json_object *json_cluster_list_list = NULL;
6215 json_object *json_ext_community = NULL;
6216 json_object *json_last_update = NULL;
6217 json_object *json_nexthop_global = NULL;
6218 json_object *json_nexthop_ll = NULL;
6219 json_object *json_nexthops = NULL;
6220 json_object *json_path = NULL;
6221 json_object *json_peer = NULL;
6222 json_object *json_string = NULL;
adbac85e
DW
6223 json_object *json_adv_to = NULL;
6224 int first = 0;
6225 struct listnode *node, *nnode;
6226 struct peer *peer;
6227 int addpath_capable;
6228 int has_adj;
06370dac 6229 int first_as;
b05a1c8b
DS
6230
6231 if (json_paths)
6232 {
6233 json_path = json_object_new_object();
f1aa5d8a
DS
6234 json_peer = json_object_new_object();
6235 json_nexthop_global = json_object_new_object();
b05a1c8b
DS
6236 }
6237
718e3744 6238 attr = binfo->attr;
6239
6240 if (attr)
6241 {
6242 /* Line1 display AS-path, Aggregator */
6243 if (attr->aspath)
6244 {
f1aa5d8a
DS
6245 if (json_paths)
6246 {
6247 json_object_lock(attr->aspath->json);
6248 json_object_object_add(json_path, "aspath", attr->aspath->json);
6249 }
6250 else
b05a1c8b 6251 {
f1aa5d8a
DS
6252 if (attr->aspath->segments)
6253 aspath_print_vty (vty, " %s", attr->aspath, "");
b05a1c8b 6254 else
f1aa5d8a 6255 vty_out (vty, " Local");
b05a1c8b 6256 }
718e3744 6257 }
6258
b40d939b 6259 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
b05a1c8b
DS
6260 {
6261 if (json_paths)
f1aa5d8a 6262 json_object_boolean_true_add(json_path, "removed");
b05a1c8b
DS
6263 else
6264 vty_out (vty, ", (removed)");
6265 }
6266
93406d87 6267 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
b05a1c8b
DS
6268 {
6269 if (json_paths)
f1aa5d8a 6270 json_object_boolean_true_add(json_path, "stale");
b05a1c8b
DS
6271 else
6272 vty_out (vty, ", (stale)");
6273 }
6274
93406d87 6275 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
b05a1c8b
DS
6276 {
6277 if (json_paths)
6278 {
62d6dca0
DS
6279 json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as);
6280 json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr));
b05a1c8b
DS
6281 }
6282 else
6283 {
6284 vty_out (vty, ", (aggregated by %u %s)",
6285 attr->extra->aggregator_as,
6286 inet_ntoa (attr->extra->aggregator_addr));
6287 }
6288 }
6289
93406d87 6290 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
b05a1c8b
DS
6291 {
6292 if (json_paths)
62d6dca0 6293 json_object_boolean_true_add(json_path, "rxedFromRrClient");
b05a1c8b
DS
6294 else
6295 vty_out (vty, ", (Received from a RR-client)");
6296 }
6297
93406d87 6298 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
b05a1c8b
DS
6299 {
6300 if (json_paths)
62d6dca0 6301 json_object_boolean_true_add(json_path, "rxedFromRsClient");
b05a1c8b
DS
6302 else
6303 vty_out (vty, ", (Received from a RS-client)");
6304 }
6305
93406d87 6306 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
6307 {
6308 if (json_paths)
62d6dca0 6309 json_object_boolean_true_add(json_path, "dampeningHistoryEntry");
b05a1c8b
DS
6310 else
6311 vty_out (vty, ", (history entry)");
6312 }
93406d87 6313 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
b05a1c8b
DS
6314 {
6315 if (json_paths)
62d6dca0 6316 json_object_boolean_true_add(json_path, "dampeningSuppressed");
b05a1c8b
DS
6317 else
6318 vty_out (vty, ", (suppressed due to dampening)");
6319 }
6320
6321 if (!json_paths)
6322 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6323
6324 /* Line2 display Next-hop, Neighbor, Router-id */
f1aa5d8a 6325 /* Display the nexthop */
8a92a8a0
DS
6326 if (p->family == AF_INET
6327 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 6328 {
b05a1c8b
DS
6329 if (safi == SAFI_MPLS_VPN)
6330 {
6331 if (json_paths)
f1aa5d8a 6332 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
b05a1c8b
DS
6333 else
6334 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6335 }
6336 else
6337 {
6338 if (json_paths)
f1aa5d8a 6339 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
b05a1c8b
DS
6340 else
6341 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
6342 }
6343
6344 if (json_paths)
f1aa5d8a 6345 json_object_string_add(json_nexthop_global, "afi", "ipv4");
718e3744 6346 }
6347#ifdef HAVE_IPV6
6348 else
6349 {
fb982c25 6350 assert (attr->extra);
b05a1c8b
DS
6351 if (json_paths)
6352 {
f1aa5d8a
DS
6353 json_object_string_add(json_nexthop_global, "ip",
6354 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6355 buf, INET6_ADDRSTRLEN));
6356 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6357 json_object_string_add(json_nexthop_global, "scope", "global");
b05a1c8b
DS
6358 }
6359 else
6360 {
6361 vty_out (vty, " %s",
6362 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6363 buf, INET6_ADDRSTRLEN));
6364 }
718e3744 6365 }
6366#endif /* HAVE_IPV6 */
6367
b05a1c8b 6368
f1aa5d8a
DS
6369 /* Display the IGP cost or 'inaccessible' */
6370 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6371 {
6372 if (json_paths)
6373 json_object_boolean_false_add(json_nexthop_global, "accessible");
6374 else
6375 vty_out (vty, " (inaccessible)");
6376 }
6377 else
6378 {
6379 if (binfo->extra && binfo->extra->igpmetric)
b05a1c8b
DS
6380 {
6381 if (json_paths)
f1aa5d8a 6382 json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric);
b05a1c8b 6383 else
f1aa5d8a 6384 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
b05a1c8b 6385 }
f1aa5d8a
DS
6386
6387 /* IGP cost is 0, display this only for json */
b05a1c8b
DS
6388 else
6389 {
6390 if (json_paths)
f1aa5d8a 6391 json_object_int_add(json_nexthop_global, "metric", 0);
b05a1c8b
DS
6392 }
6393
6394 if (json_paths)
f1aa5d8a
DS
6395 json_object_boolean_true_add(json_nexthop_global, "accessible");
6396 }
6397
6398 /* Display peer "from" output */
6399 /* This path was originated locally */
6400 if (binfo->peer == bgp->peer_self)
718e3744 6401 {
f1aa5d8a
DS
6402
6403 if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
b05a1c8b
DS
6404 {
6405 if (json_paths)
62d6dca0 6406 json_object_string_add(json_peer, "peerId", "0.0.0.0");
b05a1c8b 6407 else
f1aa5d8a 6408 vty_out (vty, " from 0.0.0.0 ");
b05a1c8b 6409 }
f1aa5d8a 6410 else
b05a1c8b
DS
6411 {
6412 if (json_paths)
62d6dca0 6413 json_object_string_add(json_peer, "peerId", "::");
b05a1c8b 6414 else
f1aa5d8a 6415 vty_out (vty, " from :: ");
b05a1c8b
DS
6416 }
6417
f1aa5d8a 6418 if (json_paths)
62d6dca0 6419 json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id));
b05a1c8b 6420 else
f1aa5d8a
DS
6421 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6422 }
6423
6424 /* We RXed this path from one of our peers */
6425 else
6426 {
b05a1c8b
DS
6427
6428 if (json_paths)
6429 {
62d6dca0
DS
6430 json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6431 json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
f1aa5d8a 6432
04b6bdc0
DW
6433 if (binfo->peer->hostname)
6434 json_object_string_add(json_peer, "hostname", binfo->peer->hostname);
6435
6436 if (binfo->peer->domainname)
6437 json_object_string_add(json_peer, "domainname", binfo->peer->domainname);
6438
036a4e7d 6439 if (binfo->peer->conf_if)
f1aa5d8a 6440 json_object_string_add(json_peer, "interface", binfo->peer->conf_if);
b05a1c8b
DS
6441 }
6442 else
6443 {
036a4e7d 6444 if (binfo->peer->conf_if)
04b6bdc0
DW
6445 {
6446 if (binfo->peer->hostname &&
6447 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6448 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
6449 binfo->peer->conf_if);
6450 else
6451 vty_out (vty, " from %s", binfo->peer->conf_if);
6452 }
036a4e7d 6453 else
04b6bdc0
DW
6454 {
6455 if (binfo->peer->hostname &&
6456 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6457 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
6458 binfo->peer->host);
6459 else
6460 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6461 }
b05a1c8b 6462
f1aa5d8a
DS
6463 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6464 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
6465 else
6466 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
b05a1c8b 6467 }
718e3744 6468 }
b05a1c8b
DS
6469
6470 if (!json_paths)
6471 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6472
6473#ifdef HAVE_IPV6
f1aa5d8a 6474 /* display the link-local nexthop */
801a9bcc 6475 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
718e3744 6476 {
b05a1c8b
DS
6477 if (json_paths)
6478 {
f1aa5d8a
DS
6479 json_nexthop_ll = json_object_new_object();
6480 json_object_string_add(json_nexthop_ll, "ip",
6481 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6482 buf, INET6_ADDRSTRLEN));
6483 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
6484 json_object_string_add(json_nexthop_ll, "scope", "link-local");
6485
6486 json_object_boolean_true_add(json_nexthop_ll, "accessible");
6487 json_object_boolean_true_add(json_nexthop_ll, "used");
b05a1c8b
DS
6488 }
6489 else
6490 {
356b3294 6491 vty_out (vty, " (%s) (used)%s",
b05a1c8b
DS
6492 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6493 buf, INET6_ADDRSTRLEN),
6494 VTY_NEWLINE);
6495 }
718e3744 6496 }
f1aa5d8a
DS
6497 /* If we do not have a link-local nexthop then we must flag the global as "used" */
6498 else
6499 {
6500 if (json_paths)
6501 json_object_boolean_true_add(json_nexthop_global, "used");
6502 }
718e3744 6503#endif /* HAVE_IPV6 */
6504
0d9551dc 6505 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
b05a1c8b 6506 if (json_paths)
f1aa5d8a 6507 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
b05a1c8b 6508 else
f1aa5d8a 6509 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
718e3744 6510
6511 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b
DS
6512 {
6513 if (json_paths)
f1aa5d8a 6514 json_object_int_add(json_path, "med", attr->med);
b05a1c8b 6515 else
f1aa5d8a 6516 vty_out (vty, ", metric %u", attr->med);
b05a1c8b 6517 }
718e3744 6518
6519 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
b05a1c8b
DS
6520 {
6521 if (json_paths)
f1aa5d8a 6522 json_object_int_add(json_path, "localpref", attr->local_pref);
b05a1c8b 6523 else
f1aa5d8a 6524 vty_out (vty, ", localpref %u", attr->local_pref);
b05a1c8b 6525 }
718e3744 6526 else
b05a1c8b
DS
6527 {
6528 if (json_paths)
f1aa5d8a 6529 json_object_int_add(json_path, "localpref", bgp->default_local_pref);
b05a1c8b 6530 else
f1aa5d8a 6531 vty_out (vty, ", localpref %u", bgp->default_local_pref);
b05a1c8b 6532 }
718e3744 6533
fb982c25 6534 if (attr->extra && attr->extra->weight != 0)
b05a1c8b
DS
6535 {
6536 if (json_paths)
f1aa5d8a 6537 json_object_int_add(json_path, "weight", attr->extra->weight);
b05a1c8b 6538 else
f1aa5d8a 6539 vty_out (vty, ", weight %u", attr->extra->weight);
b05a1c8b 6540 }
0d9551dc
DS
6541
6542 if (attr->extra && attr->extra->tag != 0)
b05a1c8b
DS
6543 {
6544 if (json_paths)
f1aa5d8a 6545 json_object_int_add(json_path, "tag", attr->extra->tag);
b05a1c8b 6546 else
f1aa5d8a 6547 vty_out (vty, ", tag %d", attr->extra->tag);
b05a1c8b 6548 }
718e3744 6549
31eba040 6550 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
b05a1c8b
DS
6551 {
6552 if (json_paths)
f1aa5d8a 6553 json_object_boolean_false_add(json_path, "valid");
b05a1c8b
DS
6554 else
6555 vty_out (vty, ", invalid");
6556 }
31eba040 6557 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
6558 {
6559 if (json_paths)
f1aa5d8a 6560 json_object_boolean_true_add(json_path, "valid");
b05a1c8b
DS
6561 else
6562 vty_out (vty, ", valid");
6563 }
718e3744 6564
6565 if (binfo->peer != bgp->peer_self)
6566 {
f1aa5d8a 6567 if (binfo->peer->as == binfo->peer->local_as)
b05a1c8b 6568 {
66b199b2
DS
6569 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
6570 {
6571 if (json_paths)
f1aa5d8a 6572 json_object_string_add(json_peer, "type", "confed-internal");
66b199b2 6573 else
f1aa5d8a 6574 vty_out (vty, ", confed-internal");
66b199b2 6575 }
b05a1c8b 6576 else
66b199b2
DS
6577 {
6578 if (json_paths)
f1aa5d8a 6579 json_object_string_add(json_peer, "type", "internal");
66b199b2 6580 else
f1aa5d8a 6581 vty_out (vty, ", internal");
66b199b2 6582 }
b05a1c8b 6583 }
f1aa5d8a 6584 else
b05a1c8b
DS
6585 {
6586 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
6587 {
6588 if (json_paths)
f1aa5d8a 6589 json_object_string_add(json_peer, "type", "confed-external");
b05a1c8b 6590 else
f1aa5d8a 6591 vty_out (vty, ", confed-external");
b05a1c8b
DS
6592 }
6593 else
6594 {
6595 if (json_paths)
f1aa5d8a 6596 json_object_string_add(json_peer, "type", "external");
b05a1c8b 6597 else
f1aa5d8a 6598 vty_out (vty, ", external");
b05a1c8b
DS
6599 }
6600 }
718e3744 6601 }
6602 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
b05a1c8b
DS
6603 {
6604 if (json_paths)
6605 {
f1aa5d8a
DS
6606 json_object_boolean_true_add(json_path, "aggregated");
6607 json_object_boolean_true_add(json_path, "local");
b05a1c8b
DS
6608 }
6609 else
6610 {
6611 vty_out (vty, ", aggregated, local");
6612 }
6613 }
718e3744 6614 else if (binfo->type != ZEBRA_ROUTE_BGP)
b05a1c8b
DS
6615 {
6616 if (json_paths)
f1aa5d8a 6617 json_object_boolean_true_add(json_path, "sourced");
b05a1c8b
DS
6618 else
6619 vty_out (vty, ", sourced");
6620 }
718e3744 6621 else
b05a1c8b
DS
6622 {
6623 if (json_paths)
6624 {
f1aa5d8a
DS
6625 json_object_boolean_true_add(json_path, "sourced");
6626 json_object_boolean_true_add(json_path, "local");
b05a1c8b
DS
6627 }
6628 else
6629 {
6630 vty_out (vty, ", sourced, local");
6631 }
6632 }
718e3744 6633
6634 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
b05a1c8b
DS
6635 {
6636 if (json_paths)
62d6dca0 6637 json_object_boolean_true_add(json_path, "atomicAggregate");
b05a1c8b
DS
6638 else
6639 vty_out (vty, ", atomic-aggregate");
6640 }
718e3744 6641
de8d5dff
JB
6642 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6643 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6644 bgp_info_mpath_count (binfo)))
b05a1c8b
DS
6645 {
6646 if (json_paths)
f1aa5d8a 6647 json_object_boolean_true_add(json_path, "multipath");
b05a1c8b
DS
6648 else
6649 vty_out (vty, ", multipath");
6650 }
de8d5dff 6651
06370dac
DW
6652 // Mark the bestpath(s)
6653 if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED))
6654 {
6655 first_as = aspath_get_firstas(attr->aspath);
6656
6657 if (json_paths)
6658 {
6659 if (!json_bestpath)
6660 json_bestpath = json_object_new_object();
6661 json_object_int_add(json_bestpath, "bestpathFromAs", first_as);
6662 }
6663 else
6664 {
6665 if (first_as)
6666 vty_out (vty, ", bestpath-from-AS %d", first_as);
6667 else
6668 vty_out (vty, ", bestpath-from-AS Local");
6669 }
6670 }
6671
718e3744 6672 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
b05a1c8b
DS
6673 {
6674 if (json_paths)
f1aa5d8a 6675 {
06370dac
DW
6676 if (!json_bestpath)
6677 json_bestpath = json_object_new_object();
f1aa5d8a 6678 json_object_boolean_true_add(json_bestpath, "overall");
f1aa5d8a 6679 }
b05a1c8b
DS
6680 else
6681 vty_out (vty, ", best");
6682 }
718e3744 6683
06370dac
DW
6684 if (json_bestpath)
6685 json_object_object_add(json_path, "bestpath", json_bestpath);
6686
b05a1c8b
DS
6687 if (!json_paths)
6688 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6689
6690 /* Line 4 display Community */
6691 if (attr->community)
b05a1c8b
DS
6692 {
6693 if (json_paths)
6694 {
f1aa5d8a
DS
6695 json_object_lock(attr->community->json);
6696 json_object_object_add(json_path, "community", attr->community->json);
b05a1c8b
DS
6697 }
6698 else
6699 {
6700 vty_out (vty, " Community: %s%s", attr->community->str,
6701 VTY_NEWLINE);
6702 }
6703 }
718e3744 6704
6705 /* Line 5 display Extended-community */
6706 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
b05a1c8b
DS
6707 {
6708 if (json_paths)
6709 {
f1aa5d8a
DS
6710 json_ext_community = json_object_new_object();
6711 json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str);
62d6dca0 6712 json_object_object_add(json_path, "extendedCommunity", json_ext_community);
b05a1c8b
DS
6713 }
6714 else
6715 {
6716 vty_out (vty, " Extended Community: %s%s",
6717 attr->extra->ecommunity->str, VTY_NEWLINE);
6718 }
6719 }
6720
718e3744 6721 /* Line 6 display Originator, Cluster-id */
6722 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6723 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6724 {
fb982c25 6725 assert (attr->extra);
718e3744 6726 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
b05a1c8b
DS
6727 {
6728 if (json_paths)
62d6dca0 6729 json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id));
b05a1c8b 6730 else
f1aa5d8a
DS
6731 vty_out (vty, " Originator: %s",
6732 inet_ntoa (attr->extra->originator_id));
b05a1c8b 6733 }
718e3744 6734
6735 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6736 {
6737 int i;
b05a1c8b
DS
6738
6739 if (json_paths)
6740 {
f1aa5d8a
DS
6741 json_cluster_list = json_object_new_object();
6742 json_cluster_list_list = json_object_new_array();
6743
b05a1c8b
DS
6744 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6745 {
6746 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
f1aa5d8a 6747 json_object_array_add(json_cluster_list_list, json_string);
b05a1c8b 6748 }
f1aa5d8a
DS
6749
6750 /* struct cluster_list does not have "str" variable like
6751 * aspath and community do. Add this someday if someone
6752 * asks for it.
6753 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
6754 */
6755 json_object_object_add(json_cluster_list, "list", json_cluster_list_list);
62d6dca0 6756 json_object_object_add(json_path, "clusterList", json_cluster_list);
b05a1c8b
DS
6757 }
6758 else
6759 {
6760 vty_out (vty, ", Cluster list: ");
6761
6762 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6763 {
6764 vty_out (vty, "%s ",
6765 inet_ntoa (attr->extra->cluster->list[i]));
6766 }
6767 }
718e3744 6768 }
b05a1c8b
DS
6769
6770 if (!json_paths)
6771 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6772 }
b05a1c8b 6773
fb982c25 6774 if (binfo->extra && binfo->extra->damp_info)
b05a1c8b 6775 bgp_damp_info_vty (vty, binfo, json_path);
718e3744 6776
a82478b9
DS
6777 /* Line 7 display Addpath IDs */
6778 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
b05a1c8b
DS
6779 {
6780 if (json_paths)
6781 {
62d6dca0
DS
6782 json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id);
6783 json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id);
b05a1c8b
DS
6784 }
6785 else
6786 {
6787 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
6788 binfo->addpath_rx_id, binfo->addpath_tx_id,
6789 VTY_NEWLINE);
6790 }
6791 }
a82478b9 6792
adbac85e
DW
6793 /* If we used addpath to TX a non-bestpath we need to display
6794 * "Advertised to" on a path-by-path basis */
6795 if (bgp->addpath_tx_used[afi][safi])
6796 {
6797 first = 1;
6798
6799 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6800 {
6801 addpath_capable = bgp_addpath_encode_tx (peer, afi, safi);
6802 has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id);
6803
6804 if ((addpath_capable && has_adj) ||
6805 (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)))
6806 {
6807 if (json_path && !json_adv_to)
6808 json_adv_to = json_object_new_object();
6809
6810 route_vty_out_advertised_to(vty, peer, &first,
6811 " Advertised to:",
6812 json_adv_to);
6813 }
6814 }
6815
6816 if (json_path)
6817 {
6818 if (json_adv_to)
6819 {
6820 json_object_object_add(json_path, "advertisedTo", json_adv_to);
6821 }
6822 }
6823 else
6824 {
6825 if (!first)
6826 {
6827 vty_out (vty, "%s", VTY_NEWLINE);
6828 }
6829 }
6830 }
6831
a82478b9 6832 /* Line 8 display Uptime */
30b00176
JK
6833#ifdef HAVE_CLOCK_MONOTONIC
6834 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
b05a1c8b 6835 if (json_paths)
f1aa5d8a
DS
6836 {
6837 json_last_update = json_object_new_object();
6838 json_object_int_add(json_last_update, "epoch", tbuf);
6839 json_object_string_add(json_last_update, "string", ctime(&tbuf));
62d6dca0 6840 json_object_object_add(json_path, "lastUpdate", json_last_update);
f1aa5d8a 6841 }
b05a1c8b
DS
6842 else
6843 vty_out (vty, " Last update: %s", ctime(&tbuf));
30b00176 6844#else
b05a1c8b 6845 if (json_paths)
f1aa5d8a
DS
6846 {
6847 json_last_update = json_object_new_object();
6848 json_object_int_add(json_last_update, "epoch", tbuf);
6849 json_object_string_add(json_last_update, "string", ctime(&binfo->uptime));
62d6dca0 6850 json_object_object_add(json_path, "lastUpdate", json_last_update);
f1aa5d8a 6851 }
b05a1c8b
DS
6852 else
6853 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
30b00176 6854#endif /* HAVE_CLOCK_MONOTONIC */
718e3744 6855 }
b05a1c8b
DS
6856
6857 /* We've constructed the json object for this path, add it to the json
6858 * array of paths
6859 */
6860 if (json_paths)
f1aa5d8a
DS
6861 {
6862 if (json_nexthop_global || json_nexthop_ll)
6863 {
6864 json_nexthops = json_object_new_array();
6865
6866 if (json_nexthop_global)
6867 json_object_array_add(json_nexthops, json_nexthop_global);
6868
6869 if (json_nexthop_ll)
6870 json_object_array_add(json_nexthops, json_nexthop_ll);
6871
6872 json_object_object_add(json_path, "nexthops", json_nexthops);
6873 }
6874
6875 json_object_object_add(json_path, "peer", json_peer);
6876 json_object_array_add(json_paths, json_path);
6877 }
b05a1c8b
DS
6878 else
6879 vty_out (vty, "%s", VTY_NEWLINE);
b366b518
BB
6880}
6881
47fc97cc 6882#define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
718e3744 6883#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6884#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6885
6886enum bgp_show_type
6887{
6888 bgp_show_type_normal,
6889 bgp_show_type_regexp,
6890 bgp_show_type_prefix_list,
6891 bgp_show_type_filter_list,
6892 bgp_show_type_route_map,
6893 bgp_show_type_neighbor,
6894 bgp_show_type_cidr_only,
6895 bgp_show_type_prefix_longer,
6896 bgp_show_type_community_all,
6897 bgp_show_type_community,
6898 bgp_show_type_community_exact,
6899 bgp_show_type_community_list,
6900 bgp_show_type_community_list_exact,
6901 bgp_show_type_flap_statistics,
6902 bgp_show_type_flap_address,
6903 bgp_show_type_flap_prefix,
6904 bgp_show_type_flap_cidr_only,
6905 bgp_show_type_flap_regexp,
6906 bgp_show_type_flap_filter_list,
6907 bgp_show_type_flap_prefix_list,
6908 bgp_show_type_flap_prefix_longer,
6909 bgp_show_type_flap_route_map,
6910 bgp_show_type_flap_neighbor,
6911 bgp_show_type_dampend_paths,
6912 bgp_show_type_damp_neighbor
6913};
6914
5a646650 6915static int
fee0f4c6 6916bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
856ca177 6917 enum bgp_show_type type, void *output_arg, u_char use_json)
718e3744 6918{
718e3744 6919 struct bgp_info *ri;
6920 struct bgp_node *rn;
718e3744 6921 int header = 1;
718e3744 6922 int display;
5a646650 6923 unsigned long output_count;
b05a1c8b
DS
6924 struct prefix *p;
6925 char buf[BUFSIZ];
6926 char buf2[BUFSIZ];
f1aa5d8a
DS
6927 json_object *json = NULL;
6928 json_object *json_paths = NULL;
6929 json_object *json_routes = NULL;
b05a1c8b
DS
6930
6931 if (use_json)
6932 {
6933 json = json_object_new_object();
62d6dca0
DS
6934 json_object_int_add(json, "tableVersion", table->version);
6935 json_object_string_add(json, "routerId", inet_ntoa (*router_id));
b05a1c8b
DS
6936 json_routes = json_object_new_object();
6937 }
718e3744 6938
6939 /* This is first entry point, so reset total line. */
5a646650 6940 output_count = 0;
718e3744 6941
718e3744 6942 /* Start processing of routes. */
6943 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6944 if (rn->info != NULL)
6945 {
856ca177 6946 display = 0;
718e3744 6947
b05a1c8b
DS
6948 if (use_json)
6949 json_paths = json_object_new_array();
6950 else
6951 json_paths = NULL;
6952
856ca177
MS
6953 for (ri = rn->info; ri; ri = ri->next)
6954 {
6955 if (type == bgp_show_type_flap_statistics
6956 || type == bgp_show_type_flap_address
6957 || type == bgp_show_type_flap_prefix
6958 || type == bgp_show_type_flap_cidr_only
6959 || type == bgp_show_type_flap_regexp
6960 || type == bgp_show_type_flap_filter_list
6961 || type == bgp_show_type_flap_prefix_list
6962 || type == bgp_show_type_flap_prefix_longer
6963 || type == bgp_show_type_flap_route_map
6964 || type == bgp_show_type_flap_neighbor
6965 || type == bgp_show_type_dampend_paths
6966 || type == bgp_show_type_damp_neighbor)
6967 {
6968 if (!(ri->extra && ri->extra->damp_info))
6969 continue;
6970 }
6971 if (type == bgp_show_type_regexp
6972 || type == bgp_show_type_flap_regexp)
6973 {
6974 regex_t *regex = output_arg;
718e3744 6975
856ca177
MS
6976 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6977 continue;
6978 }
6979 if (type == bgp_show_type_prefix_list
6980 || type == bgp_show_type_flap_prefix_list)
6981 {
6982 struct prefix_list *plist = output_arg;
718e3744 6983
856ca177
MS
6984 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6985 continue;
6986 }
6987 if (type == bgp_show_type_filter_list
6988 || type == bgp_show_type_flap_filter_list)
6989 {
6990 struct as_list *as_list = output_arg;
558d1fec 6991
856ca177
MS
6992 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6993 continue;
6994 }
6995 if (type == bgp_show_type_route_map
6996 || type == bgp_show_type_flap_route_map)
6997 {
6998 struct route_map *rmap = output_arg;
6999 struct bgp_info binfo;
7000 struct attr dummy_attr;
7001 struct attr_extra dummy_extra;
7002 int ret;
718e3744 7003
856ca177
MS
7004 dummy_attr.extra = &dummy_extra;
7005 bgp_attr_dup (&dummy_attr, ri->attr);
718e3744 7006
856ca177
MS
7007 binfo.peer = ri->peer;
7008 binfo.attr = &dummy_attr;
718e3744 7009
856ca177
MS
7010 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
7011 if (ret == RMAP_DENYMATCH)
7012 continue;
7013 }
7014 if (type == bgp_show_type_neighbor
7015 || type == bgp_show_type_flap_neighbor
7016 || type == bgp_show_type_damp_neighbor)
7017 {
7018 union sockunion *su = output_arg;
718e3744 7019
856ca177
MS
7020 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7021 continue;
7022 }
7023 if (type == bgp_show_type_cidr_only
7024 || type == bgp_show_type_flap_cidr_only)
7025 {
7026 u_int32_t destination;
718e3744 7027
856ca177
MS
7028 destination = ntohl (rn->p.u.prefix4.s_addr);
7029 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7030 continue;
7031 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7032 continue;
7033 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7034 continue;
7035 }
7036 if (type == bgp_show_type_prefix_longer
7037 || type == bgp_show_type_flap_prefix_longer)
7038 {
7039 struct prefix *p = output_arg;
718e3744 7040
856ca177
MS
7041 if (! prefix_match (p, &rn->p))
7042 continue;
7043 }
7044 if (type == bgp_show_type_community_all)
7045 {
7046 if (! ri->attr->community)
7047 continue;
7048 }
7049 if (type == bgp_show_type_community)
7050 {
7051 struct community *com = output_arg;
718e3744 7052
856ca177
MS
7053 if (! ri->attr->community ||
7054 ! community_match (ri->attr->community, com))
7055 continue;
7056 }
7057 if (type == bgp_show_type_community_exact)
7058 {
7059 struct community *com = output_arg;
718e3744 7060
856ca177
MS
7061 if (! ri->attr->community ||
7062 ! community_cmp (ri->attr->community, com))
7063 continue;
7064 }
7065 if (type == bgp_show_type_community_list)
7066 {
7067 struct community_list *list = output_arg;
718e3744 7068
856ca177
MS
7069 if (! community_list_match (ri->attr->community, list))
7070 continue;
7071 }
7072 if (type == bgp_show_type_community_list_exact)
7073 {
7074 struct community_list *list = output_arg;
718e3744 7075
856ca177
MS
7076 if (! community_list_exact_match (ri->attr->community, list))
7077 continue;
7078 }
7079 if (type == bgp_show_type_flap_address
7080 || type == bgp_show_type_flap_prefix)
7081 {
7082 struct prefix *p = output_arg;
718e3744 7083
856ca177
MS
7084 if (! prefix_match (&rn->p, p))
7085 continue;
b05a1c8b 7086
856ca177
MS
7087 if (type == bgp_show_type_flap_prefix)
7088 if (p->prefixlen != rn->p.prefixlen)
7089 continue;
7090 }
7091 if (type == bgp_show_type_dampend_paths
7092 || type == bgp_show_type_damp_neighbor)
7093 {
7094 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7095 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7096 continue;
7097 }
7098
7099 if (!use_json && header)
7100 {
7101 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (*router_id), VTY_NEWLINE);
7102 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7103 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7104 if (type == bgp_show_type_dampend_paths
7105 || type == bgp_show_type_damp_neighbor)
7106 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7107 else if (type == bgp_show_type_flap_statistics
7108 || type == bgp_show_type_flap_address
7109 || type == bgp_show_type_flap_prefix
7110 || type == bgp_show_type_flap_cidr_only
7111 || type == bgp_show_type_flap_regexp
7112 || type == bgp_show_type_flap_filter_list
7113 || type == bgp_show_type_flap_prefix_list
7114 || type == bgp_show_type_flap_prefix_longer
7115 || type == bgp_show_type_flap_route_map
7116 || type == bgp_show_type_flap_neighbor)
7117 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7118 else
7119 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7120 header = 0;
7121 }
7122
7123 if (type == bgp_show_type_dampend_paths
7124 || type == bgp_show_type_damp_neighbor)
7125 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7126 else if (type == bgp_show_type_flap_statistics
7127 || type == bgp_show_type_flap_address
7128 || type == bgp_show_type_flap_prefix
7129 || type == bgp_show_type_flap_cidr_only
7130 || type == bgp_show_type_flap_regexp
7131 || type == bgp_show_type_flap_filter_list
7132 || type == bgp_show_type_flap_prefix_list
7133 || type == bgp_show_type_flap_prefix_longer
7134 || type == bgp_show_type_flap_route_map
7135 || type == bgp_show_type_flap_neighbor)
7136 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7137 else
7138 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
7139 display++;
b05a1c8b
DS
7140 }
7141
856ca177
MS
7142 if (display)
7143 {
7144 output_count++;
7145 if (use_json)
7146 {
7147 p = &rn->p;
7148 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
7149 json_object_object_add(json_routes, buf2, json_paths);
7150 }
7151 }
718e3744 7152 }
7153
b05a1c8b 7154 if (use_json)
718e3744 7155 {
d1d16a96 7156 json_object_object_add(json, "routes", json_routes);
b05a1c8b 7157 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
f1aa5d8a 7158 json_object_free(json);
718e3744 7159 }
7160 else
b05a1c8b
DS
7161 {
7162 /* No route is displayed */
7163 if (output_count == 0)
7164 {
7165 if (type == bgp_show_type_normal)
856ca177 7166 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
b05a1c8b
DS
7167 }
7168 else
7169 vty_out (vty, "%sTotal number of prefixes %ld%s",
856ca177 7170 VTY_NEWLINE, output_count, VTY_NEWLINE);
b05a1c8b 7171 }
718e3744 7172
7173 return CMD_SUCCESS;
7174}
7175
5a646650 7176static int
fee0f4c6 7177bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
856ca177 7178 enum bgp_show_type type, void *output_arg, u_char use_json)
fee0f4c6 7179{
7180 struct bgp_table *table;
7181
856ca177
MS
7182 if (bgp == NULL)
7183 {
7184 bgp = bgp_get_default ();
7185 }
fee0f4c6 7186
7187 if (bgp == NULL)
7188 {
856ca177
MS
7189 if (!use_json)
7190 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
fee0f4c6 7191 return CMD_WARNING;
7192 }
7193
fee0f4c6 7194 table = bgp->rib[afi][safi];
7195
b05a1c8b 7196 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg, use_json);
fee0f4c6 7197}
7198
718e3744 7199/* Header of detailed BGP route information */
94f2b392 7200static void
718e3744 7201route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7202 struct bgp_node *rn,
b05a1c8b
DS
7203 struct prefix_rd *prd, afi_t afi, safi_t safi,
7204 json_object *json)
718e3744 7205{
7206 struct bgp_info *ri;
7207 struct prefix *p;
7208 struct peer *peer;
1eb8ef25 7209 struct listnode *node, *nnode;
718e3744 7210 char buf1[INET6_ADDRSTRLEN];
7211 char buf2[INET6_ADDRSTRLEN];
7212 int count = 0;
7213 int best = 0;
7214 int suppress = 0;
7215 int no_export = 0;
7216 int no_advertise = 0;
7217 int local_as = 0;
adbac85e 7218 int first = 1;
ffd0c037 7219 json_object *json_adv_to = NULL;
718e3744 7220
7221 p = &rn->p;
b05a1c8b
DS
7222
7223 if (json)
7224 {
f1aa5d8a
DS
7225 json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7226 json_object_int_add(json, "prefixlen", p->prefixlen);
b05a1c8b
DS
7227 }
7228 else
7229 {
7230 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
7231 (safi == SAFI_MPLS_VPN ?
7232 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7233 safi == SAFI_MPLS_VPN ? ":" : "",
7234 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7235 p->prefixlen, VTY_NEWLINE);
7236 }
718e3744 7237
7238 for (ri = rn->info; ri; ri = ri->next)
7239 {
7240 count++;
7241 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7242 {
7243 best = count;
fb982c25 7244 if (ri->extra && ri->extra->suppress)
718e3744 7245 suppress = 1;
7246 if (ri->attr->community != NULL)
7247 {
7248 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7249 no_advertise = 1;
7250 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7251 no_export = 1;
7252 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7253 local_as = 1;
7254 }
7255 }
7256 }
7257
b05a1c8b 7258 if (!json)
718e3744 7259 {
b05a1c8b
DS
7260 vty_out (vty, "Paths: (%d available", count);
7261 if (best)
7262 {
7263 vty_out (vty, ", best #%d", best);
7264 if (safi == SAFI_UNICAST)
7265 vty_out (vty, ", table Default-IP-Routing-Table");
7266 }
7267 else
7268 vty_out (vty, ", no best path");
7269
7270 if (no_advertise)
7271 vty_out (vty, ", not advertised to any peer");
7272 else if (no_export)
7273 vty_out (vty, ", not advertised to EBGP peer");
7274 else if (local_as)
7275 vty_out (vty, ", not advertised outside local AS");
7276
7277 if (suppress)
7278 vty_out (vty, ", Advertisements suppressed by an aggregate.");
7279 vty_out (vty, ")%s", VTY_NEWLINE);
718e3744 7280 }
718e3744 7281
adbac85e
DW
7282 /* If we are not using addpath then we can display Advertised to and that will
7283 * show what peers we advertised the bestpath to. If we are using addpath
7284 * though then we must display Advertised to on a path-by-path basis. */
7285 if (!bgp->addpath_tx_used[afi][safi])
718e3744 7286 {
adbac85e
DW
7287 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7288 {
7289 if (bgp_adj_out_lookup (peer, rn, 0))
b05a1c8b 7290 {
adbac85e 7291 if (json && !json_adv_to)
f1aa5d8a 7292 json_adv_to = json_object_new_object();
6410e93a 7293
adbac85e
DW
7294 route_vty_out_advertised_to(vty, peer, &first,
7295 " Advertised to non peer-group peers:\n ",
7296 json_adv_to);
b05a1c8b 7297 }
adbac85e 7298 }
036a4e7d 7299
adbac85e
DW
7300 if (json)
7301 {
7302 if (json_adv_to)
7303 {
7304 json_object_object_add(json, "advertisedTo", json_adv_to);
b05a1c8b 7305 }
adbac85e
DW
7306 }
7307 else
b05a1c8b 7308 {
adbac85e
DW
7309 if (first)
7310 vty_out (vty, " Not advertised to any peer");
7311 vty_out (vty, "%s", VTY_NEWLINE);
b05a1c8b
DS
7312 }
7313 }
718e3744 7314}
7315
7316/* Display specified route of BGP table. */
94f2b392 7317static int
fee0f4c6 7318bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
fd79ac91 7319 struct bgp_table *rib, const char *ip_str,
7320 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
7321 int prefix_check, enum bgp_path_type pathtype,
7322 u_char use_json)
718e3744 7323{
7324 int ret;
7325 int header;
7326 int display = 0;
7327 struct prefix match;
7328 struct bgp_node *rn;
7329 struct bgp_node *rm;
7330 struct bgp_info *ri;
718e3744 7331 struct bgp_table *table;
f1aa5d8a
DS
7332 json_object *json = NULL;
7333 json_object *json_paths = NULL;
718e3744 7334
718e3744 7335 /* Check IP address argument. */
7336 ret = str2prefix (ip_str, &match);
7337 if (! ret)
7338 {
7339 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
7340 return CMD_WARNING;
7341 }
7342
7343 match.family = afi2family (afi);
7344
b05a1c8b
DS
7345 if (use_json)
7346 {
7347 json = json_object_new_object();
7348 json_paths = json_object_new_array();
7349 }
b05a1c8b 7350
718e3744 7351 if (safi == SAFI_MPLS_VPN)
7352 {
fee0f4c6 7353 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
718e3744 7354 {
7355 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
7356 continue;
7357
7358 if ((table = rn->info) != NULL)
7359 {
7360 header = 1;
7361
7362 if ((rm = bgp_node_match (table, &match)) != NULL)
7363 {
7364 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6c88b44d
CC
7365 {
7366 bgp_unlock_node (rm);
7367 continue;
7368 }
718e3744 7369
7370 for (ri = rm->info; ri; ri = ri->next)
7371 {
7372 if (header)
7373 {
7374 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
b05a1c8b 7375 AFI_IP, SAFI_MPLS_VPN, json);
718e3744 7376
7377 header = 0;
7378 }
7379 display++;
4092b06c
DS
7380
7381 if (pathtype == BGP_PATH_ALL ||
7382 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7383 (pathtype == BGP_PATH_MULTIPATH &&
7384 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
b05a1c8b 7385 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN, json_paths);
718e3744 7386 }
6c88b44d
CC
7387
7388 bgp_unlock_node (rm);
718e3744 7389 }
7390 }
7391 }
7392 }
7393 else
7394 {
7395 header = 1;
7396
fee0f4c6 7397 if ((rn = bgp_node_match (rib, &match)) != NULL)
718e3744 7398 {
7399 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
7400 {
7401 for (ri = rn->info; ri; ri = ri->next)
7402 {
7403 if (header)
7404 {
b05a1c8b 7405 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
718e3744 7406 header = 0;
7407 }
7408 display++;
4092b06c
DS
7409
7410 if (pathtype == BGP_PATH_ALL ||
7411 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7412 (pathtype == BGP_PATH_MULTIPATH &&
7413 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
b05a1c8b 7414 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
718e3744 7415 }
7416 }
6c88b44d
CC
7417
7418 bgp_unlock_node (rn);
718e3744 7419 }
7420 }
7421
e5eee9af 7422 if (use_json)
718e3744 7423 {
e5eee9af
DS
7424 if (display)
7425 json_object_object_add(json, "paths", json_paths);
7426
7427 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
f1aa5d8a 7428 json_object_free(json);
b05a1c8b
DS
7429 }
7430 else
7431 {
e5eee9af 7432 if (!display)
b05a1c8b
DS
7433 {
7434 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
7435 return CMD_WARNING;
7436 }
7437 }
7438
718e3744 7439 return CMD_SUCCESS;
7440}
7441
fee0f4c6 7442/* Display specified route of Main RIB */
94f2b392 7443static int
fd79ac91 7444bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
fee0f4c6 7445 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
7446 int prefix_check, enum bgp_path_type pathtype,
7447 u_char use_json)
fee0f4c6 7448{
7449 struct bgp *bgp;
7450
7451 /* BGP structure lookup. */
7452 if (view_name)
7453 {
7454 bgp = bgp_lookup_by_name (view_name);
7455 if (bgp == NULL)
7456 {
7457 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7458 return CMD_WARNING;
7459 }
7460 }
7461 else
7462 {
7463 bgp = bgp_get_default ();
7464 if (bgp == NULL)
7465 {
7466 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7467 return CMD_WARNING;
7468 }
7469 }
7470
7471 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
b05a1c8b
DS
7472 afi, safi, prd, prefix_check, pathtype,
7473 use_json);
fee0f4c6 7474}
7475
718e3744 7476/* BGP route print out function. */
7477DEFUN (show_ip_bgp,
7478 show_ip_bgp_cmd,
b05a1c8b 7479 "show ip bgp {json}",
47fc97cc
DS
7480 SHOW_STR
7481 IP_STR
b05a1c8b
DS
7482 BGP_STR
7483 "JavaScript Object Notation\n")
47fc97cc 7484{
db7c8528 7485 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
718e3744 7486}
7487
7488DEFUN (show_ip_bgp_ipv4,
7489 show_ip_bgp_ipv4_cmd,
b05a1c8b 7490 "show ip bgp ipv4 (unicast|multicast) {json}",
718e3744 7491 SHOW_STR
7492 IP_STR
7493 BGP_STR
7494 "Address family\n"
7495 "Address Family modifier\n"
b05a1c8b
DS
7496 "Address Family modifier\n"
7497 "JavaScript Object Notation\n")
718e3744 7498{
db7c8528 7499 u_char uj = use_json(argc, argv);
b05a1c8b 7500
718e3744 7501 if (strncmp (argv[0], "m", 1) == 0)
5a646650 7502 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
db7c8528 7503 NULL, uj);
718e3744 7504
db7c8528 7505 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
718e3744 7506}
7507
95cbbd2a
ML
7508ALIAS (show_ip_bgp_ipv4,
7509 show_bgp_ipv4_safi_cmd,
b05a1c8b 7510 "show bgp ipv4 (unicast|multicast) {json}",
95cbbd2a
ML
7511 SHOW_STR
7512 BGP_STR
7513 "Address family\n"
7514 "Address Family modifier\n"
47fc97cc 7515 "Address Family modifier\n"
b05a1c8b 7516 "JavaScript Object Notation\n")
47fc97cc 7517
718e3744 7518DEFUN (show_ip_bgp_route,
7519 show_ip_bgp_route_cmd,
b05a1c8b 7520 "show ip bgp A.B.C.D {json}",
718e3744 7521 SHOW_STR
7522 IP_STR
7523 BGP_STR
b05a1c8b
DS
7524 "Network in the BGP routing table to display\n"
7525 "JavaScript Object Notation\n")
718e3744 7526{
db7c8528 7527 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
4092b06c
DS
7528}
7529
7530DEFUN (show_ip_bgp_route_pathtype,
7531 show_ip_bgp_route_pathtype_cmd,
b05a1c8b 7532 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
4092b06c
DS
7533 SHOW_STR
7534 IP_STR
7535 BGP_STR
7536 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7537 "Display only the bestpath\n"
b05a1c8b
DS
7538 "Display only multipaths\n"
7539 "JavaScript Object Notation\n")
4092b06c 7540{
db7c8528 7541 u_char uj = use_json(argc, argv);
b05a1c8b 7542
4092b06c 7543 if (strncmp (argv[1], "b", 1) == 0)
db7c8528 7544 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 7545 else
db7c8528 7546 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
7547}
7548
7549DEFUN (show_bgp_ipv4_safi_route_pathtype,
7550 show_bgp_ipv4_safi_route_pathtype_cmd,
b05a1c8b 7551 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath) {json}",
4092b06c
DS
7552 SHOW_STR
7553 BGP_STR
7554 "Address family\n"
7555 "Address Family modifier\n"
7556 "Address Family modifier\n"
7557 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7558 "Display only the bestpath\n"
b05a1c8b
DS
7559 "Display only multipaths\n"
7560 "JavaScript Object Notation\n")
4092b06c 7561{
db7c8528 7562 u_char uj = use_json(argc, argv);
b05a1c8b 7563
4092b06c
DS
7564 if (strncmp (argv[0], "m", 1) == 0)
7565 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 7566 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 7567 else
db7c8528 7568 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
7569 else
7570 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 7571 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 7572 else
db7c8528 7573 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
718e3744 7574}
7575
7576DEFUN (show_ip_bgp_ipv4_route,
7577 show_ip_bgp_ipv4_route_cmd,
b05a1c8b 7578 "show ip bgp ipv4 (unicast|multicast) A.B.C.D {json}",
718e3744 7579 SHOW_STR
7580 IP_STR
7581 BGP_STR
7582 "Address family\n"
7583 "Address Family modifier\n"
7584 "Address Family modifier\n"
b05a1c8b
DS
7585 "Network in the BGP routing table to display\n"
7586 "JavaScript Object Notation\n")
718e3744 7587{
db7c8528 7588 u_char uj = use_json(argc, argv);
b05a1c8b 7589
718e3744 7590 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 7591 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
718e3744 7592
db7c8528 7593 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
718e3744 7594}
7595
95cbbd2a
ML
7596ALIAS (show_ip_bgp_ipv4_route,
7597 show_bgp_ipv4_safi_route_cmd,
b05a1c8b 7598 "show bgp ipv4 (unicast|multicast) A.B.C.D {json}",
95cbbd2a
ML
7599 SHOW_STR
7600 BGP_STR
7601 "Address family\n"
7602 "Address Family modifier\n"
7603 "Address Family modifier\n"
b05a1c8b
DS
7604 "Network in the BGP routing table to display\n"
7605 "JavaScript Object Notation\n")
95cbbd2a 7606
718e3744 7607DEFUN (show_ip_bgp_vpnv4_all_route,
7608 show_ip_bgp_vpnv4_all_route_cmd,
b05a1c8b 7609 "show ip bgp vpnv4 all A.B.C.D {json}",
718e3744 7610 SHOW_STR
7611 IP_STR
7612 BGP_STR
7613 "Display VPNv4 NLRI specific information\n"
7614 "Display information about all VPNv4 NLRIs\n"
b05a1c8b
DS
7615 "Network in the BGP routing table to display\n"
7616 "JavaScript Object Notation\n")
718e3744 7617{
db7c8528 7618 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 7619}
7620
4092b06c 7621
718e3744 7622DEFUN (show_ip_bgp_vpnv4_rd_route,
7623 show_ip_bgp_vpnv4_rd_route_cmd,
b05a1c8b 7624 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
718e3744 7625 SHOW_STR
7626 IP_STR
7627 BGP_STR
7628 "Display VPNv4 NLRI specific information\n"
7629 "Display information for a route distinguisher\n"
7630 "VPN Route Distinguisher\n"
b05a1c8b
DS
7631 "Network in the BGP routing table to display\n"
7632 "JavaScript Object Notation\n")
718e3744 7633{
7634 int ret;
7635 struct prefix_rd prd;
db7c8528 7636 u_char uj= use_json(argc, argv);
718e3744 7637
7638 ret = str2prefix_rd (argv[0], &prd);
7639 if (! ret)
7640 {
7641 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7642 return CMD_WARNING;
7643 }
db7c8528 7644 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, uj);
718e3744 7645}
7646
7647DEFUN (show_ip_bgp_prefix,
7648 show_ip_bgp_prefix_cmd,
b05a1c8b 7649 "show ip bgp A.B.C.D/M {json}",
718e3744 7650 SHOW_STR
7651 IP_STR
7652 BGP_STR
b05a1c8b
DS
7653 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7654 "JavaScript Object Notation\n")
718e3744 7655{
db7c8528 7656 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
4092b06c
DS
7657}
7658
7659DEFUN (show_ip_bgp_prefix_pathtype,
7660 show_ip_bgp_prefix_pathtype_cmd,
b05a1c8b 7661 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
7662 SHOW_STR
7663 IP_STR
7664 BGP_STR
7665 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7666 "Display only the bestpath\n"
b05a1c8b
DS
7667 "Display only multipaths\n"
7668 "JavaScript Object Notation\n")
4092b06c 7669{
db7c8528 7670 u_char uj = use_json(argc, argv);
4092b06c 7671 if (strncmp (argv[1], "b", 1) == 0)
db7c8528 7672 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 7673 else
db7c8528 7674 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
718e3744 7675}
7676
7677DEFUN (show_ip_bgp_ipv4_prefix,
7678 show_ip_bgp_ipv4_prefix_cmd,
b05a1c8b 7679 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
718e3744 7680 SHOW_STR
7681 IP_STR
7682 BGP_STR
7683 "Address family\n"
7684 "Address Family modifier\n"
7685 "Address Family modifier\n"
b05a1c8b
DS
7686 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7687 "JavaScript Object Notation\n")
718e3744 7688{
db7c8528 7689 u_char uj = use_json(argc, argv);
b05a1c8b 7690
718e3744 7691 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 7692 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
718e3744 7693
db7c8528 7694 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
718e3744 7695}
7696
95cbbd2a
ML
7697ALIAS (show_ip_bgp_ipv4_prefix,
7698 show_bgp_ipv4_safi_prefix_cmd,
b05a1c8b 7699 "show bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
95cbbd2a
ML
7700 SHOW_STR
7701 BGP_STR
7702 "Address family\n"
7703 "Address Family modifier\n"
7704 "Address Family modifier\n"
b05a1c8b
DS
7705 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7706 "JavaScript Object Notation\n")
95cbbd2a 7707
4092b06c
DS
7708DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
7709 show_ip_bgp_ipv4_prefix_pathtype_cmd,
b05a1c8b 7710 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
7711 SHOW_STR
7712 IP_STR
7713 BGP_STR
7714 "Address family\n"
7715 "Address Family modifier\n"
7716 "Address Family modifier\n"
7717 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7718 "Display only the bestpath\n"
b05a1c8b
DS
7719 "Display only multipaths\n"
7720 "JavaScript Object Notation\n")
4092b06c 7721{
db7c8528 7722 u_char uj = use_json(argc, argv);
b05a1c8b 7723
4092b06c
DS
7724 if (strncmp (argv[0], "m", 1) == 0)
7725 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 7726 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 7727 else
db7c8528 7728 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
7729 else
7730 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 7731 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 7732 else
db7c8528 7733 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
7734}
7735
7736ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
7737 show_bgp_ipv4_safi_prefix_pathtype_cmd,
b05a1c8b 7738 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
7739 SHOW_STR
7740 BGP_STR
7741 "Address family\n"
7742 "Address Family modifier\n"
7743 "Address Family modifier\n"
7744 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7745 "Display only the bestpath\n"
b05a1c8b
DS
7746 "Display only multipaths\n"
7747 "JavaScript Object Notation\n")
4092b06c 7748
718e3744 7749DEFUN (show_ip_bgp_vpnv4_all_prefix,
7750 show_ip_bgp_vpnv4_all_prefix_cmd,
b05a1c8b 7751 "show ip bgp vpnv4 all A.B.C.D/M {json}",
718e3744 7752 SHOW_STR
7753 IP_STR
7754 BGP_STR
7755 "Display VPNv4 NLRI specific information\n"
7756 "Display information about all VPNv4 NLRIs\n"
b05a1c8b
DS
7757 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7758 "JavaScript Object Notation\n")
718e3744 7759{
db7c8528 7760 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 7761}
7762
7763DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7764 show_ip_bgp_vpnv4_rd_prefix_cmd,
b05a1c8b 7765 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
718e3744 7766 SHOW_STR
7767 IP_STR
7768 BGP_STR
7769 "Display VPNv4 NLRI specific information\n"
7770 "Display information for a route distinguisher\n"
7771 "VPN Route Distinguisher\n"
b05a1c8b
DS
7772 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7773 "JavaScript Object Notation\n")
718e3744 7774{
7775 int ret;
7776 struct prefix_rd prd;
7777
7778 ret = str2prefix_rd (argv[0], &prd);
7779 if (! ret)
7780 {
7781 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7782 return CMD_WARNING;
7783 }
db7c8528 7784 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 7785}
7786
7787DEFUN (show_ip_bgp_view,
7788 show_ip_bgp_view_cmd,
b05a1c8b 7789 "show ip bgp view WORD {json}",
718e3744 7790 SHOW_STR
7791 IP_STR
7792 BGP_STR
7793 "BGP view\n"
b05a1c8b
DS
7794 "View name\n"
7795 "JavaScript Object Notation\n")
718e3744 7796{
bb46e94f 7797 struct bgp *bgp;
7798
7799 /* BGP structure lookup. */
7800 bgp = bgp_lookup_by_name (argv[0]);
7801 if (bgp == NULL)
7802 {
7803 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7804 return CMD_WARNING;
7805 }
7806
db7c8528 7807 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
718e3744 7808}
7809
7810DEFUN (show_ip_bgp_view_route,
7811 show_ip_bgp_view_route_cmd,
b05a1c8b 7812 "show ip bgp view WORD A.B.C.D {json}",
718e3744 7813 SHOW_STR
7814 IP_STR
7815 BGP_STR
7816 "BGP view\n"
2b00515a 7817 "View name\n"
b05a1c8b
DS
7818 "Network in the BGP routing table to display\n"
7819 "JavaScript Object Notation\n")
718e3744 7820{
db7c8528 7821 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 7822}
7823
7824DEFUN (show_ip_bgp_view_prefix,
7825 show_ip_bgp_view_prefix_cmd,
b05a1c8b 7826 "show ip bgp view WORD A.B.C.D/M {json}",
718e3744 7827 SHOW_STR
7828 IP_STR
7829 BGP_STR
7830 "BGP view\n"
2b00515a 7831 "View name\n"
b05a1c8b
DS
7832 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7833 "JavaScript Object Notation\n")
718e3744 7834{
db7c8528 7835 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 7836}
7837
7838#ifdef HAVE_IPV6
7839DEFUN (show_bgp,
7840 show_bgp_cmd,
b05a1c8b 7841 "show bgp {json}",
718e3744 7842 SHOW_STR
b05a1c8b
DS
7843 BGP_STR
7844 "JavaScript Object Notation\n")
718e3744 7845{
5a646650 7846 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
db7c8528 7847 NULL, use_json(argc, argv));
718e3744 7848}
7849
7850ALIAS (show_bgp,
7851 show_bgp_ipv6_cmd,
b05a1c8b 7852 "show bgp ipv6 {json}",
718e3744 7853 SHOW_STR
7854 BGP_STR
b05a1c8b
DS
7855 "Address family\n"
7856 "JavaScript Object Notation\n")
718e3744 7857
95cbbd2a
ML
7858DEFUN (show_bgp_ipv6_safi,
7859 show_bgp_ipv6_safi_cmd,
b05a1c8b 7860 "show bgp ipv6 (unicast|multicast) {json}",
95cbbd2a
ML
7861 SHOW_STR
7862 BGP_STR
7863 "Address family\n"
7864 "Address Family modifier\n"
47fc97cc 7865 "Address Family modifier\n"
b05a1c8b 7866 "JavaScript Object Notation\n")
47fc97cc 7867{
db7c8528 7868 u_char uj = use_json(argc, argv);
47fc97cc
DS
7869 if (strncmp (argv[0], "m", 1) == 0)
7870 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
db7c8528 7871 NULL, uj);
47fc97cc 7872
db7c8528 7873 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
95cbbd2a
ML
7874}
7875
47e9b292
DW
7876static void
7877bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty)
7878{
7879 vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our"
7880 " next release%sPlese use 'show bgp ipv6' instead%s%s",
7881 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
7882}
7883
718e3744 7884/* old command */
7885DEFUN (show_ipv6_bgp,
7886 show_ipv6_bgp_cmd,
b05a1c8b 7887 "show ipv6 bgp {json}",
718e3744 7888 SHOW_STR
7889 IP_STR
b05a1c8b
DS
7890 BGP_STR
7891 "JavaScript Object Notation\n")
718e3744 7892{
47e9b292 7893 bgp_show_ipv6_bgp_deprecate_warning(vty);
5a646650 7894 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
db7c8528 7895 NULL, use_json(argc, argv));
718e3744 7896}
7897
7898DEFUN (show_bgp_route,
7899 show_bgp_route_cmd,
b05a1c8b 7900 "show bgp X:X::X:X {json}",
718e3744 7901 SHOW_STR
7902 BGP_STR
b05a1c8b
DS
7903 "Network in the BGP routing table to display\n"
7904 "JavaScript Object Notation\n")
718e3744 7905{
db7c8528 7906 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 7907}
7908
7909ALIAS (show_bgp_route,
7910 show_bgp_ipv6_route_cmd,
b05a1c8b 7911 "show bgp ipv6 X:X::X:X {json}",
718e3744 7912 SHOW_STR
7913 BGP_STR
7914 "Address family\n"
b05a1c8b
DS
7915 "Network in the BGP routing table to display\n"
7916 "JavaScript Object Notation\n")
718e3744 7917
95cbbd2a
ML
7918DEFUN (show_bgp_ipv6_safi_route,
7919 show_bgp_ipv6_safi_route_cmd,
b05a1c8b 7920 "show bgp ipv6 (unicast|multicast) X:X::X:X {json}",
95cbbd2a
ML
7921 SHOW_STR
7922 BGP_STR
7923 "Address family\n"
7924 "Address Family modifier\n"
7925 "Address Family modifier\n"
b05a1c8b
DS
7926 "Network in the BGP routing table to display\n"
7927 "JavaScript Object Notation\n")
95cbbd2a 7928{
db7c8528 7929 u_char uj = use_json(argc, argv);
95cbbd2a 7930 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 7931 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
95cbbd2a 7932
db7c8528 7933 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
4092b06c
DS
7934}
7935
7936DEFUN (show_bgp_route_pathtype,
7937 show_bgp_route_pathtype_cmd,
b05a1c8b 7938 "show bgp X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
7939 SHOW_STR
7940 BGP_STR
7941 "Network in the BGP routing table to display\n"
7942 "Display only the bestpath\n"
b05a1c8b
DS
7943 "Display only multipaths\n"
7944 "JavaScript Object Notation\n")
4092b06c 7945{
db7c8528 7946 u_char uj = use_json(argc, argv);
4092b06c 7947 if (strncmp (argv[1], "b", 1) == 0)
db7c8528 7948 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 7949 else
db7c8528 7950 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
7951}
7952
7953ALIAS (show_bgp_route_pathtype,
7954 show_bgp_ipv6_route_pathtype_cmd,
b05a1c8b 7955 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
7956 SHOW_STR
7957 BGP_STR
7958 "Address family\n"
7959 "Network in the BGP routing table to display\n"
7960 "Display only the bestpath\n"
b05a1c8b
DS
7961 "Display only multipaths\n"
7962 "JavaScript Object Notation\n")
4092b06c
DS
7963
7964DEFUN (show_bgp_ipv6_safi_route_pathtype,
7965 show_bgp_ipv6_safi_route_pathtype_cmd,
b05a1c8b 7966 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
7967 SHOW_STR
7968 BGP_STR
7969 "Address family\n"
7970 "Address Family modifier\n"
7971 "Address Family modifier\n"
7972 "Network in the BGP routing table to display\n"
7973 "Display only the bestpath\n"
b05a1c8b
DS
7974 "Display only multipaths\n"
7975 "JavaScript Object Notation\n")
4092b06c 7976{
db7c8528 7977 u_char uj = use_json(argc, argv);
4092b06c
DS
7978 if (strncmp (argv[0], "m", 1) == 0)
7979 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 7980 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 7981 else
db7c8528 7982 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
7983 else
7984 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 7985 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 7986 else
db7c8528 7987 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
95cbbd2a
ML
7988}
7989
718e3744 7990/* old command */
7991DEFUN (show_ipv6_bgp_route,
7992 show_ipv6_bgp_route_cmd,
b05a1c8b 7993 "show ipv6 bgp X:X::X:X {json}",
718e3744 7994 SHOW_STR
7995 IP_STR
7996 BGP_STR
b05a1c8b
DS
7997 "Network in the BGP routing table to display\n"
7998 "JavaScript Object Notation\n")
718e3744 7999{
47e9b292 8000 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 8001 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8002}
8003
8004DEFUN (show_bgp_prefix,
8005 show_bgp_prefix_cmd,
b05a1c8b 8006 "show bgp X:X::X:X/M {json}",
718e3744 8007 SHOW_STR
8008 BGP_STR
b05a1c8b
DS
8009 "IPv6 prefix <network>/<length>\n"
8010 "JavaScript Object Notation\n")
718e3744 8011{
db7c8528 8012 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8013}
8014
8015ALIAS (show_bgp_prefix,
8016 show_bgp_ipv6_prefix_cmd,
b05a1c8b 8017 "show bgp ipv6 X:X::X:X/M {json}",
718e3744 8018 SHOW_STR
8019 BGP_STR
8020 "Address family\n"
b05a1c8b
DS
8021 "IPv6 prefix <network>/<length>\n"
8022 "JavaScript Object Notation\n")
718e3744 8023
95cbbd2a
ML
8024DEFUN (show_bgp_ipv6_safi_prefix,
8025 show_bgp_ipv6_safi_prefix_cmd,
b05a1c8b 8026 "show bgp ipv6 (unicast|multicast) X:X::X:X/M {json}",
95cbbd2a
ML
8027 SHOW_STR
8028 BGP_STR
8029 "Address family\n"
8030 "Address Family modifier\n"
8031 "Address Family modifier\n"
b05a1c8b
DS
8032 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8033 "JavaScript Object Notation\n")
95cbbd2a 8034{
db7c8528 8035 u_char uj = use_json(argc, argv);
95cbbd2a 8036 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 8037 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
95cbbd2a 8038
db7c8528 8039 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
4092b06c
DS
8040}
8041
8042DEFUN (show_bgp_prefix_pathtype,
8043 show_bgp_prefix_pathtype_cmd,
b05a1c8b 8044 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8045 SHOW_STR
8046 BGP_STR
8047 "IPv6 prefix <network>/<length>\n"
8048 "Display only the bestpath\n"
b05a1c8b
DS
8049 "Display only multipaths\n"
8050 "JavaScript Object Notation\n")
4092b06c 8051{
db7c8528 8052 u_char uj = use_json(argc, argv);
4092b06c 8053 if (strncmp (argv[1], "b", 1) == 0)
db7c8528 8054 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8055 else
db7c8528 8056 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8057}
8058
8059ALIAS (show_bgp_prefix_pathtype,
8060 show_bgp_ipv6_prefix_pathtype_cmd,
b05a1c8b 8061 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8062 SHOW_STR
8063 BGP_STR
8064 "Address family\n"
8065 "IPv6 prefix <network>/<length>\n"
8066 "Display only the bestpath\n"
b05a1c8b
DS
8067 "Display only multipaths\n"
8068 "JavaScript Object Notation\n")
4092b06c
DS
8069
8070DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8071 show_bgp_ipv6_safi_prefix_pathtype_cmd,
b05a1c8b 8072 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8073 SHOW_STR
8074 BGP_STR
8075 "Address family\n"
8076 "Address Family modifier\n"
8077 "Address Family modifier\n"
8078 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8079 "Display only the bestpath\n"
b05a1c8b
DS
8080 "Display only multipaths\n"
8081 "JavaScript Object Notation\n")
4092b06c 8082{
db7c8528 8083 u_char uj = use_json(argc, argv);
4092b06c
DS
8084 if (strncmp (argv[0], "m", 1) == 0)
8085 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 8086 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8087 else
db7c8528 8088 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8089 else
8090 if (strncmp (argv[2], "b", 1) == 0)
db7c8528 8091 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8092 else
db7c8528 8093 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
95cbbd2a
ML
8094}
8095
718e3744 8096/* old command */
8097DEFUN (show_ipv6_bgp_prefix,
8098 show_ipv6_bgp_prefix_cmd,
b05a1c8b 8099 "show ipv6 bgp X:X::X:X/M {json}",
718e3744 8100 SHOW_STR
8101 IP_STR
8102 BGP_STR
b05a1c8b
DS
8103 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8104 "JavaScript Object Notation\n")
718e3744 8105{
47e9b292 8106 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 8107 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8108}
8109
bb46e94f 8110DEFUN (show_bgp_view,
8111 show_bgp_view_cmd,
b05a1c8b 8112 "show bgp view WORD {json}",
bb46e94f 8113 SHOW_STR
8114 BGP_STR
8115 "BGP view\n"
b05a1c8b
DS
8116 "View name\n"
8117 "JavaScript Object Notation\n")
bb46e94f 8118{
8119 struct bgp *bgp;
8120
8121 /* BGP structure lookup. */
8122 bgp = bgp_lookup_by_name (argv[0]);
8123 if (bgp == NULL)
db7c8528
DS
8124 {
8125 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8126 return CMD_WARNING;
8127 }
8128
8129 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
bb46e94f 8130}
8131
8132ALIAS (show_bgp_view,
8133 show_bgp_view_ipv6_cmd,
b05a1c8b 8134 "show bgp view WORD ipv6 {json}",
bb46e94f 8135 SHOW_STR
8136 BGP_STR
8137 "BGP view\n"
8138 "View name\n"
b05a1c8b
DS
8139 "Address family\n"
8140 "JavaScript Object Notation\n")
bb46e94f 8141
8142DEFUN (show_bgp_view_route,
8143 show_bgp_view_route_cmd,
b05a1c8b 8144 "show bgp view WORD X:X::X:X {json}",
bb46e94f 8145 SHOW_STR
8146 BGP_STR
8147 "BGP view\n"
8148 "View name\n"
b05a1c8b
DS
8149 "Network in the BGP routing table to display\n"
8150 "JavaScript Object Notation\n")
bb46e94f 8151{
db7c8528 8152 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
bb46e94f 8153}
8154
8155ALIAS (show_bgp_view_route,
8156 show_bgp_view_ipv6_route_cmd,
b05a1c8b 8157 "show bgp view WORD ipv6 X:X::X:X {json}",
bb46e94f 8158 SHOW_STR
8159 BGP_STR
8160 "BGP view\n"
8161 "View name\n"
8162 "Address family\n"
b05a1c8b
DS
8163 "Network in the BGP routing table to display\n"
8164 "JavaScript Object Notation\n")
bb46e94f 8165
8166DEFUN (show_bgp_view_prefix,
8167 show_bgp_view_prefix_cmd,
b05a1c8b 8168 "show bgp view WORD X:X::X:X/M {json}",
bb46e94f 8169 SHOW_STR
8170 BGP_STR
8171 "BGP view\n"
8172 "View name\n"
b05a1c8b
DS
8173 "IPv6 prefix <network>/<length>\n"
8174 "JavaScript Object Notation\n")
bb46e94f 8175{
db7c8528 8176 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
bb46e94f 8177}
8178
8179ALIAS (show_bgp_view_prefix,
8180 show_bgp_view_ipv6_prefix_cmd,
b05a1c8b 8181 "show bgp view WORD ipv6 X:X::X:X/M {json}",
bb46e94f 8182 SHOW_STR
8183 BGP_STR
8184 "BGP view\n"
8185 "View name\n"
8186 "Address family\n"
b05a1c8b
DS
8187 "IPv6 prefix <network>/<length>\n"
8188 "JavaScript Object Notation\n")
bb46e94f 8189
718e3744 8190/* old command */
8191DEFUN (show_ipv6_mbgp,
8192 show_ipv6_mbgp_cmd,
b05a1c8b 8193 "show ipv6 mbgp {json}",
718e3744 8194 SHOW_STR
8195 IP_STR
b05a1c8b
DS
8196 MBGP_STR
8197 "JavaScript Object Notation\n")
718e3744 8198{
47e9b292 8199 bgp_show_ipv6_bgp_deprecate_warning(vty);
5a646650 8200 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
db7c8528 8201 NULL, use_json(argc, argv));
718e3744 8202}
8203
8204/* old command */
8205DEFUN (show_ipv6_mbgp_route,
8206 show_ipv6_mbgp_route_cmd,
b05a1c8b 8207 "show ipv6 mbgp X:X::X:X {json}",
718e3744 8208 SHOW_STR
8209 IP_STR
8210 MBGP_STR
b05a1c8b
DS
8211 "Network in the MBGP routing table to display\n"
8212 "JavaScript Object Notation\n")
718e3744 8213{
47e9b292 8214 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 8215 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8216}
8217
8218/* old command */
8219DEFUN (show_ipv6_mbgp_prefix,
8220 show_ipv6_mbgp_prefix_cmd,
b05a1c8b 8221 "show ipv6 mbgp X:X::X:X/M {json}",
718e3744 8222 SHOW_STR
8223 IP_STR
8224 MBGP_STR
b05a1c8b
DS
8225 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8226 "JavaScript Object Notation\n")
718e3744 8227{
47e9b292 8228 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 8229 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8230}
8231#endif
6b0655a2 8232
718e3744 8233
94f2b392 8234static int
fd79ac91 8235bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
718e3744 8236 safi_t safi, enum bgp_show_type type)
8237{
8238 int i;
8239 struct buffer *b;
8240 char *regstr;
8241 int first;
8242 regex_t *regex;
5a646650 8243 int rc;
718e3744 8244
8245 first = 0;
8246 b = buffer_new (1024);
8247 for (i = 0; i < argc; i++)
8248 {
8249 if (first)
8250 buffer_putc (b, ' ');
8251 else
8252 {
8253 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8254 continue;
8255 first = 1;
8256 }
8257
8258 buffer_putstr (b, argv[i]);
8259 }
8260 buffer_putc (b, '\0');
8261
8262 regstr = buffer_getstr (b);
8263 buffer_free (b);
8264
8265 regex = bgp_regcomp (regstr);
3b8b1855 8266 XFREE(MTYPE_TMP, regstr);
718e3744 8267 if (! regex)
8268 {
8269 vty_out (vty, "Can't compile regexp %s%s", argv[0],
8270 VTY_NEWLINE);
8271 return CMD_WARNING;
8272 }
8273
b05a1c8b 8274 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
5a646650 8275 bgp_regex_free (regex);
8276 return rc;
718e3744 8277}
8278
8279DEFUN (show_ip_bgp_regexp,
8280 show_ip_bgp_regexp_cmd,
8281 "show ip bgp regexp .LINE",
8282 SHOW_STR
8283 IP_STR
8284 BGP_STR
8285 "Display routes matching the AS path regular expression\n"
8286 "A regular-expression to match the BGP AS paths\n")
8287{
8288 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8289 bgp_show_type_regexp);
8290}
8291
8292DEFUN (show_ip_bgp_flap_regexp,
8293 show_ip_bgp_flap_regexp_cmd,
8294 "show ip bgp flap-statistics regexp .LINE",
8295 SHOW_STR
8296 IP_STR
8297 BGP_STR
8298 "Display flap statistics of routes\n"
8299 "Display routes matching the AS path regular expression\n"
8300 "A regular-expression to match the BGP AS paths\n")
8301{
8302 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8303 bgp_show_type_flap_regexp);
8304}
8305
8306DEFUN (show_ip_bgp_ipv4_regexp,
8307 show_ip_bgp_ipv4_regexp_cmd,
8308 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
8309 SHOW_STR
8310 IP_STR
8311 BGP_STR
8312 "Address family\n"
8313 "Address Family modifier\n"
8314 "Address Family modifier\n"
8315 "Display routes matching the AS path regular expression\n"
8316 "A regular-expression to match the BGP AS paths\n")
8317{
8318 if (strncmp (argv[0], "m", 1) == 0)
8319 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
8320 bgp_show_type_regexp);
8321
8322 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8323 bgp_show_type_regexp);
8324}
8325
8326#ifdef HAVE_IPV6
8327DEFUN (show_bgp_regexp,
8328 show_bgp_regexp_cmd,
8329 "show bgp regexp .LINE",
8330 SHOW_STR
8331 BGP_STR
8332 "Display routes matching the AS path regular expression\n"
8333 "A regular-expression to match the BGP AS paths\n")
8334{
8335 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8336 bgp_show_type_regexp);
8337}
8338
8339ALIAS (show_bgp_regexp,
8340 show_bgp_ipv6_regexp_cmd,
8341 "show bgp ipv6 regexp .LINE",
8342 SHOW_STR
8343 BGP_STR
8344 "Address family\n"
8345 "Display routes matching the AS path regular expression\n"
8346 "A regular-expression to match the BGP AS paths\n")
8347
8348/* old command */
8349DEFUN (show_ipv6_bgp_regexp,
8350 show_ipv6_bgp_regexp_cmd,
8351 "show ipv6 bgp regexp .LINE",
8352 SHOW_STR
8353 IP_STR
8354 BGP_STR
8355 "Display routes matching the AS path regular expression\n"
8356 "A regular-expression to match the BGP AS paths\n")
8357{
47e9b292 8358 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 8359 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8360 bgp_show_type_regexp);
8361}
8362
8363/* old command */
8364DEFUN (show_ipv6_mbgp_regexp,
8365 show_ipv6_mbgp_regexp_cmd,
8366 "show ipv6 mbgp regexp .LINE",
8367 SHOW_STR
8368 IP_STR
8369 BGP_STR
8370 "Display routes matching the AS path regular expression\n"
8371 "A regular-expression to match the MBGP AS paths\n")
8372{
47e9b292 8373 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 8374 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
8375 bgp_show_type_regexp);
8376}
8377#endif /* HAVE_IPV6 */
6b0655a2 8378
94f2b392 8379static int
fd79ac91 8380bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
718e3744 8381 safi_t safi, enum bgp_show_type type)
8382{
8383 struct prefix_list *plist;
8384
8385 plist = prefix_list_lookup (afi, prefix_list_str);
8386 if (plist == NULL)
8387 {
8388 vty_out (vty, "%% %s is not a valid prefix-list name%s",
8389 prefix_list_str, VTY_NEWLINE);
8390 return CMD_WARNING;
8391 }
8392
b05a1c8b 8393 return bgp_show (vty, NULL, afi, safi, type, plist, 0);
718e3744 8394}
8395
8396DEFUN (show_ip_bgp_prefix_list,
8397 show_ip_bgp_prefix_list_cmd,
8398 "show ip bgp prefix-list WORD",
8399 SHOW_STR
8400 IP_STR
8401 BGP_STR
8402 "Display routes conforming to the prefix-list\n"
8403 "IP prefix-list name\n")
8404{
8405 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8406 bgp_show_type_prefix_list);
8407}
8408
8409DEFUN (show_ip_bgp_flap_prefix_list,
8410 show_ip_bgp_flap_prefix_list_cmd,
8411 "show ip bgp flap-statistics prefix-list WORD",
8412 SHOW_STR
8413 IP_STR
8414 BGP_STR
8415 "Display flap statistics of routes\n"
8416 "Display routes conforming to the prefix-list\n"
8417 "IP prefix-list name\n")
8418{
8419 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8420 bgp_show_type_flap_prefix_list);
8421}
8422
8423DEFUN (show_ip_bgp_ipv4_prefix_list,
8424 show_ip_bgp_ipv4_prefix_list_cmd,
8425 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
8426 SHOW_STR
8427 IP_STR
8428 BGP_STR
8429 "Address family\n"
8430 "Address Family modifier\n"
8431 "Address Family modifier\n"
8432 "Display routes conforming to the prefix-list\n"
8433 "IP prefix-list name\n")
8434{
8435 if (strncmp (argv[0], "m", 1) == 0)
8436 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8437 bgp_show_type_prefix_list);
8438
8439 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8440 bgp_show_type_prefix_list);
8441}
8442
8443#ifdef HAVE_IPV6
8444DEFUN (show_bgp_prefix_list,
8445 show_bgp_prefix_list_cmd,
8446 "show bgp prefix-list WORD",
8447 SHOW_STR
8448 BGP_STR
8449 "Display routes conforming to the prefix-list\n"
8450 "IPv6 prefix-list name\n")
8451{
8452 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8453 bgp_show_type_prefix_list);
8454}
8455
8456ALIAS (show_bgp_prefix_list,
8457 show_bgp_ipv6_prefix_list_cmd,
8458 "show bgp ipv6 prefix-list WORD",
8459 SHOW_STR
8460 BGP_STR
8461 "Address family\n"
8462 "Display routes conforming to the prefix-list\n"
8463 "IPv6 prefix-list name\n")
8464
8465/* old command */
8466DEFUN (show_ipv6_bgp_prefix_list,
8467 show_ipv6_bgp_prefix_list_cmd,
8468 "show ipv6 bgp prefix-list WORD",
8469 SHOW_STR
8470 IPV6_STR
8471 BGP_STR
8472 "Display routes matching the prefix-list\n"
8473 "IPv6 prefix-list name\n")
8474{
47e9b292 8475 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 8476 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8477 bgp_show_type_prefix_list);
8478}
8479
8480/* old command */
8481DEFUN (show_ipv6_mbgp_prefix_list,
8482 show_ipv6_mbgp_prefix_list_cmd,
8483 "show ipv6 mbgp prefix-list WORD",
8484 SHOW_STR
8485 IPV6_STR
8486 MBGP_STR
8487 "Display routes matching the prefix-list\n"
8488 "IPv6 prefix-list name\n")
8489{
47e9b292 8490 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 8491 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8492 bgp_show_type_prefix_list);
8493}
8494#endif /* HAVE_IPV6 */
6b0655a2 8495
94f2b392 8496static int
fd79ac91 8497bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
718e3744 8498 safi_t safi, enum bgp_show_type type)
8499{
8500 struct as_list *as_list;
8501
8502 as_list = as_list_lookup (filter);
8503 if (as_list == NULL)
8504 {
8505 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
8506 return CMD_WARNING;
8507 }
8508
b05a1c8b 8509 return bgp_show (vty, NULL, afi, safi, type, as_list, 0);
718e3744 8510}
8511
8512DEFUN (show_ip_bgp_filter_list,
8513 show_ip_bgp_filter_list_cmd,
8514 "show ip bgp filter-list WORD",
8515 SHOW_STR
8516 IP_STR
8517 BGP_STR
8518 "Display routes conforming to the filter-list\n"
8519 "Regular expression access list name\n")
8520{
8521 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8522 bgp_show_type_filter_list);
8523}
8524
8525DEFUN (show_ip_bgp_flap_filter_list,
8526 show_ip_bgp_flap_filter_list_cmd,
8527 "show ip bgp flap-statistics filter-list WORD",
8528 SHOW_STR
8529 IP_STR
8530 BGP_STR
8531 "Display flap statistics of routes\n"
8532 "Display routes conforming to the filter-list\n"
8533 "Regular expression access list name\n")
8534{
8535 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8536 bgp_show_type_flap_filter_list);
8537}
8538
8539DEFUN (show_ip_bgp_ipv4_filter_list,
8540 show_ip_bgp_ipv4_filter_list_cmd,
8541 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
8542 SHOW_STR
8543 IP_STR
8544 BGP_STR
8545 "Address family\n"
8546 "Address Family modifier\n"
8547 "Address Family modifier\n"
8548 "Display routes conforming to the filter-list\n"
8549 "Regular expression access list name\n")
8550{
8551 if (strncmp (argv[0], "m", 1) == 0)
8552 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8553 bgp_show_type_filter_list);
8554
8555 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8556 bgp_show_type_filter_list);
8557}
8558
8559#ifdef HAVE_IPV6
8560DEFUN (show_bgp_filter_list,
8561 show_bgp_filter_list_cmd,
8562 "show bgp filter-list WORD",
8563 SHOW_STR
8564 BGP_STR
8565 "Display routes conforming to the filter-list\n"
8566 "Regular expression access list name\n")
8567{
8568 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8569 bgp_show_type_filter_list);
8570}
8571
8572ALIAS (show_bgp_filter_list,
8573 show_bgp_ipv6_filter_list_cmd,
8574 "show bgp ipv6 filter-list WORD",
8575 SHOW_STR
8576 BGP_STR
8577 "Address family\n"
8578 "Display routes conforming to the filter-list\n"
8579 "Regular expression access list name\n")
8580
8581/* old command */
8582DEFUN (show_ipv6_bgp_filter_list,
8583 show_ipv6_bgp_filter_list_cmd,
8584 "show ipv6 bgp filter-list WORD",
8585 SHOW_STR
8586 IPV6_STR
8587 BGP_STR
8588 "Display routes conforming to the filter-list\n"
8589 "Regular expression access list name\n")
8590{
47e9b292 8591 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 8592 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8593 bgp_show_type_filter_list);
8594}
8595
8596/* old command */
8597DEFUN (show_ipv6_mbgp_filter_list,
8598 show_ipv6_mbgp_filter_list_cmd,
8599 "show ipv6 mbgp filter-list WORD",
8600 SHOW_STR
8601 IPV6_STR
8602 MBGP_STR
8603 "Display routes conforming to the filter-list\n"
8604 "Regular expression access list name\n")
8605{
47e9b292 8606 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 8607 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8608 bgp_show_type_filter_list);
8609}
8610#endif /* HAVE_IPV6 */
6b0655a2 8611
94f2b392 8612static int
fd79ac91 8613bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
718e3744 8614 safi_t safi, enum bgp_show_type type)
8615{
8616 struct route_map *rmap;
8617
8618 rmap = route_map_lookup_by_name (rmap_str);
8619 if (! rmap)
8620 {
8621 vty_out (vty, "%% %s is not a valid route-map name%s",
8622 rmap_str, VTY_NEWLINE);
8623 return CMD_WARNING;
8624 }
8625
b05a1c8b 8626 return bgp_show (vty, NULL, afi, safi, type, rmap, 0);
718e3744 8627}
8628
8629DEFUN (show_ip_bgp_route_map,
8630 show_ip_bgp_route_map_cmd,
8631 "show ip bgp route-map WORD",
8632 SHOW_STR
8633 IP_STR
8634 BGP_STR
8635 "Display routes matching the route-map\n"
8636 "A route-map to match on\n")
8637{
8638 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8639 bgp_show_type_route_map);
8640}
8641
8642DEFUN (show_ip_bgp_flap_route_map,
8643 show_ip_bgp_flap_route_map_cmd,
8644 "show ip bgp flap-statistics route-map WORD",
8645 SHOW_STR
8646 IP_STR
8647 BGP_STR
8648 "Display flap statistics of routes\n"
8649 "Display routes matching the route-map\n"
8650 "A route-map to match on\n")
8651{
8652 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8653 bgp_show_type_flap_route_map);
8654}
8655
8656DEFUN (show_ip_bgp_ipv4_route_map,
8657 show_ip_bgp_ipv4_route_map_cmd,
8658 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
8659 SHOW_STR
8660 IP_STR
8661 BGP_STR
8662 "Address family\n"
8663 "Address Family modifier\n"
8664 "Address Family modifier\n"
8665 "Display routes matching the route-map\n"
8666 "A route-map to match on\n")
8667{
8668 if (strncmp (argv[0], "m", 1) == 0)
8669 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8670 bgp_show_type_route_map);
8671
8672 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
8673 bgp_show_type_route_map);
8674}
8675
8676DEFUN (show_bgp_route_map,
8677 show_bgp_route_map_cmd,
8678 "show bgp route-map WORD",
8679 SHOW_STR
8680 BGP_STR
8681 "Display routes matching the route-map\n"
8682 "A route-map to match on\n")
8683{
8684 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8685 bgp_show_type_route_map);
8686}
8687
8688ALIAS (show_bgp_route_map,
8689 show_bgp_ipv6_route_map_cmd,
8690 "show bgp ipv6 route-map WORD",
8691 SHOW_STR
8692 BGP_STR
8693 "Address family\n"
8694 "Display routes matching the route-map\n"
8695 "A route-map to match on\n")
6b0655a2 8696
718e3744 8697DEFUN (show_ip_bgp_cidr_only,
8698 show_ip_bgp_cidr_only_cmd,
8699 "show ip bgp cidr-only",
8700 SHOW_STR
8701 IP_STR
8702 BGP_STR
8703 "Display only routes with non-natural netmasks\n")
8704{
8705 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 8706 bgp_show_type_cidr_only, NULL, 0);
718e3744 8707}
8708
8709DEFUN (show_ip_bgp_flap_cidr_only,
8710 show_ip_bgp_flap_cidr_only_cmd,
8711 "show ip bgp flap-statistics cidr-only",
8712 SHOW_STR
8713 IP_STR
8714 BGP_STR
8715 "Display flap statistics of routes\n"
8716 "Display only routes with non-natural netmasks\n")
8717{
8718 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 8719 bgp_show_type_flap_cidr_only, NULL, 0);
718e3744 8720}
8721
8722DEFUN (show_ip_bgp_ipv4_cidr_only,
8723 show_ip_bgp_ipv4_cidr_only_cmd,
8724 "show ip bgp ipv4 (unicast|multicast) cidr-only",
8725 SHOW_STR
8726 IP_STR
8727 BGP_STR
8728 "Address family\n"
8729 "Address Family modifier\n"
8730 "Address Family modifier\n"
8731 "Display only routes with non-natural netmasks\n")
8732{
8733 if (strncmp (argv[0], "m", 1) == 0)
8734 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
b05a1c8b 8735 bgp_show_type_cidr_only, NULL, 0);
718e3744 8736
8737 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 8738 bgp_show_type_cidr_only, NULL, 0);
718e3744 8739}
6b0655a2 8740
718e3744 8741DEFUN (show_ip_bgp_community_all,
8742 show_ip_bgp_community_all_cmd,
8743 "show ip bgp community",
8744 SHOW_STR
8745 IP_STR
8746 BGP_STR
8747 "Display routes matching the communities\n")
8748{
8749 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 8750 bgp_show_type_community_all, NULL, 0);
718e3744 8751}
8752
8753DEFUN (show_ip_bgp_ipv4_community_all,
8754 show_ip_bgp_ipv4_community_all_cmd,
8755 "show ip bgp ipv4 (unicast|multicast) community",
8756 SHOW_STR
8757 IP_STR
8758 BGP_STR
8759 "Address family\n"
8760 "Address Family modifier\n"
8761 "Address Family modifier\n"
8762 "Display routes matching the communities\n")
8763{
8764 if (strncmp (argv[0], "m", 1) == 0)
8765 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
b05a1c8b 8766 bgp_show_type_community_all, NULL, 0);
718e3744 8767
8768 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 8769 bgp_show_type_community_all, NULL, 0);
718e3744 8770}
8771
8772#ifdef HAVE_IPV6
8773DEFUN (show_bgp_community_all,
8774 show_bgp_community_all_cmd,
8775 "show bgp community",
8776 SHOW_STR
8777 BGP_STR
8778 "Display routes matching the communities\n")
8779{
8780 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 8781 bgp_show_type_community_all, NULL, 0);
718e3744 8782}
8783
8784ALIAS (show_bgp_community_all,
8785 show_bgp_ipv6_community_all_cmd,
8786 "show bgp ipv6 community",
8787 SHOW_STR
8788 BGP_STR
8789 "Address family\n"
8790 "Display routes matching the communities\n")
8791
8792/* old command */
8793DEFUN (show_ipv6_bgp_community_all,
8794 show_ipv6_bgp_community_all_cmd,
8795 "show ipv6 bgp community",
8796 SHOW_STR
8797 IPV6_STR
8798 BGP_STR
8799 "Display routes matching the communities\n")
8800{
47e9b292 8801 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 8802 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 8803 bgp_show_type_community_all, NULL, 0);
718e3744 8804}
8805
8806/* old command */
8807DEFUN (show_ipv6_mbgp_community_all,
8808 show_ipv6_mbgp_community_all_cmd,
8809 "show ipv6 mbgp community",
8810 SHOW_STR
8811 IPV6_STR
8812 MBGP_STR
8813 "Display routes matching the communities\n")
8814{
47e9b292 8815 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 8816 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
b05a1c8b 8817 bgp_show_type_community_all, NULL, 0);
718e3744 8818}
8819#endif /* HAVE_IPV6 */
6b0655a2 8820
94f2b392 8821static int
95cbbd2a
ML
8822bgp_show_community (struct vty *vty, const char *view_name, int argc,
8823 const char **argv, int exact, afi_t afi, safi_t safi)
718e3744 8824{
8825 struct community *com;
8826 struct buffer *b;
95cbbd2a 8827 struct bgp *bgp;
718e3744 8828 int i;
8829 char *str;
8830 int first = 0;
8831
95cbbd2a
ML
8832 /* BGP structure lookup */
8833 if (view_name)
8834 {
8835 bgp = bgp_lookup_by_name (view_name);
8836 if (bgp == NULL)
8837 {
8838 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8839 return CMD_WARNING;
8840 }
8841 }
8842 else
8843 {
8844 bgp = bgp_get_default ();
8845 if (bgp == NULL)
8846 {
8847 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8848 return CMD_WARNING;
8849 }
8850 }
8851
718e3744 8852 b = buffer_new (1024);
8853 for (i = 0; i < argc; i++)
8854 {
8855 if (first)
8856 buffer_putc (b, ' ');
8857 else
8858 {
8859 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8860 continue;
8861 first = 1;
8862 }
8863
8864 buffer_putstr (b, argv[i]);
8865 }
8866 buffer_putc (b, '\0');
8867
8868 str = buffer_getstr (b);
8869 buffer_free (b);
8870
8871 com = community_str2com (str);
3b8b1855 8872 XFREE (MTYPE_TMP, str);
718e3744 8873 if (! com)
8874 {
8875 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
8876 return CMD_WARNING;
8877 }
8878
95cbbd2a 8879 return bgp_show (vty, bgp, afi, safi,
5a646650 8880 (exact ? bgp_show_type_community_exact :
b05a1c8b 8881 bgp_show_type_community), com, 0);
718e3744 8882}
8883
8884DEFUN (show_ip_bgp_community,
8885 show_ip_bgp_community_cmd,
8886 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
8887 SHOW_STR
8888 IP_STR
8889 BGP_STR
8890 "Display routes matching the communities\n"
8891 "community number\n"
8892 "Do not send outside local AS (well-known community)\n"
8893 "Do not advertise to any peer (well-known community)\n"
8894 "Do not export to next AS (well-known community)\n")
8895{
95cbbd2a 8896 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 8897}
8898
8899ALIAS (show_ip_bgp_community,
8900 show_ip_bgp_community2_cmd,
8901 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8902 SHOW_STR
8903 IP_STR
8904 BGP_STR
8905 "Display routes matching the communities\n"
8906 "community number\n"
8907 "Do not send outside local AS (well-known community)\n"
8908 "Do not advertise to any peer (well-known community)\n"
8909 "Do not export to next AS (well-known community)\n"
8910 "community number\n"
8911 "Do not send outside local AS (well-known community)\n"
8912 "Do not advertise to any peer (well-known community)\n"
8913 "Do not export to next AS (well-known community)\n")
8914
8915ALIAS (show_ip_bgp_community,
8916 show_ip_bgp_community3_cmd,
8917 "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)",
8918 SHOW_STR
8919 IP_STR
8920 BGP_STR
8921 "Display routes matching the communities\n"
8922 "community number\n"
8923 "Do not send outside local AS (well-known community)\n"
8924 "Do not advertise to any peer (well-known community)\n"
8925 "Do not export to next AS (well-known community)\n"
8926 "community number\n"
8927 "Do not send outside local AS (well-known community)\n"
8928 "Do not advertise to any peer (well-known community)\n"
8929 "Do not export to next AS (well-known community)\n"
8930 "community number\n"
8931 "Do not send outside local AS (well-known community)\n"
8932 "Do not advertise to any peer (well-known community)\n"
8933 "Do not export to next AS (well-known community)\n")
8934
8935ALIAS (show_ip_bgp_community,
8936 show_ip_bgp_community4_cmd,
8937 "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)",
8938 SHOW_STR
8939 IP_STR
8940 BGP_STR
8941 "Display routes matching the communities\n"
8942 "community number\n"
8943 "Do not send outside local AS (well-known community)\n"
8944 "Do not advertise to any peer (well-known community)\n"
8945 "Do not export to next AS (well-known community)\n"
8946 "community number\n"
8947 "Do not send outside local AS (well-known community)\n"
8948 "Do not advertise to any peer (well-known community)\n"
8949 "Do not export to next AS (well-known community)\n"
8950 "community number\n"
8951 "Do not send outside local AS (well-known community)\n"
8952 "Do not advertise to any peer (well-known community)\n"
8953 "Do not export to next AS (well-known community)\n"
8954 "community number\n"
8955 "Do not send outside local AS (well-known community)\n"
8956 "Do not advertise to any peer (well-known community)\n"
8957 "Do not export to next AS (well-known community)\n")
8958
8959DEFUN (show_ip_bgp_ipv4_community,
8960 show_ip_bgp_ipv4_community_cmd,
8961 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
8962 SHOW_STR
8963 IP_STR
8964 BGP_STR
8965 "Address family\n"
8966 "Address Family modifier\n"
8967 "Address Family modifier\n"
8968 "Display routes matching the communities\n"
8969 "community number\n"
8970 "Do not send outside local AS (well-known community)\n"
8971 "Do not advertise to any peer (well-known community)\n"
8972 "Do not export to next AS (well-known community)\n")
8973{
8974 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 8975 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
718e3744 8976
95cbbd2a 8977 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 8978}
8979
8980ALIAS (show_ip_bgp_ipv4_community,
8981 show_ip_bgp_ipv4_community2_cmd,
8982 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8983 SHOW_STR
8984 IP_STR
8985 BGP_STR
8986 "Address family\n"
8987 "Address Family modifier\n"
8988 "Address Family modifier\n"
8989 "Display routes matching the communities\n"
8990 "community number\n"
8991 "Do not send outside local AS (well-known community)\n"
8992 "Do not advertise to any peer (well-known community)\n"
8993 "Do not export to next AS (well-known community)\n"
8994 "community number\n"
8995 "Do not send outside local AS (well-known community)\n"
8996 "Do not advertise to any peer (well-known community)\n"
8997 "Do not export to next AS (well-known community)\n")
8998
8999ALIAS (show_ip_bgp_ipv4_community,
9000 show_ip_bgp_ipv4_community3_cmd,
9001 "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)",
9002 SHOW_STR
9003 IP_STR
9004 BGP_STR
9005 "Address family\n"
9006 "Address Family modifier\n"
9007 "Address Family modifier\n"
9008 "Display routes matching the communities\n"
9009 "community number\n"
9010 "Do not send outside local AS (well-known community)\n"
9011 "Do not advertise to any peer (well-known community)\n"
9012 "Do not export to next AS (well-known community)\n"
9013 "community number\n"
9014 "Do not send outside local AS (well-known community)\n"
9015 "Do not advertise to any peer (well-known community)\n"
9016 "Do not export to next AS (well-known community)\n"
9017 "community number\n"
9018 "Do not send outside local AS (well-known community)\n"
9019 "Do not advertise to any peer (well-known community)\n"
9020 "Do not export to next AS (well-known community)\n")
9021
9022ALIAS (show_ip_bgp_ipv4_community,
9023 show_ip_bgp_ipv4_community4_cmd,
9024 "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)",
9025 SHOW_STR
9026 IP_STR
9027 BGP_STR
9028 "Address family\n"
9029 "Address Family modifier\n"
9030 "Address Family modifier\n"
9031 "Display routes matching the communities\n"
9032 "community number\n"
9033 "Do not send outside local AS (well-known community)\n"
9034 "Do not advertise to any peer (well-known community)\n"
9035 "Do not export to next AS (well-known community)\n"
9036 "community number\n"
9037 "Do not send outside local AS (well-known community)\n"
9038 "Do not advertise to any peer (well-known community)\n"
9039 "Do not export to next AS (well-known community)\n"
9040 "community number\n"
9041 "Do not send outside local AS (well-known community)\n"
9042 "Do not advertise to any peer (well-known community)\n"
9043 "Do not export to next AS (well-known community)\n"
9044 "community number\n"
9045 "Do not send outside local AS (well-known community)\n"
9046 "Do not advertise to any peer (well-known community)\n"
9047 "Do not export to next AS (well-known community)\n")
9048
95cbbd2a
ML
9049DEFUN (show_bgp_view_afi_safi_community_all,
9050 show_bgp_view_afi_safi_community_all_cmd,
9051#ifdef HAVE_IPV6
9052 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
9053#else
9054 "show bgp view WORD ipv4 (unicast|multicast) community",
9055#endif
9056 SHOW_STR
9057 BGP_STR
9058 "BGP view\n"
2b00515a 9059 "View name\n"
95cbbd2a
ML
9060 "Address family\n"
9061#ifdef HAVE_IPV6
9062 "Address family\n"
9063#endif
9064 "Address Family modifier\n"
9065 "Address Family modifier\n"
2b00515a 9066 "Display routes matching the communities\n")
95cbbd2a
ML
9067{
9068 int afi;
9069 int safi;
9070 struct bgp *bgp;
9071
9072 /* BGP structure lookup. */
9073 bgp = bgp_lookup_by_name (argv[0]);
9074 if (bgp == NULL)
9075 {
9076 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9077 return CMD_WARNING;
9078 }
9079
9080#ifdef HAVE_IPV6
9081 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9082 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9083#else
9084 afi = AFI_IP;
9085 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9086#endif
b05a1c8b 9087 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
95cbbd2a
ML
9088}
9089
9090DEFUN (show_bgp_view_afi_safi_community,
9091 show_bgp_view_afi_safi_community_cmd,
9092#ifdef HAVE_IPV6
9093 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9094#else
9095 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9096#endif
9097 SHOW_STR
9098 BGP_STR
9099 "BGP view\n"
2b00515a 9100 "View name\n"
95cbbd2a
ML
9101 "Address family\n"
9102#ifdef HAVE_IPV6
9103 "Address family\n"
9104#endif
9105 "Address family modifier\n"
9106 "Address family modifier\n"
9107 "Display routes matching the communities\n"
9108 "community number\n"
9109 "Do not send outside local AS (well-known community)\n"
9110 "Do not advertise to any peer (well-known community)\n"
9111 "Do not export to next AS (well-known community)\n")
9112{
9113 int afi;
9114 int safi;
9115
9116#ifdef HAVE_IPV6
9117 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9118 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9119 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
9120#else
9121 afi = AFI_IP;
9122 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9123 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
9124#endif
9125}
9126
9127ALIAS (show_bgp_view_afi_safi_community,
9128 show_bgp_view_afi_safi_community2_cmd,
9129#ifdef HAVE_IPV6
9130 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9131#else
9132 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9133#endif
9134 SHOW_STR
9135 BGP_STR
9136 "BGP view\n"
2b00515a 9137 "View name\n"
95cbbd2a
ML
9138 "Address family\n"
9139#ifdef HAVE_IPV6
9140 "Address family\n"
9141#endif
9142 "Address family modifier\n"
9143 "Address family modifier\n"
9144 "Display routes matching the communities\n"
9145 "community number\n"
9146 "Do not send outside local AS (well-known community)\n"
9147 "Do not advertise to any peer (well-known community)\n"
9148 "Do not export to next AS (well-known community)\n"
9149 "community number\n"
9150 "Do not send outside local AS (well-known community)\n"
9151 "Do not advertise to any peer (well-known community)\n"
9152 "Do not export to next AS (well-known community)\n")
9153
9154ALIAS (show_bgp_view_afi_safi_community,
9155 show_bgp_view_afi_safi_community3_cmd,
9156#ifdef HAVE_IPV6
9157 "show bgp view WORD (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)",
9158#else
9159 "show bgp view WORD 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)",
9160#endif
9161 SHOW_STR
9162 BGP_STR
9163 "BGP view\n"
2b00515a 9164 "View name\n"
95cbbd2a
ML
9165 "Address family\n"
9166#ifdef HAVE_IPV6
9167 "Address family\n"
9168#endif
9169 "Address family modifier\n"
9170 "Address family modifier\n"
9171 "Display routes matching the communities\n"
9172 "community number\n"
9173 "Do not send outside local AS (well-known community)\n"
9174 "Do not advertise to any peer (well-known community)\n"
9175 "Do not export to next AS (well-known community)\n"
9176 "community number\n"
9177 "Do not send outside local AS (well-known community)\n"
9178 "Do not advertise to any peer (well-known community)\n"
9179 "Do not export to next AS (well-known community)\n"
9180 "community number\n"
9181 "Do not send outside local AS (well-known community)\n"
9182 "Do not advertise to any peer (well-known community)\n"
9183 "Do not export to next AS (well-known community)\n")
9184
9185ALIAS (show_bgp_view_afi_safi_community,
9186 show_bgp_view_afi_safi_community4_cmd,
9187#ifdef HAVE_IPV6
9188 "show bgp view WORD (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)",
9189#else
9190 "show bgp view WORD 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)",
9191#endif
9192 SHOW_STR
9193 BGP_STR
9194 "BGP view\n"
2b00515a 9195 "View name\n"
95cbbd2a
ML
9196 "Address family\n"
9197#ifdef HAVE_IPV6
9198 "Address family\n"
9199#endif
9200 "Address family modifier\n"
9201 "Address family modifier\n"
9202 "Display routes matching the communities\n"
9203 "community number\n"
9204 "Do not send outside local AS (well-known community)\n"
9205 "Do not advertise to any peer (well-known community)\n"
9206 "Do not export to next AS (well-known community)\n"
9207 "community number\n"
9208 "Do not send outside local AS (well-known community)\n"
9209 "Do not advertise to any peer (well-known community)\n"
9210 "Do not export to next AS (well-known community)\n"
9211 "community number\n"
9212 "Do not send outside local AS (well-known community)\n"
9213 "Do not advertise to any peer (well-known community)\n"
9214 "Do not export to next AS (well-known community)\n"
9215 "community number\n"
9216 "Do not send outside local AS (well-known community)\n"
9217 "Do not advertise to any peer (well-known community)\n"
9218 "Do not export to next AS (well-known community)\n")
9219
718e3744 9220DEFUN (show_ip_bgp_community_exact,
9221 show_ip_bgp_community_exact_cmd,
9222 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9223 SHOW_STR
9224 IP_STR
9225 BGP_STR
9226 "Display routes matching the communities\n"
9227 "community number\n"
9228 "Do not send outside local AS (well-known community)\n"
9229 "Do not advertise to any peer (well-known community)\n"
9230 "Do not export to next AS (well-known community)\n"
9231 "Exact match of the communities")
9232{
95cbbd2a 9233 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 9234}
9235
9236ALIAS (show_ip_bgp_community_exact,
9237 show_ip_bgp_community2_exact_cmd,
9238 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9239 SHOW_STR
9240 IP_STR
9241 BGP_STR
9242 "Display routes matching the communities\n"
9243 "community number\n"
9244 "Do not send outside local AS (well-known community)\n"
9245 "Do not advertise to any peer (well-known community)\n"
9246 "Do not export to next AS (well-known community)\n"
9247 "community number\n"
9248 "Do not send outside local AS (well-known community)\n"
9249 "Do not advertise to any peer (well-known community)\n"
9250 "Do not export to next AS (well-known community)\n"
9251 "Exact match of the communities")
9252
9253ALIAS (show_ip_bgp_community_exact,
9254 show_ip_bgp_community3_exact_cmd,
9255 "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",
9256 SHOW_STR
9257 IP_STR
9258 BGP_STR
9259 "Display routes matching the communities\n"
9260 "community number\n"
9261 "Do not send outside local AS (well-known community)\n"
9262 "Do not advertise to any peer (well-known community)\n"
9263 "Do not export to next AS (well-known community)\n"
9264 "community number\n"
9265 "Do not send outside local AS (well-known community)\n"
9266 "Do not advertise to any peer (well-known community)\n"
9267 "Do not export to next AS (well-known community)\n"
9268 "community number\n"
9269 "Do not send outside local AS (well-known community)\n"
9270 "Do not advertise to any peer (well-known community)\n"
9271 "Do not export to next AS (well-known community)\n"
9272 "Exact match of the communities")
9273
9274ALIAS (show_ip_bgp_community_exact,
9275 show_ip_bgp_community4_exact_cmd,
9276 "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",
9277 SHOW_STR
9278 IP_STR
9279 BGP_STR
9280 "Display routes matching the communities\n"
9281 "community number\n"
9282 "Do not send outside local AS (well-known community)\n"
9283 "Do not advertise to any peer (well-known community)\n"
9284 "Do not export to next AS (well-known community)\n"
9285 "community number\n"
9286 "Do not send outside local AS (well-known community)\n"
9287 "Do not advertise to any peer (well-known community)\n"
9288 "Do not export to next AS (well-known community)\n"
9289 "community number\n"
9290 "Do not send outside local AS (well-known community)\n"
9291 "Do not advertise to any peer (well-known community)\n"
9292 "Do not export to next AS (well-known community)\n"
9293 "community number\n"
9294 "Do not send outside local AS (well-known community)\n"
9295 "Do not advertise to any peer (well-known community)\n"
9296 "Do not export to next AS (well-known community)\n"
9297 "Exact match of the communities")
9298
9299DEFUN (show_ip_bgp_ipv4_community_exact,
9300 show_ip_bgp_ipv4_community_exact_cmd,
9301 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9302 SHOW_STR
9303 IP_STR
9304 BGP_STR
9305 "Address family\n"
9306 "Address Family modifier\n"
9307 "Address Family modifier\n"
9308 "Display routes matching the communities\n"
9309 "community number\n"
9310 "Do not send outside local AS (well-known community)\n"
9311 "Do not advertise to any peer (well-known community)\n"
9312 "Do not export to next AS (well-known community)\n"
9313 "Exact match of the communities")
9314{
9315 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 9316 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
718e3744 9317
95cbbd2a 9318 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 9319}
9320
9321ALIAS (show_ip_bgp_ipv4_community_exact,
9322 show_ip_bgp_ipv4_community2_exact_cmd,
9323 "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",
9324 SHOW_STR
9325 IP_STR
9326 BGP_STR
9327 "Address family\n"
9328 "Address Family modifier\n"
9329 "Address Family modifier\n"
9330 "Display routes matching the communities\n"
9331 "community number\n"
9332 "Do not send outside local AS (well-known community)\n"
9333 "Do not advertise to any peer (well-known community)\n"
9334 "Do not export to next AS (well-known community)\n"
9335 "community number\n"
9336 "Do not send outside local AS (well-known community)\n"
9337 "Do not advertise to any peer (well-known community)\n"
9338 "Do not export to next AS (well-known community)\n"
9339 "Exact match of the communities")
9340
9341ALIAS (show_ip_bgp_ipv4_community_exact,
9342 show_ip_bgp_ipv4_community3_exact_cmd,
9343 "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",
9344 SHOW_STR
9345 IP_STR
9346 BGP_STR
9347 "Address family\n"
9348 "Address Family modifier\n"
9349 "Address Family modifier\n"
9350 "Display routes matching the communities\n"
9351 "community number\n"
9352 "Do not send outside local AS (well-known community)\n"
9353 "Do not advertise to any peer (well-known community)\n"
9354 "Do not export to next AS (well-known community)\n"
9355 "community number\n"
9356 "Do not send outside local AS (well-known community)\n"
9357 "Do not advertise to any peer (well-known community)\n"
9358 "Do not export to next AS (well-known community)\n"
9359 "community number\n"
9360 "Do not send outside local AS (well-known community)\n"
9361 "Do not advertise to any peer (well-known community)\n"
9362 "Do not export to next AS (well-known community)\n"
9363 "Exact match of the communities")
9364
9365ALIAS (show_ip_bgp_ipv4_community_exact,
9366 show_ip_bgp_ipv4_community4_exact_cmd,
9367 "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",
9368 SHOW_STR
9369 IP_STR
9370 BGP_STR
9371 "Address family\n"
9372 "Address Family modifier\n"
9373 "Address Family modifier\n"
9374 "Display routes matching the communities\n"
9375 "community number\n"
9376 "Do not send outside local AS (well-known community)\n"
9377 "Do not advertise to any peer (well-known community)\n"
9378 "Do not export to next AS (well-known community)\n"
9379 "community number\n"
9380 "Do not send outside local AS (well-known community)\n"
9381 "Do not advertise to any peer (well-known community)\n"
9382 "Do not export to next AS (well-known community)\n"
9383 "community number\n"
9384 "Do not send outside local AS (well-known community)\n"
9385 "Do not advertise to any peer (well-known community)\n"
9386 "Do not export to next AS (well-known community)\n"
9387 "community number\n"
9388 "Do not send outside local AS (well-known community)\n"
9389 "Do not advertise to any peer (well-known community)\n"
9390 "Do not export to next AS (well-known community)\n"
9391 "Exact match of the communities")
9392
9393#ifdef HAVE_IPV6
9394DEFUN (show_bgp_community,
9395 show_bgp_community_cmd,
9396 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
9397 SHOW_STR
9398 BGP_STR
9399 "Display routes matching the communities\n"
9400 "community number\n"
9401 "Do not send outside local AS (well-known community)\n"
9402 "Do not advertise to any peer (well-known community)\n"
9403 "Do not export to next AS (well-known community)\n")
9404{
95cbbd2a 9405 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 9406}
9407
9408ALIAS (show_bgp_community,
9409 show_bgp_ipv6_community_cmd,
9410 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
9411 SHOW_STR
9412 BGP_STR
9413 "Address family\n"
9414 "Display routes matching the communities\n"
9415 "community number\n"
9416 "Do not send outside local AS (well-known community)\n"
9417 "Do not advertise to any peer (well-known community)\n"
9418 "Do not export to next AS (well-known community)\n")
9419
9420ALIAS (show_bgp_community,
9421 show_bgp_community2_cmd,
9422 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9423 SHOW_STR
9424 BGP_STR
9425 "Display routes matching the communities\n"
9426 "community number\n"
9427 "Do not send outside local AS (well-known community)\n"
9428 "Do not advertise to any peer (well-known community)\n"
9429 "Do not export to next AS (well-known community)\n"
9430 "community number\n"
9431 "Do not send outside local AS (well-known community)\n"
9432 "Do not advertise to any peer (well-known community)\n"
9433 "Do not export to next AS (well-known community)\n")
9434
9435ALIAS (show_bgp_community,
9436 show_bgp_ipv6_community2_cmd,
9437 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9438 SHOW_STR
9439 BGP_STR
9440 "Address family\n"
9441 "Display routes matching the communities\n"
9442 "community number\n"
9443 "Do not send outside local AS (well-known community)\n"
9444 "Do not advertise to any peer (well-known community)\n"
9445 "Do not export to next AS (well-known community)\n"
9446 "community number\n"
9447 "Do not send outside local AS (well-known community)\n"
9448 "Do not advertise to any peer (well-known community)\n"
9449 "Do not export to next AS (well-known community)\n")
9450
9451ALIAS (show_bgp_community,
9452 show_bgp_community3_cmd,
9453 "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)",
9454 SHOW_STR
9455 BGP_STR
9456 "Display routes matching the communities\n"
9457 "community number\n"
9458 "Do not send outside local AS (well-known community)\n"
9459 "Do not advertise to any peer (well-known community)\n"
9460 "Do not export to next AS (well-known community)\n"
9461 "community number\n"
9462 "Do not send outside local AS (well-known community)\n"
9463 "Do not advertise to any peer (well-known community)\n"
9464 "Do not export to next AS (well-known community)\n"
9465 "community number\n"
9466 "Do not send outside local AS (well-known community)\n"
9467 "Do not advertise to any peer (well-known community)\n"
9468 "Do not export to next AS (well-known community)\n")
9469
9470ALIAS (show_bgp_community,
9471 show_bgp_ipv6_community3_cmd,
9472 "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)",
9473 SHOW_STR
9474 BGP_STR
9475 "Address family\n"
9476 "Display routes matching the communities\n"
9477 "community number\n"
9478 "Do not send outside local AS (well-known community)\n"
9479 "Do not advertise to any peer (well-known community)\n"
9480 "Do not export to next AS (well-known community)\n"
9481 "community number\n"
9482 "Do not send outside local AS (well-known community)\n"
9483 "Do not advertise to any peer (well-known community)\n"
9484 "Do not export to next AS (well-known community)\n"
9485 "community number\n"
9486 "Do not send outside local AS (well-known community)\n"
9487 "Do not advertise to any peer (well-known community)\n"
9488 "Do not export to next AS (well-known community)\n")
9489
9490ALIAS (show_bgp_community,
9491 show_bgp_community4_cmd,
9492 "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)",
9493 SHOW_STR
9494 BGP_STR
9495 "Display routes matching the communities\n"
9496 "community number\n"
9497 "Do not send outside local AS (well-known community)\n"
9498 "Do not advertise to any peer (well-known community)\n"
9499 "Do not export to next AS (well-known community)\n"
9500 "community number\n"
9501 "Do not send outside local AS (well-known community)\n"
9502 "Do not advertise to any peer (well-known community)\n"
9503 "Do not export to next AS (well-known community)\n"
9504 "community number\n"
9505 "Do not send outside local AS (well-known community)\n"
9506 "Do not advertise to any peer (well-known community)\n"
9507 "Do not export to next AS (well-known community)\n"
9508 "community number\n"
9509 "Do not send outside local AS (well-known community)\n"
9510 "Do not advertise to any peer (well-known community)\n"
9511 "Do not export to next AS (well-known community)\n")
9512
9513ALIAS (show_bgp_community,
9514 show_bgp_ipv6_community4_cmd,
9515 "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)",
9516 SHOW_STR
9517 BGP_STR
9518 "Address family\n"
9519 "Display routes matching the communities\n"
9520 "community number\n"
9521 "Do not send outside local AS (well-known community)\n"
9522 "Do not advertise to any peer (well-known community)\n"
9523 "Do not export to next AS (well-known community)\n"
9524 "community number\n"
9525 "Do not send outside local AS (well-known community)\n"
9526 "Do not advertise to any peer (well-known community)\n"
9527 "Do not export to next AS (well-known community)\n"
9528 "community number\n"
9529 "Do not send outside local AS (well-known community)\n"
9530 "Do not advertise to any peer (well-known community)\n"
9531 "Do not export to next AS (well-known community)\n"
9532 "community number\n"
9533 "Do not send outside local AS (well-known community)\n"
9534 "Do not advertise to any peer (well-known community)\n"
9535 "Do not export to next AS (well-known community)\n")
9536
9537/* old command */
9538DEFUN (show_ipv6_bgp_community,
9539 show_ipv6_bgp_community_cmd,
9540 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
9541 SHOW_STR
9542 IPV6_STR
9543 BGP_STR
9544 "Display routes matching the communities\n"
9545 "community number\n"
9546 "Do not send outside local AS (well-known community)\n"
9547 "Do not advertise to any peer (well-known community)\n"
9548 "Do not export to next AS (well-known community)\n")
9549{
47e9b292 9550 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 9551 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 9552}
9553
9554/* old command */
9555ALIAS (show_ipv6_bgp_community,
9556 show_ipv6_bgp_community2_cmd,
9557 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9558 SHOW_STR
9559 IPV6_STR
9560 BGP_STR
9561 "Display routes matching the communities\n"
9562 "community number\n"
9563 "Do not send outside local AS (well-known community)\n"
9564 "Do not advertise to any peer (well-known community)\n"
9565 "Do not export to next AS (well-known community)\n"
9566 "community number\n"
9567 "Do not send outside local AS (well-known community)\n"
9568 "Do not advertise to any peer (well-known community)\n"
9569 "Do not export to next AS (well-known community)\n")
9570
9571/* old command */
9572ALIAS (show_ipv6_bgp_community,
9573 show_ipv6_bgp_community3_cmd,
9574 "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)",
9575 SHOW_STR
9576 IPV6_STR
9577 BGP_STR
9578 "Display routes matching the communities\n"
9579 "community number\n"
9580 "Do not send outside local AS (well-known community)\n"
9581 "Do not advertise to any peer (well-known community)\n"
9582 "Do not export to next AS (well-known community)\n"
9583 "community number\n"
9584 "Do not send outside local AS (well-known community)\n"
9585 "Do not advertise to any peer (well-known community)\n"
9586 "Do not export to next AS (well-known community)\n"
9587 "community number\n"
9588 "Do not send outside local AS (well-known community)\n"
9589 "Do not advertise to any peer (well-known community)\n"
9590 "Do not export to next AS (well-known community)\n")
9591
9592/* old command */
9593ALIAS (show_ipv6_bgp_community,
9594 show_ipv6_bgp_community4_cmd,
9595 "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)",
9596 SHOW_STR
9597 IPV6_STR
9598 BGP_STR
9599 "Display routes matching the communities\n"
9600 "community number\n"
9601 "Do not send outside local AS (well-known community)\n"
9602 "Do not advertise to any peer (well-known community)\n"
9603 "Do not export to next AS (well-known community)\n"
9604 "community number\n"
9605 "Do not send outside local AS (well-known community)\n"
9606 "Do not advertise to any peer (well-known community)\n"
9607 "Do not export to next AS (well-known community)\n"
9608 "community number\n"
9609 "Do not send outside local AS (well-known community)\n"
9610 "Do not advertise to any peer (well-known community)\n"
9611 "Do not export to next AS (well-known community)\n"
9612 "community number\n"
9613 "Do not send outside local AS (well-known community)\n"
9614 "Do not advertise to any peer (well-known community)\n"
9615 "Do not export to next AS (well-known community)\n")
9616
9617DEFUN (show_bgp_community_exact,
9618 show_bgp_community_exact_cmd,
9619 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9620 SHOW_STR
9621 BGP_STR
9622 "Display routes matching the communities\n"
9623 "community number\n"
9624 "Do not send outside local AS (well-known community)\n"
9625 "Do not advertise to any peer (well-known community)\n"
9626 "Do not export to next AS (well-known community)\n"
9627 "Exact match of the communities")
9628{
95cbbd2a 9629 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 9630}
9631
9632ALIAS (show_bgp_community_exact,
9633 show_bgp_ipv6_community_exact_cmd,
9634 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9635 SHOW_STR
9636 BGP_STR
9637 "Address family\n"
9638 "Display routes matching the communities\n"
9639 "community number\n"
9640 "Do not send outside local AS (well-known community)\n"
9641 "Do not advertise to any peer (well-known community)\n"
9642 "Do not export to next AS (well-known community)\n"
9643 "Exact match of the communities")
9644
9645ALIAS (show_bgp_community_exact,
9646 show_bgp_community2_exact_cmd,
9647 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9648 SHOW_STR
9649 BGP_STR
9650 "Display routes matching the communities\n"
9651 "community number\n"
9652 "Do not send outside local AS (well-known community)\n"
9653 "Do not advertise to any peer (well-known community)\n"
9654 "Do not export to next AS (well-known community)\n"
9655 "community number\n"
9656 "Do not send outside local AS (well-known community)\n"
9657 "Do not advertise to any peer (well-known community)\n"
9658 "Do not export to next AS (well-known community)\n"
9659 "Exact match of the communities")
9660
9661ALIAS (show_bgp_community_exact,
9662 show_bgp_ipv6_community2_exact_cmd,
9663 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9664 SHOW_STR
9665 BGP_STR
9666 "Address family\n"
9667 "Display routes matching the communities\n"
9668 "community number\n"
9669 "Do not send outside local AS (well-known community)\n"
9670 "Do not advertise to any peer (well-known community)\n"
9671 "Do not export to next AS (well-known community)\n"
9672 "community number\n"
9673 "Do not send outside local AS (well-known community)\n"
9674 "Do not advertise to any peer (well-known community)\n"
9675 "Do not export to next AS (well-known community)\n"
9676 "Exact match of the communities")
9677
9678ALIAS (show_bgp_community_exact,
9679 show_bgp_community3_exact_cmd,
9680 "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",
9681 SHOW_STR
9682 BGP_STR
9683 "Display routes matching the communities\n"
9684 "community number\n"
9685 "Do not send outside local AS (well-known community)\n"
9686 "Do not advertise to any peer (well-known community)\n"
9687 "Do not export to next AS (well-known community)\n"
9688 "community number\n"
9689 "Do not send outside local AS (well-known community)\n"
9690 "Do not advertise to any peer (well-known community)\n"
9691 "Do not export to next AS (well-known community)\n"
9692 "community number\n"
9693 "Do not send outside local AS (well-known community)\n"
9694 "Do not advertise to any peer (well-known community)\n"
9695 "Do not export to next AS (well-known community)\n"
9696 "Exact match of the communities")
9697
9698ALIAS (show_bgp_community_exact,
9699 show_bgp_ipv6_community3_exact_cmd,
9700 "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",
9701 SHOW_STR
9702 BGP_STR
9703 "Address family\n"
9704 "Display routes matching the communities\n"
9705 "community number\n"
9706 "Do not send outside local AS (well-known community)\n"
9707 "Do not advertise to any peer (well-known community)\n"
9708 "Do not export to next AS (well-known community)\n"
9709 "community number\n"
9710 "Do not send outside local AS (well-known community)\n"
9711 "Do not advertise to any peer (well-known community)\n"
9712 "Do not export to next AS (well-known community)\n"
9713 "community number\n"
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 "Exact match of the communities")
9718
9719ALIAS (show_bgp_community_exact,
9720 show_bgp_community4_exact_cmd,
9721 "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",
9722 SHOW_STR
9723 BGP_STR
9724 "Display routes matching the communities\n"
9725 "community number\n"
9726 "Do not send outside local AS (well-known community)\n"
9727 "Do not advertise to any peer (well-known community)\n"
9728 "Do not export to next AS (well-known community)\n"
9729 "community number\n"
9730 "Do not send outside local AS (well-known community)\n"
9731 "Do not advertise to any peer (well-known community)\n"
9732 "Do not export to next AS (well-known community)\n"
9733 "community number\n"
9734 "Do not send outside local AS (well-known community)\n"
9735 "Do not advertise to any peer (well-known community)\n"
9736 "Do not export to next AS (well-known community)\n"
9737 "community number\n"
9738 "Do not send outside local AS (well-known community)\n"
9739 "Do not advertise to any peer (well-known community)\n"
9740 "Do not export to next AS (well-known community)\n"
9741 "Exact match of the communities")
9742
9743ALIAS (show_bgp_community_exact,
9744 show_bgp_ipv6_community4_exact_cmd,
9745 "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",
9746 SHOW_STR
9747 BGP_STR
9748 "Address family\n"
9749 "Display routes matching the communities\n"
9750 "community number\n"
9751 "Do not send outside local AS (well-known community)\n"
9752 "Do not advertise to any peer (well-known community)\n"
9753 "Do not export to next AS (well-known community)\n"
9754 "community number\n"
9755 "Do not send outside local AS (well-known community)\n"
9756 "Do not advertise to any peer (well-known community)\n"
9757 "Do not export to next AS (well-known community)\n"
9758 "community number\n"
9759 "Do not send outside local AS (well-known community)\n"
9760 "Do not advertise to any peer (well-known community)\n"
9761 "Do not export to next AS (well-known community)\n"
9762 "community number\n"
9763 "Do not send outside local AS (well-known community)\n"
9764 "Do not advertise to any peer (well-known community)\n"
9765 "Do not export to next AS (well-known community)\n"
9766 "Exact match of the communities")
9767
9768/* old command */
9769DEFUN (show_ipv6_bgp_community_exact,
9770 show_ipv6_bgp_community_exact_cmd,
9771 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9772 SHOW_STR
9773 IPV6_STR
9774 BGP_STR
9775 "Display routes matching the communities\n"
9776 "community number\n"
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"
9780 "Exact match of the communities")
9781{
47e9b292 9782 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 9783 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 9784}
9785
9786/* old command */
9787ALIAS (show_ipv6_bgp_community_exact,
9788 show_ipv6_bgp_community2_exact_cmd,
9789 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9790 SHOW_STR
9791 IPV6_STR
9792 BGP_STR
9793 "Display routes matching the communities\n"
9794 "community number\n"
9795 "Do not send outside local AS (well-known community)\n"
9796 "Do not advertise to any peer (well-known community)\n"
9797 "Do not export to next AS (well-known community)\n"
9798 "community number\n"
9799 "Do not send outside local AS (well-known community)\n"
9800 "Do not advertise to any peer (well-known community)\n"
9801 "Do not export to next AS (well-known community)\n"
9802 "Exact match of the communities")
9803
9804/* old command */
9805ALIAS (show_ipv6_bgp_community_exact,
9806 show_ipv6_bgp_community3_exact_cmd,
9807 "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",
9808 SHOW_STR
9809 IPV6_STR
9810 BGP_STR
9811 "Display routes matching the communities\n"
9812 "community number\n"
9813 "Do not send outside local AS (well-known community)\n"
9814 "Do not advertise to any peer (well-known community)\n"
9815 "Do not export to next AS (well-known community)\n"
9816 "community number\n"
9817 "Do not send outside local AS (well-known community)\n"
9818 "Do not advertise to any peer (well-known community)\n"
9819 "Do not export to next AS (well-known community)\n"
9820 "community number\n"
9821 "Do not send outside local AS (well-known community)\n"
9822 "Do not advertise to any peer (well-known community)\n"
9823 "Do not export to next AS (well-known community)\n"
9824 "Exact match of the communities")
9825
9826/* old command */
9827ALIAS (show_ipv6_bgp_community_exact,
9828 show_ipv6_bgp_community4_exact_cmd,
9829 "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",
9830 SHOW_STR
9831 IPV6_STR
9832 BGP_STR
9833 "Display routes matching the communities\n"
9834 "community number\n"
9835 "Do not send outside local AS (well-known community)\n"
9836 "Do not advertise to any peer (well-known community)\n"
9837 "Do not export to next AS (well-known community)\n"
9838 "community number\n"
9839 "Do not send outside local AS (well-known community)\n"
9840 "Do not advertise to any peer (well-known community)\n"
9841 "Do not export to next AS (well-known community)\n"
9842 "community number\n"
9843 "Do not send outside local AS (well-known community)\n"
9844 "Do not advertise to any peer (well-known community)\n"
9845 "Do not export to next AS (well-known community)\n"
9846 "community number\n"
9847 "Do not send outside local AS (well-known community)\n"
9848 "Do not advertise to any peer (well-known community)\n"
9849 "Do not export to next AS (well-known community)\n"
9850 "Exact match of the communities")
9851
9852/* old command */
9853DEFUN (show_ipv6_mbgp_community,
9854 show_ipv6_mbgp_community_cmd,
9855 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
9856 SHOW_STR
9857 IPV6_STR
9858 MBGP_STR
9859 "Display routes matching the communities\n"
9860 "community number\n"
9861 "Do not send outside local AS (well-known community)\n"
9862 "Do not advertise to any peer (well-known community)\n"
9863 "Do not export to next AS (well-known community)\n")
9864{
47e9b292 9865 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 9866 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
718e3744 9867}
9868
9869/* old command */
9870ALIAS (show_ipv6_mbgp_community,
9871 show_ipv6_mbgp_community2_cmd,
9872 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9873 SHOW_STR
9874 IPV6_STR
9875 MBGP_STR
9876 "Display routes matching the communities\n"
9877 "community number\n"
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"
9881 "community number\n"
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")
9885
9886/* old command */
9887ALIAS (show_ipv6_mbgp_community,
9888 show_ipv6_mbgp_community3_cmd,
9889 "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)",
9890 SHOW_STR
9891 IPV6_STR
9892 MBGP_STR
9893 "Display routes matching the communities\n"
9894 "community number\n"
9895 "Do not send outside local AS (well-known community)\n"
9896 "Do not advertise to any peer (well-known community)\n"
9897 "Do not export to next AS (well-known community)\n"
9898 "community number\n"
9899 "Do not send outside local AS (well-known community)\n"
9900 "Do not advertise to any peer (well-known community)\n"
9901 "Do not export to next AS (well-known community)\n"
9902 "community number\n"
9903 "Do not send outside local AS (well-known community)\n"
9904 "Do not advertise to any peer (well-known community)\n"
9905 "Do not export to next AS (well-known community)\n")
9906
9907/* old command */
9908ALIAS (show_ipv6_mbgp_community,
9909 show_ipv6_mbgp_community4_cmd,
9910 "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)",
9911 SHOW_STR
9912 IPV6_STR
9913 MBGP_STR
9914 "Display routes matching the communities\n"
9915 "community number\n"
9916 "Do not send outside local AS (well-known community)\n"
9917 "Do not advertise to any peer (well-known community)\n"
9918 "Do not export to next AS (well-known community)\n"
9919 "community number\n"
9920 "Do not send outside local AS (well-known community)\n"
9921 "Do not advertise to any peer (well-known community)\n"
9922 "Do not export to next AS (well-known community)\n"
9923 "community number\n"
9924 "Do not send outside local AS (well-known community)\n"
9925 "Do not advertise to any peer (well-known community)\n"
9926 "Do not export to next AS (well-known community)\n"
9927 "community number\n"
9928 "Do not send outside local AS (well-known community)\n"
9929 "Do not advertise to any peer (well-known community)\n"
9930 "Do not export to next AS (well-known community)\n")
9931
9932/* old command */
9933DEFUN (show_ipv6_mbgp_community_exact,
9934 show_ipv6_mbgp_community_exact_cmd,
9935 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9936 SHOW_STR
9937 IPV6_STR
9938 MBGP_STR
9939 "Display routes matching the communities\n"
9940 "community number\n"
9941 "Do not send outside local AS (well-known community)\n"
9942 "Do not advertise to any peer (well-known community)\n"
9943 "Do not export to next AS (well-known community)\n"
9944 "Exact match of the communities")
9945{
47e9b292 9946 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 9947 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
718e3744 9948}
9949
9950/* old command */
9951ALIAS (show_ipv6_mbgp_community_exact,
9952 show_ipv6_mbgp_community2_exact_cmd,
9953 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9954 SHOW_STR
9955 IPV6_STR
9956 MBGP_STR
9957 "Display routes matching the communities\n"
9958 "community number\n"
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"
9962 "community number\n"
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"
9966 "Exact match of the communities")
9967
9968/* old command */
9969ALIAS (show_ipv6_mbgp_community_exact,
9970 show_ipv6_mbgp_community3_exact_cmd,
9971 "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",
9972 SHOW_STR
9973 IPV6_STR
9974 MBGP_STR
9975 "Display routes matching the communities\n"
9976 "community number\n"
9977 "Do not send outside local AS (well-known community)\n"
9978 "Do not advertise to any peer (well-known community)\n"
9979 "Do not export to next AS (well-known community)\n"
9980 "community number\n"
9981 "Do not send outside local AS (well-known community)\n"
9982 "Do not advertise to any peer (well-known community)\n"
9983 "Do not export to next AS (well-known community)\n"
9984 "community number\n"
9985 "Do not send outside local AS (well-known community)\n"
9986 "Do not advertise to any peer (well-known community)\n"
9987 "Do not export to next AS (well-known community)\n"
9988 "Exact match of the communities")
9989
9990/* old command */
9991ALIAS (show_ipv6_mbgp_community_exact,
9992 show_ipv6_mbgp_community4_exact_cmd,
9993 "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",
9994 SHOW_STR
9995 IPV6_STR
9996 MBGP_STR
9997 "Display routes matching the communities\n"
9998 "community number\n"
9999 "Do not send outside local AS (well-known community)\n"
10000 "Do not advertise to any peer (well-known community)\n"
10001 "Do not export to next AS (well-known community)\n"
10002 "community number\n"
10003 "Do not send outside local AS (well-known community)\n"
10004 "Do not advertise to any peer (well-known community)\n"
10005 "Do not export to next AS (well-known community)\n"
10006 "community number\n"
10007 "Do not send outside local AS (well-known community)\n"
10008 "Do not advertise to any peer (well-known community)\n"
10009 "Do not export to next AS (well-known community)\n"
10010 "community number\n"
10011 "Do not send outside local AS (well-known community)\n"
10012 "Do not advertise to any peer (well-known community)\n"
10013 "Do not export to next AS (well-known community)\n"
10014 "Exact match of the communities")
10015#endif /* HAVE_IPV6 */
6b0655a2 10016
94f2b392 10017static int
fd79ac91 10018bgp_show_community_list (struct vty *vty, const char *com, int exact,
4c9641ba 10019 afi_t afi, safi_t safi)
718e3744 10020{
10021 struct community_list *list;
10022
fee6e4e4 10023 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
718e3744 10024 if (list == NULL)
10025 {
10026 vty_out (vty, "%% %s is not a valid community-list name%s", com,
10027 VTY_NEWLINE);
10028 return CMD_WARNING;
10029 }
10030
5a646650 10031 return bgp_show (vty, NULL, afi, safi,
10032 (exact ? bgp_show_type_community_list_exact :
b05a1c8b 10033 bgp_show_type_community_list), list, 0);
718e3744 10034}
10035
10036DEFUN (show_ip_bgp_community_list,
10037 show_ip_bgp_community_list_cmd,
fee6e4e4 10038 "show ip bgp community-list (<1-500>|WORD)",
718e3744 10039 SHOW_STR
10040 IP_STR
10041 BGP_STR
10042 "Display routes matching the community-list\n"
fee6e4e4 10043 "community-list number\n"
718e3744 10044 "community-list name\n")
10045{
10046 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
10047}
10048
10049DEFUN (show_ip_bgp_ipv4_community_list,
10050 show_ip_bgp_ipv4_community_list_cmd,
fee6e4e4 10051 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
718e3744 10052 SHOW_STR
10053 IP_STR
10054 BGP_STR
10055 "Address family\n"
10056 "Address Family modifier\n"
10057 "Address Family modifier\n"
10058 "Display routes matching the community-list\n"
fee6e4e4 10059 "community-list number\n"
718e3744 10060 "community-list name\n")
10061{
10062 if (strncmp (argv[0], "m", 1) == 0)
10063 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
10064
10065 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
10066}
10067
10068DEFUN (show_ip_bgp_community_list_exact,
10069 show_ip_bgp_community_list_exact_cmd,
fee6e4e4 10070 "show ip bgp community-list (<1-500>|WORD) exact-match",
718e3744 10071 SHOW_STR
10072 IP_STR
10073 BGP_STR
10074 "Display routes matching the community-list\n"
fee6e4e4 10075 "community-list number\n"
718e3744 10076 "community-list name\n"
10077 "Exact match of the communities\n")
10078{
10079 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
10080}
10081
10082DEFUN (show_ip_bgp_ipv4_community_list_exact,
10083 show_ip_bgp_ipv4_community_list_exact_cmd,
fee6e4e4 10084 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
718e3744 10085 SHOW_STR
10086 IP_STR
10087 BGP_STR
10088 "Address family\n"
10089 "Address Family modifier\n"
10090 "Address Family modifier\n"
10091 "Display routes matching the community-list\n"
fee6e4e4 10092 "community-list number\n"
718e3744 10093 "community-list name\n"
10094 "Exact match of the communities\n")
10095{
10096 if (strncmp (argv[0], "m", 1) == 0)
10097 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
10098
10099 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
10100}
10101
10102#ifdef HAVE_IPV6
10103DEFUN (show_bgp_community_list,
10104 show_bgp_community_list_cmd,
fee6e4e4 10105 "show bgp community-list (<1-500>|WORD)",
718e3744 10106 SHOW_STR
10107 BGP_STR
10108 "Display routes matching the community-list\n"
fee6e4e4 10109 "community-list number\n"
718e3744 10110 "community-list name\n")
10111{
10112 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10113}
10114
10115ALIAS (show_bgp_community_list,
10116 show_bgp_ipv6_community_list_cmd,
fee6e4e4 10117 "show bgp ipv6 community-list (<1-500>|WORD)",
718e3744 10118 SHOW_STR
10119 BGP_STR
10120 "Address family\n"
10121 "Display routes matching the community-list\n"
fee6e4e4 10122 "community-list number\n"
e8e1946e 10123 "community-list name\n")
718e3744 10124
10125/* old command */
10126DEFUN (show_ipv6_bgp_community_list,
10127 show_ipv6_bgp_community_list_cmd,
10128 "show ipv6 bgp community-list WORD",
10129 SHOW_STR
10130 IPV6_STR
10131 BGP_STR
10132 "Display routes matching the community-list\n"
10133 "community-list name\n")
10134{
47e9b292 10135 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 10136 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10137}
10138
10139/* old command */
10140DEFUN (show_ipv6_mbgp_community_list,
10141 show_ipv6_mbgp_community_list_cmd,
10142 "show ipv6 mbgp community-list WORD",
10143 SHOW_STR
10144 IPV6_STR
10145 MBGP_STR
10146 "Display routes matching the community-list\n"
10147 "community-list name\n")
10148{
47e9b292 10149 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 10150 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
10151}
10152
10153DEFUN (show_bgp_community_list_exact,
10154 show_bgp_community_list_exact_cmd,
fee6e4e4 10155 "show bgp community-list (<1-500>|WORD) exact-match",
718e3744 10156 SHOW_STR
10157 BGP_STR
10158 "Display routes matching the community-list\n"
fee6e4e4 10159 "community-list number\n"
718e3744 10160 "community-list name\n"
10161 "Exact match of the communities\n")
10162{
10163 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10164}
10165
10166ALIAS (show_bgp_community_list_exact,
10167 show_bgp_ipv6_community_list_exact_cmd,
fee6e4e4 10168 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
718e3744 10169 SHOW_STR
10170 BGP_STR
10171 "Address family\n"
10172 "Display routes matching the community-list\n"
fee6e4e4 10173 "community-list number\n"
718e3744 10174 "community-list name\n"
10175 "Exact match of the communities\n")
10176
10177/* old command */
10178DEFUN (show_ipv6_bgp_community_list_exact,
10179 show_ipv6_bgp_community_list_exact_cmd,
10180 "show ipv6 bgp community-list WORD exact-match",
10181 SHOW_STR
10182 IPV6_STR
10183 BGP_STR
10184 "Display routes matching the community-list\n"
10185 "community-list name\n"
10186 "Exact match of the communities\n")
10187{
47e9b292 10188 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 10189 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10190}
10191
10192/* old command */
10193DEFUN (show_ipv6_mbgp_community_list_exact,
10194 show_ipv6_mbgp_community_list_exact_cmd,
10195 "show ipv6 mbgp community-list WORD exact-match",
10196 SHOW_STR
10197 IPV6_STR
10198 MBGP_STR
10199 "Display routes matching the community-list\n"
10200 "community-list name\n"
10201 "Exact match of the communities\n")
10202{
47e9b292 10203 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 10204 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
10205}
10206#endif /* HAVE_IPV6 */
6b0655a2 10207
94f2b392 10208static int
fd79ac91 10209bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
718e3744 10210 safi_t safi, enum bgp_show_type type)
10211{
10212 int ret;
10213 struct prefix *p;
10214
10215 p = prefix_new();
10216
10217 ret = str2prefix (prefix, p);
10218 if (! ret)
10219 {
10220 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
10221 return CMD_WARNING;
10222 }
10223
b05a1c8b 10224 ret = bgp_show (vty, NULL, afi, safi, type, p, 0);
5a646650 10225 prefix_free(p);
10226 return ret;
718e3744 10227}
10228
10229DEFUN (show_ip_bgp_prefix_longer,
10230 show_ip_bgp_prefix_longer_cmd,
10231 "show ip bgp A.B.C.D/M longer-prefixes",
10232 SHOW_STR
10233 IP_STR
10234 BGP_STR
10235 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10236 "Display route and more specific routes\n")
10237{
10238 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
10239 bgp_show_type_prefix_longer);
10240}
10241
10242DEFUN (show_ip_bgp_flap_prefix_longer,
10243 show_ip_bgp_flap_prefix_longer_cmd,
10244 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
10245 SHOW_STR
10246 IP_STR
10247 BGP_STR
10248 "Display flap statistics of routes\n"
10249 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10250 "Display route and more specific routes\n")
10251{
10252 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
10253 bgp_show_type_flap_prefix_longer);
10254}
10255
10256DEFUN (show_ip_bgp_ipv4_prefix_longer,
10257 show_ip_bgp_ipv4_prefix_longer_cmd,
10258 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
10259 SHOW_STR
10260 IP_STR
10261 BGP_STR
10262 "Address family\n"
10263 "Address Family modifier\n"
10264 "Address Family modifier\n"
10265 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10266 "Display route and more specific routes\n")
10267{
10268 if (strncmp (argv[0], "m", 1) == 0)
10269 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
10270 bgp_show_type_prefix_longer);
10271
10272 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
10273 bgp_show_type_prefix_longer);
10274}
10275
10276DEFUN (show_ip_bgp_flap_address,
10277 show_ip_bgp_flap_address_cmd,
10278 "show ip bgp flap-statistics A.B.C.D",
10279 SHOW_STR
10280 IP_STR
10281 BGP_STR
10282 "Display flap statistics of routes\n"
10283 "Network in the BGP routing table to display\n")
10284{
10285 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
10286 bgp_show_type_flap_address);
10287}
10288
10289DEFUN (show_ip_bgp_flap_prefix,
10290 show_ip_bgp_flap_prefix_cmd,
10291 "show ip bgp flap-statistics A.B.C.D/M",
10292 SHOW_STR
10293 IP_STR
10294 BGP_STR
10295 "Display flap statistics of routes\n"
10296 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10297{
10298 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
10299 bgp_show_type_flap_prefix);
10300}
10301#ifdef HAVE_IPV6
10302DEFUN (show_bgp_prefix_longer,
10303 show_bgp_prefix_longer_cmd,
10304 "show bgp X:X::X:X/M longer-prefixes",
10305 SHOW_STR
10306 BGP_STR
10307 "IPv6 prefix <network>/<length>\n"
10308 "Display route and more specific routes\n")
10309{
10310 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
10311 bgp_show_type_prefix_longer);
10312}
10313
10314ALIAS (show_bgp_prefix_longer,
10315 show_bgp_ipv6_prefix_longer_cmd,
10316 "show bgp ipv6 X:X::X:X/M longer-prefixes",
10317 SHOW_STR
10318 BGP_STR
10319 "Address family\n"
10320 "IPv6 prefix <network>/<length>\n"
10321 "Display route and more specific routes\n")
10322
10323/* old command */
10324DEFUN (show_ipv6_bgp_prefix_longer,
10325 show_ipv6_bgp_prefix_longer_cmd,
10326 "show ipv6 bgp X:X::X:X/M longer-prefixes",
10327 SHOW_STR
10328 IPV6_STR
10329 BGP_STR
10330 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
10331 "Display route and more specific routes\n")
10332{
47e9b292 10333 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 10334 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
10335 bgp_show_type_prefix_longer);
10336}
10337
10338/* old command */
10339DEFUN (show_ipv6_mbgp_prefix_longer,
10340 show_ipv6_mbgp_prefix_longer_cmd,
10341 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
10342 SHOW_STR
10343 IPV6_STR
10344 MBGP_STR
10345 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
10346 "Display route and more specific routes\n")
10347{
47e9b292 10348 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 10349 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
10350 bgp_show_type_prefix_longer);
10351}
10352#endif /* HAVE_IPV6 */
bb46e94f 10353
94f2b392 10354static struct peer *
fd79ac91 10355peer_lookup_in_view (struct vty *vty, const char *view_name,
856ca177 10356 const char *ip_str, u_char use_json)
bb46e94f 10357{
10358 int ret;
10359 struct bgp *bgp;
10360 struct peer *peer;
10361 union sockunion su;
10362
10363 /* BGP structure lookup. */
10364 if (view_name)
10365 {
10366 bgp = bgp_lookup_by_name (view_name);
10367 if (! bgp)
10368 {
856ca177
MS
10369 if (use_json)
10370 {
10371 json_object *json_no = NULL;
10372 json_no = json_object_new_object();
10373 json_object_string_add(json_no, "warning", "Can't find BGP view");
10374 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
10375 json_object_free(json_no);
10376 }
10377 else
10378 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
bb46e94f 10379 return NULL;
10380 }
10381 }
5228ad27 10382 else
bb46e94f 10383 {
10384 bgp = bgp_get_default ();
10385 if (! bgp)
10386 {
856ca177
MS
10387 if (use_json)
10388 {
10389 json_object *json_no = NULL;
10390 json_no = json_object_new_object();
10391 json_object_string_add(json_no, "warning", "No BGP process configured");
10392 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
10393 json_object_free(json_no);
10394 }
10395 else
10396 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
bb46e94f 10397 return NULL;
10398 }
10399 }
10400
10401 /* Get peer sockunion. */
10402 ret = str2sockunion (ip_str, &su);
10403 if (ret < 0)
10404 {
a80beece
DS
10405 peer = peer_lookup_by_conf_if (bgp, ip_str);
10406 if (!peer)
10407 {
04b6bdc0
DW
10408 peer = peer_lookup_by_hostname(bgp, ip_str);
10409
10410 if (!peer)
856ca177 10411 {
04b6bdc0
DW
10412 if (use_json)
10413 {
10414 json_object *json_no = NULL;
10415 json_no = json_object_new_object();
10416 json_object_string_add(json_no, "malformedAddressOrName", ip_str);
10417 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
10418 json_object_free(json_no);
10419 }
10420 else
10421 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
10422 return NULL;
856ca177 10423 }
a80beece
DS
10424 }
10425 return peer;
bb46e94f 10426 }
10427
10428 /* Peer structure lookup. */
10429 peer = peer_lookup (bgp, &su);
10430 if (! peer)
10431 {
856ca177
MS
10432 if (use_json)
10433 {
10434 json_object *json_no = NULL;
10435 json_no = json_object_new_object();
10436 json_object_string_add(json_no, "warning","No such neighbor");
10437 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
10438 json_object_free(json_no);
10439 }
10440 else
10441 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
bb46e94f 10442 return NULL;
10443 }
10444
10445 return peer;
10446}
6b0655a2 10447
2815e61f
PJ
10448enum bgp_stats
10449{
10450 BGP_STATS_MAXBITLEN = 0,
10451 BGP_STATS_RIB,
10452 BGP_STATS_PREFIXES,
10453 BGP_STATS_TOTPLEN,
10454 BGP_STATS_UNAGGREGATEABLE,
10455 BGP_STATS_MAX_AGGREGATEABLE,
10456 BGP_STATS_AGGREGATES,
10457 BGP_STATS_SPACE,
10458 BGP_STATS_ASPATH_COUNT,
10459 BGP_STATS_ASPATH_MAXHOPS,
10460 BGP_STATS_ASPATH_TOTHOPS,
10461 BGP_STATS_ASPATH_MAXSIZE,
10462 BGP_STATS_ASPATH_TOTSIZE,
10463 BGP_STATS_ASN_HIGHEST,
10464 BGP_STATS_MAX,
10465};
10466
10467static const char *table_stats_strs[] =
10468{
10469 [BGP_STATS_PREFIXES] = "Total Prefixes",
10470 [BGP_STATS_TOTPLEN] = "Average prefix length",
10471 [BGP_STATS_RIB] = "Total Advertisements",
10472 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
10473 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
10474 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
10475 [BGP_STATS_SPACE] = "Address space advertised",
10476 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
10477 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
10478 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
10479 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
10480 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
10481 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
10482 [BGP_STATS_MAX] = NULL,
10483};
10484
10485struct bgp_table_stats
10486{
10487 struct bgp_table *table;
10488 unsigned long long counts[BGP_STATS_MAX];
10489};
10490
10491#if 0
10492#define TALLY_SIGFIG 100000
10493static unsigned long
10494ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
10495{
10496 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
10497 unsigned long res = (newtot * TALLY_SIGFIG) / count;
10498 unsigned long ret = newtot / count;
10499
10500 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
10501 return ret + 1;
10502 else
10503 return ret;
10504}
10505#endif
10506
10507static int
10508bgp_table_stats_walker (struct thread *t)
10509{
10510 struct bgp_node *rn;
10511 struct bgp_node *top;
10512 struct bgp_table_stats *ts = THREAD_ARG (t);
10513 unsigned int space = 0;
10514
53d9f67a
PJ
10515 if (!(top = bgp_table_top (ts->table)))
10516 return 0;
2815e61f
PJ
10517
10518 switch (top->p.family)
10519 {
10520 case AF_INET:
10521 space = IPV4_MAX_BITLEN;
10522 break;
10523 case AF_INET6:
10524 space = IPV6_MAX_BITLEN;
10525 break;
10526 }
10527
10528 ts->counts[BGP_STATS_MAXBITLEN] = space;
10529
10530 for (rn = top; rn; rn = bgp_route_next (rn))
10531 {
10532 struct bgp_info *ri;
67174041 10533 struct bgp_node *prn = bgp_node_parent_nolock (rn);
2815e61f
PJ
10534 unsigned int rinum = 0;
10535
10536 if (rn == top)
10537 continue;
10538
10539 if (!rn->info)
10540 continue;
10541
10542 ts->counts[BGP_STATS_PREFIXES]++;
10543 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
10544
10545#if 0
10546 ts->counts[BGP_STATS_AVGPLEN]
10547 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
10548 ts->counts[BGP_STATS_AVGPLEN],
10549 rn->p.prefixlen);
10550#endif
10551
10552 /* check if the prefix is included by any other announcements */
10553 while (prn && !prn->info)
67174041 10554 prn = bgp_node_parent_nolock (prn);
2815e61f
PJ
10555
10556 if (prn == NULL || prn == top)
8383a9bd
PJ
10557 {
10558 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
10559 /* announced address space */
10560 if (space)
10561 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
10562 }
2815e61f
PJ
10563 else if (prn->info)
10564 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
10565
2815e61f
PJ
10566 for (ri = rn->info; ri; ri = ri->next)
10567 {
10568 rinum++;
10569 ts->counts[BGP_STATS_RIB]++;
10570
10571 if (ri->attr &&
10572 (CHECK_FLAG (ri->attr->flag,
10573 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
10574 ts->counts[BGP_STATS_AGGREGATES]++;
10575
10576 /* as-path stats */
10577 if (ri->attr && ri->attr->aspath)
10578 {
10579 unsigned int hops = aspath_count_hops (ri->attr->aspath);
10580 unsigned int size = aspath_size (ri->attr->aspath);
10581 as_t highest = aspath_highest (ri->attr->aspath);
10582
10583 ts->counts[BGP_STATS_ASPATH_COUNT]++;
10584
10585 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
10586 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
10587
10588 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
10589 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
10590
10591 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
10592 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
10593#if 0
10594 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
10595 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
10596 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
10597 hops);
10598 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
10599 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
10600 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
10601 size);
10602#endif
10603 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
10604 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
10605 }
10606 }
10607 }
10608 return 0;
10609}
10610
10611static int
10612bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
10613{
10614 struct bgp_table_stats ts;
10615 unsigned int i;
10616
10617 if (!bgp->rib[afi][safi])
10618 {
10619 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
10620 return CMD_WARNING;
10621 }
10622
10623 memset (&ts, 0, sizeof (ts));
10624 ts.table = bgp->rib[afi][safi];
87d4a781 10625 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
bb46e94f 10626
2815e61f
PJ
10627 vty_out (vty, "BGP %s RIB statistics%s%s",
10628 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
10629
10630 for (i = 0; i < BGP_STATS_MAX; i++)
10631 {
10632 if (!table_stats_strs[i])
10633 continue;
10634
10635 switch (i)
10636 {
10637#if 0
10638 case BGP_STATS_ASPATH_AVGHOPS:
10639 case BGP_STATS_ASPATH_AVGSIZE:
10640 case BGP_STATS_AVGPLEN:
10641 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10642 vty_out (vty, "%12.2f",
10643 (float)ts.counts[i] / (float)TALLY_SIGFIG);
10644 break;
10645#endif
10646 case BGP_STATS_ASPATH_TOTHOPS:
10647 case BGP_STATS_ASPATH_TOTSIZE:
10648 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10649 vty_out (vty, "%12.2f",
10650 ts.counts[i] ?
10651 (float)ts.counts[i] /
10652 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
10653 : 0);
10654 break;
10655 case BGP_STATS_TOTPLEN:
10656 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10657 vty_out (vty, "%12.2f",
10658 ts.counts[i] ?
10659 (float)ts.counts[i] /
10660 (float)ts.counts[BGP_STATS_PREFIXES]
10661 : 0);
10662 break;
10663 case BGP_STATS_SPACE:
10664 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10665 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
10666 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
10667 break;
30a2231a 10668 vty_out (vty, "%30s: ", "%% announced ");
2815e61f
PJ
10669 vty_out (vty, "%12.2f%s",
10670 100 * (float)ts.counts[BGP_STATS_SPACE] /
56395af7 10671 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
2815e61f
PJ
10672 VTY_NEWLINE);
10673 vty_out (vty, "%30s: ", "/8 equivalent ");
10674 vty_out (vty, "%12.2f%s",
10675 (float)ts.counts[BGP_STATS_SPACE] /
10676 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
10677 VTY_NEWLINE);
10678 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
10679 break;
10680 vty_out (vty, "%30s: ", "/24 equivalent ");
10681 vty_out (vty, "%12.2f",
10682 (float)ts.counts[BGP_STATS_SPACE] /
10683 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
10684 break;
10685 default:
10686 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10687 vty_out (vty, "%12llu", ts.counts[i]);
10688 }
10689
10690 vty_out (vty, "%s", VTY_NEWLINE);
10691 }
10692 return CMD_SUCCESS;
10693}
10694
10695static int
10696bgp_table_stats_vty (struct vty *vty, const char *name,
10697 const char *afi_str, const char *safi_str)
10698{
10699 struct bgp *bgp;
10700 afi_t afi;
10701 safi_t safi;
10702
10703 if (name)
10704 bgp = bgp_lookup_by_name (name);
10705 else
10706 bgp = bgp_get_default ();
10707
10708 if (!bgp)
10709 {
10710 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
10711 return CMD_WARNING;
10712 }
10713 if (strncmp (afi_str, "ipv", 3) == 0)
10714 {
10715 if (strncmp (afi_str, "ipv4", 4) == 0)
10716 afi = AFI_IP;
10717 else if (strncmp (afi_str, "ipv6", 4) == 0)
10718 afi = AFI_IP6;
10719 else
10720 {
10721 vty_out (vty, "%% Invalid address family %s%s",
10722 afi_str, VTY_NEWLINE);
10723 return CMD_WARNING;
10724 }
10725 if (strncmp (safi_str, "m", 1) == 0)
10726 safi = SAFI_MULTICAST;
10727 else if (strncmp (safi_str, "u", 1) == 0)
10728 safi = SAFI_UNICAST;
42e6d745
DO
10729 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
10730 safi = SAFI_MPLS_LABELED_VPN;
2815e61f
PJ
10731 else
10732 {
10733 vty_out (vty, "%% Invalid subsequent address family %s%s",
10734 safi_str, VTY_NEWLINE);
10735 return CMD_WARNING;
10736 }
10737 }
10738 else
10739 {
10740 vty_out (vty, "%% Invalid address family %s%s",
10741 afi_str, VTY_NEWLINE);
10742 return CMD_WARNING;
10743 }
10744
2815e61f
PJ
10745 return bgp_table_stats (vty, bgp, afi, safi);
10746}
10747
10748DEFUN (show_bgp_statistics,
10749 show_bgp_statistics_cmd,
10750 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
10751 SHOW_STR
10752 BGP_STR
10753 "Address family\n"
10754 "Address family\n"
10755 "Address Family modifier\n"
10756 "Address Family modifier\n"
10757 "BGP RIB advertisement statistics\n")
10758{
10759 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
10760}
10761
10762ALIAS (show_bgp_statistics,
10763 show_bgp_statistics_vpnv4_cmd,
10764 "show bgp (ipv4) (vpnv4) statistics",
10765 SHOW_STR
10766 BGP_STR
10767 "Address family\n"
10768 "Address Family modifier\n"
10769 "BGP RIB advertisement statistics\n")
10770
10771DEFUN (show_bgp_statistics_view,
10772 show_bgp_statistics_view_cmd,
10773 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
10774 SHOW_STR
10775 BGP_STR
10776 "BGP view\n"
10777 "Address family\n"
10778 "Address family\n"
10779 "Address Family modifier\n"
10780 "Address Family modifier\n"
10781 "BGP RIB advertisement statistics\n")
10782{
10783 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
10784}
10785
10786ALIAS (show_bgp_statistics_view,
10787 show_bgp_statistics_view_vpnv4_cmd,
10788 "show bgp view WORD (ipv4) (vpnv4) statistics",
10789 SHOW_STR
10790 BGP_STR
10791 "BGP view\n"
10792 "Address family\n"
10793 "Address Family modifier\n"
10794 "BGP RIB advertisement statistics\n")
6b0655a2 10795
ff7924f6
PJ
10796enum bgp_pcounts
10797{
10798 PCOUNT_ADJ_IN = 0,
10799 PCOUNT_DAMPED,
10800 PCOUNT_REMOVED,
10801 PCOUNT_HISTORY,
10802 PCOUNT_STALE,
10803 PCOUNT_VALID,
10804 PCOUNT_ALL,
10805 PCOUNT_COUNTED,
10806 PCOUNT_PFCNT, /* the figure we display to users */
10807 PCOUNT_MAX,
10808};
10809
10810static const char *pcount_strs[] =
10811{
10812 [PCOUNT_ADJ_IN] = "Adj-in",
10813 [PCOUNT_DAMPED] = "Damped",
10814 [PCOUNT_REMOVED] = "Removed",
10815 [PCOUNT_HISTORY] = "History",
10816 [PCOUNT_STALE] = "Stale",
10817 [PCOUNT_VALID] = "Valid",
10818 [PCOUNT_ALL] = "All RIB",
10819 [PCOUNT_COUNTED] = "PfxCt counted",
10820 [PCOUNT_PFCNT] = "Useable",
10821 [PCOUNT_MAX] = NULL,
10822};
10823
2815e61f
PJ
10824struct peer_pcounts
10825{
10826 unsigned int count[PCOUNT_MAX];
10827 const struct peer *peer;
10828 const struct bgp_table *table;
10829};
10830
ff7924f6 10831static int
2815e61f 10832bgp_peer_count_walker (struct thread *t)
ff7924f6
PJ
10833{
10834 struct bgp_node *rn;
2815e61f
PJ
10835 struct peer_pcounts *pc = THREAD_ARG (t);
10836 const struct peer *peer = pc->peer;
ff7924f6 10837
2815e61f 10838 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
ff7924f6
PJ
10839 {
10840 struct bgp_adj_in *ain;
2815e61f 10841 struct bgp_info *ri;
ff7924f6
PJ
10842
10843 for (ain = rn->adj_in; ain; ain = ain->next)
10844 if (ain->peer == peer)
2815e61f 10845 pc->count[PCOUNT_ADJ_IN]++;
ff7924f6 10846
ff7924f6
PJ
10847 for (ri = rn->info; ri; ri = ri->next)
10848 {
10849 char buf[SU_ADDRSTRLEN];
10850
10851 if (ri->peer != peer)
10852 continue;
10853
2815e61f 10854 pc->count[PCOUNT_ALL]++;
ff7924f6
PJ
10855
10856 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
2815e61f 10857 pc->count[PCOUNT_DAMPED]++;
ff7924f6 10858 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2815e61f 10859 pc->count[PCOUNT_HISTORY]++;
ff7924f6 10860 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
2815e61f 10861 pc->count[PCOUNT_REMOVED]++;
ff7924f6 10862 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2815e61f 10863 pc->count[PCOUNT_STALE]++;
ff7924f6 10864 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
2815e61f 10865 pc->count[PCOUNT_VALID]++;
1a392d46 10866 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2815e61f 10867 pc->count[PCOUNT_PFCNT]++;
ff7924f6
PJ
10868
10869 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
10870 {
2815e61f 10871 pc->count[PCOUNT_COUNTED]++;
1a392d46 10872 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 10873 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
ff7924f6
PJ
10874 peer->host,
10875 inet_ntop(rn->p.family, &rn->p.u.prefix,
10876 buf, SU_ADDRSTRLEN),
10877 rn->p.prefixlen,
10878 ri->flags);
10879 }
10880 else
10881 {
1a392d46 10882 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 10883 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
ff7924f6
PJ
10884 peer->host,
10885 inet_ntop(rn->p.family, &rn->p.u.prefix,
10886 buf, SU_ADDRSTRLEN),
10887 rn->p.prefixlen,
10888 ri->flags);
10889 }
10890 }
10891 }
2815e61f
PJ
10892 return 0;
10893}
ff7924f6 10894
2815e61f 10895static int
856ca177 10896bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json)
2815e61f
PJ
10897{
10898 struct peer_pcounts pcounts = { .peer = peer };
10899 unsigned int i;
856ca177
MS
10900 json_object *json = NULL;
10901 json_object *json_loop = NULL;
10902
10903 if (use_json)
10904 {
10905 json = json_object_new_object();
10906 json_loop = json_object_new_object();
10907 }
2815e61f
PJ
10908
10909 if (!peer || !peer->bgp || !peer->afc[afi][safi]
10910 || !peer->bgp->rib[afi][safi])
10911 {
856ca177
MS
10912 if (use_json)
10913 {
10914 json_object_string_add(json, "warning", "No such neighbor or address family");
10915 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
10916 json_object_free(json);
10917 }
10918 else
10919 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10920
2815e61f
PJ
10921 return CMD_WARNING;
10922 }
10923
10924 memset (&pcounts, 0, sizeof(pcounts));
10925 pcounts.peer = peer;
10926 pcounts.table = peer->bgp->rib[afi][safi];
10927
10928 /* in-place call via thread subsystem so as to record execution time
856ca177
MS
10929 * * stats for the thread-walk (i.e. ensure this can't be blamed on
10930 * * on just vty_read()).
10931 * */
87d4a781 10932 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
6410e93a 10933
856ca177
MS
10934 if (use_json)
10935 {
10936 json_object_string_add(json, "prefixCountsFor", peer->host);
10937 json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi));
10938 json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]);
10939
10940 for (i = 0; i < PCOUNT_MAX; i++)
10941 json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]);
ff7924f6 10942
856ca177 10943 json_object_object_add(json, "ribTableWalkCounters", json_loop);
ff7924f6 10944
856ca177
MS
10945 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
10946 {
10947 json_object_string_add(json, "pfxctDriftFor", peer->host);
10948 json_object_string_add(json, "recommended", "Please report this bug, with the above command output");
10949 }
10950 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
10951 json_object_free(json);
10952 }
10953 else
ff7924f6 10954 {
04b6bdc0
DW
10955
10956 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
10957 {
10958 vty_out (vty, "Prefix counts for %s/%s, %s%s",
10959 peer->hostname, peer->host, afi_safi_print (afi, safi),
10960 VTY_NEWLINE);
10961 }
10962 else
10963 {
10964 vty_out (vty, "Prefix counts for %s, %s%s",
10965 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
10966 }
10967
856ca177
MS
10968 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
10969 vty_out (vty, "%sCounts from RIB table walk:%s%s",
10970 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
10971
10972 for (i = 0; i < PCOUNT_MAX; i++)
10973 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
10974
10975 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
10976 {
10977 vty_out (vty, "%s [pcount] PfxCt drift!%s",
10978 peer->host, VTY_NEWLINE);
10979 vty_out (vty, "Please report this bug, with the above command output%s",
10980 VTY_NEWLINE);
10981 }
ff7924f6
PJ
10982 }
10983
10984 return CMD_SUCCESS;
10985}
10986
10987DEFUN (show_ip_bgp_neighbor_prefix_counts,
10988 show_ip_bgp_neighbor_prefix_counts_cmd,
856ca177 10989 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
10990 SHOW_STR
10991 IP_STR
10992 BGP_STR
10993 "Detailed information on TCP and BGP neighbor connections\n"
10994 "Neighbor to display information about\n"
10995 "Neighbor to display information about\n"
a80beece 10996 "Neighbor on bgp configured interface\n"
856ca177
MS
10997 "Display detailed prefix count information\n"
10998 "JavaScript Object Notation\n")
ff7924f6
PJ
10999{
11000 struct peer *peer;
db7c8528 11001 u_char uj = use_json(argc, argv);
ff7924f6 11002
db7c8528 11003 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
ff7924f6
PJ
11004 if (! peer)
11005 return CMD_WARNING;
11006
db7c8528 11007 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
ff7924f6
PJ
11008}
11009
11010DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
11011 show_bgp_ipv6_neighbor_prefix_counts_cmd,
856ca177 11012 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
11013 SHOW_STR
11014 BGP_STR
11015 "Address family\n"
11016 "Detailed information on TCP and BGP neighbor connections\n"
11017 "Neighbor to display information about\n"
11018 "Neighbor to display information about\n"
a80beece 11019 "Neighbor on bgp configured interface\n"
856ca177
MS
11020 "Display detailed prefix count information\n"
11021 "JavaScript Object Notation\n")
ff7924f6
PJ
11022{
11023 struct peer *peer;
db7c8528 11024 u_char uj = use_json(argc, argv);
856ca177 11025
db7c8528 11026 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
ff7924f6
PJ
11027 if (! peer)
11028 return CMD_WARNING;
11029
db7c8528 11030 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
ff7924f6
PJ
11031}
11032
11033DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
11034 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
856ca177 11035 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
11036 SHOW_STR
11037 IP_STR
11038 BGP_STR
11039 "Address family\n"
11040 "Address Family modifier\n"
11041 "Address Family modifier\n"
11042 "Detailed information on TCP and BGP neighbor connections\n"
11043 "Neighbor to display information about\n"
11044 "Neighbor to display information about\n"
a80beece 11045 "Neighbor on bgp configured interface\n"
856ca177
MS
11046 "Display detailed prefix count information\n"
11047 "JavaScript Object Notation\n")
ff7924f6
PJ
11048{
11049 struct peer *peer;
db7c8528 11050 u_char uj = use_json(argc, argv);
ff7924f6 11051
db7c8528 11052 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
ff7924f6
PJ
11053 if (! peer)
11054 return CMD_WARNING;
11055
11056 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 11057 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST, uj);
ff7924f6 11058
db7c8528 11059 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
ff7924f6
PJ
11060}
11061
11062DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
11063 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
856ca177 11064 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
11065 SHOW_STR
11066 IP_STR
11067 BGP_STR
11068 "Address family\n"
11069 "Address Family modifier\n"
11070 "Address Family modifier\n"
11071 "Detailed information on TCP and BGP neighbor connections\n"
11072 "Neighbor to display information about\n"
11073 "Neighbor to display information about\n"
a80beece 11074 "Neighbor on bgp configured interface\n"
856ca177
MS
11075 "Display detailed prefix count information\n"
11076 "JavaScript Object Notation\n")
ff7924f6
PJ
11077{
11078 struct peer *peer;
db7c8528 11079 u_char uj = use_json(argc, argv);
856ca177 11080
db7c8528 11081 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
ff7924f6
PJ
11082 if (! peer)
11083 return CMD_WARNING;
11084
db7c8528 11085 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN, uj);
ff7924f6
PJ
11086}
11087
94f2b392 11088static void
718e3744 11089show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
856ca177 11090 int in, const char *rmap_name, u_char use_json, json_object *json)
718e3744 11091{
11092 struct bgp_table *table;
11093 struct bgp_adj_in *ain;
11094 struct bgp_adj_out *adj;
11095 unsigned long output_count;
0b16f239 11096 unsigned long filtered_count;
718e3744 11097 struct bgp_node *rn;
11098 int header1 = 1;
11099 struct bgp *bgp;
11100 int header2 = 1;
0b16f239
DS
11101 struct attr attr;
11102 struct attr_extra extra;
11103 int ret;
840fced9 11104 struct update_subgroup *subgrp;
856ca177
MS
11105 json_object *json_scode = NULL;
11106 json_object *json_ocode = NULL;
11107 json_object *json_ar = NULL;
adbac85e 11108 struct peer_af *paf;
856ca177
MS
11109
11110 if (use_json)
11111 {
11112 json_scode = json_object_new_object();
11113 json_ocode = json_object_new_object();
11114 json_ar = json_object_new_object();
11115
11116 json_object_string_add(json_scode, "suppressed", "s");
11117 json_object_string_add(json_scode, "damped", "d");
11118 json_object_string_add(json_scode, "history", "h");
11119 json_object_string_add(json_scode, "valid", "*");
11120 json_object_string_add(json_scode, "best", ">");
11121 json_object_string_add(json_scode, "multipath", "=");
11122 json_object_string_add(json_scode, "internal", "i");
11123 json_object_string_add(json_scode, "ribFailure", "r");
11124 json_object_string_add(json_scode, "stale", "S");
11125 json_object_string_add(json_scode, "removed", "R");
11126
11127 json_object_string_add(json_ocode, "igp", "i");
11128 json_object_string_add(json_ocode, "egp", "e");
11129 json_object_string_add(json_ocode, "incomplete", "?");
11130 }
718e3744 11131
bb46e94f 11132 bgp = peer->bgp;
718e3744 11133
11134 if (! bgp)
856ca177
MS
11135 {
11136 if (use_json)
11137 {
11138 json_object_string_add(json, "alert", "no BGP");
11139 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11140 json_object_free(json);
11141 }
11142 else
11143 vty_out (vty, "%% No bgp%s", VTY_NEWLINE);
11144 return;
11145 }
718e3744 11146
11147 table = bgp->rib[afi][safi];
11148
0b16f239 11149 output_count = filtered_count = 0;
840fced9 11150 subgrp = peer_subgroup(peer, afi, safi);
47fc97cc 11151
840fced9 11152 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
718e3744 11153 {
856ca177
MS
11154 if (use_json)
11155 {
11156 json_object_int_add(json, "bgpTableVersion", table->version);
11157 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
11158 json_object_object_add(json, "bgpStatusCodes", json_scode);
11159 json_object_object_add(json, "bgpOriginCodes", json_ocode);
11160 json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0");
11161 }
11162 else
11163 {
11164 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
11165 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11166 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 11167
856ca177
MS
11168 vty_out (vty, "Originating default network 0.0.0.0%s%s",
11169 VTY_NEWLINE, VTY_NEWLINE);
11170 }
718e3744 11171 header1 = 0;
11172 }
11173
0b16f239 11174 attr.extra = &extra;
718e3744 11175 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
856ca177
MS
11176 {
11177 if (in)
11178 {
11179 for (ain = rn->adj_in; ain; ain = ain->next)
11180 {
11181 if (ain->peer == peer)
11182 {
11183 if (header1)
11184 {
11185 if (use_json)
11186 {
11187 json_object_int_add(json, "bgpTableVersion", 0);
11188 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
11189 json_object_object_add(json, "bgpStatusCodes", json_scode);
11190 json_object_object_add(json, "bgpOriginCodes", json_ocode);
11191 }
11192 else
11193 {
11194 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
11195 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11196 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11197 }
11198 header1 = 0;
11199 }
11200 if (header2)
11201 {
11202 if (!use_json)
11203 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
11204 header2 = 0;
11205 }
11206 if (ain->attr)
11207 {
11208 bgp_attr_dup(&attr, ain->attr);
11209 if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY)
11210 {
11211 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
11212 output_count++;
11213 }
11214 else
11215 filtered_count++;
11216 }
11217 }
11218 }
11219 }
11220 else
11221 {
adbac85e
DW
11222 for (adj = rn->adj_out; adj; adj = adj->next)
11223 SUBGRP_FOREACH_PEER(adj->subgroup, paf)
11224 if (paf->peer == peer)
856ca177 11225 {
adbac85e 11226 if (header1)
856ca177 11227 {
adbac85e
DW
11228 if (use_json)
11229 {
11230 json_object_int_add(json, "bgpTableVersion", table->version);
11231 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
11232 json_object_object_add(json, "bgpStatusCodes", json_scode);
11233 json_object_object_add(json, "bgpOriginCodes", json_ocode);
11234 }
11235 else
11236 {
11237 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version,
11238 inet_ntoa (bgp->router_id), VTY_NEWLINE);
11239 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11240 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11241 }
11242 header1 = 0;
856ca177 11243 }
adbac85e
DW
11244
11245 if (header2)
856ca177 11246 {
adbac85e
DW
11247 if (!use_json)
11248 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
11249 header2 = 0;
856ca177 11250 }
adbac85e
DW
11251
11252 if (adj->attr)
856ca177 11253 {
adbac85e
DW
11254 bgp_attr_dup(&attr, adj->attr);
11255 ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name);
11256 if (ret != RMAP_DENY)
11257 {
11258 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
11259 output_count++;
11260 }
11261 else
11262 filtered_count++;
856ca177 11263 }
856ca177 11264 }
856ca177
MS
11265 }
11266 }
11267 if (use_json)
11268 json_object_object_add(json, "advertisedRoutes", json_ar);
47fc97cc 11269
718e3744 11270 if (output_count != 0)
856ca177
MS
11271 {
11272 if (use_json)
11273 json_object_int_add(json, "totalPrefixCounter", output_count);
11274 else
11275 vty_out (vty, "%sTotal number of prefixes %ld%s",
11276 VTY_NEWLINE, output_count, VTY_NEWLINE);
11277 }
11278 if (use_json)
11279 {
11280 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11281 json_object_free(json);
11282 }
11283
718e3744 11284}
11285
94f2b392 11286static int
47fc97cc 11287peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
856ca177
MS
11288 int in, const char *rmap_name, u_char use_json)
11289{
11290 json_object *json = NULL;
11291
11292 if (use_json)
11293 json = json_object_new_object();
11294
11295 if (!peer || !peer->afc[afi][safi])
718e3744 11296 {
856ca177
MS
11297 if (use_json)
11298 {
11299 json_object_string_add(json, "warning", "No such neighbor or address family");
11300 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11301 json_object_free(json);
11302 }
11303 else
11304 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11305
718e3744 11306 return CMD_WARNING;
11307 }
11308
856ca177 11309 if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
718e3744 11310 {
856ca177
MS
11311 if (use_json)
11312 {
11313 json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
11314 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11315 json_object_free(json);
11316 }
11317 else
11318 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE);
11319
718e3744 11320 return CMD_WARNING;
11321 }
11322
856ca177 11323 show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json);
718e3744 11324
11325 return CMD_SUCCESS;
11326}
11327
2a71e9ce
TP
11328DEFUN (show_ip_bgp_view_neighbor_advertised_route,
11329 show_ip_bgp_view_neighbor_advertised_route_cmd,
856ca177 11330 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 11331 SHOW_STR
11332 IP_STR
11333 BGP_STR
2a71e9ce
TP
11334 "BGP view\n"
11335 "View name\n"
718e3744 11336 "Detailed information on TCP and BGP neighbor connections\n"
11337 "Neighbor to display information about\n"
11338 "Neighbor to display information about\n"
856ca177
MS
11339 "Display the routes advertised to a BGP neighbor\n"
11340 "JavaScript Object Notation\n")
718e3744 11341{
bb46e94f 11342 struct peer *peer;
db7c8528 11343 u_char uj = use_json(argc, argv);
856ca177
MS
11344
11345 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
db7c8528 11346 peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
2a71e9ce 11347 else
db7c8528 11348 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
2a71e9ce 11349
bb46e94f 11350 if (! peer)
11351 return CMD_WARNING;
0b16f239 11352
db7c8528 11353 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj);
718e3744 11354}
11355
0b16f239 11356DEFUN (show_ip_bgp_neighbor_advertised_route,
2a71e9ce 11357 show_ip_bgp_neighbor_advertised_route_cmd,
856ca177 11358 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
2a71e9ce
TP
11359 SHOW_STR
11360 IP_STR
11361 BGP_STR
11362 "Detailed information on TCP and BGP neighbor connections\n"
11363 "Neighbor to display information about\n"
11364 "Neighbor to display information about\n"
a80beece 11365 "Neighbor on bgp configured interface\n"
856ca177
MS
11366 "Display the routes advertised to a BGP neighbor\n"
11367 "JavaScript Object Notation\n")
2a71e9ce 11368
0b16f239
DS
11369{
11370 struct peer *peer;
ffd0c037 11371 const char *rmap_name = NULL;
db7c8528 11372 u_char uj = use_json(argc, argv);
0b16f239 11373
db7c8528 11374 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
0b16f239
DS
11375
11376 if (! peer)
11377 return CMD_WARNING;
11378
856ca177
MS
11379 if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)
11380 || (argc == 3))
0b16f239
DS
11381 rmap_name = argv[1];
11382
db7c8528 11383 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
0b16f239
DS
11384}
11385
11386ALIAS (show_ip_bgp_neighbor_advertised_route,
11387 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
856ca177 11388 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
0b16f239
DS
11389 SHOW_STR
11390 IP_STR
11391 BGP_STR
11392 "Detailed information on TCP and BGP neighbor connections\n"
11393 "Neighbor to display information about\n"
11394 "Neighbor to display information about\n"
11395 "Neighbor on bgp configured interface\n"
856ca177
MS
11396 "Display the routes advertised to a BGP neighbor\n"
11397 "JavaScript Object Notation\n")
0b16f239 11398
718e3744 11399DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
11400 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
856ca177 11401 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 11402 SHOW_STR
11403 IP_STR
11404 BGP_STR
11405 "Address family\n"
11406 "Address Family modifier\n"
11407 "Address Family modifier\n"
11408 "Detailed information on TCP and BGP neighbor connections\n"
11409 "Neighbor to display information about\n"
11410 "Neighbor to display information about\n"
a80beece 11411 "Neighbor on bgp configured interface\n"
856ca177
MS
11412 "Display the routes advertised to a BGP neighbor\n"
11413 "JavaScript Object Notation\n")
718e3744 11414{
bb46e94f 11415 struct peer *peer;
ffd0c037 11416 const char *rmap_name = NULL;
db7c8528 11417 u_char uj = use_json(argc, argv);
856ca177 11418
db7c8528 11419 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 11420 if (! peer)
11421 return CMD_WARNING;
11422
856ca177 11423 if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
0b16f239
DS
11424 rmap_name = argv[2];
11425
718e3744 11426 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 11427 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name, uj);
856ca177 11428 else
db7c8528 11429 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
718e3744 11430}
11431
0b16f239
DS
11432ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
11433 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
856ca177 11434 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
0b16f239
DS
11435 SHOW_STR
11436 IP_STR
11437 BGP_STR
11438 "Address family\n"
11439 "Address Family modifier\n"
11440 "Address Family modifier\n"
11441 "Detailed information on TCP and BGP neighbor connections\n"
11442 "Neighbor to display information about\n"
11443 "Neighbor to display information about\n"
11444 "Neighbor on bgp configured interface\n"
11445 "Display the routes advertised to a BGP neighbor\n"
856ca177
MS
11446 "Route-map to control what is displayed\n"
11447 "JavaScript Object Notation\n")
0b16f239 11448
718e3744 11449#ifdef HAVE_IPV6
bb46e94f 11450DEFUN (show_bgp_view_neighbor_advertised_route,
11451 show_bgp_view_neighbor_advertised_route_cmd,
856ca177 11452 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 11453 SHOW_STR
11454 BGP_STR
bb46e94f 11455 "BGP view\n"
11456 "View name\n"
718e3744 11457 "Detailed information on TCP and BGP neighbor connections\n"
11458 "Neighbor to display information about\n"
11459 "Neighbor to display information about\n"
a80beece 11460 "Neighbor on bgp configured interface\n"
856ca177
MS
11461 "Display the routes advertised to a BGP neighbor\n"
11462 "JavaScript Object Notation\n")
718e3744 11463{
bb46e94f 11464 struct peer *peer;
db7c8528 11465 u_char uj = use_json(argc, argv);
856ca177
MS
11466
11467 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
db7c8528 11468 peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
bb46e94f 11469 else
db7c8528 11470 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 11471
11472 if (! peer)
0b16f239 11473 return CMD_WARNING;
bb46e94f 11474
db7c8528 11475 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj);
47fc97cc
DS
11476}
11477
0b16f239
DS
11478ALIAS (show_bgp_view_neighbor_advertised_route,
11479 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
856ca177 11480 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
0b16f239
DS
11481 SHOW_STR
11482 BGP_STR
11483 "BGP view\n"
11484 "View name\n"
11485 "Address family\n"
11486 "Detailed information on TCP and BGP neighbor connections\n"
11487 "Neighbor to display information about\n"
11488 "Neighbor to display information about\n"
11489 "Neighbor on bgp configured interface\n"
856ca177
MS
11490 "Display the routes advertised to a BGP neighbor\n"
11491 "JavaScript Object Notation\n")
0b16f239 11492
0b16f239
DS
11493DEFUN (show_bgp_neighbor_advertised_route,
11494 show_bgp_neighbor_advertised_route_cmd,
856ca177 11495 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
bb46e94f 11496 SHOW_STR
11497 BGP_STR
bb46e94f 11498 "Detailed information on TCP and BGP neighbor connections\n"
11499 "Neighbor to display information about\n"
11500 "Neighbor to display information about\n"
a80beece 11501 "Neighbor on bgp configured interface\n"
856ca177
MS
11502 "Display the routes advertised to a BGP neighbor\n"
11503 "JavaScript Object Notation\n")
0b16f239 11504
bb46e94f 11505{
11506 struct peer *peer;
ffd0c037 11507 const char *rmap_name = NULL;
db7c8528 11508 u_char uj = use_json(argc, argv);
bb46e94f 11509
db7c8528 11510 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
856ca177
MS
11511
11512 if (!peer)
bb46e94f 11513 return CMD_WARNING;
11514
856ca177 11515 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
0b16f239
DS
11516 rmap_name = argv[1];
11517
db7c8528 11518 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj);
718e3744 11519}
11520
0b16f239
DS
11521ALIAS (show_bgp_neighbor_advertised_route,
11522 show_bgp_ipv6_neighbor_advertised_route_cmd,
856ca177 11523 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 11524 SHOW_STR
11525 BGP_STR
11526 "Address family\n"
11527 "Detailed information on TCP and BGP neighbor connections\n"
11528 "Neighbor to display information about\n"
11529 "Neighbor to display information about\n"
a80beece 11530 "Neighbor on bgp configured interface\n"
856ca177
MS
11531 "Display the routes advertised to a BGP neighbor\n"
11532 "JavaScript Object Notation\n")
718e3744 11533
11534/* old command */
0b16f239 11535ALIAS (show_bgp_neighbor_advertised_route,
718e3744 11536 ipv6_bgp_neighbor_advertised_route_cmd,
856ca177 11537 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 11538 SHOW_STR
11539 IPV6_STR
11540 BGP_STR
11541 "Detailed information on TCP and BGP neighbor connections\n"
11542 "Neighbor to display information about\n"
11543 "Neighbor to display information about\n"
a80beece 11544 "Neighbor on bgp configured interface\n"
856ca177
MS
11545 "Display the routes advertised to a BGP neighbor\n"
11546 "JavaScript Object Notation\n")
bb46e94f 11547
718e3744 11548/* old command */
11549DEFUN (ipv6_mbgp_neighbor_advertised_route,
11550 ipv6_mbgp_neighbor_advertised_route_cmd,
856ca177 11551 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 11552 SHOW_STR
11553 IPV6_STR
11554 MBGP_STR
11555 "Detailed information on TCP and BGP neighbor connections\n"
11556 "Neighbor to display information about\n"
11557 "Neighbor to display information about\n"
a80beece
DS
11558 "Neighbor on bgp configured interface\n"
11559 "Neighbor on bgp configured interface\n"
856ca177
MS
11560 "Display the routes advertised to a BGP neighbor\n"
11561 "JavaScript Object Notation\n")
718e3744 11562{
bb46e94f 11563 struct peer *peer;
db7c8528 11564 u_char uj = use_json(argc, argv);
856ca177 11565
db7c8528 11566 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 11567 if (! peer)
856ca177 11568 return CMD_WARNING;
bb46e94f 11569
47e9b292 11570 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 11571 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj);
718e3744 11572}
11573#endif /* HAVE_IPV6 */
6b0655a2 11574
0b16f239
DS
11575DEFUN (show_bgp_view_neighbor_received_routes,
11576 show_bgp_view_neighbor_received_routes_cmd,
856ca177 11577 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
0b16f239
DS
11578 SHOW_STR
11579 BGP_STR
11580 "BGP view\n"
11581 "View name\n"
11582 "Detailed information on TCP and BGP neighbor connections\n"
11583 "Neighbor to display information about\n"
11584 "Neighbor to display information about\n"
11585 "Neighbor on bgp configured interface\n"
856ca177
MS
11586 "Display the received routes from neighbor\n"
11587 "JavaScript Object Notation\n")
0b16f239
DS
11588{
11589 struct peer *peer;
db7c8528 11590 u_char uj = use_json(argc, argv);
856ca177 11591
db7c8528 11592 if (uj)
856ca177
MS
11593 {
11594 if (argc == 3)
db7c8528 11595 peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
856ca177 11596 else
db7c8528 11597 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
856ca177 11598 }
0b16f239 11599 else
856ca177
MS
11600 {
11601 if (argc == 2)
db7c8528 11602 peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
856ca177 11603 else
db7c8528 11604 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
856ca177 11605 }
0b16f239
DS
11606
11607 if (! peer)
11608 return CMD_WARNING;
11609
db7c8528 11610 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj);
0b16f239
DS
11611}
11612
2a71e9ce
TP
11613DEFUN (show_ip_bgp_view_neighbor_received_routes,
11614 show_ip_bgp_view_neighbor_received_routes_cmd,
856ca177 11615 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 11616 SHOW_STR
11617 IP_STR
11618 BGP_STR
2a71e9ce
TP
11619 "BGP view\n"
11620 "View name\n"
718e3744 11621 "Detailed information on TCP and BGP neighbor connections\n"
11622 "Neighbor to display information about\n"
11623 "Neighbor to display information about\n"
a80beece 11624 "Neighbor on bgp configured interface\n"
856ca177
MS
11625 "Display the received routes from neighbor\n"
11626 "JavaScript Object Notation\n")
718e3744 11627{
bb46e94f 11628 struct peer *peer;
db7c8528 11629 u_char uj = use_json(argc, argv);
856ca177
MS
11630
11631 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
db7c8528 11632 peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
2a71e9ce 11633 else
db7c8528 11634 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
2a71e9ce 11635
bb46e94f 11636 if (! peer)
11637 return CMD_WARNING;
11638
db7c8528 11639 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj);
718e3744 11640}
11641
0b16f239
DS
11642ALIAS (show_bgp_view_neighbor_received_routes,
11643 show_bgp_view_ipv6_neighbor_received_routes_cmd,
856ca177 11644 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
0b16f239
DS
11645 SHOW_STR
11646 BGP_STR
11647 "BGP view\n"
11648 "View name\n"
11649 "Address family\n"
11650 "Detailed information on TCP and BGP neighbor connections\n"
11651 "Neighbor to display information about\n"
11652 "Neighbor to display information about\n"
11653 "Neighbor on bgp configured interface\n"
856ca177
MS
11654 "Display the received routes from neighbor\n"
11655 "JavaScript Object Notation\n")
0b16f239
DS
11656
11657DEFUN (show_ip_bgp_neighbor_received_routes,
2a71e9ce 11658 show_ip_bgp_neighbor_received_routes_cmd,
856ca177 11659 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
2a71e9ce
TP
11660 SHOW_STR
11661 IP_STR
11662 BGP_STR
11663 "Detailed information on TCP and BGP neighbor connections\n"
11664 "Neighbor to display information about\n"
11665 "Neighbor to display information about\n"
a80beece 11666 "Neighbor on bgp configured interface\n"
856ca177
MS
11667 "Display the received routes from neighbor\n"
11668 "JavaScript Object Notation\n")
2a71e9ce 11669
0b16f239
DS
11670{
11671 struct peer *peer;
ffd0c037 11672 const char *rmap_name = NULL;
db7c8528 11673 u_char uj = use_json(argc, argv);
0b16f239 11674
db7c8528 11675 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
0b16f239
DS
11676
11677 if (! peer)
11678 return CMD_WARNING;
11679
856ca177 11680 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
0b16f239
DS
11681 rmap_name = argv[1];
11682
db7c8528 11683 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
0b16f239
DS
11684}
11685
11686ALIAS (show_ip_bgp_neighbor_received_routes,
11687 show_ip_bgp_neighbor_received_routes_rmap_cmd,
856ca177 11688 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
0b16f239
DS
11689 SHOW_STR
11690 IP_STR
11691 BGP_STR
11692 "Detailed information on TCP and BGP neighbor connections\n"
11693 "Neighbor to display information about\n"
11694 "Neighbor to display information about\n"
11695 "Neighbor on bgp configured interface\n"
856ca177
MS
11696 "Display the received routes from neighbor\n"
11697 "JavaScript Object Notation\n")
0b16f239 11698
718e3744 11699DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
11700 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
856ca177 11701 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 11702 SHOW_STR
11703 IP_STR
11704 BGP_STR
11705 "Address family\n"
11706 "Address Family modifier\n"
11707 "Address Family modifier\n"
11708 "Detailed information on TCP and BGP neighbor connections\n"
11709 "Neighbor to display information about\n"
11710 "Neighbor to display information about\n"
a80beece 11711 "Neighbor on bgp configured interface\n"
856ca177
MS
11712 "Display the received routes from neighbor\n"
11713 "JavaScript Object Notation\n")
718e3744 11714{
bb46e94f 11715 struct peer *peer;
ffd0c037 11716 const char *rmap_name = NULL;
db7c8528 11717 u_char uj = use_json(argc, argv);
bb46e94f 11718
db7c8528 11719 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 11720 if (! peer)
11721 return CMD_WARNING;
0b16f239 11722
856ca177 11723 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
0b16f239
DS
11724 rmap_name = argv[2];
11725
718e3744 11726 if (strncmp (argv[0], "m", 1) == 0)
db7c8528 11727 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name, uj);
856ca177 11728 else
db7c8528 11729 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
718e3744 11730}
11731
0b16f239
DS
11732ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
11733 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
856ca177 11734 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
0b16f239
DS
11735 SHOW_STR
11736 IP_STR
11737 BGP_STR
11738 "Address family\n"
11739 "Address Family modifier\n"
11740 "Address Family modifier\n"
11741 "Detailed information on TCP and BGP neighbor connections\n"
11742 "Neighbor to display information about\n"
11743 "Neighbor to display information about\n"
11744 "Neighbor on bgp configured interface\n"
856ca177
MS
11745 "Display the received routes from neighbor\n"
11746 "JavaScript Object Notation\n")
0b16f239 11747
95cbbd2a
ML
11748DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
11749 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
11750#ifdef HAVE_IPV6
856ca177 11751 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
95cbbd2a 11752#else
856ca177 11753 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
95cbbd2a
ML
11754#endif
11755 SHOW_STR
11756 BGP_STR
11757 "BGP view\n"
2b00515a 11758 "View name\n"
95cbbd2a
ML
11759 "Address family\n"
11760#ifdef HAVE_IPV6
11761 "Address family\n"
11762#endif
11763 "Address family modifier\n"
11764 "Address family modifier\n"
11765 "Detailed information on TCP and BGP neighbor connections\n"
11766 "Neighbor to display information about\n"
11767 "Neighbor to display information about\n"
a80beece 11768 "Neighbor on bgp configured interface\n"
95cbbd2a 11769 "Display the advertised routes to neighbor\n"
856ca177
MS
11770 "Display the received routes from neighbor\n"
11771 "JavaScript Object Notation\n")
95cbbd2a
ML
11772{
11773 int afi;
11774 int safi;
11775 int in;
11776 struct peer *peer;
db7c8528 11777 u_char uj = use_json(argc, argv);
856ca177 11778
db7c8528 11779 peer = peer_lookup_in_view (vty, argv[0], argv[3], uj);
95cbbd2a
ML
11780
11781 if (! peer)
11782 return CMD_WARNING;
11783
95cbbd2a
ML
11784 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
11785 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11786 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
95cbbd2a 11787
db7c8528 11788 return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj);
95cbbd2a
ML
11789}
11790
718e3744 11791DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
11792 show_ip_bgp_neighbor_received_prefix_filter_cmd,
856ca177 11793 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 11794 SHOW_STR
11795 IP_STR
11796 BGP_STR
11797 "Detailed information on TCP and BGP neighbor connections\n"
11798 "Neighbor to display information about\n"
11799 "Neighbor to display information about\n"
a80beece 11800 "Neighbor on bgp configured interface\n"
718e3744 11801 "Display information received from a BGP neighbor\n"
856ca177
MS
11802 "Display the prefixlist filter\n"
11803 "JavaScript Object Notation\n")
718e3744 11804{
11805 char name[BUFSIZ];
c63b83fe 11806 union sockunion su;
718e3744 11807 struct peer *peer;
c63b83fe 11808 int count, ret;
db7c8528 11809 u_char uj = use_json(argc, argv);
718e3744 11810
c63b83fe
JBD
11811 ret = str2sockunion (argv[0], &su);
11812 if (ret < 0)
11813 {
a80beece 11814 peer = peer_lookup_by_conf_if (NULL, argv[0]);
856ca177 11815 if (! peer)
a80beece 11816 {
db7c8528 11817 if (uj)
856ca177
MS
11818 {
11819 json_object *json_no = NULL;
11820 json_object *json_sub = NULL;
11821 json_no = json_object_new_object();
11822 json_sub = json_object_new_object();
11823 json_object_string_add(json_no, "warning", "Malformed address or name");
11824 json_object_string_add(json_sub, "warningCause", argv[0]);
11825 json_object_object_add(json_no, "detail", json_sub);
11826 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11827 json_object_free(json_no);
11828 }
11829 else
11830 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
a80beece
DS
11831 return CMD_WARNING;
11832 }
11833 }
11834 else
11835 {
11836 peer = peer_lookup (NULL, &su);
11837 if (! peer)
856ca177 11838 {
db7c8528 11839 if (uj)
856ca177
MS
11840 {
11841 json_object *json_no = NULL;
11842 json_no = json_object_new_object();
11843 json_object_string_add(json_no, "warning", "Peer not found");
11844 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11845 json_object_free(json_no);
11846 }
11847 else
11848 vty_out (vty, "No peer%s", VTY_NEWLINE);
11849 return CMD_WARNING;
11850 }
c63b83fe 11851 }
718e3744 11852
11853 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
db7c8528 11854 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
718e3744 11855 if (count)
11856 {
db7c8528 11857 if (!uj)
856ca177 11858 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
db7c8528 11859 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
856ca177
MS
11860 }
11861 else
11862 {
db7c8528 11863 if (uj)
856ca177
MS
11864 {
11865 json_object *json_no = NULL;
11866 json_no = json_object_new_object();
11867 json_object_boolean_true_add(json_no, "noFuntionalOutput");
11868 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11869 json_object_free(json_no);
11870 }
11871 else
11872 vty_out (vty, "No functional output%s", VTY_NEWLINE);
718e3744 11873 }
11874
11875 return CMD_SUCCESS;
11876}
11877
11878DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
11879 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
856ca177 11880 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 11881 SHOW_STR
11882 IP_STR
11883 BGP_STR
11884 "Address family\n"
11885 "Address Family modifier\n"
11886 "Address Family modifier\n"
11887 "Detailed information on TCP and BGP neighbor connections\n"
11888 "Neighbor to display information about\n"
11889 "Neighbor to display information about\n"
a80beece 11890 "Neighbor on bgp configured interface\n"
718e3744 11891 "Display information received from a BGP neighbor\n"
856ca177
MS
11892 "Display the prefixlist filter\n"
11893 "JavaScript Object Notation\n")
718e3744 11894{
11895 char name[BUFSIZ];
c63b83fe 11896 union sockunion su;
718e3744 11897 struct peer *peer;
c63b83fe 11898 int count, ret;
db7c8528 11899 u_char uj = use_json(argc, argv);
718e3744 11900
c63b83fe
JBD
11901 ret = str2sockunion (argv[1], &su);
11902 if (ret < 0)
11903 {
a80beece 11904 peer = peer_lookup_by_conf_if (NULL, argv[1]);
856ca177 11905 if (! peer)
a80beece 11906 {
db7c8528 11907 if (uj)
856ca177
MS
11908 {
11909 json_object *json_no = NULL;
11910 json_object *json_sub = NULL;
11911 json_no = json_object_new_object();
11912 json_sub = json_object_new_object();
11913 json_object_string_add(json_no, "warning", "Malformed address or name");
11914 json_object_string_add(json_sub, "warningCause", argv[1]);
11915 json_object_object_add(json_no, "detail", json_sub);
11916 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11917 json_object_free(json_no);
11918 }
11919 else
11920 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
a80beece
DS
11921 return CMD_WARNING;
11922 }
11923 }
11924 else
11925 {
11926 peer = peer_lookup (NULL, &su);
11927 if (! peer)
856ca177 11928 {
db7c8528 11929 if (uj)
856ca177
MS
11930 {
11931 json_object *json_no = NULL;
11932 json_no = json_object_new_object();
11933 json_object_string_add(json_no, "warning", "Peer not found");
11934 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11935 json_object_free(json_no);
11936 }
11937 else
11938 vty_out (vty, "No peer%s", VTY_NEWLINE);
11939 return CMD_WARNING;
11940 }
c63b83fe 11941 }
718e3744 11942
11943 if (strncmp (argv[0], "m", 1) == 0)
11944 {
11945 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
db7c8528 11946 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
718e3744 11947 if (count)
856ca177 11948 {
db7c8528 11949 if (!uj)
856ca177 11950 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
db7c8528 11951 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
856ca177
MS
11952 }
11953 else
11954 {
db7c8528 11955 if (uj)
856ca177
MS
11956 {
11957 json_object *json_no = NULL;
11958 json_no = json_object_new_object();
11959 json_object_boolean_true_add(json_no, "noFuntionalOutput");
11960 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11961 json_object_free(json_no);
11962 }
11963 else
11964 vty_out (vty, "No functional output%s", VTY_NEWLINE);
11965 }
718e3744 11966 }
11967 else
11968 {
11969 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
db7c8528 11970 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
718e3744 11971 if (count)
856ca177 11972 {
db7c8528 11973 if (!uj)
856ca177 11974 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
db7c8528 11975 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
856ca177
MS
11976 }
11977 else
11978 {
db7c8528 11979 if (uj)
856ca177
MS
11980 {
11981 json_object *json_no = NULL;
11982 json_no = json_object_new_object();
11983 json_object_boolean_true_add(json_no, "noFuntionalOutput");
11984 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11985 json_object_free(json_no);
11986 }
11987 else
11988 vty_out (vty, "No functional output%s", VTY_NEWLINE);
11989 }
718e3744 11990 }
11991
11992 return CMD_SUCCESS;
11993}
718e3744 11994#ifdef HAVE_IPV6
bb46e94f 11995ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 11996 show_bgp_neighbor_received_routes_cmd,
856ca177 11997 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 11998 SHOW_STR
11999 BGP_STR
12000 "Detailed information on TCP and BGP neighbor connections\n"
12001 "Neighbor to display information about\n"
12002 "Neighbor to display information about\n"
a80beece 12003 "Neighbor on bgp configured interface\n"
856ca177
MS
12004 "Display the received routes from neighbor\n"
12005 "JavaScript Object Notation\n")
718e3744 12006
bb46e94f 12007ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 12008 show_bgp_ipv6_neighbor_received_routes_cmd,
856ca177 12009 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
0b16f239
DS
12010 SHOW_STR
12011 BGP_STR
12012 "Address family\n"
12013 "Detailed information on TCP and BGP neighbor connections\n"
12014 "Neighbor to display information about\n"
12015 "Neighbor to display information about\n"
12016 "Neighbor on bgp configured interface\n"
856ca177
MS
12017 "Display the received routes from neighbor\n"
12018 "JavaScript Object Notation\n")
0b16f239 12019
718e3744 12020DEFUN (show_bgp_neighbor_received_prefix_filter,
12021 show_bgp_neighbor_received_prefix_filter_cmd,
856ca177 12022 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 12023 SHOW_STR
12024 BGP_STR
12025 "Detailed information on TCP and BGP neighbor connections\n"
12026 "Neighbor to display information about\n"
12027 "Neighbor to display information about\n"
a80beece 12028 "Neighbor on bgp configured interface\n"
718e3744 12029 "Display information received from a BGP neighbor\n"
856ca177
MS
12030 "Display the prefixlist filter\n"
12031 "JavaScript Object Notation\n")
718e3744 12032{
12033 char name[BUFSIZ];
c63b83fe 12034 union sockunion su;
718e3744 12035 struct peer *peer;
c63b83fe 12036 int count, ret;
db7c8528 12037 u_char uj = use_json(argc, argv);
718e3744 12038
c63b83fe
JBD
12039 ret = str2sockunion (argv[0], &su);
12040 if (ret < 0)
12041 {
a80beece 12042 peer = peer_lookup_by_conf_if (NULL, argv[0]);
856ca177 12043 if (! peer)
a80beece 12044 {
db7c8528 12045 if (uj)
856ca177
MS
12046 {
12047 json_object *json_no = NULL;
12048 json_object *json_sub = NULL;
12049 json_no = json_object_new_object();
12050 json_sub = json_object_new_object();
12051 json_object_string_add(json_no, "warning", "Malformed address or name");
12052 json_object_string_add(json_sub, "warningCause", argv[0]);
12053 json_object_object_add(json_no, "detail", json_sub);
12054 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12055 json_object_free(json_no);
12056 }
12057 else
12058 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
a80beece
DS
12059 return CMD_WARNING;
12060 }
12061 }
12062 else
12063 {
12064 peer = peer_lookup (NULL, &su);
12065 if (! peer)
856ca177 12066 {
db7c8528 12067 if (uj)
856ca177
MS
12068 {
12069 json_object *json_no = NULL;
12070 json_no = json_object_new_object();
12071 json_object_string_add(json_no, "warning", "No Peer");
12072 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12073 json_object_free(json_no);
12074 }
12075 else
12076 vty_out (vty, "No peer%s", VTY_NEWLINE);
12077 return CMD_WARNING;
12078 }
c63b83fe 12079 }
718e3744 12080
12081 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
db7c8528 12082 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
718e3744 12083 if (count)
12084 {
db7c8528 12085 if (!uj)
856ca177 12086 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
db7c8528 12087 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
856ca177
MS
12088 }
12089 else
12090 {
db7c8528 12091 if (uj)
856ca177
MS
12092 {
12093 json_object *json_no = NULL;
12094 json_no = json_object_new_object();
12095 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12096 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12097 json_object_free(json_no);
12098 }
12099 else
12100 vty_out (vty, "No functional output%s", VTY_NEWLINE);
718e3744 12101 }
12102
12103 return CMD_SUCCESS;
12104}
12105
12106ALIAS (show_bgp_neighbor_received_prefix_filter,
12107 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
856ca177 12108 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 12109 SHOW_STR
12110 BGP_STR
12111 "Address family\n"
12112 "Detailed information on TCP and BGP neighbor connections\n"
12113 "Neighbor to display information about\n"
12114 "Neighbor to display information about\n"
a80beece 12115 "Neighbor on bgp configured interface\n"
718e3744 12116 "Display information received from a BGP neighbor\n"
856ca177
MS
12117 "Display the prefixlist filter\n"
12118 "JavaScript Object Notation\n")
718e3744 12119
12120/* old command */
bb46e94f 12121ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 12122 ipv6_bgp_neighbor_received_routes_cmd,
856ca177 12123 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 12124 SHOW_STR
12125 IPV6_STR
12126 BGP_STR
12127 "Detailed information on TCP and BGP neighbor connections\n"
12128 "Neighbor to display information about\n"
12129 "Neighbor to display information about\n"
a80beece 12130 "Neighbor on bgp configured interface\n"
856ca177
MS
12131 "Display the received routes from neighbor\n"
12132 "JavaScript Object Notation\n")
718e3744 12133
12134/* old command */
12135DEFUN (ipv6_mbgp_neighbor_received_routes,
12136 ipv6_mbgp_neighbor_received_routes_cmd,
856ca177 12137 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 12138 SHOW_STR
12139 IPV6_STR
12140 MBGP_STR
12141 "Detailed information on TCP and BGP neighbor connections\n"
12142 "Neighbor to display information about\n"
12143 "Neighbor to display information about\n"
a80beece 12144 "Neighbor on bgp configured interface\n"
856ca177
MS
12145 "Display the received routes from neighbor\n"
12146 "JavaScript Object Notation\n")
718e3744 12147{
bb46e94f 12148 struct peer *peer;
db7c8528 12149 u_char uj = use_json(argc, argv);
bb46e94f 12150
db7c8528 12151 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 12152 if (! peer)
12153 return CMD_WARNING;
12154
47e9b292 12155 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 12156 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj);
bb46e94f 12157}
12158
12159DEFUN (show_bgp_view_neighbor_received_prefix_filter,
12160 show_bgp_view_neighbor_received_prefix_filter_cmd,
856ca177 12161 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
bb46e94f 12162 SHOW_STR
12163 BGP_STR
12164 "BGP view\n"
12165 "View name\n"
12166 "Detailed information on TCP and BGP neighbor connections\n"
12167 "Neighbor to display information about\n"
12168 "Neighbor to display information about\n"
a80beece 12169 "Neighbor on bgp configured interface\n"
bb46e94f 12170 "Display information received from a BGP neighbor\n"
856ca177
MS
12171 "Display the prefixlist filter\n"
12172 "JavaScript Object Notation\n")
bb46e94f 12173{
12174 char name[BUFSIZ];
c63b83fe 12175 union sockunion su;
bb46e94f 12176 struct peer *peer;
12177 struct bgp *bgp;
c63b83fe 12178 int count, ret;
db7c8528 12179 u_char uj = use_json(argc, argv);
bb46e94f 12180
12181 /* BGP structure lookup. */
12182 bgp = bgp_lookup_by_name (argv[0]);
12183 if (bgp == NULL)
856ca177 12184 {
db7c8528 12185 if (uj)
856ca177
MS
12186 {
12187 json_object *json_no = NULL;
12188 json_no = json_object_new_object();
12189 json_object_string_add(json_no, "warning", "Can't find BGP view");
12190 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12191 json_object_free(json_no);
12192 }
12193 else
12194 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12195 return CMD_WARNING;
12196 }
12197
c63b83fe
JBD
12198 ret = str2sockunion (argv[1], &su);
12199 if (ret < 0)
12200 {
a80beece 12201 peer = peer_lookup_by_conf_if (bgp, argv[1]);
856ca177 12202 if (! peer)
a80beece 12203 {
db7c8528 12204 if (uj)
856ca177
MS
12205 {
12206 json_object *json_no = NULL;
12207 json_object *json_sub = NULL;
12208 json_no = json_object_new_object();
12209 json_sub = json_object_new_object();
12210 json_object_string_add(json_no, "warning", "Malformed address or name");
12211 json_object_string_add(json_sub, "warningCause", argv[1]);
12212 json_object_object_add(json_no, "detail", json_sub);
12213 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12214 json_object_free(json_no);
12215 }
12216 else
12217 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
a80beece
DS
12218 return CMD_WARNING;
12219 }
12220 }
12221 else
12222 {
12223 peer = peer_lookup (bgp, &su);
12224 if (! peer)
856ca177 12225 {
db7c8528 12226 if (uj)
856ca177
MS
12227 {
12228 json_object *json_no = NULL;
12229 json_no = json_object_new_object();
12230 json_object_boolean_true_add(json_no, "noPeer");
12231 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12232 json_object_free(json_no);
12233 }
12234 else
12235 vty_out (vty, "No peer%s", VTY_NEWLINE);
12236 return CMD_WARNING;
12237 }
12238
c63b83fe 12239 }
bb46e94f 12240
12241 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
db7c8528 12242 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
bb46e94f 12243 if (count)
12244 {
db7c8528 12245 if (!uj)
856ca177 12246 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
db7c8528 12247 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
bb46e94f 12248 }
12249
12250 return CMD_SUCCESS;
718e3744 12251}
bb46e94f 12252ALIAS (show_bgp_view_neighbor_received_prefix_filter,
12253 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
856ca177 12254 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
bb46e94f 12255 SHOW_STR
12256 BGP_STR
12257 "BGP view\n"
12258 "View name\n"
12259 "Address family\n"
12260 "Detailed information on TCP and BGP neighbor connections\n"
12261 "Neighbor to display information about\n"
12262 "Neighbor to display information about\n"
a80beece 12263 "Neighbor on bgp configured interface\n"
bb46e94f 12264 "Display information received from a BGP neighbor\n"
856ca177
MS
12265 "Display the prefixlist filter\n"
12266 "JavaScript Object NOtation\n")
718e3744 12267#endif /* HAVE_IPV6 */
6b0655a2 12268
94f2b392 12269static int
bb46e94f 12270bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
856ca177 12271 safi_t safi, enum bgp_show_type type, u_char use_json)
718e3744 12272{
718e3744 12273 if (! peer || ! peer->afc[afi][safi])
12274 {
856ca177
MS
12275 if (use_json)
12276 {
12277 json_object *json_no = NULL;
12278 json_no = json_object_new_object();
12279 json_object_string_add(json_no, "warning", "No such neighbor or address family");
12280 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12281 json_object_free(json_no);
12282 }
12283 else
12284 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
718e3744 12285 return CMD_WARNING;
12286 }
47fc97cc 12287
856ca177 12288 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json);
718e3744 12289}
12290
12291DEFUN (show_ip_bgp_neighbor_routes,
12292 show_ip_bgp_neighbor_routes_cmd,
856ca177 12293 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 12294 SHOW_STR
12295 IP_STR
12296 BGP_STR
12297 "Detailed information on TCP and BGP neighbor connections\n"
12298 "Neighbor to display information about\n"
12299 "Neighbor to display information about\n"
a80beece 12300 "Neighbor on bgp configured interface\n"
856ca177
MS
12301 "Display routes learned from neighbor\n"
12302 "JavaScript Object Notation\n")
718e3744 12303{
bb46e94f 12304 struct peer *peer;
db7c8528 12305 u_char uj = use_json(argc, argv);
856ca177 12306
db7c8528 12307 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 12308 if (! peer)
12309 return CMD_WARNING;
12310
12311 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 12312 bgp_show_type_neighbor, uj);
718e3744 12313}
12314
12315DEFUN (show_ip_bgp_neighbor_flap,
12316 show_ip_bgp_neighbor_flap_cmd,
856ca177 12317 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
718e3744 12318 SHOW_STR
12319 IP_STR
12320 BGP_STR
12321 "Detailed information on TCP and BGP neighbor connections\n"
12322 "Neighbor to display information about\n"
12323 "Neighbor to display information about\n"
a80beece 12324 "Neighbor on bgp configured interface\n"
856ca177
MS
12325 "Display flap statistics of the routes learned from neighbor\n"
12326 "JavaScript Object Notation\n")
718e3744 12327{
bb46e94f 12328 struct peer *peer;
db7c8528 12329 u_char uj = use_json(argc, argv);
856ca177 12330
db7c8528 12331 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 12332 if (! peer)
12333 return CMD_WARNING;
12334
12335 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 12336 bgp_show_type_flap_neighbor, uj);
718e3744 12337}
12338
12339DEFUN (show_ip_bgp_neighbor_damp,
12340 show_ip_bgp_neighbor_damp_cmd,
856ca177 12341 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
718e3744 12342 SHOW_STR
12343 IP_STR
12344 BGP_STR
12345 "Detailed information on TCP and BGP neighbor connections\n"
12346 "Neighbor to display information about\n"
12347 "Neighbor to display information about\n"
a80beece 12348 "Neighbor on bgp configured interface\n"
856ca177
MS
12349 "Display the dampened routes received from neighbor\n"
12350 "JavaScript Object Notation\n")
718e3744 12351{
bb46e94f 12352 struct peer *peer;
db7c8528 12353 u_char uj = use_json(argc, argv);
856ca177 12354
db7c8528 12355 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 12356 if (! peer)
12357 return CMD_WARNING;
12358
12359 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 12360 bgp_show_type_damp_neighbor, uj);
718e3744 12361}
12362
12363DEFUN (show_ip_bgp_ipv4_neighbor_routes,
12364 show_ip_bgp_ipv4_neighbor_routes_cmd,
856ca177 12365 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 12366 SHOW_STR
12367 IP_STR
12368 BGP_STR
12369 "Address family\n"
12370 "Address Family modifier\n"
12371 "Address Family modifier\n"
12372 "Detailed information on TCP and BGP neighbor connections\n"
12373 "Neighbor to display information about\n"
12374 "Neighbor to display information about\n"
a80beece 12375 "Neighbor on bgp configured interface\n"
856ca177
MS
12376 "Display routes learned from neighbor\n"
12377 "JavaScript Object Notation\n")
718e3744 12378{
bb46e94f 12379 struct peer *peer;
db7c8528 12380 u_char uj = use_json(argc, argv);
bb46e94f 12381
db7c8528 12382 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 12383 if (! peer)
12384 return CMD_WARNING;
12385
718e3744 12386 if (strncmp (argv[0], "m", 1) == 0)
bb46e94f 12387 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
db7c8528 12388 bgp_show_type_neighbor, uj);
718e3744 12389
bb46e94f 12390 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 12391 bgp_show_type_neighbor, uj);
718e3744 12392}
bb46e94f 12393
2a3d5731
DW
12394#ifdef HAVE_IPV6
12395DEFUN (show_bgp_view_neighbor_routes,
12396 show_bgp_view_neighbor_routes_cmd,
12397 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
fee0f4c6 12398 SHOW_STR
fee0f4c6 12399 BGP_STR
12400 "BGP view\n"
2b00515a 12401 "View name\n"
2a3d5731
DW
12402 "Detailed information on TCP and BGP neighbor connections\n"
12403 "Neighbor to display information about\n"
12404 "Neighbor to display information about\n"
12405 "Neighbor on bgp configured interface\n"
12406 "Display routes learned from neighbor\n"
12407 "JavaScript Object Notation\n")
fee0f4c6 12408{
fee0f4c6 12409 struct peer *peer;
db7c8528 12410 u_char uj = use_json(argc, argv);
fee0f4c6 12411
2a3d5731
DW
12412 if ((argc == 3 && argv[2] && strcmp(argv[2], "json") == 0)
12413 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
db7c8528 12414 peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
2a3d5731 12415 else
db7c8528 12416 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
2a3d5731 12417
fee0f4c6 12418 if (! peer)
12419 return CMD_WARNING;
12420
2a3d5731 12421 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
db7c8528 12422 bgp_show_type_neighbor, uj);
fee0f4c6 12423}
12424
2a3d5731
DW
12425ALIAS (show_bgp_view_neighbor_routes,
12426 show_bgp_view_ipv6_neighbor_routes_cmd,
12427 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
fee0f4c6 12428 SHOW_STR
fee0f4c6 12429 BGP_STR
2a3d5731
DW
12430 "BGP view\n"
12431 "View name\n"
12432 "Address family\n"
12433 "Detailed information on TCP and BGP neighbor connections\n"
12434 "Neighbor to display information about\n"
12435 "Neighbor to display information about\n"
12436 "Neighbor on bgp configured interface\n"
12437 "Display routes learned from neighbor\n"
12438 "JavaScript Object Notation\n")
fee0f4c6 12439
2a3d5731
DW
12440DEFUN (show_bgp_view_neighbor_damp,
12441 show_bgp_view_neighbor_damp_cmd,
12442 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
fee0f4c6 12443 SHOW_STR
fee0f4c6 12444 BGP_STR
12445 "BGP view\n"
2b00515a 12446 "View name\n"
2a3d5731
DW
12447 "Detailed information on TCP and BGP neighbor connections\n"
12448 "Neighbor to display information about\n"
12449 "Neighbor to display information about\n"
12450 "Neighbor on bgp configured interface\n"
12451 "Display the dampened routes received from neighbor\n"
12452 "JavaScript Object Notation\n")
bb46e94f 12453{
12454 struct peer *peer;
db7c8528 12455 u_char uj = use_json(argc, argv);
856ca177
MS
12456
12457 if ((argc == 3 && argv[2] && strcmp(argv[2], "json") == 0)
12458 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
db7c8528 12459 peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
bb46e94f 12460 else
db7c8528 12461 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 12462
12463 if (! peer)
12464 return CMD_WARNING;
12465
12466 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
db7c8528 12467 bgp_show_type_damp_neighbor, uj);
bb46e94f 12468}
12469
12470ALIAS (show_bgp_view_neighbor_damp,
12471 show_bgp_view_ipv6_neighbor_damp_cmd,
856ca177 12472 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
bb46e94f 12473 SHOW_STR
12474 BGP_STR
12475 "BGP view\n"
2b00515a 12476 "View name\n"
bb46e94f 12477 "Address family\n"
12478 "Detailed information on TCP and BGP neighbor connections\n"
12479 "Neighbor to display information about\n"
12480 "Neighbor to display information about\n"
a80beece 12481 "Neighbor on bgp configured interface\n"
856ca177
MS
12482 "Display the dampened routes received from neighbor\n"
12483 "JavaScript Object Notation\n")
bb46e94f 12484
12485DEFUN (show_bgp_view_neighbor_flap,
12486 show_bgp_view_neighbor_flap_cmd,
856ca177 12487 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 12488 SHOW_STR
12489 BGP_STR
12490 "BGP view\n"
2b00515a 12491 "View name\n"
bb46e94f 12492 "Detailed information on TCP and BGP neighbor connections\n"
12493 "Neighbor to display information about\n"
12494 "Neighbor to display information about\n"
a80beece 12495 "Neighbor on bgp configured interface\n"
856ca177
MS
12496 "Display flap statistics of the routes learned from neighbor\n"
12497 "JavaScript Object Notation\n")
bb46e94f 12498{
12499 struct peer *peer;
db7c8528 12500 u_char uj = use_json(argc, argv);
856ca177
MS
12501
12502 if ((argc == 3 && argv[2] && strcmp(argv[2], "json") == 0)
12503 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
db7c8528 12504 peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
bb46e94f 12505 else
db7c8528 12506 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 12507
12508 if (! peer)
12509 return CMD_WARNING;
12510
12511 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
db7c8528 12512 bgp_show_type_flap_neighbor, uj);
bb46e94f 12513}
12514
12515ALIAS (show_bgp_view_neighbor_flap,
12516 show_bgp_view_ipv6_neighbor_flap_cmd,
856ca177 12517 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 12518 SHOW_STR
12519 BGP_STR
12520 "BGP view\n"
2b00515a 12521 "View name\n"
bb46e94f 12522 "Address family\n"
12523 "Detailed information on TCP and BGP neighbor connections\n"
12524 "Neighbor to display information about\n"
12525 "Neighbor to display information about\n"
a80beece 12526 "Neighbor on bgp configured interface\n"
856ca177
MS
12527 "Display flap statistics of the routes learned from neighbor\n"
12528 "JavaScript Object Notation\n")
bb46e94f 12529
12530ALIAS (show_bgp_view_neighbor_routes,
12531 show_bgp_neighbor_routes_cmd,
856ca177 12532 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
bb46e94f 12533 SHOW_STR
12534 BGP_STR
12535 "Detailed information on TCP and BGP neighbor connections\n"
12536 "Neighbor to display information about\n"
12537 "Neighbor to display information about\n"
a80beece 12538 "Neighbor on bgp configured interface\n"
856ca177
MS
12539 "Display routes learned from neighbor\n"
12540 "JavaScript Object Notation\n")
bb46e94f 12541
12542
12543ALIAS (show_bgp_view_neighbor_routes,
718e3744 12544 show_bgp_ipv6_neighbor_routes_cmd,
856ca177 12545 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 12546 SHOW_STR
12547 BGP_STR
12548 "Address family\n"
12549 "Detailed information on TCP and BGP neighbor connections\n"
12550 "Neighbor to display information about\n"
12551 "Neighbor to display information about\n"
a80beece 12552 "Neighbor on bgp configured interface\n"
856ca177
MS
12553 "Display routes learned from neighbor\n"
12554 "JavaScript Object Notation\n")
718e3744 12555
12556/* old command */
bb46e94f 12557ALIAS (show_bgp_view_neighbor_routes,
718e3744 12558 ipv6_bgp_neighbor_routes_cmd,
856ca177 12559 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 12560 SHOW_STR
12561 IPV6_STR
12562 BGP_STR
12563 "Detailed information on TCP and BGP neighbor connections\n"
12564 "Neighbor to display information about\n"
12565 "Neighbor to display information about\n"
a80beece 12566 "Neighbor on bgp configured interface\n"
856ca177
MS
12567 "Display routes learned from neighbor\n"
12568 "JavaScript Object Notation\n")
718e3744 12569
12570/* old command */
12571DEFUN (ipv6_mbgp_neighbor_routes,
12572 ipv6_mbgp_neighbor_routes_cmd,
856ca177 12573 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 12574 SHOW_STR
12575 IPV6_STR
12576 MBGP_STR
12577 "Detailed information on TCP and BGP neighbor connections\n"
12578 "Neighbor to display information about\n"
12579 "Neighbor to display information about\n"
a80beece 12580 "Neighbor on bgp configured interface\n"
856ca177
MS
12581 "Display routes learned from neighbor\n"
12582 "JavaScript Object Notation\n")
718e3744 12583{
bb46e94f 12584 struct peer *peer;
db7c8528 12585 u_char uj = use_json(argc, argv);
bb46e94f 12586
db7c8528 12587 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 12588 if (! peer)
12589 return CMD_WARNING;
12590
47e9b292 12591 bgp_show_ipv6_bgp_deprecate_warning(vty);
bb46e94f 12592 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
db7c8528 12593 bgp_show_type_neighbor, uj);
718e3744 12594}
bb46e94f 12595
12596ALIAS (show_bgp_view_neighbor_flap,
12597 show_bgp_neighbor_flap_cmd,
856ca177 12598 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 12599 SHOW_STR
12600 BGP_STR
12601 "Detailed information on TCP and BGP neighbor connections\n"
12602 "Neighbor to display information about\n"
12603 "Neighbor to display information about\n"
a80beece 12604 "Neighbor on bgp configured interface\n"
856ca177
MS
12605 "Display flap statistics of the routes learned from neighbor\n"
12606 "JavaScript Object Notation\n")
bb46e94f 12607
12608ALIAS (show_bgp_view_neighbor_flap,
12609 show_bgp_ipv6_neighbor_flap_cmd,
856ca177 12610 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 12611 SHOW_STR
12612 BGP_STR
12613 "Address family\n"
12614 "Detailed information on TCP and BGP neighbor connections\n"
12615 "Neighbor to display information about\n"
12616 "Neighbor to display information about\n"
a80beece 12617 "Neighbor on bgp configured interface\n"
856ca177
MS
12618 "Display flap statistics of the routes learned from neighbor\n"
12619 "JavaScript Object Notation\n")
bb46e94f 12620
12621ALIAS (show_bgp_view_neighbor_damp,
12622 show_bgp_neighbor_damp_cmd,
856ca177 12623 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
bb46e94f 12624 SHOW_STR
12625 BGP_STR
12626 "Detailed information on TCP and BGP neighbor connections\n"
12627 "Neighbor to display information about\n"
12628 "Neighbor to display information about\n"
a80beece 12629 "Neighbor on bgp configured interface\n"
856ca177
MS
12630 "Display the dampened routes received from neighbor\n"
12631 "JavaScript Object Notation\n")
bb46e94f 12632
12633ALIAS (show_bgp_view_neighbor_damp,
12634 show_bgp_ipv6_neighbor_damp_cmd,
856ca177 12635 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
bb46e94f 12636 SHOW_STR
12637 BGP_STR
12638 "Address family\n"
12639 "Detailed information on TCP and BGP neighbor connections\n"
12640 "Neighbor to display information about\n"
12641 "Neighbor to display information about\n"
a80beece 12642 "Neighbor on bgp configured interface\n"
856ca177
MS
12643 "Display the dampened routes received from neighbor\n"
12644 "JavaScript Object Notation\n")
fee0f4c6 12645
718e3744 12646#endif /* HAVE_IPV6 */
6b0655a2 12647
718e3744 12648struct bgp_table *bgp_distance_table;
12649
12650struct bgp_distance
12651{
12652 /* Distance value for the IP source prefix. */
12653 u_char distance;
12654
12655 /* Name of the access-list to be matched. */
12656 char *access_list;
12657};
12658
94f2b392 12659static struct bgp_distance *
66e5cd87 12660bgp_distance_new (void)
718e3744 12661{
393deb9b 12662 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
718e3744 12663}
12664
94f2b392 12665static void
718e3744 12666bgp_distance_free (struct bgp_distance *bdistance)
12667{
12668 XFREE (MTYPE_BGP_DISTANCE, bdistance);
12669}
12670
94f2b392 12671static int
fd79ac91 12672bgp_distance_set (struct vty *vty, const char *distance_str,
12673 const char *ip_str, const char *access_list_str)
718e3744 12674{
12675 int ret;
12676 struct prefix_ipv4 p;
12677 u_char distance;
12678 struct bgp_node *rn;
12679 struct bgp_distance *bdistance;
12680
12681 ret = str2prefix_ipv4 (ip_str, &p);
12682 if (ret == 0)
12683 {
12684 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
12685 return CMD_WARNING;
12686 }
12687
12688 distance = atoi (distance_str);
12689
12690 /* Get BGP distance node. */
12691 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
12692 if (rn->info)
12693 {
12694 bdistance = rn->info;
12695 bgp_unlock_node (rn);
12696 }
12697 else
12698 {
12699 bdistance = bgp_distance_new ();
12700 rn->info = bdistance;
12701 }
12702
12703 /* Set distance value. */
12704 bdistance->distance = distance;
12705
12706 /* Reset access-list configuration. */
12707 if (bdistance->access_list)
12708 {
6e919709 12709 XFREE(MTYPE_AS_LIST, bdistance->access_list);
718e3744 12710 bdistance->access_list = NULL;
12711 }
12712 if (access_list_str)
6e919709 12713 bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str);
718e3744 12714
12715 return CMD_SUCCESS;
12716}
12717
94f2b392 12718static int
fd79ac91 12719bgp_distance_unset (struct vty *vty, const char *distance_str,
12720 const char *ip_str, const char *access_list_str)
718e3744 12721{
12722 int ret;
12723 struct prefix_ipv4 p;
718e3744 12724 struct bgp_node *rn;
12725 struct bgp_distance *bdistance;
12726
12727 ret = str2prefix_ipv4 (ip_str, &p);
12728 if (ret == 0)
12729 {
12730 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
12731 return CMD_WARNING;
12732 }
12733
718e3744 12734 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
12735 if (! rn)
12736 {
12737 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
12738 return CMD_WARNING;
12739 }
12740
12741 bdistance = rn->info;
12742
12743 if (bdistance->access_list)
6e919709 12744 XFREE(MTYPE_AS_LIST, bdistance->access_list);
718e3744 12745 bgp_distance_free (bdistance);
12746
12747 rn->info = NULL;
12748 bgp_unlock_node (rn);
12749 bgp_unlock_node (rn);
12750
12751 return CMD_SUCCESS;
12752}
12753
718e3744 12754/* Apply BGP information to distance method. */
12755u_char
12756bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
12757{
12758 struct bgp_node *rn;
12759 struct prefix_ipv4 q;
12760 struct peer *peer;
12761 struct bgp_distance *bdistance;
12762 struct access_list *alist;
12763 struct bgp_static *bgp_static;
12764
12765 if (! bgp)
12766 return 0;
12767
12768 if (p->family != AF_INET)
12769 return 0;
12770
12771 peer = rinfo->peer;
12772
12773 if (peer->su.sa.sa_family != AF_INET)
12774 return 0;
12775
12776 memset (&q, 0, sizeof (struct prefix_ipv4));
12777 q.family = AF_INET;
12778 q.prefix = peer->su.sin.sin_addr;
12779 q.prefixlen = IPV4_MAX_BITLEN;
12780
12781 /* Check source address. */
12782 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
12783 if (rn)
12784 {
12785 bdistance = rn->info;
12786 bgp_unlock_node (rn);
12787
12788 if (bdistance->access_list)
12789 {
12790 alist = access_list_lookup (AFI_IP, bdistance->access_list);
12791 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
12792 return bdistance->distance;
12793 }
12794 else
12795 return bdistance->distance;
12796 }
12797
12798 /* Backdoor check. */
12799 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
12800 if (rn)
12801 {
12802 bgp_static = rn->info;
12803 bgp_unlock_node (rn);
12804
12805 if (bgp_static->backdoor)
12806 {
12807 if (bgp->distance_local)
12808 return bgp->distance_local;
12809 else
12810 return ZEBRA_IBGP_DISTANCE_DEFAULT;
12811 }
12812 }
12813
6d85b15b 12814 if (peer->sort == BGP_PEER_EBGP)
718e3744 12815 {
12816 if (bgp->distance_ebgp)
12817 return bgp->distance_ebgp;
12818 return ZEBRA_EBGP_DISTANCE_DEFAULT;
12819 }
12820 else
12821 {
12822 if (bgp->distance_ibgp)
12823 return bgp->distance_ibgp;
12824 return ZEBRA_IBGP_DISTANCE_DEFAULT;
12825 }
12826}
12827
12828DEFUN (bgp_distance,
12829 bgp_distance_cmd,
12830 "distance bgp <1-255> <1-255> <1-255>",
12831 "Define an administrative distance\n"
12832 "BGP distance\n"
12833 "Distance for routes external to the AS\n"
12834 "Distance for routes internal to the AS\n"
12835 "Distance for local routes\n")
12836{
12837 struct bgp *bgp;
12838
12839 bgp = vty->index;
12840
12841 bgp->distance_ebgp = atoi (argv[0]);
12842 bgp->distance_ibgp = atoi (argv[1]);
12843 bgp->distance_local = atoi (argv[2]);
12844 return CMD_SUCCESS;
12845}
12846
12847DEFUN (no_bgp_distance,
12848 no_bgp_distance_cmd,
12849 "no distance bgp <1-255> <1-255> <1-255>",
12850 NO_STR
12851 "Define an administrative distance\n"
12852 "BGP distance\n"
12853 "Distance for routes external to the AS\n"
12854 "Distance for routes internal to the AS\n"
12855 "Distance for local routes\n")
12856{
12857 struct bgp *bgp;
12858
12859 bgp = vty->index;
12860
12861 bgp->distance_ebgp= 0;
12862 bgp->distance_ibgp = 0;
12863 bgp->distance_local = 0;
12864 return CMD_SUCCESS;
12865}
12866
12867ALIAS (no_bgp_distance,
12868 no_bgp_distance2_cmd,
12869 "no distance bgp",
12870 NO_STR
12871 "Define an administrative distance\n"
12872 "BGP distance\n")
12873
12874DEFUN (bgp_distance_source,
12875 bgp_distance_source_cmd,
12876 "distance <1-255> A.B.C.D/M",
12877 "Define an administrative distance\n"
12878 "Administrative distance\n"
12879 "IP source prefix\n")
12880{
12881 bgp_distance_set (vty, argv[0], argv[1], NULL);
12882 return CMD_SUCCESS;
12883}
12884
12885DEFUN (no_bgp_distance_source,
12886 no_bgp_distance_source_cmd,
12887 "no distance <1-255> A.B.C.D/M",
12888 NO_STR
12889 "Define an administrative distance\n"
12890 "Administrative distance\n"
12891 "IP source prefix\n")
12892{
12893 bgp_distance_unset (vty, argv[0], argv[1], NULL);
12894 return CMD_SUCCESS;
12895}
12896
12897DEFUN (bgp_distance_source_access_list,
12898 bgp_distance_source_access_list_cmd,
12899 "distance <1-255> A.B.C.D/M WORD",
12900 "Define an administrative distance\n"
12901 "Administrative distance\n"
12902 "IP source prefix\n"
12903 "Access list name\n")
12904{
12905 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
12906 return CMD_SUCCESS;
12907}
12908
12909DEFUN (no_bgp_distance_source_access_list,
12910 no_bgp_distance_source_access_list_cmd,
12911 "no distance <1-255> A.B.C.D/M WORD",
12912 NO_STR
12913 "Define an administrative distance\n"
12914 "Administrative distance\n"
12915 "IP source prefix\n"
12916 "Access list name\n")
12917{
12918 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
12919 return CMD_SUCCESS;
12920}
6b0655a2 12921
718e3744 12922DEFUN (bgp_damp_set,
12923 bgp_damp_set_cmd,
12924 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12925 "BGP Specific commands\n"
12926 "Enable route-flap dampening\n"
12927 "Half-life time for the penalty\n"
12928 "Value to start reusing a route\n"
12929 "Value to start suppressing a route\n"
12930 "Maximum duration to suppress a stable route\n")
12931{
12932 struct bgp *bgp;
12933 int half = DEFAULT_HALF_LIFE * 60;
12934 int reuse = DEFAULT_REUSE;
12935 int suppress = DEFAULT_SUPPRESS;
12936 int max = 4 * half;
12937
12938 if (argc == 4)
12939 {
12940 half = atoi (argv[0]) * 60;
12941 reuse = atoi (argv[1]);
12942 suppress = atoi (argv[2]);
12943 max = atoi (argv[3]) * 60;
12944 }
12945 else if (argc == 1)
12946 {
12947 half = atoi (argv[0]) * 60;
12948 max = 4 * half;
12949 }
12950
12951 bgp = vty->index;
12952 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
12953 half, reuse, suppress, max);
12954}
12955
12956ALIAS (bgp_damp_set,
12957 bgp_damp_set2_cmd,
12958 "bgp dampening <1-45>",
12959 "BGP Specific commands\n"
12960 "Enable route-flap dampening\n"
12961 "Half-life time for the penalty\n")
12962
12963ALIAS (bgp_damp_set,
12964 bgp_damp_set3_cmd,
12965 "bgp dampening",
12966 "BGP Specific commands\n"
12967 "Enable route-flap dampening\n")
12968
12969DEFUN (bgp_damp_unset,
12970 bgp_damp_unset_cmd,
12971 "no bgp dampening",
12972 NO_STR
12973 "BGP Specific commands\n"
12974 "Enable route-flap dampening\n")
12975{
12976 struct bgp *bgp;
12977
12978 bgp = vty->index;
12979 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12980}
12981
12982ALIAS (bgp_damp_unset,
12983 bgp_damp_unset2_cmd,
12984 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12985 NO_STR
12986 "BGP Specific commands\n"
12987 "Enable route-flap dampening\n"
12988 "Half-life time for the penalty\n"
12989 "Value to start reusing a route\n"
12990 "Value to start suppressing a route\n"
12991 "Maximum duration to suppress a stable route\n")
12992
12993DEFUN (show_ip_bgp_dampened_paths,
12994 show_ip_bgp_dampened_paths_cmd,
12995 "show ip bgp dampened-paths",
12996 SHOW_STR
12997 IP_STR
12998 BGP_STR
12999 "Display paths suppressed due to dampening\n")
13000{
5a646650 13001 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
b05a1c8b 13002 NULL, 0);
718e3744 13003}
13004
13005DEFUN (show_ip_bgp_flap_statistics,
13006 show_ip_bgp_flap_statistics_cmd,
13007 "show ip bgp flap-statistics",
13008 SHOW_STR
13009 IP_STR
13010 BGP_STR
13011 "Display flap statistics of routes\n")
13012{
5a646650 13013 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 13014 bgp_show_type_flap_statistics, NULL, 0);
718e3744 13015}
6b0655a2 13016
718e3744 13017/* Display specified route of BGP table. */
94f2b392 13018static int
fd79ac91 13019bgp_clear_damp_route (struct vty *vty, const char *view_name,
13020 const char *ip_str, afi_t afi, safi_t safi,
13021 struct prefix_rd *prd, int prefix_check)
718e3744 13022{
13023 int ret;
13024 struct prefix match;
13025 struct bgp_node *rn;
13026 struct bgp_node *rm;
13027 struct bgp_info *ri;
13028 struct bgp_info *ri_temp;
13029 struct bgp *bgp;
13030 struct bgp_table *table;
13031
13032 /* BGP structure lookup. */
13033 if (view_name)
13034 {
13035 bgp = bgp_lookup_by_name (view_name);
13036 if (bgp == NULL)
13037 {
13038 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
13039 return CMD_WARNING;
13040 }
13041 }
13042 else
13043 {
13044 bgp = bgp_get_default ();
13045 if (bgp == NULL)
13046 {
13047 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
13048 return CMD_WARNING;
13049 }
13050 }
13051
13052 /* Check IP address argument. */
13053 ret = str2prefix (ip_str, &match);
13054 if (! ret)
13055 {
13056 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
13057 return CMD_WARNING;
13058 }
13059
13060 match.family = afi2family (afi);
13061
13062 if (safi == SAFI_MPLS_VPN)
13063 {
13064 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
13065 {
13066 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
13067 continue;
13068
13069 if ((table = rn->info) != NULL)
13070 if ((rm = bgp_node_match (table, &match)) != NULL)
6c88b44d
CC
13071 {
13072 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
13073 {
13074 ri = rm->info;
13075 while (ri)
13076 {
13077 if (ri->extra && ri->extra->damp_info)
13078 {
13079 ri_temp = ri->next;
13080 bgp_damp_info_free (ri->extra->damp_info, 1);
13081 ri = ri_temp;
13082 }
13083 else
13084 ri = ri->next;
13085 }
13086 }
13087
13088 bgp_unlock_node (rm);
13089 }
718e3744 13090 }
13091 }
13092 else
13093 {
13094 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
6c88b44d
CC
13095 {
13096 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
13097 {
13098 ri = rn->info;
13099 while (ri)
13100 {
13101 if (ri->extra && ri->extra->damp_info)
13102 {
13103 ri_temp = ri->next;
13104 bgp_damp_info_free (ri->extra->damp_info, 1);
13105 ri = ri_temp;
13106 }
13107 else
13108 ri = ri->next;
13109 }
13110 }
13111
13112 bgp_unlock_node (rn);
13113 }
718e3744 13114 }
13115
13116 return CMD_SUCCESS;
13117}
13118
13119DEFUN (clear_ip_bgp_dampening,
13120 clear_ip_bgp_dampening_cmd,
13121 "clear ip bgp dampening",
13122 CLEAR_STR
13123 IP_STR
13124 BGP_STR
13125 "Clear route flap dampening information\n")
13126{
13127 bgp_damp_info_clean ();
13128 return CMD_SUCCESS;
13129}
13130
13131DEFUN (clear_ip_bgp_dampening_prefix,
13132 clear_ip_bgp_dampening_prefix_cmd,
13133 "clear ip bgp dampening A.B.C.D/M",
13134 CLEAR_STR
13135 IP_STR
13136 BGP_STR
13137 "Clear route flap dampening information\n"
13138 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13139{
13140 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
13141 SAFI_UNICAST, NULL, 1);
13142}
13143
13144DEFUN (clear_ip_bgp_dampening_address,
13145 clear_ip_bgp_dampening_address_cmd,
13146 "clear ip bgp dampening A.B.C.D",
13147 CLEAR_STR
13148 IP_STR
13149 BGP_STR
13150 "Clear route flap dampening information\n"
13151 "Network to clear damping information\n")
13152{
13153 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
13154 SAFI_UNICAST, NULL, 0);
13155}
13156
13157DEFUN (clear_ip_bgp_dampening_address_mask,
13158 clear_ip_bgp_dampening_address_mask_cmd,
13159 "clear ip bgp dampening A.B.C.D A.B.C.D",
13160 CLEAR_STR
13161 IP_STR
13162 BGP_STR
13163 "Clear route flap dampening information\n"
13164 "Network to clear damping information\n"
13165 "Network mask\n")
13166{
13167 int ret;
13168 char prefix_str[BUFSIZ];
13169
13170 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
13171 if (! ret)
13172 {
13173 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
13174 return CMD_WARNING;
13175 }
13176
13177 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
13178 SAFI_UNICAST, NULL, 0);
13179}
6b0655a2 13180
94f2b392 13181static int
718e3744 13182bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
13183 afi_t afi, safi_t safi, int *write)
13184{
13185 struct bgp_node *prn;
13186 struct bgp_node *rn;
13187 struct bgp_table *table;
13188 struct prefix *p;
13189 struct prefix_rd *prd;
13190 struct bgp_static *bgp_static;
13191 u_int32_t label;
13192 char buf[SU_ADDRSTRLEN];
13193 char rdbuf[RD_ADDRSTRLEN];
13194
13195 /* Network configuration. */
13196 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
13197 if ((table = prn->info) != NULL)
13198 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
13199 if ((bgp_static = rn->info) != NULL)
13200 {
13201 p = &rn->p;
13202 prd = (struct prefix_rd *) &prn->p;
13203
13204 /* "address-family" display. */
13205 bgp_config_write_family_header (vty, afi, safi, write);
13206
13207 /* "network" configuration display. */
13208 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
13209 label = decode_label (bgp_static->tag);
13210
0b960b4d 13211 vty_out (vty, " network %s/%d rd %s tag %d",
718e3744 13212 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13213 p->prefixlen,
13214 rdbuf, label);
13215 vty_out (vty, "%s", VTY_NEWLINE);
13216 }
13217 return 0;
13218}
13219
13220/* Configuration of static route announcement and aggregate
13221 information. */
13222int
13223bgp_config_write_network (struct vty *vty, struct bgp *bgp,
13224 afi_t afi, safi_t safi, int *write)
13225{
13226 struct bgp_node *rn;
13227 struct prefix *p;
13228 struct bgp_static *bgp_static;
13229 struct bgp_aggregate *bgp_aggregate;
13230 char buf[SU_ADDRSTRLEN];
13231
13232 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
13233 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
13234
13235 /* Network configuration. */
13236 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
13237 if ((bgp_static = rn->info) != NULL)
13238 {
13239 p = &rn->p;
13240
13241 /* "address-family" display. */
13242 bgp_config_write_family_header (vty, afi, safi, write);
13243
13244 /* "network" configuration display. */
13245 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
13246 {
13247 u_int32_t destination;
13248 struct in_addr netmask;
13249
13250 destination = ntohl (p->u.prefix4.s_addr);
13251 masklen2ip (p->prefixlen, &netmask);
0b960b4d 13252 vty_out (vty, " network %s",
718e3744 13253 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
13254
13255 if ((IN_CLASSC (destination) && p->prefixlen == 24)
13256 || (IN_CLASSB (destination) && p->prefixlen == 16)
13257 || (IN_CLASSA (destination) && p->prefixlen == 8)
13258 || p->u.prefix4.s_addr == 0)
13259 {
13260 /* Natural mask is not display. */
13261 }
13262 else
13263 vty_out (vty, " mask %s", inet_ntoa (netmask));
13264 }
13265 else
13266 {
0b960b4d 13267 vty_out (vty, " network %s/%d",
718e3744 13268 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13269 p->prefixlen);
13270 }
13271
13272 if (bgp_static->rmap.name)
13273 vty_out (vty, " route-map %s", bgp_static->rmap.name);
41367172
PJ
13274 else
13275 {
13276 if (bgp_static->backdoor)
13277 vty_out (vty, " backdoor");
41367172 13278 }
718e3744 13279
13280 vty_out (vty, "%s", VTY_NEWLINE);
13281 }
13282
13283 /* Aggregate-address configuration. */
13284 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
13285 if ((bgp_aggregate = rn->info) != NULL)
13286 {
13287 p = &rn->p;
13288
13289 /* "address-family" display. */
13290 bgp_config_write_family_header (vty, afi, safi, write);
13291
13292 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
13293 {
13294 struct in_addr netmask;
13295
13296 masklen2ip (p->prefixlen, &netmask);
0b960b4d 13297 vty_out (vty, " aggregate-address %s %s",
718e3744 13298 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13299 inet_ntoa (netmask));
13300 }
13301 else
13302 {
0b960b4d 13303 vty_out (vty, " aggregate-address %s/%d",
718e3744 13304 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13305 p->prefixlen);
13306 }
13307
13308 if (bgp_aggregate->as_set)
13309 vty_out (vty, " as-set");
13310
13311 if (bgp_aggregate->summary_only)
13312 vty_out (vty, " summary-only");
13313
13314 vty_out (vty, "%s", VTY_NEWLINE);
13315 }
13316
13317 return 0;
13318}
13319
13320int
13321bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
13322{
13323 struct bgp_node *rn;
13324 struct bgp_distance *bdistance;
13325
13326 /* Distance configuration. */
13327 if (bgp->distance_ebgp
13328 && bgp->distance_ibgp
13329 && bgp->distance_local
13330 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
13331 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
13332 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
13333 vty_out (vty, " distance bgp %d %d %d%s",
13334 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
13335 VTY_NEWLINE);
13336
13337 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
13338 if ((bdistance = rn->info) != NULL)
13339 {
13340 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
13341 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
13342 bdistance->access_list ? bdistance->access_list : "",
13343 VTY_NEWLINE);
13344 }
13345
13346 return 0;
13347}
13348
13349/* Allocate routing table structure and install commands. */
13350void
66e5cd87 13351bgp_route_init (void)
718e3744 13352{
13353 /* Init BGP distance table. */
64e580a7 13354 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
718e3744 13355
13356 /* IPv4 BGP commands. */
73ac8160 13357 install_element (BGP_NODE, &bgp_table_map_cmd);
718e3744 13358 install_element (BGP_NODE, &bgp_network_cmd);
13359 install_element (BGP_NODE, &bgp_network_mask_cmd);
13360 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
13361 install_element (BGP_NODE, &bgp_network_route_map_cmd);
13362 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
13363 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
13364 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
13365 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
13366 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
73ac8160 13367 install_element (BGP_NODE, &no_bgp_table_map_cmd);
718e3744 13368 install_element (BGP_NODE, &no_bgp_network_cmd);
13369 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
13370 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
13371 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
13372 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
13373 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
13374 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
13375 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
13376 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
13377
13378 install_element (BGP_NODE, &aggregate_address_cmd);
13379 install_element (BGP_NODE, &aggregate_address_mask_cmd);
13380 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
13381 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
13382 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
13383 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
13384 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
13385 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
13386 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
13387 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
13388 install_element (BGP_NODE, &no_aggregate_address_cmd);
13389 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
13390 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
13391 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
13392 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
13393 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
13394 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
13395 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
13396 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
13397 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
13398
13399 /* IPv4 unicast configuration. */
73ac8160 13400 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
718e3744 13401 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
13402 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
13403 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
13404 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
13405 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
13406 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 13407 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
c8f3fe30 13408 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
718e3744 13409 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
13410 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
13411 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
13412 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
13413 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
c8f3fe30 13414
718e3744 13415 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
13416 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
13417 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
13418 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
13419 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
13420 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
13421 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
13422 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
13423 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
13424 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
13425 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
13426 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
13427 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
13428 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
13429 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
13430 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
13431 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
13432 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
13433 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
13434 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
13435
13436 /* IPv4 multicast configuration. */
73ac8160 13437 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
718e3744 13438 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
13439 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
13440 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
13441 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
13442 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
13443 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 13444 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
718e3744 13445 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
13446 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
13447 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
13448 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
13449 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
13450 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
13451 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
13452 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
13453 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
13454 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
13455 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
13456 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
13457 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
13458 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
13459 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
13460 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
13461 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
13462 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
13463 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
13464 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
13465 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
13466 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
13467 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
13468 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
13469 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
13470 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
13471
13472 install_element (VIEW_NODE, &show_ip_bgp_cmd);
13473 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 13474 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
718e3744 13475 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
13476 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
13477 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 13478 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 13479 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 13480 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
13481 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
13482 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
13483 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
13484 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
13485 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 13486 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 13487 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
718e3744 13488 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
13489 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
13490 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
13491 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
13492 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
13493 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
13494 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
13495 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
13496 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
13497 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
13498 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
13499 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
13500 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
13501 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
13502 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
13503 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
13504 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
13505 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
13506 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
13507 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
13508 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
13509 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
13510 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
13511 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
13512 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
13513 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
13514 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
13515 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
13516 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
13517 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
718e3744 13518 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
13519 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
13520 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
13521 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
13522 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
13523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
13524 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
13525 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
13526 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
13527 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
13528 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
13529 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
13530 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
13531 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
13532 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
0b16f239 13533 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
718e3744 13534 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
0b16f239 13535 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
718e3744 13536 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
0b16f239 13537 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
718e3744 13538 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
0b16f239 13539 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
95cbbd2a 13540 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 13541 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
13542 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
13543 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
13544 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
13545 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
13546 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
13547 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
13548 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
13549 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
13550 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
13551 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
13552 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
13553 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
13554 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
13555 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
13556 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
2a71e9ce
TP
13557 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
13558 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
62687ff1
PJ
13559
13560 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
13561 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
13562 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
13563 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
62687ff1 13564 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 13565 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
62687ff1
PJ
13566 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
13567 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
13568 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
13569 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
13570 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 13571 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 13572 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
62687ff1
PJ
13573 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
13574 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
13575 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
13576 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
13577 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
13578 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
13579 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
13580 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
13581 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
13582 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
13583 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
13584 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
13585 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
13586 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
13587 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
13588 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
13589 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
62687ff1
PJ
13590 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
13591 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
13592 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
13593 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
13594 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
13595 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
13596 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
13597 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
718e3744 13598
13599 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
13600 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 13601 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
718e3744 13602 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
13603 install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd);
13604 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 13605 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 13606 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 13607 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
13608 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
13609 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
13610 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
13611 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
13612 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 13613 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 13614 install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd);
718e3744 13615 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
13616 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
13617 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
13618 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
13619 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
13620 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
13621 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
13622 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
13623 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
13624 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
13625 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
13626 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
13627 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
13628 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
13629 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
13630 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
13631 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
13632 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
13633 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
13634 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
13635 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
13636 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
13637 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
13638 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
13639 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
13640 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
13641 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
13642 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
13643 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
13644 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
718e3744 13645 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
13646 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
13647 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
13648 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
13649 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
13650 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
13651 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
13652 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
13653 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
13654 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
13655 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
13656 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
13657 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
13658 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
13659 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
0b16f239 13660 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
718e3744 13661 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
0b16f239 13662 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
718e3744 13663 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
0b16f239 13664 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
718e3744 13665 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
0b16f239 13666 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
95cbbd2a 13667 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 13668 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
13669 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
13670 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
13671 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
13672 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
13673 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
13674 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
13675 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
13676 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
13677 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
13678 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
13679 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
13680 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
13681 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
13682 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
13683 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
2a71e9ce
TP
13684 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
13685 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
718e3744 13686
13687 /* BGP dampening clear commands */
13688 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
13689 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
13690 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
13691 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
13692
ff7924f6
PJ
13693 /* prefix count */
13694 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
13695 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
13696 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
718e3744 13697#ifdef HAVE_IPV6
ff7924f6
PJ
13698 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
13699
718e3744 13700 /* New config IPv6 BGP commands. */
73ac8160 13701 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
718e3744 13702 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
13703 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
73ac8160 13704 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
718e3744 13705 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
13706 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
13707
13708 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
13709 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
13710 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
13711 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
73bfe0bd
B
13712
13713 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
13714 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
718e3744 13715
13716 /* Old config IPv6 BGP commands. */
13717 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
13718 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
13719
13720 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
13721 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
13722 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
13723 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
13724
13725 install_element (VIEW_NODE, &show_bgp_cmd);
13726 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 13727 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 13728 install_element (VIEW_NODE, &show_bgp_route_cmd);
13729 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 13730 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
13731 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
13732 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
13733 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 13734 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
13735 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 13736 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c
DS
13737 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
13738 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
13739 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 13740 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
13741 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
13742 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
13743 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
13744 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
13745 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
13746 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
13747 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
13748 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
13749 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
13750 install_element (VIEW_NODE, &show_bgp_community_cmd);
13751 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
13752 install_element (VIEW_NODE, &show_bgp_community2_cmd);
13753 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
13754 install_element (VIEW_NODE, &show_bgp_community3_cmd);
13755 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
13756 install_element (VIEW_NODE, &show_bgp_community4_cmd);
13757 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
13758 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
13759 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
13760 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
13761 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
13762 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
13763 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
13764 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
13765 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
13766 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
13767 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
13768 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
13769 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13770 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
13771 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13772 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
13773 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13774 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
13775 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13776 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
13777 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13778 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13779 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 13780 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
13781 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13782 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
13783 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
13784 install_element (VIEW_NODE, &show_bgp_view_cmd);
13785 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
13786 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
13787 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
13788 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
13789 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
13790 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13791 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13792 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13793 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13794 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
13795 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13796 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13797 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13798 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
13799 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13800 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
13801 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
62687ff1
PJ
13802
13803 /* Restricted:
13804 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
13805 */
13806 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
13807 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 13808 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
13809 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
13810 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
13811 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
62687ff1
PJ
13812 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
13813 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 13814 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c
DS
13815 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
13816 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
13817 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
62687ff1
PJ
13818 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
13819 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
13820 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
13821 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
13822 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
13823 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
13824 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
13825 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
13826 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
13827 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
13828 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
13829 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
13830 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
13831 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
13832 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
13833 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
62687ff1
PJ
13834 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
13835 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
13836 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
13837 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
13838 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13839 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
718e3744 13840
13841 install_element (ENABLE_NODE, &show_bgp_cmd);
13842 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 13843 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 13844 install_element (ENABLE_NODE, &show_bgp_route_cmd);
13845 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 13846 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
13847 install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd);
13848 install_element (ENABLE_NODE, &show_bgp_ipv6_route_pathtype_cmd);
13849 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 13850 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
4092b06c
DS
13851 install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd);
13852 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
13853 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 13854 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 13855 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
718e3744 13856 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
13857 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
13858 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
13859 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
13860 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
13861 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
13862 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
13863 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
13864 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
13865 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
13866 install_element (ENABLE_NODE, &show_bgp_community_cmd);
13867 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
13868 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
13869 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
13870 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
13871 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
13872 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
13873 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
13874 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
13875 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
13876 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
13877 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
13878 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
13879 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
13880 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
13881 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
13882 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
13883 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
13884 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
13885 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13886 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
13887 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13888 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
13889 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13890 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
13891 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13892 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
13893 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13894 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13895 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 13896 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
13897 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13898 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
13899 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
13900 install_element (ENABLE_NODE, &show_bgp_view_cmd);
13901 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
13902 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
13903 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
13904 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
13905 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
13906 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13907 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13908 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13909 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13910 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
13911 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13912 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13913 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13914 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
13915 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13916 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
13917 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
2815e61f
PJ
13918
13919 /* Statistics */
13920 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
13921 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
13922 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
13923 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
13924
718e3744 13925 /* old command */
13926 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
13927 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
13928 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
13929 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
13930 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
13931 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
13932 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
13933 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
13934 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
13935 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
13936 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
13937 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
13938 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
13939 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
13940 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
13941 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
13942 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13943 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13944 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
13945 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
13946 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
13947 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
13948 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13949 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
13950 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
13951 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
13952 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
13953 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
13954 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13955 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13956 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13957 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13958 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13959 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13960 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13961 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
bb46e94f 13962
718e3744 13963 /* old command */
13964 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13965 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13966 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13967 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13968 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13969 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13970 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13971 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13972 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13973 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13974 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13975 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13976 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13977 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13978 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13979 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13980 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13981 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13982 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13983 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13984 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13985 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13986 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13987 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13988 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13989 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13990 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13991 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13992 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13993 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13994 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13995 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13996 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13997 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13998 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13999 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
14000
14001 /* old command */
14002 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14003 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14004 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14005 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14006
14007 /* old command */
14008 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14009 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14010 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14011 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14012
14013 /* old command */
14014 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
14015 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
14016 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14017 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14018#endif /* HAVE_IPV6 */
14019
14020 install_element (BGP_NODE, &bgp_distance_cmd);
14021 install_element (BGP_NODE, &no_bgp_distance_cmd);
14022 install_element (BGP_NODE, &no_bgp_distance2_cmd);
14023 install_element (BGP_NODE, &bgp_distance_source_cmd);
14024 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
14025 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
14026 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
14027
14028 install_element (BGP_NODE, &bgp_damp_set_cmd);
14029 install_element (BGP_NODE, &bgp_damp_set2_cmd);
14030 install_element (BGP_NODE, &bgp_damp_set3_cmd);
14031 install_element (BGP_NODE, &bgp_damp_unset_cmd);
14032 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
14033 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
14034 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
14035 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
14036 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
14037 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
14038}
228da428
CC
14039
14040void
14041bgp_route_finish (void)
14042{
14043 bgp_table_unlock (bgp_distance_table);
14044 bgp_distance_table = NULL;
14045}