]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_route.c
debian: Modify Quagga cumulus version in debian packaging
[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
1a392d46 249 /* Ignore 'pcount' for RS-client tables */
67174041 250 if (table->type != BGP_TABLE_MAIN
1a392d46
PJ
251 || ri->peer == ri->peer->bgp->peer_self)
252 return;
253
80e0ad24 254 if (!BGP_INFO_COUNTABLE (ri)
1a392d46
PJ
255 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
256 {
257
258 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
259
260 /* slight hack, but more robust against errors. */
67174041
AS
261 if (ri->peer->pcount[table->afi][table->safi])
262 ri->peer->pcount[table->afi][table->safi]--;
1a392d46
PJ
263 else
264 {
265 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
266 __func__, ri->peer->host);
267 zlog_backtrace (LOG_WARNING);
268 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
269 }
270 }
80e0ad24 271 else if (BGP_INFO_COUNTABLE (ri)
1a392d46
PJ
272 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
273 {
274 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
67174041 275 ri->peer->pcount[table->afi][table->safi]++;
1a392d46
PJ
276 }
277}
278
279
280/* Set/unset bgp_info flags, adjusting any other state as needed.
281 * This is here primarily to keep prefix-count in check.
282 */
283void
284bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
285{
286 SET_FLAG (ri->flags, flag);
287
80e0ad24
DS
288 /* early bath if we know it's not a flag that changes countability state */
289 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
1a392d46
PJ
290 return;
291
292 bgp_pcount_adjust (rn, ri);
293}
294
295void
296bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
297{
298 UNSET_FLAG (ri->flags, flag);
299
80e0ad24
DS
300 /* early bath if we know it's not a flag that changes countability state */
301 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
1a392d46
PJ
302 return;
303
304 bgp_pcount_adjust (rn, ri);
305}
306
718e3744 307/* Get MED value. If MED value is missing and "bgp bestpath
308 missing-as-worst" is specified, treat it as the worst value. */
94f2b392 309static u_int32_t
718e3744 310bgp_med_value (struct attr *attr, struct bgp *bgp)
311{
312 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
313 return attr->med;
314 else
315 {
316 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
3b424979 317 return BGP_MED_MAX;
718e3744 318 else
319 return 0;
320 }
321}
322
9fbdd100 323/* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1. */
94f2b392 324static int
96450faf 325bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
9fbdd100
DS
326 int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg, int debug,
327 char *pfx_buf)
718e3744 328{
8ff56318
JBD
329 struct attr *newattr, *existattr;
330 struct attr_extra *newattre, *existattre;
331 bgp_peer_sort_t new_sort;
332 bgp_peer_sort_t exist_sort;
718e3744 333 u_int32_t new_pref;
334 u_int32_t exist_pref;
335 u_int32_t new_med;
336 u_int32_t exist_med;
8ff56318
JBD
337 u_int32_t new_weight;
338 u_int32_t exist_weight;
339 uint32_t newm, existm;
718e3744 340 struct in_addr new_id;
341 struct in_addr exist_id;
342 int new_cluster;
343 int exist_cluster;
8ff56318
JBD
344 int internal_as_route;
345 int confed_as_route;
718e3744 346 int ret;
96450faf
JB
347
348 *paths_eq = 0;
718e3744 349
350 /* 0. Null check. */
351 if (new == NULL)
9fbdd100
DS
352 {
353 if (debug)
354 zlog_debug("%s: new is NULL", pfx_buf);
355 return 0;
356 }
357
718e3744 358 if (exist == NULL)
9fbdd100
DS
359 {
360 if (debug)
361 zlog_debug("%s: path %s is the initial bestpath",
362 pfx_buf, new->peer->host);
363 return 1;
364 }
718e3744 365
8ff56318
JBD
366 newattr = new->attr;
367 existattr = exist->attr;
368 newattre = newattr->extra;
369 existattre = existattr->extra;
370
718e3744 371 /* 1. Weight check. */
8ff56318
JBD
372 new_weight = exist_weight = 0;
373
374 if (newattre)
375 new_weight = newattre->weight;
376 if (existattre)
377 exist_weight = existattre->weight;
378
fb982c25 379 if (new_weight > exist_weight)
9fbdd100
DS
380 {
381 if (debug)
382 zlog_debug("%s: path %s wins over path %s due to weight %d > %d",
383 pfx_buf, new->peer->host, exist->peer->host, new_weight,
384 exist_weight);
385 return 1;
386 }
387
fb982c25 388 if (new_weight < exist_weight)
9fbdd100
DS
389 {
390 if (debug)
391 zlog_debug("%s: path %s loses to path %s due to weight %d < %d",
392 pfx_buf, new->peer->host, exist->peer->host, new_weight,
393 exist_weight);
394 return 0;
395 }
718e3744 396
397 /* 2. Local preference check. */
8ff56318
JBD
398 new_pref = exist_pref = bgp->default_local_pref;
399
400 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
401 new_pref = newattr->local_pref;
402 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
403 exist_pref = existattr->local_pref;
718e3744 404
718e3744 405 if (new_pref > exist_pref)
9fbdd100
DS
406 {
407 if (debug)
408 zlog_debug("%s: path %s wins over path %s due to localpref %d > %d",
409 pfx_buf, new->peer->host, exist->peer->host, new_pref,
410 exist_pref);
411 return 1;
412 }
413
718e3744 414 if (new_pref < exist_pref)
9fbdd100
DS
415 {
416 if (debug)
417 zlog_debug("%s: path %s loses to path %s due to localpref %d < %d",
418 pfx_buf, new->peer->host, exist->peer->host, new_pref,
419 exist_pref);
420 return 0;
421 }
718e3744 422
8ff56318
JBD
423 /* 3. Local route check. We prefer:
424 * - BGP_ROUTE_STATIC
425 * - BGP_ROUTE_AGGREGATE
426 * - BGP_ROUTE_REDISTRIBUTE
427 */
428 if (! (new->sub_type == BGP_ROUTE_NORMAL))
9fbdd100
DS
429 {
430 if (debug)
431 zlog_debug("%s: path %s wins over path %s due to preferred BGP_ROUTE type",
432 pfx_buf, new->peer->host, exist->peer->host);
433 return 1;
434 }
435
8ff56318 436 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
9fbdd100
DS
437 {
438 if (debug)
439 zlog_debug("%s: path %s loses to path %s due to preferred BGP_ROUTE type",
440 pfx_buf, new->peer->host, exist->peer->host);
441 return 0;
442 }
718e3744 443
444 /* 4. AS path length check. */
445 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
446 {
8ff56318
JBD
447 int exist_hops = aspath_count_hops (existattr->aspath);
448 int exist_confeds = aspath_count_confeds (existattr->aspath);
fe69a505 449
6811845b 450 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
451 {
fe69a505 452 int aspath_hops;
453
8ff56318
JBD
454 aspath_hops = aspath_count_hops (newattr->aspath);
455 aspath_hops += aspath_count_confeds (newattr->aspath);
fe69a505 456
457 if ( aspath_hops < (exist_hops + exist_confeds))
9fbdd100
DS
458 {
459 if (debug)
460 zlog_debug("%s: path %s wins over path %s due to aspath (with confeds) hopcount %d < %d",
461 pfx_buf, new->peer->host, exist->peer->host,
462 aspath_hops, (exist_hops + exist_confeds));
463 return 1;
464 }
465
fe69a505 466 if ( aspath_hops > (exist_hops + exist_confeds))
9fbdd100
DS
467 {
468 if (debug)
469 zlog_debug("%s: path %s loses to path %s due to aspath (with confeds) hopcount %d > %d",
470 pfx_buf, new->peer->host, exist->peer->host,
471 aspath_hops, (exist_hops + exist_confeds));
472 return 0;
473 }
6811845b 474 }
475 else
476 {
8ff56318 477 int newhops = aspath_count_hops (newattr->aspath);
fe69a505 478
479 if (newhops < exist_hops)
9fbdd100
DS
480 {
481 if (debug)
482 zlog_debug("%s: path %s wins over path %s due to aspath hopcount %d < %d",
483 pfx_buf, new->peer->host, exist->peer->host,
484 newhops, exist_hops);
485 return 1;
486 }
487
fe69a505 488 if (newhops > exist_hops)
9fbdd100
DS
489 {
490 if (debug)
491 zlog_debug("%s: path %s loses to path %s due to aspath hopcount %d > %d",
492 pfx_buf, new->peer->host, exist->peer->host,
493 newhops, exist_hops);
494 return 0;
495 }
6811845b 496 }
718e3744 497 }
498
499 /* 5. Origin check. */
8ff56318 500 if (newattr->origin < existattr->origin)
9fbdd100
DS
501 {
502 if (debug)
503 zlog_debug("%s: path %s wins over path %s due to ORIGIN %s < %s",
504 pfx_buf, new->peer->host, exist->peer->host,
505 bgp_origin_long_str[newattr->origin],
506 bgp_origin_long_str[existattr->origin]);
507 return 1;
508 }
509
8ff56318 510 if (newattr->origin > existattr->origin)
9fbdd100
DS
511 {
512 if (debug)
513 zlog_debug("%s: path %s loses to path %s due to ORIGIN %s > %s",
514 pfx_buf, new->peer->host, exist->peer->host,
515 bgp_origin_long_str[newattr->origin],
516 bgp_origin_long_str[existattr->origin]);
517 return 0;
518 }
718e3744 519
520 /* 6. MED check. */
8ff56318
JBD
521 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
522 && aspath_count_hops (existattr->aspath) == 0);
523 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
524 && aspath_count_confeds (existattr->aspath) > 0
525 && aspath_count_hops (newattr->aspath) == 0
526 && aspath_count_hops (existattr->aspath) == 0);
718e3744 527
528 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
529 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
530 && confed_as_route)
8ff56318
JBD
531 || aspath_cmp_left (newattr->aspath, existattr->aspath)
532 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
718e3744 533 || internal_as_route)
534 {
535 new_med = bgp_med_value (new->attr, bgp);
536 exist_med = bgp_med_value (exist->attr, bgp);
537
538 if (new_med < exist_med)
9fbdd100
DS
539 {
540 if (debug)
541 zlog_debug("%s: path %s wins over path %s due to MED %d < %d",
542 pfx_buf, new->peer->host, exist->peer->host, new_med,
543 exist_med);
544 return 1;
545 }
546
718e3744 547 if (new_med > exist_med)
9fbdd100
DS
548 {
549 if (debug)
550 zlog_debug("%s: path %s loses to path %s due to MED %d > %d",
551 pfx_buf, new->peer->host, exist->peer->host, new_med,
552 exist_med);
553 return 0;
554 }
718e3744 555 }
556
557 /* 7. Peer type check. */
8ff56318
JBD
558 new_sort = new->peer->sort;
559 exist_sort = exist->peer->sort;
560
561 if (new_sort == BGP_PEER_EBGP
562 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
9fbdd100
DS
563 {
564 if (debug)
31a4638f 565 zlog_debug("%s: path %s wins over path %s due to eBGP peer > iBGP peer",
9fbdd100
DS
566 pfx_buf, new->peer->host, exist->peer->host);
567 return 1;
568 }
569
8ff56318
JBD
570 if (exist_sort == BGP_PEER_EBGP
571 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
9fbdd100
DS
572 {
573 if (debug)
31a4638f 574 zlog_debug("%s: path %s loses to path %s due to iBGP peer < eBGP peer",
9fbdd100
DS
575 pfx_buf, new->peer->host, exist->peer->host);
576 return 0;
577 }
718e3744 578
579 /* 8. IGP metric check. */
8ff56318
JBD
580 newm = existm = 0;
581
582 if (new->extra)
583 newm = new->extra->igpmetric;
584 if (exist->extra)
585 existm = exist->extra->igpmetric;
586
96450faf 587 if (newm < existm)
9fbdd100
DS
588 {
589 if (debug)
590 zlog_debug("%s: path %s wins over path %s due to IGP metric %d < %d",
591 pfx_buf, new->peer->host, exist->peer->host, newm, existm);
592 ret = 1;
593 }
594
96450faf 595 if (newm > existm)
9fbdd100
DS
596 {
597 if (debug)
598 zlog_debug("%s: path %s loses to path %s due to IGP metric %d > %d",
599 pfx_buf, new->peer->host, exist->peer->host, newm, existm);
600 ret = 0;
601 }
718e3744 602
31a4638f 603 /* 9. Same IGP metric. Compare the cluster list length as
5e242b0d
DS
604 representative of IGP hops metric. Rewrite the metric value
605 pair (newm, existm) with the cluster list length. Prefer the
606 path with smaller cluster list length. */
607 if (newm == existm)
608 {
609 if (peer_sort (new->peer) == BGP_PEER_IBGP
610 && peer_sort (exist->peer) == BGP_PEER_IBGP
611 && CHECK_FLAG (mpath_cfg->ibgp_flags,
612 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
613 {
614 newm = BGP_CLUSTER_LIST_LENGTH(new->attr);
615 existm = BGP_CLUSTER_LIST_LENGTH(exist->attr);
9fbdd100 616
5e242b0d 617 if (newm < existm)
9fbdd100
DS
618 {
619 if (debug)
620 zlog_debug("%s: path %s wins over path %s due to CLUSTER_LIST length %d < %d",
621 pfx_buf, new->peer->host, exist->peer->host, newm,
622 existm);
623 ret = 1;
624 }
625
5e242b0d 626 if (newm > existm)
9fbdd100
DS
627 {
628 if (debug)
629 zlog_debug("%s: path %s loses to path %s due to CLUSTER_LIST length %d > %d",
630 pfx_buf, new->peer->host, exist->peer->host, newm,
631 existm);
632 ret = 0;
633 }
5e242b0d
DS
634 }
635 }
636
31a4638f
DS
637 /* 10. confed-external vs. confed-internal */
638 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
639 {
640 if (new_sort == BGP_PEER_CONFED && exist_sort == BGP_PEER_IBGP)
641 {
642 if (debug)
643 zlog_debug("%s: path %s wins over path %s due to confed-external peer > confed-internal peer",
644 pfx_buf, new->peer->host, exist->peer->host);
645 return 1;
646 }
647
648 if (exist_sort == BGP_PEER_CONFED && new_sort == BGP_PEER_IBGP)
649 {
650 if (debug)
651 zlog_debug("%s: path %s loses to path %s due to confed-internal peer < confed-external peer",
652 pfx_buf, new->peer->host, exist->peer->host);
653 return 0;
654 }
655 }
656
657 /* 11. Maximum path check. */
96450faf
JB
658 if (newm == existm)
659 {
2fdd455c
PM
660 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
661 {
662
663 /*
664 * For the two paths, all comparison steps till IGP metric
665 * have succeeded - including AS_PATH hop count. Since 'bgp
666 * bestpath as-path multipath-relax' knob is on, we don't need
667 * an exact match of AS_PATH. Thus, mark the paths are equal.
668 * That will trigger both these paths to get into the multipath
669 * array.
670 */
671 *paths_eq = 1;
9fbdd100
DS
672
673 if (debug)
674 zlog_debug("%s: path %s and path %s are equal via multipath-relax",
675 pfx_buf, new->peer->host, exist->peer->host);
2fdd455c
PM
676 }
677 else if (new->peer->sort == BGP_PEER_IBGP)
96450faf
JB
678 {
679 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
9fbdd100
DS
680 {
681 *paths_eq = 1;
682
683 if (debug)
684 zlog_debug("%s: path %s and path %s are equal via matching aspaths",
685 pfx_buf, new->peer->host, exist->peer->host);
686 }
96450faf
JB
687 }
688 else if (new->peer->as == exist->peer->as)
9fbdd100
DS
689 {
690 *paths_eq = 1;
691
692 if (debug)
693 zlog_debug("%s: path %s and path %s are equal via same remote-as",
694 pfx_buf, new->peer->host, exist->peer->host);
695 }
96450faf
JB
696 }
697 else
698 {
699 /*
700 * TODO: If unequal cost ibgp multipath is enabled we can
701 * mark the paths as equal here instead of returning
702 */
703 return ret;
704 }
718e3744 705
31a4638f 706 /* 12. If both paths are external, prefer the path that was received
718e3744 707 first (the oldest one). This step minimizes route-flap, since a
708 newer path won't displace an older one, even if it was the
709 preferred route based on the additional decision criteria below. */
710 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
8ff56318
JBD
711 && new_sort == BGP_PEER_EBGP
712 && exist_sort == BGP_PEER_EBGP)
718e3744 713 {
714 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
9fbdd100
DS
715 {
716 if (debug)
717 zlog_debug("%s: path %s wins over path %s due to oldest external",
718 pfx_buf, new->peer->host, exist->peer->host);
719 return 1;
720 }
721
718e3744 722 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
9fbdd100
DS
723 {
724 if (debug)
725 zlog_debug("%s: path %s loses to path %s due to oldest external",
726 pfx_buf, new->peer->host, exist->peer->host);
727 return 0;
728 }
718e3744 729 }
730
31a4638f 731 /* 13. Router-ID comparision. */
0de5153c
DS
732 /* If one of the paths is "stale", the corresponding peer router-id will
733 * be 0 and would always win over the other path. If originator id is
734 * used for the comparision, it will decide which path is better.
735 */
8ff56318
JBD
736 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
737 new_id.s_addr = newattre->originator_id.s_addr;
718e3744 738 else
739 new_id.s_addr = new->peer->remote_id.s_addr;
8ff56318
JBD
740 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
741 exist_id.s_addr = existattre->originator_id.s_addr;
718e3744 742 else
743 exist_id.s_addr = exist->peer->remote_id.s_addr;
744
745 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
9fbdd100
DS
746 {
747 if (debug)
748 zlog_debug("%s: path %s wins over path %s due to Router-ID comparison",
749 pfx_buf, new->peer->host, exist->peer->host);
750 return 1;
751 }
752
718e3744 753 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
9fbdd100
DS
754 {
755 if (debug)
756 zlog_debug("%s: path %s loses to path %s due to Router-ID comparison",
757 pfx_buf, new->peer->host, exist->peer->host);
758 return 0;
759 }
718e3744 760
31a4638f 761 /* 14. Cluster length comparision. */
5e242b0d
DS
762 new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
763 exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
718e3744 764
765 if (new_cluster < exist_cluster)
9fbdd100
DS
766 {
767 if (debug)
768 zlog_debug("%s: path %s wins over path %s due to CLUSTER_LIST length %d < %d",
769 pfx_buf, new->peer->host, exist->peer->host, new_cluster,
770 exist_cluster);
771 return 1;
772 }
773
718e3744 774 if (new_cluster > exist_cluster)
9fbdd100
DS
775 {
776 if (debug)
777 zlog_debug("%s: path %s loses to path %s due to CLUSTER_LIST length %d > %d",
778 pfx_buf, new->peer->host, exist->peer->host, new_cluster,
779 exist_cluster);
780 return 0;
781 }
718e3744 782
31a4638f 783 /* 15. Neighbor address comparision. */
0de5153c
DS
784 /* Do this only if neither path is "stale" as stale paths do not have
785 * valid peer information (as the connection may or may not be up).
786 */
787 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
9fbdd100
DS
788 {
789 if (debug)
790 zlog_debug("%s: path %s wins over path %s due to latter path being STALE",
791 pfx_buf, new->peer->host, exist->peer->host);
792 return 1;
793 }
794
0de5153c 795 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
9fbdd100
DS
796 {
797 if (debug)
798 zlog_debug("%s: path %s loses to path %s due to former path being STALE",
799 pfx_buf, new->peer->host, exist->peer->host);
800 return 0;
801 }
0de5153c 802
718e3744 803 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
804
805 if (ret == 1)
9fbdd100
DS
806 {
807 if (debug)
808 zlog_debug("%s: path %s loses to path %s due to Neighor IP comparison",
809 pfx_buf, new->peer->host, exist->peer->host);
810 return 0;
811 }
812
718e3744 813 if (ret == -1)
9fbdd100
DS
814 {
815 if (debug)
816 zlog_debug("%s: path %s wins over path %s due to Neighor IP comparison",
817 pfx_buf, new->peer->host, exist->peer->host);
818 return 1;
819 }
820
821 if (debug)
822 zlog_debug("%s: path %s wins over path %s due to nothing left to compare",
823 pfx_buf, new->peer->host, exist->peer->host);
718e3744 824
825 return 1;
826}
827
94f2b392 828static enum filter_type
718e3744 829bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
830 afi_t afi, safi_t safi)
831{
832 struct bgp_filter *filter;
833
834 filter = &peer->filter[afi][safi];
835
650f76c2
PJ
836#define FILTER_EXIST_WARN(F,f,filter) \
837 if (BGP_DEBUG (update, UPDATE_IN) \
838 && !(F ## _IN (filter))) \
16286195 839 zlog_warn ("%s: Could not find configured input %s-list %s!", \
650f76c2
PJ
840 peer->host, #f, F ## _IN_NAME(filter));
841
842 if (DISTRIBUTE_IN_NAME (filter)) {
843 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
844
718e3744 845 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
846 return FILTER_DENY;
650f76c2 847 }
718e3744 848
650f76c2
PJ
849 if (PREFIX_LIST_IN_NAME (filter)) {
850 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
851
718e3744 852 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
853 return FILTER_DENY;
650f76c2 854 }
718e3744 855
650f76c2
PJ
856 if (FILTER_LIST_IN_NAME (filter)) {
857 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
858
718e3744 859 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
860 return FILTER_DENY;
650f76c2
PJ
861 }
862
718e3744 863 return FILTER_PERMIT;
650f76c2 864#undef FILTER_EXIST_WARN
718e3744 865}
866
94f2b392 867static enum filter_type
718e3744 868bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
869 afi_t afi, safi_t safi)
870{
871 struct bgp_filter *filter;
872
873 filter = &peer->filter[afi][safi];
874
650f76c2
PJ
875#define FILTER_EXIST_WARN(F,f,filter) \
876 if (BGP_DEBUG (update, UPDATE_OUT) \
877 && !(F ## _OUT (filter))) \
16286195 878 zlog_warn ("%s: Could not find configured output %s-list %s!", \
650f76c2
PJ
879 peer->host, #f, F ## _OUT_NAME(filter));
880
881 if (DISTRIBUTE_OUT_NAME (filter)) {
882 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
883
718e3744 884 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
885 return FILTER_DENY;
650f76c2 886 }
718e3744 887
650f76c2
PJ
888 if (PREFIX_LIST_OUT_NAME (filter)) {
889 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
890
718e3744 891 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
892 return FILTER_DENY;
650f76c2 893 }
718e3744 894
650f76c2
PJ
895 if (FILTER_LIST_OUT_NAME (filter)) {
896 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
897
718e3744 898 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
899 return FILTER_DENY;
650f76c2 900 }
718e3744 901
902 return FILTER_PERMIT;
650f76c2 903#undef FILTER_EXIST_WARN
718e3744 904}
905
906/* If community attribute includes no_export then return 1. */
94f2b392 907static int
718e3744 908bgp_community_filter (struct peer *peer, struct attr *attr)
909{
910 if (attr->community)
911 {
912 /* NO_ADVERTISE check. */
913 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
914 return 1;
915
916 /* NO_EXPORT check. */
6d85b15b 917 if (peer->sort == BGP_PEER_EBGP &&
718e3744 918 community_include (attr->community, COMMUNITY_NO_EXPORT))
919 return 1;
920
921 /* NO_EXPORT_SUBCONFED check. */
6d85b15b
JBD
922 if (peer->sort == BGP_PEER_EBGP
923 || peer->sort == BGP_PEER_CONFED)
718e3744 924 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
925 return 1;
926 }
927 return 0;
928}
929
930/* Route reflection loop check. */
931static int
932bgp_cluster_filter (struct peer *peer, struct attr *attr)
933{
934 struct in_addr cluster_id;
935
fb982c25 936 if (attr->extra && attr->extra->cluster)
718e3744 937 {
938 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
939 cluster_id = peer->bgp->cluster_id;
940 else
941 cluster_id = peer->bgp->router_id;
942
fb982c25 943 if (cluster_loop_check (attr->extra->cluster, cluster_id))
718e3744 944 return 1;
945 }
946 return 0;
947}
6b0655a2 948
94f2b392 949static int
718e3744 950bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
ffd0c037 951 afi_t afi, safi_t safi, const char *rmap_name)
718e3744 952{
953 struct bgp_filter *filter;
954 struct bgp_info info;
955 route_map_result_t ret;
0b16f239 956 struct route_map *rmap = NULL;
718e3744 957
958 filter = &peer->filter[afi][safi];
959
960 /* Apply default weight value. */
fb982c25
PJ
961 if (peer->weight)
962 (bgp_attr_extra_get (attr))->weight = peer->weight;
718e3744 963
0b16f239
DS
964 if (rmap_name)
965 {
966 rmap = route_map_lookup_by_name(rmap_name);
98a4a44e
DS
967
968 if (rmap == NULL)
969 return RMAP_DENY;
0b16f239
DS
970 }
971 else
972 {
973 if (ROUTE_MAP_IN_NAME(filter))
98a4a44e
DS
974 {
975 rmap = ROUTE_MAP_IN (filter);
976
977 if (rmap == NULL)
978 return RMAP_DENY;
979 }
0b16f239
DS
980 }
981
718e3744 982 /* Route map apply. */
0b16f239 983 if (rmap)
718e3744 984 {
985 /* Duplicate current value to new strucutre for modification. */
986 info.peer = peer;
987 info.attr = attr;
988
ac41b2a2 989 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
990
718e3744 991 /* Apply BGP route map to the attribute. */
0b16f239
DS
992 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
993
994 peer->rmap_type = 0;
995
996 if (ret == RMAP_DENYMATCH)
997 {
998 /* Free newly generated AS path and community by route-map. */
999 bgp_attr_flush (attr);
1000 return RMAP_DENY;
1001 }
1002 }
1003 return RMAP_PERMIT;
1004}
1005
1006static int
1007bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
ffd0c037 1008 afi_t afi, safi_t safi, const char *rmap_name)
0b16f239
DS
1009{
1010 struct bgp_filter *filter;
1011 struct bgp_info info;
1012 route_map_result_t ret;
1013 struct route_map *rmap = NULL;
1014
1015 filter = &peer->filter[afi][safi];
1016
1017 /* Apply default weight value. */
1018 if (peer->weight)
1019 (bgp_attr_extra_get (attr))->weight = peer->weight;
1020
1021 if (rmap_name)
1022 {
1023 rmap = route_map_lookup_by_name(rmap_name);
98a4a44e
DS
1024
1025 if (rmap == NULL)
1026 return RMAP_DENY;
0b16f239
DS
1027 }
1028 else
1029 {
1030 if (ROUTE_MAP_OUT_NAME(filter))
98a4a44e
DS
1031 {
1032 rmap = ROUTE_MAP_OUT (filter);
1033
1034 if (rmap == NULL)
1035 return RMAP_DENY;
1036 }
0b16f239
DS
1037 }
1038
1039 /* Route map apply. */
1040 if (rmap)
1041 {
1042 /* Duplicate current value to new strucutre for modification. */
1043 info.peer = peer;
1044 info.attr = attr;
1045
1046 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1047
1048 /* Apply BGP route map to the attribute. */
1049 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
ac41b2a2 1050
1051 peer->rmap_type = 0;
1052
718e3744 1053 if (ret == RMAP_DENYMATCH)
c460e572
DL
1054 /* caller has multiple error paths with bgp_attr_flush() */
1055 return RMAP_DENY;
718e3744 1056 }
1057 return RMAP_PERMIT;
1058}
6b0655a2 1059
94f2b392 1060static int
fee0f4c6 1061bgp_export_modifier (struct peer *rsclient, struct peer *peer,
1062 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
1063{
1064 struct bgp_filter *filter;
1065 struct bgp_info info;
1066 route_map_result_t ret;
1067
1068 filter = &peer->filter[afi][safi];
1069
1070 /* Route map apply. */
1071 if (ROUTE_MAP_EXPORT_NAME (filter))
1072 {
1073 /* Duplicate current value to new strucutre for modification. */
1074 info.peer = rsclient;
1075 info.attr = attr;
1076
1077 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
1078
1079 /* Apply BGP route map to the attribute. */
1080 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
1081
1082 rsclient->rmap_type = 0;
1083
1084 if (ret == RMAP_DENYMATCH)
1085 {
1086 /* Free newly generated AS path and community by route-map. */
1087 bgp_attr_flush (attr);
1088 return RMAP_DENY;
1089 }
1090 }
1091 return RMAP_PERMIT;
1092}
1093
94f2b392 1094static int
fee0f4c6 1095bgp_import_modifier (struct peer *rsclient, struct peer *peer,
1096 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
1097{
1098 struct bgp_filter *filter;
1099 struct bgp_info info;
1100 route_map_result_t ret;
1101
1102 filter = &rsclient->filter[afi][safi];
1103
1104 /* Apply default weight value. */
fb982c25
PJ
1105 if (peer->weight)
1106 (bgp_attr_extra_get (attr))->weight = peer->weight;
fee0f4c6 1107
1108 /* Route map apply. */
1109 if (ROUTE_MAP_IMPORT_NAME (filter))
1110 {
1111 /* Duplicate current value to new strucutre for modification. */
1112 info.peer = peer;
1113 info.attr = attr;
1114
1115 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
1116
1117 /* Apply BGP route map to the attribute. */
1118 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
1119
1120 peer->rmap_type = 0;
1121
1122 if (ret == RMAP_DENYMATCH)
1123 {
1124 /* Free newly generated AS path and community by route-map. */
1125 bgp_attr_flush (attr);
1126 return RMAP_DENY;
1127 }
1128 }
1129 return RMAP_PERMIT;
1130}
6b0655a2 1131
5000f21c
DS
1132
1133/* If this is an EBGP peer with remove-private-AS */
ffd0c037 1134static void
5000f21c
DS
1135bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
1136 struct peer *peer, struct attr *attr)
1137{
1138 if (peer->sort == BGP_PEER_EBGP &&
88b8ed8d
DW
1139 (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1140 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE) ||
1141 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL) ||
1142 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)))
5000f21c
DS
1143 {
1144 // Take action on the entire aspath
88b8ed8d
DW
1145 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1146 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
5000f21c 1147 {
88b8ed8d 1148 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
5000f21c
DS
1149 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1150
1151 // The entire aspath consists of private ASNs so create an empty aspath
1152 else if (aspath_private_as_check (attr->aspath))
1153 attr->aspath = aspath_empty_get ();
1154
1155 // There are some public and some private ASNs, remove the private ASNs
1156 else
1157 attr->aspath = aspath_remove_private_asns (attr->aspath);
1158 }
1159
1160 // 'all' was not specified so the entire aspath must be private ASNs
1161 // for us to do anything
1162 else if (aspath_private_as_check (attr->aspath))
1163 {
1164 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
1165 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1166 else
1167 attr->aspath = aspath_empty_get ();
1168 }
1169 }
1170}
1171
c7122e14
DS
1172/* If this is an EBGP peer with as-override */
1173static void
1174bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
1175 struct peer *peer, struct attr *attr)
1176{
1177 if (peer->sort == BGP_PEER_EBGP &&
1178 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
1179 {
1180 if (aspath_single_asn_check (attr->aspath, peer->as))
1181 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
1182 }
1183}
1184
3f9c7369
DS
1185static void
1186subgroup_announce_reset_nhop (u_char family, struct attr *attr)
1187{
1188 if (family == AF_INET)
1189 attr->nexthop.s_addr = 0;
1190#ifdef HAVE_IPV6
1191 if (family == AF_INET6)
1192 memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
1193#endif
1194}
1195
1196int
1197subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp,
1198 struct prefix *p, struct attr *attr)
1199{
1200 struct bgp_filter *filter;
1201 struct peer *from;
1202 struct peer *peer;
1203 struct peer *onlypeer;
1204 struct bgp *bgp;
1205 struct attr *riattr;
1206 struct peer_af *paf;
1207 char buf[SU_ADDRSTRLEN];
1208 int ret;
1209 int transparent;
1210 int reflect;
1211 afi_t afi;
1212 safi_t safi;
1213
1214 if (DISABLE_BGP_ANNOUNCE)
1215 return 0;
1216
1217 afi = SUBGRP_AFI(subgrp);
1218 safi = SUBGRP_SAFI(subgrp);
1219 peer = SUBGRP_PEER(subgrp);
1220 onlypeer = NULL;
1221 if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL))
1222 onlypeer = SUBGRP_PFIRST(subgrp)->peer;
1223
1224 from = ri->peer;
1225 filter = &peer->filter[afi][safi];
1226 bgp = SUBGRP_INST(subgrp);
1227 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1228
1229 /* Aggregate-address suppress check. */
1230 if (ri->extra && ri->extra->suppress)
1231 if (! UNSUPPRESS_MAP_NAME (filter))
1232 {
1233 return 0;
1234 }
1235
1236 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
1237 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1238 {
1239 return 0;
1240 }
1241
1242 /* Do not send back route to sender. */
1243 if (onlypeer && from == onlypeer)
1244 {
1245 return 0;
1246 }
1247
4125bb67
DS
1248 /* Do not send the default route in the BGP table if the neighbor is
1249 * configured for default-originate */
1250 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
1251 {
1252 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1253 return 0;
1254#ifdef HAVE_IPV6
1255 else if (p->family == AF_INET6 && p->prefixlen == 0)
1256 return 0;
1257#endif /* HAVE_IPV6 */
1258 }
1259
3f9c7369
DS
1260 /* Transparency check. */
1261 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1262 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1263 transparent = 1;
1264 else
1265 transparent = 0;
1266
1267 /* If community is not disabled check the no-export and local. */
1268 if (! transparent && bgp_community_filter (peer, riattr))
1269 {
1270 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1271 zlog_debug ("subgrpannouncecheck: community filter check fail");
1272 return 0;
1273 }
1274
1275 /* If the attribute has originator-id and it is same as remote
1276 peer's id. */
1277 if (onlypeer &&
1278 riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) &&
1279 (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id)))
1280 {
1281 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1282 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as "
1283 "remote router-id",
1284 onlypeer->host,
1285 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1286 p->prefixlen);
1287 return 0;
1288 }
1289
1290 /* ORF prefix-list filter check */
1291 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1292 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1293 || CHECK_FLAG (peer->af_cap[afi][safi],
1294 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1295 if (peer->orf_plist[afi][safi])
1296 {
1297 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1298 {
40d2700d
DW
1299 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1300 zlog_debug ("%s [Update:SEND] %s/%d is filtered via ORF",
1301 peer->host,
1302 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1303 p->prefixlen);
3f9c7369
DS
1304 return 0;
1305 }
1306 }
1307
1308 /* Output filter check. */
1309 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1310 {
1311 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1312 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1313 peer->host,
1314 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1315 p->prefixlen);
1316 return 0;
1317 }
1318
1319#ifdef BGP_SEND_ASPATH_CHECK
1320 /* AS path loop check. */
1321 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
1322 {
1323 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1324 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1325 "that is part of AS path.",
1326 onlypeer->host, onlypeer->as);
1327 return 0;
1328 }
1329#endif /* BGP_SEND_ASPATH_CHECK */
1330
1331 /* If we're a CONFED we need to loop check the CONFED ID too */
1332 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1333 {
1334 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1335 {
1336 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1337 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u"
1338 " is AS path.",
1339 peer->host,
1340 bgp->confed_id);
1341 return 0;
1342 }
1343 }
1344
1345 /* Route-Reflect check. */
1346 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1347 reflect = 1;
1348 else
1349 reflect = 0;
1350
1351 /* IBGP reflection check. */
1352 if (reflect)
1353 {
1354 /* A route from a Client peer. */
1355 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1356 {
1357 /* Reflect to all the Non-Client peers and also to the
1358 Client peers other than the originator. Originator check
1359 is already done. So there is noting to do. */
1360 /* no bgp client-to-client reflection check. */
1361 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1362 if (CHECK_FLAG (peer->af_flags[afi][safi],
1363 PEER_FLAG_REFLECTOR_CLIENT))
1364 return 0;
1365 }
1366 else
1367 {
1368 /* A route from a Non-client peer. Reflect to all other
1369 clients. */
1370 if (! CHECK_FLAG (peer->af_flags[afi][safi],
1371 PEER_FLAG_REFLECTOR_CLIENT))
1372 return 0;
1373 }
1374 }
1375
1376 /* For modify attribute, copy it to temporary structure. */
1377 bgp_attr_dup (attr, riattr);
1378
1379 /* If local-preference is not set. */
1380 if ((peer->sort == BGP_PEER_IBGP
1381 || peer->sort == BGP_PEER_CONFED)
1382 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1383 {
1384 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1385 attr->local_pref = bgp->default_local_pref;
1386 }
1387
1388 /* If originator-id is not set and the route is to be reflected,
1389 set the originator id */
1390 if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1391 {
1392 attr->extra = bgp_attr_extra_get(attr);
1393 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1394 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1395 }
1396
1397 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1398 if (peer->sort == BGP_PEER_EBGP
1399 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1400 {
1401 if (ri->peer != bgp->peer_self && ! transparent
1402 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1403 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1404 }
1405
1406 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1407 * in announce check, only certain flags and length (or number of nexthops
1408 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1409 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1410 * Typically, the source nexthop in the attribute is preserved but in the
1411 * scenarios where we know it will always be overwritten, we reset the
1412 * nexthop to "0" in an attempt to achieve better Update packing. An
1413 * example of this is when a prefix from each of 2 IBGP peers needs to be
1414 * announced to an EBGP peer (and they have the same attributes barring
1415 * their nexthop).
1416 */
1417 if (reflect)
1418 SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
1419
1420#ifdef HAVE_IPV6
3811f1e2
DS
1421 /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if
1422 * the peer (group) is configured to receive link-local nexthop unchanged
1423 * and it is available in the prefix OR we're not reflecting the route and
1424 * the peer (group) to whom we're going to announce is on a shared network
3f9c7369 1425 */
8a92a8a0 1426 if (p->family == AF_INET6 || peer_cap_enhe(peer))
3f9c7369 1427 {
801a9bcc 1428 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
3811f1e2
DS
1429 if ((CHECK_FLAG (peer->af_flags[afi][safi],
1430 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1431 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) ||
1432 (!reflect && peer->shared_network))
3f9c7369 1433 {
3811f1e2 1434 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
3f9c7369
DS
1435 }
1436
3811f1e2
DS
1437 /* Clear off link-local nexthop in source, whenever it is not needed to
1438 * ensure more prefixes share the same attribute for announcement.
3f9c7369
DS
1439 */
1440 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1441 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1442 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1443 }
1444#endif /* HAVE_IPV6 */
1445
1446 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1447 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1448
1449 /* Route map & unsuppress-map apply. */
1450 if (ROUTE_MAP_OUT_NAME (filter)
1451 || (ri->extra && ri->extra->suppress) )
1452 {
1453 struct bgp_info info;
1454 struct attr dummy_attr;
1455 struct attr_extra dummy_extra;
1456
1457 dummy_attr.extra = &dummy_extra;
1458
1459 info.peer = peer;
1460 info.attr = attr;
316e074d
DS
1461 /* don't confuse inbound and outbound setting */
1462 RESET_FLAG(attr->rmap_change_flags);
3f9c7369
DS
1463
1464 /*
1465 * The route reflector is not allowed to modify the attributes
1466 * of the reflected IBGP routes unless explicitly allowed.
1467 */
1468 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1469 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1470 {
1471 bgp_attr_dup (&dummy_attr, attr);
1472 info.attr = &dummy_attr;
1473 }
1474
1475 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1476
1477 if (ri->extra && ri->extra->suppress)
1478 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1479 else
1480 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1481
1482 peer->rmap_type = 0;
1483
1484 if (ret == RMAP_DENYMATCH)
1485 {
1486 bgp_attr_flush (attr);
1487 return 0;
1488 }
1489 }
1490
1491 /* After route-map has been applied, we check to see if the nexthop to
1492 * be carried in the attribute (that is used for the announcement) can
1493 * be cleared off or not. We do this in all cases where we would be
1494 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1495 * the global nexthop here; the link-local nexthop would have been cleared
1496 * already, and if not, it is required by the update formation code.
1497 * Also see earlier comments in this function.
43fdf718 1498 */
3811f1e2
DS
1499 /*
1500 * If route-map has performed some operation on the nexthop or the peer
1501 * configuration says to pass it unchanged, we cannot reset the nexthop
1502 * here, so only attempt to do it if these aren't true. Note that the
1503 * route-map handler itself might have cleared the nexthop, if for example,
1504 * it is configured as 'peer-address'.
3f9c7369 1505 */
3811f1e2
DS
1506 if (!bgp_rmap_nhop_changed(attr->rmap_change_flags,
1507 riattr->rmap_change_flags) &&
1508 !transparent &&
1509 !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
3f9c7369 1510 {
3811f1e2 1511 /* We can reset the nexthop, if setting (or forcing) it to 'self' */
88b8ed8d
DW
1512 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
1513 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
3f9c7369
DS
1514 {
1515 if (!reflect ||
1516 CHECK_FLAG (peer->af_flags[afi][safi],
43fdf718 1517 PEER_FLAG_FORCE_NEXTHOP_SELF))
3811f1e2
DS
1518 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ?
1519 AF_INET6 : p->family), attr);
3f9c7369
DS
1520 }
1521 else if (peer->sort == BGP_PEER_EBGP)
1522 {
3811f1e2
DS
1523 /* Can also reset the nexthop if announcing to EBGP, but only if
1524 * no peer in the subgroup is on a shared subnet.
1525 * Note: 3rd party nexthop currently implemented for IPv4 only.
1526 */
3f9c7369
DS
1527 SUBGRP_FOREACH_PEER (subgrp, paf)
1528 {
1529 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1530 break;
1531 }
1532 if (!paf)
8a92a8a0 1533 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr);
3f9c7369
DS
1534 }
1535 }
1536
1537 return 1;
1538}
1539
94f2b392 1540static int
3f9c7369
DS
1541subgroup_announce_check_rsclient (struct bgp_info *ri,
1542 struct update_subgroup *subgrp,
1543 struct prefix *p, struct attr *attr)
fee0f4c6 1544{
1545 int ret;
1546 char buf[SU_ADDRSTRLEN];
1547 struct bgp_filter *filter;
1548 struct bgp_info info;
1549 struct peer *from;
3f9c7369
DS
1550 struct peer *rsclient;
1551 struct peer *onlypeer;
0b597ef0 1552 struct attr *riattr;
5000f21c 1553 struct bgp *bgp;
3f9c7369
DS
1554 afi_t afi;
1555 safi_t safi;
1556
1557 if (DISABLE_BGP_ANNOUNCE)
1558 return 0;
fee0f4c6 1559
3f9c7369
DS
1560 afi = SUBGRP_AFI(subgrp);
1561 safi = SUBGRP_SAFI(subgrp);
1562 rsclient = SUBGRP_PEER(subgrp);
1563 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1564 (SUBGRP_PFIRST(subgrp))->peer : NULL);
fee0f4c6 1565 from = ri->peer;
1566 filter = &rsclient->filter[afi][safi];
5000f21c 1567 bgp = rsclient->bgp;
0b597ef0 1568 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
fee0f4c6 1569
fee0f4c6 1570 /* Do not send back route to sender. */
3f9c7369 1571 if (onlypeer && (from == onlypeer))
fee0f4c6 1572 return 0;
1573
1574 /* Aggregate-address suppress check. */
fb982c25 1575 if (ri->extra && ri->extra->suppress)
fee0f4c6 1576 if (! UNSUPPRESS_MAP_NAME (filter))
1577 return 0;
1578
1579 /* Default route check. */
840fced9 1580 if (subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
fee0f4c6 1581 {
1582 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1583 return 0;
1584#ifdef HAVE_IPV6
1585 else if (p->family == AF_INET6 && p->prefixlen == 0)
1586 return 0;
1587#endif /* HAVE_IPV6 */
1588 }
1589
1590 /* If the attribute has originator-id and it is same as remote
1591 peer's id. */
3f9c7369 1592 if (onlypeer && riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
fee0f4c6 1593 {
3f9c7369 1594 if (IPV4_ADDR_SAME (&onlypeer->remote_id,
0b597ef0 1595 &riattr->extra->originator_id))
fee0f4c6 1596 {
3f9c7369 1597 if (bgp_debug_update(rsclient, p, subgrp->update_group, 0))
16286195 1598 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as remote router-id",
3f9c7369 1599 onlypeer->host,
16286195
DS
1600 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1601 p->prefixlen);
fee0f4c6 1602 return 0;
1603 }
1604 }
1605
1606 /* ORF prefix-list filter check */
1607 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1608 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1609 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1610 if (rsclient->orf_plist[afi][safi])
1611 {
1612 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1613 return 0;
1614 }
1615
1616 /* Output filter check. */
0b597ef0 1617 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
fee0f4c6 1618 {
3f9c7369 1619 if (bgp_debug_update(rsclient, p, subgrp->update_group, 0))
16286195
DS
1620 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1621 rsclient->host,
1622 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1623 p->prefixlen);
fee0f4c6 1624 return 0;
1625 }
1626
1627#ifdef BGP_SEND_ASPATH_CHECK
1628 /* AS path loop check. */
3f9c7369 1629 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
fee0f4c6 1630 {
3f9c7369 1631 if (bgp_debug_update(rsclient, p, subgrp->update_group, 0))
16286195 1632 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
3f9c7369 1633 onlypeer->host, onlypeer->as);
fee0f4c6 1634 return 0;
1635 }
1636#endif /* BGP_SEND_ASPATH_CHECK */
1637
1638 /* For modify attribute, copy it to temporary structure. */
0b597ef0 1639 bgp_attr_dup (attr, riattr);
fee0f4c6 1640
1641 /* next-hop-set */
8a92a8a0
DS
1642 if ((p->family == AF_INET && !peer_cap_enhe(rsclient)
1643 && attr->nexthop.s_addr == 0)
fee0f4c6 1644#ifdef HAVE_IPV6
8a92a8a0 1645 || ((p->family == AF_INET6 || peer_cap_enhe(rsclient)) &&
fb982c25 1646 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
fee0f4c6 1647#endif /* HAVE_IPV6 */
1648 )
1649 {
1650 /* Set IPv4 nexthop. */
1651 if (p->family == AF_INET)
1652 {
1653 if (safi == SAFI_MPLS_VPN)
fb982c25 1654 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
fee0f4c6 1655 IPV4_MAX_BYTELEN);
8a92a8a0 1656 else if (!peer_cap_enhe(rsclient))
fee0f4c6 1657 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1658 }
1659#ifdef HAVE_IPV6
1660 /* Set IPv6 nexthop. */
8a92a8a0 1661 if (p->family == AF_INET6 || peer_cap_enhe(rsclient))
fee0f4c6 1662 {
1663 /* IPv6 global nexthop must be included. */
fb982c25 1664 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
fee0f4c6 1665 IPV6_MAX_BYTELEN);
801a9bcc 1666 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 1667 }
1668#endif /* HAVE_IPV6 */
1669 }
1670
1671#ifdef HAVE_IPV6
8a92a8a0 1672 if (p->family == AF_INET6 || peer_cap_enhe(rsclient))
fee0f4c6 1673 {
fb982c25 1674 struct attr_extra *attre = attr->extra;
558d1fec 1675
fee0f4c6 1676 /* Left nexthop_local unchanged if so configured. */
3f9c7369 1677 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
fee0f4c6 1678 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1679 {
fb982c25 1680 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
801a9bcc 1681 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
fee0f4c6 1682 else
801a9bcc 1683 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 1684 }
3f9c7369 1685
fee0f4c6 1686 /* Default nexthop_local treatment for RS-Clients */
3f9c7369
DS
1687 else
1688 {
1689 /* Announcer and RS-Client are both in the same network */
fee0f4c6 1690 if (rsclient->shared_network && from->shared_network &&
1691 (rsclient->ifindex == from->ifindex))
1692 {
fb982c25 1693 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
801a9bcc 1694 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
fee0f4c6 1695 else
801a9bcc 1696 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 1697 }
1698
1699 /* Set link-local address for shared network peer. */
1700 else if (rsclient->shared_network
1701 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1702 {
fb982c25 1703 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
fee0f4c6 1704 IPV6_MAX_BYTELEN);
801a9bcc 1705 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
fee0f4c6 1706 }
1707
1708 else
801a9bcc 1709 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 1710 }
1711
1712 }
1713#endif /* HAVE_IPV6 */
1714
5000f21c 1715 bgp_peer_remove_private_as(bgp, afi, safi, rsclient, attr);
c7122e14 1716 bgp_peer_as_override(bgp, afi, safi, rsclient, attr);
fee0f4c6 1717
1718 /* Route map & unsuppress-map apply. */
fb982c25 1719 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
fee0f4c6 1720 {
1721 info.peer = rsclient;
1722 info.attr = attr;
1723
1724 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1725
fb982c25 1726 if (ri->extra && ri->extra->suppress)
fee0f4c6 1727 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1728 else
1729 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1730
1731 rsclient->rmap_type = 0;
1732
1733 if (ret == RMAP_DENYMATCH)
1734 {
1735 bgp_attr_flush (attr);
1736 return 0;
1737 }
1738 }
1739
1740 return 1;
1741}
1742
1743struct bgp_info_pair
1744{
1745 struct bgp_info *old;
1746 struct bgp_info *new;
1747};
1748
94f2b392 1749static void
96450faf
JB
1750bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1751 struct bgp_maxpaths_cfg *mpath_cfg,
1752 struct bgp_info_pair *result)
718e3744 1753{
718e3744 1754 struct bgp_info *new_select;
1755 struct bgp_info *old_select;
fee0f4c6 1756 struct bgp_info *ri;
718e3744 1757 struct bgp_info *ri1;
1758 struct bgp_info *ri2;
b40d939b 1759 struct bgp_info *nextri = NULL;
9fbdd100 1760 int paths_eq, do_mpath, debug;
96450faf 1761 struct list mp_list;
9fbdd100 1762 char pfx_buf[INET6_ADDRSTRLEN];
96450faf
JB
1763
1764 bgp_mp_list_init (&mp_list);
1765 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1766 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1767
9fbdd100
DS
1768 debug = bgp_debug_bestpath(&rn->p);
1769
1770 if (debug)
1771 prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf));
1772
718e3744 1773 /* bgp deterministic-med */
1774 new_select = NULL;
1775 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1776 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1777 {
1778 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1779 continue;
1780 if (BGP_INFO_HOLDDOWN (ri1))
1781 continue;
2fed8887
DS
1782 if (ri1->peer && ri1->peer != bgp->peer_self)
1783 if (ri1->peer->status != Established)
1784 continue;
718e3744 1785
1786 new_select = ri1;
6918e74b 1787 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
718e3744 1788 if (ri1->next)
1789 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1790 {
1791 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1792 continue;
1793 if (BGP_INFO_HOLDDOWN (ri2))
1794 continue;
2fed8887
DS
1795 if (ri2->peer &&
1796 ri2->peer != bgp->peer_self &&
1797 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1798 if (ri2->peer->status != Established)
1799 continue;
718e3744 1800
1801 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1802 || aspath_cmp_left_confed (ri1->attr->aspath,
1803 ri2->attr->aspath))
1804 {
6918e74b
JB
1805 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1806 old_select = ri2;
5e242b0d 1807 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
9fbdd100 1808 mpath_cfg, debug, pfx_buf))
718e3744 1809 {
1a392d46 1810 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
718e3744 1811 new_select = ri2;
1812 }
1813
1a392d46 1814 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
718e3744 1815 }
1816 }
1a392d46
PJ
1817 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1818 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
718e3744 1819 }
1820
1821 /* Check old selected route and new selected route. */
1822 old_select = NULL;
1823 new_select = NULL;
b40d939b 1824 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
718e3744 1825 {
1826 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1827 old_select = ri;
1828
1829 if (BGP_INFO_HOLDDOWN (ri))
b40d939b 1830 {
1831 /* reap REMOVED routes, if needs be
1832 * selected route must stay for a while longer though
1833 */
1834 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1835 && (ri != old_select))
1836 bgp_info_reap (rn, ri);
1837
1838 continue;
1839 }
718e3744 1840
2fed8887
DS
1841 if (ri->peer &&
1842 ri->peer != bgp->peer_self &&
1843 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1844 if (ri->peer->status != Established)
1845 continue;
1846
718e3744 1847 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1848 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1849 {
1a392d46 1850 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
718e3744 1851 continue;
1852 }
1a392d46
PJ
1853 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1854 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
718e3744 1855
9fbdd100 1856 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
96450faf
JB
1857 {
1858 new_select = ri;
96450faf 1859 }
718e3744 1860 }
b40d939b 1861
f4eeff72
DS
1862 /* Now that we know which path is the bestpath see if any of the other paths
1863 * qualify as multipaths
1864 */
1865 if (do_mpath && new_select)
1866 {
9fbdd100
DS
1867 if (debug)
1868 zlog_debug("%s: path %s is the bestpath, now find multipaths",
1869 pfx_buf, new_select->peer->host);
1870
f4eeff72
DS
1871 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1872 {
1873 if (ri == new_select)
1874 {
9fbdd100
DS
1875 if (debug)
1876 zlog_debug("%s: path %s is the bestpath, add to the multipath list",
1877 pfx_buf, ri->peer->host);
f4eeff72
DS
1878 bgp_mp_list_add (&mp_list, ri);
1879 continue;
1880 }
1881
1882 if (BGP_INFO_HOLDDOWN (ri))
1883 continue;
1884
1885 if (ri->peer &&
1886 ri->peer != bgp->peer_self &&
1887 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1888 if (ri->peer->status != Established)
1889 continue;
1890
9fbdd100 1891 bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
f4eeff72
DS
1892
1893 if (paths_eq)
1894 {
9fbdd100
DS
1895 if (debug)
1896 zlog_debug("%s: %s path is equivalent to the bestpath, add to the multipath list",
1897 pfx_buf, ri->peer->host);
f4eeff72
DS
1898 bgp_mp_list_add (&mp_list, ri);
1899 }
1900 }
1901 }
fee0f4c6 1902
b354c427 1903 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
0b597ef0 1904 bgp_info_mpath_aggregate_update (new_select, old_select);
96450faf
JB
1905 bgp_mp_list_clear (&mp_list);
1906
1907 result->old = old_select;
1908 result->new = new_select;
1909
1910 return;
fee0f4c6 1911}
1912
3f9c7369
DS
1913/*
1914 * A new route/change in bestpath of an existing route. Evaluate the path
1915 * for advertisement to the subgroup.
1916 */
1917int
1918subgroup_process_announce_selected (struct update_subgroup *subgrp,
1919 struct bgp_info *selected,
1920 struct bgp_node *rn)
9eda90ce 1921{
fee0f4c6 1922 struct prefix *p;
3f9c7369 1923 struct peer *onlypeer;
558d1fec
JBD
1924 struct attr attr;
1925 struct attr_extra extra;
3f9c7369
DS
1926 afi_t afi;
1927 safi_t safi;
fee0f4c6 1928
1929 p = &rn->p;
3f9c7369
DS
1930 afi = SUBGRP_AFI(subgrp);
1931 safi = SUBGRP_SAFI(subgrp);
1932 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1933 (SUBGRP_PFIRST(subgrp))->peer : NULL);
718e3744 1934
9eda90ce 1935 /* First update is deferred until ORF or ROUTE-REFRESH is received */
3f9c7369
DS
1936 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
1937 PEER_STATUS_ORF_WAIT_REFRESH))
fee0f4c6 1938 return 0;
718e3744 1939
558d1fec
JBD
1940 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1941 attr.extra = &extra;
1942
67174041 1943 switch (bgp_node_table (rn)->type)
fee0f4c6 1944 {
1945 case BGP_TABLE_MAIN:
3f9c7369 1946 /* Announcement to the subgroup. If the route is filtered,
718e3744 1947 withdraw it. */
3f9c7369
DS
1948 if (selected && subgroup_announce_check(selected, subgrp, p, &attr))
1949 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
fee0f4c6 1950 else
4125bb67 1951 bgp_adj_out_unset_subgroup(rn, subgrp, 1);
3f9c7369 1952
fee0f4c6 1953 break;
1954 case BGP_TABLE_RSCLIENT:
3f9c7369 1955 /* Announcement to peer->conf. If the route is filtered,
fee0f4c6 1956 withdraw it. */
3f9c7369
DS
1957 if (selected &&
1958 subgroup_announce_check_rsclient (selected, subgrp, p, &attr))
1959 bgp_adj_out_set_subgroup (rn, subgrp, &attr, selected);
9eda90ce 1960 else
4125bb67 1961 bgp_adj_out_unset_subgroup(rn, subgrp, 1);
fee0f4c6 1962 break;
1963 }
558d1fec 1964
fee0f4c6 1965 return 0;
200df115 1966}
fee0f4c6 1967
3f9c7369 1968struct bgp_process_queue
fee0f4c6 1969{
200df115 1970 struct bgp *bgp;
1971 struct bgp_node *rn;
1972 afi_t afi;
1973 safi_t safi;
1974};
1975
1976static wq_item_status
0fb58d5d 1977bgp_process_rsclient (struct work_queue *wq, void *data)
200df115 1978{
0fb58d5d 1979 struct bgp_process_queue *pq = data;
200df115 1980 struct bgp *bgp = pq->bgp;
1981 struct bgp_node *rn = pq->rn;
1982 afi_t afi = pq->afi;
1983 safi_t safi = pq->safi;
fee0f4c6 1984 struct bgp_info *new_select;
1985 struct bgp_info *old_select;
1986 struct bgp_info_pair old_and_new;
1eb8ef25 1987 struct listnode *node, *nnode;
cb1faec9 1988 struct peer *rsclient;
3f9c7369
DS
1989 struct peer_af *paf;
1990 struct update_subgroup *subgrp;
cb1faec9
DS
1991
1992 /* Is it end of initial update? (after startup) */
1993 if (!rn)
1994 {
4a16ae86
DS
1995 /* This is just to keep the display sane in case all the peers are
1996 rsclients only */
1997 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1998 sizeof(bgp->update_delay_zebra_resume_time));
1999
2000 bgp->rsclient_peers_update_hold = 0;
cb1faec9
DS
2001 bgp_start_routeadv(bgp);
2002 return WQ_SUCCESS;
2003 }
2004
2005 rsclient = bgp_node_table (rn)->owner;
2006
fee0f4c6 2007 /* Best path selection. */
96450faf 2008 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 2009 new_select = old_and_new.new;
2010 old_select = old_and_new.old;
2011
200df115 2012 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
2013 {
228da428
CC
2014 if (rsclient->group)
2015 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
2016 {
2017 /* Nothing to do. */
2018 if (old_select && old_select == new_select)
2019 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
2020 continue;
2021
2022 if (old_select)
2023 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
2024 if (new_select)
2025 {
2026 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
2027 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d
JB
2028 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
2029 }
228da428 2030
3f9c7369
DS
2031 paf = peer_af_find(rsclient, afi, safi);
2032 assert(paf);
2033 subgrp = PAF_SUBGRP(paf);
2034 if (!subgrp) /* not an established session */
2035 continue;
2036 subgroup_process_announce_selected (subgrp, new_select, rn);
228da428 2037 }
200df115 2038 }
2039 else
2040 {
b7395791 2041 if (old_select)
1a392d46 2042 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
b7395791 2043 if (new_select)
2044 {
1a392d46
PJ
2045 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
2046 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 2047 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
b7395791 2048 }
3f9c7369
DS
2049 paf = peer_af_find(rsclient, afi, safi);
2050 if (paf && (subgrp = PAF_SUBGRP(paf))) /* if an established session */
2051 subgroup_process_announce_selected (subgrp, new_select, rn);
200df115 2052 }
2053
b40d939b 2054 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
2055 bgp_info_reap (rn, old_select);
3f9c7369 2056
200df115 2057 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2058 return WQ_SUCCESS;
fee0f4c6 2059}
2060
200df115 2061static wq_item_status
0fb58d5d 2062bgp_process_main (struct work_queue *wq, void *data)
200df115 2063{
0fb58d5d 2064 struct bgp_process_queue *pq = data;
200df115 2065 struct bgp *bgp = pq->bgp;
2066 struct bgp_node *rn = pq->rn;
2067 afi_t afi = pq->afi;
2068 safi_t safi = pq->safi;
2069 struct prefix *p = &rn->p;
fee0f4c6 2070 struct bgp_info *new_select;
2071 struct bgp_info *old_select;
2072 struct bgp_info_pair old_and_new;
cb1faec9
DS
2073
2074 /* Is it end of initial update? (after startup) */
2075 if (!rn)
2076 {
4a16ae86
DS
2077 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
2078 sizeof(bgp->update_delay_zebra_resume_time));
2079
2080 bgp->main_zebra_update_hold = 0;
2081 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2082 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2083 {
2084 bgp_zebra_announce_table(bgp, afi, safi);
2085 }
2086 bgp->main_peers_update_hold = 0;
2087
cb1faec9
DS
2088 bgp_start_routeadv(bgp);
2089 return WQ_SUCCESS;
2090 }
2091
fee0f4c6 2092 /* Best path selection. */
96450faf 2093 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 2094 old_select = old_and_new.old;
2095 new_select = old_and_new.new;
2096
2097 /* Nothing to do. */
8ad7271d 2098 if (old_select && old_select == new_select && !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR))
fee0f4c6 2099 {
2100 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
200df115 2101 {
8196f13d
JB
2102 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
2103 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
73ac8160 2104 bgp_zebra_announce (p, old_select, bgp, afi, safi);
200df115 2105
8196f13d 2106 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
200df115 2107 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2108 return WQ_SUCCESS;
2109 }
fee0f4c6 2110 }
2111
8ad7271d
DS
2112 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
2113 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
2114
3f9c7369
DS
2115 /* bestpath has changed; bump version */
2116 if (old_select || new_select)
0de4848d
DS
2117 {
2118 bgp_bump_version(rn);
2119
2120 if (!bgp->t_rmap_def_originate_eval)
2121 {
2122 bgp_lock (bgp);
9229d914 2123 THREAD_TIMER_ON(bm->master, bgp->t_rmap_def_originate_eval,
0de4848d
DS
2124 update_group_refresh_default_originate_route_map,
2125 bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER);
2126 }
2127 }
3f9c7369 2128
338b3424 2129 if (old_select)
1a392d46 2130 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
338b3424 2131 if (new_select)
2132 {
1a392d46
PJ
2133 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
2134 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 2135 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
338b3424 2136 }
2137
3f9c7369 2138 group_announce_route(bgp, afi, safi, rn, new_select);
718e3744 2139
2140 /* FIB update. */
5a616c08
B
2141 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
2142 ! bgp_option_check (BGP_OPT_NO_FIB)))
718e3744 2143 {
2144 if (new_select
2145 && new_select->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
2146 && (new_select->sub_type == BGP_ROUTE_NORMAL ||
2147 new_select->sub_type == BGP_ROUTE_AGGREGATE))
73ac8160 2148 bgp_zebra_announce (p, new_select, bgp, afi, safi);
718e3744 2149 else
2150 {
2151 /* Withdraw the route from the kernel. */
2152 if (old_select
2153 && old_select->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
2154 && (old_select->sub_type == BGP_ROUTE_NORMAL ||
2155 old_select->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 2156 bgp_zebra_withdraw (p, old_select, safi);
718e3744 2157 }
2158 }
b40d939b 2159
2160 /* Reap old select bgp_info, it it has been removed */
2161 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
2162 bgp_info_reap (rn, old_select);
2163
200df115 2164 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2165 return WQ_SUCCESS;
718e3744 2166}
2167
200df115 2168static void
0fb58d5d 2169bgp_processq_del (struct work_queue *wq, void *data)
200df115 2170{
0fb58d5d 2171 struct bgp_process_queue *pq = data;
cb1faec9
DS
2172 struct bgp_table *table;
2173
228da428 2174 bgp_unlock (pq->bgp);
cb1faec9
DS
2175 if (pq->rn)
2176 {
2177 table = bgp_node_table (pq->rn);
2178 bgp_unlock_node (pq->rn);
2179 bgp_table_unlock (table);
2180 }
200df115 2181 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
2182}
2183
f188f2c4 2184void
200df115 2185bgp_process_queue_init (void)
2186{
495f0b13
DS
2187 if (!bm->process_main_queue)
2188 {
2189 bm->process_main_queue
87d4a781 2190 = work_queue_new (bm->master, "process_main_queue");
495f0b13
DS
2191 }
2192
2193 if (!bm->process_rsclient_queue)
2194 {
2195 bm->process_rsclient_queue
87d4a781 2196 = work_queue_new (bm->master, "process_rsclient_queue");
495f0b13
DS
2197 }
2198
200df115 2199 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
2200 {
2201 zlog_err ("%s: Failed to allocate work queue", __func__);
2202 exit (1);
2203 }
2204
2205 bm->process_main_queue->spec.workfunc = &bgp_process_main;
200df115 2206 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
838bbde0
PJ
2207 bm->process_main_queue->spec.max_retries = 0;
2208 bm->process_main_queue->spec.hold = 50;
d889623f
DS
2209 /* Use a higher yield value of 50ms for main queue processing */
2210 bm->process_main_queue->spec.yield = 50 * 1000L;
838bbde0 2211
838bbde0 2212 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
c12cd8bb
DW
2213 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
2214 bm->process_rsclient_queue->spec.max_retries = 0;
2215 bm->process_rsclient_queue->spec.hold = 50;
2216 /* Use a higher yield value of 50ms for main queue processing */
2217 bm->process_rsclient_queue->spec.yield = 50 * 1000L;
200df115 2218}
2219
2220void
fee0f4c6 2221bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
2222{
200df115 2223 struct bgp_process_queue *pqnode;
2224
2225 /* already scheduled for processing? */
2226 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
2227 return;
495f0b13 2228
2e02b9b2
DS
2229 if ( (bm->process_main_queue == NULL) ||
2230 (bm->process_rsclient_queue == NULL) )
2231 bgp_process_queue_init ();
2232
200df115 2233 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2234 sizeof (struct bgp_process_queue));
2235 if (!pqnode)
2236 return;
228da428
CC
2237
2238 /* all unlocked in bgp_processq_del */
67174041 2239 bgp_table_lock (bgp_node_table (rn));
228da428 2240 pqnode->rn = bgp_lock_node (rn);
200df115 2241 pqnode->bgp = bgp;
228da428 2242 bgp_lock (bgp);
200df115 2243 pqnode->afi = afi;
2244 pqnode->safi = safi;
2245
67174041 2246 switch (bgp_node_table (rn)->type)
fee0f4c6 2247 {
200df115 2248 case BGP_TABLE_MAIN:
2249 work_queue_add (bm->process_main_queue, pqnode);
2250 break;
2251 case BGP_TABLE_RSCLIENT:
2252 work_queue_add (bm->process_rsclient_queue, pqnode);
2253 break;
fee0f4c6 2254 }
200df115 2255
07ff4dc4 2256 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
200df115 2257 return;
fee0f4c6 2258}
0a486e5f 2259
cb1faec9
DS
2260void
2261bgp_add_eoiu_mark (struct bgp *bgp, bgp_table_t type)
2262{
2263 struct bgp_process_queue *pqnode;
2264
2e02b9b2
DS
2265 if ( (bm->process_main_queue == NULL) ||
2266 (bm->process_rsclient_queue == NULL) )
2267 bgp_process_queue_init ();
2268
cb1faec9
DS
2269 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2270 sizeof (struct bgp_process_queue));
2271 if (!pqnode)
2272 return;
2273
2274 pqnode->rn = NULL;
2275 pqnode->bgp = bgp;
2276 bgp_lock (bgp);
2277 switch (type)
2278 {
2279 case BGP_TABLE_MAIN:
2280 work_queue_add (bm->process_main_queue, pqnode);
2281 break;
2282 case BGP_TABLE_RSCLIENT:
2283 work_queue_add (bm->process_rsclient_queue, pqnode);
2284 break;
2285 }
2286
2287 return;
2288}
2289
94f2b392 2290static int
0a486e5f 2291bgp_maximum_prefix_restart_timer (struct thread *thread)
2292{
2293 struct peer *peer;
2294
2295 peer = THREAD_ARG (thread);
2296 peer->t_pmax_restart = NULL;
2297
16286195 2298 if (bgp_debug_neighbor_events(peer))
0a486e5f 2299 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
2300 peer->host);
2301
1ff9a340 2302 peer_clear (peer, NULL);
0a486e5f 2303
2304 return 0;
2305}
2306
718e3744 2307int
5228ad27 2308bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
2309 safi_t safi, int always)
718e3744 2310{
e0701b79 2311 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
2312 return 0;
2313
2314 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
718e3744 2315 {
e0701b79 2316 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
2317 && ! always)
2318 return 0;
2319
16286195
DS
2320 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
2321 "limit %ld", afi_safi_print (afi, safi), peer->host,
2322 peer->pcount[afi][safi], peer->pmax[afi][safi]);
e0701b79 2323 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2324
2325 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
2326 return 0;
2327
2328 {
5228ad27 2329 u_int8_t ndata[7];
e0701b79 2330
2331 if (safi == SAFI_MPLS_VPN)
42e6d745 2332 safi = SAFI_MPLS_LABELED_VPN;
5228ad27 2333
2334 ndata[0] = (afi >> 8);
2335 ndata[1] = afi;
2336 ndata[2] = safi;
2337 ndata[3] = (peer->pmax[afi][safi] >> 24);
2338 ndata[4] = (peer->pmax[afi][safi] >> 16);
2339 ndata[5] = (peer->pmax[afi][safi] >> 8);
2340 ndata[6] = (peer->pmax[afi][safi]);
e0701b79 2341
2342 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
2343 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
2344 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
2345 }
0a486e5f 2346
f14e6fdb
DS
2347 /* Dynamic peers will just close their connection. */
2348 if (peer_dynamic_neighbor (peer))
2349 return 1;
2350
0a486e5f 2351 /* restart timer start */
2352 if (peer->pmax_restart[afi][safi])
2353 {
2354 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
2355
16286195 2356 if (bgp_debug_neighbor_events(peer))
0a486e5f 2357 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2358 peer->host, peer->v_pmax_restart);
2359
2360 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2361 peer->v_pmax_restart);
2362 }
2363
e0701b79 2364 return 1;
2365 }
2366 else
2367 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2368
2369 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2370 {
2371 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2372 && ! always)
2373 return 0;
2374
16286195
DS
2375 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2376 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2377 peer->pmax[afi][safi]);
e0701b79 2378 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2379 }
e0701b79 2380 else
2381 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2382 return 0;
2383}
2384
b40d939b 2385/* Unconditionally remove the route from the RIB, without taking
2386 * damping into consideration (eg, because the session went down)
2387 */
94f2b392 2388static void
718e3744 2389bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2390 afi_t afi, safi_t safi)
2391{
902212c3 2392 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2393
2394 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2395 bgp_info_delete (rn, ri); /* keep historical info */
2396
b40d939b 2397 bgp_process (peer->bgp, rn, afi, safi);
718e3744 2398}
2399
94f2b392 2400static void
718e3744 2401bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
b40d939b 2402 afi_t afi, safi_t safi)
718e3744 2403{
718e3744 2404 int status = BGP_DAMP_NONE;
2405
b40d939b 2406 /* apply dampening, if result is suppressed, we'll be retaining
2407 * the bgp_info in the RIB for historical reference.
2408 */
2409 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2410 && peer->sort == BGP_PEER_EBGP)
b40d939b 2411 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2412 == BGP_DAMP_SUPPRESSED)
902212c3 2413 {
902212c3 2414 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2415 return;
2416 }
2417
2418 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 2419}
2420
fb018d25 2421static struct bgp_info *
7c8ff89e 2422info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
fb018d25
DS
2423 struct bgp_node *rn)
2424{
2425 struct bgp_info *new;
2426
2427 /* Make new BGP info. */
2428 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2429 new->type = type;
7c8ff89e 2430 new->instance = instance;
fb018d25
DS
2431 new->sub_type = sub_type;
2432 new->peer = peer;
2433 new->attr = attr;
2434 new->uptime = bgp_clock ();
2435 new->net = rn;
2436 return new;
2437}
2438
94f2b392 2439static void
cd808e74
DS
2440bgp_info_addpath_rx_str(struct bgp_info *ri, char *buf)
2441{
2442 if (ri && ri->addpath_rx_id)
2443 sprintf(buf, " with addpath ID %d", ri->addpath_rx_id);
cd808e74
DS
2444}
2445
c265ee22
DS
2446/* Check if received nexthop is valid or not. */
2447static int
2448bgp_update_martian_nexthop (afi_t afi, safi_t safi, struct attr *attr)
2449{
2450 struct attr_extra *attre = attr->extra;
2451 int ret = 0;
2452
2453 /* Only validated for unicast and multicast currently. */
2454 if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST)
2455 return 0;
2456
2457 /* If NEXT_HOP is present, validate it. */
2458 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP))
2459 {
2460 if (attr->nexthop.s_addr == 0 ||
2461 IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) ||
2462 bgp_nexthop_self (attr))
2463 ret = 1;
2464 }
2465
2466 /* If MP_NEXTHOP is present, validate it. */
2467 /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop;
2468 * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if
2469 * it is not an IPv6 link-local address.
2470 */
2471 if (attre && attre->mp_nexthop_len)
2472 {
2473 switch (attre->mp_nexthop_len)
2474 {
2475 case BGP_ATTR_NHLEN_IPV4:
2476 case BGP_ATTR_NHLEN_VPNV4:
2477 ret = (attre->mp_nexthop_global_in.s_addr == 0 ||
2478 IPV4_CLASS_DE (ntohl (attre->mp_nexthop_global_in.s_addr)));
2479 break;
2480
2481#ifdef HAVE_IPV6
2482 case BGP_ATTR_NHLEN_IPV6_GLOBAL:
2483 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
2484 ret = (IN6_IS_ADDR_UNSPECIFIED(&attre->mp_nexthop_global) ||
2485 IN6_IS_ADDR_LOOPBACK(&attre->mp_nexthop_global) ||
2486 IN6_IS_ADDR_MULTICAST(&attre->mp_nexthop_global));
2487 break;
2488#endif /* HAVE_IPV6 */
2489
2490 default:
2491 ret = 1;
2492 break;
2493 }
2494 }
2495
2496 return ret;
2497}
2498
cd808e74
DS
2499static void
2500bgp_update_rsclient (struct peer *rsclient, u_int32_t addpath_id,
2501 afi_t afi, safi_t safi, struct attr *attr,
2502 struct peer *peer, struct prefix *p, int type,
2503 int sub_type, struct prefix_rd *prd, u_char *tag)
fee0f4c6 2504{
2505 struct bgp_node *rn;
2506 struct bgp *bgp;
558d1fec
JBD
2507 struct attr new_attr;
2508 struct attr_extra new_extra;
fee0f4c6 2509 struct attr *attr_new;
2510 struct attr *attr_new2;
2511 struct bgp_info *ri;
2512 struct bgp_info *new;
fd79ac91 2513 const char *reason;
fee0f4c6 2514 char buf[SU_ADDRSTRLEN];
cd808e74 2515 char buf2[30];
fee0f4c6 2516
2517 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
2518 if (peer == rsclient)
2519 return;
2520
2521 bgp = peer->bgp;
2522 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2523
2524 /* Check previously received route. */
2525 for (ri = rn->info; ri; ri = ri->next)
cd808e74
DS
2526 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2527 ri->addpath_rx_id == addpath_id)
fee0f4c6 2528 break;
2529
2530 /* AS path loop check. */
000e157c 2531 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
fee0f4c6 2532 {
2533 reason = "as-path contains our own AS;";
2534 goto filtered;
2535 }
2536
2537 /* Route reflector originator ID check. */
2538 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 2539 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
fee0f4c6 2540 {
2541 reason = "originator is us;";
2542 goto filtered;
2543 }
fb982c25 2544
558d1fec 2545 new_attr.extra = &new_extra;
fb982c25 2546 bgp_attr_dup (&new_attr, attr);
fee0f4c6 2547
2548 /* Apply export policy. */
2549 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
2550 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
2551 {
2552 reason = "export-policy;";
2553 goto filtered;
2554 }
2555
2556 attr_new2 = bgp_attr_intern (&new_attr);
fb982c25 2557
fee0f4c6 2558 /* Apply import policy. */
2559 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
2560 {
f6f434b2 2561 bgp_attr_unintern (&attr_new2);
fee0f4c6 2562
2563 reason = "import-policy;";
2564 goto filtered;
2565 }
2566
2567 attr_new = bgp_attr_intern (&new_attr);
f6f434b2 2568 bgp_attr_unintern (&attr_new2);
fee0f4c6 2569
c265ee22
DS
2570 /* next hop check. */
2571 if (bgp_update_martian_nexthop (afi, safi, &new_attr))
fee0f4c6 2572 {
c265ee22
DS
2573 bgp_attr_unintern (&attr_new);
2574 reason = "martian next-hop;";
2575 goto filtered;
fee0f4c6 2576 }
558d1fec 2577
fee0f4c6 2578 /* If the update is implicit withdraw. */
2579 if (ri)
2580 {
65957886 2581 ri->uptime = bgp_clock ();
fee0f4c6 2582
2583 /* Same attribute comes in. */
16d2e241
PJ
2584 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
2585 && attrhash_cmp (ri->attr, attr_new))
fee0f4c6 2586 {
2587
3f9c7369 2588 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2589 {
2590 bgp_info_addpath_rx_str(ri, buf2);
2591 zlog_debug ("%s rcvd %s/%d%s for RS-client %s...duplicate ignored",
2592 peer->host,
2593 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2594 p->prefixlen, buf2, rsclient->host);
2595 }
fee0f4c6 2596
228da428 2597 bgp_unlock_node (rn);
f6f434b2 2598 bgp_attr_unintern (&attr_new);
fee0f4c6 2599
228da428 2600 return;
fee0f4c6 2601 }
2602
16d2e241
PJ
2603 /* Withdraw/Announce before we fully processed the withdraw */
2604 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2605 bgp_info_restore (rn, ri);
2606
fee0f4c6 2607 /* Received Logging. */
3f9c7369 2608 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2609 {
2610 bgp_info_addpath_rx_str(ri, buf2);
2611 zlog_debug ("%s rcvd %s/%d%s for RS-client %s",
2612 peer->host,
2613 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2614 p->prefixlen, buf2, rsclient->host);
2615 }
fee0f4c6 2616
2617 /* The attribute is changed. */
1a392d46 2618 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
fee0f4c6 2619
2620 /* Update to new attribute. */
f6f434b2 2621 bgp_attr_unintern (&ri->attr);
fee0f4c6 2622 ri->attr = attr_new;
2623
2624 /* Update MPLS tag. */
2625 if (safi == SAFI_MPLS_VPN)
fb982c25 2626 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
fee0f4c6 2627
1a392d46 2628 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
fee0f4c6 2629
2630 /* Process change. */
2631 bgp_process (bgp, rn, afi, safi);
2632 bgp_unlock_node (rn);
2633
2634 return;
2635 }
2636
2637 /* Received Logging. */
3f9c7369 2638 if (bgp_debug_update(peer, p, NULL, 1))
fee0f4c6 2639 {
cd808e74
DS
2640 bgp_info_addpath_rx_str(ri, buf2);
2641 zlog_debug ("%s rcvd %s/%d%s for RS-client %s",
16286195
DS
2642 peer->host,
2643 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2644 p->prefixlen, buf2, rsclient->host);
fee0f4c6 2645 }
2646
7c8ff89e 2647 new = info_make(type, sub_type, 0, peer, attr_new, rn);
fee0f4c6 2648
2649 /* Update MPLS tag. */
2650 if (safi == SAFI_MPLS_VPN)
fb982c25 2651 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
fee0f4c6 2652
1a392d46 2653 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
fee0f4c6 2654
2655 /* Register new BGP information. */
2656 bgp_info_add (rn, new);
200df115 2657
2658 /* route_node_get lock */
2659 bgp_unlock_node (rn);
2660
fee0f4c6 2661 /* Process change. */
2662 bgp_process (bgp, rn, afi, safi);
558d1fec 2663
fee0f4c6 2664 return;
2665
2666 filtered:
2667
2668 /* This BGP update is filtered. Log the reason then update BGP entry. */
3f9c7369 2669 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2670 {
2671 bgp_info_addpath_rx_str(ri, buf2);
2672 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED for RS-client %s due to: %s",
2673 peer->host,
2674 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2675 p->prefixlen, buf2, rsclient->host, reason);
2676 }
fee0f4c6 2677
2678 if (ri)
b40d939b 2679 bgp_rib_remove (rn, ri, peer, afi, safi);
fee0f4c6 2680
2681 bgp_unlock_node (rn);
558d1fec 2682
fee0f4c6 2683 return;
2684}
2685
94f2b392 2686static void
cd808e74
DS
2687bgp_withdraw_rsclient (struct peer *rsclient, u_int32_t addpath_id,
2688 afi_t afi, safi_t safi, struct peer *peer,
2689 struct prefix *p, int type, int sub_type,
2690 struct prefix_rd *prd, u_char *tag)
228da428 2691{
fee0f4c6 2692 struct bgp_node *rn;
2693 struct bgp_info *ri;
2694 char buf[SU_ADDRSTRLEN];
2695
2696 if (rsclient == peer)
228da428 2697 return;
fee0f4c6 2698
2699 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2700
2701 /* Lookup withdrawn route. */
2702 for (ri = rn->info; ri; ri = ri->next)
cd808e74
DS
2703 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2704 ri->addpath_rx_id == addpath_id)
fee0f4c6 2705 break;
2706
2707 /* Withdraw specified route from routing table. */
2708 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
b40d939b 2709 bgp_rib_withdraw (rn, ri, peer, afi, safi);
3f9c7369 2710 else if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2711 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2712 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2713 p->prefixlen);
fee0f4c6 2714
2715 /* Unlock bgp_node_get() lock. */
228da428
CC
2716 bgp_unlock_node (rn);
2717}
fee0f4c6 2718
94f2b392 2719static int
a82478b9
DS
2720bgp_update_main (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2721 struct attr *attr, afi_t afi, safi_t safi, int type,
2722 int sub_type, struct prefix_rd *prd, u_char *tag,
2723 int soft_reconfig)
718e3744 2724{
2725 int ret;
2726 int aspath_loop_count = 0;
2727 struct bgp_node *rn;
2728 struct bgp *bgp;
558d1fec
JBD
2729 struct attr new_attr;
2730 struct attr_extra new_extra;
718e3744 2731 struct attr *attr_new;
2732 struct bgp_info *ri;
2733 struct bgp_info *new;
fd79ac91 2734 const char *reason;
718e3744 2735 char buf[SU_ADDRSTRLEN];
cd808e74 2736 char buf2[30];
fc9a856f 2737 int connected = 0;
718e3744 2738
2739 bgp = peer->bgp;
fee0f4c6 2740 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
fb982c25 2741
718e3744 2742 /* When peer's soft reconfiguration enabled. Record input packet in
2743 Adj-RIBs-In. */
343aa822
JBD
2744 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2745 && peer != bgp->peer_self)
43143c8f 2746 bgp_adj_in_set (rn, peer, attr, addpath_id);
718e3744 2747
2748 /* Check previously received route. */
2749 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
2750 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2751 ri->addpath_rx_id == addpath_id)
718e3744 2752 break;
2753
2754 /* AS path local-as loop check. */
2755 if (peer->change_local_as)
2756 {
2757 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2758 aspath_loop_count = 1;
2759
2760 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2761 {
2762 reason = "as-path contains our own AS;";
2763 goto filtered;
2764 }
2765 }
2766
2767 /* AS path loop check. */
2768 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2769 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2770 && aspath_loop_check(attr->aspath, bgp->confed_id)
2771 > peer->allowas_in[afi][safi]))
2772 {
2773 reason = "as-path contains our own AS;";
2774 goto filtered;
2775 }
2776
2777 /* Route reflector originator ID check. */
2778 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 2779 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
718e3744 2780 {
2781 reason = "originator is us;";
2782 goto filtered;
2783 }
2784
2785 /* Route reflector cluster ID check. */
2786 if (bgp_cluster_filter (peer, attr))
2787 {
2788 reason = "reflected from the same cluster;";
2789 goto filtered;
2790 }
2791
2792 /* Apply incoming filter. */
2793 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2794 {
2795 reason = "filter;";
2796 goto filtered;
2797 }
2798
558d1fec 2799 new_attr.extra = &new_extra;
fb982c25 2800 bgp_attr_dup (&new_attr, attr);
718e3744 2801
c460e572
DL
2802 /* Apply incoming route-map.
2803 * NB: new_attr may now contain newly allocated values from route-map "set"
2804 * commands, so we need bgp_attr_flush in the error paths, until we intern
2805 * the attr (which takes over the memory references) */
0b16f239 2806 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
718e3744 2807 {
2808 reason = "route-map;";
c460e572 2809 bgp_attr_flush (&new_attr);
718e3744 2810 goto filtered;
2811 }
2812
c265ee22
DS
2813 /* next hop check. */
2814 if (bgp_update_martian_nexthop (afi, safi, &new_attr))
718e3744 2815 {
c265ee22
DS
2816 reason = "martian or self next-hop;";
2817 bgp_attr_flush (&new_attr);
2818 goto filtered;
718e3744 2819 }
2820
2821 attr_new = bgp_attr_intern (&new_attr);
2822
2823 /* If the update is implicit withdraw. */
2824 if (ri)
2825 {
65957886 2826 ri->uptime = bgp_clock ();
718e3744 2827
2828 /* Same attribute comes in. */
16d2e241
PJ
2829 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2830 && attrhash_cmp (ri->attr, attr_new))
718e3744 2831 {
718e3744 2832 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2833 && peer->sort == BGP_PEER_EBGP
718e3744 2834 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2835 {
3f9c7369 2836 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2837 {
2838 bgp_info_addpath_rx_str(ri, buf2);
2839 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2840 peer->host,
2841 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74
DS
2842 p->prefixlen, buf2);
2843 }
718e3744 2844
902212c3 2845 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2846 {
2847 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2848 bgp_process (bgp, rn, afi, safi);
2849 }
718e3744 2850 }
16d2e241 2851 else /* Duplicate - odd */
718e3744 2852 {
3f9c7369 2853 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2854 {
2855 if (!peer->rcvd_attr_printed)
2856 {
2857 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2858 peer->rcvd_attr_printed = 1;
2859 }
2860
cd808e74
DS
2861 bgp_info_addpath_rx_str(ri, buf2);
2862 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
16286195
DS
2863 peer->host,
2864 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2865 p->prefixlen, buf2);
16286195 2866 }
93406d87 2867
2868 /* graceful restart STALE flag unset. */
2869 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2870 {
1a392d46 2871 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
902212c3 2872 bgp_process (bgp, rn, afi, safi);
93406d87 2873 }
718e3744 2874 }
2875
2876 bgp_unlock_node (rn);
f6f434b2 2877 bgp_attr_unintern (&attr_new);
558d1fec 2878
718e3744 2879 return 0;
2880 }
2881
16d2e241
PJ
2882 /* Withdraw/Announce before we fully processed the withdraw */
2883 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2884 {
3f9c7369 2885 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2886 {
2887 bgp_info_addpath_rx_str(ri, buf2);
2888 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
2889 peer->host,
2890 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2891 p->prefixlen, buf2);
2892 }
16d2e241
PJ
2893 bgp_info_restore (rn, ri);
2894 }
2895
718e3744 2896 /* Received Logging. */
3f9c7369 2897 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2898 {
2899 bgp_info_addpath_rx_str(ri, buf2);
2900 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2901 peer->host,
2902 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74
DS
2903 p->prefixlen, buf2);
2904 }
718e3744 2905
93406d87 2906 /* graceful restart STALE flag unset. */
2907 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1a392d46 2908 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
93406d87 2909
718e3744 2910 /* The attribute is changed. */
1a392d46 2911 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
902212c3 2912
2913 /* implicit withdraw, decrement aggregate and pcount here.
2914 * only if update is accepted, they'll increment below.
2915 */
902212c3 2916 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2917
718e3744 2918 /* Update bgp route dampening information. */
2919 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2920 && peer->sort == BGP_PEER_EBGP)
718e3744 2921 {
2922 /* This is implicit withdraw so we should update dampening
2923 information. */
2924 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2925 bgp_damp_withdraw (ri, rn, afi, safi, 1);
718e3744 2926 }
2927
718e3744 2928 /* Update to new attribute. */
f6f434b2 2929 bgp_attr_unintern (&ri->attr);
718e3744 2930 ri->attr = attr_new;
2931
2932 /* Update MPLS tag. */
2933 if (safi == SAFI_MPLS_VPN)
fb982c25 2934 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
718e3744 2935
2936 /* Update bgp route dampening information. */
2937 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2938 && peer->sort == BGP_PEER_EBGP)
718e3744 2939 {
2940 /* Now we do normal update dampening. */
2941 ret = bgp_damp_update (ri, rn, afi, safi);
2942 if (ret == BGP_DAMP_SUPPRESSED)
2943 {
2944 bgp_unlock_node (rn);
2945 return 0;
2946 }
2947 }
2948
2949 /* Nexthop reachability check. */
fc9a856f 2950 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
718e3744 2951 {
fc9a856f 2952 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
907f92c8
DS
2953 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2954 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
fc9a856f
DS
2955 connected = 1;
2956 else
2957 connected = 0;
2958
75aead62 2959 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
1a392d46 2960 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 2961 else
fc9a856f
DS
2962 {
2963 if (BGP_DEBUG(nht, NHT))
2964 {
2965 char buf1[INET6_ADDRSTRLEN];
2966 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2967 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2968 }
2969 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2970 }
718e3744 2971 }
2972 else
fc9a856f 2973 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 2974
2975 /* Process change. */
2976 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2977
2978 bgp_process (bgp, rn, afi, safi);
2979 bgp_unlock_node (rn);
558d1fec 2980
718e3744 2981 return 0;
a82478b9 2982 } // End of implicit withdraw
718e3744 2983
2984 /* Received Logging. */
3f9c7369 2985 if (bgp_debug_update(peer, p, NULL, 1))
718e3744 2986 {
16286195
DS
2987 if (!peer->rcvd_attr_printed)
2988 {
2989 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2990 peer->rcvd_attr_printed = 1;
2991 }
2992
cd808e74
DS
2993 bgp_info_addpath_rx_str(ri, buf2);
2994 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2995 peer->host,
2996 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2997 p->prefixlen, buf2);
718e3744 2998 }
2999
718e3744 3000 /* Make new BGP info. */
7c8ff89e 3001 new = info_make(type, sub_type, 0, peer, attr_new, rn);
718e3744 3002
3003 /* Update MPLS tag. */
3004 if (safi == SAFI_MPLS_VPN)
fb982c25 3005 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
718e3744 3006
3007 /* Nexthop reachability check. */
fc9a856f
DS
3008 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
3009 {
3010 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
907f92c8
DS
3011 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
3012 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
fc9a856f
DS
3013 connected = 1;
3014 else
3015 connected = 0;
3016
75aead62 3017 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
1a392d46 3018 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 3019 else
fc9a856f
DS
3020 {
3021 if (BGP_DEBUG(nht, NHT))
3022 {
3023 char buf1[INET6_ADDRSTRLEN];
3024 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
3025 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3026 }
3027 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3028 }
718e3744 3029 }
3030 else
1a392d46 3031 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 3032
a82478b9
DS
3033 /* Addpath ID */
3034 new->addpath_rx_id = addpath_id;
3035 new->addpath_tx_id = 0;
3036
902212c3 3037 /* Increment prefix */
718e3744 3038 bgp_aggregate_increment (bgp, p, new, afi, safi);
3039
3040 /* Register new BGP information. */
3041 bgp_info_add (rn, new);
200df115 3042
3043 /* route_node_get lock */
3044 bgp_unlock_node (rn);
558d1fec 3045
718e3744 3046 /* If maximum prefix count is configured and current prefix
3047 count exeed it. */
e0701b79 3048 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
3049 return -1;
718e3744 3050
3051 /* Process change. */
3052 bgp_process (bgp, rn, afi, safi);
3053
3054 return 0;
3055
3056 /* This BGP update is filtered. Log the reason then update BGP
3057 entry. */
3058 filtered:
3f9c7369 3059 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
3060 {
3061 if (!peer->rcvd_attr_printed)
3062 {
3063 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
3064 peer->rcvd_attr_printed = 1;
3065 }
3066
cd808e74
DS
3067 bgp_info_addpath_rx_str(ri, buf2);
3068 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
16286195
DS
3069 peer->host,
3070 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 3071 p->prefixlen, buf2, reason);
16286195 3072 }
718e3744 3073
3074 if (ri)
b40d939b 3075 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 3076
3077 bgp_unlock_node (rn);
558d1fec 3078
718e3744 3079 return 0;
3080}
3081
fee0f4c6 3082int
a82478b9
DS
3083bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
3084 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
fee0f4c6 3085 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
3086{
3087 struct peer *rsclient;
1eb8ef25 3088 struct listnode *node, *nnode;
fee0f4c6 3089 struct bgp *bgp;
3090 int ret;
3091
a82478b9
DS
3092 ret = bgp_update_main (peer, p, addpath_id, attr, afi, safi, type, sub_type,
3093 prd, tag, soft_reconfig);
fee0f4c6 3094
3095 bgp = peer->bgp;
3096
3097 /* Process the update for each RS-client. */
1eb8ef25 3098 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 3099 {
3100 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
cd808e74 3101 bgp_update_rsclient (rsclient, addpath_id, afi, safi, attr, peer, p,
a82478b9 3102 type, sub_type, prd, tag);
fee0f4c6 3103 }
3104
3105 return ret;
3106}
3107
718e3744 3108int
a82478b9
DS
3109bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
3110 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
3111 struct prefix_rd *prd, u_char *tag)
718e3744 3112{
3113 struct bgp *bgp;
3114 char buf[SU_ADDRSTRLEN];
cd808e74 3115 char buf2[30];
718e3744 3116 struct bgp_node *rn;
3117 struct bgp_info *ri;
fee0f4c6 3118 struct peer *rsclient;
1eb8ef25 3119 struct listnode *node, *nnode;
718e3744 3120
3121 bgp = peer->bgp;
3122
fee0f4c6 3123 /* Process the withdraw for each RS-client. */
1eb8ef25 3124 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 3125 {
3126 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
cd808e74 3127 bgp_withdraw_rsclient (rsclient, addpath_id, afi, safi, peer, p, type,
a82478b9 3128 sub_type, prd, tag);
fee0f4c6 3129 }
3130
718e3744 3131 /* Lookup node. */
fee0f4c6 3132 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 3133
3134 /* If peer is soft reconfiguration enabled. Record input packet for
3135 further calculation. */
3136 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
3137 && peer != bgp->peer_self)
43143c8f 3138 bgp_adj_in_unset (rn, peer, addpath_id);
718e3744 3139
3140 /* Lookup withdrawn route. */
3141 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
3142 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
3143 ri->addpath_rx_id == addpath_id)
718e3744 3144 break;
3145
cd808e74
DS
3146 /* Logging. */
3147 if (bgp_debug_update(peer, p, NULL, 1))
3148 {
3149 bgp_info_addpath_rx_str(ri, buf2);
3150 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
3151 peer->host,
3152 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3153 p->prefixlen, buf2);
3154 }
3155
718e3744 3156 /* Withdraw specified route from routing table. */
3157 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
b40d939b 3158 bgp_rib_withdraw (rn, ri, peer, afi, safi);
3f9c7369 3159 else if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
3160 zlog_debug ("%s Can't find the route %s/%d", peer->host,
3161 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3162 p->prefixlen);
718e3744 3163
3164 /* Unlock bgp_node_get() lock. */
3165 bgp_unlock_node (rn);
3166
3167 return 0;
3168}
6b0655a2 3169
718e3744 3170void
3171bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
3172{
3f9c7369
DS
3173 struct update_subgroup *subgrp;
3174 subgrp = peer_subgroup(peer, afi, safi);
3175 subgroup_default_originate(subgrp, withdraw);
3176}
6182d65b 3177
718e3744 3178
3f9c7369
DS
3179/*
3180 * bgp_stop_announce_route_timer
3181 */
3182void
3183bgp_stop_announce_route_timer (struct peer_af *paf)
3184{
3185 if (!paf->t_announce_route)
3186 return;
718e3744 3187
3f9c7369 3188 THREAD_TIMER_OFF (paf->t_announce_route);
718e3744 3189}
6b0655a2 3190
3f9c7369
DS
3191/*
3192 * bgp_announce_route_timer_expired
3193 *
3194 * Callback that is invoked when the route announcement timer for a
3195 * peer_af expires.
3196 */
3197static int
3198bgp_announce_route_timer_expired (struct thread *t)
718e3744 3199{
3f9c7369
DS
3200 struct peer_af *paf;
3201 struct peer *peer;
558d1fec 3202
718e3744 3203
3f9c7369
DS
3204 paf = THREAD_ARG (t);
3205 peer = paf->peer;
718e3744 3206
3f9c7369
DS
3207 assert (paf->t_announce_route);
3208 paf->t_announce_route = NULL;
558d1fec 3209
3f9c7369
DS
3210 if (peer->status != Established)
3211 return 0;
3212
3213 if (!peer->afc_nego[paf->afi][paf->safi])
3214 return 0;
3215
3216 peer_af_announce_route (paf, 1);
3217 return 0;
718e3744 3218}
3219
3f9c7369
DS
3220/*
3221 * bgp_announce_route
3222 *
3223 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
3224 */
718e3744 3225void
3226bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
3227{
3f9c7369
DS
3228 struct peer_af *paf;
3229 struct update_subgroup *subgrp;
718e3744 3230
3f9c7369
DS
3231 paf = peer_af_find (peer, afi, safi);
3232 if (!paf)
718e3744 3233 return;
3f9c7369 3234 subgrp = PAF_SUBGRP(paf);
718e3744 3235
3f9c7369
DS
3236 /*
3237 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
3238 * or a refresh has already been triggered.
3239 */
3240 if (!subgrp || paf->t_announce_route)
718e3744 3241 return;
3242
d889623f 3243 /*
3f9c7369
DS
3244 * Start a timer to stagger/delay the announce. This serves
3245 * two purposes - announcement can potentially be combined for
3246 * multiple peers and the announcement doesn't happen in the
3247 * vty context.
d889623f 3248 */
9229d914 3249 THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route,
3f9c7369
DS
3250 bgp_announce_route_timer_expired, paf,
3251 (subgrp->peer_count == 1) ?
3252 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
3253 BGP_ANNOUNCE_ROUTE_DELAY_MS);
3254}
3255
3256/*
3257 * Announce routes from all AF tables to a peer.
3258 *
3259 * This should ONLY be called when there is a need to refresh the
3260 * routes to the peer based on a policy change for this peer alone
3261 * or a route refresh request received from the peer.
3262 * The operation will result in splitting the peer from its existing
3263 * subgroups and putting it in new subgroups.
3264 */
718e3744 3265void
3266bgp_announce_route_all (struct peer *peer)
3267{
3268 afi_t afi;
3269 safi_t safi;
3270
3271 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3272 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3273 bgp_announce_route (peer, afi, safi);
3274}
6b0655a2 3275
718e3744 3276static void
fee0f4c6 3277bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
8692c506 3278 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
fee0f4c6 3279{
3280 struct bgp_node *rn;
3281 struct bgp_adj_in *ain;
3282
3283 if (! table)
3284 table = rsclient->bgp->rib[afi][safi];
3285
3286 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3287 for (ain = rn->adj_in; ain; ain = ain->next)
3288 {
8692c506 3289 struct bgp_info *ri = rn->info;
d53d8fda 3290 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 3291
cd808e74
DS
3292 bgp_update_rsclient (rsclient, ri->addpath_rx_id, afi, safi, ain->attr,
3293 ain->peer, &rn->p, ZEBRA_ROUTE_BGP,
3294 BGP_ROUTE_NORMAL, prd, tag);
fee0f4c6 3295 }
3296}
3297
3298void
3299bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3300{
3301 struct bgp_table *table;
3302 struct bgp_node *rn;
3303
3304 if (safi != SAFI_MPLS_VPN)
8692c506 3305 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
fee0f4c6 3306
3307 else
3308 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
3309 rn = bgp_route_next (rn))
3310 if ((table = rn->info) != NULL)
8692c506
JBD
3311 {
3312 struct prefix_rd prd;
3313 prd.family = AF_UNSPEC;
3314 prd.prefixlen = 64;
3315 memcpy(&prd.val, rn->p.u.val, 8);
3316
3317 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
3318 }
fee0f4c6 3319}
6b0655a2 3320
fee0f4c6 3321static void
718e3744 3322bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
8692c506 3323 struct bgp_table *table, struct prefix_rd *prd)
718e3744 3324{
3325 int ret;
3326 struct bgp_node *rn;
3327 struct bgp_adj_in *ain;
3328
3329 if (! table)
3330 table = peer->bgp->rib[afi][safi];
3331
3332 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3333 for (ain = rn->adj_in; ain; ain = ain->next)
3334 {
3335 if (ain->peer == peer)
3336 {
8692c506 3337 struct bgp_info *ri = rn->info;
d53d8fda 3338 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 3339
43143c8f 3340 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
a82478b9 3341 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
d53d8fda 3342 prd, tag, 1);
8692c506 3343
718e3744 3344 if (ret < 0)
3345 {
3346 bgp_unlock_node (rn);
3347 return;
3348 }
718e3744 3349 }
3350 }
3351}
3352
3353void
3354bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
3355{
3356 struct bgp_node *rn;
3357 struct bgp_table *table;
3358
3359 if (peer->status != Established)
3360 return;
3361
3362 if (safi != SAFI_MPLS_VPN)
8692c506 3363 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
718e3744 3364 else
3365 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3366 rn = bgp_route_next (rn))
3367 if ((table = rn->info) != NULL)
8692c506
JBD
3368 {
3369 struct prefix_rd prd;
3370 prd.family = AF_UNSPEC;
3371 prd.prefixlen = 64;
3372 memcpy(&prd.val, rn->p.u.val, 8);
3373
3374 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
3375 }
718e3744 3376}
6b0655a2 3377
228da428
CC
3378
3379struct bgp_clear_node_queue
3380{
3381 struct bgp_node *rn;
3382 enum bgp_clear_route_type purpose;
3383};
3384
200df115 3385static wq_item_status
0fb58d5d 3386bgp_clear_route_node (struct work_queue *wq, void *data)
200df115 3387{
228da428
CC
3388 struct bgp_clear_node_queue *cnq = data;
3389 struct bgp_node *rn = cnq->rn;
64e580a7 3390 struct peer *peer = wq->spec.data;
718e3744 3391 struct bgp_info *ri;
67174041
AS
3392 afi_t afi = bgp_node_table (rn)->afi;
3393 safi_t safi = bgp_node_table (rn)->safi;
200df115 3394
64e580a7 3395 assert (rn && peer);
200df115 3396
43143c8f
DS
3397 /* It is possible that we have multiple paths for a prefix from a peer
3398 * if that peer is using AddPath.
3399 */
64e580a7 3400 for (ri = rn->info; ri; ri = ri->next)
228da428 3401 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
200df115 3402 {
3403 /* graceful restart STALE flag set. */
64e580a7
PJ
3404 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
3405 && peer->nsf[afi][safi]
200df115 3406 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
1a392d46
PJ
3407 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
3408 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
200df115 3409 else
64e580a7 3410 bgp_rib_remove (rn, ri, peer, afi, safi);
200df115 3411 }
200df115 3412 return WQ_SUCCESS;
3413}
3414
3415static void
0fb58d5d 3416bgp_clear_node_queue_del (struct work_queue *wq, void *data)
200df115 3417{
228da428
CC
3418 struct bgp_clear_node_queue *cnq = data;
3419 struct bgp_node *rn = cnq->rn;
67174041 3420 struct bgp_table *table = bgp_node_table (rn);
64e580a7
PJ
3421
3422 bgp_unlock_node (rn);
228da428
CC
3423 bgp_table_unlock (table);
3424 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
200df115 3425}
3426
3427static void
94f2b392 3428bgp_clear_node_complete (struct work_queue *wq)
200df115 3429{
64e580a7
PJ
3430 struct peer *peer = wq->spec.data;
3431
3e0c78ef 3432 /* Tickle FSM to start moving again */
ca058a30 3433 BGP_EVENT_ADD (peer, Clearing_Completed);
228da428
CC
3434
3435 peer_unlock (peer); /* bgp_clear_route */
200df115 3436}
3437
3438static void
64e580a7 3439bgp_clear_node_queue_init (struct peer *peer)
200df115 3440{
a2943657 3441 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
64e580a7 3442
a2943657 3443 snprintf (wname, sizeof(wname), "clear %s", peer->host);
64e580a7
PJ
3444#undef CLEAR_QUEUE_NAME_LEN
3445
87d4a781 3446 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
200df115 3447 {
3448 zlog_err ("%s: Failed to allocate work queue", __func__);
3449 exit (1);
3450 }
64e580a7
PJ
3451 peer->clear_node_queue->spec.hold = 10;
3452 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
3453 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
3454 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
3455 peer->clear_node_queue->spec.max_retries = 0;
3456
3457 /* we only 'lock' this peer reference when the queue is actually active */
3458 peer->clear_node_queue->spec.data = peer;
200df115 3459}
718e3744 3460
200df115 3461static void
3462bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
228da428
CC
3463 struct bgp_table *table, struct peer *rsclient,
3464 enum bgp_clear_route_type purpose)
200df115 3465{
200df115 3466 struct bgp_node *rn;
3467
f2c31acb 3468
718e3744 3469 if (! table)
fee0f4c6 3470 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
64e580a7 3471
6cf159b9 3472 /* If still no table => afi/safi isn't configured at all or smth. */
3473 if (! table)
3474 return;
65ca75e0
PJ
3475
3476 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3477 {
f2c31acb
PJ
3478 struct bgp_info *ri;
3479 struct bgp_adj_in *ain;
43143c8f 3480 struct bgp_adj_in *ain_next;
f2c31acb
PJ
3481
3482 /* XXX:TODO: This is suboptimal, every non-empty route_node is
3483 * queued for every clearing peer, regardless of whether it is
3484 * relevant to the peer at hand.
3485 *
3486 * Overview: There are 3 different indices which need to be
3487 * scrubbed, potentially, when a peer is removed:
3488 *
3489 * 1 peer's routes visible via the RIB (ie accepted routes)
3490 * 2 peer's routes visible by the (optional) peer's adj-in index
3491 * 3 other routes visible by the peer's adj-out index
3492 *
3493 * 3 there is no hurry in scrubbing, once the struct peer is
3494 * removed from bgp->peer, we could just GC such deleted peer's
3495 * adj-outs at our leisure.
3496 *
3497 * 1 and 2 must be 'scrubbed' in some way, at least made
3498 * invisible via RIB index before peer session is allowed to be
3499 * brought back up. So one needs to know when such a 'search' is
3500 * complete.
3501 *
3502 * Ideally:
3503 *
3504 * - there'd be a single global queue or a single RIB walker
3505 * - rather than tracking which route_nodes still need to be
3506 * examined on a peer basis, we'd track which peers still
3507 * aren't cleared
3508 *
3509 * Given that our per-peer prefix-counts now should be reliable,
3510 * this may actually be achievable. It doesn't seem to be a huge
3511 * problem at this time,
43143c8f
DS
3512 *
3513 * It is possible that we have multiple paths for a prefix from a peer
3514 * if that peer is using AddPath.
f2c31acb 3515 */
43143c8f
DS
3516 ain = rn->adj_in;
3517 while (ain)
3518 {
3519 ain_next = ain->next;
3520
3521 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
3522 {
3523 bgp_adj_in_remove (rn, ain);
3524 bgp_unlock_node (rn);
3525 }
3526
3527 ain = ain_next;
3528 }
3f9c7369
DS
3529
3530 /*
3531 * Can't do this anymore. adj-outs are not maintained per peer.
3532 *
24e50f20
JBD
3533 for (aout = rn->adj_out; aout; aout = aout->next)
3534 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
3535 {
3536 bgp_adj_out_remove (rn, aout, peer, afi, safi);
3537 bgp_unlock_node (rn);
3538 break;
3539 }
3f9c7369 3540 */
f2c31acb 3541 for (ri = rn->info; ri; ri = ri->next)
228da428 3542 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
f2c31acb 3543 {
228da428
CC
3544 struct bgp_clear_node_queue *cnq;
3545
3546 /* both unlocked in bgp_clear_node_queue_del */
67174041 3547 bgp_table_lock (bgp_node_table (rn));
228da428
CC
3548 bgp_lock_node (rn);
3549 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
3550 sizeof (struct bgp_clear_node_queue));
3551 cnq->rn = rn;
3552 cnq->purpose = purpose;
3553 work_queue_add (peer->clear_node_queue, cnq);
3554 break;
f2c31acb 3555 }
65ca75e0
PJ
3556 }
3557 return;
3558}
3559
3560void
228da428
CC
3561bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
3562 enum bgp_clear_route_type purpose)
65ca75e0
PJ
3563{
3564 struct bgp_node *rn;
3565 struct bgp_table *table;
3566 struct peer *rsclient;
3567 struct listnode *node, *nnode;
6cf159b9 3568
64e580a7
PJ
3569 if (peer->clear_node_queue == NULL)
3570 bgp_clear_node_queue_init (peer);
200df115 3571
ca058a30
PJ
3572 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3573 * Idle until it receives a Clearing_Completed event. This protects
3574 * against peers which flap faster than we can we clear, which could
3575 * lead to:
64e580a7
PJ
3576 *
3577 * a) race with routes from the new session being installed before
3578 * clear_route_node visits the node (to delete the route of that
3579 * peer)
3580 * b) resource exhaustion, clear_route_node likely leads to an entry
3581 * on the process_main queue. Fast-flapping could cause that queue
3582 * to grow and grow.
200df115 3583 */
dc83d712
DS
3584
3585 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3586 * the unlock will happen upon work-queue completion; other wise, the
3587 * unlock happens at the end of this function.
3588 */
ca058a30 3589 if (!peer->clear_node_queue->thread)
dc83d712 3590 peer_lock (peer);
fee0f4c6 3591
228da428 3592 switch (purpose)
fee0f4c6 3593 {
228da428
CC
3594 case BGP_CLEAR_ROUTE_NORMAL:
3595 if (safi != SAFI_MPLS_VPN)
3596 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3597 else
3598 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3599 rn = bgp_route_next (rn))
3600 if ((table = rn->info) != NULL)
3601 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3602
3603 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3604 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3605 PEER_FLAG_RSERVER_CLIENT))
3606 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3607 break;
3608
3609 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
3610 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3611 break;
3612
3613 default:
3614 assert (0);
3615 break;
fee0f4c6 3616 }
dc83d712
DS
3617
3618 /* unlock if no nodes got added to the clear-node-queue. */
65ca75e0 3619 if (!peer->clear_node_queue->thread)
dc83d712
DS
3620 peer_unlock (peer);
3621
718e3744 3622}
3623
3624void
3625bgp_clear_route_all (struct peer *peer)
3626{
3627 afi_t afi;
3628 safi_t safi;
3629
3630 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3631 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
228da428 3632 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
718e3744 3633}
3634
3635void
3636bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3637{
3638 struct bgp_table *table;
3639 struct bgp_node *rn;
3640 struct bgp_adj_in *ain;
43143c8f 3641 struct bgp_adj_in *ain_next;
718e3744 3642
3643 table = peer->bgp->rib[afi][safi];
3644
43143c8f
DS
3645 /* It is possible that we have multiple paths for a prefix from a peer
3646 * if that peer is using AddPath.
3647 */
718e3744 3648 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
43143c8f
DS
3649 {
3650 ain = rn->adj_in;
3651
3652 while (ain)
3653 {
3654 ain_next = ain->next;
3655
3656 if (ain->peer == peer)
3657 {
3658 bgp_adj_in_remove (rn, ain);
3659 bgp_unlock_node (rn);
3660 }
3661
3662 ain = ain_next;
3663 }
3664 }
718e3744 3665}
93406d87 3666
3667void
3668bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3669{
3670 struct bgp_node *rn;
3671 struct bgp_info *ri;
3672 struct bgp_table *table;
3673
3674 table = peer->bgp->rib[afi][safi];
3675
3676 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3677 {
3678 for (ri = rn->info; ri; ri = ri->next)
3679 if (ri->peer == peer)
3680 {
3681 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3682 bgp_rib_remove (rn, ri, peer, afi, safi);
3683 break;
3684 }
3685 }
3686}
6b0655a2 3687
718e3744 3688/* Delete all kernel routes. */
3689void
66e5cd87 3690bgp_cleanup_routes (void)
718e3744 3691{
3692 struct bgp *bgp;
1eb8ef25 3693 struct listnode *node, *nnode;
718e3744 3694 struct bgp_node *rn;
3695 struct bgp_table *table;
3696 struct bgp_info *ri;
3697
1eb8ef25 3698 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 3699 {
3700 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3701
3702 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3703 for (ri = rn->info; ri; ri = ri->next)
3704 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3705 && ri->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
3706 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3707 ri->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 3708 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
718e3744 3709
3710 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3711
3712 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3713 for (ri = rn->info; ri; ri = ri->next)
3714 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3715 && ri->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
3716 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3717 ri->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 3718 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
718e3744 3719 }
3720}
3721
3722void
66e5cd87 3723bgp_reset (void)
718e3744 3724{
3725 vty_reset ();
3726 bgp_zclient_reset ();
3727 access_list_reset ();
3728 prefix_list_reset ();
3729}
6b0655a2 3730
718e3744 3731/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3732 value. */
3733int
3734bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3735{
3736 u_char *pnt;
3737 u_char *lim;
3738 struct prefix p;
3739 int psize;
3740 int ret;
a82478b9
DS
3741 afi_t afi;
3742 safi_t safi;
3743 u_char addpath_encoded;
3744 u_int32_t addpath_id;
718e3744 3745
3746 /* Check peer status. */
3747 if (peer->status != Established)
3748 return 0;
3749
3750 pnt = packet->nlri;
3751 lim = pnt + packet->length;
a82478b9
DS
3752 afi = packet->afi;
3753 safi = packet->safi;
3754 addpath_id = 0;
3755
3756 addpath_encoded = (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3757 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
718e3744 3758
3759 for (; pnt < lim; pnt += psize)
3760 {
3761 /* Clear prefix structure. */
3762 memset (&p, 0, sizeof (struct prefix));
3763
a82478b9
DS
3764 if (addpath_encoded)
3765 {
cd808e74
DS
3766
3767 /* When packet overflow occurs return immediately. */
3768 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3769 return -1;
3770
a82478b9
DS
3771 addpath_id = ntohl(*((uint32_t*) pnt));
3772 pnt += BGP_ADDPATH_ID_LEN;
3773 }
3774
718e3744 3775 /* Fetch prefix length. */
3776 p.prefixlen = *pnt++;
a82478b9 3777 p.family = afi2family (afi);
718e3744 3778
3779 /* Already checked in nlri_sanity_check(). We do double check
3780 here. */
a82478b9
DS
3781 if ((afi == AFI_IP && p.prefixlen > 32)
3782 || (afi == AFI_IP6 && p.prefixlen > 128))
718e3744 3783 return -1;
3784
3785 /* Packet size overflow check. */
3786 psize = PSIZE (p.prefixlen);
3787
3788 /* When packet overflow occur return immediately. */
3789 if (pnt + psize > lim)
3790 return -1;
3791
3792 /* Fetch prefix from NLRI packet. */
3793 memcpy (&p.u.prefix, pnt, psize);
3794
3795 /* Check address. */
a82478b9 3796 if (afi == AFI_IP && safi == SAFI_UNICAST)
718e3744 3797 {
3798 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3799 {
f5ba3874 3800 /*
3801 * From draft-ietf-idr-bgp4-22, Section 6.3:
3802 * If a BGP router receives an UPDATE message with a
3803 * semantically incorrect NLRI field, in which a prefix is
3804 * semantically incorrect (eg. an unexpected multicast IP
3805 * address), it should ignore the prefix.
3806 */
16286195
DS
3807 zlog_err ("IPv4 unicast NLRI is multicast address %s",
3808 inet_ntoa (p.u.prefix4));
f5ba3874 3809
718e3744 3810 return -1;
3811 }
3812 }
3813
3814#ifdef HAVE_IPV6
3815 /* Check address. */
a82478b9 3816 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
718e3744 3817 {
3818 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3819 {
3820 char buf[BUFSIZ];
3821
16286195
DS
3822 zlog_warn ("IPv6 link-local NLRI received %s ignore this NLRI",
3823 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
718e3744 3824
3825 continue;
3826 }
3827 }
3828#endif /* HAVE_IPV6 */
3829
3830 /* Normal process. */
3831 if (attr)
a82478b9 3832 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
718e3744 3833 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3834 else
a82478b9 3835 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
718e3744 3836 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3837
3838 /* Address family configuration mismatch or maximum-prefix count
3839 overflow. */
3840 if (ret < 0)
3841 return -1;
3842 }
3843
3844 /* Packet length consistency check. */
3845 if (pnt != lim)
3846 return -1;
3847
3848 return 0;
3849}
3850
3851/* NLRI encode syntax check routine. */
3852int
a82478b9 3853bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi, u_char *pnt,
d889623f 3854 bgp_size_t length, int *numpfx)
718e3744 3855{
3856 u_char *end;
3857 u_char prefixlen;
3858 int psize;
a82478b9 3859 u_char addpath_encoded;
718e3744 3860
d889623f 3861 *numpfx = 0;
718e3744 3862 end = pnt + length;
3863
a82478b9
DS
3864 addpath_encoded = (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3865 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3866
718e3744 3867 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3868 syntactic validity. If the field is syntactically incorrect,
3869 then the Error Subcode is set to Invalid Network Field. */
3870
3871 while (pnt < end)
3872 {
cd808e74 3873
a82478b9
DS
3874 /* If the NLRI is encoded using addpath then the first 4 bytes are
3875 * the addpath ID. */
3876 if (addpath_encoded)
cd808e74
DS
3877 {
3878 if (pnt + BGP_ADDPATH_ID_LEN > end)
3879 {
3880 zlog_err ("%s [Error] Update packet error"
3881 " (prefix data addpath overflow)",
3882 peer->host);
3883 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3884 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3885 return -1;
3886 }
3887 pnt += BGP_ADDPATH_ID_LEN;
3888 }
a82478b9 3889
718e3744 3890 prefixlen = *pnt++;
3891
3892 /* Prefix length check. */
3893 if ((afi == AFI_IP && prefixlen > 32)
3894 || (afi == AFI_IP6 && prefixlen > 128))
3895 {
16286195 3896 zlog_err ("%s [Error] Update packet error (wrong prefix length %d)",
718e3744 3897 peer->host, prefixlen);
3898 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3899 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3900 return -1;
3901 }
3902
3903 /* Packet size overflow check. */
3904 psize = PSIZE (prefixlen);
3905
3906 if (pnt + psize > end)
3907 {
16286195 3908 zlog_err ("%s [Error] Update packet error"
718e3744 3909 " (prefix data overflow prefix size is %d)",
3910 peer->host, psize);
3911 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3912 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3913 return -1;
3914 }
3915
3916 pnt += psize;
d889623f 3917 (*numpfx)++;
718e3744 3918 }
3919
3920 /* Packet length consistency check. */
3921 if (pnt != end)
3922 {
16286195 3923 zlog_err ("%s [Error] Update packet error"
718e3744 3924 " (prefix length mismatch with total length)",
3925 peer->host);
3926 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3927 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3928 return -1;
3929 }
3930 return 0;
3931}
6b0655a2 3932
94f2b392 3933static struct bgp_static *
66e5cd87 3934bgp_static_new (void)
718e3744 3935{
393deb9b 3936 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
718e3744 3937}
3938
94f2b392 3939static void
718e3744 3940bgp_static_free (struct bgp_static *bgp_static)
3941{
3942 if (bgp_static->rmap.name)
6e919709 3943 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
718e3744 3944 XFREE (MTYPE_BGP_STATIC, bgp_static);
3945}
3946
94f2b392 3947static void
fee0f4c6 3948bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3949 struct prefix *p, afi_t afi, safi_t safi)
3950{
3951 struct bgp_node *rn;
3952 struct bgp_info *ri;
3953
3954 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3955
3956 /* Check selected route and self inserted route. */
3957 for (ri = rn->info; ri; ri = ri->next)
3958 if (ri->peer == bgp->peer_self
3959 && ri->type == ZEBRA_ROUTE_BGP
3960 && ri->sub_type == BGP_ROUTE_STATIC)
3961 break;
3962
3963 /* Withdraw static BGP route from routing table. */
3964 if (ri)
3965 {
fee0f4c6 3966 bgp_info_delete (rn, ri);
1a392d46 3967 bgp_process (bgp, rn, afi, safi);
fee0f4c6 3968 }
3969
3970 /* Unlock bgp_node_lookup. */
3971 bgp_unlock_node (rn);
3972}
3973
94f2b392 3974static void
fee0f4c6 3975bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
fb982c25
PJ
3976 struct bgp_static *bgp_static,
3977 afi_t afi, safi_t safi)
fee0f4c6 3978{
3979 struct bgp_node *rn;
3980 struct bgp_info *ri;
3981 struct bgp_info *new;
3982 struct bgp_info info;
fee0f4c6 3983 struct attr *attr_new;
e16a4133 3984 struct attr attr;
558d1fec
JBD
3985 struct attr new_attr;
3986 struct attr_extra new_extra;
fee0f4c6 3987 struct bgp *bgp;
3988 int ret;
3989 char buf[SU_ADDRSTRLEN];
3990
3991 bgp = rsclient->bgp;
3992
06e110f9
PJ
3993 assert (bgp_static);
3994 if (!bgp_static)
3995 return;
3996
fee0f4c6 3997 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3998
3999 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
06e110f9
PJ
4000
4001 attr.nexthop = bgp_static->igpnexthop;
4002 attr.med = bgp_static->igpmetric;
4003 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
41367172 4004
41367172
PJ
4005 if (bgp_static->atomic)
4006 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
4007
fee0f4c6 4008 /* Apply network route-map for export to this rsclient. */
4009 if (bgp_static->rmap.name)
4010 {
fb982c25 4011 struct attr attr_tmp = attr;
fee0f4c6 4012 info.peer = rsclient;
fb982c25
PJ
4013 info.attr = &attr_tmp;
4014
fee0f4c6 4015 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
4016 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
4017
4018 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
4019
4020 rsclient->rmap_type = 0;
4021
4022 if (ret == RMAP_DENYMATCH)
4023 {
4024 /* Free uninterned attribute. */
fb982c25 4025 bgp_attr_flush (&attr_tmp);
fee0f4c6 4026
4027 /* Unintern original. */
f6f434b2 4028 aspath_unintern (&attr.aspath);
fee0f4c6 4029 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
fb982c25
PJ
4030 bgp_attr_extra_free (&attr);
4031
fee0f4c6 4032 return;
4033 }
fb982c25 4034 attr_new = bgp_attr_intern (&attr_tmp);
fee0f4c6 4035 }
4036 else
4037 attr_new = bgp_attr_intern (&attr);
558d1fec
JBD
4038
4039 new_attr.extra = &new_extra;
7badc263 4040 bgp_attr_dup(&new_attr, attr_new);
fb982c25 4041
fee0f4c6 4042 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
4043
fb982c25
PJ
4044 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
4045 == RMAP_DENY)
4046 {
fee0f4c6 4047 /* This BGP update is filtered. Log the reason then update BGP entry. */
3f9c7369 4048 if (bgp_debug_update(rsclient, p, NULL, 1))
16286195
DS
4049 zlog_debug ("Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
4050 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
4051 p->prefixlen, rsclient->host);
fee0f4c6 4052
4053 bgp->peer_self->rmap_type = 0;
4054
f6f434b2
PJ
4055 bgp_attr_unintern (&attr_new);
4056 aspath_unintern (&attr.aspath);
fb982c25 4057 bgp_attr_extra_free (&attr);
fee0f4c6 4058
4059 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
4060
4061 return;
fb982c25 4062 }
fee0f4c6 4063
4064 bgp->peer_self->rmap_type = 0;
4065
f6f434b2 4066 bgp_attr_unintern (&attr_new);
fee0f4c6 4067 attr_new = bgp_attr_intern (&new_attr);
4068
4069 for (ri = rn->info; ri; ri = ri->next)
4070 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
4071 && ri->sub_type == BGP_ROUTE_STATIC)
4072 break;
4073
4074 if (ri)
4075 {
8d45210e 4076 if (attrhash_cmp (ri->attr, attr_new) &&
078430f6
DS
4077 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
4078 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
fee0f4c6 4079 {
4080 bgp_unlock_node (rn);
f6f434b2
PJ
4081 bgp_attr_unintern (&attr_new);
4082 aspath_unintern (&attr.aspath);
fb982c25 4083 bgp_attr_extra_free (&attr);
fee0f4c6 4084 return;
4085 }
4086 else
4087 {
4088 /* The attribute is changed. */
1a392d46 4089 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
fee0f4c6 4090
4091 /* Rewrite BGP route information. */
8d45210e
AS
4092 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
4093 bgp_info_restore(rn, ri);
f6f434b2 4094 bgp_attr_unintern (&ri->attr);
fee0f4c6 4095 ri->attr = attr_new;
65957886 4096 ri->uptime = bgp_clock ();
fee0f4c6 4097
fc9a856f
DS
4098 /* Nexthop reachability check. */
4099 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4100 {
75aead62 4101 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
fc9a856f
DS
4102 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
4103 else
4104 {
4105 if (BGP_DEBUG(nht, NHT))
4106 {
4107 char buf1[INET6_ADDRSTRLEN];
078430f6
DS
4108 inet_ntop (p->family, &p->u.prefix, buf1,
4109 INET6_ADDRSTRLEN);
4110 zlog_debug("%s(%s): Route not in table, not advertising",
4111 __FUNCTION__, buf1);
fc9a856f
DS
4112 }
4113 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
4114 }
4115 }
078430f6
DS
4116 else
4117 {
4118 /* Delete the NHT structure if any, if we're toggling between
4119 * enabling/disabling import check. We deregister the route
4120 * from NHT to avoid overloading NHT and the process interaction
4121 */
4122 bgp_unlink_nexthop(ri);
4123 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
4124 }
fee0f4c6 4125 /* Process change. */
4126 bgp_process (bgp, rn, afi, safi);
4127 bgp_unlock_node (rn);
f6f434b2 4128 aspath_unintern (&attr.aspath);
fb982c25 4129 bgp_attr_extra_free (&attr);
fee0f4c6 4130 return;
fb982c25 4131 }
fee0f4c6 4132 }
fb018d25 4133
fee0f4c6 4134 /* Make new BGP info. */
7c8ff89e 4135 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
fb018d25 4136 attr_new, rn);
fc9a856f
DS
4137 /* Nexthop reachability check. */
4138 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4139 {
75aead62 4140 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
fc9a856f
DS
4141 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
4142 else
4143 {
4144 if (BGP_DEBUG(nht, NHT))
4145 {
4146 char buf1[INET6_ADDRSTRLEN];
078430f6
DS
4147 inet_ntop(p->family, &p->u.prefix, buf1,
4148 INET6_ADDRSTRLEN);
4149 zlog_debug("%s(%s): Route not in table, not advertising", __FUNCTION__,
4150 buf1);
fc9a856f
DS
4151 }
4152 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
4153 }
4154 }
4155 else
078430f6
DS
4156 {
4157 /* Delete the NHT structure if any, if we're toggling between
4158 * enabling/disabling import check. We deregister the route
4159 * from NHT to avoid overloading NHT and the process interaction
4160 */
4161 bgp_unlink_nexthop(new);
4162 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
4163 }
fee0f4c6 4164
4165 /* Register new BGP information. */
4166 bgp_info_add (rn, new);
200df115 4167
4168 /* route_node_get lock */
4169 bgp_unlock_node (rn);
4170
fee0f4c6 4171 /* Process change. */
4172 bgp_process (bgp, rn, afi, safi);
4173
4174 /* Unintern original. */
f6f434b2 4175 aspath_unintern (&attr.aspath);
fb982c25 4176 bgp_attr_extra_free (&attr);
fee0f4c6 4177}
4178
94f2b392 4179static void
fee0f4c6 4180bgp_static_update_main (struct bgp *bgp, struct prefix *p,
fc9a856f 4181 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
718e3744 4182{
4183 struct bgp_node *rn;
4184 struct bgp_info *ri;
4185 struct bgp_info *new;
4186 struct bgp_info info;
e16a4133 4187 struct attr attr;
718e3744 4188 struct attr *attr_new;
4189 int ret;
4190
dd8103a9
PJ
4191 assert (bgp_static);
4192 if (!bgp_static)
4193 return;
4194
fee0f4c6 4195 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 4196
4197 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
dd8103a9
PJ
4198
4199 attr.nexthop = bgp_static->igpnexthop;
4200 attr.med = bgp_static->igpmetric;
4201 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
718e3744 4202
41367172
PJ
4203 if (bgp_static->atomic)
4204 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
4205
718e3744 4206 /* Apply route-map. */
4207 if (bgp_static->rmap.name)
4208 {
fb982c25 4209 struct attr attr_tmp = attr;
718e3744 4210 info.peer = bgp->peer_self;
286e1e71 4211 info.attr = &attr_tmp;
718e3744 4212
fee0f4c6 4213 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
4214
718e3744 4215 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
286e1e71 4216
fee0f4c6 4217 bgp->peer_self->rmap_type = 0;
4218
718e3744 4219 if (ret == RMAP_DENYMATCH)
4220 {
4221 /* Free uninterned attribute. */
286e1e71 4222 bgp_attr_flush (&attr_tmp);
718e3744 4223
4224 /* Unintern original. */
f6f434b2 4225 aspath_unintern (&attr.aspath);
fb982c25 4226 bgp_attr_extra_free (&attr);
718e3744 4227 bgp_static_withdraw (bgp, p, afi, safi);
4228 return;
4229 }
286e1e71 4230 attr_new = bgp_attr_intern (&attr_tmp);
718e3744 4231 }
286e1e71 4232 else
4233 attr_new = bgp_attr_intern (&attr);
718e3744 4234
4235 for (ri = rn->info; ri; ri = ri->next)
4236 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
4237 && ri->sub_type == BGP_ROUTE_STATIC)
4238 break;
4239
4240 if (ri)
4241 {
8d45210e 4242 if (attrhash_cmp (ri->attr, attr_new) &&
078430f6
DS
4243 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
4244 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
718e3744 4245 {
4246 bgp_unlock_node (rn);
f6f434b2
PJ
4247 bgp_attr_unintern (&attr_new);
4248 aspath_unintern (&attr.aspath);
fb982c25 4249 bgp_attr_extra_free (&attr);
718e3744 4250 return;
4251 }
4252 else
4253 {
4254 /* The attribute is changed. */
1a392d46 4255 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4256
4257 /* Rewrite BGP route information. */
8d45210e
AS
4258 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
4259 bgp_info_restore(rn, ri);
4260 else
4261 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
f6f434b2 4262 bgp_attr_unintern (&ri->attr);
718e3744 4263 ri->attr = attr_new;
65957886 4264 ri->uptime = bgp_clock ();
718e3744 4265
fc9a856f
DS
4266 /* Nexthop reachability check. */
4267 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4268 {
75aead62 4269 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
fc9a856f
DS
4270 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
4271 else
4272 {
4273 if (BGP_DEBUG(nht, NHT))
4274 {
4275 char buf1[INET6_ADDRSTRLEN];
078430f6
DS
4276 inet_ntop(p->family, &p->u.prefix, buf1,
4277 INET6_ADDRSTRLEN);
4278 zlog_debug("%s(%s): Route not in table, not advertising",
4279 __FUNCTION__, buf1);
fc9a856f
DS
4280 }
4281 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
4282 }
4283 }
078430f6
DS
4284 else
4285 {
4286 /* Delete the NHT structure if any, if we're toggling between
4287 * enabling/disabling import check. We deregister the route
4288 * from NHT to avoid overloading NHT and the process interaction
4289 */
4290 bgp_unlink_nexthop(ri);
4291 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
4292 }
718e3744 4293 /* Process change. */
4294 bgp_aggregate_increment (bgp, p, ri, afi, safi);
4295 bgp_process (bgp, rn, afi, safi);
4296 bgp_unlock_node (rn);
f6f434b2 4297 aspath_unintern (&attr.aspath);
fb982c25 4298 bgp_attr_extra_free (&attr);
718e3744 4299 return;
4300 }
4301 }
4302
4303 /* Make new BGP info. */
7c8ff89e 4304 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
fb018d25 4305 rn);
fc9a856f
DS
4306 /* Nexthop reachability check. */
4307 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4308 {
75aead62 4309 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
fc9a856f
DS
4310 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
4311 else
4312 {
4313 if (BGP_DEBUG(nht, NHT))
4314 {
4315 char buf1[INET6_ADDRSTRLEN];
078430f6 4316 inet_ntop(p->family, &p->u.prefix, buf1,
fc9a856f 4317 INET6_ADDRSTRLEN);
078430f6
DS
4318 zlog_debug("%s(%s): Route not in table, not advertising",
4319 __FUNCTION__, buf1);
fc9a856f
DS
4320 }
4321 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
4322 }
4323 }
4324 else
078430f6
DS
4325 {
4326 /* Delete the NHT structure if any, if we're toggling between
4327 * enabling/disabling import check. We deregister the route
4328 * from NHT to avoid overloading NHT and the process interaction
4329 */
4330 bgp_unlink_nexthop(new);
4331
4332 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
4333 }
718e3744 4334
4335 /* Aggregate address increment. */
4336 bgp_aggregate_increment (bgp, p, new, afi, safi);
4337
4338 /* Register new BGP information. */
4339 bgp_info_add (rn, new);
200df115 4340
4341 /* route_node_get lock */
4342 bgp_unlock_node (rn);
4343
718e3744 4344 /* Process change. */
4345 bgp_process (bgp, rn, afi, safi);
4346
4347 /* Unintern original. */
f6f434b2 4348 aspath_unintern (&attr.aspath);
fb982c25 4349 bgp_attr_extra_free (&attr);
718e3744 4350}
4351
fee0f4c6 4352void
4353bgp_static_update (struct bgp *bgp, struct prefix *p,
4354 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
4355{
4356 struct peer *rsclient;
1eb8ef25 4357 struct listnode *node, *nnode;
fee0f4c6 4358
4359 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
4360
1eb8ef25 4361 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 4362 {
da5b30f6
PJ
4363 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
4364 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
fee0f4c6 4365 }
4366}
4367
94f2b392 4368static void
4c9641ba
ML
4369bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
4370 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 4371{
4372 struct bgp_node *rn;
4373 struct bgp_info *new;
fb982c25 4374
fee0f4c6 4375 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 4376
4377 /* Make new BGP info. */
7c8ff89e 4378 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
fb018d25
DS
4379 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
4380
718e3744 4381 SET_FLAG (new->flags, BGP_INFO_VALID);
fb982c25
PJ
4382 new->extra = bgp_info_extra_new();
4383 memcpy (new->extra->tag, tag, 3);
718e3744 4384
4385 /* Aggregate address increment. */
200df115 4386 bgp_aggregate_increment (bgp, p, new, afi, safi);
718e3744 4387
4388 /* Register new BGP information. */
200df115 4389 bgp_info_add (rn, new);
718e3744 4390
200df115 4391 /* route_node_get lock */
4392 bgp_unlock_node (rn);
4393
718e3744 4394 /* Process change. */
4395 bgp_process (bgp, rn, afi, safi);
4396}
4397
4398void
4399bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
4400 safi_t safi)
4401{
4402 struct bgp_node *rn;
4403 struct bgp_info *ri;
4404
fee0f4c6 4405 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 4406
4407 /* Check selected route and self inserted route. */
4408 for (ri = rn->info; ri; ri = ri->next)
4409 if (ri->peer == bgp->peer_self
4410 && ri->type == ZEBRA_ROUTE_BGP
4411 && ri->sub_type == BGP_ROUTE_STATIC)
4412 break;
4413
4414 /* Withdraw static BGP route from routing table. */
4415 if (ri)
4416 {
4417 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
fc9a856f 4418 bgp_unlink_nexthop(ri);
718e3744 4419 bgp_info_delete (rn, ri);
1a392d46 4420 bgp_process (bgp, rn, afi, safi);
718e3744 4421 }
4422
4423 /* Unlock bgp_node_lookup. */
4424 bgp_unlock_node (rn);
4425}
4426
fee0f4c6 4427void
4428bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
4429{
4430 struct bgp_static *bgp_static;
4431 struct bgp *bgp;
4432 struct bgp_node *rn;
4433 struct prefix *p;
4434
4435 bgp = rsclient->bgp;
4436
4437 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4438 if ((bgp_static = rn->info) != NULL)
4439 {
4440 p = &rn->p;
4441
4442 bgp_static_update_rsclient (rsclient, p, bgp_static,
4443 afi, safi);
4444 }
4445}
4446
94f2b392 4447static void
4c9641ba
ML
4448bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
4449 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 4450{
4451 struct bgp_node *rn;
4452 struct bgp_info *ri;
4453
fee0f4c6 4454 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 4455
4456 /* Check selected route and self inserted route. */
4457 for (ri = rn->info; ri; ri = ri->next)
4458 if (ri->peer == bgp->peer_self
4459 && ri->type == ZEBRA_ROUTE_BGP
4460 && ri->sub_type == BGP_ROUTE_STATIC)
4461 break;
4462
4463 /* Withdraw static BGP route from routing table. */
4464 if (ri)
4465 {
4466 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
718e3744 4467 bgp_info_delete (rn, ri);
1a392d46 4468 bgp_process (bgp, rn, afi, safi);
718e3744 4469 }
4470
4471 /* Unlock bgp_node_lookup. */
4472 bgp_unlock_node (rn);
4473}
4474
4475/* Configure static BGP network. When user don't run zebra, static
4476 route should be installed as valid. */
94f2b392 4477static int
fd79ac91 4478bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
c8f3fe30 4479 afi_t afi, safi_t safi, const char *rmap, int backdoor)
718e3744 4480{
4481 int ret;
4482 struct prefix p;
4483 struct bgp_static *bgp_static;
4484 struct bgp_node *rn;
41367172 4485 u_char need_update = 0;
718e3744 4486
4487 /* Convert IP prefix string to struct prefix. */
4488 ret = str2prefix (ip_str, &p);
4489 if (! ret)
4490 {
4491 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4492 return CMD_WARNING;
4493 }
4494#ifdef HAVE_IPV6
4495 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4496 {
4497 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4498 VTY_NEWLINE);
4499 return CMD_WARNING;
4500 }
4501#endif /* HAVE_IPV6 */
4502
4503 apply_mask (&p);
4504
4505 /* Set BGP static route configuration. */
4506 rn = bgp_node_get (bgp->route[afi][safi], &p);
4507
4508 if (rn->info)
4509 {
4510 /* Configuration change. */
4511 bgp_static = rn->info;
4512
4513 /* Check previous routes are installed into BGP. */
c8f3fe30
PJ
4514 if (bgp_static->valid && bgp_static->backdoor != backdoor)
4515 need_update = 1;
41367172 4516
718e3744 4517 bgp_static->backdoor = backdoor;
41367172 4518
718e3744 4519 if (rmap)
4520 {
4521 if (bgp_static->rmap.name)
6e919709
DS
4522 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4523 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
718e3744 4524 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4525 }
4526 else
4527 {
4528 if (bgp_static->rmap.name)
6e919709 4529 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
718e3744 4530 bgp_static->rmap.name = NULL;
4531 bgp_static->rmap.map = NULL;
4532 bgp_static->valid = 0;
4533 }
4534 bgp_unlock_node (rn);
4535 }
4536 else
4537 {
4538 /* New configuration. */
4539 bgp_static = bgp_static_new ();
4540 bgp_static->backdoor = backdoor;
4541 bgp_static->valid = 0;
4542 bgp_static->igpmetric = 0;
4543 bgp_static->igpnexthop.s_addr = 0;
41367172 4544
718e3744 4545 if (rmap)
4546 {
4547 if (bgp_static->rmap.name)
6e919709
DS
4548 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4549 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
718e3744 4550 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4551 }
4552 rn->info = bgp_static;
4553 }
4554
fc9a856f
DS
4555 bgp_static->valid = 1;
4556 if (need_update)
4557 bgp_static_withdraw (bgp, &p, afi, safi);
718e3744 4558
fc9a856f
DS
4559 if (! bgp_static->backdoor)
4560 bgp_static_update (bgp, &p, bgp_static, afi, safi);
718e3744 4561
4562 return CMD_SUCCESS;
4563}
4564
4565/* Configure static BGP network. */
94f2b392 4566static int
fd79ac91 4567bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4c9641ba 4568 afi_t afi, safi_t safi)
718e3744 4569{
4570 int ret;
4571 struct prefix p;
4572 struct bgp_static *bgp_static;
4573 struct bgp_node *rn;
4574
4575 /* Convert IP prefix string to struct prefix. */
4576 ret = str2prefix (ip_str, &p);
4577 if (! ret)
4578 {
4579 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4580 return CMD_WARNING;
4581 }
4582#ifdef HAVE_IPV6
4583 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4584 {
4585 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4586 VTY_NEWLINE);
4587 return CMD_WARNING;
4588 }
4589#endif /* HAVE_IPV6 */
4590
4591 apply_mask (&p);
4592
4593 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4594 if (! rn)
4595 {
4596 vty_out (vty, "%% Can't find specified static route configuration.%s",
4597 VTY_NEWLINE);
4598 return CMD_WARNING;
4599 }
4600
4601 bgp_static = rn->info;
41367172 4602
718e3744 4603 /* Update BGP RIB. */
4604 if (! bgp_static->backdoor)
4605 bgp_static_withdraw (bgp, &p, afi, safi);
4606
4607 /* Clear configuration. */
4608 bgp_static_free (bgp_static);
4609 rn->info = NULL;
4610 bgp_unlock_node (rn);
4611 bgp_unlock_node (rn);
4612
4613 return CMD_SUCCESS;
4614}
4615
4616/* Called from bgp_delete(). Delete all static routes from the BGP
4617 instance. */
4618void
4619bgp_static_delete (struct bgp *bgp)
4620{
4621 afi_t afi;
4622 safi_t safi;
4623 struct bgp_node *rn;
4624 struct bgp_node *rm;
4625 struct bgp_table *table;
4626 struct bgp_static *bgp_static;
4627
4628 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4629 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4630 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4631 if (rn->info != NULL)
4632 {
4633 if (safi == SAFI_MPLS_VPN)
4634 {
4635 table = rn->info;
4636
4637 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4638 {
4639 bgp_static = rn->info;
4640 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
4641 AFI_IP, SAFI_MPLS_VPN,
4642 (struct prefix_rd *)&rn->p,
4643 bgp_static->tag);
4644 bgp_static_free (bgp_static);
4645 rn->info = NULL;
4646 bgp_unlock_node (rn);
4647 }
4648 }
4649 else
4650 {
4651 bgp_static = rn->info;
4652 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4653 bgp_static_free (bgp_static);
4654 rn->info = NULL;
4655 bgp_unlock_node (rn);
4656 }
4657 }
4658}
4659
078430f6
DS
4660void
4661bgp_static_redo_import_check (struct bgp *bgp)
4662{
4663 afi_t afi;
4664 safi_t safi;
4665 struct bgp_node *rn;
078430f6
DS
4666 struct bgp_static *bgp_static;
4667
4668 /* Use this flag to force reprocessing of the route */
4669 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4670 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4671 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4672 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4673 if (rn->info != NULL)
4674 {
4675 bgp_static = rn->info;
4676 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
4677 }
4678 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4679}
4680
718e3744 4681int
fd79ac91 4682bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
4683 const char *tag_str)
718e3744 4684{
4685 int ret;
4686 struct prefix p;
4687 struct prefix_rd prd;
4688 struct bgp *bgp;
4689 struct bgp_node *prn;
4690 struct bgp_node *rn;
4691 struct bgp_table *table;
4692 struct bgp_static *bgp_static;
4693 u_char tag[3];
4694
4695 bgp = vty->index;
4696
4697 ret = str2prefix (ip_str, &p);
4698 if (! ret)
4699 {
4700 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4701 return CMD_WARNING;
4702 }
4703 apply_mask (&p);
4704
4705 ret = str2prefix_rd (rd_str, &prd);
4706 if (! ret)
4707 {
4708 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4709 return CMD_WARNING;
4710 }
4711
4712 ret = str2tag (tag_str, tag);
4713 if (! ret)
4714 {
4715 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4716 return CMD_WARNING;
4717 }
4718
4719 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4720 (struct prefix *)&prd);
4721 if (prn->info == NULL)
64e580a7 4722 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
718e3744 4723 else
4724 bgp_unlock_node (prn);
4725 table = prn->info;
4726
4727 rn = bgp_node_get (table, &p);
4728
4729 if (rn->info)
4730 {
4731 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4732 bgp_unlock_node (rn);
4733 }
4734 else
4735 {
4736 /* New configuration. */
4737 bgp_static = bgp_static_new ();
4738 bgp_static->valid = 1;
4739 memcpy (bgp_static->tag, tag, 3);
4740 rn->info = bgp_static;
4741
4742 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4743 }
4744
4745 return CMD_SUCCESS;
4746}
4747
4748/* Configure static BGP network. */
4749int
fd79ac91 4750bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
4751 const char *rd_str, const char *tag_str)
718e3744 4752{
4753 int ret;
4754 struct bgp *bgp;
4755 struct prefix p;
4756 struct prefix_rd prd;
4757 struct bgp_node *prn;
4758 struct bgp_node *rn;
4759 struct bgp_table *table;
4760 struct bgp_static *bgp_static;
4761 u_char tag[3];
4762
4763 bgp = vty->index;
4764
4765 /* Convert IP prefix string to struct prefix. */
4766 ret = str2prefix (ip_str, &p);
4767 if (! ret)
4768 {
4769 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4770 return CMD_WARNING;
4771 }
4772 apply_mask (&p);
4773
4774 ret = str2prefix_rd (rd_str, &prd);
4775 if (! ret)
4776 {
4777 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4778 return CMD_WARNING;
4779 }
4780
4781 ret = str2tag (tag_str, tag);
4782 if (! ret)
4783 {
4784 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4785 return CMD_WARNING;
4786 }
4787
4788 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4789 (struct prefix *)&prd);
4790 if (prn->info == NULL)
64e580a7 4791 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
718e3744 4792 else
4793 bgp_unlock_node (prn);
4794 table = prn->info;
4795
4796 rn = bgp_node_lookup (table, &p);
4797
4798 if (rn)
4799 {
4800 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4801
4802 bgp_static = rn->info;
4803 bgp_static_free (bgp_static);
4804 rn->info = NULL;
4805 bgp_unlock_node (rn);
4806 bgp_unlock_node (rn);
4807 }
4808 else
4809 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4810
4811 return CMD_SUCCESS;
4812}
6b0655a2 4813
73ac8160
DS
4814static int
4815bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4816 const char *rmap_name)
4817{
4818 struct bgp_rmap *rmap;
4819
4820 rmap = &bgp->table_map[afi][safi];
4821 if (rmap_name)
4822 {
4823 if (rmap->name)
6e919709
DS
4824 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4825 rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name);
73ac8160
DS
4826 rmap->map = route_map_lookup_by_name (rmap_name);
4827 }
4828 else
4829 {
4830 if (rmap->name)
6e919709 4831 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
73ac8160
DS
4832 rmap->name = NULL;
4833 rmap->map = NULL;
4834 }
4835
4836 bgp_zebra_announce_table(bgp, afi, safi);
4837
4838 return CMD_SUCCESS;
4839}
4840
4841static int
4842bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4843 const char *rmap_name)
4844{
4845 struct bgp_rmap *rmap;
4846
4847 rmap = &bgp->table_map[afi][safi];
4848 if (rmap->name)
6e919709 4849 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
73ac8160
DS
4850 rmap->name = NULL;
4851 rmap->map = NULL;
4852
4853 bgp_zebra_announce_table(bgp, afi, safi);
4854
4855 return CMD_SUCCESS;
4856}
4857
4858int
4859bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4860 safi_t safi, int *write)
4861{
4862 if (bgp->table_map[afi][safi].name)
4863 {
4864 bgp_config_write_family_header (vty, afi, safi, write);
0b960b4d 4865 vty_out (vty, " table-map %s%s",
73ac8160
DS
4866 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4867 }
4868
4869 return 0;
4870}
4871
4872
4873DEFUN (bgp_table_map,
4874 bgp_table_map_cmd,
4875 "table-map WORD",
4876 "BGP table to RIB route download filter\n"
4877 "Name of the route map\n")
4878{
4879 return bgp_table_map_set (vty, vty->index,
4880 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4881}
4882DEFUN (no_bgp_table_map,
4883 no_bgp_table_map_cmd,
4884 "no table-map WORD",
4885 "BGP table to RIB route download filter\n"
4886 "Name of the route map\n")
4887{
4888 return bgp_table_map_unset (vty, vty->index,
4889 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4890}
4891
718e3744 4892DEFUN (bgp_network,
4893 bgp_network_cmd,
4894 "network A.B.C.D/M",
4895 "Specify a network to announce via BGP\n"
4896 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4897{
4898 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 4899 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4900}
4901
4902DEFUN (bgp_network_route_map,
4903 bgp_network_route_map_cmd,
4904 "network A.B.C.D/M route-map WORD",
4905 "Specify a network to announce via BGP\n"
4906 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4907 "Route-map to modify the attributes\n"
4908 "Name of the route map\n")
4909{
4910 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 4911 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 4912}
4913
4914DEFUN (bgp_network_backdoor,
4915 bgp_network_backdoor_cmd,
4916 "network A.B.C.D/M backdoor",
4917 "Specify a network to announce via BGP\n"
4918 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4919 "Specify a BGP backdoor route\n")
4920{
41367172 4921 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
c8f3fe30 4922 NULL, 1);
718e3744 4923}
4924
4925DEFUN (bgp_network_mask,
4926 bgp_network_mask_cmd,
4927 "network A.B.C.D mask A.B.C.D",
4928 "Specify a network to announce via BGP\n"
4929 "Network number\n"
4930 "Network mask\n"
4931 "Network mask\n")
4932{
4933 int ret;
4934 char prefix_str[BUFSIZ];
41367172 4935
718e3744 4936 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4937 if (! ret)
4938 {
4939 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4940 return CMD_WARNING;
4941 }
4942
4943 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4944 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4945}
4946
4947DEFUN (bgp_network_mask_route_map,
4948 bgp_network_mask_route_map_cmd,
4949 "network A.B.C.D mask A.B.C.D route-map WORD",
4950 "Specify a network to announce via BGP\n"
4951 "Network number\n"
4952 "Network mask\n"
4953 "Network mask\n"
4954 "Route-map to modify the attributes\n"
4955 "Name of the route map\n")
4956{
4957 int ret;
4958 char prefix_str[BUFSIZ];
41367172 4959
718e3744 4960 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4961 if (! ret)
4962 {
4963 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4964 return CMD_WARNING;
4965 }
4966
4967 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4968 AFI_IP, bgp_node_safi (vty), argv[2], 0);
718e3744 4969}
4970
4971DEFUN (bgp_network_mask_backdoor,
4972 bgp_network_mask_backdoor_cmd,
4973 "network A.B.C.D mask A.B.C.D backdoor",
4974 "Specify a network to announce via BGP\n"
4975 "Network number\n"
4976 "Network mask\n"
4977 "Network mask\n"
4978 "Specify a BGP backdoor route\n")
4979{
4980 int ret;
4981 char prefix_str[BUFSIZ];
41367172 4982
718e3744 4983 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4984 if (! ret)
4985 {
4986 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4987 return CMD_WARNING;
4988 }
4989
41367172 4990 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 4991 NULL, 1);
718e3744 4992}
4993
4994DEFUN (bgp_network_mask_natural,
4995 bgp_network_mask_natural_cmd,
4996 "network A.B.C.D",
4997 "Specify a network to announce via BGP\n"
4998 "Network number\n")
4999{
5000 int ret;
5001 char prefix_str[BUFSIZ];
5002
5003 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
5004 if (! ret)
5005 {
5006 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5007 return CMD_WARNING;
5008 }
5009
5010 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 5011 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 5012}
5013
5014DEFUN (bgp_network_mask_natural_route_map,
5015 bgp_network_mask_natural_route_map_cmd,
5016 "network A.B.C.D route-map WORD",
5017 "Specify a network to announce via BGP\n"
5018 "Network number\n"
5019 "Route-map to modify the attributes\n"
5020 "Name of the route map\n")
5021{
5022 int ret;
5023 char prefix_str[BUFSIZ];
5024
5025 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
5026 if (! ret)
5027 {
5028 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5029 return CMD_WARNING;
5030 }
5031
5032 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 5033 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 5034}
5035
5036DEFUN (bgp_network_mask_natural_backdoor,
5037 bgp_network_mask_natural_backdoor_cmd,
5038 "network A.B.C.D backdoor",
5039 "Specify a network to announce via BGP\n"
5040 "Network number\n"
5041 "Specify a BGP backdoor route\n")
5042{
5043 int ret;
5044 char prefix_str[BUFSIZ];
5045
5046 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
5047 if (! ret)
5048 {
5049 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5050 return CMD_WARNING;
5051 }
5052
41367172 5053 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 5054 NULL, 1);
718e3744 5055}
5056
5057DEFUN (no_bgp_network,
5058 no_bgp_network_cmd,
5059 "no network A.B.C.D/M",
5060 NO_STR
5061 "Specify a network to announce via BGP\n"
5062 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5063{
5064 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
5065 bgp_node_safi (vty));
5066}
5067
5068ALIAS (no_bgp_network,
5069 no_bgp_network_route_map_cmd,
5070 "no network A.B.C.D/M route-map WORD",
5071 NO_STR
5072 "Specify a network to announce via BGP\n"
5073 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5074 "Route-map to modify the attributes\n"
5075 "Name of the route map\n")
5076
5077ALIAS (no_bgp_network,
5078 no_bgp_network_backdoor_cmd,
5079 "no network A.B.C.D/M backdoor",
5080 NO_STR
5081 "Specify a network to announce via BGP\n"
5082 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5083 "Specify a BGP backdoor route\n")
5084
5085DEFUN (no_bgp_network_mask,
5086 no_bgp_network_mask_cmd,
5087 "no network A.B.C.D mask A.B.C.D",
5088 NO_STR
5089 "Specify a network to announce via BGP\n"
5090 "Network number\n"
5091 "Network mask\n"
5092 "Network mask\n")
5093{
5094 int ret;
5095 char prefix_str[BUFSIZ];
5096
5097 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5098 if (! ret)
5099 {
5100 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5101 return CMD_WARNING;
5102 }
5103
5104 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
5105 bgp_node_safi (vty));
5106}
5107
5108ALIAS (no_bgp_network_mask,
5109 no_bgp_network_mask_route_map_cmd,
5110 "no network A.B.C.D mask A.B.C.D route-map WORD",
5111 NO_STR
5112 "Specify a network to announce via BGP\n"
5113 "Network number\n"
5114 "Network mask\n"
5115 "Network mask\n"
5116 "Route-map to modify the attributes\n"
5117 "Name of the route map\n")
5118
5119ALIAS (no_bgp_network_mask,
5120 no_bgp_network_mask_backdoor_cmd,
5121 "no network A.B.C.D mask A.B.C.D backdoor",
5122 NO_STR
5123 "Specify a network to announce via BGP\n"
5124 "Network number\n"
5125 "Network mask\n"
5126 "Network mask\n"
5127 "Specify a BGP backdoor route\n")
5128
5129DEFUN (no_bgp_network_mask_natural,
5130 no_bgp_network_mask_natural_cmd,
5131 "no network A.B.C.D",
5132 NO_STR
5133 "Specify a network to announce via BGP\n"
5134 "Network number\n")
5135{
5136 int ret;
5137 char prefix_str[BUFSIZ];
5138
5139 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
5140 if (! ret)
5141 {
5142 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5143 return CMD_WARNING;
5144 }
5145
5146 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
5147 bgp_node_safi (vty));
5148}
5149
5150ALIAS (no_bgp_network_mask_natural,
5151 no_bgp_network_mask_natural_route_map_cmd,
5152 "no network A.B.C.D route-map WORD",
5153 NO_STR
5154 "Specify a network to announce via BGP\n"
5155 "Network number\n"
5156 "Route-map to modify the attributes\n"
5157 "Name of the route map\n")
5158
5159ALIAS (no_bgp_network_mask_natural,
5160 no_bgp_network_mask_natural_backdoor_cmd,
5161 "no network A.B.C.D backdoor",
5162 NO_STR
5163 "Specify a network to announce via BGP\n"
5164 "Network number\n"
5165 "Specify a BGP backdoor route\n")
5166
5167#ifdef HAVE_IPV6
5168DEFUN (ipv6_bgp_network,
5169 ipv6_bgp_network_cmd,
5170 "network X:X::X:X/M",
5171 "Specify a network to announce via BGP\n"
5172 "IPv6 prefix <network>/<length>\n")
5173{
73bfe0bd 5174 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
c8f3fe30 5175 NULL, 0);
718e3744 5176}
5177
5178DEFUN (ipv6_bgp_network_route_map,
5179 ipv6_bgp_network_route_map_cmd,
5180 "network X:X::X:X/M route-map WORD",
5181 "Specify a network to announce via BGP\n"
5182 "IPv6 prefix <network>/<length>\n"
5183 "Route-map to modify the attributes\n"
5184 "Name of the route map\n")
5185{
5186 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
c8f3fe30 5187 bgp_node_safi (vty), argv[1], 0);
718e3744 5188}
5189
5190DEFUN (no_ipv6_bgp_network,
5191 no_ipv6_bgp_network_cmd,
5192 "no network X:X::X:X/M",
5193 NO_STR
5194 "Specify a network to announce via BGP\n"
5195 "IPv6 prefix <network>/<length>\n")
5196{
73bfe0bd 5197 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
718e3744 5198}
5199
5200ALIAS (no_ipv6_bgp_network,
5201 no_ipv6_bgp_network_route_map_cmd,
5202 "no network X:X::X:X/M route-map WORD",
5203 NO_STR
5204 "Specify a network to announce via BGP\n"
5205 "IPv6 prefix <network>/<length>\n"
5206 "Route-map to modify the attributes\n"
5207 "Name of the route map\n")
5208
5209ALIAS (ipv6_bgp_network,
5210 old_ipv6_bgp_network_cmd,
5211 "ipv6 bgp network X:X::X:X/M",
5212 IPV6_STR
5213 BGP_STR
5214 "Specify a network to announce via BGP\n"
5215 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5216
5217ALIAS (no_ipv6_bgp_network,
5218 old_no_ipv6_bgp_network_cmd,
5219 "no ipv6 bgp network X:X::X:X/M",
5220 NO_STR
5221 IPV6_STR
5222 BGP_STR
5223 "Specify a network to announce via BGP\n"
5224 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5225#endif /* HAVE_IPV6 */
c8f3fe30
PJ
5226
5227/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
5228ALIAS_DEPRECATED (bgp_network,
5229 bgp_network_ttl_cmd,
5230 "network A.B.C.D/M pathlimit <0-255>",
5231 "Specify a network to announce via BGP\n"
5232 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5233 "AS-Path hopcount limit attribute\n"
5234 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5235ALIAS_DEPRECATED (bgp_network_backdoor,
5236 bgp_network_backdoor_ttl_cmd,
5237 "network A.B.C.D/M backdoor pathlimit <0-255>",
5238 "Specify a network to announce via BGP\n"
5239 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5240 "Specify a BGP backdoor route\n"
5241 "AS-Path hopcount limit attribute\n"
5242 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5243ALIAS_DEPRECATED (bgp_network_mask,
5244 bgp_network_mask_ttl_cmd,
5245 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
5246 "Specify a network to announce via BGP\n"
5247 "Network number\n"
5248 "Network mask\n"
5249 "Network mask\n"
5250 "AS-Path hopcount limit attribute\n"
5251 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5252ALIAS_DEPRECATED (bgp_network_mask_backdoor,
5253 bgp_network_mask_backdoor_ttl_cmd,
5254 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
5255 "Specify a network to announce via BGP\n"
5256 "Network number\n"
5257 "Network mask\n"
5258 "Network mask\n"
5259 "Specify a BGP backdoor route\n"
5260 "AS-Path hopcount limit attribute\n"
5261 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5262ALIAS_DEPRECATED (bgp_network_mask_natural,
5263 bgp_network_mask_natural_ttl_cmd,
5264 "network A.B.C.D pathlimit <0-255>",
5265 "Specify a network to announce via BGP\n"
5266 "Network number\n"
5267 "AS-Path hopcount limit attribute\n"
5268 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5269ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
5270 bgp_network_mask_natural_backdoor_ttl_cmd,
2b00515a 5271 "network A.B.C.D backdoor pathlimit <1-255>",
c8f3fe30
PJ
5272 "Specify a network to announce via BGP\n"
5273 "Network number\n"
5274 "Specify a BGP backdoor route\n"
5275 "AS-Path hopcount limit attribute\n"
5276 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5277ALIAS_DEPRECATED (no_bgp_network,
5278 no_bgp_network_ttl_cmd,
5279 "no network A.B.C.D/M pathlimit <0-255>",
5280 NO_STR
5281 "Specify a network to announce via BGP\n"
5282 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5283 "AS-Path hopcount limit attribute\n"
5284 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5285ALIAS_DEPRECATED (no_bgp_network,
5286 no_bgp_network_backdoor_ttl_cmd,
5287 "no network A.B.C.D/M backdoor pathlimit <0-255>",
5288 NO_STR
5289 "Specify a network to announce via BGP\n"
5290 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5291 "Specify a BGP backdoor route\n"
5292 "AS-Path hopcount limit attribute\n"
5293 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5294ALIAS_DEPRECATED (no_bgp_network,
5295 no_bgp_network_mask_ttl_cmd,
5296 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
5297 NO_STR
5298 "Specify a network to announce via BGP\n"
5299 "Network number\n"
5300 "Network mask\n"
5301 "Network mask\n"
5302 "AS-Path hopcount limit attribute\n"
5303 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5304ALIAS_DEPRECATED (no_bgp_network_mask,
5305 no_bgp_network_mask_backdoor_ttl_cmd,
5306 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
5307 NO_STR
5308 "Specify a network to announce via BGP\n"
5309 "Network number\n"
5310 "Network mask\n"
5311 "Network mask\n"
5312 "Specify a BGP backdoor route\n"
5313 "AS-Path hopcount limit attribute\n"
5314 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5315ALIAS_DEPRECATED (no_bgp_network_mask_natural,
5316 no_bgp_network_mask_natural_ttl_cmd,
5317 "no network A.B.C.D pathlimit <0-255>",
5318 NO_STR
5319 "Specify a network to announce via BGP\n"
5320 "Network number\n"
5321 "AS-Path hopcount limit attribute\n"
5322 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5323ALIAS_DEPRECATED (no_bgp_network_mask_natural,
5324 no_bgp_network_mask_natural_backdoor_ttl_cmd,
5325 "no network A.B.C.D backdoor pathlimit <0-255>",
5326 NO_STR
5327 "Specify a network to announce via BGP\n"
5328 "Network number\n"
5329 "Specify a BGP backdoor route\n"
5330 "AS-Path hopcount limit attribute\n"
5331 "AS-Pathlimit TTL, in number of AS-Path hops\n")
3bde17f1 5332#ifdef HAVE_IPV6
c8f3fe30
PJ
5333ALIAS_DEPRECATED (ipv6_bgp_network,
5334 ipv6_bgp_network_ttl_cmd,
5335 "network X:X::X:X/M pathlimit <0-255>",
5336 "Specify a network to announce via BGP\n"
5337 "IPv6 prefix <network>/<length>\n"
5338 "AS-Path hopcount limit attribute\n"
5339 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5340ALIAS_DEPRECATED (no_ipv6_bgp_network,
5341 no_ipv6_bgp_network_ttl_cmd,
5342 "no network X:X::X:X/M pathlimit <0-255>",
5343 NO_STR
5344 "Specify a network to announce via BGP\n"
5345 "IPv6 prefix <network>/<length>\n"
5346 "AS-Path hopcount limit attribute\n"
5347 "AS-Pathlimit TTL, in number of AS-Path hops\n")
3bde17f1 5348#endif /* HAVE_IPV6 */
6b0655a2 5349
718e3744 5350/* Aggreagete address:
5351
5352 advertise-map Set condition to advertise attribute
5353 as-set Generate AS set path information
5354 attribute-map Set attributes of aggregate
5355 route-map Set parameters of aggregate
5356 summary-only Filter more specific routes from updates
5357 suppress-map Conditionally filter more specific routes from updates
5358 <cr>
5359 */
5360struct bgp_aggregate
5361{
5362 /* Summary-only flag. */
5363 u_char summary_only;
5364
5365 /* AS set generation. */
5366 u_char as_set;
5367
5368 /* Route-map for aggregated route. */
5369 struct route_map *map;
5370
5371 /* Suppress-count. */
5372 unsigned long count;
5373
5374 /* SAFI configuration. */
5375 safi_t safi;
5376};
5377
94f2b392 5378static struct bgp_aggregate *
66e5cd87 5379bgp_aggregate_new (void)
718e3744 5380{
393deb9b 5381 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
718e3744 5382}
5383
94f2b392 5384static void
718e3744 5385bgp_aggregate_free (struct bgp_aggregate *aggregate)
5386{
5387 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
5388}
5389
b5d58c32 5390/* Update an aggregate as routes are added/removed from the BGP table */
94f2b392 5391static void
718e3744 5392bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
5393 afi_t afi, safi_t safi, struct bgp_info *del,
5394 struct bgp_aggregate *aggregate)
5395{
5396 struct bgp_table *table;
5397 struct bgp_node *top;
5398 struct bgp_node *rn;
5399 u_char origin;
5400 struct aspath *aspath = NULL;
5401 struct aspath *asmerge = NULL;
5402 struct community *community = NULL;
5403 struct community *commerge = NULL;
ffd0c037 5404#if defined(AGGREGATE_NEXTHOP_CHECK)
718e3744 5405 struct in_addr nexthop;
5406 u_int32_t med = 0;
ffd0c037 5407#endif
718e3744 5408 struct bgp_info *ri;
5409 struct bgp_info *new;
5410 int first = 1;
5411 unsigned long match = 0;
42f7e184 5412 u_char atomic_aggregate = 0;
718e3744 5413
5414 /* Record adding route's nexthop and med. */
ffd0c037
DS
5415 if (rinew)
5416 {
5417#if defined(AGGREGATE_NEXTHOP_CHECK)
5418 nexthop = rinew->attr->nexthop;
5419 med = rinew->attr->med;
5420#endif
5421 }
718e3744 5422
5423 /* ORIGIN attribute: If at least one route among routes that are
5424 aggregated has ORIGIN with the value INCOMPLETE, then the
5425 aggregated route must have the ORIGIN attribute with the value
5426 INCOMPLETE. Otherwise, if at least one route among routes that
5427 are aggregated has ORIGIN with the value EGP, then the aggregated
5428 route must have the origin attribute with the value EGP. In all
5429 other case the value of the ORIGIN attribute of the aggregated
5430 route is INTERNAL. */
5431 origin = BGP_ORIGIN_IGP;
5432
5433 table = bgp->rib[afi][safi];
5434
5435 top = bgp_node_get (table, p);
5436 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5437 if (rn->p.prefixlen > p->prefixlen)
5438 {
5439 match = 0;
5440
5441 for (ri = rn->info; ri; ri = ri->next)
5442 {
5443 if (BGP_INFO_HOLDDOWN (ri))
5444 continue;
5445
5446 if (del && ri == del)
5447 continue;
5448
5449 if (! rinew && first)
5450 {
ffd0c037 5451#if defined(AGGREGATE_NEXTHOP_CHECK)
718e3744 5452 nexthop = ri->attr->nexthop;
5453 med = ri->attr->med;
ffd0c037 5454#endif
718e3744 5455 first = 0;
5456 }
5457
5458#ifdef AGGREGATE_NEXTHOP_CHECK
5459 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
5460 || ri->attr->med != med)
5461 {
5462 if (aspath)
5463 aspath_free (aspath);
5464 if (community)
5465 community_free (community);
5466 bgp_unlock_node (rn);
5467 bgp_unlock_node (top);
5468 return;
5469 }
5470#endif /* AGGREGATE_NEXTHOP_CHECK */
5471
42f7e184
DS
5472 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5473 atomic_aggregate = 1;
5474
718e3744 5475 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5476 {
5477 if (aggregate->summary_only)
5478 {
fb982c25 5479 (bgp_info_extra_get (ri))->suppress++;
1a392d46 5480 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5481 match++;
5482 }
5483
5484 aggregate->count++;
5485
b5d58c32
DS
5486 if (origin < ri->attr->origin)
5487 origin = ri->attr->origin;
5488
718e3744 5489 if (aggregate->as_set)
5490 {
718e3744 5491 if (aspath)
5492 {
5493 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5494 aspath_free (aspath);
5495 aspath = asmerge;
5496 }
5497 else
5498 aspath = aspath_dup (ri->attr->aspath);
5499
5500 if (ri->attr->community)
5501 {
5502 if (community)
5503 {
5504 commerge = community_merge (community,
5505 ri->attr->community);
5506 community = community_uniq_sort (commerge);
5507 community_free (commerge);
5508 }
5509 else
5510 community = community_dup (ri->attr->community);
5511 }
5512 }
5513 }
5514 }
5515 if (match)
5516 bgp_process (bgp, rn, afi, safi);
5517 }
5518 bgp_unlock_node (top);
5519
5520 if (rinew)
5521 {
5522 aggregate->count++;
5523
5524 if (aggregate->summary_only)
fb982c25 5525 (bgp_info_extra_get (rinew))->suppress++;
718e3744 5526
b5d58c32
DS
5527 if (origin < rinew->attr->origin)
5528 origin = rinew->attr->origin;
5529
718e3744 5530 if (aggregate->as_set)
5531 {
718e3744 5532 if (aspath)
5533 {
5534 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
5535 aspath_free (aspath);
5536 aspath = asmerge;
5537 }
5538 else
5539 aspath = aspath_dup (rinew->attr->aspath);
5540
5541 if (rinew->attr->community)
5542 {
5543 if (community)
5544 {
5545 commerge = community_merge (community,
5546 rinew->attr->community);
5547 community = community_uniq_sort (commerge);
5548 community_free (commerge);
5549 }
5550 else
5551 community = community_dup (rinew->attr->community);
5552 }
5553 }
5554 }
5555
5556 if (aggregate->count > 0)
5557 {
5558 rn = bgp_node_get (table, p);
7c8ff89e 5559 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 5560 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
5561 aggregate->as_set,
5562 atomic_aggregate), rn);
718e3744 5563 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 5564
5565 bgp_info_add (rn, new);
200df115 5566 bgp_unlock_node (rn);
718e3744 5567 bgp_process (bgp, rn, afi, safi);
5568 }
5569 else
5570 {
5571 if (aspath)
5572 aspath_free (aspath);
5573 if (community)
5574 community_free (community);
5575 }
5576}
5577
5578void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
5579 struct bgp_aggregate *);
5580
5581void
5582bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
5583 struct bgp_info *ri, afi_t afi, safi_t safi)
5584{
5585 struct bgp_node *child;
5586 struct bgp_node *rn;
5587 struct bgp_aggregate *aggregate;
f018db83 5588 struct bgp_table *table;
718e3744 5589
5590 /* MPLS-VPN aggregation is not yet supported. */
5591 if (safi == SAFI_MPLS_VPN)
5592 return;
5593
f018db83
JBD
5594 table = bgp->aggregate[afi][safi];
5595
5596 /* No aggregates configured. */
67174041 5597 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
5598 return;
5599
718e3744 5600 if (p->prefixlen == 0)
5601 return;
5602
5603 if (BGP_INFO_HOLDDOWN (ri))
5604 return;
5605
bb782fb5 5606 child = bgp_node_get (table, p);
718e3744 5607
5608 /* Aggregate address configuration check. */
67174041 5609 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 5610 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5611 {
5612 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 5613 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
718e3744 5614 }
5615 bgp_unlock_node (child);
5616}
5617
5618void
5619bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
5620 struct bgp_info *del, afi_t afi, safi_t safi)
5621{
5622 struct bgp_node *child;
5623 struct bgp_node *rn;
5624 struct bgp_aggregate *aggregate;
f018db83 5625 struct bgp_table *table;
718e3744 5626
5627 /* MPLS-VPN aggregation is not yet supported. */
5628 if (safi == SAFI_MPLS_VPN)
5629 return;
5630
f018db83
JBD
5631 table = bgp->aggregate[afi][safi];
5632
5633 /* No aggregates configured. */
67174041 5634 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
5635 return;
5636
718e3744 5637 if (p->prefixlen == 0)
5638 return;
5639
bb782fb5 5640 child = bgp_node_get (table, p);
718e3744 5641
5642 /* Aggregate address configuration check. */
67174041 5643 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 5644 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5645 {
5646 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 5647 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
718e3744 5648 }
5649 bgp_unlock_node (child);
5650}
5651
b5d58c32 5652/* Called via bgp_aggregate_set when the user configures aggregate-address */
94f2b392 5653static void
718e3744 5654bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5655 struct bgp_aggregate *aggregate)
5656{
5657 struct bgp_table *table;
5658 struct bgp_node *top;
5659 struct bgp_node *rn;
5660 struct bgp_info *new;
5661 struct bgp_info *ri;
5662 unsigned long match;
5663 u_char origin = BGP_ORIGIN_IGP;
5664 struct aspath *aspath = NULL;
5665 struct aspath *asmerge = NULL;
5666 struct community *community = NULL;
5667 struct community *commerge = NULL;
42f7e184 5668 u_char atomic_aggregate = 0;
718e3744 5669
5670 table = bgp->rib[afi][safi];
5671
5672 /* Sanity check. */
5673 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5674 return;
5675 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5676 return;
5677
5678 /* If routes exists below this node, generate aggregate routes. */
5679 top = bgp_node_get (table, p);
5680 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5681 if (rn->p.prefixlen > p->prefixlen)
5682 {
5683 match = 0;
5684
5685 for (ri = rn->info; ri; ri = ri->next)
5686 {
5687 if (BGP_INFO_HOLDDOWN (ri))
5688 continue;
5689
42f7e184
DS
5690 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5691 atomic_aggregate = 1;
5692
718e3744 5693 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5694 {
5695 /* summary-only aggregate route suppress aggregated
5696 route announcement. */
5697 if (aggregate->summary_only)
5698 {
fb982c25 5699 (bgp_info_extra_get (ri))->suppress++;
1a392d46 5700 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5701 match++;
5702 }
b5d58c32
DS
5703
5704 /* If at least one route among routes that are aggregated has
5705 * ORIGIN with the value INCOMPLETE, then the aggregated route
5706 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5707 * Otherwise, if at least one route among routes that are
5708 * aggregated has ORIGIN with the value EGP, then the aggregated
5709 * route MUST have the ORIGIN attribute with the value EGP.
5710 */
5711 if (origin < ri->attr->origin)
5712 origin = ri->attr->origin;
5713
718e3744 5714 /* as-set aggregate route generate origin, as path,
5715 community aggregation. */
5716 if (aggregate->as_set)
5717 {
718e3744 5718 if (aspath)
5719 {
5720 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5721 aspath_free (aspath);
5722 aspath = asmerge;
5723 }
5724 else
5725 aspath = aspath_dup (ri->attr->aspath);
5726
5727 if (ri->attr->community)
5728 {
5729 if (community)
5730 {
5731 commerge = community_merge (community,
5732 ri->attr->community);
5733 community = community_uniq_sort (commerge);
5734 community_free (commerge);
5735 }
5736 else
5737 community = community_dup (ri->attr->community);
5738 }
5739 }
5740 aggregate->count++;
5741 }
5742 }
5743
5744 /* If this node is suppressed, process the change. */
5745 if (match)
5746 bgp_process (bgp, rn, afi, safi);
5747 }
5748 bgp_unlock_node (top);
5749
5750 /* Add aggregate route to BGP table. */
5751 if (aggregate->count)
5752 {
5753 rn = bgp_node_get (table, p);
7c8ff89e 5754 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 5755 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
5756 aggregate->as_set,
5757 atomic_aggregate), rn);
718e3744 5758 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 5759
5760 bgp_info_add (rn, new);
200df115 5761 bgp_unlock_node (rn);
5762
718e3744 5763 /* Process change. */
5764 bgp_process (bgp, rn, afi, safi);
5765 }
610f23cf
DV
5766 else
5767 {
5768 if (aspath)
5769 aspath_free (aspath);
5770 if (community)
5771 community_free (community);
5772 }
718e3744 5773}
5774
5775void
5776bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5777 safi_t safi, struct bgp_aggregate *aggregate)
5778{
5779 struct bgp_table *table;
5780 struct bgp_node *top;
5781 struct bgp_node *rn;
5782 struct bgp_info *ri;
5783 unsigned long match;
5784
5785 table = bgp->rib[afi][safi];
5786
5787 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5788 return;
5789 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5790 return;
5791
5792 /* If routes exists below this node, generate aggregate routes. */
5793 top = bgp_node_get (table, p);
5794 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5795 if (rn->p.prefixlen > p->prefixlen)
5796 {
5797 match = 0;
5798
5799 for (ri = rn->info; ri; ri = ri->next)
5800 {
5801 if (BGP_INFO_HOLDDOWN (ri))
5802 continue;
5803
5804 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5805 {
fb982c25 5806 if (aggregate->summary_only && ri->extra)
718e3744 5807 {
fb982c25 5808 ri->extra->suppress--;
718e3744 5809
fb982c25 5810 if (ri->extra->suppress == 0)
718e3744 5811 {
1a392d46 5812 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5813 match++;
5814 }
5815 }
5816 aggregate->count--;
5817 }
5818 }
5819
fb982c25 5820 /* If this node was suppressed, process the change. */
718e3744 5821 if (match)
5822 bgp_process (bgp, rn, afi, safi);
5823 }
5824 bgp_unlock_node (top);
5825
5826 /* Delete aggregate route from BGP table. */
5827 rn = bgp_node_get (table, p);
5828
5829 for (ri = rn->info; ri; ri = ri->next)
5830 if (ri->peer == bgp->peer_self
5831 && ri->type == ZEBRA_ROUTE_BGP
5832 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5833 break;
5834
5835 /* Withdraw static BGP route from routing table. */
5836 if (ri)
5837 {
718e3744 5838 bgp_info_delete (rn, ri);
1a392d46 5839 bgp_process (bgp, rn, afi, safi);
718e3744 5840 }
5841
5842 /* Unlock bgp_node_lookup. */
5843 bgp_unlock_node (rn);
5844}
5845
5846/* Aggregate route attribute. */
5847#define AGGREGATE_SUMMARY_ONLY 1
5848#define AGGREGATE_AS_SET 1
5849
94f2b392 5850static int
f6269b4f
RB
5851bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5852 afi_t afi, safi_t safi)
718e3744 5853{
5854 int ret;
5855 struct prefix p;
5856 struct bgp_node *rn;
5857 struct bgp *bgp;
5858 struct bgp_aggregate *aggregate;
5859
5860 /* Convert string to prefix structure. */
5861 ret = str2prefix (prefix_str, &p);
5862 if (!ret)
5863 {
5864 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5865 return CMD_WARNING;
5866 }
5867 apply_mask (&p);
5868
5869 /* Get BGP structure. */
5870 bgp = vty->index;
5871
5872 /* Old configuration check. */
f6269b4f
RB
5873 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5874 if (! rn)
718e3744 5875 {
f6269b4f
RB
5876 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5877 VTY_NEWLINE);
718e3744 5878 return CMD_WARNING;
5879 }
5880
f6269b4f
RB
5881 aggregate = rn->info;
5882 if (aggregate->safi & SAFI_UNICAST)
5883 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5884 if (aggregate->safi & SAFI_MULTICAST)
5885 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 5886
f6269b4f
RB
5887 /* Unlock aggregate address configuration. */
5888 rn->info = NULL;
5889 bgp_aggregate_free (aggregate);
5890 bgp_unlock_node (rn);
5891 bgp_unlock_node (rn);
718e3744 5892
5893 return CMD_SUCCESS;
5894}
5895
94f2b392 5896static int
f6269b4f
RB
5897bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5898 afi_t afi, safi_t safi,
5899 u_char summary_only, u_char as_set)
718e3744 5900{
5901 int ret;
5902 struct prefix p;
5903 struct bgp_node *rn;
5904 struct bgp *bgp;
5905 struct bgp_aggregate *aggregate;
5906
5907 /* Convert string to prefix structure. */
5908 ret = str2prefix (prefix_str, &p);
5909 if (!ret)
5910 {
5911 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5912 return CMD_WARNING;
5913 }
5914 apply_mask (&p);
5915
5916 /* Get BGP structure. */
5917 bgp = vty->index;
5918
5919 /* Old configuration check. */
f6269b4f
RB
5920 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5921
5922 if (rn->info)
718e3744 5923 {
f6269b4f 5924 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
368473f6 5925 /* try to remove the old entry */
f6269b4f
RB
5926 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5927 if (ret)
5928 {
368473f6
RB
5929 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5930 bgp_unlock_node (rn);
f6269b4f
RB
5931 return CMD_WARNING;
5932 }
718e3744 5933 }
5934
f6269b4f
RB
5935 /* Make aggregate address structure. */
5936 aggregate = bgp_aggregate_new ();
5937 aggregate->summary_only = summary_only;
5938 aggregate->as_set = as_set;
5939 aggregate->safi = safi;
5940 rn->info = aggregate;
718e3744 5941
f6269b4f
RB
5942 /* Aggregate address insert into BGP routing table. */
5943 if (safi & SAFI_UNICAST)
5944 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5945 if (safi & SAFI_MULTICAST)
5946 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 5947
5948 return CMD_SUCCESS;
5949}
5950
5951DEFUN (aggregate_address,
5952 aggregate_address_cmd,
5953 "aggregate-address A.B.C.D/M",
5954 "Configure BGP aggregate entries\n"
5955 "Aggregate prefix\n")
5956{
5957 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5958}
5959
5960DEFUN (aggregate_address_mask,
5961 aggregate_address_mask_cmd,
5962 "aggregate-address A.B.C.D A.B.C.D",
5963 "Configure BGP aggregate entries\n"
5964 "Aggregate address\n"
5965 "Aggregate mask\n")
5966{
5967 int ret;
5968 char prefix_str[BUFSIZ];
5969
5970 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5971
5972 if (! ret)
5973 {
5974 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5975 return CMD_WARNING;
5976 }
5977
5978 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5979 0, 0);
5980}
5981
5982DEFUN (aggregate_address_summary_only,
5983 aggregate_address_summary_only_cmd,
5984 "aggregate-address A.B.C.D/M summary-only",
5985 "Configure BGP aggregate entries\n"
5986 "Aggregate prefix\n"
5987 "Filter more specific routes from updates\n")
5988{
5989 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5990 AGGREGATE_SUMMARY_ONLY, 0);
5991}
5992
5993DEFUN (aggregate_address_mask_summary_only,
5994 aggregate_address_mask_summary_only_cmd,
5995 "aggregate-address A.B.C.D A.B.C.D summary-only",
5996 "Configure BGP aggregate entries\n"
5997 "Aggregate address\n"
5998 "Aggregate mask\n"
5999 "Filter more specific routes from updates\n")
6000{
6001 int ret;
6002 char prefix_str[BUFSIZ];
6003
6004 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6005
6006 if (! ret)
6007 {
6008 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6009 return CMD_WARNING;
6010 }
6011
6012 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
6013 AGGREGATE_SUMMARY_ONLY, 0);
6014}
6015
6016DEFUN (aggregate_address_as_set,
6017 aggregate_address_as_set_cmd,
6018 "aggregate-address A.B.C.D/M as-set",
6019 "Configure BGP aggregate entries\n"
6020 "Aggregate prefix\n"
6021 "Generate AS set path information\n")
6022{
6023 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
6024 0, AGGREGATE_AS_SET);
6025}
6026
6027DEFUN (aggregate_address_mask_as_set,
6028 aggregate_address_mask_as_set_cmd,
6029 "aggregate-address A.B.C.D A.B.C.D as-set",
6030 "Configure BGP aggregate entries\n"
6031 "Aggregate address\n"
6032 "Aggregate mask\n"
6033 "Generate AS set path information\n")
6034{
6035 int ret;
6036 char prefix_str[BUFSIZ];
6037
6038 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6039
6040 if (! ret)
6041 {
6042 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6043 return CMD_WARNING;
6044 }
6045
6046 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
6047 0, AGGREGATE_AS_SET);
6048}
6049
6050
6051DEFUN (aggregate_address_as_set_summary,
6052 aggregate_address_as_set_summary_cmd,
6053 "aggregate-address A.B.C.D/M as-set summary-only",
6054 "Configure BGP aggregate entries\n"
6055 "Aggregate prefix\n"
6056 "Generate AS set path information\n"
6057 "Filter more specific routes from updates\n")
6058{
6059 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
6060 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
6061}
6062
6063ALIAS (aggregate_address_as_set_summary,
6064 aggregate_address_summary_as_set_cmd,
6065 "aggregate-address A.B.C.D/M summary-only as-set",
6066 "Configure BGP aggregate entries\n"
6067 "Aggregate prefix\n"
6068 "Filter more specific routes from updates\n"
6069 "Generate AS set path information\n")
6070
6071DEFUN (aggregate_address_mask_as_set_summary,
6072 aggregate_address_mask_as_set_summary_cmd,
6073 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
6074 "Configure BGP aggregate entries\n"
6075 "Aggregate address\n"
6076 "Aggregate mask\n"
6077 "Generate AS set path information\n"
6078 "Filter more specific routes from updates\n")
6079{
6080 int ret;
6081 char prefix_str[BUFSIZ];
6082
6083 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6084
6085 if (! ret)
6086 {
6087 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6088 return CMD_WARNING;
6089 }
6090
6091 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
6092 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
6093}
6094
6095ALIAS (aggregate_address_mask_as_set_summary,
6096 aggregate_address_mask_summary_as_set_cmd,
6097 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
6098 "Configure BGP aggregate entries\n"
6099 "Aggregate address\n"
6100 "Aggregate mask\n"
6101 "Filter more specific routes from updates\n"
6102 "Generate AS set path information\n")
6103
6104DEFUN (no_aggregate_address,
6105 no_aggregate_address_cmd,
6106 "no aggregate-address A.B.C.D/M",
6107 NO_STR
6108 "Configure BGP aggregate entries\n"
6109 "Aggregate prefix\n")
6110{
6111 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
6112}
6113
6114ALIAS (no_aggregate_address,
6115 no_aggregate_address_summary_only_cmd,
6116 "no aggregate-address A.B.C.D/M summary-only",
6117 NO_STR
6118 "Configure BGP aggregate entries\n"
6119 "Aggregate prefix\n"
6120 "Filter more specific routes from updates\n")
6121
6122ALIAS (no_aggregate_address,
6123 no_aggregate_address_as_set_cmd,
6124 "no aggregate-address A.B.C.D/M as-set",
6125 NO_STR
6126 "Configure BGP aggregate entries\n"
6127 "Aggregate prefix\n"
6128 "Generate AS set path information\n")
6129
6130ALIAS (no_aggregate_address,
6131 no_aggregate_address_as_set_summary_cmd,
6132 "no aggregate-address A.B.C.D/M as-set summary-only",
6133 NO_STR
6134 "Configure BGP aggregate entries\n"
6135 "Aggregate prefix\n"
6136 "Generate AS set path information\n"
6137 "Filter more specific routes from updates\n")
6138
6139ALIAS (no_aggregate_address,
6140 no_aggregate_address_summary_as_set_cmd,
6141 "no aggregate-address A.B.C.D/M summary-only as-set",
6142 NO_STR
6143 "Configure BGP aggregate entries\n"
6144 "Aggregate prefix\n"
6145 "Filter more specific routes from updates\n"
6146 "Generate AS set path information\n")
6147
6148DEFUN (no_aggregate_address_mask,
6149 no_aggregate_address_mask_cmd,
6150 "no aggregate-address A.B.C.D A.B.C.D",
6151 NO_STR
6152 "Configure BGP aggregate entries\n"
6153 "Aggregate address\n"
6154 "Aggregate mask\n")
6155{
6156 int ret;
6157 char prefix_str[BUFSIZ];
6158
6159 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6160
6161 if (! ret)
6162 {
6163 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6164 return CMD_WARNING;
6165 }
6166
6167 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
6168}
6169
6170ALIAS (no_aggregate_address_mask,
6171 no_aggregate_address_mask_summary_only_cmd,
6172 "no aggregate-address A.B.C.D A.B.C.D summary-only",
6173 NO_STR
6174 "Configure BGP aggregate entries\n"
6175 "Aggregate address\n"
6176 "Aggregate mask\n"
6177 "Filter more specific routes from updates\n")
6178
6179ALIAS (no_aggregate_address_mask,
6180 no_aggregate_address_mask_as_set_cmd,
6181 "no aggregate-address A.B.C.D A.B.C.D as-set",
6182 NO_STR
6183 "Configure BGP aggregate entries\n"
6184 "Aggregate address\n"
6185 "Aggregate mask\n"
6186 "Generate AS set path information\n")
6187
6188ALIAS (no_aggregate_address_mask,
6189 no_aggregate_address_mask_as_set_summary_cmd,
6190 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
6191 NO_STR
6192 "Configure BGP aggregate entries\n"
6193 "Aggregate address\n"
6194 "Aggregate mask\n"
6195 "Generate AS set path information\n"
6196 "Filter more specific routes from updates\n")
6197
6198ALIAS (no_aggregate_address_mask,
6199 no_aggregate_address_mask_summary_as_set_cmd,
6200 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
6201 NO_STR
6202 "Configure BGP aggregate entries\n"
6203 "Aggregate address\n"
6204 "Aggregate mask\n"
6205 "Filter more specific routes from updates\n"
6206 "Generate AS set path information\n")
6207
6208#ifdef HAVE_IPV6
6209DEFUN (ipv6_aggregate_address,
6210 ipv6_aggregate_address_cmd,
6211 "aggregate-address X:X::X:X/M",
6212 "Configure BGP aggregate entries\n"
6213 "Aggregate prefix\n")
6214{
6215 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
6216}
6217
6218DEFUN (ipv6_aggregate_address_summary_only,
6219 ipv6_aggregate_address_summary_only_cmd,
6220 "aggregate-address X:X::X:X/M summary-only",
6221 "Configure BGP aggregate entries\n"
6222 "Aggregate prefix\n"
6223 "Filter more specific routes from updates\n")
6224{
6225 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6226 AGGREGATE_SUMMARY_ONLY, 0);
6227}
6228
6229DEFUN (no_ipv6_aggregate_address,
6230 no_ipv6_aggregate_address_cmd,
6231 "no aggregate-address X:X::X:X/M",
6232 NO_STR
6233 "Configure BGP aggregate entries\n"
6234 "Aggregate prefix\n")
6235{
6236 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
6237}
6238
6239DEFUN (no_ipv6_aggregate_address_summary_only,
6240 no_ipv6_aggregate_address_summary_only_cmd,
6241 "no aggregate-address X:X::X:X/M summary-only",
6242 NO_STR
6243 "Configure BGP aggregate entries\n"
6244 "Aggregate prefix\n"
6245 "Filter more specific routes from updates\n")
6246{
6247 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
6248}
6249
6250ALIAS (ipv6_aggregate_address,
6251 old_ipv6_aggregate_address_cmd,
6252 "ipv6 bgp aggregate-address X:X::X:X/M",
6253 IPV6_STR
6254 BGP_STR
6255 "Configure BGP aggregate entries\n"
6256 "Aggregate prefix\n")
6257
6258ALIAS (ipv6_aggregate_address_summary_only,
6259 old_ipv6_aggregate_address_summary_only_cmd,
6260 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
6261 IPV6_STR
6262 BGP_STR
6263 "Configure BGP aggregate entries\n"
6264 "Aggregate prefix\n"
6265 "Filter more specific routes from updates\n")
6266
6267ALIAS (no_ipv6_aggregate_address,
6268 old_no_ipv6_aggregate_address_cmd,
6269 "no ipv6 bgp aggregate-address X:X::X:X/M",
6270 NO_STR
6271 IPV6_STR
6272 BGP_STR
6273 "Configure BGP aggregate entries\n"
6274 "Aggregate prefix\n")
6275
6276ALIAS (no_ipv6_aggregate_address_summary_only,
6277 old_no_ipv6_aggregate_address_summary_only_cmd,
6278 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
6279 NO_STR
6280 IPV6_STR
6281 BGP_STR
6282 "Configure BGP aggregate entries\n"
6283 "Aggregate prefix\n"
6284 "Filter more specific routes from updates\n")
6285#endif /* HAVE_IPV6 */
6b0655a2 6286
718e3744 6287/* Redistribute route treatment. */
6288void
f04a80a5 6289bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
bc413143 6290 const struct in6_addr *nexthop6, unsigned int ifindex,
7c8ff89e 6291 u_int32_t metric, u_char type, u_short instance, u_short tag)
718e3744 6292{
6293 struct bgp *bgp;
1eb8ef25 6294 struct listnode *node, *nnode;
718e3744 6295 struct bgp_info *new;
6296 struct bgp_info *bi;
6297 struct bgp_info info;
6298 struct bgp_node *bn;
e16a4133 6299 struct attr attr;
718e3744 6300 struct attr *new_attr;
6301 afi_t afi;
6302 int ret;
7c8ff89e 6303 struct bgp_redist *red;
718e3744 6304
6305 /* Make default attribute. */
6306 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
6307 if (nexthop)
6308 attr.nexthop = *nexthop;
bc413143 6309 attr.nh_ifindex = ifindex;
718e3744 6310
f04a80a5
SH
6311#ifdef HAVE_IPV6
6312 if (nexthop6)
6313 {
6314 struct attr_extra *extra = bgp_attr_extra_get(&attr);
6315 extra->mp_nexthop_global = *nexthop6;
801a9bcc 6316 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
f04a80a5
SH
6317 }
6318#endif
6319
718e3744 6320 attr.med = metric;
6321 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
0d9551dc 6322 attr.extra->tag = tag;
718e3744 6323
1eb8ef25 6324 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 6325 {
6326 afi = family2afi (p->family);
6327
7c8ff89e
DS
6328 red = bgp_redist_lookup(bgp, afi, type, instance);
6329 if (red)
718e3744 6330 {
558d1fec
JBD
6331 struct attr attr_new;
6332 struct attr_extra extra_new;
6333
718e3744 6334 /* Copy attribute for modification. */
558d1fec 6335 attr_new.extra = &extra_new;
fb982c25 6336 bgp_attr_dup (&attr_new, &attr);
718e3744 6337
7c8ff89e
DS
6338 if (red->redist_metric_flag)
6339 attr_new.med = red->redist_metric;
718e3744 6340
6341 /* Apply route-map. */
91e89998 6342 if (red->rmap.name)
718e3744 6343 {
6344 info.peer = bgp->peer_self;
6345 info.attr = &attr_new;
6346
fee0f4c6 6347 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
6348
7c8ff89e 6349 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
fee0f4c6 6350
6351 bgp->peer_self->rmap_type = 0;
6352
718e3744 6353 if (ret == RMAP_DENYMATCH)
6354 {
6355 /* Free uninterned attribute. */
6356 bgp_attr_flush (&attr_new);
558d1fec 6357
718e3744 6358 /* Unintern original. */
f6f434b2 6359 aspath_unintern (&attr.aspath);
fb982c25 6360 bgp_attr_extra_free (&attr);
7c8ff89e 6361 bgp_redistribute_delete (p, type, instance);
718e3744 6362 return;
6363 }
6364 }
6365
fb982c25
PJ
6366 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
6367 afi, SAFI_UNICAST, p, NULL);
6368
718e3744 6369 new_attr = bgp_attr_intern (&attr_new);
558d1fec 6370
718e3744 6371 for (bi = bn->info; bi; bi = bi->next)
6372 if (bi->peer == bgp->peer_self
6373 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
6374 break;
6375
6376 if (bi)
6377 {
1844fdbd 6378 /* Ensure the (source route) type is updated. */
6379 bi->type = type;
8d45210e
AS
6380 if (attrhash_cmp (bi->attr, new_attr) &&
6381 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
718e3744 6382 {
f6f434b2
PJ
6383 bgp_attr_unintern (&new_attr);
6384 aspath_unintern (&attr.aspath);
fb982c25 6385 bgp_attr_extra_free (&attr);
718e3744 6386 bgp_unlock_node (bn);
6387 return;
6388 }
6389 else
6390 {
6391 /* The attribute is changed. */
1a392d46 6392 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
718e3744 6393
6394 /* Rewrite BGP route information. */
8d45210e
AS
6395 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
6396 bgp_info_restore(bn, bi);
6397 else
6398 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
f6f434b2 6399 bgp_attr_unintern (&bi->attr);
718e3744 6400 bi->attr = new_attr;
65957886 6401 bi->uptime = bgp_clock ();
718e3744 6402
6403 /* Process change. */
6404 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
6405 bgp_process (bgp, bn, afi, SAFI_UNICAST);
6406 bgp_unlock_node (bn);
f6f434b2 6407 aspath_unintern (&attr.aspath);
fb982c25 6408 bgp_attr_extra_free (&attr);
718e3744 6409 return;
fb018d25 6410 }
718e3744 6411 }
6412
7c8ff89e 6413 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
fb018d25 6414 new_attr, bn);
718e3744 6415 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 6416
6417 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
6418 bgp_info_add (bn, new);
200df115 6419 bgp_unlock_node (bn);
718e3744 6420 bgp_process (bgp, bn, afi, SAFI_UNICAST);
6421 }
6422 }
6423
6424 /* Unintern original. */
f6f434b2 6425 aspath_unintern (&attr.aspath);
fb982c25 6426 bgp_attr_extra_free (&attr);
718e3744 6427}
6428
6429void
7c8ff89e 6430bgp_redistribute_delete (struct prefix *p, u_char type, u_short instance)
718e3744 6431{
6432 struct bgp *bgp;
1eb8ef25 6433 struct listnode *node, *nnode;
718e3744 6434 afi_t afi;
6435 struct bgp_node *rn;
6436 struct bgp_info *ri;
7c8ff89e 6437 struct bgp_redist *red;
718e3744 6438
1eb8ef25 6439 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 6440 {
6441 afi = family2afi (p->family);
6442
7c8ff89e
DS
6443 red = bgp_redist_lookup(bgp, afi, type, instance);
6444 if (red)
718e3744 6445 {
fee0f4c6 6446 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
718e3744 6447
6448 for (ri = rn->info; ri; ri = ri->next)
6449 if (ri->peer == bgp->peer_self
6450 && ri->type == type)
6451 break;
6452
6453 if (ri)
6454 {
6455 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
718e3744 6456 bgp_info_delete (rn, ri);
1a392d46 6457 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 6458 }
6459 bgp_unlock_node (rn);
6460 }
6461 }
6462}
6463
6464/* Withdraw specified route type's route. */
6465void
7c8ff89e 6466bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
718e3744 6467{
6468 struct bgp_node *rn;
6469 struct bgp_info *ri;
6470 struct bgp_table *table;
6471
6472 table = bgp->rib[afi][SAFI_UNICAST];
6473
6474 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6475 {
6476 for (ri = rn->info; ri; ri = ri->next)
6477 if (ri->peer == bgp->peer_self
7c8ff89e
DS
6478 && ri->type == type
6479 && ri->instance == instance)
718e3744 6480 break;
6481
6482 if (ri)
6483 {
6484 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
718e3744 6485 bgp_info_delete (rn, ri);
1a392d46 6486 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 6487 }
6488 }
6489}
6b0655a2 6490
718e3744 6491/* Static function to display route. */
94f2b392 6492static void
718e3744 6493route_vty_out_route (struct prefix *p, struct vty *vty)
6494{
6495 int len;
6496 u_int32_t destination;
6497 char buf[BUFSIZ];
6498
6499 if (p->family == AF_INET)
6500 {
6501 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
6502 destination = ntohl (p->u.prefix4.s_addr);
6503
6504 if ((IN_CLASSC (destination) && p->prefixlen == 24)
856ca177
MS
6505 || (IN_CLASSB (destination) && p->prefixlen == 16)
6506 || (IN_CLASSA (destination) && p->prefixlen == 8)
6507 || p->u.prefix4.s_addr == 0)
6508 {
6509 /* When mask is natural, mask is not displayed. */
6510 }
718e3744 6511 else
856ca177 6512 len += vty_out (vty, "/%d", p->prefixlen);
718e3744 6513 }
6514 else
6515 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
6516 p->prefixlen);
6517
6518 len = 17 - len;
6519 if (len < 1)
6520 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
6521 else
6522 vty_out (vty, "%*s", len, " ");
6523}
6524
718e3744 6525enum bgp_display_type
6526{
6527 normal_list,
6528};
6529
b40d939b 6530/* Print the short form route status for a bgp_info */
6531static void
b05a1c8b
DS
6532route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
6533 json_object *json_path)
718e3744 6534{
b05a1c8b
DS
6535 if (json_path)
6536 {
b05a1c8b
DS
6537
6538 /* Route status display. */
6539 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
f1aa5d8a 6540 json_object_boolean_true_add(json_path, "removed");
b05a1c8b
DS
6541
6542 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
f1aa5d8a 6543 json_object_boolean_true_add(json_path, "stale");
b05a1c8b
DS
6544
6545 if (binfo->extra && binfo->extra->suppress)
f1aa5d8a 6546 json_object_boolean_true_add(json_path, "suppressed");
b05a1c8b
DS
6547
6548 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6549 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
f1aa5d8a 6550 json_object_boolean_true_add(json_path, "valid");
b05a1c8b
DS
6551
6552 /* Selected */
6553 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
f1aa5d8a 6554 json_object_boolean_true_add(json_path, "history");
b05a1c8b
DS
6555
6556 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
f1aa5d8a 6557 json_object_boolean_true_add(json_path, "damped");
b05a1c8b
DS
6558
6559 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
f1aa5d8a 6560 json_object_boolean_true_add(json_path, "bestpath");
b05a1c8b
DS
6561
6562 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
f1aa5d8a 6563 json_object_boolean_true_add(json_path, "multipath");
b05a1c8b
DS
6564
6565 /* Internal route. */
6566 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
62d6dca0 6567 json_object_string_add(json_path, "pathFrom", "internal");
b05a1c8b 6568 else
62d6dca0 6569 json_object_string_add(json_path, "pathFrom", "external");
b05a1c8b
DS
6570
6571 return;
6572 }
6573
b40d939b 6574 /* Route status display. */
6575 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6576 vty_out (vty, "R");
6577 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
93406d87 6578 vty_out (vty, "S");
fb982c25 6579 else if (binfo->extra && binfo->extra->suppress)
718e3744 6580 vty_out (vty, "s");
31eba040
DS
6581 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6582 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
718e3744 6583 vty_out (vty, "*");
6584 else
6585 vty_out (vty, " ");
6586
6587 /* Selected */
6588 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6589 vty_out (vty, "h");
6590 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6591 vty_out (vty, "d");
6592 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6593 vty_out (vty, ">");
b366b518
BB
6594 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6595 vty_out (vty, "=");
718e3744 6596 else
6597 vty_out (vty, " ");
6598
6599 /* Internal route. */
b05a1c8b
DS
6600 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6601 vty_out (vty, "i");
6602 else
6603 vty_out (vty, " ");
b40d939b 6604}
6605
6606/* called from terminal list command */
6607void
6608route_vty_out (struct vty *vty, struct prefix *p,
b05a1c8b
DS
6609 struct bgp_info *binfo, int display, safi_t safi,
6610 json_object *json_paths)
b40d939b 6611{
6612 struct attr *attr;
f1aa5d8a
DS
6613 json_object *json_path = NULL;
6614 json_object *json_nexthops = NULL;
6615 json_object *json_nexthop_global = NULL;
6616 json_object *json_nexthop_ll = NULL;
47fc97cc 6617
b05a1c8b
DS
6618 if (json_paths)
6619 json_path = json_object_new_object();
b05a1c8b
DS
6620
6621 /* short status lead text */
6622 route_vty_short_status_out (vty, binfo, json_path);
718e3744 6623
b05a1c8b
DS
6624 if (!json_paths)
6625 {
6626 /* print prefix and mask */
6627 if (! display)
6628 route_vty_out_route (p, vty);
6629 else
6630 vty_out (vty, "%*s", 17, " ");
6631 }
47fc97cc 6632
718e3744 6633 /* Print attribute */
6634 attr = binfo->attr;
6635 if (attr)
6636 {
b05a1c8b
DS
6637
6638 /* IPv4 Next Hop */
8a92a8a0
DS
6639 if (p->family == AF_INET
6640 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 6641 {
b05a1c8b
DS
6642 if (json_paths)
6643 {
f1aa5d8a
DS
6644 json_nexthop_global = json_object_new_object();
6645
b05a1c8b 6646 if (safi == SAFI_MPLS_VPN)
f1aa5d8a 6647 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
b05a1c8b 6648 else
f1aa5d8a
DS
6649 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6650
6651 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6652 json_object_boolean_true_add(json_nexthop_global, "used");
b05a1c8b
DS
6653 }
6654 else
6655 {
6656 if (safi == SAFI_MPLS_VPN)
6657 vty_out (vty, "%-16s",
6658 inet_ntoa (attr->extra->mp_nexthop_global_in));
6659 else
6660 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6661 }
718e3744 6662 }
b05a1c8b
DS
6663
6664#ifdef HAVE_IPV6
6665 /* IPv6 Next Hop */
8a92a8a0 6666 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
718e3744 6667 {
6668 int len;
6669 char buf[BUFSIZ];
6670
b05a1c8b
DS
6671 if (json_paths)
6672 {
f1aa5d8a
DS
6673 json_nexthop_global = json_object_new_object();
6674 json_object_string_add(json_nexthop_global, "ip",
6675 inet_ntop (AF_INET6,
6676 &attr->extra->mp_nexthop_global,
6677 buf, BUFSIZ));
6678 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6679 json_object_string_add(json_nexthop_global, "scope", "global");
6680
6681 /* We display both LL & GL if both have been received */
6682 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
6683 {
6684 json_nexthop_ll = json_object_new_object();
6685 json_object_string_add(json_nexthop_ll, "ip",
6686 inet_ntop (AF_INET6,
6687 &attr->extra->mp_nexthop_local,
6688 buf, BUFSIZ));
6689 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
6690 json_object_string_add(json_nexthop_ll, "scope", "link-local");
6691
6692 if (IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global,
6693 &attr->extra->mp_nexthop_local) != 0)
6694 json_object_boolean_true_add(json_nexthop_ll, "used");
6695 else
6696 json_object_boolean_true_add(json_nexthop_global, "used");
6697 }
6698 else
6699 json_object_boolean_true_add(json_nexthop_global, "used");
b05a1c8b
DS
6700 }
6701 else
6702 {
433e8b67
DS
6703 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
6704 {
6705 if (binfo->peer->conf_if)
6706 {
6707 len = vty_out (vty, "%s",
6708 binfo->peer->conf_if);
6709 len = 7 - len; /* len of IPv6 addr + max len of def ifname */
6710
6711 if (len < 1)
6712 vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " ");
6713 else
6714 vty_out (vty, "%*s", len, " ");
6715 }
6716 else
6717 {
6718 len = vty_out (vty, "%s",
6719 inet_ntop (AF_INET6,
6720 &attr->extra->mp_nexthop_local,
6721 buf, BUFSIZ));
6722 len = 16 - len;
6723
6724 if (len < 1)
6725 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6726 else
6727 vty_out (vty, "%*s", len, " ");
6728 }
6729 }
6730 else
6731 {
6732 len = vty_out (vty, "%s",
6733 inet_ntop (AF_INET6,
6734 &attr->extra->mp_nexthop_global,
6735 buf, BUFSIZ));
6736 len = 16 - len;
6737
6738 if (len < 1)
6739 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6740 else
6741 vty_out (vty, "%*s", len, " ");
6742 }
b05a1c8b 6743 }
718e3744 6744 }
6745#endif /* HAVE_IPV6 */
6746
b05a1c8b 6747 /* MED/Metric */
718e3744 6748 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b 6749 if (json_paths)
f1aa5d8a 6750 json_object_int_add(json_path, "med", attr->med);
b05a1c8b
DS
6751 else
6752 vty_out (vty, "%10u", attr->med);
718e3744 6753 else
b05a1c8b
DS
6754 if (!json_paths)
6755 vty_out (vty, " ");
47fc97cc 6756
b05a1c8b 6757 /* Local Pref */
718e3744 6758 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
b05a1c8b 6759 if (json_paths)
f1aa5d8a 6760 json_object_int_add(json_path, "localpref", attr->local_pref);
b05a1c8b
DS
6761 else
6762 vty_out (vty, "%7u", attr->local_pref);
718e3744 6763 else
b05a1c8b
DS
6764 if (!json_paths)
6765 vty_out (vty, " ");
718e3744 6766
b05a1c8b
DS
6767 if (json_paths)
6768 {
6769 if (attr->extra)
f1aa5d8a 6770 json_object_int_add(json_path, "weight", attr->extra->weight);
b05a1c8b 6771 else
f1aa5d8a 6772 json_object_int_add(json_path, "weight", 0);
b05a1c8b
DS
6773 }
6774 else
6775 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
47fc97cc 6776
b2518c1e
PJ
6777 /* Print aspath */
6778 if (attr->aspath)
b05a1c8b
DS
6779 {
6780 if (json_paths)
f1aa5d8a 6781 json_object_string_add(json_path, "aspath", attr->aspath->str);
b05a1c8b 6782 else
f1aa5d8a 6783 aspath_print_vty (vty, "%s", attr->aspath, " ");
b05a1c8b 6784 }
47fc97cc 6785
b2518c1e 6786 /* Print origin */
b05a1c8b 6787 if (json_paths)
f1aa5d8a 6788 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
b05a1c8b
DS
6789 else
6790 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 6791 }
856ca177
MS
6792 else
6793 {
6794 if (json_paths)
6795 json_object_string_add(json_path, "alert", "No attributes");
6796 else
6797 vty_out (vty, "No attributes to print%s", VTY_NEWLINE);
6798 }
b05a1c8b
DS
6799
6800 if (json_paths)
f1aa5d8a
DS
6801 {
6802 if (json_nexthop_global || json_nexthop_ll)
6803 {
6804 json_nexthops = json_object_new_array();
6805
6806 if (json_nexthop_global)
6807 json_object_array_add(json_nexthops, json_nexthop_global);
6808
6809 if (json_nexthop_ll)
6810 json_object_array_add(json_nexthops, json_nexthop_ll);
6811
6812 json_object_object_add(json_path, "nexthops", json_nexthops);
6813 }
6814
6815 json_object_array_add(json_paths, json_path);
6816 }
b05a1c8b
DS
6817 else
6818 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6819}
6820
6821/* called from terminal list command */
6822void
856ca177
MS
6823route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi,
6824 u_char use_json, json_object *json_ar)
718e3744 6825{
856ca177
MS
6826 json_object *json_status = NULL;
6827 json_object *json_net = NULL;
6828 char buff[BUFSIZ];
718e3744 6829 /* Route status display. */
856ca177
MS
6830 if (use_json)
6831 {
6832 json_status = json_object_new_object();
6833 json_net = json_object_new_object();
6834 }
6835 else
6836 {
6837 vty_out (vty, "*");
6838 vty_out (vty, ">");
6839 vty_out (vty, " ");
6840 }
718e3744 6841
6842 /* print prefix and mask */
856ca177
MS
6843 if (use_json)
6844 json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ));
6845 else
6846 route_vty_out_route (p, vty);
718e3744 6847
6848 /* Print attribute */
6849 if (attr)
6850 {
856ca177 6851 if (use_json)
718e3744 6852 {
856ca177
MS
6853 if (p->family == AF_INET && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6854 {
6855 if (safi == SAFI_MPLS_VPN)
6856 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in));
6857 else
6858 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop));
6859 }
6860#ifdef HAVE_IPV6
6861 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6862 {
6863 char buf[BUFSIZ];
718e3744 6864
856ca177
MS
6865 json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6866 buf, BUFSIZ));
6867 }
6868#endif /* HAVE_IPV6 */
6869
6870 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6871 json_object_int_add(json_net, "metric", attr->med);
6872
6873 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6874 json_object_int_add(json_net, "localPref", attr->local_pref);
6875
6876 if (attr->extra)
6877 json_object_int_add(json_net, "weight", attr->extra->weight);
718e3744 6878 else
856ca177
MS
6879 json_object_int_add(json_net, "weight", 0);
6880
6881 /* Print aspath */
6882 if (attr->aspath)
6883 json_object_string_add(json_net, "asPath", attr->aspath->str);
6884
6885 /* Print origin */
6886 json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]);
718e3744 6887 }
856ca177
MS
6888 else
6889 {
6890 if (p->family == AF_INET && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6891 {
6892 if (safi == SAFI_MPLS_VPN)
6893 vty_out (vty, "%-16s",
6894 inet_ntoa (attr->extra->mp_nexthop_global_in));
6895 else
6896 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6897 }
6898#ifdef HAVE_IPV6
6899 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6900 {
6901 int len;
6902 char buf[BUFSIZ];
6903
6904 assert (attr->extra);
6905
6906 len = vty_out (vty, "%s",
6907 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6908 buf, BUFSIZ));
6909 len = 16 - len;
6910 if (len < 1)
6911 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6912 else
6913 vty_out (vty, "%*s", len, " ");
6914 }
718e3744 6915#endif /* HAVE_IPV6 */
856ca177
MS
6916 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6917 vty_out (vty, "%10u", attr->med);
6918 else
6919 vty_out (vty, " ");
718e3744 6920
856ca177
MS
6921 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6922 vty_out (vty, "%7u", attr->local_pref);
6923 else
6924 vty_out (vty, " ");
718e3744 6925
856ca177 6926 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
718e3744 6927
856ca177
MS
6928 /* Print aspath */
6929 if (attr->aspath)
6930 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 6931
856ca177
MS
6932 /* Print origin */
6933 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6934 }
6935 }
6936 if (use_json)
6937 {
6938 json_object_boolean_true_add(json_status, "*");
6939 json_object_boolean_true_add(json_status, ">");
6940 json_object_object_add(json_net, "appliedStatusSymbols", json_status);
6941 char buf_cut[BUFSIZ];
6942 json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net);
6943 }
6944 else
6945 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6946}
6947
5a646650 6948void
718e3744 6949route_vty_out_tag (struct vty *vty, struct prefix *p,
856ca177 6950 struct bgp_info *binfo, int display, safi_t safi, json_object *json)
718e3744 6951{
856ca177 6952 json_object *json_out = NULL;
718e3744 6953 struct attr *attr;
718e3744 6954 u_int32_t label = 0;
fb982c25
PJ
6955
6956 if (!binfo->extra)
6957 return;
856ca177
MS
6958
6959 if (json)
6960 json_out = json_object_new_object();
fb982c25 6961
b40d939b 6962 /* short status lead text */
856ca177 6963 route_vty_short_status_out (vty, binfo, json_out);
b40d939b 6964
718e3744 6965 /* print prefix and mask */
856ca177
MS
6966 if (json == NULL)
6967 {
6968 if (! display)
6969 route_vty_out_route (p, vty);
6970 else
6971 vty_out (vty, "%*s", 17, " ");
6972 }
718e3744 6973
6974 /* Print attribute */
6975 attr = binfo->attr;
6976 if (attr)
6977 {
8a92a8a0
DS
6978 if (p->family == AF_INET
6979 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 6980 {
6981 if (safi == SAFI_MPLS_VPN)
856ca177
MS
6982 {
6983 if (json)
6984 json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in));
6985 else
6986 vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6987 }
718e3744 6988 else
856ca177
MS
6989 {
6990 if (json)
6991 json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop));
6992 else
6993 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6994 }
718e3744 6995 }
6996#ifdef HAVE_IPV6
8a92a8a0 6997 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
718e3744 6998 {
fb982c25 6999 assert (attr->extra);
856ca177
MS
7000 char buf_a[BUFSIZ];
7001 char buf_b[BUFSIZ];
7002 char buf_c[BUFSIZ];
801a9bcc 7003 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
856ca177
MS
7004 {
7005 if (json)
7006 json_object_string_add(json_out, "mpNexthopGlobalIn",
7007 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ));
7008 else
7009 vty_out (vty, "%s",
7010 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7011 buf_a, BUFSIZ));
7012 }
801a9bcc 7013 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
856ca177
MS
7014 {
7015 if (json)
7016 {
7017 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7018 buf_a, BUFSIZ);
7019 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7020 buf_b, BUFSIZ);
7021 sprintf(buf_c, "%s(%s)", buf_a, buf_b);
7022 json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c);
7023 }
7024 else
7025 vty_out (vty, "%s(%s)",
7026 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7027 buf_a, BUFSIZ),
7028 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7029 buf_b, BUFSIZ));
7030 }
7031
718e3744 7032 }
7033#endif /* HAVE_IPV6 */
7034 }
7035
fb982c25 7036 label = decode_label (binfo->extra->tag);
718e3744 7037
856ca177
MS
7038 if (json)
7039 {
7040 if (label)
7041 json_object_int_add(json_out, "notag", label);
7042 json_object_array_add(json, json_out);
7043 }
7044 else
7045 {
7046 vty_out (vty, "notag/%d", label);
7047 vty_out (vty, "%s", VTY_NEWLINE);
7048 }
718e3744 7049}
7050
7051/* dampening route */
5a646650 7052static void
856ca177
MS
7053damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
7054 int display, safi_t safi, u_char use_json, json_object *json)
718e3744 7055{
7056 struct attr *attr;
718e3744 7057 int len;
50aef6f3 7058 char timebuf[BGP_UPTIME_LEN];
718e3744 7059
b40d939b 7060 /* short status lead text */
856ca177 7061 route_vty_short_status_out (vty, binfo, json);
b40d939b 7062
718e3744 7063 /* print prefix and mask */
856ca177
MS
7064 if (!use_json)
7065 {
7066 if (! display)
7067 route_vty_out_route (p, vty);
7068 else
7069 vty_out (vty, "%*s", 17, " ");
7070 }
718e3744 7071
7072 len = vty_out (vty, "%s", binfo->peer->host);
7073 len = 17 - len;
7074 if (len < 1)
856ca177
MS
7075 {
7076 if (!use_json)
7077 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
7078 }
718e3744 7079 else
856ca177
MS
7080 {
7081 if (use_json)
7082 json_object_int_add(json, "peerHost", len);
7083 else
7084 vty_out (vty, "%*s", len, " ");
7085 }
718e3744 7086
856ca177
MS
7087 if (use_json)
7088 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
7089 else
7090 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
718e3744 7091
7092 /* Print attribute */
7093 attr = binfo->attr;
7094 if (attr)
7095 {
7096 /* Print aspath */
7097 if (attr->aspath)
856ca177
MS
7098 {
7099 if (use_json)
7100 json_object_string_add(json, "asPath", attr->aspath->str);
7101 else
7102 aspath_print_vty (vty, "%s", attr->aspath, " ");
7103 }
718e3744 7104
7105 /* Print origin */
856ca177
MS
7106 if (use_json)
7107 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
7108 else
7109 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 7110 }
856ca177
MS
7111 if (!use_json)
7112 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7113}
7114
718e3744 7115/* flap route */
5a646650 7116static void
856ca177
MS
7117flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
7118 int display, safi_t safi, u_char use_json, json_object *json)
718e3744 7119{
7120 struct attr *attr;
7121 struct bgp_damp_info *bdi;
718e3744 7122 char timebuf[BGP_UPTIME_LEN];
7123 int len;
fb982c25
PJ
7124
7125 if (!binfo->extra)
7126 return;
7127
7128 bdi = binfo->extra->damp_info;
718e3744 7129
b40d939b 7130 /* short status lead text */
856ca177 7131 route_vty_short_status_out (vty, binfo, json);
b40d939b 7132
718e3744 7133 /* print prefix and mask */
856ca177
MS
7134 if (!use_json)
7135 {
7136 if (! display)
7137 route_vty_out_route (p, vty);
7138 else
7139 vty_out (vty, "%*s", 17, " ");
7140 }
718e3744 7141
7142 len = vty_out (vty, "%s", binfo->peer->host);
7143 len = 16 - len;
7144 if (len < 1)
856ca177
MS
7145 {
7146 if (!use_json)
7147 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
7148 }
718e3744 7149 else
856ca177
MS
7150 {
7151 if (use_json)
7152 json_object_int_add(json, "peerHost", len);
7153 else
7154 vty_out (vty, "%*s", len, " ");
7155 }
718e3744 7156
7157 len = vty_out (vty, "%d", bdi->flap);
7158 len = 5 - len;
7159 if (len < 1)
856ca177
MS
7160 {
7161 if (!use_json)
7162 vty_out (vty, " ");
7163 }
718e3744 7164 else
856ca177
MS
7165 {
7166 if (use_json)
7167 json_object_int_add(json, "bdiFlap", len);
7168 else
7169 vty_out (vty, "%*s", len, " ");
7170 }
7171
7172 if (use_json)
7173 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json);
7174 else
7175 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
7176 timebuf, BGP_UPTIME_LEN, 0, NULL));
718e3744 7177
7178 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
7179 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
856ca177
MS
7180 {
7181 if (use_json)
7182 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
7183 else
7184 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
7185 }
718e3744 7186 else
856ca177
MS
7187 {
7188 if (!use_json)
7189 vty_out (vty, "%*s ", 8, " ");
7190 }
718e3744 7191
7192 /* Print attribute */
7193 attr = binfo->attr;
7194 if (attr)
7195 {
7196 /* Print aspath */
7197 if (attr->aspath)
856ca177
MS
7198 {
7199 if (use_json)
7200 json_object_string_add(json, "asPath", attr->aspath->str);
7201 else
7202 aspath_print_vty (vty, "%s", attr->aspath, " ");
7203 }
718e3744 7204
7205 /* Print origin */
856ca177
MS
7206 if (use_json)
7207 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
7208 else
7209 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 7210 }
856ca177
MS
7211 if (!use_json)
7212 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7213}
7214
94f2b392 7215static void
718e3744 7216route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
b05a1c8b
DS
7217 struct bgp_info *binfo, afi_t afi, safi_t safi,
7218 json_object *json_paths)
718e3744 7219{
7220 char buf[INET6_ADDRSTRLEN];
7221 char buf1[BUFSIZ];
7222 struct attr *attr;
7223 int sockunion_vty_out (struct vty *, union sockunion *);
30b00176
JK
7224#ifdef HAVE_CLOCK_MONOTONIC
7225 time_t tbuf;
7226#endif
f1aa5d8a 7227 json_object *json_bestpath = NULL;
ffd0c037 7228 json_object *json_cluster_list = NULL;
f1aa5d8a
DS
7229 json_object *json_cluster_list_list = NULL;
7230 json_object *json_ext_community = NULL;
7231 json_object *json_last_update = NULL;
7232 json_object *json_nexthop_global = NULL;
7233 json_object *json_nexthop_ll = NULL;
7234 json_object *json_nexthops = NULL;
7235 json_object *json_path = NULL;
7236 json_object *json_peer = NULL;
7237 json_object *json_string = NULL;
b05a1c8b
DS
7238
7239 if (json_paths)
7240 {
7241 json_path = json_object_new_object();
f1aa5d8a
DS
7242 json_peer = json_object_new_object();
7243 json_nexthop_global = json_object_new_object();
b05a1c8b
DS
7244 }
7245
718e3744 7246 attr = binfo->attr;
7247
7248 if (attr)
7249 {
7250 /* Line1 display AS-path, Aggregator */
7251 if (attr->aspath)
7252 {
f1aa5d8a
DS
7253 if (json_paths)
7254 {
7255 json_object_lock(attr->aspath->json);
7256 json_object_object_add(json_path, "aspath", attr->aspath->json);
7257 }
7258 else
b05a1c8b 7259 {
f1aa5d8a
DS
7260 if (attr->aspath->segments)
7261 aspath_print_vty (vty, " %s", attr->aspath, "");
b05a1c8b 7262 else
f1aa5d8a 7263 vty_out (vty, " Local");
b05a1c8b 7264 }
718e3744 7265 }
7266
b40d939b 7267 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
b05a1c8b
DS
7268 {
7269 if (json_paths)
f1aa5d8a 7270 json_object_boolean_true_add(json_path, "removed");
b05a1c8b
DS
7271 else
7272 vty_out (vty, ", (removed)");
7273 }
7274
93406d87 7275 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
b05a1c8b
DS
7276 {
7277 if (json_paths)
f1aa5d8a 7278 json_object_boolean_true_add(json_path, "stale");
b05a1c8b
DS
7279 else
7280 vty_out (vty, ", (stale)");
7281 }
7282
93406d87 7283 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
b05a1c8b
DS
7284 {
7285 if (json_paths)
7286 {
62d6dca0
DS
7287 json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as);
7288 json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr));
b05a1c8b
DS
7289 }
7290 else
7291 {
7292 vty_out (vty, ", (aggregated by %u %s)",
7293 attr->extra->aggregator_as,
7294 inet_ntoa (attr->extra->aggregator_addr));
7295 }
7296 }
7297
93406d87 7298 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
b05a1c8b
DS
7299 {
7300 if (json_paths)
62d6dca0 7301 json_object_boolean_true_add(json_path, "rxedFromRrClient");
b05a1c8b
DS
7302 else
7303 vty_out (vty, ", (Received from a RR-client)");
7304 }
7305
93406d87 7306 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
b05a1c8b
DS
7307 {
7308 if (json_paths)
62d6dca0 7309 json_object_boolean_true_add(json_path, "rxedFromRsClient");
b05a1c8b
DS
7310 else
7311 vty_out (vty, ", (Received from a RS-client)");
7312 }
7313
93406d87 7314 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
7315 {
7316 if (json_paths)
62d6dca0 7317 json_object_boolean_true_add(json_path, "dampeningHistoryEntry");
b05a1c8b
DS
7318 else
7319 vty_out (vty, ", (history entry)");
7320 }
93406d87 7321 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
b05a1c8b
DS
7322 {
7323 if (json_paths)
62d6dca0 7324 json_object_boolean_true_add(json_path, "dampeningSuppressed");
b05a1c8b
DS
7325 else
7326 vty_out (vty, ", (suppressed due to dampening)");
7327 }
7328
7329 if (!json_paths)
7330 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7331
7332 /* Line2 display Next-hop, Neighbor, Router-id */
f1aa5d8a 7333 /* Display the nexthop */
8a92a8a0
DS
7334 if (p->family == AF_INET
7335 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 7336 {
b05a1c8b
DS
7337 if (safi == SAFI_MPLS_VPN)
7338 {
7339 if (json_paths)
f1aa5d8a 7340 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
b05a1c8b
DS
7341 else
7342 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
7343 }
7344 else
7345 {
7346 if (json_paths)
f1aa5d8a 7347 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
b05a1c8b
DS
7348 else
7349 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
7350 }
7351
7352 if (json_paths)
f1aa5d8a 7353 json_object_string_add(json_nexthop_global, "afi", "ipv4");
718e3744 7354 }
7355#ifdef HAVE_IPV6
7356 else
7357 {
fb982c25 7358 assert (attr->extra);
b05a1c8b
DS
7359 if (json_paths)
7360 {
f1aa5d8a
DS
7361 json_object_string_add(json_nexthop_global, "ip",
7362 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7363 buf, INET6_ADDRSTRLEN));
7364 json_object_string_add(json_nexthop_global, "afi", "ipv6");
7365 json_object_string_add(json_nexthop_global, "scope", "global");
b05a1c8b
DS
7366 }
7367 else
7368 {
7369 vty_out (vty, " %s",
7370 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7371 buf, INET6_ADDRSTRLEN));
7372 }
718e3744 7373 }
7374#endif /* HAVE_IPV6 */
7375
b05a1c8b 7376
f1aa5d8a
DS
7377 /* Display the IGP cost or 'inaccessible' */
7378 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
7379 {
7380 if (json_paths)
7381 json_object_boolean_false_add(json_nexthop_global, "accessible");
7382 else
7383 vty_out (vty, " (inaccessible)");
7384 }
7385 else
7386 {
7387 if (binfo->extra && binfo->extra->igpmetric)
b05a1c8b
DS
7388 {
7389 if (json_paths)
f1aa5d8a 7390 json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric);
b05a1c8b 7391 else
f1aa5d8a 7392 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
b05a1c8b 7393 }
f1aa5d8a
DS
7394
7395 /* IGP cost is 0, display this only for json */
b05a1c8b
DS
7396 else
7397 {
7398 if (json_paths)
f1aa5d8a 7399 json_object_int_add(json_nexthop_global, "metric", 0);
b05a1c8b
DS
7400 }
7401
7402 if (json_paths)
f1aa5d8a
DS
7403 json_object_boolean_true_add(json_nexthop_global, "accessible");
7404 }
7405
7406 /* Display peer "from" output */
7407 /* This path was originated locally */
7408 if (binfo->peer == bgp->peer_self)
718e3744 7409 {
f1aa5d8a
DS
7410
7411 if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
b05a1c8b
DS
7412 {
7413 if (json_paths)
62d6dca0 7414 json_object_string_add(json_peer, "peerId", "0.0.0.0");
b05a1c8b 7415 else
f1aa5d8a 7416 vty_out (vty, " from 0.0.0.0 ");
b05a1c8b 7417 }
f1aa5d8a 7418 else
b05a1c8b
DS
7419 {
7420 if (json_paths)
62d6dca0 7421 json_object_string_add(json_peer, "peerId", "::");
b05a1c8b 7422 else
f1aa5d8a 7423 vty_out (vty, " from :: ");
b05a1c8b
DS
7424 }
7425
f1aa5d8a 7426 if (json_paths)
62d6dca0 7427 json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id));
b05a1c8b 7428 else
f1aa5d8a
DS
7429 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
7430 }
7431
7432 /* We RXed this path from one of our peers */
7433 else
7434 {
b05a1c8b
DS
7435
7436 if (json_paths)
7437 {
62d6dca0
DS
7438 json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7439 json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
f1aa5d8a 7440
04b6bdc0
DW
7441 if (binfo->peer->hostname)
7442 json_object_string_add(json_peer, "hostname", binfo->peer->hostname);
7443
7444 if (binfo->peer->domainname)
7445 json_object_string_add(json_peer, "domainname", binfo->peer->domainname);
7446
036a4e7d 7447 if (binfo->peer->conf_if)
f1aa5d8a 7448 json_object_string_add(json_peer, "interface", binfo->peer->conf_if);
b05a1c8b
DS
7449 }
7450 else
7451 {
036a4e7d 7452 if (binfo->peer->conf_if)
04b6bdc0
DW
7453 {
7454 if (binfo->peer->hostname &&
7455 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7456 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7457 binfo->peer->conf_if);
7458 else
7459 vty_out (vty, " from %s", binfo->peer->conf_if);
7460 }
036a4e7d 7461 else
04b6bdc0
DW
7462 {
7463 if (binfo->peer->hostname &&
7464 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7465 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7466 binfo->peer->host);
7467 else
7468 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7469 }
b05a1c8b 7470
f1aa5d8a
DS
7471 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7472 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
7473 else
7474 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
b05a1c8b 7475 }
718e3744 7476 }
b05a1c8b
DS
7477
7478 if (!json_paths)
7479 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7480
7481#ifdef HAVE_IPV6
f1aa5d8a 7482 /* display the link-local nexthop */
801a9bcc 7483 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
718e3744 7484 {
b05a1c8b
DS
7485 if (json_paths)
7486 {
f1aa5d8a
DS
7487 json_nexthop_ll = json_object_new_object();
7488 json_object_string_add(json_nexthop_ll, "ip",
7489 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7490 buf, INET6_ADDRSTRLEN));
7491 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
7492 json_object_string_add(json_nexthop_ll, "scope", "link-local");
7493
7494 json_object_boolean_true_add(json_nexthop_ll, "accessible");
7495 json_object_boolean_true_add(json_nexthop_ll, "used");
b05a1c8b
DS
7496 }
7497 else
7498 {
356b3294 7499 vty_out (vty, " (%s) (used)%s",
b05a1c8b
DS
7500 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7501 buf, INET6_ADDRSTRLEN),
7502 VTY_NEWLINE);
7503 }
718e3744 7504 }
f1aa5d8a
DS
7505 /* If we do not have a link-local nexthop then we must flag the global as "used" */
7506 else
7507 {
7508 if (json_paths)
7509 json_object_boolean_true_add(json_nexthop_global, "used");
7510 }
718e3744 7511#endif /* HAVE_IPV6 */
7512
0d9551dc 7513 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
b05a1c8b 7514 if (json_paths)
f1aa5d8a 7515 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
b05a1c8b 7516 else
f1aa5d8a 7517 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
718e3744 7518
7519 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b
DS
7520 {
7521 if (json_paths)
f1aa5d8a 7522 json_object_int_add(json_path, "med", attr->med);
b05a1c8b 7523 else
f1aa5d8a 7524 vty_out (vty, ", metric %u", attr->med);
b05a1c8b 7525 }
718e3744 7526
7527 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
b05a1c8b
DS
7528 {
7529 if (json_paths)
f1aa5d8a 7530 json_object_int_add(json_path, "localpref", attr->local_pref);
b05a1c8b 7531 else
f1aa5d8a 7532 vty_out (vty, ", localpref %u", attr->local_pref);
b05a1c8b 7533 }
718e3744 7534 else
b05a1c8b
DS
7535 {
7536 if (json_paths)
f1aa5d8a 7537 json_object_int_add(json_path, "localpref", bgp->default_local_pref);
b05a1c8b 7538 else
f1aa5d8a 7539 vty_out (vty, ", localpref %u", bgp->default_local_pref);
b05a1c8b 7540 }
718e3744 7541
fb982c25 7542 if (attr->extra && attr->extra->weight != 0)
b05a1c8b
DS
7543 {
7544 if (json_paths)
f1aa5d8a 7545 json_object_int_add(json_path, "weight", attr->extra->weight);
b05a1c8b 7546 else
f1aa5d8a 7547 vty_out (vty, ", weight %u", attr->extra->weight);
b05a1c8b 7548 }
0d9551dc
DS
7549
7550 if (attr->extra && attr->extra->tag != 0)
b05a1c8b
DS
7551 {
7552 if (json_paths)
f1aa5d8a 7553 json_object_int_add(json_path, "tag", attr->extra->tag);
b05a1c8b 7554 else
f1aa5d8a 7555 vty_out (vty, ", tag %d", attr->extra->tag);
b05a1c8b 7556 }
718e3744 7557
31eba040 7558 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
b05a1c8b
DS
7559 {
7560 if (json_paths)
f1aa5d8a 7561 json_object_boolean_false_add(json_path, "valid");
b05a1c8b
DS
7562 else
7563 vty_out (vty, ", invalid");
7564 }
31eba040 7565 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
7566 {
7567 if (json_paths)
f1aa5d8a 7568 json_object_boolean_true_add(json_path, "valid");
b05a1c8b
DS
7569 else
7570 vty_out (vty, ", valid");
7571 }
718e3744 7572
7573 if (binfo->peer != bgp->peer_self)
7574 {
f1aa5d8a 7575 if (binfo->peer->as == binfo->peer->local_as)
b05a1c8b 7576 {
66b199b2
DS
7577 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7578 {
7579 if (json_paths)
f1aa5d8a 7580 json_object_string_add(json_peer, "type", "confed-internal");
66b199b2 7581 else
f1aa5d8a 7582 vty_out (vty, ", confed-internal");
66b199b2 7583 }
b05a1c8b 7584 else
66b199b2
DS
7585 {
7586 if (json_paths)
f1aa5d8a 7587 json_object_string_add(json_peer, "type", "internal");
66b199b2 7588 else
f1aa5d8a 7589 vty_out (vty, ", internal");
66b199b2 7590 }
b05a1c8b 7591 }
f1aa5d8a 7592 else
b05a1c8b
DS
7593 {
7594 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
7595 {
7596 if (json_paths)
f1aa5d8a 7597 json_object_string_add(json_peer, "type", "confed-external");
b05a1c8b 7598 else
f1aa5d8a 7599 vty_out (vty, ", confed-external");
b05a1c8b
DS
7600 }
7601 else
7602 {
7603 if (json_paths)
f1aa5d8a 7604 json_object_string_add(json_peer, "type", "external");
b05a1c8b 7605 else
f1aa5d8a 7606 vty_out (vty, ", external");
b05a1c8b
DS
7607 }
7608 }
718e3744 7609 }
7610 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
b05a1c8b
DS
7611 {
7612 if (json_paths)
7613 {
f1aa5d8a
DS
7614 json_object_boolean_true_add(json_path, "aggregated");
7615 json_object_boolean_true_add(json_path, "local");
b05a1c8b
DS
7616 }
7617 else
7618 {
7619 vty_out (vty, ", aggregated, local");
7620 }
7621 }
718e3744 7622 else if (binfo->type != ZEBRA_ROUTE_BGP)
b05a1c8b
DS
7623 {
7624 if (json_paths)
f1aa5d8a 7625 json_object_boolean_true_add(json_path, "sourced");
b05a1c8b
DS
7626 else
7627 vty_out (vty, ", sourced");
7628 }
718e3744 7629 else
b05a1c8b
DS
7630 {
7631 if (json_paths)
7632 {
f1aa5d8a
DS
7633 json_object_boolean_true_add(json_path, "sourced");
7634 json_object_boolean_true_add(json_path, "local");
b05a1c8b
DS
7635 }
7636 else
7637 {
7638 vty_out (vty, ", sourced, local");
7639 }
7640 }
718e3744 7641
7642 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
b05a1c8b
DS
7643 {
7644 if (json_paths)
62d6dca0 7645 json_object_boolean_true_add(json_path, "atomicAggregate");
b05a1c8b
DS
7646 else
7647 vty_out (vty, ", atomic-aggregate");
7648 }
718e3744 7649
de8d5dff
JB
7650 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
7651 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
7652 bgp_info_mpath_count (binfo)))
b05a1c8b
DS
7653 {
7654 if (json_paths)
f1aa5d8a 7655 json_object_boolean_true_add(json_path, "multipath");
b05a1c8b
DS
7656 else
7657 vty_out (vty, ", multipath");
7658 }
de8d5dff 7659
718e3744 7660 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
b05a1c8b
DS
7661 {
7662 if (json_paths)
f1aa5d8a
DS
7663 {
7664 json_bestpath = json_object_new_object();
7665 json_object_boolean_true_add(json_bestpath, "overall");
7666 json_object_object_add(json_path, "bestpath", json_bestpath);
7667 }
b05a1c8b
DS
7668 else
7669 vty_out (vty, ", best");
7670 }
718e3744 7671
b05a1c8b
DS
7672 if (!json_paths)
7673 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7674
7675 /* Line 4 display Community */
7676 if (attr->community)
b05a1c8b
DS
7677 {
7678 if (json_paths)
7679 {
f1aa5d8a
DS
7680 json_object_lock(attr->community->json);
7681 json_object_object_add(json_path, "community", attr->community->json);
b05a1c8b
DS
7682 }
7683 else
7684 {
7685 vty_out (vty, " Community: %s%s", attr->community->str,
7686 VTY_NEWLINE);
7687 }
7688 }
718e3744 7689
7690 /* Line 5 display Extended-community */
7691 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
b05a1c8b
DS
7692 {
7693 if (json_paths)
7694 {
f1aa5d8a
DS
7695 json_ext_community = json_object_new_object();
7696 json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str);
62d6dca0 7697 json_object_object_add(json_path, "extendedCommunity", json_ext_community);
b05a1c8b
DS
7698 }
7699 else
7700 {
7701 vty_out (vty, " Extended Community: %s%s",
7702 attr->extra->ecommunity->str, VTY_NEWLINE);
7703 }
7704 }
7705
718e3744 7706 /* Line 6 display Originator, Cluster-id */
7707 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
7708 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
7709 {
fb982c25 7710 assert (attr->extra);
718e3744 7711 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
b05a1c8b
DS
7712 {
7713 if (json_paths)
62d6dca0 7714 json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id));
b05a1c8b 7715 else
f1aa5d8a
DS
7716 vty_out (vty, " Originator: %s",
7717 inet_ntoa (attr->extra->originator_id));
b05a1c8b 7718 }
718e3744 7719
7720 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
7721 {
7722 int i;
b05a1c8b
DS
7723
7724 if (json_paths)
7725 {
f1aa5d8a
DS
7726 json_cluster_list = json_object_new_object();
7727 json_cluster_list_list = json_object_new_array();
7728
b05a1c8b
DS
7729 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7730 {
7731 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
f1aa5d8a 7732 json_object_array_add(json_cluster_list_list, json_string);
b05a1c8b 7733 }
f1aa5d8a
DS
7734
7735 /* struct cluster_list does not have "str" variable like
7736 * aspath and community do. Add this someday if someone
7737 * asks for it.
7738 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
7739 */
7740 json_object_object_add(json_cluster_list, "list", json_cluster_list_list);
62d6dca0 7741 json_object_object_add(json_path, "clusterList", json_cluster_list);
b05a1c8b
DS
7742 }
7743 else
7744 {
7745 vty_out (vty, ", Cluster list: ");
7746
7747 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7748 {
7749 vty_out (vty, "%s ",
7750 inet_ntoa (attr->extra->cluster->list[i]));
7751 }
7752 }
718e3744 7753 }
b05a1c8b
DS
7754
7755 if (!json_paths)
7756 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7757 }
b05a1c8b 7758
fb982c25 7759 if (binfo->extra && binfo->extra->damp_info)
b05a1c8b 7760 bgp_damp_info_vty (vty, binfo, json_path);
718e3744 7761
a82478b9
DS
7762 /* Line 7 display Addpath IDs */
7763 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
b05a1c8b
DS
7764 {
7765 if (json_paths)
7766 {
62d6dca0
DS
7767 json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id);
7768 json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id);
b05a1c8b
DS
7769 }
7770 else
7771 {
7772 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
7773 binfo->addpath_rx_id, binfo->addpath_tx_id,
7774 VTY_NEWLINE);
7775 }
7776 }
a82478b9
DS
7777
7778 /* Line 8 display Uptime */
30b00176
JK
7779#ifdef HAVE_CLOCK_MONOTONIC
7780 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
b05a1c8b 7781 if (json_paths)
f1aa5d8a
DS
7782 {
7783 json_last_update = json_object_new_object();
7784 json_object_int_add(json_last_update, "epoch", tbuf);
7785 json_object_string_add(json_last_update, "string", ctime(&tbuf));
62d6dca0 7786 json_object_object_add(json_path, "lastUpdate", json_last_update);
f1aa5d8a 7787 }
b05a1c8b
DS
7788 else
7789 vty_out (vty, " Last update: %s", ctime(&tbuf));
30b00176 7790#else
b05a1c8b 7791 if (json_paths)
f1aa5d8a
DS
7792 {
7793 json_last_update = json_object_new_object();
7794 json_object_int_add(json_last_update, "epoch", tbuf);
7795 json_object_string_add(json_last_update, "string", ctime(&binfo->uptime));
62d6dca0 7796 json_object_object_add(json_path, "lastUpdate", json_last_update);
f1aa5d8a 7797 }
b05a1c8b
DS
7798 else
7799 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
30b00176 7800#endif /* HAVE_CLOCK_MONOTONIC */
718e3744 7801 }
b05a1c8b
DS
7802
7803 /* We've constructed the json object for this path, add it to the json
7804 * array of paths
7805 */
7806 if (json_paths)
f1aa5d8a
DS
7807 {
7808 if (json_nexthop_global || json_nexthop_ll)
7809 {
7810 json_nexthops = json_object_new_array();
7811
7812 if (json_nexthop_global)
7813 json_object_array_add(json_nexthops, json_nexthop_global);
7814
7815 if (json_nexthop_ll)
7816 json_object_array_add(json_nexthops, json_nexthop_ll);
7817
7818 json_object_object_add(json_path, "nexthops", json_nexthops);
7819 }
7820
7821 json_object_object_add(json_path, "peer", json_peer);
7822 json_object_array_add(json_paths, json_path);
7823 }
b05a1c8b
DS
7824 else
7825 vty_out (vty, "%s", VTY_NEWLINE);
b366b518
BB
7826}
7827
47fc97cc 7828#define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
718e3744 7829#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7830#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7831
7832enum bgp_show_type
7833{
7834 bgp_show_type_normal,
7835 bgp_show_type_regexp,
7836 bgp_show_type_prefix_list,
7837 bgp_show_type_filter_list,
7838 bgp_show_type_route_map,
7839 bgp_show_type_neighbor,
7840 bgp_show_type_cidr_only,
7841 bgp_show_type_prefix_longer,
7842 bgp_show_type_community_all,
7843 bgp_show_type_community,
7844 bgp_show_type_community_exact,
7845 bgp_show_type_community_list,
7846 bgp_show_type_community_list_exact,
7847 bgp_show_type_flap_statistics,
7848 bgp_show_type_flap_address,
7849 bgp_show_type_flap_prefix,
7850 bgp_show_type_flap_cidr_only,
7851 bgp_show_type_flap_regexp,
7852 bgp_show_type_flap_filter_list,
7853 bgp_show_type_flap_prefix_list,
7854 bgp_show_type_flap_prefix_longer,
7855 bgp_show_type_flap_route_map,
7856 bgp_show_type_flap_neighbor,
7857 bgp_show_type_dampend_paths,
7858 bgp_show_type_damp_neighbor
7859};
7860
5a646650 7861static int
fee0f4c6 7862bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
856ca177 7863 enum bgp_show_type type, void *output_arg, u_char use_json)
718e3744 7864{
718e3744 7865 struct bgp_info *ri;
7866 struct bgp_node *rn;
718e3744 7867 int header = 1;
718e3744 7868 int display;
5a646650 7869 unsigned long output_count;
b05a1c8b
DS
7870 struct prefix *p;
7871 char buf[BUFSIZ];
7872 char buf2[BUFSIZ];
f1aa5d8a
DS
7873 json_object *json = NULL;
7874 json_object *json_paths = NULL;
7875 json_object *json_routes = NULL;
b05a1c8b
DS
7876
7877 if (use_json)
7878 {
7879 json = json_object_new_object();
62d6dca0
DS
7880 json_object_int_add(json, "tableVersion", table->version);
7881 json_object_string_add(json, "routerId", inet_ntoa (*router_id));
b05a1c8b
DS
7882 json_routes = json_object_new_object();
7883 }
718e3744 7884
7885 /* This is first entry point, so reset total line. */
5a646650 7886 output_count = 0;
718e3744 7887
718e3744 7888 /* Start processing of routes. */
7889 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7890 if (rn->info != NULL)
7891 {
856ca177 7892 display = 0;
718e3744 7893
b05a1c8b
DS
7894 if (use_json)
7895 json_paths = json_object_new_array();
7896 else
7897 json_paths = NULL;
7898
856ca177
MS
7899 for (ri = rn->info; ri; ri = ri->next)
7900 {
7901 if (type == bgp_show_type_flap_statistics
7902 || type == bgp_show_type_flap_address
7903 || type == bgp_show_type_flap_prefix
7904 || type == bgp_show_type_flap_cidr_only
7905 || type == bgp_show_type_flap_regexp
7906 || type == bgp_show_type_flap_filter_list
7907 || type == bgp_show_type_flap_prefix_list
7908 || type == bgp_show_type_flap_prefix_longer
7909 || type == bgp_show_type_flap_route_map
7910 || type == bgp_show_type_flap_neighbor
7911 || type == bgp_show_type_dampend_paths
7912 || type == bgp_show_type_damp_neighbor)
7913 {
7914 if (!(ri->extra && ri->extra->damp_info))
7915 continue;
7916 }
7917 if (type == bgp_show_type_regexp
7918 || type == bgp_show_type_flap_regexp)
7919 {
7920 regex_t *regex = output_arg;
718e3744 7921
856ca177
MS
7922 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7923 continue;
7924 }
7925 if (type == bgp_show_type_prefix_list
7926 || type == bgp_show_type_flap_prefix_list)
7927 {
7928 struct prefix_list *plist = output_arg;
718e3744 7929
856ca177
MS
7930 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7931 continue;
7932 }
7933 if (type == bgp_show_type_filter_list
7934 || type == bgp_show_type_flap_filter_list)
7935 {
7936 struct as_list *as_list = output_arg;
558d1fec 7937
856ca177
MS
7938 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7939 continue;
7940 }
7941 if (type == bgp_show_type_route_map
7942 || type == bgp_show_type_flap_route_map)
7943 {
7944 struct route_map *rmap = output_arg;
7945 struct bgp_info binfo;
7946 struct attr dummy_attr;
7947 struct attr_extra dummy_extra;
7948 int ret;
718e3744 7949
856ca177
MS
7950 dummy_attr.extra = &dummy_extra;
7951 bgp_attr_dup (&dummy_attr, ri->attr);
718e3744 7952
856ca177
MS
7953 binfo.peer = ri->peer;
7954 binfo.attr = &dummy_attr;
718e3744 7955
856ca177
MS
7956 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
7957 if (ret == RMAP_DENYMATCH)
7958 continue;
7959 }
7960 if (type == bgp_show_type_neighbor
7961 || type == bgp_show_type_flap_neighbor
7962 || type == bgp_show_type_damp_neighbor)
7963 {
7964 union sockunion *su = output_arg;
718e3744 7965
856ca177
MS
7966 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7967 continue;
7968 }
7969 if (type == bgp_show_type_cidr_only
7970 || type == bgp_show_type_flap_cidr_only)
7971 {
7972 u_int32_t destination;
718e3744 7973
856ca177
MS
7974 destination = ntohl (rn->p.u.prefix4.s_addr);
7975 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7976 continue;
7977 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7978 continue;
7979 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7980 continue;
7981 }
7982 if (type == bgp_show_type_prefix_longer
7983 || type == bgp_show_type_flap_prefix_longer)
7984 {
7985 struct prefix *p = output_arg;
718e3744 7986
856ca177
MS
7987 if (! prefix_match (p, &rn->p))
7988 continue;
7989 }
7990 if (type == bgp_show_type_community_all)
7991 {
7992 if (! ri->attr->community)
7993 continue;
7994 }
7995 if (type == bgp_show_type_community)
7996 {
7997 struct community *com = output_arg;
718e3744 7998
856ca177
MS
7999 if (! ri->attr->community ||
8000 ! community_match (ri->attr->community, com))
8001 continue;
8002 }
8003 if (type == bgp_show_type_community_exact)
8004 {
8005 struct community *com = output_arg;
718e3744 8006
856ca177
MS
8007 if (! ri->attr->community ||
8008 ! community_cmp (ri->attr->community, com))
8009 continue;
8010 }
8011 if (type == bgp_show_type_community_list)
8012 {
8013 struct community_list *list = output_arg;
718e3744 8014
856ca177
MS
8015 if (! community_list_match (ri->attr->community, list))
8016 continue;
8017 }
8018 if (type == bgp_show_type_community_list_exact)
8019 {
8020 struct community_list *list = output_arg;
718e3744 8021
856ca177
MS
8022 if (! community_list_exact_match (ri->attr->community, list))
8023 continue;
8024 }
8025 if (type == bgp_show_type_flap_address
8026 || type == bgp_show_type_flap_prefix)
8027 {
8028 struct prefix *p = output_arg;
718e3744 8029
856ca177
MS
8030 if (! prefix_match (&rn->p, p))
8031 continue;
b05a1c8b 8032
856ca177
MS
8033 if (type == bgp_show_type_flap_prefix)
8034 if (p->prefixlen != rn->p.prefixlen)
8035 continue;
8036 }
8037 if (type == bgp_show_type_dampend_paths
8038 || type == bgp_show_type_damp_neighbor)
8039 {
8040 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
8041 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
8042 continue;
8043 }
8044
8045 if (!use_json && header)
8046 {
8047 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (*router_id), VTY_NEWLINE);
8048 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8049 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8050 if (type == bgp_show_type_dampend_paths
8051 || type == bgp_show_type_damp_neighbor)
8052 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
8053 else if (type == bgp_show_type_flap_statistics
8054 || type == bgp_show_type_flap_address
8055 || type == bgp_show_type_flap_prefix
8056 || type == bgp_show_type_flap_cidr_only
8057 || type == bgp_show_type_flap_regexp
8058 || type == bgp_show_type_flap_filter_list
8059 || type == bgp_show_type_flap_prefix_list
8060 || type == bgp_show_type_flap_prefix_longer
8061 || type == bgp_show_type_flap_route_map
8062 || type == bgp_show_type_flap_neighbor)
8063 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
8064 else
8065 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8066 header = 0;
8067 }
8068
8069 if (type == bgp_show_type_dampend_paths
8070 || type == bgp_show_type_damp_neighbor)
8071 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
8072 else if (type == bgp_show_type_flap_statistics
8073 || type == bgp_show_type_flap_address
8074 || type == bgp_show_type_flap_prefix
8075 || type == bgp_show_type_flap_cidr_only
8076 || type == bgp_show_type_flap_regexp
8077 || type == bgp_show_type_flap_filter_list
8078 || type == bgp_show_type_flap_prefix_list
8079 || type == bgp_show_type_flap_prefix_longer
8080 || type == bgp_show_type_flap_route_map
8081 || type == bgp_show_type_flap_neighbor)
8082 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
8083 else
8084 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
8085 display++;
b05a1c8b
DS
8086 }
8087
856ca177
MS
8088 if (display)
8089 {
8090 output_count++;
8091 if (use_json)
8092 {
8093 p = &rn->p;
8094 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
8095 json_object_object_add(json_routes, buf2, json_paths);
8096 }
8097 }
718e3744 8098 }
8099
b05a1c8b 8100 if (use_json)
718e3744 8101 {
d1d16a96 8102 json_object_object_add(json, "routes", json_routes);
b05a1c8b 8103 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
f1aa5d8a 8104 json_object_free(json);
718e3744 8105 }
8106 else
b05a1c8b
DS
8107 {
8108 /* No route is displayed */
8109 if (output_count == 0)
8110 {
8111 if (type == bgp_show_type_normal)
856ca177 8112 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
b05a1c8b
DS
8113 }
8114 else
8115 vty_out (vty, "%sTotal number of prefixes %ld%s",
856ca177 8116 VTY_NEWLINE, output_count, VTY_NEWLINE);
b05a1c8b 8117 }
718e3744 8118
8119 return CMD_SUCCESS;
8120}
8121
5a646650 8122static int
fee0f4c6 8123bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
856ca177 8124 enum bgp_show_type type, void *output_arg, u_char use_json)
fee0f4c6 8125{
8126 struct bgp_table *table;
8127
856ca177
MS
8128 if (bgp == NULL)
8129 {
8130 bgp = bgp_get_default ();
8131 }
fee0f4c6 8132
8133 if (bgp == NULL)
8134 {
856ca177
MS
8135 if (!use_json)
8136 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
fee0f4c6 8137 return CMD_WARNING;
8138 }
8139
fee0f4c6 8140 table = bgp->rib[afi][safi];
8141
b05a1c8b 8142 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg, use_json);
fee0f4c6 8143}
8144
718e3744 8145/* Header of detailed BGP route information */
94f2b392 8146static void
718e3744 8147route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
8148 struct bgp_node *rn,
b05a1c8b
DS
8149 struct prefix_rd *prd, afi_t afi, safi_t safi,
8150 json_object *json)
718e3744 8151{
8152 struct bgp_info *ri;
8153 struct prefix *p;
8154 struct peer *peer;
1eb8ef25 8155 struct listnode *node, *nnode;
718e3744 8156 char buf1[INET6_ADDRSTRLEN];
8157 char buf2[INET6_ADDRSTRLEN];
8158 int count = 0;
8159 int best = 0;
8160 int suppress = 0;
8161 int no_export = 0;
8162 int no_advertise = 0;
8163 int local_as = 0;
8164 int first = 0;
ffd0c037 8165 json_object *json_adv_to = NULL;
f1aa5d8a 8166 json_object *json_peer = NULL;
718e3744 8167
8168 p = &rn->p;
b05a1c8b
DS
8169
8170 if (json)
8171 {
f1aa5d8a
DS
8172 json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
8173 json_object_int_add(json, "prefixlen", p->prefixlen);
b05a1c8b
DS
8174 }
8175 else
8176 {
8177 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
8178 (safi == SAFI_MPLS_VPN ?
8179 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
8180 safi == SAFI_MPLS_VPN ? ":" : "",
8181 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
8182 p->prefixlen, VTY_NEWLINE);
8183 }
718e3744 8184
8185 for (ri = rn->info; ri; ri = ri->next)
8186 {
8187 count++;
8188 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
8189 {
8190 best = count;
fb982c25 8191 if (ri->extra && ri->extra->suppress)
718e3744 8192 suppress = 1;
8193 if (ri->attr->community != NULL)
8194 {
8195 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
8196 no_advertise = 1;
8197 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
8198 no_export = 1;
8199 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
8200 local_as = 1;
8201 }
8202 }
8203 }
8204
b05a1c8b 8205 if (!json)
718e3744 8206 {
b05a1c8b
DS
8207 vty_out (vty, "Paths: (%d available", count);
8208 if (best)
8209 {
8210 vty_out (vty, ", best #%d", best);
8211 if (safi == SAFI_UNICAST)
8212 vty_out (vty, ", table Default-IP-Routing-Table");
8213 }
8214 else
8215 vty_out (vty, ", no best path");
8216
8217 if (no_advertise)
8218 vty_out (vty, ", not advertised to any peer");
8219 else if (no_export)
8220 vty_out (vty, ", not advertised to EBGP peer");
8221 else if (local_as)
8222 vty_out (vty, ", not advertised outside local AS");
8223
8224 if (suppress)
8225 vty_out (vty, ", Advertisements suppressed by an aggregate.");
8226 vty_out (vty, ")%s", VTY_NEWLINE);
718e3744 8227 }
718e3744 8228
8229 /* advertised peer */
1eb8ef25 8230 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
718e3744 8231 {
8232 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
8233 {
b05a1c8b
DS
8234 if (json)
8235 {
f1aa5d8a
DS
8236 /* 'advertised-to' is a dictionary of peers we have advertised this
8237 * prefix too. The key is the peer's IP or swpX, the value is the
8238 * hostname if we know it and "" if not.
8239 */
8240 json_peer = json_object_new_object();
8241
04b6bdc0
DW
8242 if (peer->hostname)
8243 json_object_string_add(json_peer, "hostname", peer->hostname);
8244
f1aa5d8a
DS
8245 if (!json_adv_to)
8246 json_adv_to = json_object_new_object();
6410e93a 8247
036a4e7d 8248 if (peer->conf_if)
f1aa5d8a 8249 json_object_object_add(json_adv_to, peer->conf_if, json_peer);
036a4e7d 8250 else
f1aa5d8a
DS
8251 json_object_object_add(json_adv_to,
8252 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN),
8253 json_peer);
b05a1c8b
DS
8254 }
8255 else
8256 {
8257 if (! first)
8258 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
036a4e7d 8259
04b6bdc0
DW
8260 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
8261 {
8262 if (peer->conf_if)
8263 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
8264 else
8265 vty_out (vty, " %s(%s)", peer->hostname,
8266 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
8267 }
8268 else
8269 {
8270 if (peer->conf_if)
8271 vty_out (vty, " %s", peer->conf_if);
8272 else
8273 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
8274 }
b05a1c8b
DS
8275 }
8276 first = 1;
718e3744 8277 }
8278 }
b05a1c8b
DS
8279
8280 if (json)
8281 {
8282 if (first)
8283 {
62d6dca0 8284 json_object_object_add(json, "advertisedTo", json_adv_to);
b05a1c8b
DS
8285 }
8286 }
8287 else
8288 {
8289 if (!first)
8290 vty_out (vty, " Not advertised to any peer");
8291 vty_out (vty, "%s", VTY_NEWLINE);
8292 }
718e3744 8293}
8294
8295/* Display specified route of BGP table. */
94f2b392 8296static int
fee0f4c6 8297bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
fd79ac91 8298 struct bgp_table *rib, const char *ip_str,
8299 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
8300 int prefix_check, enum bgp_path_type pathtype,
8301 u_char use_json)
718e3744 8302{
8303 int ret;
8304 int header;
8305 int display = 0;
8306 struct prefix match;
8307 struct bgp_node *rn;
8308 struct bgp_node *rm;
8309 struct bgp_info *ri;
718e3744 8310 struct bgp_table *table;
f1aa5d8a
DS
8311 json_object *json = NULL;
8312 json_object *json_paths = NULL;
718e3744 8313
718e3744 8314 /* Check IP address argument. */
8315 ret = str2prefix (ip_str, &match);
8316 if (! ret)
8317 {
8318 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
8319 return CMD_WARNING;
8320 }
8321
8322 match.family = afi2family (afi);
8323
b05a1c8b
DS
8324 if (use_json)
8325 {
8326 json = json_object_new_object();
8327 json_paths = json_object_new_array();
8328 }
b05a1c8b 8329
718e3744 8330 if (safi == SAFI_MPLS_VPN)
8331 {
fee0f4c6 8332 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
718e3744 8333 {
8334 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
8335 continue;
8336
8337 if ((table = rn->info) != NULL)
8338 {
8339 header = 1;
8340
8341 if ((rm = bgp_node_match (table, &match)) != NULL)
8342 {
8343 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6c88b44d
CC
8344 {
8345 bgp_unlock_node (rm);
8346 continue;
8347 }
718e3744 8348
8349 for (ri = rm->info; ri; ri = ri->next)
8350 {
8351 if (header)
8352 {
8353 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
b05a1c8b 8354 AFI_IP, SAFI_MPLS_VPN, json);
718e3744 8355
8356 header = 0;
8357 }
8358 display++;
4092b06c
DS
8359
8360 if (pathtype == BGP_PATH_ALL ||
8361 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8362 (pathtype == BGP_PATH_MULTIPATH &&
8363 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
b05a1c8b 8364 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN, json_paths);
718e3744 8365 }
6c88b44d
CC
8366
8367 bgp_unlock_node (rm);
718e3744 8368 }
8369 }
8370 }
8371 }
8372 else
8373 {
8374 header = 1;
8375
fee0f4c6 8376 if ((rn = bgp_node_match (rib, &match)) != NULL)
718e3744 8377 {
8378 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
8379 {
8380 for (ri = rn->info; ri; ri = ri->next)
8381 {
8382 if (header)
8383 {
b05a1c8b 8384 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
718e3744 8385 header = 0;
8386 }
8387 display++;
4092b06c
DS
8388
8389 if (pathtype == BGP_PATH_ALL ||
8390 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8391 (pathtype == BGP_PATH_MULTIPATH &&
8392 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
b05a1c8b 8393 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
718e3744 8394 }
8395 }
6c88b44d
CC
8396
8397 bgp_unlock_node (rn);
718e3744 8398 }
8399 }
8400
e5eee9af 8401 if (use_json)
718e3744 8402 {
e5eee9af
DS
8403 if (display)
8404 json_object_object_add(json, "paths", json_paths);
8405
8406 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
f1aa5d8a 8407 json_object_free(json);
b05a1c8b
DS
8408 }
8409 else
8410 {
e5eee9af 8411 if (!display)
b05a1c8b
DS
8412 {
8413 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
8414 return CMD_WARNING;
8415 }
8416 }
8417
718e3744 8418 return CMD_SUCCESS;
8419}
8420
fee0f4c6 8421/* Display specified route of Main RIB */
94f2b392 8422static int
fd79ac91 8423bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
fee0f4c6 8424 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
8425 int prefix_check, enum bgp_path_type pathtype,
8426 u_char use_json)
fee0f4c6 8427{
8428 struct bgp *bgp;
8429
8430 /* BGP structure lookup. */
8431 if (view_name)
8432 {
8433 bgp = bgp_lookup_by_name (view_name);
8434 if (bgp == NULL)
8435 {
8436 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8437 return CMD_WARNING;
8438 }
8439 }
8440 else
8441 {
8442 bgp = bgp_get_default ();
8443 if (bgp == NULL)
8444 {
8445 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8446 return CMD_WARNING;
8447 }
8448 }
8449
8450 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
b05a1c8b
DS
8451 afi, safi, prd, prefix_check, pathtype,
8452 use_json);
fee0f4c6 8453}
8454
718e3744 8455/* BGP route print out function. */
8456DEFUN (show_ip_bgp,
8457 show_ip_bgp_cmd,
b05a1c8b 8458 "show ip bgp {json}",
47fc97cc
DS
8459 SHOW_STR
8460 IP_STR
b05a1c8b
DS
8461 BGP_STR
8462 "JavaScript Object Notation\n")
47fc97cc 8463{
b05a1c8b
DS
8464 u_char use_json = (argv[0] != NULL);
8465 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
718e3744 8466}
8467
8468DEFUN (show_ip_bgp_ipv4,
8469 show_ip_bgp_ipv4_cmd,
b05a1c8b 8470 "show ip bgp ipv4 (unicast|multicast) {json}",
718e3744 8471 SHOW_STR
8472 IP_STR
8473 BGP_STR
8474 "Address family\n"
8475 "Address Family modifier\n"
b05a1c8b
DS
8476 "Address Family modifier\n"
8477 "JavaScript Object Notation\n")
718e3744 8478{
b05a1c8b
DS
8479 u_char use_json = (argv[1] != NULL);
8480
718e3744 8481 if (strncmp (argv[0], "m", 1) == 0)
5a646650 8482 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
b05a1c8b 8483 NULL, use_json);
718e3744 8484
b05a1c8b 8485 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
718e3744 8486}
8487
95cbbd2a
ML
8488ALIAS (show_ip_bgp_ipv4,
8489 show_bgp_ipv4_safi_cmd,
b05a1c8b 8490 "show bgp ipv4 (unicast|multicast) {json}",
95cbbd2a
ML
8491 SHOW_STR
8492 BGP_STR
8493 "Address family\n"
8494 "Address Family modifier\n"
47fc97cc 8495 "Address Family modifier\n"
b05a1c8b 8496 "JavaScript Object Notation\n")
47fc97cc 8497
718e3744 8498DEFUN (show_ip_bgp_route,
8499 show_ip_bgp_route_cmd,
b05a1c8b 8500 "show ip bgp A.B.C.D {json}",
718e3744 8501 SHOW_STR
8502 IP_STR
8503 BGP_STR
b05a1c8b
DS
8504 "Network in the BGP routing table to display\n"
8505 "JavaScript Object Notation\n")
718e3744 8506{
b05a1c8b
DS
8507 u_char use_json = (argv[1] != NULL);
8508 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
4092b06c
DS
8509}
8510
8511DEFUN (show_ip_bgp_route_pathtype,
8512 show_ip_bgp_route_pathtype_cmd,
b05a1c8b 8513 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
4092b06c
DS
8514 SHOW_STR
8515 IP_STR
8516 BGP_STR
8517 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8518 "Display only the bestpath\n"
b05a1c8b
DS
8519 "Display only multipaths\n"
8520 "JavaScript Object Notation\n")
4092b06c 8521{
b05a1c8b
DS
8522 u_char use_json = (argv[2] != NULL);
8523
4092b06c 8524 if (strncmp (argv[1], "b", 1) == 0)
b05a1c8b 8525 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8526 else
b05a1c8b 8527 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8528}
8529
8530DEFUN (show_bgp_ipv4_safi_route_pathtype,
8531 show_bgp_ipv4_safi_route_pathtype_cmd,
b05a1c8b 8532 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath) {json}",
4092b06c
DS
8533 SHOW_STR
8534 BGP_STR
8535 "Address family\n"
8536 "Address Family modifier\n"
8537 "Address Family modifier\n"
8538 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8539 "Display only the bestpath\n"
b05a1c8b
DS
8540 "Display only multipaths\n"
8541 "JavaScript Object Notation\n")
4092b06c 8542{
b05a1c8b
DS
8543 u_char use_json = (argv[3] != NULL);
8544
4092b06c
DS
8545 if (strncmp (argv[0], "m", 1) == 0)
8546 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8547 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8548 else
b05a1c8b 8549 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8550 else
8551 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8552 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8553 else
b05a1c8b 8554 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
718e3744 8555}
8556
8557DEFUN (show_ip_bgp_ipv4_route,
8558 show_ip_bgp_ipv4_route_cmd,
b05a1c8b 8559 "show ip bgp ipv4 (unicast|multicast) A.B.C.D {json}",
718e3744 8560 SHOW_STR
8561 IP_STR
8562 BGP_STR
8563 "Address family\n"
8564 "Address Family modifier\n"
8565 "Address Family modifier\n"
b05a1c8b
DS
8566 "Network in the BGP routing table to display\n"
8567 "JavaScript Object Notation\n")
718e3744 8568{
b05a1c8b
DS
8569 u_char use_json = (argv[2] != NULL);
8570
718e3744 8571 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 8572 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8573
b05a1c8b 8574 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8575}
8576
95cbbd2a
ML
8577ALIAS (show_ip_bgp_ipv4_route,
8578 show_bgp_ipv4_safi_route_cmd,
b05a1c8b 8579 "show bgp ipv4 (unicast|multicast) A.B.C.D {json}",
95cbbd2a
ML
8580 SHOW_STR
8581 BGP_STR
8582 "Address family\n"
8583 "Address Family modifier\n"
8584 "Address Family modifier\n"
b05a1c8b
DS
8585 "Network in the BGP routing table to display\n"
8586 "JavaScript Object Notation\n")
95cbbd2a 8587
718e3744 8588DEFUN (show_ip_bgp_vpnv4_all_route,
8589 show_ip_bgp_vpnv4_all_route_cmd,
b05a1c8b 8590 "show ip bgp vpnv4 all A.B.C.D {json}",
718e3744 8591 SHOW_STR
8592 IP_STR
8593 BGP_STR
8594 "Display VPNv4 NLRI specific information\n"
8595 "Display information about all VPNv4 NLRIs\n"
b05a1c8b
DS
8596 "Network in the BGP routing table to display\n"
8597 "JavaScript Object Notation\n")
718e3744 8598{
b05a1c8b
DS
8599 u_char use_json = (argv[1] != NULL);
8600 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8601}
8602
4092b06c 8603
718e3744 8604DEFUN (show_ip_bgp_vpnv4_rd_route,
8605 show_ip_bgp_vpnv4_rd_route_cmd,
b05a1c8b 8606 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
718e3744 8607 SHOW_STR
8608 IP_STR
8609 BGP_STR
8610 "Display VPNv4 NLRI specific information\n"
8611 "Display information for a route distinguisher\n"
8612 "VPN Route Distinguisher\n"
b05a1c8b
DS
8613 "Network in the BGP routing table to display\n"
8614 "JavaScript Object Notation\n")
718e3744 8615{
8616 int ret;
8617 struct prefix_rd prd;
b05a1c8b 8618 u_char use_json = (argv[2] != NULL);
718e3744 8619
8620 ret = str2prefix_rd (argv[0], &prd);
8621 if (! ret)
8622 {
8623 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8624 return CMD_WARNING;
8625 }
b05a1c8b 8626 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json);
718e3744 8627}
8628
8629DEFUN (show_ip_bgp_prefix,
8630 show_ip_bgp_prefix_cmd,
b05a1c8b 8631 "show ip bgp A.B.C.D/M {json}",
718e3744 8632 SHOW_STR
8633 IP_STR
8634 BGP_STR
b05a1c8b
DS
8635 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8636 "JavaScript Object Notation\n")
718e3744 8637{
b05a1c8b
DS
8638 u_char use_json = (argv[1] != NULL);
8639 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
4092b06c
DS
8640}
8641
8642DEFUN (show_ip_bgp_prefix_pathtype,
8643 show_ip_bgp_prefix_pathtype_cmd,
b05a1c8b 8644 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8645 SHOW_STR
8646 IP_STR
8647 BGP_STR
8648 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8649 "Display only the bestpath\n"
b05a1c8b
DS
8650 "Display only multipaths\n"
8651 "JavaScript Object Notation\n")
4092b06c 8652{
b05a1c8b 8653 u_char use_json = (argv[2] != NULL);
4092b06c 8654 if (strncmp (argv[1], "b", 1) == 0)
b05a1c8b 8655 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8656 else
b05a1c8b 8657 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
718e3744 8658}
8659
8660DEFUN (show_ip_bgp_ipv4_prefix,
8661 show_ip_bgp_ipv4_prefix_cmd,
b05a1c8b 8662 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
718e3744 8663 SHOW_STR
8664 IP_STR
8665 BGP_STR
8666 "Address family\n"
8667 "Address Family modifier\n"
8668 "Address Family modifier\n"
b05a1c8b
DS
8669 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8670 "JavaScript Object Notation\n")
718e3744 8671{
b05a1c8b
DS
8672 u_char use_json = (argv[2] != NULL);
8673
718e3744 8674 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 8675 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8676
b05a1c8b 8677 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8678}
8679
95cbbd2a
ML
8680ALIAS (show_ip_bgp_ipv4_prefix,
8681 show_bgp_ipv4_safi_prefix_cmd,
b05a1c8b 8682 "show bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
95cbbd2a
ML
8683 SHOW_STR
8684 BGP_STR
8685 "Address family\n"
8686 "Address Family modifier\n"
8687 "Address Family modifier\n"
b05a1c8b
DS
8688 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8689 "JavaScript Object Notation\n")
95cbbd2a 8690
4092b06c
DS
8691DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
8692 show_ip_bgp_ipv4_prefix_pathtype_cmd,
b05a1c8b 8693 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8694 SHOW_STR
8695 IP_STR
8696 BGP_STR
8697 "Address family\n"
8698 "Address Family modifier\n"
8699 "Address Family modifier\n"
8700 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8701 "Display only the bestpath\n"
b05a1c8b
DS
8702 "Display only multipaths\n"
8703 "JavaScript Object Notation\n")
4092b06c 8704{
b05a1c8b
DS
8705 u_char use_json = (argv[3] != NULL);
8706
4092b06c
DS
8707 if (strncmp (argv[0], "m", 1) == 0)
8708 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8709 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8710 else
b05a1c8b 8711 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8712 else
8713 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8714 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8715 else
b05a1c8b 8716 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8717}
8718
8719ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
8720 show_bgp_ipv4_safi_prefix_pathtype_cmd,
b05a1c8b 8721 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8722 SHOW_STR
8723 BGP_STR
8724 "Address family\n"
8725 "Address Family modifier\n"
8726 "Address Family modifier\n"
8727 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8728 "Display only the bestpath\n"
b05a1c8b
DS
8729 "Display only multipaths\n"
8730 "JavaScript Object Notation\n")
4092b06c 8731
718e3744 8732DEFUN (show_ip_bgp_vpnv4_all_prefix,
8733 show_ip_bgp_vpnv4_all_prefix_cmd,
b05a1c8b 8734 "show ip bgp vpnv4 all A.B.C.D/M {json}",
718e3744 8735 SHOW_STR
8736 IP_STR
8737 BGP_STR
8738 "Display VPNv4 NLRI specific information\n"
8739 "Display information about all VPNv4 NLRIs\n"
b05a1c8b
DS
8740 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8741 "JavaScript Object Notation\n")
718e3744 8742{
b05a1c8b
DS
8743 u_char use_json = (argv[1] != NULL);
8744 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8745}
8746
8747DEFUN (show_ip_bgp_vpnv4_rd_prefix,
8748 show_ip_bgp_vpnv4_rd_prefix_cmd,
b05a1c8b 8749 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
718e3744 8750 SHOW_STR
8751 IP_STR
8752 BGP_STR
8753 "Display VPNv4 NLRI specific information\n"
8754 "Display information for a route distinguisher\n"
8755 "VPN Route Distinguisher\n"
b05a1c8b
DS
8756 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8757 "JavaScript Object Notation\n")
718e3744 8758{
8759 int ret;
8760 struct prefix_rd prd;
b05a1c8b 8761 u_char use_json = (argv[2] != NULL);
718e3744 8762
8763 ret = str2prefix_rd (argv[0], &prd);
8764 if (! ret)
8765 {
8766 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8767 return CMD_WARNING;
8768 }
b05a1c8b 8769 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json);
718e3744 8770}
8771
8772DEFUN (show_ip_bgp_view,
8773 show_ip_bgp_view_cmd,
b05a1c8b 8774 "show ip bgp view WORD {json}",
718e3744 8775 SHOW_STR
8776 IP_STR
8777 BGP_STR
8778 "BGP view\n"
b05a1c8b
DS
8779 "View name\n"
8780 "JavaScript Object Notation\n")
718e3744 8781{
bb46e94f 8782 struct bgp *bgp;
b05a1c8b 8783 u_char use_json = (argv[1] != NULL);
bb46e94f 8784
8785 /* BGP structure lookup. */
8786 bgp = bgp_lookup_by_name (argv[0]);
8787 if (bgp == NULL)
8788 {
8789 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8790 return CMD_WARNING;
8791 }
8792
b05a1c8b 8793 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
718e3744 8794}
8795
8796DEFUN (show_ip_bgp_view_route,
8797 show_ip_bgp_view_route_cmd,
b05a1c8b 8798 "show ip bgp view WORD A.B.C.D {json}",
718e3744 8799 SHOW_STR
8800 IP_STR
8801 BGP_STR
8802 "BGP view\n"
2b00515a 8803 "View name\n"
b05a1c8b
DS
8804 "Network in the BGP routing table to display\n"
8805 "JavaScript Object Notation\n")
718e3744 8806{
b05a1c8b
DS
8807 u_char use_json = (argv[2] != NULL);
8808 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8809}
8810
8811DEFUN (show_ip_bgp_view_prefix,
8812 show_ip_bgp_view_prefix_cmd,
b05a1c8b 8813 "show ip bgp view WORD A.B.C.D/M {json}",
718e3744 8814 SHOW_STR
8815 IP_STR
8816 BGP_STR
8817 "BGP view\n"
2b00515a 8818 "View name\n"
b05a1c8b
DS
8819 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8820 "JavaScript Object Notation\n")
718e3744 8821{
b05a1c8b
DS
8822 u_char use_json = (argv[2] != NULL);
8823 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8824}
8825
8826#ifdef HAVE_IPV6
8827DEFUN (show_bgp,
8828 show_bgp_cmd,
b05a1c8b 8829 "show bgp {json}",
718e3744 8830 SHOW_STR
b05a1c8b
DS
8831 BGP_STR
8832 "JavaScript Object Notation\n")
718e3744 8833{
b05a1c8b 8834 u_char use_json = (argv[0] != NULL);
5a646650 8835 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
b05a1c8b 8836 NULL, use_json);
718e3744 8837}
8838
8839ALIAS (show_bgp,
8840 show_bgp_ipv6_cmd,
b05a1c8b 8841 "show bgp ipv6 {json}",
718e3744 8842 SHOW_STR
8843 BGP_STR
b05a1c8b
DS
8844 "Address family\n"
8845 "JavaScript Object Notation\n")
718e3744 8846
95cbbd2a
ML
8847DEFUN (show_bgp_ipv6_safi,
8848 show_bgp_ipv6_safi_cmd,
b05a1c8b 8849 "show bgp ipv6 (unicast|multicast) {json}",
95cbbd2a
ML
8850 SHOW_STR
8851 BGP_STR
8852 "Address family\n"
8853 "Address Family modifier\n"
47fc97cc 8854 "Address Family modifier\n"
b05a1c8b 8855 "JavaScript Object Notation\n")
47fc97cc 8856{
b05a1c8b 8857 u_char use_json = (argv[1] != NULL);
47fc97cc
DS
8858 if (strncmp (argv[0], "m", 1) == 0)
8859 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
b05a1c8b 8860 NULL, use_json);
47fc97cc 8861
b05a1c8b 8862 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
95cbbd2a
ML
8863}
8864
718e3744 8865/* old command */
8866DEFUN (show_ipv6_bgp,
8867 show_ipv6_bgp_cmd,
b05a1c8b 8868 "show ipv6 bgp {json}",
718e3744 8869 SHOW_STR
8870 IP_STR
b05a1c8b
DS
8871 BGP_STR
8872 "JavaScript Object Notation\n")
718e3744 8873{
b05a1c8b 8874 u_char use_json = (argv[0] != NULL);
5a646650 8875 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
b05a1c8b 8876 NULL, use_json);
718e3744 8877}
8878
8879DEFUN (show_bgp_route,
8880 show_bgp_route_cmd,
b05a1c8b 8881 "show bgp X:X::X:X {json}",
718e3744 8882 SHOW_STR
8883 BGP_STR
b05a1c8b
DS
8884 "Network in the BGP routing table to display\n"
8885 "JavaScript Object Notation\n")
718e3744 8886{
b05a1c8b
DS
8887 u_char use_json = (argv[1] != NULL);
8888 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8889}
8890
8891ALIAS (show_bgp_route,
8892 show_bgp_ipv6_route_cmd,
b05a1c8b 8893 "show bgp ipv6 X:X::X:X {json}",
718e3744 8894 SHOW_STR
8895 BGP_STR
8896 "Address family\n"
b05a1c8b
DS
8897 "Network in the BGP routing table to display\n"
8898 "JavaScript Object Notation\n")
718e3744 8899
95cbbd2a
ML
8900DEFUN (show_bgp_ipv6_safi_route,
8901 show_bgp_ipv6_safi_route_cmd,
b05a1c8b 8902 "show bgp ipv6 (unicast|multicast) X:X::X:X {json}",
95cbbd2a
ML
8903 SHOW_STR
8904 BGP_STR
8905 "Address family\n"
8906 "Address Family modifier\n"
8907 "Address Family modifier\n"
b05a1c8b
DS
8908 "Network in the BGP routing table to display\n"
8909 "JavaScript Object Notation\n")
95cbbd2a 8910{
b05a1c8b 8911 u_char use_json = (argv[2] != NULL);
95cbbd2a 8912 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 8913 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json);
95cbbd2a 8914
b05a1c8b 8915 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
4092b06c
DS
8916}
8917
8918DEFUN (show_bgp_route_pathtype,
8919 show_bgp_route_pathtype_cmd,
b05a1c8b 8920 "show bgp X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8921 SHOW_STR
8922 BGP_STR
8923 "Network in the BGP routing table to display\n"
8924 "Display only the bestpath\n"
b05a1c8b
DS
8925 "Display only multipaths\n"
8926 "JavaScript Object Notation\n")
4092b06c 8927{
b05a1c8b 8928 u_char use_json = (argv[2] != NULL);
4092b06c 8929 if (strncmp (argv[1], "b", 1) == 0)
b05a1c8b 8930 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8931 else
b05a1c8b 8932 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8933}
8934
8935ALIAS (show_bgp_route_pathtype,
8936 show_bgp_ipv6_route_pathtype_cmd,
b05a1c8b 8937 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8938 SHOW_STR
8939 BGP_STR
8940 "Address family\n"
8941 "Network in the BGP routing table to display\n"
8942 "Display only the bestpath\n"
b05a1c8b
DS
8943 "Display only multipaths\n"
8944 "JavaScript Object Notation\n")
4092b06c
DS
8945
8946DEFUN (show_bgp_ipv6_safi_route_pathtype,
8947 show_bgp_ipv6_safi_route_pathtype_cmd,
b05a1c8b 8948 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8949 SHOW_STR
8950 BGP_STR
8951 "Address family\n"
8952 "Address Family modifier\n"
8953 "Address Family modifier\n"
8954 "Network in the BGP routing table to display\n"
8955 "Display only the bestpath\n"
b05a1c8b
DS
8956 "Display only multipaths\n"
8957 "JavaScript Object Notation\n")
4092b06c 8958{
b05a1c8b 8959 u_char use_json = (argv[3] != NULL);
4092b06c
DS
8960 if (strncmp (argv[0], "m", 1) == 0)
8961 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8962 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8963 else
b05a1c8b 8964 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8965 else
8966 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8967 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8968 else
b05a1c8b 8969 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
95cbbd2a
ML
8970}
8971
718e3744 8972/* old command */
8973DEFUN (show_ipv6_bgp_route,
8974 show_ipv6_bgp_route_cmd,
b05a1c8b 8975 "show ipv6 bgp X:X::X:X {json}",
718e3744 8976 SHOW_STR
8977 IP_STR
8978 BGP_STR
b05a1c8b
DS
8979 "Network in the BGP routing table to display\n"
8980 "JavaScript Object Notation\n")
718e3744 8981{
b05a1c8b
DS
8982 u_char use_json = (argv[1] != NULL);
8983 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8984}
8985
8986DEFUN (show_bgp_prefix,
8987 show_bgp_prefix_cmd,
b05a1c8b 8988 "show bgp X:X::X:X/M {json}",
718e3744 8989 SHOW_STR
8990 BGP_STR
b05a1c8b
DS
8991 "IPv6 prefix <network>/<length>\n"
8992 "JavaScript Object Notation\n")
718e3744 8993{
b05a1c8b
DS
8994 u_char use_json = (argv[1] != NULL);
8995 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8996}
8997
8998ALIAS (show_bgp_prefix,
8999 show_bgp_ipv6_prefix_cmd,
b05a1c8b 9000 "show bgp ipv6 X:X::X:X/M {json}",
718e3744 9001 SHOW_STR
9002 BGP_STR
9003 "Address family\n"
b05a1c8b
DS
9004 "IPv6 prefix <network>/<length>\n"
9005 "JavaScript Object Notation\n")
718e3744 9006
95cbbd2a
ML
9007DEFUN (show_bgp_ipv6_safi_prefix,
9008 show_bgp_ipv6_safi_prefix_cmd,
b05a1c8b 9009 "show bgp ipv6 (unicast|multicast) X:X::X:X/M {json}",
95cbbd2a
ML
9010 SHOW_STR
9011 BGP_STR
9012 "Address family\n"
9013 "Address Family modifier\n"
9014 "Address Family modifier\n"
b05a1c8b
DS
9015 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9016 "JavaScript Object Notation\n")
95cbbd2a 9017{
b05a1c8b 9018 u_char use_json = (argv[2] != NULL);
95cbbd2a 9019 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 9020 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json);
95cbbd2a 9021
b05a1c8b 9022 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
4092b06c
DS
9023}
9024
9025DEFUN (show_bgp_prefix_pathtype,
9026 show_bgp_prefix_pathtype_cmd,
b05a1c8b 9027 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
9028 SHOW_STR
9029 BGP_STR
9030 "IPv6 prefix <network>/<length>\n"
9031 "Display only the bestpath\n"
b05a1c8b
DS
9032 "Display only multipaths\n"
9033 "JavaScript Object Notation\n")
4092b06c 9034{
b05a1c8b 9035 u_char use_json = (argv[2] != NULL);
4092b06c 9036 if (strncmp (argv[1], "b", 1) == 0)
b05a1c8b 9037 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 9038 else
b05a1c8b 9039 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
9040}
9041
9042ALIAS (show_bgp_prefix_pathtype,
9043 show_bgp_ipv6_prefix_pathtype_cmd,
b05a1c8b 9044 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
9045 SHOW_STR
9046 BGP_STR
9047 "Address family\n"
9048 "IPv6 prefix <network>/<length>\n"
9049 "Display only the bestpath\n"
b05a1c8b
DS
9050 "Display only multipaths\n"
9051 "JavaScript Object Notation\n")
4092b06c
DS
9052
9053DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
9054 show_bgp_ipv6_safi_prefix_pathtype_cmd,
b05a1c8b 9055 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
9056 SHOW_STR
9057 BGP_STR
9058 "Address family\n"
9059 "Address Family modifier\n"
9060 "Address Family modifier\n"
9061 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9062 "Display only the bestpath\n"
b05a1c8b
DS
9063 "Display only multipaths\n"
9064 "JavaScript Object Notation\n")
4092b06c 9065{
b05a1c8b 9066 u_char use_json = (argv[3] != NULL);
4092b06c
DS
9067 if (strncmp (argv[0], "m", 1) == 0)
9068 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 9069 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 9070 else
b05a1c8b 9071 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
9072 else
9073 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 9074 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 9075 else
b05a1c8b 9076 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
95cbbd2a
ML
9077}
9078
718e3744 9079/* old command */
9080DEFUN (show_ipv6_bgp_prefix,
9081 show_ipv6_bgp_prefix_cmd,
b05a1c8b 9082 "show ipv6 bgp X:X::X:X/M {json}",
718e3744 9083 SHOW_STR
9084 IP_STR
9085 BGP_STR
b05a1c8b
DS
9086 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9087 "JavaScript Object Notation\n")
718e3744 9088{
b05a1c8b
DS
9089 u_char use_json = (argv[1] != NULL);
9090 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 9091}
9092
bb46e94f 9093DEFUN (show_bgp_view,
9094 show_bgp_view_cmd,
b05a1c8b 9095 "show bgp view WORD {json}",
bb46e94f 9096 SHOW_STR
9097 BGP_STR
9098 "BGP view\n"
b05a1c8b
DS
9099 "View name\n"
9100 "JavaScript Object Notation\n")
bb46e94f 9101{
9102 struct bgp *bgp;
b05a1c8b 9103 u_char use_json = (argv[1] != NULL);
bb46e94f 9104
9105 /* BGP structure lookup. */
9106 bgp = bgp_lookup_by_name (argv[0]);
9107 if (bgp == NULL)
9108 {
9109 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9110 return CMD_WARNING;
9111 }
9112
b05a1c8b 9113 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
bb46e94f 9114}
9115
9116ALIAS (show_bgp_view,
9117 show_bgp_view_ipv6_cmd,
b05a1c8b 9118 "show bgp view WORD ipv6 {json}",
bb46e94f 9119 SHOW_STR
9120 BGP_STR
9121 "BGP view\n"
9122 "View name\n"
b05a1c8b
DS
9123 "Address family\n"
9124 "JavaScript Object Notation\n")
bb46e94f 9125
9126DEFUN (show_bgp_view_route,
9127 show_bgp_view_route_cmd,
b05a1c8b 9128 "show bgp view WORD X:X::X:X {json}",
bb46e94f 9129 SHOW_STR
9130 BGP_STR
9131 "BGP view\n"
9132 "View name\n"
b05a1c8b
DS
9133 "Network in the BGP routing table to display\n"
9134 "JavaScript Object Notation\n")
bb46e94f 9135{
b05a1c8b
DS
9136 u_char use_json = (argv[2] != NULL);
9137 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
bb46e94f 9138}
9139
9140ALIAS (show_bgp_view_route,
9141 show_bgp_view_ipv6_route_cmd,
b05a1c8b 9142 "show bgp view WORD ipv6 X:X::X:X {json}",
bb46e94f 9143 SHOW_STR
9144 BGP_STR
9145 "BGP view\n"
9146 "View name\n"
9147 "Address family\n"
b05a1c8b
DS
9148 "Network in the BGP routing table to display\n"
9149 "JavaScript Object Notation\n")
bb46e94f 9150
9151DEFUN (show_bgp_view_prefix,
9152 show_bgp_view_prefix_cmd,
b05a1c8b 9153 "show bgp view WORD X:X::X:X/M {json}",
bb46e94f 9154 SHOW_STR
9155 BGP_STR
9156 "BGP view\n"
9157 "View name\n"
b05a1c8b
DS
9158 "IPv6 prefix <network>/<length>\n"
9159 "JavaScript Object Notation\n")
bb46e94f 9160{
b05a1c8b
DS
9161 u_char use_json = (argv[2] != NULL);
9162 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
bb46e94f 9163}
9164
9165ALIAS (show_bgp_view_prefix,
9166 show_bgp_view_ipv6_prefix_cmd,
b05a1c8b 9167 "show bgp view WORD ipv6 X:X::X:X/M {json}",
bb46e94f 9168 SHOW_STR
9169 BGP_STR
9170 "BGP view\n"
9171 "View name\n"
9172 "Address family\n"
b05a1c8b
DS
9173 "IPv6 prefix <network>/<length>\n"
9174 "JavaScript Object Notation\n")
bb46e94f 9175
718e3744 9176/* old command */
9177DEFUN (show_ipv6_mbgp,
9178 show_ipv6_mbgp_cmd,
b05a1c8b 9179 "show ipv6 mbgp {json}",
718e3744 9180 SHOW_STR
9181 IP_STR
b05a1c8b
DS
9182 MBGP_STR
9183 "JavaScript Object Notation\n")
718e3744 9184{
b05a1c8b 9185 u_char use_json = (argv[0] != NULL);
5a646650 9186 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
b05a1c8b 9187 NULL, use_json);
718e3744 9188}
9189
9190/* old command */
9191DEFUN (show_ipv6_mbgp_route,
9192 show_ipv6_mbgp_route_cmd,
b05a1c8b 9193 "show ipv6 mbgp X:X::X:X {json}",
718e3744 9194 SHOW_STR
9195 IP_STR
9196 MBGP_STR
b05a1c8b
DS
9197 "Network in the MBGP routing table to display\n"
9198 "JavaScript Object Notation\n")
718e3744 9199{
b05a1c8b
DS
9200 u_char use_json = (argv[1] != NULL);
9201 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 9202}
9203
9204/* old command */
9205DEFUN (show_ipv6_mbgp_prefix,
9206 show_ipv6_mbgp_prefix_cmd,
b05a1c8b 9207 "show ipv6 mbgp X:X::X:X/M {json}",
718e3744 9208 SHOW_STR
9209 IP_STR
9210 MBGP_STR
b05a1c8b
DS
9211 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9212 "JavaScript Object Notation\n")
718e3744 9213{
b05a1c8b
DS
9214 u_char use_json = (argv[1] != NULL);
9215 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 9216}
9217#endif
6b0655a2 9218
718e3744 9219
94f2b392 9220static int
fd79ac91 9221bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
718e3744 9222 safi_t safi, enum bgp_show_type type)
9223{
9224 int i;
9225 struct buffer *b;
9226 char *regstr;
9227 int first;
9228 regex_t *regex;
5a646650 9229 int rc;
718e3744 9230
9231 first = 0;
9232 b = buffer_new (1024);
9233 for (i = 0; i < argc; i++)
9234 {
9235 if (first)
9236 buffer_putc (b, ' ');
9237 else
9238 {
9239 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9240 continue;
9241 first = 1;
9242 }
9243
9244 buffer_putstr (b, argv[i]);
9245 }
9246 buffer_putc (b, '\0');
9247
9248 regstr = buffer_getstr (b);
9249 buffer_free (b);
9250
9251 regex = bgp_regcomp (regstr);
3b8b1855 9252 XFREE(MTYPE_TMP, regstr);
718e3744 9253 if (! regex)
9254 {
9255 vty_out (vty, "Can't compile regexp %s%s", argv[0],
9256 VTY_NEWLINE);
9257 return CMD_WARNING;
9258 }
9259
b05a1c8b 9260 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
5a646650 9261 bgp_regex_free (regex);
9262 return rc;
718e3744 9263}
9264
9265DEFUN (show_ip_bgp_regexp,
9266 show_ip_bgp_regexp_cmd,
9267 "show ip bgp regexp .LINE",
9268 SHOW_STR
9269 IP_STR
9270 BGP_STR
9271 "Display routes matching the AS path regular expression\n"
9272 "A regular-expression to match the BGP AS paths\n")
9273{
9274 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9275 bgp_show_type_regexp);
9276}
9277
9278DEFUN (show_ip_bgp_flap_regexp,
9279 show_ip_bgp_flap_regexp_cmd,
9280 "show ip bgp flap-statistics regexp .LINE",
9281 SHOW_STR
9282 IP_STR
9283 BGP_STR
9284 "Display flap statistics of routes\n"
9285 "Display routes matching the AS path regular expression\n"
9286 "A regular-expression to match the BGP AS paths\n")
9287{
9288 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9289 bgp_show_type_flap_regexp);
9290}
9291
9292DEFUN (show_ip_bgp_ipv4_regexp,
9293 show_ip_bgp_ipv4_regexp_cmd,
9294 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
9295 SHOW_STR
9296 IP_STR
9297 BGP_STR
9298 "Address family\n"
9299 "Address Family modifier\n"
9300 "Address Family modifier\n"
9301 "Display routes matching the AS path regular expression\n"
9302 "A regular-expression to match the BGP AS paths\n")
9303{
9304 if (strncmp (argv[0], "m", 1) == 0)
9305 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
9306 bgp_show_type_regexp);
9307
9308 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9309 bgp_show_type_regexp);
9310}
9311
9312#ifdef HAVE_IPV6
9313DEFUN (show_bgp_regexp,
9314 show_bgp_regexp_cmd,
9315 "show bgp regexp .LINE",
9316 SHOW_STR
9317 BGP_STR
9318 "Display routes matching the AS path regular expression\n"
9319 "A regular-expression to match the BGP AS paths\n")
9320{
9321 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9322 bgp_show_type_regexp);
9323}
9324
9325ALIAS (show_bgp_regexp,
9326 show_bgp_ipv6_regexp_cmd,
9327 "show bgp ipv6 regexp .LINE",
9328 SHOW_STR
9329 BGP_STR
9330 "Address family\n"
9331 "Display routes matching the AS path regular expression\n"
9332 "A regular-expression to match the BGP AS paths\n")
9333
9334/* old command */
9335DEFUN (show_ipv6_bgp_regexp,
9336 show_ipv6_bgp_regexp_cmd,
9337 "show ipv6 bgp regexp .LINE",
9338 SHOW_STR
9339 IP_STR
9340 BGP_STR
9341 "Display routes matching the AS path regular expression\n"
9342 "A regular-expression to match the BGP AS paths\n")
9343{
9344 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9345 bgp_show_type_regexp);
9346}
9347
9348/* old command */
9349DEFUN (show_ipv6_mbgp_regexp,
9350 show_ipv6_mbgp_regexp_cmd,
9351 "show ipv6 mbgp regexp .LINE",
9352 SHOW_STR
9353 IP_STR
9354 BGP_STR
9355 "Display routes matching the AS path regular expression\n"
9356 "A regular-expression to match the MBGP AS paths\n")
9357{
9358 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
9359 bgp_show_type_regexp);
9360}
9361#endif /* HAVE_IPV6 */
6b0655a2 9362
94f2b392 9363static int
fd79ac91 9364bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
718e3744 9365 safi_t safi, enum bgp_show_type type)
9366{
9367 struct prefix_list *plist;
9368
9369 plist = prefix_list_lookup (afi, prefix_list_str);
9370 if (plist == NULL)
9371 {
9372 vty_out (vty, "%% %s is not a valid prefix-list name%s",
9373 prefix_list_str, VTY_NEWLINE);
9374 return CMD_WARNING;
9375 }
9376
b05a1c8b 9377 return bgp_show (vty, NULL, afi, safi, type, plist, 0);
718e3744 9378}
9379
9380DEFUN (show_ip_bgp_prefix_list,
9381 show_ip_bgp_prefix_list_cmd,
9382 "show ip bgp prefix-list WORD",
9383 SHOW_STR
9384 IP_STR
9385 BGP_STR
9386 "Display routes conforming to the prefix-list\n"
9387 "IP prefix-list name\n")
9388{
9389 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
9390 bgp_show_type_prefix_list);
9391}
9392
9393DEFUN (show_ip_bgp_flap_prefix_list,
9394 show_ip_bgp_flap_prefix_list_cmd,
9395 "show ip bgp flap-statistics prefix-list WORD",
9396 SHOW_STR
9397 IP_STR
9398 BGP_STR
9399 "Display flap statistics of routes\n"
9400 "Display routes conforming to the prefix-list\n"
9401 "IP prefix-list name\n")
9402{
9403 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
9404 bgp_show_type_flap_prefix_list);
9405}
9406
9407DEFUN (show_ip_bgp_ipv4_prefix_list,
9408 show_ip_bgp_ipv4_prefix_list_cmd,
9409 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
9410 SHOW_STR
9411 IP_STR
9412 BGP_STR
9413 "Address family\n"
9414 "Address Family modifier\n"
9415 "Address Family modifier\n"
9416 "Display routes conforming to the prefix-list\n"
9417 "IP prefix-list name\n")
9418{
9419 if (strncmp (argv[0], "m", 1) == 0)
9420 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9421 bgp_show_type_prefix_list);
9422
9423 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
9424 bgp_show_type_prefix_list);
9425}
9426
9427#ifdef HAVE_IPV6
9428DEFUN (show_bgp_prefix_list,
9429 show_bgp_prefix_list_cmd,
9430 "show bgp prefix-list WORD",
9431 SHOW_STR
9432 BGP_STR
9433 "Display routes conforming to the prefix-list\n"
9434 "IPv6 prefix-list name\n")
9435{
9436 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9437 bgp_show_type_prefix_list);
9438}
9439
9440ALIAS (show_bgp_prefix_list,
9441 show_bgp_ipv6_prefix_list_cmd,
9442 "show bgp ipv6 prefix-list WORD",
9443 SHOW_STR
9444 BGP_STR
9445 "Address family\n"
9446 "Display routes conforming to the prefix-list\n"
9447 "IPv6 prefix-list name\n")
9448
9449/* old command */
9450DEFUN (show_ipv6_bgp_prefix_list,
9451 show_ipv6_bgp_prefix_list_cmd,
9452 "show ipv6 bgp prefix-list WORD",
9453 SHOW_STR
9454 IPV6_STR
9455 BGP_STR
9456 "Display routes matching the prefix-list\n"
9457 "IPv6 prefix-list name\n")
9458{
9459 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9460 bgp_show_type_prefix_list);
9461}
9462
9463/* old command */
9464DEFUN (show_ipv6_mbgp_prefix_list,
9465 show_ipv6_mbgp_prefix_list_cmd,
9466 "show ipv6 mbgp prefix-list WORD",
9467 SHOW_STR
9468 IPV6_STR
9469 MBGP_STR
9470 "Display routes matching the prefix-list\n"
9471 "IPv6 prefix-list name\n")
9472{
9473 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9474 bgp_show_type_prefix_list);
9475}
9476#endif /* HAVE_IPV6 */
6b0655a2 9477
94f2b392 9478static int
fd79ac91 9479bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
718e3744 9480 safi_t safi, enum bgp_show_type type)
9481{
9482 struct as_list *as_list;
9483
9484 as_list = as_list_lookup (filter);
9485 if (as_list == NULL)
9486 {
9487 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
9488 return CMD_WARNING;
9489 }
9490
b05a1c8b 9491 return bgp_show (vty, NULL, afi, safi, type, as_list, 0);
718e3744 9492}
9493
9494DEFUN (show_ip_bgp_filter_list,
9495 show_ip_bgp_filter_list_cmd,
9496 "show ip bgp filter-list WORD",
9497 SHOW_STR
9498 IP_STR
9499 BGP_STR
9500 "Display routes conforming to the filter-list\n"
9501 "Regular expression access list name\n")
9502{
9503 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
9504 bgp_show_type_filter_list);
9505}
9506
9507DEFUN (show_ip_bgp_flap_filter_list,
9508 show_ip_bgp_flap_filter_list_cmd,
9509 "show ip bgp flap-statistics filter-list WORD",
9510 SHOW_STR
9511 IP_STR
9512 BGP_STR
9513 "Display flap statistics of routes\n"
9514 "Display routes conforming to the filter-list\n"
9515 "Regular expression access list name\n")
9516{
9517 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
9518 bgp_show_type_flap_filter_list);
9519}
9520
9521DEFUN (show_ip_bgp_ipv4_filter_list,
9522 show_ip_bgp_ipv4_filter_list_cmd,
9523 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
9524 SHOW_STR
9525 IP_STR
9526 BGP_STR
9527 "Address family\n"
9528 "Address Family modifier\n"
9529 "Address Family modifier\n"
9530 "Display routes conforming to the filter-list\n"
9531 "Regular expression access list name\n")
9532{
9533 if (strncmp (argv[0], "m", 1) == 0)
9534 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9535 bgp_show_type_filter_list);
9536
9537 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
9538 bgp_show_type_filter_list);
9539}
9540
9541#ifdef HAVE_IPV6
9542DEFUN (show_bgp_filter_list,
9543 show_bgp_filter_list_cmd,
9544 "show bgp filter-list WORD",
9545 SHOW_STR
9546 BGP_STR
9547 "Display routes conforming to the filter-list\n"
9548 "Regular expression access list name\n")
9549{
9550 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9551 bgp_show_type_filter_list);
9552}
9553
9554ALIAS (show_bgp_filter_list,
9555 show_bgp_ipv6_filter_list_cmd,
9556 "show bgp ipv6 filter-list WORD",
9557 SHOW_STR
9558 BGP_STR
9559 "Address family\n"
9560 "Display routes conforming to the filter-list\n"
9561 "Regular expression access list name\n")
9562
9563/* old command */
9564DEFUN (show_ipv6_bgp_filter_list,
9565 show_ipv6_bgp_filter_list_cmd,
9566 "show ipv6 bgp filter-list WORD",
9567 SHOW_STR
9568 IPV6_STR
9569 BGP_STR
9570 "Display routes conforming to the filter-list\n"
9571 "Regular expression access list name\n")
9572{
9573 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9574 bgp_show_type_filter_list);
9575}
9576
9577/* old command */
9578DEFUN (show_ipv6_mbgp_filter_list,
9579 show_ipv6_mbgp_filter_list_cmd,
9580 "show ipv6 mbgp filter-list WORD",
9581 SHOW_STR
9582 IPV6_STR
9583 MBGP_STR
9584 "Display routes conforming to the filter-list\n"
9585 "Regular expression access list name\n")
9586{
9587 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9588 bgp_show_type_filter_list);
9589}
9590#endif /* HAVE_IPV6 */
6b0655a2 9591
94f2b392 9592static int
fd79ac91 9593bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
718e3744 9594 safi_t safi, enum bgp_show_type type)
9595{
9596 struct route_map *rmap;
9597
9598 rmap = route_map_lookup_by_name (rmap_str);
9599 if (! rmap)
9600 {
9601 vty_out (vty, "%% %s is not a valid route-map name%s",
9602 rmap_str, VTY_NEWLINE);
9603 return CMD_WARNING;
9604 }
9605
b05a1c8b 9606 return bgp_show (vty, NULL, afi, safi, type, rmap, 0);
718e3744 9607}
9608
9609DEFUN (show_ip_bgp_route_map,
9610 show_ip_bgp_route_map_cmd,
9611 "show ip bgp route-map WORD",
9612 SHOW_STR
9613 IP_STR
9614 BGP_STR
9615 "Display routes matching the route-map\n"
9616 "A route-map to match on\n")
9617{
9618 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
9619 bgp_show_type_route_map);
9620}
9621
9622DEFUN (show_ip_bgp_flap_route_map,
9623 show_ip_bgp_flap_route_map_cmd,
9624 "show ip bgp flap-statistics route-map WORD",
9625 SHOW_STR
9626 IP_STR
9627 BGP_STR
9628 "Display flap statistics of routes\n"
9629 "Display routes matching the route-map\n"
9630 "A route-map to match on\n")
9631{
9632 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
9633 bgp_show_type_flap_route_map);
9634}
9635
9636DEFUN (show_ip_bgp_ipv4_route_map,
9637 show_ip_bgp_ipv4_route_map_cmd,
9638 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
9639 SHOW_STR
9640 IP_STR
9641 BGP_STR
9642 "Address family\n"
9643 "Address Family modifier\n"
9644 "Address Family modifier\n"
9645 "Display routes matching the route-map\n"
9646 "A route-map to match on\n")
9647{
9648 if (strncmp (argv[0], "m", 1) == 0)
9649 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9650 bgp_show_type_route_map);
9651
9652 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
9653 bgp_show_type_route_map);
9654}
9655
9656DEFUN (show_bgp_route_map,
9657 show_bgp_route_map_cmd,
9658 "show bgp route-map WORD",
9659 SHOW_STR
9660 BGP_STR
9661 "Display routes matching the route-map\n"
9662 "A route-map to match on\n")
9663{
9664 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9665 bgp_show_type_route_map);
9666}
9667
9668ALIAS (show_bgp_route_map,
9669 show_bgp_ipv6_route_map_cmd,
9670 "show bgp ipv6 route-map WORD",
9671 SHOW_STR
9672 BGP_STR
9673 "Address family\n"
9674 "Display routes matching the route-map\n"
9675 "A route-map to match on\n")
6b0655a2 9676
718e3744 9677DEFUN (show_ip_bgp_cidr_only,
9678 show_ip_bgp_cidr_only_cmd,
9679 "show ip bgp cidr-only",
9680 SHOW_STR
9681 IP_STR
9682 BGP_STR
9683 "Display only routes with non-natural netmasks\n")
9684{
9685 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9686 bgp_show_type_cidr_only, NULL, 0);
718e3744 9687}
9688
9689DEFUN (show_ip_bgp_flap_cidr_only,
9690 show_ip_bgp_flap_cidr_only_cmd,
9691 "show ip bgp flap-statistics cidr-only",
9692 SHOW_STR
9693 IP_STR
9694 BGP_STR
9695 "Display flap statistics of routes\n"
9696 "Display only routes with non-natural netmasks\n")
9697{
9698 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9699 bgp_show_type_flap_cidr_only, NULL, 0);
718e3744 9700}
9701
9702DEFUN (show_ip_bgp_ipv4_cidr_only,
9703 show_ip_bgp_ipv4_cidr_only_cmd,
9704 "show ip bgp ipv4 (unicast|multicast) cidr-only",
9705 SHOW_STR
9706 IP_STR
9707 BGP_STR
9708 "Address family\n"
9709 "Address Family modifier\n"
9710 "Address Family modifier\n"
9711 "Display only routes with non-natural netmasks\n")
9712{
9713 if (strncmp (argv[0], "m", 1) == 0)
9714 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
b05a1c8b 9715 bgp_show_type_cidr_only, NULL, 0);
718e3744 9716
9717 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9718 bgp_show_type_cidr_only, NULL, 0);
718e3744 9719}
6b0655a2 9720
718e3744 9721DEFUN (show_ip_bgp_community_all,
9722 show_ip_bgp_community_all_cmd,
9723 "show ip bgp community",
9724 SHOW_STR
9725 IP_STR
9726 BGP_STR
9727 "Display routes matching the communities\n")
9728{
9729 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9730 bgp_show_type_community_all, NULL, 0);
718e3744 9731}
9732
9733DEFUN (show_ip_bgp_ipv4_community_all,
9734 show_ip_bgp_ipv4_community_all_cmd,
9735 "show ip bgp ipv4 (unicast|multicast) community",
9736 SHOW_STR
9737 IP_STR
9738 BGP_STR
9739 "Address family\n"
9740 "Address Family modifier\n"
9741 "Address Family modifier\n"
9742 "Display routes matching the communities\n")
9743{
9744 if (strncmp (argv[0], "m", 1) == 0)
9745 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
b05a1c8b 9746 bgp_show_type_community_all, NULL, 0);
718e3744 9747
9748 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9749 bgp_show_type_community_all, NULL, 0);
718e3744 9750}
9751
9752#ifdef HAVE_IPV6
9753DEFUN (show_bgp_community_all,
9754 show_bgp_community_all_cmd,
9755 "show bgp community",
9756 SHOW_STR
9757 BGP_STR
9758 "Display routes matching the communities\n")
9759{
9760 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 9761 bgp_show_type_community_all, NULL, 0);
718e3744 9762}
9763
9764ALIAS (show_bgp_community_all,
9765 show_bgp_ipv6_community_all_cmd,
9766 "show bgp ipv6 community",
9767 SHOW_STR
9768 BGP_STR
9769 "Address family\n"
9770 "Display routes matching the communities\n")
9771
9772/* old command */
9773DEFUN (show_ipv6_bgp_community_all,
9774 show_ipv6_bgp_community_all_cmd,
9775 "show ipv6 bgp community",
9776 SHOW_STR
9777 IPV6_STR
9778 BGP_STR
9779 "Display routes matching the communities\n")
9780{
9781 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 9782 bgp_show_type_community_all, NULL, 0);
718e3744 9783}
9784
9785/* old command */
9786DEFUN (show_ipv6_mbgp_community_all,
9787 show_ipv6_mbgp_community_all_cmd,
9788 "show ipv6 mbgp community",
9789 SHOW_STR
9790 IPV6_STR
9791 MBGP_STR
9792 "Display routes matching the communities\n")
9793{
9794 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
b05a1c8b 9795 bgp_show_type_community_all, NULL, 0);
718e3744 9796}
9797#endif /* HAVE_IPV6 */
6b0655a2 9798
94f2b392 9799static int
95cbbd2a
ML
9800bgp_show_community (struct vty *vty, const char *view_name, int argc,
9801 const char **argv, int exact, afi_t afi, safi_t safi)
718e3744 9802{
9803 struct community *com;
9804 struct buffer *b;
95cbbd2a 9805 struct bgp *bgp;
718e3744 9806 int i;
9807 char *str;
9808 int first = 0;
9809
95cbbd2a
ML
9810 /* BGP structure lookup */
9811 if (view_name)
9812 {
9813 bgp = bgp_lookup_by_name (view_name);
9814 if (bgp == NULL)
9815 {
9816 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9817 return CMD_WARNING;
9818 }
9819 }
9820 else
9821 {
9822 bgp = bgp_get_default ();
9823 if (bgp == NULL)
9824 {
9825 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9826 return CMD_WARNING;
9827 }
9828 }
9829
718e3744 9830 b = buffer_new (1024);
9831 for (i = 0; i < argc; i++)
9832 {
9833 if (first)
9834 buffer_putc (b, ' ');
9835 else
9836 {
9837 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9838 continue;
9839 first = 1;
9840 }
9841
9842 buffer_putstr (b, argv[i]);
9843 }
9844 buffer_putc (b, '\0');
9845
9846 str = buffer_getstr (b);
9847 buffer_free (b);
9848
9849 com = community_str2com (str);
3b8b1855 9850 XFREE (MTYPE_TMP, str);
718e3744 9851 if (! com)
9852 {
9853 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9854 return CMD_WARNING;
9855 }
9856
95cbbd2a 9857 return bgp_show (vty, bgp, afi, safi,
5a646650 9858 (exact ? bgp_show_type_community_exact :
b05a1c8b 9859 bgp_show_type_community), com, 0);
718e3744 9860}
9861
9862DEFUN (show_ip_bgp_community,
9863 show_ip_bgp_community_cmd,
9864 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9865 SHOW_STR
9866 IP_STR
9867 BGP_STR
9868 "Display routes matching the communities\n"
9869 "community number\n"
9870 "Do not send outside local AS (well-known community)\n"
9871 "Do not advertise to any peer (well-known community)\n"
9872 "Do not export to next AS (well-known community)\n")
9873{
95cbbd2a 9874 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 9875}
9876
9877ALIAS (show_ip_bgp_community,
9878 show_ip_bgp_community2_cmd,
9879 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9880 SHOW_STR
9881 IP_STR
9882 BGP_STR
9883 "Display routes matching the communities\n"
9884 "community number\n"
9885 "Do not send outside local AS (well-known community)\n"
9886 "Do not advertise to any peer (well-known community)\n"
9887 "Do not export to next AS (well-known community)\n"
9888 "community number\n"
9889 "Do not send outside local AS (well-known community)\n"
9890 "Do not advertise to any peer (well-known community)\n"
9891 "Do not export to next AS (well-known community)\n")
9892
9893ALIAS (show_ip_bgp_community,
9894 show_ip_bgp_community3_cmd,
9895 "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)",
9896 SHOW_STR
9897 IP_STR
9898 BGP_STR
9899 "Display routes matching the communities\n"
9900 "community number\n"
9901 "Do not send outside local AS (well-known community)\n"
9902 "Do not advertise to any peer (well-known community)\n"
9903 "Do not export to next AS (well-known community)\n"
9904 "community number\n"
9905 "Do not send outside local AS (well-known community)\n"
9906 "Do not advertise to any peer (well-known community)\n"
9907 "Do not export to next AS (well-known community)\n"
9908 "community number\n"
9909 "Do not send outside local AS (well-known community)\n"
9910 "Do not advertise to any peer (well-known community)\n"
9911 "Do not export to next AS (well-known community)\n")
9912
9913ALIAS (show_ip_bgp_community,
9914 show_ip_bgp_community4_cmd,
9915 "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)",
9916 SHOW_STR
9917 IP_STR
9918 BGP_STR
9919 "Display routes matching the communities\n"
9920 "community number\n"
9921 "Do not send outside local AS (well-known community)\n"
9922 "Do not advertise to any peer (well-known community)\n"
9923 "Do not export to next AS (well-known community)\n"
9924 "community number\n"
9925 "Do not send outside local AS (well-known community)\n"
9926 "Do not advertise to any peer (well-known community)\n"
9927 "Do not export to next AS (well-known community)\n"
9928 "community number\n"
9929 "Do not send outside local AS (well-known community)\n"
9930 "Do not advertise to any peer (well-known community)\n"
9931 "Do not export to next AS (well-known community)\n"
9932 "community number\n"
9933 "Do not send outside local AS (well-known community)\n"
9934 "Do not advertise to any peer (well-known community)\n"
9935 "Do not export to next AS (well-known community)\n")
9936
9937DEFUN (show_ip_bgp_ipv4_community,
9938 show_ip_bgp_ipv4_community_cmd,
9939 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9940 SHOW_STR
9941 IP_STR
9942 BGP_STR
9943 "Address family\n"
9944 "Address Family modifier\n"
9945 "Address Family modifier\n"
9946 "Display routes matching the communities\n"
9947 "community number\n"
9948 "Do not send outside local AS (well-known community)\n"
9949 "Do not advertise to any peer (well-known community)\n"
9950 "Do not export to next AS (well-known community)\n")
9951{
9952 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 9953 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
718e3744 9954
95cbbd2a 9955 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 9956}
9957
9958ALIAS (show_ip_bgp_ipv4_community,
9959 show_ip_bgp_ipv4_community2_cmd,
9960 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9961 SHOW_STR
9962 IP_STR
9963 BGP_STR
9964 "Address family\n"
9965 "Address Family modifier\n"
9966 "Address Family modifier\n"
9967 "Display routes matching the communities\n"
9968 "community number\n"
9969 "Do not send outside local AS (well-known community)\n"
9970 "Do not advertise to any peer (well-known community)\n"
9971 "Do not export to next AS (well-known community)\n"
9972 "community number\n"
9973 "Do not send outside local AS (well-known community)\n"
9974 "Do not advertise to any peer (well-known community)\n"
9975 "Do not export to next AS (well-known community)\n")
9976
9977ALIAS (show_ip_bgp_ipv4_community,
9978 show_ip_bgp_ipv4_community3_cmd,
9979 "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)",
9980 SHOW_STR
9981 IP_STR
9982 BGP_STR
9983 "Address family\n"
9984 "Address Family modifier\n"
9985 "Address Family modifier\n"
9986 "Display routes matching the communities\n"
9987 "community number\n"
9988 "Do not send outside local AS (well-known community)\n"
9989 "Do not advertise to any peer (well-known community)\n"
9990 "Do not export to next AS (well-known community)\n"
9991 "community number\n"
9992 "Do not send outside local AS (well-known community)\n"
9993 "Do not advertise to any peer (well-known community)\n"
9994 "Do not export to next AS (well-known community)\n"
9995 "community number\n"
9996 "Do not send outside local AS (well-known community)\n"
9997 "Do not advertise to any peer (well-known community)\n"
9998 "Do not export to next AS (well-known community)\n")
9999
10000ALIAS (show_ip_bgp_ipv4_community,
10001 show_ip_bgp_ipv4_community4_cmd,
10002 "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)",
10003 SHOW_STR
10004 IP_STR
10005 BGP_STR
10006 "Address family\n"
10007 "Address Family modifier\n"
10008 "Address Family modifier\n"
10009 "Display routes matching the communities\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 "community number\n"
10015 "Do not send outside local AS (well-known community)\n"
10016 "Do not advertise to any peer (well-known community)\n"
10017 "Do not export to next AS (well-known community)\n"
10018 "community number\n"
10019 "Do not send outside local AS (well-known community)\n"
10020 "Do not advertise to any peer (well-known community)\n"
10021 "Do not export to next AS (well-known community)\n"
10022 "community number\n"
10023 "Do not send outside local AS (well-known community)\n"
10024 "Do not advertise to any peer (well-known community)\n"
10025 "Do not export to next AS (well-known community)\n")
10026
95cbbd2a
ML
10027DEFUN (show_bgp_view_afi_safi_community_all,
10028 show_bgp_view_afi_safi_community_all_cmd,
10029#ifdef HAVE_IPV6
10030 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
10031#else
10032 "show bgp view WORD ipv4 (unicast|multicast) community",
10033#endif
10034 SHOW_STR
10035 BGP_STR
10036 "BGP view\n"
2b00515a 10037 "View name\n"
95cbbd2a
ML
10038 "Address family\n"
10039#ifdef HAVE_IPV6
10040 "Address family\n"
10041#endif
10042 "Address Family modifier\n"
10043 "Address Family modifier\n"
2b00515a 10044 "Display routes matching the communities\n")
95cbbd2a
ML
10045{
10046 int afi;
10047 int safi;
10048 struct bgp *bgp;
10049
10050 /* BGP structure lookup. */
10051 bgp = bgp_lookup_by_name (argv[0]);
10052 if (bgp == NULL)
10053 {
10054 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10055 return CMD_WARNING;
10056 }
10057
10058#ifdef HAVE_IPV6
10059 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10060 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10061#else
10062 afi = AFI_IP;
10063 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10064#endif
b05a1c8b 10065 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
95cbbd2a
ML
10066}
10067
10068DEFUN (show_bgp_view_afi_safi_community,
10069 show_bgp_view_afi_safi_community_cmd,
10070#ifdef HAVE_IPV6
10071 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10072#else
10073 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10074#endif
10075 SHOW_STR
10076 BGP_STR
10077 "BGP view\n"
2b00515a 10078 "View name\n"
95cbbd2a
ML
10079 "Address family\n"
10080#ifdef HAVE_IPV6
10081 "Address family\n"
10082#endif
10083 "Address family modifier\n"
10084 "Address family modifier\n"
10085 "Display routes matching the communities\n"
10086 "community number\n"
10087 "Do not send outside local AS (well-known community)\n"
10088 "Do not advertise to any peer (well-known community)\n"
10089 "Do not export to next AS (well-known community)\n")
10090{
10091 int afi;
10092 int safi;
10093
10094#ifdef HAVE_IPV6
10095 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10096 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10097 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
10098#else
10099 afi = AFI_IP;
10100 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10101 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
10102#endif
10103}
10104
10105ALIAS (show_bgp_view_afi_safi_community,
10106 show_bgp_view_afi_safi_community2_cmd,
10107#ifdef HAVE_IPV6
10108 "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)",
10109#else
10110 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10111#endif
10112 SHOW_STR
10113 BGP_STR
10114 "BGP view\n"
2b00515a 10115 "View name\n"
95cbbd2a
ML
10116 "Address family\n"
10117#ifdef HAVE_IPV6
10118 "Address family\n"
10119#endif
10120 "Address family modifier\n"
10121 "Address family modifier\n"
10122 "Display routes matching the communities\n"
10123 "community number\n"
10124 "Do not send outside local AS (well-known community)\n"
10125 "Do not advertise to any peer (well-known community)\n"
10126 "Do not export to next AS (well-known community)\n"
10127 "community number\n"
10128 "Do not send outside local AS (well-known community)\n"
10129 "Do not advertise to any peer (well-known community)\n"
10130 "Do not export to next AS (well-known community)\n")
10131
10132ALIAS (show_bgp_view_afi_safi_community,
10133 show_bgp_view_afi_safi_community3_cmd,
10134#ifdef HAVE_IPV6
10135 "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)",
10136#else
10137 "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)",
10138#endif
10139 SHOW_STR
10140 BGP_STR
10141 "BGP view\n"
2b00515a 10142 "View name\n"
95cbbd2a
ML
10143 "Address family\n"
10144#ifdef HAVE_IPV6
10145 "Address family\n"
10146#endif
10147 "Address family modifier\n"
10148 "Address family modifier\n"
10149 "Display routes matching the communities\n"
10150 "community number\n"
10151 "Do not send outside local AS (well-known community)\n"
10152 "Do not advertise to any peer (well-known community)\n"
10153 "Do not export to next AS (well-known community)\n"
10154 "community number\n"
10155 "Do not send outside local AS (well-known community)\n"
10156 "Do not advertise to any peer (well-known community)\n"
10157 "Do not export to next AS (well-known community)\n"
10158 "community number\n"
10159 "Do not send outside local AS (well-known community)\n"
10160 "Do not advertise to any peer (well-known community)\n"
10161 "Do not export to next AS (well-known community)\n")
10162
10163ALIAS (show_bgp_view_afi_safi_community,
10164 show_bgp_view_afi_safi_community4_cmd,
10165#ifdef HAVE_IPV6
10166 "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)",
10167#else
10168 "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)",
10169#endif
10170 SHOW_STR
10171 BGP_STR
10172 "BGP view\n"
2b00515a 10173 "View name\n"
95cbbd2a
ML
10174 "Address family\n"
10175#ifdef HAVE_IPV6
10176 "Address family\n"
10177#endif
10178 "Address family modifier\n"
10179 "Address family modifier\n"
10180 "Display routes matching the communities\n"
10181 "community number\n"
10182 "Do not send outside local AS (well-known community)\n"
10183 "Do not advertise to any peer (well-known community)\n"
10184 "Do not export to next AS (well-known community)\n"
10185 "community number\n"
10186 "Do not send outside local AS (well-known community)\n"
10187 "Do not advertise to any peer (well-known community)\n"
10188 "Do not export to next AS (well-known community)\n"
10189 "community number\n"
10190 "Do not send outside local AS (well-known community)\n"
10191 "Do not advertise to any peer (well-known community)\n"
10192 "Do not export to next AS (well-known community)\n"
10193 "community number\n"
10194 "Do not send outside local AS (well-known community)\n"
10195 "Do not advertise to any peer (well-known community)\n"
10196 "Do not export to next AS (well-known community)\n")
10197
718e3744 10198DEFUN (show_ip_bgp_community_exact,
10199 show_ip_bgp_community_exact_cmd,
10200 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10201 SHOW_STR
10202 IP_STR
10203 BGP_STR
10204 "Display routes matching the communities\n"
10205 "community number\n"
10206 "Do not send outside local AS (well-known community)\n"
10207 "Do not advertise to any peer (well-known community)\n"
10208 "Do not export to next AS (well-known community)\n"
10209 "Exact match of the communities")
10210{
95cbbd2a 10211 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 10212}
10213
10214ALIAS (show_ip_bgp_community_exact,
10215 show_ip_bgp_community2_exact_cmd,
10216 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10217 SHOW_STR
10218 IP_STR
10219 BGP_STR
10220 "Display routes matching the communities\n"
10221 "community number\n"
10222 "Do not send outside local AS (well-known community)\n"
10223 "Do not advertise to any peer (well-known community)\n"
10224 "Do not export to next AS (well-known community)\n"
10225 "community number\n"
10226 "Do not send outside local AS (well-known community)\n"
10227 "Do not advertise to any peer (well-known community)\n"
10228 "Do not export to next AS (well-known community)\n"
10229 "Exact match of the communities")
10230
10231ALIAS (show_ip_bgp_community_exact,
10232 show_ip_bgp_community3_exact_cmd,
10233 "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",
10234 SHOW_STR
10235 IP_STR
10236 BGP_STR
10237 "Display routes matching the communities\n"
10238 "community number\n"
10239 "Do not send outside local AS (well-known community)\n"
10240 "Do not advertise to any peer (well-known community)\n"
10241 "Do not export to next AS (well-known community)\n"
10242 "community number\n"
10243 "Do not send outside local AS (well-known community)\n"
10244 "Do not advertise to any peer (well-known community)\n"
10245 "Do not export to next AS (well-known community)\n"
10246 "community number\n"
10247 "Do not send outside local AS (well-known community)\n"
10248 "Do not advertise to any peer (well-known community)\n"
10249 "Do not export to next AS (well-known community)\n"
10250 "Exact match of the communities")
10251
10252ALIAS (show_ip_bgp_community_exact,
10253 show_ip_bgp_community4_exact_cmd,
10254 "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",
10255 SHOW_STR
10256 IP_STR
10257 BGP_STR
10258 "Display routes matching the communities\n"
10259 "community number\n"
10260 "Do not send outside local AS (well-known community)\n"
10261 "Do not advertise to any peer (well-known community)\n"
10262 "Do not export to next AS (well-known community)\n"
10263 "community number\n"
10264 "Do not send outside local AS (well-known community)\n"
10265 "Do not advertise to any peer (well-known community)\n"
10266 "Do not export to next AS (well-known community)\n"
10267 "community number\n"
10268 "Do not send outside local AS (well-known community)\n"
10269 "Do not advertise to any peer (well-known community)\n"
10270 "Do not export to next AS (well-known community)\n"
10271 "community number\n"
10272 "Do not send outside local AS (well-known community)\n"
10273 "Do not advertise to any peer (well-known community)\n"
10274 "Do not export to next AS (well-known community)\n"
10275 "Exact match of the communities")
10276
10277DEFUN (show_ip_bgp_ipv4_community_exact,
10278 show_ip_bgp_ipv4_community_exact_cmd,
10279 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10280 SHOW_STR
10281 IP_STR
10282 BGP_STR
10283 "Address family\n"
10284 "Address Family modifier\n"
10285 "Address Family modifier\n"
10286 "Display routes matching the communities\n"
10287 "community number\n"
10288 "Do not send outside local AS (well-known community)\n"
10289 "Do not advertise to any peer (well-known community)\n"
10290 "Do not export to next AS (well-known community)\n"
10291 "Exact match of the communities")
10292{
10293 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 10294 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
718e3744 10295
95cbbd2a 10296 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 10297}
10298
10299ALIAS (show_ip_bgp_ipv4_community_exact,
10300 show_ip_bgp_ipv4_community2_exact_cmd,
10301 "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",
10302 SHOW_STR
10303 IP_STR
10304 BGP_STR
10305 "Address family\n"
10306 "Address Family modifier\n"
10307 "Address Family modifier\n"
10308 "Display routes matching the communities\n"
10309 "community number\n"
10310 "Do not send outside local AS (well-known community)\n"
10311 "Do not advertise to any peer (well-known community)\n"
10312 "Do not export to next AS (well-known community)\n"
10313 "community number\n"
10314 "Do not send outside local AS (well-known community)\n"
10315 "Do not advertise to any peer (well-known community)\n"
10316 "Do not export to next AS (well-known community)\n"
10317 "Exact match of the communities")
10318
10319ALIAS (show_ip_bgp_ipv4_community_exact,
10320 show_ip_bgp_ipv4_community3_exact_cmd,
10321 "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",
10322 SHOW_STR
10323 IP_STR
10324 BGP_STR
10325 "Address family\n"
10326 "Address Family modifier\n"
10327 "Address Family modifier\n"
10328 "Display routes matching the communities\n"
10329 "community number\n"
10330 "Do not send outside local AS (well-known community)\n"
10331 "Do not advertise to any peer (well-known community)\n"
10332 "Do not export to next AS (well-known community)\n"
10333 "community number\n"
10334 "Do not send outside local AS (well-known community)\n"
10335 "Do not advertise to any peer (well-known community)\n"
10336 "Do not export to next AS (well-known community)\n"
10337 "community number\n"
10338 "Do not send outside local AS (well-known community)\n"
10339 "Do not advertise to any peer (well-known community)\n"
10340 "Do not export to next AS (well-known community)\n"
10341 "Exact match of the communities")
10342
10343ALIAS (show_ip_bgp_ipv4_community_exact,
10344 show_ip_bgp_ipv4_community4_exact_cmd,
10345 "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",
10346 SHOW_STR
10347 IP_STR
10348 BGP_STR
10349 "Address family\n"
10350 "Address Family modifier\n"
10351 "Address Family modifier\n"
10352 "Display routes matching the communities\n"
10353 "community number\n"
10354 "Do not send outside local AS (well-known community)\n"
10355 "Do not advertise to any peer (well-known community)\n"
10356 "Do not export to next AS (well-known community)\n"
10357 "community number\n"
10358 "Do not send outside local AS (well-known community)\n"
10359 "Do not advertise to any peer (well-known community)\n"
10360 "Do not export to next AS (well-known community)\n"
10361 "community number\n"
10362 "Do not send outside local AS (well-known community)\n"
10363 "Do not advertise to any peer (well-known community)\n"
10364 "Do not export to next AS (well-known community)\n"
10365 "community number\n"
10366 "Do not send outside local AS (well-known community)\n"
10367 "Do not advertise to any peer (well-known community)\n"
10368 "Do not export to next AS (well-known community)\n"
10369 "Exact match of the communities")
10370
10371#ifdef HAVE_IPV6
10372DEFUN (show_bgp_community,
10373 show_bgp_community_cmd,
10374 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
10375 SHOW_STR
10376 BGP_STR
10377 "Display routes matching the communities\n"
10378 "community number\n"
10379 "Do not send outside local AS (well-known community)\n"
10380 "Do not advertise to any peer (well-known community)\n"
10381 "Do not export to next AS (well-known community)\n")
10382{
95cbbd2a 10383 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 10384}
10385
10386ALIAS (show_bgp_community,
10387 show_bgp_ipv6_community_cmd,
10388 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
10389 SHOW_STR
10390 BGP_STR
10391 "Address family\n"
10392 "Display routes matching the communities\n"
10393 "community number\n"
10394 "Do not send outside local AS (well-known community)\n"
10395 "Do not advertise to any peer (well-known community)\n"
10396 "Do not export to next AS (well-known community)\n")
10397
10398ALIAS (show_bgp_community,
10399 show_bgp_community2_cmd,
10400 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10401 SHOW_STR
10402 BGP_STR
10403 "Display routes matching the communities\n"
10404 "community number\n"
10405 "Do not send outside local AS (well-known community)\n"
10406 "Do not advertise to any peer (well-known community)\n"
10407 "Do not export to next AS (well-known community)\n"
10408 "community number\n"
10409 "Do not send outside local AS (well-known community)\n"
10410 "Do not advertise to any peer (well-known community)\n"
10411 "Do not export to next AS (well-known community)\n")
10412
10413ALIAS (show_bgp_community,
10414 show_bgp_ipv6_community2_cmd,
10415 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10416 SHOW_STR
10417 BGP_STR
10418 "Address family\n"
10419 "Display routes matching the communities\n"
10420 "community number\n"
10421 "Do not send outside local AS (well-known community)\n"
10422 "Do not advertise to any peer (well-known community)\n"
10423 "Do not export to next AS (well-known community)\n"
10424 "community number\n"
10425 "Do not send outside local AS (well-known community)\n"
10426 "Do not advertise to any peer (well-known community)\n"
10427 "Do not export to next AS (well-known community)\n")
10428
10429ALIAS (show_bgp_community,
10430 show_bgp_community3_cmd,
10431 "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)",
10432 SHOW_STR
10433 BGP_STR
10434 "Display routes matching the communities\n"
10435 "community number\n"
10436 "Do not send outside local AS (well-known community)\n"
10437 "Do not advertise to any peer (well-known community)\n"
10438 "Do not export to next AS (well-known community)\n"
10439 "community number\n"
10440 "Do not send outside local AS (well-known community)\n"
10441 "Do not advertise to any peer (well-known community)\n"
10442 "Do not export to next AS (well-known community)\n"
10443 "community number\n"
10444 "Do not send outside local AS (well-known community)\n"
10445 "Do not advertise to any peer (well-known community)\n"
10446 "Do not export to next AS (well-known community)\n")
10447
10448ALIAS (show_bgp_community,
10449 show_bgp_ipv6_community3_cmd,
10450 "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)",
10451 SHOW_STR
10452 BGP_STR
10453 "Address family\n"
10454 "Display routes matching the communities\n"
10455 "community number\n"
10456 "Do not send outside local AS (well-known community)\n"
10457 "Do not advertise to any peer (well-known community)\n"
10458 "Do not export to next AS (well-known community)\n"
10459 "community number\n"
10460 "Do not send outside local AS (well-known community)\n"
10461 "Do not advertise to any peer (well-known community)\n"
10462 "Do not export to next AS (well-known community)\n"
10463 "community number\n"
10464 "Do not send outside local AS (well-known community)\n"
10465 "Do not advertise to any peer (well-known community)\n"
10466 "Do not export to next AS (well-known community)\n")
10467
10468ALIAS (show_bgp_community,
10469 show_bgp_community4_cmd,
10470 "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)",
10471 SHOW_STR
10472 BGP_STR
10473 "Display routes matching the communities\n"
10474 "community number\n"
10475 "Do not send outside local AS (well-known community)\n"
10476 "Do not advertise to any peer (well-known community)\n"
10477 "Do not export to next AS (well-known community)\n"
10478 "community number\n"
10479 "Do not send outside local AS (well-known community)\n"
10480 "Do not advertise to any peer (well-known community)\n"
10481 "Do not export to next AS (well-known community)\n"
10482 "community number\n"
10483 "Do not send outside local AS (well-known community)\n"
10484 "Do not advertise to any peer (well-known community)\n"
10485 "Do not export to next AS (well-known community)\n"
10486 "community number\n"
10487 "Do not send outside local AS (well-known community)\n"
10488 "Do not advertise to any peer (well-known community)\n"
10489 "Do not export to next AS (well-known community)\n")
10490
10491ALIAS (show_bgp_community,
10492 show_bgp_ipv6_community4_cmd,
10493 "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)",
10494 SHOW_STR
10495 BGP_STR
10496 "Address family\n"
10497 "Display routes matching the communities\n"
10498 "community number\n"
10499 "Do not send outside local AS (well-known community)\n"
10500 "Do not advertise to any peer (well-known community)\n"
10501 "Do not export to next AS (well-known community)\n"
10502 "community number\n"
10503 "Do not send outside local AS (well-known community)\n"
10504 "Do not advertise to any peer (well-known community)\n"
10505 "Do not export to next AS (well-known community)\n"
10506 "community number\n"
10507 "Do not send outside local AS (well-known community)\n"
10508 "Do not advertise to any peer (well-known community)\n"
10509 "Do not export to next AS (well-known community)\n"
10510 "community number\n"
10511 "Do not send outside local AS (well-known community)\n"
10512 "Do not advertise to any peer (well-known community)\n"
10513 "Do not export to next AS (well-known community)\n")
10514
10515/* old command */
10516DEFUN (show_ipv6_bgp_community,
10517 show_ipv6_bgp_community_cmd,
10518 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
10519 SHOW_STR
10520 IPV6_STR
10521 BGP_STR
10522 "Display routes matching the communities\n"
10523 "community number\n"
10524 "Do not send outside local AS (well-known community)\n"
10525 "Do not advertise to any peer (well-known community)\n"
10526 "Do not export to next AS (well-known community)\n")
10527{
95cbbd2a 10528 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 10529}
10530
10531/* old command */
10532ALIAS (show_ipv6_bgp_community,
10533 show_ipv6_bgp_community2_cmd,
10534 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10535 SHOW_STR
10536 IPV6_STR
10537 BGP_STR
10538 "Display routes matching the communities\n"
10539 "community number\n"
10540 "Do not send outside local AS (well-known community)\n"
10541 "Do not advertise to any peer (well-known community)\n"
10542 "Do not export to next AS (well-known community)\n"
10543 "community number\n"
10544 "Do not send outside local AS (well-known community)\n"
10545 "Do not advertise to any peer (well-known community)\n"
10546 "Do not export to next AS (well-known community)\n")
10547
10548/* old command */
10549ALIAS (show_ipv6_bgp_community,
10550 show_ipv6_bgp_community3_cmd,
10551 "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)",
10552 SHOW_STR
10553 IPV6_STR
10554 BGP_STR
10555 "Display routes matching the communities\n"
10556 "community number\n"
10557 "Do not send outside local AS (well-known community)\n"
10558 "Do not advertise to any peer (well-known community)\n"
10559 "Do not export to next AS (well-known community)\n"
10560 "community number\n"
10561 "Do not send outside local AS (well-known community)\n"
10562 "Do not advertise to any peer (well-known community)\n"
10563 "Do not export to next AS (well-known community)\n"
10564 "community number\n"
10565 "Do not send outside local AS (well-known community)\n"
10566 "Do not advertise to any peer (well-known community)\n"
10567 "Do not export to next AS (well-known community)\n")
10568
10569/* old command */
10570ALIAS (show_ipv6_bgp_community,
10571 show_ipv6_bgp_community4_cmd,
10572 "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)",
10573 SHOW_STR
10574 IPV6_STR
10575 BGP_STR
10576 "Display routes matching the communities\n"
10577 "community number\n"
10578 "Do not send outside local AS (well-known community)\n"
10579 "Do not advertise to any peer (well-known community)\n"
10580 "Do not export to next AS (well-known community)\n"
10581 "community number\n"
10582 "Do not send outside local AS (well-known community)\n"
10583 "Do not advertise to any peer (well-known community)\n"
10584 "Do not export to next AS (well-known community)\n"
10585 "community number\n"
10586 "Do not send outside local AS (well-known community)\n"
10587 "Do not advertise to any peer (well-known community)\n"
10588 "Do not export to next AS (well-known community)\n"
10589 "community number\n"
10590 "Do not send outside local AS (well-known community)\n"
10591 "Do not advertise to any peer (well-known community)\n"
10592 "Do not export to next AS (well-known community)\n")
10593
10594DEFUN (show_bgp_community_exact,
10595 show_bgp_community_exact_cmd,
10596 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10597 SHOW_STR
10598 BGP_STR
10599 "Display routes matching the communities\n"
10600 "community number\n"
10601 "Do not send outside local AS (well-known community)\n"
10602 "Do not advertise to any peer (well-known community)\n"
10603 "Do not export to next AS (well-known community)\n"
10604 "Exact match of the communities")
10605{
95cbbd2a 10606 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 10607}
10608
10609ALIAS (show_bgp_community_exact,
10610 show_bgp_ipv6_community_exact_cmd,
10611 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10612 SHOW_STR
10613 BGP_STR
10614 "Address family\n"
10615 "Display routes matching the communities\n"
10616 "community number\n"
10617 "Do not send outside local AS (well-known community)\n"
10618 "Do not advertise to any peer (well-known community)\n"
10619 "Do not export to next AS (well-known community)\n"
10620 "Exact match of the communities")
10621
10622ALIAS (show_bgp_community_exact,
10623 show_bgp_community2_exact_cmd,
10624 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10625 SHOW_STR
10626 BGP_STR
10627 "Display routes matching the communities\n"
10628 "community number\n"
10629 "Do not send outside local AS (well-known community)\n"
10630 "Do not advertise to any peer (well-known community)\n"
10631 "Do not export to next AS (well-known community)\n"
10632 "community number\n"
10633 "Do not send outside local AS (well-known community)\n"
10634 "Do not advertise to any peer (well-known community)\n"
10635 "Do not export to next AS (well-known community)\n"
10636 "Exact match of the communities")
10637
10638ALIAS (show_bgp_community_exact,
10639 show_bgp_ipv6_community2_exact_cmd,
10640 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10641 SHOW_STR
10642 BGP_STR
10643 "Address family\n"
10644 "Display routes matching the communities\n"
10645 "community number\n"
10646 "Do not send outside local AS (well-known community)\n"
10647 "Do not advertise to any peer (well-known community)\n"
10648 "Do not export to next AS (well-known community)\n"
10649 "community number\n"
10650 "Do not send outside local AS (well-known community)\n"
10651 "Do not advertise to any peer (well-known community)\n"
10652 "Do not export to next AS (well-known community)\n"
10653 "Exact match of the communities")
10654
10655ALIAS (show_bgp_community_exact,
10656 show_bgp_community3_exact_cmd,
10657 "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",
10658 SHOW_STR
10659 BGP_STR
10660 "Display routes matching the communities\n"
10661 "community number\n"
10662 "Do not send outside local AS (well-known community)\n"
10663 "Do not advertise to any peer (well-known community)\n"
10664 "Do not export to next AS (well-known community)\n"
10665 "community number\n"
10666 "Do not send outside local AS (well-known community)\n"
10667 "Do not advertise to any peer (well-known community)\n"
10668 "Do not export to next AS (well-known community)\n"
10669 "community number\n"
10670 "Do not send outside local AS (well-known community)\n"
10671 "Do not advertise to any peer (well-known community)\n"
10672 "Do not export to next AS (well-known community)\n"
10673 "Exact match of the communities")
10674
10675ALIAS (show_bgp_community_exact,
10676 show_bgp_ipv6_community3_exact_cmd,
10677 "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",
10678 SHOW_STR
10679 BGP_STR
10680 "Address family\n"
10681 "Display routes matching the communities\n"
10682 "community number\n"
10683 "Do not send outside local AS (well-known community)\n"
10684 "Do not advertise to any peer (well-known community)\n"
10685 "Do not export to next AS (well-known community)\n"
10686 "community number\n"
10687 "Do not send outside local AS (well-known community)\n"
10688 "Do not advertise to any peer (well-known community)\n"
10689 "Do not export to next AS (well-known community)\n"
10690 "community number\n"
10691 "Do not send outside local AS (well-known community)\n"
10692 "Do not advertise to any peer (well-known community)\n"
10693 "Do not export to next AS (well-known community)\n"
10694 "Exact match of the communities")
10695
10696ALIAS (show_bgp_community_exact,
10697 show_bgp_community4_exact_cmd,
10698 "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",
10699 SHOW_STR
10700 BGP_STR
10701 "Display routes matching the communities\n"
10702 "community number\n"
10703 "Do not send outside local AS (well-known community)\n"
10704 "Do not advertise to any peer (well-known community)\n"
10705 "Do not export to next AS (well-known community)\n"
10706 "community number\n"
10707 "Do not send outside local AS (well-known community)\n"
10708 "Do not advertise to any peer (well-known community)\n"
10709 "Do not export to next AS (well-known community)\n"
10710 "community number\n"
10711 "Do not send outside local AS (well-known community)\n"
10712 "Do not advertise to any peer (well-known community)\n"
10713 "Do not export to next AS (well-known community)\n"
10714 "community number\n"
10715 "Do not send outside local AS (well-known community)\n"
10716 "Do not advertise to any peer (well-known community)\n"
10717 "Do not export to next AS (well-known community)\n"
10718 "Exact match of the communities")
10719
10720ALIAS (show_bgp_community_exact,
10721 show_bgp_ipv6_community4_exact_cmd,
10722 "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",
10723 SHOW_STR
10724 BGP_STR
10725 "Address family\n"
10726 "Display routes matching the communities\n"
10727 "community number\n"
10728 "Do not send outside local AS (well-known community)\n"
10729 "Do not advertise to any peer (well-known community)\n"
10730 "Do not export to next AS (well-known community)\n"
10731 "community number\n"
10732 "Do not send outside local AS (well-known community)\n"
10733 "Do not advertise to any peer (well-known community)\n"
10734 "Do not export to next AS (well-known community)\n"
10735 "community number\n"
10736 "Do not send outside local AS (well-known community)\n"
10737 "Do not advertise to any peer (well-known community)\n"
10738 "Do not export to next AS (well-known community)\n"
10739 "community number\n"
10740 "Do not send outside local AS (well-known community)\n"
10741 "Do not advertise to any peer (well-known community)\n"
10742 "Do not export to next AS (well-known community)\n"
10743 "Exact match of the communities")
10744
10745/* old command */
10746DEFUN (show_ipv6_bgp_community_exact,
10747 show_ipv6_bgp_community_exact_cmd,
10748 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10749 SHOW_STR
10750 IPV6_STR
10751 BGP_STR
10752 "Display routes matching the communities\n"
10753 "community number\n"
10754 "Do not send outside local AS (well-known community)\n"
10755 "Do not advertise to any peer (well-known community)\n"
10756 "Do not export to next AS (well-known community)\n"
10757 "Exact match of the communities")
10758{
95cbbd2a 10759 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 10760}
10761
10762/* old command */
10763ALIAS (show_ipv6_bgp_community_exact,
10764 show_ipv6_bgp_community2_exact_cmd,
10765 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10766 SHOW_STR
10767 IPV6_STR
10768 BGP_STR
10769 "Display routes matching the communities\n"
10770 "community number\n"
10771 "Do not send outside local AS (well-known community)\n"
10772 "Do not advertise to any peer (well-known community)\n"
10773 "Do not export to next AS (well-known community)\n"
10774 "community number\n"
10775 "Do not send outside local AS (well-known community)\n"
10776 "Do not advertise to any peer (well-known community)\n"
10777 "Do not export to next AS (well-known community)\n"
10778 "Exact match of the communities")
10779
10780/* old command */
10781ALIAS (show_ipv6_bgp_community_exact,
10782 show_ipv6_bgp_community3_exact_cmd,
10783 "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",
10784 SHOW_STR
10785 IPV6_STR
10786 BGP_STR
10787 "Display routes matching the communities\n"
10788 "community number\n"
10789 "Do not send outside local AS (well-known community)\n"
10790 "Do not advertise to any peer (well-known community)\n"
10791 "Do not export to next AS (well-known community)\n"
10792 "community number\n"
10793 "Do not send outside local AS (well-known community)\n"
10794 "Do not advertise to any peer (well-known community)\n"
10795 "Do not export to next AS (well-known community)\n"
10796 "community number\n"
10797 "Do not send outside local AS (well-known community)\n"
10798 "Do not advertise to any peer (well-known community)\n"
10799 "Do not export to next AS (well-known community)\n"
10800 "Exact match of the communities")
10801
10802/* old command */
10803ALIAS (show_ipv6_bgp_community_exact,
10804 show_ipv6_bgp_community4_exact_cmd,
10805 "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",
10806 SHOW_STR
10807 IPV6_STR
10808 BGP_STR
10809 "Display routes matching the communities\n"
10810 "community number\n"
10811 "Do not send outside local AS (well-known community)\n"
10812 "Do not advertise to any peer (well-known community)\n"
10813 "Do not export to next AS (well-known community)\n"
10814 "community number\n"
10815 "Do not send outside local AS (well-known community)\n"
10816 "Do not advertise to any peer (well-known community)\n"
10817 "Do not export to next AS (well-known community)\n"
10818 "community number\n"
10819 "Do not send outside local AS (well-known community)\n"
10820 "Do not advertise to any peer (well-known community)\n"
10821 "Do not export to next AS (well-known community)\n"
10822 "community number\n"
10823 "Do not send outside local AS (well-known community)\n"
10824 "Do not advertise to any peer (well-known community)\n"
10825 "Do not export to next AS (well-known community)\n"
10826 "Exact match of the communities")
10827
10828/* old command */
10829DEFUN (show_ipv6_mbgp_community,
10830 show_ipv6_mbgp_community_cmd,
10831 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10832 SHOW_STR
10833 IPV6_STR
10834 MBGP_STR
10835 "Display routes matching the communities\n"
10836 "community number\n"
10837 "Do not send outside local AS (well-known community)\n"
10838 "Do not advertise to any peer (well-known community)\n"
10839 "Do not export to next AS (well-known community)\n")
10840{
95cbbd2a 10841 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
718e3744 10842}
10843
10844/* old command */
10845ALIAS (show_ipv6_mbgp_community,
10846 show_ipv6_mbgp_community2_cmd,
10847 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10848 SHOW_STR
10849 IPV6_STR
10850 MBGP_STR
10851 "Display routes matching the communities\n"
10852 "community number\n"
10853 "Do not send outside local AS (well-known community)\n"
10854 "Do not advertise to any peer (well-known community)\n"
10855 "Do not export to next AS (well-known community)\n"
10856 "community number\n"
10857 "Do not send outside local AS (well-known community)\n"
10858 "Do not advertise to any peer (well-known community)\n"
10859 "Do not export to next AS (well-known community)\n")
10860
10861/* old command */
10862ALIAS (show_ipv6_mbgp_community,
10863 show_ipv6_mbgp_community3_cmd,
10864 "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)",
10865 SHOW_STR
10866 IPV6_STR
10867 MBGP_STR
10868 "Display routes matching the communities\n"
10869 "community number\n"
10870 "Do not send outside local AS (well-known community)\n"
10871 "Do not advertise to any peer (well-known community)\n"
10872 "Do not export to next AS (well-known community)\n"
10873 "community number\n"
10874 "Do not send outside local AS (well-known community)\n"
10875 "Do not advertise to any peer (well-known community)\n"
10876 "Do not export to next AS (well-known community)\n"
10877 "community number\n"
10878 "Do not send outside local AS (well-known community)\n"
10879 "Do not advertise to any peer (well-known community)\n"
10880 "Do not export to next AS (well-known community)\n")
10881
10882/* old command */
10883ALIAS (show_ipv6_mbgp_community,
10884 show_ipv6_mbgp_community4_cmd,
10885 "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)",
10886 SHOW_STR
10887 IPV6_STR
10888 MBGP_STR
10889 "Display routes matching the communities\n"
10890 "community number\n"
10891 "Do not send outside local AS (well-known community)\n"
10892 "Do not advertise to any peer (well-known community)\n"
10893 "Do not export to next AS (well-known community)\n"
10894 "community number\n"
10895 "Do not send outside local AS (well-known community)\n"
10896 "Do not advertise to any peer (well-known community)\n"
10897 "Do not export to next AS (well-known community)\n"
10898 "community number\n"
10899 "Do not send outside local AS (well-known community)\n"
10900 "Do not advertise to any peer (well-known community)\n"
10901 "Do not export to next AS (well-known community)\n"
10902 "community number\n"
10903 "Do not send outside local AS (well-known community)\n"
10904 "Do not advertise to any peer (well-known community)\n"
10905 "Do not export to next AS (well-known community)\n")
10906
10907/* old command */
10908DEFUN (show_ipv6_mbgp_community_exact,
10909 show_ipv6_mbgp_community_exact_cmd,
10910 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10911 SHOW_STR
10912 IPV6_STR
10913 MBGP_STR
10914 "Display routes matching the communities\n"
10915 "community number\n"
10916 "Do not send outside local AS (well-known community)\n"
10917 "Do not advertise to any peer (well-known community)\n"
10918 "Do not export to next AS (well-known community)\n"
10919 "Exact match of the communities")
10920{
95cbbd2a 10921 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
718e3744 10922}
10923
10924/* old command */
10925ALIAS (show_ipv6_mbgp_community_exact,
10926 show_ipv6_mbgp_community2_exact_cmd,
10927 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10928 SHOW_STR
10929 IPV6_STR
10930 MBGP_STR
10931 "Display routes matching the communities\n"
10932 "community number\n"
10933 "Do not send outside local AS (well-known community)\n"
10934 "Do not advertise to any peer (well-known community)\n"
10935 "Do not export to next AS (well-known community)\n"
10936 "community number\n"
10937 "Do not send outside local AS (well-known community)\n"
10938 "Do not advertise to any peer (well-known community)\n"
10939 "Do not export to next AS (well-known community)\n"
10940 "Exact match of the communities")
10941
10942/* old command */
10943ALIAS (show_ipv6_mbgp_community_exact,
10944 show_ipv6_mbgp_community3_exact_cmd,
10945 "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",
10946 SHOW_STR
10947 IPV6_STR
10948 MBGP_STR
10949 "Display routes matching the communities\n"
10950 "community number\n"
10951 "Do not send outside local AS (well-known community)\n"
10952 "Do not advertise to any peer (well-known community)\n"
10953 "Do not export to next AS (well-known community)\n"
10954 "community number\n"
10955 "Do not send outside local AS (well-known community)\n"
10956 "Do not advertise to any peer (well-known community)\n"
10957 "Do not export to next AS (well-known community)\n"
10958 "community number\n"
10959 "Do not send outside local AS (well-known community)\n"
10960 "Do not advertise to any peer (well-known community)\n"
10961 "Do not export to next AS (well-known community)\n"
10962 "Exact match of the communities")
10963
10964/* old command */
10965ALIAS (show_ipv6_mbgp_community_exact,
10966 show_ipv6_mbgp_community4_exact_cmd,
10967 "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",
10968 SHOW_STR
10969 IPV6_STR
10970 MBGP_STR
10971 "Display routes matching the communities\n"
10972 "community number\n"
10973 "Do not send outside local AS (well-known community)\n"
10974 "Do not advertise to any peer (well-known community)\n"
10975 "Do not export to next AS (well-known community)\n"
10976 "community number\n"
10977 "Do not send outside local AS (well-known community)\n"
10978 "Do not advertise to any peer (well-known community)\n"
10979 "Do not export to next AS (well-known community)\n"
10980 "community number\n"
10981 "Do not send outside local AS (well-known community)\n"
10982 "Do not advertise to any peer (well-known community)\n"
10983 "Do not export to next AS (well-known community)\n"
10984 "community number\n"
10985 "Do not send outside local AS (well-known community)\n"
10986 "Do not advertise to any peer (well-known community)\n"
10987 "Do not export to next AS (well-known community)\n"
10988 "Exact match of the communities")
10989#endif /* HAVE_IPV6 */
6b0655a2 10990
94f2b392 10991static int
fd79ac91 10992bgp_show_community_list (struct vty *vty, const char *com, int exact,
4c9641ba 10993 afi_t afi, safi_t safi)
718e3744 10994{
10995 struct community_list *list;
10996
fee6e4e4 10997 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
718e3744 10998 if (list == NULL)
10999 {
11000 vty_out (vty, "%% %s is not a valid community-list name%s", com,
11001 VTY_NEWLINE);
11002 return CMD_WARNING;
11003 }
11004
5a646650 11005 return bgp_show (vty, NULL, afi, safi,
11006 (exact ? bgp_show_type_community_list_exact :
b05a1c8b 11007 bgp_show_type_community_list), list, 0);
718e3744 11008}
11009
11010DEFUN (show_ip_bgp_community_list,
11011 show_ip_bgp_community_list_cmd,
fee6e4e4 11012 "show ip bgp community-list (<1-500>|WORD)",
718e3744 11013 SHOW_STR
11014 IP_STR
11015 BGP_STR
11016 "Display routes matching the community-list\n"
fee6e4e4 11017 "community-list number\n"
718e3744 11018 "community-list name\n")
11019{
11020 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11021}
11022
11023DEFUN (show_ip_bgp_ipv4_community_list,
11024 show_ip_bgp_ipv4_community_list_cmd,
fee6e4e4 11025 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
718e3744 11026 SHOW_STR
11027 IP_STR
11028 BGP_STR
11029 "Address family\n"
11030 "Address Family modifier\n"
11031 "Address Family modifier\n"
11032 "Display routes matching the community-list\n"
fee6e4e4 11033 "community-list number\n"
718e3744 11034 "community-list name\n")
11035{
11036 if (strncmp (argv[0], "m", 1) == 0)
11037 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11038
11039 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11040}
11041
11042DEFUN (show_ip_bgp_community_list_exact,
11043 show_ip_bgp_community_list_exact_cmd,
fee6e4e4 11044 "show ip bgp community-list (<1-500>|WORD) exact-match",
718e3744 11045 SHOW_STR
11046 IP_STR
11047 BGP_STR
11048 "Display routes matching the community-list\n"
fee6e4e4 11049 "community-list number\n"
718e3744 11050 "community-list name\n"
11051 "Exact match of the communities\n")
11052{
11053 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11054}
11055
11056DEFUN (show_ip_bgp_ipv4_community_list_exact,
11057 show_ip_bgp_ipv4_community_list_exact_cmd,
fee6e4e4 11058 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
718e3744 11059 SHOW_STR
11060 IP_STR
11061 BGP_STR
11062 "Address family\n"
11063 "Address Family modifier\n"
11064 "Address Family modifier\n"
11065 "Display routes matching the community-list\n"
fee6e4e4 11066 "community-list number\n"
718e3744 11067 "community-list name\n"
11068 "Exact match of the communities\n")
11069{
11070 if (strncmp (argv[0], "m", 1) == 0)
11071 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11072
11073 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11074}
11075
11076#ifdef HAVE_IPV6
11077DEFUN (show_bgp_community_list,
11078 show_bgp_community_list_cmd,
fee6e4e4 11079 "show bgp community-list (<1-500>|WORD)",
718e3744 11080 SHOW_STR
11081 BGP_STR
11082 "Display routes matching the community-list\n"
fee6e4e4 11083 "community-list number\n"
718e3744 11084 "community-list name\n")
11085{
11086 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11087}
11088
11089ALIAS (show_bgp_community_list,
11090 show_bgp_ipv6_community_list_cmd,
fee6e4e4 11091 "show bgp ipv6 community-list (<1-500>|WORD)",
718e3744 11092 SHOW_STR
11093 BGP_STR
11094 "Address family\n"
11095 "Display routes matching the community-list\n"
fee6e4e4 11096 "community-list number\n"
e8e1946e 11097 "community-list name\n")
718e3744 11098
11099/* old command */
11100DEFUN (show_ipv6_bgp_community_list,
11101 show_ipv6_bgp_community_list_cmd,
11102 "show ipv6 bgp community-list WORD",
11103 SHOW_STR
11104 IPV6_STR
11105 BGP_STR
11106 "Display routes matching the community-list\n"
11107 "community-list name\n")
11108{
11109 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11110}
11111
11112/* old command */
11113DEFUN (show_ipv6_mbgp_community_list,
11114 show_ipv6_mbgp_community_list_cmd,
11115 "show ipv6 mbgp community-list WORD",
11116 SHOW_STR
11117 IPV6_STR
11118 MBGP_STR
11119 "Display routes matching the community-list\n"
11120 "community-list name\n")
11121{
11122 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
11123}
11124
11125DEFUN (show_bgp_community_list_exact,
11126 show_bgp_community_list_exact_cmd,
fee6e4e4 11127 "show bgp community-list (<1-500>|WORD) exact-match",
718e3744 11128 SHOW_STR
11129 BGP_STR
11130 "Display routes matching the community-list\n"
fee6e4e4 11131 "community-list number\n"
718e3744 11132 "community-list name\n"
11133 "Exact match of the communities\n")
11134{
11135 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11136}
11137
11138ALIAS (show_bgp_community_list_exact,
11139 show_bgp_ipv6_community_list_exact_cmd,
fee6e4e4 11140 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
718e3744 11141 SHOW_STR
11142 BGP_STR
11143 "Address family\n"
11144 "Display routes matching the community-list\n"
fee6e4e4 11145 "community-list number\n"
718e3744 11146 "community-list name\n"
11147 "Exact match of the communities\n")
11148
11149/* old command */
11150DEFUN (show_ipv6_bgp_community_list_exact,
11151 show_ipv6_bgp_community_list_exact_cmd,
11152 "show ipv6 bgp community-list WORD exact-match",
11153 SHOW_STR
11154 IPV6_STR
11155 BGP_STR
11156 "Display routes matching the community-list\n"
11157 "community-list name\n"
11158 "Exact match of the communities\n")
11159{
11160 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11161}
11162
11163/* old command */
11164DEFUN (show_ipv6_mbgp_community_list_exact,
11165 show_ipv6_mbgp_community_list_exact_cmd,
11166 "show ipv6 mbgp community-list WORD exact-match",
11167 SHOW_STR
11168 IPV6_STR
11169 MBGP_STR
11170 "Display routes matching the community-list\n"
11171 "community-list name\n"
11172 "Exact match of the communities\n")
11173{
11174 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
11175}
11176#endif /* HAVE_IPV6 */
6b0655a2 11177
94f2b392 11178static int
fd79ac91 11179bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
718e3744 11180 safi_t safi, enum bgp_show_type type)
11181{
11182 int ret;
11183 struct prefix *p;
11184
11185 p = prefix_new();
11186
11187 ret = str2prefix (prefix, p);
11188 if (! ret)
11189 {
11190 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11191 return CMD_WARNING;
11192 }
11193
b05a1c8b 11194 ret = bgp_show (vty, NULL, afi, safi, type, p, 0);
5a646650 11195 prefix_free(p);
11196 return ret;
718e3744 11197}
11198
11199DEFUN (show_ip_bgp_prefix_longer,
11200 show_ip_bgp_prefix_longer_cmd,
11201 "show ip bgp A.B.C.D/M longer-prefixes",
11202 SHOW_STR
11203 IP_STR
11204 BGP_STR
11205 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11206 "Display route and more specific routes\n")
11207{
11208 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11209 bgp_show_type_prefix_longer);
11210}
11211
11212DEFUN (show_ip_bgp_flap_prefix_longer,
11213 show_ip_bgp_flap_prefix_longer_cmd,
11214 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11215 SHOW_STR
11216 IP_STR
11217 BGP_STR
11218 "Display flap statistics of routes\n"
11219 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11220 "Display route and more specific routes\n")
11221{
11222 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11223 bgp_show_type_flap_prefix_longer);
11224}
11225
11226DEFUN (show_ip_bgp_ipv4_prefix_longer,
11227 show_ip_bgp_ipv4_prefix_longer_cmd,
11228 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11229 SHOW_STR
11230 IP_STR
11231 BGP_STR
11232 "Address family\n"
11233 "Address Family modifier\n"
11234 "Address Family modifier\n"
11235 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11236 "Display route and more specific routes\n")
11237{
11238 if (strncmp (argv[0], "m", 1) == 0)
11239 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
11240 bgp_show_type_prefix_longer);
11241
11242 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
11243 bgp_show_type_prefix_longer);
11244}
11245
11246DEFUN (show_ip_bgp_flap_address,
11247 show_ip_bgp_flap_address_cmd,
11248 "show ip bgp flap-statistics A.B.C.D",
11249 SHOW_STR
11250 IP_STR
11251 BGP_STR
11252 "Display flap statistics of routes\n"
11253 "Network in the BGP routing table to display\n")
11254{
11255 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11256 bgp_show_type_flap_address);
11257}
11258
11259DEFUN (show_ip_bgp_flap_prefix,
11260 show_ip_bgp_flap_prefix_cmd,
11261 "show ip bgp flap-statistics A.B.C.D/M",
11262 SHOW_STR
11263 IP_STR
11264 BGP_STR
11265 "Display flap statistics of routes\n"
11266 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11267{
11268 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11269 bgp_show_type_flap_prefix);
11270}
11271#ifdef HAVE_IPV6
11272DEFUN (show_bgp_prefix_longer,
11273 show_bgp_prefix_longer_cmd,
11274 "show bgp X:X::X:X/M longer-prefixes",
11275 SHOW_STR
11276 BGP_STR
11277 "IPv6 prefix <network>/<length>\n"
11278 "Display route and more specific routes\n")
11279{
11280 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11281 bgp_show_type_prefix_longer);
11282}
11283
11284ALIAS (show_bgp_prefix_longer,
11285 show_bgp_ipv6_prefix_longer_cmd,
11286 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11287 SHOW_STR
11288 BGP_STR
11289 "Address family\n"
11290 "IPv6 prefix <network>/<length>\n"
11291 "Display route and more specific routes\n")
11292
11293/* old command */
11294DEFUN (show_ipv6_bgp_prefix_longer,
11295 show_ipv6_bgp_prefix_longer_cmd,
11296 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11297 SHOW_STR
11298 IPV6_STR
11299 BGP_STR
11300 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11301 "Display route and more specific routes\n")
11302{
11303 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11304 bgp_show_type_prefix_longer);
11305}
11306
11307/* old command */
11308DEFUN (show_ipv6_mbgp_prefix_longer,
11309 show_ipv6_mbgp_prefix_longer_cmd,
11310 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11311 SHOW_STR
11312 IPV6_STR
11313 MBGP_STR
11314 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11315 "Display route and more specific routes\n")
11316{
11317 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
11318 bgp_show_type_prefix_longer);
11319}
11320#endif /* HAVE_IPV6 */
bb46e94f 11321
94f2b392 11322static struct peer *
fd79ac91 11323peer_lookup_in_view (struct vty *vty, const char *view_name,
856ca177 11324 const char *ip_str, u_char use_json)
bb46e94f 11325{
11326 int ret;
11327 struct bgp *bgp;
11328 struct peer *peer;
11329 union sockunion su;
11330
11331 /* BGP structure lookup. */
11332 if (view_name)
11333 {
11334 bgp = bgp_lookup_by_name (view_name);
11335 if (! bgp)
11336 {
856ca177
MS
11337 if (use_json)
11338 {
11339 json_object *json_no = NULL;
11340 json_no = json_object_new_object();
11341 json_object_string_add(json_no, "warning", "Can't find BGP view");
11342 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11343 json_object_free(json_no);
11344 }
11345 else
11346 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
bb46e94f 11347 return NULL;
11348 }
11349 }
5228ad27 11350 else
bb46e94f 11351 {
11352 bgp = bgp_get_default ();
11353 if (! bgp)
11354 {
856ca177
MS
11355 if (use_json)
11356 {
11357 json_object *json_no = NULL;
11358 json_no = json_object_new_object();
11359 json_object_string_add(json_no, "warning", "No BGP process configured");
11360 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11361 json_object_free(json_no);
11362 }
11363 else
11364 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
bb46e94f 11365 return NULL;
11366 }
11367 }
11368
11369 /* Get peer sockunion. */
11370 ret = str2sockunion (ip_str, &su);
11371 if (ret < 0)
11372 {
a80beece
DS
11373 peer = peer_lookup_by_conf_if (bgp, ip_str);
11374 if (!peer)
11375 {
04b6bdc0
DW
11376 peer = peer_lookup_by_hostname(bgp, ip_str);
11377
11378 if (!peer)
856ca177 11379 {
04b6bdc0
DW
11380 if (use_json)
11381 {
11382 json_object *json_no = NULL;
11383 json_no = json_object_new_object();
11384 json_object_string_add(json_no, "malformedAddressOrName", ip_str);
11385 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11386 json_object_free(json_no);
11387 }
11388 else
11389 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
11390 return NULL;
856ca177 11391 }
a80beece
DS
11392 }
11393 return peer;
bb46e94f 11394 }
11395
11396 /* Peer structure lookup. */
11397 peer = peer_lookup (bgp, &su);
11398 if (! peer)
11399 {
856ca177
MS
11400 if (use_json)
11401 {
11402 json_object *json_no = NULL;
11403 json_no = json_object_new_object();
11404 json_object_string_add(json_no, "warning","No such neighbor");
11405 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11406 json_object_free(json_no);
11407 }
11408 else
11409 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
bb46e94f 11410 return NULL;
11411 }
11412
11413 return peer;
11414}
6b0655a2 11415
2815e61f
PJ
11416enum bgp_stats
11417{
11418 BGP_STATS_MAXBITLEN = 0,
11419 BGP_STATS_RIB,
11420 BGP_STATS_PREFIXES,
11421 BGP_STATS_TOTPLEN,
11422 BGP_STATS_UNAGGREGATEABLE,
11423 BGP_STATS_MAX_AGGREGATEABLE,
11424 BGP_STATS_AGGREGATES,
11425 BGP_STATS_SPACE,
11426 BGP_STATS_ASPATH_COUNT,
11427 BGP_STATS_ASPATH_MAXHOPS,
11428 BGP_STATS_ASPATH_TOTHOPS,
11429 BGP_STATS_ASPATH_MAXSIZE,
11430 BGP_STATS_ASPATH_TOTSIZE,
11431 BGP_STATS_ASN_HIGHEST,
11432 BGP_STATS_MAX,
11433};
11434
11435static const char *table_stats_strs[] =
11436{
11437 [BGP_STATS_PREFIXES] = "Total Prefixes",
11438 [BGP_STATS_TOTPLEN] = "Average prefix length",
11439 [BGP_STATS_RIB] = "Total Advertisements",
11440 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11441 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11442 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11443 [BGP_STATS_SPACE] = "Address space advertised",
11444 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11445 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11446 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11447 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11448 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11449 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11450 [BGP_STATS_MAX] = NULL,
11451};
11452
11453struct bgp_table_stats
11454{
11455 struct bgp_table *table;
11456 unsigned long long counts[BGP_STATS_MAX];
11457};
11458
11459#if 0
11460#define TALLY_SIGFIG 100000
11461static unsigned long
11462ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11463{
11464 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11465 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11466 unsigned long ret = newtot / count;
11467
11468 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11469 return ret + 1;
11470 else
11471 return ret;
11472}
11473#endif
11474
11475static int
11476bgp_table_stats_walker (struct thread *t)
11477{
11478 struct bgp_node *rn;
11479 struct bgp_node *top;
11480 struct bgp_table_stats *ts = THREAD_ARG (t);
11481 unsigned int space = 0;
11482
53d9f67a
PJ
11483 if (!(top = bgp_table_top (ts->table)))
11484 return 0;
2815e61f
PJ
11485
11486 switch (top->p.family)
11487 {
11488 case AF_INET:
11489 space = IPV4_MAX_BITLEN;
11490 break;
11491 case AF_INET6:
11492 space = IPV6_MAX_BITLEN;
11493 break;
11494 }
11495
11496 ts->counts[BGP_STATS_MAXBITLEN] = space;
11497
11498 for (rn = top; rn; rn = bgp_route_next (rn))
11499 {
11500 struct bgp_info *ri;
67174041 11501 struct bgp_node *prn = bgp_node_parent_nolock (rn);
2815e61f
PJ
11502 unsigned int rinum = 0;
11503
11504 if (rn == top)
11505 continue;
11506
11507 if (!rn->info)
11508 continue;
11509
11510 ts->counts[BGP_STATS_PREFIXES]++;
11511 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11512
11513#if 0
11514 ts->counts[BGP_STATS_AVGPLEN]
11515 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11516 ts->counts[BGP_STATS_AVGPLEN],
11517 rn->p.prefixlen);
11518#endif
11519
11520 /* check if the prefix is included by any other announcements */
11521 while (prn && !prn->info)
67174041 11522 prn = bgp_node_parent_nolock (prn);
2815e61f
PJ
11523
11524 if (prn == NULL || prn == top)
8383a9bd
PJ
11525 {
11526 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11527 /* announced address space */
11528 if (space)
11529 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11530 }
2815e61f
PJ
11531 else if (prn->info)
11532 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11533
2815e61f
PJ
11534 for (ri = rn->info; ri; ri = ri->next)
11535 {
11536 rinum++;
11537 ts->counts[BGP_STATS_RIB]++;
11538
11539 if (ri->attr &&
11540 (CHECK_FLAG (ri->attr->flag,
11541 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11542 ts->counts[BGP_STATS_AGGREGATES]++;
11543
11544 /* as-path stats */
11545 if (ri->attr && ri->attr->aspath)
11546 {
11547 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11548 unsigned int size = aspath_size (ri->attr->aspath);
11549 as_t highest = aspath_highest (ri->attr->aspath);
11550
11551 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11552
11553 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11554 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11555
11556 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11557 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11558
11559 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11560 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11561#if 0
11562 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11563 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11564 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11565 hops);
11566 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11567 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11568 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11569 size);
11570#endif
11571 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11572 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11573 }
11574 }
11575 }
11576 return 0;
11577}
11578
11579static int
11580bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11581{
11582 struct bgp_table_stats ts;
11583 unsigned int i;
11584
11585 if (!bgp->rib[afi][safi])
11586 {
11587 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
11588 return CMD_WARNING;
11589 }
11590
11591 memset (&ts, 0, sizeof (ts));
11592 ts.table = bgp->rib[afi][safi];
87d4a781 11593 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
bb46e94f 11594
2815e61f
PJ
11595 vty_out (vty, "BGP %s RIB statistics%s%s",
11596 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11597
11598 for (i = 0; i < BGP_STATS_MAX; i++)
11599 {
11600 if (!table_stats_strs[i])
11601 continue;
11602
11603 switch (i)
11604 {
11605#if 0
11606 case BGP_STATS_ASPATH_AVGHOPS:
11607 case BGP_STATS_ASPATH_AVGSIZE:
11608 case BGP_STATS_AVGPLEN:
11609 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11610 vty_out (vty, "%12.2f",
11611 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11612 break;
11613#endif
11614 case BGP_STATS_ASPATH_TOTHOPS:
11615 case BGP_STATS_ASPATH_TOTSIZE:
11616 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11617 vty_out (vty, "%12.2f",
11618 ts.counts[i] ?
11619 (float)ts.counts[i] /
11620 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11621 : 0);
11622 break;
11623 case BGP_STATS_TOTPLEN:
11624 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11625 vty_out (vty, "%12.2f",
11626 ts.counts[i] ?
11627 (float)ts.counts[i] /
11628 (float)ts.counts[BGP_STATS_PREFIXES]
11629 : 0);
11630 break;
11631 case BGP_STATS_SPACE:
11632 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11633 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11634 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11635 break;
30a2231a 11636 vty_out (vty, "%30s: ", "%% announced ");
2815e61f
PJ
11637 vty_out (vty, "%12.2f%s",
11638 100 * (float)ts.counts[BGP_STATS_SPACE] /
56395af7 11639 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
2815e61f
PJ
11640 VTY_NEWLINE);
11641 vty_out (vty, "%30s: ", "/8 equivalent ");
11642 vty_out (vty, "%12.2f%s",
11643 (float)ts.counts[BGP_STATS_SPACE] /
11644 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11645 VTY_NEWLINE);
11646 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11647 break;
11648 vty_out (vty, "%30s: ", "/24 equivalent ");
11649 vty_out (vty, "%12.2f",
11650 (float)ts.counts[BGP_STATS_SPACE] /
11651 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11652 break;
11653 default:
11654 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11655 vty_out (vty, "%12llu", ts.counts[i]);
11656 }
11657
11658 vty_out (vty, "%s", VTY_NEWLINE);
11659 }
11660 return CMD_SUCCESS;
11661}
11662
11663static int
11664bgp_table_stats_vty (struct vty *vty, const char *name,
11665 const char *afi_str, const char *safi_str)
11666{
11667 struct bgp *bgp;
11668 afi_t afi;
11669 safi_t safi;
11670
11671 if (name)
11672 bgp = bgp_lookup_by_name (name);
11673 else
11674 bgp = bgp_get_default ();
11675
11676 if (!bgp)
11677 {
11678 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
11679 return CMD_WARNING;
11680 }
11681 if (strncmp (afi_str, "ipv", 3) == 0)
11682 {
11683 if (strncmp (afi_str, "ipv4", 4) == 0)
11684 afi = AFI_IP;
11685 else if (strncmp (afi_str, "ipv6", 4) == 0)
11686 afi = AFI_IP6;
11687 else
11688 {
11689 vty_out (vty, "%% Invalid address family %s%s",
11690 afi_str, VTY_NEWLINE);
11691 return CMD_WARNING;
11692 }
11693 if (strncmp (safi_str, "m", 1) == 0)
11694 safi = SAFI_MULTICAST;
11695 else if (strncmp (safi_str, "u", 1) == 0)
11696 safi = SAFI_UNICAST;
42e6d745
DO
11697 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
11698 safi = SAFI_MPLS_LABELED_VPN;
2815e61f
PJ
11699 else
11700 {
11701 vty_out (vty, "%% Invalid subsequent address family %s%s",
11702 safi_str, VTY_NEWLINE);
11703 return CMD_WARNING;
11704 }
11705 }
11706 else
11707 {
11708 vty_out (vty, "%% Invalid address family %s%s",
11709 afi_str, VTY_NEWLINE);
11710 return CMD_WARNING;
11711 }
11712
2815e61f
PJ
11713 return bgp_table_stats (vty, bgp, afi, safi);
11714}
11715
11716DEFUN (show_bgp_statistics,
11717 show_bgp_statistics_cmd,
11718 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
11719 SHOW_STR
11720 BGP_STR
11721 "Address family\n"
11722 "Address family\n"
11723 "Address Family modifier\n"
11724 "Address Family modifier\n"
11725 "BGP RIB advertisement statistics\n")
11726{
11727 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11728}
11729
11730ALIAS (show_bgp_statistics,
11731 show_bgp_statistics_vpnv4_cmd,
11732 "show bgp (ipv4) (vpnv4) statistics",
11733 SHOW_STR
11734 BGP_STR
11735 "Address family\n"
11736 "Address Family modifier\n"
11737 "BGP RIB advertisement statistics\n")
11738
11739DEFUN (show_bgp_statistics_view,
11740 show_bgp_statistics_view_cmd,
11741 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
11742 SHOW_STR
11743 BGP_STR
11744 "BGP view\n"
11745 "Address family\n"
11746 "Address family\n"
11747 "Address Family modifier\n"
11748 "Address Family modifier\n"
11749 "BGP RIB advertisement statistics\n")
11750{
11751 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11752}
11753
11754ALIAS (show_bgp_statistics_view,
11755 show_bgp_statistics_view_vpnv4_cmd,
11756 "show bgp view WORD (ipv4) (vpnv4) statistics",
11757 SHOW_STR
11758 BGP_STR
11759 "BGP view\n"
11760 "Address family\n"
11761 "Address Family modifier\n"
11762 "BGP RIB advertisement statistics\n")
6b0655a2 11763
ff7924f6
PJ
11764enum bgp_pcounts
11765{
11766 PCOUNT_ADJ_IN = 0,
11767 PCOUNT_DAMPED,
11768 PCOUNT_REMOVED,
11769 PCOUNT_HISTORY,
11770 PCOUNT_STALE,
11771 PCOUNT_VALID,
11772 PCOUNT_ALL,
11773 PCOUNT_COUNTED,
11774 PCOUNT_PFCNT, /* the figure we display to users */
11775 PCOUNT_MAX,
11776};
11777
11778static const char *pcount_strs[] =
11779{
11780 [PCOUNT_ADJ_IN] = "Adj-in",
11781 [PCOUNT_DAMPED] = "Damped",
11782 [PCOUNT_REMOVED] = "Removed",
11783 [PCOUNT_HISTORY] = "History",
11784 [PCOUNT_STALE] = "Stale",
11785 [PCOUNT_VALID] = "Valid",
11786 [PCOUNT_ALL] = "All RIB",
11787 [PCOUNT_COUNTED] = "PfxCt counted",
11788 [PCOUNT_PFCNT] = "Useable",
11789 [PCOUNT_MAX] = NULL,
11790};
11791
2815e61f
PJ
11792struct peer_pcounts
11793{
11794 unsigned int count[PCOUNT_MAX];
11795 const struct peer *peer;
11796 const struct bgp_table *table;
11797};
11798
ff7924f6 11799static int
2815e61f 11800bgp_peer_count_walker (struct thread *t)
ff7924f6
PJ
11801{
11802 struct bgp_node *rn;
2815e61f
PJ
11803 struct peer_pcounts *pc = THREAD_ARG (t);
11804 const struct peer *peer = pc->peer;
ff7924f6 11805
2815e61f 11806 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
ff7924f6
PJ
11807 {
11808 struct bgp_adj_in *ain;
2815e61f 11809 struct bgp_info *ri;
ff7924f6
PJ
11810
11811 for (ain = rn->adj_in; ain; ain = ain->next)
11812 if (ain->peer == peer)
2815e61f 11813 pc->count[PCOUNT_ADJ_IN]++;
ff7924f6 11814
ff7924f6
PJ
11815 for (ri = rn->info; ri; ri = ri->next)
11816 {
11817 char buf[SU_ADDRSTRLEN];
11818
11819 if (ri->peer != peer)
11820 continue;
11821
2815e61f 11822 pc->count[PCOUNT_ALL]++;
ff7924f6
PJ
11823
11824 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
2815e61f 11825 pc->count[PCOUNT_DAMPED]++;
ff7924f6 11826 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2815e61f 11827 pc->count[PCOUNT_HISTORY]++;
ff7924f6 11828 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
2815e61f 11829 pc->count[PCOUNT_REMOVED]++;
ff7924f6 11830 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2815e61f 11831 pc->count[PCOUNT_STALE]++;
ff7924f6 11832 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
2815e61f 11833 pc->count[PCOUNT_VALID]++;
1a392d46 11834 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2815e61f 11835 pc->count[PCOUNT_PFCNT]++;
ff7924f6
PJ
11836
11837 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
11838 {
2815e61f 11839 pc->count[PCOUNT_COUNTED]++;
1a392d46 11840 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 11841 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
ff7924f6
PJ
11842 peer->host,
11843 inet_ntop(rn->p.family, &rn->p.u.prefix,
11844 buf, SU_ADDRSTRLEN),
11845 rn->p.prefixlen,
11846 ri->flags);
11847 }
11848 else
11849 {
1a392d46 11850 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 11851 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
ff7924f6
PJ
11852 peer->host,
11853 inet_ntop(rn->p.family, &rn->p.u.prefix,
11854 buf, SU_ADDRSTRLEN),
11855 rn->p.prefixlen,
11856 ri->flags);
11857 }
11858 }
11859 }
2815e61f
PJ
11860 return 0;
11861}
ff7924f6 11862
2815e61f 11863static int
856ca177 11864bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json)
2815e61f
PJ
11865{
11866 struct peer_pcounts pcounts = { .peer = peer };
11867 unsigned int i;
856ca177
MS
11868 json_object *json = NULL;
11869 json_object *json_loop = NULL;
11870
11871 if (use_json)
11872 {
11873 json = json_object_new_object();
11874 json_loop = json_object_new_object();
11875 }
2815e61f
PJ
11876
11877 if (!peer || !peer->bgp || !peer->afc[afi][safi]
11878 || !peer->bgp->rib[afi][safi])
11879 {
856ca177
MS
11880 if (use_json)
11881 {
11882 json_object_string_add(json, "warning", "No such neighbor or address family");
11883 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11884 json_object_free(json);
11885 }
11886 else
11887 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11888
2815e61f
PJ
11889 return CMD_WARNING;
11890 }
11891
11892 memset (&pcounts, 0, sizeof(pcounts));
11893 pcounts.peer = peer;
11894 pcounts.table = peer->bgp->rib[afi][safi];
11895
11896 /* in-place call via thread subsystem so as to record execution time
856ca177
MS
11897 * * stats for the thread-walk (i.e. ensure this can't be blamed on
11898 * * on just vty_read()).
11899 * */
87d4a781 11900 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
6410e93a 11901
856ca177
MS
11902 if (use_json)
11903 {
11904 json_object_string_add(json, "prefixCountsFor", peer->host);
11905 json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi));
11906 json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]);
11907
11908 for (i = 0; i < PCOUNT_MAX; i++)
11909 json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]);
ff7924f6 11910
856ca177 11911 json_object_object_add(json, "ribTableWalkCounters", json_loop);
ff7924f6 11912
856ca177
MS
11913 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
11914 {
11915 json_object_string_add(json, "pfxctDriftFor", peer->host);
11916 json_object_string_add(json, "recommended", "Please report this bug, with the above command output");
11917 }
11918 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11919 json_object_free(json);
11920 }
11921 else
ff7924f6 11922 {
04b6bdc0
DW
11923
11924 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
11925 {
11926 vty_out (vty, "Prefix counts for %s/%s, %s%s",
11927 peer->hostname, peer->host, afi_safi_print (afi, safi),
11928 VTY_NEWLINE);
11929 }
11930 else
11931 {
11932 vty_out (vty, "Prefix counts for %s, %s%s",
11933 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
11934 }
11935
856ca177
MS
11936 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
11937 vty_out (vty, "%sCounts from RIB table walk:%s%s",
11938 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
11939
11940 for (i = 0; i < PCOUNT_MAX; i++)
11941 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
11942
11943 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
11944 {
11945 vty_out (vty, "%s [pcount] PfxCt drift!%s",
11946 peer->host, VTY_NEWLINE);
11947 vty_out (vty, "Please report this bug, with the above command output%s",
11948 VTY_NEWLINE);
11949 }
ff7924f6
PJ
11950 }
11951
11952 return CMD_SUCCESS;
11953}
11954
11955DEFUN (show_ip_bgp_neighbor_prefix_counts,
11956 show_ip_bgp_neighbor_prefix_counts_cmd,
856ca177 11957 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
11958 SHOW_STR
11959 IP_STR
11960 BGP_STR
11961 "Detailed information on TCP and BGP neighbor connections\n"
11962 "Neighbor to display information about\n"
11963 "Neighbor to display information about\n"
a80beece 11964 "Neighbor on bgp configured interface\n"
856ca177
MS
11965 "Display detailed prefix count information\n"
11966 "JavaScript Object Notation\n")
ff7924f6
PJ
11967{
11968 struct peer *peer;
856ca177
MS
11969 u_char use_json;
11970
11971 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
11972 use_json = 1;
11973 else
11974 use_json = 0;
ff7924f6 11975
856ca177 11976 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
ff7924f6
PJ
11977 if (! peer)
11978 return CMD_WARNING;
11979
856ca177 11980 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, use_json);
ff7924f6
PJ
11981}
11982
11983DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
11984 show_bgp_ipv6_neighbor_prefix_counts_cmd,
856ca177 11985 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
11986 SHOW_STR
11987 BGP_STR
11988 "Address family\n"
11989 "Detailed information on TCP and BGP neighbor connections\n"
11990 "Neighbor to display information about\n"
11991 "Neighbor to display information about\n"
a80beece 11992 "Neighbor on bgp configured interface\n"
856ca177
MS
11993 "Display detailed prefix count information\n"
11994 "JavaScript Object Notation\n")
ff7924f6
PJ
11995{
11996 struct peer *peer;
856ca177
MS
11997 u_char use_json;
11998
11999 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
12000 use_json = 1;
12001 else
12002 use_json = 0;
ff7924f6 12003
856ca177 12004 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
ff7924f6
PJ
12005 if (! peer)
12006 return CMD_WARNING;
12007
856ca177 12008 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, use_json);
ff7924f6
PJ
12009}
12010
12011DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12012 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
856ca177 12013 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
12014 SHOW_STR
12015 IP_STR
12016 BGP_STR
12017 "Address family\n"
12018 "Address Family modifier\n"
12019 "Address Family modifier\n"
12020 "Detailed information on TCP and BGP neighbor connections\n"
12021 "Neighbor to display information about\n"
12022 "Neighbor to display information about\n"
a80beece 12023 "Neighbor on bgp configured interface\n"
856ca177
MS
12024 "Display detailed prefix count information\n"
12025 "JavaScript Object Notation\n")
ff7924f6
PJ
12026{
12027 struct peer *peer;
856ca177
MS
12028 u_char use_json;
12029
12030 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
12031 use_json = 1;
12032 else
12033 use_json = 0;
ff7924f6 12034
856ca177 12035 peer = peer_lookup_in_view (vty, NULL, argv[1], use_json);
ff7924f6
PJ
12036 if (! peer)
12037 return CMD_WARNING;
12038
12039 if (strncmp (argv[0], "m", 1) == 0)
856ca177 12040 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST, use_json);
ff7924f6 12041
856ca177 12042 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, use_json);
ff7924f6
PJ
12043}
12044
12045DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
12046 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
856ca177 12047 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
12048 SHOW_STR
12049 IP_STR
12050 BGP_STR
12051 "Address family\n"
12052 "Address Family modifier\n"
12053 "Address Family modifier\n"
12054 "Detailed information on TCP and BGP neighbor connections\n"
12055 "Neighbor to display information about\n"
12056 "Neighbor to display information about\n"
a80beece 12057 "Neighbor on bgp configured interface\n"
856ca177
MS
12058 "Display detailed prefix count information\n"
12059 "JavaScript Object Notation\n")
ff7924f6
PJ
12060{
12061 struct peer *peer;
856ca177 12062 u_char use_json;
ff7924f6 12063
856ca177
MS
12064 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
12065 use_json = 1;
12066 else
12067 use_json = 0;
12068
12069 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
ff7924f6
PJ
12070 if (! peer)
12071 return CMD_WARNING;
12072
856ca177 12073 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN, use_json);
ff7924f6
PJ
12074}
12075
94f2b392 12076static void
718e3744 12077show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
856ca177 12078 int in, const char *rmap_name, u_char use_json, json_object *json)
718e3744 12079{
12080 struct bgp_table *table;
12081 struct bgp_adj_in *ain;
12082 struct bgp_adj_out *adj;
12083 unsigned long output_count;
0b16f239 12084 unsigned long filtered_count;
718e3744 12085 struct bgp_node *rn;
12086 int header1 = 1;
12087 struct bgp *bgp;
12088 int header2 = 1;
0b16f239
DS
12089 struct attr attr;
12090 struct attr_extra extra;
12091 int ret;
840fced9 12092 struct update_subgroup *subgrp;
856ca177
MS
12093 json_object *json_scode = NULL;
12094 json_object *json_ocode = NULL;
12095 json_object *json_ar = NULL;
12096
12097 if (use_json)
12098 {
12099 json_scode = json_object_new_object();
12100 json_ocode = json_object_new_object();
12101 json_ar = json_object_new_object();
12102
12103 json_object_string_add(json_scode, "suppressed", "s");
12104 json_object_string_add(json_scode, "damped", "d");
12105 json_object_string_add(json_scode, "history", "h");
12106 json_object_string_add(json_scode, "valid", "*");
12107 json_object_string_add(json_scode, "best", ">");
12108 json_object_string_add(json_scode, "multipath", "=");
12109 json_object_string_add(json_scode, "internal", "i");
12110 json_object_string_add(json_scode, "ribFailure", "r");
12111 json_object_string_add(json_scode, "stale", "S");
12112 json_object_string_add(json_scode, "removed", "R");
12113
12114 json_object_string_add(json_ocode, "igp", "i");
12115 json_object_string_add(json_ocode, "egp", "e");
12116 json_object_string_add(json_ocode, "incomplete", "?");
12117 }
718e3744 12118
bb46e94f 12119 bgp = peer->bgp;
718e3744 12120
12121 if (! bgp)
856ca177
MS
12122 {
12123 if (use_json)
12124 {
12125 json_object_string_add(json, "alert", "no BGP");
12126 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12127 json_object_free(json);
12128 }
12129 else
12130 vty_out (vty, "%% No bgp%s", VTY_NEWLINE);
12131 return;
12132 }
718e3744 12133
12134 table = bgp->rib[afi][safi];
12135
0b16f239 12136 output_count = filtered_count = 0;
840fced9 12137 subgrp = peer_subgroup(peer, afi, safi);
47fc97cc 12138
840fced9 12139 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
718e3744 12140 {
856ca177
MS
12141 if (use_json)
12142 {
12143 json_object_int_add(json, "bgpTableVersion", table->version);
12144 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12145 json_object_object_add(json, "bgpStatusCodes", json_scode);
12146 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12147 json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0");
12148 }
12149 else
12150 {
12151 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
12152 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12153 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 12154
856ca177
MS
12155 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12156 VTY_NEWLINE, VTY_NEWLINE);
12157 }
718e3744 12158 header1 = 0;
12159 }
12160
0b16f239 12161 attr.extra = &extra;
718e3744 12162 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
856ca177
MS
12163 {
12164 if (in)
12165 {
12166 for (ain = rn->adj_in; ain; ain = ain->next)
12167 {
12168 if (ain->peer == peer)
12169 {
12170 if (header1)
12171 {
12172 if (use_json)
12173 {
12174 json_object_int_add(json, "bgpTableVersion", 0);
12175 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12176 json_object_object_add(json, "bgpStatusCodes", json_scode);
12177 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12178 }
12179 else
12180 {
12181 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
12182 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12183 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12184 }
12185 header1 = 0;
12186 }
12187 if (header2)
12188 {
12189 if (!use_json)
12190 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12191 header2 = 0;
12192 }
12193 if (ain->attr)
12194 {
12195 bgp_attr_dup(&attr, ain->attr);
12196 if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY)
12197 {
12198 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12199 output_count++;
12200 }
12201 else
12202 filtered_count++;
12203 }
12204 }
12205 }
12206 }
12207 else
12208 {
12209 adj = bgp_adj_peer_lookup(peer, rn);
12210 if (adj)
12211 {
12212 if (header1)
12213 {
12214 if (use_json)
12215 {
12216 json_object_int_add(json, "bgpTableVersion", table->version);
12217 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12218 json_object_object_add(json, "bgpStatusCodes", json_scode);
12219 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12220 }
12221 else
12222 {
12223 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version,
12224 inet_ntoa (bgp->router_id), VTY_NEWLINE);
12225 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12226 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12227 }
12228 header1 = 0;
12229 }
12230 if (header2)
12231 {
12232 if (!use_json)
12233 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12234 header2 = 0;
12235 }
12236 if (adj->attr)
12237 {
12238 bgp_attr_dup(&attr, adj->attr);
12239 ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name);
12240 if (ret != RMAP_DENY)
12241 {
12242 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12243 output_count++;
12244 }
12245 else
12246 filtered_count++;
12247 }
12248 }
12249 }
12250 }
12251 if (use_json)
12252 json_object_object_add(json, "advertisedRoutes", json_ar);
47fc97cc 12253
718e3744 12254 if (output_count != 0)
856ca177
MS
12255 {
12256 if (use_json)
12257 json_object_int_add(json, "totalPrefixCounter", output_count);
12258 else
12259 vty_out (vty, "%sTotal number of prefixes %ld%s",
12260 VTY_NEWLINE, output_count, VTY_NEWLINE);
12261 }
12262 if (use_json)
12263 {
12264 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12265 json_object_free(json);
12266 }
12267
718e3744 12268}
12269
94f2b392 12270static int
47fc97cc 12271peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
856ca177
MS
12272 int in, const char *rmap_name, u_char use_json)
12273{
12274 json_object *json = NULL;
12275
12276 if (use_json)
12277 json = json_object_new_object();
12278
12279 if (!peer || !peer->afc[afi][safi])
718e3744 12280 {
856ca177
MS
12281 if (use_json)
12282 {
12283 json_object_string_add(json, "warning", "No such neighbor or address family");
12284 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12285 json_object_free(json);
12286 }
12287 else
12288 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12289
718e3744 12290 return CMD_WARNING;
12291 }
12292
856ca177 12293 if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
718e3744 12294 {
856ca177
MS
12295 if (use_json)
12296 {
12297 json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
12298 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12299 json_object_free(json);
12300 }
12301 else
12302 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE);
12303
718e3744 12304 return CMD_WARNING;
12305 }
12306
856ca177 12307 show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json);
718e3744 12308
12309 return CMD_SUCCESS;
12310}
12311
2a71e9ce
TP
12312DEFUN (show_ip_bgp_view_neighbor_advertised_route,
12313 show_ip_bgp_view_neighbor_advertised_route_cmd,
856ca177 12314 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12315 SHOW_STR
12316 IP_STR
12317 BGP_STR
2a71e9ce
TP
12318 "BGP view\n"
12319 "View name\n"
718e3744 12320 "Detailed information on TCP and BGP neighbor connections\n"
12321 "Neighbor to display information about\n"
12322 "Neighbor to display information about\n"
856ca177
MS
12323 "Display the routes advertised to a BGP neighbor\n"
12324 "JavaScript Object Notation\n")
718e3744 12325{
bb46e94f 12326 struct peer *peer;
12327
856ca177
MS
12328 u_char use_json;
12329
12330 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
12331 use_json = 1;
12332 else
12333 use_json = 0;
12334
12335 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12336 peer = peer_lookup_in_view (vty, argv[0], argv[1], use_json);
2a71e9ce 12337 else
856ca177 12338 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
2a71e9ce 12339
bb46e94f 12340 if (! peer)
12341 return CMD_WARNING;
0b16f239 12342
856ca177 12343 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, use_json);
718e3744 12344}
12345
0b16f239 12346DEFUN (show_ip_bgp_neighbor_advertised_route,
2a71e9ce 12347 show_ip_bgp_neighbor_advertised_route_cmd,
856ca177 12348 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
2a71e9ce
TP
12349 SHOW_STR
12350 IP_STR
12351 BGP_STR
12352 "Detailed information on TCP and BGP neighbor connections\n"
12353 "Neighbor to display information about\n"
12354 "Neighbor to display information about\n"
a80beece 12355 "Neighbor on bgp configured interface\n"
856ca177
MS
12356 "Display the routes advertised to a BGP neighbor\n"
12357 "JavaScript Object Notation\n")
2a71e9ce 12358
0b16f239
DS
12359{
12360 struct peer *peer;
ffd0c037 12361 const char *rmap_name = NULL;
856ca177
MS
12362 u_char use_json;
12363
12364 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
12365 use_json = 1;
12366 else
12367 use_json = 0;
0b16f239 12368
856ca177 12369 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
0b16f239
DS
12370
12371 if (! peer)
12372 return CMD_WARNING;
12373
856ca177
MS
12374 if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)
12375 || (argc == 3))
0b16f239
DS
12376 rmap_name = argv[1];
12377
856ca177 12378 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, use_json);
0b16f239
DS
12379}
12380
12381ALIAS (show_ip_bgp_neighbor_advertised_route,
12382 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
856ca177 12383 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
0b16f239
DS
12384 SHOW_STR
12385 IP_STR
12386 BGP_STR
12387 "Detailed information on TCP and BGP neighbor connections\n"
12388 "Neighbor to display information about\n"
12389 "Neighbor to display information about\n"
12390 "Neighbor on bgp configured interface\n"
856ca177
MS
12391 "Display the routes advertised to a BGP neighbor\n"
12392 "JavaScript Object Notation\n")
0b16f239 12393
718e3744 12394DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12395 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
856ca177 12396 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12397 SHOW_STR
12398 IP_STR
12399 BGP_STR
12400 "Address family\n"
12401 "Address Family modifier\n"
12402 "Address Family modifier\n"
12403 "Detailed information on TCP and BGP neighbor connections\n"
12404 "Neighbor to display information about\n"
12405 "Neighbor to display information about\n"
a80beece 12406 "Neighbor on bgp configured interface\n"
856ca177
MS
12407 "Display the routes advertised to a BGP neighbor\n"
12408 "JavaScript Object Notation\n")
718e3744 12409{
bb46e94f 12410 struct peer *peer;
ffd0c037 12411 const char *rmap_name = NULL;
856ca177
MS
12412 u_char use_json;
12413
12414 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
12415 use_json = 1;
12416 else
12417 use_json = 0;
bb46e94f 12418
856ca177 12419 peer = peer_lookup_in_view (vty, NULL, argv[1], use_json);
bb46e94f 12420 if (! peer)
12421 return CMD_WARNING;
12422
856ca177 12423 if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
0b16f239
DS
12424 rmap_name = argv[2];
12425
718e3744 12426 if (strncmp (argv[0], "m", 1) == 0)
856ca177
MS
12427 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name, use_json);
12428 else
12429 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, use_json);
718e3744 12430}
12431
0b16f239
DS
12432ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
12433 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
856ca177 12434 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
0b16f239
DS
12435 SHOW_STR
12436 IP_STR
12437 BGP_STR
12438 "Address family\n"
12439 "Address Family modifier\n"
12440 "Address Family modifier\n"
12441 "Detailed information on TCP and BGP neighbor connections\n"
12442 "Neighbor to display information about\n"
12443 "Neighbor to display information about\n"
12444 "Neighbor on bgp configured interface\n"
12445 "Display the routes advertised to a BGP neighbor\n"
856ca177
MS
12446 "Route-map to control what is displayed\n"
12447 "JavaScript Object Notation\n")
0b16f239 12448
718e3744 12449#ifdef HAVE_IPV6
bb46e94f 12450DEFUN (show_bgp_view_neighbor_advertised_route,
12451 show_bgp_view_neighbor_advertised_route_cmd,
856ca177 12452 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12453 SHOW_STR
12454 BGP_STR
bb46e94f 12455 "BGP view\n"
12456 "View name\n"
718e3744 12457 "Detailed information on TCP and BGP neighbor connections\n"
12458 "Neighbor to display information about\n"
12459 "Neighbor to display information about\n"
a80beece 12460 "Neighbor on bgp configured interface\n"
856ca177
MS
12461 "Display the routes advertised to a BGP neighbor\n"
12462 "JavaScript Object Notation\n")
718e3744 12463{
bb46e94f 12464 struct peer *peer;
856ca177 12465 u_char use_json;
bb46e94f 12466
856ca177
MS
12467 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
12468 use_json = 1;
12469 else
12470 use_json = 0;
12471
12472 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12473 peer = peer_lookup_in_view (vty, argv[0], argv[1], use_json);
bb46e94f 12474 else
856ca177 12475 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
bb46e94f 12476
12477 if (! peer)
0b16f239 12478 return CMD_WARNING;
bb46e94f 12479
856ca177 12480 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, use_json);
47fc97cc
DS
12481}
12482
0b16f239
DS
12483ALIAS (show_bgp_view_neighbor_advertised_route,
12484 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
856ca177 12485 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
0b16f239
DS
12486 SHOW_STR
12487 BGP_STR
12488 "BGP view\n"
12489 "View name\n"
12490 "Address family\n"
12491 "Detailed information on TCP and BGP neighbor connections\n"
12492 "Neighbor to display information about\n"
12493 "Neighbor to display information about\n"
12494 "Neighbor on bgp configured interface\n"
856ca177
MS
12495 "Display the routes advertised to a BGP neighbor\n"
12496 "JavaScript Object Notation\n")
0b16f239 12497
0b16f239
DS
12498DEFUN (show_bgp_neighbor_advertised_route,
12499 show_bgp_neighbor_advertised_route_cmd,
856ca177 12500 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
bb46e94f 12501 SHOW_STR
12502 BGP_STR
bb46e94f 12503 "Detailed information on TCP and BGP neighbor connections\n"
12504 "Neighbor to display information about\n"
12505 "Neighbor to display information about\n"
a80beece 12506 "Neighbor on bgp configured interface\n"
856ca177
MS
12507 "Display the routes advertised to a BGP neighbor\n"
12508 "JavaScript Object Notation\n")
0b16f239 12509
bb46e94f 12510{
12511 struct peer *peer;
ffd0c037 12512 const char *rmap_name = NULL;
856ca177 12513 u_char use_json;
bb46e94f 12514
856ca177
MS
12515 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
12516 use_json = 1;
12517 else
12518 use_json = 0;
bb46e94f 12519
856ca177
MS
12520 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
12521
12522 if (!peer)
bb46e94f 12523 return CMD_WARNING;
12524
856ca177 12525 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
0b16f239
DS
12526 rmap_name = argv[1];
12527
856ca177 12528 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, use_json);
718e3744 12529}
12530
0b16f239
DS
12531ALIAS (show_bgp_neighbor_advertised_route,
12532 show_bgp_ipv6_neighbor_advertised_route_cmd,
856ca177 12533 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12534 SHOW_STR
12535 BGP_STR
12536 "Address family\n"
12537 "Detailed information on TCP and BGP neighbor connections\n"
12538 "Neighbor to display information about\n"
12539 "Neighbor to display information about\n"
a80beece 12540 "Neighbor on bgp configured interface\n"
856ca177
MS
12541 "Display the routes advertised to a BGP neighbor\n"
12542 "JavaScript Object Notation\n")
718e3744 12543
12544/* old command */
0b16f239 12545ALIAS (show_bgp_neighbor_advertised_route,
718e3744 12546 ipv6_bgp_neighbor_advertised_route_cmd,
856ca177 12547 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12548 SHOW_STR
12549 IPV6_STR
12550 BGP_STR
12551 "Detailed information on TCP and BGP neighbor connections\n"
12552 "Neighbor to display information about\n"
12553 "Neighbor to display information about\n"
a80beece 12554 "Neighbor on bgp configured interface\n"
856ca177
MS
12555 "Display the routes advertised to a BGP neighbor\n"
12556 "JavaScript Object Notation\n")
bb46e94f 12557
718e3744 12558/* old command */
12559DEFUN (ipv6_mbgp_neighbor_advertised_route,
12560 ipv6_mbgp_neighbor_advertised_route_cmd,
856ca177 12561 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12562 SHOW_STR
12563 IPV6_STR
12564 MBGP_STR
12565 "Detailed information on TCP and BGP neighbor connections\n"
12566 "Neighbor to display information about\n"
12567 "Neighbor to display information about\n"
a80beece
DS
12568 "Neighbor on bgp configured interface\n"
12569 "Neighbor on bgp configured interface\n"
856ca177
MS
12570 "Display the routes advertised to a BGP neighbor\n"
12571 "JavaScript Object Notation\n")
718e3744 12572{
bb46e94f 12573 struct peer *peer;
856ca177
MS
12574 u_char use_json;
12575
12576 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
12577 use_json = 1;
12578 else
12579 use_json = 0;
bb46e94f 12580
856ca177 12581 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
bb46e94f 12582 if (! peer)
856ca177 12583 return CMD_WARNING;
bb46e94f 12584
856ca177 12585 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, use_json);
718e3744 12586}
12587#endif /* HAVE_IPV6 */
6b0655a2 12588
0b16f239
DS
12589DEFUN (show_bgp_view_neighbor_received_routes,
12590 show_bgp_view_neighbor_received_routes_cmd,
856ca177 12591 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
0b16f239
DS
12592 SHOW_STR
12593 BGP_STR
12594 "BGP view\n"
12595 "View name\n"
12596 "Detailed information on TCP and BGP neighbor connections\n"
12597 "Neighbor to display information about\n"
12598 "Neighbor to display information about\n"
12599 "Neighbor on bgp configured interface\n"
856ca177
MS
12600 "Display the received routes from neighbor\n"
12601 "JavaScript Object Notation\n")
0b16f239
DS
12602{
12603 struct peer *peer;
856ca177 12604 u_char use_json;
0b16f239 12605
856ca177
MS
12606 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
12607 use_json = 1;
12608 else
12609 use_json = 0;
12610
12611 if (use_json)
12612 {
12613 if (argc == 3)
12614 peer = peer_lookup_in_view (vty, argv[0], argv[1], use_json);
12615 else
12616 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
12617 }
0b16f239 12618 else
856ca177
MS
12619 {
12620 if (argc == 2)
12621 peer = peer_lookup_in_view (vty, argv[0], argv[1], use_json);
12622 else
12623 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
12624 }
0b16f239
DS
12625
12626 if (! peer)
12627 return CMD_WARNING;
12628
856ca177 12629 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, use_json);
0b16f239
DS
12630}
12631
2a71e9ce
TP
12632DEFUN (show_ip_bgp_view_neighbor_received_routes,
12633 show_ip_bgp_view_neighbor_received_routes_cmd,
856ca177 12634 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 12635 SHOW_STR
12636 IP_STR
12637 BGP_STR
2a71e9ce
TP
12638 "BGP view\n"
12639 "View name\n"
718e3744 12640 "Detailed information on TCP and BGP neighbor connections\n"
12641 "Neighbor to display information about\n"
12642 "Neighbor to display information about\n"
a80beece 12643 "Neighbor on bgp configured interface\n"
856ca177
MS
12644 "Display the received routes from neighbor\n"
12645 "JavaScript Object Notation\n")
718e3744 12646{
bb46e94f 12647 struct peer *peer;
856ca177 12648 u_char use_json;
bb46e94f 12649
856ca177
MS
12650 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
12651 use_json = 1;
12652 else
12653 use_json = 0;
12654
12655 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12656 peer = peer_lookup_in_view (vty, argv[0], argv[1], use_json);
2a71e9ce 12657 else
856ca177 12658 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
2a71e9ce 12659
bb46e94f 12660 if (! peer)
12661 return CMD_WARNING;
12662
856ca177 12663 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, use_json);
718e3744 12664}
12665
0b16f239
DS
12666ALIAS (show_bgp_view_neighbor_received_routes,
12667 show_bgp_view_ipv6_neighbor_received_routes_cmd,
856ca177 12668 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
0b16f239
DS
12669 SHOW_STR
12670 BGP_STR
12671 "BGP view\n"
12672 "View name\n"
12673 "Address family\n"
12674 "Detailed information on TCP and BGP neighbor connections\n"
12675 "Neighbor to display information about\n"
12676 "Neighbor to display information about\n"
12677 "Neighbor on bgp configured interface\n"
856ca177
MS
12678 "Display the received routes from neighbor\n"
12679 "JavaScript Object Notation\n")
0b16f239
DS
12680
12681DEFUN (show_ip_bgp_neighbor_received_routes,
2a71e9ce 12682 show_ip_bgp_neighbor_received_routes_cmd,
856ca177 12683 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
2a71e9ce
TP
12684 SHOW_STR
12685 IP_STR
12686 BGP_STR
12687 "Detailed information on TCP and BGP neighbor connections\n"
12688 "Neighbor to display information about\n"
12689 "Neighbor to display information about\n"
a80beece 12690 "Neighbor on bgp configured interface\n"
856ca177
MS
12691 "Display the received routes from neighbor\n"
12692 "JavaScript Object Notation\n")
2a71e9ce 12693
0b16f239
DS
12694{
12695 struct peer *peer;
ffd0c037 12696 const char *rmap_name = NULL;
856ca177
MS
12697 u_char use_json;
12698
12699 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
12700 use_json = 1;
12701 else
12702 use_json = 0;
0b16f239 12703
856ca177 12704 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
0b16f239
DS
12705
12706 if (! peer)
12707 return CMD_WARNING;
12708
856ca177 12709 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
0b16f239
DS
12710 rmap_name = argv[1];
12711
856ca177 12712 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, use_json);
0b16f239
DS
12713}
12714
12715ALIAS (show_ip_bgp_neighbor_received_routes,
12716 show_ip_bgp_neighbor_received_routes_rmap_cmd,
856ca177 12717 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
0b16f239
DS
12718 SHOW_STR
12719 IP_STR
12720 BGP_STR
12721 "Detailed information on TCP and BGP neighbor connections\n"
12722 "Neighbor to display information about\n"
12723 "Neighbor to display information about\n"
12724 "Neighbor on bgp configured interface\n"
856ca177
MS
12725 "Display the received routes from neighbor\n"
12726 "JavaScript Object Notation\n")
0b16f239 12727
718e3744 12728DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12729 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
856ca177 12730 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 12731 SHOW_STR
12732 IP_STR
12733 BGP_STR
12734 "Address family\n"
12735 "Address Family modifier\n"
12736 "Address Family modifier\n"
12737 "Detailed information on TCP and BGP neighbor connections\n"
12738 "Neighbor to display information about\n"
12739 "Neighbor to display information about\n"
a80beece 12740 "Neighbor on bgp configured interface\n"
856ca177
MS
12741 "Display the received routes from neighbor\n"
12742 "JavaScript Object Notation\n")
718e3744 12743{
bb46e94f 12744 struct peer *peer;
ffd0c037 12745 const char *rmap_name = NULL;
856ca177 12746 u_char use_json;
bb46e94f 12747
856ca177
MS
12748 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
12749 use_json = 1;
12750 else
12751 use_json = 0;
12752
12753 peer = peer_lookup_in_view (vty, NULL, argv[1], use_json);
bb46e94f 12754 if (! peer)
12755 return CMD_WARNING;
0b16f239 12756
856ca177 12757 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
0b16f239
DS
12758 rmap_name = argv[2];
12759
718e3744 12760 if (strncmp (argv[0], "m", 1) == 0)
856ca177
MS
12761 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name, use_json);
12762 else
12763 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, use_json);
718e3744 12764}
12765
0b16f239
DS
12766ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
12767 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
856ca177 12768 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
0b16f239
DS
12769 SHOW_STR
12770 IP_STR
12771 BGP_STR
12772 "Address family\n"
12773 "Address Family modifier\n"
12774 "Address Family modifier\n"
12775 "Detailed information on TCP and BGP neighbor connections\n"
12776 "Neighbor to display information about\n"
12777 "Neighbor to display information about\n"
12778 "Neighbor on bgp configured interface\n"
856ca177
MS
12779 "Display the received routes from neighbor\n"
12780 "JavaScript Object Notation\n")
0b16f239 12781
95cbbd2a
ML
12782DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
12783 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
12784#ifdef HAVE_IPV6
856ca177 12785 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
95cbbd2a 12786#else
856ca177 12787 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
95cbbd2a
ML
12788#endif
12789 SHOW_STR
12790 BGP_STR
12791 "BGP view\n"
2b00515a 12792 "View name\n"
95cbbd2a
ML
12793 "Address family\n"
12794#ifdef HAVE_IPV6
12795 "Address family\n"
12796#endif
12797 "Address family modifier\n"
12798 "Address family modifier\n"
12799 "Detailed information on TCP and BGP neighbor connections\n"
12800 "Neighbor to display information about\n"
12801 "Neighbor to display information about\n"
a80beece 12802 "Neighbor on bgp configured interface\n"
95cbbd2a 12803 "Display the advertised routes to neighbor\n"
856ca177
MS
12804 "Display the received routes from neighbor\n"
12805 "JavaScript Object Notation\n")
95cbbd2a
ML
12806{
12807 int afi;
12808 int safi;
12809 int in;
12810 struct peer *peer;
856ca177
MS
12811 u_char use_json;
12812
12813 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
12814 use_json = 1;
12815 else
12816 use_json = 0;
95cbbd2a
ML
12817
12818#ifdef HAVE_IPV6
856ca177 12819 peer = peer_lookup_in_view (vty, argv[0], argv[3], use_json);
95cbbd2a 12820#else
856ca177 12821 peer = peer_lookup_in_view (vty, argv[0], argv[2], use_json);
95cbbd2a
ML
12822#endif
12823
12824 if (! peer)
12825 return CMD_WARNING;
12826
12827#ifdef HAVE_IPV6
12828 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
12829 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12830 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
12831#else
12832 afi = AFI_IP;
12833 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12834 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
12835#endif
12836
856ca177 12837 return peer_adj_routes (vty, peer, afi, safi, in, NULL, use_json);
95cbbd2a
ML
12838}
12839
718e3744 12840DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12841 show_ip_bgp_neighbor_received_prefix_filter_cmd,
856ca177 12842 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 12843 SHOW_STR
12844 IP_STR
12845 BGP_STR
12846 "Detailed information on TCP and BGP neighbor connections\n"
12847 "Neighbor to display information about\n"
12848 "Neighbor to display information about\n"
a80beece 12849 "Neighbor on bgp configured interface\n"
718e3744 12850 "Display information received from a BGP neighbor\n"
856ca177
MS
12851 "Display the prefixlist filter\n"
12852 "JavaScript Object Notation\n")
718e3744 12853{
12854 char name[BUFSIZ];
c63b83fe 12855 union sockunion su;
718e3744 12856 struct peer *peer;
c63b83fe 12857 int count, ret;
856ca177
MS
12858 u_char use_json;
12859
12860 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
12861 use_json = 1;
12862 else
12863 use_json = 0;
718e3744 12864
c63b83fe
JBD
12865 ret = str2sockunion (argv[0], &su);
12866 if (ret < 0)
12867 {
a80beece 12868 peer = peer_lookup_by_conf_if (NULL, argv[0]);
856ca177 12869 if (! peer)
a80beece 12870 {
856ca177
MS
12871 if (use_json)
12872 {
12873 json_object *json_no = NULL;
12874 json_object *json_sub = NULL;
12875 json_no = json_object_new_object();
12876 json_sub = json_object_new_object();
12877 json_object_string_add(json_no, "warning", "Malformed address or name");
12878 json_object_string_add(json_sub, "warningCause", argv[0]);
12879 json_object_object_add(json_no, "detail", json_sub);
12880 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12881 json_object_free(json_no);
12882 }
12883 else
12884 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
a80beece
DS
12885 return CMD_WARNING;
12886 }
12887 }
12888 else
12889 {
12890 peer = peer_lookup (NULL, &su);
12891 if (! peer)
856ca177
MS
12892 {
12893 if (use_json)
12894 {
12895 json_object *json_no = NULL;
12896 json_no = json_object_new_object();
12897 json_object_string_add(json_no, "warning", "Peer not found");
12898 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12899 json_object_free(json_no);
12900 }
12901 else
12902 vty_out (vty, "No peer%s", VTY_NEWLINE);
12903 return CMD_WARNING;
12904 }
c63b83fe 12905 }
718e3744 12906
12907 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
856ca177 12908 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, use_json);
718e3744 12909 if (count)
12910 {
856ca177
MS
12911 if (!use_json)
12912 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
12913 prefix_bgp_show_prefix_list (vty, AFI_IP, name, use_json);
12914 }
12915 else
12916 {
12917 if (use_json)
12918 {
12919 json_object *json_no = NULL;
12920 json_no = json_object_new_object();
12921 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12922 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12923 json_object_free(json_no);
12924 }
12925 else
12926 vty_out (vty, "No functional output%s", VTY_NEWLINE);
718e3744 12927 }
12928
12929 return CMD_SUCCESS;
12930}
12931
12932DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
12933 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
856ca177 12934 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 12935 SHOW_STR
12936 IP_STR
12937 BGP_STR
12938 "Address family\n"
12939 "Address Family modifier\n"
12940 "Address Family modifier\n"
12941 "Detailed information on TCP and BGP neighbor connections\n"
12942 "Neighbor to display information about\n"
12943 "Neighbor to display information about\n"
a80beece 12944 "Neighbor on bgp configured interface\n"
718e3744 12945 "Display information received from a BGP neighbor\n"
856ca177
MS
12946 "Display the prefixlist filter\n"
12947 "JavaScript Object Notation\n")
718e3744 12948{
12949 char name[BUFSIZ];
c63b83fe 12950 union sockunion su;
718e3744 12951 struct peer *peer;
c63b83fe 12952 int count, ret;
856ca177
MS
12953 u_char use_json;
12954
12955 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
12956 use_json = 1;
12957 else
12958 use_json = 0;
718e3744 12959
c63b83fe
JBD
12960 ret = str2sockunion (argv[1], &su);
12961 if (ret < 0)
12962 {
a80beece 12963 peer = peer_lookup_by_conf_if (NULL, argv[1]);
856ca177 12964 if (! peer)
a80beece 12965 {
856ca177
MS
12966 if (use_json)
12967 {
12968 json_object *json_no = NULL;
12969 json_object *json_sub = NULL;
12970 json_no = json_object_new_object();
12971 json_sub = json_object_new_object();
12972 json_object_string_add(json_no, "warning", "Malformed address or name");
12973 json_object_string_add(json_sub, "warningCause", argv[1]);
12974 json_object_object_add(json_no, "detail", json_sub);
12975 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12976 json_object_free(json_no);
12977 }
12978 else
12979 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
a80beece
DS
12980 return CMD_WARNING;
12981 }
12982 }
12983 else
12984 {
12985 peer = peer_lookup (NULL, &su);
12986 if (! peer)
856ca177
MS
12987 {
12988 if (use_json)
12989 {
12990 json_object *json_no = NULL;
12991 json_no = json_object_new_object();
12992 json_object_string_add(json_no, "warning", "Peer not found");
12993 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12994 json_object_free(json_no);
12995 }
12996 else
12997 vty_out (vty, "No peer%s", VTY_NEWLINE);
12998 return CMD_WARNING;
12999 }
c63b83fe 13000 }
718e3744 13001
13002 if (strncmp (argv[0], "m", 1) == 0)
13003 {
13004 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
856ca177 13005 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, use_json);
718e3744 13006 if (count)
856ca177
MS
13007 {
13008 if (!use_json)
13009 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
13010 prefix_bgp_show_prefix_list (vty, AFI_IP, name, use_json);
13011 }
13012 else
13013 {
13014 if (use_json)
13015 {
13016 json_object *json_no = NULL;
13017 json_no = json_object_new_object();
13018 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13019 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13020 json_object_free(json_no);
13021 }
13022 else
13023 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13024 }
718e3744 13025 }
13026 else
13027 {
13028 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
856ca177 13029 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, use_json);
718e3744 13030 if (count)
856ca177
MS
13031 {
13032 if (!use_json)
13033 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13034 prefix_bgp_show_prefix_list (vty, AFI_IP, name, use_json);
13035 }
13036 else
13037 {
13038 if (use_json)
13039 {
13040 json_object *json_no = NULL;
13041 json_no = json_object_new_object();
13042 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13043 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13044 json_object_free(json_no);
13045 }
13046 else
13047 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13048 }
718e3744 13049 }
13050
13051 return CMD_SUCCESS;
13052}
718e3744 13053#ifdef HAVE_IPV6
bb46e94f 13054ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 13055 show_bgp_neighbor_received_routes_cmd,
856ca177 13056 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 13057 SHOW_STR
13058 BGP_STR
13059 "Detailed information on TCP and BGP neighbor connections\n"
13060 "Neighbor to display information about\n"
13061 "Neighbor to display information about\n"
a80beece 13062 "Neighbor on bgp configured interface\n"
856ca177
MS
13063 "Display the received routes from neighbor\n"
13064 "JavaScript Object Notation\n")
718e3744 13065
bb46e94f 13066ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 13067 show_bgp_ipv6_neighbor_received_routes_cmd,
856ca177 13068 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
0b16f239
DS
13069 SHOW_STR
13070 BGP_STR
13071 "Address family\n"
13072 "Detailed information on TCP and BGP neighbor connections\n"
13073 "Neighbor to display information about\n"
13074 "Neighbor to display information about\n"
13075 "Neighbor on bgp configured interface\n"
856ca177
MS
13076 "Display the received routes from neighbor\n"
13077 "JavaScript Object Notation\n")
0b16f239 13078
718e3744 13079DEFUN (show_bgp_neighbor_received_prefix_filter,
13080 show_bgp_neighbor_received_prefix_filter_cmd,
856ca177 13081 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 13082 SHOW_STR
13083 BGP_STR
13084 "Detailed information on TCP and BGP neighbor connections\n"
13085 "Neighbor to display information about\n"
13086 "Neighbor to display information about\n"
a80beece 13087 "Neighbor on bgp configured interface\n"
718e3744 13088 "Display information received from a BGP neighbor\n"
856ca177
MS
13089 "Display the prefixlist filter\n"
13090 "JavaScript Object Notation\n")
718e3744 13091{
13092 char name[BUFSIZ];
c63b83fe 13093 union sockunion su;
718e3744 13094 struct peer *peer;
c63b83fe 13095 int count, ret;
856ca177
MS
13096 u_char use_json;
13097
13098 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
13099 use_json = 1;
13100 else
13101 use_json = 0;
718e3744 13102
c63b83fe
JBD
13103 ret = str2sockunion (argv[0], &su);
13104 if (ret < 0)
13105 {
a80beece 13106 peer = peer_lookup_by_conf_if (NULL, argv[0]);
856ca177 13107 if (! peer)
a80beece 13108 {
856ca177
MS
13109 if (use_json)
13110 {
13111 json_object *json_no = NULL;
13112 json_object *json_sub = NULL;
13113 json_no = json_object_new_object();
13114 json_sub = json_object_new_object();
13115 json_object_string_add(json_no, "warning", "Malformed address or name");
13116 json_object_string_add(json_sub, "warningCause", argv[0]);
13117 json_object_object_add(json_no, "detail", json_sub);
13118 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13119 json_object_free(json_no);
13120 }
13121 else
13122 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
a80beece
DS
13123 return CMD_WARNING;
13124 }
13125 }
13126 else
13127 {
13128 peer = peer_lookup (NULL, &su);
13129 if (! peer)
856ca177
MS
13130 {
13131 if (use_json)
13132 {
13133 json_object *json_no = NULL;
13134 json_no = json_object_new_object();
13135 json_object_string_add(json_no, "warning", "No Peer");
13136 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13137 json_object_free(json_no);
13138 }
13139 else
13140 vty_out (vty, "No peer%s", VTY_NEWLINE);
13141 return CMD_WARNING;
13142 }
c63b83fe 13143 }
718e3744 13144
13145 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
856ca177 13146 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, use_json);
718e3744 13147 if (count)
13148 {
856ca177
MS
13149 if (!use_json)
13150 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13151 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, use_json);
13152 }
13153 else
13154 {
13155 if (use_json)
13156 {
13157 json_object *json_no = NULL;
13158 json_no = json_object_new_object();
13159 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13160 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13161 json_object_free(json_no);
13162 }
13163 else
13164 vty_out (vty, "No functional output%s", VTY_NEWLINE);
718e3744 13165 }
13166
13167 return CMD_SUCCESS;
13168}
13169
13170ALIAS (show_bgp_neighbor_received_prefix_filter,
13171 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
856ca177 13172 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 13173 SHOW_STR
13174 BGP_STR
13175 "Address family\n"
13176 "Detailed information on TCP and BGP neighbor connections\n"
13177 "Neighbor to display information about\n"
13178 "Neighbor to display information about\n"
a80beece 13179 "Neighbor on bgp configured interface\n"
718e3744 13180 "Display information received from a BGP neighbor\n"
856ca177
MS
13181 "Display the prefixlist filter\n"
13182 "JavaScript Object Notation\n")
718e3744 13183
13184/* old command */
bb46e94f 13185ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 13186 ipv6_bgp_neighbor_received_routes_cmd,
856ca177 13187 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 13188 SHOW_STR
13189 IPV6_STR
13190 BGP_STR
13191 "Detailed information on TCP and BGP neighbor connections\n"
13192 "Neighbor to display information about\n"
13193 "Neighbor to display information about\n"
a80beece 13194 "Neighbor on bgp configured interface\n"
856ca177
MS
13195 "Display the received routes from neighbor\n"
13196 "JavaScript Object Notation\n")
718e3744 13197
13198/* old command */
13199DEFUN (ipv6_mbgp_neighbor_received_routes,
13200 ipv6_mbgp_neighbor_received_routes_cmd,
856ca177 13201 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 13202 SHOW_STR
13203 IPV6_STR
13204 MBGP_STR
13205 "Detailed information on TCP and BGP neighbor connections\n"
13206 "Neighbor to display information about\n"
13207 "Neighbor to display information about\n"
a80beece 13208 "Neighbor on bgp configured interface\n"
856ca177
MS
13209 "Display the received routes from neighbor\n"
13210 "JavaScript Object Notation\n")
718e3744 13211{
bb46e94f 13212 struct peer *peer;
856ca177
MS
13213 u_char use_json;
13214
13215 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
13216 use_json = 1;
13217 else
13218 use_json = 0;
bb46e94f 13219
856ca177 13220 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
bb46e94f 13221 if (! peer)
13222 return CMD_WARNING;
13223
856ca177 13224 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL,use_json);
bb46e94f 13225}
13226
13227DEFUN (show_bgp_view_neighbor_received_prefix_filter,
13228 show_bgp_view_neighbor_received_prefix_filter_cmd,
856ca177 13229 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
bb46e94f 13230 SHOW_STR
13231 BGP_STR
13232 "BGP view\n"
13233 "View name\n"
13234 "Detailed information on TCP and BGP neighbor connections\n"
13235 "Neighbor to display information about\n"
13236 "Neighbor to display information about\n"
a80beece 13237 "Neighbor on bgp configured interface\n"
bb46e94f 13238 "Display information received from a BGP neighbor\n"
856ca177
MS
13239 "Display the prefixlist filter\n"
13240 "JavaScript Object Notation\n")
bb46e94f 13241{
13242 char name[BUFSIZ];
c63b83fe 13243 union sockunion su;
bb46e94f 13244 struct peer *peer;
13245 struct bgp *bgp;
c63b83fe 13246 int count, ret;
856ca177
MS
13247 u_char use_json;
13248
13249 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
13250 use_json = 1;
13251 else
13252 use_json = 0;
bb46e94f 13253
13254 /* BGP structure lookup. */
13255 bgp = bgp_lookup_by_name (argv[0]);
13256 if (bgp == NULL)
856ca177
MS
13257 {
13258 if (use_json)
13259 {
13260 json_object *json_no = NULL;
13261 json_no = json_object_new_object();
13262 json_object_string_add(json_no, "warning", "Can't find BGP view");
13263 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13264 json_object_free(json_no);
13265 }
13266 else
13267 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13268 return CMD_WARNING;
13269 }
13270
c63b83fe
JBD
13271 ret = str2sockunion (argv[1], &su);
13272 if (ret < 0)
13273 {
a80beece 13274 peer = peer_lookup_by_conf_if (bgp, argv[1]);
856ca177 13275 if (! peer)
a80beece 13276 {
856ca177
MS
13277 if (use_json)
13278 {
13279 json_object *json_no = NULL;
13280 json_object *json_sub = NULL;
13281 json_no = json_object_new_object();
13282 json_sub = json_object_new_object();
13283 json_object_string_add(json_no, "warning", "Malformed address or name");
13284 json_object_string_add(json_sub, "warningCause", argv[1]);
13285 json_object_object_add(json_no, "detail", json_sub);
13286 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13287 json_object_free(json_no);
13288 }
13289 else
13290 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
a80beece
DS
13291 return CMD_WARNING;
13292 }
13293 }
13294 else
13295 {
13296 peer = peer_lookup (bgp, &su);
13297 if (! peer)
856ca177
MS
13298 {
13299 if (use_json)
13300 {
13301 json_object *json_no = NULL;
13302 json_no = json_object_new_object();
13303 json_object_boolean_true_add(json_no, "noPeer");
13304 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13305 json_object_free(json_no);
13306 }
13307 else
13308 vty_out (vty, "No peer%s", VTY_NEWLINE);
13309 return CMD_WARNING;
13310 }
13311
c63b83fe 13312 }
bb46e94f 13313
13314 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
856ca177 13315 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, use_json);
bb46e94f 13316 if (count)
13317 {
856ca177
MS
13318 if (!use_json)
13319 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13320 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, use_json);
bb46e94f 13321 }
13322
13323 return CMD_SUCCESS;
718e3744 13324}
bb46e94f 13325ALIAS (show_bgp_view_neighbor_received_prefix_filter,
13326 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
856ca177 13327 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
bb46e94f 13328 SHOW_STR
13329 BGP_STR
13330 "BGP view\n"
13331 "View name\n"
13332 "Address family\n"
13333 "Detailed information on TCP and BGP neighbor connections\n"
13334 "Neighbor to display information about\n"
13335 "Neighbor to display information about\n"
a80beece 13336 "Neighbor on bgp configured interface\n"
bb46e94f 13337 "Display information received from a BGP neighbor\n"
856ca177
MS
13338 "Display the prefixlist filter\n"
13339 "JavaScript Object NOtation\n")
718e3744 13340#endif /* HAVE_IPV6 */
6b0655a2 13341
94f2b392 13342static int
bb46e94f 13343bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
856ca177 13344 safi_t safi, enum bgp_show_type type, u_char use_json)
718e3744 13345{
718e3744 13346 if (! peer || ! peer->afc[afi][safi])
13347 {
856ca177
MS
13348 if (use_json)
13349 {
13350 json_object *json_no = NULL;
13351 json_no = json_object_new_object();
13352 json_object_string_add(json_no, "warning", "No such neighbor or address family");
13353 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13354 json_object_free(json_no);
13355 }
13356 else
13357 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
718e3744 13358 return CMD_WARNING;
13359 }
47fc97cc 13360
856ca177 13361 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json);
718e3744 13362}
13363
13364DEFUN (show_ip_bgp_neighbor_routes,
13365 show_ip_bgp_neighbor_routes_cmd,
856ca177 13366 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13367 SHOW_STR
13368 IP_STR
13369 BGP_STR
13370 "Detailed information on TCP and BGP neighbor connections\n"
13371 "Neighbor to display information about\n"
13372 "Neighbor to display information about\n"
a80beece 13373 "Neighbor on bgp configured interface\n"
856ca177
MS
13374 "Display routes learned from neighbor\n"
13375 "JavaScript Object Notation\n")
718e3744 13376{
bb46e94f 13377 struct peer *peer;
856ca177 13378 u_char use_json;
bb46e94f 13379
856ca177
MS
13380 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
13381 use_json = 1;
13382 else
13383 use_json = 0;
13384
13385 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
bb46e94f 13386 if (! peer)
13387 return CMD_WARNING;
13388
13389 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
856ca177 13390 bgp_show_type_neighbor, use_json);
718e3744 13391}
13392
13393DEFUN (show_ip_bgp_neighbor_flap,
13394 show_ip_bgp_neighbor_flap_cmd,
856ca177 13395 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
718e3744 13396 SHOW_STR
13397 IP_STR
13398 BGP_STR
13399 "Detailed information on TCP and BGP neighbor connections\n"
13400 "Neighbor to display information about\n"
13401 "Neighbor to display information about\n"
a80beece 13402 "Neighbor on bgp configured interface\n"
856ca177
MS
13403 "Display flap statistics of the routes learned from neighbor\n"
13404 "JavaScript Object Notation\n")
718e3744 13405{
bb46e94f 13406 struct peer *peer;
856ca177
MS
13407 u_char use_json;
13408
13409 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
13410 use_json = 1;
13411 else
13412 use_json = 0;
bb46e94f 13413
856ca177 13414 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
bb46e94f 13415 if (! peer)
13416 return CMD_WARNING;
13417
13418 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
856ca177 13419 bgp_show_type_flap_neighbor, use_json);
718e3744 13420}
13421
13422DEFUN (show_ip_bgp_neighbor_damp,
13423 show_ip_bgp_neighbor_damp_cmd,
856ca177 13424 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
718e3744 13425 SHOW_STR
13426 IP_STR
13427 BGP_STR
13428 "Detailed information on TCP and BGP neighbor connections\n"
13429 "Neighbor to display information about\n"
13430 "Neighbor to display information about\n"
a80beece 13431 "Neighbor on bgp configured interface\n"
856ca177
MS
13432 "Display the dampened routes received from neighbor\n"
13433 "JavaScript Object Notation\n")
718e3744 13434{
bb46e94f 13435 struct peer *peer;
856ca177
MS
13436 u_char use_json;
13437
13438 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
13439 use_json = 1;
13440 else
13441 use_json = 0;
bb46e94f 13442
856ca177 13443 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
bb46e94f 13444 if (! peer)
13445 return CMD_WARNING;
13446
13447 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
856ca177 13448 bgp_show_type_damp_neighbor, use_json);
718e3744 13449}
13450
13451DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13452 show_ip_bgp_ipv4_neighbor_routes_cmd,
856ca177 13453 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13454 SHOW_STR
13455 IP_STR
13456 BGP_STR
13457 "Address family\n"
13458 "Address Family modifier\n"
13459 "Address Family modifier\n"
13460 "Detailed information on TCP and BGP neighbor connections\n"
13461 "Neighbor to display information about\n"
13462 "Neighbor to display information about\n"
a80beece 13463 "Neighbor on bgp configured interface\n"
856ca177
MS
13464 "Display routes learned from neighbor\n"
13465 "JavaScript Object Notation\n")
718e3744 13466{
bb46e94f 13467 struct peer *peer;
856ca177
MS
13468 u_char use_json;
13469
13470 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
13471 use_json = 1;
13472 else
13473 use_json = 0;
bb46e94f 13474
856ca177 13475 peer = peer_lookup_in_view (vty, NULL, argv[1], use_json);
bb46e94f 13476 if (! peer)
13477 return CMD_WARNING;
13478
718e3744 13479 if (strncmp (argv[0], "m", 1) == 0)
bb46e94f 13480 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
856ca177 13481 bgp_show_type_neighbor, use_json);
718e3744 13482
bb46e94f 13483 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
856ca177 13484 bgp_show_type_neighbor, use_json);
718e3744 13485}
bb46e94f 13486
fee0f4c6 13487DEFUN (show_ip_bgp_view_rsclient,
13488 show_ip_bgp_view_rsclient_cmd,
a80beece 13489 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 13490 SHOW_STR
13491 IP_STR
13492 BGP_STR
13493 "BGP view\n"
2b00515a 13494 "View name\n"
fee0f4c6 13495 "Information about Route Server Client\n"
a80beece 13496 NEIGHBOR_ADDR_STR3)
fee0f4c6 13497{
13498 struct bgp_table *table;
13499 struct peer *peer;
13500
13501 if (argc == 2)
856ca177 13502 peer = peer_lookup_in_view (vty, argv[0], argv[1], 0);
fee0f4c6 13503 else
856ca177 13504 peer = peer_lookup_in_view (vty, NULL, argv[0], 0);
fee0f4c6 13505
13506 if (! peer)
13507 return CMD_WARNING;
13508
13509 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13510 {
13511 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13512 VTY_NEWLINE);
13513 return CMD_WARNING;
13514 }
13515
13516 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13517 PEER_FLAG_RSERVER_CLIENT))
13518 {
13519 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13520 VTY_NEWLINE);
13521 return CMD_WARNING;
13522 }
13523
13524 table = peer->rib[AFI_IP][SAFI_UNICAST];
13525
47fc97cc 13526 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
b05a1c8b 13527 NULL, 0);
fee0f4c6 13528}
13529
13530ALIAS (show_ip_bgp_view_rsclient,
13531 show_ip_bgp_rsclient_cmd,
a80beece 13532 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 13533 SHOW_STR
13534 IP_STR
13535 BGP_STR
13536 "Information about Route Server Client\n"
a80beece 13537 NEIGHBOR_ADDR_STR3)
fee0f4c6 13538
95cbbd2a
ML
13539DEFUN (show_bgp_view_ipv4_safi_rsclient,
13540 show_bgp_view_ipv4_safi_rsclient_cmd,
a80beece 13541 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 13542 SHOW_STR
fee0f4c6 13543 BGP_STR
13544 "BGP view\n"
2b00515a 13545 "View name\n"
95cbbd2a
ML
13546 "Address family\n"
13547 "Address Family modifier\n"
13548 "Address Family modifier\n"
fee0f4c6 13549 "Information about Route Server Client\n"
a80beece 13550 NEIGHBOR_ADDR_STR3)
fee0f4c6 13551{
95cbbd2a 13552 struct bgp_table *table;
fee0f4c6 13553 struct peer *peer;
95cbbd2a 13554 safi_t safi;
fee0f4c6 13555
95cbbd2a 13556 if (argc == 3) {
856ca177 13557 peer = peer_lookup_in_view (vty, argv[0], argv[2], 0);
95cbbd2a
ML
13558 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13559 } else {
856ca177 13560 peer = peer_lookup_in_view (vty, NULL, argv[1], 0);
95cbbd2a
ML
13561 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13562 }
13563
13564 if (! peer)
13565 return CMD_WARNING;
13566
13567 if (! peer->afc[AFI_IP][safi])
fee0f4c6 13568 {
95cbbd2a
ML
13569 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13570 VTY_NEWLINE);
13571 return CMD_WARNING;
13572 }
13573
13574 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13575 PEER_FLAG_RSERVER_CLIENT))
13576 {
13577 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13578 VTY_NEWLINE);
13579 return CMD_WARNING;
13580 }
13581
13582 table = peer->rib[AFI_IP][safi];
13583
47fc97cc 13584 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
b05a1c8b 13585 NULL, 0);
95cbbd2a
ML
13586}
13587
13588ALIAS (show_bgp_view_ipv4_safi_rsclient,
13589 show_bgp_ipv4_safi_rsclient_cmd,
a80beece 13590 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
95cbbd2a
ML
13591 SHOW_STR
13592 BGP_STR
13593 "Address family\n"
13594 "Address Family modifier\n"
13595 "Address Family modifier\n"
13596 "Information about Route Server Client\n"
a80beece 13597 NEIGHBOR_ADDR_STR3)
95cbbd2a
ML
13598
13599DEFUN (show_ip_bgp_view_rsclient_route,
13600 show_ip_bgp_view_rsclient_route_cmd,
a80beece 13601 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
95cbbd2a
ML
13602 SHOW_STR
13603 IP_STR
13604 BGP_STR
13605 "BGP view\n"
2b00515a 13606 "View name\n"
95cbbd2a 13607 "Information about Route Server Client\n"
a80beece 13608 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13609 "Network in the BGP routing table to display\n")
13610{
13611 struct bgp *bgp;
13612 struct peer *peer;
13613
13614 /* BGP structure lookup. */
13615 if (argc == 3)
13616 {
13617 bgp = bgp_lookup_by_name (argv[0]);
13618 if (bgp == NULL)
13619 {
13620 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13621 return CMD_WARNING;
fee0f4c6 13622 }
13623 }
13624 else
13625 {
13626 bgp = bgp_get_default ();
13627 if (bgp == NULL)
13628 {
13629 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13630 return CMD_WARNING;
13631 }
13632 }
13633
13634 if (argc == 3)
856ca177 13635 peer = peer_lookup_in_view (vty, argv[0], argv[1], 0);
fee0f4c6 13636 else
856ca177 13637 peer = peer_lookup_in_view (vty, NULL, argv[0], 0);
fee0f4c6 13638
13639 if (! peer)
13640 return CMD_WARNING;
13641
13642 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13643 {
13644 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13645 VTY_NEWLINE);
13646 return CMD_WARNING;
b05a1c8b 13647 }
fee0f4c6 13648
13649 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13650 PEER_FLAG_RSERVER_CLIENT))
13651 {
13652 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13653 VTY_NEWLINE);
13654 return CMD_WARNING;
13655 }
13656
13657 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13658 (argc == 3) ? argv[2] : argv[1],
b05a1c8b 13659 AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, 0);
fee0f4c6 13660}
13661
13662ALIAS (show_ip_bgp_view_rsclient_route,
13663 show_ip_bgp_rsclient_route_cmd,
a80beece 13664 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
fee0f4c6 13665 SHOW_STR
13666 IP_STR
13667 BGP_STR
13668 "Information about Route Server Client\n"
a80beece 13669 NEIGHBOR_ADDR_STR3
fee0f4c6 13670 "Network in the BGP routing table to display\n")
13671
95cbbd2a
ML
13672DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
13673 show_bgp_view_ipv4_safi_rsclient_route_cmd,
a80beece 13674 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
95cbbd2a
ML
13675 SHOW_STR
13676 BGP_STR
13677 "BGP view\n"
2b00515a 13678 "View name\n"
95cbbd2a
ML
13679 "Address family\n"
13680 "Address Family modifier\n"
13681 "Address Family modifier\n"
13682 "Information about Route Server Client\n"
a80beece 13683 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13684 "Network in the BGP routing table to display\n")
13685{
13686 struct bgp *bgp;
13687 struct peer *peer;
13688 safi_t safi;
13689
13690 /* BGP structure lookup. */
13691 if (argc == 4)
13692 {
13693 bgp = bgp_lookup_by_name (argv[0]);
13694 if (bgp == NULL)
13695 {
13696 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13697 return CMD_WARNING;
13698 }
13699 }
13700 else
13701 {
13702 bgp = bgp_get_default ();
13703 if (bgp == NULL)
13704 {
13705 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13706 return CMD_WARNING;
13707 }
13708 }
13709
13710 if (argc == 4) {
856ca177 13711 peer = peer_lookup_in_view (vty, argv[0], argv[2], 0);
95cbbd2a
ML
13712 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13713 } else {
856ca177 13714 peer = peer_lookup_in_view (vty, NULL, argv[1], 0);
95cbbd2a
ML
13715 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13716 }
13717
13718 if (! peer)
13719 return CMD_WARNING;
13720
13721 if (! peer->afc[AFI_IP][safi])
13722 {
13723 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13724 VTY_NEWLINE);
13725 return CMD_WARNING;
13726}
13727
13728 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13729 PEER_FLAG_RSERVER_CLIENT))
13730 {
13731 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13732 VTY_NEWLINE);
13733 return CMD_WARNING;
13734 }
13735
13736 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
13737 (argc == 4) ? argv[3] : argv[2],
b05a1c8b 13738 AFI_IP, safi, NULL, 0, BGP_PATH_ALL, 0);
95cbbd2a
ML
13739}
13740
13741ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
13742 show_bgp_ipv4_safi_rsclient_route_cmd,
a80beece 13743 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
95cbbd2a
ML
13744 SHOW_STR
13745 BGP_STR
13746 "Address family\n"
13747 "Address Family modifier\n"
13748 "Address Family modifier\n"
13749 "Information about Route Server Client\n"
a80beece 13750 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13751 "Network in the BGP routing table to display\n")
13752
fee0f4c6 13753DEFUN (show_ip_bgp_view_rsclient_prefix,
13754 show_ip_bgp_view_rsclient_prefix_cmd,
a80beece 13755 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
fee0f4c6 13756 SHOW_STR
13757 IP_STR
13758 BGP_STR
13759 "BGP view\n"
2b00515a 13760 "View name\n"
fee0f4c6 13761 "Information about Route Server Client\n"
a80beece 13762 NEIGHBOR_ADDR_STR3
fee0f4c6 13763 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13764{
13765 struct bgp *bgp;
13766 struct peer *peer;
13767
13768 /* BGP structure lookup. */
13769 if (argc == 3)
13770 {
13771 bgp = bgp_lookup_by_name (argv[0]);
13772 if (bgp == NULL)
13773 {
13774 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13775 return CMD_WARNING;
13776 }
13777 }
13778 else
13779 {
13780 bgp = bgp_get_default ();
13781 if (bgp == NULL)
13782 {
13783 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13784 return CMD_WARNING;
13785 }
13786 }
13787
13788 if (argc == 3)
856ca177 13789 peer = peer_lookup_in_view (vty, argv[0], argv[1], 0);
fee0f4c6 13790 else
856ca177 13791 peer = peer_lookup_in_view (vty, NULL, argv[0], 0);
fee0f4c6 13792
13793 if (! peer)
13794 return CMD_WARNING;
13795
13796 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13797 {
13798 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13799 VTY_NEWLINE);
13800 return CMD_WARNING;
13801}
13802
13803 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13804 PEER_FLAG_RSERVER_CLIENT))
13805{
13806 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13807 VTY_NEWLINE);
13808 return CMD_WARNING;
13809 }
13810
13811 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13812 (argc == 3) ? argv[2] : argv[1],
b05a1c8b 13813 AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, 0);
fee0f4c6 13814}
13815
13816ALIAS (show_ip_bgp_view_rsclient_prefix,
13817 show_ip_bgp_rsclient_prefix_cmd,
a80beece 13818 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
fee0f4c6 13819 SHOW_STR
13820 IP_STR
13821 BGP_STR
13822 "Information about Route Server Client\n"
a80beece 13823 NEIGHBOR_ADDR_STR3
fee0f4c6 13824 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13825
95cbbd2a
ML
13826DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
13827 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
a80beece 13828 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
95cbbd2a
ML
13829 SHOW_STR
13830 BGP_STR
13831 "BGP view\n"
2b00515a 13832 "View name\n"
95cbbd2a
ML
13833 "Address family\n"
13834 "Address Family modifier\n"
13835 "Address Family modifier\n"
13836 "Information about Route Server Client\n"
a80beece 13837 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13838 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13839{
13840 struct bgp *bgp;
13841 struct peer *peer;
13842 safi_t safi;
13843
13844 /* BGP structure lookup. */
13845 if (argc == 4)
13846 {
13847 bgp = bgp_lookup_by_name (argv[0]);
13848 if (bgp == NULL)
13849 {
13850 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13851 return CMD_WARNING;
13852 }
13853 }
13854 else
13855 {
13856 bgp = bgp_get_default ();
13857 if (bgp == NULL)
13858 {
13859 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13860 return CMD_WARNING;
13861 }
13862 }
13863
13864 if (argc == 4) {
856ca177 13865 peer = peer_lookup_in_view (vty, argv[0], argv[2], 0);
95cbbd2a
ML
13866 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13867 } else {
856ca177 13868 peer = peer_lookup_in_view (vty, NULL, argv[1], 0);
95cbbd2a
ML
13869 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13870 }
13871
13872 if (! peer)
13873 return CMD_WARNING;
13874
13875 if (! peer->afc[AFI_IP][safi])
13876 {
13877 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13878 VTY_NEWLINE);
13879 return CMD_WARNING;
13880}
13881
13882 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13883 PEER_FLAG_RSERVER_CLIENT))
13884{
13885 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13886 VTY_NEWLINE);
13887 return CMD_WARNING;
13888 }
13889
13890 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
13891 (argc == 4) ? argv[3] : argv[2],
b05a1c8b 13892 AFI_IP, safi, NULL, 1, BGP_PATH_ALL, 0);
95cbbd2a
ML
13893}
13894
13895ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
13896 show_bgp_ipv4_safi_rsclient_prefix_cmd,
a80beece 13897 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
95cbbd2a
ML
13898 SHOW_STR
13899 BGP_STR
13900 "Address family\n"
13901 "Address Family modifier\n"
13902 "Address Family modifier\n"
13903 "Information about Route Server Client\n"
a80beece 13904 NEIGHBOR_ADDR_STR3
95cbbd2a 13905 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
fee0f4c6 13906
718e3744 13907#ifdef HAVE_IPV6
bb46e94f 13908DEFUN (show_bgp_view_neighbor_routes,
13909 show_bgp_view_neighbor_routes_cmd,
856ca177 13910 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13911 SHOW_STR
13912 BGP_STR
bb46e94f 13913 "BGP view\n"
2b00515a 13914 "View name\n"
718e3744 13915 "Detailed information on TCP and BGP neighbor connections\n"
13916 "Neighbor to display information about\n"
13917 "Neighbor to display information about\n"
a80beece 13918 "Neighbor on bgp configured interface\n"
856ca177
MS
13919 "Display routes learned from neighbor\n"
13920 "JavaScript Object Notation\n")
718e3744 13921{
bb46e94f 13922 struct peer *peer;
856ca177 13923 u_char use_json;
bb46e94f 13924
856ca177
MS
13925 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
13926 use_json = 1;
13927 else
13928 use_json = 0;
13929
13930 if ((argc == 3 && argv[2] && strcmp(argv[2], "json") == 0)
13931 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
13932 peer = peer_lookup_in_view (vty, argv[0], argv[1], use_json);
bb46e94f 13933 else
856ca177 13934 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
bb46e94f 13935
13936 if (! peer)
13937 return CMD_WARNING;
13938
13939 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
856ca177 13940 bgp_show_type_neighbor, use_json);
718e3744 13941}
13942
bb46e94f 13943ALIAS (show_bgp_view_neighbor_routes,
13944 show_bgp_view_ipv6_neighbor_routes_cmd,
856ca177 13945 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
bb46e94f 13946 SHOW_STR
13947 BGP_STR
13948 "BGP view\n"
2b00515a 13949 "View name\n"
bb46e94f 13950 "Address family\n"
13951 "Detailed information on TCP and BGP neighbor connections\n"
13952 "Neighbor to display information about\n"
13953 "Neighbor to display information about\n"
a80beece 13954 "Neighbor on bgp configured interface\n"
856ca177
MS
13955 "Display routes learned from neighbor\n"
13956 "JavaScript Object Notation\n")
bb46e94f 13957
13958DEFUN (show_bgp_view_neighbor_damp,
13959 show_bgp_view_neighbor_damp_cmd,
856ca177 13960 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
bb46e94f 13961 SHOW_STR
13962 BGP_STR
13963 "BGP view\n"
2b00515a 13964 "View name\n"
bb46e94f 13965 "Detailed information on TCP and BGP neighbor connections\n"
13966 "Neighbor to display information about\n"
13967 "Neighbor to display information about\n"
a80beece 13968 "Neighbor on bgp configured interface\n"
856ca177
MS
13969 "Display the dampened routes received from neighbor\n"
13970 "JavaScript Object Notation\n")
bb46e94f 13971{
13972 struct peer *peer;
856ca177 13973 u_char use_json;
bb46e94f 13974
856ca177
MS
13975 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
13976 use_json = 1;
13977 else
13978 use_json = 0;
13979
13980 if ((argc == 3 && argv[2] && strcmp(argv[2], "json") == 0)
13981 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
13982 peer = peer_lookup_in_view (vty, argv[0], argv[1], use_json);
bb46e94f 13983 else
856ca177 13984 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
bb46e94f 13985
13986 if (! peer)
13987 return CMD_WARNING;
13988
13989 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
856ca177 13990 bgp_show_type_damp_neighbor, use_json);
bb46e94f 13991}
13992
13993ALIAS (show_bgp_view_neighbor_damp,
13994 show_bgp_view_ipv6_neighbor_damp_cmd,
856ca177 13995 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
bb46e94f 13996 SHOW_STR
13997 BGP_STR
13998 "BGP view\n"
2b00515a 13999 "View name\n"
bb46e94f 14000 "Address family\n"
14001 "Detailed information on TCP and BGP neighbor connections\n"
14002 "Neighbor to display information about\n"
14003 "Neighbor to display information about\n"
a80beece 14004 "Neighbor on bgp configured interface\n"
856ca177
MS
14005 "Display the dampened routes received from neighbor\n"
14006 "JavaScript Object Notation\n")
bb46e94f 14007
14008DEFUN (show_bgp_view_neighbor_flap,
14009 show_bgp_view_neighbor_flap_cmd,
856ca177 14010 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 14011 SHOW_STR
14012 BGP_STR
14013 "BGP view\n"
2b00515a 14014 "View name\n"
bb46e94f 14015 "Detailed information on TCP and BGP neighbor connections\n"
14016 "Neighbor to display information about\n"
14017 "Neighbor to display information about\n"
a80beece 14018 "Neighbor on bgp configured interface\n"
856ca177
MS
14019 "Display flap statistics of the routes learned from neighbor\n"
14020 "JavaScript Object Notation\n")
bb46e94f 14021{
14022 struct peer *peer;
856ca177 14023 u_char use_json;
bb46e94f 14024
856ca177
MS
14025 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
14026 use_json = 1;
14027 else
14028 use_json = 0;
14029
14030 if ((argc == 3 && argv[2] && strcmp(argv[2], "json") == 0)
14031 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
14032 peer = peer_lookup_in_view (vty, argv[0], argv[1], use_json);
bb46e94f 14033 else
856ca177 14034 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
bb46e94f 14035
14036 if (! peer)
14037 return CMD_WARNING;
14038
14039 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
856ca177 14040 bgp_show_type_flap_neighbor, use_json);
bb46e94f 14041}
14042
14043ALIAS (show_bgp_view_neighbor_flap,
14044 show_bgp_view_ipv6_neighbor_flap_cmd,
856ca177 14045 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 14046 SHOW_STR
14047 BGP_STR
14048 "BGP view\n"
2b00515a 14049 "View name\n"
bb46e94f 14050 "Address family\n"
14051 "Detailed information on TCP and BGP neighbor connections\n"
14052 "Neighbor to display information about\n"
14053 "Neighbor to display information about\n"
a80beece 14054 "Neighbor on bgp configured interface\n"
856ca177
MS
14055 "Display flap statistics of the routes learned from neighbor\n"
14056 "JavaScript Object Notation\n")
bb46e94f 14057
14058ALIAS (show_bgp_view_neighbor_routes,
14059 show_bgp_neighbor_routes_cmd,
856ca177 14060 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
bb46e94f 14061 SHOW_STR
14062 BGP_STR
14063 "Detailed information on TCP and BGP neighbor connections\n"
14064 "Neighbor to display information about\n"
14065 "Neighbor to display information about\n"
a80beece 14066 "Neighbor on bgp configured interface\n"
856ca177
MS
14067 "Display routes learned from neighbor\n"
14068 "JavaScript Object Notation\n")
bb46e94f 14069
14070
14071ALIAS (show_bgp_view_neighbor_routes,
718e3744 14072 show_bgp_ipv6_neighbor_routes_cmd,
856ca177 14073 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 14074 SHOW_STR
14075 BGP_STR
14076 "Address family\n"
14077 "Detailed information on TCP and BGP neighbor connections\n"
14078 "Neighbor to display information about\n"
14079 "Neighbor to display information about\n"
a80beece 14080 "Neighbor on bgp configured interface\n"
856ca177
MS
14081 "Display routes learned from neighbor\n"
14082 "JavaScript Object Notation\n")
718e3744 14083
14084/* old command */
bb46e94f 14085ALIAS (show_bgp_view_neighbor_routes,
718e3744 14086 ipv6_bgp_neighbor_routes_cmd,
856ca177 14087 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 14088 SHOW_STR
14089 IPV6_STR
14090 BGP_STR
14091 "Detailed information on TCP and BGP neighbor connections\n"
14092 "Neighbor to display information about\n"
14093 "Neighbor to display information about\n"
a80beece 14094 "Neighbor on bgp configured interface\n"
856ca177
MS
14095 "Display routes learned from neighbor\n"
14096 "JavaScript Object Notation\n")
718e3744 14097
14098/* old command */
14099DEFUN (ipv6_mbgp_neighbor_routes,
14100 ipv6_mbgp_neighbor_routes_cmd,
856ca177 14101 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 14102 SHOW_STR
14103 IPV6_STR
14104 MBGP_STR
14105 "Detailed information on TCP and BGP neighbor connections\n"
14106 "Neighbor to display information about\n"
14107 "Neighbor to display information about\n"
a80beece 14108 "Neighbor on bgp configured interface\n"
856ca177
MS
14109 "Display routes learned from neighbor\n"
14110 "JavaScript Object Notation\n")
718e3744 14111{
bb46e94f 14112 struct peer *peer;
856ca177
MS
14113 u_char use_json;
14114
14115 if (argv[argc - 1] && strcmp(argv[argc - 1], "json") == 0)
14116 use_json = 1;
14117 else
14118 use_json = 0;
bb46e94f 14119
856ca177 14120 peer = peer_lookup_in_view (vty, NULL, argv[0], use_json);
bb46e94f 14121 if (! peer)
14122 return CMD_WARNING;
14123
14124 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
856ca177 14125 bgp_show_type_neighbor, use_json);
718e3744 14126}
bb46e94f 14127
14128ALIAS (show_bgp_view_neighbor_flap,
14129 show_bgp_neighbor_flap_cmd,
856ca177 14130 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 14131 SHOW_STR
14132 BGP_STR
14133 "Detailed information on TCP and BGP neighbor connections\n"
14134 "Neighbor to display information about\n"
14135 "Neighbor to display information about\n"
a80beece 14136 "Neighbor on bgp configured interface\n"
856ca177
MS
14137 "Display flap statistics of the routes learned from neighbor\n"
14138 "JavaScript Object Notation\n")
bb46e94f 14139
14140ALIAS (show_bgp_view_neighbor_flap,
14141 show_bgp_ipv6_neighbor_flap_cmd,
856ca177 14142 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 14143 SHOW_STR
14144 BGP_STR
14145 "Address family\n"
14146 "Detailed information on TCP and BGP neighbor connections\n"
14147 "Neighbor to display information about\n"
14148 "Neighbor to display information about\n"
a80beece 14149 "Neighbor on bgp configured interface\n"
856ca177
MS
14150 "Display flap statistics of the routes learned from neighbor\n"
14151 "JavaScript Object Notation\n")
bb46e94f 14152
14153ALIAS (show_bgp_view_neighbor_damp,
14154 show_bgp_neighbor_damp_cmd,
856ca177 14155 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
bb46e94f 14156 SHOW_STR
14157 BGP_STR
14158 "Detailed information on TCP and BGP neighbor connections\n"
14159 "Neighbor to display information about\n"
14160 "Neighbor to display information about\n"
a80beece 14161 "Neighbor on bgp configured interface\n"
856ca177
MS
14162 "Display the dampened routes received from neighbor\n"
14163 "JavaScript Object Notation\n")
bb46e94f 14164
14165ALIAS (show_bgp_view_neighbor_damp,
14166 show_bgp_ipv6_neighbor_damp_cmd,
856ca177 14167 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
bb46e94f 14168 SHOW_STR
14169 BGP_STR
14170 "Address family\n"
14171 "Detailed information on TCP and BGP neighbor connections\n"
14172 "Neighbor to display information about\n"
14173 "Neighbor to display information about\n"
a80beece 14174 "Neighbor on bgp configured interface\n"
856ca177
MS
14175 "Display the dampened routes received from neighbor\n"
14176 "JavaScript Object Notation\n")
fee0f4c6 14177
14178DEFUN (show_bgp_view_rsclient,
14179 show_bgp_view_rsclient_cmd,
a80beece 14180 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 14181 SHOW_STR
14182 BGP_STR
14183 "BGP view\n"
2b00515a 14184 "View name\n"
fee0f4c6 14185 "Information about Route Server Client\n"
a80beece 14186 NEIGHBOR_ADDR_STR3)
fee0f4c6 14187{
14188 struct bgp_table *table;
14189 struct peer *peer;
14190
14191 if (argc == 2)
856ca177 14192 peer = peer_lookup_in_view (vty, argv[0], argv[1], 0);
fee0f4c6 14193 else
856ca177 14194 peer = peer_lookup_in_view (vty, NULL, argv[0], 0);
fee0f4c6 14195
14196 if (! peer)
14197 return CMD_WARNING;
14198
14199 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14200 {
14201 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14202 VTY_NEWLINE);
14203 return CMD_WARNING;
14204 }
14205
14206 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14207 PEER_FLAG_RSERVER_CLIENT))
14208 {
14209 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14210 VTY_NEWLINE);
14211 return CMD_WARNING;
14212 }
14213
14214 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14215
47fc97cc 14216 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
b05a1c8b 14217 NULL, 0);
fee0f4c6 14218}
14219
14220ALIAS (show_bgp_view_rsclient,
14221 show_bgp_rsclient_cmd,
a80beece 14222 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 14223 SHOW_STR
14224 BGP_STR
14225 "Information about Route Server Client\n"
a80beece 14226 NEIGHBOR_ADDR_STR3)
fee0f4c6 14227
95cbbd2a
ML
14228DEFUN (show_bgp_view_ipv6_safi_rsclient,
14229 show_bgp_view_ipv6_safi_rsclient_cmd,
a80beece 14230 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
95cbbd2a
ML
14231 SHOW_STR
14232 BGP_STR
14233 "BGP view\n"
2b00515a 14234 "View name\n"
95cbbd2a
ML
14235 "Address family\n"
14236 "Address Family modifier\n"
14237 "Address Family modifier\n"
14238 "Information about Route Server Client\n"
a80beece 14239 NEIGHBOR_ADDR_STR3)
95cbbd2a
ML
14240{
14241 struct bgp_table *table;
14242 struct peer *peer;
14243 safi_t safi;
14244
14245 if (argc == 3) {
856ca177 14246 peer = peer_lookup_in_view (vty, argv[0], argv[2], 0);
95cbbd2a
ML
14247 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14248 } else {
856ca177 14249 peer = peer_lookup_in_view (vty, NULL, argv[1], 0);
95cbbd2a
ML
14250 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14251 }
14252
14253 if (! peer)
14254 return CMD_WARNING;
14255
14256 if (! peer->afc[AFI_IP6][safi])
14257 {
14258 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14259 VTY_NEWLINE);
14260 return CMD_WARNING;
14261 }
14262
14263 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14264 PEER_FLAG_RSERVER_CLIENT))
14265 {
14266 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14267 VTY_NEWLINE);
14268 return CMD_WARNING;
14269 }
14270
14271 table = peer->rib[AFI_IP6][safi];
14272
47fc97cc 14273 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
b05a1c8b 14274 NULL, 0);
95cbbd2a
ML
14275}
14276
14277ALIAS (show_bgp_view_ipv6_safi_rsclient,
14278 show_bgp_ipv6_safi_rsclient_cmd,
a80beece 14279 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
95cbbd2a
ML
14280 SHOW_STR
14281 BGP_STR
14282 "Address family\n"
14283 "Address Family modifier\n"
14284 "Address Family modifier\n"
14285 "Information about Route Server Client\n"
a80beece 14286 NEIGHBOR_ADDR_STR3)
95cbbd2a 14287
fee0f4c6 14288DEFUN (show_bgp_view_rsclient_route,
14289 show_bgp_view_rsclient_route_cmd,
a80beece 14290 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
fee0f4c6 14291 SHOW_STR
14292 BGP_STR
14293 "BGP view\n"
2b00515a 14294 "View name\n"
fee0f4c6 14295 "Information about Route Server Client\n"
a80beece 14296 NEIGHBOR_ADDR_STR3
fee0f4c6 14297 "Network in the BGP routing table to display\n")
14298{
14299 struct bgp *bgp;
14300 struct peer *peer;
14301
14302 /* BGP structure lookup. */
14303 if (argc == 3)
14304 {
14305 bgp = bgp_lookup_by_name (argv[0]);
14306 if (bgp == NULL)
14307 {
14308 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14309 return CMD_WARNING;
14310 }
14311 }
14312 else
14313 {
14314 bgp = bgp_get_default ();
14315 if (bgp == NULL)
14316 {
14317 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14318 return CMD_WARNING;
14319 }
14320 }
14321
14322 if (argc == 3)
856ca177 14323 peer = peer_lookup_in_view (vty, argv[0], argv[1], 0);
fee0f4c6 14324 else
856ca177 14325 peer = peer_lookup_in_view (vty, NULL, argv[0], 0);
fee0f4c6 14326
14327 if (! peer)
14328 return CMD_WARNING;
14329
14330 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14331 {
14332 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14333 VTY_NEWLINE);
14334 return CMD_WARNING;
14335 }
14336
14337 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14338 PEER_FLAG_RSERVER_CLIENT))
14339 {
14340 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14341 VTY_NEWLINE);
14342 return CMD_WARNING;
14343 }
14344
14345 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14346 (argc == 3) ? argv[2] : argv[1],
b05a1c8b 14347 AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, 0);
fee0f4c6 14348}
14349
14350ALIAS (show_bgp_view_rsclient_route,
14351 show_bgp_rsclient_route_cmd,
a80beece 14352 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
fee0f4c6 14353 SHOW_STR
14354 BGP_STR
14355 "Information about Route Server Client\n"
a80beece 14356 NEIGHBOR_ADDR_STR3
fee0f4c6 14357 "Network in the BGP routing table to display\n")
14358
95cbbd2a
ML
14359DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
14360 show_bgp_view_ipv6_safi_rsclient_route_cmd,
a80beece 14361 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
95cbbd2a
ML
14362 SHOW_STR
14363 BGP_STR
14364 "BGP view\n"
2b00515a 14365 "View name\n"
95cbbd2a
ML
14366 "Address family\n"
14367 "Address Family modifier\n"
14368 "Address Family modifier\n"
14369 "Information about Route Server Client\n"
a80beece 14370 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
14371 "Network in the BGP routing table to display\n")
14372{
14373 struct bgp *bgp;
14374 struct peer *peer;
14375 safi_t safi;
14376
14377 /* BGP structure lookup. */
14378 if (argc == 4)
14379 {
14380 bgp = bgp_lookup_by_name (argv[0]);
14381 if (bgp == NULL)
14382 {
14383 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14384 return CMD_WARNING;
14385 }
14386 }
14387 else
14388 {
14389 bgp = bgp_get_default ();
14390 if (bgp == NULL)
14391 {
14392 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14393 return CMD_WARNING;
14394 }
14395 }
14396
14397 if (argc == 4) {
856ca177 14398 peer = peer_lookup_in_view (vty, argv[0], argv[2], 0);
95cbbd2a
ML
14399 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14400 } else {
856ca177 14401 peer = peer_lookup_in_view (vty, NULL, argv[1], 0);
95cbbd2a
ML
14402 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14403 }
14404
14405 if (! peer)
14406 return CMD_WARNING;
14407
14408 if (! peer->afc[AFI_IP6][safi])
14409 {
14410 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14411 VTY_NEWLINE);
14412 return CMD_WARNING;
14413}
14414
14415 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14416 PEER_FLAG_RSERVER_CLIENT))
14417 {
14418 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14419 VTY_NEWLINE);
14420 return CMD_WARNING;
14421 }
14422
14423 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
14424 (argc == 4) ? argv[3] : argv[2],
b05a1c8b 14425 AFI_IP6, safi, NULL, 0, BGP_PATH_ALL, 0);
95cbbd2a
ML
14426}
14427
14428ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
14429 show_bgp_ipv6_safi_rsclient_route_cmd,
a80beece 14430 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
95cbbd2a
ML
14431 SHOW_STR
14432 BGP_STR
14433 "Address family\n"
14434 "Address Family modifier\n"
14435 "Address Family modifier\n"
14436 "Information about Route Server Client\n"
a80beece 14437 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
14438 "Network in the BGP routing table to display\n")
14439
fee0f4c6 14440DEFUN (show_bgp_view_rsclient_prefix,
14441 show_bgp_view_rsclient_prefix_cmd,
a80beece 14442 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
fee0f4c6 14443 SHOW_STR
14444 BGP_STR
14445 "BGP view\n"
2b00515a 14446 "View name\n"
fee0f4c6 14447 "Information about Route Server Client\n"
a80beece 14448 NEIGHBOR_ADDR_STR3
fee0f4c6 14449 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14450{
14451 struct bgp *bgp;
14452 struct peer *peer;
14453
14454 /* BGP structure lookup. */
14455 if (argc == 3)
14456 {
14457 bgp = bgp_lookup_by_name (argv[0]);
14458 if (bgp == NULL)
14459 {
14460 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14461 return CMD_WARNING;
14462 }
14463 }
14464 else
14465 {
14466 bgp = bgp_get_default ();
14467 if (bgp == NULL)
14468 {
14469 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14470 return CMD_WARNING;
14471 }
14472 }
14473
14474 if (argc == 3)
856ca177 14475 peer = peer_lookup_in_view (vty, argv[0], argv[1], 0);
fee0f4c6 14476 else
856ca177 14477 peer = peer_lookup_in_view (vty, NULL, argv[0], 0);
fee0f4c6 14478
14479 if (! peer)
14480 return CMD_WARNING;
14481
14482 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14483 {
14484 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14485 VTY_NEWLINE);
14486 return CMD_WARNING;
14487 }
14488
14489 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14490 PEER_FLAG_RSERVER_CLIENT))
14491 {
14492 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14493 VTY_NEWLINE);
14494 return CMD_WARNING;
14495 }
14496
14497 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14498 (argc == 3) ? argv[2] : argv[1],
b05a1c8b 14499 AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, 0);
fee0f4c6 14500}
14501
14502ALIAS (show_bgp_view_rsclient_prefix,
14503 show_bgp_rsclient_prefix_cmd,
a80beece 14504 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
fee0f4c6 14505 SHOW_STR
14506 BGP_STR
14507 "Information about Route Server Client\n"
a80beece 14508 NEIGHBOR_ADDR_STR3
fee0f4c6 14509 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14510
95cbbd2a
ML
14511DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
14512 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
a80beece 14513 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
95cbbd2a
ML
14514 SHOW_STR
14515 BGP_STR
14516 "BGP view\n"
2b00515a 14517 "View name\n"
95cbbd2a
ML
14518 "Address family\n"
14519 "Address Family modifier\n"
14520 "Address Family modifier\n"
14521 "Information about Route Server Client\n"
a80beece 14522 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
14523 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
14524{
14525 struct bgp *bgp;
14526 struct peer *peer;
14527 safi_t safi;
14528
14529 /* BGP structure lookup. */
14530 if (argc == 4)
14531 {
14532 bgp = bgp_lookup_by_name (argv[0]);
14533 if (bgp == NULL)
14534 {
14535 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14536 return CMD_WARNING;
14537 }
14538 }
14539 else
14540 {
14541 bgp = bgp_get_default ();
14542 if (bgp == NULL)
14543 {
14544 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14545 return CMD_WARNING;
14546 }
14547 }
14548
14549 if (argc == 4) {
856ca177 14550 peer = peer_lookup_in_view (vty, argv[0], argv[2], 0);
95cbbd2a
ML
14551 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14552 } else {
856ca177 14553 peer = peer_lookup_in_view (vty, NULL, argv[1], 0);
95cbbd2a
ML
14554 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14555 }
14556
14557 if (! peer)
14558 return CMD_WARNING;
14559
14560 if (! peer->afc[AFI_IP6][safi])
14561 {
14562 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14563 VTY_NEWLINE);
14564 return CMD_WARNING;
14565}
14566
14567 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14568 PEER_FLAG_RSERVER_CLIENT))
14569{
14570 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14571 VTY_NEWLINE);
14572 return CMD_WARNING;
14573 }
14574
14575 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
14576 (argc == 4) ? argv[3] : argv[2],
b05a1c8b 14577 AFI_IP6, safi, NULL, 1, BGP_PATH_ALL, 0);
95cbbd2a
ML
14578}
14579
14580ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
14581 show_bgp_ipv6_safi_rsclient_prefix_cmd,
a80beece 14582 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
95cbbd2a
ML
14583 SHOW_STR
14584 BGP_STR
14585 "Address family\n"
14586 "Address Family modifier\n"
14587 "Address Family modifier\n"
14588 "Information about Route Server Client\n"
a80beece 14589 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
14590 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
14591
718e3744 14592#endif /* HAVE_IPV6 */
6b0655a2 14593
718e3744 14594struct bgp_table *bgp_distance_table;
14595
14596struct bgp_distance
14597{
14598 /* Distance value for the IP source prefix. */
14599 u_char distance;
14600
14601 /* Name of the access-list to be matched. */
14602 char *access_list;
14603};
14604
94f2b392 14605static struct bgp_distance *
66e5cd87 14606bgp_distance_new (void)
718e3744 14607{
393deb9b 14608 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
718e3744 14609}
14610
94f2b392 14611static void
718e3744 14612bgp_distance_free (struct bgp_distance *bdistance)
14613{
14614 XFREE (MTYPE_BGP_DISTANCE, bdistance);
14615}
14616
94f2b392 14617static int
fd79ac91 14618bgp_distance_set (struct vty *vty, const char *distance_str,
14619 const char *ip_str, const char *access_list_str)
718e3744 14620{
14621 int ret;
14622 struct prefix_ipv4 p;
14623 u_char distance;
14624 struct bgp_node *rn;
14625 struct bgp_distance *bdistance;
14626
14627 ret = str2prefix_ipv4 (ip_str, &p);
14628 if (ret == 0)
14629 {
14630 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
14631 return CMD_WARNING;
14632 }
14633
14634 distance = atoi (distance_str);
14635
14636 /* Get BGP distance node. */
14637 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
14638 if (rn->info)
14639 {
14640 bdistance = rn->info;
14641 bgp_unlock_node (rn);
14642 }
14643 else
14644 {
14645 bdistance = bgp_distance_new ();
14646 rn->info = bdistance;
14647 }
14648
14649 /* Set distance value. */
14650 bdistance->distance = distance;
14651
14652 /* Reset access-list configuration. */
14653 if (bdistance->access_list)
14654 {
6e919709 14655 XFREE(MTYPE_AS_LIST, bdistance->access_list);
718e3744 14656 bdistance->access_list = NULL;
14657 }
14658 if (access_list_str)
6e919709 14659 bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str);
718e3744 14660
14661 return CMD_SUCCESS;
14662}
14663
94f2b392 14664static int
fd79ac91 14665bgp_distance_unset (struct vty *vty, const char *distance_str,
14666 const char *ip_str, const char *access_list_str)
718e3744 14667{
14668 int ret;
14669 struct prefix_ipv4 p;
718e3744 14670 struct bgp_node *rn;
14671 struct bgp_distance *bdistance;
14672
14673 ret = str2prefix_ipv4 (ip_str, &p);
14674 if (ret == 0)
14675 {
14676 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
14677 return CMD_WARNING;
14678 }
14679
718e3744 14680 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
14681 if (! rn)
14682 {
14683 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
14684 return CMD_WARNING;
14685 }
14686
14687 bdistance = rn->info;
14688
14689 if (bdistance->access_list)
6e919709 14690 XFREE(MTYPE_AS_LIST, bdistance->access_list);
718e3744 14691 bgp_distance_free (bdistance);
14692
14693 rn->info = NULL;
14694 bgp_unlock_node (rn);
14695 bgp_unlock_node (rn);
14696
14697 return CMD_SUCCESS;
14698}
14699
718e3744 14700/* Apply BGP information to distance method. */
14701u_char
14702bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
14703{
14704 struct bgp_node *rn;
14705 struct prefix_ipv4 q;
14706 struct peer *peer;
14707 struct bgp_distance *bdistance;
14708 struct access_list *alist;
14709 struct bgp_static *bgp_static;
14710
14711 if (! bgp)
14712 return 0;
14713
14714 if (p->family != AF_INET)
14715 return 0;
14716
14717 peer = rinfo->peer;
14718
14719 if (peer->su.sa.sa_family != AF_INET)
14720 return 0;
14721
14722 memset (&q, 0, sizeof (struct prefix_ipv4));
14723 q.family = AF_INET;
14724 q.prefix = peer->su.sin.sin_addr;
14725 q.prefixlen = IPV4_MAX_BITLEN;
14726
14727 /* Check source address. */
14728 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
14729 if (rn)
14730 {
14731 bdistance = rn->info;
14732 bgp_unlock_node (rn);
14733
14734 if (bdistance->access_list)
14735 {
14736 alist = access_list_lookup (AFI_IP, bdistance->access_list);
14737 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
14738 return bdistance->distance;
14739 }
14740 else
14741 return bdistance->distance;
14742 }
14743
14744 /* Backdoor check. */
14745 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
14746 if (rn)
14747 {
14748 bgp_static = rn->info;
14749 bgp_unlock_node (rn);
14750
14751 if (bgp_static->backdoor)
14752 {
14753 if (bgp->distance_local)
14754 return bgp->distance_local;
14755 else
14756 return ZEBRA_IBGP_DISTANCE_DEFAULT;
14757 }
14758 }
14759
6d85b15b 14760 if (peer->sort == BGP_PEER_EBGP)
718e3744 14761 {
14762 if (bgp->distance_ebgp)
14763 return bgp->distance_ebgp;
14764 return ZEBRA_EBGP_DISTANCE_DEFAULT;
14765 }
14766 else
14767 {
14768 if (bgp->distance_ibgp)
14769 return bgp->distance_ibgp;
14770 return ZEBRA_IBGP_DISTANCE_DEFAULT;
14771 }
14772}
14773
14774DEFUN (bgp_distance,
14775 bgp_distance_cmd,
14776 "distance bgp <1-255> <1-255> <1-255>",
14777 "Define an administrative distance\n"
14778 "BGP distance\n"
14779 "Distance for routes external to the AS\n"
14780 "Distance for routes internal to the AS\n"
14781 "Distance for local routes\n")
14782{
14783 struct bgp *bgp;
14784
14785 bgp = vty->index;
14786
14787 bgp->distance_ebgp = atoi (argv[0]);
14788 bgp->distance_ibgp = atoi (argv[1]);
14789 bgp->distance_local = atoi (argv[2]);
14790 return CMD_SUCCESS;
14791}
14792
14793DEFUN (no_bgp_distance,
14794 no_bgp_distance_cmd,
14795 "no distance bgp <1-255> <1-255> <1-255>",
14796 NO_STR
14797 "Define an administrative distance\n"
14798 "BGP distance\n"
14799 "Distance for routes external to the AS\n"
14800 "Distance for routes internal to the AS\n"
14801 "Distance for local routes\n")
14802{
14803 struct bgp *bgp;
14804
14805 bgp = vty->index;
14806
14807 bgp->distance_ebgp= 0;
14808 bgp->distance_ibgp = 0;
14809 bgp->distance_local = 0;
14810 return CMD_SUCCESS;
14811}
14812
14813ALIAS (no_bgp_distance,
14814 no_bgp_distance2_cmd,
14815 "no distance bgp",
14816 NO_STR
14817 "Define an administrative distance\n"
14818 "BGP distance\n")
14819
14820DEFUN (bgp_distance_source,
14821 bgp_distance_source_cmd,
14822 "distance <1-255> A.B.C.D/M",
14823 "Define an administrative distance\n"
14824 "Administrative distance\n"
14825 "IP source prefix\n")
14826{
14827 bgp_distance_set (vty, argv[0], argv[1], NULL);
14828 return CMD_SUCCESS;
14829}
14830
14831DEFUN (no_bgp_distance_source,
14832 no_bgp_distance_source_cmd,
14833 "no distance <1-255> A.B.C.D/M",
14834 NO_STR
14835 "Define an administrative distance\n"
14836 "Administrative distance\n"
14837 "IP source prefix\n")
14838{
14839 bgp_distance_unset (vty, argv[0], argv[1], NULL);
14840 return CMD_SUCCESS;
14841}
14842
14843DEFUN (bgp_distance_source_access_list,
14844 bgp_distance_source_access_list_cmd,
14845 "distance <1-255> A.B.C.D/M WORD",
14846 "Define an administrative distance\n"
14847 "Administrative distance\n"
14848 "IP source prefix\n"
14849 "Access list name\n")
14850{
14851 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
14852 return CMD_SUCCESS;
14853}
14854
14855DEFUN (no_bgp_distance_source_access_list,
14856 no_bgp_distance_source_access_list_cmd,
14857 "no distance <1-255> A.B.C.D/M WORD",
14858 NO_STR
14859 "Define an administrative distance\n"
14860 "Administrative distance\n"
14861 "IP source prefix\n"
14862 "Access list name\n")
14863{
14864 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
14865 return CMD_SUCCESS;
14866}
6b0655a2 14867
718e3744 14868DEFUN (bgp_damp_set,
14869 bgp_damp_set_cmd,
14870 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14871 "BGP Specific commands\n"
14872 "Enable route-flap dampening\n"
14873 "Half-life time for the penalty\n"
14874 "Value to start reusing a route\n"
14875 "Value to start suppressing a route\n"
14876 "Maximum duration to suppress a stable route\n")
14877{
14878 struct bgp *bgp;
14879 int half = DEFAULT_HALF_LIFE * 60;
14880 int reuse = DEFAULT_REUSE;
14881 int suppress = DEFAULT_SUPPRESS;
14882 int max = 4 * half;
14883
14884 if (argc == 4)
14885 {
14886 half = atoi (argv[0]) * 60;
14887 reuse = atoi (argv[1]);
14888 suppress = atoi (argv[2]);
14889 max = atoi (argv[3]) * 60;
14890 }
14891 else if (argc == 1)
14892 {
14893 half = atoi (argv[0]) * 60;
14894 max = 4 * half;
14895 }
14896
14897 bgp = vty->index;
14898 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
14899 half, reuse, suppress, max);
14900}
14901
14902ALIAS (bgp_damp_set,
14903 bgp_damp_set2_cmd,
14904 "bgp dampening <1-45>",
14905 "BGP Specific commands\n"
14906 "Enable route-flap dampening\n"
14907 "Half-life time for the penalty\n")
14908
14909ALIAS (bgp_damp_set,
14910 bgp_damp_set3_cmd,
14911 "bgp dampening",
14912 "BGP Specific commands\n"
14913 "Enable route-flap dampening\n")
14914
14915DEFUN (bgp_damp_unset,
14916 bgp_damp_unset_cmd,
14917 "no bgp dampening",
14918 NO_STR
14919 "BGP Specific commands\n"
14920 "Enable route-flap dampening\n")
14921{
14922 struct bgp *bgp;
14923
14924 bgp = vty->index;
14925 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
14926}
14927
14928ALIAS (bgp_damp_unset,
14929 bgp_damp_unset2_cmd,
14930 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14931 NO_STR
14932 "BGP Specific commands\n"
14933 "Enable route-flap dampening\n"
14934 "Half-life time for the penalty\n"
14935 "Value to start reusing a route\n"
14936 "Value to start suppressing a route\n"
14937 "Maximum duration to suppress a stable route\n")
14938
14939DEFUN (show_ip_bgp_dampened_paths,
14940 show_ip_bgp_dampened_paths_cmd,
14941 "show ip bgp dampened-paths",
14942 SHOW_STR
14943 IP_STR
14944 BGP_STR
14945 "Display paths suppressed due to dampening\n")
14946{
5a646650 14947 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
b05a1c8b 14948 NULL, 0);
718e3744 14949}
14950
14951DEFUN (show_ip_bgp_flap_statistics,
14952 show_ip_bgp_flap_statistics_cmd,
14953 "show ip bgp flap-statistics",
14954 SHOW_STR
14955 IP_STR
14956 BGP_STR
14957 "Display flap statistics of routes\n")
14958{
5a646650 14959 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 14960 bgp_show_type_flap_statistics, NULL, 0);
718e3744 14961}
6b0655a2 14962
718e3744 14963/* Display specified route of BGP table. */
94f2b392 14964static int
fd79ac91 14965bgp_clear_damp_route (struct vty *vty, const char *view_name,
14966 const char *ip_str, afi_t afi, safi_t safi,
14967 struct prefix_rd *prd, int prefix_check)
718e3744 14968{
14969 int ret;
14970 struct prefix match;
14971 struct bgp_node *rn;
14972 struct bgp_node *rm;
14973 struct bgp_info *ri;
14974 struct bgp_info *ri_temp;
14975 struct bgp *bgp;
14976 struct bgp_table *table;
14977
14978 /* BGP structure lookup. */
14979 if (view_name)
14980 {
14981 bgp = bgp_lookup_by_name (view_name);
14982 if (bgp == NULL)
14983 {
14984 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
14985 return CMD_WARNING;
14986 }
14987 }
14988 else
14989 {
14990 bgp = bgp_get_default ();
14991 if (bgp == NULL)
14992 {
14993 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
14994 return CMD_WARNING;
14995 }
14996 }
14997
14998 /* Check IP address argument. */
14999 ret = str2prefix (ip_str, &match);
15000 if (! ret)
15001 {
15002 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
15003 return CMD_WARNING;
15004 }
15005
15006 match.family = afi2family (afi);
15007
15008 if (safi == SAFI_MPLS_VPN)
15009 {
15010 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
15011 {
15012 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
15013 continue;
15014
15015 if ((table = rn->info) != NULL)
15016 if ((rm = bgp_node_match (table, &match)) != NULL)
6c88b44d
CC
15017 {
15018 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
15019 {
15020 ri = rm->info;
15021 while (ri)
15022 {
15023 if (ri->extra && ri->extra->damp_info)
15024 {
15025 ri_temp = ri->next;
15026 bgp_damp_info_free (ri->extra->damp_info, 1);
15027 ri = ri_temp;
15028 }
15029 else
15030 ri = ri->next;
15031 }
15032 }
15033
15034 bgp_unlock_node (rm);
15035 }
718e3744 15036 }
15037 }
15038 else
15039 {
15040 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
6c88b44d
CC
15041 {
15042 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
15043 {
15044 ri = rn->info;
15045 while (ri)
15046 {
15047 if (ri->extra && ri->extra->damp_info)
15048 {
15049 ri_temp = ri->next;
15050 bgp_damp_info_free (ri->extra->damp_info, 1);
15051 ri = ri_temp;
15052 }
15053 else
15054 ri = ri->next;
15055 }
15056 }
15057
15058 bgp_unlock_node (rn);
15059 }
718e3744 15060 }
15061
15062 return CMD_SUCCESS;
15063}
15064
15065DEFUN (clear_ip_bgp_dampening,
15066 clear_ip_bgp_dampening_cmd,
15067 "clear ip bgp dampening",
15068 CLEAR_STR
15069 IP_STR
15070 BGP_STR
15071 "Clear route flap dampening information\n")
15072{
15073 bgp_damp_info_clean ();
15074 return CMD_SUCCESS;
15075}
15076
15077DEFUN (clear_ip_bgp_dampening_prefix,
15078 clear_ip_bgp_dampening_prefix_cmd,
15079 "clear ip bgp dampening A.B.C.D/M",
15080 CLEAR_STR
15081 IP_STR
15082 BGP_STR
15083 "Clear route flap dampening information\n"
15084 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
15085{
15086 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15087 SAFI_UNICAST, NULL, 1);
15088}
15089
15090DEFUN (clear_ip_bgp_dampening_address,
15091 clear_ip_bgp_dampening_address_cmd,
15092 "clear ip bgp dampening A.B.C.D",
15093 CLEAR_STR
15094 IP_STR
15095 BGP_STR
15096 "Clear route flap dampening information\n"
15097 "Network to clear damping information\n")
15098{
15099 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15100 SAFI_UNICAST, NULL, 0);
15101}
15102
15103DEFUN (clear_ip_bgp_dampening_address_mask,
15104 clear_ip_bgp_dampening_address_mask_cmd,
15105 "clear ip bgp dampening A.B.C.D A.B.C.D",
15106 CLEAR_STR
15107 IP_STR
15108 BGP_STR
15109 "Clear route flap dampening information\n"
15110 "Network to clear damping information\n"
15111 "Network mask\n")
15112{
15113 int ret;
15114 char prefix_str[BUFSIZ];
15115
15116 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
15117 if (! ret)
15118 {
15119 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
15120 return CMD_WARNING;
15121 }
15122
15123 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
15124 SAFI_UNICAST, NULL, 0);
15125}
6b0655a2 15126
94f2b392 15127static int
718e3744 15128bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
15129 afi_t afi, safi_t safi, int *write)
15130{
15131 struct bgp_node *prn;
15132 struct bgp_node *rn;
15133 struct bgp_table *table;
15134 struct prefix *p;
15135 struct prefix_rd *prd;
15136 struct bgp_static *bgp_static;
15137 u_int32_t label;
15138 char buf[SU_ADDRSTRLEN];
15139 char rdbuf[RD_ADDRSTRLEN];
15140
15141 /* Network configuration. */
15142 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
15143 if ((table = prn->info) != NULL)
15144 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
15145 if ((bgp_static = rn->info) != NULL)
15146 {
15147 p = &rn->p;
15148 prd = (struct prefix_rd *) &prn->p;
15149
15150 /* "address-family" display. */
15151 bgp_config_write_family_header (vty, afi, safi, write);
15152
15153 /* "network" configuration display. */
15154 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
15155 label = decode_label (bgp_static->tag);
15156
0b960b4d 15157 vty_out (vty, " network %s/%d rd %s tag %d",
718e3744 15158 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15159 p->prefixlen,
15160 rdbuf, label);
15161 vty_out (vty, "%s", VTY_NEWLINE);
15162 }
15163 return 0;
15164}
15165
15166/* Configuration of static route announcement and aggregate
15167 information. */
15168int
15169bgp_config_write_network (struct vty *vty, struct bgp *bgp,
15170 afi_t afi, safi_t safi, int *write)
15171{
15172 struct bgp_node *rn;
15173 struct prefix *p;
15174 struct bgp_static *bgp_static;
15175 struct bgp_aggregate *bgp_aggregate;
15176 char buf[SU_ADDRSTRLEN];
15177
15178 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
15179 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
15180
15181 /* Network configuration. */
15182 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
15183 if ((bgp_static = rn->info) != NULL)
15184 {
15185 p = &rn->p;
15186
15187 /* "address-family" display. */
15188 bgp_config_write_family_header (vty, afi, safi, write);
15189
15190 /* "network" configuration display. */
15191 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
15192 {
15193 u_int32_t destination;
15194 struct in_addr netmask;
15195
15196 destination = ntohl (p->u.prefix4.s_addr);
15197 masklen2ip (p->prefixlen, &netmask);
0b960b4d 15198 vty_out (vty, " network %s",
718e3744 15199 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
15200
15201 if ((IN_CLASSC (destination) && p->prefixlen == 24)
15202 || (IN_CLASSB (destination) && p->prefixlen == 16)
15203 || (IN_CLASSA (destination) && p->prefixlen == 8)
15204 || p->u.prefix4.s_addr == 0)
15205 {
15206 /* Natural mask is not display. */
15207 }
15208 else
15209 vty_out (vty, " mask %s", inet_ntoa (netmask));
15210 }
15211 else
15212 {
0b960b4d 15213 vty_out (vty, " network %s/%d",
718e3744 15214 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15215 p->prefixlen);
15216 }
15217
15218 if (bgp_static->rmap.name)
15219 vty_out (vty, " route-map %s", bgp_static->rmap.name);
41367172
PJ
15220 else
15221 {
15222 if (bgp_static->backdoor)
15223 vty_out (vty, " backdoor");
41367172 15224 }
718e3744 15225
15226 vty_out (vty, "%s", VTY_NEWLINE);
15227 }
15228
15229 /* Aggregate-address configuration. */
15230 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
15231 if ((bgp_aggregate = rn->info) != NULL)
15232 {
15233 p = &rn->p;
15234
15235 /* "address-family" display. */
15236 bgp_config_write_family_header (vty, afi, safi, write);
15237
15238 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
15239 {
15240 struct in_addr netmask;
15241
15242 masklen2ip (p->prefixlen, &netmask);
0b960b4d 15243 vty_out (vty, " aggregate-address %s %s",
718e3744 15244 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15245 inet_ntoa (netmask));
15246 }
15247 else
15248 {
0b960b4d 15249 vty_out (vty, " aggregate-address %s/%d",
718e3744 15250 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15251 p->prefixlen);
15252 }
15253
15254 if (bgp_aggregate->as_set)
15255 vty_out (vty, " as-set");
15256
15257 if (bgp_aggregate->summary_only)
15258 vty_out (vty, " summary-only");
15259
15260 vty_out (vty, "%s", VTY_NEWLINE);
15261 }
15262
15263 return 0;
15264}
15265
15266int
15267bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
15268{
15269 struct bgp_node *rn;
15270 struct bgp_distance *bdistance;
15271
15272 /* Distance configuration. */
15273 if (bgp->distance_ebgp
15274 && bgp->distance_ibgp
15275 && bgp->distance_local
15276 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
15277 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
15278 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
15279 vty_out (vty, " distance bgp %d %d %d%s",
15280 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
15281 VTY_NEWLINE);
15282
15283 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
15284 if ((bdistance = rn->info) != NULL)
15285 {
15286 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
15287 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
15288 bdistance->access_list ? bdistance->access_list : "",
15289 VTY_NEWLINE);
15290 }
15291
15292 return 0;
15293}
15294
15295/* Allocate routing table structure and install commands. */
15296void
66e5cd87 15297bgp_route_init (void)
718e3744 15298{
15299 /* Init BGP distance table. */
64e580a7 15300 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
718e3744 15301
15302 /* IPv4 BGP commands. */
73ac8160 15303 install_element (BGP_NODE, &bgp_table_map_cmd);
718e3744 15304 install_element (BGP_NODE, &bgp_network_cmd);
15305 install_element (BGP_NODE, &bgp_network_mask_cmd);
15306 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
15307 install_element (BGP_NODE, &bgp_network_route_map_cmd);
15308 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
15309 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
15310 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
15311 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
15312 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
73ac8160 15313 install_element (BGP_NODE, &no_bgp_table_map_cmd);
718e3744 15314 install_element (BGP_NODE, &no_bgp_network_cmd);
15315 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
15316 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
15317 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
15318 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
15319 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
15320 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
15321 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
15322 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
15323
15324 install_element (BGP_NODE, &aggregate_address_cmd);
15325 install_element (BGP_NODE, &aggregate_address_mask_cmd);
15326 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
15327 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
15328 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
15329 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
15330 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
15331 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
15332 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
15333 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
15334 install_element (BGP_NODE, &no_aggregate_address_cmd);
15335 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
15336 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
15337 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
15338 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
15339 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
15340 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
15341 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
15342 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
15343 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
15344
15345 /* IPv4 unicast configuration. */
73ac8160 15346 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
718e3744 15347 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
15348 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
15349 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
15350 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
15351 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
15352 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 15353 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
c8f3fe30 15354 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
718e3744 15355 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
15356 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
15357 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
15358 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
15359 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
c8f3fe30 15360
718e3744 15361 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
15362 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
15363 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
15364 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
15365 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
15366 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
15367 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
15368 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
15369 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
15370 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
15371 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
15372 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
15373 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
15374 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
15375 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
15376 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
15377 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
15378 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
15379 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
15380 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
15381
15382 /* IPv4 multicast configuration. */
73ac8160 15383 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
718e3744 15384 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
15385 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
15386 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
15387 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
15388 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
15389 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 15390 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
718e3744 15391 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
15392 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
15393 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
15394 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
15395 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
15396 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
15397 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
15398 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
15399 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
15400 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
15401 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
15402 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
15403 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
15404 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
15405 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
15406 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
15407 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
15408 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
15409 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
15410 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
15411 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
15412 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
15413 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
15414 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
15415 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
15416 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
15417
15418 install_element (VIEW_NODE, &show_ip_bgp_cmd);
15419 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 15420 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
718e3744 15421 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
15422 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
15423 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 15424 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 15425 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 15426 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
15427 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
15428 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
15429 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
15430 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
15431 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 15432 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 15433 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
718e3744 15434 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
15435 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
15436 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
15437 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
15438 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
15439 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
15440 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
15441 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
15442 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
15443 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
15444 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
15445 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
15446 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
15447 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
15448 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
15449 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
15450 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
15451 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
15452 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
15453 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
15454 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
15455 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
15456 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
15457 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
15458 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
15459 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
15460 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
15461 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
15462 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
15463 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
718e3744 15464 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
15465 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
15466 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
15467 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
15468 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
15469 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
15470 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
15471 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
15472 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
15473 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
15474 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
15475 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
15476 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
15477 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
15478 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
0b16f239 15479 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
718e3744 15480 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
0b16f239 15481 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
718e3744 15482 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
0b16f239 15483 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
718e3744 15484 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
0b16f239 15485 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
95cbbd2a 15486 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 15487 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
15488 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
15489 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
15490 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
15491 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
15492 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
15493 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
15494 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
15495 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
15496 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
15497 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
15498 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
15499 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
15500 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
15501 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
15502 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
fee0f4c6 15503 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
95cbbd2a 15504 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
fee0f4c6 15505 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 15506 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
fee0f4c6 15507 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 15508 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
2a71e9ce
TP
15509 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
15510 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
fee0f4c6 15511 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
95cbbd2a 15512 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
fee0f4c6 15513 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 15514 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
fee0f4c6 15515 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 15516 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
62687ff1
PJ
15517
15518 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
15519 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
15520 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
15521 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
62687ff1 15522 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 15523 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
62687ff1
PJ
15524 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
15525 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
15526 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
15527 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
15528 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 15529 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 15530 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
62687ff1
PJ
15531 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
15532 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
15533 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
15534 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
15535 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
15536 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
15537 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
15538 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
15539 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
15540 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
15541 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
15542 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
15543 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
15544 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
15545 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
15546 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
15547 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
62687ff1
PJ
15548 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
15549 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
15550 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
15551 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
15552 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
15553 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
15554 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
15555 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
15556 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 15557 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
62687ff1 15558 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 15559 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
62687ff1 15560 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 15561 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
62687ff1 15562 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 15563 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
718e3744 15564
15565 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
15566 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 15567 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
718e3744 15568 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
15569 install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd);
15570 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 15571 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 15572 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 15573 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
15574 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
15575 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
15576 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
15577 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
15578 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 15579 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 15580 install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd);
718e3744 15581 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
15582 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
15583 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
15584 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
15585 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
15586 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
15587 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
15588 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
15589 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
15590 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
15591 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
15592 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
15593 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
15594 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
15595 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
15596 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
15597 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
15598 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
15599 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
15600 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
15601 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
15602 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
15603 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
15604 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
15605 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
15606 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
15607 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
15608 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
15609 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
15610 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
718e3744 15611 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
15612 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
15613 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
15614 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
15615 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
15616 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
15617 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
15618 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
15619 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
15620 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
15621 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
15622 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
15623 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
15624 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
15625 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
0b16f239 15626 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
718e3744 15627 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
0b16f239 15628 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
718e3744 15629 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
0b16f239 15630 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
718e3744 15631 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
0b16f239 15632 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
95cbbd2a 15633 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 15634 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
15635 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
15636 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
15637 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
15638 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
15639 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
15640 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
15641 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
15642 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
15643 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
15644 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
15645 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
15646 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
15647 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
15648 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
15649 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
fee0f4c6 15650 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
95cbbd2a 15651 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
fee0f4c6 15652 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 15653 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
fee0f4c6 15654 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 15655 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
2a71e9ce
TP
15656 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
15657 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
fee0f4c6 15658 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
95cbbd2a 15659 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
fee0f4c6 15660 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 15661 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
fee0f4c6 15662 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 15663 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
718e3744 15664
15665 /* BGP dampening clear commands */
15666 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
15667 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
15668 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
15669 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
15670
ff7924f6
PJ
15671 /* prefix count */
15672 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
15673 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
15674 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
718e3744 15675#ifdef HAVE_IPV6
ff7924f6
PJ
15676 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
15677
718e3744 15678 /* New config IPv6 BGP commands. */
73ac8160 15679 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
718e3744 15680 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
15681 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
73ac8160 15682 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
718e3744 15683 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
15684 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
15685
15686 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
15687 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
15688 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
15689 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
73bfe0bd
B
15690
15691 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
15692 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
718e3744 15693
15694 /* Old config IPv6 BGP commands. */
15695 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
15696 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
15697
15698 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
15699 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
15700 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
15701 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
15702
15703 install_element (VIEW_NODE, &show_bgp_cmd);
15704 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 15705 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 15706 install_element (VIEW_NODE, &show_bgp_route_cmd);
15707 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 15708 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
15709 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
15710 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
15711 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 15712 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
15713 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 15714 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c
DS
15715 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
15716 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
15717 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 15718 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
15719 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
15720 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
15721 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
15722 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
15723 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
15724 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
15725 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
15726 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
15727 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
15728 install_element (VIEW_NODE, &show_bgp_community_cmd);
15729 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
15730 install_element (VIEW_NODE, &show_bgp_community2_cmd);
15731 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
15732 install_element (VIEW_NODE, &show_bgp_community3_cmd);
15733 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
15734 install_element (VIEW_NODE, &show_bgp_community4_cmd);
15735 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
15736 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
15737 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
15738 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
15739 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
15740 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
15741 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
15742 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
15743 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
15744 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
15745 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
15746 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
15747 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
15748 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
15749 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
15750 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
15751 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
15752 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
15753 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
15754 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
15755 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
15756 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
15757 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 15758 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
15759 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
15760 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
15761 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
fee0f4c6 15762 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
95cbbd2a 15763 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
fee0f4c6 15764 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 15765 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
fee0f4c6 15766 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 15767 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
bb46e94f 15768 install_element (VIEW_NODE, &show_bgp_view_cmd);
15769 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
15770 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
15771 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
15772 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
15773 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
15774 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
15775 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
15776 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
15777 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
15778 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
15779 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
15780 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
15781 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
15782 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
15783 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
15784 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
15785 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
fee0f4c6 15786 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
95cbbd2a 15787 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
fee0f4c6 15788 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 15789 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
fee0f4c6 15790 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 15791 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
62687ff1
PJ
15792
15793 /* Restricted:
15794 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
15795 */
15796 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
15797 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 15798 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
15799 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
15800 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
15801 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
62687ff1
PJ
15802 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
15803 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 15804 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c
DS
15805 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
15806 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
15807 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
62687ff1
PJ
15808 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
15809 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
15810 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
15811 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
15812 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
15813 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
15814 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
15815 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
15816 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
15817 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
15818 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
15819 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
15820 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
15821 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
15822 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
15823 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
15824 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 15825 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
62687ff1 15826 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 15827 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
62687ff1
PJ
15828 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
15829 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
15830 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
15831 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
15832 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
15833 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
15834 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 15835 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
62687ff1 15836 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 15837 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
718e3744 15838
15839 install_element (ENABLE_NODE, &show_bgp_cmd);
15840 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 15841 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 15842 install_element (ENABLE_NODE, &show_bgp_route_cmd);
15843 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 15844 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
15845 install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd);
15846 install_element (ENABLE_NODE, &show_bgp_ipv6_route_pathtype_cmd);
15847 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 15848 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
4092b06c
DS
15849 install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd);
15850 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
15851 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 15852 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 15853 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
718e3744 15854 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
15855 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
15856 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
15857 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
15858 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
15859 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
15860 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
15861 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
15862 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
15863 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
15864 install_element (ENABLE_NODE, &show_bgp_community_cmd);
15865 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
15866 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
15867 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
15868 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
15869 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
15870 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
15871 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
15872 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
15873 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
15874 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
15875 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
15876 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
15877 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
15878 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
15879 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
15880 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
15881 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
15882 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
15883 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
15884 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
15885 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
15886 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
15887 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
15888 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
15889 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
15890 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
15891 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
15892 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
15893 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 15894 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
15895 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
15896 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
15897 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
fee0f4c6 15898 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
95cbbd2a 15899 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
fee0f4c6 15900 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 15901 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
fee0f4c6 15902 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 15903 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
bb46e94f 15904 install_element (ENABLE_NODE, &show_bgp_view_cmd);
15905 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
15906 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
15907 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
15908 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
15909 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
15910 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
15911 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
15912 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
15913 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
15914 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
15915 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
15916 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
15917 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
15918 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
15919 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
15920 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
15921 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
fee0f4c6 15922 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
95cbbd2a 15923 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
fee0f4c6 15924 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 15925 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
fee0f4c6 15926 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 15927 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
2815e61f
PJ
15928
15929 /* Statistics */
15930 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
15931 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
15932 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
15933 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
15934
718e3744 15935 /* old command */
15936 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
15937 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
15938 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
15939 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
15940 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
15941 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
15942 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
15943 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
15944 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
15945 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
15946 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
15947 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
15948 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
15949 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
15950 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
15951 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
15952 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15953 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15954 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
15955 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
15956 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
15957 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
15958 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15959 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
15960 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
15961 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
15962 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
15963 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
15964 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
15965 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
15966 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
15967 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
15968 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
15969 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
15970 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15971 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
bb46e94f 15972
718e3744 15973 /* old command */
15974 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
15975 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
15976 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
15977 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
15978 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
15979 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
15980 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
15981 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
15982 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
15983 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
15984 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
15985 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
15986 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
15987 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
15988 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
15989 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
15990 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15991 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15992 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
15993 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
15994 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
15995 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
15996 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15997 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
15998 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
15999 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
16000 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
16001 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
16002 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
16003 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
16004 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
16005 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
16006 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
16007 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
16008 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
16009 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
16010
16011 /* old command */
16012 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
16013 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
16014 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
16015 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
16016
16017 /* old command */
16018 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
16019 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
16020 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
16021 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
16022
16023 /* old command */
16024 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
16025 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
16026 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
16027 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
16028#endif /* HAVE_IPV6 */
16029
16030 install_element (BGP_NODE, &bgp_distance_cmd);
16031 install_element (BGP_NODE, &no_bgp_distance_cmd);
16032 install_element (BGP_NODE, &no_bgp_distance2_cmd);
16033 install_element (BGP_NODE, &bgp_distance_source_cmd);
16034 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
16035 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
16036 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
16037
16038 install_element (BGP_NODE, &bgp_damp_set_cmd);
16039 install_element (BGP_NODE, &bgp_damp_set2_cmd);
16040 install_element (BGP_NODE, &bgp_damp_set3_cmd);
16041 install_element (BGP_NODE, &bgp_damp_unset_cmd);
16042 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
16043 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
16044 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
16045 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
16046 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
16047 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
c8f3fe30
PJ
16048
16049 /* Deprecated AS-Pathlimit commands */
16050 install_element (BGP_NODE, &bgp_network_ttl_cmd);
16051 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
16052 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
16053 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
16054 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16055 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16056
16057 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
16058 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
16059 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16060 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
16061 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16062 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16063
16064 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
16065 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
16066 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
16067 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
16068 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16069 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16070
16071 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
16072 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
16073 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16074 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
16075 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16076 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16077
16078 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
16079 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
16080 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
16081 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
16082 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16083 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16084
16085 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
16086 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
16087 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16088 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
16089 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16090 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
3bde17f1
PJ
16091
16092#ifdef HAVE_IPV6
c8f3fe30
PJ
16093 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
16094 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
3bde17f1 16095#endif
718e3744 16096}
228da428
CC
16097
16098void
16099bgp_route_finish (void)
16100{
16101 bgp_table_unlock (bgp_distance_table);
16102 bgp_distance_table = NULL;
16103}