]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_route.c
When a route-reflector is configured with "next-hop self" towards an IBGP
[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
4125bb67 67struct 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,
ffd0c037 930 afi_t afi, safi_t safi, const 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);
98a4a44e
DS
946
947 if (rmap == NULL)
948 return RMAP_DENY;
0b16f239
DS
949 }
950 else
951 {
952 if (ROUTE_MAP_IN_NAME(filter))
98a4a44e
DS
953 {
954 rmap = ROUTE_MAP_IN (filter);
955
956 if (rmap == NULL)
957 return RMAP_DENY;
958 }
0b16f239
DS
959 }
960
718e3744 961 /* Route map apply. */
0b16f239 962 if (rmap)
718e3744 963 {
964 /* Duplicate current value to new strucutre for modification. */
965 info.peer = peer;
966 info.attr = attr;
967
ac41b2a2 968 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
969
718e3744 970 /* Apply BGP route map to the attribute. */
0b16f239
DS
971 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
972
973 peer->rmap_type = 0;
974
975 if (ret == RMAP_DENYMATCH)
976 {
977 /* Free newly generated AS path and community by route-map. */
978 bgp_attr_flush (attr);
979 return RMAP_DENY;
980 }
981 }
982 return RMAP_PERMIT;
983}
984
985static int
986bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
ffd0c037 987 afi_t afi, safi_t safi, const char *rmap_name)
0b16f239
DS
988{
989 struct bgp_filter *filter;
990 struct bgp_info info;
991 route_map_result_t ret;
992 struct route_map *rmap = NULL;
993
994 filter = &peer->filter[afi][safi];
995
996 /* Apply default weight value. */
997 if (peer->weight)
998 (bgp_attr_extra_get (attr))->weight = peer->weight;
999
1000 if (rmap_name)
1001 {
1002 rmap = route_map_lookup_by_name(rmap_name);
98a4a44e
DS
1003
1004 if (rmap == NULL)
1005 return RMAP_DENY;
0b16f239
DS
1006 }
1007 else
1008 {
1009 if (ROUTE_MAP_OUT_NAME(filter))
98a4a44e
DS
1010 {
1011 rmap = ROUTE_MAP_OUT (filter);
1012
1013 if (rmap == NULL)
1014 return RMAP_DENY;
1015 }
0b16f239
DS
1016 }
1017
1018 /* Route map apply. */
1019 if (rmap)
1020 {
1021 /* Duplicate current value to new strucutre for modification. */
1022 info.peer = peer;
1023 info.attr = attr;
1024
1025 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1026
1027 /* Apply BGP route map to the attribute. */
1028 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
ac41b2a2 1029
1030 peer->rmap_type = 0;
1031
718e3744 1032 if (ret == RMAP_DENYMATCH)
c460e572
DL
1033 /* caller has multiple error paths with bgp_attr_flush() */
1034 return RMAP_DENY;
718e3744 1035 }
1036 return RMAP_PERMIT;
1037}
6b0655a2 1038
94f2b392 1039static int
fee0f4c6 1040bgp_export_modifier (struct peer *rsclient, struct peer *peer,
1041 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
1042{
1043 struct bgp_filter *filter;
1044 struct bgp_info info;
1045 route_map_result_t ret;
1046
1047 filter = &peer->filter[afi][safi];
1048
1049 /* Route map apply. */
1050 if (ROUTE_MAP_EXPORT_NAME (filter))
1051 {
1052 /* Duplicate current value to new strucutre for modification. */
1053 info.peer = rsclient;
1054 info.attr = attr;
1055
1056 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
1057
1058 /* Apply BGP route map to the attribute. */
1059 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
1060
1061 rsclient->rmap_type = 0;
1062
1063 if (ret == RMAP_DENYMATCH)
1064 {
1065 /* Free newly generated AS path and community by route-map. */
1066 bgp_attr_flush (attr);
1067 return RMAP_DENY;
1068 }
1069 }
1070 return RMAP_PERMIT;
1071}
1072
94f2b392 1073static int
fee0f4c6 1074bgp_import_modifier (struct peer *rsclient, struct peer *peer,
1075 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
1076{
1077 struct bgp_filter *filter;
1078 struct bgp_info info;
1079 route_map_result_t ret;
1080
1081 filter = &rsclient->filter[afi][safi];
1082
1083 /* Apply default weight value. */
fb982c25
PJ
1084 if (peer->weight)
1085 (bgp_attr_extra_get (attr))->weight = peer->weight;
fee0f4c6 1086
1087 /* Route map apply. */
1088 if (ROUTE_MAP_IMPORT_NAME (filter))
1089 {
1090 /* Duplicate current value to new strucutre for modification. */
1091 info.peer = peer;
1092 info.attr = attr;
1093
1094 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
1095
1096 /* Apply BGP route map to the attribute. */
1097 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
1098
1099 peer->rmap_type = 0;
1100
1101 if (ret == RMAP_DENYMATCH)
1102 {
1103 /* Free newly generated AS path and community by route-map. */
1104 bgp_attr_flush (attr);
1105 return RMAP_DENY;
1106 }
1107 }
1108 return RMAP_PERMIT;
1109}
6b0655a2 1110
5000f21c
DS
1111
1112/* If this is an EBGP peer with remove-private-AS */
ffd0c037 1113static void
5000f21c
DS
1114bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
1115 struct peer *peer, struct attr *attr)
1116{
1117 if (peer->sort == BGP_PEER_EBGP &&
1118 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS))
1119 {
1120 // Take action on the entire aspath
1121 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
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
1126 // The entire aspath consists of private ASNs so create an empty aspath
1127 else if (aspath_private_as_check (attr->aspath))
1128 attr->aspath = aspath_empty_get ();
1129
1130 // There are some public and some private ASNs, remove the private ASNs
1131 else
1132 attr->aspath = aspath_remove_private_asns (attr->aspath);
1133 }
1134
1135 // 'all' was not specified so the entire aspath must be private ASNs
1136 // for us to do anything
1137 else if (aspath_private_as_check (attr->aspath))
1138 {
1139 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
1140 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1141 else
1142 attr->aspath = aspath_empty_get ();
1143 }
1144 }
1145}
1146
c7122e14
DS
1147/* If this is an EBGP peer with as-override */
1148static void
1149bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
1150 struct peer *peer, struct attr *attr)
1151{
1152 if (peer->sort == BGP_PEER_EBGP &&
1153 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
1154 {
1155 if (aspath_single_asn_check (attr->aspath, peer->as))
1156 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
1157 }
1158}
1159
3f9c7369
DS
1160static void
1161subgroup_announce_reset_nhop (u_char family, struct attr *attr)
1162{
1163 if (family == AF_INET)
1164 attr->nexthop.s_addr = 0;
1165#ifdef HAVE_IPV6
1166 if (family == AF_INET6)
1167 memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
1168#endif
1169}
1170
1171int
1172subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp,
1173 struct prefix *p, struct attr *attr)
1174{
1175 struct bgp_filter *filter;
1176 struct peer *from;
1177 struct peer *peer;
1178 struct peer *onlypeer;
1179 struct bgp *bgp;
1180 struct attr *riattr;
1181 struct peer_af *paf;
1182 char buf[SU_ADDRSTRLEN];
1183 int ret;
1184 int transparent;
1185 int reflect;
1186 afi_t afi;
1187 safi_t safi;
1188
1189 if (DISABLE_BGP_ANNOUNCE)
1190 return 0;
1191
1192 afi = SUBGRP_AFI(subgrp);
1193 safi = SUBGRP_SAFI(subgrp);
1194 peer = SUBGRP_PEER(subgrp);
1195 onlypeer = NULL;
1196 if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL))
1197 onlypeer = SUBGRP_PFIRST(subgrp)->peer;
1198
1199 from = ri->peer;
1200 filter = &peer->filter[afi][safi];
1201 bgp = SUBGRP_INST(subgrp);
1202 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1203
1204 /* Aggregate-address suppress check. */
1205 if (ri->extra && ri->extra->suppress)
1206 if (! UNSUPPRESS_MAP_NAME (filter))
1207 {
1208 return 0;
1209 }
1210
1211 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
1212 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1213 {
1214 return 0;
1215 }
1216
1217 /* Do not send back route to sender. */
1218 if (onlypeer && from == onlypeer)
1219 {
1220 return 0;
1221 }
1222
4125bb67
DS
1223 /* Do not send the default route in the BGP table if the neighbor is
1224 * configured for default-originate */
1225 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
1226 {
1227 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1228 return 0;
1229#ifdef HAVE_IPV6
1230 else if (p->family == AF_INET6 && p->prefixlen == 0)
1231 return 0;
1232#endif /* HAVE_IPV6 */
1233 }
1234
3f9c7369
DS
1235 /* Transparency check. */
1236 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1237 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1238 transparent = 1;
1239 else
1240 transparent = 0;
1241
1242 /* If community is not disabled check the no-export and local. */
1243 if (! transparent && bgp_community_filter (peer, riattr))
1244 {
1245 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1246 zlog_debug ("subgrpannouncecheck: community filter check fail");
1247 return 0;
1248 }
1249
1250 /* If the attribute has originator-id and it is same as remote
1251 peer's id. */
1252 if (onlypeer &&
1253 riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) &&
1254 (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id)))
1255 {
1256 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1257 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as "
1258 "remote router-id",
1259 onlypeer->host,
1260 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1261 p->prefixlen);
1262 return 0;
1263 }
1264
1265 /* ORF prefix-list filter check */
1266 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1267 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1268 || CHECK_FLAG (peer->af_cap[afi][safi],
1269 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1270 if (peer->orf_plist[afi][safi])
1271 {
1272 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1273 {
1274 return 0;
1275 }
1276 }
1277
1278 /* Output filter check. */
1279 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1280 {
1281 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1282 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1283 peer->host,
1284 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1285 p->prefixlen);
1286 return 0;
1287 }
1288
1289#ifdef BGP_SEND_ASPATH_CHECK
1290 /* AS path loop check. */
1291 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
1292 {
1293 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1294 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1295 "that is part of AS path.",
1296 onlypeer->host, onlypeer->as);
1297 return 0;
1298 }
1299#endif /* BGP_SEND_ASPATH_CHECK */
1300
1301 /* If we're a CONFED we need to loop check the CONFED ID too */
1302 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1303 {
1304 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1305 {
1306 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1307 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u"
1308 " is AS path.",
1309 peer->host,
1310 bgp->confed_id);
1311 return 0;
1312 }
1313 }
1314
1315 /* Route-Reflect check. */
1316 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1317 reflect = 1;
1318 else
1319 reflect = 0;
1320
1321 /* IBGP reflection check. */
1322 if (reflect)
1323 {
1324 /* A route from a Client peer. */
1325 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1326 {
1327 /* Reflect to all the Non-Client peers and also to the
1328 Client peers other than the originator. Originator check
1329 is already done. So there is noting to do. */
1330 /* no bgp client-to-client reflection check. */
1331 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1332 if (CHECK_FLAG (peer->af_flags[afi][safi],
1333 PEER_FLAG_REFLECTOR_CLIENT))
1334 return 0;
1335 }
1336 else
1337 {
1338 /* A route from a Non-client peer. Reflect to all other
1339 clients. */
1340 if (! CHECK_FLAG (peer->af_flags[afi][safi],
1341 PEER_FLAG_REFLECTOR_CLIENT))
1342 return 0;
1343 }
1344 }
1345
1346 /* For modify attribute, copy it to temporary structure. */
1347 bgp_attr_dup (attr, riattr);
1348
1349 /* If local-preference is not set. */
1350 if ((peer->sort == BGP_PEER_IBGP
1351 || peer->sort == BGP_PEER_CONFED)
1352 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1353 {
1354 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1355 attr->local_pref = bgp->default_local_pref;
1356 }
1357
1358 /* If originator-id is not set and the route is to be reflected,
1359 set the originator id */
1360 if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1361 {
1362 attr->extra = bgp_attr_extra_get(attr);
1363 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1364 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1365 }
1366
1367 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1368 if (peer->sort == BGP_PEER_EBGP
1369 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1370 {
1371 if (ri->peer != bgp->peer_self && ! transparent
1372 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1373 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1374 }
1375
1376 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1377 * in announce check, only certain flags and length (or number of nexthops
1378 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1379 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1380 * Typically, the source nexthop in the attribute is preserved but in the
1381 * scenarios where we know it will always be overwritten, we reset the
1382 * nexthop to "0" in an attempt to achieve better Update packing. An
1383 * example of this is when a prefix from each of 2 IBGP peers needs to be
1384 * announced to an EBGP peer (and they have the same attributes barring
1385 * their nexthop).
1386 */
1387 if (reflect)
1388 SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
1389
1390#ifdef HAVE_IPV6
3811f1e2
DS
1391 /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if
1392 * the peer (group) is configured to receive link-local nexthop unchanged
1393 * and it is available in the prefix OR we're not reflecting the route and
1394 * the peer (group) to whom we're going to announce is on a shared network
3f9c7369 1395 */
8a92a8a0 1396 if (p->family == AF_INET6 || peer_cap_enhe(peer))
3f9c7369 1397 {
801a9bcc 1398 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
3811f1e2
DS
1399 if ((CHECK_FLAG (peer->af_flags[afi][safi],
1400 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1401 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) ||
1402 (!reflect && peer->shared_network))
3f9c7369 1403 {
3811f1e2 1404 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
3f9c7369
DS
1405 }
1406
3811f1e2
DS
1407 /* Clear off link-local nexthop in source, whenever it is not needed to
1408 * ensure more prefixes share the same attribute for announcement.
3f9c7369
DS
1409 */
1410 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1411 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1412 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1413 }
1414#endif /* HAVE_IPV6 */
1415
1416 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1417 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1418
1419 /* Route map & unsuppress-map apply. */
1420 if (ROUTE_MAP_OUT_NAME (filter)
1421 || (ri->extra && ri->extra->suppress) )
1422 {
1423 struct bgp_info info;
1424 struct attr dummy_attr;
1425 struct attr_extra dummy_extra;
1426
1427 dummy_attr.extra = &dummy_extra;
1428
1429 info.peer = peer;
1430 info.attr = attr;
316e074d
DS
1431 /* don't confuse inbound and outbound setting */
1432 RESET_FLAG(attr->rmap_change_flags);
3f9c7369
DS
1433
1434 /*
1435 * The route reflector is not allowed to modify the attributes
1436 * of the reflected IBGP routes unless explicitly allowed.
1437 */
1438 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1439 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1440 {
1441 bgp_attr_dup (&dummy_attr, attr);
1442 info.attr = &dummy_attr;
1443 }
1444
1445 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1446
1447 if (ri->extra && ri->extra->suppress)
1448 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1449 else
1450 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1451
1452 peer->rmap_type = 0;
1453
1454 if (ret == RMAP_DENYMATCH)
1455 {
1456 bgp_attr_flush (attr);
1457 return 0;
1458 }
1459 }
1460
1461 /* After route-map has been applied, we check to see if the nexthop to
1462 * be carried in the attribute (that is used for the announcement) can
1463 * be cleared off or not. We do this in all cases where we would be
1464 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1465 * the global nexthop here; the link-local nexthop would have been cleared
1466 * already, and if not, it is required by the update formation code.
1467 * Also see earlier comments in this function.
3811f1e2
DS
1468 */
1469 /*
1470 * If route-map has performed some operation on the nexthop or the peer
1471 * configuration says to pass it unchanged, we cannot reset the nexthop
1472 * here, so only attempt to do it if these aren't true. Note that the
1473 * route-map handler itself might have cleared the nexthop, if for example,
1474 * it is configured as 'peer-address'.
3f9c7369 1475 */
3811f1e2
DS
1476 if (!bgp_rmap_nhop_changed(attr->rmap_change_flags,
1477 riattr->rmap_change_flags) &&
1478 !transparent &&
1479 !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
1480
3f9c7369 1481 {
3811f1e2 1482 /* We can reset the nexthop, if setting (or forcing) it to 'self' */
3f9c7369
DS
1483 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF))
1484 {
1485 if (!reflect ||
1486 CHECK_FLAG (peer->af_flags[afi][safi],
d998c0f7 1487 PEER_FLAG_NEXTHOP_SELF_ALL))
3811f1e2
DS
1488 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ?
1489 AF_INET6 : p->family), attr);
3f9c7369
DS
1490 }
1491 else if (peer->sort == BGP_PEER_EBGP)
1492 {
3811f1e2
DS
1493 /* Can also reset the nexthop if announcing to EBGP, but only if
1494 * no peer in the subgroup is on a shared subnet.
1495 * Note: 3rd party nexthop currently implemented for IPv4 only.
1496 */
3f9c7369
DS
1497 SUBGRP_FOREACH_PEER (subgrp, paf)
1498 {
1499 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1500 break;
1501 }
1502 if (!paf)
8a92a8a0 1503 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr);
3f9c7369
DS
1504 }
1505 }
1506
1507 return 1;
1508}
1509
94f2b392 1510static int
3f9c7369
DS
1511subgroup_announce_check_rsclient (struct bgp_info *ri,
1512 struct update_subgroup *subgrp,
1513 struct prefix *p, struct attr *attr)
fee0f4c6 1514{
1515 int ret;
1516 char buf[SU_ADDRSTRLEN];
1517 struct bgp_filter *filter;
1518 struct bgp_info info;
1519 struct peer *from;
3f9c7369
DS
1520 struct peer *rsclient;
1521 struct peer *onlypeer;
0b597ef0 1522 struct attr *riattr;
5000f21c 1523 struct bgp *bgp;
3f9c7369
DS
1524 afi_t afi;
1525 safi_t safi;
1526
1527 if (DISABLE_BGP_ANNOUNCE)
1528 return 0;
fee0f4c6 1529
3f9c7369
DS
1530 afi = SUBGRP_AFI(subgrp);
1531 safi = SUBGRP_SAFI(subgrp);
1532 rsclient = SUBGRP_PEER(subgrp);
1533 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1534 (SUBGRP_PFIRST(subgrp))->peer : NULL);
fee0f4c6 1535 from = ri->peer;
1536 filter = &rsclient->filter[afi][safi];
5000f21c 1537 bgp = rsclient->bgp;
0b597ef0 1538 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
fee0f4c6 1539
fee0f4c6 1540 /* Do not send back route to sender. */
3f9c7369 1541 if (onlypeer && (from == onlypeer))
fee0f4c6 1542 return 0;
1543
1544 /* Aggregate-address suppress check. */
fb982c25 1545 if (ri->extra && ri->extra->suppress)
fee0f4c6 1546 if (! UNSUPPRESS_MAP_NAME (filter))
1547 return 0;
1548
1549 /* Default route check. */
840fced9 1550 if (subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
fee0f4c6 1551 {
1552 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1553 return 0;
1554#ifdef HAVE_IPV6
1555 else if (p->family == AF_INET6 && p->prefixlen == 0)
1556 return 0;
1557#endif /* HAVE_IPV6 */
1558 }
1559
1560 /* If the attribute has originator-id and it is same as remote
1561 peer's id. */
3f9c7369 1562 if (onlypeer && riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
fee0f4c6 1563 {
3f9c7369 1564 if (IPV4_ADDR_SAME (&onlypeer->remote_id,
0b597ef0 1565 &riattr->extra->originator_id))
fee0f4c6 1566 {
3f9c7369 1567 if (bgp_debug_update(rsclient, p, subgrp->update_group, 0))
16286195 1568 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as remote router-id",
3f9c7369 1569 onlypeer->host,
16286195
DS
1570 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1571 p->prefixlen);
fee0f4c6 1572 return 0;
1573 }
1574 }
1575
1576 /* ORF prefix-list filter check */
1577 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1578 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1579 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1580 if (rsclient->orf_plist[afi][safi])
1581 {
1582 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1583 return 0;
1584 }
1585
1586 /* Output filter check. */
0b597ef0 1587 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
fee0f4c6 1588 {
3f9c7369 1589 if (bgp_debug_update(rsclient, p, subgrp->update_group, 0))
16286195
DS
1590 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1591 rsclient->host,
1592 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1593 p->prefixlen);
fee0f4c6 1594 return 0;
1595 }
1596
1597#ifdef BGP_SEND_ASPATH_CHECK
1598 /* AS path loop check. */
3f9c7369 1599 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
fee0f4c6 1600 {
3f9c7369 1601 if (bgp_debug_update(rsclient, p, subgrp->update_group, 0))
16286195 1602 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
3f9c7369 1603 onlypeer->host, onlypeer->as);
fee0f4c6 1604 return 0;
1605 }
1606#endif /* BGP_SEND_ASPATH_CHECK */
1607
1608 /* For modify attribute, copy it to temporary structure. */
0b597ef0 1609 bgp_attr_dup (attr, riattr);
fee0f4c6 1610
1611 /* next-hop-set */
8a92a8a0
DS
1612 if ((p->family == AF_INET && !peer_cap_enhe(rsclient)
1613 && attr->nexthop.s_addr == 0)
fee0f4c6 1614#ifdef HAVE_IPV6
8a92a8a0 1615 || ((p->family == AF_INET6 || peer_cap_enhe(rsclient)) &&
fb982c25 1616 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
fee0f4c6 1617#endif /* HAVE_IPV6 */
1618 )
1619 {
1620 /* Set IPv4 nexthop. */
1621 if (p->family == AF_INET)
1622 {
1623 if (safi == SAFI_MPLS_VPN)
fb982c25 1624 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
fee0f4c6 1625 IPV4_MAX_BYTELEN);
8a92a8a0 1626 else if (!peer_cap_enhe(rsclient))
fee0f4c6 1627 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1628 }
1629#ifdef HAVE_IPV6
1630 /* Set IPv6 nexthop. */
8a92a8a0 1631 if (p->family == AF_INET6 || peer_cap_enhe(rsclient))
fee0f4c6 1632 {
1633 /* IPv6 global nexthop must be included. */
fb982c25 1634 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
fee0f4c6 1635 IPV6_MAX_BYTELEN);
801a9bcc 1636 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 1637 }
1638#endif /* HAVE_IPV6 */
1639 }
1640
1641#ifdef HAVE_IPV6
8a92a8a0 1642 if (p->family == AF_INET6 || peer_cap_enhe(rsclient))
fee0f4c6 1643 {
fb982c25 1644 struct attr_extra *attre = attr->extra;
558d1fec 1645
fee0f4c6 1646 /* Left nexthop_local unchanged if so configured. */
3f9c7369 1647 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
fee0f4c6 1648 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1649 {
fb982c25 1650 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
801a9bcc 1651 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
fee0f4c6 1652 else
801a9bcc 1653 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 1654 }
3f9c7369 1655
fee0f4c6 1656 /* Default nexthop_local treatment for RS-Clients */
3f9c7369
DS
1657 else
1658 {
1659 /* Announcer and RS-Client are both in the same network */
fee0f4c6 1660 if (rsclient->shared_network && from->shared_network &&
1661 (rsclient->ifindex == from->ifindex))
1662 {
fb982c25 1663 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
801a9bcc 1664 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
fee0f4c6 1665 else
801a9bcc 1666 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 1667 }
1668
1669 /* Set link-local address for shared network peer. */
1670 else if (rsclient->shared_network
1671 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1672 {
fb982c25 1673 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
fee0f4c6 1674 IPV6_MAX_BYTELEN);
801a9bcc 1675 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
fee0f4c6 1676 }
1677
1678 else
801a9bcc 1679 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 1680 }
1681
1682 }
1683#endif /* HAVE_IPV6 */
1684
5000f21c 1685 bgp_peer_remove_private_as(bgp, afi, safi, rsclient, attr);
c7122e14 1686 bgp_peer_as_override(bgp, afi, safi, rsclient, attr);
fee0f4c6 1687
1688 /* Route map & unsuppress-map apply. */
fb982c25 1689 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
fee0f4c6 1690 {
1691 info.peer = rsclient;
1692 info.attr = attr;
1693
1694 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1695
fb982c25 1696 if (ri->extra && ri->extra->suppress)
fee0f4c6 1697 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1698 else
1699 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1700
1701 rsclient->rmap_type = 0;
1702
1703 if (ret == RMAP_DENYMATCH)
1704 {
1705 bgp_attr_flush (attr);
1706 return 0;
1707 }
1708 }
1709
1710 return 1;
1711}
1712
1713struct bgp_info_pair
1714{
1715 struct bgp_info *old;
1716 struct bgp_info *new;
1717};
1718
94f2b392 1719static void
96450faf
JB
1720bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1721 struct bgp_maxpaths_cfg *mpath_cfg,
1722 struct bgp_info_pair *result)
718e3744 1723{
718e3744 1724 struct bgp_info *new_select;
1725 struct bgp_info *old_select;
fee0f4c6 1726 struct bgp_info *ri;
718e3744 1727 struct bgp_info *ri1;
1728 struct bgp_info *ri2;
b40d939b 1729 struct bgp_info *nextri = NULL;
9fbdd100 1730 int paths_eq, do_mpath, debug;
96450faf 1731 struct list mp_list;
9fbdd100 1732 char pfx_buf[INET6_ADDRSTRLEN];
96450faf
JB
1733
1734 bgp_mp_list_init (&mp_list);
1735 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1736 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1737
9fbdd100
DS
1738 debug = bgp_debug_bestpath(&rn->p);
1739
1740 if (debug)
1741 prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf));
1742
718e3744 1743 /* bgp deterministic-med */
1744 new_select = NULL;
1745 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1746 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1747 {
1748 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1749 continue;
1750 if (BGP_INFO_HOLDDOWN (ri1))
1751 continue;
2fed8887
DS
1752 if (ri1->peer && ri1->peer != bgp->peer_self)
1753 if (ri1->peer->status != Established)
1754 continue;
718e3744 1755
1756 new_select = ri1;
6918e74b 1757 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
718e3744 1758 if (ri1->next)
1759 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1760 {
1761 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1762 continue;
1763 if (BGP_INFO_HOLDDOWN (ri2))
1764 continue;
2fed8887
DS
1765 if (ri2->peer &&
1766 ri2->peer != bgp->peer_self &&
1767 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1768 if (ri2->peer->status != Established)
1769 continue;
718e3744 1770
1771 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1772 || aspath_cmp_left_confed (ri1->attr->aspath,
1773 ri2->attr->aspath))
1774 {
6918e74b
JB
1775 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1776 old_select = ri2;
5e242b0d 1777 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
9fbdd100 1778 mpath_cfg, debug, pfx_buf))
718e3744 1779 {
1a392d46 1780 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
718e3744 1781 new_select = ri2;
1782 }
1783
1a392d46 1784 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
718e3744 1785 }
1786 }
1a392d46
PJ
1787 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1788 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
718e3744 1789 }
1790
1791 /* Check old selected route and new selected route. */
1792 old_select = NULL;
1793 new_select = NULL;
b40d939b 1794 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
718e3744 1795 {
1796 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1797 old_select = ri;
1798
1799 if (BGP_INFO_HOLDDOWN (ri))
b40d939b 1800 {
1801 /* reap REMOVED routes, if needs be
1802 * selected route must stay for a while longer though
1803 */
1804 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1805 && (ri != old_select))
1806 bgp_info_reap (rn, ri);
1807
1808 continue;
1809 }
718e3744 1810
2fed8887
DS
1811 if (ri->peer &&
1812 ri->peer != bgp->peer_self &&
1813 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1814 if (ri->peer->status != Established)
1815 continue;
1816
718e3744 1817 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1818 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1819 {
1a392d46 1820 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
718e3744 1821 continue;
1822 }
1a392d46
PJ
1823 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1824 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
718e3744 1825
9fbdd100 1826 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
96450faf
JB
1827 {
1828 new_select = ri;
96450faf 1829 }
718e3744 1830 }
b40d939b 1831
f4eeff72
DS
1832 /* Now that we know which path is the bestpath see if any of the other paths
1833 * qualify as multipaths
1834 */
1835 if (do_mpath && new_select)
1836 {
9fbdd100
DS
1837 if (debug)
1838 zlog_debug("%s: path %s is the bestpath, now find multipaths",
1839 pfx_buf, new_select->peer->host);
1840
f4eeff72
DS
1841 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1842 {
1843 if (ri == new_select)
1844 {
9fbdd100
DS
1845 if (debug)
1846 zlog_debug("%s: path %s is the bestpath, add to the multipath list",
1847 pfx_buf, ri->peer->host);
f4eeff72
DS
1848 bgp_mp_list_add (&mp_list, ri);
1849 continue;
1850 }
1851
1852 if (BGP_INFO_HOLDDOWN (ri))
1853 continue;
1854
1855 if (ri->peer &&
1856 ri->peer != bgp->peer_self &&
1857 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1858 if (ri->peer->status != Established)
1859 continue;
1860
1861 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1862 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1863 continue;
1864
9fbdd100 1865 bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
f4eeff72
DS
1866
1867 if (paths_eq)
1868 {
9fbdd100
DS
1869 if (debug)
1870 zlog_debug("%s: %s path is equivalent to the bestpath, add to the multipath list",
1871 pfx_buf, ri->peer->host);
f4eeff72
DS
1872 bgp_mp_list_add (&mp_list, ri);
1873 }
1874 }
1875 }
fee0f4c6 1876
6918e74b
JB
1877 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1878 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
96450faf 1879
0b597ef0 1880 bgp_info_mpath_aggregate_update (new_select, old_select);
96450faf
JB
1881 bgp_mp_list_clear (&mp_list);
1882
1883 result->old = old_select;
1884 result->new = new_select;
1885
1886 return;
fee0f4c6 1887}
1888
3f9c7369
DS
1889/*
1890 * A new route/change in bestpath of an existing route. Evaluate the path
1891 * for advertisement to the subgroup.
1892 */
1893int
1894subgroup_process_announce_selected (struct update_subgroup *subgrp,
1895 struct bgp_info *selected,
1896 struct bgp_node *rn)
9eda90ce 1897{
fee0f4c6 1898 struct prefix *p;
3f9c7369 1899 struct peer *onlypeer;
558d1fec
JBD
1900 struct attr attr;
1901 struct attr_extra extra;
3f9c7369
DS
1902 afi_t afi;
1903 safi_t safi;
fee0f4c6 1904
1905 p = &rn->p;
3f9c7369
DS
1906 afi = SUBGRP_AFI(subgrp);
1907 safi = SUBGRP_SAFI(subgrp);
1908 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1909 (SUBGRP_PFIRST(subgrp))->peer : NULL);
718e3744 1910
9eda90ce 1911 /* First update is deferred until ORF or ROUTE-REFRESH is received */
3f9c7369
DS
1912 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
1913 PEER_STATUS_ORF_WAIT_REFRESH))
fee0f4c6 1914 return 0;
718e3744 1915
558d1fec
JBD
1916 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1917 attr.extra = &extra;
1918
67174041 1919 switch (bgp_node_table (rn)->type)
fee0f4c6 1920 {
1921 case BGP_TABLE_MAIN:
3f9c7369 1922 /* Announcement to the subgroup. If the route is filtered,
718e3744 1923 withdraw it. */
3f9c7369
DS
1924 if (selected && subgroup_announce_check(selected, subgrp, p, &attr))
1925 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
fee0f4c6 1926 else
4125bb67 1927 bgp_adj_out_unset_subgroup(rn, subgrp, 1);
3f9c7369 1928
fee0f4c6 1929 break;
1930 case BGP_TABLE_RSCLIENT:
3f9c7369 1931 /* Announcement to peer->conf. If the route is filtered,
fee0f4c6 1932 withdraw it. */
3f9c7369
DS
1933 if (selected &&
1934 subgroup_announce_check_rsclient (selected, subgrp, p, &attr))
1935 bgp_adj_out_set_subgroup (rn, subgrp, &attr, selected);
9eda90ce 1936 else
4125bb67 1937 bgp_adj_out_unset_subgroup(rn, subgrp, 1);
fee0f4c6 1938 break;
1939 }
558d1fec 1940
fee0f4c6 1941 return 0;
200df115 1942}
fee0f4c6 1943
3f9c7369 1944struct bgp_process_queue
fee0f4c6 1945{
200df115 1946 struct bgp *bgp;
1947 struct bgp_node *rn;
1948 afi_t afi;
1949 safi_t safi;
1950};
1951
1952static wq_item_status
0fb58d5d 1953bgp_process_rsclient (struct work_queue *wq, void *data)
200df115 1954{
0fb58d5d 1955 struct bgp_process_queue *pq = data;
200df115 1956 struct bgp *bgp = pq->bgp;
1957 struct bgp_node *rn = pq->rn;
1958 afi_t afi = pq->afi;
1959 safi_t safi = pq->safi;
fee0f4c6 1960 struct bgp_info *new_select;
1961 struct bgp_info *old_select;
1962 struct bgp_info_pair old_and_new;
1eb8ef25 1963 struct listnode *node, *nnode;
cb1faec9 1964 struct peer *rsclient;
3f9c7369
DS
1965 struct peer_af *paf;
1966 struct update_subgroup *subgrp;
cb1faec9
DS
1967
1968 /* Is it end of initial update? (after startup) */
1969 if (!rn)
1970 {
4a16ae86
DS
1971 /* This is just to keep the display sane in case all the peers are
1972 rsclients only */
1973 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1974 sizeof(bgp->update_delay_zebra_resume_time));
1975
1976 bgp->rsclient_peers_update_hold = 0;
cb1faec9
DS
1977 bgp_start_routeadv(bgp);
1978 return WQ_SUCCESS;
1979 }
1980
1981 rsclient = bgp_node_table (rn)->owner;
1982
fee0f4c6 1983 /* Best path selection. */
96450faf 1984 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 1985 new_select = old_and_new.new;
1986 old_select = old_and_new.old;
1987
200df115 1988 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1989 {
228da428
CC
1990 if (rsclient->group)
1991 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1992 {
1993 /* Nothing to do. */
1994 if (old_select && old_select == new_select)
1995 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1996 continue;
1997
1998 if (old_select)
1999 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
2000 if (new_select)
2001 {
2002 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
2003 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d
JB
2004 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
2005 }
228da428 2006
3f9c7369
DS
2007 paf = peer_af_find(rsclient, afi, safi);
2008 assert(paf);
2009 subgrp = PAF_SUBGRP(paf);
2010 if (!subgrp) /* not an established session */
2011 continue;
2012 subgroup_process_announce_selected (subgrp, new_select, rn);
228da428 2013 }
200df115 2014 }
2015 else
2016 {
b7395791 2017 if (old_select)
1a392d46 2018 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
b7395791 2019 if (new_select)
2020 {
1a392d46
PJ
2021 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
2022 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 2023 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
b7395791 2024 }
3f9c7369
DS
2025 paf = peer_af_find(rsclient, afi, safi);
2026 if (paf && (subgrp = PAF_SUBGRP(paf))) /* if an established session */
2027 subgroup_process_announce_selected (subgrp, new_select, rn);
200df115 2028 }
2029
b40d939b 2030 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
2031 bgp_info_reap (rn, old_select);
3f9c7369 2032
200df115 2033 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2034 return WQ_SUCCESS;
fee0f4c6 2035}
2036
200df115 2037static wq_item_status
0fb58d5d 2038bgp_process_main (struct work_queue *wq, void *data)
200df115 2039{
0fb58d5d 2040 struct bgp_process_queue *pq = data;
200df115 2041 struct bgp *bgp = pq->bgp;
2042 struct bgp_node *rn = pq->rn;
2043 afi_t afi = pq->afi;
2044 safi_t safi = pq->safi;
2045 struct prefix *p = &rn->p;
fee0f4c6 2046 struct bgp_info *new_select;
2047 struct bgp_info *old_select;
2048 struct bgp_info_pair old_and_new;
cb1faec9
DS
2049
2050 /* Is it end of initial update? (after startup) */
2051 if (!rn)
2052 {
4a16ae86
DS
2053 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
2054 sizeof(bgp->update_delay_zebra_resume_time));
2055
2056 bgp->main_zebra_update_hold = 0;
2057 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2058 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2059 {
2060 bgp_zebra_announce_table(bgp, afi, safi);
2061 }
2062 bgp->main_peers_update_hold = 0;
2063
cb1faec9
DS
2064 bgp_start_routeadv(bgp);
2065 return WQ_SUCCESS;
2066 }
2067
fee0f4c6 2068 /* Best path selection. */
96450faf 2069 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 2070 old_select = old_and_new.old;
2071 new_select = old_and_new.new;
2072
2073 /* Nothing to do. */
8ad7271d 2074 if (old_select && old_select == new_select && !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR))
fee0f4c6 2075 {
2076 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
200df115 2077 {
8196f13d
JB
2078 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
2079 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
73ac8160 2080 bgp_zebra_announce (p, old_select, bgp, afi, safi);
200df115 2081
8196f13d 2082 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
200df115 2083 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2084 return WQ_SUCCESS;
2085 }
fee0f4c6 2086 }
2087
8ad7271d
DS
2088 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
2089 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
2090
3f9c7369
DS
2091 /* bestpath has changed; bump version */
2092 if (old_select || new_select)
0de4848d
DS
2093 {
2094 bgp_bump_version(rn);
2095
2096 if (!bgp->t_rmap_def_originate_eval)
2097 {
2098 bgp_lock (bgp);
2099 THREAD_TIMER_ON(master, bgp->t_rmap_def_originate_eval,
2100 update_group_refresh_default_originate_route_map,
2101 bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER);
2102 }
2103 }
3f9c7369 2104
338b3424 2105 if (old_select)
1a392d46 2106 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
338b3424 2107 if (new_select)
2108 {
1a392d46
PJ
2109 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
2110 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 2111 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
338b3424 2112 }
2113
3f9c7369 2114 group_announce_route(bgp, afi, safi, rn, new_select);
718e3744 2115
2116 /* FIB update. */
5a616c08
B
2117 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
2118 ! bgp_option_check (BGP_OPT_NO_FIB)))
718e3744 2119 {
2120 if (new_select
2121 && new_select->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
2122 && (new_select->sub_type == BGP_ROUTE_NORMAL ||
2123 new_select->sub_type == BGP_ROUTE_AGGREGATE))
73ac8160 2124 bgp_zebra_announce (p, new_select, bgp, afi, safi);
718e3744 2125 else
2126 {
2127 /* Withdraw the route from the kernel. */
2128 if (old_select
2129 && old_select->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
2130 && (old_select->sub_type == BGP_ROUTE_NORMAL ||
2131 old_select->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 2132 bgp_zebra_withdraw (p, old_select, safi);
718e3744 2133 }
2134 }
b40d939b 2135
2136 /* Reap old select bgp_info, it it has been removed */
2137 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
2138 bgp_info_reap (rn, old_select);
2139
200df115 2140 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2141 return WQ_SUCCESS;
718e3744 2142}
2143
200df115 2144static void
0fb58d5d 2145bgp_processq_del (struct work_queue *wq, void *data)
200df115 2146{
0fb58d5d 2147 struct bgp_process_queue *pq = data;
cb1faec9
DS
2148 struct bgp_table *table;
2149
228da428 2150 bgp_unlock (pq->bgp);
cb1faec9
DS
2151 if (pq->rn)
2152 {
2153 table = bgp_node_table (pq->rn);
2154 bgp_unlock_node (pq->rn);
2155 bgp_table_unlock (table);
2156 }
200df115 2157 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
2158}
2159
f188f2c4 2160void
200df115 2161bgp_process_queue_init (void)
2162{
2163 bm->process_main_queue
2164 = work_queue_new (bm->master, "process_main_queue");
2165 bm->process_rsclient_queue
2166 = work_queue_new (bm->master, "process_rsclient_queue");
2167
2168 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
2169 {
2170 zlog_err ("%s: Failed to allocate work queue", __func__);
2171 exit (1);
2172 }
2173
2174 bm->process_main_queue->spec.workfunc = &bgp_process_main;
200df115 2175 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
838bbde0
PJ
2176 bm->process_main_queue->spec.max_retries = 0;
2177 bm->process_main_queue->spec.hold = 50;
d889623f
DS
2178 /* Use a higher yield value of 50ms for main queue processing */
2179 bm->process_main_queue->spec.yield = 50 * 1000L;
838bbde0
PJ
2180
2181 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
2182 sizeof (struct work_queue *));
2183 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
200df115 2184}
2185
2186void
fee0f4c6 2187bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
2188{
200df115 2189 struct bgp_process_queue *pqnode;
2190
2191 /* already scheduled for processing? */
2192 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
2193 return;
2194
2195 if ( (bm->process_main_queue == NULL) ||
2196 (bm->process_rsclient_queue == NULL) )
2197 bgp_process_queue_init ();
2198
2199 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2200 sizeof (struct bgp_process_queue));
2201 if (!pqnode)
2202 return;
228da428
CC
2203
2204 /* all unlocked in bgp_processq_del */
67174041 2205 bgp_table_lock (bgp_node_table (rn));
228da428 2206 pqnode->rn = bgp_lock_node (rn);
200df115 2207 pqnode->bgp = bgp;
228da428 2208 bgp_lock (bgp);
200df115 2209 pqnode->afi = afi;
2210 pqnode->safi = safi;
2211
67174041 2212 switch (bgp_node_table (rn)->type)
fee0f4c6 2213 {
200df115 2214 case BGP_TABLE_MAIN:
2215 work_queue_add (bm->process_main_queue, pqnode);
2216 break;
2217 case BGP_TABLE_RSCLIENT:
2218 work_queue_add (bm->process_rsclient_queue, pqnode);
2219 break;
fee0f4c6 2220 }
200df115 2221
07ff4dc4 2222 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
200df115 2223 return;
fee0f4c6 2224}
0a486e5f 2225
cb1faec9
DS
2226void
2227bgp_add_eoiu_mark (struct bgp *bgp, bgp_table_t type)
2228{
2229 struct bgp_process_queue *pqnode;
2230
2231 if ( (bm->process_main_queue == NULL) ||
2232 (bm->process_rsclient_queue == NULL) )
2233 bgp_process_queue_init ();
2234
2235 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2236 sizeof (struct bgp_process_queue));
2237 if (!pqnode)
2238 return;
2239
2240 pqnode->rn = NULL;
2241 pqnode->bgp = bgp;
2242 bgp_lock (bgp);
2243 switch (type)
2244 {
2245 case BGP_TABLE_MAIN:
2246 work_queue_add (bm->process_main_queue, pqnode);
2247 break;
2248 case BGP_TABLE_RSCLIENT:
2249 work_queue_add (bm->process_rsclient_queue, pqnode);
2250 break;
2251 }
2252
2253 return;
2254}
2255
94f2b392 2256static int
0a486e5f 2257bgp_maximum_prefix_restart_timer (struct thread *thread)
2258{
2259 struct peer *peer;
2260
2261 peer = THREAD_ARG (thread);
2262 peer->t_pmax_restart = NULL;
2263
16286195 2264 if (bgp_debug_neighbor_events(peer))
0a486e5f 2265 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
2266 peer->host);
2267
1ff9a340 2268 peer_clear (peer, NULL);
0a486e5f 2269
2270 return 0;
2271}
2272
718e3744 2273int
5228ad27 2274bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
2275 safi_t safi, int always)
718e3744 2276{
e0701b79 2277 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
2278 return 0;
2279
2280 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
718e3744 2281 {
e0701b79 2282 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
2283 && ! always)
2284 return 0;
2285
16286195
DS
2286 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
2287 "limit %ld", afi_safi_print (afi, safi), peer->host,
2288 peer->pcount[afi][safi], peer->pmax[afi][safi]);
e0701b79 2289 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2290
2291 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
2292 return 0;
2293
2294 {
5228ad27 2295 u_int8_t ndata[7];
e0701b79 2296
2297 if (safi == SAFI_MPLS_VPN)
42e6d745 2298 safi = SAFI_MPLS_LABELED_VPN;
5228ad27 2299
2300 ndata[0] = (afi >> 8);
2301 ndata[1] = afi;
2302 ndata[2] = safi;
2303 ndata[3] = (peer->pmax[afi][safi] >> 24);
2304 ndata[4] = (peer->pmax[afi][safi] >> 16);
2305 ndata[5] = (peer->pmax[afi][safi] >> 8);
2306 ndata[6] = (peer->pmax[afi][safi]);
e0701b79 2307
2308 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
2309 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
2310 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
2311 }
0a486e5f 2312
f14e6fdb
DS
2313 /* Dynamic peers will just close their connection. */
2314 if (peer_dynamic_neighbor (peer))
2315 return 1;
2316
0a486e5f 2317 /* restart timer start */
2318 if (peer->pmax_restart[afi][safi])
2319 {
2320 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
2321
16286195 2322 if (bgp_debug_neighbor_events(peer))
0a486e5f 2323 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2324 peer->host, peer->v_pmax_restart);
2325
2326 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2327 peer->v_pmax_restart);
2328 }
2329
e0701b79 2330 return 1;
2331 }
2332 else
2333 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2334
2335 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2336 {
2337 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2338 && ! always)
2339 return 0;
2340
16286195
DS
2341 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2342 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2343 peer->pmax[afi][safi]);
e0701b79 2344 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2345 }
e0701b79 2346 else
2347 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2348 return 0;
2349}
2350
b40d939b 2351/* Unconditionally remove the route from the RIB, without taking
2352 * damping into consideration (eg, because the session went down)
2353 */
94f2b392 2354static void
718e3744 2355bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2356 afi_t afi, safi_t safi)
2357{
902212c3 2358 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2359
2360 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2361 bgp_info_delete (rn, ri); /* keep historical info */
2362
b40d939b 2363 bgp_process (peer->bgp, rn, afi, safi);
718e3744 2364}
2365
94f2b392 2366static void
718e3744 2367bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
b40d939b 2368 afi_t afi, safi_t safi)
718e3744 2369{
718e3744 2370 int status = BGP_DAMP_NONE;
2371
b40d939b 2372 /* apply dampening, if result is suppressed, we'll be retaining
2373 * the bgp_info in the RIB for historical reference.
2374 */
2375 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2376 && peer->sort == BGP_PEER_EBGP)
b40d939b 2377 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2378 == BGP_DAMP_SUPPRESSED)
902212c3 2379 {
902212c3 2380 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2381 return;
2382 }
2383
2384 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 2385}
2386
fb018d25 2387static struct bgp_info *
7c8ff89e 2388info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
fb018d25
DS
2389 struct bgp_node *rn)
2390{
2391 struct bgp_info *new;
2392
2393 /* Make new BGP info. */
2394 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2395 new->type = type;
7c8ff89e 2396 new->instance = instance;
fb018d25
DS
2397 new->sub_type = sub_type;
2398 new->peer = peer;
2399 new->attr = attr;
2400 new->uptime = bgp_clock ();
2401 new->net = rn;
2402 return new;
2403}
2404
94f2b392 2405static void
cd808e74
DS
2406bgp_info_addpath_rx_str(struct bgp_info *ri, char *buf)
2407{
2408 if (ri && ri->addpath_rx_id)
2409 sprintf(buf, " with addpath ID %d", ri->addpath_rx_id);
cd808e74
DS
2410}
2411
2412static void
2413bgp_update_rsclient (struct peer *rsclient, u_int32_t addpath_id,
2414 afi_t afi, safi_t safi, struct attr *attr,
2415 struct peer *peer, struct prefix *p, int type,
2416 int sub_type, struct prefix_rd *prd, u_char *tag)
fee0f4c6 2417{
2418 struct bgp_node *rn;
2419 struct bgp *bgp;
558d1fec
JBD
2420 struct attr new_attr;
2421 struct attr_extra new_extra;
fee0f4c6 2422 struct attr *attr_new;
2423 struct attr *attr_new2;
2424 struct bgp_info *ri;
2425 struct bgp_info *new;
fd79ac91 2426 const char *reason;
fee0f4c6 2427 char buf[SU_ADDRSTRLEN];
cd808e74 2428 char buf2[30];
fee0f4c6 2429
2430 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
2431 if (peer == rsclient)
2432 return;
2433
2434 bgp = peer->bgp;
2435 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2436
2437 /* Check previously received route. */
2438 for (ri = rn->info; ri; ri = ri->next)
cd808e74
DS
2439 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2440 ri->addpath_rx_id == addpath_id)
fee0f4c6 2441 break;
2442
2443 /* AS path loop check. */
000e157c 2444 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
fee0f4c6 2445 {
2446 reason = "as-path contains our own AS;";
2447 goto filtered;
2448 }
2449
2450 /* Route reflector originator ID check. */
2451 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 2452 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
fee0f4c6 2453 {
2454 reason = "originator is us;";
2455 goto filtered;
2456 }
fb982c25 2457
558d1fec 2458 new_attr.extra = &new_extra;
fb982c25 2459 bgp_attr_dup (&new_attr, attr);
fee0f4c6 2460
2461 /* Apply export policy. */
2462 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
2463 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
2464 {
2465 reason = "export-policy;";
2466 goto filtered;
2467 }
2468
2469 attr_new2 = bgp_attr_intern (&new_attr);
fb982c25 2470
fee0f4c6 2471 /* Apply import policy. */
2472 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
2473 {
f6f434b2 2474 bgp_attr_unintern (&attr_new2);
fee0f4c6 2475
2476 reason = "import-policy;";
2477 goto filtered;
2478 }
2479
2480 attr_new = bgp_attr_intern (&new_attr);
f6f434b2 2481 bgp_attr_unintern (&attr_new2);
fee0f4c6 2482
2483 /* IPv4 unicast next hop check. */
8a92a8a0
DS
2484 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST && !peer_cap_enhe(peer))
2485 || safi == SAFI_MULTICAST))
fee0f4c6 2486 {
733cd9e5 2487 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
fee0f4c6 2488 if (new_attr.nexthop.s_addr == 0
733cd9e5 2489 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
fee0f4c6 2490 {
f6f434b2 2491 bgp_attr_unintern (&attr_new);
fee0f4c6 2492
2493 reason = "martian next-hop;";
2494 goto filtered;
2495 }
2496 }
558d1fec 2497
fee0f4c6 2498 /* If the update is implicit withdraw. */
2499 if (ri)
2500 {
65957886 2501 ri->uptime = bgp_clock ();
fee0f4c6 2502
2503 /* Same attribute comes in. */
16d2e241
PJ
2504 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
2505 && attrhash_cmp (ri->attr, attr_new))
fee0f4c6 2506 {
2507
3f9c7369 2508 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2509 {
2510 bgp_info_addpath_rx_str(ri, buf2);
2511 zlog_debug ("%s rcvd %s/%d%s for RS-client %s...duplicate ignored",
2512 peer->host,
2513 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2514 p->prefixlen, buf2, rsclient->host);
2515 }
fee0f4c6 2516
228da428 2517 bgp_unlock_node (rn);
f6f434b2 2518 bgp_attr_unintern (&attr_new);
fee0f4c6 2519
228da428 2520 return;
fee0f4c6 2521 }
2522
16d2e241
PJ
2523 /* Withdraw/Announce before we fully processed the withdraw */
2524 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2525 bgp_info_restore (rn, ri);
2526
fee0f4c6 2527 /* Received Logging. */
3f9c7369 2528 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2529 {
2530 bgp_info_addpath_rx_str(ri, buf2);
2531 zlog_debug ("%s rcvd %s/%d%s for RS-client %s",
2532 peer->host,
2533 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2534 p->prefixlen, buf2, rsclient->host);
2535 }
fee0f4c6 2536
2537 /* The attribute is changed. */
1a392d46 2538 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
fee0f4c6 2539
2540 /* Update to new attribute. */
f6f434b2 2541 bgp_attr_unintern (&ri->attr);
fee0f4c6 2542 ri->attr = attr_new;
2543
2544 /* Update MPLS tag. */
2545 if (safi == SAFI_MPLS_VPN)
fb982c25 2546 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
fee0f4c6 2547
1a392d46 2548 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
fee0f4c6 2549
2550 /* Process change. */
2551 bgp_process (bgp, rn, afi, safi);
2552 bgp_unlock_node (rn);
2553
2554 return;
2555 }
2556
2557 /* Received Logging. */
3f9c7369 2558 if (bgp_debug_update(peer, p, NULL, 1))
fee0f4c6 2559 {
cd808e74
DS
2560 bgp_info_addpath_rx_str(ri, buf2);
2561 zlog_debug ("%s rcvd %s/%d%s for RS-client %s",
16286195
DS
2562 peer->host,
2563 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2564 p->prefixlen, buf2, rsclient->host);
fee0f4c6 2565 }
2566
7c8ff89e 2567 new = info_make(type, sub_type, 0, peer, attr_new, rn);
fee0f4c6 2568
2569 /* Update MPLS tag. */
2570 if (safi == SAFI_MPLS_VPN)
fb982c25 2571 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
fee0f4c6 2572
1a392d46 2573 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
fee0f4c6 2574
2575 /* Register new BGP information. */
2576 bgp_info_add (rn, new);
200df115 2577
2578 /* route_node_get lock */
2579 bgp_unlock_node (rn);
2580
fee0f4c6 2581 /* Process change. */
2582 bgp_process (bgp, rn, afi, safi);
558d1fec 2583
fee0f4c6 2584 return;
2585
2586 filtered:
2587
2588 /* This BGP update is filtered. Log the reason then update BGP entry. */
3f9c7369 2589 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2590 {
2591 bgp_info_addpath_rx_str(ri, buf2);
2592 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED for RS-client %s due to: %s",
2593 peer->host,
2594 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2595 p->prefixlen, buf2, rsclient->host, reason);
2596 }
fee0f4c6 2597
2598 if (ri)
b40d939b 2599 bgp_rib_remove (rn, ri, peer, afi, safi);
fee0f4c6 2600
2601 bgp_unlock_node (rn);
558d1fec 2602
fee0f4c6 2603 return;
2604}
2605
94f2b392 2606static void
cd808e74
DS
2607bgp_withdraw_rsclient (struct peer *rsclient, u_int32_t addpath_id,
2608 afi_t afi, safi_t safi, struct peer *peer,
2609 struct prefix *p, int type, int sub_type,
2610 struct prefix_rd *prd, u_char *tag)
228da428 2611{
fee0f4c6 2612 struct bgp_node *rn;
2613 struct bgp_info *ri;
2614 char buf[SU_ADDRSTRLEN];
2615
2616 if (rsclient == peer)
228da428 2617 return;
fee0f4c6 2618
2619 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2620
2621 /* Lookup withdrawn route. */
2622 for (ri = rn->info; ri; ri = ri->next)
cd808e74
DS
2623 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2624 ri->addpath_rx_id == addpath_id)
fee0f4c6 2625 break;
2626
2627 /* Withdraw specified route from routing table. */
2628 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
b40d939b 2629 bgp_rib_withdraw (rn, ri, peer, afi, safi);
3f9c7369 2630 else if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2631 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2632 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2633 p->prefixlen);
fee0f4c6 2634
2635 /* Unlock bgp_node_get() lock. */
228da428
CC
2636 bgp_unlock_node (rn);
2637}
fee0f4c6 2638
94f2b392 2639static int
a82478b9
DS
2640bgp_update_main (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2641 struct attr *attr, afi_t afi, safi_t safi, int type,
2642 int sub_type, struct prefix_rd *prd, u_char *tag,
2643 int soft_reconfig)
718e3744 2644{
2645 int ret;
2646 int aspath_loop_count = 0;
2647 struct bgp_node *rn;
2648 struct bgp *bgp;
558d1fec
JBD
2649 struct attr new_attr;
2650 struct attr_extra new_extra;
718e3744 2651 struct attr *attr_new;
2652 struct bgp_info *ri;
2653 struct bgp_info *new;
fd79ac91 2654 const char *reason;
718e3744 2655 char buf[SU_ADDRSTRLEN];
cd808e74 2656 char buf2[30];
fc9a856f 2657 int connected = 0;
718e3744 2658
2659 bgp = peer->bgp;
fee0f4c6 2660 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
fb982c25 2661
718e3744 2662 /* When peer's soft reconfiguration enabled. Record input packet in
2663 Adj-RIBs-In. */
343aa822
JBD
2664 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2665 && peer != bgp->peer_self)
43143c8f 2666 bgp_adj_in_set (rn, peer, attr, addpath_id);
718e3744 2667
2668 /* Check previously received route. */
2669 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
2670 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2671 ri->addpath_rx_id == addpath_id)
718e3744 2672 break;
2673
2674 /* AS path local-as loop check. */
2675 if (peer->change_local_as)
2676 {
2677 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2678 aspath_loop_count = 1;
2679
2680 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2681 {
2682 reason = "as-path contains our own AS;";
2683 goto filtered;
2684 }
2685 }
2686
2687 /* AS path loop check. */
2688 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2689 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2690 && aspath_loop_check(attr->aspath, bgp->confed_id)
2691 > peer->allowas_in[afi][safi]))
2692 {
2693 reason = "as-path contains our own AS;";
2694 goto filtered;
2695 }
2696
2697 /* Route reflector originator ID check. */
2698 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 2699 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
718e3744 2700 {
2701 reason = "originator is us;";
2702 goto filtered;
2703 }
2704
2705 /* Route reflector cluster ID check. */
2706 if (bgp_cluster_filter (peer, attr))
2707 {
2708 reason = "reflected from the same cluster;";
2709 goto filtered;
2710 }
2711
2712 /* Apply incoming filter. */
2713 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2714 {
2715 reason = "filter;";
2716 goto filtered;
2717 }
2718
558d1fec 2719 new_attr.extra = &new_extra;
fb982c25 2720 bgp_attr_dup (&new_attr, attr);
718e3744 2721
c460e572
DL
2722 /* Apply incoming route-map.
2723 * NB: new_attr may now contain newly allocated values from route-map "set"
2724 * commands, so we need bgp_attr_flush in the error paths, until we intern
2725 * the attr (which takes over the memory references) */
0b16f239 2726 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
718e3744 2727 {
2728 reason = "route-map;";
c460e572 2729 bgp_attr_flush (&new_attr);
718e3744 2730 goto filtered;
2731 }
2732
2733 /* IPv4 unicast next hop check. */
8a92a8a0 2734 if (afi == AFI_IP && safi == SAFI_UNICAST && !peer_cap_enhe(peer))
718e3744 2735 {
3caff6ca 2736 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
10f9bf3f 2737 if (new_attr.nexthop.s_addr == 0
3caff6ca 2738 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
718e3744 2739 {
2740 reason = "martian next-hop;";
c460e572 2741 bgp_attr_flush (&new_attr);
718e3744 2742 goto filtered;
2743 }
3caff6ca
DS
2744
2745 /* Next hop must not be my own address. */
2746 if (bgp_nexthop_self (&new_attr))
2747 {
2748 reason = "local IP next-hop;";
2749 bgp_attr_flush (&new_attr);
2750 goto filtered;
2751 }
718e3744 2752 }
2753
2754 attr_new = bgp_attr_intern (&new_attr);
2755
2756 /* If the update is implicit withdraw. */
2757 if (ri)
2758 {
65957886 2759 ri->uptime = bgp_clock ();
718e3744 2760
2761 /* Same attribute comes in. */
16d2e241
PJ
2762 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2763 && attrhash_cmp (ri->attr, attr_new))
718e3744 2764 {
718e3744 2765 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2766 && peer->sort == BGP_PEER_EBGP
718e3744 2767 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2768 {
3f9c7369 2769 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2770 {
2771 bgp_info_addpath_rx_str(ri, buf2);
2772 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2773 peer->host,
2774 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74
DS
2775 p->prefixlen, buf2);
2776 }
718e3744 2777
902212c3 2778 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2779 {
2780 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2781 bgp_process (bgp, rn, afi, safi);
2782 }
718e3744 2783 }
16d2e241 2784 else /* Duplicate - odd */
718e3744 2785 {
3f9c7369 2786 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2787 {
2788 if (!peer->rcvd_attr_printed)
2789 {
2790 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2791 peer->rcvd_attr_printed = 1;
2792 }
2793
cd808e74
DS
2794 bgp_info_addpath_rx_str(ri, buf2);
2795 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
16286195
DS
2796 peer->host,
2797 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2798 p->prefixlen, buf2);
16286195 2799 }
93406d87 2800
2801 /* graceful restart STALE flag unset. */
2802 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2803 {
1a392d46 2804 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
902212c3 2805 bgp_process (bgp, rn, afi, safi);
93406d87 2806 }
718e3744 2807 }
2808
2809 bgp_unlock_node (rn);
f6f434b2 2810 bgp_attr_unintern (&attr_new);
558d1fec 2811
718e3744 2812 return 0;
2813 }
2814
16d2e241
PJ
2815 /* Withdraw/Announce before we fully processed the withdraw */
2816 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2817 {
3f9c7369 2818 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2819 {
2820 bgp_info_addpath_rx_str(ri, buf2);
2821 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
2822 peer->host,
2823 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2824 p->prefixlen, buf2);
2825 }
16d2e241
PJ
2826 bgp_info_restore (rn, ri);
2827 }
2828
718e3744 2829 /* Received Logging. */
3f9c7369 2830 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2831 {
2832 bgp_info_addpath_rx_str(ri, buf2);
2833 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2834 peer->host,
2835 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74
DS
2836 p->prefixlen, buf2);
2837 }
718e3744 2838
93406d87 2839 /* graceful restart STALE flag unset. */
2840 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1a392d46 2841 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
93406d87 2842
718e3744 2843 /* The attribute is changed. */
1a392d46 2844 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
902212c3 2845
2846 /* implicit withdraw, decrement aggregate and pcount here.
2847 * only if update is accepted, they'll increment below.
2848 */
902212c3 2849 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2850
718e3744 2851 /* Update bgp route dampening information. */
2852 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2853 && peer->sort == BGP_PEER_EBGP)
718e3744 2854 {
2855 /* This is implicit withdraw so we should update dampening
2856 information. */
2857 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2858 bgp_damp_withdraw (ri, rn, afi, safi, 1);
718e3744 2859 }
2860
718e3744 2861 /* Update to new attribute. */
f6f434b2 2862 bgp_attr_unintern (&ri->attr);
718e3744 2863 ri->attr = attr_new;
2864
2865 /* Update MPLS tag. */
2866 if (safi == SAFI_MPLS_VPN)
fb982c25 2867 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
718e3744 2868
2869 /* Update bgp route dampening information. */
2870 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2871 && peer->sort == BGP_PEER_EBGP)
718e3744 2872 {
2873 /* Now we do normal update dampening. */
2874 ret = bgp_damp_update (ri, rn, afi, safi);
2875 if (ret == BGP_DAMP_SUPPRESSED)
2876 {
2877 bgp_unlock_node (rn);
2878 return 0;
2879 }
2880 }
2881
2882 /* Nexthop reachability check. */
fc9a856f 2883 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
718e3744 2884 {
fc9a856f 2885 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
907f92c8
DS
2886 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2887 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
fc9a856f
DS
2888 connected = 1;
2889 else
2890 connected = 0;
2891
75aead62 2892 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
1a392d46 2893 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 2894 else
fc9a856f
DS
2895 {
2896 if (BGP_DEBUG(nht, NHT))
2897 {
2898 char buf1[INET6_ADDRSTRLEN];
2899 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2900 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2901 }
2902 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2903 }
718e3744 2904 }
2905 else
fc9a856f 2906 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 2907
2908 /* Process change. */
2909 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2910
2911 bgp_process (bgp, rn, afi, safi);
2912 bgp_unlock_node (rn);
558d1fec 2913
718e3744 2914 return 0;
a82478b9 2915 } // End of implicit withdraw
718e3744 2916
2917 /* Received Logging. */
3f9c7369 2918 if (bgp_debug_update(peer, p, NULL, 1))
718e3744 2919 {
16286195
DS
2920 if (!peer->rcvd_attr_printed)
2921 {
2922 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2923 peer->rcvd_attr_printed = 1;
2924 }
2925
cd808e74
DS
2926 bgp_info_addpath_rx_str(ri, buf2);
2927 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2928 peer->host,
2929 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2930 p->prefixlen, buf2);
718e3744 2931 }
2932
718e3744 2933 /* Make new BGP info. */
7c8ff89e 2934 new = info_make(type, sub_type, 0, peer, attr_new, rn);
718e3744 2935
2936 /* Update MPLS tag. */
2937 if (safi == SAFI_MPLS_VPN)
fb982c25 2938 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
718e3744 2939
2940 /* Nexthop reachability check. */
fc9a856f
DS
2941 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2942 {
2943 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
907f92c8
DS
2944 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2945 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
fc9a856f
DS
2946 connected = 1;
2947 else
2948 connected = 0;
2949
75aead62 2950 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
1a392d46 2951 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 2952 else
fc9a856f
DS
2953 {
2954 if (BGP_DEBUG(nht, NHT))
2955 {
2956 char buf1[INET6_ADDRSTRLEN];
2957 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2958 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2959 }
2960 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2961 }
718e3744 2962 }
2963 else
1a392d46 2964 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 2965
a82478b9
DS
2966 /* Addpath ID */
2967 new->addpath_rx_id = addpath_id;
2968 new->addpath_tx_id = 0;
2969
902212c3 2970 /* Increment prefix */
718e3744 2971 bgp_aggregate_increment (bgp, p, new, afi, safi);
2972
2973 /* Register new BGP information. */
2974 bgp_info_add (rn, new);
200df115 2975
2976 /* route_node_get lock */
2977 bgp_unlock_node (rn);
558d1fec 2978
718e3744 2979 /* If maximum prefix count is configured and current prefix
2980 count exeed it. */
e0701b79 2981 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2982 return -1;
718e3744 2983
2984 /* Process change. */
2985 bgp_process (bgp, rn, afi, safi);
2986
2987 return 0;
2988
2989 /* This BGP update is filtered. Log the reason then update BGP
2990 entry. */
2991 filtered:
3f9c7369 2992 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2993 {
2994 if (!peer->rcvd_attr_printed)
2995 {
2996 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2997 peer->rcvd_attr_printed = 1;
2998 }
2999
cd808e74
DS
3000 bgp_info_addpath_rx_str(ri, buf2);
3001 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
16286195
DS
3002 peer->host,
3003 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 3004 p->prefixlen, buf2, reason);
16286195 3005 }
718e3744 3006
3007 if (ri)
b40d939b 3008 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 3009
3010 bgp_unlock_node (rn);
558d1fec 3011
718e3744 3012 return 0;
3013}
3014
fee0f4c6 3015int
a82478b9
DS
3016bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
3017 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
fee0f4c6 3018 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
3019{
3020 struct peer *rsclient;
1eb8ef25 3021 struct listnode *node, *nnode;
fee0f4c6 3022 struct bgp *bgp;
3023 int ret;
3024
a82478b9
DS
3025 ret = bgp_update_main (peer, p, addpath_id, attr, afi, safi, type, sub_type,
3026 prd, tag, soft_reconfig);
fee0f4c6 3027
3028 bgp = peer->bgp;
3029
3030 /* Process the update for each RS-client. */
1eb8ef25 3031 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 3032 {
3033 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
cd808e74 3034 bgp_update_rsclient (rsclient, addpath_id, afi, safi, attr, peer, p,
a82478b9 3035 type, sub_type, prd, tag);
fee0f4c6 3036 }
3037
3038 return ret;
3039}
3040
718e3744 3041int
a82478b9
DS
3042bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
3043 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
3044 struct prefix_rd *prd, u_char *tag)
718e3744 3045{
3046 struct bgp *bgp;
3047 char buf[SU_ADDRSTRLEN];
cd808e74 3048 char buf2[30];
718e3744 3049 struct bgp_node *rn;
3050 struct bgp_info *ri;
fee0f4c6 3051 struct peer *rsclient;
1eb8ef25 3052 struct listnode *node, *nnode;
718e3744 3053
3054 bgp = peer->bgp;
3055
fee0f4c6 3056 /* Process the withdraw for each RS-client. */
1eb8ef25 3057 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 3058 {
3059 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
cd808e74 3060 bgp_withdraw_rsclient (rsclient, addpath_id, afi, safi, peer, p, type,
a82478b9 3061 sub_type, prd, tag);
fee0f4c6 3062 }
3063
718e3744 3064 /* Lookup node. */
fee0f4c6 3065 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 3066
3067 /* If peer is soft reconfiguration enabled. Record input packet for
3068 further calculation. */
3069 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
3070 && peer != bgp->peer_self)
43143c8f 3071 bgp_adj_in_unset (rn, peer, addpath_id);
718e3744 3072
3073 /* Lookup withdrawn route. */
3074 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
3075 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
3076 ri->addpath_rx_id == addpath_id)
718e3744 3077 break;
3078
cd808e74
DS
3079 /* Logging. */
3080 if (bgp_debug_update(peer, p, NULL, 1))
3081 {
3082 bgp_info_addpath_rx_str(ri, buf2);
3083 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
3084 peer->host,
3085 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3086 p->prefixlen, buf2);
3087 }
3088
718e3744 3089 /* Withdraw specified route from routing table. */
3090 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
b40d939b 3091 bgp_rib_withdraw (rn, ri, peer, afi, safi);
3f9c7369 3092 else if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
3093 zlog_debug ("%s Can't find the route %s/%d", peer->host,
3094 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3095 p->prefixlen);
718e3744 3096
3097 /* Unlock bgp_node_get() lock. */
3098 bgp_unlock_node (rn);
3099
3100 return 0;
3101}
6b0655a2 3102
718e3744 3103void
3104bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
3105{
3f9c7369
DS
3106 struct update_subgroup *subgrp;
3107 subgrp = peer_subgroup(peer, afi, safi);
3108 subgroup_default_originate(subgrp, withdraw);
3109}
6182d65b 3110
718e3744 3111
3f9c7369
DS
3112/*
3113 * bgp_stop_announce_route_timer
3114 */
3115void
3116bgp_stop_announce_route_timer (struct peer_af *paf)
3117{
3118 if (!paf->t_announce_route)
3119 return;
718e3744 3120
3f9c7369 3121 THREAD_TIMER_OFF (paf->t_announce_route);
718e3744 3122}
6b0655a2 3123
3f9c7369
DS
3124/*
3125 * bgp_announce_route_timer_expired
3126 *
3127 * Callback that is invoked when the route announcement timer for a
3128 * peer_af expires.
3129 */
3130static int
3131bgp_announce_route_timer_expired (struct thread *t)
718e3744 3132{
3f9c7369
DS
3133 struct peer_af *paf;
3134 struct peer *peer;
558d1fec 3135
718e3744 3136
3f9c7369
DS
3137 paf = THREAD_ARG (t);
3138 peer = paf->peer;
718e3744 3139
3f9c7369
DS
3140 assert (paf->t_announce_route);
3141 paf->t_announce_route = NULL;
558d1fec 3142
3f9c7369
DS
3143 if (peer->status != Established)
3144 return 0;
3145
3146 if (!peer->afc_nego[paf->afi][paf->safi])
3147 return 0;
3148
3149 peer_af_announce_route (paf, 1);
3150 return 0;
718e3744 3151}
3152
3f9c7369
DS
3153/*
3154 * bgp_announce_route
3155 *
3156 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
3157 */
718e3744 3158void
3159bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
3160{
3f9c7369
DS
3161 struct peer_af *paf;
3162 struct update_subgroup *subgrp;
718e3744 3163
3f9c7369
DS
3164 paf = peer_af_find (peer, afi, safi);
3165 if (!paf)
718e3744 3166 return;
3f9c7369 3167 subgrp = PAF_SUBGRP(paf);
718e3744 3168
3f9c7369
DS
3169 /*
3170 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
3171 * or a refresh has already been triggered.
3172 */
3173 if (!subgrp || paf->t_announce_route)
718e3744 3174 return;
3175
d889623f 3176 /*
3f9c7369
DS
3177 * Start a timer to stagger/delay the announce. This serves
3178 * two purposes - announcement can potentially be combined for
3179 * multiple peers and the announcement doesn't happen in the
3180 * vty context.
d889623f 3181 */
3f9c7369
DS
3182 THREAD_TIMER_MSEC_ON (master, paf->t_announce_route,
3183 bgp_announce_route_timer_expired, paf,
3184 (subgrp->peer_count == 1) ?
3185 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
3186 BGP_ANNOUNCE_ROUTE_DELAY_MS);
3187}
3188
3189/*
3190 * Announce routes from all AF tables to a peer.
3191 *
3192 * This should ONLY be called when there is a need to refresh the
3193 * routes to the peer based on a policy change for this peer alone
3194 * or a route refresh request received from the peer.
3195 * The operation will result in splitting the peer from its existing
3196 * subgroups and putting it in new subgroups.
3197 */
718e3744 3198void
3199bgp_announce_route_all (struct peer *peer)
3200{
3201 afi_t afi;
3202 safi_t safi;
3203
3204 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3205 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3206 bgp_announce_route (peer, afi, safi);
3207}
6b0655a2 3208
718e3744 3209static void
fee0f4c6 3210bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
8692c506 3211 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
fee0f4c6 3212{
3213 struct bgp_node *rn;
3214 struct bgp_adj_in *ain;
3215
3216 if (! table)
3217 table = rsclient->bgp->rib[afi][safi];
3218
3219 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3220 for (ain = rn->adj_in; ain; ain = ain->next)
3221 {
8692c506 3222 struct bgp_info *ri = rn->info;
d53d8fda 3223 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 3224
cd808e74
DS
3225 bgp_update_rsclient (rsclient, ri->addpath_rx_id, afi, safi, ain->attr,
3226 ain->peer, &rn->p, ZEBRA_ROUTE_BGP,
3227 BGP_ROUTE_NORMAL, prd, tag);
fee0f4c6 3228 }
3229}
3230
3231void
3232bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3233{
3234 struct bgp_table *table;
3235 struct bgp_node *rn;
3236
3237 if (safi != SAFI_MPLS_VPN)
8692c506 3238 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
fee0f4c6 3239
3240 else
3241 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
3242 rn = bgp_route_next (rn))
3243 if ((table = rn->info) != NULL)
8692c506
JBD
3244 {
3245 struct prefix_rd prd;
3246 prd.family = AF_UNSPEC;
3247 prd.prefixlen = 64;
3248 memcpy(&prd.val, rn->p.u.val, 8);
3249
3250 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
3251 }
fee0f4c6 3252}
6b0655a2 3253
fee0f4c6 3254static void
718e3744 3255bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
8692c506 3256 struct bgp_table *table, struct prefix_rd *prd)
718e3744 3257{
3258 int ret;
3259 struct bgp_node *rn;
3260 struct bgp_adj_in *ain;
3261
3262 if (! table)
3263 table = peer->bgp->rib[afi][safi];
3264
3265 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3266 for (ain = rn->adj_in; ain; ain = ain->next)
3267 {
3268 if (ain->peer == peer)
3269 {
8692c506 3270 struct bgp_info *ri = rn->info;
d53d8fda 3271 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 3272
43143c8f 3273 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
a82478b9 3274 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
d53d8fda 3275 prd, tag, 1);
8692c506 3276
718e3744 3277 if (ret < 0)
3278 {
3279 bgp_unlock_node (rn);
3280 return;
3281 }
718e3744 3282 }
3283 }
3284}
3285
3286void
3287bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
3288{
3289 struct bgp_node *rn;
3290 struct bgp_table *table;
3291
3292 if (peer->status != Established)
3293 return;
3294
3295 if (safi != SAFI_MPLS_VPN)
8692c506 3296 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
718e3744 3297 else
3298 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3299 rn = bgp_route_next (rn))
3300 if ((table = rn->info) != NULL)
8692c506
JBD
3301 {
3302 struct prefix_rd prd;
3303 prd.family = AF_UNSPEC;
3304 prd.prefixlen = 64;
3305 memcpy(&prd.val, rn->p.u.val, 8);
3306
3307 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
3308 }
718e3744 3309}
6b0655a2 3310
228da428
CC
3311
3312struct bgp_clear_node_queue
3313{
3314 struct bgp_node *rn;
3315 enum bgp_clear_route_type purpose;
3316};
3317
200df115 3318static wq_item_status
0fb58d5d 3319bgp_clear_route_node (struct work_queue *wq, void *data)
200df115 3320{
228da428
CC
3321 struct bgp_clear_node_queue *cnq = data;
3322 struct bgp_node *rn = cnq->rn;
64e580a7 3323 struct peer *peer = wq->spec.data;
718e3744 3324 struct bgp_info *ri;
67174041
AS
3325 afi_t afi = bgp_node_table (rn)->afi;
3326 safi_t safi = bgp_node_table (rn)->safi;
200df115 3327
64e580a7 3328 assert (rn && peer);
200df115 3329
43143c8f
DS
3330 /* It is possible that we have multiple paths for a prefix from a peer
3331 * if that peer is using AddPath.
3332 */
64e580a7 3333 for (ri = rn->info; ri; ri = ri->next)
228da428 3334 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
200df115 3335 {
3336 /* graceful restart STALE flag set. */
64e580a7
PJ
3337 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
3338 && peer->nsf[afi][safi]
200df115 3339 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
1a392d46
PJ
3340 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
3341 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
200df115 3342 else
64e580a7 3343 bgp_rib_remove (rn, ri, peer, afi, safi);
200df115 3344 }
200df115 3345 return WQ_SUCCESS;
3346}
3347
3348static void
0fb58d5d 3349bgp_clear_node_queue_del (struct work_queue *wq, void *data)
200df115 3350{
228da428
CC
3351 struct bgp_clear_node_queue *cnq = data;
3352 struct bgp_node *rn = cnq->rn;
67174041 3353 struct bgp_table *table = bgp_node_table (rn);
64e580a7
PJ
3354
3355 bgp_unlock_node (rn);
228da428
CC
3356 bgp_table_unlock (table);
3357 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
200df115 3358}
3359
3360static void
94f2b392 3361bgp_clear_node_complete (struct work_queue *wq)
200df115 3362{
64e580a7
PJ
3363 struct peer *peer = wq->spec.data;
3364
3e0c78ef 3365 /* Tickle FSM to start moving again */
ca058a30 3366 BGP_EVENT_ADD (peer, Clearing_Completed);
228da428
CC
3367
3368 peer_unlock (peer); /* bgp_clear_route */
200df115 3369}
3370
3371static void
64e580a7 3372bgp_clear_node_queue_init (struct peer *peer)
200df115 3373{
a2943657 3374 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
64e580a7 3375
a2943657 3376 snprintf (wname, sizeof(wname), "clear %s", peer->host);
64e580a7
PJ
3377#undef CLEAR_QUEUE_NAME_LEN
3378
3379 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
200df115 3380 {
3381 zlog_err ("%s: Failed to allocate work queue", __func__);
3382 exit (1);
3383 }
64e580a7
PJ
3384 peer->clear_node_queue->spec.hold = 10;
3385 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
3386 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
3387 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
3388 peer->clear_node_queue->spec.max_retries = 0;
3389
3390 /* we only 'lock' this peer reference when the queue is actually active */
3391 peer->clear_node_queue->spec.data = peer;
200df115 3392}
718e3744 3393
200df115 3394static void
3395bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
228da428
CC
3396 struct bgp_table *table, struct peer *rsclient,
3397 enum bgp_clear_route_type purpose)
200df115 3398{
200df115 3399 struct bgp_node *rn;
3400
f2c31acb 3401
718e3744 3402 if (! table)
fee0f4c6 3403 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
64e580a7 3404
6cf159b9 3405 /* If still no table => afi/safi isn't configured at all or smth. */
3406 if (! table)
3407 return;
65ca75e0
PJ
3408
3409 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3410 {
f2c31acb
PJ
3411 struct bgp_info *ri;
3412 struct bgp_adj_in *ain;
43143c8f 3413 struct bgp_adj_in *ain_next;
f2c31acb
PJ
3414
3415 /* XXX:TODO: This is suboptimal, every non-empty route_node is
3416 * queued for every clearing peer, regardless of whether it is
3417 * relevant to the peer at hand.
3418 *
3419 * Overview: There are 3 different indices which need to be
3420 * scrubbed, potentially, when a peer is removed:
3421 *
3422 * 1 peer's routes visible via the RIB (ie accepted routes)
3423 * 2 peer's routes visible by the (optional) peer's adj-in index
3424 * 3 other routes visible by the peer's adj-out index
3425 *
3426 * 3 there is no hurry in scrubbing, once the struct peer is
3427 * removed from bgp->peer, we could just GC such deleted peer's
3428 * adj-outs at our leisure.
3429 *
3430 * 1 and 2 must be 'scrubbed' in some way, at least made
3431 * invisible via RIB index before peer session is allowed to be
3432 * brought back up. So one needs to know when such a 'search' is
3433 * complete.
3434 *
3435 * Ideally:
3436 *
3437 * - there'd be a single global queue or a single RIB walker
3438 * - rather than tracking which route_nodes still need to be
3439 * examined on a peer basis, we'd track which peers still
3440 * aren't cleared
3441 *
3442 * Given that our per-peer prefix-counts now should be reliable,
3443 * this may actually be achievable. It doesn't seem to be a huge
3444 * problem at this time,
43143c8f
DS
3445 *
3446 * It is possible that we have multiple paths for a prefix from a peer
3447 * if that peer is using AddPath.
f2c31acb 3448 */
43143c8f
DS
3449 ain = rn->adj_in;
3450 while (ain)
3451 {
3452 ain_next = ain->next;
3453
3454 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
3455 {
3456 bgp_adj_in_remove (rn, ain);
3457 bgp_unlock_node (rn);
3458 }
3459
3460 ain = ain_next;
3461 }
3f9c7369
DS
3462
3463 /*
3464 * Can't do this anymore. adj-outs are not maintained per peer.
3465 *
24e50f20
JBD
3466 for (aout = rn->adj_out; aout; aout = aout->next)
3467 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
3468 {
3469 bgp_adj_out_remove (rn, aout, peer, afi, safi);
3470 bgp_unlock_node (rn);
3471 break;
3472 }
3f9c7369 3473 */
f2c31acb 3474 for (ri = rn->info; ri; ri = ri->next)
228da428 3475 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
f2c31acb 3476 {
228da428
CC
3477 struct bgp_clear_node_queue *cnq;
3478
3479 /* both unlocked in bgp_clear_node_queue_del */
67174041 3480 bgp_table_lock (bgp_node_table (rn));
228da428
CC
3481 bgp_lock_node (rn);
3482 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
3483 sizeof (struct bgp_clear_node_queue));
3484 cnq->rn = rn;
3485 cnq->purpose = purpose;
3486 work_queue_add (peer->clear_node_queue, cnq);
3487 break;
f2c31acb 3488 }
65ca75e0
PJ
3489 }
3490 return;
3491}
3492
3493void
228da428
CC
3494bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
3495 enum bgp_clear_route_type purpose)
65ca75e0
PJ
3496{
3497 struct bgp_node *rn;
3498 struct bgp_table *table;
3499 struct peer *rsclient;
3500 struct listnode *node, *nnode;
6cf159b9 3501
64e580a7
PJ
3502 if (peer->clear_node_queue == NULL)
3503 bgp_clear_node_queue_init (peer);
200df115 3504
ca058a30
PJ
3505 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3506 * Idle until it receives a Clearing_Completed event. This protects
3507 * against peers which flap faster than we can we clear, which could
3508 * lead to:
64e580a7
PJ
3509 *
3510 * a) race with routes from the new session being installed before
3511 * clear_route_node visits the node (to delete the route of that
3512 * peer)
3513 * b) resource exhaustion, clear_route_node likely leads to an entry
3514 * on the process_main queue. Fast-flapping could cause that queue
3515 * to grow and grow.
200df115 3516 */
dc83d712
DS
3517
3518 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3519 * the unlock will happen upon work-queue completion; other wise, the
3520 * unlock happens at the end of this function.
3521 */
ca058a30 3522 if (!peer->clear_node_queue->thread)
dc83d712 3523 peer_lock (peer);
fee0f4c6 3524
228da428 3525 switch (purpose)
fee0f4c6 3526 {
228da428
CC
3527 case BGP_CLEAR_ROUTE_NORMAL:
3528 if (safi != SAFI_MPLS_VPN)
3529 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3530 else
3531 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3532 rn = bgp_route_next (rn))
3533 if ((table = rn->info) != NULL)
3534 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3535
3536 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3537 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3538 PEER_FLAG_RSERVER_CLIENT))
3539 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3540 break;
3541
3542 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
3543 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3544 break;
3545
3546 default:
3547 assert (0);
3548 break;
fee0f4c6 3549 }
dc83d712
DS
3550
3551 /* unlock if no nodes got added to the clear-node-queue. */
65ca75e0 3552 if (!peer->clear_node_queue->thread)
dc83d712
DS
3553 peer_unlock (peer);
3554
718e3744 3555}
3556
3557void
3558bgp_clear_route_all (struct peer *peer)
3559{
3560 afi_t afi;
3561 safi_t safi;
3562
3563 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3564 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
228da428 3565 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
718e3744 3566}
3567
3568void
3569bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3570{
3571 struct bgp_table *table;
3572 struct bgp_node *rn;
3573 struct bgp_adj_in *ain;
43143c8f 3574 struct bgp_adj_in *ain_next;
718e3744 3575
3576 table = peer->bgp->rib[afi][safi];
3577
43143c8f
DS
3578 /* It is possible that we have multiple paths for a prefix from a peer
3579 * if that peer is using AddPath.
3580 */
718e3744 3581 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
43143c8f
DS
3582 {
3583 ain = rn->adj_in;
3584
3585 while (ain)
3586 {
3587 ain_next = ain->next;
3588
3589 if (ain->peer == peer)
3590 {
3591 bgp_adj_in_remove (rn, ain);
3592 bgp_unlock_node (rn);
3593 }
3594
3595 ain = ain_next;
3596 }
3597 }
718e3744 3598}
93406d87 3599
3600void
3601bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3602{
3603 struct bgp_node *rn;
3604 struct bgp_info *ri;
3605 struct bgp_table *table;
3606
3607 table = peer->bgp->rib[afi][safi];
3608
3609 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3610 {
3611 for (ri = rn->info; ri; ri = ri->next)
3612 if (ri->peer == peer)
3613 {
3614 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3615 bgp_rib_remove (rn, ri, peer, afi, safi);
3616 break;
3617 }
3618 }
3619}
6b0655a2 3620
718e3744 3621/* Delete all kernel routes. */
3622void
66e5cd87 3623bgp_cleanup_routes (void)
718e3744 3624{
3625 struct bgp *bgp;
1eb8ef25 3626 struct listnode *node, *nnode;
718e3744 3627 struct bgp_node *rn;
3628 struct bgp_table *table;
3629 struct bgp_info *ri;
3630
1eb8ef25 3631 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 3632 {
3633 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3634
3635 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3636 for (ri = rn->info; ri; ri = ri->next)
3637 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3638 && ri->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
3639 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3640 ri->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 3641 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
718e3744 3642
3643 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3644
3645 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3646 for (ri = rn->info; ri; ri = ri->next)
3647 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3648 && ri->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
3649 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3650 ri->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 3651 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
718e3744 3652 }
3653}
3654
3655void
66e5cd87 3656bgp_reset (void)
718e3744 3657{
3658 vty_reset ();
3659 bgp_zclient_reset ();
3660 access_list_reset ();
3661 prefix_list_reset ();
3662}
6b0655a2 3663
718e3744 3664/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3665 value. */
3666int
3667bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3668{
3669 u_char *pnt;
3670 u_char *lim;
3671 struct prefix p;
3672 int psize;
3673 int ret;
a82478b9
DS
3674 afi_t afi;
3675 safi_t safi;
3676 u_char addpath_encoded;
3677 u_int32_t addpath_id;
718e3744 3678
3679 /* Check peer status. */
3680 if (peer->status != Established)
3681 return 0;
3682
3683 pnt = packet->nlri;
3684 lim = pnt + packet->length;
a82478b9
DS
3685 afi = packet->afi;
3686 safi = packet->safi;
3687 addpath_id = 0;
3688
3689 addpath_encoded = (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3690 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
718e3744 3691
3692 for (; pnt < lim; pnt += psize)
3693 {
3694 /* Clear prefix structure. */
3695 memset (&p, 0, sizeof (struct prefix));
3696
a82478b9
DS
3697 if (addpath_encoded)
3698 {
cd808e74
DS
3699
3700 /* When packet overflow occurs return immediately. */
3701 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3702 return -1;
3703
a82478b9
DS
3704 addpath_id = ntohl(*((uint32_t*) pnt));
3705 pnt += BGP_ADDPATH_ID_LEN;
3706 }
3707
718e3744 3708 /* Fetch prefix length. */
3709 p.prefixlen = *pnt++;
a82478b9 3710 p.family = afi2family (afi);
718e3744 3711
3712 /* Already checked in nlri_sanity_check(). We do double check
3713 here. */
a82478b9
DS
3714 if ((afi == AFI_IP && p.prefixlen > 32)
3715 || (afi == AFI_IP6 && p.prefixlen > 128))
718e3744 3716 return -1;
3717
3718 /* Packet size overflow check. */
3719 psize = PSIZE (p.prefixlen);
3720
3721 /* When packet overflow occur return immediately. */
3722 if (pnt + psize > lim)
3723 return -1;
3724
3725 /* Fetch prefix from NLRI packet. */
3726 memcpy (&p.u.prefix, pnt, psize);
3727
3728 /* Check address. */
a82478b9 3729 if (afi == AFI_IP && safi == SAFI_UNICAST)
718e3744 3730 {
3731 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3732 {
f5ba3874 3733 /*
3734 * From draft-ietf-idr-bgp4-22, Section 6.3:
3735 * If a BGP router receives an UPDATE message with a
3736 * semantically incorrect NLRI field, in which a prefix is
3737 * semantically incorrect (eg. an unexpected multicast IP
3738 * address), it should ignore the prefix.
3739 */
16286195
DS
3740 zlog_err ("IPv4 unicast NLRI is multicast address %s",
3741 inet_ntoa (p.u.prefix4));
f5ba3874 3742
718e3744 3743 return -1;
3744 }
3745 }
3746
3747#ifdef HAVE_IPV6
3748 /* Check address. */
a82478b9 3749 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
718e3744 3750 {
3751 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3752 {
3753 char buf[BUFSIZ];
3754
16286195
DS
3755 zlog_warn ("IPv6 link-local NLRI received %s ignore this NLRI",
3756 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
718e3744 3757
3758 continue;
3759 }
3760 }
3761#endif /* HAVE_IPV6 */
3762
3763 /* Normal process. */
3764 if (attr)
a82478b9 3765 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
718e3744 3766 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3767 else
a82478b9 3768 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
718e3744 3769 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3770
3771 /* Address family configuration mismatch or maximum-prefix count
3772 overflow. */
3773 if (ret < 0)
3774 return -1;
3775 }
3776
3777 /* Packet length consistency check. */
3778 if (pnt != lim)
3779 return -1;
3780
3781 return 0;
3782}
3783
3784/* NLRI encode syntax check routine. */
3785int
a82478b9 3786bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi, u_char *pnt,
d889623f 3787 bgp_size_t length, int *numpfx)
718e3744 3788{
3789 u_char *end;
3790 u_char prefixlen;
3791 int psize;
a82478b9 3792 u_char addpath_encoded;
718e3744 3793
d889623f 3794 *numpfx = 0;
718e3744 3795 end = pnt + length;
3796
a82478b9
DS
3797 addpath_encoded = (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3798 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3799
718e3744 3800 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3801 syntactic validity. If the field is syntactically incorrect,
3802 then the Error Subcode is set to Invalid Network Field. */
3803
3804 while (pnt < end)
3805 {
cd808e74 3806
a82478b9
DS
3807 /* If the NLRI is encoded using addpath then the first 4 bytes are
3808 * the addpath ID. */
3809 if (addpath_encoded)
cd808e74
DS
3810 {
3811 if (pnt + BGP_ADDPATH_ID_LEN > end)
3812 {
3813 zlog_err ("%s [Error] Update packet error"
3814 " (prefix data addpath overflow)",
3815 peer->host);
3816 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3817 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3818 return -1;
3819 }
3820 pnt += BGP_ADDPATH_ID_LEN;
3821 }
a82478b9 3822
718e3744 3823 prefixlen = *pnt++;
3824
3825 /* Prefix length check. */
3826 if ((afi == AFI_IP && prefixlen > 32)
3827 || (afi == AFI_IP6 && prefixlen > 128))
3828 {
16286195 3829 zlog_err ("%s [Error] Update packet error (wrong prefix length %d)",
718e3744 3830 peer->host, prefixlen);
3831 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3832 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3833 return -1;
3834 }
3835
3836 /* Packet size overflow check. */
3837 psize = PSIZE (prefixlen);
3838
3839 if (pnt + psize > end)
3840 {
16286195 3841 zlog_err ("%s [Error] Update packet error"
718e3744 3842 " (prefix data overflow prefix size is %d)",
3843 peer->host, psize);
3844 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3845 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3846 return -1;
3847 }
3848
3849 pnt += psize;
d889623f 3850 (*numpfx)++;
718e3744 3851 }
3852
3853 /* Packet length consistency check. */
3854 if (pnt != end)
3855 {
16286195 3856 zlog_err ("%s [Error] Update packet error"
718e3744 3857 " (prefix length mismatch with total length)",
3858 peer->host);
3859 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3860 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3861 return -1;
3862 }
3863 return 0;
3864}
6b0655a2 3865
94f2b392 3866static struct bgp_static *
66e5cd87 3867bgp_static_new (void)
718e3744 3868{
393deb9b 3869 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
718e3744 3870}
3871
94f2b392 3872static void
718e3744 3873bgp_static_free (struct bgp_static *bgp_static)
3874{
3875 if (bgp_static->rmap.name)
3876 free (bgp_static->rmap.name);
3877 XFREE (MTYPE_BGP_STATIC, bgp_static);
3878}
3879
94f2b392 3880static void
fee0f4c6 3881bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3882 struct prefix *p, afi_t afi, safi_t safi)
3883{
3884 struct bgp_node *rn;
3885 struct bgp_info *ri;
3886
3887 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3888
3889 /* Check selected route and self inserted route. */
3890 for (ri = rn->info; ri; ri = ri->next)
3891 if (ri->peer == bgp->peer_self
3892 && ri->type == ZEBRA_ROUTE_BGP
3893 && ri->sub_type == BGP_ROUTE_STATIC)
3894 break;
3895
3896 /* Withdraw static BGP route from routing table. */
3897 if (ri)
3898 {
fee0f4c6 3899 bgp_info_delete (rn, ri);
1a392d46 3900 bgp_process (bgp, rn, afi, safi);
fee0f4c6 3901 }
3902
3903 /* Unlock bgp_node_lookup. */
3904 bgp_unlock_node (rn);
3905}
3906
94f2b392 3907static void
fee0f4c6 3908bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
fb982c25
PJ
3909 struct bgp_static *bgp_static,
3910 afi_t afi, safi_t safi)
fee0f4c6 3911{
3912 struct bgp_node *rn;
3913 struct bgp_info *ri;
3914 struct bgp_info *new;
3915 struct bgp_info info;
fee0f4c6 3916 struct attr *attr_new;
e16a4133 3917 struct attr attr;
558d1fec
JBD
3918 struct attr new_attr;
3919 struct attr_extra new_extra;
fee0f4c6 3920 struct bgp *bgp;
3921 int ret;
3922 char buf[SU_ADDRSTRLEN];
3923
3924 bgp = rsclient->bgp;
3925
06e110f9
PJ
3926 assert (bgp_static);
3927 if (!bgp_static)
3928 return;
3929
fee0f4c6 3930 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3931
3932 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
06e110f9
PJ
3933
3934 attr.nexthop = bgp_static->igpnexthop;
3935 attr.med = bgp_static->igpmetric;
3936 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
41367172 3937
41367172
PJ
3938 if (bgp_static->atomic)
3939 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3940
fee0f4c6 3941 /* Apply network route-map for export to this rsclient. */
3942 if (bgp_static->rmap.name)
3943 {
fb982c25 3944 struct attr attr_tmp = attr;
fee0f4c6 3945 info.peer = rsclient;
fb982c25
PJ
3946 info.attr = &attr_tmp;
3947
fee0f4c6 3948 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3949 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3950
3951 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3952
3953 rsclient->rmap_type = 0;
3954
3955 if (ret == RMAP_DENYMATCH)
3956 {
3957 /* Free uninterned attribute. */
fb982c25 3958 bgp_attr_flush (&attr_tmp);
fee0f4c6 3959
3960 /* Unintern original. */
f6f434b2 3961 aspath_unintern (&attr.aspath);
fee0f4c6 3962 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
fb982c25
PJ
3963 bgp_attr_extra_free (&attr);
3964
fee0f4c6 3965 return;
3966 }
fb982c25 3967 attr_new = bgp_attr_intern (&attr_tmp);
fee0f4c6 3968 }
3969 else
3970 attr_new = bgp_attr_intern (&attr);
558d1fec
JBD
3971
3972 new_attr.extra = &new_extra;
7badc263 3973 bgp_attr_dup(&new_attr, attr_new);
fb982c25 3974
fee0f4c6 3975 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3976
fb982c25
PJ
3977 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3978 == RMAP_DENY)
3979 {
fee0f4c6 3980 /* This BGP update is filtered. Log the reason then update BGP entry. */
3f9c7369 3981 if (bgp_debug_update(rsclient, p, NULL, 1))
16286195
DS
3982 zlog_debug ("Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3983 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3984 p->prefixlen, rsclient->host);
fee0f4c6 3985
3986 bgp->peer_self->rmap_type = 0;
3987
f6f434b2
PJ
3988 bgp_attr_unintern (&attr_new);
3989 aspath_unintern (&attr.aspath);
fb982c25 3990 bgp_attr_extra_free (&attr);
fee0f4c6 3991
3992 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3993
3994 return;
fb982c25 3995 }
fee0f4c6 3996
3997 bgp->peer_self->rmap_type = 0;
3998
f6f434b2 3999 bgp_attr_unintern (&attr_new);
fee0f4c6 4000 attr_new = bgp_attr_intern (&new_attr);
4001
4002 for (ri = rn->info; ri; ri = ri->next)
4003 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
4004 && ri->sub_type == BGP_ROUTE_STATIC)
4005 break;
4006
4007 if (ri)
4008 {
8d45210e 4009 if (attrhash_cmp (ri->attr, attr_new) &&
078430f6
DS
4010 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
4011 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
fee0f4c6 4012 {
4013 bgp_unlock_node (rn);
f6f434b2
PJ
4014 bgp_attr_unintern (&attr_new);
4015 aspath_unintern (&attr.aspath);
fb982c25 4016 bgp_attr_extra_free (&attr);
fee0f4c6 4017 return;
4018 }
4019 else
4020 {
4021 /* The attribute is changed. */
1a392d46 4022 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
fee0f4c6 4023
4024 /* Rewrite BGP route information. */
8d45210e
AS
4025 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
4026 bgp_info_restore(rn, ri);
f6f434b2 4027 bgp_attr_unintern (&ri->attr);
fee0f4c6 4028 ri->attr = attr_new;
65957886 4029 ri->uptime = bgp_clock ();
fee0f4c6 4030
fc9a856f
DS
4031 /* Nexthop reachability check. */
4032 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4033 {
75aead62 4034 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
fc9a856f
DS
4035 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
4036 else
4037 {
4038 if (BGP_DEBUG(nht, NHT))
4039 {
4040 char buf1[INET6_ADDRSTRLEN];
078430f6
DS
4041 inet_ntop (p->family, &p->u.prefix, buf1,
4042 INET6_ADDRSTRLEN);
4043 zlog_debug("%s(%s): Route not in table, not advertising",
4044 __FUNCTION__, buf1);
fc9a856f
DS
4045 }
4046 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
4047 }
4048 }
078430f6
DS
4049 else
4050 {
4051 /* Delete the NHT structure if any, if we're toggling between
4052 * enabling/disabling import check. We deregister the route
4053 * from NHT to avoid overloading NHT and the process interaction
4054 */
4055 bgp_unlink_nexthop(ri);
4056 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
4057 }
fee0f4c6 4058 /* Process change. */
4059 bgp_process (bgp, rn, afi, safi);
4060 bgp_unlock_node (rn);
f6f434b2 4061 aspath_unintern (&attr.aspath);
fb982c25 4062 bgp_attr_extra_free (&attr);
fee0f4c6 4063 return;
fb982c25 4064 }
fee0f4c6 4065 }
fb018d25 4066
fee0f4c6 4067 /* Make new BGP info. */
7c8ff89e 4068 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
fb018d25 4069 attr_new, rn);
fc9a856f
DS
4070 /* Nexthop reachability check. */
4071 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4072 {
75aead62 4073 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
fc9a856f
DS
4074 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
4075 else
4076 {
4077 if (BGP_DEBUG(nht, NHT))
4078 {
4079 char buf1[INET6_ADDRSTRLEN];
078430f6
DS
4080 inet_ntop(p->family, &p->u.prefix, buf1,
4081 INET6_ADDRSTRLEN);
4082 zlog_debug("%s(%s): Route not in table, not advertising", __FUNCTION__,
4083 buf1);
fc9a856f
DS
4084 }
4085 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
4086 }
4087 }
4088 else
078430f6
DS
4089 {
4090 /* Delete the NHT structure if any, if we're toggling between
4091 * enabling/disabling import check. We deregister the route
4092 * from NHT to avoid overloading NHT and the process interaction
4093 */
4094 bgp_unlink_nexthop(new);
4095 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
4096 }
fee0f4c6 4097
4098 /* Register new BGP information. */
4099 bgp_info_add (rn, new);
200df115 4100
4101 /* route_node_get lock */
4102 bgp_unlock_node (rn);
4103
fee0f4c6 4104 /* Process change. */
4105 bgp_process (bgp, rn, afi, safi);
4106
4107 /* Unintern original. */
f6f434b2 4108 aspath_unintern (&attr.aspath);
fb982c25 4109 bgp_attr_extra_free (&attr);
fee0f4c6 4110}
4111
94f2b392 4112static void
fee0f4c6 4113bgp_static_update_main (struct bgp *bgp, struct prefix *p,
fc9a856f 4114 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
718e3744 4115{
4116 struct bgp_node *rn;
4117 struct bgp_info *ri;
4118 struct bgp_info *new;
4119 struct bgp_info info;
e16a4133 4120 struct attr attr;
718e3744 4121 struct attr *attr_new;
4122 int ret;
4123
dd8103a9
PJ
4124 assert (bgp_static);
4125 if (!bgp_static)
4126 return;
4127
fee0f4c6 4128 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 4129
4130 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
dd8103a9
PJ
4131
4132 attr.nexthop = bgp_static->igpnexthop;
4133 attr.med = bgp_static->igpmetric;
4134 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
718e3744 4135
41367172
PJ
4136 if (bgp_static->atomic)
4137 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
4138
718e3744 4139 /* Apply route-map. */
4140 if (bgp_static->rmap.name)
4141 {
fb982c25 4142 struct attr attr_tmp = attr;
718e3744 4143 info.peer = bgp->peer_self;
286e1e71 4144 info.attr = &attr_tmp;
718e3744 4145
fee0f4c6 4146 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
4147
718e3744 4148 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
286e1e71 4149
fee0f4c6 4150 bgp->peer_self->rmap_type = 0;
4151
718e3744 4152 if (ret == RMAP_DENYMATCH)
4153 {
4154 /* Free uninterned attribute. */
286e1e71 4155 bgp_attr_flush (&attr_tmp);
718e3744 4156
4157 /* Unintern original. */
f6f434b2 4158 aspath_unintern (&attr.aspath);
fb982c25 4159 bgp_attr_extra_free (&attr);
718e3744 4160 bgp_static_withdraw (bgp, p, afi, safi);
4161 return;
4162 }
286e1e71 4163 attr_new = bgp_attr_intern (&attr_tmp);
718e3744 4164 }
286e1e71 4165 else
4166 attr_new = bgp_attr_intern (&attr);
718e3744 4167
4168 for (ri = rn->info; ri; ri = ri->next)
4169 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
4170 && ri->sub_type == BGP_ROUTE_STATIC)
4171 break;
4172
4173 if (ri)
4174 {
8d45210e 4175 if (attrhash_cmp (ri->attr, attr_new) &&
078430f6
DS
4176 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
4177 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
718e3744 4178 {
4179 bgp_unlock_node (rn);
f6f434b2
PJ
4180 bgp_attr_unintern (&attr_new);
4181 aspath_unintern (&attr.aspath);
fb982c25 4182 bgp_attr_extra_free (&attr);
718e3744 4183 return;
4184 }
4185 else
4186 {
4187 /* The attribute is changed. */
1a392d46 4188 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4189
4190 /* Rewrite BGP route information. */
8d45210e
AS
4191 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
4192 bgp_info_restore(rn, ri);
4193 else
4194 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
f6f434b2 4195 bgp_attr_unintern (&ri->attr);
718e3744 4196 ri->attr = attr_new;
65957886 4197 ri->uptime = bgp_clock ();
718e3744 4198
fc9a856f
DS
4199 /* Nexthop reachability check. */
4200 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4201 {
75aead62 4202 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
fc9a856f
DS
4203 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
4204 else
4205 {
4206 if (BGP_DEBUG(nht, NHT))
4207 {
4208 char buf1[INET6_ADDRSTRLEN];
078430f6
DS
4209 inet_ntop(p->family, &p->u.prefix, buf1,
4210 INET6_ADDRSTRLEN);
4211 zlog_debug("%s(%s): Route not in table, not advertising",
4212 __FUNCTION__, buf1);
fc9a856f
DS
4213 }
4214 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
4215 }
4216 }
078430f6
DS
4217 else
4218 {
4219 /* Delete the NHT structure if any, if we're toggling between
4220 * enabling/disabling import check. We deregister the route
4221 * from NHT to avoid overloading NHT and the process interaction
4222 */
4223 bgp_unlink_nexthop(ri);
4224 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
4225 }
718e3744 4226 /* Process change. */
4227 bgp_aggregate_increment (bgp, p, ri, afi, safi);
4228 bgp_process (bgp, rn, afi, safi);
4229 bgp_unlock_node (rn);
f6f434b2 4230 aspath_unintern (&attr.aspath);
fb982c25 4231 bgp_attr_extra_free (&attr);
718e3744 4232 return;
4233 }
4234 }
4235
4236 /* Make new BGP info. */
7c8ff89e 4237 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
fb018d25 4238 rn);
fc9a856f
DS
4239 /* Nexthop reachability check. */
4240 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4241 {
75aead62 4242 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
fc9a856f
DS
4243 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
4244 else
4245 {
4246 if (BGP_DEBUG(nht, NHT))
4247 {
4248 char buf1[INET6_ADDRSTRLEN];
078430f6 4249 inet_ntop(p->family, &p->u.prefix, buf1,
fc9a856f 4250 INET6_ADDRSTRLEN);
078430f6
DS
4251 zlog_debug("%s(%s): Route not in table, not advertising",
4252 __FUNCTION__, buf1);
fc9a856f
DS
4253 }
4254 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
4255 }
4256 }
4257 else
078430f6
DS
4258 {
4259 /* Delete the NHT structure if any, if we're toggling between
4260 * enabling/disabling import check. We deregister the route
4261 * from NHT to avoid overloading NHT and the process interaction
4262 */
4263 bgp_unlink_nexthop(new);
4264
4265 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
4266 }
718e3744 4267
4268 /* Aggregate address increment. */
4269 bgp_aggregate_increment (bgp, p, new, afi, safi);
4270
4271 /* Register new BGP information. */
4272 bgp_info_add (rn, new);
200df115 4273
4274 /* route_node_get lock */
4275 bgp_unlock_node (rn);
4276
718e3744 4277 /* Process change. */
4278 bgp_process (bgp, rn, afi, safi);
4279
4280 /* Unintern original. */
f6f434b2 4281 aspath_unintern (&attr.aspath);
fb982c25 4282 bgp_attr_extra_free (&attr);
718e3744 4283}
4284
fee0f4c6 4285void
4286bgp_static_update (struct bgp *bgp, struct prefix *p,
4287 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
4288{
4289 struct peer *rsclient;
1eb8ef25 4290 struct listnode *node, *nnode;
fee0f4c6 4291
4292 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
4293
1eb8ef25 4294 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 4295 {
da5b30f6
PJ
4296 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
4297 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
fee0f4c6 4298 }
4299}
4300
94f2b392 4301static void
4c9641ba
ML
4302bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
4303 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 4304{
4305 struct bgp_node *rn;
4306 struct bgp_info *new;
fb982c25 4307
fee0f4c6 4308 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 4309
4310 /* Make new BGP info. */
7c8ff89e 4311 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
fb018d25
DS
4312 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
4313
718e3744 4314 SET_FLAG (new->flags, BGP_INFO_VALID);
fb982c25
PJ
4315 new->extra = bgp_info_extra_new();
4316 memcpy (new->extra->tag, tag, 3);
718e3744 4317
4318 /* Aggregate address increment. */
200df115 4319 bgp_aggregate_increment (bgp, p, new, afi, safi);
718e3744 4320
4321 /* Register new BGP information. */
200df115 4322 bgp_info_add (rn, new);
718e3744 4323
200df115 4324 /* route_node_get lock */
4325 bgp_unlock_node (rn);
4326
718e3744 4327 /* Process change. */
4328 bgp_process (bgp, rn, afi, safi);
4329}
4330
4331void
4332bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
4333 safi_t safi)
4334{
4335 struct bgp_node *rn;
4336 struct bgp_info *ri;
4337
fee0f4c6 4338 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 4339
4340 /* Check selected route and self inserted route. */
4341 for (ri = rn->info; ri; ri = ri->next)
4342 if (ri->peer == bgp->peer_self
4343 && ri->type == ZEBRA_ROUTE_BGP
4344 && ri->sub_type == BGP_ROUTE_STATIC)
4345 break;
4346
4347 /* Withdraw static BGP route from routing table. */
4348 if (ri)
4349 {
4350 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
fc9a856f 4351 bgp_unlink_nexthop(ri);
718e3744 4352 bgp_info_delete (rn, ri);
1a392d46 4353 bgp_process (bgp, rn, afi, safi);
718e3744 4354 }
4355
4356 /* Unlock bgp_node_lookup. */
4357 bgp_unlock_node (rn);
4358}
4359
fee0f4c6 4360void
4361bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
4362{
4363 struct bgp_static *bgp_static;
4364 struct bgp *bgp;
4365 struct bgp_node *rn;
4366 struct prefix *p;
4367
4368 bgp = rsclient->bgp;
4369
4370 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4371 if ((bgp_static = rn->info) != NULL)
4372 {
4373 p = &rn->p;
4374
4375 bgp_static_update_rsclient (rsclient, p, bgp_static,
4376 afi, safi);
4377 }
4378}
4379
94f2b392 4380static void
4c9641ba
ML
4381bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
4382 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 4383{
4384 struct bgp_node *rn;
4385 struct bgp_info *ri;
4386
fee0f4c6 4387 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 4388
4389 /* Check selected route and self inserted route. */
4390 for (ri = rn->info; ri; ri = ri->next)
4391 if (ri->peer == bgp->peer_self
4392 && ri->type == ZEBRA_ROUTE_BGP
4393 && ri->sub_type == BGP_ROUTE_STATIC)
4394 break;
4395
4396 /* Withdraw static BGP route from routing table. */
4397 if (ri)
4398 {
4399 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
718e3744 4400 bgp_info_delete (rn, ri);
1a392d46 4401 bgp_process (bgp, rn, afi, safi);
718e3744 4402 }
4403
4404 /* Unlock bgp_node_lookup. */
4405 bgp_unlock_node (rn);
4406}
4407
4408/* Configure static BGP network. When user don't run zebra, static
4409 route should be installed as valid. */
94f2b392 4410static int
fd79ac91 4411bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
c8f3fe30 4412 afi_t afi, safi_t safi, const char *rmap, int backdoor)
718e3744 4413{
4414 int ret;
4415 struct prefix p;
4416 struct bgp_static *bgp_static;
4417 struct bgp_node *rn;
41367172 4418 u_char need_update = 0;
718e3744 4419
4420 /* Convert IP prefix string to struct prefix. */
4421 ret = str2prefix (ip_str, &p);
4422 if (! ret)
4423 {
4424 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4425 return CMD_WARNING;
4426 }
4427#ifdef HAVE_IPV6
4428 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4429 {
4430 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4431 VTY_NEWLINE);
4432 return CMD_WARNING;
4433 }
4434#endif /* HAVE_IPV6 */
4435
4436 apply_mask (&p);
4437
4438 /* Set BGP static route configuration. */
4439 rn = bgp_node_get (bgp->route[afi][safi], &p);
4440
4441 if (rn->info)
4442 {
4443 /* Configuration change. */
4444 bgp_static = rn->info;
4445
4446 /* Check previous routes are installed into BGP. */
c8f3fe30
PJ
4447 if (bgp_static->valid && bgp_static->backdoor != backdoor)
4448 need_update = 1;
41367172 4449
718e3744 4450 bgp_static->backdoor = backdoor;
41367172 4451
718e3744 4452 if (rmap)
4453 {
4454 if (bgp_static->rmap.name)
4455 free (bgp_static->rmap.name);
4456 bgp_static->rmap.name = strdup (rmap);
4457 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4458 }
4459 else
4460 {
4461 if (bgp_static->rmap.name)
4462 free (bgp_static->rmap.name);
4463 bgp_static->rmap.name = NULL;
4464 bgp_static->rmap.map = NULL;
4465 bgp_static->valid = 0;
4466 }
4467 bgp_unlock_node (rn);
4468 }
4469 else
4470 {
4471 /* New configuration. */
4472 bgp_static = bgp_static_new ();
4473 bgp_static->backdoor = backdoor;
4474 bgp_static->valid = 0;
4475 bgp_static->igpmetric = 0;
4476 bgp_static->igpnexthop.s_addr = 0;
41367172 4477
718e3744 4478 if (rmap)
4479 {
4480 if (bgp_static->rmap.name)
4481 free (bgp_static->rmap.name);
4482 bgp_static->rmap.name = strdup (rmap);
4483 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4484 }
4485 rn->info = bgp_static;
4486 }
4487
fc9a856f
DS
4488 bgp_static->valid = 1;
4489 if (need_update)
4490 bgp_static_withdraw (bgp, &p, afi, safi);
718e3744 4491
fc9a856f
DS
4492 if (! bgp_static->backdoor)
4493 bgp_static_update (bgp, &p, bgp_static, afi, safi);
718e3744 4494
4495 return CMD_SUCCESS;
4496}
4497
4498/* Configure static BGP network. */
94f2b392 4499static int
fd79ac91 4500bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4c9641ba 4501 afi_t afi, safi_t safi)
718e3744 4502{
4503 int ret;
4504 struct prefix p;
4505 struct bgp_static *bgp_static;
4506 struct bgp_node *rn;
4507
4508 /* Convert IP prefix string to struct prefix. */
4509 ret = str2prefix (ip_str, &p);
4510 if (! ret)
4511 {
4512 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4513 return CMD_WARNING;
4514 }
4515#ifdef HAVE_IPV6
4516 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4517 {
4518 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4519 VTY_NEWLINE);
4520 return CMD_WARNING;
4521 }
4522#endif /* HAVE_IPV6 */
4523
4524 apply_mask (&p);
4525
4526 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4527 if (! rn)
4528 {
4529 vty_out (vty, "%% Can't find specified static route configuration.%s",
4530 VTY_NEWLINE);
4531 return CMD_WARNING;
4532 }
4533
4534 bgp_static = rn->info;
41367172 4535
718e3744 4536 /* Update BGP RIB. */
4537 if (! bgp_static->backdoor)
4538 bgp_static_withdraw (bgp, &p, afi, safi);
4539
4540 /* Clear configuration. */
4541 bgp_static_free (bgp_static);
4542 rn->info = NULL;
4543 bgp_unlock_node (rn);
4544 bgp_unlock_node (rn);
4545
4546 return CMD_SUCCESS;
4547}
4548
4549/* Called from bgp_delete(). Delete all static routes from the BGP
4550 instance. */
4551void
4552bgp_static_delete (struct bgp *bgp)
4553{
4554 afi_t afi;
4555 safi_t safi;
4556 struct bgp_node *rn;
4557 struct bgp_node *rm;
4558 struct bgp_table *table;
4559 struct bgp_static *bgp_static;
4560
4561 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4562 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4563 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4564 if (rn->info != NULL)
4565 {
4566 if (safi == SAFI_MPLS_VPN)
4567 {
4568 table = rn->info;
4569
4570 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4571 {
4572 bgp_static = rn->info;
4573 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
4574 AFI_IP, SAFI_MPLS_VPN,
4575 (struct prefix_rd *)&rn->p,
4576 bgp_static->tag);
4577 bgp_static_free (bgp_static);
4578 rn->info = NULL;
4579 bgp_unlock_node (rn);
4580 }
4581 }
4582 else
4583 {
4584 bgp_static = rn->info;
4585 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4586 bgp_static_free (bgp_static);
4587 rn->info = NULL;
4588 bgp_unlock_node (rn);
4589 }
4590 }
4591}
4592
078430f6
DS
4593void
4594bgp_static_redo_import_check (struct bgp *bgp)
4595{
4596 afi_t afi;
4597 safi_t safi;
4598 struct bgp_node *rn;
078430f6
DS
4599 struct bgp_static *bgp_static;
4600
4601 /* Use this flag to force reprocessing of the route */
4602 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4603 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4604 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4605 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4606 if (rn->info != NULL)
4607 {
4608 bgp_static = rn->info;
4609 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
4610 }
4611 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4612}
4613
718e3744 4614int
fd79ac91 4615bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
4616 const char *tag_str)
718e3744 4617{
4618 int ret;
4619 struct prefix p;
4620 struct prefix_rd prd;
4621 struct bgp *bgp;
4622 struct bgp_node *prn;
4623 struct bgp_node *rn;
4624 struct bgp_table *table;
4625 struct bgp_static *bgp_static;
4626 u_char tag[3];
4627
4628 bgp = vty->index;
4629
4630 ret = str2prefix (ip_str, &p);
4631 if (! ret)
4632 {
4633 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4634 return CMD_WARNING;
4635 }
4636 apply_mask (&p);
4637
4638 ret = str2prefix_rd (rd_str, &prd);
4639 if (! ret)
4640 {
4641 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4642 return CMD_WARNING;
4643 }
4644
4645 ret = str2tag (tag_str, tag);
4646 if (! ret)
4647 {
4648 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4649 return CMD_WARNING;
4650 }
4651
4652 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4653 (struct prefix *)&prd);
4654 if (prn->info == NULL)
64e580a7 4655 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
718e3744 4656 else
4657 bgp_unlock_node (prn);
4658 table = prn->info;
4659
4660 rn = bgp_node_get (table, &p);
4661
4662 if (rn->info)
4663 {
4664 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4665 bgp_unlock_node (rn);
4666 }
4667 else
4668 {
4669 /* New configuration. */
4670 bgp_static = bgp_static_new ();
4671 bgp_static->valid = 1;
4672 memcpy (bgp_static->tag, tag, 3);
4673 rn->info = bgp_static;
4674
4675 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4676 }
4677
4678 return CMD_SUCCESS;
4679}
4680
4681/* Configure static BGP network. */
4682int
fd79ac91 4683bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
4684 const char *rd_str, const char *tag_str)
718e3744 4685{
4686 int ret;
4687 struct bgp *bgp;
4688 struct prefix p;
4689 struct prefix_rd prd;
4690 struct bgp_node *prn;
4691 struct bgp_node *rn;
4692 struct bgp_table *table;
4693 struct bgp_static *bgp_static;
4694 u_char tag[3];
4695
4696 bgp = vty->index;
4697
4698 /* Convert IP prefix string to struct prefix. */
4699 ret = str2prefix (ip_str, &p);
4700 if (! ret)
4701 {
4702 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4703 return CMD_WARNING;
4704 }
4705 apply_mask (&p);
4706
4707 ret = str2prefix_rd (rd_str, &prd);
4708 if (! ret)
4709 {
4710 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4711 return CMD_WARNING;
4712 }
4713
4714 ret = str2tag (tag_str, tag);
4715 if (! ret)
4716 {
4717 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4718 return CMD_WARNING;
4719 }
4720
4721 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4722 (struct prefix *)&prd);
4723 if (prn->info == NULL)
64e580a7 4724 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
718e3744 4725 else
4726 bgp_unlock_node (prn);
4727 table = prn->info;
4728
4729 rn = bgp_node_lookup (table, &p);
4730
4731 if (rn)
4732 {
4733 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4734
4735 bgp_static = rn->info;
4736 bgp_static_free (bgp_static);
4737 rn->info = NULL;
4738 bgp_unlock_node (rn);
4739 bgp_unlock_node (rn);
4740 }
4741 else
4742 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4743
4744 return CMD_SUCCESS;
4745}
6b0655a2 4746
73ac8160
DS
4747static int
4748bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4749 const char *rmap_name)
4750{
4751 struct bgp_rmap *rmap;
4752
4753 rmap = &bgp->table_map[afi][safi];
4754 if (rmap_name)
4755 {
4756 if (rmap->name)
4757 free (rmap->name);
4758 rmap->name = strdup (rmap_name);
4759 rmap->map = route_map_lookup_by_name (rmap_name);
4760 }
4761 else
4762 {
4763 if (rmap->name)
4764 free (rmap->name);
4765 rmap->name = NULL;
4766 rmap->map = NULL;
4767 }
4768
4769 bgp_zebra_announce_table(bgp, afi, safi);
4770
4771 return CMD_SUCCESS;
4772}
4773
4774static int
4775bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4776 const char *rmap_name)
4777{
4778 struct bgp_rmap *rmap;
4779
4780 rmap = &bgp->table_map[afi][safi];
4781 if (rmap->name)
4782 free (rmap->name);
4783 rmap->name = NULL;
4784 rmap->map = NULL;
4785
4786 bgp_zebra_announce_table(bgp, afi, safi);
4787
4788 return CMD_SUCCESS;
4789}
4790
4791int
4792bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4793 safi_t safi, int *write)
4794{
4795 if (bgp->table_map[afi][safi].name)
4796 {
4797 bgp_config_write_family_header (vty, afi, safi, write);
4798 vty_out (vty, " table-map %s%s",
4799 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4800 }
4801
4802 return 0;
4803}
4804
4805
4806DEFUN (bgp_table_map,
4807 bgp_table_map_cmd,
4808 "table-map WORD",
4809 "BGP table to RIB route download filter\n"
4810 "Name of the route map\n")
4811{
4812 return bgp_table_map_set (vty, vty->index,
4813 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4814}
4815DEFUN (no_bgp_table_map,
4816 no_bgp_table_map_cmd,
4817 "no table-map WORD",
4818 "BGP table to RIB route download filter\n"
4819 "Name of the route map\n")
4820{
4821 return bgp_table_map_unset (vty, vty->index,
4822 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4823}
4824
718e3744 4825DEFUN (bgp_network,
4826 bgp_network_cmd,
4827 "network A.B.C.D/M",
4828 "Specify a network to announce via BGP\n"
4829 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4830{
4831 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 4832 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4833}
4834
4835DEFUN (bgp_network_route_map,
4836 bgp_network_route_map_cmd,
4837 "network A.B.C.D/M route-map WORD",
4838 "Specify a network to announce via BGP\n"
4839 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4840 "Route-map to modify the attributes\n"
4841 "Name of the route map\n")
4842{
4843 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 4844 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 4845}
4846
4847DEFUN (bgp_network_backdoor,
4848 bgp_network_backdoor_cmd,
4849 "network A.B.C.D/M backdoor",
4850 "Specify a network to announce via BGP\n"
4851 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4852 "Specify a BGP backdoor route\n")
4853{
41367172 4854 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
c8f3fe30 4855 NULL, 1);
718e3744 4856}
4857
4858DEFUN (bgp_network_mask,
4859 bgp_network_mask_cmd,
4860 "network A.B.C.D mask A.B.C.D",
4861 "Specify a network to announce via BGP\n"
4862 "Network number\n"
4863 "Network mask\n"
4864 "Network mask\n")
4865{
4866 int ret;
4867 char prefix_str[BUFSIZ];
41367172 4868
718e3744 4869 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4870 if (! ret)
4871 {
4872 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4873 return CMD_WARNING;
4874 }
4875
4876 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4877 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4878}
4879
4880DEFUN (bgp_network_mask_route_map,
4881 bgp_network_mask_route_map_cmd,
4882 "network A.B.C.D mask A.B.C.D route-map WORD",
4883 "Specify a network to announce via BGP\n"
4884 "Network number\n"
4885 "Network mask\n"
4886 "Network mask\n"
4887 "Route-map to modify the attributes\n"
4888 "Name of the route map\n")
4889{
4890 int ret;
4891 char prefix_str[BUFSIZ];
41367172 4892
718e3744 4893 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4894 if (! ret)
4895 {
4896 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4897 return CMD_WARNING;
4898 }
4899
4900 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4901 AFI_IP, bgp_node_safi (vty), argv[2], 0);
718e3744 4902}
4903
4904DEFUN (bgp_network_mask_backdoor,
4905 bgp_network_mask_backdoor_cmd,
4906 "network A.B.C.D mask A.B.C.D backdoor",
4907 "Specify a network to announce via BGP\n"
4908 "Network number\n"
4909 "Network mask\n"
4910 "Network mask\n"
4911 "Specify a BGP backdoor route\n")
4912{
4913 int ret;
4914 char prefix_str[BUFSIZ];
41367172 4915
718e3744 4916 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4917 if (! ret)
4918 {
4919 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4920 return CMD_WARNING;
4921 }
4922
41367172 4923 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 4924 NULL, 1);
718e3744 4925}
4926
4927DEFUN (bgp_network_mask_natural,
4928 bgp_network_mask_natural_cmd,
4929 "network A.B.C.D",
4930 "Specify a network to announce via BGP\n"
4931 "Network number\n")
4932{
4933 int ret;
4934 char prefix_str[BUFSIZ];
4935
4936 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4937 if (! ret)
4938 {
4939 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4940 return CMD_WARNING;
4941 }
4942
4943 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4944 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4945}
4946
4947DEFUN (bgp_network_mask_natural_route_map,
4948 bgp_network_mask_natural_route_map_cmd,
4949 "network A.B.C.D route-map WORD",
4950 "Specify a network to announce via BGP\n"
4951 "Network number\n"
4952 "Route-map to modify the attributes\n"
4953 "Name of the route map\n")
4954{
4955 int ret;
4956 char prefix_str[BUFSIZ];
4957
4958 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4959 if (! ret)
4960 {
4961 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4962 return CMD_WARNING;
4963 }
4964
4965 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4966 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 4967}
4968
4969DEFUN (bgp_network_mask_natural_backdoor,
4970 bgp_network_mask_natural_backdoor_cmd,
4971 "network A.B.C.D backdoor",
4972 "Specify a network to announce via BGP\n"
4973 "Network number\n"
4974 "Specify a BGP backdoor route\n")
4975{
4976 int ret;
4977 char prefix_str[BUFSIZ];
4978
4979 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4980 if (! ret)
4981 {
4982 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4983 return CMD_WARNING;
4984 }
4985
41367172 4986 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 4987 NULL, 1);
718e3744 4988}
4989
4990DEFUN (no_bgp_network,
4991 no_bgp_network_cmd,
4992 "no network A.B.C.D/M",
4993 NO_STR
4994 "Specify a network to announce via BGP\n"
4995 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4996{
4997 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4998 bgp_node_safi (vty));
4999}
5000
5001ALIAS (no_bgp_network,
5002 no_bgp_network_route_map_cmd,
5003 "no network A.B.C.D/M route-map WORD",
5004 NO_STR
5005 "Specify a network to announce via BGP\n"
5006 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5007 "Route-map to modify the attributes\n"
5008 "Name of the route map\n")
5009
5010ALIAS (no_bgp_network,
5011 no_bgp_network_backdoor_cmd,
5012 "no network A.B.C.D/M backdoor",
5013 NO_STR
5014 "Specify a network to announce via BGP\n"
5015 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5016 "Specify a BGP backdoor route\n")
5017
5018DEFUN (no_bgp_network_mask,
5019 no_bgp_network_mask_cmd,
5020 "no network A.B.C.D mask A.B.C.D",
5021 NO_STR
5022 "Specify a network to announce via BGP\n"
5023 "Network number\n"
5024 "Network mask\n"
5025 "Network mask\n")
5026{
5027 int ret;
5028 char prefix_str[BUFSIZ];
5029
5030 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5031 if (! ret)
5032 {
5033 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5034 return CMD_WARNING;
5035 }
5036
5037 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
5038 bgp_node_safi (vty));
5039}
5040
5041ALIAS (no_bgp_network_mask,
5042 no_bgp_network_mask_route_map_cmd,
5043 "no network A.B.C.D mask A.B.C.D route-map WORD",
5044 NO_STR
5045 "Specify a network to announce via BGP\n"
5046 "Network number\n"
5047 "Network mask\n"
5048 "Network mask\n"
5049 "Route-map to modify the attributes\n"
5050 "Name of the route map\n")
5051
5052ALIAS (no_bgp_network_mask,
5053 no_bgp_network_mask_backdoor_cmd,
5054 "no network A.B.C.D mask A.B.C.D backdoor",
5055 NO_STR
5056 "Specify a network to announce via BGP\n"
5057 "Network number\n"
5058 "Network mask\n"
5059 "Network mask\n"
5060 "Specify a BGP backdoor route\n")
5061
5062DEFUN (no_bgp_network_mask_natural,
5063 no_bgp_network_mask_natural_cmd,
5064 "no network A.B.C.D",
5065 NO_STR
5066 "Specify a network to announce via BGP\n"
5067 "Network number\n")
5068{
5069 int ret;
5070 char prefix_str[BUFSIZ];
5071
5072 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
5073 if (! ret)
5074 {
5075 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5076 return CMD_WARNING;
5077 }
5078
5079 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
5080 bgp_node_safi (vty));
5081}
5082
5083ALIAS (no_bgp_network_mask_natural,
5084 no_bgp_network_mask_natural_route_map_cmd,
5085 "no network A.B.C.D route-map WORD",
5086 NO_STR
5087 "Specify a network to announce via BGP\n"
5088 "Network number\n"
5089 "Route-map to modify the attributes\n"
5090 "Name of the route map\n")
5091
5092ALIAS (no_bgp_network_mask_natural,
5093 no_bgp_network_mask_natural_backdoor_cmd,
5094 "no network A.B.C.D backdoor",
5095 NO_STR
5096 "Specify a network to announce via BGP\n"
5097 "Network number\n"
5098 "Specify a BGP backdoor route\n")
5099
5100#ifdef HAVE_IPV6
5101DEFUN (ipv6_bgp_network,
5102 ipv6_bgp_network_cmd,
5103 "network X:X::X:X/M",
5104 "Specify a network to announce via BGP\n"
5105 "IPv6 prefix <network>/<length>\n")
5106{
73bfe0bd 5107 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
c8f3fe30 5108 NULL, 0);
718e3744 5109}
5110
5111DEFUN (ipv6_bgp_network_route_map,
5112 ipv6_bgp_network_route_map_cmd,
5113 "network X:X::X:X/M route-map WORD",
5114 "Specify a network to announce via BGP\n"
5115 "IPv6 prefix <network>/<length>\n"
5116 "Route-map to modify the attributes\n"
5117 "Name of the route map\n")
5118{
5119 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
c8f3fe30 5120 bgp_node_safi (vty), argv[1], 0);
718e3744 5121}
5122
5123DEFUN (no_ipv6_bgp_network,
5124 no_ipv6_bgp_network_cmd,
5125 "no network X:X::X:X/M",
5126 NO_STR
5127 "Specify a network to announce via BGP\n"
5128 "IPv6 prefix <network>/<length>\n")
5129{
73bfe0bd 5130 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
718e3744 5131}
5132
5133ALIAS (no_ipv6_bgp_network,
5134 no_ipv6_bgp_network_route_map_cmd,
5135 "no network X:X::X:X/M route-map WORD",
5136 NO_STR
5137 "Specify a network to announce via BGP\n"
5138 "IPv6 prefix <network>/<length>\n"
5139 "Route-map to modify the attributes\n"
5140 "Name of the route map\n")
5141
5142ALIAS (ipv6_bgp_network,
5143 old_ipv6_bgp_network_cmd,
5144 "ipv6 bgp network X:X::X:X/M",
5145 IPV6_STR
5146 BGP_STR
5147 "Specify a network to announce via BGP\n"
5148 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5149
5150ALIAS (no_ipv6_bgp_network,
5151 old_no_ipv6_bgp_network_cmd,
5152 "no ipv6 bgp network X:X::X:X/M",
5153 NO_STR
5154 IPV6_STR
5155 BGP_STR
5156 "Specify a network to announce via BGP\n"
5157 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5158#endif /* HAVE_IPV6 */
c8f3fe30
PJ
5159
5160/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
5161ALIAS_DEPRECATED (bgp_network,
5162 bgp_network_ttl_cmd,
5163 "network A.B.C.D/M pathlimit <0-255>",
5164 "Specify a network to announce via BGP\n"
5165 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5166 "AS-Path hopcount limit attribute\n"
5167 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5168ALIAS_DEPRECATED (bgp_network_backdoor,
5169 bgp_network_backdoor_ttl_cmd,
5170 "network A.B.C.D/M backdoor pathlimit <0-255>",
5171 "Specify a network to announce via BGP\n"
5172 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5173 "Specify a BGP backdoor route\n"
5174 "AS-Path hopcount limit attribute\n"
5175 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5176ALIAS_DEPRECATED (bgp_network_mask,
5177 bgp_network_mask_ttl_cmd,
5178 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
5179 "Specify a network to announce via BGP\n"
5180 "Network number\n"
5181 "Network mask\n"
5182 "Network mask\n"
5183 "AS-Path hopcount limit attribute\n"
5184 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5185ALIAS_DEPRECATED (bgp_network_mask_backdoor,
5186 bgp_network_mask_backdoor_ttl_cmd,
5187 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
5188 "Specify a network to announce via BGP\n"
5189 "Network number\n"
5190 "Network mask\n"
5191 "Network mask\n"
5192 "Specify a BGP backdoor route\n"
5193 "AS-Path hopcount limit attribute\n"
5194 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5195ALIAS_DEPRECATED (bgp_network_mask_natural,
5196 bgp_network_mask_natural_ttl_cmd,
5197 "network A.B.C.D pathlimit <0-255>",
5198 "Specify a network to announce via BGP\n"
5199 "Network number\n"
5200 "AS-Path hopcount limit attribute\n"
5201 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5202ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
5203 bgp_network_mask_natural_backdoor_ttl_cmd,
2b00515a 5204 "network A.B.C.D backdoor pathlimit <1-255>",
c8f3fe30
PJ
5205 "Specify a network to announce via BGP\n"
5206 "Network number\n"
5207 "Specify a BGP backdoor route\n"
5208 "AS-Path hopcount limit attribute\n"
5209 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5210ALIAS_DEPRECATED (no_bgp_network,
5211 no_bgp_network_ttl_cmd,
5212 "no network A.B.C.D/M pathlimit <0-255>",
5213 NO_STR
5214 "Specify a network to announce via BGP\n"
5215 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5216 "AS-Path hopcount limit attribute\n"
5217 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5218ALIAS_DEPRECATED (no_bgp_network,
5219 no_bgp_network_backdoor_ttl_cmd,
5220 "no network A.B.C.D/M backdoor pathlimit <0-255>",
5221 NO_STR
5222 "Specify a network to announce via BGP\n"
5223 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5224 "Specify a BGP backdoor route\n"
5225 "AS-Path hopcount limit attribute\n"
5226 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5227ALIAS_DEPRECATED (no_bgp_network,
5228 no_bgp_network_mask_ttl_cmd,
5229 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
5230 NO_STR
5231 "Specify a network to announce via BGP\n"
5232 "Network number\n"
5233 "Network mask\n"
5234 "Network mask\n"
5235 "AS-Path hopcount limit attribute\n"
5236 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5237ALIAS_DEPRECATED (no_bgp_network_mask,
5238 no_bgp_network_mask_backdoor_ttl_cmd,
5239 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
5240 NO_STR
5241 "Specify a network to announce via BGP\n"
5242 "Network number\n"
5243 "Network mask\n"
5244 "Network mask\n"
5245 "Specify a BGP backdoor route\n"
5246 "AS-Path hopcount limit attribute\n"
5247 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5248ALIAS_DEPRECATED (no_bgp_network_mask_natural,
5249 no_bgp_network_mask_natural_ttl_cmd,
5250 "no network A.B.C.D pathlimit <0-255>",
5251 NO_STR
5252 "Specify a network to announce via BGP\n"
5253 "Network number\n"
5254 "AS-Path hopcount limit attribute\n"
5255 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5256ALIAS_DEPRECATED (no_bgp_network_mask_natural,
5257 no_bgp_network_mask_natural_backdoor_ttl_cmd,
5258 "no network A.B.C.D backdoor pathlimit <0-255>",
5259 NO_STR
5260 "Specify a network to announce via BGP\n"
5261 "Network number\n"
5262 "Specify a BGP backdoor route\n"
5263 "AS-Path hopcount limit attribute\n"
5264 "AS-Pathlimit TTL, in number of AS-Path hops\n")
3bde17f1 5265#ifdef HAVE_IPV6
c8f3fe30
PJ
5266ALIAS_DEPRECATED (ipv6_bgp_network,
5267 ipv6_bgp_network_ttl_cmd,
5268 "network X:X::X:X/M pathlimit <0-255>",
5269 "Specify a network to announce via BGP\n"
5270 "IPv6 prefix <network>/<length>\n"
5271 "AS-Path hopcount limit attribute\n"
5272 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5273ALIAS_DEPRECATED (no_ipv6_bgp_network,
5274 no_ipv6_bgp_network_ttl_cmd,
5275 "no network X:X::X:X/M pathlimit <0-255>",
5276 NO_STR
5277 "Specify a network to announce via BGP\n"
5278 "IPv6 prefix <network>/<length>\n"
5279 "AS-Path hopcount limit attribute\n"
5280 "AS-Pathlimit TTL, in number of AS-Path hops\n")
3bde17f1 5281#endif /* HAVE_IPV6 */
6b0655a2 5282
718e3744 5283/* Aggreagete address:
5284
5285 advertise-map Set condition to advertise attribute
5286 as-set Generate AS set path information
5287 attribute-map Set attributes of aggregate
5288 route-map Set parameters of aggregate
5289 summary-only Filter more specific routes from updates
5290 suppress-map Conditionally filter more specific routes from updates
5291 <cr>
5292 */
5293struct bgp_aggregate
5294{
5295 /* Summary-only flag. */
5296 u_char summary_only;
5297
5298 /* AS set generation. */
5299 u_char as_set;
5300
5301 /* Route-map for aggregated route. */
5302 struct route_map *map;
5303
5304 /* Suppress-count. */
5305 unsigned long count;
5306
5307 /* SAFI configuration. */
5308 safi_t safi;
5309};
5310
94f2b392 5311static struct bgp_aggregate *
66e5cd87 5312bgp_aggregate_new (void)
718e3744 5313{
393deb9b 5314 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
718e3744 5315}
5316
94f2b392 5317static void
718e3744 5318bgp_aggregate_free (struct bgp_aggregate *aggregate)
5319{
5320 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
5321}
5322
b5d58c32 5323/* Update an aggregate as routes are added/removed from the BGP table */
94f2b392 5324static void
718e3744 5325bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
5326 afi_t afi, safi_t safi, struct bgp_info *del,
5327 struct bgp_aggregate *aggregate)
5328{
5329 struct bgp_table *table;
5330 struct bgp_node *top;
5331 struct bgp_node *rn;
5332 u_char origin;
5333 struct aspath *aspath = NULL;
5334 struct aspath *asmerge = NULL;
5335 struct community *community = NULL;
5336 struct community *commerge = NULL;
ffd0c037 5337#if defined(AGGREGATE_NEXTHOP_CHECK)
718e3744 5338 struct in_addr nexthop;
5339 u_int32_t med = 0;
ffd0c037 5340#endif
718e3744 5341 struct bgp_info *ri;
5342 struct bgp_info *new;
5343 int first = 1;
5344 unsigned long match = 0;
42f7e184 5345 u_char atomic_aggregate = 0;
718e3744 5346
5347 /* Record adding route's nexthop and med. */
ffd0c037
DS
5348 if (rinew)
5349 {
5350#if defined(AGGREGATE_NEXTHOP_CHECK)
5351 nexthop = rinew->attr->nexthop;
5352 med = rinew->attr->med;
5353#endif
5354 }
718e3744 5355
5356 /* ORIGIN attribute: If at least one route among routes that are
5357 aggregated has ORIGIN with the value INCOMPLETE, then the
5358 aggregated route must have the ORIGIN attribute with the value
5359 INCOMPLETE. Otherwise, if at least one route among routes that
5360 are aggregated has ORIGIN with the value EGP, then the aggregated
5361 route must have the origin attribute with the value EGP. In all
5362 other case the value of the ORIGIN attribute of the aggregated
5363 route is INTERNAL. */
5364 origin = BGP_ORIGIN_IGP;
5365
5366 table = bgp->rib[afi][safi];
5367
5368 top = bgp_node_get (table, p);
5369 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5370 if (rn->p.prefixlen > p->prefixlen)
5371 {
5372 match = 0;
5373
5374 for (ri = rn->info; ri; ri = ri->next)
5375 {
5376 if (BGP_INFO_HOLDDOWN (ri))
5377 continue;
5378
5379 if (del && ri == del)
5380 continue;
5381
5382 if (! rinew && first)
5383 {
ffd0c037 5384#if defined(AGGREGATE_NEXTHOP_CHECK)
718e3744 5385 nexthop = ri->attr->nexthop;
5386 med = ri->attr->med;
ffd0c037 5387#endif
718e3744 5388 first = 0;
5389 }
5390
5391#ifdef AGGREGATE_NEXTHOP_CHECK
5392 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
5393 || ri->attr->med != med)
5394 {
5395 if (aspath)
5396 aspath_free (aspath);
5397 if (community)
5398 community_free (community);
5399 bgp_unlock_node (rn);
5400 bgp_unlock_node (top);
5401 return;
5402 }
5403#endif /* AGGREGATE_NEXTHOP_CHECK */
5404
42f7e184
DS
5405 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5406 atomic_aggregate = 1;
5407
718e3744 5408 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5409 {
5410 if (aggregate->summary_only)
5411 {
fb982c25 5412 (bgp_info_extra_get (ri))->suppress++;
1a392d46 5413 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5414 match++;
5415 }
5416
5417 aggregate->count++;
5418
b5d58c32
DS
5419 if (origin < ri->attr->origin)
5420 origin = ri->attr->origin;
5421
718e3744 5422 if (aggregate->as_set)
5423 {
718e3744 5424 if (aspath)
5425 {
5426 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5427 aspath_free (aspath);
5428 aspath = asmerge;
5429 }
5430 else
5431 aspath = aspath_dup (ri->attr->aspath);
5432
5433 if (ri->attr->community)
5434 {
5435 if (community)
5436 {
5437 commerge = community_merge (community,
5438 ri->attr->community);
5439 community = community_uniq_sort (commerge);
5440 community_free (commerge);
5441 }
5442 else
5443 community = community_dup (ri->attr->community);
5444 }
5445 }
5446 }
5447 }
5448 if (match)
5449 bgp_process (bgp, rn, afi, safi);
5450 }
5451 bgp_unlock_node (top);
5452
5453 if (rinew)
5454 {
5455 aggregate->count++;
5456
5457 if (aggregate->summary_only)
fb982c25 5458 (bgp_info_extra_get (rinew))->suppress++;
718e3744 5459
b5d58c32
DS
5460 if (origin < rinew->attr->origin)
5461 origin = rinew->attr->origin;
5462
718e3744 5463 if (aggregate->as_set)
5464 {
718e3744 5465 if (aspath)
5466 {
5467 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
5468 aspath_free (aspath);
5469 aspath = asmerge;
5470 }
5471 else
5472 aspath = aspath_dup (rinew->attr->aspath);
5473
5474 if (rinew->attr->community)
5475 {
5476 if (community)
5477 {
5478 commerge = community_merge (community,
5479 rinew->attr->community);
5480 community = community_uniq_sort (commerge);
5481 community_free (commerge);
5482 }
5483 else
5484 community = community_dup (rinew->attr->community);
5485 }
5486 }
5487 }
5488
5489 if (aggregate->count > 0)
5490 {
5491 rn = bgp_node_get (table, p);
7c8ff89e 5492 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 5493 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
5494 aggregate->as_set,
5495 atomic_aggregate), rn);
718e3744 5496 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 5497
5498 bgp_info_add (rn, new);
200df115 5499 bgp_unlock_node (rn);
718e3744 5500 bgp_process (bgp, rn, afi, safi);
5501 }
5502 else
5503 {
5504 if (aspath)
5505 aspath_free (aspath);
5506 if (community)
5507 community_free (community);
5508 }
5509}
5510
5511void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
5512 struct bgp_aggregate *);
5513
5514void
5515bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
5516 struct bgp_info *ri, afi_t afi, safi_t safi)
5517{
5518 struct bgp_node *child;
5519 struct bgp_node *rn;
5520 struct bgp_aggregate *aggregate;
f018db83 5521 struct bgp_table *table;
718e3744 5522
5523 /* MPLS-VPN aggregation is not yet supported. */
5524 if (safi == SAFI_MPLS_VPN)
5525 return;
5526
f018db83
JBD
5527 table = bgp->aggregate[afi][safi];
5528
5529 /* No aggregates configured. */
67174041 5530 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
5531 return;
5532
718e3744 5533 if (p->prefixlen == 0)
5534 return;
5535
5536 if (BGP_INFO_HOLDDOWN (ri))
5537 return;
5538
bb782fb5 5539 child = bgp_node_get (table, p);
718e3744 5540
5541 /* Aggregate address configuration check. */
67174041 5542 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 5543 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5544 {
5545 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 5546 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
718e3744 5547 }
5548 bgp_unlock_node (child);
5549}
5550
5551void
5552bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
5553 struct bgp_info *del, afi_t afi, safi_t safi)
5554{
5555 struct bgp_node *child;
5556 struct bgp_node *rn;
5557 struct bgp_aggregate *aggregate;
f018db83 5558 struct bgp_table *table;
718e3744 5559
5560 /* MPLS-VPN aggregation is not yet supported. */
5561 if (safi == SAFI_MPLS_VPN)
5562 return;
5563
f018db83
JBD
5564 table = bgp->aggregate[afi][safi];
5565
5566 /* No aggregates configured. */
67174041 5567 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
5568 return;
5569
718e3744 5570 if (p->prefixlen == 0)
5571 return;
5572
bb782fb5 5573 child = bgp_node_get (table, p);
718e3744 5574
5575 /* Aggregate address configuration check. */
67174041 5576 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 5577 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5578 {
5579 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 5580 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
718e3744 5581 }
5582 bgp_unlock_node (child);
5583}
5584
b5d58c32 5585/* Called via bgp_aggregate_set when the user configures aggregate-address */
94f2b392 5586static void
718e3744 5587bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5588 struct bgp_aggregate *aggregate)
5589{
5590 struct bgp_table *table;
5591 struct bgp_node *top;
5592 struct bgp_node *rn;
5593 struct bgp_info *new;
5594 struct bgp_info *ri;
5595 unsigned long match;
5596 u_char origin = BGP_ORIGIN_IGP;
5597 struct aspath *aspath = NULL;
5598 struct aspath *asmerge = NULL;
5599 struct community *community = NULL;
5600 struct community *commerge = NULL;
42f7e184 5601 u_char atomic_aggregate = 0;
718e3744 5602
5603 table = bgp->rib[afi][safi];
5604
5605 /* Sanity check. */
5606 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5607 return;
5608 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5609 return;
5610
5611 /* If routes exists below this node, generate aggregate routes. */
5612 top = bgp_node_get (table, p);
5613 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5614 if (rn->p.prefixlen > p->prefixlen)
5615 {
5616 match = 0;
5617
5618 for (ri = rn->info; ri; ri = ri->next)
5619 {
5620 if (BGP_INFO_HOLDDOWN (ri))
5621 continue;
5622
42f7e184
DS
5623 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5624 atomic_aggregate = 1;
5625
718e3744 5626 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5627 {
5628 /* summary-only aggregate route suppress aggregated
5629 route announcement. */
5630 if (aggregate->summary_only)
5631 {
fb982c25 5632 (bgp_info_extra_get (ri))->suppress++;
1a392d46 5633 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5634 match++;
5635 }
b5d58c32
DS
5636
5637 /* If at least one route among routes that are aggregated has
5638 * ORIGIN with the value INCOMPLETE, then the aggregated route
5639 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5640 * Otherwise, if at least one route among routes that are
5641 * aggregated has ORIGIN with the value EGP, then the aggregated
5642 * route MUST have the ORIGIN attribute with the value EGP.
5643 */
5644 if (origin < ri->attr->origin)
5645 origin = ri->attr->origin;
5646
718e3744 5647 /* as-set aggregate route generate origin, as path,
5648 community aggregation. */
5649 if (aggregate->as_set)
5650 {
718e3744 5651 if (aspath)
5652 {
5653 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5654 aspath_free (aspath);
5655 aspath = asmerge;
5656 }
5657 else
5658 aspath = aspath_dup (ri->attr->aspath);
5659
5660 if (ri->attr->community)
5661 {
5662 if (community)
5663 {
5664 commerge = community_merge (community,
5665 ri->attr->community);
5666 community = community_uniq_sort (commerge);
5667 community_free (commerge);
5668 }
5669 else
5670 community = community_dup (ri->attr->community);
5671 }
5672 }
5673 aggregate->count++;
5674 }
5675 }
5676
5677 /* If this node is suppressed, process the change. */
5678 if (match)
5679 bgp_process (bgp, rn, afi, safi);
5680 }
5681 bgp_unlock_node (top);
5682
5683 /* Add aggregate route to BGP table. */
5684 if (aggregate->count)
5685 {
5686 rn = bgp_node_get (table, p);
7c8ff89e 5687 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 5688 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
5689 aggregate->as_set,
5690 atomic_aggregate), rn);
718e3744 5691 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 5692
5693 bgp_info_add (rn, new);
200df115 5694 bgp_unlock_node (rn);
5695
718e3744 5696 /* Process change. */
5697 bgp_process (bgp, rn, afi, safi);
5698 }
5699}
5700
5701void
5702bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5703 safi_t safi, struct bgp_aggregate *aggregate)
5704{
5705 struct bgp_table *table;
5706 struct bgp_node *top;
5707 struct bgp_node *rn;
5708 struct bgp_info *ri;
5709 unsigned long match;
5710
5711 table = bgp->rib[afi][safi];
5712
5713 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5714 return;
5715 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5716 return;
5717
5718 /* If routes exists below this node, generate aggregate routes. */
5719 top = bgp_node_get (table, p);
5720 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5721 if (rn->p.prefixlen > p->prefixlen)
5722 {
5723 match = 0;
5724
5725 for (ri = rn->info; ri; ri = ri->next)
5726 {
5727 if (BGP_INFO_HOLDDOWN (ri))
5728 continue;
5729
5730 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5731 {
fb982c25 5732 if (aggregate->summary_only && ri->extra)
718e3744 5733 {
fb982c25 5734 ri->extra->suppress--;
718e3744 5735
fb982c25 5736 if (ri->extra->suppress == 0)
718e3744 5737 {
1a392d46 5738 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5739 match++;
5740 }
5741 }
5742 aggregate->count--;
5743 }
5744 }
5745
fb982c25 5746 /* If this node was suppressed, process the change. */
718e3744 5747 if (match)
5748 bgp_process (bgp, rn, afi, safi);
5749 }
5750 bgp_unlock_node (top);
5751
5752 /* Delete aggregate route from BGP table. */
5753 rn = bgp_node_get (table, p);
5754
5755 for (ri = rn->info; ri; ri = ri->next)
5756 if (ri->peer == bgp->peer_self
5757 && ri->type == ZEBRA_ROUTE_BGP
5758 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5759 break;
5760
5761 /* Withdraw static BGP route from routing table. */
5762 if (ri)
5763 {
718e3744 5764 bgp_info_delete (rn, ri);
1a392d46 5765 bgp_process (bgp, rn, afi, safi);
718e3744 5766 }
5767
5768 /* Unlock bgp_node_lookup. */
5769 bgp_unlock_node (rn);
5770}
5771
5772/* Aggregate route attribute. */
5773#define AGGREGATE_SUMMARY_ONLY 1
5774#define AGGREGATE_AS_SET 1
5775
94f2b392 5776static int
f6269b4f
RB
5777bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5778 afi_t afi, safi_t safi)
718e3744 5779{
5780 int ret;
5781 struct prefix p;
5782 struct bgp_node *rn;
5783 struct bgp *bgp;
5784 struct bgp_aggregate *aggregate;
5785
5786 /* Convert string to prefix structure. */
5787 ret = str2prefix (prefix_str, &p);
5788 if (!ret)
5789 {
5790 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5791 return CMD_WARNING;
5792 }
5793 apply_mask (&p);
5794
5795 /* Get BGP structure. */
5796 bgp = vty->index;
5797
5798 /* Old configuration check. */
f6269b4f
RB
5799 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5800 if (! rn)
718e3744 5801 {
f6269b4f
RB
5802 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5803 VTY_NEWLINE);
718e3744 5804 return CMD_WARNING;
5805 }
5806
f6269b4f
RB
5807 aggregate = rn->info;
5808 if (aggregate->safi & SAFI_UNICAST)
5809 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5810 if (aggregate->safi & SAFI_MULTICAST)
5811 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 5812
f6269b4f
RB
5813 /* Unlock aggregate address configuration. */
5814 rn->info = NULL;
5815 bgp_aggregate_free (aggregate);
5816 bgp_unlock_node (rn);
5817 bgp_unlock_node (rn);
718e3744 5818
5819 return CMD_SUCCESS;
5820}
5821
94f2b392 5822static int
f6269b4f
RB
5823bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5824 afi_t afi, safi_t safi,
5825 u_char summary_only, u_char as_set)
718e3744 5826{
5827 int ret;
5828 struct prefix p;
5829 struct bgp_node *rn;
5830 struct bgp *bgp;
5831 struct bgp_aggregate *aggregate;
5832
5833 /* Convert string to prefix structure. */
5834 ret = str2prefix (prefix_str, &p);
5835 if (!ret)
5836 {
5837 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5838 return CMD_WARNING;
5839 }
5840 apply_mask (&p);
5841
5842 /* Get BGP structure. */
5843 bgp = vty->index;
5844
5845 /* Old configuration check. */
f6269b4f
RB
5846 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5847
5848 if (rn->info)
718e3744 5849 {
f6269b4f 5850 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
368473f6 5851 /* try to remove the old entry */
f6269b4f
RB
5852 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5853 if (ret)
5854 {
368473f6
RB
5855 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5856 bgp_unlock_node (rn);
f6269b4f
RB
5857 return CMD_WARNING;
5858 }
718e3744 5859 }
5860
f6269b4f
RB
5861 /* Make aggregate address structure. */
5862 aggregate = bgp_aggregate_new ();
5863 aggregate->summary_only = summary_only;
5864 aggregate->as_set = as_set;
5865 aggregate->safi = safi;
5866 rn->info = aggregate;
718e3744 5867
f6269b4f
RB
5868 /* Aggregate address insert into BGP routing table. */
5869 if (safi & SAFI_UNICAST)
5870 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5871 if (safi & SAFI_MULTICAST)
5872 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 5873
5874 return CMD_SUCCESS;
5875}
5876
5877DEFUN (aggregate_address,
5878 aggregate_address_cmd,
5879 "aggregate-address A.B.C.D/M",
5880 "Configure BGP aggregate entries\n"
5881 "Aggregate prefix\n")
5882{
5883 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5884}
5885
5886DEFUN (aggregate_address_mask,
5887 aggregate_address_mask_cmd,
5888 "aggregate-address A.B.C.D A.B.C.D",
5889 "Configure BGP aggregate entries\n"
5890 "Aggregate address\n"
5891 "Aggregate mask\n")
5892{
5893 int ret;
5894 char prefix_str[BUFSIZ];
5895
5896 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5897
5898 if (! ret)
5899 {
5900 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5901 return CMD_WARNING;
5902 }
5903
5904 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5905 0, 0);
5906}
5907
5908DEFUN (aggregate_address_summary_only,
5909 aggregate_address_summary_only_cmd,
5910 "aggregate-address A.B.C.D/M summary-only",
5911 "Configure BGP aggregate entries\n"
5912 "Aggregate prefix\n"
5913 "Filter more specific routes from updates\n")
5914{
5915 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5916 AGGREGATE_SUMMARY_ONLY, 0);
5917}
5918
5919DEFUN (aggregate_address_mask_summary_only,
5920 aggregate_address_mask_summary_only_cmd,
5921 "aggregate-address A.B.C.D A.B.C.D summary-only",
5922 "Configure BGP aggregate entries\n"
5923 "Aggregate address\n"
5924 "Aggregate mask\n"
5925 "Filter more specific routes from updates\n")
5926{
5927 int ret;
5928 char prefix_str[BUFSIZ];
5929
5930 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5931
5932 if (! ret)
5933 {
5934 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5935 return CMD_WARNING;
5936 }
5937
5938 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5939 AGGREGATE_SUMMARY_ONLY, 0);
5940}
5941
5942DEFUN (aggregate_address_as_set,
5943 aggregate_address_as_set_cmd,
5944 "aggregate-address A.B.C.D/M as-set",
5945 "Configure BGP aggregate entries\n"
5946 "Aggregate prefix\n"
5947 "Generate AS set path information\n")
5948{
5949 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5950 0, AGGREGATE_AS_SET);
5951}
5952
5953DEFUN (aggregate_address_mask_as_set,
5954 aggregate_address_mask_as_set_cmd,
5955 "aggregate-address A.B.C.D A.B.C.D as-set",
5956 "Configure BGP aggregate entries\n"
5957 "Aggregate address\n"
5958 "Aggregate mask\n"
5959 "Generate AS set path information\n")
5960{
5961 int ret;
5962 char prefix_str[BUFSIZ];
5963
5964 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5965
5966 if (! ret)
5967 {
5968 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5969 return CMD_WARNING;
5970 }
5971
5972 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5973 0, AGGREGATE_AS_SET);
5974}
5975
5976
5977DEFUN (aggregate_address_as_set_summary,
5978 aggregate_address_as_set_summary_cmd,
5979 "aggregate-address A.B.C.D/M as-set summary-only",
5980 "Configure BGP aggregate entries\n"
5981 "Aggregate prefix\n"
5982 "Generate AS set path information\n"
5983 "Filter more specific routes from updates\n")
5984{
5985 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5986 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5987}
5988
5989ALIAS (aggregate_address_as_set_summary,
5990 aggregate_address_summary_as_set_cmd,
5991 "aggregate-address A.B.C.D/M summary-only as-set",
5992 "Configure BGP aggregate entries\n"
5993 "Aggregate prefix\n"
5994 "Filter more specific routes from updates\n"
5995 "Generate AS set path information\n")
5996
5997DEFUN (aggregate_address_mask_as_set_summary,
5998 aggregate_address_mask_as_set_summary_cmd,
5999 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
6000 "Configure BGP aggregate entries\n"
6001 "Aggregate address\n"
6002 "Aggregate mask\n"
6003 "Generate AS set path information\n"
6004 "Filter more specific routes from updates\n")
6005{
6006 int ret;
6007 char prefix_str[BUFSIZ];
6008
6009 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6010
6011 if (! ret)
6012 {
6013 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6014 return CMD_WARNING;
6015 }
6016
6017 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
6018 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
6019}
6020
6021ALIAS (aggregate_address_mask_as_set_summary,
6022 aggregate_address_mask_summary_as_set_cmd,
6023 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
6024 "Configure BGP aggregate entries\n"
6025 "Aggregate address\n"
6026 "Aggregate mask\n"
6027 "Filter more specific routes from updates\n"
6028 "Generate AS set path information\n")
6029
6030DEFUN (no_aggregate_address,
6031 no_aggregate_address_cmd,
6032 "no aggregate-address A.B.C.D/M",
6033 NO_STR
6034 "Configure BGP aggregate entries\n"
6035 "Aggregate prefix\n")
6036{
6037 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
6038}
6039
6040ALIAS (no_aggregate_address,
6041 no_aggregate_address_summary_only_cmd,
6042 "no aggregate-address A.B.C.D/M summary-only",
6043 NO_STR
6044 "Configure BGP aggregate entries\n"
6045 "Aggregate prefix\n"
6046 "Filter more specific routes from updates\n")
6047
6048ALIAS (no_aggregate_address,
6049 no_aggregate_address_as_set_cmd,
6050 "no aggregate-address A.B.C.D/M as-set",
6051 NO_STR
6052 "Configure BGP aggregate entries\n"
6053 "Aggregate prefix\n"
6054 "Generate AS set path information\n")
6055
6056ALIAS (no_aggregate_address,
6057 no_aggregate_address_as_set_summary_cmd,
6058 "no aggregate-address A.B.C.D/M as-set summary-only",
6059 NO_STR
6060 "Configure BGP aggregate entries\n"
6061 "Aggregate prefix\n"
6062 "Generate AS set path information\n"
6063 "Filter more specific routes from updates\n")
6064
6065ALIAS (no_aggregate_address,
6066 no_aggregate_address_summary_as_set_cmd,
6067 "no aggregate-address A.B.C.D/M summary-only as-set",
6068 NO_STR
6069 "Configure BGP aggregate entries\n"
6070 "Aggregate prefix\n"
6071 "Filter more specific routes from updates\n"
6072 "Generate AS set path information\n")
6073
6074DEFUN (no_aggregate_address_mask,
6075 no_aggregate_address_mask_cmd,
6076 "no aggregate-address A.B.C.D A.B.C.D",
6077 NO_STR
6078 "Configure BGP aggregate entries\n"
6079 "Aggregate address\n"
6080 "Aggregate mask\n")
6081{
6082 int ret;
6083 char prefix_str[BUFSIZ];
6084
6085 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6086
6087 if (! ret)
6088 {
6089 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6090 return CMD_WARNING;
6091 }
6092
6093 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
6094}
6095
6096ALIAS (no_aggregate_address_mask,
6097 no_aggregate_address_mask_summary_only_cmd,
6098 "no aggregate-address A.B.C.D A.B.C.D summary-only",
6099 NO_STR
6100 "Configure BGP aggregate entries\n"
6101 "Aggregate address\n"
6102 "Aggregate mask\n"
6103 "Filter more specific routes from updates\n")
6104
6105ALIAS (no_aggregate_address_mask,
6106 no_aggregate_address_mask_as_set_cmd,
6107 "no aggregate-address A.B.C.D A.B.C.D as-set",
6108 NO_STR
6109 "Configure BGP aggregate entries\n"
6110 "Aggregate address\n"
6111 "Aggregate mask\n"
6112 "Generate AS set path information\n")
6113
6114ALIAS (no_aggregate_address_mask,
6115 no_aggregate_address_mask_as_set_summary_cmd,
6116 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
6117 NO_STR
6118 "Configure BGP aggregate entries\n"
6119 "Aggregate address\n"
6120 "Aggregate mask\n"
6121 "Generate AS set path information\n"
6122 "Filter more specific routes from updates\n")
6123
6124ALIAS (no_aggregate_address_mask,
6125 no_aggregate_address_mask_summary_as_set_cmd,
6126 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
6127 NO_STR
6128 "Configure BGP aggregate entries\n"
6129 "Aggregate address\n"
6130 "Aggregate mask\n"
6131 "Filter more specific routes from updates\n"
6132 "Generate AS set path information\n")
6133
6134#ifdef HAVE_IPV6
6135DEFUN (ipv6_aggregate_address,
6136 ipv6_aggregate_address_cmd,
6137 "aggregate-address X:X::X:X/M",
6138 "Configure BGP aggregate entries\n"
6139 "Aggregate prefix\n")
6140{
6141 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
6142}
6143
6144DEFUN (ipv6_aggregate_address_summary_only,
6145 ipv6_aggregate_address_summary_only_cmd,
6146 "aggregate-address X:X::X:X/M summary-only",
6147 "Configure BGP aggregate entries\n"
6148 "Aggregate prefix\n"
6149 "Filter more specific routes from updates\n")
6150{
6151 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6152 AGGREGATE_SUMMARY_ONLY, 0);
6153}
6154
6155DEFUN (no_ipv6_aggregate_address,
6156 no_ipv6_aggregate_address_cmd,
6157 "no aggregate-address X:X::X:X/M",
6158 NO_STR
6159 "Configure BGP aggregate entries\n"
6160 "Aggregate prefix\n")
6161{
6162 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
6163}
6164
6165DEFUN (no_ipv6_aggregate_address_summary_only,
6166 no_ipv6_aggregate_address_summary_only_cmd,
6167 "no aggregate-address X:X::X:X/M summary-only",
6168 NO_STR
6169 "Configure BGP aggregate entries\n"
6170 "Aggregate prefix\n"
6171 "Filter more specific routes from updates\n")
6172{
6173 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
6174}
6175
6176ALIAS (ipv6_aggregate_address,
6177 old_ipv6_aggregate_address_cmd,
6178 "ipv6 bgp aggregate-address X:X::X:X/M",
6179 IPV6_STR
6180 BGP_STR
6181 "Configure BGP aggregate entries\n"
6182 "Aggregate prefix\n")
6183
6184ALIAS (ipv6_aggregate_address_summary_only,
6185 old_ipv6_aggregate_address_summary_only_cmd,
6186 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
6187 IPV6_STR
6188 BGP_STR
6189 "Configure BGP aggregate entries\n"
6190 "Aggregate prefix\n"
6191 "Filter more specific routes from updates\n")
6192
6193ALIAS (no_ipv6_aggregate_address,
6194 old_no_ipv6_aggregate_address_cmd,
6195 "no ipv6 bgp aggregate-address X:X::X:X/M",
6196 NO_STR
6197 IPV6_STR
6198 BGP_STR
6199 "Configure BGP aggregate entries\n"
6200 "Aggregate prefix\n")
6201
6202ALIAS (no_ipv6_aggregate_address_summary_only,
6203 old_no_ipv6_aggregate_address_summary_only_cmd,
6204 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
6205 NO_STR
6206 IPV6_STR
6207 BGP_STR
6208 "Configure BGP aggregate entries\n"
6209 "Aggregate prefix\n"
6210 "Filter more specific routes from updates\n")
6211#endif /* HAVE_IPV6 */
6b0655a2 6212
718e3744 6213/* Redistribute route treatment. */
6214void
f04a80a5 6215bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
bc413143 6216 const struct in6_addr *nexthop6, unsigned int ifindex,
7c8ff89e 6217 u_int32_t metric, u_char type, u_short instance, u_short tag)
718e3744 6218{
6219 struct bgp *bgp;
1eb8ef25 6220 struct listnode *node, *nnode;
718e3744 6221 struct bgp_info *new;
6222 struct bgp_info *bi;
6223 struct bgp_info info;
6224 struct bgp_node *bn;
e16a4133 6225 struct attr attr;
718e3744 6226 struct attr *new_attr;
6227 afi_t afi;
6228 int ret;
7c8ff89e 6229 struct bgp_redist *red;
718e3744 6230
6231 /* Make default attribute. */
6232 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
6233 if (nexthop)
6234 attr.nexthop = *nexthop;
bc413143 6235 attr.nh_ifindex = ifindex;
718e3744 6236
f04a80a5
SH
6237#ifdef HAVE_IPV6
6238 if (nexthop6)
6239 {
6240 struct attr_extra *extra = bgp_attr_extra_get(&attr);
6241 extra->mp_nexthop_global = *nexthop6;
801a9bcc 6242 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
f04a80a5
SH
6243 }
6244#endif
6245
718e3744 6246 attr.med = metric;
6247 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
0d9551dc 6248 attr.extra->tag = tag;
718e3744 6249
1eb8ef25 6250 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 6251 {
6252 afi = family2afi (p->family);
6253
7c8ff89e
DS
6254 red = bgp_redist_lookup(bgp, afi, type, instance);
6255 if (red)
718e3744 6256 {
558d1fec
JBD
6257 struct attr attr_new;
6258 struct attr_extra extra_new;
6259
718e3744 6260 /* Copy attribute for modification. */
558d1fec 6261 attr_new.extra = &extra_new;
fb982c25 6262 bgp_attr_dup (&attr_new, &attr);
718e3744 6263
7c8ff89e
DS
6264 if (red->redist_metric_flag)
6265 attr_new.med = red->redist_metric;
718e3744 6266
6267 /* Apply route-map. */
91e89998 6268 if (red->rmap.name)
718e3744 6269 {
6270 info.peer = bgp->peer_self;
6271 info.attr = &attr_new;
6272
fee0f4c6 6273 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
6274
7c8ff89e 6275 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
fee0f4c6 6276
6277 bgp->peer_self->rmap_type = 0;
6278
718e3744 6279 if (ret == RMAP_DENYMATCH)
6280 {
6281 /* Free uninterned attribute. */
6282 bgp_attr_flush (&attr_new);
558d1fec 6283
718e3744 6284 /* Unintern original. */
f6f434b2 6285 aspath_unintern (&attr.aspath);
fb982c25 6286 bgp_attr_extra_free (&attr);
7c8ff89e 6287 bgp_redistribute_delete (p, type, instance);
718e3744 6288 return;
6289 }
6290 }
6291
fb982c25
PJ
6292 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
6293 afi, SAFI_UNICAST, p, NULL);
6294
718e3744 6295 new_attr = bgp_attr_intern (&attr_new);
558d1fec 6296
718e3744 6297 for (bi = bn->info; bi; bi = bi->next)
6298 if (bi->peer == bgp->peer_self
6299 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
6300 break;
6301
6302 if (bi)
6303 {
8d45210e
AS
6304 if (attrhash_cmp (bi->attr, new_attr) &&
6305 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
718e3744 6306 {
f6f434b2
PJ
6307 bgp_attr_unintern (&new_attr);
6308 aspath_unintern (&attr.aspath);
fb982c25 6309 bgp_attr_extra_free (&attr);
718e3744 6310 bgp_unlock_node (bn);
6311 return;
6312 }
6313 else
6314 {
6315 /* The attribute is changed. */
1a392d46 6316 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
718e3744 6317
6318 /* Rewrite BGP route information. */
8d45210e
AS
6319 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
6320 bgp_info_restore(bn, bi);
6321 else
6322 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
f6f434b2 6323 bgp_attr_unintern (&bi->attr);
718e3744 6324 bi->attr = new_attr;
65957886 6325 bi->uptime = bgp_clock ();
718e3744 6326
6327 /* Process change. */
6328 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
6329 bgp_process (bgp, bn, afi, SAFI_UNICAST);
6330 bgp_unlock_node (bn);
f6f434b2 6331 aspath_unintern (&attr.aspath);
fb982c25 6332 bgp_attr_extra_free (&attr);
718e3744 6333 return;
fb018d25 6334 }
718e3744 6335 }
6336
7c8ff89e 6337 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
fb018d25 6338 new_attr, bn);
718e3744 6339 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 6340
6341 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
6342 bgp_info_add (bn, new);
200df115 6343 bgp_unlock_node (bn);
718e3744 6344 bgp_process (bgp, bn, afi, SAFI_UNICAST);
6345 }
6346 }
6347
6348 /* Unintern original. */
f6f434b2 6349 aspath_unintern (&attr.aspath);
fb982c25 6350 bgp_attr_extra_free (&attr);
718e3744 6351}
6352
6353void
7c8ff89e 6354bgp_redistribute_delete (struct prefix *p, u_char type, u_short instance)
718e3744 6355{
6356 struct bgp *bgp;
1eb8ef25 6357 struct listnode *node, *nnode;
718e3744 6358 afi_t afi;
6359 struct bgp_node *rn;
6360 struct bgp_info *ri;
7c8ff89e 6361 struct bgp_redist *red;
718e3744 6362
1eb8ef25 6363 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 6364 {
6365 afi = family2afi (p->family);
6366
7c8ff89e
DS
6367 red = bgp_redist_lookup(bgp, afi, type, instance);
6368 if (red)
718e3744 6369 {
fee0f4c6 6370 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
718e3744 6371
6372 for (ri = rn->info; ri; ri = ri->next)
6373 if (ri->peer == bgp->peer_self
6374 && ri->type == type)
6375 break;
6376
6377 if (ri)
6378 {
6379 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
718e3744 6380 bgp_info_delete (rn, ri);
1a392d46 6381 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 6382 }
6383 bgp_unlock_node (rn);
6384 }
6385 }
6386}
6387
6388/* Withdraw specified route type's route. */
6389void
7c8ff89e 6390bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
718e3744 6391{
6392 struct bgp_node *rn;
6393 struct bgp_info *ri;
6394 struct bgp_table *table;
6395
6396 table = bgp->rib[afi][SAFI_UNICAST];
6397
6398 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6399 {
6400 for (ri = rn->info; ri; ri = ri->next)
6401 if (ri->peer == bgp->peer_self
7c8ff89e
DS
6402 && ri->type == type
6403 && ri->instance == instance)
718e3744 6404 break;
6405
6406 if (ri)
6407 {
6408 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
718e3744 6409 bgp_info_delete (rn, ri);
1a392d46 6410 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 6411 }
6412 }
6413}
6b0655a2 6414
718e3744 6415/* Static function to display route. */
94f2b392 6416static void
718e3744 6417route_vty_out_route (struct prefix *p, struct vty *vty)
6418{
6419 int len;
6420 u_int32_t destination;
6421 char buf[BUFSIZ];
6422
6423 if (p->family == AF_INET)
6424 {
6425 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
6426 destination = ntohl (p->u.prefix4.s_addr);
6427
6428 if ((IN_CLASSC (destination) && p->prefixlen == 24)
6429 || (IN_CLASSB (destination) && p->prefixlen == 16)
6430 || (IN_CLASSA (destination) && p->prefixlen == 8)
6431 || p->u.prefix4.s_addr == 0)
6432 {
6433 /* When mask is natural, mask is not displayed. */
6434 }
6435 else
6436 len += vty_out (vty, "/%d", p->prefixlen);
6437 }
6438 else
6439 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
6440 p->prefixlen);
6441
6442 len = 17 - len;
6443 if (len < 1)
6444 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
6445 else
6446 vty_out (vty, "%*s", len, " ");
6447}
6448
718e3744 6449enum bgp_display_type
6450{
6451 normal_list,
6452};
6453
b40d939b 6454/* Print the short form route status for a bgp_info */
6455static void
b05a1c8b
DS
6456route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
6457 json_object *json_path)
718e3744 6458{
b05a1c8b
DS
6459 json_object *json_boolean_true;
6460
6461 if (json_path)
6462 {
b05a1c8b
DS
6463 json_boolean_true = json_object_new_boolean(1);
6464
6465 /* Route status display. */
6466 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6467 json_object_object_add(json_path, "removed", json_boolean_true);
6468
6469 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6470 json_object_object_add(json_path, "stale", json_boolean_true);
6471
6472 if (binfo->extra && binfo->extra->suppress)
6473 json_object_object_add(json_path, "suppressed", json_boolean_true);
6474
6475 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6476 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6477 json_object_object_add(json_path, "valid", json_boolean_true);
6478
6479 /* Selected */
6480 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6481 json_object_object_add(json_path, "history", json_boolean_true);
6482
6483 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6484 json_object_object_add(json_path, "damped", json_boolean_true);
6485
6486 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6487 json_object_object_add(json_path, "bestpath", json_boolean_true);
6488
6489 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6490 json_object_object_add(json_path, "multipath", json_boolean_true);
6491
6492 /* Internal route. */
6493 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6494 json_object_object_add(json_path, "internal", json_boolean_true);
6495 else
6496 json_object_object_add(json_path, "external", json_boolean_true);
6497
6498 return;
6499 }
6500
b40d939b 6501 /* Route status display. */
6502 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6503 vty_out (vty, "R");
6504 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
93406d87 6505 vty_out (vty, "S");
fb982c25 6506 else if (binfo->extra && binfo->extra->suppress)
718e3744 6507 vty_out (vty, "s");
31eba040
DS
6508 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6509 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
718e3744 6510 vty_out (vty, "*");
6511 else
6512 vty_out (vty, " ");
6513
6514 /* Selected */
6515 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6516 vty_out (vty, "h");
6517 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6518 vty_out (vty, "d");
6519 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6520 vty_out (vty, ">");
b366b518
BB
6521 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6522 vty_out (vty, "=");
718e3744 6523 else
6524 vty_out (vty, " ");
6525
6526 /* Internal route. */
b05a1c8b
DS
6527 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6528 vty_out (vty, "i");
6529 else
6530 vty_out (vty, " ");
b40d939b 6531}
6532
6533/* called from terminal list command */
6534void
6535route_vty_out (struct vty *vty, struct prefix *p,
b05a1c8b
DS
6536 struct bgp_info *binfo, int display, safi_t safi,
6537 json_object *json_paths)
b40d939b 6538{
6539 struct attr *attr;
b05a1c8b
DS
6540 json_object *json_path;
6541 json_object *json_int;
6542 json_object *json_string;
47fc97cc 6543
b05a1c8b
DS
6544 if (json_paths)
6545 json_path = json_object_new_object();
718e3744 6546 else
b05a1c8b
DS
6547 json_path = NULL;
6548
6549 /* short status lead text */
6550 route_vty_short_status_out (vty, binfo, json_path);
718e3744 6551
b05a1c8b
DS
6552 if (!json_paths)
6553 {
6554 /* print prefix and mask */
6555 if (! display)
6556 route_vty_out_route (p, vty);
6557 else
6558 vty_out (vty, "%*s", 17, " ");
6559 }
47fc97cc 6560
718e3744 6561 /* Print attribute */
6562 attr = binfo->attr;
6563 if (attr)
6564 {
b05a1c8b
DS
6565
6566 /* IPv4 Next Hop */
8a92a8a0
DS
6567 if (p->family == AF_INET
6568 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 6569 {
b05a1c8b
DS
6570 if (json_paths)
6571 {
6572 if (safi == SAFI_MPLS_VPN)
6573 {
6574 json_string = json_object_new_string(inet_ntoa (attr->extra->mp_nexthop_global_in));
6575 json_object_object_add(json_path, "nexthop", json_string);
6576 }
6577 else
6578 {
6579 json_string = json_object_new_string(inet_ntoa (attr->nexthop));
6580 json_object_object_add(json_path, "nexthop", json_string);
6581 }
6582 }
6583 else
6584 {
6585 if (safi == SAFI_MPLS_VPN)
6586 vty_out (vty, "%-16s",
6587 inet_ntoa (attr->extra->mp_nexthop_global_in));
6588 else
6589 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6590 }
718e3744 6591 }
b05a1c8b
DS
6592
6593#ifdef HAVE_IPV6
6594 /* IPv6 Next Hop */
8a92a8a0 6595 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
718e3744 6596 {
6597 int len;
6598 char buf[BUFSIZ];
6599
b05a1c8b
DS
6600 if (json_paths)
6601 {
6602 json_string = json_object_new_string(inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf, BUFSIZ));
6603 json_object_object_add(json_path, "nexthop", json_string);
6604 }
6605 else
6606 {
6607 len = vty_out (vty, "%s",
6608 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6609 buf, BUFSIZ));
6610 len = 16 - len;
6611 if (len < 1)
6612 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6613 else
6614 vty_out (vty, "%*s", len, " ");
6615 }
718e3744 6616 }
6617#endif /* HAVE_IPV6 */
6618
b05a1c8b 6619 /* MED/Metric */
718e3744 6620 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b
DS
6621 if (json_paths)
6622 {
6623 json_int = json_object_new_int(attr->med);
6624 json_object_object_add(json_path, "med", json_int);
6625 }
6626 else
6627 vty_out (vty, "%10u", attr->med);
718e3744 6628 else
b05a1c8b
DS
6629 if (!json_paths)
6630 vty_out (vty, " ");
47fc97cc 6631
b05a1c8b 6632 /* Local Pref */
718e3744 6633 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
b05a1c8b
DS
6634 if (json_paths)
6635 {
6636 json_int = json_object_new_int(attr->local_pref);
6637 json_object_object_add(json_path, "localpref", json_int);
6638 }
6639 else
6640 vty_out (vty, "%7u", attr->local_pref);
718e3744 6641 else
b05a1c8b
DS
6642 if (!json_paths)
6643 vty_out (vty, " ");
718e3744 6644
b05a1c8b
DS
6645 if (json_paths)
6646 {
6647 if (attr->extra)
6648 json_int = json_object_new_int(attr->extra->weight);
6649 else
6650 json_int = json_object_new_int(0);
47fc97cc 6651
b05a1c8b
DS
6652 json_object_object_add(json_path, "weight", json_int);
6653 }
6654 else
6655 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
47fc97cc 6656
b2518c1e
PJ
6657 /* Print aspath */
6658 if (attr->aspath)
b05a1c8b
DS
6659 {
6660 if (json_paths)
6661 {
e5eee9af
DS
6662 if (!attr->aspath->str || aspath_count_hops (attr->aspath) == 0)
6663 json_string = json_object_new_string("Local");
6664 else
6665 json_string = json_object_new_string(attr->aspath->str);
b05a1c8b
DS
6666 json_object_object_add(json_path, "aspath", json_string);
6667 }
6668 else
6669 {
6670 aspath_print_vty (vty, "%s", attr->aspath, " ");
6671 }
6672 }
47fc97cc 6673
b2518c1e 6674 /* Print origin */
b05a1c8b
DS
6675 if (json_paths)
6676 {
6677 json_string = json_object_new_string(bgp_origin_str[attr->origin]);
6678 json_object_object_add(json_path, "origin", json_string);
6679 }
6680 else
6681 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 6682 }
b05a1c8b
DS
6683
6684 if (json_paths)
6685 json_object_array_add(json_paths, json_path);
6686 else
6687 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6688}
6689
6690/* called from terminal list command */
6691void
6692route_vty_out_tmp (struct vty *vty, struct prefix *p,
b05a1c8b 6693 struct attr *attr, safi_t safi)
718e3744 6694{
6695 /* Route status display. */
6696 vty_out (vty, "*");
6697 vty_out (vty, ">");
6698 vty_out (vty, " ");
6699
6700 /* print prefix and mask */
6701 route_vty_out_route (p, vty);
6702
6703 /* Print attribute */
6704 if (attr)
6705 {
8a92a8a0
DS
6706 if (p->family == AF_INET
6707 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 6708 {
6709 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
6710 vty_out (vty, "%-16s",
6711 inet_ntoa (attr->extra->mp_nexthop_global_in));
718e3744 6712 else
6713 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6714 }
6715#ifdef HAVE_IPV6
8a92a8a0 6716 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
718e3744 6717 {
6718 int len;
6719 char buf[BUFSIZ];
fb982c25
PJ
6720
6721 assert (attr->extra);
718e3744 6722
6723 len = vty_out (vty, "%s",
fb982c25
PJ
6724 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6725 buf, BUFSIZ));
718e3744 6726 len = 16 - len;
6727 if (len < 1)
6728 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6729 else
6730 vty_out (vty, "%*s", len, " ");
6731 }
6732#endif /* HAVE_IPV6 */
6733
6734 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
c099baf6 6735 vty_out (vty, "%10u", attr->med);
718e3744 6736 else
6737 vty_out (vty, " ");
6738
6739 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
c099baf6 6740 vty_out (vty, "%7u", attr->local_pref);
718e3744 6741 else
6742 vty_out (vty, " ");
fb982c25 6743
c099baf6 6744 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
fb982c25 6745
b2518c1e
PJ
6746 /* Print aspath */
6747 if (attr->aspath)
841f7a57 6748 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 6749
b2518c1e 6750 /* Print origin */
718e3744 6751 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 6752 }
718e3744 6753
6754 vty_out (vty, "%s", VTY_NEWLINE);
6755}
6756
5a646650 6757void
718e3744 6758route_vty_out_tag (struct vty *vty, struct prefix *p,
6759 struct bgp_info *binfo, int display, safi_t safi)
6760{
6761 struct attr *attr;
718e3744 6762 u_int32_t label = 0;
fb982c25
PJ
6763
6764 if (!binfo->extra)
6765 return;
6766
b40d939b 6767 /* short status lead text */
b05a1c8b 6768 route_vty_short_status_out (vty, binfo, NULL);
b40d939b 6769
718e3744 6770 /* print prefix and mask */
6771 if (! display)
6772 route_vty_out_route (p, vty);
6773 else
6774 vty_out (vty, "%*s", 17, " ");
6775
6776 /* Print attribute */
6777 attr = binfo->attr;
6778 if (attr)
6779 {
8a92a8a0
DS
6780 if (p->family == AF_INET
6781 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 6782 {
6783 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
6784 vty_out (vty, "%-16s",
6785 inet_ntoa (attr->extra->mp_nexthop_global_in));
718e3744 6786 else
6787 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6788 }
6789#ifdef HAVE_IPV6
8a92a8a0 6790 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
718e3744 6791 {
fb982c25 6792 assert (attr->extra);
718e3744 6793 char buf[BUFSIZ];
6794 char buf1[BUFSIZ];
801a9bcc 6795 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
718e3744 6796 vty_out (vty, "%s",
fb982c25
PJ
6797 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6798 buf, BUFSIZ));
801a9bcc 6799 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
718e3744 6800 vty_out (vty, "%s(%s)",
fb982c25
PJ
6801 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6802 buf, BUFSIZ),
6803 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6804 buf1, BUFSIZ));
718e3744 6805
6806 }
6807#endif /* HAVE_IPV6 */
6808 }
6809
fb982c25 6810 label = decode_label (binfo->extra->tag);
718e3744 6811
6812 vty_out (vty, "notag/%d", label);
6813
6814 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6815}
6816
6817/* dampening route */
5a646650 6818static void
718e3744 6819damp_route_vty_out (struct vty *vty, struct prefix *p,
6820 struct bgp_info *binfo, int display, safi_t safi)
6821{
6822 struct attr *attr;
718e3744 6823 int len;
50aef6f3 6824 char timebuf[BGP_UPTIME_LEN];
718e3744 6825
b40d939b 6826 /* short status lead text */
b05a1c8b 6827 route_vty_short_status_out (vty, binfo, NULL);
b40d939b 6828
718e3744 6829 /* print prefix and mask */
6830 if (! display)
6831 route_vty_out_route (p, vty);
6832 else
6833 vty_out (vty, "%*s", 17, " ");
6834
6835 len = vty_out (vty, "%s", binfo->peer->host);
6836 len = 17 - len;
6837 if (len < 1)
6838 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6839 else
6840 vty_out (vty, "%*s", len, " ");
6841
50aef6f3 6842 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
718e3744 6843
6844 /* Print attribute */
6845 attr = binfo->attr;
6846 if (attr)
6847 {
6848 /* Print aspath */
6849 if (attr->aspath)
841f7a57 6850 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 6851
6852 /* Print origin */
b2518c1e 6853 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 6854 }
6855 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6856}
6857
718e3744 6858/* flap route */
5a646650 6859static void
718e3744 6860flap_route_vty_out (struct vty *vty, struct prefix *p,
6861 struct bgp_info *binfo, int display, safi_t safi)
6862{
6863 struct attr *attr;
6864 struct bgp_damp_info *bdi;
718e3744 6865 char timebuf[BGP_UPTIME_LEN];
6866 int len;
fb982c25
PJ
6867
6868 if (!binfo->extra)
6869 return;
6870
6871 bdi = binfo->extra->damp_info;
718e3744 6872
b40d939b 6873 /* short status lead text */
b05a1c8b 6874 route_vty_short_status_out (vty, binfo, NULL);
b40d939b 6875
718e3744 6876 /* print prefix and mask */
6877 if (! display)
6878 route_vty_out_route (p, vty);
6879 else
6880 vty_out (vty, "%*s", 17, " ");
6881
6882 len = vty_out (vty, "%s", binfo->peer->host);
6883 len = 16 - len;
6884 if (len < 1)
6885 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6886 else
6887 vty_out (vty, "%*s", len, " ");
6888
6889 len = vty_out (vty, "%d", bdi->flap);
6890 len = 5 - len;
6891 if (len < 1)
6892 vty_out (vty, " ");
6893 else
6894 vty_out (vty, "%*s ", len, " ");
6895
6896 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6897 timebuf, BGP_UPTIME_LEN));
6898
6899 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6900 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
50aef6f3 6901 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
718e3744 6902 else
6903 vty_out (vty, "%*s ", 8, " ");
6904
6905 /* Print attribute */
6906 attr = binfo->attr;
6907 if (attr)
6908 {
6909 /* Print aspath */
6910 if (attr->aspath)
841f7a57 6911 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 6912
6913 /* Print origin */
b2518c1e 6914 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 6915 }
6916 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6917}
6918
94f2b392 6919static void
718e3744 6920route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
b05a1c8b
DS
6921 struct bgp_info *binfo, afi_t afi, safi_t safi,
6922 json_object *json_paths)
718e3744 6923{
6924 char buf[INET6_ADDRSTRLEN];
6925 char buf1[BUFSIZ];
6926 struct attr *attr;
6927 int sockunion_vty_out (struct vty *, union sockunion *);
30b00176
JK
6928#ifdef HAVE_CLOCK_MONOTONIC
6929 time_t tbuf;
6930#endif
b05a1c8b
DS
6931 json_object *json_int;
6932 json_object *json_string;
ffd0c037 6933 json_object *json_path = NULL;
b05a1c8b 6934 json_object *json_boolean_false;
ffd0c037
DS
6935 json_object *json_boolean_true = NULL;
6936 json_object *json_cluster_list = NULL;
b05a1c8b
DS
6937
6938 if (json_paths)
6939 {
6940 json_path = json_object_new_object();
6941 json_boolean_false = json_object_new_boolean(0);
6942 json_boolean_true = json_object_new_boolean(1);
6943 json_cluster_list = json_object_new_array();
6944 }
6945
718e3744 6946 attr = binfo->attr;
6947
6948 if (attr)
6949 {
6950 /* Line1 display AS-path, Aggregator */
6951 if (attr->aspath)
6952 {
b05a1c8b
DS
6953 if (!json_paths)
6954 vty_out (vty, " ");
6955
fe69a505 6956 if (aspath_count_hops (attr->aspath) == 0)
b05a1c8b
DS
6957 {
6958 if (json_paths)
6959 json_string = json_object_new_string("Local");
6960 else
6961 vty_out (vty, "Local");
6962 }
718e3744 6963 else
b05a1c8b
DS
6964 {
6965 if (json_paths)
6966 json_string = json_object_new_string(attr->aspath->str);
6967 else
6968 aspath_print_vty (vty, "%s", attr->aspath, "");
6969 }
6970
6971 if (json_paths)
6972 json_object_object_add(json_path, "aspath", json_string);
718e3744 6973 }
6974
b40d939b 6975 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
b05a1c8b
DS
6976 {
6977 if (json_paths)
6978 json_object_object_add(json_path, "removed", json_boolean_true);
6979 else
6980 vty_out (vty, ", (removed)");
6981 }
6982
93406d87 6983 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
b05a1c8b
DS
6984 {
6985 if (json_paths)
6986 json_object_object_add(json_path, "stale", json_boolean_true);
6987 else
6988 vty_out (vty, ", (stale)");
6989 }
6990
93406d87 6991 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
b05a1c8b
DS
6992 {
6993 if (json_paths)
6994 {
6995 json_int = json_object_new_int(attr->extra->aggregator_as);
6996 json_string = json_object_new_string(inet_ntoa (attr->extra->aggregator_addr));
6997 json_object_object_add(json_path, "aggregator-as", json_int);
6998 json_object_object_add(json_path, "aggregator-id", json_string);
6999 }
7000 else
7001 {
7002 vty_out (vty, ", (aggregated by %u %s)",
7003 attr->extra->aggregator_as,
7004 inet_ntoa (attr->extra->aggregator_addr));
7005 }
7006 }
7007
93406d87 7008 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
b05a1c8b
DS
7009 {
7010 if (json_paths)
7011 json_object_object_add(json_path, "rxed-from-rr-client", json_boolean_true);
7012 else
7013 vty_out (vty, ", (Received from a RR-client)");
7014 }
7015
93406d87 7016 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
b05a1c8b
DS
7017 {
7018 if (json_paths)
7019 json_object_object_add(json_path, "rxed-from-rs-client", json_boolean_true);
7020 else
7021 vty_out (vty, ", (Received from a RS-client)");
7022 }
7023
93406d87 7024 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
7025 {
7026 if (json_paths)
7027 json_object_object_add(json_path, "dampening-history-entry", json_boolean_true);
7028 else
7029 vty_out (vty, ", (history entry)");
7030 }
93406d87 7031 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
b05a1c8b
DS
7032 {
7033 if (json_paths)
7034 json_object_object_add(json_path, "dampening-suppressed", json_boolean_true);
7035 else
7036 vty_out (vty, ", (suppressed due to dampening)");
7037 }
7038
7039 if (!json_paths)
7040 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7041
7042 /* Line2 display Next-hop, Neighbor, Router-id */
8a92a8a0
DS
7043 if (p->family == AF_INET
7044 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 7045 {
b05a1c8b
DS
7046 if (safi == SAFI_MPLS_VPN)
7047 {
7048 if (json_paths)
7049 json_string = json_object_new_string(inet_ntoa (attr->extra->mp_nexthop_global_in));
7050 else
7051 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
7052 }
7053 else
7054 {
7055 if (json_paths)
7056 json_string = json_object_new_string(inet_ntoa (attr->nexthop));
7057 else
7058 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
7059 }
7060
7061 if (json_paths)
7062 json_object_object_add(json_path, "nexthop", json_string);
718e3744 7063 }
7064#ifdef HAVE_IPV6
7065 else
7066 {
fb982c25 7067 assert (attr->extra);
b05a1c8b
DS
7068 if (json_paths)
7069 {
7070 json_string = json_object_new_string(inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7071 buf, INET6_ADDRSTRLEN));
7072 json_object_object_add(json_path, "nexthop", json_string);
7073 }
7074 else
7075 {
7076 vty_out (vty, " %s",
7077 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7078 buf, INET6_ADDRSTRLEN));
7079 }
718e3744 7080 }
7081#endif /* HAVE_IPV6 */
7082
7083 if (binfo->peer == bgp->peer_self)
7084 {
b05a1c8b 7085
8a92a8a0 7086 if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
b05a1c8b
DS
7087 {
7088 if (json_paths)
7089 json_string = json_object_new_string("0.0.0.0");
7090 else
7091 vty_out (vty, " from 0.0.0.0 ");
7092 }
7093 else
7094 {
7095 if (json_paths)
7096 json_string = json_object_new_string("::");
7097 else
7098 vty_out (vty, " from :: ");
7099 }
7100
7101 if (json_paths)
7102 {
b05a1c8b 7103 json_object_object_add(json_path, "peer-id", json_string);
1c36cb2e
DS
7104 json_string = json_object_new_string(inet_ntoa(bgp->router_id));
7105 json_object_object_add(json_path, "peer-router-id", json_string);
b05a1c8b
DS
7106 }
7107 else
7108 {
7109 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
7110 }
718e3744 7111 }
7112 else
7113 {
7114 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
b05a1c8b
DS
7115 {
7116 if (json_paths)
7117 json_object_object_add(json_path, "nexthop-accessible", json_boolean_false);
7118 else
7119 vty_out (vty, " (inaccessible)");
7120 }
fb982c25 7121 else if (binfo->extra && binfo->extra->igpmetric)
b05a1c8b
DS
7122 {
7123 if (json_paths)
7124 {
7125 json_int = json_object_new_int(binfo->extra->igpmetric);
7126 json_object_object_add(json_path, "nexthop-igp-cost", json_int);
7127 json_object_object_add(json_path, "nexthop-accessible", json_boolean_true);
7128 }
7129 else
7130 {
7131 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
7132 }
7133 }
7134
7135 /* IGP cost to nexthop is 0 */
7136 else
7137 if (json_paths)
7138 json_object_object_add(json_path, "nexthop-accessible", json_boolean_true);
7139
7140 if (json_paths)
7141 {
7142 json_string = json_object_new_string(sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
1c36cb2e 7143 json_object_object_add(json_path, "peer-id", json_string);
6410e93a
DS
7144 if (binfo->peer->hostname)
7145 {
7146 json_string = json_object_new_string(binfo->peer->hostname);
7147 json_object_object_add(json_path, "peer-hostname", json_string);
7148 }
7149 if (binfo->peer->domainname)
7150 {
7151 json_string = json_object_new_string(binfo->peer->domainname);
7152 json_object_object_add(json_path, "peer-domainname", json_string);
7153 }
036a4e7d
DS
7154 if (binfo->peer->conf_if)
7155 {
7156 json_string = json_object_new_string(binfo->peer->conf_if);
7157 json_object_object_add(json_path, "peer-interface", json_string);
7158 }
b05a1c8b
DS
7159 }
7160 else
7161 {
036a4e7d 7162 if (binfo->peer->conf_if)
6410e93a
DS
7163 {
7164 if (binfo->peer->hostname &&
7165 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7166 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7167 binfo->peer->conf_if);
7168 else
7169 vty_out (vty, " from %s", binfo->peer->conf_if);
7170 }
036a4e7d 7171 else
6410e93a
DS
7172 {
7173 if (binfo->peer->hostname &&
7174 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7175 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7176 binfo->peer->host);
7177 else
7178 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7179 }
b05a1c8b
DS
7180
7181 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7182 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
7183 else
7184 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
7185 }
7186
7187 /* Always encode the peer's router-id in the json output. We will
7188 * include the originator-id later if this is a reflected route.
7189 */
7190 if (json_paths)
7191 {
7192 json_string = json_object_new_string(inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
1c36cb2e 7193 json_object_object_add(json_path, "peer-router-id", json_string);
b05a1c8b 7194 }
718e3744 7195 }
b05a1c8b
DS
7196
7197 if (!json_paths)
7198 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7199
7200#ifdef HAVE_IPV6
7201 /* display nexthop local */
801a9bcc 7202 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
718e3744 7203 {
b05a1c8b
DS
7204 if (json_paths)
7205 {
7206 json_string = json_object_new_string(inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7207 buf, INET6_ADDRSTRLEN));
7208 json_object_object_add(json_path, "nexthop-local", json_string);
7209 }
7210 else
7211 {
7212 vty_out (vty, " (%s)%s",
7213 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7214 buf, INET6_ADDRSTRLEN),
7215 VTY_NEWLINE);
7216 }
718e3744 7217 }
7218#endif /* HAVE_IPV6 */
7219
0d9551dc 7220 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
b05a1c8b
DS
7221 if (json_paths)
7222 {
7223 json_string = json_object_new_string(bgp_origin_long_str[attr->origin]);
7224 json_object_object_add(json_path, "origin", json_string);
7225 }
7226 else
7227 {
7228 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
7229 }
718e3744 7230
7231 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b
DS
7232 {
7233 if (json_paths)
7234 {
7235 json_int = json_object_new_int(attr->med);
7236 json_object_object_add(json_path, "med", json_int);
7237 }
7238 else
7239 {
7240 vty_out (vty, ", metric %u", attr->med);
7241 }
7242 }
718e3744 7243
7244 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
b05a1c8b
DS
7245 {
7246 if (json_paths)
7247 {
7248 json_int = json_object_new_int(attr->local_pref);
7249 json_object_object_add(json_path, "localpref", json_int);
7250 }
7251 else
7252 {
7253 vty_out (vty, ", localpref %u", attr->local_pref);
7254 }
7255 }
718e3744 7256 else
b05a1c8b
DS
7257 {
7258 if (json_paths)
7259 {
7260 json_int = json_object_new_int(bgp->default_local_pref);
7261 json_object_object_add(json_path, "localpref", json_int);
7262 }
7263 else
7264 {
7265 vty_out (vty, ", localpref %u", bgp->default_local_pref);
7266 }
7267 }
718e3744 7268
fb982c25 7269 if (attr->extra && attr->extra->weight != 0)
b05a1c8b
DS
7270 {
7271 if (json_paths)
7272 {
7273 json_int = json_object_new_int(attr->extra->weight);
7274 json_object_object_add(json_path, "weight", json_int);
7275 }
7276 else
7277 {
7278 vty_out (vty, ", weight %u", attr->extra->weight);
7279 }
7280 }
0d9551dc
DS
7281
7282 if (attr->extra && attr->extra->tag != 0)
b05a1c8b
DS
7283 {
7284 if (json_paths)
7285 {
7286 json_int = json_object_new_int(attr->extra->tag);
7287 json_object_object_add(json_path, "tag", json_int);
7288 }
7289 else
7290 {
7291 vty_out (vty, ", tag %d", attr->extra->tag);
7292 }
7293 }
718e3744 7294
31eba040 7295 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
b05a1c8b
DS
7296 {
7297 if (json_paths)
7298 json_object_object_add(json_path, "valid", json_boolean_false);
7299 else
7300 vty_out (vty, ", invalid");
7301 }
31eba040 7302 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
7303 {
7304 if (json_paths)
7305 json_object_object_add(json_path, "valid", json_boolean_true);
7306 else
7307 vty_out (vty, ", valid");
7308 }
718e3744 7309
7310 if (binfo->peer != bgp->peer_self)
7311 {
7312 if (binfo->peer->as == binfo->peer->local_as)
b05a1c8b
DS
7313 {
7314 if (json_paths)
7315 json_object_object_add(json_path, "internal", json_boolean_true);
7316 else
7317 vty_out (vty, ", internal");
7318 }
718e3744 7319 else
b05a1c8b
DS
7320 {
7321 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
7322 {
7323 if (json_paths)
7324 json_object_object_add(json_path, "confed-external", json_boolean_true);
7325 else
7326 vty_out (vty, ", confed-external");
7327 }
7328 else
7329 {
7330 if (json_paths)
7331 json_object_object_add(json_path, "external", json_boolean_true);
7332 else
7333 vty_out (vty, ", external");
7334 }
7335 }
718e3744 7336 }
7337 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
b05a1c8b
DS
7338 {
7339 if (json_paths)
7340 {
7341 json_object_object_add(json_path, "aggregated", json_boolean_true);
7342 json_object_object_add(json_path, "local", json_boolean_true);
7343 }
7344 else
7345 {
7346 vty_out (vty, ", aggregated, local");
7347 }
7348 }
718e3744 7349 else if (binfo->type != ZEBRA_ROUTE_BGP)
b05a1c8b
DS
7350 {
7351 if (json_paths)
7352 json_object_object_add(json_path, "sourced", json_boolean_true);
7353 else
7354 vty_out (vty, ", sourced");
7355 }
718e3744 7356 else
b05a1c8b
DS
7357 {
7358 if (json_paths)
7359 {
7360 json_object_object_add(json_path, "sourced", json_boolean_true);
7361 json_object_object_add(json_path, "local", json_boolean_true);
7362 }
7363 else
7364 {
7365 vty_out (vty, ", sourced, local");
7366 }
7367 }
718e3744 7368
7369 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
b05a1c8b
DS
7370 {
7371 if (json_paths)
7372 json_object_object_add(json_path, "atomic-aggregate", json_boolean_true);
7373 else
7374 vty_out (vty, ", atomic-aggregate");
7375 }
718e3744 7376
de8d5dff
JB
7377 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
7378 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
7379 bgp_info_mpath_count (binfo)))
b05a1c8b
DS
7380 {
7381 if (json_paths)
7382 json_object_object_add(json_path, "multipath", json_boolean_true);
7383 else
7384 vty_out (vty, ", multipath");
7385 }
de8d5dff 7386
718e3744 7387 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
b05a1c8b
DS
7388 {
7389 if (json_paths)
7390 json_object_object_add(json_path, "bestpath", json_boolean_true);
7391 else
7392 vty_out (vty, ", best");
7393 }
718e3744 7394
b05a1c8b
DS
7395 if (!json_paths)
7396 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7397
7398 /* Line 4 display Community */
7399 if (attr->community)
b05a1c8b
DS
7400 {
7401 if (json_paths)
7402 {
7403 json_string = json_object_new_string(attr->community->str);
7404 json_object_object_add(json_path, "community", json_string);
7405 }
7406 else
7407 {
7408 vty_out (vty, " Community: %s%s", attr->community->str,
7409 VTY_NEWLINE);
7410 }
7411 }
718e3744 7412
7413 /* Line 5 display Extended-community */
7414 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
b05a1c8b
DS
7415 {
7416 if (json_paths)
7417 {
7418 json_string = json_object_new_string(attr->extra->ecommunity->str);
7419 json_object_object_add(json_path, "extended-community", json_string);
7420 }
7421 else
7422 {
7423 vty_out (vty, " Extended Community: %s%s",
7424 attr->extra->ecommunity->str, VTY_NEWLINE);
7425 }
7426 }
7427
718e3744 7428 /* Line 6 display Originator, Cluster-id */
7429 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
7430 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
7431 {
fb982c25 7432 assert (attr->extra);
718e3744 7433 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
b05a1c8b
DS
7434 {
7435 if (json_paths)
7436 {
7437 json_string = json_object_new_string(inet_ntoa (attr->extra->originator_id));
7438 json_object_object_add(json_path, "originator-id", json_string);
7439 }
7440 else
7441 {
7442 vty_out (vty, " Originator: %s",
7443 inet_ntoa (attr->extra->originator_id));
7444 }
7445 }
718e3744 7446
7447 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
7448 {
7449 int i;
b05a1c8b
DS
7450
7451 if (json_paths)
7452 {
7453 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7454 {
7455 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
7456 json_object_array_add(json_cluster_list, json_string);
7457 }
7458 json_object_object_add(json_path, "cluster-list", json_cluster_list);
7459 }
7460 else
7461 {
7462 vty_out (vty, ", Cluster list: ");
7463
7464 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7465 {
7466 vty_out (vty, "%s ",
7467 inet_ntoa (attr->extra->cluster->list[i]));
7468 }
7469 }
718e3744 7470 }
b05a1c8b
DS
7471
7472 if (!json_paths)
7473 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7474 }
b05a1c8b 7475
fb982c25 7476 if (binfo->extra && binfo->extra->damp_info)
b05a1c8b 7477 bgp_damp_info_vty (vty, binfo, json_path);
718e3744 7478
a82478b9
DS
7479 /* Line 7 display Addpath IDs */
7480 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
b05a1c8b
DS
7481 {
7482 if (json_paths)
7483 {
7484 json_int = json_object_new_int(binfo->addpath_rx_id);
7485 json_object_object_add(json_path, "addpath-rx-id", json_int);
7486
7487 json_int = json_object_new_int(binfo->addpath_tx_id);
7488 json_object_object_add(json_path, "addpath-tx-id", json_int);
7489 }
7490 else
7491 {
7492 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
7493 binfo->addpath_rx_id, binfo->addpath_tx_id,
7494 VTY_NEWLINE);
7495 }
7496 }
a82478b9
DS
7497
7498 /* Line 8 display Uptime */
30b00176
JK
7499#ifdef HAVE_CLOCK_MONOTONIC
7500 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
b05a1c8b
DS
7501 if (json_paths)
7502 json_string = json_object_new_string(ctime(&tbuf));
7503 else
7504 vty_out (vty, " Last update: %s", ctime(&tbuf));
30b00176 7505#else
b05a1c8b
DS
7506 if (json_paths)
7507 json_string = json_object_new_string(ctime(&binfo->uptime));
7508 else
7509 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
30b00176 7510#endif /* HAVE_CLOCK_MONOTONIC */
b05a1c8b
DS
7511 if (json_paths)
7512 json_object_object_add(json_path, "last-update", json_string);
718e3744 7513 }
b05a1c8b
DS
7514
7515 /* We've constructed the json object for this path, add it to the json
7516 * array of paths
7517 */
7518 if (json_paths)
7519 json_object_array_add(json_paths, json_path);
7520 else
7521 vty_out (vty, "%s", VTY_NEWLINE);
b366b518
BB
7522}
7523
47fc97cc 7524#define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
718e3744 7525#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7526#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7527
7528enum bgp_show_type
7529{
7530 bgp_show_type_normal,
7531 bgp_show_type_regexp,
7532 bgp_show_type_prefix_list,
7533 bgp_show_type_filter_list,
7534 bgp_show_type_route_map,
7535 bgp_show_type_neighbor,
7536 bgp_show_type_cidr_only,
7537 bgp_show_type_prefix_longer,
7538 bgp_show_type_community_all,
7539 bgp_show_type_community,
7540 bgp_show_type_community_exact,
7541 bgp_show_type_community_list,
7542 bgp_show_type_community_list_exact,
7543 bgp_show_type_flap_statistics,
7544 bgp_show_type_flap_address,
7545 bgp_show_type_flap_prefix,
7546 bgp_show_type_flap_cidr_only,
7547 bgp_show_type_flap_regexp,
7548 bgp_show_type_flap_filter_list,
7549 bgp_show_type_flap_prefix_list,
7550 bgp_show_type_flap_prefix_longer,
7551 bgp_show_type_flap_route_map,
7552 bgp_show_type_flap_neighbor,
7553 bgp_show_type_dampend_paths,
7554 bgp_show_type_damp_neighbor
7555};
7556
5a646650 7557static int
fee0f4c6 7558bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
b05a1c8b 7559 enum bgp_show_type type, void *output_arg, u_char use_json)
718e3744 7560{
718e3744 7561 struct bgp_info *ri;
7562 struct bgp_node *rn;
718e3744 7563 int header = 1;
718e3744 7564 int display;
5a646650 7565 unsigned long output_count;
b05a1c8b
DS
7566 struct prefix *p;
7567 char buf[BUFSIZ];
7568 char buf2[BUFSIZ];
7569 json_object *json;
7570 json_object *json_int;
7571 json_object *json_paths;
7572 json_object *json_routes;
7573 json_object *json_string;
7574
7575 if (use_json)
7576 {
7577 json = json_object_new_object();
7578 json_int = json_object_new_int(table->version);
7579 json_object_object_add(json, "table-version", json_int);
7580
7581 json_string = json_object_new_string(inet_ntoa (*router_id));
7582 json_object_object_add(json, "router-id", json_string);
7583
7584 json_routes = json_object_new_object();
7585 }
718e3744 7586
7587 /* This is first entry point, so reset total line. */
5a646650 7588 output_count = 0;
718e3744 7589
718e3744 7590 /* Start processing of routes. */
7591 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7592 if (rn->info != NULL)
7593 {
7594 display = 0;
7595
b05a1c8b
DS
7596 if (use_json)
7597 json_paths = json_object_new_array();
7598 else
7599 json_paths = NULL;
7600
718e3744 7601 for (ri = rn->info; ri; ri = ri->next)
7602 {
5a646650 7603 if (type == bgp_show_type_flap_statistics
718e3744 7604 || type == bgp_show_type_flap_address
7605 || type == bgp_show_type_flap_prefix
7606 || type == bgp_show_type_flap_cidr_only
7607 || type == bgp_show_type_flap_regexp
7608 || type == bgp_show_type_flap_filter_list
7609 || type == bgp_show_type_flap_prefix_list
7610 || type == bgp_show_type_flap_prefix_longer
7611 || type == bgp_show_type_flap_route_map
7612 || type == bgp_show_type_flap_neighbor
7613 || type == bgp_show_type_dampend_paths
7614 || type == bgp_show_type_damp_neighbor)
7615 {
fb982c25 7616 if (!(ri->extra && ri->extra->damp_info))
718e3744 7617 continue;
7618 }
7619 if (type == bgp_show_type_regexp
7620 || type == bgp_show_type_flap_regexp)
7621 {
5a646650 7622 regex_t *regex = output_arg;
718e3744 7623
7624 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7625 continue;
7626 }
7627 if (type == bgp_show_type_prefix_list
7628 || type == bgp_show_type_flap_prefix_list)
7629 {
5a646650 7630 struct prefix_list *plist = output_arg;
718e3744 7631
7632 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7633 continue;
7634 }
7635 if (type == bgp_show_type_filter_list
7636 || type == bgp_show_type_flap_filter_list)
7637 {
5a646650 7638 struct as_list *as_list = output_arg;
718e3744 7639
7640 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7641 continue;
7642 }
7643 if (type == bgp_show_type_route_map
7644 || type == bgp_show_type_flap_route_map)
7645 {
5a646650 7646 struct route_map *rmap = output_arg;
718e3744 7647 struct bgp_info binfo;
558d1fec
JBD
7648 struct attr dummy_attr;
7649 struct attr_extra dummy_extra;
718e3744 7650 int ret;
7651
558d1fec 7652 dummy_attr.extra = &dummy_extra;
fb982c25 7653 bgp_attr_dup (&dummy_attr, ri->attr);
558d1fec 7654
718e3744 7655 binfo.peer = ri->peer;
7656 binfo.attr = &dummy_attr;
7657
7658 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
718e3744 7659 if (ret == RMAP_DENYMATCH)
7660 continue;
7661 }
7662 if (type == bgp_show_type_neighbor
7663 || type == bgp_show_type_flap_neighbor
7664 || type == bgp_show_type_damp_neighbor)
7665 {
5a646650 7666 union sockunion *su = output_arg;
718e3744 7667
7668 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7669 continue;
7670 }
7671 if (type == bgp_show_type_cidr_only
7672 || type == bgp_show_type_flap_cidr_only)
7673 {
7674 u_int32_t destination;
7675
7676 destination = ntohl (rn->p.u.prefix4.s_addr);
7677 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7678 continue;
7679 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7680 continue;
7681 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7682 continue;
7683 }
7684 if (type == bgp_show_type_prefix_longer
7685 || type == bgp_show_type_flap_prefix_longer)
7686 {
5a646650 7687 struct prefix *p = output_arg;
718e3744 7688
7689 if (! prefix_match (p, &rn->p))
7690 continue;
7691 }
7692 if (type == bgp_show_type_community_all)
7693 {
7694 if (! ri->attr->community)
7695 continue;
7696 }
7697 if (type == bgp_show_type_community)
7698 {
5a646650 7699 struct community *com = output_arg;
718e3744 7700
7701 if (! ri->attr->community ||
7702 ! community_match (ri->attr->community, com))
7703 continue;
7704 }
7705 if (type == bgp_show_type_community_exact)
7706 {
5a646650 7707 struct community *com = output_arg;
718e3744 7708
7709 if (! ri->attr->community ||
7710 ! community_cmp (ri->attr->community, com))
7711 continue;
7712 }
7713 if (type == bgp_show_type_community_list)
7714 {
5a646650 7715 struct community_list *list = output_arg;
718e3744 7716
7717 if (! community_list_match (ri->attr->community, list))
7718 continue;
7719 }
7720 if (type == bgp_show_type_community_list_exact)
7721 {
5a646650 7722 struct community_list *list = output_arg;
718e3744 7723
7724 if (! community_list_exact_match (ri->attr->community, list))
7725 continue;
7726 }
7727 if (type == bgp_show_type_flap_address
7728 || type == bgp_show_type_flap_prefix)
7729 {
5a646650 7730 struct prefix *p = output_arg;
718e3744 7731
7732 if (! prefix_match (&rn->p, p))
7733 continue;
7734
7735 if (type == bgp_show_type_flap_prefix)
7736 if (p->prefixlen != rn->p.prefixlen)
7737 continue;
7738 }
7739 if (type == bgp_show_type_dampend_paths
7740 || type == bgp_show_type_damp_neighbor)
7741 {
7742 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7743 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7744 continue;
7745 }
7746
b05a1c8b 7747 if (!use_json && header)
718e3744 7748 {
ffd0c037 7749 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (*router_id), VTY_NEWLINE);
93406d87 7750 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7751 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 7752 if (type == bgp_show_type_dampend_paths
7753 || type == bgp_show_type_damp_neighbor)
7754 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7755 else if (type == bgp_show_type_flap_statistics
7756 || type == bgp_show_type_flap_address
7757 || type == bgp_show_type_flap_prefix
7758 || type == bgp_show_type_flap_cidr_only
7759 || type == bgp_show_type_flap_regexp
7760 || type == bgp_show_type_flap_filter_list
7761 || type == bgp_show_type_flap_prefix_list
7762 || type == bgp_show_type_flap_prefix_longer
7763 || type == bgp_show_type_flap_route_map
7764 || type == bgp_show_type_flap_neighbor)
7765 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7766 else
7767 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
718e3744 7768 header = 0;
7769 }
7770
7771 if (type == bgp_show_type_dampend_paths
7772 || type == bgp_show_type_damp_neighbor)
5a646650 7773 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
718e3744 7774 else if (type == bgp_show_type_flap_statistics
7775 || type == bgp_show_type_flap_address
7776 || type == bgp_show_type_flap_prefix
7777 || type == bgp_show_type_flap_cidr_only
7778 || type == bgp_show_type_flap_regexp
7779 || type == bgp_show_type_flap_filter_list
7780 || type == bgp_show_type_flap_prefix_list
7781 || type == bgp_show_type_flap_prefix_longer
7782 || type == bgp_show_type_flap_route_map
7783 || type == bgp_show_type_flap_neighbor)
5a646650 7784 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
718e3744 7785 else
b05a1c8b 7786 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
718e3744 7787 display++;
7788 }
b05a1c8b
DS
7789
7790 if (use_json)
7791 {
7792 p = &rn->p;
7793 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
7794 json_object_object_add(json_routes, buf2, json_paths);
7795 }
7796
718e3744 7797 if (display)
5a646650 7798 output_count++;
718e3744 7799 }
7800
b05a1c8b 7801 if (use_json)
718e3744 7802 {
b05a1c8b
DS
7803 json_object_object_add(json, "routes", json_routes);
7804 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
7805
7806 // Recursively free all json structures
7807 json_object_put(json);
718e3744 7808 }
7809 else
b05a1c8b
DS
7810 {
7811 /* No route is displayed */
7812 if (output_count == 0)
7813 {
7814 if (type == bgp_show_type_normal)
7815 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
7816 }
7817 else
7818 vty_out (vty, "%sTotal number of prefixes %ld%s",
7819 VTY_NEWLINE, output_count, VTY_NEWLINE);
7820 }
718e3744 7821
7822 return CMD_SUCCESS;
7823}
7824
5a646650 7825static int
fee0f4c6 7826bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
b05a1c8b 7827 enum bgp_show_type type, void *output_arg, u_char use_json)
fee0f4c6 7828{
7829 struct bgp_table *table;
7830
7831 if (bgp == NULL) {
7832 bgp = bgp_get_default ();
7833 }
7834
7835 if (bgp == NULL)
7836 {
7837 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7838 return CMD_WARNING;
7839 }
7840
7841
7842 table = bgp->rib[afi][safi];
7843
b05a1c8b 7844 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg, use_json);
fee0f4c6 7845}
7846
718e3744 7847/* Header of detailed BGP route information */
94f2b392 7848static void
718e3744 7849route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7850 struct bgp_node *rn,
b05a1c8b
DS
7851 struct prefix_rd *prd, afi_t afi, safi_t safi,
7852 json_object *json)
718e3744 7853{
7854 struct bgp_info *ri;
7855 struct prefix *p;
7856 struct peer *peer;
1eb8ef25 7857 struct listnode *node, *nnode;
718e3744 7858 char buf1[INET6_ADDRSTRLEN];
7859 char buf2[INET6_ADDRSTRLEN];
7860 int count = 0;
7861 int best = 0;
7862 int suppress = 0;
7863 int no_export = 0;
7864 int no_advertise = 0;
7865 int local_as = 0;
7866 int first = 0;
b05a1c8b
DS
7867 json_object *json_string;
7868 json_object *json_int;
ffd0c037 7869 json_object *json_adv_to = NULL;
718e3744 7870
7871 p = &rn->p;
b05a1c8b
DS
7872
7873 if (json)
7874 {
7875 json_string = json_object_new_string(inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7876 json_object_object_add(json, "prefix", json_string);
7877
7878 json_int = json_object_new_int(p->prefixlen);
7879 json_object_object_add(json, "prefixlen", json_int);
7880 json_adv_to = json_object_new_array();
7881 }
7882 else
7883 {
7884 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
7885 (safi == SAFI_MPLS_VPN ?
7886 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7887 safi == SAFI_MPLS_VPN ? ":" : "",
7888 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7889 p->prefixlen, VTY_NEWLINE);
7890 }
718e3744 7891
7892 for (ri = rn->info; ri; ri = ri->next)
7893 {
7894 count++;
7895 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7896 {
7897 best = count;
fb982c25 7898 if (ri->extra && ri->extra->suppress)
718e3744 7899 suppress = 1;
7900 if (ri->attr->community != NULL)
7901 {
7902 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7903 no_advertise = 1;
7904 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7905 no_export = 1;
7906 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7907 local_as = 1;
7908 }
7909 }
7910 }
7911
b05a1c8b 7912 if (!json)
718e3744 7913 {
b05a1c8b
DS
7914 vty_out (vty, "Paths: (%d available", count);
7915 if (best)
7916 {
7917 vty_out (vty, ", best #%d", best);
7918 if (safi == SAFI_UNICAST)
7919 vty_out (vty, ", table Default-IP-Routing-Table");
7920 }
7921 else
7922 vty_out (vty, ", no best path");
7923
7924 if (no_advertise)
7925 vty_out (vty, ", not advertised to any peer");
7926 else if (no_export)
7927 vty_out (vty, ", not advertised to EBGP peer");
7928 else if (local_as)
7929 vty_out (vty, ", not advertised outside local AS");
7930
7931 if (suppress)
7932 vty_out (vty, ", Advertisements suppressed by an aggregate.");
7933 vty_out (vty, ")%s", VTY_NEWLINE);
718e3744 7934 }
718e3744 7935
7936 /* advertised peer */
1eb8ef25 7937 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
718e3744 7938 {
7939 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
7940 {
b05a1c8b
DS
7941 if (json)
7942 {
6410e93a
DS
7943 if (peer->hostname)
7944 {
7945 json_string = json_object_new_string(peer->hostname);
7946 json_object_array_add(json_adv_to, json_string);
7947
7948 /* TODO: Have to add domain name here too */
7949 }
036a4e7d
DS
7950 if (peer->conf_if)
7951 {
7952 json_string = json_object_new_string(peer->conf_if);
7953 json_object_array_add(json_adv_to, json_string);
7954 }
7955 else
7956 {
7957 json_string = json_object_new_string(sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
7958 json_object_array_add(json_adv_to, json_string);
7959 }
b05a1c8b
DS
7960 }
7961 else
7962 {
7963 if (! first)
7964 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
036a4e7d 7965
6410e93a
DS
7966 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7967 {
7968 if (peer->conf_if)
7969 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
7970 else
7971 vty_out (vty, " %s(%s)", peer->hostname,
7972 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
7973 }
7974 else
7975 {
7976 if (peer->conf_if)
7977 vty_out (vty, " %s", peer->conf_if);
7978 else
7979 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
7980 }
b05a1c8b
DS
7981 }
7982 first = 1;
718e3744 7983 }
7984 }
b05a1c8b
DS
7985
7986 if (json)
7987 {
7988 if (first)
7989 {
7990 json_object_object_add(json, "advertised-to", json_adv_to);
7991 }
7992 }
7993 else
7994 {
7995 if (!first)
7996 vty_out (vty, " Not advertised to any peer");
7997 vty_out (vty, "%s", VTY_NEWLINE);
7998 }
718e3744 7999}
8000
8001/* Display specified route of BGP table. */
94f2b392 8002static int
fee0f4c6 8003bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
fd79ac91 8004 struct bgp_table *rib, const char *ip_str,
8005 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
8006 int prefix_check, enum bgp_path_type pathtype,
8007 u_char use_json)
718e3744 8008{
8009 int ret;
8010 int header;
8011 int display = 0;
8012 struct prefix match;
8013 struct bgp_node *rn;
8014 struct bgp_node *rm;
8015 struct bgp_info *ri;
718e3744 8016 struct bgp_table *table;
b05a1c8b
DS
8017 json_object *json;
8018 json_object *json_paths;
718e3744 8019
718e3744 8020 /* Check IP address argument. */
8021 ret = str2prefix (ip_str, &match);
8022 if (! ret)
8023 {
8024 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
8025 return CMD_WARNING;
8026 }
8027
8028 match.family = afi2family (afi);
8029
b05a1c8b
DS
8030 if (use_json)
8031 {
8032 json = json_object_new_object();
8033 json_paths = json_object_new_array();
8034 }
8035 else
8036 {
8037 json = NULL;
8038 json_paths = NULL;
8039 }
8040
718e3744 8041 if (safi == SAFI_MPLS_VPN)
8042 {
fee0f4c6 8043 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
718e3744 8044 {
8045 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
8046 continue;
8047
8048 if ((table = rn->info) != NULL)
8049 {
8050 header = 1;
8051
8052 if ((rm = bgp_node_match (table, &match)) != NULL)
8053 {
8054 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6c88b44d
CC
8055 {
8056 bgp_unlock_node (rm);
8057 continue;
8058 }
718e3744 8059
8060 for (ri = rm->info; ri; ri = ri->next)
8061 {
8062 if (header)
8063 {
8064 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
b05a1c8b 8065 AFI_IP, SAFI_MPLS_VPN, json);
718e3744 8066
8067 header = 0;
8068 }
8069 display++;
4092b06c
DS
8070
8071 if (pathtype == BGP_PATH_ALL ||
8072 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8073 (pathtype == BGP_PATH_MULTIPATH &&
8074 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
b05a1c8b 8075 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN, json_paths);
718e3744 8076 }
6c88b44d
CC
8077
8078 bgp_unlock_node (rm);
718e3744 8079 }
8080 }
8081 }
8082 }
8083 else
8084 {
8085 header = 1;
8086
fee0f4c6 8087 if ((rn = bgp_node_match (rib, &match)) != NULL)
718e3744 8088 {
8089 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
8090 {
8091 for (ri = rn->info; ri; ri = ri->next)
8092 {
8093 if (header)
8094 {
b05a1c8b 8095 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
718e3744 8096 header = 0;
8097 }
8098 display++;
4092b06c
DS
8099
8100 if (pathtype == BGP_PATH_ALL ||
8101 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8102 (pathtype == BGP_PATH_MULTIPATH &&
8103 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
b05a1c8b 8104 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
718e3744 8105 }
8106 }
6c88b44d
CC
8107
8108 bgp_unlock_node (rn);
718e3744 8109 }
8110 }
8111
e5eee9af 8112 if (use_json)
718e3744 8113 {
e5eee9af
DS
8114 if (display)
8115 json_object_object_add(json, "paths", json_paths);
8116
8117 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
8118
8119 // Recursively free all json structures
8120 json_object_put(json);
b05a1c8b
DS
8121 }
8122 else
8123 {
e5eee9af 8124 if (!display)
b05a1c8b
DS
8125 {
8126 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
8127 return CMD_WARNING;
8128 }
8129 }
8130
718e3744 8131 return CMD_SUCCESS;
8132}
8133
fee0f4c6 8134/* Display specified route of Main RIB */
94f2b392 8135static int
fd79ac91 8136bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
fee0f4c6 8137 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
8138 int prefix_check, enum bgp_path_type pathtype,
8139 u_char use_json)
fee0f4c6 8140{
8141 struct bgp *bgp;
8142
8143 /* BGP structure lookup. */
8144 if (view_name)
8145 {
8146 bgp = bgp_lookup_by_name (view_name);
8147 if (bgp == NULL)
8148 {
8149 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8150 return CMD_WARNING;
8151 }
8152 }
8153 else
8154 {
8155 bgp = bgp_get_default ();
8156 if (bgp == NULL)
8157 {
8158 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8159 return CMD_WARNING;
8160 }
8161 }
8162
8163 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
b05a1c8b
DS
8164 afi, safi, prd, prefix_check, pathtype,
8165 use_json);
fee0f4c6 8166}
8167
718e3744 8168/* BGP route print out function. */
8169DEFUN (show_ip_bgp,
8170 show_ip_bgp_cmd,
b05a1c8b 8171 "show ip bgp {json}",
47fc97cc
DS
8172 SHOW_STR
8173 IP_STR
b05a1c8b
DS
8174 BGP_STR
8175 "JavaScript Object Notation\n")
47fc97cc 8176{
b05a1c8b
DS
8177 u_char use_json = (argv[0] != NULL);
8178 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
718e3744 8179}
8180
8181DEFUN (show_ip_bgp_ipv4,
8182 show_ip_bgp_ipv4_cmd,
b05a1c8b 8183 "show ip bgp ipv4 (unicast|multicast) {json}",
718e3744 8184 SHOW_STR
8185 IP_STR
8186 BGP_STR
8187 "Address family\n"
8188 "Address Family modifier\n"
b05a1c8b
DS
8189 "Address Family modifier\n"
8190 "JavaScript Object Notation\n")
718e3744 8191{
b05a1c8b
DS
8192 u_char use_json = (argv[1] != NULL);
8193
718e3744 8194 if (strncmp (argv[0], "m", 1) == 0)
5a646650 8195 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
b05a1c8b 8196 NULL, use_json);
718e3744 8197
b05a1c8b 8198 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
718e3744 8199}
8200
95cbbd2a
ML
8201ALIAS (show_ip_bgp_ipv4,
8202 show_bgp_ipv4_safi_cmd,
b05a1c8b 8203 "show bgp ipv4 (unicast|multicast) {json}",
95cbbd2a
ML
8204 SHOW_STR
8205 BGP_STR
8206 "Address family\n"
8207 "Address Family modifier\n"
47fc97cc 8208 "Address Family modifier\n"
b05a1c8b 8209 "JavaScript Object Notation\n")
47fc97cc 8210
718e3744 8211DEFUN (show_ip_bgp_route,
8212 show_ip_bgp_route_cmd,
b05a1c8b 8213 "show ip bgp A.B.C.D {json}",
718e3744 8214 SHOW_STR
8215 IP_STR
8216 BGP_STR
b05a1c8b
DS
8217 "Network in the BGP routing table to display\n"
8218 "JavaScript Object Notation\n")
718e3744 8219{
b05a1c8b
DS
8220 u_char use_json = (argv[1] != NULL);
8221 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
4092b06c
DS
8222}
8223
8224DEFUN (show_ip_bgp_route_pathtype,
8225 show_ip_bgp_route_pathtype_cmd,
b05a1c8b 8226 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
4092b06c
DS
8227 SHOW_STR
8228 IP_STR
8229 BGP_STR
8230 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8231 "Display only the bestpath\n"
b05a1c8b
DS
8232 "Display only multipaths\n"
8233 "JavaScript Object Notation\n")
4092b06c 8234{
b05a1c8b
DS
8235 u_char use_json = (argv[2] != NULL);
8236
4092b06c 8237 if (strncmp (argv[1], "b", 1) == 0)
b05a1c8b 8238 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8239 else
b05a1c8b 8240 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8241}
8242
8243DEFUN (show_bgp_ipv4_safi_route_pathtype,
8244 show_bgp_ipv4_safi_route_pathtype_cmd,
b05a1c8b 8245 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath) {json}",
4092b06c
DS
8246 SHOW_STR
8247 BGP_STR
8248 "Address family\n"
8249 "Address Family modifier\n"
8250 "Address Family modifier\n"
8251 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8252 "Display only the bestpath\n"
b05a1c8b
DS
8253 "Display only multipaths\n"
8254 "JavaScript Object Notation\n")
4092b06c 8255{
b05a1c8b
DS
8256 u_char use_json = (argv[3] != NULL);
8257
4092b06c
DS
8258 if (strncmp (argv[0], "m", 1) == 0)
8259 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8260 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8261 else
b05a1c8b 8262 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8263 else
8264 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8265 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8266 else
b05a1c8b 8267 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
718e3744 8268}
8269
8270DEFUN (show_ip_bgp_ipv4_route,
8271 show_ip_bgp_ipv4_route_cmd,
b05a1c8b 8272 "show ip bgp ipv4 (unicast|multicast) A.B.C.D {json}",
718e3744 8273 SHOW_STR
8274 IP_STR
8275 BGP_STR
8276 "Address family\n"
8277 "Address Family modifier\n"
8278 "Address Family modifier\n"
b05a1c8b
DS
8279 "Network in the BGP routing table to display\n"
8280 "JavaScript Object Notation\n")
718e3744 8281{
b05a1c8b
DS
8282 u_char use_json = (argv[2] != NULL);
8283
718e3744 8284 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 8285 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8286
b05a1c8b 8287 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8288}
8289
95cbbd2a
ML
8290ALIAS (show_ip_bgp_ipv4_route,
8291 show_bgp_ipv4_safi_route_cmd,
b05a1c8b 8292 "show bgp ipv4 (unicast|multicast) A.B.C.D {json}",
95cbbd2a
ML
8293 SHOW_STR
8294 BGP_STR
8295 "Address family\n"
8296 "Address Family modifier\n"
8297 "Address Family modifier\n"
b05a1c8b
DS
8298 "Network in the BGP routing table to display\n"
8299 "JavaScript Object Notation\n")
95cbbd2a 8300
718e3744 8301DEFUN (show_ip_bgp_vpnv4_all_route,
8302 show_ip_bgp_vpnv4_all_route_cmd,
b05a1c8b 8303 "show ip bgp vpnv4 all A.B.C.D {json}",
718e3744 8304 SHOW_STR
8305 IP_STR
8306 BGP_STR
8307 "Display VPNv4 NLRI specific information\n"
8308 "Display information about all VPNv4 NLRIs\n"
b05a1c8b
DS
8309 "Network in the BGP routing table to display\n"
8310 "JavaScript Object Notation\n")
718e3744 8311{
b05a1c8b
DS
8312 u_char use_json = (argv[1] != NULL);
8313 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8314}
8315
4092b06c 8316
718e3744 8317DEFUN (show_ip_bgp_vpnv4_rd_route,
8318 show_ip_bgp_vpnv4_rd_route_cmd,
b05a1c8b 8319 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
718e3744 8320 SHOW_STR
8321 IP_STR
8322 BGP_STR
8323 "Display VPNv4 NLRI specific information\n"
8324 "Display information for a route distinguisher\n"
8325 "VPN Route Distinguisher\n"
b05a1c8b
DS
8326 "Network in the BGP routing table to display\n"
8327 "JavaScript Object Notation\n")
718e3744 8328{
8329 int ret;
8330 struct prefix_rd prd;
b05a1c8b 8331 u_char use_json = (argv[2] != NULL);
718e3744 8332
8333 ret = str2prefix_rd (argv[0], &prd);
8334 if (! ret)
8335 {
8336 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8337 return CMD_WARNING;
8338 }
b05a1c8b 8339 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json);
718e3744 8340}
8341
8342DEFUN (show_ip_bgp_prefix,
8343 show_ip_bgp_prefix_cmd,
b05a1c8b 8344 "show ip bgp A.B.C.D/M {json}",
718e3744 8345 SHOW_STR
8346 IP_STR
8347 BGP_STR
b05a1c8b
DS
8348 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8349 "JavaScript Object Notation\n")
718e3744 8350{
b05a1c8b
DS
8351 u_char use_json = (argv[1] != NULL);
8352 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
4092b06c
DS
8353}
8354
8355DEFUN (show_ip_bgp_prefix_pathtype,
8356 show_ip_bgp_prefix_pathtype_cmd,
b05a1c8b 8357 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8358 SHOW_STR
8359 IP_STR
8360 BGP_STR
8361 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8362 "Display only the bestpath\n"
b05a1c8b
DS
8363 "Display only multipaths\n"
8364 "JavaScript Object Notation\n")
4092b06c 8365{
b05a1c8b 8366 u_char use_json = (argv[2] != NULL);
4092b06c 8367 if (strncmp (argv[1], "b", 1) == 0)
b05a1c8b 8368 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8369 else
b05a1c8b 8370 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
718e3744 8371}
8372
8373DEFUN (show_ip_bgp_ipv4_prefix,
8374 show_ip_bgp_ipv4_prefix_cmd,
b05a1c8b 8375 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
718e3744 8376 SHOW_STR
8377 IP_STR
8378 BGP_STR
8379 "Address family\n"
8380 "Address Family modifier\n"
8381 "Address Family modifier\n"
b05a1c8b
DS
8382 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8383 "JavaScript Object Notation\n")
718e3744 8384{
b05a1c8b
DS
8385 u_char use_json = (argv[2] != NULL);
8386
718e3744 8387 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 8388 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8389
b05a1c8b 8390 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8391}
8392
95cbbd2a
ML
8393ALIAS (show_ip_bgp_ipv4_prefix,
8394 show_bgp_ipv4_safi_prefix_cmd,
b05a1c8b 8395 "show bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
95cbbd2a
ML
8396 SHOW_STR
8397 BGP_STR
8398 "Address family\n"
8399 "Address Family modifier\n"
8400 "Address Family modifier\n"
b05a1c8b
DS
8401 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8402 "JavaScript Object Notation\n")
95cbbd2a 8403
4092b06c
DS
8404DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
8405 show_ip_bgp_ipv4_prefix_pathtype_cmd,
b05a1c8b 8406 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8407 SHOW_STR
8408 IP_STR
8409 BGP_STR
8410 "Address family\n"
8411 "Address Family modifier\n"
8412 "Address Family modifier\n"
8413 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8414 "Display only the bestpath\n"
b05a1c8b
DS
8415 "Display only multipaths\n"
8416 "JavaScript Object Notation\n")
4092b06c 8417{
b05a1c8b
DS
8418 u_char use_json = (argv[3] != NULL);
8419
4092b06c
DS
8420 if (strncmp (argv[0], "m", 1) == 0)
8421 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8422 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8423 else
b05a1c8b 8424 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8425 else
8426 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8427 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8428 else
b05a1c8b 8429 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8430}
8431
8432ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
8433 show_bgp_ipv4_safi_prefix_pathtype_cmd,
b05a1c8b 8434 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8435 SHOW_STR
8436 BGP_STR
8437 "Address family\n"
8438 "Address Family modifier\n"
8439 "Address Family modifier\n"
8440 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8441 "Display only the bestpath\n"
b05a1c8b
DS
8442 "Display only multipaths\n"
8443 "JavaScript Object Notation\n")
4092b06c 8444
718e3744 8445DEFUN (show_ip_bgp_vpnv4_all_prefix,
8446 show_ip_bgp_vpnv4_all_prefix_cmd,
b05a1c8b 8447 "show ip bgp vpnv4 all A.B.C.D/M {json}",
718e3744 8448 SHOW_STR
8449 IP_STR
8450 BGP_STR
8451 "Display VPNv4 NLRI specific information\n"
8452 "Display information about all VPNv4 NLRIs\n"
b05a1c8b
DS
8453 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8454 "JavaScript Object Notation\n")
718e3744 8455{
b05a1c8b
DS
8456 u_char use_json = (argv[1] != NULL);
8457 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8458}
8459
8460DEFUN (show_ip_bgp_vpnv4_rd_prefix,
8461 show_ip_bgp_vpnv4_rd_prefix_cmd,
b05a1c8b 8462 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
718e3744 8463 SHOW_STR
8464 IP_STR
8465 BGP_STR
8466 "Display VPNv4 NLRI specific information\n"
8467 "Display information for a route distinguisher\n"
8468 "VPN Route Distinguisher\n"
b05a1c8b
DS
8469 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8470 "JavaScript Object Notation\n")
718e3744 8471{
8472 int ret;
8473 struct prefix_rd prd;
b05a1c8b 8474 u_char use_json = (argv[2] != NULL);
718e3744 8475
8476 ret = str2prefix_rd (argv[0], &prd);
8477 if (! ret)
8478 {
8479 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8480 return CMD_WARNING;
8481 }
b05a1c8b 8482 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json);
718e3744 8483}
8484
8485DEFUN (show_ip_bgp_view,
8486 show_ip_bgp_view_cmd,
b05a1c8b 8487 "show ip bgp view WORD {json}",
718e3744 8488 SHOW_STR
8489 IP_STR
8490 BGP_STR
8491 "BGP view\n"
b05a1c8b
DS
8492 "View name\n"
8493 "JavaScript Object Notation\n")
718e3744 8494{
bb46e94f 8495 struct bgp *bgp;
b05a1c8b 8496 u_char use_json = (argv[1] != NULL);
bb46e94f 8497
8498 /* BGP structure lookup. */
8499 bgp = bgp_lookup_by_name (argv[0]);
8500 if (bgp == NULL)
8501 {
8502 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8503 return CMD_WARNING;
8504 }
8505
b05a1c8b 8506 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
718e3744 8507}
8508
8509DEFUN (show_ip_bgp_view_route,
8510 show_ip_bgp_view_route_cmd,
b05a1c8b 8511 "show ip bgp view WORD A.B.C.D {json}",
718e3744 8512 SHOW_STR
8513 IP_STR
8514 BGP_STR
8515 "BGP view\n"
2b00515a 8516 "View name\n"
b05a1c8b
DS
8517 "Network in the BGP routing table to display\n"
8518 "JavaScript Object Notation\n")
718e3744 8519{
b05a1c8b
DS
8520 u_char use_json = (argv[2] != NULL);
8521 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8522}
8523
8524DEFUN (show_ip_bgp_view_prefix,
8525 show_ip_bgp_view_prefix_cmd,
b05a1c8b 8526 "show ip bgp view WORD A.B.C.D/M {json}",
718e3744 8527 SHOW_STR
8528 IP_STR
8529 BGP_STR
8530 "BGP view\n"
2b00515a 8531 "View name\n"
b05a1c8b
DS
8532 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8533 "JavaScript Object Notation\n")
718e3744 8534{
b05a1c8b
DS
8535 u_char use_json = (argv[2] != NULL);
8536 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8537}
8538
8539#ifdef HAVE_IPV6
8540DEFUN (show_bgp,
8541 show_bgp_cmd,
b05a1c8b 8542 "show bgp {json}",
718e3744 8543 SHOW_STR
b05a1c8b
DS
8544 BGP_STR
8545 "JavaScript Object Notation\n")
718e3744 8546{
b05a1c8b 8547 u_char use_json = (argv[0] != NULL);
5a646650 8548 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
b05a1c8b 8549 NULL, use_json);
718e3744 8550}
8551
8552ALIAS (show_bgp,
8553 show_bgp_ipv6_cmd,
b05a1c8b 8554 "show bgp ipv6 {json}",
718e3744 8555 SHOW_STR
8556 BGP_STR
b05a1c8b
DS
8557 "Address family\n"
8558 "JavaScript Object Notation\n")
718e3744 8559
95cbbd2a
ML
8560DEFUN (show_bgp_ipv6_safi,
8561 show_bgp_ipv6_safi_cmd,
b05a1c8b 8562 "show bgp ipv6 (unicast|multicast) {json}",
95cbbd2a
ML
8563 SHOW_STR
8564 BGP_STR
8565 "Address family\n"
8566 "Address Family modifier\n"
47fc97cc 8567 "Address Family modifier\n"
b05a1c8b 8568 "JavaScript Object Notation\n")
47fc97cc 8569{
b05a1c8b 8570 u_char use_json = (argv[1] != NULL);
47fc97cc
DS
8571 if (strncmp (argv[0], "m", 1) == 0)
8572 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
b05a1c8b 8573 NULL, use_json);
47fc97cc 8574
b05a1c8b 8575 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
95cbbd2a
ML
8576}
8577
718e3744 8578/* old command */
8579DEFUN (show_ipv6_bgp,
8580 show_ipv6_bgp_cmd,
b05a1c8b 8581 "show ipv6 bgp {json}",
718e3744 8582 SHOW_STR
8583 IP_STR
b05a1c8b
DS
8584 BGP_STR
8585 "JavaScript Object Notation\n")
718e3744 8586{
b05a1c8b 8587 u_char use_json = (argv[0] != NULL);
5a646650 8588 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
b05a1c8b 8589 NULL, use_json);
718e3744 8590}
8591
8592DEFUN (show_bgp_route,
8593 show_bgp_route_cmd,
b05a1c8b 8594 "show bgp X:X::X:X {json}",
718e3744 8595 SHOW_STR
8596 BGP_STR
b05a1c8b
DS
8597 "Network in the BGP routing table to display\n"
8598 "JavaScript Object Notation\n")
718e3744 8599{
b05a1c8b
DS
8600 u_char use_json = (argv[1] != NULL);
8601 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8602}
8603
8604ALIAS (show_bgp_route,
8605 show_bgp_ipv6_route_cmd,
b05a1c8b 8606 "show bgp ipv6 X:X::X:X {json}",
718e3744 8607 SHOW_STR
8608 BGP_STR
8609 "Address family\n"
b05a1c8b
DS
8610 "Network in the BGP routing table to display\n"
8611 "JavaScript Object Notation\n")
718e3744 8612
95cbbd2a
ML
8613DEFUN (show_bgp_ipv6_safi_route,
8614 show_bgp_ipv6_safi_route_cmd,
b05a1c8b 8615 "show bgp ipv6 (unicast|multicast) X:X::X:X {json}",
95cbbd2a
ML
8616 SHOW_STR
8617 BGP_STR
8618 "Address family\n"
8619 "Address Family modifier\n"
8620 "Address Family modifier\n"
b05a1c8b
DS
8621 "Network in the BGP routing table to display\n"
8622 "JavaScript Object Notation\n")
95cbbd2a 8623{
b05a1c8b 8624 u_char use_json = (argv[2] != NULL);
95cbbd2a 8625 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 8626 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json);
95cbbd2a 8627
b05a1c8b 8628 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
4092b06c
DS
8629}
8630
8631DEFUN (show_bgp_route_pathtype,
8632 show_bgp_route_pathtype_cmd,
b05a1c8b 8633 "show bgp X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8634 SHOW_STR
8635 BGP_STR
8636 "Network in the BGP routing table to display\n"
8637 "Display only the bestpath\n"
b05a1c8b
DS
8638 "Display only multipaths\n"
8639 "JavaScript Object Notation\n")
4092b06c 8640{
b05a1c8b 8641 u_char use_json = (argv[2] != NULL);
4092b06c 8642 if (strncmp (argv[1], "b", 1) == 0)
b05a1c8b 8643 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8644 else
b05a1c8b 8645 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8646}
8647
8648ALIAS (show_bgp_route_pathtype,
8649 show_bgp_ipv6_route_pathtype_cmd,
b05a1c8b 8650 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8651 SHOW_STR
8652 BGP_STR
8653 "Address family\n"
8654 "Network in the BGP routing table to display\n"
8655 "Display only the bestpath\n"
b05a1c8b
DS
8656 "Display only multipaths\n"
8657 "JavaScript Object Notation\n")
4092b06c
DS
8658
8659DEFUN (show_bgp_ipv6_safi_route_pathtype,
8660 show_bgp_ipv6_safi_route_pathtype_cmd,
b05a1c8b 8661 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8662 SHOW_STR
8663 BGP_STR
8664 "Address family\n"
8665 "Address Family modifier\n"
8666 "Address Family modifier\n"
8667 "Network in the BGP routing table to display\n"
8668 "Display only the bestpath\n"
b05a1c8b
DS
8669 "Display only multipaths\n"
8670 "JavaScript Object Notation\n")
4092b06c 8671{
b05a1c8b 8672 u_char use_json = (argv[3] != NULL);
4092b06c
DS
8673 if (strncmp (argv[0], "m", 1) == 0)
8674 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8675 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8676 else
b05a1c8b 8677 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8678 else
8679 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8680 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8681 else
b05a1c8b 8682 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
95cbbd2a
ML
8683}
8684
718e3744 8685/* old command */
8686DEFUN (show_ipv6_bgp_route,
8687 show_ipv6_bgp_route_cmd,
b05a1c8b 8688 "show ipv6 bgp X:X::X:X {json}",
718e3744 8689 SHOW_STR
8690 IP_STR
8691 BGP_STR
b05a1c8b
DS
8692 "Network in the BGP routing table to display\n"
8693 "JavaScript Object Notation\n")
718e3744 8694{
b05a1c8b
DS
8695 u_char use_json = (argv[1] != NULL);
8696 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8697}
8698
8699DEFUN (show_bgp_prefix,
8700 show_bgp_prefix_cmd,
b05a1c8b 8701 "show bgp X:X::X:X/M {json}",
718e3744 8702 SHOW_STR
8703 BGP_STR
b05a1c8b
DS
8704 "IPv6 prefix <network>/<length>\n"
8705 "JavaScript Object Notation\n")
718e3744 8706{
b05a1c8b
DS
8707 u_char use_json = (argv[1] != NULL);
8708 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8709}
8710
8711ALIAS (show_bgp_prefix,
8712 show_bgp_ipv6_prefix_cmd,
b05a1c8b 8713 "show bgp ipv6 X:X::X:X/M {json}",
718e3744 8714 SHOW_STR
8715 BGP_STR
8716 "Address family\n"
b05a1c8b
DS
8717 "IPv6 prefix <network>/<length>\n"
8718 "JavaScript Object Notation\n")
718e3744 8719
95cbbd2a
ML
8720DEFUN (show_bgp_ipv6_safi_prefix,
8721 show_bgp_ipv6_safi_prefix_cmd,
b05a1c8b 8722 "show bgp ipv6 (unicast|multicast) X:X::X:X/M {json}",
95cbbd2a
ML
8723 SHOW_STR
8724 BGP_STR
8725 "Address family\n"
8726 "Address Family modifier\n"
8727 "Address Family modifier\n"
b05a1c8b
DS
8728 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8729 "JavaScript Object Notation\n")
95cbbd2a 8730{
b05a1c8b 8731 u_char use_json = (argv[2] != NULL);
95cbbd2a 8732 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 8733 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json);
95cbbd2a 8734
b05a1c8b 8735 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
4092b06c
DS
8736}
8737
8738DEFUN (show_bgp_prefix_pathtype,
8739 show_bgp_prefix_pathtype_cmd,
b05a1c8b 8740 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8741 SHOW_STR
8742 BGP_STR
8743 "IPv6 prefix <network>/<length>\n"
8744 "Display only the bestpath\n"
b05a1c8b
DS
8745 "Display only multipaths\n"
8746 "JavaScript Object Notation\n")
4092b06c 8747{
b05a1c8b 8748 u_char use_json = (argv[2] != NULL);
4092b06c 8749 if (strncmp (argv[1], "b", 1) == 0)
b05a1c8b 8750 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8751 else
b05a1c8b 8752 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8753}
8754
8755ALIAS (show_bgp_prefix_pathtype,
8756 show_bgp_ipv6_prefix_pathtype_cmd,
b05a1c8b 8757 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8758 SHOW_STR
8759 BGP_STR
8760 "Address family\n"
8761 "IPv6 prefix <network>/<length>\n"
8762 "Display only the bestpath\n"
b05a1c8b
DS
8763 "Display only multipaths\n"
8764 "JavaScript Object Notation\n")
4092b06c
DS
8765
8766DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8767 show_bgp_ipv6_safi_prefix_pathtype_cmd,
b05a1c8b 8768 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8769 SHOW_STR
8770 BGP_STR
8771 "Address family\n"
8772 "Address Family modifier\n"
8773 "Address Family modifier\n"
8774 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8775 "Display only the bestpath\n"
b05a1c8b
DS
8776 "Display only multipaths\n"
8777 "JavaScript Object Notation\n")
4092b06c 8778{
b05a1c8b 8779 u_char use_json = (argv[3] != NULL);
4092b06c
DS
8780 if (strncmp (argv[0], "m", 1) == 0)
8781 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8782 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8783 else
b05a1c8b 8784 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8785 else
8786 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8787 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8788 else
b05a1c8b 8789 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
95cbbd2a
ML
8790}
8791
718e3744 8792/* old command */
8793DEFUN (show_ipv6_bgp_prefix,
8794 show_ipv6_bgp_prefix_cmd,
b05a1c8b 8795 "show ipv6 bgp X:X::X:X/M {json}",
718e3744 8796 SHOW_STR
8797 IP_STR
8798 BGP_STR
b05a1c8b
DS
8799 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8800 "JavaScript Object Notation\n")
718e3744 8801{
b05a1c8b
DS
8802 u_char use_json = (argv[1] != NULL);
8803 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8804}
8805
bb46e94f 8806DEFUN (show_bgp_view,
8807 show_bgp_view_cmd,
b05a1c8b 8808 "show bgp view WORD {json}",
bb46e94f 8809 SHOW_STR
8810 BGP_STR
8811 "BGP view\n"
b05a1c8b
DS
8812 "View name\n"
8813 "JavaScript Object Notation\n")
bb46e94f 8814{
8815 struct bgp *bgp;
b05a1c8b 8816 u_char use_json = (argv[1] != NULL);
bb46e94f 8817
8818 /* BGP structure lookup. */
8819 bgp = bgp_lookup_by_name (argv[0]);
8820 if (bgp == NULL)
8821 {
8822 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8823 return CMD_WARNING;
8824 }
8825
b05a1c8b 8826 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
bb46e94f 8827}
8828
8829ALIAS (show_bgp_view,
8830 show_bgp_view_ipv6_cmd,
b05a1c8b 8831 "show bgp view WORD ipv6 {json}",
bb46e94f 8832 SHOW_STR
8833 BGP_STR
8834 "BGP view\n"
8835 "View name\n"
b05a1c8b
DS
8836 "Address family\n"
8837 "JavaScript Object Notation\n")
bb46e94f 8838
8839DEFUN (show_bgp_view_route,
8840 show_bgp_view_route_cmd,
b05a1c8b 8841 "show bgp view WORD X:X::X:X {json}",
bb46e94f 8842 SHOW_STR
8843 BGP_STR
8844 "BGP view\n"
8845 "View name\n"
b05a1c8b
DS
8846 "Network in the BGP routing table to display\n"
8847 "JavaScript Object Notation\n")
bb46e94f 8848{
b05a1c8b
DS
8849 u_char use_json = (argv[2] != NULL);
8850 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
bb46e94f 8851}
8852
8853ALIAS (show_bgp_view_route,
8854 show_bgp_view_ipv6_route_cmd,
b05a1c8b 8855 "show bgp view WORD ipv6 X:X::X:X {json}",
bb46e94f 8856 SHOW_STR
8857 BGP_STR
8858 "BGP view\n"
8859 "View name\n"
8860 "Address family\n"
b05a1c8b
DS
8861 "Network in the BGP routing table to display\n"
8862 "JavaScript Object Notation\n")
bb46e94f 8863
8864DEFUN (show_bgp_view_prefix,
8865 show_bgp_view_prefix_cmd,
b05a1c8b 8866 "show bgp view WORD X:X::X:X/M {json}",
bb46e94f 8867 SHOW_STR
8868 BGP_STR
8869 "BGP view\n"
8870 "View name\n"
b05a1c8b
DS
8871 "IPv6 prefix <network>/<length>\n"
8872 "JavaScript Object Notation\n")
bb46e94f 8873{
b05a1c8b
DS
8874 u_char use_json = (argv[2] != NULL);
8875 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
bb46e94f 8876}
8877
8878ALIAS (show_bgp_view_prefix,
8879 show_bgp_view_ipv6_prefix_cmd,
b05a1c8b 8880 "show bgp view WORD ipv6 X:X::X:X/M {json}",
bb46e94f 8881 SHOW_STR
8882 BGP_STR
8883 "BGP view\n"
8884 "View name\n"
8885 "Address family\n"
b05a1c8b
DS
8886 "IPv6 prefix <network>/<length>\n"
8887 "JavaScript Object Notation\n")
bb46e94f 8888
718e3744 8889/* old command */
8890DEFUN (show_ipv6_mbgp,
8891 show_ipv6_mbgp_cmd,
b05a1c8b 8892 "show ipv6 mbgp {json}",
718e3744 8893 SHOW_STR
8894 IP_STR
b05a1c8b
DS
8895 MBGP_STR
8896 "JavaScript Object Notation\n")
718e3744 8897{
b05a1c8b 8898 u_char use_json = (argv[0] != NULL);
5a646650 8899 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
b05a1c8b 8900 NULL, use_json);
718e3744 8901}
8902
8903/* old command */
8904DEFUN (show_ipv6_mbgp_route,
8905 show_ipv6_mbgp_route_cmd,
b05a1c8b 8906 "show ipv6 mbgp X:X::X:X {json}",
718e3744 8907 SHOW_STR
8908 IP_STR
8909 MBGP_STR
b05a1c8b
DS
8910 "Network in the MBGP routing table to display\n"
8911 "JavaScript Object Notation\n")
718e3744 8912{
b05a1c8b
DS
8913 u_char use_json = (argv[1] != NULL);
8914 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8915}
8916
8917/* old command */
8918DEFUN (show_ipv6_mbgp_prefix,
8919 show_ipv6_mbgp_prefix_cmd,
b05a1c8b 8920 "show ipv6 mbgp X:X::X:X/M {json}",
718e3744 8921 SHOW_STR
8922 IP_STR
8923 MBGP_STR
b05a1c8b
DS
8924 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8925 "JavaScript Object Notation\n")
718e3744 8926{
b05a1c8b
DS
8927 u_char use_json = (argv[1] != NULL);
8928 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8929}
8930#endif
6b0655a2 8931
718e3744 8932
94f2b392 8933static int
fd79ac91 8934bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
718e3744 8935 safi_t safi, enum bgp_show_type type)
8936{
8937 int i;
8938 struct buffer *b;
8939 char *regstr;
8940 int first;
8941 regex_t *regex;
5a646650 8942 int rc;
718e3744 8943
8944 first = 0;
8945 b = buffer_new (1024);
8946 for (i = 0; i < argc; i++)
8947 {
8948 if (first)
8949 buffer_putc (b, ' ');
8950 else
8951 {
8952 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8953 continue;
8954 first = 1;
8955 }
8956
8957 buffer_putstr (b, argv[i]);
8958 }
8959 buffer_putc (b, '\0');
8960
8961 regstr = buffer_getstr (b);
8962 buffer_free (b);
8963
8964 regex = bgp_regcomp (regstr);
3b8b1855 8965 XFREE(MTYPE_TMP, regstr);
718e3744 8966 if (! regex)
8967 {
8968 vty_out (vty, "Can't compile regexp %s%s", argv[0],
8969 VTY_NEWLINE);
8970 return CMD_WARNING;
8971 }
8972
b05a1c8b 8973 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
5a646650 8974 bgp_regex_free (regex);
8975 return rc;
718e3744 8976}
8977
8978DEFUN (show_ip_bgp_regexp,
8979 show_ip_bgp_regexp_cmd,
8980 "show ip bgp regexp .LINE",
8981 SHOW_STR
8982 IP_STR
8983 BGP_STR
8984 "Display routes matching the AS path regular expression\n"
8985 "A regular-expression to match the BGP AS paths\n")
8986{
8987 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8988 bgp_show_type_regexp);
8989}
8990
8991DEFUN (show_ip_bgp_flap_regexp,
8992 show_ip_bgp_flap_regexp_cmd,
8993 "show ip bgp flap-statistics regexp .LINE",
8994 SHOW_STR
8995 IP_STR
8996 BGP_STR
8997 "Display flap statistics of routes\n"
8998 "Display routes matching the AS path regular expression\n"
8999 "A regular-expression to match the BGP AS paths\n")
9000{
9001 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9002 bgp_show_type_flap_regexp);
9003}
9004
9005DEFUN (show_ip_bgp_ipv4_regexp,
9006 show_ip_bgp_ipv4_regexp_cmd,
9007 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
9008 SHOW_STR
9009 IP_STR
9010 BGP_STR
9011 "Address family\n"
9012 "Address Family modifier\n"
9013 "Address Family modifier\n"
9014 "Display routes matching the AS path regular expression\n"
9015 "A regular-expression to match the BGP AS paths\n")
9016{
9017 if (strncmp (argv[0], "m", 1) == 0)
9018 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
9019 bgp_show_type_regexp);
9020
9021 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9022 bgp_show_type_regexp);
9023}
9024
9025#ifdef HAVE_IPV6
9026DEFUN (show_bgp_regexp,
9027 show_bgp_regexp_cmd,
9028 "show bgp regexp .LINE",
9029 SHOW_STR
9030 BGP_STR
9031 "Display routes matching the AS path regular expression\n"
9032 "A regular-expression to match the BGP AS paths\n")
9033{
9034 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9035 bgp_show_type_regexp);
9036}
9037
9038ALIAS (show_bgp_regexp,
9039 show_bgp_ipv6_regexp_cmd,
9040 "show bgp ipv6 regexp .LINE",
9041 SHOW_STR
9042 BGP_STR
9043 "Address family\n"
9044 "Display routes matching the AS path regular expression\n"
9045 "A regular-expression to match the BGP AS paths\n")
9046
9047/* old command */
9048DEFUN (show_ipv6_bgp_regexp,
9049 show_ipv6_bgp_regexp_cmd,
9050 "show ipv6 bgp regexp .LINE",
9051 SHOW_STR
9052 IP_STR
9053 BGP_STR
9054 "Display routes matching the AS path regular expression\n"
9055 "A regular-expression to match the BGP AS paths\n")
9056{
9057 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9058 bgp_show_type_regexp);
9059}
9060
9061/* old command */
9062DEFUN (show_ipv6_mbgp_regexp,
9063 show_ipv6_mbgp_regexp_cmd,
9064 "show ipv6 mbgp regexp .LINE",
9065 SHOW_STR
9066 IP_STR
9067 BGP_STR
9068 "Display routes matching the AS path regular expression\n"
9069 "A regular-expression to match the MBGP AS paths\n")
9070{
9071 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
9072 bgp_show_type_regexp);
9073}
9074#endif /* HAVE_IPV6 */
6b0655a2 9075
94f2b392 9076static int
fd79ac91 9077bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
718e3744 9078 safi_t safi, enum bgp_show_type type)
9079{
9080 struct prefix_list *plist;
9081
9082 plist = prefix_list_lookup (afi, prefix_list_str);
9083 if (plist == NULL)
9084 {
9085 vty_out (vty, "%% %s is not a valid prefix-list name%s",
9086 prefix_list_str, VTY_NEWLINE);
9087 return CMD_WARNING;
9088 }
9089
b05a1c8b 9090 return bgp_show (vty, NULL, afi, safi, type, plist, 0);
718e3744 9091}
9092
9093DEFUN (show_ip_bgp_prefix_list,
9094 show_ip_bgp_prefix_list_cmd,
9095 "show ip bgp prefix-list WORD",
9096 SHOW_STR
9097 IP_STR
9098 BGP_STR
9099 "Display routes conforming to the prefix-list\n"
9100 "IP prefix-list name\n")
9101{
9102 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
9103 bgp_show_type_prefix_list);
9104}
9105
9106DEFUN (show_ip_bgp_flap_prefix_list,
9107 show_ip_bgp_flap_prefix_list_cmd,
9108 "show ip bgp flap-statistics prefix-list WORD",
9109 SHOW_STR
9110 IP_STR
9111 BGP_STR
9112 "Display flap statistics of routes\n"
9113 "Display routes conforming to the prefix-list\n"
9114 "IP prefix-list name\n")
9115{
9116 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
9117 bgp_show_type_flap_prefix_list);
9118}
9119
9120DEFUN (show_ip_bgp_ipv4_prefix_list,
9121 show_ip_bgp_ipv4_prefix_list_cmd,
9122 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
9123 SHOW_STR
9124 IP_STR
9125 BGP_STR
9126 "Address family\n"
9127 "Address Family modifier\n"
9128 "Address Family modifier\n"
9129 "Display routes conforming to the prefix-list\n"
9130 "IP prefix-list name\n")
9131{
9132 if (strncmp (argv[0], "m", 1) == 0)
9133 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9134 bgp_show_type_prefix_list);
9135
9136 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
9137 bgp_show_type_prefix_list);
9138}
9139
9140#ifdef HAVE_IPV6
9141DEFUN (show_bgp_prefix_list,
9142 show_bgp_prefix_list_cmd,
9143 "show bgp prefix-list WORD",
9144 SHOW_STR
9145 BGP_STR
9146 "Display routes conforming to the prefix-list\n"
9147 "IPv6 prefix-list name\n")
9148{
9149 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9150 bgp_show_type_prefix_list);
9151}
9152
9153ALIAS (show_bgp_prefix_list,
9154 show_bgp_ipv6_prefix_list_cmd,
9155 "show bgp ipv6 prefix-list WORD",
9156 SHOW_STR
9157 BGP_STR
9158 "Address family\n"
9159 "Display routes conforming to the prefix-list\n"
9160 "IPv6 prefix-list name\n")
9161
9162/* old command */
9163DEFUN (show_ipv6_bgp_prefix_list,
9164 show_ipv6_bgp_prefix_list_cmd,
9165 "show ipv6 bgp prefix-list WORD",
9166 SHOW_STR
9167 IPV6_STR
9168 BGP_STR
9169 "Display routes matching the prefix-list\n"
9170 "IPv6 prefix-list name\n")
9171{
9172 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9173 bgp_show_type_prefix_list);
9174}
9175
9176/* old command */
9177DEFUN (show_ipv6_mbgp_prefix_list,
9178 show_ipv6_mbgp_prefix_list_cmd,
9179 "show ipv6 mbgp prefix-list WORD",
9180 SHOW_STR
9181 IPV6_STR
9182 MBGP_STR
9183 "Display routes matching the prefix-list\n"
9184 "IPv6 prefix-list name\n")
9185{
9186 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9187 bgp_show_type_prefix_list);
9188}
9189#endif /* HAVE_IPV6 */
6b0655a2 9190
94f2b392 9191static int
fd79ac91 9192bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
718e3744 9193 safi_t safi, enum bgp_show_type type)
9194{
9195 struct as_list *as_list;
9196
9197 as_list = as_list_lookup (filter);
9198 if (as_list == NULL)
9199 {
9200 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
9201 return CMD_WARNING;
9202 }
9203
b05a1c8b 9204 return bgp_show (vty, NULL, afi, safi, type, as_list, 0);
718e3744 9205}
9206
9207DEFUN (show_ip_bgp_filter_list,
9208 show_ip_bgp_filter_list_cmd,
9209 "show ip bgp filter-list WORD",
9210 SHOW_STR
9211 IP_STR
9212 BGP_STR
9213 "Display routes conforming to the filter-list\n"
9214 "Regular expression access list name\n")
9215{
9216 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
9217 bgp_show_type_filter_list);
9218}
9219
9220DEFUN (show_ip_bgp_flap_filter_list,
9221 show_ip_bgp_flap_filter_list_cmd,
9222 "show ip bgp flap-statistics filter-list WORD",
9223 SHOW_STR
9224 IP_STR
9225 BGP_STR
9226 "Display flap statistics of routes\n"
9227 "Display routes conforming to the filter-list\n"
9228 "Regular expression access list name\n")
9229{
9230 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
9231 bgp_show_type_flap_filter_list);
9232}
9233
9234DEFUN (show_ip_bgp_ipv4_filter_list,
9235 show_ip_bgp_ipv4_filter_list_cmd,
9236 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
9237 SHOW_STR
9238 IP_STR
9239 BGP_STR
9240 "Address family\n"
9241 "Address Family modifier\n"
9242 "Address Family modifier\n"
9243 "Display routes conforming to the filter-list\n"
9244 "Regular expression access list name\n")
9245{
9246 if (strncmp (argv[0], "m", 1) == 0)
9247 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9248 bgp_show_type_filter_list);
9249
9250 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
9251 bgp_show_type_filter_list);
9252}
9253
9254#ifdef HAVE_IPV6
9255DEFUN (show_bgp_filter_list,
9256 show_bgp_filter_list_cmd,
9257 "show bgp filter-list WORD",
9258 SHOW_STR
9259 BGP_STR
9260 "Display routes conforming to the filter-list\n"
9261 "Regular expression access list name\n")
9262{
9263 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9264 bgp_show_type_filter_list);
9265}
9266
9267ALIAS (show_bgp_filter_list,
9268 show_bgp_ipv6_filter_list_cmd,
9269 "show bgp ipv6 filter-list WORD",
9270 SHOW_STR
9271 BGP_STR
9272 "Address family\n"
9273 "Display routes conforming to the filter-list\n"
9274 "Regular expression access list name\n")
9275
9276/* old command */
9277DEFUN (show_ipv6_bgp_filter_list,
9278 show_ipv6_bgp_filter_list_cmd,
9279 "show ipv6 bgp filter-list WORD",
9280 SHOW_STR
9281 IPV6_STR
9282 BGP_STR
9283 "Display routes conforming to the filter-list\n"
9284 "Regular expression access list name\n")
9285{
9286 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9287 bgp_show_type_filter_list);
9288}
9289
9290/* old command */
9291DEFUN (show_ipv6_mbgp_filter_list,
9292 show_ipv6_mbgp_filter_list_cmd,
9293 "show ipv6 mbgp filter-list WORD",
9294 SHOW_STR
9295 IPV6_STR
9296 MBGP_STR
9297 "Display routes conforming to the filter-list\n"
9298 "Regular expression access list name\n")
9299{
9300 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9301 bgp_show_type_filter_list);
9302}
9303#endif /* HAVE_IPV6 */
6b0655a2 9304
94f2b392 9305static int
fd79ac91 9306bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
718e3744 9307 safi_t safi, enum bgp_show_type type)
9308{
9309 struct route_map *rmap;
9310
9311 rmap = route_map_lookup_by_name (rmap_str);
9312 if (! rmap)
9313 {
9314 vty_out (vty, "%% %s is not a valid route-map name%s",
9315 rmap_str, VTY_NEWLINE);
9316 return CMD_WARNING;
9317 }
9318
b05a1c8b 9319 return bgp_show (vty, NULL, afi, safi, type, rmap, 0);
718e3744 9320}
9321
9322DEFUN (show_ip_bgp_route_map,
9323 show_ip_bgp_route_map_cmd,
9324 "show ip bgp route-map WORD",
9325 SHOW_STR
9326 IP_STR
9327 BGP_STR
9328 "Display routes matching the route-map\n"
9329 "A route-map to match on\n")
9330{
9331 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
9332 bgp_show_type_route_map);
9333}
9334
9335DEFUN (show_ip_bgp_flap_route_map,
9336 show_ip_bgp_flap_route_map_cmd,
9337 "show ip bgp flap-statistics route-map WORD",
9338 SHOW_STR
9339 IP_STR
9340 BGP_STR
9341 "Display flap statistics of routes\n"
9342 "Display routes matching the route-map\n"
9343 "A route-map to match on\n")
9344{
9345 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
9346 bgp_show_type_flap_route_map);
9347}
9348
9349DEFUN (show_ip_bgp_ipv4_route_map,
9350 show_ip_bgp_ipv4_route_map_cmd,
9351 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
9352 SHOW_STR
9353 IP_STR
9354 BGP_STR
9355 "Address family\n"
9356 "Address Family modifier\n"
9357 "Address Family modifier\n"
9358 "Display routes matching the route-map\n"
9359 "A route-map to match on\n")
9360{
9361 if (strncmp (argv[0], "m", 1) == 0)
9362 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9363 bgp_show_type_route_map);
9364
9365 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
9366 bgp_show_type_route_map);
9367}
9368
9369DEFUN (show_bgp_route_map,
9370 show_bgp_route_map_cmd,
9371 "show bgp route-map WORD",
9372 SHOW_STR
9373 BGP_STR
9374 "Display routes matching the route-map\n"
9375 "A route-map to match on\n")
9376{
9377 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9378 bgp_show_type_route_map);
9379}
9380
9381ALIAS (show_bgp_route_map,
9382 show_bgp_ipv6_route_map_cmd,
9383 "show bgp ipv6 route-map WORD",
9384 SHOW_STR
9385 BGP_STR
9386 "Address family\n"
9387 "Display routes matching the route-map\n"
9388 "A route-map to match on\n")
6b0655a2 9389
718e3744 9390DEFUN (show_ip_bgp_cidr_only,
9391 show_ip_bgp_cidr_only_cmd,
9392 "show ip bgp cidr-only",
9393 SHOW_STR
9394 IP_STR
9395 BGP_STR
9396 "Display only routes with non-natural netmasks\n")
9397{
9398 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9399 bgp_show_type_cidr_only, NULL, 0);
718e3744 9400}
9401
9402DEFUN (show_ip_bgp_flap_cidr_only,
9403 show_ip_bgp_flap_cidr_only_cmd,
9404 "show ip bgp flap-statistics cidr-only",
9405 SHOW_STR
9406 IP_STR
9407 BGP_STR
9408 "Display flap statistics of routes\n"
9409 "Display only routes with non-natural netmasks\n")
9410{
9411 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9412 bgp_show_type_flap_cidr_only, NULL, 0);
718e3744 9413}
9414
9415DEFUN (show_ip_bgp_ipv4_cidr_only,
9416 show_ip_bgp_ipv4_cidr_only_cmd,
9417 "show ip bgp ipv4 (unicast|multicast) cidr-only",
9418 SHOW_STR
9419 IP_STR
9420 BGP_STR
9421 "Address family\n"
9422 "Address Family modifier\n"
9423 "Address Family modifier\n"
9424 "Display only routes with non-natural netmasks\n")
9425{
9426 if (strncmp (argv[0], "m", 1) == 0)
9427 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
b05a1c8b 9428 bgp_show_type_cidr_only, NULL, 0);
718e3744 9429
9430 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9431 bgp_show_type_cidr_only, NULL, 0);
718e3744 9432}
6b0655a2 9433
718e3744 9434DEFUN (show_ip_bgp_community_all,
9435 show_ip_bgp_community_all_cmd,
9436 "show ip bgp community",
9437 SHOW_STR
9438 IP_STR
9439 BGP_STR
9440 "Display routes matching the communities\n")
9441{
9442 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9443 bgp_show_type_community_all, NULL, 0);
718e3744 9444}
9445
9446DEFUN (show_ip_bgp_ipv4_community_all,
9447 show_ip_bgp_ipv4_community_all_cmd,
9448 "show ip bgp ipv4 (unicast|multicast) community",
9449 SHOW_STR
9450 IP_STR
9451 BGP_STR
9452 "Address family\n"
9453 "Address Family modifier\n"
9454 "Address Family modifier\n"
9455 "Display routes matching the communities\n")
9456{
9457 if (strncmp (argv[0], "m", 1) == 0)
9458 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
b05a1c8b 9459 bgp_show_type_community_all, NULL, 0);
718e3744 9460
9461 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9462 bgp_show_type_community_all, NULL, 0);
718e3744 9463}
9464
9465#ifdef HAVE_IPV6
9466DEFUN (show_bgp_community_all,
9467 show_bgp_community_all_cmd,
9468 "show bgp community",
9469 SHOW_STR
9470 BGP_STR
9471 "Display routes matching the communities\n")
9472{
9473 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 9474 bgp_show_type_community_all, NULL, 0);
718e3744 9475}
9476
9477ALIAS (show_bgp_community_all,
9478 show_bgp_ipv6_community_all_cmd,
9479 "show bgp ipv6 community",
9480 SHOW_STR
9481 BGP_STR
9482 "Address family\n"
9483 "Display routes matching the communities\n")
9484
9485/* old command */
9486DEFUN (show_ipv6_bgp_community_all,
9487 show_ipv6_bgp_community_all_cmd,
9488 "show ipv6 bgp community",
9489 SHOW_STR
9490 IPV6_STR
9491 BGP_STR
9492 "Display routes matching the communities\n")
9493{
9494 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 9495 bgp_show_type_community_all, NULL, 0);
718e3744 9496}
9497
9498/* old command */
9499DEFUN (show_ipv6_mbgp_community_all,
9500 show_ipv6_mbgp_community_all_cmd,
9501 "show ipv6 mbgp community",
9502 SHOW_STR
9503 IPV6_STR
9504 MBGP_STR
9505 "Display routes matching the communities\n")
9506{
9507 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
b05a1c8b 9508 bgp_show_type_community_all, NULL, 0);
718e3744 9509}
9510#endif /* HAVE_IPV6 */
6b0655a2 9511
94f2b392 9512static int
95cbbd2a
ML
9513bgp_show_community (struct vty *vty, const char *view_name, int argc,
9514 const char **argv, int exact, afi_t afi, safi_t safi)
718e3744 9515{
9516 struct community *com;
9517 struct buffer *b;
95cbbd2a 9518 struct bgp *bgp;
718e3744 9519 int i;
9520 char *str;
9521 int first = 0;
9522
95cbbd2a
ML
9523 /* BGP structure lookup */
9524 if (view_name)
9525 {
9526 bgp = bgp_lookup_by_name (view_name);
9527 if (bgp == NULL)
9528 {
9529 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9530 return CMD_WARNING;
9531 }
9532 }
9533 else
9534 {
9535 bgp = bgp_get_default ();
9536 if (bgp == NULL)
9537 {
9538 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9539 return CMD_WARNING;
9540 }
9541 }
9542
718e3744 9543 b = buffer_new (1024);
9544 for (i = 0; i < argc; i++)
9545 {
9546 if (first)
9547 buffer_putc (b, ' ');
9548 else
9549 {
9550 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9551 continue;
9552 first = 1;
9553 }
9554
9555 buffer_putstr (b, argv[i]);
9556 }
9557 buffer_putc (b, '\0');
9558
9559 str = buffer_getstr (b);
9560 buffer_free (b);
9561
9562 com = community_str2com (str);
3b8b1855 9563 XFREE (MTYPE_TMP, str);
718e3744 9564 if (! com)
9565 {
9566 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9567 return CMD_WARNING;
9568 }
9569
95cbbd2a 9570 return bgp_show (vty, bgp, afi, safi,
5a646650 9571 (exact ? bgp_show_type_community_exact :
b05a1c8b 9572 bgp_show_type_community), com, 0);
718e3744 9573}
9574
9575DEFUN (show_ip_bgp_community,
9576 show_ip_bgp_community_cmd,
9577 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9578 SHOW_STR
9579 IP_STR
9580 BGP_STR
9581 "Display routes matching the communities\n"
9582 "community number\n"
9583 "Do not send outside local AS (well-known community)\n"
9584 "Do not advertise to any peer (well-known community)\n"
9585 "Do not export to next AS (well-known community)\n")
9586{
95cbbd2a 9587 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 9588}
9589
9590ALIAS (show_ip_bgp_community,
9591 show_ip_bgp_community2_cmd,
9592 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9593 SHOW_STR
9594 IP_STR
9595 BGP_STR
9596 "Display routes matching the communities\n"
9597 "community number\n"
9598 "Do not send outside local AS (well-known community)\n"
9599 "Do not advertise to any peer (well-known community)\n"
9600 "Do not export to next AS (well-known community)\n"
9601 "community number\n"
9602 "Do not send outside local AS (well-known community)\n"
9603 "Do not advertise to any peer (well-known community)\n"
9604 "Do not export to next AS (well-known community)\n")
9605
9606ALIAS (show_ip_bgp_community,
9607 show_ip_bgp_community3_cmd,
9608 "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)",
9609 SHOW_STR
9610 IP_STR
9611 BGP_STR
9612 "Display routes matching the communities\n"
9613 "community number\n"
9614 "Do not send outside local AS (well-known community)\n"
9615 "Do not advertise to any peer (well-known community)\n"
9616 "Do not export to next AS (well-known community)\n"
9617 "community number\n"
9618 "Do not send outside local AS (well-known community)\n"
9619 "Do not advertise to any peer (well-known community)\n"
9620 "Do not export to next AS (well-known community)\n"
9621 "community number\n"
9622 "Do not send outside local AS (well-known community)\n"
9623 "Do not advertise to any peer (well-known community)\n"
9624 "Do not export to next AS (well-known community)\n")
9625
9626ALIAS (show_ip_bgp_community,
9627 show_ip_bgp_community4_cmd,
9628 "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)",
9629 SHOW_STR
9630 IP_STR
9631 BGP_STR
9632 "Display routes matching the communities\n"
9633 "community number\n"
9634 "Do not send outside local AS (well-known community)\n"
9635 "Do not advertise to any peer (well-known community)\n"
9636 "Do not export to next AS (well-known community)\n"
9637 "community number\n"
9638 "Do not send outside local AS (well-known community)\n"
9639 "Do not advertise to any peer (well-known community)\n"
9640 "Do not export to next AS (well-known community)\n"
9641 "community number\n"
9642 "Do not send outside local AS (well-known community)\n"
9643 "Do not advertise to any peer (well-known community)\n"
9644 "Do not export to next AS (well-known community)\n"
9645 "community number\n"
9646 "Do not send outside local AS (well-known community)\n"
9647 "Do not advertise to any peer (well-known community)\n"
9648 "Do not export to next AS (well-known community)\n")
9649
9650DEFUN (show_ip_bgp_ipv4_community,
9651 show_ip_bgp_ipv4_community_cmd,
9652 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9653 SHOW_STR
9654 IP_STR
9655 BGP_STR
9656 "Address family\n"
9657 "Address Family modifier\n"
9658 "Address Family modifier\n"
9659 "Display routes matching the communities\n"
9660 "community number\n"
9661 "Do not send outside local AS (well-known community)\n"
9662 "Do not advertise to any peer (well-known community)\n"
9663 "Do not export to next AS (well-known community)\n")
9664{
9665 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 9666 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
718e3744 9667
95cbbd2a 9668 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 9669}
9670
9671ALIAS (show_ip_bgp_ipv4_community,
9672 show_ip_bgp_ipv4_community2_cmd,
9673 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9674 SHOW_STR
9675 IP_STR
9676 BGP_STR
9677 "Address family\n"
9678 "Address Family modifier\n"
9679 "Address Family modifier\n"
9680 "Display routes matching the communities\n"
9681 "community number\n"
9682 "Do not send outside local AS (well-known community)\n"
9683 "Do not advertise to any peer (well-known community)\n"
9684 "Do not export to next AS (well-known community)\n"
9685 "community number\n"
9686 "Do not send outside local AS (well-known community)\n"
9687 "Do not advertise to any peer (well-known community)\n"
9688 "Do not export to next AS (well-known community)\n")
9689
9690ALIAS (show_ip_bgp_ipv4_community,
9691 show_ip_bgp_ipv4_community3_cmd,
9692 "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)",
9693 SHOW_STR
9694 IP_STR
9695 BGP_STR
9696 "Address family\n"
9697 "Address Family modifier\n"
9698 "Address Family modifier\n"
9699 "Display routes matching the communities\n"
9700 "community number\n"
9701 "Do not send outside local AS (well-known community)\n"
9702 "Do not advertise to any peer (well-known community)\n"
9703 "Do not export to next AS (well-known community)\n"
9704 "community number\n"
9705 "Do not send outside local AS (well-known community)\n"
9706 "Do not advertise to any peer (well-known community)\n"
9707 "Do not export to next AS (well-known community)\n"
9708 "community number\n"
9709 "Do not send outside local AS (well-known community)\n"
9710 "Do not advertise to any peer (well-known community)\n"
9711 "Do not export to next AS (well-known community)\n")
9712
9713ALIAS (show_ip_bgp_ipv4_community,
9714 show_ip_bgp_ipv4_community4_cmd,
9715 "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)",
9716 SHOW_STR
9717 IP_STR
9718 BGP_STR
9719 "Address family\n"
9720 "Address Family modifier\n"
9721 "Address Family modifier\n"
9722 "Display routes matching the communities\n"
9723 "community number\n"
9724 "Do not send outside local AS (well-known community)\n"
9725 "Do not advertise to any peer (well-known community)\n"
9726 "Do not export to next AS (well-known community)\n"
9727 "community number\n"
9728 "Do not send outside local AS (well-known community)\n"
9729 "Do not advertise to any peer (well-known community)\n"
9730 "Do not export to next AS (well-known community)\n"
9731 "community number\n"
9732 "Do not send outside local AS (well-known community)\n"
9733 "Do not advertise to any peer (well-known community)\n"
9734 "Do not export to next AS (well-known community)\n"
9735 "community number\n"
9736 "Do not send outside local AS (well-known community)\n"
9737 "Do not advertise to any peer (well-known community)\n"
9738 "Do not export to next AS (well-known community)\n")
9739
95cbbd2a
ML
9740DEFUN (show_bgp_view_afi_safi_community_all,
9741 show_bgp_view_afi_safi_community_all_cmd,
9742#ifdef HAVE_IPV6
9743 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
9744#else
9745 "show bgp view WORD ipv4 (unicast|multicast) community",
9746#endif
9747 SHOW_STR
9748 BGP_STR
9749 "BGP view\n"
2b00515a 9750 "View name\n"
95cbbd2a
ML
9751 "Address family\n"
9752#ifdef HAVE_IPV6
9753 "Address family\n"
9754#endif
9755 "Address Family modifier\n"
9756 "Address Family modifier\n"
2b00515a 9757 "Display routes matching the communities\n")
95cbbd2a
ML
9758{
9759 int afi;
9760 int safi;
9761 struct bgp *bgp;
9762
9763 /* BGP structure lookup. */
9764 bgp = bgp_lookup_by_name (argv[0]);
9765 if (bgp == NULL)
9766 {
9767 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9768 return CMD_WARNING;
9769 }
9770
9771#ifdef HAVE_IPV6
9772 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9773 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9774#else
9775 afi = AFI_IP;
9776 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9777#endif
b05a1c8b 9778 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
95cbbd2a
ML
9779}
9780
9781DEFUN (show_bgp_view_afi_safi_community,
9782 show_bgp_view_afi_safi_community_cmd,
9783#ifdef HAVE_IPV6
9784 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9785#else
9786 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9787#endif
9788 SHOW_STR
9789 BGP_STR
9790 "BGP view\n"
2b00515a 9791 "View name\n"
95cbbd2a
ML
9792 "Address family\n"
9793#ifdef HAVE_IPV6
9794 "Address family\n"
9795#endif
9796 "Address family modifier\n"
9797 "Address family modifier\n"
9798 "Display routes matching the communities\n"
9799 "community number\n"
9800 "Do not send outside local AS (well-known community)\n"
9801 "Do not advertise to any peer (well-known community)\n"
9802 "Do not export to next AS (well-known community)\n")
9803{
9804 int afi;
9805 int safi;
9806
9807#ifdef HAVE_IPV6
9808 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9809 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9810 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
9811#else
9812 afi = AFI_IP;
9813 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9814 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
9815#endif
9816}
9817
9818ALIAS (show_bgp_view_afi_safi_community,
9819 show_bgp_view_afi_safi_community2_cmd,
9820#ifdef HAVE_IPV6
9821 "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)",
9822#else
9823 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9824#endif
9825 SHOW_STR
9826 BGP_STR
9827 "BGP view\n"
2b00515a 9828 "View name\n"
95cbbd2a
ML
9829 "Address family\n"
9830#ifdef HAVE_IPV6
9831 "Address family\n"
9832#endif
9833 "Address family modifier\n"
9834 "Address family modifier\n"
9835 "Display routes matching the communities\n"
9836 "community number\n"
9837 "Do not send outside local AS (well-known community)\n"
9838 "Do not advertise to any peer (well-known community)\n"
9839 "Do not export to next AS (well-known community)\n"
9840 "community number\n"
9841 "Do not send outside local AS (well-known community)\n"
9842 "Do not advertise to any peer (well-known community)\n"
9843 "Do not export to next AS (well-known community)\n")
9844
9845ALIAS (show_bgp_view_afi_safi_community,
9846 show_bgp_view_afi_safi_community3_cmd,
9847#ifdef HAVE_IPV6
9848 "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)",
9849#else
9850 "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)",
9851#endif
9852 SHOW_STR
9853 BGP_STR
9854 "BGP view\n"
2b00515a 9855 "View name\n"
95cbbd2a
ML
9856 "Address family\n"
9857#ifdef HAVE_IPV6
9858 "Address family\n"
9859#endif
9860 "Address family modifier\n"
9861 "Address family modifier\n"
9862 "Display routes matching the communities\n"
9863 "community number\n"
9864 "Do not send outside local AS (well-known community)\n"
9865 "Do not advertise to any peer (well-known community)\n"
9866 "Do not export to next AS (well-known community)\n"
9867 "community number\n"
9868 "Do not send outside local AS (well-known community)\n"
9869 "Do not advertise to any peer (well-known community)\n"
9870 "Do not export to next AS (well-known community)\n"
9871 "community number\n"
9872 "Do not send outside local AS (well-known community)\n"
9873 "Do not advertise to any peer (well-known community)\n"
9874 "Do not export to next AS (well-known community)\n")
9875
9876ALIAS (show_bgp_view_afi_safi_community,
9877 show_bgp_view_afi_safi_community4_cmd,
9878#ifdef HAVE_IPV6
9879 "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)",
9880#else
9881 "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)",
9882#endif
9883 SHOW_STR
9884 BGP_STR
9885 "BGP view\n"
2b00515a 9886 "View name\n"
95cbbd2a
ML
9887 "Address family\n"
9888#ifdef HAVE_IPV6
9889 "Address family\n"
9890#endif
9891 "Address family modifier\n"
9892 "Address family modifier\n"
9893 "Display routes matching the communities\n"
9894 "community number\n"
9895 "Do not send outside local AS (well-known community)\n"
9896 "Do not advertise to any peer (well-known community)\n"
9897 "Do not export to next AS (well-known community)\n"
9898 "community number\n"
9899 "Do not send outside local AS (well-known community)\n"
9900 "Do not advertise to any peer (well-known community)\n"
9901 "Do not export to next AS (well-known community)\n"
9902 "community number\n"
9903 "Do not send outside local AS (well-known community)\n"
9904 "Do not advertise to any peer (well-known community)\n"
9905 "Do not export to next AS (well-known community)\n"
9906 "community number\n"
9907 "Do not send outside local AS (well-known community)\n"
9908 "Do not advertise to any peer (well-known community)\n"
9909 "Do not export to next AS (well-known community)\n")
9910
718e3744 9911DEFUN (show_ip_bgp_community_exact,
9912 show_ip_bgp_community_exact_cmd,
9913 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9914 SHOW_STR
9915 IP_STR
9916 BGP_STR
9917 "Display routes matching the communities\n"
9918 "community number\n"
9919 "Do not send outside local AS (well-known community)\n"
9920 "Do not advertise to any peer (well-known community)\n"
9921 "Do not export to next AS (well-known community)\n"
9922 "Exact match of the communities")
9923{
95cbbd2a 9924 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 9925}
9926
9927ALIAS (show_ip_bgp_community_exact,
9928 show_ip_bgp_community2_exact_cmd,
9929 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9930 SHOW_STR
9931 IP_STR
9932 BGP_STR
9933 "Display routes matching the communities\n"
9934 "community number\n"
9935 "Do not send outside local AS (well-known community)\n"
9936 "Do not advertise to any peer (well-known community)\n"
9937 "Do not export to next AS (well-known community)\n"
9938 "community number\n"
9939 "Do not send outside local AS (well-known community)\n"
9940 "Do not advertise to any peer (well-known community)\n"
9941 "Do not export to next AS (well-known community)\n"
9942 "Exact match of the communities")
9943
9944ALIAS (show_ip_bgp_community_exact,
9945 show_ip_bgp_community3_exact_cmd,
9946 "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",
9947 SHOW_STR
9948 IP_STR
9949 BGP_STR
9950 "Display routes matching the communities\n"
9951 "community number\n"
9952 "Do not send outside local AS (well-known community)\n"
9953 "Do not advertise to any peer (well-known community)\n"
9954 "Do not export to next AS (well-known community)\n"
9955 "community number\n"
9956 "Do not send outside local AS (well-known community)\n"
9957 "Do not advertise to any peer (well-known community)\n"
9958 "Do not export to next AS (well-known community)\n"
9959 "community number\n"
9960 "Do not send outside local AS (well-known community)\n"
9961 "Do not advertise to any peer (well-known community)\n"
9962 "Do not export to next AS (well-known community)\n"
9963 "Exact match of the communities")
9964
9965ALIAS (show_ip_bgp_community_exact,
9966 show_ip_bgp_community4_exact_cmd,
9967 "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",
9968 SHOW_STR
9969 IP_STR
9970 BGP_STR
9971 "Display routes matching the communities\n"
9972 "community number\n"
9973 "Do not send outside local AS (well-known community)\n"
9974 "Do not advertise to any peer (well-known community)\n"
9975 "Do not export to next AS (well-known community)\n"
9976 "community number\n"
9977 "Do not send outside local AS (well-known community)\n"
9978 "Do not advertise to any peer (well-known community)\n"
9979 "Do not export to next AS (well-known community)\n"
9980 "community number\n"
9981 "Do not send outside local AS (well-known community)\n"
9982 "Do not advertise to any peer (well-known community)\n"
9983 "Do not export to next AS (well-known community)\n"
9984 "community number\n"
9985 "Do not send outside local AS (well-known community)\n"
9986 "Do not advertise to any peer (well-known community)\n"
9987 "Do not export to next AS (well-known community)\n"
9988 "Exact match of the communities")
9989
9990DEFUN (show_ip_bgp_ipv4_community_exact,
9991 show_ip_bgp_ipv4_community_exact_cmd,
9992 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9993 SHOW_STR
9994 IP_STR
9995 BGP_STR
9996 "Address family\n"
9997 "Address Family modifier\n"
9998 "Address Family modifier\n"
9999 "Display routes matching the communities\n"
10000 "community number\n"
10001 "Do not send outside local AS (well-known community)\n"
10002 "Do not advertise to any peer (well-known community)\n"
10003 "Do not export to next AS (well-known community)\n"
10004 "Exact match of the communities")
10005{
10006 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 10007 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
718e3744 10008
95cbbd2a 10009 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 10010}
10011
10012ALIAS (show_ip_bgp_ipv4_community_exact,
10013 show_ip_bgp_ipv4_community2_exact_cmd,
10014 "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",
10015 SHOW_STR
10016 IP_STR
10017 BGP_STR
10018 "Address family\n"
10019 "Address Family modifier\n"
10020 "Address Family modifier\n"
10021 "Display routes matching the communities\n"
10022 "community number\n"
10023 "Do not send outside local AS (well-known community)\n"
10024 "Do not advertise to any peer (well-known community)\n"
10025 "Do not export to next AS (well-known community)\n"
10026 "community number\n"
10027 "Do not send outside local AS (well-known community)\n"
10028 "Do not advertise to any peer (well-known community)\n"
10029 "Do not export to next AS (well-known community)\n"
10030 "Exact match of the communities")
10031
10032ALIAS (show_ip_bgp_ipv4_community_exact,
10033 show_ip_bgp_ipv4_community3_exact_cmd,
10034 "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",
10035 SHOW_STR
10036 IP_STR
10037 BGP_STR
10038 "Address family\n"
10039 "Address Family modifier\n"
10040 "Address Family modifier\n"
10041 "Display routes matching the communities\n"
10042 "community number\n"
10043 "Do not send outside local AS (well-known community)\n"
10044 "Do not advertise to any peer (well-known community)\n"
10045 "Do not export to next AS (well-known community)\n"
10046 "community number\n"
10047 "Do not send outside local AS (well-known community)\n"
10048 "Do not advertise to any peer (well-known community)\n"
10049 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10055
10056ALIAS (show_ip_bgp_ipv4_community_exact,
10057 show_ip_bgp_ipv4_community4_exact_cmd,
10058 "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",
10059 SHOW_STR
10060 IP_STR
10061 BGP_STR
10062 "Address family\n"
10063 "Address Family modifier\n"
10064 "Address Family modifier\n"
10065 "Display routes matching the communities\n"
10066 "community number\n"
10067 "Do not send outside local AS (well-known community)\n"
10068 "Do not advertise to any peer (well-known community)\n"
10069 "Do not export to next AS (well-known community)\n"
10070 "community number\n"
10071 "Do not send outside local AS (well-known community)\n"
10072 "Do not advertise to any peer (well-known community)\n"
10073 "Do not export to next AS (well-known community)\n"
10074 "community number\n"
10075 "Do not send outside local AS (well-known community)\n"
10076 "Do not advertise to any peer (well-known community)\n"
10077 "Do not export to next AS (well-known community)\n"
10078 "community number\n"
10079 "Do not send outside local AS (well-known community)\n"
10080 "Do not advertise to any peer (well-known community)\n"
10081 "Do not export to next AS (well-known community)\n"
10082 "Exact match of the communities")
10083
10084#ifdef HAVE_IPV6
10085DEFUN (show_bgp_community,
10086 show_bgp_community_cmd,
10087 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
10088 SHOW_STR
10089 BGP_STR
10090 "Display routes matching the communities\n"
10091 "community number\n"
10092 "Do not send outside local AS (well-known community)\n"
10093 "Do not advertise to any peer (well-known community)\n"
10094 "Do not export to next AS (well-known community)\n")
10095{
95cbbd2a 10096 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 10097}
10098
10099ALIAS (show_bgp_community,
10100 show_bgp_ipv6_community_cmd,
10101 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
10102 SHOW_STR
10103 BGP_STR
10104 "Address family\n"
10105 "Display routes matching the communities\n"
10106 "community number\n"
10107 "Do not send outside local AS (well-known community)\n"
10108 "Do not advertise to any peer (well-known community)\n"
10109 "Do not export to next AS (well-known community)\n")
10110
10111ALIAS (show_bgp_community,
10112 show_bgp_community2_cmd,
10113 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10114 SHOW_STR
10115 BGP_STR
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
10126ALIAS (show_bgp_community,
10127 show_bgp_ipv6_community2_cmd,
10128 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10129 SHOW_STR
10130 BGP_STR
10131 "Address family\n"
10132 "Display routes matching the communities\n"
10133 "community number\n"
10134 "Do not send outside local AS (well-known community)\n"
10135 "Do not advertise to any peer (well-known community)\n"
10136 "Do not export to next AS (well-known community)\n"
10137 "community number\n"
10138 "Do not send outside local AS (well-known community)\n"
10139 "Do not advertise to any peer (well-known community)\n"
10140 "Do not export to next AS (well-known community)\n")
10141
10142ALIAS (show_bgp_community,
10143 show_bgp_community3_cmd,
10144 "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)",
10145 SHOW_STR
10146 BGP_STR
10147 "Display routes matching the communities\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 "community number\n"
10157 "Do not send outside local AS (well-known community)\n"
10158 "Do not advertise to any peer (well-known community)\n"
10159 "Do not export to next AS (well-known community)\n")
10160
10161ALIAS (show_bgp_community,
10162 show_bgp_ipv6_community3_cmd,
10163 "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)",
10164 SHOW_STR
10165 BGP_STR
10166 "Address family\n"
10167 "Display routes matching the communities\n"
10168 "community number\n"
10169 "Do not send outside local AS (well-known community)\n"
10170 "Do not advertise to any peer (well-known community)\n"
10171 "Do not export to next AS (well-known community)\n"
10172 "community number\n"
10173 "Do not send outside local AS (well-known community)\n"
10174 "Do not advertise to any peer (well-known community)\n"
10175 "Do not export to next AS (well-known community)\n"
10176 "community number\n"
10177 "Do not send outside local AS (well-known community)\n"
10178 "Do not advertise to any peer (well-known community)\n"
10179 "Do not export to next AS (well-known community)\n")
10180
10181ALIAS (show_bgp_community,
10182 show_bgp_community4_cmd,
10183 "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)",
10184 SHOW_STR
10185 BGP_STR
10186 "Display routes matching the communities\n"
10187 "community number\n"
10188 "Do not send outside local AS (well-known community)\n"
10189 "Do not advertise to any peer (well-known community)\n"
10190 "Do not export to next AS (well-known community)\n"
10191 "community number\n"
10192 "Do not send outside local AS (well-known community)\n"
10193 "Do not advertise to any peer (well-known community)\n"
10194 "Do not export to next AS (well-known community)\n"
10195 "community number\n"
10196 "Do not send outside local AS (well-known community)\n"
10197 "Do not advertise to any peer (well-known community)\n"
10198 "Do not export to next AS (well-known community)\n"
10199 "community number\n"
10200 "Do not send outside local AS (well-known community)\n"
10201 "Do not advertise to any peer (well-known community)\n"
10202 "Do not export to next AS (well-known community)\n")
10203
10204ALIAS (show_bgp_community,
10205 show_bgp_ipv6_community4_cmd,
10206 "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)",
10207 SHOW_STR
10208 BGP_STR
10209 "Address family\n"
10210 "Display routes matching the communities\n"
10211 "community number\n"
10212 "Do not send outside local AS (well-known community)\n"
10213 "Do not advertise to any peer (well-known community)\n"
10214 "Do not export to next AS (well-known community)\n"
10215 "community number\n"
10216 "Do not send outside local AS (well-known community)\n"
10217 "Do not advertise to any peer (well-known community)\n"
10218 "Do not export to next AS (well-known community)\n"
10219 "community number\n"
10220 "Do not send outside local AS (well-known community)\n"
10221 "Do not advertise to any peer (well-known community)\n"
10222 "Do not export to next AS (well-known community)\n"
10223 "community number\n"
10224 "Do not send outside local AS (well-known community)\n"
10225 "Do not advertise to any peer (well-known community)\n"
10226 "Do not export to next AS (well-known community)\n")
10227
10228/* old command */
10229DEFUN (show_ipv6_bgp_community,
10230 show_ipv6_bgp_community_cmd,
10231 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
10232 SHOW_STR
10233 IPV6_STR
10234 BGP_STR
10235 "Display routes matching the communities\n"
10236 "community number\n"
10237 "Do not send outside local AS (well-known community)\n"
10238 "Do not advertise to any peer (well-known community)\n"
10239 "Do not export to next AS (well-known community)\n")
10240{
95cbbd2a 10241 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 10242}
10243
10244/* old command */
10245ALIAS (show_ipv6_bgp_community,
10246 show_ipv6_bgp_community2_cmd,
10247 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10248 SHOW_STR
10249 IPV6_STR
10250 BGP_STR
10251 "Display routes matching the communities\n"
10252 "community number\n"
10253 "Do not send outside local AS (well-known community)\n"
10254 "Do not advertise to any peer (well-known community)\n"
10255 "Do not export to next AS (well-known community)\n"
10256 "community number\n"
10257 "Do not send outside local AS (well-known community)\n"
10258 "Do not advertise to any peer (well-known community)\n"
10259 "Do not export to next AS (well-known community)\n")
10260
10261/* old command */
10262ALIAS (show_ipv6_bgp_community,
10263 show_ipv6_bgp_community3_cmd,
10264 "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)",
10265 SHOW_STR
10266 IPV6_STR
10267 BGP_STR
10268 "Display routes matching the communities\n"
10269 "community number\n"
10270 "Do not send outside local AS (well-known community)\n"
10271 "Do not advertise to any peer (well-known community)\n"
10272 "Do not export to next AS (well-known community)\n"
10273 "community number\n"
10274 "Do not send outside local AS (well-known community)\n"
10275 "Do not advertise to any peer (well-known community)\n"
10276 "Do not export to next AS (well-known community)\n"
10277 "community number\n"
10278 "Do not send outside local AS (well-known community)\n"
10279 "Do not advertise to any peer (well-known community)\n"
10280 "Do not export to next AS (well-known community)\n")
10281
10282/* old command */
10283ALIAS (show_ipv6_bgp_community,
10284 show_ipv6_bgp_community4_cmd,
10285 "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)",
10286 SHOW_STR
10287 IPV6_STR
10288 BGP_STR
10289 "Display routes matching the communities\n"
10290 "community number\n"
10291 "Do not send outside local AS (well-known community)\n"
10292 "Do not advertise to any peer (well-known community)\n"
10293 "Do not export to next AS (well-known community)\n"
10294 "community number\n"
10295 "Do not send outside local AS (well-known community)\n"
10296 "Do not advertise to any peer (well-known community)\n"
10297 "Do not export to next AS (well-known community)\n"
10298 "community number\n"
10299 "Do not send outside local AS (well-known community)\n"
10300 "Do not advertise to any peer (well-known community)\n"
10301 "Do not export to next AS (well-known community)\n"
10302 "community number\n"
10303 "Do not send outside local AS (well-known community)\n"
10304 "Do not advertise to any peer (well-known community)\n"
10305 "Do not export to next AS (well-known community)\n")
10306
10307DEFUN (show_bgp_community_exact,
10308 show_bgp_community_exact_cmd,
10309 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10310 SHOW_STR
10311 BGP_STR
10312 "Display routes matching the communities\n"
10313 "community number\n"
10314 "Do not send outside local AS (well-known community)\n"
10315 "Do not advertise to any peer (well-known community)\n"
10316 "Do not export to next AS (well-known community)\n"
10317 "Exact match of the communities")
10318{
95cbbd2a 10319 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 10320}
10321
10322ALIAS (show_bgp_community_exact,
10323 show_bgp_ipv6_community_exact_cmd,
10324 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10325 SHOW_STR
10326 BGP_STR
10327 "Address family\n"
10328 "Display routes matching the communities\n"
10329 "community number\n"
10330 "Do not send outside local AS (well-known community)\n"
10331 "Do not advertise to any peer (well-known community)\n"
10332 "Do not export to next AS (well-known community)\n"
10333 "Exact match of the communities")
10334
10335ALIAS (show_bgp_community_exact,
10336 show_bgp_community2_exact_cmd,
10337 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10338 SHOW_STR
10339 BGP_STR
10340 "Display routes matching the communities\n"
10341 "community number\n"
10342 "Do not send outside local AS (well-known community)\n"
10343 "Do not advertise to any peer (well-known community)\n"
10344 "Do not export to next AS (well-known community)\n"
10345 "community number\n"
10346 "Do not send outside local AS (well-known community)\n"
10347 "Do not advertise to any peer (well-known community)\n"
10348 "Do not export to next AS (well-known community)\n"
10349 "Exact match of the communities")
10350
10351ALIAS (show_bgp_community_exact,
10352 show_bgp_ipv6_community2_exact_cmd,
10353 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10354 SHOW_STR
10355 BGP_STR
10356 "Address family\n"
10357 "Display routes matching the communities\n"
10358 "community number\n"
10359 "Do not send outside local AS (well-known community)\n"
10360 "Do not advertise to any peer (well-known community)\n"
10361 "Do not export to next AS (well-known community)\n"
10362 "community number\n"
10363 "Do not send outside local AS (well-known community)\n"
10364 "Do not advertise to any peer (well-known community)\n"
10365 "Do not export to next AS (well-known community)\n"
10366 "Exact match of the communities")
10367
10368ALIAS (show_bgp_community_exact,
10369 show_bgp_community3_exact_cmd,
10370 "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",
10371 SHOW_STR
10372 BGP_STR
10373 "Display routes matching the communities\n"
10374 "community number\n"
10375 "Do not send outside local AS (well-known community)\n"
10376 "Do not advertise to any peer (well-known community)\n"
10377 "Do not export to next AS (well-known community)\n"
10378 "community number\n"
10379 "Do not send outside local AS (well-known community)\n"
10380 "Do not advertise to any peer (well-known community)\n"
10381 "Do not export to next AS (well-known community)\n"
10382 "community number\n"
10383 "Do not send outside local AS (well-known community)\n"
10384 "Do not advertise to any peer (well-known community)\n"
10385 "Do not export to next AS (well-known community)\n"
10386 "Exact match of the communities")
10387
10388ALIAS (show_bgp_community_exact,
10389 show_bgp_ipv6_community3_exact_cmd,
10390 "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",
10391 SHOW_STR
10392 BGP_STR
10393 "Address family\n"
10394 "Display routes matching the communities\n"
10395 "community number\n"
10396 "Do not send outside local AS (well-known community)\n"
10397 "Do not advertise to any peer (well-known community)\n"
10398 "Do not export to next AS (well-known community)\n"
10399 "community number\n"
10400 "Do not send outside local AS (well-known community)\n"
10401 "Do not advertise to any peer (well-known community)\n"
10402 "Do not export to next AS (well-known community)\n"
10403 "community number\n"
10404 "Do not send outside local AS (well-known community)\n"
10405 "Do not advertise to any peer (well-known community)\n"
10406 "Do not export to next AS (well-known community)\n"
10407 "Exact match of the communities")
10408
10409ALIAS (show_bgp_community_exact,
10410 show_bgp_community4_exact_cmd,
10411 "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",
10412 SHOW_STR
10413 BGP_STR
10414 "Display routes matching the communities\n"
10415 "community number\n"
10416 "Do not send outside local AS (well-known community)\n"
10417 "Do not advertise to any peer (well-known community)\n"
10418 "Do not export to next AS (well-known community)\n"
10419 "community number\n"
10420 "Do not send outside local AS (well-known community)\n"
10421 "Do not advertise to any peer (well-known community)\n"
10422 "Do not export to next AS (well-known community)\n"
10423 "community number\n"
10424 "Do not send outside local AS (well-known community)\n"
10425 "Do not advertise to any peer (well-known community)\n"
10426 "Do not export to next AS (well-known community)\n"
10427 "community number\n"
10428 "Do not send outside local AS (well-known community)\n"
10429 "Do not advertise to any peer (well-known community)\n"
10430 "Do not export to next AS (well-known community)\n"
10431 "Exact match of the communities")
10432
10433ALIAS (show_bgp_community_exact,
10434 show_bgp_ipv6_community4_exact_cmd,
10435 "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",
10436 SHOW_STR
10437 BGP_STR
10438 "Address family\n"
10439 "Display routes matching the communities\n"
10440 "community number\n"
10441 "Do not send outside local AS (well-known community)\n"
10442 "Do not advertise to any peer (well-known community)\n"
10443 "Do not export to next AS (well-known community)\n"
10444 "community number\n"
10445 "Do not send outside local AS (well-known community)\n"
10446 "Do not advertise to any peer (well-known community)\n"
10447 "Do not export to next AS (well-known community)\n"
10448 "community number\n"
10449 "Do not send outside local AS (well-known community)\n"
10450 "Do not advertise to any peer (well-known community)\n"
10451 "Do not export to next AS (well-known community)\n"
10452 "community number\n"
10453 "Do not send outside local AS (well-known community)\n"
10454 "Do not advertise to any peer (well-known community)\n"
10455 "Do not export to next AS (well-known community)\n"
10456 "Exact match of the communities")
10457
10458/* old command */
10459DEFUN (show_ipv6_bgp_community_exact,
10460 show_ipv6_bgp_community_exact_cmd,
10461 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10462 SHOW_STR
10463 IPV6_STR
10464 BGP_STR
10465 "Display routes matching the communities\n"
10466 "community number\n"
10467 "Do not send outside local AS (well-known community)\n"
10468 "Do not advertise to any peer (well-known community)\n"
10469 "Do not export to next AS (well-known community)\n"
10470 "Exact match of the communities")
10471{
95cbbd2a 10472 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 10473}
10474
10475/* old command */
10476ALIAS (show_ipv6_bgp_community_exact,
10477 show_ipv6_bgp_community2_exact_cmd,
10478 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10479 SHOW_STR
10480 IPV6_STR
10481 BGP_STR
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 "Exact match of the communities")
10492
10493/* old command */
10494ALIAS (show_ipv6_bgp_community_exact,
10495 show_ipv6_bgp_community3_exact_cmd,
10496 "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",
10497 SHOW_STR
10498 IPV6_STR
10499 BGP_STR
10500 "Display routes matching the communities\n"
10501 "community number\n"
10502 "Do not send outside local AS (well-known community)\n"
10503 "Do not advertise to any peer (well-known community)\n"
10504 "Do not export to next AS (well-known community)\n"
10505 "community number\n"
10506 "Do not send outside local AS (well-known community)\n"
10507 "Do not advertise to any peer (well-known community)\n"
10508 "Do not export to next AS (well-known community)\n"
10509 "community number\n"
10510 "Do not send outside local AS (well-known community)\n"
10511 "Do not advertise to any peer (well-known community)\n"
10512 "Do not export to next AS (well-known community)\n"
10513 "Exact match of the communities")
10514
10515/* old command */
10516ALIAS (show_ipv6_bgp_community_exact,
10517 show_ipv6_bgp_community4_exact_cmd,
10518 "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",
10519 SHOW_STR
10520 IPV6_STR
10521 BGP_STR
10522 "Display routes matching the communities\n"
10523 "community number\n"
10524 "Do not send outside local AS (well-known community)\n"
10525 "Do not advertise to any peer (well-known community)\n"
10526 "Do not export to next AS (well-known community)\n"
10527 "community number\n"
10528 "Do not send outside local AS (well-known community)\n"
10529 "Do not advertise to any peer (well-known community)\n"
10530 "Do not export to next AS (well-known community)\n"
10531 "community number\n"
10532 "Do not send outside local AS (well-known community)\n"
10533 "Do not advertise to any peer (well-known community)\n"
10534 "Do not export to next AS (well-known community)\n"
10535 "community number\n"
10536 "Do not send outside local AS (well-known community)\n"
10537 "Do not advertise to any peer (well-known community)\n"
10538 "Do not export to next AS (well-known community)\n"
10539 "Exact match of the communities")
10540
10541/* old command */
10542DEFUN (show_ipv6_mbgp_community,
10543 show_ipv6_mbgp_community_cmd,
10544 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10545 SHOW_STR
10546 IPV6_STR
10547 MBGP_STR
10548 "Display routes matching the communities\n"
10549 "community number\n"
10550 "Do not send outside local AS (well-known community)\n"
10551 "Do not advertise to any peer (well-known community)\n"
10552 "Do not export to next AS (well-known community)\n")
10553{
95cbbd2a 10554 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
718e3744 10555}
10556
10557/* old command */
10558ALIAS (show_ipv6_mbgp_community,
10559 show_ipv6_mbgp_community2_cmd,
10560 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10561 SHOW_STR
10562 IPV6_STR
10563 MBGP_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
10574/* old command */
10575ALIAS (show_ipv6_mbgp_community,
10576 show_ipv6_mbgp_community3_cmd,
10577 "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)",
10578 SHOW_STR
10579 IPV6_STR
10580 MBGP_STR
10581 "Display routes matching the communities\n"
10582 "community number\n"
10583 "Do not send outside local AS (well-known community)\n"
10584 "Do not advertise to any peer (well-known community)\n"
10585 "Do not export to next AS (well-known community)\n"
10586 "community number\n"
10587 "Do not send outside local AS (well-known community)\n"
10588 "Do not advertise to any peer (well-known community)\n"
10589 "Do not export to next AS (well-known community)\n"
10590 "community number\n"
10591 "Do not send outside local AS (well-known community)\n"
10592 "Do not advertise to any peer (well-known community)\n"
10593 "Do not export to next AS (well-known community)\n")
10594
10595/* old command */
10596ALIAS (show_ipv6_mbgp_community,
10597 show_ipv6_mbgp_community4_cmd,
10598 "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)",
10599 SHOW_STR
10600 IPV6_STR
10601 MBGP_STR
10602 "Display routes matching the communities\n"
10603 "community number\n"
10604 "Do not send outside local AS (well-known community)\n"
10605 "Do not advertise to any peer (well-known community)\n"
10606 "Do not export to next AS (well-known community)\n"
10607 "community number\n"
10608 "Do not send outside local AS (well-known community)\n"
10609 "Do not advertise to any peer (well-known community)\n"
10610 "Do not export to next AS (well-known community)\n"
10611 "community number\n"
10612 "Do not send outside local AS (well-known community)\n"
10613 "Do not advertise to any peer (well-known community)\n"
10614 "Do not export to next AS (well-known community)\n"
10615 "community number\n"
10616 "Do not send outside local AS (well-known community)\n"
10617 "Do not advertise to any peer (well-known community)\n"
10618 "Do not export to next AS (well-known community)\n")
10619
10620/* old command */
10621DEFUN (show_ipv6_mbgp_community_exact,
10622 show_ipv6_mbgp_community_exact_cmd,
10623 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10624 SHOW_STR
10625 IPV6_STR
10626 MBGP_STR
10627 "Display routes matching the communities\n"
10628 "community number\n"
10629 "Do not send outside local AS (well-known community)\n"
10630 "Do not advertise to any peer (well-known community)\n"
10631 "Do not export to next AS (well-known community)\n"
10632 "Exact match of the communities")
10633{
95cbbd2a 10634 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
718e3744 10635}
10636
10637/* old command */
10638ALIAS (show_ipv6_mbgp_community_exact,
10639 show_ipv6_mbgp_community2_exact_cmd,
10640 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10641 SHOW_STR
10642 IPV6_STR
10643 MBGP_STR
10644 "Display routes matching the communities\n"
10645 "community number\n"
10646 "Do not send outside local AS (well-known community)\n"
10647 "Do not advertise to any peer (well-known community)\n"
10648 "Do not export to next AS (well-known community)\n"
10649 "community number\n"
10650 "Do not send outside local AS (well-known community)\n"
10651 "Do not advertise to any peer (well-known community)\n"
10652 "Do not export to next AS (well-known community)\n"
10653 "Exact match of the communities")
10654
10655/* old command */
10656ALIAS (show_ipv6_mbgp_community_exact,
10657 show_ipv6_mbgp_community3_exact_cmd,
10658 "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",
10659 SHOW_STR
10660 IPV6_STR
10661 MBGP_STR
10662 "Display routes matching the communities\n"
10663 "community number\n"
10664 "Do not send outside local AS (well-known community)\n"
10665 "Do not advertise to any peer (well-known community)\n"
10666 "Do not export to next AS (well-known community)\n"
10667 "community number\n"
10668 "Do not send outside local AS (well-known community)\n"
10669 "Do not advertise to any peer (well-known community)\n"
10670 "Do not export to next AS (well-known community)\n"
10671 "community number\n"
10672 "Do not send outside local AS (well-known community)\n"
10673 "Do not advertise to any peer (well-known community)\n"
10674 "Do not export to next AS (well-known community)\n"
10675 "Exact match of the communities")
10676
10677/* old command */
10678ALIAS (show_ipv6_mbgp_community_exact,
10679 show_ipv6_mbgp_community4_exact_cmd,
10680 "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",
10681 SHOW_STR
10682 IPV6_STR
10683 MBGP_STR
10684 "Display routes matching the communities\n"
10685 "community number\n"
10686 "Do not send outside local AS (well-known community)\n"
10687 "Do not advertise to any peer (well-known community)\n"
10688 "Do not export to next AS (well-known community)\n"
10689 "community number\n"
10690 "Do not send outside local AS (well-known community)\n"
10691 "Do not advertise to any peer (well-known community)\n"
10692 "Do not export to next AS (well-known community)\n"
10693 "community number\n"
10694 "Do not send outside local AS (well-known community)\n"
10695 "Do not advertise to any peer (well-known community)\n"
10696 "Do not export to next AS (well-known community)\n"
10697 "community number\n"
10698 "Do not send outside local AS (well-known community)\n"
10699 "Do not advertise to any peer (well-known community)\n"
10700 "Do not export to next AS (well-known community)\n"
10701 "Exact match of the communities")
10702#endif /* HAVE_IPV6 */
6b0655a2 10703
94f2b392 10704static int
fd79ac91 10705bgp_show_community_list (struct vty *vty, const char *com, int exact,
4c9641ba 10706 afi_t afi, safi_t safi)
718e3744 10707{
10708 struct community_list *list;
10709
fee6e4e4 10710 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
718e3744 10711 if (list == NULL)
10712 {
10713 vty_out (vty, "%% %s is not a valid community-list name%s", com,
10714 VTY_NEWLINE);
10715 return CMD_WARNING;
10716 }
10717
5a646650 10718 return bgp_show (vty, NULL, afi, safi,
10719 (exact ? bgp_show_type_community_list_exact :
b05a1c8b 10720 bgp_show_type_community_list), list, 0);
718e3744 10721}
10722
10723DEFUN (show_ip_bgp_community_list,
10724 show_ip_bgp_community_list_cmd,
fee6e4e4 10725 "show ip bgp community-list (<1-500>|WORD)",
718e3744 10726 SHOW_STR
10727 IP_STR
10728 BGP_STR
10729 "Display routes matching the community-list\n"
fee6e4e4 10730 "community-list number\n"
718e3744 10731 "community-list name\n")
10732{
10733 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
10734}
10735
10736DEFUN (show_ip_bgp_ipv4_community_list,
10737 show_ip_bgp_ipv4_community_list_cmd,
fee6e4e4 10738 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
718e3744 10739 SHOW_STR
10740 IP_STR
10741 BGP_STR
10742 "Address family\n"
10743 "Address Family modifier\n"
10744 "Address Family modifier\n"
10745 "Display routes matching the community-list\n"
fee6e4e4 10746 "community-list number\n"
718e3744 10747 "community-list name\n")
10748{
10749 if (strncmp (argv[0], "m", 1) == 0)
10750 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
10751
10752 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
10753}
10754
10755DEFUN (show_ip_bgp_community_list_exact,
10756 show_ip_bgp_community_list_exact_cmd,
fee6e4e4 10757 "show ip bgp community-list (<1-500>|WORD) exact-match",
718e3744 10758 SHOW_STR
10759 IP_STR
10760 BGP_STR
10761 "Display routes matching the community-list\n"
fee6e4e4 10762 "community-list number\n"
718e3744 10763 "community-list name\n"
10764 "Exact match of the communities\n")
10765{
10766 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
10767}
10768
10769DEFUN (show_ip_bgp_ipv4_community_list_exact,
10770 show_ip_bgp_ipv4_community_list_exact_cmd,
fee6e4e4 10771 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
718e3744 10772 SHOW_STR
10773 IP_STR
10774 BGP_STR
10775 "Address family\n"
10776 "Address Family modifier\n"
10777 "Address Family modifier\n"
10778 "Display routes matching the community-list\n"
fee6e4e4 10779 "community-list number\n"
718e3744 10780 "community-list name\n"
10781 "Exact match of the communities\n")
10782{
10783 if (strncmp (argv[0], "m", 1) == 0)
10784 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
10785
10786 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
10787}
10788
10789#ifdef HAVE_IPV6
10790DEFUN (show_bgp_community_list,
10791 show_bgp_community_list_cmd,
fee6e4e4 10792 "show bgp community-list (<1-500>|WORD)",
718e3744 10793 SHOW_STR
10794 BGP_STR
10795 "Display routes matching the community-list\n"
fee6e4e4 10796 "community-list number\n"
718e3744 10797 "community-list name\n")
10798{
10799 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10800}
10801
10802ALIAS (show_bgp_community_list,
10803 show_bgp_ipv6_community_list_cmd,
fee6e4e4 10804 "show bgp ipv6 community-list (<1-500>|WORD)",
718e3744 10805 SHOW_STR
10806 BGP_STR
10807 "Address family\n"
10808 "Display routes matching the community-list\n"
fee6e4e4 10809 "community-list number\n"
e8e1946e 10810 "community-list name\n")
718e3744 10811
10812/* old command */
10813DEFUN (show_ipv6_bgp_community_list,
10814 show_ipv6_bgp_community_list_cmd,
10815 "show ipv6 bgp community-list WORD",
10816 SHOW_STR
10817 IPV6_STR
10818 BGP_STR
10819 "Display routes matching the community-list\n"
10820 "community-list name\n")
10821{
10822 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10823}
10824
10825/* old command */
10826DEFUN (show_ipv6_mbgp_community_list,
10827 show_ipv6_mbgp_community_list_cmd,
10828 "show ipv6 mbgp community-list WORD",
10829 SHOW_STR
10830 IPV6_STR
10831 MBGP_STR
10832 "Display routes matching the community-list\n"
10833 "community-list name\n")
10834{
10835 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
10836}
10837
10838DEFUN (show_bgp_community_list_exact,
10839 show_bgp_community_list_exact_cmd,
fee6e4e4 10840 "show bgp community-list (<1-500>|WORD) exact-match",
718e3744 10841 SHOW_STR
10842 BGP_STR
10843 "Display routes matching the community-list\n"
fee6e4e4 10844 "community-list number\n"
718e3744 10845 "community-list name\n"
10846 "Exact match of the communities\n")
10847{
10848 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10849}
10850
10851ALIAS (show_bgp_community_list_exact,
10852 show_bgp_ipv6_community_list_exact_cmd,
fee6e4e4 10853 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
718e3744 10854 SHOW_STR
10855 BGP_STR
10856 "Address family\n"
10857 "Display routes matching the community-list\n"
fee6e4e4 10858 "community-list number\n"
718e3744 10859 "community-list name\n"
10860 "Exact match of the communities\n")
10861
10862/* old command */
10863DEFUN (show_ipv6_bgp_community_list_exact,
10864 show_ipv6_bgp_community_list_exact_cmd,
10865 "show ipv6 bgp community-list WORD exact-match",
10866 SHOW_STR
10867 IPV6_STR
10868 BGP_STR
10869 "Display routes matching the community-list\n"
10870 "community-list name\n"
10871 "Exact match of the communities\n")
10872{
10873 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10874}
10875
10876/* old command */
10877DEFUN (show_ipv6_mbgp_community_list_exact,
10878 show_ipv6_mbgp_community_list_exact_cmd,
10879 "show ipv6 mbgp community-list WORD exact-match",
10880 SHOW_STR
10881 IPV6_STR
10882 MBGP_STR
10883 "Display routes matching the community-list\n"
10884 "community-list name\n"
10885 "Exact match of the communities\n")
10886{
10887 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
10888}
10889#endif /* HAVE_IPV6 */
6b0655a2 10890
94f2b392 10891static int
fd79ac91 10892bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
718e3744 10893 safi_t safi, enum bgp_show_type type)
10894{
10895 int ret;
10896 struct prefix *p;
10897
10898 p = prefix_new();
10899
10900 ret = str2prefix (prefix, p);
10901 if (! ret)
10902 {
10903 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
10904 return CMD_WARNING;
10905 }
10906
b05a1c8b 10907 ret = bgp_show (vty, NULL, afi, safi, type, p, 0);
5a646650 10908 prefix_free(p);
10909 return ret;
718e3744 10910}
10911
10912DEFUN (show_ip_bgp_prefix_longer,
10913 show_ip_bgp_prefix_longer_cmd,
10914 "show ip bgp A.B.C.D/M longer-prefixes",
10915 SHOW_STR
10916 IP_STR
10917 BGP_STR
10918 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10919 "Display route and more specific routes\n")
10920{
10921 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
10922 bgp_show_type_prefix_longer);
10923}
10924
10925DEFUN (show_ip_bgp_flap_prefix_longer,
10926 show_ip_bgp_flap_prefix_longer_cmd,
10927 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
10928 SHOW_STR
10929 IP_STR
10930 BGP_STR
10931 "Display flap statistics of routes\n"
10932 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10933 "Display route and more specific routes\n")
10934{
10935 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
10936 bgp_show_type_flap_prefix_longer);
10937}
10938
10939DEFUN (show_ip_bgp_ipv4_prefix_longer,
10940 show_ip_bgp_ipv4_prefix_longer_cmd,
10941 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
10942 SHOW_STR
10943 IP_STR
10944 BGP_STR
10945 "Address family\n"
10946 "Address Family modifier\n"
10947 "Address Family modifier\n"
10948 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10949 "Display route and more specific routes\n")
10950{
10951 if (strncmp (argv[0], "m", 1) == 0)
10952 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
10953 bgp_show_type_prefix_longer);
10954
10955 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
10956 bgp_show_type_prefix_longer);
10957}
10958
10959DEFUN (show_ip_bgp_flap_address,
10960 show_ip_bgp_flap_address_cmd,
10961 "show ip bgp flap-statistics A.B.C.D",
10962 SHOW_STR
10963 IP_STR
10964 BGP_STR
10965 "Display flap statistics of routes\n"
10966 "Network in the BGP routing table to display\n")
10967{
10968 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
10969 bgp_show_type_flap_address);
10970}
10971
10972DEFUN (show_ip_bgp_flap_prefix,
10973 show_ip_bgp_flap_prefix_cmd,
10974 "show ip bgp flap-statistics A.B.C.D/M",
10975 SHOW_STR
10976 IP_STR
10977 BGP_STR
10978 "Display flap statistics of routes\n"
10979 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10980{
10981 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
10982 bgp_show_type_flap_prefix);
10983}
10984#ifdef HAVE_IPV6
10985DEFUN (show_bgp_prefix_longer,
10986 show_bgp_prefix_longer_cmd,
10987 "show bgp X:X::X:X/M longer-prefixes",
10988 SHOW_STR
10989 BGP_STR
10990 "IPv6 prefix <network>/<length>\n"
10991 "Display route and more specific routes\n")
10992{
10993 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
10994 bgp_show_type_prefix_longer);
10995}
10996
10997ALIAS (show_bgp_prefix_longer,
10998 show_bgp_ipv6_prefix_longer_cmd,
10999 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11000 SHOW_STR
11001 BGP_STR
11002 "Address family\n"
11003 "IPv6 prefix <network>/<length>\n"
11004 "Display route and more specific routes\n")
11005
11006/* old command */
11007DEFUN (show_ipv6_bgp_prefix_longer,
11008 show_ipv6_bgp_prefix_longer_cmd,
11009 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11010 SHOW_STR
11011 IPV6_STR
11012 BGP_STR
11013 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11014 "Display route and more specific routes\n")
11015{
11016 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11017 bgp_show_type_prefix_longer);
11018}
11019
11020/* old command */
11021DEFUN (show_ipv6_mbgp_prefix_longer,
11022 show_ipv6_mbgp_prefix_longer_cmd,
11023 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11024 SHOW_STR
11025 IPV6_STR
11026 MBGP_STR
11027 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11028 "Display route and more specific routes\n")
11029{
11030 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
11031 bgp_show_type_prefix_longer);
11032}
11033#endif /* HAVE_IPV6 */
bb46e94f 11034
94f2b392 11035static struct peer *
fd79ac91 11036peer_lookup_in_view (struct vty *vty, const char *view_name,
11037 const char *ip_str)
bb46e94f 11038{
11039 int ret;
11040 struct bgp *bgp;
11041 struct peer *peer;
11042 union sockunion su;
11043
11044 /* BGP structure lookup. */
11045 if (view_name)
11046 {
11047 bgp = bgp_lookup_by_name (view_name);
11048 if (! bgp)
11049 {
11050 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11051 return NULL;
11052 }
11053 }
5228ad27 11054 else
bb46e94f 11055 {
11056 bgp = bgp_get_default ();
11057 if (! bgp)
11058 {
11059 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11060 return NULL;
11061 }
11062 }
11063
11064 /* Get peer sockunion. */
11065 ret = str2sockunion (ip_str, &su);
11066 if (ret < 0)
11067 {
a80beece
DS
11068 peer = peer_lookup_by_conf_if (bgp, ip_str);
11069 if (!peer)
11070 {
6410e93a
DS
11071 /* search for peer by hostname */
11072 peer = peer_lookup_by_hostname(bgp, ip_str);
11073 if (!peer)
11074 {
11075 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
11076 return NULL;
11077 }
a80beece
DS
11078 }
11079 return peer;
bb46e94f 11080 }
11081
11082 /* Peer structure lookup. */
11083 peer = peer_lookup (bgp, &su);
11084 if (! peer)
11085 {
11086 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11087 return NULL;
11088 }
11089
11090 return peer;
11091}
6b0655a2 11092
2815e61f
PJ
11093enum bgp_stats
11094{
11095 BGP_STATS_MAXBITLEN = 0,
11096 BGP_STATS_RIB,
11097 BGP_STATS_PREFIXES,
11098 BGP_STATS_TOTPLEN,
11099 BGP_STATS_UNAGGREGATEABLE,
11100 BGP_STATS_MAX_AGGREGATEABLE,
11101 BGP_STATS_AGGREGATES,
11102 BGP_STATS_SPACE,
11103 BGP_STATS_ASPATH_COUNT,
11104 BGP_STATS_ASPATH_MAXHOPS,
11105 BGP_STATS_ASPATH_TOTHOPS,
11106 BGP_STATS_ASPATH_MAXSIZE,
11107 BGP_STATS_ASPATH_TOTSIZE,
11108 BGP_STATS_ASN_HIGHEST,
11109 BGP_STATS_MAX,
11110};
11111
11112static const char *table_stats_strs[] =
11113{
11114 [BGP_STATS_PREFIXES] = "Total Prefixes",
11115 [BGP_STATS_TOTPLEN] = "Average prefix length",
11116 [BGP_STATS_RIB] = "Total Advertisements",
11117 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11118 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11119 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11120 [BGP_STATS_SPACE] = "Address space advertised",
11121 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11122 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11123 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11124 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11125 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11126 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11127 [BGP_STATS_MAX] = NULL,
11128};
11129
11130struct bgp_table_stats
11131{
11132 struct bgp_table *table;
11133 unsigned long long counts[BGP_STATS_MAX];
11134};
11135
11136#if 0
11137#define TALLY_SIGFIG 100000
11138static unsigned long
11139ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11140{
11141 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11142 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11143 unsigned long ret = newtot / count;
11144
11145 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11146 return ret + 1;
11147 else
11148 return ret;
11149}
11150#endif
11151
11152static int
11153bgp_table_stats_walker (struct thread *t)
11154{
11155 struct bgp_node *rn;
11156 struct bgp_node *top;
11157 struct bgp_table_stats *ts = THREAD_ARG (t);
11158 unsigned int space = 0;
11159
53d9f67a
PJ
11160 if (!(top = bgp_table_top (ts->table)))
11161 return 0;
2815e61f
PJ
11162
11163 switch (top->p.family)
11164 {
11165 case AF_INET:
11166 space = IPV4_MAX_BITLEN;
11167 break;
11168 case AF_INET6:
11169 space = IPV6_MAX_BITLEN;
11170 break;
11171 }
11172
11173 ts->counts[BGP_STATS_MAXBITLEN] = space;
11174
11175 for (rn = top; rn; rn = bgp_route_next (rn))
11176 {
11177 struct bgp_info *ri;
67174041 11178 struct bgp_node *prn = bgp_node_parent_nolock (rn);
2815e61f
PJ
11179 unsigned int rinum = 0;
11180
11181 if (rn == top)
11182 continue;
11183
11184 if (!rn->info)
11185 continue;
11186
11187 ts->counts[BGP_STATS_PREFIXES]++;
11188 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11189
11190#if 0
11191 ts->counts[BGP_STATS_AVGPLEN]
11192 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11193 ts->counts[BGP_STATS_AVGPLEN],
11194 rn->p.prefixlen);
11195#endif
11196
11197 /* check if the prefix is included by any other announcements */
11198 while (prn && !prn->info)
67174041 11199 prn = bgp_node_parent_nolock (prn);
2815e61f
PJ
11200
11201 if (prn == NULL || prn == top)
8383a9bd
PJ
11202 {
11203 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11204 /* announced address space */
11205 if (space)
11206 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11207 }
2815e61f
PJ
11208 else if (prn->info)
11209 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11210
2815e61f
PJ
11211 for (ri = rn->info; ri; ri = ri->next)
11212 {
11213 rinum++;
11214 ts->counts[BGP_STATS_RIB]++;
11215
11216 if (ri->attr &&
11217 (CHECK_FLAG (ri->attr->flag,
11218 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11219 ts->counts[BGP_STATS_AGGREGATES]++;
11220
11221 /* as-path stats */
11222 if (ri->attr && ri->attr->aspath)
11223 {
11224 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11225 unsigned int size = aspath_size (ri->attr->aspath);
11226 as_t highest = aspath_highest (ri->attr->aspath);
11227
11228 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11229
11230 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11231 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11232
11233 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11234 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11235
11236 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11237 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11238#if 0
11239 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11240 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11241 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11242 hops);
11243 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11244 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11245 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11246 size);
11247#endif
11248 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11249 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11250 }
11251 }
11252 }
11253 return 0;
11254}
11255
11256static int
11257bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11258{
11259 struct bgp_table_stats ts;
11260 unsigned int i;
11261
11262 if (!bgp->rib[afi][safi])
11263 {
11264 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
11265 return CMD_WARNING;
11266 }
11267
11268 memset (&ts, 0, sizeof (ts));
11269 ts.table = bgp->rib[afi][safi];
11270 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
bb46e94f 11271
2815e61f
PJ
11272 vty_out (vty, "BGP %s RIB statistics%s%s",
11273 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11274
11275 for (i = 0; i < BGP_STATS_MAX; i++)
11276 {
11277 if (!table_stats_strs[i])
11278 continue;
11279
11280 switch (i)
11281 {
11282#if 0
11283 case BGP_STATS_ASPATH_AVGHOPS:
11284 case BGP_STATS_ASPATH_AVGSIZE:
11285 case BGP_STATS_AVGPLEN:
11286 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11287 vty_out (vty, "%12.2f",
11288 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11289 break;
11290#endif
11291 case BGP_STATS_ASPATH_TOTHOPS:
11292 case BGP_STATS_ASPATH_TOTSIZE:
11293 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11294 vty_out (vty, "%12.2f",
11295 ts.counts[i] ?
11296 (float)ts.counts[i] /
11297 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11298 : 0);
11299 break;
11300 case BGP_STATS_TOTPLEN:
11301 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11302 vty_out (vty, "%12.2f",
11303 ts.counts[i] ?
11304 (float)ts.counts[i] /
11305 (float)ts.counts[BGP_STATS_PREFIXES]
11306 : 0);
11307 break;
11308 case BGP_STATS_SPACE:
11309 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11310 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11311 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11312 break;
30a2231a 11313 vty_out (vty, "%30s: ", "%% announced ");
2815e61f
PJ
11314 vty_out (vty, "%12.2f%s",
11315 100 * (float)ts.counts[BGP_STATS_SPACE] /
56395af7 11316 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
2815e61f
PJ
11317 VTY_NEWLINE);
11318 vty_out (vty, "%30s: ", "/8 equivalent ");
11319 vty_out (vty, "%12.2f%s",
11320 (float)ts.counts[BGP_STATS_SPACE] /
11321 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11322 VTY_NEWLINE);
11323 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11324 break;
11325 vty_out (vty, "%30s: ", "/24 equivalent ");
11326 vty_out (vty, "%12.2f",
11327 (float)ts.counts[BGP_STATS_SPACE] /
11328 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11329 break;
11330 default:
11331 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11332 vty_out (vty, "%12llu", ts.counts[i]);
11333 }
11334
11335 vty_out (vty, "%s", VTY_NEWLINE);
11336 }
11337 return CMD_SUCCESS;
11338}
11339
11340static int
11341bgp_table_stats_vty (struct vty *vty, const char *name,
11342 const char *afi_str, const char *safi_str)
11343{
11344 struct bgp *bgp;
11345 afi_t afi;
11346 safi_t safi;
11347
11348 if (name)
11349 bgp = bgp_lookup_by_name (name);
11350 else
11351 bgp = bgp_get_default ();
11352
11353 if (!bgp)
11354 {
11355 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
11356 return CMD_WARNING;
11357 }
11358 if (strncmp (afi_str, "ipv", 3) == 0)
11359 {
11360 if (strncmp (afi_str, "ipv4", 4) == 0)
11361 afi = AFI_IP;
11362 else if (strncmp (afi_str, "ipv6", 4) == 0)
11363 afi = AFI_IP6;
11364 else
11365 {
11366 vty_out (vty, "%% Invalid address family %s%s",
11367 afi_str, VTY_NEWLINE);
11368 return CMD_WARNING;
11369 }
11370 if (strncmp (safi_str, "m", 1) == 0)
11371 safi = SAFI_MULTICAST;
11372 else if (strncmp (safi_str, "u", 1) == 0)
11373 safi = SAFI_UNICAST;
42e6d745
DO
11374 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
11375 safi = SAFI_MPLS_LABELED_VPN;
2815e61f
PJ
11376 else
11377 {
11378 vty_out (vty, "%% Invalid subsequent address family %s%s",
11379 safi_str, VTY_NEWLINE);
11380 return CMD_WARNING;
11381 }
11382 }
11383 else
11384 {
11385 vty_out (vty, "%% Invalid address family %s%s",
11386 afi_str, VTY_NEWLINE);
11387 return CMD_WARNING;
11388 }
11389
2815e61f
PJ
11390 return bgp_table_stats (vty, bgp, afi, safi);
11391}
11392
11393DEFUN (show_bgp_statistics,
11394 show_bgp_statistics_cmd,
11395 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
11396 SHOW_STR
11397 BGP_STR
11398 "Address family\n"
11399 "Address family\n"
11400 "Address Family modifier\n"
11401 "Address Family modifier\n"
11402 "BGP RIB advertisement statistics\n")
11403{
11404 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11405}
11406
11407ALIAS (show_bgp_statistics,
11408 show_bgp_statistics_vpnv4_cmd,
11409 "show bgp (ipv4) (vpnv4) statistics",
11410 SHOW_STR
11411 BGP_STR
11412 "Address family\n"
11413 "Address Family modifier\n"
11414 "BGP RIB advertisement statistics\n")
11415
11416DEFUN (show_bgp_statistics_view,
11417 show_bgp_statistics_view_cmd,
11418 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
11419 SHOW_STR
11420 BGP_STR
11421 "BGP view\n"
11422 "Address family\n"
11423 "Address family\n"
11424 "Address Family modifier\n"
11425 "Address Family modifier\n"
11426 "BGP RIB advertisement statistics\n")
11427{
11428 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11429}
11430
11431ALIAS (show_bgp_statistics_view,
11432 show_bgp_statistics_view_vpnv4_cmd,
11433 "show bgp view WORD (ipv4) (vpnv4) statistics",
11434 SHOW_STR
11435 BGP_STR
11436 "BGP view\n"
11437 "Address family\n"
11438 "Address Family modifier\n"
11439 "BGP RIB advertisement statistics\n")
6b0655a2 11440
ff7924f6
PJ
11441enum bgp_pcounts
11442{
11443 PCOUNT_ADJ_IN = 0,
11444 PCOUNT_DAMPED,
11445 PCOUNT_REMOVED,
11446 PCOUNT_HISTORY,
11447 PCOUNT_STALE,
11448 PCOUNT_VALID,
11449 PCOUNT_ALL,
11450 PCOUNT_COUNTED,
11451 PCOUNT_PFCNT, /* the figure we display to users */
11452 PCOUNT_MAX,
11453};
11454
11455static const char *pcount_strs[] =
11456{
11457 [PCOUNT_ADJ_IN] = "Adj-in",
11458 [PCOUNT_DAMPED] = "Damped",
11459 [PCOUNT_REMOVED] = "Removed",
11460 [PCOUNT_HISTORY] = "History",
11461 [PCOUNT_STALE] = "Stale",
11462 [PCOUNT_VALID] = "Valid",
11463 [PCOUNT_ALL] = "All RIB",
11464 [PCOUNT_COUNTED] = "PfxCt counted",
11465 [PCOUNT_PFCNT] = "Useable",
11466 [PCOUNT_MAX] = NULL,
11467};
11468
2815e61f
PJ
11469struct peer_pcounts
11470{
11471 unsigned int count[PCOUNT_MAX];
11472 const struct peer *peer;
11473 const struct bgp_table *table;
11474};
11475
ff7924f6 11476static int
2815e61f 11477bgp_peer_count_walker (struct thread *t)
ff7924f6
PJ
11478{
11479 struct bgp_node *rn;
2815e61f
PJ
11480 struct peer_pcounts *pc = THREAD_ARG (t);
11481 const struct peer *peer = pc->peer;
ff7924f6 11482
2815e61f 11483 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
ff7924f6
PJ
11484 {
11485 struct bgp_adj_in *ain;
2815e61f 11486 struct bgp_info *ri;
ff7924f6
PJ
11487
11488 for (ain = rn->adj_in; ain; ain = ain->next)
11489 if (ain->peer == peer)
2815e61f 11490 pc->count[PCOUNT_ADJ_IN]++;
ff7924f6 11491
ff7924f6
PJ
11492 for (ri = rn->info; ri; ri = ri->next)
11493 {
11494 char buf[SU_ADDRSTRLEN];
11495
11496 if (ri->peer != peer)
11497 continue;
11498
2815e61f 11499 pc->count[PCOUNT_ALL]++;
ff7924f6
PJ
11500
11501 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
2815e61f 11502 pc->count[PCOUNT_DAMPED]++;
ff7924f6 11503 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2815e61f 11504 pc->count[PCOUNT_HISTORY]++;
ff7924f6 11505 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
2815e61f 11506 pc->count[PCOUNT_REMOVED]++;
ff7924f6 11507 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2815e61f 11508 pc->count[PCOUNT_STALE]++;
ff7924f6 11509 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
2815e61f 11510 pc->count[PCOUNT_VALID]++;
1a392d46 11511 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2815e61f 11512 pc->count[PCOUNT_PFCNT]++;
ff7924f6
PJ
11513
11514 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
11515 {
2815e61f 11516 pc->count[PCOUNT_COUNTED]++;
1a392d46 11517 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 11518 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
ff7924f6
PJ
11519 peer->host,
11520 inet_ntop(rn->p.family, &rn->p.u.prefix,
11521 buf, SU_ADDRSTRLEN),
11522 rn->p.prefixlen,
11523 ri->flags);
11524 }
11525 else
11526 {
1a392d46 11527 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 11528 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
ff7924f6
PJ
11529 peer->host,
11530 inet_ntop(rn->p.family, &rn->p.u.prefix,
11531 buf, SU_ADDRSTRLEN),
11532 rn->p.prefixlen,
11533 ri->flags);
11534 }
11535 }
11536 }
2815e61f
PJ
11537 return 0;
11538}
ff7924f6 11539
2815e61f
PJ
11540static int
11541bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
11542{
11543 struct peer_pcounts pcounts = { .peer = peer };
11544 unsigned int i;
11545
11546 if (!peer || !peer->bgp || !peer->afc[afi][safi]
11547 || !peer->bgp->rib[afi][safi])
11548 {
11549 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11550 return CMD_WARNING;
11551 }
11552
11553 memset (&pcounts, 0, sizeof(pcounts));
11554 pcounts.peer = peer;
11555 pcounts.table = peer->bgp->rib[afi][safi];
11556
11557 /* in-place call via thread subsystem so as to record execution time
11558 * stats for the thread-walk (i.e. ensure this can't be blamed on
11559 * on just vty_read()).
11560 */
11561 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
6410e93a
DS
11562
11563 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
11564 {
11565 vty_out (vty, "Prefix counts for %s/%s, %s%s",
11566 peer->hostname, peer->host, afi_safi_print (afi, safi),
11567 VTY_NEWLINE);
11568 }
11569 else
11570 vty_out (vty, "Prefix counts for %s, %s%s",
11571 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
ff7924f6
PJ
11572 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
11573 vty_out (vty, "%sCounts from RIB table walk:%s%s",
11574 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
11575
11576 for (i = 0; i < PCOUNT_MAX; i++)
2815e61f
PJ
11577 vty_out (vty, "%20s: %-10d%s",
11578 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
ff7924f6 11579
2815e61f 11580 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
ff7924f6
PJ
11581 {
11582 vty_out (vty, "%s [pcount] PfxCt drift!%s",
11583 peer->host, VTY_NEWLINE);
11584 vty_out (vty, "Please report this bug, with the above command output%s",
11585 VTY_NEWLINE);
11586 }
11587
11588 return CMD_SUCCESS;
11589}
11590
11591DEFUN (show_ip_bgp_neighbor_prefix_counts,
11592 show_ip_bgp_neighbor_prefix_counts_cmd,
a80beece 11593 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
ff7924f6
PJ
11594 SHOW_STR
11595 IP_STR
11596 BGP_STR
11597 "Detailed information on TCP and BGP neighbor connections\n"
11598 "Neighbor to display information about\n"
11599 "Neighbor to display information about\n"
a80beece 11600 "Neighbor on bgp configured interface\n"
ff7924f6
PJ
11601 "Display detailed prefix count information\n")
11602{
11603 struct peer *peer;
11604
11605 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11606 if (! peer)
11607 return CMD_WARNING;
11608
11609 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
11610}
11611
11612DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
11613 show_bgp_ipv6_neighbor_prefix_counts_cmd,
a80beece 11614 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
ff7924f6
PJ
11615 SHOW_STR
11616 BGP_STR
11617 "Address family\n"
11618 "Detailed information on TCP and BGP neighbor connections\n"
11619 "Neighbor to display information about\n"
11620 "Neighbor to display information about\n"
a80beece 11621 "Neighbor on bgp configured interface\n"
ff7924f6
PJ
11622 "Display detailed prefix count information\n")
11623{
11624 struct peer *peer;
11625
11626 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11627 if (! peer)
11628 return CMD_WARNING;
11629
11630 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
11631}
11632
11633DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
11634 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
a80beece 11635 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
ff7924f6
PJ
11636 SHOW_STR
11637 IP_STR
11638 BGP_STR
11639 "Address family\n"
11640 "Address Family modifier\n"
11641 "Address Family modifier\n"
11642 "Detailed information on TCP and BGP neighbor connections\n"
11643 "Neighbor to display information about\n"
11644 "Neighbor to display information about\n"
a80beece 11645 "Neighbor on bgp configured interface\n"
ff7924f6
PJ
11646 "Display detailed prefix count information\n")
11647{
11648 struct peer *peer;
11649
11650 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11651 if (! peer)
11652 return CMD_WARNING;
11653
11654 if (strncmp (argv[0], "m", 1) == 0)
11655 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
11656
11657 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
11658}
11659
11660DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
11661 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
a80beece 11662 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
ff7924f6
PJ
11663 SHOW_STR
11664 IP_STR
11665 BGP_STR
11666 "Address family\n"
11667 "Address Family modifier\n"
11668 "Address Family modifier\n"
11669 "Detailed information on TCP and BGP neighbor connections\n"
11670 "Neighbor to display information about\n"
11671 "Neighbor to display information about\n"
a80beece 11672 "Neighbor on bgp configured interface\n"
ff7924f6
PJ
11673 "Display detailed prefix count information\n")
11674{
11675 struct peer *peer;
11676
11677 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11678 if (! peer)
11679 return CMD_WARNING;
11680
11681 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
11682}
11683
94f2b392 11684static void
718e3744 11685show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
ffd0c037 11686 int in, const char *rmap_name)
718e3744 11687{
11688 struct bgp_table *table;
11689 struct bgp_adj_in *ain;
11690 struct bgp_adj_out *adj;
11691 unsigned long output_count;
0b16f239 11692 unsigned long filtered_count;
718e3744 11693 struct bgp_node *rn;
11694 int header1 = 1;
11695 struct bgp *bgp;
11696 int header2 = 1;
0b16f239
DS
11697 struct attr attr;
11698 struct attr_extra extra;
11699 int ret;
840fced9 11700 struct update_subgroup *subgrp;
718e3744 11701
bb46e94f 11702 bgp = peer->bgp;
718e3744 11703
11704 if (! bgp)
11705 return;
11706
11707 table = bgp->rib[afi][safi];
11708
0b16f239 11709 output_count = filtered_count = 0;
840fced9 11710 subgrp = peer_subgroup(peer, afi, safi);
47fc97cc 11711
840fced9 11712 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
718e3744 11713 {
ffd0c037 11714 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
93406d87 11715 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11716 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 11717
11718 vty_out (vty, "Originating default network 0.0.0.0%s%s",
11719 VTY_NEWLINE, VTY_NEWLINE);
11720 header1 = 0;
11721 }
11722
0b16f239 11723 attr.extra = &extra;
718e3744 11724 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11725 if (in)
11726 {
11727 for (ain = rn->adj_in; ain; ain = ain->next)
11728 if (ain->peer == peer)
11729 {
11730 if (header1)
11731 {
11732 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
93406d87 11733 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11734 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 11735 header1 = 0;
11736 }
11737 if (header2)
11738 {
b05a1c8b 11739 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
718e3744 11740 header2 = 0;
11741 }
11742 if (ain->attr)
47fc97cc 11743 {
0b16f239
DS
11744 bgp_attr_dup(&attr, ain->attr);
11745 if (bgp_input_modifier(peer, &rn->p, &attr, afi,
11746 safi, rmap_name) != RMAP_DENY)
11747 {
b05a1c8b 11748 route_vty_out_tmp (vty, &rn->p, &attr, safi);
0b16f239
DS
11749 output_count++;
11750 }
11751 else
11752 filtered_count++;
718e3744 11753 }
11754 }
11755 }
11756 else
11757 {
3f9c7369
DS
11758 adj = bgp_adj_peer_lookup(peer, rn);
11759 if (adj)
11760 {
11761 if (header1)
11762 {
ffd0c037 11763 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID "
3f9c7369
DS
11764 "is %s%s", table->version,
11765 inet_ntoa (bgp->router_id), VTY_NEWLINE);
11766 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11767 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11768 header1 = 0;
11769 }
11770 if (header2)
11771 {
b05a1c8b 11772 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
3f9c7369
DS
11773 header2 = 0;
11774 }
11775 if (adj->attr)
11776 {
8f950571
DS
11777 bgp_attr_dup(&attr, adj->attr);
11778 ret = bgp_output_modifier(peer, &rn->p, &attr, afi,
11779 safi, rmap_name);
0b16f239 11780
3f9c7369
DS
11781 if (ret != RMAP_DENY)
11782 {
b05a1c8b 11783 route_vty_out_tmp (vty, &rn->p, &attr, safi);
3f9c7369
DS
11784 output_count++;
11785 }
11786 else
11787 filtered_count++;
11788 }
11789 }
718e3744 11790 }
47fc97cc 11791
718e3744 11792 if (output_count != 0)
11793 vty_out (vty, "%sTotal number of prefixes %ld%s",
11794 VTY_NEWLINE, output_count, VTY_NEWLINE);
11795}
11796
94f2b392 11797static int
47fc97cc 11798peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
ffd0c037 11799 int in, const char *rmap_name)
bb46e94f 11800{
718e3744 11801 if (! peer || ! peer->afc[afi][safi])
11802 {
11803 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11804 return CMD_WARNING;
11805 }
11806
11807 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11808 {
11809 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
11810 VTY_NEWLINE);
11811 return CMD_WARNING;
11812 }
11813
b05a1c8b 11814 show_adj_route (vty, peer, afi, safi, in, rmap_name);
718e3744 11815
11816 return CMD_SUCCESS;
11817}
11818
2a71e9ce
TP
11819DEFUN (show_ip_bgp_view_neighbor_advertised_route,
11820 show_ip_bgp_view_neighbor_advertised_route_cmd,
a80beece 11821 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 11822 SHOW_STR
11823 IP_STR
11824 BGP_STR
2a71e9ce
TP
11825 "BGP view\n"
11826 "View name\n"
718e3744 11827 "Detailed information on TCP and BGP neighbor connections\n"
11828 "Neighbor to display information about\n"
11829 "Neighbor to display information about\n"
11830 "Display the routes advertised to a BGP neighbor\n")
11831{
bb46e94f 11832 struct peer *peer;
11833
2a71e9ce
TP
11834 if (argc == 2)
11835 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11836 else
11837 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11838
bb46e94f 11839 if (! peer)
11840 return CMD_WARNING;
0b16f239 11841
b05a1c8b 11842 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL);
718e3744 11843}
11844
0b16f239 11845DEFUN (show_ip_bgp_neighbor_advertised_route,
2a71e9ce 11846 show_ip_bgp_neighbor_advertised_route_cmd,
a80beece 11847 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
2a71e9ce
TP
11848 SHOW_STR
11849 IP_STR
11850 BGP_STR
11851 "Detailed information on TCP and BGP neighbor connections\n"
11852 "Neighbor to display information about\n"
11853 "Neighbor to display information about\n"
a80beece 11854 "Neighbor on bgp configured interface\n"
2a71e9ce
TP
11855 "Display the routes advertised to a BGP neighbor\n")
11856
0b16f239
DS
11857{
11858 struct peer *peer;
ffd0c037 11859 const char *rmap_name = NULL;
0b16f239
DS
11860
11861 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11862
11863 if (! peer)
11864 return CMD_WARNING;
11865
11866 if (argc == 2)
11867 rmap_name = argv[1];
11868
b05a1c8b 11869 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name);
0b16f239
DS
11870}
11871
11872ALIAS (show_ip_bgp_neighbor_advertised_route,
11873 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
11874 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
11875 SHOW_STR
11876 IP_STR
11877 BGP_STR
11878 "Detailed information on TCP and BGP neighbor connections\n"
11879 "Neighbor to display information about\n"
11880 "Neighbor to display information about\n"
11881 "Neighbor on bgp configured interface\n"
11882 "Display the routes advertised to a BGP neighbor\n")
11883
718e3744 11884DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
11885 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
a80beece 11886 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 11887 SHOW_STR
11888 IP_STR
11889 BGP_STR
11890 "Address family\n"
11891 "Address Family modifier\n"
11892 "Address Family modifier\n"
11893 "Detailed information on TCP and BGP neighbor connections\n"
11894 "Neighbor to display information about\n"
11895 "Neighbor to display information about\n"
a80beece 11896 "Neighbor on bgp configured interface\n"
718e3744 11897 "Display the routes advertised to a BGP neighbor\n")
11898{
bb46e94f 11899 struct peer *peer;
ffd0c037 11900 const char *rmap_name = NULL;
bb46e94f 11901
11902 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11903 if (! peer)
11904 return CMD_WARNING;
11905
0b16f239
DS
11906 if (argc == 3)
11907 rmap_name = argv[2];
11908
718e3744 11909 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 11910 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name);
718e3744 11911
b05a1c8b 11912 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name);
718e3744 11913}
11914
0b16f239
DS
11915ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
11916 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
11917 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
11918 SHOW_STR
11919 IP_STR
11920 BGP_STR
11921 "Address family\n"
11922 "Address Family modifier\n"
11923 "Address Family modifier\n"
11924 "Detailed information on TCP and BGP neighbor connections\n"
11925 "Neighbor to display information about\n"
11926 "Neighbor to display information about\n"
11927 "Neighbor on bgp configured interface\n"
11928 "Display the routes advertised to a BGP neighbor\n"
11929 "Route-map to control what is displayed\n")
11930
718e3744 11931#ifdef HAVE_IPV6
bb46e94f 11932DEFUN (show_bgp_view_neighbor_advertised_route,
11933 show_bgp_view_neighbor_advertised_route_cmd,
a80beece 11934 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 11935 SHOW_STR
11936 BGP_STR
bb46e94f 11937 "BGP view\n"
11938 "View name\n"
718e3744 11939 "Detailed information on TCP and BGP neighbor connections\n"
11940 "Neighbor to display information about\n"
11941 "Neighbor to display information about\n"
a80beece 11942 "Neighbor on bgp configured interface\n"
718e3744 11943 "Display the routes advertised to a BGP neighbor\n")
11944{
bb46e94f 11945 struct peer *peer;
11946
11947 if (argc == 2)
11948 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11949 else
11950 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11951
11952 if (! peer)
0b16f239 11953 return CMD_WARNING;
bb46e94f 11954
b05a1c8b 11955 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL);
47fc97cc
DS
11956}
11957
0b16f239
DS
11958ALIAS (show_bgp_view_neighbor_advertised_route,
11959 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
11960 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
11961 SHOW_STR
11962 BGP_STR
11963 "BGP view\n"
11964 "View name\n"
11965 "Address family\n"
11966 "Detailed information on TCP and BGP neighbor connections\n"
11967 "Neighbor to display information about\n"
11968 "Neighbor to display information about\n"
11969 "Neighbor on bgp configured interface\n"
11970 "Display the routes advertised to a BGP neighbor\n")
11971
0b16f239
DS
11972DEFUN (show_bgp_neighbor_advertised_route,
11973 show_bgp_neighbor_advertised_route_cmd,
11974 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
bb46e94f 11975 SHOW_STR
11976 BGP_STR
bb46e94f 11977 "Detailed information on TCP and BGP neighbor connections\n"
11978 "Neighbor to display information about\n"
11979 "Neighbor to display information about\n"
a80beece 11980 "Neighbor on bgp configured interface\n"
0b16f239
DS
11981 "Display the routes advertised to a BGP neighbor\n")
11982
bb46e94f 11983{
11984 struct peer *peer;
ffd0c037 11985 const char *rmap_name = NULL;
bb46e94f 11986
0b16f239 11987 peer = peer_lookup_in_view (vty, NULL, argv[0]);
bb46e94f 11988
11989 if (! peer)
11990 return CMD_WARNING;
11991
0b16f239
DS
11992 if (argc == 2)
11993 rmap_name = argv[1];
11994
b05a1c8b 11995 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name);
718e3744 11996}
11997
0b16f239
DS
11998ALIAS (show_bgp_neighbor_advertised_route,
11999 show_bgp_neighbor_advertised_route_rmap_cmd,
12000 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
bb46e94f 12001 SHOW_STR
12002 BGP_STR
bb46e94f 12003 "Detailed information on TCP and BGP neighbor connections\n"
12004 "Neighbor to display information about\n"
12005 "Neighbor to display information about\n"
a80beece 12006 "Neighbor on bgp configured interface\n"
0b16f239 12007 "Display the routes advertised to a BGP neighbor\n")
bb46e94f 12008
0b16f239
DS
12009ALIAS (show_bgp_neighbor_advertised_route,
12010 show_bgp_ipv6_neighbor_advertised_route_cmd,
12011 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
bb46e94f 12012 SHOW_STR
12013 BGP_STR
0b16f239 12014 "Address family\n"
bb46e94f 12015 "Detailed information on TCP and BGP neighbor connections\n"
12016 "Neighbor to display information about\n"
12017 "Neighbor to display information about\n"
a80beece 12018 "Neighbor on bgp configured interface\n"
bb46e94f 12019 "Display the routes advertised to a BGP neighbor\n")
0b16f239
DS
12020
12021ALIAS (show_bgp_neighbor_advertised_route,
12022 show_bgp_ipv6_neighbor_advertised_route_rmap_cmd,
12023 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
718e3744 12024 SHOW_STR
12025 BGP_STR
12026 "Address family\n"
12027 "Detailed information on TCP and BGP neighbor connections\n"
12028 "Neighbor to display information about\n"
12029 "Neighbor to display information about\n"
a80beece 12030 "Neighbor on bgp configured interface\n"
718e3744 12031 "Display the routes advertised to a BGP neighbor\n")
12032
12033/* old command */
0b16f239 12034ALIAS (show_bgp_neighbor_advertised_route,
718e3744 12035 ipv6_bgp_neighbor_advertised_route_cmd,
a80beece 12036 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 12037 SHOW_STR
12038 IPV6_STR
12039 BGP_STR
12040 "Detailed information on TCP and BGP neighbor connections\n"
12041 "Neighbor to display information about\n"
12042 "Neighbor to display information about\n"
a80beece 12043 "Neighbor on bgp configured interface\n"
718e3744 12044 "Display the routes advertised to a BGP neighbor\n")
bb46e94f 12045
718e3744 12046/* old command */
12047DEFUN (ipv6_mbgp_neighbor_advertised_route,
12048 ipv6_mbgp_neighbor_advertised_route_cmd,
a80beece 12049 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 12050 SHOW_STR
12051 IPV6_STR
12052 MBGP_STR
12053 "Detailed information on TCP and BGP neighbor connections\n"
12054 "Neighbor to display information about\n"
12055 "Neighbor to display information about\n"
a80beece
DS
12056 "Neighbor on bgp configured interface\n"
12057 "Neighbor on bgp configured interface\n"
718e3744 12058 "Display the routes advertised to a BGP neighbor\n")
12059{
bb46e94f 12060 struct peer *peer;
12061
12062 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12063 if (! peer)
12064 return CMD_WARNING;
12065
b05a1c8b 12066 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL);
718e3744 12067}
12068#endif /* HAVE_IPV6 */
6b0655a2 12069
0b16f239
DS
12070DEFUN (show_bgp_view_neighbor_received_routes,
12071 show_bgp_view_neighbor_received_routes_cmd,
12072 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
12073 SHOW_STR
12074 BGP_STR
12075 "BGP view\n"
12076 "View name\n"
12077 "Detailed information on TCP and BGP neighbor connections\n"
12078 "Neighbor to display information about\n"
12079 "Neighbor to display information about\n"
12080 "Neighbor on bgp configured interface\n"
12081 "Display the received routes from neighbor\n")
12082{
12083 struct peer *peer;
12084
12085 if (argc == 2)
12086 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12087 else
12088 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12089
12090 if (! peer)
12091 return CMD_WARNING;
12092
b05a1c8b 12093 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL);
0b16f239
DS
12094}
12095
2a71e9ce
TP
12096DEFUN (show_ip_bgp_view_neighbor_received_routes,
12097 show_ip_bgp_view_neighbor_received_routes_cmd,
a80beece 12098 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12099 SHOW_STR
12100 IP_STR
12101 BGP_STR
2a71e9ce
TP
12102 "BGP view\n"
12103 "View name\n"
718e3744 12104 "Detailed information on TCP and BGP neighbor connections\n"
12105 "Neighbor to display information about\n"
12106 "Neighbor to display information about\n"
a80beece 12107 "Neighbor on bgp configured interface\n"
718e3744 12108 "Display the received routes from neighbor\n")
12109{
bb46e94f 12110 struct peer *peer;
12111
2a71e9ce
TP
12112 if (argc == 2)
12113 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12114 else
12115 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12116
bb46e94f 12117 if (! peer)
12118 return CMD_WARNING;
12119
b05a1c8b 12120 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL);
718e3744 12121}
12122
0b16f239
DS
12123ALIAS (show_bgp_view_neighbor_received_routes,
12124 show_bgp_view_ipv6_neighbor_received_routes_cmd,
12125 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
12126 SHOW_STR
12127 BGP_STR
12128 "BGP view\n"
12129 "View name\n"
12130 "Address family\n"
12131 "Detailed information on TCP and BGP neighbor connections\n"
12132 "Neighbor to display information about\n"
12133 "Neighbor to display information about\n"
12134 "Neighbor on bgp configured interface\n"
12135 "Display the received routes from neighbor\n")
12136
12137DEFUN (show_ip_bgp_neighbor_received_routes,
2a71e9ce 12138 show_ip_bgp_neighbor_received_routes_cmd,
a80beece 12139 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
2a71e9ce
TP
12140 SHOW_STR
12141 IP_STR
12142 BGP_STR
12143 "Detailed information on TCP and BGP neighbor connections\n"
12144 "Neighbor to display information about\n"
12145 "Neighbor to display information about\n"
a80beece 12146 "Neighbor on bgp configured interface\n"
2a71e9ce
TP
12147 "Display the received routes from neighbor\n")
12148
0b16f239
DS
12149{
12150 struct peer *peer;
ffd0c037 12151 const char *rmap_name = NULL;
0b16f239
DS
12152
12153 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12154
12155 if (! peer)
12156 return CMD_WARNING;
12157
12158 if (argc == 2)
12159 rmap_name = argv[1];
12160
b05a1c8b 12161 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name);
0b16f239
DS
12162}
12163
12164ALIAS (show_ip_bgp_neighbor_received_routes,
12165 show_ip_bgp_neighbor_received_routes_rmap_cmd,
12166 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
12167 SHOW_STR
12168 IP_STR
12169 BGP_STR
12170 "Detailed information on TCP and BGP neighbor connections\n"
12171 "Neighbor to display information about\n"
12172 "Neighbor to display information about\n"
12173 "Neighbor on bgp configured interface\n"
12174 "Display the received routes from neighbor\n")
12175
718e3744 12176DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12177 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
a80beece 12178 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12179 SHOW_STR
12180 IP_STR
12181 BGP_STR
12182 "Address family\n"
12183 "Address Family modifier\n"
12184 "Address Family modifier\n"
12185 "Detailed information on TCP and BGP neighbor connections\n"
12186 "Neighbor to display information about\n"
12187 "Neighbor to display information about\n"
a80beece 12188 "Neighbor on bgp configured interface\n"
718e3744 12189 "Display the received routes from neighbor\n")
12190{
bb46e94f 12191 struct peer *peer;
ffd0c037 12192 const char *rmap_name = NULL;
bb46e94f 12193
12194 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12195 if (! peer)
12196 return CMD_WARNING;
0b16f239
DS
12197
12198 if (argc == 3)
12199 rmap_name = argv[2];
12200
718e3744 12201 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 12202 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name);
718e3744 12203
b05a1c8b 12204 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name);
718e3744 12205}
12206
0b16f239
DS
12207ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
12208 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
12209 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
12210 SHOW_STR
12211 IP_STR
12212 BGP_STR
12213 "Address family\n"
12214 "Address Family modifier\n"
12215 "Address Family modifier\n"
12216 "Detailed information on TCP and BGP neighbor connections\n"
12217 "Neighbor to display information about\n"
12218 "Neighbor to display information about\n"
12219 "Neighbor on bgp configured interface\n"
12220 "Display the received routes from neighbor\n")
12221
95cbbd2a
ML
12222DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
12223 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
12224#ifdef HAVE_IPV6
a80beece 12225 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes)",
95cbbd2a 12226#else
a80beece 12227 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes)",
95cbbd2a
ML
12228#endif
12229 SHOW_STR
12230 BGP_STR
12231 "BGP view\n"
2b00515a 12232 "View name\n"
95cbbd2a
ML
12233 "Address family\n"
12234#ifdef HAVE_IPV6
12235 "Address family\n"
12236#endif
12237 "Address family modifier\n"
12238 "Address family modifier\n"
12239 "Detailed information on TCP and BGP neighbor connections\n"
12240 "Neighbor to display information about\n"
12241 "Neighbor to display information about\n"
a80beece 12242 "Neighbor on bgp configured interface\n"
95cbbd2a
ML
12243 "Display the advertised routes to neighbor\n"
12244 "Display the received routes from neighbor\n")
12245{
12246 int afi;
12247 int safi;
12248 int in;
12249 struct peer *peer;
12250
12251#ifdef HAVE_IPV6
12252 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
12253#else
12254 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12255#endif
12256
12257 if (! peer)
12258 return CMD_WARNING;
12259
12260#ifdef HAVE_IPV6
12261 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
12262 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12263 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
12264#else
12265 afi = AFI_IP;
12266 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12267 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
12268#endif
12269
b05a1c8b 12270 return peer_adj_routes (vty, peer, afi, safi, in, NULL);
95cbbd2a
ML
12271}
12272
718e3744 12273DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12274 show_ip_bgp_neighbor_received_prefix_filter_cmd,
a80beece 12275 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
718e3744 12276 SHOW_STR
12277 IP_STR
12278 BGP_STR
12279 "Detailed information on TCP and BGP neighbor connections\n"
12280 "Neighbor to display information about\n"
12281 "Neighbor to display information about\n"
a80beece 12282 "Neighbor on bgp configured interface\n"
718e3744 12283 "Display information received from a BGP neighbor\n"
12284 "Display the prefixlist filter\n")
12285{
12286 char name[BUFSIZ];
c63b83fe 12287 union sockunion su;
718e3744 12288 struct peer *peer;
c63b83fe 12289 int count, ret;
718e3744 12290
c63b83fe
JBD
12291 ret = str2sockunion (argv[0], &su);
12292 if (ret < 0)
12293 {
a80beece
DS
12294 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12295 if (!peer)
12296 {
12297 vty_out (vty, "Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12298 return CMD_WARNING;
12299 }
12300 }
12301 else
12302 {
12303 peer = peer_lookup (NULL, &su);
12304 if (! peer)
12305 return CMD_WARNING;
c63b83fe 12306 }
718e3744 12307
12308 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12309 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
12310 if (count)
12311 {
12312 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
12313 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
12314 }
12315
12316 return CMD_SUCCESS;
12317}
12318
12319DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
12320 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
a80beece 12321 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
718e3744 12322 SHOW_STR
12323 IP_STR
12324 BGP_STR
12325 "Address family\n"
12326 "Address Family modifier\n"
12327 "Address Family modifier\n"
12328 "Detailed information on TCP and BGP neighbor connections\n"
12329 "Neighbor to display information about\n"
12330 "Neighbor to display information about\n"
a80beece 12331 "Neighbor on bgp configured interface\n"
718e3744 12332 "Display information received from a BGP neighbor\n"
12333 "Display the prefixlist filter\n")
12334{
12335 char name[BUFSIZ];
c63b83fe 12336 union sockunion su;
718e3744 12337 struct peer *peer;
c63b83fe 12338 int count, ret;
718e3744 12339
c63b83fe
JBD
12340 ret = str2sockunion (argv[1], &su);
12341 if (ret < 0)
12342 {
a80beece
DS
12343 peer = peer_lookup_by_conf_if (NULL, argv[1]);
12344 if (!peer)
12345 {
12346 vty_out (vty, "Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
12347 return CMD_WARNING;
12348 }
12349 }
12350 else
12351 {
12352 peer = peer_lookup (NULL, &su);
12353 if (! peer)
12354 return CMD_WARNING;
c63b83fe 12355 }
718e3744 12356
12357 if (strncmp (argv[0], "m", 1) == 0)
12358 {
12359 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
12360 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
12361 if (count)
12362 {
12363 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
12364 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
12365 }
12366 }
12367 else
12368 {
12369 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12370 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
12371 if (count)
12372 {
12373 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
12374 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
12375 }
12376 }
12377
12378 return CMD_SUCCESS;
12379}
12380
12381
12382#ifdef HAVE_IPV6
bb46e94f 12383ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 12384 show_bgp_neighbor_received_routes_cmd,
a80beece 12385 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12386 SHOW_STR
12387 BGP_STR
12388 "Detailed information on TCP and BGP neighbor connections\n"
12389 "Neighbor to display information about\n"
12390 "Neighbor to display information about\n"
a80beece 12391 "Neighbor on bgp configured interface\n"
718e3744 12392 "Display the received routes from neighbor\n")
718e3744 12393
bb46e94f 12394ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 12395 show_bgp_ipv6_neighbor_received_routes_cmd,
a80beece 12396 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12397 SHOW_STR
12398 BGP_STR
12399 "Address family\n"
12400 "Detailed information on TCP and BGP neighbor connections\n"
12401 "Neighbor to display information about\n"
12402 "Neighbor to display information about\n"
a80beece 12403 "Neighbor on bgp configured interface\n"
718e3744 12404 "Display the received routes from neighbor\n")
12405
0b16f239
DS
12406ALIAS (show_bgp_view_neighbor_received_routes,
12407 show_bgp_neighbor_received_routes_rmap_cmd,
12408 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
12409 SHOW_STR
12410 BGP_STR
12411 "Detailed information on TCP and BGP neighbor connections\n"
12412 "Neighbor to display information about\n"
12413 "Neighbor to display information about\n"
12414 "Neighbor on bgp configured interface\n"
12415 "Display the received routes from neighbor\n")
12416
12417ALIAS (show_bgp_view_neighbor_received_routes,
12418 show_bgp_ipv6_neighbor_received_routes_rmap_cmd,
12419 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
12420 SHOW_STR
12421 BGP_STR
12422 "Address family\n"
12423 "Detailed information on TCP and BGP neighbor connections\n"
12424 "Neighbor to display information about\n"
12425 "Neighbor to display information about\n"
12426 "Neighbor on bgp configured interface\n"
12427 "Display the received routes from neighbor\n")
12428
718e3744 12429DEFUN (show_bgp_neighbor_received_prefix_filter,
12430 show_bgp_neighbor_received_prefix_filter_cmd,
a80beece 12431 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
718e3744 12432 SHOW_STR
12433 BGP_STR
12434 "Detailed information on TCP and BGP neighbor connections\n"
12435 "Neighbor to display information about\n"
12436 "Neighbor to display information about\n"
a80beece 12437 "Neighbor on bgp configured interface\n"
718e3744 12438 "Display information received from a BGP neighbor\n"
12439 "Display the prefixlist filter\n")
12440{
12441 char name[BUFSIZ];
c63b83fe 12442 union sockunion su;
718e3744 12443 struct peer *peer;
c63b83fe 12444 int count, ret;
718e3744 12445
c63b83fe
JBD
12446 ret = str2sockunion (argv[0], &su);
12447 if (ret < 0)
12448 {
a80beece
DS
12449 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12450 if (!peer)
12451 {
12452 vty_out (vty, "Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12453 return CMD_WARNING;
12454 }
12455 }
12456 else
12457 {
12458 peer = peer_lookup (NULL, &su);
12459 if (! peer)
12460 return CMD_WARNING;
c63b83fe 12461 }
718e3744 12462
12463 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12464 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12465 if (count)
12466 {
12467 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12468 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12469 }
12470
12471 return CMD_SUCCESS;
12472}
12473
12474ALIAS (show_bgp_neighbor_received_prefix_filter,
12475 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
a80beece 12476 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
718e3744 12477 SHOW_STR
12478 BGP_STR
12479 "Address family\n"
12480 "Detailed information on TCP and BGP neighbor connections\n"
12481 "Neighbor to display information about\n"
12482 "Neighbor to display information about\n"
a80beece 12483 "Neighbor on bgp configured interface\n"
718e3744 12484 "Display information received from a BGP neighbor\n"
12485 "Display the prefixlist filter\n")
12486
12487/* old command */
bb46e94f 12488ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 12489 ipv6_bgp_neighbor_received_routes_cmd,
a80beece 12490 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12491 SHOW_STR
12492 IPV6_STR
12493 BGP_STR
12494 "Detailed information on TCP and BGP neighbor connections\n"
12495 "Neighbor to display information about\n"
12496 "Neighbor to display information about\n"
a80beece 12497 "Neighbor on bgp configured interface\n"
718e3744 12498 "Display the received routes from neighbor\n")
718e3744 12499
12500/* old command */
12501DEFUN (ipv6_mbgp_neighbor_received_routes,
12502 ipv6_mbgp_neighbor_received_routes_cmd,
a80beece 12503 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12504 SHOW_STR
12505 IPV6_STR
12506 MBGP_STR
12507 "Detailed information on TCP and BGP neighbor connections\n"
12508 "Neighbor to display information about\n"
12509 "Neighbor to display information about\n"
a80beece 12510 "Neighbor on bgp configured interface\n"
718e3744 12511 "Display the received routes from neighbor\n")
12512{
bb46e94f 12513 struct peer *peer;
12514
12515 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12516 if (! peer)
12517 return CMD_WARNING;
12518
b05a1c8b 12519 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL);
bb46e94f 12520}
12521
12522DEFUN (show_bgp_view_neighbor_received_prefix_filter,
12523 show_bgp_view_neighbor_received_prefix_filter_cmd,
a80beece 12524 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
bb46e94f 12525 SHOW_STR
12526 BGP_STR
12527 "BGP view\n"
12528 "View name\n"
12529 "Detailed information on TCP and BGP neighbor connections\n"
12530 "Neighbor to display information about\n"
12531 "Neighbor to display information about\n"
a80beece 12532 "Neighbor on bgp configured interface\n"
bb46e94f 12533 "Display information received from a BGP neighbor\n"
12534 "Display the prefixlist filter\n")
12535{
12536 char name[BUFSIZ];
c63b83fe 12537 union sockunion su;
bb46e94f 12538 struct peer *peer;
12539 struct bgp *bgp;
c63b83fe 12540 int count, ret;
bb46e94f 12541
12542 /* BGP structure lookup. */
12543 bgp = bgp_lookup_by_name (argv[0]);
12544 if (bgp == NULL)
12545 {
12546 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12547 return CMD_WARNING;
12548 }
12549
c63b83fe
JBD
12550 ret = str2sockunion (argv[1], &su);
12551 if (ret < 0)
12552 {
a80beece
DS
12553 peer = peer_lookup_by_conf_if (bgp, argv[1]);
12554 if (!peer)
12555 {
12556 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
12557 return CMD_WARNING;
12558 }
12559 }
12560 else
12561 {
12562 peer = peer_lookup (bgp, &su);
12563 if (! peer)
12564 return CMD_WARNING;
c63b83fe 12565 }
bb46e94f 12566
12567 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12568 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12569 if (count)
12570 {
12571 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12572 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12573 }
12574
12575 return CMD_SUCCESS;
718e3744 12576}
bb46e94f 12577
12578ALIAS (show_bgp_view_neighbor_received_prefix_filter,
12579 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
a80beece 12580 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
bb46e94f 12581 SHOW_STR
12582 BGP_STR
12583 "BGP view\n"
12584 "View name\n"
12585 "Address family\n"
12586 "Detailed information on TCP and BGP neighbor connections\n"
12587 "Neighbor to display information about\n"
12588 "Neighbor to display information about\n"
a80beece 12589 "Neighbor on bgp configured interface\n"
bb46e94f 12590 "Display information received from a BGP neighbor\n"
12591 "Display the prefixlist filter\n")
718e3744 12592#endif /* HAVE_IPV6 */
6b0655a2 12593
94f2b392 12594static int
bb46e94f 12595bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
b05a1c8b 12596 safi_t safi, enum bgp_show_type type)
718e3744 12597{
718e3744 12598 if (! peer || ! peer->afc[afi][safi])
12599 {
12600 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
718e3744 12601 return CMD_WARNING;
12602 }
47fc97cc 12603
b05a1c8b 12604 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, 0);
718e3744 12605}
12606
12607DEFUN (show_ip_bgp_neighbor_routes,
12608 show_ip_bgp_neighbor_routes_cmd,
a80beece 12609 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 12610 SHOW_STR
12611 IP_STR
12612 BGP_STR
12613 "Detailed information on TCP and BGP neighbor connections\n"
12614 "Neighbor to display information about\n"
12615 "Neighbor to display information about\n"
a80beece 12616 "Neighbor on bgp configured interface\n"
718e3744 12617 "Display routes learned from neighbor\n")
12618{
bb46e94f 12619 struct peer *peer;
12620
12621 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12622 if (! peer)
12623 return CMD_WARNING;
12624
12625 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
b05a1c8b 12626 bgp_show_type_neighbor);
718e3744 12627}
12628
12629DEFUN (show_ip_bgp_neighbor_flap,
12630 show_ip_bgp_neighbor_flap_cmd,
a80beece 12631 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
718e3744 12632 SHOW_STR
12633 IP_STR
12634 BGP_STR
12635 "Detailed information on TCP and BGP neighbor connections\n"
12636 "Neighbor to display information about\n"
12637 "Neighbor to display information about\n"
a80beece 12638 "Neighbor on bgp configured interface\n"
718e3744 12639 "Display flap statistics of the routes learned from neighbor\n")
12640{
bb46e94f 12641 struct peer *peer;
12642
12643 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12644 if (! peer)
12645 return CMD_WARNING;
12646
12647 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
b05a1c8b 12648 bgp_show_type_flap_neighbor);
718e3744 12649}
12650
12651DEFUN (show_ip_bgp_neighbor_damp,
12652 show_ip_bgp_neighbor_damp_cmd,
a80beece 12653 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
718e3744 12654 SHOW_STR
12655 IP_STR
12656 BGP_STR
12657 "Detailed information on TCP and BGP neighbor connections\n"
12658 "Neighbor to display information about\n"
12659 "Neighbor to display information about\n"
a80beece 12660 "Neighbor on bgp configured interface\n"
718e3744 12661 "Display the dampened routes received from neighbor\n")
12662{
bb46e94f 12663 struct peer *peer;
12664
12665 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12666 if (! peer)
12667 return CMD_WARNING;
12668
12669 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
b05a1c8b 12670 bgp_show_type_damp_neighbor);
718e3744 12671}
12672
12673DEFUN (show_ip_bgp_ipv4_neighbor_routes,
12674 show_ip_bgp_ipv4_neighbor_routes_cmd,
a80beece 12675 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 12676 SHOW_STR
12677 IP_STR
12678 BGP_STR
12679 "Address family\n"
12680 "Address Family modifier\n"
12681 "Address Family modifier\n"
12682 "Detailed information on TCP and BGP neighbor connections\n"
12683 "Neighbor to display information about\n"
12684 "Neighbor to display information about\n"
a80beece 12685 "Neighbor on bgp configured interface\n"
718e3744 12686 "Display routes learned from neighbor\n")
12687{
bb46e94f 12688 struct peer *peer;
12689
12690 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12691 if (! peer)
12692 return CMD_WARNING;
12693
718e3744 12694 if (strncmp (argv[0], "m", 1) == 0)
bb46e94f 12695 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
b05a1c8b 12696 bgp_show_type_neighbor);
718e3744 12697
bb46e94f 12698 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
b05a1c8b 12699 bgp_show_type_neighbor);
718e3744 12700}
bb46e94f 12701
fee0f4c6 12702DEFUN (show_ip_bgp_view_rsclient,
12703 show_ip_bgp_view_rsclient_cmd,
a80beece 12704 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 12705 SHOW_STR
12706 IP_STR
12707 BGP_STR
12708 "BGP view\n"
2b00515a 12709 "View name\n"
fee0f4c6 12710 "Information about Route Server Client\n"
a80beece 12711 NEIGHBOR_ADDR_STR3)
fee0f4c6 12712{
12713 struct bgp_table *table;
12714 struct peer *peer;
12715
12716 if (argc == 2)
12717 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12718 else
12719 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12720
12721 if (! peer)
12722 return CMD_WARNING;
12723
12724 if (! peer->afc[AFI_IP][SAFI_UNICAST])
12725 {
12726 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12727 VTY_NEWLINE);
12728 return CMD_WARNING;
12729 }
12730
12731 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
12732 PEER_FLAG_RSERVER_CLIENT))
12733 {
12734 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12735 VTY_NEWLINE);
12736 return CMD_WARNING;
12737 }
12738
12739 table = peer->rib[AFI_IP][SAFI_UNICAST];
12740
47fc97cc 12741 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
b05a1c8b 12742 NULL, 0);
fee0f4c6 12743}
12744
12745ALIAS (show_ip_bgp_view_rsclient,
12746 show_ip_bgp_rsclient_cmd,
a80beece 12747 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 12748 SHOW_STR
12749 IP_STR
12750 BGP_STR
12751 "Information about Route Server Client\n"
a80beece 12752 NEIGHBOR_ADDR_STR3)
fee0f4c6 12753
95cbbd2a
ML
12754DEFUN (show_bgp_view_ipv4_safi_rsclient,
12755 show_bgp_view_ipv4_safi_rsclient_cmd,
a80beece 12756 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 12757 SHOW_STR
fee0f4c6 12758 BGP_STR
12759 "BGP view\n"
2b00515a 12760 "View name\n"
95cbbd2a
ML
12761 "Address family\n"
12762 "Address Family modifier\n"
12763 "Address Family modifier\n"
fee0f4c6 12764 "Information about Route Server Client\n"
a80beece 12765 NEIGHBOR_ADDR_STR3)
fee0f4c6 12766{
95cbbd2a 12767 struct bgp_table *table;
fee0f4c6 12768 struct peer *peer;
95cbbd2a 12769 safi_t safi;
fee0f4c6 12770
95cbbd2a
ML
12771 if (argc == 3) {
12772 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12773 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12774 } else {
12775 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12776 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12777 }
12778
12779 if (! peer)
12780 return CMD_WARNING;
12781
12782 if (! peer->afc[AFI_IP][safi])
fee0f4c6 12783 {
95cbbd2a
ML
12784 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12785 VTY_NEWLINE);
12786 return CMD_WARNING;
12787 }
12788
12789 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
12790 PEER_FLAG_RSERVER_CLIENT))
12791 {
12792 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12793 VTY_NEWLINE);
12794 return CMD_WARNING;
12795 }
12796
12797 table = peer->rib[AFI_IP][safi];
12798
47fc97cc 12799 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
b05a1c8b 12800 NULL, 0);
95cbbd2a
ML
12801}
12802
12803ALIAS (show_bgp_view_ipv4_safi_rsclient,
12804 show_bgp_ipv4_safi_rsclient_cmd,
a80beece 12805 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
95cbbd2a
ML
12806 SHOW_STR
12807 BGP_STR
12808 "Address family\n"
12809 "Address Family modifier\n"
12810 "Address Family modifier\n"
12811 "Information about Route Server Client\n"
a80beece 12812 NEIGHBOR_ADDR_STR3)
95cbbd2a
ML
12813
12814DEFUN (show_ip_bgp_view_rsclient_route,
12815 show_ip_bgp_view_rsclient_route_cmd,
a80beece 12816 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
95cbbd2a
ML
12817 SHOW_STR
12818 IP_STR
12819 BGP_STR
12820 "BGP view\n"
2b00515a 12821 "View name\n"
95cbbd2a 12822 "Information about Route Server Client\n"
a80beece 12823 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
12824 "Network in the BGP routing table to display\n")
12825{
12826 struct bgp *bgp;
12827 struct peer *peer;
12828
12829 /* BGP structure lookup. */
12830 if (argc == 3)
12831 {
12832 bgp = bgp_lookup_by_name (argv[0]);
12833 if (bgp == NULL)
12834 {
12835 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12836 return CMD_WARNING;
fee0f4c6 12837 }
12838 }
12839 else
12840 {
12841 bgp = bgp_get_default ();
12842 if (bgp == NULL)
12843 {
12844 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12845 return CMD_WARNING;
12846 }
12847 }
12848
12849 if (argc == 3)
12850 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12851 else
12852 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12853
12854 if (! peer)
12855 return CMD_WARNING;
12856
12857 if (! peer->afc[AFI_IP][SAFI_UNICAST])
12858 {
12859 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12860 VTY_NEWLINE);
12861 return CMD_WARNING;
b05a1c8b 12862 }
fee0f4c6 12863
12864 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
12865 PEER_FLAG_RSERVER_CLIENT))
12866 {
12867 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12868 VTY_NEWLINE);
12869 return CMD_WARNING;
12870 }
12871
12872 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
12873 (argc == 3) ? argv[2] : argv[1],
b05a1c8b 12874 AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, 0);
fee0f4c6 12875}
12876
12877ALIAS (show_ip_bgp_view_rsclient_route,
12878 show_ip_bgp_rsclient_route_cmd,
a80beece 12879 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
fee0f4c6 12880 SHOW_STR
12881 IP_STR
12882 BGP_STR
12883 "Information about Route Server Client\n"
a80beece 12884 NEIGHBOR_ADDR_STR3
fee0f4c6 12885 "Network in the BGP routing table to display\n")
12886
95cbbd2a
ML
12887DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
12888 show_bgp_view_ipv4_safi_rsclient_route_cmd,
a80beece 12889 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
95cbbd2a
ML
12890 SHOW_STR
12891 BGP_STR
12892 "BGP view\n"
2b00515a 12893 "View name\n"
95cbbd2a
ML
12894 "Address family\n"
12895 "Address Family modifier\n"
12896 "Address Family modifier\n"
12897 "Information about Route Server Client\n"
a80beece 12898 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
12899 "Network in the BGP routing table to display\n")
12900{
12901 struct bgp *bgp;
12902 struct peer *peer;
12903 safi_t safi;
12904
12905 /* BGP structure lookup. */
12906 if (argc == 4)
12907 {
12908 bgp = bgp_lookup_by_name (argv[0]);
12909 if (bgp == NULL)
12910 {
12911 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12912 return CMD_WARNING;
12913 }
12914 }
12915 else
12916 {
12917 bgp = bgp_get_default ();
12918 if (bgp == NULL)
12919 {
12920 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12921 return CMD_WARNING;
12922 }
12923 }
12924
12925 if (argc == 4) {
12926 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12927 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12928 } else {
12929 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12930 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12931 }
12932
12933 if (! peer)
12934 return CMD_WARNING;
12935
12936 if (! peer->afc[AFI_IP][safi])
12937 {
12938 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12939 VTY_NEWLINE);
12940 return CMD_WARNING;
12941}
12942
12943 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
12944 PEER_FLAG_RSERVER_CLIENT))
12945 {
12946 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12947 VTY_NEWLINE);
12948 return CMD_WARNING;
12949 }
12950
12951 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
12952 (argc == 4) ? argv[3] : argv[2],
b05a1c8b 12953 AFI_IP, safi, NULL, 0, BGP_PATH_ALL, 0);
95cbbd2a
ML
12954}
12955
12956ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
12957 show_bgp_ipv4_safi_rsclient_route_cmd,
a80beece 12958 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
95cbbd2a
ML
12959 SHOW_STR
12960 BGP_STR
12961 "Address family\n"
12962 "Address Family modifier\n"
12963 "Address Family modifier\n"
12964 "Information about Route Server Client\n"
a80beece 12965 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
12966 "Network in the BGP routing table to display\n")
12967
fee0f4c6 12968DEFUN (show_ip_bgp_view_rsclient_prefix,
12969 show_ip_bgp_view_rsclient_prefix_cmd,
a80beece 12970 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
fee0f4c6 12971 SHOW_STR
12972 IP_STR
12973 BGP_STR
12974 "BGP view\n"
2b00515a 12975 "View name\n"
fee0f4c6 12976 "Information about Route Server Client\n"
a80beece 12977 NEIGHBOR_ADDR_STR3
fee0f4c6 12978 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12979{
12980 struct bgp *bgp;
12981 struct peer *peer;
12982
12983 /* BGP structure lookup. */
12984 if (argc == 3)
12985 {
12986 bgp = bgp_lookup_by_name (argv[0]);
12987 if (bgp == NULL)
12988 {
12989 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12990 return CMD_WARNING;
12991 }
12992 }
12993 else
12994 {
12995 bgp = bgp_get_default ();
12996 if (bgp == NULL)
12997 {
12998 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12999 return CMD_WARNING;
13000 }
13001 }
13002
13003 if (argc == 3)
13004 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13005 else
13006 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13007
13008 if (! peer)
13009 return CMD_WARNING;
13010
13011 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13012 {
13013 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13014 VTY_NEWLINE);
13015 return CMD_WARNING;
13016}
13017
13018 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13019 PEER_FLAG_RSERVER_CLIENT))
13020{
13021 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13022 VTY_NEWLINE);
13023 return CMD_WARNING;
13024 }
13025
13026 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13027 (argc == 3) ? argv[2] : argv[1],
b05a1c8b 13028 AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, 0);
fee0f4c6 13029}
13030
13031ALIAS (show_ip_bgp_view_rsclient_prefix,
13032 show_ip_bgp_rsclient_prefix_cmd,
a80beece 13033 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
fee0f4c6 13034 SHOW_STR
13035 IP_STR
13036 BGP_STR
13037 "Information about Route Server Client\n"
a80beece 13038 NEIGHBOR_ADDR_STR3
fee0f4c6 13039 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13040
95cbbd2a
ML
13041DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
13042 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
a80beece 13043 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
95cbbd2a
ML
13044 SHOW_STR
13045 BGP_STR
13046 "BGP view\n"
2b00515a 13047 "View name\n"
95cbbd2a
ML
13048 "Address family\n"
13049 "Address Family modifier\n"
13050 "Address Family modifier\n"
13051 "Information about Route Server Client\n"
a80beece 13052 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13053 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13054{
13055 struct bgp *bgp;
13056 struct peer *peer;
13057 safi_t safi;
13058
13059 /* BGP structure lookup. */
13060 if (argc == 4)
13061 {
13062 bgp = bgp_lookup_by_name (argv[0]);
13063 if (bgp == NULL)
13064 {
13065 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13066 return CMD_WARNING;
13067 }
13068 }
13069 else
13070 {
13071 bgp = bgp_get_default ();
13072 if (bgp == NULL)
13073 {
13074 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13075 return CMD_WARNING;
13076 }
13077 }
13078
13079 if (argc == 4) {
13080 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13081 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13082 } else {
13083 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13084 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13085 }
13086
13087 if (! peer)
13088 return CMD_WARNING;
13089
13090 if (! peer->afc[AFI_IP][safi])
13091 {
13092 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13093 VTY_NEWLINE);
13094 return CMD_WARNING;
13095}
13096
13097 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13098 PEER_FLAG_RSERVER_CLIENT))
13099{
13100 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13101 VTY_NEWLINE);
13102 return CMD_WARNING;
13103 }
13104
13105 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
13106 (argc == 4) ? argv[3] : argv[2],
b05a1c8b 13107 AFI_IP, safi, NULL, 1, BGP_PATH_ALL, 0);
95cbbd2a
ML
13108}
13109
13110ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
13111 show_bgp_ipv4_safi_rsclient_prefix_cmd,
a80beece 13112 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
95cbbd2a
ML
13113 SHOW_STR
13114 BGP_STR
13115 "Address family\n"
13116 "Address Family modifier\n"
13117 "Address Family modifier\n"
13118 "Information about Route Server Client\n"
a80beece 13119 NEIGHBOR_ADDR_STR3
95cbbd2a 13120 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
fee0f4c6 13121
718e3744 13122#ifdef HAVE_IPV6
bb46e94f 13123DEFUN (show_bgp_view_neighbor_routes,
13124 show_bgp_view_neighbor_routes_cmd,
a80beece 13125 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 13126 SHOW_STR
13127 BGP_STR
bb46e94f 13128 "BGP view\n"
2b00515a 13129 "View name\n"
718e3744 13130 "Detailed information on TCP and BGP neighbor connections\n"
13131 "Neighbor to display information about\n"
13132 "Neighbor to display information about\n"
a80beece 13133 "Neighbor on bgp configured interface\n"
718e3744 13134 "Display routes learned from neighbor\n")
13135{
bb46e94f 13136 struct peer *peer;
13137
13138 if (argc == 2)
13139 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13140 else
13141 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13142
13143 if (! peer)
13144 return CMD_WARNING;
13145
13146 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
b05a1c8b 13147 bgp_show_type_neighbor);
718e3744 13148}
13149
bb46e94f 13150ALIAS (show_bgp_view_neighbor_routes,
13151 show_bgp_view_ipv6_neighbor_routes_cmd,
a80beece 13152 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes",
bb46e94f 13153 SHOW_STR
13154 BGP_STR
13155 "BGP view\n"
2b00515a 13156 "View name\n"
bb46e94f 13157 "Address family\n"
13158 "Detailed information on TCP and BGP neighbor connections\n"
13159 "Neighbor to display information about\n"
13160 "Neighbor to display information about\n"
a80beece 13161 "Neighbor on bgp configured interface\n"
bb46e94f 13162 "Display routes learned from neighbor\n")
13163
13164DEFUN (show_bgp_view_neighbor_damp,
13165 show_bgp_view_neighbor_damp_cmd,
a80beece 13166 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
bb46e94f 13167 SHOW_STR
13168 BGP_STR
13169 "BGP view\n"
2b00515a 13170 "View name\n"
bb46e94f 13171 "Detailed information on TCP and BGP neighbor connections\n"
13172 "Neighbor to display information about\n"
13173 "Neighbor to display information about\n"
a80beece 13174 "Neighbor on bgp configured interface\n"
bb46e94f 13175 "Display the dampened routes received from neighbor\n")
13176{
13177 struct peer *peer;
13178
13179 if (argc == 2)
13180 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13181 else
13182 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13183
13184 if (! peer)
13185 return CMD_WARNING;
13186
13187 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
b05a1c8b 13188 bgp_show_type_damp_neighbor);
bb46e94f 13189}
13190
13191ALIAS (show_bgp_view_neighbor_damp,
13192 show_bgp_view_ipv6_neighbor_damp_cmd,
a80beece 13193 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
bb46e94f 13194 SHOW_STR
13195 BGP_STR
13196 "BGP view\n"
2b00515a 13197 "View name\n"
bb46e94f 13198 "Address family\n"
13199 "Detailed information on TCP and BGP neighbor connections\n"
13200 "Neighbor to display information about\n"
13201 "Neighbor to display information about\n"
a80beece 13202 "Neighbor on bgp configured interface\n"
bb46e94f 13203 "Display the dampened routes received from neighbor\n")
13204
13205DEFUN (show_bgp_view_neighbor_flap,
13206 show_bgp_view_neighbor_flap_cmd,
a80beece 13207 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
bb46e94f 13208 SHOW_STR
13209 BGP_STR
13210 "BGP view\n"
2b00515a 13211 "View name\n"
bb46e94f 13212 "Detailed information on TCP and BGP neighbor connections\n"
13213 "Neighbor to display information about\n"
13214 "Neighbor to display information about\n"
a80beece 13215 "Neighbor on bgp configured interface\n"
bb46e94f 13216 "Display flap statistics of the routes learned from neighbor\n")
13217{
13218 struct peer *peer;
13219
13220 if (argc == 2)
13221 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13222 else
13223 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13224
13225 if (! peer)
13226 return CMD_WARNING;
13227
13228 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
b05a1c8b 13229 bgp_show_type_flap_neighbor);
bb46e94f 13230}
13231
13232ALIAS (show_bgp_view_neighbor_flap,
13233 show_bgp_view_ipv6_neighbor_flap_cmd,
a80beece 13234 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
bb46e94f 13235 SHOW_STR
13236 BGP_STR
13237 "BGP view\n"
2b00515a 13238 "View name\n"
bb46e94f 13239 "Address family\n"
13240 "Detailed information on TCP and BGP neighbor connections\n"
13241 "Neighbor to display information about\n"
13242 "Neighbor to display information about\n"
a80beece 13243 "Neighbor on bgp configured interface\n"
bb46e94f 13244 "Display flap statistics of the routes learned from neighbor\n")
13245
13246ALIAS (show_bgp_view_neighbor_routes,
13247 show_bgp_neighbor_routes_cmd,
a80beece 13248 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
bb46e94f 13249 SHOW_STR
13250 BGP_STR
13251 "Detailed information on TCP and BGP neighbor connections\n"
13252 "Neighbor to display information about\n"
13253 "Neighbor to display information about\n"
a80beece 13254 "Neighbor on bgp configured interface\n"
bb46e94f 13255 "Display routes learned from neighbor\n")
13256
13257
13258ALIAS (show_bgp_view_neighbor_routes,
718e3744 13259 show_bgp_ipv6_neighbor_routes_cmd,
a80beece 13260 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 13261 SHOW_STR
13262 BGP_STR
13263 "Address family\n"
13264 "Detailed information on TCP and BGP neighbor connections\n"
13265 "Neighbor to display information about\n"
13266 "Neighbor to display information about\n"
a80beece 13267 "Neighbor on bgp configured interface\n"
718e3744 13268 "Display routes learned from neighbor\n")
13269
13270/* old command */
bb46e94f 13271ALIAS (show_bgp_view_neighbor_routes,
718e3744 13272 ipv6_bgp_neighbor_routes_cmd,
a80beece 13273 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 13274 SHOW_STR
13275 IPV6_STR
13276 BGP_STR
13277 "Detailed information on TCP and BGP neighbor connections\n"
13278 "Neighbor to display information about\n"
13279 "Neighbor to display information about\n"
a80beece 13280 "Neighbor on bgp configured interface\n"
718e3744 13281 "Display routes learned from neighbor\n")
718e3744 13282
13283/* old command */
13284DEFUN (ipv6_mbgp_neighbor_routes,
13285 ipv6_mbgp_neighbor_routes_cmd,
a80beece 13286 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 13287 SHOW_STR
13288 IPV6_STR
13289 MBGP_STR
13290 "Detailed information on TCP and BGP neighbor connections\n"
13291 "Neighbor to display information about\n"
13292 "Neighbor to display information about\n"
a80beece 13293 "Neighbor on bgp configured interface\n"
718e3744 13294 "Display routes learned from neighbor\n")
13295{
bb46e94f 13296 struct peer *peer;
13297
13298 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13299 if (! peer)
13300 return CMD_WARNING;
13301
13302 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
b05a1c8b 13303 bgp_show_type_neighbor);
718e3744 13304}
bb46e94f 13305
13306ALIAS (show_bgp_view_neighbor_flap,
13307 show_bgp_neighbor_flap_cmd,
a80beece 13308 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
bb46e94f 13309 SHOW_STR
13310 BGP_STR
13311 "Detailed information on TCP and BGP neighbor connections\n"
13312 "Neighbor to display information about\n"
13313 "Neighbor to display information about\n"
a80beece 13314 "Neighbor on bgp configured interface\n"
bb46e94f 13315 "Display flap statistics of the routes learned from neighbor\n")
13316
13317ALIAS (show_bgp_view_neighbor_flap,
13318 show_bgp_ipv6_neighbor_flap_cmd,
a80beece 13319 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
bb46e94f 13320 SHOW_STR
13321 BGP_STR
13322 "Address family\n"
13323 "Detailed information on TCP and BGP neighbor connections\n"
13324 "Neighbor to display information about\n"
13325 "Neighbor to display information about\n"
a80beece 13326 "Neighbor on bgp configured interface\n"
bb46e94f 13327 "Display flap statistics of the routes learned from neighbor\n")
13328
13329ALIAS (show_bgp_view_neighbor_damp,
13330 show_bgp_neighbor_damp_cmd,
a80beece 13331 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
bb46e94f 13332 SHOW_STR
13333 BGP_STR
13334 "Detailed information on TCP and BGP neighbor connections\n"
13335 "Neighbor to display information about\n"
13336 "Neighbor to display information about\n"
a80beece 13337 "Neighbor on bgp configured interface\n"
bb46e94f 13338 "Display the dampened routes received from neighbor\n")
13339
13340ALIAS (show_bgp_view_neighbor_damp,
13341 show_bgp_ipv6_neighbor_damp_cmd,
a80beece 13342 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
bb46e94f 13343 SHOW_STR
13344 BGP_STR
13345 "Address family\n"
13346 "Detailed information on TCP and BGP neighbor connections\n"
13347 "Neighbor to display information about\n"
13348 "Neighbor to display information about\n"
a80beece 13349 "Neighbor on bgp configured interface\n"
c001ae62 13350 "Display the dampened routes received from neighbor\n")
fee0f4c6 13351
13352DEFUN (show_bgp_view_rsclient,
13353 show_bgp_view_rsclient_cmd,
a80beece 13354 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 13355 SHOW_STR
13356 BGP_STR
13357 "BGP view\n"
2b00515a 13358 "View name\n"
fee0f4c6 13359 "Information about Route Server Client\n"
a80beece 13360 NEIGHBOR_ADDR_STR3)
fee0f4c6 13361{
13362 struct bgp_table *table;
13363 struct peer *peer;
13364
13365 if (argc == 2)
13366 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13367 else
13368 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13369
13370 if (! peer)
13371 return CMD_WARNING;
13372
13373 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
13374 {
13375 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13376 VTY_NEWLINE);
13377 return CMD_WARNING;
13378 }
13379
13380 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
13381 PEER_FLAG_RSERVER_CLIENT))
13382 {
13383 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13384 VTY_NEWLINE);
13385 return CMD_WARNING;
13386 }
13387
13388 table = peer->rib[AFI_IP6][SAFI_UNICAST];
13389
47fc97cc 13390 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
b05a1c8b 13391 NULL, 0);
fee0f4c6 13392}
13393
13394ALIAS (show_bgp_view_rsclient,
13395 show_bgp_rsclient_cmd,
a80beece 13396 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 13397 SHOW_STR
13398 BGP_STR
13399 "Information about Route Server Client\n"
a80beece 13400 NEIGHBOR_ADDR_STR3)
fee0f4c6 13401
95cbbd2a
ML
13402DEFUN (show_bgp_view_ipv6_safi_rsclient,
13403 show_bgp_view_ipv6_safi_rsclient_cmd,
a80beece 13404 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
95cbbd2a
ML
13405 SHOW_STR
13406 BGP_STR
13407 "BGP view\n"
2b00515a 13408 "View name\n"
95cbbd2a
ML
13409 "Address family\n"
13410 "Address Family modifier\n"
13411 "Address Family modifier\n"
13412 "Information about Route Server Client\n"
a80beece 13413 NEIGHBOR_ADDR_STR3)
95cbbd2a
ML
13414{
13415 struct bgp_table *table;
13416 struct peer *peer;
13417 safi_t safi;
13418
13419 if (argc == 3) {
13420 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13421 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13422 } else {
13423 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13424 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13425 }
13426
13427 if (! peer)
13428 return CMD_WARNING;
13429
13430 if (! peer->afc[AFI_IP6][safi])
13431 {
13432 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13433 VTY_NEWLINE);
13434 return CMD_WARNING;
13435 }
13436
13437 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
13438 PEER_FLAG_RSERVER_CLIENT))
13439 {
13440 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13441 VTY_NEWLINE);
13442 return CMD_WARNING;
13443 }
13444
13445 table = peer->rib[AFI_IP6][safi];
13446
47fc97cc 13447 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
b05a1c8b 13448 NULL, 0);
95cbbd2a
ML
13449}
13450
13451ALIAS (show_bgp_view_ipv6_safi_rsclient,
13452 show_bgp_ipv6_safi_rsclient_cmd,
a80beece 13453 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
95cbbd2a
ML
13454 SHOW_STR
13455 BGP_STR
13456 "Address family\n"
13457 "Address Family modifier\n"
13458 "Address Family modifier\n"
13459 "Information about Route Server Client\n"
a80beece 13460 NEIGHBOR_ADDR_STR3)
95cbbd2a 13461
fee0f4c6 13462DEFUN (show_bgp_view_rsclient_route,
13463 show_bgp_view_rsclient_route_cmd,
a80beece 13464 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
fee0f4c6 13465 SHOW_STR
13466 BGP_STR
13467 "BGP view\n"
2b00515a 13468 "View name\n"
fee0f4c6 13469 "Information about Route Server Client\n"
a80beece 13470 NEIGHBOR_ADDR_STR3
fee0f4c6 13471 "Network in the BGP routing table to display\n")
13472{
13473 struct bgp *bgp;
13474 struct peer *peer;
13475
13476 /* BGP structure lookup. */
13477 if (argc == 3)
13478 {
13479 bgp = bgp_lookup_by_name (argv[0]);
13480 if (bgp == NULL)
13481 {
13482 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13483 return CMD_WARNING;
13484 }
13485 }
13486 else
13487 {
13488 bgp = bgp_get_default ();
13489 if (bgp == NULL)
13490 {
13491 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13492 return CMD_WARNING;
13493 }
13494 }
13495
13496 if (argc == 3)
13497 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13498 else
13499 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13500
13501 if (! peer)
13502 return CMD_WARNING;
13503
13504 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
13505 {
13506 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13507 VTY_NEWLINE);
13508 return CMD_WARNING;
13509 }
13510
13511 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
13512 PEER_FLAG_RSERVER_CLIENT))
13513 {
13514 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13515 VTY_NEWLINE);
13516 return CMD_WARNING;
13517 }
13518
13519 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
13520 (argc == 3) ? argv[2] : argv[1],
b05a1c8b 13521 AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, 0);
fee0f4c6 13522}
13523
13524ALIAS (show_bgp_view_rsclient_route,
13525 show_bgp_rsclient_route_cmd,
a80beece 13526 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
fee0f4c6 13527 SHOW_STR
13528 BGP_STR
13529 "Information about Route Server Client\n"
a80beece 13530 NEIGHBOR_ADDR_STR3
fee0f4c6 13531 "Network in the BGP routing table to display\n")
13532
95cbbd2a
ML
13533DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
13534 show_bgp_view_ipv6_safi_rsclient_route_cmd,
a80beece 13535 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
95cbbd2a
ML
13536 SHOW_STR
13537 BGP_STR
13538 "BGP view\n"
2b00515a 13539 "View name\n"
95cbbd2a
ML
13540 "Address family\n"
13541 "Address Family modifier\n"
13542 "Address Family modifier\n"
13543 "Information about Route Server Client\n"
a80beece 13544 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13545 "Network in the BGP routing table to display\n")
13546{
13547 struct bgp *bgp;
13548 struct peer *peer;
13549 safi_t safi;
13550
13551 /* BGP structure lookup. */
13552 if (argc == 4)
13553 {
13554 bgp = bgp_lookup_by_name (argv[0]);
13555 if (bgp == NULL)
13556 {
13557 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13558 return CMD_WARNING;
13559 }
13560 }
13561 else
13562 {
13563 bgp = bgp_get_default ();
13564 if (bgp == NULL)
13565 {
13566 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13567 return CMD_WARNING;
13568 }
13569 }
13570
13571 if (argc == 4) {
13572 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13573 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13574 } else {
13575 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13576 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13577 }
13578
13579 if (! peer)
13580 return CMD_WARNING;
13581
13582 if (! peer->afc[AFI_IP6][safi])
13583 {
13584 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13585 VTY_NEWLINE);
13586 return CMD_WARNING;
13587}
13588
13589 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
13590 PEER_FLAG_RSERVER_CLIENT))
13591 {
13592 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13593 VTY_NEWLINE);
13594 return CMD_WARNING;
13595 }
13596
13597 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
13598 (argc == 4) ? argv[3] : argv[2],
b05a1c8b 13599 AFI_IP6, safi, NULL, 0, BGP_PATH_ALL, 0);
95cbbd2a
ML
13600}
13601
13602ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
13603 show_bgp_ipv6_safi_rsclient_route_cmd,
a80beece 13604 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
95cbbd2a
ML
13605 SHOW_STR
13606 BGP_STR
13607 "Address family\n"
13608 "Address Family modifier\n"
13609 "Address Family modifier\n"
13610 "Information about Route Server Client\n"
a80beece 13611 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13612 "Network in the BGP routing table to display\n")
13613
fee0f4c6 13614DEFUN (show_bgp_view_rsclient_prefix,
13615 show_bgp_view_rsclient_prefix_cmd,
a80beece 13616 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
fee0f4c6 13617 SHOW_STR
13618 BGP_STR
13619 "BGP view\n"
2b00515a 13620 "View name\n"
fee0f4c6 13621 "Information about Route Server Client\n"
a80beece 13622 NEIGHBOR_ADDR_STR3
fee0f4c6 13623 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
13624{
13625 struct bgp *bgp;
13626 struct peer *peer;
13627
13628 /* BGP structure lookup. */
13629 if (argc == 3)
13630 {
13631 bgp = bgp_lookup_by_name (argv[0]);
13632 if (bgp == NULL)
13633 {
13634 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13635 return CMD_WARNING;
13636 }
13637 }
13638 else
13639 {
13640 bgp = bgp_get_default ();
13641 if (bgp == NULL)
13642 {
13643 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13644 return CMD_WARNING;
13645 }
13646 }
13647
13648 if (argc == 3)
13649 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13650 else
13651 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13652
13653 if (! peer)
13654 return CMD_WARNING;
13655
13656 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
13657 {
13658 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13659 VTY_NEWLINE);
13660 return CMD_WARNING;
13661 }
13662
13663 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
13664 PEER_FLAG_RSERVER_CLIENT))
13665 {
13666 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13667 VTY_NEWLINE);
13668 return CMD_WARNING;
13669 }
13670
13671 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
13672 (argc == 3) ? argv[2] : argv[1],
b05a1c8b 13673 AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, 0);
fee0f4c6 13674}
13675
13676ALIAS (show_bgp_view_rsclient_prefix,
13677 show_bgp_rsclient_prefix_cmd,
a80beece 13678 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
fee0f4c6 13679 SHOW_STR
13680 BGP_STR
13681 "Information about Route Server Client\n"
a80beece 13682 NEIGHBOR_ADDR_STR3
fee0f4c6 13683 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
13684
95cbbd2a
ML
13685DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
13686 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
a80beece 13687 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
95cbbd2a
ML
13688 SHOW_STR
13689 BGP_STR
13690 "BGP view\n"
2b00515a 13691 "View name\n"
95cbbd2a
ML
13692 "Address family\n"
13693 "Address Family modifier\n"
13694 "Address Family modifier\n"
13695 "Information about Route Server Client\n"
a80beece 13696 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13697 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
13698{
13699 struct bgp *bgp;
13700 struct peer *peer;
13701 safi_t safi;
13702
13703 /* BGP structure lookup. */
13704 if (argc == 4)
13705 {
13706 bgp = bgp_lookup_by_name (argv[0]);
13707 if (bgp == NULL)
13708 {
13709 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13710 return CMD_WARNING;
13711 }
13712 }
13713 else
13714 {
13715 bgp = bgp_get_default ();
13716 if (bgp == NULL)
13717 {
13718 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13719 return CMD_WARNING;
13720 }
13721 }
13722
13723 if (argc == 4) {
13724 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13725 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13726 } else {
13727 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13728 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13729 }
13730
13731 if (! peer)
13732 return CMD_WARNING;
13733
13734 if (! peer->afc[AFI_IP6][safi])
13735 {
13736 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13737 VTY_NEWLINE);
13738 return CMD_WARNING;
13739}
13740
13741 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
13742 PEER_FLAG_RSERVER_CLIENT))
13743{
13744 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13745 VTY_NEWLINE);
13746 return CMD_WARNING;
13747 }
13748
13749 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
13750 (argc == 4) ? argv[3] : argv[2],
b05a1c8b 13751 AFI_IP6, safi, NULL, 1, BGP_PATH_ALL, 0);
95cbbd2a
ML
13752}
13753
13754ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
13755 show_bgp_ipv6_safi_rsclient_prefix_cmd,
a80beece 13756 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
95cbbd2a
ML
13757 SHOW_STR
13758 BGP_STR
13759 "Address family\n"
13760 "Address Family modifier\n"
13761 "Address Family modifier\n"
13762 "Information about Route Server Client\n"
a80beece 13763 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13764 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
13765
718e3744 13766#endif /* HAVE_IPV6 */
6b0655a2 13767
718e3744 13768struct bgp_table *bgp_distance_table;
13769
13770struct bgp_distance
13771{
13772 /* Distance value for the IP source prefix. */
13773 u_char distance;
13774
13775 /* Name of the access-list to be matched. */
13776 char *access_list;
13777};
13778
94f2b392 13779static struct bgp_distance *
66e5cd87 13780bgp_distance_new (void)
718e3744 13781{
393deb9b 13782 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
718e3744 13783}
13784
94f2b392 13785static void
718e3744 13786bgp_distance_free (struct bgp_distance *bdistance)
13787{
13788 XFREE (MTYPE_BGP_DISTANCE, bdistance);
13789}
13790
94f2b392 13791static int
fd79ac91 13792bgp_distance_set (struct vty *vty, const char *distance_str,
13793 const char *ip_str, const char *access_list_str)
718e3744 13794{
13795 int ret;
13796 struct prefix_ipv4 p;
13797 u_char distance;
13798 struct bgp_node *rn;
13799 struct bgp_distance *bdistance;
13800
13801 ret = str2prefix_ipv4 (ip_str, &p);
13802 if (ret == 0)
13803 {
13804 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13805 return CMD_WARNING;
13806 }
13807
13808 distance = atoi (distance_str);
13809
13810 /* Get BGP distance node. */
13811 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
13812 if (rn->info)
13813 {
13814 bdistance = rn->info;
13815 bgp_unlock_node (rn);
13816 }
13817 else
13818 {
13819 bdistance = bgp_distance_new ();
13820 rn->info = bdistance;
13821 }
13822
13823 /* Set distance value. */
13824 bdistance->distance = distance;
13825
13826 /* Reset access-list configuration. */
13827 if (bdistance->access_list)
13828 {
13829 free (bdistance->access_list);
13830 bdistance->access_list = NULL;
13831 }
13832 if (access_list_str)
13833 bdistance->access_list = strdup (access_list_str);
13834
13835 return CMD_SUCCESS;
13836}
13837
94f2b392 13838static int
fd79ac91 13839bgp_distance_unset (struct vty *vty, const char *distance_str,
13840 const char *ip_str, const char *access_list_str)
718e3744 13841{
13842 int ret;
13843 struct prefix_ipv4 p;
718e3744 13844 struct bgp_node *rn;
13845 struct bgp_distance *bdistance;
13846
13847 ret = str2prefix_ipv4 (ip_str, &p);
13848 if (ret == 0)
13849 {
13850 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13851 return CMD_WARNING;
13852 }
13853
718e3744 13854 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
13855 if (! rn)
13856 {
13857 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
13858 return CMD_WARNING;
13859 }
13860
13861 bdistance = rn->info;
13862
13863 if (bdistance->access_list)
13864 free (bdistance->access_list);
13865 bgp_distance_free (bdistance);
13866
13867 rn->info = NULL;
13868 bgp_unlock_node (rn);
13869 bgp_unlock_node (rn);
13870
13871 return CMD_SUCCESS;
13872}
13873
718e3744 13874/* Apply BGP information to distance method. */
13875u_char
13876bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
13877{
13878 struct bgp_node *rn;
13879 struct prefix_ipv4 q;
13880 struct peer *peer;
13881 struct bgp_distance *bdistance;
13882 struct access_list *alist;
13883 struct bgp_static *bgp_static;
13884
13885 if (! bgp)
13886 return 0;
13887
13888 if (p->family != AF_INET)
13889 return 0;
13890
13891 peer = rinfo->peer;
13892
13893 if (peer->su.sa.sa_family != AF_INET)
13894 return 0;
13895
13896 memset (&q, 0, sizeof (struct prefix_ipv4));
13897 q.family = AF_INET;
13898 q.prefix = peer->su.sin.sin_addr;
13899 q.prefixlen = IPV4_MAX_BITLEN;
13900
13901 /* Check source address. */
13902 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
13903 if (rn)
13904 {
13905 bdistance = rn->info;
13906 bgp_unlock_node (rn);
13907
13908 if (bdistance->access_list)
13909 {
13910 alist = access_list_lookup (AFI_IP, bdistance->access_list);
13911 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
13912 return bdistance->distance;
13913 }
13914 else
13915 return bdistance->distance;
13916 }
13917
13918 /* Backdoor check. */
13919 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
13920 if (rn)
13921 {
13922 bgp_static = rn->info;
13923 bgp_unlock_node (rn);
13924
13925 if (bgp_static->backdoor)
13926 {
13927 if (bgp->distance_local)
13928 return bgp->distance_local;
13929 else
13930 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13931 }
13932 }
13933
6d85b15b 13934 if (peer->sort == BGP_PEER_EBGP)
718e3744 13935 {
13936 if (bgp->distance_ebgp)
13937 return bgp->distance_ebgp;
13938 return ZEBRA_EBGP_DISTANCE_DEFAULT;
13939 }
13940 else
13941 {
13942 if (bgp->distance_ibgp)
13943 return bgp->distance_ibgp;
13944 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13945 }
13946}
13947
13948DEFUN (bgp_distance,
13949 bgp_distance_cmd,
13950 "distance bgp <1-255> <1-255> <1-255>",
13951 "Define an administrative distance\n"
13952 "BGP distance\n"
13953 "Distance for routes external to the AS\n"
13954 "Distance for routes internal to the AS\n"
13955 "Distance for local routes\n")
13956{
13957 struct bgp *bgp;
13958
13959 bgp = vty->index;
13960
13961 bgp->distance_ebgp = atoi (argv[0]);
13962 bgp->distance_ibgp = atoi (argv[1]);
13963 bgp->distance_local = atoi (argv[2]);
13964 return CMD_SUCCESS;
13965}
13966
13967DEFUN (no_bgp_distance,
13968 no_bgp_distance_cmd,
13969 "no distance bgp <1-255> <1-255> <1-255>",
13970 NO_STR
13971 "Define an administrative distance\n"
13972 "BGP distance\n"
13973 "Distance for routes external to the AS\n"
13974 "Distance for routes internal to the AS\n"
13975 "Distance for local routes\n")
13976{
13977 struct bgp *bgp;
13978
13979 bgp = vty->index;
13980
13981 bgp->distance_ebgp= 0;
13982 bgp->distance_ibgp = 0;
13983 bgp->distance_local = 0;
13984 return CMD_SUCCESS;
13985}
13986
13987ALIAS (no_bgp_distance,
13988 no_bgp_distance2_cmd,
13989 "no distance bgp",
13990 NO_STR
13991 "Define an administrative distance\n"
13992 "BGP distance\n")
13993
13994DEFUN (bgp_distance_source,
13995 bgp_distance_source_cmd,
13996 "distance <1-255> A.B.C.D/M",
13997 "Define an administrative distance\n"
13998 "Administrative distance\n"
13999 "IP source prefix\n")
14000{
14001 bgp_distance_set (vty, argv[0], argv[1], NULL);
14002 return CMD_SUCCESS;
14003}
14004
14005DEFUN (no_bgp_distance_source,
14006 no_bgp_distance_source_cmd,
14007 "no distance <1-255> A.B.C.D/M",
14008 NO_STR
14009 "Define an administrative distance\n"
14010 "Administrative distance\n"
14011 "IP source prefix\n")
14012{
14013 bgp_distance_unset (vty, argv[0], argv[1], NULL);
14014 return CMD_SUCCESS;
14015}
14016
14017DEFUN (bgp_distance_source_access_list,
14018 bgp_distance_source_access_list_cmd,
14019 "distance <1-255> A.B.C.D/M WORD",
14020 "Define an administrative distance\n"
14021 "Administrative distance\n"
14022 "IP source prefix\n"
14023 "Access list name\n")
14024{
14025 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
14026 return CMD_SUCCESS;
14027}
14028
14029DEFUN (no_bgp_distance_source_access_list,
14030 no_bgp_distance_source_access_list_cmd,
14031 "no distance <1-255> A.B.C.D/M WORD",
14032 NO_STR
14033 "Define an administrative distance\n"
14034 "Administrative distance\n"
14035 "IP source prefix\n"
14036 "Access list name\n")
14037{
14038 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
14039 return CMD_SUCCESS;
14040}
6b0655a2 14041
718e3744 14042DEFUN (bgp_damp_set,
14043 bgp_damp_set_cmd,
14044 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14045 "BGP Specific commands\n"
14046 "Enable route-flap dampening\n"
14047 "Half-life time for the penalty\n"
14048 "Value to start reusing a route\n"
14049 "Value to start suppressing a route\n"
14050 "Maximum duration to suppress a stable route\n")
14051{
14052 struct bgp *bgp;
14053 int half = DEFAULT_HALF_LIFE * 60;
14054 int reuse = DEFAULT_REUSE;
14055 int suppress = DEFAULT_SUPPRESS;
14056 int max = 4 * half;
14057
14058 if (argc == 4)
14059 {
14060 half = atoi (argv[0]) * 60;
14061 reuse = atoi (argv[1]);
14062 suppress = atoi (argv[2]);
14063 max = atoi (argv[3]) * 60;
14064 }
14065 else if (argc == 1)
14066 {
14067 half = atoi (argv[0]) * 60;
14068 max = 4 * half;
14069 }
14070
14071 bgp = vty->index;
14072 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
14073 half, reuse, suppress, max);
14074}
14075
14076ALIAS (bgp_damp_set,
14077 bgp_damp_set2_cmd,
14078 "bgp dampening <1-45>",
14079 "BGP Specific commands\n"
14080 "Enable route-flap dampening\n"
14081 "Half-life time for the penalty\n")
14082
14083ALIAS (bgp_damp_set,
14084 bgp_damp_set3_cmd,
14085 "bgp dampening",
14086 "BGP Specific commands\n"
14087 "Enable route-flap dampening\n")
14088
14089DEFUN (bgp_damp_unset,
14090 bgp_damp_unset_cmd,
14091 "no bgp dampening",
14092 NO_STR
14093 "BGP Specific commands\n"
14094 "Enable route-flap dampening\n")
14095{
14096 struct bgp *bgp;
14097
14098 bgp = vty->index;
14099 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
14100}
14101
14102ALIAS (bgp_damp_unset,
14103 bgp_damp_unset2_cmd,
14104 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14105 NO_STR
14106 "BGP Specific commands\n"
14107 "Enable route-flap dampening\n"
14108 "Half-life time for the penalty\n"
14109 "Value to start reusing a route\n"
14110 "Value to start suppressing a route\n"
14111 "Maximum duration to suppress a stable route\n")
14112
14113DEFUN (show_ip_bgp_dampened_paths,
14114 show_ip_bgp_dampened_paths_cmd,
14115 "show ip bgp dampened-paths",
14116 SHOW_STR
14117 IP_STR
14118 BGP_STR
14119 "Display paths suppressed due to dampening\n")
14120{
5a646650 14121 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
b05a1c8b 14122 NULL, 0);
718e3744 14123}
14124
14125DEFUN (show_ip_bgp_flap_statistics,
14126 show_ip_bgp_flap_statistics_cmd,
14127 "show ip bgp flap-statistics",
14128 SHOW_STR
14129 IP_STR
14130 BGP_STR
14131 "Display flap statistics of routes\n")
14132{
5a646650 14133 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 14134 bgp_show_type_flap_statistics, NULL, 0);
718e3744 14135}
6b0655a2 14136
718e3744 14137/* Display specified route of BGP table. */
94f2b392 14138static int
fd79ac91 14139bgp_clear_damp_route (struct vty *vty, const char *view_name,
14140 const char *ip_str, afi_t afi, safi_t safi,
14141 struct prefix_rd *prd, int prefix_check)
718e3744 14142{
14143 int ret;
14144 struct prefix match;
14145 struct bgp_node *rn;
14146 struct bgp_node *rm;
14147 struct bgp_info *ri;
14148 struct bgp_info *ri_temp;
14149 struct bgp *bgp;
14150 struct bgp_table *table;
14151
14152 /* BGP structure lookup. */
14153 if (view_name)
14154 {
14155 bgp = bgp_lookup_by_name (view_name);
14156 if (bgp == NULL)
14157 {
14158 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
14159 return CMD_WARNING;
14160 }
14161 }
14162 else
14163 {
14164 bgp = bgp_get_default ();
14165 if (bgp == NULL)
14166 {
14167 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
14168 return CMD_WARNING;
14169 }
14170 }
14171
14172 /* Check IP address argument. */
14173 ret = str2prefix (ip_str, &match);
14174 if (! ret)
14175 {
14176 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
14177 return CMD_WARNING;
14178 }
14179
14180 match.family = afi2family (afi);
14181
14182 if (safi == SAFI_MPLS_VPN)
14183 {
14184 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
14185 {
14186 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
14187 continue;
14188
14189 if ((table = rn->info) != NULL)
14190 if ((rm = bgp_node_match (table, &match)) != NULL)
6c88b44d
CC
14191 {
14192 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
14193 {
14194 ri = rm->info;
14195 while (ri)
14196 {
14197 if (ri->extra && ri->extra->damp_info)
14198 {
14199 ri_temp = ri->next;
14200 bgp_damp_info_free (ri->extra->damp_info, 1);
14201 ri = ri_temp;
14202 }
14203 else
14204 ri = ri->next;
14205 }
14206 }
14207
14208 bgp_unlock_node (rm);
14209 }
718e3744 14210 }
14211 }
14212 else
14213 {
14214 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
6c88b44d
CC
14215 {
14216 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
14217 {
14218 ri = rn->info;
14219 while (ri)
14220 {
14221 if (ri->extra && ri->extra->damp_info)
14222 {
14223 ri_temp = ri->next;
14224 bgp_damp_info_free (ri->extra->damp_info, 1);
14225 ri = ri_temp;
14226 }
14227 else
14228 ri = ri->next;
14229 }
14230 }
14231
14232 bgp_unlock_node (rn);
14233 }
718e3744 14234 }
14235
14236 return CMD_SUCCESS;
14237}
14238
14239DEFUN (clear_ip_bgp_dampening,
14240 clear_ip_bgp_dampening_cmd,
14241 "clear ip bgp dampening",
14242 CLEAR_STR
14243 IP_STR
14244 BGP_STR
14245 "Clear route flap dampening information\n")
14246{
14247 bgp_damp_info_clean ();
14248 return CMD_SUCCESS;
14249}
14250
14251DEFUN (clear_ip_bgp_dampening_prefix,
14252 clear_ip_bgp_dampening_prefix_cmd,
14253 "clear ip bgp dampening A.B.C.D/M",
14254 CLEAR_STR
14255 IP_STR
14256 BGP_STR
14257 "Clear route flap dampening information\n"
14258 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14259{
14260 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14261 SAFI_UNICAST, NULL, 1);
14262}
14263
14264DEFUN (clear_ip_bgp_dampening_address,
14265 clear_ip_bgp_dampening_address_cmd,
14266 "clear ip bgp dampening A.B.C.D",
14267 CLEAR_STR
14268 IP_STR
14269 BGP_STR
14270 "Clear route flap dampening information\n"
14271 "Network to clear damping information\n")
14272{
14273 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14274 SAFI_UNICAST, NULL, 0);
14275}
14276
14277DEFUN (clear_ip_bgp_dampening_address_mask,
14278 clear_ip_bgp_dampening_address_mask_cmd,
14279 "clear ip bgp dampening A.B.C.D A.B.C.D",
14280 CLEAR_STR
14281 IP_STR
14282 BGP_STR
14283 "Clear route flap dampening information\n"
14284 "Network to clear damping information\n"
14285 "Network mask\n")
14286{
14287 int ret;
14288 char prefix_str[BUFSIZ];
14289
14290 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
14291 if (! ret)
14292 {
14293 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
14294 return CMD_WARNING;
14295 }
14296
14297 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
14298 SAFI_UNICAST, NULL, 0);
14299}
6b0655a2 14300
94f2b392 14301static int
718e3744 14302bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
14303 afi_t afi, safi_t safi, int *write)
14304{
14305 struct bgp_node *prn;
14306 struct bgp_node *rn;
14307 struct bgp_table *table;
14308 struct prefix *p;
14309 struct prefix_rd *prd;
14310 struct bgp_static *bgp_static;
14311 u_int32_t label;
14312 char buf[SU_ADDRSTRLEN];
14313 char rdbuf[RD_ADDRSTRLEN];
14314
14315 /* Network configuration. */
14316 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
14317 if ((table = prn->info) != NULL)
14318 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
14319 if ((bgp_static = rn->info) != NULL)
14320 {
14321 p = &rn->p;
14322 prd = (struct prefix_rd *) &prn->p;
14323
14324 /* "address-family" display. */
14325 bgp_config_write_family_header (vty, afi, safi, write);
14326
14327 /* "network" configuration display. */
14328 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
14329 label = decode_label (bgp_static->tag);
14330
14331 vty_out (vty, " network %s/%d rd %s tag %d",
14332 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14333 p->prefixlen,
14334 rdbuf, label);
14335 vty_out (vty, "%s", VTY_NEWLINE);
14336 }
14337 return 0;
14338}
14339
14340/* Configuration of static route announcement and aggregate
14341 information. */
14342int
14343bgp_config_write_network (struct vty *vty, struct bgp *bgp,
14344 afi_t afi, safi_t safi, int *write)
14345{
14346 struct bgp_node *rn;
14347 struct prefix *p;
14348 struct bgp_static *bgp_static;
14349 struct bgp_aggregate *bgp_aggregate;
14350 char buf[SU_ADDRSTRLEN];
14351
14352 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
14353 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
14354
14355 /* Network configuration. */
14356 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
14357 if ((bgp_static = rn->info) != NULL)
14358 {
14359 p = &rn->p;
14360
14361 /* "address-family" display. */
14362 bgp_config_write_family_header (vty, afi, safi, write);
14363
14364 /* "network" configuration display. */
14365 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14366 {
14367 u_int32_t destination;
14368 struct in_addr netmask;
14369
14370 destination = ntohl (p->u.prefix4.s_addr);
14371 masklen2ip (p->prefixlen, &netmask);
14372 vty_out (vty, " network %s",
14373 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
14374
14375 if ((IN_CLASSC (destination) && p->prefixlen == 24)
14376 || (IN_CLASSB (destination) && p->prefixlen == 16)
14377 || (IN_CLASSA (destination) && p->prefixlen == 8)
14378 || p->u.prefix4.s_addr == 0)
14379 {
14380 /* Natural mask is not display. */
14381 }
14382 else
14383 vty_out (vty, " mask %s", inet_ntoa (netmask));
14384 }
14385 else
14386 {
14387 vty_out (vty, " network %s/%d",
14388 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14389 p->prefixlen);
14390 }
14391
14392 if (bgp_static->rmap.name)
14393 vty_out (vty, " route-map %s", bgp_static->rmap.name);
41367172
PJ
14394 else
14395 {
14396 if (bgp_static->backdoor)
14397 vty_out (vty, " backdoor");
41367172 14398 }
718e3744 14399
14400 vty_out (vty, "%s", VTY_NEWLINE);
14401 }
14402
14403 /* Aggregate-address configuration. */
14404 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
14405 if ((bgp_aggregate = rn->info) != NULL)
14406 {
14407 p = &rn->p;
14408
14409 /* "address-family" display. */
14410 bgp_config_write_family_header (vty, afi, safi, write);
14411
14412 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14413 {
14414 struct in_addr netmask;
14415
14416 masklen2ip (p->prefixlen, &netmask);
14417 vty_out (vty, " aggregate-address %s %s",
14418 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14419 inet_ntoa (netmask));
14420 }
14421 else
14422 {
14423 vty_out (vty, " aggregate-address %s/%d",
14424 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14425 p->prefixlen);
14426 }
14427
14428 if (bgp_aggregate->as_set)
14429 vty_out (vty, " as-set");
14430
14431 if (bgp_aggregate->summary_only)
14432 vty_out (vty, " summary-only");
14433
14434 vty_out (vty, "%s", VTY_NEWLINE);
14435 }
14436
14437 return 0;
14438}
14439
14440int
14441bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
14442{
14443 struct bgp_node *rn;
14444 struct bgp_distance *bdistance;
14445
14446 /* Distance configuration. */
14447 if (bgp->distance_ebgp
14448 && bgp->distance_ibgp
14449 && bgp->distance_local
14450 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
14451 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
14452 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
14453 vty_out (vty, " distance bgp %d %d %d%s",
14454 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
14455 VTY_NEWLINE);
14456
14457 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
14458 if ((bdistance = rn->info) != NULL)
14459 {
14460 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
14461 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
14462 bdistance->access_list ? bdistance->access_list : "",
14463 VTY_NEWLINE);
14464 }
14465
14466 return 0;
14467}
14468
14469/* Allocate routing table structure and install commands. */
14470void
66e5cd87 14471bgp_route_init (void)
718e3744 14472{
14473 /* Init BGP distance table. */
64e580a7 14474 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
718e3744 14475
14476 /* IPv4 BGP commands. */
73ac8160 14477 install_element (BGP_NODE, &bgp_table_map_cmd);
718e3744 14478 install_element (BGP_NODE, &bgp_network_cmd);
14479 install_element (BGP_NODE, &bgp_network_mask_cmd);
14480 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
14481 install_element (BGP_NODE, &bgp_network_route_map_cmd);
14482 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
14483 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
14484 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
14485 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
14486 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
73ac8160 14487 install_element (BGP_NODE, &no_bgp_table_map_cmd);
718e3744 14488 install_element (BGP_NODE, &no_bgp_network_cmd);
14489 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
14490 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
14491 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
14492 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
14493 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14494 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
14495 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
14496 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
14497
14498 install_element (BGP_NODE, &aggregate_address_cmd);
14499 install_element (BGP_NODE, &aggregate_address_mask_cmd);
14500 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
14501 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
14502 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
14503 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
14504 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
14505 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
14506 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
14507 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
14508 install_element (BGP_NODE, &no_aggregate_address_cmd);
14509 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
14510 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
14511 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
14512 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
14513 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
14514 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
14515 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
14516 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14517 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14518
14519 /* IPv4 unicast configuration. */
73ac8160 14520 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
718e3744 14521 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
14522 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
14523 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
14524 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
14525 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
14526 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 14527 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
c8f3fe30 14528 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
718e3744 14529 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
14530 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
14531 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
14532 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
14533 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
c8f3fe30 14534
718e3744 14535 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
14536 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
14537 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
14538 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
14539 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
14540 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
14541 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
14542 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
14543 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
14544 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
14545 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
14546 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
14547 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
14548 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
14549 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
14550 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
14551 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
14552 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
14553 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14554 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14555
14556 /* IPv4 multicast configuration. */
73ac8160 14557 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
718e3744 14558 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
14559 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
14560 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
14561 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
14562 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
14563 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 14564 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
718e3744 14565 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
14566 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
14567 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
14568 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
14569 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
14570 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14571 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
14572 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
14573 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
14574 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
14575 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
14576 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
14577 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
14578 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
14579 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
14580 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
14581 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
14582 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
14583 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
14584 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
14585 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
14586 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
14587 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
14588 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
14589 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14590 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14591
14592 install_element (VIEW_NODE, &show_ip_bgp_cmd);
14593 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 14594 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
718e3744 14595 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
14596 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
14597 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 14598 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 14599 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 14600 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14601 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14602 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
14603 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
14604 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14605 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 14606 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 14607 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
718e3744 14608 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14609 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14610 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
14611 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
14612 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
14613 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
14614 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14615 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
14616 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14617 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
14618 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14619 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
14620 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14621 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
14622 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14623 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
14624 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14625 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
14626 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
14627 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
14628 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
14629 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
14630 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
14631 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
14632 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
14633 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
14634 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
14635 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
14636 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
14637 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
718e3744 14638 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
14639 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
14640 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
14641 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
14642 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14643 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14644 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14645 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14646 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
14647 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14648 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
14649 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14650 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
14651 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14652 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
0b16f239 14653 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
718e3744 14654 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
0b16f239 14655 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
718e3744 14656 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
0b16f239 14657 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
718e3744 14658 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
0b16f239 14659 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
95cbbd2a 14660 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 14661 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
14662 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14663 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14664 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14665 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
14666 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
14667 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
14668 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
14669 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14670 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
14671 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
14672 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14673 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14674 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
14675 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
14676 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
fee0f4c6 14677 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
95cbbd2a 14678 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
fee0f4c6 14679 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 14680 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
fee0f4c6 14681 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 14682 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
2a71e9ce
TP
14683 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
14684 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
fee0f4c6 14685 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
95cbbd2a 14686 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
fee0f4c6 14687 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 14688 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
fee0f4c6 14689 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 14690 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
62687ff1
PJ
14691
14692 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
14693 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
14694 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
14695 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
62687ff1 14696 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 14697 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
62687ff1
PJ
14698 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14699 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
14700 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
14701 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14702 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 14703 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 14704 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
62687ff1
PJ
14705 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14706 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14707 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
14708 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
14709 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
14710 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
14711 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
14712 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
14713 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
14714 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
14715 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
14716 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
14717 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
14718 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
14719 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
14720 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
14721 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
62687ff1
PJ
14722 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
14723 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
14724 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
14725 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
14726 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14727 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14728 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14729 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14730 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 14731 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
62687ff1 14732 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 14733 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
62687ff1 14734 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 14735 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
62687ff1 14736 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 14737 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
718e3744 14738
14739 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
14740 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 14741 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
718e3744 14742 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
14743 install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd);
14744 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 14745 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 14746 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 14747 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14748 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14749 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
14750 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
14751 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14752 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 14753 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 14754 install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd);
718e3744 14755 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14756 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14757 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
14758 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
14759 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
14760 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
14761 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14762 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
14763 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14764 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
14765 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14766 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
14767 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14768 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
14769 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14770 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
14771 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14772 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
14773 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
14774 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
14775 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
14776 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
14777 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
14778 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
14779 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
14780 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
14781 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
14782 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
14783 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
14784 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
718e3744 14785 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
14786 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
14787 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
14788 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
14789 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14790 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14791 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14792 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14793 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
14794 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14795 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
14796 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14797 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
14798 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14799 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
0b16f239 14800 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
718e3744 14801 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
0b16f239 14802 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
718e3744 14803 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
0b16f239 14804 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
718e3744 14805 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
0b16f239 14806 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
95cbbd2a 14807 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 14808 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
14809 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14810 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14811 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14812 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
14813 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
14814 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
14815 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
14816 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14817 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
14818 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
14819 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14820 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14821 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
14822 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
14823 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
fee0f4c6 14824 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
95cbbd2a 14825 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
fee0f4c6 14826 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 14827 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
fee0f4c6 14828 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 14829 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
2a71e9ce
TP
14830 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
14831 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
fee0f4c6 14832 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
95cbbd2a 14833 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
fee0f4c6 14834 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 14835 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
fee0f4c6 14836 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 14837 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
718e3744 14838
14839 /* BGP dampening clear commands */
14840 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
14841 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
14842 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
14843 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
14844
ff7924f6
PJ
14845 /* prefix count */
14846 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
14847 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
14848 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
718e3744 14849#ifdef HAVE_IPV6
ff7924f6
PJ
14850 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
14851
718e3744 14852 /* New config IPv6 BGP commands. */
73ac8160 14853 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
718e3744 14854 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
14855 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
73ac8160 14856 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
718e3744 14857 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
14858 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
14859
14860 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
14861 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
14862 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
14863 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
73bfe0bd
B
14864
14865 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
14866 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
718e3744 14867
14868 /* Old config IPv6 BGP commands. */
14869 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
14870 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
14871
14872 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
14873 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
14874 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
14875 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
14876
14877 install_element (VIEW_NODE, &show_bgp_cmd);
14878 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 14879 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 14880 install_element (VIEW_NODE, &show_bgp_route_cmd);
14881 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 14882 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
14883 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
14884 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14885 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 14886 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
14887 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 14888 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c
DS
14889 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
14890 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14891 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 14892 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
14893 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
14894 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
14895 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
14896 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
14897 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
14898 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
14899 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
14900 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
14901 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
14902 install_element (VIEW_NODE, &show_bgp_community_cmd);
14903 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
14904 install_element (VIEW_NODE, &show_bgp_community2_cmd);
14905 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
14906 install_element (VIEW_NODE, &show_bgp_community3_cmd);
14907 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
14908 install_element (VIEW_NODE, &show_bgp_community4_cmd);
14909 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
14910 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
14911 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
14912 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
14913 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
14914 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
14915 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
14916 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
14917 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
14918 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
14919 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
14920 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
14921 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14922 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
14923 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14924 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
14925 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14926 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
14927 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14928 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
14929 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14930 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14931 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 14932 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
14933 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14934 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
14935 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
fee0f4c6 14936 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
95cbbd2a 14937 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
fee0f4c6 14938 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 14939 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
fee0f4c6 14940 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 14941 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
bb46e94f 14942 install_element (VIEW_NODE, &show_bgp_view_cmd);
14943 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
14944 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
14945 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
14946 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
14947 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
14948 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
14949 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
14950 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
14951 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
14952 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
14953 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
14954 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
14955 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
14956 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
14957 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
14958 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
14959 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
fee0f4c6 14960 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
95cbbd2a 14961 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
fee0f4c6 14962 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 14963 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
fee0f4c6 14964 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 14965 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
62687ff1
PJ
14966
14967 /* Restricted:
14968 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
14969 */
14970 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
14971 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 14972 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
14973 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
14974 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14975 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
62687ff1
PJ
14976 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
14977 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 14978 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c
DS
14979 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
14980 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14981 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
62687ff1
PJ
14982 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
14983 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
14984 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
14985 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
14986 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
14987 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
14988 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
14989 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
14990 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
14991 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
14992 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
14993 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
14994 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
14995 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
14996 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
14997 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
14998 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 14999 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
62687ff1 15000 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 15001 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
62687ff1
PJ
15002 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
15003 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
15004 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
15005 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
15006 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
15007 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
15008 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 15009 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
62687ff1 15010 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 15011 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
718e3744 15012
15013 install_element (ENABLE_NODE, &show_bgp_cmd);
15014 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 15015 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 15016 install_element (ENABLE_NODE, &show_bgp_route_cmd);
15017 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 15018 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
15019 install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd);
15020 install_element (ENABLE_NODE, &show_bgp_ipv6_route_pathtype_cmd);
15021 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 15022 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
4092b06c
DS
15023 install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd);
15024 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
15025 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 15026 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 15027 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
718e3744 15028 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
15029 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
15030 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
15031 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
15032 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
15033 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
15034 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
15035 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
15036 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
15037 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
15038 install_element (ENABLE_NODE, &show_bgp_community_cmd);
15039 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
15040 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
15041 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
15042 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
15043 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
15044 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
15045 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
15046 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
15047 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
15048 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
15049 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
15050 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
15051 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
15052 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
15053 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
15054 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
15055 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
15056 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
15057 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
15058 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
15059 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
15060 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
15061 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
15062 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
15063 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
15064 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
15065 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
15066 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
15067 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 15068 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
15069 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
15070 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
15071 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
fee0f4c6 15072 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
95cbbd2a 15073 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
fee0f4c6 15074 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 15075 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
fee0f4c6 15076 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 15077 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
bb46e94f 15078 install_element (ENABLE_NODE, &show_bgp_view_cmd);
15079 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
15080 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
15081 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
15082 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
15083 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
15084 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
15085 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
15086 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
15087 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
15088 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
15089 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
15090 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
15091 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
15092 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
15093 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
15094 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
15095 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
fee0f4c6 15096 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
95cbbd2a 15097 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
fee0f4c6 15098 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 15099 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
fee0f4c6 15100 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 15101 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
2815e61f
PJ
15102
15103 /* Statistics */
15104 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
15105 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
15106 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
15107 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
15108
718e3744 15109 /* old command */
15110 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
15111 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
15112 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
15113 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
15114 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
15115 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
15116 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
15117 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
15118 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
15119 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
15120 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
15121 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
15122 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
15123 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
15124 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
15125 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
15126 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15127 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15128 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
15129 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
15130 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
15131 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
15132 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15133 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
15134 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
15135 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
15136 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
15137 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
15138 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
15139 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
15140 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
15141 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
15142 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
15143 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
15144 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15145 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
bb46e94f 15146
718e3744 15147 /* old command */
15148 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
15149 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
15150 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
15151 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
15152 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
15153 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
15154 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
15155 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
15156 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
15157 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
15158 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
15159 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
15160 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
15161 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
15162 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
15163 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
15164 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15165 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15166 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
15167 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
15168 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
15169 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
15170 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15171 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
15172 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
15173 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
15174 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
15175 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
15176 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
15177 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
15178 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
15179 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
15180 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
15181 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
15182 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15183 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
15184
15185 /* old command */
15186 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
15187 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
15188 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
15189 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
15190
15191 /* old command */
15192 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
15193 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
15194 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
15195 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
15196
15197 /* old command */
15198 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
15199 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
15200 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
15201 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
15202#endif /* HAVE_IPV6 */
15203
15204 install_element (BGP_NODE, &bgp_distance_cmd);
15205 install_element (BGP_NODE, &no_bgp_distance_cmd);
15206 install_element (BGP_NODE, &no_bgp_distance2_cmd);
15207 install_element (BGP_NODE, &bgp_distance_source_cmd);
15208 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
15209 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
15210 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
15211
15212 install_element (BGP_NODE, &bgp_damp_set_cmd);
15213 install_element (BGP_NODE, &bgp_damp_set2_cmd);
15214 install_element (BGP_NODE, &bgp_damp_set3_cmd);
15215 install_element (BGP_NODE, &bgp_damp_unset_cmd);
15216 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
15217 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
15218 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
15219 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
15220 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
15221 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
c8f3fe30
PJ
15222
15223 /* Deprecated AS-Pathlimit commands */
15224 install_element (BGP_NODE, &bgp_network_ttl_cmd);
15225 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
15226 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
15227 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
15228 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
15229 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
15230
15231 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
15232 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
15233 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
15234 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
15235 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
15236 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
15237
15238 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
15239 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
15240 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
15241 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
15242 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
15243 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
15244
15245 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
15246 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
15247 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
15248 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
15249 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
15250 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
15251
15252 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
15253 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
15254 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
15255 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
15256 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
15257 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
15258
15259 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
15260 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
15261 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
15262 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
15263 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
15264 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
3bde17f1
PJ
15265
15266#ifdef HAVE_IPV6
c8f3fe30
PJ
15267 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
15268 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
3bde17f1 15269#endif
718e3744 15270}
228da428
CC
15271
15272void
15273bgp_route_finish (void)
15274{
15275 bgp_table_unlock (bgp_distance_table);
15276 bgp_distance_table = NULL;
15277}