]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_route.c
If a route-map is used on a neighbor default-originate statement we need to dynamical...
[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>
b05a1c8b 22#include <json/json.h>
718e3744 23
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"
718e3744 39
40#include "bgpd/bgpd.h"
41#include "bgpd/bgp_table.h"
42#include "bgpd/bgp_route.h"
43#include "bgpd/bgp_attr.h"
44#include "bgpd/bgp_debug.h"
45#include "bgpd/bgp_aspath.h"
46#include "bgpd/bgp_regex.h"
47#include "bgpd/bgp_community.h"
48#include "bgpd/bgp_ecommunity.h"
49#include "bgpd/bgp_clist.h"
50#include "bgpd/bgp_packet.h"
51#include "bgpd/bgp_filter.h"
52#include "bgpd/bgp_fsm.h"
53#include "bgpd/bgp_mplsvpn.h"
54#include "bgpd/bgp_nexthop.h"
55#include "bgpd/bgp_damp.h"
56#include "bgpd/bgp_advertise.h"
57#include "bgpd/bgp_zebra.h"
0a486e5f 58#include "bgpd/bgp_vty.h"
96450faf 59#include "bgpd/bgp_mpath.h"
fc9a856f 60#include "bgpd/bgp_nht.h"
3f9c7369 61#include "bgpd/bgp_updgrp.h"
718e3744 62
63/* Extern from bgp_dump.c */
dde72586
SH
64extern const char *bgp_origin_str[];
65extern const char *bgp_origin_long_str[];
6b0655a2 66
94f2b392 67static struct bgp_node *
fee0f4c6 68bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
718e3744 69 struct prefix_rd *prd)
70{
71 struct bgp_node *rn;
72 struct bgp_node *prn = NULL;
da5b30f6
PJ
73
74 assert (table);
75 if (!table)
76 return NULL;
77
718e3744 78 if (safi == SAFI_MPLS_VPN)
79 {
fee0f4c6 80 prn = bgp_node_get (table, (struct prefix *) prd);
718e3744 81
82 if (prn->info == NULL)
64e580a7 83 prn->info = bgp_table_init (afi, safi);
718e3744 84 else
85 bgp_unlock_node (prn);
86 table = prn->info;
87 }
718e3744 88
89 rn = bgp_node_get (table, p);
90
91 if (safi == SAFI_MPLS_VPN)
92 rn->prn = prn;
93
94 return rn;
95}
6b0655a2 96
fb982c25
PJ
97/* Allocate bgp_info_extra */
98static struct bgp_info_extra *
99bgp_info_extra_new (void)
100{
101 struct bgp_info_extra *new;
102 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
103 return new;
104}
105
106static void
107bgp_info_extra_free (struct bgp_info_extra **extra)
108{
109 if (extra && *extra)
110 {
111 if ((*extra)->damp_info)
112 bgp_damp_info_free ((*extra)->damp_info, 0);
113
114 (*extra)->damp_info = NULL;
115
116 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
117
118 *extra = NULL;
119 }
120}
121
122/* Get bgp_info extra information for the given bgp_info, lazy allocated
123 * if required.
124 */
125struct bgp_info_extra *
126bgp_info_extra_get (struct bgp_info *ri)
127{
128 if (!ri->extra)
129 ri->extra = bgp_info_extra_new();
130 return ri->extra;
131}
132
718e3744 133/* Free bgp route information. */
200df115 134static void
718e3744 135bgp_info_free (struct bgp_info *binfo)
136{
137 if (binfo->attr)
f6f434b2 138 bgp_attr_unintern (&binfo->attr);
fb018d25
DS
139
140 bgp_unlink_nexthop(binfo);
fb982c25 141 bgp_info_extra_free (&binfo->extra);
de8d5dff 142 bgp_info_mpath_free (&binfo->mpath);
718e3744 143
200df115 144 peer_unlock (binfo->peer); /* bgp_info peer reference */
145
718e3744 146 XFREE (MTYPE_BGP_ROUTE, binfo);
147}
148
200df115 149struct bgp_info *
150bgp_info_lock (struct bgp_info *binfo)
151{
152 binfo->lock++;
153 return binfo;
154}
155
156struct bgp_info *
157bgp_info_unlock (struct bgp_info *binfo)
158{
159 assert (binfo && binfo->lock > 0);
160 binfo->lock--;
161
162 if (binfo->lock == 0)
163 {
164#if 0
165 zlog_debug ("%s: unlocked and freeing", __func__);
166 zlog_backtrace (LOG_DEBUG);
167#endif
168 bgp_info_free (binfo);
169 return NULL;
170 }
171
172#if 0
173 if (binfo->lock == 1)
174 {
175 zlog_debug ("%s: unlocked to 1", __func__);
176 zlog_backtrace (LOG_DEBUG);
177 }
178#endif
179
180 return binfo;
181}
182
718e3744 183void
184bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
185{
186 struct bgp_info *top;
187
188 top = rn->info;
200df115 189
718e3744 190 ri->next = rn->info;
191 ri->prev = NULL;
192 if (top)
193 top->prev = ri;
194 rn->info = ri;
200df115 195
196 bgp_info_lock (ri);
197 bgp_lock_node (rn);
198 peer_lock (ri->peer); /* bgp_info peer reference */
718e3744 199}
200
b40d939b 201/* Do the actual removal of info from RIB, for use by bgp_process
202 completion callback *only* */
203static void
204bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
718e3744 205{
206 if (ri->next)
207 ri->next->prev = ri->prev;
208 if (ri->prev)
209 ri->prev->next = ri->next;
210 else
211 rn->info = ri->next;
200df115 212
de8d5dff 213 bgp_info_mpath_dequeue (ri);
200df115 214 bgp_info_unlock (ri);
215 bgp_unlock_node (rn);
718e3744 216}
217
b40d939b 218void
219bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
220{
1a392d46
PJ
221 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
222 /* set of previous already took care of pcount */
b40d939b 223 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
224}
225
8d45210e
AS
226/* undo the effects of a previous call to bgp_info_delete; typically
227 called when a route is deleted and then quickly re-added before the
228 deletion has been processed */
229static void
230bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
231{
232 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
233 /* unset of previous already took care of pcount */
234 SET_FLAG (ri->flags, BGP_INFO_VALID);
235}
236
1a392d46
PJ
237/* Adjust pcount as required */
238static void
239bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
240{
67174041
AS
241 struct bgp_table *table;
242
243 assert (rn && bgp_node_table (rn));
6f58544d
PJ
244 assert (ri && ri->peer && ri->peer->bgp);
245
67174041
AS
246 table = bgp_node_table (rn);
247
1a392d46 248 /* Ignore 'pcount' for RS-client tables */
67174041 249 if (table->type != BGP_TABLE_MAIN
1a392d46
PJ
250 || ri->peer == ri->peer->bgp->peer_self)
251 return;
252
80e0ad24 253 if (!BGP_INFO_COUNTABLE (ri)
1a392d46
PJ
254 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
255 {
256
257 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
258
259 /* slight hack, but more robust against errors. */
67174041
AS
260 if (ri->peer->pcount[table->afi][table->safi])
261 ri->peer->pcount[table->afi][table->safi]--;
1a392d46
PJ
262 else
263 {
264 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
265 __func__, ri->peer->host);
266 zlog_backtrace (LOG_WARNING);
267 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
268 }
269 }
80e0ad24 270 else if (BGP_INFO_COUNTABLE (ri)
1a392d46
PJ
271 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
272 {
273 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
67174041 274 ri->peer->pcount[table->afi][table->safi]++;
1a392d46
PJ
275 }
276}
277
278
279/* Set/unset bgp_info flags, adjusting any other state as needed.
280 * This is here primarily to keep prefix-count in check.
281 */
282void
283bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
284{
285 SET_FLAG (ri->flags, flag);
286
80e0ad24
DS
287 /* early bath if we know it's not a flag that changes countability state */
288 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
1a392d46
PJ
289 return;
290
291 bgp_pcount_adjust (rn, ri);
292}
293
294void
295bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
296{
297 UNSET_FLAG (ri->flags, flag);
298
80e0ad24
DS
299 /* early bath if we know it's not a flag that changes countability state */
300 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
1a392d46
PJ
301 return;
302
303 bgp_pcount_adjust (rn, ri);
304}
305
718e3744 306/* Get MED value. If MED value is missing and "bgp bestpath
307 missing-as-worst" is specified, treat it as the worst value. */
94f2b392 308static u_int32_t
718e3744 309bgp_med_value (struct attr *attr, struct bgp *bgp)
310{
311 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
312 return attr->med;
313 else
314 {
315 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
3b424979 316 return BGP_MED_MAX;
718e3744 317 else
318 return 0;
319 }
320}
321
9fbdd100 322/* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1. */
94f2b392 323static int
96450faf 324bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
9fbdd100
DS
325 int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg, int debug,
326 char *pfx_buf)
718e3744 327{
8ff56318
JBD
328 struct attr *newattr, *existattr;
329 struct attr_extra *newattre, *existattre;
330 bgp_peer_sort_t new_sort;
331 bgp_peer_sort_t exist_sort;
718e3744 332 u_int32_t new_pref;
333 u_int32_t exist_pref;
334 u_int32_t new_med;
335 u_int32_t exist_med;
8ff56318
JBD
336 u_int32_t new_weight;
337 u_int32_t exist_weight;
338 uint32_t newm, existm;
718e3744 339 struct in_addr new_id;
340 struct in_addr exist_id;
341 int new_cluster;
342 int exist_cluster;
8ff56318
JBD
343 int internal_as_route;
344 int confed_as_route;
718e3744 345 int ret;
96450faf
JB
346
347 *paths_eq = 0;
718e3744 348
349 /* 0. Null check. */
350 if (new == NULL)
9fbdd100
DS
351 {
352 if (debug)
353 zlog_debug("%s: new is NULL", pfx_buf);
354 return 0;
355 }
356
718e3744 357 if (exist == NULL)
9fbdd100
DS
358 {
359 if (debug)
360 zlog_debug("%s: path %s is the initial bestpath",
361 pfx_buf, new->peer->host);
362 return 1;
363 }
718e3744 364
8ff56318
JBD
365 newattr = new->attr;
366 existattr = exist->attr;
367 newattre = newattr->extra;
368 existattre = existattr->extra;
369
718e3744 370 /* 1. Weight check. */
8ff56318
JBD
371 new_weight = exist_weight = 0;
372
373 if (newattre)
374 new_weight = newattre->weight;
375 if (existattre)
376 exist_weight = existattre->weight;
377
fb982c25 378 if (new_weight > exist_weight)
9fbdd100
DS
379 {
380 if (debug)
381 zlog_debug("%s: path %s wins over path %s due to weight %d > %d",
382 pfx_buf, new->peer->host, exist->peer->host, new_weight,
383 exist_weight);
384 return 1;
385 }
386
fb982c25 387 if (new_weight < exist_weight)
9fbdd100
DS
388 {
389 if (debug)
390 zlog_debug("%s: path %s loses to path %s due to weight %d < %d",
391 pfx_buf, new->peer->host, exist->peer->host, new_weight,
392 exist_weight);
393 return 0;
394 }
718e3744 395
396 /* 2. Local preference check. */
8ff56318
JBD
397 new_pref = exist_pref = bgp->default_local_pref;
398
399 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
400 new_pref = newattr->local_pref;
401 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
402 exist_pref = existattr->local_pref;
718e3744 403
718e3744 404 if (new_pref > exist_pref)
9fbdd100
DS
405 {
406 if (debug)
407 zlog_debug("%s: path %s wins over path %s due to localpref %d > %d",
408 pfx_buf, new->peer->host, exist->peer->host, new_pref,
409 exist_pref);
410 return 1;
411 }
412
718e3744 413 if (new_pref < exist_pref)
9fbdd100
DS
414 {
415 if (debug)
416 zlog_debug("%s: path %s loses to path %s due to localpref %d < %d",
417 pfx_buf, new->peer->host, exist->peer->host, new_pref,
418 exist_pref);
419 return 0;
420 }
718e3744 421
8ff56318
JBD
422 /* 3. Local route check. We prefer:
423 * - BGP_ROUTE_STATIC
424 * - BGP_ROUTE_AGGREGATE
425 * - BGP_ROUTE_REDISTRIBUTE
426 */
427 if (! (new->sub_type == BGP_ROUTE_NORMAL))
9fbdd100
DS
428 {
429 if (debug)
430 zlog_debug("%s: path %s wins over path %s due to preferred BGP_ROUTE type",
431 pfx_buf, new->peer->host, exist->peer->host);
432 return 1;
433 }
434
8ff56318 435 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
9fbdd100
DS
436 {
437 if (debug)
438 zlog_debug("%s: path %s loses to path %s due to preferred BGP_ROUTE type",
439 pfx_buf, new->peer->host, exist->peer->host);
440 return 0;
441 }
718e3744 442
443 /* 4. AS path length check. */
444 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
445 {
8ff56318
JBD
446 int exist_hops = aspath_count_hops (existattr->aspath);
447 int exist_confeds = aspath_count_confeds (existattr->aspath);
fe69a505 448
6811845b 449 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
450 {
fe69a505 451 int aspath_hops;
452
8ff56318
JBD
453 aspath_hops = aspath_count_hops (newattr->aspath);
454 aspath_hops += aspath_count_confeds (newattr->aspath);
fe69a505 455
456 if ( aspath_hops < (exist_hops + exist_confeds))
9fbdd100
DS
457 {
458 if (debug)
459 zlog_debug("%s: path %s wins over path %s due to aspath (with confeds) hopcount %d < %d",
460 pfx_buf, new->peer->host, exist->peer->host,
461 aspath_hops, (exist_hops + exist_confeds));
462 return 1;
463 }
464
fe69a505 465 if ( aspath_hops > (exist_hops + exist_confeds))
9fbdd100
DS
466 {
467 if (debug)
468 zlog_debug("%s: path %s loses to path %s due to aspath (with confeds) hopcount %d > %d",
469 pfx_buf, new->peer->host, exist->peer->host,
470 aspath_hops, (exist_hops + exist_confeds));
471 return 0;
472 }
6811845b 473 }
474 else
475 {
8ff56318 476 int newhops = aspath_count_hops (newattr->aspath);
fe69a505 477
478 if (newhops < exist_hops)
9fbdd100
DS
479 {
480 if (debug)
481 zlog_debug("%s: path %s wins over path %s due to aspath hopcount %d < %d",
482 pfx_buf, new->peer->host, exist->peer->host,
483 newhops, exist_hops);
484 return 1;
485 }
486
fe69a505 487 if (newhops > exist_hops)
9fbdd100
DS
488 {
489 if (debug)
490 zlog_debug("%s: path %s loses to path %s due to aspath hopcount %d > %d",
491 pfx_buf, new->peer->host, exist->peer->host,
492 newhops, exist_hops);
493 return 0;
494 }
6811845b 495 }
718e3744 496 }
497
498 /* 5. Origin check. */
8ff56318 499 if (newattr->origin < existattr->origin)
9fbdd100
DS
500 {
501 if (debug)
502 zlog_debug("%s: path %s wins over path %s due to ORIGIN %s < %s",
503 pfx_buf, new->peer->host, exist->peer->host,
504 bgp_origin_long_str[newattr->origin],
505 bgp_origin_long_str[existattr->origin]);
506 return 1;
507 }
508
8ff56318 509 if (newattr->origin > existattr->origin)
9fbdd100
DS
510 {
511 if (debug)
512 zlog_debug("%s: path %s loses to path %s due to ORIGIN %s > %s",
513 pfx_buf, new->peer->host, exist->peer->host,
514 bgp_origin_long_str[newattr->origin],
515 bgp_origin_long_str[existattr->origin]);
516 return 0;
517 }
718e3744 518
519 /* 6. MED check. */
8ff56318
JBD
520 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
521 && aspath_count_hops (existattr->aspath) == 0);
522 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
523 && aspath_count_confeds (existattr->aspath) > 0
524 && aspath_count_hops (newattr->aspath) == 0
525 && aspath_count_hops (existattr->aspath) == 0);
718e3744 526
527 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
528 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
529 && confed_as_route)
8ff56318
JBD
530 || aspath_cmp_left (newattr->aspath, existattr->aspath)
531 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
718e3744 532 || internal_as_route)
533 {
534 new_med = bgp_med_value (new->attr, bgp);
535 exist_med = bgp_med_value (exist->attr, bgp);
536
537 if (new_med < exist_med)
9fbdd100
DS
538 {
539 if (debug)
540 zlog_debug("%s: path %s wins over path %s due to MED %d < %d",
541 pfx_buf, new->peer->host, exist->peer->host, new_med,
542 exist_med);
543 return 1;
544 }
545
718e3744 546 if (new_med > exist_med)
9fbdd100
DS
547 {
548 if (debug)
549 zlog_debug("%s: path %s loses to path %s due to MED %d > %d",
550 pfx_buf, new->peer->host, exist->peer->host, new_med,
551 exist_med);
552 return 0;
553 }
718e3744 554 }
555
556 /* 7. Peer type check. */
8ff56318
JBD
557 new_sort = new->peer->sort;
558 exist_sort = exist->peer->sort;
559
560 if (new_sort == BGP_PEER_EBGP
561 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
9fbdd100
DS
562 {
563 if (debug)
564 zlog_debug("%s: path %s wins over path %s due to eBGP peer > iBGP peeer",
565 pfx_buf, new->peer->host, exist->peer->host);
566 return 1;
567 }
568
8ff56318
JBD
569 if (exist_sort == BGP_PEER_EBGP
570 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
9fbdd100
DS
571 {
572 if (debug)
573 zlog_debug("%s: path %s loses to path %s due to iBGP peer < eBGP peeer",
574 pfx_buf, new->peer->host, exist->peer->host);
575 return 0;
576 }
718e3744 577
578 /* 8. IGP metric check. */
8ff56318
JBD
579 newm = existm = 0;
580
581 if (new->extra)
582 newm = new->extra->igpmetric;
583 if (exist->extra)
584 existm = exist->extra->igpmetric;
585
96450faf 586 if (newm < existm)
9fbdd100
DS
587 {
588 if (debug)
589 zlog_debug("%s: path %s wins over path %s due to IGP metric %d < %d",
590 pfx_buf, new->peer->host, exist->peer->host, newm, existm);
591 ret = 1;
592 }
593
96450faf 594 if (newm > existm)
9fbdd100
DS
595 {
596 if (debug)
597 zlog_debug("%s: path %s loses to path %s due to IGP metric %d > %d",
598 pfx_buf, new->peer->host, exist->peer->host, newm, existm);
599 ret = 0;
600 }
718e3744 601
5e242b0d
DS
602 /* 8.1. Same IGP metric. Compare the cluster list length as
603 representative of IGP hops metric. Rewrite the metric value
604 pair (newm, existm) with the cluster list length. Prefer the
605 path with smaller cluster list length. */
606 if (newm == existm)
607 {
608 if (peer_sort (new->peer) == BGP_PEER_IBGP
609 && peer_sort (exist->peer) == BGP_PEER_IBGP
610 && CHECK_FLAG (mpath_cfg->ibgp_flags,
611 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
612 {
613 newm = BGP_CLUSTER_LIST_LENGTH(new->attr);
614 existm = BGP_CLUSTER_LIST_LENGTH(exist->attr);
9fbdd100 615
5e242b0d 616 if (newm < existm)
9fbdd100
DS
617 {
618 if (debug)
619 zlog_debug("%s: path %s wins over path %s due to CLUSTER_LIST length %d < %d",
620 pfx_buf, new->peer->host, exist->peer->host, newm,
621 existm);
622 ret = 1;
623 }
624
5e242b0d 625 if (newm > existm)
9fbdd100
DS
626 {
627 if (debug)
628 zlog_debug("%s: path %s loses to path %s due to CLUSTER_LIST length %d > %d",
629 pfx_buf, new->peer->host, exist->peer->host, newm,
630 existm);
631 ret = 0;
632 }
5e242b0d
DS
633 }
634 }
635
718e3744 636 /* 9. Maximum path check. */
96450faf
JB
637 if (newm == existm)
638 {
2fdd455c
PM
639 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
640 {
641
642 /*
643 * For the two paths, all comparison steps till IGP metric
644 * have succeeded - including AS_PATH hop count. Since 'bgp
645 * bestpath as-path multipath-relax' knob is on, we don't need
646 * an exact match of AS_PATH. Thus, mark the paths are equal.
647 * That will trigger both these paths to get into the multipath
648 * array.
649 */
650 *paths_eq = 1;
9fbdd100
DS
651
652 if (debug)
653 zlog_debug("%s: path %s and path %s are equal via multipath-relax",
654 pfx_buf, new->peer->host, exist->peer->host);
2fdd455c
PM
655 }
656 else if (new->peer->sort == BGP_PEER_IBGP)
96450faf
JB
657 {
658 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
9fbdd100
DS
659 {
660 *paths_eq = 1;
661
662 if (debug)
663 zlog_debug("%s: path %s and path %s are equal via matching aspaths",
664 pfx_buf, new->peer->host, exist->peer->host);
665 }
96450faf
JB
666 }
667 else if (new->peer->as == exist->peer->as)
9fbdd100
DS
668 {
669 *paths_eq = 1;
670
671 if (debug)
672 zlog_debug("%s: path %s and path %s are equal via same remote-as",
673 pfx_buf, new->peer->host, exist->peer->host);
674 }
96450faf
JB
675 }
676 else
677 {
678 /*
679 * TODO: If unequal cost ibgp multipath is enabled we can
680 * mark the paths as equal here instead of returning
681 */
682 return ret;
683 }
718e3744 684
685 /* 10. If both paths are external, prefer the path that was received
686 first (the oldest one). This step minimizes route-flap, since a
687 newer path won't displace an older one, even if it was the
688 preferred route based on the additional decision criteria below. */
689 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
8ff56318
JBD
690 && new_sort == BGP_PEER_EBGP
691 && exist_sort == BGP_PEER_EBGP)
718e3744 692 {
693 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
9fbdd100
DS
694 {
695 if (debug)
696 zlog_debug("%s: path %s wins over path %s due to oldest external",
697 pfx_buf, new->peer->host, exist->peer->host);
698 return 1;
699 }
700
718e3744 701 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
9fbdd100
DS
702 {
703 if (debug)
704 zlog_debug("%s: path %s loses to path %s due to oldest external",
705 pfx_buf, new->peer->host, exist->peer->host);
706 return 0;
707 }
718e3744 708 }
709
0de5153c
DS
710 /* 11. Router-ID comparision. */
711 /* If one of the paths is "stale", the corresponding peer router-id will
712 * be 0 and would always win over the other path. If originator id is
713 * used for the comparision, it will decide which path is better.
714 */
8ff56318
JBD
715 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
716 new_id.s_addr = newattre->originator_id.s_addr;
718e3744 717 else
718 new_id.s_addr = new->peer->remote_id.s_addr;
8ff56318
JBD
719 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
720 exist_id.s_addr = existattre->originator_id.s_addr;
718e3744 721 else
722 exist_id.s_addr = exist->peer->remote_id.s_addr;
723
724 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
9fbdd100
DS
725 {
726 if (debug)
727 zlog_debug("%s: path %s wins over path %s due to Router-ID comparison",
728 pfx_buf, new->peer->host, exist->peer->host);
729 return 1;
730 }
731
718e3744 732 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
9fbdd100
DS
733 {
734 if (debug)
735 zlog_debug("%s: path %s loses to path %s due to Router-ID comparison",
736 pfx_buf, new->peer->host, exist->peer->host);
737 return 0;
738 }
718e3744 739
740 /* 12. Cluster length comparision. */
5e242b0d
DS
741 new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
742 exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
718e3744 743
744 if (new_cluster < exist_cluster)
9fbdd100
DS
745 {
746 if (debug)
747 zlog_debug("%s: path %s wins over path %s due to CLUSTER_LIST length %d < %d",
748 pfx_buf, new->peer->host, exist->peer->host, new_cluster,
749 exist_cluster);
750 return 1;
751 }
752
718e3744 753 if (new_cluster > exist_cluster)
9fbdd100
DS
754 {
755 if (debug)
756 zlog_debug("%s: path %s loses to path %s due to CLUSTER_LIST length %d > %d",
757 pfx_buf, new->peer->host, exist->peer->host, new_cluster,
758 exist_cluster);
759 return 0;
760 }
718e3744 761
762 /* 13. Neighbor address comparision. */
0de5153c
DS
763 /* Do this only if neither path is "stale" as stale paths do not have
764 * valid peer information (as the connection may or may not be up).
765 */
766 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
9fbdd100
DS
767 {
768 if (debug)
769 zlog_debug("%s: path %s wins over path %s due to latter path being STALE",
770 pfx_buf, new->peer->host, exist->peer->host);
771 return 1;
772 }
773
0de5153c 774 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
9fbdd100
DS
775 {
776 if (debug)
777 zlog_debug("%s: path %s loses to path %s due to former path being STALE",
778 pfx_buf, new->peer->host, exist->peer->host);
779 return 0;
780 }
0de5153c 781
718e3744 782 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
783
784 if (ret == 1)
9fbdd100
DS
785 {
786 if (debug)
787 zlog_debug("%s: path %s loses to path %s due to Neighor IP comparison",
788 pfx_buf, new->peer->host, exist->peer->host);
789 return 0;
790 }
791
718e3744 792 if (ret == -1)
9fbdd100
DS
793 {
794 if (debug)
795 zlog_debug("%s: path %s wins over path %s due to Neighor IP comparison",
796 pfx_buf, new->peer->host, exist->peer->host);
797 return 1;
798 }
799
800 if (debug)
801 zlog_debug("%s: path %s wins over path %s due to nothing left to compare",
802 pfx_buf, new->peer->host, exist->peer->host);
718e3744 803
804 return 1;
805}
806
94f2b392 807static enum filter_type
718e3744 808bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
809 afi_t afi, safi_t safi)
810{
811 struct bgp_filter *filter;
812
813 filter = &peer->filter[afi][safi];
814
650f76c2
PJ
815#define FILTER_EXIST_WARN(F,f,filter) \
816 if (BGP_DEBUG (update, UPDATE_IN) \
817 && !(F ## _IN (filter))) \
16286195 818 zlog_warn ("%s: Could not find configured input %s-list %s!", \
650f76c2
PJ
819 peer->host, #f, F ## _IN_NAME(filter));
820
821 if (DISTRIBUTE_IN_NAME (filter)) {
822 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
823
718e3744 824 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
825 return FILTER_DENY;
650f76c2 826 }
718e3744 827
650f76c2
PJ
828 if (PREFIX_LIST_IN_NAME (filter)) {
829 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
830
718e3744 831 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
832 return FILTER_DENY;
650f76c2 833 }
718e3744 834
650f76c2
PJ
835 if (FILTER_LIST_IN_NAME (filter)) {
836 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
837
718e3744 838 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
839 return FILTER_DENY;
650f76c2
PJ
840 }
841
718e3744 842 return FILTER_PERMIT;
650f76c2 843#undef FILTER_EXIST_WARN
718e3744 844}
845
94f2b392 846static enum filter_type
718e3744 847bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
848 afi_t afi, safi_t safi)
849{
850 struct bgp_filter *filter;
851
852 filter = &peer->filter[afi][safi];
853
650f76c2
PJ
854#define FILTER_EXIST_WARN(F,f,filter) \
855 if (BGP_DEBUG (update, UPDATE_OUT) \
856 && !(F ## _OUT (filter))) \
16286195 857 zlog_warn ("%s: Could not find configured output %s-list %s!", \
650f76c2
PJ
858 peer->host, #f, F ## _OUT_NAME(filter));
859
860 if (DISTRIBUTE_OUT_NAME (filter)) {
861 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
862
718e3744 863 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
864 return FILTER_DENY;
650f76c2 865 }
718e3744 866
650f76c2
PJ
867 if (PREFIX_LIST_OUT_NAME (filter)) {
868 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
869
718e3744 870 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
871 return FILTER_DENY;
650f76c2 872 }
718e3744 873
650f76c2
PJ
874 if (FILTER_LIST_OUT_NAME (filter)) {
875 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
876
718e3744 877 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
878 return FILTER_DENY;
650f76c2 879 }
718e3744 880
881 return FILTER_PERMIT;
650f76c2 882#undef FILTER_EXIST_WARN
718e3744 883}
884
885/* If community attribute includes no_export then return 1. */
94f2b392 886static int
718e3744 887bgp_community_filter (struct peer *peer, struct attr *attr)
888{
889 if (attr->community)
890 {
891 /* NO_ADVERTISE check. */
892 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
893 return 1;
894
895 /* NO_EXPORT check. */
6d85b15b 896 if (peer->sort == BGP_PEER_EBGP &&
718e3744 897 community_include (attr->community, COMMUNITY_NO_EXPORT))
898 return 1;
899
900 /* NO_EXPORT_SUBCONFED check. */
6d85b15b
JBD
901 if (peer->sort == BGP_PEER_EBGP
902 || peer->sort == BGP_PEER_CONFED)
718e3744 903 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
904 return 1;
905 }
906 return 0;
907}
908
909/* Route reflection loop check. */
910static int
911bgp_cluster_filter (struct peer *peer, struct attr *attr)
912{
913 struct in_addr cluster_id;
914
fb982c25 915 if (attr->extra && attr->extra->cluster)
718e3744 916 {
917 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
918 cluster_id = peer->bgp->cluster_id;
919 else
920 cluster_id = peer->bgp->router_id;
921
fb982c25 922 if (cluster_loop_check (attr->extra->cluster, cluster_id))
718e3744 923 return 1;
924 }
925 return 0;
926}
6b0655a2 927
94f2b392 928static int
718e3744 929bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
0b16f239 930 afi_t afi, safi_t safi, char *rmap_name)
718e3744 931{
932 struct bgp_filter *filter;
933 struct bgp_info info;
934 route_map_result_t ret;
0b16f239 935 struct route_map *rmap = NULL;
718e3744 936
937 filter = &peer->filter[afi][safi];
938
939 /* Apply default weight value. */
fb982c25
PJ
940 if (peer->weight)
941 (bgp_attr_extra_get (attr))->weight = peer->weight;
718e3744 942
0b16f239
DS
943 if (rmap_name)
944 {
945 rmap = route_map_lookup_by_name(rmap_name);
946 }
947 else
948 {
949 if (ROUTE_MAP_IN_NAME(filter))
950 rmap = ROUTE_MAP_IN (filter);
951 }
952
718e3744 953 /* Route map apply. */
0b16f239 954 if (rmap)
718e3744 955 {
956 /* Duplicate current value to new strucutre for modification. */
957 info.peer = peer;
958 info.attr = attr;
959
ac41b2a2 960 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
961
718e3744 962 /* Apply BGP route map to the attribute. */
0b16f239
DS
963 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
964
965 peer->rmap_type = 0;
966
967 if (ret == RMAP_DENYMATCH)
968 {
969 /* Free newly generated AS path and community by route-map. */
970 bgp_attr_flush (attr);
971 return RMAP_DENY;
972 }
973 }
974 return RMAP_PERMIT;
975}
976
977static int
978bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
979 afi_t afi, safi_t safi, char *rmap_name)
980{
981 struct bgp_filter *filter;
982 struct bgp_info info;
983 route_map_result_t ret;
984 struct route_map *rmap = NULL;
985
986 filter = &peer->filter[afi][safi];
987
988 /* Apply default weight value. */
989 if (peer->weight)
990 (bgp_attr_extra_get (attr))->weight = peer->weight;
991
992 if (rmap_name)
993 {
994 rmap = route_map_lookup_by_name(rmap_name);
995 }
996 else
997 {
998 if (ROUTE_MAP_OUT_NAME(filter))
999 rmap = ROUTE_MAP_OUT (filter);
1000 }
1001
1002 /* Route map apply. */
1003 if (rmap)
1004 {
1005 /* Duplicate current value to new strucutre for modification. */
1006 info.peer = peer;
1007 info.attr = attr;
1008
1009 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1010
1011 /* Apply BGP route map to the attribute. */
1012 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
ac41b2a2 1013
1014 peer->rmap_type = 0;
1015
718e3744 1016 if (ret == RMAP_DENYMATCH)
c460e572
DL
1017 /* caller has multiple error paths with bgp_attr_flush() */
1018 return RMAP_DENY;
718e3744 1019 }
1020 return RMAP_PERMIT;
1021}
6b0655a2 1022
94f2b392 1023static int
fee0f4c6 1024bgp_export_modifier (struct peer *rsclient, struct peer *peer,
1025 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
1026{
1027 struct bgp_filter *filter;
1028 struct bgp_info info;
1029 route_map_result_t ret;
1030
1031 filter = &peer->filter[afi][safi];
1032
1033 /* Route map apply. */
1034 if (ROUTE_MAP_EXPORT_NAME (filter))
1035 {
1036 /* Duplicate current value to new strucutre for modification. */
1037 info.peer = rsclient;
1038 info.attr = attr;
1039
1040 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
1041
1042 /* Apply BGP route map to the attribute. */
1043 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
1044
1045 rsclient->rmap_type = 0;
1046
1047 if (ret == RMAP_DENYMATCH)
1048 {
1049 /* Free newly generated AS path and community by route-map. */
1050 bgp_attr_flush (attr);
1051 return RMAP_DENY;
1052 }
1053 }
1054 return RMAP_PERMIT;
1055}
1056
94f2b392 1057static int
fee0f4c6 1058bgp_import_modifier (struct peer *rsclient, struct peer *peer,
1059 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
1060{
1061 struct bgp_filter *filter;
1062 struct bgp_info info;
1063 route_map_result_t ret;
1064
1065 filter = &rsclient->filter[afi][safi];
1066
1067 /* Apply default weight value. */
fb982c25
PJ
1068 if (peer->weight)
1069 (bgp_attr_extra_get (attr))->weight = peer->weight;
fee0f4c6 1070
1071 /* Route map apply. */
1072 if (ROUTE_MAP_IMPORT_NAME (filter))
1073 {
1074 /* Duplicate current value to new strucutre for modification. */
1075 info.peer = peer;
1076 info.attr = attr;
1077
1078 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
1079
1080 /* Apply BGP route map to the attribute. */
1081 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
1082
1083 peer->rmap_type = 0;
1084
1085 if (ret == RMAP_DENYMATCH)
1086 {
1087 /* Free newly generated AS path and community by route-map. */
1088 bgp_attr_flush (attr);
1089 return RMAP_DENY;
1090 }
1091 }
1092 return RMAP_PERMIT;
1093}
6b0655a2 1094
5000f21c
DS
1095
1096/* If this is an EBGP peer with remove-private-AS */
1097void
1098bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
1099 struct peer *peer, struct attr *attr)
1100{
1101 if (peer->sort == BGP_PEER_EBGP &&
1102 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS))
1103 {
1104 // Take action on the entire aspath
1105 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
1106 {
1107 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
1108 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1109
1110 // The entire aspath consists of private ASNs so create an empty aspath
1111 else if (aspath_private_as_check (attr->aspath))
1112 attr->aspath = aspath_empty_get ();
1113
1114 // There are some public and some private ASNs, remove the private ASNs
1115 else
1116 attr->aspath = aspath_remove_private_asns (attr->aspath);
1117 }
1118
1119 // 'all' was not specified so the entire aspath must be private ASNs
1120 // for us to do anything
1121 else if (aspath_private_as_check (attr->aspath))
1122 {
1123 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
1124 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1125 else
1126 attr->aspath = aspath_empty_get ();
1127 }
1128 }
1129}
1130
c7122e14
DS
1131/* If this is an EBGP peer with as-override */
1132static void
1133bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
1134 struct peer *peer, struct attr *attr)
1135{
1136 if (peer->sort == BGP_PEER_EBGP &&
1137 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
1138 {
1139 if (aspath_single_asn_check (attr->aspath, peer->as))
1140 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
1141 }
1142}
1143
94f2b392 1144static int
718e3744 1145bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
1146 struct attr *attr, afi_t afi, safi_t safi)
1147{
1148 int ret;
1149 char buf[SU_ADDRSTRLEN];
1150 struct bgp_filter *filter;
718e3744 1151 struct peer *from;
1152 struct bgp *bgp;
718e3744 1153 int transparent;
1154 int reflect;
0b597ef0 1155 struct attr *riattr;
718e3744 1156
1157 from = ri->peer;
1158 filter = &peer->filter[afi][safi];
1159 bgp = peer->bgp;
0b597ef0 1160 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
718e3744 1161
750e8146
PJ
1162 if (DISABLE_BGP_ANNOUNCE)
1163 return 0;
718e3744 1164
fee0f4c6 1165 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
1166 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1167 return 0;
1168
718e3744 1169 /* Do not send back route to sender. */
1170 if (from == peer)
1171 return 0;
1172
1173 /* Aggregate-address suppress check. */
fb982c25 1174 if (ri->extra && ri->extra->suppress)
718e3744 1175 if (! UNSUPPRESS_MAP_NAME (filter))
1176 return 0;
1177
1178 /* Default route check. */
1179 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
1180 {
1181 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1182 return 0;
1183#ifdef HAVE_IPV6
1184 else if (p->family == AF_INET6 && p->prefixlen == 0)
1185 return 0;
1186#endif /* HAVE_IPV6 */
1187 }
1188
286e1e71 1189 /* Transparency check. */
1190 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1191 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1192 transparent = 1;
1193 else
1194 transparent = 0;
1195
718e3744 1196 /* If community is not disabled check the no-export and local. */
0b597ef0 1197 if (! transparent && bgp_community_filter (peer, riattr))
718e3744 1198 return 0;
1199
1200 /* If the attribute has originator-id and it is same as remote
1201 peer's id. */
0b597ef0 1202 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
718e3744 1203 {
0b597ef0 1204 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
718e3744 1205 {
3f9c7369 1206 if (bgp_debug_update(peer, p, NULL, 0))
16286195
DS
1207 zlog_debug("%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1208 peer->host,
1209 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1210 p->prefixlen);
718e3744 1211 return 0;
1212 }
1213 }
1214
1215 /* ORF prefix-list filter check */
1216 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1217 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1218 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1219 if (peer->orf_plist[afi][safi])
1220 {
1221 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1222 return 0;
1223 }
1224
1225 /* Output filter check. */
0b597ef0 1226 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
718e3744 1227 {
3f9c7369 1228 if (bgp_debug_update(peer, p, NULL, 0))
16286195
DS
1229 zlog_debug("%s [Update:SEND] %s/%d is filtered",
1230 peer->host,
1231 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1232 p->prefixlen);
718e3744 1233 return 0;
1234 }
1235
1236#ifdef BGP_SEND_ASPATH_CHECK
1237 /* AS path loop check. */
0b597ef0 1238 if (aspath_loop_check (riattr->aspath, peer->as))
718e3744 1239 {
3f9c7369 1240 if (bgp_debug_update(peer, p, NULL, 0))
16286195
DS
1241 zlog_debug("%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
1242 peer->host, peer->as);
718e3744 1243 return 0;
1244 }
1245#endif /* BGP_SEND_ASPATH_CHECK */
1246
1247 /* If we're a CONFED we need to loop check the CONFED ID too */
1248 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1249 {
0b597ef0 1250 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
718e3744 1251 {
3f9c7369 1252 if (bgp_debug_update(peer, p, NULL, 0))
16286195
DS
1253 zlog_debug("%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
1254 peer->host,
1255 bgp->confed_id);
718e3744 1256 return 0;
1257 }
1258 }
1259
1260 /* Route-Reflect check. */
6d85b15b 1261 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
718e3744 1262 reflect = 1;
1263 else
1264 reflect = 0;
1265
1266 /* IBGP reflection check. */
1267 if (reflect)
1268 {
1269 /* A route from a Client peer. */
1270 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1271 {
1272 /* Reflect to all the Non-Client peers and also to the
1273 Client peers other than the originator. Originator check
1274 is already done. So there is noting to do. */
1275 /* no bgp client-to-client reflection check. */
1276 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1277 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1278 return 0;
1279 }
1280 else
1281 {
1282 /* A route from a Non-client peer. Reflect to all other
1283 clients. */
1284 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1285 return 0;
1286 }
1287 }
41367172 1288
718e3744 1289 /* For modify attribute, copy it to temporary structure. */
0b597ef0 1290 bgp_attr_dup (attr, riattr);
fb982c25 1291
718e3744 1292 /* If local-preference is not set. */
6d85b15b
JBD
1293 if ((peer->sort == BGP_PEER_IBGP
1294 || peer->sort == BGP_PEER_CONFED)
718e3744 1295 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1296 {
1297 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1298 attr->local_pref = bgp->default_local_pref;
1299 }
1300
689bb66c
PM
1301 /* If originator-id is not set and the route is to be reflected,
1302 set the originator id */
1303 if (peer && from && peer->sort == BGP_PEER_IBGP &&
1304 from->sort == BGP_PEER_IBGP &&
1305 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1306 {
1307 attr->extra = bgp_attr_extra_get(attr);
1308 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1309 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1310 }
1311
718e3744 1312 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
6d85b15b 1313 if (peer->sort == BGP_PEER_EBGP
718e3744 1314 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1315 {
1316 if (ri->peer != bgp->peer_self && ! transparent
1317 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1318 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1319 }
1320
1321 /* next-hop-set */
9e7a53c1
TT
1322 if (transparent
1323 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
718e3744 1324 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
1325 && ((p->family == AF_INET && attr->nexthop.s_addr)
286e1e71 1326#ifdef HAVE_IPV6
fee0f4c6 1327 || (p->family == AF_INET6 &&
fb982c25 1328 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
286e1e71 1329#endif /* HAVE_IPV6 */
1330 )))
718e3744 1331 {
1332 /* NEXT-HOP Unchanged. */
1333 }
1334 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
1335 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
1336#ifdef HAVE_IPV6
fee0f4c6 1337 || (p->family == AF_INET6 &&
fb982c25 1338 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
718e3744 1339#endif /* HAVE_IPV6 */
6d85b15b 1340 || (peer->sort == BGP_PEER_EBGP
fc9a856f 1341 && (bgp_multiaccess_check_v4 (attr->nexthop, peer) == 0)))
718e3744 1342 {
1343 /* Set IPv4 nexthop. */
1344 if (p->family == AF_INET)
1345 {
1346 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
1347 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1348 IPV4_MAX_BYTELEN);
718e3744 1349 else
1350 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1351 }
1352#ifdef HAVE_IPV6
1353 /* Set IPv6 nexthop. */
1354 if (p->family == AF_INET6)
1355 {
1356 /* IPv6 global nexthop must be included. */
fb982c25 1357 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
718e3744 1358 IPV6_MAX_BYTELEN);
801a9bcc 1359 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
718e3744 1360 }
1361#endif /* HAVE_IPV6 */
1362 }
1363
1364#ifdef HAVE_IPV6
1365 if (p->family == AF_INET6)
1366 {
fee0f4c6 1367 /* Left nexthop_local unchanged if so configured. */
1368 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1369 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1370 {
fb982c25 1371 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
801a9bcc 1372 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
fee0f4c6 1373 else
801a9bcc 1374 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 1375 }
1376
1377 /* Default nexthop_local treatment for non-RS-Clients */
1378 else
1379 {
718e3744 1380 /* Link-local address should not be transit to different peer. */
801a9bcc 1381 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
718e3744 1382
1383 /* Set link-local address for shared network peer. */
1384 if (peer->shared_network
1385 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1386 {
fb982c25 1387 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
718e3744 1388 IPV6_MAX_BYTELEN);
801a9bcc 1389 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
718e3744 1390 }
1391
1392 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1393 address.*/
1394 if (reflect)
801a9bcc 1395 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
718e3744 1396
1397 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1398 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
801a9bcc 1399 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
718e3744 1400 }
fee0f4c6 1401
1402 }
718e3744 1403#endif /* HAVE_IPV6 */
1404
5000f21c 1405 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
c7122e14 1406 bgp_peer_as_override(bgp, afi, safi, peer, attr);
718e3744 1407
1408 /* Route map & unsuppress-map apply. */
1409 if (ROUTE_MAP_OUT_NAME (filter)
fb982c25 1410 || (ri->extra && ri->extra->suppress) )
718e3744 1411 {
7c7fa1b4 1412 struct bgp_info info;
558d1fec
JBD
1413 struct attr dummy_attr;
1414 struct attr_extra dummy_extra;
1415
1416 dummy_attr.extra = &dummy_extra;
1417
718e3744 1418 info.peer = peer;
1419 info.attr = attr;
1420
1421 /* The route reflector is not allowed to modify the attributes
1422 of the reflected IBGP routes. */
8bd9d948
DS
1423 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP) &&
1424 !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
718e3744 1425 {
fb982c25 1426 bgp_attr_dup (&dummy_attr, attr);
9eda90ce 1427 info.attr = &dummy_attr;
718e3744 1428 }
ac41b2a2 1429
1430 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1431
fb982c25 1432 if (ri->extra && ri->extra->suppress)
718e3744 1433 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1434 else
1435 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1436
ac41b2a2 1437 peer->rmap_type = 0;
558d1fec 1438
718e3744 1439 if (ret == RMAP_DENYMATCH)
1440 {
1441 bgp_attr_flush (attr);
1442 return 0;
1443 }
1444 }
1445 return 1;
1446}
1447
3f9c7369
DS
1448static void
1449subgroup_announce_reset_nhop (u_char family, struct attr *attr)
1450{
1451 if (family == AF_INET)
1452 attr->nexthop.s_addr = 0;
1453#ifdef HAVE_IPV6
1454 if (family == AF_INET6)
1455 memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
1456#endif
1457}
1458
1459int
1460subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp,
1461 struct prefix *p, struct attr *attr)
1462{
1463 struct bgp_filter *filter;
1464 struct peer *from;
1465 struct peer *peer;
1466 struct peer *onlypeer;
1467 struct bgp *bgp;
1468 struct attr *riattr;
1469 struct peer_af *paf;
1470 char buf[SU_ADDRSTRLEN];
1471 int ret;
1472 int transparent;
1473 int reflect;
1474 afi_t afi;
1475 safi_t safi;
1476
1477 if (DISABLE_BGP_ANNOUNCE)
1478 return 0;
1479
1480 afi = SUBGRP_AFI(subgrp);
1481 safi = SUBGRP_SAFI(subgrp);
1482 peer = SUBGRP_PEER(subgrp);
1483 onlypeer = NULL;
1484 if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL))
1485 onlypeer = SUBGRP_PFIRST(subgrp)->peer;
1486
1487 from = ri->peer;
1488 filter = &peer->filter[afi][safi];
1489 bgp = SUBGRP_INST(subgrp);
1490 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1491
1492 /* Aggregate-address suppress check. */
1493 if (ri->extra && ri->extra->suppress)
1494 if (! UNSUPPRESS_MAP_NAME (filter))
1495 {
1496 return 0;
1497 }
1498
1499 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
1500 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1501 {
1502 return 0;
1503 }
1504
1505 /* Do not send back route to sender. */
1506 if (onlypeer && from == onlypeer)
1507 {
1508 return 0;
1509 }
1510
1511 /* Transparency check. */
1512 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1513 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1514 transparent = 1;
1515 else
1516 transparent = 0;
1517
1518 /* If community is not disabled check the no-export and local. */
1519 if (! transparent && bgp_community_filter (peer, riattr))
1520 {
1521 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1522 zlog_debug ("subgrpannouncecheck: community filter check fail");
1523 return 0;
1524 }
1525
1526 /* If the attribute has originator-id and it is same as remote
1527 peer's id. */
1528 if (onlypeer &&
1529 riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) &&
1530 (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id)))
1531 {
1532 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1533 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as "
1534 "remote router-id",
1535 onlypeer->host,
1536 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1537 p->prefixlen);
1538 return 0;
1539 }
1540
1541 /* ORF prefix-list filter check */
1542 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1543 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1544 || CHECK_FLAG (peer->af_cap[afi][safi],
1545 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1546 if (peer->orf_plist[afi][safi])
1547 {
1548 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1549 {
1550 return 0;
1551 }
1552 }
1553
1554 /* Output filter check. */
1555 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1556 {
1557 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1558 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1559 peer->host,
1560 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1561 p->prefixlen);
1562 return 0;
1563 }
1564
1565#ifdef BGP_SEND_ASPATH_CHECK
1566 /* AS path loop check. */
1567 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
1568 {
1569 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1570 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1571 "that is part of AS path.",
1572 onlypeer->host, onlypeer->as);
1573 return 0;
1574 }
1575#endif /* BGP_SEND_ASPATH_CHECK */
1576
1577 /* If we're a CONFED we need to loop check the CONFED ID too */
1578 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1579 {
1580 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1581 {
1582 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1583 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u"
1584 " is AS path.",
1585 peer->host,
1586 bgp->confed_id);
1587 return 0;
1588 }
1589 }
1590
1591 /* Route-Reflect check. */
1592 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1593 reflect = 1;
1594 else
1595 reflect = 0;
1596
1597 /* IBGP reflection check. */
1598 if (reflect)
1599 {
1600 /* A route from a Client peer. */
1601 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1602 {
1603 /* Reflect to all the Non-Client peers and also to the
1604 Client peers other than the originator. Originator check
1605 is already done. So there is noting to do. */
1606 /* no bgp client-to-client reflection check. */
1607 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1608 if (CHECK_FLAG (peer->af_flags[afi][safi],
1609 PEER_FLAG_REFLECTOR_CLIENT))
1610 return 0;
1611 }
1612 else
1613 {
1614 /* A route from a Non-client peer. Reflect to all other
1615 clients. */
1616 if (! CHECK_FLAG (peer->af_flags[afi][safi],
1617 PEER_FLAG_REFLECTOR_CLIENT))
1618 return 0;
1619 }
1620 }
1621
1622 /* For modify attribute, copy it to temporary structure. */
1623 bgp_attr_dup (attr, riattr);
1624
1625 /* If local-preference is not set. */
1626 if ((peer->sort == BGP_PEER_IBGP
1627 || peer->sort == BGP_PEER_CONFED)
1628 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1629 {
1630 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1631 attr->local_pref = bgp->default_local_pref;
1632 }
1633
1634 /* If originator-id is not set and the route is to be reflected,
1635 set the originator id */
1636 if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1637 {
1638 attr->extra = bgp_attr_extra_get(attr);
1639 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1640 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1641 }
1642
1643 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1644 if (peer->sort == BGP_PEER_EBGP
1645 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1646 {
1647 if (ri->peer != bgp->peer_self && ! transparent
1648 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1649 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1650 }
1651
1652 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1653 * in announce check, only certain flags and length (or number of nexthops
1654 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1655 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1656 * Typically, the source nexthop in the attribute is preserved but in the
1657 * scenarios where we know it will always be overwritten, we reset the
1658 * nexthop to "0" in an attempt to achieve better Update packing. An
1659 * example of this is when a prefix from each of 2 IBGP peers needs to be
1660 * announced to an EBGP peer (and they have the same attributes barring
1661 * their nexthop).
1662 */
1663 if (reflect)
1664 SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
1665
1666#ifdef HAVE_IPV6
1667 /* IPv6/MP starts with 1 nexthop, the link-local address is passed only if
1668 * we're not reflecting the route and the peer (group) to whom we're going
1669 * to announce is on a shared network (directly connected peers) or the
1670 * peer (group) is configured to receive link-local nexthop and it is
1671 * available in the prefix.
1672 * Of course, the operator can always set it through the route-map, if
1673 * so desired.
1674 */
1675 if (p->family == AF_INET6)
1676 {
801a9bcc 1677 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
3f9c7369
DS
1678 if (!reflect)
1679 {
1680 if (peer->shared_network ||
1681 (CHECK_FLAG (peer->af_flags[afi][safi],
1682 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1683 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)))
801a9bcc 1684 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
3f9c7369
DS
1685 }
1686
1687 /* Clear off link-local nexthop in source, if not needed. This may help
1688 * more prefixes share the same attribute for announcement.
1689 */
1690 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1691 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1692 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1693 }
1694#endif /* HAVE_IPV6 */
1695
1696 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1697 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1698
1699 /* Route map & unsuppress-map apply. */
1700 if (ROUTE_MAP_OUT_NAME (filter)
1701 || (ri->extra && ri->extra->suppress) )
1702 {
1703 struct bgp_info info;
1704 struct attr dummy_attr;
1705 struct attr_extra dummy_extra;
1706
1707 dummy_attr.extra = &dummy_extra;
1708
1709 info.peer = peer;
1710 info.attr = attr;
316e074d
DS
1711 /* don't confuse inbound and outbound setting */
1712 RESET_FLAG(attr->rmap_change_flags);
3f9c7369
DS
1713
1714 /*
1715 * The route reflector is not allowed to modify the attributes
1716 * of the reflected IBGP routes unless explicitly allowed.
1717 */
1718 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1719 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1720 {
1721 bgp_attr_dup (&dummy_attr, attr);
1722 info.attr = &dummy_attr;
1723 }
1724
1725 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1726
1727 if (ri->extra && ri->extra->suppress)
1728 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1729 else
1730 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1731
1732 peer->rmap_type = 0;
1733
1734 if (ret == RMAP_DENYMATCH)
1735 {
1736 bgp_attr_flush (attr);
1737 return 0;
1738 }
1739 }
1740
1741 /* After route-map has been applied, we check to see if the nexthop to
1742 * be carried in the attribute (that is used for the announcement) can
1743 * be cleared off or not. We do this in all cases where we would be
1744 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1745 * the global nexthop here; the link-local nexthop would have been cleared
1746 * already, and if not, it is required by the update formation code.
1747 * Also see earlier comments in this function.
1748 */
1749 if (!(CHECK_FLAG(attr->rmap_change_flags, BATTR_RMAP_NEXTHOP_CHANGED) ||
316e074d
DS
1750 CHECK_FLAG(attr->rmap_change_flags, BATTR_RMAP_NEXTHOP_UNCHANGED) ||
1751 CHECK_FLAG(riattr->rmap_change_flags, BATTR_RMAP_NEXTHOP_UNCHANGED) ||
3f9c7369
DS
1752 transparent ||
1753 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)))
1754 {
1755 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF))
1756 {
1757 if (!reflect ||
1758 CHECK_FLAG (peer->af_flags[afi][safi],
1759 PEER_FLAG_FORCE_NEXTHOP_SELF))
1760 subgroup_announce_reset_nhop (p->family, attr);
1761 }
1762 else if (peer->sort == BGP_PEER_EBGP)
1763 {
1764 SUBGRP_FOREACH_PEER (subgrp, paf)
1765 {
1766 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1767 break;
1768 }
1769 if (!paf)
1770 subgroup_announce_reset_nhop (p->family, attr);
1771 }
1772 }
1773
1774 return 1;
1775}
1776
1777static int
1778bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1779 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
1780{
1781 int ret;
1782 char buf[SU_ADDRSTRLEN];
1783 struct bgp_filter *filter;
1784 struct bgp_info info;
1785 struct peer *from;
1786 struct attr *riattr;
1787
1788 from = ri->peer;
1789 filter = &rsclient->filter[afi][safi];
1790 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1791
1792 if (DISABLE_BGP_ANNOUNCE)
1793 return 0;
1794
1795 /* Do not send back route to sender. */
1796 if (from == rsclient)
1797 return 0;
1798
1799 /* Aggregate-address suppress check. */
1800 if (ri->extra && ri->extra->suppress)
1801 if (! UNSUPPRESS_MAP_NAME (filter))
1802 return 0;
1803
1804 /* Default route check. */
1805 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1806 PEER_STATUS_DEFAULT_ORIGINATE))
1807 {
1808 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1809 return 0;
1810#ifdef HAVE_IPV6
1811 else if (p->family == AF_INET6 && p->prefixlen == 0)
1812 return 0;
1813#endif /* HAVE_IPV6 */
1814 }
1815
1816 /* If the attribute has originator-id and it is same as remote
1817 peer's id. */
1818 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1819 {
1820 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1821 &riattr->extra->originator_id))
1822 {
1823 if (bgp_debug_update(rsclient, p, NULL, 0))
1824 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1825 rsclient->host,
1826 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1827 p->prefixlen);
1828 return 0;
1829 }
1830 }
1831
1832 /* ORF prefix-list filter check */
1833 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1834 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1835 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1836 if (rsclient->orf_plist[afi][safi])
1837 {
1838 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1839 return 0;
1840 }
1841
1842 /* Output filter check. */
1843 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
1844 {
1845 if (bgp_debug_update(rsclient, p, NULL, 0))
1846 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1847 rsclient->host,
1848 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1849 p->prefixlen);
1850 return 0;
1851 }
1852
1853#ifdef BGP_SEND_ASPATH_CHECK
1854 /* AS path loop check. */
1855 if (aspath_loop_check (riattr->aspath, rsclient->as))
1856 {
1857 if (bgp_debug_update(rsclient, p, NULL, 0))
1858 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
1859 rsclient->host, rsclient->as);
1860 return 0;
1861 }
1862#endif /* BGP_SEND_ASPATH_CHECK */
1863
1864 /* For modify attribute, copy it to temporary structure. */
1865 bgp_attr_dup (attr, riattr);
1866
1867 /* next-hop-set */
1868 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1869#ifdef HAVE_IPV6
1870 || (p->family == AF_INET6 &&
1871 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
1872#endif /* HAVE_IPV6 */
1873 )
1874 {
1875 /* Set IPv4 nexthop. */
1876 if (p->family == AF_INET)
1877 {
1878 if (safi == SAFI_MPLS_VPN)
1879 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
1880 IPV4_MAX_BYTELEN);
1881 else
1882 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1883 }
1884#ifdef HAVE_IPV6
1885 /* Set IPv6 nexthop. */
1886 if (p->family == AF_INET6)
1887 {
1888 /* IPv6 global nexthop must be included. */
1889 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
1890 IPV6_MAX_BYTELEN);
801a9bcc 1891 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
3f9c7369
DS
1892 }
1893#endif /* HAVE_IPV6 */
1894 }
1895
1896#ifdef HAVE_IPV6
1897 if (p->family == AF_INET6)
1898 {
1899 struct attr_extra *attre = attr->extra;
1900
1901 /* Left nexthop_local unchanged if so configured. */
1902 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1903 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1904 {
1905 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
801a9bcc 1906 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
3f9c7369 1907 else
801a9bcc 1908 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
3f9c7369
DS
1909 }
1910
1911 /* Default nexthop_local treatment for RS-Clients */
1912 else
1913 {
1914 /* Announcer and RS-Client are both in the same network */
1915 if (rsclient->shared_network && from->shared_network &&
1916 (rsclient->ifindex == from->ifindex))
1917 {
1918 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
801a9bcc 1919 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
3f9c7369 1920 else
801a9bcc 1921 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
3f9c7369
DS
1922 }
1923
1924 /* Set link-local address for shared network peer. */
1925 else if (rsclient->shared_network
1926 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1927 {
1928 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
1929 IPV6_MAX_BYTELEN);
801a9bcc 1930 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
3f9c7369
DS
1931 }
1932
1933 else
801a9bcc 1934 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
3f9c7369
DS
1935 }
1936
1937 }
1938#endif /* HAVE_IPV6 */
1939
1940
1941 /* If this is EBGP peer and remove-private-AS is set. */
1942 if (rsclient->sort == BGP_PEER_EBGP
1943 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1944 && aspath_private_as_check (attr->aspath))
1945 attr->aspath = aspath_empty_get ();
1946
1947 /* Route map & unsuppress-map apply. */
1948 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
1949 {
1950 info.peer = rsclient;
1951 info.attr = attr;
1952
1953 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1954
1955 if (ri->extra && ri->extra->suppress)
1956 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1957 else
1958 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1959
1960 rsclient->rmap_type = 0;
1961
1962 if (ret == RMAP_DENYMATCH)
1963 {
1964 bgp_attr_flush (attr);
1965 return 0;
1966 }
1967 }
1968
1969 return 1;
1970}
1971
94f2b392 1972static int
3f9c7369
DS
1973subgroup_announce_check_rsclient (struct bgp_info *ri,
1974 struct update_subgroup *subgrp,
1975 struct prefix *p, struct attr *attr)
fee0f4c6 1976{
1977 int ret;
1978 char buf[SU_ADDRSTRLEN];
1979 struct bgp_filter *filter;
1980 struct bgp_info info;
1981 struct peer *from;
3f9c7369
DS
1982 struct peer *rsclient;
1983 struct peer *onlypeer;
0b597ef0 1984 struct attr *riattr;
5000f21c 1985 struct bgp *bgp;
3f9c7369
DS
1986 afi_t afi;
1987 safi_t safi;
1988
1989 if (DISABLE_BGP_ANNOUNCE)
1990 return 0;
fee0f4c6 1991
3f9c7369
DS
1992 afi = SUBGRP_AFI(subgrp);
1993 safi = SUBGRP_SAFI(subgrp);
1994 rsclient = SUBGRP_PEER(subgrp);
1995 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1996 (SUBGRP_PFIRST(subgrp))->peer : NULL);
fee0f4c6 1997 from = ri->peer;
1998 filter = &rsclient->filter[afi][safi];
5000f21c 1999 bgp = rsclient->bgp;
0b597ef0 2000 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
fee0f4c6 2001
fee0f4c6 2002 /* Do not send back route to sender. */
3f9c7369 2003 if (onlypeer && (from == onlypeer))
fee0f4c6 2004 return 0;
2005
2006 /* Aggregate-address suppress check. */
fb982c25 2007 if (ri->extra && ri->extra->suppress)
fee0f4c6 2008 if (! UNSUPPRESS_MAP_NAME (filter))
2009 return 0;
2010
2011 /* Default route check. */
2012 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
2013 PEER_STATUS_DEFAULT_ORIGINATE))
2014 {
2015 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
2016 return 0;
2017#ifdef HAVE_IPV6
2018 else if (p->family == AF_INET6 && p->prefixlen == 0)
2019 return 0;
2020#endif /* HAVE_IPV6 */
2021 }
2022
2023 /* If the attribute has originator-id and it is same as remote
2024 peer's id. */
3f9c7369 2025 if (onlypeer && riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
fee0f4c6 2026 {
3f9c7369 2027 if (IPV4_ADDR_SAME (&onlypeer->remote_id,
0b597ef0 2028 &riattr->extra->originator_id))
fee0f4c6 2029 {
3f9c7369 2030 if (bgp_debug_update(rsclient, p, subgrp->update_group, 0))
16286195 2031 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as remote router-id",
3f9c7369 2032 onlypeer->host,
16286195
DS
2033 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2034 p->prefixlen);
fee0f4c6 2035 return 0;
2036 }
2037 }
2038
2039 /* ORF prefix-list filter check */
2040 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
2041 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
2042 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
2043 if (rsclient->orf_plist[afi][safi])
2044 {
2045 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
2046 return 0;
2047 }
2048
2049 /* Output filter check. */
0b597ef0 2050 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
fee0f4c6 2051 {
3f9c7369 2052 if (bgp_debug_update(rsclient, p, subgrp->update_group, 0))
16286195
DS
2053 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
2054 rsclient->host,
2055 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2056 p->prefixlen);
fee0f4c6 2057 return 0;
2058 }
2059
2060#ifdef BGP_SEND_ASPATH_CHECK
2061 /* AS path loop check. */
3f9c7369 2062 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
fee0f4c6 2063 {
3f9c7369 2064 if (bgp_debug_update(rsclient, p, subgrp->update_group, 0))
16286195 2065 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
3f9c7369 2066 onlypeer->host, onlypeer->as);
fee0f4c6 2067 return 0;
2068 }
2069#endif /* BGP_SEND_ASPATH_CHECK */
2070
2071 /* For modify attribute, copy it to temporary structure. */
0b597ef0 2072 bgp_attr_dup (attr, riattr);
fee0f4c6 2073
2074 /* next-hop-set */
2075 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
2076#ifdef HAVE_IPV6
2077 || (p->family == AF_INET6 &&
fb982c25 2078 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
fee0f4c6 2079#endif /* HAVE_IPV6 */
2080 )
2081 {
2082 /* Set IPv4 nexthop. */
2083 if (p->family == AF_INET)
2084 {
2085 if (safi == SAFI_MPLS_VPN)
fb982c25 2086 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
fee0f4c6 2087 IPV4_MAX_BYTELEN);
2088 else
2089 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
2090 }
2091#ifdef HAVE_IPV6
2092 /* Set IPv6 nexthop. */
2093 if (p->family == AF_INET6)
2094 {
2095 /* IPv6 global nexthop must be included. */
fb982c25 2096 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
fee0f4c6 2097 IPV6_MAX_BYTELEN);
801a9bcc 2098 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 2099 }
2100#endif /* HAVE_IPV6 */
2101 }
2102
2103#ifdef HAVE_IPV6
2104 if (p->family == AF_INET6)
2105 {
fb982c25 2106 struct attr_extra *attre = attr->extra;
558d1fec 2107
fee0f4c6 2108 /* Left nexthop_local unchanged if so configured. */
3f9c7369 2109 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
fee0f4c6 2110 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
2111 {
fb982c25 2112 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
801a9bcc 2113 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
fee0f4c6 2114 else
801a9bcc 2115 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 2116 }
3f9c7369 2117
fee0f4c6 2118 /* Default nexthop_local treatment for RS-Clients */
3f9c7369
DS
2119 else
2120 {
2121 /* Announcer and RS-Client are both in the same network */
fee0f4c6 2122 if (rsclient->shared_network && from->shared_network &&
2123 (rsclient->ifindex == from->ifindex))
2124 {
fb982c25 2125 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
801a9bcc 2126 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
fee0f4c6 2127 else
801a9bcc 2128 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 2129 }
2130
2131 /* Set link-local address for shared network peer. */
2132 else if (rsclient->shared_network
2133 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
2134 {
fb982c25 2135 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
fee0f4c6 2136 IPV6_MAX_BYTELEN);
801a9bcc 2137 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
fee0f4c6 2138 }
2139
2140 else
801a9bcc 2141 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 2142 }
2143
2144 }
2145#endif /* HAVE_IPV6 */
2146
5000f21c 2147 bgp_peer_remove_private_as(bgp, afi, safi, rsclient, attr);
c7122e14 2148 bgp_peer_as_override(bgp, afi, safi, rsclient, attr);
fee0f4c6 2149
2150 /* Route map & unsuppress-map apply. */
fb982c25 2151 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
fee0f4c6 2152 {
2153 info.peer = rsclient;
2154 info.attr = attr;
2155
2156 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
2157
fb982c25 2158 if (ri->extra && ri->extra->suppress)
fee0f4c6 2159 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
2160 else
2161 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
2162
2163 rsclient->rmap_type = 0;
2164
2165 if (ret == RMAP_DENYMATCH)
2166 {
2167 bgp_attr_flush (attr);
2168 return 0;
2169 }
2170 }
2171
2172 return 1;
2173}
2174
2175struct bgp_info_pair
2176{
2177 struct bgp_info *old;
2178 struct bgp_info *new;
2179};
2180
94f2b392 2181static void
96450faf
JB
2182bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
2183 struct bgp_maxpaths_cfg *mpath_cfg,
2184 struct bgp_info_pair *result)
718e3744 2185{
718e3744 2186 struct bgp_info *new_select;
2187 struct bgp_info *old_select;
fee0f4c6 2188 struct bgp_info *ri;
718e3744 2189 struct bgp_info *ri1;
2190 struct bgp_info *ri2;
b40d939b 2191 struct bgp_info *nextri = NULL;
9fbdd100 2192 int paths_eq, do_mpath, debug;
96450faf 2193 struct list mp_list;
d889623f 2194 char buf[INET6_BUFSIZ];
9fbdd100 2195 char pfx_buf[INET6_ADDRSTRLEN];
96450faf
JB
2196
2197 bgp_mp_list_init (&mp_list);
2198 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
2199 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
2200
9fbdd100
DS
2201 debug = bgp_debug_bestpath(&rn->p);
2202
2203 if (debug)
2204 prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf));
2205
718e3744 2206 /* bgp deterministic-med */
2207 new_select = NULL;
2208 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
2209 for (ri1 = rn->info; ri1; ri1 = ri1->next)
2210 {
2211 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
2212 continue;
2213 if (BGP_INFO_HOLDDOWN (ri1))
2214 continue;
2fed8887
DS
2215 if (ri1->peer && ri1->peer != bgp->peer_self)
2216 if (ri1->peer->status != Established)
2217 continue;
718e3744 2218
2219 new_select = ri1;
6918e74b 2220 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
718e3744 2221 if (ri1->next)
2222 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
2223 {
2224 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
2225 continue;
2226 if (BGP_INFO_HOLDDOWN (ri2))
2227 continue;
2fed8887
DS
2228 if (ri2->peer &&
2229 ri2->peer != bgp->peer_self &&
2230 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
2231 if (ri2->peer->status != Established)
2232 continue;
718e3744 2233
2234 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
2235 || aspath_cmp_left_confed (ri1->attr->aspath,
2236 ri2->attr->aspath))
2237 {
6918e74b
JB
2238 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
2239 old_select = ri2;
5e242b0d 2240 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
9fbdd100 2241 mpath_cfg, debug, pfx_buf))
718e3744 2242 {
1a392d46 2243 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
718e3744 2244 new_select = ri2;
2245 }
2246
1a392d46 2247 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
718e3744 2248 }
2249 }
1a392d46
PJ
2250 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
2251 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
718e3744 2252 }
2253
2254 /* Check old selected route and new selected route. */
2255 old_select = NULL;
2256 new_select = NULL;
b40d939b 2257 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
718e3744 2258 {
2259 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
2260 old_select = ri;
2261
2262 if (BGP_INFO_HOLDDOWN (ri))
b40d939b 2263 {
2264 /* reap REMOVED routes, if needs be
2265 * selected route must stay for a while longer though
2266 */
2267 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2268 && (ri != old_select))
2269 bgp_info_reap (rn, ri);
2270
2271 continue;
2272 }
718e3744 2273
2fed8887
DS
2274 if (ri->peer &&
2275 ri->peer != bgp->peer_self &&
2276 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
2277 if (ri->peer->status != Established)
2278 continue;
2279
718e3744 2280 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
2281 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
2282 {
1a392d46 2283 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
718e3744 2284 continue;
2285 }
1a392d46
PJ
2286 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
2287 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
718e3744 2288
9fbdd100 2289 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
96450faf
JB
2290 {
2291 new_select = ri;
96450faf 2292 }
718e3744 2293 }
b40d939b 2294
f4eeff72
DS
2295 /* Now that we know which path is the bestpath see if any of the other paths
2296 * qualify as multipaths
2297 */
2298 if (do_mpath && new_select)
2299 {
9fbdd100
DS
2300 if (debug)
2301 zlog_debug("%s: path %s is the bestpath, now find multipaths",
2302 pfx_buf, new_select->peer->host);
2303
f4eeff72
DS
2304 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
2305 {
2306 if (ri == new_select)
2307 {
9fbdd100
DS
2308 if (debug)
2309 zlog_debug("%s: path %s is the bestpath, add to the multipath list",
2310 pfx_buf, ri->peer->host);
f4eeff72
DS
2311 bgp_mp_list_add (&mp_list, ri);
2312 continue;
2313 }
2314
2315 if (BGP_INFO_HOLDDOWN (ri))
2316 continue;
2317
2318 if (ri->peer &&
2319 ri->peer != bgp->peer_self &&
2320 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
2321 if (ri->peer->status != Established)
2322 continue;
2323
2324 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
2325 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
2326 continue;
2327
9fbdd100 2328 bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
f4eeff72
DS
2329
2330 if (paths_eq)
2331 {
9fbdd100
DS
2332 if (debug)
2333 zlog_debug("%s: %s path is equivalent to the bestpath, add to the multipath list",
2334 pfx_buf, ri->peer->host);
f4eeff72
DS
2335 bgp_mp_list_add (&mp_list, ri);
2336 }
2337 }
2338 }
fee0f4c6 2339
6918e74b
JB
2340 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
2341 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
96450faf 2342
0b597ef0 2343 bgp_info_mpath_aggregate_update (new_select, old_select);
96450faf
JB
2344 bgp_mp_list_clear (&mp_list);
2345
2346 result->old = old_select;
2347 result->new = new_select;
2348
2349 return;
fee0f4c6 2350}
2351
3f9c7369
DS
2352/*
2353 * A new route/change in bestpath of an existing route. Evaluate the path
2354 * for advertisement to the subgroup.
2355 */
2356int
2357subgroup_process_announce_selected (struct update_subgroup *subgrp,
2358 struct bgp_info *selected,
2359 struct bgp_node *rn)
9eda90ce 2360{
fee0f4c6 2361 struct prefix *p;
3f9c7369
DS
2362 struct peer_af *paf;
2363 struct peer *onlypeer;
558d1fec
JBD
2364 struct attr attr;
2365 struct attr_extra extra;
3f9c7369
DS
2366 afi_t afi;
2367 safi_t safi;
fee0f4c6 2368
2369 p = &rn->p;
3f9c7369
DS
2370 afi = SUBGRP_AFI(subgrp);
2371 safi = SUBGRP_SAFI(subgrp);
2372 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
2373 (SUBGRP_PFIRST(subgrp))->peer : NULL);
718e3744 2374
9eda90ce 2375 /* First update is deferred until ORF or ROUTE-REFRESH is received */
3f9c7369
DS
2376 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
2377 PEER_STATUS_ORF_WAIT_REFRESH))
fee0f4c6 2378 return 0;
718e3744 2379
558d1fec
JBD
2380 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2381 attr.extra = &extra;
2382
67174041 2383 switch (bgp_node_table (rn)->type)
fee0f4c6 2384 {
2385 case BGP_TABLE_MAIN:
3f9c7369 2386 /* Announcement to the subgroup. If the route is filtered,
718e3744 2387 withdraw it. */
3f9c7369
DS
2388 if (selected && subgroup_announce_check(selected, subgrp, p, &attr))
2389 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
fee0f4c6 2390 else
3f9c7369
DS
2391 bgp_adj_out_unset_subgroup(rn, subgrp);
2392
fee0f4c6 2393 break;
2394 case BGP_TABLE_RSCLIENT:
3f9c7369 2395 /* Announcement to peer->conf. If the route is filtered,
fee0f4c6 2396 withdraw it. */
3f9c7369
DS
2397 if (selected &&
2398 subgroup_announce_check_rsclient (selected, subgrp, p, &attr))
2399 bgp_adj_out_set_subgroup (rn, subgrp, &attr, selected);
9eda90ce 2400 else
3f9c7369 2401 bgp_adj_out_unset_subgroup(rn, subgrp);
fee0f4c6 2402 break;
2403 }
558d1fec 2404
fee0f4c6 2405 return 0;
200df115 2406}
fee0f4c6 2407
3f9c7369 2408struct bgp_process_queue
fee0f4c6 2409{
200df115 2410 struct bgp *bgp;
2411 struct bgp_node *rn;
2412 afi_t afi;
2413 safi_t safi;
2414};
2415
2416static wq_item_status
0fb58d5d 2417bgp_process_rsclient (struct work_queue *wq, void *data)
200df115 2418{
0fb58d5d 2419 struct bgp_process_queue *pq = data;
200df115 2420 struct bgp *bgp = pq->bgp;
2421 struct bgp_node *rn = pq->rn;
2422 afi_t afi = pq->afi;
2423 safi_t safi = pq->safi;
fee0f4c6 2424 struct bgp_info *new_select;
2425 struct bgp_info *old_select;
2426 struct bgp_info_pair old_and_new;
1eb8ef25 2427 struct listnode *node, *nnode;
cb1faec9 2428 struct peer *rsclient;
3f9c7369
DS
2429 struct peer_af *paf;
2430 struct update_subgroup *subgrp;
cb1faec9
DS
2431
2432 /* Is it end of initial update? (after startup) */
2433 if (!rn)
2434 {
4a16ae86
DS
2435 /* This is just to keep the display sane in case all the peers are
2436 rsclients only */
2437 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
2438 sizeof(bgp->update_delay_zebra_resume_time));
2439
2440 bgp->rsclient_peers_update_hold = 0;
cb1faec9
DS
2441 bgp_start_routeadv(bgp);
2442 return WQ_SUCCESS;
2443 }
2444
2445 rsclient = bgp_node_table (rn)->owner;
2446
fee0f4c6 2447 /* Best path selection. */
96450faf 2448 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 2449 new_select = old_and_new.new;
2450 old_select = old_and_new.old;
2451
200df115 2452 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
2453 {
228da428
CC
2454 if (rsclient->group)
2455 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
2456 {
2457 /* Nothing to do. */
2458 if (old_select && old_select == new_select)
2459 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
2460 continue;
2461
2462 if (old_select)
2463 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
2464 if (new_select)
2465 {
2466 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
2467 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d
JB
2468 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
2469 }
228da428 2470
3f9c7369
DS
2471 paf = peer_af_find(rsclient, afi, safi);
2472 assert(paf);
2473 subgrp = PAF_SUBGRP(paf);
2474 if (!subgrp) /* not an established session */
2475 continue;
2476 subgroup_process_announce_selected (subgrp, new_select, rn);
228da428 2477 }
200df115 2478 }
2479 else
2480 {
b7395791 2481 if (old_select)
1a392d46 2482 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
b7395791 2483 if (new_select)
2484 {
1a392d46
PJ
2485 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
2486 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 2487 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
b7395791 2488 }
3f9c7369
DS
2489 paf = peer_af_find(rsclient, afi, safi);
2490 if (paf && (subgrp = PAF_SUBGRP(paf))) /* if an established session */
2491 subgroup_process_announce_selected (subgrp, new_select, rn);
200df115 2492 }
2493
b40d939b 2494 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
2495 bgp_info_reap (rn, old_select);
3f9c7369 2496
200df115 2497 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2498 return WQ_SUCCESS;
fee0f4c6 2499}
2500
200df115 2501static wq_item_status
0fb58d5d 2502bgp_process_main (struct work_queue *wq, void *data)
200df115 2503{
0fb58d5d 2504 struct bgp_process_queue *pq = data;
200df115 2505 struct bgp *bgp = pq->bgp;
2506 struct bgp_node *rn = pq->rn;
2507 afi_t afi = pq->afi;
2508 safi_t safi = pq->safi;
2509 struct prefix *p = &rn->p;
fee0f4c6 2510 struct bgp_info *new_select;
2511 struct bgp_info *old_select;
2512 struct bgp_info_pair old_and_new;
1eb8ef25 2513 struct listnode *node, *nnode;
fee0f4c6 2514 struct peer *peer;
cb1faec9
DS
2515
2516 /* Is it end of initial update? (after startup) */
2517 if (!rn)
2518 {
4a16ae86
DS
2519 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
2520 sizeof(bgp->update_delay_zebra_resume_time));
2521
2522 bgp->main_zebra_update_hold = 0;
2523 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2524 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2525 {
2526 bgp_zebra_announce_table(bgp, afi, safi);
2527 }
2528 bgp->main_peers_update_hold = 0;
2529
cb1faec9
DS
2530 bgp_start_routeadv(bgp);
2531 return WQ_SUCCESS;
2532 }
2533
fee0f4c6 2534 /* Best path selection. */
96450faf 2535 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 2536 old_select = old_and_new.old;
2537 new_select = old_and_new.new;
2538
2539 /* Nothing to do. */
8ad7271d 2540 if (old_select && old_select == new_select && !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR))
fee0f4c6 2541 {
2542 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
200df115 2543 {
8196f13d
JB
2544 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
2545 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
73ac8160 2546 bgp_zebra_announce (p, old_select, bgp, afi, safi);
200df115 2547
8196f13d 2548 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
200df115 2549 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2550 return WQ_SUCCESS;
2551 }
fee0f4c6 2552 }
2553
8ad7271d
DS
2554 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
2555 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
2556
3f9c7369
DS
2557 /* bestpath has changed; bump version */
2558 if (old_select || new_select)
0de4848d
DS
2559 {
2560 bgp_bump_version(rn);
2561
2562 if (!bgp->t_rmap_def_originate_eval)
2563 {
2564 bgp_lock (bgp);
2565 THREAD_TIMER_ON(master, bgp->t_rmap_def_originate_eval,
2566 update_group_refresh_default_originate_route_map,
2567 bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER);
2568 }
2569 }
3f9c7369 2570
338b3424 2571 if (old_select)
1a392d46 2572 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
338b3424 2573 if (new_select)
2574 {
1a392d46
PJ
2575 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
2576 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 2577 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
338b3424 2578 }
2579
3f9c7369 2580 group_announce_route(bgp, afi, safi, rn, new_select);
718e3744 2581
2582 /* FIB update. */
5a616c08
B
2583 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
2584 ! bgp_option_check (BGP_OPT_NO_FIB)))
718e3744 2585 {
2586 if (new_select
2587 && new_select->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
2588 && (new_select->sub_type == BGP_ROUTE_NORMAL ||
2589 new_select->sub_type == BGP_ROUTE_AGGREGATE))
73ac8160 2590 bgp_zebra_announce (p, new_select, bgp, afi, safi);
718e3744 2591 else
2592 {
2593 /* Withdraw the route from the kernel. */
2594 if (old_select
2595 && old_select->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
2596 && (old_select->sub_type == BGP_ROUTE_NORMAL ||
2597 old_select->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 2598 bgp_zebra_withdraw (p, old_select, safi);
718e3744 2599 }
2600 }
b40d939b 2601
2602 /* Reap old select bgp_info, it it has been removed */
2603 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
2604 bgp_info_reap (rn, old_select);
2605
200df115 2606 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2607 return WQ_SUCCESS;
718e3744 2608}
2609
200df115 2610static void
0fb58d5d 2611bgp_processq_del (struct work_queue *wq, void *data)
200df115 2612{
0fb58d5d 2613 struct bgp_process_queue *pq = data;
cb1faec9
DS
2614 struct bgp_table *table;
2615
228da428 2616 bgp_unlock (pq->bgp);
cb1faec9
DS
2617 if (pq->rn)
2618 {
2619 table = bgp_node_table (pq->rn);
2620 bgp_unlock_node (pq->rn);
2621 bgp_table_unlock (table);
2622 }
200df115 2623 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
2624}
2625
f188f2c4 2626void
200df115 2627bgp_process_queue_init (void)
2628{
2629 bm->process_main_queue
2630 = work_queue_new (bm->master, "process_main_queue");
2631 bm->process_rsclient_queue
2632 = work_queue_new (bm->master, "process_rsclient_queue");
2633
2634 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
2635 {
2636 zlog_err ("%s: Failed to allocate work queue", __func__);
2637 exit (1);
2638 }
2639
2640 bm->process_main_queue->spec.workfunc = &bgp_process_main;
200df115 2641 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
838bbde0
PJ
2642 bm->process_main_queue->spec.max_retries = 0;
2643 bm->process_main_queue->spec.hold = 50;
d889623f
DS
2644 /* Use a higher yield value of 50ms for main queue processing */
2645 bm->process_main_queue->spec.yield = 50 * 1000L;
838bbde0
PJ
2646
2647 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
2648 sizeof (struct work_queue *));
2649 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
200df115 2650}
2651
2652void
fee0f4c6 2653bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
2654{
200df115 2655 struct bgp_process_queue *pqnode;
2656
2657 /* already scheduled for processing? */
2658 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
2659 return;
2660
2661 if ( (bm->process_main_queue == NULL) ||
2662 (bm->process_rsclient_queue == NULL) )
2663 bgp_process_queue_init ();
2664
2665 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2666 sizeof (struct bgp_process_queue));
2667 if (!pqnode)
2668 return;
228da428
CC
2669
2670 /* all unlocked in bgp_processq_del */
67174041 2671 bgp_table_lock (bgp_node_table (rn));
228da428 2672 pqnode->rn = bgp_lock_node (rn);
200df115 2673 pqnode->bgp = bgp;
228da428 2674 bgp_lock (bgp);
200df115 2675 pqnode->afi = afi;
2676 pqnode->safi = safi;
2677
67174041 2678 switch (bgp_node_table (rn)->type)
fee0f4c6 2679 {
200df115 2680 case BGP_TABLE_MAIN:
2681 work_queue_add (bm->process_main_queue, pqnode);
2682 break;
2683 case BGP_TABLE_RSCLIENT:
2684 work_queue_add (bm->process_rsclient_queue, pqnode);
2685 break;
fee0f4c6 2686 }
200df115 2687
07ff4dc4 2688 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
200df115 2689 return;
fee0f4c6 2690}
0a486e5f 2691
cb1faec9
DS
2692void
2693bgp_add_eoiu_mark (struct bgp *bgp, bgp_table_t type)
2694{
2695 struct bgp_process_queue *pqnode;
2696
2697 if ( (bm->process_main_queue == NULL) ||
2698 (bm->process_rsclient_queue == NULL) )
2699 bgp_process_queue_init ();
2700
2701 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2702 sizeof (struct bgp_process_queue));
2703 if (!pqnode)
2704 return;
2705
2706 pqnode->rn = NULL;
2707 pqnode->bgp = bgp;
2708 bgp_lock (bgp);
2709 switch (type)
2710 {
2711 case BGP_TABLE_MAIN:
2712 work_queue_add (bm->process_main_queue, pqnode);
2713 break;
2714 case BGP_TABLE_RSCLIENT:
2715 work_queue_add (bm->process_rsclient_queue, pqnode);
2716 break;
2717 }
2718
2719 return;
2720}
2721
94f2b392 2722static int
0a486e5f 2723bgp_maximum_prefix_restart_timer (struct thread *thread)
2724{
2725 struct peer *peer;
2726
2727 peer = THREAD_ARG (thread);
2728 peer->t_pmax_restart = NULL;
2729
16286195 2730 if (bgp_debug_neighbor_events(peer))
0a486e5f 2731 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
2732 peer->host);
2733
1ff9a340 2734 peer_clear (peer, NULL);
0a486e5f 2735
2736 return 0;
2737}
2738
718e3744 2739int
5228ad27 2740bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
2741 safi_t safi, int always)
718e3744 2742{
e0701b79 2743 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
2744 return 0;
2745
2746 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
718e3744 2747 {
e0701b79 2748 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
2749 && ! always)
2750 return 0;
2751
16286195
DS
2752 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
2753 "limit %ld", afi_safi_print (afi, safi), peer->host,
2754 peer->pcount[afi][safi], peer->pmax[afi][safi]);
e0701b79 2755 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2756
2757 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
2758 return 0;
2759
2760 {
5228ad27 2761 u_int8_t ndata[7];
e0701b79 2762
2763 if (safi == SAFI_MPLS_VPN)
42e6d745 2764 safi = SAFI_MPLS_LABELED_VPN;
5228ad27 2765
2766 ndata[0] = (afi >> 8);
2767 ndata[1] = afi;
2768 ndata[2] = safi;
2769 ndata[3] = (peer->pmax[afi][safi] >> 24);
2770 ndata[4] = (peer->pmax[afi][safi] >> 16);
2771 ndata[5] = (peer->pmax[afi][safi] >> 8);
2772 ndata[6] = (peer->pmax[afi][safi]);
e0701b79 2773
2774 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
2775 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
2776 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
2777 }
0a486e5f 2778
f14e6fdb
DS
2779 /* Dynamic peers will just close their connection. */
2780 if (peer_dynamic_neighbor (peer))
2781 return 1;
2782
0a486e5f 2783 /* restart timer start */
2784 if (peer->pmax_restart[afi][safi])
2785 {
2786 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
2787
16286195 2788 if (bgp_debug_neighbor_events(peer))
0a486e5f 2789 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2790 peer->host, peer->v_pmax_restart);
2791
2792 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2793 peer->v_pmax_restart);
2794 }
2795
e0701b79 2796 return 1;
2797 }
2798 else
2799 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2800
2801 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2802 {
2803 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2804 && ! always)
2805 return 0;
2806
16286195
DS
2807 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2808 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2809 peer->pmax[afi][safi]);
e0701b79 2810 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2811 }
e0701b79 2812 else
2813 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2814 return 0;
2815}
2816
b40d939b 2817/* Unconditionally remove the route from the RIB, without taking
2818 * damping into consideration (eg, because the session went down)
2819 */
94f2b392 2820static void
718e3744 2821bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2822 afi_t afi, safi_t safi)
2823{
902212c3 2824 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2825
2826 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2827 bgp_info_delete (rn, ri); /* keep historical info */
2828
b40d939b 2829 bgp_process (peer->bgp, rn, afi, safi);
718e3744 2830}
2831
94f2b392 2832static void
718e3744 2833bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
b40d939b 2834 afi_t afi, safi_t safi)
718e3744 2835{
718e3744 2836 int status = BGP_DAMP_NONE;
2837
b40d939b 2838 /* apply dampening, if result is suppressed, we'll be retaining
2839 * the bgp_info in the RIB for historical reference.
2840 */
2841 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2842 && peer->sort == BGP_PEER_EBGP)
b40d939b 2843 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2844 == BGP_DAMP_SUPPRESSED)
902212c3 2845 {
902212c3 2846 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2847 return;
2848 }
2849
2850 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 2851}
2852
fb018d25 2853static struct bgp_info *
7c8ff89e 2854info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
fb018d25
DS
2855 struct bgp_node *rn)
2856{
2857 struct bgp_info *new;
2858
2859 /* Make new BGP info. */
2860 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2861 new->type = type;
7c8ff89e 2862 new->instance = instance;
fb018d25
DS
2863 new->sub_type = sub_type;
2864 new->peer = peer;
2865 new->attr = attr;
2866 new->uptime = bgp_clock ();
2867 new->net = rn;
2868 return new;
2869}
2870
94f2b392 2871static void
cd808e74
DS
2872bgp_info_addpath_rx_str(struct bgp_info *ri, char *buf)
2873{
2874 if (ri && ri->addpath_rx_id)
2875 sprintf(buf, " with addpath ID %d", ri->addpath_rx_id);
2876 else
2877 sprintf(buf, "");
2878}
2879
2880static void
2881bgp_update_rsclient (struct peer *rsclient, u_int32_t addpath_id,
2882 afi_t afi, safi_t safi, struct attr *attr,
2883 struct peer *peer, struct prefix *p, int type,
2884 int sub_type, struct prefix_rd *prd, u_char *tag)
fee0f4c6 2885{
2886 struct bgp_node *rn;
2887 struct bgp *bgp;
558d1fec
JBD
2888 struct attr new_attr;
2889 struct attr_extra new_extra;
fee0f4c6 2890 struct attr *attr_new;
2891 struct attr *attr_new2;
2892 struct bgp_info *ri;
2893 struct bgp_info *new;
fd79ac91 2894 const char *reason;
fee0f4c6 2895 char buf[SU_ADDRSTRLEN];
cd808e74 2896 char buf2[30];
fee0f4c6 2897
2898 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
2899 if (peer == rsclient)
2900 return;
2901
2902 bgp = peer->bgp;
2903 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2904
2905 /* Check previously received route. */
2906 for (ri = rn->info; ri; ri = ri->next)
cd808e74
DS
2907 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2908 ri->addpath_rx_id == addpath_id)
fee0f4c6 2909 break;
2910
2911 /* AS path loop check. */
000e157c 2912 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
fee0f4c6 2913 {
2914 reason = "as-path contains our own AS;";
2915 goto filtered;
2916 }
2917
2918 /* Route reflector originator ID check. */
2919 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 2920 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
fee0f4c6 2921 {
2922 reason = "originator is us;";
2923 goto filtered;
2924 }
fb982c25 2925
558d1fec 2926 new_attr.extra = &new_extra;
fb982c25 2927 bgp_attr_dup (&new_attr, attr);
fee0f4c6 2928
2929 /* Apply export policy. */
2930 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
2931 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
2932 {
2933 reason = "export-policy;";
2934 goto filtered;
2935 }
2936
2937 attr_new2 = bgp_attr_intern (&new_attr);
fb982c25 2938
fee0f4c6 2939 /* Apply import policy. */
2940 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
2941 {
f6f434b2 2942 bgp_attr_unintern (&attr_new2);
fee0f4c6 2943
2944 reason = "import-policy;";
2945 goto filtered;
2946 }
2947
2948 attr_new = bgp_attr_intern (&new_attr);
f6f434b2 2949 bgp_attr_unintern (&attr_new2);
fee0f4c6 2950
2951 /* IPv4 unicast next hop check. */
5a616c08 2952 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
fee0f4c6 2953 {
733cd9e5 2954 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
fee0f4c6 2955 if (new_attr.nexthop.s_addr == 0
733cd9e5 2956 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
fee0f4c6 2957 {
f6f434b2 2958 bgp_attr_unintern (&attr_new);
fee0f4c6 2959
2960 reason = "martian next-hop;";
2961 goto filtered;
2962 }
2963 }
558d1fec 2964
fee0f4c6 2965 /* If the update is implicit withdraw. */
2966 if (ri)
2967 {
65957886 2968 ri->uptime = bgp_clock ();
fee0f4c6 2969
2970 /* Same attribute comes in. */
16d2e241
PJ
2971 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
2972 && attrhash_cmp (ri->attr, attr_new))
fee0f4c6 2973 {
2974
3f9c7369 2975 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2976 {
2977 bgp_info_addpath_rx_str(ri, buf2);
2978 zlog_debug ("%s rcvd %s/%d%s for RS-client %s...duplicate ignored",
2979 peer->host,
2980 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2981 p->prefixlen, buf2, rsclient->host);
2982 }
fee0f4c6 2983
228da428 2984 bgp_unlock_node (rn);
f6f434b2 2985 bgp_attr_unintern (&attr_new);
fee0f4c6 2986
228da428 2987 return;
fee0f4c6 2988 }
2989
16d2e241
PJ
2990 /* Withdraw/Announce before we fully processed the withdraw */
2991 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2992 bgp_info_restore (rn, ri);
2993
fee0f4c6 2994 /* Received Logging. */
3f9c7369 2995 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2996 {
2997 bgp_info_addpath_rx_str(ri, buf2);
2998 zlog_debug ("%s rcvd %s/%d%s for RS-client %s",
2999 peer->host,
3000 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3001 p->prefixlen, buf2, rsclient->host);
3002 }
fee0f4c6 3003
3004 /* The attribute is changed. */
1a392d46 3005 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
fee0f4c6 3006
3007 /* Update to new attribute. */
f6f434b2 3008 bgp_attr_unintern (&ri->attr);
fee0f4c6 3009 ri->attr = attr_new;
3010
3011 /* Update MPLS tag. */
3012 if (safi == SAFI_MPLS_VPN)
fb982c25 3013 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
fee0f4c6 3014
1a392d46 3015 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
fee0f4c6 3016
3017 /* Process change. */
3018 bgp_process (bgp, rn, afi, safi);
3019 bgp_unlock_node (rn);
3020
3021 return;
3022 }
3023
3024 /* Received Logging. */
3f9c7369 3025 if (bgp_debug_update(peer, p, NULL, 1))
fee0f4c6 3026 {
cd808e74
DS
3027 bgp_info_addpath_rx_str(ri, buf2);
3028 zlog_debug ("%s rcvd %s/%d%s for RS-client %s",
16286195
DS
3029 peer->host,
3030 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 3031 p->prefixlen, buf2, rsclient->host);
fee0f4c6 3032 }
3033
7c8ff89e 3034 new = info_make(type, sub_type, 0, peer, attr_new, rn);
fee0f4c6 3035
3036 /* Update MPLS tag. */
3037 if (safi == SAFI_MPLS_VPN)
fb982c25 3038 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
fee0f4c6 3039
1a392d46 3040 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
fee0f4c6 3041
3042 /* Register new BGP information. */
3043 bgp_info_add (rn, new);
200df115 3044
3045 /* route_node_get lock */
3046 bgp_unlock_node (rn);
3047
fee0f4c6 3048 /* Process change. */
3049 bgp_process (bgp, rn, afi, safi);
558d1fec 3050
fee0f4c6 3051 return;
3052
3053 filtered:
3054
3055 /* This BGP update is filtered. Log the reason then update BGP entry. */
3f9c7369 3056 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
3057 {
3058 bgp_info_addpath_rx_str(ri, buf2);
3059 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED for RS-client %s due to: %s",
3060 peer->host,
3061 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3062 p->prefixlen, buf2, rsclient->host, reason);
3063 }
fee0f4c6 3064
3065 if (ri)
b40d939b 3066 bgp_rib_remove (rn, ri, peer, afi, safi);
fee0f4c6 3067
3068 bgp_unlock_node (rn);
558d1fec 3069
fee0f4c6 3070 return;
3071}
3072
94f2b392 3073static void
cd808e74
DS
3074bgp_withdraw_rsclient (struct peer *rsclient, u_int32_t addpath_id,
3075 afi_t afi, safi_t safi, struct peer *peer,
3076 struct prefix *p, int type, int sub_type,
3077 struct prefix_rd *prd, u_char *tag)
228da428 3078{
fee0f4c6 3079 struct bgp_node *rn;
3080 struct bgp_info *ri;
3081 char buf[SU_ADDRSTRLEN];
3082
3083 if (rsclient == peer)
228da428 3084 return;
fee0f4c6 3085
3086 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
3087
3088 /* Lookup withdrawn route. */
3089 for (ri = rn->info; ri; ri = ri->next)
cd808e74
DS
3090 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
3091 ri->addpath_rx_id == addpath_id)
fee0f4c6 3092 break;
3093
3094 /* Withdraw specified route from routing table. */
3095 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
b40d939b 3096 bgp_rib_withdraw (rn, ri, peer, afi, safi);
3f9c7369 3097 else if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
3098 zlog_debug ("%s Can't find the route %s/%d", peer->host,
3099 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3100 p->prefixlen);
fee0f4c6 3101
3102 /* Unlock bgp_node_get() lock. */
228da428
CC
3103 bgp_unlock_node (rn);
3104}
fee0f4c6 3105
94f2b392 3106static int
a82478b9
DS
3107bgp_update_main (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
3108 struct attr *attr, afi_t afi, safi_t safi, int type,
3109 int sub_type, struct prefix_rd *prd, u_char *tag,
3110 int soft_reconfig)
718e3744 3111{
3112 int ret;
3113 int aspath_loop_count = 0;
3114 struct bgp_node *rn;
3115 struct bgp *bgp;
558d1fec
JBD
3116 struct attr new_attr;
3117 struct attr_extra new_extra;
718e3744 3118 struct attr *attr_new;
3119 struct bgp_info *ri;
3120 struct bgp_info *new;
fd79ac91 3121 const char *reason;
718e3744 3122 char buf[SU_ADDRSTRLEN];
cd808e74 3123 char buf2[30];
fc9a856f 3124 int connected = 0;
718e3744 3125
3126 bgp = peer->bgp;
fee0f4c6 3127 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
fb982c25 3128
718e3744 3129 /* When peer's soft reconfiguration enabled. Record input packet in
3130 Adj-RIBs-In. */
343aa822
JBD
3131 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
3132 && peer != bgp->peer_self)
43143c8f 3133 bgp_adj_in_set (rn, peer, attr, addpath_id);
718e3744 3134
3135 /* Check previously received route. */
3136 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
3137 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
3138 ri->addpath_rx_id == addpath_id)
718e3744 3139 break;
3140
3141 /* AS path local-as loop check. */
3142 if (peer->change_local_as)
3143 {
3144 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
3145 aspath_loop_count = 1;
3146
3147 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
3148 {
3149 reason = "as-path contains our own AS;";
3150 goto filtered;
3151 }
3152 }
3153
3154 /* AS path loop check. */
3155 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
3156 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
3157 && aspath_loop_check(attr->aspath, bgp->confed_id)
3158 > peer->allowas_in[afi][safi]))
3159 {
3160 reason = "as-path contains our own AS;";
3161 goto filtered;
3162 }
3163
3164 /* Route reflector originator ID check. */
3165 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 3166 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
718e3744 3167 {
3168 reason = "originator is us;";
3169 goto filtered;
3170 }
3171
3172 /* Route reflector cluster ID check. */
3173 if (bgp_cluster_filter (peer, attr))
3174 {
3175 reason = "reflected from the same cluster;";
3176 goto filtered;
3177 }
3178
3179 /* Apply incoming filter. */
3180 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
3181 {
3182 reason = "filter;";
3183 goto filtered;
3184 }
3185
558d1fec 3186 new_attr.extra = &new_extra;
fb982c25 3187 bgp_attr_dup (&new_attr, attr);
718e3744 3188
c460e572
DL
3189 /* Apply incoming route-map.
3190 * NB: new_attr may now contain newly allocated values from route-map "set"
3191 * commands, so we need bgp_attr_flush in the error paths, until we intern
3192 * the attr (which takes over the memory references) */
0b16f239 3193 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
718e3744 3194 {
3195 reason = "route-map;";
c460e572 3196 bgp_attr_flush (&new_attr);
718e3744 3197 goto filtered;
3198 }
3199
3200 /* IPv4 unicast next hop check. */
3201 if (afi == AFI_IP && safi == SAFI_UNICAST)
3202 {
733cd9e5 3203 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
718e3744 3204 must not be my own address. */
10f9bf3f
JBD
3205 if (new_attr.nexthop.s_addr == 0
3206 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
3207 || bgp_nexthop_self (&new_attr))
718e3744 3208 {
3209 reason = "martian next-hop;";
c460e572 3210 bgp_attr_flush (&new_attr);
718e3744 3211 goto filtered;
3212 }
3213 }
3214
3215 attr_new = bgp_attr_intern (&new_attr);
3216
3217 /* If the update is implicit withdraw. */
3218 if (ri)
3219 {
65957886 3220 ri->uptime = bgp_clock ();
718e3744 3221
3222 /* Same attribute comes in. */
16d2e241
PJ
3223 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
3224 && attrhash_cmp (ri->attr, attr_new))
718e3744 3225 {
718e3744 3226 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 3227 && peer->sort == BGP_PEER_EBGP
718e3744 3228 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
3229 {
3f9c7369 3230 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
3231 {
3232 bgp_info_addpath_rx_str(ri, buf2);
3233 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
3234 peer->host,
3235 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74
DS
3236 p->prefixlen, buf2);
3237 }
718e3744 3238
902212c3 3239 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
3240 {
3241 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3242 bgp_process (bgp, rn, afi, safi);
3243 }
718e3744 3244 }
16d2e241 3245 else /* Duplicate - odd */
718e3744 3246 {
3f9c7369 3247 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
3248 {
3249 if (!peer->rcvd_attr_printed)
3250 {
3251 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
3252 peer->rcvd_attr_printed = 1;
3253 }
3254
cd808e74
DS
3255 bgp_info_addpath_rx_str(ri, buf2);
3256 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
16286195
DS
3257 peer->host,
3258 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 3259 p->prefixlen, buf2);
16286195 3260 }
93406d87 3261
3262 /* graceful restart STALE flag unset. */
3263 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3264 {
1a392d46 3265 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
902212c3 3266 bgp_process (bgp, rn, afi, safi);
93406d87 3267 }
718e3744 3268 }
3269
3270 bgp_unlock_node (rn);
f6f434b2 3271 bgp_attr_unintern (&attr_new);
558d1fec 3272
718e3744 3273 return 0;
3274 }
3275
16d2e241
PJ
3276 /* Withdraw/Announce before we fully processed the withdraw */
3277 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3278 {
3f9c7369 3279 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
3280 {
3281 bgp_info_addpath_rx_str(ri, buf2);
3282 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
3283 peer->host,
3284 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3285 p->prefixlen, buf2);
3286 }
16d2e241
PJ
3287 bgp_info_restore (rn, ri);
3288 }
3289
718e3744 3290 /* Received Logging. */
3f9c7369 3291 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
3292 {
3293 bgp_info_addpath_rx_str(ri, buf2);
3294 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
3295 peer->host,
3296 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74
DS
3297 p->prefixlen, buf2);
3298 }
718e3744 3299
93406d87 3300 /* graceful restart STALE flag unset. */
3301 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1a392d46 3302 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
93406d87 3303
718e3744 3304 /* The attribute is changed. */
1a392d46 3305 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
902212c3 3306
3307 /* implicit withdraw, decrement aggregate and pcount here.
3308 * only if update is accepted, they'll increment below.
3309 */
902212c3 3310 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3311
718e3744 3312 /* Update bgp route dampening information. */
3313 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 3314 && peer->sort == BGP_PEER_EBGP)
718e3744 3315 {
3316 /* This is implicit withdraw so we should update dampening
3317 information. */
3318 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
3319 bgp_damp_withdraw (ri, rn, afi, safi, 1);
718e3744 3320 }
3321
718e3744 3322 /* Update to new attribute. */
f6f434b2 3323 bgp_attr_unintern (&ri->attr);
718e3744 3324 ri->attr = attr_new;
3325
3326 /* Update MPLS tag. */
3327 if (safi == SAFI_MPLS_VPN)
fb982c25 3328 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
718e3744 3329
3330 /* Update bgp route dampening information. */
3331 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 3332 && peer->sort == BGP_PEER_EBGP)
718e3744 3333 {
3334 /* Now we do normal update dampening. */
3335 ret = bgp_damp_update (ri, rn, afi, safi);
3336 if (ret == BGP_DAMP_SUPPRESSED)
3337 {
3338 bgp_unlock_node (rn);
3339 return 0;
3340 }
3341 }
3342
3343 /* Nexthop reachability check. */
fc9a856f 3344 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
718e3744 3345 {
fc9a856f 3346 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
907f92c8
DS
3347 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
3348 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
fc9a856f
DS
3349 connected = 1;
3350 else
3351 connected = 0;
3352
75aead62 3353 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
1a392d46 3354 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 3355 else
fc9a856f
DS
3356 {
3357 if (BGP_DEBUG(nht, NHT))
3358 {
3359 char buf1[INET6_ADDRSTRLEN];
3360 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
3361 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3362 }
3363 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3364 }
718e3744 3365 }
3366 else
fc9a856f 3367 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 3368
3369 /* Process change. */
3370 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3371
3372 bgp_process (bgp, rn, afi, safi);
3373 bgp_unlock_node (rn);
558d1fec 3374
718e3744 3375 return 0;
a82478b9 3376 } // End of implicit withdraw
718e3744 3377
3378 /* Received Logging. */
3f9c7369 3379 if (bgp_debug_update(peer, p, NULL, 1))
718e3744 3380 {
16286195
DS
3381 if (!peer->rcvd_attr_printed)
3382 {
3383 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
3384 peer->rcvd_attr_printed = 1;
3385 }
3386
cd808e74
DS
3387 bgp_info_addpath_rx_str(ri, buf2);
3388 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
3389 peer->host,
3390 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 3391 p->prefixlen, buf2);
718e3744 3392 }
3393
718e3744 3394 /* Make new BGP info. */
7c8ff89e 3395 new = info_make(type, sub_type, 0, peer, attr_new, rn);
718e3744 3396
3397 /* Update MPLS tag. */
3398 if (safi == SAFI_MPLS_VPN)
fb982c25 3399 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
718e3744 3400
3401 /* Nexthop reachability check. */
fc9a856f
DS
3402 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
3403 {
3404 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
907f92c8
DS
3405 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
3406 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
fc9a856f
DS
3407 connected = 1;
3408 else
3409 connected = 0;
3410
75aead62 3411 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
1a392d46 3412 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 3413 else
fc9a856f
DS
3414 {
3415 if (BGP_DEBUG(nht, NHT))
3416 {
3417 char buf1[INET6_ADDRSTRLEN];
3418 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
3419 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3420 }
3421 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3422 }
718e3744 3423 }
3424 else
1a392d46 3425 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 3426
a82478b9
DS
3427 /* Addpath ID */
3428 new->addpath_rx_id = addpath_id;
3429 new->addpath_tx_id = 0;
3430
902212c3 3431 /* Increment prefix */
718e3744 3432 bgp_aggregate_increment (bgp, p, new, afi, safi);
3433
3434 /* Register new BGP information. */
3435 bgp_info_add (rn, new);
200df115 3436
3437 /* route_node_get lock */
3438 bgp_unlock_node (rn);
558d1fec 3439
718e3744 3440 /* If maximum prefix count is configured and current prefix
3441 count exeed it. */
e0701b79 3442 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
3443 return -1;
718e3744 3444
3445 /* Process change. */
3446 bgp_process (bgp, rn, afi, safi);
3447
3448 return 0;
3449
3450 /* This BGP update is filtered. Log the reason then update BGP
3451 entry. */
3452 filtered:
3f9c7369 3453 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
3454 {
3455 if (!peer->rcvd_attr_printed)
3456 {
3457 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
3458 peer->rcvd_attr_printed = 1;
3459 }
3460
cd808e74
DS
3461 bgp_info_addpath_rx_str(ri, buf2);
3462 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
16286195
DS
3463 peer->host,
3464 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 3465 p->prefixlen, buf2, reason);
16286195 3466 }
718e3744 3467
3468 if (ri)
b40d939b 3469 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 3470
3471 bgp_unlock_node (rn);
558d1fec 3472
718e3744 3473 return 0;
3474}
3475
fee0f4c6 3476int
a82478b9
DS
3477bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
3478 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
fee0f4c6 3479 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
3480{
3481 struct peer *rsclient;
1eb8ef25 3482 struct listnode *node, *nnode;
fee0f4c6 3483 struct bgp *bgp;
3484 int ret;
3485
a82478b9
DS
3486 ret = bgp_update_main (peer, p, addpath_id, attr, afi, safi, type, sub_type,
3487 prd, tag, soft_reconfig);
fee0f4c6 3488
3489 bgp = peer->bgp;
3490
3491 /* Process the update for each RS-client. */
1eb8ef25 3492 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 3493 {
3494 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
cd808e74 3495 bgp_update_rsclient (rsclient, addpath_id, afi, safi, attr, peer, p,
a82478b9 3496 type, sub_type, prd, tag);
fee0f4c6 3497 }
3498
3499 return ret;
3500}
3501
718e3744 3502int
a82478b9
DS
3503bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
3504 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
3505 struct prefix_rd *prd, u_char *tag)
718e3744 3506{
3507 struct bgp *bgp;
3508 char buf[SU_ADDRSTRLEN];
cd808e74 3509 char buf2[30];
718e3744 3510 struct bgp_node *rn;
3511 struct bgp_info *ri;
fee0f4c6 3512 struct peer *rsclient;
1eb8ef25 3513 struct listnode *node, *nnode;
718e3744 3514
3515 bgp = peer->bgp;
3516
fee0f4c6 3517 /* Process the withdraw for each RS-client. */
1eb8ef25 3518 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 3519 {
3520 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
cd808e74 3521 bgp_withdraw_rsclient (rsclient, addpath_id, afi, safi, peer, p, type,
a82478b9 3522 sub_type, prd, tag);
fee0f4c6 3523 }
3524
718e3744 3525 /* Lookup node. */
fee0f4c6 3526 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 3527
3528 /* If peer is soft reconfiguration enabled. Record input packet for
3529 further calculation. */
3530 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
3531 && peer != bgp->peer_self)
43143c8f 3532 bgp_adj_in_unset (rn, peer, addpath_id);
718e3744 3533
3534 /* Lookup withdrawn route. */
3535 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
3536 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
3537 ri->addpath_rx_id == addpath_id)
718e3744 3538 break;
3539
cd808e74
DS
3540 /* Logging. */
3541 if (bgp_debug_update(peer, p, NULL, 1))
3542 {
3543 bgp_info_addpath_rx_str(ri, buf2);
3544 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
3545 peer->host,
3546 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3547 p->prefixlen, buf2);
3548 }
3549
718e3744 3550 /* Withdraw specified route from routing table. */
3551 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
b40d939b 3552 bgp_rib_withdraw (rn, ri, peer, afi, safi);
3f9c7369 3553 else if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
3554 zlog_debug ("%s Can't find the route %s/%d", peer->host,
3555 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3556 p->prefixlen);
718e3744 3557
3558 /* Unlock bgp_node_get() lock. */
3559 bgp_unlock_node (rn);
3560
3561 return 0;
3562}
6b0655a2 3563
718e3744 3564void
3565bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
3566{
3f9c7369
DS
3567 struct update_subgroup *subgrp;
3568 subgrp = peer_subgroup(peer, afi, safi);
3569 subgroup_default_originate(subgrp, withdraw);
3570}
6182d65b 3571
718e3744 3572
3f9c7369
DS
3573/*
3574 * bgp_stop_announce_route_timer
3575 */
3576void
3577bgp_stop_announce_route_timer (struct peer_af *paf)
3578{
3579 if (!paf->t_announce_route)
3580 return;
718e3744 3581
3f9c7369 3582 THREAD_TIMER_OFF (paf->t_announce_route);
718e3744 3583}
6b0655a2 3584
3f9c7369
DS
3585/*
3586 * bgp_announce_route_timer_expired
3587 *
3588 * Callback that is invoked when the route announcement timer for a
3589 * peer_af expires.
3590 */
3591static int
3592bgp_announce_route_timer_expired (struct thread *t)
718e3744 3593{
3f9c7369
DS
3594 struct peer_af *paf;
3595 struct peer *peer;
558d1fec 3596
718e3744 3597
3f9c7369
DS
3598 paf = THREAD_ARG (t);
3599 peer = paf->peer;
718e3744 3600
3f9c7369
DS
3601 assert (paf->t_announce_route);
3602 paf->t_announce_route = NULL;
558d1fec 3603
3f9c7369
DS
3604 if (peer->status != Established)
3605 return 0;
3606
3607 if (!peer->afc_nego[paf->afi][paf->safi])
3608 return 0;
3609
3610 peer_af_announce_route (paf, 1);
3611 return 0;
718e3744 3612}
3613
3f9c7369
DS
3614/*
3615 * bgp_announce_route
3616 *
3617 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
3618 */
718e3744 3619void
3620bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
3621{
3f9c7369
DS
3622 struct peer_af *paf;
3623 struct update_subgroup *subgrp;
718e3744 3624
3f9c7369
DS
3625 paf = peer_af_find (peer, afi, safi);
3626 if (!paf)
718e3744 3627 return;
3f9c7369 3628 subgrp = PAF_SUBGRP(paf);
718e3744 3629
3f9c7369
DS
3630 /*
3631 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
3632 * or a refresh has already been triggered.
3633 */
3634 if (!subgrp || paf->t_announce_route)
718e3744 3635 return;
3636
d889623f 3637 /*
3f9c7369
DS
3638 * Start a timer to stagger/delay the announce. This serves
3639 * two purposes - announcement can potentially be combined for
3640 * multiple peers and the announcement doesn't happen in the
3641 * vty context.
d889623f 3642 */
3f9c7369
DS
3643 THREAD_TIMER_MSEC_ON (master, paf->t_announce_route,
3644 bgp_announce_route_timer_expired, paf,
3645 (subgrp->peer_count == 1) ?
3646 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
3647 BGP_ANNOUNCE_ROUTE_DELAY_MS);
3648}
3649
3650/*
3651 * Announce routes from all AF tables to a peer.
3652 *
3653 * This should ONLY be called when there is a need to refresh the
3654 * routes to the peer based on a policy change for this peer alone
3655 * or a route refresh request received from the peer.
3656 * The operation will result in splitting the peer from its existing
3657 * subgroups and putting it in new subgroups.
3658 */
718e3744 3659void
3660bgp_announce_route_all (struct peer *peer)
3661{
3f9c7369
DS
3662 struct peer_af *paf;
3663 int af;
718e3744 3664 afi_t afi;
3665 safi_t safi;
3666
3667 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3668 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3669 bgp_announce_route (peer, afi, safi);
3670}
6b0655a2 3671
718e3744 3672static void
fee0f4c6 3673bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
8692c506 3674 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
fee0f4c6 3675{
3676 struct bgp_node *rn;
3677 struct bgp_adj_in *ain;
3678
3679 if (! table)
3680 table = rsclient->bgp->rib[afi][safi];
3681
3682 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3683 for (ain = rn->adj_in; ain; ain = ain->next)
3684 {
8692c506 3685 struct bgp_info *ri = rn->info;
d53d8fda 3686 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 3687
cd808e74
DS
3688 bgp_update_rsclient (rsclient, ri->addpath_rx_id, afi, safi, ain->attr,
3689 ain->peer, &rn->p, ZEBRA_ROUTE_BGP,
3690 BGP_ROUTE_NORMAL, prd, tag);
fee0f4c6 3691 }
3692}
3693
3694void
3695bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3696{
3697 struct bgp_table *table;
3698 struct bgp_node *rn;
3699
3700 if (safi != SAFI_MPLS_VPN)
8692c506 3701 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
fee0f4c6 3702
3703 else
3704 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
3705 rn = bgp_route_next (rn))
3706 if ((table = rn->info) != NULL)
8692c506
JBD
3707 {
3708 struct prefix_rd prd;
3709 prd.family = AF_UNSPEC;
3710 prd.prefixlen = 64;
3711 memcpy(&prd.val, rn->p.u.val, 8);
3712
3713 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
3714 }
fee0f4c6 3715}
6b0655a2 3716
fee0f4c6 3717static void
718e3744 3718bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
8692c506 3719 struct bgp_table *table, struct prefix_rd *prd)
718e3744 3720{
3721 int ret;
3722 struct bgp_node *rn;
3723 struct bgp_adj_in *ain;
3724
3725 if (! table)
3726 table = peer->bgp->rib[afi][safi];
3727
3728 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3729 for (ain = rn->adj_in; ain; ain = ain->next)
3730 {
3731 if (ain->peer == peer)
3732 {
8692c506 3733 struct bgp_info *ri = rn->info;
d53d8fda 3734 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 3735
43143c8f 3736 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
a82478b9 3737 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
d53d8fda 3738 prd, tag, 1);
8692c506 3739
718e3744 3740 if (ret < 0)
3741 {
3742 bgp_unlock_node (rn);
3743 return;
3744 }
718e3744 3745 }
3746 }
3747}
3748
3749void
3750bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
3751{
3752 struct bgp_node *rn;
3753 struct bgp_table *table;
3754
3755 if (peer->status != Established)
3756 return;
3757
3758 if (safi != SAFI_MPLS_VPN)
8692c506 3759 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
718e3744 3760 else
3761 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3762 rn = bgp_route_next (rn))
3763 if ((table = rn->info) != NULL)
8692c506
JBD
3764 {
3765 struct prefix_rd prd;
3766 prd.family = AF_UNSPEC;
3767 prd.prefixlen = 64;
3768 memcpy(&prd.val, rn->p.u.val, 8);
3769
3770 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
3771 }
718e3744 3772}
6b0655a2 3773
228da428
CC
3774
3775struct bgp_clear_node_queue
3776{
3777 struct bgp_node *rn;
3778 enum bgp_clear_route_type purpose;
3779};
3780
200df115 3781static wq_item_status
0fb58d5d 3782bgp_clear_route_node (struct work_queue *wq, void *data)
200df115 3783{
228da428
CC
3784 struct bgp_clear_node_queue *cnq = data;
3785 struct bgp_node *rn = cnq->rn;
64e580a7 3786 struct peer *peer = wq->spec.data;
718e3744 3787 struct bgp_info *ri;
67174041
AS
3788 afi_t afi = bgp_node_table (rn)->afi;
3789 safi_t safi = bgp_node_table (rn)->safi;
200df115 3790
64e580a7 3791 assert (rn && peer);
200df115 3792
43143c8f
DS
3793 /* It is possible that we have multiple paths for a prefix from a peer
3794 * if that peer is using AddPath.
3795 */
64e580a7 3796 for (ri = rn->info; ri; ri = ri->next)
228da428 3797 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
200df115 3798 {
3799 /* graceful restart STALE flag set. */
64e580a7
PJ
3800 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
3801 && peer->nsf[afi][safi]
200df115 3802 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
1a392d46
PJ
3803 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
3804 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
200df115 3805 else
64e580a7 3806 bgp_rib_remove (rn, ri, peer, afi, safi);
200df115 3807 }
200df115 3808 return WQ_SUCCESS;
3809}
3810
3811static void
0fb58d5d 3812bgp_clear_node_queue_del (struct work_queue *wq, void *data)
200df115 3813{
228da428
CC
3814 struct bgp_clear_node_queue *cnq = data;
3815 struct bgp_node *rn = cnq->rn;
67174041 3816 struct bgp_table *table = bgp_node_table (rn);
64e580a7
PJ
3817
3818 bgp_unlock_node (rn);
228da428
CC
3819 bgp_table_unlock (table);
3820 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
200df115 3821}
3822
3823static void
94f2b392 3824bgp_clear_node_complete (struct work_queue *wq)
200df115 3825{
64e580a7
PJ
3826 struct peer *peer = wq->spec.data;
3827
3e0c78ef 3828 /* Tickle FSM to start moving again */
ca058a30 3829 BGP_EVENT_ADD (peer, Clearing_Completed);
228da428
CC
3830
3831 peer_unlock (peer); /* bgp_clear_route */
200df115 3832}
3833
3834static void
64e580a7 3835bgp_clear_node_queue_init (struct peer *peer)
200df115 3836{
a2943657 3837 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
64e580a7 3838
a2943657 3839 snprintf (wname, sizeof(wname), "clear %s", peer->host);
64e580a7
PJ
3840#undef CLEAR_QUEUE_NAME_LEN
3841
3842 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
200df115 3843 {
3844 zlog_err ("%s: Failed to allocate work queue", __func__);
3845 exit (1);
3846 }
64e580a7
PJ
3847 peer->clear_node_queue->spec.hold = 10;
3848 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
3849 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
3850 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
3851 peer->clear_node_queue->spec.max_retries = 0;
3852
3853 /* we only 'lock' this peer reference when the queue is actually active */
3854 peer->clear_node_queue->spec.data = peer;
200df115 3855}
718e3744 3856
200df115 3857static void
3858bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
228da428
CC
3859 struct bgp_table *table, struct peer *rsclient,
3860 enum bgp_clear_route_type purpose)
200df115 3861{
200df115 3862 struct bgp_node *rn;
3863
f2c31acb 3864
718e3744 3865 if (! table)
fee0f4c6 3866 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
64e580a7 3867
6cf159b9 3868 /* If still no table => afi/safi isn't configured at all or smth. */
3869 if (! table)
3870 return;
65ca75e0
PJ
3871
3872 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3873 {
f2c31acb
PJ
3874 struct bgp_info *ri;
3875 struct bgp_adj_in *ain;
43143c8f 3876 struct bgp_adj_in *ain_next;
f2c31acb 3877 struct bgp_adj_out *aout;
f2c31acb
PJ
3878
3879 /* XXX:TODO: This is suboptimal, every non-empty route_node is
3880 * queued for every clearing peer, regardless of whether it is
3881 * relevant to the peer at hand.
3882 *
3883 * Overview: There are 3 different indices which need to be
3884 * scrubbed, potentially, when a peer is removed:
3885 *
3886 * 1 peer's routes visible via the RIB (ie accepted routes)
3887 * 2 peer's routes visible by the (optional) peer's adj-in index
3888 * 3 other routes visible by the peer's adj-out index
3889 *
3890 * 3 there is no hurry in scrubbing, once the struct peer is
3891 * removed from bgp->peer, we could just GC such deleted peer's
3892 * adj-outs at our leisure.
3893 *
3894 * 1 and 2 must be 'scrubbed' in some way, at least made
3895 * invisible via RIB index before peer session is allowed to be
3896 * brought back up. So one needs to know when such a 'search' is
3897 * complete.
3898 *
3899 * Ideally:
3900 *
3901 * - there'd be a single global queue or a single RIB walker
3902 * - rather than tracking which route_nodes still need to be
3903 * examined on a peer basis, we'd track which peers still
3904 * aren't cleared
3905 *
3906 * Given that our per-peer prefix-counts now should be reliable,
3907 * this may actually be achievable. It doesn't seem to be a huge
3908 * problem at this time,
43143c8f
DS
3909 *
3910 * It is possible that we have multiple paths for a prefix from a peer
3911 * if that peer is using AddPath.
f2c31acb 3912 */
43143c8f
DS
3913 ain = rn->adj_in;
3914 while (ain)
3915 {
3916 ain_next = ain->next;
3917
3918 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
3919 {
3920 bgp_adj_in_remove (rn, ain);
3921 bgp_unlock_node (rn);
3922 }
3923
3924 ain = ain_next;
3925 }
3f9c7369
DS
3926
3927 /*
3928 * Can't do this anymore. adj-outs are not maintained per peer.
3929 *
24e50f20
JBD
3930 for (aout = rn->adj_out; aout; aout = aout->next)
3931 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
3932 {
3933 bgp_adj_out_remove (rn, aout, peer, afi, safi);
3934 bgp_unlock_node (rn);
3935 break;
3936 }
3f9c7369 3937 */
f2c31acb 3938 for (ri = rn->info; ri; ri = ri->next)
228da428 3939 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
f2c31acb 3940 {
228da428
CC
3941 struct bgp_clear_node_queue *cnq;
3942
3943 /* both unlocked in bgp_clear_node_queue_del */
67174041 3944 bgp_table_lock (bgp_node_table (rn));
228da428
CC
3945 bgp_lock_node (rn);
3946 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
3947 sizeof (struct bgp_clear_node_queue));
3948 cnq->rn = rn;
3949 cnq->purpose = purpose;
3950 work_queue_add (peer->clear_node_queue, cnq);
3951 break;
f2c31acb 3952 }
65ca75e0
PJ
3953 }
3954 return;
3955}
3956
3957void
228da428
CC
3958bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
3959 enum bgp_clear_route_type purpose)
65ca75e0
PJ
3960{
3961 struct bgp_node *rn;
3962 struct bgp_table *table;
3963 struct peer *rsclient;
3964 struct listnode *node, *nnode;
6cf159b9 3965
64e580a7
PJ
3966 if (peer->clear_node_queue == NULL)
3967 bgp_clear_node_queue_init (peer);
200df115 3968
ca058a30
PJ
3969 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3970 * Idle until it receives a Clearing_Completed event. This protects
3971 * against peers which flap faster than we can we clear, which could
3972 * lead to:
64e580a7
PJ
3973 *
3974 * a) race with routes from the new session being installed before
3975 * clear_route_node visits the node (to delete the route of that
3976 * peer)
3977 * b) resource exhaustion, clear_route_node likely leads to an entry
3978 * on the process_main queue. Fast-flapping could cause that queue
3979 * to grow and grow.
200df115 3980 */
dc83d712
DS
3981
3982 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3983 * the unlock will happen upon work-queue completion; other wise, the
3984 * unlock happens at the end of this function.
3985 */
ca058a30 3986 if (!peer->clear_node_queue->thread)
dc83d712 3987 peer_lock (peer);
fee0f4c6 3988
228da428 3989 switch (purpose)
fee0f4c6 3990 {
228da428
CC
3991 case BGP_CLEAR_ROUTE_NORMAL:
3992 if (safi != SAFI_MPLS_VPN)
3993 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3994 else
3995 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3996 rn = bgp_route_next (rn))
3997 if ((table = rn->info) != NULL)
3998 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3999
4000 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
4001 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
4002 PEER_FLAG_RSERVER_CLIENT))
4003 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
4004 break;
4005
4006 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
4007 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
4008 break;
4009
4010 default:
4011 assert (0);
4012 break;
fee0f4c6 4013 }
dc83d712
DS
4014
4015 /* unlock if no nodes got added to the clear-node-queue. */
65ca75e0 4016 if (!peer->clear_node_queue->thread)
dc83d712
DS
4017 peer_unlock (peer);
4018
718e3744 4019}
4020
4021void
4022bgp_clear_route_all (struct peer *peer)
4023{
4024 afi_t afi;
4025 safi_t safi;
4026
4027 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4028 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
228da428 4029 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
718e3744 4030}
4031
4032void
4033bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
4034{
4035 struct bgp_table *table;
4036 struct bgp_node *rn;
4037 struct bgp_adj_in *ain;
43143c8f 4038 struct bgp_adj_in *ain_next;
718e3744 4039
4040 table = peer->bgp->rib[afi][safi];
4041
43143c8f
DS
4042 /* It is possible that we have multiple paths for a prefix from a peer
4043 * if that peer is using AddPath.
4044 */
718e3744 4045 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
43143c8f
DS
4046 {
4047 ain = rn->adj_in;
4048
4049 while (ain)
4050 {
4051 ain_next = ain->next;
4052
4053 if (ain->peer == peer)
4054 {
4055 bgp_adj_in_remove (rn, ain);
4056 bgp_unlock_node (rn);
4057 }
4058
4059 ain = ain_next;
4060 }
4061 }
718e3744 4062}
93406d87 4063
4064void
4065bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
4066{
4067 struct bgp_node *rn;
4068 struct bgp_info *ri;
4069 struct bgp_table *table;
4070
4071 table = peer->bgp->rib[afi][safi];
4072
4073 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4074 {
4075 for (ri = rn->info; ri; ri = ri->next)
4076 if (ri->peer == peer)
4077 {
4078 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
4079 bgp_rib_remove (rn, ri, peer, afi, safi);
4080 break;
4081 }
4082 }
4083}
6b0655a2 4084
718e3744 4085/* Delete all kernel routes. */
4086void
66e5cd87 4087bgp_cleanup_routes (void)
718e3744 4088{
4089 struct bgp *bgp;
1eb8ef25 4090 struct listnode *node, *nnode;
718e3744 4091 struct bgp_node *rn;
4092 struct bgp_table *table;
4093 struct bgp_info *ri;
4094
1eb8ef25 4095 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 4096 {
4097 table = bgp->rib[AFI_IP][SAFI_UNICAST];
4098
4099 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4100 for (ri = rn->info; ri; ri = ri->next)
4101 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
4102 && ri->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
4103 && (ri->sub_type == BGP_ROUTE_NORMAL ||
4104 ri->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 4105 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
718e3744 4106
4107 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
4108
4109 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4110 for (ri = rn->info; ri; ri = ri->next)
4111 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
4112 && ri->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
4113 && (ri->sub_type == BGP_ROUTE_NORMAL ||
4114 ri->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 4115 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
718e3744 4116 }
4117}
4118
4119void
66e5cd87 4120bgp_reset (void)
718e3744 4121{
4122 vty_reset ();
4123 bgp_zclient_reset ();
4124 access_list_reset ();
4125 prefix_list_reset ();
4126}
6b0655a2 4127
718e3744 4128/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
4129 value. */
4130int
4131bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
4132{
4133 u_char *pnt;
4134 u_char *lim;
4135 struct prefix p;
4136 int psize;
4137 int ret;
a82478b9
DS
4138 afi_t afi;
4139 safi_t safi;
4140 u_char addpath_encoded;
4141 u_int32_t addpath_id;
718e3744 4142
4143 /* Check peer status. */
4144 if (peer->status != Established)
4145 return 0;
4146
4147 pnt = packet->nlri;
4148 lim = pnt + packet->length;
a82478b9
DS
4149 afi = packet->afi;
4150 safi = packet->safi;
4151 addpath_id = 0;
4152
4153 addpath_encoded = (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
4154 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
718e3744 4155
4156 for (; pnt < lim; pnt += psize)
4157 {
4158 /* Clear prefix structure. */
4159 memset (&p, 0, sizeof (struct prefix));
4160
a82478b9
DS
4161 if (addpath_encoded)
4162 {
cd808e74
DS
4163
4164 /* When packet overflow occurs return immediately. */
4165 if (pnt + BGP_ADDPATH_ID_LEN > lim)
4166 return -1;
4167
a82478b9
DS
4168 addpath_id = ntohl(*((uint32_t*) pnt));
4169 pnt += BGP_ADDPATH_ID_LEN;
4170 }
4171
718e3744 4172 /* Fetch prefix length. */
4173 p.prefixlen = *pnt++;
a82478b9 4174 p.family = afi2family (afi);
718e3744 4175
4176 /* Already checked in nlri_sanity_check(). We do double check
4177 here. */
a82478b9
DS
4178 if ((afi == AFI_IP && p.prefixlen > 32)
4179 || (afi == AFI_IP6 && p.prefixlen > 128))
718e3744 4180 return -1;
4181
4182 /* Packet size overflow check. */
4183 psize = PSIZE (p.prefixlen);
4184
4185 /* When packet overflow occur return immediately. */
4186 if (pnt + psize > lim)
4187 return -1;
4188
4189 /* Fetch prefix from NLRI packet. */
4190 memcpy (&p.u.prefix, pnt, psize);
4191
4192 /* Check address. */
a82478b9 4193 if (afi == AFI_IP && safi == SAFI_UNICAST)
718e3744 4194 {
4195 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
4196 {
f5ba3874 4197 /*
4198 * From draft-ietf-idr-bgp4-22, Section 6.3:
4199 * If a BGP router receives an UPDATE message with a
4200 * semantically incorrect NLRI field, in which a prefix is
4201 * semantically incorrect (eg. an unexpected multicast IP
4202 * address), it should ignore the prefix.
4203 */
16286195
DS
4204 zlog_err ("IPv4 unicast NLRI is multicast address %s",
4205 inet_ntoa (p.u.prefix4));
f5ba3874 4206
718e3744 4207 return -1;
4208 }
4209 }
4210
4211#ifdef HAVE_IPV6
4212 /* Check address. */
a82478b9 4213 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
718e3744 4214 {
4215 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4216 {
4217 char buf[BUFSIZ];
4218
16286195
DS
4219 zlog_warn ("IPv6 link-local NLRI received %s ignore this NLRI",
4220 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
718e3744 4221
4222 continue;
4223 }
4224 }
4225#endif /* HAVE_IPV6 */
4226
4227 /* Normal process. */
4228 if (attr)
a82478b9 4229 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
718e3744 4230 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
4231 else
a82478b9 4232 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
718e3744 4233 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
4234
4235 /* Address family configuration mismatch or maximum-prefix count
4236 overflow. */
4237 if (ret < 0)
4238 return -1;
4239 }
4240
4241 /* Packet length consistency check. */
4242 if (pnt != lim)
4243 return -1;
4244
4245 return 0;
4246}
4247
4248/* NLRI encode syntax check routine. */
4249int
a82478b9 4250bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi, u_char *pnt,
d889623f 4251 bgp_size_t length, int *numpfx)
718e3744 4252{
4253 u_char *end;
4254 u_char prefixlen;
4255 int psize;
a82478b9 4256 u_char addpath_encoded;
718e3744 4257
d889623f 4258 *numpfx = 0;
718e3744 4259 end = pnt + length;
4260
a82478b9
DS
4261 addpath_encoded = (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
4262 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
4263
718e3744 4264 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
4265 syntactic validity. If the field is syntactically incorrect,
4266 then the Error Subcode is set to Invalid Network Field. */
4267
4268 while (pnt < end)
4269 {
cd808e74 4270
a82478b9
DS
4271 /* If the NLRI is encoded using addpath then the first 4 bytes are
4272 * the addpath ID. */
4273 if (addpath_encoded)
cd808e74
DS
4274 {
4275 if (pnt + BGP_ADDPATH_ID_LEN > end)
4276 {
4277 zlog_err ("%s [Error] Update packet error"
4278 " (prefix data addpath overflow)",
4279 peer->host);
4280 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
4281 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
4282 return -1;
4283 }
4284 pnt += BGP_ADDPATH_ID_LEN;
4285 }
a82478b9 4286
718e3744 4287 prefixlen = *pnt++;
4288
4289 /* Prefix length check. */
4290 if ((afi == AFI_IP && prefixlen > 32)
4291 || (afi == AFI_IP6 && prefixlen > 128))
4292 {
16286195 4293 zlog_err ("%s [Error] Update packet error (wrong prefix length %d)",
718e3744 4294 peer->host, prefixlen);
4295 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
4296 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
4297 return -1;
4298 }
4299
4300 /* Packet size overflow check. */
4301 psize = PSIZE (prefixlen);
4302
4303 if (pnt + psize > end)
4304 {
16286195 4305 zlog_err ("%s [Error] Update packet error"
718e3744 4306 " (prefix data overflow prefix size is %d)",
4307 peer->host, psize);
4308 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
4309 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
4310 return -1;
4311 }
4312
4313 pnt += psize;
d889623f 4314 (*numpfx)++;
718e3744 4315 }
4316
4317 /* Packet length consistency check. */
4318 if (pnt != end)
4319 {
16286195 4320 zlog_err ("%s [Error] Update packet error"
718e3744 4321 " (prefix length mismatch with total length)",
4322 peer->host);
4323 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
4324 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
4325 return -1;
4326 }
4327 return 0;
4328}
6b0655a2 4329
94f2b392 4330static struct bgp_static *
66e5cd87 4331bgp_static_new (void)
718e3744 4332{
393deb9b 4333 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
718e3744 4334}
4335
94f2b392 4336static void
718e3744 4337bgp_static_free (struct bgp_static *bgp_static)
4338{
4339 if (bgp_static->rmap.name)
4340 free (bgp_static->rmap.name);
4341 XFREE (MTYPE_BGP_STATIC, bgp_static);
4342}
4343
94f2b392 4344static void
fee0f4c6 4345bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
4346 struct prefix *p, afi_t afi, safi_t safi)
4347{
4348 struct bgp_node *rn;
4349 struct bgp_info *ri;
4350
4351 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
4352
4353 /* Check selected route and self inserted route. */
4354 for (ri = rn->info; ri; ri = ri->next)
4355 if (ri->peer == bgp->peer_self
4356 && ri->type == ZEBRA_ROUTE_BGP
4357 && ri->sub_type == BGP_ROUTE_STATIC)
4358 break;
4359
4360 /* Withdraw static BGP route from routing table. */
4361 if (ri)
4362 {
fee0f4c6 4363 bgp_info_delete (rn, ri);
1a392d46 4364 bgp_process (bgp, rn, afi, safi);
fee0f4c6 4365 }
4366
4367 /* Unlock bgp_node_lookup. */
4368 bgp_unlock_node (rn);
4369}
4370
94f2b392 4371static void
fee0f4c6 4372bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
fb982c25
PJ
4373 struct bgp_static *bgp_static,
4374 afi_t afi, safi_t safi)
fee0f4c6 4375{
4376 struct bgp_node *rn;
4377 struct bgp_info *ri;
4378 struct bgp_info *new;
4379 struct bgp_info info;
fee0f4c6 4380 struct attr *attr_new;
e16a4133 4381 struct attr attr;
558d1fec
JBD
4382 struct attr new_attr;
4383 struct attr_extra new_extra;
fee0f4c6 4384 struct bgp *bgp;
4385 int ret;
4386 char buf[SU_ADDRSTRLEN];
4387
4388 bgp = rsclient->bgp;
4389
06e110f9
PJ
4390 assert (bgp_static);
4391 if (!bgp_static)
4392 return;
4393
fee0f4c6 4394 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
4395
4396 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
06e110f9
PJ
4397
4398 attr.nexthop = bgp_static->igpnexthop;
4399 attr.med = bgp_static->igpmetric;
4400 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
41367172 4401
41367172
PJ
4402 if (bgp_static->atomic)
4403 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
4404
fee0f4c6 4405 /* Apply network route-map for export to this rsclient. */
4406 if (bgp_static->rmap.name)
4407 {
fb982c25 4408 struct attr attr_tmp = attr;
fee0f4c6 4409 info.peer = rsclient;
fb982c25
PJ
4410 info.attr = &attr_tmp;
4411
fee0f4c6 4412 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
4413 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
4414
4415 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
4416
4417 rsclient->rmap_type = 0;
4418
4419 if (ret == RMAP_DENYMATCH)
4420 {
4421 /* Free uninterned attribute. */
fb982c25 4422 bgp_attr_flush (&attr_tmp);
fee0f4c6 4423
4424 /* Unintern original. */
f6f434b2 4425 aspath_unintern (&attr.aspath);
fee0f4c6 4426 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
fb982c25
PJ
4427 bgp_attr_extra_free (&attr);
4428
fee0f4c6 4429 return;
4430 }
fb982c25 4431 attr_new = bgp_attr_intern (&attr_tmp);
fee0f4c6 4432 }
4433 else
4434 attr_new = bgp_attr_intern (&attr);
558d1fec
JBD
4435
4436 new_attr.extra = &new_extra;
7badc263 4437 bgp_attr_dup(&new_attr, attr_new);
fb982c25 4438
fee0f4c6 4439 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
4440
fb982c25
PJ
4441 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
4442 == RMAP_DENY)
4443 {
fee0f4c6 4444 /* This BGP update is filtered. Log the reason then update BGP entry. */
3f9c7369 4445 if (bgp_debug_update(rsclient, p, NULL, 1))
16286195
DS
4446 zlog_debug ("Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
4447 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
4448 p->prefixlen, rsclient->host);
fee0f4c6 4449
4450 bgp->peer_self->rmap_type = 0;
4451
f6f434b2
PJ
4452 bgp_attr_unintern (&attr_new);
4453 aspath_unintern (&attr.aspath);
fb982c25 4454 bgp_attr_extra_free (&attr);
fee0f4c6 4455
4456 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
4457
4458 return;
fb982c25 4459 }
fee0f4c6 4460
4461 bgp->peer_self->rmap_type = 0;
4462
f6f434b2 4463 bgp_attr_unintern (&attr_new);
fee0f4c6 4464 attr_new = bgp_attr_intern (&new_attr);
4465
4466 for (ri = rn->info; ri; ri = ri->next)
4467 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
4468 && ri->sub_type == BGP_ROUTE_STATIC)
4469 break;
4470
4471 if (ri)
4472 {
8d45210e 4473 if (attrhash_cmp (ri->attr, attr_new) &&
078430f6
DS
4474 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
4475 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
fee0f4c6 4476 {
4477 bgp_unlock_node (rn);
f6f434b2
PJ
4478 bgp_attr_unintern (&attr_new);
4479 aspath_unintern (&attr.aspath);
fb982c25 4480 bgp_attr_extra_free (&attr);
fee0f4c6 4481 return;
4482 }
4483 else
4484 {
4485 /* The attribute is changed. */
1a392d46 4486 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
fee0f4c6 4487
4488 /* Rewrite BGP route information. */
8d45210e
AS
4489 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
4490 bgp_info_restore(rn, ri);
f6f434b2 4491 bgp_attr_unintern (&ri->attr);
fee0f4c6 4492 ri->attr = attr_new;
65957886 4493 ri->uptime = bgp_clock ();
fee0f4c6 4494
fc9a856f
DS
4495 /* Nexthop reachability check. */
4496 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4497 {
75aead62 4498 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
fc9a856f
DS
4499 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
4500 else
4501 {
4502 if (BGP_DEBUG(nht, NHT))
4503 {
4504 char buf1[INET6_ADDRSTRLEN];
078430f6
DS
4505 inet_ntop (p->family, &p->u.prefix, buf1,
4506 INET6_ADDRSTRLEN);
4507 zlog_debug("%s(%s): Route not in table, not advertising",
4508 __FUNCTION__, buf1);
fc9a856f
DS
4509 }
4510 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
4511 }
4512 }
078430f6
DS
4513 else
4514 {
4515 /* Delete the NHT structure if any, if we're toggling between
4516 * enabling/disabling import check. We deregister the route
4517 * from NHT to avoid overloading NHT and the process interaction
4518 */
4519 bgp_unlink_nexthop(ri);
4520 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
4521 }
fee0f4c6 4522 /* Process change. */
4523 bgp_process (bgp, rn, afi, safi);
4524 bgp_unlock_node (rn);
f6f434b2 4525 aspath_unintern (&attr.aspath);
fb982c25 4526 bgp_attr_extra_free (&attr);
fee0f4c6 4527 return;
fb982c25 4528 }
fee0f4c6 4529 }
fb018d25 4530
fee0f4c6 4531 /* Make new BGP info. */
7c8ff89e 4532 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
fb018d25 4533 attr_new, rn);
fc9a856f
DS
4534 /* Nexthop reachability check. */
4535 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4536 {
75aead62 4537 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
fc9a856f
DS
4538 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
4539 else
4540 {
4541 if (BGP_DEBUG(nht, NHT))
4542 {
4543 char buf1[INET6_ADDRSTRLEN];
078430f6
DS
4544 inet_ntop(p->family, &p->u.prefix, buf1,
4545 INET6_ADDRSTRLEN);
4546 zlog_debug("%s(%s): Route not in table, not advertising", __FUNCTION__,
4547 buf1);
fc9a856f
DS
4548 }
4549 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
4550 }
4551 }
4552 else
078430f6
DS
4553 {
4554 /* Delete the NHT structure if any, if we're toggling between
4555 * enabling/disabling import check. We deregister the route
4556 * from NHT to avoid overloading NHT and the process interaction
4557 */
4558 bgp_unlink_nexthop(new);
4559 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
4560 }
fee0f4c6 4561
4562 /* Register new BGP information. */
4563 bgp_info_add (rn, new);
200df115 4564
4565 /* route_node_get lock */
4566 bgp_unlock_node (rn);
4567
fee0f4c6 4568 /* Process change. */
4569 bgp_process (bgp, rn, afi, safi);
4570
4571 /* Unintern original. */
f6f434b2 4572 aspath_unintern (&attr.aspath);
fb982c25 4573 bgp_attr_extra_free (&attr);
fee0f4c6 4574}
4575
94f2b392 4576static void
fee0f4c6 4577bgp_static_update_main (struct bgp *bgp, struct prefix *p,
fc9a856f 4578 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
718e3744 4579{
4580 struct bgp_node *rn;
4581 struct bgp_info *ri;
4582 struct bgp_info *new;
4583 struct bgp_info info;
e16a4133 4584 struct attr attr;
718e3744 4585 struct attr *attr_new;
4586 int ret;
4587
dd8103a9
PJ
4588 assert (bgp_static);
4589 if (!bgp_static)
4590 return;
4591
fee0f4c6 4592 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 4593
4594 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
dd8103a9
PJ
4595
4596 attr.nexthop = bgp_static->igpnexthop;
4597 attr.med = bgp_static->igpmetric;
4598 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
718e3744 4599
41367172
PJ
4600 if (bgp_static->atomic)
4601 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
4602
718e3744 4603 /* Apply route-map. */
4604 if (bgp_static->rmap.name)
4605 {
fb982c25 4606 struct attr attr_tmp = attr;
718e3744 4607 info.peer = bgp->peer_self;
286e1e71 4608 info.attr = &attr_tmp;
718e3744 4609
fee0f4c6 4610 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
4611
718e3744 4612 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
286e1e71 4613
fee0f4c6 4614 bgp->peer_self->rmap_type = 0;
4615
718e3744 4616 if (ret == RMAP_DENYMATCH)
4617 {
4618 /* Free uninterned attribute. */
286e1e71 4619 bgp_attr_flush (&attr_tmp);
718e3744 4620
4621 /* Unintern original. */
f6f434b2 4622 aspath_unintern (&attr.aspath);
fb982c25 4623 bgp_attr_extra_free (&attr);
718e3744 4624 bgp_static_withdraw (bgp, p, afi, safi);
4625 return;
4626 }
286e1e71 4627 attr_new = bgp_attr_intern (&attr_tmp);
718e3744 4628 }
286e1e71 4629 else
4630 attr_new = bgp_attr_intern (&attr);
718e3744 4631
4632 for (ri = rn->info; ri; ri = ri->next)
4633 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
4634 && ri->sub_type == BGP_ROUTE_STATIC)
4635 break;
4636
4637 if (ri)
4638 {
8d45210e 4639 if (attrhash_cmp (ri->attr, attr_new) &&
078430f6
DS
4640 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
4641 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
718e3744 4642 {
4643 bgp_unlock_node (rn);
f6f434b2
PJ
4644 bgp_attr_unintern (&attr_new);
4645 aspath_unintern (&attr.aspath);
fb982c25 4646 bgp_attr_extra_free (&attr);
718e3744 4647 return;
4648 }
4649 else
4650 {
4651 /* The attribute is changed. */
1a392d46 4652 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4653
4654 /* Rewrite BGP route information. */
8d45210e
AS
4655 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
4656 bgp_info_restore(rn, ri);
4657 else
4658 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
f6f434b2 4659 bgp_attr_unintern (&ri->attr);
718e3744 4660 ri->attr = attr_new;
65957886 4661 ri->uptime = bgp_clock ();
718e3744 4662
fc9a856f
DS
4663 /* Nexthop reachability check. */
4664 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4665 {
75aead62 4666 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
fc9a856f
DS
4667 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
4668 else
4669 {
4670 if (BGP_DEBUG(nht, NHT))
4671 {
4672 char buf1[INET6_ADDRSTRLEN];
078430f6
DS
4673 inet_ntop(p->family, &p->u.prefix, buf1,
4674 INET6_ADDRSTRLEN);
4675 zlog_debug("%s(%s): Route not in table, not advertising",
4676 __FUNCTION__, buf1);
fc9a856f
DS
4677 }
4678 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
4679 }
4680 }
078430f6
DS
4681 else
4682 {
4683 /* Delete the NHT structure if any, if we're toggling between
4684 * enabling/disabling import check. We deregister the route
4685 * from NHT to avoid overloading NHT and the process interaction
4686 */
4687 bgp_unlink_nexthop(ri);
4688 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
4689 }
718e3744 4690 /* Process change. */
4691 bgp_aggregate_increment (bgp, p, ri, afi, safi);
4692 bgp_process (bgp, rn, afi, safi);
4693 bgp_unlock_node (rn);
f6f434b2 4694 aspath_unintern (&attr.aspath);
fb982c25 4695 bgp_attr_extra_free (&attr);
718e3744 4696 return;
4697 }
4698 }
4699
4700 /* Make new BGP info. */
7c8ff89e 4701 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
fb018d25 4702 rn);
fc9a856f
DS
4703 /* Nexthop reachability check. */
4704 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4705 {
75aead62 4706 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
fc9a856f
DS
4707 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
4708 else
4709 {
4710 if (BGP_DEBUG(nht, NHT))
4711 {
4712 char buf1[INET6_ADDRSTRLEN];
078430f6 4713 inet_ntop(p->family, &p->u.prefix, buf1,
fc9a856f 4714 INET6_ADDRSTRLEN);
078430f6
DS
4715 zlog_debug("%s(%s): Route not in table, not advertising",
4716 __FUNCTION__, buf1);
fc9a856f
DS
4717 }
4718 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
4719 }
4720 }
4721 else
078430f6
DS
4722 {
4723 /* Delete the NHT structure if any, if we're toggling between
4724 * enabling/disabling import check. We deregister the route
4725 * from NHT to avoid overloading NHT and the process interaction
4726 */
4727 bgp_unlink_nexthop(new);
4728
4729 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
4730 }
718e3744 4731
4732 /* Aggregate address increment. */
4733 bgp_aggregate_increment (bgp, p, new, afi, safi);
4734
4735 /* Register new BGP information. */
4736 bgp_info_add (rn, new);
200df115 4737
4738 /* route_node_get lock */
4739 bgp_unlock_node (rn);
4740
718e3744 4741 /* Process change. */
4742 bgp_process (bgp, rn, afi, safi);
4743
4744 /* Unintern original. */
f6f434b2 4745 aspath_unintern (&attr.aspath);
fb982c25 4746 bgp_attr_extra_free (&attr);
718e3744 4747}
4748
fee0f4c6 4749void
4750bgp_static_update (struct bgp *bgp, struct prefix *p,
4751 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
4752{
4753 struct peer *rsclient;
1eb8ef25 4754 struct listnode *node, *nnode;
fee0f4c6 4755
4756 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
4757
1eb8ef25 4758 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 4759 {
da5b30f6
PJ
4760 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
4761 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
fee0f4c6 4762 }
4763}
4764
94f2b392 4765static void
4c9641ba
ML
4766bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
4767 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 4768{
4769 struct bgp_node *rn;
4770 struct bgp_info *new;
fb982c25 4771
fee0f4c6 4772 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 4773
4774 /* Make new BGP info. */
7c8ff89e 4775 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
fb018d25
DS
4776 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
4777
718e3744 4778 SET_FLAG (new->flags, BGP_INFO_VALID);
fb982c25
PJ
4779 new->extra = bgp_info_extra_new();
4780 memcpy (new->extra->tag, tag, 3);
718e3744 4781
4782 /* Aggregate address increment. */
200df115 4783 bgp_aggregate_increment (bgp, p, new, afi, safi);
718e3744 4784
4785 /* Register new BGP information. */
200df115 4786 bgp_info_add (rn, new);
718e3744 4787
200df115 4788 /* route_node_get lock */
4789 bgp_unlock_node (rn);
4790
718e3744 4791 /* Process change. */
4792 bgp_process (bgp, rn, afi, safi);
4793}
4794
4795void
4796bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
4797 safi_t safi)
4798{
4799 struct bgp_node *rn;
4800 struct bgp_info *ri;
4801
fee0f4c6 4802 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 4803
4804 /* Check selected route and self inserted route. */
4805 for (ri = rn->info; ri; ri = ri->next)
4806 if (ri->peer == bgp->peer_self
4807 && ri->type == ZEBRA_ROUTE_BGP
4808 && ri->sub_type == BGP_ROUTE_STATIC)
4809 break;
4810
4811 /* Withdraw static BGP route from routing table. */
4812 if (ri)
4813 {
4814 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
fc9a856f 4815 bgp_unlink_nexthop(ri);
718e3744 4816 bgp_info_delete (rn, ri);
1a392d46 4817 bgp_process (bgp, rn, afi, safi);
718e3744 4818 }
4819
4820 /* Unlock bgp_node_lookup. */
4821 bgp_unlock_node (rn);
4822}
4823
fee0f4c6 4824void
4825bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
4826{
4827 struct bgp_static *bgp_static;
4828 struct bgp *bgp;
4829 struct bgp_node *rn;
4830 struct prefix *p;
4831
4832 bgp = rsclient->bgp;
4833
4834 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4835 if ((bgp_static = rn->info) != NULL)
4836 {
4837 p = &rn->p;
4838
4839 bgp_static_update_rsclient (rsclient, p, bgp_static,
4840 afi, safi);
4841 }
4842}
4843
94f2b392 4844static void
4c9641ba
ML
4845bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
4846 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 4847{
4848 struct bgp_node *rn;
4849 struct bgp_info *ri;
4850
fee0f4c6 4851 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 4852
4853 /* Check selected route and self inserted route. */
4854 for (ri = rn->info; ri; ri = ri->next)
4855 if (ri->peer == bgp->peer_self
4856 && ri->type == ZEBRA_ROUTE_BGP
4857 && ri->sub_type == BGP_ROUTE_STATIC)
4858 break;
4859
4860 /* Withdraw static BGP route from routing table. */
4861 if (ri)
4862 {
4863 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
718e3744 4864 bgp_info_delete (rn, ri);
1a392d46 4865 bgp_process (bgp, rn, afi, safi);
718e3744 4866 }
4867
4868 /* Unlock bgp_node_lookup. */
4869 bgp_unlock_node (rn);
4870}
4871
4872/* Configure static BGP network. When user don't run zebra, static
4873 route should be installed as valid. */
94f2b392 4874static int
fd79ac91 4875bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
c8f3fe30 4876 afi_t afi, safi_t safi, const char *rmap, int backdoor)
718e3744 4877{
4878 int ret;
4879 struct prefix p;
4880 struct bgp_static *bgp_static;
4881 struct bgp_node *rn;
41367172 4882 u_char need_update = 0;
718e3744 4883
4884 /* Convert IP prefix string to struct prefix. */
4885 ret = str2prefix (ip_str, &p);
4886 if (! ret)
4887 {
4888 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4889 return CMD_WARNING;
4890 }
4891#ifdef HAVE_IPV6
4892 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4893 {
4894 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4895 VTY_NEWLINE);
4896 return CMD_WARNING;
4897 }
4898#endif /* HAVE_IPV6 */
4899
4900 apply_mask (&p);
4901
4902 /* Set BGP static route configuration. */
4903 rn = bgp_node_get (bgp->route[afi][safi], &p);
4904
4905 if (rn->info)
4906 {
4907 /* Configuration change. */
4908 bgp_static = rn->info;
4909
4910 /* Check previous routes are installed into BGP. */
c8f3fe30
PJ
4911 if (bgp_static->valid && bgp_static->backdoor != backdoor)
4912 need_update = 1;
41367172 4913
718e3744 4914 bgp_static->backdoor = backdoor;
41367172 4915
718e3744 4916 if (rmap)
4917 {
4918 if (bgp_static->rmap.name)
4919 free (bgp_static->rmap.name);
4920 bgp_static->rmap.name = strdup (rmap);
4921 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4922 }
4923 else
4924 {
4925 if (bgp_static->rmap.name)
4926 free (bgp_static->rmap.name);
4927 bgp_static->rmap.name = NULL;
4928 bgp_static->rmap.map = NULL;
4929 bgp_static->valid = 0;
4930 }
4931 bgp_unlock_node (rn);
4932 }
4933 else
4934 {
4935 /* New configuration. */
4936 bgp_static = bgp_static_new ();
4937 bgp_static->backdoor = backdoor;
4938 bgp_static->valid = 0;
4939 bgp_static->igpmetric = 0;
4940 bgp_static->igpnexthop.s_addr = 0;
41367172 4941
718e3744 4942 if (rmap)
4943 {
4944 if (bgp_static->rmap.name)
4945 free (bgp_static->rmap.name);
4946 bgp_static->rmap.name = strdup (rmap);
4947 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4948 }
4949 rn->info = bgp_static;
4950 }
4951
fc9a856f
DS
4952 bgp_static->valid = 1;
4953 if (need_update)
4954 bgp_static_withdraw (bgp, &p, afi, safi);
718e3744 4955
fc9a856f
DS
4956 if (! bgp_static->backdoor)
4957 bgp_static_update (bgp, &p, bgp_static, afi, safi);
718e3744 4958
4959 return CMD_SUCCESS;
4960}
4961
4962/* Configure static BGP network. */
94f2b392 4963static int
fd79ac91 4964bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4c9641ba 4965 afi_t afi, safi_t safi)
718e3744 4966{
4967 int ret;
4968 struct prefix p;
4969 struct bgp_static *bgp_static;
4970 struct bgp_node *rn;
4971
4972 /* Convert IP prefix string to struct prefix. */
4973 ret = str2prefix (ip_str, &p);
4974 if (! ret)
4975 {
4976 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4977 return CMD_WARNING;
4978 }
4979#ifdef HAVE_IPV6
4980 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4981 {
4982 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4983 VTY_NEWLINE);
4984 return CMD_WARNING;
4985 }
4986#endif /* HAVE_IPV6 */
4987
4988 apply_mask (&p);
4989
4990 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4991 if (! rn)
4992 {
4993 vty_out (vty, "%% Can't find specified static route configuration.%s",
4994 VTY_NEWLINE);
4995 return CMD_WARNING;
4996 }
4997
4998 bgp_static = rn->info;
41367172 4999
718e3744 5000 /* Update BGP RIB. */
5001 if (! bgp_static->backdoor)
5002 bgp_static_withdraw (bgp, &p, afi, safi);
5003
5004 /* Clear configuration. */
5005 bgp_static_free (bgp_static);
5006 rn->info = NULL;
5007 bgp_unlock_node (rn);
5008 bgp_unlock_node (rn);
5009
5010 return CMD_SUCCESS;
5011}
5012
5013/* Called from bgp_delete(). Delete all static routes from the BGP
5014 instance. */
5015void
5016bgp_static_delete (struct bgp *bgp)
5017{
5018 afi_t afi;
5019 safi_t safi;
5020 struct bgp_node *rn;
5021 struct bgp_node *rm;
5022 struct bgp_table *table;
5023 struct bgp_static *bgp_static;
5024
5025 for (afi = AFI_IP; afi < AFI_MAX; afi++)
5026 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
5027 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
5028 if (rn->info != NULL)
5029 {
5030 if (safi == SAFI_MPLS_VPN)
5031 {
5032 table = rn->info;
5033
5034 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
5035 {
5036 bgp_static = rn->info;
5037 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
5038 AFI_IP, SAFI_MPLS_VPN,
5039 (struct prefix_rd *)&rn->p,
5040 bgp_static->tag);
5041 bgp_static_free (bgp_static);
5042 rn->info = NULL;
5043 bgp_unlock_node (rn);
5044 }
5045 }
5046 else
5047 {
5048 bgp_static = rn->info;
5049 bgp_static_withdraw (bgp, &rn->p, afi, safi);
5050 bgp_static_free (bgp_static);
5051 rn->info = NULL;
5052 bgp_unlock_node (rn);
5053 }
5054 }
5055}
5056
078430f6
DS
5057void
5058bgp_static_redo_import_check (struct bgp *bgp)
5059{
5060 afi_t afi;
5061 safi_t safi;
5062 struct bgp_node *rn;
5063 struct bgp_node *rm;
5064 struct bgp_table *table;
5065 struct bgp_static *bgp_static;
5066
5067 /* Use this flag to force reprocessing of the route */
5068 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
5069 for (afi = AFI_IP; afi < AFI_MAX; afi++)
5070 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
5071 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
5072 if (rn->info != NULL)
5073 {
5074 bgp_static = rn->info;
5075 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
5076 }
5077 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
5078}
5079
718e3744 5080int
fd79ac91 5081bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
5082 const char *tag_str)
718e3744 5083{
5084 int ret;
5085 struct prefix p;
5086 struct prefix_rd prd;
5087 struct bgp *bgp;
5088 struct bgp_node *prn;
5089 struct bgp_node *rn;
5090 struct bgp_table *table;
5091 struct bgp_static *bgp_static;
5092 u_char tag[3];
5093
5094 bgp = vty->index;
5095
5096 ret = str2prefix (ip_str, &p);
5097 if (! ret)
5098 {
5099 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
5100 return CMD_WARNING;
5101 }
5102 apply_mask (&p);
5103
5104 ret = str2prefix_rd (rd_str, &prd);
5105 if (! ret)
5106 {
5107 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
5108 return CMD_WARNING;
5109 }
5110
5111 ret = str2tag (tag_str, tag);
5112 if (! ret)
5113 {
5114 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
5115 return CMD_WARNING;
5116 }
5117
5118 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
5119 (struct prefix *)&prd);
5120 if (prn->info == NULL)
64e580a7 5121 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
718e3744 5122 else
5123 bgp_unlock_node (prn);
5124 table = prn->info;
5125
5126 rn = bgp_node_get (table, &p);
5127
5128 if (rn->info)
5129 {
5130 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
5131 bgp_unlock_node (rn);
5132 }
5133 else
5134 {
5135 /* New configuration. */
5136 bgp_static = bgp_static_new ();
5137 bgp_static->valid = 1;
5138 memcpy (bgp_static->tag, tag, 3);
5139 rn->info = bgp_static;
5140
5141 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
5142 }
5143
5144 return CMD_SUCCESS;
5145}
5146
5147/* Configure static BGP network. */
5148int
fd79ac91 5149bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
5150 const char *rd_str, const char *tag_str)
718e3744 5151{
5152 int ret;
5153 struct bgp *bgp;
5154 struct prefix p;
5155 struct prefix_rd prd;
5156 struct bgp_node *prn;
5157 struct bgp_node *rn;
5158 struct bgp_table *table;
5159 struct bgp_static *bgp_static;
5160 u_char tag[3];
5161
5162 bgp = vty->index;
5163
5164 /* Convert IP prefix string to struct prefix. */
5165 ret = str2prefix (ip_str, &p);
5166 if (! ret)
5167 {
5168 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
5169 return CMD_WARNING;
5170 }
5171 apply_mask (&p);
5172
5173 ret = str2prefix_rd (rd_str, &prd);
5174 if (! ret)
5175 {
5176 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
5177 return CMD_WARNING;
5178 }
5179
5180 ret = str2tag (tag_str, tag);
5181 if (! ret)
5182 {
5183 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
5184 return CMD_WARNING;
5185 }
5186
5187 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
5188 (struct prefix *)&prd);
5189 if (prn->info == NULL)
64e580a7 5190 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
718e3744 5191 else
5192 bgp_unlock_node (prn);
5193 table = prn->info;
5194
5195 rn = bgp_node_lookup (table, &p);
5196
5197 if (rn)
5198 {
5199 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
5200
5201 bgp_static = rn->info;
5202 bgp_static_free (bgp_static);
5203 rn->info = NULL;
5204 bgp_unlock_node (rn);
5205 bgp_unlock_node (rn);
5206 }
5207 else
5208 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
5209
5210 return CMD_SUCCESS;
5211}
6b0655a2 5212
73ac8160
DS
5213static int
5214bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
5215 const char *rmap_name)
5216{
5217 struct bgp_rmap *rmap;
5218
5219 rmap = &bgp->table_map[afi][safi];
5220 if (rmap_name)
5221 {
5222 if (rmap->name)
5223 free (rmap->name);
5224 rmap->name = strdup (rmap_name);
5225 rmap->map = route_map_lookup_by_name (rmap_name);
5226 }
5227 else
5228 {
5229 if (rmap->name)
5230 free (rmap->name);
5231 rmap->name = NULL;
5232 rmap->map = NULL;
5233 }
5234
5235 bgp_zebra_announce_table(bgp, afi, safi);
5236
5237 return CMD_SUCCESS;
5238}
5239
5240static int
5241bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
5242 const char *rmap_name)
5243{
5244 struct bgp_rmap *rmap;
5245
5246 rmap = &bgp->table_map[afi][safi];
5247 if (rmap->name)
5248 free (rmap->name);
5249 rmap->name = NULL;
5250 rmap->map = NULL;
5251
5252 bgp_zebra_announce_table(bgp, afi, safi);
5253
5254 return CMD_SUCCESS;
5255}
5256
5257int
5258bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
5259 safi_t safi, int *write)
5260{
5261 if (bgp->table_map[afi][safi].name)
5262 {
5263 bgp_config_write_family_header (vty, afi, safi, write);
5264 vty_out (vty, " table-map %s%s",
5265 bgp->table_map[afi][safi].name, VTY_NEWLINE);
5266 }
5267
5268 return 0;
5269}
5270
5271
5272DEFUN (bgp_table_map,
5273 bgp_table_map_cmd,
5274 "table-map WORD",
5275 "BGP table to RIB route download filter\n"
5276 "Name of the route map\n")
5277{
5278 return bgp_table_map_set (vty, vty->index,
5279 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
5280}
5281DEFUN (no_bgp_table_map,
5282 no_bgp_table_map_cmd,
5283 "no table-map WORD",
5284 "BGP table to RIB route download filter\n"
5285 "Name of the route map\n")
5286{
5287 return bgp_table_map_unset (vty, vty->index,
5288 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
5289}
5290
718e3744 5291DEFUN (bgp_network,
5292 bgp_network_cmd,
5293 "network A.B.C.D/M",
5294 "Specify a network to announce via BGP\n"
5295 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5296{
5297 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 5298 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 5299}
5300
5301DEFUN (bgp_network_route_map,
5302 bgp_network_route_map_cmd,
5303 "network A.B.C.D/M route-map WORD",
5304 "Specify a network to announce via BGP\n"
5305 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5306 "Route-map to modify the attributes\n"
5307 "Name of the route map\n")
5308{
5309 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 5310 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 5311}
5312
5313DEFUN (bgp_network_backdoor,
5314 bgp_network_backdoor_cmd,
5315 "network A.B.C.D/M backdoor",
5316 "Specify a network to announce via BGP\n"
5317 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5318 "Specify a BGP backdoor route\n")
5319{
41367172 5320 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
c8f3fe30 5321 NULL, 1);
718e3744 5322}
5323
5324DEFUN (bgp_network_mask,
5325 bgp_network_mask_cmd,
5326 "network A.B.C.D mask A.B.C.D",
5327 "Specify a network to announce via BGP\n"
5328 "Network number\n"
5329 "Network mask\n"
5330 "Network mask\n")
5331{
5332 int ret;
5333 char prefix_str[BUFSIZ];
41367172 5334
718e3744 5335 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5336 if (! ret)
5337 {
5338 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5339 return CMD_WARNING;
5340 }
5341
5342 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 5343 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 5344}
5345
5346DEFUN (bgp_network_mask_route_map,
5347 bgp_network_mask_route_map_cmd,
5348 "network A.B.C.D mask A.B.C.D route-map WORD",
5349 "Specify a network to announce via BGP\n"
5350 "Network number\n"
5351 "Network mask\n"
5352 "Network mask\n"
5353 "Route-map to modify the attributes\n"
5354 "Name of the route map\n")
5355{
5356 int ret;
5357 char prefix_str[BUFSIZ];
41367172 5358
718e3744 5359 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5360 if (! ret)
5361 {
5362 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5363 return CMD_WARNING;
5364 }
5365
5366 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 5367 AFI_IP, bgp_node_safi (vty), argv[2], 0);
718e3744 5368}
5369
5370DEFUN (bgp_network_mask_backdoor,
5371 bgp_network_mask_backdoor_cmd,
5372 "network A.B.C.D mask A.B.C.D backdoor",
5373 "Specify a network to announce via BGP\n"
5374 "Network number\n"
5375 "Network mask\n"
5376 "Network mask\n"
5377 "Specify a BGP backdoor route\n")
5378{
5379 int ret;
5380 char prefix_str[BUFSIZ];
41367172 5381
718e3744 5382 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5383 if (! ret)
5384 {
5385 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5386 return CMD_WARNING;
5387 }
5388
41367172 5389 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 5390 NULL, 1);
718e3744 5391}
5392
5393DEFUN (bgp_network_mask_natural,
5394 bgp_network_mask_natural_cmd,
5395 "network A.B.C.D",
5396 "Specify a network to announce via BGP\n"
5397 "Network number\n")
5398{
5399 int ret;
5400 char prefix_str[BUFSIZ];
5401
5402 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
5403 if (! ret)
5404 {
5405 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5406 return CMD_WARNING;
5407 }
5408
5409 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 5410 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 5411}
5412
5413DEFUN (bgp_network_mask_natural_route_map,
5414 bgp_network_mask_natural_route_map_cmd,
5415 "network A.B.C.D route-map WORD",
5416 "Specify a network to announce via BGP\n"
5417 "Network number\n"
5418 "Route-map to modify the attributes\n"
5419 "Name of the route map\n")
5420{
5421 int ret;
5422 char prefix_str[BUFSIZ];
5423
5424 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
5425 if (! ret)
5426 {
5427 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5428 return CMD_WARNING;
5429 }
5430
5431 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 5432 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 5433}
5434
5435DEFUN (bgp_network_mask_natural_backdoor,
5436 bgp_network_mask_natural_backdoor_cmd,
5437 "network A.B.C.D backdoor",
5438 "Specify a network to announce via BGP\n"
5439 "Network number\n"
5440 "Specify a BGP backdoor route\n")
5441{
5442 int ret;
5443 char prefix_str[BUFSIZ];
5444
5445 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
5446 if (! ret)
5447 {
5448 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5449 return CMD_WARNING;
5450 }
5451
41367172 5452 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 5453 NULL, 1);
718e3744 5454}
5455
5456DEFUN (no_bgp_network,
5457 no_bgp_network_cmd,
5458 "no network A.B.C.D/M",
5459 NO_STR
5460 "Specify a network to announce via BGP\n"
5461 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5462{
5463 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
5464 bgp_node_safi (vty));
5465}
5466
5467ALIAS (no_bgp_network,
5468 no_bgp_network_route_map_cmd,
5469 "no network A.B.C.D/M route-map WORD",
5470 NO_STR
5471 "Specify a network to announce via BGP\n"
5472 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5473 "Route-map to modify the attributes\n"
5474 "Name of the route map\n")
5475
5476ALIAS (no_bgp_network,
5477 no_bgp_network_backdoor_cmd,
5478 "no network A.B.C.D/M backdoor",
5479 NO_STR
5480 "Specify a network to announce via BGP\n"
5481 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5482 "Specify a BGP backdoor route\n")
5483
5484DEFUN (no_bgp_network_mask,
5485 no_bgp_network_mask_cmd,
5486 "no network A.B.C.D mask A.B.C.D",
5487 NO_STR
5488 "Specify a network to announce via BGP\n"
5489 "Network number\n"
5490 "Network mask\n"
5491 "Network mask\n")
5492{
5493 int ret;
5494 char prefix_str[BUFSIZ];
5495
5496 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5497 if (! ret)
5498 {
5499 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5500 return CMD_WARNING;
5501 }
5502
5503 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
5504 bgp_node_safi (vty));
5505}
5506
5507ALIAS (no_bgp_network_mask,
5508 no_bgp_network_mask_route_map_cmd,
5509 "no network A.B.C.D mask A.B.C.D route-map WORD",
5510 NO_STR
5511 "Specify a network to announce via BGP\n"
5512 "Network number\n"
5513 "Network mask\n"
5514 "Network mask\n"
5515 "Route-map to modify the attributes\n"
5516 "Name of the route map\n")
5517
5518ALIAS (no_bgp_network_mask,
5519 no_bgp_network_mask_backdoor_cmd,
5520 "no network A.B.C.D mask A.B.C.D backdoor",
5521 NO_STR
5522 "Specify a network to announce via BGP\n"
5523 "Network number\n"
5524 "Network mask\n"
5525 "Network mask\n"
5526 "Specify a BGP backdoor route\n")
5527
5528DEFUN (no_bgp_network_mask_natural,
5529 no_bgp_network_mask_natural_cmd,
5530 "no network A.B.C.D",
5531 NO_STR
5532 "Specify a network to announce via BGP\n"
5533 "Network number\n")
5534{
5535 int ret;
5536 char prefix_str[BUFSIZ];
5537
5538 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
5539 if (! ret)
5540 {
5541 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5542 return CMD_WARNING;
5543 }
5544
5545 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
5546 bgp_node_safi (vty));
5547}
5548
5549ALIAS (no_bgp_network_mask_natural,
5550 no_bgp_network_mask_natural_route_map_cmd,
5551 "no network A.B.C.D route-map WORD",
5552 NO_STR
5553 "Specify a network to announce via BGP\n"
5554 "Network number\n"
5555 "Route-map to modify the attributes\n"
5556 "Name of the route map\n")
5557
5558ALIAS (no_bgp_network_mask_natural,
5559 no_bgp_network_mask_natural_backdoor_cmd,
5560 "no network A.B.C.D backdoor",
5561 NO_STR
5562 "Specify a network to announce via BGP\n"
5563 "Network number\n"
5564 "Specify a BGP backdoor route\n")
5565
5566#ifdef HAVE_IPV6
5567DEFUN (ipv6_bgp_network,
5568 ipv6_bgp_network_cmd,
5569 "network X:X::X:X/M",
5570 "Specify a network to announce via BGP\n"
5571 "IPv6 prefix <network>/<length>\n")
5572{
73bfe0bd 5573 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
c8f3fe30 5574 NULL, 0);
718e3744 5575}
5576
5577DEFUN (ipv6_bgp_network_route_map,
5578 ipv6_bgp_network_route_map_cmd,
5579 "network X:X::X:X/M route-map WORD",
5580 "Specify a network to announce via BGP\n"
5581 "IPv6 prefix <network>/<length>\n"
5582 "Route-map to modify the attributes\n"
5583 "Name of the route map\n")
5584{
5585 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
c8f3fe30 5586 bgp_node_safi (vty), argv[1], 0);
718e3744 5587}
5588
5589DEFUN (no_ipv6_bgp_network,
5590 no_ipv6_bgp_network_cmd,
5591 "no network X:X::X:X/M",
5592 NO_STR
5593 "Specify a network to announce via BGP\n"
5594 "IPv6 prefix <network>/<length>\n")
5595{
73bfe0bd 5596 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
718e3744 5597}
5598
5599ALIAS (no_ipv6_bgp_network,
5600 no_ipv6_bgp_network_route_map_cmd,
5601 "no network X:X::X:X/M route-map WORD",
5602 NO_STR
5603 "Specify a network to announce via BGP\n"
5604 "IPv6 prefix <network>/<length>\n"
5605 "Route-map to modify the attributes\n"
5606 "Name of the route map\n")
5607
5608ALIAS (ipv6_bgp_network,
5609 old_ipv6_bgp_network_cmd,
5610 "ipv6 bgp network X:X::X:X/M",
5611 IPV6_STR
5612 BGP_STR
5613 "Specify a network to announce via BGP\n"
5614 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5615
5616ALIAS (no_ipv6_bgp_network,
5617 old_no_ipv6_bgp_network_cmd,
5618 "no ipv6 bgp network X:X::X:X/M",
5619 NO_STR
5620 IPV6_STR
5621 BGP_STR
5622 "Specify a network to announce via BGP\n"
5623 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5624#endif /* HAVE_IPV6 */
c8f3fe30
PJ
5625
5626/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
5627ALIAS_DEPRECATED (bgp_network,
5628 bgp_network_ttl_cmd,
5629 "network A.B.C.D/M pathlimit <0-255>",
5630 "Specify a network to announce via BGP\n"
5631 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5632 "AS-Path hopcount limit attribute\n"
5633 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5634ALIAS_DEPRECATED (bgp_network_backdoor,
5635 bgp_network_backdoor_ttl_cmd,
5636 "network A.B.C.D/M backdoor pathlimit <0-255>",
5637 "Specify a network to announce via BGP\n"
5638 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5639 "Specify a BGP backdoor route\n"
5640 "AS-Path hopcount limit attribute\n"
5641 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5642ALIAS_DEPRECATED (bgp_network_mask,
5643 bgp_network_mask_ttl_cmd,
5644 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
5645 "Specify a network to announce via BGP\n"
5646 "Network number\n"
5647 "Network mask\n"
5648 "Network mask\n"
5649 "AS-Path hopcount limit attribute\n"
5650 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5651ALIAS_DEPRECATED (bgp_network_mask_backdoor,
5652 bgp_network_mask_backdoor_ttl_cmd,
5653 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
5654 "Specify a network to announce via BGP\n"
5655 "Network number\n"
5656 "Network mask\n"
5657 "Network mask\n"
5658 "Specify a BGP backdoor route\n"
5659 "AS-Path hopcount limit attribute\n"
5660 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5661ALIAS_DEPRECATED (bgp_network_mask_natural,
5662 bgp_network_mask_natural_ttl_cmd,
5663 "network A.B.C.D pathlimit <0-255>",
5664 "Specify a network to announce via BGP\n"
5665 "Network number\n"
5666 "AS-Path hopcount limit attribute\n"
5667 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5668ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
5669 bgp_network_mask_natural_backdoor_ttl_cmd,
2b00515a 5670 "network A.B.C.D backdoor pathlimit <1-255>",
c8f3fe30
PJ
5671 "Specify a network to announce via BGP\n"
5672 "Network number\n"
5673 "Specify a BGP backdoor route\n"
5674 "AS-Path hopcount limit attribute\n"
5675 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5676ALIAS_DEPRECATED (no_bgp_network,
5677 no_bgp_network_ttl_cmd,
5678 "no network A.B.C.D/M pathlimit <0-255>",
5679 NO_STR
5680 "Specify a network to announce via BGP\n"
5681 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5682 "AS-Path hopcount limit attribute\n"
5683 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5684ALIAS_DEPRECATED (no_bgp_network,
5685 no_bgp_network_backdoor_ttl_cmd,
5686 "no network A.B.C.D/M backdoor pathlimit <0-255>",
5687 NO_STR
5688 "Specify a network to announce via BGP\n"
5689 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5690 "Specify a BGP backdoor route\n"
5691 "AS-Path hopcount limit attribute\n"
5692 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5693ALIAS_DEPRECATED (no_bgp_network,
5694 no_bgp_network_mask_ttl_cmd,
5695 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
5696 NO_STR
5697 "Specify a network to announce via BGP\n"
5698 "Network number\n"
5699 "Network mask\n"
5700 "Network mask\n"
5701 "AS-Path hopcount limit attribute\n"
5702 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5703ALIAS_DEPRECATED (no_bgp_network_mask,
5704 no_bgp_network_mask_backdoor_ttl_cmd,
5705 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
5706 NO_STR
5707 "Specify a network to announce via BGP\n"
5708 "Network number\n"
5709 "Network mask\n"
5710 "Network mask\n"
5711 "Specify a BGP backdoor route\n"
5712 "AS-Path hopcount limit attribute\n"
5713 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5714ALIAS_DEPRECATED (no_bgp_network_mask_natural,
5715 no_bgp_network_mask_natural_ttl_cmd,
5716 "no network A.B.C.D pathlimit <0-255>",
5717 NO_STR
5718 "Specify a network to announce via BGP\n"
5719 "Network number\n"
5720 "AS-Path hopcount limit attribute\n"
5721 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5722ALIAS_DEPRECATED (no_bgp_network_mask_natural,
5723 no_bgp_network_mask_natural_backdoor_ttl_cmd,
5724 "no network A.B.C.D backdoor pathlimit <0-255>",
5725 NO_STR
5726 "Specify a network to announce via BGP\n"
5727 "Network number\n"
5728 "Specify a BGP backdoor route\n"
5729 "AS-Path hopcount limit attribute\n"
5730 "AS-Pathlimit TTL, in number of AS-Path hops\n")
3bde17f1 5731#ifdef HAVE_IPV6
c8f3fe30
PJ
5732ALIAS_DEPRECATED (ipv6_bgp_network,
5733 ipv6_bgp_network_ttl_cmd,
5734 "network X:X::X:X/M pathlimit <0-255>",
5735 "Specify a network to announce via BGP\n"
5736 "IPv6 prefix <network>/<length>\n"
5737 "AS-Path hopcount limit attribute\n"
5738 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5739ALIAS_DEPRECATED (no_ipv6_bgp_network,
5740 no_ipv6_bgp_network_ttl_cmd,
5741 "no network X:X::X:X/M pathlimit <0-255>",
5742 NO_STR
5743 "Specify a network to announce via BGP\n"
5744 "IPv6 prefix <network>/<length>\n"
5745 "AS-Path hopcount limit attribute\n"
5746 "AS-Pathlimit TTL, in number of AS-Path hops\n")
3bde17f1 5747#endif /* HAVE_IPV6 */
6b0655a2 5748
718e3744 5749/* Aggreagete address:
5750
5751 advertise-map Set condition to advertise attribute
5752 as-set Generate AS set path information
5753 attribute-map Set attributes of aggregate
5754 route-map Set parameters of aggregate
5755 summary-only Filter more specific routes from updates
5756 suppress-map Conditionally filter more specific routes from updates
5757 <cr>
5758 */
5759struct bgp_aggregate
5760{
5761 /* Summary-only flag. */
5762 u_char summary_only;
5763
5764 /* AS set generation. */
5765 u_char as_set;
5766
5767 /* Route-map for aggregated route. */
5768 struct route_map *map;
5769
5770 /* Suppress-count. */
5771 unsigned long count;
5772
5773 /* SAFI configuration. */
5774 safi_t safi;
5775};
5776
94f2b392 5777static struct bgp_aggregate *
66e5cd87 5778bgp_aggregate_new (void)
718e3744 5779{
393deb9b 5780 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
718e3744 5781}
5782
94f2b392 5783static void
718e3744 5784bgp_aggregate_free (struct bgp_aggregate *aggregate)
5785{
5786 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
5787}
5788
b5d58c32 5789/* Update an aggregate as routes are added/removed from the BGP table */
94f2b392 5790static void
718e3744 5791bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
5792 afi_t afi, safi_t safi, struct bgp_info *del,
5793 struct bgp_aggregate *aggregate)
5794{
5795 struct bgp_table *table;
5796 struct bgp_node *top;
5797 struct bgp_node *rn;
5798 u_char origin;
5799 struct aspath *aspath = NULL;
5800 struct aspath *asmerge = NULL;
5801 struct community *community = NULL;
5802 struct community *commerge = NULL;
5803 struct in_addr nexthop;
5804 u_int32_t med = 0;
5805 struct bgp_info *ri;
5806 struct bgp_info *new;
5807 int first = 1;
5808 unsigned long match = 0;
42f7e184 5809 u_char atomic_aggregate = 0;
718e3744 5810
5811 /* Record adding route's nexthop and med. */
5812 if (rinew)
5813 {
5814 nexthop = rinew->attr->nexthop;
5815 med = rinew->attr->med;
5816 }
5817
5818 /* ORIGIN attribute: If at least one route among routes that are
5819 aggregated has ORIGIN with the value INCOMPLETE, then the
5820 aggregated route must have the ORIGIN attribute with the value
5821 INCOMPLETE. Otherwise, if at least one route among routes that
5822 are aggregated has ORIGIN with the value EGP, then the aggregated
5823 route must have the origin attribute with the value EGP. In all
5824 other case the value of the ORIGIN attribute of the aggregated
5825 route is INTERNAL. */
5826 origin = BGP_ORIGIN_IGP;
5827
5828 table = bgp->rib[afi][safi];
5829
5830 top = bgp_node_get (table, p);
5831 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5832 if (rn->p.prefixlen > p->prefixlen)
5833 {
5834 match = 0;
5835
5836 for (ri = rn->info; ri; ri = ri->next)
5837 {
5838 if (BGP_INFO_HOLDDOWN (ri))
5839 continue;
5840
5841 if (del && ri == del)
5842 continue;
5843
5844 if (! rinew && first)
5845 {
5846 nexthop = ri->attr->nexthop;
5847 med = ri->attr->med;
5848 first = 0;
5849 }
5850
5851#ifdef AGGREGATE_NEXTHOP_CHECK
5852 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
5853 || ri->attr->med != med)
5854 {
5855 if (aspath)
5856 aspath_free (aspath);
5857 if (community)
5858 community_free (community);
5859 bgp_unlock_node (rn);
5860 bgp_unlock_node (top);
5861 return;
5862 }
5863#endif /* AGGREGATE_NEXTHOP_CHECK */
5864
42f7e184
DS
5865 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5866 atomic_aggregate = 1;
5867
718e3744 5868 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5869 {
5870 if (aggregate->summary_only)
5871 {
fb982c25 5872 (bgp_info_extra_get (ri))->suppress++;
1a392d46 5873 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5874 match++;
5875 }
5876
5877 aggregate->count++;
5878
b5d58c32
DS
5879 if (origin < ri->attr->origin)
5880 origin = ri->attr->origin;
5881
718e3744 5882 if (aggregate->as_set)
5883 {
718e3744 5884 if (aspath)
5885 {
5886 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5887 aspath_free (aspath);
5888 aspath = asmerge;
5889 }
5890 else
5891 aspath = aspath_dup (ri->attr->aspath);
5892
5893 if (ri->attr->community)
5894 {
5895 if (community)
5896 {
5897 commerge = community_merge (community,
5898 ri->attr->community);
5899 community = community_uniq_sort (commerge);
5900 community_free (commerge);
5901 }
5902 else
5903 community = community_dup (ri->attr->community);
5904 }
5905 }
5906 }
5907 }
5908 if (match)
5909 bgp_process (bgp, rn, afi, safi);
5910 }
5911 bgp_unlock_node (top);
5912
5913 if (rinew)
5914 {
5915 aggregate->count++;
5916
5917 if (aggregate->summary_only)
fb982c25 5918 (bgp_info_extra_get (rinew))->suppress++;
718e3744 5919
b5d58c32
DS
5920 if (origin < rinew->attr->origin)
5921 origin = rinew->attr->origin;
5922
718e3744 5923 if (aggregate->as_set)
5924 {
718e3744 5925 if (aspath)
5926 {
5927 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
5928 aspath_free (aspath);
5929 aspath = asmerge;
5930 }
5931 else
5932 aspath = aspath_dup (rinew->attr->aspath);
5933
5934 if (rinew->attr->community)
5935 {
5936 if (community)
5937 {
5938 commerge = community_merge (community,
5939 rinew->attr->community);
5940 community = community_uniq_sort (commerge);
5941 community_free (commerge);
5942 }
5943 else
5944 community = community_dup (rinew->attr->community);
5945 }
5946 }
5947 }
5948
5949 if (aggregate->count > 0)
5950 {
5951 rn = bgp_node_get (table, p);
7c8ff89e 5952 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 5953 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
5954 aggregate->as_set,
5955 atomic_aggregate), rn);
718e3744 5956 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 5957
5958 bgp_info_add (rn, new);
200df115 5959 bgp_unlock_node (rn);
718e3744 5960 bgp_process (bgp, rn, afi, safi);
5961 }
5962 else
5963 {
5964 if (aspath)
5965 aspath_free (aspath);
5966 if (community)
5967 community_free (community);
5968 }
5969}
5970
5971void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
5972 struct bgp_aggregate *);
5973
5974void
5975bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
5976 struct bgp_info *ri, afi_t afi, safi_t safi)
5977{
5978 struct bgp_node *child;
5979 struct bgp_node *rn;
5980 struct bgp_aggregate *aggregate;
f018db83 5981 struct bgp_table *table;
718e3744 5982
5983 /* MPLS-VPN aggregation is not yet supported. */
5984 if (safi == SAFI_MPLS_VPN)
5985 return;
5986
f018db83
JBD
5987 table = bgp->aggregate[afi][safi];
5988
5989 /* No aggregates configured. */
67174041 5990 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
5991 return;
5992
718e3744 5993 if (p->prefixlen == 0)
5994 return;
5995
5996 if (BGP_INFO_HOLDDOWN (ri))
5997 return;
5998
bb782fb5 5999 child = bgp_node_get (table, p);
718e3744 6000
6001 /* Aggregate address configuration check. */
67174041 6002 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 6003 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
6004 {
6005 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 6006 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
718e3744 6007 }
6008 bgp_unlock_node (child);
6009}
6010
6011void
6012bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
6013 struct bgp_info *del, afi_t afi, safi_t safi)
6014{
6015 struct bgp_node *child;
6016 struct bgp_node *rn;
6017 struct bgp_aggregate *aggregate;
f018db83 6018 struct bgp_table *table;
718e3744 6019
6020 /* MPLS-VPN aggregation is not yet supported. */
6021 if (safi == SAFI_MPLS_VPN)
6022 return;
6023
f018db83
JBD
6024 table = bgp->aggregate[afi][safi];
6025
6026 /* No aggregates configured. */
67174041 6027 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
6028 return;
6029
718e3744 6030 if (p->prefixlen == 0)
6031 return;
6032
bb782fb5 6033 child = bgp_node_get (table, p);
718e3744 6034
6035 /* Aggregate address configuration check. */
67174041 6036 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 6037 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
6038 {
6039 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 6040 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
718e3744 6041 }
6042 bgp_unlock_node (child);
6043}
6044
b5d58c32 6045/* Called via bgp_aggregate_set when the user configures aggregate-address */
94f2b392 6046static void
718e3744 6047bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
6048 struct bgp_aggregate *aggregate)
6049{
6050 struct bgp_table *table;
6051 struct bgp_node *top;
6052 struct bgp_node *rn;
6053 struct bgp_info *new;
6054 struct bgp_info *ri;
6055 unsigned long match;
6056 u_char origin = BGP_ORIGIN_IGP;
6057 struct aspath *aspath = NULL;
6058 struct aspath *asmerge = NULL;
6059 struct community *community = NULL;
6060 struct community *commerge = NULL;
42f7e184 6061 u_char atomic_aggregate = 0;
718e3744 6062
6063 table = bgp->rib[afi][safi];
6064
6065 /* Sanity check. */
6066 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
6067 return;
6068 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
6069 return;
6070
6071 /* If routes exists below this node, generate aggregate routes. */
6072 top = bgp_node_get (table, p);
6073 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
6074 if (rn->p.prefixlen > p->prefixlen)
6075 {
6076 match = 0;
6077
6078 for (ri = rn->info; ri; ri = ri->next)
6079 {
6080 if (BGP_INFO_HOLDDOWN (ri))
6081 continue;
6082
42f7e184
DS
6083 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6084 atomic_aggregate = 1;
6085
718e3744 6086 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
6087 {
6088 /* summary-only aggregate route suppress aggregated
6089 route announcement. */
6090 if (aggregate->summary_only)
6091 {
fb982c25 6092 (bgp_info_extra_get (ri))->suppress++;
1a392d46 6093 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 6094 match++;
6095 }
b5d58c32
DS
6096
6097 /* If at least one route among routes that are aggregated has
6098 * ORIGIN with the value INCOMPLETE, then the aggregated route
6099 * MUST have the ORIGIN attribute with the value INCOMPLETE.
6100 * Otherwise, if at least one route among routes that are
6101 * aggregated has ORIGIN with the value EGP, then the aggregated
6102 * route MUST have the ORIGIN attribute with the value EGP.
6103 */
6104 if (origin < ri->attr->origin)
6105 origin = ri->attr->origin;
6106
718e3744 6107 /* as-set aggregate route generate origin, as path,
6108 community aggregation. */
6109 if (aggregate->as_set)
6110 {
718e3744 6111 if (aspath)
6112 {
6113 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
6114 aspath_free (aspath);
6115 aspath = asmerge;
6116 }
6117 else
6118 aspath = aspath_dup (ri->attr->aspath);
6119
6120 if (ri->attr->community)
6121 {
6122 if (community)
6123 {
6124 commerge = community_merge (community,
6125 ri->attr->community);
6126 community = community_uniq_sort (commerge);
6127 community_free (commerge);
6128 }
6129 else
6130 community = community_dup (ri->attr->community);
6131 }
6132 }
6133 aggregate->count++;
6134 }
6135 }
6136
6137 /* If this node is suppressed, process the change. */
6138 if (match)
6139 bgp_process (bgp, rn, afi, safi);
6140 }
6141 bgp_unlock_node (top);
6142
6143 /* Add aggregate route to BGP table. */
6144 if (aggregate->count)
6145 {
6146 rn = bgp_node_get (table, p);
7c8ff89e 6147 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 6148 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
6149 aggregate->as_set,
6150 atomic_aggregate), rn);
718e3744 6151 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 6152
6153 bgp_info_add (rn, new);
200df115 6154 bgp_unlock_node (rn);
6155
718e3744 6156 /* Process change. */
6157 bgp_process (bgp, rn, afi, safi);
6158 }
6159}
6160
6161void
6162bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
6163 safi_t safi, struct bgp_aggregate *aggregate)
6164{
6165 struct bgp_table *table;
6166 struct bgp_node *top;
6167 struct bgp_node *rn;
6168 struct bgp_info *ri;
6169 unsigned long match;
6170
6171 table = bgp->rib[afi][safi];
6172
6173 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
6174 return;
6175 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
6176 return;
6177
6178 /* If routes exists below this node, generate aggregate routes. */
6179 top = bgp_node_get (table, p);
6180 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
6181 if (rn->p.prefixlen > p->prefixlen)
6182 {
6183 match = 0;
6184
6185 for (ri = rn->info; ri; ri = ri->next)
6186 {
6187 if (BGP_INFO_HOLDDOWN (ri))
6188 continue;
6189
6190 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
6191 {
fb982c25 6192 if (aggregate->summary_only && ri->extra)
718e3744 6193 {
fb982c25 6194 ri->extra->suppress--;
718e3744 6195
fb982c25 6196 if (ri->extra->suppress == 0)
718e3744 6197 {
1a392d46 6198 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 6199 match++;
6200 }
6201 }
6202 aggregate->count--;
6203 }
6204 }
6205
fb982c25 6206 /* If this node was suppressed, process the change. */
718e3744 6207 if (match)
6208 bgp_process (bgp, rn, afi, safi);
6209 }
6210 bgp_unlock_node (top);
6211
6212 /* Delete aggregate route from BGP table. */
6213 rn = bgp_node_get (table, p);
6214
6215 for (ri = rn->info; ri; ri = ri->next)
6216 if (ri->peer == bgp->peer_self
6217 && ri->type == ZEBRA_ROUTE_BGP
6218 && ri->sub_type == BGP_ROUTE_AGGREGATE)
6219 break;
6220
6221 /* Withdraw static BGP route from routing table. */
6222 if (ri)
6223 {
718e3744 6224 bgp_info_delete (rn, ri);
1a392d46 6225 bgp_process (bgp, rn, afi, safi);
718e3744 6226 }
6227
6228 /* Unlock bgp_node_lookup. */
6229 bgp_unlock_node (rn);
6230}
6231
6232/* Aggregate route attribute. */
6233#define AGGREGATE_SUMMARY_ONLY 1
6234#define AGGREGATE_AS_SET 1
6235
94f2b392 6236static int
f6269b4f
RB
6237bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
6238 afi_t afi, safi_t safi)
718e3744 6239{
6240 int ret;
6241 struct prefix p;
6242 struct bgp_node *rn;
6243 struct bgp *bgp;
6244 struct bgp_aggregate *aggregate;
6245
6246 /* Convert string to prefix structure. */
6247 ret = str2prefix (prefix_str, &p);
6248 if (!ret)
6249 {
6250 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
6251 return CMD_WARNING;
6252 }
6253 apply_mask (&p);
6254
6255 /* Get BGP structure. */
6256 bgp = vty->index;
6257
6258 /* Old configuration check. */
f6269b4f
RB
6259 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
6260 if (! rn)
718e3744 6261 {
f6269b4f
RB
6262 vty_out (vty, "%% There is no aggregate-address configuration.%s",
6263 VTY_NEWLINE);
718e3744 6264 return CMD_WARNING;
6265 }
6266
f6269b4f
RB
6267 aggregate = rn->info;
6268 if (aggregate->safi & SAFI_UNICAST)
6269 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
6270 if (aggregate->safi & SAFI_MULTICAST)
6271 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 6272
f6269b4f
RB
6273 /* Unlock aggregate address configuration. */
6274 rn->info = NULL;
6275 bgp_aggregate_free (aggregate);
6276 bgp_unlock_node (rn);
6277 bgp_unlock_node (rn);
718e3744 6278
6279 return CMD_SUCCESS;
6280}
6281
94f2b392 6282static int
f6269b4f
RB
6283bgp_aggregate_set (struct vty *vty, const char *prefix_str,
6284 afi_t afi, safi_t safi,
6285 u_char summary_only, u_char as_set)
718e3744 6286{
6287 int ret;
6288 struct prefix p;
6289 struct bgp_node *rn;
6290 struct bgp *bgp;
6291 struct bgp_aggregate *aggregate;
6292
6293 /* Convert string to prefix structure. */
6294 ret = str2prefix (prefix_str, &p);
6295 if (!ret)
6296 {
6297 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
6298 return CMD_WARNING;
6299 }
6300 apply_mask (&p);
6301
6302 /* Get BGP structure. */
6303 bgp = vty->index;
6304
6305 /* Old configuration check. */
f6269b4f
RB
6306 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
6307
6308 if (rn->info)
718e3744 6309 {
f6269b4f 6310 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
368473f6 6311 /* try to remove the old entry */
f6269b4f
RB
6312 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
6313 if (ret)
6314 {
368473f6
RB
6315 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
6316 bgp_unlock_node (rn);
f6269b4f
RB
6317 return CMD_WARNING;
6318 }
718e3744 6319 }
6320
f6269b4f
RB
6321 /* Make aggregate address structure. */
6322 aggregate = bgp_aggregate_new ();
6323 aggregate->summary_only = summary_only;
6324 aggregate->as_set = as_set;
6325 aggregate->safi = safi;
6326 rn->info = aggregate;
718e3744 6327
f6269b4f
RB
6328 /* Aggregate address insert into BGP routing table. */
6329 if (safi & SAFI_UNICAST)
6330 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
6331 if (safi & SAFI_MULTICAST)
6332 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 6333
6334 return CMD_SUCCESS;
6335}
6336
6337DEFUN (aggregate_address,
6338 aggregate_address_cmd,
6339 "aggregate-address A.B.C.D/M",
6340 "Configure BGP aggregate entries\n"
6341 "Aggregate prefix\n")
6342{
6343 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
6344}
6345
6346DEFUN (aggregate_address_mask,
6347 aggregate_address_mask_cmd,
6348 "aggregate-address A.B.C.D A.B.C.D",
6349 "Configure BGP aggregate entries\n"
6350 "Aggregate address\n"
6351 "Aggregate mask\n")
6352{
6353 int ret;
6354 char prefix_str[BUFSIZ];
6355
6356 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6357
6358 if (! ret)
6359 {
6360 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6361 return CMD_WARNING;
6362 }
6363
6364 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
6365 0, 0);
6366}
6367
6368DEFUN (aggregate_address_summary_only,
6369 aggregate_address_summary_only_cmd,
6370 "aggregate-address A.B.C.D/M summary-only",
6371 "Configure BGP aggregate entries\n"
6372 "Aggregate prefix\n"
6373 "Filter more specific routes from updates\n")
6374{
6375 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
6376 AGGREGATE_SUMMARY_ONLY, 0);
6377}
6378
6379DEFUN (aggregate_address_mask_summary_only,
6380 aggregate_address_mask_summary_only_cmd,
6381 "aggregate-address A.B.C.D A.B.C.D summary-only",
6382 "Configure BGP aggregate entries\n"
6383 "Aggregate address\n"
6384 "Aggregate mask\n"
6385 "Filter more specific routes from updates\n")
6386{
6387 int ret;
6388 char prefix_str[BUFSIZ];
6389
6390 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6391
6392 if (! ret)
6393 {
6394 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6395 return CMD_WARNING;
6396 }
6397
6398 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
6399 AGGREGATE_SUMMARY_ONLY, 0);
6400}
6401
6402DEFUN (aggregate_address_as_set,
6403 aggregate_address_as_set_cmd,
6404 "aggregate-address A.B.C.D/M as-set",
6405 "Configure BGP aggregate entries\n"
6406 "Aggregate prefix\n"
6407 "Generate AS set path information\n")
6408{
6409 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
6410 0, AGGREGATE_AS_SET);
6411}
6412
6413DEFUN (aggregate_address_mask_as_set,
6414 aggregate_address_mask_as_set_cmd,
6415 "aggregate-address A.B.C.D A.B.C.D as-set",
6416 "Configure BGP aggregate entries\n"
6417 "Aggregate address\n"
6418 "Aggregate mask\n"
6419 "Generate AS set path information\n")
6420{
6421 int ret;
6422 char prefix_str[BUFSIZ];
6423
6424 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6425
6426 if (! ret)
6427 {
6428 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6429 return CMD_WARNING;
6430 }
6431
6432 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
6433 0, AGGREGATE_AS_SET);
6434}
6435
6436
6437DEFUN (aggregate_address_as_set_summary,
6438 aggregate_address_as_set_summary_cmd,
6439 "aggregate-address A.B.C.D/M as-set summary-only",
6440 "Configure BGP aggregate entries\n"
6441 "Aggregate prefix\n"
6442 "Generate AS set path information\n"
6443 "Filter more specific routes from updates\n")
6444{
6445 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
6446 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
6447}
6448
6449ALIAS (aggregate_address_as_set_summary,
6450 aggregate_address_summary_as_set_cmd,
6451 "aggregate-address A.B.C.D/M summary-only as-set",
6452 "Configure BGP aggregate entries\n"
6453 "Aggregate prefix\n"
6454 "Filter more specific routes from updates\n"
6455 "Generate AS set path information\n")
6456
6457DEFUN (aggregate_address_mask_as_set_summary,
6458 aggregate_address_mask_as_set_summary_cmd,
6459 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
6460 "Configure BGP aggregate entries\n"
6461 "Aggregate address\n"
6462 "Aggregate mask\n"
6463 "Generate AS set path information\n"
6464 "Filter more specific routes from updates\n")
6465{
6466 int ret;
6467 char prefix_str[BUFSIZ];
6468
6469 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6470
6471 if (! ret)
6472 {
6473 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6474 return CMD_WARNING;
6475 }
6476
6477 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
6478 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
6479}
6480
6481ALIAS (aggregate_address_mask_as_set_summary,
6482 aggregate_address_mask_summary_as_set_cmd,
6483 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
6484 "Configure BGP aggregate entries\n"
6485 "Aggregate address\n"
6486 "Aggregate mask\n"
6487 "Filter more specific routes from updates\n"
6488 "Generate AS set path information\n")
6489
6490DEFUN (no_aggregate_address,
6491 no_aggregate_address_cmd,
6492 "no aggregate-address A.B.C.D/M",
6493 NO_STR
6494 "Configure BGP aggregate entries\n"
6495 "Aggregate prefix\n")
6496{
6497 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
6498}
6499
6500ALIAS (no_aggregate_address,
6501 no_aggregate_address_summary_only_cmd,
6502 "no aggregate-address A.B.C.D/M summary-only",
6503 NO_STR
6504 "Configure BGP aggregate entries\n"
6505 "Aggregate prefix\n"
6506 "Filter more specific routes from updates\n")
6507
6508ALIAS (no_aggregate_address,
6509 no_aggregate_address_as_set_cmd,
6510 "no aggregate-address A.B.C.D/M as-set",
6511 NO_STR
6512 "Configure BGP aggregate entries\n"
6513 "Aggregate prefix\n"
6514 "Generate AS set path information\n")
6515
6516ALIAS (no_aggregate_address,
6517 no_aggregate_address_as_set_summary_cmd,
6518 "no aggregate-address A.B.C.D/M as-set summary-only",
6519 NO_STR
6520 "Configure BGP aggregate entries\n"
6521 "Aggregate prefix\n"
6522 "Generate AS set path information\n"
6523 "Filter more specific routes from updates\n")
6524
6525ALIAS (no_aggregate_address,
6526 no_aggregate_address_summary_as_set_cmd,
6527 "no aggregate-address A.B.C.D/M summary-only as-set",
6528 NO_STR
6529 "Configure BGP aggregate entries\n"
6530 "Aggregate prefix\n"
6531 "Filter more specific routes from updates\n"
6532 "Generate AS set path information\n")
6533
6534DEFUN (no_aggregate_address_mask,
6535 no_aggregate_address_mask_cmd,
6536 "no aggregate-address A.B.C.D A.B.C.D",
6537 NO_STR
6538 "Configure BGP aggregate entries\n"
6539 "Aggregate address\n"
6540 "Aggregate mask\n")
6541{
6542 int ret;
6543 char prefix_str[BUFSIZ];
6544
6545 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6546
6547 if (! ret)
6548 {
6549 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6550 return CMD_WARNING;
6551 }
6552
6553 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
6554}
6555
6556ALIAS (no_aggregate_address_mask,
6557 no_aggregate_address_mask_summary_only_cmd,
6558 "no aggregate-address A.B.C.D A.B.C.D summary-only",
6559 NO_STR
6560 "Configure BGP aggregate entries\n"
6561 "Aggregate address\n"
6562 "Aggregate mask\n"
6563 "Filter more specific routes from updates\n")
6564
6565ALIAS (no_aggregate_address_mask,
6566 no_aggregate_address_mask_as_set_cmd,
6567 "no aggregate-address A.B.C.D A.B.C.D as-set",
6568 NO_STR
6569 "Configure BGP aggregate entries\n"
6570 "Aggregate address\n"
6571 "Aggregate mask\n"
6572 "Generate AS set path information\n")
6573
6574ALIAS (no_aggregate_address_mask,
6575 no_aggregate_address_mask_as_set_summary_cmd,
6576 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
6577 NO_STR
6578 "Configure BGP aggregate entries\n"
6579 "Aggregate address\n"
6580 "Aggregate mask\n"
6581 "Generate AS set path information\n"
6582 "Filter more specific routes from updates\n")
6583
6584ALIAS (no_aggregate_address_mask,
6585 no_aggregate_address_mask_summary_as_set_cmd,
6586 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
6587 NO_STR
6588 "Configure BGP aggregate entries\n"
6589 "Aggregate address\n"
6590 "Aggregate mask\n"
6591 "Filter more specific routes from updates\n"
6592 "Generate AS set path information\n")
6593
6594#ifdef HAVE_IPV6
6595DEFUN (ipv6_aggregate_address,
6596 ipv6_aggregate_address_cmd,
6597 "aggregate-address X:X::X:X/M",
6598 "Configure BGP aggregate entries\n"
6599 "Aggregate prefix\n")
6600{
6601 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
6602}
6603
6604DEFUN (ipv6_aggregate_address_summary_only,
6605 ipv6_aggregate_address_summary_only_cmd,
6606 "aggregate-address X:X::X:X/M summary-only",
6607 "Configure BGP aggregate entries\n"
6608 "Aggregate prefix\n"
6609 "Filter more specific routes from updates\n")
6610{
6611 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6612 AGGREGATE_SUMMARY_ONLY, 0);
6613}
6614
6615DEFUN (no_ipv6_aggregate_address,
6616 no_ipv6_aggregate_address_cmd,
6617 "no aggregate-address X:X::X:X/M",
6618 NO_STR
6619 "Configure BGP aggregate entries\n"
6620 "Aggregate prefix\n")
6621{
6622 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
6623}
6624
6625DEFUN (no_ipv6_aggregate_address_summary_only,
6626 no_ipv6_aggregate_address_summary_only_cmd,
6627 "no aggregate-address X:X::X:X/M summary-only",
6628 NO_STR
6629 "Configure BGP aggregate entries\n"
6630 "Aggregate prefix\n"
6631 "Filter more specific routes from updates\n")
6632{
6633 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
6634}
6635
6636ALIAS (ipv6_aggregate_address,
6637 old_ipv6_aggregate_address_cmd,
6638 "ipv6 bgp aggregate-address X:X::X:X/M",
6639 IPV6_STR
6640 BGP_STR
6641 "Configure BGP aggregate entries\n"
6642 "Aggregate prefix\n")
6643
6644ALIAS (ipv6_aggregate_address_summary_only,
6645 old_ipv6_aggregate_address_summary_only_cmd,
6646 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
6647 IPV6_STR
6648 BGP_STR
6649 "Configure BGP aggregate entries\n"
6650 "Aggregate prefix\n"
6651 "Filter more specific routes from updates\n")
6652
6653ALIAS (no_ipv6_aggregate_address,
6654 old_no_ipv6_aggregate_address_cmd,
6655 "no ipv6 bgp aggregate-address X:X::X:X/M",
6656 NO_STR
6657 IPV6_STR
6658 BGP_STR
6659 "Configure BGP aggregate entries\n"
6660 "Aggregate prefix\n")
6661
6662ALIAS (no_ipv6_aggregate_address_summary_only,
6663 old_no_ipv6_aggregate_address_summary_only_cmd,
6664 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
6665 NO_STR
6666 IPV6_STR
6667 BGP_STR
6668 "Configure BGP aggregate entries\n"
6669 "Aggregate prefix\n"
6670 "Filter more specific routes from updates\n")
6671#endif /* HAVE_IPV6 */
6b0655a2 6672
718e3744 6673/* Redistribute route treatment. */
6674void
f04a80a5 6675bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
bc413143 6676 const struct in6_addr *nexthop6, unsigned int ifindex,
7c8ff89e 6677 u_int32_t metric, u_char type, u_short instance, u_short tag)
718e3744 6678{
6679 struct bgp *bgp;
1eb8ef25 6680 struct listnode *node, *nnode;
718e3744 6681 struct bgp_info *new;
6682 struct bgp_info *bi;
6683 struct bgp_info info;
6684 struct bgp_node *bn;
e16a4133 6685 struct attr attr;
718e3744 6686 struct attr *new_attr;
6687 afi_t afi;
6688 int ret;
7c8ff89e 6689 struct bgp_redist *red;
718e3744 6690
6691 /* Make default attribute. */
6692 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
6693 if (nexthop)
6694 attr.nexthop = *nexthop;
bc413143 6695 attr.nh_ifindex = ifindex;
718e3744 6696
f04a80a5
SH
6697#ifdef HAVE_IPV6
6698 if (nexthop6)
6699 {
6700 struct attr_extra *extra = bgp_attr_extra_get(&attr);
6701 extra->mp_nexthop_global = *nexthop6;
801a9bcc 6702 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
f04a80a5
SH
6703 }
6704#endif
6705
718e3744 6706 attr.med = metric;
6707 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
0d9551dc 6708 attr.extra->tag = tag;
718e3744 6709
1eb8ef25 6710 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 6711 {
6712 afi = family2afi (p->family);
6713
7c8ff89e
DS
6714 red = bgp_redist_lookup(bgp, afi, type, instance);
6715 if (red)
718e3744 6716 {
558d1fec
JBD
6717 struct attr attr_new;
6718 struct attr_extra extra_new;
6719
718e3744 6720 /* Copy attribute for modification. */
558d1fec 6721 attr_new.extra = &extra_new;
fb982c25 6722 bgp_attr_dup (&attr_new, &attr);
718e3744 6723
7c8ff89e
DS
6724 if (red->redist_metric_flag)
6725 attr_new.med = red->redist_metric;
718e3744 6726
6727 /* Apply route-map. */
7c8ff89e 6728 if (red->rmap.map)
718e3744 6729 {
6730 info.peer = bgp->peer_self;
6731 info.attr = &attr_new;
6732
fee0f4c6 6733 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
6734
7c8ff89e 6735 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
fee0f4c6 6736
6737 bgp->peer_self->rmap_type = 0;
6738
718e3744 6739 if (ret == RMAP_DENYMATCH)
6740 {
6741 /* Free uninterned attribute. */
6742 bgp_attr_flush (&attr_new);
558d1fec 6743
718e3744 6744 /* Unintern original. */
f6f434b2 6745 aspath_unintern (&attr.aspath);
fb982c25 6746 bgp_attr_extra_free (&attr);
7c8ff89e 6747 bgp_redistribute_delete (p, type, instance);
718e3744 6748 return;
6749 }
6750 }
6751
fb982c25
PJ
6752 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
6753 afi, SAFI_UNICAST, p, NULL);
6754
718e3744 6755 new_attr = bgp_attr_intern (&attr_new);
558d1fec 6756
718e3744 6757 for (bi = bn->info; bi; bi = bi->next)
6758 if (bi->peer == bgp->peer_self
6759 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
6760 break;
6761
6762 if (bi)
6763 {
8d45210e
AS
6764 if (attrhash_cmp (bi->attr, new_attr) &&
6765 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
718e3744 6766 {
f6f434b2
PJ
6767 bgp_attr_unintern (&new_attr);
6768 aspath_unintern (&attr.aspath);
fb982c25 6769 bgp_attr_extra_free (&attr);
718e3744 6770 bgp_unlock_node (bn);
6771 return;
6772 }
6773 else
6774 {
6775 /* The attribute is changed. */
1a392d46 6776 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
718e3744 6777
6778 /* Rewrite BGP route information. */
8d45210e
AS
6779 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
6780 bgp_info_restore(bn, bi);
6781 else
6782 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
f6f434b2 6783 bgp_attr_unintern (&bi->attr);
718e3744 6784 bi->attr = new_attr;
65957886 6785 bi->uptime = bgp_clock ();
718e3744 6786
6787 /* Process change. */
6788 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
6789 bgp_process (bgp, bn, afi, SAFI_UNICAST);
6790 bgp_unlock_node (bn);
f6f434b2 6791 aspath_unintern (&attr.aspath);
fb982c25 6792 bgp_attr_extra_free (&attr);
718e3744 6793 return;
fb018d25 6794 }
718e3744 6795 }
6796
7c8ff89e 6797 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
fb018d25 6798 new_attr, bn);
718e3744 6799 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 6800
6801 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
6802 bgp_info_add (bn, new);
200df115 6803 bgp_unlock_node (bn);
718e3744 6804 bgp_process (bgp, bn, afi, SAFI_UNICAST);
6805 }
6806 }
6807
6808 /* Unintern original. */
f6f434b2 6809 aspath_unintern (&attr.aspath);
fb982c25 6810 bgp_attr_extra_free (&attr);
718e3744 6811}
6812
6813void
7c8ff89e 6814bgp_redistribute_delete (struct prefix *p, u_char type, u_short instance)
718e3744 6815{
6816 struct bgp *bgp;
1eb8ef25 6817 struct listnode *node, *nnode;
718e3744 6818 afi_t afi;
6819 struct bgp_node *rn;
6820 struct bgp_info *ri;
7c8ff89e 6821 struct bgp_redist *red;
718e3744 6822
1eb8ef25 6823 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 6824 {
6825 afi = family2afi (p->family);
6826
7c8ff89e
DS
6827 red = bgp_redist_lookup(bgp, afi, type, instance);
6828 if (red)
718e3744 6829 {
fee0f4c6 6830 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
718e3744 6831
6832 for (ri = rn->info; ri; ri = ri->next)
6833 if (ri->peer == bgp->peer_self
6834 && ri->type == type)
6835 break;
6836
6837 if (ri)
6838 {
6839 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
718e3744 6840 bgp_info_delete (rn, ri);
1a392d46 6841 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 6842 }
6843 bgp_unlock_node (rn);
6844 }
6845 }
6846}
6847
6848/* Withdraw specified route type's route. */
6849void
7c8ff89e 6850bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
718e3744 6851{
6852 struct bgp_node *rn;
6853 struct bgp_info *ri;
6854 struct bgp_table *table;
6855
6856 table = bgp->rib[afi][SAFI_UNICAST];
6857
6858 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6859 {
6860 for (ri = rn->info; ri; ri = ri->next)
6861 if (ri->peer == bgp->peer_self
7c8ff89e
DS
6862 && ri->type == type
6863 && ri->instance == instance)
718e3744 6864 break;
6865
6866 if (ri)
6867 {
6868 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
718e3744 6869 bgp_info_delete (rn, ri);
1a392d46 6870 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 6871 }
6872 }
6873}
6b0655a2 6874
718e3744 6875/* Static function to display route. */
94f2b392 6876static void
718e3744 6877route_vty_out_route (struct prefix *p, struct vty *vty)
6878{
6879 int len;
6880 u_int32_t destination;
6881 char buf[BUFSIZ];
6882
6883 if (p->family == AF_INET)
6884 {
6885 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
6886 destination = ntohl (p->u.prefix4.s_addr);
6887
6888 if ((IN_CLASSC (destination) && p->prefixlen == 24)
6889 || (IN_CLASSB (destination) && p->prefixlen == 16)
6890 || (IN_CLASSA (destination) && p->prefixlen == 8)
6891 || p->u.prefix4.s_addr == 0)
6892 {
6893 /* When mask is natural, mask is not displayed. */
6894 }
6895 else
6896 len += vty_out (vty, "/%d", p->prefixlen);
6897 }
6898 else
6899 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
6900 p->prefixlen);
6901
6902 len = 17 - len;
6903 if (len < 1)
6904 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
6905 else
6906 vty_out (vty, "%*s", len, " ");
6907}
6908
718e3744 6909enum bgp_display_type
6910{
6911 normal_list,
6912};
6913
b40d939b 6914/* Print the short form route status for a bgp_info */
6915static void
b05a1c8b
DS
6916route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
6917 json_object *json_path)
718e3744 6918{
b05a1c8b
DS
6919 json_object *json_boolean_false;
6920 json_object *json_boolean_true;
6921
6922 if (json_path)
6923 {
6924 json_boolean_false = json_object_new_boolean(0);
6925 json_boolean_true = json_object_new_boolean(1);
6926
6927 /* Route status display. */
6928 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6929 json_object_object_add(json_path, "removed", json_boolean_true);
6930
6931 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6932 json_object_object_add(json_path, "stale", json_boolean_true);
6933
6934 if (binfo->extra && binfo->extra->suppress)
6935 json_object_object_add(json_path, "suppressed", json_boolean_true);
6936
6937 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6938 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6939 json_object_object_add(json_path, "valid", json_boolean_true);
6940
6941 /* Selected */
6942 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6943 json_object_object_add(json_path, "history", json_boolean_true);
6944
6945 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6946 json_object_object_add(json_path, "damped", json_boolean_true);
6947
6948 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6949 json_object_object_add(json_path, "bestpath", json_boolean_true);
6950
6951 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6952 json_object_object_add(json_path, "multipath", json_boolean_true);
6953
6954 /* Internal route. */
6955 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6956 json_object_object_add(json_path, "internal", json_boolean_true);
6957 else
6958 json_object_object_add(json_path, "external", json_boolean_true);
6959
6960 return;
6961 }
6962
b40d939b 6963 /* Route status display. */
6964 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6965 vty_out (vty, "R");
6966 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
93406d87 6967 vty_out (vty, "S");
fb982c25 6968 else if (binfo->extra && binfo->extra->suppress)
718e3744 6969 vty_out (vty, "s");
31eba040
DS
6970 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6971 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
718e3744 6972 vty_out (vty, "*");
6973 else
6974 vty_out (vty, " ");
6975
6976 /* Selected */
6977 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6978 vty_out (vty, "h");
6979 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6980 vty_out (vty, "d");
6981 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6982 vty_out (vty, ">");
b366b518
BB
6983 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6984 vty_out (vty, "=");
718e3744 6985 else
6986 vty_out (vty, " ");
6987
6988 /* Internal route. */
b05a1c8b
DS
6989 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6990 vty_out (vty, "i");
6991 else
6992 vty_out (vty, " ");
b40d939b 6993}
6994
6995/* called from terminal list command */
6996void
6997route_vty_out (struct vty *vty, struct prefix *p,
b05a1c8b
DS
6998 struct bgp_info *binfo, int display, safi_t safi,
6999 json_object *json_paths)
b40d939b 7000{
7001 struct attr *attr;
b05a1c8b
DS
7002 json_object *json_path;
7003 json_object *json_int;
7004 json_object *json_string;
47fc97cc 7005
b05a1c8b
DS
7006 if (json_paths)
7007 json_path = json_object_new_object();
718e3744 7008 else
b05a1c8b
DS
7009 json_path = NULL;
7010
7011 /* short status lead text */
7012 route_vty_short_status_out (vty, binfo, json_path);
718e3744 7013
b05a1c8b
DS
7014 if (!json_paths)
7015 {
7016 /* print prefix and mask */
7017 if (! display)
7018 route_vty_out_route (p, vty);
7019 else
7020 vty_out (vty, "%*s", 17, " ");
7021 }
47fc97cc 7022
718e3744 7023 /* Print attribute */
7024 attr = binfo->attr;
7025 if (attr)
7026 {
b05a1c8b
DS
7027
7028 /* IPv4 Next Hop */
718e3744 7029 if (p->family == AF_INET)
7030 {
b05a1c8b
DS
7031 if (json_paths)
7032 {
7033 if (safi == SAFI_MPLS_VPN)
7034 {
7035 json_string = json_object_new_string(inet_ntoa (attr->extra->mp_nexthop_global_in));
7036 json_object_object_add(json_path, "nexthop", json_string);
7037 }
7038 else
7039 {
7040 json_string = json_object_new_string(inet_ntoa (attr->nexthop));
7041 json_object_object_add(json_path, "nexthop", json_string);
7042 }
7043 }
7044 else
7045 {
7046 if (safi == SAFI_MPLS_VPN)
7047 vty_out (vty, "%-16s",
7048 inet_ntoa (attr->extra->mp_nexthop_global_in));
7049 else
7050 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
7051 }
718e3744 7052 }
b05a1c8b
DS
7053
7054#ifdef HAVE_IPV6
7055 /* IPv6 Next Hop */
718e3744 7056 else if (p->family == AF_INET6)
7057 {
7058 int len;
7059 char buf[BUFSIZ];
7060
b05a1c8b
DS
7061 if (json_paths)
7062 {
7063 json_string = json_object_new_string(inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf, BUFSIZ));
7064 json_object_object_add(json_path, "nexthop", json_string);
7065 }
7066 else
7067 {
7068 len = vty_out (vty, "%s",
7069 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7070 buf, BUFSIZ));
7071 len = 16 - len;
7072 if (len < 1)
7073 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
7074 else
7075 vty_out (vty, "%*s", len, " ");
7076 }
718e3744 7077 }
7078#endif /* HAVE_IPV6 */
7079
b05a1c8b 7080 /* MED/Metric */
718e3744 7081 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b
DS
7082 if (json_paths)
7083 {
7084 json_int = json_object_new_int(attr->med);
7085 json_object_object_add(json_path, "med", json_int);
7086 }
7087 else
7088 vty_out (vty, "%10u", attr->med);
718e3744 7089 else
b05a1c8b
DS
7090 if (!json_paths)
7091 vty_out (vty, " ");
47fc97cc 7092
b05a1c8b 7093 /* Local Pref */
718e3744 7094 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
b05a1c8b
DS
7095 if (json_paths)
7096 {
7097 json_int = json_object_new_int(attr->local_pref);
7098 json_object_object_add(json_path, "localpref", json_int);
7099 }
7100 else
7101 vty_out (vty, "%7u", attr->local_pref);
718e3744 7102 else
b05a1c8b
DS
7103 if (!json_paths)
7104 vty_out (vty, " ");
718e3744 7105
b05a1c8b
DS
7106 if (json_paths)
7107 {
7108 if (attr->extra)
7109 json_int = json_object_new_int(attr->extra->weight);
7110 else
7111 json_int = json_object_new_int(0);
47fc97cc 7112
b05a1c8b
DS
7113 json_object_object_add(json_path, "weight", json_int);
7114 }
7115 else
7116 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
47fc97cc 7117
b2518c1e
PJ
7118 /* Print aspath */
7119 if (attr->aspath)
b05a1c8b
DS
7120 {
7121 if (json_paths)
7122 {
e5eee9af
DS
7123 if (!attr->aspath->str || aspath_count_hops (attr->aspath) == 0)
7124 json_string = json_object_new_string("Local");
7125 else
7126 json_string = json_object_new_string(attr->aspath->str);
b05a1c8b
DS
7127 json_object_object_add(json_path, "aspath", json_string);
7128 }
7129 else
7130 {
7131 aspath_print_vty (vty, "%s", attr->aspath, " ");
7132 }
7133 }
47fc97cc 7134
b2518c1e 7135 /* Print origin */
b05a1c8b
DS
7136 if (json_paths)
7137 {
7138 json_string = json_object_new_string(bgp_origin_str[attr->origin]);
7139 json_object_object_add(json_path, "origin", json_string);
7140 }
7141 else
7142 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 7143 }
b05a1c8b
DS
7144
7145 if (json_paths)
7146 json_object_array_add(json_paths, json_path);
7147 else
7148 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7149}
7150
7151/* called from terminal list command */
7152void
7153route_vty_out_tmp (struct vty *vty, struct prefix *p,
b05a1c8b 7154 struct attr *attr, safi_t safi)
718e3744 7155{
7156 /* Route status display. */
7157 vty_out (vty, "*");
7158 vty_out (vty, ">");
7159 vty_out (vty, " ");
7160
7161 /* print prefix and mask */
7162 route_vty_out_route (p, vty);
7163
7164 /* Print attribute */
7165 if (attr)
7166 {
7167 if (p->family == AF_INET)
7168 {
7169 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
7170 vty_out (vty, "%-16s",
7171 inet_ntoa (attr->extra->mp_nexthop_global_in));
718e3744 7172 else
7173 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
7174 }
7175#ifdef HAVE_IPV6
7176 else if (p->family == AF_INET6)
7177 {
7178 int len;
7179 char buf[BUFSIZ];
fb982c25
PJ
7180
7181 assert (attr->extra);
718e3744 7182
7183 len = vty_out (vty, "%s",
fb982c25
PJ
7184 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7185 buf, BUFSIZ));
718e3744 7186 len = 16 - len;
7187 if (len < 1)
7188 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
7189 else
7190 vty_out (vty, "%*s", len, " ");
7191 }
7192#endif /* HAVE_IPV6 */
7193
7194 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
c099baf6 7195 vty_out (vty, "%10u", attr->med);
718e3744 7196 else
7197 vty_out (vty, " ");
7198
7199 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
c099baf6 7200 vty_out (vty, "%7u", attr->local_pref);
718e3744 7201 else
7202 vty_out (vty, " ");
fb982c25 7203
c099baf6 7204 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
fb982c25 7205
b2518c1e
PJ
7206 /* Print aspath */
7207 if (attr->aspath)
841f7a57 7208 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 7209
b2518c1e 7210 /* Print origin */
718e3744 7211 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 7212 }
718e3744 7213
7214 vty_out (vty, "%s", VTY_NEWLINE);
7215}
7216
5a646650 7217void
718e3744 7218route_vty_out_tag (struct vty *vty, struct prefix *p,
7219 struct bgp_info *binfo, int display, safi_t safi)
7220{
7221 struct attr *attr;
718e3744 7222 u_int32_t label = 0;
fb982c25
PJ
7223
7224 if (!binfo->extra)
7225 return;
7226
b40d939b 7227 /* short status lead text */
b05a1c8b 7228 route_vty_short_status_out (vty, binfo, NULL);
b40d939b 7229
718e3744 7230 /* print prefix and mask */
7231 if (! display)
7232 route_vty_out_route (p, vty);
7233 else
7234 vty_out (vty, "%*s", 17, " ");
7235
7236 /* Print attribute */
7237 attr = binfo->attr;
7238 if (attr)
7239 {
7240 if (p->family == AF_INET)
7241 {
7242 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
7243 vty_out (vty, "%-16s",
7244 inet_ntoa (attr->extra->mp_nexthop_global_in));
718e3744 7245 else
7246 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
7247 }
7248#ifdef HAVE_IPV6
7249 else if (p->family == AF_INET6)
7250 {
fb982c25 7251 assert (attr->extra);
718e3744 7252 char buf[BUFSIZ];
7253 char buf1[BUFSIZ];
801a9bcc 7254 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
718e3744 7255 vty_out (vty, "%s",
fb982c25
PJ
7256 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7257 buf, BUFSIZ));
801a9bcc 7258 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
718e3744 7259 vty_out (vty, "%s(%s)",
fb982c25
PJ
7260 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7261 buf, BUFSIZ),
7262 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7263 buf1, BUFSIZ));
718e3744 7264
7265 }
7266#endif /* HAVE_IPV6 */
7267 }
7268
fb982c25 7269 label = decode_label (binfo->extra->tag);
718e3744 7270
7271 vty_out (vty, "notag/%d", label);
7272
7273 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7274}
7275
7276/* dampening route */
5a646650 7277static void
718e3744 7278damp_route_vty_out (struct vty *vty, struct prefix *p,
7279 struct bgp_info *binfo, int display, safi_t safi)
7280{
7281 struct attr *attr;
718e3744 7282 int len;
50aef6f3 7283 char timebuf[BGP_UPTIME_LEN];
718e3744 7284
b40d939b 7285 /* short status lead text */
b05a1c8b 7286 route_vty_short_status_out (vty, binfo, NULL);
b40d939b 7287
718e3744 7288 /* print prefix and mask */
7289 if (! display)
7290 route_vty_out_route (p, vty);
7291 else
7292 vty_out (vty, "%*s", 17, " ");
7293
7294 len = vty_out (vty, "%s", binfo->peer->host);
7295 len = 17 - len;
7296 if (len < 1)
7297 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
7298 else
7299 vty_out (vty, "%*s", len, " ");
7300
50aef6f3 7301 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
718e3744 7302
7303 /* Print attribute */
7304 attr = binfo->attr;
7305 if (attr)
7306 {
7307 /* Print aspath */
7308 if (attr->aspath)
841f7a57 7309 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 7310
7311 /* Print origin */
b2518c1e 7312 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 7313 }
7314 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7315}
7316
718e3744 7317/* flap route */
5a646650 7318static void
718e3744 7319flap_route_vty_out (struct vty *vty, struct prefix *p,
7320 struct bgp_info *binfo, int display, safi_t safi)
7321{
7322 struct attr *attr;
7323 struct bgp_damp_info *bdi;
718e3744 7324 char timebuf[BGP_UPTIME_LEN];
7325 int len;
fb982c25
PJ
7326
7327 if (!binfo->extra)
7328 return;
7329
7330 bdi = binfo->extra->damp_info;
718e3744 7331
b40d939b 7332 /* short status lead text */
b05a1c8b 7333 route_vty_short_status_out (vty, binfo, NULL);
b40d939b 7334
718e3744 7335 /* print prefix and mask */
7336 if (! display)
7337 route_vty_out_route (p, vty);
7338 else
7339 vty_out (vty, "%*s", 17, " ");
7340
7341 len = vty_out (vty, "%s", binfo->peer->host);
7342 len = 16 - len;
7343 if (len < 1)
7344 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
7345 else
7346 vty_out (vty, "%*s", len, " ");
7347
7348 len = vty_out (vty, "%d", bdi->flap);
7349 len = 5 - len;
7350 if (len < 1)
7351 vty_out (vty, " ");
7352 else
7353 vty_out (vty, "%*s ", len, " ");
7354
7355 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
7356 timebuf, BGP_UPTIME_LEN));
7357
7358 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
7359 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
50aef6f3 7360 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
718e3744 7361 else
7362 vty_out (vty, "%*s ", 8, " ");
7363
7364 /* Print attribute */
7365 attr = binfo->attr;
7366 if (attr)
7367 {
7368 /* Print aspath */
7369 if (attr->aspath)
841f7a57 7370 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 7371
7372 /* Print origin */
b2518c1e 7373 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 7374 }
7375 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7376}
7377
94f2b392 7378static void
718e3744 7379route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
b05a1c8b
DS
7380 struct bgp_info *binfo, afi_t afi, safi_t safi,
7381 json_object *json_paths)
718e3744 7382{
7383 char buf[INET6_ADDRSTRLEN];
7384 char buf1[BUFSIZ];
7385 struct attr *attr;
7386 int sockunion_vty_out (struct vty *, union sockunion *);
30b00176
JK
7387#ifdef HAVE_CLOCK_MONOTONIC
7388 time_t tbuf;
7389#endif
b05a1c8b
DS
7390 json_object *json_int;
7391 json_object *json_string;
7392 json_object *json_path;
7393 json_object *json_boolean_false;
7394 json_object *json_boolean_true;
7395 json_object *json_cluster_list;
7396
7397 if (json_paths)
7398 {
7399 json_path = json_object_new_object();
7400 json_boolean_false = json_object_new_boolean(0);
7401 json_boolean_true = json_object_new_boolean(1);
7402 json_cluster_list = json_object_new_array();
7403 }
7404
718e3744 7405 attr = binfo->attr;
7406
7407 if (attr)
7408 {
7409 /* Line1 display AS-path, Aggregator */
7410 if (attr->aspath)
7411 {
b05a1c8b
DS
7412 if (!json_paths)
7413 vty_out (vty, " ");
7414
fe69a505 7415 if (aspath_count_hops (attr->aspath) == 0)
b05a1c8b
DS
7416 {
7417 if (json_paths)
7418 json_string = json_object_new_string("Local");
7419 else
7420 vty_out (vty, "Local");
7421 }
718e3744 7422 else
b05a1c8b
DS
7423 {
7424 if (json_paths)
7425 json_string = json_object_new_string(attr->aspath->str);
7426 else
7427 aspath_print_vty (vty, "%s", attr->aspath, "");
7428 }
7429
7430 if (json_paths)
7431 json_object_object_add(json_path, "aspath", json_string);
718e3744 7432 }
7433
b40d939b 7434 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
b05a1c8b
DS
7435 {
7436 if (json_paths)
7437 json_object_object_add(json_path, "removed", json_boolean_true);
7438 else
7439 vty_out (vty, ", (removed)");
7440 }
7441
93406d87 7442 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
b05a1c8b
DS
7443 {
7444 if (json_paths)
7445 json_object_object_add(json_path, "stale", json_boolean_true);
7446 else
7447 vty_out (vty, ", (stale)");
7448 }
7449
93406d87 7450 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
b05a1c8b
DS
7451 {
7452 if (json_paths)
7453 {
7454 json_int = json_object_new_int(attr->extra->aggregator_as);
7455 json_string = json_object_new_string(inet_ntoa (attr->extra->aggregator_addr));
7456 json_object_object_add(json_path, "aggregator-as", json_int);
7457 json_object_object_add(json_path, "aggregator-id", json_string);
7458 }
7459 else
7460 {
7461 vty_out (vty, ", (aggregated by %u %s)",
7462 attr->extra->aggregator_as,
7463 inet_ntoa (attr->extra->aggregator_addr));
7464 }
7465 }
7466
93406d87 7467 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
b05a1c8b
DS
7468 {
7469 if (json_paths)
7470 json_object_object_add(json_path, "rxed-from-rr-client", json_boolean_true);
7471 else
7472 vty_out (vty, ", (Received from a RR-client)");
7473 }
7474
93406d87 7475 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
b05a1c8b
DS
7476 {
7477 if (json_paths)
7478 json_object_object_add(json_path, "rxed-from-rs-client", json_boolean_true);
7479 else
7480 vty_out (vty, ", (Received from a RS-client)");
7481 }
7482
93406d87 7483 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
7484 {
7485 if (json_paths)
7486 json_object_object_add(json_path, "dampening-history-entry", json_boolean_true);
7487 else
7488 vty_out (vty, ", (history entry)");
7489 }
93406d87 7490 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
b05a1c8b
DS
7491 {
7492 if (json_paths)
7493 json_object_object_add(json_path, "dampening-suppressed", json_boolean_true);
7494 else
7495 vty_out (vty, ", (suppressed due to dampening)");
7496 }
7497
7498 if (!json_paths)
7499 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7500
7501 /* Line2 display Next-hop, Neighbor, Router-id */
7502 if (p->family == AF_INET)
7503 {
b05a1c8b
DS
7504 if (safi == SAFI_MPLS_VPN)
7505 {
7506 if (json_paths)
7507 json_string = json_object_new_string(inet_ntoa (attr->extra->mp_nexthop_global_in));
7508 else
7509 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
7510 }
7511 else
7512 {
7513 if (json_paths)
7514 json_string = json_object_new_string(inet_ntoa (attr->nexthop));
7515 else
7516 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
7517 }
7518
7519 if (json_paths)
7520 json_object_object_add(json_path, "nexthop", json_string);
718e3744 7521 }
7522#ifdef HAVE_IPV6
7523 else
7524 {
fb982c25 7525 assert (attr->extra);
b05a1c8b
DS
7526 if (json_paths)
7527 {
7528 json_string = json_object_new_string(inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7529 buf, INET6_ADDRSTRLEN));
7530 json_object_object_add(json_path, "nexthop", json_string);
7531 }
7532 else
7533 {
7534 vty_out (vty, " %s",
7535 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7536 buf, INET6_ADDRSTRLEN));
7537 }
718e3744 7538 }
7539#endif /* HAVE_IPV6 */
7540
7541 if (binfo->peer == bgp->peer_self)
7542 {
b05a1c8b
DS
7543
7544 if (p->family == AF_INET)
7545 {
7546 if (json_paths)
7547 json_string = json_object_new_string("0.0.0.0");
7548 else
7549 vty_out (vty, " from 0.0.0.0 ");
7550 }
7551 else
7552 {
7553 if (json_paths)
7554 json_string = json_object_new_string("::");
7555 else
7556 vty_out (vty, " from :: ");
7557 }
7558
7559 if (json_paths)
7560 {
7561 json_object_object_add(json_path, "peer-ip", json_string);
7562 json_string = json_object_new_string(inet_ntoa(bgp->router_id));
7563 json_object_object_add(json_path, "peer-id", json_string);
7564 }
7565 else
7566 {
7567 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
7568 }
718e3744 7569 }
7570 else
7571 {
7572 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
b05a1c8b
DS
7573 {
7574 if (json_paths)
7575 json_object_object_add(json_path, "nexthop-accessible", json_boolean_false);
7576 else
7577 vty_out (vty, " (inaccessible)");
7578 }
fb982c25 7579 else if (binfo->extra && binfo->extra->igpmetric)
b05a1c8b
DS
7580 {
7581 if (json_paths)
7582 {
7583 json_int = json_object_new_int(binfo->extra->igpmetric);
7584 json_object_object_add(json_path, "nexthop-igp-cost", json_int);
7585 json_object_object_add(json_path, "nexthop-accessible", json_boolean_true);
7586 }
7587 else
7588 {
7589 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
7590 }
7591 }
7592
7593 /* IGP cost to nexthop is 0 */
7594 else
7595 if (json_paths)
7596 json_object_object_add(json_path, "nexthop-accessible", json_boolean_true);
7597
7598 if (json_paths)
7599 {
7600 json_string = json_object_new_string(sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7601 json_object_object_add(json_path, "peer-ip", json_string);
036a4e7d
DS
7602
7603 if (binfo->peer->conf_if)
7604 {
7605 json_string = json_object_new_string(binfo->peer->conf_if);
7606 json_object_object_add(json_path, "peer-interface", json_string);
7607 }
b05a1c8b
DS
7608 }
7609 else
7610 {
036a4e7d
DS
7611 if (binfo->peer->conf_if)
7612 vty_out (vty, " from %s", binfo->peer->conf_if);
7613 else
7614 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
b05a1c8b
DS
7615
7616 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7617 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
7618 else
7619 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
7620 }
7621
7622 /* Always encode the peer's router-id in the json output. We will
7623 * include the originator-id later if this is a reflected route.
7624 */
7625 if (json_paths)
7626 {
7627 json_string = json_object_new_string(inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
7628 json_object_object_add(json_path, "peer-id", json_string);
7629 }
718e3744 7630 }
b05a1c8b
DS
7631
7632 if (!json_paths)
7633 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7634
7635#ifdef HAVE_IPV6
7636 /* display nexthop local */
801a9bcc 7637 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
718e3744 7638 {
b05a1c8b
DS
7639 if (json_paths)
7640 {
7641 json_string = json_object_new_string(inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7642 buf, INET6_ADDRSTRLEN));
7643 json_object_object_add(json_path, "nexthop-local", json_string);
7644 }
7645 else
7646 {
7647 vty_out (vty, " (%s)%s",
7648 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7649 buf, INET6_ADDRSTRLEN),
7650 VTY_NEWLINE);
7651 }
718e3744 7652 }
7653#endif /* HAVE_IPV6 */
7654
0d9551dc 7655 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
b05a1c8b
DS
7656 if (json_paths)
7657 {
7658 json_string = json_object_new_string(bgp_origin_long_str[attr->origin]);
7659 json_object_object_add(json_path, "origin", json_string);
7660 }
7661 else
7662 {
7663 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
7664 }
718e3744 7665
7666 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b
DS
7667 {
7668 if (json_paths)
7669 {
7670 json_int = json_object_new_int(attr->med);
7671 json_object_object_add(json_path, "med", json_int);
7672 }
7673 else
7674 {
7675 vty_out (vty, ", metric %u", attr->med);
7676 }
7677 }
718e3744 7678
7679 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
b05a1c8b
DS
7680 {
7681 if (json_paths)
7682 {
7683 json_int = json_object_new_int(attr->local_pref);
7684 json_object_object_add(json_path, "localpref", json_int);
7685 }
7686 else
7687 {
7688 vty_out (vty, ", localpref %u", attr->local_pref);
7689 }
7690 }
718e3744 7691 else
b05a1c8b
DS
7692 {
7693 if (json_paths)
7694 {
7695 json_int = json_object_new_int(bgp->default_local_pref);
7696 json_object_object_add(json_path, "localpref", json_int);
7697 }
7698 else
7699 {
7700 vty_out (vty, ", localpref %u", bgp->default_local_pref);
7701 }
7702 }
718e3744 7703
fb982c25 7704 if (attr->extra && attr->extra->weight != 0)
b05a1c8b
DS
7705 {
7706 if (json_paths)
7707 {
7708 json_int = json_object_new_int(attr->extra->weight);
7709 json_object_object_add(json_path, "weight", json_int);
7710 }
7711 else
7712 {
7713 vty_out (vty, ", weight %u", attr->extra->weight);
7714 }
7715 }
0d9551dc
DS
7716
7717 if (attr->extra && attr->extra->tag != 0)
b05a1c8b
DS
7718 {
7719 if (json_paths)
7720 {
7721 json_int = json_object_new_int(attr->extra->tag);
7722 json_object_object_add(json_path, "tag", json_int);
7723 }
7724 else
7725 {
7726 vty_out (vty, ", tag %d", attr->extra->tag);
7727 }
7728 }
718e3744 7729
31eba040 7730 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
b05a1c8b
DS
7731 {
7732 if (json_paths)
7733 json_object_object_add(json_path, "valid", json_boolean_false);
7734 else
7735 vty_out (vty, ", invalid");
7736 }
31eba040 7737 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
7738 {
7739 if (json_paths)
7740 json_object_object_add(json_path, "valid", json_boolean_true);
7741 else
7742 vty_out (vty, ", valid");
7743 }
718e3744 7744
7745 if (binfo->peer != bgp->peer_self)
7746 {
7747 if (binfo->peer->as == binfo->peer->local_as)
b05a1c8b
DS
7748 {
7749 if (json_paths)
7750 json_object_object_add(json_path, "internal", json_boolean_true);
7751 else
7752 vty_out (vty, ", internal");
7753 }
718e3744 7754 else
b05a1c8b
DS
7755 {
7756 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
7757 {
7758 if (json_paths)
7759 json_object_object_add(json_path, "confed-external", json_boolean_true);
7760 else
7761 vty_out (vty, ", confed-external");
7762 }
7763 else
7764 {
7765 if (json_paths)
7766 json_object_object_add(json_path, "external", json_boolean_true);
7767 else
7768 vty_out (vty, ", external");
7769 }
7770 }
718e3744 7771 }
7772 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
b05a1c8b
DS
7773 {
7774 if (json_paths)
7775 {
7776 json_object_object_add(json_path, "aggregated", json_boolean_true);
7777 json_object_object_add(json_path, "local", json_boolean_true);
7778 }
7779 else
7780 {
7781 vty_out (vty, ", aggregated, local");
7782 }
7783 }
718e3744 7784 else if (binfo->type != ZEBRA_ROUTE_BGP)
b05a1c8b
DS
7785 {
7786 if (json_paths)
7787 json_object_object_add(json_path, "sourced", json_boolean_true);
7788 else
7789 vty_out (vty, ", sourced");
7790 }
718e3744 7791 else
b05a1c8b
DS
7792 {
7793 if (json_paths)
7794 {
7795 json_object_object_add(json_path, "sourced", json_boolean_true);
7796 json_object_object_add(json_path, "local", json_boolean_true);
7797 }
7798 else
7799 {
7800 vty_out (vty, ", sourced, local");
7801 }
7802 }
718e3744 7803
7804 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
b05a1c8b
DS
7805 {
7806 if (json_paths)
7807 json_object_object_add(json_path, "atomic-aggregate", json_boolean_true);
7808 else
7809 vty_out (vty, ", atomic-aggregate");
7810 }
718e3744 7811
de8d5dff
JB
7812 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
7813 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
7814 bgp_info_mpath_count (binfo)))
b05a1c8b
DS
7815 {
7816 if (json_paths)
7817 json_object_object_add(json_path, "multipath", json_boolean_true);
7818 else
7819 vty_out (vty, ", multipath");
7820 }
de8d5dff 7821
718e3744 7822 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
b05a1c8b
DS
7823 {
7824 if (json_paths)
7825 json_object_object_add(json_path, "bestpath", json_boolean_true);
7826 else
7827 vty_out (vty, ", best");
7828 }
718e3744 7829
b05a1c8b
DS
7830 if (!json_paths)
7831 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7832
7833 /* Line 4 display Community */
7834 if (attr->community)
b05a1c8b
DS
7835 {
7836 if (json_paths)
7837 {
7838 json_string = json_object_new_string(attr->community->str);
7839 json_object_object_add(json_path, "community", json_string);
7840 }
7841 else
7842 {
7843 vty_out (vty, " Community: %s%s", attr->community->str,
7844 VTY_NEWLINE);
7845 }
7846 }
718e3744 7847
7848 /* Line 5 display Extended-community */
7849 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
b05a1c8b
DS
7850 {
7851 if (json_paths)
7852 {
7853 json_string = json_object_new_string(attr->extra->ecommunity->str);
7854 json_object_object_add(json_path, "extended-community", json_string);
7855 }
7856 else
7857 {
7858 vty_out (vty, " Extended Community: %s%s",
7859 attr->extra->ecommunity->str, VTY_NEWLINE);
7860 }
7861 }
7862
718e3744 7863 /* Line 6 display Originator, Cluster-id */
7864 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
7865 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
7866 {
fb982c25 7867 assert (attr->extra);
718e3744 7868 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
b05a1c8b
DS
7869 {
7870 if (json_paths)
7871 {
7872 json_string = json_object_new_string(inet_ntoa (attr->extra->originator_id));
7873 json_object_object_add(json_path, "originator-id", json_string);
7874 }
7875 else
7876 {
7877 vty_out (vty, " Originator: %s",
7878 inet_ntoa (attr->extra->originator_id));
7879 }
7880 }
718e3744 7881
7882 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
7883 {
7884 int i;
b05a1c8b
DS
7885
7886 if (json_paths)
7887 {
7888 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7889 {
7890 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
7891 json_object_array_add(json_cluster_list, json_string);
7892 }
7893 json_object_object_add(json_path, "cluster-list", json_cluster_list);
7894 }
7895 else
7896 {
7897 vty_out (vty, ", Cluster list: ");
7898
7899 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7900 {
7901 vty_out (vty, "%s ",
7902 inet_ntoa (attr->extra->cluster->list[i]));
7903 }
7904 }
718e3744 7905 }
b05a1c8b
DS
7906
7907 if (!json_paths)
7908 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7909 }
b05a1c8b 7910
fb982c25 7911 if (binfo->extra && binfo->extra->damp_info)
b05a1c8b 7912 bgp_damp_info_vty (vty, binfo, json_path);
718e3744 7913
a82478b9
DS
7914 /* Line 7 display Addpath IDs */
7915 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
b05a1c8b
DS
7916 {
7917 if (json_paths)
7918 {
7919 json_int = json_object_new_int(binfo->addpath_rx_id);
7920 json_object_object_add(json_path, "addpath-rx-id", json_int);
7921
7922 json_int = json_object_new_int(binfo->addpath_tx_id);
7923 json_object_object_add(json_path, "addpath-tx-id", json_int);
7924 }
7925 else
7926 {
7927 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
7928 binfo->addpath_rx_id, binfo->addpath_tx_id,
7929 VTY_NEWLINE);
7930 }
7931 }
a82478b9
DS
7932
7933 /* Line 8 display Uptime */
30b00176
JK
7934#ifdef HAVE_CLOCK_MONOTONIC
7935 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
b05a1c8b
DS
7936 if (json_paths)
7937 json_string = json_object_new_string(ctime(&tbuf));
7938 else
7939 vty_out (vty, " Last update: %s", ctime(&tbuf));
30b00176 7940#else
b05a1c8b
DS
7941 if (json_paths)
7942 json_string = json_object_new_string(ctime(&binfo->uptime));
7943 else
7944 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
30b00176 7945#endif /* HAVE_CLOCK_MONOTONIC */
b05a1c8b
DS
7946 if (json_paths)
7947 json_object_object_add(json_path, "last-update", json_string);
718e3744 7948 }
b05a1c8b
DS
7949
7950 /* We've constructed the json object for this path, add it to the json
7951 * array of paths
7952 */
7953 if (json_paths)
7954 json_object_array_add(json_paths, json_path);
7955 else
7956 vty_out (vty, "%s", VTY_NEWLINE);
b366b518
BB
7957}
7958
47fc97cc 7959#define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
718e3744 7960#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7961#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7962
7963enum bgp_show_type
7964{
7965 bgp_show_type_normal,
7966 bgp_show_type_regexp,
7967 bgp_show_type_prefix_list,
7968 bgp_show_type_filter_list,
7969 bgp_show_type_route_map,
7970 bgp_show_type_neighbor,
7971 bgp_show_type_cidr_only,
7972 bgp_show_type_prefix_longer,
7973 bgp_show_type_community_all,
7974 bgp_show_type_community,
7975 bgp_show_type_community_exact,
7976 bgp_show_type_community_list,
7977 bgp_show_type_community_list_exact,
7978 bgp_show_type_flap_statistics,
7979 bgp_show_type_flap_address,
7980 bgp_show_type_flap_prefix,
7981 bgp_show_type_flap_cidr_only,
7982 bgp_show_type_flap_regexp,
7983 bgp_show_type_flap_filter_list,
7984 bgp_show_type_flap_prefix_list,
7985 bgp_show_type_flap_prefix_longer,
7986 bgp_show_type_flap_route_map,
7987 bgp_show_type_flap_neighbor,
7988 bgp_show_type_dampend_paths,
7989 bgp_show_type_damp_neighbor
7990};
7991
5a646650 7992static int
fee0f4c6 7993bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
b05a1c8b 7994 enum bgp_show_type type, void *output_arg, u_char use_json)
718e3744 7995{
718e3744 7996 struct bgp_info *ri;
7997 struct bgp_node *rn;
718e3744 7998 int header = 1;
718e3744 7999 int display;
5a646650 8000 unsigned long output_count;
b05a1c8b
DS
8001 struct prefix *p;
8002 char buf[BUFSIZ];
8003 char buf2[BUFSIZ];
8004 json_object *json;
8005 json_object *json_int;
8006 json_object *json_paths;
8007 json_object *json_routes;
8008 json_object *json_string;
8009
8010 if (use_json)
8011 {
8012 json = json_object_new_object();
8013 json_int = json_object_new_int(table->version);
8014 json_object_object_add(json, "table-version", json_int);
8015
8016 json_string = json_object_new_string(inet_ntoa (*router_id));
8017 json_object_object_add(json, "router-id", json_string);
8018
8019 json_routes = json_object_new_object();
8020 }
718e3744 8021
8022 /* This is first entry point, so reset total line. */
5a646650 8023 output_count = 0;
718e3744 8024
718e3744 8025 /* Start processing of routes. */
8026 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
8027 if (rn->info != NULL)
8028 {
8029 display = 0;
8030
b05a1c8b
DS
8031 if (use_json)
8032 json_paths = json_object_new_array();
8033 else
8034 json_paths = NULL;
8035
718e3744 8036 for (ri = rn->info; ri; ri = ri->next)
8037 {
5a646650 8038 if (type == bgp_show_type_flap_statistics
718e3744 8039 || type == bgp_show_type_flap_address
8040 || type == bgp_show_type_flap_prefix
8041 || type == bgp_show_type_flap_cidr_only
8042 || type == bgp_show_type_flap_regexp
8043 || type == bgp_show_type_flap_filter_list
8044 || type == bgp_show_type_flap_prefix_list
8045 || type == bgp_show_type_flap_prefix_longer
8046 || type == bgp_show_type_flap_route_map
8047 || type == bgp_show_type_flap_neighbor
8048 || type == bgp_show_type_dampend_paths
8049 || type == bgp_show_type_damp_neighbor)
8050 {
fb982c25 8051 if (!(ri->extra && ri->extra->damp_info))
718e3744 8052 continue;
8053 }
8054 if (type == bgp_show_type_regexp
8055 || type == bgp_show_type_flap_regexp)
8056 {
5a646650 8057 regex_t *regex = output_arg;
718e3744 8058
8059 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
8060 continue;
8061 }
8062 if (type == bgp_show_type_prefix_list
8063 || type == bgp_show_type_flap_prefix_list)
8064 {
5a646650 8065 struct prefix_list *plist = output_arg;
718e3744 8066
8067 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
8068 continue;
8069 }
8070 if (type == bgp_show_type_filter_list
8071 || type == bgp_show_type_flap_filter_list)
8072 {
5a646650 8073 struct as_list *as_list = output_arg;
718e3744 8074
8075 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
8076 continue;
8077 }
8078 if (type == bgp_show_type_route_map
8079 || type == bgp_show_type_flap_route_map)
8080 {
5a646650 8081 struct route_map *rmap = output_arg;
718e3744 8082 struct bgp_info binfo;
558d1fec
JBD
8083 struct attr dummy_attr;
8084 struct attr_extra dummy_extra;
718e3744 8085 int ret;
8086
558d1fec 8087 dummy_attr.extra = &dummy_extra;
fb982c25 8088 bgp_attr_dup (&dummy_attr, ri->attr);
558d1fec 8089
718e3744 8090 binfo.peer = ri->peer;
8091 binfo.attr = &dummy_attr;
8092
8093 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
718e3744 8094 if (ret == RMAP_DENYMATCH)
8095 continue;
8096 }
8097 if (type == bgp_show_type_neighbor
8098 || type == bgp_show_type_flap_neighbor
8099 || type == bgp_show_type_damp_neighbor)
8100 {
5a646650 8101 union sockunion *su = output_arg;
718e3744 8102
8103 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
8104 continue;
8105 }
8106 if (type == bgp_show_type_cidr_only
8107 || type == bgp_show_type_flap_cidr_only)
8108 {
8109 u_int32_t destination;
8110
8111 destination = ntohl (rn->p.u.prefix4.s_addr);
8112 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
8113 continue;
8114 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
8115 continue;
8116 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
8117 continue;
8118 }
8119 if (type == bgp_show_type_prefix_longer
8120 || type == bgp_show_type_flap_prefix_longer)
8121 {
5a646650 8122 struct prefix *p = output_arg;
718e3744 8123
8124 if (! prefix_match (p, &rn->p))
8125 continue;
8126 }
8127 if (type == bgp_show_type_community_all)
8128 {
8129 if (! ri->attr->community)
8130 continue;
8131 }
8132 if (type == bgp_show_type_community)
8133 {
5a646650 8134 struct community *com = output_arg;
718e3744 8135
8136 if (! ri->attr->community ||
8137 ! community_match (ri->attr->community, com))
8138 continue;
8139 }
8140 if (type == bgp_show_type_community_exact)
8141 {
5a646650 8142 struct community *com = output_arg;
718e3744 8143
8144 if (! ri->attr->community ||
8145 ! community_cmp (ri->attr->community, com))
8146 continue;
8147 }
8148 if (type == bgp_show_type_community_list)
8149 {
5a646650 8150 struct community_list *list = output_arg;
718e3744 8151
8152 if (! community_list_match (ri->attr->community, list))
8153 continue;
8154 }
8155 if (type == bgp_show_type_community_list_exact)
8156 {
5a646650 8157 struct community_list *list = output_arg;
718e3744 8158
8159 if (! community_list_exact_match (ri->attr->community, list))
8160 continue;
8161 }
8162 if (type == bgp_show_type_flap_address
8163 || type == bgp_show_type_flap_prefix)
8164 {
5a646650 8165 struct prefix *p = output_arg;
718e3744 8166
8167 if (! prefix_match (&rn->p, p))
8168 continue;
8169
8170 if (type == bgp_show_type_flap_prefix)
8171 if (p->prefixlen != rn->p.prefixlen)
8172 continue;
8173 }
8174 if (type == bgp_show_type_dampend_paths
8175 || type == bgp_show_type_damp_neighbor)
8176 {
8177 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
8178 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
8179 continue;
8180 }
8181
b05a1c8b 8182 if (!use_json && header)
718e3744 8183 {
3f9c7369 8184 vty_out (vty, "BGP table version is %llu, local router ID is %s%s", table->version, inet_ntoa (*router_id), VTY_NEWLINE);
93406d87 8185 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8186 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 8187 if (type == bgp_show_type_dampend_paths
8188 || type == bgp_show_type_damp_neighbor)
8189 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
8190 else if (type == bgp_show_type_flap_statistics
8191 || type == bgp_show_type_flap_address
8192 || type == bgp_show_type_flap_prefix
8193 || type == bgp_show_type_flap_cidr_only
8194 || type == bgp_show_type_flap_regexp
8195 || type == bgp_show_type_flap_filter_list
8196 || type == bgp_show_type_flap_prefix_list
8197 || type == bgp_show_type_flap_prefix_longer
8198 || type == bgp_show_type_flap_route_map
8199 || type == bgp_show_type_flap_neighbor)
8200 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
8201 else
8202 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
718e3744 8203 header = 0;
8204 }
8205
8206 if (type == bgp_show_type_dampend_paths
8207 || type == bgp_show_type_damp_neighbor)
5a646650 8208 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
718e3744 8209 else if (type == bgp_show_type_flap_statistics
8210 || type == bgp_show_type_flap_address
8211 || type == bgp_show_type_flap_prefix
8212 || type == bgp_show_type_flap_cidr_only
8213 || type == bgp_show_type_flap_regexp
8214 || type == bgp_show_type_flap_filter_list
8215 || type == bgp_show_type_flap_prefix_list
8216 || type == bgp_show_type_flap_prefix_longer
8217 || type == bgp_show_type_flap_route_map
8218 || type == bgp_show_type_flap_neighbor)
5a646650 8219 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
718e3744 8220 else
b05a1c8b 8221 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
718e3744 8222 display++;
8223 }
b05a1c8b
DS
8224
8225 if (use_json)
8226 {
8227 p = &rn->p;
8228 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
8229 json_object_object_add(json_routes, buf2, json_paths);
8230 }
8231
718e3744 8232 if (display)
5a646650 8233 output_count++;
718e3744 8234 }
8235
b05a1c8b 8236 if (use_json)
718e3744 8237 {
b05a1c8b
DS
8238 json_object_object_add(json, "routes", json_routes);
8239 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
8240
8241 // Recursively free all json structures
8242 json_object_put(json);
718e3744 8243 }
8244 else
b05a1c8b
DS
8245 {
8246 /* No route is displayed */
8247 if (output_count == 0)
8248 {
8249 if (type == bgp_show_type_normal)
8250 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
8251 }
8252 else
8253 vty_out (vty, "%sTotal number of prefixes %ld%s",
8254 VTY_NEWLINE, output_count, VTY_NEWLINE);
8255 }
718e3744 8256
8257 return CMD_SUCCESS;
8258}
8259
5a646650 8260static int
fee0f4c6 8261bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
b05a1c8b 8262 enum bgp_show_type type, void *output_arg, u_char use_json)
fee0f4c6 8263{
8264 struct bgp_table *table;
8265
8266 if (bgp == NULL) {
8267 bgp = bgp_get_default ();
8268 }
8269
8270 if (bgp == NULL)
8271 {
8272 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8273 return CMD_WARNING;
8274 }
8275
8276
8277 table = bgp->rib[afi][safi];
8278
b05a1c8b 8279 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg, use_json);
fee0f4c6 8280}
8281
718e3744 8282/* Header of detailed BGP route information */
94f2b392 8283static void
718e3744 8284route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
8285 struct bgp_node *rn,
b05a1c8b
DS
8286 struct prefix_rd *prd, afi_t afi, safi_t safi,
8287 json_object *json)
718e3744 8288{
8289 struct bgp_info *ri;
8290 struct prefix *p;
8291 struct peer *peer;
1eb8ef25 8292 struct listnode *node, *nnode;
718e3744 8293 char buf1[INET6_ADDRSTRLEN];
8294 char buf2[INET6_ADDRSTRLEN];
8295 int count = 0;
8296 int best = 0;
8297 int suppress = 0;
8298 int no_export = 0;
8299 int no_advertise = 0;
8300 int local_as = 0;
8301 int first = 0;
b05a1c8b
DS
8302 json_object *json_string;
8303 json_object *json_int;
8304 json_object *json_adv_to;
718e3744 8305
8306 p = &rn->p;
b05a1c8b
DS
8307
8308 if (json)
8309 {
8310 json_string = json_object_new_string(inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
8311 json_object_object_add(json, "prefix", json_string);
8312
8313 json_int = json_object_new_int(p->prefixlen);
8314 json_object_object_add(json, "prefixlen", json_int);
8315 json_adv_to = json_object_new_array();
8316 }
8317 else
8318 {
8319 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
8320 (safi == SAFI_MPLS_VPN ?
8321 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
8322 safi == SAFI_MPLS_VPN ? ":" : "",
8323 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
8324 p->prefixlen, VTY_NEWLINE);
8325 }
718e3744 8326
8327 for (ri = rn->info; ri; ri = ri->next)
8328 {
8329 count++;
8330 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
8331 {
8332 best = count;
fb982c25 8333 if (ri->extra && ri->extra->suppress)
718e3744 8334 suppress = 1;
8335 if (ri->attr->community != NULL)
8336 {
8337 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
8338 no_advertise = 1;
8339 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
8340 no_export = 1;
8341 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
8342 local_as = 1;
8343 }
8344 }
8345 }
8346
b05a1c8b 8347 if (!json)
718e3744 8348 {
b05a1c8b
DS
8349 vty_out (vty, "Paths: (%d available", count);
8350 if (best)
8351 {
8352 vty_out (vty, ", best #%d", best);
8353 if (safi == SAFI_UNICAST)
8354 vty_out (vty, ", table Default-IP-Routing-Table");
8355 }
8356 else
8357 vty_out (vty, ", no best path");
8358
8359 if (no_advertise)
8360 vty_out (vty, ", not advertised to any peer");
8361 else if (no_export)
8362 vty_out (vty, ", not advertised to EBGP peer");
8363 else if (local_as)
8364 vty_out (vty, ", not advertised outside local AS");
8365
8366 if (suppress)
8367 vty_out (vty, ", Advertisements suppressed by an aggregate.");
8368 vty_out (vty, ")%s", VTY_NEWLINE);
718e3744 8369 }
718e3744 8370
8371 /* advertised peer */
1eb8ef25 8372 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
718e3744 8373 {
8374 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
8375 {
b05a1c8b
DS
8376 if (json)
8377 {
036a4e7d
DS
8378 if (peer->conf_if)
8379 {
8380 json_string = json_object_new_string(peer->conf_if);
8381 json_object_array_add(json_adv_to, json_string);
8382 }
8383 else
8384 {
8385 json_string = json_object_new_string(sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
8386 json_object_array_add(json_adv_to, json_string);
8387 }
b05a1c8b
DS
8388 }
8389 else
8390 {
8391 if (! first)
8392 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
036a4e7d
DS
8393
8394 if (peer->conf_if)
8395 vty_out (vty, " %s", peer->conf_if);
8396 else
8397 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
b05a1c8b
DS
8398 }
8399 first = 1;
718e3744 8400 }
8401 }
b05a1c8b
DS
8402
8403 if (json)
8404 {
8405 if (first)
8406 {
8407 json_object_object_add(json, "advertised-to", json_adv_to);
8408 }
8409 }
8410 else
8411 {
8412 if (!first)
8413 vty_out (vty, " Not advertised to any peer");
8414 vty_out (vty, "%s", VTY_NEWLINE);
8415 }
718e3744 8416}
8417
8418/* Display specified route of BGP table. */
94f2b392 8419static int
fee0f4c6 8420bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
fd79ac91 8421 struct bgp_table *rib, const char *ip_str,
8422 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
8423 int prefix_check, enum bgp_path_type pathtype,
8424 u_char use_json)
718e3744 8425{
8426 int ret;
8427 int header;
8428 int display = 0;
8429 struct prefix match;
8430 struct bgp_node *rn;
8431 struct bgp_node *rm;
8432 struct bgp_info *ri;
718e3744 8433 struct bgp_table *table;
b05a1c8b
DS
8434 json_object *json;
8435 json_object *json_paths;
718e3744 8436
718e3744 8437 /* Check IP address argument. */
8438 ret = str2prefix (ip_str, &match);
8439 if (! ret)
8440 {
8441 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
8442 return CMD_WARNING;
8443 }
8444
8445 match.family = afi2family (afi);
8446
b05a1c8b
DS
8447 if (use_json)
8448 {
8449 json = json_object_new_object();
8450 json_paths = json_object_new_array();
8451 }
8452 else
8453 {
8454 json = NULL;
8455 json_paths = NULL;
8456 }
8457
718e3744 8458 if (safi == SAFI_MPLS_VPN)
8459 {
fee0f4c6 8460 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
718e3744 8461 {
8462 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
8463 continue;
8464
8465 if ((table = rn->info) != NULL)
8466 {
8467 header = 1;
8468
8469 if ((rm = bgp_node_match (table, &match)) != NULL)
8470 {
8471 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6c88b44d
CC
8472 {
8473 bgp_unlock_node (rm);
8474 continue;
8475 }
718e3744 8476
8477 for (ri = rm->info; ri; ri = ri->next)
8478 {
8479 if (header)
8480 {
8481 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
b05a1c8b 8482 AFI_IP, SAFI_MPLS_VPN, json);
718e3744 8483
8484 header = 0;
8485 }
8486 display++;
4092b06c
DS
8487
8488 if (pathtype == BGP_PATH_ALL ||
8489 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8490 (pathtype == BGP_PATH_MULTIPATH &&
8491 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
b05a1c8b 8492 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN, json_paths);
718e3744 8493 }
6c88b44d
CC
8494
8495 bgp_unlock_node (rm);
718e3744 8496 }
8497 }
8498 }
8499 }
8500 else
8501 {
8502 header = 1;
8503
fee0f4c6 8504 if ((rn = bgp_node_match (rib, &match)) != NULL)
718e3744 8505 {
8506 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
8507 {
8508 for (ri = rn->info; ri; ri = ri->next)
8509 {
8510 if (header)
8511 {
b05a1c8b 8512 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
718e3744 8513 header = 0;
8514 }
8515 display++;
4092b06c
DS
8516
8517 if (pathtype == BGP_PATH_ALL ||
8518 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8519 (pathtype == BGP_PATH_MULTIPATH &&
8520 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
b05a1c8b 8521 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
718e3744 8522 }
8523 }
6c88b44d
CC
8524
8525 bgp_unlock_node (rn);
718e3744 8526 }
8527 }
8528
e5eee9af 8529 if (use_json)
718e3744 8530 {
e5eee9af
DS
8531 if (display)
8532 json_object_object_add(json, "paths", json_paths);
8533
8534 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
8535
8536 // Recursively free all json structures
8537 json_object_put(json);
b05a1c8b
DS
8538 }
8539 else
8540 {
e5eee9af 8541 if (!display)
b05a1c8b
DS
8542 {
8543 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
8544 return CMD_WARNING;
8545 }
8546 }
8547
718e3744 8548 return CMD_SUCCESS;
8549}
8550
fee0f4c6 8551/* Display specified route of Main RIB */
94f2b392 8552static int
fd79ac91 8553bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
fee0f4c6 8554 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
8555 int prefix_check, enum bgp_path_type pathtype,
8556 u_char use_json)
fee0f4c6 8557{
8558 struct bgp *bgp;
8559
8560 /* BGP structure lookup. */
8561 if (view_name)
8562 {
8563 bgp = bgp_lookup_by_name (view_name);
8564 if (bgp == NULL)
8565 {
8566 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8567 return CMD_WARNING;
8568 }
8569 }
8570 else
8571 {
8572 bgp = bgp_get_default ();
8573 if (bgp == NULL)
8574 {
8575 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8576 return CMD_WARNING;
8577 }
8578 }
8579
8580 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
b05a1c8b
DS
8581 afi, safi, prd, prefix_check, pathtype,
8582 use_json);
fee0f4c6 8583}
8584
718e3744 8585/* BGP route print out function. */
8586DEFUN (show_ip_bgp,
8587 show_ip_bgp_cmd,
b05a1c8b 8588 "show ip bgp {json}",
47fc97cc
DS
8589 SHOW_STR
8590 IP_STR
b05a1c8b
DS
8591 BGP_STR
8592 "JavaScript Object Notation\n")
47fc97cc 8593{
b05a1c8b
DS
8594 u_char use_json = (argv[0] != NULL);
8595 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
718e3744 8596}
8597
8598DEFUN (show_ip_bgp_ipv4,
8599 show_ip_bgp_ipv4_cmd,
b05a1c8b 8600 "show ip bgp ipv4 (unicast|multicast) {json}",
718e3744 8601 SHOW_STR
8602 IP_STR
8603 BGP_STR
8604 "Address family\n"
8605 "Address Family modifier\n"
b05a1c8b
DS
8606 "Address Family modifier\n"
8607 "JavaScript Object Notation\n")
718e3744 8608{
b05a1c8b
DS
8609 u_char use_json = (argv[1] != NULL);
8610
718e3744 8611 if (strncmp (argv[0], "m", 1) == 0)
5a646650 8612 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
b05a1c8b 8613 NULL, use_json);
718e3744 8614
b05a1c8b 8615 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
718e3744 8616}
8617
95cbbd2a
ML
8618ALIAS (show_ip_bgp_ipv4,
8619 show_bgp_ipv4_safi_cmd,
b05a1c8b 8620 "show bgp ipv4 (unicast|multicast) {json}",
95cbbd2a
ML
8621 SHOW_STR
8622 BGP_STR
8623 "Address family\n"
8624 "Address Family modifier\n"
47fc97cc 8625 "Address Family modifier\n"
b05a1c8b 8626 "JavaScript Object Notation\n")
47fc97cc 8627
718e3744 8628DEFUN (show_ip_bgp_route,
8629 show_ip_bgp_route_cmd,
b05a1c8b 8630 "show ip bgp A.B.C.D {json}",
718e3744 8631 SHOW_STR
8632 IP_STR
8633 BGP_STR
b05a1c8b
DS
8634 "Network in the BGP routing table to display\n"
8635 "JavaScript Object Notation\n")
718e3744 8636{
b05a1c8b
DS
8637 u_char use_json = (argv[1] != NULL);
8638 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
4092b06c
DS
8639}
8640
8641DEFUN (show_ip_bgp_route_pathtype,
8642 show_ip_bgp_route_pathtype_cmd,
b05a1c8b 8643 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
4092b06c
DS
8644 SHOW_STR
8645 IP_STR
8646 BGP_STR
8647 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8648 "Display only the bestpath\n"
b05a1c8b
DS
8649 "Display only multipaths\n"
8650 "JavaScript Object Notation\n")
4092b06c 8651{
b05a1c8b
DS
8652 u_char use_json = (argv[2] != NULL);
8653
4092b06c 8654 if (strncmp (argv[1], "b", 1) == 0)
b05a1c8b 8655 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8656 else
b05a1c8b 8657 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8658}
8659
8660DEFUN (show_bgp_ipv4_safi_route_pathtype,
8661 show_bgp_ipv4_safi_route_pathtype_cmd,
b05a1c8b 8662 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath) {json}",
4092b06c
DS
8663 SHOW_STR
8664 BGP_STR
8665 "Address family\n"
8666 "Address Family modifier\n"
8667 "Address Family modifier\n"
8668 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8669 "Display only the bestpath\n"
b05a1c8b
DS
8670 "Display only multipaths\n"
8671 "JavaScript Object Notation\n")
4092b06c 8672{
b05a1c8b
DS
8673 u_char use_json = (argv[3] != NULL);
8674
4092b06c
DS
8675 if (strncmp (argv[0], "m", 1) == 0)
8676 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8677 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8678 else
b05a1c8b 8679 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8680 else
8681 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8682 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8683 else
b05a1c8b 8684 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
718e3744 8685}
8686
8687DEFUN (show_ip_bgp_ipv4_route,
8688 show_ip_bgp_ipv4_route_cmd,
b05a1c8b 8689 "show ip bgp ipv4 (unicast|multicast) A.B.C.D {json}",
718e3744 8690 SHOW_STR
8691 IP_STR
8692 BGP_STR
8693 "Address family\n"
8694 "Address Family modifier\n"
8695 "Address Family modifier\n"
b05a1c8b
DS
8696 "Network in the BGP routing table to display\n"
8697 "JavaScript Object Notation\n")
718e3744 8698{
b05a1c8b
DS
8699 u_char use_json = (argv[2] != NULL);
8700
718e3744 8701 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 8702 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8703
b05a1c8b 8704 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8705}
8706
95cbbd2a
ML
8707ALIAS (show_ip_bgp_ipv4_route,
8708 show_bgp_ipv4_safi_route_cmd,
b05a1c8b 8709 "show bgp ipv4 (unicast|multicast) A.B.C.D {json}",
95cbbd2a
ML
8710 SHOW_STR
8711 BGP_STR
8712 "Address family\n"
8713 "Address Family modifier\n"
8714 "Address Family modifier\n"
b05a1c8b
DS
8715 "Network in the BGP routing table to display\n"
8716 "JavaScript Object Notation\n")
95cbbd2a 8717
718e3744 8718DEFUN (show_ip_bgp_vpnv4_all_route,
8719 show_ip_bgp_vpnv4_all_route_cmd,
b05a1c8b 8720 "show ip bgp vpnv4 all A.B.C.D {json}",
718e3744 8721 SHOW_STR
8722 IP_STR
8723 BGP_STR
8724 "Display VPNv4 NLRI specific information\n"
8725 "Display information about all VPNv4 NLRIs\n"
b05a1c8b
DS
8726 "Network in the BGP routing table to display\n"
8727 "JavaScript Object Notation\n")
718e3744 8728{
b05a1c8b
DS
8729 u_char use_json = (argv[1] != NULL);
8730 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8731}
8732
4092b06c 8733
718e3744 8734DEFUN (show_ip_bgp_vpnv4_rd_route,
8735 show_ip_bgp_vpnv4_rd_route_cmd,
b05a1c8b 8736 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
718e3744 8737 SHOW_STR
8738 IP_STR
8739 BGP_STR
8740 "Display VPNv4 NLRI specific information\n"
8741 "Display information for a route distinguisher\n"
8742 "VPN Route Distinguisher\n"
b05a1c8b
DS
8743 "Network in the BGP routing table to display\n"
8744 "JavaScript Object Notation\n")
718e3744 8745{
8746 int ret;
8747 struct prefix_rd prd;
b05a1c8b 8748 u_char use_json = (argv[2] != NULL);
718e3744 8749
8750 ret = str2prefix_rd (argv[0], &prd);
8751 if (! ret)
8752 {
8753 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8754 return CMD_WARNING;
8755 }
b05a1c8b 8756 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json);
718e3744 8757}
8758
8759DEFUN (show_ip_bgp_prefix,
8760 show_ip_bgp_prefix_cmd,
b05a1c8b 8761 "show ip bgp A.B.C.D/M {json}",
718e3744 8762 SHOW_STR
8763 IP_STR
8764 BGP_STR
b05a1c8b
DS
8765 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8766 "JavaScript Object Notation\n")
718e3744 8767{
b05a1c8b
DS
8768 u_char use_json = (argv[1] != NULL);
8769 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
4092b06c
DS
8770}
8771
8772DEFUN (show_ip_bgp_prefix_pathtype,
8773 show_ip_bgp_prefix_pathtype_cmd,
b05a1c8b 8774 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8775 SHOW_STR
8776 IP_STR
8777 BGP_STR
8778 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8779 "Display only the bestpath\n"
b05a1c8b
DS
8780 "Display only multipaths\n"
8781 "JavaScript Object Notation\n")
4092b06c 8782{
b05a1c8b 8783 u_char use_json = (argv[2] != NULL);
4092b06c 8784 if (strncmp (argv[1], "b", 1) == 0)
b05a1c8b 8785 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8786 else
b05a1c8b 8787 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
718e3744 8788}
8789
8790DEFUN (show_ip_bgp_ipv4_prefix,
8791 show_ip_bgp_ipv4_prefix_cmd,
b05a1c8b 8792 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
718e3744 8793 SHOW_STR
8794 IP_STR
8795 BGP_STR
8796 "Address family\n"
8797 "Address Family modifier\n"
8798 "Address Family modifier\n"
b05a1c8b
DS
8799 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8800 "JavaScript Object Notation\n")
718e3744 8801{
b05a1c8b
DS
8802 u_char use_json = (argv[2] != NULL);
8803
718e3744 8804 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 8805 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8806
b05a1c8b 8807 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8808}
8809
95cbbd2a
ML
8810ALIAS (show_ip_bgp_ipv4_prefix,
8811 show_bgp_ipv4_safi_prefix_cmd,
b05a1c8b 8812 "show bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
95cbbd2a
ML
8813 SHOW_STR
8814 BGP_STR
8815 "Address family\n"
8816 "Address Family modifier\n"
8817 "Address Family modifier\n"
b05a1c8b
DS
8818 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8819 "JavaScript Object Notation\n")
95cbbd2a 8820
4092b06c
DS
8821DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
8822 show_ip_bgp_ipv4_prefix_pathtype_cmd,
b05a1c8b 8823 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8824 SHOW_STR
8825 IP_STR
8826 BGP_STR
8827 "Address family\n"
8828 "Address Family modifier\n"
8829 "Address Family modifier\n"
8830 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8831 "Display only the bestpath\n"
b05a1c8b
DS
8832 "Display only multipaths\n"
8833 "JavaScript Object Notation\n")
4092b06c 8834{
b05a1c8b
DS
8835 u_char use_json = (argv[3] != NULL);
8836
4092b06c
DS
8837 if (strncmp (argv[0], "m", 1) == 0)
8838 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8839 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8840 else
b05a1c8b 8841 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8842 else
8843 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8844 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8845 else
b05a1c8b 8846 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8847}
8848
8849ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
8850 show_bgp_ipv4_safi_prefix_pathtype_cmd,
b05a1c8b 8851 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8852 SHOW_STR
8853 BGP_STR
8854 "Address family\n"
8855 "Address Family modifier\n"
8856 "Address Family modifier\n"
8857 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8858 "Display only the bestpath\n"
b05a1c8b
DS
8859 "Display only multipaths\n"
8860 "JavaScript Object Notation\n")
4092b06c 8861
718e3744 8862DEFUN (show_ip_bgp_vpnv4_all_prefix,
8863 show_ip_bgp_vpnv4_all_prefix_cmd,
b05a1c8b 8864 "show ip bgp vpnv4 all A.B.C.D/M {json}",
718e3744 8865 SHOW_STR
8866 IP_STR
8867 BGP_STR
8868 "Display VPNv4 NLRI specific information\n"
8869 "Display information about all VPNv4 NLRIs\n"
b05a1c8b
DS
8870 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8871 "JavaScript Object Notation\n")
718e3744 8872{
b05a1c8b
DS
8873 u_char use_json = (argv[1] != NULL);
8874 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8875}
8876
8877DEFUN (show_ip_bgp_vpnv4_rd_prefix,
8878 show_ip_bgp_vpnv4_rd_prefix_cmd,
b05a1c8b 8879 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
718e3744 8880 SHOW_STR
8881 IP_STR
8882 BGP_STR
8883 "Display VPNv4 NLRI specific information\n"
8884 "Display information for a route distinguisher\n"
8885 "VPN Route Distinguisher\n"
b05a1c8b
DS
8886 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8887 "JavaScript Object Notation\n")
718e3744 8888{
8889 int ret;
8890 struct prefix_rd prd;
b05a1c8b 8891 u_char use_json = (argv[2] != NULL);
718e3744 8892
8893 ret = str2prefix_rd (argv[0], &prd);
8894 if (! ret)
8895 {
8896 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8897 return CMD_WARNING;
8898 }
b05a1c8b 8899 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json);
718e3744 8900}
8901
8902DEFUN (show_ip_bgp_view,
8903 show_ip_bgp_view_cmd,
b05a1c8b 8904 "show ip bgp view WORD {json}",
718e3744 8905 SHOW_STR
8906 IP_STR
8907 BGP_STR
8908 "BGP view\n"
b05a1c8b
DS
8909 "View name\n"
8910 "JavaScript Object Notation\n")
718e3744 8911{
bb46e94f 8912 struct bgp *bgp;
b05a1c8b 8913 u_char use_json = (argv[1] != NULL);
bb46e94f 8914
8915 /* BGP structure lookup. */
8916 bgp = bgp_lookup_by_name (argv[0]);
8917 if (bgp == NULL)
8918 {
8919 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8920 return CMD_WARNING;
8921 }
8922
b05a1c8b 8923 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
718e3744 8924}
8925
8926DEFUN (show_ip_bgp_view_route,
8927 show_ip_bgp_view_route_cmd,
b05a1c8b 8928 "show ip bgp view WORD A.B.C.D {json}",
718e3744 8929 SHOW_STR
8930 IP_STR
8931 BGP_STR
8932 "BGP view\n"
2b00515a 8933 "View name\n"
b05a1c8b
DS
8934 "Network in the BGP routing table to display\n"
8935 "JavaScript Object Notation\n")
718e3744 8936{
b05a1c8b
DS
8937 u_char use_json = (argv[2] != NULL);
8938 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8939}
8940
8941DEFUN (show_ip_bgp_view_prefix,
8942 show_ip_bgp_view_prefix_cmd,
b05a1c8b 8943 "show ip bgp view WORD A.B.C.D/M {json}",
718e3744 8944 SHOW_STR
8945 IP_STR
8946 BGP_STR
8947 "BGP view\n"
2b00515a 8948 "View name\n"
b05a1c8b
DS
8949 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8950 "JavaScript Object Notation\n")
718e3744 8951{
b05a1c8b
DS
8952 u_char use_json = (argv[2] != NULL);
8953 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8954}
8955
8956#ifdef HAVE_IPV6
8957DEFUN (show_bgp,
8958 show_bgp_cmd,
b05a1c8b 8959 "show bgp {json}",
718e3744 8960 SHOW_STR
b05a1c8b
DS
8961 BGP_STR
8962 "JavaScript Object Notation\n")
718e3744 8963{
b05a1c8b 8964 u_char use_json = (argv[0] != NULL);
5a646650 8965 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
b05a1c8b 8966 NULL, use_json);
718e3744 8967}
8968
8969ALIAS (show_bgp,
8970 show_bgp_ipv6_cmd,
b05a1c8b 8971 "show bgp ipv6 {json}",
718e3744 8972 SHOW_STR
8973 BGP_STR
b05a1c8b
DS
8974 "Address family\n"
8975 "JavaScript Object Notation\n")
718e3744 8976
95cbbd2a
ML
8977DEFUN (show_bgp_ipv6_safi,
8978 show_bgp_ipv6_safi_cmd,
b05a1c8b 8979 "show bgp ipv6 (unicast|multicast) {json}",
95cbbd2a
ML
8980 SHOW_STR
8981 BGP_STR
8982 "Address family\n"
8983 "Address Family modifier\n"
47fc97cc 8984 "Address Family modifier\n"
b05a1c8b 8985 "JavaScript Object Notation\n")
47fc97cc 8986{
b05a1c8b 8987 u_char use_json = (argv[1] != NULL);
47fc97cc
DS
8988 if (strncmp (argv[0], "m", 1) == 0)
8989 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
b05a1c8b 8990 NULL, use_json);
47fc97cc 8991
b05a1c8b 8992 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
95cbbd2a
ML
8993}
8994
718e3744 8995/* old command */
8996DEFUN (show_ipv6_bgp,
8997 show_ipv6_bgp_cmd,
b05a1c8b 8998 "show ipv6 bgp {json}",
718e3744 8999 SHOW_STR
9000 IP_STR
b05a1c8b
DS
9001 BGP_STR
9002 "JavaScript Object Notation\n")
718e3744 9003{
b05a1c8b 9004 u_char use_json = (argv[0] != NULL);
5a646650 9005 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
b05a1c8b 9006 NULL, use_json);
718e3744 9007}
9008
9009DEFUN (show_bgp_route,
9010 show_bgp_route_cmd,
b05a1c8b 9011 "show bgp X:X::X:X {json}",
718e3744 9012 SHOW_STR
9013 BGP_STR
b05a1c8b
DS
9014 "Network in the BGP routing table to display\n"
9015 "JavaScript Object Notation\n")
718e3744 9016{
b05a1c8b
DS
9017 u_char use_json = (argv[1] != NULL);
9018 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 9019}
9020
9021ALIAS (show_bgp_route,
9022 show_bgp_ipv6_route_cmd,
b05a1c8b 9023 "show bgp ipv6 X:X::X:X {json}",
718e3744 9024 SHOW_STR
9025 BGP_STR
9026 "Address family\n"
b05a1c8b
DS
9027 "Network in the BGP routing table to display\n"
9028 "JavaScript Object Notation\n")
718e3744 9029
95cbbd2a
ML
9030DEFUN (show_bgp_ipv6_safi_route,
9031 show_bgp_ipv6_safi_route_cmd,
b05a1c8b 9032 "show bgp ipv6 (unicast|multicast) X:X::X:X {json}",
95cbbd2a
ML
9033 SHOW_STR
9034 BGP_STR
9035 "Address family\n"
9036 "Address Family modifier\n"
9037 "Address Family modifier\n"
b05a1c8b
DS
9038 "Network in the BGP routing table to display\n"
9039 "JavaScript Object Notation\n")
95cbbd2a 9040{
b05a1c8b 9041 u_char use_json = (argv[2] != NULL);
95cbbd2a 9042 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 9043 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json);
95cbbd2a 9044
b05a1c8b 9045 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
4092b06c
DS
9046}
9047
9048DEFUN (show_bgp_route_pathtype,
9049 show_bgp_route_pathtype_cmd,
b05a1c8b 9050 "show bgp X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
9051 SHOW_STR
9052 BGP_STR
9053 "Network in the BGP routing table to display\n"
9054 "Display only the bestpath\n"
b05a1c8b
DS
9055 "Display only multipaths\n"
9056 "JavaScript Object Notation\n")
4092b06c 9057{
b05a1c8b 9058 u_char use_json = (argv[2] != NULL);
4092b06c 9059 if (strncmp (argv[1], "b", 1) == 0)
b05a1c8b 9060 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 9061 else
b05a1c8b 9062 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
9063}
9064
9065ALIAS (show_bgp_route_pathtype,
9066 show_bgp_ipv6_route_pathtype_cmd,
b05a1c8b 9067 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
9068 SHOW_STR
9069 BGP_STR
9070 "Address family\n"
9071 "Network in the BGP routing table to display\n"
9072 "Display only the bestpath\n"
b05a1c8b
DS
9073 "Display only multipaths\n"
9074 "JavaScript Object Notation\n")
4092b06c
DS
9075
9076DEFUN (show_bgp_ipv6_safi_route_pathtype,
9077 show_bgp_ipv6_safi_route_pathtype_cmd,
b05a1c8b 9078 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
9079 SHOW_STR
9080 BGP_STR
9081 "Address family\n"
9082 "Address Family modifier\n"
9083 "Address Family modifier\n"
9084 "Network in the BGP routing table to display\n"
9085 "Display only the bestpath\n"
b05a1c8b
DS
9086 "Display only multipaths\n"
9087 "JavaScript Object Notation\n")
4092b06c 9088{
b05a1c8b 9089 u_char use_json = (argv[3] != NULL);
4092b06c
DS
9090 if (strncmp (argv[0], "m", 1) == 0)
9091 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 9092 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 9093 else
b05a1c8b 9094 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
9095 else
9096 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 9097 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 9098 else
b05a1c8b 9099 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
95cbbd2a
ML
9100}
9101
718e3744 9102/* old command */
9103DEFUN (show_ipv6_bgp_route,
9104 show_ipv6_bgp_route_cmd,
b05a1c8b 9105 "show ipv6 bgp X:X::X:X {json}",
718e3744 9106 SHOW_STR
9107 IP_STR
9108 BGP_STR
b05a1c8b
DS
9109 "Network in the BGP routing table to display\n"
9110 "JavaScript Object Notation\n")
718e3744 9111{
b05a1c8b
DS
9112 u_char use_json = (argv[1] != NULL);
9113 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 9114}
9115
9116DEFUN (show_bgp_prefix,
9117 show_bgp_prefix_cmd,
b05a1c8b 9118 "show bgp X:X::X:X/M {json}",
718e3744 9119 SHOW_STR
9120 BGP_STR
b05a1c8b
DS
9121 "IPv6 prefix <network>/<length>\n"
9122 "JavaScript Object Notation\n")
718e3744 9123{
b05a1c8b
DS
9124 u_char use_json = (argv[1] != NULL);
9125 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 9126}
9127
9128ALIAS (show_bgp_prefix,
9129 show_bgp_ipv6_prefix_cmd,
b05a1c8b 9130 "show bgp ipv6 X:X::X:X/M {json}",
718e3744 9131 SHOW_STR
9132 BGP_STR
9133 "Address family\n"
b05a1c8b
DS
9134 "IPv6 prefix <network>/<length>\n"
9135 "JavaScript Object Notation\n")
718e3744 9136
95cbbd2a
ML
9137DEFUN (show_bgp_ipv6_safi_prefix,
9138 show_bgp_ipv6_safi_prefix_cmd,
b05a1c8b 9139 "show bgp ipv6 (unicast|multicast) X:X::X:X/M {json}",
95cbbd2a
ML
9140 SHOW_STR
9141 BGP_STR
9142 "Address family\n"
9143 "Address Family modifier\n"
9144 "Address Family modifier\n"
b05a1c8b
DS
9145 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9146 "JavaScript Object Notation\n")
95cbbd2a 9147{
b05a1c8b 9148 u_char use_json = (argv[2] != NULL);
95cbbd2a 9149 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 9150 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json);
95cbbd2a 9151
b05a1c8b 9152 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
4092b06c
DS
9153}
9154
9155DEFUN (show_bgp_prefix_pathtype,
9156 show_bgp_prefix_pathtype_cmd,
b05a1c8b 9157 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
9158 SHOW_STR
9159 BGP_STR
9160 "IPv6 prefix <network>/<length>\n"
9161 "Display only the bestpath\n"
b05a1c8b
DS
9162 "Display only multipaths\n"
9163 "JavaScript Object Notation\n")
4092b06c 9164{
b05a1c8b 9165 u_char use_json = (argv[2] != NULL);
4092b06c 9166 if (strncmp (argv[1], "b", 1) == 0)
b05a1c8b 9167 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 9168 else
b05a1c8b 9169 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
9170}
9171
9172ALIAS (show_bgp_prefix_pathtype,
9173 show_bgp_ipv6_prefix_pathtype_cmd,
b05a1c8b 9174 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
9175 SHOW_STR
9176 BGP_STR
9177 "Address family\n"
9178 "IPv6 prefix <network>/<length>\n"
9179 "Display only the bestpath\n"
b05a1c8b
DS
9180 "Display only multipaths\n"
9181 "JavaScript Object Notation\n")
4092b06c
DS
9182
9183DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
9184 show_bgp_ipv6_safi_prefix_pathtype_cmd,
b05a1c8b 9185 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
9186 SHOW_STR
9187 BGP_STR
9188 "Address family\n"
9189 "Address Family modifier\n"
9190 "Address Family modifier\n"
9191 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9192 "Display only the bestpath\n"
b05a1c8b
DS
9193 "Display only multipaths\n"
9194 "JavaScript Object Notation\n")
4092b06c 9195{
b05a1c8b 9196 u_char use_json = (argv[3] != NULL);
4092b06c
DS
9197 if (strncmp (argv[0], "m", 1) == 0)
9198 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 9199 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 9200 else
b05a1c8b 9201 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
9202 else
9203 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 9204 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 9205 else
b05a1c8b 9206 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
95cbbd2a
ML
9207}
9208
718e3744 9209/* old command */
9210DEFUN (show_ipv6_bgp_prefix,
9211 show_ipv6_bgp_prefix_cmd,
b05a1c8b 9212 "show ipv6 bgp X:X::X:X/M {json}",
718e3744 9213 SHOW_STR
9214 IP_STR
9215 BGP_STR
b05a1c8b
DS
9216 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9217 "JavaScript Object Notation\n")
718e3744 9218{
b05a1c8b
DS
9219 u_char use_json = (argv[1] != NULL);
9220 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 9221}
9222
bb46e94f 9223DEFUN (show_bgp_view,
9224 show_bgp_view_cmd,
b05a1c8b 9225 "show bgp view WORD {json}",
bb46e94f 9226 SHOW_STR
9227 BGP_STR
9228 "BGP view\n"
b05a1c8b
DS
9229 "View name\n"
9230 "JavaScript Object Notation\n")
bb46e94f 9231{
9232 struct bgp *bgp;
b05a1c8b 9233 u_char use_json = (argv[1] != NULL);
bb46e94f 9234
9235 /* BGP structure lookup. */
9236 bgp = bgp_lookup_by_name (argv[0]);
9237 if (bgp == NULL)
9238 {
9239 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9240 return CMD_WARNING;
9241 }
9242
b05a1c8b 9243 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
bb46e94f 9244}
9245
9246ALIAS (show_bgp_view,
9247 show_bgp_view_ipv6_cmd,
b05a1c8b 9248 "show bgp view WORD ipv6 {json}",
bb46e94f 9249 SHOW_STR
9250 BGP_STR
9251 "BGP view\n"
9252 "View name\n"
b05a1c8b
DS
9253 "Address family\n"
9254 "JavaScript Object Notation\n")
bb46e94f 9255
9256DEFUN (show_bgp_view_route,
9257 show_bgp_view_route_cmd,
b05a1c8b 9258 "show bgp view WORD X:X::X:X {json}",
bb46e94f 9259 SHOW_STR
9260 BGP_STR
9261 "BGP view\n"
9262 "View name\n"
b05a1c8b
DS
9263 "Network in the BGP routing table to display\n"
9264 "JavaScript Object Notation\n")
bb46e94f 9265{
b05a1c8b
DS
9266 u_char use_json = (argv[2] != NULL);
9267 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
bb46e94f 9268}
9269
9270ALIAS (show_bgp_view_route,
9271 show_bgp_view_ipv6_route_cmd,
b05a1c8b 9272 "show bgp view WORD ipv6 X:X::X:X {json}",
bb46e94f 9273 SHOW_STR
9274 BGP_STR
9275 "BGP view\n"
9276 "View name\n"
9277 "Address family\n"
b05a1c8b
DS
9278 "Network in the BGP routing table to display\n"
9279 "JavaScript Object Notation\n")
bb46e94f 9280
9281DEFUN (show_bgp_view_prefix,
9282 show_bgp_view_prefix_cmd,
b05a1c8b 9283 "show bgp view WORD X:X::X:X/M {json}",
bb46e94f 9284 SHOW_STR
9285 BGP_STR
9286 "BGP view\n"
9287 "View name\n"
b05a1c8b
DS
9288 "IPv6 prefix <network>/<length>\n"
9289 "JavaScript Object Notation\n")
bb46e94f 9290{
b05a1c8b
DS
9291 u_char use_json = (argv[2] != NULL);
9292 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
bb46e94f 9293}
9294
9295ALIAS (show_bgp_view_prefix,
9296 show_bgp_view_ipv6_prefix_cmd,
b05a1c8b 9297 "show bgp view WORD ipv6 X:X::X:X/M {json}",
bb46e94f 9298 SHOW_STR
9299 BGP_STR
9300 "BGP view\n"
9301 "View name\n"
9302 "Address family\n"
b05a1c8b
DS
9303 "IPv6 prefix <network>/<length>\n"
9304 "JavaScript Object Notation\n")
bb46e94f 9305
718e3744 9306/* old command */
9307DEFUN (show_ipv6_mbgp,
9308 show_ipv6_mbgp_cmd,
b05a1c8b 9309 "show ipv6 mbgp {json}",
718e3744 9310 SHOW_STR
9311 IP_STR
b05a1c8b
DS
9312 MBGP_STR
9313 "JavaScript Object Notation\n")
718e3744 9314{
b05a1c8b 9315 u_char use_json = (argv[0] != NULL);
5a646650 9316 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
b05a1c8b 9317 NULL, use_json);
718e3744 9318}
9319
9320/* old command */
9321DEFUN (show_ipv6_mbgp_route,
9322 show_ipv6_mbgp_route_cmd,
b05a1c8b 9323 "show ipv6 mbgp X:X::X:X {json}",
718e3744 9324 SHOW_STR
9325 IP_STR
9326 MBGP_STR
b05a1c8b
DS
9327 "Network in the MBGP routing table to display\n"
9328 "JavaScript Object Notation\n")
718e3744 9329{
b05a1c8b
DS
9330 u_char use_json = (argv[1] != NULL);
9331 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 9332}
9333
9334/* old command */
9335DEFUN (show_ipv6_mbgp_prefix,
9336 show_ipv6_mbgp_prefix_cmd,
b05a1c8b 9337 "show ipv6 mbgp X:X::X:X/M {json}",
718e3744 9338 SHOW_STR
9339 IP_STR
9340 MBGP_STR
b05a1c8b
DS
9341 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9342 "JavaScript Object Notation\n")
718e3744 9343{
b05a1c8b
DS
9344 u_char use_json = (argv[1] != NULL);
9345 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 9346}
9347#endif
6b0655a2 9348
718e3744 9349
94f2b392 9350static int
fd79ac91 9351bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
718e3744 9352 safi_t safi, enum bgp_show_type type)
9353{
9354 int i;
9355 struct buffer *b;
9356 char *regstr;
9357 int first;
9358 regex_t *regex;
5a646650 9359 int rc;
718e3744 9360
9361 first = 0;
9362 b = buffer_new (1024);
9363 for (i = 0; i < argc; i++)
9364 {
9365 if (first)
9366 buffer_putc (b, ' ');
9367 else
9368 {
9369 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9370 continue;
9371 first = 1;
9372 }
9373
9374 buffer_putstr (b, argv[i]);
9375 }
9376 buffer_putc (b, '\0');
9377
9378 regstr = buffer_getstr (b);
9379 buffer_free (b);
9380
9381 regex = bgp_regcomp (regstr);
3b8b1855 9382 XFREE(MTYPE_TMP, regstr);
718e3744 9383 if (! regex)
9384 {
9385 vty_out (vty, "Can't compile regexp %s%s", argv[0],
9386 VTY_NEWLINE);
9387 return CMD_WARNING;
9388 }
9389
b05a1c8b 9390 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
5a646650 9391 bgp_regex_free (regex);
9392 return rc;
718e3744 9393}
9394
9395DEFUN (show_ip_bgp_regexp,
9396 show_ip_bgp_regexp_cmd,
9397 "show ip bgp regexp .LINE",
9398 SHOW_STR
9399 IP_STR
9400 BGP_STR
9401 "Display routes matching the AS path regular expression\n"
9402 "A regular-expression to match the BGP AS paths\n")
9403{
9404 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9405 bgp_show_type_regexp);
9406}
9407
9408DEFUN (show_ip_bgp_flap_regexp,
9409 show_ip_bgp_flap_regexp_cmd,
9410 "show ip bgp flap-statistics regexp .LINE",
9411 SHOW_STR
9412 IP_STR
9413 BGP_STR
9414 "Display flap statistics of routes\n"
9415 "Display routes matching the AS path regular expression\n"
9416 "A regular-expression to match the BGP AS paths\n")
9417{
9418 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9419 bgp_show_type_flap_regexp);
9420}
9421
9422DEFUN (show_ip_bgp_ipv4_regexp,
9423 show_ip_bgp_ipv4_regexp_cmd,
9424 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
9425 SHOW_STR
9426 IP_STR
9427 BGP_STR
9428 "Address family\n"
9429 "Address Family modifier\n"
9430 "Address Family modifier\n"
9431 "Display routes matching the AS path regular expression\n"
9432 "A regular-expression to match the BGP AS paths\n")
9433{
9434 if (strncmp (argv[0], "m", 1) == 0)
9435 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
9436 bgp_show_type_regexp);
9437
9438 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9439 bgp_show_type_regexp);
9440}
9441
9442#ifdef HAVE_IPV6
9443DEFUN (show_bgp_regexp,
9444 show_bgp_regexp_cmd,
9445 "show bgp regexp .LINE",
9446 SHOW_STR
9447 BGP_STR
9448 "Display routes matching the AS path regular expression\n"
9449 "A regular-expression to match the BGP AS paths\n")
9450{
9451 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9452 bgp_show_type_regexp);
9453}
9454
9455ALIAS (show_bgp_regexp,
9456 show_bgp_ipv6_regexp_cmd,
9457 "show bgp ipv6 regexp .LINE",
9458 SHOW_STR
9459 BGP_STR
9460 "Address family\n"
9461 "Display routes matching the AS path regular expression\n"
9462 "A regular-expression to match the BGP AS paths\n")
9463
9464/* old command */
9465DEFUN (show_ipv6_bgp_regexp,
9466 show_ipv6_bgp_regexp_cmd,
9467 "show ipv6 bgp regexp .LINE",
9468 SHOW_STR
9469 IP_STR
9470 BGP_STR
9471 "Display routes matching the AS path regular expression\n"
9472 "A regular-expression to match the BGP AS paths\n")
9473{
9474 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9475 bgp_show_type_regexp);
9476}
9477
9478/* old command */
9479DEFUN (show_ipv6_mbgp_regexp,
9480 show_ipv6_mbgp_regexp_cmd,
9481 "show ipv6 mbgp regexp .LINE",
9482 SHOW_STR
9483 IP_STR
9484 BGP_STR
9485 "Display routes matching the AS path regular expression\n"
9486 "A regular-expression to match the MBGP AS paths\n")
9487{
9488 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
9489 bgp_show_type_regexp);
9490}
9491#endif /* HAVE_IPV6 */
6b0655a2 9492
94f2b392 9493static int
fd79ac91 9494bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
718e3744 9495 safi_t safi, enum bgp_show_type type)
9496{
9497 struct prefix_list *plist;
9498
9499 plist = prefix_list_lookup (afi, prefix_list_str);
9500 if (plist == NULL)
9501 {
9502 vty_out (vty, "%% %s is not a valid prefix-list name%s",
9503 prefix_list_str, VTY_NEWLINE);
9504 return CMD_WARNING;
9505 }
9506
b05a1c8b 9507 return bgp_show (vty, NULL, afi, safi, type, plist, 0);
718e3744 9508}
9509
9510DEFUN (show_ip_bgp_prefix_list,
9511 show_ip_bgp_prefix_list_cmd,
9512 "show ip bgp prefix-list WORD",
9513 SHOW_STR
9514 IP_STR
9515 BGP_STR
9516 "Display routes conforming to the prefix-list\n"
9517 "IP prefix-list name\n")
9518{
9519 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
9520 bgp_show_type_prefix_list);
9521}
9522
9523DEFUN (show_ip_bgp_flap_prefix_list,
9524 show_ip_bgp_flap_prefix_list_cmd,
9525 "show ip bgp flap-statistics prefix-list WORD",
9526 SHOW_STR
9527 IP_STR
9528 BGP_STR
9529 "Display flap statistics of routes\n"
9530 "Display routes conforming to the prefix-list\n"
9531 "IP prefix-list name\n")
9532{
9533 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
9534 bgp_show_type_flap_prefix_list);
9535}
9536
9537DEFUN (show_ip_bgp_ipv4_prefix_list,
9538 show_ip_bgp_ipv4_prefix_list_cmd,
9539 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
9540 SHOW_STR
9541 IP_STR
9542 BGP_STR
9543 "Address family\n"
9544 "Address Family modifier\n"
9545 "Address Family modifier\n"
9546 "Display routes conforming to the prefix-list\n"
9547 "IP prefix-list name\n")
9548{
9549 if (strncmp (argv[0], "m", 1) == 0)
9550 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9551 bgp_show_type_prefix_list);
9552
9553 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
9554 bgp_show_type_prefix_list);
9555}
9556
9557#ifdef HAVE_IPV6
9558DEFUN (show_bgp_prefix_list,
9559 show_bgp_prefix_list_cmd,
9560 "show bgp prefix-list WORD",
9561 SHOW_STR
9562 BGP_STR
9563 "Display routes conforming to the prefix-list\n"
9564 "IPv6 prefix-list name\n")
9565{
9566 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9567 bgp_show_type_prefix_list);
9568}
9569
9570ALIAS (show_bgp_prefix_list,
9571 show_bgp_ipv6_prefix_list_cmd,
9572 "show bgp ipv6 prefix-list WORD",
9573 SHOW_STR
9574 BGP_STR
9575 "Address family\n"
9576 "Display routes conforming to the prefix-list\n"
9577 "IPv6 prefix-list name\n")
9578
9579/* old command */
9580DEFUN (show_ipv6_bgp_prefix_list,
9581 show_ipv6_bgp_prefix_list_cmd,
9582 "show ipv6 bgp prefix-list WORD",
9583 SHOW_STR
9584 IPV6_STR
9585 BGP_STR
9586 "Display routes matching the prefix-list\n"
9587 "IPv6 prefix-list name\n")
9588{
9589 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9590 bgp_show_type_prefix_list);
9591}
9592
9593/* old command */
9594DEFUN (show_ipv6_mbgp_prefix_list,
9595 show_ipv6_mbgp_prefix_list_cmd,
9596 "show ipv6 mbgp prefix-list WORD",
9597 SHOW_STR
9598 IPV6_STR
9599 MBGP_STR
9600 "Display routes matching the prefix-list\n"
9601 "IPv6 prefix-list name\n")
9602{
9603 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9604 bgp_show_type_prefix_list);
9605}
9606#endif /* HAVE_IPV6 */
6b0655a2 9607
94f2b392 9608static int
fd79ac91 9609bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
718e3744 9610 safi_t safi, enum bgp_show_type type)
9611{
9612 struct as_list *as_list;
9613
9614 as_list = as_list_lookup (filter);
9615 if (as_list == NULL)
9616 {
9617 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
9618 return CMD_WARNING;
9619 }
9620
b05a1c8b 9621 return bgp_show (vty, NULL, afi, safi, type, as_list, 0);
718e3744 9622}
9623
9624DEFUN (show_ip_bgp_filter_list,
9625 show_ip_bgp_filter_list_cmd,
9626 "show ip bgp filter-list WORD",
9627 SHOW_STR
9628 IP_STR
9629 BGP_STR
9630 "Display routes conforming to the filter-list\n"
9631 "Regular expression access list name\n")
9632{
9633 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
9634 bgp_show_type_filter_list);
9635}
9636
9637DEFUN (show_ip_bgp_flap_filter_list,
9638 show_ip_bgp_flap_filter_list_cmd,
9639 "show ip bgp flap-statistics filter-list WORD",
9640 SHOW_STR
9641 IP_STR
9642 BGP_STR
9643 "Display flap statistics of routes\n"
9644 "Display routes conforming to the filter-list\n"
9645 "Regular expression access list name\n")
9646{
9647 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
9648 bgp_show_type_flap_filter_list);
9649}
9650
9651DEFUN (show_ip_bgp_ipv4_filter_list,
9652 show_ip_bgp_ipv4_filter_list_cmd,
9653 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
9654 SHOW_STR
9655 IP_STR
9656 BGP_STR
9657 "Address family\n"
9658 "Address Family modifier\n"
9659 "Address Family modifier\n"
9660 "Display routes conforming to the filter-list\n"
9661 "Regular expression access list name\n")
9662{
9663 if (strncmp (argv[0], "m", 1) == 0)
9664 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9665 bgp_show_type_filter_list);
9666
9667 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
9668 bgp_show_type_filter_list);
9669}
9670
9671#ifdef HAVE_IPV6
9672DEFUN (show_bgp_filter_list,
9673 show_bgp_filter_list_cmd,
9674 "show bgp filter-list WORD",
9675 SHOW_STR
9676 BGP_STR
9677 "Display routes conforming to the filter-list\n"
9678 "Regular expression access list name\n")
9679{
9680 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9681 bgp_show_type_filter_list);
9682}
9683
9684ALIAS (show_bgp_filter_list,
9685 show_bgp_ipv6_filter_list_cmd,
9686 "show bgp ipv6 filter-list WORD",
9687 SHOW_STR
9688 BGP_STR
9689 "Address family\n"
9690 "Display routes conforming to the filter-list\n"
9691 "Regular expression access list name\n")
9692
9693/* old command */
9694DEFUN (show_ipv6_bgp_filter_list,
9695 show_ipv6_bgp_filter_list_cmd,
9696 "show ipv6 bgp filter-list WORD",
9697 SHOW_STR
9698 IPV6_STR
9699 BGP_STR
9700 "Display routes conforming to the filter-list\n"
9701 "Regular expression access list name\n")
9702{
9703 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9704 bgp_show_type_filter_list);
9705}
9706
9707/* old command */
9708DEFUN (show_ipv6_mbgp_filter_list,
9709 show_ipv6_mbgp_filter_list_cmd,
9710 "show ipv6 mbgp filter-list WORD",
9711 SHOW_STR
9712 IPV6_STR
9713 MBGP_STR
9714 "Display routes conforming to the filter-list\n"
9715 "Regular expression access list name\n")
9716{
9717 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9718 bgp_show_type_filter_list);
9719}
9720#endif /* HAVE_IPV6 */
6b0655a2 9721
94f2b392 9722static int
fd79ac91 9723bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
718e3744 9724 safi_t safi, enum bgp_show_type type)
9725{
9726 struct route_map *rmap;
9727
9728 rmap = route_map_lookup_by_name (rmap_str);
9729 if (! rmap)
9730 {
9731 vty_out (vty, "%% %s is not a valid route-map name%s",
9732 rmap_str, VTY_NEWLINE);
9733 return CMD_WARNING;
9734 }
9735
b05a1c8b 9736 return bgp_show (vty, NULL, afi, safi, type, rmap, 0);
718e3744 9737}
9738
9739DEFUN (show_ip_bgp_route_map,
9740 show_ip_bgp_route_map_cmd,
9741 "show ip bgp route-map WORD",
9742 SHOW_STR
9743 IP_STR
9744 BGP_STR
9745 "Display routes matching the route-map\n"
9746 "A route-map to match on\n")
9747{
9748 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
9749 bgp_show_type_route_map);
9750}
9751
9752DEFUN (show_ip_bgp_flap_route_map,
9753 show_ip_bgp_flap_route_map_cmd,
9754 "show ip bgp flap-statistics route-map WORD",
9755 SHOW_STR
9756 IP_STR
9757 BGP_STR
9758 "Display flap statistics of routes\n"
9759 "Display routes matching the route-map\n"
9760 "A route-map to match on\n")
9761{
9762 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
9763 bgp_show_type_flap_route_map);
9764}
9765
9766DEFUN (show_ip_bgp_ipv4_route_map,
9767 show_ip_bgp_ipv4_route_map_cmd,
9768 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
9769 SHOW_STR
9770 IP_STR
9771 BGP_STR
9772 "Address family\n"
9773 "Address Family modifier\n"
9774 "Address Family modifier\n"
9775 "Display routes matching the route-map\n"
9776 "A route-map to match on\n")
9777{
9778 if (strncmp (argv[0], "m", 1) == 0)
9779 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9780 bgp_show_type_route_map);
9781
9782 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
9783 bgp_show_type_route_map);
9784}
9785
9786DEFUN (show_bgp_route_map,
9787 show_bgp_route_map_cmd,
9788 "show bgp route-map WORD",
9789 SHOW_STR
9790 BGP_STR
9791 "Display routes matching the route-map\n"
9792 "A route-map to match on\n")
9793{
9794 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9795 bgp_show_type_route_map);
9796}
9797
9798ALIAS (show_bgp_route_map,
9799 show_bgp_ipv6_route_map_cmd,
9800 "show bgp ipv6 route-map WORD",
9801 SHOW_STR
9802 BGP_STR
9803 "Address family\n"
9804 "Display routes matching the route-map\n"
9805 "A route-map to match on\n")
6b0655a2 9806
718e3744 9807DEFUN (show_ip_bgp_cidr_only,
9808 show_ip_bgp_cidr_only_cmd,
9809 "show ip bgp cidr-only",
9810 SHOW_STR
9811 IP_STR
9812 BGP_STR
9813 "Display only routes with non-natural netmasks\n")
9814{
9815 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9816 bgp_show_type_cidr_only, NULL, 0);
718e3744 9817}
9818
9819DEFUN (show_ip_bgp_flap_cidr_only,
9820 show_ip_bgp_flap_cidr_only_cmd,
9821 "show ip bgp flap-statistics cidr-only",
9822 SHOW_STR
9823 IP_STR
9824 BGP_STR
9825 "Display flap statistics of routes\n"
9826 "Display only routes with non-natural netmasks\n")
9827{
9828 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9829 bgp_show_type_flap_cidr_only, NULL, 0);
718e3744 9830}
9831
9832DEFUN (show_ip_bgp_ipv4_cidr_only,
9833 show_ip_bgp_ipv4_cidr_only_cmd,
9834 "show ip bgp ipv4 (unicast|multicast) cidr-only",
9835 SHOW_STR
9836 IP_STR
9837 BGP_STR
9838 "Address family\n"
9839 "Address Family modifier\n"
9840 "Address Family modifier\n"
9841 "Display only routes with non-natural netmasks\n")
9842{
9843 if (strncmp (argv[0], "m", 1) == 0)
9844 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
b05a1c8b 9845 bgp_show_type_cidr_only, NULL, 0);
718e3744 9846
9847 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9848 bgp_show_type_cidr_only, NULL, 0);
718e3744 9849}
6b0655a2 9850
718e3744 9851DEFUN (show_ip_bgp_community_all,
9852 show_ip_bgp_community_all_cmd,
9853 "show ip bgp community",
9854 SHOW_STR
9855 IP_STR
9856 BGP_STR
9857 "Display routes matching the communities\n")
9858{
9859 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9860 bgp_show_type_community_all, NULL, 0);
718e3744 9861}
9862
9863DEFUN (show_ip_bgp_ipv4_community_all,
9864 show_ip_bgp_ipv4_community_all_cmd,
9865 "show ip bgp ipv4 (unicast|multicast) community",
9866 SHOW_STR
9867 IP_STR
9868 BGP_STR
9869 "Address family\n"
9870 "Address Family modifier\n"
9871 "Address Family modifier\n"
9872 "Display routes matching the communities\n")
9873{
9874 if (strncmp (argv[0], "m", 1) == 0)
9875 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
b05a1c8b 9876 bgp_show_type_community_all, NULL, 0);
718e3744 9877
9878 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9879 bgp_show_type_community_all, NULL, 0);
718e3744 9880}
9881
9882#ifdef HAVE_IPV6
9883DEFUN (show_bgp_community_all,
9884 show_bgp_community_all_cmd,
9885 "show bgp community",
9886 SHOW_STR
9887 BGP_STR
9888 "Display routes matching the communities\n")
9889{
9890 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 9891 bgp_show_type_community_all, NULL, 0);
718e3744 9892}
9893
9894ALIAS (show_bgp_community_all,
9895 show_bgp_ipv6_community_all_cmd,
9896 "show bgp ipv6 community",
9897 SHOW_STR
9898 BGP_STR
9899 "Address family\n"
9900 "Display routes matching the communities\n")
9901
9902/* old command */
9903DEFUN (show_ipv6_bgp_community_all,
9904 show_ipv6_bgp_community_all_cmd,
9905 "show ipv6 bgp community",
9906 SHOW_STR
9907 IPV6_STR
9908 BGP_STR
9909 "Display routes matching the communities\n")
9910{
9911 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 9912 bgp_show_type_community_all, NULL, 0);
718e3744 9913}
9914
9915/* old command */
9916DEFUN (show_ipv6_mbgp_community_all,
9917 show_ipv6_mbgp_community_all_cmd,
9918 "show ipv6 mbgp community",
9919 SHOW_STR
9920 IPV6_STR
9921 MBGP_STR
9922 "Display routes matching the communities\n")
9923{
9924 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
b05a1c8b 9925 bgp_show_type_community_all, NULL, 0);
718e3744 9926}
9927#endif /* HAVE_IPV6 */
6b0655a2 9928
94f2b392 9929static int
95cbbd2a
ML
9930bgp_show_community (struct vty *vty, const char *view_name, int argc,
9931 const char **argv, int exact, afi_t afi, safi_t safi)
718e3744 9932{
9933 struct community *com;
9934 struct buffer *b;
95cbbd2a 9935 struct bgp *bgp;
718e3744 9936 int i;
9937 char *str;
9938 int first = 0;
9939
95cbbd2a
ML
9940 /* BGP structure lookup */
9941 if (view_name)
9942 {
9943 bgp = bgp_lookup_by_name (view_name);
9944 if (bgp == NULL)
9945 {
9946 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9947 return CMD_WARNING;
9948 }
9949 }
9950 else
9951 {
9952 bgp = bgp_get_default ();
9953 if (bgp == NULL)
9954 {
9955 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9956 return CMD_WARNING;
9957 }
9958 }
9959
718e3744 9960 b = buffer_new (1024);
9961 for (i = 0; i < argc; i++)
9962 {
9963 if (first)
9964 buffer_putc (b, ' ');
9965 else
9966 {
9967 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9968 continue;
9969 first = 1;
9970 }
9971
9972 buffer_putstr (b, argv[i]);
9973 }
9974 buffer_putc (b, '\0');
9975
9976 str = buffer_getstr (b);
9977 buffer_free (b);
9978
9979 com = community_str2com (str);
3b8b1855 9980 XFREE (MTYPE_TMP, str);
718e3744 9981 if (! com)
9982 {
9983 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9984 return CMD_WARNING;
9985 }
9986
95cbbd2a 9987 return bgp_show (vty, bgp, afi, safi,
5a646650 9988 (exact ? bgp_show_type_community_exact :
b05a1c8b 9989 bgp_show_type_community), com, 0);
718e3744 9990}
9991
9992DEFUN (show_ip_bgp_community,
9993 show_ip_bgp_community_cmd,
9994 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9995 SHOW_STR
9996 IP_STR
9997 BGP_STR
9998 "Display routes matching the communities\n"
9999 "community number\n"
10000 "Do not send outside local AS (well-known community)\n"
10001 "Do not advertise to any peer (well-known community)\n"
10002 "Do not export to next AS (well-known community)\n")
10003{
95cbbd2a 10004 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 10005}
10006
10007ALIAS (show_ip_bgp_community,
10008 show_ip_bgp_community2_cmd,
10009 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10010 SHOW_STR
10011 IP_STR
10012 BGP_STR
10013 "Display routes matching the communities\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
10023ALIAS (show_ip_bgp_community,
10024 show_ip_bgp_community3_cmd,
10025 "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)",
10026 SHOW_STR
10027 IP_STR
10028 BGP_STR
10029 "Display routes matching the communities\n"
10030 "community number\n"
10031 "Do not send outside local AS (well-known community)\n"
10032 "Do not advertise to any peer (well-known community)\n"
10033 "Do not export to next AS (well-known community)\n"
10034 "community number\n"
10035 "Do not send outside local AS (well-known community)\n"
10036 "Do not advertise to any peer (well-known community)\n"
10037 "Do not export to next AS (well-known community)\n"
10038 "community number\n"
10039 "Do not send outside local AS (well-known community)\n"
10040 "Do not advertise to any peer (well-known community)\n"
10041 "Do not export to next AS (well-known community)\n")
10042
10043ALIAS (show_ip_bgp_community,
10044 show_ip_bgp_community4_cmd,
10045 "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)",
10046 SHOW_STR
10047 IP_STR
10048 BGP_STR
10049 "Display routes matching the communities\n"
10050 "community number\n"
10051 "Do not send outside local AS (well-known community)\n"
10052 "Do not advertise to any peer (well-known community)\n"
10053 "Do not export to next AS (well-known community)\n"
10054 "community number\n"
10055 "Do not send outside local AS (well-known community)\n"
10056 "Do not advertise to any peer (well-known community)\n"
10057 "Do not export to next AS (well-known community)\n"
10058 "community number\n"
10059 "Do not send outside local AS (well-known community)\n"
10060 "Do not advertise to any peer (well-known community)\n"
10061 "Do not export to next AS (well-known community)\n"
10062 "community number\n"
10063 "Do not send outside local AS (well-known community)\n"
10064 "Do not advertise to any peer (well-known community)\n"
10065 "Do not export to next AS (well-known community)\n")
10066
10067DEFUN (show_ip_bgp_ipv4_community,
10068 show_ip_bgp_ipv4_community_cmd,
10069 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10070 SHOW_STR
10071 IP_STR
10072 BGP_STR
10073 "Address family\n"
10074 "Address Family modifier\n"
10075 "Address Family modifier\n"
10076 "Display routes matching the communities\n"
10077 "community number\n"
10078 "Do not send outside local AS (well-known community)\n"
10079 "Do not advertise to any peer (well-known community)\n"
10080 "Do not export to next AS (well-known community)\n")
10081{
10082 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 10083 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
718e3744 10084
95cbbd2a 10085 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 10086}
10087
10088ALIAS (show_ip_bgp_ipv4_community,
10089 show_ip_bgp_ipv4_community2_cmd,
10090 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10091 SHOW_STR
10092 IP_STR
10093 BGP_STR
10094 "Address family\n"
10095 "Address Family modifier\n"
10096 "Address Family modifier\n"
10097 "Display routes matching the communities\n"
10098 "community number\n"
10099 "Do not send outside local AS (well-known community)\n"
10100 "Do not advertise to any peer (well-known community)\n"
10101 "Do not export to next AS (well-known community)\n"
10102 "community number\n"
10103 "Do not send outside local AS (well-known community)\n"
10104 "Do not advertise to any peer (well-known community)\n"
10105 "Do not export to next AS (well-known community)\n")
10106
10107ALIAS (show_ip_bgp_ipv4_community,
10108 show_ip_bgp_ipv4_community3_cmd,
10109 "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)",
10110 SHOW_STR
10111 IP_STR
10112 BGP_STR
10113 "Address family\n"
10114 "Address Family modifier\n"
10115 "Address Family modifier\n"
10116 "Display routes matching the communities\n"
10117 "community number\n"
10118 "Do not send outside local AS (well-known community)\n"
10119 "Do not advertise to any peer (well-known community)\n"
10120 "Do not export to next AS (well-known community)\n"
10121 "community number\n"
10122 "Do not send outside local AS (well-known community)\n"
10123 "Do not advertise to any peer (well-known community)\n"
10124 "Do not export to next AS (well-known community)\n"
10125 "community number\n"
10126 "Do not send outside local AS (well-known community)\n"
10127 "Do not advertise to any peer (well-known community)\n"
10128 "Do not export to next AS (well-known community)\n")
10129
10130ALIAS (show_ip_bgp_ipv4_community,
10131 show_ip_bgp_ipv4_community4_cmd,
10132 "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)",
10133 SHOW_STR
10134 IP_STR
10135 BGP_STR
10136 "Address family\n"
10137 "Address Family modifier\n"
10138 "Address Family modifier\n"
10139 "Display routes matching the communities\n"
10140 "community number\n"
10141 "Do not send outside local AS (well-known community)\n"
10142 "Do not advertise to any peer (well-known community)\n"
10143 "Do not export to next AS (well-known community)\n"
10144 "community number\n"
10145 "Do not send outside local AS (well-known community)\n"
10146 "Do not advertise to any peer (well-known community)\n"
10147 "Do not export to next AS (well-known community)\n"
10148 "community number\n"
10149 "Do not send outside local AS (well-known community)\n"
10150 "Do not advertise to any peer (well-known community)\n"
10151 "Do not export to next AS (well-known community)\n"
10152 "community number\n"
10153 "Do not send outside local AS (well-known community)\n"
10154 "Do not advertise to any peer (well-known community)\n"
10155 "Do not export to next AS (well-known community)\n")
10156
95cbbd2a
ML
10157DEFUN (show_bgp_view_afi_safi_community_all,
10158 show_bgp_view_afi_safi_community_all_cmd,
10159#ifdef HAVE_IPV6
10160 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
10161#else
10162 "show bgp view WORD ipv4 (unicast|multicast) community",
10163#endif
10164 SHOW_STR
10165 BGP_STR
10166 "BGP view\n"
2b00515a 10167 "View name\n"
95cbbd2a
ML
10168 "Address family\n"
10169#ifdef HAVE_IPV6
10170 "Address family\n"
10171#endif
10172 "Address Family modifier\n"
10173 "Address Family modifier\n"
2b00515a 10174 "Display routes matching the communities\n")
95cbbd2a
ML
10175{
10176 int afi;
10177 int safi;
10178 struct bgp *bgp;
10179
10180 /* BGP structure lookup. */
10181 bgp = bgp_lookup_by_name (argv[0]);
10182 if (bgp == NULL)
10183 {
10184 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10185 return CMD_WARNING;
10186 }
10187
10188#ifdef HAVE_IPV6
10189 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10190 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10191#else
10192 afi = AFI_IP;
10193 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10194#endif
b05a1c8b 10195 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
95cbbd2a
ML
10196}
10197
10198DEFUN (show_bgp_view_afi_safi_community,
10199 show_bgp_view_afi_safi_community_cmd,
10200#ifdef HAVE_IPV6
10201 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10202#else
10203 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10204#endif
10205 SHOW_STR
10206 BGP_STR
10207 "BGP view\n"
2b00515a 10208 "View name\n"
95cbbd2a
ML
10209 "Address family\n"
10210#ifdef HAVE_IPV6
10211 "Address family\n"
10212#endif
10213 "Address family modifier\n"
10214 "Address family modifier\n"
10215 "Display routes matching the communities\n"
10216 "community number\n"
10217 "Do not send outside local AS (well-known community)\n"
10218 "Do not advertise to any peer (well-known community)\n"
10219 "Do not export to next AS (well-known community)\n")
10220{
10221 int afi;
10222 int safi;
10223
10224#ifdef HAVE_IPV6
10225 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10226 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10227 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
10228#else
10229 afi = AFI_IP;
10230 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10231 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
10232#endif
10233}
10234
10235ALIAS (show_bgp_view_afi_safi_community,
10236 show_bgp_view_afi_safi_community2_cmd,
10237#ifdef HAVE_IPV6
10238 "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)",
10239#else
10240 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10241#endif
10242 SHOW_STR
10243 BGP_STR
10244 "BGP view\n"
2b00515a 10245 "View name\n"
95cbbd2a
ML
10246 "Address family\n"
10247#ifdef HAVE_IPV6
10248 "Address family\n"
10249#endif
10250 "Address family modifier\n"
10251 "Address family modifier\n"
10252 "Display routes matching the communities\n"
10253 "community number\n"
10254 "Do not send outside local AS (well-known community)\n"
10255 "Do not advertise to any peer (well-known community)\n"
10256 "Do not export to next AS (well-known community)\n"
10257 "community number\n"
10258 "Do not send outside local AS (well-known community)\n"
10259 "Do not advertise to any peer (well-known community)\n"
10260 "Do not export to next AS (well-known community)\n")
10261
10262ALIAS (show_bgp_view_afi_safi_community,
10263 show_bgp_view_afi_safi_community3_cmd,
10264#ifdef HAVE_IPV6
10265 "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)",
10266#else
10267 "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)",
10268#endif
10269 SHOW_STR
10270 BGP_STR
10271 "BGP view\n"
2b00515a 10272 "View name\n"
95cbbd2a
ML
10273 "Address family\n"
10274#ifdef HAVE_IPV6
10275 "Address family\n"
10276#endif
10277 "Address family modifier\n"
10278 "Address family modifier\n"
10279 "Display routes matching the communities\n"
10280 "community number\n"
10281 "Do not send outside local AS (well-known community)\n"
10282 "Do not advertise to any peer (well-known community)\n"
10283 "Do not export to next AS (well-known community)\n"
10284 "community number\n"
10285 "Do not send outside local AS (well-known community)\n"
10286 "Do not advertise to any peer (well-known community)\n"
10287 "Do not export to next AS (well-known community)\n"
10288 "community number\n"
10289 "Do not send outside local AS (well-known community)\n"
10290 "Do not advertise to any peer (well-known community)\n"
10291 "Do not export to next AS (well-known community)\n")
10292
10293ALIAS (show_bgp_view_afi_safi_community,
10294 show_bgp_view_afi_safi_community4_cmd,
10295#ifdef HAVE_IPV6
10296 "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)",
10297#else
10298 "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)",
10299#endif
10300 SHOW_STR
10301 BGP_STR
10302 "BGP view\n"
2b00515a 10303 "View name\n"
95cbbd2a
ML
10304 "Address family\n"
10305#ifdef HAVE_IPV6
10306 "Address family\n"
10307#endif
10308 "Address family modifier\n"
10309 "Address family modifier\n"
10310 "Display routes matching the communities\n"
10311 "community number\n"
10312 "Do not send outside local AS (well-known community)\n"
10313 "Do not advertise to any peer (well-known community)\n"
10314 "Do not export to next AS (well-known community)\n"
10315 "community number\n"
10316 "Do not send outside local AS (well-known community)\n"
10317 "Do not advertise to any peer (well-known community)\n"
10318 "Do not export to next AS (well-known community)\n"
10319 "community number\n"
10320 "Do not send outside local AS (well-known community)\n"
10321 "Do not advertise to any peer (well-known community)\n"
10322 "Do not export to next AS (well-known community)\n"
10323 "community number\n"
10324 "Do not send outside local AS (well-known community)\n"
10325 "Do not advertise to any peer (well-known community)\n"
10326 "Do not export to next AS (well-known community)\n")
10327
718e3744 10328DEFUN (show_ip_bgp_community_exact,
10329 show_ip_bgp_community_exact_cmd,
10330 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10331 SHOW_STR
10332 IP_STR
10333 BGP_STR
10334 "Display routes matching the communities\n"
10335 "community number\n"
10336 "Do not send outside local AS (well-known community)\n"
10337 "Do not advertise to any peer (well-known community)\n"
10338 "Do not export to next AS (well-known community)\n"
10339 "Exact match of the communities")
10340{
95cbbd2a 10341 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 10342}
10343
10344ALIAS (show_ip_bgp_community_exact,
10345 show_ip_bgp_community2_exact_cmd,
10346 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10347 SHOW_STR
10348 IP_STR
10349 BGP_STR
10350 "Display routes matching the communities\n"
10351 "community number\n"
10352 "Do not send outside local AS (well-known community)\n"
10353 "Do not advertise to any peer (well-known community)\n"
10354 "Do not export to next AS (well-known community)\n"
10355 "community number\n"
10356 "Do not send outside local AS (well-known community)\n"
10357 "Do not advertise to any peer (well-known community)\n"
10358 "Do not export to next AS (well-known community)\n"
10359 "Exact match of the communities")
10360
10361ALIAS (show_ip_bgp_community_exact,
10362 show_ip_bgp_community3_exact_cmd,
10363 "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",
10364 SHOW_STR
10365 IP_STR
10366 BGP_STR
10367 "Display routes matching the communities\n"
10368 "community number\n"
10369 "Do not send outside local AS (well-known community)\n"
10370 "Do not advertise to any peer (well-known community)\n"
10371 "Do not export to next AS (well-known community)\n"
10372 "community number\n"
10373 "Do not send outside local AS (well-known community)\n"
10374 "Do not advertise to any peer (well-known community)\n"
10375 "Do not export to next AS (well-known community)\n"
10376 "community number\n"
10377 "Do not send outside local AS (well-known community)\n"
10378 "Do not advertise to any peer (well-known community)\n"
10379 "Do not export to next AS (well-known community)\n"
10380 "Exact match of the communities")
10381
10382ALIAS (show_ip_bgp_community_exact,
10383 show_ip_bgp_community4_exact_cmd,
10384 "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",
10385 SHOW_STR
10386 IP_STR
10387 BGP_STR
10388 "Display routes matching the communities\n"
10389 "community number\n"
10390 "Do not send outside local AS (well-known community)\n"
10391 "Do not advertise to any peer (well-known community)\n"
10392 "Do not export to next AS (well-known community)\n"
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 "community number\n"
10398 "Do not send outside local AS (well-known community)\n"
10399 "Do not advertise to any peer (well-known community)\n"
10400 "Do not export to next AS (well-known community)\n"
10401 "community number\n"
10402 "Do not send outside local AS (well-known community)\n"
10403 "Do not advertise to any peer (well-known community)\n"
10404 "Do not export to next AS (well-known community)\n"
10405 "Exact match of the communities")
10406
10407DEFUN (show_ip_bgp_ipv4_community_exact,
10408 show_ip_bgp_ipv4_community_exact_cmd,
10409 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10410 SHOW_STR
10411 IP_STR
10412 BGP_STR
10413 "Address family\n"
10414 "Address Family modifier\n"
10415 "Address Family modifier\n"
10416 "Display routes matching the communities\n"
10417 "community number\n"
10418 "Do not send outside local AS (well-known community)\n"
10419 "Do not advertise to any peer (well-known community)\n"
10420 "Do not export to next AS (well-known community)\n"
10421 "Exact match of the communities")
10422{
10423 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 10424 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
718e3744 10425
95cbbd2a 10426 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 10427}
10428
10429ALIAS (show_ip_bgp_ipv4_community_exact,
10430 show_ip_bgp_ipv4_community2_exact_cmd,
10431 "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",
10432 SHOW_STR
10433 IP_STR
10434 BGP_STR
10435 "Address family\n"
10436 "Address Family modifier\n"
10437 "Address Family modifier\n"
10438 "Display routes matching the communities\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 "Exact match of the communities")
10448
10449ALIAS (show_ip_bgp_ipv4_community_exact,
10450 show_ip_bgp_ipv4_community3_exact_cmd,
10451 "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",
10452 SHOW_STR
10453 IP_STR
10454 BGP_STR
10455 "Address family\n"
10456 "Address Family modifier\n"
10457 "Address Family modifier\n"
10458 "Display routes matching the communities\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 "community number\n"
10468 "Do not send outside local AS (well-known community)\n"
10469 "Do not advertise to any peer (well-known community)\n"
10470 "Do not export to next AS (well-known community)\n"
10471 "Exact match of the communities")
10472
10473ALIAS (show_ip_bgp_ipv4_community_exact,
10474 show_ip_bgp_ipv4_community4_exact_cmd,
10475 "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",
10476 SHOW_STR
10477 IP_STR
10478 BGP_STR
10479 "Address family\n"
10480 "Address Family modifier\n"
10481 "Address Family modifier\n"
10482 "Display routes matching the communities\n"
10483 "community number\n"
10484 "Do not send outside local AS (well-known community)\n"
10485 "Do not advertise to any peer (well-known community)\n"
10486 "Do not export to next AS (well-known community)\n"
10487 "community number\n"
10488 "Do not send outside local AS (well-known community)\n"
10489 "Do not advertise to any peer (well-known community)\n"
10490 "Do not export to next AS (well-known community)\n"
10491 "community number\n"
10492 "Do not send outside local AS (well-known community)\n"
10493 "Do not advertise to any peer (well-known community)\n"
10494 "Do not export to next AS (well-known community)\n"
10495 "community number\n"
10496 "Do not send outside local AS (well-known community)\n"
10497 "Do not advertise to any peer (well-known community)\n"
10498 "Do not export to next AS (well-known community)\n"
10499 "Exact match of the communities")
10500
10501#ifdef HAVE_IPV6
10502DEFUN (show_bgp_community,
10503 show_bgp_community_cmd,
10504 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
10505 SHOW_STR
10506 BGP_STR
10507 "Display routes matching the communities\n"
10508 "community number\n"
10509 "Do not send outside local AS (well-known community)\n"
10510 "Do not advertise to any peer (well-known community)\n"
10511 "Do not export to next AS (well-known community)\n")
10512{
95cbbd2a 10513 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 10514}
10515
10516ALIAS (show_bgp_community,
10517 show_bgp_ipv6_community_cmd,
10518 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
10519 SHOW_STR
10520 BGP_STR
10521 "Address family\n"
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
10528ALIAS (show_bgp_community,
10529 show_bgp_community2_cmd,
10530 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10531 SHOW_STR
10532 BGP_STR
10533 "Display routes matching the communities\n"
10534 "community number\n"
10535 "Do not send outside local AS (well-known community)\n"
10536 "Do not advertise to any peer (well-known community)\n"
10537 "Do not export to next AS (well-known community)\n"
10538 "community number\n"
10539 "Do not send outside local AS (well-known community)\n"
10540 "Do not advertise to any peer (well-known community)\n"
10541 "Do not export to next AS (well-known community)\n")
10542
10543ALIAS (show_bgp_community,
10544 show_bgp_ipv6_community2_cmd,
10545 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10546 SHOW_STR
10547 BGP_STR
10548 "Address family\n"
10549 "Display routes matching the communities\n"
10550 "community number\n"
10551 "Do not send outside local AS (well-known community)\n"
10552 "Do not advertise to any peer (well-known community)\n"
10553 "Do not export to next AS (well-known community)\n"
10554 "community number\n"
10555 "Do not send outside local AS (well-known community)\n"
10556 "Do not advertise to any peer (well-known community)\n"
10557 "Do not export to next AS (well-known community)\n")
10558
10559ALIAS (show_bgp_community,
10560 show_bgp_community3_cmd,
10561 "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)",
10562 SHOW_STR
10563 BGP_STR
10564 "Display routes matching the communities\n"
10565 "community number\n"
10566 "Do not send outside local AS (well-known community)\n"
10567 "Do not advertise to any peer (well-known community)\n"
10568 "Do not export to next AS (well-known community)\n"
10569 "community number\n"
10570 "Do not send outside local AS (well-known community)\n"
10571 "Do not advertise to any peer (well-known community)\n"
10572 "Do not export to next AS (well-known community)\n"
10573 "community number\n"
10574 "Do not send outside local AS (well-known community)\n"
10575 "Do not advertise to any peer (well-known community)\n"
10576 "Do not export to next AS (well-known community)\n")
10577
10578ALIAS (show_bgp_community,
10579 show_bgp_ipv6_community3_cmd,
10580 "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)",
10581 SHOW_STR
10582 BGP_STR
10583 "Address family\n"
10584 "Display routes matching the communities\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 "community number\n"
10594 "Do not send outside local AS (well-known community)\n"
10595 "Do not advertise to any peer (well-known community)\n"
10596 "Do not export to next AS (well-known community)\n")
10597
10598ALIAS (show_bgp_community,
10599 show_bgp_community4_cmd,
10600 "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)",
10601 SHOW_STR
10602 BGP_STR
10603 "Display routes matching the communities\n"
10604 "community number\n"
10605 "Do not send outside local AS (well-known community)\n"
10606 "Do not advertise to any peer (well-known community)\n"
10607 "Do not export to next AS (well-known community)\n"
10608 "community number\n"
10609 "Do not send outside local AS (well-known community)\n"
10610 "Do not advertise to any peer (well-known community)\n"
10611 "Do not export to next AS (well-known community)\n"
10612 "community number\n"
10613 "Do not send outside local AS (well-known community)\n"
10614 "Do not advertise to any peer (well-known community)\n"
10615 "Do not export to next AS (well-known community)\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
10621ALIAS (show_bgp_community,
10622 show_bgp_ipv6_community4_cmd,
10623 "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)",
10624 SHOW_STR
10625 BGP_STR
10626 "Address family\n"
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 "community number\n"
10637 "Do not send outside local AS (well-known community)\n"
10638 "Do not advertise to any peer (well-known community)\n"
10639 "Do not export to next AS (well-known community)\n"
10640 "community number\n"
10641 "Do not send outside local AS (well-known community)\n"
10642 "Do not advertise to any peer (well-known community)\n"
10643 "Do not export to next AS (well-known community)\n")
10644
10645/* old command */
10646DEFUN (show_ipv6_bgp_community,
10647 show_ipv6_bgp_community_cmd,
10648 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
10649 SHOW_STR
10650 IPV6_STR
10651 BGP_STR
10652 "Display routes matching the communities\n"
10653 "community number\n"
10654 "Do not send outside local AS (well-known community)\n"
10655 "Do not advertise to any peer (well-known community)\n"
10656 "Do not export to next AS (well-known community)\n")
10657{
95cbbd2a 10658 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 10659}
10660
10661/* old command */
10662ALIAS (show_ipv6_bgp_community,
10663 show_ipv6_bgp_community2_cmd,
10664 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10665 SHOW_STR
10666 IPV6_STR
10667 BGP_STR
10668 "Display routes matching the communities\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 "community number\n"
10674 "Do not send outside local AS (well-known community)\n"
10675 "Do not advertise to any peer (well-known community)\n"
10676 "Do not export to next AS (well-known community)\n")
10677
10678/* old command */
10679ALIAS (show_ipv6_bgp_community,
10680 show_ipv6_bgp_community3_cmd,
10681 "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)",
10682 SHOW_STR
10683 IPV6_STR
10684 BGP_STR
10685 "Display routes matching the communities\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 "community number\n"
10695 "Do not send outside local AS (well-known community)\n"
10696 "Do not advertise to any peer (well-known community)\n"
10697 "Do not export to next AS (well-known community)\n")
10698
10699/* old command */
10700ALIAS (show_ipv6_bgp_community,
10701 show_ipv6_bgp_community4_cmd,
10702 "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)",
10703 SHOW_STR
10704 IPV6_STR
10705 BGP_STR
10706 "Display routes matching the communities\n"
10707 "community number\n"
10708 "Do not send outside local AS (well-known community)\n"
10709 "Do not advertise to any peer (well-known community)\n"
10710 "Do not export to next AS (well-known community)\n"
10711 "community number\n"
10712 "Do not send outside local AS (well-known community)\n"
10713 "Do not advertise to any peer (well-known community)\n"
10714 "Do not export to next AS (well-known community)\n"
10715 "community number\n"
10716 "Do not send outside local AS (well-known community)\n"
10717 "Do not advertise to any peer (well-known community)\n"
10718 "Do not export to next AS (well-known community)\n"
10719 "community number\n"
10720 "Do not send outside local AS (well-known community)\n"
10721 "Do not advertise to any peer (well-known community)\n"
10722 "Do not export to next AS (well-known community)\n")
10723
10724DEFUN (show_bgp_community_exact,
10725 show_bgp_community_exact_cmd,
10726 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10727 SHOW_STR
10728 BGP_STR
10729 "Display routes matching the communities\n"
10730 "community number\n"
10731 "Do not send outside local AS (well-known community)\n"
10732 "Do not advertise to any peer (well-known community)\n"
10733 "Do not export to next AS (well-known community)\n"
10734 "Exact match of the communities")
10735{
95cbbd2a 10736 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 10737}
10738
10739ALIAS (show_bgp_community_exact,
10740 show_bgp_ipv6_community_exact_cmd,
10741 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10742 SHOW_STR
10743 BGP_STR
10744 "Address family\n"
10745 "Display routes matching the communities\n"
10746 "community number\n"
10747 "Do not send outside local AS (well-known community)\n"
10748 "Do not advertise to any peer (well-known community)\n"
10749 "Do not export to next AS (well-known community)\n"
10750 "Exact match of the communities")
10751
10752ALIAS (show_bgp_community_exact,
10753 show_bgp_community2_exact_cmd,
10754 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10755 SHOW_STR
10756 BGP_STR
10757 "Display routes matching the communities\n"
10758 "community number\n"
10759 "Do not send outside local AS (well-known community)\n"
10760 "Do not advertise to any peer (well-known community)\n"
10761 "Do not export to next AS (well-known community)\n"
10762 "community number\n"
10763 "Do not send outside local AS (well-known community)\n"
10764 "Do not advertise to any peer (well-known community)\n"
10765 "Do not export to next AS (well-known community)\n"
10766 "Exact match of the communities")
10767
10768ALIAS (show_bgp_community_exact,
10769 show_bgp_ipv6_community2_exact_cmd,
10770 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10771 SHOW_STR
10772 BGP_STR
10773 "Address family\n"
10774 "Display routes matching the communities\n"
10775 "community number\n"
10776 "Do not send outside local AS (well-known community)\n"
10777 "Do not advertise to any peer (well-known community)\n"
10778 "Do not export to next AS (well-known community)\n"
10779 "community number\n"
10780 "Do not send outside local AS (well-known community)\n"
10781 "Do not advertise to any peer (well-known community)\n"
10782 "Do not export to next AS (well-known community)\n"
10783 "Exact match of the communities")
10784
10785ALIAS (show_bgp_community_exact,
10786 show_bgp_community3_exact_cmd,
10787 "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",
10788 SHOW_STR
10789 BGP_STR
10790 "Display routes matching the communities\n"
10791 "community number\n"
10792 "Do not send outside local AS (well-known community)\n"
10793 "Do not advertise to any peer (well-known community)\n"
10794 "Do not export to next AS (well-known community)\n"
10795 "community number\n"
10796 "Do not send outside local AS (well-known community)\n"
10797 "Do not advertise to any peer (well-known community)\n"
10798 "Do not export to next AS (well-known community)\n"
10799 "community number\n"
10800 "Do not send outside local AS (well-known community)\n"
10801 "Do not advertise to any peer (well-known community)\n"
10802 "Do not export to next AS (well-known community)\n"
10803 "Exact match of the communities")
10804
10805ALIAS (show_bgp_community_exact,
10806 show_bgp_ipv6_community3_exact_cmd,
10807 "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",
10808 SHOW_STR
10809 BGP_STR
10810 "Address family\n"
10811 "Display routes matching the communities\n"
10812 "community number\n"
10813 "Do not send outside local AS (well-known community)\n"
10814 "Do not advertise to any peer (well-known community)\n"
10815 "Do not export to next AS (well-known community)\n"
10816 "community number\n"
10817 "Do not send outside local AS (well-known community)\n"
10818 "Do not advertise to any peer (well-known community)\n"
10819 "Do not export to next AS (well-known community)\n"
10820 "community number\n"
10821 "Do not send outside local AS (well-known community)\n"
10822 "Do not advertise to any peer (well-known community)\n"
10823 "Do not export to next AS (well-known community)\n"
10824 "Exact match of the communities")
10825
10826ALIAS (show_bgp_community_exact,
10827 show_bgp_community4_exact_cmd,
10828 "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",
10829 SHOW_STR
10830 BGP_STR
10831 "Display routes matching the communities\n"
10832 "community number\n"
10833 "Do not send outside local AS (well-known community)\n"
10834 "Do not advertise to any peer (well-known community)\n"
10835 "Do not export to next AS (well-known community)\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 "community number\n"
10841 "Do not send outside local AS (well-known community)\n"
10842 "Do not advertise to any peer (well-known community)\n"
10843 "Do not export to next AS (well-known community)\n"
10844 "community number\n"
10845 "Do not send outside local AS (well-known community)\n"
10846 "Do not advertise to any peer (well-known community)\n"
10847 "Do not export to next AS (well-known community)\n"
10848 "Exact match of the communities")
10849
10850ALIAS (show_bgp_community_exact,
10851 show_bgp_ipv6_community4_exact_cmd,
10852 "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",
10853 SHOW_STR
10854 BGP_STR
10855 "Address family\n"
10856 "Display routes matching the communities\n"
10857 "community number\n"
10858 "Do not send outside local AS (well-known community)\n"
10859 "Do not advertise to any peer (well-known community)\n"
10860 "Do not export to next AS (well-known community)\n"
10861 "community number\n"
10862 "Do not send outside local AS (well-known community)\n"
10863 "Do not advertise to any peer (well-known community)\n"
10864 "Do not export to next AS (well-known community)\n"
10865 "community number\n"
10866 "Do not send outside local AS (well-known community)\n"
10867 "Do not advertise to any peer (well-known community)\n"
10868 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10874
10875/* old command */
10876DEFUN (show_ipv6_bgp_community_exact,
10877 show_ipv6_bgp_community_exact_cmd,
10878 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10879 SHOW_STR
10880 IPV6_STR
10881 BGP_STR
10882 "Display routes matching the communities\n"
10883 "community number\n"
10884 "Do not send outside local AS (well-known community)\n"
10885 "Do not advertise to any peer (well-known community)\n"
10886 "Do not export to next AS (well-known community)\n"
10887 "Exact match of the communities")
10888{
95cbbd2a 10889 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 10890}
10891
10892/* old command */
10893ALIAS (show_ipv6_bgp_community_exact,
10894 show_ipv6_bgp_community2_exact_cmd,
10895 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10896 SHOW_STR
10897 IPV6_STR
10898 BGP_STR
10899 "Display routes matching the communities\n"
10900 "community number\n"
10901 "Do not send outside local AS (well-known community)\n"
10902 "Do not advertise to any peer (well-known community)\n"
10903 "Do not export to next AS (well-known community)\n"
10904 "community number\n"
10905 "Do not send outside local AS (well-known community)\n"
10906 "Do not advertise to any peer (well-known community)\n"
10907 "Do not export to next AS (well-known community)\n"
10908 "Exact match of the communities")
10909
10910/* old command */
10911ALIAS (show_ipv6_bgp_community_exact,
10912 show_ipv6_bgp_community3_exact_cmd,
10913 "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",
10914 SHOW_STR
10915 IPV6_STR
10916 BGP_STR
10917 "Display routes matching the communities\n"
10918 "community number\n"
10919 "Do not send outside local AS (well-known community)\n"
10920 "Do not advertise to any peer (well-known community)\n"
10921 "Do not export to next AS (well-known community)\n"
10922 "community number\n"
10923 "Do not send outside local AS (well-known community)\n"
10924 "Do not advertise to any peer (well-known community)\n"
10925 "Do not export to next AS (well-known community)\n"
10926 "community number\n"
10927 "Do not send outside local AS (well-known community)\n"
10928 "Do not advertise to any peer (well-known community)\n"
10929 "Do not export to next AS (well-known community)\n"
10930 "Exact match of the communities")
10931
10932/* old command */
10933ALIAS (show_ipv6_bgp_community_exact,
10934 show_ipv6_bgp_community4_exact_cmd,
10935 "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",
10936 SHOW_STR
10937 IPV6_STR
10938 BGP_STR
10939 "Display routes matching the communities\n"
10940 "community number\n"
10941 "Do not send outside local AS (well-known community)\n"
10942 "Do not advertise to any peer (well-known community)\n"
10943 "Do not export to next AS (well-known community)\n"
10944 "community number\n"
10945 "Do not send outside local AS (well-known community)\n"
10946 "Do not advertise to any peer (well-known community)\n"
10947 "Do not export to next AS (well-known community)\n"
10948 "community number\n"
10949 "Do not send outside local AS (well-known community)\n"
10950 "Do not advertise to any peer (well-known community)\n"
10951 "Do not export to next AS (well-known community)\n"
10952 "community number\n"
10953 "Do not send outside local AS (well-known community)\n"
10954 "Do not advertise to any peer (well-known community)\n"
10955 "Do not export to next AS (well-known community)\n"
10956 "Exact match of the communities")
10957
10958/* old command */
10959DEFUN (show_ipv6_mbgp_community,
10960 show_ipv6_mbgp_community_cmd,
10961 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10962 SHOW_STR
10963 IPV6_STR
10964 MBGP_STR
10965 "Display routes matching the communities\n"
10966 "community number\n"
10967 "Do not send outside local AS (well-known community)\n"
10968 "Do not advertise to any peer (well-known community)\n"
10969 "Do not export to next AS (well-known community)\n")
10970{
95cbbd2a 10971 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
718e3744 10972}
10973
10974/* old command */
10975ALIAS (show_ipv6_mbgp_community,
10976 show_ipv6_mbgp_community2_cmd,
10977 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10978 SHOW_STR
10979 IPV6_STR
10980 MBGP_STR
10981 "Display routes matching the communities\n"
10982 "community number\n"
10983 "Do not send outside local AS (well-known community)\n"
10984 "Do not advertise to any peer (well-known community)\n"
10985 "Do not export to next AS (well-known community)\n"
10986 "community number\n"
10987 "Do not send outside local AS (well-known community)\n"
10988 "Do not advertise to any peer (well-known community)\n"
10989 "Do not export to next AS (well-known community)\n")
10990
10991/* old command */
10992ALIAS (show_ipv6_mbgp_community,
10993 show_ipv6_mbgp_community3_cmd,
10994 "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)",
10995 SHOW_STR
10996 IPV6_STR
10997 MBGP_STR
10998 "Display routes matching the communities\n"
10999 "community number\n"
11000 "Do not send outside local AS (well-known community)\n"
11001 "Do not advertise to any peer (well-known community)\n"
11002 "Do not export to next AS (well-known community)\n"
11003 "community number\n"
11004 "Do not send outside local AS (well-known community)\n"
11005 "Do not advertise to any peer (well-known community)\n"
11006 "Do not export to next AS (well-known community)\n"
11007 "community number\n"
11008 "Do not send outside local AS (well-known community)\n"
11009 "Do not advertise to any peer (well-known community)\n"
11010 "Do not export to next AS (well-known community)\n")
11011
11012/* old command */
11013ALIAS (show_ipv6_mbgp_community,
11014 show_ipv6_mbgp_community4_cmd,
11015 "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)",
11016 SHOW_STR
11017 IPV6_STR
11018 MBGP_STR
11019 "Display routes matching the communities\n"
11020 "community number\n"
11021 "Do not send outside local AS (well-known community)\n"
11022 "Do not advertise to any peer (well-known community)\n"
11023 "Do not export to next AS (well-known community)\n"
11024 "community number\n"
11025 "Do not send outside local AS (well-known community)\n"
11026 "Do not advertise to any peer (well-known community)\n"
11027 "Do not export to next AS (well-known community)\n"
11028 "community number\n"
11029 "Do not send outside local AS (well-known community)\n"
11030 "Do not advertise to any peer (well-known community)\n"
11031 "Do not export to next AS (well-known community)\n"
11032 "community number\n"
11033 "Do not send outside local AS (well-known community)\n"
11034 "Do not advertise to any peer (well-known community)\n"
11035 "Do not export to next AS (well-known community)\n")
11036
11037/* old command */
11038DEFUN (show_ipv6_mbgp_community_exact,
11039 show_ipv6_mbgp_community_exact_cmd,
11040 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
11041 SHOW_STR
11042 IPV6_STR
11043 MBGP_STR
11044 "Display routes matching the communities\n"
11045 "community number\n"
11046 "Do not send outside local AS (well-known community)\n"
11047 "Do not advertise to any peer (well-known community)\n"
11048 "Do not export to next AS (well-known community)\n"
11049 "Exact match of the communities")
11050{
95cbbd2a 11051 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
718e3744 11052}
11053
11054/* old command */
11055ALIAS (show_ipv6_mbgp_community_exact,
11056 show_ipv6_mbgp_community2_exact_cmd,
11057 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
11058 SHOW_STR
11059 IPV6_STR
11060 MBGP_STR
11061 "Display routes matching the communities\n"
11062 "community number\n"
11063 "Do not send outside local AS (well-known community)\n"
11064 "Do not advertise to any peer (well-known community)\n"
11065 "Do not export to next AS (well-known community)\n"
11066 "community number\n"
11067 "Do not send outside local AS (well-known community)\n"
11068 "Do not advertise to any peer (well-known community)\n"
11069 "Do not export to next AS (well-known community)\n"
11070 "Exact match of the communities")
11071
11072/* old command */
11073ALIAS (show_ipv6_mbgp_community_exact,
11074 show_ipv6_mbgp_community3_exact_cmd,
11075 "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",
11076 SHOW_STR
11077 IPV6_STR
11078 MBGP_STR
11079 "Display routes matching the communities\n"
11080 "community number\n"
11081 "Do not send outside local AS (well-known community)\n"
11082 "Do not advertise to any peer (well-known community)\n"
11083 "Do not export to next AS (well-known community)\n"
11084 "community number\n"
11085 "Do not send outside local AS (well-known community)\n"
11086 "Do not advertise to any peer (well-known community)\n"
11087 "Do not export to next AS (well-known community)\n"
11088 "community number\n"
11089 "Do not send outside local AS (well-known community)\n"
11090 "Do not advertise to any peer (well-known community)\n"
11091 "Do not export to next AS (well-known community)\n"
11092 "Exact match of the communities")
11093
11094/* old command */
11095ALIAS (show_ipv6_mbgp_community_exact,
11096 show_ipv6_mbgp_community4_exact_cmd,
11097 "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",
11098 SHOW_STR
11099 IPV6_STR
11100 MBGP_STR
11101 "Display routes matching the communities\n"
11102 "community number\n"
11103 "Do not send outside local AS (well-known community)\n"
11104 "Do not advertise to any peer (well-known community)\n"
11105 "Do not export to next AS (well-known community)\n"
11106 "community number\n"
11107 "Do not send outside local AS (well-known community)\n"
11108 "Do not advertise to any peer (well-known community)\n"
11109 "Do not export to next AS (well-known community)\n"
11110 "community number\n"
11111 "Do not send outside local AS (well-known community)\n"
11112 "Do not advertise to any peer (well-known community)\n"
11113 "Do not export to next AS (well-known community)\n"
11114 "community number\n"
11115 "Do not send outside local AS (well-known community)\n"
11116 "Do not advertise to any peer (well-known community)\n"
11117 "Do not export to next AS (well-known community)\n"
11118 "Exact match of the communities")
11119#endif /* HAVE_IPV6 */
6b0655a2 11120
94f2b392 11121static int
fd79ac91 11122bgp_show_community_list (struct vty *vty, const char *com, int exact,
4c9641ba 11123 afi_t afi, safi_t safi)
718e3744 11124{
11125 struct community_list *list;
11126
fee6e4e4 11127 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
718e3744 11128 if (list == NULL)
11129 {
11130 vty_out (vty, "%% %s is not a valid community-list name%s", com,
11131 VTY_NEWLINE);
11132 return CMD_WARNING;
11133 }
11134
5a646650 11135 return bgp_show (vty, NULL, afi, safi,
11136 (exact ? bgp_show_type_community_list_exact :
b05a1c8b 11137 bgp_show_type_community_list), list, 0);
718e3744 11138}
11139
11140DEFUN (show_ip_bgp_community_list,
11141 show_ip_bgp_community_list_cmd,
fee6e4e4 11142 "show ip bgp community-list (<1-500>|WORD)",
718e3744 11143 SHOW_STR
11144 IP_STR
11145 BGP_STR
11146 "Display routes matching the community-list\n"
fee6e4e4 11147 "community-list number\n"
718e3744 11148 "community-list name\n")
11149{
11150 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11151}
11152
11153DEFUN (show_ip_bgp_ipv4_community_list,
11154 show_ip_bgp_ipv4_community_list_cmd,
fee6e4e4 11155 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
718e3744 11156 SHOW_STR
11157 IP_STR
11158 BGP_STR
11159 "Address family\n"
11160 "Address Family modifier\n"
11161 "Address Family modifier\n"
11162 "Display routes matching the community-list\n"
fee6e4e4 11163 "community-list number\n"
718e3744 11164 "community-list name\n")
11165{
11166 if (strncmp (argv[0], "m", 1) == 0)
11167 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11168
11169 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11170}
11171
11172DEFUN (show_ip_bgp_community_list_exact,
11173 show_ip_bgp_community_list_exact_cmd,
fee6e4e4 11174 "show ip bgp community-list (<1-500>|WORD) exact-match",
718e3744 11175 SHOW_STR
11176 IP_STR
11177 BGP_STR
11178 "Display routes matching the community-list\n"
fee6e4e4 11179 "community-list number\n"
718e3744 11180 "community-list name\n"
11181 "Exact match of the communities\n")
11182{
11183 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11184}
11185
11186DEFUN (show_ip_bgp_ipv4_community_list_exact,
11187 show_ip_bgp_ipv4_community_list_exact_cmd,
fee6e4e4 11188 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
718e3744 11189 SHOW_STR
11190 IP_STR
11191 BGP_STR
11192 "Address family\n"
11193 "Address Family modifier\n"
11194 "Address Family modifier\n"
11195 "Display routes matching the community-list\n"
fee6e4e4 11196 "community-list number\n"
718e3744 11197 "community-list name\n"
11198 "Exact match of the communities\n")
11199{
11200 if (strncmp (argv[0], "m", 1) == 0)
11201 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11202
11203 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11204}
11205
11206#ifdef HAVE_IPV6
11207DEFUN (show_bgp_community_list,
11208 show_bgp_community_list_cmd,
fee6e4e4 11209 "show bgp community-list (<1-500>|WORD)",
718e3744 11210 SHOW_STR
11211 BGP_STR
11212 "Display routes matching the community-list\n"
fee6e4e4 11213 "community-list number\n"
718e3744 11214 "community-list name\n")
11215{
11216 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11217}
11218
11219ALIAS (show_bgp_community_list,
11220 show_bgp_ipv6_community_list_cmd,
fee6e4e4 11221 "show bgp ipv6 community-list (<1-500>|WORD)",
718e3744 11222 SHOW_STR
11223 BGP_STR
11224 "Address family\n"
11225 "Display routes matching the community-list\n"
fee6e4e4 11226 "community-list number\n"
e8e1946e 11227 "community-list name\n")
718e3744 11228
11229/* old command */
11230DEFUN (show_ipv6_bgp_community_list,
11231 show_ipv6_bgp_community_list_cmd,
11232 "show ipv6 bgp community-list WORD",
11233 SHOW_STR
11234 IPV6_STR
11235 BGP_STR
11236 "Display routes matching the community-list\n"
11237 "community-list name\n")
11238{
11239 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11240}
11241
11242/* old command */
11243DEFUN (show_ipv6_mbgp_community_list,
11244 show_ipv6_mbgp_community_list_cmd,
11245 "show ipv6 mbgp community-list WORD",
11246 SHOW_STR
11247 IPV6_STR
11248 MBGP_STR
11249 "Display routes matching the community-list\n"
11250 "community-list name\n")
11251{
11252 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
11253}
11254
11255DEFUN (show_bgp_community_list_exact,
11256 show_bgp_community_list_exact_cmd,
fee6e4e4 11257 "show bgp community-list (<1-500>|WORD) exact-match",
718e3744 11258 SHOW_STR
11259 BGP_STR
11260 "Display routes matching the community-list\n"
fee6e4e4 11261 "community-list number\n"
718e3744 11262 "community-list name\n"
11263 "Exact match of the communities\n")
11264{
11265 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11266}
11267
11268ALIAS (show_bgp_community_list_exact,
11269 show_bgp_ipv6_community_list_exact_cmd,
fee6e4e4 11270 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
718e3744 11271 SHOW_STR
11272 BGP_STR
11273 "Address family\n"
11274 "Display routes matching the community-list\n"
fee6e4e4 11275 "community-list number\n"
718e3744 11276 "community-list name\n"
11277 "Exact match of the communities\n")
11278
11279/* old command */
11280DEFUN (show_ipv6_bgp_community_list_exact,
11281 show_ipv6_bgp_community_list_exact_cmd,
11282 "show ipv6 bgp community-list WORD exact-match",
11283 SHOW_STR
11284 IPV6_STR
11285 BGP_STR
11286 "Display routes matching the community-list\n"
11287 "community-list name\n"
11288 "Exact match of the communities\n")
11289{
11290 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11291}
11292
11293/* old command */
11294DEFUN (show_ipv6_mbgp_community_list_exact,
11295 show_ipv6_mbgp_community_list_exact_cmd,
11296 "show ipv6 mbgp community-list WORD exact-match",
11297 SHOW_STR
11298 IPV6_STR
11299 MBGP_STR
11300 "Display routes matching the community-list\n"
11301 "community-list name\n"
11302 "Exact match of the communities\n")
11303{
11304 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
11305}
11306#endif /* HAVE_IPV6 */
6b0655a2 11307
94f2b392 11308static int
fd79ac91 11309bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
718e3744 11310 safi_t safi, enum bgp_show_type type)
11311{
11312 int ret;
11313 struct prefix *p;
11314
11315 p = prefix_new();
11316
11317 ret = str2prefix (prefix, p);
11318 if (! ret)
11319 {
11320 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11321 return CMD_WARNING;
11322 }
11323
b05a1c8b 11324 ret = bgp_show (vty, NULL, afi, safi, type, p, 0);
5a646650 11325 prefix_free(p);
11326 return ret;
718e3744 11327}
11328
11329DEFUN (show_ip_bgp_prefix_longer,
11330 show_ip_bgp_prefix_longer_cmd,
11331 "show ip bgp A.B.C.D/M longer-prefixes",
11332 SHOW_STR
11333 IP_STR
11334 BGP_STR
11335 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11336 "Display route and more specific routes\n")
11337{
11338 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11339 bgp_show_type_prefix_longer);
11340}
11341
11342DEFUN (show_ip_bgp_flap_prefix_longer,
11343 show_ip_bgp_flap_prefix_longer_cmd,
11344 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11345 SHOW_STR
11346 IP_STR
11347 BGP_STR
11348 "Display flap statistics of routes\n"
11349 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11350 "Display route and more specific routes\n")
11351{
11352 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11353 bgp_show_type_flap_prefix_longer);
11354}
11355
11356DEFUN (show_ip_bgp_ipv4_prefix_longer,
11357 show_ip_bgp_ipv4_prefix_longer_cmd,
11358 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11359 SHOW_STR
11360 IP_STR
11361 BGP_STR
11362 "Address family\n"
11363 "Address Family modifier\n"
11364 "Address Family modifier\n"
11365 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11366 "Display route and more specific routes\n")
11367{
11368 if (strncmp (argv[0], "m", 1) == 0)
11369 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
11370 bgp_show_type_prefix_longer);
11371
11372 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
11373 bgp_show_type_prefix_longer);
11374}
11375
11376DEFUN (show_ip_bgp_flap_address,
11377 show_ip_bgp_flap_address_cmd,
11378 "show ip bgp flap-statistics A.B.C.D",
11379 SHOW_STR
11380 IP_STR
11381 BGP_STR
11382 "Display flap statistics of routes\n"
11383 "Network in the BGP routing table to display\n")
11384{
11385 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11386 bgp_show_type_flap_address);
11387}
11388
11389DEFUN (show_ip_bgp_flap_prefix,
11390 show_ip_bgp_flap_prefix_cmd,
11391 "show ip bgp flap-statistics A.B.C.D/M",
11392 SHOW_STR
11393 IP_STR
11394 BGP_STR
11395 "Display flap statistics of routes\n"
11396 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11397{
11398 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11399 bgp_show_type_flap_prefix);
11400}
11401#ifdef HAVE_IPV6
11402DEFUN (show_bgp_prefix_longer,
11403 show_bgp_prefix_longer_cmd,
11404 "show bgp X:X::X:X/M longer-prefixes",
11405 SHOW_STR
11406 BGP_STR
11407 "IPv6 prefix <network>/<length>\n"
11408 "Display route and more specific routes\n")
11409{
11410 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11411 bgp_show_type_prefix_longer);
11412}
11413
11414ALIAS (show_bgp_prefix_longer,
11415 show_bgp_ipv6_prefix_longer_cmd,
11416 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11417 SHOW_STR
11418 BGP_STR
11419 "Address family\n"
11420 "IPv6 prefix <network>/<length>\n"
11421 "Display route and more specific routes\n")
11422
11423/* old command */
11424DEFUN (show_ipv6_bgp_prefix_longer,
11425 show_ipv6_bgp_prefix_longer_cmd,
11426 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11427 SHOW_STR
11428 IPV6_STR
11429 BGP_STR
11430 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11431 "Display route and more specific routes\n")
11432{
11433 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11434 bgp_show_type_prefix_longer);
11435}
11436
11437/* old command */
11438DEFUN (show_ipv6_mbgp_prefix_longer,
11439 show_ipv6_mbgp_prefix_longer_cmd,
11440 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11441 SHOW_STR
11442 IPV6_STR
11443 MBGP_STR
11444 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11445 "Display route and more specific routes\n")
11446{
11447 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
11448 bgp_show_type_prefix_longer);
11449}
11450#endif /* HAVE_IPV6 */
bb46e94f 11451
94f2b392 11452static struct peer *
fd79ac91 11453peer_lookup_in_view (struct vty *vty, const char *view_name,
11454 const char *ip_str)
bb46e94f 11455{
11456 int ret;
11457 struct bgp *bgp;
11458 struct peer *peer;
11459 union sockunion su;
11460
11461 /* BGP structure lookup. */
11462 if (view_name)
11463 {
11464 bgp = bgp_lookup_by_name (view_name);
11465 if (! bgp)
11466 {
11467 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11468 return NULL;
11469 }
11470 }
5228ad27 11471 else
bb46e94f 11472 {
11473 bgp = bgp_get_default ();
11474 if (! bgp)
11475 {
11476 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11477 return NULL;
11478 }
11479 }
11480
11481 /* Get peer sockunion. */
11482 ret = str2sockunion (ip_str, &su);
11483 if (ret < 0)
11484 {
a80beece
DS
11485 peer = peer_lookup_by_conf_if (bgp, ip_str);
11486 if (!peer)
11487 {
11488 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
11489 return NULL;
11490 }
11491 return peer;
bb46e94f 11492 }
11493
11494 /* Peer structure lookup. */
11495 peer = peer_lookup (bgp, &su);
11496 if (! peer)
11497 {
11498 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11499 return NULL;
11500 }
11501
11502 return peer;
11503}
6b0655a2 11504
2815e61f
PJ
11505enum bgp_stats
11506{
11507 BGP_STATS_MAXBITLEN = 0,
11508 BGP_STATS_RIB,
11509 BGP_STATS_PREFIXES,
11510 BGP_STATS_TOTPLEN,
11511 BGP_STATS_UNAGGREGATEABLE,
11512 BGP_STATS_MAX_AGGREGATEABLE,
11513 BGP_STATS_AGGREGATES,
11514 BGP_STATS_SPACE,
11515 BGP_STATS_ASPATH_COUNT,
11516 BGP_STATS_ASPATH_MAXHOPS,
11517 BGP_STATS_ASPATH_TOTHOPS,
11518 BGP_STATS_ASPATH_MAXSIZE,
11519 BGP_STATS_ASPATH_TOTSIZE,
11520 BGP_STATS_ASN_HIGHEST,
11521 BGP_STATS_MAX,
11522};
11523
11524static const char *table_stats_strs[] =
11525{
11526 [BGP_STATS_PREFIXES] = "Total Prefixes",
11527 [BGP_STATS_TOTPLEN] = "Average prefix length",
11528 [BGP_STATS_RIB] = "Total Advertisements",
11529 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11530 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11531 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11532 [BGP_STATS_SPACE] = "Address space advertised",
11533 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11534 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11535 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11536 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11537 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11538 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11539 [BGP_STATS_MAX] = NULL,
11540};
11541
11542struct bgp_table_stats
11543{
11544 struct bgp_table *table;
11545 unsigned long long counts[BGP_STATS_MAX];
11546};
11547
11548#if 0
11549#define TALLY_SIGFIG 100000
11550static unsigned long
11551ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11552{
11553 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11554 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11555 unsigned long ret = newtot / count;
11556
11557 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11558 return ret + 1;
11559 else
11560 return ret;
11561}
11562#endif
11563
11564static int
11565bgp_table_stats_walker (struct thread *t)
11566{
11567 struct bgp_node *rn;
11568 struct bgp_node *top;
11569 struct bgp_table_stats *ts = THREAD_ARG (t);
11570 unsigned int space = 0;
11571
53d9f67a
PJ
11572 if (!(top = bgp_table_top (ts->table)))
11573 return 0;
2815e61f
PJ
11574
11575 switch (top->p.family)
11576 {
11577 case AF_INET:
11578 space = IPV4_MAX_BITLEN;
11579 break;
11580 case AF_INET6:
11581 space = IPV6_MAX_BITLEN;
11582 break;
11583 }
11584
11585 ts->counts[BGP_STATS_MAXBITLEN] = space;
11586
11587 for (rn = top; rn; rn = bgp_route_next (rn))
11588 {
11589 struct bgp_info *ri;
67174041 11590 struct bgp_node *prn = bgp_node_parent_nolock (rn);
2815e61f
PJ
11591 unsigned int rinum = 0;
11592
11593 if (rn == top)
11594 continue;
11595
11596 if (!rn->info)
11597 continue;
11598
11599 ts->counts[BGP_STATS_PREFIXES]++;
11600 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11601
11602#if 0
11603 ts->counts[BGP_STATS_AVGPLEN]
11604 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11605 ts->counts[BGP_STATS_AVGPLEN],
11606 rn->p.prefixlen);
11607#endif
11608
11609 /* check if the prefix is included by any other announcements */
11610 while (prn && !prn->info)
67174041 11611 prn = bgp_node_parent_nolock (prn);
2815e61f
PJ
11612
11613 if (prn == NULL || prn == top)
8383a9bd
PJ
11614 {
11615 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11616 /* announced address space */
11617 if (space)
11618 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11619 }
2815e61f
PJ
11620 else if (prn->info)
11621 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11622
2815e61f
PJ
11623 for (ri = rn->info; ri; ri = ri->next)
11624 {
11625 rinum++;
11626 ts->counts[BGP_STATS_RIB]++;
11627
11628 if (ri->attr &&
11629 (CHECK_FLAG (ri->attr->flag,
11630 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11631 ts->counts[BGP_STATS_AGGREGATES]++;
11632
11633 /* as-path stats */
11634 if (ri->attr && ri->attr->aspath)
11635 {
11636 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11637 unsigned int size = aspath_size (ri->attr->aspath);
11638 as_t highest = aspath_highest (ri->attr->aspath);
11639
11640 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11641
11642 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11643 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11644
11645 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11646 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11647
11648 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11649 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11650#if 0
11651 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11652 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11653 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11654 hops);
11655 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11656 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11657 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11658 size);
11659#endif
11660 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11661 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11662 }
11663 }
11664 }
11665 return 0;
11666}
11667
11668static int
11669bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11670{
11671 struct bgp_table_stats ts;
11672 unsigned int i;
11673
11674 if (!bgp->rib[afi][safi])
11675 {
11676 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
11677 return CMD_WARNING;
11678 }
11679
11680 memset (&ts, 0, sizeof (ts));
11681 ts.table = bgp->rib[afi][safi];
11682 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
bb46e94f 11683
2815e61f
PJ
11684 vty_out (vty, "BGP %s RIB statistics%s%s",
11685 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11686
11687 for (i = 0; i < BGP_STATS_MAX; i++)
11688 {
11689 if (!table_stats_strs[i])
11690 continue;
11691
11692 switch (i)
11693 {
11694#if 0
11695 case BGP_STATS_ASPATH_AVGHOPS:
11696 case BGP_STATS_ASPATH_AVGSIZE:
11697 case BGP_STATS_AVGPLEN:
11698 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11699 vty_out (vty, "%12.2f",
11700 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11701 break;
11702#endif
11703 case BGP_STATS_ASPATH_TOTHOPS:
11704 case BGP_STATS_ASPATH_TOTSIZE:
11705 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11706 vty_out (vty, "%12.2f",
11707 ts.counts[i] ?
11708 (float)ts.counts[i] /
11709 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11710 : 0);
11711 break;
11712 case BGP_STATS_TOTPLEN:
11713 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11714 vty_out (vty, "%12.2f",
11715 ts.counts[i] ?
11716 (float)ts.counts[i] /
11717 (float)ts.counts[BGP_STATS_PREFIXES]
11718 : 0);
11719 break;
11720 case BGP_STATS_SPACE:
11721 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11722 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11723 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11724 break;
30a2231a 11725 vty_out (vty, "%30s: ", "%% announced ");
2815e61f
PJ
11726 vty_out (vty, "%12.2f%s",
11727 100 * (float)ts.counts[BGP_STATS_SPACE] /
56395af7 11728 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
2815e61f
PJ
11729 VTY_NEWLINE);
11730 vty_out (vty, "%30s: ", "/8 equivalent ");
11731 vty_out (vty, "%12.2f%s",
11732 (float)ts.counts[BGP_STATS_SPACE] /
11733 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11734 VTY_NEWLINE);
11735 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11736 break;
11737 vty_out (vty, "%30s: ", "/24 equivalent ");
11738 vty_out (vty, "%12.2f",
11739 (float)ts.counts[BGP_STATS_SPACE] /
11740 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11741 break;
11742 default:
11743 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11744 vty_out (vty, "%12llu", ts.counts[i]);
11745 }
11746
11747 vty_out (vty, "%s", VTY_NEWLINE);
11748 }
11749 return CMD_SUCCESS;
11750}
11751
11752static int
11753bgp_table_stats_vty (struct vty *vty, const char *name,
11754 const char *afi_str, const char *safi_str)
11755{
11756 struct bgp *bgp;
11757 afi_t afi;
11758 safi_t safi;
11759
11760 if (name)
11761 bgp = bgp_lookup_by_name (name);
11762 else
11763 bgp = bgp_get_default ();
11764
11765 if (!bgp)
11766 {
11767 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
11768 return CMD_WARNING;
11769 }
11770 if (strncmp (afi_str, "ipv", 3) == 0)
11771 {
11772 if (strncmp (afi_str, "ipv4", 4) == 0)
11773 afi = AFI_IP;
11774 else if (strncmp (afi_str, "ipv6", 4) == 0)
11775 afi = AFI_IP6;
11776 else
11777 {
11778 vty_out (vty, "%% Invalid address family %s%s",
11779 afi_str, VTY_NEWLINE);
11780 return CMD_WARNING;
11781 }
11782 if (strncmp (safi_str, "m", 1) == 0)
11783 safi = SAFI_MULTICAST;
11784 else if (strncmp (safi_str, "u", 1) == 0)
11785 safi = SAFI_UNICAST;
42e6d745
DO
11786 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
11787 safi = SAFI_MPLS_LABELED_VPN;
2815e61f
PJ
11788 else
11789 {
11790 vty_out (vty, "%% Invalid subsequent address family %s%s",
11791 safi_str, VTY_NEWLINE);
11792 return CMD_WARNING;
11793 }
11794 }
11795 else
11796 {
11797 vty_out (vty, "%% Invalid address family %s%s",
11798 afi_str, VTY_NEWLINE);
11799 return CMD_WARNING;
11800 }
11801
2815e61f
PJ
11802 return bgp_table_stats (vty, bgp, afi, safi);
11803}
11804
11805DEFUN (show_bgp_statistics,
11806 show_bgp_statistics_cmd,
11807 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
11808 SHOW_STR
11809 BGP_STR
11810 "Address family\n"
11811 "Address family\n"
11812 "Address Family modifier\n"
11813 "Address Family modifier\n"
11814 "BGP RIB advertisement statistics\n")
11815{
11816 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11817}
11818
11819ALIAS (show_bgp_statistics,
11820 show_bgp_statistics_vpnv4_cmd,
11821 "show bgp (ipv4) (vpnv4) statistics",
11822 SHOW_STR
11823 BGP_STR
11824 "Address family\n"
11825 "Address Family modifier\n"
11826 "BGP RIB advertisement statistics\n")
11827
11828DEFUN (show_bgp_statistics_view,
11829 show_bgp_statistics_view_cmd,
11830 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
11831 SHOW_STR
11832 BGP_STR
11833 "BGP view\n"
11834 "Address family\n"
11835 "Address family\n"
11836 "Address Family modifier\n"
11837 "Address Family modifier\n"
11838 "BGP RIB advertisement statistics\n")
11839{
11840 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11841}
11842
11843ALIAS (show_bgp_statistics_view,
11844 show_bgp_statistics_view_vpnv4_cmd,
11845 "show bgp view WORD (ipv4) (vpnv4) statistics",
11846 SHOW_STR
11847 BGP_STR
11848 "BGP view\n"
11849 "Address family\n"
11850 "Address Family modifier\n"
11851 "BGP RIB advertisement statistics\n")
6b0655a2 11852
ff7924f6
PJ
11853enum bgp_pcounts
11854{
11855 PCOUNT_ADJ_IN = 0,
11856 PCOUNT_DAMPED,
11857 PCOUNT_REMOVED,
11858 PCOUNT_HISTORY,
11859 PCOUNT_STALE,
11860 PCOUNT_VALID,
11861 PCOUNT_ALL,
11862 PCOUNT_COUNTED,
11863 PCOUNT_PFCNT, /* the figure we display to users */
11864 PCOUNT_MAX,
11865};
11866
11867static const char *pcount_strs[] =
11868{
11869 [PCOUNT_ADJ_IN] = "Adj-in",
11870 [PCOUNT_DAMPED] = "Damped",
11871 [PCOUNT_REMOVED] = "Removed",
11872 [PCOUNT_HISTORY] = "History",
11873 [PCOUNT_STALE] = "Stale",
11874 [PCOUNT_VALID] = "Valid",
11875 [PCOUNT_ALL] = "All RIB",
11876 [PCOUNT_COUNTED] = "PfxCt counted",
11877 [PCOUNT_PFCNT] = "Useable",
11878 [PCOUNT_MAX] = NULL,
11879};
11880
2815e61f
PJ
11881struct peer_pcounts
11882{
11883 unsigned int count[PCOUNT_MAX];
11884 const struct peer *peer;
11885 const struct bgp_table *table;
11886};
11887
ff7924f6 11888static int
2815e61f 11889bgp_peer_count_walker (struct thread *t)
ff7924f6
PJ
11890{
11891 struct bgp_node *rn;
2815e61f
PJ
11892 struct peer_pcounts *pc = THREAD_ARG (t);
11893 const struct peer *peer = pc->peer;
ff7924f6 11894
2815e61f 11895 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
ff7924f6
PJ
11896 {
11897 struct bgp_adj_in *ain;
2815e61f 11898 struct bgp_info *ri;
ff7924f6
PJ
11899
11900 for (ain = rn->adj_in; ain; ain = ain->next)
11901 if (ain->peer == peer)
2815e61f 11902 pc->count[PCOUNT_ADJ_IN]++;
ff7924f6 11903
ff7924f6
PJ
11904 for (ri = rn->info; ri; ri = ri->next)
11905 {
11906 char buf[SU_ADDRSTRLEN];
11907
11908 if (ri->peer != peer)
11909 continue;
11910
2815e61f 11911 pc->count[PCOUNT_ALL]++;
ff7924f6
PJ
11912
11913 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
2815e61f 11914 pc->count[PCOUNT_DAMPED]++;
ff7924f6 11915 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2815e61f 11916 pc->count[PCOUNT_HISTORY]++;
ff7924f6 11917 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
2815e61f 11918 pc->count[PCOUNT_REMOVED]++;
ff7924f6 11919 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2815e61f 11920 pc->count[PCOUNT_STALE]++;
ff7924f6 11921 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
2815e61f 11922 pc->count[PCOUNT_VALID]++;
1a392d46 11923 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2815e61f 11924 pc->count[PCOUNT_PFCNT]++;
ff7924f6
PJ
11925
11926 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
11927 {
2815e61f 11928 pc->count[PCOUNT_COUNTED]++;
1a392d46 11929 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 11930 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
ff7924f6
PJ
11931 peer->host,
11932 inet_ntop(rn->p.family, &rn->p.u.prefix,
11933 buf, SU_ADDRSTRLEN),
11934 rn->p.prefixlen,
11935 ri->flags);
11936 }
11937 else
11938 {
1a392d46 11939 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 11940 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
ff7924f6
PJ
11941 peer->host,
11942 inet_ntop(rn->p.family, &rn->p.u.prefix,
11943 buf, SU_ADDRSTRLEN),
11944 rn->p.prefixlen,
11945 ri->flags);
11946 }
11947 }
11948 }
2815e61f
PJ
11949 return 0;
11950}
ff7924f6 11951
2815e61f
PJ
11952static int
11953bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
11954{
11955 struct peer_pcounts pcounts = { .peer = peer };
11956 unsigned int i;
11957
11958 if (!peer || !peer->bgp || !peer->afc[afi][safi]
11959 || !peer->bgp->rib[afi][safi])
11960 {
11961 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11962 return CMD_WARNING;
11963 }
11964
11965 memset (&pcounts, 0, sizeof(pcounts));
11966 pcounts.peer = peer;
11967 pcounts.table = peer->bgp->rib[afi][safi];
11968
11969 /* in-place call via thread subsystem so as to record execution time
11970 * stats for the thread-walk (i.e. ensure this can't be blamed on
11971 * on just vty_read()).
11972 */
11973 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
11974
ff7924f6
PJ
11975 vty_out (vty, "Prefix counts for %s, %s%s",
11976 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
11977 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
11978 vty_out (vty, "%sCounts from RIB table walk:%s%s",
11979 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
11980
11981 for (i = 0; i < PCOUNT_MAX; i++)
2815e61f
PJ
11982 vty_out (vty, "%20s: %-10d%s",
11983 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
ff7924f6 11984
2815e61f 11985 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
ff7924f6
PJ
11986 {
11987 vty_out (vty, "%s [pcount] PfxCt drift!%s",
11988 peer->host, VTY_NEWLINE);
11989 vty_out (vty, "Please report this bug, with the above command output%s",
11990 VTY_NEWLINE);
11991 }
11992
11993 return CMD_SUCCESS;
11994}
11995
11996DEFUN (show_ip_bgp_neighbor_prefix_counts,
11997 show_ip_bgp_neighbor_prefix_counts_cmd,
a80beece 11998 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
ff7924f6
PJ
11999 SHOW_STR
12000 IP_STR
12001 BGP_STR
12002 "Detailed information on TCP and BGP neighbor connections\n"
12003 "Neighbor to display information about\n"
12004 "Neighbor to display information about\n"
a80beece 12005 "Neighbor on bgp configured interface\n"
ff7924f6
PJ
12006 "Display detailed prefix count information\n")
12007{
12008 struct peer *peer;
12009
12010 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12011 if (! peer)
12012 return CMD_WARNING;
12013
12014 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12015}
12016
12017DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12018 show_bgp_ipv6_neighbor_prefix_counts_cmd,
a80beece 12019 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
ff7924f6
PJ
12020 SHOW_STR
12021 BGP_STR
12022 "Address family\n"
12023 "Detailed information on TCP and BGP neighbor connections\n"
12024 "Neighbor to display information about\n"
12025 "Neighbor to display information about\n"
a80beece 12026 "Neighbor on bgp configured interface\n"
ff7924f6
PJ
12027 "Display detailed prefix count information\n")
12028{
12029 struct peer *peer;
12030
12031 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12032 if (! peer)
12033 return CMD_WARNING;
12034
12035 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
12036}
12037
12038DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12039 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
a80beece 12040 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
ff7924f6
PJ
12041 SHOW_STR
12042 IP_STR
12043 BGP_STR
12044 "Address family\n"
12045 "Address Family modifier\n"
12046 "Address Family modifier\n"
12047 "Detailed information on TCP and BGP neighbor connections\n"
12048 "Neighbor to display information about\n"
12049 "Neighbor to display information about\n"
a80beece 12050 "Neighbor on bgp configured interface\n"
ff7924f6
PJ
12051 "Display detailed prefix count information\n")
12052{
12053 struct peer *peer;
12054
12055 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12056 if (! peer)
12057 return CMD_WARNING;
12058
12059 if (strncmp (argv[0], "m", 1) == 0)
12060 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
12061
12062 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12063}
12064
12065DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
12066 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
a80beece 12067 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
ff7924f6
PJ
12068 SHOW_STR
12069 IP_STR
12070 BGP_STR
12071 "Address family\n"
12072 "Address Family modifier\n"
12073 "Address Family modifier\n"
12074 "Detailed information on TCP and BGP neighbor connections\n"
12075 "Neighbor to display information about\n"
12076 "Neighbor to display information about\n"
a80beece 12077 "Neighbor on bgp configured interface\n"
ff7924f6
PJ
12078 "Display detailed prefix count information\n")
12079{
12080 struct peer *peer;
12081
12082 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12083 if (! peer)
12084 return CMD_WARNING;
12085
12086 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
12087}
12088
94f2b392 12089static void
718e3744 12090show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
b05a1c8b 12091 int in, char *rmap_name)
718e3744 12092{
12093 struct bgp_table *table;
12094 struct bgp_adj_in *ain;
12095 struct bgp_adj_out *adj;
12096 unsigned long output_count;
0b16f239 12097 unsigned long filtered_count;
718e3744 12098 struct bgp_node *rn;
12099 int header1 = 1;
12100 struct bgp *bgp;
12101 int header2 = 1;
0b16f239
DS
12102 struct attr attr;
12103 struct attr_extra extra;
12104 int ret;
718e3744 12105
bb46e94f 12106 bgp = peer->bgp;
718e3744 12107
12108 if (! bgp)
12109 return;
12110
12111 table = bgp->rib[afi][safi];
12112
0b16f239 12113 output_count = filtered_count = 0;
47fc97cc 12114
718e3744 12115 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
12116 PEER_STATUS_DEFAULT_ORIGINATE))
12117 {
3f9c7369 12118 vty_out (vty, "BGP table version is %llu, local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
93406d87 12119 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12120 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 12121
12122 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12123 VTY_NEWLINE, VTY_NEWLINE);
12124 header1 = 0;
12125 }
12126
0b16f239 12127 attr.extra = &extra;
718e3744 12128 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12129 if (in)
12130 {
12131 for (ain = rn->adj_in; ain; ain = ain->next)
12132 if (ain->peer == peer)
12133 {
12134 if (header1)
12135 {
12136 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
93406d87 12137 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12138 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 12139 header1 = 0;
12140 }
12141 if (header2)
12142 {
b05a1c8b 12143 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
718e3744 12144 header2 = 0;
12145 }
12146 if (ain->attr)
47fc97cc 12147 {
0b16f239
DS
12148 bgp_attr_dup(&attr, ain->attr);
12149 if (bgp_input_modifier(peer, &rn->p, &attr, afi,
12150 safi, rmap_name) != RMAP_DENY)
12151 {
b05a1c8b 12152 route_vty_out_tmp (vty, &rn->p, &attr, safi);
0b16f239
DS
12153 output_count++;
12154 }
12155 else
12156 filtered_count++;
718e3744 12157 }
12158 }
12159 }
12160 else
12161 {
3f9c7369
DS
12162 adj = bgp_adj_peer_lookup(peer, rn);
12163 if (adj)
12164 {
12165 if (header1)
12166 {
12167 vty_out (vty, "BGP table version is %llu, local router ID "
12168 "is %s%s", table->version,
12169 inet_ntoa (bgp->router_id), VTY_NEWLINE);
12170 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12171 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12172 header1 = 0;
12173 }
12174 if (header2)
12175 {
b05a1c8b 12176 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
3f9c7369
DS
12177 header2 = 0;
12178 }
12179 if (adj->attr)
12180 {
12181 if (!CHECK_FLAG(peer->af_flags[afi][safi],
12182 PEER_FLAG_REFLECTOR_CLIENT)
12183 || bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
12184 {
12185 bgp_attr_dup(&attr, adj->attr);
12186 ret = bgp_output_modifier(peer, &rn->p, &attr, afi,
12187 safi, rmap_name);
12188 }
12189 else
12190 ret = RMAP_PERMIT;
0b16f239 12191
3f9c7369
DS
12192 if (ret != RMAP_DENY)
12193 {
b05a1c8b 12194 route_vty_out_tmp (vty, &rn->p, &attr, safi);
3f9c7369
DS
12195 output_count++;
12196 }
12197 else
12198 filtered_count++;
12199 }
12200 }
718e3744 12201 }
47fc97cc 12202
718e3744 12203 if (output_count != 0)
12204 vty_out (vty, "%sTotal number of prefixes %ld%s",
12205 VTY_NEWLINE, output_count, VTY_NEWLINE);
12206}
12207
94f2b392 12208static int
47fc97cc 12209peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
b05a1c8b 12210 int in, char *rmap_name)
bb46e94f 12211{
718e3744 12212 if (! peer || ! peer->afc[afi][safi])
12213 {
12214 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12215 return CMD_WARNING;
12216 }
12217
12218 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12219 {
12220 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
12221 VTY_NEWLINE);
12222 return CMD_WARNING;
12223 }
12224
0b16f239
DS
12225 if (!in && (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)
12226 && !bgp_flag_check(peer->bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)))
12227 {
12228 vty_out (vty, "%% Cannot apply outgoing route-map on route-reflector clients%s",
12229 VTY_NEWLINE);
12230 vty_out (vty, "%% Enable bgp route-reflector allow-outbound-policy flag%s",
12231 VTY_NEWLINE);
12232 return CMD_WARNING;
12233 }
12234
b05a1c8b 12235 show_adj_route (vty, peer, afi, safi, in, rmap_name);
718e3744 12236
12237 return CMD_SUCCESS;
12238}
12239
2a71e9ce
TP
12240DEFUN (show_ip_bgp_view_neighbor_advertised_route,
12241 show_ip_bgp_view_neighbor_advertised_route_cmd,
a80beece 12242 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 12243 SHOW_STR
12244 IP_STR
12245 BGP_STR
2a71e9ce
TP
12246 "BGP view\n"
12247 "View name\n"
718e3744 12248 "Detailed information on TCP and BGP neighbor connections\n"
12249 "Neighbor to display information about\n"
12250 "Neighbor to display information about\n"
12251 "Display the routes advertised to a BGP neighbor\n")
12252{
bb46e94f 12253 struct peer *peer;
12254
2a71e9ce
TP
12255 if (argc == 2)
12256 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12257 else
12258 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12259
bb46e94f 12260 if (! peer)
12261 return CMD_WARNING;
0b16f239 12262
b05a1c8b 12263 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL);
718e3744 12264}
12265
0b16f239 12266DEFUN (show_ip_bgp_neighbor_advertised_route,
2a71e9ce 12267 show_ip_bgp_neighbor_advertised_route_cmd,
a80beece 12268 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
2a71e9ce
TP
12269 SHOW_STR
12270 IP_STR
12271 BGP_STR
12272 "Detailed information on TCP and BGP neighbor connections\n"
12273 "Neighbor to display information about\n"
12274 "Neighbor to display information about\n"
a80beece 12275 "Neighbor on bgp configured interface\n"
2a71e9ce
TP
12276 "Display the routes advertised to a BGP neighbor\n")
12277
0b16f239
DS
12278{
12279 struct peer *peer;
12280 char *rmap_name = NULL;
12281
12282 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12283
12284 if (! peer)
12285 return CMD_WARNING;
12286
12287 if (argc == 2)
12288 rmap_name = argv[1];
12289
b05a1c8b 12290 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name);
0b16f239
DS
12291}
12292
12293ALIAS (show_ip_bgp_neighbor_advertised_route,
12294 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
12295 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
12296 SHOW_STR
12297 IP_STR
12298 BGP_STR
12299 "Detailed information on TCP and BGP neighbor connections\n"
12300 "Neighbor to display information about\n"
12301 "Neighbor to display information about\n"
12302 "Neighbor on bgp configured interface\n"
12303 "Display the routes advertised to a BGP neighbor\n")
12304
718e3744 12305DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12306 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
a80beece 12307 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 12308 SHOW_STR
12309 IP_STR
12310 BGP_STR
12311 "Address family\n"
12312 "Address Family modifier\n"
12313 "Address Family modifier\n"
12314 "Detailed information on TCP and BGP neighbor connections\n"
12315 "Neighbor to display information about\n"
12316 "Neighbor to display information about\n"
a80beece 12317 "Neighbor on bgp configured interface\n"
718e3744 12318 "Display the routes advertised to a BGP neighbor\n")
12319{
bb46e94f 12320 struct peer *peer;
0b16f239 12321 char *rmap_name = NULL;
bb46e94f 12322
12323 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12324 if (! peer)
12325 return CMD_WARNING;
12326
0b16f239
DS
12327 if (argc == 3)
12328 rmap_name = argv[2];
12329
718e3744 12330 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 12331 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name);
718e3744 12332
b05a1c8b 12333 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name);
718e3744 12334}
12335
0b16f239
DS
12336ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
12337 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
12338 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
12339 SHOW_STR
12340 IP_STR
12341 BGP_STR
12342 "Address family\n"
12343 "Address Family modifier\n"
12344 "Address Family modifier\n"
12345 "Detailed information on TCP and BGP neighbor connections\n"
12346 "Neighbor to display information about\n"
12347 "Neighbor to display information about\n"
12348 "Neighbor on bgp configured interface\n"
12349 "Display the routes advertised to a BGP neighbor\n"
12350 "Route-map to control what is displayed\n")
12351
718e3744 12352#ifdef HAVE_IPV6
bb46e94f 12353DEFUN (show_bgp_view_neighbor_advertised_route,
12354 show_bgp_view_neighbor_advertised_route_cmd,
a80beece 12355 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 12356 SHOW_STR
12357 BGP_STR
bb46e94f 12358 "BGP view\n"
12359 "View name\n"
718e3744 12360 "Detailed information on TCP and BGP neighbor connections\n"
12361 "Neighbor to display information about\n"
12362 "Neighbor to display information about\n"
a80beece 12363 "Neighbor on bgp configured interface\n"
718e3744 12364 "Display the routes advertised to a BGP neighbor\n")
12365{
bb46e94f 12366 struct peer *peer;
12367
12368 if (argc == 2)
12369 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12370 else
12371 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12372
12373 if (! peer)
0b16f239 12374 return CMD_WARNING;
bb46e94f 12375
b05a1c8b 12376 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL);
47fc97cc
DS
12377}
12378
0b16f239
DS
12379ALIAS (show_bgp_view_neighbor_advertised_route,
12380 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
12381 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
12382 SHOW_STR
12383 BGP_STR
12384 "BGP view\n"
12385 "View name\n"
12386 "Address family\n"
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"
12391 "Display the routes advertised to a BGP neighbor\n")
12392
0b16f239
DS
12393DEFUN (show_bgp_neighbor_advertised_route,
12394 show_bgp_neighbor_advertised_route_cmd,
12395 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
bb46e94f 12396 SHOW_STR
12397 BGP_STR
bb46e94f 12398 "Detailed information on TCP and BGP neighbor connections\n"
12399 "Neighbor to display information about\n"
12400 "Neighbor to display information about\n"
a80beece 12401 "Neighbor on bgp configured interface\n"
0b16f239
DS
12402 "Display the routes advertised to a BGP neighbor\n")
12403
bb46e94f 12404{
12405 struct peer *peer;
0b16f239 12406 char *rmap_name = NULL;
bb46e94f 12407
0b16f239 12408 peer = peer_lookup_in_view (vty, NULL, argv[0]);
bb46e94f 12409
12410 if (! peer)
12411 return CMD_WARNING;
12412
0b16f239
DS
12413 if (argc == 2)
12414 rmap_name = argv[1];
12415
b05a1c8b 12416 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name);
718e3744 12417}
12418
0b16f239
DS
12419ALIAS (show_bgp_neighbor_advertised_route,
12420 show_bgp_neighbor_advertised_route_rmap_cmd,
12421 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
bb46e94f 12422 SHOW_STR
12423 BGP_STR
bb46e94f 12424 "Detailed information on TCP and BGP neighbor connections\n"
12425 "Neighbor to display information about\n"
12426 "Neighbor to display information about\n"
a80beece 12427 "Neighbor on bgp configured interface\n"
0b16f239 12428 "Display the routes advertised to a BGP neighbor\n")
bb46e94f 12429
0b16f239
DS
12430ALIAS (show_bgp_neighbor_advertised_route,
12431 show_bgp_ipv6_neighbor_advertised_route_cmd,
12432 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
bb46e94f 12433 SHOW_STR
12434 BGP_STR
0b16f239 12435 "Address family\n"
bb46e94f 12436 "Detailed information on TCP and BGP neighbor connections\n"
12437 "Neighbor to display information about\n"
12438 "Neighbor to display information about\n"
a80beece 12439 "Neighbor on bgp configured interface\n"
bb46e94f 12440 "Display the routes advertised to a BGP neighbor\n")
0b16f239
DS
12441
12442ALIAS (show_bgp_neighbor_advertised_route,
12443 show_bgp_ipv6_neighbor_advertised_route_rmap_cmd,
12444 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
718e3744 12445 SHOW_STR
12446 BGP_STR
12447 "Address family\n"
12448 "Detailed information on TCP and BGP neighbor connections\n"
12449 "Neighbor to display information about\n"
12450 "Neighbor to display information about\n"
a80beece 12451 "Neighbor on bgp configured interface\n"
718e3744 12452 "Display the routes advertised to a BGP neighbor\n")
12453
12454/* old command */
0b16f239 12455ALIAS (show_bgp_neighbor_advertised_route,
718e3744 12456 ipv6_bgp_neighbor_advertised_route_cmd,
a80beece 12457 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 12458 SHOW_STR
12459 IPV6_STR
12460 BGP_STR
12461 "Detailed information on TCP and BGP neighbor connections\n"
12462 "Neighbor to display information about\n"
12463 "Neighbor to display information about\n"
a80beece 12464 "Neighbor on bgp configured interface\n"
718e3744 12465 "Display the routes advertised to a BGP neighbor\n")
bb46e94f 12466
718e3744 12467/* old command */
12468DEFUN (ipv6_mbgp_neighbor_advertised_route,
12469 ipv6_mbgp_neighbor_advertised_route_cmd,
a80beece 12470 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 12471 SHOW_STR
12472 IPV6_STR
12473 MBGP_STR
12474 "Detailed information on TCP and BGP neighbor connections\n"
12475 "Neighbor to display information about\n"
12476 "Neighbor to display information about\n"
a80beece
DS
12477 "Neighbor on bgp configured interface\n"
12478 "Neighbor on bgp configured interface\n"
718e3744 12479 "Display the routes advertised to a BGP neighbor\n")
12480{
bb46e94f 12481 struct peer *peer;
12482
12483 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12484 if (! peer)
12485 return CMD_WARNING;
12486
b05a1c8b 12487 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL);
718e3744 12488}
12489#endif /* HAVE_IPV6 */
6b0655a2 12490
0b16f239
DS
12491DEFUN (show_bgp_view_neighbor_received_routes,
12492 show_bgp_view_neighbor_received_routes_cmd,
12493 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
12494 SHOW_STR
12495 BGP_STR
12496 "BGP view\n"
12497 "View name\n"
12498 "Detailed information on TCP and BGP neighbor connections\n"
12499 "Neighbor to display information about\n"
12500 "Neighbor to display information about\n"
12501 "Neighbor on bgp configured interface\n"
12502 "Display the received routes from neighbor\n")
12503{
12504 struct peer *peer;
12505
12506 if (argc == 2)
12507 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12508 else
12509 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12510
12511 if (! peer)
12512 return CMD_WARNING;
12513
b05a1c8b 12514 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL);
0b16f239
DS
12515}
12516
2a71e9ce
TP
12517DEFUN (show_ip_bgp_view_neighbor_received_routes,
12518 show_ip_bgp_view_neighbor_received_routes_cmd,
a80beece 12519 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12520 SHOW_STR
12521 IP_STR
12522 BGP_STR
2a71e9ce
TP
12523 "BGP view\n"
12524 "View name\n"
718e3744 12525 "Detailed information on TCP and BGP neighbor connections\n"
12526 "Neighbor to display information about\n"
12527 "Neighbor to display information about\n"
a80beece 12528 "Neighbor on bgp configured interface\n"
718e3744 12529 "Display the received routes from neighbor\n")
12530{
bb46e94f 12531 struct peer *peer;
12532
2a71e9ce
TP
12533 if (argc == 2)
12534 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12535 else
12536 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12537
bb46e94f 12538 if (! peer)
12539 return CMD_WARNING;
12540
b05a1c8b 12541 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL);
718e3744 12542}
12543
0b16f239
DS
12544ALIAS (show_bgp_view_neighbor_received_routes,
12545 show_bgp_view_ipv6_neighbor_received_routes_cmd,
12546 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
12547 SHOW_STR
12548 BGP_STR
12549 "BGP view\n"
12550 "View name\n"
12551 "Address family\n"
12552 "Detailed information on TCP and BGP neighbor connections\n"
12553 "Neighbor to display information about\n"
12554 "Neighbor to display information about\n"
12555 "Neighbor on bgp configured interface\n"
12556 "Display the received routes from neighbor\n")
12557
12558DEFUN (show_ip_bgp_neighbor_received_routes,
2a71e9ce 12559 show_ip_bgp_neighbor_received_routes_cmd,
a80beece 12560 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
2a71e9ce
TP
12561 SHOW_STR
12562 IP_STR
12563 BGP_STR
12564 "Detailed information on TCP and BGP neighbor connections\n"
12565 "Neighbor to display information about\n"
12566 "Neighbor to display information about\n"
a80beece 12567 "Neighbor on bgp configured interface\n"
2a71e9ce
TP
12568 "Display the received routes from neighbor\n")
12569
0b16f239
DS
12570{
12571 struct peer *peer;
12572 char *rmap_name = NULL;
12573
12574 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12575
12576 if (! peer)
12577 return CMD_WARNING;
12578
12579 if (argc == 2)
12580 rmap_name = argv[1];
12581
b05a1c8b 12582 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name);
0b16f239
DS
12583}
12584
12585ALIAS (show_ip_bgp_neighbor_received_routes,
12586 show_ip_bgp_neighbor_received_routes_rmap_cmd,
12587 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
12588 SHOW_STR
12589 IP_STR
12590 BGP_STR
12591 "Detailed information on TCP and BGP neighbor connections\n"
12592 "Neighbor to display information about\n"
12593 "Neighbor to display information about\n"
12594 "Neighbor on bgp configured interface\n"
12595 "Display the received routes from neighbor\n")
12596
718e3744 12597DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12598 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
a80beece 12599 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12600 SHOW_STR
12601 IP_STR
12602 BGP_STR
12603 "Address family\n"
12604 "Address Family modifier\n"
12605 "Address Family modifier\n"
12606 "Detailed information on TCP and BGP neighbor connections\n"
12607 "Neighbor to display information about\n"
12608 "Neighbor to display information about\n"
a80beece 12609 "Neighbor on bgp configured interface\n"
718e3744 12610 "Display the received routes from neighbor\n")
12611{
bb46e94f 12612 struct peer *peer;
0b16f239 12613 char *rmap_name = NULL;
bb46e94f 12614
12615 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12616 if (! peer)
12617 return CMD_WARNING;
0b16f239
DS
12618
12619 if (argc == 3)
12620 rmap_name = argv[2];
12621
718e3744 12622 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 12623 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name);
718e3744 12624
b05a1c8b 12625 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name);
718e3744 12626}
12627
0b16f239
DS
12628ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
12629 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
12630 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
12631 SHOW_STR
12632 IP_STR
12633 BGP_STR
12634 "Address family\n"
12635 "Address Family modifier\n"
12636 "Address Family modifier\n"
12637 "Detailed information on TCP and BGP neighbor connections\n"
12638 "Neighbor to display information about\n"
12639 "Neighbor to display information about\n"
12640 "Neighbor on bgp configured interface\n"
12641 "Display the received routes from neighbor\n")
12642
95cbbd2a
ML
12643DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
12644 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
12645#ifdef HAVE_IPV6
a80beece 12646 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes)",
95cbbd2a 12647#else
a80beece 12648 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes)",
95cbbd2a
ML
12649#endif
12650 SHOW_STR
12651 BGP_STR
12652 "BGP view\n"
2b00515a 12653 "View name\n"
95cbbd2a
ML
12654 "Address family\n"
12655#ifdef HAVE_IPV6
12656 "Address family\n"
12657#endif
12658 "Address family modifier\n"
12659 "Address family modifier\n"
12660 "Detailed information on TCP and BGP neighbor connections\n"
12661 "Neighbor to display information about\n"
12662 "Neighbor to display information about\n"
a80beece 12663 "Neighbor on bgp configured interface\n"
95cbbd2a
ML
12664 "Display the advertised routes to neighbor\n"
12665 "Display the received routes from neighbor\n")
12666{
12667 int afi;
12668 int safi;
12669 int in;
12670 struct peer *peer;
12671
12672#ifdef HAVE_IPV6
12673 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
12674#else
12675 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12676#endif
12677
12678 if (! peer)
12679 return CMD_WARNING;
12680
12681#ifdef HAVE_IPV6
12682 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
12683 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12684 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
12685#else
12686 afi = AFI_IP;
12687 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12688 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
12689#endif
12690
b05a1c8b 12691 return peer_adj_routes (vty, peer, afi, safi, in, NULL);
95cbbd2a
ML
12692}
12693
718e3744 12694DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12695 show_ip_bgp_neighbor_received_prefix_filter_cmd,
a80beece 12696 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
718e3744 12697 SHOW_STR
12698 IP_STR
12699 BGP_STR
12700 "Detailed information on TCP and BGP neighbor connections\n"
12701 "Neighbor to display information about\n"
12702 "Neighbor to display information about\n"
a80beece 12703 "Neighbor on bgp configured interface\n"
718e3744 12704 "Display information received from a BGP neighbor\n"
12705 "Display the prefixlist filter\n")
12706{
12707 char name[BUFSIZ];
c63b83fe 12708 union sockunion su;
718e3744 12709 struct peer *peer;
c63b83fe 12710 int count, ret;
718e3744 12711
c63b83fe
JBD
12712 ret = str2sockunion (argv[0], &su);
12713 if (ret < 0)
12714 {
a80beece
DS
12715 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12716 if (!peer)
12717 {
12718 vty_out (vty, "Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12719 return CMD_WARNING;
12720 }
12721 }
12722 else
12723 {
12724 peer = peer_lookup (NULL, &su);
12725 if (! peer)
12726 return CMD_WARNING;
c63b83fe 12727 }
718e3744 12728
12729 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12730 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
12731 if (count)
12732 {
12733 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
12734 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
12735 }
12736
12737 return CMD_SUCCESS;
12738}
12739
12740DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
12741 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
a80beece 12742 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
718e3744 12743 SHOW_STR
12744 IP_STR
12745 BGP_STR
12746 "Address family\n"
12747 "Address Family modifier\n"
12748 "Address Family modifier\n"
12749 "Detailed information on TCP and BGP neighbor connections\n"
12750 "Neighbor to display information about\n"
12751 "Neighbor to display information about\n"
a80beece 12752 "Neighbor on bgp configured interface\n"
718e3744 12753 "Display information received from a BGP neighbor\n"
12754 "Display the prefixlist filter\n")
12755{
12756 char name[BUFSIZ];
c63b83fe 12757 union sockunion su;
718e3744 12758 struct peer *peer;
c63b83fe 12759 int count, ret;
718e3744 12760
c63b83fe
JBD
12761 ret = str2sockunion (argv[1], &su);
12762 if (ret < 0)
12763 {
a80beece
DS
12764 peer = peer_lookup_by_conf_if (NULL, argv[1]);
12765 if (!peer)
12766 {
12767 vty_out (vty, "Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
12768 return CMD_WARNING;
12769 }
12770 }
12771 else
12772 {
12773 peer = peer_lookup (NULL, &su);
12774 if (! peer)
12775 return CMD_WARNING;
c63b83fe 12776 }
718e3744 12777
12778 if (strncmp (argv[0], "m", 1) == 0)
12779 {
12780 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
12781 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
12782 if (count)
12783 {
12784 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
12785 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
12786 }
12787 }
12788 else
12789 {
12790 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12791 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
12792 if (count)
12793 {
12794 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
12795 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
12796 }
12797 }
12798
12799 return CMD_SUCCESS;
12800}
12801
12802
12803#ifdef HAVE_IPV6
bb46e94f 12804ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 12805 show_bgp_neighbor_received_routes_cmd,
a80beece 12806 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12807 SHOW_STR
12808 BGP_STR
12809 "Detailed information on TCP and BGP neighbor connections\n"
12810 "Neighbor to display information about\n"
12811 "Neighbor to display information about\n"
a80beece 12812 "Neighbor on bgp configured interface\n"
718e3744 12813 "Display the received routes from neighbor\n")
718e3744 12814
bb46e94f 12815ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 12816 show_bgp_ipv6_neighbor_received_routes_cmd,
a80beece 12817 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12818 SHOW_STR
12819 BGP_STR
12820 "Address family\n"
12821 "Detailed information on TCP and BGP neighbor connections\n"
12822 "Neighbor to display information about\n"
12823 "Neighbor to display information about\n"
a80beece 12824 "Neighbor on bgp configured interface\n"
718e3744 12825 "Display the received routes from neighbor\n")
12826
0b16f239
DS
12827ALIAS (show_bgp_view_neighbor_received_routes,
12828 show_bgp_neighbor_received_routes_rmap_cmd,
12829 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
12830 SHOW_STR
12831 BGP_STR
12832 "Detailed information on TCP and BGP neighbor connections\n"
12833 "Neighbor to display information about\n"
12834 "Neighbor to display information about\n"
12835 "Neighbor on bgp configured interface\n"
12836 "Display the received routes from neighbor\n")
12837
12838ALIAS (show_bgp_view_neighbor_received_routes,
12839 show_bgp_ipv6_neighbor_received_routes_rmap_cmd,
12840 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
12841 SHOW_STR
12842 BGP_STR
12843 "Address family\n"
12844 "Detailed information on TCP and BGP neighbor connections\n"
12845 "Neighbor to display information about\n"
12846 "Neighbor to display information about\n"
12847 "Neighbor on bgp configured interface\n"
12848 "Display the received routes from neighbor\n")
12849
718e3744 12850DEFUN (show_bgp_neighbor_received_prefix_filter,
12851 show_bgp_neighbor_received_prefix_filter_cmd,
a80beece 12852 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
718e3744 12853 SHOW_STR
12854 BGP_STR
12855 "Detailed information on TCP and BGP neighbor connections\n"
12856 "Neighbor to display information about\n"
12857 "Neighbor to display information about\n"
a80beece 12858 "Neighbor on bgp configured interface\n"
718e3744 12859 "Display information received from a BGP neighbor\n"
12860 "Display the prefixlist filter\n")
12861{
12862 char name[BUFSIZ];
c63b83fe 12863 union sockunion su;
718e3744 12864 struct peer *peer;
c63b83fe 12865 int count, ret;
718e3744 12866
c63b83fe
JBD
12867 ret = str2sockunion (argv[0], &su);
12868 if (ret < 0)
12869 {
a80beece
DS
12870 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12871 if (!peer)
12872 {
12873 vty_out (vty, "Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12874 return CMD_WARNING;
12875 }
12876 }
12877 else
12878 {
12879 peer = peer_lookup (NULL, &su);
12880 if (! peer)
12881 return CMD_WARNING;
c63b83fe 12882 }
718e3744 12883
12884 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12885 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12886 if (count)
12887 {
12888 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12889 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12890 }
12891
12892 return CMD_SUCCESS;
12893}
12894
12895ALIAS (show_bgp_neighbor_received_prefix_filter,
12896 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
a80beece 12897 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
718e3744 12898 SHOW_STR
12899 BGP_STR
12900 "Address family\n"
12901 "Detailed information on TCP and BGP neighbor connections\n"
12902 "Neighbor to display information about\n"
12903 "Neighbor to display information about\n"
a80beece 12904 "Neighbor on bgp configured interface\n"
718e3744 12905 "Display information received from a BGP neighbor\n"
12906 "Display the prefixlist filter\n")
12907
12908/* old command */
bb46e94f 12909ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 12910 ipv6_bgp_neighbor_received_routes_cmd,
a80beece 12911 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12912 SHOW_STR
12913 IPV6_STR
12914 BGP_STR
12915 "Detailed information on TCP and BGP neighbor connections\n"
12916 "Neighbor to display information about\n"
12917 "Neighbor to display information about\n"
a80beece 12918 "Neighbor on bgp configured interface\n"
718e3744 12919 "Display the received routes from neighbor\n")
718e3744 12920
12921/* old command */
12922DEFUN (ipv6_mbgp_neighbor_received_routes,
12923 ipv6_mbgp_neighbor_received_routes_cmd,
a80beece 12924 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12925 SHOW_STR
12926 IPV6_STR
12927 MBGP_STR
12928 "Detailed information on TCP and BGP neighbor connections\n"
12929 "Neighbor to display information about\n"
12930 "Neighbor to display information about\n"
a80beece 12931 "Neighbor on bgp configured interface\n"
718e3744 12932 "Display the received routes from neighbor\n")
12933{
bb46e94f 12934 struct peer *peer;
12935
12936 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12937 if (! peer)
12938 return CMD_WARNING;
12939
b05a1c8b 12940 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL);
bb46e94f 12941}
12942
12943DEFUN (show_bgp_view_neighbor_received_prefix_filter,
12944 show_bgp_view_neighbor_received_prefix_filter_cmd,
a80beece 12945 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
bb46e94f 12946 SHOW_STR
12947 BGP_STR
12948 "BGP view\n"
12949 "View name\n"
12950 "Detailed information on TCP and BGP neighbor connections\n"
12951 "Neighbor to display information about\n"
12952 "Neighbor to display information about\n"
a80beece 12953 "Neighbor on bgp configured interface\n"
bb46e94f 12954 "Display information received from a BGP neighbor\n"
12955 "Display the prefixlist filter\n")
12956{
12957 char name[BUFSIZ];
c63b83fe 12958 union sockunion su;
bb46e94f 12959 struct peer *peer;
12960 struct bgp *bgp;
c63b83fe 12961 int count, ret;
bb46e94f 12962
12963 /* BGP structure lookup. */
12964 bgp = bgp_lookup_by_name (argv[0]);
12965 if (bgp == NULL)
12966 {
12967 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12968 return CMD_WARNING;
12969 }
12970
c63b83fe
JBD
12971 ret = str2sockunion (argv[1], &su);
12972 if (ret < 0)
12973 {
a80beece
DS
12974 peer = peer_lookup_by_conf_if (bgp, argv[1]);
12975 if (!peer)
12976 {
12977 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
12978 return CMD_WARNING;
12979 }
12980 }
12981 else
12982 {
12983 peer = peer_lookup (bgp, &su);
12984 if (! peer)
12985 return CMD_WARNING;
c63b83fe 12986 }
bb46e94f 12987
12988 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12989 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12990 if (count)
12991 {
12992 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12993 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12994 }
12995
12996 return CMD_SUCCESS;
718e3744 12997}
bb46e94f 12998
12999ALIAS (show_bgp_view_neighbor_received_prefix_filter,
13000 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
a80beece 13001 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
bb46e94f 13002 SHOW_STR
13003 BGP_STR
13004 "BGP view\n"
13005 "View name\n"
13006 "Address family\n"
13007 "Detailed information on TCP and BGP neighbor connections\n"
13008 "Neighbor to display information about\n"
13009 "Neighbor to display information about\n"
a80beece 13010 "Neighbor on bgp configured interface\n"
bb46e94f 13011 "Display information received from a BGP neighbor\n"
13012 "Display the prefixlist filter\n")
718e3744 13013#endif /* HAVE_IPV6 */
6b0655a2 13014
94f2b392 13015static int
bb46e94f 13016bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
b05a1c8b 13017 safi_t safi, enum bgp_show_type type)
718e3744 13018{
718e3744 13019 if (! peer || ! peer->afc[afi][safi])
13020 {
13021 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
718e3744 13022 return CMD_WARNING;
13023 }
47fc97cc 13024
b05a1c8b 13025 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, 0);
718e3744 13026}
13027
13028DEFUN (show_ip_bgp_neighbor_routes,
13029 show_ip_bgp_neighbor_routes_cmd,
a80beece 13030 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 13031 SHOW_STR
13032 IP_STR
13033 BGP_STR
13034 "Detailed information on TCP and BGP neighbor connections\n"
13035 "Neighbor to display information about\n"
13036 "Neighbor to display information about\n"
a80beece 13037 "Neighbor on bgp configured interface\n"
718e3744 13038 "Display routes learned from neighbor\n")
13039{
bb46e94f 13040 struct peer *peer;
13041
13042 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13043 if (! peer)
13044 return CMD_WARNING;
13045
13046 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
b05a1c8b 13047 bgp_show_type_neighbor);
718e3744 13048}
13049
13050DEFUN (show_ip_bgp_neighbor_flap,
13051 show_ip_bgp_neighbor_flap_cmd,
a80beece 13052 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
718e3744 13053 SHOW_STR
13054 IP_STR
13055 BGP_STR
13056 "Detailed information on TCP and BGP neighbor connections\n"
13057 "Neighbor to display information about\n"
13058 "Neighbor to display information about\n"
a80beece 13059 "Neighbor on bgp configured interface\n"
718e3744 13060 "Display flap statistics of the routes learned from neighbor\n")
13061{
bb46e94f 13062 struct peer *peer;
13063
13064 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13065 if (! peer)
13066 return CMD_WARNING;
13067
13068 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
b05a1c8b 13069 bgp_show_type_flap_neighbor);
718e3744 13070}
13071
13072DEFUN (show_ip_bgp_neighbor_damp,
13073 show_ip_bgp_neighbor_damp_cmd,
a80beece 13074 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
718e3744 13075 SHOW_STR
13076 IP_STR
13077 BGP_STR
13078 "Detailed information on TCP and BGP neighbor connections\n"
13079 "Neighbor to display information about\n"
13080 "Neighbor to display information about\n"
a80beece 13081 "Neighbor on bgp configured interface\n"
718e3744 13082 "Display the dampened routes received from neighbor\n")
13083{
bb46e94f 13084 struct peer *peer;
13085
13086 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13087 if (! peer)
13088 return CMD_WARNING;
13089
13090 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
b05a1c8b 13091 bgp_show_type_damp_neighbor);
718e3744 13092}
13093
13094DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13095 show_ip_bgp_ipv4_neighbor_routes_cmd,
a80beece 13096 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 13097 SHOW_STR
13098 IP_STR
13099 BGP_STR
13100 "Address family\n"
13101 "Address Family modifier\n"
13102 "Address Family modifier\n"
13103 "Detailed information on TCP and BGP neighbor connections\n"
13104 "Neighbor to display information about\n"
13105 "Neighbor to display information about\n"
a80beece 13106 "Neighbor on bgp configured interface\n"
718e3744 13107 "Display routes learned from neighbor\n")
13108{
bb46e94f 13109 struct peer *peer;
13110
13111 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13112 if (! peer)
13113 return CMD_WARNING;
13114
718e3744 13115 if (strncmp (argv[0], "m", 1) == 0)
bb46e94f 13116 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
b05a1c8b 13117 bgp_show_type_neighbor);
718e3744 13118
bb46e94f 13119 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
b05a1c8b 13120 bgp_show_type_neighbor);
718e3744 13121}
bb46e94f 13122
fee0f4c6 13123DEFUN (show_ip_bgp_view_rsclient,
13124 show_ip_bgp_view_rsclient_cmd,
a80beece 13125 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 13126 SHOW_STR
13127 IP_STR
13128 BGP_STR
13129 "BGP view\n"
2b00515a 13130 "View name\n"
fee0f4c6 13131 "Information about Route Server Client\n"
a80beece 13132 NEIGHBOR_ADDR_STR3)
fee0f4c6 13133{
13134 struct bgp_table *table;
13135 struct peer *peer;
13136
13137 if (argc == 2)
13138 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13139 else
13140 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13141
13142 if (! peer)
13143 return CMD_WARNING;
13144
13145 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13146 {
13147 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13148 VTY_NEWLINE);
13149 return CMD_WARNING;
13150 }
13151
13152 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13153 PEER_FLAG_RSERVER_CLIENT))
13154 {
13155 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13156 VTY_NEWLINE);
13157 return CMD_WARNING;
13158 }
13159
13160 table = peer->rib[AFI_IP][SAFI_UNICAST];
13161
47fc97cc 13162 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
b05a1c8b 13163 NULL, 0);
fee0f4c6 13164}
13165
13166ALIAS (show_ip_bgp_view_rsclient,
13167 show_ip_bgp_rsclient_cmd,
a80beece 13168 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 13169 SHOW_STR
13170 IP_STR
13171 BGP_STR
13172 "Information about Route Server Client\n"
a80beece 13173 NEIGHBOR_ADDR_STR3)
fee0f4c6 13174
95cbbd2a
ML
13175DEFUN (show_bgp_view_ipv4_safi_rsclient,
13176 show_bgp_view_ipv4_safi_rsclient_cmd,
a80beece 13177 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 13178 SHOW_STR
fee0f4c6 13179 BGP_STR
13180 "BGP view\n"
2b00515a 13181 "View name\n"
95cbbd2a
ML
13182 "Address family\n"
13183 "Address Family modifier\n"
13184 "Address Family modifier\n"
fee0f4c6 13185 "Information about Route Server Client\n"
a80beece 13186 NEIGHBOR_ADDR_STR3)
fee0f4c6 13187{
95cbbd2a 13188 struct bgp_table *table;
fee0f4c6 13189 struct peer *peer;
95cbbd2a 13190 safi_t safi;
fee0f4c6 13191
95cbbd2a
ML
13192 if (argc == 3) {
13193 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13194 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13195 } else {
13196 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13197 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13198 }
13199
13200 if (! peer)
13201 return CMD_WARNING;
13202
13203 if (! peer->afc[AFI_IP][safi])
fee0f4c6 13204 {
95cbbd2a
ML
13205 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13206 VTY_NEWLINE);
13207 return CMD_WARNING;
13208 }
13209
13210 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13211 PEER_FLAG_RSERVER_CLIENT))
13212 {
13213 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13214 VTY_NEWLINE);
13215 return CMD_WARNING;
13216 }
13217
13218 table = peer->rib[AFI_IP][safi];
13219
47fc97cc 13220 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
b05a1c8b 13221 NULL, 0);
95cbbd2a
ML
13222}
13223
13224ALIAS (show_bgp_view_ipv4_safi_rsclient,
13225 show_bgp_ipv4_safi_rsclient_cmd,
a80beece 13226 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
95cbbd2a
ML
13227 SHOW_STR
13228 BGP_STR
13229 "Address family\n"
13230 "Address Family modifier\n"
13231 "Address Family modifier\n"
13232 "Information about Route Server Client\n"
a80beece 13233 NEIGHBOR_ADDR_STR3)
95cbbd2a
ML
13234
13235DEFUN (show_ip_bgp_view_rsclient_route,
13236 show_ip_bgp_view_rsclient_route_cmd,
a80beece 13237 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
95cbbd2a
ML
13238 SHOW_STR
13239 IP_STR
13240 BGP_STR
13241 "BGP view\n"
2b00515a 13242 "View name\n"
95cbbd2a 13243 "Information about Route Server Client\n"
a80beece 13244 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13245 "Network in the BGP routing table to display\n")
13246{
13247 struct bgp *bgp;
13248 struct peer *peer;
13249
13250 /* BGP structure lookup. */
13251 if (argc == 3)
13252 {
13253 bgp = bgp_lookup_by_name (argv[0]);
13254 if (bgp == NULL)
13255 {
13256 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13257 return CMD_WARNING;
fee0f4c6 13258 }
13259 }
13260 else
13261 {
13262 bgp = bgp_get_default ();
13263 if (bgp == NULL)
13264 {
13265 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13266 return CMD_WARNING;
13267 }
13268 }
13269
13270 if (argc == 3)
13271 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13272 else
13273 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13274
13275 if (! peer)
13276 return CMD_WARNING;
13277
13278 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13279 {
13280 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13281 VTY_NEWLINE);
13282 return CMD_WARNING;
b05a1c8b 13283 }
fee0f4c6 13284
13285 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13286 PEER_FLAG_RSERVER_CLIENT))
13287 {
13288 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13289 VTY_NEWLINE);
13290 return CMD_WARNING;
13291 }
13292
13293 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13294 (argc == 3) ? argv[2] : argv[1],
b05a1c8b 13295 AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, 0);
fee0f4c6 13296}
13297
13298ALIAS (show_ip_bgp_view_rsclient_route,
13299 show_ip_bgp_rsclient_route_cmd,
a80beece 13300 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
fee0f4c6 13301 SHOW_STR
13302 IP_STR
13303 BGP_STR
13304 "Information about Route Server Client\n"
a80beece 13305 NEIGHBOR_ADDR_STR3
fee0f4c6 13306 "Network in the BGP routing table to display\n")
13307
95cbbd2a
ML
13308DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
13309 show_bgp_view_ipv4_safi_rsclient_route_cmd,
a80beece 13310 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
95cbbd2a
ML
13311 SHOW_STR
13312 BGP_STR
13313 "BGP view\n"
2b00515a 13314 "View name\n"
95cbbd2a
ML
13315 "Address family\n"
13316 "Address Family modifier\n"
13317 "Address Family modifier\n"
13318 "Information about Route Server Client\n"
a80beece 13319 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13320 "Network in the BGP routing table to display\n")
13321{
13322 struct bgp *bgp;
13323 struct peer *peer;
13324 safi_t safi;
13325
13326 /* BGP structure lookup. */
13327 if (argc == 4)
13328 {
13329 bgp = bgp_lookup_by_name (argv[0]);
13330 if (bgp == NULL)
13331 {
13332 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13333 return CMD_WARNING;
13334 }
13335 }
13336 else
13337 {
13338 bgp = bgp_get_default ();
13339 if (bgp == NULL)
13340 {
13341 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13342 return CMD_WARNING;
13343 }
13344 }
13345
13346 if (argc == 4) {
13347 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13348 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13349 } else {
13350 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13351 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13352 }
13353
13354 if (! peer)
13355 return CMD_WARNING;
13356
13357 if (! peer->afc[AFI_IP][safi])
13358 {
13359 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13360 VTY_NEWLINE);
13361 return CMD_WARNING;
13362}
13363
13364 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13365 PEER_FLAG_RSERVER_CLIENT))
13366 {
13367 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13368 VTY_NEWLINE);
13369 return CMD_WARNING;
13370 }
13371
13372 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
13373 (argc == 4) ? argv[3] : argv[2],
b05a1c8b 13374 AFI_IP, safi, NULL, 0, BGP_PATH_ALL, 0);
95cbbd2a
ML
13375}
13376
13377ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
13378 show_bgp_ipv4_safi_rsclient_route_cmd,
a80beece 13379 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
95cbbd2a
ML
13380 SHOW_STR
13381 BGP_STR
13382 "Address family\n"
13383 "Address Family modifier\n"
13384 "Address Family modifier\n"
13385 "Information about Route Server Client\n"
a80beece 13386 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13387 "Network in the BGP routing table to display\n")
13388
fee0f4c6 13389DEFUN (show_ip_bgp_view_rsclient_prefix,
13390 show_ip_bgp_view_rsclient_prefix_cmd,
a80beece 13391 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
fee0f4c6 13392 SHOW_STR
13393 IP_STR
13394 BGP_STR
13395 "BGP view\n"
2b00515a 13396 "View name\n"
fee0f4c6 13397 "Information about Route Server Client\n"
a80beece 13398 NEIGHBOR_ADDR_STR3
fee0f4c6 13399 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13400{
13401 struct bgp *bgp;
13402 struct peer *peer;
13403
13404 /* BGP structure lookup. */
13405 if (argc == 3)
13406 {
13407 bgp = bgp_lookup_by_name (argv[0]);
13408 if (bgp == NULL)
13409 {
13410 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13411 return CMD_WARNING;
13412 }
13413 }
13414 else
13415 {
13416 bgp = bgp_get_default ();
13417 if (bgp == NULL)
13418 {
13419 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13420 return CMD_WARNING;
13421 }
13422 }
13423
13424 if (argc == 3)
13425 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13426 else
13427 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13428
13429 if (! peer)
13430 return CMD_WARNING;
13431
13432 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13433 {
13434 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13435 VTY_NEWLINE);
13436 return CMD_WARNING;
13437}
13438
13439 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13440 PEER_FLAG_RSERVER_CLIENT))
13441{
13442 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13443 VTY_NEWLINE);
13444 return CMD_WARNING;
13445 }
13446
13447 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13448 (argc == 3) ? argv[2] : argv[1],
b05a1c8b 13449 AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, 0);
fee0f4c6 13450}
13451
13452ALIAS (show_ip_bgp_view_rsclient_prefix,
13453 show_ip_bgp_rsclient_prefix_cmd,
a80beece 13454 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
fee0f4c6 13455 SHOW_STR
13456 IP_STR
13457 BGP_STR
13458 "Information about Route Server Client\n"
a80beece 13459 NEIGHBOR_ADDR_STR3
fee0f4c6 13460 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13461
95cbbd2a
ML
13462DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
13463 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
a80beece 13464 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
95cbbd2a
ML
13465 SHOW_STR
13466 BGP_STR
13467 "BGP view\n"
2b00515a 13468 "View name\n"
95cbbd2a
ML
13469 "Address family\n"
13470 "Address Family modifier\n"
13471 "Address Family modifier\n"
13472 "Information about Route Server Client\n"
a80beece 13473 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13474 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13475{
13476 struct bgp *bgp;
13477 struct peer *peer;
13478 safi_t safi;
13479
13480 /* BGP structure lookup. */
13481 if (argc == 4)
13482 {
13483 bgp = bgp_lookup_by_name (argv[0]);
13484 if (bgp == NULL)
13485 {
13486 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13487 return CMD_WARNING;
13488 }
13489 }
13490 else
13491 {
13492 bgp = bgp_get_default ();
13493 if (bgp == NULL)
13494 {
13495 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13496 return CMD_WARNING;
13497 }
13498 }
13499
13500 if (argc == 4) {
13501 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13502 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13503 } else {
13504 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13505 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13506 }
13507
13508 if (! peer)
13509 return CMD_WARNING;
13510
13511 if (! peer->afc[AFI_IP][safi])
13512 {
13513 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13514 VTY_NEWLINE);
13515 return CMD_WARNING;
13516}
13517
13518 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13519 PEER_FLAG_RSERVER_CLIENT))
13520{
13521 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13522 VTY_NEWLINE);
13523 return CMD_WARNING;
13524 }
13525
13526 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
13527 (argc == 4) ? argv[3] : argv[2],
b05a1c8b 13528 AFI_IP, safi, NULL, 1, BGP_PATH_ALL, 0);
95cbbd2a
ML
13529}
13530
13531ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
13532 show_bgp_ipv4_safi_rsclient_prefix_cmd,
a80beece 13533 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
95cbbd2a
ML
13534 SHOW_STR
13535 BGP_STR
13536 "Address family\n"
13537 "Address Family modifier\n"
13538 "Address Family modifier\n"
13539 "Information about Route Server Client\n"
a80beece 13540 NEIGHBOR_ADDR_STR3
95cbbd2a 13541 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
fee0f4c6 13542
718e3744 13543#ifdef HAVE_IPV6
bb46e94f 13544DEFUN (show_bgp_view_neighbor_routes,
13545 show_bgp_view_neighbor_routes_cmd,
a80beece 13546 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 13547 SHOW_STR
13548 BGP_STR
bb46e94f 13549 "BGP view\n"
2b00515a 13550 "View name\n"
718e3744 13551 "Detailed information on TCP and BGP neighbor connections\n"
13552 "Neighbor to display information about\n"
13553 "Neighbor to display information about\n"
a80beece 13554 "Neighbor on bgp configured interface\n"
718e3744 13555 "Display routes learned from neighbor\n")
13556{
bb46e94f 13557 struct peer *peer;
13558
13559 if (argc == 2)
13560 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13561 else
13562 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13563
13564 if (! peer)
13565 return CMD_WARNING;
13566
13567 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
b05a1c8b 13568 bgp_show_type_neighbor);
718e3744 13569}
13570
bb46e94f 13571ALIAS (show_bgp_view_neighbor_routes,
13572 show_bgp_view_ipv6_neighbor_routes_cmd,
a80beece 13573 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes",
bb46e94f 13574 SHOW_STR
13575 BGP_STR
13576 "BGP view\n"
2b00515a 13577 "View name\n"
bb46e94f 13578 "Address family\n"
13579 "Detailed information on TCP and BGP neighbor connections\n"
13580 "Neighbor to display information about\n"
13581 "Neighbor to display information about\n"
a80beece 13582 "Neighbor on bgp configured interface\n"
bb46e94f 13583 "Display routes learned from neighbor\n")
13584
13585DEFUN (show_bgp_view_neighbor_damp,
13586 show_bgp_view_neighbor_damp_cmd,
a80beece 13587 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
bb46e94f 13588 SHOW_STR
13589 BGP_STR
13590 "BGP view\n"
2b00515a 13591 "View name\n"
bb46e94f 13592 "Detailed information on TCP and BGP neighbor connections\n"
13593 "Neighbor to display information about\n"
13594 "Neighbor to display information about\n"
a80beece 13595 "Neighbor on bgp configured interface\n"
bb46e94f 13596 "Display the dampened routes received from neighbor\n")
13597{
13598 struct peer *peer;
13599
13600 if (argc == 2)
13601 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13602 else
13603 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13604
13605 if (! peer)
13606 return CMD_WARNING;
13607
13608 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
b05a1c8b 13609 bgp_show_type_damp_neighbor);
bb46e94f 13610}
13611
13612ALIAS (show_bgp_view_neighbor_damp,
13613 show_bgp_view_ipv6_neighbor_damp_cmd,
a80beece 13614 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
bb46e94f 13615 SHOW_STR
13616 BGP_STR
13617 "BGP view\n"
2b00515a 13618 "View name\n"
bb46e94f 13619 "Address family\n"
13620 "Detailed information on TCP and BGP neighbor connections\n"
13621 "Neighbor to display information about\n"
13622 "Neighbor to display information about\n"
a80beece 13623 "Neighbor on bgp configured interface\n"
bb46e94f 13624 "Display the dampened routes received from neighbor\n")
13625
13626DEFUN (show_bgp_view_neighbor_flap,
13627 show_bgp_view_neighbor_flap_cmd,
a80beece 13628 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
bb46e94f 13629 SHOW_STR
13630 BGP_STR
13631 "BGP view\n"
2b00515a 13632 "View name\n"
bb46e94f 13633 "Detailed information on TCP and BGP neighbor connections\n"
13634 "Neighbor to display information about\n"
13635 "Neighbor to display information about\n"
a80beece 13636 "Neighbor on bgp configured interface\n"
bb46e94f 13637 "Display flap statistics of the routes learned from neighbor\n")
13638{
13639 struct peer *peer;
13640
13641 if (argc == 2)
13642 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13643 else
13644 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13645
13646 if (! peer)
13647 return CMD_WARNING;
13648
13649 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
b05a1c8b 13650 bgp_show_type_flap_neighbor);
bb46e94f 13651}
13652
13653ALIAS (show_bgp_view_neighbor_flap,
13654 show_bgp_view_ipv6_neighbor_flap_cmd,
a80beece 13655 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
bb46e94f 13656 SHOW_STR
13657 BGP_STR
13658 "BGP view\n"
2b00515a 13659 "View name\n"
bb46e94f 13660 "Address family\n"
13661 "Detailed information on TCP and BGP neighbor connections\n"
13662 "Neighbor to display information about\n"
13663 "Neighbor to display information about\n"
a80beece 13664 "Neighbor on bgp configured interface\n"
bb46e94f 13665 "Display flap statistics of the routes learned from neighbor\n")
13666
13667ALIAS (show_bgp_view_neighbor_routes,
13668 show_bgp_neighbor_routes_cmd,
a80beece 13669 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
bb46e94f 13670 SHOW_STR
13671 BGP_STR
13672 "Detailed information on TCP and BGP neighbor connections\n"
13673 "Neighbor to display information about\n"
13674 "Neighbor to display information about\n"
a80beece 13675 "Neighbor on bgp configured interface\n"
bb46e94f 13676 "Display routes learned from neighbor\n")
13677
13678
13679ALIAS (show_bgp_view_neighbor_routes,
718e3744 13680 show_bgp_ipv6_neighbor_routes_cmd,
a80beece 13681 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 13682 SHOW_STR
13683 BGP_STR
13684 "Address family\n"
13685 "Detailed information on TCP and BGP neighbor connections\n"
13686 "Neighbor to display information about\n"
13687 "Neighbor to display information about\n"
a80beece 13688 "Neighbor on bgp configured interface\n"
718e3744 13689 "Display routes learned from neighbor\n")
13690
13691/* old command */
bb46e94f 13692ALIAS (show_bgp_view_neighbor_routes,
718e3744 13693 ipv6_bgp_neighbor_routes_cmd,
a80beece 13694 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 13695 SHOW_STR
13696 IPV6_STR
13697 BGP_STR
13698 "Detailed information on TCP and BGP neighbor connections\n"
13699 "Neighbor to display information about\n"
13700 "Neighbor to display information about\n"
a80beece 13701 "Neighbor on bgp configured interface\n"
718e3744 13702 "Display routes learned from neighbor\n")
718e3744 13703
13704/* old command */
13705DEFUN (ipv6_mbgp_neighbor_routes,
13706 ipv6_mbgp_neighbor_routes_cmd,
a80beece 13707 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 13708 SHOW_STR
13709 IPV6_STR
13710 MBGP_STR
13711 "Detailed information on TCP and BGP neighbor connections\n"
13712 "Neighbor to display information about\n"
13713 "Neighbor to display information about\n"
a80beece 13714 "Neighbor on bgp configured interface\n"
718e3744 13715 "Display routes learned from neighbor\n")
13716{
bb46e94f 13717 struct peer *peer;
13718
13719 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13720 if (! peer)
13721 return CMD_WARNING;
13722
13723 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
b05a1c8b 13724 bgp_show_type_neighbor);
718e3744 13725}
bb46e94f 13726
13727ALIAS (show_bgp_view_neighbor_flap,
13728 show_bgp_neighbor_flap_cmd,
a80beece 13729 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
bb46e94f 13730 SHOW_STR
13731 BGP_STR
13732 "Detailed information on TCP and BGP neighbor connections\n"
13733 "Neighbor to display information about\n"
13734 "Neighbor to display information about\n"
a80beece 13735 "Neighbor on bgp configured interface\n"
bb46e94f 13736 "Display flap statistics of the routes learned from neighbor\n")
13737
13738ALIAS (show_bgp_view_neighbor_flap,
13739 show_bgp_ipv6_neighbor_flap_cmd,
a80beece 13740 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
bb46e94f 13741 SHOW_STR
13742 BGP_STR
13743 "Address family\n"
13744 "Detailed information on TCP and BGP neighbor connections\n"
13745 "Neighbor to display information about\n"
13746 "Neighbor to display information about\n"
a80beece 13747 "Neighbor on bgp configured interface\n"
bb46e94f 13748 "Display flap statistics of the routes learned from neighbor\n")
13749
13750ALIAS (show_bgp_view_neighbor_damp,
13751 show_bgp_neighbor_damp_cmd,
a80beece 13752 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
bb46e94f 13753 SHOW_STR
13754 BGP_STR
13755 "Detailed information on TCP and BGP neighbor connections\n"
13756 "Neighbor to display information about\n"
13757 "Neighbor to display information about\n"
a80beece 13758 "Neighbor on bgp configured interface\n"
bb46e94f 13759 "Display the dampened routes received from neighbor\n")
13760
13761ALIAS (show_bgp_view_neighbor_damp,
13762 show_bgp_ipv6_neighbor_damp_cmd,
a80beece 13763 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
bb46e94f 13764 SHOW_STR
13765 BGP_STR
13766 "Address family\n"
13767 "Detailed information on TCP and BGP neighbor connections\n"
13768 "Neighbor to display information about\n"
13769 "Neighbor to display information about\n"
a80beece 13770 "Neighbor on bgp configured interface\n"
c001ae62 13771 "Display the dampened routes received from neighbor\n")
fee0f4c6 13772
13773DEFUN (show_bgp_view_rsclient,
13774 show_bgp_view_rsclient_cmd,
a80beece 13775 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 13776 SHOW_STR
13777 BGP_STR
13778 "BGP view\n"
2b00515a 13779 "View name\n"
fee0f4c6 13780 "Information about Route Server Client\n"
a80beece 13781 NEIGHBOR_ADDR_STR3)
fee0f4c6 13782{
13783 struct bgp_table *table;
13784 struct peer *peer;
13785
13786 if (argc == 2)
13787 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13788 else
13789 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13790
13791 if (! peer)
13792 return CMD_WARNING;
13793
13794 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
13795 {
13796 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13797 VTY_NEWLINE);
13798 return CMD_WARNING;
13799 }
13800
13801 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
13802 PEER_FLAG_RSERVER_CLIENT))
13803 {
13804 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13805 VTY_NEWLINE);
13806 return CMD_WARNING;
13807 }
13808
13809 table = peer->rib[AFI_IP6][SAFI_UNICAST];
13810
47fc97cc 13811 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
b05a1c8b 13812 NULL, 0);
fee0f4c6 13813}
13814
13815ALIAS (show_bgp_view_rsclient,
13816 show_bgp_rsclient_cmd,
a80beece 13817 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 13818 SHOW_STR
13819 BGP_STR
13820 "Information about Route Server Client\n"
a80beece 13821 NEIGHBOR_ADDR_STR3)
fee0f4c6 13822
95cbbd2a
ML
13823DEFUN (show_bgp_view_ipv6_safi_rsclient,
13824 show_bgp_view_ipv6_safi_rsclient_cmd,
a80beece 13825 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
95cbbd2a
ML
13826 SHOW_STR
13827 BGP_STR
13828 "BGP view\n"
2b00515a 13829 "View name\n"
95cbbd2a
ML
13830 "Address family\n"
13831 "Address Family modifier\n"
13832 "Address Family modifier\n"
13833 "Information about Route Server Client\n"
a80beece 13834 NEIGHBOR_ADDR_STR3)
95cbbd2a
ML
13835{
13836 struct bgp_table *table;
13837 struct peer *peer;
13838 safi_t safi;
13839
13840 if (argc == 3) {
13841 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13842 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13843 } else {
13844 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13845 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13846 }
13847
13848 if (! peer)
13849 return CMD_WARNING;
13850
13851 if (! peer->afc[AFI_IP6][safi])
13852 {
13853 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13854 VTY_NEWLINE);
13855 return CMD_WARNING;
13856 }
13857
13858 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
13859 PEER_FLAG_RSERVER_CLIENT))
13860 {
13861 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13862 VTY_NEWLINE);
13863 return CMD_WARNING;
13864 }
13865
13866 table = peer->rib[AFI_IP6][safi];
13867
47fc97cc 13868 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
b05a1c8b 13869 NULL, 0);
95cbbd2a
ML
13870}
13871
13872ALIAS (show_bgp_view_ipv6_safi_rsclient,
13873 show_bgp_ipv6_safi_rsclient_cmd,
a80beece 13874 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
95cbbd2a
ML
13875 SHOW_STR
13876 BGP_STR
13877 "Address family\n"
13878 "Address Family modifier\n"
13879 "Address Family modifier\n"
13880 "Information about Route Server Client\n"
a80beece 13881 NEIGHBOR_ADDR_STR3)
95cbbd2a 13882
fee0f4c6 13883DEFUN (show_bgp_view_rsclient_route,
13884 show_bgp_view_rsclient_route_cmd,
a80beece 13885 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
fee0f4c6 13886 SHOW_STR
13887 BGP_STR
13888 "BGP view\n"
2b00515a 13889 "View name\n"
fee0f4c6 13890 "Information about Route Server Client\n"
a80beece 13891 NEIGHBOR_ADDR_STR3
fee0f4c6 13892 "Network in the BGP routing table to display\n")
13893{
13894 struct bgp *bgp;
13895 struct peer *peer;
13896
13897 /* BGP structure lookup. */
13898 if (argc == 3)
13899 {
13900 bgp = bgp_lookup_by_name (argv[0]);
13901 if (bgp == NULL)
13902 {
13903 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13904 return CMD_WARNING;
13905 }
13906 }
13907 else
13908 {
13909 bgp = bgp_get_default ();
13910 if (bgp == NULL)
13911 {
13912 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13913 return CMD_WARNING;
13914 }
13915 }
13916
13917 if (argc == 3)
13918 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13919 else
13920 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13921
13922 if (! peer)
13923 return CMD_WARNING;
13924
13925 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
13926 {
13927 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13928 VTY_NEWLINE);
13929 return CMD_WARNING;
13930 }
13931
13932 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
13933 PEER_FLAG_RSERVER_CLIENT))
13934 {
13935 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13936 VTY_NEWLINE);
13937 return CMD_WARNING;
13938 }
13939
13940 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
13941 (argc == 3) ? argv[2] : argv[1],
b05a1c8b 13942 AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, 0);
fee0f4c6 13943}
13944
13945ALIAS (show_bgp_view_rsclient_route,
13946 show_bgp_rsclient_route_cmd,
a80beece 13947 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
fee0f4c6 13948 SHOW_STR
13949 BGP_STR
13950 "Information about Route Server Client\n"
a80beece 13951 NEIGHBOR_ADDR_STR3
fee0f4c6 13952 "Network in the BGP routing table to display\n")
13953
95cbbd2a
ML
13954DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
13955 show_bgp_view_ipv6_safi_rsclient_route_cmd,
a80beece 13956 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
95cbbd2a
ML
13957 SHOW_STR
13958 BGP_STR
13959 "BGP view\n"
2b00515a 13960 "View name\n"
95cbbd2a
ML
13961 "Address family\n"
13962 "Address Family modifier\n"
13963 "Address Family modifier\n"
13964 "Information about Route Server Client\n"
a80beece 13965 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13966 "Network in the BGP routing table to display\n")
13967{
13968 struct bgp *bgp;
13969 struct peer *peer;
13970 safi_t safi;
13971
13972 /* BGP structure lookup. */
13973 if (argc == 4)
13974 {
13975 bgp = bgp_lookup_by_name (argv[0]);
13976 if (bgp == NULL)
13977 {
13978 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13979 return CMD_WARNING;
13980 }
13981 }
13982 else
13983 {
13984 bgp = bgp_get_default ();
13985 if (bgp == NULL)
13986 {
13987 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13988 return CMD_WARNING;
13989 }
13990 }
13991
13992 if (argc == 4) {
13993 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13994 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13995 } else {
13996 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13997 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13998 }
13999
14000 if (! peer)
14001 return CMD_WARNING;
14002
14003 if (! peer->afc[AFI_IP6][safi])
14004 {
14005 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14006 VTY_NEWLINE);
14007 return CMD_WARNING;
14008}
14009
14010 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14011 PEER_FLAG_RSERVER_CLIENT))
14012 {
14013 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14014 VTY_NEWLINE);
14015 return CMD_WARNING;
14016 }
14017
14018 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
14019 (argc == 4) ? argv[3] : argv[2],
b05a1c8b 14020 AFI_IP6, safi, NULL, 0, BGP_PATH_ALL, 0);
95cbbd2a
ML
14021}
14022
14023ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
14024 show_bgp_ipv6_safi_rsclient_route_cmd,
a80beece 14025 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
95cbbd2a
ML
14026 SHOW_STR
14027 BGP_STR
14028 "Address family\n"
14029 "Address Family modifier\n"
14030 "Address Family modifier\n"
14031 "Information about Route Server Client\n"
a80beece 14032 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
14033 "Network in the BGP routing table to display\n")
14034
fee0f4c6 14035DEFUN (show_bgp_view_rsclient_prefix,
14036 show_bgp_view_rsclient_prefix_cmd,
a80beece 14037 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
fee0f4c6 14038 SHOW_STR
14039 BGP_STR
14040 "BGP view\n"
2b00515a 14041 "View name\n"
fee0f4c6 14042 "Information about Route Server Client\n"
a80beece 14043 NEIGHBOR_ADDR_STR3
fee0f4c6 14044 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14045{
14046 struct bgp *bgp;
14047 struct peer *peer;
14048
14049 /* BGP structure lookup. */
14050 if (argc == 3)
14051 {
14052 bgp = bgp_lookup_by_name (argv[0]);
14053 if (bgp == NULL)
14054 {
14055 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14056 return CMD_WARNING;
14057 }
14058 }
14059 else
14060 {
14061 bgp = bgp_get_default ();
14062 if (bgp == NULL)
14063 {
14064 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14065 return CMD_WARNING;
14066 }
14067 }
14068
14069 if (argc == 3)
14070 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14071 else
14072 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14073
14074 if (! peer)
14075 return CMD_WARNING;
14076
14077 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14078 {
14079 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14080 VTY_NEWLINE);
14081 return CMD_WARNING;
14082 }
14083
14084 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14085 PEER_FLAG_RSERVER_CLIENT))
14086 {
14087 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14088 VTY_NEWLINE);
14089 return CMD_WARNING;
14090 }
14091
14092 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14093 (argc == 3) ? argv[2] : argv[1],
b05a1c8b 14094 AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, 0);
fee0f4c6 14095}
14096
14097ALIAS (show_bgp_view_rsclient_prefix,
14098 show_bgp_rsclient_prefix_cmd,
a80beece 14099 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
fee0f4c6 14100 SHOW_STR
14101 BGP_STR
14102 "Information about Route Server Client\n"
a80beece 14103 NEIGHBOR_ADDR_STR3
fee0f4c6 14104 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14105
95cbbd2a
ML
14106DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
14107 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
a80beece 14108 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
95cbbd2a
ML
14109 SHOW_STR
14110 BGP_STR
14111 "BGP view\n"
2b00515a 14112 "View name\n"
95cbbd2a
ML
14113 "Address family\n"
14114 "Address Family modifier\n"
14115 "Address Family modifier\n"
14116 "Information about Route Server Client\n"
a80beece 14117 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
14118 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
14119{
14120 struct bgp *bgp;
14121 struct peer *peer;
14122 safi_t safi;
14123
14124 /* BGP structure lookup. */
14125 if (argc == 4)
14126 {
14127 bgp = bgp_lookup_by_name (argv[0]);
14128 if (bgp == NULL)
14129 {
14130 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14131 return CMD_WARNING;
14132 }
14133 }
14134 else
14135 {
14136 bgp = bgp_get_default ();
14137 if (bgp == NULL)
14138 {
14139 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14140 return CMD_WARNING;
14141 }
14142 }
14143
14144 if (argc == 4) {
14145 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14146 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14147 } else {
14148 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14149 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14150 }
14151
14152 if (! peer)
14153 return CMD_WARNING;
14154
14155 if (! peer->afc[AFI_IP6][safi])
14156 {
14157 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14158 VTY_NEWLINE);
14159 return CMD_WARNING;
14160}
14161
14162 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14163 PEER_FLAG_RSERVER_CLIENT))
14164{
14165 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14166 VTY_NEWLINE);
14167 return CMD_WARNING;
14168 }
14169
14170 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
14171 (argc == 4) ? argv[3] : argv[2],
b05a1c8b 14172 AFI_IP6, safi, NULL, 1, BGP_PATH_ALL, 0);
95cbbd2a
ML
14173}
14174
14175ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
14176 show_bgp_ipv6_safi_rsclient_prefix_cmd,
a80beece 14177 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
95cbbd2a
ML
14178 SHOW_STR
14179 BGP_STR
14180 "Address family\n"
14181 "Address Family modifier\n"
14182 "Address Family modifier\n"
14183 "Information about Route Server Client\n"
a80beece 14184 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
14185 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
14186
718e3744 14187#endif /* HAVE_IPV6 */
6b0655a2 14188
718e3744 14189struct bgp_table *bgp_distance_table;
14190
14191struct bgp_distance
14192{
14193 /* Distance value for the IP source prefix. */
14194 u_char distance;
14195
14196 /* Name of the access-list to be matched. */
14197 char *access_list;
14198};
14199
94f2b392 14200static struct bgp_distance *
66e5cd87 14201bgp_distance_new (void)
718e3744 14202{
393deb9b 14203 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
718e3744 14204}
14205
94f2b392 14206static void
718e3744 14207bgp_distance_free (struct bgp_distance *bdistance)
14208{
14209 XFREE (MTYPE_BGP_DISTANCE, bdistance);
14210}
14211
94f2b392 14212static int
fd79ac91 14213bgp_distance_set (struct vty *vty, const char *distance_str,
14214 const char *ip_str, const char *access_list_str)
718e3744 14215{
14216 int ret;
14217 struct prefix_ipv4 p;
14218 u_char distance;
14219 struct bgp_node *rn;
14220 struct bgp_distance *bdistance;
14221
14222 ret = str2prefix_ipv4 (ip_str, &p);
14223 if (ret == 0)
14224 {
14225 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
14226 return CMD_WARNING;
14227 }
14228
14229 distance = atoi (distance_str);
14230
14231 /* Get BGP distance node. */
14232 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
14233 if (rn->info)
14234 {
14235 bdistance = rn->info;
14236 bgp_unlock_node (rn);
14237 }
14238 else
14239 {
14240 bdistance = bgp_distance_new ();
14241 rn->info = bdistance;
14242 }
14243
14244 /* Set distance value. */
14245 bdistance->distance = distance;
14246
14247 /* Reset access-list configuration. */
14248 if (bdistance->access_list)
14249 {
14250 free (bdistance->access_list);
14251 bdistance->access_list = NULL;
14252 }
14253 if (access_list_str)
14254 bdistance->access_list = strdup (access_list_str);
14255
14256 return CMD_SUCCESS;
14257}
14258
94f2b392 14259static int
fd79ac91 14260bgp_distance_unset (struct vty *vty, const char *distance_str,
14261 const char *ip_str, const char *access_list_str)
718e3744 14262{
14263 int ret;
14264 struct prefix_ipv4 p;
14265 u_char distance;
14266 struct bgp_node *rn;
14267 struct bgp_distance *bdistance;
14268
14269 ret = str2prefix_ipv4 (ip_str, &p);
14270 if (ret == 0)
14271 {
14272 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
14273 return CMD_WARNING;
14274 }
14275
14276 distance = atoi (distance_str);
14277
14278 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
14279 if (! rn)
14280 {
14281 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
14282 return CMD_WARNING;
14283 }
14284
14285 bdistance = rn->info;
14286
14287 if (bdistance->access_list)
14288 free (bdistance->access_list);
14289 bgp_distance_free (bdistance);
14290
14291 rn->info = NULL;
14292 bgp_unlock_node (rn);
14293 bgp_unlock_node (rn);
14294
14295 return CMD_SUCCESS;
14296}
14297
718e3744 14298/* Apply BGP information to distance method. */
14299u_char
14300bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
14301{
14302 struct bgp_node *rn;
14303 struct prefix_ipv4 q;
14304 struct peer *peer;
14305 struct bgp_distance *bdistance;
14306 struct access_list *alist;
14307 struct bgp_static *bgp_static;
14308
14309 if (! bgp)
14310 return 0;
14311
14312 if (p->family != AF_INET)
14313 return 0;
14314
14315 peer = rinfo->peer;
14316
14317 if (peer->su.sa.sa_family != AF_INET)
14318 return 0;
14319
14320 memset (&q, 0, sizeof (struct prefix_ipv4));
14321 q.family = AF_INET;
14322 q.prefix = peer->su.sin.sin_addr;
14323 q.prefixlen = IPV4_MAX_BITLEN;
14324
14325 /* Check source address. */
14326 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
14327 if (rn)
14328 {
14329 bdistance = rn->info;
14330 bgp_unlock_node (rn);
14331
14332 if (bdistance->access_list)
14333 {
14334 alist = access_list_lookup (AFI_IP, bdistance->access_list);
14335 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
14336 return bdistance->distance;
14337 }
14338 else
14339 return bdistance->distance;
14340 }
14341
14342 /* Backdoor check. */
14343 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
14344 if (rn)
14345 {
14346 bgp_static = rn->info;
14347 bgp_unlock_node (rn);
14348
14349 if (bgp_static->backdoor)
14350 {
14351 if (bgp->distance_local)
14352 return bgp->distance_local;
14353 else
14354 return ZEBRA_IBGP_DISTANCE_DEFAULT;
14355 }
14356 }
14357
6d85b15b 14358 if (peer->sort == BGP_PEER_EBGP)
718e3744 14359 {
14360 if (bgp->distance_ebgp)
14361 return bgp->distance_ebgp;
14362 return ZEBRA_EBGP_DISTANCE_DEFAULT;
14363 }
14364 else
14365 {
14366 if (bgp->distance_ibgp)
14367 return bgp->distance_ibgp;
14368 return ZEBRA_IBGP_DISTANCE_DEFAULT;
14369 }
14370}
14371
14372DEFUN (bgp_distance,
14373 bgp_distance_cmd,
14374 "distance bgp <1-255> <1-255> <1-255>",
14375 "Define an administrative distance\n"
14376 "BGP distance\n"
14377 "Distance for routes external to the AS\n"
14378 "Distance for routes internal to the AS\n"
14379 "Distance for local routes\n")
14380{
14381 struct bgp *bgp;
14382
14383 bgp = vty->index;
14384
14385 bgp->distance_ebgp = atoi (argv[0]);
14386 bgp->distance_ibgp = atoi (argv[1]);
14387 bgp->distance_local = atoi (argv[2]);
14388 return CMD_SUCCESS;
14389}
14390
14391DEFUN (no_bgp_distance,
14392 no_bgp_distance_cmd,
14393 "no distance bgp <1-255> <1-255> <1-255>",
14394 NO_STR
14395 "Define an administrative distance\n"
14396 "BGP distance\n"
14397 "Distance for routes external to the AS\n"
14398 "Distance for routes internal to the AS\n"
14399 "Distance for local routes\n")
14400{
14401 struct bgp *bgp;
14402
14403 bgp = vty->index;
14404
14405 bgp->distance_ebgp= 0;
14406 bgp->distance_ibgp = 0;
14407 bgp->distance_local = 0;
14408 return CMD_SUCCESS;
14409}
14410
14411ALIAS (no_bgp_distance,
14412 no_bgp_distance2_cmd,
14413 "no distance bgp",
14414 NO_STR
14415 "Define an administrative distance\n"
14416 "BGP distance\n")
14417
14418DEFUN (bgp_distance_source,
14419 bgp_distance_source_cmd,
14420 "distance <1-255> A.B.C.D/M",
14421 "Define an administrative distance\n"
14422 "Administrative distance\n"
14423 "IP source prefix\n")
14424{
14425 bgp_distance_set (vty, argv[0], argv[1], NULL);
14426 return CMD_SUCCESS;
14427}
14428
14429DEFUN (no_bgp_distance_source,
14430 no_bgp_distance_source_cmd,
14431 "no distance <1-255> A.B.C.D/M",
14432 NO_STR
14433 "Define an administrative distance\n"
14434 "Administrative distance\n"
14435 "IP source prefix\n")
14436{
14437 bgp_distance_unset (vty, argv[0], argv[1], NULL);
14438 return CMD_SUCCESS;
14439}
14440
14441DEFUN (bgp_distance_source_access_list,
14442 bgp_distance_source_access_list_cmd,
14443 "distance <1-255> A.B.C.D/M WORD",
14444 "Define an administrative distance\n"
14445 "Administrative distance\n"
14446 "IP source prefix\n"
14447 "Access list name\n")
14448{
14449 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
14450 return CMD_SUCCESS;
14451}
14452
14453DEFUN (no_bgp_distance_source_access_list,
14454 no_bgp_distance_source_access_list_cmd,
14455 "no distance <1-255> A.B.C.D/M WORD",
14456 NO_STR
14457 "Define an administrative distance\n"
14458 "Administrative distance\n"
14459 "IP source prefix\n"
14460 "Access list name\n")
14461{
14462 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
14463 return CMD_SUCCESS;
14464}
6b0655a2 14465
718e3744 14466DEFUN (bgp_damp_set,
14467 bgp_damp_set_cmd,
14468 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14469 "BGP Specific commands\n"
14470 "Enable route-flap dampening\n"
14471 "Half-life time for the penalty\n"
14472 "Value to start reusing a route\n"
14473 "Value to start suppressing a route\n"
14474 "Maximum duration to suppress a stable route\n")
14475{
14476 struct bgp *bgp;
14477 int half = DEFAULT_HALF_LIFE * 60;
14478 int reuse = DEFAULT_REUSE;
14479 int suppress = DEFAULT_SUPPRESS;
14480 int max = 4 * half;
14481
14482 if (argc == 4)
14483 {
14484 half = atoi (argv[0]) * 60;
14485 reuse = atoi (argv[1]);
14486 suppress = atoi (argv[2]);
14487 max = atoi (argv[3]) * 60;
14488 }
14489 else if (argc == 1)
14490 {
14491 half = atoi (argv[0]) * 60;
14492 max = 4 * half;
14493 }
14494
14495 bgp = vty->index;
14496 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
14497 half, reuse, suppress, max);
14498}
14499
14500ALIAS (bgp_damp_set,
14501 bgp_damp_set2_cmd,
14502 "bgp dampening <1-45>",
14503 "BGP Specific commands\n"
14504 "Enable route-flap dampening\n"
14505 "Half-life time for the penalty\n")
14506
14507ALIAS (bgp_damp_set,
14508 bgp_damp_set3_cmd,
14509 "bgp dampening",
14510 "BGP Specific commands\n"
14511 "Enable route-flap dampening\n")
14512
14513DEFUN (bgp_damp_unset,
14514 bgp_damp_unset_cmd,
14515 "no bgp dampening",
14516 NO_STR
14517 "BGP Specific commands\n"
14518 "Enable route-flap dampening\n")
14519{
14520 struct bgp *bgp;
14521
14522 bgp = vty->index;
14523 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
14524}
14525
14526ALIAS (bgp_damp_unset,
14527 bgp_damp_unset2_cmd,
14528 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14529 NO_STR
14530 "BGP Specific commands\n"
14531 "Enable route-flap dampening\n"
14532 "Half-life time for the penalty\n"
14533 "Value to start reusing a route\n"
14534 "Value to start suppressing a route\n"
14535 "Maximum duration to suppress a stable route\n")
14536
14537DEFUN (show_ip_bgp_dampened_paths,
14538 show_ip_bgp_dampened_paths_cmd,
14539 "show ip bgp dampened-paths",
14540 SHOW_STR
14541 IP_STR
14542 BGP_STR
14543 "Display paths suppressed due to dampening\n")
14544{
5a646650 14545 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
b05a1c8b 14546 NULL, 0);
718e3744 14547}
14548
14549DEFUN (show_ip_bgp_flap_statistics,
14550 show_ip_bgp_flap_statistics_cmd,
14551 "show ip bgp flap-statistics",
14552 SHOW_STR
14553 IP_STR
14554 BGP_STR
14555 "Display flap statistics of routes\n")
14556{
5a646650 14557 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 14558 bgp_show_type_flap_statistics, NULL, 0);
718e3744 14559}
6b0655a2 14560
718e3744 14561/* Display specified route of BGP table. */
94f2b392 14562static int
fd79ac91 14563bgp_clear_damp_route (struct vty *vty, const char *view_name,
14564 const char *ip_str, afi_t afi, safi_t safi,
14565 struct prefix_rd *prd, int prefix_check)
718e3744 14566{
14567 int ret;
14568 struct prefix match;
14569 struct bgp_node *rn;
14570 struct bgp_node *rm;
14571 struct bgp_info *ri;
14572 struct bgp_info *ri_temp;
14573 struct bgp *bgp;
14574 struct bgp_table *table;
14575
14576 /* BGP structure lookup. */
14577 if (view_name)
14578 {
14579 bgp = bgp_lookup_by_name (view_name);
14580 if (bgp == NULL)
14581 {
14582 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
14583 return CMD_WARNING;
14584 }
14585 }
14586 else
14587 {
14588 bgp = bgp_get_default ();
14589 if (bgp == NULL)
14590 {
14591 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
14592 return CMD_WARNING;
14593 }
14594 }
14595
14596 /* Check IP address argument. */
14597 ret = str2prefix (ip_str, &match);
14598 if (! ret)
14599 {
14600 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
14601 return CMD_WARNING;
14602 }
14603
14604 match.family = afi2family (afi);
14605
14606 if (safi == SAFI_MPLS_VPN)
14607 {
14608 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
14609 {
14610 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
14611 continue;
14612
14613 if ((table = rn->info) != NULL)
14614 if ((rm = bgp_node_match (table, &match)) != NULL)
6c88b44d
CC
14615 {
14616 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
14617 {
14618 ri = rm->info;
14619 while (ri)
14620 {
14621 if (ri->extra && ri->extra->damp_info)
14622 {
14623 ri_temp = ri->next;
14624 bgp_damp_info_free (ri->extra->damp_info, 1);
14625 ri = ri_temp;
14626 }
14627 else
14628 ri = ri->next;
14629 }
14630 }
14631
14632 bgp_unlock_node (rm);
14633 }
718e3744 14634 }
14635 }
14636 else
14637 {
14638 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
6c88b44d
CC
14639 {
14640 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
14641 {
14642 ri = rn->info;
14643 while (ri)
14644 {
14645 if (ri->extra && ri->extra->damp_info)
14646 {
14647 ri_temp = ri->next;
14648 bgp_damp_info_free (ri->extra->damp_info, 1);
14649 ri = ri_temp;
14650 }
14651 else
14652 ri = ri->next;
14653 }
14654 }
14655
14656 bgp_unlock_node (rn);
14657 }
718e3744 14658 }
14659
14660 return CMD_SUCCESS;
14661}
14662
14663DEFUN (clear_ip_bgp_dampening,
14664 clear_ip_bgp_dampening_cmd,
14665 "clear ip bgp dampening",
14666 CLEAR_STR
14667 IP_STR
14668 BGP_STR
14669 "Clear route flap dampening information\n")
14670{
14671 bgp_damp_info_clean ();
14672 return CMD_SUCCESS;
14673}
14674
14675DEFUN (clear_ip_bgp_dampening_prefix,
14676 clear_ip_bgp_dampening_prefix_cmd,
14677 "clear ip bgp dampening A.B.C.D/M",
14678 CLEAR_STR
14679 IP_STR
14680 BGP_STR
14681 "Clear route flap dampening information\n"
14682 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14683{
14684 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14685 SAFI_UNICAST, NULL, 1);
14686}
14687
14688DEFUN (clear_ip_bgp_dampening_address,
14689 clear_ip_bgp_dampening_address_cmd,
14690 "clear ip bgp dampening A.B.C.D",
14691 CLEAR_STR
14692 IP_STR
14693 BGP_STR
14694 "Clear route flap dampening information\n"
14695 "Network to clear damping information\n")
14696{
14697 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14698 SAFI_UNICAST, NULL, 0);
14699}
14700
14701DEFUN (clear_ip_bgp_dampening_address_mask,
14702 clear_ip_bgp_dampening_address_mask_cmd,
14703 "clear ip bgp dampening A.B.C.D A.B.C.D",
14704 CLEAR_STR
14705 IP_STR
14706 BGP_STR
14707 "Clear route flap dampening information\n"
14708 "Network to clear damping information\n"
14709 "Network mask\n")
14710{
14711 int ret;
14712 char prefix_str[BUFSIZ];
14713
14714 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
14715 if (! ret)
14716 {
14717 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
14718 return CMD_WARNING;
14719 }
14720
14721 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
14722 SAFI_UNICAST, NULL, 0);
14723}
6b0655a2 14724
94f2b392 14725static int
718e3744 14726bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
14727 afi_t afi, safi_t safi, int *write)
14728{
14729 struct bgp_node *prn;
14730 struct bgp_node *rn;
14731 struct bgp_table *table;
14732 struct prefix *p;
14733 struct prefix_rd *prd;
14734 struct bgp_static *bgp_static;
14735 u_int32_t label;
14736 char buf[SU_ADDRSTRLEN];
14737 char rdbuf[RD_ADDRSTRLEN];
14738
14739 /* Network configuration. */
14740 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
14741 if ((table = prn->info) != NULL)
14742 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
14743 if ((bgp_static = rn->info) != NULL)
14744 {
14745 p = &rn->p;
14746 prd = (struct prefix_rd *) &prn->p;
14747
14748 /* "address-family" display. */
14749 bgp_config_write_family_header (vty, afi, safi, write);
14750
14751 /* "network" configuration display. */
14752 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
14753 label = decode_label (bgp_static->tag);
14754
14755 vty_out (vty, " network %s/%d rd %s tag %d",
14756 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14757 p->prefixlen,
14758 rdbuf, label);
14759 vty_out (vty, "%s", VTY_NEWLINE);
14760 }
14761 return 0;
14762}
14763
14764/* Configuration of static route announcement and aggregate
14765 information. */
14766int
14767bgp_config_write_network (struct vty *vty, struct bgp *bgp,
14768 afi_t afi, safi_t safi, int *write)
14769{
14770 struct bgp_node *rn;
14771 struct prefix *p;
14772 struct bgp_static *bgp_static;
14773 struct bgp_aggregate *bgp_aggregate;
14774 char buf[SU_ADDRSTRLEN];
14775
14776 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
14777 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
14778
14779 /* Network configuration. */
14780 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
14781 if ((bgp_static = rn->info) != NULL)
14782 {
14783 p = &rn->p;
14784
14785 /* "address-family" display. */
14786 bgp_config_write_family_header (vty, afi, safi, write);
14787
14788 /* "network" configuration display. */
14789 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14790 {
14791 u_int32_t destination;
14792 struct in_addr netmask;
14793
14794 destination = ntohl (p->u.prefix4.s_addr);
14795 masklen2ip (p->prefixlen, &netmask);
14796 vty_out (vty, " network %s",
14797 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
14798
14799 if ((IN_CLASSC (destination) && p->prefixlen == 24)
14800 || (IN_CLASSB (destination) && p->prefixlen == 16)
14801 || (IN_CLASSA (destination) && p->prefixlen == 8)
14802 || p->u.prefix4.s_addr == 0)
14803 {
14804 /* Natural mask is not display. */
14805 }
14806 else
14807 vty_out (vty, " mask %s", inet_ntoa (netmask));
14808 }
14809 else
14810 {
14811 vty_out (vty, " network %s/%d",
14812 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14813 p->prefixlen);
14814 }
14815
14816 if (bgp_static->rmap.name)
14817 vty_out (vty, " route-map %s", bgp_static->rmap.name);
41367172
PJ
14818 else
14819 {
14820 if (bgp_static->backdoor)
14821 vty_out (vty, " backdoor");
41367172 14822 }
718e3744 14823
14824 vty_out (vty, "%s", VTY_NEWLINE);
14825 }
14826
14827 /* Aggregate-address configuration. */
14828 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
14829 if ((bgp_aggregate = rn->info) != NULL)
14830 {
14831 p = &rn->p;
14832
14833 /* "address-family" display. */
14834 bgp_config_write_family_header (vty, afi, safi, write);
14835
14836 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14837 {
14838 struct in_addr netmask;
14839
14840 masklen2ip (p->prefixlen, &netmask);
14841 vty_out (vty, " aggregate-address %s %s",
14842 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14843 inet_ntoa (netmask));
14844 }
14845 else
14846 {
14847 vty_out (vty, " aggregate-address %s/%d",
14848 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14849 p->prefixlen);
14850 }
14851
14852 if (bgp_aggregate->as_set)
14853 vty_out (vty, " as-set");
14854
14855 if (bgp_aggregate->summary_only)
14856 vty_out (vty, " summary-only");
14857
14858 vty_out (vty, "%s", VTY_NEWLINE);
14859 }
14860
14861 return 0;
14862}
14863
14864int
14865bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
14866{
14867 struct bgp_node *rn;
14868 struct bgp_distance *bdistance;
14869
14870 /* Distance configuration. */
14871 if (bgp->distance_ebgp
14872 && bgp->distance_ibgp
14873 && bgp->distance_local
14874 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
14875 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
14876 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
14877 vty_out (vty, " distance bgp %d %d %d%s",
14878 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
14879 VTY_NEWLINE);
14880
14881 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
14882 if ((bdistance = rn->info) != NULL)
14883 {
14884 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
14885 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
14886 bdistance->access_list ? bdistance->access_list : "",
14887 VTY_NEWLINE);
14888 }
14889
14890 return 0;
14891}
14892
14893/* Allocate routing table structure and install commands. */
14894void
66e5cd87 14895bgp_route_init (void)
718e3744 14896{
14897 /* Init BGP distance table. */
64e580a7 14898 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
718e3744 14899
14900 /* IPv4 BGP commands. */
73ac8160 14901 install_element (BGP_NODE, &bgp_table_map_cmd);
718e3744 14902 install_element (BGP_NODE, &bgp_network_cmd);
14903 install_element (BGP_NODE, &bgp_network_mask_cmd);
14904 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
14905 install_element (BGP_NODE, &bgp_network_route_map_cmd);
14906 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
14907 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
14908 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
14909 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
14910 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
73ac8160 14911 install_element (BGP_NODE, &no_bgp_table_map_cmd);
718e3744 14912 install_element (BGP_NODE, &no_bgp_network_cmd);
14913 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
14914 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
14915 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
14916 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
14917 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14918 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
14919 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
14920 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
14921
14922 install_element (BGP_NODE, &aggregate_address_cmd);
14923 install_element (BGP_NODE, &aggregate_address_mask_cmd);
14924 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
14925 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
14926 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
14927 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
14928 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
14929 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
14930 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
14931 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
14932 install_element (BGP_NODE, &no_aggregate_address_cmd);
14933 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
14934 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
14935 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
14936 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
14937 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
14938 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
14939 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
14940 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14941 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14942
14943 /* IPv4 unicast configuration. */
73ac8160 14944 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
718e3744 14945 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
14946 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
14947 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
14948 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
14949 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
14950 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 14951 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
c8f3fe30 14952 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
718e3744 14953 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
14954 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
14955 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
14956 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
14957 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
c8f3fe30 14958
718e3744 14959 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
14960 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
14961 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
14962 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
14963 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
14964 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
14965 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
14966 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
14967 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
14968 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
14969 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
14970 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
14971 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
14972 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
14973 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
14974 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
14975 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
14976 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
14977 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14978 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14979
14980 /* IPv4 multicast configuration. */
73ac8160 14981 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
718e3744 14982 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
14983 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
14984 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
14985 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
14986 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
14987 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 14988 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
718e3744 14989 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
14990 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
14991 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
14992 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
14993 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
14994 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14995 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
14996 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
14997 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
14998 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
14999 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
15000 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
15001 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
15002 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
15003 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
15004 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
15005 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
15006 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
15007 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
15008 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
15009 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
15010 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
15011 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
15012 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
15013 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
15014 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
15015
15016 install_element (VIEW_NODE, &show_ip_bgp_cmd);
15017 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 15018 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
718e3744 15019 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
15020 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
15021 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 15022 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 15023 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 15024 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
15025 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
15026 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
15027 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
15028 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
15029 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 15030 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 15031 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
718e3744 15032 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
15033 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
15034 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
15035 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
15036 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
15037 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
15038 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
15039 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
15040 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
15041 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
15042 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
15043 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
15044 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
15045 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
15046 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
15047 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
15048 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
15049 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
15050 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
15051 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
15052 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
15053 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
15054 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
15055 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
15056 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
15057 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
15058 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
15059 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
15060 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
15061 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
718e3744 15062 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
15063 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
15064 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
15065 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
15066 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
15067 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
15068 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
15069 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
15070 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
15071 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
15072 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
15073 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
15074 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
15075 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
15076 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
0b16f239 15077 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
718e3744 15078 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
0b16f239 15079 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
718e3744 15080 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
0b16f239 15081 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
718e3744 15082 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
0b16f239 15083 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
95cbbd2a 15084 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 15085 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
15086 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
15087 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
15088 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
15089 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
15090 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
15091 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
15092 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
15093 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
15094 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
15095 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
15096 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
15097 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
15098 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
15099 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
15100 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
fee0f4c6 15101 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
95cbbd2a 15102 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
fee0f4c6 15103 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 15104 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
fee0f4c6 15105 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 15106 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
2a71e9ce
TP
15107 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
15108 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
fee0f4c6 15109 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
95cbbd2a 15110 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
fee0f4c6 15111 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 15112 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
fee0f4c6 15113 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 15114 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
62687ff1
PJ
15115
15116 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
15117 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
15118 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
15119 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
62687ff1 15120 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 15121 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
62687ff1
PJ
15122 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
15123 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
15124 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
15125 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
15126 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 15127 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 15128 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
62687ff1
PJ
15129 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
15130 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
15131 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
15132 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
15133 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
15134 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
15135 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
15136 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
15137 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
15138 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
15139 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
15140 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
15141 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
15142 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
15143 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
15144 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
15145 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
62687ff1
PJ
15146 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
15147 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
15148 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
15149 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
15150 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
15151 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
15152 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
15153 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
15154 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 15155 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
62687ff1 15156 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 15157 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
62687ff1 15158 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 15159 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
62687ff1 15160 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 15161 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
718e3744 15162
15163 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
15164 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 15165 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
718e3744 15166 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
15167 install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd);
15168 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 15169 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 15170 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 15171 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
15172 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
15173 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
15174 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
15175 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
15176 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 15177 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 15178 install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd);
718e3744 15179 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
15180 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
15181 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
15182 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
15183 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
15184 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
15185 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
15186 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
15187 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
15188 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
15189 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
15190 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
15191 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
15192 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
15193 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
15194 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
15195 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
15196 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
15197 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
15198 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
15199 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
15200 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
15201 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
15202 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
15203 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
15204 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
15205 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
15206 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
15207 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
15208 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
718e3744 15209 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
15210 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
15211 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
15212 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
15213 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
15214 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
15215 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
15216 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
15217 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
15218 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
15219 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
15220 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
15221 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
15222 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
15223 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
0b16f239 15224 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
718e3744 15225 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
0b16f239 15226 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
718e3744 15227 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
0b16f239 15228 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
718e3744 15229 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
0b16f239 15230 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
95cbbd2a 15231 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 15232 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
15233 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
15234 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
15235 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
15236 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
15237 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
15238 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
15239 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
15240 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
15241 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
15242 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
15243 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
15244 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
15245 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
15246 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
15247 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
fee0f4c6 15248 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
95cbbd2a 15249 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
fee0f4c6 15250 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 15251 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
fee0f4c6 15252 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 15253 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
2a71e9ce
TP
15254 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
15255 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
fee0f4c6 15256 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
95cbbd2a 15257 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
fee0f4c6 15258 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 15259 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
fee0f4c6 15260 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 15261 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
718e3744 15262
15263 /* BGP dampening clear commands */
15264 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
15265 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
15266 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
15267 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
15268
ff7924f6
PJ
15269 /* prefix count */
15270 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
15271 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
15272 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
718e3744 15273#ifdef HAVE_IPV6
ff7924f6
PJ
15274 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
15275
718e3744 15276 /* New config IPv6 BGP commands. */
73ac8160 15277 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
718e3744 15278 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
15279 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
73ac8160 15280 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
718e3744 15281 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
15282 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
15283
15284 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
15285 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
15286 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
15287 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
73bfe0bd
B
15288
15289 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
15290 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
718e3744 15291
15292 /* Old config IPv6 BGP commands. */
15293 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
15294 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
15295
15296 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
15297 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
15298 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
15299 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
15300
15301 install_element (VIEW_NODE, &show_bgp_cmd);
15302 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 15303 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 15304 install_element (VIEW_NODE, &show_bgp_route_cmd);
15305 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 15306 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
15307 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
15308 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
15309 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 15310 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
15311 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 15312 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c
DS
15313 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
15314 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
15315 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 15316 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
15317 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
15318 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
15319 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
15320 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
15321 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
15322 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
15323 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
15324 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
15325 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
15326 install_element (VIEW_NODE, &show_bgp_community_cmd);
15327 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
15328 install_element (VIEW_NODE, &show_bgp_community2_cmd);
15329 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
15330 install_element (VIEW_NODE, &show_bgp_community3_cmd);
15331 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
15332 install_element (VIEW_NODE, &show_bgp_community4_cmd);
15333 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
15334 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
15335 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
15336 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
15337 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
15338 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
15339 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
15340 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
15341 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
15342 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
15343 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
15344 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
15345 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
15346 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
15347 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
15348 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
15349 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
15350 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
15351 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
15352 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
15353 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
15354 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
15355 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 15356 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
15357 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
15358 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
15359 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
fee0f4c6 15360 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
95cbbd2a 15361 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
fee0f4c6 15362 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 15363 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
fee0f4c6 15364 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 15365 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
bb46e94f 15366 install_element (VIEW_NODE, &show_bgp_view_cmd);
15367 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
15368 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
15369 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
15370 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
15371 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
15372 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
15373 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
15374 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
15375 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
15376 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
15377 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
15378 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
15379 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
15380 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
15381 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
15382 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
15383 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
fee0f4c6 15384 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
95cbbd2a 15385 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
fee0f4c6 15386 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 15387 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
fee0f4c6 15388 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 15389 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
62687ff1
PJ
15390
15391 /* Restricted:
15392 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
15393 */
15394 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
15395 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 15396 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
15397 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
15398 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
15399 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
62687ff1
PJ
15400 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
15401 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 15402 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c
DS
15403 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
15404 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
15405 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
62687ff1
PJ
15406 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
15407 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
15408 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
15409 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
15410 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
15411 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
15412 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
15413 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
15414 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
15415 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
15416 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
15417 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
15418 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
15419 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
15420 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
15421 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
15422 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 15423 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
62687ff1 15424 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 15425 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
62687ff1
PJ
15426 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
15427 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
15428 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
15429 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
15430 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
15431 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
15432 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 15433 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
62687ff1 15434 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 15435 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
718e3744 15436
15437 install_element (ENABLE_NODE, &show_bgp_cmd);
15438 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 15439 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 15440 install_element (ENABLE_NODE, &show_bgp_route_cmd);
15441 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 15442 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
15443 install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd);
15444 install_element (ENABLE_NODE, &show_bgp_ipv6_route_pathtype_cmd);
15445 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 15446 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
4092b06c
DS
15447 install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd);
15448 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
15449 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 15450 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 15451 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
718e3744 15452 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
15453 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
15454 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
15455 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
15456 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
15457 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
15458 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
15459 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
15460 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
15461 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
15462 install_element (ENABLE_NODE, &show_bgp_community_cmd);
15463 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
15464 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
15465 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
15466 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
15467 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
15468 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
15469 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
15470 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
15471 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
15472 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
15473 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
15474 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
15475 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
15476 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
15477 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
15478 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
15479 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
15480 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
15481 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
15482 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
15483 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
15484 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
15485 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
15486 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
15487 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
15488 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
15489 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
15490 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
15491 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 15492 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
15493 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
15494 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
15495 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
fee0f4c6 15496 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
95cbbd2a 15497 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
fee0f4c6 15498 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 15499 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
fee0f4c6 15500 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 15501 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
bb46e94f 15502 install_element (ENABLE_NODE, &show_bgp_view_cmd);
15503 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
15504 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
15505 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
15506 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
15507 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
15508 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
15509 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
15510 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
15511 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
15512 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
15513 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
15514 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
15515 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
15516 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
15517 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
15518 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
15519 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
fee0f4c6 15520 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
95cbbd2a 15521 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
fee0f4c6 15522 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 15523 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
fee0f4c6 15524 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 15525 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
2815e61f
PJ
15526
15527 /* Statistics */
15528 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
15529 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
15530 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
15531 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
15532
718e3744 15533 /* old command */
15534 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
15535 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
15536 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
15537 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
15538 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
15539 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
15540 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
15541 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
15542 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
15543 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
15544 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
15545 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
15546 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
15547 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
15548 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
15549 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
15550 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15551 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15552 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
15553 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
15554 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
15555 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
15556 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15557 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
15558 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
15559 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
15560 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
15561 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
15562 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
15563 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
15564 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
15565 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
15566 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
15567 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
15568 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15569 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
bb46e94f 15570
718e3744 15571 /* old command */
15572 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
15573 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
15574 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
15575 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
15576 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
15577 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
15578 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
15579 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
15580 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
15581 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
15582 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
15583 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
15584 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
15585 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
15586 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
15587 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
15588 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15589 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15590 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
15591 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
15592 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
15593 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
15594 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15595 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
15596 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
15597 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
15598 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
15599 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
15600 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
15601 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
15602 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
15603 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
15604 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
15605 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
15606 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15607 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
15608
15609 /* old command */
15610 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
15611 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
15612 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
15613 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
15614
15615 /* old command */
15616 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
15617 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
15618 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
15619 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
15620
15621 /* old command */
15622 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
15623 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
15624 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
15625 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
15626#endif /* HAVE_IPV6 */
15627
15628 install_element (BGP_NODE, &bgp_distance_cmd);
15629 install_element (BGP_NODE, &no_bgp_distance_cmd);
15630 install_element (BGP_NODE, &no_bgp_distance2_cmd);
15631 install_element (BGP_NODE, &bgp_distance_source_cmd);
15632 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
15633 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
15634 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
15635
15636 install_element (BGP_NODE, &bgp_damp_set_cmd);
15637 install_element (BGP_NODE, &bgp_damp_set2_cmd);
15638 install_element (BGP_NODE, &bgp_damp_set3_cmd);
15639 install_element (BGP_NODE, &bgp_damp_unset_cmd);
15640 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
15641 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
15642 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
15643 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
15644 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
15645 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
c8f3fe30
PJ
15646
15647 /* Deprecated AS-Pathlimit commands */
15648 install_element (BGP_NODE, &bgp_network_ttl_cmd);
15649 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
15650 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
15651 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
15652 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
15653 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
15654
15655 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
15656 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
15657 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
15658 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
15659 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
15660 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
15661
15662 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
15663 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
15664 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
15665 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
15666 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
15667 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
15668
15669 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
15670 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
15671 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
15672 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
15673 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
15674 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
15675
15676 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
15677 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
15678 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
15679 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
15680 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
15681 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
15682
15683 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
15684 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
15685 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
15686 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
15687 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
15688 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
3bde17f1
PJ
15689
15690#ifdef HAVE_IPV6
c8f3fe30
PJ
15691 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
15692 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
3bde17f1 15693#endif
718e3744 15694}
228da428
CC
15695
15696void
15697bgp_route_finish (void)
15698{
15699 bgp_table_unlock (bgp_distance_table);
15700 bgp_distance_table = NULL;
15701}