]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_route.c
Merge pull request #760 from opensourcerouting/rpm-non-redhat-fix
[mirror_frr.git] / bgpd / bgp_route.c
CommitLineData
718e3744 1/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
856ca177 23#include "lib/json.h"
718e3744 24#include "prefix.h"
25#include "linklist.h"
26#include "memory.h"
27#include "command.h"
28#include "stream.h"
29#include "filter.h"
718e3744 30#include "log.h"
31#include "routemap.h"
32#include "buffer.h"
33#include "sockunion.h"
34#include "plist.h"
35#include "thread.h"
200df115 36#include "workqueue.h"
3f9c7369 37#include "queue.h"
6e919709 38#include "memory.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"
8386ac43 62#include "bgpd/bgp_vty.h"
718e3744 63
65efcfce 64#if ENABLE_BGP_VNC
f8b6f499
LB
65#include "bgpd/rfapi/rfapi_backend.h"
66#include "bgpd/rfapi/vnc_import_bgp.h"
67#include "bgpd/rfapi/vnc_export_bgp.h"
65efcfce
LB
68#endif
69
718e3744 70/* Extern from bgp_dump.c */
dde72586
SH
71extern const char *bgp_origin_str[];
72extern const char *bgp_origin_long_str[];
6b0655a2 73
4125bb67 74struct bgp_node *
fee0f4c6 75bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
718e3744 76 struct prefix_rd *prd)
77{
78 struct bgp_node *rn;
79 struct bgp_node *prn = NULL;
da5b30f6
PJ
80
81 assert (table);
82 if (!table)
83 return NULL;
84
587ff0fd 85 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 86 {
fee0f4c6 87 prn = bgp_node_get (table, (struct prefix *) prd);
718e3744 88
89 if (prn->info == NULL)
64e580a7 90 prn->info = bgp_table_init (afi, safi);
718e3744 91 else
92 bgp_unlock_node (prn);
93 table = prn->info;
94 }
718e3744 95
96 rn = bgp_node_get (table, p);
97
587ff0fd 98 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 99 rn->prn = prn;
100
101 return rn;
102}
6b0655a2 103
fb982c25
PJ
104/* Allocate bgp_info_extra */
105static struct bgp_info_extra *
106bgp_info_extra_new (void)
107{
108 struct bgp_info_extra *new;
109 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
110 return new;
111}
112
113static void
114bgp_info_extra_free (struct bgp_info_extra **extra)
115{
116 if (extra && *extra)
117 {
118 if ((*extra)->damp_info)
119 bgp_damp_info_free ((*extra)->damp_info, 0);
120
121 (*extra)->damp_info = NULL;
122
123 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
124
125 *extra = NULL;
126 }
127}
128
129/* Get bgp_info extra information for the given bgp_info, lazy allocated
130 * if required.
131 */
132struct bgp_info_extra *
133bgp_info_extra_get (struct bgp_info *ri)
134{
135 if (!ri->extra)
136 ri->extra = bgp_info_extra_new();
137 return ri->extra;
138}
139
65efcfce
LB
140/* Allocate new bgp info structure. */
141struct bgp_info *
142bgp_info_new (void)
143{
144 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
145}
146
718e3744 147/* Free bgp route information. */
200df115 148static void
718e3744 149bgp_info_free (struct bgp_info *binfo)
150{
151 if (binfo->attr)
f6f434b2 152 bgp_attr_unintern (&binfo->attr);
fb018d25
DS
153
154 bgp_unlink_nexthop(binfo);
fb982c25 155 bgp_info_extra_free (&binfo->extra);
de8d5dff 156 bgp_info_mpath_free (&binfo->mpath);
718e3744 157
200df115 158 peer_unlock (binfo->peer); /* bgp_info peer reference */
159
718e3744 160 XFREE (MTYPE_BGP_ROUTE, binfo);
161}
162
200df115 163struct bgp_info *
164bgp_info_lock (struct bgp_info *binfo)
165{
166 binfo->lock++;
167 return binfo;
168}
169
170struct bgp_info *
171bgp_info_unlock (struct bgp_info *binfo)
172{
173 assert (binfo && binfo->lock > 0);
174 binfo->lock--;
175
176 if (binfo->lock == 0)
177 {
178#if 0
179 zlog_debug ("%s: unlocked and freeing", __func__);
180 zlog_backtrace (LOG_DEBUG);
181#endif
182 bgp_info_free (binfo);
183 return NULL;
184 }
185
186#if 0
187 if (binfo->lock == 1)
188 {
189 zlog_debug ("%s: unlocked to 1", __func__);
190 zlog_backtrace (LOG_DEBUG);
191 }
192#endif
193
194 return binfo;
195}
196
718e3744 197void
198bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
199{
200 struct bgp_info *top;
201
202 top = rn->info;
200df115 203
718e3744 204 ri->next = rn->info;
205 ri->prev = NULL;
206 if (top)
207 top->prev = ri;
208 rn->info = ri;
200df115 209
210 bgp_info_lock (ri);
211 bgp_lock_node (rn);
212 peer_lock (ri->peer); /* bgp_info peer reference */
718e3744 213}
214
b40d939b 215/* Do the actual removal of info from RIB, for use by bgp_process
216 completion callback *only* */
217static void
218bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
718e3744 219{
220 if (ri->next)
221 ri->next->prev = ri->prev;
222 if (ri->prev)
223 ri->prev->next = ri->next;
224 else
225 rn->info = ri->next;
200df115 226
de8d5dff 227 bgp_info_mpath_dequeue (ri);
200df115 228 bgp_info_unlock (ri);
229 bgp_unlock_node (rn);
718e3744 230}
231
b40d939b 232void
233bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
234{
1a392d46
PJ
235 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
236 /* set of previous already took care of pcount */
b40d939b 237 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
238}
239
8d45210e
AS
240/* undo the effects of a previous call to bgp_info_delete; typically
241 called when a route is deleted and then quickly re-added before the
242 deletion has been processed */
65efcfce 243void
8d45210e
AS
244bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
245{
246 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
247 /* unset of previous already took care of pcount */
248 SET_FLAG (ri->flags, BGP_INFO_VALID);
249}
250
1a392d46
PJ
251/* Adjust pcount as required */
252static void
253bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
254{
67174041
AS
255 struct bgp_table *table;
256
257 assert (rn && bgp_node_table (rn));
6f58544d
PJ
258 assert (ri && ri->peer && ri->peer->bgp);
259
67174041
AS
260 table = bgp_node_table (rn);
261
2a3d5731 262 if (ri->peer == ri->peer->bgp->peer_self)
1a392d46
PJ
263 return;
264
80e0ad24 265 if (!BGP_INFO_COUNTABLE (ri)
1a392d46
PJ
266 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
267 {
268
269 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
270
271 /* slight hack, but more robust against errors. */
67174041
AS
272 if (ri->peer->pcount[table->afi][table->safi])
273 ri->peer->pcount[table->afi][table->safi]--;
1a392d46
PJ
274 else
275 {
276 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
277 __func__, ri->peer->host);
278 zlog_backtrace (LOG_WARNING);
279 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
280 }
281 }
80e0ad24 282 else if (BGP_INFO_COUNTABLE (ri)
1a392d46
PJ
283 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
284 {
285 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
67174041 286 ri->peer->pcount[table->afi][table->safi]++;
1a392d46
PJ
287 }
288}
289
290
291/* Set/unset bgp_info flags, adjusting any other state as needed.
292 * This is here primarily to keep prefix-count in check.
293 */
294void
295bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
296{
297 SET_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
306void
307bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
308{
309 UNSET_FLAG (ri->flags, flag);
310
80e0ad24
DS
311 /* early bath if we know it's not a flag that changes countability state */
312 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
1a392d46
PJ
313 return;
314
315 bgp_pcount_adjust (rn, ri);
316}
317
718e3744 318/* Get MED value. If MED value is missing and "bgp bestpath
319 missing-as-worst" is specified, treat it as the worst value. */
94f2b392 320static u_int32_t
718e3744 321bgp_med_value (struct attr *attr, struct bgp *bgp)
322{
323 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
324 return attr->med;
325 else
326 {
327 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
3b424979 328 return BGP_MED_MAX;
718e3744 329 else
330 return 0;
331 }
332}
333
2ec1e66f
DW
334void
335bgp_info_path_with_addpath_rx_str (struct bgp_info *ri, char *buf)
336{
337 if (ri->addpath_rx_id)
338 sprintf(buf, "path %s (addpath rxid %d)", ri->peer->host, ri->addpath_rx_id);
339 else
340 sprintf(buf, "path %s", ri->peer->host);
341}
342
9fbdd100 343/* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1. */
94f2b392 344static int
96450faf 345bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
9fbdd100 346 int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg, int debug,
65efcfce 347 const char *pfx_buf)
718e3744 348{
8ff56318
JBD
349 struct attr *newattr, *existattr;
350 struct attr_extra *newattre, *existattre;
351 bgp_peer_sort_t new_sort;
352 bgp_peer_sort_t exist_sort;
718e3744 353 u_int32_t new_pref;
354 u_int32_t exist_pref;
355 u_int32_t new_med;
356 u_int32_t exist_med;
8ff56318
JBD
357 u_int32_t new_weight;
358 u_int32_t exist_weight;
359 uint32_t newm, existm;
718e3744 360 struct in_addr new_id;
361 struct in_addr exist_id;
362 int new_cluster;
363 int exist_cluster;
8ff56318
JBD
364 int internal_as_route;
365 int confed_as_route;
718e3744 366 int ret;
2ec1e66f
DW
367 char new_buf[PATH_ADDPATH_STR_BUFFER];
368 char exist_buf[PATH_ADDPATH_STR_BUFFER];
96450faf
JB
369
370 *paths_eq = 0;
718e3744 371
372 /* 0. Null check. */
373 if (new == NULL)
9fbdd100
DS
374 {
375 if (debug)
376 zlog_debug("%s: new is NULL", pfx_buf);
377 return 0;
378 }
379
2ec1e66f
DW
380 if (debug)
381 bgp_info_path_with_addpath_rx_str (new, new_buf);
382
718e3744 383 if (exist == NULL)
9fbdd100
DS
384 {
385 if (debug)
2ec1e66f 386 zlog_debug("%s: %s is the initial bestpath", pfx_buf, new_buf);
9fbdd100
DS
387 return 1;
388 }
718e3744 389
2ec1e66f 390 if (debug)
a6086ad4 391 {
392 bgp_info_path_with_addpath_rx_str (exist, exist_buf);
393 zlog_debug("%s: Comparing %s flags 0x%x with %s flags 0x%x",
394 pfx_buf, new_buf, new->flags, exist_buf, exist->flags);
395 }
2ec1e66f 396
8ff56318
JBD
397 newattr = new->attr;
398 existattr = exist->attr;
399 newattre = newattr->extra;
400 existattre = existattr->extra;
401
718e3744 402 /* 1. Weight check. */
8ff56318
JBD
403 new_weight = exist_weight = 0;
404
405 if (newattre)
406 new_weight = newattre->weight;
407 if (existattre)
408 exist_weight = existattre->weight;
409
fb982c25 410 if (new_weight > exist_weight)
9fbdd100
DS
411 {
412 if (debug)
2ec1e66f
DW
413 zlog_debug("%s: %s wins over %s due to weight %d > %d",
414 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
9fbdd100
DS
415 return 1;
416 }
417
fb982c25 418 if (new_weight < exist_weight)
9fbdd100
DS
419 {
420 if (debug)
2ec1e66f
DW
421 zlog_debug("%s: %s loses to %s due to weight %d < %d",
422 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
9fbdd100
DS
423 return 0;
424 }
718e3744 425
426 /* 2. Local preference check. */
8ff56318
JBD
427 new_pref = exist_pref = bgp->default_local_pref;
428
429 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
430 new_pref = newattr->local_pref;
431 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
432 exist_pref = existattr->local_pref;
718e3744 433
718e3744 434 if (new_pref > exist_pref)
9fbdd100
DS
435 {
436 if (debug)
2ec1e66f
DW
437 zlog_debug("%s: %s wins over %s due to localpref %d > %d",
438 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
9fbdd100
DS
439 return 1;
440 }
441
718e3744 442 if (new_pref < exist_pref)
9fbdd100
DS
443 {
444 if (debug)
2ec1e66f
DW
445 zlog_debug("%s: %s loses to %s due to localpref %d < %d",
446 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
9fbdd100
DS
447 return 0;
448 }
718e3744 449
8ff56318
JBD
450 /* 3. Local route check. We prefer:
451 * - BGP_ROUTE_STATIC
452 * - BGP_ROUTE_AGGREGATE
453 * - BGP_ROUTE_REDISTRIBUTE
454 */
455 if (! (new->sub_type == BGP_ROUTE_NORMAL))
9fbdd100
DS
456 {
457 if (debug)
2ec1e66f
DW
458 zlog_debug("%s: %s wins over %s due to preferred BGP_ROUTE type",
459 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
460 return 1;
461 }
462
8ff56318 463 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
9fbdd100
DS
464 {
465 if (debug)
2ec1e66f
DW
466 zlog_debug("%s: %s loses to %s due to preferred BGP_ROUTE type",
467 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
468 return 0;
469 }
718e3744 470
471 /* 4. AS path length check. */
472 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
473 {
8ff56318
JBD
474 int exist_hops = aspath_count_hops (existattr->aspath);
475 int exist_confeds = aspath_count_confeds (existattr->aspath);
fe69a505 476
6811845b 477 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
478 {
fe69a505 479 int aspath_hops;
480
8ff56318
JBD
481 aspath_hops = aspath_count_hops (newattr->aspath);
482 aspath_hops += aspath_count_confeds (newattr->aspath);
fe69a505 483
484 if ( aspath_hops < (exist_hops + exist_confeds))
9fbdd100
DS
485 {
486 if (debug)
2ec1e66f
DW
487 zlog_debug("%s: %s wins over %s due to aspath (with confeds) hopcount %d < %d",
488 pfx_buf, new_buf, exist_buf,
9fbdd100
DS
489 aspath_hops, (exist_hops + exist_confeds));
490 return 1;
491 }
492
fe69a505 493 if ( aspath_hops > (exist_hops + exist_confeds))
9fbdd100
DS
494 {
495 if (debug)
2ec1e66f
DW
496 zlog_debug("%s: %s loses to %s due to aspath (with confeds) hopcount %d > %d",
497 pfx_buf, new_buf, exist_buf,
9fbdd100
DS
498 aspath_hops, (exist_hops + exist_confeds));
499 return 0;
500 }
6811845b 501 }
502 else
503 {
8ff56318 504 int newhops = aspath_count_hops (newattr->aspath);
fe69a505 505
506 if (newhops < exist_hops)
9fbdd100
DS
507 {
508 if (debug)
2ec1e66f
DW
509 zlog_debug("%s: %s wins over %s due to aspath hopcount %d < %d",
510 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
9fbdd100
DS
511 return 1;
512 }
513
fe69a505 514 if (newhops > exist_hops)
9fbdd100
DS
515 {
516 if (debug)
2ec1e66f
DW
517 zlog_debug("%s: %s loses to %s due to aspath hopcount %d > %d",
518 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
9fbdd100
DS
519 return 0;
520 }
6811845b 521 }
718e3744 522 }
523
524 /* 5. Origin check. */
8ff56318 525 if (newattr->origin < existattr->origin)
9fbdd100
DS
526 {
527 if (debug)
2ec1e66f
DW
528 zlog_debug("%s: %s wins over %s due to ORIGIN %s < %s",
529 pfx_buf, new_buf, exist_buf,
9fbdd100
DS
530 bgp_origin_long_str[newattr->origin],
531 bgp_origin_long_str[existattr->origin]);
532 return 1;
533 }
534
8ff56318 535 if (newattr->origin > existattr->origin)
9fbdd100
DS
536 {
537 if (debug)
2ec1e66f
DW
538 zlog_debug("%s: %s loses to %s due to ORIGIN %s > %s",
539 pfx_buf, new_buf, exist_buf,
9fbdd100
DS
540 bgp_origin_long_str[newattr->origin],
541 bgp_origin_long_str[existattr->origin]);
542 return 0;
543 }
718e3744 544
545 /* 6. MED check. */
8ff56318
JBD
546 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
547 && aspath_count_hops (existattr->aspath) == 0);
548 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
549 && aspath_count_confeds (existattr->aspath) > 0
550 && aspath_count_hops (newattr->aspath) == 0
551 && aspath_count_hops (existattr->aspath) == 0);
718e3744 552
553 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
554 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
555 && confed_as_route)
8ff56318
JBD
556 || aspath_cmp_left (newattr->aspath, existattr->aspath)
557 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
718e3744 558 || internal_as_route)
559 {
560 new_med = bgp_med_value (new->attr, bgp);
561 exist_med = bgp_med_value (exist->attr, bgp);
562
563 if (new_med < exist_med)
9fbdd100
DS
564 {
565 if (debug)
2ec1e66f
DW
566 zlog_debug("%s: %s wins over %s due to MED %d < %d",
567 pfx_buf, new_buf, exist_buf, new_med, exist_med);
9fbdd100
DS
568 return 1;
569 }
570
718e3744 571 if (new_med > exist_med)
9fbdd100
DS
572 {
573 if (debug)
2ec1e66f
DW
574 zlog_debug("%s: %s loses to %s due to MED %d > %d",
575 pfx_buf, new_buf, exist_buf, new_med, exist_med);
9fbdd100
DS
576 return 0;
577 }
718e3744 578 }
579
580 /* 7. Peer type check. */
8ff56318
JBD
581 new_sort = new->peer->sort;
582 exist_sort = exist->peer->sort;
583
584 if (new_sort == BGP_PEER_EBGP
585 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
9fbdd100
DS
586 {
587 if (debug)
2ec1e66f
DW
588 zlog_debug("%s: %s wins over %s due to eBGP peer > iBGP peer",
589 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
590 return 1;
591 }
592
8ff56318
JBD
593 if (exist_sort == BGP_PEER_EBGP
594 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
9fbdd100
DS
595 {
596 if (debug)
2ec1e66f
DW
597 zlog_debug("%s: %s loses to %s due to iBGP peer < eBGP peer",
598 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
599 return 0;
600 }
718e3744 601
602 /* 8. IGP metric check. */
8ff56318
JBD
603 newm = existm = 0;
604
605 if (new->extra)
606 newm = new->extra->igpmetric;
607 if (exist->extra)
608 existm = exist->extra->igpmetric;
609
96450faf 610 if (newm < existm)
9fbdd100
DS
611 {
612 if (debug)
2ec1e66f
DW
613 zlog_debug("%s: %s wins over %s due to IGP metric %d < %d",
614 pfx_buf, new_buf, exist_buf, newm, existm);
9fbdd100
DS
615 ret = 1;
616 }
617
96450faf 618 if (newm > existm)
9fbdd100
DS
619 {
620 if (debug)
2ec1e66f
DW
621 zlog_debug("%s: %s loses to %s due to IGP metric %d > %d",
622 pfx_buf, new_buf, exist_buf, newm, existm);
9fbdd100
DS
623 ret = 0;
624 }
718e3744 625
31a4638f 626 /* 9. Same IGP metric. Compare the cluster list length as
5e242b0d
DS
627 representative of IGP hops metric. Rewrite the metric value
628 pair (newm, existm) with the cluster list length. Prefer the
629 path with smaller cluster list length. */
630 if (newm == existm)
631 {
632 if (peer_sort (new->peer) == BGP_PEER_IBGP
633 && peer_sort (exist->peer) == BGP_PEER_IBGP
53a7a065
LB
634 && (mpath_cfg == NULL ||
635 CHECK_FLAG (mpath_cfg->ibgp_flags,
636 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN)))
5e242b0d
DS
637 {
638 newm = BGP_CLUSTER_LIST_LENGTH(new->attr);
639 existm = BGP_CLUSTER_LIST_LENGTH(exist->attr);
9fbdd100 640
5e242b0d 641 if (newm < existm)
9fbdd100
DS
642 {
643 if (debug)
2ec1e66f
DW
644 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
645 pfx_buf, new_buf, exist_buf, newm, existm);
9fbdd100
DS
646 ret = 1;
647 }
648
5e242b0d 649 if (newm > existm)
9fbdd100
DS
650 {
651 if (debug)
2ec1e66f
DW
652 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
653 pfx_buf, new_buf, exist_buf, newm, existm);
9fbdd100
DS
654 ret = 0;
655 }
5e242b0d
DS
656 }
657 }
658
31a4638f
DS
659 /* 10. confed-external vs. confed-internal */
660 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
661 {
662 if (new_sort == BGP_PEER_CONFED && exist_sort == BGP_PEER_IBGP)
663 {
664 if (debug)
2ec1e66f
DW
665 zlog_debug("%s: %s wins over %s due to confed-external peer > confed-internal peer",
666 pfx_buf, new_buf, exist_buf);
31a4638f
DS
667 return 1;
668 }
669
670 if (exist_sort == BGP_PEER_CONFED && new_sort == BGP_PEER_IBGP)
671 {
672 if (debug)
2ec1e66f
DW
673 zlog_debug("%s: %s loses to %s due to confed-internal peer < confed-external peer",
674 pfx_buf, new_buf, exist_buf);
31a4638f
DS
675 return 0;
676 }
677 }
678
679 /* 11. Maximum path check. */
96450faf
JB
680 if (newm == existm)
681 {
2fdd455c
PM
682 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
683 {
684
685 /*
686 * For the two paths, all comparison steps till IGP metric
687 * have succeeded - including AS_PATH hop count. Since 'bgp
688 * bestpath as-path multipath-relax' knob is on, we don't need
689 * an exact match of AS_PATH. Thus, mark the paths are equal.
690 * That will trigger both these paths to get into the multipath
691 * array.
692 */
693 *paths_eq = 1;
9fbdd100
DS
694
695 if (debug)
2ec1e66f
DW
696 zlog_debug("%s: %s and %s are equal via multipath-relax",
697 pfx_buf, new_buf, exist_buf);
2fdd455c
PM
698 }
699 else if (new->peer->sort == BGP_PEER_IBGP)
96450faf
JB
700 {
701 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
9fbdd100
DS
702 {
703 *paths_eq = 1;
704
705 if (debug)
2ec1e66f
DW
706 zlog_debug("%s: %s and %s are equal via matching aspaths",
707 pfx_buf, new_buf, exist_buf);
9fbdd100 708 }
96450faf
JB
709 }
710 else if (new->peer->as == exist->peer->as)
9fbdd100
DS
711 {
712 *paths_eq = 1;
713
714 if (debug)
2ec1e66f
DW
715 zlog_debug("%s: %s and %s are equal via same remote-as",
716 pfx_buf, new_buf, exist_buf);
9fbdd100 717 }
96450faf
JB
718 }
719 else
720 {
721 /*
722 * TODO: If unequal cost ibgp multipath is enabled we can
723 * mark the paths as equal here instead of returning
724 */
a6086ad4 725 if (debug)
726 {
727 if (ret == 1)
728 zlog_debug("%s: %s wins over %s after IGP metric comparison",
729 pfx_buf, new_buf, exist_buf);
730 else
731 zlog_debug("%s: %s loses to %s after IGP metric comparison",
732 pfx_buf, new_buf, exist_buf);
733 }
96450faf
JB
734 return ret;
735 }
718e3744 736
31a4638f 737 /* 12. If both paths are external, prefer the path that was received
718e3744 738 first (the oldest one). This step minimizes route-flap, since a
739 newer path won't displace an older one, even if it was the
740 preferred route based on the additional decision criteria below. */
741 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
8ff56318
JBD
742 && new_sort == BGP_PEER_EBGP
743 && exist_sort == BGP_PEER_EBGP)
718e3744 744 {
745 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
9fbdd100
DS
746 {
747 if (debug)
2ec1e66f
DW
748 zlog_debug("%s: %s wins over %s due to oldest external",
749 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
750 return 1;
751 }
752
718e3744 753 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
9fbdd100
DS
754 {
755 if (debug)
2ec1e66f
DW
756 zlog_debug("%s: %s loses to %s due to oldest external",
757 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
758 return 0;
759 }
718e3744 760 }
761
31a4638f 762 /* 13. Router-ID comparision. */
0de5153c
DS
763 /* If one of the paths is "stale", the corresponding peer router-id will
764 * be 0 and would always win over the other path. If originator id is
765 * used for the comparision, it will decide which path is better.
766 */
8ff56318
JBD
767 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
768 new_id.s_addr = newattre->originator_id.s_addr;
718e3744 769 else
770 new_id.s_addr = new->peer->remote_id.s_addr;
8ff56318
JBD
771 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
772 exist_id.s_addr = existattre->originator_id.s_addr;
718e3744 773 else
774 exist_id.s_addr = exist->peer->remote_id.s_addr;
775
776 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
9fbdd100
DS
777 {
778 if (debug)
2ec1e66f
DW
779 zlog_debug("%s: %s wins over %s due to Router-ID comparison",
780 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
781 return 1;
782 }
783
718e3744 784 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
9fbdd100
DS
785 {
786 if (debug)
2ec1e66f
DW
787 zlog_debug("%s: %s loses to %s due to Router-ID comparison",
788 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
789 return 0;
790 }
718e3744 791
31a4638f 792 /* 14. Cluster length comparision. */
5e242b0d
DS
793 new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
794 exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
718e3744 795
796 if (new_cluster < exist_cluster)
9fbdd100
DS
797 {
798 if (debug)
2ec1e66f
DW
799 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
800 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
9fbdd100
DS
801 return 1;
802 }
803
718e3744 804 if (new_cluster > exist_cluster)
9fbdd100
DS
805 {
806 if (debug)
2ec1e66f
DW
807 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
808 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
9fbdd100
DS
809 return 0;
810 }
718e3744 811
31a4638f 812 /* 15. Neighbor address comparision. */
0de5153c
DS
813 /* Do this only if neither path is "stale" as stale paths do not have
814 * valid peer information (as the connection may or may not be up).
815 */
816 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
9fbdd100
DS
817 {
818 if (debug)
2ec1e66f
DW
819 zlog_debug("%s: %s wins over %s due to latter path being STALE",
820 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
821 return 1;
822 }
823
0de5153c 824 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
9fbdd100
DS
825 {
826 if (debug)
2ec1e66f
DW
827 zlog_debug("%s: %s loses to %s due to former path being STALE",
828 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
829 return 0;
830 }
0de5153c 831
43ed4fe5
TT
832 /* locally configured routes to advertise do not have su_remote */
833 if (new->peer->su_remote == NULL)
834 return 0;
835 if (exist->peer->su_remote == NULL)
836 return 1;
837
718e3744 838 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
839
840 if (ret == 1)
9fbdd100
DS
841 {
842 if (debug)
2ec1e66f
DW
843 zlog_debug("%s: %s loses to %s due to Neighor IP comparison",
844 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
845 return 0;
846 }
847
718e3744 848 if (ret == -1)
9fbdd100
DS
849 {
850 if (debug)
2ec1e66f
DW
851 zlog_debug("%s: %s wins over %s due to Neighor IP comparison",
852 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
853 return 1;
854 }
855
856 if (debug)
2ec1e66f
DW
857 zlog_debug("%s: %s wins over %s due to nothing left to compare",
858 pfx_buf, new_buf, exist_buf);
718e3744 859
860 return 1;
861}
862
65efcfce
LB
863/* Compare two bgp route entity. Return -1 if new is preferred, 1 if exist
864 * is preferred, or 0 if they are the same (usually will only occur if
865 * multipath is enabled
866 * This version is compatible with */
867int
868bgp_info_cmp_compatible (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
869 afi_t afi, safi_t safi)
870{
871 int paths_eq;
65efcfce 872 int ret;
53a7a065 873 ret = bgp_info_cmp (bgp, new, exist, &paths_eq, NULL, 0, __func__);
65efcfce
LB
874
875 if (paths_eq)
876 ret = 0;
877 else
878 {
879 if (ret == 1)
880 ret = -1;
881 else
882 ret = 1;
883 }
884 return ret;
885}
886
94f2b392 887static enum filter_type
718e3744 888bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
889 afi_t afi, safi_t safi)
890{
891 struct bgp_filter *filter;
892
893 filter = &peer->filter[afi][safi];
894
650f76c2
PJ
895#define FILTER_EXIST_WARN(F,f,filter) \
896 if (BGP_DEBUG (update, UPDATE_IN) \
897 && !(F ## _IN (filter))) \
16286195 898 zlog_warn ("%s: Could not find configured input %s-list %s!", \
650f76c2
PJ
899 peer->host, #f, F ## _IN_NAME(filter));
900
901 if (DISTRIBUTE_IN_NAME (filter)) {
902 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
903
718e3744 904 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
905 return FILTER_DENY;
650f76c2 906 }
718e3744 907
650f76c2
PJ
908 if (PREFIX_LIST_IN_NAME (filter)) {
909 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
910
718e3744 911 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
912 return FILTER_DENY;
650f76c2 913 }
718e3744 914
650f76c2
PJ
915 if (FILTER_LIST_IN_NAME (filter)) {
916 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
917
718e3744 918 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
919 return FILTER_DENY;
650f76c2
PJ
920 }
921
718e3744 922 return FILTER_PERMIT;
650f76c2 923#undef FILTER_EXIST_WARN
718e3744 924}
925
94f2b392 926static enum filter_type
718e3744 927bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
928 afi_t afi, safi_t safi)
929{
930 struct bgp_filter *filter;
931
932 filter = &peer->filter[afi][safi];
933
650f76c2
PJ
934#define FILTER_EXIST_WARN(F,f,filter) \
935 if (BGP_DEBUG (update, UPDATE_OUT) \
936 && !(F ## _OUT (filter))) \
16286195 937 zlog_warn ("%s: Could not find configured output %s-list %s!", \
650f76c2
PJ
938 peer->host, #f, F ## _OUT_NAME(filter));
939
940 if (DISTRIBUTE_OUT_NAME (filter)) {
941 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
942
718e3744 943 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
944 return FILTER_DENY;
650f76c2 945 }
718e3744 946
650f76c2
PJ
947 if (PREFIX_LIST_OUT_NAME (filter)) {
948 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
949
718e3744 950 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
951 return FILTER_DENY;
650f76c2 952 }
718e3744 953
650f76c2
PJ
954 if (FILTER_LIST_OUT_NAME (filter)) {
955 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
956
718e3744 957 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
958 return FILTER_DENY;
650f76c2 959 }
718e3744 960
961 return FILTER_PERMIT;
650f76c2 962#undef FILTER_EXIST_WARN
718e3744 963}
964
965/* If community attribute includes no_export then return 1. */
94f2b392 966static int
718e3744 967bgp_community_filter (struct peer *peer, struct attr *attr)
968{
969 if (attr->community)
970 {
971 /* NO_ADVERTISE check. */
972 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
973 return 1;
974
975 /* NO_EXPORT check. */
6d85b15b 976 if (peer->sort == BGP_PEER_EBGP &&
718e3744 977 community_include (attr->community, COMMUNITY_NO_EXPORT))
978 return 1;
979
980 /* NO_EXPORT_SUBCONFED check. */
6d85b15b
JBD
981 if (peer->sort == BGP_PEER_EBGP
982 || peer->sort == BGP_PEER_CONFED)
718e3744 983 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
984 return 1;
985 }
986 return 0;
987}
988
989/* Route reflection loop check. */
990static int
991bgp_cluster_filter (struct peer *peer, struct attr *attr)
992{
993 struct in_addr cluster_id;
994
fb982c25 995 if (attr->extra && attr->extra->cluster)
718e3744 996 {
997 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
998 cluster_id = peer->bgp->cluster_id;
999 else
1000 cluster_id = peer->bgp->router_id;
1001
fb982c25 1002 if (cluster_loop_check (attr->extra->cluster, cluster_id))
718e3744 1003 return 1;
1004 }
1005 return 0;
1006}
6b0655a2 1007
94f2b392 1008static int
718e3744 1009bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
ffd0c037 1010 afi_t afi, safi_t safi, const char *rmap_name)
718e3744 1011{
1012 struct bgp_filter *filter;
1013 struct bgp_info info;
1014 route_map_result_t ret;
0b16f239 1015 struct route_map *rmap = NULL;
718e3744 1016
1017 filter = &peer->filter[afi][safi];
1018
1019 /* Apply default weight value. */
d93f7ffc
DW
1020 if (peer->weight[afi][safi])
1021 (bgp_attr_extra_get (attr))->weight = peer->weight[afi][safi];
718e3744 1022
0b16f239
DS
1023 if (rmap_name)
1024 {
1025 rmap = route_map_lookup_by_name(rmap_name);
98a4a44e
DS
1026
1027 if (rmap == NULL)
1028 return RMAP_DENY;
0b16f239
DS
1029 }
1030 else
1031 {
1032 if (ROUTE_MAP_IN_NAME(filter))
98a4a44e
DS
1033 {
1034 rmap = ROUTE_MAP_IN (filter);
1035
1036 if (rmap == NULL)
1037 return RMAP_DENY;
1038 }
0b16f239
DS
1039 }
1040
718e3744 1041 /* Route map apply. */
0b16f239 1042 if (rmap)
718e3744 1043 {
1044 /* Duplicate current value to new strucutre for modification. */
1045 info.peer = peer;
1046 info.attr = attr;
1047
ac41b2a2 1048 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
1049
718e3744 1050 /* Apply BGP route map to the attribute. */
0b16f239
DS
1051 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1052
1053 peer->rmap_type = 0;
1054
1055 if (ret == RMAP_DENYMATCH)
1056 {
1057 /* Free newly generated AS path and community by route-map. */
1058 bgp_attr_flush (attr);
1059 return RMAP_DENY;
1060 }
1061 }
1062 return RMAP_PERMIT;
1063}
1064
1065static int
1066bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
ffd0c037 1067 afi_t afi, safi_t safi, const char *rmap_name)
0b16f239
DS
1068{
1069 struct bgp_filter *filter;
1070 struct bgp_info info;
1071 route_map_result_t ret;
1072 struct route_map *rmap = NULL;
1073
1074 filter = &peer->filter[afi][safi];
1075
1076 /* Apply default weight value. */
d93f7ffc
DW
1077 if (peer->weight[afi][safi])
1078 (bgp_attr_extra_get (attr))->weight = peer->weight[afi][safi];
0b16f239
DS
1079
1080 if (rmap_name)
1081 {
1082 rmap = route_map_lookup_by_name(rmap_name);
98a4a44e
DS
1083
1084 if (rmap == NULL)
1085 return RMAP_DENY;
0b16f239
DS
1086 }
1087 else
1088 {
1089 if (ROUTE_MAP_OUT_NAME(filter))
98a4a44e
DS
1090 {
1091 rmap = ROUTE_MAP_OUT (filter);
1092
1093 if (rmap == NULL)
1094 return RMAP_DENY;
1095 }
0b16f239
DS
1096 }
1097
1098 /* Route map apply. */
1099 if (rmap)
1100 {
1101 /* Duplicate current value to new strucutre for modification. */
1102 info.peer = peer;
1103 info.attr = attr;
1104
1105 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1106
1107 /* Apply BGP route map to the attribute. */
1108 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
ac41b2a2 1109
1110 peer->rmap_type = 0;
1111
718e3744 1112 if (ret == RMAP_DENYMATCH)
c460e572
DL
1113 /* caller has multiple error paths with bgp_attr_flush() */
1114 return RMAP_DENY;
718e3744 1115 }
1116 return RMAP_PERMIT;
1117}
6b0655a2 1118
5000f21c 1119/* If this is an EBGP peer with remove-private-AS */
ffd0c037 1120static void
5000f21c
DS
1121bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
1122 struct peer *peer, struct attr *attr)
1123{
1124 if (peer->sort == BGP_PEER_EBGP &&
88b8ed8d
DW
1125 (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1126 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE) ||
1127 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL) ||
1128 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)))
5000f21c
DS
1129 {
1130 // Take action on the entire aspath
88b8ed8d
DW
1131 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1132 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
5000f21c 1133 {
88b8ed8d 1134 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
5000f21c
DS
1135 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1136
1137 // The entire aspath consists of private ASNs so create an empty aspath
1138 else if (aspath_private_as_check (attr->aspath))
1139 attr->aspath = aspath_empty_get ();
1140
1141 // There are some public and some private ASNs, remove the private ASNs
1142 else
1143 attr->aspath = aspath_remove_private_asns (attr->aspath);
1144 }
1145
1146 // 'all' was not specified so the entire aspath must be private ASNs
1147 // for us to do anything
1148 else if (aspath_private_as_check (attr->aspath))
1149 {
1150 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
1151 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1152 else
1153 attr->aspath = aspath_empty_get ();
1154 }
1155 }
1156}
1157
c7122e14
DS
1158/* If this is an EBGP peer with as-override */
1159static void
1160bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
1161 struct peer *peer, struct attr *attr)
1162{
1163 if (peer->sort == BGP_PEER_EBGP &&
1164 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
1165 {
1166 if (aspath_single_asn_check (attr->aspath, peer->as))
1167 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
1168 }
1169}
1170
3f9c7369
DS
1171static void
1172subgroup_announce_reset_nhop (u_char family, struct attr *attr)
1173{
1174 if (family == AF_INET)
1175 attr->nexthop.s_addr = 0;
1176#ifdef HAVE_IPV6
1177 if (family == AF_INET6)
1178 memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
1179#endif
1180}
1181
1182int
1183subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp,
1184 struct prefix *p, struct attr *attr)
1185{
1186 struct bgp_filter *filter;
1187 struct peer *from;
1188 struct peer *peer;
1189 struct peer *onlypeer;
1190 struct bgp *bgp;
1191 struct attr *riattr;
1192 struct peer_af *paf;
1193 char buf[SU_ADDRSTRLEN];
1194 int ret;
1195 int transparent;
1196 int reflect;
1197 afi_t afi;
1198 safi_t safi;
65efcfce 1199 int samepeer_safe = 0; /* for synthetic mplsvpns routes */
3f9c7369
DS
1200
1201 if (DISABLE_BGP_ANNOUNCE)
1202 return 0;
1203
1204 afi = SUBGRP_AFI(subgrp);
1205 safi = SUBGRP_SAFI(subgrp);
1206 peer = SUBGRP_PEER(subgrp);
1207 onlypeer = NULL;
1208 if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL))
1209 onlypeer = SUBGRP_PFIRST(subgrp)->peer;
1210
1211 from = ri->peer;
1212 filter = &peer->filter[afi][safi];
1213 bgp = SUBGRP_INST(subgrp);
1214 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1215
65efcfce
LB
1216#if ENABLE_BGP_VNC
1217 if (((afi == AFI_IP) || (afi == AFI_IP6)) && (safi == SAFI_MPLS_VPN) &&
1218 ((ri->type == ZEBRA_ROUTE_BGP_DIRECT) ||
1219 (ri->type == ZEBRA_ROUTE_BGP_DIRECT_EXT))) {
1220
1221 /*
1222 * direct and direct_ext type routes originate internally even
1223 * though they can have peer pointers that reference other systems
1224 */
1225 char buf[BUFSIZ];
1226 prefix2str(p, buf, BUFSIZ);
1227 zlog_debug("%s: pfx %s bgp_direct->vpn route peer safe", __func__, buf);
1228 samepeer_safe = 1;
1229 }
1230#endif
1231
adbac85e
DW
1232 /* With addpath we may be asked to TX all kinds of paths so make sure
1233 * ri is valid */
1234 if (!CHECK_FLAG (ri->flags, BGP_INFO_VALID) ||
1235 CHECK_FLAG (ri->flags, BGP_INFO_HISTORY) ||
1236 CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
1237 {
1238 return 0;
1239 }
1240
06370dac
DW
1241 /* If this is not the bestpath then check to see if there is an enabled addpath
1242 * feature that requires us to advertise it */
1243 if (! CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1244 {
1245 if (! bgp_addpath_tx_path(peer, afi, safi, ri))
1246 {
1247 return 0;
1248 }
1249 }
1250
3f9c7369
DS
1251 /* Aggregate-address suppress check. */
1252 if (ri->extra && ri->extra->suppress)
1253 if (! UNSUPPRESS_MAP_NAME (filter))
1254 {
1255 return 0;
1256 }
1257
3f9c7369
DS
1258 /* Do not send back route to sender. */
1259 if (onlypeer && from == onlypeer)
1260 {
1261 return 0;
1262 }
1263
4125bb67
DS
1264 /* Do not send the default route in the BGP table if the neighbor is
1265 * configured for default-originate */
1266 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
1267 {
1268 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1269 return 0;
1270#ifdef HAVE_IPV6
1271 else if (p->family == AF_INET6 && p->prefixlen == 0)
1272 return 0;
1273#endif /* HAVE_IPV6 */
1274 }
1275
3f9c7369
DS
1276 /* Transparency check. */
1277 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1278 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1279 transparent = 1;
1280 else
1281 transparent = 0;
1282
1283 /* If community is not disabled check the no-export and local. */
1284 if (! transparent && bgp_community_filter (peer, riattr))
1285 {
1286 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1287 zlog_debug ("subgrpannouncecheck: community filter check fail");
1288 return 0;
1289 }
1290
1291 /* If the attribute has originator-id and it is same as remote
1292 peer's id. */
1293 if (onlypeer &&
1294 riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) &&
1295 (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id)))
1296 {
1297 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1298 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as "
1299 "remote router-id",
1300 onlypeer->host,
1301 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1302 p->prefixlen);
1303 return 0;
1304 }
1305
1306 /* ORF prefix-list filter check */
1307 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1308 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1309 || CHECK_FLAG (peer->af_cap[afi][safi],
1310 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1311 if (peer->orf_plist[afi][safi])
1312 {
1313 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1314 {
40d2700d
DW
1315 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1316 zlog_debug ("%s [Update:SEND] %s/%d is filtered via ORF",
1317 peer->host,
1318 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1319 p->prefixlen);
3f9c7369
DS
1320 return 0;
1321 }
1322 }
1323
1324 /* Output filter check. */
1325 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1326 {
1327 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1328 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1329 peer->host,
1330 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1331 p->prefixlen);
1332 return 0;
1333 }
1334
1335#ifdef BGP_SEND_ASPATH_CHECK
1336 /* AS path loop check. */
1337 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
1338 {
1339 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1340 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1341 "that is part of AS path.",
1342 onlypeer->host, onlypeer->as);
1343 return 0;
1344 }
1345#endif /* BGP_SEND_ASPATH_CHECK */
1346
1347 /* If we're a CONFED we need to loop check the CONFED ID too */
1348 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1349 {
1350 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1351 {
1352 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1353 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u"
1354 " is AS path.",
1355 peer->host,
1356 bgp->confed_id);
1357 return 0;
1358 }
1359 }
1360
1361 /* Route-Reflect check. */
1362 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1363 reflect = 1;
1364 else
1365 reflect = 0;
1366
1367 /* IBGP reflection check. */
65efcfce 1368 if (reflect && !samepeer_safe)
3f9c7369
DS
1369 {
1370 /* A route from a Client peer. */
1371 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1372 {
1373 /* Reflect to all the Non-Client peers and also to the
1374 Client peers other than the originator. Originator check
1375 is already done. So there is noting to do. */
1376 /* no bgp client-to-client reflection check. */
1377 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1378 if (CHECK_FLAG (peer->af_flags[afi][safi],
1379 PEER_FLAG_REFLECTOR_CLIENT))
1380 return 0;
1381 }
1382 else
1383 {
1384 /* A route from a Non-client peer. Reflect to all other
1385 clients. */
1386 if (! CHECK_FLAG (peer->af_flags[afi][safi],
1387 PEER_FLAG_REFLECTOR_CLIENT))
1388 return 0;
1389 }
1390 }
1391
1392 /* For modify attribute, copy it to temporary structure. */
1393 bgp_attr_dup (attr, riattr);
1394
1395 /* If local-preference is not set. */
1396 if ((peer->sort == BGP_PEER_IBGP
1397 || peer->sort == BGP_PEER_CONFED)
1398 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1399 {
1400 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1401 attr->local_pref = bgp->default_local_pref;
1402 }
1403
1404 /* If originator-id is not set and the route is to be reflected,
1405 set the originator id */
1406 if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1407 {
1408 attr->extra = bgp_attr_extra_get(attr);
1409 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1410 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1411 }
1412
1413 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1414 if (peer->sort == BGP_PEER_EBGP
1415 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1416 {
003c1ba0 1417 if (from != bgp->peer_self && ! transparent
3f9c7369
DS
1418 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1419 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1420 }
1421
1422 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1423 * in announce check, only certain flags and length (or number of nexthops
1424 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1425 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1426 * Typically, the source nexthop in the attribute is preserved but in the
1427 * scenarios where we know it will always be overwritten, we reset the
1428 * nexthop to "0" in an attempt to achieve better Update packing. An
1429 * example of this is when a prefix from each of 2 IBGP peers needs to be
1430 * announced to an EBGP peer (and they have the same attributes barring
1431 * their nexthop).
1432 */
1433 if (reflect)
1434 SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
1435
1436#ifdef HAVE_IPV6
587ff0fd 1437#define NEXTHOP_IS_V6 (\
4c6f219a 1438 (safi != SAFI_ENCAP && safi != SAFI_MPLS_VPN &&\
587ff0fd 1439 (p->family == AF_INET6 || peer_cap_enhe(peer))) || \
7a4732c1 1440 ((safi == SAFI_ENCAP || safi == SAFI_MPLS_VPN) &&\
4c6f219a 1441 attr->extra->mp_nexthop_len >= IPV6_MAX_BYTELEN))
587ff0fd 1442
3811f1e2
DS
1443 /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if
1444 * the peer (group) is configured to receive link-local nexthop unchanged
1445 * and it is available in the prefix OR we're not reflecting the route and
1446 * the peer (group) to whom we're going to announce is on a shared network
003c1ba0 1447 * and this is either a self-originated route or the peer is EBGP.
3f9c7369 1448 */
587ff0fd 1449 if (NEXTHOP_IS_V6)
3f9c7369 1450 {
801a9bcc 1451 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
3811f1e2
DS
1452 if ((CHECK_FLAG (peer->af_flags[afi][safi],
1453 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1454 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) ||
003c1ba0 1455 (!reflect && peer->shared_network &&
1456 (from == bgp->peer_self || peer->sort == BGP_PEER_EBGP)))
3f9c7369 1457 {
3811f1e2 1458 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
3f9c7369
DS
1459 }
1460
3811f1e2
DS
1461 /* Clear off link-local nexthop in source, whenever it is not needed to
1462 * ensure more prefixes share the same attribute for announcement.
3f9c7369
DS
1463 */
1464 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1465 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1466 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1467 }
1468#endif /* HAVE_IPV6 */
1469
1470 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1471 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1472
1473 /* Route map & unsuppress-map apply. */
1474 if (ROUTE_MAP_OUT_NAME (filter)
1475 || (ri->extra && ri->extra->suppress) )
1476 {
1477 struct bgp_info info;
1478 struct attr dummy_attr;
1479 struct attr_extra dummy_extra;
1480
1481 dummy_attr.extra = &dummy_extra;
1482
1483 info.peer = peer;
1484 info.attr = attr;
316e074d
DS
1485 /* don't confuse inbound and outbound setting */
1486 RESET_FLAG(attr->rmap_change_flags);
3f9c7369
DS
1487
1488 /*
1489 * The route reflector is not allowed to modify the attributes
1490 * of the reflected IBGP routes unless explicitly allowed.
1491 */
1492 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1493 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1494 {
1495 bgp_attr_dup (&dummy_attr, attr);
1496 info.attr = &dummy_attr;
1497 }
1498
1499 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1500
1501 if (ri->extra && ri->extra->suppress)
1502 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1503 else
1504 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1505
1506 peer->rmap_type = 0;
1507
1508 if (ret == RMAP_DENYMATCH)
1509 {
1510 bgp_attr_flush (attr);
1511 return 0;
1512 }
1513 }
1514
1515 /* After route-map has been applied, we check to see if the nexthop to
1516 * be carried in the attribute (that is used for the announcement) can
1517 * be cleared off or not. We do this in all cases where we would be
1518 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1519 * the global nexthop here; the link-local nexthop would have been cleared
1520 * already, and if not, it is required by the update formation code.
1521 * Also see earlier comments in this function.
43fdf718 1522 */
3811f1e2
DS
1523 /*
1524 * If route-map has performed some operation on the nexthop or the peer
1525 * configuration says to pass it unchanged, we cannot reset the nexthop
1526 * here, so only attempt to do it if these aren't true. Note that the
1527 * route-map handler itself might have cleared the nexthop, if for example,
1528 * it is configured as 'peer-address'.
3f9c7369 1529 */
3811f1e2
DS
1530 if (!bgp_rmap_nhop_changed(attr->rmap_change_flags,
1531 riattr->rmap_change_flags) &&
1532 !transparent &&
1533 !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
3f9c7369 1534 {
3811f1e2 1535 /* We can reset the nexthop, if setting (or forcing) it to 'self' */
88b8ed8d
DW
1536 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
1537 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
3f9c7369
DS
1538 {
1539 if (!reflect ||
1540 CHECK_FLAG (peer->af_flags[afi][safi],
43fdf718 1541 PEER_FLAG_FORCE_NEXTHOP_SELF))
3811f1e2
DS
1542 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ?
1543 AF_INET6 : p->family), attr);
3f9c7369
DS
1544 }
1545 else if (peer->sort == BGP_PEER_EBGP)
1546 {
3811f1e2
DS
1547 /* Can also reset the nexthop if announcing to EBGP, but only if
1548 * no peer in the subgroup is on a shared subnet.
1549 * Note: 3rd party nexthop currently implemented for IPv4 only.
1550 */
3f9c7369
DS
1551 SUBGRP_FOREACH_PEER (subgrp, paf)
1552 {
1553 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1554 break;
1555 }
1556 if (!paf)
8a92a8a0 1557 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr);
3f9c7369 1558 }
003c1ba0 1559 /* If IPv6/MP and nexthop does not have any override and happens to
1560 * be a link-local address, reset it so that we don't pass along the
1561 * source's link-local IPv6 address to recipients who may not be on
1562 * the same interface.
1563 */
1564 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1565 {
1566 if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global))
1567 subgroup_announce_reset_nhop (AF_INET6, attr);
1568 }
3f9c7369
DS
1569 }
1570
1571 return 1;
1572}
1573
fee0f4c6 1574struct bgp_info_pair
1575{
1576 struct bgp_info *old;
1577 struct bgp_info *new;
1578};
1579
94f2b392 1580static void
96450faf
JB
1581bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1582 struct bgp_maxpaths_cfg *mpath_cfg,
1583 struct bgp_info_pair *result)
718e3744 1584{
718e3744 1585 struct bgp_info *new_select;
1586 struct bgp_info *old_select;
fee0f4c6 1587 struct bgp_info *ri;
718e3744 1588 struct bgp_info *ri1;
1589 struct bgp_info *ri2;
b40d939b 1590 struct bgp_info *nextri = NULL;
9fbdd100 1591 int paths_eq, do_mpath, debug;
96450faf 1592 struct list mp_list;
4690c7d7 1593 char pfx_buf[PREFIX2STR_BUFFER];
2ec1e66f 1594 char path_buf[PATH_ADDPATH_STR_BUFFER];
96450faf
JB
1595
1596 bgp_mp_list_init (&mp_list);
99030da1 1597 do_mpath = (mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1);
96450faf 1598
9fbdd100
DS
1599 debug = bgp_debug_bestpath(&rn->p);
1600
1601 if (debug)
1602 prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf));
1603
718e3744 1604 /* bgp deterministic-med */
1605 new_select = NULL;
1606 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
06370dac
DW
1607 {
1608
1609 /* Clear BGP_INFO_DMED_SELECTED for all paths */
1610 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1611 bgp_info_unset_flag (rn, ri1, BGP_INFO_DMED_SELECTED);
1612
1613 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1614 {
1615 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1616 continue;
1617 if (BGP_INFO_HOLDDOWN (ri1))
2fed8887 1618 continue;
06370dac
DW
1619 if (ri1->peer && ri1->peer != bgp->peer_self)
1620 if (ri1->peer->status != Established)
1621 continue;
718e3744 1622
06370dac 1623 new_select = ri1;
06370dac
DW
1624 if (ri1->next)
1625 {
1626 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1627 {
1628 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1629 continue;
1630 if (BGP_INFO_HOLDDOWN (ri2))
1631 continue;
1632 if (ri2->peer &&
1633 ri2->peer != bgp->peer_self &&
1634 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1635 if (ri2->peer->status != Established)
1636 continue;
1637
1638 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1639 || aspath_cmp_left_confed (ri1->attr->aspath,
1640 ri2->attr->aspath))
1641 {
06370dac
DW
1642 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
1643 mpath_cfg, debug, pfx_buf))
1644 {
1645 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1646 new_select = ri2;
1647 }
1648
1649 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1650 }
1651 }
1652 }
1653 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1654 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
718e3744 1655
06370dac 1656 if (debug)
2ec1e66f
DW
1657 {
1658 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1659 zlog_debug("%s: %s is the bestpath from AS %d",
aac9ef6c 1660 pfx_buf, path_buf, aspath_get_first_as(new_select->attr->aspath));
2ec1e66f 1661 }
06370dac
DW
1662 }
1663 }
718e3744 1664
1665 /* Check old selected route and new selected route. */
1666 old_select = NULL;
1667 new_select = NULL;
b40d939b 1668 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
718e3744 1669 {
1670 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1671 old_select = ri;
1672
1673 if (BGP_INFO_HOLDDOWN (ri))
b40d939b 1674 {
1675 /* reap REMOVED routes, if needs be
1676 * selected route must stay for a while longer though
1677 */
1678 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1679 && (ri != old_select))
1680 bgp_info_reap (rn, ri);
1681
1682 continue;
1683 }
718e3744 1684
2fed8887
DS
1685 if (ri->peer &&
1686 ri->peer != bgp->peer_self &&
1687 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1688 if (ri->peer->status != Established)
1689 continue;
1690
718e3744 1691 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1692 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1693 {
1a392d46 1694 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
718e3744 1695 continue;
1696 }
06370dac 1697
1a392d46 1698 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
718e3744 1699
9fbdd100 1700 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
96450faf
JB
1701 {
1702 new_select = ri;
96450faf 1703 }
718e3744 1704 }
b40d939b 1705
f4eeff72
DS
1706 /* Now that we know which path is the bestpath see if any of the other paths
1707 * qualify as multipaths
1708 */
a6086ad4 1709 if (debug)
f4eeff72 1710 {
a6086ad4 1711 if (new_select)
1712 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1713 else
1714 sprintf (path_buf, "NONE");
1715 zlog_debug("%s: After path selection, newbest is %s oldbest was %s",
1716 pfx_buf, path_buf,
1717 old_select ? old_select->peer->host : "NONE");
1718 }
9fbdd100 1719
a6086ad4 1720 if (do_mpath && new_select)
1721 {
f4eeff72
DS
1722 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1723 {
2ec1e66f
DW
1724
1725 if (debug)
1726 bgp_info_path_with_addpath_rx_str (ri, path_buf);
1727
f4eeff72
DS
1728 if (ri == new_select)
1729 {
9fbdd100 1730 if (debug)
2ec1e66f
DW
1731 zlog_debug("%s: %s is the bestpath, add to the multipath list",
1732 pfx_buf, path_buf);
3064bf43 1733 bgp_mp_list_add (&mp_list, ri);
f4eeff72
DS
1734 continue;
1735 }
1736
1737 if (BGP_INFO_HOLDDOWN (ri))
1738 continue;
1739
1740 if (ri->peer &&
1741 ri->peer != bgp->peer_self &&
1742 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1743 if (ri->peer->status != Established)
1744 continue;
1745
7dc9d4e4
DW
1746 if (!bgp_info_nexthop_cmp (ri, new_select))
1747 {
1748 if (debug)
2ec1e66f
DW
1749 zlog_debug("%s: %s has the same nexthop as the bestpath, skip it",
1750 pfx_buf, path_buf);
7dc9d4e4
DW
1751 continue;
1752 }
1753
9fbdd100 1754 bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
f4eeff72
DS
1755
1756 if (paths_eq)
1757 {
9fbdd100 1758 if (debug)
2ec1e66f
DW
1759 zlog_debug("%s: %s is equivalent to the bestpath, add to the multipath list",
1760 pfx_buf, path_buf);
f4eeff72
DS
1761 bgp_mp_list_add (&mp_list, ri);
1762 }
1763 }
1764 }
fee0f4c6 1765
b354c427 1766 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
0b597ef0 1767 bgp_info_mpath_aggregate_update (new_select, old_select);
96450faf
JB
1768 bgp_mp_list_clear (&mp_list);
1769
1770 result->old = old_select;
1771 result->new = new_select;
1772
1773 return;
fee0f4c6 1774}
1775
3f9c7369
DS
1776/*
1777 * A new route/change in bestpath of an existing route. Evaluate the path
1778 * for advertisement to the subgroup.
1779 */
1780int
1781subgroup_process_announce_selected (struct update_subgroup *subgrp,
1782 struct bgp_info *selected,
adbac85e
DW
1783 struct bgp_node *rn,
1784 u_int32_t addpath_tx_id)
9eda90ce 1785{
fee0f4c6 1786 struct prefix *p;
3f9c7369 1787 struct peer *onlypeer;
558d1fec
JBD
1788 struct attr attr;
1789 struct attr_extra extra;
3f9c7369
DS
1790 afi_t afi;
1791 safi_t safi;
fee0f4c6 1792
1793 p = &rn->p;
3f9c7369
DS
1794 afi = SUBGRP_AFI(subgrp);
1795 safi = SUBGRP_SAFI(subgrp);
1796 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1797 (SUBGRP_PFIRST(subgrp))->peer : NULL);
718e3744 1798
9eda90ce 1799 /* First update is deferred until ORF or ROUTE-REFRESH is received */
3f9c7369
DS
1800 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
1801 PEER_STATUS_ORF_WAIT_REFRESH))
fee0f4c6 1802 return 0;
718e3744 1803
bede7744 1804 memset(&extra, 0, sizeof(struct attr_extra));
2a3d5731 1805 /* It's initialized in bgp_announce_check() */
558d1fec
JBD
1806 attr.extra = &extra;
1807
2a3d5731
DW
1808 /* Announcement to the subgroup. If the route is filtered withdraw it. */
1809 if (selected)
fee0f4c6 1810 {
2a3d5731
DW
1811 if (subgroup_announce_check(selected, subgrp, p, &attr))
1812 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
1813 else
1814 bgp_adj_out_unset_subgroup(rn, subgrp, 1, selected->addpath_tx_id);
1815 }
adbac85e 1816
2a3d5731
DW
1817 /* If selected is NULL we must withdraw the path using addpath_tx_id */
1818 else
1819 {
1820 bgp_adj_out_unset_subgroup(rn, subgrp, 1, addpath_tx_id);
fee0f4c6 1821 }
558d1fec 1822
fee0f4c6 1823 return 0;
200df115 1824}
fee0f4c6 1825
3064bf43 1826/*
e1072051 1827 * Clear IGP changed flag and attribute changed flag for a route (all paths).
1828 * This is called at the end of route processing.
3064bf43 1829 */
1830static void
1831bgp_zebra_clear_route_change_flags (struct bgp_node *rn)
1832{
1833 struct bgp_info *ri;
1834
1835 for (ri = rn->info; ri; ri = ri->next)
1836 {
1837 if (BGP_INFO_HOLDDOWN (ri))
1838 continue;
1839 UNSET_FLAG (ri->flags, BGP_INFO_IGP_CHANGED);
e1072051 1840 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3064bf43 1841 }
1842}
1843
1844/*
1845 * Has the route changed from the RIB's perspective? This is invoked only
1846 * if the route selection returns the same best route as earlier - to
1847 * determine if we need to update zebra or not.
1848 */
1849static int
1850bgp_zebra_has_route_changed (struct bgp_node *rn, struct bgp_info *selected)
1851{
1852 struct bgp_info *mpinfo;
1853
e1072051 1854 /* If this is multipath, check all selected paths for any nexthop change or
1855 * attribute change. Some attribute changes (e.g., community) aren't of
1856 * relevance to the RIB, but we'll update zebra to ensure we handle the
1857 * case of BGP nexthop change. This is the behavior when the best path has
1858 * an attribute change anyway.
1859 */
3064bf43 1860 if (CHECK_FLAG (selected->flags, BGP_INFO_IGP_CHANGED) ||
1861 CHECK_FLAG (selected->flags, BGP_INFO_MULTIPATH_CHG))
1862 return 1;
1863
1864 /* If this is multipath, check all selected paths for any nexthop change */
1865 for (mpinfo = bgp_info_mpath_first (selected); mpinfo;
1866 mpinfo = bgp_info_mpath_next (mpinfo))
1867 {
e1072051 1868 if (CHECK_FLAG (mpinfo->flags, BGP_INFO_IGP_CHANGED)
1869 || CHECK_FLAG (mpinfo->flags, BGP_INFO_ATTR_CHANGED))
3064bf43 1870 return 1;
1871 }
1872
1873 /* Nothing has changed from the RIB's perspective. */
1874 return 0;
1875}
1876
3f9c7369 1877struct bgp_process_queue
fee0f4c6 1878{
200df115 1879 struct bgp *bgp;
1880 struct bgp_node *rn;
1881 afi_t afi;
1882 safi_t safi;
1883};
1884
200df115 1885static wq_item_status
0fb58d5d 1886bgp_process_main (struct work_queue *wq, void *data)
200df115 1887{
0fb58d5d 1888 struct bgp_process_queue *pq = data;
200df115 1889 struct bgp *bgp = pq->bgp;
1890 struct bgp_node *rn = pq->rn;
1891 afi_t afi = pq->afi;
1892 safi_t safi = pq->safi;
1893 struct prefix *p = &rn->p;
fee0f4c6 1894 struct bgp_info *new_select;
1895 struct bgp_info *old_select;
1896 struct bgp_info_pair old_and_new;
cb1faec9
DS
1897
1898 /* Is it end of initial update? (after startup) */
1899 if (!rn)
1900 {
4a16ae86
DS
1901 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1902 sizeof(bgp->update_delay_zebra_resume_time));
1903
1904 bgp->main_zebra_update_hold = 0;
1905 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1906 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1907 {
1908 bgp_zebra_announce_table(bgp, afi, safi);
1909 }
1910 bgp->main_peers_update_hold = 0;
1911
cb1faec9
DS
1912 bgp_start_routeadv(bgp);
1913 return WQ_SUCCESS;
1914 }
1915
fee0f4c6 1916 /* Best path selection. */
96450faf 1917 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 1918 old_select = old_and_new.old;
1919 new_select = old_and_new.new;
1920
1921 /* Nothing to do. */
adbac85e
DW
1922 if (old_select && old_select == new_select &&
1923 !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR) &&
1924 !CHECK_FLAG(old_select->flags, BGP_INFO_ATTR_CHANGED) &&
1925 !bgp->addpath_tx_used[afi][safi])
1926 {
3064bf43 1927 if (bgp_zebra_has_route_changed (rn, old_select))
65efcfce
LB
1928 {
1929#if ENABLE_BGP_VNC
1930 vnc_import_bgp_add_route(bgp, p, old_select);
1931 vnc_import_bgp_exterior_add_route(bgp, p, old_select);
1932#endif
1933 bgp_zebra_announce (p, old_select, bgp, afi, safi);
1934 }
adbac85e 1935 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
3064bf43 1936 bgp_zebra_clear_route_change_flags (rn);
adbac85e
DW
1937 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1938 return WQ_SUCCESS;
fee0f4c6 1939 }
1940
8ad7271d
DS
1941 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1942 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1943
3f9c7369
DS
1944 /* bestpath has changed; bump version */
1945 if (old_select || new_select)
0de4848d
DS
1946 {
1947 bgp_bump_version(rn);
1948
1949 if (!bgp->t_rmap_def_originate_eval)
1950 {
1951 bgp_lock (bgp);
9229d914 1952 THREAD_TIMER_ON(bm->master, bgp->t_rmap_def_originate_eval,
0de4848d
DS
1953 update_group_refresh_default_originate_route_map,
1954 bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER);
1955 }
1956 }
3f9c7369 1957
338b3424 1958 if (old_select)
1a392d46 1959 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
338b3424 1960 if (new_select)
1961 {
1a392d46
PJ
1962 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1963 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 1964 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
338b3424 1965 }
1966
65efcfce
LB
1967#if ENABLE_BGP_VNC
1968 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
1969 if (old_select != new_select) {
1970 if (old_select) {
1971 vnc_import_bgp_exterior_del_route(bgp, p, old_select);
1972 vnc_import_bgp_del_route(bgp, p, old_select);
1973 }
1974 if (new_select) {
1975 vnc_import_bgp_exterior_add_route(bgp, p, new_select);
1976 vnc_import_bgp_add_route(bgp, p, new_select);
1977 }
1978 }
1979 }
1980#endif
1981
3f9c7369 1982 group_announce_route(bgp, afi, safi, rn, new_select);
718e3744 1983
1984 /* FIB update. */
ad4cbda1 1985 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) &&
1986 (bgp->inst_type != BGP_INSTANCE_TYPE_VIEW) &&
1987 !bgp_option_check (BGP_OPT_NO_FIB))
718e3744 1988 {
1989 if (new_select
1990 && new_select->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
1991 && (new_select->sub_type == BGP_ROUTE_NORMAL ||
1992 new_select->sub_type == BGP_ROUTE_AGGREGATE))
73ac8160 1993 bgp_zebra_announce (p, new_select, bgp, afi, safi);
718e3744 1994 else
1995 {
1996 /* Withdraw the route from the kernel. */
1997 if (old_select
1998 && old_select->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
1999 && (old_select->sub_type == BGP_ROUTE_NORMAL ||
2000 old_select->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 2001 bgp_zebra_withdraw (p, old_select, safi);
718e3744 2002 }
2003 }
3064bf43 2004
2005 /* Clear any route change flags. */
2006 bgp_zebra_clear_route_change_flags (rn);
2007
adbac85e 2008 /* Reap old select bgp_info, if it has been removed */
b40d939b 2009 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
2010 bgp_info_reap (rn, old_select);
2011
200df115 2012 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2013 return WQ_SUCCESS;
718e3744 2014}
2015
200df115 2016static void
0fb58d5d 2017bgp_processq_del (struct work_queue *wq, void *data)
200df115 2018{
0fb58d5d 2019 struct bgp_process_queue *pq = data;
cb1faec9
DS
2020 struct bgp_table *table;
2021
228da428 2022 bgp_unlock (pq->bgp);
cb1faec9
DS
2023 if (pq->rn)
2024 {
2025 table = bgp_node_table (pq->rn);
2026 bgp_unlock_node (pq->rn);
2027 bgp_table_unlock (table);
2028 }
200df115 2029 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
2030}
2031
f188f2c4 2032void
200df115 2033bgp_process_queue_init (void)
2034{
495f0b13
DS
2035 if (!bm->process_main_queue)
2036 {
2037 bm->process_main_queue
87d4a781 2038 = work_queue_new (bm->master, "process_main_queue");
495f0b13 2039
2a3d5731
DW
2040 if ( !bm->process_main_queue)
2041 {
2042 zlog_err ("%s: Failed to allocate work queue", __func__);
2043 exit (1);
2044 }
200df115 2045 }
2046
2047 bm->process_main_queue->spec.workfunc = &bgp_process_main;
200df115 2048 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
838bbde0
PJ
2049 bm->process_main_queue->spec.max_retries = 0;
2050 bm->process_main_queue->spec.hold = 50;
d889623f
DS
2051 /* Use a higher yield value of 50ms for main queue processing */
2052 bm->process_main_queue->spec.yield = 50 * 1000L;
200df115 2053}
2054
2055void
fee0f4c6 2056bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
2057{
200df115 2058 struct bgp_process_queue *pqnode;
2059
2060 /* already scheduled for processing? */
2061 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
2062 return;
495f0b13 2063
2a3d5731 2064 if (bm->process_main_queue == NULL)
6bf1fe47 2065 return;
2e02b9b2 2066
200df115 2067 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2068 sizeof (struct bgp_process_queue));
2069 if (!pqnode)
2070 return;
228da428
CC
2071
2072 /* all unlocked in bgp_processq_del */
67174041 2073 bgp_table_lock (bgp_node_table (rn));
228da428 2074 pqnode->rn = bgp_lock_node (rn);
200df115 2075 pqnode->bgp = bgp;
228da428 2076 bgp_lock (bgp);
200df115 2077 pqnode->afi = afi;
2078 pqnode->safi = safi;
2a3d5731 2079 work_queue_add (bm->process_main_queue, pqnode);
07ff4dc4 2080 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
200df115 2081 return;
fee0f4c6 2082}
0a486e5f 2083
cb1faec9 2084void
2a3d5731 2085bgp_add_eoiu_mark (struct bgp *bgp)
cb1faec9
DS
2086{
2087 struct bgp_process_queue *pqnode;
2088
2a3d5731 2089 if (bm->process_main_queue == NULL)
6bf1fe47 2090 return;
2e02b9b2 2091
cb1faec9
DS
2092 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2093 sizeof (struct bgp_process_queue));
2094 if (!pqnode)
2095 return;
2096
2097 pqnode->rn = NULL;
2098 pqnode->bgp = bgp;
2099 bgp_lock (bgp);
2a3d5731 2100 work_queue_add (bm->process_main_queue, pqnode);
cb1faec9
DS
2101}
2102
94f2b392 2103static int
0a486e5f 2104bgp_maximum_prefix_restart_timer (struct thread *thread)
2105{
2106 struct peer *peer;
2107
2108 peer = THREAD_ARG (thread);
2109 peer->t_pmax_restart = NULL;
2110
16286195 2111 if (bgp_debug_neighbor_events(peer))
0a486e5f 2112 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
2113 peer->host);
2114
1ff9a340 2115 peer_clear (peer, NULL);
0a486e5f 2116
2117 return 0;
2118}
2119
718e3744 2120int
5228ad27 2121bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
2122 safi_t safi, int always)
718e3744 2123{
e0701b79 2124 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
2125 return 0;
2126
2127 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
718e3744 2128 {
e0701b79 2129 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
2130 && ! always)
2131 return 0;
2132
16286195
DS
2133 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
2134 "limit %ld", afi_safi_print (afi, safi), peer->host,
2135 peer->pcount[afi][safi], peer->pmax[afi][safi]);
e0701b79 2136 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2137
2138 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
2139 return 0;
2140
2141 {
5228ad27 2142 u_int8_t ndata[7];
e0701b79 2143
2144 if (safi == SAFI_MPLS_VPN)
42e6d745 2145 safi = SAFI_MPLS_LABELED_VPN;
5228ad27 2146
2147 ndata[0] = (afi >> 8);
2148 ndata[1] = afi;
2149 ndata[2] = safi;
2150 ndata[3] = (peer->pmax[afi][safi] >> 24);
2151 ndata[4] = (peer->pmax[afi][safi] >> 16);
2152 ndata[5] = (peer->pmax[afi][safi] >> 8);
2153 ndata[6] = (peer->pmax[afi][safi]);
e0701b79 2154
2155 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
2156 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
2157 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
2158 }
0a486e5f 2159
f14e6fdb
DS
2160 /* Dynamic peers will just close their connection. */
2161 if (peer_dynamic_neighbor (peer))
2162 return 1;
2163
0a486e5f 2164 /* restart timer start */
2165 if (peer->pmax_restart[afi][safi])
2166 {
2167 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
2168
16286195 2169 if (bgp_debug_neighbor_events(peer))
0a486e5f 2170 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2171 peer->host, peer->v_pmax_restart);
2172
2173 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2174 peer->v_pmax_restart);
2175 }
2176
e0701b79 2177 return 1;
2178 }
2179 else
2180 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2181
2182 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2183 {
2184 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2185 && ! always)
2186 return 0;
2187
16286195
DS
2188 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2189 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2190 peer->pmax[afi][safi]);
e0701b79 2191 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2192 }
e0701b79 2193 else
2194 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2195 return 0;
2196}
2197
b40d939b 2198/* Unconditionally remove the route from the RIB, without taking
2199 * damping into consideration (eg, because the session went down)
2200 */
94f2b392 2201static void
718e3744 2202bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2203 afi_t afi, safi_t safi)
2204{
902212c3 2205 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2206
2207 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2208 bgp_info_delete (rn, ri); /* keep historical info */
2209
b40d939b 2210 bgp_process (peer->bgp, rn, afi, safi);
718e3744 2211}
2212
94f2b392 2213static void
718e3744 2214bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
65efcfce 2215 afi_t afi, safi_t safi, struct prefix_rd *prd)
718e3744 2216{
718e3744 2217 int status = BGP_DAMP_NONE;
2218
b40d939b 2219 /* apply dampening, if result is suppressed, we'll be retaining
2220 * the bgp_info in the RIB for historical reference.
2221 */
2222 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2223 && peer->sort == BGP_PEER_EBGP)
b40d939b 2224 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2225 == BGP_DAMP_SUPPRESSED)
902212c3 2226 {
902212c3 2227 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2228 return;
2229 }
65efcfce
LB
2230
2231#if ENABLE_BGP_VNC
2232 if (safi == SAFI_MPLS_VPN) {
2233 struct bgp_node *prn = NULL;
2234 struct bgp_table *table = NULL;
2235
2236 prn = bgp_node_get(peer->bgp->rib[afi][safi], (struct prefix *) prd);
2237 if (prn->info) {
2238 table = (struct bgp_table *)(prn->info);
2239
2240 vnc_import_bgp_del_vnc_host_route_mode_resolve_nve(
2241 peer->bgp,
2242 prd,
2243 table,
2244 &rn->p,
2245 ri);
2246 }
2247 bgp_unlock_node(prn);
2248 }
2249 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
2250 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) {
2251
2252 vnc_import_bgp_del_route(peer->bgp, &rn->p, ri);
2253 vnc_import_bgp_exterior_del_route(peer->bgp, &rn->p, ri);
2254 }
2255 }
2256#endif
902212c3 2257 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 2258}
2259
fb018d25 2260static struct bgp_info *
7c8ff89e 2261info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
fb018d25
DS
2262 struct bgp_node *rn)
2263{
2264 struct bgp_info *new;
2265
2266 /* Make new BGP info. */
2267 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2268 new->type = type;
7c8ff89e 2269 new->instance = instance;
fb018d25
DS
2270 new->sub_type = sub_type;
2271 new->peer = peer;
2272 new->attr = attr;
2273 new->uptime = bgp_clock ();
2274 new->net = rn;
adbac85e 2275 new->addpath_tx_id = ++peer->bgp->addpath_tx_id;
fb018d25
DS
2276 return new;
2277}
2278
94f2b392 2279static void
2ec1e66f 2280bgp_info_addpath_rx_str(u_int32_t addpath_id, char *buf)
cd808e74 2281{
2ec1e66f
DW
2282 if (addpath_id)
2283 sprintf(buf, " with addpath ID %d", addpath_id);
b79d6f95
CF
2284 else
2285 buf[0] = '\0';
cd808e74
DS
2286}
2287
2ec1e66f 2288
c265ee22
DS
2289/* Check if received nexthop is valid or not. */
2290static int
6aeb9e78 2291bgp_update_martian_nexthop (struct bgp *bgp, afi_t afi, safi_t safi, struct attr *attr)
c265ee22
DS
2292{
2293 struct attr_extra *attre = attr->extra;
2294 int ret = 0;
2295
2296 /* Only validated for unicast and multicast currently. */
2297 if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST)
2298 return 0;
2299
2300 /* If NEXT_HOP is present, validate it. */
2301 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP))
2302 {
2303 if (attr->nexthop.s_addr == 0 ||
2304 IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) ||
6aeb9e78 2305 bgp_nexthop_self (bgp, attr))
c265ee22
DS
2306 ret = 1;
2307 }
2308
2309 /* If MP_NEXTHOP is present, validate it. */
2310 /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop;
2311 * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if
2312 * it is not an IPv6 link-local address.
2313 */
2314 if (attre && attre->mp_nexthop_len)
2315 {
2316 switch (attre->mp_nexthop_len)
2317 {
2318 case BGP_ATTR_NHLEN_IPV4:
2319 case BGP_ATTR_NHLEN_VPNV4:
2320 ret = (attre->mp_nexthop_global_in.s_addr == 0 ||
2321 IPV4_CLASS_DE (ntohl (attre->mp_nexthop_global_in.s_addr)));
2322 break;
2323
2324#ifdef HAVE_IPV6
2325 case BGP_ATTR_NHLEN_IPV6_GLOBAL:
2326 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
cf6c0c08 2327 case BGP_ATTR_NHLEN_VPNV6_GLOBAL:
c265ee22
DS
2328 ret = (IN6_IS_ADDR_UNSPECIFIED(&attre->mp_nexthop_global) ||
2329 IN6_IS_ADDR_LOOPBACK(&attre->mp_nexthop_global) ||
2330 IN6_IS_ADDR_MULTICAST(&attre->mp_nexthop_global));
2331 break;
2332#endif /* HAVE_IPV6 */
2333
2334 default:
2335 ret = 1;
2336 break;
2337 }
2338 }
2339
2340 return ret;
2341}
2342
a7ee645d
DS
2343int
2344bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2345 struct attr *attr, afi_t afi, safi_t safi, int type,
2346 int sub_type, struct prefix_rd *prd, u_char *tag,
2347 int soft_reconfig)
718e3744 2348{
2349 int ret;
2350 int aspath_loop_count = 0;
2351 struct bgp_node *rn;
2352 struct bgp *bgp;
558d1fec
JBD
2353 struct attr new_attr;
2354 struct attr_extra new_extra;
718e3744 2355 struct attr *attr_new;
2356 struct bgp_info *ri;
2357 struct bgp_info *new;
fd79ac91 2358 const char *reason;
718e3744 2359 char buf[SU_ADDRSTRLEN];
cd808e74 2360 char buf2[30];
fc9a856f 2361 int connected = 0;
aac9ef6c 2362 int do_loop_check = 1;
65efcfce
LB
2363#if ENABLE_BGP_VNC
2364 int vnc_implicit_withdraw = 0;
2365#endif
718e3744 2366
f9a3a260
LB
2367 memset (&new_attr, 0, sizeof(struct attr));
2368 memset (&new_extra, 0, sizeof(struct attr_extra));
2369
718e3744 2370 bgp = peer->bgp;
fee0f4c6 2371 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
fb982c25 2372
718e3744 2373 /* When peer's soft reconfiguration enabled. Record input packet in
2374 Adj-RIBs-In. */
343aa822
JBD
2375 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2376 && peer != bgp->peer_self)
43143c8f 2377 bgp_adj_in_set (rn, peer, attr, addpath_id);
718e3744 2378
2379 /* Check previously received route. */
2380 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
2381 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2382 ri->addpath_rx_id == addpath_id)
718e3744 2383 break;
2384
2385 /* AS path local-as loop check. */
2386 if (peer->change_local_as)
2387 {
2388 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2389 aspath_loop_count = 1;
2390
2391 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2392 {
2393 reason = "as-path contains our own AS;";
2394 goto filtered;
2395 }
2396 }
2397
aac9ef6c
DW
2398 /* If the peer is configured for "allowas-in origin" and the last ASN in the
2399 * as-path is our ASN then we do not need to call aspath_loop_check
2400 */
2401 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN_ORIGIN))
2402 if (aspath_get_last_as(attr->aspath) == bgp->as)
2403 do_loop_check = 0;
2404
718e3744 2405 /* AS path loop check. */
aac9ef6c 2406 if (do_loop_check)
718e3744 2407 {
aac9ef6c
DW
2408 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2409 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2410 && aspath_loop_check(attr->aspath, bgp->confed_id) > peer->allowas_in[afi][safi]))
2411 {
2412 reason = "as-path contains our own AS;";
2413 goto filtered;
2414 }
718e3744 2415 }
2416
2417 /* Route reflector originator ID check. */
2418 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 2419 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
718e3744 2420 {
2421 reason = "originator is us;";
2422 goto filtered;
2423 }
2424
2425 /* Route reflector cluster ID check. */
2426 if (bgp_cluster_filter (peer, attr))
2427 {
2428 reason = "reflected from the same cluster;";
2429 goto filtered;
2430 }
2431
2432 /* Apply incoming filter. */
2433 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2434 {
2435 reason = "filter;";
2436 goto filtered;
2437 }
2438
558d1fec 2439 new_attr.extra = &new_extra;
fb982c25 2440 bgp_attr_dup (&new_attr, attr);
718e3744 2441
c460e572
DL
2442 /* Apply incoming route-map.
2443 * NB: new_attr may now contain newly allocated values from route-map "set"
2444 * commands, so we need bgp_attr_flush in the error paths, until we intern
2445 * the attr (which takes over the memory references) */
0b16f239 2446 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
718e3744 2447 {
2448 reason = "route-map;";
c460e572 2449 bgp_attr_flush (&new_attr);
718e3744 2450 goto filtered;
2451 }
2452
c265ee22 2453 /* next hop check. */
6aeb9e78 2454 if (bgp_update_martian_nexthop (bgp, afi, safi, &new_attr))
718e3744 2455 {
c265ee22
DS
2456 reason = "martian or self next-hop;";
2457 bgp_attr_flush (&new_attr);
2458 goto filtered;
718e3744 2459 }
2460
2461 attr_new = bgp_attr_intern (&new_attr);
2462
2463 /* If the update is implicit withdraw. */
2464 if (ri)
2465 {
65957886 2466 ri->uptime = bgp_clock ();
718e3744 2467
2468 /* Same attribute comes in. */
16d2e241
PJ
2469 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2470 && attrhash_cmp (ri->attr, attr_new))
718e3744 2471 {
718e3744 2472 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2473 && peer->sort == BGP_PEER_EBGP
718e3744 2474 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2475 {
3f9c7369 2476 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74 2477 {
2ec1e66f 2478 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74 2479 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2480 peer->host,
2481 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74
DS
2482 p->prefixlen, buf2);
2483 }
718e3744 2484
902212c3 2485 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2486 {
2487 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2488 bgp_process (bgp, rn, afi, safi);
2489 }
718e3744 2490 }
16d2e241 2491 else /* Duplicate - odd */
718e3744 2492 {
3f9c7369 2493 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2494 {
2495 if (!peer->rcvd_attr_printed)
2496 {
2497 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2498 peer->rcvd_attr_printed = 1;
2499 }
2500
2ec1e66f 2501 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74 2502 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
16286195
DS
2503 peer->host,
2504 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2505 p->prefixlen, buf2);
16286195 2506 }
93406d87 2507
2508 /* graceful restart STALE flag unset. */
2509 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2510 {
1a392d46 2511 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
902212c3 2512 bgp_process (bgp, rn, afi, safi);
93406d87 2513 }
718e3744 2514 }
2515
2516 bgp_unlock_node (rn);
f6f434b2 2517 bgp_attr_unintern (&attr_new);
558d1fec 2518
718e3744 2519 return 0;
2520 }
2521
16d2e241
PJ
2522 /* Withdraw/Announce before we fully processed the withdraw */
2523 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2524 {
3f9c7369 2525 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74 2526 {
2ec1e66f 2527 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74
DS
2528 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
2529 peer->host,
2530 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2531 p->prefixlen, buf2);
2532 }
16d2e241
PJ
2533 bgp_info_restore (rn, ri);
2534 }
2535
718e3744 2536 /* Received Logging. */
3f9c7369 2537 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74 2538 {
2ec1e66f 2539 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74 2540 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2541 peer->host,
2542 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74
DS
2543 p->prefixlen, buf2);
2544 }
718e3744 2545
93406d87 2546 /* graceful restart STALE flag unset. */
2547 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1a392d46 2548 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
93406d87 2549
718e3744 2550 /* The attribute is changed. */
1a392d46 2551 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
902212c3 2552
2553 /* implicit withdraw, decrement aggregate and pcount here.
2554 * only if update is accepted, they'll increment below.
2555 */
902212c3 2556 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2557
718e3744 2558 /* Update bgp route dampening information. */
2559 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2560 && peer->sort == BGP_PEER_EBGP)
718e3744 2561 {
2562 /* This is implicit withdraw so we should update dampening
2563 information. */
2564 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2565 bgp_damp_withdraw (ri, rn, afi, safi, 1);
718e3744 2566 }
65efcfce
LB
2567#if ENABLE_BGP_VNC
2568 if (safi == SAFI_MPLS_VPN) {
2569 struct bgp_node *prn = NULL;
2570 struct bgp_table *table = NULL;
2571
2572 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2573 if (prn->info) {
2574 table = (struct bgp_table *)(prn->info);
2575
2576 vnc_import_bgp_del_vnc_host_route_mode_resolve_nve(
2577 bgp,
2578 prd,
2579 table,
2580 p,
2581 ri);
2582 }
2583 bgp_unlock_node(prn);
2584 }
2585 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
2586 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) {
2587 /*
2588 * Implicit withdraw case.
2589 */
2590 ++vnc_implicit_withdraw;
2591 vnc_import_bgp_del_route(bgp, p, ri);
2592 vnc_import_bgp_exterior_del_route(bgp, p, ri);
2593 }
2594 }
2595#endif
718e3744 2596
718e3744 2597 /* Update to new attribute. */
f6f434b2 2598 bgp_attr_unintern (&ri->attr);
718e3744 2599 ri->attr = attr_new;
2600
2601 /* Update MPLS tag. */
2602 if (safi == SAFI_MPLS_VPN)
fb982c25 2603 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
718e3744 2604
65efcfce
LB
2605#if ENABLE_BGP_VNC
2606 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
2607 {
2608 if (vnc_implicit_withdraw)
2609 {
2610 /*
2611 * Add back the route with its new attributes (e.g., nexthop).
2612 * The route is still selected, until the route selection
2613 * queued by bgp_process actually runs. We have to make this
2614 * update to the VNC side immediately to avoid racing against
2615 * configuration changes (e.g., route-map changes) which
2616 * trigger re-importation of the entire RIB.
2617 */
2618 vnc_import_bgp_add_route(bgp, p, ri);
2619 vnc_import_bgp_exterior_add_route(bgp, p, ri);
2620 }
2621 }
2622#endif
2623
718e3744 2624 /* Update bgp route dampening information. */
2625 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2626 && peer->sort == BGP_PEER_EBGP)
718e3744 2627 {
2628 /* Now we do normal update dampening. */
2629 ret = bgp_damp_update (ri, rn, afi, safi);
2630 if (ret == BGP_DAMP_SUPPRESSED)
2631 {
2632 bgp_unlock_node (rn);
2633 return 0;
2634 }
2635 }
2636
2637 /* Nexthop reachability check. */
fc9a856f 2638 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
718e3744 2639 {
fc9a856f 2640 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
907f92c8
DS
2641 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2642 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
fc9a856f
DS
2643 connected = 1;
2644 else
2645 connected = 0;
2646
75aead62 2647 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
1a392d46 2648 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 2649 else
fc9a856f
DS
2650 {
2651 if (BGP_DEBUG(nht, NHT))
2652 {
2653 char buf1[INET6_ADDRSTRLEN];
2654 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2655 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2656 }
2657 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2658 }
718e3744 2659 }
2660 else
fc9a856f 2661 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 2662
65efcfce
LB
2663#if ENABLE_BGP_VNC
2664 if (safi == SAFI_MPLS_VPN)
2665 {
2666 struct bgp_node *prn = NULL;
2667 struct bgp_table *table = NULL;
2668
2669 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2670 if (prn->info)
2671 {
2672 table = (struct bgp_table *)(prn->info);
2673
2674 vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
2675 bgp,
2676 prd,
2677 table,
2678 p,
2679 ri);
2680 }
2681 bgp_unlock_node(prn);
2682 }
2683#endif
2684
718e3744 2685 /* Process change. */
2686 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2687
2688 bgp_process (bgp, rn, afi, safi);
2689 bgp_unlock_node (rn);
558d1fec 2690
eb78bc46
PZ
2691#if ENABLE_BGP_VNC
2692 if (SAFI_MPLS_VPN == safi)
2693 {
2694 uint32_t label = decode_label(tag);
2695
2696 rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type, sub_type,
2697 &label);
2698 }
2699 if (SAFI_ENCAP == safi)
2700 {
2701 rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type, sub_type,
2702 NULL);
2703 }
2704#endif
2705
718e3744 2706 return 0;
a82478b9 2707 } // End of implicit withdraw
718e3744 2708
2709 /* Received Logging. */
3f9c7369 2710 if (bgp_debug_update(peer, p, NULL, 1))
718e3744 2711 {
16286195
DS
2712 if (!peer->rcvd_attr_printed)
2713 {
2714 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2715 peer->rcvd_attr_printed = 1;
2716 }
2717
2ec1e66f 2718 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74 2719 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2720 peer->host,
2721 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2722 p->prefixlen, buf2);
718e3744 2723 }
2724
718e3744 2725 /* Make new BGP info. */
7c8ff89e 2726 new = info_make(type, sub_type, 0, peer, attr_new, rn);
718e3744 2727
2728 /* Update MPLS tag. */
2729 if (safi == SAFI_MPLS_VPN)
fb982c25 2730 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
718e3744 2731
2732 /* Nexthop reachability check. */
fc9a856f
DS
2733 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2734 {
2735 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
907f92c8
DS
2736 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2737 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
fc9a856f
DS
2738 connected = 1;
2739 else
2740 connected = 0;
2741
75aead62 2742 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
1a392d46 2743 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 2744 else
fc9a856f
DS
2745 {
2746 if (BGP_DEBUG(nht, NHT))
2747 {
2748 char buf1[INET6_ADDRSTRLEN];
2749 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2750 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2751 }
2752 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2753 }
718e3744 2754 }
2755 else
1a392d46 2756 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 2757
a82478b9
DS
2758 /* Addpath ID */
2759 new->addpath_rx_id = addpath_id;
a82478b9 2760
902212c3 2761 /* Increment prefix */
718e3744 2762 bgp_aggregate_increment (bgp, p, new, afi, safi);
2763
2764 /* Register new BGP information. */
2765 bgp_info_add (rn, new);
200df115 2766
2767 /* route_node_get lock */
2768 bgp_unlock_node (rn);
558d1fec 2769
65efcfce
LB
2770#if ENABLE_BGP_VNC
2771 if (safi == SAFI_MPLS_VPN)
2772 {
2773 struct bgp_node *prn = NULL;
2774 struct bgp_table *table = NULL;
2775
2776 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2777 if (prn->info)
2778 {
2779 table = (struct bgp_table *)(prn->info);
2780
2781 vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
2782 bgp,
2783 prd,
2784 table,
2785 p,
2786 new);
2787 }
2788 bgp_unlock_node(prn);
2789 }
2790#endif
2791
718e3744 2792 /* If maximum prefix count is configured and current prefix
2793 count exeed it. */
e0701b79 2794 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2795 return -1;
718e3744 2796
2797 /* Process change. */
2798 bgp_process (bgp, rn, afi, safi);
2799
eb78bc46
PZ
2800#if ENABLE_BGP_VNC
2801 if (SAFI_MPLS_VPN == safi)
2802 {
2803 uint32_t label = decode_label(tag);
2804
2805 rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type, sub_type,
2806 &label);
2807 }
2808 if (SAFI_ENCAP == safi)
2809 {
2810 rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type, sub_type,
2811 NULL);
2812 }
2813#endif
2814
718e3744 2815 return 0;
2816
2817 /* This BGP update is filtered. Log the reason then update BGP
2818 entry. */
2819 filtered:
3f9c7369 2820 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2821 {
2822 if (!peer->rcvd_attr_printed)
2823 {
2824 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2825 peer->rcvd_attr_printed = 1;
2826 }
2827
2ec1e66f 2828 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74 2829 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
16286195
DS
2830 peer->host,
2831 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2832 p->prefixlen, buf2, reason);
16286195 2833 }
718e3744 2834
2835 if (ri)
b40d939b 2836 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 2837
2838 bgp_unlock_node (rn);
558d1fec 2839
63f6bb81
PZ
2840#if ENABLE_BGP_VNC
2841 /*
2842 * Filtered update is treated as an implicit withdrawal (see bgp_rib_remove()
2843 * a few lines above)
2844 */
2845 if ((SAFI_MPLS_VPN == safi) || (SAFI_ENCAP == safi))
2846 {
2847 rfapiProcessWithdraw(peer, NULL, p, prd, NULL, afi, safi, type, 0);
2848 }
2849#endif
2850
718e3744 2851 return 0;
2852}
2853
2854int
a82478b9
DS
2855bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2856 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2857 struct prefix_rd *prd, u_char *tag)
718e3744 2858{
2859 struct bgp *bgp;
2860 char buf[SU_ADDRSTRLEN];
cd808e74 2861 char buf2[30];
718e3744 2862 struct bgp_node *rn;
2863 struct bgp_info *ri;
2864
eb78bc46
PZ
2865#if ENABLE_BGP_VNC
2866 if ((SAFI_MPLS_VPN == safi) || (SAFI_ENCAP == safi))
2867 {
2868 rfapiProcessWithdraw(peer, NULL, p, prd, NULL, afi, safi, type, 0);
2869 }
2870#endif
2871
718e3744 2872 bgp = peer->bgp;
2873
718e3744 2874 /* Lookup node. */
fee0f4c6 2875 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 2876
2877 /* If peer is soft reconfiguration enabled. Record input packet for
6b87f736
DL
2878 * further calculation.
2879 *
2880 * Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2881 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2882 * the iteration over all RS clients.
2883 * Since we need to remove the entry from adj_in anyway, do that first and
2884 * if there was no entry, we don't need to do anything more.
2885 */
718e3744 2886 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2887 && peer != bgp->peer_self)
6b87f736
DL
2888 if (!bgp_adj_in_unset (rn, peer, addpath_id))
2889 {
2890 if (bgp_debug_update (peer, p, NULL, 1))
2891 zlog_debug ("%s withdrawing route %s/%d "
2892 "not in adj-in", peer->host,
2893 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2894 p->prefixlen);
2895 bgp_unlock_node (rn);
2896 return 0;
2897 }
718e3744 2898
2899 /* Lookup withdrawn route. */
2900 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
2901 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2902 ri->addpath_rx_id == addpath_id)
718e3744 2903 break;
2904
cd808e74
DS
2905 /* Logging. */
2906 if (bgp_debug_update(peer, p, NULL, 1))
2907 {
2ec1e66f 2908 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74
DS
2909 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
2910 peer->host,
2911 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2912 p->prefixlen, buf2);
2913 }
2914
718e3744 2915 /* Withdraw specified route from routing table. */
2916 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
65efcfce 2917 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
3f9c7369 2918 else if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2919 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2920 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2921 p->prefixlen);
718e3744 2922
2923 /* Unlock bgp_node_get() lock. */
2924 bgp_unlock_node (rn);
2925
2926 return 0;
2927}
6b0655a2 2928
718e3744 2929void
2930bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2931{
3f9c7369
DS
2932 struct update_subgroup *subgrp;
2933 subgrp = peer_subgroup(peer, afi, safi);
2934 subgroup_default_originate(subgrp, withdraw);
2935}
6182d65b 2936
718e3744 2937
3f9c7369
DS
2938/*
2939 * bgp_stop_announce_route_timer
2940 */
2941void
2942bgp_stop_announce_route_timer (struct peer_af *paf)
2943{
2944 if (!paf->t_announce_route)
2945 return;
718e3744 2946
3f9c7369 2947 THREAD_TIMER_OFF (paf->t_announce_route);
718e3744 2948}
6b0655a2 2949
3f9c7369
DS
2950/*
2951 * bgp_announce_route_timer_expired
2952 *
2953 * Callback that is invoked when the route announcement timer for a
2954 * peer_af expires.
2955 */
2956static int
2957bgp_announce_route_timer_expired (struct thread *t)
718e3744 2958{
3f9c7369
DS
2959 struct peer_af *paf;
2960 struct peer *peer;
558d1fec 2961
3f9c7369
DS
2962 paf = THREAD_ARG (t);
2963 peer = paf->peer;
718e3744 2964
3f9c7369
DS
2965 assert (paf->t_announce_route);
2966 paf->t_announce_route = NULL;
558d1fec 2967
3f9c7369
DS
2968 if (peer->status != Established)
2969 return 0;
2970
2971 if (!peer->afc_nego[paf->afi][paf->safi])
2972 return 0;
2973
2974 peer_af_announce_route (paf, 1);
2975 return 0;
718e3744 2976}
2977
3f9c7369
DS
2978/*
2979 * bgp_announce_route
2980 *
2981 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
2982 */
718e3744 2983void
2984bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2985{
3f9c7369
DS
2986 struct peer_af *paf;
2987 struct update_subgroup *subgrp;
718e3744 2988
3f9c7369
DS
2989 paf = peer_af_find (peer, afi, safi);
2990 if (!paf)
718e3744 2991 return;
3f9c7369 2992 subgrp = PAF_SUBGRP(paf);
718e3744 2993
3f9c7369
DS
2994 /*
2995 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
2996 * or a refresh has already been triggered.
2997 */
2998 if (!subgrp || paf->t_announce_route)
718e3744 2999 return;
3000
d889623f 3001 /*
3f9c7369
DS
3002 * Start a timer to stagger/delay the announce. This serves
3003 * two purposes - announcement can potentially be combined for
3004 * multiple peers and the announcement doesn't happen in the
3005 * vty context.
d889623f 3006 */
9229d914 3007 THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route,
3f9c7369
DS
3008 bgp_announce_route_timer_expired, paf,
3009 (subgrp->peer_count == 1) ?
3010 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
3011 BGP_ANNOUNCE_ROUTE_DELAY_MS);
3012}
3013
3014/*
3015 * Announce routes from all AF tables to a peer.
3016 *
3017 * This should ONLY be called when there is a need to refresh the
3018 * routes to the peer based on a policy change for this peer alone
3019 * or a route refresh request received from the peer.
3020 * The operation will result in splitting the peer from its existing
3021 * subgroups and putting it in new subgroups.
3022 */
718e3744 3023void
3024bgp_announce_route_all (struct peer *peer)
3025{
3026 afi_t afi;
3027 safi_t safi;
3028
3029 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3030 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3031 bgp_announce_route (peer, afi, safi);
3032}
6b0655a2 3033
fee0f4c6 3034static void
718e3744 3035bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
8692c506 3036 struct bgp_table *table, struct prefix_rd *prd)
718e3744 3037{
3038 int ret;
3039 struct bgp_node *rn;
3040 struct bgp_adj_in *ain;
3041
3042 if (! table)
3043 table = peer->bgp->rib[afi][safi];
3044
3045 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3046 for (ain = rn->adj_in; ain; ain = ain->next)
3047 {
3048 if (ain->peer == peer)
3049 {
8692c506 3050 struct bgp_info *ri = rn->info;
d53d8fda 3051 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 3052
43143c8f 3053 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
a82478b9 3054 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
d53d8fda 3055 prd, tag, 1);
8692c506 3056
718e3744 3057 if (ret < 0)
3058 {
3059 bgp_unlock_node (rn);
3060 return;
3061 }
718e3744 3062 }
3063 }
3064}
3065
3066void
3067bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
3068{
3069 struct bgp_node *rn;
3070 struct bgp_table *table;
3071
3072 if (peer->status != Established)
3073 return;
3074
587ff0fd 3075 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
8692c506 3076 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
718e3744 3077 else
3078 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3079 rn = bgp_route_next (rn))
3080 if ((table = rn->info) != NULL)
8692c506
JBD
3081 {
3082 struct prefix_rd prd;
3083 prd.family = AF_UNSPEC;
3084 prd.prefixlen = 64;
3085 memcpy(&prd.val, rn->p.u.val, 8);
3086
3087 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
3088 }
718e3744 3089}
6b0655a2 3090
228da428
CC
3091
3092struct bgp_clear_node_queue
3093{
3094 struct bgp_node *rn;
228da428
CC
3095};
3096
200df115 3097static wq_item_status
0fb58d5d 3098bgp_clear_route_node (struct work_queue *wq, void *data)
200df115 3099{
228da428
CC
3100 struct bgp_clear_node_queue *cnq = data;
3101 struct bgp_node *rn = cnq->rn;
64e580a7 3102 struct peer *peer = wq->spec.data;
718e3744 3103 struct bgp_info *ri;
67174041
AS
3104 afi_t afi = bgp_node_table (rn)->afi;
3105 safi_t safi = bgp_node_table (rn)->safi;
200df115 3106
64e580a7 3107 assert (rn && peer);
200df115 3108
43143c8f
DS
3109 /* It is possible that we have multiple paths for a prefix from a peer
3110 * if that peer is using AddPath.
3111 */
64e580a7 3112 for (ri = rn->info; ri; ri = ri->next)
2a3d5731 3113 if (ri->peer == peer)
200df115 3114 {
3115 /* graceful restart STALE flag set. */
64e580a7
PJ
3116 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
3117 && peer->nsf[afi][safi]
200df115 3118 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
1a392d46
PJ
3119 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
3120 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
200df115 3121 else
64e580a7 3122 bgp_rib_remove (rn, ri, peer, afi, safi);
200df115 3123 }
200df115 3124 return WQ_SUCCESS;
3125}
3126
3127static void
0fb58d5d 3128bgp_clear_node_queue_del (struct work_queue *wq, void *data)
200df115 3129{
228da428
CC
3130 struct bgp_clear_node_queue *cnq = data;
3131 struct bgp_node *rn = cnq->rn;
67174041 3132 struct bgp_table *table = bgp_node_table (rn);
64e580a7
PJ
3133
3134 bgp_unlock_node (rn);
228da428
CC
3135 bgp_table_unlock (table);
3136 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
200df115 3137}
3138
3139static void
94f2b392 3140bgp_clear_node_complete (struct work_queue *wq)
200df115 3141{
64e580a7
PJ
3142 struct peer *peer = wq->spec.data;
3143
3e0c78ef 3144 /* Tickle FSM to start moving again */
ca058a30 3145 BGP_EVENT_ADD (peer, Clearing_Completed);
228da428
CC
3146
3147 peer_unlock (peer); /* bgp_clear_route */
200df115 3148}
3149
3150static void
64e580a7 3151bgp_clear_node_queue_init (struct peer *peer)
200df115 3152{
a2943657 3153 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
64e580a7 3154
a2943657 3155 snprintf (wname, sizeof(wname), "clear %s", peer->host);
64e580a7
PJ
3156#undef CLEAR_QUEUE_NAME_LEN
3157
87d4a781 3158 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
200df115 3159 {
3160 zlog_err ("%s: Failed to allocate work queue", __func__);
3161 exit (1);
3162 }
64e580a7
PJ
3163 peer->clear_node_queue->spec.hold = 10;
3164 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
3165 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
3166 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
3167 peer->clear_node_queue->spec.max_retries = 0;
3168
3169 /* we only 'lock' this peer reference when the queue is actually active */
3170 peer->clear_node_queue->spec.data = peer;
200df115 3171}
718e3744 3172
200df115 3173static void
3174bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
2a3d5731 3175 struct bgp_table *table)
200df115 3176{
200df115 3177 struct bgp_node *rn;
0c6262ed 3178 int force = bm->process_main_queue ? 0 : 1;
f2c31acb 3179
718e3744 3180 if (! table)
2a3d5731 3181 table = peer->bgp->rib[afi][safi];
64e580a7 3182
6cf159b9 3183 /* If still no table => afi/safi isn't configured at all or smth. */
3184 if (! table)
3185 return;
65ca75e0
PJ
3186
3187 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3188 {
0c6262ed 3189 struct bgp_info *ri, *next;
f2c31acb 3190 struct bgp_adj_in *ain;
43143c8f 3191 struct bgp_adj_in *ain_next;
f2c31acb
PJ
3192
3193 /* XXX:TODO: This is suboptimal, every non-empty route_node is
3194 * queued for every clearing peer, regardless of whether it is
3195 * relevant to the peer at hand.
3196 *
3197 * Overview: There are 3 different indices which need to be
3198 * scrubbed, potentially, when a peer is removed:
3199 *
3200 * 1 peer's routes visible via the RIB (ie accepted routes)
3201 * 2 peer's routes visible by the (optional) peer's adj-in index
3202 * 3 other routes visible by the peer's adj-out index
3203 *
3204 * 3 there is no hurry in scrubbing, once the struct peer is
3205 * removed from bgp->peer, we could just GC such deleted peer's
3206 * adj-outs at our leisure.
3207 *
3208 * 1 and 2 must be 'scrubbed' in some way, at least made
3209 * invisible via RIB index before peer session is allowed to be
3210 * brought back up. So one needs to know when such a 'search' is
3211 * complete.
3212 *
3213 * Ideally:
3214 *
3215 * - there'd be a single global queue or a single RIB walker
3216 * - rather than tracking which route_nodes still need to be
3217 * examined on a peer basis, we'd track which peers still
3218 * aren't cleared
3219 *
3220 * Given that our per-peer prefix-counts now should be reliable,
3221 * this may actually be achievable. It doesn't seem to be a huge
3222 * problem at this time,
43143c8f
DS
3223 *
3224 * It is possible that we have multiple paths for a prefix from a peer
3225 * if that peer is using AddPath.
f2c31acb 3226 */
43143c8f
DS
3227 ain = rn->adj_in;
3228 while (ain)
3229 {
3230 ain_next = ain->next;
3231
2a3d5731 3232 if (ain->peer == peer)
43143c8f
DS
3233 {
3234 bgp_adj_in_remove (rn, ain);
3235 bgp_unlock_node (rn);
3236 }
3237
3238 ain = ain_next;
3239 }
3f9c7369 3240
0c6262ed
RW
3241 for (ri = rn->info; ri; ri = next)
3242 {
3243 next = ri->next;
3244 if (ri->peer != peer)
3245 continue;
3246
3247 if (force)
3248 bgp_info_reap (rn, ri);
3249 else
3250 {
3251 struct bgp_clear_node_queue *cnq;
3252
3253 /* both unlocked in bgp_clear_node_queue_del */
3254 bgp_table_lock (bgp_node_table (rn));
3255 bgp_lock_node (rn);
3256 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
3257 sizeof (struct bgp_clear_node_queue));
3258 cnq->rn = rn;
3259 work_queue_add (peer->clear_node_queue, cnq);
3260 break;
3261 }
3262 }
65ca75e0
PJ
3263 }
3264 return;
3265}
3266
3267void
2a3d5731 3268bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
65ca75e0
PJ
3269{
3270 struct bgp_node *rn;
3271 struct bgp_table *table;
6cf159b9 3272
64e580a7
PJ
3273 if (peer->clear_node_queue == NULL)
3274 bgp_clear_node_queue_init (peer);
200df115 3275
ca058a30
PJ
3276 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3277 * Idle until it receives a Clearing_Completed event. This protects
3278 * against peers which flap faster than we can we clear, which could
3279 * lead to:
64e580a7
PJ
3280 *
3281 * a) race with routes from the new session being installed before
3282 * clear_route_node visits the node (to delete the route of that
3283 * peer)
3284 * b) resource exhaustion, clear_route_node likely leads to an entry
3285 * on the process_main queue. Fast-flapping could cause that queue
3286 * to grow and grow.
200df115 3287 */
dc83d712
DS
3288
3289 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3290 * the unlock will happen upon work-queue completion; other wise, the
3291 * unlock happens at the end of this function.
3292 */
ca058a30 3293 if (!peer->clear_node_queue->thread)
dc83d712 3294 peer_lock (peer);
fee0f4c6 3295
587ff0fd 3296 if (safi != SAFI_MPLS_VPN && safi != SAFI_ENCAP)
2a3d5731
DW
3297 bgp_clear_route_table (peer, afi, safi, NULL);
3298 else
3299 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3300 rn = bgp_route_next (rn))
3301 if ((table = rn->info) != NULL)
3302 bgp_clear_route_table (peer, afi, safi, table);
dc83d712
DS
3303
3304 /* unlock if no nodes got added to the clear-node-queue. */
65ca75e0 3305 if (!peer->clear_node_queue->thread)
dc83d712
DS
3306 peer_unlock (peer);
3307
718e3744 3308}
3309
3310void
3311bgp_clear_route_all (struct peer *peer)
3312{
3313 afi_t afi;
3314 safi_t safi;
3315
3316 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3317 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2a3d5731 3318 bgp_clear_route (peer, afi, safi);
65efcfce
LB
3319
3320#if ENABLE_BGP_VNC
3321 rfapiProcessPeerDown(peer);
3322#endif
718e3744 3323}
3324
3325void
3326bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3327{
3328 struct bgp_table *table;
3329 struct bgp_node *rn;
3330 struct bgp_adj_in *ain;
43143c8f 3331 struct bgp_adj_in *ain_next;
718e3744 3332
3333 table = peer->bgp->rib[afi][safi];
3334
43143c8f
DS
3335 /* It is possible that we have multiple paths for a prefix from a peer
3336 * if that peer is using AddPath.
3337 */
718e3744 3338 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
43143c8f
DS
3339 {
3340 ain = rn->adj_in;
3341
3342 while (ain)
3343 {
3344 ain_next = ain->next;
3345
3346 if (ain->peer == peer)
3347 {
3348 bgp_adj_in_remove (rn, ain);
3349 bgp_unlock_node (rn);
3350 }
3351
3352 ain = ain_next;
3353 }
3354 }
718e3744 3355}
93406d87 3356
3357void
3358bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3359{
3360 struct bgp_node *rn;
3361 struct bgp_info *ri;
3362 struct bgp_table *table;
3363
3364 table = peer->bgp->rib[afi][safi];
3365
3366 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3367 {
3368 for (ri = rn->info; ri; ri = ri->next)
3369 if (ri->peer == peer)
3370 {
3371 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3372 bgp_rib_remove (rn, ri, peer, afi, safi);
3373 break;
3374 }
3375 }
3376}
6b0655a2 3377
bb86c601
LB
3378static void
3379bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3380{
3381 struct bgp_node *rn;
3382 struct bgp_info *ri;
3383 struct bgp_info *next;
3384
3385 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3386 for (ri = rn->info; ri; ri = next)
3387 {
3388 next = ri->next;
3389 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3390 && ri->type == ZEBRA_ROUTE_BGP
3391 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3392 ri->sub_type == BGP_ROUTE_AGGREGATE))
65efcfce
LB
3393 {
3394#if ENABLE_BGP_VNC
3395 if (table->owner && table->owner->bgp)
3396 vnc_import_bgp_del_route(table->owner->bgp, &rn->p, ri);
3397#endif
3398 bgp_zebra_withdraw (&rn->p, ri, safi);
0c6262ed 3399 bgp_info_reap (rn, ri);
65efcfce 3400 }
bb86c601
LB
3401 }
3402}
3403
718e3744 3404/* Delete all kernel routes. */
3405void
0c6262ed 3406bgp_cleanup_routes (struct bgp *bgp)
718e3744 3407{
bb86c601 3408 afi_t afi;
718e3744 3409
0c6262ed 3410 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
718e3744 3411 {
0c6262ed 3412 struct bgp_node *rn;
bb86c601 3413
0c6262ed 3414 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
bb86c601 3415
0c6262ed
RW
3416 /*
3417 * VPN and ENCAP tables are two-level (RD is top level)
3418 */
3419 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3420 rn = bgp_route_next (rn))
3421 {
3422 if (rn->info)
587ff0fd 3423 {
0c6262ed
RW
3424 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3425 bgp_table_finish ((struct bgp_table **)&(rn->info));
3426 rn->info = NULL;
3427 bgp_unlock_node(rn);
587ff0fd 3428 }
0c6262ed 3429 }
587ff0fd 3430
0c6262ed
RW
3431 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3432 rn = bgp_route_next (rn))
3433 {
3434 if (rn->info)
587ff0fd 3435 {
0c6262ed
RW
3436 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3437 bgp_table_finish ((struct bgp_table **)&(rn->info));
3438 rn->info = NULL;
3439 bgp_unlock_node(rn);
587ff0fd 3440 }
bb86c601 3441 }
718e3744 3442 }
3443}
3444
3445void
66e5cd87 3446bgp_reset (void)
718e3744 3447{
3448 vty_reset ();
3449 bgp_zclient_reset ();
3450 access_list_reset ();
3451 prefix_list_reset ();
3452}
6b0655a2 3453
adbac85e
DW
3454static int
3455bgp_addpath_encode_rx (struct peer *peer, afi_t afi, safi_t safi)
3456{
3457 return (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3458 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3459}
3460
718e3744 3461/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3462 value. */
3463int
96e52474
PJ
3464bgp_nlri_parse_ip (struct peer *peer, struct attr *attr,
3465 struct bgp_nlri *packet)
718e3744 3466{
3467 u_char *pnt;
3468 u_char *lim;
3469 struct prefix p;
3470 int psize;
3471 int ret;
a82478b9
DS
3472 afi_t afi;
3473 safi_t safi;
adbac85e 3474 int addpath_encoded;
a82478b9 3475 u_int32_t addpath_id;
718e3744 3476
3477 /* Check peer status. */
3478 if (peer->status != Established)
3479 return 0;
3480
3481 pnt = packet->nlri;
3482 lim = pnt + packet->length;
a82478b9
DS
3483 afi = packet->afi;
3484 safi = packet->safi;
3485 addpath_id = 0;
adbac85e 3486 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
718e3744 3487
ebd12e62
PJ
3488 /* RFC4771 6.3 The NLRI field in the UPDATE message is checked for
3489 syntactic validity. If the field is syntactically incorrect,
3490 then the Error Subcode is set to Invalid Network Field. */
718e3744 3491 for (; pnt < lim; pnt += psize)
3492 {
3493 /* Clear prefix structure. */
3494 memset (&p, 0, sizeof (struct prefix));
3495
a82478b9
DS
3496 if (addpath_encoded)
3497 {
cd808e74
DS
3498
3499 /* When packet overflow occurs return immediately. */
3500 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3501 return -1;
3502
a82478b9
DS
3503 addpath_id = ntohl(*((uint32_t*) pnt));
3504 pnt += BGP_ADDPATH_ID_LEN;
3505 }
3506
718e3744 3507 /* Fetch prefix length. */
3508 p.prefixlen = *pnt++;
ebd12e62 3509 /* afi/safi validity already verified by caller, bgp_update_receive */
a82478b9 3510 p.family = afi2family (afi);
ebd12e62
PJ
3511
3512 /* Prefix length check. */
3513 if (p.prefixlen > prefix_blen (&p) * 8)
3514 {
3515 zlog_err("%s [Error] Update packet error (wrong perfix length %d for afi %u)",
3516 peer->host, p.prefixlen, packet->afi);
3517 return -1;
3518 }
718e3744 3519
3520 /* Packet size overflow check. */
3521 psize = PSIZE (p.prefixlen);
3522
3523 /* When packet overflow occur return immediately. */
3524 if (pnt + psize > lim)
ebd12e62
PJ
3525 {
3526 zlog_err("%s [Error] Update packet error (prefix length %d overflows packet)",
3527 peer->host, p.prefixlen);
3528 return -1;
3529 }
3530
3531 /* Defensive coding, double-check the psize fits in a struct prefix */
3532 if (psize > (ssize_t) sizeof(p.u))
3533 {
3534 zlog_err("%s [Error] Update packet error (prefix length %d too large for prefix storage %zu)",
3535 peer->host, p.prefixlen, sizeof(p.u));
3536 return -1;
3537 }
718e3744 3538
3539 /* Fetch prefix from NLRI packet. */
3540 memcpy (&p.u.prefix, pnt, psize);
3541
3542 /* Check address. */
a82478b9 3543 if (afi == AFI_IP && safi == SAFI_UNICAST)
718e3744 3544 {
3545 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3546 {
ebd12e62
PJ
3547 /* From RFC4271 Section 6.3:
3548 *
3549 * If a prefix in the NLRI field is semantically incorrect
3550 * (e.g., an unexpected multicast IP address), an error SHOULD
3551 * be logged locally, and the prefix SHOULD be ignored.
3552 */
3553 zlog_err ("%s: IPv4 unicast NLRI is multicast address %s, ignoring",
3554 peer->host, inet_ntoa (p.u.prefix4));
3555 continue;
718e3744 3556 }
3557 }
3558
3559#ifdef HAVE_IPV6
3560 /* Check address. */
a82478b9 3561 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
718e3744 3562 {
3563 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3564 {
3565 char buf[BUFSIZ];
3566
ebd12e62
PJ
3567 zlog_err ("%s: IPv6 unicast NLRI is link-local address %s, ignoring",
3568 peer->host, inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3569
3570 continue;
3571 }
3572 if (IN6_IS_ADDR_MULTICAST (&p.u.prefix6))
3573 {
3574 char buf[BUFSIZ];
3575
3576 zlog_err ("%s: IPv6 unicast NLRI is multicast address %s, ignoring",
3577 peer->host, inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
718e3744 3578
3579 continue;
3580 }
3581 }
3582#endif /* HAVE_IPV6 */
3583
3584 /* Normal process. */
3585 if (attr)
a82478b9 3586 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
718e3744 3587 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3588 else
a82478b9 3589 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
718e3744 3590 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3591
3592 /* Address family configuration mismatch or maximum-prefix count
3593 overflow. */
3594 if (ret < 0)
3595 return -1;
3596 }
3597
3598 /* Packet length consistency check. */
3599 if (pnt != lim)
718e3744 3600 {
ebd12e62
PJ
3601 zlog_err ("%s [Error] Update packet error (prefix length mismatch with total length)",
3602 peer->host);
718e3744 3603 return -1;
3604 }
6b0655a2 3605
ebd12e62 3606 return 0;
48a5452b
PJ
3607}
3608
94f2b392 3609static struct bgp_static *
66e5cd87 3610bgp_static_new (void)
718e3744 3611{
393deb9b 3612 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
718e3744 3613}
3614
94f2b392 3615static void
718e3744 3616bgp_static_free (struct bgp_static *bgp_static)
3617{
3618 if (bgp_static->rmap.name)
6e919709 3619 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
718e3744 3620 XFREE (MTYPE_BGP_STATIC, bgp_static);
3621}
3622
94f2b392 3623static void
2a3d5731
DW
3624bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3625 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
fee0f4c6 3626{
3627 struct bgp_node *rn;
3628 struct bgp_info *ri;
2a3d5731
DW
3629 struct bgp_info *new;
3630 struct bgp_info info;
3631 struct attr attr;
3632 struct attr *attr_new;
3633 int ret;
65efcfce
LB
3634#if ENABLE_BGP_VNC
3635 int vnc_implicit_withdraw = 0;
3636#endif
fee0f4c6 3637
2a3d5731
DW
3638 assert (bgp_static);
3639 if (!bgp_static)
3640 return;
dd8103a9 3641
fee0f4c6 3642 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 3643
3644 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
dd8103a9
PJ
3645
3646 attr.nexthop = bgp_static->igpnexthop;
3647 attr.med = bgp_static->igpmetric;
3648 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
718e3744 3649
41367172
PJ
3650 if (bgp_static->atomic)
3651 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3652
718e3744 3653 /* Apply route-map. */
3654 if (bgp_static->rmap.name)
3655 {
fb982c25 3656 struct attr attr_tmp = attr;
718e3744 3657 info.peer = bgp->peer_self;
286e1e71 3658 info.attr = &attr_tmp;
718e3744 3659
fee0f4c6 3660 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3661
718e3744 3662 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
286e1e71 3663
fee0f4c6 3664 bgp->peer_self->rmap_type = 0;
3665
718e3744 3666 if (ret == RMAP_DENYMATCH)
3667 {
3668 /* Free uninterned attribute. */
286e1e71 3669 bgp_attr_flush (&attr_tmp);
718e3744 3670
3671 /* Unintern original. */
f6f434b2 3672 aspath_unintern (&attr.aspath);
fb982c25 3673 bgp_attr_extra_free (&attr);
718e3744 3674 bgp_static_withdraw (bgp, p, afi, safi);
3675 return;
3676 }
286e1e71 3677 attr_new = bgp_attr_intern (&attr_tmp);
718e3744 3678 }
286e1e71 3679 else
3680 attr_new = bgp_attr_intern (&attr);
718e3744 3681
3682 for (ri = rn->info; ri; ri = ri->next)
3683 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3684 && ri->sub_type == BGP_ROUTE_STATIC)
3685 break;
3686
3687 if (ri)
3688 {
8d45210e 3689 if (attrhash_cmp (ri->attr, attr_new) &&
078430f6
DS
3690 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
3691 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
718e3744 3692 {
3693 bgp_unlock_node (rn);
f6f434b2
PJ
3694 bgp_attr_unintern (&attr_new);
3695 aspath_unintern (&attr.aspath);
fb982c25 3696 bgp_attr_extra_free (&attr);
718e3744 3697 return;
3698 }
3699 else
3700 {
3701 /* The attribute is changed. */
1a392d46 3702 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 3703
3704 /* Rewrite BGP route information. */
8d45210e
AS
3705 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3706 bgp_info_restore(rn, ri);
3707 else
3708 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
65efcfce
LB
3709#if ENABLE_BGP_VNC
3710 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
3711 {
3712 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
3713 {
3714 /*
3715 * Implicit withdraw case.
3716 * We have to do this before ri is changed
3717 */
3718 ++vnc_implicit_withdraw;
3719 vnc_import_bgp_del_route(bgp, p, ri);
3720 vnc_import_bgp_exterior_del_route(bgp, p, ri);
3721 }
3722 }
3723#endif
f6f434b2 3724 bgp_attr_unintern (&ri->attr);
718e3744 3725 ri->attr = attr_new;
65957886 3726 ri->uptime = bgp_clock ();
65efcfce
LB
3727#if ENABLE_BGP_VNC
3728 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
3729 {
3730 if (vnc_implicit_withdraw)
3731 {
3732 vnc_import_bgp_add_route(bgp, p, ri);
3733 vnc_import_bgp_exterior_add_route(bgp, p, ri);
3734 }
3735 }
3736#endif
718e3744 3737
fc9a856f
DS
3738 /* Nexthop reachability check. */
3739 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3740 {
75aead62 3741 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
fc9a856f
DS
3742 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3743 else
3744 {
3745 if (BGP_DEBUG(nht, NHT))
3746 {
3747 char buf1[INET6_ADDRSTRLEN];
078430f6
DS
3748 inet_ntop(p->family, &p->u.prefix, buf1,
3749 INET6_ADDRSTRLEN);
3750 zlog_debug("%s(%s): Route not in table, not advertising",
3751 __FUNCTION__, buf1);
fc9a856f
DS
3752 }
3753 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3754 }
3755 }
078430f6
DS
3756 else
3757 {
3758 /* Delete the NHT structure if any, if we're toggling between
3759 * enabling/disabling import check. We deregister the route
3760 * from NHT to avoid overloading NHT and the process interaction
3761 */
3762 bgp_unlink_nexthop(ri);
3763 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3764 }
718e3744 3765 /* Process change. */
3766 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3767 bgp_process (bgp, rn, afi, safi);
3768 bgp_unlock_node (rn);
f6f434b2 3769 aspath_unintern (&attr.aspath);
fb982c25 3770 bgp_attr_extra_free (&attr);
718e3744 3771 return;
3772 }
3773 }
3774
3775 /* Make new BGP info. */
7c8ff89e 3776 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
fb018d25 3777 rn);
fc9a856f
DS
3778 /* Nexthop reachability check. */
3779 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3780 {
75aead62 3781 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
fc9a856f
DS
3782 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3783 else
3784 {
3785 if (BGP_DEBUG(nht, NHT))
3786 {
3787 char buf1[INET6_ADDRSTRLEN];
078430f6 3788 inet_ntop(p->family, &p->u.prefix, buf1,
fc9a856f 3789 INET6_ADDRSTRLEN);
078430f6
DS
3790 zlog_debug("%s(%s): Route not in table, not advertising",
3791 __FUNCTION__, buf1);
fc9a856f
DS
3792 }
3793 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3794 }
3795 }
3796 else
078430f6
DS
3797 {
3798 /* Delete the NHT structure if any, if we're toggling between
3799 * enabling/disabling import check. We deregister the route
3800 * from NHT to avoid overloading NHT and the process interaction
3801 */
3802 bgp_unlink_nexthop(new);
3803
3804 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3805 }
718e3744 3806
3807 /* Aggregate address increment. */
3808 bgp_aggregate_increment (bgp, p, new, afi, safi);
3809
3810 /* Register new BGP information. */
3811 bgp_info_add (rn, new);
200df115 3812
3813 /* route_node_get lock */
3814 bgp_unlock_node (rn);
3815
718e3744 3816 /* Process change. */
3817 bgp_process (bgp, rn, afi, safi);
3818
3819 /* Unintern original. */
f6f434b2 3820 aspath_unintern (&attr.aspath);
fb982c25 3821 bgp_attr_extra_free (&attr);
718e3744 3822}
3823
fee0f4c6 3824void
3825bgp_static_update (struct bgp *bgp, struct prefix *p,
3826 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3827{
fee0f4c6 3828 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
fee0f4c6 3829}
3830
718e3744 3831void
3832bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3833 safi_t safi)
3834{
3835 struct bgp_node *rn;
3836 struct bgp_info *ri;
3837
fee0f4c6 3838 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 3839
3840 /* Check selected route and self inserted route. */
3841 for (ri = rn->info; ri; ri = ri->next)
3842 if (ri->peer == bgp->peer_self
3843 && ri->type == ZEBRA_ROUTE_BGP
3844 && ri->sub_type == BGP_ROUTE_STATIC)
3845 break;
3846
3847 /* Withdraw static BGP route from routing table. */
3848 if (ri)
3849 {
3850 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
fc9a856f 3851 bgp_unlink_nexthop(ri);
718e3744 3852 bgp_info_delete (rn, ri);
1a392d46 3853 bgp_process (bgp, rn, afi, safi);
718e3744 3854 }
3855
3856 /* Unlock bgp_node_lookup. */
3857 bgp_unlock_node (rn);
3858}
3859
137446f9
LB
3860/*
3861 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3862 */
94f2b392 3863static void
137446f9
LB
3864bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3865 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 3866{
3867 struct bgp_node *rn;
3868 struct bgp_info *ri;
3869
fee0f4c6 3870 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 3871
3872 /* Check selected route and self inserted route. */
3873 for (ri = rn->info; ri; ri = ri->next)
3874 if (ri->peer == bgp->peer_self
3875 && ri->type == ZEBRA_ROUTE_BGP
3876 && ri->sub_type == BGP_ROUTE_STATIC)
3877 break;
3878
3879 /* Withdraw static BGP route from routing table. */
3880 if (ri)
3881 {
65efcfce
LB
3882#if ENABLE_BGP_VNC
3883 rfapiProcessWithdraw(
3884 ri->peer,
3885 NULL,
3886 p,
3887 prd,
3888 ri->attr,
3889 afi,
3890 safi,
3891 ri->type,
3892 1); /* Kill, since it is an administrative change */
3893#endif
718e3744 3894 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
718e3744 3895 bgp_info_delete (rn, ri);
1a392d46 3896 bgp_process (bgp, rn, afi, safi);
718e3744 3897 }
3898
3899 /* Unlock bgp_node_lookup. */
3900 bgp_unlock_node (rn);
3901}
3902
137446f9
LB
3903static void
3904bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3905 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3906{
3907 struct bgp_node *rn;
3908 struct bgp_info *new;
3909 struct attr *attr_new;
3910 struct attr attr = { 0 };
3911 struct bgp_info *ri;
65efcfce
LB
3912#if ENABLE_BGP_VNC
3913 u_int32_t label = 0;
3914#endif
137446f9
LB
3915
3916 assert (bgp_static);
3917
3918 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3919
3920 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3921
3922 attr.nexthop = bgp_static->igpnexthop;
3923 attr.med = bgp_static->igpmetric;
3924 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3925
3926 /* Apply route-map. */
3927 if (bgp_static->rmap.name)
3928 {
3929 struct attr attr_tmp = attr;
3930 struct bgp_info info;
3931 int ret;
3932
3933 info.peer = bgp->peer_self;
3934 info.attr = &attr_tmp;
3935
3936 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3937
3938 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3939
3940 bgp->peer_self->rmap_type = 0;
3941
3942 if (ret == RMAP_DENYMATCH)
3943 {
3944 /* Free uninterned attribute. */
3945 bgp_attr_flush (&attr_tmp);
3946
3947 /* Unintern original. */
3948 aspath_unintern (&attr.aspath);
3949 bgp_attr_extra_free (&attr);
3950 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3951 bgp_static->tag);
3952 return;
3953 }
3954
3955 attr_new = bgp_attr_intern (&attr_tmp);
3956 }
3957 else
3958 {
3959 attr_new = bgp_attr_intern (&attr);
3960 }
3961
3962 for (ri = rn->info; ri; ri = ri->next)
3963 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3964 && ri->sub_type == BGP_ROUTE_STATIC)
3965 break;
3966
3967 if (ri)
3968 {
3969 if (attrhash_cmp (ri->attr, attr_new) &&
3970 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3971 {
3972 bgp_unlock_node (rn);
3973 bgp_attr_unintern (&attr_new);
3974 aspath_unintern (&attr.aspath);
3975 bgp_attr_extra_free (&attr);
3976 return;
3977 }
3978 else
3979 {
3980 /* The attribute is changed. */
3981 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3982
3983 /* Rewrite BGP route information. */
3984 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3985 bgp_info_restore(rn, ri);
3986 else
3987 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3988 bgp_attr_unintern (&ri->attr);
3989 ri->attr = attr_new;
3990 ri->uptime = bgp_clock ();
65efcfce
LB
3991#if ENABLE_BGP_VNC
3992 if (ri->extra)
3993 label = decode_label (ri->extra->tag);
3994#endif
137446f9
LB
3995
3996 /* Process change. */
3997 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3998 bgp_process (bgp, rn, afi, safi);
65efcfce
LB
3999#if ENABLE_BGP_VNC
4000 rfapiProcessUpdate(ri->peer, NULL, p, &bgp_static->prd,
4001 ri->attr, afi, safi,
4002 ri->type, ri->sub_type, &label);
4003#endif
137446f9
LB
4004 bgp_unlock_node (rn);
4005 aspath_unintern (&attr.aspath);
4006 bgp_attr_extra_free (&attr);
4007 return;
4008 }
4009 }
4010
4011
4012 /* Make new BGP info. */
4013 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
4014 rn);
4015 SET_FLAG (new->flags, BGP_INFO_VALID);
4016 new->extra = bgp_info_extra_new();
4017 memcpy (new->extra->tag, bgp_static->tag, 3);
65efcfce
LB
4018#if ENABLE_BGP_VNC
4019 label = decode_label (bgp_static->tag);
4020#endif
137446f9
LB
4021
4022 /* Aggregate address increment. */
4023 bgp_aggregate_increment (bgp, p, new, afi, safi);
4024
4025 /* Register new BGP information. */
4026 bgp_info_add (rn, new);
4027
4028 /* route_node_get lock */
4029 bgp_unlock_node (rn);
4030
4031 /* Process change. */
4032 bgp_process (bgp, rn, afi, safi);
4033
65efcfce
LB
4034#if ENABLE_BGP_VNC
4035 rfapiProcessUpdate(new->peer, NULL, p, &bgp_static->prd,
4036 new->attr, afi, safi,
4037 new->type, new->sub_type, &label);
4038#endif
4039
137446f9
LB
4040 /* Unintern original. */
4041 aspath_unintern (&attr.aspath);
4042 bgp_attr_extra_free (&attr);
4043}
4044
718e3744 4045/* Configure static BGP network. When user don't run zebra, static
4046 route should be installed as valid. */
94f2b392 4047static int
fd79ac91 4048bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
c8f3fe30 4049 afi_t afi, safi_t safi, const char *rmap, int backdoor)
718e3744 4050{
4051 int ret;
4052 struct prefix p;
4053 struct bgp_static *bgp_static;
4054 struct bgp_node *rn;
41367172 4055 u_char need_update = 0;
718e3744 4056
4057 /* Convert IP prefix string to struct prefix. */
4058 ret = str2prefix (ip_str, &p);
4059 if (! ret)
4060 {
4061 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4062 return CMD_WARNING;
4063 }
4064#ifdef HAVE_IPV6
4065 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4066 {
4067 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4068 VTY_NEWLINE);
4069 return CMD_WARNING;
4070 }
4071#endif /* HAVE_IPV6 */
4072
4073 apply_mask (&p);
4074
4075 /* Set BGP static route configuration. */
4076 rn = bgp_node_get (bgp->route[afi][safi], &p);
4077
4078 if (rn->info)
4079 {
4080 /* Configuration change. */
4081 bgp_static = rn->info;
4082
4083 /* Check previous routes are installed into BGP. */
c8f3fe30
PJ
4084 if (bgp_static->valid && bgp_static->backdoor != backdoor)
4085 need_update = 1;
41367172 4086
718e3744 4087 bgp_static->backdoor = backdoor;
41367172 4088
718e3744 4089 if (rmap)
4090 {
4091 if (bgp_static->rmap.name)
6e919709
DS
4092 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4093 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
718e3744 4094 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4095 }
4096 else
4097 {
4098 if (bgp_static->rmap.name)
6e919709 4099 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
718e3744 4100 bgp_static->rmap.name = NULL;
4101 bgp_static->rmap.map = NULL;
4102 bgp_static->valid = 0;
4103 }
4104 bgp_unlock_node (rn);
4105 }
4106 else
4107 {
4108 /* New configuration. */
4109 bgp_static = bgp_static_new ();
4110 bgp_static->backdoor = backdoor;
4111 bgp_static->valid = 0;
4112 bgp_static->igpmetric = 0;
4113 bgp_static->igpnexthop.s_addr = 0;
41367172 4114
718e3744 4115 if (rmap)
4116 {
4117 if (bgp_static->rmap.name)
6e919709
DS
4118 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4119 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
718e3744 4120 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4121 }
4122 rn->info = bgp_static;
4123 }
4124
fc9a856f
DS
4125 bgp_static->valid = 1;
4126 if (need_update)
4127 bgp_static_withdraw (bgp, &p, afi, safi);
718e3744 4128
fc9a856f
DS
4129 if (! bgp_static->backdoor)
4130 bgp_static_update (bgp, &p, bgp_static, afi, safi);
718e3744 4131
4132 return CMD_SUCCESS;
4133}
4134
4135/* Configure static BGP network. */
94f2b392 4136static int
fd79ac91 4137bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4c9641ba 4138 afi_t afi, safi_t safi)
718e3744 4139{
4140 int ret;
4141 struct prefix p;
4142 struct bgp_static *bgp_static;
4143 struct bgp_node *rn;
4144
4145 /* Convert IP prefix string to struct prefix. */
4146 ret = str2prefix (ip_str, &p);
4147 if (! ret)
4148 {
4149 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4150 return CMD_WARNING;
4151 }
4152#ifdef HAVE_IPV6
4153 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4154 {
4155 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4156 VTY_NEWLINE);
4157 return CMD_WARNING;
4158 }
4159#endif /* HAVE_IPV6 */
4160
4161 apply_mask (&p);
4162
4163 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4164 if (! rn)
4165 {
4166 vty_out (vty, "%% Can't find specified static route configuration.%s",
4167 VTY_NEWLINE);
4168 return CMD_WARNING;
4169 }
4170
4171 bgp_static = rn->info;
41367172 4172
718e3744 4173 /* Update BGP RIB. */
4174 if (! bgp_static->backdoor)
4175 bgp_static_withdraw (bgp, &p, afi, safi);
4176
4177 /* Clear configuration. */
4178 bgp_static_free (bgp_static);
4179 rn->info = NULL;
4180 bgp_unlock_node (rn);
4181 bgp_unlock_node (rn);
4182
4183 return CMD_SUCCESS;
4184}
4185
6aeb9e78
DS
4186void
4187bgp_static_add (struct bgp *bgp)
4188{
4189 afi_t afi;
4190 safi_t safi;
4191 struct bgp_node *rn;
4192 struct bgp_node *rm;
4193 struct bgp_table *table;
4194 struct bgp_static *bgp_static;
4195
4196 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4197 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4198 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4199 if (rn->info != NULL)
4200 {
4201 if (safi == SAFI_MPLS_VPN)
4202 {
4203 table = rn->info;
4204
4205 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4206 {
4207 bgp_static = rn->info;
137446f9 4208 bgp_static_update_safi (bgp, &rm->p, bgp_static, afi, safi);
6aeb9e78
DS
4209 }
4210 }
4211 else
4212 {
4213 bgp_static_update (bgp, &rn->p, rn->info, afi, safi);
4214 }
4215 }
4216}
4217
718e3744 4218/* Called from bgp_delete(). Delete all static routes from the BGP
4219 instance. */
4220void
4221bgp_static_delete (struct bgp *bgp)
4222{
4223 afi_t afi;
4224 safi_t safi;
4225 struct bgp_node *rn;
4226 struct bgp_node *rm;
4227 struct bgp_table *table;
4228 struct bgp_static *bgp_static;
4229
4230 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4231 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4232 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4233 if (rn->info != NULL)
4234 {
587ff0fd 4235 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 4236 {
4237 table = rn->info;
4238
4239 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4240 {
4241 bgp_static = rn->info;
137446f9
LB
4242 bgp_static_withdraw_safi (bgp, &rm->p,
4243 AFI_IP, safi,
718e3744 4244 (struct prefix_rd *)&rn->p,
4245 bgp_static->tag);
4246 bgp_static_free (bgp_static);
4247 rn->info = NULL;
4248 bgp_unlock_node (rn);
4249 }
4250 }
4251 else
4252 {
4253 bgp_static = rn->info;
4254 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4255 bgp_static_free (bgp_static);
4256 rn->info = NULL;
4257 bgp_unlock_node (rn);
4258 }
4259 }
4260}
4261
078430f6
DS
4262void
4263bgp_static_redo_import_check (struct bgp *bgp)
4264{
4265 afi_t afi;
4266 safi_t safi;
4267 struct bgp_node *rn;
078430f6
DS
4268 struct bgp_static *bgp_static;
4269
4270 /* Use this flag to force reprocessing of the route */
4271 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4272 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4273 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4274 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4275 if (rn->info != NULL)
4276 {
4277 bgp_static = rn->info;
4278 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
4279 }
4280 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4281}
4282
ad4cbda1 4283static void
4284bgp_purge_af_static_redist_routes (struct bgp *bgp, afi_t afi, safi_t safi)
4285{
4286 struct bgp_table *table;
4287 struct bgp_node *rn;
4288 struct bgp_info *ri;
4289
4290 table = bgp->rib[afi][safi];
4291 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4292 {
4293 for (ri = rn->info; ri; ri = ri->next)
4294 {
4295 if (ri->peer == bgp->peer_self &&
4296 ((ri->type == ZEBRA_ROUTE_BGP &&
4297 ri->sub_type == BGP_ROUTE_STATIC) ||
4298 (ri->type != ZEBRA_ROUTE_BGP &&
4299 ri->sub_type == BGP_ROUTE_REDISTRIBUTE)))
4300 {
4301 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, safi);
4302 bgp_unlink_nexthop(ri);
4303 bgp_info_delete (rn, ri);
4304 bgp_process (bgp, rn, afi, safi);
4305 }
4306 }
4307 }
4308}
4309
4310/*
4311 * Purge all networks and redistributed routes from routing table.
4312 * Invoked upon the instance going down.
4313 */
4314void
4315bgp_purge_static_redist_routes (struct bgp *bgp)
4316{
4317 afi_t afi;
4318 safi_t safi;
4319
4320 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4321 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4322 bgp_purge_af_static_redist_routes (bgp, afi, safi);
4323}
4324
137446f9
LB
4325/*
4326 * gpz 110624
4327 * Currently this is used to set static routes for VPN and ENCAP.
4328 * I think it can probably be factored with bgp_static_set.
4329 */
718e3744 4330int
137446f9
LB
4331bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4332 const char *rd_str, const char *tag_str,
4333 const char *rmap_str)
718e3744 4334{
4335 int ret;
4336 struct prefix p;
4337 struct prefix_rd prd;
4338 struct bgp *bgp;
4339 struct bgp_node *prn;
4340 struct bgp_node *rn;
4341 struct bgp_table *table;
4342 struct bgp_static *bgp_static;
4343 u_char tag[3];
4344
4345 bgp = vty->index;
4346
4347 ret = str2prefix (ip_str, &p);
4348 if (! ret)
4349 {
4350 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4351 return CMD_WARNING;
4352 }
4353 apply_mask (&p);
4354
4355 ret = str2prefix_rd (rd_str, &prd);
4356 if (! ret)
4357 {
4358 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4359 return CMD_WARNING;
4360 }
4361
4362 ret = str2tag (tag_str, tag);
4363 if (! ret)
4364 {
4365 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4366 return CMD_WARNING;
4367 }
4368
137446f9 4369 prn = bgp_node_get (bgp->route[AFI_IP][safi],
718e3744 4370 (struct prefix *)&prd);
4371 if (prn->info == NULL)
137446f9 4372 prn->info = bgp_table_init (AFI_IP, safi);
718e3744 4373 else
4374 bgp_unlock_node (prn);
4375 table = prn->info;
4376
4377 rn = bgp_node_get (table, &p);
4378
4379 if (rn->info)
4380 {
4381 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4382 bgp_unlock_node (rn);
4383 }
4384 else
4385 {
4386 /* New configuration. */
4387 bgp_static = bgp_static_new ();
137446f9
LB
4388 bgp_static->backdoor = 0;
4389 bgp_static->valid = 0;
4390 bgp_static->igpmetric = 0;
4391 bgp_static->igpnexthop.s_addr = 0;
4392 memcpy(bgp_static->tag, tag, 3);
4393 bgp_static->prd = prd;
4394
4395 if (rmap_str)
4396 {
4397 if (bgp_static->rmap.name)
4398 free (bgp_static->rmap.name);
4399 bgp_static->rmap.name = strdup (rmap_str);
4400 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4401 }
718e3744 4402 rn->info = bgp_static;
4403
137446f9
LB
4404 bgp_static->valid = 1;
4405 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
718e3744 4406 }
4407
4408 return CMD_SUCCESS;
4409}
4410
4411/* Configure static BGP network. */
4412int
137446f9
LB
4413bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4414 const char *rd_str, const char *tag_str)
718e3744 4415{
4416 int ret;
4417 struct bgp *bgp;
4418 struct prefix p;
4419 struct prefix_rd prd;
4420 struct bgp_node *prn;
4421 struct bgp_node *rn;
4422 struct bgp_table *table;
4423 struct bgp_static *bgp_static;
4424 u_char tag[3];
4425
4426 bgp = vty->index;
4427
4428 /* Convert IP prefix string to struct prefix. */
4429 ret = str2prefix (ip_str, &p);
4430 if (! ret)
4431 {
4432 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4433 return CMD_WARNING;
4434 }
4435 apply_mask (&p);
4436
4437 ret = str2prefix_rd (rd_str, &prd);
4438 if (! ret)
4439 {
4440 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4441 return CMD_WARNING;
4442 }
4443
4444 ret = str2tag (tag_str, tag);
4445 if (! ret)
4446 {
4447 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4448 return CMD_WARNING;
4449 }
4450
137446f9 4451 prn = bgp_node_get (bgp->route[AFI_IP][safi],
718e3744 4452 (struct prefix *)&prd);
4453 if (prn->info == NULL)
137446f9 4454 prn->info = bgp_table_init (AFI_IP, safi);
718e3744 4455 else
4456 bgp_unlock_node (prn);
4457 table = prn->info;
4458
4459 rn = bgp_node_lookup (table, &p);
4460
4461 if (rn)
4462 {
137446f9 4463 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
718e3744 4464
4465 bgp_static = rn->info;
4466 bgp_static_free (bgp_static);
4467 rn->info = NULL;
4468 bgp_unlock_node (rn);
4469 bgp_unlock_node (rn);
4470 }
4471 else
4472 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4473
4474 return CMD_SUCCESS;
4475}
6b0655a2 4476
73ac8160
DS
4477static int
4478bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4479 const char *rmap_name)
4480{
4481 struct bgp_rmap *rmap;
4482
4483 rmap = &bgp->table_map[afi][safi];
4484 if (rmap_name)
4485 {
4486 if (rmap->name)
6e919709
DS
4487 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4488 rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name);
73ac8160
DS
4489 rmap->map = route_map_lookup_by_name (rmap_name);
4490 }
4491 else
4492 {
4493 if (rmap->name)
6e919709 4494 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
73ac8160
DS
4495 rmap->name = NULL;
4496 rmap->map = NULL;
4497 }
4498
4499 bgp_zebra_announce_table(bgp, afi, safi);
4500
4501 return CMD_SUCCESS;
4502}
4503
4504static int
4505bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4506 const char *rmap_name)
4507{
4508 struct bgp_rmap *rmap;
4509
4510 rmap = &bgp->table_map[afi][safi];
4511 if (rmap->name)
6e919709 4512 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
73ac8160
DS
4513 rmap->name = NULL;
4514 rmap->map = NULL;
4515
4516 bgp_zebra_announce_table(bgp, afi, safi);
4517
4518 return CMD_SUCCESS;
4519}
4520
4521int
4522bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4523 safi_t safi, int *write)
4524{
4525 if (bgp->table_map[afi][safi].name)
4526 {
4527 bgp_config_write_family_header (vty, afi, safi, write);
0b960b4d 4528 vty_out (vty, " table-map %s%s",
73ac8160
DS
4529 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4530 }
4531
4532 return 0;
4533}
4534
73ac8160
DS
4535DEFUN (bgp_table_map,
4536 bgp_table_map_cmd,
4537 "table-map WORD",
4538 "BGP table to RIB route download filter\n"
4539 "Name of the route map\n")
4540{
4541 return bgp_table_map_set (vty, vty->index,
4542 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4543}
4544DEFUN (no_bgp_table_map,
4545 no_bgp_table_map_cmd,
4546 "no table-map WORD",
4547 "BGP table to RIB route download filter\n"
4548 "Name of the route map\n")
4549{
4550 return bgp_table_map_unset (vty, vty->index,
4551 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4552}
4553
718e3744 4554DEFUN (bgp_network,
4555 bgp_network_cmd,
4556 "network A.B.C.D/M",
4557 "Specify a network to announce via BGP\n"
4558 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4559{
4560 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 4561 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4562}
4563
4564DEFUN (bgp_network_route_map,
4565 bgp_network_route_map_cmd,
4566 "network A.B.C.D/M route-map WORD",
4567 "Specify a network to announce via BGP\n"
4568 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4569 "Route-map to modify the attributes\n"
4570 "Name of the route map\n")
4571{
4572 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 4573 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 4574}
4575
4576DEFUN (bgp_network_backdoor,
4577 bgp_network_backdoor_cmd,
4578 "network A.B.C.D/M backdoor",
4579 "Specify a network to announce via BGP\n"
4580 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4581 "Specify a BGP backdoor route\n")
4582{
41367172 4583 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
c8f3fe30 4584 NULL, 1);
718e3744 4585}
4586
4587DEFUN (bgp_network_mask,
4588 bgp_network_mask_cmd,
4589 "network A.B.C.D mask A.B.C.D",
4590 "Specify a network to announce via BGP\n"
4591 "Network number\n"
4592 "Network mask\n"
4593 "Network mask\n")
4594{
4595 int ret;
4596 char prefix_str[BUFSIZ];
41367172 4597
718e3744 4598 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4599 if (! ret)
4600 {
4601 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4602 return CMD_WARNING;
4603 }
4604
4605 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4606 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4607}
4608
4609DEFUN (bgp_network_mask_route_map,
4610 bgp_network_mask_route_map_cmd,
4611 "network A.B.C.D mask A.B.C.D route-map WORD",
4612 "Specify a network to announce via BGP\n"
4613 "Network number\n"
4614 "Network mask\n"
4615 "Network mask\n"
4616 "Route-map to modify the attributes\n"
4617 "Name of the route map\n")
4618{
4619 int ret;
4620 char prefix_str[BUFSIZ];
41367172 4621
718e3744 4622 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4623 if (! ret)
4624 {
4625 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4626 return CMD_WARNING;
4627 }
4628
4629 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4630 AFI_IP, bgp_node_safi (vty), argv[2], 0);
718e3744 4631}
4632
4633DEFUN (bgp_network_mask_backdoor,
4634 bgp_network_mask_backdoor_cmd,
4635 "network A.B.C.D mask A.B.C.D backdoor",
4636 "Specify a network to announce via BGP\n"
4637 "Network number\n"
4638 "Network mask\n"
4639 "Network mask\n"
4640 "Specify a BGP backdoor route\n")
4641{
4642 int ret;
4643 char prefix_str[BUFSIZ];
41367172 4644
718e3744 4645 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4646 if (! ret)
4647 {
4648 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4649 return CMD_WARNING;
4650 }
4651
41367172 4652 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 4653 NULL, 1);
718e3744 4654}
4655
4656DEFUN (bgp_network_mask_natural,
4657 bgp_network_mask_natural_cmd,
4658 "network A.B.C.D",
4659 "Specify a network to announce via BGP\n"
4660 "Network number\n")
4661{
4662 int ret;
4663 char prefix_str[BUFSIZ];
4664
4665 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4666 if (! ret)
4667 {
4668 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4669 return CMD_WARNING;
4670 }
4671
4672 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4673 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4674}
4675
4676DEFUN (bgp_network_mask_natural_route_map,
4677 bgp_network_mask_natural_route_map_cmd,
4678 "network A.B.C.D route-map WORD",
4679 "Specify a network to announce via BGP\n"
4680 "Network number\n"
4681 "Route-map to modify the attributes\n"
4682 "Name of the route map\n")
4683{
4684 int ret;
4685 char prefix_str[BUFSIZ];
4686
4687 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4688 if (! ret)
4689 {
4690 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4691 return CMD_WARNING;
4692 }
4693
4694 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4695 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 4696}
4697
4698DEFUN (bgp_network_mask_natural_backdoor,
4699 bgp_network_mask_natural_backdoor_cmd,
4700 "network A.B.C.D backdoor",
4701 "Specify a network to announce via BGP\n"
4702 "Network number\n"
4703 "Specify a BGP backdoor route\n")
4704{
4705 int ret;
4706 char prefix_str[BUFSIZ];
4707
4708 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4709 if (! ret)
4710 {
4711 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4712 return CMD_WARNING;
4713 }
4714
41367172 4715 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 4716 NULL, 1);
718e3744 4717}
4718
4719DEFUN (no_bgp_network,
4720 no_bgp_network_cmd,
4721 "no network A.B.C.D/M",
4722 NO_STR
4723 "Specify a network to announce via BGP\n"
4724 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4725{
4726 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4727 bgp_node_safi (vty));
4728}
4729
4730ALIAS (no_bgp_network,
4731 no_bgp_network_route_map_cmd,
4732 "no network A.B.C.D/M route-map WORD",
4733 NO_STR
4734 "Specify a network to announce via BGP\n"
4735 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4736 "Route-map to modify the attributes\n"
4737 "Name of the route map\n")
4738
4739ALIAS (no_bgp_network,
4740 no_bgp_network_backdoor_cmd,
4741 "no network A.B.C.D/M backdoor",
4742 NO_STR
4743 "Specify a network to announce via BGP\n"
4744 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4745 "Specify a BGP backdoor route\n")
4746
4747DEFUN (no_bgp_network_mask,
4748 no_bgp_network_mask_cmd,
4749 "no network A.B.C.D mask A.B.C.D",
4750 NO_STR
4751 "Specify a network to announce via BGP\n"
4752 "Network number\n"
4753 "Network mask\n"
4754 "Network mask\n")
4755{
4756 int ret;
4757 char prefix_str[BUFSIZ];
4758
4759 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4760 if (! ret)
4761 {
4762 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4763 return CMD_WARNING;
4764 }
4765
4766 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4767 bgp_node_safi (vty));
4768}
4769
4770ALIAS (no_bgp_network_mask,
4771 no_bgp_network_mask_route_map_cmd,
4772 "no network A.B.C.D mask A.B.C.D route-map WORD",
4773 NO_STR
4774 "Specify a network to announce via BGP\n"
4775 "Network number\n"
4776 "Network mask\n"
4777 "Network mask\n"
4778 "Route-map to modify the attributes\n"
4779 "Name of the route map\n")
4780
4781ALIAS (no_bgp_network_mask,
4782 no_bgp_network_mask_backdoor_cmd,
4783 "no network A.B.C.D mask A.B.C.D backdoor",
4784 NO_STR
4785 "Specify a network to announce via BGP\n"
4786 "Network number\n"
4787 "Network mask\n"
4788 "Network mask\n"
4789 "Specify a BGP backdoor route\n")
4790
4791DEFUN (no_bgp_network_mask_natural,
4792 no_bgp_network_mask_natural_cmd,
4793 "no network A.B.C.D",
4794 NO_STR
4795 "Specify a network to announce via BGP\n"
4796 "Network number\n")
4797{
4798 int ret;
4799 char prefix_str[BUFSIZ];
4800
4801 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4802 if (! ret)
4803 {
4804 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4805 return CMD_WARNING;
4806 }
4807
4808 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4809 bgp_node_safi (vty));
4810}
4811
4812ALIAS (no_bgp_network_mask_natural,
4813 no_bgp_network_mask_natural_route_map_cmd,
4814 "no network A.B.C.D route-map WORD",
4815 NO_STR
4816 "Specify a network to announce via BGP\n"
4817 "Network number\n"
4818 "Route-map to modify the attributes\n"
4819 "Name of the route map\n")
4820
4821ALIAS (no_bgp_network_mask_natural,
4822 no_bgp_network_mask_natural_backdoor_cmd,
4823 "no network A.B.C.D backdoor",
4824 NO_STR
4825 "Specify a network to announce via BGP\n"
4826 "Network number\n"
4827 "Specify a BGP backdoor route\n")
4828
4829#ifdef HAVE_IPV6
4830DEFUN (ipv6_bgp_network,
4831 ipv6_bgp_network_cmd,
4832 "network X:X::X:X/M",
4833 "Specify a network to announce via BGP\n"
4834 "IPv6 prefix <network>/<length>\n")
4835{
73bfe0bd 4836 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
c8f3fe30 4837 NULL, 0);
718e3744 4838}
4839
4840DEFUN (ipv6_bgp_network_route_map,
4841 ipv6_bgp_network_route_map_cmd,
4842 "network X:X::X:X/M route-map WORD",
4843 "Specify a network to announce via BGP\n"
4844 "IPv6 prefix <network>/<length>\n"
4845 "Route-map to modify the attributes\n"
4846 "Name of the route map\n")
4847{
4848 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
c8f3fe30 4849 bgp_node_safi (vty), argv[1], 0);
718e3744 4850}
4851
4852DEFUN (no_ipv6_bgp_network,
4853 no_ipv6_bgp_network_cmd,
4854 "no network X:X::X:X/M",
4855 NO_STR
4856 "Specify a network to announce via BGP\n"
4857 "IPv6 prefix <network>/<length>\n")
4858{
73bfe0bd 4859 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
718e3744 4860}
4861
4862ALIAS (no_ipv6_bgp_network,
4863 no_ipv6_bgp_network_route_map_cmd,
4864 "no network X:X::X:X/M route-map WORD",
4865 NO_STR
4866 "Specify a network to announce via BGP\n"
4867 "IPv6 prefix <network>/<length>\n"
4868 "Route-map to modify the attributes\n"
4869 "Name of the route map\n")
4870
4871ALIAS (ipv6_bgp_network,
4872 old_ipv6_bgp_network_cmd,
4873 "ipv6 bgp network X:X::X:X/M",
4874 IPV6_STR
4875 BGP_STR
4876 "Specify a network to announce via BGP\n"
4877 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4878
4879ALIAS (no_ipv6_bgp_network,
4880 old_no_ipv6_bgp_network_cmd,
4881 "no ipv6 bgp network X:X::X:X/M",
4882 NO_STR
4883 IPV6_STR
4884 BGP_STR
4885 "Specify a network to announce via BGP\n"
4886 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4887#endif /* HAVE_IPV6 */
c8f3fe30 4888
718e3744 4889/* Aggreagete address:
4890
4891 advertise-map Set condition to advertise attribute
4892 as-set Generate AS set path information
4893 attribute-map Set attributes of aggregate
4894 route-map Set parameters of aggregate
4895 summary-only Filter more specific routes from updates
4896 suppress-map Conditionally filter more specific routes from updates
4897 <cr>
4898 */
4899struct bgp_aggregate
4900{
4901 /* Summary-only flag. */
4902 u_char summary_only;
4903
4904 /* AS set generation. */
4905 u_char as_set;
4906
4907 /* Route-map for aggregated route. */
4908 struct route_map *map;
4909
4910 /* Suppress-count. */
4911 unsigned long count;
4912
4913 /* SAFI configuration. */
4914 safi_t safi;
4915};
4916
94f2b392 4917static struct bgp_aggregate *
66e5cd87 4918bgp_aggregate_new (void)
718e3744 4919{
393deb9b 4920 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
718e3744 4921}
4922
94f2b392 4923static void
718e3744 4924bgp_aggregate_free (struct bgp_aggregate *aggregate)
4925{
4926 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4927}
4928
b5d58c32 4929/* Update an aggregate as routes are added/removed from the BGP table */
94f2b392 4930static void
718e3744 4931bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4932 afi_t afi, safi_t safi, struct bgp_info *del,
4933 struct bgp_aggregate *aggregate)
4934{
4935 struct bgp_table *table;
4936 struct bgp_node *top;
4937 struct bgp_node *rn;
4938 u_char origin;
4939 struct aspath *aspath = NULL;
4940 struct aspath *asmerge = NULL;
4941 struct community *community = NULL;
4942 struct community *commerge = NULL;
ffd0c037 4943#if defined(AGGREGATE_NEXTHOP_CHECK)
718e3744 4944 struct in_addr nexthop;
4945 u_int32_t med = 0;
ffd0c037 4946#endif
718e3744 4947 struct bgp_info *ri;
4948 struct bgp_info *new;
4949 int first = 1;
4950 unsigned long match = 0;
42f7e184 4951 u_char atomic_aggregate = 0;
718e3744 4952
4953 /* Record adding route's nexthop and med. */
ffd0c037
DS
4954 if (rinew)
4955 {
4956#if defined(AGGREGATE_NEXTHOP_CHECK)
4957 nexthop = rinew->attr->nexthop;
4958 med = rinew->attr->med;
4959#endif
4960 }
718e3744 4961
4962 /* ORIGIN attribute: If at least one route among routes that are
4963 aggregated has ORIGIN with the value INCOMPLETE, then the
4964 aggregated route must have the ORIGIN attribute with the value
4965 INCOMPLETE. Otherwise, if at least one route among routes that
4966 are aggregated has ORIGIN with the value EGP, then the aggregated
4967 route must have the origin attribute with the value EGP. In all
4968 other case the value of the ORIGIN attribute of the aggregated
4969 route is INTERNAL. */
4970 origin = BGP_ORIGIN_IGP;
4971
4972 table = bgp->rib[afi][safi];
4973
4974 top = bgp_node_get (table, p);
4975 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4976 if (rn->p.prefixlen > p->prefixlen)
4977 {
4978 match = 0;
4979
4980 for (ri = rn->info; ri; ri = ri->next)
4981 {
4982 if (BGP_INFO_HOLDDOWN (ri))
4983 continue;
4984
4985 if (del && ri == del)
4986 continue;
4987
4988 if (! rinew && first)
4989 {
ffd0c037 4990#if defined(AGGREGATE_NEXTHOP_CHECK)
718e3744 4991 nexthop = ri->attr->nexthop;
4992 med = ri->attr->med;
ffd0c037 4993#endif
718e3744 4994 first = 0;
4995 }
4996
4997#ifdef AGGREGATE_NEXTHOP_CHECK
4998 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4999 || ri->attr->med != med)
5000 {
5001 if (aspath)
5002 aspath_free (aspath);
5003 if (community)
5004 community_free (community);
5005 bgp_unlock_node (rn);
5006 bgp_unlock_node (top);
5007 return;
5008 }
5009#endif /* AGGREGATE_NEXTHOP_CHECK */
5010
42f7e184
DS
5011 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5012 atomic_aggregate = 1;
5013
718e3744 5014 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5015 {
5016 if (aggregate->summary_only)
5017 {
fb982c25 5018 (bgp_info_extra_get (ri))->suppress++;
1a392d46 5019 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5020 match++;
5021 }
5022
5023 aggregate->count++;
5024
b5d58c32
DS
5025 if (origin < ri->attr->origin)
5026 origin = ri->attr->origin;
5027
718e3744 5028 if (aggregate->as_set)
5029 {
718e3744 5030 if (aspath)
5031 {
5032 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5033 aspath_free (aspath);
5034 aspath = asmerge;
5035 }
5036 else
5037 aspath = aspath_dup (ri->attr->aspath);
5038
5039 if (ri->attr->community)
5040 {
5041 if (community)
5042 {
5043 commerge = community_merge (community,
5044 ri->attr->community);
5045 community = community_uniq_sort (commerge);
5046 community_free (commerge);
5047 }
5048 else
5049 community = community_dup (ri->attr->community);
5050 }
5051 }
5052 }
5053 }
5054 if (match)
5055 bgp_process (bgp, rn, afi, safi);
5056 }
5057 bgp_unlock_node (top);
5058
5059 if (rinew)
5060 {
5061 aggregate->count++;
5062
5063 if (aggregate->summary_only)
fb982c25 5064 (bgp_info_extra_get (rinew))->suppress++;
718e3744 5065
b5d58c32
DS
5066 if (origin < rinew->attr->origin)
5067 origin = rinew->attr->origin;
5068
718e3744 5069 if (aggregate->as_set)
5070 {
718e3744 5071 if (aspath)
5072 {
5073 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
5074 aspath_free (aspath);
5075 aspath = asmerge;
5076 }
5077 else
5078 aspath = aspath_dup (rinew->attr->aspath);
5079
5080 if (rinew->attr->community)
5081 {
5082 if (community)
5083 {
5084 commerge = community_merge (community,
5085 rinew->attr->community);
5086 community = community_uniq_sort (commerge);
5087 community_free (commerge);
5088 }
5089 else
5090 community = community_dup (rinew->attr->community);
5091 }
5092 }
5093 }
5094
5095 if (aggregate->count > 0)
5096 {
5097 rn = bgp_node_get (table, p);
7c8ff89e 5098 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 5099 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
5100 aggregate->as_set,
5101 atomic_aggregate), rn);
718e3744 5102 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 5103
5104 bgp_info_add (rn, new);
200df115 5105 bgp_unlock_node (rn);
718e3744 5106 bgp_process (bgp, rn, afi, safi);
5107 }
5108 else
5109 {
5110 if (aspath)
5111 aspath_free (aspath);
5112 if (community)
5113 community_free (community);
5114 }
5115}
5116
5117void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
5118 struct bgp_aggregate *);
5119
5120void
5121bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
5122 struct bgp_info *ri, afi_t afi, safi_t safi)
5123{
5124 struct bgp_node *child;
5125 struct bgp_node *rn;
5126 struct bgp_aggregate *aggregate;
f018db83 5127 struct bgp_table *table;
718e3744 5128
5129 /* MPLS-VPN aggregation is not yet supported. */
587ff0fd 5130 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 5131 return;
5132
f018db83
JBD
5133 table = bgp->aggregate[afi][safi];
5134
5135 /* No aggregates configured. */
67174041 5136 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
5137 return;
5138
718e3744 5139 if (p->prefixlen == 0)
5140 return;
5141
5142 if (BGP_INFO_HOLDDOWN (ri))
5143 return;
5144
bb782fb5 5145 child = bgp_node_get (table, p);
718e3744 5146
5147 /* Aggregate address configuration check. */
67174041 5148 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 5149 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5150 {
5151 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 5152 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
718e3744 5153 }
5154 bgp_unlock_node (child);
5155}
5156
5157void
5158bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
5159 struct bgp_info *del, afi_t afi, safi_t safi)
5160{
5161 struct bgp_node *child;
5162 struct bgp_node *rn;
5163 struct bgp_aggregate *aggregate;
f018db83 5164 struct bgp_table *table;
718e3744 5165
5166 /* MPLS-VPN aggregation is not yet supported. */
587ff0fd 5167 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 5168 return;
5169
f018db83
JBD
5170 table = bgp->aggregate[afi][safi];
5171
5172 /* No aggregates configured. */
67174041 5173 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
5174 return;
5175
718e3744 5176 if (p->prefixlen == 0)
5177 return;
5178
bb782fb5 5179 child = bgp_node_get (table, p);
718e3744 5180
5181 /* Aggregate address configuration check. */
67174041 5182 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 5183 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5184 {
5185 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 5186 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
718e3744 5187 }
5188 bgp_unlock_node (child);
5189}
5190
b5d58c32 5191/* Called via bgp_aggregate_set when the user configures aggregate-address */
94f2b392 5192static void
718e3744 5193bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5194 struct bgp_aggregate *aggregate)
5195{
5196 struct bgp_table *table;
5197 struct bgp_node *top;
5198 struct bgp_node *rn;
5199 struct bgp_info *new;
5200 struct bgp_info *ri;
5201 unsigned long match;
5202 u_char origin = BGP_ORIGIN_IGP;
5203 struct aspath *aspath = NULL;
5204 struct aspath *asmerge = NULL;
5205 struct community *community = NULL;
5206 struct community *commerge = NULL;
42f7e184 5207 u_char atomic_aggregate = 0;
718e3744 5208
5209 table = bgp->rib[afi][safi];
5210
5211 /* Sanity check. */
5212 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5213 return;
5214 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5215 return;
5216
5217 /* If routes exists below this node, generate aggregate routes. */
5218 top = bgp_node_get (table, p);
5219 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5220 if (rn->p.prefixlen > p->prefixlen)
5221 {
5222 match = 0;
5223
5224 for (ri = rn->info; ri; ri = ri->next)
5225 {
5226 if (BGP_INFO_HOLDDOWN (ri))
5227 continue;
5228
42f7e184
DS
5229 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5230 atomic_aggregate = 1;
5231
718e3744 5232 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5233 {
5234 /* summary-only aggregate route suppress aggregated
5235 route announcement. */
5236 if (aggregate->summary_only)
5237 {
fb982c25 5238 (bgp_info_extra_get (ri))->suppress++;
1a392d46 5239 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5240 match++;
5241 }
b5d58c32
DS
5242
5243 /* If at least one route among routes that are aggregated has
5244 * ORIGIN with the value INCOMPLETE, then the aggregated route
5245 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5246 * Otherwise, if at least one route among routes that are
5247 * aggregated has ORIGIN with the value EGP, then the aggregated
5248 * route MUST have the ORIGIN attribute with the value EGP.
5249 */
5250 if (origin < ri->attr->origin)
5251 origin = ri->attr->origin;
5252
718e3744 5253 /* as-set aggregate route generate origin, as path,
5254 community aggregation. */
5255 if (aggregate->as_set)
5256 {
718e3744 5257 if (aspath)
5258 {
5259 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5260 aspath_free (aspath);
5261 aspath = asmerge;
5262 }
5263 else
5264 aspath = aspath_dup (ri->attr->aspath);
5265
5266 if (ri->attr->community)
5267 {
5268 if (community)
5269 {
5270 commerge = community_merge (community,
5271 ri->attr->community);
5272 community = community_uniq_sort (commerge);
5273 community_free (commerge);
5274 }
5275 else
5276 community = community_dup (ri->attr->community);
5277 }
5278 }
5279 aggregate->count++;
5280 }
5281 }
5282
5283 /* If this node is suppressed, process the change. */
5284 if (match)
5285 bgp_process (bgp, rn, afi, safi);
5286 }
5287 bgp_unlock_node (top);
5288
5289 /* Add aggregate route to BGP table. */
5290 if (aggregate->count)
5291 {
5292 rn = bgp_node_get (table, p);
7c8ff89e 5293 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 5294 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
5295 aggregate->as_set,
5296 atomic_aggregate), rn);
718e3744 5297 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 5298
5299 bgp_info_add (rn, new);
200df115 5300 bgp_unlock_node (rn);
5301
718e3744 5302 /* Process change. */
5303 bgp_process (bgp, rn, afi, safi);
5304 }
610f23cf
DV
5305 else
5306 {
5307 if (aspath)
5308 aspath_free (aspath);
5309 if (community)
5310 community_free (community);
5311 }
718e3744 5312}
5313
5314void
5315bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5316 safi_t safi, struct bgp_aggregate *aggregate)
5317{
5318 struct bgp_table *table;
5319 struct bgp_node *top;
5320 struct bgp_node *rn;
5321 struct bgp_info *ri;
5322 unsigned long match;
5323
5324 table = bgp->rib[afi][safi];
5325
5326 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5327 return;
5328 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5329 return;
5330
5331 /* If routes exists below this node, generate aggregate routes. */
5332 top = bgp_node_get (table, p);
5333 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5334 if (rn->p.prefixlen > p->prefixlen)
5335 {
5336 match = 0;
5337
5338 for (ri = rn->info; ri; ri = ri->next)
5339 {
5340 if (BGP_INFO_HOLDDOWN (ri))
5341 continue;
5342
5343 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5344 {
fb982c25 5345 if (aggregate->summary_only && ri->extra)
718e3744 5346 {
fb982c25 5347 ri->extra->suppress--;
718e3744 5348
fb982c25 5349 if (ri->extra->suppress == 0)
718e3744 5350 {
1a392d46 5351 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5352 match++;
5353 }
5354 }
5355 aggregate->count--;
5356 }
5357 }
5358
fb982c25 5359 /* If this node was suppressed, process the change. */
718e3744 5360 if (match)
5361 bgp_process (bgp, rn, afi, safi);
5362 }
5363 bgp_unlock_node (top);
5364
5365 /* Delete aggregate route from BGP table. */
5366 rn = bgp_node_get (table, p);
5367
5368 for (ri = rn->info; ri; ri = ri->next)
5369 if (ri->peer == bgp->peer_self
5370 && ri->type == ZEBRA_ROUTE_BGP
5371 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5372 break;
5373
5374 /* Withdraw static BGP route from routing table. */
5375 if (ri)
5376 {
718e3744 5377 bgp_info_delete (rn, ri);
1a392d46 5378 bgp_process (bgp, rn, afi, safi);
718e3744 5379 }
5380
5381 /* Unlock bgp_node_lookup. */
5382 bgp_unlock_node (rn);
5383}
5384
5385/* Aggregate route attribute. */
5386#define AGGREGATE_SUMMARY_ONLY 1
5387#define AGGREGATE_AS_SET 1
5388
94f2b392 5389static int
f6269b4f
RB
5390bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5391 afi_t afi, safi_t safi)
718e3744 5392{
5393 int ret;
5394 struct prefix p;
5395 struct bgp_node *rn;
5396 struct bgp *bgp;
5397 struct bgp_aggregate *aggregate;
5398
5399 /* Convert string to prefix structure. */
5400 ret = str2prefix (prefix_str, &p);
5401 if (!ret)
5402 {
5403 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5404 return CMD_WARNING;
5405 }
5406 apply_mask (&p);
5407
5408 /* Get BGP structure. */
5409 bgp = vty->index;
5410
5411 /* Old configuration check. */
f6269b4f
RB
5412 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5413 if (! rn)
718e3744 5414 {
f6269b4f
RB
5415 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5416 VTY_NEWLINE);
718e3744 5417 return CMD_WARNING;
5418 }
5419
f6269b4f
RB
5420 aggregate = rn->info;
5421 if (aggregate->safi & SAFI_UNICAST)
5422 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5423 if (aggregate->safi & SAFI_MULTICAST)
5424 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 5425
f6269b4f
RB
5426 /* Unlock aggregate address configuration. */
5427 rn->info = NULL;
5428 bgp_aggregate_free (aggregate);
5429 bgp_unlock_node (rn);
5430 bgp_unlock_node (rn);
718e3744 5431
5432 return CMD_SUCCESS;
5433}
5434
94f2b392 5435static int
f6269b4f
RB
5436bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5437 afi_t afi, safi_t safi,
5438 u_char summary_only, u_char as_set)
718e3744 5439{
5440 int ret;
5441 struct prefix p;
5442 struct bgp_node *rn;
5443 struct bgp *bgp;
5444 struct bgp_aggregate *aggregate;
5445
5446 /* Convert string to prefix structure. */
5447 ret = str2prefix (prefix_str, &p);
5448 if (!ret)
5449 {
5450 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5451 return CMD_WARNING;
5452 }
5453 apply_mask (&p);
5454
5455 /* Get BGP structure. */
5456 bgp = vty->index;
5457
5458 /* Old configuration check. */
f6269b4f
RB
5459 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5460
5461 if (rn->info)
718e3744 5462 {
f6269b4f 5463 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
368473f6 5464 /* try to remove the old entry */
f6269b4f
RB
5465 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5466 if (ret)
5467 {
368473f6
RB
5468 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5469 bgp_unlock_node (rn);
f6269b4f
RB
5470 return CMD_WARNING;
5471 }
718e3744 5472 }
5473
f6269b4f
RB
5474 /* Make aggregate address structure. */
5475 aggregate = bgp_aggregate_new ();
5476 aggregate->summary_only = summary_only;
5477 aggregate->as_set = as_set;
5478 aggregate->safi = safi;
5479 rn->info = aggregate;
718e3744 5480
f6269b4f
RB
5481 /* Aggregate address insert into BGP routing table. */
5482 if (safi & SAFI_UNICAST)
5483 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5484 if (safi & SAFI_MULTICAST)
5485 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 5486
5487 return CMD_SUCCESS;
5488}
5489
5490DEFUN (aggregate_address,
5491 aggregate_address_cmd,
5492 "aggregate-address A.B.C.D/M",
5493 "Configure BGP aggregate entries\n"
5494 "Aggregate prefix\n")
5495{
5496 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5497}
5498
5499DEFUN (aggregate_address_mask,
5500 aggregate_address_mask_cmd,
5501 "aggregate-address A.B.C.D A.B.C.D",
5502 "Configure BGP aggregate entries\n"
5503 "Aggregate address\n"
5504 "Aggregate mask\n")
5505{
5506 int ret;
5507 char prefix_str[BUFSIZ];
5508
5509 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5510
5511 if (! ret)
5512 {
5513 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5514 return CMD_WARNING;
5515 }
5516
5517 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5518 0, 0);
5519}
5520
5521DEFUN (aggregate_address_summary_only,
5522 aggregate_address_summary_only_cmd,
5523 "aggregate-address A.B.C.D/M summary-only",
5524 "Configure BGP aggregate entries\n"
5525 "Aggregate prefix\n"
5526 "Filter more specific routes from updates\n")
5527{
5528 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5529 AGGREGATE_SUMMARY_ONLY, 0);
5530}
5531
5532DEFUN (aggregate_address_mask_summary_only,
5533 aggregate_address_mask_summary_only_cmd,
5534 "aggregate-address A.B.C.D A.B.C.D summary-only",
5535 "Configure BGP aggregate entries\n"
5536 "Aggregate address\n"
5537 "Aggregate mask\n"
5538 "Filter more specific routes from updates\n")
5539{
5540 int ret;
5541 char prefix_str[BUFSIZ];
5542
5543 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5544
5545 if (! ret)
5546 {
5547 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5548 return CMD_WARNING;
5549 }
5550
5551 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5552 AGGREGATE_SUMMARY_ONLY, 0);
5553}
5554
5555DEFUN (aggregate_address_as_set,
5556 aggregate_address_as_set_cmd,
5557 "aggregate-address A.B.C.D/M as-set",
5558 "Configure BGP aggregate entries\n"
5559 "Aggregate prefix\n"
5560 "Generate AS set path information\n")
5561{
5562 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5563 0, AGGREGATE_AS_SET);
5564}
5565
5566DEFUN (aggregate_address_mask_as_set,
5567 aggregate_address_mask_as_set_cmd,
5568 "aggregate-address A.B.C.D A.B.C.D as-set",
5569 "Configure BGP aggregate entries\n"
5570 "Aggregate address\n"
5571 "Aggregate mask\n"
5572 "Generate AS set path information\n")
5573{
5574 int ret;
5575 char prefix_str[BUFSIZ];
5576
5577 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5578
5579 if (! ret)
5580 {
5581 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5582 return CMD_WARNING;
5583 }
5584
5585 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5586 0, AGGREGATE_AS_SET);
5587}
5588
5589
5590DEFUN (aggregate_address_as_set_summary,
5591 aggregate_address_as_set_summary_cmd,
5592 "aggregate-address A.B.C.D/M as-set summary-only",
5593 "Configure BGP aggregate entries\n"
5594 "Aggregate prefix\n"
5595 "Generate AS set path information\n"
5596 "Filter more specific routes from updates\n")
5597{
5598 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5599 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5600}
5601
5602ALIAS (aggregate_address_as_set_summary,
5603 aggregate_address_summary_as_set_cmd,
5604 "aggregate-address A.B.C.D/M summary-only as-set",
5605 "Configure BGP aggregate entries\n"
5606 "Aggregate prefix\n"
5607 "Filter more specific routes from updates\n"
5608 "Generate AS set path information\n")
5609
5610DEFUN (aggregate_address_mask_as_set_summary,
5611 aggregate_address_mask_as_set_summary_cmd,
5612 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5613 "Configure BGP aggregate entries\n"
5614 "Aggregate address\n"
5615 "Aggregate mask\n"
5616 "Generate AS set path information\n"
5617 "Filter more specific routes from updates\n")
5618{
5619 int ret;
5620 char prefix_str[BUFSIZ];
5621
5622 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5623
5624 if (! ret)
5625 {
5626 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5627 return CMD_WARNING;
5628 }
5629
5630 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5631 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5632}
5633
5634ALIAS (aggregate_address_mask_as_set_summary,
5635 aggregate_address_mask_summary_as_set_cmd,
5636 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5637 "Configure BGP aggregate entries\n"
5638 "Aggregate address\n"
5639 "Aggregate mask\n"
5640 "Filter more specific routes from updates\n"
5641 "Generate AS set path information\n")
5642
5643DEFUN (no_aggregate_address,
5644 no_aggregate_address_cmd,
5645 "no aggregate-address A.B.C.D/M",
5646 NO_STR
5647 "Configure BGP aggregate entries\n"
5648 "Aggregate prefix\n")
5649{
5650 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5651}
5652
5653ALIAS (no_aggregate_address,
5654 no_aggregate_address_summary_only_cmd,
5655 "no aggregate-address A.B.C.D/M summary-only",
5656 NO_STR
5657 "Configure BGP aggregate entries\n"
5658 "Aggregate prefix\n"
5659 "Filter more specific routes from updates\n")
5660
5661ALIAS (no_aggregate_address,
5662 no_aggregate_address_as_set_cmd,
5663 "no aggregate-address A.B.C.D/M as-set",
5664 NO_STR
5665 "Configure BGP aggregate entries\n"
5666 "Aggregate prefix\n"
5667 "Generate AS set path information\n")
5668
5669ALIAS (no_aggregate_address,
5670 no_aggregate_address_as_set_summary_cmd,
5671 "no aggregate-address A.B.C.D/M as-set summary-only",
5672 NO_STR
5673 "Configure BGP aggregate entries\n"
5674 "Aggregate prefix\n"
5675 "Generate AS set path information\n"
5676 "Filter more specific routes from updates\n")
5677
5678ALIAS (no_aggregate_address,
5679 no_aggregate_address_summary_as_set_cmd,
5680 "no aggregate-address A.B.C.D/M summary-only as-set",
5681 NO_STR
5682 "Configure BGP aggregate entries\n"
5683 "Aggregate prefix\n"
5684 "Filter more specific routes from updates\n"
5685 "Generate AS set path information\n")
5686
5687DEFUN (no_aggregate_address_mask,
5688 no_aggregate_address_mask_cmd,
5689 "no aggregate-address A.B.C.D A.B.C.D",
5690 NO_STR
5691 "Configure BGP aggregate entries\n"
5692 "Aggregate address\n"
5693 "Aggregate mask\n")
5694{
5695 int ret;
5696 char prefix_str[BUFSIZ];
5697
5698 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5699
5700 if (! ret)
5701 {
5702 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5703 return CMD_WARNING;
5704 }
5705
5706 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5707}
5708
5709ALIAS (no_aggregate_address_mask,
5710 no_aggregate_address_mask_summary_only_cmd,
5711 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5712 NO_STR
5713 "Configure BGP aggregate entries\n"
5714 "Aggregate address\n"
5715 "Aggregate mask\n"
5716 "Filter more specific routes from updates\n")
5717
5718ALIAS (no_aggregate_address_mask,
5719 no_aggregate_address_mask_as_set_cmd,
5720 "no aggregate-address A.B.C.D A.B.C.D as-set",
5721 NO_STR
5722 "Configure BGP aggregate entries\n"
5723 "Aggregate address\n"
5724 "Aggregate mask\n"
5725 "Generate AS set path information\n")
5726
5727ALIAS (no_aggregate_address_mask,
5728 no_aggregate_address_mask_as_set_summary_cmd,
5729 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5730 NO_STR
5731 "Configure BGP aggregate entries\n"
5732 "Aggregate address\n"
5733 "Aggregate mask\n"
5734 "Generate AS set path information\n"
5735 "Filter more specific routes from updates\n")
5736
5737ALIAS (no_aggregate_address_mask,
5738 no_aggregate_address_mask_summary_as_set_cmd,
5739 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5740 NO_STR
5741 "Configure BGP aggregate entries\n"
5742 "Aggregate address\n"
5743 "Aggregate mask\n"
5744 "Filter more specific routes from updates\n"
5745 "Generate AS set path information\n")
5746
5747#ifdef HAVE_IPV6
5748DEFUN (ipv6_aggregate_address,
5749 ipv6_aggregate_address_cmd,
5750 "aggregate-address X:X::X:X/M",
5751 "Configure BGP aggregate entries\n"
5752 "Aggregate prefix\n")
5753{
5754 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5755}
5756
5757DEFUN (ipv6_aggregate_address_summary_only,
5758 ipv6_aggregate_address_summary_only_cmd,
5759 "aggregate-address X:X::X:X/M summary-only",
5760 "Configure BGP aggregate entries\n"
5761 "Aggregate prefix\n"
5762 "Filter more specific routes from updates\n")
5763{
5764 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5765 AGGREGATE_SUMMARY_ONLY, 0);
5766}
5767
5768DEFUN (no_ipv6_aggregate_address,
5769 no_ipv6_aggregate_address_cmd,
5770 "no aggregate-address X:X::X:X/M",
5771 NO_STR
5772 "Configure BGP aggregate entries\n"
5773 "Aggregate prefix\n")
5774{
5775 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5776}
5777
5778DEFUN (no_ipv6_aggregate_address_summary_only,
5779 no_ipv6_aggregate_address_summary_only_cmd,
5780 "no aggregate-address X:X::X:X/M summary-only",
5781 NO_STR
5782 "Configure BGP aggregate entries\n"
5783 "Aggregate prefix\n"
5784 "Filter more specific routes from updates\n")
5785{
5786 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5787}
5788
5789ALIAS (ipv6_aggregate_address,
5790 old_ipv6_aggregate_address_cmd,
5791 "ipv6 bgp aggregate-address X:X::X:X/M",
5792 IPV6_STR
5793 BGP_STR
5794 "Configure BGP aggregate entries\n"
5795 "Aggregate prefix\n")
5796
5797ALIAS (ipv6_aggregate_address_summary_only,
5798 old_ipv6_aggregate_address_summary_only_cmd,
5799 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5800 IPV6_STR
5801 BGP_STR
5802 "Configure BGP aggregate entries\n"
5803 "Aggregate prefix\n"
5804 "Filter more specific routes from updates\n")
5805
5806ALIAS (no_ipv6_aggregate_address,
5807 old_no_ipv6_aggregate_address_cmd,
5808 "no ipv6 bgp aggregate-address X:X::X:X/M",
5809 NO_STR
5810 IPV6_STR
5811 BGP_STR
5812 "Configure BGP aggregate entries\n"
5813 "Aggregate prefix\n")
5814
5815ALIAS (no_ipv6_aggregate_address_summary_only,
5816 old_no_ipv6_aggregate_address_summary_only_cmd,
5817 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5818 NO_STR
5819 IPV6_STR
5820 BGP_STR
5821 "Configure BGP aggregate entries\n"
5822 "Aggregate prefix\n"
5823 "Filter more specific routes from updates\n")
5824#endif /* HAVE_IPV6 */
6b0655a2 5825
718e3744 5826/* Redistribute route treatment. */
5827void
6aeb9e78 5828bgp_redistribute_add (struct bgp *bgp, struct prefix *p, const struct in_addr *nexthop,
bc413143 5829 const struct in6_addr *nexthop6, unsigned int ifindex,
dc9ffce8 5830 u_int32_t metric, u_char type, u_short instance, route_tag_t tag)
718e3744 5831{
718e3744 5832 struct bgp_info *new;
5833 struct bgp_info *bi;
5834 struct bgp_info info;
5835 struct bgp_node *bn;
e16a4133 5836 struct attr attr;
718e3744 5837 struct attr *new_attr;
5838 afi_t afi;
5839 int ret;
7c8ff89e 5840 struct bgp_redist *red;
718e3744 5841
5842 /* Make default attribute. */
5843 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5844 if (nexthop)
5845 attr.nexthop = *nexthop;
bc413143 5846 attr.nh_ifindex = ifindex;
718e3744 5847
f04a80a5
SH
5848#ifdef HAVE_IPV6
5849 if (nexthop6)
5850 {
5851 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5852 extra->mp_nexthop_global = *nexthop6;
801a9bcc 5853 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
f04a80a5
SH
5854 }
5855#endif
5856
718e3744 5857 attr.med = metric;
5858 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
0d9551dc 5859 attr.extra->tag = tag;
718e3744 5860
6aeb9e78
DS
5861 afi = family2afi (p->family);
5862
5863 red = bgp_redist_lookup(bgp, afi, type, instance);
5864 if (red)
718e3744 5865 {
6aeb9e78
DS
5866 struct attr attr_new;
5867 struct attr_extra extra_new;
718e3744 5868
6aeb9e78
DS
5869 /* Copy attribute for modification. */
5870 attr_new.extra = &extra_new;
5871 bgp_attr_dup (&attr_new, &attr);
558d1fec 5872
6aeb9e78
DS
5873 if (red->redist_metric_flag)
5874 attr_new.med = red->redist_metric;
718e3744 5875
6aeb9e78
DS
5876 /* Apply route-map. */
5877 if (red->rmap.name)
5878 {
5879 info.peer = bgp->peer_self;
5880 info.attr = &attr_new;
718e3744 5881
6aeb9e78 5882 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
718e3744 5883
6aeb9e78 5884 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
fee0f4c6 5885
6aeb9e78 5886 bgp->peer_self->rmap_type = 0;
fee0f4c6 5887
6aeb9e78
DS
5888 if (ret == RMAP_DENYMATCH)
5889 {
5890 /* Free uninterned attribute. */
5891 bgp_attr_flush (&attr_new);
5892
5893 /* Unintern original. */
5894 aspath_unintern (&attr.aspath);
5895 bgp_attr_extra_free (&attr);
5896 bgp_redistribute_delete (bgp, p, type, instance);
5897 return;
5898 }
5899 }
fee0f4c6 5900
6aeb9e78
DS
5901 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5902 afi, SAFI_UNICAST, p, NULL);
718e3744 5903
6aeb9e78 5904 new_attr = bgp_attr_intern (&attr_new);
558d1fec 5905
6aeb9e78
DS
5906 for (bi = bn->info; bi; bi = bi->next)
5907 if (bi->peer == bgp->peer_self
5908 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5909 break;
5910
5911 if (bi)
5912 {
5913 /* Ensure the (source route) type is updated. */
5914 bi->type = type;
5915 if (attrhash_cmp (bi->attr, new_attr) &&
5916 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5917 {
5918 bgp_attr_unintern (&new_attr);
5919 aspath_unintern (&attr.aspath);
5920 bgp_attr_extra_free (&attr);
5921 bgp_unlock_node (bn);
5922 return;
5923 }
5924 else
5925 {
5926 /* The attribute is changed. */
5927 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
718e3744 5928
6aeb9e78
DS
5929 /* Rewrite BGP route information. */
5930 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5931 bgp_info_restore(bn, bi);
5932 else
5933 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5934 bgp_attr_unintern (&bi->attr);
5935 bi->attr = new_attr;
5936 bi->uptime = bgp_clock ();
5937
5938 /* Process change. */
5939 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5940 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5941 bgp_unlock_node (bn);
5942 aspath_unintern (&attr.aspath);
5943 bgp_attr_extra_free (&attr);
5944 return;
5945 }
5946 }
718e3744 5947
6aeb9e78
DS
5948 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
5949 new_attr, bn);
5950 SET_FLAG (new->flags, BGP_INFO_VALID);
5951
5952 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5953 bgp_info_add (bn, new);
5954 bgp_unlock_node (bn);
5955 bgp_process (bgp, bn, afi, SAFI_UNICAST);
718e3744 5956 }
5957
5958 /* Unintern original. */
f6f434b2 5959 aspath_unintern (&attr.aspath);
fb982c25 5960 bgp_attr_extra_free (&attr);
718e3744 5961}
5962
5963void
6aeb9e78 5964bgp_redistribute_delete (struct bgp *bgp, struct prefix *p, u_char type, u_short instance)
718e3744 5965{
718e3744 5966 afi_t afi;
5967 struct bgp_node *rn;
5968 struct bgp_info *ri;
7c8ff89e 5969 struct bgp_redist *red;
718e3744 5970
6aeb9e78 5971 afi = family2afi (p->family);
718e3744 5972
6aeb9e78
DS
5973 red = bgp_redist_lookup(bgp, afi, type, instance);
5974 if (red)
5975 {
5976 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
718e3744 5977
6aeb9e78
DS
5978 for (ri = rn->info; ri; ri = ri->next)
5979 if (ri->peer == bgp->peer_self
5980 && ri->type == type)
5981 break;
718e3744 5982
6aeb9e78
DS
5983 if (ri)
5984 {
5985 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5986 bgp_info_delete (rn, ri);
5987 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5988 }
5989 bgp_unlock_node (rn);
718e3744 5990 }
5991}
5992
5993/* Withdraw specified route type's route. */
5994void
7c8ff89e 5995bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
718e3744 5996{
5997 struct bgp_node *rn;
5998 struct bgp_info *ri;
5999 struct bgp_table *table;
6000
6001 table = bgp->rib[afi][SAFI_UNICAST];
6002
6003 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6004 {
6005 for (ri = rn->info; ri; ri = ri->next)
6006 if (ri->peer == bgp->peer_self
7c8ff89e
DS
6007 && ri->type == type
6008 && ri->instance == instance)
718e3744 6009 break;
6010
6011 if (ri)
6012 {
6013 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
718e3744 6014 bgp_info_delete (rn, ri);
1a392d46 6015 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 6016 }
6017 }
6018}
6b0655a2 6019
718e3744 6020/* Static function to display route. */
94f2b392 6021static void
718e3744 6022route_vty_out_route (struct prefix *p, struct vty *vty)
6023{
6024 int len;
6025 u_int32_t destination;
6026 char buf[BUFSIZ];
6027
6028 if (p->family == AF_INET)
6029 {
6030 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
6031 destination = ntohl (p->u.prefix4.s_addr);
6032
6033 if ((IN_CLASSC (destination) && p->prefixlen == 24)
856ca177
MS
6034 || (IN_CLASSB (destination) && p->prefixlen == 16)
6035 || (IN_CLASSA (destination) && p->prefixlen == 8)
6036 || p->u.prefix4.s_addr == 0)
6037 {
6038 /* When mask is natural, mask is not displayed. */
6039 }
718e3744 6040 else
856ca177 6041 len += vty_out (vty, "/%d", p->prefixlen);
718e3744 6042 }
6043 else
6044 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
6045 p->prefixlen);
6046
6047 len = 17 - len;
6048 if (len < 1)
6049 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
6050 else
6051 vty_out (vty, "%*s", len, " ");
6052}
6053
718e3744 6054enum bgp_display_type
6055{
6056 normal_list,
6057};
6058
b40d939b 6059/* Print the short form route status for a bgp_info */
6060static void
b05a1c8b
DS
6061route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
6062 json_object *json_path)
718e3744 6063{
b05a1c8b
DS
6064 if (json_path)
6065 {
b05a1c8b
DS
6066
6067 /* Route status display. */
6068 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
f1aa5d8a 6069 json_object_boolean_true_add(json_path, "removed");
b05a1c8b
DS
6070
6071 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
f1aa5d8a 6072 json_object_boolean_true_add(json_path, "stale");
b05a1c8b
DS
6073
6074 if (binfo->extra && binfo->extra->suppress)
f1aa5d8a 6075 json_object_boolean_true_add(json_path, "suppressed");
b05a1c8b
DS
6076
6077 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6078 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
f1aa5d8a 6079 json_object_boolean_true_add(json_path, "valid");
b05a1c8b
DS
6080
6081 /* Selected */
6082 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
f1aa5d8a 6083 json_object_boolean_true_add(json_path, "history");
b05a1c8b
DS
6084
6085 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
f1aa5d8a 6086 json_object_boolean_true_add(json_path, "damped");
b05a1c8b
DS
6087
6088 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
f1aa5d8a 6089 json_object_boolean_true_add(json_path, "bestpath");
b05a1c8b
DS
6090
6091 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
f1aa5d8a 6092 json_object_boolean_true_add(json_path, "multipath");
b05a1c8b
DS
6093
6094 /* Internal route. */
6095 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
62d6dca0 6096 json_object_string_add(json_path, "pathFrom", "internal");
b05a1c8b 6097 else
62d6dca0 6098 json_object_string_add(json_path, "pathFrom", "external");
b05a1c8b
DS
6099
6100 return;
6101 }
6102
b40d939b 6103 /* Route status display. */
6104 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6105 vty_out (vty, "R");
6106 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
93406d87 6107 vty_out (vty, "S");
fb982c25 6108 else if (binfo->extra && binfo->extra->suppress)
718e3744 6109 vty_out (vty, "s");
31eba040
DS
6110 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6111 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
718e3744 6112 vty_out (vty, "*");
6113 else
6114 vty_out (vty, " ");
6115
6116 /* Selected */
6117 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6118 vty_out (vty, "h");
6119 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6120 vty_out (vty, "d");
6121 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6122 vty_out (vty, ">");
b366b518
BB
6123 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6124 vty_out (vty, "=");
718e3744 6125 else
6126 vty_out (vty, " ");
6127
6128 /* Internal route. */
b05a1c8b
DS
6129 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6130 vty_out (vty, "i");
6131 else
6132 vty_out (vty, " ");
b40d939b 6133}
6134
6135/* called from terminal list command */
6136void
6137route_vty_out (struct vty *vty, struct prefix *p,
b05a1c8b
DS
6138 struct bgp_info *binfo, int display, safi_t safi,
6139 json_object *json_paths)
b40d939b 6140{
6141 struct attr *attr;
f1aa5d8a
DS
6142 json_object *json_path = NULL;
6143 json_object *json_nexthops = NULL;
6144 json_object *json_nexthop_global = NULL;
6145 json_object *json_nexthop_ll = NULL;
47fc97cc 6146
b05a1c8b
DS
6147 if (json_paths)
6148 json_path = json_object_new_object();
b05a1c8b
DS
6149
6150 /* short status lead text */
6151 route_vty_short_status_out (vty, binfo, json_path);
718e3744 6152
b05a1c8b
DS
6153 if (!json_paths)
6154 {
6155 /* print prefix and mask */
6156 if (! display)
6157 route_vty_out_route (p, vty);
6158 else
6159 vty_out (vty, "%*s", 17, " ");
6160 }
47fc97cc 6161
718e3744 6162 /* Print attribute */
6163 attr = binfo->attr;
6164 if (attr)
6165 {
587ff0fd
LB
6166 /*
6167 * For ENCAP routes, nexthop address family is not
6168 * neccessarily the same as the prefix address family.
6169 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
6170 */
6171 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN))
6172 {
6173 if (attr->extra)
6174 {
6175 char buf[BUFSIZ];
6176 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
b05a1c8b 6177
587ff0fd
LB
6178 switch (af)
6179 {
6180 case AF_INET:
6181 vty_out (vty, "%s", inet_ntop(af,
6182 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
6183 break;
6184#if HAVE_IPV6
6185 case AF_INET6:
6186 vty_out (vty, "%s", inet_ntop(af,
6187 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
6188 break;
6189#endif
6190 default:
6191 vty_out(vty, "?");
6192 break;
6193 }
6194 }
6195 else
6196 vty_out(vty, "?");
6197 }
b05a1c8b 6198 /* IPv4 Next Hop */
f81e127e 6199 else if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
718e3744 6200 {
b05a1c8b
DS
6201 if (json_paths)
6202 {
f1aa5d8a
DS
6203 json_nexthop_global = json_object_new_object();
6204
b05a1c8b 6205 if (safi == SAFI_MPLS_VPN)
f1aa5d8a 6206 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
b05a1c8b 6207 else
f1aa5d8a
DS
6208 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6209
6210 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6211 json_object_boolean_true_add(json_nexthop_global, "used");
b05a1c8b
DS
6212 }
6213 else
6214 {
6215 if (safi == SAFI_MPLS_VPN)
6216 vty_out (vty, "%-16s",
6217 inet_ntoa (attr->extra->mp_nexthop_global_in));
6218 else
6219 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6220 }
718e3744 6221 }
161995ea 6222
b05a1c8b 6223 /* IPv6 Next Hop */
8a92a8a0 6224 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
718e3744 6225 {
6226 int len;
6227 char buf[BUFSIZ];
6228
b05a1c8b
DS
6229 if (json_paths)
6230 {
f1aa5d8a
DS
6231 json_nexthop_global = json_object_new_object();
6232 json_object_string_add(json_nexthop_global, "ip",
6233 inet_ntop (AF_INET6,
6234 &attr->extra->mp_nexthop_global,
6235 buf, BUFSIZ));
6236 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6237 json_object_string_add(json_nexthop_global, "scope", "global");
6238
6239 /* We display both LL & GL if both have been received */
6240 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
6241 {
6242 json_nexthop_ll = json_object_new_object();
6243 json_object_string_add(json_nexthop_ll, "ip",
6244 inet_ntop (AF_INET6,
6245 &attr->extra->mp_nexthop_local,
6246 buf, BUFSIZ));
6247 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
6248 json_object_string_add(json_nexthop_ll, "scope", "link-local");
6249
161995ea
DS
6250 if ((IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global,
6251 &attr->extra->mp_nexthop_local) != 0) &&
6252 !attr->extra->mp_nexthop_prefer_global)
f1aa5d8a
DS
6253 json_object_boolean_true_add(json_nexthop_ll, "used");
6254 else
6255 json_object_boolean_true_add(json_nexthop_global, "used");
6256 }
6257 else
6258 json_object_boolean_true_add(json_nexthop_global, "used");
b05a1c8b
DS
6259 }
6260 else
6261 {
161995ea
DS
6262 /* Display LL if LL/Global both in table unless prefer-global is set */
6263 if (((attr->extra->mp_nexthop_len == 32) &&
6264 !attr->extra->mp_nexthop_prefer_global) ||
6265 (binfo->peer->conf_if))
433e8b67
DS
6266 {
6267 if (binfo->peer->conf_if)
6268 {
6269 len = vty_out (vty, "%s",
6270 binfo->peer->conf_if);
6271 len = 7 - len; /* len of IPv6 addr + max len of def ifname */
6272
6273 if (len < 1)
6274 vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " ");
6275 else
6276 vty_out (vty, "%*s", len, " ");
6277 }
6278 else
6279 {
6280 len = vty_out (vty, "%s",
6281 inet_ntop (AF_INET6,
6282 &attr->extra->mp_nexthop_local,
6283 buf, BUFSIZ));
6284 len = 16 - len;
6285
6286 if (len < 1)
6287 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6288 else
6289 vty_out (vty, "%*s", len, " ");
6290 }
6291 }
6292 else
6293 {
6294 len = vty_out (vty, "%s",
6295 inet_ntop (AF_INET6,
6296 &attr->extra->mp_nexthop_global,
6297 buf, BUFSIZ));
6298 len = 16 - len;
6299
6300 if (len < 1)
6301 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6302 else
6303 vty_out (vty, "%*s", len, " ");
6304 }
b05a1c8b 6305 }
718e3744 6306 }
718e3744 6307
b05a1c8b 6308 /* MED/Metric */
718e3744 6309 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b 6310 if (json_paths)
f1aa5d8a 6311 json_object_int_add(json_path, "med", attr->med);
b05a1c8b 6312 else
fa86975d 6313 vty_out (vty, "%10u", attr->med);
718e3744 6314 else
b05a1c8b
DS
6315 if (!json_paths)
6316 vty_out (vty, " ");
47fc97cc 6317
b05a1c8b 6318 /* Local Pref */
718e3744 6319 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
b05a1c8b 6320 if (json_paths)
f1aa5d8a 6321 json_object_int_add(json_path, "localpref", attr->local_pref);
b05a1c8b 6322 else
fa86975d 6323 vty_out (vty, "%7u", attr->local_pref);
718e3744 6324 else
b05a1c8b
DS
6325 if (!json_paths)
6326 vty_out (vty, " ");
718e3744 6327
b05a1c8b
DS
6328 if (json_paths)
6329 {
6330 if (attr->extra)
f1aa5d8a 6331 json_object_int_add(json_path, "weight", attr->extra->weight);
b05a1c8b 6332 else
f1aa5d8a 6333 json_object_int_add(json_path, "weight", 0);
b05a1c8b
DS
6334 }
6335 else
6336 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
47fc97cc 6337
39e871e6
ST
6338 if (json_paths) {
6339 char buf[BUFSIZ];
6340 json_object_string_add(json_path, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6341 }
6342
b2518c1e
PJ
6343 /* Print aspath */
6344 if (attr->aspath)
b05a1c8b
DS
6345 {
6346 if (json_paths)
f1aa5d8a 6347 json_object_string_add(json_path, "aspath", attr->aspath->str);
b05a1c8b 6348 else
f1aa5d8a 6349 aspath_print_vty (vty, "%s", attr->aspath, " ");
b05a1c8b 6350 }
47fc97cc 6351
b2518c1e 6352 /* Print origin */
b05a1c8b 6353 if (json_paths)
f1aa5d8a 6354 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
b05a1c8b
DS
6355 else
6356 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 6357 }
856ca177
MS
6358 else
6359 {
6360 if (json_paths)
6361 json_object_string_add(json_path, "alert", "No attributes");
6362 else
6363 vty_out (vty, "No attributes to print%s", VTY_NEWLINE);
6364 }
b05a1c8b
DS
6365
6366 if (json_paths)
f1aa5d8a
DS
6367 {
6368 if (json_nexthop_global || json_nexthop_ll)
6369 {
6370 json_nexthops = json_object_new_array();
6371
6372 if (json_nexthop_global)
6373 json_object_array_add(json_nexthops, json_nexthop_global);
6374
6375 if (json_nexthop_ll)
6376 json_object_array_add(json_nexthops, json_nexthop_ll);
6377
6378 json_object_object_add(json_path, "nexthops", json_nexthops);
6379 }
6380
6381 json_object_array_add(json_paths, json_path);
6382 }
b05a1c8b 6383 else
65efcfce
LB
6384 {
6385 vty_out (vty, "%s", VTY_NEWLINE);
6386#if ENABLE_BGP_VNC
6387 /* prints an additional line, indented, with VNC info, if present */
61263032 6388 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
65efcfce
LB
6389 rfapi_vty_out_vncinfo(vty, p, binfo, safi);
6390#endif
6391 }
718e3744 6392}
6393
6394/* called from terminal list command */
6395void
856ca177
MS
6396route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi,
6397 u_char use_json, json_object *json_ar)
718e3744 6398{
856ca177
MS
6399 json_object *json_status = NULL;
6400 json_object *json_net = NULL;
6401 char buff[BUFSIZ];
718e3744 6402 /* Route status display. */
856ca177
MS
6403 if (use_json)
6404 {
6405 json_status = json_object_new_object();
6406 json_net = json_object_new_object();
6407 }
6408 else
6409 {
6410 vty_out (vty, "*");
6411 vty_out (vty, ">");
6412 vty_out (vty, " ");
6413 }
718e3744 6414
6415 /* print prefix and mask */
856ca177
MS
6416 if (use_json)
6417 json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ));
6418 else
6419 route_vty_out_route (p, vty);
718e3744 6420
6421 /* Print attribute */
6422 if (attr)
6423 {
856ca177 6424 if (use_json)
718e3744 6425 {
587ff0fd
LB
6426 if (p->family == AF_INET &&
6427 (safi == SAFI_MPLS_VPN ||
6428 safi == SAFI_ENCAP ||
6429 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
856ca177 6430 {
587ff0fd 6431 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
856ca177
MS
6432 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in));
6433 else
6434 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop));
6435 }
6436#ifdef HAVE_IPV6
6437 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6438 {
6439 char buf[BUFSIZ];
718e3744 6440
856ca177
MS
6441 json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6442 buf, BUFSIZ));
6443 }
6444#endif /* HAVE_IPV6 */
6445
6446 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6447 json_object_int_add(json_net, "metric", attr->med);
6448
6449 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6450 json_object_int_add(json_net, "localPref", attr->local_pref);
6451
6452 if (attr->extra)
6453 json_object_int_add(json_net, "weight", attr->extra->weight);
718e3744 6454 else
856ca177
MS
6455 json_object_int_add(json_net, "weight", 0);
6456
6457 /* Print aspath */
6458 if (attr->aspath)
6459 json_object_string_add(json_net, "asPath", attr->aspath->str);
6460
6461 /* Print origin */
6462 json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]);
718e3744 6463 }
856ca177
MS
6464 else
6465 {
587ff0fd
LB
6466 if (p->family == AF_INET &&
6467 (safi == SAFI_MPLS_VPN ||
6468 safi == SAFI_ENCAP ||
6469 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
856ca177 6470 {
912e5234
LB
6471 if (attr->extra &&
6472 (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP))
856ca177
MS
6473 vty_out (vty, "%-16s",
6474 inet_ntoa (attr->extra->mp_nexthop_global_in));
6475 else
6476 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6477 }
6478#ifdef HAVE_IPV6
6479 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6480 {
6481 int len;
6482 char buf[BUFSIZ];
912e5234
LB
6483 if (attr->extra)
6484 {
6485 len = vty_out (vty, "%s",
6486 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6487 buf, BUFSIZ));
6488 len = 16 - len;
6489 }
6490 else
6491 len = 0;
856ca177
MS
6492 if (len < 1)
6493 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6494 else
6495 vty_out (vty, "%*s", len, " ");
6496 }
718e3744 6497#endif /* HAVE_IPV6 */
856ca177 6498 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
fa86975d 6499 vty_out (vty, "%10u", attr->med);
856ca177
MS
6500 else
6501 vty_out (vty, " ");
718e3744 6502
856ca177 6503 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
fa86975d 6504 vty_out (vty, "%7u", attr->local_pref);
856ca177
MS
6505 else
6506 vty_out (vty, " ");
718e3744 6507
856ca177 6508 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
718e3744 6509
856ca177
MS
6510 /* Print aspath */
6511 if (attr->aspath)
6512 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 6513
856ca177
MS
6514 /* Print origin */
6515 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6516 }
6517 }
6518 if (use_json)
6519 {
6520 json_object_boolean_true_add(json_status, "*");
6521 json_object_boolean_true_add(json_status, ">");
6522 json_object_object_add(json_net, "appliedStatusSymbols", json_status);
6523 char buf_cut[BUFSIZ];
6524 json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net);
6525 }
6526 else
6527 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6528}
6529
5a646650 6530void
718e3744 6531route_vty_out_tag (struct vty *vty, struct prefix *p,
856ca177 6532 struct bgp_info *binfo, int display, safi_t safi, json_object *json)
718e3744 6533{
856ca177 6534 json_object *json_out = NULL;
718e3744 6535 struct attr *attr;
718e3744 6536 u_int32_t label = 0;
fb982c25
PJ
6537
6538 if (!binfo->extra)
6539 return;
856ca177
MS
6540
6541 if (json)
6542 json_out = json_object_new_object();
fb982c25 6543
b40d939b 6544 /* short status lead text */
856ca177 6545 route_vty_short_status_out (vty, binfo, json_out);
b40d939b 6546
718e3744 6547 /* print prefix and mask */
856ca177
MS
6548 if (json == NULL)
6549 {
6550 if (! display)
6551 route_vty_out_route (p, vty);
6552 else
6553 vty_out (vty, "%*s", 17, " ");
6554 }
718e3744 6555
6556 /* Print attribute */
6557 attr = binfo->attr;
6558 if (attr)
6559 {
8a92a8a0
DS
6560 if (p->family == AF_INET
6561 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 6562 {
587ff0fd 6563 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
856ca177
MS
6564 {
6565 if (json)
6566 json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in));
6567 else
6568 vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6569 }
718e3744 6570 else
856ca177
MS
6571 {
6572 if (json)
6573 json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop));
6574 else
6575 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6576 }
718e3744 6577 }
6578#ifdef HAVE_IPV6
8a92a8a0 6579 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
718e3744 6580 {
fb982c25 6581 assert (attr->extra);
856ca177
MS
6582 char buf_a[BUFSIZ];
6583 char buf_b[BUFSIZ];
6584 char buf_c[BUFSIZ];
801a9bcc 6585 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
856ca177
MS
6586 {
6587 if (json)
6588 json_object_string_add(json_out, "mpNexthopGlobalIn",
6589 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ));
6590 else
6591 vty_out (vty, "%s",
6592 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6593 buf_a, BUFSIZ));
6594 }
801a9bcc 6595 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
856ca177
MS
6596 {
6597 if (json)
6598 {
6599 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6600 buf_a, BUFSIZ);
6601 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6602 buf_b, BUFSIZ);
6603 sprintf(buf_c, "%s(%s)", buf_a, buf_b);
6604 json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c);
6605 }
6606 else
6607 vty_out (vty, "%s(%s)",
6608 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6609 buf_a, BUFSIZ),
6610 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6611 buf_b, BUFSIZ));
6612 }
6613
718e3744 6614 }
6615#endif /* HAVE_IPV6 */
6616 }
6617
fb982c25 6618 label = decode_label (binfo->extra->tag);
718e3744 6619
856ca177
MS
6620 if (json)
6621 {
6622 if (label)
6623 json_object_int_add(json_out, "notag", label);
6624 json_object_array_add(json, json_out);
6625 }
6626 else
6627 {
6628 vty_out (vty, "notag/%d", label);
6629 vty_out (vty, "%s", VTY_NEWLINE);
6630 }
718e3744 6631}
6632
6633/* dampening route */
5a646650 6634static void
856ca177
MS
6635damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6636 int display, safi_t safi, u_char use_json, json_object *json)
718e3744 6637{
6638 struct attr *attr;
718e3744 6639 int len;
50aef6f3 6640 char timebuf[BGP_UPTIME_LEN];
718e3744 6641
b40d939b 6642 /* short status lead text */
856ca177 6643 route_vty_short_status_out (vty, binfo, json);
b40d939b 6644
718e3744 6645 /* print prefix and mask */
856ca177
MS
6646 if (!use_json)
6647 {
6648 if (! display)
6649 route_vty_out_route (p, vty);
6650 else
6651 vty_out (vty, "%*s", 17, " ");
6652 }
718e3744 6653
6654 len = vty_out (vty, "%s", binfo->peer->host);
6655 len = 17 - len;
6656 if (len < 1)
856ca177
MS
6657 {
6658 if (!use_json)
6659 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6660 }
718e3744 6661 else
856ca177
MS
6662 {
6663 if (use_json)
6664 json_object_int_add(json, "peerHost", len);
6665 else
6666 vty_out (vty, "%*s", len, " ");
6667 }
718e3744 6668
856ca177
MS
6669 if (use_json)
6670 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6671 else
6672 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
718e3744 6673
6674 /* Print attribute */
6675 attr = binfo->attr;
6676 if (attr)
6677 {
6678 /* Print aspath */
6679 if (attr->aspath)
856ca177
MS
6680 {
6681 if (use_json)
6682 json_object_string_add(json, "asPath", attr->aspath->str);
6683 else
6684 aspath_print_vty (vty, "%s", attr->aspath, " ");
6685 }
718e3744 6686
6687 /* Print origin */
856ca177
MS
6688 if (use_json)
6689 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6690 else
6691 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 6692 }
856ca177
MS
6693 if (!use_json)
6694 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6695}
6696
718e3744 6697/* flap route */
5a646650 6698static void
856ca177
MS
6699flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6700 int display, safi_t safi, u_char use_json, json_object *json)
718e3744 6701{
6702 struct attr *attr;
6703 struct bgp_damp_info *bdi;
718e3744 6704 char timebuf[BGP_UPTIME_LEN];
6705 int len;
fb982c25
PJ
6706
6707 if (!binfo->extra)
6708 return;
6709
6710 bdi = binfo->extra->damp_info;
718e3744 6711
b40d939b 6712 /* short status lead text */
856ca177 6713 route_vty_short_status_out (vty, binfo, json);
b40d939b 6714
718e3744 6715 /* print prefix and mask */
856ca177
MS
6716 if (!use_json)
6717 {
6718 if (! display)
6719 route_vty_out_route (p, vty);
6720 else
6721 vty_out (vty, "%*s", 17, " ");
6722 }
718e3744 6723
6724 len = vty_out (vty, "%s", binfo->peer->host);
6725 len = 16 - len;
6726 if (len < 1)
856ca177
MS
6727 {
6728 if (!use_json)
6729 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6730 }
718e3744 6731 else
856ca177
MS
6732 {
6733 if (use_json)
6734 json_object_int_add(json, "peerHost", len);
6735 else
6736 vty_out (vty, "%*s", len, " ");
6737 }
718e3744 6738
6739 len = vty_out (vty, "%d", bdi->flap);
6740 len = 5 - len;
6741 if (len < 1)
856ca177
MS
6742 {
6743 if (!use_json)
6744 vty_out (vty, " ");
6745 }
718e3744 6746 else
856ca177
MS
6747 {
6748 if (use_json)
6749 json_object_int_add(json, "bdiFlap", len);
6750 else
6751 vty_out (vty, "%*s", len, " ");
6752 }
6753
6754 if (use_json)
6755 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json);
6756 else
6757 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6758 timebuf, BGP_UPTIME_LEN, 0, NULL));
718e3744 6759
6760 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6761 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
856ca177
MS
6762 {
6763 if (use_json)
6764 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6765 else
6766 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6767 }
718e3744 6768 else
856ca177
MS
6769 {
6770 if (!use_json)
6771 vty_out (vty, "%*s ", 8, " ");
6772 }
718e3744 6773
6774 /* Print attribute */
6775 attr = binfo->attr;
6776 if (attr)
6777 {
6778 /* Print aspath */
6779 if (attr->aspath)
856ca177
MS
6780 {
6781 if (use_json)
6782 json_object_string_add(json, "asPath", attr->aspath->str);
6783 else
6784 aspath_print_vty (vty, "%s", attr->aspath, " ");
6785 }
718e3744 6786
6787 /* Print origin */
856ca177
MS
6788 if (use_json)
6789 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6790 else
6791 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 6792 }
856ca177
MS
6793 if (!use_json)
6794 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6795}
6796
adbac85e
DW
6797static void
6798route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first,
6799 const char *header, json_object *json_adv_to)
6800{
6801 char buf1[INET6_ADDRSTRLEN];
6802 json_object *json_peer = NULL;
6803
6804 if (json_adv_to)
6805 {
6806 /* 'advertised-to' is a dictionary of peers we have advertised this
6807 * prefix too. The key is the peer's IP or swpX, the value is the
6808 * hostname if we know it and "" if not.
6809 */
6810 json_peer = json_object_new_object();
6811
6812 if (peer->hostname)
6813 json_object_string_add(json_peer, "hostname", peer->hostname);
6814
6815 if (peer->conf_if)
6816 json_object_object_add(json_adv_to, peer->conf_if, json_peer);
6817 else
6818 json_object_object_add(json_adv_to,
6819 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN),
6820 json_peer);
6821 }
6822 else
6823 {
6824 if (*first)
6825 {
6826 vty_out (vty, "%s", header);
6827 *first = 0;
6828 }
6829
6830 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6831 {
6832 if (peer->conf_if)
6833 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
6834 else
6835 vty_out (vty, " %s(%s)", peer->hostname,
6836 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6837 }
6838 else
6839 {
6840 if (peer->conf_if)
6841 vty_out (vty, " %s", peer->conf_if);
6842 else
6843 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6844 }
6845 }
6846}
6847
94f2b392 6848static void
718e3744 6849route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
b05a1c8b
DS
6850 struct bgp_info *binfo, afi_t afi, safi_t safi,
6851 json_object *json_paths)
718e3744 6852{
6853 char buf[INET6_ADDRSTRLEN];
6854 char buf1[BUFSIZ];
6855 struct attr *attr;
6856 int sockunion_vty_out (struct vty *, union sockunion *);
30b00176
JK
6857#ifdef HAVE_CLOCK_MONOTONIC
6858 time_t tbuf;
6859#endif
f1aa5d8a 6860 json_object *json_bestpath = NULL;
ffd0c037 6861 json_object *json_cluster_list = NULL;
f1aa5d8a
DS
6862 json_object *json_cluster_list_list = NULL;
6863 json_object *json_ext_community = NULL;
6864 json_object *json_last_update = NULL;
6865 json_object *json_nexthop_global = NULL;
6866 json_object *json_nexthop_ll = NULL;
6867 json_object *json_nexthops = NULL;
6868 json_object *json_path = NULL;
6869 json_object *json_peer = NULL;
6870 json_object *json_string = NULL;
adbac85e
DW
6871 json_object *json_adv_to = NULL;
6872 int first = 0;
6873 struct listnode *node, *nnode;
6874 struct peer *peer;
6875 int addpath_capable;
6876 int has_adj;
aac9ef6c 6877 unsigned int first_as;
b05a1c8b
DS
6878
6879 if (json_paths)
6880 {
6881 json_path = json_object_new_object();
f1aa5d8a
DS
6882 json_peer = json_object_new_object();
6883 json_nexthop_global = json_object_new_object();
b05a1c8b
DS
6884 }
6885
718e3744 6886 attr = binfo->attr;
6887
6888 if (attr)
6889 {
6890 /* Line1 display AS-path, Aggregator */
6891 if (attr->aspath)
6892 {
f1aa5d8a
DS
6893 if (json_paths)
6894 {
6895 json_object_lock(attr->aspath->json);
6896 json_object_object_add(json_path, "aspath", attr->aspath->json);
6897 }
6898 else
b05a1c8b 6899 {
f1aa5d8a
DS
6900 if (attr->aspath->segments)
6901 aspath_print_vty (vty, " %s", attr->aspath, "");
b05a1c8b 6902 else
f1aa5d8a 6903 vty_out (vty, " Local");
b05a1c8b 6904 }
718e3744 6905 }
6906
b40d939b 6907 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
b05a1c8b
DS
6908 {
6909 if (json_paths)
f1aa5d8a 6910 json_object_boolean_true_add(json_path, "removed");
b05a1c8b
DS
6911 else
6912 vty_out (vty, ", (removed)");
6913 }
6914
93406d87 6915 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
b05a1c8b
DS
6916 {
6917 if (json_paths)
f1aa5d8a 6918 json_object_boolean_true_add(json_path, "stale");
b05a1c8b
DS
6919 else
6920 vty_out (vty, ", (stale)");
6921 }
6922
93406d87 6923 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
b05a1c8b
DS
6924 {
6925 if (json_paths)
6926 {
62d6dca0
DS
6927 json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as);
6928 json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr));
b05a1c8b
DS
6929 }
6930 else
6931 {
6932 vty_out (vty, ", (aggregated by %u %s)",
6933 attr->extra->aggregator_as,
6934 inet_ntoa (attr->extra->aggregator_addr));
6935 }
6936 }
6937
93406d87 6938 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
b05a1c8b
DS
6939 {
6940 if (json_paths)
62d6dca0 6941 json_object_boolean_true_add(json_path, "rxedFromRrClient");
b05a1c8b
DS
6942 else
6943 vty_out (vty, ", (Received from a RR-client)");
6944 }
6945
93406d87 6946 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
b05a1c8b
DS
6947 {
6948 if (json_paths)
62d6dca0 6949 json_object_boolean_true_add(json_path, "rxedFromRsClient");
b05a1c8b
DS
6950 else
6951 vty_out (vty, ", (Received from a RS-client)");
6952 }
6953
93406d87 6954 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
6955 {
6956 if (json_paths)
62d6dca0 6957 json_object_boolean_true_add(json_path, "dampeningHistoryEntry");
b05a1c8b
DS
6958 else
6959 vty_out (vty, ", (history entry)");
6960 }
93406d87 6961 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
b05a1c8b
DS
6962 {
6963 if (json_paths)
62d6dca0 6964 json_object_boolean_true_add(json_path, "dampeningSuppressed");
b05a1c8b
DS
6965 else
6966 vty_out (vty, ", (suppressed due to dampening)");
6967 }
6968
6969 if (!json_paths)
6970 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6971
6972 /* Line2 display Next-hop, Neighbor, Router-id */
f1aa5d8a 6973 /* Display the nexthop */
587ff0fd
LB
6974 if (p->family == AF_INET &&
6975 (safi == SAFI_MPLS_VPN ||
6976 safi == SAFI_ENCAP ||
6977 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 6978 {
587ff0fd 6979 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
b05a1c8b
DS
6980 {
6981 if (json_paths)
f1aa5d8a 6982 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
b05a1c8b
DS
6983 else
6984 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6985 }
6986 else
6987 {
6988 if (json_paths)
f1aa5d8a 6989 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
b05a1c8b
DS
6990 else
6991 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
6992 }
6993
6994 if (json_paths)
f1aa5d8a 6995 json_object_string_add(json_nexthop_global, "afi", "ipv4");
718e3744 6996 }
718e3744 6997 else
6998 {
fb982c25 6999 assert (attr->extra);
b05a1c8b
DS
7000 if (json_paths)
7001 {
f1aa5d8a
DS
7002 json_object_string_add(json_nexthop_global, "ip",
7003 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7004 buf, INET6_ADDRSTRLEN));
7005 json_object_string_add(json_nexthop_global, "afi", "ipv6");
7006 json_object_string_add(json_nexthop_global, "scope", "global");
b05a1c8b
DS
7007 }
7008 else
7009 {
7010 vty_out (vty, " %s",
7011 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7012 buf, INET6_ADDRSTRLEN));
7013 }
718e3744 7014 }
b05a1c8b 7015
f1aa5d8a
DS
7016 /* Display the IGP cost or 'inaccessible' */
7017 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
7018 {
7019 if (json_paths)
7020 json_object_boolean_false_add(json_nexthop_global, "accessible");
7021 else
7022 vty_out (vty, " (inaccessible)");
7023 }
7024 else
7025 {
7026 if (binfo->extra && binfo->extra->igpmetric)
b05a1c8b
DS
7027 {
7028 if (json_paths)
f1aa5d8a 7029 json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric);
b05a1c8b 7030 else
f1aa5d8a 7031 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
b05a1c8b 7032 }
f1aa5d8a
DS
7033
7034 /* IGP cost is 0, display this only for json */
b05a1c8b
DS
7035 else
7036 {
7037 if (json_paths)
f1aa5d8a 7038 json_object_int_add(json_nexthop_global, "metric", 0);
b05a1c8b
DS
7039 }
7040
7041 if (json_paths)
f1aa5d8a
DS
7042 json_object_boolean_true_add(json_nexthop_global, "accessible");
7043 }
7044
7045 /* Display peer "from" output */
7046 /* This path was originated locally */
7047 if (binfo->peer == bgp->peer_self)
718e3744 7048 {
f1aa5d8a
DS
7049
7050 if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
b05a1c8b
DS
7051 {
7052 if (json_paths)
62d6dca0 7053 json_object_string_add(json_peer, "peerId", "0.0.0.0");
b05a1c8b 7054 else
f1aa5d8a 7055 vty_out (vty, " from 0.0.0.0 ");
b05a1c8b 7056 }
f1aa5d8a 7057 else
b05a1c8b
DS
7058 {
7059 if (json_paths)
62d6dca0 7060 json_object_string_add(json_peer, "peerId", "::");
b05a1c8b 7061 else
f1aa5d8a 7062 vty_out (vty, " from :: ");
b05a1c8b
DS
7063 }
7064
f1aa5d8a 7065 if (json_paths)
62d6dca0 7066 json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id));
b05a1c8b 7067 else
f1aa5d8a
DS
7068 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
7069 }
7070
7071 /* We RXed this path from one of our peers */
7072 else
7073 {
b05a1c8b
DS
7074
7075 if (json_paths)
7076 {
62d6dca0
DS
7077 json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7078 json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
f1aa5d8a 7079
04b6bdc0
DW
7080 if (binfo->peer->hostname)
7081 json_object_string_add(json_peer, "hostname", binfo->peer->hostname);
7082
7083 if (binfo->peer->domainname)
7084 json_object_string_add(json_peer, "domainname", binfo->peer->domainname);
7085
036a4e7d 7086 if (binfo->peer->conf_if)
f1aa5d8a 7087 json_object_string_add(json_peer, "interface", binfo->peer->conf_if);
b05a1c8b
DS
7088 }
7089 else
7090 {
036a4e7d 7091 if (binfo->peer->conf_if)
04b6bdc0
DW
7092 {
7093 if (binfo->peer->hostname &&
7094 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7095 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7096 binfo->peer->conf_if);
7097 else
7098 vty_out (vty, " from %s", binfo->peer->conf_if);
7099 }
036a4e7d 7100 else
04b6bdc0
DW
7101 {
7102 if (binfo->peer->hostname &&
7103 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7104 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7105 binfo->peer->host);
7106 else
7107 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7108 }
b05a1c8b 7109
f1aa5d8a
DS
7110 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7111 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
7112 else
7113 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
b05a1c8b 7114 }
718e3744 7115 }
b05a1c8b
DS
7116
7117 if (!json_paths)
7118 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7119
f1aa5d8a 7120 /* display the link-local nexthop */
801a9bcc 7121 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
718e3744 7122 {
b05a1c8b
DS
7123 if (json_paths)
7124 {
f1aa5d8a
DS
7125 json_nexthop_ll = json_object_new_object();
7126 json_object_string_add(json_nexthop_ll, "ip",
7127 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7128 buf, INET6_ADDRSTRLEN));
7129 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
7130 json_object_string_add(json_nexthop_ll, "scope", "link-local");
7131
7132 json_object_boolean_true_add(json_nexthop_ll, "accessible");
161995ea
DS
7133
7134 if (!attr->extra->mp_nexthop_prefer_global)
7135 json_object_boolean_true_add(json_nexthop_ll, "used");
7136 else
7137 json_object_boolean_true_add(json_nexthop_global, "used");
b05a1c8b
DS
7138 }
7139 else
7140 {
161995ea
DS
7141 vty_out (vty, " (%s) %s%s",
7142 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
b05a1c8b 7143 buf, INET6_ADDRSTRLEN),
161995ea
DS
7144 attr->extra->mp_nexthop_prefer_global ?
7145 "(prefer-global)" : "(used)",
b05a1c8b
DS
7146 VTY_NEWLINE);
7147 }
718e3744 7148 }
f1aa5d8a
DS
7149 /* If we do not have a link-local nexthop then we must flag the global as "used" */
7150 else
7151 {
7152 if (json_paths)
7153 json_object_boolean_true_add(json_nexthop_global, "used");
7154 }
718e3744 7155
0d9551dc 7156 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
b05a1c8b 7157 if (json_paths)
f1aa5d8a 7158 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
b05a1c8b 7159 else
f1aa5d8a 7160 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
718e3744 7161
7162 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b
DS
7163 {
7164 if (json_paths)
f1aa5d8a 7165 json_object_int_add(json_path, "med", attr->med);
b05a1c8b 7166 else
f1aa5d8a 7167 vty_out (vty, ", metric %u", attr->med);
b05a1c8b 7168 }
718e3744 7169
7170 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
b05a1c8b
DS
7171 {
7172 if (json_paths)
f1aa5d8a 7173 json_object_int_add(json_path, "localpref", attr->local_pref);
b05a1c8b 7174 else
f1aa5d8a 7175 vty_out (vty, ", localpref %u", attr->local_pref);
b05a1c8b 7176 }
718e3744 7177 else
b05a1c8b
DS
7178 {
7179 if (json_paths)
f1aa5d8a 7180 json_object_int_add(json_path, "localpref", bgp->default_local_pref);
b05a1c8b 7181 else
f1aa5d8a 7182 vty_out (vty, ", localpref %u", bgp->default_local_pref);
b05a1c8b 7183 }
718e3744 7184
fb982c25 7185 if (attr->extra && attr->extra->weight != 0)
b05a1c8b
DS
7186 {
7187 if (json_paths)
f1aa5d8a 7188 json_object_int_add(json_path, "weight", attr->extra->weight);
b05a1c8b 7189 else
f1aa5d8a 7190 vty_out (vty, ", weight %u", attr->extra->weight);
b05a1c8b 7191 }
0d9551dc
DS
7192
7193 if (attr->extra && attr->extra->tag != 0)
b05a1c8b
DS
7194 {
7195 if (json_paths)
f1aa5d8a 7196 json_object_int_add(json_path, "tag", attr->extra->tag);
b05a1c8b 7197 else
dc9ffce8 7198 vty_out (vty, ", tag %"ROUTE_TAG_PRI, attr->extra->tag);
b05a1c8b 7199 }
718e3744 7200
31eba040 7201 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
b05a1c8b
DS
7202 {
7203 if (json_paths)
f1aa5d8a 7204 json_object_boolean_false_add(json_path, "valid");
b05a1c8b
DS
7205 else
7206 vty_out (vty, ", invalid");
7207 }
31eba040 7208 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
7209 {
7210 if (json_paths)
f1aa5d8a 7211 json_object_boolean_true_add(json_path, "valid");
b05a1c8b
DS
7212 else
7213 vty_out (vty, ", valid");
7214 }
718e3744 7215
7216 if (binfo->peer != bgp->peer_self)
7217 {
f1aa5d8a 7218 if (binfo->peer->as == binfo->peer->local_as)
b05a1c8b 7219 {
66b199b2
DS
7220 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7221 {
7222 if (json_paths)
f1aa5d8a 7223 json_object_string_add(json_peer, "type", "confed-internal");
66b199b2 7224 else
f1aa5d8a 7225 vty_out (vty, ", confed-internal");
66b199b2 7226 }
b05a1c8b 7227 else
66b199b2
DS
7228 {
7229 if (json_paths)
f1aa5d8a 7230 json_object_string_add(json_peer, "type", "internal");
66b199b2 7231 else
f1aa5d8a 7232 vty_out (vty, ", internal");
66b199b2 7233 }
b05a1c8b 7234 }
f1aa5d8a 7235 else
b05a1c8b
DS
7236 {
7237 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
7238 {
7239 if (json_paths)
f1aa5d8a 7240 json_object_string_add(json_peer, "type", "confed-external");
b05a1c8b 7241 else
f1aa5d8a 7242 vty_out (vty, ", confed-external");
b05a1c8b
DS
7243 }
7244 else
7245 {
7246 if (json_paths)
f1aa5d8a 7247 json_object_string_add(json_peer, "type", "external");
b05a1c8b 7248 else
f1aa5d8a 7249 vty_out (vty, ", external");
b05a1c8b
DS
7250 }
7251 }
718e3744 7252 }
7253 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
b05a1c8b
DS
7254 {
7255 if (json_paths)
7256 {
f1aa5d8a
DS
7257 json_object_boolean_true_add(json_path, "aggregated");
7258 json_object_boolean_true_add(json_path, "local");
b05a1c8b
DS
7259 }
7260 else
7261 {
7262 vty_out (vty, ", aggregated, local");
7263 }
7264 }
718e3744 7265 else if (binfo->type != ZEBRA_ROUTE_BGP)
b05a1c8b
DS
7266 {
7267 if (json_paths)
f1aa5d8a 7268 json_object_boolean_true_add(json_path, "sourced");
b05a1c8b
DS
7269 else
7270 vty_out (vty, ", sourced");
7271 }
718e3744 7272 else
b05a1c8b
DS
7273 {
7274 if (json_paths)
7275 {
f1aa5d8a
DS
7276 json_object_boolean_true_add(json_path, "sourced");
7277 json_object_boolean_true_add(json_path, "local");
b05a1c8b
DS
7278 }
7279 else
7280 {
7281 vty_out (vty, ", sourced, local");
7282 }
7283 }
718e3744 7284
7285 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
b05a1c8b
DS
7286 {
7287 if (json_paths)
62d6dca0 7288 json_object_boolean_true_add(json_path, "atomicAggregate");
b05a1c8b
DS
7289 else
7290 vty_out (vty, ", atomic-aggregate");
7291 }
718e3744 7292
de8d5dff
JB
7293 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
7294 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
7295 bgp_info_mpath_count (binfo)))
b05a1c8b
DS
7296 {
7297 if (json_paths)
f1aa5d8a 7298 json_object_boolean_true_add(json_path, "multipath");
b05a1c8b
DS
7299 else
7300 vty_out (vty, ", multipath");
7301 }
de8d5dff 7302
06370dac
DW
7303 // Mark the bestpath(s)
7304 if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED))
7305 {
aac9ef6c 7306 first_as = aspath_get_first_as(attr->aspath);
06370dac
DW
7307
7308 if (json_paths)
7309 {
7310 if (!json_bestpath)
7311 json_bestpath = json_object_new_object();
7312 json_object_int_add(json_bestpath, "bestpathFromAs", first_as);
7313 }
7314 else
7315 {
7316 if (first_as)
7317 vty_out (vty, ", bestpath-from-AS %d", first_as);
7318 else
7319 vty_out (vty, ", bestpath-from-AS Local");
7320 }
7321 }
7322
718e3744 7323 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
b05a1c8b
DS
7324 {
7325 if (json_paths)
f1aa5d8a 7326 {
06370dac
DW
7327 if (!json_bestpath)
7328 json_bestpath = json_object_new_object();
f1aa5d8a 7329 json_object_boolean_true_add(json_bestpath, "overall");
f1aa5d8a 7330 }
b05a1c8b
DS
7331 else
7332 vty_out (vty, ", best");
7333 }
718e3744 7334
06370dac
DW
7335 if (json_bestpath)
7336 json_object_object_add(json_path, "bestpath", json_bestpath);
7337
b05a1c8b
DS
7338 if (!json_paths)
7339 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7340
7341 /* Line 4 display Community */
7342 if (attr->community)
b05a1c8b
DS
7343 {
7344 if (json_paths)
7345 {
f1aa5d8a
DS
7346 json_object_lock(attr->community->json);
7347 json_object_object_add(json_path, "community", attr->community->json);
b05a1c8b
DS
7348 }
7349 else
7350 {
7351 vty_out (vty, " Community: %s%s", attr->community->str,
7352 VTY_NEWLINE);
7353 }
7354 }
718e3744 7355
7356 /* Line 5 display Extended-community */
7357 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
b05a1c8b
DS
7358 {
7359 if (json_paths)
7360 {
f1aa5d8a
DS
7361 json_ext_community = json_object_new_object();
7362 json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str);
62d6dca0 7363 json_object_object_add(json_path, "extendedCommunity", json_ext_community);
b05a1c8b
DS
7364 }
7365 else
7366 {
7367 vty_out (vty, " Extended Community: %s%s",
7368 attr->extra->ecommunity->str, VTY_NEWLINE);
7369 }
7370 }
7371
718e3744 7372 /* Line 6 display Originator, Cluster-id */
7373 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
7374 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
7375 {
fb982c25 7376 assert (attr->extra);
718e3744 7377 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
b05a1c8b
DS
7378 {
7379 if (json_paths)
62d6dca0 7380 json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id));
b05a1c8b 7381 else
f1aa5d8a
DS
7382 vty_out (vty, " Originator: %s",
7383 inet_ntoa (attr->extra->originator_id));
b05a1c8b 7384 }
718e3744 7385
7386 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
7387 {
7388 int i;
b05a1c8b
DS
7389
7390 if (json_paths)
7391 {
f1aa5d8a
DS
7392 json_cluster_list = json_object_new_object();
7393 json_cluster_list_list = json_object_new_array();
7394
b05a1c8b
DS
7395 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7396 {
7397 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
f1aa5d8a 7398 json_object_array_add(json_cluster_list_list, json_string);
b05a1c8b 7399 }
f1aa5d8a
DS
7400
7401 /* struct cluster_list does not have "str" variable like
7402 * aspath and community do. Add this someday if someone
7403 * asks for it.
7404 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
7405 */
7406 json_object_object_add(json_cluster_list, "list", json_cluster_list_list);
62d6dca0 7407 json_object_object_add(json_path, "clusterList", json_cluster_list);
b05a1c8b
DS
7408 }
7409 else
7410 {
7411 vty_out (vty, ", Cluster list: ");
7412
7413 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7414 {
7415 vty_out (vty, "%s ",
7416 inet_ntoa (attr->extra->cluster->list[i]));
7417 }
7418 }
718e3744 7419 }
b05a1c8b
DS
7420
7421 if (!json_paths)
7422 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7423 }
b05a1c8b 7424
fb982c25 7425 if (binfo->extra && binfo->extra->damp_info)
b05a1c8b 7426 bgp_damp_info_vty (vty, binfo, json_path);
718e3744 7427
a82478b9
DS
7428 /* Line 7 display Addpath IDs */
7429 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
b05a1c8b
DS
7430 {
7431 if (json_paths)
7432 {
62d6dca0
DS
7433 json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id);
7434 json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id);
b05a1c8b
DS
7435 }
7436 else
7437 {
7438 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
7439 binfo->addpath_rx_id, binfo->addpath_tx_id,
7440 VTY_NEWLINE);
7441 }
7442 }
a82478b9 7443
adbac85e
DW
7444 /* If we used addpath to TX a non-bestpath we need to display
7445 * "Advertised to" on a path-by-path basis */
7446 if (bgp->addpath_tx_used[afi][safi])
7447 {
7448 first = 1;
7449
7450 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7451 {
7452 addpath_capable = bgp_addpath_encode_tx (peer, afi, safi);
7453 has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id);
7454
7455 if ((addpath_capable && has_adj) ||
7456 (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)))
7457 {
7458 if (json_path && !json_adv_to)
7459 json_adv_to = json_object_new_object();
7460
7461 route_vty_out_advertised_to(vty, peer, &first,
7462 " Advertised to:",
7463 json_adv_to);
7464 }
7465 }
7466
7467 if (json_path)
7468 {
7469 if (json_adv_to)
7470 {
7471 json_object_object_add(json_path, "advertisedTo", json_adv_to);
7472 }
7473 }
7474 else
7475 {
7476 if (!first)
7477 {
7478 vty_out (vty, "%s", VTY_NEWLINE);
7479 }
7480 }
7481 }
7482
a82478b9 7483 /* Line 8 display Uptime */
30b00176
JK
7484#ifdef HAVE_CLOCK_MONOTONIC
7485 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
b05a1c8b 7486 if (json_paths)
f1aa5d8a
DS
7487 {
7488 json_last_update = json_object_new_object();
7489 json_object_int_add(json_last_update, "epoch", tbuf);
7490 json_object_string_add(json_last_update, "string", ctime(&tbuf));
62d6dca0 7491 json_object_object_add(json_path, "lastUpdate", json_last_update);
f1aa5d8a 7492 }
b05a1c8b
DS
7493 else
7494 vty_out (vty, " Last update: %s", ctime(&tbuf));
30b00176 7495#else
b05a1c8b 7496 if (json_paths)
f1aa5d8a
DS
7497 {
7498 json_last_update = json_object_new_object();
7499 json_object_int_add(json_last_update, "epoch", tbuf);
7500 json_object_string_add(json_last_update, "string", ctime(&binfo->uptime));
62d6dca0 7501 json_object_object_add(json_path, "lastUpdate", json_last_update);
f1aa5d8a 7502 }
b05a1c8b
DS
7503 else
7504 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
30b00176 7505#endif /* HAVE_CLOCK_MONOTONIC */
718e3744 7506 }
b05a1c8b
DS
7507
7508 /* We've constructed the json object for this path, add it to the json
7509 * array of paths
7510 */
7511 if (json_paths)
f1aa5d8a
DS
7512 {
7513 if (json_nexthop_global || json_nexthop_ll)
7514 {
7515 json_nexthops = json_object_new_array();
7516
7517 if (json_nexthop_global)
7518 json_object_array_add(json_nexthops, json_nexthop_global);
7519
7520 if (json_nexthop_ll)
7521 json_object_array_add(json_nexthops, json_nexthop_ll);
7522
7523 json_object_object_add(json_path, "nexthops", json_nexthops);
7524 }
7525
7526 json_object_object_add(json_path, "peer", json_peer);
7527 json_object_array_add(json_paths, json_path);
7528 }
b05a1c8b
DS
7529 else
7530 vty_out (vty, "%s", VTY_NEWLINE);
b366b518
BB
7531}
7532
47fc97cc 7533#define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
718e3744 7534#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7535#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7536
7537enum bgp_show_type
7538{
7539 bgp_show_type_normal,
7540 bgp_show_type_regexp,
7541 bgp_show_type_prefix_list,
7542 bgp_show_type_filter_list,
7543 bgp_show_type_route_map,
7544 bgp_show_type_neighbor,
7545 bgp_show_type_cidr_only,
7546 bgp_show_type_prefix_longer,
7547 bgp_show_type_community_all,
7548 bgp_show_type_community,
7549 bgp_show_type_community_exact,
7550 bgp_show_type_community_list,
7551 bgp_show_type_community_list_exact,
7552 bgp_show_type_flap_statistics,
7553 bgp_show_type_flap_address,
7554 bgp_show_type_flap_prefix,
7555 bgp_show_type_flap_cidr_only,
7556 bgp_show_type_flap_regexp,
7557 bgp_show_type_flap_filter_list,
7558 bgp_show_type_flap_prefix_list,
7559 bgp_show_type_flap_prefix_longer,
7560 bgp_show_type_flap_route_map,
7561 bgp_show_type_flap_neighbor,
7562 bgp_show_type_dampend_paths,
7563 bgp_show_type_damp_neighbor
7564};
7565
50ef26d4 7566static int
7567bgp_show_prefix_list (struct vty *vty, const char *name,
7568 const char *prefix_list_str, afi_t afi,
7569 safi_t safi, enum bgp_show_type type);
7570static int
7571bgp_show_filter_list (struct vty *vty, const char *name,
7572 const char *filter, afi_t afi,
7573 safi_t safi, enum bgp_show_type type);
7574static int
7575bgp_show_route_map (struct vty *vty, const char *name,
7576 const char *rmap_str, afi_t afi,
7577 safi_t safi, enum bgp_show_type type);
7578static int
7579bgp_show_community_list (struct vty *vty, const char *name,
7580 const char *com, int exact,
7581 afi_t afi, safi_t safi);
7582static int
7583bgp_show_prefix_longer (struct vty *vty, const char *name,
7584 const char *prefix, afi_t afi,
7585 safi_t safi, enum bgp_show_type type);
7586
5a646650 7587static int
31303c3e
DS
7588bgp_show_table (struct vty *vty, struct bgp *bgp, struct bgp_table *table,
7589 enum bgp_show_type type, void *output_arg, u_char use_json)
718e3744 7590{
718e3744 7591 struct bgp_info *ri;
7592 struct bgp_node *rn;
718e3744 7593 int header = 1;
718e3744 7594 int display;
5a646650 7595 unsigned long output_count;
18200902 7596 unsigned long total_count;
b05a1c8b
DS
7597 struct prefix *p;
7598 char buf[BUFSIZ];
7599 char buf2[BUFSIZ];
f1aa5d8a 7600 json_object *json_paths = NULL;
31303c3e 7601 int first = 1;
b05a1c8b
DS
7602
7603 if (use_json)
7604 {
31303c3e
DS
7605 vty_out (vty, "{ \"vrfId\": %d, \"vrfName\": \"%s\", \"tableVersion\": %" PRId64 ", \"routerId\": \"%s\", \"routes\": { ",
7606 bgp->vrf_id == VRF_UNKNOWN ? -1 : bgp->vrf_id,
7607 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ? "Default" : bgp->name,
7608 table->version, inet_ntoa (bgp->router_id));
7609 json_paths = json_object_new_object();
b05a1c8b 7610 }
718e3744 7611
7612 /* This is first entry point, so reset total line. */
5a646650 7613 output_count = 0;
18200902 7614 total_count = 0;
718e3744 7615
718e3744 7616 /* Start processing of routes. */
7617 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7618 if (rn->info != NULL)
7619 {
856ca177 7620 display = 0;
31303c3e
DS
7621 if (!first && use_json)
7622 {
7623 vty_out (vty, ",");
7624 }
b05a1c8b
DS
7625 if (use_json)
7626 json_paths = json_object_new_array();
7627 else
7628 json_paths = NULL;
7629
856ca177
MS
7630 for (ri = rn->info; ri; ri = ri->next)
7631 {
18200902 7632 total_count++;
856ca177
MS
7633 if (type == bgp_show_type_flap_statistics
7634 || type == bgp_show_type_flap_address
7635 || type == bgp_show_type_flap_prefix
7636 || type == bgp_show_type_flap_cidr_only
7637 || type == bgp_show_type_flap_regexp
7638 || type == bgp_show_type_flap_filter_list
7639 || type == bgp_show_type_flap_prefix_list
7640 || type == bgp_show_type_flap_prefix_longer
7641 || type == bgp_show_type_flap_route_map
7642 || type == bgp_show_type_flap_neighbor
7643 || type == bgp_show_type_dampend_paths
7644 || type == bgp_show_type_damp_neighbor)
7645 {
7646 if (!(ri->extra && ri->extra->damp_info))
7647 continue;
7648 }
7649 if (type == bgp_show_type_regexp
7650 || type == bgp_show_type_flap_regexp)
7651 {
7652 regex_t *regex = output_arg;
718e3744 7653
856ca177
MS
7654 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7655 continue;
7656 }
7657 if (type == bgp_show_type_prefix_list
7658 || type == bgp_show_type_flap_prefix_list)
7659 {
7660 struct prefix_list *plist = output_arg;
718e3744 7661
856ca177
MS
7662 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7663 continue;
7664 }
7665 if (type == bgp_show_type_filter_list
7666 || type == bgp_show_type_flap_filter_list)
7667 {
7668 struct as_list *as_list = output_arg;
558d1fec 7669
856ca177
MS
7670 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7671 continue;
7672 }
7673 if (type == bgp_show_type_route_map
7674 || type == bgp_show_type_flap_route_map)
7675 {
7676 struct route_map *rmap = output_arg;
7677 struct bgp_info binfo;
7678 struct attr dummy_attr;
7679 struct attr_extra dummy_extra;
7680 int ret;
718e3744 7681
856ca177
MS
7682 dummy_attr.extra = &dummy_extra;
7683 bgp_attr_dup (&dummy_attr, ri->attr);
718e3744 7684
856ca177
MS
7685 binfo.peer = ri->peer;
7686 binfo.attr = &dummy_attr;
718e3744 7687
856ca177
MS
7688 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
7689 if (ret == RMAP_DENYMATCH)
7690 continue;
7691 }
7692 if (type == bgp_show_type_neighbor
7693 || type == bgp_show_type_flap_neighbor
7694 || type == bgp_show_type_damp_neighbor)
7695 {
7696 union sockunion *su = output_arg;
718e3744 7697
856ca177
MS
7698 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7699 continue;
7700 }
7701 if (type == bgp_show_type_cidr_only
7702 || type == bgp_show_type_flap_cidr_only)
7703 {
7704 u_int32_t destination;
718e3744 7705
856ca177
MS
7706 destination = ntohl (rn->p.u.prefix4.s_addr);
7707 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7708 continue;
7709 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7710 continue;
7711 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7712 continue;
7713 }
7714 if (type == bgp_show_type_prefix_longer
7715 || type == bgp_show_type_flap_prefix_longer)
7716 {
7717 struct prefix *p = output_arg;
718e3744 7718
856ca177
MS
7719 if (! prefix_match (p, &rn->p))
7720 continue;
7721 }
7722 if (type == bgp_show_type_community_all)
7723 {
7724 if (! ri->attr->community)
7725 continue;
7726 }
7727 if (type == bgp_show_type_community)
7728 {
7729 struct community *com = output_arg;
718e3744 7730
856ca177
MS
7731 if (! ri->attr->community ||
7732 ! community_match (ri->attr->community, com))
7733 continue;
7734 }
7735 if (type == bgp_show_type_community_exact)
7736 {
7737 struct community *com = output_arg;
718e3744 7738
856ca177
MS
7739 if (! ri->attr->community ||
7740 ! community_cmp (ri->attr->community, com))
7741 continue;
7742 }
7743 if (type == bgp_show_type_community_list)
7744 {
7745 struct community_list *list = output_arg;
718e3744 7746
856ca177
MS
7747 if (! community_list_match (ri->attr->community, list))
7748 continue;
7749 }
7750 if (type == bgp_show_type_community_list_exact)
7751 {
7752 struct community_list *list = output_arg;
718e3744 7753
856ca177
MS
7754 if (! community_list_exact_match (ri->attr->community, list))
7755 continue;
7756 }
7757 if (type == bgp_show_type_flap_address
7758 || type == bgp_show_type_flap_prefix)
7759 {
7760 struct prefix *p = output_arg;
718e3744 7761
856ca177
MS
7762 if (! prefix_match (&rn->p, p))
7763 continue;
b05a1c8b 7764
856ca177
MS
7765 if (type == bgp_show_type_flap_prefix)
7766 if (p->prefixlen != rn->p.prefixlen)
7767 continue;
7768 }
7769 if (type == bgp_show_type_dampend_paths
7770 || type == bgp_show_type_damp_neighbor)
7771 {
7772 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7773 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7774 continue;
7775 }
7776
7777 if (!use_json && header)
7778 {
31303c3e 7779 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
856ca177
MS
7780 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7781 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7782 if (type == bgp_show_type_dampend_paths
7783 || type == bgp_show_type_damp_neighbor)
7784 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7785 else if (type == bgp_show_type_flap_statistics
7786 || type == bgp_show_type_flap_address
7787 || type == bgp_show_type_flap_prefix
7788 || type == bgp_show_type_flap_cidr_only
7789 || type == bgp_show_type_flap_regexp
7790 || type == bgp_show_type_flap_filter_list
7791 || type == bgp_show_type_flap_prefix_list
7792 || type == bgp_show_type_flap_prefix_longer
7793 || type == bgp_show_type_flap_route_map
7794 || type == bgp_show_type_flap_neighbor)
7795 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7796 else
7797 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7798 header = 0;
7799 }
7800
7801 if (type == bgp_show_type_dampend_paths
7802 || type == bgp_show_type_damp_neighbor)
7803 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7804 else if (type == bgp_show_type_flap_statistics
7805 || type == bgp_show_type_flap_address
7806 || type == bgp_show_type_flap_prefix
7807 || type == bgp_show_type_flap_cidr_only
7808 || type == bgp_show_type_flap_regexp
7809 || type == bgp_show_type_flap_filter_list
7810 || type == bgp_show_type_flap_prefix_list
7811 || type == bgp_show_type_flap_prefix_longer
7812 || type == bgp_show_type_flap_route_map
7813 || type == bgp_show_type_flap_neighbor)
7814 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7815 else
7816 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
7817 display++;
b05a1c8b
DS
7818 }
7819
856ca177
MS
7820 if (display)
7821 {
7822 output_count++;
7823 if (use_json)
7824 {
7825 p = &rn->p;
7826 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
31303c3e
DS
7827 vty_out (vty, "\"%s\": ", buf2);
7828 vty_out (vty, "%s", json_object_to_json_string (json_paths));
7829 json_object_free (json_paths);
7830 first = 0;
7831
856ca177
MS
7832 }
7833 }
9f689658 7834 }
718e3744 7835
b05a1c8b 7836 if (use_json)
718e3744 7837 {
31303c3e
DS
7838 json_object_free (json_paths);
7839 vty_out (vty, " } }%s", VTY_NEWLINE);
718e3744 7840 }
7841 else
b05a1c8b
DS
7842 {
7843 /* No route is displayed */
7844 if (output_count == 0)
7845 {
7846 if (type == bgp_show_type_normal)
18200902 7847 vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
b05a1c8b
DS
7848 }
7849 else
5c3cc3ae 7850 vty_out (vty, "%sDisplayed %ld routes and %ld total paths%s",
18200902 7851 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
b05a1c8b 7852 }
718e3744 7853
7854 return CMD_SUCCESS;
7855}
7856
5a646650 7857static int
fee0f4c6 7858bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
856ca177 7859 enum bgp_show_type type, void *output_arg, u_char use_json)
fee0f4c6 7860{
7861 struct bgp_table *table;
7862
856ca177
MS
7863 if (bgp == NULL)
7864 {
7865 bgp = bgp_get_default ();
7866 }
fee0f4c6 7867
7868 if (bgp == NULL)
7869 {
856ca177
MS
7870 if (!use_json)
7871 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
fee0f4c6 7872 return CMD_WARNING;
7873 }
7874
fee0f4c6 7875 table = bgp->rib[afi][safi];
7876
31303c3e
DS
7877 return bgp_show_table (vty, bgp, table, type, output_arg,
7878 use_json);
fee0f4c6 7879}
7880
f186de26 7881static void
7882bgp_show_all_instances_routes_vty (struct vty *vty, afi_t afi, safi_t safi,
7883 u_char use_json)
7884{
7885 struct listnode *node, *nnode;
7886 struct bgp *bgp;
7887 struct bgp_table *table;
9f689658
DD
7888 int is_first = 1;
7889
7890 if (use_json)
7891 vty_out (vty, "{%s", VTY_NEWLINE);
f186de26 7892
7893 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
7894 {
9f689658
DD
7895 if (use_json)
7896 {
9f689658
DD
7897 if (! is_first)
7898 vty_out (vty, ",%s", VTY_NEWLINE);
7899 else
7900 is_first = 0;
7901
7902 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7903 ? "Default" : bgp->name);
7904 }
7905 else
7906 {
7907 vty_out (vty, "%sInstance %s:%s",
7908 VTY_NEWLINE,
7909 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7910 ? "Default" : bgp->name,
7911 VTY_NEWLINE);
7912 }
f186de26 7913 table = bgp->rib[afi][safi];
31303c3e
DS
7914 bgp_show_table (vty, bgp, table,
7915 bgp_show_type_normal, NULL, use_json);
9f689658 7916
f186de26 7917 }
9f689658
DD
7918
7919 if (use_json)
7920 vty_out (vty, "}%s", VTY_NEWLINE);
f186de26 7921}
7922
718e3744 7923/* Header of detailed BGP route information */
94f2b392 7924static void
718e3744 7925route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7926 struct bgp_node *rn,
b05a1c8b
DS
7927 struct prefix_rd *prd, afi_t afi, safi_t safi,
7928 json_object *json)
718e3744 7929{
7930 struct bgp_info *ri;
7931 struct prefix *p;
7932 struct peer *peer;
1eb8ef25 7933 struct listnode *node, *nnode;
718e3744 7934 char buf1[INET6_ADDRSTRLEN];
7935 char buf2[INET6_ADDRSTRLEN];
7936 int count = 0;
7937 int best = 0;
7938 int suppress = 0;
7939 int no_export = 0;
7940 int no_advertise = 0;
7941 int local_as = 0;
adbac85e 7942 int first = 1;
ffd0c037 7943 json_object *json_adv_to = NULL;
718e3744 7944
7945 p = &rn->p;
b05a1c8b
DS
7946
7947 if (json)
7948 {
f1aa5d8a
DS
7949 json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7950 json_object_int_add(json, "prefixlen", p->prefixlen);
b05a1c8b
DS
7951 }
7952 else
7953 {
7954 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
587ff0fd 7955 ((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) ?
b05a1c8b
DS
7956 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7957 safi == SAFI_MPLS_VPN ? ":" : "",
7958 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7959 p->prefixlen, VTY_NEWLINE);
7960 }
718e3744 7961
7962 for (ri = rn->info; ri; ri = ri->next)
7963 {
7964 count++;
7965 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7966 {
7967 best = count;
fb982c25 7968 if (ri->extra && ri->extra->suppress)
718e3744 7969 suppress = 1;
7970 if (ri->attr->community != NULL)
7971 {
7972 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7973 no_advertise = 1;
7974 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7975 no_export = 1;
7976 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7977 local_as = 1;
7978 }
7979 }
7980 }
7981
b05a1c8b 7982 if (!json)
718e3744 7983 {
b05a1c8b
DS
7984 vty_out (vty, "Paths: (%d available", count);
7985 if (best)
7986 {
7987 vty_out (vty, ", best #%d", best);
7988 if (safi == SAFI_UNICAST)
46827ae9
DS
7989 vty_out (vty, ", table %s",
7990 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7991 ? "Default-IP-Routing-Table" : bgp->name);
b05a1c8b
DS
7992 }
7993 else
7994 vty_out (vty, ", no best path");
7995
7996 if (no_advertise)
7997 vty_out (vty, ", not advertised to any peer");
7998 else if (no_export)
7999 vty_out (vty, ", not advertised to EBGP peer");
8000 else if (local_as)
8001 vty_out (vty, ", not advertised outside local AS");
8002
8003 if (suppress)
8004 vty_out (vty, ", Advertisements suppressed by an aggregate.");
8005 vty_out (vty, ")%s", VTY_NEWLINE);
718e3744 8006 }
718e3744 8007
adbac85e
DW
8008 /* If we are not using addpath then we can display Advertised to and that will
8009 * show what peers we advertised the bestpath to. If we are using addpath
8010 * though then we must display Advertised to on a path-by-path basis. */
8011 if (!bgp->addpath_tx_used[afi][safi])
718e3744 8012 {
adbac85e
DW
8013 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
8014 {
8015 if (bgp_adj_out_lookup (peer, rn, 0))
b05a1c8b 8016 {
adbac85e 8017 if (json && !json_adv_to)
f1aa5d8a 8018 json_adv_to = json_object_new_object();
6410e93a 8019
adbac85e
DW
8020 route_vty_out_advertised_to(vty, peer, &first,
8021 " Advertised to non peer-group peers:\n ",
8022 json_adv_to);
b05a1c8b 8023 }
adbac85e 8024 }
036a4e7d 8025
adbac85e
DW
8026 if (json)
8027 {
8028 if (json_adv_to)
8029 {
8030 json_object_object_add(json, "advertisedTo", json_adv_to);
b05a1c8b 8031 }
adbac85e
DW
8032 }
8033 else
b05a1c8b 8034 {
adbac85e
DW
8035 if (first)
8036 vty_out (vty, " Not advertised to any peer");
8037 vty_out (vty, "%s", VTY_NEWLINE);
b05a1c8b
DS
8038 }
8039 }
718e3744 8040}
8041
8042/* Display specified route of BGP table. */
94f2b392 8043static int
fee0f4c6 8044bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
fd79ac91 8045 struct bgp_table *rib, const char *ip_str,
8046 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
8047 int prefix_check, enum bgp_path_type pathtype,
8048 u_char use_json)
718e3744 8049{
8050 int ret;
8051 int header;
8052 int display = 0;
8053 struct prefix match;
8054 struct bgp_node *rn;
8055 struct bgp_node *rm;
8056 struct bgp_info *ri;
718e3744 8057 struct bgp_table *table;
f1aa5d8a
DS
8058 json_object *json = NULL;
8059 json_object *json_paths = NULL;
718e3744 8060
718e3744 8061 /* Check IP address argument. */
8062 ret = str2prefix (ip_str, &match);
8063 if (! ret)
8064 {
8065 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
8066 return CMD_WARNING;
8067 }
8068
8069 match.family = afi2family (afi);
8070
b05a1c8b
DS
8071 if (use_json)
8072 {
8073 json = json_object_new_object();
8074 json_paths = json_object_new_array();
8075 }
b05a1c8b 8076
587ff0fd 8077 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
718e3744 8078 {
fee0f4c6 8079 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
718e3744 8080 {
8081 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
8082 continue;
8083
8084 if ((table = rn->info) != NULL)
8085 {
8086 header = 1;
8087
8088 if ((rm = bgp_node_match (table, &match)) != NULL)
8089 {
8090 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6c88b44d
CC
8091 {
8092 bgp_unlock_node (rm);
8093 continue;
8094 }
718e3744 8095
8096 for (ri = rm->info; ri; ri = ri->next)
8097 {
8098 if (header)
8099 {
8100 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
587ff0fd 8101 AFI_IP, safi, json);
718e3744 8102 header = 0;
8103 }
8104 display++;
4092b06c
DS
8105
8106 if (pathtype == BGP_PATH_ALL ||
8107 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8108 (pathtype == BGP_PATH_MULTIPATH &&
8109 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
587ff0fd 8110 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi, json_paths);
718e3744 8111 }
6c88b44d
CC
8112
8113 bgp_unlock_node (rm);
718e3744 8114 }
8115 }
8116 }
8117 }
8118 else
8119 {
8120 header = 1;
8121
fee0f4c6 8122 if ((rn = bgp_node_match (rib, &match)) != NULL)
718e3744 8123 {
8124 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
8125 {
8126 for (ri = rn->info; ri; ri = ri->next)
8127 {
8128 if (header)
8129 {
b05a1c8b 8130 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
718e3744 8131 header = 0;
8132 }
8133 display++;
4092b06c
DS
8134
8135 if (pathtype == BGP_PATH_ALL ||
8136 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8137 (pathtype == BGP_PATH_MULTIPATH &&
8138 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
b05a1c8b 8139 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
718e3744 8140 }
8141 }
6c88b44d
CC
8142
8143 bgp_unlock_node (rn);
718e3744 8144 }
8145 }
8146
e5eee9af 8147 if (use_json)
718e3744 8148 {
e5eee9af
DS
8149 if (display)
8150 json_object_object_add(json, "paths", json_paths);
8151
2aac5767 8152 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
f1aa5d8a 8153 json_object_free(json);
b05a1c8b
DS
8154 }
8155 else
8156 {
e5eee9af 8157 if (!display)
b05a1c8b
DS
8158 {
8159 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
8160 return CMD_WARNING;
8161 }
8162 }
8163
718e3744 8164 return CMD_SUCCESS;
8165}
8166
fee0f4c6 8167/* Display specified route of Main RIB */
94f2b392 8168static int
fd79ac91 8169bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
fee0f4c6 8170 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
8171 int prefix_check, enum bgp_path_type pathtype,
8172 u_char use_json)
fee0f4c6 8173{
8174 struct bgp *bgp;
8175
8176 /* BGP structure lookup. */
8177 if (view_name)
8178 {
8179 bgp = bgp_lookup_by_name (view_name);
8180 if (bgp == NULL)
8181 {
6aeb9e78 8182 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
fee0f4c6 8183 return CMD_WARNING;
8184 }
8185 }
8186 else
8187 {
8188 bgp = bgp_get_default ();
8189 if (bgp == NULL)
8190 {
8191 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8192 return CMD_WARNING;
8193 }
8194 }
8195
8196 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
b05a1c8b
DS
8197 afi, safi, prd, prefix_check, pathtype,
8198 use_json);
fee0f4c6 8199}
8200
718e3744 8201/* BGP route print out function. */
8202DEFUN (show_ip_bgp,
8203 show_ip_bgp_cmd,
b05a1c8b 8204 "show ip bgp {json}",
47fc97cc
DS
8205 SHOW_STR
8206 IP_STR
b05a1c8b
DS
8207 BGP_STR
8208 "JavaScript Object Notation\n")
47fc97cc 8209{
db7c8528 8210 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
718e3744 8211}
8212
f799a22a
LB
8213ALIAS (show_ip_bgp,
8214 show_bgp_ipv4_cmd,
8215 "show bgp ipv4 {json}",
8216 SHOW_STR
8217 IP_STR
8218 BGP_STR
8219 "Address family\n"
8220 "JavaScript Object Notation\n")
8221
718e3744 8222DEFUN (show_ip_bgp_ipv4,
8223 show_ip_bgp_ipv4_cmd,
4575cfc3 8224 "show ip bgp ipv4 (unicast|multicast) {json}",
718e3744 8225 SHOW_STR
8226 IP_STR
8227 BGP_STR
8228 "Address family\n"
4575cfc3
LB
8229 "Address Family modifier\n"
8230 "Address Family modifier\n"
b05a1c8b 8231 "JavaScript Object Notation\n")
718e3744 8232{
db7c8528 8233 u_char uj = use_json(argc, argv);
718e3744 8234
ccbb332a
LB
8235 return bgp_show (vty, NULL, AFI_IP,
8236 bgp_vty_safi_from_arg(argv[0]),
8237 bgp_show_type_normal, NULL, uj);
718e3744 8238}
8239
95cbbd2a
ML
8240ALIAS (show_ip_bgp_ipv4,
8241 show_bgp_ipv4_safi_cmd,
4575cfc3 8242 "show bgp ipv4 (unicast|multicast) {json}",
95cbbd2a
ML
8243 SHOW_STR
8244 BGP_STR
8245 "Address family\n"
4575cfc3
LB
8246 "Address Family modifier\n"
8247 "Address Family modifier\n"
b05a1c8b 8248 "JavaScript Object Notation\n")
47fc97cc 8249
718e3744 8250DEFUN (show_ip_bgp_route,
8251 show_ip_bgp_route_cmd,
b05a1c8b 8252 "show ip bgp A.B.C.D {json}",
718e3744 8253 SHOW_STR
8254 IP_STR
8255 BGP_STR
b05a1c8b
DS
8256 "Network in the BGP routing table to display\n"
8257 "JavaScript Object Notation\n")
718e3744 8258{
db7c8528 8259 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
4092b06c
DS
8260}
8261
8262DEFUN (show_ip_bgp_route_pathtype,
8263 show_ip_bgp_route_pathtype_cmd,
b05a1c8b 8264 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
4092b06c
DS
8265 SHOW_STR
8266 IP_STR
8267 BGP_STR
8268 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8269 "Display only the bestpath\n"
b05a1c8b
DS
8270 "Display only multipaths\n"
8271 "JavaScript Object Notation\n")
4092b06c 8272{
db7c8528 8273 u_char uj = use_json(argc, argv);
b05a1c8b 8274
4092b06c 8275 if (strncmp (argv[1], "b", 1) == 0)
db7c8528 8276 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 8277 else
db7c8528 8278 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8279}
8280
8281DEFUN (show_bgp_ipv4_safi_route_pathtype,
8282 show_bgp_ipv4_safi_route_pathtype_cmd,
d02fbbdb 8283 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D (bestpath|multipath) {json}",
4092b06c
DS
8284 SHOW_STR
8285 BGP_STR
d02fbbdb 8286 BGP_AFI_SAFI_HELP_STR
4092b06c
DS
8287 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8288 "Display only the bestpath\n"
b05a1c8b
DS
8289 "Display only multipaths\n"
8290 "JavaScript Object Notation\n")
4092b06c 8291{
db7c8528 8292 u_char uj = use_json(argc, argv);
b05a1c8b 8293
ccbb332a
LB
8294 if (strncmp (argv[2], "b", 1) == 0)
8295 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8296 bgp_vty_safi_from_arg(argv[0]),
8297 NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 8298 else
ccbb332a
LB
8299 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8300 bgp_vty_safi_from_arg(argv[0]),
8301 NULL, 0, BGP_PATH_MULTIPATH, uj);
718e3744 8302}
8303
e3e29b32
LB
8304DEFUN (show_bgp_ipv4_prefix,
8305 show_bgp_ipv4_prefix_cmd,
8306 "show bgp ipv4 A.B.C.D/M {json}",
8307 SHOW_STR
8308 BGP_STR
8309 IP_STR
8310 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8311 JSON_STR)
8312{
8313 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc, argv));
8314}
8315
8316DEFUN (show_bgp_ipv6_route,
8317 show_bgp_ipv6_route_cmd,
847e983f 8318 "show bgp ipv6 X:X::X:X {json}",
e3e29b32
LB
8319 SHOW_STR
8320 BGP_STR
8321 "Address family\n"
8322 "Network in the BGP routing table to display\n"
8323 JSON_STR)
8324{
8325 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json (argc, argv));
8326}
8327
8328DEFUN (show_bgp_ipv6_prefix,
8329 show_bgp_ipv6_prefix_cmd,
8330 "show bgp ipv6 X:X::X:X/M {json}",
8331 SHOW_STR
8332 BGP_STR
8333 IP_STR
8334 "IPv6 prefix <network>/<length>\n"
8335 JSON_STR)
8336{
8337 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc,argv));
8338}
8339
718e3744 8340DEFUN (show_ip_bgp_ipv4_route,
8341 show_ip_bgp_ipv4_route_cmd,
d02fbbdb 8342 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D {json}",
718e3744 8343 SHOW_STR
8344 IP_STR
8345 BGP_STR
d02fbbdb 8346 BGP_AFI_SAFI_HELP_STR
b05a1c8b
DS
8347 "Network in the BGP routing table to display\n"
8348 "JavaScript Object Notation\n")
718e3744 8349{
db7c8528 8350 u_char uj = use_json(argc, argv);
b05a1c8b 8351
ccbb332a
LB
8352 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8353 bgp_vty_safi_from_arg(argv[0]),
8354 NULL, 0, BGP_PATH_ALL, uj);
718e3744 8355}
8356
95cbbd2a
ML
8357ALIAS (show_ip_bgp_ipv4_route,
8358 show_bgp_ipv4_safi_route_cmd,
d02fbbdb 8359 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D {json}",
95cbbd2a
ML
8360 SHOW_STR
8361 BGP_STR
d02fbbdb 8362 BGP_AFI_SAFI_HELP_STR
b05a1c8b
DS
8363 "Network in the BGP routing table to display\n"
8364 "JavaScript Object Notation\n")
95cbbd2a 8365
ccbb332a
LB
8366DEFUN (show_bgp_ipv4_safi_rd_route,
8367 show_bgp_ipv4_safi_rd_route_cmd,
8368 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
e3e29b32
LB
8369 SHOW_STR
8370 BGP_STR
8371 "Address Family\n"
ccbb332a
LB
8372 "Address Family Modifier\n"
8373 "Address Family Modifier\n"
8374 "Display information for a route distinguisher\n"
8375 "ENCAP Route Distinguisher\n"
8376 "Network in the BGP routing table to display\n")
e3e29b32 8377{
ccbb332a
LB
8378 int ret;
8379 struct prefix_rd prd;
8380 safi_t safi;
8381
8382 if (bgp_parse_safi(argv[0], &safi)) {
8383 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8384 return CMD_WARNING;
8385 }
8386 ret = str2prefix_rd (argv[1], &prd);
8387 if (! ret)
8388 {
8389 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8390 return CMD_WARNING;
8391 }
8392 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0, BGP_PATH_ALL, use_json (argc, argv));
e3e29b32
LB
8393}
8394
ccbb332a
LB
8395DEFUN (show_bgp_ipv6_safi_rd_route,
8396 show_bgp_ipv6_safi_rd_route_cmd,
8397 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X {json}",
e3e29b32
LB
8398 SHOW_STR
8399 BGP_STR
8400 "Address Family\n"
ccbb332a
LB
8401 "Address Family Modifier\n"
8402 "Address Family Modifier\n"
8403 "Display information for a route distinguisher\n"
8404 "ENCAP Route Distinguisher\n"
8405 "Network in the BGP routing table to display\n")
e3e29b32 8406{
ccbb332a
LB
8407 int ret;
8408 struct prefix_rd prd;
8409 safi_t safi;
8410
8411 if (bgp_parse_safi(argv[0], &safi)) {
8412 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8413 return CMD_WARNING;
8414 }
8415 ret = str2prefix_rd (argv[1], &prd);
8416 if (! ret)
8417 {
8418 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8419 return CMD_WARNING;
8420 }
8421 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0, BGP_PATH_ALL, use_json (argc, argv));
e3e29b32
LB
8422}
8423
ccbb332a
LB
8424
8425DEFUN (show_bgp_ipv4_safi_rd_prefix,
8426 show_bgp_ipv4_safi_rd_prefix_cmd,
8427 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
e3e29b32
LB
8428 SHOW_STR
8429 BGP_STR
ccbb332a
LB
8430 "Address Family\n"
8431 "Address Family Modifier\n"
8432 "Address Family Modifier\n"
e3e29b32 8433 "Display information for a route distinguisher\n"
ccbb332a
LB
8434 "ENCAP Route Distinguisher\n"
8435 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
e3e29b32
LB
8436{
8437 int ret;
8438 struct prefix_rd prd;
ccbb332a 8439 safi_t safi;
e3e29b32 8440
ccbb332a
LB
8441 if (bgp_parse_safi(argv[0], &safi)) {
8442 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8443 return CMD_WARNING;
8444 }
8445
8446 ret = str2prefix_rd (argv[1], &prd);
e3e29b32
LB
8447 if (! ret)
8448 {
8449 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8450 return CMD_WARNING;
8451 }
ccbb332a 8452 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1, BGP_PATH_ALL, use_json (argc, argv));
e3e29b32
LB
8453}
8454
ccbb332a
LB
8455DEFUN (show_bgp_ipv6_safi_rd_prefix,
8456 show_bgp_ipv6_safi_rd_prefix_cmd,
8457 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M {json}",
e3e29b32
LB
8458 SHOW_STR
8459 BGP_STR
8460 "Address Family\n"
ccbb332a
LB
8461 "Address Family Modifier\n"
8462 "Address Family Modifier\n"
e3e29b32 8463 "Display information for a route distinguisher\n"
ccbb332a
LB
8464 "ENCAP Route Distinguisher\n"
8465 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
e3e29b32
LB
8466{
8467 int ret;
8468 struct prefix_rd prd;
ccbb332a 8469 safi_t safi;
e3e29b32 8470
ccbb332a
LB
8471 if (bgp_parse_safi(argv[0], &safi)) {
8472 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8473 return CMD_WARNING;
8474 }
8475
8476 ret = str2prefix_rd (argv[1], &prd);
e3e29b32
LB
8477 if (! ret)
8478 {
8479 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8480 return CMD_WARNING;
8481 }
ccbb332a 8482 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1, BGP_PATH_ALL, use_json (argc, argv));
e3e29b32 8483}
4092b06c 8484
718e3744 8485DEFUN (show_ip_bgp_prefix,
8486 show_ip_bgp_prefix_cmd,
b05a1c8b 8487 "show ip bgp A.B.C.D/M {json}",
718e3744 8488 SHOW_STR
8489 IP_STR
8490 BGP_STR
b05a1c8b
DS
8491 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8492 "JavaScript Object Notation\n")
718e3744 8493{
db7c8528 8494 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
4092b06c
DS
8495}
8496
8497DEFUN (show_ip_bgp_prefix_pathtype,
8498 show_ip_bgp_prefix_pathtype_cmd,
b05a1c8b 8499 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8500 SHOW_STR
8501 IP_STR
8502 BGP_STR
8503 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8504 "Display only the bestpath\n"
b05a1c8b
DS
8505 "Display only multipaths\n"
8506 "JavaScript Object Notation\n")
4092b06c 8507{
db7c8528 8508 u_char uj = use_json(argc, argv);
4092b06c 8509 if (strncmp (argv[1], "b", 1) == 0)
db7c8528 8510 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8511 else
db7c8528 8512 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
718e3744 8513}
8514
8515DEFUN (show_ip_bgp_ipv4_prefix,
8516 show_ip_bgp_ipv4_prefix_cmd,
d02fbbdb 8517 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M {json}",
718e3744 8518 SHOW_STR
8519 IP_STR
8520 BGP_STR
d02fbbdb 8521 BGP_AFI_SAFI_HELP_STR
b05a1c8b
DS
8522 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8523 "JavaScript Object Notation\n")
718e3744 8524{
db7c8528 8525 u_char uj = use_json(argc, argv);
b05a1c8b 8526
ccbb332a
LB
8527 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8528 bgp_vty_safi_from_arg(argv[0]),
8529 NULL, 1, BGP_PATH_ALL, uj);
718e3744 8530}
8531
95cbbd2a
ML
8532ALIAS (show_ip_bgp_ipv4_prefix,
8533 show_bgp_ipv4_safi_prefix_cmd,
d02fbbdb 8534 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M {json}",
95cbbd2a
ML
8535 SHOW_STR
8536 BGP_STR
d02fbbdb 8537 BGP_AFI_SAFI_HELP_STR
b05a1c8b
DS
8538 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8539 "JavaScript Object Notation\n")
95cbbd2a 8540
4092b06c
DS
8541DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
8542 show_ip_bgp_ipv4_prefix_pathtype_cmd,
d02fbbdb 8543 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8544 SHOW_STR
8545 IP_STR
8546 BGP_STR
d02fbbdb 8547 BGP_AFI_SAFI_HELP_STR
4092b06c
DS
8548 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8549 "Display only the bestpath\n"
b05a1c8b
DS
8550 "Display only multipaths\n"
8551 "JavaScript Object Notation\n")
4092b06c 8552{
db7c8528 8553 u_char uj = use_json(argc, argv);
b05a1c8b 8554
ccbb332a
LB
8555 if (strncmp (argv[2], "b", 1) == 0)
8556 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8557 bgp_vty_safi_from_arg(argv[0]),
8558 NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8559 else
ccbb332a
LB
8560 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8561 bgp_vty_safi_from_arg(argv[0]),
8562 NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8563}
8564
8565ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
8566 show_bgp_ipv4_safi_prefix_pathtype_cmd,
d02fbbdb 8567 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8568 SHOW_STR
8569 BGP_STR
d02fbbdb 8570 BGP_AFI_SAFI_HELP_STR
4092b06c
DS
8571 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8572 "Display only the bestpath\n"
b05a1c8b
DS
8573 "Display only multipaths\n"
8574 "JavaScript Object Notation\n")
4092b06c 8575
718e3744 8576
8577DEFUN (show_ip_bgp_view,
8386ac43 8578 show_ip_bgp_instance_cmd,
8579 "show ip bgp " BGP_INSTANCE_CMD " {json}",
718e3744 8580 SHOW_STR
8581 IP_STR
8582 BGP_STR
8386ac43 8583 BGP_INSTANCE_HELP_STR
b05a1c8b 8584 "JavaScript Object Notation\n")
718e3744 8585{
bb46e94f 8586 struct bgp *bgp;
8587
8588 /* BGP structure lookup. */
6aeb9e78 8589 bgp = bgp_lookup_by_name (argv[1]);
bb46e94f 8590 if (bgp == NULL)
8591 {
6aeb9e78 8592 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
bb46e94f 8593 return CMD_WARNING;
8594 }
8595
db7c8528 8596 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
718e3744 8597}
8598
f186de26 8599DEFUN (show_ip_bgp_instance_all,
8600 show_ip_bgp_instance_all_cmd,
8601 "show ip bgp " BGP_INSTANCE_ALL_CMD " {json}",
8602 SHOW_STR
8603 IP_STR
8604 BGP_STR
8605 BGP_INSTANCE_ALL_HELP_STR
8606 "JavaScript Object Notation\n")
8607{
8608 u_char uj = use_json(argc, argv);
8609
8610 bgp_show_all_instances_routes_vty (vty, AFI_IP, SAFI_UNICAST, uj);
8611 return CMD_SUCCESS;
8612}
8613
8386ac43 8614DEFUN (show_ip_bgp_instance_route,
8615 show_ip_bgp_instance_route_cmd,
8616 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D {json}",
718e3744 8617 SHOW_STR
8618 IP_STR
8619 BGP_STR
8386ac43 8620 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8621 "Network in the BGP routing table to display\n"
8622 "JavaScript Object Notation\n")
718e3744 8623{
6aeb9e78 8624 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8625}
8626
8386ac43 8627DEFUN (show_ip_bgp_instance_route_pathtype,
8628 show_ip_bgp_instance_route_pathtype_cmd,
8629 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D (bestpath|multipath) {json}",
50ef26d4 8630 SHOW_STR
8631 IP_STR
8632 BGP_STR
8386ac43 8633 BGP_INSTANCE_HELP_STR
50ef26d4 8634 "Network in the BGP routing table to display\n"
8635 "Display only the bestpath\n"
8636 "Display only multipaths\n"
8637 "JavaScript Object Notation\n")
8638{
8639 u_char uj = use_json(argc, argv);
8640
8641 if (strncmp (argv[3], "b", 1) == 0)
8642 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8643 else
8644 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8645}
8646
8386ac43 8647DEFUN (show_ip_bgp_instance_prefix,
8648 show_ip_bgp_instance_prefix_cmd,
8649 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M {json}",
718e3744 8650 SHOW_STR
8651 IP_STR
8652 BGP_STR
8386ac43 8653 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8654 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8655 "JavaScript Object Notation\n")
718e3744 8656{
6aeb9e78 8657 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8658}
8659
8386ac43 8660DEFUN (show_ip_bgp_instance_prefix_pathtype,
8661 show_ip_bgp_instance_prefix_pathtype_cmd,
8662 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M (bestpath|multipath) {json}",
50ef26d4 8663 SHOW_STR
8664 IP_STR
8665 BGP_STR
8386ac43 8666 BGP_INSTANCE_HELP_STR
50ef26d4 8667 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8668 "Display only the bestpath\n"
8669 "Display only multipaths\n"
8670 "JavaScript Object Notation\n")
8671{
8672 u_char uj = use_json(argc, argv);
8673 if (strncmp (argv[3], "b", 1) == 0)
8674 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8675 else
8676 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8677}
8678
718e3744 8679#ifdef HAVE_IPV6
8680DEFUN (show_bgp,
8681 show_bgp_cmd,
b05a1c8b 8682 "show bgp {json}",
718e3744 8683 SHOW_STR
b05a1c8b
DS
8684 BGP_STR
8685 "JavaScript Object Notation\n")
718e3744 8686{
5a646650 8687 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
db7c8528 8688 NULL, use_json(argc, argv));
718e3744 8689}
8690
8691ALIAS (show_bgp,
8692 show_bgp_ipv6_cmd,
b05a1c8b 8693 "show bgp ipv6 {json}",
718e3744 8694 SHOW_STR
8695 BGP_STR
b05a1c8b
DS
8696 "Address family\n"
8697 "JavaScript Object Notation\n")
718e3744 8698
95cbbd2a
ML
8699DEFUN (show_bgp_ipv6_safi,
8700 show_bgp_ipv6_safi_cmd,
4575cfc3 8701 "show bgp ipv6 (unicast|multicast) {json}",
95cbbd2a
ML
8702 SHOW_STR
8703 BGP_STR
8704 "Address family\n"
4575cfc3
LB
8705 "Address Family modifier\n"
8706 "Address Family modifier\n"
b05a1c8b 8707 "JavaScript Object Notation\n")
47fc97cc 8708{
db7c8528 8709 u_char uj = use_json(argc, argv);
47fc97cc 8710
ccbb332a
LB
8711 return bgp_show (vty, NULL, AFI_IP6,
8712 bgp_vty_safi_from_arg(argv[0]),
8713 bgp_show_type_normal, NULL, uj);
95cbbd2a
ML
8714}
8715
47e9b292
DW
8716static void
8717bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty)
8718{
8719 vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our"
8720 " next release%sPlese use 'show bgp ipv6' instead%s%s",
8721 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8722}
8723
718e3744 8724/* old command */
8725DEFUN (show_ipv6_bgp,
8726 show_ipv6_bgp_cmd,
b05a1c8b 8727 "show ipv6 bgp {json}",
718e3744 8728 SHOW_STR
8729 IP_STR
b05a1c8b
DS
8730 BGP_STR
8731 "JavaScript Object Notation\n")
718e3744 8732{
47e9b292 8733 bgp_show_ipv6_bgp_deprecate_warning(vty);
5a646650 8734 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
db7c8528 8735 NULL, use_json(argc, argv));
718e3744 8736}
8737
8738DEFUN (show_bgp_route,
8739 show_bgp_route_cmd,
b05a1c8b 8740 "show bgp X:X::X:X {json}",
718e3744 8741 SHOW_STR
8742 BGP_STR
b05a1c8b
DS
8743 "Network in the BGP routing table to display\n"
8744 "JavaScript Object Notation\n")
718e3744 8745{
db7c8528 8746 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8747}
8748
95cbbd2a
ML
8749DEFUN (show_bgp_ipv6_safi_route,
8750 show_bgp_ipv6_safi_route_cmd,
d02fbbdb 8751 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X {json}",
95cbbd2a
ML
8752 SHOW_STR
8753 BGP_STR
d02fbbdb 8754 BGP_AFI_SAFI_HELP_STR
b05a1c8b
DS
8755 "Network in the BGP routing table to display\n"
8756 "JavaScript Object Notation\n")
95cbbd2a 8757{
db7c8528 8758 u_char uj = use_json(argc, argv);
95cbbd2a 8759
ccbb332a
LB
8760 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8761 bgp_vty_safi_from_arg(argv[0]),
8762 NULL, 0, BGP_PATH_ALL, uj);
4092b06c
DS
8763}
8764
8765DEFUN (show_bgp_route_pathtype,
8766 show_bgp_route_pathtype_cmd,
b05a1c8b 8767 "show bgp X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8768 SHOW_STR
8769 BGP_STR
8770 "Network in the BGP routing table to display\n"
8771 "Display only the bestpath\n"
b05a1c8b
DS
8772 "Display only multipaths\n"
8773 "JavaScript Object Notation\n")
4092b06c 8774{
db7c8528 8775 u_char uj = use_json(argc, argv);
4092b06c 8776 if (strncmp (argv[1], "b", 1) == 0)
db7c8528 8777 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 8778 else
db7c8528 8779 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8780}
8781
8782ALIAS (show_bgp_route_pathtype,
8783 show_bgp_ipv6_route_pathtype_cmd,
b05a1c8b 8784 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8785 SHOW_STR
8786 BGP_STR
8787 "Address family\n"
8788 "Network in the BGP routing table to display\n"
8789 "Display only the bestpath\n"
b05a1c8b
DS
8790 "Display only multipaths\n"
8791 "JavaScript Object Notation\n")
4092b06c
DS
8792
8793DEFUN (show_bgp_ipv6_safi_route_pathtype,
8794 show_bgp_ipv6_safi_route_pathtype_cmd,
d02fbbdb 8795 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8796 SHOW_STR
8797 BGP_STR
d02fbbdb 8798 BGP_AFI_SAFI_HELP_STR
4092b06c
DS
8799 "Network in the BGP routing table to display\n"
8800 "Display only the bestpath\n"
b05a1c8b
DS
8801 "Display only multipaths\n"
8802 "JavaScript Object Notation\n")
4092b06c 8803{
db7c8528 8804 u_char uj = use_json(argc, argv);
ccbb332a
LB
8805 if (strncmp (argv[2], "b", 1) == 0)
8806 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8807 bgp_vty_safi_from_arg(argv[0]),
8808 NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 8809 else
ccbb332a
LB
8810 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8811 bgp_vty_safi_from_arg(argv[0]),
8812 NULL, 0, BGP_PATH_MULTIPATH, uj);
95cbbd2a
ML
8813}
8814
718e3744 8815/* old command */
8816DEFUN (show_ipv6_bgp_route,
8817 show_ipv6_bgp_route_cmd,
b05a1c8b 8818 "show ipv6 bgp X:X::X:X {json}",
718e3744 8819 SHOW_STR
8820 IP_STR
8821 BGP_STR
b05a1c8b
DS
8822 "Network in the BGP routing table to display\n"
8823 "JavaScript Object Notation\n")
718e3744 8824{
47e9b292 8825 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 8826 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8827}
8828
8829DEFUN (show_bgp_prefix,
8830 show_bgp_prefix_cmd,
b05a1c8b 8831 "show bgp X:X::X:X/M {json}",
718e3744 8832 SHOW_STR
8833 BGP_STR
b05a1c8b
DS
8834 "IPv6 prefix <network>/<length>\n"
8835 "JavaScript Object Notation\n")
718e3744 8836{
db7c8528 8837 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8838}
8839
95cbbd2a
ML
8840DEFUN (show_bgp_ipv6_safi_prefix,
8841 show_bgp_ipv6_safi_prefix_cmd,
d02fbbdb 8842 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X/M {json}",
95cbbd2a
ML
8843 SHOW_STR
8844 BGP_STR
d02fbbdb 8845 BGP_AFI_SAFI_HELP_STR
b05a1c8b
DS
8846 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8847 "JavaScript Object Notation\n")
95cbbd2a 8848{
db7c8528 8849 u_char uj = use_json(argc, argv);
95cbbd2a 8850
ccbb332a
LB
8851 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8852 bgp_vty_safi_from_arg(argv[0]),
8853 NULL, 1, BGP_PATH_ALL, uj);
4092b06c
DS
8854}
8855
8856DEFUN (show_bgp_prefix_pathtype,
8857 show_bgp_prefix_pathtype_cmd,
b05a1c8b 8858 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8859 SHOW_STR
8860 BGP_STR
8861 "IPv6 prefix <network>/<length>\n"
8862 "Display only the bestpath\n"
b05a1c8b
DS
8863 "Display only multipaths\n"
8864 "JavaScript Object Notation\n")
4092b06c 8865{
db7c8528 8866 u_char uj = use_json(argc, argv);
4092b06c 8867 if (strncmp (argv[1], "b", 1) == 0)
db7c8528 8868 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8869 else
db7c8528 8870 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8871}
8872
8873ALIAS (show_bgp_prefix_pathtype,
8874 show_bgp_ipv6_prefix_pathtype_cmd,
b05a1c8b 8875 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8876 SHOW_STR
8877 BGP_STR
8878 "Address family\n"
8879 "IPv6 prefix <network>/<length>\n"
8880 "Display only the bestpath\n"
b05a1c8b
DS
8881 "Display only multipaths\n"
8882 "JavaScript Object Notation\n")
4092b06c
DS
8883
8884DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8885 show_bgp_ipv6_safi_prefix_pathtype_cmd,
d02fbbdb 8886 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8887 SHOW_STR
8888 BGP_STR
d02fbbdb 8889 BGP_AFI_SAFI_HELP_STR
4092b06c
DS
8890 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8891 "Display only the bestpath\n"
b05a1c8b
DS
8892 "Display only multipaths\n"
8893 "JavaScript Object Notation\n")
4092b06c 8894{
db7c8528 8895 u_char uj = use_json(argc, argv);
ccbb332a
LB
8896 if (strncmp (argv[2], "b", 1) == 0)
8897 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8898 bgp_vty_safi_from_arg(argv[0]),
8899 NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8900 else
ccbb332a
LB
8901 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8902 bgp_vty_safi_from_arg(argv[0]), NULL, 1, BGP_PATH_MULTIPATH, uj);
95cbbd2a
ML
8903}
8904
718e3744 8905/* old command */
8906DEFUN (show_ipv6_bgp_prefix,
8907 show_ipv6_bgp_prefix_cmd,
b05a1c8b 8908 "show ipv6 bgp X:X::X:X/M {json}",
718e3744 8909 SHOW_STR
8910 IP_STR
8911 BGP_STR
b05a1c8b
DS
8912 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8913 "JavaScript Object Notation\n")
718e3744 8914{
47e9b292 8915 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 8916 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8917}
8918
bb46e94f 8919DEFUN (show_bgp_view,
8386ac43 8920 show_bgp_instance_cmd,
8921 "show bgp " BGP_INSTANCE_CMD " {json}",
bb46e94f 8922 SHOW_STR
8923 BGP_STR
8386ac43 8924 BGP_INSTANCE_HELP_STR
b05a1c8b 8925 "JavaScript Object Notation\n")
bb46e94f 8926{
8927 struct bgp *bgp;
8928
8929 /* BGP structure lookup. */
6aeb9e78 8930 bgp = bgp_lookup_by_name (argv[1]);
bb46e94f 8931 if (bgp == NULL)
db7c8528 8932 {
6aeb9e78 8933 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
db7c8528
DS
8934 return CMD_WARNING;
8935 }
8936
8937 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
bb46e94f 8938}
8939
f186de26 8940DEFUN (show_bgp_instance_all,
8941 show_bgp_instance_all_cmd,
8942 "show bgp " BGP_INSTANCE_ALL_CMD " {json}",
8943 SHOW_STR
8944 BGP_STR
8945 BGP_INSTANCE_ALL_HELP_STR
8946 "JavaScript Object Notation\n")
8947{
8948 u_char uj = use_json(argc, argv);
8949
8950 bgp_show_all_instances_routes_vty (vty, AFI_IP6, SAFI_UNICAST, uj);
8951 return CMD_SUCCESS;
8952}
8953
bb46e94f 8954ALIAS (show_bgp_view,
8386ac43 8955 show_bgp_instance_ipv6_cmd,
8956 "show bgp " BGP_INSTANCE_CMD " ipv6 {json}",
bb46e94f 8957 SHOW_STR
8958 BGP_STR
8386ac43 8959 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8960 "Address family\n"
8961 "JavaScript Object Notation\n")
bb46e94f 8962
8386ac43 8963DEFUN (show_bgp_instance_route,
8964 show_bgp_instance_route_cmd,
8965 "show bgp " BGP_INSTANCE_CMD " X:X::X:X {json}",
bb46e94f 8966 SHOW_STR
8967 BGP_STR
8386ac43 8968 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8969 "Network in the BGP routing table to display\n"
8970 "JavaScript Object Notation\n")
bb46e94f 8971{
6aeb9e78 8972 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
bb46e94f 8973}
8974
8386ac43 8975ALIAS (show_bgp_instance_route,
8976 show_bgp_instance_ipv6_route_cmd,
8977 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X {json}",
bb46e94f 8978 SHOW_STR
8979 BGP_STR
8386ac43 8980 BGP_INSTANCE_HELP_STR
bb46e94f 8981 "Address family\n"
b05a1c8b
DS
8982 "Network in the BGP routing table to display\n"
8983 "JavaScript Object Notation\n")
bb46e94f 8984
8386ac43 8985DEFUN (show_bgp_instance_route_pathtype,
8986 show_bgp_instance_route_pathtype_cmd,
8987 "show bgp " BGP_INSTANCE_CMD " X:X::X:X (bestpath|multipath) {json}",
50ef26d4 8988 SHOW_STR
8989 BGP_STR
8386ac43 8990 BGP_INSTANCE_HELP_STR
50ef26d4 8991 "Network in the BGP routing table to display\n"
8992 "Display only the bestpath\n"
8993 "Display only multipaths\n"
8994 "JavaScript Object Notation\n")
8995{
8996 u_char uj = use_json(argc, argv);
8997 if (strncmp (argv[3], "b", 1) == 0)
8998 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8999 else
9000 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
9001}
9002
8386ac43 9003ALIAS (show_bgp_instance_route_pathtype,
9004 show_bgp_instance_ipv6_route_pathtype_cmd,
9005 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X (bestpath|multipath) {json}",
50ef26d4 9006 SHOW_STR
9007 BGP_STR
8386ac43 9008 BGP_INSTANCE_HELP_STR
50ef26d4 9009 "Address family\n"
9010 "Network in the BGP routing table to display\n"
9011 "Display only the bestpath\n"
9012 "Display only multipaths\n"
9013 "JavaScript Object Notation\n")
9014
8386ac43 9015DEFUN (show_bgp_instance_prefix,
9016 show_bgp_instance_prefix_cmd,
9017 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M {json}",
bb46e94f 9018 SHOW_STR
9019 BGP_STR
8386ac43 9020 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
9021 "IPv6 prefix <network>/<length>\n"
9022 "JavaScript Object Notation\n")
bb46e94f 9023{
6aeb9e78 9024 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
bb46e94f 9025}
9026
8386ac43 9027ALIAS (show_bgp_instance_prefix,
9028 show_bgp_instance_ipv6_prefix_cmd,
9029 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M {json}",
bb46e94f 9030 SHOW_STR
9031 BGP_STR
8386ac43 9032 BGP_INSTANCE_HELP_STR
bb46e94f 9033 "Address family\n"
b05a1c8b
DS
9034 "IPv6 prefix <network>/<length>\n"
9035 "JavaScript Object Notation\n")
bb46e94f 9036
8386ac43 9037DEFUN (show_bgp_instance_prefix_pathtype,
9038 show_bgp_instance_prefix_pathtype_cmd,
9039 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M (bestpath|multipath) {json}",
50ef26d4 9040 SHOW_STR
9041 BGP_STR
8386ac43 9042 BGP_INSTANCE_HELP_STR
50ef26d4 9043 "IPv6 prefix <network>/<length>\n"
9044 "Display only the bestpath\n"
9045 "Display only multipaths\n"
9046 "JavaScript Object Notation\n")
9047{
9048 u_char uj = use_json(argc, argv);
9049 if (strncmp (argv[3], "b", 1) == 0)
9050 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
9051 else
9052 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
9053}
9054
8386ac43 9055ALIAS (show_bgp_instance_prefix_pathtype,
9056 show_bgp_instance_ipv6_prefix_pathtype_cmd,
9057 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M (bestpath|multipath) {json}",
50ef26d4 9058 SHOW_STR
9059 BGP_STR
8386ac43 9060 BGP_INSTANCE_HELP_STR
50ef26d4 9061 "Address family\n"
9062 "IPv6 prefix <network>/<length>\n"
9063 "Display only the bestpath\n"
9064 "Display only multipaths\n"
9065 "JavaScript Object Notation\n")
9066
8386ac43 9067DEFUN (show_bgp_instance_prefix_list,
9068 show_bgp_instance_prefix_list_cmd,
9069 "show bgp " BGP_INSTANCE_CMD " prefix-list WORD",
50ef26d4 9070 SHOW_STR
9071 BGP_STR
8386ac43 9072 BGP_INSTANCE_HELP_STR
50ef26d4 9073 "Display routes conforming to the prefix-list\n"
9074 "IPv6 prefix-list name\n")
9075{
9076 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9077 bgp_show_type_prefix_list);
9078}
9079
8386ac43 9080ALIAS (show_bgp_instance_prefix_list,
9081 show_bgp_instance_ipv6_prefix_list_cmd,
9082 "show bgp " BGP_INSTANCE_CMD " ipv6 prefix-list WORD",
50ef26d4 9083 SHOW_STR
9084 BGP_STR
8386ac43 9085 BGP_INSTANCE_HELP_STR
50ef26d4 9086 "Address family\n"
9087 "Display routes conforming to the prefix-list\n"
9088 "IPv6 prefix-list name\n")
9089
8386ac43 9090DEFUN (show_bgp_instance_filter_list,
9091 show_bgp_instance_filter_list_cmd,
9092 "show bgp " BGP_INSTANCE_CMD " filter-list WORD",
50ef26d4 9093 SHOW_STR
9094 BGP_STR
8386ac43 9095 BGP_INSTANCE_HELP_STR
50ef26d4 9096 "Display routes conforming to the filter-list\n"
9097 "Regular expression access list name\n")
9098{
9099 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9100 bgp_show_type_filter_list);
9101}
9102
8386ac43 9103ALIAS (show_bgp_instance_filter_list,
9104 show_bgp_instance_ipv6_filter_list_cmd,
9105 "show bgp " BGP_INSTANCE_CMD " ipv6 filter-list WORD",
50ef26d4 9106 SHOW_STR
9107 BGP_STR
8386ac43 9108 BGP_INSTANCE_HELP_STR
50ef26d4 9109 "Address family\n"
9110 "Display routes conforming to the filter-list\n"
9111 "Regular expression access list name\n")
9112
8386ac43 9113DEFUN (show_bgp_instance_route_map,
9114 show_bgp_instance_route_map_cmd,
9115 "show bgp " BGP_INSTANCE_CMD " route-map WORD",
50ef26d4 9116 SHOW_STR
9117 BGP_STR
8386ac43 9118 BGP_INSTANCE_HELP_STR
50ef26d4 9119 "Display routes matching the route-map\n"
9120 "A route-map to match on\n")
9121{
9122 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9123 bgp_show_type_route_map);
9124}
9125
8386ac43 9126ALIAS (show_bgp_instance_route_map,
9127 show_bgp_instance_ipv6_route_map_cmd,
9128 "show bgp " BGP_INSTANCE_CMD " ipv6 route-map WORD",
50ef26d4 9129 SHOW_STR
9130 BGP_STR
8386ac43 9131 BGP_INSTANCE_HELP_STR
50ef26d4 9132 "Address family\n"
9133 "Display routes matching the route-map\n"
9134 "A route-map to match on\n")
9135
8386ac43 9136DEFUN (show_bgp_instance_community_list,
9137 show_bgp_instance_community_list_cmd,
9138 "show bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
50ef26d4 9139 SHOW_STR
9140 BGP_STR
8386ac43 9141 BGP_INSTANCE_HELP_STR
50ef26d4 9142 "Display routes matching the community-list\n"
9143 "community-list number\n"
9144 "community-list name\n")
9145{
9146 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP6, SAFI_UNICAST);
9147}
9148
8386ac43 9149ALIAS (show_bgp_instance_community_list,
9150 show_bgp_instance_ipv6_community_list_cmd,
9151 "show bgp " BGP_INSTANCE_CMD " ipv6 community-list (<1-500>|WORD)",
50ef26d4 9152 SHOW_STR
9153 BGP_STR
8386ac43 9154 BGP_INSTANCE_HELP_STR
50ef26d4 9155 "Address family\n"
9156 "Display routes matching the community-list\n"
9157 "community-list number\n"
9158 "community-list name\n")
9159
8386ac43 9160DEFUN (show_bgp_instance_prefix_longer,
9161 show_bgp_instance_prefix_longer_cmd,
9162 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M longer-prefixes",
50ef26d4 9163 SHOW_STR
9164 BGP_STR
8386ac43 9165 BGP_INSTANCE_HELP_STR
50ef26d4 9166 "IPv6 prefix <network>/<length>\n"
9167 "Display route and more specific routes\n")
9168{
9169 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9170 bgp_show_type_prefix_longer);
9171}
9172
8386ac43 9173ALIAS (show_bgp_instance_prefix_longer,
9174 show_bgp_instance_ipv6_prefix_longer_cmd,
9175 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M longer-prefixes",
50ef26d4 9176 SHOW_STR
9177 BGP_STR
8386ac43 9178 BGP_INSTANCE_HELP_STR
50ef26d4 9179 "Address family\n"
9180 "IPv6 prefix <network>/<length>\n"
9181 "Display route and more specific routes\n")
9182
718e3744 9183/* old command */
9184DEFUN (show_ipv6_mbgp,
9185 show_ipv6_mbgp_cmd,
b05a1c8b 9186 "show ipv6 mbgp {json}",
718e3744 9187 SHOW_STR
9188 IP_STR
b05a1c8b
DS
9189 MBGP_STR
9190 "JavaScript Object Notation\n")
718e3744 9191{
47e9b292 9192 bgp_show_ipv6_bgp_deprecate_warning(vty);
5a646650 9193 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
db7c8528 9194 NULL, use_json(argc, argv));
718e3744 9195}
9196
9197/* old command */
9198DEFUN (show_ipv6_mbgp_route,
9199 show_ipv6_mbgp_route_cmd,
b05a1c8b 9200 "show ipv6 mbgp X:X::X:X {json}",
718e3744 9201 SHOW_STR
9202 IP_STR
9203 MBGP_STR
b05a1c8b
DS
9204 "Network in the MBGP routing table to display\n"
9205 "JavaScript Object Notation\n")
718e3744 9206{
47e9b292 9207 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 9208 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 9209}
9210
9211/* old command */
9212DEFUN (show_ipv6_mbgp_prefix,
9213 show_ipv6_mbgp_prefix_cmd,
b05a1c8b 9214 "show ipv6 mbgp X:X::X:X/M {json}",
718e3744 9215 SHOW_STR
9216 IP_STR
9217 MBGP_STR
b05a1c8b
DS
9218 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9219 "JavaScript Object Notation\n")
718e3744 9220{
47e9b292 9221 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 9222 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 9223}
9224#endif
6b0655a2 9225
718e3744 9226
94f2b392 9227static int
fd79ac91 9228bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
718e3744 9229 safi_t safi, enum bgp_show_type type)
9230{
9231 int i;
9232 struct buffer *b;
9233 char *regstr;
9234 int first;
9235 regex_t *regex;
5a646650 9236 int rc;
718e3744 9237
9238 first = 0;
9239 b = buffer_new (1024);
9240 for (i = 0; i < argc; i++)
9241 {
9242 if (first)
9243 buffer_putc (b, ' ');
9244 else
9245 {
9246 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9247 continue;
9248 first = 1;
9249 }
9250
9251 buffer_putstr (b, argv[i]);
9252 }
9253 buffer_putc (b, '\0');
9254
9255 regstr = buffer_getstr (b);
9256 buffer_free (b);
9257
9258 regex = bgp_regcomp (regstr);
3b8b1855 9259 XFREE(MTYPE_TMP, regstr);
718e3744 9260 if (! regex)
9261 {
9262 vty_out (vty, "Can't compile regexp %s%s", argv[0],
9263 VTY_NEWLINE);
9264 return CMD_WARNING;
9265 }
9266
b05a1c8b 9267 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
5a646650 9268 bgp_regex_free (regex);
9269 return rc;
718e3744 9270}
9271
9272DEFUN (show_ip_bgp_regexp,
9273 show_ip_bgp_regexp_cmd,
9274 "show ip bgp regexp .LINE",
9275 SHOW_STR
9276 IP_STR
9277 BGP_STR
9278 "Display routes matching the AS path regular expression\n"
9279 "A regular-expression to match the BGP AS paths\n")
9280{
9281 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9282 bgp_show_type_regexp);
9283}
9284
9285DEFUN (show_ip_bgp_flap_regexp,
9286 show_ip_bgp_flap_regexp_cmd,
9287 "show ip bgp flap-statistics regexp .LINE",
9288 SHOW_STR
9289 IP_STR
9290 BGP_STR
9291 "Display flap statistics of routes\n"
9292 "Display routes matching the AS path regular expression\n"
9293 "A regular-expression to match the BGP AS paths\n")
9294{
9295 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9296 bgp_show_type_flap_regexp);
9297}
9298
81304aaf
B
9299ALIAS (show_ip_bgp_flap_regexp,
9300 show_ip_bgp_damp_flap_regexp_cmd,
9301 "show ip bgp dampening flap-statistics regexp .LINE",
9302 SHOW_STR
9303 IP_STR
9304 BGP_STR
9305 "Display detailed information about dampening\n"
9306 "Display flap statistics of routes\n"
9307 "Display routes matching the AS path regular expression\n"
9308 "A regular-expression to match the BGP AS paths\n")
9309
718e3744 9310DEFUN (show_ip_bgp_ipv4_regexp,
9311 show_ip_bgp_ipv4_regexp_cmd,
4575cfc3 9312 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
718e3744 9313 SHOW_STR
9314 IP_STR
9315 BGP_STR
9316 "Address family\n"
4575cfc3
LB
9317 "Address Family modifier\n"
9318 "Address Family modifier\n"
718e3744 9319 "Display routes matching the AS path regular expression\n"
9320 "A regular-expression to match the BGP AS paths\n")
9321{
d02fbbdb
LB
9322 safi_t safi;
9323 safi = bgp_vty_safi_from_arg(argv[0]);
9324 return bgp_show_regexp (vty, argc, argv, AFI_IP, safi,
9325 bgp_show_type_regexp);
718e3744 9326}
9327
9328#ifdef HAVE_IPV6
9329DEFUN (show_bgp_regexp,
9330 show_bgp_regexp_cmd,
9331 "show bgp regexp .LINE",
9332 SHOW_STR
9333 BGP_STR
9334 "Display routes matching the AS path regular expression\n"
9335 "A regular-expression to match the BGP AS paths\n")
9336{
9337 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9338 bgp_show_type_regexp);
9339}
9340
9341ALIAS (show_bgp_regexp,
9342 show_bgp_ipv6_regexp_cmd,
9343 "show bgp ipv6 regexp .LINE",
9344 SHOW_STR
9345 BGP_STR
9346 "Address family\n"
9347 "Display routes matching the AS path regular expression\n"
9348 "A regular-expression to match the BGP AS paths\n")
9349
9350/* old command */
9351DEFUN (show_ipv6_bgp_regexp,
9352 show_ipv6_bgp_regexp_cmd,
9353 "show ipv6 bgp regexp .LINE",
9354 SHOW_STR
9355 IP_STR
9356 BGP_STR
9357 "Display routes matching the AS path regular expression\n"
9358 "A regular-expression to match the BGP AS paths\n")
9359{
47e9b292 9360 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 9361 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9362 bgp_show_type_regexp);
9363}
9364
9365/* old command */
9366DEFUN (show_ipv6_mbgp_regexp,
9367 show_ipv6_mbgp_regexp_cmd,
9368 "show ipv6 mbgp regexp .LINE",
9369 SHOW_STR
9370 IP_STR
9371 BGP_STR
9372 "Display routes matching the AS path regular expression\n"
9373 "A regular-expression to match the MBGP AS paths\n")
9374{
47e9b292 9375 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 9376 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
9377 bgp_show_type_regexp);
9378}
9379#endif /* HAVE_IPV6 */
6b0655a2 9380
94f2b392 9381static int
50ef26d4 9382bgp_show_prefix_list (struct vty *vty, const char *name,
9383 const char *prefix_list_str, afi_t afi,
718e3744 9384 safi_t safi, enum bgp_show_type type)
9385{
9386 struct prefix_list *plist;
50ef26d4 9387 struct bgp *bgp = NULL;
9388
9389 if (name && !(bgp = bgp_lookup_by_name(name)))
9390 {
9391 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9392 return CMD_WARNING;
9393 }
718e3744 9394
9395 plist = prefix_list_lookup (afi, prefix_list_str);
9396 if (plist == NULL)
9397 {
9398 vty_out (vty, "%% %s is not a valid prefix-list name%s",
9399 prefix_list_str, VTY_NEWLINE);
9400 return CMD_WARNING;
9401 }
9402
50ef26d4 9403 return bgp_show (vty, bgp, afi, safi, type, plist, 0);
718e3744 9404}
9405
9406DEFUN (show_ip_bgp_prefix_list,
9407 show_ip_bgp_prefix_list_cmd,
9408 "show ip bgp prefix-list WORD",
9409 SHOW_STR
9410 IP_STR
9411 BGP_STR
9412 "Display routes conforming to the prefix-list\n"
9413 "IP prefix-list name\n")
9414{
50ef26d4 9415 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9416 bgp_show_type_prefix_list);
9417}
9418
8386ac43 9419DEFUN (show_ip_bgp_instance_prefix_list,
9420 show_ip_bgp_instance_prefix_list_cmd,
9421 "show ip bgp " BGP_INSTANCE_CMD " prefix-list WORD",
50ef26d4 9422 SHOW_STR
9423 IP_STR
9424 BGP_STR
8386ac43 9425 BGP_INSTANCE_HELP_STR
50ef26d4 9426 "Display routes conforming to the prefix-list\n"
9427 "IP prefix-list name\n")
9428{
9429 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
718e3744 9430 bgp_show_type_prefix_list);
9431}
9432
9433DEFUN (show_ip_bgp_flap_prefix_list,
9434 show_ip_bgp_flap_prefix_list_cmd,
9435 "show ip bgp flap-statistics prefix-list WORD",
9436 SHOW_STR
9437 IP_STR
9438 BGP_STR
9439 "Display flap statistics of routes\n"
9440 "Display routes conforming to the prefix-list\n"
9441 "IP prefix-list name\n")
9442{
50ef26d4 9443 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 9444 bgp_show_type_flap_prefix_list);
9445}
9446
81304aaf
B
9447ALIAS (show_ip_bgp_flap_prefix_list,
9448 show_ip_bgp_damp_flap_prefix_list_cmd,
9449 "show ip bgp dampening flap-statistics prefix-list WORD",
9450 SHOW_STR
9451 IP_STR
9452 BGP_STR
9453 "Display detailed information about dampening\n"
9454 "Display flap statistics of routes\n"
9455 "Display routes conforming to the prefix-list\n"
9456 "IP prefix-list name\n")
9457
718e3744 9458DEFUN (show_ip_bgp_ipv4_prefix_list,
9459 show_ip_bgp_ipv4_prefix_list_cmd,
4575cfc3 9460 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
718e3744 9461 SHOW_STR
9462 IP_STR
9463 BGP_STR
9464 "Address family\n"
4575cfc3
LB
9465 "Address Family modifier\n"
9466 "Address Family modifier\n"
718e3744 9467 "Display routes conforming to the prefix-list\n"
9468 "IP prefix-list name\n")
9469{
d02fbbdb
LB
9470 safi_t safi;
9471 safi = bgp_vty_safi_from_arg(argv[0]);
9472 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, safi,
9473 bgp_show_type_prefix_list);
718e3744 9474}
9475
9476#ifdef HAVE_IPV6
9477DEFUN (show_bgp_prefix_list,
9478 show_bgp_prefix_list_cmd,
9479 "show bgp prefix-list WORD",
9480 SHOW_STR
9481 BGP_STR
9482 "Display routes conforming to the prefix-list\n"
9483 "IPv6 prefix-list name\n")
9484{
50ef26d4 9485 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 9486 bgp_show_type_prefix_list);
9487}
9488
9489ALIAS (show_bgp_prefix_list,
9490 show_bgp_ipv6_prefix_list_cmd,
9491 "show bgp ipv6 prefix-list WORD",
9492 SHOW_STR
9493 BGP_STR
9494 "Address family\n"
9495 "Display routes conforming to the prefix-list\n"
9496 "IPv6 prefix-list name\n")
9497
9498/* old command */
9499DEFUN (show_ipv6_bgp_prefix_list,
9500 show_ipv6_bgp_prefix_list_cmd,
9501 "show ipv6 bgp prefix-list WORD",
9502 SHOW_STR
9503 IPV6_STR
9504 BGP_STR
9505 "Display routes matching the prefix-list\n"
9506 "IPv6 prefix-list name\n")
9507{
47e9b292 9508 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 9509 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 9510 bgp_show_type_prefix_list);
9511}
9512
9513/* old command */
9514DEFUN (show_ipv6_mbgp_prefix_list,
9515 show_ipv6_mbgp_prefix_list_cmd,
9516 "show ipv6 mbgp prefix-list WORD",
9517 SHOW_STR
9518 IPV6_STR
9519 MBGP_STR
9520 "Display routes matching the prefix-list\n"
9521 "IPv6 prefix-list name\n")
9522{
47e9b292 9523 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 9524 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
718e3744 9525 bgp_show_type_prefix_list);
9526}
9527#endif /* HAVE_IPV6 */
6b0655a2 9528
94f2b392 9529static int
50ef26d4 9530bgp_show_filter_list (struct vty *vty, const char *name,
9531 const char *filter, afi_t afi,
718e3744 9532 safi_t safi, enum bgp_show_type type)
9533{
9534 struct as_list *as_list;
50ef26d4 9535 struct bgp *bgp = NULL;
9536
9537 if (name && !(bgp = bgp_lookup_by_name(name)))
9538 {
9539 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9540 return CMD_WARNING;
9541 }
718e3744 9542
9543 as_list = as_list_lookup (filter);
9544 if (as_list == NULL)
9545 {
9546 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
9547 return CMD_WARNING;
9548 }
9549
50ef26d4 9550 return bgp_show (vty, bgp, afi, safi, type, as_list, 0);
718e3744 9551}
9552
9553DEFUN (show_ip_bgp_filter_list,
9554 show_ip_bgp_filter_list_cmd,
9555 "show ip bgp filter-list WORD",
9556 SHOW_STR
9557 IP_STR
9558 BGP_STR
9559 "Display routes conforming to the filter-list\n"
9560 "Regular expression access list name\n")
9561{
50ef26d4 9562 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9563 bgp_show_type_filter_list);
9564}
9565
8386ac43 9566DEFUN (show_ip_bgp_instance_filter_list,
9567 show_ip_bgp_instance_filter_list_cmd,
9568 "show ip bgp " BGP_INSTANCE_CMD " filter-list WORD",
50ef26d4 9569 SHOW_STR
9570 IP_STR
9571 BGP_STR
8386ac43 9572 BGP_INSTANCE_HELP_STR
50ef26d4 9573 "Display routes conforming to the filter-list\n"
9574 "Regular expression access list name\n")
9575{
9576 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
718e3744 9577 bgp_show_type_filter_list);
9578}
9579
9580DEFUN (show_ip_bgp_flap_filter_list,
9581 show_ip_bgp_flap_filter_list_cmd,
9582 "show ip bgp flap-statistics filter-list WORD",
9583 SHOW_STR
9584 IP_STR
9585 BGP_STR
9586 "Display flap statistics of routes\n"
9587 "Display routes conforming to the filter-list\n"
9588 "Regular expression access list name\n")
9589{
50ef26d4 9590 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 9591 bgp_show_type_flap_filter_list);
9592}
9593
81304aaf
B
9594ALIAS (show_ip_bgp_flap_filter_list,
9595 show_ip_bgp_damp_flap_filter_list_cmd,
9596 "show ip bgp dampening flap-statistics filter-list WORD",
9597 SHOW_STR
9598 IP_STR
9599 BGP_STR
9600 "Display detailed information about dampening\n"
9601 "Display flap statistics of routes\n"
9602 "Display routes conforming to the filter-list\n"
9603 "Regular expression access list name\n")
9604
718e3744 9605DEFUN (show_ip_bgp_ipv4_filter_list,
9606 show_ip_bgp_ipv4_filter_list_cmd,
4575cfc3 9607 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
718e3744 9608 SHOW_STR
9609 IP_STR
9610 BGP_STR
9611 "Address family\n"
4575cfc3
LB
9612 "Address Family modifier\n"
9613 "Address Family modifier\n"
718e3744 9614 "Display routes conforming to the filter-list\n"
9615 "Regular expression access list name\n")
9616{
d02fbbdb
LB
9617 safi_t safi;
9618 safi = bgp_vty_safi_from_arg(argv[0]);
9619 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, safi,
9620 bgp_show_type_filter_list);
718e3744 9621}
9622
9623#ifdef HAVE_IPV6
9624DEFUN (show_bgp_filter_list,
9625 show_bgp_filter_list_cmd,
9626 "show bgp filter-list WORD",
9627 SHOW_STR
9628 BGP_STR
9629 "Display routes conforming to the filter-list\n"
9630 "Regular expression access list name\n")
9631{
50ef26d4 9632 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 9633 bgp_show_type_filter_list);
9634}
9635
9636ALIAS (show_bgp_filter_list,
9637 show_bgp_ipv6_filter_list_cmd,
9638 "show bgp ipv6 filter-list WORD",
9639 SHOW_STR
9640 BGP_STR
9641 "Address family\n"
9642 "Display routes conforming to the filter-list\n"
9643 "Regular expression access list name\n")
9644
9645/* old command */
9646DEFUN (show_ipv6_bgp_filter_list,
9647 show_ipv6_bgp_filter_list_cmd,
9648 "show ipv6 bgp filter-list WORD",
9649 SHOW_STR
9650 IPV6_STR
9651 BGP_STR
9652 "Display routes conforming to the filter-list\n"
9653 "Regular expression access list name\n")
9654{
47e9b292 9655 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 9656 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 9657 bgp_show_type_filter_list);
9658}
9659
9660/* old command */
9661DEFUN (show_ipv6_mbgp_filter_list,
9662 show_ipv6_mbgp_filter_list_cmd,
9663 "show ipv6 mbgp filter-list WORD",
9664 SHOW_STR
9665 IPV6_STR
9666 MBGP_STR
9667 "Display routes conforming to the filter-list\n"
9668 "Regular expression access list name\n")
9669{
47e9b292 9670 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 9671 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
718e3744 9672 bgp_show_type_filter_list);
9673}
9674#endif /* HAVE_IPV6 */
6b0655a2 9675
81304aaf
B
9676DEFUN (show_ip_bgp_dampening_info,
9677 show_ip_bgp_dampening_params_cmd,
9678 "show ip bgp dampening parameters",
9679 SHOW_STR
9680 IP_STR
9681 BGP_STR
9682 "Display detailed information about dampening\n"
9683 "Display detail of configured dampening parameters\n")
9684{
9685 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
9686}
9687
58a90275
B
9688
9689DEFUN (show_ip_bgp_ipv4_dampening_parameters,
9690 show_ip_bgp_ipv4_dampening_parameters_cmd,
4575cfc3 9691 "show ip bgp ipv4 (unicast|multicast) dampening parameters",
58a90275
B
9692 SHOW_STR
9693 IP_STR
9694 BGP_STR
9695 "Address family\n"
4575cfc3
LB
9696 "Address Family modifier\n"
9697 "Address Family modifier\n"
58a90275
B
9698 "Display detailed information about dampening\n"
9699 "Display detail of configured dampening parameters\n")
9700{
d02fbbdb
LB
9701 safi_t safi;
9702 safi = bgp_vty_safi_from_arg(argv[0]);
9703 return bgp_show_dampening_parameters (vty, AFI_IP, safi);
58a90275
B
9704}
9705
9706
9707DEFUN (show_ip_bgp_ipv4_dampening_flap_stats,
9708 show_ip_bgp_ipv4_dampening_flap_stats_cmd,
4575cfc3 9709 "show ip bgp ipv4 (unicast|multicast) dampening flap-statistics",
58a90275
B
9710 SHOW_STR
9711 IP_STR
9712 BGP_STR
9713 "Address family\n"
4575cfc3
LB
9714 "Address Family modifier\n"
9715 "Address Family modifier\n"
58a90275
B
9716 "Display detailed information about dampening\n"
9717 "Display flap statistics of routes\n")
9718{
d02fbbdb
LB
9719 safi_t safi;
9720 safi = bgp_vty_safi_from_arg(argv[0]);
9721 return bgp_show (vty, NULL, AFI_IP, safi,
58a90275 9722 bgp_show_type_flap_statistics, NULL, 0);
58a90275
B
9723}
9724
9725DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths,
9726 show_ip_bgp_ipv4_dampening_dampd_paths_cmd,
4575cfc3 9727 "show ip bgp ipv4 (unicast|multicast) dampening dampened-paths",
58a90275
B
9728 SHOW_STR
9729 IP_STR
9730 BGP_STR
9731 "Address family\n"
4575cfc3
LB
9732 "Address Family modifier\n"
9733 "Address Family modifier\n"
58a90275
B
9734 "Display detailed information about dampening\n"
9735 "Display paths suppressed due to dampening\n")
9736{
d02fbbdb
LB
9737 safi_t safi;
9738 safi = bgp_vty_safi_from_arg(argv[0]);
9739 return bgp_show (vty, NULL, AFI_IP, safi,
58a90275 9740 bgp_show_type_dampend_paths, NULL, 0);
58a90275
B
9741}
9742
94f2b392 9743static int
50ef26d4 9744bgp_show_route_map (struct vty *vty, const char *name,
9745 const char *rmap_str, afi_t afi,
718e3744 9746 safi_t safi, enum bgp_show_type type)
9747{
9748 struct route_map *rmap;
50ef26d4 9749 struct bgp *bgp = NULL;
9750
9751 if (name && !(bgp = bgp_lookup_by_name(name)))
9752 {
9753 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9754 return CMD_WARNING;
9755 }
718e3744 9756
9757 rmap = route_map_lookup_by_name (rmap_str);
9758 if (! rmap)
9759 {
9760 vty_out (vty, "%% %s is not a valid route-map name%s",
9761 rmap_str, VTY_NEWLINE);
9762 return CMD_WARNING;
9763 }
9764
50ef26d4 9765 return bgp_show (vty, bgp, afi, safi, type, rmap, 0);
718e3744 9766}
9767
9768DEFUN (show_ip_bgp_route_map,
9769 show_ip_bgp_route_map_cmd,
9770 "show ip bgp route-map WORD",
9771 SHOW_STR
9772 IP_STR
9773 BGP_STR
9774 "Display routes matching the route-map\n"
9775 "A route-map to match on\n")
9776{
50ef26d4 9777 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9778 bgp_show_type_route_map);
9779}
9780
8386ac43 9781DEFUN (show_ip_bgp_instance_route_map,
9782 show_ip_bgp_instance_route_map_cmd,
9783 "show ip bgp " BGP_INSTANCE_CMD " route-map WORD",
50ef26d4 9784 SHOW_STR
9785 IP_STR
9786 BGP_STR
8386ac43 9787 BGP_INSTANCE_HELP_STR
50ef26d4 9788 "Display routes matching the route-map\n"
9789 "A route-map to match on\n")
9790{
9791 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
718e3744 9792 bgp_show_type_route_map);
9793}
9794
9795DEFUN (show_ip_bgp_flap_route_map,
9796 show_ip_bgp_flap_route_map_cmd,
9797 "show ip bgp flap-statistics route-map WORD",
9798 SHOW_STR
9799 IP_STR
9800 BGP_STR
9801 "Display flap statistics of routes\n"
9802 "Display routes matching the route-map\n"
9803 "A route-map to match on\n")
9804{
50ef26d4 9805 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 9806 bgp_show_type_flap_route_map);
9807}
9808
81304aaf
B
9809ALIAS (show_ip_bgp_flap_route_map,
9810 show_ip_bgp_damp_flap_route_map_cmd,
9811 "show ip bgp dampening flap-statistics route-map WORD",
9812 SHOW_STR
9813 IP_STR
9814 BGP_STR
9815 "Display detailed information about dampening\n"
9816 "Display flap statistics of routes\n"
9817 "Display routes matching the route-map\n"
9818 "A route-map to match on\n")
9819
718e3744 9820DEFUN (show_ip_bgp_ipv4_route_map,
9821 show_ip_bgp_ipv4_route_map_cmd,
4575cfc3 9822 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
718e3744 9823 SHOW_STR
9824 IP_STR
9825 BGP_STR
9826 "Address family\n"
4575cfc3
LB
9827 "Address Family modifier\n"
9828 "Address Family modifier\n"
718e3744 9829 "Display routes matching the route-map\n"
9830 "A route-map to match on\n")
9831{
d02fbbdb
LB
9832 safi_t safi;
9833 safi = bgp_vty_safi_from_arg(argv[0]);
9834 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, safi,
9835 bgp_show_type_route_map);
718e3744 9836}
9837
9838DEFUN (show_bgp_route_map,
9839 show_bgp_route_map_cmd,
9840 "show bgp route-map WORD",
9841 SHOW_STR
9842 BGP_STR
9843 "Display routes matching the route-map\n"
9844 "A route-map to match on\n")
9845{
50ef26d4 9846 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 9847 bgp_show_type_route_map);
9848}
9849
9850ALIAS (show_bgp_route_map,
9851 show_bgp_ipv6_route_map_cmd,
9852 "show bgp ipv6 route-map WORD",
9853 SHOW_STR
9854 BGP_STR
9855 "Address family\n"
9856 "Display routes matching the route-map\n"
9857 "A route-map to match on\n")
6b0655a2 9858
718e3744 9859DEFUN (show_ip_bgp_cidr_only,
9860 show_ip_bgp_cidr_only_cmd,
9861 "show ip bgp cidr-only",
9862 SHOW_STR
9863 IP_STR
9864 BGP_STR
9865 "Display only routes with non-natural netmasks\n")
9866{
9867 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9868 bgp_show_type_cidr_only, NULL, 0);
718e3744 9869}
9870
9871DEFUN (show_ip_bgp_flap_cidr_only,
9872 show_ip_bgp_flap_cidr_only_cmd,
9873 "show ip bgp flap-statistics cidr-only",
9874 SHOW_STR
9875 IP_STR
9876 BGP_STR
9877 "Display flap statistics of routes\n"
9878 "Display only routes with non-natural netmasks\n")
9879{
9880 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9881 bgp_show_type_flap_cidr_only, NULL, 0);
718e3744 9882}
9883
81304aaf
B
9884ALIAS (show_ip_bgp_flap_cidr_only,
9885 show_ip_bgp_damp_flap_cidr_only_cmd,
9886 "show ip bgp dampening flap-statistics cidr-only",
9887 SHOW_STR
9888 IP_STR
9889 BGP_STR
9890 "Display detailed information about dampening\n"
9891 "Display flap statistics of routes\n"
9892 "Display only routes with non-natural netmasks\n")
9893
718e3744 9894DEFUN (show_ip_bgp_ipv4_cidr_only,
9895 show_ip_bgp_ipv4_cidr_only_cmd,
4575cfc3 9896 "show ip bgp ipv4 (unicast|multicast) cidr-only",
718e3744 9897 SHOW_STR
9898 IP_STR
9899 BGP_STR
9900 "Address family\n"
4575cfc3
LB
9901 "Address Family modifier\n"
9902 "Address Family modifier\n"
718e3744 9903 "Display only routes with non-natural netmasks\n")
9904{
d02fbbdb
LB
9905 safi_t safi;
9906 safi = bgp_vty_safi_from_arg(argv[0]);
9907 return bgp_show (vty, NULL, AFI_IP, safi,
9908 bgp_show_type_cidr_only, NULL, 0);
718e3744 9909}
6b0655a2 9910
718e3744 9911DEFUN (show_ip_bgp_community_all,
9912 show_ip_bgp_community_all_cmd,
9913 "show ip bgp community",
9914 SHOW_STR
9915 IP_STR
9916 BGP_STR
9917 "Display routes matching the communities\n")
9918{
9919 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9920 bgp_show_type_community_all, NULL, 0);
718e3744 9921}
9922
9923DEFUN (show_ip_bgp_ipv4_community_all,
9924 show_ip_bgp_ipv4_community_all_cmd,
4575cfc3 9925 "show ip bgp ipv4 (unicast|multicast) community",
718e3744 9926 SHOW_STR
9927 IP_STR
9928 BGP_STR
9929 "Address family\n"
4575cfc3
LB
9930 "Address Family modifier\n"
9931 "Address Family modifier\n"
718e3744 9932 "Display routes matching the communities\n")
9933{
d02fbbdb
LB
9934 safi_t safi;
9935 safi = bgp_vty_safi_from_arg(argv[0]);
9936 return bgp_show (vty, NULL, AFI_IP, safi,
9937 bgp_show_type_community_all, NULL, 0);
718e3744 9938}
9939
9940#ifdef HAVE_IPV6
9941DEFUN (show_bgp_community_all,
9942 show_bgp_community_all_cmd,
9943 "show bgp community",
9944 SHOW_STR
9945 BGP_STR
9946 "Display routes matching the communities\n")
9947{
9948 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 9949 bgp_show_type_community_all, NULL, 0);
718e3744 9950}
9951
9952ALIAS (show_bgp_community_all,
9953 show_bgp_ipv6_community_all_cmd,
9954 "show bgp ipv6 community",
9955 SHOW_STR
9956 BGP_STR
9957 "Address family\n"
9958 "Display routes matching the communities\n")
9959
9960/* old command */
9961DEFUN (show_ipv6_bgp_community_all,
9962 show_ipv6_bgp_community_all_cmd,
9963 "show ipv6 bgp community",
9964 SHOW_STR
9965 IPV6_STR
9966 BGP_STR
9967 "Display routes matching the communities\n")
9968{
47e9b292 9969 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 9970 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 9971 bgp_show_type_community_all, NULL, 0);
718e3744 9972}
9973
9974/* old command */
9975DEFUN (show_ipv6_mbgp_community_all,
9976 show_ipv6_mbgp_community_all_cmd,
9977 "show ipv6 mbgp community",
9978 SHOW_STR
9979 IPV6_STR
9980 MBGP_STR
9981 "Display routes matching the communities\n")
9982{
47e9b292 9983 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 9984 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
b05a1c8b 9985 bgp_show_type_community_all, NULL, 0);
718e3744 9986}
9987#endif /* HAVE_IPV6 */
6b0655a2 9988
94f2b392 9989static int
95cbbd2a
ML
9990bgp_show_community (struct vty *vty, const char *view_name, int argc,
9991 const char **argv, int exact, afi_t afi, safi_t safi)
718e3744 9992{
9993 struct community *com;
9994 struct buffer *b;
95cbbd2a 9995 struct bgp *bgp;
718e3744 9996 int i;
9997 char *str;
9998 int first = 0;
9999
95cbbd2a
ML
10000 /* BGP structure lookup */
10001 if (view_name)
10002 {
10003 bgp = bgp_lookup_by_name (view_name);
10004 if (bgp == NULL)
10005 {
6aeb9e78 10006 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
95cbbd2a
ML
10007 return CMD_WARNING;
10008 }
10009 }
10010 else
10011 {
10012 bgp = bgp_get_default ();
10013 if (bgp == NULL)
10014 {
10015 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10016 return CMD_WARNING;
10017 }
10018 }
10019
718e3744 10020 b = buffer_new (1024);
10021 for (i = 0; i < argc; i++)
10022 {
10023 if (first)
10024 buffer_putc (b, ' ');
10025 else
10026 {
10027 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
10028 continue;
10029 first = 1;
10030 }
10031
10032 buffer_putstr (b, argv[i]);
10033 }
10034 buffer_putc (b, '\0');
10035
10036 str = buffer_getstr (b);
10037 buffer_free (b);
10038
10039 com = community_str2com (str);
3b8b1855 10040 XFREE (MTYPE_TMP, str);
718e3744 10041 if (! com)
10042 {
10043 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
10044 return CMD_WARNING;
10045 }
10046
95cbbd2a 10047 return bgp_show (vty, bgp, afi, safi,
5a646650 10048 (exact ? bgp_show_type_community_exact :
b05a1c8b 10049 bgp_show_type_community), com, 0);
718e3744 10050}
10051
10052DEFUN (show_ip_bgp_community,
10053 show_ip_bgp_community_cmd,
10054 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
10055 SHOW_STR
10056 IP_STR
10057 BGP_STR
10058 "Display routes matching the communities\n"
859d388e 10059 COMMUNITY_AANN_STR
718e3744 10060 "Do not send outside local AS (well-known community)\n"
10061 "Do not advertise to any peer (well-known community)\n"
10062 "Do not export to next AS (well-known community)\n")
10063{
95cbbd2a 10064 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 10065}
10066
10067ALIAS (show_ip_bgp_community,
10068 show_ip_bgp_community2_cmd,
10069 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10070 SHOW_STR
10071 IP_STR
10072 BGP_STR
10073 "Display routes matching the communities\n"
859d388e 10074 COMMUNITY_AANN_STR
718e3744 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"
859d388e 10078 COMMUNITY_AANN_STR
718e3744 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
10083ALIAS (show_ip_bgp_community,
10084 show_ip_bgp_community3_cmd,
10085 "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)",
10086 SHOW_STR
10087 IP_STR
10088 BGP_STR
10089 "Display routes matching the communities\n"
859d388e 10090 COMMUNITY_AANN_STR
718e3744 10091 "Do not send outside local AS (well-known community)\n"
10092 "Do not advertise to any peer (well-known community)\n"
10093 "Do not export to next AS (well-known community)\n"
859d388e 10094 COMMUNITY_AANN_STR
718e3744 10095 "Do not send outside local AS (well-known community)\n"
10096 "Do not advertise to any peer (well-known community)\n"
10097 "Do not export to next AS (well-known community)\n"
859d388e 10098 COMMUNITY_AANN_STR
718e3744 10099 "Do not send outside local AS (well-known community)\n"
10100 "Do not advertise to any peer (well-known community)\n"
10101 "Do not export to next AS (well-known community)\n")
10102
10103ALIAS (show_ip_bgp_community,
10104 show_ip_bgp_community4_cmd,
10105 "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)",
10106 SHOW_STR
10107 IP_STR
10108 BGP_STR
10109 "Display routes matching the communities\n"
859d388e 10110 COMMUNITY_AANN_STR
718e3744 10111 "Do not send outside local AS (well-known community)\n"
10112 "Do not advertise to any peer (well-known community)\n"
10113 "Do not export to next AS (well-known community)\n"
859d388e 10114 COMMUNITY_AANN_STR
718e3744 10115 "Do not send outside local AS (well-known community)\n"
10116 "Do not advertise to any peer (well-known community)\n"
10117 "Do not export to next AS (well-known community)\n"
859d388e 10118 COMMUNITY_AANN_STR
718e3744 10119 "Do not send outside local AS (well-known community)\n"
10120 "Do not advertise to any peer (well-known community)\n"
10121 "Do not export to next AS (well-known community)\n"
859d388e 10122 COMMUNITY_AANN_STR
718e3744 10123 "Do not send outside local AS (well-known community)\n"
10124 "Do not advertise to any peer (well-known community)\n"
10125 "Do not export to next AS (well-known community)\n")
10126
10127DEFUN (show_ip_bgp_ipv4_community,
10128 show_ip_bgp_ipv4_community_cmd,
4575cfc3 10129 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
718e3744 10130 SHOW_STR
10131 IP_STR
10132 BGP_STR
10133 "Address family\n"
4575cfc3
LB
10134 "Address Family modifier\n"
10135 "Address Family modifier\n"
718e3744 10136 "Display routes matching the communities\n"
859d388e 10137 COMMUNITY_AANN_STR
718e3744 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{
d02fbbdb
LB
10142 safi_t safi;
10143 safi = bgp_vty_safi_from_arg(argv[0]);
10144 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, safi);
718e3744 10145}
10146
10147ALIAS (show_ip_bgp_ipv4_community,
10148 show_ip_bgp_ipv4_community2_cmd,
4575cfc3 10149 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
718e3744 10150 SHOW_STR
10151 IP_STR
10152 BGP_STR
10153 "Address family\n"
4575cfc3
LB
10154 "Address Family modifier\n"
10155 "Address Family modifier\n"
718e3744 10156 "Display routes matching the communities\n"
859d388e 10157 COMMUNITY_AANN_STR
718e3744 10158 "Do not send outside local AS (well-known community)\n"
10159 "Do not advertise to any peer (well-known community)\n"
10160 "Do not export to next AS (well-known community)\n"
859d388e 10161 COMMUNITY_AANN_STR
718e3744 10162 "Do not send outside local AS (well-known community)\n"
10163 "Do not advertise to any peer (well-known community)\n"
10164 "Do not export to next AS (well-known community)\n")
10165
10166ALIAS (show_ip_bgp_ipv4_community,
10167 show_ip_bgp_ipv4_community3_cmd,
4575cfc3 10168 "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)",
718e3744 10169 SHOW_STR
10170 IP_STR
10171 BGP_STR
10172 "Address family\n"
4575cfc3
LB
10173 "Address Family modifier\n"
10174 "Address Family modifier\n"
718e3744 10175 "Display routes matching the communities\n"
859d388e 10176 COMMUNITY_AANN_STR
718e3744 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"
859d388e 10180 COMMUNITY_AANN_STR
718e3744 10181 "Do not send outside local AS (well-known community)\n"
10182 "Do not advertise to any peer (well-known community)\n"
10183 "Do not export to next AS (well-known community)\n"
859d388e 10184 COMMUNITY_AANN_STR
718e3744 10185 "Do not send outside local AS (well-known community)\n"
10186 "Do not advertise to any peer (well-known community)\n"
10187 "Do not export to next AS (well-known community)\n")
10188
10189ALIAS (show_ip_bgp_ipv4_community,
10190 show_ip_bgp_ipv4_community4_cmd,
4575cfc3 10191 "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)",
718e3744 10192 SHOW_STR
10193 IP_STR
10194 BGP_STR
10195 "Address family\n"
4575cfc3
LB
10196 "Address Family modifier\n"
10197 "Address Family modifier\n"
718e3744 10198 "Display routes matching the communities\n"
859d388e 10199 COMMUNITY_AANN_STR
718e3744 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"
859d388e 10203 COMMUNITY_AANN_STR
718e3744 10204 "Do not send outside local AS (well-known community)\n"
10205 "Do not advertise to any peer (well-known community)\n"
10206 "Do not export to next AS (well-known community)\n"
859d388e 10207 COMMUNITY_AANN_STR
718e3744 10208 "Do not send outside local AS (well-known community)\n"
10209 "Do not advertise to any peer (well-known community)\n"
10210 "Do not export to next AS (well-known community)\n"
859d388e 10211 COMMUNITY_AANN_STR
718e3744 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
8386ac43 10216DEFUN (show_bgp_instance_afi_safi_community_all,
10217 show_bgp_instance_afi_safi_community_all_cmd,
4575cfc3 10218 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community",
95cbbd2a
ML
10219 SHOW_STR
10220 BGP_STR
8386ac43 10221 BGP_INSTANCE_HELP_STR
4575cfc3
LB
10222 "Address family\n"
10223 "Address family\n"
10224 "Address Family modifier\n"
10225 "Address Family modifier\n"
2b00515a 10226 "Display routes matching the communities\n")
95cbbd2a
ML
10227{
10228 int afi;
10229 int safi;
10230 struct bgp *bgp;
10231
10232 /* BGP structure lookup. */
6aeb9e78 10233 bgp = bgp_lookup_by_name (argv[1]);
95cbbd2a
ML
10234 if (bgp == NULL)
10235 {
6aeb9e78 10236 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
95cbbd2a
ML
10237 return CMD_WARNING;
10238 }
10239
d02fbbdb
LB
10240 afi = bgp_vty_safi_from_arg(argv[2]);
10241 safi = bgp_vty_safi_from_arg(argv[3]);
b05a1c8b 10242 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
95cbbd2a
ML
10243}
10244
8386ac43 10245DEFUN (show_bgp_instance_afi_safi_community,
10246 show_bgp_instance_afi_safi_community_cmd,
4575cfc3 10247 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
95cbbd2a
ML
10248 SHOW_STR
10249 BGP_STR
8386ac43 10250 BGP_INSTANCE_HELP_STR
95cbbd2a 10251 "Address family\n"
95cbbd2a 10252 "Address family\n"
95cbbd2a
ML
10253 "Address family modifier\n"
10254 "Address family modifier\n"
10255 "Display routes matching the communities\n"
859d388e 10256 COMMUNITY_AANN_STR
95cbbd2a
ML
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 int afi;
10262 int safi;
10263
d02fbbdb
LB
10264 afi = bgp_vty_safi_from_arg(argv[2]);
10265 safi = bgp_vty_safi_from_arg(argv[3]);
6aeb9e78 10266 return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi);
95cbbd2a
ML
10267}
10268
8386ac43 10269ALIAS (show_bgp_instance_afi_safi_community,
10270 show_bgp_instance_afi_safi_community2_cmd,
4575cfc3 10271 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
95cbbd2a
ML
10272 SHOW_STR
10273 BGP_STR
8386ac43 10274 BGP_INSTANCE_HELP_STR
95cbbd2a 10275 "Address family\n"
95cbbd2a 10276 "Address family\n"
95cbbd2a
ML
10277 "Address family modifier\n"
10278 "Address family modifier\n"
10279 "Display routes matching the communities\n"
859d388e 10280 COMMUNITY_AANN_STR
95cbbd2a
ML
10281 "Do not send outside local AS (well-known community)\n"
10282 "Do not advertise to any peer (well-known community)\n"
10283 "Do not export to next AS (well-known community)\n"
859d388e 10284 COMMUNITY_AANN_STR
95cbbd2a
ML
10285 "Do not send outside local AS (well-known community)\n"
10286 "Do not advertise to any peer (well-known community)\n"
10287 "Do not export to next AS (well-known community)\n")
10288
8386ac43 10289ALIAS (show_bgp_instance_afi_safi_community,
10290 show_bgp_instance_afi_safi_community3_cmd,
4575cfc3 10291 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
95cbbd2a
ML
10292 SHOW_STR
10293 BGP_STR
8386ac43 10294 BGP_INSTANCE_HELP_STR
95cbbd2a 10295 "Address family\n"
95cbbd2a 10296 "Address family\n"
95cbbd2a
ML
10297 "Address family modifier\n"
10298 "Address family modifier\n"
10299 "Display routes matching the communities\n"
859d388e 10300 COMMUNITY_AANN_STR
95cbbd2a
ML
10301 "Do not send outside local AS (well-known community)\n"
10302 "Do not advertise to any peer (well-known community)\n"
10303 "Do not export to next AS (well-known community)\n"
859d388e 10304 COMMUNITY_AANN_STR
95cbbd2a
ML
10305 "Do not send outside local AS (well-known community)\n"
10306 "Do not advertise to any peer (well-known community)\n"
10307 "Do not export to next AS (well-known community)\n"
859d388e 10308 COMMUNITY_AANN_STR
95cbbd2a
ML
10309 "Do not send outside local AS (well-known community)\n"
10310 "Do not advertise to any peer (well-known community)\n"
10311 "Do not export to next AS (well-known community)\n")
10312
8386ac43 10313ALIAS (show_bgp_instance_afi_safi_community,
10314 show_bgp_instance_afi_safi_community4_cmd,
4575cfc3 10315 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
95cbbd2a
ML
10316 SHOW_STR
10317 BGP_STR
8386ac43 10318 BGP_INSTANCE_HELP_STR
95cbbd2a 10319 "Address family\n"
95cbbd2a 10320 "Address family\n"
95cbbd2a
ML
10321 "Address family modifier\n"
10322 "Address family modifier\n"
10323 "Display routes matching the communities\n"
859d388e 10324 COMMUNITY_AANN_STR
95cbbd2a
ML
10325 "Do not send outside local AS (well-known community)\n"
10326 "Do not advertise to any peer (well-known community)\n"
10327 "Do not export to next AS (well-known community)\n"
859d388e 10328 COMMUNITY_AANN_STR
95cbbd2a
ML
10329 "Do not send outside local AS (well-known community)\n"
10330 "Do not advertise to any peer (well-known community)\n"
10331 "Do not export to next AS (well-known community)\n"
859d388e 10332 COMMUNITY_AANN_STR
95cbbd2a
ML
10333 "Do not send outside local AS (well-known community)\n"
10334 "Do not advertise to any peer (well-known community)\n"
10335 "Do not export to next AS (well-known community)\n"
859d388e 10336 COMMUNITY_AANN_STR
95cbbd2a
ML
10337 "Do not send outside local AS (well-known community)\n"
10338 "Do not advertise to any peer (well-known community)\n"
10339 "Do not export to next AS (well-known community)\n")
10340
718e3744 10341DEFUN (show_ip_bgp_community_exact,
10342 show_ip_bgp_community_exact_cmd,
10343 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10344 SHOW_STR
10345 IP_STR
10346 BGP_STR
10347 "Display routes matching the communities\n"
859d388e 10348 COMMUNITY_AANN_STR
718e3744 10349 "Do not send outside local AS (well-known community)\n"
10350 "Do not advertise to any peer (well-known community)\n"
10351 "Do not export to next AS (well-known community)\n"
10352 "Exact match of the communities")
10353{
95cbbd2a 10354 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 10355}
10356
10357ALIAS (show_ip_bgp_community_exact,
10358 show_ip_bgp_community2_exact_cmd,
10359 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10360 SHOW_STR
10361 IP_STR
10362 BGP_STR
10363 "Display routes matching the communities\n"
859d388e 10364 COMMUNITY_AANN_STR
718e3744 10365 "Do not send outside local AS (well-known community)\n"
10366 "Do not advertise to any peer (well-known community)\n"
10367 "Do not export to next AS (well-known community)\n"
859d388e 10368 COMMUNITY_AANN_STR
718e3744 10369 "Do not send outside local AS (well-known community)\n"
10370 "Do not advertise to any peer (well-known community)\n"
10371 "Do not export to next AS (well-known community)\n"
10372 "Exact match of the communities")
10373
10374ALIAS (show_ip_bgp_community_exact,
10375 show_ip_bgp_community3_exact_cmd,
10376 "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",
10377 SHOW_STR
10378 IP_STR
10379 BGP_STR
10380 "Display routes matching the communities\n"
859d388e 10381 COMMUNITY_AANN_STR
718e3744 10382 "Do not send outside local AS (well-known community)\n"
10383 "Do not advertise to any peer (well-known community)\n"
10384 "Do not export to next AS (well-known community)\n"
859d388e 10385 COMMUNITY_AANN_STR
718e3744 10386 "Do not send outside local AS (well-known community)\n"
10387 "Do not advertise to any peer (well-known community)\n"
10388 "Do not export to next AS (well-known community)\n"
859d388e 10389 COMMUNITY_AANN_STR
718e3744 10390 "Do not send outside local AS (well-known community)\n"
10391 "Do not advertise to any peer (well-known community)\n"
10392 "Do not export to next AS (well-known community)\n"
10393 "Exact match of the communities")
10394
10395ALIAS (show_ip_bgp_community_exact,
10396 show_ip_bgp_community4_exact_cmd,
10397 "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",
10398 SHOW_STR
10399 IP_STR
10400 BGP_STR
10401 "Display routes matching the communities\n"
859d388e 10402 COMMUNITY_AANN_STR
718e3744 10403 "Do not send outside local AS (well-known community)\n"
10404 "Do not advertise to any peer (well-known community)\n"
10405 "Do not export to next AS (well-known community)\n"
859d388e 10406 COMMUNITY_AANN_STR
718e3744 10407 "Do not send outside local AS (well-known community)\n"
10408 "Do not advertise to any peer (well-known community)\n"
10409 "Do not export to next AS (well-known community)\n"
859d388e 10410 COMMUNITY_AANN_STR
718e3744 10411 "Do not send outside local AS (well-known community)\n"
10412 "Do not advertise to any peer (well-known community)\n"
10413 "Do not export to next AS (well-known community)\n"
859d388e 10414 COMMUNITY_AANN_STR
718e3744 10415 "Do not send outside local AS (well-known community)\n"
10416 "Do not advertise to any peer (well-known community)\n"
10417 "Do not export to next AS (well-known community)\n"
10418 "Exact match of the communities")
10419
10420DEFUN (show_ip_bgp_ipv4_community_exact,
10421 show_ip_bgp_ipv4_community_exact_cmd,
4575cfc3 10422 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
718e3744 10423 SHOW_STR
10424 IP_STR
10425 BGP_STR
10426 "Address family\n"
4575cfc3
LB
10427 "Address Family modifier\n"
10428 "Address Family modifier\n"
718e3744 10429 "Display routes matching the communities\n"
859d388e 10430 COMMUNITY_AANN_STR
718e3744 10431 "Do not send outside local AS (well-known community)\n"
10432 "Do not advertise to any peer (well-known community)\n"
10433 "Do not export to next AS (well-known community)\n"
10434 "Exact match of the communities")
10435{
d02fbbdb
LB
10436 safi_t safi;
10437 safi = bgp_vty_safi_from_arg(argv[0]);
10438 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, safi);
718e3744 10439}
10440
10441ALIAS (show_ip_bgp_ipv4_community_exact,
10442 show_ip_bgp_ipv4_community2_exact_cmd,
4575cfc3 10443 "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",
718e3744 10444 SHOW_STR
10445 IP_STR
10446 BGP_STR
10447 "Address family\n"
4575cfc3
LB
10448 "Address Family modifier\n"
10449 "Address Family modifier\n"
718e3744 10450 "Display routes matching the communities\n"
859d388e 10451 COMMUNITY_AANN_STR
718e3744 10452 "Do not send outside local AS (well-known community)\n"
10453 "Do not advertise to any peer (well-known community)\n"
10454 "Do not export to next AS (well-known community)\n"
859d388e 10455 COMMUNITY_AANN_STR
718e3744 10456 "Do not send outside local AS (well-known community)\n"
10457 "Do not advertise to any peer (well-known community)\n"
10458 "Do not export to next AS (well-known community)\n"
10459 "Exact match of the communities")
10460
10461ALIAS (show_ip_bgp_ipv4_community_exact,
10462 show_ip_bgp_ipv4_community3_exact_cmd,
4575cfc3 10463 "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",
718e3744 10464 SHOW_STR
10465 IP_STR
10466 BGP_STR
10467 "Address family\n"
4575cfc3
LB
10468 "Address Family modifier\n"
10469 "Address Family modifier\n"
718e3744 10470 "Display routes matching the communities\n"
859d388e 10471 COMMUNITY_AANN_STR
718e3744 10472 "Do not send outside local AS (well-known community)\n"
10473 "Do not advertise to any peer (well-known community)\n"
10474 "Do not export to next AS (well-known community)\n"
859d388e 10475 COMMUNITY_AANN_STR
718e3744 10476 "Do not send outside local AS (well-known community)\n"
10477 "Do not advertise to any peer (well-known community)\n"
10478 "Do not export to next AS (well-known community)\n"
859d388e 10479 COMMUNITY_AANN_STR
718e3744 10480 "Do not send outside local AS (well-known community)\n"
10481 "Do not advertise to any peer (well-known community)\n"
10482 "Do not export to next AS (well-known community)\n"
10483 "Exact match of the communities")
10484
10485ALIAS (show_ip_bgp_ipv4_community_exact,
10486 show_ip_bgp_ipv4_community4_exact_cmd,
4575cfc3 10487 "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",
718e3744 10488 SHOW_STR
10489 IP_STR
10490 BGP_STR
10491 "Address family\n"
4575cfc3
LB
10492 "Address Family modifier\n"
10493 "Address Family modifier\n"
718e3744 10494 "Display routes matching the communities\n"
859d388e 10495 COMMUNITY_AANN_STR
718e3744 10496 "Do not send outside local AS (well-known community)\n"
10497 "Do not advertise to any peer (well-known community)\n"
10498 "Do not export to next AS (well-known community)\n"
859d388e 10499 COMMUNITY_AANN_STR
718e3744 10500 "Do not send outside local AS (well-known community)\n"
10501 "Do not advertise to any peer (well-known community)\n"
10502 "Do not export to next AS (well-known community)\n"
859d388e 10503 COMMUNITY_AANN_STR
718e3744 10504 "Do not send outside local AS (well-known community)\n"
10505 "Do not advertise to any peer (well-known community)\n"
10506 "Do not export to next AS (well-known community)\n"
859d388e 10507 COMMUNITY_AANN_STR
718e3744 10508 "Do not send outside local AS (well-known community)\n"
10509 "Do not advertise to any peer (well-known community)\n"
10510 "Do not export to next AS (well-known community)\n"
10511 "Exact match of the communities")
10512
10513#ifdef HAVE_IPV6
10514DEFUN (show_bgp_community,
10515 show_bgp_community_cmd,
10516 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
10517 SHOW_STR
10518 BGP_STR
10519 "Display routes matching the communities\n"
859d388e 10520 COMMUNITY_AANN_STR
718e3744 10521 "Do not send outside local AS (well-known community)\n"
10522 "Do not advertise to any peer (well-known community)\n"
10523 "Do not export to next AS (well-known community)\n")
10524{
95cbbd2a 10525 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 10526}
10527
10528ALIAS (show_bgp_community,
10529 show_bgp_ipv6_community_cmd,
10530 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
10531 SHOW_STR
10532 BGP_STR
10533 "Address family\n"
10534 "Display routes matching the communities\n"
859d388e 10535 COMMUNITY_AANN_STR
718e3744 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
10540ALIAS (show_bgp_community,
10541 show_bgp_community2_cmd,
10542 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10543 SHOW_STR
10544 BGP_STR
10545 "Display routes matching the communities\n"
859d388e 10546 COMMUNITY_AANN_STR
718e3744 10547 "Do not send outside local AS (well-known community)\n"
10548 "Do not advertise to any peer (well-known community)\n"
10549 "Do not export to next AS (well-known community)\n"
859d388e 10550 COMMUNITY_AANN_STR
718e3744 10551 "Do not send outside local AS (well-known community)\n"
10552 "Do not advertise to any peer (well-known community)\n"
10553 "Do not export to next AS (well-known community)\n")
10554
10555ALIAS (show_bgp_community,
10556 show_bgp_ipv6_community2_cmd,
10557 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10558 SHOW_STR
10559 BGP_STR
10560 "Address family\n"
10561 "Display routes matching the communities\n"
859d388e 10562 COMMUNITY_AANN_STR
718e3744 10563 "Do not send outside local AS (well-known community)\n"
10564 "Do not advertise to any peer (well-known community)\n"
10565 "Do not export to next AS (well-known community)\n"
859d388e 10566 COMMUNITY_AANN_STR
718e3744 10567 "Do not send outside local AS (well-known community)\n"
10568 "Do not advertise to any peer (well-known community)\n"
10569 "Do not export to next AS (well-known community)\n")
10570
10571ALIAS (show_bgp_community,
10572 show_bgp_community3_cmd,
10573 "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)",
10574 SHOW_STR
10575 BGP_STR
10576 "Display routes matching the communities\n"
859d388e 10577 COMMUNITY_AANN_STR
718e3744 10578 "Do not send outside local AS (well-known community)\n"
10579 "Do not advertise to any peer (well-known community)\n"
10580 "Do not export to next AS (well-known community)\n"
859d388e 10581 COMMUNITY_AANN_STR
718e3744 10582 "Do not send outside local AS (well-known community)\n"
10583 "Do not advertise to any peer (well-known community)\n"
10584 "Do not export to next AS (well-known community)\n"
859d388e 10585 COMMUNITY_AANN_STR
718e3744 10586 "Do not send outside local AS (well-known community)\n"
10587 "Do not advertise to any peer (well-known community)\n"
10588 "Do not export to next AS (well-known community)\n")
10589
10590ALIAS (show_bgp_community,
10591 show_bgp_ipv6_community3_cmd,
10592 "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)",
10593 SHOW_STR
10594 BGP_STR
10595 "Address family\n"
10596 "Display routes matching the communities\n"
859d388e 10597 COMMUNITY_AANN_STR
718e3744 10598 "Do not send outside local AS (well-known community)\n"
10599 "Do not advertise to any peer (well-known community)\n"
10600 "Do not export to next AS (well-known community)\n"
859d388e 10601 COMMUNITY_AANN_STR
718e3744 10602 "Do not send outside local AS (well-known community)\n"
10603 "Do not advertise to any peer (well-known community)\n"
10604 "Do not export to next AS (well-known community)\n"
859d388e 10605 COMMUNITY_AANN_STR
718e3744 10606 "Do not send outside local AS (well-known community)\n"
10607 "Do not advertise to any peer (well-known community)\n"
10608 "Do not export to next AS (well-known community)\n")
10609
10610ALIAS (show_bgp_community,
10611 show_bgp_community4_cmd,
10612 "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)",
10613 SHOW_STR
10614 BGP_STR
10615 "Display routes matching the communities\n"
859d388e 10616 COMMUNITY_AANN_STR
718e3744 10617 "Do not send outside local AS (well-known community)\n"
10618 "Do not advertise to any peer (well-known community)\n"
10619 "Do not export to next AS (well-known community)\n"
859d388e 10620 COMMUNITY_AANN_STR
718e3744 10621 "Do not send outside local AS (well-known community)\n"
10622 "Do not advertise to any peer (well-known community)\n"
10623 "Do not export to next AS (well-known community)\n"
859d388e 10624 COMMUNITY_AANN_STR
718e3744 10625 "Do not send outside local AS (well-known community)\n"
10626 "Do not advertise to any peer (well-known community)\n"
10627 "Do not export to next AS (well-known community)\n"
859d388e 10628 COMMUNITY_AANN_STR
718e3744 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
10633ALIAS (show_bgp_community,
10634 show_bgp_ipv6_community4_cmd,
10635 "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)",
10636 SHOW_STR
10637 BGP_STR
10638 "Address family\n"
10639 "Display routes matching the communities\n"
859d388e 10640 COMMUNITY_AANN_STR
718e3744 10641 "Do not send outside local AS (well-known community)\n"
10642 "Do not advertise to any peer (well-known community)\n"
10643 "Do not export to next AS (well-known community)\n"
859d388e 10644 COMMUNITY_AANN_STR
718e3744 10645 "Do not send outside local AS (well-known community)\n"
10646 "Do not advertise to any peer (well-known community)\n"
10647 "Do not export to next AS (well-known community)\n"
859d388e 10648 COMMUNITY_AANN_STR
718e3744 10649 "Do not send outside local AS (well-known community)\n"
10650 "Do not advertise to any peer (well-known community)\n"
10651 "Do not export to next AS (well-known community)\n"
859d388e 10652 COMMUNITY_AANN_STR
718e3744 10653 "Do not send outside local AS (well-known community)\n"
10654 "Do not advertise to any peer (well-known community)\n"
10655 "Do not export to next AS (well-known community)\n")
10656
10657/* old command */
10658DEFUN (show_ipv6_bgp_community,
10659 show_ipv6_bgp_community_cmd,
10660 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
10661 SHOW_STR
10662 IPV6_STR
10663 BGP_STR
10664 "Display routes matching the communities\n"
859d388e 10665 COMMUNITY_AANN_STR
718e3744 10666 "Do not send outside local AS (well-known community)\n"
10667 "Do not advertise to any peer (well-known community)\n"
10668 "Do not export to next AS (well-known community)\n")
10669{
47e9b292 10670 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 10671 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 10672}
10673
10674/* old command */
10675ALIAS (show_ipv6_bgp_community,
10676 show_ipv6_bgp_community2_cmd,
10677 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10678 SHOW_STR
10679 IPV6_STR
10680 BGP_STR
10681 "Display routes matching the communities\n"
859d388e 10682 COMMUNITY_AANN_STR
718e3744 10683 "Do not send outside local AS (well-known community)\n"
10684 "Do not advertise to any peer (well-known community)\n"
10685 "Do not export to next AS (well-known community)\n"
859d388e 10686 COMMUNITY_AANN_STR
718e3744 10687 "Do not send outside local AS (well-known community)\n"
10688 "Do not advertise to any peer (well-known community)\n"
10689 "Do not export to next AS (well-known community)\n")
10690
10691/* old command */
10692ALIAS (show_ipv6_bgp_community,
10693 show_ipv6_bgp_community3_cmd,
10694 "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)",
10695 SHOW_STR
10696 IPV6_STR
10697 BGP_STR
10698 "Display routes matching the communities\n"
859d388e 10699 COMMUNITY_AANN_STR
718e3744 10700 "Do not send outside local AS (well-known community)\n"
10701 "Do not advertise to any peer (well-known community)\n"
10702 "Do not export to next AS (well-known community)\n"
859d388e 10703 COMMUNITY_AANN_STR
718e3744 10704 "Do not send outside local AS (well-known community)\n"
10705 "Do not advertise to any peer (well-known community)\n"
10706 "Do not export to next AS (well-known community)\n"
859d388e 10707 COMMUNITY_AANN_STR
718e3744 10708 "Do not send outside local AS (well-known community)\n"
10709 "Do not advertise to any peer (well-known community)\n"
10710 "Do not export to next AS (well-known community)\n")
10711
10712/* old command */
10713ALIAS (show_ipv6_bgp_community,
10714 show_ipv6_bgp_community4_cmd,
10715 "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)",
10716 SHOW_STR
10717 IPV6_STR
10718 BGP_STR
10719 "Display routes matching the communities\n"
859d388e 10720 COMMUNITY_AANN_STR
718e3744 10721 "Do not send outside local AS (well-known community)\n"
10722 "Do not advertise to any peer (well-known community)\n"
10723 "Do not export to next AS (well-known community)\n"
859d388e 10724 COMMUNITY_AANN_STR
718e3744 10725 "Do not send outside local AS (well-known community)\n"
10726 "Do not advertise to any peer (well-known community)\n"
10727 "Do not export to next AS (well-known community)\n"
859d388e 10728 COMMUNITY_AANN_STR
718e3744 10729 "Do not send outside local AS (well-known community)\n"
10730 "Do not advertise to any peer (well-known community)\n"
10731 "Do not export to next AS (well-known community)\n"
859d388e 10732 COMMUNITY_AANN_STR
718e3744 10733 "Do not send outside local AS (well-known community)\n"
10734 "Do not advertise to any peer (well-known community)\n"
10735 "Do not export to next AS (well-known community)\n")
10736
10737DEFUN (show_bgp_community_exact,
10738 show_bgp_community_exact_cmd,
10739 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10740 SHOW_STR
10741 BGP_STR
10742 "Display routes matching the communities\n"
859d388e 10743 COMMUNITY_AANN_STR
718e3744 10744 "Do not send outside local AS (well-known community)\n"
10745 "Do not advertise to any peer (well-known community)\n"
10746 "Do not export to next AS (well-known community)\n"
10747 "Exact match of the communities")
10748{
95cbbd2a 10749 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 10750}
10751
10752ALIAS (show_bgp_community_exact,
10753 show_bgp_ipv6_community_exact_cmd,
10754 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10755 SHOW_STR
10756 BGP_STR
10757 "Address family\n"
10758 "Display routes matching the communities\n"
859d388e 10759 COMMUNITY_AANN_STR
718e3744 10760 "Do not send outside local AS (well-known community)\n"
10761 "Do not advertise to any peer (well-known community)\n"
10762 "Do not export to next AS (well-known community)\n"
10763 "Exact match of the communities")
10764
10765ALIAS (show_bgp_community_exact,
10766 show_bgp_community2_exact_cmd,
10767 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10768 SHOW_STR
10769 BGP_STR
10770 "Display routes matching the communities\n"
859d388e 10771 COMMUNITY_AANN_STR
718e3744 10772 "Do not send outside local AS (well-known community)\n"
10773 "Do not advertise to any peer (well-known community)\n"
10774 "Do not export to next AS (well-known community)\n"
859d388e 10775 COMMUNITY_AANN_STR
718e3744 10776 "Do not send outside local AS (well-known community)\n"
10777 "Do not advertise to any peer (well-known community)\n"
10778 "Do not export to next AS (well-known community)\n"
10779 "Exact match of the communities")
10780
10781ALIAS (show_bgp_community_exact,
10782 show_bgp_ipv6_community2_exact_cmd,
10783 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10784 SHOW_STR
10785 BGP_STR
10786 "Address family\n"
10787 "Display routes matching the communities\n"
859d388e 10788 COMMUNITY_AANN_STR
718e3744 10789 "Do not send outside local AS (well-known community)\n"
10790 "Do not advertise to any peer (well-known community)\n"
10791 "Do not export to next AS (well-known community)\n"
859d388e 10792 COMMUNITY_AANN_STR
718e3744 10793 "Do not send outside local AS (well-known community)\n"
10794 "Do not advertise to any peer (well-known community)\n"
10795 "Do not export to next AS (well-known community)\n"
10796 "Exact match of the communities")
10797
10798ALIAS (show_bgp_community_exact,
10799 show_bgp_community3_exact_cmd,
10800 "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",
10801 SHOW_STR
10802 BGP_STR
10803 "Display routes matching the communities\n"
859d388e 10804 COMMUNITY_AANN_STR
718e3744 10805 "Do not send outside local AS (well-known community)\n"
10806 "Do not advertise to any peer (well-known community)\n"
10807 "Do not export to next AS (well-known community)\n"
859d388e 10808 COMMUNITY_AANN_STR
718e3744 10809 "Do not send outside local AS (well-known community)\n"
10810 "Do not advertise to any peer (well-known community)\n"
10811 "Do not export to next AS (well-known community)\n"
859d388e 10812 COMMUNITY_AANN_STR
718e3744 10813 "Do not send outside local AS (well-known community)\n"
10814 "Do not advertise to any peer (well-known community)\n"
10815 "Do not export to next AS (well-known community)\n"
10816 "Exact match of the communities")
10817
10818ALIAS (show_bgp_community_exact,
10819 show_bgp_ipv6_community3_exact_cmd,
10820 "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",
10821 SHOW_STR
10822 BGP_STR
10823 "Address family\n"
10824 "Display routes matching the communities\n"
859d388e 10825 COMMUNITY_AANN_STR
718e3744 10826 "Do not send outside local AS (well-known community)\n"
10827 "Do not advertise to any peer (well-known community)\n"
10828 "Do not export to next AS (well-known community)\n"
859d388e 10829 COMMUNITY_AANN_STR
718e3744 10830 "Do not send outside local AS (well-known community)\n"
10831 "Do not advertise to any peer (well-known community)\n"
10832 "Do not export to next AS (well-known community)\n"
859d388e 10833 COMMUNITY_AANN_STR
718e3744 10834 "Do not send outside local AS (well-known community)\n"
10835 "Do not advertise to any peer (well-known community)\n"
10836 "Do not export to next AS (well-known community)\n"
10837 "Exact match of the communities")
10838
10839ALIAS (show_bgp_community_exact,
10840 show_bgp_community4_exact_cmd,
10841 "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",
10842 SHOW_STR
10843 BGP_STR
10844 "Display routes matching the communities\n"
859d388e 10845 COMMUNITY_AANN_STR
718e3744 10846 "Do not send outside local AS (well-known community)\n"
10847 "Do not advertise to any peer (well-known community)\n"
10848 "Do not export to next AS (well-known community)\n"
859d388e 10849 COMMUNITY_AANN_STR
718e3744 10850 "Do not send outside local AS (well-known community)\n"
10851 "Do not advertise to any peer (well-known community)\n"
10852 "Do not export to next AS (well-known community)\n"
859d388e 10853 COMMUNITY_AANN_STR
718e3744 10854 "Do not send outside local AS (well-known community)\n"
10855 "Do not advertise to any peer (well-known community)\n"
10856 "Do not export to next AS (well-known community)\n"
859d388e 10857 COMMUNITY_AANN_STR
718e3744 10858 "Do not send outside local AS (well-known community)\n"
10859 "Do not advertise to any peer (well-known community)\n"
10860 "Do not export to next AS (well-known community)\n"
10861 "Exact match of the communities")
10862
10863ALIAS (show_bgp_community_exact,
10864 show_bgp_ipv6_community4_exact_cmd,
10865 "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",
10866 SHOW_STR
10867 BGP_STR
10868 "Address family\n"
10869 "Display routes matching the communities\n"
859d388e 10870 COMMUNITY_AANN_STR
718e3744 10871 "Do not send outside local AS (well-known community)\n"
10872 "Do not advertise to any peer (well-known community)\n"
10873 "Do not export to next AS (well-known community)\n"
859d388e 10874 COMMUNITY_AANN_STR
718e3744 10875 "Do not send outside local AS (well-known community)\n"
10876 "Do not advertise to any peer (well-known community)\n"
10877 "Do not export to next AS (well-known community)\n"
859d388e 10878 COMMUNITY_AANN_STR
718e3744 10879 "Do not send outside local AS (well-known community)\n"
10880 "Do not advertise to any peer (well-known community)\n"
10881 "Do not export to next AS (well-known community)\n"
859d388e 10882 COMMUNITY_AANN_STR
718e3744 10883 "Do not send outside local AS (well-known community)\n"
10884 "Do not advertise to any peer (well-known community)\n"
10885 "Do not export to next AS (well-known community)\n"
10886 "Exact match of the communities")
10887
10888/* old command */
10889DEFUN (show_ipv6_bgp_community_exact,
10890 show_ipv6_bgp_community_exact_cmd,
10891 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10892 SHOW_STR
10893 IPV6_STR
10894 BGP_STR
10895 "Display routes matching the communities\n"
859d388e 10896 COMMUNITY_AANN_STR
718e3744 10897 "Do not send outside local AS (well-known community)\n"
10898 "Do not advertise to any peer (well-known community)\n"
10899 "Do not export to next AS (well-known community)\n"
10900 "Exact match of the communities")
10901{
47e9b292 10902 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 10903 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 10904}
10905
10906/* old command */
10907ALIAS (show_ipv6_bgp_community_exact,
10908 show_ipv6_bgp_community2_exact_cmd,
10909 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10910 SHOW_STR
10911 IPV6_STR
10912 BGP_STR
10913 "Display routes matching the communities\n"
859d388e 10914 COMMUNITY_AANN_STR
718e3744 10915 "Do not send outside local AS (well-known community)\n"
10916 "Do not advertise to any peer (well-known community)\n"
10917 "Do not export to next AS (well-known community)\n"
859d388e 10918 COMMUNITY_AANN_STR
718e3744 10919 "Do not send outside local AS (well-known community)\n"
10920 "Do not advertise to any peer (well-known community)\n"
10921 "Do not export to next AS (well-known community)\n"
10922 "Exact match of the communities")
10923
10924/* old command */
10925ALIAS (show_ipv6_bgp_community_exact,
10926 show_ipv6_bgp_community3_exact_cmd,
10927 "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",
10928 SHOW_STR
10929 IPV6_STR
10930 BGP_STR
10931 "Display routes matching the communities\n"
859d388e 10932 COMMUNITY_AANN_STR
718e3744 10933 "Do not send outside local AS (well-known community)\n"
10934 "Do not advertise to any peer (well-known community)\n"
10935 "Do not export to next AS (well-known community)\n"
859d388e 10936 COMMUNITY_AANN_STR
718e3744 10937 "Do not send outside local AS (well-known community)\n"
10938 "Do not advertise to any peer (well-known community)\n"
10939 "Do not export to next AS (well-known community)\n"
859d388e 10940 COMMUNITY_AANN_STR
718e3744 10941 "Do not send outside local AS (well-known community)\n"
10942 "Do not advertise to any peer (well-known community)\n"
10943 "Do not export to next AS (well-known community)\n"
10944 "Exact match of the communities")
10945
10946/* old command */
10947ALIAS (show_ipv6_bgp_community_exact,
10948 show_ipv6_bgp_community4_exact_cmd,
10949 "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",
10950 SHOW_STR
10951 IPV6_STR
10952 BGP_STR
10953 "Display routes matching the communities\n"
859d388e 10954 COMMUNITY_AANN_STR
718e3744 10955 "Do not send outside local AS (well-known community)\n"
10956 "Do not advertise to any peer (well-known community)\n"
10957 "Do not export to next AS (well-known community)\n"
859d388e 10958 COMMUNITY_AANN_STR
718e3744 10959 "Do not send outside local AS (well-known community)\n"
10960 "Do not advertise to any peer (well-known community)\n"
10961 "Do not export to next AS (well-known community)\n"
859d388e 10962 COMMUNITY_AANN_STR
718e3744 10963 "Do not send outside local AS (well-known community)\n"
10964 "Do not advertise to any peer (well-known community)\n"
10965 "Do not export to next AS (well-known community)\n"
859d388e 10966 COMMUNITY_AANN_STR
718e3744 10967 "Do not send outside local AS (well-known community)\n"
10968 "Do not advertise to any peer (well-known community)\n"
10969 "Do not export to next AS (well-known community)\n"
10970 "Exact match of the communities")
10971
10972/* old command */
10973DEFUN (show_ipv6_mbgp_community,
10974 show_ipv6_mbgp_community_cmd,
10975 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10976 SHOW_STR
10977 IPV6_STR
10978 MBGP_STR
10979 "Display routes matching the communities\n"
859d388e 10980 COMMUNITY_AANN_STR
718e3744 10981 "Do not send outside local AS (well-known community)\n"
10982 "Do not advertise to any peer (well-known community)\n"
10983 "Do not export to next AS (well-known community)\n")
10984{
47e9b292 10985 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 10986 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
718e3744 10987}
10988
10989/* old command */
10990ALIAS (show_ipv6_mbgp_community,
10991 show_ipv6_mbgp_community2_cmd,
10992 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10993 SHOW_STR
10994 IPV6_STR
10995 MBGP_STR
10996 "Display routes matching the communities\n"
859d388e 10997 COMMUNITY_AANN_STR
718e3744 10998 "Do not send outside local AS (well-known community)\n"
10999 "Do not advertise to any peer (well-known community)\n"
11000 "Do not export to next AS (well-known community)\n"
859d388e 11001 COMMUNITY_AANN_STR
718e3744 11002 "Do not send outside local AS (well-known community)\n"
11003 "Do not advertise to any peer (well-known community)\n"
11004 "Do not export to next AS (well-known community)\n")
11005
11006/* old command */
11007ALIAS (show_ipv6_mbgp_community,
11008 show_ipv6_mbgp_community3_cmd,
11009 "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)",
11010 SHOW_STR
11011 IPV6_STR
11012 MBGP_STR
11013 "Display routes matching the communities\n"
859d388e 11014 COMMUNITY_AANN_STR
718e3744 11015 "Do not send outside local AS (well-known community)\n"
11016 "Do not advertise to any peer (well-known community)\n"
11017 "Do not export to next AS (well-known community)\n"
859d388e 11018 COMMUNITY_AANN_STR
718e3744 11019 "Do not send outside local AS (well-known community)\n"
11020 "Do not advertise to any peer (well-known community)\n"
11021 "Do not export to next AS (well-known community)\n"
859d388e 11022 COMMUNITY_AANN_STR
718e3744 11023 "Do not send outside local AS (well-known community)\n"
11024 "Do not advertise to any peer (well-known community)\n"
11025 "Do not export to next AS (well-known community)\n")
11026
11027/* old command */
11028ALIAS (show_ipv6_mbgp_community,
11029 show_ipv6_mbgp_community4_cmd,
11030 "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)",
11031 SHOW_STR
11032 IPV6_STR
11033 MBGP_STR
11034 "Display routes matching the communities\n"
859d388e 11035 COMMUNITY_AANN_STR
718e3744 11036 "Do not send outside local AS (well-known community)\n"
11037 "Do not advertise to any peer (well-known community)\n"
11038 "Do not export to next AS (well-known community)\n"
859d388e 11039 COMMUNITY_AANN_STR
718e3744 11040 "Do not send outside local AS (well-known community)\n"
11041 "Do not advertise to any peer (well-known community)\n"
11042 "Do not export to next AS (well-known community)\n"
859d388e 11043 COMMUNITY_AANN_STR
718e3744 11044 "Do not send outside local AS (well-known community)\n"
11045 "Do not advertise to any peer (well-known community)\n"
11046 "Do not export to next AS (well-known community)\n"
859d388e 11047 COMMUNITY_AANN_STR
718e3744 11048 "Do not send outside local AS (well-known community)\n"
11049 "Do not advertise to any peer (well-known community)\n"
11050 "Do not export to next AS (well-known community)\n")
11051
11052/* old command */
11053DEFUN (show_ipv6_mbgp_community_exact,
11054 show_ipv6_mbgp_community_exact_cmd,
11055 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
11056 SHOW_STR
11057 IPV6_STR
11058 MBGP_STR
11059 "Display routes matching the communities\n"
859d388e 11060 COMMUNITY_AANN_STR
718e3744 11061 "Do not send outside local AS (well-known community)\n"
11062 "Do not advertise to any peer (well-known community)\n"
11063 "Do not export to next AS (well-known community)\n"
11064 "Exact match of the communities")
11065{
47e9b292 11066 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 11067 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
718e3744 11068}
11069
11070/* old command */
11071ALIAS (show_ipv6_mbgp_community_exact,
11072 show_ipv6_mbgp_community2_exact_cmd,
11073 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
11074 SHOW_STR
11075 IPV6_STR
11076 MBGP_STR
11077 "Display routes matching the communities\n"
859d388e 11078 COMMUNITY_AANN_STR
718e3744 11079 "Do not send outside local AS (well-known community)\n"
11080 "Do not advertise to any peer (well-known community)\n"
11081 "Do not export to next AS (well-known community)\n"
859d388e 11082 COMMUNITY_AANN_STR
718e3744 11083 "Do not send outside local AS (well-known community)\n"
11084 "Do not advertise to any peer (well-known community)\n"
11085 "Do not export to next AS (well-known community)\n"
11086 "Exact match of the communities")
11087
11088/* old command */
11089ALIAS (show_ipv6_mbgp_community_exact,
11090 show_ipv6_mbgp_community3_exact_cmd,
11091 "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",
11092 SHOW_STR
11093 IPV6_STR
11094 MBGP_STR
11095 "Display routes matching the communities\n"
859d388e 11096 COMMUNITY_AANN_STR
718e3744 11097 "Do not send outside local AS (well-known community)\n"
11098 "Do not advertise to any peer (well-known community)\n"
11099 "Do not export to next AS (well-known community)\n"
859d388e 11100 COMMUNITY_AANN_STR
718e3744 11101 "Do not send outside local AS (well-known community)\n"
11102 "Do not advertise to any peer (well-known community)\n"
11103 "Do not export to next AS (well-known community)\n"
859d388e 11104 COMMUNITY_AANN_STR
718e3744 11105 "Do not send outside local AS (well-known community)\n"
11106 "Do not advertise to any peer (well-known community)\n"
11107 "Do not export to next AS (well-known community)\n"
11108 "Exact match of the communities")
11109
11110/* old command */
11111ALIAS (show_ipv6_mbgp_community_exact,
11112 show_ipv6_mbgp_community4_exact_cmd,
11113 "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",
11114 SHOW_STR
11115 IPV6_STR
11116 MBGP_STR
11117 "Display routes matching the communities\n"
859d388e 11118 COMMUNITY_AANN_STR
718e3744 11119 "Do not send outside local AS (well-known community)\n"
11120 "Do not advertise to any peer (well-known community)\n"
11121 "Do not export to next AS (well-known community)\n"
859d388e 11122 COMMUNITY_AANN_STR
718e3744 11123 "Do not send outside local AS (well-known community)\n"
11124 "Do not advertise to any peer (well-known community)\n"
11125 "Do not export to next AS (well-known community)\n"
859d388e 11126 COMMUNITY_AANN_STR
718e3744 11127 "Do not send outside local AS (well-known community)\n"
11128 "Do not advertise to any peer (well-known community)\n"
11129 "Do not export to next AS (well-known community)\n"
859d388e 11130 COMMUNITY_AANN_STR
718e3744 11131 "Do not send outside local AS (well-known community)\n"
11132 "Do not advertise to any peer (well-known community)\n"
11133 "Do not export to next AS (well-known community)\n"
11134 "Exact match of the communities")
11135#endif /* HAVE_IPV6 */
6b0655a2 11136
94f2b392 11137static int
50ef26d4 11138bgp_show_community_list (struct vty *vty, const char *name,
11139 const char *com, int exact,
4c9641ba 11140 afi_t afi, safi_t safi)
718e3744 11141{
11142 struct community_list *list;
50ef26d4 11143 struct bgp *bgp = NULL;
11144
11145 if (name && !(bgp = bgp_lookup_by_name(name)))
11146 {
11147 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11148 return CMD_WARNING;
11149 }
718e3744 11150
fee6e4e4 11151 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
718e3744 11152 if (list == NULL)
11153 {
11154 vty_out (vty, "%% %s is not a valid community-list name%s", com,
11155 VTY_NEWLINE);
11156 return CMD_WARNING;
11157 }
11158
50ef26d4 11159 return bgp_show (vty, bgp, afi, safi,
5a646650 11160 (exact ? bgp_show_type_community_list_exact :
b05a1c8b 11161 bgp_show_type_community_list), list, 0);
718e3744 11162}
11163
11164DEFUN (show_ip_bgp_community_list,
11165 show_ip_bgp_community_list_cmd,
fee6e4e4 11166 "show ip bgp community-list (<1-500>|WORD)",
718e3744 11167 SHOW_STR
11168 IP_STR
11169 BGP_STR
11170 "Display routes matching the community-list\n"
fee6e4e4 11171 "community-list number\n"
718e3744 11172 "community-list name\n")
11173{
50ef26d4 11174 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP, SAFI_UNICAST);
11175}
11176
8386ac43 11177DEFUN (show_ip_bgp_instance_community_list,
11178 show_ip_bgp_instance_community_list_cmd,
11179 "show ip bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
50ef26d4 11180 SHOW_STR
11181 IP_STR
11182 BGP_STR
8386ac43 11183 BGP_INSTANCE_HELP_STR
50ef26d4 11184 "Display routes matching the community-list\n"
11185 "community-list number\n"
11186 "community-list name\n")
11187{
11188 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP, SAFI_UNICAST);
718e3744 11189}
11190
11191DEFUN (show_ip_bgp_ipv4_community_list,
11192 show_ip_bgp_ipv4_community_list_cmd,
4575cfc3 11193 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
718e3744 11194 SHOW_STR
11195 IP_STR
11196 BGP_STR
11197 "Address family\n"
4575cfc3
LB
11198 "Address Family modifier\n"
11199 "Address Family modifier\n"
718e3744 11200 "Display routes matching the community-list\n"
fee6e4e4 11201 "community-list number\n"
718e3744 11202 "community-list name\n")
11203{
d02fbbdb
LB
11204 safi_t safi;
11205 safi = bgp_vty_safi_from_arg(argv[0]);
11206 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, safi);
718e3744 11207}
11208
11209DEFUN (show_ip_bgp_community_list_exact,
11210 show_ip_bgp_community_list_exact_cmd,
fee6e4e4 11211 "show ip bgp community-list (<1-500>|WORD) exact-match",
718e3744 11212 SHOW_STR
11213 IP_STR
11214 BGP_STR
11215 "Display routes matching the community-list\n"
fee6e4e4 11216 "community-list number\n"
718e3744 11217 "community-list name\n"
11218 "Exact match of the communities\n")
11219{
50ef26d4 11220 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP, SAFI_UNICAST);
718e3744 11221}
11222
11223DEFUN (show_ip_bgp_ipv4_community_list_exact,
11224 show_ip_bgp_ipv4_community_list_exact_cmd,
4575cfc3 11225 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
718e3744 11226 SHOW_STR
11227 IP_STR
11228 BGP_STR
11229 "Address family\n"
4575cfc3
LB
11230 "Address Family modifier\n"
11231 "Address Family modifier\n"
718e3744 11232 "Display routes matching the community-list\n"
fee6e4e4 11233 "community-list number\n"
718e3744 11234 "community-list name\n"
11235 "Exact match of the communities\n")
11236{
d02fbbdb
LB
11237 safi_t safi;
11238 safi = bgp_vty_safi_from_arg(argv[0]);
11239 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, safi);
718e3744 11240}
11241
11242#ifdef HAVE_IPV6
11243DEFUN (show_bgp_community_list,
11244 show_bgp_community_list_cmd,
fee6e4e4 11245 "show bgp community-list (<1-500>|WORD)",
718e3744 11246 SHOW_STR
11247 BGP_STR
11248 "Display routes matching the community-list\n"
fee6e4e4 11249 "community-list number\n"
718e3744 11250 "community-list name\n")
11251{
50ef26d4 11252 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
718e3744 11253}
11254
11255ALIAS (show_bgp_community_list,
11256 show_bgp_ipv6_community_list_cmd,
fee6e4e4 11257 "show bgp ipv6 community-list (<1-500>|WORD)",
718e3744 11258 SHOW_STR
11259 BGP_STR
11260 "Address family\n"
11261 "Display routes matching the community-list\n"
fee6e4e4 11262 "community-list number\n"
e8e1946e 11263 "community-list name\n")
718e3744 11264
11265/* old command */
11266DEFUN (show_ipv6_bgp_community_list,
11267 show_ipv6_bgp_community_list_cmd,
11268 "show ipv6 bgp community-list WORD",
11269 SHOW_STR
11270 IPV6_STR
11271 BGP_STR
11272 "Display routes matching the community-list\n"
11273 "community-list name\n")
11274{
47e9b292 11275 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 11276 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
718e3744 11277}
11278
11279/* old command */
11280DEFUN (show_ipv6_mbgp_community_list,
11281 show_ipv6_mbgp_community_list_cmd,
11282 "show ipv6 mbgp community-list WORD",
11283 SHOW_STR
11284 IPV6_STR
11285 MBGP_STR
11286 "Display routes matching the community-list\n"
11287 "community-list name\n")
11288{
47e9b292 11289 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 11290 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
718e3744 11291}
11292
11293DEFUN (show_bgp_community_list_exact,
11294 show_bgp_community_list_exact_cmd,
fee6e4e4 11295 "show bgp community-list (<1-500>|WORD) exact-match",
718e3744 11296 SHOW_STR
11297 BGP_STR
11298 "Display routes matching the community-list\n"
fee6e4e4 11299 "community-list number\n"
718e3744 11300 "community-list name\n"
11301 "Exact match of the communities\n")
11302{
50ef26d4 11303 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
718e3744 11304}
11305
11306ALIAS (show_bgp_community_list_exact,
11307 show_bgp_ipv6_community_list_exact_cmd,
fee6e4e4 11308 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
718e3744 11309 SHOW_STR
11310 BGP_STR
11311 "Address family\n"
11312 "Display routes matching the community-list\n"
fee6e4e4 11313 "community-list number\n"
718e3744 11314 "community-list name\n"
11315 "Exact match of the communities\n")
11316
11317/* old command */
11318DEFUN (show_ipv6_bgp_community_list_exact,
11319 show_ipv6_bgp_community_list_exact_cmd,
11320 "show ipv6 bgp community-list WORD exact-match",
11321 SHOW_STR
11322 IPV6_STR
11323 BGP_STR
11324 "Display routes matching the community-list\n"
11325 "community-list name\n"
11326 "Exact match of the communities\n")
11327{
47e9b292 11328 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 11329 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
718e3744 11330}
11331
11332/* old command */
11333DEFUN (show_ipv6_mbgp_community_list_exact,
11334 show_ipv6_mbgp_community_list_exact_cmd,
11335 "show ipv6 mbgp community-list WORD exact-match",
11336 SHOW_STR
11337 IPV6_STR
11338 MBGP_STR
11339 "Display routes matching the community-list\n"
11340 "community-list name\n"
11341 "Exact match of the communities\n")
11342{
47e9b292 11343 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 11344 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
718e3744 11345}
11346#endif /* HAVE_IPV6 */
6b0655a2 11347
94f2b392 11348static int
50ef26d4 11349bgp_show_prefix_longer (struct vty *vty, const char *name,
11350 const char *prefix, afi_t afi,
718e3744 11351 safi_t safi, enum bgp_show_type type)
11352{
11353 int ret;
11354 struct prefix *p;
50ef26d4 11355 struct bgp *bgp = NULL;
11356
11357 if (name && !(bgp = bgp_lookup_by_name(name)))
11358 {
11359 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11360 return CMD_WARNING;
11361 }
718e3744 11362
11363 p = prefix_new();
11364
11365 ret = str2prefix (prefix, p);
11366 if (! ret)
11367 {
11368 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11369 return CMD_WARNING;
11370 }
11371
50ef26d4 11372 ret = bgp_show (vty, bgp, afi, safi, type, p, 0);
5a646650 11373 prefix_free(p);
11374 return ret;
718e3744 11375}
11376
11377DEFUN (show_ip_bgp_prefix_longer,
11378 show_ip_bgp_prefix_longer_cmd,
11379 "show ip bgp A.B.C.D/M longer-prefixes",
11380 SHOW_STR
11381 IP_STR
11382 BGP_STR
11383 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11384 "Display route and more specific routes\n")
11385{
50ef26d4 11386 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11387 bgp_show_type_prefix_longer);
11388}
11389
8386ac43 11390DEFUN (show_ip_bgp_instance_prefix_longer,
11391 show_ip_bgp_instance_prefix_longer_cmd,
11392 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M longer-prefixes",
50ef26d4 11393 SHOW_STR
11394 IP_STR
11395 BGP_STR
8386ac43 11396 BGP_INSTANCE_HELP_STR
50ef26d4 11397 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11398 "Display route and more specific routes\n")
11399{
11400 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
718e3744 11401 bgp_show_type_prefix_longer);
11402}
11403
11404DEFUN (show_ip_bgp_flap_prefix_longer,
11405 show_ip_bgp_flap_prefix_longer_cmd,
11406 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11407 SHOW_STR
11408 IP_STR
11409 BGP_STR
11410 "Display flap statistics of routes\n"
11411 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11412 "Display route and more specific routes\n")
11413{
50ef26d4 11414 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 11415 bgp_show_type_flap_prefix_longer);
11416}
11417
81304aaf
B
11418ALIAS (show_ip_bgp_flap_prefix_longer,
11419 show_ip_bgp_damp_flap_prefix_longer_cmd,
11420 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11421 SHOW_STR
11422 IP_STR
11423 BGP_STR
11424 "Display detailed information about dampening\n"
11425 "Display flap statistics of routes\n"
11426 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11427 "Display route and more specific routes\n")
11428
718e3744 11429DEFUN (show_ip_bgp_ipv4_prefix_longer,
11430 show_ip_bgp_ipv4_prefix_longer_cmd,
4575cfc3 11431 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
718e3744 11432 SHOW_STR
11433 IP_STR
11434 BGP_STR
11435 "Address family\n"
4575cfc3
LB
11436 "Address Family modifier\n"
11437 "Address Family modifier\n"
718e3744 11438 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11439 "Display route and more specific routes\n")
11440{
d02fbbdb
LB
11441 safi_t safi;
11442 safi = bgp_vty_safi_from_arg(argv[0]);
11443 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, safi,
11444 bgp_show_type_prefix_longer);
718e3744 11445}
11446
11447DEFUN (show_ip_bgp_flap_address,
11448 show_ip_bgp_flap_address_cmd,
11449 "show ip bgp flap-statistics A.B.C.D",
11450 SHOW_STR
11451 IP_STR
11452 BGP_STR
11453 "Display flap statistics of routes\n"
11454 "Network in the BGP routing table to display\n")
11455{
50ef26d4 11456 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 11457 bgp_show_type_flap_address);
11458}
11459
81304aaf
B
11460ALIAS (show_ip_bgp_flap_address,
11461 show_ip_bgp_damp_flap_address_cmd,
11462 "show ip bgp dampening flap-statistics A.B.C.D",
11463 SHOW_STR
11464 IP_STR
11465 BGP_STR
11466 "Display detailed information about dampening\n"
11467 "Display flap statistics of routes\n"
11468 "Network in the BGP routing table to display\n")
11469
718e3744 11470DEFUN (show_ip_bgp_flap_prefix,
11471 show_ip_bgp_flap_prefix_cmd,
11472 "show ip bgp flap-statistics A.B.C.D/M",
11473 SHOW_STR
11474 IP_STR
11475 BGP_STR
11476 "Display flap statistics of routes\n"
11477 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11478{
50ef26d4 11479 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
718e3744 11480 bgp_show_type_flap_prefix);
11481}
81304aaf
B
11482
11483ALIAS (show_ip_bgp_flap_prefix,
11484 show_ip_bgp_damp_flap_prefix_cmd,
11485 "show ip bgp dampening flap-statistics A.B.C.D/M",
11486 SHOW_STR
11487 IP_STR
11488 BGP_STR
11489 "Display detailed information about dampening\n"
11490 "Display flap statistics of routes\n"
11491 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11492
718e3744 11493#ifdef HAVE_IPV6
11494DEFUN (show_bgp_prefix_longer,
11495 show_bgp_prefix_longer_cmd,
11496 "show bgp X:X::X:X/M longer-prefixes",
11497 SHOW_STR
11498 BGP_STR
11499 "IPv6 prefix <network>/<length>\n"
11500 "Display route and more specific routes\n")
11501{
50ef26d4 11502 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 11503 bgp_show_type_prefix_longer);
11504}
11505
11506ALIAS (show_bgp_prefix_longer,
11507 show_bgp_ipv6_prefix_longer_cmd,
11508 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11509 SHOW_STR
11510 BGP_STR
11511 "Address family\n"
11512 "IPv6 prefix <network>/<length>\n"
11513 "Display route and more specific routes\n")
11514
11515/* old command */
11516DEFUN (show_ipv6_bgp_prefix_longer,
11517 show_ipv6_bgp_prefix_longer_cmd,
11518 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11519 SHOW_STR
11520 IPV6_STR
11521 BGP_STR
11522 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11523 "Display route and more specific routes\n")
11524{
47e9b292 11525 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 11526 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
718e3744 11527 bgp_show_type_prefix_longer);
11528}
11529
11530/* old command */
11531DEFUN (show_ipv6_mbgp_prefix_longer,
11532 show_ipv6_mbgp_prefix_longer_cmd,
11533 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11534 SHOW_STR
11535 IPV6_STR
11536 MBGP_STR
11537 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11538 "Display route and more specific routes\n")
11539{
47e9b292 11540 bgp_show_ipv6_bgp_deprecate_warning(vty);
50ef26d4 11541 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
718e3744 11542 bgp_show_type_prefix_longer);
11543}
11544#endif /* HAVE_IPV6 */
bb46e94f 11545
94f2b392 11546static struct peer *
fd79ac91 11547peer_lookup_in_view (struct vty *vty, const char *view_name,
856ca177 11548 const char *ip_str, u_char use_json)
bb46e94f 11549{
11550 int ret;
11551 struct bgp *bgp;
11552 struct peer *peer;
11553 union sockunion su;
11554
11555 /* BGP structure lookup. */
11556 if (view_name)
11557 {
11558 bgp = bgp_lookup_by_name (view_name);
11559 if (! bgp)
11560 {
856ca177
MS
11561 if (use_json)
11562 {
11563 json_object *json_no = NULL;
11564 json_no = json_object_new_object();
11565 json_object_string_add(json_no, "warning", "Can't find BGP view");
11566 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11567 json_object_free(json_no);
11568 }
11569 else
6aeb9e78 11570 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
bb46e94f 11571 return NULL;
11572 }
11573 }
5228ad27 11574 else
bb46e94f 11575 {
11576 bgp = bgp_get_default ();
11577 if (! bgp)
11578 {
856ca177
MS
11579 if (use_json)
11580 {
11581 json_object *json_no = NULL;
11582 json_no = json_object_new_object();
11583 json_object_string_add(json_no, "warning", "No BGP process configured");
11584 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11585 json_object_free(json_no);
11586 }
11587 else
11588 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
bb46e94f 11589 return NULL;
11590 }
11591 }
11592
11593 /* Get peer sockunion. */
11594 ret = str2sockunion (ip_str, &su);
11595 if (ret < 0)
11596 {
a80beece
DS
11597 peer = peer_lookup_by_conf_if (bgp, ip_str);
11598 if (!peer)
11599 {
04b6bdc0
DW
11600 peer = peer_lookup_by_hostname(bgp, ip_str);
11601
11602 if (!peer)
856ca177 11603 {
04b6bdc0
DW
11604 if (use_json)
11605 {
11606 json_object *json_no = NULL;
11607 json_no = json_object_new_object();
11608 json_object_string_add(json_no, "malformedAddressOrName", ip_str);
11609 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11610 json_object_free(json_no);
11611 }
11612 else
11613 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
11614 return NULL;
856ca177 11615 }
a80beece
DS
11616 }
11617 return peer;
bb46e94f 11618 }
11619
11620 /* Peer structure lookup. */
11621 peer = peer_lookup (bgp, &su);
11622 if (! peer)
11623 {
856ca177
MS
11624 if (use_json)
11625 {
11626 json_object *json_no = NULL;
11627 json_no = json_object_new_object();
11628 json_object_string_add(json_no, "warning","No such neighbor");
11629 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11630 json_object_free(json_no);
11631 }
11632 else
11633 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
bb46e94f 11634 return NULL;
11635 }
11636
11637 return peer;
11638}
6b0655a2 11639
2815e61f
PJ
11640enum bgp_stats
11641{
11642 BGP_STATS_MAXBITLEN = 0,
11643 BGP_STATS_RIB,
11644 BGP_STATS_PREFIXES,
11645 BGP_STATS_TOTPLEN,
11646 BGP_STATS_UNAGGREGATEABLE,
11647 BGP_STATS_MAX_AGGREGATEABLE,
11648 BGP_STATS_AGGREGATES,
11649 BGP_STATS_SPACE,
11650 BGP_STATS_ASPATH_COUNT,
11651 BGP_STATS_ASPATH_MAXHOPS,
11652 BGP_STATS_ASPATH_TOTHOPS,
11653 BGP_STATS_ASPATH_MAXSIZE,
11654 BGP_STATS_ASPATH_TOTSIZE,
11655 BGP_STATS_ASN_HIGHEST,
11656 BGP_STATS_MAX,
11657};
11658
11659static const char *table_stats_strs[] =
11660{
11661 [BGP_STATS_PREFIXES] = "Total Prefixes",
11662 [BGP_STATS_TOTPLEN] = "Average prefix length",
11663 [BGP_STATS_RIB] = "Total Advertisements",
11664 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11665 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11666 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11667 [BGP_STATS_SPACE] = "Address space advertised",
11668 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11669 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11670 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11671 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11672 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11673 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11674 [BGP_STATS_MAX] = NULL,
11675};
11676
11677struct bgp_table_stats
11678{
11679 struct bgp_table *table;
11680 unsigned long long counts[BGP_STATS_MAX];
11681};
11682
11683#if 0
11684#define TALLY_SIGFIG 100000
11685static unsigned long
11686ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11687{
11688 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11689 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11690 unsigned long ret = newtot / count;
11691
11692 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11693 return ret + 1;
11694 else
11695 return ret;
11696}
11697#endif
11698
11699static int
11700bgp_table_stats_walker (struct thread *t)
11701{
11702 struct bgp_node *rn;
11703 struct bgp_node *top;
11704 struct bgp_table_stats *ts = THREAD_ARG (t);
11705 unsigned int space = 0;
11706
53d9f67a
PJ
11707 if (!(top = bgp_table_top (ts->table)))
11708 return 0;
2815e61f
PJ
11709
11710 switch (top->p.family)
11711 {
11712 case AF_INET:
11713 space = IPV4_MAX_BITLEN;
11714 break;
11715 case AF_INET6:
11716 space = IPV6_MAX_BITLEN;
11717 break;
11718 }
11719
11720 ts->counts[BGP_STATS_MAXBITLEN] = space;
11721
11722 for (rn = top; rn; rn = bgp_route_next (rn))
11723 {
11724 struct bgp_info *ri;
67174041 11725 struct bgp_node *prn = bgp_node_parent_nolock (rn);
2815e61f
PJ
11726 unsigned int rinum = 0;
11727
11728 if (rn == top)
11729 continue;
11730
11731 if (!rn->info)
11732 continue;
11733
11734 ts->counts[BGP_STATS_PREFIXES]++;
11735 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11736
11737#if 0
11738 ts->counts[BGP_STATS_AVGPLEN]
11739 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11740 ts->counts[BGP_STATS_AVGPLEN],
11741 rn->p.prefixlen);
11742#endif
11743
11744 /* check if the prefix is included by any other announcements */
11745 while (prn && !prn->info)
67174041 11746 prn = bgp_node_parent_nolock (prn);
2815e61f
PJ
11747
11748 if (prn == NULL || prn == top)
8383a9bd
PJ
11749 {
11750 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11751 /* announced address space */
11752 if (space)
11753 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11754 }
2815e61f
PJ
11755 else if (prn->info)
11756 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11757
2815e61f
PJ
11758 for (ri = rn->info; ri; ri = ri->next)
11759 {
11760 rinum++;
11761 ts->counts[BGP_STATS_RIB]++;
11762
11763 if (ri->attr &&
11764 (CHECK_FLAG (ri->attr->flag,
11765 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11766 ts->counts[BGP_STATS_AGGREGATES]++;
11767
11768 /* as-path stats */
11769 if (ri->attr && ri->attr->aspath)
11770 {
11771 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11772 unsigned int size = aspath_size (ri->attr->aspath);
11773 as_t highest = aspath_highest (ri->attr->aspath);
11774
11775 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11776
11777 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11778 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11779
11780 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11781 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11782
11783 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11784 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11785#if 0
11786 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11787 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11788 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11789 hops);
11790 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11791 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11792 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11793 size);
11794#endif
11795 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11796 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11797 }
11798 }
11799 }
11800 return 0;
11801}
11802
11803static int
11804bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11805{
11806 struct bgp_table_stats ts;
11807 unsigned int i;
11808
11809 if (!bgp->rib[afi][safi])
11810 {
18200902 11811 vty_out (vty, "%% No RIB exists for the AFI(%d)/SAFI(%d)%s",
06da0daf 11812 afi, safi, VTY_NEWLINE);
2815e61f
PJ
11813 return CMD_WARNING;
11814 }
11815
11816 memset (&ts, 0, sizeof (ts));
11817 ts.table = bgp->rib[afi][safi];
87d4a781 11818 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
bb46e94f 11819
2815e61f
PJ
11820 vty_out (vty, "BGP %s RIB statistics%s%s",
11821 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11822
11823 for (i = 0; i < BGP_STATS_MAX; i++)
11824 {
11825 if (!table_stats_strs[i])
11826 continue;
11827
11828 switch (i)
11829 {
11830#if 0
11831 case BGP_STATS_ASPATH_AVGHOPS:
11832 case BGP_STATS_ASPATH_AVGSIZE:
11833 case BGP_STATS_AVGPLEN:
11834 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11835 vty_out (vty, "%12.2f",
11836 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11837 break;
11838#endif
11839 case BGP_STATS_ASPATH_TOTHOPS:
11840 case BGP_STATS_ASPATH_TOTSIZE:
11841 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11842 vty_out (vty, "%12.2f",
11843 ts.counts[i] ?
11844 (float)ts.counts[i] /
11845 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11846 : 0);
11847 break;
11848 case BGP_STATS_TOTPLEN:
11849 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11850 vty_out (vty, "%12.2f",
11851 ts.counts[i] ?
11852 (float)ts.counts[i] /
11853 (float)ts.counts[BGP_STATS_PREFIXES]
11854 : 0);
11855 break;
11856 case BGP_STATS_SPACE:
11857 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11858 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11859 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11860 break;
30a2231a 11861 vty_out (vty, "%30s: ", "%% announced ");
2815e61f
PJ
11862 vty_out (vty, "%12.2f%s",
11863 100 * (float)ts.counts[BGP_STATS_SPACE] /
56395af7 11864 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
2815e61f
PJ
11865 VTY_NEWLINE);
11866 vty_out (vty, "%30s: ", "/8 equivalent ");
11867 vty_out (vty, "%12.2f%s",
11868 (float)ts.counts[BGP_STATS_SPACE] /
11869 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11870 VTY_NEWLINE);
11871 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11872 break;
11873 vty_out (vty, "%30s: ", "/24 equivalent ");
11874 vty_out (vty, "%12.2f",
11875 (float)ts.counts[BGP_STATS_SPACE] /
11876 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11877 break;
11878 default:
11879 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11880 vty_out (vty, "%12llu", ts.counts[i]);
11881 }
11882
11883 vty_out (vty, "%s", VTY_NEWLINE);
11884 }
11885 return CMD_SUCCESS;
11886}
11887
11888static int
11889bgp_table_stats_vty (struct vty *vty, const char *name,
11890 const char *afi_str, const char *safi_str)
11891{
11892 struct bgp *bgp;
11893 afi_t afi;
11894 safi_t safi;
11895
11896 if (name)
11897 bgp = bgp_lookup_by_name (name);
11898 else
11899 bgp = bgp_get_default ();
11900
11901 if (!bgp)
11902 {
18200902 11903 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
2815e61f
PJ
11904 return CMD_WARNING;
11905 }
d02fbbdb
LB
11906 afi = bgp_vty_afi_from_arg(afi_str);
11907 if (afi == AFI_MAX)
2815e61f 11908 {
587ff0fd 11909 vty_out (vty, "%% Invalid address family \"%s\"%s",
2815e61f
PJ
11910 afi_str, VTY_NEWLINE);
11911 return CMD_WARNING;
11912 }
d02fbbdb
LB
11913 safi = bgp_vty_safi_from_arg(safi_str);
11914 if (safi == SAFI_MAX)
11915 {
11916 vty_out (vty, "%% Invalid subsequent address family %s%s",
11917 safi_str, VTY_NEWLINE);
11918 return CMD_WARNING;
11919 }
2815e61f 11920
2815e61f
PJ
11921 return bgp_table_stats (vty, bgp, afi, safi);
11922}
11923
11924DEFUN (show_bgp_statistics,
11925 show_bgp_statistics_cmd,
d02fbbdb 11926 "show bgp "BGP_AFI_SAFI_CMD_STR" statistics",
2815e61f
PJ
11927 SHOW_STR
11928 BGP_STR
4575cfc3 11929 BGP_AFI_SAFI_HELP_STR
2815e61f
PJ
11930 "BGP RIB advertisement statistics\n")
11931{
11932 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11933}
11934
2815e61f
PJ
11935DEFUN (show_bgp_statistics_view,
11936 show_bgp_statistics_view_cmd,
d02fbbdb 11937 "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" statistics",
2815e61f
PJ
11938 SHOW_STR
11939 BGP_STR
8386ac43 11940 BGP_INSTANCE_HELP_STR
d02fbbdb 11941 BGP_AFI_SAFI_HELP_STR
2815e61f
PJ
11942 "BGP RIB advertisement statistics\n")
11943{
6aeb9e78 11944 return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]);
2815e61f
PJ
11945}
11946
ff7924f6
PJ
11947enum bgp_pcounts
11948{
11949 PCOUNT_ADJ_IN = 0,
11950 PCOUNT_DAMPED,
11951 PCOUNT_REMOVED,
11952 PCOUNT_HISTORY,
11953 PCOUNT_STALE,
11954 PCOUNT_VALID,
11955 PCOUNT_ALL,
11956 PCOUNT_COUNTED,
11957 PCOUNT_PFCNT, /* the figure we display to users */
11958 PCOUNT_MAX,
11959};
11960
11961static const char *pcount_strs[] =
11962{
11963 [PCOUNT_ADJ_IN] = "Adj-in",
11964 [PCOUNT_DAMPED] = "Damped",
11965 [PCOUNT_REMOVED] = "Removed",
11966 [PCOUNT_HISTORY] = "History",
11967 [PCOUNT_STALE] = "Stale",
11968 [PCOUNT_VALID] = "Valid",
11969 [PCOUNT_ALL] = "All RIB",
11970 [PCOUNT_COUNTED] = "PfxCt counted",
11971 [PCOUNT_PFCNT] = "Useable",
11972 [PCOUNT_MAX] = NULL,
11973};
11974
2815e61f
PJ
11975struct peer_pcounts
11976{
11977 unsigned int count[PCOUNT_MAX];
11978 const struct peer *peer;
11979 const struct bgp_table *table;
11980};
11981
ff7924f6 11982static int
2815e61f 11983bgp_peer_count_walker (struct thread *t)
ff7924f6
PJ
11984{
11985 struct bgp_node *rn;
2815e61f
PJ
11986 struct peer_pcounts *pc = THREAD_ARG (t);
11987 const struct peer *peer = pc->peer;
ff7924f6 11988
2815e61f 11989 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
ff7924f6
PJ
11990 {
11991 struct bgp_adj_in *ain;
2815e61f 11992 struct bgp_info *ri;
ff7924f6
PJ
11993
11994 for (ain = rn->adj_in; ain; ain = ain->next)
11995 if (ain->peer == peer)
2815e61f 11996 pc->count[PCOUNT_ADJ_IN]++;
ff7924f6 11997
ff7924f6
PJ
11998 for (ri = rn->info; ri; ri = ri->next)
11999 {
12000 char buf[SU_ADDRSTRLEN];
12001
12002 if (ri->peer != peer)
12003 continue;
12004
2815e61f 12005 pc->count[PCOUNT_ALL]++;
ff7924f6
PJ
12006
12007 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
2815e61f 12008 pc->count[PCOUNT_DAMPED]++;
ff7924f6 12009 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2815e61f 12010 pc->count[PCOUNT_HISTORY]++;
ff7924f6 12011 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
2815e61f 12012 pc->count[PCOUNT_REMOVED]++;
ff7924f6 12013 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2815e61f 12014 pc->count[PCOUNT_STALE]++;
ff7924f6 12015 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
2815e61f 12016 pc->count[PCOUNT_VALID]++;
1a392d46 12017 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2815e61f 12018 pc->count[PCOUNT_PFCNT]++;
ff7924f6
PJ
12019
12020 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
12021 {
2815e61f 12022 pc->count[PCOUNT_COUNTED]++;
1a392d46 12023 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 12024 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
ff7924f6
PJ
12025 peer->host,
12026 inet_ntop(rn->p.family, &rn->p.u.prefix,
12027 buf, SU_ADDRSTRLEN),
12028 rn->p.prefixlen,
12029 ri->flags);
12030 }
12031 else
12032 {
1a392d46 12033 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 12034 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
ff7924f6
PJ
12035 peer->host,
12036 inet_ntop(rn->p.family, &rn->p.u.prefix,
12037 buf, SU_ADDRSTRLEN),
12038 rn->p.prefixlen,
12039 ri->flags);
12040 }
12041 }
12042 }
2815e61f
PJ
12043 return 0;
12044}
ff7924f6 12045
2815e61f 12046static int
856ca177 12047bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json)
2815e61f
PJ
12048{
12049 struct peer_pcounts pcounts = { .peer = peer };
12050 unsigned int i;
856ca177
MS
12051 json_object *json = NULL;
12052 json_object *json_loop = NULL;
12053
12054 if (use_json)
12055 {
12056 json = json_object_new_object();
12057 json_loop = json_object_new_object();
12058 }
2815e61f
PJ
12059
12060 if (!peer || !peer->bgp || !peer->afc[afi][safi]
12061 || !peer->bgp->rib[afi][safi])
12062 {
856ca177
MS
12063 if (use_json)
12064 {
12065 json_object_string_add(json, "warning", "No such neighbor or address family");
2aac5767 12066 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
856ca177
MS
12067 json_object_free(json);
12068 }
12069 else
12070 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12071
2815e61f
PJ
12072 return CMD_WARNING;
12073 }
12074
12075 memset (&pcounts, 0, sizeof(pcounts));
12076 pcounts.peer = peer;
12077 pcounts.table = peer->bgp->rib[afi][safi];
12078
12079 /* in-place call via thread subsystem so as to record execution time
856ca177
MS
12080 * * stats for the thread-walk (i.e. ensure this can't be blamed on
12081 * * on just vty_read()).
12082 * */
87d4a781 12083 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
6410e93a 12084
856ca177
MS
12085 if (use_json)
12086 {
12087 json_object_string_add(json, "prefixCountsFor", peer->host);
12088 json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi));
12089 json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]);
12090
12091 for (i = 0; i < PCOUNT_MAX; i++)
12092 json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]);
ff7924f6 12093
856ca177 12094 json_object_object_add(json, "ribTableWalkCounters", json_loop);
ff7924f6 12095
856ca177
MS
12096 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
12097 {
12098 json_object_string_add(json, "pfxctDriftFor", peer->host);
12099 json_object_string_add(json, "recommended", "Please report this bug, with the above command output");
12100 }
2aac5767 12101 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
856ca177
MS
12102 json_object_free(json);
12103 }
12104 else
ff7924f6 12105 {
04b6bdc0
DW
12106
12107 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
12108 {
12109 vty_out (vty, "Prefix counts for %s/%s, %s%s",
12110 peer->hostname, peer->host, afi_safi_print (afi, safi),
12111 VTY_NEWLINE);
12112 }
12113 else
12114 {
12115 vty_out (vty, "Prefix counts for %s, %s%s",
12116 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
12117 }
12118
856ca177
MS
12119 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
12120 vty_out (vty, "%sCounts from RIB table walk:%s%s",
12121 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12122
12123 for (i = 0; i < PCOUNT_MAX; i++)
12124 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
12125
12126 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
12127 {
12128 vty_out (vty, "%s [pcount] PfxCt drift!%s",
12129 peer->host, VTY_NEWLINE);
12130 vty_out (vty, "Please report this bug, with the above command output%s",
12131 VTY_NEWLINE);
12132 }
ff7924f6
PJ
12133 }
12134
12135 return CMD_SUCCESS;
12136}
12137
12138DEFUN (show_ip_bgp_neighbor_prefix_counts,
12139 show_ip_bgp_neighbor_prefix_counts_cmd,
856ca177 12140 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
12141 SHOW_STR
12142 IP_STR
12143 BGP_STR
12144 "Detailed information on TCP and BGP neighbor connections\n"
12145 "Neighbor to display information about\n"
12146 "Neighbor to display information about\n"
a80beece 12147 "Neighbor on bgp configured interface\n"
856ca177
MS
12148 "Display detailed prefix count information\n"
12149 "JavaScript Object Notation\n")
ff7924f6
PJ
12150{
12151 struct peer *peer;
db7c8528 12152 u_char uj = use_json(argc, argv);
ff7924f6 12153
db7c8528 12154 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
ff7924f6
PJ
12155 if (! peer)
12156 return CMD_WARNING;
12157
db7c8528 12158 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
ff7924f6
PJ
12159}
12160
8386ac43 12161DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
12162 show_ip_bgp_instance_neighbor_prefix_counts_cmd,
12163 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
50ef26d4 12164 SHOW_STR
12165 IP_STR
12166 BGP_STR
8386ac43 12167 BGP_INSTANCE_HELP_STR
50ef26d4 12168 "Detailed information on TCP and BGP neighbor connections\n"
12169 "Neighbor to display information about\n"
12170 "Neighbor to display information about\n"
12171 "Neighbor on bgp configured interface\n"
12172 "Display detailed prefix count information\n"
12173 "JavaScript Object Notation\n")
12174{
12175 struct peer *peer;
12176 u_char uj = use_json(argc, argv);
12177
12178 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12179 if (! peer)
12180 return CMD_WARNING;
12181
12182 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
12183}
12184
ff7924f6
PJ
12185DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12186 show_bgp_ipv6_neighbor_prefix_counts_cmd,
856ca177 12187 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
12188 SHOW_STR
12189 BGP_STR
12190 "Address family\n"
12191 "Detailed information on TCP and BGP neighbor connections\n"
12192 "Neighbor to display information about\n"
12193 "Neighbor to display information about\n"
a80beece 12194 "Neighbor on bgp configured interface\n"
856ca177
MS
12195 "Display detailed prefix count information\n"
12196 "JavaScript Object Notation\n")
ff7924f6
PJ
12197{
12198 struct peer *peer;
db7c8528 12199 u_char uj = use_json(argc, argv);
856ca177 12200
db7c8528 12201 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
ff7924f6
PJ
12202 if (! peer)
12203 return CMD_WARNING;
12204
db7c8528 12205 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
ff7924f6
PJ
12206}
12207
8386ac43 12208DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts,
12209 show_bgp_instance_ipv6_neighbor_prefix_counts_cmd,
12210 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
50ef26d4 12211 SHOW_STR
12212 BGP_STR
8386ac43 12213 BGP_INSTANCE_HELP_STR
50ef26d4 12214 "Address family\n"
12215 "Detailed information on TCP and BGP neighbor connections\n"
12216 "Neighbor to display information about\n"
12217 "Neighbor to display information about\n"
12218 "Neighbor on bgp configured interface\n"
12219 "Display detailed prefix count information\n"
12220 "JavaScript Object Notation\n")
12221{
12222 struct peer *peer;
12223 u_char uj = use_json(argc, argv);
12224
12225 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12226 if (! peer)
12227 return CMD_WARNING;
12228
12229 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
12230}
12231
ff7924f6
PJ
12232DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12233 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
4575cfc3 12234 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
ff7924f6
PJ
12235 SHOW_STR
12236 IP_STR
12237 BGP_STR
12238 "Address family\n"
4575cfc3
LB
12239 "Address Family modifier\n"
12240 "Address Family modifier\n"
ff7924f6
PJ
12241 "Detailed information on TCP and BGP neighbor connections\n"
12242 "Neighbor to display information about\n"
12243 "Neighbor to display information about\n"
a80beece 12244 "Neighbor on bgp configured interface\n"
856ca177
MS
12245 "Display detailed prefix count information\n"
12246 "JavaScript Object Notation\n")
ff7924f6
PJ
12247{
12248 struct peer *peer;
db7c8528 12249 u_char uj = use_json(argc, argv);
ff7924f6 12250
db7c8528 12251 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
ff7924f6
PJ
12252 if (! peer)
12253 return CMD_WARNING;
12254
d02fbbdb
LB
12255 safi_t safi;
12256 safi = bgp_vty_safi_from_arg(argv[0]);
12257 return bgp_peer_counts (vty, peer, AFI_IP, safi, uj);
ff7924f6
PJ
12258}
12259
94f2b392 12260static void
718e3744 12261show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
856ca177 12262 int in, const char *rmap_name, u_char use_json, json_object *json)
718e3744 12263{
12264 struct bgp_table *table;
12265 struct bgp_adj_in *ain;
12266 struct bgp_adj_out *adj;
12267 unsigned long output_count;
0b16f239 12268 unsigned long filtered_count;
718e3744 12269 struct bgp_node *rn;
12270 int header1 = 1;
12271 struct bgp *bgp;
12272 int header2 = 1;
0b16f239
DS
12273 struct attr attr;
12274 struct attr_extra extra;
12275 int ret;
840fced9 12276 struct update_subgroup *subgrp;
856ca177
MS
12277 json_object *json_scode = NULL;
12278 json_object *json_ocode = NULL;
12279 json_object *json_ar = NULL;
adbac85e 12280 struct peer_af *paf;
856ca177
MS
12281
12282 if (use_json)
12283 {
12284 json_scode = json_object_new_object();
12285 json_ocode = json_object_new_object();
12286 json_ar = json_object_new_object();
12287
12288 json_object_string_add(json_scode, "suppressed", "s");
12289 json_object_string_add(json_scode, "damped", "d");
12290 json_object_string_add(json_scode, "history", "h");
12291 json_object_string_add(json_scode, "valid", "*");
12292 json_object_string_add(json_scode, "best", ">");
12293 json_object_string_add(json_scode, "multipath", "=");
12294 json_object_string_add(json_scode, "internal", "i");
12295 json_object_string_add(json_scode, "ribFailure", "r");
12296 json_object_string_add(json_scode, "stale", "S");
12297 json_object_string_add(json_scode, "removed", "R");
12298
12299 json_object_string_add(json_ocode, "igp", "i");
12300 json_object_string_add(json_ocode, "egp", "e");
12301 json_object_string_add(json_ocode, "incomplete", "?");
12302 }
718e3744 12303
bb46e94f 12304 bgp = peer->bgp;
718e3744 12305
12306 if (! bgp)
856ca177
MS
12307 {
12308 if (use_json)
12309 {
12310 json_object_string_add(json, "alert", "no BGP");
2aac5767 12311 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
856ca177
MS
12312 json_object_free(json);
12313 }
12314 else
12315 vty_out (vty, "%% No bgp%s", VTY_NEWLINE);
12316 return;
12317 }
718e3744 12318
12319 table = bgp->rib[afi][safi];
12320
0b16f239 12321 output_count = filtered_count = 0;
840fced9 12322 subgrp = peer_subgroup(peer, afi, safi);
47fc97cc 12323
840fced9 12324 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
718e3744 12325 {
856ca177
MS
12326 if (use_json)
12327 {
12328 json_object_int_add(json, "bgpTableVersion", table->version);
12329 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12330 json_object_object_add(json, "bgpStatusCodes", json_scode);
12331 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12332 json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0");
12333 }
12334 else
12335 {
12336 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
12337 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12338 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 12339
856ca177
MS
12340 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12341 VTY_NEWLINE, VTY_NEWLINE);
12342 }
718e3744 12343 header1 = 0;
12344 }
12345
0b16f239 12346 attr.extra = &extra;
718e3744 12347 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
856ca177
MS
12348 {
12349 if (in)
12350 {
12351 for (ain = rn->adj_in; ain; ain = ain->next)
12352 {
12353 if (ain->peer == peer)
12354 {
12355 if (header1)
12356 {
12357 if (use_json)
12358 {
12359 json_object_int_add(json, "bgpTableVersion", 0);
12360 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12361 json_object_object_add(json, "bgpStatusCodes", json_scode);
12362 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12363 }
12364 else
12365 {
12366 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
12367 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12368 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12369 }
12370 header1 = 0;
12371 }
12372 if (header2)
12373 {
12374 if (!use_json)
12375 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12376 header2 = 0;
12377 }
12378 if (ain->attr)
12379 {
12380 bgp_attr_dup(&attr, ain->attr);
12381 if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY)
12382 {
12383 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12384 output_count++;
12385 }
12386 else
12387 filtered_count++;
12388 }
12389 }
12390 }
12391 }
12392 else
12393 {
adbac85e
DW
12394 for (adj = rn->adj_out; adj; adj = adj->next)
12395 SUBGRP_FOREACH_PEER(adj->subgroup, paf)
12396 if (paf->peer == peer)
856ca177 12397 {
adbac85e 12398 if (header1)
856ca177 12399 {
adbac85e
DW
12400 if (use_json)
12401 {
12402 json_object_int_add(json, "bgpTableVersion", table->version);
12403 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12404 json_object_object_add(json, "bgpStatusCodes", json_scode);
12405 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12406 }
12407 else
12408 {
12409 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version,
12410 inet_ntoa (bgp->router_id), VTY_NEWLINE);
12411 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12412 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12413 }
12414 header1 = 0;
856ca177 12415 }
adbac85e
DW
12416
12417 if (header2)
856ca177 12418 {
adbac85e
DW
12419 if (!use_json)
12420 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12421 header2 = 0;
856ca177 12422 }
adbac85e
DW
12423
12424 if (adj->attr)
856ca177 12425 {
adbac85e
DW
12426 bgp_attr_dup(&attr, adj->attr);
12427 ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name);
12428 if (ret != RMAP_DENY)
12429 {
12430 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12431 output_count++;
12432 }
12433 else
12434 filtered_count++;
856ca177 12435 }
856ca177 12436 }
856ca177
MS
12437 }
12438 }
12439 if (use_json)
12440 json_object_object_add(json, "advertisedRoutes", json_ar);
47fc97cc 12441
718e3744 12442 if (output_count != 0)
856ca177
MS
12443 {
12444 if (use_json)
12445 json_object_int_add(json, "totalPrefixCounter", output_count);
12446 else
12447 vty_out (vty, "%sTotal number of prefixes %ld%s",
12448 VTY_NEWLINE, output_count, VTY_NEWLINE);
12449 }
12450 if (use_json)
12451 {
2aac5767 12452 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
856ca177
MS
12453 json_object_free(json);
12454 }
12455
718e3744 12456}
12457
94f2b392 12458static int
47fc97cc 12459peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
856ca177
MS
12460 int in, const char *rmap_name, u_char use_json)
12461{
12462 json_object *json = NULL;
12463
12464 if (use_json)
12465 json = json_object_new_object();
12466
12467 if (!peer || !peer->afc[afi][safi])
718e3744 12468 {
856ca177
MS
12469 if (use_json)
12470 {
12471 json_object_string_add(json, "warning", "No such neighbor or address family");
2aac5767 12472 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
856ca177
MS
12473 json_object_free(json);
12474 }
12475 else
12476 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12477
718e3744 12478 return CMD_WARNING;
12479 }
12480
856ca177 12481 if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
718e3744 12482 {
856ca177
MS
12483 if (use_json)
12484 {
12485 json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
2aac5767 12486 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
856ca177
MS
12487 json_object_free(json);
12488 }
12489 else
12490 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE);
12491
718e3744 12492 return CMD_WARNING;
12493 }
12494
856ca177 12495 show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json);
718e3744 12496
12497 return CMD_SUCCESS;
12498}
12499
8386ac43 12500DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
12501 show_ip_bgp_instance_neighbor_advertised_route_cmd,
12502 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12503 SHOW_STR
12504 IP_STR
12505 BGP_STR
8386ac43 12506 BGP_INSTANCE_HELP_STR
718e3744 12507 "Detailed information on TCP and BGP neighbor connections\n"
12508 "Neighbor to display information about\n"
12509 "Neighbor to display information about\n"
856ca177
MS
12510 "Display the routes advertised to a BGP neighbor\n"
12511 "JavaScript Object Notation\n")
718e3744 12512{
bb46e94f 12513 struct peer *peer;
db7c8528 12514 u_char uj = use_json(argc, argv);
856ca177 12515
6aeb9e78
DS
12516 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12517 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
2a71e9ce 12518 else
6aeb9e78 12519 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
2a71e9ce 12520
bb46e94f 12521 if (! peer)
12522 return CMD_WARNING;
0b16f239 12523
db7c8528 12524 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj);
718e3744 12525}
12526
0b16f239 12527DEFUN (show_ip_bgp_neighbor_advertised_route,
2a71e9ce 12528 show_ip_bgp_neighbor_advertised_route_cmd,
856ca177 12529 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
2a71e9ce
TP
12530 SHOW_STR
12531 IP_STR
12532 BGP_STR
12533 "Detailed information on TCP and BGP neighbor connections\n"
12534 "Neighbor to display information about\n"
12535 "Neighbor to display information about\n"
a80beece 12536 "Neighbor on bgp configured interface\n"
856ca177
MS
12537 "Display the routes advertised to a BGP neighbor\n"
12538 "JavaScript Object Notation\n")
2a71e9ce 12539
0b16f239
DS
12540{
12541 struct peer *peer;
ffd0c037 12542 const char *rmap_name = NULL;
db7c8528 12543 u_char uj = use_json(argc, argv);
0b16f239 12544
db7c8528 12545 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
0b16f239
DS
12546
12547 if (! peer)
12548 return CMD_WARNING;
12549
856ca177
MS
12550 if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)
12551 || (argc == 3))
0b16f239
DS
12552 rmap_name = argv[1];
12553
db7c8528 12554 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
0b16f239
DS
12555}
12556
12557ALIAS (show_ip_bgp_neighbor_advertised_route,
12558 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
856ca177 12559 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
0b16f239
DS
12560 SHOW_STR
12561 IP_STR
12562 BGP_STR
12563 "Detailed information on TCP and BGP neighbor connections\n"
12564 "Neighbor to display information about\n"
12565 "Neighbor to display information about\n"
12566 "Neighbor on bgp configured interface\n"
856ca177
MS
12567 "Display the routes advertised to a BGP neighbor\n"
12568 "JavaScript Object Notation\n")
0b16f239 12569
8386ac43 12570ALIAS (show_ip_bgp_instance_neighbor_advertised_route,
12571 show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd,
12572 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
50ef26d4 12573 SHOW_STR
12574 IP_STR
12575 BGP_STR
8386ac43 12576 BGP_INSTANCE_HELP_STR
50ef26d4 12577 "Detailed information on TCP and BGP neighbor connections\n"
12578 "Neighbor to display information about\n"
12579 "Neighbor to display information about\n"
12580 "Neighbor on bgp configured interface\n"
12581 "Display the routes advertised to a BGP neighbor\n"
12582 "JavaScript Object Notation\n")
718e3744 12583DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12584 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
4575cfc3 12585 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12586 SHOW_STR
12587 IP_STR
12588 BGP_STR
12589 "Address family\n"
4575cfc3
LB
12590 "Address Family modifier\n"
12591 "Address Family modifier\n"
718e3744 12592 "Detailed information on TCP and BGP neighbor connections\n"
12593 "Neighbor to display information about\n"
12594 "Neighbor to display information about\n"
a80beece 12595 "Neighbor on bgp configured interface\n"
856ca177
MS
12596 "Display the routes advertised to a BGP neighbor\n"
12597 "JavaScript Object Notation\n")
718e3744 12598{
bb46e94f 12599 struct peer *peer;
ffd0c037 12600 const char *rmap_name = NULL;
d02fbbdb
LB
12601 safi_t safi;
12602
db7c8528 12603 u_char uj = use_json(argc, argv);
856ca177 12604
db7c8528 12605 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 12606 if (! peer)
12607 return CMD_WARNING;
12608
856ca177 12609 if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
0b16f239
DS
12610 rmap_name = argv[2];
12611
d02fbbdb
LB
12612 safi = bgp_vty_safi_from_arg(argv[0]);
12613 return peer_adj_routes (vty, peer, AFI_IP, safi, 0, rmap_name, uj);
718e3744 12614}
12615
0b16f239
DS
12616ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
12617 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
4575cfc3 12618 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
0b16f239
DS
12619 SHOW_STR
12620 IP_STR
12621 BGP_STR
12622 "Address family\n"
4575cfc3
LB
12623 "Address Family modifier\n"
12624 "Address Family modifier\n"
0b16f239
DS
12625 "Detailed information on TCP and BGP neighbor connections\n"
12626 "Neighbor to display information about\n"
12627 "Neighbor to display information about\n"
12628 "Neighbor on bgp configured interface\n"
12629 "Display the routes advertised to a BGP neighbor\n"
856ca177
MS
12630 "Route-map to control what is displayed\n"
12631 "JavaScript Object Notation\n")
0b16f239 12632
718e3744 12633#ifdef HAVE_IPV6
8386ac43 12634DEFUN (show_bgp_instance_neighbor_advertised_route,
12635 show_bgp_instance_neighbor_advertised_route_cmd,
12636 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12637 SHOW_STR
12638 BGP_STR
8386ac43 12639 BGP_INSTANCE_HELP_STR
718e3744 12640 "Detailed information on TCP and BGP neighbor connections\n"
12641 "Neighbor to display information about\n"
12642 "Neighbor to display information about\n"
a80beece 12643 "Neighbor on bgp configured interface\n"
856ca177
MS
12644 "Display the routes advertised to a BGP neighbor\n"
12645 "JavaScript Object Notation\n")
718e3744 12646{
bb46e94f 12647 struct peer *peer;
db7c8528 12648 u_char uj = use_json(argc, argv);
856ca177 12649
6aeb9e78
DS
12650 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12651 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
bb46e94f 12652 else
6aeb9e78 12653 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 12654
12655 if (! peer)
0b16f239 12656 return CMD_WARNING;
bb46e94f 12657
db7c8528 12658 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj);
47fc97cc
DS
12659}
12660
8386ac43 12661ALIAS (show_bgp_instance_neighbor_advertised_route,
12662 show_bgp_instance_ipv6_neighbor_advertised_route_cmd,
12663 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
0b16f239
DS
12664 SHOW_STR
12665 BGP_STR
8386ac43 12666 BGP_INSTANCE_HELP_STR
0b16f239
DS
12667 "Address family\n"
12668 "Detailed information on TCP and BGP neighbor connections\n"
12669 "Neighbor to display information about\n"
12670 "Neighbor to display information about\n"
12671 "Neighbor on bgp configured interface\n"
856ca177
MS
12672 "Display the routes advertised to a BGP neighbor\n"
12673 "JavaScript Object Notation\n")
0b16f239 12674
0b16f239
DS
12675DEFUN (show_bgp_neighbor_advertised_route,
12676 show_bgp_neighbor_advertised_route_cmd,
856ca177 12677 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
bb46e94f 12678 SHOW_STR
12679 BGP_STR
bb46e94f 12680 "Detailed information on TCP and BGP neighbor connections\n"
12681 "Neighbor to display information about\n"
12682 "Neighbor to display information about\n"
a80beece 12683 "Neighbor on bgp configured interface\n"
856ca177
MS
12684 "Display the routes advertised to a BGP neighbor\n"
12685 "JavaScript Object Notation\n")
0b16f239 12686
bb46e94f 12687{
12688 struct peer *peer;
ffd0c037 12689 const char *rmap_name = NULL;
db7c8528 12690 u_char uj = use_json(argc, argv);
bb46e94f 12691
db7c8528 12692 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
856ca177
MS
12693
12694 if (!peer)
bb46e94f 12695 return CMD_WARNING;
12696
856ca177 12697 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
0b16f239
DS
12698 rmap_name = argv[1];
12699
db7c8528 12700 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj);
718e3744 12701}
12702
0b16f239
DS
12703ALIAS (show_bgp_neighbor_advertised_route,
12704 show_bgp_ipv6_neighbor_advertised_route_cmd,
856ca177 12705 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12706 SHOW_STR
12707 BGP_STR
12708 "Address family\n"
12709 "Detailed information on TCP and BGP neighbor connections\n"
12710 "Neighbor to display information about\n"
12711 "Neighbor to display information about\n"
a80beece 12712 "Neighbor on bgp configured interface\n"
856ca177
MS
12713 "Display the routes advertised to a BGP neighbor\n"
12714 "JavaScript Object Notation\n")
718e3744 12715
12716/* old command */
0b16f239 12717ALIAS (show_bgp_neighbor_advertised_route,
718e3744 12718 ipv6_bgp_neighbor_advertised_route_cmd,
856ca177 12719 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12720 SHOW_STR
12721 IPV6_STR
12722 BGP_STR
12723 "Detailed information on TCP and BGP neighbor connections\n"
12724 "Neighbor to display information about\n"
12725 "Neighbor to display information about\n"
a80beece 12726 "Neighbor on bgp configured interface\n"
856ca177
MS
12727 "Display the routes advertised to a BGP neighbor\n"
12728 "JavaScript Object Notation\n")
bb46e94f 12729
718e3744 12730/* old command */
12731DEFUN (ipv6_mbgp_neighbor_advertised_route,
12732 ipv6_mbgp_neighbor_advertised_route_cmd,
856ca177 12733 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
718e3744 12734 SHOW_STR
12735 IPV6_STR
12736 MBGP_STR
12737 "Detailed information on TCP and BGP neighbor connections\n"
12738 "Neighbor to display information about\n"
12739 "Neighbor to display information about\n"
a80beece
DS
12740 "Neighbor on bgp configured interface\n"
12741 "Neighbor on bgp configured interface\n"
856ca177
MS
12742 "Display the routes advertised to a BGP neighbor\n"
12743 "JavaScript Object Notation\n")
718e3744 12744{
bb46e94f 12745 struct peer *peer;
db7c8528 12746 u_char uj = use_json(argc, argv);
856ca177 12747
db7c8528 12748 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 12749 if (! peer)
856ca177 12750 return CMD_WARNING;
bb46e94f 12751
47e9b292 12752 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 12753 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj);
718e3744 12754}
12755#endif /* HAVE_IPV6 */
6b0655a2 12756
8386ac43 12757DEFUN (show_bgp_instance_neighbor_received_routes,
12758 show_bgp_instance_neighbor_received_routes_cmd,
12759 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
0b16f239
DS
12760 SHOW_STR
12761 BGP_STR
8386ac43 12762 BGP_INSTANCE_HELP_STR
0b16f239
DS
12763 "Detailed information on TCP and BGP neighbor connections\n"
12764 "Neighbor to display information about\n"
12765 "Neighbor to display information about\n"
12766 "Neighbor on bgp configured interface\n"
856ca177
MS
12767 "Display the received routes from neighbor\n"
12768 "JavaScript Object Notation\n")
0b16f239
DS
12769{
12770 struct peer *peer;
db7c8528 12771 u_char uj = use_json(argc, argv);
856ca177 12772
50ef26d4 12773 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
0b16f239
DS
12774 if (! peer)
12775 return CMD_WARNING;
12776
db7c8528 12777 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj);
0b16f239
DS
12778}
12779
8386ac43 12780DEFUN (show_ip_bgp_instance_neighbor_received_routes,
12781 show_ip_bgp_instance_neighbor_received_routes_cmd,
12782 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 12783 SHOW_STR
12784 IP_STR
12785 BGP_STR
8386ac43 12786 BGP_INSTANCE_HELP_STR
718e3744 12787 "Detailed information on TCP and BGP neighbor connections\n"
12788 "Neighbor to display information about\n"
12789 "Neighbor to display information about\n"
a80beece 12790 "Neighbor on bgp configured interface\n"
856ca177
MS
12791 "Display the received routes from neighbor\n"
12792 "JavaScript Object Notation\n")
718e3744 12793{
bb46e94f 12794 struct peer *peer;
db7c8528 12795 u_char uj = use_json(argc, argv);
856ca177 12796
50ef26d4 12797 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
bb46e94f 12798 if (! peer)
12799 return CMD_WARNING;
12800
db7c8528 12801 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj);
718e3744 12802}
12803
8386ac43 12804ALIAS (show_bgp_instance_neighbor_received_routes,
12805 show_bgp_instance_ipv6_neighbor_received_routes_cmd,
12806 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
0b16f239
DS
12807 SHOW_STR
12808 BGP_STR
8386ac43 12809 BGP_INSTANCE_HELP_STR
0b16f239
DS
12810 "Address family\n"
12811 "Detailed information on TCP and BGP neighbor connections\n"
12812 "Neighbor to display information about\n"
12813 "Neighbor to display information about\n"
12814 "Neighbor on bgp configured interface\n"
856ca177
MS
12815 "Display the received routes from neighbor\n"
12816 "JavaScript Object Notation\n")
0b16f239
DS
12817
12818DEFUN (show_ip_bgp_neighbor_received_routes,
2a71e9ce 12819 show_ip_bgp_neighbor_received_routes_cmd,
856ca177 12820 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
2a71e9ce
TP
12821 SHOW_STR
12822 IP_STR
12823 BGP_STR
12824 "Detailed information on TCP and BGP neighbor connections\n"
12825 "Neighbor to display information about\n"
12826 "Neighbor to display information about\n"
a80beece 12827 "Neighbor on bgp configured interface\n"
856ca177
MS
12828 "Display the received routes from neighbor\n"
12829 "JavaScript Object Notation\n")
2a71e9ce 12830
0b16f239
DS
12831{
12832 struct peer *peer;
ffd0c037 12833 const char *rmap_name = NULL;
db7c8528 12834 u_char uj = use_json(argc, argv);
0b16f239 12835
db7c8528 12836 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
0b16f239
DS
12837
12838 if (! peer)
12839 return CMD_WARNING;
12840
856ca177 12841 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
0b16f239
DS
12842 rmap_name = argv[1];
12843
db7c8528 12844 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
0b16f239
DS
12845}
12846
12847ALIAS (show_ip_bgp_neighbor_received_routes,
12848 show_ip_bgp_neighbor_received_routes_rmap_cmd,
856ca177 12849 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
0b16f239
DS
12850 SHOW_STR
12851 IP_STR
12852 BGP_STR
12853 "Detailed information on TCP and BGP neighbor connections\n"
12854 "Neighbor to display information about\n"
12855 "Neighbor to display information about\n"
12856 "Neighbor on bgp configured interface\n"
856ca177
MS
12857 "Display the received routes from neighbor\n"
12858 "JavaScript Object Notation\n")
0b16f239 12859
8386ac43 12860ALIAS (show_ip_bgp_instance_neighbor_received_routes,
12861 show_ip_bgp_instance_neighbor_received_routes_rmap_cmd,
12862 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
50ef26d4 12863 SHOW_STR
12864 IP_STR
12865 BGP_STR
8386ac43 12866 BGP_INSTANCE_HELP_STR
50ef26d4 12867 "Detailed information on TCP and BGP neighbor connections\n"
12868 "Neighbor to display information about\n"
12869 "Neighbor to display information about\n"
12870 "Neighbor on bgp configured interface\n"
12871 "Display the received routes from neighbor\n"
12872 "JavaScript Object Notation\n")
12873
718e3744 12874DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12875 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
4575cfc3 12876 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 12877 SHOW_STR
12878 IP_STR
12879 BGP_STR
12880 "Address family\n"
4575cfc3
LB
12881 "Address Family modifier\n"
12882 "Address Family modifier\n"
718e3744 12883 "Detailed information on TCP and BGP neighbor connections\n"
12884 "Neighbor to display information about\n"
12885 "Neighbor to display information about\n"
a80beece 12886 "Neighbor on bgp configured interface\n"
856ca177
MS
12887 "Display the received routes from neighbor\n"
12888 "JavaScript Object Notation\n")
718e3744 12889{
bb46e94f 12890 struct peer *peer;
ffd0c037 12891 const char *rmap_name = NULL;
d02fbbdb 12892 safi_t safi;
db7c8528 12893 u_char uj = use_json(argc, argv);
bb46e94f 12894
db7c8528 12895 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 12896 if (! peer)
12897 return CMD_WARNING;
0b16f239 12898
856ca177 12899 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
0b16f239
DS
12900 rmap_name = argv[2];
12901
d02fbbdb
LB
12902 safi = bgp_vty_safi_from_arg(argv[0]);
12903 return peer_adj_routes (vty, peer, AFI_IP, safi, 1, rmap_name, uj);
718e3744 12904}
12905
0b16f239
DS
12906ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
12907 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
4575cfc3 12908 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
0b16f239
DS
12909 SHOW_STR
12910 IP_STR
12911 BGP_STR
12912 "Address family\n"
4575cfc3
LB
12913 "Address Family modifier\n"
12914 "Address Family modifier\n"
0b16f239
DS
12915 "Detailed information on TCP and BGP neighbor connections\n"
12916 "Neighbor to display information about\n"
12917 "Neighbor to display information about\n"
12918 "Neighbor on bgp configured interface\n"
856ca177
MS
12919 "Display the received routes from neighbor\n"
12920 "JavaScript Object Notation\n")
0b16f239 12921
8386ac43 12922DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes,
12923 show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd,
4575cfc3 12924 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
95cbbd2a
ML
12925 SHOW_STR
12926 BGP_STR
8386ac43 12927 BGP_INSTANCE_HELP_STR
4575cfc3
LB
12928 "Address family\n"
12929 "Address family\n"
12930 "Address family modifier\n"
12931 "Address family modifier\n"
95cbbd2a
ML
12932 "Detailed information on TCP and BGP neighbor connections\n"
12933 "Neighbor to display information about\n"
12934 "Neighbor to display information about\n"
a80beece 12935 "Neighbor on bgp configured interface\n"
95cbbd2a 12936 "Display the advertised routes to neighbor\n"
856ca177
MS
12937 "Display the received routes from neighbor\n"
12938 "JavaScript Object Notation\n")
95cbbd2a
ML
12939{
12940 int afi;
12941 int safi;
12942 int in;
12943 struct peer *peer;
db7c8528 12944 u_char uj = use_json(argc, argv);
856ca177 12945
6aeb9e78 12946 peer = peer_lookup_in_view (vty, argv[1], argv[4], uj);
95cbbd2a
ML
12947
12948 if (! peer)
12949 return CMD_WARNING;
12950
d02fbbdb
LB
12951 afi = bgp_vty_safi_from_arg(argv[2]);
12952 safi = bgp_vty_safi_from_arg(argv[3]);
6aeb9e78 12953 in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0;
95cbbd2a 12954
db7c8528 12955 return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj);
95cbbd2a
ML
12956}
12957
718e3744 12958DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12959 show_ip_bgp_neighbor_received_prefix_filter_cmd,
856ca177 12960 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 12961 SHOW_STR
12962 IP_STR
12963 BGP_STR
12964 "Detailed information on TCP and BGP neighbor connections\n"
12965 "Neighbor to display information about\n"
12966 "Neighbor to display information about\n"
a80beece 12967 "Neighbor on bgp configured interface\n"
718e3744 12968 "Display information received from a BGP neighbor\n"
856ca177
MS
12969 "Display the prefixlist filter\n"
12970 "JavaScript Object Notation\n")
718e3744 12971{
12972 char name[BUFSIZ];
c63b83fe 12973 union sockunion su;
718e3744 12974 struct peer *peer;
c63b83fe 12975 int count, ret;
db7c8528 12976 u_char uj = use_json(argc, argv);
718e3744 12977
c63b83fe
JBD
12978 ret = str2sockunion (argv[0], &su);
12979 if (ret < 0)
12980 {
a80beece 12981 peer = peer_lookup_by_conf_if (NULL, argv[0]);
856ca177 12982 if (! peer)
a80beece 12983 {
db7c8528 12984 if (uj)
856ca177
MS
12985 {
12986 json_object *json_no = NULL;
12987 json_object *json_sub = NULL;
12988 json_no = json_object_new_object();
12989 json_sub = json_object_new_object();
12990 json_object_string_add(json_no, "warning", "Malformed address or name");
12991 json_object_string_add(json_sub, "warningCause", argv[0]);
12992 json_object_object_add(json_no, "detail", json_sub);
12993 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12994 json_object_free(json_no);
12995 }
12996 else
12997 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
a80beece
DS
12998 return CMD_WARNING;
12999 }
13000 }
13001 else
13002 {
13003 peer = peer_lookup (NULL, &su);
13004 if (! peer)
856ca177 13005 {
db7c8528 13006 if (uj)
856ca177
MS
13007 {
13008 json_object *json_no = NULL;
13009 json_no = json_object_new_object();
13010 json_object_string_add(json_no, "warning", "Peer not found");
13011 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13012 json_object_free(json_no);
13013 }
13014 else
13015 vty_out (vty, "No peer%s", VTY_NEWLINE);
13016 return CMD_WARNING;
13017 }
c63b83fe 13018 }
718e3744 13019
13020 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
db7c8528 13021 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
718e3744 13022 if (count)
13023 {
db7c8528 13024 if (!uj)
856ca177 13025 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
db7c8528 13026 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
856ca177
MS
13027 }
13028 else
13029 {
db7c8528 13030 if (uj)
856ca177
MS
13031 {
13032 json_object *json_no = NULL;
13033 json_no = json_object_new_object();
13034 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13035 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13036 json_object_free(json_no);
13037 }
13038 else
13039 vty_out (vty, "No functional output%s", VTY_NEWLINE);
718e3744 13040 }
13041
13042 return CMD_SUCCESS;
13043}
13044
13045DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
13046 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
4575cfc3 13047 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 13048 SHOW_STR
13049 IP_STR
13050 BGP_STR
13051 "Address family\n"
4575cfc3
LB
13052 "Address Family modifier\n"
13053 "Address Family modifier\n"
718e3744 13054 "Detailed information on TCP and BGP neighbor connections\n"
13055 "Neighbor to display information about\n"
13056 "Neighbor to display information about\n"
a80beece 13057 "Neighbor on bgp configured interface\n"
718e3744 13058 "Display information received from a BGP neighbor\n"
856ca177
MS
13059 "Display the prefixlist filter\n"
13060 "JavaScript Object Notation\n")
718e3744 13061{
13062 char name[BUFSIZ];
c63b83fe 13063 union sockunion su;
718e3744 13064 struct peer *peer;
c63b83fe 13065 int count, ret;
db7c8528 13066 u_char uj = use_json(argc, argv);
718e3744 13067
c63b83fe
JBD
13068 ret = str2sockunion (argv[1], &su);
13069 if (ret < 0)
13070 {
a80beece 13071 peer = peer_lookup_by_conf_if (NULL, argv[1]);
856ca177 13072 if (! peer)
a80beece 13073 {
db7c8528 13074 if (uj)
856ca177
MS
13075 {
13076 json_object *json_no = NULL;
13077 json_object *json_sub = NULL;
13078 json_no = json_object_new_object();
13079 json_sub = json_object_new_object();
13080 json_object_string_add(json_no, "warning", "Malformed address or name");
13081 json_object_string_add(json_sub, "warningCause", argv[1]);
13082 json_object_object_add(json_no, "detail", json_sub);
13083 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13084 json_object_free(json_no);
13085 }
13086 else
13087 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
a80beece
DS
13088 return CMD_WARNING;
13089 }
13090 }
13091 else
13092 {
13093 peer = peer_lookup (NULL, &su);
13094 if (! peer)
856ca177 13095 {
db7c8528 13096 if (uj)
856ca177
MS
13097 {
13098 json_object *json_no = NULL;
13099 json_no = json_object_new_object();
13100 json_object_string_add(json_no, "warning", "Peer not found");
13101 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13102 json_object_free(json_no);
13103 }
13104 else
13105 vty_out (vty, "No peer%s", VTY_NEWLINE);
13106 return CMD_WARNING;
13107 }
c63b83fe 13108 }
718e3744 13109
718e3744 13110 {
d02fbbdb
LB
13111 safi_t safi;
13112 safi = bgp_vty_safi_from_arg(argv[0]);
13113 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi);
db7c8528 13114 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
718e3744 13115 if (count)
856ca177 13116 {
db7c8528 13117 if (!uj)
d02fbbdb
LB
13118 vty_out (vty, "Address family: %s%s",
13119 afi_safi_print (AFI_IP, safi), VTY_NEWLINE);
db7c8528 13120 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
856ca177
MS
13121 }
13122 else
13123 {
db7c8528 13124 if (uj)
856ca177
MS
13125 {
13126 json_object *json_no = NULL;
13127 json_no = json_object_new_object();
13128 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13129 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13130 json_object_free(json_no);
13131 }
13132 else
13133 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13134 }
718e3744 13135 }
13136
13137 return CMD_SUCCESS;
13138}
718e3744 13139#ifdef HAVE_IPV6
50ef26d4 13140DEFUN (show_bgp_neighbor_received_routes,
718e3744 13141 show_bgp_neighbor_received_routes_cmd,
856ca177 13142 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 13143 SHOW_STR
13144 BGP_STR
13145 "Detailed information on TCP and BGP neighbor connections\n"
13146 "Neighbor to display information about\n"
13147 "Neighbor to display information about\n"
a80beece 13148 "Neighbor on bgp configured interface\n"
856ca177
MS
13149 "Display the received routes from neighbor\n"
13150 "JavaScript Object Notation\n")
50ef26d4 13151{
13152 struct peer *peer;
13153 const char *rmap_name = NULL;
13154 u_char uj = use_json(argc, argv);
718e3744 13155
50ef26d4 13156 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13157
13158 if (! peer)
13159 return CMD_WARNING;
13160
13161 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
13162 rmap_name = argv[1];
13163
13164 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, rmap_name, uj);
13165}
13166
13167ALIAS (show_bgp_neighbor_received_routes,
718e3744 13168 show_bgp_ipv6_neighbor_received_routes_cmd,
856ca177 13169 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
0b16f239
DS
13170 SHOW_STR
13171 BGP_STR
13172 "Address family\n"
13173 "Detailed information on TCP and BGP neighbor connections\n"
13174 "Neighbor to display information about\n"
13175 "Neighbor to display information about\n"
13176 "Neighbor on bgp configured interface\n"
856ca177
MS
13177 "Display the received routes from neighbor\n"
13178 "JavaScript Object Notation\n")
0b16f239 13179
718e3744 13180DEFUN (show_bgp_neighbor_received_prefix_filter,
13181 show_bgp_neighbor_received_prefix_filter_cmd,
856ca177 13182 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 13183 SHOW_STR
13184 BGP_STR
13185 "Detailed information on TCP and BGP neighbor connections\n"
13186 "Neighbor to display information about\n"
13187 "Neighbor to display information about\n"
a80beece 13188 "Neighbor on bgp configured interface\n"
718e3744 13189 "Display information received from a BGP neighbor\n"
856ca177
MS
13190 "Display the prefixlist filter\n"
13191 "JavaScript Object Notation\n")
718e3744 13192{
13193 char name[BUFSIZ];
c63b83fe 13194 union sockunion su;
718e3744 13195 struct peer *peer;
c63b83fe 13196 int count, ret;
db7c8528 13197 u_char uj = use_json(argc, argv);
718e3744 13198
c63b83fe
JBD
13199 ret = str2sockunion (argv[0], &su);
13200 if (ret < 0)
13201 {
a80beece 13202 peer = peer_lookup_by_conf_if (NULL, argv[0]);
856ca177 13203 if (! peer)
a80beece 13204 {
db7c8528 13205 if (uj)
856ca177
MS
13206 {
13207 json_object *json_no = NULL;
13208 json_object *json_sub = NULL;
13209 json_no = json_object_new_object();
13210 json_sub = json_object_new_object();
13211 json_object_string_add(json_no, "warning", "Malformed address or name");
13212 json_object_string_add(json_sub, "warningCause", argv[0]);
13213 json_object_object_add(json_no, "detail", json_sub);
13214 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13215 json_object_free(json_no);
13216 }
13217 else
13218 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
a80beece
DS
13219 return CMD_WARNING;
13220 }
13221 }
13222 else
13223 {
13224 peer = peer_lookup (NULL, &su);
13225 if (! peer)
856ca177 13226 {
db7c8528 13227 if (uj)
856ca177
MS
13228 {
13229 json_object *json_no = NULL;
13230 json_no = json_object_new_object();
13231 json_object_string_add(json_no, "warning", "No Peer");
13232 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13233 json_object_free(json_no);
13234 }
13235 else
13236 vty_out (vty, "No peer%s", VTY_NEWLINE);
13237 return CMD_WARNING;
13238 }
c63b83fe 13239 }
718e3744 13240
13241 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
db7c8528 13242 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
718e3744 13243 if (count)
13244 {
db7c8528 13245 if (!uj)
856ca177 13246 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
db7c8528 13247 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
856ca177
MS
13248 }
13249 else
13250 {
db7c8528 13251 if (uj)
856ca177
MS
13252 {
13253 json_object *json_no = NULL;
13254 json_no = json_object_new_object();
13255 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13256 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13257 json_object_free(json_no);
13258 }
13259 else
13260 vty_out (vty, "No functional output%s", VTY_NEWLINE);
718e3744 13261 }
13262
13263 return CMD_SUCCESS;
13264}
13265
13266ALIAS (show_bgp_neighbor_received_prefix_filter,
13267 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
856ca177 13268 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
718e3744 13269 SHOW_STR
13270 BGP_STR
13271 "Address family\n"
13272 "Detailed information on TCP and BGP neighbor connections\n"
13273 "Neighbor to display information about\n"
13274 "Neighbor to display information about\n"
a80beece 13275 "Neighbor on bgp configured interface\n"
718e3744 13276 "Display information received from a BGP neighbor\n"
856ca177
MS
13277 "Display the prefixlist filter\n"
13278 "JavaScript Object Notation\n")
718e3744 13279
13280/* old command */
50ef26d4 13281ALIAS (show_bgp_neighbor_received_routes,
718e3744 13282 ipv6_bgp_neighbor_received_routes_cmd,
856ca177 13283 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 13284 SHOW_STR
13285 IPV6_STR
13286 BGP_STR
13287 "Detailed information on TCP and BGP neighbor connections\n"
13288 "Neighbor to display information about\n"
13289 "Neighbor to display information about\n"
a80beece 13290 "Neighbor on bgp configured interface\n"
856ca177
MS
13291 "Display the received routes from neighbor\n"
13292 "JavaScript Object Notation\n")
718e3744 13293
13294/* old command */
13295DEFUN (ipv6_mbgp_neighbor_received_routes,
13296 ipv6_mbgp_neighbor_received_routes_cmd,
856ca177 13297 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
718e3744 13298 SHOW_STR
13299 IPV6_STR
13300 MBGP_STR
13301 "Detailed information on TCP and BGP neighbor connections\n"
13302 "Neighbor to display information about\n"
13303 "Neighbor to display information about\n"
a80beece 13304 "Neighbor on bgp configured interface\n"
856ca177
MS
13305 "Display the received routes from neighbor\n"
13306 "JavaScript Object Notation\n")
718e3744 13307{
bb46e94f 13308 struct peer *peer;
db7c8528 13309 u_char uj = use_json(argc, argv);
bb46e94f 13310
db7c8528 13311 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 13312 if (! peer)
13313 return CMD_WARNING;
13314
47e9b292 13315 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 13316 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj);
bb46e94f 13317}
13318
8386ac43 13319DEFUN (show_bgp_instance_neighbor_received_prefix_filter,
13320 show_bgp_instance_neighbor_received_prefix_filter_cmd,
13321 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
bb46e94f 13322 SHOW_STR
13323 BGP_STR
8386ac43 13324 BGP_INSTANCE_HELP_STR
bb46e94f 13325 "Detailed information on TCP and BGP neighbor connections\n"
13326 "Neighbor to display information about\n"
13327 "Neighbor to display information about\n"
a80beece 13328 "Neighbor on bgp configured interface\n"
bb46e94f 13329 "Display information received from a BGP neighbor\n"
856ca177
MS
13330 "Display the prefixlist filter\n"
13331 "JavaScript Object Notation\n")
bb46e94f 13332{
13333 char name[BUFSIZ];
c63b83fe 13334 union sockunion su;
bb46e94f 13335 struct peer *peer;
13336 struct bgp *bgp;
c63b83fe 13337 int count, ret;
db7c8528 13338 u_char uj = use_json(argc, argv);
bb46e94f 13339
13340 /* BGP structure lookup. */
6aeb9e78 13341 bgp = bgp_lookup_by_name (argv[1]);
bb46e94f 13342 if (bgp == NULL)
856ca177 13343 {
db7c8528 13344 if (uj)
856ca177
MS
13345 {
13346 json_object *json_no = NULL;
13347 json_no = json_object_new_object();
13348 json_object_string_add(json_no, "warning", "Can't find BGP view");
13349 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13350 json_object_free(json_no);
13351 }
13352 else
6aeb9e78 13353 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
856ca177
MS
13354 return CMD_WARNING;
13355 }
13356
6aeb9e78 13357 ret = str2sockunion (argv[2], &su);
c63b83fe
JBD
13358 if (ret < 0)
13359 {
6aeb9e78 13360 peer = peer_lookup_by_conf_if (bgp, argv[2]);
856ca177 13361 if (! peer)
a80beece 13362 {
db7c8528 13363 if (uj)
856ca177
MS
13364 {
13365 json_object *json_no = NULL;
13366 json_object *json_sub = NULL;
13367 json_no = json_object_new_object();
13368 json_sub = json_object_new_object();
13369 json_object_string_add(json_no, "warning", "Malformed address or name");
6aeb9e78 13370 json_object_string_add(json_sub, "warningCause", argv[2]);
856ca177
MS
13371 json_object_object_add(json_no, "detail", json_sub);
13372 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13373 json_object_free(json_no);
13374 }
13375 else
6aeb9e78 13376 vty_out (vty, "%% Malformed address or name: %s%s", argv[2], VTY_NEWLINE);
a80beece
DS
13377 return CMD_WARNING;
13378 }
13379 }
13380 else
13381 {
13382 peer = peer_lookup (bgp, &su);
13383 if (! peer)
856ca177 13384 {
db7c8528 13385 if (uj)
856ca177
MS
13386 {
13387 json_object *json_no = NULL;
13388 json_no = json_object_new_object();
13389 json_object_boolean_true_add(json_no, "noPeer");
13390 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13391 json_object_free(json_no);
13392 }
13393 else
13394 vty_out (vty, "No peer%s", VTY_NEWLINE);
13395 return CMD_WARNING;
13396 }
13397
c63b83fe 13398 }
bb46e94f 13399
13400 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
db7c8528 13401 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
bb46e94f 13402 if (count)
13403 {
db7c8528 13404 if (!uj)
856ca177 13405 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
db7c8528 13406 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
bb46e94f 13407 }
13408
13409 return CMD_SUCCESS;
718e3744 13410}
8386ac43 13411ALIAS (show_bgp_instance_neighbor_received_prefix_filter,
13412 show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd,
13413 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
bb46e94f 13414 SHOW_STR
13415 BGP_STR
8386ac43 13416 BGP_INSTANCE_HELP_STR
bb46e94f 13417 "Address family\n"
13418 "Detailed information on TCP and BGP neighbor connections\n"
13419 "Neighbor to display information about\n"
13420 "Neighbor to display information about\n"
a80beece 13421 "Neighbor on bgp configured interface\n"
bb46e94f 13422 "Display information received from a BGP neighbor\n"
856ca177
MS
13423 "Display the prefixlist filter\n"
13424 "JavaScript Object NOtation\n")
718e3744 13425#endif /* HAVE_IPV6 */
6b0655a2 13426
94f2b392 13427static int
bb46e94f 13428bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
856ca177 13429 safi_t safi, enum bgp_show_type type, u_char use_json)
718e3744 13430{
718e3744 13431 if (! peer || ! peer->afc[afi][safi])
13432 {
856ca177
MS
13433 if (use_json)
13434 {
13435 json_object *json_no = NULL;
13436 json_no = json_object_new_object();
13437 json_object_string_add(json_no, "warning", "No such neighbor or address family");
13438 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13439 json_object_free(json_no);
13440 }
13441 else
13442 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
718e3744 13443 return CMD_WARNING;
13444 }
47fc97cc 13445
856ca177 13446 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json);
718e3744 13447}
13448
13449DEFUN (show_ip_bgp_neighbor_routes,
13450 show_ip_bgp_neighbor_routes_cmd,
856ca177 13451 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13452 SHOW_STR
13453 IP_STR
13454 BGP_STR
13455 "Detailed information on TCP and BGP neighbor connections\n"
13456 "Neighbor to display information about\n"
13457 "Neighbor to display information about\n"
a80beece 13458 "Neighbor on bgp configured interface\n"
856ca177
MS
13459 "Display routes learned from neighbor\n"
13460 "JavaScript Object Notation\n")
718e3744 13461{
bb46e94f 13462 struct peer *peer;
db7c8528 13463 u_char uj = use_json(argc, argv);
856ca177 13464
db7c8528 13465 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 13466 if (! peer)
13467 return CMD_WARNING;
13468
13469 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 13470 bgp_show_type_neighbor, uj);
718e3744 13471}
13472
8386ac43 13473DEFUN (show_ip_bgp_instance_neighbor_routes,
13474 show_ip_bgp_instance_neighbor_routes_cmd,
13475 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
50ef26d4 13476 SHOW_STR
13477 IP_STR
13478 BGP_STR
8386ac43 13479 BGP_INSTANCE_HELP_STR
50ef26d4 13480 "Detailed information on TCP and BGP neighbor connections\n"
13481 "Neighbor to display information about\n"
13482 "Neighbor to display information about\n"
13483 "Neighbor on bgp configured interface\n"
13484 "Display routes learned from neighbor\n"
13485 "JavaScript Object Notation\n")
13486{
13487 struct peer *peer;
13488 u_char uj = use_json(argc, argv);
13489
13490 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13491 if (! peer)
13492 return CMD_WARNING;
13493
13494 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13495 bgp_show_type_neighbor, uj);
13496}
13497
718e3744 13498DEFUN (show_ip_bgp_neighbor_flap,
13499 show_ip_bgp_neighbor_flap_cmd,
856ca177 13500 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
718e3744 13501 SHOW_STR
13502 IP_STR
13503 BGP_STR
13504 "Detailed information on TCP and BGP neighbor connections\n"
13505 "Neighbor to display information about\n"
13506 "Neighbor to display information about\n"
a80beece 13507 "Neighbor on bgp configured interface\n"
856ca177
MS
13508 "Display flap statistics of the routes learned from neighbor\n"
13509 "JavaScript Object Notation\n")
718e3744 13510{
bb46e94f 13511 struct peer *peer;
db7c8528 13512 u_char uj = use_json(argc, argv);
856ca177 13513
db7c8528 13514 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 13515 if (! peer)
13516 return CMD_WARNING;
13517
13518 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 13519 bgp_show_type_flap_neighbor, uj);
718e3744 13520}
13521
13522DEFUN (show_ip_bgp_neighbor_damp,
13523 show_ip_bgp_neighbor_damp_cmd,
856ca177 13524 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
718e3744 13525 SHOW_STR
13526 IP_STR
13527 BGP_STR
13528 "Detailed information on TCP and BGP neighbor connections\n"
13529 "Neighbor to display information about\n"
13530 "Neighbor to display information about\n"
a80beece 13531 "Neighbor on bgp configured interface\n"
856ca177
MS
13532 "Display the dampened routes received from neighbor\n"
13533 "JavaScript Object Notation\n")
718e3744 13534{
bb46e94f 13535 struct peer *peer;
db7c8528 13536 u_char uj = use_json(argc, argv);
856ca177 13537
db7c8528 13538 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 13539 if (! peer)
13540 return CMD_WARNING;
13541
13542 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 13543 bgp_show_type_damp_neighbor, uj);
718e3744 13544}
13545
13546DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13547 show_ip_bgp_ipv4_neighbor_routes_cmd,
4575cfc3 13548 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13549 SHOW_STR
13550 IP_STR
13551 BGP_STR
13552 "Address family\n"
4575cfc3
LB
13553 "Address Family modifier\n"
13554 "Address Family modifier\n"
718e3744 13555 "Detailed information on TCP and BGP neighbor connections\n"
13556 "Neighbor to display information about\n"
13557 "Neighbor to display information about\n"
a80beece 13558 "Neighbor on bgp configured interface\n"
856ca177
MS
13559 "Display routes learned from neighbor\n"
13560 "JavaScript Object Notation\n")
718e3744 13561{
bb46e94f 13562 struct peer *peer;
d02fbbdb 13563 safi_t safi;
db7c8528 13564 u_char uj = use_json(argc, argv);
bb46e94f 13565
db7c8528 13566 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 13567 if (! peer)
13568 return CMD_WARNING;
13569
d02fbbdb
LB
13570 safi = bgp_vty_safi_from_arg(argv[0]);
13571 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
13572 bgp_show_type_neighbor, uj);
718e3744 13573}
bb46e94f 13574
2a3d5731 13575#ifdef HAVE_IPV6
8386ac43 13576DEFUN (show_bgp_instance_neighbor_routes,
13577 show_bgp_instance_neighbor_routes_cmd,
13578 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
fee0f4c6 13579 SHOW_STR
fee0f4c6 13580 BGP_STR
8386ac43 13581 BGP_INSTANCE_HELP_STR
2a3d5731
DW
13582 "Detailed information on TCP and BGP neighbor connections\n"
13583 "Neighbor to display information about\n"
13584 "Neighbor to display information about\n"
13585 "Neighbor on bgp configured interface\n"
13586 "Display routes learned from neighbor\n"
13587 "JavaScript Object Notation\n")
fee0f4c6 13588{
fee0f4c6 13589 struct peer *peer;
db7c8528 13590 u_char uj = use_json(argc, argv);
fee0f4c6 13591
50ef26d4 13592 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
fee0f4c6 13593 if (! peer)
13594 return CMD_WARNING;
13595
2a3d5731 13596 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
db7c8528 13597 bgp_show_type_neighbor, uj);
fee0f4c6 13598}
13599
8386ac43 13600ALIAS (show_bgp_instance_neighbor_routes,
13601 show_bgp_instance_ipv6_neighbor_routes_cmd,
13602 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
fee0f4c6 13603 SHOW_STR
fee0f4c6 13604 BGP_STR
8386ac43 13605 BGP_INSTANCE_HELP_STR
2a3d5731
DW
13606 "Address family\n"
13607 "Detailed information on TCP and BGP neighbor connections\n"
13608 "Neighbor to display information about\n"
13609 "Neighbor to display information about\n"
13610 "Neighbor on bgp configured interface\n"
13611 "Display routes learned from neighbor\n"
13612 "JavaScript Object Notation\n")
fee0f4c6 13613
8386ac43 13614DEFUN (show_bgp_instance_neighbor_damp,
13615 show_bgp_instance_neighbor_damp_cmd,
13616 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
fee0f4c6 13617 SHOW_STR
fee0f4c6 13618 BGP_STR
8386ac43 13619 BGP_INSTANCE_HELP_STR
2a3d5731
DW
13620 "Detailed information on TCP and BGP neighbor connections\n"
13621 "Neighbor to display information about\n"
13622 "Neighbor to display information about\n"
13623 "Neighbor on bgp configured interface\n"
13624 "Display the dampened routes received from neighbor\n"
13625 "JavaScript Object Notation\n")
bb46e94f 13626{
13627 struct peer *peer;
db7c8528 13628 u_char uj = use_json(argc, argv);
856ca177 13629
6aeb9e78
DS
13630 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13631 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13632 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
bb46e94f 13633 else
6aeb9e78 13634 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 13635
13636 if (! peer)
13637 return CMD_WARNING;
13638
13639 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
db7c8528 13640 bgp_show_type_damp_neighbor, uj);
bb46e94f 13641}
13642
8386ac43 13643ALIAS (show_bgp_instance_neighbor_damp,
13644 show_bgp_instance_ipv6_neighbor_damp_cmd,
13645 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
bb46e94f 13646 SHOW_STR
13647 BGP_STR
8386ac43 13648 BGP_INSTANCE_HELP_STR
bb46e94f 13649 "Address family\n"
13650 "Detailed information on TCP and BGP neighbor connections\n"
13651 "Neighbor to display information about\n"
13652 "Neighbor to display information about\n"
a80beece 13653 "Neighbor on bgp configured interface\n"
856ca177
MS
13654 "Display the dampened routes received from neighbor\n"
13655 "JavaScript Object Notation\n")
bb46e94f 13656
8386ac43 13657DEFUN (show_bgp_instance_neighbor_flap,
13658 show_bgp_instance_neighbor_flap_cmd,
13659 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 13660 SHOW_STR
13661 BGP_STR
8386ac43 13662 BGP_INSTANCE_HELP_STR
bb46e94f 13663 "Detailed information on TCP and BGP neighbor connections\n"
13664 "Neighbor to display information about\n"
13665 "Neighbor to display information about\n"
a80beece 13666 "Neighbor on bgp configured interface\n"
856ca177
MS
13667 "Display flap statistics of the routes learned from neighbor\n"
13668 "JavaScript Object Notation\n")
bb46e94f 13669{
13670 struct peer *peer;
db7c8528 13671 u_char uj = use_json(argc, argv);
856ca177 13672
6aeb9e78
DS
13673 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13674 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13675 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
bb46e94f 13676 else
6aeb9e78 13677 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
bb46e94f 13678
13679 if (! peer)
13680 return CMD_WARNING;
13681
13682 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
db7c8528 13683 bgp_show_type_flap_neighbor, uj);
bb46e94f 13684}
13685
8386ac43 13686ALIAS (show_bgp_instance_neighbor_flap,
13687 show_bgp_instance_ipv6_neighbor_flap_cmd,
13688 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 13689 SHOW_STR
13690 BGP_STR
8386ac43 13691 BGP_INSTANCE_HELP_STR
bb46e94f 13692 "Address family\n"
13693 "Detailed information on TCP and BGP neighbor connections\n"
13694 "Neighbor to display information about\n"
13695 "Neighbor to display information about\n"
a80beece 13696 "Neighbor on bgp configured interface\n"
856ca177
MS
13697 "Display flap statistics of the routes learned from neighbor\n"
13698 "JavaScript Object Notation\n")
bb46e94f 13699
50ef26d4 13700DEFUN (show_bgp_neighbor_routes,
bb46e94f 13701 show_bgp_neighbor_routes_cmd,
856ca177 13702 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
bb46e94f 13703 SHOW_STR
13704 BGP_STR
13705 "Detailed information on TCP and BGP neighbor connections\n"
13706 "Neighbor to display information about\n"
13707 "Neighbor to display information about\n"
a80beece 13708 "Neighbor on bgp configured interface\n"
856ca177
MS
13709 "Display routes learned from neighbor\n"
13710 "JavaScript Object Notation\n")
50ef26d4 13711{
13712 struct peer *peer;
13713 u_char uj = use_json(argc, argv);
bb46e94f 13714
50ef26d4 13715 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13716 if (! peer)
13717 return CMD_WARNING;
bb46e94f 13718
50ef26d4 13719 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13720 bgp_show_type_neighbor, uj);
13721}
13722
13723
13724ALIAS (show_bgp_neighbor_routes,
718e3744 13725 show_bgp_ipv6_neighbor_routes_cmd,
856ca177 13726 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13727 SHOW_STR
13728 BGP_STR
13729 "Address family\n"
13730 "Detailed information on TCP and BGP neighbor connections\n"
13731 "Neighbor to display information about\n"
13732 "Neighbor to display information about\n"
a80beece 13733 "Neighbor on bgp configured interface\n"
856ca177
MS
13734 "Display routes learned from neighbor\n"
13735 "JavaScript Object Notation\n")
718e3744 13736
13737/* old command */
50ef26d4 13738ALIAS (show_bgp_neighbor_routes,
718e3744 13739 ipv6_bgp_neighbor_routes_cmd,
856ca177 13740 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13741 SHOW_STR
13742 IPV6_STR
13743 BGP_STR
13744 "Detailed information on TCP and BGP neighbor connections\n"
13745 "Neighbor to display information about\n"
13746 "Neighbor to display information about\n"
a80beece 13747 "Neighbor on bgp configured interface\n"
856ca177
MS
13748 "Display routes learned from neighbor\n"
13749 "JavaScript Object Notation\n")
718e3744 13750
13751/* old command */
13752DEFUN (ipv6_mbgp_neighbor_routes,
13753 ipv6_mbgp_neighbor_routes_cmd,
856ca177 13754 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
718e3744 13755 SHOW_STR
13756 IPV6_STR
13757 MBGP_STR
13758 "Detailed information on TCP and BGP neighbor connections\n"
13759 "Neighbor to display information about\n"
13760 "Neighbor to display information about\n"
a80beece 13761 "Neighbor on bgp configured interface\n"
856ca177
MS
13762 "Display routes learned from neighbor\n"
13763 "JavaScript Object Notation\n")
718e3744 13764{
bb46e94f 13765 struct peer *peer;
db7c8528 13766 u_char uj = use_json(argc, argv);
bb46e94f 13767
db7c8528 13768 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
bb46e94f 13769 if (! peer)
13770 return CMD_WARNING;
13771
47e9b292 13772 bgp_show_ipv6_bgp_deprecate_warning(vty);
bb46e94f 13773 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
db7c8528 13774 bgp_show_type_neighbor, uj);
718e3744 13775}
bb46e94f 13776
8386ac43 13777ALIAS (show_bgp_instance_neighbor_flap,
bb46e94f 13778 show_bgp_neighbor_flap_cmd,
856ca177 13779 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 13780 SHOW_STR
13781 BGP_STR
13782 "Detailed information on TCP and BGP neighbor connections\n"
13783 "Neighbor to display information about\n"
13784 "Neighbor to display information about\n"
a80beece 13785 "Neighbor on bgp configured interface\n"
856ca177
MS
13786 "Display flap statistics of the routes learned from neighbor\n"
13787 "JavaScript Object Notation\n")
bb46e94f 13788
8386ac43 13789ALIAS (show_bgp_instance_neighbor_flap,
bb46e94f 13790 show_bgp_ipv6_neighbor_flap_cmd,
856ca177 13791 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
bb46e94f 13792 SHOW_STR
13793 BGP_STR
13794 "Address family\n"
13795 "Detailed information on TCP and BGP neighbor connections\n"
13796 "Neighbor to display information about\n"
13797 "Neighbor to display information about\n"
a80beece 13798 "Neighbor on bgp configured interface\n"
856ca177
MS
13799 "Display flap statistics of the routes learned from neighbor\n"
13800 "JavaScript Object Notation\n")
bb46e94f 13801
8386ac43 13802ALIAS (show_bgp_instance_neighbor_damp,
bb46e94f 13803 show_bgp_neighbor_damp_cmd,
856ca177 13804 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
bb46e94f 13805 SHOW_STR
13806 BGP_STR
13807 "Detailed information on TCP and BGP neighbor connections\n"
13808 "Neighbor to display information about\n"
13809 "Neighbor to display information about\n"
a80beece 13810 "Neighbor on bgp configured interface\n"
856ca177
MS
13811 "Display the dampened routes received from neighbor\n"
13812 "JavaScript Object Notation\n")
bb46e94f 13813
8386ac43 13814ALIAS (show_bgp_instance_neighbor_damp,
bb46e94f 13815 show_bgp_ipv6_neighbor_damp_cmd,
856ca177 13816 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
bb46e94f 13817 SHOW_STR
13818 BGP_STR
13819 "Address family\n"
13820 "Detailed information on TCP and BGP neighbor connections\n"
13821 "Neighbor to display information about\n"
13822 "Neighbor to display information about\n"
a80beece 13823 "Neighbor on bgp configured interface\n"
856ca177
MS
13824 "Display the dampened routes received from neighbor\n"
13825 "JavaScript Object Notation\n")
fee0f4c6 13826
718e3744 13827#endif /* HAVE_IPV6 */
6b0655a2 13828
734b349e 13829struct bgp_table *bgp_distance_table[AFI_MAX][SAFI_MAX];
718e3744 13830
13831struct bgp_distance
13832{
13833 /* Distance value for the IP source prefix. */
13834 u_char distance;
13835
13836 /* Name of the access-list to be matched. */
13837 char *access_list;
13838};
13839
94f2b392 13840static struct bgp_distance *
66e5cd87 13841bgp_distance_new (void)
718e3744 13842{
393deb9b 13843 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
718e3744 13844}
13845
94f2b392 13846static void
718e3744 13847bgp_distance_free (struct bgp_distance *bdistance)
13848{
13849 XFREE (MTYPE_BGP_DISTANCE, bdistance);
13850}
13851
94f2b392 13852static int
fd79ac91 13853bgp_distance_set (struct vty *vty, const char *distance_str,
13854 const char *ip_str, const char *access_list_str)
718e3744 13855{
13856 int ret;
734b349e
MZ
13857 afi_t afi;
13858 safi_t safi;
13859 struct prefix p;
718e3744 13860 u_char distance;
13861 struct bgp_node *rn;
13862 struct bgp_distance *bdistance;
13863
734b349e
MZ
13864 afi = bgp_node_afi (vty);
13865 safi = bgp_node_safi (vty);
13866
13867 ret = str2prefix (ip_str, &p);
718e3744 13868 if (ret == 0)
13869 {
13870 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13871 return CMD_WARNING;
13872 }
13873
13874 distance = atoi (distance_str);
13875
13876 /* Get BGP distance node. */
734b349e 13877 rn = bgp_node_get (bgp_distance_table[afi][safi], (struct prefix *) &p);
718e3744 13878 if (rn->info)
13879 {
13880 bdistance = rn->info;
13881 bgp_unlock_node (rn);
13882 }
13883 else
13884 {
13885 bdistance = bgp_distance_new ();
13886 rn->info = bdistance;
13887 }
13888
13889 /* Set distance value. */
13890 bdistance->distance = distance;
13891
13892 /* Reset access-list configuration. */
13893 if (bdistance->access_list)
13894 {
6e919709 13895 XFREE(MTYPE_AS_LIST, bdistance->access_list);
718e3744 13896 bdistance->access_list = NULL;
13897 }
13898 if (access_list_str)
6e919709 13899 bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str);
718e3744 13900
13901 return CMD_SUCCESS;
13902}
13903
94f2b392 13904static int
fd79ac91 13905bgp_distance_unset (struct vty *vty, const char *distance_str,
13906 const char *ip_str, const char *access_list_str)
718e3744 13907{
13908 int ret;
734b349e
MZ
13909 afi_t afi;
13910 safi_t safi;
13911 struct prefix p;
1f9a9fff 13912 int distance;
718e3744 13913 struct bgp_node *rn;
13914 struct bgp_distance *bdistance;
13915
734b349e
MZ
13916 afi = bgp_node_afi (vty);
13917 safi = bgp_node_safi (vty);
13918
13919 ret = str2prefix (ip_str, &p);
718e3744 13920 if (ret == 0)
13921 {
13922 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13923 return CMD_WARNING;
13924 }
13925
734b349e 13926 rn = bgp_node_lookup (bgp_distance_table[afi][safi], (struct prefix *)&p);
718e3744 13927 if (! rn)
13928 {
13929 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
13930 return CMD_WARNING;
13931 }
13932
13933 bdistance = rn->info;
1f9a9fff
PJ
13934 distance = atoi(distance_str);
13935
13936 if (bdistance->distance != distance)
13937 {
13938 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
13939 return CMD_WARNING;
13940 }
718e3744 13941
13942 if (bdistance->access_list)
6e919709 13943 XFREE(MTYPE_AS_LIST, bdistance->access_list);
718e3744 13944 bgp_distance_free (bdistance);
13945
13946 rn->info = NULL;
13947 bgp_unlock_node (rn);
13948 bgp_unlock_node (rn);
13949
13950 return CMD_SUCCESS;
13951}
13952
718e3744 13953/* Apply BGP information to distance method. */
13954u_char
734b349e
MZ
13955bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, afi_t afi,
13956 safi_t safi, struct bgp *bgp)
718e3744 13957{
13958 struct bgp_node *rn;
734b349e 13959 struct prefix q;
718e3744 13960 struct peer *peer;
13961 struct bgp_distance *bdistance;
13962 struct access_list *alist;
13963 struct bgp_static *bgp_static;
13964
13965 if (! bgp)
13966 return 0;
13967
718e3744 13968 peer = rinfo->peer;
13969
718e3744 13970 /* Check source address. */
734b349e
MZ
13971 sockunion2hostprefix (&peer->su, &q);
13972 rn = bgp_node_match (bgp_distance_table[afi][safi], &q);
718e3744 13973 if (rn)
13974 {
13975 bdistance = rn->info;
13976 bgp_unlock_node (rn);
13977
13978 if (bdistance->access_list)
13979 {
734b349e 13980 alist = access_list_lookup (afi, bdistance->access_list);
718e3744 13981 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
13982 return bdistance->distance;
13983 }
13984 else
13985 return bdistance->distance;
13986 }
13987
13988 /* Backdoor check. */
734b349e 13989 rn = bgp_node_lookup (bgp->route[afi][safi], p);
718e3744 13990 if (rn)
13991 {
13992 bgp_static = rn->info;
13993 bgp_unlock_node (rn);
13994
13995 if (bgp_static->backdoor)
13996 {
734b349e
MZ
13997 if (bgp->distance_local[afi][safi])
13998 return bgp->distance_local[afi][safi];
718e3744 13999 else
14000 return ZEBRA_IBGP_DISTANCE_DEFAULT;
14001 }
14002 }
14003
6d85b15b 14004 if (peer->sort == BGP_PEER_EBGP)
718e3744 14005 {
734b349e
MZ
14006 if (bgp->distance_ebgp[afi][safi])
14007 return bgp->distance_ebgp[afi][safi];
718e3744 14008 return ZEBRA_EBGP_DISTANCE_DEFAULT;
14009 }
14010 else
14011 {
734b349e
MZ
14012 if (bgp->distance_ibgp[afi][safi])
14013 return bgp->distance_ibgp[afi][safi];
718e3744 14014 return ZEBRA_IBGP_DISTANCE_DEFAULT;
14015 }
14016}
14017
14018DEFUN (bgp_distance,
14019 bgp_distance_cmd,
14020 "distance bgp <1-255> <1-255> <1-255>",
14021 "Define an administrative distance\n"
14022 "BGP distance\n"
14023 "Distance for routes external to the AS\n"
14024 "Distance for routes internal to the AS\n"
14025 "Distance for local routes\n")
14026{
14027 struct bgp *bgp;
734b349e
MZ
14028 afi_t afi;
14029 safi_t safi;
718e3744 14030
14031 bgp = vty->index;
734b349e
MZ
14032 afi = bgp_node_afi (vty);
14033 safi = bgp_node_safi (vty);
718e3744 14034
734b349e
MZ
14035 bgp->distance_ebgp[afi][safi] = atoi (argv[0]);
14036 bgp->distance_ibgp[afi][safi] = atoi (argv[1]);
14037 bgp->distance_local[afi][safi] = atoi (argv[2]);
718e3744 14038 return CMD_SUCCESS;
14039}
14040
14041DEFUN (no_bgp_distance,
14042 no_bgp_distance_cmd,
14043 "no distance bgp <1-255> <1-255> <1-255>",
14044 NO_STR
14045 "Define an administrative distance\n"
14046 "BGP distance\n"
14047 "Distance for routes external to the AS\n"
14048 "Distance for routes internal to the AS\n"
14049 "Distance for local routes\n")
14050{
14051 struct bgp *bgp;
734b349e
MZ
14052 afi_t afi;
14053 safi_t safi;
718e3744 14054
14055 bgp = vty->index;
734b349e
MZ
14056 afi = bgp_node_afi (vty);
14057 safi = bgp_node_safi (vty);
718e3744 14058
734b349e
MZ
14059 bgp->distance_ebgp[afi][safi] = 0;
14060 bgp->distance_ibgp[afi][safi] = 0;
14061 bgp->distance_local[afi][safi] = 0;
718e3744 14062 return CMD_SUCCESS;
14063}
14064
14065ALIAS (no_bgp_distance,
14066 no_bgp_distance2_cmd,
14067 "no distance bgp",
14068 NO_STR
14069 "Define an administrative distance\n"
14070 "BGP distance\n")
14071
14072DEFUN (bgp_distance_source,
14073 bgp_distance_source_cmd,
14074 "distance <1-255> A.B.C.D/M",
14075 "Define an administrative distance\n"
14076 "Administrative distance\n"
14077 "IP source prefix\n")
14078{
14079 bgp_distance_set (vty, argv[0], argv[1], NULL);
14080 return CMD_SUCCESS;
14081}
14082
14083DEFUN (no_bgp_distance_source,
14084 no_bgp_distance_source_cmd,
14085 "no distance <1-255> A.B.C.D/M",
14086 NO_STR
14087 "Define an administrative distance\n"
14088 "Administrative distance\n"
14089 "IP source prefix\n")
14090{
14091 bgp_distance_unset (vty, argv[0], argv[1], NULL);
14092 return CMD_SUCCESS;
14093}
14094
14095DEFUN (bgp_distance_source_access_list,
14096 bgp_distance_source_access_list_cmd,
14097 "distance <1-255> A.B.C.D/M WORD",
14098 "Define an administrative distance\n"
14099 "Administrative distance\n"
14100 "IP source prefix\n"
14101 "Access list name\n")
14102{
14103 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
14104 return CMD_SUCCESS;
14105}
14106
14107DEFUN (no_bgp_distance_source_access_list,
14108 no_bgp_distance_source_access_list_cmd,
14109 "no distance <1-255> A.B.C.D/M WORD",
14110 NO_STR
14111 "Define an administrative distance\n"
14112 "Administrative distance\n"
14113 "IP source prefix\n"
14114 "Access list name\n")
14115{
14116 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
14117 return CMD_SUCCESS;
14118}
6b0655a2 14119
734b349e
MZ
14120DEFUN (ipv6_bgp_distance_source,
14121 ipv6_bgp_distance_source_cmd,
14122 "distance <1-255> X:X::X:X/M",
14123 "Define an administrative distance\n"
14124 "Administrative distance\n"
14125 "IP source prefix\n")
14126{
14127 bgp_distance_set (vty, argv[0], argv[1], NULL);
14128 return CMD_SUCCESS;
14129}
14130
14131DEFUN (no_ipv6_bgp_distance_source,
14132 no_ipv6_bgp_distance_source_cmd,
14133 "no distance <1-255> X:X::X:X/M",
14134 NO_STR
14135 "Define an administrative distance\n"
14136 "Administrative distance\n"
14137 "IP source prefix\n")
14138{
14139 bgp_distance_unset (vty, argv[0], argv[1], NULL);
14140 return CMD_SUCCESS;
14141}
14142
14143DEFUN (ipv6_bgp_distance_source_access_list,
14144 ipv6_bgp_distance_source_access_list_cmd,
14145 "distance <1-255> X:X::X:X/M WORD",
14146 "Define an administrative distance\n"
14147 "Administrative distance\n"
14148 "IP source prefix\n"
14149 "Access list name\n")
14150{
14151 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
14152 return CMD_SUCCESS;
14153}
14154
14155DEFUN (no_ipv6_bgp_distance_source_access_list,
14156 no_ipv6_bgp_distance_source_access_list_cmd,
14157 "no distance <1-255> X:X::X:X/M WORD",
14158 NO_STR
14159 "Define an administrative distance\n"
14160 "Administrative distance\n"
14161 "IP source prefix\n"
14162 "Access list name\n")
14163{
14164 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
14165 return CMD_SUCCESS;
14166}
14167
718e3744 14168DEFUN (bgp_damp_set,
14169 bgp_damp_set_cmd,
14170 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14171 "BGP Specific commands\n"
14172 "Enable route-flap dampening\n"
14173 "Half-life time for the penalty\n"
14174 "Value to start reusing a route\n"
14175 "Value to start suppressing a route\n"
14176 "Maximum duration to suppress a stable route\n")
14177{
14178 struct bgp *bgp;
14179 int half = DEFAULT_HALF_LIFE * 60;
14180 int reuse = DEFAULT_REUSE;
14181 int suppress = DEFAULT_SUPPRESS;
14182 int max = 4 * half;
14183
14184 if (argc == 4)
14185 {
14186 half = atoi (argv[0]) * 60;
14187 reuse = atoi (argv[1]);
14188 suppress = atoi (argv[2]);
14189 max = atoi (argv[3]) * 60;
14190 }
14191 else if (argc == 1)
14192 {
14193 half = atoi (argv[0]) * 60;
14194 max = 4 * half;
14195 }
14196
14197 bgp = vty->index;
7ebe9748
B
14198
14199 if (suppress < reuse)
14200 {
14201 vty_out (vty, "Suppress value cannot be less than reuse value %s",
14202 VTY_NEWLINE);
14203 return 0;
14204 }
14205
718e3744 14206 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
14207 half, reuse, suppress, max);
14208}
14209
14210ALIAS (bgp_damp_set,
14211 bgp_damp_set2_cmd,
14212 "bgp dampening <1-45>",
14213 "BGP Specific commands\n"
14214 "Enable route-flap dampening\n"
14215 "Half-life time for the penalty\n")
14216
14217ALIAS (bgp_damp_set,
14218 bgp_damp_set3_cmd,
14219 "bgp dampening",
14220 "BGP Specific commands\n"
14221 "Enable route-flap dampening\n")
14222
14223DEFUN (bgp_damp_unset,
14224 bgp_damp_unset_cmd,
14225 "no bgp dampening",
14226 NO_STR
14227 "BGP Specific commands\n"
14228 "Enable route-flap dampening\n")
14229{
14230 struct bgp *bgp;
14231
14232 bgp = vty->index;
14233 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
14234}
14235
14236ALIAS (bgp_damp_unset,
14237 bgp_damp_unset2_cmd,
14238 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14239 NO_STR
14240 "BGP Specific commands\n"
14241 "Enable route-flap dampening\n"
14242 "Half-life time for the penalty\n"
14243 "Value to start reusing a route\n"
14244 "Value to start suppressing a route\n"
14245 "Maximum duration to suppress a stable route\n")
14246
813d4307
DW
14247ALIAS (bgp_damp_unset,
14248 bgp_damp_unset3_cmd,
14249 "no bgp dampening <1-45>",
14250 NO_STR
14251 "BGP Specific commands\n"
14252 "Enable route-flap dampening\n"
14253 "Half-life time for the penalty\n")
14254
718e3744 14255DEFUN (show_ip_bgp_dampened_paths,
14256 show_ip_bgp_dampened_paths_cmd,
14257 "show ip bgp dampened-paths",
14258 SHOW_STR
14259 IP_STR
14260 BGP_STR
14261 "Display paths suppressed due to dampening\n")
14262{
5a646650 14263 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
b05a1c8b 14264 NULL, 0);
718e3744 14265}
14266
81304aaf
B
14267ALIAS (show_ip_bgp_dampened_paths,
14268 show_ip_bgp_damp_dampened_paths_cmd,
14269 "show ip bgp dampening dampened-paths",
14270 SHOW_STR
14271 IP_STR
14272 BGP_STR
14273 "Display detailed information about dampening\n"
14274 "Display paths suppressed due to dampening\n")
14275
718e3744 14276DEFUN (show_ip_bgp_flap_statistics,
14277 show_ip_bgp_flap_statistics_cmd,
14278 "show ip bgp flap-statistics",
14279 SHOW_STR
14280 IP_STR
14281 BGP_STR
14282 "Display flap statistics of routes\n")
14283{
5a646650 14284 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 14285 bgp_show_type_flap_statistics, NULL, 0);
718e3744 14286}
6b0655a2 14287
81304aaf
B
14288ALIAS (show_ip_bgp_flap_statistics,
14289 show_ip_bgp_damp_flap_statistics_cmd,
14290 "show ip bgp dampening flap-statistics",
14291 SHOW_STR
14292 IP_STR
14293 BGP_STR
14294 "Display detailed information about dampening\n"
14295 "Display flap statistics of routes\n")
14296
718e3744 14297/* Display specified route of BGP table. */
94f2b392 14298static int
fd79ac91 14299bgp_clear_damp_route (struct vty *vty, const char *view_name,
14300 const char *ip_str, afi_t afi, safi_t safi,
14301 struct prefix_rd *prd, int prefix_check)
718e3744 14302{
14303 int ret;
14304 struct prefix match;
14305 struct bgp_node *rn;
14306 struct bgp_node *rm;
14307 struct bgp_info *ri;
14308 struct bgp_info *ri_temp;
14309 struct bgp *bgp;
14310 struct bgp_table *table;
14311
14312 /* BGP structure lookup. */
14313 if (view_name)
14314 {
14315 bgp = bgp_lookup_by_name (view_name);
14316 if (bgp == NULL)
14317 {
6aeb9e78 14318 vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
718e3744 14319 return CMD_WARNING;
14320 }
14321 }
14322 else
14323 {
14324 bgp = bgp_get_default ();
14325 if (bgp == NULL)
14326 {
14327 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
14328 return CMD_WARNING;
14329 }
14330 }
14331
14332 /* Check IP address argument. */
14333 ret = str2prefix (ip_str, &match);
14334 if (! ret)
14335 {
14336 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
14337 return CMD_WARNING;
14338 }
14339
14340 match.family = afi2family (afi);
14341
587ff0fd 14342 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 14343 {
587ff0fd 14344 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
718e3744 14345 {
14346 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
14347 continue;
14348
14349 if ((table = rn->info) != NULL)
14350 if ((rm = bgp_node_match (table, &match)) != NULL)
6c88b44d
CC
14351 {
14352 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
14353 {
14354 ri = rm->info;
14355 while (ri)
14356 {
14357 if (ri->extra && ri->extra->damp_info)
14358 {
14359 ri_temp = ri->next;
14360 bgp_damp_info_free (ri->extra->damp_info, 1);
14361 ri = ri_temp;
14362 }
14363 else
14364 ri = ri->next;
14365 }
14366 }
14367
14368 bgp_unlock_node (rm);
14369 }
718e3744 14370 }
14371 }
14372 else
14373 {
14374 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
6c88b44d
CC
14375 {
14376 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
14377 {
14378 ri = rn->info;
14379 while (ri)
14380 {
14381 if (ri->extra && ri->extra->damp_info)
14382 {
14383 ri_temp = ri->next;
14384 bgp_damp_info_free (ri->extra->damp_info, 1);
14385 ri = ri_temp;
14386 }
14387 else
14388 ri = ri->next;
14389 }
14390 }
14391
14392 bgp_unlock_node (rn);
14393 }
718e3744 14394 }
14395
14396 return CMD_SUCCESS;
14397}
14398
14399DEFUN (clear_ip_bgp_dampening,
14400 clear_ip_bgp_dampening_cmd,
14401 "clear ip bgp dampening",
14402 CLEAR_STR
14403 IP_STR
14404 BGP_STR
14405 "Clear route flap dampening information\n")
14406{
14407 bgp_damp_info_clean ();
14408 return CMD_SUCCESS;
14409}
14410
14411DEFUN (clear_ip_bgp_dampening_prefix,
14412 clear_ip_bgp_dampening_prefix_cmd,
14413 "clear ip bgp dampening A.B.C.D/M",
14414 CLEAR_STR
14415 IP_STR
14416 BGP_STR
14417 "Clear route flap dampening information\n"
14418 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14419{
14420 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14421 SAFI_UNICAST, NULL, 1);
14422}
14423
14424DEFUN (clear_ip_bgp_dampening_address,
14425 clear_ip_bgp_dampening_address_cmd,
14426 "clear ip bgp dampening A.B.C.D",
14427 CLEAR_STR
14428 IP_STR
14429 BGP_STR
14430 "Clear route flap dampening information\n"
14431 "Network to clear damping information\n")
14432{
14433 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14434 SAFI_UNICAST, NULL, 0);
14435}
14436
14437DEFUN (clear_ip_bgp_dampening_address_mask,
14438 clear_ip_bgp_dampening_address_mask_cmd,
14439 "clear ip bgp dampening A.B.C.D A.B.C.D",
14440 CLEAR_STR
14441 IP_STR
14442 BGP_STR
14443 "Clear route flap dampening information\n"
14444 "Network to clear damping information\n"
14445 "Network mask\n")
14446{
14447 int ret;
14448 char prefix_str[BUFSIZ];
14449
14450 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
14451 if (! ret)
14452 {
14453 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
14454 return CMD_WARNING;
14455 }
14456
14457 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
14458 SAFI_UNICAST, NULL, 0);
14459}
6b0655a2 14460
587ff0fd 14461/* also used for encap safi */
94f2b392 14462static int
718e3744 14463bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
14464 afi_t afi, safi_t safi, int *write)
14465{
14466 struct bgp_node *prn;
14467 struct bgp_node *rn;
14468 struct bgp_table *table;
14469 struct prefix *p;
14470 struct prefix_rd *prd;
14471 struct bgp_static *bgp_static;
14472 u_int32_t label;
14473 char buf[SU_ADDRSTRLEN];
14474 char rdbuf[RD_ADDRSTRLEN];
14475
14476 /* Network configuration. */
14477 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
14478 if ((table = prn->info) != NULL)
14479 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
14480 if ((bgp_static = rn->info) != NULL)
14481 {
14482 p = &rn->p;
14483 prd = (struct prefix_rd *) &prn->p;
14484
14485 /* "address-family" display. */
14486 bgp_config_write_family_header (vty, afi, safi, write);
14487
14488 /* "network" configuration display. */
14489 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
14490 label = decode_label (bgp_static->tag);
14491
0b960b4d 14492 vty_out (vty, " network %s/%d rd %s tag %d",
718e3744 14493 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14494 p->prefixlen,
14495 rdbuf, label);
14496 vty_out (vty, "%s", VTY_NEWLINE);
14497 }
14498 return 0;
14499}
14500
14501/* Configuration of static route announcement and aggregate
14502 information. */
14503int
14504bgp_config_write_network (struct vty *vty, struct bgp *bgp,
14505 afi_t afi, safi_t safi, int *write)
14506{
14507 struct bgp_node *rn;
14508 struct prefix *p;
14509 struct bgp_static *bgp_static;
14510 struct bgp_aggregate *bgp_aggregate;
14511 char buf[SU_ADDRSTRLEN];
14512
587ff0fd 14513 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
718e3744 14514 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
14515
14516 /* Network configuration. */
14517 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
14518 if ((bgp_static = rn->info) != NULL)
14519 {
14520 p = &rn->p;
14521
14522 /* "address-family" display. */
14523 bgp_config_write_family_header (vty, afi, safi, write);
14524
14525 /* "network" configuration display. */
14526 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14527 {
14528 u_int32_t destination;
14529 struct in_addr netmask;
14530
14531 destination = ntohl (p->u.prefix4.s_addr);
14532 masklen2ip (p->prefixlen, &netmask);
0b960b4d 14533 vty_out (vty, " network %s",
718e3744 14534 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
14535
14536 if ((IN_CLASSC (destination) && p->prefixlen == 24)
14537 || (IN_CLASSB (destination) && p->prefixlen == 16)
14538 || (IN_CLASSA (destination) && p->prefixlen == 8)
14539 || p->u.prefix4.s_addr == 0)
14540 {
14541 /* Natural mask is not display. */
14542 }
14543 else
14544 vty_out (vty, " mask %s", inet_ntoa (netmask));
14545 }
14546 else
14547 {
0b960b4d 14548 vty_out (vty, " network %s/%d",
718e3744 14549 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14550 p->prefixlen);
14551 }
14552
14553 if (bgp_static->rmap.name)
14554 vty_out (vty, " route-map %s", bgp_static->rmap.name);
41367172
PJ
14555 else
14556 {
14557 if (bgp_static->backdoor)
14558 vty_out (vty, " backdoor");
41367172 14559 }
718e3744 14560
14561 vty_out (vty, "%s", VTY_NEWLINE);
14562 }
14563
14564 /* Aggregate-address configuration. */
14565 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
14566 if ((bgp_aggregate = rn->info) != NULL)
14567 {
14568 p = &rn->p;
14569
14570 /* "address-family" display. */
14571 bgp_config_write_family_header (vty, afi, safi, write);
14572
14573 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14574 {
14575 struct in_addr netmask;
14576
14577 masklen2ip (p->prefixlen, &netmask);
0b960b4d 14578 vty_out (vty, " aggregate-address %s %s",
718e3744 14579 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14580 inet_ntoa (netmask));
14581 }
14582 else
14583 {
0b960b4d 14584 vty_out (vty, " aggregate-address %s/%d",
718e3744 14585 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14586 p->prefixlen);
14587 }
14588
14589 if (bgp_aggregate->as_set)
14590 vty_out (vty, " as-set");
14591
14592 if (bgp_aggregate->summary_only)
14593 vty_out (vty, " summary-only");
14594
14595 vty_out (vty, "%s", VTY_NEWLINE);
14596 }
14597
14598 return 0;
14599}
14600
14601int
734b349e
MZ
14602bgp_config_write_distance (struct vty *vty, struct bgp *bgp, afi_t afi,
14603 safi_t safi, int *write)
718e3744 14604{
14605 struct bgp_node *rn;
14606 struct bgp_distance *bdistance;
14607
14608 /* Distance configuration. */
734b349e
MZ
14609 if (bgp->distance_ebgp[afi][safi]
14610 && bgp->distance_ibgp[afi][safi]
14611 && bgp->distance_local[afi][safi]
14612 && (bgp->distance_ebgp[afi][safi] != ZEBRA_EBGP_DISTANCE_DEFAULT
14613 || bgp->distance_ibgp[afi][safi] != ZEBRA_IBGP_DISTANCE_DEFAULT
14614 || bgp->distance_local[afi][safi] != ZEBRA_IBGP_DISTANCE_DEFAULT))
14615 {
14616 bgp_config_write_family_header (vty, afi, safi, write);
14617 vty_out (vty, " distance bgp %d %d %d%s",
14618 bgp->distance_ebgp[afi][safi], bgp->distance_ibgp[afi][safi],
14619 bgp->distance_local[afi][safi], VTY_NEWLINE);
14620 }
14621
14622 for (rn = bgp_table_top (bgp_distance_table[afi][safi]); rn;
14623 rn = bgp_route_next (rn))
718e3744 14624 if ((bdistance = rn->info) != NULL)
14625 {
734b349e
MZ
14626 char buf[PREFIX_STRLEN];
14627
14628 bgp_config_write_family_header (vty, afi, safi, write);
14629 vty_out (vty, " distance %d %s %s%s", bdistance->distance,
14630 prefix2str (&rn->p, buf, sizeof (buf)),
718e3744 14631 bdistance->access_list ? bdistance->access_list : "",
14632 VTY_NEWLINE);
14633 }
14634
734b349e 14635 return *write;
718e3744 14636}
14637
14638/* Allocate routing table structure and install commands. */
14639void
66e5cd87 14640bgp_route_init (void)
718e3744 14641{
734b349e
MZ
14642 afi_t afi;
14643 safi_t safi;
14644
718e3744 14645 /* Init BGP distance table. */
734b349e
MZ
14646 for (afi = AFI_IP; afi < AFI_MAX; afi++)
14647 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
14648 bgp_distance_table[afi][safi] = bgp_table_init (afi, safi);
718e3744 14649
14650 /* IPv4 BGP commands. */
73ac8160 14651 install_element (BGP_NODE, &bgp_table_map_cmd);
718e3744 14652 install_element (BGP_NODE, &bgp_network_cmd);
14653 install_element (BGP_NODE, &bgp_network_mask_cmd);
14654 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
14655 install_element (BGP_NODE, &bgp_network_route_map_cmd);
14656 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
14657 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
14658 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
14659 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
14660 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
73ac8160 14661 install_element (BGP_NODE, &no_bgp_table_map_cmd);
718e3744 14662 install_element (BGP_NODE, &no_bgp_network_cmd);
14663 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
14664 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
14665 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
14666 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
14667 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14668 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
14669 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
14670 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
14671
14672 install_element (BGP_NODE, &aggregate_address_cmd);
14673 install_element (BGP_NODE, &aggregate_address_mask_cmd);
14674 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
14675 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
14676 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
14677 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
14678 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
14679 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
14680 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
14681 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
14682 install_element (BGP_NODE, &no_aggregate_address_cmd);
14683 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
14684 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
14685 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
14686 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
14687 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
14688 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
14689 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
14690 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14691 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14692
14693 /* IPv4 unicast configuration. */
73ac8160 14694 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
718e3744 14695 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
14696 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
14697 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
14698 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
14699 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
14700 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 14701 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
c8f3fe30 14702 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
718e3744 14703 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
14704 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
14705 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
14706 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
14707 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
c8f3fe30 14708
718e3744 14709 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
14710 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
14711 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
14712 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
14713 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
14714 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
14715 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
14716 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
14717 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
14718 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
14719 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
14720 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
14721 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
14722 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
14723 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
14724 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
14725 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
14726 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
14727 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14728 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14729
14730 /* IPv4 multicast configuration. */
73ac8160 14731 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
718e3744 14732 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
14733 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
14734 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
14735 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
14736 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
14737 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 14738 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
718e3744 14739 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
14740 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
14741 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
14742 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
14743 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
14744 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14745 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
14746 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
14747 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
14748 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
14749 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
14750 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
14751 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
14752 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
14753 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
14754 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
14755 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
14756 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
14757 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
14758 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
14759 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
14760 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
14761 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
14762 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
14763 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14764 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14765
14766 install_element (VIEW_NODE, &show_ip_bgp_cmd);
f799a22a 14767 install_element (VIEW_NODE, &show_bgp_ipv4_cmd);
8386ac43 14768 install_element (VIEW_NODE, &show_ip_bgp_instance_cmd);
f186de26 14769 install_element (VIEW_NODE, &show_ip_bgp_instance_all_cmd);
718e3744 14770 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 14771 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
718e3744 14772 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
8386ac43 14773 install_element (VIEW_NODE, &show_ip_bgp_instance_route_cmd);
4092b06c 14774 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
8386ac43 14775 install_element (VIEW_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
4092b06c 14776 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 14777 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 14778 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 14779 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
8386ac43 14780 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd);
718e3744 14781 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
14782 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14783 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 14784 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 14785 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
8386ac43 14786 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
50ef26d4 14787
718e3744 14788 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
14789 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14790 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
8386ac43 14791 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_list_cmd);
718e3744 14792 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14793 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
8386ac43 14794 install_element (VIEW_NODE, &show_ip_bgp_instance_filter_list_cmd);
718e3744 14795 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14796 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
8386ac43 14797 install_element (VIEW_NODE, &show_ip_bgp_instance_route_map_cmd);
718e3744 14798 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14799 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
14800 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14801 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
14802 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14803 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
14804 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
14805 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
14806 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
14807 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
14808 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
14809 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
14810 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
8386ac43 14811 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14812 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_cmd);
14813 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14814 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14815 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community4_cmd);
718e3744 14816 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
14817 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
14818 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
14819 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
14820 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14821 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14822 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14823 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14824 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
8386ac43 14825 install_element (VIEW_NODE, &show_ip_bgp_instance_community_list_cmd);
718e3744 14826 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14827 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
14828 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14829 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
8386ac43 14830 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
718e3744 14831 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14832 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
8386ac43 14833 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
0b16f239 14834 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
8386ac43 14835 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
718e3744 14836 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
0b16f239 14837 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
718e3744 14838 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
8386ac43 14839 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
0b16f239 14840 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
8386ac43 14841 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
718e3744 14842 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
0b16f239 14843 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
8386ac43 14844 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 14845 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
8386ac43 14846 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
718e3744 14847 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14848 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14849 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
81304aaf 14850 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
58a90275 14851 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
718e3744 14852 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
58a90275
B
14853 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
14854 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
81304aaf 14855 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
718e3744 14856 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
81304aaf 14857 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
718e3744 14858 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
81304aaf 14859 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
718e3744 14860 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
14861 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
81304aaf 14862 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
718e3744 14863 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
14864 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
81304aaf 14865 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
718e3744 14866 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
81304aaf 14867 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
718e3744 14868 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
81304aaf 14869 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
718e3744 14870 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
81304aaf 14871 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
718e3744 14872 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
14873 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
14874
e3e29b32 14875 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
ccbb332a
LB
14876 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
14877 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
14878 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
14879 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
e3e29b32 14880
718e3744 14881 /* BGP dampening clear commands */
14882 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
14883 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
14884 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
14885 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
14886
ff7924f6
PJ
14887 /* prefix count */
14888 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
8386ac43 14889 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd);
ff7924f6 14890 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
718e3744 14891#ifdef HAVE_IPV6
ff7924f6 14892 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
8386ac43 14893 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd);
ff7924f6 14894
718e3744 14895 /* New config IPv6 BGP commands. */
73ac8160 14896 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
718e3744 14897 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
14898 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
73ac8160 14899 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
718e3744 14900 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
14901 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
14902
14903 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
14904 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
14905 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
14906 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
73bfe0bd
B
14907
14908 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
14909 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
718e3744 14910
14911 /* Old config IPv6 BGP commands. */
14912 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
14913 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
14914
14915 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
14916 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
14917 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
14918 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
14919
14920 install_element (VIEW_NODE, &show_bgp_cmd);
14921 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 14922 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 14923 install_element (VIEW_NODE, &show_bgp_route_cmd);
14924 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 14925 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
14926 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
14927 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14928 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 14929 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
14930 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 14931 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c
DS
14932 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
14933 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14934 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 14935 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
14936 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
14937 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
14938 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
14939 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
14940 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
14941 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
14942 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
14943 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
14944 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
14945 install_element (VIEW_NODE, &show_bgp_community_cmd);
14946 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
14947 install_element (VIEW_NODE, &show_bgp_community2_cmd);
14948 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
14949 install_element (VIEW_NODE, &show_bgp_community3_cmd);
14950 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
14951 install_element (VIEW_NODE, &show_bgp_community4_cmd);
14952 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
14953 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
14954 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
14955 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
14956 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
14957 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
14958 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
14959 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
14960 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
14961 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
14962 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
14963 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
14964 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14965 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
14966 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14967 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
14968 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14969 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
14970 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14971 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
14972 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14973 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14974 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 14975 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
14976 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14977 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
14978 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
8386ac43 14979 install_element (VIEW_NODE, &show_bgp_instance_cmd);
f186de26 14980 install_element (VIEW_NODE, &show_bgp_instance_all_cmd);
8386ac43 14981 install_element (VIEW_NODE, &show_bgp_instance_ipv6_cmd);
14982 install_element (VIEW_NODE, &show_bgp_instance_route_cmd);
14983 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_cmd);
14984 install_element (VIEW_NODE, &show_bgp_instance_route_pathtype_cmd);
14985 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14986 install_element (VIEW_NODE, &show_bgp_instance_prefix_cmd);
14987 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14988 install_element (VIEW_NODE, &show_bgp_instance_prefix_pathtype_cmd);
14989 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
14990 install_element (VIEW_NODE, &show_bgp_instance_prefix_list_cmd);
14991 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
14992 install_element (VIEW_NODE, &show_bgp_instance_filter_list_cmd);
14993 install_element (VIEW_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
14994 install_element (VIEW_NODE, &show_bgp_instance_route_map_cmd);
14995 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_map_cmd);
14996 install_element (VIEW_NODE, &show_bgp_instance_community_list_cmd);
14997 install_element (VIEW_NODE, &show_bgp_instance_ipv6_community_list_cmd);
14998 install_element (VIEW_NODE, &show_bgp_instance_prefix_longer_cmd);
14999 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
15000 install_element (VIEW_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
15001 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
15002 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
15003 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
15004 install_element (VIEW_NODE, &show_bgp_instance_neighbor_routes_cmd);
15005 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
15006 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
15007 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
15008 install_element (VIEW_NODE, &show_bgp_instance_neighbor_flap_cmd);
15009 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
15010 install_element (VIEW_NODE, &show_bgp_instance_neighbor_damp_cmd);
15011 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
718e3744 15012
2815e61f
PJ
15013 /* Statistics */
15014 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
587ff0fd 15015 //install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
2815e61f 15016 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
587ff0fd 15017 //install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
2815e61f 15018
718e3744 15019 /* old command */
15020 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
15021 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
15022 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
15023 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
15024 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
15025 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
15026 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
15027 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
15028 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
15029 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
15030 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
15031 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
15032 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
15033 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
15034 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
15035 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
15036 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15037 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15038 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
15039 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
15040 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
15041 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
15042 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15043 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
15044 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
15045 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
15046 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
15047 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
15048 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
15049 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
15050 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
15051 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
15052 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
15053 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
15054 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15055 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
bb46e94f 15056
718e3744 15057 /* old command */
15058 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
718e3744 15059 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
718e3744 15060
15061 /* old command */
15062 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
718e3744 15063 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
718e3744 15064
15065 /* old command */
15066 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
718e3744 15067 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
718e3744 15068#endif /* HAVE_IPV6 */
15069
15070 install_element (BGP_NODE, &bgp_distance_cmd);
15071 install_element (BGP_NODE, &no_bgp_distance_cmd);
15072 install_element (BGP_NODE, &no_bgp_distance2_cmd);
15073 install_element (BGP_NODE, &bgp_distance_source_cmd);
15074 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
15075 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
15076 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
734b349e
MZ
15077 install_element (BGP_IPV4_NODE, &bgp_distance_cmd);
15078 install_element (BGP_IPV4_NODE, &no_bgp_distance_cmd);
15079 install_element (BGP_IPV4_NODE, &no_bgp_distance2_cmd);
15080 install_element (BGP_IPV4_NODE, &bgp_distance_source_cmd);
15081 install_element (BGP_IPV4_NODE, &no_bgp_distance_source_cmd);
15082 install_element (BGP_IPV4_NODE, &bgp_distance_source_access_list_cmd);
15083 install_element (BGP_IPV4_NODE, &no_bgp_distance_source_access_list_cmd);
15084 install_element (BGP_IPV4M_NODE, &bgp_distance_cmd);
15085 install_element (BGP_IPV4M_NODE, &no_bgp_distance_cmd);
15086 install_element (BGP_IPV4M_NODE, &no_bgp_distance2_cmd);
15087 install_element (BGP_IPV4M_NODE, &bgp_distance_source_cmd);
15088 install_element (BGP_IPV4M_NODE, &no_bgp_distance_source_cmd);
15089 install_element (BGP_IPV4M_NODE, &bgp_distance_source_access_list_cmd);
15090 install_element (BGP_IPV4M_NODE, &no_bgp_distance_source_access_list_cmd);
15091 install_element (BGP_IPV6_NODE, &bgp_distance_cmd);
15092 install_element (BGP_IPV6_NODE, &no_bgp_distance_cmd);
15093 install_element (BGP_IPV6_NODE, &no_bgp_distance2_cmd);
15094 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_cmd);
15095 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_cmd);
15096 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_access_list_cmd);
15097 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
15098 install_element (BGP_IPV6M_NODE, &bgp_distance_cmd);
15099 install_element (BGP_IPV6M_NODE, &no_bgp_distance_cmd);
15100 install_element (BGP_IPV6M_NODE, &no_bgp_distance2_cmd);
15101 install_element (BGP_IPV6M_NODE, &ipv6_bgp_distance_source_cmd);
15102 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_distance_source_cmd);
15103 install_element (BGP_IPV6M_NODE, &ipv6_bgp_distance_source_access_list_cmd);
15104 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
718e3744 15105
15106 install_element (BGP_NODE, &bgp_damp_set_cmd);
15107 install_element (BGP_NODE, &bgp_damp_set2_cmd);
15108 install_element (BGP_NODE, &bgp_damp_set3_cmd);
15109 install_element (BGP_NODE, &bgp_damp_unset_cmd);
15110 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
813d4307 15111 install_element (BGP_NODE, &bgp_damp_unset3_cmd);
718e3744 15112 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
15113 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
15114 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
15115 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
15116 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
813d4307 15117 install_element (BGP_IPV4_NODE, &bgp_damp_unset3_cmd);
5c9e5a8d
B
15118
15119 /* IPv4 Multicast Mode */
15120 install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd);
15121 install_element (BGP_IPV4M_NODE, &bgp_damp_set2_cmd);
15122 install_element (BGP_IPV4M_NODE, &bgp_damp_set3_cmd);
15123 install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
15124 install_element (BGP_IPV4M_NODE, &bgp_damp_unset2_cmd);
718e3744 15125}
228da428
CC
15126
15127void
15128bgp_route_finish (void)
15129{
734b349e
MZ
15130 afi_t afi;
15131 safi_t safi;
15132
15133 for (afi = AFI_IP; afi < AFI_MAX; afi++)
15134 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
15135 {
15136 bgp_table_unlock (bgp_distance_table[afi][safi]);
15137 bgp_distance_table[afi][safi] = NULL;
15138 }
228da428 15139}