]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_route.c
convert <1-255> to (1-255), ()s to <>s, etc
[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
23#include "prefix.h"
24#include "linklist.h"
25#include "memory.h"
26#include "command.h"
27#include "stream.h"
28#include "filter.h"
29#include "str.h"
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"
4dcadbef 39#include "lib/json.h"
718e3744 40
41#include "bgpd/bgpd.h"
42#include "bgpd/bgp_table.h"
43#include "bgpd/bgp_route.h"
44#include "bgpd/bgp_attr.h"
45#include "bgpd/bgp_debug.h"
46#include "bgpd/bgp_aspath.h"
47#include "bgpd/bgp_regex.h"
48#include "bgpd/bgp_community.h"
49#include "bgpd/bgp_ecommunity.h"
50#include "bgpd/bgp_clist.h"
51#include "bgpd/bgp_packet.h"
52#include "bgpd/bgp_filter.h"
53#include "bgpd/bgp_fsm.h"
54#include "bgpd/bgp_mplsvpn.h"
55#include "bgpd/bgp_nexthop.h"
56#include "bgpd/bgp_damp.h"
57#include "bgpd/bgp_advertise.h"
58#include "bgpd/bgp_zebra.h"
0a486e5f 59#include "bgpd/bgp_vty.h"
96450faf 60#include "bgpd/bgp_mpath.h"
fc9a856f 61#include "bgpd/bgp_nht.h"
3f9c7369 62#include "bgpd/bgp_updgrp.h"
8386ac43 63#include "bgpd/bgp_vty.h"
718e3744 64
65/* Extern from bgp_dump.c */
dde72586
SH
66extern const char *bgp_origin_str[];
67extern const char *bgp_origin_long_str[];
6b0655a2 68
4125bb67 69struct bgp_node *
fee0f4c6 70bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
718e3744 71 struct prefix_rd *prd)
72{
73 struct bgp_node *rn;
74 struct bgp_node *prn = NULL;
da5b30f6
PJ
75
76 assert (table);
77 if (!table)
78 return NULL;
79
587ff0fd 80 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 81 {
fee0f4c6 82 prn = bgp_node_get (table, (struct prefix *) prd);
718e3744 83
84 if (prn->info == NULL)
64e580a7 85 prn->info = bgp_table_init (afi, safi);
718e3744 86 else
87 bgp_unlock_node (prn);
88 table = prn->info;
89 }
718e3744 90
91 rn = bgp_node_get (table, p);
92
587ff0fd 93 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 94 rn->prn = prn;
95
96 return rn;
97}
6b0655a2 98
fb982c25
PJ
99/* Allocate bgp_info_extra */
100static struct bgp_info_extra *
101bgp_info_extra_new (void)
102{
103 struct bgp_info_extra *new;
104 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
105 return new;
106}
107
108static void
109bgp_info_extra_free (struct bgp_info_extra **extra)
110{
111 if (extra && *extra)
112 {
113 if ((*extra)->damp_info)
114 bgp_damp_info_free ((*extra)->damp_info, 0);
115
116 (*extra)->damp_info = NULL;
117
118 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
119
120 *extra = NULL;
121 }
122}
123
124/* Get bgp_info extra information for the given bgp_info, lazy allocated
125 * if required.
126 */
127struct bgp_info_extra *
128bgp_info_extra_get (struct bgp_info *ri)
129{
130 if (!ri->extra)
131 ri->extra = bgp_info_extra_new();
132 return ri->extra;
133}
134
718e3744 135/* Free bgp route information. */
200df115 136static void
718e3744 137bgp_info_free (struct bgp_info *binfo)
138{
139 if (binfo->attr)
f6f434b2 140 bgp_attr_unintern (&binfo->attr);
fb018d25
DS
141
142 bgp_unlink_nexthop(binfo);
fb982c25 143 bgp_info_extra_free (&binfo->extra);
de8d5dff 144 bgp_info_mpath_free (&binfo->mpath);
718e3744 145
200df115 146 peer_unlock (binfo->peer); /* bgp_info peer reference */
147
718e3744 148 XFREE (MTYPE_BGP_ROUTE, binfo);
149}
150
200df115 151struct bgp_info *
152bgp_info_lock (struct bgp_info *binfo)
153{
154 binfo->lock++;
155 return binfo;
156}
157
158struct bgp_info *
159bgp_info_unlock (struct bgp_info *binfo)
160{
161 assert (binfo && binfo->lock > 0);
162 binfo->lock--;
163
164 if (binfo->lock == 0)
165 {
166#if 0
167 zlog_debug ("%s: unlocked and freeing", __func__);
168 zlog_backtrace (LOG_DEBUG);
169#endif
170 bgp_info_free (binfo);
171 return NULL;
172 }
173
174#if 0
175 if (binfo->lock == 1)
176 {
177 zlog_debug ("%s: unlocked to 1", __func__);
178 zlog_backtrace (LOG_DEBUG);
179 }
180#endif
181
182 return binfo;
183}
184
718e3744 185void
186bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
187{
188 struct bgp_info *top;
189
190 top = rn->info;
200df115 191
718e3744 192 ri->next = rn->info;
193 ri->prev = NULL;
194 if (top)
195 top->prev = ri;
196 rn->info = ri;
200df115 197
198 bgp_info_lock (ri);
199 bgp_lock_node (rn);
200 peer_lock (ri->peer); /* bgp_info peer reference */
718e3744 201}
202
b40d939b 203/* Do the actual removal of info from RIB, for use by bgp_process
204 completion callback *only* */
205static void
206bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
718e3744 207{
208 if (ri->next)
209 ri->next->prev = ri->prev;
210 if (ri->prev)
211 ri->prev->next = ri->next;
212 else
213 rn->info = ri->next;
200df115 214
de8d5dff 215 bgp_info_mpath_dequeue (ri);
200df115 216 bgp_info_unlock (ri);
217 bgp_unlock_node (rn);
718e3744 218}
219
b40d939b 220void
221bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
222{
1a392d46
PJ
223 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
224 /* set of previous already took care of pcount */
b40d939b 225 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
226}
227
8d45210e
AS
228/* undo the effects of a previous call to bgp_info_delete; typically
229 called when a route is deleted and then quickly re-added before the
230 deletion has been processed */
231static void
232bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
233{
234 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
235 /* unset of previous already took care of pcount */
236 SET_FLAG (ri->flags, BGP_INFO_VALID);
237}
238
1a392d46
PJ
239/* Adjust pcount as required */
240static void
241bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
242{
67174041
AS
243 struct bgp_table *table;
244
245 assert (rn && bgp_node_table (rn));
6f58544d
PJ
246 assert (ri && ri->peer && ri->peer->bgp);
247
67174041
AS
248 table = bgp_node_table (rn);
249
2a3d5731 250 if (ri->peer == ri->peer->bgp->peer_self)
1a392d46
PJ
251 return;
252
80e0ad24 253 if (!BGP_INFO_COUNTABLE (ri)
1a392d46
PJ
254 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
255 {
256
257 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
258
259 /* slight hack, but more robust against errors. */
67174041
AS
260 if (ri->peer->pcount[table->afi][table->safi])
261 ri->peer->pcount[table->afi][table->safi]--;
1a392d46
PJ
262 else
263 {
264 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
265 __func__, ri->peer->host);
266 zlog_backtrace (LOG_WARNING);
267 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
268 }
269 }
80e0ad24 270 else if (BGP_INFO_COUNTABLE (ri)
1a392d46
PJ
271 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
272 {
273 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
67174041 274 ri->peer->pcount[table->afi][table->safi]++;
1a392d46
PJ
275 }
276}
277
278
279/* Set/unset bgp_info flags, adjusting any other state as needed.
280 * This is here primarily to keep prefix-count in check.
281 */
282void
283bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
284{
285 SET_FLAG (ri->flags, flag);
286
80e0ad24
DS
287 /* early bath if we know it's not a flag that changes countability state */
288 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
1a392d46
PJ
289 return;
290
291 bgp_pcount_adjust (rn, ri);
292}
293
294void
295bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
296{
297 UNSET_FLAG (ri->flags, flag);
298
80e0ad24
DS
299 /* early bath if we know it's not a flag that changes countability state */
300 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
1a392d46
PJ
301 return;
302
303 bgp_pcount_adjust (rn, ri);
304}
305
718e3744 306/* Get MED value. If MED value is missing and "bgp bestpath
307 missing-as-worst" is specified, treat it as the worst value. */
94f2b392 308static u_int32_t
718e3744 309bgp_med_value (struct attr *attr, struct bgp *bgp)
310{
311 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
312 return attr->med;
313 else
314 {
315 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
3b424979 316 return BGP_MED_MAX;
718e3744 317 else
318 return 0;
319 }
320}
321
2ec1e66f
DW
322void
323bgp_info_path_with_addpath_rx_str (struct bgp_info *ri, char *buf)
324{
325 if (ri->addpath_rx_id)
326 sprintf(buf, "path %s (addpath rxid %d)", ri->peer->host, ri->addpath_rx_id);
327 else
328 sprintf(buf, "path %s", ri->peer->host);
329}
330
9fbdd100 331/* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1. */
94f2b392 332static int
96450faf 333bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
9fbdd100
DS
334 int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg, int debug,
335 char *pfx_buf)
718e3744 336{
8ff56318
JBD
337 struct attr *newattr, *existattr;
338 struct attr_extra *newattre, *existattre;
339 bgp_peer_sort_t new_sort;
340 bgp_peer_sort_t exist_sort;
718e3744 341 u_int32_t new_pref;
342 u_int32_t exist_pref;
343 u_int32_t new_med;
344 u_int32_t exist_med;
8ff56318
JBD
345 u_int32_t new_weight;
346 u_int32_t exist_weight;
347 uint32_t newm, existm;
718e3744 348 struct in_addr new_id;
349 struct in_addr exist_id;
350 int new_cluster;
351 int exist_cluster;
8ff56318
JBD
352 int internal_as_route;
353 int confed_as_route;
718e3744 354 int ret;
2ec1e66f
DW
355 char new_buf[PATH_ADDPATH_STR_BUFFER];
356 char exist_buf[PATH_ADDPATH_STR_BUFFER];
96450faf
JB
357
358 *paths_eq = 0;
718e3744 359
360 /* 0. Null check. */
361 if (new == NULL)
9fbdd100
DS
362 {
363 if (debug)
364 zlog_debug("%s: new is NULL", pfx_buf);
365 return 0;
366 }
367
2ec1e66f
DW
368 if (debug)
369 bgp_info_path_with_addpath_rx_str (new, new_buf);
370
718e3744 371 if (exist == NULL)
9fbdd100
DS
372 {
373 if (debug)
2ec1e66f 374 zlog_debug("%s: %s is the initial bestpath", pfx_buf, new_buf);
9fbdd100
DS
375 return 1;
376 }
718e3744 377
2ec1e66f 378 if (debug)
a6086ad4 379 {
380 bgp_info_path_with_addpath_rx_str (exist, exist_buf);
381 zlog_debug("%s: Comparing %s flags 0x%x with %s flags 0x%x",
382 pfx_buf, new_buf, new->flags, exist_buf, exist->flags);
383 }
2ec1e66f 384
8ff56318
JBD
385 newattr = new->attr;
386 existattr = exist->attr;
387 newattre = newattr->extra;
388 existattre = existattr->extra;
389
718e3744 390 /* 1. Weight check. */
8ff56318
JBD
391 new_weight = exist_weight = 0;
392
393 if (newattre)
394 new_weight = newattre->weight;
395 if (existattre)
396 exist_weight = existattre->weight;
397
fb982c25 398 if (new_weight > exist_weight)
9fbdd100
DS
399 {
400 if (debug)
2ec1e66f
DW
401 zlog_debug("%s: %s wins over %s due to weight %d > %d",
402 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
9fbdd100
DS
403 return 1;
404 }
405
fb982c25 406 if (new_weight < exist_weight)
9fbdd100
DS
407 {
408 if (debug)
2ec1e66f
DW
409 zlog_debug("%s: %s loses to %s due to weight %d < %d",
410 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
9fbdd100
DS
411 return 0;
412 }
718e3744 413
414 /* 2. Local preference check. */
8ff56318
JBD
415 new_pref = exist_pref = bgp->default_local_pref;
416
417 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
418 new_pref = newattr->local_pref;
419 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
420 exist_pref = existattr->local_pref;
718e3744 421
718e3744 422 if (new_pref > exist_pref)
9fbdd100
DS
423 {
424 if (debug)
2ec1e66f
DW
425 zlog_debug("%s: %s wins over %s due to localpref %d > %d",
426 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
9fbdd100
DS
427 return 1;
428 }
429
718e3744 430 if (new_pref < exist_pref)
9fbdd100
DS
431 {
432 if (debug)
2ec1e66f
DW
433 zlog_debug("%s: %s loses to %s due to localpref %d < %d",
434 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
9fbdd100
DS
435 return 0;
436 }
718e3744 437
8ff56318
JBD
438 /* 3. Local route check. We prefer:
439 * - BGP_ROUTE_STATIC
440 * - BGP_ROUTE_AGGREGATE
441 * - BGP_ROUTE_REDISTRIBUTE
442 */
443 if (! (new->sub_type == BGP_ROUTE_NORMAL))
9fbdd100
DS
444 {
445 if (debug)
2ec1e66f
DW
446 zlog_debug("%s: %s wins over %s due to preferred BGP_ROUTE type",
447 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
448 return 1;
449 }
450
8ff56318 451 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
9fbdd100
DS
452 {
453 if (debug)
2ec1e66f
DW
454 zlog_debug("%s: %s loses to %s due to preferred BGP_ROUTE type",
455 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
456 return 0;
457 }
718e3744 458
459 /* 4. AS path length check. */
460 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
461 {
8ff56318
JBD
462 int exist_hops = aspath_count_hops (existattr->aspath);
463 int exist_confeds = aspath_count_confeds (existattr->aspath);
fe69a505 464
6811845b 465 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
466 {
fe69a505 467 int aspath_hops;
468
8ff56318
JBD
469 aspath_hops = aspath_count_hops (newattr->aspath);
470 aspath_hops += aspath_count_confeds (newattr->aspath);
fe69a505 471
472 if ( aspath_hops < (exist_hops + exist_confeds))
9fbdd100
DS
473 {
474 if (debug)
2ec1e66f
DW
475 zlog_debug("%s: %s wins over %s due to aspath (with confeds) hopcount %d < %d",
476 pfx_buf, new_buf, exist_buf,
9fbdd100
DS
477 aspath_hops, (exist_hops + exist_confeds));
478 return 1;
479 }
480
fe69a505 481 if ( aspath_hops > (exist_hops + exist_confeds))
9fbdd100
DS
482 {
483 if (debug)
2ec1e66f
DW
484 zlog_debug("%s: %s loses to %s due to aspath (with confeds) hopcount %d > %d",
485 pfx_buf, new_buf, exist_buf,
9fbdd100
DS
486 aspath_hops, (exist_hops + exist_confeds));
487 return 0;
488 }
6811845b 489 }
490 else
491 {
8ff56318 492 int newhops = aspath_count_hops (newattr->aspath);
fe69a505 493
494 if (newhops < exist_hops)
9fbdd100
DS
495 {
496 if (debug)
2ec1e66f
DW
497 zlog_debug("%s: %s wins over %s due to aspath hopcount %d < %d",
498 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
9fbdd100
DS
499 return 1;
500 }
501
fe69a505 502 if (newhops > exist_hops)
9fbdd100
DS
503 {
504 if (debug)
2ec1e66f
DW
505 zlog_debug("%s: %s loses to %s due to aspath hopcount %d > %d",
506 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
9fbdd100
DS
507 return 0;
508 }
6811845b 509 }
718e3744 510 }
511
512 /* 5. Origin check. */
8ff56318 513 if (newattr->origin < existattr->origin)
9fbdd100
DS
514 {
515 if (debug)
2ec1e66f
DW
516 zlog_debug("%s: %s wins over %s due to ORIGIN %s < %s",
517 pfx_buf, new_buf, exist_buf,
9fbdd100
DS
518 bgp_origin_long_str[newattr->origin],
519 bgp_origin_long_str[existattr->origin]);
520 return 1;
521 }
522
8ff56318 523 if (newattr->origin > existattr->origin)
9fbdd100
DS
524 {
525 if (debug)
2ec1e66f
DW
526 zlog_debug("%s: %s loses to %s due to ORIGIN %s > %s",
527 pfx_buf, new_buf, exist_buf,
9fbdd100
DS
528 bgp_origin_long_str[newattr->origin],
529 bgp_origin_long_str[existattr->origin]);
530 return 0;
531 }
718e3744 532
533 /* 6. MED check. */
8ff56318
JBD
534 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
535 && aspath_count_hops (existattr->aspath) == 0);
536 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
537 && aspath_count_confeds (existattr->aspath) > 0
538 && aspath_count_hops (newattr->aspath) == 0
539 && aspath_count_hops (existattr->aspath) == 0);
718e3744 540
541 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
542 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
543 && confed_as_route)
8ff56318
JBD
544 || aspath_cmp_left (newattr->aspath, existattr->aspath)
545 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
718e3744 546 || internal_as_route)
547 {
548 new_med = bgp_med_value (new->attr, bgp);
549 exist_med = bgp_med_value (exist->attr, bgp);
550
551 if (new_med < exist_med)
9fbdd100
DS
552 {
553 if (debug)
2ec1e66f
DW
554 zlog_debug("%s: %s wins over %s due to MED %d < %d",
555 pfx_buf, new_buf, exist_buf, new_med, exist_med);
9fbdd100
DS
556 return 1;
557 }
558
718e3744 559 if (new_med > exist_med)
9fbdd100
DS
560 {
561 if (debug)
2ec1e66f
DW
562 zlog_debug("%s: %s loses to %s due to MED %d > %d",
563 pfx_buf, new_buf, exist_buf, new_med, exist_med);
9fbdd100
DS
564 return 0;
565 }
718e3744 566 }
567
568 /* 7. Peer type check. */
8ff56318
JBD
569 new_sort = new->peer->sort;
570 exist_sort = exist->peer->sort;
571
572 if (new_sort == BGP_PEER_EBGP
573 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
9fbdd100
DS
574 {
575 if (debug)
2ec1e66f
DW
576 zlog_debug("%s: %s wins over %s due to eBGP peer > iBGP peer",
577 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
578 return 1;
579 }
580
8ff56318
JBD
581 if (exist_sort == BGP_PEER_EBGP
582 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
9fbdd100
DS
583 {
584 if (debug)
2ec1e66f
DW
585 zlog_debug("%s: %s loses to %s due to iBGP peer < eBGP peer",
586 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
587 return 0;
588 }
718e3744 589
590 /* 8. IGP metric check. */
8ff56318
JBD
591 newm = existm = 0;
592
593 if (new->extra)
594 newm = new->extra->igpmetric;
595 if (exist->extra)
596 existm = exist->extra->igpmetric;
597
96450faf 598 if (newm < existm)
9fbdd100
DS
599 {
600 if (debug)
2ec1e66f
DW
601 zlog_debug("%s: %s wins over %s due to IGP metric %d < %d",
602 pfx_buf, new_buf, exist_buf, newm, existm);
9fbdd100
DS
603 ret = 1;
604 }
605
96450faf 606 if (newm > existm)
9fbdd100
DS
607 {
608 if (debug)
2ec1e66f
DW
609 zlog_debug("%s: %s loses to %s due to IGP metric %d > %d",
610 pfx_buf, new_buf, exist_buf, newm, existm);
9fbdd100
DS
611 ret = 0;
612 }
718e3744 613
31a4638f 614 /* 9. Same IGP metric. Compare the cluster list length as
5e242b0d
DS
615 representative of IGP hops metric. Rewrite the metric value
616 pair (newm, existm) with the cluster list length. Prefer the
617 path with smaller cluster list length. */
618 if (newm == existm)
619 {
620 if (peer_sort (new->peer) == BGP_PEER_IBGP
621 && peer_sort (exist->peer) == BGP_PEER_IBGP
622 && CHECK_FLAG (mpath_cfg->ibgp_flags,
623 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
624 {
625 newm = BGP_CLUSTER_LIST_LENGTH(new->attr);
626 existm = BGP_CLUSTER_LIST_LENGTH(exist->attr);
9fbdd100 627
5e242b0d 628 if (newm < existm)
9fbdd100
DS
629 {
630 if (debug)
2ec1e66f
DW
631 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
632 pfx_buf, new_buf, exist_buf, newm, existm);
9fbdd100
DS
633 ret = 1;
634 }
635
5e242b0d 636 if (newm > existm)
9fbdd100
DS
637 {
638 if (debug)
2ec1e66f
DW
639 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
640 pfx_buf, new_buf, exist_buf, newm, existm);
9fbdd100
DS
641 ret = 0;
642 }
5e242b0d
DS
643 }
644 }
645
31a4638f
DS
646 /* 10. confed-external vs. confed-internal */
647 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
648 {
649 if (new_sort == BGP_PEER_CONFED && exist_sort == BGP_PEER_IBGP)
650 {
651 if (debug)
2ec1e66f
DW
652 zlog_debug("%s: %s wins over %s due to confed-external peer > confed-internal peer",
653 pfx_buf, new_buf, exist_buf);
31a4638f
DS
654 return 1;
655 }
656
657 if (exist_sort == BGP_PEER_CONFED && new_sort == BGP_PEER_IBGP)
658 {
659 if (debug)
2ec1e66f
DW
660 zlog_debug("%s: %s loses to %s due to confed-internal peer < confed-external peer",
661 pfx_buf, new_buf, exist_buf);
31a4638f
DS
662 return 0;
663 }
664 }
665
666 /* 11. Maximum path check. */
96450faf
JB
667 if (newm == existm)
668 {
2fdd455c
PM
669 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
670 {
671
672 /*
673 * For the two paths, all comparison steps till IGP metric
674 * have succeeded - including AS_PATH hop count. Since 'bgp
675 * bestpath as-path multipath-relax' knob is on, we don't need
676 * an exact match of AS_PATH. Thus, mark the paths are equal.
677 * That will trigger both these paths to get into the multipath
678 * array.
679 */
680 *paths_eq = 1;
9fbdd100
DS
681
682 if (debug)
2ec1e66f
DW
683 zlog_debug("%s: %s and %s are equal via multipath-relax",
684 pfx_buf, new_buf, exist_buf);
2fdd455c
PM
685 }
686 else if (new->peer->sort == BGP_PEER_IBGP)
96450faf
JB
687 {
688 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
9fbdd100
DS
689 {
690 *paths_eq = 1;
691
692 if (debug)
2ec1e66f
DW
693 zlog_debug("%s: %s and %s are equal via matching aspaths",
694 pfx_buf, new_buf, exist_buf);
9fbdd100 695 }
96450faf
JB
696 }
697 else if (new->peer->as == exist->peer->as)
9fbdd100
DS
698 {
699 *paths_eq = 1;
700
701 if (debug)
2ec1e66f
DW
702 zlog_debug("%s: %s and %s are equal via same remote-as",
703 pfx_buf, new_buf, exist_buf);
9fbdd100 704 }
96450faf
JB
705 }
706 else
707 {
708 /*
709 * TODO: If unequal cost ibgp multipath is enabled we can
710 * mark the paths as equal here instead of returning
711 */
a6086ad4 712 if (debug)
713 {
714 if (ret == 1)
715 zlog_debug("%s: %s wins over %s after IGP metric comparison",
716 pfx_buf, new_buf, exist_buf);
717 else
718 zlog_debug("%s: %s loses to %s after IGP metric comparison",
719 pfx_buf, new_buf, exist_buf);
720 }
96450faf
JB
721 return ret;
722 }
718e3744 723
31a4638f 724 /* 12. If both paths are external, prefer the path that was received
718e3744 725 first (the oldest one). This step minimizes route-flap, since a
726 newer path won't displace an older one, even if it was the
727 preferred route based on the additional decision criteria below. */
728 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
8ff56318
JBD
729 && new_sort == BGP_PEER_EBGP
730 && exist_sort == BGP_PEER_EBGP)
718e3744 731 {
732 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
9fbdd100
DS
733 {
734 if (debug)
2ec1e66f
DW
735 zlog_debug("%s: %s wins over %s due to oldest external",
736 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
737 return 1;
738 }
739
718e3744 740 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
9fbdd100
DS
741 {
742 if (debug)
2ec1e66f
DW
743 zlog_debug("%s: %s loses to %s due to oldest external",
744 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
745 return 0;
746 }
718e3744 747 }
748
31a4638f 749 /* 13. Router-ID comparision. */
0de5153c
DS
750 /* If one of the paths is "stale", the corresponding peer router-id will
751 * be 0 and would always win over the other path. If originator id is
752 * used for the comparision, it will decide which path is better.
753 */
8ff56318
JBD
754 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
755 new_id.s_addr = newattre->originator_id.s_addr;
718e3744 756 else
757 new_id.s_addr = new->peer->remote_id.s_addr;
8ff56318
JBD
758 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
759 exist_id.s_addr = existattre->originator_id.s_addr;
718e3744 760 else
761 exist_id.s_addr = exist->peer->remote_id.s_addr;
762
763 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
9fbdd100
DS
764 {
765 if (debug)
2ec1e66f
DW
766 zlog_debug("%s: %s wins over %s due to Router-ID comparison",
767 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
768 return 1;
769 }
770
718e3744 771 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
9fbdd100
DS
772 {
773 if (debug)
2ec1e66f
DW
774 zlog_debug("%s: %s loses to %s due to Router-ID comparison",
775 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
776 return 0;
777 }
718e3744 778
31a4638f 779 /* 14. Cluster length comparision. */
5e242b0d
DS
780 new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
781 exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
718e3744 782
783 if (new_cluster < exist_cluster)
9fbdd100
DS
784 {
785 if (debug)
2ec1e66f
DW
786 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
787 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
9fbdd100
DS
788 return 1;
789 }
790
718e3744 791 if (new_cluster > exist_cluster)
9fbdd100
DS
792 {
793 if (debug)
2ec1e66f
DW
794 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
795 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
9fbdd100
DS
796 return 0;
797 }
718e3744 798
31a4638f 799 /* 15. Neighbor address comparision. */
0de5153c
DS
800 /* Do this only if neither path is "stale" as stale paths do not have
801 * valid peer information (as the connection may or may not be up).
802 */
803 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
9fbdd100
DS
804 {
805 if (debug)
2ec1e66f
DW
806 zlog_debug("%s: %s wins over %s due to latter path being STALE",
807 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
808 return 1;
809 }
810
0de5153c 811 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
9fbdd100
DS
812 {
813 if (debug)
2ec1e66f
DW
814 zlog_debug("%s: %s loses to %s due to former path being STALE",
815 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
816 return 0;
817 }
0de5153c 818
43ed4fe5
TT
819 /* locally configured routes to advertise do not have su_remote */
820 if (new->peer->su_remote == NULL)
821 return 0;
822 if (exist->peer->su_remote == NULL)
823 return 1;
824
718e3744 825 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
826
827 if (ret == 1)
9fbdd100
DS
828 {
829 if (debug)
2ec1e66f
DW
830 zlog_debug("%s: %s loses to %s due to Neighor IP comparison",
831 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
832 return 0;
833 }
834
718e3744 835 if (ret == -1)
9fbdd100
DS
836 {
837 if (debug)
2ec1e66f
DW
838 zlog_debug("%s: %s wins over %s due to Neighor IP comparison",
839 pfx_buf, new_buf, exist_buf);
9fbdd100
DS
840 return 1;
841 }
842
843 if (debug)
2ec1e66f
DW
844 zlog_debug("%s: %s wins over %s due to nothing left to compare",
845 pfx_buf, new_buf, exist_buf);
718e3744 846
847 return 1;
848}
849
94f2b392 850static enum filter_type
718e3744 851bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
852 afi_t afi, safi_t safi)
853{
854 struct bgp_filter *filter;
855
856 filter = &peer->filter[afi][safi];
857
650f76c2
PJ
858#define FILTER_EXIST_WARN(F,f,filter) \
859 if (BGP_DEBUG (update, UPDATE_IN) \
860 && !(F ## _IN (filter))) \
16286195 861 zlog_warn ("%s: Could not find configured input %s-list %s!", \
650f76c2
PJ
862 peer->host, #f, F ## _IN_NAME(filter));
863
864 if (DISTRIBUTE_IN_NAME (filter)) {
865 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
866
718e3744 867 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
868 return FILTER_DENY;
650f76c2 869 }
718e3744 870
650f76c2
PJ
871 if (PREFIX_LIST_IN_NAME (filter)) {
872 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
873
718e3744 874 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
875 return FILTER_DENY;
650f76c2 876 }
718e3744 877
650f76c2
PJ
878 if (FILTER_LIST_IN_NAME (filter)) {
879 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
880
718e3744 881 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
882 return FILTER_DENY;
650f76c2
PJ
883 }
884
718e3744 885 return FILTER_PERMIT;
650f76c2 886#undef FILTER_EXIST_WARN
718e3744 887}
888
94f2b392 889static enum filter_type
718e3744 890bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
891 afi_t afi, safi_t safi)
892{
893 struct bgp_filter *filter;
894
895 filter = &peer->filter[afi][safi];
896
650f76c2
PJ
897#define FILTER_EXIST_WARN(F,f,filter) \
898 if (BGP_DEBUG (update, UPDATE_OUT) \
899 && !(F ## _OUT (filter))) \
16286195 900 zlog_warn ("%s: Could not find configured output %s-list %s!", \
650f76c2
PJ
901 peer->host, #f, F ## _OUT_NAME(filter));
902
903 if (DISTRIBUTE_OUT_NAME (filter)) {
904 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
905
718e3744 906 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
907 return FILTER_DENY;
650f76c2 908 }
718e3744 909
650f76c2
PJ
910 if (PREFIX_LIST_OUT_NAME (filter)) {
911 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
912
718e3744 913 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
914 return FILTER_DENY;
650f76c2 915 }
718e3744 916
650f76c2
PJ
917 if (FILTER_LIST_OUT_NAME (filter)) {
918 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
919
718e3744 920 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
921 return FILTER_DENY;
650f76c2 922 }
718e3744 923
924 return FILTER_PERMIT;
650f76c2 925#undef FILTER_EXIST_WARN
718e3744 926}
927
928/* If community attribute includes no_export then return 1. */
94f2b392 929static int
718e3744 930bgp_community_filter (struct peer *peer, struct attr *attr)
931{
932 if (attr->community)
933 {
934 /* NO_ADVERTISE check. */
935 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
936 return 1;
937
938 /* NO_EXPORT check. */
6d85b15b 939 if (peer->sort == BGP_PEER_EBGP &&
718e3744 940 community_include (attr->community, COMMUNITY_NO_EXPORT))
941 return 1;
942
943 /* NO_EXPORT_SUBCONFED check. */
6d85b15b
JBD
944 if (peer->sort == BGP_PEER_EBGP
945 || peer->sort == BGP_PEER_CONFED)
718e3744 946 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
947 return 1;
948 }
949 return 0;
950}
951
952/* Route reflection loop check. */
953static int
954bgp_cluster_filter (struct peer *peer, struct attr *attr)
955{
956 struct in_addr cluster_id;
957
fb982c25 958 if (attr->extra && attr->extra->cluster)
718e3744 959 {
960 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
961 cluster_id = peer->bgp->cluster_id;
962 else
963 cluster_id = peer->bgp->router_id;
964
fb982c25 965 if (cluster_loop_check (attr->extra->cluster, cluster_id))
718e3744 966 return 1;
967 }
968 return 0;
969}
6b0655a2 970
94f2b392 971static int
718e3744 972bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
ffd0c037 973 afi_t afi, safi_t safi, const char *rmap_name)
718e3744 974{
975 struct bgp_filter *filter;
976 struct bgp_info info;
977 route_map_result_t ret;
0b16f239 978 struct route_map *rmap = NULL;
718e3744 979
980 filter = &peer->filter[afi][safi];
981
982 /* Apply default weight value. */
fb982c25
PJ
983 if (peer->weight)
984 (bgp_attr_extra_get (attr))->weight = peer->weight;
718e3744 985
0b16f239
DS
986 if (rmap_name)
987 {
988 rmap = route_map_lookup_by_name(rmap_name);
98a4a44e
DS
989
990 if (rmap == NULL)
991 return RMAP_DENY;
0b16f239
DS
992 }
993 else
994 {
995 if (ROUTE_MAP_IN_NAME(filter))
98a4a44e
DS
996 {
997 rmap = ROUTE_MAP_IN (filter);
998
999 if (rmap == NULL)
1000 return RMAP_DENY;
1001 }
0b16f239
DS
1002 }
1003
718e3744 1004 /* Route map apply. */
0b16f239 1005 if (rmap)
718e3744 1006 {
1007 /* Duplicate current value to new strucutre for modification. */
1008 info.peer = peer;
1009 info.attr = attr;
1010
ac41b2a2 1011 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
1012
718e3744 1013 /* Apply BGP route map to the attribute. */
0b16f239
DS
1014 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1015
1016 peer->rmap_type = 0;
1017
1018 if (ret == RMAP_DENYMATCH)
1019 {
1020 /* Free newly generated AS path and community by route-map. */
1021 bgp_attr_flush (attr);
1022 return RMAP_DENY;
1023 }
1024 }
1025 return RMAP_PERMIT;
1026}
1027
1028static int
1029bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
ffd0c037 1030 afi_t afi, safi_t safi, const char *rmap_name)
0b16f239
DS
1031{
1032 struct bgp_filter *filter;
1033 struct bgp_info info;
1034 route_map_result_t ret;
1035 struct route_map *rmap = NULL;
1036
1037 filter = &peer->filter[afi][safi];
1038
1039 /* Apply default weight value. */
1040 if (peer->weight)
1041 (bgp_attr_extra_get (attr))->weight = peer->weight;
1042
1043 if (rmap_name)
1044 {
1045 rmap = route_map_lookup_by_name(rmap_name);
98a4a44e
DS
1046
1047 if (rmap == NULL)
1048 return RMAP_DENY;
0b16f239
DS
1049 }
1050 else
1051 {
1052 if (ROUTE_MAP_OUT_NAME(filter))
98a4a44e
DS
1053 {
1054 rmap = ROUTE_MAP_OUT (filter);
1055
1056 if (rmap == NULL)
1057 return RMAP_DENY;
1058 }
0b16f239
DS
1059 }
1060
1061 /* Route map apply. */
1062 if (rmap)
1063 {
1064 /* Duplicate current value to new strucutre for modification. */
1065 info.peer = peer;
1066 info.attr = attr;
1067
1068 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1069
1070 /* Apply BGP route map to the attribute. */
1071 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
ac41b2a2 1072
1073 peer->rmap_type = 0;
1074
718e3744 1075 if (ret == RMAP_DENYMATCH)
c460e572
DL
1076 /* caller has multiple error paths with bgp_attr_flush() */
1077 return RMAP_DENY;
718e3744 1078 }
1079 return RMAP_PERMIT;
1080}
6b0655a2 1081
5000f21c 1082/* If this is an EBGP peer with remove-private-AS */
ffd0c037 1083static void
5000f21c
DS
1084bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
1085 struct peer *peer, struct attr *attr)
1086{
1087 if (peer->sort == BGP_PEER_EBGP &&
88b8ed8d
DW
1088 (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1089 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE) ||
1090 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL) ||
1091 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)))
5000f21c
DS
1092 {
1093 // Take action on the entire aspath
88b8ed8d
DW
1094 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1095 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
5000f21c 1096 {
88b8ed8d 1097 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
5000f21c
DS
1098 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1099
1100 // The entire aspath consists of private ASNs so create an empty aspath
1101 else if (aspath_private_as_check (attr->aspath))
1102 attr->aspath = aspath_empty_get ();
1103
1104 // There are some public and some private ASNs, remove the private ASNs
1105 else
1106 attr->aspath = aspath_remove_private_asns (attr->aspath);
1107 }
1108
1109 // 'all' was not specified so the entire aspath must be private ASNs
1110 // for us to do anything
1111 else if (aspath_private_as_check (attr->aspath))
1112 {
1113 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
1114 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1115 else
1116 attr->aspath = aspath_empty_get ();
1117 }
1118 }
1119}
1120
c7122e14
DS
1121/* If this is an EBGP peer with as-override */
1122static void
1123bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
1124 struct peer *peer, struct attr *attr)
1125{
1126 if (peer->sort == BGP_PEER_EBGP &&
1127 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
1128 {
1129 if (aspath_single_asn_check (attr->aspath, peer->as))
1130 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
1131 }
1132}
1133
3f9c7369
DS
1134static void
1135subgroup_announce_reset_nhop (u_char family, struct attr *attr)
1136{
1137 if (family == AF_INET)
1138 attr->nexthop.s_addr = 0;
1139#ifdef HAVE_IPV6
1140 if (family == AF_INET6)
1141 memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
1142#endif
1143}
1144
1145int
1146subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp,
1147 struct prefix *p, struct attr *attr)
1148{
1149 struct bgp_filter *filter;
1150 struct peer *from;
1151 struct peer *peer;
1152 struct peer *onlypeer;
1153 struct bgp *bgp;
1154 struct attr *riattr;
1155 struct peer_af *paf;
1156 char buf[SU_ADDRSTRLEN];
1157 int ret;
1158 int transparent;
1159 int reflect;
1160 afi_t afi;
1161 safi_t safi;
1162
1163 if (DISABLE_BGP_ANNOUNCE)
1164 return 0;
1165
1166 afi = SUBGRP_AFI(subgrp);
1167 safi = SUBGRP_SAFI(subgrp);
1168 peer = SUBGRP_PEER(subgrp);
1169 onlypeer = NULL;
1170 if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL))
1171 onlypeer = SUBGRP_PFIRST(subgrp)->peer;
1172
1173 from = ri->peer;
1174 filter = &peer->filter[afi][safi];
1175 bgp = SUBGRP_INST(subgrp);
1176 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1177
adbac85e
DW
1178 /* With addpath we may be asked to TX all kinds of paths so make sure
1179 * ri is valid */
1180 if (!CHECK_FLAG (ri->flags, BGP_INFO_VALID) ||
1181 CHECK_FLAG (ri->flags, BGP_INFO_HISTORY) ||
1182 CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
1183 {
1184 return 0;
1185 }
1186
06370dac
DW
1187 /* If this is not the bestpath then check to see if there is an enabled addpath
1188 * feature that requires us to advertise it */
1189 if (! CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1190 {
1191 if (! bgp_addpath_tx_path(peer, afi, safi, ri))
1192 {
1193 return 0;
1194 }
1195 }
1196
3f9c7369
DS
1197 /* Aggregate-address suppress check. */
1198 if (ri->extra && ri->extra->suppress)
1199 if (! UNSUPPRESS_MAP_NAME (filter))
1200 {
1201 return 0;
1202 }
1203
3f9c7369
DS
1204 /* Do not send back route to sender. */
1205 if (onlypeer && from == onlypeer)
1206 {
1207 return 0;
1208 }
1209
4125bb67
DS
1210 /* Do not send the default route in the BGP table if the neighbor is
1211 * configured for default-originate */
1212 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
1213 {
1214 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1215 return 0;
1216#ifdef HAVE_IPV6
1217 else if (p->family == AF_INET6 && p->prefixlen == 0)
1218 return 0;
1219#endif /* HAVE_IPV6 */
1220 }
1221
3f9c7369
DS
1222 /* Transparency check. */
1223 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1224 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1225 transparent = 1;
1226 else
1227 transparent = 0;
1228
1229 /* If community is not disabled check the no-export and local. */
1230 if (! transparent && bgp_community_filter (peer, riattr))
1231 {
1232 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1233 zlog_debug ("subgrpannouncecheck: community filter check fail");
1234 return 0;
1235 }
1236
1237 /* If the attribute has originator-id and it is same as remote
1238 peer's id. */
1239 if (onlypeer &&
1240 riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) &&
1241 (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id)))
1242 {
1243 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1244 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as "
1245 "remote router-id",
1246 onlypeer->host,
1247 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1248 p->prefixlen);
1249 return 0;
1250 }
1251
1252 /* ORF prefix-list filter check */
1253 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1254 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1255 || CHECK_FLAG (peer->af_cap[afi][safi],
1256 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1257 if (peer->orf_plist[afi][safi])
1258 {
1259 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1260 {
40d2700d
DW
1261 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1262 zlog_debug ("%s [Update:SEND] %s/%d is filtered via ORF",
1263 peer->host,
1264 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1265 p->prefixlen);
3f9c7369
DS
1266 return 0;
1267 }
1268 }
1269
1270 /* Output filter check. */
1271 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1272 {
1273 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1274 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1275 peer->host,
1276 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1277 p->prefixlen);
1278 return 0;
1279 }
1280
1281#ifdef BGP_SEND_ASPATH_CHECK
1282 /* AS path loop check. */
1283 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
1284 {
1285 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1286 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1287 "that is part of AS path.",
1288 onlypeer->host, onlypeer->as);
1289 return 0;
1290 }
1291#endif /* BGP_SEND_ASPATH_CHECK */
1292
1293 /* If we're a CONFED we need to loop check the CONFED ID too */
1294 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1295 {
1296 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1297 {
1298 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1299 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u"
1300 " is AS path.",
1301 peer->host,
1302 bgp->confed_id);
1303 return 0;
1304 }
1305 }
1306
1307 /* Route-Reflect check. */
1308 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1309 reflect = 1;
1310 else
1311 reflect = 0;
1312
1313 /* IBGP reflection check. */
1314 if (reflect)
1315 {
1316 /* A route from a Client peer. */
1317 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1318 {
1319 /* Reflect to all the Non-Client peers and also to the
1320 Client peers other than the originator. Originator check
1321 is already done. So there is noting to do. */
1322 /* no bgp client-to-client reflection check. */
1323 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1324 if (CHECK_FLAG (peer->af_flags[afi][safi],
1325 PEER_FLAG_REFLECTOR_CLIENT))
1326 return 0;
1327 }
1328 else
1329 {
1330 /* A route from a Non-client peer. Reflect to all other
1331 clients. */
1332 if (! CHECK_FLAG (peer->af_flags[afi][safi],
1333 PEER_FLAG_REFLECTOR_CLIENT))
1334 return 0;
1335 }
1336 }
1337
1338 /* For modify attribute, copy it to temporary structure. */
1339 bgp_attr_dup (attr, riattr);
1340
1341 /* If local-preference is not set. */
1342 if ((peer->sort == BGP_PEER_IBGP
1343 || peer->sort == BGP_PEER_CONFED)
1344 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1345 {
1346 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1347 attr->local_pref = bgp->default_local_pref;
1348 }
1349
1350 /* If originator-id is not set and the route is to be reflected,
1351 set the originator id */
1352 if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1353 {
1354 attr->extra = bgp_attr_extra_get(attr);
1355 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1356 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1357 }
1358
1359 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1360 if (peer->sort == BGP_PEER_EBGP
1361 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1362 {
003c1ba0 1363 if (from != bgp->peer_self && ! transparent
3f9c7369
DS
1364 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1365 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1366 }
1367
1368 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1369 * in announce check, only certain flags and length (or number of nexthops
1370 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1371 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1372 * Typically, the source nexthop in the attribute is preserved but in the
1373 * scenarios where we know it will always be overwritten, we reset the
1374 * nexthop to "0" in an attempt to achieve better Update packing. An
1375 * example of this is when a prefix from each of 2 IBGP peers needs to be
1376 * announced to an EBGP peer (and they have the same attributes barring
1377 * their nexthop).
1378 */
1379 if (reflect)
1380 SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
1381
1382#ifdef HAVE_IPV6
587ff0fd
LB
1383#define NEXTHOP_IS_V6 (\
1384 (safi != SAFI_ENCAP && \
1385 (p->family == AF_INET6 || peer_cap_enhe(peer))) || \
1386 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 16))
1387
3811f1e2
DS
1388 /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if
1389 * the peer (group) is configured to receive link-local nexthop unchanged
1390 * and it is available in the prefix OR we're not reflecting the route and
1391 * the peer (group) to whom we're going to announce is on a shared network
003c1ba0 1392 * and this is either a self-originated route or the peer is EBGP.
3f9c7369 1393 */
587ff0fd 1394 if (NEXTHOP_IS_V6)
3f9c7369 1395 {
801a9bcc 1396 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
3811f1e2
DS
1397 if ((CHECK_FLAG (peer->af_flags[afi][safi],
1398 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1399 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) ||
003c1ba0 1400 (!reflect && peer->shared_network &&
1401 (from == bgp->peer_self || peer->sort == BGP_PEER_EBGP)))
3f9c7369 1402 {
3811f1e2 1403 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
3f9c7369
DS
1404 }
1405
3811f1e2
DS
1406 /* Clear off link-local nexthop in source, whenever it is not needed to
1407 * ensure more prefixes share the same attribute for announcement.
3f9c7369
DS
1408 */
1409 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1410 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1411 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1412 }
1413#endif /* HAVE_IPV6 */
1414
1415 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1416 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1417
1418 /* Route map & unsuppress-map apply. */
1419 if (ROUTE_MAP_OUT_NAME (filter)
1420 || (ri->extra && ri->extra->suppress) )
1421 {
1422 struct bgp_info info;
1423 struct attr dummy_attr;
1424 struct attr_extra dummy_extra;
1425
1426 dummy_attr.extra = &dummy_extra;
1427
1428 info.peer = peer;
1429 info.attr = attr;
316e074d
DS
1430 /* don't confuse inbound and outbound setting */
1431 RESET_FLAG(attr->rmap_change_flags);
3f9c7369
DS
1432
1433 /*
1434 * The route reflector is not allowed to modify the attributes
1435 * of the reflected IBGP routes unless explicitly allowed.
1436 */
1437 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1438 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1439 {
1440 bgp_attr_dup (&dummy_attr, attr);
1441 info.attr = &dummy_attr;
1442 }
1443
1444 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1445
1446 if (ri->extra && ri->extra->suppress)
1447 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1448 else
1449 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1450
1451 peer->rmap_type = 0;
1452
1453 if (ret == RMAP_DENYMATCH)
1454 {
1455 bgp_attr_flush (attr);
1456 return 0;
1457 }
1458 }
1459
1460 /* After route-map has been applied, we check to see if the nexthop to
1461 * be carried in the attribute (that is used for the announcement) can
1462 * be cleared off or not. We do this in all cases where we would be
1463 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1464 * the global nexthop here; the link-local nexthop would have been cleared
1465 * already, and if not, it is required by the update formation code.
1466 * Also see earlier comments in this function.
43fdf718 1467 */
3811f1e2
DS
1468 /*
1469 * If route-map has performed some operation on the nexthop or the peer
1470 * configuration says to pass it unchanged, we cannot reset the nexthop
1471 * here, so only attempt to do it if these aren't true. Note that the
1472 * route-map handler itself might have cleared the nexthop, if for example,
1473 * it is configured as 'peer-address'.
3f9c7369 1474 */
3811f1e2
DS
1475 if (!bgp_rmap_nhop_changed(attr->rmap_change_flags,
1476 riattr->rmap_change_flags) &&
1477 !transparent &&
1478 !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
3f9c7369 1479 {
3811f1e2 1480 /* We can reset the nexthop, if setting (or forcing) it to 'self' */
88b8ed8d
DW
1481 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
1482 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
3f9c7369
DS
1483 {
1484 if (!reflect ||
1485 CHECK_FLAG (peer->af_flags[afi][safi],
43fdf718 1486 PEER_FLAG_FORCE_NEXTHOP_SELF))
3811f1e2
DS
1487 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ?
1488 AF_INET6 : p->family), attr);
3f9c7369
DS
1489 }
1490 else if (peer->sort == BGP_PEER_EBGP)
1491 {
3811f1e2
DS
1492 /* Can also reset the nexthop if announcing to EBGP, but only if
1493 * no peer in the subgroup is on a shared subnet.
1494 * Note: 3rd party nexthop currently implemented for IPv4 only.
1495 */
3f9c7369
DS
1496 SUBGRP_FOREACH_PEER (subgrp, paf)
1497 {
1498 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1499 break;
1500 }
1501 if (!paf)
8a92a8a0 1502 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr);
3f9c7369 1503 }
003c1ba0 1504 /* If IPv6/MP and nexthop does not have any override and happens to
1505 * be a link-local address, reset it so that we don't pass along the
1506 * source's link-local IPv6 address to recipients who may not be on
1507 * the same interface.
1508 */
1509 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1510 {
1511 if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global))
1512 subgroup_announce_reset_nhop (AF_INET6, attr);
1513 }
3f9c7369
DS
1514 }
1515
1516 return 1;
1517}
1518
fee0f4c6 1519struct bgp_info_pair
1520{
1521 struct bgp_info *old;
1522 struct bgp_info *new;
1523};
1524
94f2b392 1525static void
96450faf
JB
1526bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1527 struct bgp_maxpaths_cfg *mpath_cfg,
1528 struct bgp_info_pair *result)
718e3744 1529{
718e3744 1530 struct bgp_info *new_select;
1531 struct bgp_info *old_select;
fee0f4c6 1532 struct bgp_info *ri;
718e3744 1533 struct bgp_info *ri1;
1534 struct bgp_info *ri2;
b40d939b 1535 struct bgp_info *nextri = NULL;
9fbdd100 1536 int paths_eq, do_mpath, debug;
96450faf 1537 struct list mp_list;
4690c7d7 1538 char pfx_buf[PREFIX2STR_BUFFER];
2ec1e66f 1539 char path_buf[PATH_ADDPATH_STR_BUFFER];
96450faf
JB
1540
1541 bgp_mp_list_init (&mp_list);
99030da1 1542 do_mpath = (mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1);
96450faf 1543
9fbdd100
DS
1544 debug = bgp_debug_bestpath(&rn->p);
1545
1546 if (debug)
1547 prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf));
1548
718e3744 1549 /* bgp deterministic-med */
1550 new_select = NULL;
1551 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
06370dac
DW
1552 {
1553
1554 /* Clear BGP_INFO_DMED_SELECTED for all paths */
1555 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1556 bgp_info_unset_flag (rn, ri1, BGP_INFO_DMED_SELECTED);
1557
1558 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1559 {
1560 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1561 continue;
1562 if (BGP_INFO_HOLDDOWN (ri1))
2fed8887 1563 continue;
06370dac
DW
1564 if (ri1->peer && ri1->peer != bgp->peer_self)
1565 if (ri1->peer->status != Established)
1566 continue;
718e3744 1567
06370dac 1568 new_select = ri1;
06370dac
DW
1569 if (ri1->next)
1570 {
1571 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1572 {
1573 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1574 continue;
1575 if (BGP_INFO_HOLDDOWN (ri2))
1576 continue;
1577 if (ri2->peer &&
1578 ri2->peer != bgp->peer_self &&
1579 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1580 if (ri2->peer->status != Established)
1581 continue;
1582
1583 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1584 || aspath_cmp_left_confed (ri1->attr->aspath,
1585 ri2->attr->aspath))
1586 {
06370dac
DW
1587 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
1588 mpath_cfg, debug, pfx_buf))
1589 {
1590 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1591 new_select = ri2;
1592 }
1593
1594 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1595 }
1596 }
1597 }
1598 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1599 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
718e3744 1600
06370dac 1601 if (debug)
2ec1e66f
DW
1602 {
1603 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1604 zlog_debug("%s: %s is the bestpath from AS %d",
1605 pfx_buf, path_buf, aspath_get_firstas(new_select->attr->aspath));
1606 }
06370dac
DW
1607 }
1608 }
718e3744 1609
1610 /* Check old selected route and new selected route. */
1611 old_select = NULL;
1612 new_select = NULL;
b40d939b 1613 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
718e3744 1614 {
1615 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1616 old_select = ri;
1617
1618 if (BGP_INFO_HOLDDOWN (ri))
b40d939b 1619 {
1620 /* reap REMOVED routes, if needs be
1621 * selected route must stay for a while longer though
1622 */
1623 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1624 && (ri != old_select))
1625 bgp_info_reap (rn, ri);
1626
1627 continue;
1628 }
718e3744 1629
2fed8887
DS
1630 if (ri->peer &&
1631 ri->peer != bgp->peer_self &&
1632 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1633 if (ri->peer->status != Established)
1634 continue;
1635
718e3744 1636 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1637 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1638 {
1a392d46 1639 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
718e3744 1640 continue;
1641 }
06370dac 1642
1a392d46 1643 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
718e3744 1644
9fbdd100 1645 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
96450faf
JB
1646 {
1647 new_select = ri;
96450faf 1648 }
718e3744 1649 }
b40d939b 1650
f4eeff72
DS
1651 /* Now that we know which path is the bestpath see if any of the other paths
1652 * qualify as multipaths
1653 */
a6086ad4 1654 if (debug)
f4eeff72 1655 {
a6086ad4 1656 if (new_select)
1657 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1658 else
1659 sprintf (path_buf, "NONE");
1660 zlog_debug("%s: After path selection, newbest is %s oldbest was %s",
1661 pfx_buf, path_buf,
1662 old_select ? old_select->peer->host : "NONE");
1663 }
9fbdd100 1664
a6086ad4 1665 if (do_mpath && new_select)
1666 {
f4eeff72
DS
1667 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1668 {
2ec1e66f
DW
1669
1670 if (debug)
1671 bgp_info_path_with_addpath_rx_str (ri, path_buf);
1672
f4eeff72
DS
1673 if (ri == new_select)
1674 {
9fbdd100 1675 if (debug)
2ec1e66f
DW
1676 zlog_debug("%s: %s is the bestpath, add to the multipath list",
1677 pfx_buf, path_buf);
3064bf43 1678 bgp_mp_list_add (&mp_list, ri);
f4eeff72
DS
1679 continue;
1680 }
1681
1682 if (BGP_INFO_HOLDDOWN (ri))
1683 continue;
1684
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
7dc9d4e4
DW
1691 if (!bgp_info_nexthop_cmp (ri, new_select))
1692 {
1693 if (debug)
2ec1e66f
DW
1694 zlog_debug("%s: %s has the same nexthop as the bestpath, skip it",
1695 pfx_buf, path_buf);
7dc9d4e4
DW
1696 continue;
1697 }
1698
9fbdd100 1699 bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
f4eeff72
DS
1700
1701 if (paths_eq)
1702 {
9fbdd100 1703 if (debug)
2ec1e66f
DW
1704 zlog_debug("%s: %s is equivalent to the bestpath, add to the multipath list",
1705 pfx_buf, path_buf);
f4eeff72
DS
1706 bgp_mp_list_add (&mp_list, ri);
1707 }
1708 }
1709 }
fee0f4c6 1710
b354c427 1711 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
0b597ef0 1712 bgp_info_mpath_aggregate_update (new_select, old_select);
96450faf
JB
1713 bgp_mp_list_clear (&mp_list);
1714
1715 result->old = old_select;
1716 result->new = new_select;
1717
1718 return;
fee0f4c6 1719}
1720
3f9c7369
DS
1721/*
1722 * A new route/change in bestpath of an existing route. Evaluate the path
1723 * for advertisement to the subgroup.
1724 */
1725int
1726subgroup_process_announce_selected (struct update_subgroup *subgrp,
1727 struct bgp_info *selected,
adbac85e
DW
1728 struct bgp_node *rn,
1729 u_int32_t addpath_tx_id)
9eda90ce 1730{
fee0f4c6 1731 struct prefix *p;
3f9c7369 1732 struct peer *onlypeer;
558d1fec
JBD
1733 struct attr attr;
1734 struct attr_extra extra;
3f9c7369
DS
1735 afi_t afi;
1736 safi_t safi;
fee0f4c6 1737
1738 p = &rn->p;
3f9c7369
DS
1739 afi = SUBGRP_AFI(subgrp);
1740 safi = SUBGRP_SAFI(subgrp);
1741 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1742 (SUBGRP_PFIRST(subgrp))->peer : NULL);
718e3744 1743
9eda90ce 1744 /* First update is deferred until ORF or ROUTE-REFRESH is received */
3f9c7369
DS
1745 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
1746 PEER_STATUS_ORF_WAIT_REFRESH))
fee0f4c6 1747 return 0;
718e3744 1748
2a3d5731 1749 /* It's initialized in bgp_announce_check() */
558d1fec
JBD
1750 attr.extra = &extra;
1751
2a3d5731
DW
1752 /* Announcement to the subgroup. If the route is filtered withdraw it. */
1753 if (selected)
fee0f4c6 1754 {
2a3d5731
DW
1755 if (subgroup_announce_check(selected, subgrp, p, &attr))
1756 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
1757 else
1758 bgp_adj_out_unset_subgroup(rn, subgrp, 1, selected->addpath_tx_id);
1759 }
adbac85e 1760
2a3d5731
DW
1761 /* If selected is NULL we must withdraw the path using addpath_tx_id */
1762 else
1763 {
1764 bgp_adj_out_unset_subgroup(rn, subgrp, 1, addpath_tx_id);
fee0f4c6 1765 }
558d1fec 1766
fee0f4c6 1767 return 0;
200df115 1768}
fee0f4c6 1769
3064bf43 1770/*
e1072051 1771 * Clear IGP changed flag and attribute changed flag for a route (all paths).
1772 * This is called at the end of route processing.
3064bf43 1773 */
1774static void
1775bgp_zebra_clear_route_change_flags (struct bgp_node *rn)
1776{
1777 struct bgp_info *ri;
1778
1779 for (ri = rn->info; ri; ri = ri->next)
1780 {
1781 if (BGP_INFO_HOLDDOWN (ri))
1782 continue;
1783 UNSET_FLAG (ri->flags, BGP_INFO_IGP_CHANGED);
e1072051 1784 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3064bf43 1785 }
1786}
1787
1788/*
1789 * Has the route changed from the RIB's perspective? This is invoked only
1790 * if the route selection returns the same best route as earlier - to
1791 * determine if we need to update zebra or not.
1792 */
1793static int
1794bgp_zebra_has_route_changed (struct bgp_node *rn, struct bgp_info *selected)
1795{
1796 struct bgp_info *mpinfo;
1797
e1072051 1798 /* If this is multipath, check all selected paths for any nexthop change or
1799 * attribute change. Some attribute changes (e.g., community) aren't of
1800 * relevance to the RIB, but we'll update zebra to ensure we handle the
1801 * case of BGP nexthop change. This is the behavior when the best path has
1802 * an attribute change anyway.
1803 */
3064bf43 1804 if (CHECK_FLAG (selected->flags, BGP_INFO_IGP_CHANGED) ||
1805 CHECK_FLAG (selected->flags, BGP_INFO_MULTIPATH_CHG))
1806 return 1;
1807
1808 /* If this is multipath, check all selected paths for any nexthop change */
1809 for (mpinfo = bgp_info_mpath_first (selected); mpinfo;
1810 mpinfo = bgp_info_mpath_next (mpinfo))
1811 {
e1072051 1812 if (CHECK_FLAG (mpinfo->flags, BGP_INFO_IGP_CHANGED)
1813 || CHECK_FLAG (mpinfo->flags, BGP_INFO_ATTR_CHANGED))
3064bf43 1814 return 1;
1815 }
1816
1817 /* Nothing has changed from the RIB's perspective. */
1818 return 0;
1819}
1820
3f9c7369 1821struct bgp_process_queue
fee0f4c6 1822{
200df115 1823 struct bgp *bgp;
1824 struct bgp_node *rn;
1825 afi_t afi;
1826 safi_t safi;
1827};
1828
200df115 1829static wq_item_status
0fb58d5d 1830bgp_process_main (struct work_queue *wq, void *data)
200df115 1831{
0fb58d5d 1832 struct bgp_process_queue *pq = data;
200df115 1833 struct bgp *bgp = pq->bgp;
1834 struct bgp_node *rn = pq->rn;
1835 afi_t afi = pq->afi;
1836 safi_t safi = pq->safi;
1837 struct prefix *p = &rn->p;
fee0f4c6 1838 struct bgp_info *new_select;
1839 struct bgp_info *old_select;
1840 struct bgp_info_pair old_and_new;
cb1faec9
DS
1841
1842 /* Is it end of initial update? (after startup) */
1843 if (!rn)
1844 {
4a16ae86
DS
1845 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1846 sizeof(bgp->update_delay_zebra_resume_time));
1847
1848 bgp->main_zebra_update_hold = 0;
1849 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1850 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1851 {
1852 bgp_zebra_announce_table(bgp, afi, safi);
1853 }
1854 bgp->main_peers_update_hold = 0;
1855
cb1faec9
DS
1856 bgp_start_routeadv(bgp);
1857 return WQ_SUCCESS;
1858 }
1859
fee0f4c6 1860 /* Best path selection. */
96450faf 1861 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 1862 old_select = old_and_new.old;
1863 new_select = old_and_new.new;
1864
1865 /* Nothing to do. */
adbac85e
DW
1866 if (old_select && old_select == new_select &&
1867 !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR) &&
1868 !CHECK_FLAG(old_select->flags, BGP_INFO_ATTR_CHANGED) &&
1869 !bgp->addpath_tx_used[afi][safi])
1870 {
3064bf43 1871 if (bgp_zebra_has_route_changed (rn, old_select))
adbac85e 1872 bgp_zebra_announce (p, old_select, bgp, afi, safi);
200df115 1873
adbac85e 1874 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
3064bf43 1875 bgp_zebra_clear_route_change_flags (rn);
adbac85e
DW
1876 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1877 return WQ_SUCCESS;
fee0f4c6 1878 }
1879
8ad7271d
DS
1880 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1881 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1882
3f9c7369
DS
1883 /* bestpath has changed; bump version */
1884 if (old_select || new_select)
0de4848d
DS
1885 {
1886 bgp_bump_version(rn);
1887
1888 if (!bgp->t_rmap_def_originate_eval)
1889 {
1890 bgp_lock (bgp);
9229d914 1891 THREAD_TIMER_ON(bm->master, bgp->t_rmap_def_originate_eval,
0de4848d
DS
1892 update_group_refresh_default_originate_route_map,
1893 bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER);
1894 }
1895 }
3f9c7369 1896
338b3424 1897 if (old_select)
1a392d46 1898 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
338b3424 1899 if (new_select)
1900 {
1a392d46
PJ
1901 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1902 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 1903 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
338b3424 1904 }
1905
3f9c7369 1906 group_announce_route(bgp, afi, safi, rn, new_select);
718e3744 1907
1908 /* FIB update. */
ad4cbda1 1909 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) &&
1910 (bgp->inst_type != BGP_INSTANCE_TYPE_VIEW) &&
1911 !bgp_option_check (BGP_OPT_NO_FIB))
718e3744 1912 {
1913 if (new_select
1914 && new_select->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
1915 && (new_select->sub_type == BGP_ROUTE_NORMAL ||
1916 new_select->sub_type == BGP_ROUTE_AGGREGATE))
73ac8160 1917 bgp_zebra_announce (p, new_select, bgp, afi, safi);
718e3744 1918 else
1919 {
1920 /* Withdraw the route from the kernel. */
1921 if (old_select
1922 && old_select->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
1923 && (old_select->sub_type == BGP_ROUTE_NORMAL ||
1924 old_select->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 1925 bgp_zebra_withdraw (p, old_select, safi);
718e3744 1926 }
1927 }
3064bf43 1928
1929 /* Clear any route change flags. */
1930 bgp_zebra_clear_route_change_flags (rn);
1931
adbac85e 1932 /* Reap old select bgp_info, if it has been removed */
b40d939b 1933 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1934 bgp_info_reap (rn, old_select);
1935
200df115 1936 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1937 return WQ_SUCCESS;
718e3744 1938}
1939
200df115 1940static void
0fb58d5d 1941bgp_processq_del (struct work_queue *wq, void *data)
200df115 1942{
0fb58d5d 1943 struct bgp_process_queue *pq = data;
cb1faec9
DS
1944 struct bgp_table *table;
1945
228da428 1946 bgp_unlock (pq->bgp);
cb1faec9
DS
1947 if (pq->rn)
1948 {
1949 table = bgp_node_table (pq->rn);
1950 bgp_unlock_node (pq->rn);
1951 bgp_table_unlock (table);
1952 }
200df115 1953 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1954}
1955
f188f2c4 1956void
200df115 1957bgp_process_queue_init (void)
1958{
495f0b13
DS
1959 if (!bm->process_main_queue)
1960 {
1961 bm->process_main_queue
87d4a781 1962 = work_queue_new (bm->master, "process_main_queue");
495f0b13 1963
2a3d5731
DW
1964 if ( !bm->process_main_queue)
1965 {
1966 zlog_err ("%s: Failed to allocate work queue", __func__);
1967 exit (1);
1968 }
200df115 1969 }
1970
1971 bm->process_main_queue->spec.workfunc = &bgp_process_main;
200df115 1972 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
838bbde0
PJ
1973 bm->process_main_queue->spec.max_retries = 0;
1974 bm->process_main_queue->spec.hold = 50;
d889623f
DS
1975 /* Use a higher yield value of 50ms for main queue processing */
1976 bm->process_main_queue->spec.yield = 50 * 1000L;
200df115 1977}
1978
1979void
fee0f4c6 1980bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1981{
200df115 1982 struct bgp_process_queue *pqnode;
1983
1984 /* already scheduled for processing? */
1985 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1986 return;
495f0b13 1987
2a3d5731 1988 if (bm->process_main_queue == NULL)
2e02b9b2
DS
1989 bgp_process_queue_init ();
1990
200df115 1991 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1992 sizeof (struct bgp_process_queue));
1993 if (!pqnode)
1994 return;
228da428
CC
1995
1996 /* all unlocked in bgp_processq_del */
67174041 1997 bgp_table_lock (bgp_node_table (rn));
228da428 1998 pqnode->rn = bgp_lock_node (rn);
200df115 1999 pqnode->bgp = bgp;
228da428 2000 bgp_lock (bgp);
200df115 2001 pqnode->afi = afi;
2002 pqnode->safi = safi;
2a3d5731 2003 work_queue_add (bm->process_main_queue, pqnode);
07ff4dc4 2004 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
200df115 2005 return;
fee0f4c6 2006}
0a486e5f 2007
cb1faec9 2008void
2a3d5731 2009bgp_add_eoiu_mark (struct bgp *bgp)
cb1faec9
DS
2010{
2011 struct bgp_process_queue *pqnode;
2012
2a3d5731 2013 if (bm->process_main_queue == NULL)
2e02b9b2
DS
2014 bgp_process_queue_init ();
2015
cb1faec9
DS
2016 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2017 sizeof (struct bgp_process_queue));
2018 if (!pqnode)
2019 return;
2020
2021 pqnode->rn = NULL;
2022 pqnode->bgp = bgp;
2023 bgp_lock (bgp);
2a3d5731 2024 work_queue_add (bm->process_main_queue, pqnode);
cb1faec9
DS
2025}
2026
94f2b392 2027static int
0a486e5f 2028bgp_maximum_prefix_restart_timer (struct thread *thread)
2029{
2030 struct peer *peer;
2031
2032 peer = THREAD_ARG (thread);
2033 peer->t_pmax_restart = NULL;
2034
16286195 2035 if (bgp_debug_neighbor_events(peer))
0a486e5f 2036 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
2037 peer->host);
2038
1ff9a340 2039 peer_clear (peer, NULL);
0a486e5f 2040
2041 return 0;
2042}
2043
718e3744 2044int
5228ad27 2045bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
2046 safi_t safi, int always)
718e3744 2047{
e0701b79 2048 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
2049 return 0;
2050
2051 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
718e3744 2052 {
e0701b79 2053 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
2054 && ! always)
2055 return 0;
2056
16286195
DS
2057 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
2058 "limit %ld", afi_safi_print (afi, safi), peer->host,
2059 peer->pcount[afi][safi], peer->pmax[afi][safi]);
e0701b79 2060 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2061
2062 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
2063 return 0;
2064
2065 {
5228ad27 2066 u_int8_t ndata[7];
e0701b79 2067
2068 if (safi == SAFI_MPLS_VPN)
42e6d745 2069 safi = SAFI_MPLS_LABELED_VPN;
5228ad27 2070
2071 ndata[0] = (afi >> 8);
2072 ndata[1] = afi;
2073 ndata[2] = safi;
2074 ndata[3] = (peer->pmax[afi][safi] >> 24);
2075 ndata[4] = (peer->pmax[afi][safi] >> 16);
2076 ndata[5] = (peer->pmax[afi][safi] >> 8);
2077 ndata[6] = (peer->pmax[afi][safi]);
e0701b79 2078
2079 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
2080 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
2081 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
2082 }
0a486e5f 2083
f14e6fdb
DS
2084 /* Dynamic peers will just close their connection. */
2085 if (peer_dynamic_neighbor (peer))
2086 return 1;
2087
0a486e5f 2088 /* restart timer start */
2089 if (peer->pmax_restart[afi][safi])
2090 {
2091 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
2092
16286195 2093 if (bgp_debug_neighbor_events(peer))
0a486e5f 2094 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2095 peer->host, peer->v_pmax_restart);
2096
2097 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2098 peer->v_pmax_restart);
2099 }
2100
e0701b79 2101 return 1;
2102 }
2103 else
2104 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2105
2106 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2107 {
2108 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2109 && ! always)
2110 return 0;
2111
16286195
DS
2112 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2113 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2114 peer->pmax[afi][safi]);
e0701b79 2115 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2116 }
e0701b79 2117 else
2118 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2119 return 0;
2120}
2121
b40d939b 2122/* Unconditionally remove the route from the RIB, without taking
2123 * damping into consideration (eg, because the session went down)
2124 */
94f2b392 2125static void
718e3744 2126bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2127 afi_t afi, safi_t safi)
2128{
902212c3 2129 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2130
2131 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2132 bgp_info_delete (rn, ri); /* keep historical info */
2133
b40d939b 2134 bgp_process (peer->bgp, rn, afi, safi);
718e3744 2135}
2136
94f2b392 2137static void
718e3744 2138bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
b40d939b 2139 afi_t afi, safi_t safi)
718e3744 2140{
718e3744 2141 int status = BGP_DAMP_NONE;
2142
b40d939b 2143 /* apply dampening, if result is suppressed, we'll be retaining
2144 * the bgp_info in the RIB for historical reference.
2145 */
2146 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2147 && peer->sort == BGP_PEER_EBGP)
b40d939b 2148 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2149 == BGP_DAMP_SUPPRESSED)
902212c3 2150 {
902212c3 2151 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2152 return;
2153 }
2154
2155 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 2156}
2157
fb018d25 2158static struct bgp_info *
7c8ff89e 2159info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
fb018d25
DS
2160 struct bgp_node *rn)
2161{
2162 struct bgp_info *new;
2163
2164 /* Make new BGP info. */
2165 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2166 new->type = type;
7c8ff89e 2167 new->instance = instance;
fb018d25
DS
2168 new->sub_type = sub_type;
2169 new->peer = peer;
2170 new->attr = attr;
2171 new->uptime = bgp_clock ();
2172 new->net = rn;
adbac85e 2173 new->addpath_tx_id = ++peer->bgp->addpath_tx_id;
fb018d25
DS
2174 return new;
2175}
2176
94f2b392 2177static void
2ec1e66f 2178bgp_info_addpath_rx_str(u_int32_t addpath_id, char *buf)
cd808e74 2179{
2ec1e66f
DW
2180 if (addpath_id)
2181 sprintf(buf, " with addpath ID %d", addpath_id);
cd808e74
DS
2182}
2183
2ec1e66f 2184
c265ee22
DS
2185/* Check if received nexthop is valid or not. */
2186static int
6aeb9e78 2187bgp_update_martian_nexthop (struct bgp *bgp, afi_t afi, safi_t safi, struct attr *attr)
c265ee22
DS
2188{
2189 struct attr_extra *attre = attr->extra;
2190 int ret = 0;
2191
2192 /* Only validated for unicast and multicast currently. */
2193 if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST)
2194 return 0;
2195
2196 /* If NEXT_HOP is present, validate it. */
2197 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP))
2198 {
2199 if (attr->nexthop.s_addr == 0 ||
2200 IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) ||
6aeb9e78 2201 bgp_nexthop_self (bgp, attr))
c265ee22
DS
2202 ret = 1;
2203 }
2204
2205 /* If MP_NEXTHOP is present, validate it. */
2206 /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop;
2207 * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if
2208 * it is not an IPv6 link-local address.
2209 */
2210 if (attre && attre->mp_nexthop_len)
2211 {
2212 switch (attre->mp_nexthop_len)
2213 {
2214 case BGP_ATTR_NHLEN_IPV4:
2215 case BGP_ATTR_NHLEN_VPNV4:
2216 ret = (attre->mp_nexthop_global_in.s_addr == 0 ||
2217 IPV4_CLASS_DE (ntohl (attre->mp_nexthop_global_in.s_addr)));
2218 break;
2219
2220#ifdef HAVE_IPV6
2221 case BGP_ATTR_NHLEN_IPV6_GLOBAL:
2222 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
2223 ret = (IN6_IS_ADDR_UNSPECIFIED(&attre->mp_nexthop_global) ||
2224 IN6_IS_ADDR_LOOPBACK(&attre->mp_nexthop_global) ||
2225 IN6_IS_ADDR_MULTICAST(&attre->mp_nexthop_global));
2226 break;
2227#endif /* HAVE_IPV6 */
2228
2229 default:
2230 ret = 1;
2231 break;
2232 }
2233 }
2234
2235 return ret;
2236}
2237
a7ee645d
DS
2238int
2239bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2240 struct attr *attr, afi_t afi, safi_t safi, int type,
2241 int sub_type, struct prefix_rd *prd, u_char *tag,
2242 int soft_reconfig)
718e3744 2243{
2244 int ret;
2245 int aspath_loop_count = 0;
2246 struct bgp_node *rn;
2247 struct bgp *bgp;
558d1fec
JBD
2248 struct attr new_attr;
2249 struct attr_extra new_extra;
718e3744 2250 struct attr *attr_new;
2251 struct bgp_info *ri;
2252 struct bgp_info *new;
fd79ac91 2253 const char *reason;
718e3744 2254 char buf[SU_ADDRSTRLEN];
cd808e74 2255 char buf2[30];
fc9a856f 2256 int connected = 0;
718e3744 2257
2258 bgp = peer->bgp;
fee0f4c6 2259 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
fb982c25 2260
718e3744 2261 /* When peer's soft reconfiguration enabled. Record input packet in
2262 Adj-RIBs-In. */
343aa822
JBD
2263 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2264 && peer != bgp->peer_self)
43143c8f 2265 bgp_adj_in_set (rn, peer, attr, addpath_id);
718e3744 2266
2267 /* Check previously received route. */
2268 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
2269 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2270 ri->addpath_rx_id == addpath_id)
718e3744 2271 break;
2272
2273 /* AS path local-as loop check. */
2274 if (peer->change_local_as)
2275 {
2276 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2277 aspath_loop_count = 1;
2278
2279 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2280 {
2281 reason = "as-path contains our own AS;";
2282 goto filtered;
2283 }
2284 }
2285
2286 /* AS path loop check. */
2287 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2288 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2289 && aspath_loop_check(attr->aspath, bgp->confed_id)
2290 > peer->allowas_in[afi][safi]))
2291 {
2292 reason = "as-path contains our own AS;";
2293 goto filtered;
2294 }
2295
2296 /* Route reflector originator ID check. */
2297 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 2298 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
718e3744 2299 {
2300 reason = "originator is us;";
2301 goto filtered;
2302 }
2303
2304 /* Route reflector cluster ID check. */
2305 if (bgp_cluster_filter (peer, attr))
2306 {
2307 reason = "reflected from the same cluster;";
2308 goto filtered;
2309 }
2310
2311 /* Apply incoming filter. */
2312 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2313 {
2314 reason = "filter;";
2315 goto filtered;
2316 }
2317
558d1fec 2318 new_attr.extra = &new_extra;
fb982c25 2319 bgp_attr_dup (&new_attr, attr);
718e3744 2320
c460e572
DL
2321 /* Apply incoming route-map.
2322 * NB: new_attr may now contain newly allocated values from route-map "set"
2323 * commands, so we need bgp_attr_flush in the error paths, until we intern
2324 * the attr (which takes over the memory references) */
0b16f239 2325 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
718e3744 2326 {
2327 reason = "route-map;";
c460e572 2328 bgp_attr_flush (&new_attr);
718e3744 2329 goto filtered;
2330 }
2331
c265ee22 2332 /* next hop check. */
6aeb9e78 2333 if (bgp_update_martian_nexthop (bgp, afi, safi, &new_attr))
718e3744 2334 {
c265ee22
DS
2335 reason = "martian or self next-hop;";
2336 bgp_attr_flush (&new_attr);
2337 goto filtered;
718e3744 2338 }
2339
2340 attr_new = bgp_attr_intern (&new_attr);
2341
2342 /* If the update is implicit withdraw. */
2343 if (ri)
2344 {
65957886 2345 ri->uptime = bgp_clock ();
718e3744 2346
2347 /* Same attribute comes in. */
16d2e241
PJ
2348 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2349 && attrhash_cmp (ri->attr, attr_new))
718e3744 2350 {
718e3744 2351 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2352 && peer->sort == BGP_PEER_EBGP
718e3744 2353 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2354 {
3f9c7369 2355 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74 2356 {
2ec1e66f 2357 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74 2358 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2359 peer->host,
2360 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74
DS
2361 p->prefixlen, buf2);
2362 }
718e3744 2363
902212c3 2364 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2365 {
2366 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2367 bgp_process (bgp, rn, afi, safi);
2368 }
718e3744 2369 }
16d2e241 2370 else /* Duplicate - odd */
718e3744 2371 {
3f9c7369 2372 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2373 {
2374 if (!peer->rcvd_attr_printed)
2375 {
2376 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2377 peer->rcvd_attr_printed = 1;
2378 }
2379
2ec1e66f 2380 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74 2381 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
16286195
DS
2382 peer->host,
2383 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2384 p->prefixlen, buf2);
16286195 2385 }
93406d87 2386
2387 /* graceful restart STALE flag unset. */
2388 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2389 {
1a392d46 2390 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
902212c3 2391 bgp_process (bgp, rn, afi, safi);
93406d87 2392 }
718e3744 2393 }
2394
2395 bgp_unlock_node (rn);
f6f434b2 2396 bgp_attr_unintern (&attr_new);
558d1fec 2397
718e3744 2398 return 0;
2399 }
2400
16d2e241
PJ
2401 /* Withdraw/Announce before we fully processed the withdraw */
2402 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2403 {
3f9c7369 2404 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74 2405 {
2ec1e66f 2406 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74
DS
2407 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
2408 peer->host,
2409 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2410 p->prefixlen, buf2);
2411 }
16d2e241
PJ
2412 bgp_info_restore (rn, ri);
2413 }
2414
718e3744 2415 /* Received Logging. */
3f9c7369 2416 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74 2417 {
2ec1e66f 2418 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74 2419 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2420 peer->host,
2421 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74
DS
2422 p->prefixlen, buf2);
2423 }
718e3744 2424
93406d87 2425 /* graceful restart STALE flag unset. */
2426 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1a392d46 2427 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
93406d87 2428
718e3744 2429 /* The attribute is changed. */
1a392d46 2430 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
902212c3 2431
2432 /* implicit withdraw, decrement aggregate and pcount here.
2433 * only if update is accepted, they'll increment below.
2434 */
902212c3 2435 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2436
718e3744 2437 /* Update bgp route dampening information. */
2438 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2439 && peer->sort == BGP_PEER_EBGP)
718e3744 2440 {
2441 /* This is implicit withdraw so we should update dampening
2442 information. */
2443 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2444 bgp_damp_withdraw (ri, rn, afi, safi, 1);
718e3744 2445 }
2446
718e3744 2447 /* Update to new attribute. */
f6f434b2 2448 bgp_attr_unintern (&ri->attr);
718e3744 2449 ri->attr = attr_new;
2450
2451 /* Update MPLS tag. */
2452 if (safi == SAFI_MPLS_VPN)
fb982c25 2453 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
718e3744 2454
2455 /* Update bgp route dampening information. */
2456 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2457 && peer->sort == BGP_PEER_EBGP)
718e3744 2458 {
2459 /* Now we do normal update dampening. */
2460 ret = bgp_damp_update (ri, rn, afi, safi);
2461 if (ret == BGP_DAMP_SUPPRESSED)
2462 {
2463 bgp_unlock_node (rn);
2464 return 0;
2465 }
2466 }
2467
2468 /* Nexthop reachability check. */
fc9a856f 2469 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
718e3744 2470 {
fc9a856f 2471 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
907f92c8
DS
2472 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2473 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
fc9a856f
DS
2474 connected = 1;
2475 else
2476 connected = 0;
2477
75aead62 2478 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
1a392d46 2479 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 2480 else
fc9a856f
DS
2481 {
2482 if (BGP_DEBUG(nht, NHT))
2483 {
2484 char buf1[INET6_ADDRSTRLEN];
2485 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2486 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2487 }
2488 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2489 }
718e3744 2490 }
2491 else
fc9a856f 2492 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 2493
2494 /* Process change. */
2495 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2496
2497 bgp_process (bgp, rn, afi, safi);
2498 bgp_unlock_node (rn);
558d1fec 2499
718e3744 2500 return 0;
a82478b9 2501 } // End of implicit withdraw
718e3744 2502
2503 /* Received Logging. */
3f9c7369 2504 if (bgp_debug_update(peer, p, NULL, 1))
718e3744 2505 {
16286195
DS
2506 if (!peer->rcvd_attr_printed)
2507 {
2508 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2509 peer->rcvd_attr_printed = 1;
2510 }
2511
2ec1e66f 2512 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74 2513 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2514 peer->host,
2515 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2516 p->prefixlen, buf2);
718e3744 2517 }
2518
718e3744 2519 /* Make new BGP info. */
7c8ff89e 2520 new = info_make(type, sub_type, 0, peer, attr_new, rn);
718e3744 2521
2522 /* Update MPLS tag. */
2523 if (safi == SAFI_MPLS_VPN)
fb982c25 2524 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
718e3744 2525
2526 /* Nexthop reachability check. */
fc9a856f
DS
2527 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2528 {
2529 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
907f92c8
DS
2530 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2531 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
fc9a856f
DS
2532 connected = 1;
2533 else
2534 connected = 0;
2535
75aead62 2536 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
1a392d46 2537 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 2538 else
fc9a856f
DS
2539 {
2540 if (BGP_DEBUG(nht, NHT))
2541 {
2542 char buf1[INET6_ADDRSTRLEN];
2543 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2544 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2545 }
2546 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2547 }
718e3744 2548 }
2549 else
1a392d46 2550 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 2551
a82478b9
DS
2552 /* Addpath ID */
2553 new->addpath_rx_id = addpath_id;
a82478b9 2554
902212c3 2555 /* Increment prefix */
718e3744 2556 bgp_aggregate_increment (bgp, p, new, afi, safi);
2557
2558 /* Register new BGP information. */
2559 bgp_info_add (rn, new);
200df115 2560
2561 /* route_node_get lock */
2562 bgp_unlock_node (rn);
558d1fec 2563
718e3744 2564 /* If maximum prefix count is configured and current prefix
2565 count exeed it. */
e0701b79 2566 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2567 return -1;
718e3744 2568
2569 /* Process change. */
2570 bgp_process (bgp, rn, afi, safi);
2571
2572 return 0;
2573
2574 /* This BGP update is filtered. Log the reason then update BGP
2575 entry. */
2576 filtered:
3f9c7369 2577 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2578 {
2579 if (!peer->rcvd_attr_printed)
2580 {
2581 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2582 peer->rcvd_attr_printed = 1;
2583 }
2584
2ec1e66f 2585 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74 2586 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
16286195
DS
2587 peer->host,
2588 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2589 p->prefixlen, buf2, reason);
16286195 2590 }
718e3744 2591
2592 if (ri)
b40d939b 2593 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 2594
2595 bgp_unlock_node (rn);
558d1fec 2596
718e3744 2597 return 0;
2598}
2599
2600int
a82478b9
DS
2601bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2602 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2603 struct prefix_rd *prd, u_char *tag)
718e3744 2604{
2605 struct bgp *bgp;
2606 char buf[SU_ADDRSTRLEN];
cd808e74 2607 char buf2[30];
718e3744 2608 struct bgp_node *rn;
2609 struct bgp_info *ri;
2610
2611 bgp = peer->bgp;
2612
718e3744 2613 /* Lookup node. */
fee0f4c6 2614 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 2615
2616 /* If peer is soft reconfiguration enabled. Record input packet for
6b87f736
DL
2617 * further calculation.
2618 *
2619 * Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2620 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2621 * the iteration over all RS clients.
2622 * Since we need to remove the entry from adj_in anyway, do that first and
2623 * if there was no entry, we don't need to do anything more.
2624 */
718e3744 2625 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2626 && peer != bgp->peer_self)
6b87f736
DL
2627 if (!bgp_adj_in_unset (rn, peer, addpath_id))
2628 {
2629 if (bgp_debug_update (peer, p, NULL, 1))
2630 zlog_debug ("%s withdrawing route %s/%d "
2631 "not in adj-in", peer->host,
2632 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2633 p->prefixlen);
2634 bgp_unlock_node (rn);
2635 return 0;
2636 }
718e3744 2637
2638 /* Lookup withdrawn route. */
2639 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
2640 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2641 ri->addpath_rx_id == addpath_id)
718e3744 2642 break;
2643
cd808e74
DS
2644 /* Logging. */
2645 if (bgp_debug_update(peer, p, NULL, 1))
2646 {
2ec1e66f 2647 bgp_info_addpath_rx_str(addpath_id, buf2);
cd808e74
DS
2648 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
2649 peer->host,
2650 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2651 p->prefixlen, buf2);
2652 }
2653
718e3744 2654 /* Withdraw specified route from routing table. */
2655 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
b40d939b 2656 bgp_rib_withdraw (rn, ri, peer, afi, safi);
3f9c7369 2657 else if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2658 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2659 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2660 p->prefixlen);
718e3744 2661
2662 /* Unlock bgp_node_get() lock. */
2663 bgp_unlock_node (rn);
2664
2665 return 0;
2666}
6b0655a2 2667
718e3744 2668void
2669bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2670{
3f9c7369
DS
2671 struct update_subgroup *subgrp;
2672 subgrp = peer_subgroup(peer, afi, safi);
2673 subgroup_default_originate(subgrp, withdraw);
2674}
6182d65b 2675
718e3744 2676
3f9c7369
DS
2677/*
2678 * bgp_stop_announce_route_timer
2679 */
2680void
2681bgp_stop_announce_route_timer (struct peer_af *paf)
2682{
2683 if (!paf->t_announce_route)
2684 return;
718e3744 2685
3f9c7369 2686 THREAD_TIMER_OFF (paf->t_announce_route);
718e3744 2687}
6b0655a2 2688
3f9c7369
DS
2689/*
2690 * bgp_announce_route_timer_expired
2691 *
2692 * Callback that is invoked when the route announcement timer for a
2693 * peer_af expires.
2694 */
2695static int
2696bgp_announce_route_timer_expired (struct thread *t)
718e3744 2697{
3f9c7369
DS
2698 struct peer_af *paf;
2699 struct peer *peer;
558d1fec 2700
3f9c7369
DS
2701 paf = THREAD_ARG (t);
2702 peer = paf->peer;
718e3744 2703
3f9c7369
DS
2704 assert (paf->t_announce_route);
2705 paf->t_announce_route = NULL;
558d1fec 2706
3f9c7369
DS
2707 if (peer->status != Established)
2708 return 0;
2709
2710 if (!peer->afc_nego[paf->afi][paf->safi])
2711 return 0;
2712
2713 peer_af_announce_route (paf, 1);
2714 return 0;
718e3744 2715}
2716
3f9c7369
DS
2717/*
2718 * bgp_announce_route
2719 *
2720 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
2721 */
718e3744 2722void
2723bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2724{
3f9c7369
DS
2725 struct peer_af *paf;
2726 struct update_subgroup *subgrp;
718e3744 2727
3f9c7369
DS
2728 paf = peer_af_find (peer, afi, safi);
2729 if (!paf)
718e3744 2730 return;
3f9c7369 2731 subgrp = PAF_SUBGRP(paf);
718e3744 2732
3f9c7369
DS
2733 /*
2734 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
2735 * or a refresh has already been triggered.
2736 */
2737 if (!subgrp || paf->t_announce_route)
718e3744 2738 return;
2739
d889623f 2740 /*
3f9c7369
DS
2741 * Start a timer to stagger/delay the announce. This serves
2742 * two purposes - announcement can potentially be combined for
2743 * multiple peers and the announcement doesn't happen in the
2744 * vty context.
d889623f 2745 */
9229d914 2746 THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route,
3f9c7369
DS
2747 bgp_announce_route_timer_expired, paf,
2748 (subgrp->peer_count == 1) ?
2749 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
2750 BGP_ANNOUNCE_ROUTE_DELAY_MS);
2751}
2752
2753/*
2754 * Announce routes from all AF tables to a peer.
2755 *
2756 * This should ONLY be called when there is a need to refresh the
2757 * routes to the peer based on a policy change for this peer alone
2758 * or a route refresh request received from the peer.
2759 * The operation will result in splitting the peer from its existing
2760 * subgroups and putting it in new subgroups.
2761 */
718e3744 2762void
2763bgp_announce_route_all (struct peer *peer)
2764{
2765 afi_t afi;
2766 safi_t safi;
2767
2768 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2769 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2770 bgp_announce_route (peer, afi, safi);
2771}
6b0655a2 2772
fee0f4c6 2773static void
718e3744 2774bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
8692c506 2775 struct bgp_table *table, struct prefix_rd *prd)
718e3744 2776{
2777 int ret;
2778 struct bgp_node *rn;
2779 struct bgp_adj_in *ain;
2780
2781 if (! table)
2782 table = peer->bgp->rib[afi][safi];
2783
2784 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2785 for (ain = rn->adj_in; ain; ain = ain->next)
2786 {
2787 if (ain->peer == peer)
2788 {
8692c506 2789 struct bgp_info *ri = rn->info;
d53d8fda 2790 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 2791
43143c8f 2792 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
a82478b9 2793 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
d53d8fda 2794 prd, tag, 1);
8692c506 2795
718e3744 2796 if (ret < 0)
2797 {
2798 bgp_unlock_node (rn);
2799 return;
2800 }
718e3744 2801 }
2802 }
2803}
2804
2805void
2806bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2807{
2808 struct bgp_node *rn;
2809 struct bgp_table *table;
2810
2811 if (peer->status != Established)
2812 return;
2813
587ff0fd 2814 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
8692c506 2815 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
718e3744 2816 else
2817 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2818 rn = bgp_route_next (rn))
2819 if ((table = rn->info) != NULL)
8692c506
JBD
2820 {
2821 struct prefix_rd prd;
2822 prd.family = AF_UNSPEC;
2823 prd.prefixlen = 64;
2824 memcpy(&prd.val, rn->p.u.val, 8);
2825
2826 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2827 }
718e3744 2828}
6b0655a2 2829
228da428
CC
2830
2831struct bgp_clear_node_queue
2832{
2833 struct bgp_node *rn;
228da428
CC
2834};
2835
200df115 2836static wq_item_status
0fb58d5d 2837bgp_clear_route_node (struct work_queue *wq, void *data)
200df115 2838{
228da428
CC
2839 struct bgp_clear_node_queue *cnq = data;
2840 struct bgp_node *rn = cnq->rn;
64e580a7 2841 struct peer *peer = wq->spec.data;
718e3744 2842 struct bgp_info *ri;
67174041
AS
2843 afi_t afi = bgp_node_table (rn)->afi;
2844 safi_t safi = bgp_node_table (rn)->safi;
200df115 2845
64e580a7 2846 assert (rn && peer);
200df115 2847
43143c8f
DS
2848 /* It is possible that we have multiple paths for a prefix from a peer
2849 * if that peer is using AddPath.
2850 */
64e580a7 2851 for (ri = rn->info; ri; ri = ri->next)
2a3d5731 2852 if (ri->peer == peer)
200df115 2853 {
2854 /* graceful restart STALE flag set. */
64e580a7
PJ
2855 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2856 && peer->nsf[afi][safi]
200df115 2857 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
1a392d46
PJ
2858 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2859 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
200df115 2860 else
64e580a7 2861 bgp_rib_remove (rn, ri, peer, afi, safi);
200df115 2862 }
200df115 2863 return WQ_SUCCESS;
2864}
2865
2866static void
0fb58d5d 2867bgp_clear_node_queue_del (struct work_queue *wq, void *data)
200df115 2868{
228da428
CC
2869 struct bgp_clear_node_queue *cnq = data;
2870 struct bgp_node *rn = cnq->rn;
67174041 2871 struct bgp_table *table = bgp_node_table (rn);
64e580a7
PJ
2872
2873 bgp_unlock_node (rn);
228da428
CC
2874 bgp_table_unlock (table);
2875 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
200df115 2876}
2877
2878static void
94f2b392 2879bgp_clear_node_complete (struct work_queue *wq)
200df115 2880{
64e580a7
PJ
2881 struct peer *peer = wq->spec.data;
2882
3e0c78ef 2883 /* Tickle FSM to start moving again */
ca058a30 2884 BGP_EVENT_ADD (peer, Clearing_Completed);
228da428
CC
2885
2886 peer_unlock (peer); /* bgp_clear_route */
200df115 2887}
2888
2889static void
64e580a7 2890bgp_clear_node_queue_init (struct peer *peer)
200df115 2891{
a2943657 2892 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
64e580a7 2893
a2943657 2894 snprintf (wname, sizeof(wname), "clear %s", peer->host);
64e580a7
PJ
2895#undef CLEAR_QUEUE_NAME_LEN
2896
87d4a781 2897 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
200df115 2898 {
2899 zlog_err ("%s: Failed to allocate work queue", __func__);
2900 exit (1);
2901 }
64e580a7
PJ
2902 peer->clear_node_queue->spec.hold = 10;
2903 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2904 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2905 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2906 peer->clear_node_queue->spec.max_retries = 0;
2907
2908 /* we only 'lock' this peer reference when the queue is actually active */
2909 peer->clear_node_queue->spec.data = peer;
200df115 2910}
718e3744 2911
200df115 2912static void
2913bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
2a3d5731 2914 struct bgp_table *table)
200df115 2915{
200df115 2916 struct bgp_node *rn;
2917
f2c31acb 2918
718e3744 2919 if (! table)
2a3d5731 2920 table = peer->bgp->rib[afi][safi];
64e580a7 2921
6cf159b9 2922 /* If still no table => afi/safi isn't configured at all or smth. */
2923 if (! table)
2924 return;
65ca75e0
PJ
2925
2926 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2927 {
f2c31acb
PJ
2928 struct bgp_info *ri;
2929 struct bgp_adj_in *ain;
43143c8f 2930 struct bgp_adj_in *ain_next;
f2c31acb
PJ
2931
2932 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2933 * queued for every clearing peer, regardless of whether it is
2934 * relevant to the peer at hand.
2935 *
2936 * Overview: There are 3 different indices which need to be
2937 * scrubbed, potentially, when a peer is removed:
2938 *
2939 * 1 peer's routes visible via the RIB (ie accepted routes)
2940 * 2 peer's routes visible by the (optional) peer's adj-in index
2941 * 3 other routes visible by the peer's adj-out index
2942 *
2943 * 3 there is no hurry in scrubbing, once the struct peer is
2944 * removed from bgp->peer, we could just GC such deleted peer's
2945 * adj-outs at our leisure.
2946 *
2947 * 1 and 2 must be 'scrubbed' in some way, at least made
2948 * invisible via RIB index before peer session is allowed to be
2949 * brought back up. So one needs to know when such a 'search' is
2950 * complete.
2951 *
2952 * Ideally:
2953 *
2954 * - there'd be a single global queue or a single RIB walker
2955 * - rather than tracking which route_nodes still need to be
2956 * examined on a peer basis, we'd track which peers still
2957 * aren't cleared
2958 *
2959 * Given that our per-peer prefix-counts now should be reliable,
2960 * this may actually be achievable. It doesn't seem to be a huge
2961 * problem at this time,
43143c8f
DS
2962 *
2963 * It is possible that we have multiple paths for a prefix from a peer
2964 * if that peer is using AddPath.
f2c31acb 2965 */
43143c8f
DS
2966 ain = rn->adj_in;
2967 while (ain)
2968 {
2969 ain_next = ain->next;
2970
2a3d5731 2971 if (ain->peer == peer)
43143c8f
DS
2972 {
2973 bgp_adj_in_remove (rn, ain);
2974 bgp_unlock_node (rn);
2975 }
2976
2977 ain = ain_next;
2978 }
3f9c7369 2979
f2c31acb 2980 for (ri = rn->info; ri; ri = ri->next)
2a3d5731 2981 if (ri->peer == peer)
f2c31acb 2982 {
228da428
CC
2983 struct bgp_clear_node_queue *cnq;
2984
2985 /* both unlocked in bgp_clear_node_queue_del */
67174041 2986 bgp_table_lock (bgp_node_table (rn));
228da428
CC
2987 bgp_lock_node (rn);
2988 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2989 sizeof (struct bgp_clear_node_queue));
2990 cnq->rn = rn;
228da428
CC
2991 work_queue_add (peer->clear_node_queue, cnq);
2992 break;
f2c31acb 2993 }
65ca75e0
PJ
2994 }
2995 return;
2996}
2997
2998void
2a3d5731 2999bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
65ca75e0
PJ
3000{
3001 struct bgp_node *rn;
3002 struct bgp_table *table;
6cf159b9 3003
64e580a7
PJ
3004 if (peer->clear_node_queue == NULL)
3005 bgp_clear_node_queue_init (peer);
200df115 3006
ca058a30
PJ
3007 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3008 * Idle until it receives a Clearing_Completed event. This protects
3009 * against peers which flap faster than we can we clear, which could
3010 * lead to:
64e580a7
PJ
3011 *
3012 * a) race with routes from the new session being installed before
3013 * clear_route_node visits the node (to delete the route of that
3014 * peer)
3015 * b) resource exhaustion, clear_route_node likely leads to an entry
3016 * on the process_main queue. Fast-flapping could cause that queue
3017 * to grow and grow.
200df115 3018 */
dc83d712
DS
3019
3020 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3021 * the unlock will happen upon work-queue completion; other wise, the
3022 * unlock happens at the end of this function.
3023 */
ca058a30 3024 if (!peer->clear_node_queue->thread)
dc83d712 3025 peer_lock (peer);
fee0f4c6 3026
587ff0fd 3027 if (safi != SAFI_MPLS_VPN && safi != SAFI_ENCAP)
2a3d5731
DW
3028 bgp_clear_route_table (peer, afi, safi, NULL);
3029 else
3030 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3031 rn = bgp_route_next (rn))
3032 if ((table = rn->info) != NULL)
3033 bgp_clear_route_table (peer, afi, safi, table);
dc83d712
DS
3034
3035 /* unlock if no nodes got added to the clear-node-queue. */
65ca75e0 3036 if (!peer->clear_node_queue->thread)
dc83d712
DS
3037 peer_unlock (peer);
3038
718e3744 3039}
3040
3041void
3042bgp_clear_route_all (struct peer *peer)
3043{
3044 afi_t afi;
3045 safi_t safi;
3046
3047 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3048 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2a3d5731 3049 bgp_clear_route (peer, afi, safi);
718e3744 3050}
3051
3052void
3053bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3054{
3055 struct bgp_table *table;
3056 struct bgp_node *rn;
3057 struct bgp_adj_in *ain;
43143c8f 3058 struct bgp_adj_in *ain_next;
718e3744 3059
3060 table = peer->bgp->rib[afi][safi];
3061
43143c8f
DS
3062 /* It is possible that we have multiple paths for a prefix from a peer
3063 * if that peer is using AddPath.
3064 */
718e3744 3065 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
43143c8f
DS
3066 {
3067 ain = rn->adj_in;
3068
3069 while (ain)
3070 {
3071 ain_next = ain->next;
3072
3073 if (ain->peer == peer)
3074 {
3075 bgp_adj_in_remove (rn, ain);
3076 bgp_unlock_node (rn);
3077 }
3078
3079 ain = ain_next;
3080 }
3081 }
718e3744 3082}
93406d87 3083
3084void
3085bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3086{
3087 struct bgp_node *rn;
3088 struct bgp_info *ri;
3089 struct bgp_table *table;
3090
3091 table = peer->bgp->rib[afi][safi];
3092
3093 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3094 {
3095 for (ri = rn->info; ri; ri = ri->next)
3096 if (ri->peer == peer)
3097 {
3098 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3099 bgp_rib_remove (rn, ri, peer, afi, safi);
3100 break;
3101 }
3102 }
3103}
6b0655a2 3104
bb86c601
LB
3105static void
3106bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3107{
3108 struct bgp_node *rn;
3109 struct bgp_info *ri;
3110 struct bgp_info *next;
3111
3112 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3113 for (ri = rn->info; ri; ri = next)
3114 {
3115 next = ri->next;
3116 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3117 && ri->type == ZEBRA_ROUTE_BGP
3118 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3119 ri->sub_type == BGP_ROUTE_AGGREGATE))
3120 bgp_zebra_withdraw (&rn->p, ri, safi);
3121 }
3122}
3123
718e3744 3124/* Delete all kernel routes. */
3125void
66e5cd87 3126bgp_cleanup_routes (void)
718e3744 3127{
3128 struct bgp *bgp;
1eb8ef25 3129 struct listnode *node, *nnode;
bb86c601 3130 afi_t afi;
718e3744 3131
1eb8ef25 3132 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 3133 {
bb86c601
LB
3134 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3135 {
3136 struct bgp_node *rn;
3137
3138 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
3139
3140 /*
3141 * VPN and ENCAP tables are two-level (RD is top level)
3142 */
3143 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3144 rn = bgp_route_next (rn))
587ff0fd
LB
3145 {
3146 if (rn->info)
bb86c601 3147 {
587ff0fd
LB
3148 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3149 bgp_table_finish ((struct bgp_table **)&(rn->info));
3150 rn->info = NULL;
3151 bgp_unlock_node(rn);
bb86c601 3152 }
587ff0fd
LB
3153 }
3154
3155 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3156 rn = bgp_route_next (rn))
3157 {
3158 if (rn->info)
3159 {
3160 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3161 bgp_table_finish ((struct bgp_table **)&(rn->info));
3162 rn->info = NULL;
3163 bgp_unlock_node(rn);
3164 }
3165 }
bb86c601 3166 }
718e3744 3167 }
3168}
3169
3170void
66e5cd87 3171bgp_reset (void)
718e3744 3172{
3173 vty_reset ();
3174 bgp_zclient_reset ();
3175 access_list_reset ();
3176 prefix_list_reset ();
3177}
6b0655a2 3178
adbac85e
DW
3179static int
3180bgp_addpath_encode_rx (struct peer *peer, afi_t afi, safi_t safi)
3181{
3182 return (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3183 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3184}
3185
718e3744 3186/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3187 value. */
3188int
3189bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3190{
3191 u_char *pnt;
3192 u_char *lim;
3193 struct prefix p;
3194 int psize;
3195 int ret;
a82478b9
DS
3196 afi_t afi;
3197 safi_t safi;
adbac85e 3198 int addpath_encoded;
a82478b9 3199 u_int32_t addpath_id;
718e3744 3200
3201 /* Check peer status. */
3202 if (peer->status != Established)
3203 return 0;
3204
3205 pnt = packet->nlri;
3206 lim = pnt + packet->length;
a82478b9
DS
3207 afi = packet->afi;
3208 safi = packet->safi;
3209 addpath_id = 0;
adbac85e 3210 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
718e3744 3211
3212 for (; pnt < lim; pnt += psize)
3213 {
3214 /* Clear prefix structure. */
3215 memset (&p, 0, sizeof (struct prefix));
3216
a82478b9
DS
3217 if (addpath_encoded)
3218 {
cd808e74
DS
3219
3220 /* When packet overflow occurs return immediately. */
3221 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3222 return -1;
3223
a82478b9
DS
3224 addpath_id = ntohl(*((uint32_t*) pnt));
3225 pnt += BGP_ADDPATH_ID_LEN;
3226 }
3227
718e3744 3228 /* Fetch prefix length. */
3229 p.prefixlen = *pnt++;
a82478b9 3230 p.family = afi2family (afi);
718e3744 3231
3232 /* Already checked in nlri_sanity_check(). We do double check
3233 here. */
a82478b9
DS
3234 if ((afi == AFI_IP && p.prefixlen > 32)
3235 || (afi == AFI_IP6 && p.prefixlen > 128))
718e3744 3236 return -1;
3237
3238 /* Packet size overflow check. */
3239 psize = PSIZE (p.prefixlen);
3240
3241 /* When packet overflow occur return immediately. */
3242 if (pnt + psize > lim)
3243 return -1;
3244
3245 /* Fetch prefix from NLRI packet. */
3246 memcpy (&p.u.prefix, pnt, psize);
3247
3248 /* Check address. */
a82478b9 3249 if (afi == AFI_IP && safi == SAFI_UNICAST)
718e3744 3250 {
3251 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3252 {
f5ba3874 3253 /*
3254 * From draft-ietf-idr-bgp4-22, Section 6.3:
3255 * If a BGP router receives an UPDATE message with a
3256 * semantically incorrect NLRI field, in which a prefix is
3257 * semantically incorrect (eg. an unexpected multicast IP
3258 * address), it should ignore the prefix.
3259 */
16286195
DS
3260 zlog_err ("IPv4 unicast NLRI is multicast address %s",
3261 inet_ntoa (p.u.prefix4));
f5ba3874 3262
718e3744 3263 return -1;
3264 }
3265 }
3266
3267#ifdef HAVE_IPV6
3268 /* Check address. */
a82478b9 3269 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
718e3744 3270 {
3271 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3272 {
3273 char buf[BUFSIZ];
3274
16286195
DS
3275 zlog_warn ("IPv6 link-local NLRI received %s ignore this NLRI",
3276 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
718e3744 3277
3278 continue;
3279 }
3280 }
3281#endif /* HAVE_IPV6 */
3282
3283 /* Normal process. */
3284 if (attr)
a82478b9 3285 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
718e3744 3286 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3287 else
a82478b9 3288 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
718e3744 3289 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3290
3291 /* Address family configuration mismatch or maximum-prefix count
3292 overflow. */
3293 if (ret < 0)
3294 return -1;
3295 }
3296
3297 /* Packet length consistency check. */
3298 if (pnt != lim)
3299 return -1;
3300
3301 return 0;
3302}
3303
3304/* NLRI encode syntax check routine. */
3305int
a82478b9 3306bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi, u_char *pnt,
d889623f 3307 bgp_size_t length, int *numpfx)
718e3744 3308{
3309 u_char *end;
3310 u_char prefixlen;
3311 int psize;
adbac85e 3312 int addpath_encoded;
718e3744 3313
d889623f 3314 *numpfx = 0;
718e3744 3315 end = pnt + length;
adbac85e 3316 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
a82478b9 3317
718e3744 3318 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3319 syntactic validity. If the field is syntactically incorrect,
3320 then the Error Subcode is set to Invalid Network Field. */
3321
3322 while (pnt < end)
3323 {
587ff0fd 3324 int badlength;
cd808e74 3325
a82478b9
DS
3326 /* If the NLRI is encoded using addpath then the first 4 bytes are
3327 * the addpath ID. */
3328 if (addpath_encoded)
cd808e74
DS
3329 {
3330 if (pnt + BGP_ADDPATH_ID_LEN > end)
3331 {
3332 zlog_err ("%s [Error] Update packet error"
3333 " (prefix data addpath overflow)",
3334 peer->host);
3335 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3336 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3337 return -1;
3338 }
3339 pnt += BGP_ADDPATH_ID_LEN;
3340 }
a82478b9 3341
718e3744 3342 prefixlen = *pnt++;
3343
3344 /* Prefix length check. */
587ff0fd
LB
3345 badlength = 0;
3346 if (safi == SAFI_ENCAP) {
3347 if (prefixlen > 128)
3348 badlength = 1;
3349 } else {
3350 if ((afi == AFI_IP && prefixlen > 32) ||
3351 (afi == AFI_IP6 && prefixlen > 128)) {
3352
3353 badlength = 1;
3354 }
3355 }
3356 if (badlength)
718e3744 3357 {
16286195 3358 zlog_err ("%s [Error] Update packet error (wrong prefix length %d)",
718e3744 3359 peer->host, prefixlen);
3360 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3361 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3362 return -1;
3363 }
3364
3365 /* Packet size overflow check. */
3366 psize = PSIZE (prefixlen);
3367
3368 if (pnt + psize > end)
3369 {
16286195 3370 zlog_err ("%s [Error] Update packet error"
718e3744 3371 " (prefix data overflow prefix size is %d)",
3372 peer->host, psize);
3373 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3374 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3375 return -1;
3376 }
3377
3378 pnt += psize;
d889623f 3379 (*numpfx)++;
718e3744 3380 }
3381
3382 /* Packet length consistency check. */
3383 if (pnt != end)
3384 {
16286195 3385 zlog_err ("%s [Error] Update packet error"
718e3744 3386 " (prefix length mismatch with total length)",
3387 peer->host);
3388 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3389 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3390 return -1;
3391 }
3392 return 0;
3393}
6b0655a2 3394
94f2b392 3395static struct bgp_static *
66e5cd87 3396bgp_static_new (void)
718e3744 3397{
393deb9b 3398 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
718e3744 3399}
3400
94f2b392 3401static void
718e3744 3402bgp_static_free (struct bgp_static *bgp_static)
3403{
3404 if (bgp_static->rmap.name)
6e919709 3405 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
718e3744 3406 XFREE (MTYPE_BGP_STATIC, bgp_static);
3407}
3408
94f2b392 3409static void
2a3d5731
DW
3410bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3411 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
fee0f4c6 3412{
3413 struct bgp_node *rn;
3414 struct bgp_info *ri;
2a3d5731
DW
3415 struct bgp_info *new;
3416 struct bgp_info info;
3417 struct attr attr;
3418 struct attr *attr_new;
3419 int ret;
fee0f4c6 3420
2a3d5731
DW
3421 assert (bgp_static);
3422 if (!bgp_static)
3423 return;
dd8103a9 3424
fee0f4c6 3425 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 3426
3427 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
dd8103a9
PJ
3428
3429 attr.nexthop = bgp_static->igpnexthop;
3430 attr.med = bgp_static->igpmetric;
3431 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
718e3744 3432
41367172
PJ
3433 if (bgp_static->atomic)
3434 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3435
718e3744 3436 /* Apply route-map. */
3437 if (bgp_static->rmap.name)
3438 {
fb982c25 3439 struct attr attr_tmp = attr;
718e3744 3440 info.peer = bgp->peer_self;
286e1e71 3441 info.attr = &attr_tmp;
718e3744 3442
fee0f4c6 3443 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3444
718e3744 3445 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
286e1e71 3446
fee0f4c6 3447 bgp->peer_self->rmap_type = 0;
3448
718e3744 3449 if (ret == RMAP_DENYMATCH)
3450 {
3451 /* Free uninterned attribute. */
286e1e71 3452 bgp_attr_flush (&attr_tmp);
718e3744 3453
3454 /* Unintern original. */
f6f434b2 3455 aspath_unintern (&attr.aspath);
fb982c25 3456 bgp_attr_extra_free (&attr);
718e3744 3457 bgp_static_withdraw (bgp, p, afi, safi);
3458 return;
3459 }
286e1e71 3460 attr_new = bgp_attr_intern (&attr_tmp);
718e3744 3461 }
286e1e71 3462 else
3463 attr_new = bgp_attr_intern (&attr);
718e3744 3464
3465 for (ri = rn->info; ri; ri = ri->next)
3466 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3467 && ri->sub_type == BGP_ROUTE_STATIC)
3468 break;
3469
3470 if (ri)
3471 {
8d45210e 3472 if (attrhash_cmp (ri->attr, attr_new) &&
078430f6
DS
3473 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
3474 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
718e3744 3475 {
3476 bgp_unlock_node (rn);
f6f434b2
PJ
3477 bgp_attr_unintern (&attr_new);
3478 aspath_unintern (&attr.aspath);
fb982c25 3479 bgp_attr_extra_free (&attr);
718e3744 3480 return;
3481 }
3482 else
3483 {
3484 /* The attribute is changed. */
1a392d46 3485 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 3486
3487 /* Rewrite BGP route information. */
8d45210e
AS
3488 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3489 bgp_info_restore(rn, ri);
3490 else
3491 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
f6f434b2 3492 bgp_attr_unintern (&ri->attr);
718e3744 3493 ri->attr = attr_new;
65957886 3494 ri->uptime = bgp_clock ();
718e3744 3495
fc9a856f
DS
3496 /* Nexthop reachability check. */
3497 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3498 {
75aead62 3499 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
fc9a856f
DS
3500 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3501 else
3502 {
3503 if (BGP_DEBUG(nht, NHT))
3504 {
3505 char buf1[INET6_ADDRSTRLEN];
078430f6
DS
3506 inet_ntop(p->family, &p->u.prefix, buf1,
3507 INET6_ADDRSTRLEN);
3508 zlog_debug("%s(%s): Route not in table, not advertising",
3509 __FUNCTION__, buf1);
fc9a856f
DS
3510 }
3511 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3512 }
3513 }
078430f6
DS
3514 else
3515 {
3516 /* Delete the NHT structure if any, if we're toggling between
3517 * enabling/disabling import check. We deregister the route
3518 * from NHT to avoid overloading NHT and the process interaction
3519 */
3520 bgp_unlink_nexthop(ri);
3521 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3522 }
718e3744 3523 /* Process change. */
3524 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3525 bgp_process (bgp, rn, afi, safi);
3526 bgp_unlock_node (rn);
f6f434b2 3527 aspath_unintern (&attr.aspath);
fb982c25 3528 bgp_attr_extra_free (&attr);
718e3744 3529 return;
3530 }
3531 }
3532
3533 /* Make new BGP info. */
7c8ff89e 3534 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
fb018d25 3535 rn);
fc9a856f
DS
3536 /* Nexthop reachability check. */
3537 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3538 {
75aead62 3539 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
fc9a856f
DS
3540 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3541 else
3542 {
3543 if (BGP_DEBUG(nht, NHT))
3544 {
3545 char buf1[INET6_ADDRSTRLEN];
078430f6 3546 inet_ntop(p->family, &p->u.prefix, buf1,
fc9a856f 3547 INET6_ADDRSTRLEN);
078430f6
DS
3548 zlog_debug("%s(%s): Route not in table, not advertising",
3549 __FUNCTION__, buf1);
fc9a856f
DS
3550 }
3551 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3552 }
3553 }
3554 else
078430f6
DS
3555 {
3556 /* Delete the NHT structure if any, if we're toggling between
3557 * enabling/disabling import check. We deregister the route
3558 * from NHT to avoid overloading NHT and the process interaction
3559 */
3560 bgp_unlink_nexthop(new);
3561
3562 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3563 }
718e3744 3564
3565 /* Aggregate address increment. */
3566 bgp_aggregate_increment (bgp, p, new, afi, safi);
3567
3568 /* Register new BGP information. */
3569 bgp_info_add (rn, new);
200df115 3570
3571 /* route_node_get lock */
3572 bgp_unlock_node (rn);
3573
718e3744 3574 /* Process change. */
3575 bgp_process (bgp, rn, afi, safi);
3576
3577 /* Unintern original. */
f6f434b2 3578 aspath_unintern (&attr.aspath);
fb982c25 3579 bgp_attr_extra_free (&attr);
718e3744 3580}
3581
fee0f4c6 3582void
3583bgp_static_update (struct bgp *bgp, struct prefix *p,
3584 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3585{
fee0f4c6 3586 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
fee0f4c6 3587}
3588
718e3744 3589void
3590bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3591 safi_t safi)
3592{
3593 struct bgp_node *rn;
3594 struct bgp_info *ri;
3595
fee0f4c6 3596 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 3597
3598 /* Check selected route and self inserted route. */
3599 for (ri = rn->info; ri; ri = ri->next)
3600 if (ri->peer == bgp->peer_self
3601 && ri->type == ZEBRA_ROUTE_BGP
3602 && ri->sub_type == BGP_ROUTE_STATIC)
3603 break;
3604
3605 /* Withdraw static BGP route from routing table. */
3606 if (ri)
3607 {
3608 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
fc9a856f 3609 bgp_unlink_nexthop(ri);
718e3744 3610 bgp_info_delete (rn, ri);
1a392d46 3611 bgp_process (bgp, rn, afi, safi);
718e3744 3612 }
3613
3614 /* Unlock bgp_node_lookup. */
3615 bgp_unlock_node (rn);
3616}
3617
137446f9
LB
3618/*
3619 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3620 */
94f2b392 3621static void
137446f9
LB
3622bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3623 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 3624{
3625 struct bgp_node *rn;
3626 struct bgp_info *ri;
3627
fee0f4c6 3628 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 3629
3630 /* Check selected route and self inserted route. */
3631 for (ri = rn->info; ri; ri = ri->next)
3632 if (ri->peer == bgp->peer_self
3633 && ri->type == ZEBRA_ROUTE_BGP
3634 && ri->sub_type == BGP_ROUTE_STATIC)
3635 break;
3636
3637 /* Withdraw static BGP route from routing table. */
3638 if (ri)
3639 {
3640 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
718e3744 3641 bgp_info_delete (rn, ri);
1a392d46 3642 bgp_process (bgp, rn, afi, safi);
718e3744 3643 }
3644
3645 /* Unlock bgp_node_lookup. */
3646 bgp_unlock_node (rn);
3647}
3648
137446f9
LB
3649static void
3650bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3651 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3652{
3653 struct bgp_node *rn;
3654 struct bgp_info *new;
3655 struct attr *attr_new;
3656 struct attr attr = { 0 };
3657 struct bgp_info *ri;
3658
3659 assert (bgp_static);
3660
3661 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3662
3663 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3664
3665 attr.nexthop = bgp_static->igpnexthop;
3666 attr.med = bgp_static->igpmetric;
3667 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3668
3669 /* Apply route-map. */
3670 if (bgp_static->rmap.name)
3671 {
3672 struct attr attr_tmp = attr;
3673 struct bgp_info info;
3674 int ret;
3675
3676 info.peer = bgp->peer_self;
3677 info.attr = &attr_tmp;
3678
3679 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3680
3681 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3682
3683 bgp->peer_self->rmap_type = 0;
3684
3685 if (ret == RMAP_DENYMATCH)
3686 {
3687 /* Free uninterned attribute. */
3688 bgp_attr_flush (&attr_tmp);
3689
3690 /* Unintern original. */
3691 aspath_unintern (&attr.aspath);
3692 bgp_attr_extra_free (&attr);
3693 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3694 bgp_static->tag);
3695 return;
3696 }
3697
3698 attr_new = bgp_attr_intern (&attr_tmp);
3699 }
3700 else
3701 {
3702 attr_new = bgp_attr_intern (&attr);
3703 }
3704
3705 for (ri = rn->info; ri; ri = ri->next)
3706 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3707 && ri->sub_type == BGP_ROUTE_STATIC)
3708 break;
3709
3710 if (ri)
3711 {
3712 if (attrhash_cmp (ri->attr, attr_new) &&
3713 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3714 {
3715 bgp_unlock_node (rn);
3716 bgp_attr_unintern (&attr_new);
3717 aspath_unintern (&attr.aspath);
3718 bgp_attr_extra_free (&attr);
3719 return;
3720 }
3721 else
3722 {
3723 /* The attribute is changed. */
3724 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3725
3726 /* Rewrite BGP route information. */
3727 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3728 bgp_info_restore(rn, ri);
3729 else
3730 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3731 bgp_attr_unintern (&ri->attr);
3732 ri->attr = attr_new;
3733 ri->uptime = bgp_clock ();
3734
3735 /* Process change. */
3736 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3737 bgp_process (bgp, rn, afi, safi);
3738 bgp_unlock_node (rn);
3739 aspath_unintern (&attr.aspath);
3740 bgp_attr_extra_free (&attr);
3741 return;
3742 }
3743 }
3744
3745
3746 /* Make new BGP info. */
3747 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
3748 rn);
3749 SET_FLAG (new->flags, BGP_INFO_VALID);
3750 new->extra = bgp_info_extra_new();
3751 memcpy (new->extra->tag, bgp_static->tag, 3);
3752
3753 /* Aggregate address increment. */
3754 bgp_aggregate_increment (bgp, p, new, afi, safi);
3755
3756 /* Register new BGP information. */
3757 bgp_info_add (rn, new);
3758
3759 /* route_node_get lock */
3760 bgp_unlock_node (rn);
3761
3762 /* Process change. */
3763 bgp_process (bgp, rn, afi, safi);
3764
3765 /* Unintern original. */
3766 aspath_unintern (&attr.aspath);
3767 bgp_attr_extra_free (&attr);
3768}
3769
718e3744 3770/* Configure static BGP network. When user don't run zebra, static
3771 route should be installed as valid. */
94f2b392 3772static int
fd79ac91 3773bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
c8f3fe30 3774 afi_t afi, safi_t safi, const char *rmap, int backdoor)
718e3744 3775{
3776 int ret;
3777 struct prefix p;
3778 struct bgp_static *bgp_static;
3779 struct bgp_node *rn;
41367172 3780 u_char need_update = 0;
718e3744 3781
3782 /* Convert IP prefix string to struct prefix. */
3783 ret = str2prefix (ip_str, &p);
3784 if (! ret)
3785 {
3786 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3787 return CMD_WARNING;
3788 }
3789#ifdef HAVE_IPV6
3790 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3791 {
3792 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3793 VTY_NEWLINE);
3794 return CMD_WARNING;
3795 }
3796#endif /* HAVE_IPV6 */
3797
3798 apply_mask (&p);
3799
3800 /* Set BGP static route configuration. */
3801 rn = bgp_node_get (bgp->route[afi][safi], &p);
3802
3803 if (rn->info)
3804 {
3805 /* Configuration change. */
3806 bgp_static = rn->info;
3807
3808 /* Check previous routes are installed into BGP. */
c8f3fe30
PJ
3809 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3810 need_update = 1;
41367172 3811
718e3744 3812 bgp_static->backdoor = backdoor;
41367172 3813
718e3744 3814 if (rmap)
3815 {
3816 if (bgp_static->rmap.name)
6e919709
DS
3817 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3818 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
718e3744 3819 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3820 }
3821 else
3822 {
3823 if (bgp_static->rmap.name)
6e919709 3824 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
718e3744 3825 bgp_static->rmap.name = NULL;
3826 bgp_static->rmap.map = NULL;
3827 bgp_static->valid = 0;
3828 }
3829 bgp_unlock_node (rn);
3830 }
3831 else
3832 {
3833 /* New configuration. */
3834 bgp_static = bgp_static_new ();
3835 bgp_static->backdoor = backdoor;
3836 bgp_static->valid = 0;
3837 bgp_static->igpmetric = 0;
3838 bgp_static->igpnexthop.s_addr = 0;
41367172 3839
718e3744 3840 if (rmap)
3841 {
3842 if (bgp_static->rmap.name)
6e919709
DS
3843 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3844 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
718e3744 3845 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3846 }
3847 rn->info = bgp_static;
3848 }
3849
fc9a856f
DS
3850 bgp_static->valid = 1;
3851 if (need_update)
3852 bgp_static_withdraw (bgp, &p, afi, safi);
718e3744 3853
fc9a856f
DS
3854 if (! bgp_static->backdoor)
3855 bgp_static_update (bgp, &p, bgp_static, afi, safi);
718e3744 3856
3857 return CMD_SUCCESS;
3858}
3859
3860/* Configure static BGP network. */
94f2b392 3861static int
fd79ac91 3862bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4c9641ba 3863 afi_t afi, safi_t safi)
718e3744 3864{
3865 int ret;
3866 struct prefix p;
3867 struct bgp_static *bgp_static;
3868 struct bgp_node *rn;
3869
3870 /* Convert IP prefix string to struct prefix. */
3871 ret = str2prefix (ip_str, &p);
3872 if (! ret)
3873 {
3874 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3875 return CMD_WARNING;
3876 }
3877#ifdef HAVE_IPV6
3878 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3879 {
3880 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3881 VTY_NEWLINE);
3882 return CMD_WARNING;
3883 }
3884#endif /* HAVE_IPV6 */
3885
3886 apply_mask (&p);
3887
3888 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3889 if (! rn)
3890 {
3891 vty_out (vty, "%% Can't find specified static route configuration.%s",
3892 VTY_NEWLINE);
3893 return CMD_WARNING;
3894 }
3895
3896 bgp_static = rn->info;
41367172 3897
718e3744 3898 /* Update BGP RIB. */
3899 if (! bgp_static->backdoor)
3900 bgp_static_withdraw (bgp, &p, afi, safi);
3901
3902 /* Clear configuration. */
3903 bgp_static_free (bgp_static);
3904 rn->info = NULL;
3905 bgp_unlock_node (rn);
3906 bgp_unlock_node (rn);
3907
3908 return CMD_SUCCESS;
3909}
3910
6aeb9e78
DS
3911void
3912bgp_static_add (struct bgp *bgp)
3913{
3914 afi_t afi;
3915 safi_t safi;
3916 struct bgp_node *rn;
3917 struct bgp_node *rm;
3918 struct bgp_table *table;
3919 struct bgp_static *bgp_static;
3920
3921 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3922 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3923 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3924 if (rn->info != NULL)
3925 {
3926 if (safi == SAFI_MPLS_VPN)
3927 {
3928 table = rn->info;
3929
3930 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3931 {
3932 bgp_static = rn->info;
137446f9 3933 bgp_static_update_safi (bgp, &rm->p, bgp_static, afi, safi);
6aeb9e78
DS
3934 }
3935 }
3936 else
3937 {
3938 bgp_static_update (bgp, &rn->p, rn->info, afi, safi);
3939 }
3940 }
3941}
3942
718e3744 3943/* Called from bgp_delete(). Delete all static routes from the BGP
3944 instance. */
3945void
3946bgp_static_delete (struct bgp *bgp)
3947{
3948 afi_t afi;
3949 safi_t safi;
3950 struct bgp_node *rn;
3951 struct bgp_node *rm;
3952 struct bgp_table *table;
3953 struct bgp_static *bgp_static;
3954
3955 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3956 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3957 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3958 if (rn->info != NULL)
3959 {
587ff0fd 3960 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 3961 {
3962 table = rn->info;
3963
3964 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3965 {
3966 bgp_static = rn->info;
137446f9
LB
3967 bgp_static_withdraw_safi (bgp, &rm->p,
3968 AFI_IP, safi,
718e3744 3969 (struct prefix_rd *)&rn->p,
3970 bgp_static->tag);
3971 bgp_static_free (bgp_static);
3972 rn->info = NULL;
3973 bgp_unlock_node (rn);
3974 }
3975 }
3976 else
3977 {
3978 bgp_static = rn->info;
3979 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3980 bgp_static_free (bgp_static);
3981 rn->info = NULL;
3982 bgp_unlock_node (rn);
3983 }
3984 }
3985}
3986
078430f6
DS
3987void
3988bgp_static_redo_import_check (struct bgp *bgp)
3989{
3990 afi_t afi;
3991 safi_t safi;
3992 struct bgp_node *rn;
078430f6
DS
3993 struct bgp_static *bgp_static;
3994
3995 /* Use this flag to force reprocessing of the route */
3996 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
3997 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3998 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3999 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4000 if (rn->info != NULL)
4001 {
4002 bgp_static = rn->info;
4003 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
4004 }
4005 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4006}
4007
ad4cbda1 4008static void
4009bgp_purge_af_static_redist_routes (struct bgp *bgp, afi_t afi, safi_t safi)
4010{
4011 struct bgp_table *table;
4012 struct bgp_node *rn;
4013 struct bgp_info *ri;
4014
4015 table = bgp->rib[afi][safi];
4016 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4017 {
4018 for (ri = rn->info; ri; ri = ri->next)
4019 {
4020 if (ri->peer == bgp->peer_self &&
4021 ((ri->type == ZEBRA_ROUTE_BGP &&
4022 ri->sub_type == BGP_ROUTE_STATIC) ||
4023 (ri->type != ZEBRA_ROUTE_BGP &&
4024 ri->sub_type == BGP_ROUTE_REDISTRIBUTE)))
4025 {
4026 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, safi);
4027 bgp_unlink_nexthop(ri);
4028 bgp_info_delete (rn, ri);
4029 bgp_process (bgp, rn, afi, safi);
4030 }
4031 }
4032 }
4033}
4034
4035/*
4036 * Purge all networks and redistributed routes from routing table.
4037 * Invoked upon the instance going down.
4038 */
4039void
4040bgp_purge_static_redist_routes (struct bgp *bgp)
4041{
4042 afi_t afi;
4043 safi_t safi;
4044
4045 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4046 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4047 bgp_purge_af_static_redist_routes (bgp, afi, safi);
4048}
4049
137446f9
LB
4050/*
4051 * gpz 110624
4052 * Currently this is used to set static routes for VPN and ENCAP.
4053 * I think it can probably be factored with bgp_static_set.
4054 */
718e3744 4055int
137446f9
LB
4056bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4057 const char *rd_str, const char *tag_str,
4058 const char *rmap_str)
718e3744 4059{
4060 int ret;
4061 struct prefix p;
4062 struct prefix_rd prd;
4063 struct bgp *bgp;
4064 struct bgp_node *prn;
4065 struct bgp_node *rn;
4066 struct bgp_table *table;
4067 struct bgp_static *bgp_static;
4068 u_char tag[3];
4069
4070 bgp = vty->index;
4071
4072 ret = str2prefix (ip_str, &p);
4073 if (! ret)
4074 {
4075 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4076 return CMD_WARNING;
4077 }
4078 apply_mask (&p);
4079
4080 ret = str2prefix_rd (rd_str, &prd);
4081 if (! ret)
4082 {
4083 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4084 return CMD_WARNING;
4085 }
4086
4087 ret = str2tag (tag_str, tag);
4088 if (! ret)
4089 {
4090 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4091 return CMD_WARNING;
4092 }
4093
137446f9 4094 prn = bgp_node_get (bgp->route[AFI_IP][safi],
718e3744 4095 (struct prefix *)&prd);
4096 if (prn->info == NULL)
137446f9 4097 prn->info = bgp_table_init (AFI_IP, safi);
718e3744 4098 else
4099 bgp_unlock_node (prn);
4100 table = prn->info;
4101
4102 rn = bgp_node_get (table, &p);
4103
4104 if (rn->info)
4105 {
4106 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4107 bgp_unlock_node (rn);
4108 }
4109 else
4110 {
4111 /* New configuration. */
4112 bgp_static = bgp_static_new ();
137446f9
LB
4113 bgp_static->backdoor = 0;
4114 bgp_static->valid = 0;
4115 bgp_static->igpmetric = 0;
4116 bgp_static->igpnexthop.s_addr = 0;
4117 memcpy(bgp_static->tag, tag, 3);
4118 bgp_static->prd = prd;
4119
4120 if (rmap_str)
4121 {
4122 if (bgp_static->rmap.name)
4123 free (bgp_static->rmap.name);
4124 bgp_static->rmap.name = strdup (rmap_str);
4125 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4126 }
718e3744 4127 rn->info = bgp_static;
4128
137446f9
LB
4129 bgp_static->valid = 1;
4130 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
718e3744 4131 }
4132
4133 return CMD_SUCCESS;
4134}
4135
4136/* Configure static BGP network. */
4137int
137446f9
LB
4138bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4139 const char *rd_str, const char *tag_str)
718e3744 4140{
4141 int ret;
4142 struct bgp *bgp;
4143 struct prefix p;
4144 struct prefix_rd prd;
4145 struct bgp_node *prn;
4146 struct bgp_node *rn;
4147 struct bgp_table *table;
4148 struct bgp_static *bgp_static;
4149 u_char tag[3];
4150
4151 bgp = vty->index;
4152
4153 /* Convert IP prefix string to struct prefix. */
4154 ret = str2prefix (ip_str, &p);
4155 if (! ret)
4156 {
4157 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4158 return CMD_WARNING;
4159 }
4160 apply_mask (&p);
4161
4162 ret = str2prefix_rd (rd_str, &prd);
4163 if (! ret)
4164 {
4165 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4166 return CMD_WARNING;
4167 }
4168
4169 ret = str2tag (tag_str, tag);
4170 if (! ret)
4171 {
4172 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4173 return CMD_WARNING;
4174 }
4175
137446f9 4176 prn = bgp_node_get (bgp->route[AFI_IP][safi],
718e3744 4177 (struct prefix *)&prd);
4178 if (prn->info == NULL)
137446f9 4179 prn->info = bgp_table_init (AFI_IP, safi);
718e3744 4180 else
4181 bgp_unlock_node (prn);
4182 table = prn->info;
4183
4184 rn = bgp_node_lookup (table, &p);
4185
4186 if (rn)
4187 {
137446f9 4188 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
718e3744 4189
4190 bgp_static = rn->info;
4191 bgp_static_free (bgp_static);
4192 rn->info = NULL;
4193 bgp_unlock_node (rn);
4194 bgp_unlock_node (rn);
4195 }
4196 else
4197 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4198
4199 return CMD_SUCCESS;
4200}
6b0655a2 4201
73ac8160
DS
4202static int
4203bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4204 const char *rmap_name)
4205{
4206 struct bgp_rmap *rmap;
4207
4208 rmap = &bgp->table_map[afi][safi];
4209 if (rmap_name)
4210 {
4211 if (rmap->name)
6e919709
DS
4212 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4213 rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name);
73ac8160
DS
4214 rmap->map = route_map_lookup_by_name (rmap_name);
4215 }
4216 else
4217 {
4218 if (rmap->name)
6e919709 4219 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
73ac8160
DS
4220 rmap->name = NULL;
4221 rmap->map = NULL;
4222 }
4223
4224 bgp_zebra_announce_table(bgp, afi, safi);
4225
4226 return CMD_SUCCESS;
4227}
4228
4229static int
4230bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4231 const char *rmap_name)
4232{
4233 struct bgp_rmap *rmap;
4234
4235 rmap = &bgp->table_map[afi][safi];
4236 if (rmap->name)
6e919709 4237 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
73ac8160
DS
4238 rmap->name = NULL;
4239 rmap->map = NULL;
4240
4241 bgp_zebra_announce_table(bgp, afi, safi);
4242
4243 return CMD_SUCCESS;
4244}
4245
4246int
4247bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4248 safi_t safi, int *write)
4249{
4250 if (bgp->table_map[afi][safi].name)
4251 {
4252 bgp_config_write_family_header (vty, afi, safi, write);
0b960b4d 4253 vty_out (vty, " table-map %s%s",
73ac8160
DS
4254 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4255 }
4256
4257 return 0;
4258}
4259
4260
4261DEFUN (bgp_table_map,
4262 bgp_table_map_cmd,
4263 "table-map WORD",
4264 "BGP table to RIB route download filter\n"
4265 "Name of the route map\n")
4266{
4267 return bgp_table_map_set (vty, vty->index,
4dcadbef 4268 bgp_node_afi (vty), bgp_node_safi (vty), argv[1]->arg);
73ac8160
DS
4269}
4270DEFUN (no_bgp_table_map,
4271 no_bgp_table_map_cmd,
4272 "no table-map WORD",
4273 "BGP table to RIB route download filter\n"
4274 "Name of the route map\n")
4275{
4276 return bgp_table_map_unset (vty, vty->index,
4dcadbef 4277 bgp_node_afi (vty), bgp_node_safi (vty), argv[2]->arg);
73ac8160
DS
4278}
4279
718e3744 4280DEFUN (bgp_network,
4281 bgp_network_cmd,
4282 "network A.B.C.D/M",
4283 "Specify a network to announce via BGP\n"
4284 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4285{
4dcadbef 4286 return bgp_static_set (vty, vty->index, argv[1]->arg,
c8f3fe30 4287 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4288}
4289
4290DEFUN (bgp_network_route_map,
4291 bgp_network_route_map_cmd,
4292 "network A.B.C.D/M route-map WORD",
4293 "Specify a network to announce via BGP\n"
4294 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4295 "Route-map to modify the attributes\n"
4296 "Name of the route map\n")
4297{
4dcadbef
DW
4298 return bgp_static_set (vty, vty->index, argv[1]->arg,
4299 AFI_IP, bgp_node_safi (vty), argv[3]->arg, 0);
718e3744 4300}
4301
4302DEFUN (bgp_network_backdoor,
4303 bgp_network_backdoor_cmd,
4304 "network A.B.C.D/M backdoor",
4305 "Specify a network to announce via BGP\n"
4306 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4307 "Specify a BGP backdoor route\n")
4308{
4dcadbef 4309 return bgp_static_set (vty, vty->index, argv[1]->arg, AFI_IP, SAFI_UNICAST,
c8f3fe30 4310 NULL, 1);
718e3744 4311}
4312
4313DEFUN (bgp_network_mask,
4314 bgp_network_mask_cmd,
4315 "network A.B.C.D mask A.B.C.D",
4316 "Specify a network to announce via BGP\n"
4317 "Network number\n"
4318 "Network mask\n"
4319 "Network mask\n")
4320{
4321 int ret;
4322 char prefix_str[BUFSIZ];
41367172 4323
4dcadbef 4324 ret = netmask_str2prefix_str (argv[1]->arg, argv[3]->arg, prefix_str);
718e3744 4325 if (! ret)
4326 {
4327 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4328 return CMD_WARNING;
4329 }
4330
4331 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4332 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4333}
4334
4335DEFUN (bgp_network_mask_route_map,
4336 bgp_network_mask_route_map_cmd,
4337 "network A.B.C.D mask A.B.C.D route-map WORD",
4338 "Specify a network to announce via BGP\n"
4339 "Network number\n"
4340 "Network mask\n"
4341 "Network mask\n"
4342 "Route-map to modify the attributes\n"
4343 "Name of the route map\n")
4344{
4345 int ret;
4346 char prefix_str[BUFSIZ];
41367172 4347
4dcadbef 4348 ret = netmask_str2prefix_str (argv[1]->arg, argv[3]->arg, prefix_str);
718e3744 4349 if (! ret)
4350 {
4351 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4352 return CMD_WARNING;
4353 }
4354
4355 return bgp_static_set (vty, vty->index, prefix_str,
4dcadbef 4356 AFI_IP, bgp_node_safi (vty), argv[5]->arg, 0);
718e3744 4357}
4358
4359DEFUN (bgp_network_mask_backdoor,
4360 bgp_network_mask_backdoor_cmd,
4361 "network A.B.C.D mask A.B.C.D backdoor",
4362 "Specify a network to announce via BGP\n"
4363 "Network number\n"
4364 "Network mask\n"
4365 "Network mask\n"
4366 "Specify a BGP backdoor route\n")
4367{
4368 int ret;
4369 char prefix_str[BUFSIZ];
41367172 4370
4dcadbef 4371 ret = netmask_str2prefix_str (argv[1]->arg, argv[3]->arg, prefix_str);
718e3744 4372 if (! ret)
4373 {
4374 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4375 return CMD_WARNING;
4376 }
4377
41367172 4378 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 4379 NULL, 1);
718e3744 4380}
4381
4382DEFUN (bgp_network_mask_natural,
4383 bgp_network_mask_natural_cmd,
4384 "network A.B.C.D",
4385 "Specify a network to announce via BGP\n"
4386 "Network number\n")
4387{
4388 int ret;
4389 char prefix_str[BUFSIZ];
4390
4dcadbef 4391 ret = netmask_str2prefix_str (argv[1]->arg, NULL, prefix_str);
718e3744 4392 if (! ret)
4393 {
4394 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4395 return CMD_WARNING;
4396 }
4397
4398 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4399 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4400}
4401
4402DEFUN (bgp_network_mask_natural_route_map,
4403 bgp_network_mask_natural_route_map_cmd,
4404 "network A.B.C.D route-map WORD",
4405 "Specify a network to announce via BGP\n"
4406 "Network number\n"
4407 "Route-map to modify the attributes\n"
4408 "Name of the route map\n")
4409{
4410 int ret;
4411 char prefix_str[BUFSIZ];
4412
4dcadbef 4413 ret = netmask_str2prefix_str (argv[1]->arg, NULL, prefix_str);
718e3744 4414 if (! ret)
4415 {
4416 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4417 return CMD_WARNING;
4418 }
4419
4420 return bgp_static_set (vty, vty->index, prefix_str,
4dcadbef 4421 AFI_IP, bgp_node_safi (vty), argv[3]->arg, 0);
718e3744 4422}
4423
4424DEFUN (bgp_network_mask_natural_backdoor,
4425 bgp_network_mask_natural_backdoor_cmd,
4426 "network A.B.C.D backdoor",
4427 "Specify a network to announce via BGP\n"
4428 "Network number\n"
4429 "Specify a BGP backdoor route\n")
4430{
4431 int ret;
4432 char prefix_str[BUFSIZ];
4433
4dcadbef 4434 ret = netmask_str2prefix_str (argv[1]->arg, NULL, prefix_str);
718e3744 4435 if (! ret)
4436 {
4437 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4438 return CMD_WARNING;
4439 }
4440
41367172 4441 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 4442 NULL, 1);
718e3744 4443}
4444
f412b39a
DW
4445/*
4446 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
4447 * "no network A.B.C.D/M route-map WORD",
4448 * NO_STR
4449 * "Specify a network to announce via BGP\n"
4450 * "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4451 * "Route-map to modify the attributes\n"
4452 * "Name of the route map\n"
4453 *
4454 * "no network A.B.C.D/M backdoor",
4455 * NO_STR
4456 * "Specify a network to announce via BGP\n"
4457 * "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4458 * "Specify a BGP backdoor route\n"
4459 *
4460 */
718e3744 4461DEFUN (no_bgp_network,
4462 no_bgp_network_cmd,
4463 "no network A.B.C.D/M",
4464 NO_STR
4465 "Specify a network to announce via BGP\n"
4466 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4467{
4dcadbef 4468 return bgp_static_unset (vty, vty->index, argv[2]->arg, AFI_IP,
718e3744 4469 bgp_node_safi (vty));
4470}
4471
718e3744 4472
718e3744 4473
f412b39a
DW
4474/*
4475 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
4476 * "no network A.B.C.D mask A.B.C.D backdoor",
4477 * NO_STR
4478 * "Specify a network to announce via BGP\n"
4479 * "Network number\n"
4480 * "Network mask\n"
4481 * "Network mask\n"
4482 * "Specify a BGP backdoor route\n"
4483 *
4484 * "no network A.B.C.D mask A.B.C.D route-map WORD",
4485 * NO_STR
4486 * "Specify a network to announce via BGP\n"
4487 * "Network number\n"
4488 * "Network mask\n"
4489 * "Network mask\n"
4490 * "Route-map to modify the attributes\n"
4491 * "Name of the route map\n"
4492 *
4493 */
718e3744 4494DEFUN (no_bgp_network_mask,
4495 no_bgp_network_mask_cmd,
4496 "no network A.B.C.D mask A.B.C.D",
4497 NO_STR
4498 "Specify a network to announce via BGP\n"
4499 "Network number\n"
4500 "Network mask\n"
4501 "Network mask\n")
4502{
4503 int ret;
4504 char prefix_str[BUFSIZ];
4505
4dcadbef 4506 ret = netmask_str2prefix_str (argv[2]->arg, argv[4]->arg, prefix_str);
718e3744 4507 if (! ret)
4508 {
4509 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4510 return CMD_WARNING;
4511 }
4512
4513 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4514 bgp_node_safi (vty));
4515}
4516
718e3744 4517
718e3744 4518
f412b39a
DW
4519/*
4520 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
4521 * "no network A.B.C.D backdoor",
4522 * NO_STR
4523 * "Specify a network to announce via BGP\n"
4524 * "Network number\n"
4525 * "Specify a BGP backdoor route\n"
4526 *
4527 * "no network A.B.C.D route-map WORD",
4528 * NO_STR
4529 * "Specify a network to announce via BGP\n"
4530 * "Network number\n"
4531 * "Route-map to modify the attributes\n"
4532 * "Name of the route map\n"
4533 *
4534 */
718e3744 4535DEFUN (no_bgp_network_mask_natural,
4536 no_bgp_network_mask_natural_cmd,
4537 "no network A.B.C.D",
4538 NO_STR
4539 "Specify a network to announce via BGP\n"
4540 "Network number\n")
4541{
4542 int ret;
4543 char prefix_str[BUFSIZ];
4544
4dcadbef 4545 ret = netmask_str2prefix_str (argv[2]->arg, NULL, prefix_str);
718e3744 4546 if (! ret)
4547 {
4548 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4549 return CMD_WARNING;
4550 }
4551
4552 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4553 bgp_node_safi (vty));
4554}
4555
718e3744 4556
718e3744 4557
4558#ifdef HAVE_IPV6
f412b39a
DW
4559/*
4560 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
4561 * "ipv6 bgp network X:X::X:X/M",
4562 * IPV6_STR
4563 * BGP_STR
4564 * "Specify a network to announce via BGP\n"
4565 * "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
4566 *
4567 */
718e3744 4568DEFUN (ipv6_bgp_network,
4569 ipv6_bgp_network_cmd,
4570 "network X:X::X:X/M",
4571 "Specify a network to announce via BGP\n"
4572 "IPv6 prefix <network>/<length>\n")
4573{
4dcadbef 4574 return bgp_static_set (vty, vty->index, argv[1]->arg, AFI_IP6, bgp_node_safi(vty),
c8f3fe30 4575 NULL, 0);
718e3744 4576}
4577
4578DEFUN (ipv6_bgp_network_route_map,
4579 ipv6_bgp_network_route_map_cmd,
4580 "network X:X::X:X/M route-map WORD",
4581 "Specify a network to announce via BGP\n"
4582 "IPv6 prefix <network>/<length>\n"
4583 "Route-map to modify the attributes\n"
4584 "Name of the route map\n")
4585{
4dcadbef
DW
4586 return bgp_static_set (vty, vty->index, argv[1]->arg, AFI_IP6,
4587 bgp_node_safi (vty), argv[3]->arg, 0);
718e3744 4588}
4589
f412b39a
DW
4590/*
4591 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
4592 * "no network X:X::X:X/M route-map WORD",
4593 * NO_STR
4594 * "Specify a network to announce via BGP\n"
4595 * "IPv6 prefix <network>/<length>\n"
4596 * "Route-map to modify the attributes\n"
4597 * "Name of the route map\n"
4598 *
4599 * "no ipv6 bgp network X:X::X:X/M",
4600 * NO_STR
4601 * IPV6_STR
4602 * BGP_STR
4603 * "Specify a network to announce via BGP\n"
4604 * "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
4605 *
4606 */
718e3744 4607DEFUN (no_ipv6_bgp_network,
4608 no_ipv6_bgp_network_cmd,
4609 "no network X:X::X:X/M",
4610 NO_STR
4611 "Specify a network to announce via BGP\n"
4612 "IPv6 prefix <network>/<length>\n")
4613{
4dcadbef 4614 return bgp_static_unset (vty, vty->index, argv[2]->arg, AFI_IP6, bgp_node_safi(vty));
718e3744 4615}
4616
718e3744 4617
718e3744 4618
718e3744 4619#endif /* HAVE_IPV6 */
c8f3fe30 4620
718e3744 4621/* Aggreagete address:
4622
4623 advertise-map Set condition to advertise attribute
4624 as-set Generate AS set path information
4625 attribute-map Set attributes of aggregate
4626 route-map Set parameters of aggregate
4627 summary-only Filter more specific routes from updates
4628 suppress-map Conditionally filter more specific routes from updates
4629 <cr>
4630 */
4631struct bgp_aggregate
4632{
4633 /* Summary-only flag. */
4634 u_char summary_only;
4635
4636 /* AS set generation. */
4637 u_char as_set;
4638
4639 /* Route-map for aggregated route. */
4640 struct route_map *map;
4641
4642 /* Suppress-count. */
4643 unsigned long count;
4644
4645 /* SAFI configuration. */
4646 safi_t safi;
4647};
4648
94f2b392 4649static struct bgp_aggregate *
66e5cd87 4650bgp_aggregate_new (void)
718e3744 4651{
393deb9b 4652 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
718e3744 4653}
4654
94f2b392 4655static void
718e3744 4656bgp_aggregate_free (struct bgp_aggregate *aggregate)
4657{
4658 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4659}
4660
b5d58c32 4661/* Update an aggregate as routes are added/removed from the BGP table */
94f2b392 4662static void
718e3744 4663bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4664 afi_t afi, safi_t safi, struct bgp_info *del,
4665 struct bgp_aggregate *aggregate)
4666{
4667 struct bgp_table *table;
4668 struct bgp_node *top;
4669 struct bgp_node *rn;
4670 u_char origin;
4671 struct aspath *aspath = NULL;
4672 struct aspath *asmerge = NULL;
4673 struct community *community = NULL;
4674 struct community *commerge = NULL;
ffd0c037 4675#if defined(AGGREGATE_NEXTHOP_CHECK)
718e3744 4676 struct in_addr nexthop;
4677 u_int32_t med = 0;
ffd0c037 4678#endif
718e3744 4679 struct bgp_info *ri;
4680 struct bgp_info *new;
4681 int first = 1;
4682 unsigned long match = 0;
42f7e184 4683 u_char atomic_aggregate = 0;
718e3744 4684
4685 /* Record adding route's nexthop and med. */
ffd0c037
DS
4686 if (rinew)
4687 {
4688#if defined(AGGREGATE_NEXTHOP_CHECK)
4689 nexthop = rinew->attr->nexthop;
4690 med = rinew->attr->med;
4691#endif
4692 }
718e3744 4693
4694 /* ORIGIN attribute: If at least one route among routes that are
4695 aggregated has ORIGIN with the value INCOMPLETE, then the
4696 aggregated route must have the ORIGIN attribute with the value
4697 INCOMPLETE. Otherwise, if at least one route among routes that
4698 are aggregated has ORIGIN with the value EGP, then the aggregated
4699 route must have the origin attribute with the value EGP. In all
4700 other case the value of the ORIGIN attribute of the aggregated
4701 route is INTERNAL. */
4702 origin = BGP_ORIGIN_IGP;
4703
4704 table = bgp->rib[afi][safi];
4705
4706 top = bgp_node_get (table, p);
4707 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4708 if (rn->p.prefixlen > p->prefixlen)
4709 {
4710 match = 0;
4711
4712 for (ri = rn->info; ri; ri = ri->next)
4713 {
4714 if (BGP_INFO_HOLDDOWN (ri))
4715 continue;
4716
4717 if (del && ri == del)
4718 continue;
4719
4720 if (! rinew && first)
4721 {
ffd0c037 4722#if defined(AGGREGATE_NEXTHOP_CHECK)
718e3744 4723 nexthop = ri->attr->nexthop;
4724 med = ri->attr->med;
ffd0c037 4725#endif
718e3744 4726 first = 0;
4727 }
4728
4729#ifdef AGGREGATE_NEXTHOP_CHECK
4730 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4731 || ri->attr->med != med)
4732 {
4733 if (aspath)
4734 aspath_free (aspath);
4735 if (community)
4736 community_free (community);
4737 bgp_unlock_node (rn);
4738 bgp_unlock_node (top);
4739 return;
4740 }
4741#endif /* AGGREGATE_NEXTHOP_CHECK */
4742
42f7e184
DS
4743 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4744 atomic_aggregate = 1;
4745
718e3744 4746 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4747 {
4748 if (aggregate->summary_only)
4749 {
fb982c25 4750 (bgp_info_extra_get (ri))->suppress++;
1a392d46 4751 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4752 match++;
4753 }
4754
4755 aggregate->count++;
4756
b5d58c32
DS
4757 if (origin < ri->attr->origin)
4758 origin = ri->attr->origin;
4759
718e3744 4760 if (aggregate->as_set)
4761 {
718e3744 4762 if (aspath)
4763 {
4764 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4765 aspath_free (aspath);
4766 aspath = asmerge;
4767 }
4768 else
4769 aspath = aspath_dup (ri->attr->aspath);
4770
4771 if (ri->attr->community)
4772 {
4773 if (community)
4774 {
4775 commerge = community_merge (community,
4776 ri->attr->community);
4777 community = community_uniq_sort (commerge);
4778 community_free (commerge);
4779 }
4780 else
4781 community = community_dup (ri->attr->community);
4782 }
4783 }
4784 }
4785 }
4786 if (match)
4787 bgp_process (bgp, rn, afi, safi);
4788 }
4789 bgp_unlock_node (top);
4790
4791 if (rinew)
4792 {
4793 aggregate->count++;
4794
4795 if (aggregate->summary_only)
fb982c25 4796 (bgp_info_extra_get (rinew))->suppress++;
718e3744 4797
b5d58c32
DS
4798 if (origin < rinew->attr->origin)
4799 origin = rinew->attr->origin;
4800
718e3744 4801 if (aggregate->as_set)
4802 {
718e3744 4803 if (aspath)
4804 {
4805 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4806 aspath_free (aspath);
4807 aspath = asmerge;
4808 }
4809 else
4810 aspath = aspath_dup (rinew->attr->aspath);
4811
4812 if (rinew->attr->community)
4813 {
4814 if (community)
4815 {
4816 commerge = community_merge (community,
4817 rinew->attr->community);
4818 community = community_uniq_sort (commerge);
4819 community_free (commerge);
4820 }
4821 else
4822 community = community_dup (rinew->attr->community);
4823 }
4824 }
4825 }
4826
4827 if (aggregate->count > 0)
4828 {
4829 rn = bgp_node_get (table, p);
7c8ff89e 4830 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 4831 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
4832 aggregate->as_set,
4833 atomic_aggregate), rn);
718e3744 4834 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 4835
4836 bgp_info_add (rn, new);
200df115 4837 bgp_unlock_node (rn);
718e3744 4838 bgp_process (bgp, rn, afi, safi);
4839 }
4840 else
4841 {
4842 if (aspath)
4843 aspath_free (aspath);
4844 if (community)
4845 community_free (community);
4846 }
4847}
4848
4849void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4850 struct bgp_aggregate *);
4851
4852void
4853bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4854 struct bgp_info *ri, afi_t afi, safi_t safi)
4855{
4856 struct bgp_node *child;
4857 struct bgp_node *rn;
4858 struct bgp_aggregate *aggregate;
f018db83 4859 struct bgp_table *table;
718e3744 4860
4861 /* MPLS-VPN aggregation is not yet supported. */
587ff0fd 4862 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 4863 return;
4864
f018db83
JBD
4865 table = bgp->aggregate[afi][safi];
4866
4867 /* No aggregates configured. */
67174041 4868 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
4869 return;
4870
718e3744 4871 if (p->prefixlen == 0)
4872 return;
4873
4874 if (BGP_INFO_HOLDDOWN (ri))
4875 return;
4876
bb782fb5 4877 child = bgp_node_get (table, p);
718e3744 4878
4879 /* Aggregate address configuration check. */
67174041 4880 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 4881 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4882 {
4883 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 4884 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
718e3744 4885 }
4886 bgp_unlock_node (child);
4887}
4888
4889void
4890bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4891 struct bgp_info *del, afi_t afi, safi_t safi)
4892{
4893 struct bgp_node *child;
4894 struct bgp_node *rn;
4895 struct bgp_aggregate *aggregate;
f018db83 4896 struct bgp_table *table;
718e3744 4897
4898 /* MPLS-VPN aggregation is not yet supported. */
587ff0fd 4899 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 4900 return;
4901
f018db83
JBD
4902 table = bgp->aggregate[afi][safi];
4903
4904 /* No aggregates configured. */
67174041 4905 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
4906 return;
4907
718e3744 4908 if (p->prefixlen == 0)
4909 return;
4910
bb782fb5 4911 child = bgp_node_get (table, p);
718e3744 4912
4913 /* Aggregate address configuration check. */
67174041 4914 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 4915 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4916 {
4917 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 4918 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
718e3744 4919 }
4920 bgp_unlock_node (child);
4921}
4922
b5d58c32 4923/* Called via bgp_aggregate_set when the user configures aggregate-address */
94f2b392 4924static void
718e3744 4925bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4926 struct bgp_aggregate *aggregate)
4927{
4928 struct bgp_table *table;
4929 struct bgp_node *top;
4930 struct bgp_node *rn;
4931 struct bgp_info *new;
4932 struct bgp_info *ri;
4933 unsigned long match;
4934 u_char origin = BGP_ORIGIN_IGP;
4935 struct aspath *aspath = NULL;
4936 struct aspath *asmerge = NULL;
4937 struct community *community = NULL;
4938 struct community *commerge = NULL;
42f7e184 4939 u_char atomic_aggregate = 0;
718e3744 4940
4941 table = bgp->rib[afi][safi];
4942
4943 /* Sanity check. */
4944 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4945 return;
4946 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4947 return;
4948
4949 /* If routes exists below this node, generate aggregate routes. */
4950 top = bgp_node_get (table, p);
4951 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4952 if (rn->p.prefixlen > p->prefixlen)
4953 {
4954 match = 0;
4955
4956 for (ri = rn->info; ri; ri = ri->next)
4957 {
4958 if (BGP_INFO_HOLDDOWN (ri))
4959 continue;
4960
42f7e184
DS
4961 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4962 atomic_aggregate = 1;
4963
718e3744 4964 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4965 {
4966 /* summary-only aggregate route suppress aggregated
4967 route announcement. */
4968 if (aggregate->summary_only)
4969 {
fb982c25 4970 (bgp_info_extra_get (ri))->suppress++;
1a392d46 4971 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4972 match++;
4973 }
b5d58c32
DS
4974
4975 /* If at least one route among routes that are aggregated has
4976 * ORIGIN with the value INCOMPLETE, then the aggregated route
4977 * MUST have the ORIGIN attribute with the value INCOMPLETE.
4978 * Otherwise, if at least one route among routes that are
4979 * aggregated has ORIGIN with the value EGP, then the aggregated
4980 * route MUST have the ORIGIN attribute with the value EGP.
4981 */
4982 if (origin < ri->attr->origin)
4983 origin = ri->attr->origin;
4984
718e3744 4985 /* as-set aggregate route generate origin, as path,
4986 community aggregation. */
4987 if (aggregate->as_set)
4988 {
718e3744 4989 if (aspath)
4990 {
4991 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4992 aspath_free (aspath);
4993 aspath = asmerge;
4994 }
4995 else
4996 aspath = aspath_dup (ri->attr->aspath);
4997
4998 if (ri->attr->community)
4999 {
5000 if (community)
5001 {
5002 commerge = community_merge (community,
5003 ri->attr->community);
5004 community = community_uniq_sort (commerge);
5005 community_free (commerge);
5006 }
5007 else
5008 community = community_dup (ri->attr->community);
5009 }
5010 }
5011 aggregate->count++;
5012 }
5013 }
5014
5015 /* If this node is suppressed, process the change. */
5016 if (match)
5017 bgp_process (bgp, rn, afi, safi);
5018 }
5019 bgp_unlock_node (top);
5020
5021 /* Add aggregate route to BGP table. */
5022 if (aggregate->count)
5023 {
5024 rn = bgp_node_get (table, p);
7c8ff89e 5025 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 5026 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
5027 aggregate->as_set,
5028 atomic_aggregate), rn);
718e3744 5029 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 5030
5031 bgp_info_add (rn, new);
200df115 5032 bgp_unlock_node (rn);
5033
718e3744 5034 /* Process change. */
5035 bgp_process (bgp, rn, afi, safi);
5036 }
610f23cf
DV
5037 else
5038 {
5039 if (aspath)
5040 aspath_free (aspath);
5041 if (community)
5042 community_free (community);
5043 }
718e3744 5044}
5045
5046void
5047bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5048 safi_t safi, struct bgp_aggregate *aggregate)
5049{
5050 struct bgp_table *table;
5051 struct bgp_node *top;
5052 struct bgp_node *rn;
5053 struct bgp_info *ri;
5054 unsigned long match;
5055
5056 table = bgp->rib[afi][safi];
5057
5058 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5059 return;
5060 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5061 return;
5062
5063 /* If routes exists below this node, generate aggregate routes. */
5064 top = bgp_node_get (table, p);
5065 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5066 if (rn->p.prefixlen > p->prefixlen)
5067 {
5068 match = 0;
5069
5070 for (ri = rn->info; ri; ri = ri->next)
5071 {
5072 if (BGP_INFO_HOLDDOWN (ri))
5073 continue;
5074
5075 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5076 {
fb982c25 5077 if (aggregate->summary_only && ri->extra)
718e3744 5078 {
fb982c25 5079 ri->extra->suppress--;
718e3744 5080
fb982c25 5081 if (ri->extra->suppress == 0)
718e3744 5082 {
1a392d46 5083 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5084 match++;
5085 }
5086 }
5087 aggregate->count--;
5088 }
5089 }
5090
fb982c25 5091 /* If this node was suppressed, process the change. */
718e3744 5092 if (match)
5093 bgp_process (bgp, rn, afi, safi);
5094 }
5095 bgp_unlock_node (top);
5096
5097 /* Delete aggregate route from BGP table. */
5098 rn = bgp_node_get (table, p);
5099
5100 for (ri = rn->info; ri; ri = ri->next)
5101 if (ri->peer == bgp->peer_self
5102 && ri->type == ZEBRA_ROUTE_BGP
5103 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5104 break;
5105
5106 /* Withdraw static BGP route from routing table. */
5107 if (ri)
5108 {
718e3744 5109 bgp_info_delete (rn, ri);
1a392d46 5110 bgp_process (bgp, rn, afi, safi);
718e3744 5111 }
5112
5113 /* Unlock bgp_node_lookup. */
5114 bgp_unlock_node (rn);
5115}
5116
5117/* Aggregate route attribute. */
5118#define AGGREGATE_SUMMARY_ONLY 1
5119#define AGGREGATE_AS_SET 1
5120
94f2b392 5121static int
f6269b4f
RB
5122bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5123 afi_t afi, safi_t safi)
718e3744 5124{
5125 int ret;
5126 struct prefix p;
5127 struct bgp_node *rn;
5128 struct bgp *bgp;
5129 struct bgp_aggregate *aggregate;
5130
5131 /* Convert string to prefix structure. */
5132 ret = str2prefix (prefix_str, &p);
5133 if (!ret)
5134 {
5135 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5136 return CMD_WARNING;
5137 }
5138 apply_mask (&p);
5139
5140 /* Get BGP structure. */
5141 bgp = vty->index;
5142
5143 /* Old configuration check. */
f6269b4f
RB
5144 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5145 if (! rn)
718e3744 5146 {
f6269b4f
RB
5147 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5148 VTY_NEWLINE);
718e3744 5149 return CMD_WARNING;
5150 }
5151
f6269b4f
RB
5152 aggregate = rn->info;
5153 if (aggregate->safi & SAFI_UNICAST)
5154 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5155 if (aggregate->safi & SAFI_MULTICAST)
5156 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 5157
f6269b4f
RB
5158 /* Unlock aggregate address configuration. */
5159 rn->info = NULL;
5160 bgp_aggregate_free (aggregate);
5161 bgp_unlock_node (rn);
5162 bgp_unlock_node (rn);
718e3744 5163
5164 return CMD_SUCCESS;
5165}
5166
94f2b392 5167static int
f6269b4f
RB
5168bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5169 afi_t afi, safi_t safi,
5170 u_char summary_only, u_char as_set)
718e3744 5171{
5172 int ret;
5173 struct prefix p;
5174 struct bgp_node *rn;
5175 struct bgp *bgp;
5176 struct bgp_aggregate *aggregate;
5177
5178 /* Convert string to prefix structure. */
5179 ret = str2prefix (prefix_str, &p);
5180 if (!ret)
5181 {
5182 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5183 return CMD_WARNING;
5184 }
5185 apply_mask (&p);
5186
5187 /* Get BGP structure. */
5188 bgp = vty->index;
5189
5190 /* Old configuration check. */
f6269b4f
RB
5191 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5192
5193 if (rn->info)
718e3744 5194 {
f6269b4f 5195 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
368473f6 5196 /* try to remove the old entry */
f6269b4f
RB
5197 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5198 if (ret)
5199 {
368473f6
RB
5200 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5201 bgp_unlock_node (rn);
f6269b4f
RB
5202 return CMD_WARNING;
5203 }
718e3744 5204 }
5205
f6269b4f
RB
5206 /* Make aggregate address structure. */
5207 aggregate = bgp_aggregate_new ();
5208 aggregate->summary_only = summary_only;
5209 aggregate->as_set = as_set;
5210 aggregate->safi = safi;
5211 rn->info = aggregate;
718e3744 5212
f6269b4f
RB
5213 /* Aggregate address insert into BGP routing table. */
5214 if (safi & SAFI_UNICAST)
5215 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5216 if (safi & SAFI_MULTICAST)
5217 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 5218
5219 return CMD_SUCCESS;
5220}
5221
5222DEFUN (aggregate_address,
5223 aggregate_address_cmd,
5224 "aggregate-address A.B.C.D/M",
5225 "Configure BGP aggregate entries\n"
5226 "Aggregate prefix\n")
5227{
4dcadbef 5228 return bgp_aggregate_set (vty, argv[1]->arg, AFI_IP, bgp_node_safi (vty), 0, 0);
718e3744 5229}
5230
5231DEFUN (aggregate_address_mask,
5232 aggregate_address_mask_cmd,
5233 "aggregate-address A.B.C.D A.B.C.D",
5234 "Configure BGP aggregate entries\n"
5235 "Aggregate address\n"
5236 "Aggregate mask\n")
5237{
5238 int ret;
5239 char prefix_str[BUFSIZ];
5240
4dcadbef 5241 ret = netmask_str2prefix_str (argv[1]->arg, argv[2]->arg, prefix_str);
718e3744 5242
5243 if (! ret)
5244 {
5245 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5246 return CMD_WARNING;
5247 }
5248
5249 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5250 0, 0);
5251}
5252
5253DEFUN (aggregate_address_summary_only,
5254 aggregate_address_summary_only_cmd,
5255 "aggregate-address A.B.C.D/M summary-only",
5256 "Configure BGP aggregate entries\n"
5257 "Aggregate prefix\n"
5258 "Filter more specific routes from updates\n")
5259{
4dcadbef 5260 return bgp_aggregate_set (vty, argv[1]->arg, AFI_IP, bgp_node_safi (vty),
718e3744 5261 AGGREGATE_SUMMARY_ONLY, 0);
5262}
5263
5264DEFUN (aggregate_address_mask_summary_only,
5265 aggregate_address_mask_summary_only_cmd,
5266 "aggregate-address A.B.C.D A.B.C.D summary-only",
5267 "Configure BGP aggregate entries\n"
5268 "Aggregate address\n"
5269 "Aggregate mask\n"
5270 "Filter more specific routes from updates\n")
5271{
5272 int ret;
5273 char prefix_str[BUFSIZ];
5274
4dcadbef 5275 ret = netmask_str2prefix_str (argv[1]->arg, argv[2]->arg, prefix_str);
718e3744 5276
5277 if (! ret)
5278 {
5279 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5280 return CMD_WARNING;
5281 }
5282
5283 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5284 AGGREGATE_SUMMARY_ONLY, 0);
5285}
5286
5287DEFUN (aggregate_address_as_set,
5288 aggregate_address_as_set_cmd,
5289 "aggregate-address A.B.C.D/M as-set",
5290 "Configure BGP aggregate entries\n"
5291 "Aggregate prefix\n"
5292 "Generate AS set path information\n")
5293{
4dcadbef 5294 return bgp_aggregate_set (vty, argv[1]->arg, AFI_IP, bgp_node_safi (vty),
718e3744 5295 0, AGGREGATE_AS_SET);
5296}
5297
5298DEFUN (aggregate_address_mask_as_set,
5299 aggregate_address_mask_as_set_cmd,
5300 "aggregate-address A.B.C.D A.B.C.D as-set",
5301 "Configure BGP aggregate entries\n"
5302 "Aggregate address\n"
5303 "Aggregate mask\n"
5304 "Generate AS set path information\n")
5305{
5306 int ret;
5307 char prefix_str[BUFSIZ];
5308
4dcadbef 5309 ret = netmask_str2prefix_str (argv[1]->arg, argv[2]->arg, prefix_str);
718e3744 5310
5311 if (! ret)
5312 {
5313 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5314 return CMD_WARNING;
5315 }
5316
5317 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5318 0, AGGREGATE_AS_SET);
5319}
5320
5321
f412b39a
DW
5322/*
5323 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
5324 * "aggregate-address A.B.C.D/M summary-only as-set",
5325 * "Configure BGP aggregate entries\n"
5326 * "Aggregate prefix\n"
5327 * "Filter more specific routes from updates\n"
5328 * "Generate AS set path information\n"
5329 *
5330 */
718e3744 5331DEFUN (aggregate_address_as_set_summary,
5332 aggregate_address_as_set_summary_cmd,
5333 "aggregate-address A.B.C.D/M as-set summary-only",
5334 "Configure BGP aggregate entries\n"
5335 "Aggregate prefix\n"
5336 "Generate AS set path information\n"
5337 "Filter more specific routes from updates\n")
5338{
4dcadbef 5339 return bgp_aggregate_set (vty, argv[1]->arg, AFI_IP, bgp_node_safi (vty),
718e3744 5340 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5341}
5342
718e3744 5343
f412b39a
DW
5344/*
5345 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
5346 * "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5347 * "Configure BGP aggregate entries\n"
5348 * "Aggregate address\n"
5349 * "Aggregate mask\n"
5350 * "Filter more specific routes from updates\n"
5351 * "Generate AS set path information\n"
5352 *
5353 */
718e3744 5354DEFUN (aggregate_address_mask_as_set_summary,
5355 aggregate_address_mask_as_set_summary_cmd,
5356 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5357 "Configure BGP aggregate entries\n"
5358 "Aggregate address\n"
5359 "Aggregate mask\n"
5360 "Generate AS set path information\n"
5361 "Filter more specific routes from updates\n")
5362{
5363 int ret;
5364 char prefix_str[BUFSIZ];
5365
4dcadbef 5366 ret = netmask_str2prefix_str (argv[1]->arg, argv[2]->arg, prefix_str);
718e3744 5367
5368 if (! ret)
5369 {
5370 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5371 return CMD_WARNING;
5372 }
5373
5374 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5375 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5376}
5377
718e3744 5378
f412b39a
DW
5379/*
5380 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
5381 * "no aggregate-address A.B.C.D/M summary-only",
5382 * NO_STR
5383 * "Configure BGP aggregate entries\n"
5384 * "Aggregate prefix\n"
5385 * "Filter more specific routes from updates\n"
5386 *
5387 * "no aggregate-address A.B.C.D/M as-set summary-only",
5388 * NO_STR
5389 * "Configure BGP aggregate entries\n"
5390 * "Aggregate prefix\n"
5391 * "Generate AS set path information\n"
5392 * "Filter more specific routes from updates\n"
5393 *
5394 * "no aggregate-address A.B.C.D/M summary-only as-set",
5395 * NO_STR
5396 * "Configure BGP aggregate entries\n"
5397 * "Aggregate prefix\n"
5398 * "Filter more specific routes from updates\n"
5399 * "Generate AS set path information\n"
5400 *
5401 * "no aggregate-address A.B.C.D/M as-set",
5402 * NO_STR
5403 * "Configure BGP aggregate entries\n"
5404 * "Aggregate prefix\n"
5405 * "Generate AS set path information\n"
5406 *
5407 */
718e3744 5408DEFUN (no_aggregate_address,
5409 no_aggregate_address_cmd,
5410 "no aggregate-address A.B.C.D/M",
5411 NO_STR
5412 "Configure BGP aggregate entries\n"
5413 "Aggregate prefix\n")
5414{
4dcadbef 5415 return bgp_aggregate_unset (vty, argv[2]->arg, AFI_IP, bgp_node_safi (vty));
718e3744 5416}
5417
718e3744 5418
718e3744 5419
718e3744 5420
718e3744 5421
f412b39a
DW
5422/*
5423 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
5424 * "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5425 * NO_STR
5426 * "Configure BGP aggregate entries\n"
5427 * "Aggregate address\n"
5428 * "Aggregate mask\n"
5429 * "Filter more specific routes from updates\n"
5430 * "Generate AS set path information\n"
5431 *
5432 * "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5433 * NO_STR
5434 * "Configure BGP aggregate entries\n"
5435 * "Aggregate address\n"
5436 * "Aggregate mask\n"
5437 * "Generate AS set path information\n"
5438 * "Filter more specific routes from updates\n"
5439 *
5440 * "no aggregate-address A.B.C.D A.B.C.D summary-only",
5441 * NO_STR
5442 * "Configure BGP aggregate entries\n"
5443 * "Aggregate address\n"
5444 * "Aggregate mask\n"
5445 * "Filter more specific routes from updates\n"
5446 *
5447 * "no aggregate-address A.B.C.D A.B.C.D as-set",
5448 * NO_STR
5449 * "Configure BGP aggregate entries\n"
5450 * "Aggregate address\n"
5451 * "Aggregate mask\n"
5452 * "Generate AS set path information\n"
5453 *
5454 */
718e3744 5455DEFUN (no_aggregate_address_mask,
5456 no_aggregate_address_mask_cmd,
5457 "no aggregate-address A.B.C.D A.B.C.D",
5458 NO_STR
5459 "Configure BGP aggregate entries\n"
5460 "Aggregate address\n"
5461 "Aggregate mask\n")
5462{
5463 int ret;
5464 char prefix_str[BUFSIZ];
5465
4dcadbef 5466 ret = netmask_str2prefix_str (argv[2]->arg, argv[3]->arg, prefix_str);
718e3744 5467
5468 if (! ret)
5469 {
5470 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5471 return CMD_WARNING;
5472 }
5473
5474 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5475}
5476
718e3744 5477
718e3744 5478
718e3744 5479
718e3744 5480
5481#ifdef HAVE_IPV6
f412b39a
DW
5482/*
5483 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
5484 * "ipv6 bgp aggregate-address X:X::X:X/M",
5485 * IPV6_STR
5486 * BGP_STR
5487 * "Configure BGP aggregate entries\n"
5488 * "Aggregate prefix\n"
5489 *
5490 */
718e3744 5491DEFUN (ipv6_aggregate_address,
5492 ipv6_aggregate_address_cmd,
5493 "aggregate-address X:X::X:X/M",
5494 "Configure BGP aggregate entries\n"
5495 "Aggregate prefix\n")
5496{
4dcadbef 5497 return bgp_aggregate_set (vty, argv[1]->arg, AFI_IP6, SAFI_UNICAST, 0, 0);
718e3744 5498}
5499
f412b39a
DW
5500/*
5501 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
5502 * "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5503 * IPV6_STR
5504 * BGP_STR
5505 * "Configure BGP aggregate entries\n"
5506 * "Aggregate prefix\n"
5507 * "Filter more specific routes from updates\n"
5508 *
5509 */
718e3744 5510DEFUN (ipv6_aggregate_address_summary_only,
5511 ipv6_aggregate_address_summary_only_cmd,
5512 "aggregate-address X:X::X:X/M summary-only",
5513 "Configure BGP aggregate entries\n"
5514 "Aggregate prefix\n"
5515 "Filter more specific routes from updates\n")
5516{
4dcadbef 5517 return bgp_aggregate_set (vty, argv[1]->arg, AFI_IP6, SAFI_UNICAST,
718e3744 5518 AGGREGATE_SUMMARY_ONLY, 0);
5519}
5520
f412b39a
DW
5521/*
5522 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
5523 * "no ipv6 bgp aggregate-address X:X::X:X/M",
5524 * NO_STR
5525 * IPV6_STR
5526 * BGP_STR
5527 * "Configure BGP aggregate entries\n"
5528 * "Aggregate prefix\n"
5529 *
5530 */
718e3744 5531DEFUN (no_ipv6_aggregate_address,
5532 no_ipv6_aggregate_address_cmd,
5533 "no aggregate-address X:X::X:X/M",
5534 NO_STR
5535 "Configure BGP aggregate entries\n"
5536 "Aggregate prefix\n")
5537{
4dcadbef 5538 return bgp_aggregate_unset (vty, argv[2]->arg, AFI_IP6, SAFI_UNICAST);
718e3744 5539}
5540
f412b39a
DW
5541/*
5542 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
5543 * "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5544 * NO_STR
5545 * IPV6_STR
5546 * BGP_STR
5547 * "Configure BGP aggregate entries\n"
5548 * "Aggregate prefix\n"
5549 * "Filter more specific routes from updates\n"
5550 *
5551 */
718e3744 5552DEFUN (no_ipv6_aggregate_address_summary_only,
5553 no_ipv6_aggregate_address_summary_only_cmd,
5554 "no aggregate-address X:X::X:X/M summary-only",
5555 NO_STR
5556 "Configure BGP aggregate entries\n"
5557 "Aggregate prefix\n"
5558 "Filter more specific routes from updates\n")
5559{
4dcadbef 5560 return bgp_aggregate_unset (vty, argv[2]->arg, AFI_IP6, SAFI_UNICAST);
718e3744 5561}
5562
718e3744 5563
718e3744 5564
718e3744 5565
718e3744 5566#endif /* HAVE_IPV6 */
6b0655a2 5567
718e3744 5568/* Redistribute route treatment. */
5569void
6aeb9e78 5570bgp_redistribute_add (struct bgp *bgp, struct prefix *p, const struct in_addr *nexthop,
bc413143 5571 const struct in6_addr *nexthop6, unsigned int ifindex,
7c8ff89e 5572 u_int32_t metric, u_char type, u_short instance, u_short tag)
718e3744 5573{
718e3744 5574 struct bgp_info *new;
5575 struct bgp_info *bi;
5576 struct bgp_info info;
5577 struct bgp_node *bn;
e16a4133 5578 struct attr attr;
718e3744 5579 struct attr *new_attr;
5580 afi_t afi;
5581 int ret;
7c8ff89e 5582 struct bgp_redist *red;
718e3744 5583
5584 /* Make default attribute. */
5585 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5586 if (nexthop)
5587 attr.nexthop = *nexthop;
bc413143 5588 attr.nh_ifindex = ifindex;
718e3744 5589
f04a80a5
SH
5590#ifdef HAVE_IPV6
5591 if (nexthop6)
5592 {
5593 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5594 extra->mp_nexthop_global = *nexthop6;
801a9bcc 5595 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
f04a80a5
SH
5596 }
5597#endif
5598
718e3744 5599 attr.med = metric;
5600 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
0d9551dc 5601 attr.extra->tag = tag;
718e3744 5602
6aeb9e78
DS
5603 afi = family2afi (p->family);
5604
5605 red = bgp_redist_lookup(bgp, afi, type, instance);
5606 if (red)
718e3744 5607 {
6aeb9e78
DS
5608 struct attr attr_new;
5609 struct attr_extra extra_new;
718e3744 5610
6aeb9e78
DS
5611 /* Copy attribute for modification. */
5612 attr_new.extra = &extra_new;
5613 bgp_attr_dup (&attr_new, &attr);
558d1fec 5614
6aeb9e78
DS
5615 if (red->redist_metric_flag)
5616 attr_new.med = red->redist_metric;
718e3744 5617
6aeb9e78
DS
5618 /* Apply route-map. */
5619 if (red->rmap.name)
5620 {
5621 info.peer = bgp->peer_self;
5622 info.attr = &attr_new;
718e3744 5623
6aeb9e78 5624 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
718e3744 5625
6aeb9e78 5626 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
fee0f4c6 5627
6aeb9e78 5628 bgp->peer_self->rmap_type = 0;
fee0f4c6 5629
6aeb9e78
DS
5630 if (ret == RMAP_DENYMATCH)
5631 {
5632 /* Free uninterned attribute. */
5633 bgp_attr_flush (&attr_new);
5634
5635 /* Unintern original. */
5636 aspath_unintern (&attr.aspath);
5637 bgp_attr_extra_free (&attr);
5638 bgp_redistribute_delete (bgp, p, type, instance);
5639 return;
5640 }
5641 }
fee0f4c6 5642
6aeb9e78
DS
5643 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5644 afi, SAFI_UNICAST, p, NULL);
718e3744 5645
6aeb9e78 5646 new_attr = bgp_attr_intern (&attr_new);
558d1fec 5647
6aeb9e78
DS
5648 for (bi = bn->info; bi; bi = bi->next)
5649 if (bi->peer == bgp->peer_self
5650 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5651 break;
5652
5653 if (bi)
5654 {
5655 /* Ensure the (source route) type is updated. */
5656 bi->type = type;
5657 if (attrhash_cmp (bi->attr, new_attr) &&
5658 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5659 {
5660 bgp_attr_unintern (&new_attr);
5661 aspath_unintern (&attr.aspath);
5662 bgp_attr_extra_free (&attr);
5663 bgp_unlock_node (bn);
5664 return;
5665 }
5666 else
5667 {
5668 /* The attribute is changed. */
5669 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
718e3744 5670
6aeb9e78
DS
5671 /* Rewrite BGP route information. */
5672 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5673 bgp_info_restore(bn, bi);
5674 else
5675 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5676 bgp_attr_unintern (&bi->attr);
5677 bi->attr = new_attr;
5678 bi->uptime = bgp_clock ();
5679
5680 /* Process change. */
5681 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5682 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5683 bgp_unlock_node (bn);
5684 aspath_unintern (&attr.aspath);
5685 bgp_attr_extra_free (&attr);
5686 return;
5687 }
5688 }
718e3744 5689
6aeb9e78
DS
5690 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
5691 new_attr, bn);
5692 SET_FLAG (new->flags, BGP_INFO_VALID);
5693
5694 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5695 bgp_info_add (bn, new);
5696 bgp_unlock_node (bn);
5697 bgp_process (bgp, bn, afi, SAFI_UNICAST);
718e3744 5698 }
5699
5700 /* Unintern original. */
f6f434b2 5701 aspath_unintern (&attr.aspath);
fb982c25 5702 bgp_attr_extra_free (&attr);
718e3744 5703}
5704
5705void
6aeb9e78 5706bgp_redistribute_delete (struct bgp *bgp, struct prefix *p, u_char type, u_short instance)
718e3744 5707{
718e3744 5708 afi_t afi;
5709 struct bgp_node *rn;
5710 struct bgp_info *ri;
7c8ff89e 5711 struct bgp_redist *red;
718e3744 5712
6aeb9e78 5713 afi = family2afi (p->family);
718e3744 5714
6aeb9e78
DS
5715 red = bgp_redist_lookup(bgp, afi, type, instance);
5716 if (red)
5717 {
5718 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
718e3744 5719
6aeb9e78
DS
5720 for (ri = rn->info; ri; ri = ri->next)
5721 if (ri->peer == bgp->peer_self
5722 && ri->type == type)
5723 break;
718e3744 5724
6aeb9e78
DS
5725 if (ri)
5726 {
5727 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5728 bgp_info_delete (rn, ri);
5729 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5730 }
5731 bgp_unlock_node (rn);
718e3744 5732 }
5733}
5734
5735/* Withdraw specified route type's route. */
5736void
7c8ff89e 5737bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
718e3744 5738{
5739 struct bgp_node *rn;
5740 struct bgp_info *ri;
5741 struct bgp_table *table;
5742
5743 table = bgp->rib[afi][SAFI_UNICAST];
5744
5745 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5746 {
5747 for (ri = rn->info; ri; ri = ri->next)
5748 if (ri->peer == bgp->peer_self
7c8ff89e
DS
5749 && ri->type == type
5750 && ri->instance == instance)
718e3744 5751 break;
5752
5753 if (ri)
5754 {
5755 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
718e3744 5756 bgp_info_delete (rn, ri);
1a392d46 5757 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 5758 }
5759 }
5760}
6b0655a2 5761
718e3744 5762/* Static function to display route. */
94f2b392 5763static void
718e3744 5764route_vty_out_route (struct prefix *p, struct vty *vty)
5765{
5766 int len;
5767 u_int32_t destination;
5768 char buf[BUFSIZ];
5769
5770 if (p->family == AF_INET)
5771 {
5772 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5773 destination = ntohl (p->u.prefix4.s_addr);
5774
5775 if ((IN_CLASSC (destination) && p->prefixlen == 24)
856ca177
MS
5776 || (IN_CLASSB (destination) && p->prefixlen == 16)
5777 || (IN_CLASSA (destination) && p->prefixlen == 8)
5778 || p->u.prefix4.s_addr == 0)
5779 {
5780 /* When mask is natural, mask is not displayed. */
5781 }
718e3744 5782 else
856ca177 5783 len += vty_out (vty, "/%d", p->prefixlen);
718e3744 5784 }
5785 else
5786 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5787 p->prefixlen);
5788
5789 len = 17 - len;
5790 if (len < 1)
5791 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5792 else
5793 vty_out (vty, "%*s", len, " ");
5794}
5795
718e3744 5796enum bgp_display_type
5797{
5798 normal_list,
5799};
5800
b40d939b 5801/* Print the short form route status for a bgp_info */
5802static void
b05a1c8b
DS
5803route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
5804 json_object *json_path)
718e3744 5805{
b05a1c8b
DS
5806 if (json_path)
5807 {
b05a1c8b
DS
5808
5809 /* Route status display. */
5810 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
f1aa5d8a 5811 json_object_boolean_true_add(json_path, "removed");
b05a1c8b
DS
5812
5813 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
f1aa5d8a 5814 json_object_boolean_true_add(json_path, "stale");
b05a1c8b
DS
5815
5816 if (binfo->extra && binfo->extra->suppress)
f1aa5d8a 5817 json_object_boolean_true_add(json_path, "suppressed");
b05a1c8b
DS
5818
5819 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5820 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
f1aa5d8a 5821 json_object_boolean_true_add(json_path, "valid");
b05a1c8b
DS
5822
5823 /* Selected */
5824 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
f1aa5d8a 5825 json_object_boolean_true_add(json_path, "history");
b05a1c8b
DS
5826
5827 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
f1aa5d8a 5828 json_object_boolean_true_add(json_path, "damped");
b05a1c8b
DS
5829
5830 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
f1aa5d8a 5831 json_object_boolean_true_add(json_path, "bestpath");
b05a1c8b
DS
5832
5833 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
f1aa5d8a 5834 json_object_boolean_true_add(json_path, "multipath");
b05a1c8b
DS
5835
5836 /* Internal route. */
5837 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
62d6dca0 5838 json_object_string_add(json_path, "pathFrom", "internal");
b05a1c8b 5839 else
62d6dca0 5840 json_object_string_add(json_path, "pathFrom", "external");
b05a1c8b
DS
5841
5842 return;
5843 }
5844
b40d939b 5845 /* Route status display. */
5846 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5847 vty_out (vty, "R");
5848 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
93406d87 5849 vty_out (vty, "S");
fb982c25 5850 else if (binfo->extra && binfo->extra->suppress)
718e3744 5851 vty_out (vty, "s");
31eba040
DS
5852 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5853 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
718e3744 5854 vty_out (vty, "*");
5855 else
5856 vty_out (vty, " ");
5857
5858 /* Selected */
5859 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5860 vty_out (vty, "h");
5861 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5862 vty_out (vty, "d");
5863 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5864 vty_out (vty, ">");
b366b518
BB
5865 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5866 vty_out (vty, "=");
718e3744 5867 else
5868 vty_out (vty, " ");
5869
5870 /* Internal route. */
b05a1c8b
DS
5871 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5872 vty_out (vty, "i");
5873 else
5874 vty_out (vty, " ");
b40d939b 5875}
5876
5877/* called from terminal list command */
5878void
5879route_vty_out (struct vty *vty, struct prefix *p,
b05a1c8b
DS
5880 struct bgp_info *binfo, int display, safi_t safi,
5881 json_object *json_paths)
b40d939b 5882{
5883 struct attr *attr;
f1aa5d8a
DS
5884 json_object *json_path = NULL;
5885 json_object *json_nexthops = NULL;
5886 json_object *json_nexthop_global = NULL;
5887 json_object *json_nexthop_ll = NULL;
47fc97cc 5888
b05a1c8b
DS
5889 if (json_paths)
5890 json_path = json_object_new_object();
b05a1c8b
DS
5891
5892 /* short status lead text */
5893 route_vty_short_status_out (vty, binfo, json_path);
718e3744 5894
b05a1c8b
DS
5895 if (!json_paths)
5896 {
5897 /* print prefix and mask */
5898 if (! display)
5899 route_vty_out_route (p, vty);
5900 else
5901 vty_out (vty, "%*s", 17, " ");
5902 }
47fc97cc 5903
718e3744 5904 /* Print attribute */
5905 attr = binfo->attr;
5906 if (attr)
5907 {
587ff0fd
LB
5908 /*
5909 * For ENCAP routes, nexthop address family is not
5910 * neccessarily the same as the prefix address family.
5911 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
5912 */
5913 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN))
5914 {
5915 if (attr->extra)
5916 {
5917 char buf[BUFSIZ];
5918 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
b05a1c8b 5919
587ff0fd
LB
5920 switch (af)
5921 {
5922 case AF_INET:
5923 vty_out (vty, "%s", inet_ntop(af,
5924 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
5925 break;
5926#if HAVE_IPV6
5927 case AF_INET6:
5928 vty_out (vty, "%s", inet_ntop(af,
5929 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
5930 break;
5931#endif
5932 default:
5933 vty_out(vty, "?");
5934 break;
5935 }
5936 }
5937 else
5938 vty_out(vty, "?");
5939 }
b05a1c8b 5940 /* IPv4 Next Hop */
587ff0fd 5941 else if (p->family == AF_INET || !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
718e3744 5942 {
b05a1c8b
DS
5943 if (json_paths)
5944 {
f1aa5d8a
DS
5945 json_nexthop_global = json_object_new_object();
5946
b05a1c8b 5947 if (safi == SAFI_MPLS_VPN)
f1aa5d8a 5948 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
b05a1c8b 5949 else
f1aa5d8a
DS
5950 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
5951
5952 json_object_string_add(json_nexthop_global, "afi", "ipv4");
5953 json_object_boolean_true_add(json_nexthop_global, "used");
b05a1c8b
DS
5954 }
5955 else
5956 {
5957 if (safi == SAFI_MPLS_VPN)
5958 vty_out (vty, "%-16s",
5959 inet_ntoa (attr->extra->mp_nexthop_global_in));
5960 else
5961 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5962 }
718e3744 5963 }
161995ea 5964
b05a1c8b 5965 /* IPv6 Next Hop */
8a92a8a0 5966 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
718e3744 5967 {
5968 int len;
5969 char buf[BUFSIZ];
5970
b05a1c8b
DS
5971 if (json_paths)
5972 {
f1aa5d8a
DS
5973 json_nexthop_global = json_object_new_object();
5974 json_object_string_add(json_nexthop_global, "ip",
5975 inet_ntop (AF_INET6,
5976 &attr->extra->mp_nexthop_global,
5977 buf, BUFSIZ));
5978 json_object_string_add(json_nexthop_global, "afi", "ipv6");
5979 json_object_string_add(json_nexthop_global, "scope", "global");
5980
5981 /* We display both LL & GL if both have been received */
5982 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
5983 {
5984 json_nexthop_ll = json_object_new_object();
5985 json_object_string_add(json_nexthop_ll, "ip",
5986 inet_ntop (AF_INET6,
5987 &attr->extra->mp_nexthop_local,
5988 buf, BUFSIZ));
5989 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
5990 json_object_string_add(json_nexthop_ll, "scope", "link-local");
5991
161995ea
DS
5992 if ((IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global,
5993 &attr->extra->mp_nexthop_local) != 0) &&
5994 !attr->extra->mp_nexthop_prefer_global)
f1aa5d8a
DS
5995 json_object_boolean_true_add(json_nexthop_ll, "used");
5996 else
5997 json_object_boolean_true_add(json_nexthop_global, "used");
5998 }
5999 else
6000 json_object_boolean_true_add(json_nexthop_global, "used");
b05a1c8b
DS
6001 }
6002 else
6003 {
161995ea
DS
6004 /* Display LL if LL/Global both in table unless prefer-global is set */
6005 if (((attr->extra->mp_nexthop_len == 32) &&
6006 !attr->extra->mp_nexthop_prefer_global) ||
6007 (binfo->peer->conf_if))
433e8b67
DS
6008 {
6009 if (binfo->peer->conf_if)
6010 {
6011 len = vty_out (vty, "%s",
6012 binfo->peer->conf_if);
6013 len = 7 - len; /* len of IPv6 addr + max len of def ifname */
6014
6015 if (len < 1)
6016 vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " ");
6017 else
6018 vty_out (vty, "%*s", len, " ");
6019 }
6020 else
6021 {
6022 len = vty_out (vty, "%s",
6023 inet_ntop (AF_INET6,
6024 &attr->extra->mp_nexthop_local,
6025 buf, BUFSIZ));
6026 len = 16 - len;
6027
6028 if (len < 1)
6029 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6030 else
6031 vty_out (vty, "%*s", len, " ");
6032 }
6033 }
6034 else
6035 {
6036 len = vty_out (vty, "%s",
6037 inet_ntop (AF_INET6,
6038 &attr->extra->mp_nexthop_global,
6039 buf, BUFSIZ));
6040 len = 16 - len;
6041
6042 if (len < 1)
6043 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6044 else
6045 vty_out (vty, "%*s", len, " ");
6046 }
b05a1c8b 6047 }
718e3744 6048 }
718e3744 6049
b05a1c8b 6050 /* MED/Metric */
718e3744 6051 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b 6052 if (json_paths)
f1aa5d8a 6053 json_object_int_add(json_path, "med", attr->med);
b05a1c8b
DS
6054 else
6055 vty_out (vty, "%10u", attr->med);
718e3744 6056 else
b05a1c8b
DS
6057 if (!json_paths)
6058 vty_out (vty, " ");
47fc97cc 6059
b05a1c8b 6060 /* Local Pref */
718e3744 6061 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
b05a1c8b 6062 if (json_paths)
f1aa5d8a 6063 json_object_int_add(json_path, "localpref", attr->local_pref);
b05a1c8b
DS
6064 else
6065 vty_out (vty, "%7u", attr->local_pref);
718e3744 6066 else
b05a1c8b
DS
6067 if (!json_paths)
6068 vty_out (vty, " ");
718e3744 6069
b05a1c8b
DS
6070 if (json_paths)
6071 {
6072 if (attr->extra)
f1aa5d8a 6073 json_object_int_add(json_path, "weight", attr->extra->weight);
b05a1c8b 6074 else
f1aa5d8a 6075 json_object_int_add(json_path, "weight", 0);
b05a1c8b
DS
6076 }
6077 else
6078 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
47fc97cc 6079
39e871e6
ST
6080 if (json_paths) {
6081 char buf[BUFSIZ];
6082 json_object_string_add(json_path, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6083 }
6084
b2518c1e
PJ
6085 /* Print aspath */
6086 if (attr->aspath)
b05a1c8b
DS
6087 {
6088 if (json_paths)
f1aa5d8a 6089 json_object_string_add(json_path, "aspath", attr->aspath->str);
b05a1c8b 6090 else
f1aa5d8a 6091 aspath_print_vty (vty, "%s", attr->aspath, " ");
b05a1c8b 6092 }
47fc97cc 6093
b2518c1e 6094 /* Print origin */
b05a1c8b 6095 if (json_paths)
f1aa5d8a 6096 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
b05a1c8b
DS
6097 else
6098 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 6099 }
856ca177
MS
6100 else
6101 {
6102 if (json_paths)
6103 json_object_string_add(json_path, "alert", "No attributes");
6104 else
6105 vty_out (vty, "No attributes to print%s", VTY_NEWLINE);
6106 }
b05a1c8b
DS
6107
6108 if (json_paths)
f1aa5d8a
DS
6109 {
6110 if (json_nexthop_global || json_nexthop_ll)
6111 {
6112 json_nexthops = json_object_new_array();
6113
6114 if (json_nexthop_global)
6115 json_object_array_add(json_nexthops, json_nexthop_global);
6116
6117 if (json_nexthop_ll)
6118 json_object_array_add(json_nexthops, json_nexthop_ll);
6119
6120 json_object_object_add(json_path, "nexthops", json_nexthops);
6121 }
6122
6123 json_object_array_add(json_paths, json_path);
6124 }
b05a1c8b
DS
6125 else
6126 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6127}
6128
6129/* called from terminal list command */
6130void
856ca177
MS
6131route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi,
6132 u_char use_json, json_object *json_ar)
718e3744 6133{
856ca177
MS
6134 json_object *json_status = NULL;
6135 json_object *json_net = NULL;
6136 char buff[BUFSIZ];
718e3744 6137 /* Route status display. */
856ca177
MS
6138 if (use_json)
6139 {
6140 json_status = json_object_new_object();
6141 json_net = json_object_new_object();
6142 }
6143 else
6144 {
6145 vty_out (vty, "*");
6146 vty_out (vty, ">");
6147 vty_out (vty, " ");
6148 }
718e3744 6149
6150 /* print prefix and mask */
856ca177
MS
6151 if (use_json)
6152 json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ));
6153 else
6154 route_vty_out_route (p, vty);
718e3744 6155
6156 /* Print attribute */
6157 if (attr)
6158 {
856ca177 6159 if (use_json)
718e3744 6160 {
587ff0fd
LB
6161 if (p->family == AF_INET &&
6162 (safi == SAFI_MPLS_VPN ||
6163 safi == SAFI_ENCAP ||
6164 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
856ca177 6165 {
587ff0fd 6166 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
856ca177
MS
6167 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in));
6168 else
6169 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop));
6170 }
6171#ifdef HAVE_IPV6
6172 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6173 {
6174 char buf[BUFSIZ];
718e3744 6175
856ca177
MS
6176 json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6177 buf, BUFSIZ));
6178 }
6179#endif /* HAVE_IPV6 */
6180
6181 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6182 json_object_int_add(json_net, "metric", attr->med);
6183
6184 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6185 json_object_int_add(json_net, "localPref", attr->local_pref);
6186
6187 if (attr->extra)
6188 json_object_int_add(json_net, "weight", attr->extra->weight);
718e3744 6189 else
856ca177
MS
6190 json_object_int_add(json_net, "weight", 0);
6191
6192 /* Print aspath */
6193 if (attr->aspath)
6194 json_object_string_add(json_net, "asPath", attr->aspath->str);
6195
6196 /* Print origin */
6197 json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]);
718e3744 6198 }
856ca177
MS
6199 else
6200 {
587ff0fd
LB
6201 if (p->family == AF_INET &&
6202 (safi == SAFI_MPLS_VPN ||
6203 safi == SAFI_ENCAP ||
6204 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
856ca177 6205 {
587ff0fd 6206 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
856ca177
MS
6207 vty_out (vty, "%-16s",
6208 inet_ntoa (attr->extra->mp_nexthop_global_in));
6209 else
6210 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6211 }
6212#ifdef HAVE_IPV6
6213 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6214 {
6215 int len;
6216 char buf[BUFSIZ];
6217
6218 assert (attr->extra);
6219
6220 len = vty_out (vty, "%s",
6221 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6222 buf, BUFSIZ));
6223 len = 16 - len;
6224 if (len < 1)
6225 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6226 else
6227 vty_out (vty, "%*s", len, " ");
6228 }
718e3744 6229#endif /* HAVE_IPV6 */
856ca177
MS
6230 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6231 vty_out (vty, "%10u", attr->med);
6232 else
6233 vty_out (vty, " ");
718e3744 6234
856ca177
MS
6235 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6236 vty_out (vty, "%7u", attr->local_pref);
6237 else
6238 vty_out (vty, " ");
718e3744 6239
856ca177 6240 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
718e3744 6241
856ca177
MS
6242 /* Print aspath */
6243 if (attr->aspath)
6244 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 6245
856ca177
MS
6246 /* Print origin */
6247 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6248 }
6249 }
6250 if (use_json)
6251 {
6252 json_object_boolean_true_add(json_status, "*");
6253 json_object_boolean_true_add(json_status, ">");
6254 json_object_object_add(json_net, "appliedStatusSymbols", json_status);
6255 char buf_cut[BUFSIZ];
6256 json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net);
6257 }
6258 else
6259 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6260}
6261
5a646650 6262void
718e3744 6263route_vty_out_tag (struct vty *vty, struct prefix *p,
856ca177 6264 struct bgp_info *binfo, int display, safi_t safi, json_object *json)
718e3744 6265{
856ca177 6266 json_object *json_out = NULL;
718e3744 6267 struct attr *attr;
718e3744 6268 u_int32_t label = 0;
fb982c25
PJ
6269
6270 if (!binfo->extra)
6271 return;
856ca177
MS
6272
6273 if (json)
6274 json_out = json_object_new_object();
fb982c25 6275
b40d939b 6276 /* short status lead text */
856ca177 6277 route_vty_short_status_out (vty, binfo, json_out);
b40d939b 6278
718e3744 6279 /* print prefix and mask */
856ca177
MS
6280 if (json == NULL)
6281 {
6282 if (! display)
6283 route_vty_out_route (p, vty);
6284 else
6285 vty_out (vty, "%*s", 17, " ");
6286 }
718e3744 6287
6288 /* Print attribute */
6289 attr = binfo->attr;
6290 if (attr)
6291 {
8a92a8a0
DS
6292 if (p->family == AF_INET
6293 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 6294 {
587ff0fd 6295 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
856ca177
MS
6296 {
6297 if (json)
6298 json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in));
6299 else
6300 vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6301 }
718e3744 6302 else
856ca177
MS
6303 {
6304 if (json)
6305 json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop));
6306 else
6307 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6308 }
718e3744 6309 }
6310#ifdef HAVE_IPV6
8a92a8a0 6311 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
718e3744 6312 {
fb982c25 6313 assert (attr->extra);
856ca177
MS
6314 char buf_a[BUFSIZ];
6315 char buf_b[BUFSIZ];
6316 char buf_c[BUFSIZ];
801a9bcc 6317 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
856ca177
MS
6318 {
6319 if (json)
6320 json_object_string_add(json_out, "mpNexthopGlobalIn",
6321 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ));
6322 else
6323 vty_out (vty, "%s",
6324 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6325 buf_a, BUFSIZ));
6326 }
801a9bcc 6327 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
856ca177
MS
6328 {
6329 if (json)
6330 {
6331 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6332 buf_a, BUFSIZ);
6333 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6334 buf_b, BUFSIZ);
6335 sprintf(buf_c, "%s(%s)", buf_a, buf_b);
6336 json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c);
6337 }
6338 else
6339 vty_out (vty, "%s(%s)",
6340 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6341 buf_a, BUFSIZ),
6342 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6343 buf_b, BUFSIZ));
6344 }
6345
718e3744 6346 }
6347#endif /* HAVE_IPV6 */
6348 }
6349
fb982c25 6350 label = decode_label (binfo->extra->tag);
718e3744 6351
856ca177
MS
6352 if (json)
6353 {
6354 if (label)
6355 json_object_int_add(json_out, "notag", label);
6356 json_object_array_add(json, json_out);
6357 }
6358 else
6359 {
6360 vty_out (vty, "notag/%d", label);
6361 vty_out (vty, "%s", VTY_NEWLINE);
6362 }
718e3744 6363}
6364
6365/* dampening route */
5a646650 6366static void
856ca177
MS
6367damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6368 int display, safi_t safi, u_char use_json, json_object *json)
718e3744 6369{
6370 struct attr *attr;
718e3744 6371 int len;
50aef6f3 6372 char timebuf[BGP_UPTIME_LEN];
718e3744 6373
b40d939b 6374 /* short status lead text */
856ca177 6375 route_vty_short_status_out (vty, binfo, json);
b40d939b 6376
718e3744 6377 /* print prefix and mask */
856ca177
MS
6378 if (!use_json)
6379 {
6380 if (! display)
6381 route_vty_out_route (p, vty);
6382 else
6383 vty_out (vty, "%*s", 17, " ");
6384 }
718e3744 6385
6386 len = vty_out (vty, "%s", binfo->peer->host);
6387 len = 17 - len;
6388 if (len < 1)
856ca177
MS
6389 {
6390 if (!use_json)
6391 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6392 }
718e3744 6393 else
856ca177
MS
6394 {
6395 if (use_json)
6396 json_object_int_add(json, "peerHost", len);
6397 else
6398 vty_out (vty, "%*s", len, " ");
6399 }
718e3744 6400
856ca177
MS
6401 if (use_json)
6402 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6403 else
6404 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
718e3744 6405
6406 /* Print attribute */
6407 attr = binfo->attr;
6408 if (attr)
6409 {
6410 /* Print aspath */
6411 if (attr->aspath)
856ca177
MS
6412 {
6413 if (use_json)
6414 json_object_string_add(json, "asPath", attr->aspath->str);
6415 else
6416 aspath_print_vty (vty, "%s", attr->aspath, " ");
6417 }
718e3744 6418
6419 /* Print origin */
856ca177
MS
6420 if (use_json)
6421 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6422 else
6423 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 6424 }
856ca177
MS
6425 if (!use_json)
6426 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6427}
6428
718e3744 6429/* flap route */
5a646650 6430static void
856ca177
MS
6431flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6432 int display, safi_t safi, u_char use_json, json_object *json)
718e3744 6433{
6434 struct attr *attr;
6435 struct bgp_damp_info *bdi;
718e3744 6436 char timebuf[BGP_UPTIME_LEN];
6437 int len;
fb982c25
PJ
6438
6439 if (!binfo->extra)
6440 return;
6441
6442 bdi = binfo->extra->damp_info;
718e3744 6443
b40d939b 6444 /* short status lead text */
856ca177 6445 route_vty_short_status_out (vty, binfo, json);
b40d939b 6446
718e3744 6447 /* print prefix and mask */
856ca177
MS
6448 if (!use_json)
6449 {
6450 if (! display)
6451 route_vty_out_route (p, vty);
6452 else
6453 vty_out (vty, "%*s", 17, " ");
6454 }
718e3744 6455
6456 len = vty_out (vty, "%s", binfo->peer->host);
6457 len = 16 - len;
6458 if (len < 1)
856ca177
MS
6459 {
6460 if (!use_json)
6461 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6462 }
718e3744 6463 else
856ca177
MS
6464 {
6465 if (use_json)
6466 json_object_int_add(json, "peerHost", len);
6467 else
6468 vty_out (vty, "%*s", len, " ");
6469 }
718e3744 6470
6471 len = vty_out (vty, "%d", bdi->flap);
6472 len = 5 - len;
6473 if (len < 1)
856ca177
MS
6474 {
6475 if (!use_json)
6476 vty_out (vty, " ");
6477 }
718e3744 6478 else
856ca177
MS
6479 {
6480 if (use_json)
6481 json_object_int_add(json, "bdiFlap", len);
6482 else
6483 vty_out (vty, "%*s", len, " ");
6484 }
6485
6486 if (use_json)
6487 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json);
6488 else
6489 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6490 timebuf, BGP_UPTIME_LEN, 0, NULL));
718e3744 6491
6492 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6493 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
856ca177
MS
6494 {
6495 if (use_json)
6496 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6497 else
6498 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6499 }
718e3744 6500 else
856ca177
MS
6501 {
6502 if (!use_json)
6503 vty_out (vty, "%*s ", 8, " ");
6504 }
718e3744 6505
6506 /* Print attribute */
6507 attr = binfo->attr;
6508 if (attr)
6509 {
6510 /* Print aspath */
6511 if (attr->aspath)
856ca177
MS
6512 {
6513 if (use_json)
6514 json_object_string_add(json, "asPath", attr->aspath->str);
6515 else
6516 aspath_print_vty (vty, "%s", attr->aspath, " ");
6517 }
718e3744 6518
6519 /* Print origin */
856ca177
MS
6520 if (use_json)
6521 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6522 else
6523 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 6524 }
856ca177
MS
6525 if (!use_json)
6526 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6527}
6528
adbac85e
DW
6529static void
6530route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first,
6531 const char *header, json_object *json_adv_to)
6532{
6533 char buf1[INET6_ADDRSTRLEN];
6534 json_object *json_peer = NULL;
6535
6536 if (json_adv_to)
6537 {
6538 /* 'advertised-to' is a dictionary of peers we have advertised this
6539 * prefix too. The key is the peer's IP or swpX, the value is the
6540 * hostname if we know it and "" if not.
6541 */
6542 json_peer = json_object_new_object();
6543
6544 if (peer->hostname)
6545 json_object_string_add(json_peer, "hostname", peer->hostname);
6546
6547 if (peer->conf_if)
6548 json_object_object_add(json_adv_to, peer->conf_if, json_peer);
6549 else
6550 json_object_object_add(json_adv_to,
6551 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN),
6552 json_peer);
6553 }
6554 else
6555 {
6556 if (*first)
6557 {
6558 vty_out (vty, "%s", header);
6559 *first = 0;
6560 }
6561
6562 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6563 {
6564 if (peer->conf_if)
6565 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
6566 else
6567 vty_out (vty, " %s(%s)", peer->hostname,
6568 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6569 }
6570 else
6571 {
6572 if (peer->conf_if)
6573 vty_out (vty, " %s", peer->conf_if);
6574 else
6575 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6576 }
6577 }
6578}
6579
94f2b392 6580static void
718e3744 6581route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
b05a1c8b
DS
6582 struct bgp_info *binfo, afi_t afi, safi_t safi,
6583 json_object *json_paths)
718e3744 6584{
6585 char buf[INET6_ADDRSTRLEN];
6586 char buf1[BUFSIZ];
6587 struct attr *attr;
6588 int sockunion_vty_out (struct vty *, union sockunion *);
30b00176
JK
6589#ifdef HAVE_CLOCK_MONOTONIC
6590 time_t tbuf;
6591#endif
f1aa5d8a 6592 json_object *json_bestpath = NULL;
ffd0c037 6593 json_object *json_cluster_list = NULL;
f1aa5d8a
DS
6594 json_object *json_cluster_list_list = NULL;
6595 json_object *json_ext_community = NULL;
6596 json_object *json_last_update = NULL;
6597 json_object *json_nexthop_global = NULL;
6598 json_object *json_nexthop_ll = NULL;
6599 json_object *json_nexthops = NULL;
6600 json_object *json_path = NULL;
6601 json_object *json_peer = NULL;
6602 json_object *json_string = NULL;
adbac85e
DW
6603 json_object *json_adv_to = NULL;
6604 int first = 0;
6605 struct listnode *node, *nnode;
6606 struct peer *peer;
6607 int addpath_capable;
6608 int has_adj;
06370dac 6609 int first_as;
b05a1c8b
DS
6610
6611 if (json_paths)
6612 {
6613 json_path = json_object_new_object();
f1aa5d8a
DS
6614 json_peer = json_object_new_object();
6615 json_nexthop_global = json_object_new_object();
b05a1c8b
DS
6616 }
6617
718e3744 6618 attr = binfo->attr;
6619
6620 if (attr)
6621 {
6622 /* Line1 display AS-path, Aggregator */
6623 if (attr->aspath)
6624 {
f1aa5d8a
DS
6625 if (json_paths)
6626 {
6627 json_object_lock(attr->aspath->json);
6628 json_object_object_add(json_path, "aspath", attr->aspath->json);
6629 }
6630 else
b05a1c8b 6631 {
f1aa5d8a
DS
6632 if (attr->aspath->segments)
6633 aspath_print_vty (vty, " %s", attr->aspath, "");
b05a1c8b 6634 else
f1aa5d8a 6635 vty_out (vty, " Local");
b05a1c8b 6636 }
718e3744 6637 }
6638
b40d939b 6639 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
b05a1c8b
DS
6640 {
6641 if (json_paths)
f1aa5d8a 6642 json_object_boolean_true_add(json_path, "removed");
b05a1c8b
DS
6643 else
6644 vty_out (vty, ", (removed)");
6645 }
6646
93406d87 6647 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
b05a1c8b
DS
6648 {
6649 if (json_paths)
f1aa5d8a 6650 json_object_boolean_true_add(json_path, "stale");
b05a1c8b
DS
6651 else
6652 vty_out (vty, ", (stale)");
6653 }
6654
93406d87 6655 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
b05a1c8b
DS
6656 {
6657 if (json_paths)
6658 {
62d6dca0
DS
6659 json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as);
6660 json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr));
b05a1c8b
DS
6661 }
6662 else
6663 {
6664 vty_out (vty, ", (aggregated by %u %s)",
6665 attr->extra->aggregator_as,
6666 inet_ntoa (attr->extra->aggregator_addr));
6667 }
6668 }
6669
93406d87 6670 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
b05a1c8b
DS
6671 {
6672 if (json_paths)
62d6dca0 6673 json_object_boolean_true_add(json_path, "rxedFromRrClient");
b05a1c8b
DS
6674 else
6675 vty_out (vty, ", (Received from a RR-client)");
6676 }
6677
93406d87 6678 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
b05a1c8b
DS
6679 {
6680 if (json_paths)
62d6dca0 6681 json_object_boolean_true_add(json_path, "rxedFromRsClient");
b05a1c8b
DS
6682 else
6683 vty_out (vty, ", (Received from a RS-client)");
6684 }
6685
93406d87 6686 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
6687 {
6688 if (json_paths)
62d6dca0 6689 json_object_boolean_true_add(json_path, "dampeningHistoryEntry");
b05a1c8b
DS
6690 else
6691 vty_out (vty, ", (history entry)");
6692 }
93406d87 6693 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
b05a1c8b
DS
6694 {
6695 if (json_paths)
62d6dca0 6696 json_object_boolean_true_add(json_path, "dampeningSuppressed");
b05a1c8b
DS
6697 else
6698 vty_out (vty, ", (suppressed due to dampening)");
6699 }
6700
6701 if (!json_paths)
6702 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6703
6704 /* Line2 display Next-hop, Neighbor, Router-id */
f1aa5d8a 6705 /* Display the nexthop */
587ff0fd
LB
6706 if (p->family == AF_INET &&
6707 (safi == SAFI_MPLS_VPN ||
6708 safi == SAFI_ENCAP ||
6709 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
718e3744 6710 {
587ff0fd 6711 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
b05a1c8b
DS
6712 {
6713 if (json_paths)
f1aa5d8a 6714 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
b05a1c8b
DS
6715 else
6716 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6717 }
6718 else
6719 {
6720 if (json_paths)
f1aa5d8a 6721 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
b05a1c8b
DS
6722 else
6723 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
6724 }
6725
6726 if (json_paths)
f1aa5d8a 6727 json_object_string_add(json_nexthop_global, "afi", "ipv4");
718e3744 6728 }
718e3744 6729 else
6730 {
fb982c25 6731 assert (attr->extra);
b05a1c8b
DS
6732 if (json_paths)
6733 {
f1aa5d8a
DS
6734 json_object_string_add(json_nexthop_global, "ip",
6735 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6736 buf, INET6_ADDRSTRLEN));
6737 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6738 json_object_string_add(json_nexthop_global, "scope", "global");
b05a1c8b
DS
6739 }
6740 else
6741 {
6742 vty_out (vty, " %s",
6743 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6744 buf, INET6_ADDRSTRLEN));
6745 }
718e3744 6746 }
b05a1c8b 6747
f1aa5d8a
DS
6748 /* Display the IGP cost or 'inaccessible' */
6749 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6750 {
6751 if (json_paths)
6752 json_object_boolean_false_add(json_nexthop_global, "accessible");
6753 else
6754 vty_out (vty, " (inaccessible)");
6755 }
6756 else
6757 {
6758 if (binfo->extra && binfo->extra->igpmetric)
b05a1c8b
DS
6759 {
6760 if (json_paths)
f1aa5d8a 6761 json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric);
b05a1c8b 6762 else
f1aa5d8a 6763 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
b05a1c8b 6764 }
f1aa5d8a
DS
6765
6766 /* IGP cost is 0, display this only for json */
b05a1c8b
DS
6767 else
6768 {
6769 if (json_paths)
f1aa5d8a 6770 json_object_int_add(json_nexthop_global, "metric", 0);
b05a1c8b
DS
6771 }
6772
6773 if (json_paths)
f1aa5d8a
DS
6774 json_object_boolean_true_add(json_nexthop_global, "accessible");
6775 }
6776
6777 /* Display peer "from" output */
6778 /* This path was originated locally */
6779 if (binfo->peer == bgp->peer_self)
718e3744 6780 {
f1aa5d8a
DS
6781
6782 if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
b05a1c8b
DS
6783 {
6784 if (json_paths)
62d6dca0 6785 json_object_string_add(json_peer, "peerId", "0.0.0.0");
b05a1c8b 6786 else
f1aa5d8a 6787 vty_out (vty, " from 0.0.0.0 ");
b05a1c8b 6788 }
f1aa5d8a 6789 else
b05a1c8b
DS
6790 {
6791 if (json_paths)
62d6dca0 6792 json_object_string_add(json_peer, "peerId", "::");
b05a1c8b 6793 else
f1aa5d8a 6794 vty_out (vty, " from :: ");
b05a1c8b
DS
6795 }
6796
f1aa5d8a 6797 if (json_paths)
62d6dca0 6798 json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id));
b05a1c8b 6799 else
f1aa5d8a
DS
6800 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6801 }
6802
6803 /* We RXed this path from one of our peers */
6804 else
6805 {
b05a1c8b
DS
6806
6807 if (json_paths)
6808 {
62d6dca0
DS
6809 json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6810 json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
f1aa5d8a 6811
04b6bdc0
DW
6812 if (binfo->peer->hostname)
6813 json_object_string_add(json_peer, "hostname", binfo->peer->hostname);
6814
6815 if (binfo->peer->domainname)
6816 json_object_string_add(json_peer, "domainname", binfo->peer->domainname);
6817
036a4e7d 6818 if (binfo->peer->conf_if)
f1aa5d8a 6819 json_object_string_add(json_peer, "interface", binfo->peer->conf_if);
b05a1c8b
DS
6820 }
6821 else
6822 {
036a4e7d 6823 if (binfo->peer->conf_if)
04b6bdc0
DW
6824 {
6825 if (binfo->peer->hostname &&
6826 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6827 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
6828 binfo->peer->conf_if);
6829 else
6830 vty_out (vty, " from %s", binfo->peer->conf_if);
6831 }
036a4e7d 6832 else
04b6bdc0
DW
6833 {
6834 if (binfo->peer->hostname &&
6835 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6836 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
6837 binfo->peer->host);
6838 else
6839 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6840 }
b05a1c8b 6841
f1aa5d8a
DS
6842 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6843 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
6844 else
6845 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
b05a1c8b 6846 }
718e3744 6847 }
b05a1c8b
DS
6848
6849 if (!json_paths)
6850 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6851
f1aa5d8a 6852 /* display the link-local nexthop */
801a9bcc 6853 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
718e3744 6854 {
b05a1c8b
DS
6855 if (json_paths)
6856 {
f1aa5d8a
DS
6857 json_nexthop_ll = json_object_new_object();
6858 json_object_string_add(json_nexthop_ll, "ip",
6859 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6860 buf, INET6_ADDRSTRLEN));
6861 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
6862 json_object_string_add(json_nexthop_ll, "scope", "link-local");
6863
6864 json_object_boolean_true_add(json_nexthop_ll, "accessible");
161995ea
DS
6865
6866 if (!attr->extra->mp_nexthop_prefer_global)
6867 json_object_boolean_true_add(json_nexthop_ll, "used");
6868 else
6869 json_object_boolean_true_add(json_nexthop_global, "used");
b05a1c8b
DS
6870 }
6871 else
6872 {
161995ea
DS
6873 vty_out (vty, " (%s) %s%s",
6874 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
b05a1c8b 6875 buf, INET6_ADDRSTRLEN),
161995ea
DS
6876 attr->extra->mp_nexthop_prefer_global ?
6877 "(prefer-global)" : "(used)",
b05a1c8b
DS
6878 VTY_NEWLINE);
6879 }
718e3744 6880 }
f1aa5d8a
DS
6881 /* If we do not have a link-local nexthop then we must flag the global as "used" */
6882 else
6883 {
6884 if (json_paths)
6885 json_object_boolean_true_add(json_nexthop_global, "used");
6886 }
718e3744 6887
0d9551dc 6888 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
b05a1c8b 6889 if (json_paths)
f1aa5d8a 6890 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
b05a1c8b 6891 else
f1aa5d8a 6892 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
718e3744 6893
6894 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b
DS
6895 {
6896 if (json_paths)
f1aa5d8a 6897 json_object_int_add(json_path, "med", attr->med);
b05a1c8b 6898 else
f1aa5d8a 6899 vty_out (vty, ", metric %u", attr->med);
b05a1c8b 6900 }
718e3744 6901
6902 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
b05a1c8b
DS
6903 {
6904 if (json_paths)
f1aa5d8a 6905 json_object_int_add(json_path, "localpref", attr->local_pref);
b05a1c8b 6906 else
f1aa5d8a 6907 vty_out (vty, ", localpref %u", attr->local_pref);
b05a1c8b 6908 }
718e3744 6909 else
b05a1c8b
DS
6910 {
6911 if (json_paths)
f1aa5d8a 6912 json_object_int_add(json_path, "localpref", bgp->default_local_pref);
b05a1c8b 6913 else
f1aa5d8a 6914 vty_out (vty, ", localpref %u", bgp->default_local_pref);
b05a1c8b 6915 }
718e3744 6916
fb982c25 6917 if (attr->extra && attr->extra->weight != 0)
b05a1c8b
DS
6918 {
6919 if (json_paths)
f1aa5d8a 6920 json_object_int_add(json_path, "weight", attr->extra->weight);
b05a1c8b 6921 else
f1aa5d8a 6922 vty_out (vty, ", weight %u", attr->extra->weight);
b05a1c8b 6923 }
0d9551dc
DS
6924
6925 if (attr->extra && attr->extra->tag != 0)
b05a1c8b
DS
6926 {
6927 if (json_paths)
f1aa5d8a 6928 json_object_int_add(json_path, "tag", attr->extra->tag);
b05a1c8b 6929 else
f1aa5d8a 6930 vty_out (vty, ", tag %d", attr->extra->tag);
b05a1c8b 6931 }
718e3744 6932
31eba040 6933 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
b05a1c8b
DS
6934 {
6935 if (json_paths)
f1aa5d8a 6936 json_object_boolean_false_add(json_path, "valid");
b05a1c8b
DS
6937 else
6938 vty_out (vty, ", invalid");
6939 }
31eba040 6940 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
6941 {
6942 if (json_paths)
f1aa5d8a 6943 json_object_boolean_true_add(json_path, "valid");
b05a1c8b
DS
6944 else
6945 vty_out (vty, ", valid");
6946 }
718e3744 6947
6948 if (binfo->peer != bgp->peer_self)
6949 {
f1aa5d8a 6950 if (binfo->peer->as == binfo->peer->local_as)
b05a1c8b 6951 {
66b199b2
DS
6952 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
6953 {
6954 if (json_paths)
f1aa5d8a 6955 json_object_string_add(json_peer, "type", "confed-internal");
66b199b2 6956 else
f1aa5d8a 6957 vty_out (vty, ", confed-internal");
66b199b2 6958 }
b05a1c8b 6959 else
66b199b2
DS
6960 {
6961 if (json_paths)
f1aa5d8a 6962 json_object_string_add(json_peer, "type", "internal");
66b199b2 6963 else
f1aa5d8a 6964 vty_out (vty, ", internal");
66b199b2 6965 }
b05a1c8b 6966 }
f1aa5d8a 6967 else
b05a1c8b
DS
6968 {
6969 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
6970 {
6971 if (json_paths)
f1aa5d8a 6972 json_object_string_add(json_peer, "type", "confed-external");
b05a1c8b 6973 else
f1aa5d8a 6974 vty_out (vty, ", confed-external");
b05a1c8b
DS
6975 }
6976 else
6977 {
6978 if (json_paths)
f1aa5d8a 6979 json_object_string_add(json_peer, "type", "external");
b05a1c8b 6980 else
f1aa5d8a 6981 vty_out (vty, ", external");
b05a1c8b
DS
6982 }
6983 }
718e3744 6984 }
6985 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
b05a1c8b
DS
6986 {
6987 if (json_paths)
6988 {
f1aa5d8a
DS
6989 json_object_boolean_true_add(json_path, "aggregated");
6990 json_object_boolean_true_add(json_path, "local");
b05a1c8b
DS
6991 }
6992 else
6993 {
6994 vty_out (vty, ", aggregated, local");
6995 }
6996 }
718e3744 6997 else if (binfo->type != ZEBRA_ROUTE_BGP)
b05a1c8b
DS
6998 {
6999 if (json_paths)
f1aa5d8a 7000 json_object_boolean_true_add(json_path, "sourced");
b05a1c8b
DS
7001 else
7002 vty_out (vty, ", sourced");
7003 }
718e3744 7004 else
b05a1c8b
DS
7005 {
7006 if (json_paths)
7007 {
f1aa5d8a
DS
7008 json_object_boolean_true_add(json_path, "sourced");
7009 json_object_boolean_true_add(json_path, "local");
b05a1c8b
DS
7010 }
7011 else
7012 {
7013 vty_out (vty, ", sourced, local");
7014 }
7015 }
718e3744 7016
7017 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
b05a1c8b
DS
7018 {
7019 if (json_paths)
62d6dca0 7020 json_object_boolean_true_add(json_path, "atomicAggregate");
b05a1c8b
DS
7021 else
7022 vty_out (vty, ", atomic-aggregate");
7023 }
718e3744 7024
de8d5dff
JB
7025 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
7026 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
7027 bgp_info_mpath_count (binfo)))
b05a1c8b
DS
7028 {
7029 if (json_paths)
f1aa5d8a 7030 json_object_boolean_true_add(json_path, "multipath");
b05a1c8b
DS
7031 else
7032 vty_out (vty, ", multipath");
7033 }
de8d5dff 7034
06370dac
DW
7035 // Mark the bestpath(s)
7036 if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED))
7037 {
7038 first_as = aspath_get_firstas(attr->aspath);
7039
7040 if (json_paths)
7041 {
7042 if (!json_bestpath)
7043 json_bestpath = json_object_new_object();
7044 json_object_int_add(json_bestpath, "bestpathFromAs", first_as);
7045 }
7046 else
7047 {
7048 if (first_as)
7049 vty_out (vty, ", bestpath-from-AS %d", first_as);
7050 else
7051 vty_out (vty, ", bestpath-from-AS Local");
7052 }
7053 }
7054
718e3744 7055 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
b05a1c8b
DS
7056 {
7057 if (json_paths)
f1aa5d8a 7058 {
06370dac
DW
7059 if (!json_bestpath)
7060 json_bestpath = json_object_new_object();
f1aa5d8a 7061 json_object_boolean_true_add(json_bestpath, "overall");
f1aa5d8a 7062 }
b05a1c8b
DS
7063 else
7064 vty_out (vty, ", best");
7065 }
718e3744 7066
06370dac
DW
7067 if (json_bestpath)
7068 json_object_object_add(json_path, "bestpath", json_bestpath);
7069
b05a1c8b
DS
7070 if (!json_paths)
7071 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7072
7073 /* Line 4 display Community */
7074 if (attr->community)
b05a1c8b
DS
7075 {
7076 if (json_paths)
7077 {
f1aa5d8a
DS
7078 json_object_lock(attr->community->json);
7079 json_object_object_add(json_path, "community", attr->community->json);
b05a1c8b
DS
7080 }
7081 else
7082 {
7083 vty_out (vty, " Community: %s%s", attr->community->str,
7084 VTY_NEWLINE);
7085 }
7086 }
718e3744 7087
7088 /* Line 5 display Extended-community */
7089 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
b05a1c8b
DS
7090 {
7091 if (json_paths)
7092 {
f1aa5d8a
DS
7093 json_ext_community = json_object_new_object();
7094 json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str);
62d6dca0 7095 json_object_object_add(json_path, "extendedCommunity", json_ext_community);
b05a1c8b
DS
7096 }
7097 else
7098 {
7099 vty_out (vty, " Extended Community: %s%s",
7100 attr->extra->ecommunity->str, VTY_NEWLINE);
7101 }
7102 }
7103
718e3744 7104 /* Line 6 display Originator, Cluster-id */
7105 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
7106 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
7107 {
fb982c25 7108 assert (attr->extra);
718e3744 7109 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
b05a1c8b
DS
7110 {
7111 if (json_paths)
62d6dca0 7112 json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id));
b05a1c8b 7113 else
f1aa5d8a
DS
7114 vty_out (vty, " Originator: %s",
7115 inet_ntoa (attr->extra->originator_id));
b05a1c8b 7116 }
718e3744 7117
7118 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
7119 {
7120 int i;
b05a1c8b
DS
7121
7122 if (json_paths)
7123 {
f1aa5d8a
DS
7124 json_cluster_list = json_object_new_object();
7125 json_cluster_list_list = json_object_new_array();
7126
b05a1c8b
DS
7127 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7128 {
7129 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
f1aa5d8a 7130 json_object_array_add(json_cluster_list_list, json_string);
b05a1c8b 7131 }
f1aa5d8a
DS
7132
7133 /* struct cluster_list does not have "str" variable like
7134 * aspath and community do. Add this someday if someone
7135 * asks for it.
7136 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
7137 */
7138 json_object_object_add(json_cluster_list, "list", json_cluster_list_list);
62d6dca0 7139 json_object_object_add(json_path, "clusterList", json_cluster_list);
b05a1c8b
DS
7140 }
7141 else
7142 {
7143 vty_out (vty, ", Cluster list: ");
7144
7145 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7146 {
7147 vty_out (vty, "%s ",
7148 inet_ntoa (attr->extra->cluster->list[i]));
7149 }
7150 }
718e3744 7151 }
b05a1c8b
DS
7152
7153 if (!json_paths)
7154 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7155 }
b05a1c8b 7156
fb982c25 7157 if (binfo->extra && binfo->extra->damp_info)
b05a1c8b 7158 bgp_damp_info_vty (vty, binfo, json_path);
718e3744 7159
a82478b9
DS
7160 /* Line 7 display Addpath IDs */
7161 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
b05a1c8b
DS
7162 {
7163 if (json_paths)
7164 {
62d6dca0
DS
7165 json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id);
7166 json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id);
b05a1c8b
DS
7167 }
7168 else
7169 {
7170 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
7171 binfo->addpath_rx_id, binfo->addpath_tx_id,
7172 VTY_NEWLINE);
7173 }
7174 }
a82478b9 7175
adbac85e
DW
7176 /* If we used addpath to TX a non-bestpath we need to display
7177 * "Advertised to" on a path-by-path basis */
7178 if (bgp->addpath_tx_used[afi][safi])
7179 {
7180 first = 1;
7181
7182 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7183 {
7184 addpath_capable = bgp_addpath_encode_tx (peer, afi, safi);
7185 has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id);
7186
7187 if ((addpath_capable && has_adj) ||
7188 (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)))
7189 {
7190 if (json_path && !json_adv_to)
7191 json_adv_to = json_object_new_object();
7192
7193 route_vty_out_advertised_to(vty, peer, &first,
7194 " Advertised to:",
7195 json_adv_to);
7196 }
7197 }
7198
7199 if (json_path)
7200 {
7201 if (json_adv_to)
7202 {
7203 json_object_object_add(json_path, "advertisedTo", json_adv_to);
7204 }
7205 }
7206 else
7207 {
7208 if (!first)
7209 {
7210 vty_out (vty, "%s", VTY_NEWLINE);
7211 }
7212 }
7213 }
7214
a82478b9 7215 /* Line 8 display Uptime */
30b00176
JK
7216#ifdef HAVE_CLOCK_MONOTONIC
7217 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
b05a1c8b 7218 if (json_paths)
f1aa5d8a
DS
7219 {
7220 json_last_update = json_object_new_object();
7221 json_object_int_add(json_last_update, "epoch", tbuf);
7222 json_object_string_add(json_last_update, "string", ctime(&tbuf));
62d6dca0 7223 json_object_object_add(json_path, "lastUpdate", json_last_update);
f1aa5d8a 7224 }
b05a1c8b
DS
7225 else
7226 vty_out (vty, " Last update: %s", ctime(&tbuf));
30b00176 7227#else
b05a1c8b 7228 if (json_paths)
f1aa5d8a
DS
7229 {
7230 json_last_update = json_object_new_object();
7231 json_object_int_add(json_last_update, "epoch", tbuf);
7232 json_object_string_add(json_last_update, "string", ctime(&binfo->uptime));
62d6dca0 7233 json_object_object_add(json_path, "lastUpdate", json_last_update);
f1aa5d8a 7234 }
b05a1c8b
DS
7235 else
7236 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
30b00176 7237#endif /* HAVE_CLOCK_MONOTONIC */
718e3744 7238 }
b05a1c8b
DS
7239
7240 /* We've constructed the json object for this path, add it to the json
7241 * array of paths
7242 */
7243 if (json_paths)
f1aa5d8a
DS
7244 {
7245 if (json_nexthop_global || json_nexthop_ll)
7246 {
7247 json_nexthops = json_object_new_array();
7248
7249 if (json_nexthop_global)
7250 json_object_array_add(json_nexthops, json_nexthop_global);
7251
7252 if (json_nexthop_ll)
7253 json_object_array_add(json_nexthops, json_nexthop_ll);
7254
7255 json_object_object_add(json_path, "nexthops", json_nexthops);
7256 }
7257
7258 json_object_object_add(json_path, "peer", json_peer);
7259 json_object_array_add(json_paths, json_path);
7260 }
b05a1c8b
DS
7261 else
7262 vty_out (vty, "%s", VTY_NEWLINE);
b366b518
BB
7263}
7264
47fc97cc 7265#define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
718e3744 7266#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7267#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7268
7269enum bgp_show_type
7270{
7271 bgp_show_type_normal,
7272 bgp_show_type_regexp,
7273 bgp_show_type_prefix_list,
7274 bgp_show_type_filter_list,
7275 bgp_show_type_route_map,
7276 bgp_show_type_neighbor,
7277 bgp_show_type_cidr_only,
7278 bgp_show_type_prefix_longer,
7279 bgp_show_type_community_all,
7280 bgp_show_type_community,
7281 bgp_show_type_community_exact,
7282 bgp_show_type_community_list,
7283 bgp_show_type_community_list_exact,
7284 bgp_show_type_flap_statistics,
7285 bgp_show_type_flap_address,
7286 bgp_show_type_flap_prefix,
7287 bgp_show_type_flap_cidr_only,
7288 bgp_show_type_flap_regexp,
7289 bgp_show_type_flap_filter_list,
7290 bgp_show_type_flap_prefix_list,
7291 bgp_show_type_flap_prefix_longer,
7292 bgp_show_type_flap_route_map,
7293 bgp_show_type_flap_neighbor,
7294 bgp_show_type_dampend_paths,
7295 bgp_show_type_damp_neighbor
7296};
7297
50ef26d4 7298static int
7299bgp_show_prefix_list (struct vty *vty, const char *name,
7300 const char *prefix_list_str, afi_t afi,
7301 safi_t safi, enum bgp_show_type type);
7302static int
7303bgp_show_filter_list (struct vty *vty, const char *name,
7304 const char *filter, afi_t afi,
7305 safi_t safi, enum bgp_show_type type);
7306static int
7307bgp_show_route_map (struct vty *vty, const char *name,
7308 const char *rmap_str, afi_t afi,
7309 safi_t safi, enum bgp_show_type type);
7310static int
7311bgp_show_community_list (struct vty *vty, const char *name,
7312 const char *com, int exact,
7313 afi_t afi, safi_t safi);
7314static int
7315bgp_show_prefix_longer (struct vty *vty, const char *name,
7316 const char *prefix, afi_t afi,
7317 safi_t safi, enum bgp_show_type type);
7318
5a646650 7319static int
9f689658
DD
7320bgp_show_table (struct vty *vty, struct bgp_table *table,
7321 struct in_addr *router_id, enum bgp_show_type type,
7322 void *output_arg, u_char use_json, json_object *json)
718e3744 7323{
718e3744 7324 struct bgp_info *ri;
7325 struct bgp_node *rn;
718e3744 7326 int header = 1;
718e3744 7327 int display;
5a646650 7328 unsigned long output_count;
b05a1c8b
DS
7329 struct prefix *p;
7330 char buf[BUFSIZ];
7331 char buf2[BUFSIZ];
f1aa5d8a
DS
7332 json_object *json_paths = NULL;
7333 json_object *json_routes = NULL;
b05a1c8b
DS
7334
7335 if (use_json)
7336 {
9f689658
DD
7337 if (json == NULL)
7338 json = json_object_new_object();
7339
62d6dca0
DS
7340 json_object_int_add(json, "tableVersion", table->version);
7341 json_object_string_add(json, "routerId", inet_ntoa (*router_id));
b05a1c8b
DS
7342 json_routes = json_object_new_object();
7343 }
718e3744 7344
7345 /* This is first entry point, so reset total line. */
5a646650 7346 output_count = 0;
718e3744 7347
718e3744 7348 /* Start processing of routes. */
7349 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7350 if (rn->info != NULL)
7351 {
856ca177 7352 display = 0;
718e3744 7353
b05a1c8b
DS
7354 if (use_json)
7355 json_paths = json_object_new_array();
7356 else
7357 json_paths = NULL;
7358
856ca177
MS
7359 for (ri = rn->info; ri; ri = ri->next)
7360 {
7361 if (type == bgp_show_type_flap_statistics
7362 || type == bgp_show_type_flap_address
7363 || type == bgp_show_type_flap_prefix
7364 || type == bgp_show_type_flap_cidr_only
7365 || type == bgp_show_type_flap_regexp
7366 || type == bgp_show_type_flap_filter_list
7367 || type == bgp_show_type_flap_prefix_list
7368 || type == bgp_show_type_flap_prefix_longer
7369 || type == bgp_show_type_flap_route_map
7370 || type == bgp_show_type_flap_neighbor
7371 || type == bgp_show_type_dampend_paths
7372 || type == bgp_show_type_damp_neighbor)
7373 {
7374 if (!(ri->extra && ri->extra->damp_info))
7375 continue;
7376 }
7377 if (type == bgp_show_type_regexp
7378 || type == bgp_show_type_flap_regexp)
7379 {
7380 regex_t *regex = output_arg;
718e3744 7381
856ca177
MS
7382 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7383 continue;
7384 }
7385 if (type == bgp_show_type_prefix_list
7386 || type == bgp_show_type_flap_prefix_list)
7387 {
7388 struct prefix_list *plist = output_arg;
718e3744 7389
856ca177
MS
7390 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7391 continue;
7392 }
7393 if (type == bgp_show_type_filter_list
7394 || type == bgp_show_type_flap_filter_list)
7395 {
7396 struct as_list *as_list = output_arg;
558d1fec 7397
856ca177
MS
7398 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7399 continue;
7400 }
7401 if (type == bgp_show_type_route_map
7402 || type == bgp_show_type_flap_route_map)
7403 {
7404 struct route_map *rmap = output_arg;
7405 struct bgp_info binfo;
7406 struct attr dummy_attr;
7407 struct attr_extra dummy_extra;
7408 int ret;
718e3744 7409
856ca177
MS
7410 dummy_attr.extra = &dummy_extra;
7411 bgp_attr_dup (&dummy_attr, ri->attr);
718e3744 7412
856ca177
MS
7413 binfo.peer = ri->peer;
7414 binfo.attr = &dummy_attr;
718e3744 7415
856ca177
MS
7416 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
7417 if (ret == RMAP_DENYMATCH)
7418 continue;
7419 }
7420 if (type == bgp_show_type_neighbor
7421 || type == bgp_show_type_flap_neighbor
7422 || type == bgp_show_type_damp_neighbor)
7423 {
7424 union sockunion *su = output_arg;
718e3744 7425
856ca177
MS
7426 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7427 continue;
7428 }
7429 if (type == bgp_show_type_cidr_only
7430 || type == bgp_show_type_flap_cidr_only)
7431 {
7432 u_int32_t destination;
718e3744 7433
856ca177
MS
7434 destination = ntohl (rn->p.u.prefix4.s_addr);
7435 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7436 continue;
7437 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7438 continue;
7439 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7440 continue;
7441 }
7442 if (type == bgp_show_type_prefix_longer
7443 || type == bgp_show_type_flap_prefix_longer)
7444 {
7445 struct prefix *p = output_arg;
718e3744 7446
856ca177
MS
7447 if (! prefix_match (p, &rn->p))
7448 continue;
7449 }
7450 if (type == bgp_show_type_community_all)
7451 {
7452 if (! ri->attr->community)
7453 continue;
7454 }
7455 if (type == bgp_show_type_community)
7456 {
7457 struct community *com = output_arg;
718e3744 7458
856ca177
MS
7459 if (! ri->attr->community ||
7460 ! community_match (ri->attr->community, com))
7461 continue;
7462 }
7463 if (type == bgp_show_type_community_exact)
7464 {
7465 struct community *com = output_arg;
718e3744 7466
856ca177
MS
7467 if (! ri->attr->community ||
7468 ! community_cmp (ri->attr->community, com))
7469 continue;
7470 }
7471 if (type == bgp_show_type_community_list)
7472 {
7473 struct community_list *list = output_arg;
718e3744 7474
856ca177
MS
7475 if (! community_list_match (ri->attr->community, list))
7476 continue;
7477 }
7478 if (type == bgp_show_type_community_list_exact)
7479 {
7480 struct community_list *list = output_arg;
718e3744 7481
856ca177
MS
7482 if (! community_list_exact_match (ri->attr->community, list))
7483 continue;
7484 }
7485 if (type == bgp_show_type_flap_address
7486 || type == bgp_show_type_flap_prefix)
7487 {
7488 struct prefix *p = output_arg;
718e3744 7489
856ca177
MS
7490 if (! prefix_match (&rn->p, p))
7491 continue;
b05a1c8b 7492
856ca177
MS
7493 if (type == bgp_show_type_flap_prefix)
7494 if (p->prefixlen != rn->p.prefixlen)
7495 continue;
7496 }
7497 if (type == bgp_show_type_dampend_paths
7498 || type == bgp_show_type_damp_neighbor)
7499 {
7500 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7501 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7502 continue;
7503 }
7504
7505 if (!use_json && header)
7506 {
7507 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (*router_id), VTY_NEWLINE);
7508 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7509 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7510 if (type == bgp_show_type_dampend_paths
7511 || type == bgp_show_type_damp_neighbor)
7512 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7513 else if (type == bgp_show_type_flap_statistics
7514 || type == bgp_show_type_flap_address
7515 || type == bgp_show_type_flap_prefix
7516 || type == bgp_show_type_flap_cidr_only
7517 || type == bgp_show_type_flap_regexp
7518 || type == bgp_show_type_flap_filter_list
7519 || type == bgp_show_type_flap_prefix_list
7520 || type == bgp_show_type_flap_prefix_longer
7521 || type == bgp_show_type_flap_route_map
7522 || type == bgp_show_type_flap_neighbor)
7523 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7524 else
7525 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7526 header = 0;
7527 }
7528
7529 if (type == bgp_show_type_dampend_paths
7530 || type == bgp_show_type_damp_neighbor)
7531 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7532 else if (type == bgp_show_type_flap_statistics
7533 || type == bgp_show_type_flap_address
7534 || type == bgp_show_type_flap_prefix
7535 || type == bgp_show_type_flap_cidr_only
7536 || type == bgp_show_type_flap_regexp
7537 || type == bgp_show_type_flap_filter_list
7538 || type == bgp_show_type_flap_prefix_list
7539 || type == bgp_show_type_flap_prefix_longer
7540 || type == bgp_show_type_flap_route_map
7541 || type == bgp_show_type_flap_neighbor)
7542 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7543 else
7544 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
7545 display++;
b05a1c8b
DS
7546 }
7547
856ca177
MS
7548 if (display)
7549 {
7550 output_count++;
7551 if (use_json)
7552 {
7553 p = &rn->p;
7554 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
7555 json_object_object_add(json_routes, buf2, json_paths);
7556 }
7557 }
9f689658 7558 }
718e3744 7559
b05a1c8b 7560 if (use_json)
718e3744 7561 {
d1d16a96 7562 json_object_object_add(json, "routes", json_routes);
b05a1c8b 7563 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
f1aa5d8a 7564 json_object_free(json);
718e3744 7565 }
7566 else
b05a1c8b
DS
7567 {
7568 /* No route is displayed */
7569 if (output_count == 0)
7570 {
7571 if (type == bgp_show_type_normal)
856ca177 7572 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
b05a1c8b
DS
7573 }
7574 else
7575 vty_out (vty, "%sTotal number of prefixes %ld%s",
856ca177 7576 VTY_NEWLINE, output_count, VTY_NEWLINE);
b05a1c8b 7577 }
718e3744 7578
7579 return CMD_SUCCESS;
7580}
7581
5a646650 7582static int
fee0f4c6 7583bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
856ca177 7584 enum bgp_show_type type, void *output_arg, u_char use_json)
fee0f4c6 7585{
7586 struct bgp_table *table;
7587
856ca177
MS
7588 if (bgp == NULL)
7589 {
7590 bgp = bgp_get_default ();
7591 }
fee0f4c6 7592
7593 if (bgp == NULL)
7594 {
856ca177
MS
7595 if (!use_json)
7596 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
fee0f4c6 7597 return CMD_WARNING;
7598 }
7599
fee0f4c6 7600 table = bgp->rib[afi][safi];
7601
9f689658
DD
7602 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg,
7603 use_json, NULL);
fee0f4c6 7604}
7605
f186de26 7606static void
7607bgp_show_all_instances_routes_vty (struct vty *vty, afi_t afi, safi_t safi,
7608 u_char use_json)
7609{
7610 struct listnode *node, *nnode;
7611 struct bgp *bgp;
7612 struct bgp_table *table;
9f689658
DD
7613 json_object *json = NULL;
7614 int is_first = 1;
7615
7616 if (use_json)
7617 vty_out (vty, "{%s", VTY_NEWLINE);
f186de26 7618
7619 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
7620 {
9f689658
DD
7621 if (use_json)
7622 {
7623 if (!(json = json_object_new_object()))
7624 {
7625 zlog_err("Unable to allocate memory for JSON object");
7626 vty_out (vty,
7627 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}%s",
7628 VTY_NEWLINE);
7629 return;
7630 }
7631 json_object_int_add(json, "vrfId",
7632 (bgp->vrf_id == VRF_UNKNOWN)
7633 ? -1 : bgp->vrf_id);
7634 json_object_string_add(json, "vrfName",
7635 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7636 ? "Default" : bgp->name);
7637 if (! is_first)
7638 vty_out (vty, ",%s", VTY_NEWLINE);
7639 else
7640 is_first = 0;
7641
7642 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7643 ? "Default" : bgp->name);
7644 }
7645 else
7646 {
7647 vty_out (vty, "%sInstance %s:%s",
7648 VTY_NEWLINE,
7649 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7650 ? "Default" : bgp->name,
7651 VTY_NEWLINE);
7652 }
f186de26 7653 table = bgp->rib[afi][safi];
7654 bgp_show_table (vty, table, &bgp->router_id,
9f689658
DD
7655 bgp_show_type_normal, NULL, use_json, json);
7656
f186de26 7657 }
9f689658
DD
7658
7659 if (use_json)
7660 vty_out (vty, "}%s", VTY_NEWLINE);
f186de26 7661}
7662
718e3744 7663/* Header of detailed BGP route information */
94f2b392 7664static void
718e3744 7665route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7666 struct bgp_node *rn,
b05a1c8b
DS
7667 struct prefix_rd *prd, afi_t afi, safi_t safi,
7668 json_object *json)
718e3744 7669{
7670 struct bgp_info *ri;
7671 struct prefix *p;
7672 struct peer *peer;
1eb8ef25 7673 struct listnode *node, *nnode;
718e3744 7674 char buf1[INET6_ADDRSTRLEN];
7675 char buf2[INET6_ADDRSTRLEN];
7676 int count = 0;
7677 int best = 0;
7678 int suppress = 0;
7679 int no_export = 0;
7680 int no_advertise = 0;
7681 int local_as = 0;
adbac85e 7682 int first = 1;
ffd0c037 7683 json_object *json_adv_to = NULL;
718e3744 7684
7685 p = &rn->p;
b05a1c8b
DS
7686
7687 if (json)
7688 {
f1aa5d8a
DS
7689 json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7690 json_object_int_add(json, "prefixlen", p->prefixlen);
b05a1c8b
DS
7691 }
7692 else
7693 {
7694 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
587ff0fd 7695 ((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) ?
b05a1c8b
DS
7696 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7697 safi == SAFI_MPLS_VPN ? ":" : "",
7698 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7699 p->prefixlen, VTY_NEWLINE);
7700 }
718e3744 7701
7702 for (ri = rn->info; ri; ri = ri->next)
7703 {
7704 count++;
7705 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7706 {
7707 best = count;
fb982c25 7708 if (ri->extra && ri->extra->suppress)
718e3744 7709 suppress = 1;
7710 if (ri->attr->community != NULL)
7711 {
7712 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7713 no_advertise = 1;
7714 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7715 no_export = 1;
7716 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7717 local_as = 1;
7718 }
7719 }
7720 }
7721
b05a1c8b 7722 if (!json)
718e3744 7723 {
b05a1c8b
DS
7724 vty_out (vty, "Paths: (%d available", count);
7725 if (best)
7726 {
7727 vty_out (vty, ", best #%d", best);
7728 if (safi == SAFI_UNICAST)
46827ae9
DS
7729 vty_out (vty, ", table %s",
7730 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7731 ? "Default-IP-Routing-Table" : bgp->name);
b05a1c8b
DS
7732 }
7733 else
7734 vty_out (vty, ", no best path");
7735
7736 if (no_advertise)
7737 vty_out (vty, ", not advertised to any peer");
7738 else if (no_export)
7739 vty_out (vty, ", not advertised to EBGP peer");
7740 else if (local_as)
7741 vty_out (vty, ", not advertised outside local AS");
7742
7743 if (suppress)
7744 vty_out (vty, ", Advertisements suppressed by an aggregate.");
7745 vty_out (vty, ")%s", VTY_NEWLINE);
718e3744 7746 }
718e3744 7747
adbac85e
DW
7748 /* If we are not using addpath then we can display Advertised to and that will
7749 * show what peers we advertised the bestpath to. If we are using addpath
7750 * though then we must display Advertised to on a path-by-path basis. */
7751 if (!bgp->addpath_tx_used[afi][safi])
718e3744 7752 {
adbac85e
DW
7753 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7754 {
7755 if (bgp_adj_out_lookup (peer, rn, 0))
b05a1c8b 7756 {
adbac85e 7757 if (json && !json_adv_to)
f1aa5d8a 7758 json_adv_to = json_object_new_object();
6410e93a 7759
adbac85e
DW
7760 route_vty_out_advertised_to(vty, peer, &first,
7761 " Advertised to non peer-group peers:\n ",
7762 json_adv_to);
b05a1c8b 7763 }
adbac85e 7764 }
036a4e7d 7765
adbac85e
DW
7766 if (json)
7767 {
7768 if (json_adv_to)
7769 {
7770 json_object_object_add(json, "advertisedTo", json_adv_to);
b05a1c8b 7771 }
adbac85e
DW
7772 }
7773 else
b05a1c8b 7774 {
adbac85e
DW
7775 if (first)
7776 vty_out (vty, " Not advertised to any peer");
7777 vty_out (vty, "%s", VTY_NEWLINE);
b05a1c8b
DS
7778 }
7779 }
718e3744 7780}
7781
7782/* Display specified route of BGP table. */
94f2b392 7783static int
fee0f4c6 7784bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
fd79ac91 7785 struct bgp_table *rib, const char *ip_str,
7786 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
7787 int prefix_check, enum bgp_path_type pathtype,
7788 u_char use_json)
718e3744 7789{
7790 int ret;
7791 int header;
7792 int display = 0;
7793 struct prefix match;
7794 struct bgp_node *rn;
7795 struct bgp_node *rm;
7796 struct bgp_info *ri;
718e3744 7797 struct bgp_table *table;
f1aa5d8a
DS
7798 json_object *json = NULL;
7799 json_object *json_paths = NULL;
718e3744 7800
718e3744 7801 /* Check IP address argument. */
7802 ret = str2prefix (ip_str, &match);
7803 if (! ret)
7804 {
7805 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
7806 return CMD_WARNING;
7807 }
7808
7809 match.family = afi2family (afi);
7810
b05a1c8b
DS
7811 if (use_json)
7812 {
7813 json = json_object_new_object();
7814 json_paths = json_object_new_array();
7815 }
b05a1c8b 7816
587ff0fd 7817 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
718e3744 7818 {
fee0f4c6 7819 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
718e3744 7820 {
7821 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
7822 continue;
7823
7824 if ((table = rn->info) != NULL)
7825 {
7826 header = 1;
7827
7828 if ((rm = bgp_node_match (table, &match)) != NULL)
7829 {
7830 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6c88b44d
CC
7831 {
7832 bgp_unlock_node (rm);
7833 continue;
7834 }
718e3744 7835
7836 for (ri = rm->info; ri; ri = ri->next)
7837 {
7838 if (header)
7839 {
7840 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
587ff0fd 7841 AFI_IP, safi, json);
718e3744 7842 header = 0;
7843 }
7844 display++;
4092b06c
DS
7845
7846 if (pathtype == BGP_PATH_ALL ||
7847 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7848 (pathtype == BGP_PATH_MULTIPATH &&
7849 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
587ff0fd 7850 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi, json_paths);
718e3744 7851 }
6c88b44d
CC
7852
7853 bgp_unlock_node (rm);
718e3744 7854 }
7855 }
7856 }
7857 }
7858 else
7859 {
7860 header = 1;
7861
fee0f4c6 7862 if ((rn = bgp_node_match (rib, &match)) != NULL)
718e3744 7863 {
7864 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
7865 {
7866 for (ri = rn->info; ri; ri = ri->next)
7867 {
7868 if (header)
7869 {
b05a1c8b 7870 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
718e3744 7871 header = 0;
7872 }
7873 display++;
4092b06c
DS
7874
7875 if (pathtype == BGP_PATH_ALL ||
7876 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7877 (pathtype == BGP_PATH_MULTIPATH &&
7878 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
b05a1c8b 7879 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
718e3744 7880 }
7881 }
6c88b44d
CC
7882
7883 bgp_unlock_node (rn);
718e3744 7884 }
7885 }
7886
e5eee9af 7887 if (use_json)
718e3744 7888 {
e5eee9af
DS
7889 if (display)
7890 json_object_object_add(json, "paths", json_paths);
7891
7892 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
f1aa5d8a 7893 json_object_free(json);
b05a1c8b
DS
7894 }
7895 else
7896 {
e5eee9af 7897 if (!display)
b05a1c8b
DS
7898 {
7899 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
7900 return CMD_WARNING;
7901 }
7902 }
7903
718e3744 7904 return CMD_SUCCESS;
7905}
7906
fee0f4c6 7907/* Display specified route of Main RIB */
94f2b392 7908static int
fd79ac91 7909bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
fee0f4c6 7910 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
7911 int prefix_check, enum bgp_path_type pathtype,
7912 u_char use_json)
fee0f4c6 7913{
7914 struct bgp *bgp;
7915
7916 /* BGP structure lookup. */
7917 if (view_name)
7918 {
7919 bgp = bgp_lookup_by_name (view_name);
7920 if (bgp == NULL)
7921 {
6aeb9e78 7922 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
fee0f4c6 7923 return CMD_WARNING;
7924 }
7925 }
7926 else
7927 {
7928 bgp = bgp_get_default ();
7929 if (bgp == NULL)
7930 {
7931 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7932 return CMD_WARNING;
7933 }
7934 }
7935
7936 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
b05a1c8b
DS
7937 afi, safi, prd, prefix_check, pathtype,
7938 use_json);
fee0f4c6 7939}
7940
718e3744 7941/* BGP route print out function. */
7942DEFUN (show_ip_bgp,
7943 show_ip_bgp_cmd,
b162fa78 7944 "show ip bgp [json]",
47fc97cc
DS
7945 SHOW_STR
7946 IP_STR
b05a1c8b
DS
7947 BGP_STR
7948 "JavaScript Object Notation\n")
47fc97cc 7949{
db7c8528 7950 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
718e3744 7951}
7952
f412b39a
DW
7953/*
7954 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 7955 * "show bgp ipv4 (unicast|multicast) [json]",
f412b39a
DW
7956 * SHOW_STR
7957 * BGP_STR
7958 * "Address family\n"
7959 * "Address Family modifier\n"
7960 * "Address Family modifier\n"
7961 * "JavaScript Object Notation\n"
7962 *
7963 */
718e3744 7964DEFUN (show_ip_bgp_ipv4,
7965 show_ip_bgp_ipv4_cmd,
6147e2c6 7966 "show ip bgp ipv4 <unicast|multicast> [json]",
718e3744 7967 SHOW_STR
7968 IP_STR
7969 BGP_STR
7970 "Address family\n"
7971 "Address Family modifier\n"
b05a1c8b
DS
7972 "Address Family modifier\n"
7973 "JavaScript Object Notation\n")
718e3744 7974{
db7c8528 7975 u_char uj = use_json(argc, argv);
b05a1c8b 7976
4dcadbef 7977 if (strncmp (argv[4]->arg, "m", 1) == 0)
5a646650 7978 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
db7c8528 7979 NULL, uj);
718e3744 7980
db7c8528 7981 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
718e3744 7982}
7983
47fc97cc 7984
718e3744 7985DEFUN (show_ip_bgp_route,
7986 show_ip_bgp_route_cmd,
b162fa78 7987 "show ip bgp A.B.C.D [json]",
718e3744 7988 SHOW_STR
7989 IP_STR
7990 BGP_STR
b05a1c8b
DS
7991 "Network in the BGP routing table to display\n"
7992 "JavaScript Object Notation\n")
718e3744 7993{
4dcadbef 7994 return bgp_show_route (vty, NULL, argv[3]->arg, AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
4092b06c
DS
7995}
7996
7997DEFUN (show_ip_bgp_route_pathtype,
7998 show_ip_bgp_route_pathtype_cmd,
6147e2c6 7999 "show ip bgp A.B.C.D <bestpath|multipath> [json]",
4092b06c
DS
8000 SHOW_STR
8001 IP_STR
8002 BGP_STR
8003 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8004 "Display only the bestpath\n"
b05a1c8b
DS
8005 "Display only multipaths\n"
8006 "JavaScript Object Notation\n")
4092b06c 8007{
db7c8528 8008 u_char uj = use_json(argc, argv);
b05a1c8b 8009
4dcadbef
DW
8010 if (strncmp (argv[4]->arg, "b", 1) == 0)
8011 return bgp_show_route (vty, NULL, argv[3]->arg, AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 8012 else
4dcadbef 8013 return bgp_show_route (vty, NULL, argv[3]->arg, AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8014}
8015
8016DEFUN (show_bgp_ipv4_safi_route_pathtype,
8017 show_bgp_ipv4_safi_route_pathtype_cmd,
6147e2c6 8018 "show bgp ipv4 <unicast|multicast> A.B.C.D <bestpath|multipath> [json]",
4092b06c
DS
8019 SHOW_STR
8020 BGP_STR
8021 "Address family\n"
8022 "Address Family modifier\n"
8023 "Address Family modifier\n"
8024 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8025 "Display only the bestpath\n"
b05a1c8b
DS
8026 "Display only multipaths\n"
8027 "JavaScript Object Notation\n")
4092b06c 8028{
db7c8528 8029 u_char uj = use_json(argc, argv);
b05a1c8b 8030
4dcadbef
DW
8031 if (strncmp (argv[3]->arg, "m", 1) == 0)
8032 if (strncmp (argv[5]->arg, "b", 1) == 0)
8033 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 8034 else
4dcadbef 8035 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c 8036 else
4dcadbef
DW
8037 if (strncmp (argv[5]->arg, "b", 1) == 0)
8038 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 8039 else
4dcadbef 8040 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
718e3744 8041}
8042
e3e29b32
LB
8043DEFUN (show_bgp_ipv4_prefix,
8044 show_bgp_ipv4_prefix_cmd,
b162fa78 8045 "show bgp ipv4 A.B.C.D/M [json]",
e3e29b32
LB
8046 SHOW_STR
8047 BGP_STR
8048 IP_STR
8049 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8050 JSON_STR)
8051{
4dcadbef 8052 return bgp_show_route (vty, NULL, argv[3]->arg, AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc, argv));
e3e29b32
LB
8053}
8054
8055DEFUN (show_bgp_ipv6_route,
8056 show_bgp_ipv6_route_cmd,
b162fa78 8057 "show bgp ipv6 X:X::X:X [json]",
e3e29b32
LB
8058 SHOW_STR
8059 BGP_STR
8060 "Address family\n"
8061 "Network in the BGP routing table to display\n"
8062 JSON_STR)
8063{
4dcadbef 8064 return bgp_show_route (vty, NULL, argv[3]->arg, AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json (argc, argv));
e3e29b32
LB
8065}
8066
8067DEFUN (show_bgp_ipv6_prefix,
8068 show_bgp_ipv6_prefix_cmd,
b162fa78 8069 "show bgp ipv6 X:X::X:X/M [json]",
e3e29b32
LB
8070 SHOW_STR
8071 BGP_STR
8072 IP_STR
8073 "IPv6 prefix <network>/<length>\n"
8074 JSON_STR)
8075{
4dcadbef 8076 return bgp_show_route (vty, NULL, argv[3]->arg, AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc,argv));
e3e29b32
LB
8077}
8078
f412b39a
DW
8079/*
8080 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 8081 * "show bgp ipv4 (unicast|multicast) A.B.C.D [json]",
f412b39a
DW
8082 * SHOW_STR
8083 * BGP_STR
8084 * "Address family\n"
8085 * "Address Family modifier\n"
8086 * "Address Family modifier\n"
8087 * "Network in the BGP routing table to display\n"
8088 * "JavaScript Object Notation\n"
8089 *
8090 */
718e3744 8091DEFUN (show_ip_bgp_ipv4_route,
8092 show_ip_bgp_ipv4_route_cmd,
6147e2c6 8093 "show ip bgp ipv4 <unicast|multicast> A.B.C.D [json]",
718e3744 8094 SHOW_STR
8095 IP_STR
8096 BGP_STR
8097 "Address family\n"
8098 "Address Family modifier\n"
8099 "Address Family modifier\n"
b05a1c8b
DS
8100 "Network in the BGP routing table to display\n"
8101 "JavaScript Object Notation\n")
718e3744 8102{
db7c8528 8103 u_char uj = use_json(argc, argv);
b05a1c8b 8104
4dcadbef
DW
8105 if (strncmp (argv[4]->arg, "m", 1) == 0)
8106 return bgp_show_route (vty, NULL, argv[5]->arg, AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
718e3744 8107
4dcadbef 8108 return bgp_show_route (vty, NULL, argv[5]->arg, AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
718e3744 8109}
8110
95cbbd2a 8111
718e3744 8112DEFUN (show_ip_bgp_vpnv4_all_route,
8113 show_ip_bgp_vpnv4_all_route_cmd,
b162fa78 8114 "show ip bgp vpnv4 all A.B.C.D [json]",
718e3744 8115 SHOW_STR
8116 IP_STR
8117 BGP_STR
8118 "Display VPNv4 NLRI specific information\n"
8119 "Display information about all VPNv4 NLRIs\n"
b05a1c8b
DS
8120 "Network in the BGP routing table to display\n"
8121 "JavaScript Object Notation\n")
718e3744 8122{
4dcadbef 8123 return bgp_show_route (vty, NULL, argv[5]->arg, AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8124}
8125
e3e29b32
LB
8126DEFUN (show_bgp_ipv4_vpn_route,
8127 show_bgp_ipv4_vpn_route_cmd,
b162fa78 8128 "show bgp ipv4 vpn A.B.C.D [json]",
e3e29b32
LB
8129 SHOW_STR
8130 BGP_STR
8131 "Address Family\n"
8132 "Display VPN NLRI specific information\n"
8133 "Network in the BGP routing table to display\n"
8134 JSON_STR)
8135{
4dcadbef 8136 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json (argc, argv));
e3e29b32
LB
8137}
8138
8139DEFUN (show_bgp_ipv6_vpn_route,
8140 show_bgp_ipv6_vpn_route_cmd,
b162fa78 8141 "show bgp ipv6 vpn X:X::X:X [json]",
e3e29b32
LB
8142 SHOW_STR
8143 BGP_STR
8144 "Address Family\n"
8145 "Display VPN NLRI specific information\n"
8146 "Network in the BGP routing table to display\n"
8147 JSON_STR)
8148{
4dcadbef 8149 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP6, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json (argc, argv));
e3e29b32
LB
8150}
8151
8152DEFUN (show_bgp_ipv4_vpn_rd_route,
8153 show_bgp_ipv4_vpn_rd_route_cmd,
b162fa78 8154 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn A.B.C.D [json]",
e3e29b32
LB
8155 SHOW_STR
8156 BGP_STR
8157 IP_STR
8158 "Display VPN NLRI specific information\n"
8159 "Display information for a route distinguisher\n"
8160 "VPN Route Distinguisher\n"
8161 "Network in the BGP routing table to display\n"
8162 JSON_STR)
8163{
8164 int ret;
8165 struct prefix_rd prd;
8166
4dcadbef 8167 ret = str2prefix_rd (argv[5]->arg, &prd);
e3e29b32
LB
8168 if (! ret)
8169 {
8170 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8171 return CMD_WARNING;
8172 }
4dcadbef 8173 return bgp_show_route (vty, NULL, argv[6]->arg, AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json (argc, argv));
e3e29b32
LB
8174}
8175
8176DEFUN (show_bgp_ipv6_vpn_rd_route,
8177 show_bgp_ipv6_vpn_rd_route_cmd,
b162fa78 8178 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn X:X::X:X [json]",
e3e29b32
LB
8179 SHOW_STR
8180 BGP_STR
8181 "Address Family\n"
8182 "Display VPN NLRI specific information\n"
8183 "Display information for a route distinguisher\n"
8184 "VPN Route Distinguisher\n"
8185 "Network in the BGP routing table to display\n"
8186 JSON_STR)
8187{
8188 int ret;
8189 struct prefix_rd prd;
8190
4dcadbef 8191 ret = str2prefix_rd (argv[5]->arg, &prd);
e3e29b32
LB
8192 if (! ret)
8193 {
8194 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8195 return CMD_WARNING;
8196 }
4dcadbef 8197 return bgp_show_route (vty, NULL, argv[6]->arg, AFI_IP6, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json (argc, argv));
e3e29b32 8198}
4092b06c 8199
718e3744 8200DEFUN (show_ip_bgp_vpnv4_rd_route,
8201 show_ip_bgp_vpnv4_rd_route_cmd,
b162fa78 8202 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D [json]",
718e3744 8203 SHOW_STR
8204 IP_STR
8205 BGP_STR
8206 "Display VPNv4 NLRI specific information\n"
8207 "Display information for a route distinguisher\n"
8208 "VPN Route Distinguisher\n"
b05a1c8b
DS
8209 "Network in the BGP routing table to display\n"
8210 "JavaScript Object Notation\n")
718e3744 8211{
8212 int ret;
8213 struct prefix_rd prd;
db7c8528 8214 u_char uj= use_json(argc, argv);
718e3744 8215
4dcadbef 8216 ret = str2prefix_rd (argv[5]->arg, &prd);
718e3744 8217 if (! ret)
8218 {
8219 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8220 return CMD_WARNING;
8221 }
4dcadbef 8222 return bgp_show_route (vty, NULL, argv[6]->arg, AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, uj);
718e3744 8223}
8224
8225DEFUN (show_ip_bgp_prefix,
8226 show_ip_bgp_prefix_cmd,
b162fa78 8227 "show ip bgp A.B.C.D/M [json]",
718e3744 8228 SHOW_STR
8229 IP_STR
8230 BGP_STR
b05a1c8b
DS
8231 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8232 "JavaScript Object Notation\n")
718e3744 8233{
4dcadbef 8234 return bgp_show_route (vty, NULL, argv[3]->arg, AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
4092b06c
DS
8235}
8236
8237DEFUN (show_ip_bgp_prefix_pathtype,
8238 show_ip_bgp_prefix_pathtype_cmd,
6147e2c6 8239 "show ip bgp A.B.C.D/M <bestpath|multipath> [json]",
4092b06c
DS
8240 SHOW_STR
8241 IP_STR
8242 BGP_STR
8243 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8244 "Display only the bestpath\n"
b05a1c8b
DS
8245 "Display only multipaths\n"
8246 "JavaScript Object Notation\n")
4092b06c 8247{
db7c8528 8248 u_char uj = use_json(argc, argv);
4dcadbef
DW
8249 if (strncmp (argv[4]->arg, "b", 1) == 0)
8250 return bgp_show_route (vty, NULL, argv[3]->arg, AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8251 else
4dcadbef 8252 return bgp_show_route (vty, NULL, argv[3]->arg, AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
718e3744 8253}
8254
f412b39a
DW
8255/*
8256 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 8257 * "show bgp ipv4 (unicast|multicast) A.B.C.D/M [json]",
f412b39a
DW
8258 * SHOW_STR
8259 * BGP_STR
8260 * "Address family\n"
8261 * "Address Family modifier\n"
8262 * "Address Family modifier\n"
8263 * "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8264 * "JavaScript Object Notation\n"
8265 *
8266 */
718e3744 8267DEFUN (show_ip_bgp_ipv4_prefix,
8268 show_ip_bgp_ipv4_prefix_cmd,
6147e2c6 8269 "show ip bgp ipv4 <unicast|multicast> A.B.C.D/M [json]",
718e3744 8270 SHOW_STR
8271 IP_STR
8272 BGP_STR
8273 "Address family\n"
8274 "Address Family modifier\n"
8275 "Address Family modifier\n"
b05a1c8b
DS
8276 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8277 "JavaScript Object Notation\n")
718e3744 8278{
db7c8528 8279 u_char uj = use_json(argc, argv);
b05a1c8b 8280
4dcadbef
DW
8281 if (strncmp (argv[4]->arg, "m", 1) == 0)
8282 return bgp_show_route (vty, NULL, argv[5]->arg, AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
718e3744 8283
4dcadbef 8284 return bgp_show_route (vty, NULL, argv[5]->arg, AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
718e3744 8285}
8286
95cbbd2a 8287
f412b39a
DW
8288/*
8289 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 8290 * "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) [json]",
f412b39a
DW
8291 * SHOW_STR
8292 * BGP_STR
8293 * "Address family\n"
8294 * "Address Family modifier\n"
8295 * "Address Family modifier\n"
8296 * "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8297 * "Display only the bestpath\n"
8298 * "Display only multipaths\n"
8299 * "JavaScript Object Notation\n"
8300 *
8301 */
4092b06c
DS
8302DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
8303 show_ip_bgp_ipv4_prefix_pathtype_cmd,
6147e2c6 8304 "show ip bgp ipv4 <unicast|multicast> A.B.C.D/M <bestpath|multipath> [json]",
4092b06c
DS
8305 SHOW_STR
8306 IP_STR
8307 BGP_STR
8308 "Address family\n"
8309 "Address Family modifier\n"
8310 "Address Family modifier\n"
8311 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8312 "Display only the bestpath\n"
b05a1c8b
DS
8313 "Display only multipaths\n"
8314 "JavaScript Object Notation\n")
4092b06c 8315{
db7c8528 8316 u_char uj = use_json(argc, argv);
b05a1c8b 8317
4dcadbef
DW
8318 if (strncmp (argv[4]->arg, "m", 1) == 0)
8319 if (strncmp (argv[6]->arg, "b", 1) == 0)
8320 return bgp_show_route (vty, NULL, argv[5]->arg, AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8321 else
4dcadbef 8322 return bgp_show_route (vty, NULL, argv[5]->arg, AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c 8323 else
4dcadbef
DW
8324 if (strncmp (argv[6]->arg, "b", 1) == 0)
8325 return bgp_show_route (vty, NULL, argv[5]->arg, AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8326 else
4dcadbef 8327 return bgp_show_route (vty, NULL, argv[5]->arg, AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8328}
8329
4092b06c 8330
718e3744 8331DEFUN (show_ip_bgp_vpnv4_all_prefix,
8332 show_ip_bgp_vpnv4_all_prefix_cmd,
b162fa78 8333 "show ip bgp vpnv4 all A.B.C.D/M [json]",
718e3744 8334 SHOW_STR
8335 IP_STR
8336 BGP_STR
8337 "Display VPNv4 NLRI specific information\n"
8338 "Display information about all VPNv4 NLRIs\n"
b05a1c8b
DS
8339 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8340 "JavaScript Object Notation\n")
718e3744 8341{
4dcadbef 8342 return bgp_show_route (vty, NULL, argv[5]->arg, AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8343}
8344
8345DEFUN (show_ip_bgp_vpnv4_rd_prefix,
8346 show_ip_bgp_vpnv4_rd_prefix_cmd,
b162fa78 8347 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M [json]",
718e3744 8348 SHOW_STR
8349 IP_STR
8350 BGP_STR
8351 "Display VPNv4 NLRI specific information\n"
8352 "Display information for a route distinguisher\n"
8353 "VPN Route Distinguisher\n"
b05a1c8b
DS
8354 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8355 "JavaScript Object Notation\n")
718e3744 8356{
8357 int ret;
8358 struct prefix_rd prd;
8359
4dcadbef 8360 ret = str2prefix_rd (argv[5]->arg, &prd);
718e3744 8361 if (! ret)
8362 {
8363 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8364 return CMD_WARNING;
8365 }
4dcadbef 8366 return bgp_show_route (vty, NULL, argv[6]->arg, AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8367}
8368
8369DEFUN (show_ip_bgp_view,
8386ac43 8370 show_ip_bgp_instance_cmd,
b162fa78 8371 "show ip bgp " BGP_INSTANCE_CMD " [json]",
718e3744 8372 SHOW_STR
8373 IP_STR
8374 BGP_STR
8386ac43 8375 BGP_INSTANCE_HELP_STR
b05a1c8b 8376 "JavaScript Object Notation\n")
718e3744 8377{
bb46e94f 8378 struct bgp *bgp;
8379
8380 /* BGP structure lookup. */
4dcadbef 8381 bgp = bgp_lookup_by_name (argv[4]->arg);
bb46e94f 8382 if (bgp == NULL)
8383 {
4dcadbef 8384 vty_out (vty, "Can't find BGP instance %s%s", argv[4]->arg, VTY_NEWLINE);
bb46e94f 8385 return CMD_WARNING;
8386 }
8387
db7c8528 8388 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
718e3744 8389}
8390
f186de26 8391DEFUN (show_ip_bgp_instance_all,
8392 show_ip_bgp_instance_all_cmd,
b162fa78 8393 "show ip bgp " BGP_INSTANCE_ALL_CMD " [json]",
f186de26 8394 SHOW_STR
8395 IP_STR
8396 BGP_STR
8397 BGP_INSTANCE_ALL_HELP_STR
8398 "JavaScript Object Notation\n")
8399{
8400 u_char uj = use_json(argc, argv);
8401
8402 bgp_show_all_instances_routes_vty (vty, AFI_IP, SAFI_UNICAST, uj);
8403 return CMD_SUCCESS;
8404}
8405
8386ac43 8406DEFUN (show_ip_bgp_instance_route,
8407 show_ip_bgp_instance_route_cmd,
b162fa78 8408 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D [json]",
718e3744 8409 SHOW_STR
8410 IP_STR
8411 BGP_STR
8386ac43 8412 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8413 "Network in the BGP routing table to display\n"
8414 "JavaScript Object Notation\n")
718e3744 8415{
4dcadbef 8416 return bgp_show_route (vty, argv[4]->arg, argv[5]->arg, AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8417}
8418
8386ac43 8419DEFUN (show_ip_bgp_instance_route_pathtype,
8420 show_ip_bgp_instance_route_pathtype_cmd,
6147e2c6 8421 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D <bestpath|multipath> [json]",
50ef26d4 8422 SHOW_STR
8423 IP_STR
8424 BGP_STR
8386ac43 8425 BGP_INSTANCE_HELP_STR
50ef26d4 8426 "Network in the BGP routing table to display\n"
8427 "Display only the bestpath\n"
8428 "Display only multipaths\n"
8429 "JavaScript Object Notation\n")
8430{
8431 u_char uj = use_json(argc, argv);
8432
4dcadbef
DW
8433 if (strncmp (argv[6]->arg, "b", 1) == 0)
8434 return bgp_show_route (vty, argv[4]->arg, argv[5]->arg, AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
50ef26d4 8435 else
4dcadbef 8436 return bgp_show_route (vty, argv[4]->arg, argv[5]->arg, AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
50ef26d4 8437}
8438
8386ac43 8439DEFUN (show_ip_bgp_instance_prefix,
8440 show_ip_bgp_instance_prefix_cmd,
b162fa78 8441 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M [json]",
718e3744 8442 SHOW_STR
8443 IP_STR
8444 BGP_STR
8386ac43 8445 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8446 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8447 "JavaScript Object Notation\n")
718e3744 8448{
4dcadbef 8449 return bgp_show_route (vty, argv[4]->arg, argv[5]->arg, AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8450}
8451
8386ac43 8452DEFUN (show_ip_bgp_instance_prefix_pathtype,
8453 show_ip_bgp_instance_prefix_pathtype_cmd,
6147e2c6 8454 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M <bestpath|multipath> [json]",
50ef26d4 8455 SHOW_STR
8456 IP_STR
8457 BGP_STR
8386ac43 8458 BGP_INSTANCE_HELP_STR
50ef26d4 8459 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8460 "Display only the bestpath\n"
8461 "Display only multipaths\n"
8462 "JavaScript Object Notation\n")
8463{
8464 u_char uj = use_json(argc, argv);
4dcadbef
DW
8465 if (strncmp (argv[6]->arg, "b", 1) == 0)
8466 return bgp_show_route (vty, argv[4]->arg, argv[5]->arg, AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
50ef26d4 8467 else
4dcadbef 8468 return bgp_show_route (vty, argv[4]->arg, argv[5]->arg, AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
50ef26d4 8469}
8470
718e3744 8471#ifdef HAVE_IPV6
f412b39a
DW
8472/*
8473 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 8474 * "show bgp ipv6 [json]",
f412b39a
DW
8475 * SHOW_STR
8476 * BGP_STR
8477 * "Address family\n"
8478 * "JavaScript Object Notation\n"
8479 *
8480 */
718e3744 8481DEFUN (show_bgp,
8482 show_bgp_cmd,
b162fa78 8483 "show bgp [json]",
718e3744 8484 SHOW_STR
b05a1c8b
DS
8485 BGP_STR
8486 "JavaScript Object Notation\n")
718e3744 8487{
5a646650 8488 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
db7c8528 8489 NULL, use_json(argc, argv));
718e3744 8490}
8491
718e3744 8492
95cbbd2a
ML
8493DEFUN (show_bgp_ipv6_safi,
8494 show_bgp_ipv6_safi_cmd,
6147e2c6 8495 "show bgp ipv6 <unicast|multicast> [json]",
95cbbd2a
ML
8496 SHOW_STR
8497 BGP_STR
8498 "Address family\n"
8499 "Address Family modifier\n"
47fc97cc 8500 "Address Family modifier\n"
b05a1c8b 8501 "JavaScript Object Notation\n")
47fc97cc 8502{
db7c8528 8503 u_char uj = use_json(argc, argv);
4dcadbef 8504 if (strncmp (argv[3]->arg, "m", 1) == 0)
47fc97cc 8505 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
db7c8528 8506 NULL, uj);
47fc97cc 8507
db7c8528 8508 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
95cbbd2a
ML
8509}
8510
47e9b292
DW
8511static void
8512bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty)
8513{
8514 vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our"
8515 " next release%sPlese use 'show bgp ipv6' instead%s%s",
8516 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8517}
8518
718e3744 8519/* old command */
8520DEFUN (show_ipv6_bgp,
8521 show_ipv6_bgp_cmd,
b162fa78 8522 "show ipv6 bgp [json]",
718e3744 8523 SHOW_STR
8524 IP_STR
b05a1c8b
DS
8525 BGP_STR
8526 "JavaScript Object Notation\n")
718e3744 8527{
47e9b292 8528 bgp_show_ipv6_bgp_deprecate_warning(vty);
5a646650 8529 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
db7c8528 8530 NULL, use_json(argc, argv));
718e3744 8531}
8532
8533DEFUN (show_bgp_route,
8534 show_bgp_route_cmd,
b162fa78 8535 "show bgp X:X::X:X [json]",
718e3744 8536 SHOW_STR
8537 BGP_STR
b05a1c8b
DS
8538 "Network in the BGP routing table to display\n"
8539 "JavaScript Object Notation\n")
718e3744 8540{
4dcadbef 8541 return bgp_show_route (vty, NULL, argv[2]->arg, AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8542}
8543
95cbbd2a
ML
8544DEFUN (show_bgp_ipv6_safi_route,
8545 show_bgp_ipv6_safi_route_cmd,
6147e2c6 8546 "show bgp ipv6 <unicast|multicast> X:X::X:X [json]",
95cbbd2a
ML
8547 SHOW_STR
8548 BGP_STR
8549 "Address family\n"
8550 "Address Family modifier\n"
8551 "Address Family modifier\n"
b05a1c8b
DS
8552 "Network in the BGP routing table to display\n"
8553 "JavaScript Object Notation\n")
95cbbd2a 8554{
db7c8528 8555 u_char uj = use_json(argc, argv);
4dcadbef
DW
8556 if (strncmp (argv[3]->arg, "m", 1) == 0)
8557 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
95cbbd2a 8558
4dcadbef 8559 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
4092b06c
DS
8560}
8561
f412b39a
DW
8562/*
8563 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 8564 * "show bgp ipv6 X:X::X:X (bestpath|multipath) [json]",
f412b39a
DW
8565 * SHOW_STR
8566 * BGP_STR
8567 * "Address family\n"
8568 * "Network in the BGP routing table to display\n"
8569 * "Display only the bestpath\n"
8570 * "Display only multipaths\n"
8571 * "JavaScript Object Notation\n"
8572 *
8573 */
4092b06c
DS
8574DEFUN (show_bgp_route_pathtype,
8575 show_bgp_route_pathtype_cmd,
6147e2c6 8576 "show bgp X:X::X:X <bestpath|multipath> [json]",
4092b06c
DS
8577 SHOW_STR
8578 BGP_STR
8579 "Network in the BGP routing table to display\n"
8580 "Display only the bestpath\n"
b05a1c8b
DS
8581 "Display only multipaths\n"
8582 "JavaScript Object Notation\n")
4092b06c 8583{
db7c8528 8584 u_char uj = use_json(argc, argv);
4dcadbef
DW
8585 if (strncmp (argv[3]->arg, "b", 1) == 0)
8586 return bgp_show_route (vty, NULL, argv[2]->arg, AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 8587 else
4dcadbef 8588 return bgp_show_route (vty, NULL, argv[2]->arg, AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8589}
8590
4092b06c
DS
8591
8592DEFUN (show_bgp_ipv6_safi_route_pathtype,
8593 show_bgp_ipv6_safi_route_pathtype_cmd,
6147e2c6 8594 "show bgp ipv6 <unicast|multicast> X:X::X:X <bestpath|multipath> [json]",
4092b06c
DS
8595 SHOW_STR
8596 BGP_STR
8597 "Address family\n"
8598 "Address Family modifier\n"
8599 "Address Family modifier\n"
8600 "Network in the BGP routing table to display\n"
8601 "Display only the bestpath\n"
b05a1c8b
DS
8602 "Display only multipaths\n"
8603 "JavaScript Object Notation\n")
4092b06c 8604{
db7c8528 8605 u_char uj = use_json(argc, argv);
4dcadbef
DW
8606 if (strncmp (argv[3]->arg, "m", 1) == 0)
8607 if (strncmp (argv[5]->arg, "b", 1) == 0)
8608 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 8609 else
4dcadbef 8610 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
4092b06c 8611 else
4dcadbef
DW
8612 if (strncmp (argv[5]->arg, "b", 1) == 0)
8613 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
4092b06c 8614 else
4dcadbef 8615 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
95cbbd2a
ML
8616}
8617
718e3744 8618/* old command */
8619DEFUN (show_ipv6_bgp_route,
8620 show_ipv6_bgp_route_cmd,
b162fa78 8621 "show ipv6 bgp X:X::X:X [json]",
718e3744 8622 SHOW_STR
8623 IP_STR
8624 BGP_STR
b05a1c8b
DS
8625 "Network in the BGP routing table to display\n"
8626 "JavaScript Object Notation\n")
718e3744 8627{
47e9b292 8628 bgp_show_ipv6_bgp_deprecate_warning(vty);
4dcadbef 8629 return bgp_show_route (vty, NULL, argv[3]->arg, AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8630}
8631
8632DEFUN (show_bgp_prefix,
8633 show_bgp_prefix_cmd,
b162fa78 8634 "show bgp X:X::X:X/M [json]",
718e3744 8635 SHOW_STR
8636 BGP_STR
b05a1c8b
DS
8637 "IPv6 prefix <network>/<length>\n"
8638 "JavaScript Object Notation\n")
718e3744 8639{
4dcadbef 8640 return bgp_show_route (vty, NULL, argv[2]->arg, AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8641}
8642
95cbbd2a
ML
8643DEFUN (show_bgp_ipv6_safi_prefix,
8644 show_bgp_ipv6_safi_prefix_cmd,
6147e2c6 8645 "show bgp ipv6 <unicast|multicast> X:X::X:X/M [json]",
95cbbd2a
ML
8646 SHOW_STR
8647 BGP_STR
8648 "Address family\n"
8649 "Address Family modifier\n"
8650 "Address Family modifier\n"
b05a1c8b
DS
8651 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8652 "JavaScript Object Notation\n")
95cbbd2a 8653{
db7c8528 8654 u_char uj = use_json(argc, argv);
4dcadbef
DW
8655 if (strncmp (argv[3]->arg, "m", 1) == 0)
8656 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
95cbbd2a 8657
4dcadbef 8658 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
4092b06c
DS
8659}
8660
f412b39a
DW
8661/*
8662 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 8663 * "show bgp ipv6 X:X::X:X/M (bestpath|multipath) [json]",
f412b39a
DW
8664 * SHOW_STR
8665 * BGP_STR
8666 * "Address family\n"
8667 * "IPv6 prefix <network>/<length>\n"
8668 * "Display only the bestpath\n"
8669 * "Display only multipaths\n"
8670 * "JavaScript Object Notation\n"
8671 *
8672 */
4092b06c
DS
8673DEFUN (show_bgp_prefix_pathtype,
8674 show_bgp_prefix_pathtype_cmd,
6147e2c6 8675 "show bgp X:X::X:X/M <bestpath|multipath> [json]",
4092b06c
DS
8676 SHOW_STR
8677 BGP_STR
8678 "IPv6 prefix <network>/<length>\n"
8679 "Display only the bestpath\n"
b05a1c8b
DS
8680 "Display only multipaths\n"
8681 "JavaScript Object Notation\n")
4092b06c 8682{
db7c8528 8683 u_char uj = use_json(argc, argv);
4dcadbef
DW
8684 if (strncmp (argv[3]->arg, "b", 1) == 0)
8685 return bgp_show_route (vty, NULL, argv[2]->arg, AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8686 else
4dcadbef 8687 return bgp_show_route (vty, NULL, argv[2]->arg, AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c
DS
8688}
8689
4092b06c
DS
8690
8691DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8692 show_bgp_ipv6_safi_prefix_pathtype_cmd,
6147e2c6 8693 "show bgp ipv6 <unicast|multicast> X:X::X:X/M <bestpath|multipath> [json]",
4092b06c
DS
8694 SHOW_STR
8695 BGP_STR
8696 "Address family\n"
8697 "Address Family modifier\n"
8698 "Address Family modifier\n"
8699 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8700 "Display only the bestpath\n"
b05a1c8b
DS
8701 "Display only multipaths\n"
8702 "JavaScript Object Notation\n")
4092b06c 8703{
db7c8528 8704 u_char uj = use_json(argc, argv);
4dcadbef
DW
8705 if (strncmp (argv[3]->arg, "m", 1) == 0)
8706 if (strncmp (argv[5]->arg, "b", 1) == 0)
8707 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8708 else
4dcadbef 8709 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
4092b06c 8710 else
4dcadbef
DW
8711 if (strncmp (argv[5]->arg, "b", 1) == 0)
8712 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
4092b06c 8713 else
4dcadbef 8714 return bgp_show_route (vty, NULL, argv[4]->arg, AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
95cbbd2a
ML
8715}
8716
718e3744 8717/* old command */
8718DEFUN (show_ipv6_bgp_prefix,
8719 show_ipv6_bgp_prefix_cmd,
b162fa78 8720 "show ipv6 bgp X:X::X:X/M [json]",
718e3744 8721 SHOW_STR
8722 IP_STR
8723 BGP_STR
b05a1c8b
DS
8724 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8725 "JavaScript Object Notation\n")
718e3744 8726{
47e9b292 8727 bgp_show_ipv6_bgp_deprecate_warning(vty);
4dcadbef 8728 return bgp_show_route (vty, NULL, argv[3]->arg, AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 8729}
8730
f412b39a
DW
8731/*
8732 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 8733 * "show bgp " BGP_INSTANCE_CMD " ipv6 [json]",
f412b39a
DW
8734 * SHOW_STR
8735 * BGP_STR
8736 * BGP_INSTANCE_HELP_STR
8737 * "Address family\n"
8738 * "JavaScript Object Notation\n"
8739 *
8740 */
bb46e94f 8741DEFUN (show_bgp_view,
8386ac43 8742 show_bgp_instance_cmd,
b162fa78 8743 "show bgp " BGP_INSTANCE_CMD " [json]",
bb46e94f 8744 SHOW_STR
8745 BGP_STR
8386ac43 8746 BGP_INSTANCE_HELP_STR
b05a1c8b 8747 "JavaScript Object Notation\n")
bb46e94f 8748{
8749 struct bgp *bgp;
8750
8751 /* BGP structure lookup. */
4dcadbef 8752 bgp = bgp_lookup_by_name (argv[3]->arg);
bb46e94f 8753 if (bgp == NULL)
db7c8528 8754 {
4dcadbef 8755 vty_out (vty, "Can't find BGP instance %s%s", argv[3]->arg, VTY_NEWLINE);
db7c8528
DS
8756 return CMD_WARNING;
8757 }
8758
8759 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
bb46e94f 8760}
8761
f186de26 8762DEFUN (show_bgp_instance_all,
8763 show_bgp_instance_all_cmd,
b162fa78 8764 "show bgp " BGP_INSTANCE_ALL_CMD " [json]",
f186de26 8765 SHOW_STR
8766 BGP_STR
8767 BGP_INSTANCE_ALL_HELP_STR
8768 "JavaScript Object Notation\n")
8769{
8770 u_char uj = use_json(argc, argv);
8771
8772 bgp_show_all_instances_routes_vty (vty, AFI_IP6, SAFI_UNICAST, uj);
8773 return CMD_SUCCESS;
8774}
8775
bb46e94f 8776
f412b39a
DW
8777/*
8778 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 8779 * "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X [json]",
f412b39a
DW
8780 * SHOW_STR
8781 * BGP_STR
8782 * BGP_INSTANCE_HELP_STR
8783 * "Address family\n"
8784 * "Network in the BGP routing table to display\n"
8785 * "JavaScript Object Notation\n"
8786 *
8787 */
8386ac43 8788DEFUN (show_bgp_instance_route,
8789 show_bgp_instance_route_cmd,
b162fa78 8790 "show bgp " BGP_INSTANCE_CMD " X:X::X:X [json]",
bb46e94f 8791 SHOW_STR
8792 BGP_STR
8386ac43 8793 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8794 "Network in the BGP routing table to display\n"
8795 "JavaScript Object Notation\n")
bb46e94f 8796{
4dcadbef 8797 return bgp_show_route (vty, argv[3]->arg, argv[4]->arg, AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
bb46e94f 8798}
8799
bb46e94f 8800
f412b39a
DW
8801/*
8802 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 8803 * "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X (bestpath|multipath) [json]",
f412b39a
DW
8804 * SHOW_STR
8805 * BGP_STR
8806 * BGP_INSTANCE_HELP_STR
8807 * "Address family\n"
8808 * "Network in the BGP routing table to display\n"
8809 * "Display only the bestpath\n"
8810 * "Display only multipaths\n"
8811 * "JavaScript Object Notation\n"
8812 *
8813 */
8386ac43 8814DEFUN (show_bgp_instance_route_pathtype,
8815 show_bgp_instance_route_pathtype_cmd,
6147e2c6 8816 "show bgp " BGP_INSTANCE_CMD " X:X::X:X <bestpath|multipath> [json]",
50ef26d4 8817 SHOW_STR
8818 BGP_STR
8386ac43 8819 BGP_INSTANCE_HELP_STR
50ef26d4 8820 "Network in the BGP routing table to display\n"
8821 "Display only the bestpath\n"
8822 "Display only multipaths\n"
8823 "JavaScript Object Notation\n")
8824{
8825 u_char uj = use_json(argc, argv);
4dcadbef
DW
8826 if (strncmp (argv[5]->arg, "b", 1) == 0)
8827 return bgp_show_route (vty, argv[3]->arg, argv[4]->arg, AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
50ef26d4 8828 else
4dcadbef 8829 return bgp_show_route (vty, argv[3]->arg, argv[4]->arg, AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
50ef26d4 8830}
8831
50ef26d4 8832
f412b39a
DW
8833/*
8834 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 8835 * "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M [json]",
f412b39a
DW
8836 * SHOW_STR
8837 * BGP_STR
8838 * BGP_INSTANCE_HELP_STR
8839 * "Address family\n"
8840 * "IPv6 prefix <network>/<length>\n"
8841 * "JavaScript Object Notation\n"
8842 *
8843 */
8386ac43 8844DEFUN (show_bgp_instance_prefix,
8845 show_bgp_instance_prefix_cmd,
b162fa78 8846 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M [json]",
bb46e94f 8847 SHOW_STR
8848 BGP_STR
8386ac43 8849 BGP_INSTANCE_HELP_STR
b05a1c8b
DS
8850 "IPv6 prefix <network>/<length>\n"
8851 "JavaScript Object Notation\n")
bb46e94f 8852{
4dcadbef 8853 return bgp_show_route (vty, argv[3]->arg, argv[4]->arg, AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
bb46e94f 8854}
8855
bb46e94f 8856
f412b39a
DW
8857/*
8858 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 8859 * "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M (bestpath|multipath) [json]",
f412b39a
DW
8860 * SHOW_STR
8861 * BGP_STR
8862 * BGP_INSTANCE_HELP_STR
8863 * "Address family\n"
8864 * "IPv6 prefix <network>/<length>\n"
8865 * "Display only the bestpath\n"
8866 * "Display only multipaths\n"
8867 * "JavaScript Object Notation\n"
8868 *
8869 */
8386ac43 8870DEFUN (show_bgp_instance_prefix_pathtype,
8871 show_bgp_instance_prefix_pathtype_cmd,
6147e2c6 8872 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M <bestpath|multipath> [json]",
50ef26d4 8873 SHOW_STR
8874 BGP_STR
8386ac43 8875 BGP_INSTANCE_HELP_STR
50ef26d4 8876 "IPv6 prefix <network>/<length>\n"
8877 "Display only the bestpath\n"
8878 "Display only multipaths\n"
8879 "JavaScript Object Notation\n")
8880{
8881 u_char uj = use_json(argc, argv);
4dcadbef
DW
8882 if (strncmp (argv[5]->arg, "b", 1) == 0)
8883 return bgp_show_route (vty, argv[3]->arg, argv[4]->arg, AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
50ef26d4 8884 else
4dcadbef 8885 return bgp_show_route (vty, argv[3]->arg, argv[4]->arg, AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
50ef26d4 8886}
8887
50ef26d4 8888
f412b39a
DW
8889/*
8890 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
8891 * "show bgp " BGP_INSTANCE_CMD " ipv6 prefix-list WORD",
8892 * SHOW_STR
8893 * BGP_STR
8894 * BGP_INSTANCE_HELP_STR
8895 * "Address family\n"
8896 * "Display routes conforming to the prefix-list\n"
8897 * "IPv6 prefix-list name\n"
8898 *
8899 */
8386ac43 8900DEFUN (show_bgp_instance_prefix_list,
8901 show_bgp_instance_prefix_list_cmd,
8902 "show bgp " BGP_INSTANCE_CMD " prefix-list WORD",
50ef26d4 8903 SHOW_STR
8904 BGP_STR
8386ac43 8905 BGP_INSTANCE_HELP_STR
50ef26d4 8906 "Display routes conforming to the prefix-list\n"
8907 "IPv6 prefix-list name\n")
8908{
4dcadbef 8909 return bgp_show_prefix_list (vty, argv[3]->arg, argv[5]->arg, AFI_IP6, SAFI_UNICAST,
50ef26d4 8910 bgp_show_type_prefix_list);
8911}
8912
50ef26d4 8913
f412b39a
DW
8914/*
8915 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
8916 * "show bgp " BGP_INSTANCE_CMD " ipv6 filter-list WORD",
8917 * SHOW_STR
8918 * BGP_STR
8919 * BGP_INSTANCE_HELP_STR
8920 * "Address family\n"
8921 * "Display routes conforming to the filter-list\n"
8922 * "Regular expression access list name\n"
8923 *
8924 */
8386ac43 8925DEFUN (show_bgp_instance_filter_list,
8926 show_bgp_instance_filter_list_cmd,
8927 "show bgp " BGP_INSTANCE_CMD " filter-list WORD",
50ef26d4 8928 SHOW_STR
8929 BGP_STR
8386ac43 8930 BGP_INSTANCE_HELP_STR
50ef26d4 8931 "Display routes conforming to the filter-list\n"
8932 "Regular expression access list name\n")
8933{
4dcadbef 8934 return bgp_show_filter_list (vty, argv[3]->arg, argv[5]->arg, AFI_IP6, SAFI_UNICAST,
50ef26d4 8935 bgp_show_type_filter_list);
8936}
8937
50ef26d4 8938
f412b39a
DW
8939/*
8940 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
8941 * "show bgp " BGP_INSTANCE_CMD " ipv6 route-map WORD",
8942 * SHOW_STR
8943 * BGP_STR
8944 * BGP_INSTANCE_HELP_STR
8945 * "Address family\n"
8946 * "Display routes matching the route-map\n"
8947 * "A route-map to match on\n"
8948 *
8949 */
8386ac43 8950DEFUN (show_bgp_instance_route_map,
8951 show_bgp_instance_route_map_cmd,
8952 "show bgp " BGP_INSTANCE_CMD " route-map WORD",
50ef26d4 8953 SHOW_STR
8954 BGP_STR
8386ac43 8955 BGP_INSTANCE_HELP_STR
50ef26d4 8956 "Display routes matching the route-map\n"
8957 "A route-map to match on\n")
8958{
4dcadbef 8959 return bgp_show_route_map (vty, argv[3]->arg, argv[5]->arg, AFI_IP6, SAFI_UNICAST,
50ef26d4 8960 bgp_show_type_route_map);
8961}
8962
50ef26d4 8963
f412b39a
DW
8964/*
8965 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
8966 * "show bgp " BGP_INSTANCE_CMD " ipv6 community-list (<1-500>|WORD)",
8967 * SHOW_STR
8968 * BGP_STR
8969 * BGP_INSTANCE_HELP_STR
8970 * "Address family\n"
8971 * "Display routes matching the community-list\n"
8972 * "community-list number\n"
8973 * "community-list name\n"
8974 *
8975 */
8386ac43 8976DEFUN (show_bgp_instance_community_list,
8977 show_bgp_instance_community_list_cmd,
6147e2c6 8978 "show bgp " BGP_INSTANCE_CMD " community-list <(1-500)|WORD>",
50ef26d4 8979 SHOW_STR
8980 BGP_STR
8386ac43 8981 BGP_INSTANCE_HELP_STR
50ef26d4 8982 "Display routes matching the community-list\n"
8983 "community-list number\n"
8984 "community-list name\n")
8985{
4dcadbef 8986 return bgp_show_community_list (vty, argv[3]->arg, argv[5]->arg, 0, AFI_IP6, SAFI_UNICAST);
50ef26d4 8987}
8988
50ef26d4 8989
f412b39a
DW
8990/*
8991 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
8992 * "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M longer-prefixes",
8993 * SHOW_STR
8994 * BGP_STR
8995 * BGP_INSTANCE_HELP_STR
8996 * "Address family\n"
8997 * "IPv6 prefix <network>/<length>\n"
8998 * "Display route and more specific routes\n"
8999 *
9000 */
8386ac43 9001DEFUN (show_bgp_instance_prefix_longer,
9002 show_bgp_instance_prefix_longer_cmd,
9003 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M longer-prefixes",
50ef26d4 9004 SHOW_STR
9005 BGP_STR
8386ac43 9006 BGP_INSTANCE_HELP_STR
50ef26d4 9007 "IPv6 prefix <network>/<length>\n"
9008 "Display route and more specific routes\n")
9009{
4dcadbef 9010 return bgp_show_prefix_longer (vty, argv[3]->arg, argv[4]->arg, AFI_IP6, SAFI_UNICAST,
50ef26d4 9011 bgp_show_type_prefix_longer);
9012}
9013
50ef26d4 9014
718e3744 9015/* old command */
9016DEFUN (show_ipv6_mbgp,
9017 show_ipv6_mbgp_cmd,
b162fa78 9018 "show ipv6 mbgp [json]",
718e3744 9019 SHOW_STR
9020 IP_STR
b05a1c8b
DS
9021 MBGP_STR
9022 "JavaScript Object Notation\n")
718e3744 9023{
47e9b292 9024 bgp_show_ipv6_bgp_deprecate_warning(vty);
5a646650 9025 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
db7c8528 9026 NULL, use_json(argc, argv));
718e3744 9027}
9028
9029/* old command */
9030DEFUN (show_ipv6_mbgp_route,
9031 show_ipv6_mbgp_route_cmd,
b162fa78 9032 "show ipv6 mbgp X:X::X:X [json]",
718e3744 9033 SHOW_STR
9034 IP_STR
9035 MBGP_STR
b05a1c8b
DS
9036 "Network in the MBGP routing table to display\n"
9037 "JavaScript Object Notation\n")
718e3744 9038{
47e9b292 9039 bgp_show_ipv6_bgp_deprecate_warning(vty);
4dcadbef 9040 return bgp_show_route (vty, NULL, argv[3]->arg, AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
718e3744 9041}
9042
9043/* old command */
9044DEFUN (show_ipv6_mbgp_prefix,
9045 show_ipv6_mbgp_prefix_cmd,
b162fa78 9046 "show ipv6 mbgp X:X::X:X/M [json]",
718e3744 9047 SHOW_STR
9048 IP_STR
9049 MBGP_STR
b05a1c8b
DS
9050 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9051 "JavaScript Object Notation\n")
718e3744 9052{
47e9b292 9053 bgp_show_ipv6_bgp_deprecate_warning(vty);
4dcadbef 9054 return bgp_show_route (vty, NULL, argv[3]->arg, AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
718e3744 9055}
9056#endif
6b0655a2 9057
718e3744 9058
94f2b392 9059static int
4dcadbef 9060bgp_show_regexp (struct vty *vty, int argc, struct cmd_token **argv, afi_t afi,
718e3744 9061 safi_t safi, enum bgp_show_type type)
9062{
9063 int i;
9064 struct buffer *b;
9065 char *regstr;
9066 int first;
9067 regex_t *regex;
5a646650 9068 int rc;
718e3744 9069
9070 first = 0;
9071 b = buffer_new (1024);
9072 for (i = 0; i < argc; i++)
9073 {
9074 if (first)
9075 buffer_putc (b, ' ');
9076 else
9077 {
4dcadbef 9078 if ((strcmp (argv[i]->arg, "unicast") == 0) || (strcmp (argv[i]->arg, "multicast") == 0))
718e3744 9079 continue;
9080 first = 1;
9081 }
9082
4dcadbef 9083 buffer_putstr (b, argv[i]->arg);
718e3744 9084 }
9085 buffer_putc (b, '\0');
9086
9087 regstr = buffer_getstr (b);
9088 buffer_free (b);
9089
9090 regex = bgp_regcomp (regstr);
3b8b1855 9091 XFREE(MTYPE_TMP, regstr);
718e3744 9092 if (! regex)
9093 {
4dcadbef 9094 vty_out (vty, "Can't compile regexp %s%s", argv[0]->arg,
718e3744 9095 VTY_NEWLINE);
9096 return CMD_WARNING;
9097 }
9098
b05a1c8b 9099 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
5a646650 9100 bgp_regex_free (regex);
9101 return rc;
718e3744 9102}
9103
f412b39a 9104DEFUN (show_ip_bgp_regexp,
718e3744 9105 show_ip_bgp_regexp_cmd,
9106 "show ip bgp regexp .LINE",
9107 SHOW_STR
9108 IP_STR
9109 BGP_STR
9110 "Display routes matching the AS path regular expression\n"
9111 "A regular-expression to match the BGP AS paths\n")
9112{
9113 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9114 bgp_show_type_regexp);
9115}
9116
f412b39a
DW
9117/*
9118 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
9119 * "show ip bgp dampening flap-statistics regexp .LINE",
9120 * SHOW_STR
9121 * IP_STR
9122 * BGP_STR
9123 * "Display detailed information about dampening\n"
9124 * "Display flap statistics of routes\n"
9125 * "Display routes matching the AS path regular expression\n"
9126 * "A regular-expression to match the BGP AS paths\n"
9127 *
9128 */
9129DEFUN (show_ip_bgp_flap_regexp,
718e3744 9130 show_ip_bgp_flap_regexp_cmd,
9131 "show ip bgp flap-statistics regexp .LINE",
9132 SHOW_STR
9133 IP_STR
9134 BGP_STR
9135 "Display flap statistics of routes\n"
9136 "Display routes matching the AS path regular expression\n"
9137 "A regular-expression to match the BGP AS paths\n")
9138{
9139 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9140 bgp_show_type_flap_regexp);
9141}
9142
81304aaf 9143
f412b39a 9144DEFUN (show_ip_bgp_ipv4_regexp,
718e3744 9145 show_ip_bgp_ipv4_regexp_cmd,
6147e2c6 9146 "show ip bgp ipv4 <unicast|multicast> regexp .LINE",
718e3744 9147 SHOW_STR
9148 IP_STR
9149 BGP_STR
9150 "Address family\n"
9151 "Address Family modifier\n"
9152 "Address Family modifier\n"
9153 "Display routes matching the AS path regular expression\n"
9154 "A regular-expression to match the BGP AS paths\n")
9155{
4dcadbef 9156 if (strncmp (argv[4]->arg, "m", 1) == 0)
718e3744 9157 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
9158 bgp_show_type_regexp);
9159
9160 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9161 bgp_show_type_regexp);
9162}
9163
9164#ifdef HAVE_IPV6
f412b39a
DW
9165/*
9166 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
9167 * "show bgp ipv6 regexp .LINE",
9168 * SHOW_STR
9169 * BGP_STR
9170 * "Address family\n"
9171 * "Display routes matching the AS path regular expression\n"
9172 * "A regular-expression to match the BGP AS paths\n"
9173 *
9174 */
9175DEFUN (show_bgp_regexp,
718e3744 9176 show_bgp_regexp_cmd,
9177 "show bgp regexp .LINE",
9178 SHOW_STR
9179 BGP_STR
9180 "Display routes matching the AS path regular expression\n"
9181 "A regular-expression to match the BGP AS paths\n")
9182{
9183 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9184 bgp_show_type_regexp);
9185}
9186
718e3744 9187
9188/* old command */
f412b39a 9189DEFUN (show_ipv6_bgp_regexp,
718e3744 9190 show_ipv6_bgp_regexp_cmd,
9191 "show ipv6 bgp regexp .LINE",
9192 SHOW_STR
9193 IP_STR
9194 BGP_STR
9195 "Display routes matching the AS path regular expression\n"
9196 "A regular-expression to match the BGP AS paths\n")
9197{
47e9b292 9198 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 9199 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9200 bgp_show_type_regexp);
9201}
9202
9203/* old command */
f412b39a 9204DEFUN (show_ipv6_mbgp_regexp,
718e3744 9205 show_ipv6_mbgp_regexp_cmd,
9206 "show ipv6 mbgp regexp .LINE",
9207 SHOW_STR
9208 IP_STR
9209 BGP_STR
9210 "Display routes matching the AS path regular expression\n"
9211 "A regular-expression to match the MBGP AS paths\n")
9212{
47e9b292 9213 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 9214 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
9215 bgp_show_type_regexp);
9216}
9217#endif /* HAVE_IPV6 */
6b0655a2 9218
94f2b392 9219static int
50ef26d4 9220bgp_show_prefix_list (struct vty *vty, const char *name,
9221 const char *prefix_list_str, afi_t afi,
718e3744 9222 safi_t safi, enum bgp_show_type type)
9223{
9224 struct prefix_list *plist;
50ef26d4 9225 struct bgp *bgp = NULL;
9226
9227 if (name && !(bgp = bgp_lookup_by_name(name)))
9228 {
9229 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9230 return CMD_WARNING;
9231 }
718e3744 9232
9233 plist = prefix_list_lookup (afi, prefix_list_str);
9234 if (plist == NULL)
9235 {
9236 vty_out (vty, "%% %s is not a valid prefix-list name%s",
9237 prefix_list_str, VTY_NEWLINE);
9238 return CMD_WARNING;
9239 }
9240
50ef26d4 9241 return bgp_show (vty, bgp, afi, safi, type, plist, 0);
718e3744 9242}
9243
f412b39a 9244DEFUN (show_ip_bgp_prefix_list,
718e3744 9245 show_ip_bgp_prefix_list_cmd,
9246 "show ip bgp prefix-list WORD",
9247 SHOW_STR
9248 IP_STR
9249 BGP_STR
9250 "Display routes conforming to the prefix-list\n"
9251 "IP prefix-list name\n")
9252{
4dcadbef 9253 return bgp_show_prefix_list (vty, NULL, argv[4]->arg, AFI_IP, SAFI_UNICAST,
50ef26d4 9254 bgp_show_type_prefix_list);
9255}
9256
8386ac43 9257DEFUN (show_ip_bgp_instance_prefix_list,
9258 show_ip_bgp_instance_prefix_list_cmd,
9259 "show ip bgp " BGP_INSTANCE_CMD " prefix-list WORD",
50ef26d4 9260 SHOW_STR
9261 IP_STR
9262 BGP_STR
8386ac43 9263 BGP_INSTANCE_HELP_STR
50ef26d4 9264 "Display routes conforming to the prefix-list\n"
9265 "IP prefix-list name\n")
9266{
4dcadbef 9267 return bgp_show_prefix_list (vty, argv[4]->arg, argv[6]->arg, AFI_IP, SAFI_UNICAST,
718e3744 9268 bgp_show_type_prefix_list);
9269}
9270
f412b39a
DW
9271/*
9272 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
9273 * "show ip bgp dampening flap-statistics prefix-list WORD",
9274 * SHOW_STR
9275 * IP_STR
9276 * BGP_STR
9277 * "Display detailed information about dampening\n"
9278 * "Display flap statistics of routes\n"
9279 * "Display routes conforming to the prefix-list\n"
9280 * "IP prefix-list name\n"
9281 *
9282 */
9283DEFUN (show_ip_bgp_flap_prefix_list,
718e3744 9284 show_ip_bgp_flap_prefix_list_cmd,
9285 "show ip bgp flap-statistics prefix-list WORD",
9286 SHOW_STR
9287 IP_STR
9288 BGP_STR
9289 "Display flap statistics of routes\n"
9290 "Display routes conforming to the prefix-list\n"
9291 "IP prefix-list name\n")
9292{
4dcadbef 9293 return bgp_show_prefix_list (vty, NULL, argv[5]->arg, AFI_IP, SAFI_UNICAST,
718e3744 9294 bgp_show_type_flap_prefix_list);
9295}
9296
81304aaf 9297
f412b39a 9298DEFUN (show_ip_bgp_ipv4_prefix_list,
718e3744 9299 show_ip_bgp_ipv4_prefix_list_cmd,
6147e2c6 9300 "show ip bgp ipv4 <unicast|multicast> prefix-list WORD",
718e3744 9301 SHOW_STR
9302 IP_STR
9303 BGP_STR
9304 "Address family\n"
9305 "Address Family modifier\n"
9306 "Address Family modifier\n"
9307 "Display routes conforming to the prefix-list\n"
9308 "IP prefix-list name\n")
9309{
4dcadbef
DW
9310 if (strncmp (argv[4]->arg, "m", 1) == 0)
9311 return bgp_show_prefix_list (vty, NULL, argv[6]->arg, AFI_IP, SAFI_MULTICAST,
718e3744 9312 bgp_show_type_prefix_list);
9313
4dcadbef 9314 return bgp_show_prefix_list (vty, NULL, argv[6]->arg, AFI_IP, SAFI_UNICAST,
718e3744 9315 bgp_show_type_prefix_list);
9316}
9317
9318#ifdef HAVE_IPV6
f412b39a
DW
9319/*
9320 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
9321 * "show bgp ipv6 prefix-list WORD",
9322 * SHOW_STR
9323 * BGP_STR
9324 * "Address family\n"
9325 * "Display routes conforming to the prefix-list\n"
9326 * "IPv6 prefix-list name\n"
9327 *
9328 */
9329DEFUN (show_bgp_prefix_list,
718e3744 9330 show_bgp_prefix_list_cmd,
9331 "show bgp prefix-list WORD",
9332 SHOW_STR
9333 BGP_STR
9334 "Display routes conforming to the prefix-list\n"
9335 "IPv6 prefix-list name\n")
9336{
4dcadbef 9337 return bgp_show_prefix_list (vty, NULL, argv[3]->arg, AFI_IP6, SAFI_UNICAST,
718e3744 9338 bgp_show_type_prefix_list);
9339}
9340
718e3744 9341
9342/* old command */
f412b39a 9343DEFUN (show_ipv6_bgp_prefix_list,
718e3744 9344 show_ipv6_bgp_prefix_list_cmd,
9345 "show ipv6 bgp prefix-list WORD",
9346 SHOW_STR
9347 IPV6_STR
9348 BGP_STR
9349 "Display routes matching the prefix-list\n"
9350 "IPv6 prefix-list name\n")
9351{
47e9b292 9352 bgp_show_ipv6_bgp_deprecate_warning(vty);
4dcadbef 9353 return bgp_show_prefix_list (vty, NULL, argv[4]->arg, AFI_IP6, SAFI_UNICAST,
718e3744 9354 bgp_show_type_prefix_list);
9355}
9356
9357/* old command */
f412b39a 9358DEFUN (show_ipv6_mbgp_prefix_list,
718e3744 9359 show_ipv6_mbgp_prefix_list_cmd,
9360 "show ipv6 mbgp prefix-list WORD",
9361 SHOW_STR
9362 IPV6_STR
9363 MBGP_STR
9364 "Display routes matching the prefix-list\n"
9365 "IPv6 prefix-list name\n")
9366{
47e9b292 9367 bgp_show_ipv6_bgp_deprecate_warning(vty);
4dcadbef 9368 return bgp_show_prefix_list (vty, NULL, argv[4]->arg, AFI_IP6, SAFI_MULTICAST,
718e3744 9369 bgp_show_type_prefix_list);
9370}
9371#endif /* HAVE_IPV6 */
6b0655a2 9372
94f2b392 9373static int
50ef26d4 9374bgp_show_filter_list (struct vty *vty, const char *name,
9375 const char *filter, afi_t afi,
718e3744 9376 safi_t safi, enum bgp_show_type type)
9377{
9378 struct as_list *as_list;
50ef26d4 9379 struct bgp *bgp = NULL;
9380
9381 if (name && !(bgp = bgp_lookup_by_name(name)))
9382 {
9383 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9384 return CMD_WARNING;
9385 }
718e3744 9386
9387 as_list = as_list_lookup (filter);
9388 if (as_list == NULL)
9389 {
9390 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
9391 return CMD_WARNING;
9392 }
9393
50ef26d4 9394 return bgp_show (vty, bgp, afi, safi, type, as_list, 0);
718e3744 9395}
9396
f412b39a 9397DEFUN (show_ip_bgp_filter_list,
718e3744 9398 show_ip_bgp_filter_list_cmd,
9399 "show ip bgp filter-list WORD",
9400 SHOW_STR
9401 IP_STR
9402 BGP_STR
9403 "Display routes conforming to the filter-list\n"
9404 "Regular expression access list name\n")
9405{
4dcadbef 9406 return bgp_show_filter_list (vty, NULL, argv[4]->arg, AFI_IP, SAFI_UNICAST,
50ef26d4 9407 bgp_show_type_filter_list);
9408}
9409
8386ac43 9410DEFUN (show_ip_bgp_instance_filter_list,
9411 show_ip_bgp_instance_filter_list_cmd,
9412 "show ip bgp " BGP_INSTANCE_CMD " filter-list WORD",
50ef26d4 9413 SHOW_STR
9414 IP_STR
9415 BGP_STR
8386ac43 9416 BGP_INSTANCE_HELP_STR
50ef26d4 9417 "Display routes conforming to the filter-list\n"
9418 "Regular expression access list name\n")
9419{
4dcadbef 9420 return bgp_show_filter_list (vty, argv[4]->arg, argv[6]->arg, AFI_IP, SAFI_UNICAST,
718e3744 9421 bgp_show_type_filter_list);
9422}
9423
f412b39a
DW
9424/*
9425 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
9426 * "show ip bgp dampening flap-statistics filter-list WORD",
9427 * SHOW_STR
9428 * IP_STR
9429 * BGP_STR
9430 * "Display detailed information about dampening\n"
9431 * "Display flap statistics of routes\n"
9432 * "Display routes conforming to the filter-list\n"
9433 * "Regular expression access list name\n"
9434 *
9435 */
9436DEFUN (show_ip_bgp_flap_filter_list,
718e3744 9437 show_ip_bgp_flap_filter_list_cmd,
9438 "show ip bgp flap-statistics filter-list WORD",
9439 SHOW_STR
9440 IP_STR
9441 BGP_STR
9442 "Display flap statistics of routes\n"
9443 "Display routes conforming to the filter-list\n"
9444 "Regular expression access list name\n")
9445{
4dcadbef 9446 return bgp_show_filter_list (vty, NULL, argv[5]->arg, AFI_IP, SAFI_UNICAST,
718e3744 9447 bgp_show_type_flap_filter_list);
9448}
9449
81304aaf 9450
f412b39a 9451DEFUN (show_ip_bgp_ipv4_filter_list,
718e3744 9452 show_ip_bgp_ipv4_filter_list_cmd,
6147e2c6 9453 "show ip bgp ipv4 <unicast|multicast> filter-list WORD",
718e3744 9454 SHOW_STR
9455 IP_STR
9456 BGP_STR
9457 "Address family\n"
9458 "Address Family modifier\n"
9459 "Address Family modifier\n"
9460 "Display routes conforming to the filter-list\n"
9461 "Regular expression access list name\n")
9462{
4dcadbef
DW
9463 if (strncmp (argv[4]->arg, "m", 1) == 0)
9464 return bgp_show_filter_list (vty, NULL, argv[6]->arg, AFI_IP, SAFI_MULTICAST,
718e3744 9465 bgp_show_type_filter_list);
9466
4dcadbef 9467 return bgp_show_filter_list (vty, NULL, argv[6]->arg, AFI_IP, SAFI_UNICAST,
718e3744 9468 bgp_show_type_filter_list);
9469}
9470
9471#ifdef HAVE_IPV6
f412b39a
DW
9472/*
9473 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
9474 * "show bgp ipv6 filter-list WORD",
9475 * SHOW_STR
9476 * BGP_STR
9477 * "Address family\n"
9478 * "Display routes conforming to the filter-list\n"
9479 * "Regular expression access list name\n"
9480 *
9481 */
9482DEFUN (show_bgp_filter_list,
718e3744 9483 show_bgp_filter_list_cmd,
9484 "show bgp filter-list WORD",
9485 SHOW_STR
9486 BGP_STR
9487 "Display routes conforming to the filter-list\n"
9488 "Regular expression access list name\n")
9489{
4dcadbef 9490 return bgp_show_filter_list (vty, NULL, argv[3]->arg, AFI_IP6, SAFI_UNICAST,
718e3744 9491 bgp_show_type_filter_list);
9492}
9493
718e3744 9494
9495/* old command */
f412b39a 9496DEFUN (show_ipv6_bgp_filter_list,
718e3744 9497 show_ipv6_bgp_filter_list_cmd,
9498 "show ipv6 bgp filter-list WORD",
9499 SHOW_STR
9500 IPV6_STR
9501 BGP_STR
9502 "Display routes conforming to the filter-list\n"
9503 "Regular expression access list name\n")
9504{
47e9b292 9505 bgp_show_ipv6_bgp_deprecate_warning(vty);
4dcadbef 9506 return bgp_show_filter_list (vty, NULL, argv[4]->arg, AFI_IP6, SAFI_UNICAST,
718e3744 9507 bgp_show_type_filter_list);
9508}
9509
9510/* old command */
f412b39a 9511DEFUN (show_ipv6_mbgp_filter_list,
718e3744 9512 show_ipv6_mbgp_filter_list_cmd,
9513 "show ipv6 mbgp filter-list WORD",
9514 SHOW_STR
9515 IPV6_STR
9516 MBGP_STR
9517 "Display routes conforming to the filter-list\n"
9518 "Regular expression access list name\n")
9519{
47e9b292 9520 bgp_show_ipv6_bgp_deprecate_warning(vty);
4dcadbef 9521 return bgp_show_filter_list (vty, NULL, argv[4]->arg, AFI_IP6, SAFI_MULTICAST,
718e3744 9522 bgp_show_type_filter_list);
9523}
9524#endif /* HAVE_IPV6 */
6b0655a2 9525
81304aaf
B
9526DEFUN (show_ip_bgp_dampening_info,
9527 show_ip_bgp_dampening_params_cmd,
9528 "show ip bgp dampening parameters",
9529 SHOW_STR
9530 IP_STR
9531 BGP_STR
9532 "Display detailed information about dampening\n"
9533 "Display detail of configured dampening parameters\n")
9534{
9535 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
9536}
9537
58a90275
B
9538
9539DEFUN (show_ip_bgp_ipv4_dampening_parameters,
9540 show_ip_bgp_ipv4_dampening_parameters_cmd,
6147e2c6 9541 "show ip bgp ipv4 <unicast|multicast> dampening parameters",
58a90275
B
9542 SHOW_STR
9543 IP_STR
9544 BGP_STR
9545 "Address family\n"
9546 "Address Family modifier\n"
9547 "Address Family modifier\n"
9548 "Display detailed information about dampening\n"
9549 "Display detail of configured dampening parameters\n")
9550{
4dcadbef 9551 if (strncmp(argv[4]->arg, "m", 1) == 0)
58a90275
B
9552 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_MULTICAST);
9553
9554 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
9555}
9556
9557
9558DEFUN (show_ip_bgp_ipv4_dampening_flap_stats,
9559 show_ip_bgp_ipv4_dampening_flap_stats_cmd,
6147e2c6 9560 "show ip bgp ipv4 <unicast|multicast> dampening flap-statistics",
58a90275
B
9561 SHOW_STR
9562 IP_STR
9563 BGP_STR
9564 "Address family\n"
9565 "Address Family modifier\n"
9566 "Address Family modifier\n"
9567 "Display detailed information about dampening\n"
9568 "Display flap statistics of routes\n")
9569{
4dcadbef 9570 if (strncmp(argv[4]->arg, "m", 1) == 0)
58a90275
B
9571 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9572 bgp_show_type_flap_statistics, NULL, 0);
9573
9574 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9575 bgp_show_type_flap_statistics, NULL, 0);
9576}
9577
9578DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths,
9579 show_ip_bgp_ipv4_dampening_dampd_paths_cmd,
6147e2c6 9580 "show ip bgp ipv4 <unicast|multicast> dampening dampened-paths",
58a90275
B
9581 SHOW_STR
9582 IP_STR
9583 BGP_STR
9584 "Address family\n"
9585 "Address Family modifier\n"
9586 "Address Family modifier\n"
9587 "Display detailed information about dampening\n"
9588 "Display paths suppressed due to dampening\n")
9589{
4dcadbef 9590 if (strncmp(argv[4]->arg, "m", 1) == 0)
58a90275
B
9591 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9592 bgp_show_type_dampend_paths, NULL, 0);
9593
9594 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9595 bgp_show_type_dampend_paths, NULL, 0);
9596}
9597
94f2b392 9598static int
50ef26d4 9599bgp_show_route_map (struct vty *vty, const char *name,
9600 const char *rmap_str, afi_t afi,
718e3744 9601 safi_t safi, enum bgp_show_type type)
9602{
9603 struct route_map *rmap;
50ef26d4 9604 struct bgp *bgp = NULL;
9605
9606 if (name && !(bgp = bgp_lookup_by_name(name)))
9607 {
9608 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9609 return CMD_WARNING;
9610 }
718e3744 9611
9612 rmap = route_map_lookup_by_name (rmap_str);
9613 if (! rmap)
9614 {
9615 vty_out (vty, "%% %s is not a valid route-map name%s",
9616 rmap_str, VTY_NEWLINE);
9617 return CMD_WARNING;
9618 }
9619
50ef26d4 9620 return bgp_show (vty, bgp, afi, safi, type, rmap, 0);
718e3744 9621}
9622
f412b39a 9623DEFUN (show_ip_bgp_route_map,
718e3744 9624 show_ip_bgp_route_map_cmd,
9625 "show ip bgp route-map WORD",
9626 SHOW_STR
9627 IP_STR
9628 BGP_STR
9629 "Display routes matching the route-map\n"
9630 "A route-map to match on\n")
9631{
4dcadbef 9632 return bgp_show_route_map (vty, NULL, argv[4]->arg, AFI_IP, SAFI_UNICAST,
50ef26d4 9633 bgp_show_type_route_map);
9634}
9635
8386ac43 9636DEFUN (show_ip_bgp_instance_route_map,
9637 show_ip_bgp_instance_route_map_cmd,
9638 "show ip bgp " BGP_INSTANCE_CMD " route-map WORD",
50ef26d4 9639 SHOW_STR
9640 IP_STR
9641 BGP_STR
8386ac43 9642 BGP_INSTANCE_HELP_STR
50ef26d4 9643 "Display routes matching the route-map\n"
9644 "A route-map to match on\n")
9645{
4dcadbef 9646 return bgp_show_route_map (vty, argv[4]->arg, argv[6]->arg, AFI_IP, SAFI_UNICAST,
718e3744 9647 bgp_show_type_route_map);
9648}
9649
f412b39a
DW
9650/*
9651 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
9652 * "show ip bgp dampening flap-statistics route-map WORD",
9653 * SHOW_STR
9654 * IP_STR
9655 * BGP_STR
9656 * "Display detailed information about dampening\n"
9657 * "Display flap statistics of routes\n"
9658 * "Display routes matching the route-map\n"
9659 * "A route-map to match on\n"
9660 *
9661 */
9662DEFUN (show_ip_bgp_flap_route_map,
718e3744 9663 show_ip_bgp_flap_route_map_cmd,
9664 "show ip bgp flap-statistics route-map WORD",
9665 SHOW_STR
9666 IP_STR
9667 BGP_STR
9668 "Display flap statistics of routes\n"
9669 "Display routes matching the route-map\n"
9670 "A route-map to match on\n")
9671{
4dcadbef 9672 return bgp_show_route_map (vty, NULL, argv[5]->arg, AFI_IP, SAFI_UNICAST,
718e3744 9673 bgp_show_type_flap_route_map);
9674}
9675
81304aaf 9676
f412b39a 9677DEFUN (show_ip_bgp_ipv4_route_map,
718e3744 9678 show_ip_bgp_ipv4_route_map_cmd,
6147e2c6 9679 "show ip bgp ipv4 <unicast|multicast> route-map WORD",
718e3744 9680 SHOW_STR
9681 IP_STR
9682 BGP_STR
9683 "Address family\n"
9684 "Address Family modifier\n"
9685 "Address Family modifier\n"
9686 "Display routes matching the route-map\n"
9687 "A route-map to match on\n")
9688{
4dcadbef
DW
9689 if (strncmp (argv[4]->arg, "m", 1) == 0)
9690 return bgp_show_route_map (vty, NULL, argv[6]->arg, AFI_IP, SAFI_MULTICAST,
718e3744 9691 bgp_show_type_route_map);
9692
4dcadbef 9693 return bgp_show_route_map (vty, NULL, argv[6]->arg, AFI_IP, SAFI_UNICAST,
718e3744 9694 bgp_show_type_route_map);
9695}
9696
f412b39a
DW
9697/*
9698 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
9699 * "show bgp ipv6 route-map WORD",
9700 * SHOW_STR
9701 * BGP_STR
9702 * "Address family\n"
9703 * "Display routes matching the route-map\n"
9704 * "A route-map to match on\n"
9705 *
9706 */
9707DEFUN (show_bgp_route_map,
718e3744 9708 show_bgp_route_map_cmd,
9709 "show bgp route-map WORD",
9710 SHOW_STR
9711 BGP_STR
9712 "Display routes matching the route-map\n"
9713 "A route-map to match on\n")
9714{
4dcadbef 9715 return bgp_show_route_map (vty, NULL, argv[3]->arg, AFI_IP6, SAFI_UNICAST,
718e3744 9716 bgp_show_type_route_map);
9717}
9718
6b0655a2 9719
718e3744 9720DEFUN (show_ip_bgp_cidr_only,
9721 show_ip_bgp_cidr_only_cmd,
9722 "show ip bgp cidr-only",
9723 SHOW_STR
9724 IP_STR
9725 BGP_STR
9726 "Display only routes with non-natural netmasks\n")
9727{
9728 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9729 bgp_show_type_cidr_only, NULL, 0);
718e3744 9730}
9731
f412b39a
DW
9732/*
9733 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
9734 * "show ip bgp dampening flap-statistics cidr-only",
9735 * SHOW_STR
9736 * IP_STR
9737 * BGP_STR
9738 * "Display detailed information about dampening\n"
9739 * "Display flap statistics of routes\n"
9740 * "Display only routes with non-natural netmasks\n"
9741 *
9742 */
718e3744 9743DEFUN (show_ip_bgp_flap_cidr_only,
9744 show_ip_bgp_flap_cidr_only_cmd,
9745 "show ip bgp flap-statistics cidr-only",
9746 SHOW_STR
9747 IP_STR
9748 BGP_STR
9749 "Display flap statistics of routes\n"
9750 "Display only routes with non-natural netmasks\n")
9751{
9752 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9753 bgp_show_type_flap_cidr_only, NULL, 0);
718e3744 9754}
9755
81304aaf 9756
718e3744 9757DEFUN (show_ip_bgp_ipv4_cidr_only,
9758 show_ip_bgp_ipv4_cidr_only_cmd,
6147e2c6 9759 "show ip bgp ipv4 <unicast|multicast> cidr-only",
718e3744 9760 SHOW_STR
9761 IP_STR
9762 BGP_STR
9763 "Address family\n"
9764 "Address Family modifier\n"
9765 "Address Family modifier\n"
9766 "Display only routes with non-natural netmasks\n")
9767{
4dcadbef 9768 if (strncmp (argv[4]->arg, "m", 1) == 0)
718e3744 9769 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
b05a1c8b 9770 bgp_show_type_cidr_only, NULL, 0);
718e3744 9771
9772 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9773 bgp_show_type_cidr_only, NULL, 0);
718e3744 9774}
6b0655a2 9775
718e3744 9776DEFUN (show_ip_bgp_community_all,
9777 show_ip_bgp_community_all_cmd,
9778 "show ip bgp community",
9779 SHOW_STR
9780 IP_STR
9781 BGP_STR
9782 "Display routes matching the communities\n")
9783{
9784 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9785 bgp_show_type_community_all, NULL, 0);
718e3744 9786}
9787
9788DEFUN (show_ip_bgp_ipv4_community_all,
9789 show_ip_bgp_ipv4_community_all_cmd,
6147e2c6 9790 "show ip bgp ipv4 <unicast|multicast> community",
718e3744 9791 SHOW_STR
9792 IP_STR
9793 BGP_STR
9794 "Address family\n"
9795 "Address Family modifier\n"
9796 "Address Family modifier\n"
9797 "Display routes matching the communities\n")
9798{
4dcadbef 9799 if (strncmp (argv[4]->arg, "m", 1) == 0)
718e3744 9800 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
b05a1c8b 9801 bgp_show_type_community_all, NULL, 0);
718e3744 9802
9803 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9804 bgp_show_type_community_all, NULL, 0);
718e3744 9805}
9806
9807#ifdef HAVE_IPV6
f412b39a
DW
9808/*
9809 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
9810 * "show bgp ipv6 community",
9811 * SHOW_STR
9812 * BGP_STR
9813 * "Address family\n"
9814 * "Display routes matching the communities\n"
9815 *
9816 */
718e3744 9817DEFUN (show_bgp_community_all,
9818 show_bgp_community_all_cmd,
9819 "show bgp community",
9820 SHOW_STR
9821 BGP_STR
9822 "Display routes matching the communities\n")
9823{
9824 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 9825 bgp_show_type_community_all, NULL, 0);
718e3744 9826}
9827
718e3744 9828
9829/* old command */
9830DEFUN (show_ipv6_bgp_community_all,
9831 show_ipv6_bgp_community_all_cmd,
9832 "show ipv6 bgp community",
9833 SHOW_STR
9834 IPV6_STR
9835 BGP_STR
9836 "Display routes matching the communities\n")
9837{
47e9b292 9838 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 9839 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 9840 bgp_show_type_community_all, NULL, 0);
718e3744 9841}
9842
9843/* old command */
9844DEFUN (show_ipv6_mbgp_community_all,
9845 show_ipv6_mbgp_community_all_cmd,
9846 "show ipv6 mbgp community",
9847 SHOW_STR
9848 IPV6_STR
9849 MBGP_STR
9850 "Display routes matching the communities\n")
9851{
47e9b292 9852 bgp_show_ipv6_bgp_deprecate_warning(vty);
718e3744 9853 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
b05a1c8b 9854 bgp_show_type_community_all, NULL, 0);
718e3744 9855}
9856#endif /* HAVE_IPV6 */
6b0655a2 9857
94f2b392 9858static int
95cbbd2a 9859bgp_show_community (struct vty *vty, const char *view_name, int argc,
4dcadbef 9860 struct cmd_token **argv, int exact, afi_t afi, safi_t safi)
718e3744 9861{
9862 struct community *com;
9863 struct buffer *b;
95cbbd2a 9864 struct bgp *bgp;
718e3744 9865 int i;
9866 char *str;
9867 int first = 0;
9868
95cbbd2a
ML
9869 /* BGP structure lookup */
9870 if (view_name)
9871 {
9872 bgp = bgp_lookup_by_name (view_name);
9873 if (bgp == NULL)
9874 {
6aeb9e78 9875 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
95cbbd2a
ML
9876 return CMD_WARNING;
9877 }
9878 }
9879 else
9880 {
9881 bgp = bgp_get_default ();
9882 if (bgp == NULL)
9883 {
9884 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9885 return CMD_WARNING;
9886 }
9887 }
9888
718e3744 9889 b = buffer_new (1024);
9890 for (i = 0; i < argc; i++)
9891 {
9892 if (first)
9893 buffer_putc (b, ' ');
9894 else
9895 {
4dcadbef 9896 if ((strcmp (argv[i]->arg, "unicast") == 0) || (strcmp (argv[i]->arg, "multicast") == 0))
718e3744 9897 continue;
9898 first = 1;
9899 }
9900
4dcadbef 9901 buffer_putstr (b, argv[i]->arg);
718e3744 9902 }
9903 buffer_putc (b, '\0');
9904
9905 str = buffer_getstr (b);
9906 buffer_free (b);
9907
9908 com = community_str2com (str);
3b8b1855 9909 XFREE (MTYPE_TMP, str);
718e3744 9910 if (! com)
9911 {
9912 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9913 return CMD_WARNING;
9914 }
9915
95cbbd2a 9916 return bgp_show (vty, bgp, afi, safi,
5a646650 9917 (exact ? bgp_show_type_community_exact :
b05a1c8b 9918 bgp_show_type_community), com, 0);
718e3744 9919}
9920
f412b39a
DW
9921/*
9922 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
9923 * "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)",
9924 * SHOW_STR
9925 * IP_STR
9926 * BGP_STR
9927 * "Display routes matching the communities\n"
9928 * COMMUNITY_AANN_STR
9929 * "Do not send outside local AS (well-known community)\n"
9930 * "Do not advertise to any peer (well-known community)\n"
9931 * "Do not export to next AS (well-known community)\n"
9932 * COMMUNITY_AANN_STR
9933 * "Do not send outside local AS (well-known community)\n"
9934 * "Do not advertise to any peer (well-known community)\n"
9935 * "Do not export to next AS (well-known community)\n"
9936 * COMMUNITY_AANN_STR
9937 * "Do not send outside local AS (well-known community)\n"
9938 * "Do not advertise to any peer (well-known community)\n"
9939 * "Do not export to next AS (well-known community)\n"
9940 *
9941 * "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)",
9942 * SHOW_STR
9943 * IP_STR
9944 * BGP_STR
9945 * "Display routes matching the communities\n"
9946 * COMMUNITY_AANN_STR
9947 * "Do not send outside local AS (well-known community)\n"
9948 * "Do not advertise to any peer (well-known community)\n"
9949 * "Do not export to next AS (well-known community)\n"
9950 * COMMUNITY_AANN_STR
9951 * "Do not send outside local AS (well-known community)\n"
9952 * "Do not advertise to any peer (well-known community)\n"
9953 * "Do not export to next AS (well-known community)\n"
9954 * COMMUNITY_AANN_STR
9955 * "Do not send outside local AS (well-known community)\n"
9956 * "Do not advertise to any peer (well-known community)\n"
9957 * "Do not export to next AS (well-known community)\n"
9958 * COMMUNITY_AANN_STR
9959 * "Do not send outside local AS (well-known community)\n"
9960 * "Do not advertise to any peer (well-known community)\n"
9961 * "Do not export to next AS (well-known community)\n"
9962 *
9963 * "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9964 * SHOW_STR
9965 * IP_STR
9966 * BGP_STR
9967 * "Display routes matching the communities\n"
9968 * COMMUNITY_AANN_STR
9969 * "Do not send outside local AS (well-known community)\n"
9970 * "Do not advertise to any peer (well-known community)\n"
9971 * "Do not export to next AS (well-known community)\n"
9972 * COMMUNITY_AANN_STR
9973 * "Do not send outside local AS (well-known community)\n"
9974 * "Do not advertise to any peer (well-known community)\n"
9975 * "Do not export to next AS (well-known community)\n"
9976 *
9977 */
718e3744 9978DEFUN (show_ip_bgp_community,
9979 show_ip_bgp_community_cmd,
6147e2c6 9980 "show ip bgp community <AA:NN|local-AS|no-advertise|no-export>",
718e3744 9981 SHOW_STR
9982 IP_STR
9983 BGP_STR
9984 "Display routes matching the communities\n"
859d388e 9985 COMMUNITY_AANN_STR
718e3744 9986 "Do not send outside local AS (well-known community)\n"
9987 "Do not advertise to any peer (well-known community)\n"
9988 "Do not export to next AS (well-known community)\n")
9989{
95cbbd2a 9990 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 9991}
9992
718e3744 9993
718e3744 9994
718e3744 9995
f412b39a
DW
9996/*
9997 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
9998 * "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)",
9999 * SHOW_STR
10000 * IP_STR
10001 * BGP_STR
10002 * "Address family\n"
10003 * "Address Family modifier\n"
10004 * "Address Family modifier\n"
10005 * "Display routes matching the communities\n"
10006 * COMMUNITY_AANN_STR
10007 * "Do not send outside local AS (well-known community)\n"
10008 * "Do not advertise to any peer (well-known community)\n"
10009 * "Do not export to next AS (well-known community)\n"
10010 * COMMUNITY_AANN_STR
10011 * "Do not send outside local AS (well-known community)\n"
10012 * "Do not advertise to any peer (well-known community)\n"
10013 * "Do not export to next AS (well-known community)\n"
10014 * COMMUNITY_AANN_STR
10015 * "Do not send outside local AS (well-known community)\n"
10016 * "Do not advertise to any peer (well-known community)\n"
10017 * "Do not export to next AS (well-known community)\n"
10018 *
10019 * "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10020 * SHOW_STR
10021 * IP_STR
10022 * BGP_STR
10023 * "Address family\n"
10024 * "Address Family modifier\n"
10025 * "Address Family modifier\n"
10026 * "Display routes matching the communities\n"
10027 * COMMUNITY_AANN_STR
10028 * "Do not send outside local AS (well-known community)\n"
10029 * "Do not advertise to any peer (well-known community)\n"
10030 * "Do not export to next AS (well-known community)\n"
10031 * COMMUNITY_AANN_STR
10032 * "Do not send outside local AS (well-known community)\n"
10033 * "Do not advertise to any peer (well-known community)\n"
10034 * "Do not export to next AS (well-known community)\n"
10035 *
10036 * "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)",
10037 * SHOW_STR
10038 * IP_STR
10039 * BGP_STR
10040 * "Address family\n"
10041 * "Address Family modifier\n"
10042 * "Address Family modifier\n"
10043 * "Display routes matching the communities\n"
10044 * COMMUNITY_AANN_STR
10045 * "Do not send outside local AS (well-known community)\n"
10046 * "Do not advertise to any peer (well-known community)\n"
10047 * "Do not export to next AS (well-known community)\n"
10048 * COMMUNITY_AANN_STR
10049 * "Do not send outside local AS (well-known community)\n"
10050 * "Do not advertise to any peer (well-known community)\n"
10051 * "Do not export to next AS (well-known community)\n"
10052 * COMMUNITY_AANN_STR
10053 * "Do not send outside local AS (well-known community)\n"
10054 * "Do not advertise to any peer (well-known community)\n"
10055 * "Do not export to next AS (well-known community)\n"
10056 * COMMUNITY_AANN_STR
10057 * "Do not send outside local AS (well-known community)\n"
10058 * "Do not advertise to any peer (well-known community)\n"
10059 * "Do not export to next AS (well-known community)\n"
10060 *
10061 */
718e3744 10062DEFUN (show_ip_bgp_ipv4_community,
10063 show_ip_bgp_ipv4_community_cmd,
6147e2c6 10064 "show ip bgp ipv4 <unicast|multicast> community <AA:NN|local-AS|no-advertise|no-export>",
718e3744 10065 SHOW_STR
10066 IP_STR
10067 BGP_STR
10068 "Address family\n"
10069 "Address Family modifier\n"
10070 "Address Family modifier\n"
10071 "Display routes matching the communities\n"
859d388e 10072 COMMUNITY_AANN_STR
718e3744 10073 "Do not send outside local AS (well-known community)\n"
10074 "Do not advertise to any peer (well-known community)\n"
10075 "Do not export to next AS (well-known community)\n")
10076{
4dcadbef 10077 if (strncmp (argv[4]->arg, "m", 1) == 0)
95cbbd2a 10078 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
718e3744 10079
95cbbd2a 10080 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 10081}
10082
f412b39a
DW
10083
10084
10085
10086DEFUN (show_bgp_instance_afi_safi_community_all,
10087 show_bgp_instance_afi_safi_community_all_cmd,
6147e2c6 10088 "show bgp " BGP_INSTANCE_CMD " <ipv4|ipv6> <unicast|multicast> community",
718e3744 10089 SHOW_STR
718e3744 10090 BGP_STR
f412b39a
DW
10091 BGP_INSTANCE_HELP_STR
10092 "Address family\n"
718e3744 10093 "Address family\n"
10094 "Address Family modifier\n"
10095 "Address Family modifier\n"
f412b39a
DW
10096 "Display routes matching the communities\n")
10097{
10098 int afi;
10099 int safi;
10100 struct bgp *bgp;
10101
10102 /* BGP structure lookup. */
10103 bgp = bgp_lookup_by_name (argv[3]->arg);
10104 if (bgp == NULL)
10105 {
10106 vty_out (vty, "Can't find BGP instance %s%s", argv[3]->arg, VTY_NEWLINE);
10107 return CMD_WARNING;
10108 }
10109
10110 afi = (strncmp (argv[4]->arg, "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10111 safi = (strncmp (argv[5]->arg, "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10112 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
10113}
10114
10115/*
10116 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
10117 * "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)",
10118 * SHOW_STR
10119 * BGP_STR
10120 * BGP_INSTANCE_HELP_STR
10121 * "Address family\n"
10122 * "Address family\n"
10123 * "Address family modifier\n"
10124 * "Address family modifier\n"
10125 * "Display routes matching the communities\n"
10126 * COMMUNITY_AANN_STR
10127 * "Do not send outside local AS (well-known community)\n"
10128 * "Do not advertise to any peer (well-known community)\n"
10129 * "Do not export to next AS (well-known community)\n"
10130 * COMMUNITY_AANN_STR
10131 * "Do not send outside local AS (well-known community)\n"
10132 * "Do not advertise to any peer (well-known community)\n"
10133 * "Do not export to next AS (well-known community)\n"
10134 * COMMUNITY_AANN_STR
10135 * "Do not send outside local AS (well-known community)\n"
10136 * "Do not advertise to any peer (well-known community)\n"
10137 * "Do not export to next AS (well-known community)\n"
10138 *
10139 * "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)",
10140 * SHOW_STR
10141 * BGP_STR
10142 * BGP_INSTANCE_HELP_STR
10143 * "Address family\n"
10144 * "Address family\n"
10145 * "Address family modifier\n"
10146 * "Address family modifier\n"
10147 * "Display routes matching the communities\n"
10148 * COMMUNITY_AANN_STR
10149 * "Do not send outside local AS (well-known community)\n"
10150 * "Do not advertise to any peer (well-known community)\n"
10151 * "Do not export to next AS (well-known community)\n"
10152 * COMMUNITY_AANN_STR
10153 * "Do not send outside local AS (well-known community)\n"
10154 * "Do not advertise to any peer (well-known community)\n"
10155 * "Do not export to next AS (well-known community)\n"
10156 * COMMUNITY_AANN_STR
10157 * "Do not send outside local AS (well-known community)\n"
10158 * "Do not advertise to any peer (well-known community)\n"
10159 * "Do not export to next AS (well-known community)\n"
10160 * COMMUNITY_AANN_STR
10161 * "Do not send outside local AS (well-known community)\n"
10162 * "Do not advertise to any peer (well-known community)\n"
10163 * "Do not export to next AS (well-known community)\n"
10164 *
10165 * "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)",
10166 * SHOW_STR
10167 * BGP_STR
10168 * BGP_INSTANCE_HELP_STR
10169 * "Address family\n"
10170 * "Address family\n"
10171 * "Address family modifier\n"
10172 * "Address family modifier\n"
10173 * "Display routes matching the communities\n"
10174 * COMMUNITY_AANN_STR
10175 * "Do not send outside local AS (well-known community)\n"
10176 * "Do not advertise to any peer (well-known community)\n"
10177 * "Do not export to next AS (well-known community)\n"
10178 * COMMUNITY_AANN_STR
10179 * "Do not send outside local AS (well-known community)\n"
10180 * "Do not advertise to any peer (well-known community)\n"
10181 * "Do not export to next AS (well-known community)\n"
10182 *
10183 */
10184DEFUN (show_bgp_instance_afi_safi_community,
10185 show_bgp_instance_afi_safi_community_cmd,
6147e2c6 10186 "show bgp " BGP_INSTANCE_CMD " <ipv4|ipv6> <unicast|multicast> community <AA:NN|local-AS|no-advertise|no-export>",
f412b39a
DW
10187 SHOW_STR
10188 BGP_STR
10189 BGP_INSTANCE_HELP_STR
10190 "Address family\n"
10191 "Address family\n"
10192 "Address family modifier\n"
10193 "Address family modifier\n"
95cbbd2a 10194 "Display routes matching the communities\n"
859d388e 10195 COMMUNITY_AANN_STR
95cbbd2a
ML
10196 "Do not send outside local AS (well-known community)\n"
10197 "Do not advertise to any peer (well-known community)\n"
10198 "Do not export to next AS (well-known community)\n")
10199{
10200 int afi;
10201 int safi;
10202
4dcadbef
DW
10203 afi = (strncmp (argv[4]->arg, "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10204 safi = (strncmp (argv[5]->arg, "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10205 return bgp_show_community (vty, argv[3]->arg, argc, argv, 0, afi, safi);
95cbbd2a
ML
10206}
10207
95cbbd2a 10208
95cbbd2a 10209
95cbbd2a 10210
f412b39a
DW
10211/*
10212 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
10213 * "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",
10214 * SHOW_STR
10215 * IP_STR
10216 * BGP_STR
10217 * "Display routes matching the communities\n"
10218 * COMMUNITY_AANN_STR
10219 * "Do not send outside local AS (well-known community)\n"
10220 * "Do not advertise to any peer (well-known community)\n"
10221 * "Do not export to next AS (well-known community)\n"
10222 * COMMUNITY_AANN_STR
10223 * "Do not send outside local AS (well-known community)\n"
10224 * "Do not advertise to any peer (well-known community)\n"
10225 * "Do not export to next AS (well-known community)\n"
10226 * COMMUNITY_AANN_STR
10227 * "Do not send outside local AS (well-known community)\n"
10228 * "Do not advertise to any peer (well-known community)\n"
10229 * "Do not export to next AS (well-known community)\n"
10230 * "Exact match of the communities"
10231 *
10232 * "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",
10233 * SHOW_STR
10234 * IP_STR
10235 * BGP_STR
10236 * "Display routes matching the communities\n"
10237 * COMMUNITY_AANN_STR
10238 * "Do not send outside local AS (well-known community)\n"
10239 * "Do not advertise to any peer (well-known community)\n"
10240 * "Do not export to next AS (well-known community)\n"
10241 * COMMUNITY_AANN_STR
10242 * "Do not send outside local AS (well-known community)\n"
10243 * "Do not advertise to any peer (well-known community)\n"
10244 * "Do not export to next AS (well-known community)\n"
10245 * COMMUNITY_AANN_STR
10246 * "Do not send outside local AS (well-known community)\n"
10247 * "Do not advertise to any peer (well-known community)\n"
10248 * "Do not export to next AS (well-known community)\n"
10249 * COMMUNITY_AANN_STR
10250 * "Do not send outside local AS (well-known community)\n"
10251 * "Do not advertise to any peer (well-known community)\n"
10252 * "Do not export to next AS (well-known community)\n"
10253 * "Exact match of the communities"
10254 *
10255 * "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10256 * SHOW_STR
10257 * IP_STR
10258 * BGP_STR
10259 * "Display routes matching the communities\n"
10260 * COMMUNITY_AANN_STR
10261 * "Do not send outside local AS (well-known community)\n"
10262 * "Do not advertise to any peer (well-known community)\n"
10263 * "Do not export to next AS (well-known community)\n"
10264 * COMMUNITY_AANN_STR
10265 * "Do not send outside local AS (well-known community)\n"
10266 * "Do not advertise to any peer (well-known community)\n"
10267 * "Do not export to next AS (well-known community)\n"
10268 * "Exact match of the communities"
10269 *
10270 */
718e3744 10271DEFUN (show_ip_bgp_community_exact,
10272 show_ip_bgp_community_exact_cmd,
6147e2c6 10273 "show ip bgp community <AA:NN|local-AS|no-advertise|no-export> exact-match",
718e3744 10274 SHOW_STR
10275 IP_STR
10276 BGP_STR
10277 "Display routes matching the communities\n"
859d388e 10278 COMMUNITY_AANN_STR
718e3744 10279 "Do not send outside local AS (well-known community)\n"
10280 "Do not advertise to any peer (well-known community)\n"
10281 "Do not export to next AS (well-known community)\n"
10282 "Exact match of the communities")
10283{
95cbbd2a 10284 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 10285}
10286
718e3744 10287
718e3744 10288
718e3744 10289
f412b39a
DW
10290/*
10291 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
10292 * "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",
10293 * SHOW_STR
10294 * IP_STR
10295 * BGP_STR
10296 * "Address family\n"
10297 * "Address Family modifier\n"
10298 * "Address Family modifier\n"
10299 * "Display routes matching the communities\n"
10300 * COMMUNITY_AANN_STR
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"
10304 * COMMUNITY_AANN_STR
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"
10308 * COMMUNITY_AANN_STR
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 * "Exact match of the communities"
10313 *
10314 * "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",
10315 * SHOW_STR
10316 * IP_STR
10317 * BGP_STR
10318 * "Address family\n"
10319 * "Address Family modifier\n"
10320 * "Address Family modifier\n"
10321 * "Display routes matching the communities\n"
10322 * COMMUNITY_AANN_STR
10323 * "Do not send outside local AS (well-known community)\n"
10324 * "Do not advertise to any peer (well-known community)\n"
10325 * "Do not export to next AS (well-known community)\n"
10326 * COMMUNITY_AANN_STR
10327 * "Do not send outside local AS (well-known community)\n"
10328 * "Do not advertise to any peer (well-known community)\n"
10329 * "Do not export to next AS (well-known community)\n"
10330 * "Exact match of the communities"
10331 *
10332 * "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",
10333 * SHOW_STR
10334 * IP_STR
10335 * BGP_STR
10336 * "Address family\n"
10337 * "Address Family modifier\n"
10338 * "Address Family modifier\n"
10339 * "Display routes matching the communities\n"
10340 * COMMUNITY_AANN_STR
10341 * "Do not send outside local AS (well-known community)\n"
10342 * "Do not advertise to any peer (well-known community)\n"
10343 * "Do not export to next AS (well-known community)\n"
10344 * COMMUNITY_AANN_STR
10345 * "Do not send outside local AS (well-known community)\n"
10346 * "Do not advertise to any peer (well-known community)\n"
10347 * "Do not export to next AS (well-known community)\n"
10348 * COMMUNITY_AANN_STR
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 * COMMUNITY_AANN_STR
10353 * "Do not send outside local AS (well-known community)\n"
10354 * "Do not advertise to any peer (well-known community)\n"
10355 * "Do not export to next AS (well-known community)\n"
10356 * "Exact match of the communities"
10357 *
10358 */
718e3744 10359DEFUN (show_ip_bgp_ipv4_community_exact,
10360 show_ip_bgp_ipv4_community_exact_cmd,
6147e2c6 10361 "show ip bgp ipv4 <unicast|multicast> community <AA:NN|local-AS|no-advertise|no-export> exact-match",
718e3744 10362 SHOW_STR
10363 IP_STR
10364 BGP_STR
10365 "Address family\n"
10366 "Address Family modifier\n"
10367 "Address Family modifier\n"
10368 "Display routes matching the communities\n"
859d388e 10369 COMMUNITY_AANN_STR
718e3744 10370 "Do not send outside local AS (well-known community)\n"
10371 "Do not advertise to any peer (well-known community)\n"
10372 "Do not export to next AS (well-known community)\n"
10373 "Exact match of the communities")
10374{
4dcadbef 10375 if (strncmp (argv[4]->arg, "m", 1) == 0)
95cbbd2a 10376 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
718e3744 10377
95cbbd2a 10378 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 10379}
10380
f412b39a
DW
10381
10382
10383
10384#ifdef HAVE_IPV6
10385/*
10386 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
10387 * "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
10388 * SHOW_STR
10389 * BGP_STR
10390 * "Address family\n"
10391 * "Display routes matching the communities\n"
10392 * COMMUNITY_AANN_STR
10393 * "Do not send outside local AS (well-known community)\n"
10394 * "Do not advertise to any peer (well-known community)\n"
10395 * "Do not export to next AS (well-known community)\n"
10396 *
10397 * "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)",
10398 * SHOW_STR
10399 * BGP_STR
10400 * "Address family\n"
10401 * "Display routes matching the communities\n"
10402 * COMMUNITY_AANN_STR
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"
10406 * COMMUNITY_AANN_STR
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"
10410 * COMMUNITY_AANN_STR
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"
10414 * COMMUNITY_AANN_STR
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 *
10419 * "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10420 * SHOW_STR
10421 * BGP_STR
10422 * "Address family\n"
10423 * "Display routes matching the communities\n"
10424 * COMMUNITY_AANN_STR
10425 * "Do not send outside local AS (well-known community)\n"
10426 * "Do not advertise to any peer (well-known community)\n"
10427 * "Do not export to next AS (well-known community)\n"
10428 * COMMUNITY_AANN_STR
10429 * "Do not send outside local AS (well-known community)\n"
10430 * "Do not advertise to any peer (well-known community)\n"
10431 * "Do not export to next AS (well-known community)\n"
10432 *
10433 * "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)",
10434 * SHOW_STR
10435 * BGP_STR
10436 * "Display routes matching the communities\n"
10437 * COMMUNITY_AANN_STR
10438 * "Do not send outside local AS (well-known community)\n"
10439 * "Do not advertise to any peer (well-known community)\n"
10440 * "Do not export to next AS (well-known community)\n"
10441 * COMMUNITY_AANN_STR
10442 * "Do not send outside local AS (well-known community)\n"
10443 * "Do not advertise to any peer (well-known community)\n"
10444 * "Do not export to next AS (well-known community)\n"
10445 * COMMUNITY_AANN_STR
10446 * "Do not send outside local AS (well-known community)\n"
10447 * "Do not advertise to any peer (well-known community)\n"
10448 * "Do not export to next AS (well-known community)\n"
10449 *
10450 * "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10451 * SHOW_STR
10452 * BGP_STR
10453 * "Display routes matching the communities\n"
10454 * COMMUNITY_AANN_STR
10455 * "Do not send outside local AS (well-known community)\n"
10456 * "Do not advertise to any peer (well-known community)\n"
10457 * "Do not export to next AS (well-known community)\n"
10458 * COMMUNITY_AANN_STR
10459 * "Do not send outside local AS (well-known community)\n"
10460 * "Do not advertise to any peer (well-known community)\n"
10461 * "Do not export to next AS (well-known community)\n"
10462 *
10463 * "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)",
10464 * SHOW_STR
10465 * BGP_STR
10466 * "Address family\n"
10467 * "Display routes matching the communities\n"
10468 * COMMUNITY_AANN_STR
10469 * "Do not send outside local AS (well-known community)\n"
10470 * "Do not advertise to any peer (well-known community)\n"
10471 * "Do not export to next AS (well-known community)\n"
10472 * COMMUNITY_AANN_STR
10473 * "Do not send outside local AS (well-known community)\n"
10474 * "Do not advertise to any peer (well-known community)\n"
10475 * "Do not export to next AS (well-known community)\n"
10476 * COMMUNITY_AANN_STR
10477 * "Do not send outside local AS (well-known community)\n"
10478 * "Do not advertise to any peer (well-known community)\n"
10479 * "Do not export to next AS (well-known community)\n"
10480 *
10481 * "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)",
10482 * SHOW_STR
10483 * BGP_STR
10484 * "Display routes matching the communities\n"
10485 * COMMUNITY_AANN_STR
10486 * "Do not send outside local AS (well-known community)\n"
10487 * "Do not advertise to any peer (well-known community)\n"
10488 * "Do not export to next AS (well-known community)\n"
10489 * COMMUNITY_AANN_STR
10490 * "Do not send outside local AS (well-known community)\n"
10491 * "Do not advertise to any peer (well-known community)\n"
10492 * "Do not export to next AS (well-known community)\n"
10493 * COMMUNITY_AANN_STR
10494 * "Do not send outside local AS (well-known community)\n"
10495 * "Do not advertise to any peer (well-known community)\n"
10496 * "Do not export to next AS (well-known community)\n"
10497 * COMMUNITY_AANN_STR
10498 * "Do not send outside local AS (well-known community)\n"
10499 * "Do not advertise to any peer (well-known community)\n"
10500 * "Do not export to next AS (well-known community)\n"
10501 *
10502 */
10503DEFUN (show_bgp_community,
10504 show_bgp_community_cmd,
6147e2c6 10505 "show bgp community <AA:NN|local-AS|no-advertise|no-export>",
718e3744 10506 SHOW_STR
718e3744 10507 BGP_STR
718e3744 10508 "Display routes matching the communities\n"
859d388e 10509 COMMUNITY_AANN_STR
718e3744 10510 "Do not send outside local AS (well-known community)\n"
10511 "Do not advertise to any peer (well-known community)\n"
f412b39a
DW
10512 "Do not export to next AS (well-known community)\n")
10513{
10514 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10515}
10516
10517
10518
10519
10520
10521
10522
10523
10524/* old command */
10525/*
10526 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
10527 * "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)",
10528 * SHOW_STR
10529 * IPV6_STR
10530 * BGP_STR
10531 * "Display routes matching the communities\n"
10532 * COMMUNITY_AANN_STR
10533 * "Do not send outside local AS (well-known community)\n"
10534 * "Do not advertise to any peer (well-known community)\n"
10535 * "Do not export to next AS (well-known community)\n"
10536 * COMMUNITY_AANN_STR
10537 * "Do not send outside local AS (well-known community)\n"
10538 * "Do not advertise to any peer (well-known community)\n"
10539 * "Do not export to next AS (well-known community)\n"
10540 * COMMUNITY_AANN_STR
10541 * "Do not send outside local AS (well-known community)\n"
10542 * "Do not advertise to any peer (well-known community)\n"
10543 * "Do not export to next AS (well-known community)\n"
10544 *
10545 * "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)",
10546 * SHOW_STR
10547 * IPV6_STR
10548 * BGP_STR
10549 * "Display routes matching the communities\n"
10550 * COMMUNITY_AANN_STR
10551 * "Do not send outside local AS (well-known community)\n"
10552 * "Do not advertise to any peer (well-known community)\n"
10553 * "Do not export to next AS (well-known community)\n"
10554 * COMMUNITY_AANN_STR
10555 * "Do not send outside local AS (well-known community)\n"
10556 * "Do not advertise to any peer (well-known community)\n"
10557 * "Do not export to next AS (well-known community)\n"
10558 * COMMUNITY_AANN_STR
10559 * "Do not send outside local AS (well-known community)\n"
10560 * "Do not advertise to any peer (well-known community)\n"
10561 * "Do not export to next AS (well-known community)\n"
10562 * COMMUNITY_AANN_STR
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"
10566 *
10567 * "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10568 * SHOW_STR
10569 * IPV6_STR
10570 * BGP_STR
10571 * "Display routes matching the communities\n"
10572 * COMMUNITY_AANN_STR
10573 * "Do not send outside local AS (well-known community)\n"
10574 * "Do not advertise to any peer (well-known community)\n"
10575 * "Do not export to next AS (well-known community)\n"
10576 * COMMUNITY_AANN_STR
10577 * "Do not send outside local AS (well-known community)\n"
10578 * "Do not advertise to any peer (well-known community)\n"
10579 * "Do not export to next AS (well-known community)\n"
10580 *
10581 */
10582DEFUN (show_ipv6_bgp_community,
10583 show_ipv6_bgp_community_cmd,
6147e2c6 10584 "show ipv6 bgp community <AA:NN|local-AS|no-advertise|no-export>",
f412b39a
DW
10585 SHOW_STR
10586 IPV6_STR
10587 BGP_STR
10588 "Display routes matching the communities\n"
859d388e 10589 COMMUNITY_AANN_STR
718e3744 10590 "Do not send outside local AS (well-known community)\n"
10591 "Do not advertise to any peer (well-known community)\n"
10592 "Do not export to next AS (well-known community)\n")
10593{
47e9b292 10594 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 10595 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 10596}
10597
10598/* old command */
718e3744 10599
10600/* old command */
718e3744 10601
10602/* old command */
718e3744 10603
f412b39a
DW
10604/*
10605 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
10606 * "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10607 * SHOW_STR
10608 * BGP_STR
10609 * "Display routes matching the communities\n"
10610 * COMMUNITY_AANN_STR
10611 * "Do not send outside local AS (well-known community)\n"
10612 * "Do not advertise to any peer (well-known community)\n"
10613 * "Do not export to next AS (well-known community)\n"
10614 * COMMUNITY_AANN_STR
10615 * "Do not send outside local AS (well-known community)\n"
10616 * "Do not advertise to any peer (well-known community)\n"
10617 * "Do not export to next AS (well-known community)\n"
10618 * "Exact match of the communities"
10619 *
10620 * "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",
10621 * SHOW_STR
10622 * BGP_STR
10623 * "Address family\n"
10624 * "Display routes matching the communities\n"
10625 * COMMUNITY_AANN_STR
10626 * "Do not send outside local AS (well-known community)\n"
10627 * "Do not advertise to any peer (well-known community)\n"
10628 * "Do not export to next AS (well-known community)\n"
10629 * COMMUNITY_AANN_STR
10630 * "Do not send outside local AS (well-known community)\n"
10631 * "Do not advertise to any peer (well-known community)\n"
10632 * "Do not export to next AS (well-known community)\n"
10633 * COMMUNITY_AANN_STR
10634 * "Do not send outside local AS (well-known community)\n"
10635 * "Do not advertise to any peer (well-known community)\n"
10636 * "Do not export to next AS (well-known community)\n"
10637 * COMMUNITY_AANN_STR
10638 * "Do not send outside local AS (well-known community)\n"
10639 * "Do not advertise to any peer (well-known community)\n"
10640 * "Do not export to next AS (well-known community)\n"
10641 * "Exact match of the communities"
10642 *
10643 * "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",
10644 * SHOW_STR
10645 * BGP_STR
10646 * "Address family\n"
10647 * "Display routes matching the communities\n"
10648 * COMMUNITY_AANN_STR
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"
10652 * COMMUNITY_AANN_STR
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 * COMMUNITY_AANN_STR
10657 * "Do not send outside local AS (well-known community)\n"
10658 * "Do not advertise to any peer (well-known community)\n"
10659 * "Do not export to next AS (well-known community)\n"
10660 * "Exact match of the communities"
10661 *
10662 * "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",
10663 * SHOW_STR
10664 * BGP_STR
10665 * "Display routes matching the communities\n"
10666 * COMMUNITY_AANN_STR
10667 * "Do not send outside local AS (well-known community)\n"
10668 * "Do not advertise to any peer (well-known community)\n"
10669 * "Do not export to next AS (well-known community)\n"
10670 * COMMUNITY_AANN_STR
10671 * "Do not send outside local AS (well-known community)\n"
10672 * "Do not advertise to any peer (well-known community)\n"
10673 * "Do not export to next AS (well-known community)\n"
10674 * COMMUNITY_AANN_STR
10675 * "Do not send outside local AS (well-known community)\n"
10676 * "Do not advertise to any peer (well-known community)\n"
10677 * "Do not export to next AS (well-known community)\n"
10678 * "Exact match of the communities"
10679 *
10680 * "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",
10681 * SHOW_STR
10682 * BGP_STR
10683 * "Display routes matching the communities\n"
10684 * COMMUNITY_AANN_STR
10685 * "Do not send outside local AS (well-known community)\n"
10686 * "Do not advertise to any peer (well-known community)\n"
10687 * "Do not export to next AS (well-known community)\n"
10688 * COMMUNITY_AANN_STR
10689 * "Do not send outside local AS (well-known community)\n"
10690 * "Do not advertise to any peer (well-known community)\n"
10691 * "Do not export to next AS (well-known community)\n"
10692 * COMMUNITY_AANN_STR
10693 * "Do not send outside local AS (well-known community)\n"
10694 * "Do not advertise to any peer (well-known community)\n"
10695 * "Do not export to next AS (well-known community)\n"
10696 * COMMUNITY_AANN_STR
10697 * "Do not send outside local AS (well-known community)\n"
10698 * "Do not advertise to any peer (well-known community)\n"
10699 * "Do not export to next AS (well-known community)\n"
10700 * "Exact match of the communities"
10701 *
10702 * "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10703 * SHOW_STR
10704 * BGP_STR
10705 * "Address family\n"
10706 * "Display routes matching the communities\n"
10707 * COMMUNITY_AANN_STR
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 * "Exact match of the communities"
10712 *
10713 * "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10714 * SHOW_STR
10715 * BGP_STR
10716 * "Address family\n"
10717 * "Display routes matching the communities\n"
10718 * COMMUNITY_AANN_STR
10719 * "Do not send outside local AS (well-known community)\n"
10720 * "Do not advertise to any peer (well-known community)\n"
10721 * "Do not export to next AS (well-known community)\n"
10722 * COMMUNITY_AANN_STR
10723 * "Do not send outside local AS (well-known community)\n"
10724 * "Do not advertise to any peer (well-known community)\n"
10725 * "Do not export to next AS (well-known community)\n"
10726 * "Exact match of the communities"
10727 *
10728 */
718e3744 10729DEFUN (show_bgp_community_exact,
10730 show_bgp_community_exact_cmd,
6147e2c6 10731 "show bgp community <AA:NN|local-AS|no-advertise|no-export> exact-match",
718e3744 10732 SHOW_STR
10733 BGP_STR
10734 "Display routes matching the communities\n"
859d388e 10735 COMMUNITY_AANN_STR
718e3744 10736 "Do not send outside local AS (well-known community)\n"
10737 "Do not advertise to any peer (well-known community)\n"
10738 "Do not export to next AS (well-known community)\n"
10739 "Exact match of the communities")
10740{
95cbbd2a 10741 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 10742}
10743
718e3744 10744
718e3744 10745
718e3744 10746
718e3744 10747
718e3744 10748
718e3744 10749
718e3744 10750
10751/* old command */
f412b39a
DW
10752/*
10753 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
10754 * "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",
10755 * SHOW_STR
10756 * IPV6_STR
10757 * BGP_STR
10758 * "Display routes matching the communities\n"
10759 * COMMUNITY_AANN_STR
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 * COMMUNITY_AANN_STR
10764 * "Do not send outside local AS (well-known community)\n"
10765 * "Do not advertise to any peer (well-known community)\n"
10766 * "Do not export to next AS (well-known community)\n"
10767 * COMMUNITY_AANN_STR
10768 * "Do not send outside local AS (well-known community)\n"
10769 * "Do not advertise to any peer (well-known community)\n"
10770 * "Do not export to next AS (well-known community)\n"
10771 * COMMUNITY_AANN_STR
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"
10775 * "Exact match of the communities"
10776 *
10777 * "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10778 * SHOW_STR
10779 * IPV6_STR
10780 * BGP_STR
10781 * "Display routes matching the communities\n"
10782 * COMMUNITY_AANN_STR
10783 * "Do not send outside local AS (well-known community)\n"
10784 * "Do not advertise to any peer (well-known community)\n"
10785 * "Do not export to next AS (well-known community)\n"
10786 * COMMUNITY_AANN_STR
10787 * "Do not send outside local AS (well-known community)\n"
10788 * "Do not advertise to any peer (well-known community)\n"
10789 * "Do not export to next AS (well-known community)\n"
10790 * "Exact match of the communities"
10791 *
10792 * "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",
10793 * SHOW_STR
10794 * IPV6_STR
10795 * BGP_STR
10796 * "Display routes matching the communities\n"
10797 * COMMUNITY_AANN_STR
10798 * "Do not send outside local AS (well-known community)\n"
10799 * "Do not advertise to any peer (well-known community)\n"
10800 * "Do not export to next AS (well-known community)\n"
10801 * COMMUNITY_AANN_STR
10802 * "Do not send outside local AS (well-known community)\n"
10803 * "Do not advertise to any peer (well-known community)\n"
10804 * "Do not export to next AS (well-known community)\n"
10805 * COMMUNITY_AANN_STR
10806 * "Do not send outside local AS (well-known community)\n"
10807 * "Do not advertise to any peer (well-known community)\n"
10808 * "Do not export to next AS (well-known community)\n"
10809 * "Exact match of the communities"
10810 *
10811 */
718e3744 10812DEFUN (show_ipv6_bgp_community_exact,
10813 show_ipv6_bgp_community_exact_cmd,
6147e2c6 10814 "show ipv6 bgp community <AA:NN|local-AS|no-advertise|no-export> exact-match",
718e3744 10815 SHOW_STR
10816 IPV6_STR
10817 BGP_STR
10818 "Display routes matching the communities\n"
859d388e 10819 COMMUNITY_AANN_STR
718e3744 10820 "Do not send outside local AS (well-known community)\n"
10821 "Do not advertise to any peer (well-known community)\n"
10822 "Do not export to next AS (well-known community)\n"
10823 "Exact match of the communities")
f412b39a
DW
10824{
10825 bgp_show_ipv6_bgp_deprecate_warning(vty);
10826 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10827}
10828
10829/* old command */
10830
10831/* old command */
10832
10833/* old command */
718e3744 10834
10835/* old command */
f412b39a
DW
10836/*
10837 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
10838 * "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10839 * SHOW_STR
10840 * IPV6_STR
10841 * MBGP_STR
10842 * "Display routes matching the communities\n"
10843 * COMMUNITY_AANN_STR
10844 * "Do not send outside local AS (well-known community)\n"
10845 * "Do not advertise to any peer (well-known community)\n"
10846 * "Do not export to next AS (well-known community)\n"
10847 * COMMUNITY_AANN_STR
10848 * "Do not send outside local AS (well-known community)\n"
10849 * "Do not advertise to any peer (well-known community)\n"
10850 * "Do not export to next AS (well-known community)\n"
10851 *
10852 * "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)",
10853 * SHOW_STR
10854 * IPV6_STR
10855 * MBGP_STR
10856 * "Display routes matching the communities\n"
10857 * COMMUNITY_AANN_STR
10858 * "Do not send outside local AS (well-known community)\n"
10859 * "Do not advertise to any peer (well-known community)\n"
10860 * "Do not export to next AS (well-known community)\n"
10861 * COMMUNITY_AANN_STR
10862 * "Do not send outside local AS (well-known community)\n"
10863 * "Do not advertise to any peer (well-known community)\n"
10864 * "Do not export to next AS (well-known community)\n"
10865 * COMMUNITY_AANN_STR
10866 * "Do not send outside local AS (well-known community)\n"
10867 * "Do not advertise to any peer (well-known community)\n"
10868 * "Do not export to next AS (well-known community)\n"
10869 *
10870 * "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)",
10871 * SHOW_STR
10872 * IPV6_STR
10873 * MBGP_STR
10874 * "Display routes matching the communities\n"
10875 * COMMUNITY_AANN_STR
10876 * "Do not send outside local AS (well-known community)\n"
10877 * "Do not advertise to any peer (well-known community)\n"
10878 * "Do not export to next AS (well-known community)\n"
10879 * COMMUNITY_AANN_STR
10880 * "Do not send outside local AS (well-known community)\n"
10881 * "Do not advertise to any peer (well-known community)\n"
10882 * "Do not export to next AS (well-known community)\n"
10883 * COMMUNITY_AANN_STR
10884 * "Do not send outside local AS (well-known community)\n"
10885 * "Do not advertise to any peer (well-known community)\n"
10886 * "Do not export to next AS (well-known community)\n"
10887 * COMMUNITY_AANN_STR
10888 * "Do not send outside local AS (well-known community)\n"
10889 * "Do not advertise to any peer (well-known community)\n"
10890 * "Do not export to next AS (well-known community)\n"
10891 *
10892 */
718e3744 10893DEFUN (show_ipv6_mbgp_community,
10894 show_ipv6_mbgp_community_cmd,
6147e2c6 10895 "show ipv6 mbgp community <AA:NN|local-AS|no-advertise|no-export>",
718e3744 10896 SHOW_STR
10897 IPV6_STR
10898 MBGP_STR
10899 "Display routes matching the communities\n"
859d388e 10900 COMMUNITY_AANN_STR
718e3744 10901 "Do not send outside local AS (well-known community)\n"
10902 "Do not advertise to any peer (well-known community)\n"
10903 "Do not export to next AS (well-known community)\n")
10904{
47e9b292 10905 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 10906 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
718e3744 10907}
10908
10909/* old command */
718e3744 10910
10911/* old command */
718e3744 10912
10913/* old command */
718e3744 10914
10915/* old command */
f412b39a
DW
10916/*
10917 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
10918 * "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",
10919 * SHOW_STR
10920 * IPV6_STR
10921 * MBGP_STR
10922 * "Display routes matching the communities\n"
10923 * COMMUNITY_AANN_STR
10924 * "Do not send outside local AS (well-known community)\n"
10925 * "Do not advertise to any peer (well-known community)\n"
10926 * "Do not export to next AS (well-known community)\n"
10927 * COMMUNITY_AANN_STR
10928 * "Do not send outside local AS (well-known community)\n"
10929 * "Do not advertise to any peer (well-known community)\n"
10930 * "Do not export to next AS (well-known community)\n"
10931 * COMMUNITY_AANN_STR
10932 * "Do not send outside local AS (well-known community)\n"
10933 * "Do not advertise to any peer (well-known community)\n"
10934 * "Do not export to next AS (well-known community)\n"
10935 * "Exact match of the communities"
10936 *
10937 * "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",
10938 * SHOW_STR
10939 * IPV6_STR
10940 * MBGP_STR
10941 * "Display routes matching the communities\n"
10942 * COMMUNITY_AANN_STR
10943 * "Do not send outside local AS (well-known community)\n"
10944 * "Do not advertise to any peer (well-known community)\n"
10945 * "Do not export to next AS (well-known community)\n"
10946 * COMMUNITY_AANN_STR
10947 * "Do not send outside local AS (well-known community)\n"
10948 * "Do not advertise to any peer (well-known community)\n"
10949 * "Do not export to next AS (well-known community)\n"
10950 * COMMUNITY_AANN_STR
10951 * "Do not send outside local AS (well-known community)\n"
10952 * "Do not advertise to any peer (well-known community)\n"
10953 * "Do not export to next AS (well-known community)\n"
10954 * COMMUNITY_AANN_STR
10955 * "Do not send outside local AS (well-known community)\n"
10956 * "Do not advertise to any peer (well-known community)\n"
10957 * "Do not export to next AS (well-known community)\n"
10958 * "Exact match of the communities"
10959 *
10960 * "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10961 * SHOW_STR
10962 * IPV6_STR
10963 * MBGP_STR
10964 * "Display routes matching the communities\n"
10965 * COMMUNITY_AANN_STR
10966 * "Do not send outside local AS (well-known community)\n"
10967 * "Do not advertise to any peer (well-known community)\n"
10968 * "Do not export to next AS (well-known community)\n"
10969 * COMMUNITY_AANN_STR
10970 * "Do not send outside local AS (well-known community)\n"
10971 * "Do not advertise to any peer (well-known community)\n"
10972 * "Do not export to next AS (well-known community)\n"
10973 * "Exact match of the communities"
10974 *
10975 */
718e3744 10976DEFUN (show_ipv6_mbgp_community_exact,
10977 show_ipv6_mbgp_community_exact_cmd,
6147e2c6 10978 "show ipv6 mbgp community <AA:NN|local-AS|no-advertise|no-export> exact-match",
718e3744 10979 SHOW_STR
10980 IPV6_STR
10981 MBGP_STR
10982 "Display routes matching the communities\n"
859d388e 10983 COMMUNITY_AANN_STR
718e3744 10984 "Do not send outside local AS (well-known community)\n"
10985 "Do not advertise to any peer (well-known community)\n"
10986 "Do not export to next AS (well-known community)\n"
10987 "Exact match of the communities")
10988{
47e9b292 10989 bgp_show_ipv6_bgp_deprecate_warning(vty);
95cbbd2a 10990 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
718e3744 10991}
10992
10993/* old command */
718e3744 10994
10995/* old command */
718e3744 10996
10997/* old command */
718e3744 10998#endif /* HAVE_IPV6 */
6b0655a2 10999
94f2b392 11000static int
50ef26d4 11001bgp_show_community_list (struct vty *vty, const char *name,
11002 const char *com, int exact,
4c9641ba 11003 afi_t afi, safi_t safi)
718e3744 11004{
11005 struct community_list *list;
50ef26d4 11006 struct bgp *bgp = NULL;
11007
11008 if (name && !(bgp = bgp_lookup_by_name(name)))
11009 {
11010 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11011 return CMD_WARNING;
11012 }
718e3744 11013
fee6e4e4 11014 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
718e3744 11015 if (list == NULL)
11016 {
11017 vty_out (vty, "%% %s is not a valid community-list name%s", com,
11018 VTY_NEWLINE);
11019 return CMD_WARNING;
11020 }
11021
50ef26d4 11022 return bgp_show (vty, bgp, afi, safi,
5a646650 11023 (exact ? bgp_show_type_community_list_exact :
b05a1c8b 11024 bgp_show_type_community_list), list, 0);
718e3744 11025}
11026
11027DEFUN (show_ip_bgp_community_list,
11028 show_ip_bgp_community_list_cmd,
6147e2c6 11029 "show ip bgp community-list <(1-500)|WORD>",
718e3744 11030 SHOW_STR
11031 IP_STR
11032 BGP_STR
11033 "Display routes matching the community-list\n"
fee6e4e4 11034 "community-list number\n"
718e3744 11035 "community-list name\n")
11036{
4dcadbef 11037 return bgp_show_community_list (vty, NULL, argv[4]->arg, 0, AFI_IP, SAFI_UNICAST);
50ef26d4 11038}
11039
8386ac43 11040DEFUN (show_ip_bgp_instance_community_list,
11041 show_ip_bgp_instance_community_list_cmd,
6147e2c6 11042 "show ip bgp " BGP_INSTANCE_CMD " community-list <(1-500)|WORD>",
50ef26d4 11043 SHOW_STR
11044 IP_STR
11045 BGP_STR
8386ac43 11046 BGP_INSTANCE_HELP_STR
50ef26d4 11047 "Display routes matching the community-list\n"
11048 "community-list number\n"
11049 "community-list name\n")
11050{
4dcadbef 11051 return bgp_show_community_list (vty, argv[4]->arg, argv[6]->arg, 0, AFI_IP, SAFI_UNICAST);
718e3744 11052}
11053
11054DEFUN (show_ip_bgp_ipv4_community_list,
11055 show_ip_bgp_ipv4_community_list_cmd,
6147e2c6 11056 "show ip bgp ipv4 <unicast|multicast> community-list <(1-500)|WORD>",
718e3744 11057 SHOW_STR
11058 IP_STR
11059 BGP_STR
11060 "Address family\n"
11061 "Address Family modifier\n"
11062 "Address Family modifier\n"
11063 "Display routes matching the community-list\n"
fee6e4e4 11064 "community-list number\n"
718e3744 11065 "community-list name\n")
11066{
4dcadbef
DW
11067 if (strncmp (argv[4]->arg, "m", 1) == 0)
11068 return bgp_show_community_list (vty, NULL, argv[6]->arg, 0, AFI_IP, SAFI_MULTICAST);
718e3744 11069
4dcadbef 11070 return bgp_show_community_list (vty, NULL, argv[6]->arg, 0, AFI_IP, SAFI_UNICAST);
718e3744 11071}
11072
11073DEFUN (show_ip_bgp_community_list_exact,
11074 show_ip_bgp_community_list_exact_cmd,
6147e2c6 11075 "show ip bgp community-list <(1-500)|WORD> exact-match",
718e3744 11076 SHOW_STR
11077 IP_STR
11078 BGP_STR
11079 "Display routes matching the community-list\n"
fee6e4e4 11080 "community-list number\n"
718e3744 11081 "community-list name\n"
11082 "Exact match of the communities\n")
11083{
4dcadbef 11084 return bgp_show_community_list (vty, NULL, argv[4]->arg, 1, AFI_IP, SAFI_UNICAST);
718e3744 11085}
11086
11087DEFUN (show_ip_bgp_ipv4_community_list_exact,
11088 show_ip_bgp_ipv4_community_list_exact_cmd,
6147e2c6 11089 "show ip bgp ipv4 <unicast|multicast> community-list <(1-500)|WORD> exact-match",
718e3744 11090 SHOW_STR
11091 IP_STR
11092 BGP_STR
11093 "Address family\n"
11094 "Address Family modifier\n"
11095 "Address Family modifier\n"
11096 "Display routes matching the community-list\n"
fee6e4e4 11097 "community-list number\n"
718e3744 11098 "community-list name\n"
11099 "Exact match of the communities\n")
11100{
4dcadbef
DW
11101 if (strncmp (argv[4]->arg, "m", 1) == 0)
11102 return bgp_show_community_list (vty, NULL, argv[6]->arg, 1, AFI_IP, SAFI_MULTICAST);
718e3744 11103
4dcadbef 11104 return bgp_show_community_list (vty, NULL, argv[6]->arg, 1, AFI_IP, SAFI_UNICAST);
718e3744 11105}
11106
11107#ifdef HAVE_IPV6
f412b39a
DW
11108/*
11109 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
11110 * "show bgp ipv6 community-list (<1-500>|WORD)",
11111 * SHOW_STR
11112 * BGP_STR
11113 * "Address family\n"
11114 * "Display routes matching the community-list\n"
11115 * "community-list number\n"
11116 * "community-list name\n"
11117 *
11118 */
718e3744 11119DEFUN (show_bgp_community_list,
11120 show_bgp_community_list_cmd,
6147e2c6 11121 "show bgp community-list <(1-500)|WORD>",
718e3744 11122 SHOW_STR
11123 BGP_STR
11124 "Display routes matching the community-list\n"
fee6e4e4 11125 "community-list number\n"
718e3744 11126 "community-list name\n")
11127{
4dcadbef 11128 return bgp_show_community_list (vty, NULL, argv[3]->arg, 0, AFI_IP6, SAFI_UNICAST);
718e3744 11129}
11130
718e3744 11131
11132/* old command */
11133DEFUN (show_ipv6_bgp_community_list,
11134 show_ipv6_bgp_community_list_cmd,
11135 "show ipv6 bgp community-list WORD",
11136 SHOW_STR
11137 IPV6_STR
11138 BGP_STR
11139 "Display routes matching the community-list\n"
11140 "community-list name\n")
11141{
47e9b292 11142 bgp_show_ipv6_bgp_deprecate_warning(vty);
4dcadbef 11143 return bgp_show_community_list (vty, NULL, argv[4]->arg, 0, AFI_IP6, SAFI_UNICAST);
718e3744 11144}
11145
11146/* old command */
11147DEFUN (show_ipv6_mbgp_community_list,
11148 show_ipv6_mbgp_community_list_cmd,
11149 "show ipv6 mbgp community-list WORD",
11150 SHOW_STR
11151 IPV6_STR
11152 MBGP_STR
11153 "Display routes matching the community-list\n"
11154 "community-list name\n")
11155{
47e9b292 11156 bgp_show_ipv6_bgp_deprecate_warning(vty);
4dcadbef 11157 return bgp_show_community_list (vty, NULL, argv[4]->arg, 0, AFI_IP6, SAFI_MULTICAST);
718e3744 11158}
11159
f412b39a
DW
11160/*
11161 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
11162 * "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
11163 * SHOW_STR
11164 * BGP_STR
11165 * "Address family\n"
11166 * "Display routes matching the community-list\n"
11167 * "community-list number\n"
11168 * "community-list name\n"
11169 * "Exact match of the communities\n"
11170 *
11171 */
718e3744 11172DEFUN (show_bgp_community_list_exact,
11173 show_bgp_community_list_exact_cmd,
6147e2c6 11174 "show bgp community-list <(1-500)|WORD> exact-match",
718e3744 11175 SHOW_STR
11176 BGP_STR
11177 "Display routes matching the community-list\n"
fee6e4e4 11178 "community-list number\n"
718e3744 11179 "community-list name\n"
11180 "Exact match of the communities\n")
11181{
4dcadbef 11182 return bgp_show_community_list (vty, NULL, argv[3]->arg, 1, AFI_IP6, SAFI_UNICAST);
718e3744 11183}
11184
718e3744 11185
11186/* old command */
11187DEFUN (show_ipv6_bgp_community_list_exact,
11188 show_ipv6_bgp_community_list_exact_cmd,
11189 "show ipv6 bgp community-list WORD exact-match",
11190 SHOW_STR
11191 IPV6_STR
11192 BGP_STR
11193 "Display routes matching the community-list\n"
11194 "community-list name\n"
11195 "Exact match of the communities\n")
11196{
47e9b292 11197 bgp_show_ipv6_bgp_deprecate_warning(vty);
4dcadbef 11198 return bgp_show_community_list (vty, NULL, argv[4]->arg, 1, AFI_IP6, SAFI_UNICAST);
718e3744 11199}
11200
11201/* old command */
11202DEFUN (show_ipv6_mbgp_community_list_exact,
11203 show_ipv6_mbgp_community_list_exact_cmd,
11204 "show ipv6 mbgp community-list WORD exact-match",
11205 SHOW_STR
11206 IPV6_STR
11207 MBGP_STR
11208 "Display routes matching the community-list\n"
11209 "community-list name\n"
11210 "Exact match of the communities\n")
11211{
47e9b292 11212 bgp_show_ipv6_bgp_deprecate_warning(vty);
4dcadbef 11213 return bgp_show_community_list (vty, NULL, argv[4]->arg, 1, AFI_IP6, SAFI_MULTICAST);
718e3744 11214}
11215#endif /* HAVE_IPV6 */
6b0655a2 11216
94f2b392 11217static int
50ef26d4 11218bgp_show_prefix_longer (struct vty *vty, const char *name,
11219 const char *prefix, afi_t afi,
718e3744 11220 safi_t safi, enum bgp_show_type type)
11221{
11222 int ret;
11223 struct prefix *p;
50ef26d4 11224 struct bgp *bgp = NULL;
11225
11226 if (name && !(bgp = bgp_lookup_by_name(name)))
11227 {
11228 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11229 return CMD_WARNING;
11230 }
718e3744 11231
11232 p = prefix_new();
11233
11234 ret = str2prefix (prefix, p);
11235 if (! ret)
11236 {
11237 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11238 return CMD_WARNING;
11239 }
11240
50ef26d4 11241 ret = bgp_show (vty, bgp, afi, safi, type, p, 0);
5a646650 11242 prefix_free(p);
11243 return ret;
718e3744 11244}
11245
11246DEFUN (show_ip_bgp_prefix_longer,
11247 show_ip_bgp_prefix_longer_cmd,
11248 "show ip bgp A.B.C.D/M longer-prefixes",
11249 SHOW_STR
11250 IP_STR
11251 BGP_STR
11252 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11253 "Display route and more specific routes\n")
11254{
4dcadbef 11255 return bgp_show_prefix_longer (vty, NULL, argv[3]->arg, AFI_IP, SAFI_UNICAST,
50ef26d4 11256 bgp_show_type_prefix_longer);
11257}
11258
8386ac43 11259DEFUN (show_ip_bgp_instance_prefix_longer,
11260 show_ip_bgp_instance_prefix_longer_cmd,
11261 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M longer-prefixes",
50ef26d4 11262 SHOW_STR
11263 IP_STR
11264 BGP_STR
8386ac43 11265 BGP_INSTANCE_HELP_STR
50ef26d4 11266 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11267 "Display route and more specific routes\n")
11268{
4dcadbef 11269 return bgp_show_prefix_longer (vty, argv[4]->arg, argv[5]->arg, AFI_IP, SAFI_UNICAST,
718e3744 11270 bgp_show_type_prefix_longer);
11271}
11272
f412b39a
DW
11273/*
11274 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
11275 * "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11276 * SHOW_STR
11277 * IP_STR
11278 * BGP_STR
11279 * "Display detailed information about dampening\n"
11280 * "Display flap statistics of routes\n"
11281 * "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11282 * "Display route and more specific routes\n"
11283 *
11284 */
718e3744 11285DEFUN (show_ip_bgp_flap_prefix_longer,
11286 show_ip_bgp_flap_prefix_longer_cmd,
11287 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11288 SHOW_STR
11289 IP_STR
11290 BGP_STR
11291 "Display flap statistics of routes\n"
11292 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11293 "Display route and more specific routes\n")
11294{
4dcadbef 11295 return bgp_show_prefix_longer (vty, NULL, argv[4]->arg, AFI_IP, SAFI_UNICAST,
718e3744 11296 bgp_show_type_flap_prefix_longer);
11297}
11298
81304aaf 11299
718e3744 11300DEFUN (show_ip_bgp_ipv4_prefix_longer,
11301 show_ip_bgp_ipv4_prefix_longer_cmd,
6147e2c6 11302 "show ip bgp ipv4 <unicast|multicast> A.B.C.D/M longer-prefixes",
718e3744 11303 SHOW_STR
11304 IP_STR
11305 BGP_STR
11306 "Address family\n"
11307 "Address Family modifier\n"
11308 "Address Family modifier\n"
11309 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11310 "Display route and more specific routes\n")
11311{
4dcadbef
DW
11312 if (strncmp (argv[4]->arg, "m", 1) == 0)
11313 return bgp_show_prefix_longer (vty, NULL, argv[5]->arg, AFI_IP, SAFI_MULTICAST,
718e3744 11314 bgp_show_type_prefix_longer);
11315
4dcadbef 11316 return bgp_show_prefix_longer (vty, NULL, argv[5]->arg, AFI_IP, SAFI_UNICAST,
718e3744 11317 bgp_show_type_prefix_longer);
11318}
11319
f412b39a
DW
11320/*
11321 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
11322 * "show ip bgp dampening flap-statistics A.B.C.D",
11323 * SHOW_STR
11324 * IP_STR
11325 * BGP_STR
11326 * "Display detailed information about dampening\n"
11327 * "Display flap statistics of routes\n"
11328 * "Network in the BGP routing table to display\n"
11329 *
11330 */
718e3744 11331DEFUN (show_ip_bgp_flap_address,
11332 show_ip_bgp_flap_address_cmd,
11333 "show ip bgp flap-statistics A.B.C.D",
11334 SHOW_STR
11335 IP_STR
11336 BGP_STR
11337 "Display flap statistics of routes\n"
11338 "Network in the BGP routing table to display\n")
11339{
4dcadbef 11340 return bgp_show_prefix_longer (vty, NULL, argv[4]->arg, AFI_IP, SAFI_UNICAST,
718e3744 11341 bgp_show_type_flap_address);
11342}
11343
81304aaf 11344
f412b39a
DW
11345/*
11346 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
11347 * "show ip bgp dampening flap-statistics A.B.C.D/M",
11348 * SHOW_STR
11349 * IP_STR
11350 * BGP_STR
11351 * "Display detailed information about dampening\n"
11352 * "Display flap statistics of routes\n"
11353 * "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11354 *
11355 */
718e3744 11356DEFUN (show_ip_bgp_flap_prefix,
11357 show_ip_bgp_flap_prefix_cmd,
11358 "show ip bgp flap-statistics A.B.C.D/M",
11359 SHOW_STR
11360 IP_STR
11361 BGP_STR
11362 "Display flap statistics of routes\n"
11363 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11364{
4dcadbef 11365 return bgp_show_prefix_longer (vty, NULL, argv[4]->arg, AFI_IP, SAFI_UNICAST,
718e3744 11366 bgp_show_type_flap_prefix);
11367}
81304aaf 11368
81304aaf 11369
718e3744 11370#ifdef HAVE_IPV6
f412b39a
DW
11371/*
11372 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
11373 * "show bgp ipv6 X:X::X:X/M longer-prefixes",
11374 * SHOW_STR
11375 * BGP_STR
11376 * "Address family\n"
11377 * "IPv6 prefix <network>/<length>\n"
11378 * "Display route and more specific routes\n"
11379 *
11380 */
718e3744 11381DEFUN (show_bgp_prefix_longer,
11382 show_bgp_prefix_longer_cmd,
11383 "show bgp X:X::X:X/M longer-prefixes",
11384 SHOW_STR
11385 BGP_STR
11386 "IPv6 prefix <network>/<length>\n"
11387 "Display route and more specific routes\n")
11388{
4dcadbef 11389 return bgp_show_prefix_longer (vty, NULL, argv[2]->arg, AFI_IP6, SAFI_UNICAST,
718e3744 11390 bgp_show_type_prefix_longer);
11391}
11392
718e3744 11393
11394/* old command */
11395DEFUN (show_ipv6_bgp_prefix_longer,
11396 show_ipv6_bgp_prefix_longer_cmd,
11397 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11398 SHOW_STR
11399 IPV6_STR
11400 BGP_STR
11401 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11402 "Display route and more specific routes\n")
11403{
47e9b292 11404 bgp_show_ipv6_bgp_deprecate_warning(vty);
4dcadbef 11405 return bgp_show_prefix_longer (vty, NULL, argv[3]->arg, AFI_IP6, SAFI_UNICAST,
718e3744 11406 bgp_show_type_prefix_longer);
11407}
11408
11409/* old command */
11410DEFUN (show_ipv6_mbgp_prefix_longer,
11411 show_ipv6_mbgp_prefix_longer_cmd,
11412 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11413 SHOW_STR
11414 IPV6_STR
11415 MBGP_STR
11416 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11417 "Display route and more specific routes\n")
11418{
47e9b292 11419 bgp_show_ipv6_bgp_deprecate_warning(vty);
4dcadbef 11420 return bgp_show_prefix_longer (vty, NULL, argv[3]->arg, AFI_IP6, SAFI_MULTICAST,
718e3744 11421 bgp_show_type_prefix_longer);
11422}
11423#endif /* HAVE_IPV6 */
bb46e94f 11424
94f2b392 11425static struct peer *
fd79ac91 11426peer_lookup_in_view (struct vty *vty, const char *view_name,
856ca177 11427 const char *ip_str, u_char use_json)
bb46e94f 11428{
11429 int ret;
11430 struct bgp *bgp;
11431 struct peer *peer;
11432 union sockunion su;
11433
11434 /* BGP structure lookup. */
11435 if (view_name)
11436 {
11437 bgp = bgp_lookup_by_name (view_name);
11438 if (! bgp)
11439 {
856ca177
MS
11440 if (use_json)
11441 {
11442 json_object *json_no = NULL;
11443 json_no = json_object_new_object();
11444 json_object_string_add(json_no, "warning", "Can't find BGP view");
11445 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11446 json_object_free(json_no);
11447 }
11448 else
6aeb9e78 11449 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
bb46e94f 11450 return NULL;
11451 }
11452 }
5228ad27 11453 else
bb46e94f 11454 {
11455 bgp = bgp_get_default ();
11456 if (! bgp)
11457 {
856ca177
MS
11458 if (use_json)
11459 {
11460 json_object *json_no = NULL;
11461 json_no = json_object_new_object();
11462 json_object_string_add(json_no, "warning", "No BGP process configured");
11463 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11464 json_object_free(json_no);
11465 }
11466 else
11467 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
bb46e94f 11468 return NULL;
11469 }
11470 }
11471
11472 /* Get peer sockunion. */
11473 ret = str2sockunion (ip_str, &su);
11474 if (ret < 0)
11475 {
a80beece
DS
11476 peer = peer_lookup_by_conf_if (bgp, ip_str);
11477 if (!peer)
11478 {
04b6bdc0
DW
11479 peer = peer_lookup_by_hostname(bgp, ip_str);
11480
11481 if (!peer)
856ca177 11482 {
04b6bdc0
DW
11483 if (use_json)
11484 {
11485 json_object *json_no = NULL;
11486 json_no = json_object_new_object();
11487 json_object_string_add(json_no, "malformedAddressOrName", ip_str);
11488 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11489 json_object_free(json_no);
11490 }
11491 else
11492 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
11493 return NULL;
856ca177 11494 }
a80beece
DS
11495 }
11496 return peer;
bb46e94f 11497 }
11498
11499 /* Peer structure lookup. */
11500 peer = peer_lookup (bgp, &su);
11501 if (! peer)
11502 {
856ca177
MS
11503 if (use_json)
11504 {
11505 json_object *json_no = NULL;
11506 json_no = json_object_new_object();
11507 json_object_string_add(json_no, "warning","No such neighbor");
11508 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11509 json_object_free(json_no);
11510 }
11511 else
11512 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
bb46e94f 11513 return NULL;
11514 }
11515
11516 return peer;
11517}
6b0655a2 11518
2815e61f
PJ
11519enum bgp_stats
11520{
11521 BGP_STATS_MAXBITLEN = 0,
11522 BGP_STATS_RIB,
11523 BGP_STATS_PREFIXES,
11524 BGP_STATS_TOTPLEN,
11525 BGP_STATS_UNAGGREGATEABLE,
11526 BGP_STATS_MAX_AGGREGATEABLE,
11527 BGP_STATS_AGGREGATES,
11528 BGP_STATS_SPACE,
11529 BGP_STATS_ASPATH_COUNT,
11530 BGP_STATS_ASPATH_MAXHOPS,
11531 BGP_STATS_ASPATH_TOTHOPS,
11532 BGP_STATS_ASPATH_MAXSIZE,
11533 BGP_STATS_ASPATH_TOTSIZE,
11534 BGP_STATS_ASN_HIGHEST,
11535 BGP_STATS_MAX,
11536};
11537
11538static const char *table_stats_strs[] =
11539{
11540 [BGP_STATS_PREFIXES] = "Total Prefixes",
11541 [BGP_STATS_TOTPLEN] = "Average prefix length",
11542 [BGP_STATS_RIB] = "Total Advertisements",
11543 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11544 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11545 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11546 [BGP_STATS_SPACE] = "Address space advertised",
11547 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11548 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11549 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11550 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11551 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11552 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11553 [BGP_STATS_MAX] = NULL,
11554};
11555
11556struct bgp_table_stats
11557{
11558 struct bgp_table *table;
11559 unsigned long long counts[BGP_STATS_MAX];
11560};
11561
11562#if 0
11563#define TALLY_SIGFIG 100000
11564static unsigned long
11565ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11566{
11567 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11568 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11569 unsigned long ret = newtot / count;
11570
11571 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11572 return ret + 1;
11573 else
11574 return ret;
11575}
11576#endif
11577
11578static int
11579bgp_table_stats_walker (struct thread *t)
11580{
11581 struct bgp_node *rn;
11582 struct bgp_node *top;
11583 struct bgp_table_stats *ts = THREAD_ARG (t);
11584 unsigned int space = 0;
11585
53d9f67a
PJ
11586 if (!(top = bgp_table_top (ts->table)))
11587 return 0;
2815e61f
PJ
11588
11589 switch (top->p.family)
11590 {
11591 case AF_INET:
11592 space = IPV4_MAX_BITLEN;
11593 break;
11594 case AF_INET6:
11595 space = IPV6_MAX_BITLEN;
11596 break;
11597 }
11598
11599 ts->counts[BGP_STATS_MAXBITLEN] = space;
11600
11601 for (rn = top; rn; rn = bgp_route_next (rn))
11602 {
11603 struct bgp_info *ri;
67174041 11604 struct bgp_node *prn = bgp_node_parent_nolock (rn);
2815e61f
PJ
11605 unsigned int rinum = 0;
11606
11607 if (rn == top)
11608 continue;
11609
11610 if (!rn->info)
11611 continue;
11612
11613 ts->counts[BGP_STATS_PREFIXES]++;
11614 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11615
11616#if 0
11617 ts->counts[BGP_STATS_AVGPLEN]
11618 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11619 ts->counts[BGP_STATS_AVGPLEN],
11620 rn->p.prefixlen);
11621#endif
11622
11623 /* check if the prefix is included by any other announcements */
11624 while (prn && !prn->info)
67174041 11625 prn = bgp_node_parent_nolock (prn);
2815e61f
PJ
11626
11627 if (prn == NULL || prn == top)
8383a9bd
PJ
11628 {
11629 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11630 /* announced address space */
11631 if (space)
11632 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11633 }
2815e61f
PJ
11634 else if (prn->info)
11635 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11636
2815e61f
PJ
11637 for (ri = rn->info; ri; ri = ri->next)
11638 {
11639 rinum++;
11640 ts->counts[BGP_STATS_RIB]++;
11641
11642 if (ri->attr &&
11643 (CHECK_FLAG (ri->attr->flag,
11644 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11645 ts->counts[BGP_STATS_AGGREGATES]++;
11646
11647 /* as-path stats */
11648 if (ri->attr && ri->attr->aspath)
11649 {
11650 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11651 unsigned int size = aspath_size (ri->attr->aspath);
11652 as_t highest = aspath_highest (ri->attr->aspath);
11653
11654 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11655
11656 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11657 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11658
11659 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11660 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11661
11662 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11663 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11664#if 0
11665 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11666 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11667 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11668 hops);
11669 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11670 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11671 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11672 size);
11673#endif
11674 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11675 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11676 }
11677 }
11678 }
11679 return 0;
11680}
11681
11682static int
11683bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11684{
11685 struct bgp_table_stats ts;
11686 unsigned int i;
11687
11688 if (!bgp->rib[afi][safi])
11689 {
06da0daf
DS
11690 vty_out (vty, "%% No RIB exist's for the AFI(%d)/SAFI(%d)%s",
11691 afi, safi, VTY_NEWLINE);
2815e61f
PJ
11692 return CMD_WARNING;
11693 }
11694
11695 memset (&ts, 0, sizeof (ts));
11696 ts.table = bgp->rib[afi][safi];
87d4a781 11697 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
bb46e94f 11698
2815e61f
PJ
11699 vty_out (vty, "BGP %s RIB statistics%s%s",
11700 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11701
11702 for (i = 0; i < BGP_STATS_MAX; i++)
11703 {
11704 if (!table_stats_strs[i])
11705 continue;
11706
11707 switch (i)
11708 {
11709#if 0
11710 case BGP_STATS_ASPATH_AVGHOPS:
11711 case BGP_STATS_ASPATH_AVGSIZE:
11712 case BGP_STATS_AVGPLEN:
11713 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11714 vty_out (vty, "%12.2f",
11715 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11716 break;
11717#endif
11718 case BGP_STATS_ASPATH_TOTHOPS:
11719 case BGP_STATS_ASPATH_TOTSIZE:
11720 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11721 vty_out (vty, "%12.2f",
11722 ts.counts[i] ?
11723 (float)ts.counts[i] /
11724 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11725 : 0);
11726 break;
11727 case BGP_STATS_TOTPLEN:
11728 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11729 vty_out (vty, "%12.2f",
11730 ts.counts[i] ?
11731 (float)ts.counts[i] /
11732 (float)ts.counts[BGP_STATS_PREFIXES]
11733 : 0);
11734 break;
11735 case BGP_STATS_SPACE:
11736 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11737 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11738 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11739 break;
30a2231a 11740 vty_out (vty, "%30s: ", "%% announced ");
2815e61f
PJ
11741 vty_out (vty, "%12.2f%s",
11742 100 * (float)ts.counts[BGP_STATS_SPACE] /
56395af7 11743 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
2815e61f
PJ
11744 VTY_NEWLINE);
11745 vty_out (vty, "%30s: ", "/8 equivalent ");
11746 vty_out (vty, "%12.2f%s",
11747 (float)ts.counts[BGP_STATS_SPACE] /
11748 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11749 VTY_NEWLINE);
11750 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11751 break;
11752 vty_out (vty, "%30s: ", "/24 equivalent ");
11753 vty_out (vty, "%12.2f",
11754 (float)ts.counts[BGP_STATS_SPACE] /
11755 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11756 break;
11757 default:
11758 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11759 vty_out (vty, "%12llu", ts.counts[i]);
11760 }
11761
11762 vty_out (vty, "%s", VTY_NEWLINE);
11763 }
11764 return CMD_SUCCESS;
11765}
11766
11767static int
11768bgp_table_stats_vty (struct vty *vty, const char *name,
11769 const char *afi_str, const char *safi_str)
11770{
11771 struct bgp *bgp;
11772 afi_t afi;
11773 safi_t safi;
11774
11775 if (name)
11776 bgp = bgp_lookup_by_name (name);
11777 else
11778 bgp = bgp_get_default ();
11779
11780 if (!bgp)
11781 {
11782 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
11783 return CMD_WARNING;
11784 }
11785 if (strncmp (afi_str, "ipv", 3) == 0)
11786 {
11787 if (strncmp (afi_str, "ipv4", 4) == 0)
11788 afi = AFI_IP;
11789 else if (strncmp (afi_str, "ipv6", 4) == 0)
11790 afi = AFI_IP6;
11791 else
11792 {
11793 vty_out (vty, "%% Invalid address family %s%s",
11794 afi_str, VTY_NEWLINE);
11795 return CMD_WARNING;
11796 }
11797 if (strncmp (safi_str, "m", 1) == 0)
11798 safi = SAFI_MULTICAST;
11799 else if (strncmp (safi_str, "u", 1) == 0)
11800 safi = SAFI_UNICAST;
587ff0fd
LB
11801 else if (strncmp (safi_str, "e", 1) == 0)
11802 safi = SAFI_ENCAP;
42e6d745 11803 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
06da0daf 11804 safi = SAFI_MPLS_VPN;
2815e61f
PJ
11805 else
11806 {
11807 vty_out (vty, "%% Invalid subsequent address family %s%s",
11808 safi_str, VTY_NEWLINE);
587ff0fd
LB
11809 return CMD_WARNING;
11810 }
2815e61f
PJ
11811 }
11812 else
11813 {
587ff0fd 11814 vty_out (vty, "%% Invalid address family \"%s\"%s",
2815e61f
PJ
11815 afi_str, VTY_NEWLINE);
11816 return CMD_WARNING;
11817 }
11818
2815e61f
PJ
11819 return bgp_table_stats (vty, bgp, afi, safi);
11820}
11821
11822DEFUN (show_bgp_statistics,
11823 show_bgp_statistics_cmd,
6147e2c6 11824 "show bgp <ipv4|ipv6> <encap|multicast|unicast|vpn> statistics",
2815e61f
PJ
11825 SHOW_STR
11826 BGP_STR
11827 "Address family\n"
11828 "Address family\n"
11829 "Address Family modifier\n"
11830 "Address Family modifier\n"
587ff0fd
LB
11831 "Address Family modifier\n"
11832 "Address Family modifier\n"
2815e61f
PJ
11833 "BGP RIB advertisement statistics\n")
11834{
4dcadbef 11835 return bgp_table_stats_vty (vty, NULL, argv[2]->arg, argv[3]->arg);
2815e61f
PJ
11836}
11837
2815e61f
PJ
11838DEFUN (show_bgp_statistics_view,
11839 show_bgp_statistics_view_cmd,
6147e2c6 11840 "show bgp " BGP_INSTANCE_CMD " <ipv4|ipv6> <unicast|multicast|vpn|encap> statistics",
2815e61f
PJ
11841 SHOW_STR
11842 BGP_STR
8386ac43 11843 BGP_INSTANCE_HELP_STR
2815e61f
PJ
11844 "Address family\n"
11845 "Address family\n"
11846 "Address Family modifier\n"
11847 "Address Family modifier\n"
587ff0fd
LB
11848 "Address Family modifier\n"
11849 "Address Family modifier\n"
2815e61f
PJ
11850 "BGP RIB advertisement statistics\n")
11851{
4dcadbef 11852 return bgp_table_stats_vty (vty, NULL, argv[3]->arg, argv[4]->arg);
2815e61f
PJ
11853}
11854
ff7924f6
PJ
11855enum bgp_pcounts
11856{
11857 PCOUNT_ADJ_IN = 0,
11858 PCOUNT_DAMPED,
11859 PCOUNT_REMOVED,
11860 PCOUNT_HISTORY,
11861 PCOUNT_STALE,
11862 PCOUNT_VALID,
11863 PCOUNT_ALL,
11864 PCOUNT_COUNTED,
11865 PCOUNT_PFCNT, /* the figure we display to users */
11866 PCOUNT_MAX,
11867};
11868
11869static const char *pcount_strs[] =
11870{
11871 [PCOUNT_ADJ_IN] = "Adj-in",
11872 [PCOUNT_DAMPED] = "Damped",
11873 [PCOUNT_REMOVED] = "Removed",
11874 [PCOUNT_HISTORY] = "History",
11875 [PCOUNT_STALE] = "Stale",
11876 [PCOUNT_VALID] = "Valid",
11877 [PCOUNT_ALL] = "All RIB",
11878 [PCOUNT_COUNTED] = "PfxCt counted",
11879 [PCOUNT_PFCNT] = "Useable",
11880 [PCOUNT_MAX] = NULL,
11881};
11882
2815e61f
PJ
11883struct peer_pcounts
11884{
11885 unsigned int count[PCOUNT_MAX];
11886 const struct peer *peer;
11887 const struct bgp_table *table;
11888};
11889
ff7924f6 11890static int
2815e61f 11891bgp_peer_count_walker (struct thread *t)
ff7924f6
PJ
11892{
11893 struct bgp_node *rn;
2815e61f
PJ
11894 struct peer_pcounts *pc = THREAD_ARG (t);
11895 const struct peer *peer = pc->peer;
ff7924f6 11896
2815e61f 11897 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
ff7924f6
PJ
11898 {
11899 struct bgp_adj_in *ain;
2815e61f 11900 struct bgp_info *ri;
ff7924f6
PJ
11901
11902 for (ain = rn->adj_in; ain; ain = ain->next)
11903 if (ain->peer == peer)
2815e61f 11904 pc->count[PCOUNT_ADJ_IN]++;
ff7924f6 11905
ff7924f6
PJ
11906 for (ri = rn->info; ri; ri = ri->next)
11907 {
11908 char buf[SU_ADDRSTRLEN];
11909
11910 if (ri->peer != peer)
11911 continue;
11912
2815e61f 11913 pc->count[PCOUNT_ALL]++;
ff7924f6
PJ
11914
11915 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
2815e61f 11916 pc->count[PCOUNT_DAMPED]++;
ff7924f6 11917 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2815e61f 11918 pc->count[PCOUNT_HISTORY]++;
ff7924f6 11919 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
2815e61f 11920 pc->count[PCOUNT_REMOVED]++;
ff7924f6 11921 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2815e61f 11922 pc->count[PCOUNT_STALE]++;
ff7924f6 11923 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
2815e61f 11924 pc->count[PCOUNT_VALID]++;
1a392d46 11925 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2815e61f 11926 pc->count[PCOUNT_PFCNT]++;
ff7924f6
PJ
11927
11928 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
11929 {
2815e61f 11930 pc->count[PCOUNT_COUNTED]++;
1a392d46 11931 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 11932 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
ff7924f6
PJ
11933 peer->host,
11934 inet_ntop(rn->p.family, &rn->p.u.prefix,
11935 buf, SU_ADDRSTRLEN),
11936 rn->p.prefixlen,
11937 ri->flags);
11938 }
11939 else
11940 {
1a392d46 11941 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 11942 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
ff7924f6
PJ
11943 peer->host,
11944 inet_ntop(rn->p.family, &rn->p.u.prefix,
11945 buf, SU_ADDRSTRLEN),
11946 rn->p.prefixlen,
11947 ri->flags);
11948 }
11949 }
11950 }
2815e61f
PJ
11951 return 0;
11952}
ff7924f6 11953
2815e61f 11954static int
856ca177 11955bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json)
2815e61f
PJ
11956{
11957 struct peer_pcounts pcounts = { .peer = peer };
11958 unsigned int i;
856ca177
MS
11959 json_object *json = NULL;
11960 json_object *json_loop = NULL;
11961
11962 if (use_json)
11963 {
11964 json = json_object_new_object();
11965 json_loop = json_object_new_object();
11966 }
2815e61f
PJ
11967
11968 if (!peer || !peer->bgp || !peer->afc[afi][safi]
11969 || !peer->bgp->rib[afi][safi])
11970 {
856ca177
MS
11971 if (use_json)
11972 {
11973 json_object_string_add(json, "warning", "No such neighbor or address family");
11974 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11975 json_object_free(json);
11976 }
11977 else
11978 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11979
2815e61f
PJ
11980 return CMD_WARNING;
11981 }
11982
11983 memset (&pcounts, 0, sizeof(pcounts));
11984 pcounts.peer = peer;
11985 pcounts.table = peer->bgp->rib[afi][safi];
11986
11987 /* in-place call via thread subsystem so as to record execution time
856ca177
MS
11988 * * stats for the thread-walk (i.e. ensure this can't be blamed on
11989 * * on just vty_read()).
11990 * */
87d4a781 11991 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
6410e93a 11992
856ca177
MS
11993 if (use_json)
11994 {
11995 json_object_string_add(json, "prefixCountsFor", peer->host);
11996 json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi));
11997 json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]);
11998
11999 for (i = 0; i < PCOUNT_MAX; i++)
12000 json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]);
ff7924f6 12001
856ca177 12002 json_object_object_add(json, "ribTableWalkCounters", json_loop);
ff7924f6 12003
856ca177
MS
12004 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
12005 {
12006 json_object_string_add(json, "pfxctDriftFor", peer->host);
12007 json_object_string_add(json, "recommended", "Please report this bug, with the above command output");
12008 }
12009 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12010 json_object_free(json);
12011 }
12012 else
ff7924f6 12013 {
04b6bdc0
DW
12014
12015 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
12016 {
12017 vty_out (vty, "Prefix counts for %s/%s, %s%s",
12018 peer->hostname, peer->host, afi_safi_print (afi, safi),
12019 VTY_NEWLINE);
12020 }
12021 else
12022 {
12023 vty_out (vty, "Prefix counts for %s, %s%s",
12024 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
12025 }
12026
856ca177
MS
12027 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
12028 vty_out (vty, "%sCounts from RIB table walk:%s%s",
12029 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12030
12031 for (i = 0; i < PCOUNT_MAX; i++)
12032 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
12033
12034 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
12035 {
12036 vty_out (vty, "%s [pcount] PfxCt drift!%s",
12037 peer->host, VTY_NEWLINE);
12038 vty_out (vty, "Please report this bug, with the above command output%s",
12039 VTY_NEWLINE);
12040 }
ff7924f6
PJ
12041 }
12042
12043 return CMD_SUCCESS;
12044}
12045
12046DEFUN (show_ip_bgp_neighbor_prefix_counts,
12047 show_ip_bgp_neighbor_prefix_counts_cmd,
6147e2c6 12048 "show ip bgp neighbors <A.B.C.D|X:X::X:X|WORD> prefix-counts [json]",
ff7924f6
PJ
12049 SHOW_STR
12050 IP_STR
12051 BGP_STR
12052 "Detailed information on TCP and BGP neighbor connections\n"
12053 "Neighbor to display information about\n"
12054 "Neighbor to display information about\n"
a80beece 12055 "Neighbor on bgp configured interface\n"
856ca177
MS
12056 "Display detailed prefix count information\n"
12057 "JavaScript Object Notation\n")
ff7924f6
PJ
12058{
12059 struct peer *peer;
db7c8528 12060 u_char uj = use_json(argc, argv);
ff7924f6 12061
4dcadbef 12062 peer = peer_lookup_in_view (vty, NULL, argv[4]->arg, uj);
ff7924f6
PJ
12063 if (! peer)
12064 return CMD_WARNING;
12065
db7c8528 12066 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
ff7924f6
PJ
12067}
12068
8386ac43 12069DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
12070 show_ip_bgp_instance_neighbor_prefix_counts_cmd,
6147e2c6 12071 "show ip bgp " BGP_INSTANCE_CMD " neighbors <A.B.C.D|X:X::X:X|WORD> prefix-counts [json]",
50ef26d4 12072 SHOW_STR
12073 IP_STR
12074 BGP_STR
8386ac43 12075 BGP_INSTANCE_HELP_STR
50ef26d4 12076 "Detailed information on TCP and BGP neighbor connections\n"
12077 "Neighbor to display information about\n"
12078 "Neighbor to display information about\n"
12079 "Neighbor on bgp configured interface\n"
12080 "Display detailed prefix count information\n"
12081 "JavaScript Object Notation\n")
12082{
12083 struct peer *peer;
12084 u_char uj = use_json(argc, argv);
12085
4dcadbef 12086 peer = peer_lookup_in_view (vty, argv[4]->arg, argv[6]->arg, uj);
50ef26d4 12087 if (! peer)
12088 return CMD_WARNING;
12089
12090 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
12091}
12092
ff7924f6
PJ
12093DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12094 show_bgp_ipv6_neighbor_prefix_counts_cmd,
6147e2c6 12095 "show bgp ipv6 neighbors <A.B.C.D|X:X::X:X|WORD> prefix-counts [json]",
ff7924f6
PJ
12096 SHOW_STR
12097 BGP_STR
12098 "Address family\n"
12099 "Detailed information on TCP and BGP neighbor connections\n"
12100 "Neighbor to display information about\n"
12101 "Neighbor to display information about\n"
a80beece 12102 "Neighbor on bgp configured interface\n"
856ca177
MS
12103 "Display detailed prefix count information\n"
12104 "JavaScript Object Notation\n")
ff7924f6
PJ
12105{
12106 struct peer *peer;
db7c8528 12107 u_char uj = use_json(argc, argv);
856ca177 12108
4dcadbef 12109 peer = peer_lookup_in_view (vty, NULL, argv[4]->arg, uj);
ff7924f6
PJ
12110 if (! peer)
12111 return CMD_WARNING;
12112
db7c8528 12113 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
ff7924f6
PJ
12114}
12115
8386ac43 12116DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts,
12117 show_bgp_instance_ipv6_neighbor_prefix_counts_cmd,
6147e2c6 12118 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors <A.B.C.D|X:X::X:X|WORD> prefix-counts [json]",
50ef26d4 12119 SHOW_STR
12120 BGP_STR
8386ac43 12121 BGP_INSTANCE_HELP_STR
50ef26d4 12122 "Address family\n"
12123 "Detailed information on TCP and BGP neighbor connections\n"
12124 "Neighbor to display information about\n"
12125 "Neighbor to display information about\n"
12126 "Neighbor on bgp configured interface\n"
12127 "Display detailed prefix count information\n"
12128 "JavaScript Object Notation\n")
12129{
12130 struct peer *peer;
12131 u_char uj = use_json(argc, argv);
12132
4dcadbef 12133 peer = peer_lookup_in_view (vty, argv[3]->arg, argv[6]->arg, uj);
50ef26d4 12134 if (! peer)
12135 return CMD_WARNING;
12136
12137 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
12138}
12139
ff7924f6
PJ
12140DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12141 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
6147e2c6 12142 "show ip bgp ipv4 <unicast|multicast> neighbors <A.B.C.D|X:X::X:X|WORD> prefix-counts [json]",
ff7924f6
PJ
12143 SHOW_STR
12144 IP_STR
12145 BGP_STR
12146 "Address family\n"
12147 "Address Family modifier\n"
12148 "Address Family modifier\n"
12149 "Detailed information on TCP and BGP neighbor connections\n"
12150 "Neighbor to display information about\n"
12151 "Neighbor to display information about\n"
a80beece 12152 "Neighbor on bgp configured interface\n"
856ca177
MS
12153 "Display detailed prefix count information\n"
12154 "JavaScript Object Notation\n")
ff7924f6
PJ
12155{
12156 struct peer *peer;
db7c8528 12157 u_char uj = use_json(argc, argv);
ff7924f6 12158
4dcadbef 12159 peer = peer_lookup_in_view (vty, NULL, argv[6]->arg, uj);
ff7924f6
PJ
12160 if (! peer)
12161 return CMD_WARNING;
12162
4dcadbef 12163 if (strncmp (argv[4]->arg, "m", 1) == 0)
db7c8528 12164 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST, uj);
ff7924f6 12165
db7c8528 12166 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
ff7924f6
PJ
12167}
12168
12169DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
12170 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
6147e2c6 12171 "show ip bgp vpnv4 all neighbors <A.B.C.D|X:X::X:X|WORD> prefix-counts [json]",
ff7924f6
PJ
12172 SHOW_STR
12173 IP_STR
12174 BGP_STR
12175 "Address family\n"
12176 "Address Family modifier\n"
12177 "Address Family modifier\n"
12178 "Detailed information on TCP and BGP neighbor connections\n"
12179 "Neighbor to display information about\n"
12180 "Neighbor to display information about\n"
a80beece 12181 "Neighbor on bgp configured interface\n"
856ca177
MS
12182 "Display detailed prefix count information\n"
12183 "JavaScript Object Notation\n")
ff7924f6
PJ
12184{
12185 struct peer *peer;
db7c8528 12186 u_char uj = use_json(argc, argv);
856ca177 12187
4dcadbef 12188 peer = peer_lookup_in_view (vty, NULL, argv[6]->arg, uj);
ff7924f6
PJ
12189 if (! peer)
12190 return CMD_WARNING;
12191
db7c8528 12192 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN, uj);
ff7924f6
PJ
12193}
12194
94f2b392 12195static void
718e3744 12196show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
856ca177 12197 int in, const char *rmap_name, u_char use_json, json_object *json)
718e3744 12198{
12199 struct bgp_table *table;
12200 struct bgp_adj_in *ain;
12201 struct bgp_adj_out *adj;
12202 unsigned long output_count;
0b16f239 12203 unsigned long filtered_count;
718e3744 12204 struct bgp_node *rn;
12205 int header1 = 1;
12206 struct bgp *bgp;
12207 int header2 = 1;
0b16f239
DS
12208 struct attr attr;
12209 struct attr_extra extra;
12210 int ret;
840fced9 12211 struct update_subgroup *subgrp;
856ca177
MS
12212 json_object *json_scode = NULL;
12213 json_object *json_ocode = NULL;
12214 json_object *json_ar = NULL;
adbac85e 12215 struct peer_af *paf;
856ca177
MS
12216
12217 if (use_json)
12218 {
12219 json_scode = json_object_new_object();
12220 json_ocode = json_object_new_object();
12221 json_ar = json_object_new_object();
12222
12223 json_object_string_add(json_scode, "suppressed", "s");
12224 json_object_string_add(json_scode, "damped", "d");
12225 json_object_string_add(json_scode, "history", "h");
12226 json_object_string_add(json_scode, "valid", "*");
12227 json_object_string_add(json_scode, "best", ">");
12228 json_object_string_add(json_scode, "multipath", "=");
12229 json_object_string_add(json_scode, "internal", "i");
12230 json_object_string_add(json_scode, "ribFailure", "r");
12231 json_object_string_add(json_scode, "stale", "S");
12232 json_object_string_add(json_scode, "removed", "R");
12233
12234 json_object_string_add(json_ocode, "igp", "i");
12235 json_object_string_add(json_ocode, "egp", "e");
12236 json_object_string_add(json_ocode, "incomplete", "?");
12237 }
718e3744 12238
bb46e94f 12239 bgp = peer->bgp;
718e3744 12240
12241 if (! bgp)
856ca177
MS
12242 {
12243 if (use_json)
12244 {
12245 json_object_string_add(json, "alert", "no BGP");
12246 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12247 json_object_free(json);
12248 }
12249 else
12250 vty_out (vty, "%% No bgp%s", VTY_NEWLINE);
12251 return;
12252 }
718e3744 12253
12254 table = bgp->rib[afi][safi];
12255
0b16f239 12256 output_count = filtered_count = 0;
840fced9 12257 subgrp = peer_subgroup(peer, afi, safi);
47fc97cc 12258
840fced9 12259 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
718e3744 12260 {
856ca177
MS
12261 if (use_json)
12262 {
12263 json_object_int_add(json, "bgpTableVersion", table->version);
12264 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12265 json_object_object_add(json, "bgpStatusCodes", json_scode);
12266 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12267 json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0");
12268 }
12269 else
12270 {
12271 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
12272 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12273 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 12274
856ca177
MS
12275 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12276 VTY_NEWLINE, VTY_NEWLINE);
12277 }
718e3744 12278 header1 = 0;
12279 }
12280
0b16f239 12281 attr.extra = &extra;
718e3744 12282 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
856ca177
MS
12283 {
12284 if (in)
12285 {
12286 for (ain = rn->adj_in; ain; ain = ain->next)
12287 {
12288 if (ain->peer == peer)
12289 {
12290 if (header1)
12291 {
12292 if (use_json)
12293 {
12294 json_object_int_add(json, "bgpTableVersion", 0);
12295 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12296 json_object_object_add(json, "bgpStatusCodes", json_scode);
12297 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12298 }
12299 else
12300 {
12301 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
12302 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12303 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12304 }
12305 header1 = 0;
12306 }
12307 if (header2)
12308 {
12309 if (!use_json)
12310 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12311 header2 = 0;
12312 }
12313 if (ain->attr)
12314 {
12315 bgp_attr_dup(&attr, ain->attr);
12316 if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY)
12317 {
12318 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12319 output_count++;
12320 }
12321 else
12322 filtered_count++;
12323 }
12324 }
12325 }
12326 }
12327 else
12328 {
adbac85e
DW
12329 for (adj = rn->adj_out; adj; adj = adj->next)
12330 SUBGRP_FOREACH_PEER(adj->subgroup, paf)
12331 if (paf->peer == peer)
856ca177 12332 {
adbac85e 12333 if (header1)
856ca177 12334 {
adbac85e
DW
12335 if (use_json)
12336 {
12337 json_object_int_add(json, "bgpTableVersion", table->version);
12338 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12339 json_object_object_add(json, "bgpStatusCodes", json_scode);
12340 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12341 }
12342 else
12343 {
12344 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version,
12345 inet_ntoa (bgp->router_id), VTY_NEWLINE);
12346 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12347 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12348 }
12349 header1 = 0;
856ca177 12350 }
adbac85e
DW
12351
12352 if (header2)
856ca177 12353 {
adbac85e
DW
12354 if (!use_json)
12355 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12356 header2 = 0;
856ca177 12357 }
adbac85e
DW
12358
12359 if (adj->attr)
856ca177 12360 {
adbac85e
DW
12361 bgp_attr_dup(&attr, adj->attr);
12362 ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name);
12363 if (ret != RMAP_DENY)
12364 {
12365 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12366 output_count++;
12367 }
12368 else
12369 filtered_count++;
856ca177 12370 }
856ca177 12371 }
856ca177
MS
12372 }
12373 }
12374 if (use_json)
12375 json_object_object_add(json, "advertisedRoutes", json_ar);
47fc97cc 12376
718e3744 12377 if (output_count != 0)
856ca177
MS
12378 {
12379 if (use_json)
12380 json_object_int_add(json, "totalPrefixCounter", output_count);
12381 else
12382 vty_out (vty, "%sTotal number of prefixes %ld%s",
12383 VTY_NEWLINE, output_count, VTY_NEWLINE);
12384 }
12385 if (use_json)
12386 {
12387 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12388 json_object_free(json);
12389 }
12390
718e3744 12391}
12392
94f2b392 12393static int
47fc97cc 12394peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
856ca177
MS
12395 int in, const char *rmap_name, u_char use_json)
12396{
12397 json_object *json = NULL;
12398
12399 if (use_json)
12400 json = json_object_new_object();
12401
12402 if (!peer || !peer->afc[afi][safi])
718e3744 12403 {
856ca177
MS
12404 if (use_json)
12405 {
12406 json_object_string_add(json, "warning", "No such neighbor or address family");
12407 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12408 json_object_free(json);
12409 }
12410 else
12411 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12412
718e3744 12413 return CMD_WARNING;
12414 }
12415
856ca177 12416 if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
718e3744 12417 {
856ca177
MS
12418 if (use_json)
12419 {
12420 json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
12421 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12422 json_object_free(json);
12423 }
12424 else
12425 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE);
12426
718e3744 12427 return CMD_WARNING;
12428 }
12429
856ca177 12430 show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json);
718e3744 12431
12432 return CMD_SUCCESS;
12433}
12434
f412b39a
DW
12435/*
12436 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 12437 * "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD [json]",
f412b39a
DW
12438 * SHOW_STR
12439 * IP_STR
12440 * BGP_STR
12441 * BGP_INSTANCE_HELP_STR
12442 * "Detailed information on TCP and BGP neighbor connections\n"
12443 * "Neighbor to display information about\n"
12444 * "Neighbor to display information about\n"
12445 * "Neighbor on bgp configured interface\n"
12446 * "Display the routes advertised to a BGP neighbor\n"
12447 * "JavaScript Object Notation\n"
12448 *
12449 */
8386ac43 12450DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
12451 show_ip_bgp_instance_neighbor_advertised_route_cmd,
6147e2c6 12452 "show ip bgp " BGP_INSTANCE_CMD " neighbors <A.B.C.D|X:X::X:X|WORD> advertised-routes [json]",
718e3744 12453 SHOW_STR
12454 IP_STR
12455 BGP_STR
8386ac43 12456 BGP_INSTANCE_HELP_STR
718e3744 12457 "Detailed information on TCP and BGP neighbor connections\n"
12458 "Neighbor to display information about\n"
12459 "Neighbor to display information about\n"
856ca177
MS
12460 "Display the routes advertised to a BGP neighbor\n"
12461 "JavaScript Object Notation\n")
718e3744 12462{
bb46e94f 12463 struct peer *peer;
db7c8528 12464 u_char uj = use_json(argc, argv);
856ca177 12465
4dcadbef
DW
12466 if (argc == 4 || (argc == 3 && argv[6]->arg && strcmp(argv[6]->arg, "json") != 0))
12467 peer = peer_lookup_in_view (vty, argv[4]->arg, argv[6]->arg, uj);
2a71e9ce 12468 else
4dcadbef 12469 peer = peer_lookup_in_view (vty, NULL, argv[4]->arg, uj);
2a71e9ce 12470
bb46e94f 12471 if (! peer)
12472 return CMD_WARNING;
0b16f239 12473
db7c8528 12474 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj);
718e3744 12475}
12476
f412b39a
DW
12477/*
12478 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 12479 * "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD [json]",
f412b39a
DW
12480 * SHOW_STR
12481 * IP_STR
12482 * BGP_STR
12483 * "Detailed information on TCP and BGP neighbor connections\n"
12484 * "Neighbor to display information about\n"
12485 * "Neighbor to display information about\n"
12486 * "Neighbor on bgp configured interface\n"
12487 * "Display the routes advertised to a BGP neighbor\n"
12488 * "JavaScript Object Notation\n"
12489 *
12490 */
0b16f239 12491DEFUN (show_ip_bgp_neighbor_advertised_route,
2a71e9ce 12492 show_ip_bgp_neighbor_advertised_route_cmd,
6147e2c6 12493 "show ip bgp neighbors <A.B.C.D|X:X::X:X|WORD> advertised-routes [json]",
2a71e9ce
TP
12494 SHOW_STR
12495 IP_STR
12496 BGP_STR
12497 "Detailed information on TCP and BGP neighbor connections\n"
12498 "Neighbor to display information about\n"
12499 "Neighbor to display information about\n"
a80beece 12500 "Neighbor on bgp configured interface\n"
856ca177
MS
12501 "Display the routes advertised to a BGP neighbor\n"
12502 "JavaScript Object Notation\n")
2a71e9ce 12503
0b16f239
DS
12504{
12505 struct peer *peer;
ffd0c037 12506 const char *rmap_name = NULL;
db7c8528 12507 u_char uj = use_json(argc, argv);
0b16f239 12508
4dcadbef 12509 peer = peer_lookup_in_view (vty, NULL, argv[4]->arg, uj);
0b16f239
DS
12510
12511 if (! peer)
12512 return CMD_WARNING;
12513
4dcadbef 12514 if ((argc == 2 && argv[6]->arg && strcmp(argv[6]->arg, "json") != 0)
856ca177 12515 || (argc == 3))
4dcadbef 12516 rmap_name = argv[6]->arg;
0b16f239 12517
db7c8528 12518 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
0b16f239
DS
12519}
12520
0b16f239 12521
f412b39a
DW
12522/*
12523 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 12524 * "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD [json]",
f412b39a
DW
12525 * SHOW_STR
12526 * IP_STR
12527 * BGP_STR
12528 * "Address family\n"
12529 * "Address Family modifier\n"
12530 * "Address Family modifier\n"
12531 * "Detailed information on TCP and BGP neighbor connections\n"
12532 * "Neighbor to display information about\n"
12533 * "Neighbor to display information about\n"
12534 * "Neighbor on bgp configured interface\n"
12535 * "Display the routes advertised to a BGP neighbor\n"
12536 * "Route-map to control what is displayed\n"
12537 * "JavaScript Object Notation\n"
12538 *
12539 */
718e3744 12540DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12541 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
6147e2c6 12542 "show ip bgp ipv4 <unicast|multicast> neighbors <A.B.C.D|X:X::X:X|WORD> advertised-routes [json]",
718e3744 12543 SHOW_STR
12544 IP_STR
12545 BGP_STR
12546 "Address family\n"
12547 "Address Family modifier\n"
12548 "Address Family modifier\n"
12549 "Detailed information on TCP and BGP neighbor connections\n"
12550 "Neighbor to display information about\n"
12551 "Neighbor to display information about\n"
a80beece 12552 "Neighbor on bgp configured interface\n"
856ca177
MS
12553 "Display the routes advertised to a BGP neighbor\n"
12554 "JavaScript Object Notation\n")
718e3744 12555{
bb46e94f 12556 struct peer *peer;
ffd0c037 12557 const char *rmap_name = NULL;
db7c8528 12558 u_char uj = use_json(argc, argv);
856ca177 12559
4dcadbef 12560 peer = peer_lookup_in_view (vty, NULL, argv[6]->arg, uj);
bb46e94f 12561 if (! peer)
12562 return CMD_WARNING;
12563
4dcadbef
DW
12564 if ((argc == 4) || (argc == 3 && argv[8]->arg && strcmp(argv[8]->arg, "json") != 0))
12565 rmap_name = argv[8]->arg;
0b16f239 12566
4dcadbef 12567 if (strncmp (argv[4]->arg, "m", 1) == 0)
db7c8528 12568 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name, uj);
856ca177 12569 else
db7c8528 12570 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
718e3744 12571}
12572
0b16f239 12573
718e3744 12574#ifdef HAVE_IPV6
f412b39a
DW
12575/*
12576 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 12577 * "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes [json]",
f412b39a
DW
12578 * SHOW_STR
12579 * BGP_STR
12580 * BGP_INSTANCE_HELP_STR
12581 * "Address family\n"
12582 * "Detailed information on TCP and BGP neighbor connections\n"
12583 * "Neighbor to display information about\n"
12584 * "Neighbor to display information about\n"
12585 * "Neighbor on bgp configured interface\n"
12586 * "Display the routes advertised to a BGP neighbor\n"
12587 * "JavaScript Object Notation\n"
12588 *
12589 */
8386ac43 12590DEFUN (show_bgp_instance_neighbor_advertised_route,
12591 show_bgp_instance_neighbor_advertised_route_cmd,
6147e2c6 12592 "show bgp " BGP_INSTANCE_CMD " neighbors <A.B.C.D|X:X::X:X|WORD> advertised-routes [json]",
718e3744 12593 SHOW_STR
12594 BGP_STR
8386ac43 12595 BGP_INSTANCE_HELP_STR
718e3744 12596 "Detailed information on TCP and BGP neighbor connections\n"
12597 "Neighbor to display information about\n"
12598 "Neighbor to display information about\n"
a80beece 12599 "Neighbor on bgp configured interface\n"
856ca177
MS
12600 "Display the routes advertised to a BGP neighbor\n"
12601 "JavaScript Object Notation\n")
718e3744 12602{
bb46e94f 12603 struct peer *peer;
db7c8528 12604 u_char uj = use_json(argc, argv);
856ca177 12605
4dcadbef
DW
12606 if (argc == 4 || (argc == 3 && argv[5]->arg && strcmp(argv[5]->arg, "json") != 0))
12607 peer = peer_lookup_in_view (vty, argv[3]->arg, argv[5]->arg, uj);
bb46e94f 12608 else
4dcadbef 12609 peer = peer_lookup_in_view (vty, NULL, argv[3]->arg, uj);
bb46e94f 12610
12611 if (! peer)
0b16f239 12612 return CMD_WARNING;
bb46e94f 12613
db7c8528 12614 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj);
47fc97cc
DS
12615}
12616
0b16f239 12617
f412b39a
DW
12618/*
12619 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 12620 * "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes [json]",
f412b39a
DW
12621 * SHOW_STR
12622 * BGP_STR
12623 * "Address family\n"
12624 * "Detailed information on TCP and BGP neighbor connections\n"
12625 * "Neighbor to display information about\n"
12626 * "Neighbor to display information about\n"
12627 * "Neighbor on bgp configured interface\n"
12628 * "Display the routes advertised to a BGP neighbor\n"
12629 * "JavaScript Object Notation\n"
12630 *
b162fa78 12631 * "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes [json]",
f412b39a
DW
12632 * SHOW_STR
12633 * IPV6_STR
12634 * BGP_STR
12635 * "Detailed information on TCP and BGP neighbor connections\n"
12636 * "Neighbor to display information about\n"
12637 * "Neighbor to display information about\n"
12638 * "Neighbor on bgp configured interface\n"
12639 * "Display the routes advertised to a BGP neighbor\n"
12640 * "JavaScript Object Notation\n"
12641 *
12642 */
0b16f239
DS
12643DEFUN (show_bgp_neighbor_advertised_route,
12644 show_bgp_neighbor_advertised_route_cmd,
6147e2c6 12645 "show bgp neighbors <A.B.C.D|X:X::X:X|WORD> advertised-routes [json]",
bb46e94f 12646 SHOW_STR
12647 BGP_STR
bb46e94f 12648 "Detailed information on TCP and BGP neighbor connections\n"
12649 "Neighbor to display information about\n"
12650 "Neighbor to display information about\n"
a80beece 12651 "Neighbor on bgp configured interface\n"
856ca177
MS
12652 "Display the routes advertised to a BGP neighbor\n"
12653 "JavaScript Object Notation\n")
0b16f239 12654
bb46e94f 12655{
12656 struct peer *peer;
ffd0c037 12657 const char *rmap_name = NULL;
db7c8528 12658 u_char uj = use_json(argc, argv);
bb46e94f 12659
4dcadbef 12660 peer = peer_lookup_in_view (vty, NULL, argv[3]->arg, uj);
856ca177
MS
12661
12662 if (!peer)
bb46e94f 12663 return CMD_WARNING;
12664
4dcadbef
DW
12665 if (argc == 3 || (argc == 2 && argv[5]->arg && strcmp(argv[5]->arg, "json") != 0))
12666 rmap_name = argv[5]->arg;
0b16f239 12667
f412b39a
DW
12668 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj);
12669}
12670
12671
718e3744 12672/* old command */
bb46e94f 12673
718e3744 12674/* old command */
12675DEFUN (ipv6_mbgp_neighbor_advertised_route,
12676 ipv6_mbgp_neighbor_advertised_route_cmd,
6147e2c6 12677 "show ipv6 mbgp neighbors <A.B.C.D|X:X::X:X|WORD> advertised-routes [json]",
718e3744 12678 SHOW_STR
12679 IPV6_STR
12680 MBGP_STR
12681 "Detailed information on TCP and BGP neighbor connections\n"
12682 "Neighbor to display information about\n"
12683 "Neighbor to display information about\n"
a80beece
DS
12684 "Neighbor on bgp configured interface\n"
12685 "Neighbor on bgp configured interface\n"
856ca177
MS
12686 "Display the routes advertised to a BGP neighbor\n"
12687 "JavaScript Object Notation\n")
718e3744 12688{
bb46e94f 12689 struct peer *peer;
db7c8528 12690 u_char uj = use_json(argc, argv);
856ca177 12691
4dcadbef 12692 peer = peer_lookup_in_view (vty, NULL, argv[4]->arg, uj);
bb46e94f 12693 if (! peer)
856ca177 12694 return CMD_WARNING;
bb46e94f 12695
47e9b292 12696 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 12697 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj);
718e3744 12698}
12699#endif /* HAVE_IPV6 */
6b0655a2 12700
f412b39a
DW
12701/*
12702 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 12703 * "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes [json]",
f412b39a
DW
12704 * SHOW_STR
12705 * BGP_STR
12706 * BGP_INSTANCE_HELP_STR
12707 * "Address family\n"
12708 * "Detailed information on TCP and BGP neighbor connections\n"
12709 * "Neighbor to display information about\n"
12710 * "Neighbor to display information about\n"
12711 * "Neighbor on bgp configured interface\n"
12712 * "Display the received routes from neighbor\n"
12713 * "JavaScript Object Notation\n"
12714 *
12715 */
8386ac43 12716DEFUN (show_bgp_instance_neighbor_received_routes,
12717 show_bgp_instance_neighbor_received_routes_cmd,
6147e2c6 12718 "show bgp " BGP_INSTANCE_CMD " neighbors <A.B.C.D|X:X::X:X|WORD> received-routes [json]",
0b16f239
DS
12719 SHOW_STR
12720 BGP_STR
8386ac43 12721 BGP_INSTANCE_HELP_STR
0b16f239
DS
12722 "Detailed information on TCP and BGP neighbor connections\n"
12723 "Neighbor to display information about\n"
12724 "Neighbor to display information about\n"
12725 "Neighbor on bgp configured interface\n"
856ca177
MS
12726 "Display the received routes from neighbor\n"
12727 "JavaScript Object Notation\n")
0b16f239
DS
12728{
12729 struct peer *peer;
db7c8528 12730 u_char uj = use_json(argc, argv);
856ca177 12731
4dcadbef 12732 peer = peer_lookup_in_view (vty, argv[3]->arg, argv[5]->arg, uj);
0b16f239
DS
12733 if (! peer)
12734 return CMD_WARNING;
12735
db7c8528 12736 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj);
0b16f239
DS
12737}
12738
f412b39a
DW
12739/*
12740 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 12741 * "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD [json]",
f412b39a
DW
12742 * SHOW_STR
12743 * IP_STR
12744 * BGP_STR
12745 * BGP_INSTANCE_HELP_STR
12746 * "Detailed information on TCP and BGP neighbor connections\n"
12747 * "Neighbor to display information about\n"
12748 * "Neighbor to display information about\n"
12749 * "Neighbor on bgp configured interface\n"
12750 * "Display the received routes from neighbor\n"
12751 * "JavaScript Object Notation\n"
12752 *
12753 */
8386ac43 12754DEFUN (show_ip_bgp_instance_neighbor_received_routes,
12755 show_ip_bgp_instance_neighbor_received_routes_cmd,
6147e2c6 12756 "show ip bgp " BGP_INSTANCE_CMD " neighbors <A.B.C.D|X:X::X:X|WORD> received-routes [json]",
718e3744 12757 SHOW_STR
12758 IP_STR
12759 BGP_STR
8386ac43 12760 BGP_INSTANCE_HELP_STR
718e3744 12761 "Detailed information on TCP and BGP neighbor connections\n"
12762 "Neighbor to display information about\n"
12763 "Neighbor to display information about\n"
a80beece 12764 "Neighbor on bgp configured interface\n"
856ca177
MS
12765 "Display the received routes from neighbor\n"
12766 "JavaScript Object Notation\n")
718e3744 12767{
bb46e94f 12768 struct peer *peer;
db7c8528 12769 u_char uj = use_json(argc, argv);
856ca177 12770
4dcadbef 12771 peer = peer_lookup_in_view (vty, argv[4]->arg, argv[6]->arg, uj);
bb46e94f 12772 if (! peer)
12773 return CMD_WARNING;
12774
db7c8528 12775 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj);
718e3744 12776}
12777
0b16f239 12778
f412b39a
DW
12779/*
12780 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 12781 * "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD [json]",
f412b39a
DW
12782 * SHOW_STR
12783 * IP_STR
12784 * BGP_STR
12785 * "Detailed information on TCP and BGP neighbor connections\n"
12786 * "Neighbor to display information about\n"
12787 * "Neighbor to display information about\n"
12788 * "Neighbor on bgp configured interface\n"
12789 * "Display the received routes from neighbor\n"
12790 * "JavaScript Object Notation\n"
12791 *
12792 */
0b16f239 12793DEFUN (show_ip_bgp_neighbor_received_routes,
2a71e9ce 12794 show_ip_bgp_neighbor_received_routes_cmd,
6147e2c6 12795 "show ip bgp neighbors <A.B.C.D|X:X::X:X|WORD> received-routes [json]",
2a71e9ce
TP
12796 SHOW_STR
12797 IP_STR
12798 BGP_STR
12799 "Detailed information on TCP and BGP neighbor connections\n"
12800 "Neighbor to display information about\n"
12801 "Neighbor to display information about\n"
a80beece 12802 "Neighbor on bgp configured interface\n"
856ca177
MS
12803 "Display the received routes from neighbor\n"
12804 "JavaScript Object Notation\n")
2a71e9ce 12805
0b16f239
DS
12806{
12807 struct peer *peer;
ffd0c037 12808 const char *rmap_name = NULL;
db7c8528 12809 u_char uj = use_json(argc, argv);
0b16f239 12810
4dcadbef 12811 peer = peer_lookup_in_view (vty, NULL, argv[4]->arg, uj);
0b16f239
DS
12812
12813 if (! peer)
12814 return CMD_WARNING;
12815
4dcadbef
DW
12816 if (argc == 3 || (argc == 2 && argv[6]->arg && strcmp(argv[6]->arg, "json") != 0))
12817 rmap_name = argv[6]->arg;
0b16f239 12818
db7c8528 12819 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
0b16f239
DS
12820}
12821
0b16f239 12822
50ef26d4 12823
f412b39a
DW
12824/*
12825 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 12826 * "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD [json]",
f412b39a
DW
12827 * SHOW_STR
12828 * IP_STR
12829 * BGP_STR
12830 * "Address family\n"
12831 * "Address Family modifier\n"
12832 * "Address Family modifier\n"
12833 * "Detailed information on TCP and BGP neighbor connections\n"
12834 * "Neighbor to display information about\n"
12835 * "Neighbor to display information about\n"
12836 * "Neighbor on bgp configured interface\n"
12837 * "Display the received routes from neighbor\n"
12838 * "JavaScript Object Notation\n"
12839 *
12840 */
718e3744 12841DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12842 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
6147e2c6 12843 "show ip bgp ipv4 <unicast|multicast> neighbors <A.B.C.D|X:X::X:X|WORD> received-routes [json]",
718e3744 12844 SHOW_STR
12845 IP_STR
12846 BGP_STR
12847 "Address family\n"
12848 "Address Family modifier\n"
12849 "Address Family modifier\n"
12850 "Detailed information on TCP and BGP neighbor connections\n"
12851 "Neighbor to display information about\n"
12852 "Neighbor to display information about\n"
a80beece 12853 "Neighbor on bgp configured interface\n"
856ca177
MS
12854 "Display the received routes from neighbor\n"
12855 "JavaScript Object Notation\n")
718e3744 12856{
bb46e94f 12857 struct peer *peer;
ffd0c037 12858 const char *rmap_name = NULL;
db7c8528 12859 u_char uj = use_json(argc, argv);
bb46e94f 12860
4dcadbef 12861 peer = peer_lookup_in_view (vty, NULL, argv[6]->arg, uj);
bb46e94f 12862 if (! peer)
12863 return CMD_WARNING;
0b16f239 12864
4dcadbef
DW
12865 if (argc == 4 || (argc == 3 && argv[8]->arg && strcmp(argv[8]->arg, "json") != 0))
12866 rmap_name = argv[8]->arg;
0b16f239 12867
4dcadbef 12868 if (strncmp (argv[4]->arg, "m", 1) == 0)
db7c8528 12869 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name, uj);
856ca177 12870 else
db7c8528 12871 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
718e3744 12872}
12873
0b16f239 12874
8386ac43 12875DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes,
12876 show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd,
6147e2c6 12877 "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
12878 SHOW_STR
12879 BGP_STR
8386ac43 12880 BGP_INSTANCE_HELP_STR
95cbbd2a 12881 "Address family\n"
95cbbd2a 12882 "Address family\n"
95cbbd2a
ML
12883 "Address family modifier\n"
12884 "Address family modifier\n"
12885 "Detailed information on TCP and BGP neighbor connections\n"
12886 "Neighbor to display information about\n"
12887 "Neighbor to display information about\n"
a80beece 12888 "Neighbor on bgp configured interface\n"
95cbbd2a 12889 "Display the advertised routes to neighbor\n"
856ca177
MS
12890 "Display the received routes from neighbor\n"
12891 "JavaScript Object Notation\n")
95cbbd2a
ML
12892{
12893 int afi;
12894 int safi;
12895 int in;
12896 struct peer *peer;
db7c8528 12897 u_char uj = use_json(argc, argv);
856ca177 12898
4dcadbef 12899 peer = peer_lookup_in_view (vty, argv[3]->arg, argv[7]->arg, uj);
95cbbd2a
ML
12900
12901 if (! peer)
12902 return CMD_WARNING;
12903
4dcadbef
DW
12904 afi = (strncmp (argv[4]->arg, "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
12905 safi = (strncmp (argv[5]->arg, "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12906 in = (strncmp (argv[8]->arg, "r", 1) == 0) ? 1 : 0;
95cbbd2a 12907
db7c8528 12908 return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj);
95cbbd2a
ML
12909}
12910
718e3744 12911DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12912 show_ip_bgp_neighbor_received_prefix_filter_cmd,
6147e2c6 12913 "show ip bgp neighbors <A.B.C.D|X:X::X:X|WORD> received prefix-filter [json]",
718e3744 12914 SHOW_STR
12915 IP_STR
12916 BGP_STR
12917 "Detailed information on TCP and BGP neighbor connections\n"
12918 "Neighbor to display information about\n"
12919 "Neighbor to display information about\n"
a80beece 12920 "Neighbor on bgp configured interface\n"
718e3744 12921 "Display information received from a BGP neighbor\n"
856ca177
MS
12922 "Display the prefixlist filter\n"
12923 "JavaScript Object Notation\n")
718e3744 12924{
12925 char name[BUFSIZ];
c63b83fe 12926 union sockunion su;
718e3744 12927 struct peer *peer;
c63b83fe 12928 int count, ret;
db7c8528 12929 u_char uj = use_json(argc, argv);
718e3744 12930
4dcadbef 12931 ret = str2sockunion (argv[4]->arg, &su);
c63b83fe
JBD
12932 if (ret < 0)
12933 {
4dcadbef 12934 peer = peer_lookup_by_conf_if (NULL, argv[4]->arg);
856ca177 12935 if (! peer)
a80beece 12936 {
db7c8528 12937 if (uj)
856ca177
MS
12938 {
12939 json_object *json_no = NULL;
12940 json_object *json_sub = NULL;
12941 json_no = json_object_new_object();
12942 json_sub = json_object_new_object();
12943 json_object_string_add(json_no, "warning", "Malformed address or name");
4dcadbef 12944 json_object_string_add(json_sub, "warningCause", argv[4]->arg);
856ca177
MS
12945 json_object_object_add(json_no, "detail", json_sub);
12946 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12947 json_object_free(json_no);
12948 }
12949 else
4dcadbef 12950 vty_out (vty, "%% Malformed address or name: %s%s", argv[4]->arg, VTY_NEWLINE);
a80beece
DS
12951 return CMD_WARNING;
12952 }
12953 }
12954 else
12955 {
12956 peer = peer_lookup (NULL, &su);
12957 if (! peer)
856ca177 12958 {
db7c8528 12959 if (uj)
856ca177
MS
12960 {
12961 json_object *json_no = NULL;
12962 json_no = json_object_new_object();
12963 json_object_string_add(json_no, "warning", "Peer not found");
12964 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12965 json_object_free(json_no);
12966 }
12967 else
12968 vty_out (vty, "No peer%s", VTY_NEWLINE);
12969 return CMD_WARNING;
12970 }
c63b83fe 12971 }
718e3744 12972
12973 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
db7c8528 12974 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
718e3744 12975 if (count)
12976 {
db7c8528 12977 if (!uj)
856ca177 12978 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
db7c8528 12979 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
856ca177
MS
12980 }
12981 else
12982 {
db7c8528 12983 if (uj)
856ca177
MS
12984 {
12985 json_object *json_no = NULL;
12986 json_no = json_object_new_object();
12987 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12988 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12989 json_object_free(json_no);
12990 }
12991 else
12992 vty_out (vty, "No functional output%s", VTY_NEWLINE);
718e3744 12993 }
12994
12995 return CMD_SUCCESS;
12996}
12997
12998DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
12999 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
6147e2c6 13000 "show ip bgp ipv4 <unicast|multicast> neighbors <A.B.C.D|X:X::X:X|WORD> received prefix-filter [json]",
718e3744 13001 SHOW_STR
13002 IP_STR
13003 BGP_STR
13004 "Address family\n"
13005 "Address Family modifier\n"
13006 "Address Family modifier\n"
13007 "Detailed information on TCP and BGP neighbor connections\n"
13008 "Neighbor to display information about\n"
13009 "Neighbor to display information about\n"
a80beece 13010 "Neighbor on bgp configured interface\n"
718e3744 13011 "Display information received from a BGP neighbor\n"
856ca177
MS
13012 "Display the prefixlist filter\n"
13013 "JavaScript Object Notation\n")
718e3744 13014{
13015 char name[BUFSIZ];
c63b83fe 13016 union sockunion su;
718e3744 13017 struct peer *peer;
c63b83fe 13018 int count, ret;
db7c8528 13019 u_char uj = use_json(argc, argv);
718e3744 13020
4dcadbef 13021 ret = str2sockunion (argv[6]->arg, &su);
c63b83fe
JBD
13022 if (ret < 0)
13023 {
4dcadbef 13024 peer = peer_lookup_by_conf_if (NULL, argv[6]->arg);
856ca177 13025 if (! peer)
a80beece 13026 {
db7c8528 13027 if (uj)
856ca177
MS
13028 {
13029 json_object *json_no = NULL;
13030 json_object *json_sub = NULL;
13031 json_no = json_object_new_object();
13032 json_sub = json_object_new_object();
13033 json_object_string_add(json_no, "warning", "Malformed address or name");
4dcadbef 13034 json_object_string_add(json_sub, "warningCause", argv[6]->arg);
856ca177
MS
13035 json_object_object_add(json_no, "detail", json_sub);
13036 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13037 json_object_free(json_no);
13038 }
13039 else
4dcadbef 13040 vty_out (vty, "%% Malformed address or name: %s%s", argv[6]->arg, VTY_NEWLINE);
a80beece
DS
13041 return CMD_WARNING;
13042 }
13043 }
13044 else
13045 {
13046 peer = peer_lookup (NULL, &su);
13047 if (! peer)
856ca177 13048 {
db7c8528 13049 if (uj)
856ca177
MS
13050 {
13051 json_object *json_no = NULL;
13052 json_no = json_object_new_object();
13053 json_object_string_add(json_no, "warning", "Peer not found");
13054 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13055 json_object_free(json_no);
13056 }
13057 else
13058 vty_out (vty, "No peer%s", VTY_NEWLINE);
13059 return CMD_WARNING;
13060 }
c63b83fe 13061 }
718e3744 13062
4dcadbef 13063 if (strncmp (argv[4]->arg, "m", 1) == 0)
718e3744 13064 {
13065 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
db7c8528 13066 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
718e3744 13067 if (count)
856ca177 13068 {
db7c8528 13069 if (!uj)
856ca177 13070 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
db7c8528 13071 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
856ca177
MS
13072 }
13073 else
13074 {
db7c8528 13075 if (uj)
856ca177
MS
13076 {
13077 json_object *json_no = NULL;
13078 json_no = json_object_new_object();
13079 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13080 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13081 json_object_free(json_no);
13082 }
13083 else
13084 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13085 }
718e3744 13086 }
13087 else
13088 {
13089 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
db7c8528 13090 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
718e3744 13091 if (count)
856ca177 13092 {
db7c8528 13093 if (!uj)
856ca177 13094 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
db7c8528 13095 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
856ca177
MS
13096 }
13097 else
13098 {
db7c8528 13099 if (uj)
856ca177
MS
13100 {
13101 json_object *json_no = NULL;
13102 json_no = json_object_new_object();
13103 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13104 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13105 json_object_free(json_no);
13106 }
13107 else
13108 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13109 }
718e3744 13110 }
13111
13112 return CMD_SUCCESS;
13113}
718e3744 13114#ifdef HAVE_IPV6
f412b39a
DW
13115/*
13116 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 13117 * "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes [json]",
f412b39a
DW
13118 * SHOW_STR
13119 * BGP_STR
13120 * "Address family\n"
13121 * "Detailed information on TCP and BGP neighbor connections\n"
13122 * "Neighbor to display information about\n"
13123 * "Neighbor to display information about\n"
13124 * "Neighbor on bgp configured interface\n"
13125 * "Display the received routes from neighbor\n"
13126 * "JavaScript Object Notation\n"
13127 *
b162fa78 13128 * "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes [json]",
f412b39a
DW
13129 * SHOW_STR
13130 * IPV6_STR
13131 * BGP_STR
13132 * "Detailed information on TCP and BGP neighbor connections\n"
13133 * "Neighbor to display information about\n"
13134 * "Neighbor to display information about\n"
13135 * "Neighbor on bgp configured interface\n"
13136 * "Display the received routes from neighbor\n"
13137 * "JavaScript Object Notation\n"
13138 *
13139 */
50ef26d4 13140DEFUN (show_bgp_neighbor_received_routes,
718e3744 13141 show_bgp_neighbor_received_routes_cmd,
6147e2c6 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
4dcadbef 13156 peer = peer_lookup_in_view (vty, NULL, argv[3]->arg, uj);
50ef26d4 13157
13158 if (! peer)
13159 return CMD_WARNING;
13160
4dcadbef
DW
13161 if (argc == 3 || (argc == 2 && argv[5]->arg && strcmp(argv[5]->arg, "json") != 0))
13162 rmap_name = argv[5]->arg;
50ef26d4 13163
13164 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, rmap_name, uj);
13165}
13166
0b16f239 13167
f412b39a
DW
13168/*
13169 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 13170 * "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter [json]",
f412b39a
DW
13171 * SHOW_STR
13172 * BGP_STR
13173 * "Address family\n"
13174 * "Detailed information on TCP and BGP neighbor connections\n"
13175 * "Neighbor to display information about\n"
13176 * "Neighbor to display information about\n"
13177 * "Neighbor on bgp configured interface\n"
13178 * "Display information received from a BGP neighbor\n"
13179 * "Display the prefixlist filter\n"
13180 * "JavaScript Object Notation\n"
13181 *
13182 */
718e3744 13183DEFUN (show_bgp_neighbor_received_prefix_filter,
13184 show_bgp_neighbor_received_prefix_filter_cmd,
6147e2c6 13185 "show bgp neighbors <A.B.C.D|X:X::X:X|WORD> received prefix-filter [json]",
718e3744 13186 SHOW_STR
13187 BGP_STR
13188 "Detailed information on TCP and BGP neighbor connections\n"
13189 "Neighbor to display information about\n"
13190 "Neighbor to display information about\n"
a80beece 13191 "Neighbor on bgp configured interface\n"
718e3744 13192 "Display information received from a BGP neighbor\n"
856ca177
MS
13193 "Display the prefixlist filter\n"
13194 "JavaScript Object Notation\n")
718e3744 13195{
13196 char name[BUFSIZ];
c63b83fe 13197 union sockunion su;
718e3744 13198 struct peer *peer;
c63b83fe 13199 int count, ret;
db7c8528 13200 u_char uj = use_json(argc, argv);
718e3744 13201
4dcadbef 13202 ret = str2sockunion (argv[3]->arg, &su);
c63b83fe
JBD
13203 if (ret < 0)
13204 {
4dcadbef 13205 peer = peer_lookup_by_conf_if (NULL, argv[3]->arg);
856ca177 13206 if (! peer)
a80beece 13207 {
db7c8528 13208 if (uj)
856ca177
MS
13209 {
13210 json_object *json_no = NULL;
13211 json_object *json_sub = NULL;
13212 json_no = json_object_new_object();
13213 json_sub = json_object_new_object();
13214 json_object_string_add(json_no, "warning", "Malformed address or name");
4dcadbef 13215 json_object_string_add(json_sub, "warningCause", argv[3]->arg);
856ca177
MS
13216 json_object_object_add(json_no, "detail", json_sub);
13217 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13218 json_object_free(json_no);
13219 }
13220 else
4dcadbef 13221 vty_out (vty, "%% Malformed address or name: %s%s", argv[3]->arg, VTY_NEWLINE);
a80beece
DS
13222 return CMD_WARNING;
13223 }
13224 }
13225 else
13226 {
13227 peer = peer_lookup (NULL, &su);
13228 if (! peer)
856ca177 13229 {
db7c8528 13230 if (uj)
856ca177
MS
13231 {
13232 json_object *json_no = NULL;
13233 json_no = json_object_new_object();
13234 json_object_string_add(json_no, "warning", "No Peer");
13235 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13236 json_object_free(json_no);
13237 }
13238 else
13239 vty_out (vty, "No peer%s", VTY_NEWLINE);
13240 return CMD_WARNING;
13241 }
c63b83fe 13242 }
718e3744 13243
13244 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
db7c8528 13245 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
718e3744 13246 if (count)
13247 {
db7c8528 13248 if (!uj)
856ca177 13249 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
db7c8528 13250 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
856ca177
MS
13251 }
13252 else
13253 {
db7c8528 13254 if (uj)
856ca177
MS
13255 {
13256 json_object *json_no = NULL;
13257 json_no = json_object_new_object();
13258 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13259 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13260 json_object_free(json_no);
13261 }
13262 else
13263 vty_out (vty, "No functional output%s", VTY_NEWLINE);
718e3744 13264 }
13265
13266 return CMD_SUCCESS;
13267}
13268
718e3744 13269
13270/* old command */
718e3744 13271
13272/* old command */
13273DEFUN (ipv6_mbgp_neighbor_received_routes,
13274 ipv6_mbgp_neighbor_received_routes_cmd,
6147e2c6 13275 "show ipv6 mbgp neighbors <A.B.C.D|X:X::X:X|WORD> received-routes [json]",
718e3744 13276 SHOW_STR
13277 IPV6_STR
13278 MBGP_STR
13279 "Detailed information on TCP and BGP neighbor connections\n"
13280 "Neighbor to display information about\n"
13281 "Neighbor to display information about\n"
a80beece 13282 "Neighbor on bgp configured interface\n"
856ca177
MS
13283 "Display the received routes from neighbor\n"
13284 "JavaScript Object Notation\n")
718e3744 13285{
bb46e94f 13286 struct peer *peer;
db7c8528 13287 u_char uj = use_json(argc, argv);
bb46e94f 13288
4dcadbef 13289 peer = peer_lookup_in_view (vty, NULL, argv[4]->arg, uj);
bb46e94f 13290 if (! peer)
13291 return CMD_WARNING;
13292
47e9b292 13293 bgp_show_ipv6_bgp_deprecate_warning(vty);
db7c8528 13294 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj);
bb46e94f 13295}
13296
f412b39a
DW
13297/*
13298 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 13299 * "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter [json]",
f412b39a
DW
13300 * SHOW_STR
13301 * BGP_STR
13302 * BGP_INSTANCE_HELP_STR
13303 * "Address family\n"
13304 * "Detailed information on TCP and BGP neighbor connections\n"
13305 * "Neighbor to display information about\n"
13306 * "Neighbor to display information about\n"
13307 * "Neighbor on bgp configured interface\n"
13308 * "Display information received from a BGP neighbor\n"
13309 * "Display the prefixlist filter\n"
13310 * "JavaScript Object NOtation\n"
13311 *
13312 */
8386ac43 13313DEFUN (show_bgp_instance_neighbor_received_prefix_filter,
13314 show_bgp_instance_neighbor_received_prefix_filter_cmd,
6147e2c6 13315 "show bgp " BGP_INSTANCE_CMD " neighbors <A.B.C.D|X:X::X:X|WORD> received prefix-filter [json]",
bb46e94f 13316 SHOW_STR
13317 BGP_STR
8386ac43 13318 BGP_INSTANCE_HELP_STR
bb46e94f 13319 "Detailed information on TCP and BGP neighbor connections\n"
13320 "Neighbor to display information about\n"
13321 "Neighbor to display information about\n"
a80beece 13322 "Neighbor on bgp configured interface\n"
bb46e94f 13323 "Display information received from a BGP neighbor\n"
856ca177
MS
13324 "Display the prefixlist filter\n"
13325 "JavaScript Object Notation\n")
bb46e94f 13326{
13327 char name[BUFSIZ];
c63b83fe 13328 union sockunion su;
bb46e94f 13329 struct peer *peer;
13330 struct bgp *bgp;
c63b83fe 13331 int count, ret;
db7c8528 13332 u_char uj = use_json(argc, argv);
bb46e94f 13333
13334 /* BGP structure lookup. */
4dcadbef 13335 bgp = bgp_lookup_by_name (argv[3]->arg);
bb46e94f 13336 if (bgp == NULL)
856ca177 13337 {
db7c8528 13338 if (uj)
856ca177
MS
13339 {
13340 json_object *json_no = NULL;
13341 json_no = json_object_new_object();
13342 json_object_string_add(json_no, "warning", "Can't find BGP view");
13343 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13344 json_object_free(json_no);
13345 }
13346 else
4dcadbef 13347 vty_out (vty, "Can't find BGP instance %s%s", argv[3]->arg, VTY_NEWLINE);
856ca177
MS
13348 return CMD_WARNING;
13349 }
13350
4dcadbef 13351 ret = str2sockunion (argv[5]->arg, &su);
c63b83fe
JBD
13352 if (ret < 0)
13353 {
4dcadbef 13354 peer = peer_lookup_by_conf_if (bgp, argv[5]->arg);
856ca177 13355 if (! peer)
a80beece 13356 {
db7c8528 13357 if (uj)
856ca177
MS
13358 {
13359 json_object *json_no = NULL;
13360 json_object *json_sub = NULL;
13361 json_no = json_object_new_object();
13362 json_sub = json_object_new_object();
13363 json_object_string_add(json_no, "warning", "Malformed address or name");
4dcadbef 13364 json_object_string_add(json_sub, "warningCause", argv[5]->arg);
856ca177
MS
13365 json_object_object_add(json_no, "detail", json_sub);
13366 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13367 json_object_free(json_no);
13368 }
13369 else
4dcadbef 13370 vty_out (vty, "%% Malformed address or name: %s%s", argv[5]->arg, VTY_NEWLINE);
a80beece
DS
13371 return CMD_WARNING;
13372 }
13373 }
13374 else
13375 {
13376 peer = peer_lookup (bgp, &su);
13377 if (! peer)
856ca177 13378 {
db7c8528 13379 if (uj)
856ca177
MS
13380 {
13381 json_object *json_no = NULL;
13382 json_no = json_object_new_object();
13383 json_object_boolean_true_add(json_no, "noPeer");
13384 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13385 json_object_free(json_no);
13386 }
13387 else
13388 vty_out (vty, "No peer%s", VTY_NEWLINE);
13389 return CMD_WARNING;
13390 }
13391
c63b83fe 13392 }
bb46e94f 13393
13394 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
db7c8528 13395 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
bb46e94f 13396 if (count)
13397 {
db7c8528 13398 if (!uj)
856ca177 13399 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
db7c8528 13400 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
bb46e94f 13401 }
13402
13403 return CMD_SUCCESS;
718e3744 13404}
13405#endif /* HAVE_IPV6 */
6b0655a2 13406
94f2b392 13407static int
bb46e94f 13408bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
856ca177 13409 safi_t safi, enum bgp_show_type type, u_char use_json)
718e3744 13410{
718e3744 13411 if (! peer || ! peer->afc[afi][safi])
13412 {
856ca177
MS
13413 if (use_json)
13414 {
13415 json_object *json_no = NULL;
13416 json_no = json_object_new_object();
13417 json_object_string_add(json_no, "warning", "No such neighbor or address family");
13418 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13419 json_object_free(json_no);
13420 }
13421 else
13422 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
718e3744 13423 return CMD_WARNING;
13424 }
47fc97cc 13425
856ca177 13426 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json);
718e3744 13427}
13428
13429DEFUN (show_ip_bgp_neighbor_routes,
13430 show_ip_bgp_neighbor_routes_cmd,
6147e2c6 13431 "show ip bgp neighbors <A.B.C.D|X:X::X:X|WORD> routes [json]",
718e3744 13432 SHOW_STR
13433 IP_STR
13434 BGP_STR
13435 "Detailed information on TCP and BGP neighbor connections\n"
13436 "Neighbor to display information about\n"
13437 "Neighbor to display information about\n"
a80beece 13438 "Neighbor on bgp configured interface\n"
856ca177
MS
13439 "Display routes learned from neighbor\n"
13440 "JavaScript Object Notation\n")
718e3744 13441{
bb46e94f 13442 struct peer *peer;
db7c8528 13443 u_char uj = use_json(argc, argv);
856ca177 13444
4dcadbef 13445 peer = peer_lookup_in_view (vty, NULL, argv[4]->arg, uj);
bb46e94f 13446 if (! peer)
13447 return CMD_WARNING;
13448
13449 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 13450 bgp_show_type_neighbor, uj);
718e3744 13451}
13452
8386ac43 13453DEFUN (show_ip_bgp_instance_neighbor_routes,
13454 show_ip_bgp_instance_neighbor_routes_cmd,
6147e2c6 13455 "show ip bgp " BGP_INSTANCE_CMD " neighbors <A.B.C.D|X:X::X:X|WORD> routes [json]",
50ef26d4 13456 SHOW_STR
13457 IP_STR
13458 BGP_STR
8386ac43 13459 BGP_INSTANCE_HELP_STR
50ef26d4 13460 "Detailed information on TCP and BGP neighbor connections\n"
13461 "Neighbor to display information about\n"
13462 "Neighbor to display information about\n"
13463 "Neighbor on bgp configured interface\n"
13464 "Display routes learned from neighbor\n"
13465 "JavaScript Object Notation\n")
13466{
13467 struct peer *peer;
13468 u_char uj = use_json(argc, argv);
13469
4dcadbef 13470 peer = peer_lookup_in_view (vty, argv[4]->arg, argv[6]->arg, uj);
50ef26d4 13471 if (! peer)
13472 return CMD_WARNING;
13473
13474 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13475 bgp_show_type_neighbor, uj);
13476}
13477
718e3744 13478DEFUN (show_ip_bgp_neighbor_flap,
13479 show_ip_bgp_neighbor_flap_cmd,
6147e2c6 13480 "show ip bgp neighbors <A.B.C.D|X:X::X:X|WORD> flap-statistics [json]",
718e3744 13481 SHOW_STR
13482 IP_STR
13483 BGP_STR
13484 "Detailed information on TCP and BGP neighbor connections\n"
13485 "Neighbor to display information about\n"
13486 "Neighbor to display information about\n"
a80beece 13487 "Neighbor on bgp configured interface\n"
856ca177
MS
13488 "Display flap statistics of the routes learned from neighbor\n"
13489 "JavaScript Object Notation\n")
718e3744 13490{
bb46e94f 13491 struct peer *peer;
db7c8528 13492 u_char uj = use_json(argc, argv);
856ca177 13493
4dcadbef 13494 peer = peer_lookup_in_view (vty, NULL, argv[4]->arg, uj);
bb46e94f 13495 if (! peer)
13496 return CMD_WARNING;
13497
13498 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 13499 bgp_show_type_flap_neighbor, uj);
718e3744 13500}
13501
13502DEFUN (show_ip_bgp_neighbor_damp,
13503 show_ip_bgp_neighbor_damp_cmd,
6147e2c6 13504 "show ip bgp neighbors <A.B.C.D|X:X::X:X|WORD> dampened-routes [json]",
718e3744 13505 SHOW_STR
13506 IP_STR
13507 BGP_STR
13508 "Detailed information on TCP and BGP neighbor connections\n"
13509 "Neighbor to display information about\n"
13510 "Neighbor to display information about\n"
a80beece 13511 "Neighbor on bgp configured interface\n"
856ca177
MS
13512 "Display the dampened routes received from neighbor\n"
13513 "JavaScript Object Notation\n")
718e3744 13514{
bb46e94f 13515 struct peer *peer;
db7c8528 13516 u_char uj = use_json(argc, argv);
856ca177 13517
4dcadbef 13518 peer = peer_lookup_in_view (vty, NULL, argv[4]->arg, uj);
bb46e94f 13519 if (! peer)
13520 return CMD_WARNING;
13521
13522 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 13523 bgp_show_type_damp_neighbor, uj);
718e3744 13524}
13525
13526DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13527 show_ip_bgp_ipv4_neighbor_routes_cmd,
6147e2c6 13528 "show ip bgp ipv4 <unicast|multicast> neighbors <A.B.C.D|X:X::X:X|WORD> routes [json]",
718e3744 13529 SHOW_STR
13530 IP_STR
13531 BGP_STR
13532 "Address family\n"
13533 "Address Family modifier\n"
13534 "Address Family modifier\n"
13535 "Detailed information on TCP and BGP neighbor connections\n"
13536 "Neighbor to display information about\n"
13537 "Neighbor to display information about\n"
a80beece 13538 "Neighbor on bgp configured interface\n"
856ca177
MS
13539 "Display routes learned from neighbor\n"
13540 "JavaScript Object Notation\n")
718e3744 13541{
bb46e94f 13542 struct peer *peer;
db7c8528 13543 u_char uj = use_json(argc, argv);
bb46e94f 13544
4dcadbef 13545 peer = peer_lookup_in_view (vty, NULL, argv[6]->arg, uj);
bb46e94f 13546 if (! peer)
13547 return CMD_WARNING;
13548
4dcadbef 13549 if (strncmp (argv[4]->arg, "m", 1) == 0)
bb46e94f 13550 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
db7c8528 13551 bgp_show_type_neighbor, uj);
718e3744 13552
bb46e94f 13553 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
db7c8528 13554 bgp_show_type_neighbor, uj);
718e3744 13555}
bb46e94f 13556
2a3d5731 13557#ifdef HAVE_IPV6
f412b39a
DW
13558/*
13559 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 13560 * "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes [json]",
f412b39a
DW
13561 * SHOW_STR
13562 * BGP_STR
13563 * BGP_INSTANCE_HELP_STR
13564 * "Address family\n"
13565 * "Detailed information on TCP and BGP neighbor connections\n"
13566 * "Neighbor to display information about\n"
13567 * "Neighbor to display information about\n"
13568 * "Neighbor on bgp configured interface\n"
13569 * "Display routes learned from neighbor\n"
13570 * "JavaScript Object Notation\n"
13571 *
13572 */
8386ac43 13573DEFUN (show_bgp_instance_neighbor_routes,
13574 show_bgp_instance_neighbor_routes_cmd,
6147e2c6 13575 "show bgp " BGP_INSTANCE_CMD " neighbors <A.B.C.D|X:X::X:X|WORD> routes [json]",
fee0f4c6 13576 SHOW_STR
fee0f4c6 13577 BGP_STR
8386ac43 13578 BGP_INSTANCE_HELP_STR
2a3d5731
DW
13579 "Detailed information on TCP and BGP neighbor connections\n"
13580 "Neighbor to display information about\n"
13581 "Neighbor to display information about\n"
13582 "Neighbor on bgp configured interface\n"
13583 "Display routes learned from neighbor\n"
13584 "JavaScript Object Notation\n")
fee0f4c6 13585{
fee0f4c6 13586 struct peer *peer;
db7c8528 13587 u_char uj = use_json(argc, argv);
fee0f4c6 13588
4dcadbef 13589 peer = peer_lookup_in_view (vty, argv[3]->arg, argv[5]->arg, uj);
fee0f4c6 13590 if (! peer)
13591 return CMD_WARNING;
13592
2a3d5731 13593 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
db7c8528 13594 bgp_show_type_neighbor, uj);
fee0f4c6 13595}
13596
fee0f4c6 13597
f412b39a
DW
13598/*
13599 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 13600 * "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes [json]",
f412b39a
DW
13601 * SHOW_STR
13602 * BGP_STR
13603 * "Detailed information on TCP and BGP neighbor connections\n"
13604 * "Neighbor to display information about\n"
13605 * "Neighbor to display information about\n"
13606 * "Neighbor on bgp configured interface\n"
13607 * "Display the dampened routes received from neighbor\n"
13608 * "JavaScript Object Notation\n"
13609 *
b162fa78 13610 * "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes [json]",
f412b39a
DW
13611 * SHOW_STR
13612 * BGP_STR
13613 * BGP_INSTANCE_HELP_STR
13614 * "Address family\n"
13615 * "Detailed information on TCP and BGP neighbor connections\n"
13616 * "Neighbor to display information about\n"
13617 * "Neighbor to display information about\n"
13618 * "Neighbor on bgp configured interface\n"
13619 * "Display the dampened routes received from neighbor\n"
13620 * "JavaScript Object Notation\n"
13621 *
b162fa78 13622 * "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes [json]",
f412b39a
DW
13623 * SHOW_STR
13624 * BGP_STR
13625 * "Address family\n"
13626 * "Detailed information on TCP and BGP neighbor connections\n"
13627 * "Neighbor to display information about\n"
13628 * "Neighbor to display information about\n"
13629 * "Neighbor on bgp configured interface\n"
13630 * "Display the dampened routes received from neighbor\n"
13631 * "JavaScript Object Notation\n"
13632 *
13633 */
8386ac43 13634DEFUN (show_bgp_instance_neighbor_damp,
13635 show_bgp_instance_neighbor_damp_cmd,
6147e2c6 13636 "show bgp " BGP_INSTANCE_CMD " neighbors <A.B.C.D|X:X::X:X|WORD> dampened-routes [json]",
fee0f4c6 13637 SHOW_STR
fee0f4c6 13638 BGP_STR
8386ac43 13639 BGP_INSTANCE_HELP_STR
2a3d5731
DW
13640 "Detailed information on TCP and BGP neighbor connections\n"
13641 "Neighbor to display information about\n"
13642 "Neighbor to display information about\n"
13643 "Neighbor on bgp configured interface\n"
13644 "Display the dampened routes received from neighbor\n"
13645 "JavaScript Object Notation\n")
bb46e94f 13646{
13647 struct peer *peer;
db7c8528 13648 u_char uj = use_json(argc, argv);
856ca177 13649
4dcadbef
DW
13650 if ((argc == 4 && argv[7]->arg && strcmp(argv[7]->arg, "json") == 0)
13651 || (argc == 3 && argv[5]->arg && strcmp(argv[5]->arg, "json") != 0))
13652 peer = peer_lookup_in_view (vty, argv[3]->arg, argv[5]->arg, uj);
bb46e94f 13653 else
4dcadbef 13654 peer = peer_lookup_in_view (vty, NULL, argv[3]->arg, uj);
bb46e94f 13655
13656 if (! peer)
13657 return CMD_WARNING;
13658
13659 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
db7c8528 13660 bgp_show_type_damp_neighbor, uj);
bb46e94f 13661}
13662
bb46e94f 13663
f412b39a
DW
13664/*
13665 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 13666 * "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics [json]",
f412b39a
DW
13667 * SHOW_STR
13668 * BGP_STR
13669 * "Detailed information on TCP and BGP neighbor connections\n"
13670 * "Neighbor to display information about\n"
13671 * "Neighbor to display information about\n"
13672 * "Neighbor on bgp configured interface\n"
13673 * "Display flap statistics of the routes learned from neighbor\n"
13674 * "JavaScript Object Notation\n"
13675 *
b162fa78 13676 * "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics [json]",
f412b39a
DW
13677 * SHOW_STR
13678 * BGP_STR
13679 * BGP_INSTANCE_HELP_STR
13680 * "Address family\n"
13681 * "Detailed information on TCP and BGP neighbor connections\n"
13682 * "Neighbor to display information about\n"
13683 * "Neighbor to display information about\n"
13684 * "Neighbor on bgp configured interface\n"
13685 * "Display flap statistics of the routes learned from neighbor\n"
13686 * "JavaScript Object Notation\n"
13687 *
b162fa78 13688 * "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics [json]",
f412b39a
DW
13689 * SHOW_STR
13690 * BGP_STR
13691 * "Address family\n"
13692 * "Detailed information on TCP and BGP neighbor connections\n"
13693 * "Neighbor to display information about\n"
13694 * "Neighbor to display information about\n"
13695 * "Neighbor on bgp configured interface\n"
13696 * "Display flap statistics of the routes learned from neighbor\n"
13697 * "JavaScript Object Notation\n"
13698 *
13699 */
8386ac43 13700DEFUN (show_bgp_instance_neighbor_flap,
13701 show_bgp_instance_neighbor_flap_cmd,
6147e2c6 13702 "show bgp " BGP_INSTANCE_CMD " neighbors <A.B.C.D|X:X::X:X|WORD> flap-statistics [json]",
bb46e94f 13703 SHOW_STR
13704 BGP_STR
8386ac43 13705 BGP_INSTANCE_HELP_STR
bb46e94f 13706 "Detailed information on TCP and BGP neighbor connections\n"
13707 "Neighbor to display information about\n"
13708 "Neighbor to display information about\n"
a80beece 13709 "Neighbor on bgp configured interface\n"
856ca177
MS
13710 "Display flap statistics of the routes learned from neighbor\n"
13711 "JavaScript Object Notation\n")
bb46e94f 13712{
13713 struct peer *peer;
db7c8528 13714 u_char uj = use_json(argc, argv);
856ca177 13715
4dcadbef
DW
13716 if ((argc == 4 && argv[7]->arg && strcmp(argv[7]->arg, "json") == 0)
13717 || (argc == 3 && argv[5]->arg && strcmp(argv[5]->arg, "json") != 0))
13718 peer = peer_lookup_in_view (vty, argv[3]->arg, argv[5]->arg, uj);
bb46e94f 13719 else
4dcadbef 13720 peer = peer_lookup_in_view (vty, NULL, argv[3]->arg, uj);
bb46e94f 13721
13722 if (! peer)
13723 return CMD_WARNING;
13724
13725 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
db7c8528 13726 bgp_show_type_flap_neighbor, uj);
bb46e94f 13727}
13728
bb46e94f 13729
f412b39a
DW
13730/*
13731 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
b162fa78 13732 * "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes [json]",
f412b39a
DW
13733 * SHOW_STR
13734 * IPV6_STR
13735 * BGP_STR
13736 * "Detailed information on TCP and BGP neighbor connections\n"
13737 * "Neighbor to display information about\n"
13738 * "Neighbor to display information about\n"
13739 * "Neighbor on bgp configured interface\n"
13740 * "Display routes learned from neighbor\n"
13741 * "JavaScript Object Notation\n"
13742 *
b162fa78 13743 * "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes [json]",
f412b39a
DW
13744 * SHOW_STR
13745 * BGP_STR
13746 * "Address family\n"
13747 * "Detailed information on TCP and BGP neighbor connections\n"
13748 * "Neighbor to display information about\n"
13749 * "Neighbor to display information about\n"
13750 * "Neighbor on bgp configured interface\n"
13751 * "Display routes learned from neighbor\n"
13752 * "JavaScript Object Notation\n"
13753 *
13754 */
50ef26d4 13755DEFUN (show_bgp_neighbor_routes,
bb46e94f 13756 show_bgp_neighbor_routes_cmd,
6147e2c6 13757 "show bgp neighbors <A.B.C.D|X:X::X:X|WORD> routes [json]",
bb46e94f 13758 SHOW_STR
13759 BGP_STR
13760 "Detailed information on TCP and BGP neighbor connections\n"
13761 "Neighbor to display information about\n"
13762 "Neighbor to display information about\n"
a80beece 13763 "Neighbor on bgp configured interface\n"
856ca177
MS
13764 "Display routes learned from neighbor\n"
13765 "JavaScript Object Notation\n")
50ef26d4 13766{
13767 struct peer *peer;
13768 u_char uj = use_json(argc, argv);
bb46e94f 13769
4dcadbef 13770 peer = peer_lookup_in_view (vty, NULL, argv[3]->arg, uj);
50ef26d4 13771 if (! peer)
13772 return CMD_WARNING;
bb46e94f 13773
50ef26d4 13774 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13775 bgp_show_type_neighbor, uj);
13776}
13777
13778
718e3744 13779
13780/* old command */
718e3744 13781
13782/* old command */
13783DEFUN (ipv6_mbgp_neighbor_routes,
13784 ipv6_mbgp_neighbor_routes_cmd,
6147e2c6 13785 "show ipv6 mbgp neighbors <A.B.C.D|X:X::X:X|WORD> routes [json]",
718e3744 13786 SHOW_STR
13787 IPV6_STR
13788 MBGP_STR
13789 "Detailed information on TCP and BGP neighbor connections\n"
13790 "Neighbor to display information about\n"
13791 "Neighbor to display information about\n"
a80beece 13792 "Neighbor on bgp configured interface\n"
856ca177
MS
13793 "Display routes learned from neighbor\n"
13794 "JavaScript Object Notation\n")
718e3744 13795{
bb46e94f 13796 struct peer *peer;
db7c8528 13797 u_char uj = use_json(argc, argv);
bb46e94f 13798
4dcadbef 13799 peer = peer_lookup_in_view (vty, NULL, argv[4]->arg, uj);
bb46e94f 13800 if (! peer)
13801 return CMD_WARNING;
13802
47e9b292 13803 bgp_show_ipv6_bgp_deprecate_warning(vty);
bb46e94f 13804 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
db7c8528 13805 bgp_show_type_neighbor, uj);
718e3744 13806}
bb46e94f 13807
bb46e94f 13808
bb46e94f 13809
bb46e94f 13810
fee0f4c6 13811
718e3744 13812#endif /* HAVE_IPV6 */
6b0655a2 13813
718e3744 13814struct bgp_table *bgp_distance_table;
13815
13816struct bgp_distance
13817{
13818 /* Distance value for the IP source prefix. */
13819 u_char distance;
13820
13821 /* Name of the access-list to be matched. */
13822 char *access_list;
13823};
13824
94f2b392 13825static struct bgp_distance *
66e5cd87 13826bgp_distance_new (void)
718e3744 13827{
393deb9b 13828 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
718e3744 13829}
13830
94f2b392 13831static void
718e3744 13832bgp_distance_free (struct bgp_distance *bdistance)
13833{
13834 XFREE (MTYPE_BGP_DISTANCE, bdistance);
13835}
13836
94f2b392 13837static int
fd79ac91 13838bgp_distance_set (struct vty *vty, const char *distance_str,
13839 const char *ip_str, const char *access_list_str)
718e3744 13840{
13841 int ret;
13842 struct prefix_ipv4 p;
13843 u_char distance;
13844 struct bgp_node *rn;
13845 struct bgp_distance *bdistance;
13846
13847 ret = str2prefix_ipv4 (ip_str, &p);
13848 if (ret == 0)
13849 {
13850 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13851 return CMD_WARNING;
13852 }
13853
13854 distance = atoi (distance_str);
13855
13856 /* Get BGP distance node. */
13857 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
13858 if (rn->info)
13859 {
13860 bdistance = rn->info;
13861 bgp_unlock_node (rn);
13862 }
13863 else
13864 {
13865 bdistance = bgp_distance_new ();
13866 rn->info = bdistance;
13867 }
13868
13869 /* Set distance value. */
13870 bdistance->distance = distance;
13871
13872 /* Reset access-list configuration. */
13873 if (bdistance->access_list)
13874 {
6e919709 13875 XFREE(MTYPE_AS_LIST, bdistance->access_list);
718e3744 13876 bdistance->access_list = NULL;
13877 }
13878 if (access_list_str)
6e919709 13879 bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str);
718e3744 13880
13881 return CMD_SUCCESS;
13882}
13883
94f2b392 13884static int
fd79ac91 13885bgp_distance_unset (struct vty *vty, const char *distance_str,
13886 const char *ip_str, const char *access_list_str)
718e3744 13887{
13888 int ret;
1f9a9fff 13889 int distance;
718e3744 13890 struct prefix_ipv4 p;
718e3744 13891 struct bgp_node *rn;
13892 struct bgp_distance *bdistance;
13893
13894 ret = str2prefix_ipv4 (ip_str, &p);
13895 if (ret == 0)
13896 {
13897 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13898 return CMD_WARNING;
13899 }
13900
718e3744 13901 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
13902 if (! rn)
13903 {
13904 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
13905 return CMD_WARNING;
13906 }
13907
13908 bdistance = rn->info;
1f9a9fff
PJ
13909 distance = atoi(distance_str);
13910
13911 if (bdistance->distance != distance)
13912 {
13913 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
13914 return CMD_WARNING;
13915 }
718e3744 13916
13917 if (bdistance->access_list)
6e919709 13918 XFREE(MTYPE_AS_LIST, bdistance->access_list);
718e3744 13919 bgp_distance_free (bdistance);
13920
13921 rn->info = NULL;
13922 bgp_unlock_node (rn);
13923 bgp_unlock_node (rn);
13924
13925 return CMD_SUCCESS;
13926}
13927
718e3744 13928/* Apply BGP information to distance method. */
13929u_char
13930bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
13931{
13932 struct bgp_node *rn;
13933 struct prefix_ipv4 q;
13934 struct peer *peer;
13935 struct bgp_distance *bdistance;
13936 struct access_list *alist;
13937 struct bgp_static *bgp_static;
13938
13939 if (! bgp)
13940 return 0;
13941
13942 if (p->family != AF_INET)
13943 return 0;
13944
13945 peer = rinfo->peer;
13946
13947 if (peer->su.sa.sa_family != AF_INET)
13948 return 0;
13949
13950 memset (&q, 0, sizeof (struct prefix_ipv4));
13951 q.family = AF_INET;
13952 q.prefix = peer->su.sin.sin_addr;
13953 q.prefixlen = IPV4_MAX_BITLEN;
13954
13955 /* Check source address. */
13956 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
13957 if (rn)
13958 {
13959 bdistance = rn->info;
13960 bgp_unlock_node (rn);
13961
13962 if (bdistance->access_list)
13963 {
13964 alist = access_list_lookup (AFI_IP, bdistance->access_list);
13965 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
13966 return bdistance->distance;
13967 }
13968 else
13969 return bdistance->distance;
13970 }
13971
13972 /* Backdoor check. */
13973 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
13974 if (rn)
13975 {
13976 bgp_static = rn->info;
13977 bgp_unlock_node (rn);
13978
13979 if (bgp_static->backdoor)
13980 {
13981 if (bgp->distance_local)
13982 return bgp->distance_local;
13983 else
13984 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13985 }
13986 }
13987
6d85b15b 13988 if (peer->sort == BGP_PEER_EBGP)
718e3744 13989 {
13990 if (bgp->distance_ebgp)
13991 return bgp->distance_ebgp;
13992 return ZEBRA_EBGP_DISTANCE_DEFAULT;
13993 }
13994 else
13995 {
13996 if (bgp->distance_ibgp)
13997 return bgp->distance_ibgp;
13998 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13999 }
14000}
14001
14002DEFUN (bgp_distance,
14003 bgp_distance_cmd,
6147e2c6 14004 "distance bgp (1-255) (1-255) (1-255)",
718e3744 14005 "Define an administrative distance\n"
14006 "BGP distance\n"
14007 "Distance for routes external to the AS\n"
14008 "Distance for routes internal to the AS\n"
14009 "Distance for local routes\n")
14010{
14011 struct bgp *bgp;
14012
14013 bgp = vty->index;
14014
4dcadbef
DW
14015 bgp->distance_ebgp = atoi (argv[2]->arg);
14016 bgp->distance_ibgp = atoi (argv[3]->arg);
14017 bgp->distance_local = atoi (argv[4]->arg);
718e3744 14018 return CMD_SUCCESS;
14019}
14020
f412b39a
DW
14021/*
14022 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
14023 * "no distance bgp",
14024 * NO_STR
14025 * "Define an administrative distance\n"
14026 * "BGP distance\n"
14027 *
14028 */
718e3744 14029DEFUN (no_bgp_distance,
14030 no_bgp_distance_cmd,
6147e2c6 14031 "no distance bgp (1-255) (1-255) (1-255)",
718e3744 14032 NO_STR
14033 "Define an administrative distance\n"
14034 "BGP distance\n"
14035 "Distance for routes external to the AS\n"
14036 "Distance for routes internal to the AS\n"
14037 "Distance for local routes\n")
14038{
14039 struct bgp *bgp;
14040
14041 bgp = vty->index;
14042
14043 bgp->distance_ebgp= 0;
14044 bgp->distance_ibgp = 0;
14045 bgp->distance_local = 0;
14046 return CMD_SUCCESS;
14047}
14048
718e3744 14049
14050DEFUN (bgp_distance_source,
14051 bgp_distance_source_cmd,
6147e2c6 14052 "distance (1-255) A.B.C.D/M",
718e3744 14053 "Define an administrative distance\n"
14054 "Administrative distance\n"
14055 "IP source prefix\n")
14056{
4dcadbef 14057 bgp_distance_set (vty, argv[1]->arg, argv[2]->arg, NULL);
718e3744 14058 return CMD_SUCCESS;
14059}
14060
14061DEFUN (no_bgp_distance_source,
14062 no_bgp_distance_source_cmd,
6147e2c6 14063 "no distance (1-255) A.B.C.D/M",
718e3744 14064 NO_STR
14065 "Define an administrative distance\n"
14066 "Administrative distance\n"
14067 "IP source prefix\n")
14068{
4dcadbef 14069 bgp_distance_unset (vty, argv[2]->arg, argv[3]->arg, NULL);
718e3744 14070 return CMD_SUCCESS;
14071}
14072
14073DEFUN (bgp_distance_source_access_list,
14074 bgp_distance_source_access_list_cmd,
6147e2c6 14075 "distance (1-255) A.B.C.D/M WORD",
718e3744 14076 "Define an administrative distance\n"
14077 "Administrative distance\n"
14078 "IP source prefix\n"
14079 "Access list name\n")
14080{
4dcadbef 14081 bgp_distance_set (vty, argv[1]->arg, argv[2]->arg, argv[3]->arg);
718e3744 14082 return CMD_SUCCESS;
14083}
14084
14085DEFUN (no_bgp_distance_source_access_list,
14086 no_bgp_distance_source_access_list_cmd,
6147e2c6 14087 "no distance (1-255) A.B.C.D/M WORD",
718e3744 14088 NO_STR
14089 "Define an administrative distance\n"
14090 "Administrative distance\n"
14091 "IP source prefix\n"
14092 "Access list name\n")
14093{
4dcadbef 14094 bgp_distance_unset (vty, argv[2]->arg, argv[3]->arg, argv[4]->arg);
718e3744 14095 return CMD_SUCCESS;
14096}
6b0655a2 14097
f412b39a
DW
14098/*
14099 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
14100 * "bgp dampening",
14101 * "BGP Specific commands\n"
14102 * "Enable route-flap dampening\n"
14103 *
14104 * "bgp dampening <1-45>",
14105 * "BGP Specific commands\n"
14106 * "Enable route-flap dampening\n"
14107 * "Half-life time for the penalty\n"
14108 *
14109 */
718e3744 14110DEFUN (bgp_damp_set,
14111 bgp_damp_set_cmd,
6147e2c6 14112 "bgp dampening (1-45) (1-20000) (1-20000) (1-255)",
718e3744 14113 "BGP Specific commands\n"
14114 "Enable route-flap dampening\n"
14115 "Half-life time for the penalty\n"
14116 "Value to start reusing a route\n"
14117 "Value to start suppressing a route\n"
14118 "Maximum duration to suppress a stable route\n")
14119{
14120 struct bgp *bgp;
14121 int half = DEFAULT_HALF_LIFE * 60;
14122 int reuse = DEFAULT_REUSE;
14123 int suppress = DEFAULT_SUPPRESS;
14124 int max = 4 * half;
14125
14126 if (argc == 4)
14127 {
4dcadbef
DW
14128 half = atoi (argv[2]->arg) * 60;
14129 reuse = atoi (argv[3]->arg);
14130 suppress = atoi (argv[4]->arg);
14131 max = atoi (argv[5]->arg) * 60;
718e3744 14132 }
14133 else if (argc == 1)
14134 {
4dcadbef 14135 half = atoi (argv[2]->arg) * 60;
718e3744 14136 max = 4 * half;
14137 }
14138
14139 bgp = vty->index;
7ebe9748
B
14140
14141 if (suppress < reuse)
14142 {
14143 vty_out (vty, "Suppress value cannot be less than reuse value %s",
14144 VTY_NEWLINE);
14145 return 0;
14146 }
14147
718e3744 14148 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
14149 half, reuse, suppress, max);
14150}
14151
718e3744 14152
718e3744 14153
f412b39a
DW
14154/*
14155 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
14156 * "no bgp dampening <1-45>",
14157 * NO_STR
14158 * "BGP Specific commands\n"
14159 * "Enable route-flap dampening\n"
14160 * "Half-life time for the penalty\n"
14161 *
14162 * "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14163 * NO_STR
14164 * "BGP Specific commands\n"
14165 * "Enable route-flap dampening\n"
14166 * "Half-life time for the penalty\n"
14167 * "Value to start reusing a route\n"
14168 * "Value to start suppressing a route\n"
14169 * "Maximum duration to suppress a stable route\n"
14170 *
14171 */
718e3744 14172DEFUN (bgp_damp_unset,
14173 bgp_damp_unset_cmd,
14174 "no bgp dampening",
14175 NO_STR
14176 "BGP Specific commands\n"
14177 "Enable route-flap dampening\n")
14178{
14179 struct bgp *bgp;
14180
14181 bgp = vty->index;
14182 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
14183}
14184
718e3744 14185
813d4307 14186
f412b39a
DW
14187/*
14188 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
14189 * "show ip bgp dampening dampened-paths",
14190 * SHOW_STR
14191 * IP_STR
14192 * BGP_STR
14193 * "Display detailed information about dampening\n"
14194 * "Display paths suppressed due to dampening\n"
14195 *
14196 */
718e3744 14197DEFUN (show_ip_bgp_dampened_paths,
14198 show_ip_bgp_dampened_paths_cmd,
14199 "show ip bgp dampened-paths",
14200 SHOW_STR
14201 IP_STR
14202 BGP_STR
14203 "Display paths suppressed due to dampening\n")
14204{
5a646650 14205 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
b05a1c8b 14206 NULL, 0);
718e3744 14207}
14208
81304aaf 14209
f412b39a
DW
14210/*
14211 * CHECK ME - The following ALIASes need to be implemented in this DEFUN
14212 * "show ip bgp dampening flap-statistics",
14213 * SHOW_STR
14214 * IP_STR
14215 * BGP_STR
14216 * "Display detailed information about dampening\n"
14217 * "Display flap statistics of routes\n"
14218 *
14219 */
718e3744 14220DEFUN (show_ip_bgp_flap_statistics,
14221 show_ip_bgp_flap_statistics_cmd,
14222 "show ip bgp flap-statistics",
14223 SHOW_STR
14224 IP_STR
14225 BGP_STR
14226 "Display flap statistics of routes\n")
14227{
5a646650 14228 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 14229 bgp_show_type_flap_statistics, NULL, 0);
718e3744 14230}
6b0655a2 14231
81304aaf 14232
718e3744 14233/* Display specified route of BGP table. */
94f2b392 14234static int
fd79ac91 14235bgp_clear_damp_route (struct vty *vty, const char *view_name,
14236 const char *ip_str, afi_t afi, safi_t safi,
14237 struct prefix_rd *prd, int prefix_check)
718e3744 14238{
14239 int ret;
14240 struct prefix match;
14241 struct bgp_node *rn;
14242 struct bgp_node *rm;
14243 struct bgp_info *ri;
14244 struct bgp_info *ri_temp;
14245 struct bgp *bgp;
14246 struct bgp_table *table;
14247
14248 /* BGP structure lookup. */
14249 if (view_name)
14250 {
14251 bgp = bgp_lookup_by_name (view_name);
14252 if (bgp == NULL)
14253 {
6aeb9e78 14254 vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
718e3744 14255 return CMD_WARNING;
14256 }
14257 }
14258 else
14259 {
14260 bgp = bgp_get_default ();
14261 if (bgp == NULL)
14262 {
14263 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
14264 return CMD_WARNING;
14265 }
14266 }
14267
14268 /* Check IP address argument. */
14269 ret = str2prefix (ip_str, &match);
14270 if (! ret)
14271 {
14272 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
14273 return CMD_WARNING;
14274 }
14275
14276 match.family = afi2family (afi);
14277
587ff0fd 14278 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
718e3744 14279 {
587ff0fd 14280 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
718e3744 14281 {
14282 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
14283 continue;
14284
14285 if ((table = rn->info) != NULL)
14286 if ((rm = bgp_node_match (table, &match)) != NULL)
6c88b44d
CC
14287 {
14288 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
14289 {
14290 ri = rm->info;
14291 while (ri)
14292 {
14293 if (ri->extra && ri->extra->damp_info)
14294 {
14295 ri_temp = ri->next;
14296 bgp_damp_info_free (ri->extra->damp_info, 1);
14297 ri = ri_temp;
14298 }
14299 else
14300 ri = ri->next;
14301 }
14302 }
14303
14304 bgp_unlock_node (rm);
14305 }
718e3744 14306 }
14307 }
14308 else
14309 {
14310 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
6c88b44d
CC
14311 {
14312 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
14313 {
14314 ri = rn->info;
14315 while (ri)
14316 {
14317 if (ri->extra && ri->extra->damp_info)
14318 {
14319 ri_temp = ri->next;
14320 bgp_damp_info_free (ri->extra->damp_info, 1);
14321 ri = ri_temp;
14322 }
14323 else
14324 ri = ri->next;
14325 }
14326 }
14327
14328 bgp_unlock_node (rn);
14329 }
718e3744 14330 }
14331
14332 return CMD_SUCCESS;
14333}
14334
14335DEFUN (clear_ip_bgp_dampening,
14336 clear_ip_bgp_dampening_cmd,
14337 "clear ip bgp dampening",
14338 CLEAR_STR
14339 IP_STR
14340 BGP_STR
14341 "Clear route flap dampening information\n")
14342{
14343 bgp_damp_info_clean ();
14344 return CMD_SUCCESS;
14345}
14346
14347DEFUN (clear_ip_bgp_dampening_prefix,
14348 clear_ip_bgp_dampening_prefix_cmd,
14349 "clear ip bgp dampening A.B.C.D/M",
14350 CLEAR_STR
14351 IP_STR
14352 BGP_STR
14353 "Clear route flap dampening information\n"
14354 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14355{
4dcadbef 14356 return bgp_clear_damp_route (vty, NULL, argv[4]->arg, AFI_IP,
718e3744 14357 SAFI_UNICAST, NULL, 1);
14358}
14359
14360DEFUN (clear_ip_bgp_dampening_address,
14361 clear_ip_bgp_dampening_address_cmd,
14362 "clear ip bgp dampening A.B.C.D",
14363 CLEAR_STR
14364 IP_STR
14365 BGP_STR
14366 "Clear route flap dampening information\n"
14367 "Network to clear damping information\n")
14368{
4dcadbef 14369 return bgp_clear_damp_route (vty, NULL, argv[4]->arg, AFI_IP,
718e3744 14370 SAFI_UNICAST, NULL, 0);
14371}
14372
14373DEFUN (clear_ip_bgp_dampening_address_mask,
14374 clear_ip_bgp_dampening_address_mask_cmd,
14375 "clear ip bgp dampening A.B.C.D A.B.C.D",
14376 CLEAR_STR
14377 IP_STR
14378 BGP_STR
14379 "Clear route flap dampening information\n"
14380 "Network to clear damping information\n"
14381 "Network mask\n")
14382{
14383 int ret;
14384 char prefix_str[BUFSIZ];
14385
4dcadbef 14386 ret = netmask_str2prefix_str (argv[4]->arg, argv[5]->arg, prefix_str);
718e3744 14387 if (! ret)
14388 {
14389 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
14390 return CMD_WARNING;
14391 }
14392
14393 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
14394 SAFI_UNICAST, NULL, 0);
14395}
6b0655a2 14396
587ff0fd 14397/* also used for encap safi */
94f2b392 14398static int
718e3744 14399bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
14400 afi_t afi, safi_t safi, int *write)
14401{
14402 struct bgp_node *prn;
14403 struct bgp_node *rn;
14404 struct bgp_table *table;
14405 struct prefix *p;
14406 struct prefix_rd *prd;
14407 struct bgp_static *bgp_static;
14408 u_int32_t label;
14409 char buf[SU_ADDRSTRLEN];
14410 char rdbuf[RD_ADDRSTRLEN];
14411
14412 /* Network configuration. */
14413 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
14414 if ((table = prn->info) != NULL)
14415 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
14416 if ((bgp_static = rn->info) != NULL)
14417 {
14418 p = &rn->p;
14419 prd = (struct prefix_rd *) &prn->p;
14420
14421 /* "address-family" display. */
14422 bgp_config_write_family_header (vty, afi, safi, write);
14423
14424 /* "network" configuration display. */
14425 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
14426 label = decode_label (bgp_static->tag);
14427
0b960b4d 14428 vty_out (vty, " network %s/%d rd %s tag %d",
718e3744 14429 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14430 p->prefixlen,
14431 rdbuf, label);
14432 vty_out (vty, "%s", VTY_NEWLINE);
14433 }
14434 return 0;
14435}
14436
14437/* Configuration of static route announcement and aggregate
14438 information. */
14439int
14440bgp_config_write_network (struct vty *vty, struct bgp *bgp,
14441 afi_t afi, safi_t safi, int *write)
14442{
14443 struct bgp_node *rn;
14444 struct prefix *p;
14445 struct bgp_static *bgp_static;
14446 struct bgp_aggregate *bgp_aggregate;
14447 char buf[SU_ADDRSTRLEN];
14448
587ff0fd 14449 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
718e3744 14450 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
14451
14452 /* Network configuration. */
14453 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
14454 if ((bgp_static = rn->info) != NULL)
14455 {
14456 p = &rn->p;
14457
14458 /* "address-family" display. */
14459 bgp_config_write_family_header (vty, afi, safi, write);
14460
14461 /* "network" configuration display. */
14462 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14463 {
14464 u_int32_t destination;
14465 struct in_addr netmask;
14466
14467 destination = ntohl (p->u.prefix4.s_addr);
14468 masklen2ip (p->prefixlen, &netmask);
0b960b4d 14469 vty_out (vty, " network %s",
718e3744 14470 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
14471
14472 if ((IN_CLASSC (destination) && p->prefixlen == 24)
14473 || (IN_CLASSB (destination) && p->prefixlen == 16)
14474 || (IN_CLASSA (destination) && p->prefixlen == 8)
14475 || p->u.prefix4.s_addr == 0)
14476 {
14477 /* Natural mask is not display. */
14478 }
14479 else
14480 vty_out (vty, " mask %s", inet_ntoa (netmask));
14481 }
14482 else
14483 {
0b960b4d 14484 vty_out (vty, " network %s/%d",
718e3744 14485 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14486 p->prefixlen);
14487 }
14488
14489 if (bgp_static->rmap.name)
14490 vty_out (vty, " route-map %s", bgp_static->rmap.name);
41367172
PJ
14491 else
14492 {
14493 if (bgp_static->backdoor)
14494 vty_out (vty, " backdoor");
41367172 14495 }
718e3744 14496
14497 vty_out (vty, "%s", VTY_NEWLINE);
14498 }
14499
14500 /* Aggregate-address configuration. */
14501 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
14502 if ((bgp_aggregate = rn->info) != NULL)
14503 {
14504 p = &rn->p;
14505
14506 /* "address-family" display. */
14507 bgp_config_write_family_header (vty, afi, safi, write);
14508
14509 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14510 {
14511 struct in_addr netmask;
14512
14513 masklen2ip (p->prefixlen, &netmask);
0b960b4d 14514 vty_out (vty, " aggregate-address %s %s",
718e3744 14515 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14516 inet_ntoa (netmask));
14517 }
14518 else
14519 {
0b960b4d 14520 vty_out (vty, " aggregate-address %s/%d",
718e3744 14521 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14522 p->prefixlen);
14523 }
14524
14525 if (bgp_aggregate->as_set)
14526 vty_out (vty, " as-set");
14527
14528 if (bgp_aggregate->summary_only)
14529 vty_out (vty, " summary-only");
14530
14531 vty_out (vty, "%s", VTY_NEWLINE);
14532 }
14533
14534 return 0;
14535}
14536
14537int
14538bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
14539{
14540 struct bgp_node *rn;
14541 struct bgp_distance *bdistance;
14542
14543 /* Distance configuration. */
14544 if (bgp->distance_ebgp
14545 && bgp->distance_ibgp
14546 && bgp->distance_local
14547 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
14548 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
14549 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
14550 vty_out (vty, " distance bgp %d %d %d%s",
14551 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
14552 VTY_NEWLINE);
14553
14554 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
14555 if ((bdistance = rn->info) != NULL)
14556 {
14557 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
14558 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
14559 bdistance->access_list ? bdistance->access_list : "",
14560 VTY_NEWLINE);
14561 }
14562
14563 return 0;
14564}
14565
14566/* Allocate routing table structure and install commands. */
14567void
66e5cd87 14568bgp_route_init (void)
718e3744 14569{
14570 /* Init BGP distance table. */
64e580a7 14571 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
718e3744 14572
14573 /* IPv4 BGP commands. */
73ac8160 14574 install_element (BGP_NODE, &bgp_table_map_cmd);
718e3744 14575 install_element (BGP_NODE, &bgp_network_cmd);
14576 install_element (BGP_NODE, &bgp_network_mask_cmd);
14577 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
14578 install_element (BGP_NODE, &bgp_network_route_map_cmd);
14579 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
14580 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
14581 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
14582 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
14583 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
73ac8160 14584 install_element (BGP_NODE, &no_bgp_table_map_cmd);
718e3744 14585 install_element (BGP_NODE, &no_bgp_network_cmd);
14586 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
14587 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
718e3744 14588
14589 install_element (BGP_NODE, &aggregate_address_cmd);
14590 install_element (BGP_NODE, &aggregate_address_mask_cmd);
14591 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
14592 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
14593 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
14594 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
14595 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
14596 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
718e3744 14597 install_element (BGP_NODE, &no_aggregate_address_cmd);
718e3744 14598 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
718e3744 14599
14600 /* IPv4 unicast configuration. */
73ac8160 14601 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
718e3744 14602 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
14603 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
14604 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
14605 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
14606 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
14607 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 14608 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
c8f3fe30 14609 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
718e3744 14610 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
14611 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
c8f3fe30 14612
718e3744 14613 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
14614 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
14615 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
14616 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
14617 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
14618 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
14619 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
14620 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
718e3744 14621 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
718e3744 14622 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
718e3744 14623
14624 /* IPv4 multicast configuration. */
73ac8160 14625 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
718e3744 14626 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
14627 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
14628 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
14629 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
14630 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
14631 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 14632 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
718e3744 14633 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
14634 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
14635 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
718e3744 14636 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
14637 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
14638 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
14639 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
14640 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
14641 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
14642 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
14643 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
718e3744 14644 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
718e3744 14645 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
718e3744 14646
14647 install_element (VIEW_NODE, &show_ip_bgp_cmd);
8386ac43 14648 install_element (VIEW_NODE, &show_ip_bgp_instance_cmd);
f186de26 14649 install_element (VIEW_NODE, &show_ip_bgp_instance_all_cmd);
718e3744 14650 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
14651 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
8386ac43 14652 install_element (VIEW_NODE, &show_ip_bgp_instance_route_cmd);
4092b06c 14653 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
8386ac43 14654 install_element (VIEW_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
4092b06c 14655 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 14656 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
14657 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14658 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14659 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
8386ac43 14660 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd);
718e3744 14661 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c 14662 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
4092b06c 14663 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
8386ac43 14664 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
718e3744 14665 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14666 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
50ef26d4 14667
718e3744 14668 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
14669 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14670 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
8386ac43 14671 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_list_cmd);
718e3744 14672 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14673 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
8386ac43 14674 install_element (VIEW_NODE, &show_ip_bgp_instance_filter_list_cmd);
718e3744 14675 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14676 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
8386ac43 14677 install_element (VIEW_NODE, &show_ip_bgp_instance_route_map_cmd);
718e3744 14678 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14679 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
14680 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14681 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
14682 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14683 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
718e3744 14684 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
8386ac43 14685 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14686 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_cmd);
718e3744 14687 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
718e3744 14688 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
718e3744 14689 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
8386ac43 14690 install_element (VIEW_NODE, &show_ip_bgp_instance_community_list_cmd);
718e3744 14691 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14692 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
14693 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14694 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
8386ac43 14695 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
718e3744 14696 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14697 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
8386ac43 14698 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
718e3744 14699 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
14700 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
8386ac43 14701 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
718e3744 14702 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
8386ac43 14703 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 14704 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
8386ac43 14705 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
718e3744 14706 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14707 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14708 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
81304aaf 14709 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
58a90275 14710 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
718e3744 14711 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
58a90275
B
14712 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
14713 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
718e3744 14714 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
14715 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
14716 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
14717 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14718 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
14719 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
14720 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14721 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14722 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
14723 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
14724 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
62687ff1
PJ
14725
14726 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
14727 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
8386ac43 14728 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_cmd);
4092b06c 14729 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
8386ac43 14730 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
4092b06c 14731 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
62687ff1
PJ
14732 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
14733 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14734 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
8386ac43 14735 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_cmd);
62687ff1 14736 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c 14737 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
4092b06c 14738 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
8386ac43 14739 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
62687ff1
PJ
14740 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14741 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
8386ac43 14742 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_cmd);
14743 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_cmd);
62687ff1 14744 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
62687ff1 14745 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
8386ac43 14746 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14747 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community_cmd);
62687ff1 14748 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
62687ff1 14749 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
718e3744 14750
14751 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
8386ac43 14752 install_element (ENABLE_NODE, &show_ip_bgp_instance_cmd);
f186de26 14753 install_element (ENABLE_NODE, &show_ip_bgp_instance_all_cmd);
718e3744 14754 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
14755 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
8386ac43 14756 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_cmd);
4092b06c 14757 install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd);
8386ac43 14758 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
4092b06c 14759 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 14760 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
14761 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14762 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14763 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
8386ac43 14764 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_cmd);
718e3744 14765 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c 14766 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
4092b06c 14767 install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd);
8386ac43 14768 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
718e3744 14769 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14770 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
50ef26d4 14771
718e3744 14772 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
14773 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14774 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
8386ac43 14775 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_list_cmd);
718e3744 14776 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14777 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
8386ac43 14778 install_element (ENABLE_NODE, &show_ip_bgp_instance_filter_list_cmd);
718e3744 14779 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14780 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
8386ac43 14781 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_map_cmd);
718e3744 14782 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14783 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
14784 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14785 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
14786 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14787 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
718e3744 14788 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
8386ac43 14789 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14790 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community_cmd);
718e3744 14791 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
718e3744 14792 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
718e3744 14793 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
8386ac43 14794 install_element (ENABLE_NODE, &show_ip_bgp_instance_community_list_cmd);
718e3744 14795 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14796 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
14797 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14798 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
8386ac43 14799 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
718e3744 14800 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14801 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
8386ac43 14802 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
718e3744 14803 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
14804 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
8386ac43 14805 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
718e3744 14806 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
8386ac43 14807 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 14808 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
8386ac43 14809 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
718e3744 14810 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14811 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14812 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
81304aaf 14813 install_element (ENABLE_NODE, &show_ip_bgp_dampening_params_cmd);
718e3744 14814 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
58a90275
B
14815 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
14816 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
14817 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
718e3744 14818 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
14819 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
14820 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
14821 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14822 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
14823 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
14824 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14825 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14826 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
14827 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
14828 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
14829
e3e29b32
LB
14830 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
14831 install_element (ENABLE_NODE, &show_bgp_ipv4_prefix_cmd);
14832 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
14833 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
14834 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_route_cmd);
14835 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_route_cmd);
14836
14837 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
14838 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
14839 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_route_cmd);
14840 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_route_cmd);
14841
718e3744 14842 /* BGP dampening clear commands */
14843 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
14844 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
14845 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
14846 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
14847
ff7924f6
PJ
14848 /* prefix count */
14849 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
8386ac43 14850 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd);
ff7924f6
PJ
14851 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
14852 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
718e3744 14853#ifdef HAVE_IPV6
ff7924f6 14854 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
8386ac43 14855 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd);
ff7924f6 14856
718e3744 14857 /* New config IPv6 BGP commands. */
73ac8160 14858 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
718e3744 14859 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
14860 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
73ac8160 14861 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
718e3744 14862 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
718e3744 14863
14864 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
14865 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
14866 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
14867 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
73bfe0bd
B
14868
14869 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
14870 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
718e3744 14871
14872 /* Old config IPv6 BGP commands. */
718e3744 14873
718e3744 14874
14875 install_element (VIEW_NODE, &show_bgp_cmd);
95cbbd2a 14876 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 14877 install_element (VIEW_NODE, &show_bgp_route_cmd);
14878 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 14879 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c 14880 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
4092b06c 14881 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 14882 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
14883 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 14884 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c 14885 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
4092b06c 14886 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 14887 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
718e3744 14888 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
718e3744 14889 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
718e3744 14890 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
718e3744 14891 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
718e3744 14892 install_element (VIEW_NODE, &show_bgp_community_cmd);
718e3744 14893 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
718e3744 14894 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
718e3744 14895 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
718e3744 14896 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
718e3744 14897 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
718e3744 14898 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
718e3744 14899 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
718e3744 14900 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
8386ac43 14901 install_element (VIEW_NODE, &show_bgp_instance_cmd);
f186de26 14902 install_element (VIEW_NODE, &show_bgp_instance_all_cmd);
8386ac43 14903 install_element (VIEW_NODE, &show_bgp_instance_route_cmd);
8386ac43 14904 install_element (VIEW_NODE, &show_bgp_instance_route_pathtype_cmd);
8386ac43 14905 install_element (VIEW_NODE, &show_bgp_instance_prefix_cmd);
8386ac43 14906 install_element (VIEW_NODE, &show_bgp_instance_prefix_pathtype_cmd);
8386ac43 14907 install_element (VIEW_NODE, &show_bgp_instance_prefix_list_cmd);
8386ac43 14908 install_element (VIEW_NODE, &show_bgp_instance_filter_list_cmd);
8386ac43 14909 install_element (VIEW_NODE, &show_bgp_instance_route_map_cmd);
8386ac43 14910 install_element (VIEW_NODE, &show_bgp_instance_community_list_cmd);
8386ac43 14911 install_element (VIEW_NODE, &show_bgp_instance_prefix_longer_cmd);
8386ac43 14912 install_element (VIEW_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
8386ac43 14913 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
8386ac43 14914 install_element (VIEW_NODE, &show_bgp_instance_neighbor_routes_cmd);
8386ac43 14915 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
8386ac43 14916 install_element (VIEW_NODE, &show_bgp_instance_neighbor_flap_cmd);
8386ac43 14917 install_element (VIEW_NODE, &show_bgp_instance_neighbor_damp_cmd);
62687ff1
PJ
14918
14919 /* Restricted:
14920 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
14921 */
14922 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
14923 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 14924 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c 14925 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
4092b06c 14926 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
62687ff1
PJ
14927 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
14928 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 14929 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c 14930 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
4092b06c 14931 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
62687ff1 14932 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
62687ff1 14933 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
8386ac43 14934 install_element (RESTRICTED_NODE, &show_bgp_instance_route_cmd);
8386ac43 14935 install_element (RESTRICTED_NODE, &show_bgp_instance_route_pathtype_cmd);
8386ac43 14936 install_element (RESTRICTED_NODE, &show_bgp_instance_prefix_cmd);
8386ac43 14937 install_element (RESTRICTED_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
718e3744 14938
14939 install_element (ENABLE_NODE, &show_bgp_cmd);
95cbbd2a 14940 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 14941 install_element (ENABLE_NODE, &show_bgp_route_cmd);
14942 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 14943 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c 14944 install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd);
4092b06c 14945 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 14946 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
4092b06c 14947 install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd);
4092b06c 14948 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 14949 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 14950 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
718e3744 14951 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
718e3744 14952 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
718e3744 14953 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
718e3744 14954 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
718e3744 14955 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
718e3744 14956 install_element (ENABLE_NODE, &show_bgp_community_cmd);
718e3744 14957 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
718e3744 14958 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
718e3744 14959 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
718e3744 14960 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
718e3744 14961 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
718e3744 14962 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
718e3744 14963 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
718e3744 14964 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
8386ac43 14965 install_element (ENABLE_NODE, &show_bgp_instance_cmd);
f186de26 14966 install_element (ENABLE_NODE, &show_bgp_instance_all_cmd);
8386ac43 14967 install_element (ENABLE_NODE, &show_bgp_instance_route_cmd);
8386ac43 14968 install_element (ENABLE_NODE, &show_bgp_instance_route_pathtype_cmd);
8386ac43 14969 install_element (ENABLE_NODE, &show_bgp_instance_prefix_cmd);
8386ac43 14970 install_element (ENABLE_NODE, &show_bgp_instance_prefix_pathtype_cmd);
8386ac43 14971 install_element (ENABLE_NODE, &show_bgp_instance_prefix_list_cmd);
8386ac43 14972 install_element (ENABLE_NODE, &show_bgp_instance_filter_list_cmd);
8386ac43 14973 install_element (ENABLE_NODE, &show_bgp_instance_route_map_cmd);
8386ac43 14974 install_element (ENABLE_NODE, &show_bgp_instance_community_list_cmd);
8386ac43 14975 install_element (ENABLE_NODE, &show_bgp_instance_prefix_longer_cmd);
8386ac43 14976 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
8386ac43 14977 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
8386ac43 14978 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_routes_cmd);
8386ac43 14979 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
8386ac43 14980 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_flap_cmd);
8386ac43 14981 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_damp_cmd);
50ef26d4 14982
2815e61f
PJ
14983 /* Statistics */
14984 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
587ff0fd 14985 //install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
2815e61f 14986 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
587ff0fd 14987 //install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
2815e61f 14988
718e3744 14989 /* old command */
14990 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
14991 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
14992 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
14993 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
14994 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
14995 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
14996 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
14997 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
718e3744 14998 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
718e3744 14999 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
15000 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15001 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15002 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
15003 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
15004 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
15005 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
15006 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15007 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
15008 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
15009 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
718e3744 15010 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
718e3744 15011 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
15012 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15013 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
bb46e94f 15014
718e3744 15015 /* old command */
15016 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
15017 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
15018 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
15019 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
15020 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
15021 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
15022 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
15023 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
718e3744 15024 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
718e3744 15025 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
15026 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15027 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15028 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
15029 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
15030 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
15031 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
15032 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15033 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
15034 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
15035 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
718e3744 15036 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
718e3744 15037 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
15038 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15039 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
15040
15041 /* old command */
718e3744 15042 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
15043 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
15044
15045 /* old command */
718e3744 15046 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
15047 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
15048
15049 /* old command */
718e3744 15050 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
15051 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
15052#endif /* HAVE_IPV6 */
15053
15054 install_element (BGP_NODE, &bgp_distance_cmd);
15055 install_element (BGP_NODE, &no_bgp_distance_cmd);
718e3744 15056 install_element (BGP_NODE, &bgp_distance_source_cmd);
15057 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
15058 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
15059 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
15060
15061 install_element (BGP_NODE, &bgp_damp_set_cmd);
718e3744 15062 install_element (BGP_NODE, &bgp_damp_unset_cmd);
718e3744 15063 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
718e3744 15064 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
5c9e5a8d
B
15065
15066 /* IPv4 Multicast Mode */
15067 install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd);
5c9e5a8d 15068 install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
718e3744 15069}
228da428
CC
15070
15071void
15072bgp_route_finish (void)
15073{
15074 bgp_table_unlock (bgp_distance_table);
15075 bgp_distance_table = NULL;
15076}