]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_route.c
Use #define for mp_nexthop_len values
[mirror_frr.git] / bgpd / bgp_route.c
CommitLineData
718e3744 1/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
b05a1c8b 22#include <json/json.h>
718e3744 23
24#include "prefix.h"
25#include "linklist.h"
26#include "memory.h"
27#include "command.h"
28#include "stream.h"
29#include "filter.h"
30#include "str.h"
31#include "log.h"
32#include "routemap.h"
33#include "buffer.h"
34#include "sockunion.h"
35#include "plist.h"
36#include "thread.h"
200df115 37#include "workqueue.h"
3f9c7369 38#include "queue.h"
718e3744 39
40#include "bgpd/bgpd.h"
41#include "bgpd/bgp_table.h"
42#include "bgpd/bgp_route.h"
43#include "bgpd/bgp_attr.h"
44#include "bgpd/bgp_debug.h"
45#include "bgpd/bgp_aspath.h"
46#include "bgpd/bgp_regex.h"
47#include "bgpd/bgp_community.h"
48#include "bgpd/bgp_ecommunity.h"
49#include "bgpd/bgp_clist.h"
50#include "bgpd/bgp_packet.h"
51#include "bgpd/bgp_filter.h"
52#include "bgpd/bgp_fsm.h"
53#include "bgpd/bgp_mplsvpn.h"
54#include "bgpd/bgp_nexthop.h"
55#include "bgpd/bgp_damp.h"
56#include "bgpd/bgp_advertise.h"
57#include "bgpd/bgp_zebra.h"
0a486e5f 58#include "bgpd/bgp_vty.h"
96450faf 59#include "bgpd/bgp_mpath.h"
fc9a856f 60#include "bgpd/bgp_nht.h"
3f9c7369 61#include "bgpd/bgp_updgrp.h"
718e3744 62
63/* Extern from bgp_dump.c */
dde72586
SH
64extern const char *bgp_origin_str[];
65extern const char *bgp_origin_long_str[];
6b0655a2 66
94f2b392 67static struct bgp_node *
fee0f4c6 68bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
718e3744 69 struct prefix_rd *prd)
70{
71 struct bgp_node *rn;
72 struct bgp_node *prn = NULL;
da5b30f6
PJ
73
74 assert (table);
75 if (!table)
76 return NULL;
77
718e3744 78 if (safi == SAFI_MPLS_VPN)
79 {
fee0f4c6 80 prn = bgp_node_get (table, (struct prefix *) prd);
718e3744 81
82 if (prn->info == NULL)
64e580a7 83 prn->info = bgp_table_init (afi, safi);
718e3744 84 else
85 bgp_unlock_node (prn);
86 table = prn->info;
87 }
718e3744 88
89 rn = bgp_node_get (table, p);
90
91 if (safi == SAFI_MPLS_VPN)
92 rn->prn = prn;
93
94 return rn;
95}
6b0655a2 96
fb982c25
PJ
97/* Allocate bgp_info_extra */
98static struct bgp_info_extra *
99bgp_info_extra_new (void)
100{
101 struct bgp_info_extra *new;
102 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
103 return new;
104}
105
106static void
107bgp_info_extra_free (struct bgp_info_extra **extra)
108{
109 if (extra && *extra)
110 {
111 if ((*extra)->damp_info)
112 bgp_damp_info_free ((*extra)->damp_info, 0);
113
114 (*extra)->damp_info = NULL;
115
116 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
117
118 *extra = NULL;
119 }
120}
121
122/* Get bgp_info extra information for the given bgp_info, lazy allocated
123 * if required.
124 */
125struct bgp_info_extra *
126bgp_info_extra_get (struct bgp_info *ri)
127{
128 if (!ri->extra)
129 ri->extra = bgp_info_extra_new();
130 return ri->extra;
131}
132
718e3744 133/* Free bgp route information. */
200df115 134static void
718e3744 135bgp_info_free (struct bgp_info *binfo)
136{
137 if (binfo->attr)
f6f434b2 138 bgp_attr_unintern (&binfo->attr);
fb018d25
DS
139
140 bgp_unlink_nexthop(binfo);
fb982c25 141 bgp_info_extra_free (&binfo->extra);
de8d5dff 142 bgp_info_mpath_free (&binfo->mpath);
718e3744 143
200df115 144 peer_unlock (binfo->peer); /* bgp_info peer reference */
145
718e3744 146 XFREE (MTYPE_BGP_ROUTE, binfo);
147}
148
200df115 149struct bgp_info *
150bgp_info_lock (struct bgp_info *binfo)
151{
152 binfo->lock++;
153 return binfo;
154}
155
156struct bgp_info *
157bgp_info_unlock (struct bgp_info *binfo)
158{
159 assert (binfo && binfo->lock > 0);
160 binfo->lock--;
161
162 if (binfo->lock == 0)
163 {
164#if 0
165 zlog_debug ("%s: unlocked and freeing", __func__);
166 zlog_backtrace (LOG_DEBUG);
167#endif
168 bgp_info_free (binfo);
169 return NULL;
170 }
171
172#if 0
173 if (binfo->lock == 1)
174 {
175 zlog_debug ("%s: unlocked to 1", __func__);
176 zlog_backtrace (LOG_DEBUG);
177 }
178#endif
179
180 return binfo;
181}
182
718e3744 183void
184bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
185{
186 struct bgp_info *top;
187
188 top = rn->info;
200df115 189
718e3744 190 ri->next = rn->info;
191 ri->prev = NULL;
192 if (top)
193 top->prev = ri;
194 rn->info = ri;
200df115 195
196 bgp_info_lock (ri);
197 bgp_lock_node (rn);
198 peer_lock (ri->peer); /* bgp_info peer reference */
718e3744 199}
200
b40d939b 201/* Do the actual removal of info from RIB, for use by bgp_process
202 completion callback *only* */
203static void
204bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
718e3744 205{
206 if (ri->next)
207 ri->next->prev = ri->prev;
208 if (ri->prev)
209 ri->prev->next = ri->next;
210 else
211 rn->info = ri->next;
200df115 212
de8d5dff 213 bgp_info_mpath_dequeue (ri);
200df115 214 bgp_info_unlock (ri);
215 bgp_unlock_node (rn);
718e3744 216}
217
b40d939b 218void
219bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
220{
1a392d46
PJ
221 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
222 /* set of previous already took care of pcount */
b40d939b 223 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
224}
225
8d45210e
AS
226/* undo the effects of a previous call to bgp_info_delete; typically
227 called when a route is deleted and then quickly re-added before the
228 deletion has been processed */
229static void
230bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
231{
232 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
233 /* unset of previous already took care of pcount */
234 SET_FLAG (ri->flags, BGP_INFO_VALID);
235}
236
1a392d46
PJ
237/* Adjust pcount as required */
238static void
239bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
240{
67174041
AS
241 struct bgp_table *table;
242
243 assert (rn && bgp_node_table (rn));
6f58544d
PJ
244 assert (ri && ri->peer && ri->peer->bgp);
245
67174041
AS
246 table = bgp_node_table (rn);
247
1a392d46 248 /* Ignore 'pcount' for RS-client tables */
67174041 249 if (table->type != BGP_TABLE_MAIN
1a392d46
PJ
250 || ri->peer == ri->peer->bgp->peer_self)
251 return;
252
80e0ad24 253 if (!BGP_INFO_COUNTABLE (ri)
1a392d46
PJ
254 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
255 {
256
257 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
258
259 /* slight hack, but more robust against errors. */
67174041
AS
260 if (ri->peer->pcount[table->afi][table->safi])
261 ri->peer->pcount[table->afi][table->safi]--;
1a392d46
PJ
262 else
263 {
264 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
265 __func__, ri->peer->host);
266 zlog_backtrace (LOG_WARNING);
267 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
268 }
269 }
80e0ad24 270 else if (BGP_INFO_COUNTABLE (ri)
1a392d46
PJ
271 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
272 {
273 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
67174041 274 ri->peer->pcount[table->afi][table->safi]++;
1a392d46
PJ
275 }
276}
277
278
279/* Set/unset bgp_info flags, adjusting any other state as needed.
280 * This is here primarily to keep prefix-count in check.
281 */
282void
283bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
284{
285 SET_FLAG (ri->flags, flag);
286
80e0ad24
DS
287 /* early bath if we know it's not a flag that changes countability state */
288 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
1a392d46
PJ
289 return;
290
291 bgp_pcount_adjust (rn, ri);
292}
293
294void
295bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
296{
297 UNSET_FLAG (ri->flags, flag);
298
80e0ad24
DS
299 /* early bath if we know it's not a flag that changes countability state */
300 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
1a392d46
PJ
301 return;
302
303 bgp_pcount_adjust (rn, ri);
304}
305
718e3744 306/* Get MED value. If MED value is missing and "bgp bestpath
307 missing-as-worst" is specified, treat it as the worst value. */
94f2b392 308static u_int32_t
718e3744 309bgp_med_value (struct attr *attr, struct bgp *bgp)
310{
311 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
312 return attr->med;
313 else
314 {
315 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
3b424979 316 return BGP_MED_MAX;
718e3744 317 else
318 return 0;
319 }
320}
321
322/* Compare two bgp route entity. br is preferable then return 1. */
94f2b392 323static int
96450faf 324bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
5e242b0d 325 int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg)
718e3744 326{
8ff56318
JBD
327 struct attr *newattr, *existattr;
328 struct attr_extra *newattre, *existattre;
329 bgp_peer_sort_t new_sort;
330 bgp_peer_sort_t exist_sort;
718e3744 331 u_int32_t new_pref;
332 u_int32_t exist_pref;
333 u_int32_t new_med;
334 u_int32_t exist_med;
8ff56318
JBD
335 u_int32_t new_weight;
336 u_int32_t exist_weight;
337 uint32_t newm, existm;
718e3744 338 struct in_addr new_id;
339 struct in_addr exist_id;
340 int new_cluster;
341 int exist_cluster;
8ff56318
JBD
342 int internal_as_route;
343 int confed_as_route;
718e3744 344 int ret;
96450faf
JB
345
346 *paths_eq = 0;
718e3744 347
348 /* 0. Null check. */
349 if (new == NULL)
350 return 0;
351 if (exist == NULL)
352 return 1;
353
8ff56318
JBD
354 newattr = new->attr;
355 existattr = exist->attr;
356 newattre = newattr->extra;
357 existattre = existattr->extra;
358
718e3744 359 /* 1. Weight check. */
8ff56318
JBD
360 new_weight = exist_weight = 0;
361
362 if (newattre)
363 new_weight = newattre->weight;
364 if (existattre)
365 exist_weight = existattre->weight;
366
fb982c25 367 if (new_weight > exist_weight)
718e3744 368 return 1;
fb982c25 369 if (new_weight < exist_weight)
718e3744 370 return 0;
371
372 /* 2. Local preference check. */
8ff56318
JBD
373 new_pref = exist_pref = bgp->default_local_pref;
374
375 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
376 new_pref = newattr->local_pref;
377 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
378 exist_pref = existattr->local_pref;
718e3744 379
718e3744 380 if (new_pref > exist_pref)
381 return 1;
382 if (new_pref < exist_pref)
383 return 0;
384
8ff56318
JBD
385 /* 3. Local route check. We prefer:
386 * - BGP_ROUTE_STATIC
387 * - BGP_ROUTE_AGGREGATE
388 * - BGP_ROUTE_REDISTRIBUTE
389 */
390 if (! (new->sub_type == BGP_ROUTE_NORMAL))
391 return 1;
392 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
393 return 0;
718e3744 394
395 /* 4. AS path length check. */
396 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
397 {
8ff56318
JBD
398 int exist_hops = aspath_count_hops (existattr->aspath);
399 int exist_confeds = aspath_count_confeds (existattr->aspath);
fe69a505 400
6811845b 401 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
402 {
fe69a505 403 int aspath_hops;
404
8ff56318
JBD
405 aspath_hops = aspath_count_hops (newattr->aspath);
406 aspath_hops += aspath_count_confeds (newattr->aspath);
fe69a505 407
408 if ( aspath_hops < (exist_hops + exist_confeds))
6811845b 409 return 1;
fe69a505 410 if ( aspath_hops > (exist_hops + exist_confeds))
6811845b 411 return 0;
412 }
413 else
414 {
8ff56318 415 int newhops = aspath_count_hops (newattr->aspath);
fe69a505 416
417 if (newhops < exist_hops)
6811845b 418 return 1;
fe69a505 419 if (newhops > exist_hops)
6811845b 420 return 0;
421 }
718e3744 422 }
423
424 /* 5. Origin check. */
8ff56318 425 if (newattr->origin < existattr->origin)
718e3744 426 return 1;
8ff56318 427 if (newattr->origin > existattr->origin)
718e3744 428 return 0;
429
430 /* 6. MED check. */
8ff56318
JBD
431 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
432 && aspath_count_hops (existattr->aspath) == 0);
433 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
434 && aspath_count_confeds (existattr->aspath) > 0
435 && aspath_count_hops (newattr->aspath) == 0
436 && aspath_count_hops (existattr->aspath) == 0);
718e3744 437
438 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
439 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
440 && confed_as_route)
8ff56318
JBD
441 || aspath_cmp_left (newattr->aspath, existattr->aspath)
442 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
718e3744 443 || internal_as_route)
444 {
445 new_med = bgp_med_value (new->attr, bgp);
446 exist_med = bgp_med_value (exist->attr, bgp);
447
448 if (new_med < exist_med)
449 return 1;
450 if (new_med > exist_med)
451 return 0;
452 }
453
454 /* 7. Peer type check. */
8ff56318
JBD
455 new_sort = new->peer->sort;
456 exist_sort = exist->peer->sort;
457
458 if (new_sort == BGP_PEER_EBGP
459 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
718e3744 460 return 1;
8ff56318
JBD
461 if (exist_sort == BGP_PEER_EBGP
462 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
718e3744 463 return 0;
464
465 /* 8. IGP metric check. */
8ff56318
JBD
466 newm = existm = 0;
467
468 if (new->extra)
469 newm = new->extra->igpmetric;
470 if (exist->extra)
471 existm = exist->extra->igpmetric;
472
96450faf
JB
473 if (newm < existm)
474 ret = 1;
475 if (newm > existm)
476 ret = 0;
718e3744 477
5e242b0d
DS
478 /* 8.1. Same IGP metric. Compare the cluster list length as
479 representative of IGP hops metric. Rewrite the metric value
480 pair (newm, existm) with the cluster list length. Prefer the
481 path with smaller cluster list length. */
482 if (newm == existm)
483 {
484 if (peer_sort (new->peer) == BGP_PEER_IBGP
485 && peer_sort (exist->peer) == BGP_PEER_IBGP
486 && CHECK_FLAG (mpath_cfg->ibgp_flags,
487 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
488 {
489 newm = BGP_CLUSTER_LIST_LENGTH(new->attr);
490 existm = BGP_CLUSTER_LIST_LENGTH(exist->attr);
491 if (newm < existm)
492 ret = 1;
493 if (newm > existm)
494 ret = 0;
495 }
496 }
497
718e3744 498 /* 9. Maximum path check. */
96450faf
JB
499 if (newm == existm)
500 {
2fdd455c
PM
501 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
502 {
503
504 /*
505 * For the two paths, all comparison steps till IGP metric
506 * have succeeded - including AS_PATH hop count. Since 'bgp
507 * bestpath as-path multipath-relax' knob is on, we don't need
508 * an exact match of AS_PATH. Thus, mark the paths are equal.
509 * That will trigger both these paths to get into the multipath
510 * array.
511 */
512 *paths_eq = 1;
513 }
514 else if (new->peer->sort == BGP_PEER_IBGP)
96450faf
JB
515 {
516 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
517 *paths_eq = 1;
518 }
519 else if (new->peer->as == exist->peer->as)
520 *paths_eq = 1;
521 }
522 else
523 {
524 /*
525 * TODO: If unequal cost ibgp multipath is enabled we can
526 * mark the paths as equal here instead of returning
527 */
528 return ret;
529 }
718e3744 530
531 /* 10. If both paths are external, prefer the path that was received
532 first (the oldest one). This step minimizes route-flap, since a
533 newer path won't displace an older one, even if it was the
534 preferred route based on the additional decision criteria below. */
535 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
8ff56318
JBD
536 && new_sort == BGP_PEER_EBGP
537 && exist_sort == BGP_PEER_EBGP)
718e3744 538 {
539 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
540 return 1;
541 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
542 return 0;
543 }
544
0de5153c
DS
545 /* 11. Router-ID comparision. */
546 /* If one of the paths is "stale", the corresponding peer router-id will
547 * be 0 and would always win over the other path. If originator id is
548 * used for the comparision, it will decide which path is better.
549 */
8ff56318
JBD
550 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
551 new_id.s_addr = newattre->originator_id.s_addr;
718e3744 552 else
553 new_id.s_addr = new->peer->remote_id.s_addr;
8ff56318
JBD
554 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
555 exist_id.s_addr = existattre->originator_id.s_addr;
718e3744 556 else
557 exist_id.s_addr = exist->peer->remote_id.s_addr;
558
559 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
560 return 1;
561 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
562 return 0;
563
564 /* 12. Cluster length comparision. */
5e242b0d
DS
565 new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
566 exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
718e3744 567
568 if (new_cluster < exist_cluster)
569 return 1;
570 if (new_cluster > exist_cluster)
571 return 0;
572
573 /* 13. Neighbor address comparision. */
0de5153c
DS
574 /* Do this only if neither path is "stale" as stale paths do not have
575 * valid peer information (as the connection may or may not be up).
576 */
577 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
578 return 1;
579 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
580 return 0;
581
718e3744 582 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
583
584 if (ret == 1)
585 return 0;
586 if (ret == -1)
587 return 1;
588
589 return 1;
590}
591
94f2b392 592static enum filter_type
718e3744 593bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
594 afi_t afi, safi_t safi)
595{
596 struct bgp_filter *filter;
597
598 filter = &peer->filter[afi][safi];
599
650f76c2
PJ
600#define FILTER_EXIST_WARN(F,f,filter) \
601 if (BGP_DEBUG (update, UPDATE_IN) \
602 && !(F ## _IN (filter))) \
16286195 603 zlog_warn ("%s: Could not find configured input %s-list %s!", \
650f76c2
PJ
604 peer->host, #f, F ## _IN_NAME(filter));
605
606 if (DISTRIBUTE_IN_NAME (filter)) {
607 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
608
718e3744 609 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
610 return FILTER_DENY;
650f76c2 611 }
718e3744 612
650f76c2
PJ
613 if (PREFIX_LIST_IN_NAME (filter)) {
614 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
615
718e3744 616 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
617 return FILTER_DENY;
650f76c2 618 }
718e3744 619
650f76c2
PJ
620 if (FILTER_LIST_IN_NAME (filter)) {
621 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
622
718e3744 623 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
624 return FILTER_DENY;
650f76c2
PJ
625 }
626
718e3744 627 return FILTER_PERMIT;
650f76c2 628#undef FILTER_EXIST_WARN
718e3744 629}
630
94f2b392 631static enum filter_type
718e3744 632bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
633 afi_t afi, safi_t safi)
634{
635 struct bgp_filter *filter;
636
637 filter = &peer->filter[afi][safi];
638
650f76c2
PJ
639#define FILTER_EXIST_WARN(F,f,filter) \
640 if (BGP_DEBUG (update, UPDATE_OUT) \
641 && !(F ## _OUT (filter))) \
16286195 642 zlog_warn ("%s: Could not find configured output %s-list %s!", \
650f76c2
PJ
643 peer->host, #f, F ## _OUT_NAME(filter));
644
645 if (DISTRIBUTE_OUT_NAME (filter)) {
646 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
647
718e3744 648 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
649 return FILTER_DENY;
650f76c2 650 }
718e3744 651
650f76c2
PJ
652 if (PREFIX_LIST_OUT_NAME (filter)) {
653 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
654
718e3744 655 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
656 return FILTER_DENY;
650f76c2 657 }
718e3744 658
650f76c2
PJ
659 if (FILTER_LIST_OUT_NAME (filter)) {
660 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
661
718e3744 662 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
663 return FILTER_DENY;
650f76c2 664 }
718e3744 665
666 return FILTER_PERMIT;
650f76c2 667#undef FILTER_EXIST_WARN
718e3744 668}
669
670/* If community attribute includes no_export then return 1. */
94f2b392 671static int
718e3744 672bgp_community_filter (struct peer *peer, struct attr *attr)
673{
674 if (attr->community)
675 {
676 /* NO_ADVERTISE check. */
677 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
678 return 1;
679
680 /* NO_EXPORT check. */
6d85b15b 681 if (peer->sort == BGP_PEER_EBGP &&
718e3744 682 community_include (attr->community, COMMUNITY_NO_EXPORT))
683 return 1;
684
685 /* NO_EXPORT_SUBCONFED check. */
6d85b15b
JBD
686 if (peer->sort == BGP_PEER_EBGP
687 || peer->sort == BGP_PEER_CONFED)
718e3744 688 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
689 return 1;
690 }
691 return 0;
692}
693
694/* Route reflection loop check. */
695static int
696bgp_cluster_filter (struct peer *peer, struct attr *attr)
697{
698 struct in_addr cluster_id;
699
fb982c25 700 if (attr->extra && attr->extra->cluster)
718e3744 701 {
702 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
703 cluster_id = peer->bgp->cluster_id;
704 else
705 cluster_id = peer->bgp->router_id;
706
fb982c25 707 if (cluster_loop_check (attr->extra->cluster, cluster_id))
718e3744 708 return 1;
709 }
710 return 0;
711}
6b0655a2 712
94f2b392 713static int
718e3744 714bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
0b16f239 715 afi_t afi, safi_t safi, char *rmap_name)
718e3744 716{
717 struct bgp_filter *filter;
718 struct bgp_info info;
719 route_map_result_t ret;
0b16f239 720 struct route_map *rmap = NULL;
718e3744 721
722 filter = &peer->filter[afi][safi];
723
724 /* Apply default weight value. */
fb982c25
PJ
725 if (peer->weight)
726 (bgp_attr_extra_get (attr))->weight = peer->weight;
718e3744 727
0b16f239
DS
728 if (rmap_name)
729 {
730 rmap = route_map_lookup_by_name(rmap_name);
731 }
732 else
733 {
734 if (ROUTE_MAP_IN_NAME(filter))
735 rmap = ROUTE_MAP_IN (filter);
736 }
737
718e3744 738 /* Route map apply. */
0b16f239 739 if (rmap)
718e3744 740 {
741 /* Duplicate current value to new strucutre for modification. */
742 info.peer = peer;
743 info.attr = attr;
744
ac41b2a2 745 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
746
718e3744 747 /* Apply BGP route map to the attribute. */
0b16f239
DS
748 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
749
750 peer->rmap_type = 0;
751
752 if (ret == RMAP_DENYMATCH)
753 {
754 /* Free newly generated AS path and community by route-map. */
755 bgp_attr_flush (attr);
756 return RMAP_DENY;
757 }
758 }
759 return RMAP_PERMIT;
760}
761
762static int
763bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
764 afi_t afi, safi_t safi, char *rmap_name)
765{
766 struct bgp_filter *filter;
767 struct bgp_info info;
768 route_map_result_t ret;
769 struct route_map *rmap = NULL;
770
771 filter = &peer->filter[afi][safi];
772
773 /* Apply default weight value. */
774 if (peer->weight)
775 (bgp_attr_extra_get (attr))->weight = peer->weight;
776
777 if (rmap_name)
778 {
779 rmap = route_map_lookup_by_name(rmap_name);
780 }
781 else
782 {
783 if (ROUTE_MAP_OUT_NAME(filter))
784 rmap = ROUTE_MAP_OUT (filter);
785 }
786
787 /* Route map apply. */
788 if (rmap)
789 {
790 /* Duplicate current value to new strucutre for modification. */
791 info.peer = peer;
792 info.attr = attr;
793
794 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
795
796 /* Apply BGP route map to the attribute. */
797 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
ac41b2a2 798
799 peer->rmap_type = 0;
800
718e3744 801 if (ret == RMAP_DENYMATCH)
c460e572
DL
802 /* caller has multiple error paths with bgp_attr_flush() */
803 return RMAP_DENY;
718e3744 804 }
805 return RMAP_PERMIT;
806}
6b0655a2 807
94f2b392 808static int
fee0f4c6 809bgp_export_modifier (struct peer *rsclient, struct peer *peer,
810 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
811{
812 struct bgp_filter *filter;
813 struct bgp_info info;
814 route_map_result_t ret;
815
816 filter = &peer->filter[afi][safi];
817
818 /* Route map apply. */
819 if (ROUTE_MAP_EXPORT_NAME (filter))
820 {
821 /* Duplicate current value to new strucutre for modification. */
822 info.peer = rsclient;
823 info.attr = attr;
824
825 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
826
827 /* Apply BGP route map to the attribute. */
828 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
829
830 rsclient->rmap_type = 0;
831
832 if (ret == RMAP_DENYMATCH)
833 {
834 /* Free newly generated AS path and community by route-map. */
835 bgp_attr_flush (attr);
836 return RMAP_DENY;
837 }
838 }
839 return RMAP_PERMIT;
840}
841
94f2b392 842static int
fee0f4c6 843bgp_import_modifier (struct peer *rsclient, struct peer *peer,
844 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
845{
846 struct bgp_filter *filter;
847 struct bgp_info info;
848 route_map_result_t ret;
849
850 filter = &rsclient->filter[afi][safi];
851
852 /* Apply default weight value. */
fb982c25
PJ
853 if (peer->weight)
854 (bgp_attr_extra_get (attr))->weight = peer->weight;
fee0f4c6 855
856 /* Route map apply. */
857 if (ROUTE_MAP_IMPORT_NAME (filter))
858 {
859 /* Duplicate current value to new strucutre for modification. */
860 info.peer = peer;
861 info.attr = attr;
862
863 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
864
865 /* Apply BGP route map to the attribute. */
866 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
867
868 peer->rmap_type = 0;
869
870 if (ret == RMAP_DENYMATCH)
871 {
872 /* Free newly generated AS path and community by route-map. */
873 bgp_attr_flush (attr);
874 return RMAP_DENY;
875 }
876 }
877 return RMAP_PERMIT;
878}
6b0655a2 879
5000f21c
DS
880
881/* If this is an EBGP peer with remove-private-AS */
882void
883bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
884 struct peer *peer, struct attr *attr)
885{
886 if (peer->sort == BGP_PEER_EBGP &&
887 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS))
888 {
889 // Take action on the entire aspath
890 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
891 {
892 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
893 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
894
895 // The entire aspath consists of private ASNs so create an empty aspath
896 else if (aspath_private_as_check (attr->aspath))
897 attr->aspath = aspath_empty_get ();
898
899 // There are some public and some private ASNs, remove the private ASNs
900 else
901 attr->aspath = aspath_remove_private_asns (attr->aspath);
902 }
903
904 // 'all' was not specified so the entire aspath must be private ASNs
905 // for us to do anything
906 else if (aspath_private_as_check (attr->aspath))
907 {
908 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
909 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
910 else
911 attr->aspath = aspath_empty_get ();
912 }
913 }
914}
915
c7122e14
DS
916/* If this is an EBGP peer with as-override */
917static void
918bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
919 struct peer *peer, struct attr *attr)
920{
921 if (peer->sort == BGP_PEER_EBGP &&
922 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
923 {
924 if (aspath_single_asn_check (attr->aspath, peer->as))
925 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
926 }
927}
928
94f2b392 929static int
718e3744 930bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
931 struct attr *attr, afi_t afi, safi_t safi)
932{
933 int ret;
934 char buf[SU_ADDRSTRLEN];
935 struct bgp_filter *filter;
718e3744 936 struct peer *from;
937 struct bgp *bgp;
718e3744 938 int transparent;
939 int reflect;
0b597ef0 940 struct attr *riattr;
718e3744 941
942 from = ri->peer;
943 filter = &peer->filter[afi][safi];
944 bgp = peer->bgp;
0b597ef0 945 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
718e3744 946
750e8146
PJ
947 if (DISABLE_BGP_ANNOUNCE)
948 return 0;
718e3744 949
fee0f4c6 950 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
951 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
952 return 0;
953
718e3744 954 /* Do not send back route to sender. */
955 if (from == peer)
956 return 0;
957
958 /* Aggregate-address suppress check. */
fb982c25 959 if (ri->extra && ri->extra->suppress)
718e3744 960 if (! UNSUPPRESS_MAP_NAME (filter))
961 return 0;
962
963 /* Default route check. */
964 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
965 {
966 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
967 return 0;
968#ifdef HAVE_IPV6
969 else if (p->family == AF_INET6 && p->prefixlen == 0)
970 return 0;
971#endif /* HAVE_IPV6 */
972 }
973
286e1e71 974 /* Transparency check. */
975 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
976 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
977 transparent = 1;
978 else
979 transparent = 0;
980
718e3744 981 /* If community is not disabled check the no-export and local. */
0b597ef0 982 if (! transparent && bgp_community_filter (peer, riattr))
718e3744 983 return 0;
984
985 /* If the attribute has originator-id and it is same as remote
986 peer's id. */
0b597ef0 987 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
718e3744 988 {
0b597ef0 989 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
718e3744 990 {
3f9c7369 991 if (bgp_debug_update(peer, p, NULL, 0))
16286195
DS
992 zlog_debug("%s [Update:SEND] %s/%d originator-id is same as remote router-id",
993 peer->host,
994 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
995 p->prefixlen);
718e3744 996 return 0;
997 }
998 }
999
1000 /* ORF prefix-list filter check */
1001 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1002 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1003 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1004 if (peer->orf_plist[afi][safi])
1005 {
1006 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1007 return 0;
1008 }
1009
1010 /* Output filter check. */
0b597ef0 1011 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
718e3744 1012 {
3f9c7369 1013 if (bgp_debug_update(peer, p, NULL, 0))
16286195
DS
1014 zlog_debug("%s [Update:SEND] %s/%d is filtered",
1015 peer->host,
1016 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1017 p->prefixlen);
718e3744 1018 return 0;
1019 }
1020
1021#ifdef BGP_SEND_ASPATH_CHECK
1022 /* AS path loop check. */
0b597ef0 1023 if (aspath_loop_check (riattr->aspath, peer->as))
718e3744 1024 {
3f9c7369 1025 if (bgp_debug_update(peer, p, NULL, 0))
16286195
DS
1026 zlog_debug("%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
1027 peer->host, peer->as);
718e3744 1028 return 0;
1029 }
1030#endif /* BGP_SEND_ASPATH_CHECK */
1031
1032 /* If we're a CONFED we need to loop check the CONFED ID too */
1033 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1034 {
0b597ef0 1035 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
718e3744 1036 {
3f9c7369 1037 if (bgp_debug_update(peer, p, NULL, 0))
16286195
DS
1038 zlog_debug("%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
1039 peer->host,
1040 bgp->confed_id);
718e3744 1041 return 0;
1042 }
1043 }
1044
1045 /* Route-Reflect check. */
6d85b15b 1046 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
718e3744 1047 reflect = 1;
1048 else
1049 reflect = 0;
1050
1051 /* IBGP reflection check. */
1052 if (reflect)
1053 {
1054 /* A route from a Client peer. */
1055 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1056 {
1057 /* Reflect to all the Non-Client peers and also to the
1058 Client peers other than the originator. Originator check
1059 is already done. So there is noting to do. */
1060 /* no bgp client-to-client reflection check. */
1061 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1062 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1063 return 0;
1064 }
1065 else
1066 {
1067 /* A route from a Non-client peer. Reflect to all other
1068 clients. */
1069 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1070 return 0;
1071 }
1072 }
41367172 1073
718e3744 1074 /* For modify attribute, copy it to temporary structure. */
0b597ef0 1075 bgp_attr_dup (attr, riattr);
fb982c25 1076
718e3744 1077 /* If local-preference is not set. */
6d85b15b
JBD
1078 if ((peer->sort == BGP_PEER_IBGP
1079 || peer->sort == BGP_PEER_CONFED)
718e3744 1080 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1081 {
1082 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1083 attr->local_pref = bgp->default_local_pref;
1084 }
1085
689bb66c
PM
1086 /* If originator-id is not set and the route is to be reflected,
1087 set the originator id */
1088 if (peer && from && peer->sort == BGP_PEER_IBGP &&
1089 from->sort == BGP_PEER_IBGP &&
1090 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1091 {
1092 attr->extra = bgp_attr_extra_get(attr);
1093 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1094 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1095 }
1096
718e3744 1097 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
6d85b15b 1098 if (peer->sort == BGP_PEER_EBGP
718e3744 1099 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1100 {
1101 if (ri->peer != bgp->peer_self && ! transparent
1102 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1103 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1104 }
1105
1106 /* next-hop-set */
9e7a53c1
TT
1107 if (transparent
1108 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
718e3744 1109 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
1110 && ((p->family == AF_INET && attr->nexthop.s_addr)
286e1e71 1111#ifdef HAVE_IPV6
fee0f4c6 1112 || (p->family == AF_INET6 &&
fb982c25 1113 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
286e1e71 1114#endif /* HAVE_IPV6 */
1115 )))
718e3744 1116 {
1117 /* NEXT-HOP Unchanged. */
1118 }
1119 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
1120 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
1121#ifdef HAVE_IPV6
fee0f4c6 1122 || (p->family == AF_INET6 &&
fb982c25 1123 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
718e3744 1124#endif /* HAVE_IPV6 */
6d85b15b 1125 || (peer->sort == BGP_PEER_EBGP
fc9a856f 1126 && (bgp_multiaccess_check_v4 (attr->nexthop, peer) == 0)))
718e3744 1127 {
1128 /* Set IPv4 nexthop. */
1129 if (p->family == AF_INET)
1130 {
1131 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
1132 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1133 IPV4_MAX_BYTELEN);
718e3744 1134 else
1135 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1136 }
1137#ifdef HAVE_IPV6
1138 /* Set IPv6 nexthop. */
1139 if (p->family == AF_INET6)
1140 {
1141 /* IPv6 global nexthop must be included. */
fb982c25 1142 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
718e3744 1143 IPV6_MAX_BYTELEN);
801a9bcc 1144 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
718e3744 1145 }
1146#endif /* HAVE_IPV6 */
1147 }
1148
1149#ifdef HAVE_IPV6
1150 if (p->family == AF_INET6)
1151 {
fee0f4c6 1152 /* Left nexthop_local unchanged if so configured. */
1153 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1154 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1155 {
fb982c25 1156 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
801a9bcc 1157 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
fee0f4c6 1158 else
801a9bcc 1159 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 1160 }
1161
1162 /* Default nexthop_local treatment for non-RS-Clients */
1163 else
1164 {
718e3744 1165 /* Link-local address should not be transit to different peer. */
801a9bcc 1166 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
718e3744 1167
1168 /* Set link-local address for shared network peer. */
1169 if (peer->shared_network
1170 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1171 {
fb982c25 1172 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
718e3744 1173 IPV6_MAX_BYTELEN);
801a9bcc 1174 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
718e3744 1175 }
1176
1177 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1178 address.*/
1179 if (reflect)
801a9bcc 1180 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
718e3744 1181
1182 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1183 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
801a9bcc 1184 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
718e3744 1185 }
fee0f4c6 1186
1187 }
718e3744 1188#endif /* HAVE_IPV6 */
1189
5000f21c 1190 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
c7122e14 1191 bgp_peer_as_override(bgp, afi, safi, peer, attr);
718e3744 1192
1193 /* Route map & unsuppress-map apply. */
1194 if (ROUTE_MAP_OUT_NAME (filter)
fb982c25 1195 || (ri->extra && ri->extra->suppress) )
718e3744 1196 {
7c7fa1b4 1197 struct bgp_info info;
558d1fec
JBD
1198 struct attr dummy_attr;
1199 struct attr_extra dummy_extra;
1200
1201 dummy_attr.extra = &dummy_extra;
1202
718e3744 1203 info.peer = peer;
1204 info.attr = attr;
1205
1206 /* The route reflector is not allowed to modify the attributes
1207 of the reflected IBGP routes. */
8bd9d948
DS
1208 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP) &&
1209 !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
718e3744 1210 {
fb982c25 1211 bgp_attr_dup (&dummy_attr, attr);
9eda90ce 1212 info.attr = &dummy_attr;
718e3744 1213 }
ac41b2a2 1214
1215 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1216
fb982c25 1217 if (ri->extra && ri->extra->suppress)
718e3744 1218 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1219 else
1220 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1221
ac41b2a2 1222 peer->rmap_type = 0;
558d1fec 1223
718e3744 1224 if (ret == RMAP_DENYMATCH)
1225 {
1226 bgp_attr_flush (attr);
1227 return 0;
1228 }
1229 }
1230 return 1;
1231}
1232
3f9c7369
DS
1233static void
1234subgroup_announce_reset_nhop (u_char family, struct attr *attr)
1235{
1236 if (family == AF_INET)
1237 attr->nexthop.s_addr = 0;
1238#ifdef HAVE_IPV6
1239 if (family == AF_INET6)
1240 memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
1241#endif
1242}
1243
1244int
1245subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp,
1246 struct prefix *p, struct attr *attr)
1247{
1248 struct bgp_filter *filter;
1249 struct peer *from;
1250 struct peer *peer;
1251 struct peer *onlypeer;
1252 struct bgp *bgp;
1253 struct attr *riattr;
1254 struct peer_af *paf;
1255 char buf[SU_ADDRSTRLEN];
1256 int ret;
1257 int transparent;
1258 int reflect;
1259 afi_t afi;
1260 safi_t safi;
1261
1262 if (DISABLE_BGP_ANNOUNCE)
1263 return 0;
1264
1265 afi = SUBGRP_AFI(subgrp);
1266 safi = SUBGRP_SAFI(subgrp);
1267 peer = SUBGRP_PEER(subgrp);
1268 onlypeer = NULL;
1269 if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL))
1270 onlypeer = SUBGRP_PFIRST(subgrp)->peer;
1271
1272 from = ri->peer;
1273 filter = &peer->filter[afi][safi];
1274 bgp = SUBGRP_INST(subgrp);
1275 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1276
1277 /* Aggregate-address suppress check. */
1278 if (ri->extra && ri->extra->suppress)
1279 if (! UNSUPPRESS_MAP_NAME (filter))
1280 {
1281 return 0;
1282 }
1283
1284 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
1285 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1286 {
1287 return 0;
1288 }
1289
1290 /* Do not send back route to sender. */
1291 if (onlypeer && from == onlypeer)
1292 {
1293 return 0;
1294 }
1295
1296 /* Transparency check. */
1297 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1298 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1299 transparent = 1;
1300 else
1301 transparent = 0;
1302
1303 /* If community is not disabled check the no-export and local. */
1304 if (! transparent && bgp_community_filter (peer, riattr))
1305 {
1306 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1307 zlog_debug ("subgrpannouncecheck: community filter check fail");
1308 return 0;
1309 }
1310
1311 /* If the attribute has originator-id and it is same as remote
1312 peer's id. */
1313 if (onlypeer &&
1314 riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) &&
1315 (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id)))
1316 {
1317 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1318 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as "
1319 "remote router-id",
1320 onlypeer->host,
1321 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1322 p->prefixlen);
1323 return 0;
1324 }
1325
1326 /* ORF prefix-list filter check */
1327 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1328 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1329 || CHECK_FLAG (peer->af_cap[afi][safi],
1330 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1331 if (peer->orf_plist[afi][safi])
1332 {
1333 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1334 {
1335 return 0;
1336 }
1337 }
1338
1339 /* Output filter check. */
1340 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1341 {
1342 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1343 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1344 peer->host,
1345 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1346 p->prefixlen);
1347 return 0;
1348 }
1349
1350#ifdef BGP_SEND_ASPATH_CHECK
1351 /* AS path loop check. */
1352 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
1353 {
1354 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1355 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1356 "that is part of AS path.",
1357 onlypeer->host, onlypeer->as);
1358 return 0;
1359 }
1360#endif /* BGP_SEND_ASPATH_CHECK */
1361
1362 /* If we're a CONFED we need to loop check the CONFED ID too */
1363 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1364 {
1365 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1366 {
1367 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1368 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u"
1369 " is AS path.",
1370 peer->host,
1371 bgp->confed_id);
1372 return 0;
1373 }
1374 }
1375
1376 /* Route-Reflect check. */
1377 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1378 reflect = 1;
1379 else
1380 reflect = 0;
1381
1382 /* IBGP reflection check. */
1383 if (reflect)
1384 {
1385 /* A route from a Client peer. */
1386 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1387 {
1388 /* Reflect to all the Non-Client peers and also to the
1389 Client peers other than the originator. Originator check
1390 is already done. So there is noting to do. */
1391 /* no bgp client-to-client reflection check. */
1392 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1393 if (CHECK_FLAG (peer->af_flags[afi][safi],
1394 PEER_FLAG_REFLECTOR_CLIENT))
1395 return 0;
1396 }
1397 else
1398 {
1399 /* A route from a Non-client peer. Reflect to all other
1400 clients. */
1401 if (! CHECK_FLAG (peer->af_flags[afi][safi],
1402 PEER_FLAG_REFLECTOR_CLIENT))
1403 return 0;
1404 }
1405 }
1406
1407 /* For modify attribute, copy it to temporary structure. */
1408 bgp_attr_dup (attr, riattr);
1409
1410 /* If local-preference is not set. */
1411 if ((peer->sort == BGP_PEER_IBGP
1412 || peer->sort == BGP_PEER_CONFED)
1413 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1414 {
1415 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1416 attr->local_pref = bgp->default_local_pref;
1417 }
1418
1419 /* If originator-id is not set and the route is to be reflected,
1420 set the originator id */
1421 if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1422 {
1423 attr->extra = bgp_attr_extra_get(attr);
1424 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1425 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1426 }
1427
1428 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1429 if (peer->sort == BGP_PEER_EBGP
1430 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1431 {
1432 if (ri->peer != bgp->peer_self && ! transparent
1433 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1434 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1435 }
1436
1437 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1438 * in announce check, only certain flags and length (or number of nexthops
1439 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1440 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1441 * Typically, the source nexthop in the attribute is preserved but in the
1442 * scenarios where we know it will always be overwritten, we reset the
1443 * nexthop to "0" in an attempt to achieve better Update packing. An
1444 * example of this is when a prefix from each of 2 IBGP peers needs to be
1445 * announced to an EBGP peer (and they have the same attributes barring
1446 * their nexthop).
1447 */
1448 if (reflect)
1449 SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
1450
1451#ifdef HAVE_IPV6
1452 /* IPv6/MP starts with 1 nexthop, the link-local address is passed only if
1453 * we're not reflecting the route and the peer (group) to whom we're going
1454 * to announce is on a shared network (directly connected peers) or the
1455 * peer (group) is configured to receive link-local nexthop and it is
1456 * available in the prefix.
1457 * Of course, the operator can always set it through the route-map, if
1458 * so desired.
1459 */
1460 if (p->family == AF_INET6)
1461 {
801a9bcc 1462 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
3f9c7369
DS
1463 if (!reflect)
1464 {
1465 if (peer->shared_network ||
1466 (CHECK_FLAG (peer->af_flags[afi][safi],
1467 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1468 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)))
801a9bcc 1469 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
3f9c7369
DS
1470 }
1471
1472 /* Clear off link-local nexthop in source, if not needed. This may help
1473 * more prefixes share the same attribute for announcement.
1474 */
1475 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1476 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1477 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1478 }
1479#endif /* HAVE_IPV6 */
1480
1481 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1482 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1483
1484 /* Route map & unsuppress-map apply. */
1485 if (ROUTE_MAP_OUT_NAME (filter)
1486 || (ri->extra && ri->extra->suppress) )
1487 {
1488 struct bgp_info info;
1489 struct attr dummy_attr;
1490 struct attr_extra dummy_extra;
1491
1492 dummy_attr.extra = &dummy_extra;
1493
1494 info.peer = peer;
1495 info.attr = attr;
316e074d
DS
1496 /* don't confuse inbound and outbound setting */
1497 RESET_FLAG(attr->rmap_change_flags);
3f9c7369
DS
1498
1499 /*
1500 * The route reflector is not allowed to modify the attributes
1501 * of the reflected IBGP routes unless explicitly allowed.
1502 */
1503 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1504 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1505 {
1506 bgp_attr_dup (&dummy_attr, attr);
1507 info.attr = &dummy_attr;
1508 }
1509
1510 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1511
1512 if (ri->extra && ri->extra->suppress)
1513 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1514 else
1515 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1516
1517 peer->rmap_type = 0;
1518
1519 if (ret == RMAP_DENYMATCH)
1520 {
1521 bgp_attr_flush (attr);
1522 return 0;
1523 }
1524 }
1525
1526 /* After route-map has been applied, we check to see if the nexthop to
1527 * be carried in the attribute (that is used for the announcement) can
1528 * be cleared off or not. We do this in all cases where we would be
1529 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1530 * the global nexthop here; the link-local nexthop would have been cleared
1531 * already, and if not, it is required by the update formation code.
1532 * Also see earlier comments in this function.
1533 */
1534 if (!(CHECK_FLAG(attr->rmap_change_flags, BATTR_RMAP_NEXTHOP_CHANGED) ||
316e074d
DS
1535 CHECK_FLAG(attr->rmap_change_flags, BATTR_RMAP_NEXTHOP_UNCHANGED) ||
1536 CHECK_FLAG(riattr->rmap_change_flags, BATTR_RMAP_NEXTHOP_UNCHANGED) ||
3f9c7369
DS
1537 transparent ||
1538 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)))
1539 {
1540 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF))
1541 {
1542 if (!reflect ||
1543 CHECK_FLAG (peer->af_flags[afi][safi],
1544 PEER_FLAG_FORCE_NEXTHOP_SELF))
1545 subgroup_announce_reset_nhop (p->family, attr);
1546 }
1547 else if (peer->sort == BGP_PEER_EBGP)
1548 {
1549 SUBGRP_FOREACH_PEER (subgrp, paf)
1550 {
1551 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1552 break;
1553 }
1554 if (!paf)
1555 subgroup_announce_reset_nhop (p->family, attr);
1556 }
1557 }
1558
1559 return 1;
1560}
1561
1562static int
1563bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1564 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
1565{
1566 int ret;
1567 char buf[SU_ADDRSTRLEN];
1568 struct bgp_filter *filter;
1569 struct bgp_info info;
1570 struct peer *from;
1571 struct attr *riattr;
1572
1573 from = ri->peer;
1574 filter = &rsclient->filter[afi][safi];
1575 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1576
1577 if (DISABLE_BGP_ANNOUNCE)
1578 return 0;
1579
1580 /* Do not send back route to sender. */
1581 if (from == rsclient)
1582 return 0;
1583
1584 /* Aggregate-address suppress check. */
1585 if (ri->extra && ri->extra->suppress)
1586 if (! UNSUPPRESS_MAP_NAME (filter))
1587 return 0;
1588
1589 /* Default route check. */
1590 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1591 PEER_STATUS_DEFAULT_ORIGINATE))
1592 {
1593 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1594 return 0;
1595#ifdef HAVE_IPV6
1596 else if (p->family == AF_INET6 && p->prefixlen == 0)
1597 return 0;
1598#endif /* HAVE_IPV6 */
1599 }
1600
1601 /* If the attribute has originator-id and it is same as remote
1602 peer's id. */
1603 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1604 {
1605 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1606 &riattr->extra->originator_id))
1607 {
1608 if (bgp_debug_update(rsclient, p, NULL, 0))
1609 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1610 rsclient->host,
1611 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1612 p->prefixlen);
1613 return 0;
1614 }
1615 }
1616
1617 /* ORF prefix-list filter check */
1618 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1619 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1620 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1621 if (rsclient->orf_plist[afi][safi])
1622 {
1623 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1624 return 0;
1625 }
1626
1627 /* Output filter check. */
1628 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
1629 {
1630 if (bgp_debug_update(rsclient, p, NULL, 0))
1631 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1632 rsclient->host,
1633 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1634 p->prefixlen);
1635 return 0;
1636 }
1637
1638#ifdef BGP_SEND_ASPATH_CHECK
1639 /* AS path loop check. */
1640 if (aspath_loop_check (riattr->aspath, rsclient->as))
1641 {
1642 if (bgp_debug_update(rsclient, p, NULL, 0))
1643 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
1644 rsclient->host, rsclient->as);
1645 return 0;
1646 }
1647#endif /* BGP_SEND_ASPATH_CHECK */
1648
1649 /* For modify attribute, copy it to temporary structure. */
1650 bgp_attr_dup (attr, riattr);
1651
1652 /* next-hop-set */
1653 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1654#ifdef HAVE_IPV6
1655 || (p->family == AF_INET6 &&
1656 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
1657#endif /* HAVE_IPV6 */
1658 )
1659 {
1660 /* Set IPv4 nexthop. */
1661 if (p->family == AF_INET)
1662 {
1663 if (safi == SAFI_MPLS_VPN)
1664 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
1665 IPV4_MAX_BYTELEN);
1666 else
1667 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1668 }
1669#ifdef HAVE_IPV6
1670 /* Set IPv6 nexthop. */
1671 if (p->family == AF_INET6)
1672 {
1673 /* IPv6 global nexthop must be included. */
1674 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
1675 IPV6_MAX_BYTELEN);
801a9bcc 1676 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
3f9c7369
DS
1677 }
1678#endif /* HAVE_IPV6 */
1679 }
1680
1681#ifdef HAVE_IPV6
1682 if (p->family == AF_INET6)
1683 {
1684 struct attr_extra *attre = attr->extra;
1685
1686 /* Left nexthop_local unchanged if so configured. */
1687 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1688 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1689 {
1690 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
801a9bcc 1691 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
3f9c7369 1692 else
801a9bcc 1693 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
3f9c7369
DS
1694 }
1695
1696 /* Default nexthop_local treatment for RS-Clients */
1697 else
1698 {
1699 /* Announcer and RS-Client are both in the same network */
1700 if (rsclient->shared_network && from->shared_network &&
1701 (rsclient->ifindex == from->ifindex))
1702 {
1703 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
801a9bcc 1704 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
3f9c7369 1705 else
801a9bcc 1706 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
3f9c7369
DS
1707 }
1708
1709 /* Set link-local address for shared network peer. */
1710 else if (rsclient->shared_network
1711 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1712 {
1713 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
1714 IPV6_MAX_BYTELEN);
801a9bcc 1715 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
3f9c7369
DS
1716 }
1717
1718 else
801a9bcc 1719 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
3f9c7369
DS
1720 }
1721
1722 }
1723#endif /* HAVE_IPV6 */
1724
1725
1726 /* If this is EBGP peer and remove-private-AS is set. */
1727 if (rsclient->sort == BGP_PEER_EBGP
1728 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1729 && aspath_private_as_check (attr->aspath))
1730 attr->aspath = aspath_empty_get ();
1731
1732 /* Route map & unsuppress-map apply. */
1733 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
1734 {
1735 info.peer = rsclient;
1736 info.attr = attr;
1737
1738 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1739
1740 if (ri->extra && ri->extra->suppress)
1741 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1742 else
1743 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1744
1745 rsclient->rmap_type = 0;
1746
1747 if (ret == RMAP_DENYMATCH)
1748 {
1749 bgp_attr_flush (attr);
1750 return 0;
1751 }
1752 }
1753
1754 return 1;
1755}
1756
94f2b392 1757static int
3f9c7369
DS
1758subgroup_announce_check_rsclient (struct bgp_info *ri,
1759 struct update_subgroup *subgrp,
1760 struct prefix *p, struct attr *attr)
fee0f4c6 1761{
1762 int ret;
1763 char buf[SU_ADDRSTRLEN];
1764 struct bgp_filter *filter;
1765 struct bgp_info info;
1766 struct peer *from;
3f9c7369
DS
1767 struct peer *rsclient;
1768 struct peer *onlypeer;
0b597ef0 1769 struct attr *riattr;
5000f21c 1770 struct bgp *bgp;
3f9c7369
DS
1771 afi_t afi;
1772 safi_t safi;
1773
1774 if (DISABLE_BGP_ANNOUNCE)
1775 return 0;
fee0f4c6 1776
3f9c7369
DS
1777 afi = SUBGRP_AFI(subgrp);
1778 safi = SUBGRP_SAFI(subgrp);
1779 rsclient = SUBGRP_PEER(subgrp);
1780 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1781 (SUBGRP_PFIRST(subgrp))->peer : NULL);
fee0f4c6 1782 from = ri->peer;
1783 filter = &rsclient->filter[afi][safi];
5000f21c 1784 bgp = rsclient->bgp;
0b597ef0 1785 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
fee0f4c6 1786
fee0f4c6 1787 /* Do not send back route to sender. */
3f9c7369 1788 if (onlypeer && (from == onlypeer))
fee0f4c6 1789 return 0;
1790
1791 /* Aggregate-address suppress check. */
fb982c25 1792 if (ri->extra && ri->extra->suppress)
fee0f4c6 1793 if (! UNSUPPRESS_MAP_NAME (filter))
1794 return 0;
1795
1796 /* Default route check. */
1797 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1798 PEER_STATUS_DEFAULT_ORIGINATE))
1799 {
1800 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1801 return 0;
1802#ifdef HAVE_IPV6
1803 else if (p->family == AF_INET6 && p->prefixlen == 0)
1804 return 0;
1805#endif /* HAVE_IPV6 */
1806 }
1807
1808 /* If the attribute has originator-id and it is same as remote
1809 peer's id. */
3f9c7369 1810 if (onlypeer && riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
fee0f4c6 1811 {
3f9c7369 1812 if (IPV4_ADDR_SAME (&onlypeer->remote_id,
0b597ef0 1813 &riattr->extra->originator_id))
fee0f4c6 1814 {
3f9c7369 1815 if (bgp_debug_update(rsclient, p, subgrp->update_group, 0))
16286195 1816 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as remote router-id",
3f9c7369 1817 onlypeer->host,
16286195
DS
1818 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1819 p->prefixlen);
fee0f4c6 1820 return 0;
1821 }
1822 }
1823
1824 /* ORF prefix-list filter check */
1825 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1826 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1827 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1828 if (rsclient->orf_plist[afi][safi])
1829 {
1830 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1831 return 0;
1832 }
1833
1834 /* Output filter check. */
0b597ef0 1835 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
fee0f4c6 1836 {
3f9c7369 1837 if (bgp_debug_update(rsclient, p, subgrp->update_group, 0))
16286195
DS
1838 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1839 rsclient->host,
1840 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1841 p->prefixlen);
fee0f4c6 1842 return 0;
1843 }
1844
1845#ifdef BGP_SEND_ASPATH_CHECK
1846 /* AS path loop check. */
3f9c7369 1847 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
fee0f4c6 1848 {
3f9c7369 1849 if (bgp_debug_update(rsclient, p, subgrp->update_group, 0))
16286195 1850 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
3f9c7369 1851 onlypeer->host, onlypeer->as);
fee0f4c6 1852 return 0;
1853 }
1854#endif /* BGP_SEND_ASPATH_CHECK */
1855
1856 /* For modify attribute, copy it to temporary structure. */
0b597ef0 1857 bgp_attr_dup (attr, riattr);
fee0f4c6 1858
1859 /* next-hop-set */
1860 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1861#ifdef HAVE_IPV6
1862 || (p->family == AF_INET6 &&
fb982c25 1863 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
fee0f4c6 1864#endif /* HAVE_IPV6 */
1865 )
1866 {
1867 /* Set IPv4 nexthop. */
1868 if (p->family == AF_INET)
1869 {
1870 if (safi == SAFI_MPLS_VPN)
fb982c25 1871 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
fee0f4c6 1872 IPV4_MAX_BYTELEN);
1873 else
1874 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1875 }
1876#ifdef HAVE_IPV6
1877 /* Set IPv6 nexthop. */
1878 if (p->family == AF_INET6)
1879 {
1880 /* IPv6 global nexthop must be included. */
fb982c25 1881 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
fee0f4c6 1882 IPV6_MAX_BYTELEN);
801a9bcc 1883 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 1884 }
1885#endif /* HAVE_IPV6 */
1886 }
1887
1888#ifdef HAVE_IPV6
1889 if (p->family == AF_INET6)
1890 {
fb982c25 1891 struct attr_extra *attre = attr->extra;
558d1fec 1892
fee0f4c6 1893 /* Left nexthop_local unchanged if so configured. */
3f9c7369 1894 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
fee0f4c6 1895 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1896 {
fb982c25 1897 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
801a9bcc 1898 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
fee0f4c6 1899 else
801a9bcc 1900 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 1901 }
3f9c7369 1902
fee0f4c6 1903 /* Default nexthop_local treatment for RS-Clients */
3f9c7369
DS
1904 else
1905 {
1906 /* Announcer and RS-Client are both in the same network */
fee0f4c6 1907 if (rsclient->shared_network && from->shared_network &&
1908 (rsclient->ifindex == from->ifindex))
1909 {
fb982c25 1910 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
801a9bcc 1911 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
fee0f4c6 1912 else
801a9bcc 1913 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 1914 }
1915
1916 /* Set link-local address for shared network peer. */
1917 else if (rsclient->shared_network
1918 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1919 {
fb982c25 1920 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
fee0f4c6 1921 IPV6_MAX_BYTELEN);
801a9bcc 1922 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
fee0f4c6 1923 }
1924
1925 else
801a9bcc 1926 attre->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
fee0f4c6 1927 }
1928
1929 }
1930#endif /* HAVE_IPV6 */
1931
5000f21c 1932 bgp_peer_remove_private_as(bgp, afi, safi, rsclient, attr);
c7122e14 1933 bgp_peer_as_override(bgp, afi, safi, rsclient, attr);
fee0f4c6 1934
1935 /* Route map & unsuppress-map apply. */
fb982c25 1936 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
fee0f4c6 1937 {
1938 info.peer = rsclient;
1939 info.attr = attr;
1940
1941 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1942
fb982c25 1943 if (ri->extra && ri->extra->suppress)
fee0f4c6 1944 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1945 else
1946 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1947
1948 rsclient->rmap_type = 0;
1949
1950 if (ret == RMAP_DENYMATCH)
1951 {
1952 bgp_attr_flush (attr);
1953 return 0;
1954 }
1955 }
1956
1957 return 1;
1958}
1959
1960struct bgp_info_pair
1961{
1962 struct bgp_info *old;
1963 struct bgp_info *new;
1964};
1965
94f2b392 1966static void
96450faf
JB
1967bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1968 struct bgp_maxpaths_cfg *mpath_cfg,
1969 struct bgp_info_pair *result)
718e3744 1970{
718e3744 1971 struct bgp_info *new_select;
1972 struct bgp_info *old_select;
fee0f4c6 1973 struct bgp_info *ri;
718e3744 1974 struct bgp_info *ri1;
1975 struct bgp_info *ri2;
b40d939b 1976 struct bgp_info *nextri = NULL;
96450faf
JB
1977 int paths_eq, do_mpath;
1978 struct list mp_list;
d889623f 1979 char buf[INET6_BUFSIZ];
96450faf
JB
1980
1981 bgp_mp_list_init (&mp_list);
1982 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1983 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1984
718e3744 1985 /* bgp deterministic-med */
1986 new_select = NULL;
1987 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1988 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1989 {
1990 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1991 continue;
1992 if (BGP_INFO_HOLDDOWN (ri1))
1993 continue;
2fed8887
DS
1994 if (ri1->peer && ri1->peer != bgp->peer_self)
1995 if (ri1->peer->status != Established)
1996 continue;
718e3744 1997
1998 new_select = ri1;
6918e74b
JB
1999 if (do_mpath)
2000 bgp_mp_list_add (&mp_list, ri1);
2001 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
718e3744 2002 if (ri1->next)
2003 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
2004 {
2005 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
2006 continue;
2007 if (BGP_INFO_HOLDDOWN (ri2))
2008 continue;
2fed8887
DS
2009 if (ri2->peer &&
2010 ri2->peer != bgp->peer_self &&
2011 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
2012 if (ri2->peer->status != Established)
2013 continue;
718e3744 2014
2015 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
2016 || aspath_cmp_left_confed (ri1->attr->aspath,
2017 ri2->attr->aspath))
2018 {
6918e74b
JB
2019 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
2020 old_select = ri2;
5e242b0d
DS
2021 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
2022 mpath_cfg))
718e3744 2023 {
1a392d46 2024 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
718e3744 2025 new_select = ri2;
6918e74b
JB
2026 if (do_mpath && !paths_eq)
2027 {
2028 bgp_mp_list_clear (&mp_list);
2029 bgp_mp_list_add (&mp_list, ri2);
2030 }
718e3744 2031 }
2032
6918e74b
JB
2033 if (do_mpath && paths_eq)
2034 bgp_mp_list_add (&mp_list, ri2);
2035
1a392d46 2036 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
718e3744 2037 }
2038 }
1a392d46
PJ
2039 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
2040 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
6918e74b
JB
2041
2042 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
2043 bgp_mp_list_clear (&mp_list);
718e3744 2044 }
2045
2046 /* Check old selected route and new selected route. */
2047 old_select = NULL;
2048 new_select = NULL;
b40d939b 2049 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
718e3744 2050 {
2051 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
2052 old_select = ri;
2053
2054 if (BGP_INFO_HOLDDOWN (ri))
b40d939b 2055 {
2056 /* reap REMOVED routes, if needs be
2057 * selected route must stay for a while longer though
2058 */
2059 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2060 && (ri != old_select))
2061 bgp_info_reap (rn, ri);
2062
2063 continue;
2064 }
718e3744 2065
2fed8887
DS
2066 if (ri->peer &&
2067 ri->peer != bgp->peer_self &&
2068 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
2069 if (ri->peer->status != Established)
2070 continue;
2071
718e3744 2072 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
2073 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
2074 {
1a392d46 2075 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
718e3744 2076 continue;
2077 }
1a392d46
PJ
2078 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
2079 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
718e3744 2080
5e242b0d 2081 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg))
96450faf 2082 {
6918e74b
JB
2083 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
2084 bgp_mp_dmed_deselect (new_select);
2085
96450faf
JB
2086 new_select = ri;
2087
2088 if (do_mpath && !paths_eq)
2089 {
2090 bgp_mp_list_clear (&mp_list);
2091 bgp_mp_list_add (&mp_list, ri);
2092 }
2093 }
6918e74b
JB
2094 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
2095 bgp_mp_dmed_deselect (ri);
96450faf
JB
2096
2097 if (do_mpath && paths_eq)
2098 bgp_mp_list_add (&mp_list, ri);
718e3744 2099 }
b40d939b 2100
fee0f4c6 2101
6918e74b
JB
2102 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
2103 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
96450faf 2104
0b597ef0 2105 bgp_info_mpath_aggregate_update (new_select, old_select);
96450faf
JB
2106 bgp_mp_list_clear (&mp_list);
2107
2108 result->old = old_select;
2109 result->new = new_select;
2110
2111 return;
fee0f4c6 2112}
2113
3f9c7369
DS
2114/*
2115 * A new route/change in bestpath of an existing route. Evaluate the path
2116 * for advertisement to the subgroup.
2117 */
2118int
2119subgroup_process_announce_selected (struct update_subgroup *subgrp,
2120 struct bgp_info *selected,
2121 struct bgp_node *rn)
9eda90ce 2122{
fee0f4c6 2123 struct prefix *p;
3f9c7369
DS
2124 struct peer_af *paf;
2125 struct peer *onlypeer;
558d1fec
JBD
2126 struct attr attr;
2127 struct attr_extra extra;
3f9c7369
DS
2128 afi_t afi;
2129 safi_t safi;
fee0f4c6 2130
2131 p = &rn->p;
3f9c7369
DS
2132 afi = SUBGRP_AFI(subgrp);
2133 safi = SUBGRP_SAFI(subgrp);
2134 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
2135 (SUBGRP_PFIRST(subgrp))->peer : NULL);
718e3744 2136
9eda90ce 2137 /* First update is deferred until ORF or ROUTE-REFRESH is received */
3f9c7369
DS
2138 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
2139 PEER_STATUS_ORF_WAIT_REFRESH))
fee0f4c6 2140 return 0;
718e3744 2141
558d1fec
JBD
2142 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2143 attr.extra = &extra;
2144
67174041 2145 switch (bgp_node_table (rn)->type)
fee0f4c6 2146 {
2147 case BGP_TABLE_MAIN:
3f9c7369 2148 /* Announcement to the subgroup. If the route is filtered,
718e3744 2149 withdraw it. */
3f9c7369
DS
2150 if (selected && subgroup_announce_check(selected, subgrp, p, &attr))
2151 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
fee0f4c6 2152 else
3f9c7369
DS
2153 bgp_adj_out_unset_subgroup(rn, subgrp);
2154
fee0f4c6 2155 break;
2156 case BGP_TABLE_RSCLIENT:
3f9c7369 2157 /* Announcement to peer->conf. If the route is filtered,
fee0f4c6 2158 withdraw it. */
3f9c7369
DS
2159 if (selected &&
2160 subgroup_announce_check_rsclient (selected, subgrp, p, &attr))
2161 bgp_adj_out_set_subgroup (rn, subgrp, &attr, selected);
9eda90ce 2162 else
3f9c7369 2163 bgp_adj_out_unset_subgroup(rn, subgrp);
fee0f4c6 2164 break;
2165 }
558d1fec 2166
fee0f4c6 2167 return 0;
200df115 2168}
fee0f4c6 2169
3f9c7369 2170struct bgp_process_queue
fee0f4c6 2171{
200df115 2172 struct bgp *bgp;
2173 struct bgp_node *rn;
2174 afi_t afi;
2175 safi_t safi;
2176};
2177
2178static wq_item_status
0fb58d5d 2179bgp_process_rsclient (struct work_queue *wq, void *data)
200df115 2180{
0fb58d5d 2181 struct bgp_process_queue *pq = data;
200df115 2182 struct bgp *bgp = pq->bgp;
2183 struct bgp_node *rn = pq->rn;
2184 afi_t afi = pq->afi;
2185 safi_t safi = pq->safi;
fee0f4c6 2186 struct bgp_info *new_select;
2187 struct bgp_info *old_select;
2188 struct bgp_info_pair old_and_new;
1eb8ef25 2189 struct listnode *node, *nnode;
cb1faec9 2190 struct peer *rsclient;
3f9c7369
DS
2191 struct peer_af *paf;
2192 struct update_subgroup *subgrp;
cb1faec9
DS
2193
2194 /* Is it end of initial update? (after startup) */
2195 if (!rn)
2196 {
4a16ae86
DS
2197 /* This is just to keep the display sane in case all the peers are
2198 rsclients only */
2199 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
2200 sizeof(bgp->update_delay_zebra_resume_time));
2201
2202 bgp->rsclient_peers_update_hold = 0;
cb1faec9
DS
2203 bgp_start_routeadv(bgp);
2204 return WQ_SUCCESS;
2205 }
2206
2207 rsclient = bgp_node_table (rn)->owner;
2208
fee0f4c6 2209 /* Best path selection. */
96450faf 2210 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 2211 new_select = old_and_new.new;
2212 old_select = old_and_new.old;
2213
200df115 2214 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
2215 {
228da428
CC
2216 if (rsclient->group)
2217 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
2218 {
2219 /* Nothing to do. */
2220 if (old_select && old_select == new_select)
2221 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
2222 continue;
2223
2224 if (old_select)
2225 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
2226 if (new_select)
2227 {
2228 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
2229 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d
JB
2230 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
2231 }
228da428 2232
3f9c7369
DS
2233 paf = peer_af_find(rsclient, afi, safi);
2234 assert(paf);
2235 subgrp = PAF_SUBGRP(paf);
2236 if (!subgrp) /* not an established session */
2237 continue;
2238 subgroup_process_announce_selected (subgrp, new_select, rn);
228da428 2239 }
200df115 2240 }
2241 else
2242 {
b7395791 2243 if (old_select)
1a392d46 2244 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
b7395791 2245 if (new_select)
2246 {
1a392d46
PJ
2247 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
2248 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 2249 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
b7395791 2250 }
3f9c7369
DS
2251 paf = peer_af_find(rsclient, afi, safi);
2252 if (paf && (subgrp = PAF_SUBGRP(paf))) /* if an established session */
2253 subgroup_process_announce_selected (subgrp, new_select, rn);
200df115 2254 }
2255
b40d939b 2256 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
2257 bgp_info_reap (rn, old_select);
3f9c7369 2258
200df115 2259 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2260 return WQ_SUCCESS;
fee0f4c6 2261}
2262
200df115 2263static wq_item_status
0fb58d5d 2264bgp_process_main (struct work_queue *wq, void *data)
200df115 2265{
0fb58d5d 2266 struct bgp_process_queue *pq = data;
200df115 2267 struct bgp *bgp = pq->bgp;
2268 struct bgp_node *rn = pq->rn;
2269 afi_t afi = pq->afi;
2270 safi_t safi = pq->safi;
2271 struct prefix *p = &rn->p;
fee0f4c6 2272 struct bgp_info *new_select;
2273 struct bgp_info *old_select;
2274 struct bgp_info_pair old_and_new;
1eb8ef25 2275 struct listnode *node, *nnode;
fee0f4c6 2276 struct peer *peer;
cb1faec9
DS
2277
2278 /* Is it end of initial update? (after startup) */
2279 if (!rn)
2280 {
4a16ae86
DS
2281 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
2282 sizeof(bgp->update_delay_zebra_resume_time));
2283
2284 bgp->main_zebra_update_hold = 0;
2285 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2286 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2287 {
2288 bgp_zebra_announce_table(bgp, afi, safi);
2289 }
2290 bgp->main_peers_update_hold = 0;
2291
cb1faec9
DS
2292 bgp_start_routeadv(bgp);
2293 return WQ_SUCCESS;
2294 }
2295
fee0f4c6 2296 /* Best path selection. */
96450faf 2297 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 2298 old_select = old_and_new.old;
2299 new_select = old_and_new.new;
2300
2301 /* Nothing to do. */
8ad7271d 2302 if (old_select && old_select == new_select && !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR))
fee0f4c6 2303 {
2304 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
200df115 2305 {
8196f13d
JB
2306 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
2307 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
73ac8160 2308 bgp_zebra_announce (p, old_select, bgp, afi, safi);
200df115 2309
8196f13d 2310 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
200df115 2311 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2312 return WQ_SUCCESS;
2313 }
fee0f4c6 2314 }
2315
8ad7271d
DS
2316 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
2317 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
2318
3f9c7369
DS
2319 /* bestpath has changed; bump version */
2320 if (old_select || new_select)
2321 bgp_bump_version(rn);
2322
338b3424 2323 if (old_select)
1a392d46 2324 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
338b3424 2325 if (new_select)
2326 {
1a392d46
PJ
2327 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
2328 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 2329 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
338b3424 2330 }
2331
3f9c7369 2332 group_announce_route(bgp, afi, safi, rn, new_select);
718e3744 2333
2334 /* FIB update. */
5a616c08
B
2335 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
2336 ! bgp_option_check (BGP_OPT_NO_FIB)))
718e3744 2337 {
2338 if (new_select
2339 && new_select->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
2340 && (new_select->sub_type == BGP_ROUTE_NORMAL ||
2341 new_select->sub_type == BGP_ROUTE_AGGREGATE))
73ac8160 2342 bgp_zebra_announce (p, new_select, bgp, afi, safi);
718e3744 2343 else
2344 {
2345 /* Withdraw the route from the kernel. */
2346 if (old_select
2347 && old_select->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
2348 && (old_select->sub_type == BGP_ROUTE_NORMAL ||
2349 old_select->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 2350 bgp_zebra_withdraw (p, old_select, safi);
718e3744 2351 }
2352 }
b40d939b 2353
2354 /* Reap old select bgp_info, it it has been removed */
2355 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
2356 bgp_info_reap (rn, old_select);
2357
200df115 2358 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2359 return WQ_SUCCESS;
718e3744 2360}
2361
200df115 2362static void
0fb58d5d 2363bgp_processq_del (struct work_queue *wq, void *data)
200df115 2364{
0fb58d5d 2365 struct bgp_process_queue *pq = data;
cb1faec9
DS
2366 struct bgp_table *table;
2367
228da428 2368 bgp_unlock (pq->bgp);
cb1faec9
DS
2369 if (pq->rn)
2370 {
2371 table = bgp_node_table (pq->rn);
2372 bgp_unlock_node (pq->rn);
2373 bgp_table_unlock (table);
2374 }
200df115 2375 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
2376}
2377
f188f2c4 2378void
200df115 2379bgp_process_queue_init (void)
2380{
2381 bm->process_main_queue
2382 = work_queue_new (bm->master, "process_main_queue");
2383 bm->process_rsclient_queue
2384 = work_queue_new (bm->master, "process_rsclient_queue");
2385
2386 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
2387 {
2388 zlog_err ("%s: Failed to allocate work queue", __func__);
2389 exit (1);
2390 }
2391
2392 bm->process_main_queue->spec.workfunc = &bgp_process_main;
200df115 2393 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
838bbde0
PJ
2394 bm->process_main_queue->spec.max_retries = 0;
2395 bm->process_main_queue->spec.hold = 50;
d889623f
DS
2396 /* Use a higher yield value of 50ms for main queue processing */
2397 bm->process_main_queue->spec.yield = 50 * 1000L;
838bbde0
PJ
2398
2399 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
2400 sizeof (struct work_queue *));
2401 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
200df115 2402}
2403
2404void
fee0f4c6 2405bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
2406{
200df115 2407 struct bgp_process_queue *pqnode;
2408
2409 /* already scheduled for processing? */
2410 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
2411 return;
2412
2413 if ( (bm->process_main_queue == NULL) ||
2414 (bm->process_rsclient_queue == NULL) )
2415 bgp_process_queue_init ();
2416
2417 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2418 sizeof (struct bgp_process_queue));
2419 if (!pqnode)
2420 return;
228da428
CC
2421
2422 /* all unlocked in bgp_processq_del */
67174041 2423 bgp_table_lock (bgp_node_table (rn));
228da428 2424 pqnode->rn = bgp_lock_node (rn);
200df115 2425 pqnode->bgp = bgp;
228da428 2426 bgp_lock (bgp);
200df115 2427 pqnode->afi = afi;
2428 pqnode->safi = safi;
2429
67174041 2430 switch (bgp_node_table (rn)->type)
fee0f4c6 2431 {
200df115 2432 case BGP_TABLE_MAIN:
2433 work_queue_add (bm->process_main_queue, pqnode);
2434 break;
2435 case BGP_TABLE_RSCLIENT:
2436 work_queue_add (bm->process_rsclient_queue, pqnode);
2437 break;
fee0f4c6 2438 }
200df115 2439
07ff4dc4 2440 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
200df115 2441 return;
fee0f4c6 2442}
0a486e5f 2443
cb1faec9
DS
2444void
2445bgp_add_eoiu_mark (struct bgp *bgp, bgp_table_t type)
2446{
2447 struct bgp_process_queue *pqnode;
2448
2449 if ( (bm->process_main_queue == NULL) ||
2450 (bm->process_rsclient_queue == NULL) )
2451 bgp_process_queue_init ();
2452
2453 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2454 sizeof (struct bgp_process_queue));
2455 if (!pqnode)
2456 return;
2457
2458 pqnode->rn = NULL;
2459 pqnode->bgp = bgp;
2460 bgp_lock (bgp);
2461 switch (type)
2462 {
2463 case BGP_TABLE_MAIN:
2464 work_queue_add (bm->process_main_queue, pqnode);
2465 break;
2466 case BGP_TABLE_RSCLIENT:
2467 work_queue_add (bm->process_rsclient_queue, pqnode);
2468 break;
2469 }
2470
2471 return;
2472}
2473
94f2b392 2474static int
0a486e5f 2475bgp_maximum_prefix_restart_timer (struct thread *thread)
2476{
2477 struct peer *peer;
2478
2479 peer = THREAD_ARG (thread);
2480 peer->t_pmax_restart = NULL;
2481
16286195 2482 if (bgp_debug_neighbor_events(peer))
0a486e5f 2483 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
2484 peer->host);
2485
1ff9a340 2486 peer_clear (peer, NULL);
0a486e5f 2487
2488 return 0;
2489}
2490
718e3744 2491int
5228ad27 2492bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
2493 safi_t safi, int always)
718e3744 2494{
e0701b79 2495 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
2496 return 0;
2497
2498 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
718e3744 2499 {
e0701b79 2500 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
2501 && ! always)
2502 return 0;
2503
16286195
DS
2504 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
2505 "limit %ld", afi_safi_print (afi, safi), peer->host,
2506 peer->pcount[afi][safi], peer->pmax[afi][safi]);
e0701b79 2507 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2508
2509 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
2510 return 0;
2511
2512 {
5228ad27 2513 u_int8_t ndata[7];
e0701b79 2514
2515 if (safi == SAFI_MPLS_VPN)
42e6d745 2516 safi = SAFI_MPLS_LABELED_VPN;
5228ad27 2517
2518 ndata[0] = (afi >> 8);
2519 ndata[1] = afi;
2520 ndata[2] = safi;
2521 ndata[3] = (peer->pmax[afi][safi] >> 24);
2522 ndata[4] = (peer->pmax[afi][safi] >> 16);
2523 ndata[5] = (peer->pmax[afi][safi] >> 8);
2524 ndata[6] = (peer->pmax[afi][safi]);
e0701b79 2525
2526 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
2527 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
2528 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
2529 }
0a486e5f 2530
f14e6fdb
DS
2531 /* Dynamic peers will just close their connection. */
2532 if (peer_dynamic_neighbor (peer))
2533 return 1;
2534
0a486e5f 2535 /* restart timer start */
2536 if (peer->pmax_restart[afi][safi])
2537 {
2538 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
2539
16286195 2540 if (bgp_debug_neighbor_events(peer))
0a486e5f 2541 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2542 peer->host, peer->v_pmax_restart);
2543
2544 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2545 peer->v_pmax_restart);
2546 }
2547
e0701b79 2548 return 1;
2549 }
2550 else
2551 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2552
2553 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2554 {
2555 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2556 && ! always)
2557 return 0;
2558
16286195
DS
2559 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2560 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2561 peer->pmax[afi][safi]);
e0701b79 2562 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2563 }
e0701b79 2564 else
2565 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2566 return 0;
2567}
2568
b40d939b 2569/* Unconditionally remove the route from the RIB, without taking
2570 * damping into consideration (eg, because the session went down)
2571 */
94f2b392 2572static void
718e3744 2573bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2574 afi_t afi, safi_t safi)
2575{
902212c3 2576 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2577
2578 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2579 bgp_info_delete (rn, ri); /* keep historical info */
2580
b40d939b 2581 bgp_process (peer->bgp, rn, afi, safi);
718e3744 2582}
2583
94f2b392 2584static void
718e3744 2585bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
b40d939b 2586 afi_t afi, safi_t safi)
718e3744 2587{
718e3744 2588 int status = BGP_DAMP_NONE;
2589
b40d939b 2590 /* apply dampening, if result is suppressed, we'll be retaining
2591 * the bgp_info in the RIB for historical reference.
2592 */
2593 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2594 && peer->sort == BGP_PEER_EBGP)
b40d939b 2595 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2596 == BGP_DAMP_SUPPRESSED)
902212c3 2597 {
902212c3 2598 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2599 return;
2600 }
2601
2602 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 2603}
2604
fb018d25 2605static struct bgp_info *
7c8ff89e 2606info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
fb018d25
DS
2607 struct bgp_node *rn)
2608{
2609 struct bgp_info *new;
2610
2611 /* Make new BGP info. */
2612 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2613 new->type = type;
7c8ff89e 2614 new->instance = instance;
fb018d25
DS
2615 new->sub_type = sub_type;
2616 new->peer = peer;
2617 new->attr = attr;
2618 new->uptime = bgp_clock ();
2619 new->net = rn;
2620 return new;
2621}
2622
94f2b392 2623static void
cd808e74
DS
2624bgp_info_addpath_rx_str(struct bgp_info *ri, char *buf)
2625{
2626 if (ri && ri->addpath_rx_id)
2627 sprintf(buf, " with addpath ID %d", ri->addpath_rx_id);
2628 else
2629 sprintf(buf, "");
2630}
2631
2632static void
2633bgp_update_rsclient (struct peer *rsclient, u_int32_t addpath_id,
2634 afi_t afi, safi_t safi, struct attr *attr,
2635 struct peer *peer, struct prefix *p, int type,
2636 int sub_type, struct prefix_rd *prd, u_char *tag)
fee0f4c6 2637{
2638 struct bgp_node *rn;
2639 struct bgp *bgp;
558d1fec
JBD
2640 struct attr new_attr;
2641 struct attr_extra new_extra;
fee0f4c6 2642 struct attr *attr_new;
2643 struct attr *attr_new2;
2644 struct bgp_info *ri;
2645 struct bgp_info *new;
fd79ac91 2646 const char *reason;
fee0f4c6 2647 char buf[SU_ADDRSTRLEN];
cd808e74 2648 char buf2[30];
fee0f4c6 2649
2650 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
2651 if (peer == rsclient)
2652 return;
2653
2654 bgp = peer->bgp;
2655 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2656
2657 /* Check previously received route. */
2658 for (ri = rn->info; ri; ri = ri->next)
cd808e74
DS
2659 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2660 ri->addpath_rx_id == addpath_id)
fee0f4c6 2661 break;
2662
2663 /* AS path loop check. */
000e157c 2664 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
fee0f4c6 2665 {
2666 reason = "as-path contains our own AS;";
2667 goto filtered;
2668 }
2669
2670 /* Route reflector originator ID check. */
2671 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 2672 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
fee0f4c6 2673 {
2674 reason = "originator is us;";
2675 goto filtered;
2676 }
fb982c25 2677
558d1fec 2678 new_attr.extra = &new_extra;
fb982c25 2679 bgp_attr_dup (&new_attr, attr);
fee0f4c6 2680
2681 /* Apply export policy. */
2682 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
2683 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
2684 {
2685 reason = "export-policy;";
2686 goto filtered;
2687 }
2688
2689 attr_new2 = bgp_attr_intern (&new_attr);
fb982c25 2690
fee0f4c6 2691 /* Apply import policy. */
2692 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
2693 {
f6f434b2 2694 bgp_attr_unintern (&attr_new2);
fee0f4c6 2695
2696 reason = "import-policy;";
2697 goto filtered;
2698 }
2699
2700 attr_new = bgp_attr_intern (&new_attr);
f6f434b2 2701 bgp_attr_unintern (&attr_new2);
fee0f4c6 2702
2703 /* IPv4 unicast next hop check. */
5a616c08 2704 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
fee0f4c6 2705 {
733cd9e5 2706 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
fee0f4c6 2707 if (new_attr.nexthop.s_addr == 0
733cd9e5 2708 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
fee0f4c6 2709 {
f6f434b2 2710 bgp_attr_unintern (&attr_new);
fee0f4c6 2711
2712 reason = "martian next-hop;";
2713 goto filtered;
2714 }
2715 }
558d1fec 2716
fee0f4c6 2717 /* If the update is implicit withdraw. */
2718 if (ri)
2719 {
65957886 2720 ri->uptime = bgp_clock ();
fee0f4c6 2721
2722 /* Same attribute comes in. */
16d2e241
PJ
2723 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
2724 && attrhash_cmp (ri->attr, attr_new))
fee0f4c6 2725 {
2726
3f9c7369 2727 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2728 {
2729 bgp_info_addpath_rx_str(ri, buf2);
2730 zlog_debug ("%s rcvd %s/%d%s for RS-client %s...duplicate ignored",
2731 peer->host,
2732 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2733 p->prefixlen, buf2, rsclient->host);
2734 }
fee0f4c6 2735
228da428 2736 bgp_unlock_node (rn);
f6f434b2 2737 bgp_attr_unintern (&attr_new);
fee0f4c6 2738
228da428 2739 return;
fee0f4c6 2740 }
2741
16d2e241
PJ
2742 /* Withdraw/Announce before we fully processed the withdraw */
2743 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2744 bgp_info_restore (rn, ri);
2745
fee0f4c6 2746 /* Received Logging. */
3f9c7369 2747 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2748 {
2749 bgp_info_addpath_rx_str(ri, buf2);
2750 zlog_debug ("%s rcvd %s/%d%s for RS-client %s",
2751 peer->host,
2752 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2753 p->prefixlen, buf2, rsclient->host);
2754 }
fee0f4c6 2755
2756 /* The attribute is changed. */
1a392d46 2757 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
fee0f4c6 2758
2759 /* Update to new attribute. */
f6f434b2 2760 bgp_attr_unintern (&ri->attr);
fee0f4c6 2761 ri->attr = attr_new;
2762
2763 /* Update MPLS tag. */
2764 if (safi == SAFI_MPLS_VPN)
fb982c25 2765 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
fee0f4c6 2766
1a392d46 2767 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
fee0f4c6 2768
2769 /* Process change. */
2770 bgp_process (bgp, rn, afi, safi);
2771 bgp_unlock_node (rn);
2772
2773 return;
2774 }
2775
2776 /* Received Logging. */
3f9c7369 2777 if (bgp_debug_update(peer, p, NULL, 1))
fee0f4c6 2778 {
cd808e74
DS
2779 bgp_info_addpath_rx_str(ri, buf2);
2780 zlog_debug ("%s rcvd %s/%d%s for RS-client %s",
16286195
DS
2781 peer->host,
2782 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 2783 p->prefixlen, buf2, rsclient->host);
fee0f4c6 2784 }
2785
7c8ff89e 2786 new = info_make(type, sub_type, 0, peer, attr_new, rn);
fee0f4c6 2787
2788 /* Update MPLS tag. */
2789 if (safi == SAFI_MPLS_VPN)
fb982c25 2790 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
fee0f4c6 2791
1a392d46 2792 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
fee0f4c6 2793
2794 /* Register new BGP information. */
2795 bgp_info_add (rn, new);
200df115 2796
2797 /* route_node_get lock */
2798 bgp_unlock_node (rn);
2799
fee0f4c6 2800 /* Process change. */
2801 bgp_process (bgp, rn, afi, safi);
558d1fec 2802
fee0f4c6 2803 return;
2804
2805 filtered:
2806
2807 /* This BGP update is filtered. Log the reason then update BGP entry. */
3f9c7369 2808 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2809 {
2810 bgp_info_addpath_rx_str(ri, buf2);
2811 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED for RS-client %s due to: %s",
2812 peer->host,
2813 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2814 p->prefixlen, buf2, rsclient->host, reason);
2815 }
fee0f4c6 2816
2817 if (ri)
b40d939b 2818 bgp_rib_remove (rn, ri, peer, afi, safi);
fee0f4c6 2819
2820 bgp_unlock_node (rn);
558d1fec 2821
fee0f4c6 2822 return;
2823}
2824
94f2b392 2825static void
cd808e74
DS
2826bgp_withdraw_rsclient (struct peer *rsclient, u_int32_t addpath_id,
2827 afi_t afi, safi_t safi, struct peer *peer,
2828 struct prefix *p, int type, int sub_type,
2829 struct prefix_rd *prd, u_char *tag)
228da428 2830{
fee0f4c6 2831 struct bgp_node *rn;
2832 struct bgp_info *ri;
2833 char buf[SU_ADDRSTRLEN];
2834
2835 if (rsclient == peer)
228da428 2836 return;
fee0f4c6 2837
2838 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2839
2840 /* Lookup withdrawn route. */
2841 for (ri = rn->info; ri; ri = ri->next)
cd808e74
DS
2842 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2843 ri->addpath_rx_id == addpath_id)
fee0f4c6 2844 break;
2845
2846 /* Withdraw specified route from routing table. */
2847 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
b40d939b 2848 bgp_rib_withdraw (rn, ri, peer, afi, safi);
3f9c7369 2849 else if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2850 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2851 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2852 p->prefixlen);
fee0f4c6 2853
2854 /* Unlock bgp_node_get() lock. */
228da428
CC
2855 bgp_unlock_node (rn);
2856}
fee0f4c6 2857
94f2b392 2858static int
a82478b9
DS
2859bgp_update_main (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2860 struct attr *attr, afi_t afi, safi_t safi, int type,
2861 int sub_type, struct prefix_rd *prd, u_char *tag,
2862 int soft_reconfig)
718e3744 2863{
2864 int ret;
2865 int aspath_loop_count = 0;
2866 struct bgp_node *rn;
2867 struct bgp *bgp;
558d1fec
JBD
2868 struct attr new_attr;
2869 struct attr_extra new_extra;
718e3744 2870 struct attr *attr_new;
2871 struct bgp_info *ri;
2872 struct bgp_info *new;
fd79ac91 2873 const char *reason;
718e3744 2874 char buf[SU_ADDRSTRLEN];
cd808e74 2875 char buf2[30];
fc9a856f 2876 int connected = 0;
718e3744 2877
2878 bgp = peer->bgp;
fee0f4c6 2879 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
fb982c25 2880
718e3744 2881 /* When peer's soft reconfiguration enabled. Record input packet in
2882 Adj-RIBs-In. */
343aa822
JBD
2883 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2884 && peer != bgp->peer_self)
718e3744 2885 bgp_adj_in_set (rn, peer, attr);
2886
2887 /* Check previously received route. */
2888 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
2889 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2890 ri->addpath_rx_id == addpath_id)
718e3744 2891 break;
2892
2893 /* AS path local-as loop check. */
2894 if (peer->change_local_as)
2895 {
2896 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2897 aspath_loop_count = 1;
2898
2899 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2900 {
2901 reason = "as-path contains our own AS;";
2902 goto filtered;
2903 }
2904 }
2905
2906 /* AS path loop check. */
2907 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2908 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2909 && aspath_loop_check(attr->aspath, bgp->confed_id)
2910 > peer->allowas_in[afi][safi]))
2911 {
2912 reason = "as-path contains our own AS;";
2913 goto filtered;
2914 }
2915
2916 /* Route reflector originator ID check. */
2917 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 2918 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
718e3744 2919 {
2920 reason = "originator is us;";
2921 goto filtered;
2922 }
2923
2924 /* Route reflector cluster ID check. */
2925 if (bgp_cluster_filter (peer, attr))
2926 {
2927 reason = "reflected from the same cluster;";
2928 goto filtered;
2929 }
2930
2931 /* Apply incoming filter. */
2932 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2933 {
2934 reason = "filter;";
2935 goto filtered;
2936 }
2937
558d1fec 2938 new_attr.extra = &new_extra;
fb982c25 2939 bgp_attr_dup (&new_attr, attr);
718e3744 2940
c460e572
DL
2941 /* Apply incoming route-map.
2942 * NB: new_attr may now contain newly allocated values from route-map "set"
2943 * commands, so we need bgp_attr_flush in the error paths, until we intern
2944 * the attr (which takes over the memory references) */
0b16f239 2945 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
718e3744 2946 {
2947 reason = "route-map;";
c460e572 2948 bgp_attr_flush (&new_attr);
718e3744 2949 goto filtered;
2950 }
2951
2952 /* IPv4 unicast next hop check. */
2953 if (afi == AFI_IP && safi == SAFI_UNICAST)
2954 {
733cd9e5 2955 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
718e3744 2956 must not be my own address. */
10f9bf3f
JBD
2957 if (new_attr.nexthop.s_addr == 0
2958 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2959 || bgp_nexthop_self (&new_attr))
718e3744 2960 {
2961 reason = "martian next-hop;";
c460e572 2962 bgp_attr_flush (&new_attr);
718e3744 2963 goto filtered;
2964 }
2965 }
2966
2967 attr_new = bgp_attr_intern (&new_attr);
2968
2969 /* If the update is implicit withdraw. */
2970 if (ri)
2971 {
65957886 2972 ri->uptime = bgp_clock ();
718e3744 2973
2974 /* Same attribute comes in. */
16d2e241
PJ
2975 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2976 && attrhash_cmp (ri->attr, attr_new))
718e3744 2977 {
718e3744 2978 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2979 && peer->sort == BGP_PEER_EBGP
718e3744 2980 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2981 {
3f9c7369 2982 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
2983 {
2984 bgp_info_addpath_rx_str(ri, buf2);
2985 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
2986 peer->host,
2987 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74
DS
2988 p->prefixlen, buf2);
2989 }
718e3744 2990
902212c3 2991 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2992 {
2993 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2994 bgp_process (bgp, rn, afi, safi);
2995 }
718e3744 2996 }
16d2e241 2997 else /* Duplicate - odd */
718e3744 2998 {
3f9c7369 2999 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
3000 {
3001 if (!peer->rcvd_attr_printed)
3002 {
3003 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
3004 peer->rcvd_attr_printed = 1;
3005 }
3006
cd808e74
DS
3007 bgp_info_addpath_rx_str(ri, buf2);
3008 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
16286195
DS
3009 peer->host,
3010 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 3011 p->prefixlen, buf2);
16286195 3012 }
93406d87 3013
3014 /* graceful restart STALE flag unset. */
3015 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3016 {
1a392d46 3017 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
902212c3 3018 bgp_process (bgp, rn, afi, safi);
93406d87 3019 }
718e3744 3020 }
3021
3022 bgp_unlock_node (rn);
f6f434b2 3023 bgp_attr_unintern (&attr_new);
558d1fec 3024
718e3744 3025 return 0;
3026 }
3027
16d2e241
PJ
3028 /* Withdraw/Announce before we fully processed the withdraw */
3029 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3030 {
3f9c7369 3031 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
3032 {
3033 bgp_info_addpath_rx_str(ri, buf2);
3034 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
3035 peer->host,
3036 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3037 p->prefixlen, buf2);
3038 }
16d2e241
PJ
3039 bgp_info_restore (rn, ri);
3040 }
3041
718e3744 3042 /* Received Logging. */
3f9c7369 3043 if (bgp_debug_update(peer, p, NULL, 1))
cd808e74
DS
3044 {
3045 bgp_info_addpath_rx_str(ri, buf2);
3046 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
3047 peer->host,
3048 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74
DS
3049 p->prefixlen, buf2);
3050 }
718e3744 3051
93406d87 3052 /* graceful restart STALE flag unset. */
3053 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1a392d46 3054 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
93406d87 3055
718e3744 3056 /* The attribute is changed. */
1a392d46 3057 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
902212c3 3058
3059 /* implicit withdraw, decrement aggregate and pcount here.
3060 * only if update is accepted, they'll increment below.
3061 */
902212c3 3062 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3063
718e3744 3064 /* Update bgp route dampening information. */
3065 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 3066 && peer->sort == BGP_PEER_EBGP)
718e3744 3067 {
3068 /* This is implicit withdraw so we should update dampening
3069 information. */
3070 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
3071 bgp_damp_withdraw (ri, rn, afi, safi, 1);
718e3744 3072 }
3073
718e3744 3074 /* Update to new attribute. */
f6f434b2 3075 bgp_attr_unintern (&ri->attr);
718e3744 3076 ri->attr = attr_new;
3077
3078 /* Update MPLS tag. */
3079 if (safi == SAFI_MPLS_VPN)
fb982c25 3080 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
718e3744 3081
3082 /* Update bgp route dampening information. */
3083 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 3084 && peer->sort == BGP_PEER_EBGP)
718e3744 3085 {
3086 /* Now we do normal update dampening. */
3087 ret = bgp_damp_update (ri, rn, afi, safi);
3088 if (ret == BGP_DAMP_SUPPRESSED)
3089 {
3090 bgp_unlock_node (rn);
3091 return 0;
3092 }
3093 }
3094
3095 /* Nexthop reachability check. */
fc9a856f 3096 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
718e3744 3097 {
fc9a856f 3098 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
907f92c8
DS
3099 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
3100 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
fc9a856f
DS
3101 connected = 1;
3102 else
3103 connected = 0;
3104
75aead62 3105 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
1a392d46 3106 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 3107 else
fc9a856f
DS
3108 {
3109 if (BGP_DEBUG(nht, NHT))
3110 {
3111 char buf1[INET6_ADDRSTRLEN];
3112 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
3113 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3114 }
3115 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3116 }
718e3744 3117 }
3118 else
fc9a856f 3119 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 3120
3121 /* Process change. */
3122 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3123
3124 bgp_process (bgp, rn, afi, safi);
3125 bgp_unlock_node (rn);
558d1fec 3126
718e3744 3127 return 0;
a82478b9 3128 } // End of implicit withdraw
718e3744 3129
3130 /* Received Logging. */
3f9c7369 3131 if (bgp_debug_update(peer, p, NULL, 1))
718e3744 3132 {
16286195
DS
3133 if (!peer->rcvd_attr_printed)
3134 {
3135 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
3136 peer->rcvd_attr_printed = 1;
3137 }
3138
cd808e74
DS
3139 bgp_info_addpath_rx_str(ri, buf2);
3140 zlog_debug ("%s rcvd %s/%d%s",
16286195
DS
3141 peer->host,
3142 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 3143 p->prefixlen, buf2);
718e3744 3144 }
3145
718e3744 3146 /* Make new BGP info. */
7c8ff89e 3147 new = info_make(type, sub_type, 0, peer, attr_new, rn);
718e3744 3148
3149 /* Update MPLS tag. */
3150 if (safi == SAFI_MPLS_VPN)
fb982c25 3151 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
718e3744 3152
3153 /* Nexthop reachability check. */
fc9a856f
DS
3154 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
3155 {
3156 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
907f92c8
DS
3157 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
3158 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
fc9a856f
DS
3159 connected = 1;
3160 else
3161 connected = 0;
3162
75aead62 3163 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
1a392d46 3164 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 3165 else
fc9a856f
DS
3166 {
3167 if (BGP_DEBUG(nht, NHT))
3168 {
3169 char buf1[INET6_ADDRSTRLEN];
3170 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
3171 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3172 }
3173 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3174 }
718e3744 3175 }
3176 else
1a392d46 3177 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 3178
a82478b9
DS
3179 /* Addpath ID */
3180 new->addpath_rx_id = addpath_id;
3181 new->addpath_tx_id = 0;
3182
902212c3 3183 /* Increment prefix */
718e3744 3184 bgp_aggregate_increment (bgp, p, new, afi, safi);
3185
3186 /* Register new BGP information. */
3187 bgp_info_add (rn, new);
200df115 3188
3189 /* route_node_get lock */
3190 bgp_unlock_node (rn);
558d1fec 3191
718e3744 3192 /* If maximum prefix count is configured and current prefix
3193 count exeed it. */
e0701b79 3194 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
3195 return -1;
718e3744 3196
3197 /* Process change. */
3198 bgp_process (bgp, rn, afi, safi);
3199
3200 return 0;
3201
3202 /* This BGP update is filtered. Log the reason then update BGP
3203 entry. */
3204 filtered:
3f9c7369 3205 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
3206 {
3207 if (!peer->rcvd_attr_printed)
3208 {
3209 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
3210 peer->rcvd_attr_printed = 1;
3211 }
3212
cd808e74
DS
3213 bgp_info_addpath_rx_str(ri, buf2);
3214 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
16286195
DS
3215 peer->host,
3216 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
cd808e74 3217 p->prefixlen, buf2, reason);
16286195 3218 }
718e3744 3219
3220 if (ri)
b40d939b 3221 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 3222
3223 bgp_unlock_node (rn);
558d1fec 3224
718e3744 3225 return 0;
3226}
3227
fee0f4c6 3228int
a82478b9
DS
3229bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
3230 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
fee0f4c6 3231 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
3232{
3233 struct peer *rsclient;
1eb8ef25 3234 struct listnode *node, *nnode;
fee0f4c6 3235 struct bgp *bgp;
3236 int ret;
3237
a82478b9
DS
3238 ret = bgp_update_main (peer, p, addpath_id, attr, afi, safi, type, sub_type,
3239 prd, tag, soft_reconfig);
fee0f4c6 3240
3241 bgp = peer->bgp;
3242
3243 /* Process the update for each RS-client. */
1eb8ef25 3244 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 3245 {
3246 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
cd808e74 3247 bgp_update_rsclient (rsclient, addpath_id, afi, safi, attr, peer, p,
a82478b9 3248 type, sub_type, prd, tag);
fee0f4c6 3249 }
3250
3251 return ret;
3252}
3253
718e3744 3254int
a82478b9
DS
3255bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
3256 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
3257 struct prefix_rd *prd, u_char *tag)
718e3744 3258{
3259 struct bgp *bgp;
3260 char buf[SU_ADDRSTRLEN];
cd808e74 3261 char buf2[30];
718e3744 3262 struct bgp_node *rn;
3263 struct bgp_info *ri;
fee0f4c6 3264 struct peer *rsclient;
1eb8ef25 3265 struct listnode *node, *nnode;
718e3744 3266
3267 bgp = peer->bgp;
3268
fee0f4c6 3269 /* Process the withdraw for each RS-client. */
1eb8ef25 3270 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 3271 {
3272 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
cd808e74 3273 bgp_withdraw_rsclient (rsclient, addpath_id, afi, safi, peer, p, type,
a82478b9 3274 sub_type, prd, tag);
fee0f4c6 3275 }
3276
718e3744 3277 /* Lookup node. */
fee0f4c6 3278 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 3279
3280 /* If peer is soft reconfiguration enabled. Record input packet for
3281 further calculation. */
3282 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
3283 && peer != bgp->peer_self)
3284 bgp_adj_in_unset (rn, peer);
3285
3286 /* Lookup withdrawn route. */
3287 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
3288 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
3289 ri->addpath_rx_id == addpath_id)
718e3744 3290 break;
3291
cd808e74
DS
3292 /* Logging. */
3293 if (bgp_debug_update(peer, p, NULL, 1))
3294 {
3295 bgp_info_addpath_rx_str(ri, buf2);
3296 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
3297 peer->host,
3298 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3299 p->prefixlen, buf2);
3300 }
3301
718e3744 3302 /* Withdraw specified route from routing table. */
3303 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
b40d939b 3304 bgp_rib_withdraw (rn, ri, peer, afi, safi);
3f9c7369 3305 else if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
3306 zlog_debug ("%s Can't find the route %s/%d", peer->host,
3307 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3308 p->prefixlen);
718e3744 3309
3310 /* Unlock bgp_node_get() lock. */
3311 bgp_unlock_node (rn);
3312
3313 return 0;
3314}
6b0655a2 3315
718e3744 3316void
3317bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
3318{
3f9c7369
DS
3319 struct update_subgroup *subgrp;
3320 subgrp = peer_subgroup(peer, afi, safi);
3321 subgroup_default_originate(subgrp, withdraw);
3322}
6182d65b 3323
718e3744 3324
3f9c7369
DS
3325/*
3326 * bgp_stop_announce_route_timer
3327 */
3328void
3329bgp_stop_announce_route_timer (struct peer_af *paf)
3330{
3331 if (!paf->t_announce_route)
3332 return;
718e3744 3333
3f9c7369 3334 THREAD_TIMER_OFF (paf->t_announce_route);
718e3744 3335}
6b0655a2 3336
3f9c7369
DS
3337/*
3338 * bgp_announce_route_timer_expired
3339 *
3340 * Callback that is invoked when the route announcement timer for a
3341 * peer_af expires.
3342 */
3343static int
3344bgp_announce_route_timer_expired (struct thread *t)
718e3744 3345{
3f9c7369
DS
3346 struct peer_af *paf;
3347 struct peer *peer;
558d1fec 3348
718e3744 3349
3f9c7369
DS
3350 paf = THREAD_ARG (t);
3351 peer = paf->peer;
718e3744 3352
3f9c7369
DS
3353 assert (paf->t_announce_route);
3354 paf->t_announce_route = NULL;
558d1fec 3355
3f9c7369
DS
3356 if (peer->status != Established)
3357 return 0;
3358
3359 if (!peer->afc_nego[paf->afi][paf->safi])
3360 return 0;
3361
3362 peer_af_announce_route (paf, 1);
3363 return 0;
718e3744 3364}
3365
3f9c7369
DS
3366/*
3367 * bgp_announce_route
3368 *
3369 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
3370 */
718e3744 3371void
3372bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
3373{
3f9c7369
DS
3374 struct peer_af *paf;
3375 struct update_subgroup *subgrp;
718e3744 3376
3f9c7369
DS
3377 paf = peer_af_find (peer, afi, safi);
3378 if (!paf)
718e3744 3379 return;
3f9c7369 3380 subgrp = PAF_SUBGRP(paf);
718e3744 3381
3f9c7369
DS
3382 /*
3383 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
3384 * or a refresh has already been triggered.
3385 */
3386 if (!subgrp || paf->t_announce_route)
718e3744 3387 return;
3388
d889623f 3389 /*
3f9c7369
DS
3390 * Start a timer to stagger/delay the announce. This serves
3391 * two purposes - announcement can potentially be combined for
3392 * multiple peers and the announcement doesn't happen in the
3393 * vty context.
d889623f 3394 */
3f9c7369
DS
3395 THREAD_TIMER_MSEC_ON (master, paf->t_announce_route,
3396 bgp_announce_route_timer_expired, paf,
3397 (subgrp->peer_count == 1) ?
3398 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
3399 BGP_ANNOUNCE_ROUTE_DELAY_MS);
3400}
3401
3402/*
3403 * Announce routes from all AF tables to a peer.
3404 *
3405 * This should ONLY be called when there is a need to refresh the
3406 * routes to the peer based on a policy change for this peer alone
3407 * or a route refresh request received from the peer.
3408 * The operation will result in splitting the peer from its existing
3409 * subgroups and putting it in new subgroups.
3410 */
718e3744 3411void
3412bgp_announce_route_all (struct peer *peer)
3413{
3f9c7369
DS
3414 struct peer_af *paf;
3415 int af;
718e3744 3416 afi_t afi;
3417 safi_t safi;
3418
3419 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3420 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3421 bgp_announce_route (peer, afi, safi);
3422}
6b0655a2 3423
718e3744 3424static void
fee0f4c6 3425bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
8692c506 3426 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
fee0f4c6 3427{
3428 struct bgp_node *rn;
3429 struct bgp_adj_in *ain;
3430
3431 if (! table)
3432 table = rsclient->bgp->rib[afi][safi];
3433
3434 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3435 for (ain = rn->adj_in; ain; ain = ain->next)
3436 {
8692c506 3437 struct bgp_info *ri = rn->info;
d53d8fda 3438 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 3439
cd808e74
DS
3440 bgp_update_rsclient (rsclient, ri->addpath_rx_id, afi, safi, ain->attr,
3441 ain->peer, &rn->p, ZEBRA_ROUTE_BGP,
3442 BGP_ROUTE_NORMAL, prd, tag);
fee0f4c6 3443 }
3444}
3445
3446void
3447bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3448{
3449 struct bgp_table *table;
3450 struct bgp_node *rn;
3451
3452 if (safi != SAFI_MPLS_VPN)
8692c506 3453 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
fee0f4c6 3454
3455 else
3456 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
3457 rn = bgp_route_next (rn))
3458 if ((table = rn->info) != NULL)
8692c506
JBD
3459 {
3460 struct prefix_rd prd;
3461 prd.family = AF_UNSPEC;
3462 prd.prefixlen = 64;
3463 memcpy(&prd.val, rn->p.u.val, 8);
3464
3465 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
3466 }
fee0f4c6 3467}
6b0655a2 3468
fee0f4c6 3469static void
718e3744 3470bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
8692c506 3471 struct bgp_table *table, struct prefix_rd *prd)
718e3744 3472{
3473 int ret;
3474 struct bgp_node *rn;
3475 struct bgp_adj_in *ain;
3476
3477 if (! table)
3478 table = peer->bgp->rib[afi][safi];
3479
3480 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3481 for (ain = rn->adj_in; ain; ain = ain->next)
3482 {
3483 if (ain->peer == peer)
3484 {
8692c506 3485 struct bgp_info *ri = rn->info;
d53d8fda 3486 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 3487
a82478b9
DS
3488 ret = bgp_update (peer, &rn->p, ri->addpath_rx_id, ain->attr,
3489 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
d53d8fda 3490 prd, tag, 1);
8692c506 3491
718e3744 3492 if (ret < 0)
3493 {
3494 bgp_unlock_node (rn);
3495 return;
3496 }
3497 continue;
3498 }
3499 }
3500}
3501
3502void
3503bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
3504{
3505 struct bgp_node *rn;
3506 struct bgp_table *table;
3507
3508 if (peer->status != Established)
3509 return;
3510
3511 if (safi != SAFI_MPLS_VPN)
8692c506 3512 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
718e3744 3513 else
3514 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3515 rn = bgp_route_next (rn))
3516 if ((table = rn->info) != NULL)
8692c506
JBD
3517 {
3518 struct prefix_rd prd;
3519 prd.family = AF_UNSPEC;
3520 prd.prefixlen = 64;
3521 memcpy(&prd.val, rn->p.u.val, 8);
3522
3523 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
3524 }
718e3744 3525}
6b0655a2 3526
228da428
CC
3527
3528struct bgp_clear_node_queue
3529{
3530 struct bgp_node *rn;
3531 enum bgp_clear_route_type purpose;
3532};
3533
200df115 3534static wq_item_status
0fb58d5d 3535bgp_clear_route_node (struct work_queue *wq, void *data)
200df115 3536{
228da428
CC
3537 struct bgp_clear_node_queue *cnq = data;
3538 struct bgp_node *rn = cnq->rn;
64e580a7 3539 struct peer *peer = wq->spec.data;
718e3744 3540 struct bgp_info *ri;
67174041
AS
3541 afi_t afi = bgp_node_table (rn)->afi;
3542 safi_t safi = bgp_node_table (rn)->safi;
200df115 3543
64e580a7 3544 assert (rn && peer);
200df115 3545
64e580a7 3546 for (ri = rn->info; ri; ri = ri->next)
228da428 3547 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
200df115 3548 {
3549 /* graceful restart STALE flag set. */
64e580a7
PJ
3550 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
3551 && peer->nsf[afi][safi]
200df115 3552 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
1a392d46
PJ
3553 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
3554 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
200df115 3555 else
64e580a7 3556 bgp_rib_remove (rn, ri, peer, afi, safi);
200df115 3557 break;
3558 }
200df115 3559 return WQ_SUCCESS;
3560}
3561
3562static void
0fb58d5d 3563bgp_clear_node_queue_del (struct work_queue *wq, void *data)
200df115 3564{
228da428
CC
3565 struct bgp_clear_node_queue *cnq = data;
3566 struct bgp_node *rn = cnq->rn;
67174041 3567 struct bgp_table *table = bgp_node_table (rn);
64e580a7
PJ
3568
3569 bgp_unlock_node (rn);
228da428
CC
3570 bgp_table_unlock (table);
3571 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
200df115 3572}
3573
3574static void
94f2b392 3575bgp_clear_node_complete (struct work_queue *wq)
200df115 3576{
64e580a7
PJ
3577 struct peer *peer = wq->spec.data;
3578
3e0c78ef 3579 /* Tickle FSM to start moving again */
ca058a30 3580 BGP_EVENT_ADD (peer, Clearing_Completed);
228da428
CC
3581
3582 peer_unlock (peer); /* bgp_clear_route */
200df115 3583}
3584
3585static void
64e580a7 3586bgp_clear_node_queue_init (struct peer *peer)
200df115 3587{
a2943657 3588 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
64e580a7 3589
a2943657 3590 snprintf (wname, sizeof(wname), "clear %s", peer->host);
64e580a7
PJ
3591#undef CLEAR_QUEUE_NAME_LEN
3592
3593 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
200df115 3594 {
3595 zlog_err ("%s: Failed to allocate work queue", __func__);
3596 exit (1);
3597 }
64e580a7
PJ
3598 peer->clear_node_queue->spec.hold = 10;
3599 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
3600 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
3601 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
3602 peer->clear_node_queue->spec.max_retries = 0;
3603
3604 /* we only 'lock' this peer reference when the queue is actually active */
3605 peer->clear_node_queue->spec.data = peer;
200df115 3606}
718e3744 3607
200df115 3608static void
3609bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
228da428
CC
3610 struct bgp_table *table, struct peer *rsclient,
3611 enum bgp_clear_route_type purpose)
200df115 3612{
200df115 3613 struct bgp_node *rn;
3614
f2c31acb 3615
718e3744 3616 if (! table)
fee0f4c6 3617 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
64e580a7 3618
6cf159b9 3619 /* If still no table => afi/safi isn't configured at all or smth. */
3620 if (! table)
3621 return;
65ca75e0
PJ
3622
3623 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3624 {
f2c31acb
PJ
3625 struct bgp_info *ri;
3626 struct bgp_adj_in *ain;
3627 struct bgp_adj_out *aout;
f2c31acb
PJ
3628
3629 /* XXX:TODO: This is suboptimal, every non-empty route_node is
3630 * queued for every clearing peer, regardless of whether it is
3631 * relevant to the peer at hand.
3632 *
3633 * Overview: There are 3 different indices which need to be
3634 * scrubbed, potentially, when a peer is removed:
3635 *
3636 * 1 peer's routes visible via the RIB (ie accepted routes)
3637 * 2 peer's routes visible by the (optional) peer's adj-in index
3638 * 3 other routes visible by the peer's adj-out index
3639 *
3640 * 3 there is no hurry in scrubbing, once the struct peer is
3641 * removed from bgp->peer, we could just GC such deleted peer's
3642 * adj-outs at our leisure.
3643 *
3644 * 1 and 2 must be 'scrubbed' in some way, at least made
3645 * invisible via RIB index before peer session is allowed to be
3646 * brought back up. So one needs to know when such a 'search' is
3647 * complete.
3648 *
3649 * Ideally:
3650 *
3651 * - there'd be a single global queue or a single RIB walker
3652 * - rather than tracking which route_nodes still need to be
3653 * examined on a peer basis, we'd track which peers still
3654 * aren't cleared
3655 *
3656 * Given that our per-peer prefix-counts now should be reliable,
3657 * this may actually be achievable. It doesn't seem to be a huge
3658 * problem at this time,
3659 */
24e50f20
JBD
3660 for (ain = rn->adj_in; ain; ain = ain->next)
3661 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
3662 {
3663 bgp_adj_in_remove (rn, ain);
3664 bgp_unlock_node (rn);
3665 break;
3666 }
3f9c7369
DS
3667
3668 /*
3669 * Can't do this anymore. adj-outs are not maintained per peer.
3670 *
24e50f20
JBD
3671 for (aout = rn->adj_out; aout; aout = aout->next)
3672 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
3673 {
3674 bgp_adj_out_remove (rn, aout, peer, afi, safi);
3675 bgp_unlock_node (rn);
3676 break;
3677 }
3f9c7369 3678 */
f2c31acb 3679 for (ri = rn->info; ri; ri = ri->next)
228da428 3680 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
f2c31acb 3681 {
228da428
CC
3682 struct bgp_clear_node_queue *cnq;
3683
3684 /* both unlocked in bgp_clear_node_queue_del */
67174041 3685 bgp_table_lock (bgp_node_table (rn));
228da428
CC
3686 bgp_lock_node (rn);
3687 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
3688 sizeof (struct bgp_clear_node_queue));
3689 cnq->rn = rn;
3690 cnq->purpose = purpose;
3691 work_queue_add (peer->clear_node_queue, cnq);
3692 break;
f2c31acb 3693 }
65ca75e0
PJ
3694 }
3695 return;
3696}
3697
3698void
228da428
CC
3699bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
3700 enum bgp_clear_route_type purpose)
65ca75e0
PJ
3701{
3702 struct bgp_node *rn;
3703 struct bgp_table *table;
3704 struct peer *rsclient;
3705 struct listnode *node, *nnode;
6cf159b9 3706
64e580a7
PJ
3707 if (peer->clear_node_queue == NULL)
3708 bgp_clear_node_queue_init (peer);
200df115 3709
ca058a30
PJ
3710 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3711 * Idle until it receives a Clearing_Completed event. This protects
3712 * against peers which flap faster than we can we clear, which could
3713 * lead to:
64e580a7
PJ
3714 *
3715 * a) race with routes from the new session being installed before
3716 * clear_route_node visits the node (to delete the route of that
3717 * peer)
3718 * b) resource exhaustion, clear_route_node likely leads to an entry
3719 * on the process_main queue. Fast-flapping could cause that queue
3720 * to grow and grow.
200df115 3721 */
ca058a30
PJ
3722 if (!peer->clear_node_queue->thread)
3723 peer_lock (peer); /* bgp_clear_node_complete */
fee0f4c6 3724
228da428 3725 switch (purpose)
fee0f4c6 3726 {
228da428
CC
3727 case BGP_CLEAR_ROUTE_NORMAL:
3728 if (safi != SAFI_MPLS_VPN)
3729 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3730 else
3731 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3732 rn = bgp_route_next (rn))
3733 if ((table = rn->info) != NULL)
3734 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3735
3736 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3737 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3738 PEER_FLAG_RSERVER_CLIENT))
3739 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3740 break;
3741
3742 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
3743 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3744 break;
3745
3746 default:
3747 assert (0);
3748 break;
fee0f4c6 3749 }
65ca75e0 3750
ca058a30 3751 /* If no routes were cleared, nothing was added to workqueue, the
f2c31acb
PJ
3752 * completion function won't be run by workqueue code - call it here.
3753 * XXX: Actually, this assumption doesn't hold, see
3754 * bgp_clear_route_table(), we queue all non-empty nodes.
ca058a30
PJ
3755 *
3756 * Additionally, there is a presumption in FSM that clearing is only
f2c31acb
PJ
3757 * really needed if peer state is Established - peers in
3758 * pre-Established states shouldn't have any route-update state
3759 * associated with them (in or out).
ca058a30 3760 *
f2c31acb
PJ
3761 * We still can get here in pre-Established though, through
3762 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
3763 * check to ensure the assumption above holds.
ca058a30
PJ
3764 *
3765 * At some future point, this check could be move to the top of the
3766 * function, and do a quick early-return when state is
3767 * pre-Established, avoiding above list and table scans. Once we're
3768 * sure it is safe..
65ca75e0
PJ
3769 */
3770 if (!peer->clear_node_queue->thread)
3771 bgp_clear_node_complete (peer->clear_node_queue);
718e3744 3772}
3773
3774void
3775bgp_clear_route_all (struct peer *peer)
3776{
3777 afi_t afi;
3778 safi_t safi;
3779
3780 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3781 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
228da428 3782 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
718e3744 3783}
3784
3785void
3786bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3787{
3788 struct bgp_table *table;
3789 struct bgp_node *rn;
3790 struct bgp_adj_in *ain;
3791
3792 table = peer->bgp->rib[afi][safi];
3793
3794 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3795 for (ain = rn->adj_in; ain ; ain = ain->next)
3796 if (ain->peer == peer)
3797 {
3798 bgp_adj_in_remove (rn, ain);
3799 bgp_unlock_node (rn);
3800 break;
3801 }
3802}
93406d87 3803
3804void
3805bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3806{
3807 struct bgp_node *rn;
3808 struct bgp_info *ri;
3809 struct bgp_table *table;
3810
3811 table = peer->bgp->rib[afi][safi];
3812
3813 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3814 {
3815 for (ri = rn->info; ri; ri = ri->next)
3816 if (ri->peer == peer)
3817 {
3818 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3819 bgp_rib_remove (rn, ri, peer, afi, safi);
3820 break;
3821 }
3822 }
3823}
6b0655a2 3824
718e3744 3825/* Delete all kernel routes. */
3826void
66e5cd87 3827bgp_cleanup_routes (void)
718e3744 3828{
3829 struct bgp *bgp;
1eb8ef25 3830 struct listnode *node, *nnode;
718e3744 3831 struct bgp_node *rn;
3832 struct bgp_table *table;
3833 struct bgp_info *ri;
3834
1eb8ef25 3835 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 3836 {
3837 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3838
3839 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3840 for (ri = rn->info; ri; ri = ri->next)
3841 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3842 && ri->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
3843 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3844 ri->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 3845 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
718e3744 3846
3847 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3848
3849 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3850 for (ri = rn->info; ri; ri = ri->next)
3851 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3852 && ri->type == ZEBRA_ROUTE_BGP
f992e2a9
DS
3853 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3854 ri->sub_type == BGP_ROUTE_AGGREGATE))
5a616c08 3855 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
718e3744 3856 }
3857}
3858
3859void
66e5cd87 3860bgp_reset (void)
718e3744 3861{
3862 vty_reset ();
3863 bgp_zclient_reset ();
3864 access_list_reset ();
3865 prefix_list_reset ();
3866}
6b0655a2 3867
718e3744 3868/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3869 value. */
3870int
3871bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3872{
3873 u_char *pnt;
3874 u_char *lim;
3875 struct prefix p;
3876 int psize;
3877 int ret;
a82478b9
DS
3878 afi_t afi;
3879 safi_t safi;
3880 u_char addpath_encoded;
3881 u_int32_t addpath_id;
718e3744 3882
3883 /* Check peer status. */
3884 if (peer->status != Established)
3885 return 0;
3886
3887 pnt = packet->nlri;
3888 lim = pnt + packet->length;
a82478b9
DS
3889 afi = packet->afi;
3890 safi = packet->safi;
3891 addpath_id = 0;
3892
3893 addpath_encoded = (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3894 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
718e3744 3895
3896 for (; pnt < lim; pnt += psize)
3897 {
3898 /* Clear prefix structure. */
3899 memset (&p, 0, sizeof (struct prefix));
3900
a82478b9
DS
3901 if (addpath_encoded)
3902 {
cd808e74
DS
3903
3904 /* When packet overflow occurs return immediately. */
3905 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3906 return -1;
3907
a82478b9
DS
3908 addpath_id = ntohl(*((uint32_t*) pnt));
3909 pnt += BGP_ADDPATH_ID_LEN;
3910 }
3911
718e3744 3912 /* Fetch prefix length. */
3913 p.prefixlen = *pnt++;
a82478b9 3914 p.family = afi2family (afi);
718e3744 3915
3916 /* Already checked in nlri_sanity_check(). We do double check
3917 here. */
a82478b9
DS
3918 if ((afi == AFI_IP && p.prefixlen > 32)
3919 || (afi == AFI_IP6 && p.prefixlen > 128))
718e3744 3920 return -1;
3921
3922 /* Packet size overflow check. */
3923 psize = PSIZE (p.prefixlen);
3924
3925 /* When packet overflow occur return immediately. */
3926 if (pnt + psize > lim)
3927 return -1;
3928
3929 /* Fetch prefix from NLRI packet. */
3930 memcpy (&p.u.prefix, pnt, psize);
3931
3932 /* Check address. */
a82478b9 3933 if (afi == AFI_IP && safi == SAFI_UNICAST)
718e3744 3934 {
3935 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3936 {
f5ba3874 3937 /*
3938 * From draft-ietf-idr-bgp4-22, Section 6.3:
3939 * If a BGP router receives an UPDATE message with a
3940 * semantically incorrect NLRI field, in which a prefix is
3941 * semantically incorrect (eg. an unexpected multicast IP
3942 * address), it should ignore the prefix.
3943 */
16286195
DS
3944 zlog_err ("IPv4 unicast NLRI is multicast address %s",
3945 inet_ntoa (p.u.prefix4));
f5ba3874 3946
718e3744 3947 return -1;
3948 }
3949 }
3950
3951#ifdef HAVE_IPV6
3952 /* Check address. */
a82478b9 3953 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
718e3744 3954 {
3955 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3956 {
3957 char buf[BUFSIZ];
3958
16286195
DS
3959 zlog_warn ("IPv6 link-local NLRI received %s ignore this NLRI",
3960 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
718e3744 3961
3962 continue;
3963 }
3964 }
3965#endif /* HAVE_IPV6 */
3966
3967 /* Normal process. */
3968 if (attr)
a82478b9 3969 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
718e3744 3970 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3971 else
a82478b9 3972 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
718e3744 3973 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3974
3975 /* Address family configuration mismatch or maximum-prefix count
3976 overflow. */
3977 if (ret < 0)
3978 return -1;
3979 }
3980
3981 /* Packet length consistency check. */
3982 if (pnt != lim)
3983 return -1;
3984
3985 return 0;
3986}
3987
3988/* NLRI encode syntax check routine. */
3989int
a82478b9 3990bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi, u_char *pnt,
d889623f 3991 bgp_size_t length, int *numpfx)
718e3744 3992{
3993 u_char *end;
3994 u_char prefixlen;
3995 int psize;
a82478b9 3996 u_char addpath_encoded;
718e3744 3997
d889623f 3998 *numpfx = 0;
718e3744 3999 end = pnt + length;
4000
a82478b9
DS
4001 addpath_encoded = (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
4002 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
4003
718e3744 4004 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
4005 syntactic validity. If the field is syntactically incorrect,
4006 then the Error Subcode is set to Invalid Network Field. */
4007
4008 while (pnt < end)
4009 {
cd808e74 4010
a82478b9
DS
4011 /* If the NLRI is encoded using addpath then the first 4 bytes are
4012 * the addpath ID. */
4013 if (addpath_encoded)
cd808e74
DS
4014 {
4015 if (pnt + BGP_ADDPATH_ID_LEN > end)
4016 {
4017 zlog_err ("%s [Error] Update packet error"
4018 " (prefix data addpath overflow)",
4019 peer->host);
4020 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
4021 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
4022 return -1;
4023 }
4024 pnt += BGP_ADDPATH_ID_LEN;
4025 }
a82478b9 4026
718e3744 4027 prefixlen = *pnt++;
4028
4029 /* Prefix length check. */
4030 if ((afi == AFI_IP && prefixlen > 32)
4031 || (afi == AFI_IP6 && prefixlen > 128))
4032 {
16286195 4033 zlog_err ("%s [Error] Update packet error (wrong prefix length %d)",
718e3744 4034 peer->host, prefixlen);
4035 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
4036 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
4037 return -1;
4038 }
4039
4040 /* Packet size overflow check. */
4041 psize = PSIZE (prefixlen);
4042
4043 if (pnt + psize > end)
4044 {
16286195 4045 zlog_err ("%s [Error] Update packet error"
718e3744 4046 " (prefix data overflow prefix size is %d)",
4047 peer->host, psize);
4048 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
4049 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
4050 return -1;
4051 }
4052
4053 pnt += psize;
d889623f 4054 (*numpfx)++;
718e3744 4055 }
4056
4057 /* Packet length consistency check. */
4058 if (pnt != end)
4059 {
16286195 4060 zlog_err ("%s [Error] Update packet error"
718e3744 4061 " (prefix length mismatch with total length)",
4062 peer->host);
4063 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
4064 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
4065 return -1;
4066 }
4067 return 0;
4068}
6b0655a2 4069
94f2b392 4070static struct bgp_static *
66e5cd87 4071bgp_static_new (void)
718e3744 4072{
393deb9b 4073 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
718e3744 4074}
4075
94f2b392 4076static void
718e3744 4077bgp_static_free (struct bgp_static *bgp_static)
4078{
4079 if (bgp_static->rmap.name)
4080 free (bgp_static->rmap.name);
4081 XFREE (MTYPE_BGP_STATIC, bgp_static);
4082}
4083
94f2b392 4084static void
fee0f4c6 4085bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
4086 struct prefix *p, afi_t afi, safi_t safi)
4087{
4088 struct bgp_node *rn;
4089 struct bgp_info *ri;
4090
4091 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
4092
4093 /* Check selected route and self inserted route. */
4094 for (ri = rn->info; ri; ri = ri->next)
4095 if (ri->peer == bgp->peer_self
4096 && ri->type == ZEBRA_ROUTE_BGP
4097 && ri->sub_type == BGP_ROUTE_STATIC)
4098 break;
4099
4100 /* Withdraw static BGP route from routing table. */
4101 if (ri)
4102 {
fee0f4c6 4103 bgp_info_delete (rn, ri);
1a392d46 4104 bgp_process (bgp, rn, afi, safi);
fee0f4c6 4105 }
4106
4107 /* Unlock bgp_node_lookup. */
4108 bgp_unlock_node (rn);
4109}
4110
94f2b392 4111static void
fee0f4c6 4112bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
fb982c25
PJ
4113 struct bgp_static *bgp_static,
4114 afi_t afi, safi_t safi)
fee0f4c6 4115{
4116 struct bgp_node *rn;
4117 struct bgp_info *ri;
4118 struct bgp_info *new;
4119 struct bgp_info info;
fee0f4c6 4120 struct attr *attr_new;
e16a4133 4121 struct attr attr;
558d1fec
JBD
4122 struct attr new_attr;
4123 struct attr_extra new_extra;
fee0f4c6 4124 struct bgp *bgp;
4125 int ret;
4126 char buf[SU_ADDRSTRLEN];
4127
4128 bgp = rsclient->bgp;
4129
06e110f9
PJ
4130 assert (bgp_static);
4131 if (!bgp_static)
4132 return;
4133
fee0f4c6 4134 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
4135
4136 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
06e110f9
PJ
4137
4138 attr.nexthop = bgp_static->igpnexthop;
4139 attr.med = bgp_static->igpmetric;
4140 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
41367172 4141
41367172
PJ
4142 if (bgp_static->atomic)
4143 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
4144
fee0f4c6 4145 /* Apply network route-map for export to this rsclient. */
4146 if (bgp_static->rmap.name)
4147 {
fb982c25 4148 struct attr attr_tmp = attr;
fee0f4c6 4149 info.peer = rsclient;
fb982c25
PJ
4150 info.attr = &attr_tmp;
4151
fee0f4c6 4152 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
4153 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
4154
4155 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
4156
4157 rsclient->rmap_type = 0;
4158
4159 if (ret == RMAP_DENYMATCH)
4160 {
4161 /* Free uninterned attribute. */
fb982c25 4162 bgp_attr_flush (&attr_tmp);
fee0f4c6 4163
4164 /* Unintern original. */
f6f434b2 4165 aspath_unintern (&attr.aspath);
fee0f4c6 4166 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
fb982c25
PJ
4167 bgp_attr_extra_free (&attr);
4168
fee0f4c6 4169 return;
4170 }
fb982c25 4171 attr_new = bgp_attr_intern (&attr_tmp);
fee0f4c6 4172 }
4173 else
4174 attr_new = bgp_attr_intern (&attr);
558d1fec
JBD
4175
4176 new_attr.extra = &new_extra;
7badc263 4177 bgp_attr_dup(&new_attr, attr_new);
fb982c25 4178
fee0f4c6 4179 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
4180
fb982c25
PJ
4181 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
4182 == RMAP_DENY)
4183 {
fee0f4c6 4184 /* This BGP update is filtered. Log the reason then update BGP entry. */
3f9c7369 4185 if (bgp_debug_update(rsclient, p, NULL, 1))
16286195
DS
4186 zlog_debug ("Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
4187 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
4188 p->prefixlen, rsclient->host);
fee0f4c6 4189
4190 bgp->peer_self->rmap_type = 0;
4191
f6f434b2
PJ
4192 bgp_attr_unintern (&attr_new);
4193 aspath_unintern (&attr.aspath);
fb982c25 4194 bgp_attr_extra_free (&attr);
fee0f4c6 4195
4196 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
4197
4198 return;
fb982c25 4199 }
fee0f4c6 4200
4201 bgp->peer_self->rmap_type = 0;
4202
f6f434b2 4203 bgp_attr_unintern (&attr_new);
fee0f4c6 4204 attr_new = bgp_attr_intern (&new_attr);
4205
4206 for (ri = rn->info; ri; ri = ri->next)
4207 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
4208 && ri->sub_type == BGP_ROUTE_STATIC)
4209 break;
4210
4211 if (ri)
4212 {
8d45210e
AS
4213 if (attrhash_cmp (ri->attr, attr_new) &&
4214 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
fee0f4c6 4215 {
4216 bgp_unlock_node (rn);
f6f434b2
PJ
4217 bgp_attr_unintern (&attr_new);
4218 aspath_unintern (&attr.aspath);
fb982c25 4219 bgp_attr_extra_free (&attr);
fee0f4c6 4220 return;
4221 }
4222 else
4223 {
4224 /* The attribute is changed. */
1a392d46 4225 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
fee0f4c6 4226
4227 /* Rewrite BGP route information. */
8d45210e
AS
4228 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
4229 bgp_info_restore(rn, ri);
f6f434b2 4230 bgp_attr_unintern (&ri->attr);
fee0f4c6 4231 ri->attr = attr_new;
65957886 4232 ri->uptime = bgp_clock ();
fee0f4c6 4233
fc9a856f
DS
4234 /* Nexthop reachability check. */
4235 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4236 {
75aead62 4237 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
fc9a856f
DS
4238 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
4239 else
4240 {
4241 if (BGP_DEBUG(nht, NHT))
4242 {
4243 char buf1[INET6_ADDRSTRLEN];
4244 inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
4245 buf1, INET6_ADDRSTRLEN);
4246 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
4247 }
4248 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
4249 }
4250 }
fee0f4c6 4251 /* Process change. */
4252 bgp_process (bgp, rn, afi, safi);
4253 bgp_unlock_node (rn);
f6f434b2 4254 aspath_unintern (&attr.aspath);
fb982c25 4255 bgp_attr_extra_free (&attr);
fee0f4c6 4256 return;
fb982c25 4257 }
fee0f4c6 4258 }
fb018d25 4259
fee0f4c6 4260 /* Make new BGP info. */
7c8ff89e 4261 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
fb018d25 4262 attr_new, rn);
fc9a856f
DS
4263 /* Nexthop reachability check. */
4264 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4265 {
75aead62 4266 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
fc9a856f
DS
4267 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
4268 else
4269 {
4270 if (BGP_DEBUG(nht, NHT))
4271 {
4272 char buf1[INET6_ADDRSTRLEN];
4273 inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
4274 buf1, INET6_ADDRSTRLEN);
4275 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
4276 }
4277 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
4278 }
4279 }
4280 else
4281 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
fee0f4c6 4282
4283 /* Register new BGP information. */
4284 bgp_info_add (rn, new);
200df115 4285
4286 /* route_node_get lock */
4287 bgp_unlock_node (rn);
4288
fee0f4c6 4289 /* Process change. */
4290 bgp_process (bgp, rn, afi, safi);
4291
4292 /* Unintern original. */
f6f434b2 4293 aspath_unintern (&attr.aspath);
fb982c25 4294 bgp_attr_extra_free (&attr);
fee0f4c6 4295}
4296
94f2b392 4297static void
fee0f4c6 4298bgp_static_update_main (struct bgp *bgp, struct prefix *p,
fc9a856f 4299 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
718e3744 4300{
4301 struct bgp_node *rn;
4302 struct bgp_info *ri;
4303 struct bgp_info *new;
4304 struct bgp_info info;
e16a4133 4305 struct attr attr;
718e3744 4306 struct attr *attr_new;
4307 int ret;
4308
dd8103a9
PJ
4309 assert (bgp_static);
4310 if (!bgp_static)
4311 return;
4312
fee0f4c6 4313 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 4314
4315 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
dd8103a9
PJ
4316
4317 attr.nexthop = bgp_static->igpnexthop;
4318 attr.med = bgp_static->igpmetric;
4319 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
718e3744 4320
41367172
PJ
4321 if (bgp_static->atomic)
4322 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
4323
718e3744 4324 /* Apply route-map. */
4325 if (bgp_static->rmap.name)
4326 {
fb982c25 4327 struct attr attr_tmp = attr;
718e3744 4328 info.peer = bgp->peer_self;
286e1e71 4329 info.attr = &attr_tmp;
718e3744 4330
fee0f4c6 4331 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
4332
718e3744 4333 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
286e1e71 4334
fee0f4c6 4335 bgp->peer_self->rmap_type = 0;
4336
718e3744 4337 if (ret == RMAP_DENYMATCH)
4338 {
4339 /* Free uninterned attribute. */
286e1e71 4340 bgp_attr_flush (&attr_tmp);
718e3744 4341
4342 /* Unintern original. */
f6f434b2 4343 aspath_unintern (&attr.aspath);
fb982c25 4344 bgp_attr_extra_free (&attr);
718e3744 4345 bgp_static_withdraw (bgp, p, afi, safi);
4346 return;
4347 }
286e1e71 4348 attr_new = bgp_attr_intern (&attr_tmp);
718e3744 4349 }
286e1e71 4350 else
4351 attr_new = bgp_attr_intern (&attr);
718e3744 4352
4353 for (ri = rn->info; ri; ri = ri->next)
4354 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
4355 && ri->sub_type == BGP_ROUTE_STATIC)
4356 break;
4357
4358 if (ri)
4359 {
8d45210e
AS
4360 if (attrhash_cmp (ri->attr, attr_new) &&
4361 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
718e3744 4362 {
4363 bgp_unlock_node (rn);
f6f434b2
PJ
4364 bgp_attr_unintern (&attr_new);
4365 aspath_unintern (&attr.aspath);
fb982c25 4366 bgp_attr_extra_free (&attr);
718e3744 4367 return;
4368 }
4369 else
4370 {
4371 /* The attribute is changed. */
1a392d46 4372 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4373
4374 /* Rewrite BGP route information. */
8d45210e
AS
4375 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
4376 bgp_info_restore(rn, ri);
4377 else
4378 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
f6f434b2 4379 bgp_attr_unintern (&ri->attr);
718e3744 4380 ri->attr = attr_new;
65957886 4381 ri->uptime = bgp_clock ();
718e3744 4382
fc9a856f
DS
4383 /* Nexthop reachability check. */
4384 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4385 {
75aead62 4386 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
fc9a856f
DS
4387 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
4388 else
4389 {
4390 if (BGP_DEBUG(nht, NHT))
4391 {
4392 char buf1[INET6_ADDRSTRLEN];
4393 inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
4394 buf1, INET6_ADDRSTRLEN);
4395 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
4396 }
4397 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
4398 }
4399 }
718e3744 4400 /* Process change. */
4401 bgp_aggregate_increment (bgp, p, ri, afi, safi);
4402 bgp_process (bgp, rn, afi, safi);
4403 bgp_unlock_node (rn);
f6f434b2 4404 aspath_unintern (&attr.aspath);
fb982c25 4405 bgp_attr_extra_free (&attr);
718e3744 4406 return;
4407 }
4408 }
4409
4410 /* Make new BGP info. */
7c8ff89e 4411 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
fb018d25 4412 rn);
fc9a856f
DS
4413 /* Nexthop reachability check. */
4414 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4415 {
75aead62 4416 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
fc9a856f
DS
4417 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
4418 else
4419 {
4420 if (BGP_DEBUG(nht, NHT))
4421 {
4422 char buf1[INET6_ADDRSTRLEN];
4423 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1,
4424 INET6_ADDRSTRLEN);
4425 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
4426 }
4427 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
4428 }
4429 }
4430 else
4431 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 4432
4433 /* Aggregate address increment. */
4434 bgp_aggregate_increment (bgp, p, new, afi, safi);
4435
4436 /* Register new BGP information. */
4437 bgp_info_add (rn, new);
200df115 4438
4439 /* route_node_get lock */
4440 bgp_unlock_node (rn);
4441
718e3744 4442 /* Process change. */
4443 bgp_process (bgp, rn, afi, safi);
4444
4445 /* Unintern original. */
f6f434b2 4446 aspath_unintern (&attr.aspath);
fb982c25 4447 bgp_attr_extra_free (&attr);
718e3744 4448}
4449
fee0f4c6 4450void
4451bgp_static_update (struct bgp *bgp, struct prefix *p,
4452 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
4453{
4454 struct peer *rsclient;
1eb8ef25 4455 struct listnode *node, *nnode;
fee0f4c6 4456
4457 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
4458
1eb8ef25 4459 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 4460 {
da5b30f6
PJ
4461 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
4462 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
fee0f4c6 4463 }
4464}
4465
94f2b392 4466static void
4c9641ba
ML
4467bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
4468 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 4469{
4470 struct bgp_node *rn;
4471 struct bgp_info *new;
fb982c25 4472
fee0f4c6 4473 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 4474
4475 /* Make new BGP info. */
7c8ff89e 4476 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
fb018d25
DS
4477 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
4478
718e3744 4479 SET_FLAG (new->flags, BGP_INFO_VALID);
fb982c25
PJ
4480 new->extra = bgp_info_extra_new();
4481 memcpy (new->extra->tag, tag, 3);
718e3744 4482
4483 /* Aggregate address increment. */
200df115 4484 bgp_aggregate_increment (bgp, p, new, afi, safi);
718e3744 4485
4486 /* Register new BGP information. */
200df115 4487 bgp_info_add (rn, new);
718e3744 4488
200df115 4489 /* route_node_get lock */
4490 bgp_unlock_node (rn);
4491
718e3744 4492 /* Process change. */
4493 bgp_process (bgp, rn, afi, safi);
4494}
4495
4496void
4497bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
4498 safi_t safi)
4499{
4500 struct bgp_node *rn;
4501 struct bgp_info *ri;
4502
fee0f4c6 4503 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 4504
4505 /* Check selected route and self inserted route. */
4506 for (ri = rn->info; ri; ri = ri->next)
4507 if (ri->peer == bgp->peer_self
4508 && ri->type == ZEBRA_ROUTE_BGP
4509 && ri->sub_type == BGP_ROUTE_STATIC)
4510 break;
4511
4512 /* Withdraw static BGP route from routing table. */
4513 if (ri)
4514 {
4515 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
fc9a856f 4516 bgp_unlink_nexthop(ri);
718e3744 4517 bgp_info_delete (rn, ri);
1a392d46 4518 bgp_process (bgp, rn, afi, safi);
718e3744 4519 }
4520
4521 /* Unlock bgp_node_lookup. */
4522 bgp_unlock_node (rn);
4523}
4524
fee0f4c6 4525void
4526bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
4527{
4528 struct bgp_static *bgp_static;
4529 struct bgp *bgp;
4530 struct bgp_node *rn;
4531 struct prefix *p;
4532
4533 bgp = rsclient->bgp;
4534
4535 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4536 if ((bgp_static = rn->info) != NULL)
4537 {
4538 p = &rn->p;
4539
4540 bgp_static_update_rsclient (rsclient, p, bgp_static,
4541 afi, safi);
4542 }
4543}
4544
94f2b392 4545static void
4c9641ba
ML
4546bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
4547 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 4548{
4549 struct bgp_node *rn;
4550 struct bgp_info *ri;
4551
fee0f4c6 4552 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 4553
4554 /* Check selected route and self inserted route. */
4555 for (ri = rn->info; ri; ri = ri->next)
4556 if (ri->peer == bgp->peer_self
4557 && ri->type == ZEBRA_ROUTE_BGP
4558 && ri->sub_type == BGP_ROUTE_STATIC)
4559 break;
4560
4561 /* Withdraw static BGP route from routing table. */
4562 if (ri)
4563 {
4564 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
718e3744 4565 bgp_info_delete (rn, ri);
1a392d46 4566 bgp_process (bgp, rn, afi, safi);
718e3744 4567 }
4568
4569 /* Unlock bgp_node_lookup. */
4570 bgp_unlock_node (rn);
4571}
4572
4573/* Configure static BGP network. When user don't run zebra, static
4574 route should be installed as valid. */
94f2b392 4575static int
fd79ac91 4576bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
c8f3fe30 4577 afi_t afi, safi_t safi, const char *rmap, int backdoor)
718e3744 4578{
4579 int ret;
4580 struct prefix p;
4581 struct bgp_static *bgp_static;
4582 struct bgp_node *rn;
41367172 4583 u_char need_update = 0;
718e3744 4584
4585 /* Convert IP prefix string to struct prefix. */
4586 ret = str2prefix (ip_str, &p);
4587 if (! ret)
4588 {
4589 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4590 return CMD_WARNING;
4591 }
4592#ifdef HAVE_IPV6
4593 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4594 {
4595 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4596 VTY_NEWLINE);
4597 return CMD_WARNING;
4598 }
4599#endif /* HAVE_IPV6 */
4600
4601 apply_mask (&p);
4602
4603 /* Set BGP static route configuration. */
4604 rn = bgp_node_get (bgp->route[afi][safi], &p);
4605
4606 if (rn->info)
4607 {
4608 /* Configuration change. */
4609 bgp_static = rn->info;
4610
4611 /* Check previous routes are installed into BGP. */
c8f3fe30
PJ
4612 if (bgp_static->valid && bgp_static->backdoor != backdoor)
4613 need_update = 1;
41367172 4614
718e3744 4615 bgp_static->backdoor = backdoor;
41367172 4616
718e3744 4617 if (rmap)
4618 {
4619 if (bgp_static->rmap.name)
4620 free (bgp_static->rmap.name);
4621 bgp_static->rmap.name = strdup (rmap);
4622 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4623 }
4624 else
4625 {
4626 if (bgp_static->rmap.name)
4627 free (bgp_static->rmap.name);
4628 bgp_static->rmap.name = NULL;
4629 bgp_static->rmap.map = NULL;
4630 bgp_static->valid = 0;
4631 }
4632 bgp_unlock_node (rn);
4633 }
4634 else
4635 {
4636 /* New configuration. */
4637 bgp_static = bgp_static_new ();
4638 bgp_static->backdoor = backdoor;
4639 bgp_static->valid = 0;
4640 bgp_static->igpmetric = 0;
4641 bgp_static->igpnexthop.s_addr = 0;
41367172 4642
718e3744 4643 if (rmap)
4644 {
4645 if (bgp_static->rmap.name)
4646 free (bgp_static->rmap.name);
4647 bgp_static->rmap.name = strdup (rmap);
4648 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4649 }
4650 rn->info = bgp_static;
4651 }
4652
fc9a856f
DS
4653 bgp_static->valid = 1;
4654 if (need_update)
4655 bgp_static_withdraw (bgp, &p, afi, safi);
718e3744 4656
fc9a856f
DS
4657 if (! bgp_static->backdoor)
4658 bgp_static_update (bgp, &p, bgp_static, afi, safi);
718e3744 4659
4660 return CMD_SUCCESS;
4661}
4662
4663/* Configure static BGP network. */
94f2b392 4664static int
fd79ac91 4665bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4c9641ba 4666 afi_t afi, safi_t safi)
718e3744 4667{
4668 int ret;
4669 struct prefix p;
4670 struct bgp_static *bgp_static;
4671 struct bgp_node *rn;
4672
4673 /* Convert IP prefix string to struct prefix. */
4674 ret = str2prefix (ip_str, &p);
4675 if (! ret)
4676 {
4677 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4678 return CMD_WARNING;
4679 }
4680#ifdef HAVE_IPV6
4681 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4682 {
4683 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4684 VTY_NEWLINE);
4685 return CMD_WARNING;
4686 }
4687#endif /* HAVE_IPV6 */
4688
4689 apply_mask (&p);
4690
4691 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4692 if (! rn)
4693 {
4694 vty_out (vty, "%% Can't find specified static route configuration.%s",
4695 VTY_NEWLINE);
4696 return CMD_WARNING;
4697 }
4698
4699 bgp_static = rn->info;
41367172 4700
718e3744 4701 /* Update BGP RIB. */
4702 if (! bgp_static->backdoor)
4703 bgp_static_withdraw (bgp, &p, afi, safi);
4704
4705 /* Clear configuration. */
fc9a856f 4706 bgp_unlink_nexthop(bgp_static);
718e3744 4707 bgp_static_free (bgp_static);
4708 rn->info = NULL;
4709 bgp_unlock_node (rn);
4710 bgp_unlock_node (rn);
4711
4712 return CMD_SUCCESS;
4713}
4714
4715/* Called from bgp_delete(). Delete all static routes from the BGP
4716 instance. */
4717void
4718bgp_static_delete (struct bgp *bgp)
4719{
4720 afi_t afi;
4721 safi_t safi;
4722 struct bgp_node *rn;
4723 struct bgp_node *rm;
4724 struct bgp_table *table;
4725 struct bgp_static *bgp_static;
4726
4727 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4728 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4729 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4730 if (rn->info != NULL)
4731 {
4732 if (safi == SAFI_MPLS_VPN)
4733 {
4734 table = rn->info;
4735
4736 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4737 {
4738 bgp_static = rn->info;
4739 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
4740 AFI_IP, SAFI_MPLS_VPN,
4741 (struct prefix_rd *)&rn->p,
4742 bgp_static->tag);
4743 bgp_static_free (bgp_static);
4744 rn->info = NULL;
4745 bgp_unlock_node (rn);
4746 }
4747 }
4748 else
4749 {
4750 bgp_static = rn->info;
4751 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4752 bgp_static_free (bgp_static);
4753 rn->info = NULL;
4754 bgp_unlock_node (rn);
4755 }
4756 }
4757}
4758
4759int
fd79ac91 4760bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
4761 const char *tag_str)
718e3744 4762{
4763 int ret;
4764 struct prefix p;
4765 struct prefix_rd prd;
4766 struct bgp *bgp;
4767 struct bgp_node *prn;
4768 struct bgp_node *rn;
4769 struct bgp_table *table;
4770 struct bgp_static *bgp_static;
4771 u_char tag[3];
4772
4773 bgp = vty->index;
4774
4775 ret = str2prefix (ip_str, &p);
4776 if (! ret)
4777 {
4778 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4779 return CMD_WARNING;
4780 }
4781 apply_mask (&p);
4782
4783 ret = str2prefix_rd (rd_str, &prd);
4784 if (! ret)
4785 {
4786 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4787 return CMD_WARNING;
4788 }
4789
4790 ret = str2tag (tag_str, tag);
4791 if (! ret)
4792 {
4793 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4794 return CMD_WARNING;
4795 }
4796
4797 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4798 (struct prefix *)&prd);
4799 if (prn->info == NULL)
64e580a7 4800 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
718e3744 4801 else
4802 bgp_unlock_node (prn);
4803 table = prn->info;
4804
4805 rn = bgp_node_get (table, &p);
4806
4807 if (rn->info)
4808 {
4809 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4810 bgp_unlock_node (rn);
4811 }
4812 else
4813 {
4814 /* New configuration. */
4815 bgp_static = bgp_static_new ();
4816 bgp_static->valid = 1;
4817 memcpy (bgp_static->tag, tag, 3);
4818 rn->info = bgp_static;
4819
4820 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4821 }
4822
4823 return CMD_SUCCESS;
4824}
4825
4826/* Configure static BGP network. */
4827int
fd79ac91 4828bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
4829 const char *rd_str, const char *tag_str)
718e3744 4830{
4831 int ret;
4832 struct bgp *bgp;
4833 struct prefix p;
4834 struct prefix_rd prd;
4835 struct bgp_node *prn;
4836 struct bgp_node *rn;
4837 struct bgp_table *table;
4838 struct bgp_static *bgp_static;
4839 u_char tag[3];
4840
4841 bgp = vty->index;
4842
4843 /* Convert IP prefix string to struct prefix. */
4844 ret = str2prefix (ip_str, &p);
4845 if (! ret)
4846 {
4847 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4848 return CMD_WARNING;
4849 }
4850 apply_mask (&p);
4851
4852 ret = str2prefix_rd (rd_str, &prd);
4853 if (! ret)
4854 {
4855 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4856 return CMD_WARNING;
4857 }
4858
4859 ret = str2tag (tag_str, tag);
4860 if (! ret)
4861 {
4862 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4863 return CMD_WARNING;
4864 }
4865
4866 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4867 (struct prefix *)&prd);
4868 if (prn->info == NULL)
64e580a7 4869 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
718e3744 4870 else
4871 bgp_unlock_node (prn);
4872 table = prn->info;
4873
4874 rn = bgp_node_lookup (table, &p);
4875
4876 if (rn)
4877 {
4878 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4879
4880 bgp_static = rn->info;
4881 bgp_static_free (bgp_static);
4882 rn->info = NULL;
4883 bgp_unlock_node (rn);
4884 bgp_unlock_node (rn);
4885 }
4886 else
4887 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4888
4889 return CMD_SUCCESS;
4890}
6b0655a2 4891
73ac8160
DS
4892static int
4893bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4894 const char *rmap_name)
4895{
4896 struct bgp_rmap *rmap;
4897
4898 rmap = &bgp->table_map[afi][safi];
4899 if (rmap_name)
4900 {
4901 if (rmap->name)
4902 free (rmap->name);
4903 rmap->name = strdup (rmap_name);
4904 rmap->map = route_map_lookup_by_name (rmap_name);
4905 }
4906 else
4907 {
4908 if (rmap->name)
4909 free (rmap->name);
4910 rmap->name = NULL;
4911 rmap->map = NULL;
4912 }
4913
4914 bgp_zebra_announce_table(bgp, afi, safi);
4915
4916 return CMD_SUCCESS;
4917}
4918
4919static int
4920bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4921 const char *rmap_name)
4922{
4923 struct bgp_rmap *rmap;
4924
4925 rmap = &bgp->table_map[afi][safi];
4926 if (rmap->name)
4927 free (rmap->name);
4928 rmap->name = NULL;
4929 rmap->map = NULL;
4930
4931 bgp_zebra_announce_table(bgp, afi, safi);
4932
4933 return CMD_SUCCESS;
4934}
4935
4936int
4937bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4938 safi_t safi, int *write)
4939{
4940 if (bgp->table_map[afi][safi].name)
4941 {
4942 bgp_config_write_family_header (vty, afi, safi, write);
4943 vty_out (vty, " table-map %s%s",
4944 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4945 }
4946
4947 return 0;
4948}
4949
4950
4951DEFUN (bgp_table_map,
4952 bgp_table_map_cmd,
4953 "table-map WORD",
4954 "BGP table to RIB route download filter\n"
4955 "Name of the route map\n")
4956{
4957 return bgp_table_map_set (vty, vty->index,
4958 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4959}
4960DEFUN (no_bgp_table_map,
4961 no_bgp_table_map_cmd,
4962 "no table-map WORD",
4963 "BGP table to RIB route download filter\n"
4964 "Name of the route map\n")
4965{
4966 return bgp_table_map_unset (vty, vty->index,
4967 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4968}
4969
718e3744 4970DEFUN (bgp_network,
4971 bgp_network_cmd,
4972 "network A.B.C.D/M",
4973 "Specify a network to announce via BGP\n"
4974 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4975{
4976 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 4977 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4978}
4979
4980DEFUN (bgp_network_route_map,
4981 bgp_network_route_map_cmd,
4982 "network A.B.C.D/M route-map WORD",
4983 "Specify a network to announce via BGP\n"
4984 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4985 "Route-map to modify the attributes\n"
4986 "Name of the route map\n")
4987{
4988 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 4989 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 4990}
4991
4992DEFUN (bgp_network_backdoor,
4993 bgp_network_backdoor_cmd,
4994 "network A.B.C.D/M backdoor",
4995 "Specify a network to announce via BGP\n"
4996 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4997 "Specify a BGP backdoor route\n")
4998{
41367172 4999 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
c8f3fe30 5000 NULL, 1);
718e3744 5001}
5002
5003DEFUN (bgp_network_mask,
5004 bgp_network_mask_cmd,
5005 "network A.B.C.D mask A.B.C.D",
5006 "Specify a network to announce via BGP\n"
5007 "Network number\n"
5008 "Network mask\n"
5009 "Network mask\n")
5010{
5011 int ret;
5012 char prefix_str[BUFSIZ];
41367172 5013
718e3744 5014 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5015 if (! ret)
5016 {
5017 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5018 return CMD_WARNING;
5019 }
5020
5021 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 5022 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 5023}
5024
5025DEFUN (bgp_network_mask_route_map,
5026 bgp_network_mask_route_map_cmd,
5027 "network A.B.C.D mask A.B.C.D route-map WORD",
5028 "Specify a network to announce via BGP\n"
5029 "Network number\n"
5030 "Network mask\n"
5031 "Network mask\n"
5032 "Route-map to modify the attributes\n"
5033 "Name of the route map\n")
5034{
5035 int ret;
5036 char prefix_str[BUFSIZ];
41367172 5037
718e3744 5038 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5039 if (! ret)
5040 {
5041 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5042 return CMD_WARNING;
5043 }
5044
5045 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 5046 AFI_IP, bgp_node_safi (vty), argv[2], 0);
718e3744 5047}
5048
5049DEFUN (bgp_network_mask_backdoor,
5050 bgp_network_mask_backdoor_cmd,
5051 "network A.B.C.D mask A.B.C.D backdoor",
5052 "Specify a network to announce via BGP\n"
5053 "Network number\n"
5054 "Network mask\n"
5055 "Network mask\n"
5056 "Specify a BGP backdoor route\n")
5057{
5058 int ret;
5059 char prefix_str[BUFSIZ];
41367172 5060
718e3744 5061 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5062 if (! ret)
5063 {
5064 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5065 return CMD_WARNING;
5066 }
5067
41367172 5068 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 5069 NULL, 1);
718e3744 5070}
5071
5072DEFUN (bgp_network_mask_natural,
5073 bgp_network_mask_natural_cmd,
5074 "network A.B.C.D",
5075 "Specify a network to announce via BGP\n"
5076 "Network number\n")
5077{
5078 int ret;
5079 char prefix_str[BUFSIZ];
5080
5081 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
5082 if (! ret)
5083 {
5084 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5085 return CMD_WARNING;
5086 }
5087
5088 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 5089 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 5090}
5091
5092DEFUN (bgp_network_mask_natural_route_map,
5093 bgp_network_mask_natural_route_map_cmd,
5094 "network A.B.C.D route-map WORD",
5095 "Specify a network to announce via BGP\n"
5096 "Network number\n"
5097 "Route-map to modify the attributes\n"
5098 "Name of the route map\n")
5099{
5100 int ret;
5101 char prefix_str[BUFSIZ];
5102
5103 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
5104 if (! ret)
5105 {
5106 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5107 return CMD_WARNING;
5108 }
5109
5110 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 5111 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 5112}
5113
5114DEFUN (bgp_network_mask_natural_backdoor,
5115 bgp_network_mask_natural_backdoor_cmd,
5116 "network A.B.C.D backdoor",
5117 "Specify a network to announce via BGP\n"
5118 "Network number\n"
5119 "Specify a BGP backdoor route\n")
5120{
5121 int ret;
5122 char prefix_str[BUFSIZ];
5123
5124 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
5125 if (! ret)
5126 {
5127 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5128 return CMD_WARNING;
5129 }
5130
41367172 5131 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 5132 NULL, 1);
718e3744 5133}
5134
5135DEFUN (no_bgp_network,
5136 no_bgp_network_cmd,
5137 "no network A.B.C.D/M",
5138 NO_STR
5139 "Specify a network to announce via BGP\n"
5140 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5141{
5142 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
5143 bgp_node_safi (vty));
5144}
5145
5146ALIAS (no_bgp_network,
5147 no_bgp_network_route_map_cmd,
5148 "no network A.B.C.D/M route-map WORD",
5149 NO_STR
5150 "Specify a network to announce via BGP\n"
5151 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5152 "Route-map to modify the attributes\n"
5153 "Name of the route map\n")
5154
5155ALIAS (no_bgp_network,
5156 no_bgp_network_backdoor_cmd,
5157 "no network A.B.C.D/M backdoor",
5158 NO_STR
5159 "Specify a network to announce via BGP\n"
5160 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5161 "Specify a BGP backdoor route\n")
5162
5163DEFUN (no_bgp_network_mask,
5164 no_bgp_network_mask_cmd,
5165 "no network A.B.C.D mask A.B.C.D",
5166 NO_STR
5167 "Specify a network to announce via BGP\n"
5168 "Network number\n"
5169 "Network mask\n"
5170 "Network mask\n")
5171{
5172 int ret;
5173 char prefix_str[BUFSIZ];
5174
5175 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5176 if (! ret)
5177 {
5178 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5179 return CMD_WARNING;
5180 }
5181
5182 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
5183 bgp_node_safi (vty));
5184}
5185
5186ALIAS (no_bgp_network_mask,
5187 no_bgp_network_mask_route_map_cmd,
5188 "no network A.B.C.D mask A.B.C.D route-map WORD",
5189 NO_STR
5190 "Specify a network to announce via BGP\n"
5191 "Network number\n"
5192 "Network mask\n"
5193 "Network mask\n"
5194 "Route-map to modify the attributes\n"
5195 "Name of the route map\n")
5196
5197ALIAS (no_bgp_network_mask,
5198 no_bgp_network_mask_backdoor_cmd,
5199 "no network A.B.C.D mask A.B.C.D backdoor",
5200 NO_STR
5201 "Specify a network to announce via BGP\n"
5202 "Network number\n"
5203 "Network mask\n"
5204 "Network mask\n"
5205 "Specify a BGP backdoor route\n")
5206
5207DEFUN (no_bgp_network_mask_natural,
5208 no_bgp_network_mask_natural_cmd,
5209 "no network A.B.C.D",
5210 NO_STR
5211 "Specify a network to announce via BGP\n"
5212 "Network number\n")
5213{
5214 int ret;
5215 char prefix_str[BUFSIZ];
5216
5217 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
5218 if (! ret)
5219 {
5220 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5221 return CMD_WARNING;
5222 }
5223
5224 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
5225 bgp_node_safi (vty));
5226}
5227
5228ALIAS (no_bgp_network_mask_natural,
5229 no_bgp_network_mask_natural_route_map_cmd,
5230 "no network A.B.C.D route-map WORD",
5231 NO_STR
5232 "Specify a network to announce via BGP\n"
5233 "Network number\n"
5234 "Route-map to modify the attributes\n"
5235 "Name of the route map\n")
5236
5237ALIAS (no_bgp_network_mask_natural,
5238 no_bgp_network_mask_natural_backdoor_cmd,
5239 "no network A.B.C.D backdoor",
5240 NO_STR
5241 "Specify a network to announce via BGP\n"
5242 "Network number\n"
5243 "Specify a BGP backdoor route\n")
5244
5245#ifdef HAVE_IPV6
5246DEFUN (ipv6_bgp_network,
5247 ipv6_bgp_network_cmd,
5248 "network X:X::X:X/M",
5249 "Specify a network to announce via BGP\n"
5250 "IPv6 prefix <network>/<length>\n")
5251{
73bfe0bd 5252 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
c8f3fe30 5253 NULL, 0);
718e3744 5254}
5255
5256DEFUN (ipv6_bgp_network_route_map,
5257 ipv6_bgp_network_route_map_cmd,
5258 "network X:X::X:X/M route-map WORD",
5259 "Specify a network to announce via BGP\n"
5260 "IPv6 prefix <network>/<length>\n"
5261 "Route-map to modify the attributes\n"
5262 "Name of the route map\n")
5263{
5264 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
c8f3fe30 5265 bgp_node_safi (vty), argv[1], 0);
718e3744 5266}
5267
5268DEFUN (no_ipv6_bgp_network,
5269 no_ipv6_bgp_network_cmd,
5270 "no network X:X::X:X/M",
5271 NO_STR
5272 "Specify a network to announce via BGP\n"
5273 "IPv6 prefix <network>/<length>\n")
5274{
73bfe0bd 5275 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
718e3744 5276}
5277
5278ALIAS (no_ipv6_bgp_network,
5279 no_ipv6_bgp_network_route_map_cmd,
5280 "no network X:X::X:X/M route-map WORD",
5281 NO_STR
5282 "Specify a network to announce via BGP\n"
5283 "IPv6 prefix <network>/<length>\n"
5284 "Route-map to modify the attributes\n"
5285 "Name of the route map\n")
5286
5287ALIAS (ipv6_bgp_network,
5288 old_ipv6_bgp_network_cmd,
5289 "ipv6 bgp network X:X::X:X/M",
5290 IPV6_STR
5291 BGP_STR
5292 "Specify a network to announce via BGP\n"
5293 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5294
5295ALIAS (no_ipv6_bgp_network,
5296 old_no_ipv6_bgp_network_cmd,
5297 "no ipv6 bgp network X:X::X:X/M",
5298 NO_STR
5299 IPV6_STR
5300 BGP_STR
5301 "Specify a network to announce via BGP\n"
5302 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5303#endif /* HAVE_IPV6 */
c8f3fe30
PJ
5304
5305/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
5306ALIAS_DEPRECATED (bgp_network,
5307 bgp_network_ttl_cmd,
5308 "network A.B.C.D/M pathlimit <0-255>",
5309 "Specify a network to announce via BGP\n"
5310 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5311 "AS-Path hopcount limit attribute\n"
5312 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5313ALIAS_DEPRECATED (bgp_network_backdoor,
5314 bgp_network_backdoor_ttl_cmd,
5315 "network A.B.C.D/M backdoor pathlimit <0-255>",
5316 "Specify a network to announce via BGP\n"
5317 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5318 "Specify a BGP backdoor route\n"
5319 "AS-Path hopcount limit attribute\n"
5320 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5321ALIAS_DEPRECATED (bgp_network_mask,
5322 bgp_network_mask_ttl_cmd,
5323 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
5324 "Specify a network to announce via BGP\n"
5325 "Network number\n"
5326 "Network mask\n"
5327 "Network mask\n"
5328 "AS-Path hopcount limit attribute\n"
5329 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5330ALIAS_DEPRECATED (bgp_network_mask_backdoor,
5331 bgp_network_mask_backdoor_ttl_cmd,
5332 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
5333 "Specify a network to announce via BGP\n"
5334 "Network number\n"
5335 "Network mask\n"
5336 "Network mask\n"
5337 "Specify a BGP backdoor route\n"
5338 "AS-Path hopcount limit attribute\n"
5339 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5340ALIAS_DEPRECATED (bgp_network_mask_natural,
5341 bgp_network_mask_natural_ttl_cmd,
5342 "network A.B.C.D pathlimit <0-255>",
5343 "Specify a network to announce via BGP\n"
5344 "Network number\n"
5345 "AS-Path hopcount limit attribute\n"
5346 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5347ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
5348 bgp_network_mask_natural_backdoor_ttl_cmd,
2b00515a 5349 "network A.B.C.D backdoor pathlimit <1-255>",
c8f3fe30
PJ
5350 "Specify a network to announce via BGP\n"
5351 "Network number\n"
5352 "Specify a BGP backdoor route\n"
5353 "AS-Path hopcount limit attribute\n"
5354 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5355ALIAS_DEPRECATED (no_bgp_network,
5356 no_bgp_network_ttl_cmd,
5357 "no network A.B.C.D/M pathlimit <0-255>",
5358 NO_STR
5359 "Specify a network to announce via BGP\n"
5360 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5361 "AS-Path hopcount limit attribute\n"
5362 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5363ALIAS_DEPRECATED (no_bgp_network,
5364 no_bgp_network_backdoor_ttl_cmd,
5365 "no network A.B.C.D/M backdoor pathlimit <0-255>",
5366 NO_STR
5367 "Specify a network to announce via BGP\n"
5368 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5369 "Specify a BGP backdoor route\n"
5370 "AS-Path hopcount limit attribute\n"
5371 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5372ALIAS_DEPRECATED (no_bgp_network,
5373 no_bgp_network_mask_ttl_cmd,
5374 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
5375 NO_STR
5376 "Specify a network to announce via BGP\n"
5377 "Network number\n"
5378 "Network mask\n"
5379 "Network mask\n"
5380 "AS-Path hopcount limit attribute\n"
5381 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5382ALIAS_DEPRECATED (no_bgp_network_mask,
5383 no_bgp_network_mask_backdoor_ttl_cmd,
5384 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
5385 NO_STR
5386 "Specify a network to announce via BGP\n"
5387 "Network number\n"
5388 "Network mask\n"
5389 "Network mask\n"
5390 "Specify a BGP backdoor route\n"
5391 "AS-Path hopcount limit attribute\n"
5392 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5393ALIAS_DEPRECATED (no_bgp_network_mask_natural,
5394 no_bgp_network_mask_natural_ttl_cmd,
5395 "no network A.B.C.D pathlimit <0-255>",
5396 NO_STR
5397 "Specify a network to announce via BGP\n"
5398 "Network number\n"
5399 "AS-Path hopcount limit attribute\n"
5400 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5401ALIAS_DEPRECATED (no_bgp_network_mask_natural,
5402 no_bgp_network_mask_natural_backdoor_ttl_cmd,
5403 "no network A.B.C.D backdoor pathlimit <0-255>",
5404 NO_STR
5405 "Specify a network to announce via BGP\n"
5406 "Network number\n"
5407 "Specify a BGP backdoor route\n"
5408 "AS-Path hopcount limit attribute\n"
5409 "AS-Pathlimit TTL, in number of AS-Path hops\n")
3bde17f1 5410#ifdef HAVE_IPV6
c8f3fe30
PJ
5411ALIAS_DEPRECATED (ipv6_bgp_network,
5412 ipv6_bgp_network_ttl_cmd,
5413 "network X:X::X:X/M pathlimit <0-255>",
5414 "Specify a network to announce via BGP\n"
5415 "IPv6 prefix <network>/<length>\n"
5416 "AS-Path hopcount limit attribute\n"
5417 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5418ALIAS_DEPRECATED (no_ipv6_bgp_network,
5419 no_ipv6_bgp_network_ttl_cmd,
5420 "no network X:X::X:X/M pathlimit <0-255>",
5421 NO_STR
5422 "Specify a network to announce via BGP\n"
5423 "IPv6 prefix <network>/<length>\n"
5424 "AS-Path hopcount limit attribute\n"
5425 "AS-Pathlimit TTL, in number of AS-Path hops\n")
3bde17f1 5426#endif /* HAVE_IPV6 */
6b0655a2 5427
718e3744 5428/* Aggreagete address:
5429
5430 advertise-map Set condition to advertise attribute
5431 as-set Generate AS set path information
5432 attribute-map Set attributes of aggregate
5433 route-map Set parameters of aggregate
5434 summary-only Filter more specific routes from updates
5435 suppress-map Conditionally filter more specific routes from updates
5436 <cr>
5437 */
5438struct bgp_aggregate
5439{
5440 /* Summary-only flag. */
5441 u_char summary_only;
5442
5443 /* AS set generation. */
5444 u_char as_set;
5445
5446 /* Route-map for aggregated route. */
5447 struct route_map *map;
5448
5449 /* Suppress-count. */
5450 unsigned long count;
5451
5452 /* SAFI configuration. */
5453 safi_t safi;
5454};
5455
94f2b392 5456static struct bgp_aggregate *
66e5cd87 5457bgp_aggregate_new (void)
718e3744 5458{
393deb9b 5459 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
718e3744 5460}
5461
94f2b392 5462static void
718e3744 5463bgp_aggregate_free (struct bgp_aggregate *aggregate)
5464{
5465 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
5466}
5467
b5d58c32 5468/* Update an aggregate as routes are added/removed from the BGP table */
94f2b392 5469static void
718e3744 5470bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
5471 afi_t afi, safi_t safi, struct bgp_info *del,
5472 struct bgp_aggregate *aggregate)
5473{
5474 struct bgp_table *table;
5475 struct bgp_node *top;
5476 struct bgp_node *rn;
5477 u_char origin;
5478 struct aspath *aspath = NULL;
5479 struct aspath *asmerge = NULL;
5480 struct community *community = NULL;
5481 struct community *commerge = NULL;
5482 struct in_addr nexthop;
5483 u_int32_t med = 0;
5484 struct bgp_info *ri;
5485 struct bgp_info *new;
5486 int first = 1;
5487 unsigned long match = 0;
42f7e184 5488 u_char atomic_aggregate = 0;
718e3744 5489
5490 /* Record adding route's nexthop and med. */
5491 if (rinew)
5492 {
5493 nexthop = rinew->attr->nexthop;
5494 med = rinew->attr->med;
5495 }
5496
5497 /* ORIGIN attribute: If at least one route among routes that are
5498 aggregated has ORIGIN with the value INCOMPLETE, then the
5499 aggregated route must have the ORIGIN attribute with the value
5500 INCOMPLETE. Otherwise, if at least one route among routes that
5501 are aggregated has ORIGIN with the value EGP, then the aggregated
5502 route must have the origin attribute with the value EGP. In all
5503 other case the value of the ORIGIN attribute of the aggregated
5504 route is INTERNAL. */
5505 origin = BGP_ORIGIN_IGP;
5506
5507 table = bgp->rib[afi][safi];
5508
5509 top = bgp_node_get (table, p);
5510 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5511 if (rn->p.prefixlen > p->prefixlen)
5512 {
5513 match = 0;
5514
5515 for (ri = rn->info; ri; ri = ri->next)
5516 {
5517 if (BGP_INFO_HOLDDOWN (ri))
5518 continue;
5519
5520 if (del && ri == del)
5521 continue;
5522
5523 if (! rinew && first)
5524 {
5525 nexthop = ri->attr->nexthop;
5526 med = ri->attr->med;
5527 first = 0;
5528 }
5529
5530#ifdef AGGREGATE_NEXTHOP_CHECK
5531 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
5532 || ri->attr->med != med)
5533 {
5534 if (aspath)
5535 aspath_free (aspath);
5536 if (community)
5537 community_free (community);
5538 bgp_unlock_node (rn);
5539 bgp_unlock_node (top);
5540 return;
5541 }
5542#endif /* AGGREGATE_NEXTHOP_CHECK */
5543
42f7e184
DS
5544 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5545 atomic_aggregate = 1;
5546
718e3744 5547 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5548 {
5549 if (aggregate->summary_only)
5550 {
fb982c25 5551 (bgp_info_extra_get (ri))->suppress++;
1a392d46 5552 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5553 match++;
5554 }
5555
5556 aggregate->count++;
5557
b5d58c32
DS
5558 if (origin < ri->attr->origin)
5559 origin = ri->attr->origin;
5560
718e3744 5561 if (aggregate->as_set)
5562 {
718e3744 5563 if (aspath)
5564 {
5565 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5566 aspath_free (aspath);
5567 aspath = asmerge;
5568 }
5569 else
5570 aspath = aspath_dup (ri->attr->aspath);
5571
5572 if (ri->attr->community)
5573 {
5574 if (community)
5575 {
5576 commerge = community_merge (community,
5577 ri->attr->community);
5578 community = community_uniq_sort (commerge);
5579 community_free (commerge);
5580 }
5581 else
5582 community = community_dup (ri->attr->community);
5583 }
5584 }
5585 }
5586 }
5587 if (match)
5588 bgp_process (bgp, rn, afi, safi);
5589 }
5590 bgp_unlock_node (top);
5591
5592 if (rinew)
5593 {
5594 aggregate->count++;
5595
5596 if (aggregate->summary_only)
fb982c25 5597 (bgp_info_extra_get (rinew))->suppress++;
718e3744 5598
b5d58c32
DS
5599 if (origin < rinew->attr->origin)
5600 origin = rinew->attr->origin;
5601
718e3744 5602 if (aggregate->as_set)
5603 {
718e3744 5604 if (aspath)
5605 {
5606 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
5607 aspath_free (aspath);
5608 aspath = asmerge;
5609 }
5610 else
5611 aspath = aspath_dup (rinew->attr->aspath);
5612
5613 if (rinew->attr->community)
5614 {
5615 if (community)
5616 {
5617 commerge = community_merge (community,
5618 rinew->attr->community);
5619 community = community_uniq_sort (commerge);
5620 community_free (commerge);
5621 }
5622 else
5623 community = community_dup (rinew->attr->community);
5624 }
5625 }
5626 }
5627
5628 if (aggregate->count > 0)
5629 {
5630 rn = bgp_node_get (table, p);
7c8ff89e 5631 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 5632 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
5633 aggregate->as_set,
5634 atomic_aggregate), rn);
718e3744 5635 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 5636
5637 bgp_info_add (rn, new);
200df115 5638 bgp_unlock_node (rn);
718e3744 5639 bgp_process (bgp, rn, afi, safi);
5640 }
5641 else
5642 {
5643 if (aspath)
5644 aspath_free (aspath);
5645 if (community)
5646 community_free (community);
5647 }
5648}
5649
5650void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
5651 struct bgp_aggregate *);
5652
5653void
5654bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
5655 struct bgp_info *ri, afi_t afi, safi_t safi)
5656{
5657 struct bgp_node *child;
5658 struct bgp_node *rn;
5659 struct bgp_aggregate *aggregate;
f018db83 5660 struct bgp_table *table;
718e3744 5661
5662 /* MPLS-VPN aggregation is not yet supported. */
5663 if (safi == SAFI_MPLS_VPN)
5664 return;
5665
f018db83
JBD
5666 table = bgp->aggregate[afi][safi];
5667
5668 /* No aggregates configured. */
67174041 5669 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
5670 return;
5671
718e3744 5672 if (p->prefixlen == 0)
5673 return;
5674
5675 if (BGP_INFO_HOLDDOWN (ri))
5676 return;
5677
bb782fb5 5678 child = bgp_node_get (table, p);
718e3744 5679
5680 /* Aggregate address configuration check. */
67174041 5681 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 5682 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5683 {
5684 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 5685 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
718e3744 5686 }
5687 bgp_unlock_node (child);
5688}
5689
5690void
5691bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
5692 struct bgp_info *del, afi_t afi, safi_t safi)
5693{
5694 struct bgp_node *child;
5695 struct bgp_node *rn;
5696 struct bgp_aggregate *aggregate;
f018db83 5697 struct bgp_table *table;
718e3744 5698
5699 /* MPLS-VPN aggregation is not yet supported. */
5700 if (safi == SAFI_MPLS_VPN)
5701 return;
5702
f018db83
JBD
5703 table = bgp->aggregate[afi][safi];
5704
5705 /* No aggregates configured. */
67174041 5706 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
5707 return;
5708
718e3744 5709 if (p->prefixlen == 0)
5710 return;
5711
bb782fb5 5712 child = bgp_node_get (table, p);
718e3744 5713
5714 /* Aggregate address configuration check. */
67174041 5715 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 5716 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5717 {
5718 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 5719 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
718e3744 5720 }
5721 bgp_unlock_node (child);
5722}
5723
b5d58c32 5724/* Called via bgp_aggregate_set when the user configures aggregate-address */
94f2b392 5725static void
718e3744 5726bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5727 struct bgp_aggregate *aggregate)
5728{
5729 struct bgp_table *table;
5730 struct bgp_node *top;
5731 struct bgp_node *rn;
5732 struct bgp_info *new;
5733 struct bgp_info *ri;
5734 unsigned long match;
5735 u_char origin = BGP_ORIGIN_IGP;
5736 struct aspath *aspath = NULL;
5737 struct aspath *asmerge = NULL;
5738 struct community *community = NULL;
5739 struct community *commerge = NULL;
42f7e184 5740 u_char atomic_aggregate = 0;
718e3744 5741
5742 table = bgp->rib[afi][safi];
5743
5744 /* Sanity check. */
5745 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5746 return;
5747 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5748 return;
5749
5750 /* If routes exists below this node, generate aggregate routes. */
5751 top = bgp_node_get (table, p);
5752 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5753 if (rn->p.prefixlen > p->prefixlen)
5754 {
5755 match = 0;
5756
5757 for (ri = rn->info; ri; ri = ri->next)
5758 {
5759 if (BGP_INFO_HOLDDOWN (ri))
5760 continue;
5761
42f7e184
DS
5762 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5763 atomic_aggregate = 1;
5764
718e3744 5765 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5766 {
5767 /* summary-only aggregate route suppress aggregated
5768 route announcement. */
5769 if (aggregate->summary_only)
5770 {
fb982c25 5771 (bgp_info_extra_get (ri))->suppress++;
1a392d46 5772 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5773 match++;
5774 }
b5d58c32
DS
5775
5776 /* If at least one route among routes that are aggregated has
5777 * ORIGIN with the value INCOMPLETE, then the aggregated route
5778 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5779 * Otherwise, if at least one route among routes that are
5780 * aggregated has ORIGIN with the value EGP, then the aggregated
5781 * route MUST have the ORIGIN attribute with the value EGP.
5782 */
5783 if (origin < ri->attr->origin)
5784 origin = ri->attr->origin;
5785
718e3744 5786 /* as-set aggregate route generate origin, as path,
5787 community aggregation. */
5788 if (aggregate->as_set)
5789 {
718e3744 5790 if (aspath)
5791 {
5792 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5793 aspath_free (aspath);
5794 aspath = asmerge;
5795 }
5796 else
5797 aspath = aspath_dup (ri->attr->aspath);
5798
5799 if (ri->attr->community)
5800 {
5801 if (community)
5802 {
5803 commerge = community_merge (community,
5804 ri->attr->community);
5805 community = community_uniq_sort (commerge);
5806 community_free (commerge);
5807 }
5808 else
5809 community = community_dup (ri->attr->community);
5810 }
5811 }
5812 aggregate->count++;
5813 }
5814 }
5815
5816 /* If this node is suppressed, process the change. */
5817 if (match)
5818 bgp_process (bgp, rn, afi, safi);
5819 }
5820 bgp_unlock_node (top);
5821
5822 /* Add aggregate route to BGP table. */
5823 if (aggregate->count)
5824 {
5825 rn = bgp_node_get (table, p);
7c8ff89e 5826 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 5827 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
5828 aggregate->as_set,
5829 atomic_aggregate), rn);
718e3744 5830 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 5831
5832 bgp_info_add (rn, new);
200df115 5833 bgp_unlock_node (rn);
5834
718e3744 5835 /* Process change. */
5836 bgp_process (bgp, rn, afi, safi);
5837 }
5838}
5839
5840void
5841bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5842 safi_t safi, struct bgp_aggregate *aggregate)
5843{
5844 struct bgp_table *table;
5845 struct bgp_node *top;
5846 struct bgp_node *rn;
5847 struct bgp_info *ri;
5848 unsigned long match;
5849
5850 table = bgp->rib[afi][safi];
5851
5852 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5853 return;
5854 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5855 return;
5856
5857 /* If routes exists below this node, generate aggregate routes. */
5858 top = bgp_node_get (table, p);
5859 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5860 if (rn->p.prefixlen > p->prefixlen)
5861 {
5862 match = 0;
5863
5864 for (ri = rn->info; ri; ri = ri->next)
5865 {
5866 if (BGP_INFO_HOLDDOWN (ri))
5867 continue;
5868
5869 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5870 {
fb982c25 5871 if (aggregate->summary_only && ri->extra)
718e3744 5872 {
fb982c25 5873 ri->extra->suppress--;
718e3744 5874
fb982c25 5875 if (ri->extra->suppress == 0)
718e3744 5876 {
1a392d46 5877 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5878 match++;
5879 }
5880 }
5881 aggregate->count--;
5882 }
5883 }
5884
fb982c25 5885 /* If this node was suppressed, process the change. */
718e3744 5886 if (match)
5887 bgp_process (bgp, rn, afi, safi);
5888 }
5889 bgp_unlock_node (top);
5890
5891 /* Delete aggregate route from BGP table. */
5892 rn = bgp_node_get (table, p);
5893
5894 for (ri = rn->info; ri; ri = ri->next)
5895 if (ri->peer == bgp->peer_self
5896 && ri->type == ZEBRA_ROUTE_BGP
5897 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5898 break;
5899
5900 /* Withdraw static BGP route from routing table. */
5901 if (ri)
5902 {
718e3744 5903 bgp_info_delete (rn, ri);
1a392d46 5904 bgp_process (bgp, rn, afi, safi);
718e3744 5905 }
5906
5907 /* Unlock bgp_node_lookup. */
5908 bgp_unlock_node (rn);
5909}
5910
5911/* Aggregate route attribute. */
5912#define AGGREGATE_SUMMARY_ONLY 1
5913#define AGGREGATE_AS_SET 1
5914
94f2b392 5915static int
f6269b4f
RB
5916bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5917 afi_t afi, safi_t safi)
718e3744 5918{
5919 int ret;
5920 struct prefix p;
5921 struct bgp_node *rn;
5922 struct bgp *bgp;
5923 struct bgp_aggregate *aggregate;
5924
5925 /* Convert string to prefix structure. */
5926 ret = str2prefix (prefix_str, &p);
5927 if (!ret)
5928 {
5929 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5930 return CMD_WARNING;
5931 }
5932 apply_mask (&p);
5933
5934 /* Get BGP structure. */
5935 bgp = vty->index;
5936
5937 /* Old configuration check. */
f6269b4f
RB
5938 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5939 if (! rn)
718e3744 5940 {
f6269b4f
RB
5941 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5942 VTY_NEWLINE);
718e3744 5943 return CMD_WARNING;
5944 }
5945
f6269b4f
RB
5946 aggregate = rn->info;
5947 if (aggregate->safi & SAFI_UNICAST)
5948 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5949 if (aggregate->safi & SAFI_MULTICAST)
5950 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 5951
f6269b4f
RB
5952 /* Unlock aggregate address configuration. */
5953 rn->info = NULL;
5954 bgp_aggregate_free (aggregate);
5955 bgp_unlock_node (rn);
5956 bgp_unlock_node (rn);
718e3744 5957
5958 return CMD_SUCCESS;
5959}
5960
94f2b392 5961static int
f6269b4f
RB
5962bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5963 afi_t afi, safi_t safi,
5964 u_char summary_only, u_char as_set)
718e3744 5965{
5966 int ret;
5967 struct prefix p;
5968 struct bgp_node *rn;
5969 struct bgp *bgp;
5970 struct bgp_aggregate *aggregate;
5971
5972 /* Convert string to prefix structure. */
5973 ret = str2prefix (prefix_str, &p);
5974 if (!ret)
5975 {
5976 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5977 return CMD_WARNING;
5978 }
5979 apply_mask (&p);
5980
5981 /* Get BGP structure. */
5982 bgp = vty->index;
5983
5984 /* Old configuration check. */
f6269b4f
RB
5985 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5986
5987 if (rn->info)
718e3744 5988 {
f6269b4f 5989 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
368473f6 5990 /* try to remove the old entry */
f6269b4f
RB
5991 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5992 if (ret)
5993 {
368473f6
RB
5994 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5995 bgp_unlock_node (rn);
f6269b4f
RB
5996 return CMD_WARNING;
5997 }
718e3744 5998 }
5999
f6269b4f
RB
6000 /* Make aggregate address structure. */
6001 aggregate = bgp_aggregate_new ();
6002 aggregate->summary_only = summary_only;
6003 aggregate->as_set = as_set;
6004 aggregate->safi = safi;
6005 rn->info = aggregate;
718e3744 6006
f6269b4f
RB
6007 /* Aggregate address insert into BGP routing table. */
6008 if (safi & SAFI_UNICAST)
6009 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
6010 if (safi & SAFI_MULTICAST)
6011 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 6012
6013 return CMD_SUCCESS;
6014}
6015
6016DEFUN (aggregate_address,
6017 aggregate_address_cmd,
6018 "aggregate-address A.B.C.D/M",
6019 "Configure BGP aggregate entries\n"
6020 "Aggregate prefix\n")
6021{
6022 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
6023}
6024
6025DEFUN (aggregate_address_mask,
6026 aggregate_address_mask_cmd,
6027 "aggregate-address A.B.C.D A.B.C.D",
6028 "Configure BGP aggregate entries\n"
6029 "Aggregate address\n"
6030 "Aggregate mask\n")
6031{
6032 int ret;
6033 char prefix_str[BUFSIZ];
6034
6035 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6036
6037 if (! ret)
6038 {
6039 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6040 return CMD_WARNING;
6041 }
6042
6043 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
6044 0, 0);
6045}
6046
6047DEFUN (aggregate_address_summary_only,
6048 aggregate_address_summary_only_cmd,
6049 "aggregate-address A.B.C.D/M summary-only",
6050 "Configure BGP aggregate entries\n"
6051 "Aggregate prefix\n"
6052 "Filter more specific routes from updates\n")
6053{
6054 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
6055 AGGREGATE_SUMMARY_ONLY, 0);
6056}
6057
6058DEFUN (aggregate_address_mask_summary_only,
6059 aggregate_address_mask_summary_only_cmd,
6060 "aggregate-address A.B.C.D A.B.C.D summary-only",
6061 "Configure BGP aggregate entries\n"
6062 "Aggregate address\n"
6063 "Aggregate mask\n"
6064 "Filter more specific routes from updates\n")
6065{
6066 int ret;
6067 char prefix_str[BUFSIZ];
6068
6069 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6070
6071 if (! ret)
6072 {
6073 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6074 return CMD_WARNING;
6075 }
6076
6077 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
6078 AGGREGATE_SUMMARY_ONLY, 0);
6079}
6080
6081DEFUN (aggregate_address_as_set,
6082 aggregate_address_as_set_cmd,
6083 "aggregate-address A.B.C.D/M as-set",
6084 "Configure BGP aggregate entries\n"
6085 "Aggregate prefix\n"
6086 "Generate AS set path information\n")
6087{
6088 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
6089 0, AGGREGATE_AS_SET);
6090}
6091
6092DEFUN (aggregate_address_mask_as_set,
6093 aggregate_address_mask_as_set_cmd,
6094 "aggregate-address A.B.C.D A.B.C.D as-set",
6095 "Configure BGP aggregate entries\n"
6096 "Aggregate address\n"
6097 "Aggregate mask\n"
6098 "Generate AS set path information\n")
6099{
6100 int ret;
6101 char prefix_str[BUFSIZ];
6102
6103 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6104
6105 if (! ret)
6106 {
6107 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6108 return CMD_WARNING;
6109 }
6110
6111 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
6112 0, AGGREGATE_AS_SET);
6113}
6114
6115
6116DEFUN (aggregate_address_as_set_summary,
6117 aggregate_address_as_set_summary_cmd,
6118 "aggregate-address A.B.C.D/M as-set summary-only",
6119 "Configure BGP aggregate entries\n"
6120 "Aggregate prefix\n"
6121 "Generate AS set path information\n"
6122 "Filter more specific routes from updates\n")
6123{
6124 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
6125 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
6126}
6127
6128ALIAS (aggregate_address_as_set_summary,
6129 aggregate_address_summary_as_set_cmd,
6130 "aggregate-address A.B.C.D/M summary-only as-set",
6131 "Configure BGP aggregate entries\n"
6132 "Aggregate prefix\n"
6133 "Filter more specific routes from updates\n"
6134 "Generate AS set path information\n")
6135
6136DEFUN (aggregate_address_mask_as_set_summary,
6137 aggregate_address_mask_as_set_summary_cmd,
6138 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
6139 "Configure BGP aggregate entries\n"
6140 "Aggregate address\n"
6141 "Aggregate mask\n"
6142 "Generate AS set path information\n"
6143 "Filter more specific routes from updates\n")
6144{
6145 int ret;
6146 char prefix_str[BUFSIZ];
6147
6148 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6149
6150 if (! ret)
6151 {
6152 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6153 return CMD_WARNING;
6154 }
6155
6156 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
6157 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
6158}
6159
6160ALIAS (aggregate_address_mask_as_set_summary,
6161 aggregate_address_mask_summary_as_set_cmd,
6162 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
6163 "Configure BGP aggregate entries\n"
6164 "Aggregate address\n"
6165 "Aggregate mask\n"
6166 "Filter more specific routes from updates\n"
6167 "Generate AS set path information\n")
6168
6169DEFUN (no_aggregate_address,
6170 no_aggregate_address_cmd,
6171 "no aggregate-address A.B.C.D/M",
6172 NO_STR
6173 "Configure BGP aggregate entries\n"
6174 "Aggregate prefix\n")
6175{
6176 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
6177}
6178
6179ALIAS (no_aggregate_address,
6180 no_aggregate_address_summary_only_cmd,
6181 "no aggregate-address A.B.C.D/M summary-only",
6182 NO_STR
6183 "Configure BGP aggregate entries\n"
6184 "Aggregate prefix\n"
6185 "Filter more specific routes from updates\n")
6186
6187ALIAS (no_aggregate_address,
6188 no_aggregate_address_as_set_cmd,
6189 "no aggregate-address A.B.C.D/M as-set",
6190 NO_STR
6191 "Configure BGP aggregate entries\n"
6192 "Aggregate prefix\n"
6193 "Generate AS set path information\n")
6194
6195ALIAS (no_aggregate_address,
6196 no_aggregate_address_as_set_summary_cmd,
6197 "no aggregate-address A.B.C.D/M as-set summary-only",
6198 NO_STR
6199 "Configure BGP aggregate entries\n"
6200 "Aggregate prefix\n"
6201 "Generate AS set path information\n"
6202 "Filter more specific routes from updates\n")
6203
6204ALIAS (no_aggregate_address,
6205 no_aggregate_address_summary_as_set_cmd,
6206 "no aggregate-address A.B.C.D/M summary-only as-set",
6207 NO_STR
6208 "Configure BGP aggregate entries\n"
6209 "Aggregate prefix\n"
6210 "Filter more specific routes from updates\n"
6211 "Generate AS set path information\n")
6212
6213DEFUN (no_aggregate_address_mask,
6214 no_aggregate_address_mask_cmd,
6215 "no aggregate-address A.B.C.D A.B.C.D",
6216 NO_STR
6217 "Configure BGP aggregate entries\n"
6218 "Aggregate address\n"
6219 "Aggregate mask\n")
6220{
6221 int ret;
6222 char prefix_str[BUFSIZ];
6223
6224 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6225
6226 if (! ret)
6227 {
6228 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6229 return CMD_WARNING;
6230 }
6231
6232 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
6233}
6234
6235ALIAS (no_aggregate_address_mask,
6236 no_aggregate_address_mask_summary_only_cmd,
6237 "no aggregate-address A.B.C.D A.B.C.D summary-only",
6238 NO_STR
6239 "Configure BGP aggregate entries\n"
6240 "Aggregate address\n"
6241 "Aggregate mask\n"
6242 "Filter more specific routes from updates\n")
6243
6244ALIAS (no_aggregate_address_mask,
6245 no_aggregate_address_mask_as_set_cmd,
6246 "no aggregate-address A.B.C.D A.B.C.D as-set",
6247 NO_STR
6248 "Configure BGP aggregate entries\n"
6249 "Aggregate address\n"
6250 "Aggregate mask\n"
6251 "Generate AS set path information\n")
6252
6253ALIAS (no_aggregate_address_mask,
6254 no_aggregate_address_mask_as_set_summary_cmd,
6255 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
6256 NO_STR
6257 "Configure BGP aggregate entries\n"
6258 "Aggregate address\n"
6259 "Aggregate mask\n"
6260 "Generate AS set path information\n"
6261 "Filter more specific routes from updates\n")
6262
6263ALIAS (no_aggregate_address_mask,
6264 no_aggregate_address_mask_summary_as_set_cmd,
6265 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
6266 NO_STR
6267 "Configure BGP aggregate entries\n"
6268 "Aggregate address\n"
6269 "Aggregate mask\n"
6270 "Filter more specific routes from updates\n"
6271 "Generate AS set path information\n")
6272
6273#ifdef HAVE_IPV6
6274DEFUN (ipv6_aggregate_address,
6275 ipv6_aggregate_address_cmd,
6276 "aggregate-address X:X::X:X/M",
6277 "Configure BGP aggregate entries\n"
6278 "Aggregate prefix\n")
6279{
6280 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
6281}
6282
6283DEFUN (ipv6_aggregate_address_summary_only,
6284 ipv6_aggregate_address_summary_only_cmd,
6285 "aggregate-address X:X::X:X/M summary-only",
6286 "Configure BGP aggregate entries\n"
6287 "Aggregate prefix\n"
6288 "Filter more specific routes from updates\n")
6289{
6290 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6291 AGGREGATE_SUMMARY_ONLY, 0);
6292}
6293
6294DEFUN (no_ipv6_aggregate_address,
6295 no_ipv6_aggregate_address_cmd,
6296 "no aggregate-address X:X::X:X/M",
6297 NO_STR
6298 "Configure BGP aggregate entries\n"
6299 "Aggregate prefix\n")
6300{
6301 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
6302}
6303
6304DEFUN (no_ipv6_aggregate_address_summary_only,
6305 no_ipv6_aggregate_address_summary_only_cmd,
6306 "no aggregate-address X:X::X:X/M summary-only",
6307 NO_STR
6308 "Configure BGP aggregate entries\n"
6309 "Aggregate prefix\n"
6310 "Filter more specific routes from updates\n")
6311{
6312 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
6313}
6314
6315ALIAS (ipv6_aggregate_address,
6316 old_ipv6_aggregate_address_cmd,
6317 "ipv6 bgp aggregate-address X:X::X:X/M",
6318 IPV6_STR
6319 BGP_STR
6320 "Configure BGP aggregate entries\n"
6321 "Aggregate prefix\n")
6322
6323ALIAS (ipv6_aggregate_address_summary_only,
6324 old_ipv6_aggregate_address_summary_only_cmd,
6325 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
6326 IPV6_STR
6327 BGP_STR
6328 "Configure BGP aggregate entries\n"
6329 "Aggregate prefix\n"
6330 "Filter more specific routes from updates\n")
6331
6332ALIAS (no_ipv6_aggregate_address,
6333 old_no_ipv6_aggregate_address_cmd,
6334 "no ipv6 bgp aggregate-address X:X::X:X/M",
6335 NO_STR
6336 IPV6_STR
6337 BGP_STR
6338 "Configure BGP aggregate entries\n"
6339 "Aggregate prefix\n")
6340
6341ALIAS (no_ipv6_aggregate_address_summary_only,
6342 old_no_ipv6_aggregate_address_summary_only_cmd,
6343 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
6344 NO_STR
6345 IPV6_STR
6346 BGP_STR
6347 "Configure BGP aggregate entries\n"
6348 "Aggregate prefix\n"
6349 "Filter more specific routes from updates\n")
6350#endif /* HAVE_IPV6 */
6b0655a2 6351
718e3744 6352/* Redistribute route treatment. */
6353void
f04a80a5 6354bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
bc413143 6355 const struct in6_addr *nexthop6, unsigned int ifindex,
7c8ff89e 6356 u_int32_t metric, u_char type, u_short instance, u_short tag)
718e3744 6357{
6358 struct bgp *bgp;
1eb8ef25 6359 struct listnode *node, *nnode;
718e3744 6360 struct bgp_info *new;
6361 struct bgp_info *bi;
6362 struct bgp_info info;
6363 struct bgp_node *bn;
e16a4133 6364 struct attr attr;
718e3744 6365 struct attr *new_attr;
6366 afi_t afi;
6367 int ret;
7c8ff89e 6368 struct bgp_redist *red;
718e3744 6369
6370 /* Make default attribute. */
6371 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
6372 if (nexthop)
6373 attr.nexthop = *nexthop;
bc413143 6374 attr.nh_ifindex = ifindex;
718e3744 6375
f04a80a5
SH
6376#ifdef HAVE_IPV6
6377 if (nexthop6)
6378 {
6379 struct attr_extra *extra = bgp_attr_extra_get(&attr);
6380 extra->mp_nexthop_global = *nexthop6;
801a9bcc 6381 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
f04a80a5
SH
6382 }
6383#endif
6384
718e3744 6385 attr.med = metric;
6386 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
0d9551dc 6387 attr.extra->tag = tag;
718e3744 6388
1eb8ef25 6389 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 6390 {
6391 afi = family2afi (p->family);
6392
7c8ff89e
DS
6393 red = bgp_redist_lookup(bgp, afi, type, instance);
6394 if (red)
718e3744 6395 {
558d1fec
JBD
6396 struct attr attr_new;
6397 struct attr_extra extra_new;
6398
718e3744 6399 /* Copy attribute for modification. */
558d1fec 6400 attr_new.extra = &extra_new;
fb982c25 6401 bgp_attr_dup (&attr_new, &attr);
718e3744 6402
7c8ff89e
DS
6403 if (red->redist_metric_flag)
6404 attr_new.med = red->redist_metric;
718e3744 6405
6406 /* Apply route-map. */
7c8ff89e 6407 if (red->rmap.map)
718e3744 6408 {
6409 info.peer = bgp->peer_self;
6410 info.attr = &attr_new;
6411
fee0f4c6 6412 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
6413
7c8ff89e 6414 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
fee0f4c6 6415
6416 bgp->peer_self->rmap_type = 0;
6417
718e3744 6418 if (ret == RMAP_DENYMATCH)
6419 {
6420 /* Free uninterned attribute. */
6421 bgp_attr_flush (&attr_new);
558d1fec 6422
718e3744 6423 /* Unintern original. */
f6f434b2 6424 aspath_unintern (&attr.aspath);
fb982c25 6425 bgp_attr_extra_free (&attr);
7c8ff89e 6426 bgp_redistribute_delete (p, type, instance);
718e3744 6427 return;
6428 }
6429 }
6430
fb982c25
PJ
6431 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
6432 afi, SAFI_UNICAST, p, NULL);
6433
718e3744 6434 new_attr = bgp_attr_intern (&attr_new);
558d1fec 6435
718e3744 6436 for (bi = bn->info; bi; bi = bi->next)
6437 if (bi->peer == bgp->peer_self
6438 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
6439 break;
6440
6441 if (bi)
6442 {
8d45210e
AS
6443 if (attrhash_cmp (bi->attr, new_attr) &&
6444 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
718e3744 6445 {
f6f434b2
PJ
6446 bgp_attr_unintern (&new_attr);
6447 aspath_unintern (&attr.aspath);
fb982c25 6448 bgp_attr_extra_free (&attr);
718e3744 6449 bgp_unlock_node (bn);
6450 return;
6451 }
6452 else
6453 {
6454 /* The attribute is changed. */
1a392d46 6455 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
718e3744 6456
6457 /* Rewrite BGP route information. */
8d45210e
AS
6458 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
6459 bgp_info_restore(bn, bi);
6460 else
6461 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
f6f434b2 6462 bgp_attr_unintern (&bi->attr);
718e3744 6463 bi->attr = new_attr;
65957886 6464 bi->uptime = bgp_clock ();
718e3744 6465
6466 /* Process change. */
6467 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
6468 bgp_process (bgp, bn, afi, SAFI_UNICAST);
6469 bgp_unlock_node (bn);
f6f434b2 6470 aspath_unintern (&attr.aspath);
fb982c25 6471 bgp_attr_extra_free (&attr);
718e3744 6472 return;
fb018d25 6473 }
718e3744 6474 }
6475
7c8ff89e 6476 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
fb018d25 6477 new_attr, bn);
718e3744 6478 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 6479
6480 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
6481 bgp_info_add (bn, new);
200df115 6482 bgp_unlock_node (bn);
718e3744 6483 bgp_process (bgp, bn, afi, SAFI_UNICAST);
6484 }
6485 }
6486
6487 /* Unintern original. */
f6f434b2 6488 aspath_unintern (&attr.aspath);
fb982c25 6489 bgp_attr_extra_free (&attr);
718e3744 6490}
6491
6492void
7c8ff89e 6493bgp_redistribute_delete (struct prefix *p, u_char type, u_short instance)
718e3744 6494{
6495 struct bgp *bgp;
1eb8ef25 6496 struct listnode *node, *nnode;
718e3744 6497 afi_t afi;
6498 struct bgp_node *rn;
6499 struct bgp_info *ri;
7c8ff89e 6500 struct bgp_redist *red;
718e3744 6501
1eb8ef25 6502 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 6503 {
6504 afi = family2afi (p->family);
6505
7c8ff89e
DS
6506 red = bgp_redist_lookup(bgp, afi, type, instance);
6507 if (red)
718e3744 6508 {
fee0f4c6 6509 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
718e3744 6510
6511 for (ri = rn->info; ri; ri = ri->next)
6512 if (ri->peer == bgp->peer_self
6513 && ri->type == type)
6514 break;
6515
6516 if (ri)
6517 {
6518 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
718e3744 6519 bgp_info_delete (rn, ri);
1a392d46 6520 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 6521 }
6522 bgp_unlock_node (rn);
6523 }
6524 }
6525}
6526
6527/* Withdraw specified route type's route. */
6528void
7c8ff89e 6529bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
718e3744 6530{
6531 struct bgp_node *rn;
6532 struct bgp_info *ri;
6533 struct bgp_table *table;
6534
6535 table = bgp->rib[afi][SAFI_UNICAST];
6536
6537 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6538 {
6539 for (ri = rn->info; ri; ri = ri->next)
6540 if (ri->peer == bgp->peer_self
7c8ff89e
DS
6541 && ri->type == type
6542 && ri->instance == instance)
718e3744 6543 break;
6544
6545 if (ri)
6546 {
6547 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
718e3744 6548 bgp_info_delete (rn, ri);
1a392d46 6549 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 6550 }
6551 }
6552}
6b0655a2 6553
718e3744 6554/* Static function to display route. */
94f2b392 6555static void
718e3744 6556route_vty_out_route (struct prefix *p, struct vty *vty)
6557{
6558 int len;
6559 u_int32_t destination;
6560 char buf[BUFSIZ];
6561
6562 if (p->family == AF_INET)
6563 {
6564 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
6565 destination = ntohl (p->u.prefix4.s_addr);
6566
6567 if ((IN_CLASSC (destination) && p->prefixlen == 24)
6568 || (IN_CLASSB (destination) && p->prefixlen == 16)
6569 || (IN_CLASSA (destination) && p->prefixlen == 8)
6570 || p->u.prefix4.s_addr == 0)
6571 {
6572 /* When mask is natural, mask is not displayed. */
6573 }
6574 else
6575 len += vty_out (vty, "/%d", p->prefixlen);
6576 }
6577 else
6578 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
6579 p->prefixlen);
6580
6581 len = 17 - len;
6582 if (len < 1)
6583 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
6584 else
6585 vty_out (vty, "%*s", len, " ");
6586}
6587
718e3744 6588enum bgp_display_type
6589{
6590 normal_list,
6591};
6592
b40d939b 6593/* Print the short form route status for a bgp_info */
6594static void
b05a1c8b
DS
6595route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
6596 json_object *json_path)
718e3744 6597{
b05a1c8b
DS
6598 json_object *json_boolean_false;
6599 json_object *json_boolean_true;
6600
6601 if (json_path)
6602 {
6603 json_boolean_false = json_object_new_boolean(0);
6604 json_boolean_true = json_object_new_boolean(1);
6605
6606 /* Route status display. */
6607 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6608 json_object_object_add(json_path, "removed", json_boolean_true);
6609
6610 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6611 json_object_object_add(json_path, "stale", json_boolean_true);
6612
6613 if (binfo->extra && binfo->extra->suppress)
6614 json_object_object_add(json_path, "suppressed", json_boolean_true);
6615
6616 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6617 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6618 json_object_object_add(json_path, "valid", json_boolean_true);
6619
6620 /* Selected */
6621 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6622 json_object_object_add(json_path, "history", json_boolean_true);
6623
6624 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6625 json_object_object_add(json_path, "damped", json_boolean_true);
6626
6627 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6628 json_object_object_add(json_path, "bestpath", json_boolean_true);
6629
6630 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6631 json_object_object_add(json_path, "multipath", json_boolean_true);
6632
6633 /* Internal route. */
6634 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6635 json_object_object_add(json_path, "internal", json_boolean_true);
6636 else
6637 json_object_object_add(json_path, "external", json_boolean_true);
6638
6639 return;
6640 }
6641
b40d939b 6642 /* Route status display. */
6643 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6644 vty_out (vty, "R");
6645 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
93406d87 6646 vty_out (vty, "S");
fb982c25 6647 else if (binfo->extra && binfo->extra->suppress)
718e3744 6648 vty_out (vty, "s");
31eba040
DS
6649 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6650 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
718e3744 6651 vty_out (vty, "*");
6652 else
6653 vty_out (vty, " ");
6654
6655 /* Selected */
6656 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6657 vty_out (vty, "h");
6658 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6659 vty_out (vty, "d");
6660 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6661 vty_out (vty, ">");
b366b518
BB
6662 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6663 vty_out (vty, "=");
718e3744 6664 else
6665 vty_out (vty, " ");
6666
6667 /* Internal route. */
b05a1c8b
DS
6668 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6669 vty_out (vty, "i");
6670 else
6671 vty_out (vty, " ");
b40d939b 6672}
6673
6674/* called from terminal list command */
6675void
6676route_vty_out (struct vty *vty, struct prefix *p,
b05a1c8b
DS
6677 struct bgp_info *binfo, int display, safi_t safi,
6678 json_object *json_paths)
b40d939b 6679{
6680 struct attr *attr;
b05a1c8b
DS
6681 json_object *json_path;
6682 json_object *json_int;
6683 json_object *json_string;
47fc97cc 6684
b05a1c8b
DS
6685 if (json_paths)
6686 json_path = json_object_new_object();
718e3744 6687 else
b05a1c8b
DS
6688 json_path = NULL;
6689
6690 /* short status lead text */
6691 route_vty_short_status_out (vty, binfo, json_path);
718e3744 6692
b05a1c8b
DS
6693 if (!json_paths)
6694 {
6695 /* print prefix and mask */
6696 if (! display)
6697 route_vty_out_route (p, vty);
6698 else
6699 vty_out (vty, "%*s", 17, " ");
6700 }
47fc97cc 6701
718e3744 6702 /* Print attribute */
6703 attr = binfo->attr;
6704 if (attr)
6705 {
b05a1c8b
DS
6706
6707 /* IPv4 Next Hop */
718e3744 6708 if (p->family == AF_INET)
6709 {
b05a1c8b
DS
6710 if (json_paths)
6711 {
6712 if (safi == SAFI_MPLS_VPN)
6713 {
6714 json_string = json_object_new_string(inet_ntoa (attr->extra->mp_nexthop_global_in));
6715 json_object_object_add(json_path, "nexthop", json_string);
6716 }
6717 else
6718 {
6719 json_string = json_object_new_string(inet_ntoa (attr->nexthop));
6720 json_object_object_add(json_path, "nexthop", json_string);
6721 }
6722 }
6723 else
6724 {
6725 if (safi == SAFI_MPLS_VPN)
6726 vty_out (vty, "%-16s",
6727 inet_ntoa (attr->extra->mp_nexthop_global_in));
6728 else
6729 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6730 }
718e3744 6731 }
b05a1c8b
DS
6732
6733#ifdef HAVE_IPV6
6734 /* IPv6 Next Hop */
718e3744 6735 else if (p->family == AF_INET6)
6736 {
6737 int len;
6738 char buf[BUFSIZ];
6739
b05a1c8b
DS
6740 if (json_paths)
6741 {
6742 json_string = json_object_new_string(inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf, BUFSIZ));
6743 json_object_object_add(json_path, "nexthop", json_string);
6744 }
6745 else
6746 {
6747 len = vty_out (vty, "%s",
6748 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6749 buf, BUFSIZ));
6750 len = 16 - len;
6751 if (len < 1)
6752 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6753 else
6754 vty_out (vty, "%*s", len, " ");
6755 }
718e3744 6756 }
6757#endif /* HAVE_IPV6 */
6758
b05a1c8b 6759 /* MED/Metric */
718e3744 6760 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b
DS
6761 if (json_paths)
6762 {
6763 json_int = json_object_new_int(attr->med);
6764 json_object_object_add(json_path, "med", json_int);
6765 }
6766 else
6767 vty_out (vty, "%10u", attr->med);
718e3744 6768 else
b05a1c8b
DS
6769 if (!json_paths)
6770 vty_out (vty, " ");
47fc97cc 6771
b05a1c8b 6772 /* Local Pref */
718e3744 6773 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
b05a1c8b
DS
6774 if (json_paths)
6775 {
6776 json_int = json_object_new_int(attr->local_pref);
6777 json_object_object_add(json_path, "localpref", json_int);
6778 }
6779 else
6780 vty_out (vty, "%7u", attr->local_pref);
718e3744 6781 else
b05a1c8b
DS
6782 if (!json_paths)
6783 vty_out (vty, " ");
718e3744 6784
b05a1c8b
DS
6785 if (json_paths)
6786 {
6787 if (attr->extra)
6788 json_int = json_object_new_int(attr->extra->weight);
6789 else
6790 json_int = json_object_new_int(0);
47fc97cc 6791
b05a1c8b
DS
6792 json_object_object_add(json_path, "weight", json_int);
6793 }
6794 else
6795 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
47fc97cc 6796
b2518c1e
PJ
6797 /* Print aspath */
6798 if (attr->aspath)
b05a1c8b
DS
6799 {
6800 if (json_paths)
6801 {
e5eee9af
DS
6802 if (!attr->aspath->str || aspath_count_hops (attr->aspath) == 0)
6803 json_string = json_object_new_string("Local");
6804 else
6805 json_string = json_object_new_string(attr->aspath->str);
b05a1c8b
DS
6806 json_object_object_add(json_path, "aspath", json_string);
6807 }
6808 else
6809 {
6810 aspath_print_vty (vty, "%s", attr->aspath, " ");
6811 }
6812 }
47fc97cc 6813
b2518c1e 6814 /* Print origin */
b05a1c8b
DS
6815 if (json_paths)
6816 {
6817 json_string = json_object_new_string(bgp_origin_str[attr->origin]);
6818 json_object_object_add(json_path, "origin", json_string);
6819 }
6820 else
6821 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 6822 }
b05a1c8b
DS
6823
6824 if (json_paths)
6825 json_object_array_add(json_paths, json_path);
6826 else
6827 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6828}
6829
6830/* called from terminal list command */
6831void
6832route_vty_out_tmp (struct vty *vty, struct prefix *p,
b05a1c8b 6833 struct attr *attr, safi_t safi)
718e3744 6834{
6835 /* Route status display. */
6836 vty_out (vty, "*");
6837 vty_out (vty, ">");
6838 vty_out (vty, " ");
6839
6840 /* print prefix and mask */
6841 route_vty_out_route (p, vty);
6842
6843 /* Print attribute */
6844 if (attr)
6845 {
6846 if (p->family == AF_INET)
6847 {
6848 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
6849 vty_out (vty, "%-16s",
6850 inet_ntoa (attr->extra->mp_nexthop_global_in));
718e3744 6851 else
6852 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6853 }
6854#ifdef HAVE_IPV6
6855 else if (p->family == AF_INET6)
6856 {
6857 int len;
6858 char buf[BUFSIZ];
fb982c25
PJ
6859
6860 assert (attr->extra);
718e3744 6861
6862 len = vty_out (vty, "%s",
fb982c25
PJ
6863 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6864 buf, BUFSIZ));
718e3744 6865 len = 16 - len;
6866 if (len < 1)
6867 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6868 else
6869 vty_out (vty, "%*s", len, " ");
6870 }
6871#endif /* HAVE_IPV6 */
6872
6873 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
c099baf6 6874 vty_out (vty, "%10u", attr->med);
718e3744 6875 else
6876 vty_out (vty, " ");
6877
6878 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
c099baf6 6879 vty_out (vty, "%7u", attr->local_pref);
718e3744 6880 else
6881 vty_out (vty, " ");
fb982c25 6882
c099baf6 6883 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
fb982c25 6884
b2518c1e
PJ
6885 /* Print aspath */
6886 if (attr->aspath)
841f7a57 6887 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 6888
b2518c1e 6889 /* Print origin */
718e3744 6890 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 6891 }
718e3744 6892
6893 vty_out (vty, "%s", VTY_NEWLINE);
6894}
6895
5a646650 6896void
718e3744 6897route_vty_out_tag (struct vty *vty, struct prefix *p,
6898 struct bgp_info *binfo, int display, safi_t safi)
6899{
6900 struct attr *attr;
718e3744 6901 u_int32_t label = 0;
fb982c25
PJ
6902
6903 if (!binfo->extra)
6904 return;
6905
b40d939b 6906 /* short status lead text */
b05a1c8b 6907 route_vty_short_status_out (vty, binfo, NULL);
b40d939b 6908
718e3744 6909 /* print prefix and mask */
6910 if (! display)
6911 route_vty_out_route (p, vty);
6912 else
6913 vty_out (vty, "%*s", 17, " ");
6914
6915 /* Print attribute */
6916 attr = binfo->attr;
6917 if (attr)
6918 {
6919 if (p->family == AF_INET)
6920 {
6921 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
6922 vty_out (vty, "%-16s",
6923 inet_ntoa (attr->extra->mp_nexthop_global_in));
718e3744 6924 else
6925 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6926 }
6927#ifdef HAVE_IPV6
6928 else if (p->family == AF_INET6)
6929 {
fb982c25 6930 assert (attr->extra);
718e3744 6931 char buf[BUFSIZ];
6932 char buf1[BUFSIZ];
801a9bcc 6933 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
718e3744 6934 vty_out (vty, "%s",
fb982c25
PJ
6935 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6936 buf, BUFSIZ));
801a9bcc 6937 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
718e3744 6938 vty_out (vty, "%s(%s)",
fb982c25
PJ
6939 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6940 buf, BUFSIZ),
6941 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6942 buf1, BUFSIZ));
718e3744 6943
6944 }
6945#endif /* HAVE_IPV6 */
6946 }
6947
fb982c25 6948 label = decode_label (binfo->extra->tag);
718e3744 6949
6950 vty_out (vty, "notag/%d", label);
6951
6952 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6953}
6954
6955/* dampening route */
5a646650 6956static void
718e3744 6957damp_route_vty_out (struct vty *vty, struct prefix *p,
6958 struct bgp_info *binfo, int display, safi_t safi)
6959{
6960 struct attr *attr;
718e3744 6961 int len;
50aef6f3 6962 char timebuf[BGP_UPTIME_LEN];
718e3744 6963
b40d939b 6964 /* short status lead text */
b05a1c8b 6965 route_vty_short_status_out (vty, binfo, NULL);
b40d939b 6966
718e3744 6967 /* print prefix and mask */
6968 if (! display)
6969 route_vty_out_route (p, vty);
6970 else
6971 vty_out (vty, "%*s", 17, " ");
6972
6973 len = vty_out (vty, "%s", binfo->peer->host);
6974 len = 17 - len;
6975 if (len < 1)
6976 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6977 else
6978 vty_out (vty, "%*s", len, " ");
6979
50aef6f3 6980 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
718e3744 6981
6982 /* Print attribute */
6983 attr = binfo->attr;
6984 if (attr)
6985 {
6986 /* Print aspath */
6987 if (attr->aspath)
841f7a57 6988 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 6989
6990 /* Print origin */
b2518c1e 6991 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 6992 }
6993 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6994}
6995
718e3744 6996/* flap route */
5a646650 6997static void
718e3744 6998flap_route_vty_out (struct vty *vty, struct prefix *p,
6999 struct bgp_info *binfo, int display, safi_t safi)
7000{
7001 struct attr *attr;
7002 struct bgp_damp_info *bdi;
718e3744 7003 char timebuf[BGP_UPTIME_LEN];
7004 int len;
fb982c25
PJ
7005
7006 if (!binfo->extra)
7007 return;
7008
7009 bdi = binfo->extra->damp_info;
718e3744 7010
b40d939b 7011 /* short status lead text */
b05a1c8b 7012 route_vty_short_status_out (vty, binfo, NULL);
b40d939b 7013
718e3744 7014 /* print prefix and mask */
7015 if (! display)
7016 route_vty_out_route (p, vty);
7017 else
7018 vty_out (vty, "%*s", 17, " ");
7019
7020 len = vty_out (vty, "%s", binfo->peer->host);
7021 len = 16 - len;
7022 if (len < 1)
7023 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
7024 else
7025 vty_out (vty, "%*s", len, " ");
7026
7027 len = vty_out (vty, "%d", bdi->flap);
7028 len = 5 - len;
7029 if (len < 1)
7030 vty_out (vty, " ");
7031 else
7032 vty_out (vty, "%*s ", len, " ");
7033
7034 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
7035 timebuf, BGP_UPTIME_LEN));
7036
7037 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
7038 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
50aef6f3 7039 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
718e3744 7040 else
7041 vty_out (vty, "%*s ", 8, " ");
7042
7043 /* Print attribute */
7044 attr = binfo->attr;
7045 if (attr)
7046 {
7047 /* Print aspath */
7048 if (attr->aspath)
841f7a57 7049 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 7050
7051 /* Print origin */
b2518c1e 7052 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 7053 }
7054 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7055}
7056
94f2b392 7057static void
718e3744 7058route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
b05a1c8b
DS
7059 struct bgp_info *binfo, afi_t afi, safi_t safi,
7060 json_object *json_paths)
718e3744 7061{
7062 char buf[INET6_ADDRSTRLEN];
7063 char buf1[BUFSIZ];
7064 struct attr *attr;
7065 int sockunion_vty_out (struct vty *, union sockunion *);
30b00176
JK
7066#ifdef HAVE_CLOCK_MONOTONIC
7067 time_t tbuf;
7068#endif
b05a1c8b
DS
7069 json_object *json_int;
7070 json_object *json_string;
7071 json_object *json_path;
7072 json_object *json_boolean_false;
7073 json_object *json_boolean_true;
7074 json_object *json_cluster_list;
7075
7076 if (json_paths)
7077 {
7078 json_path = json_object_new_object();
7079 json_boolean_false = json_object_new_boolean(0);
7080 json_boolean_true = json_object_new_boolean(1);
7081 json_cluster_list = json_object_new_array();
7082 }
7083
718e3744 7084 attr = binfo->attr;
7085
7086 if (attr)
7087 {
7088 /* Line1 display AS-path, Aggregator */
7089 if (attr->aspath)
7090 {
b05a1c8b
DS
7091 if (!json_paths)
7092 vty_out (vty, " ");
7093
fe69a505 7094 if (aspath_count_hops (attr->aspath) == 0)
b05a1c8b
DS
7095 {
7096 if (json_paths)
7097 json_string = json_object_new_string("Local");
7098 else
7099 vty_out (vty, "Local");
7100 }
718e3744 7101 else
b05a1c8b
DS
7102 {
7103 if (json_paths)
7104 json_string = json_object_new_string(attr->aspath->str);
7105 else
7106 aspath_print_vty (vty, "%s", attr->aspath, "");
7107 }
7108
7109 if (json_paths)
7110 json_object_object_add(json_path, "aspath", json_string);
718e3744 7111 }
7112
b40d939b 7113 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
b05a1c8b
DS
7114 {
7115 if (json_paths)
7116 json_object_object_add(json_path, "removed", json_boolean_true);
7117 else
7118 vty_out (vty, ", (removed)");
7119 }
7120
93406d87 7121 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
b05a1c8b
DS
7122 {
7123 if (json_paths)
7124 json_object_object_add(json_path, "stale", json_boolean_true);
7125 else
7126 vty_out (vty, ", (stale)");
7127 }
7128
93406d87 7129 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
b05a1c8b
DS
7130 {
7131 if (json_paths)
7132 {
7133 json_int = json_object_new_int(attr->extra->aggregator_as);
7134 json_string = json_object_new_string(inet_ntoa (attr->extra->aggregator_addr));
7135 json_object_object_add(json_path, "aggregator-as", json_int);
7136 json_object_object_add(json_path, "aggregator-id", json_string);
7137 }
7138 else
7139 {
7140 vty_out (vty, ", (aggregated by %u %s)",
7141 attr->extra->aggregator_as,
7142 inet_ntoa (attr->extra->aggregator_addr));
7143 }
7144 }
7145
93406d87 7146 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
b05a1c8b
DS
7147 {
7148 if (json_paths)
7149 json_object_object_add(json_path, "rxed-from-rr-client", json_boolean_true);
7150 else
7151 vty_out (vty, ", (Received from a RR-client)");
7152 }
7153
93406d87 7154 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
b05a1c8b
DS
7155 {
7156 if (json_paths)
7157 json_object_object_add(json_path, "rxed-from-rs-client", json_boolean_true);
7158 else
7159 vty_out (vty, ", (Received from a RS-client)");
7160 }
7161
93406d87 7162 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
7163 {
7164 if (json_paths)
7165 json_object_object_add(json_path, "dampening-history-entry", json_boolean_true);
7166 else
7167 vty_out (vty, ", (history entry)");
7168 }
93406d87 7169 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
b05a1c8b
DS
7170 {
7171 if (json_paths)
7172 json_object_object_add(json_path, "dampening-suppressed", json_boolean_true);
7173 else
7174 vty_out (vty, ", (suppressed due to dampening)");
7175 }
7176
7177 if (!json_paths)
7178 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7179
7180 /* Line2 display Next-hop, Neighbor, Router-id */
7181 if (p->family == AF_INET)
7182 {
b05a1c8b
DS
7183 if (safi == SAFI_MPLS_VPN)
7184 {
7185 if (json_paths)
7186 json_string = json_object_new_string(inet_ntoa (attr->extra->mp_nexthop_global_in));
7187 else
7188 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
7189 }
7190 else
7191 {
7192 if (json_paths)
7193 json_string = json_object_new_string(inet_ntoa (attr->nexthop));
7194 else
7195 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
7196 }
7197
7198 if (json_paths)
7199 json_object_object_add(json_path, "nexthop", json_string);
718e3744 7200 }
7201#ifdef HAVE_IPV6
7202 else
7203 {
fb982c25 7204 assert (attr->extra);
b05a1c8b
DS
7205 if (json_paths)
7206 {
7207 json_string = json_object_new_string(inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7208 buf, INET6_ADDRSTRLEN));
7209 json_object_object_add(json_path, "nexthop", json_string);
7210 }
7211 else
7212 {
7213 vty_out (vty, " %s",
7214 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7215 buf, INET6_ADDRSTRLEN));
7216 }
718e3744 7217 }
7218#endif /* HAVE_IPV6 */
7219
7220 if (binfo->peer == bgp->peer_self)
7221 {
b05a1c8b
DS
7222
7223 if (p->family == AF_INET)
7224 {
7225 if (json_paths)
7226 json_string = json_object_new_string("0.0.0.0");
7227 else
7228 vty_out (vty, " from 0.0.0.0 ");
7229 }
7230 else
7231 {
7232 if (json_paths)
7233 json_string = json_object_new_string("::");
7234 else
7235 vty_out (vty, " from :: ");
7236 }
7237
7238 if (json_paths)
7239 {
7240 json_object_object_add(json_path, "peer-ip", json_string);
7241 json_string = json_object_new_string(inet_ntoa(bgp->router_id));
7242 json_object_object_add(json_path, "peer-id", json_string);
7243 }
7244 else
7245 {
7246 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
7247 }
718e3744 7248 }
7249 else
7250 {
7251 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
b05a1c8b
DS
7252 {
7253 if (json_paths)
7254 json_object_object_add(json_path, "nexthop-accessible", json_boolean_false);
7255 else
7256 vty_out (vty, " (inaccessible)");
7257 }
fb982c25 7258 else if (binfo->extra && binfo->extra->igpmetric)
b05a1c8b
DS
7259 {
7260 if (json_paths)
7261 {
7262 json_int = json_object_new_int(binfo->extra->igpmetric);
7263 json_object_object_add(json_path, "nexthop-igp-cost", json_int);
7264 json_object_object_add(json_path, "nexthop-accessible", json_boolean_true);
7265 }
7266 else
7267 {
7268 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
7269 }
7270 }
7271
7272 /* IGP cost to nexthop is 0 */
7273 else
7274 if (json_paths)
7275 json_object_object_add(json_path, "nexthop-accessible", json_boolean_true);
7276
7277 if (json_paths)
7278 {
7279 json_string = json_object_new_string(sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7280 json_object_object_add(json_path, "peer-ip", json_string);
7281 }
7282 else
7283 {
7284 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7285
7286 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7287 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
7288 else
7289 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
7290 }
7291
7292 /* Always encode the peer's router-id in the json output. We will
7293 * include the originator-id later if this is a reflected route.
7294 */
7295 if (json_paths)
7296 {
7297 json_string = json_object_new_string(inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
7298 json_object_object_add(json_path, "peer-id", json_string);
7299 }
718e3744 7300 }
b05a1c8b
DS
7301
7302 if (!json_paths)
7303 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7304
7305#ifdef HAVE_IPV6
7306 /* display nexthop local */
801a9bcc 7307 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
718e3744 7308 {
b05a1c8b
DS
7309 if (json_paths)
7310 {
7311 json_string = json_object_new_string(inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7312 buf, INET6_ADDRSTRLEN));
7313 json_object_object_add(json_path, "nexthop-local", json_string);
7314 }
7315 else
7316 {
7317 vty_out (vty, " (%s)%s",
7318 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7319 buf, INET6_ADDRSTRLEN),
7320 VTY_NEWLINE);
7321 }
718e3744 7322 }
7323#endif /* HAVE_IPV6 */
7324
0d9551dc 7325 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
b05a1c8b
DS
7326 if (json_paths)
7327 {
7328 json_string = json_object_new_string(bgp_origin_long_str[attr->origin]);
7329 json_object_object_add(json_path, "origin", json_string);
7330 }
7331 else
7332 {
7333 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
7334 }
718e3744 7335
7336 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
b05a1c8b
DS
7337 {
7338 if (json_paths)
7339 {
7340 json_int = json_object_new_int(attr->med);
7341 json_object_object_add(json_path, "med", json_int);
7342 }
7343 else
7344 {
7345 vty_out (vty, ", metric %u", attr->med);
7346 }
7347 }
718e3744 7348
7349 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
b05a1c8b
DS
7350 {
7351 if (json_paths)
7352 {
7353 json_int = json_object_new_int(attr->local_pref);
7354 json_object_object_add(json_path, "localpref", json_int);
7355 }
7356 else
7357 {
7358 vty_out (vty, ", localpref %u", attr->local_pref);
7359 }
7360 }
718e3744 7361 else
b05a1c8b
DS
7362 {
7363 if (json_paths)
7364 {
7365 json_int = json_object_new_int(bgp->default_local_pref);
7366 json_object_object_add(json_path, "localpref", json_int);
7367 }
7368 else
7369 {
7370 vty_out (vty, ", localpref %u", bgp->default_local_pref);
7371 }
7372 }
718e3744 7373
fb982c25 7374 if (attr->extra && attr->extra->weight != 0)
b05a1c8b
DS
7375 {
7376 if (json_paths)
7377 {
7378 json_int = json_object_new_int(attr->extra->weight);
7379 json_object_object_add(json_path, "weight", json_int);
7380 }
7381 else
7382 {
7383 vty_out (vty, ", weight %u", attr->extra->weight);
7384 }
7385 }
0d9551dc
DS
7386
7387 if (attr->extra && attr->extra->tag != 0)
b05a1c8b
DS
7388 {
7389 if (json_paths)
7390 {
7391 json_int = json_object_new_int(attr->extra->tag);
7392 json_object_object_add(json_path, "tag", json_int);
7393 }
7394 else
7395 {
7396 vty_out (vty, ", tag %d", attr->extra->tag);
7397 }
7398 }
718e3744 7399
31eba040 7400 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
b05a1c8b
DS
7401 {
7402 if (json_paths)
7403 json_object_object_add(json_path, "valid", json_boolean_false);
7404 else
7405 vty_out (vty, ", invalid");
7406 }
31eba040 7407 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
b05a1c8b
DS
7408 {
7409 if (json_paths)
7410 json_object_object_add(json_path, "valid", json_boolean_true);
7411 else
7412 vty_out (vty, ", valid");
7413 }
718e3744 7414
7415 if (binfo->peer != bgp->peer_self)
7416 {
7417 if (binfo->peer->as == binfo->peer->local_as)
b05a1c8b
DS
7418 {
7419 if (json_paths)
7420 json_object_object_add(json_path, "internal", json_boolean_true);
7421 else
7422 vty_out (vty, ", internal");
7423 }
718e3744 7424 else
b05a1c8b
DS
7425 {
7426 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
7427 {
7428 if (json_paths)
7429 json_object_object_add(json_path, "confed-external", json_boolean_true);
7430 else
7431 vty_out (vty, ", confed-external");
7432 }
7433 else
7434 {
7435 if (json_paths)
7436 json_object_object_add(json_path, "external", json_boolean_true);
7437 else
7438 vty_out (vty, ", external");
7439 }
7440 }
718e3744 7441 }
7442 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
b05a1c8b
DS
7443 {
7444 if (json_paths)
7445 {
7446 json_object_object_add(json_path, "aggregated", json_boolean_true);
7447 json_object_object_add(json_path, "local", json_boolean_true);
7448 }
7449 else
7450 {
7451 vty_out (vty, ", aggregated, local");
7452 }
7453 }
718e3744 7454 else if (binfo->type != ZEBRA_ROUTE_BGP)
b05a1c8b
DS
7455 {
7456 if (json_paths)
7457 json_object_object_add(json_path, "sourced", json_boolean_true);
7458 else
7459 vty_out (vty, ", sourced");
7460 }
718e3744 7461 else
b05a1c8b
DS
7462 {
7463 if (json_paths)
7464 {
7465 json_object_object_add(json_path, "sourced", json_boolean_true);
7466 json_object_object_add(json_path, "local", json_boolean_true);
7467 }
7468 else
7469 {
7470 vty_out (vty, ", sourced, local");
7471 }
7472 }
718e3744 7473
7474 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
b05a1c8b
DS
7475 {
7476 if (json_paths)
7477 json_object_object_add(json_path, "atomic-aggregate", json_boolean_true);
7478 else
7479 vty_out (vty, ", atomic-aggregate");
7480 }
718e3744 7481
de8d5dff
JB
7482 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
7483 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
7484 bgp_info_mpath_count (binfo)))
b05a1c8b
DS
7485 {
7486 if (json_paths)
7487 json_object_object_add(json_path, "multipath", json_boolean_true);
7488 else
7489 vty_out (vty, ", multipath");
7490 }
de8d5dff 7491
718e3744 7492 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
b05a1c8b
DS
7493 {
7494 if (json_paths)
7495 json_object_object_add(json_path, "bestpath", json_boolean_true);
7496 else
7497 vty_out (vty, ", best");
7498 }
718e3744 7499
b05a1c8b
DS
7500 if (!json_paths)
7501 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7502
7503 /* Line 4 display Community */
7504 if (attr->community)
b05a1c8b
DS
7505 {
7506 if (json_paths)
7507 {
7508 json_string = json_object_new_string(attr->community->str);
7509 json_object_object_add(json_path, "community", json_string);
7510 }
7511 else
7512 {
7513 vty_out (vty, " Community: %s%s", attr->community->str,
7514 VTY_NEWLINE);
7515 }
7516 }
718e3744 7517
7518 /* Line 5 display Extended-community */
7519 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
b05a1c8b
DS
7520 {
7521 if (json_paths)
7522 {
7523 json_string = json_object_new_string(attr->extra->ecommunity->str);
7524 json_object_object_add(json_path, "extended-community", json_string);
7525 }
7526 else
7527 {
7528 vty_out (vty, " Extended Community: %s%s",
7529 attr->extra->ecommunity->str, VTY_NEWLINE);
7530 }
7531 }
7532
718e3744 7533 /* Line 6 display Originator, Cluster-id */
7534 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
7535 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
7536 {
fb982c25 7537 assert (attr->extra);
718e3744 7538 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
b05a1c8b
DS
7539 {
7540 if (json_paths)
7541 {
7542 json_string = json_object_new_string(inet_ntoa (attr->extra->originator_id));
7543 json_object_object_add(json_path, "originator-id", json_string);
7544 }
7545 else
7546 {
7547 vty_out (vty, " Originator: %s",
7548 inet_ntoa (attr->extra->originator_id));
7549 }
7550 }
718e3744 7551
7552 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
7553 {
7554 int i;
b05a1c8b
DS
7555
7556 if (json_paths)
7557 {
7558 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7559 {
7560 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
7561 json_object_array_add(json_cluster_list, json_string);
7562 }
7563 json_object_object_add(json_path, "cluster-list", json_cluster_list);
7564 }
7565 else
7566 {
7567 vty_out (vty, ", Cluster list: ");
7568
7569 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7570 {
7571 vty_out (vty, "%s ",
7572 inet_ntoa (attr->extra->cluster->list[i]));
7573 }
7574 }
718e3744 7575 }
b05a1c8b
DS
7576
7577 if (!json_paths)
7578 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7579 }
b05a1c8b 7580
fb982c25 7581 if (binfo->extra && binfo->extra->damp_info)
b05a1c8b 7582 bgp_damp_info_vty (vty, binfo, json_path);
718e3744 7583
a82478b9
DS
7584 /* Line 7 display Addpath IDs */
7585 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
b05a1c8b
DS
7586 {
7587 if (json_paths)
7588 {
7589 json_int = json_object_new_int(binfo->addpath_rx_id);
7590 json_object_object_add(json_path, "addpath-rx-id", json_int);
7591
7592 json_int = json_object_new_int(binfo->addpath_tx_id);
7593 json_object_object_add(json_path, "addpath-tx-id", json_int);
7594 }
7595 else
7596 {
7597 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
7598 binfo->addpath_rx_id, binfo->addpath_tx_id,
7599 VTY_NEWLINE);
7600 }
7601 }
a82478b9
DS
7602
7603 /* Line 8 display Uptime */
30b00176
JK
7604#ifdef HAVE_CLOCK_MONOTONIC
7605 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
b05a1c8b
DS
7606 if (json_paths)
7607 json_string = json_object_new_string(ctime(&tbuf));
7608 else
7609 vty_out (vty, " Last update: %s", ctime(&tbuf));
30b00176 7610#else
b05a1c8b
DS
7611 if (json_paths)
7612 json_string = json_object_new_string(ctime(&binfo->uptime));
7613 else
7614 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
30b00176 7615#endif /* HAVE_CLOCK_MONOTONIC */
b05a1c8b
DS
7616 if (json_paths)
7617 json_object_object_add(json_path, "last-update", json_string);
718e3744 7618 }
b05a1c8b
DS
7619
7620 /* We've constructed the json object for this path, add it to the json
7621 * array of paths
7622 */
7623 if (json_paths)
7624 json_object_array_add(json_paths, json_path);
7625 else
7626 vty_out (vty, "%s", VTY_NEWLINE);
b366b518
BB
7627}
7628
47fc97cc 7629#define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
718e3744 7630#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7631#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7632
7633enum bgp_show_type
7634{
7635 bgp_show_type_normal,
7636 bgp_show_type_regexp,
7637 bgp_show_type_prefix_list,
7638 bgp_show_type_filter_list,
7639 bgp_show_type_route_map,
7640 bgp_show_type_neighbor,
7641 bgp_show_type_cidr_only,
7642 bgp_show_type_prefix_longer,
7643 bgp_show_type_community_all,
7644 bgp_show_type_community,
7645 bgp_show_type_community_exact,
7646 bgp_show_type_community_list,
7647 bgp_show_type_community_list_exact,
7648 bgp_show_type_flap_statistics,
7649 bgp_show_type_flap_address,
7650 bgp_show_type_flap_prefix,
7651 bgp_show_type_flap_cidr_only,
7652 bgp_show_type_flap_regexp,
7653 bgp_show_type_flap_filter_list,
7654 bgp_show_type_flap_prefix_list,
7655 bgp_show_type_flap_prefix_longer,
7656 bgp_show_type_flap_route_map,
7657 bgp_show_type_flap_neighbor,
7658 bgp_show_type_dampend_paths,
7659 bgp_show_type_damp_neighbor
7660};
7661
5a646650 7662static int
fee0f4c6 7663bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
b05a1c8b 7664 enum bgp_show_type type, void *output_arg, u_char use_json)
718e3744 7665{
718e3744 7666 struct bgp_info *ri;
7667 struct bgp_node *rn;
718e3744 7668 int header = 1;
718e3744 7669 int display;
5a646650 7670 unsigned long output_count;
b05a1c8b
DS
7671 struct prefix *p;
7672 char buf[BUFSIZ];
7673 char buf2[BUFSIZ];
7674 json_object *json;
7675 json_object *json_int;
7676 json_object *json_paths;
7677 json_object *json_routes;
7678 json_object *json_string;
7679
7680 if (use_json)
7681 {
7682 json = json_object_new_object();
7683 json_int = json_object_new_int(table->version);
7684 json_object_object_add(json, "table-version", json_int);
7685
7686 json_string = json_object_new_string(inet_ntoa (*router_id));
7687 json_object_object_add(json, "router-id", json_string);
7688
7689 json_routes = json_object_new_object();
7690 }
718e3744 7691
7692 /* This is first entry point, so reset total line. */
5a646650 7693 output_count = 0;
718e3744 7694
718e3744 7695 /* Start processing of routes. */
7696 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7697 if (rn->info != NULL)
7698 {
7699 display = 0;
7700
b05a1c8b
DS
7701 if (use_json)
7702 json_paths = json_object_new_array();
7703 else
7704 json_paths = NULL;
7705
718e3744 7706 for (ri = rn->info; ri; ri = ri->next)
7707 {
5a646650 7708 if (type == bgp_show_type_flap_statistics
718e3744 7709 || type == bgp_show_type_flap_address
7710 || type == bgp_show_type_flap_prefix
7711 || type == bgp_show_type_flap_cidr_only
7712 || type == bgp_show_type_flap_regexp
7713 || type == bgp_show_type_flap_filter_list
7714 || type == bgp_show_type_flap_prefix_list
7715 || type == bgp_show_type_flap_prefix_longer
7716 || type == bgp_show_type_flap_route_map
7717 || type == bgp_show_type_flap_neighbor
7718 || type == bgp_show_type_dampend_paths
7719 || type == bgp_show_type_damp_neighbor)
7720 {
fb982c25 7721 if (!(ri->extra && ri->extra->damp_info))
718e3744 7722 continue;
7723 }
7724 if (type == bgp_show_type_regexp
7725 || type == bgp_show_type_flap_regexp)
7726 {
5a646650 7727 regex_t *regex = output_arg;
718e3744 7728
7729 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7730 continue;
7731 }
7732 if (type == bgp_show_type_prefix_list
7733 || type == bgp_show_type_flap_prefix_list)
7734 {
5a646650 7735 struct prefix_list *plist = output_arg;
718e3744 7736
7737 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7738 continue;
7739 }
7740 if (type == bgp_show_type_filter_list
7741 || type == bgp_show_type_flap_filter_list)
7742 {
5a646650 7743 struct as_list *as_list = output_arg;
718e3744 7744
7745 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7746 continue;
7747 }
7748 if (type == bgp_show_type_route_map
7749 || type == bgp_show_type_flap_route_map)
7750 {
5a646650 7751 struct route_map *rmap = output_arg;
718e3744 7752 struct bgp_info binfo;
558d1fec
JBD
7753 struct attr dummy_attr;
7754 struct attr_extra dummy_extra;
718e3744 7755 int ret;
7756
558d1fec 7757 dummy_attr.extra = &dummy_extra;
fb982c25 7758 bgp_attr_dup (&dummy_attr, ri->attr);
558d1fec 7759
718e3744 7760 binfo.peer = ri->peer;
7761 binfo.attr = &dummy_attr;
7762
7763 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
718e3744 7764 if (ret == RMAP_DENYMATCH)
7765 continue;
7766 }
7767 if (type == bgp_show_type_neighbor
7768 || type == bgp_show_type_flap_neighbor
7769 || type == bgp_show_type_damp_neighbor)
7770 {
5a646650 7771 union sockunion *su = output_arg;
718e3744 7772
7773 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7774 continue;
7775 }
7776 if (type == bgp_show_type_cidr_only
7777 || type == bgp_show_type_flap_cidr_only)
7778 {
7779 u_int32_t destination;
7780
7781 destination = ntohl (rn->p.u.prefix4.s_addr);
7782 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7783 continue;
7784 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7785 continue;
7786 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7787 continue;
7788 }
7789 if (type == bgp_show_type_prefix_longer
7790 || type == bgp_show_type_flap_prefix_longer)
7791 {
5a646650 7792 struct prefix *p = output_arg;
718e3744 7793
7794 if (! prefix_match (p, &rn->p))
7795 continue;
7796 }
7797 if (type == bgp_show_type_community_all)
7798 {
7799 if (! ri->attr->community)
7800 continue;
7801 }
7802 if (type == bgp_show_type_community)
7803 {
5a646650 7804 struct community *com = output_arg;
718e3744 7805
7806 if (! ri->attr->community ||
7807 ! community_match (ri->attr->community, com))
7808 continue;
7809 }
7810 if (type == bgp_show_type_community_exact)
7811 {
5a646650 7812 struct community *com = output_arg;
718e3744 7813
7814 if (! ri->attr->community ||
7815 ! community_cmp (ri->attr->community, com))
7816 continue;
7817 }
7818 if (type == bgp_show_type_community_list)
7819 {
5a646650 7820 struct community_list *list = output_arg;
718e3744 7821
7822 if (! community_list_match (ri->attr->community, list))
7823 continue;
7824 }
7825 if (type == bgp_show_type_community_list_exact)
7826 {
5a646650 7827 struct community_list *list = output_arg;
718e3744 7828
7829 if (! community_list_exact_match (ri->attr->community, list))
7830 continue;
7831 }
7832 if (type == bgp_show_type_flap_address
7833 || type == bgp_show_type_flap_prefix)
7834 {
5a646650 7835 struct prefix *p = output_arg;
718e3744 7836
7837 if (! prefix_match (&rn->p, p))
7838 continue;
7839
7840 if (type == bgp_show_type_flap_prefix)
7841 if (p->prefixlen != rn->p.prefixlen)
7842 continue;
7843 }
7844 if (type == bgp_show_type_dampend_paths
7845 || type == bgp_show_type_damp_neighbor)
7846 {
7847 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7848 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7849 continue;
7850 }
7851
b05a1c8b 7852 if (!use_json && header)
718e3744 7853 {
3f9c7369 7854 vty_out (vty, "BGP table version is %llu, local router ID is %s%s", table->version, inet_ntoa (*router_id), VTY_NEWLINE);
93406d87 7855 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7856 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 7857 if (type == bgp_show_type_dampend_paths
7858 || type == bgp_show_type_damp_neighbor)
7859 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7860 else if (type == bgp_show_type_flap_statistics
7861 || type == bgp_show_type_flap_address
7862 || type == bgp_show_type_flap_prefix
7863 || type == bgp_show_type_flap_cidr_only
7864 || type == bgp_show_type_flap_regexp
7865 || type == bgp_show_type_flap_filter_list
7866 || type == bgp_show_type_flap_prefix_list
7867 || type == bgp_show_type_flap_prefix_longer
7868 || type == bgp_show_type_flap_route_map
7869 || type == bgp_show_type_flap_neighbor)
7870 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7871 else
7872 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
718e3744 7873 header = 0;
7874 }
7875
7876 if (type == bgp_show_type_dampend_paths
7877 || type == bgp_show_type_damp_neighbor)
5a646650 7878 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
718e3744 7879 else if (type == bgp_show_type_flap_statistics
7880 || type == bgp_show_type_flap_address
7881 || type == bgp_show_type_flap_prefix
7882 || type == bgp_show_type_flap_cidr_only
7883 || type == bgp_show_type_flap_regexp
7884 || type == bgp_show_type_flap_filter_list
7885 || type == bgp_show_type_flap_prefix_list
7886 || type == bgp_show_type_flap_prefix_longer
7887 || type == bgp_show_type_flap_route_map
7888 || type == bgp_show_type_flap_neighbor)
5a646650 7889 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
718e3744 7890 else
b05a1c8b 7891 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
718e3744 7892 display++;
7893 }
b05a1c8b
DS
7894
7895 if (use_json)
7896 {
7897 p = &rn->p;
7898 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
7899 json_object_object_add(json_routes, buf2, json_paths);
7900 }
7901
718e3744 7902 if (display)
5a646650 7903 output_count++;
718e3744 7904 }
7905
b05a1c8b 7906 if (use_json)
718e3744 7907 {
b05a1c8b
DS
7908 json_object_object_add(json, "routes", json_routes);
7909 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
7910
7911 // Recursively free all json structures
7912 json_object_put(json);
718e3744 7913 }
7914 else
b05a1c8b
DS
7915 {
7916 /* No route is displayed */
7917 if (output_count == 0)
7918 {
7919 if (type == bgp_show_type_normal)
7920 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
7921 }
7922 else
7923 vty_out (vty, "%sTotal number of prefixes %ld%s",
7924 VTY_NEWLINE, output_count, VTY_NEWLINE);
7925 }
718e3744 7926
7927 return CMD_SUCCESS;
7928}
7929
5a646650 7930static int
fee0f4c6 7931bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
b05a1c8b 7932 enum bgp_show_type type, void *output_arg, u_char use_json)
fee0f4c6 7933{
7934 struct bgp_table *table;
7935
7936 if (bgp == NULL) {
7937 bgp = bgp_get_default ();
7938 }
7939
7940 if (bgp == NULL)
7941 {
7942 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7943 return CMD_WARNING;
7944 }
7945
7946
7947 table = bgp->rib[afi][safi];
7948
b05a1c8b 7949 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg, use_json);
fee0f4c6 7950}
7951
718e3744 7952/* Header of detailed BGP route information */
94f2b392 7953static void
718e3744 7954route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7955 struct bgp_node *rn,
b05a1c8b
DS
7956 struct prefix_rd *prd, afi_t afi, safi_t safi,
7957 json_object *json)
718e3744 7958{
7959 struct bgp_info *ri;
7960 struct prefix *p;
7961 struct peer *peer;
1eb8ef25 7962 struct listnode *node, *nnode;
718e3744 7963 char buf1[INET6_ADDRSTRLEN];
7964 char buf2[INET6_ADDRSTRLEN];
7965 int count = 0;
7966 int best = 0;
7967 int suppress = 0;
7968 int no_export = 0;
7969 int no_advertise = 0;
7970 int local_as = 0;
7971 int first = 0;
b05a1c8b
DS
7972 json_object *json_string;
7973 json_object *json_int;
7974 json_object *json_adv_to;
718e3744 7975
7976 p = &rn->p;
b05a1c8b
DS
7977
7978 if (json)
7979 {
7980 json_string = json_object_new_string(inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7981 json_object_object_add(json, "prefix", json_string);
7982
7983 json_int = json_object_new_int(p->prefixlen);
7984 json_object_object_add(json, "prefixlen", json_int);
7985 json_adv_to = json_object_new_array();
7986 }
7987 else
7988 {
7989 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
7990 (safi == SAFI_MPLS_VPN ?
7991 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7992 safi == SAFI_MPLS_VPN ? ":" : "",
7993 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7994 p->prefixlen, VTY_NEWLINE);
7995 }
718e3744 7996
7997 for (ri = rn->info; ri; ri = ri->next)
7998 {
7999 count++;
8000 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
8001 {
8002 best = count;
fb982c25 8003 if (ri->extra && ri->extra->suppress)
718e3744 8004 suppress = 1;
8005 if (ri->attr->community != NULL)
8006 {
8007 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
8008 no_advertise = 1;
8009 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
8010 no_export = 1;
8011 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
8012 local_as = 1;
8013 }
8014 }
8015 }
8016
b05a1c8b 8017 if (!json)
718e3744 8018 {
b05a1c8b
DS
8019 vty_out (vty, "Paths: (%d available", count);
8020 if (best)
8021 {
8022 vty_out (vty, ", best #%d", best);
8023 if (safi == SAFI_UNICAST)
8024 vty_out (vty, ", table Default-IP-Routing-Table");
8025 }
8026 else
8027 vty_out (vty, ", no best path");
8028
8029 if (no_advertise)
8030 vty_out (vty, ", not advertised to any peer");
8031 else if (no_export)
8032 vty_out (vty, ", not advertised to EBGP peer");
8033 else if (local_as)
8034 vty_out (vty, ", not advertised outside local AS");
8035
8036 if (suppress)
8037 vty_out (vty, ", Advertisements suppressed by an aggregate.");
8038 vty_out (vty, ")%s", VTY_NEWLINE);
718e3744 8039 }
718e3744 8040
8041 /* advertised peer */
1eb8ef25 8042 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
718e3744 8043 {
8044 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
8045 {
b05a1c8b
DS
8046 if (json)
8047 {
8048 json_string = json_object_new_string(sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
8049 json_object_array_add(json_adv_to, json_string);
8050 }
8051 else
8052 {
8053 if (! first)
8054 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
8055 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
8056 }
8057 first = 1;
718e3744 8058 }
8059 }
b05a1c8b
DS
8060
8061 if (json)
8062 {
8063 if (first)
8064 {
8065 json_object_object_add(json, "advertised-to", json_adv_to);
8066 }
8067 }
8068 else
8069 {
8070 if (!first)
8071 vty_out (vty, " Not advertised to any peer");
8072 vty_out (vty, "%s", VTY_NEWLINE);
8073 }
718e3744 8074}
8075
8076/* Display specified route of BGP table. */
94f2b392 8077static int
fee0f4c6 8078bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
fd79ac91 8079 struct bgp_table *rib, const char *ip_str,
8080 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
8081 int prefix_check, enum bgp_path_type pathtype,
8082 u_char use_json)
718e3744 8083{
8084 int ret;
8085 int header;
8086 int display = 0;
8087 struct prefix match;
8088 struct bgp_node *rn;
8089 struct bgp_node *rm;
8090 struct bgp_info *ri;
718e3744 8091 struct bgp_table *table;
b05a1c8b
DS
8092 json_object *json;
8093 json_object *json_paths;
718e3744 8094
718e3744 8095 /* Check IP address argument. */
8096 ret = str2prefix (ip_str, &match);
8097 if (! ret)
8098 {
8099 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
8100 return CMD_WARNING;
8101 }
8102
8103 match.family = afi2family (afi);
8104
b05a1c8b
DS
8105 if (use_json)
8106 {
8107 json = json_object_new_object();
8108 json_paths = json_object_new_array();
8109 }
8110 else
8111 {
8112 json = NULL;
8113 json_paths = NULL;
8114 }
8115
718e3744 8116 if (safi == SAFI_MPLS_VPN)
8117 {
fee0f4c6 8118 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
718e3744 8119 {
8120 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
8121 continue;
8122
8123 if ((table = rn->info) != NULL)
8124 {
8125 header = 1;
8126
8127 if ((rm = bgp_node_match (table, &match)) != NULL)
8128 {
8129 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6c88b44d
CC
8130 {
8131 bgp_unlock_node (rm);
8132 continue;
8133 }
718e3744 8134
8135 for (ri = rm->info; ri; ri = ri->next)
8136 {
8137 if (header)
8138 {
8139 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
b05a1c8b 8140 AFI_IP, SAFI_MPLS_VPN, json);
718e3744 8141
8142 header = 0;
8143 }
8144 display++;
4092b06c
DS
8145
8146 if (pathtype == BGP_PATH_ALL ||
8147 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8148 (pathtype == BGP_PATH_MULTIPATH &&
8149 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
b05a1c8b 8150 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN, json_paths);
718e3744 8151 }
6c88b44d
CC
8152
8153 bgp_unlock_node (rm);
718e3744 8154 }
8155 }
8156 }
8157 }
8158 else
8159 {
8160 header = 1;
8161
fee0f4c6 8162 if ((rn = bgp_node_match (rib, &match)) != NULL)
718e3744 8163 {
8164 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
8165 {
8166 for (ri = rn->info; ri; ri = ri->next)
8167 {
8168 if (header)
8169 {
b05a1c8b 8170 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
718e3744 8171 header = 0;
8172 }
8173 display++;
4092b06c
DS
8174
8175 if (pathtype == BGP_PATH_ALL ||
8176 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8177 (pathtype == BGP_PATH_MULTIPATH &&
8178 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
b05a1c8b 8179 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
718e3744 8180 }
8181 }
6c88b44d
CC
8182
8183 bgp_unlock_node (rn);
718e3744 8184 }
8185 }
8186
e5eee9af 8187 if (use_json)
718e3744 8188 {
e5eee9af
DS
8189 if (display)
8190 json_object_object_add(json, "paths", json_paths);
8191
8192 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
8193
8194 // Recursively free all json structures
8195 json_object_put(json);
b05a1c8b
DS
8196 }
8197 else
8198 {
e5eee9af 8199 if (!display)
b05a1c8b
DS
8200 {
8201 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
8202 return CMD_WARNING;
8203 }
8204 }
8205
718e3744 8206 return CMD_SUCCESS;
8207}
8208
fee0f4c6 8209/* Display specified route of Main RIB */
94f2b392 8210static int
fd79ac91 8211bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
fee0f4c6 8212 afi_t afi, safi_t safi, struct prefix_rd *prd,
b05a1c8b
DS
8213 int prefix_check, enum bgp_path_type pathtype,
8214 u_char use_json)
fee0f4c6 8215{
8216 struct bgp *bgp;
8217
8218 /* BGP structure lookup. */
8219 if (view_name)
8220 {
8221 bgp = bgp_lookup_by_name (view_name);
8222 if (bgp == NULL)
8223 {
8224 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8225 return CMD_WARNING;
8226 }
8227 }
8228 else
8229 {
8230 bgp = bgp_get_default ();
8231 if (bgp == NULL)
8232 {
8233 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8234 return CMD_WARNING;
8235 }
8236 }
8237
8238 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
b05a1c8b
DS
8239 afi, safi, prd, prefix_check, pathtype,
8240 use_json);
fee0f4c6 8241}
8242
718e3744 8243/* BGP route print out function. */
8244DEFUN (show_ip_bgp,
8245 show_ip_bgp_cmd,
b05a1c8b 8246 "show ip bgp {json}",
47fc97cc
DS
8247 SHOW_STR
8248 IP_STR
b05a1c8b
DS
8249 BGP_STR
8250 "JavaScript Object Notation\n")
47fc97cc 8251{
b05a1c8b
DS
8252 u_char use_json = (argv[0] != NULL);
8253 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
718e3744 8254}
8255
8256DEFUN (show_ip_bgp_ipv4,
8257 show_ip_bgp_ipv4_cmd,
b05a1c8b 8258 "show ip bgp ipv4 (unicast|multicast) {json}",
718e3744 8259 SHOW_STR
8260 IP_STR
8261 BGP_STR
8262 "Address family\n"
8263 "Address Family modifier\n"
b05a1c8b
DS
8264 "Address Family modifier\n"
8265 "JavaScript Object Notation\n")
718e3744 8266{
b05a1c8b
DS
8267 u_char use_json = (argv[1] != NULL);
8268
718e3744 8269 if (strncmp (argv[0], "m", 1) == 0)
5a646650 8270 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
b05a1c8b 8271 NULL, use_json);
718e3744 8272
b05a1c8b 8273 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
718e3744 8274}
8275
95cbbd2a
ML
8276ALIAS (show_ip_bgp_ipv4,
8277 show_bgp_ipv4_safi_cmd,
b05a1c8b 8278 "show bgp ipv4 (unicast|multicast) {json}",
95cbbd2a
ML
8279 SHOW_STR
8280 BGP_STR
8281 "Address family\n"
8282 "Address Family modifier\n"
47fc97cc 8283 "Address Family modifier\n"
b05a1c8b 8284 "JavaScript Object Notation\n")
47fc97cc 8285
718e3744 8286DEFUN (show_ip_bgp_route,
8287 show_ip_bgp_route_cmd,
b05a1c8b 8288 "show ip bgp A.B.C.D {json}",
718e3744 8289 SHOW_STR
8290 IP_STR
8291 BGP_STR
b05a1c8b
DS
8292 "Network in the BGP routing table to display\n"
8293 "JavaScript Object Notation\n")
718e3744 8294{
b05a1c8b
DS
8295 u_char use_json = (argv[1] != NULL);
8296 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
4092b06c
DS
8297}
8298
8299DEFUN (show_ip_bgp_route_pathtype,
8300 show_ip_bgp_route_pathtype_cmd,
b05a1c8b 8301 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
4092b06c
DS
8302 SHOW_STR
8303 IP_STR
8304 BGP_STR
8305 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8306 "Display only the bestpath\n"
b05a1c8b
DS
8307 "Display only multipaths\n"
8308 "JavaScript Object Notation\n")
4092b06c 8309{
b05a1c8b
DS
8310 u_char use_json = (argv[2] != NULL);
8311
4092b06c 8312 if (strncmp (argv[1], "b", 1) == 0)
b05a1c8b 8313 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8314 else
b05a1c8b 8315 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8316}
8317
8318DEFUN (show_bgp_ipv4_safi_route_pathtype,
8319 show_bgp_ipv4_safi_route_pathtype_cmd,
b05a1c8b 8320 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath) {json}",
4092b06c
DS
8321 SHOW_STR
8322 BGP_STR
8323 "Address family\n"
8324 "Address Family modifier\n"
8325 "Address Family modifier\n"
8326 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8327 "Display only the bestpath\n"
b05a1c8b
DS
8328 "Display only multipaths\n"
8329 "JavaScript Object Notation\n")
4092b06c 8330{
b05a1c8b
DS
8331 u_char use_json = (argv[3] != NULL);
8332
4092b06c
DS
8333 if (strncmp (argv[0], "m", 1) == 0)
8334 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8335 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8336 else
b05a1c8b 8337 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8338 else
8339 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8340 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8341 else
b05a1c8b 8342 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
718e3744 8343}
8344
8345DEFUN (show_ip_bgp_ipv4_route,
8346 show_ip_bgp_ipv4_route_cmd,
b05a1c8b 8347 "show ip bgp ipv4 (unicast|multicast) A.B.C.D {json}",
718e3744 8348 SHOW_STR
8349 IP_STR
8350 BGP_STR
8351 "Address family\n"
8352 "Address Family modifier\n"
8353 "Address Family modifier\n"
b05a1c8b
DS
8354 "Network in the BGP routing table to display\n"
8355 "JavaScript Object Notation\n")
718e3744 8356{
b05a1c8b
DS
8357 u_char use_json = (argv[2] != NULL);
8358
718e3744 8359 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 8360 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8361
b05a1c8b 8362 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8363}
8364
95cbbd2a
ML
8365ALIAS (show_ip_bgp_ipv4_route,
8366 show_bgp_ipv4_safi_route_cmd,
b05a1c8b 8367 "show bgp ipv4 (unicast|multicast) A.B.C.D {json}",
95cbbd2a
ML
8368 SHOW_STR
8369 BGP_STR
8370 "Address family\n"
8371 "Address Family modifier\n"
8372 "Address Family modifier\n"
b05a1c8b
DS
8373 "Network in the BGP routing table to display\n"
8374 "JavaScript Object Notation\n")
95cbbd2a 8375
718e3744 8376DEFUN (show_ip_bgp_vpnv4_all_route,
8377 show_ip_bgp_vpnv4_all_route_cmd,
b05a1c8b 8378 "show ip bgp vpnv4 all A.B.C.D {json}",
718e3744 8379 SHOW_STR
8380 IP_STR
8381 BGP_STR
8382 "Display VPNv4 NLRI specific information\n"
8383 "Display information about all VPNv4 NLRIs\n"
b05a1c8b
DS
8384 "Network in the BGP routing table to display\n"
8385 "JavaScript Object Notation\n")
718e3744 8386{
b05a1c8b
DS
8387 u_char use_json = (argv[1] != NULL);
8388 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8389}
8390
4092b06c 8391
718e3744 8392DEFUN (show_ip_bgp_vpnv4_rd_route,
8393 show_ip_bgp_vpnv4_rd_route_cmd,
b05a1c8b 8394 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
718e3744 8395 SHOW_STR
8396 IP_STR
8397 BGP_STR
8398 "Display VPNv4 NLRI specific information\n"
8399 "Display information for a route distinguisher\n"
8400 "VPN Route Distinguisher\n"
b05a1c8b
DS
8401 "Network in the BGP routing table to display\n"
8402 "JavaScript Object Notation\n")
718e3744 8403{
8404 int ret;
8405 struct prefix_rd prd;
b05a1c8b 8406 u_char use_json = (argv[2] != NULL);
718e3744 8407
8408 ret = str2prefix_rd (argv[0], &prd);
8409 if (! ret)
8410 {
8411 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8412 return CMD_WARNING;
8413 }
b05a1c8b 8414 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json);
718e3744 8415}
8416
8417DEFUN (show_ip_bgp_prefix,
8418 show_ip_bgp_prefix_cmd,
b05a1c8b 8419 "show ip bgp A.B.C.D/M {json}",
718e3744 8420 SHOW_STR
8421 IP_STR
8422 BGP_STR
b05a1c8b
DS
8423 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8424 "JavaScript Object Notation\n")
718e3744 8425{
b05a1c8b
DS
8426 u_char use_json = (argv[1] != NULL);
8427 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
4092b06c
DS
8428}
8429
8430DEFUN (show_ip_bgp_prefix_pathtype,
8431 show_ip_bgp_prefix_pathtype_cmd,
b05a1c8b 8432 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8433 SHOW_STR
8434 IP_STR
8435 BGP_STR
8436 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8437 "Display only the bestpath\n"
b05a1c8b
DS
8438 "Display only multipaths\n"
8439 "JavaScript Object Notation\n")
4092b06c 8440{
b05a1c8b 8441 u_char use_json = (argv[2] != NULL);
4092b06c 8442 if (strncmp (argv[1], "b", 1) == 0)
b05a1c8b 8443 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8444 else
b05a1c8b 8445 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
718e3744 8446}
8447
8448DEFUN (show_ip_bgp_ipv4_prefix,
8449 show_ip_bgp_ipv4_prefix_cmd,
b05a1c8b 8450 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
718e3744 8451 SHOW_STR
8452 IP_STR
8453 BGP_STR
8454 "Address family\n"
8455 "Address Family modifier\n"
8456 "Address Family modifier\n"
b05a1c8b
DS
8457 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8458 "JavaScript Object Notation\n")
718e3744 8459{
b05a1c8b
DS
8460 u_char use_json = (argv[2] != NULL);
8461
718e3744 8462 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 8463 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8464
b05a1c8b 8465 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8466}
8467
95cbbd2a
ML
8468ALIAS (show_ip_bgp_ipv4_prefix,
8469 show_bgp_ipv4_safi_prefix_cmd,
b05a1c8b 8470 "show bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
95cbbd2a
ML
8471 SHOW_STR
8472 BGP_STR
8473 "Address family\n"
8474 "Address Family modifier\n"
8475 "Address Family modifier\n"
b05a1c8b
DS
8476 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8477 "JavaScript Object Notation\n")
95cbbd2a 8478
4092b06c
DS
8479DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
8480 show_ip_bgp_ipv4_prefix_pathtype_cmd,
b05a1c8b 8481 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8482 SHOW_STR
8483 IP_STR
8484 BGP_STR
8485 "Address family\n"
8486 "Address Family modifier\n"
8487 "Address Family modifier\n"
8488 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8489 "Display only the bestpath\n"
b05a1c8b
DS
8490 "Display only multipaths\n"
8491 "JavaScript Object Notation\n")
4092b06c 8492{
b05a1c8b
DS
8493 u_char use_json = (argv[3] != NULL);
8494
4092b06c
DS
8495 if (strncmp (argv[0], "m", 1) == 0)
8496 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8497 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8498 else
b05a1c8b 8499 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8500 else
8501 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8502 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8503 else
b05a1c8b 8504 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8505}
8506
8507ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
8508 show_bgp_ipv4_safi_prefix_pathtype_cmd,
b05a1c8b 8509 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
4092b06c
DS
8510 SHOW_STR
8511 BGP_STR
8512 "Address family\n"
8513 "Address Family modifier\n"
8514 "Address Family modifier\n"
8515 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8516 "Display only the bestpath\n"
b05a1c8b
DS
8517 "Display only multipaths\n"
8518 "JavaScript Object Notation\n")
4092b06c 8519
718e3744 8520DEFUN (show_ip_bgp_vpnv4_all_prefix,
8521 show_ip_bgp_vpnv4_all_prefix_cmd,
b05a1c8b 8522 "show ip bgp vpnv4 all A.B.C.D/M {json}",
718e3744 8523 SHOW_STR
8524 IP_STR
8525 BGP_STR
8526 "Display VPNv4 NLRI specific information\n"
8527 "Display information about all VPNv4 NLRIs\n"
b05a1c8b
DS
8528 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8529 "JavaScript Object Notation\n")
718e3744 8530{
b05a1c8b
DS
8531 u_char use_json = (argv[1] != NULL);
8532 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8533}
8534
8535DEFUN (show_ip_bgp_vpnv4_rd_prefix,
8536 show_ip_bgp_vpnv4_rd_prefix_cmd,
b05a1c8b 8537 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
718e3744 8538 SHOW_STR
8539 IP_STR
8540 BGP_STR
8541 "Display VPNv4 NLRI specific information\n"
8542 "Display information for a route distinguisher\n"
8543 "VPN Route Distinguisher\n"
b05a1c8b
DS
8544 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8545 "JavaScript Object Notation\n")
718e3744 8546{
8547 int ret;
8548 struct prefix_rd prd;
b05a1c8b 8549 u_char use_json = (argv[2] != NULL);
718e3744 8550
8551 ret = str2prefix_rd (argv[0], &prd);
8552 if (! ret)
8553 {
8554 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8555 return CMD_WARNING;
8556 }
b05a1c8b 8557 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json);
718e3744 8558}
8559
8560DEFUN (show_ip_bgp_view,
8561 show_ip_bgp_view_cmd,
b05a1c8b 8562 "show ip bgp view WORD {json}",
718e3744 8563 SHOW_STR
8564 IP_STR
8565 BGP_STR
8566 "BGP view\n"
b05a1c8b
DS
8567 "View name\n"
8568 "JavaScript Object Notation\n")
718e3744 8569{
bb46e94f 8570 struct bgp *bgp;
b05a1c8b 8571 u_char use_json = (argv[1] != NULL);
bb46e94f 8572
8573 /* BGP structure lookup. */
8574 bgp = bgp_lookup_by_name (argv[0]);
8575 if (bgp == NULL)
8576 {
8577 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8578 return CMD_WARNING;
8579 }
8580
b05a1c8b 8581 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
718e3744 8582}
8583
8584DEFUN (show_ip_bgp_view_route,
8585 show_ip_bgp_view_route_cmd,
b05a1c8b 8586 "show ip bgp view WORD A.B.C.D {json}",
718e3744 8587 SHOW_STR
8588 IP_STR
8589 BGP_STR
8590 "BGP view\n"
2b00515a 8591 "View name\n"
b05a1c8b
DS
8592 "Network in the BGP routing table to display\n"
8593 "JavaScript Object Notation\n")
718e3744 8594{
b05a1c8b
DS
8595 u_char use_json = (argv[2] != NULL);
8596 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8597}
8598
8599DEFUN (show_ip_bgp_view_prefix,
8600 show_ip_bgp_view_prefix_cmd,
b05a1c8b 8601 "show ip bgp view WORD A.B.C.D/M {json}",
718e3744 8602 SHOW_STR
8603 IP_STR
8604 BGP_STR
8605 "BGP view\n"
2b00515a 8606 "View name\n"
b05a1c8b
DS
8607 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8608 "JavaScript Object Notation\n")
718e3744 8609{
b05a1c8b
DS
8610 u_char use_json = (argv[2] != NULL);
8611 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8612}
8613
8614#ifdef HAVE_IPV6
8615DEFUN (show_bgp,
8616 show_bgp_cmd,
b05a1c8b 8617 "show bgp {json}",
718e3744 8618 SHOW_STR
b05a1c8b
DS
8619 BGP_STR
8620 "JavaScript Object Notation\n")
718e3744 8621{
b05a1c8b 8622 u_char use_json = (argv[0] != NULL);
5a646650 8623 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
b05a1c8b 8624 NULL, use_json);
718e3744 8625}
8626
8627ALIAS (show_bgp,
8628 show_bgp_ipv6_cmd,
b05a1c8b 8629 "show bgp ipv6 {json}",
718e3744 8630 SHOW_STR
8631 BGP_STR
b05a1c8b
DS
8632 "Address family\n"
8633 "JavaScript Object Notation\n")
718e3744 8634
95cbbd2a
ML
8635DEFUN (show_bgp_ipv6_safi,
8636 show_bgp_ipv6_safi_cmd,
b05a1c8b 8637 "show bgp ipv6 (unicast|multicast) {json}",
95cbbd2a
ML
8638 SHOW_STR
8639 BGP_STR
8640 "Address family\n"
8641 "Address Family modifier\n"
47fc97cc 8642 "Address Family modifier\n"
b05a1c8b 8643 "JavaScript Object Notation\n")
47fc97cc 8644{
b05a1c8b 8645 u_char use_json = (argv[1] != NULL);
47fc97cc
DS
8646 if (strncmp (argv[0], "m", 1) == 0)
8647 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
b05a1c8b 8648 NULL, use_json);
47fc97cc 8649
b05a1c8b 8650 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
95cbbd2a
ML
8651}
8652
718e3744 8653/* old command */
8654DEFUN (show_ipv6_bgp,
8655 show_ipv6_bgp_cmd,
b05a1c8b 8656 "show ipv6 bgp {json}",
718e3744 8657 SHOW_STR
8658 IP_STR
b05a1c8b
DS
8659 BGP_STR
8660 "JavaScript Object Notation\n")
718e3744 8661{
b05a1c8b 8662 u_char use_json = (argv[0] != NULL);
5a646650 8663 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
b05a1c8b 8664 NULL, use_json);
718e3744 8665}
8666
8667DEFUN (show_bgp_route,
8668 show_bgp_route_cmd,
b05a1c8b 8669 "show bgp X:X::X:X {json}",
718e3744 8670 SHOW_STR
8671 BGP_STR
b05a1c8b
DS
8672 "Network in the BGP routing table to display\n"
8673 "JavaScript Object Notation\n")
718e3744 8674{
b05a1c8b
DS
8675 u_char use_json = (argv[1] != NULL);
8676 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8677}
8678
8679ALIAS (show_bgp_route,
8680 show_bgp_ipv6_route_cmd,
b05a1c8b 8681 "show bgp ipv6 X:X::X:X {json}",
718e3744 8682 SHOW_STR
8683 BGP_STR
8684 "Address family\n"
b05a1c8b
DS
8685 "Network in the BGP routing table to display\n"
8686 "JavaScript Object Notation\n")
718e3744 8687
95cbbd2a
ML
8688DEFUN (show_bgp_ipv6_safi_route,
8689 show_bgp_ipv6_safi_route_cmd,
b05a1c8b 8690 "show bgp ipv6 (unicast|multicast) X:X::X:X {json}",
95cbbd2a
ML
8691 SHOW_STR
8692 BGP_STR
8693 "Address family\n"
8694 "Address Family modifier\n"
8695 "Address Family modifier\n"
b05a1c8b
DS
8696 "Network in the BGP routing table to display\n"
8697 "JavaScript Object Notation\n")
95cbbd2a 8698{
b05a1c8b 8699 u_char use_json = (argv[2] != NULL);
95cbbd2a 8700 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 8701 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json);
95cbbd2a 8702
b05a1c8b 8703 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
4092b06c
DS
8704}
8705
8706DEFUN (show_bgp_route_pathtype,
8707 show_bgp_route_pathtype_cmd,
b05a1c8b 8708 "show bgp X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8709 SHOW_STR
8710 BGP_STR
8711 "Network in the BGP routing table to display\n"
8712 "Display only the bestpath\n"
b05a1c8b
DS
8713 "Display only multipaths\n"
8714 "JavaScript Object Notation\n")
4092b06c 8715{
b05a1c8b 8716 u_char use_json = (argv[2] != NULL);
4092b06c 8717 if (strncmp (argv[1], "b", 1) == 0)
b05a1c8b 8718 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8719 else
b05a1c8b 8720 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8721}
8722
8723ALIAS (show_bgp_route_pathtype,
8724 show_bgp_ipv6_route_pathtype_cmd,
b05a1c8b 8725 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8726 SHOW_STR
8727 BGP_STR
8728 "Address family\n"
8729 "Network in the BGP routing table to display\n"
8730 "Display only the bestpath\n"
b05a1c8b
DS
8731 "Display only multipaths\n"
8732 "JavaScript Object Notation\n")
4092b06c
DS
8733
8734DEFUN (show_bgp_ipv6_safi_route_pathtype,
8735 show_bgp_ipv6_safi_route_pathtype_cmd,
b05a1c8b 8736 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath) {json}",
4092b06c
DS
8737 SHOW_STR
8738 BGP_STR
8739 "Address family\n"
8740 "Address Family modifier\n"
8741 "Address Family modifier\n"
8742 "Network in the BGP routing table to display\n"
8743 "Display only the bestpath\n"
b05a1c8b
DS
8744 "Display only multipaths\n"
8745 "JavaScript Object Notation\n")
4092b06c 8746{
b05a1c8b 8747 u_char use_json = (argv[3] != NULL);
4092b06c
DS
8748 if (strncmp (argv[0], "m", 1) == 0)
8749 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8750 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8751 else
b05a1c8b 8752 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8753 else
8754 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8755 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, use_json);
4092b06c 8756 else
b05a1c8b 8757 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, use_json);
95cbbd2a
ML
8758}
8759
718e3744 8760/* old command */
8761DEFUN (show_ipv6_bgp_route,
8762 show_ipv6_bgp_route_cmd,
b05a1c8b 8763 "show ipv6 bgp X:X::X:X {json}",
718e3744 8764 SHOW_STR
8765 IP_STR
8766 BGP_STR
b05a1c8b
DS
8767 "Network in the BGP routing table to display\n"
8768 "JavaScript Object Notation\n")
718e3744 8769{
b05a1c8b
DS
8770 u_char use_json = (argv[1] != NULL);
8771 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8772}
8773
8774DEFUN (show_bgp_prefix,
8775 show_bgp_prefix_cmd,
b05a1c8b 8776 "show bgp X:X::X:X/M {json}",
718e3744 8777 SHOW_STR
8778 BGP_STR
b05a1c8b
DS
8779 "IPv6 prefix <network>/<length>\n"
8780 "JavaScript Object Notation\n")
718e3744 8781{
b05a1c8b
DS
8782 u_char use_json = (argv[1] != NULL);
8783 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8784}
8785
8786ALIAS (show_bgp_prefix,
8787 show_bgp_ipv6_prefix_cmd,
b05a1c8b 8788 "show bgp ipv6 X:X::X:X/M {json}",
718e3744 8789 SHOW_STR
8790 BGP_STR
8791 "Address family\n"
b05a1c8b
DS
8792 "IPv6 prefix <network>/<length>\n"
8793 "JavaScript Object Notation\n")
718e3744 8794
95cbbd2a
ML
8795DEFUN (show_bgp_ipv6_safi_prefix,
8796 show_bgp_ipv6_safi_prefix_cmd,
b05a1c8b 8797 "show bgp ipv6 (unicast|multicast) X:X::X:X/M {json}",
95cbbd2a
ML
8798 SHOW_STR
8799 BGP_STR
8800 "Address family\n"
8801 "Address Family modifier\n"
8802 "Address Family modifier\n"
b05a1c8b
DS
8803 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8804 "JavaScript Object Notation\n")
95cbbd2a 8805{
b05a1c8b 8806 u_char use_json = (argv[2] != NULL);
95cbbd2a 8807 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 8808 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json);
95cbbd2a 8809
b05a1c8b 8810 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
4092b06c
DS
8811}
8812
8813DEFUN (show_bgp_prefix_pathtype,
8814 show_bgp_prefix_pathtype_cmd,
b05a1c8b 8815 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8816 SHOW_STR
8817 BGP_STR
8818 "IPv6 prefix <network>/<length>\n"
8819 "Display only the bestpath\n"
b05a1c8b
DS
8820 "Display only multipaths\n"
8821 "JavaScript Object Notation\n")
4092b06c 8822{
b05a1c8b 8823 u_char use_json = (argv[2] != NULL);
4092b06c 8824 if (strncmp (argv[1], "b", 1) == 0)
b05a1c8b 8825 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8826 else
b05a1c8b 8827 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8828}
8829
8830ALIAS (show_bgp_prefix_pathtype,
8831 show_bgp_ipv6_prefix_pathtype_cmd,
b05a1c8b 8832 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8833 SHOW_STR
8834 BGP_STR
8835 "Address family\n"
8836 "IPv6 prefix <network>/<length>\n"
8837 "Display only the bestpath\n"
b05a1c8b
DS
8838 "Display only multipaths\n"
8839 "JavaScript Object Notation\n")
4092b06c
DS
8840
8841DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8842 show_bgp_ipv6_safi_prefix_pathtype_cmd,
b05a1c8b 8843 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath) {json}",
4092b06c
DS
8844 SHOW_STR
8845 BGP_STR
8846 "Address family\n"
8847 "Address Family modifier\n"
8848 "Address Family modifier\n"
8849 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8850 "Display only the bestpath\n"
b05a1c8b
DS
8851 "Display only multipaths\n"
8852 "JavaScript Object Notation\n")
4092b06c 8853{
b05a1c8b 8854 u_char use_json = (argv[3] != NULL);
4092b06c
DS
8855 if (strncmp (argv[0], "m", 1) == 0)
8856 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8857 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8858 else
b05a1c8b 8859 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
4092b06c
DS
8860 else
8861 if (strncmp (argv[2], "b", 1) == 0)
b05a1c8b 8862 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, use_json);
4092b06c 8863 else
b05a1c8b 8864 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, use_json);
95cbbd2a
ML
8865}
8866
718e3744 8867/* old command */
8868DEFUN (show_ipv6_bgp_prefix,
8869 show_ipv6_bgp_prefix_cmd,
b05a1c8b 8870 "show ipv6 bgp X:X::X:X/M {json}",
718e3744 8871 SHOW_STR
8872 IP_STR
8873 BGP_STR
b05a1c8b
DS
8874 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8875 "JavaScript Object Notation\n")
718e3744 8876{
b05a1c8b
DS
8877 u_char use_json = (argv[1] != NULL);
8878 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 8879}
8880
bb46e94f 8881DEFUN (show_bgp_view,
8882 show_bgp_view_cmd,
b05a1c8b 8883 "show bgp view WORD {json}",
bb46e94f 8884 SHOW_STR
8885 BGP_STR
8886 "BGP view\n"
b05a1c8b
DS
8887 "View name\n"
8888 "JavaScript Object Notation\n")
bb46e94f 8889{
8890 struct bgp *bgp;
b05a1c8b 8891 u_char use_json = (argv[1] != NULL);
bb46e94f 8892
8893 /* BGP structure lookup. */
8894 bgp = bgp_lookup_by_name (argv[0]);
8895 if (bgp == NULL)
8896 {
8897 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8898 return CMD_WARNING;
8899 }
8900
b05a1c8b 8901 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json);
bb46e94f 8902}
8903
8904ALIAS (show_bgp_view,
8905 show_bgp_view_ipv6_cmd,
b05a1c8b 8906 "show bgp view WORD ipv6 {json}",
bb46e94f 8907 SHOW_STR
8908 BGP_STR
8909 "BGP view\n"
8910 "View name\n"
b05a1c8b
DS
8911 "Address family\n"
8912 "JavaScript Object Notation\n")
bb46e94f 8913
8914DEFUN (show_bgp_view_route,
8915 show_bgp_view_route_cmd,
b05a1c8b 8916 "show bgp view WORD X:X::X:X {json}",
bb46e94f 8917 SHOW_STR
8918 BGP_STR
8919 "BGP view\n"
8920 "View name\n"
b05a1c8b
DS
8921 "Network in the BGP routing table to display\n"
8922 "JavaScript Object Notation\n")
bb46e94f 8923{
b05a1c8b
DS
8924 u_char use_json = (argv[2] != NULL);
8925 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json);
bb46e94f 8926}
8927
8928ALIAS (show_bgp_view_route,
8929 show_bgp_view_ipv6_route_cmd,
b05a1c8b 8930 "show bgp view WORD ipv6 X:X::X:X {json}",
bb46e94f 8931 SHOW_STR
8932 BGP_STR
8933 "BGP view\n"
8934 "View name\n"
8935 "Address family\n"
b05a1c8b
DS
8936 "Network in the BGP routing table to display\n"
8937 "JavaScript Object Notation\n")
bb46e94f 8938
8939DEFUN (show_bgp_view_prefix,
8940 show_bgp_view_prefix_cmd,
b05a1c8b 8941 "show bgp view WORD X:X::X:X/M {json}",
bb46e94f 8942 SHOW_STR
8943 BGP_STR
8944 "BGP view\n"
8945 "View name\n"
b05a1c8b
DS
8946 "IPv6 prefix <network>/<length>\n"
8947 "JavaScript Object Notation\n")
bb46e94f 8948{
b05a1c8b
DS
8949 u_char use_json = (argv[2] != NULL);
8950 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json);
bb46e94f 8951}
8952
8953ALIAS (show_bgp_view_prefix,
8954 show_bgp_view_ipv6_prefix_cmd,
b05a1c8b 8955 "show bgp view WORD ipv6 X:X::X:X/M {json}",
bb46e94f 8956 SHOW_STR
8957 BGP_STR
8958 "BGP view\n"
8959 "View name\n"
8960 "Address family\n"
b05a1c8b
DS
8961 "IPv6 prefix <network>/<length>\n"
8962 "JavaScript Object Notation\n")
bb46e94f 8963
718e3744 8964/* old command */
8965DEFUN (show_ipv6_mbgp,
8966 show_ipv6_mbgp_cmd,
b05a1c8b 8967 "show ipv6 mbgp {json}",
718e3744 8968 SHOW_STR
8969 IP_STR
b05a1c8b
DS
8970 MBGP_STR
8971 "JavaScript Object Notation\n")
718e3744 8972{
b05a1c8b 8973 u_char use_json = (argv[0] != NULL);
5a646650 8974 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
b05a1c8b 8975 NULL, use_json);
718e3744 8976}
8977
8978/* old command */
8979DEFUN (show_ipv6_mbgp_route,
8980 show_ipv6_mbgp_route_cmd,
b05a1c8b 8981 "show ipv6 mbgp X:X::X:X {json}",
718e3744 8982 SHOW_STR
8983 IP_STR
8984 MBGP_STR
b05a1c8b
DS
8985 "Network in the MBGP routing table to display\n"
8986 "JavaScript Object Notation\n")
718e3744 8987{
b05a1c8b
DS
8988 u_char use_json = (argv[1] != NULL);
8989 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json);
718e3744 8990}
8991
8992/* old command */
8993DEFUN (show_ipv6_mbgp_prefix,
8994 show_ipv6_mbgp_prefix_cmd,
b05a1c8b 8995 "show ipv6 mbgp X:X::X:X/M {json}",
718e3744 8996 SHOW_STR
8997 IP_STR
8998 MBGP_STR
b05a1c8b
DS
8999 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9000 "JavaScript Object Notation\n")
718e3744 9001{
b05a1c8b
DS
9002 u_char use_json = (argv[1] != NULL);
9003 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json);
718e3744 9004}
9005#endif
6b0655a2 9006
718e3744 9007
94f2b392 9008static int
fd79ac91 9009bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
718e3744 9010 safi_t safi, enum bgp_show_type type)
9011{
9012 int i;
9013 struct buffer *b;
9014 char *regstr;
9015 int first;
9016 regex_t *regex;
5a646650 9017 int rc;
718e3744 9018
9019 first = 0;
9020 b = buffer_new (1024);
9021 for (i = 0; i < argc; i++)
9022 {
9023 if (first)
9024 buffer_putc (b, ' ');
9025 else
9026 {
9027 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9028 continue;
9029 first = 1;
9030 }
9031
9032 buffer_putstr (b, argv[i]);
9033 }
9034 buffer_putc (b, '\0');
9035
9036 regstr = buffer_getstr (b);
9037 buffer_free (b);
9038
9039 regex = bgp_regcomp (regstr);
3b8b1855 9040 XFREE(MTYPE_TMP, regstr);
718e3744 9041 if (! regex)
9042 {
9043 vty_out (vty, "Can't compile regexp %s%s", argv[0],
9044 VTY_NEWLINE);
9045 return CMD_WARNING;
9046 }
9047
b05a1c8b 9048 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
5a646650 9049 bgp_regex_free (regex);
9050 return rc;
718e3744 9051}
9052
9053DEFUN (show_ip_bgp_regexp,
9054 show_ip_bgp_regexp_cmd,
9055 "show ip bgp regexp .LINE",
9056 SHOW_STR
9057 IP_STR
9058 BGP_STR
9059 "Display routes matching the AS path regular expression\n"
9060 "A regular-expression to match the BGP AS paths\n")
9061{
9062 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9063 bgp_show_type_regexp);
9064}
9065
9066DEFUN (show_ip_bgp_flap_regexp,
9067 show_ip_bgp_flap_regexp_cmd,
9068 "show ip bgp flap-statistics regexp .LINE",
9069 SHOW_STR
9070 IP_STR
9071 BGP_STR
9072 "Display flap statistics of routes\n"
9073 "Display routes matching the AS path regular expression\n"
9074 "A regular-expression to match the BGP AS paths\n")
9075{
9076 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9077 bgp_show_type_flap_regexp);
9078}
9079
9080DEFUN (show_ip_bgp_ipv4_regexp,
9081 show_ip_bgp_ipv4_regexp_cmd,
9082 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
9083 SHOW_STR
9084 IP_STR
9085 BGP_STR
9086 "Address family\n"
9087 "Address Family modifier\n"
9088 "Address Family modifier\n"
9089 "Display routes matching the AS path regular expression\n"
9090 "A regular-expression to match the BGP AS paths\n")
9091{
9092 if (strncmp (argv[0], "m", 1) == 0)
9093 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
9094 bgp_show_type_regexp);
9095
9096 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9097 bgp_show_type_regexp);
9098}
9099
9100#ifdef HAVE_IPV6
9101DEFUN (show_bgp_regexp,
9102 show_bgp_regexp_cmd,
9103 "show bgp regexp .LINE",
9104 SHOW_STR
9105 BGP_STR
9106 "Display routes matching the AS path regular expression\n"
9107 "A regular-expression to match the BGP AS paths\n")
9108{
9109 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9110 bgp_show_type_regexp);
9111}
9112
9113ALIAS (show_bgp_regexp,
9114 show_bgp_ipv6_regexp_cmd,
9115 "show bgp ipv6 regexp .LINE",
9116 SHOW_STR
9117 BGP_STR
9118 "Address family\n"
9119 "Display routes matching the AS path regular expression\n"
9120 "A regular-expression to match the BGP AS paths\n")
9121
9122/* old command */
9123DEFUN (show_ipv6_bgp_regexp,
9124 show_ipv6_bgp_regexp_cmd,
9125 "show ipv6 bgp regexp .LINE",
9126 SHOW_STR
9127 IP_STR
9128 BGP_STR
9129 "Display routes matching the AS path regular expression\n"
9130 "A regular-expression to match the BGP AS paths\n")
9131{
9132 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9133 bgp_show_type_regexp);
9134}
9135
9136/* old command */
9137DEFUN (show_ipv6_mbgp_regexp,
9138 show_ipv6_mbgp_regexp_cmd,
9139 "show ipv6 mbgp regexp .LINE",
9140 SHOW_STR
9141 IP_STR
9142 BGP_STR
9143 "Display routes matching the AS path regular expression\n"
9144 "A regular-expression to match the MBGP AS paths\n")
9145{
9146 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
9147 bgp_show_type_regexp);
9148}
9149#endif /* HAVE_IPV6 */
6b0655a2 9150
94f2b392 9151static int
fd79ac91 9152bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
718e3744 9153 safi_t safi, enum bgp_show_type type)
9154{
9155 struct prefix_list *plist;
9156
9157 plist = prefix_list_lookup (afi, prefix_list_str);
9158 if (plist == NULL)
9159 {
9160 vty_out (vty, "%% %s is not a valid prefix-list name%s",
9161 prefix_list_str, VTY_NEWLINE);
9162 return CMD_WARNING;
9163 }
9164
b05a1c8b 9165 return bgp_show (vty, NULL, afi, safi, type, plist, 0);
718e3744 9166}
9167
9168DEFUN (show_ip_bgp_prefix_list,
9169 show_ip_bgp_prefix_list_cmd,
9170 "show ip bgp prefix-list WORD",
9171 SHOW_STR
9172 IP_STR
9173 BGP_STR
9174 "Display routes conforming to the prefix-list\n"
9175 "IP prefix-list name\n")
9176{
9177 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
9178 bgp_show_type_prefix_list);
9179}
9180
9181DEFUN (show_ip_bgp_flap_prefix_list,
9182 show_ip_bgp_flap_prefix_list_cmd,
9183 "show ip bgp flap-statistics prefix-list WORD",
9184 SHOW_STR
9185 IP_STR
9186 BGP_STR
9187 "Display flap statistics of routes\n"
9188 "Display routes conforming to the prefix-list\n"
9189 "IP prefix-list name\n")
9190{
9191 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
9192 bgp_show_type_flap_prefix_list);
9193}
9194
9195DEFUN (show_ip_bgp_ipv4_prefix_list,
9196 show_ip_bgp_ipv4_prefix_list_cmd,
9197 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
9198 SHOW_STR
9199 IP_STR
9200 BGP_STR
9201 "Address family\n"
9202 "Address Family modifier\n"
9203 "Address Family modifier\n"
9204 "Display routes conforming to the prefix-list\n"
9205 "IP prefix-list name\n")
9206{
9207 if (strncmp (argv[0], "m", 1) == 0)
9208 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9209 bgp_show_type_prefix_list);
9210
9211 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
9212 bgp_show_type_prefix_list);
9213}
9214
9215#ifdef HAVE_IPV6
9216DEFUN (show_bgp_prefix_list,
9217 show_bgp_prefix_list_cmd,
9218 "show bgp prefix-list WORD",
9219 SHOW_STR
9220 BGP_STR
9221 "Display routes conforming to the prefix-list\n"
9222 "IPv6 prefix-list name\n")
9223{
9224 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9225 bgp_show_type_prefix_list);
9226}
9227
9228ALIAS (show_bgp_prefix_list,
9229 show_bgp_ipv6_prefix_list_cmd,
9230 "show bgp ipv6 prefix-list WORD",
9231 SHOW_STR
9232 BGP_STR
9233 "Address family\n"
9234 "Display routes conforming to the prefix-list\n"
9235 "IPv6 prefix-list name\n")
9236
9237/* old command */
9238DEFUN (show_ipv6_bgp_prefix_list,
9239 show_ipv6_bgp_prefix_list_cmd,
9240 "show ipv6 bgp prefix-list WORD",
9241 SHOW_STR
9242 IPV6_STR
9243 BGP_STR
9244 "Display routes matching the prefix-list\n"
9245 "IPv6 prefix-list name\n")
9246{
9247 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9248 bgp_show_type_prefix_list);
9249}
9250
9251/* old command */
9252DEFUN (show_ipv6_mbgp_prefix_list,
9253 show_ipv6_mbgp_prefix_list_cmd,
9254 "show ipv6 mbgp prefix-list WORD",
9255 SHOW_STR
9256 IPV6_STR
9257 MBGP_STR
9258 "Display routes matching the prefix-list\n"
9259 "IPv6 prefix-list name\n")
9260{
9261 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9262 bgp_show_type_prefix_list);
9263}
9264#endif /* HAVE_IPV6 */
6b0655a2 9265
94f2b392 9266static int
fd79ac91 9267bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
718e3744 9268 safi_t safi, enum bgp_show_type type)
9269{
9270 struct as_list *as_list;
9271
9272 as_list = as_list_lookup (filter);
9273 if (as_list == NULL)
9274 {
9275 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
9276 return CMD_WARNING;
9277 }
9278
b05a1c8b 9279 return bgp_show (vty, NULL, afi, safi, type, as_list, 0);
718e3744 9280}
9281
9282DEFUN (show_ip_bgp_filter_list,
9283 show_ip_bgp_filter_list_cmd,
9284 "show ip bgp filter-list WORD",
9285 SHOW_STR
9286 IP_STR
9287 BGP_STR
9288 "Display routes conforming to the filter-list\n"
9289 "Regular expression access list name\n")
9290{
9291 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
9292 bgp_show_type_filter_list);
9293}
9294
9295DEFUN (show_ip_bgp_flap_filter_list,
9296 show_ip_bgp_flap_filter_list_cmd,
9297 "show ip bgp flap-statistics filter-list WORD",
9298 SHOW_STR
9299 IP_STR
9300 BGP_STR
9301 "Display flap statistics of routes\n"
9302 "Display routes conforming to the filter-list\n"
9303 "Regular expression access list name\n")
9304{
9305 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
9306 bgp_show_type_flap_filter_list);
9307}
9308
9309DEFUN (show_ip_bgp_ipv4_filter_list,
9310 show_ip_bgp_ipv4_filter_list_cmd,
9311 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
9312 SHOW_STR
9313 IP_STR
9314 BGP_STR
9315 "Address family\n"
9316 "Address Family modifier\n"
9317 "Address Family modifier\n"
9318 "Display routes conforming to the filter-list\n"
9319 "Regular expression access list name\n")
9320{
9321 if (strncmp (argv[0], "m", 1) == 0)
9322 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9323 bgp_show_type_filter_list);
9324
9325 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
9326 bgp_show_type_filter_list);
9327}
9328
9329#ifdef HAVE_IPV6
9330DEFUN (show_bgp_filter_list,
9331 show_bgp_filter_list_cmd,
9332 "show bgp filter-list WORD",
9333 SHOW_STR
9334 BGP_STR
9335 "Display routes conforming to the filter-list\n"
9336 "Regular expression access list name\n")
9337{
9338 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9339 bgp_show_type_filter_list);
9340}
9341
9342ALIAS (show_bgp_filter_list,
9343 show_bgp_ipv6_filter_list_cmd,
9344 "show bgp ipv6 filter-list WORD",
9345 SHOW_STR
9346 BGP_STR
9347 "Address family\n"
9348 "Display routes conforming to the filter-list\n"
9349 "Regular expression access list name\n")
9350
9351/* old command */
9352DEFUN (show_ipv6_bgp_filter_list,
9353 show_ipv6_bgp_filter_list_cmd,
9354 "show ipv6 bgp filter-list WORD",
9355 SHOW_STR
9356 IPV6_STR
9357 BGP_STR
9358 "Display routes conforming to the filter-list\n"
9359 "Regular expression access list name\n")
9360{
9361 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9362 bgp_show_type_filter_list);
9363}
9364
9365/* old command */
9366DEFUN (show_ipv6_mbgp_filter_list,
9367 show_ipv6_mbgp_filter_list_cmd,
9368 "show ipv6 mbgp filter-list WORD",
9369 SHOW_STR
9370 IPV6_STR
9371 MBGP_STR
9372 "Display routes conforming to the filter-list\n"
9373 "Regular expression access list name\n")
9374{
9375 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9376 bgp_show_type_filter_list);
9377}
9378#endif /* HAVE_IPV6 */
6b0655a2 9379
94f2b392 9380static int
fd79ac91 9381bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
718e3744 9382 safi_t safi, enum bgp_show_type type)
9383{
9384 struct route_map *rmap;
9385
9386 rmap = route_map_lookup_by_name (rmap_str);
9387 if (! rmap)
9388 {
9389 vty_out (vty, "%% %s is not a valid route-map name%s",
9390 rmap_str, VTY_NEWLINE);
9391 return CMD_WARNING;
9392 }
9393
b05a1c8b 9394 return bgp_show (vty, NULL, afi, safi, type, rmap, 0);
718e3744 9395}
9396
9397DEFUN (show_ip_bgp_route_map,
9398 show_ip_bgp_route_map_cmd,
9399 "show ip bgp route-map WORD",
9400 SHOW_STR
9401 IP_STR
9402 BGP_STR
9403 "Display routes matching the route-map\n"
9404 "A route-map to match on\n")
9405{
9406 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
9407 bgp_show_type_route_map);
9408}
9409
9410DEFUN (show_ip_bgp_flap_route_map,
9411 show_ip_bgp_flap_route_map_cmd,
9412 "show ip bgp flap-statistics route-map WORD",
9413 SHOW_STR
9414 IP_STR
9415 BGP_STR
9416 "Display flap statistics of routes\n"
9417 "Display routes matching the route-map\n"
9418 "A route-map to match on\n")
9419{
9420 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
9421 bgp_show_type_flap_route_map);
9422}
9423
9424DEFUN (show_ip_bgp_ipv4_route_map,
9425 show_ip_bgp_ipv4_route_map_cmd,
9426 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
9427 SHOW_STR
9428 IP_STR
9429 BGP_STR
9430 "Address family\n"
9431 "Address Family modifier\n"
9432 "Address Family modifier\n"
9433 "Display routes matching the route-map\n"
9434 "A route-map to match on\n")
9435{
9436 if (strncmp (argv[0], "m", 1) == 0)
9437 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9438 bgp_show_type_route_map);
9439
9440 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
9441 bgp_show_type_route_map);
9442}
9443
9444DEFUN (show_bgp_route_map,
9445 show_bgp_route_map_cmd,
9446 "show bgp route-map WORD",
9447 SHOW_STR
9448 BGP_STR
9449 "Display routes matching the route-map\n"
9450 "A route-map to match on\n")
9451{
9452 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9453 bgp_show_type_route_map);
9454}
9455
9456ALIAS (show_bgp_route_map,
9457 show_bgp_ipv6_route_map_cmd,
9458 "show bgp ipv6 route-map WORD",
9459 SHOW_STR
9460 BGP_STR
9461 "Address family\n"
9462 "Display routes matching the route-map\n"
9463 "A route-map to match on\n")
6b0655a2 9464
718e3744 9465DEFUN (show_ip_bgp_cidr_only,
9466 show_ip_bgp_cidr_only_cmd,
9467 "show ip bgp cidr-only",
9468 SHOW_STR
9469 IP_STR
9470 BGP_STR
9471 "Display only routes with non-natural netmasks\n")
9472{
9473 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9474 bgp_show_type_cidr_only, NULL, 0);
718e3744 9475}
9476
9477DEFUN (show_ip_bgp_flap_cidr_only,
9478 show_ip_bgp_flap_cidr_only_cmd,
9479 "show ip bgp flap-statistics cidr-only",
9480 SHOW_STR
9481 IP_STR
9482 BGP_STR
9483 "Display flap statistics of routes\n"
9484 "Display only routes with non-natural netmasks\n")
9485{
9486 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9487 bgp_show_type_flap_cidr_only, NULL, 0);
718e3744 9488}
9489
9490DEFUN (show_ip_bgp_ipv4_cidr_only,
9491 show_ip_bgp_ipv4_cidr_only_cmd,
9492 "show ip bgp ipv4 (unicast|multicast) cidr-only",
9493 SHOW_STR
9494 IP_STR
9495 BGP_STR
9496 "Address family\n"
9497 "Address Family modifier\n"
9498 "Address Family modifier\n"
9499 "Display only routes with non-natural netmasks\n")
9500{
9501 if (strncmp (argv[0], "m", 1) == 0)
9502 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
b05a1c8b 9503 bgp_show_type_cidr_only, NULL, 0);
718e3744 9504
9505 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9506 bgp_show_type_cidr_only, NULL, 0);
718e3744 9507}
6b0655a2 9508
718e3744 9509DEFUN (show_ip_bgp_community_all,
9510 show_ip_bgp_community_all_cmd,
9511 "show ip bgp community",
9512 SHOW_STR
9513 IP_STR
9514 BGP_STR
9515 "Display routes matching the communities\n")
9516{
9517 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9518 bgp_show_type_community_all, NULL, 0);
718e3744 9519}
9520
9521DEFUN (show_ip_bgp_ipv4_community_all,
9522 show_ip_bgp_ipv4_community_all_cmd,
9523 "show ip bgp ipv4 (unicast|multicast) community",
9524 SHOW_STR
9525 IP_STR
9526 BGP_STR
9527 "Address family\n"
9528 "Address Family modifier\n"
9529 "Address Family modifier\n"
9530 "Display routes matching the communities\n")
9531{
9532 if (strncmp (argv[0], "m", 1) == 0)
9533 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
b05a1c8b 9534 bgp_show_type_community_all, NULL, 0);
718e3744 9535
9536 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 9537 bgp_show_type_community_all, NULL, 0);
718e3744 9538}
9539
9540#ifdef HAVE_IPV6
9541DEFUN (show_bgp_community_all,
9542 show_bgp_community_all_cmd,
9543 "show bgp community",
9544 SHOW_STR
9545 BGP_STR
9546 "Display routes matching the communities\n")
9547{
9548 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 9549 bgp_show_type_community_all, NULL, 0);
718e3744 9550}
9551
9552ALIAS (show_bgp_community_all,
9553 show_bgp_ipv6_community_all_cmd,
9554 "show bgp ipv6 community",
9555 SHOW_STR
9556 BGP_STR
9557 "Address family\n"
9558 "Display routes matching the communities\n")
9559
9560/* old command */
9561DEFUN (show_ipv6_bgp_community_all,
9562 show_ipv6_bgp_community_all_cmd,
9563 "show ipv6 bgp community",
9564 SHOW_STR
9565 IPV6_STR
9566 BGP_STR
9567 "Display routes matching the communities\n")
9568{
9569 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
b05a1c8b 9570 bgp_show_type_community_all, NULL, 0);
718e3744 9571}
9572
9573/* old command */
9574DEFUN (show_ipv6_mbgp_community_all,
9575 show_ipv6_mbgp_community_all_cmd,
9576 "show ipv6 mbgp community",
9577 SHOW_STR
9578 IPV6_STR
9579 MBGP_STR
9580 "Display routes matching the communities\n")
9581{
9582 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
b05a1c8b 9583 bgp_show_type_community_all, NULL, 0);
718e3744 9584}
9585#endif /* HAVE_IPV6 */
6b0655a2 9586
94f2b392 9587static int
95cbbd2a
ML
9588bgp_show_community (struct vty *vty, const char *view_name, int argc,
9589 const char **argv, int exact, afi_t afi, safi_t safi)
718e3744 9590{
9591 struct community *com;
9592 struct buffer *b;
95cbbd2a 9593 struct bgp *bgp;
718e3744 9594 int i;
9595 char *str;
9596 int first = 0;
9597
95cbbd2a
ML
9598 /* BGP structure lookup */
9599 if (view_name)
9600 {
9601 bgp = bgp_lookup_by_name (view_name);
9602 if (bgp == NULL)
9603 {
9604 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9605 return CMD_WARNING;
9606 }
9607 }
9608 else
9609 {
9610 bgp = bgp_get_default ();
9611 if (bgp == NULL)
9612 {
9613 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9614 return CMD_WARNING;
9615 }
9616 }
9617
718e3744 9618 b = buffer_new (1024);
9619 for (i = 0; i < argc; i++)
9620 {
9621 if (first)
9622 buffer_putc (b, ' ');
9623 else
9624 {
9625 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9626 continue;
9627 first = 1;
9628 }
9629
9630 buffer_putstr (b, argv[i]);
9631 }
9632 buffer_putc (b, '\0');
9633
9634 str = buffer_getstr (b);
9635 buffer_free (b);
9636
9637 com = community_str2com (str);
3b8b1855 9638 XFREE (MTYPE_TMP, str);
718e3744 9639 if (! com)
9640 {
9641 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9642 return CMD_WARNING;
9643 }
9644
95cbbd2a 9645 return bgp_show (vty, bgp, afi, safi,
5a646650 9646 (exact ? bgp_show_type_community_exact :
b05a1c8b 9647 bgp_show_type_community), com, 0);
718e3744 9648}
9649
9650DEFUN (show_ip_bgp_community,
9651 show_ip_bgp_community_cmd,
9652 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9653 SHOW_STR
9654 IP_STR
9655 BGP_STR
9656 "Display routes matching the communities\n"
9657 "community number\n"
9658 "Do not send outside local AS (well-known community)\n"
9659 "Do not advertise to any peer (well-known community)\n"
9660 "Do not export to next AS (well-known community)\n")
9661{
95cbbd2a 9662 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 9663}
9664
9665ALIAS (show_ip_bgp_community,
9666 show_ip_bgp_community2_cmd,
9667 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9668 SHOW_STR
9669 IP_STR
9670 BGP_STR
9671 "Display routes matching the communities\n"
9672 "community number\n"
9673 "Do not send outside local AS (well-known community)\n"
9674 "Do not advertise to any peer (well-known community)\n"
9675 "Do not export to next AS (well-known community)\n"
9676 "community number\n"
9677 "Do not send outside local AS (well-known community)\n"
9678 "Do not advertise to any peer (well-known community)\n"
9679 "Do not export to next AS (well-known community)\n")
9680
9681ALIAS (show_ip_bgp_community,
9682 show_ip_bgp_community3_cmd,
9683 "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)",
9684 SHOW_STR
9685 IP_STR
9686 BGP_STR
9687 "Display routes matching the communities\n"
9688 "community number\n"
9689 "Do not send outside local AS (well-known community)\n"
9690 "Do not advertise to any peer (well-known community)\n"
9691 "Do not export to next AS (well-known community)\n"
9692 "community number\n"
9693 "Do not send outside local AS (well-known community)\n"
9694 "Do not advertise to any peer (well-known community)\n"
9695 "Do not export to next AS (well-known community)\n"
9696 "community number\n"
9697 "Do not send outside local AS (well-known community)\n"
9698 "Do not advertise to any peer (well-known community)\n"
9699 "Do not export to next AS (well-known community)\n")
9700
9701ALIAS (show_ip_bgp_community,
9702 show_ip_bgp_community4_cmd,
9703 "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)",
9704 SHOW_STR
9705 IP_STR
9706 BGP_STR
9707 "Display routes matching the communities\n"
9708 "community number\n"
9709 "Do not send outside local AS (well-known community)\n"
9710 "Do not advertise to any peer (well-known community)\n"
9711 "Do not export to next AS (well-known community)\n"
9712 "community number\n"
9713 "Do not send outside local AS (well-known community)\n"
9714 "Do not advertise to any peer (well-known community)\n"
9715 "Do not export to next AS (well-known community)\n"
9716 "community number\n"
9717 "Do not send outside local AS (well-known community)\n"
9718 "Do not advertise to any peer (well-known community)\n"
9719 "Do not export to next AS (well-known community)\n"
9720 "community number\n"
9721 "Do not send outside local AS (well-known community)\n"
9722 "Do not advertise to any peer (well-known community)\n"
9723 "Do not export to next AS (well-known community)\n")
9724
9725DEFUN (show_ip_bgp_ipv4_community,
9726 show_ip_bgp_ipv4_community_cmd,
9727 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9728 SHOW_STR
9729 IP_STR
9730 BGP_STR
9731 "Address family\n"
9732 "Address Family modifier\n"
9733 "Address Family modifier\n"
9734 "Display routes matching the communities\n"
9735 "community number\n"
9736 "Do not send outside local AS (well-known community)\n"
9737 "Do not advertise to any peer (well-known community)\n"
9738 "Do not export to next AS (well-known community)\n")
9739{
9740 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 9741 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
718e3744 9742
95cbbd2a 9743 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 9744}
9745
9746ALIAS (show_ip_bgp_ipv4_community,
9747 show_ip_bgp_ipv4_community2_cmd,
9748 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9749 SHOW_STR
9750 IP_STR
9751 BGP_STR
9752 "Address family\n"
9753 "Address Family modifier\n"
9754 "Address Family modifier\n"
9755 "Display routes matching the communities\n"
9756 "community number\n"
9757 "Do not send outside local AS (well-known community)\n"
9758 "Do not advertise to any peer (well-known community)\n"
9759 "Do not export to next AS (well-known community)\n"
9760 "community number\n"
9761 "Do not send outside local AS (well-known community)\n"
9762 "Do not advertise to any peer (well-known community)\n"
9763 "Do not export to next AS (well-known community)\n")
9764
9765ALIAS (show_ip_bgp_ipv4_community,
9766 show_ip_bgp_ipv4_community3_cmd,
9767 "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)",
9768 SHOW_STR
9769 IP_STR
9770 BGP_STR
9771 "Address family\n"
9772 "Address Family modifier\n"
9773 "Address Family modifier\n"
9774 "Display routes matching the communities\n"
9775 "community number\n"
9776 "Do not send outside local AS (well-known community)\n"
9777 "Do not advertise to any peer (well-known community)\n"
9778 "Do not export to next AS (well-known community)\n"
9779 "community number\n"
9780 "Do not send outside local AS (well-known community)\n"
9781 "Do not advertise to any peer (well-known community)\n"
9782 "Do not export to next AS (well-known community)\n"
9783 "community number\n"
9784 "Do not send outside local AS (well-known community)\n"
9785 "Do not advertise to any peer (well-known community)\n"
9786 "Do not export to next AS (well-known community)\n")
9787
9788ALIAS (show_ip_bgp_ipv4_community,
9789 show_ip_bgp_ipv4_community4_cmd,
9790 "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)",
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 "community number\n"
9799 "Do not send outside local AS (well-known community)\n"
9800 "Do not advertise to any peer (well-known community)\n"
9801 "Do not export to next AS (well-known community)\n"
9802 "community number\n"
9803 "Do not send outside local AS (well-known community)\n"
9804 "Do not advertise to any peer (well-known community)\n"
9805 "Do not export to next AS (well-known community)\n"
9806 "community number\n"
9807 "Do not send outside local AS (well-known community)\n"
9808 "Do not advertise to any peer (well-known community)\n"
9809 "Do not export to next AS (well-known community)\n"
9810 "community number\n"
9811 "Do not send outside local AS (well-known community)\n"
9812 "Do not advertise to any peer (well-known community)\n"
9813 "Do not export to next AS (well-known community)\n")
9814
95cbbd2a
ML
9815DEFUN (show_bgp_view_afi_safi_community_all,
9816 show_bgp_view_afi_safi_community_all_cmd,
9817#ifdef HAVE_IPV6
9818 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
9819#else
9820 "show bgp view WORD ipv4 (unicast|multicast) community",
9821#endif
9822 SHOW_STR
9823 BGP_STR
9824 "BGP view\n"
2b00515a 9825 "View name\n"
95cbbd2a
ML
9826 "Address family\n"
9827#ifdef HAVE_IPV6
9828 "Address family\n"
9829#endif
9830 "Address Family modifier\n"
9831 "Address Family modifier\n"
2b00515a 9832 "Display routes matching the communities\n")
95cbbd2a
ML
9833{
9834 int afi;
9835 int safi;
9836 struct bgp *bgp;
9837
9838 /* BGP structure lookup. */
9839 bgp = bgp_lookup_by_name (argv[0]);
9840 if (bgp == NULL)
9841 {
9842 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9843 return CMD_WARNING;
9844 }
9845
9846#ifdef HAVE_IPV6
9847 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9848 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9849#else
9850 afi = AFI_IP;
9851 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9852#endif
b05a1c8b 9853 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
95cbbd2a
ML
9854}
9855
9856DEFUN (show_bgp_view_afi_safi_community,
9857 show_bgp_view_afi_safi_community_cmd,
9858#ifdef HAVE_IPV6
9859 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9860#else
9861 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9862#endif
9863 SHOW_STR
9864 BGP_STR
9865 "BGP view\n"
2b00515a 9866 "View name\n"
95cbbd2a
ML
9867 "Address family\n"
9868#ifdef HAVE_IPV6
9869 "Address family\n"
9870#endif
9871 "Address family modifier\n"
9872 "Address family modifier\n"
9873 "Display routes matching the communities\n"
9874 "community number\n"
9875 "Do not send outside local AS (well-known community)\n"
9876 "Do not advertise to any peer (well-known community)\n"
9877 "Do not export to next AS (well-known community)\n")
9878{
9879 int afi;
9880 int safi;
9881
9882#ifdef HAVE_IPV6
9883 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9884 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9885 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
9886#else
9887 afi = AFI_IP;
9888 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9889 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
9890#endif
9891}
9892
9893ALIAS (show_bgp_view_afi_safi_community,
9894 show_bgp_view_afi_safi_community2_cmd,
9895#ifdef HAVE_IPV6
9896 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9897#else
9898 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9899#endif
9900 SHOW_STR
9901 BGP_STR
9902 "BGP view\n"
2b00515a 9903 "View name\n"
95cbbd2a
ML
9904 "Address family\n"
9905#ifdef HAVE_IPV6
9906 "Address family\n"
9907#endif
9908 "Address family modifier\n"
9909 "Address family modifier\n"
9910 "Display routes matching the communities\n"
9911 "community number\n"
9912 "Do not send outside local AS (well-known community)\n"
9913 "Do not advertise to any peer (well-known community)\n"
9914 "Do not export to next AS (well-known community)\n"
9915 "community number\n"
9916 "Do not send outside local AS (well-known community)\n"
9917 "Do not advertise to any peer (well-known community)\n"
9918 "Do not export to next AS (well-known community)\n")
9919
9920ALIAS (show_bgp_view_afi_safi_community,
9921 show_bgp_view_afi_safi_community3_cmd,
9922#ifdef HAVE_IPV6
9923 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9924#else
9925 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9926#endif
9927 SHOW_STR
9928 BGP_STR
9929 "BGP view\n"
2b00515a 9930 "View name\n"
95cbbd2a
ML
9931 "Address family\n"
9932#ifdef HAVE_IPV6
9933 "Address family\n"
9934#endif
9935 "Address family modifier\n"
9936 "Address family modifier\n"
9937 "Display routes matching the communities\n"
9938 "community number\n"
9939 "Do not send outside local AS (well-known community)\n"
9940 "Do not advertise to any peer (well-known community)\n"
9941 "Do not export to next AS (well-known community)\n"
9942 "community number\n"
9943 "Do not send outside local AS (well-known community)\n"
9944 "Do not advertise to any peer (well-known community)\n"
9945 "Do not export to next AS (well-known community)\n"
9946 "community number\n"
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
9951ALIAS (show_bgp_view_afi_safi_community,
9952 show_bgp_view_afi_safi_community4_cmd,
9953#ifdef HAVE_IPV6
9954 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9955#else
9956 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9957#endif
9958 SHOW_STR
9959 BGP_STR
9960 "BGP view\n"
2b00515a 9961 "View name\n"
95cbbd2a
ML
9962 "Address family\n"
9963#ifdef HAVE_IPV6
9964 "Address family\n"
9965#endif
9966 "Address family modifier\n"
9967 "Address family modifier\n"
9968 "Display routes matching the communities\n"
9969 "community number\n"
9970 "Do not send outside local AS (well-known community)\n"
9971 "Do not advertise to any peer (well-known community)\n"
9972 "Do not export to next AS (well-known community)\n"
9973 "community number\n"
9974 "Do not send outside local AS (well-known community)\n"
9975 "Do not advertise to any peer (well-known community)\n"
9976 "Do not export to next AS (well-known community)\n"
9977 "community number\n"
9978 "Do not send outside local AS (well-known community)\n"
9979 "Do not advertise to any peer (well-known community)\n"
9980 "Do not export to next AS (well-known community)\n"
9981 "community number\n"
9982 "Do not send outside local AS (well-known community)\n"
9983 "Do not advertise to any peer (well-known community)\n"
9984 "Do not export to next AS (well-known community)\n")
9985
718e3744 9986DEFUN (show_ip_bgp_community_exact,
9987 show_ip_bgp_community_exact_cmd,
9988 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9989 SHOW_STR
9990 IP_STR
9991 BGP_STR
9992 "Display routes matching the communities\n"
9993 "community number\n"
9994 "Do not send outside local AS (well-known community)\n"
9995 "Do not advertise to any peer (well-known community)\n"
9996 "Do not export to next AS (well-known community)\n"
9997 "Exact match of the communities")
9998{
95cbbd2a 9999 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 10000}
10001
10002ALIAS (show_ip_bgp_community_exact,
10003 show_ip_bgp_community2_exact_cmd,
10004 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10005 SHOW_STR
10006 IP_STR
10007 BGP_STR
10008 "Display routes matching the communities\n"
10009 "community number\n"
10010 "Do not send outside local AS (well-known community)\n"
10011 "Do not advertise to any peer (well-known community)\n"
10012 "Do not export to next AS (well-known community)\n"
10013 "community number\n"
10014 "Do not send outside local AS (well-known community)\n"
10015 "Do not advertise to any peer (well-known community)\n"
10016 "Do not export to next AS (well-known community)\n"
10017 "Exact match of the communities")
10018
10019ALIAS (show_ip_bgp_community_exact,
10020 show_ip_bgp_community3_exact_cmd,
10021 "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",
10022 SHOW_STR
10023 IP_STR
10024 BGP_STR
10025 "Display routes matching the communities\n"
10026 "community number\n"
10027 "Do not send outside local AS (well-known community)\n"
10028 "Do not advertise to any peer (well-known community)\n"
10029 "Do not export to next AS (well-known community)\n"
10030 "community number\n"
10031 "Do not send outside local AS (well-known community)\n"
10032 "Do not advertise to any peer (well-known community)\n"
10033 "Do not export to next AS (well-known community)\n"
10034 "community number\n"
10035 "Do not send outside local AS (well-known community)\n"
10036 "Do not advertise to any peer (well-known community)\n"
10037 "Do not export to next AS (well-known community)\n"
10038 "Exact match of the communities")
10039
10040ALIAS (show_ip_bgp_community_exact,
10041 show_ip_bgp_community4_exact_cmd,
10042 "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",
10043 SHOW_STR
10044 IP_STR
10045 BGP_STR
10046 "Display routes matching the communities\n"
10047 "community number\n"
10048 "Do not send outside local AS (well-known community)\n"
10049 "Do not advertise to any peer (well-known community)\n"
10050 "Do not export to next AS (well-known community)\n"
10051 "community number\n"
10052 "Do not send outside local AS (well-known community)\n"
10053 "Do not advertise to any peer (well-known community)\n"
10054 "Do not export to next AS (well-known community)\n"
10055 "community number\n"
10056 "Do not send outside local AS (well-known community)\n"
10057 "Do not advertise to any peer (well-known community)\n"
10058 "Do not export to next AS (well-known community)\n"
10059 "community number\n"
10060 "Do not send outside local AS (well-known community)\n"
10061 "Do not advertise to any peer (well-known community)\n"
10062 "Do not export to next AS (well-known community)\n"
10063 "Exact match of the communities")
10064
10065DEFUN (show_ip_bgp_ipv4_community_exact,
10066 show_ip_bgp_ipv4_community_exact_cmd,
10067 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10068 SHOW_STR
10069 IP_STR
10070 BGP_STR
10071 "Address family\n"
10072 "Address Family modifier\n"
10073 "Address Family modifier\n"
10074 "Display routes matching the communities\n"
10075 "community number\n"
10076 "Do not send outside local AS (well-known community)\n"
10077 "Do not advertise to any peer (well-known community)\n"
10078 "Do not export to next AS (well-known community)\n"
10079 "Exact match of the communities")
10080{
10081 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 10082 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
718e3744 10083
95cbbd2a 10084 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 10085}
10086
10087ALIAS (show_ip_bgp_ipv4_community_exact,
10088 show_ip_bgp_ipv4_community2_exact_cmd,
10089 "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",
10090 SHOW_STR
10091 IP_STR
10092 BGP_STR
10093 "Address family\n"
10094 "Address Family modifier\n"
10095 "Address Family modifier\n"
10096 "Display routes matching the communities\n"
10097 "community number\n"
10098 "Do not send outside local AS (well-known community)\n"
10099 "Do not advertise to any peer (well-known community)\n"
10100 "Do not export to next AS (well-known community)\n"
10101 "community number\n"
10102 "Do not send outside local AS (well-known community)\n"
10103 "Do not advertise to any peer (well-known community)\n"
10104 "Do not export to next AS (well-known community)\n"
10105 "Exact match of the communities")
10106
10107ALIAS (show_ip_bgp_ipv4_community_exact,
10108 show_ip_bgp_ipv4_community3_exact_cmd,
10109 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10110 SHOW_STR
10111 IP_STR
10112 BGP_STR
10113 "Address family\n"
10114 "Address Family modifier\n"
10115 "Address Family modifier\n"
10116 "Display routes matching the communities\n"
10117 "community number\n"
10118 "Do not send outside local AS (well-known community)\n"
10119 "Do not advertise to any peer (well-known community)\n"
10120 "Do not export to next AS (well-known community)\n"
10121 "community number\n"
10122 "Do not send outside local AS (well-known community)\n"
10123 "Do not advertise to any peer (well-known community)\n"
10124 "Do not export to next AS (well-known community)\n"
10125 "community number\n"
10126 "Do not send outside local AS (well-known community)\n"
10127 "Do not advertise to any peer (well-known community)\n"
10128 "Do not export to next AS (well-known community)\n"
10129 "Exact match of the communities")
10130
10131ALIAS (show_ip_bgp_ipv4_community_exact,
10132 show_ip_bgp_ipv4_community4_exact_cmd,
10133 "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",
10134 SHOW_STR
10135 IP_STR
10136 BGP_STR
10137 "Address family\n"
10138 "Address Family modifier\n"
10139 "Address Family modifier\n"
10140 "Display routes matching the communities\n"
10141 "community number\n"
10142 "Do not send outside local AS (well-known community)\n"
10143 "Do not advertise to any peer (well-known community)\n"
10144 "Do not export to next AS (well-known community)\n"
10145 "community number\n"
10146 "Do not send outside local AS (well-known community)\n"
10147 "Do not advertise to any peer (well-known community)\n"
10148 "Do not export to next AS (well-known community)\n"
10149 "community number\n"
10150 "Do not send outside local AS (well-known community)\n"
10151 "Do not advertise to any peer (well-known community)\n"
10152 "Do not export to next AS (well-known community)\n"
10153 "community number\n"
10154 "Do not send outside local AS (well-known community)\n"
10155 "Do not advertise to any peer (well-known community)\n"
10156 "Do not export to next AS (well-known community)\n"
10157 "Exact match of the communities")
10158
10159#ifdef HAVE_IPV6
10160DEFUN (show_bgp_community,
10161 show_bgp_community_cmd,
10162 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
10163 SHOW_STR
10164 BGP_STR
10165 "Display routes matching the communities\n"
10166 "community number\n"
10167 "Do not send outside local AS (well-known community)\n"
10168 "Do not advertise to any peer (well-known community)\n"
10169 "Do not export to next AS (well-known community)\n")
10170{
95cbbd2a 10171 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 10172}
10173
10174ALIAS (show_bgp_community,
10175 show_bgp_ipv6_community_cmd,
10176 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
10177 SHOW_STR
10178 BGP_STR
10179 "Address family\n"
10180 "Display routes matching the communities\n"
10181 "community number\n"
10182 "Do not send outside local AS (well-known community)\n"
10183 "Do not advertise to any peer (well-known community)\n"
10184 "Do not export to next AS (well-known community)\n")
10185
10186ALIAS (show_bgp_community,
10187 show_bgp_community2_cmd,
10188 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10189 SHOW_STR
10190 BGP_STR
10191 "Display routes matching the communities\n"
10192 "community number\n"
10193 "Do not send outside local AS (well-known community)\n"
10194 "Do not advertise to any peer (well-known community)\n"
10195 "Do not export to next AS (well-known community)\n"
10196 "community number\n"
10197 "Do not send outside local AS (well-known community)\n"
10198 "Do not advertise to any peer (well-known community)\n"
10199 "Do not export to next AS (well-known community)\n")
10200
10201ALIAS (show_bgp_community,
10202 show_bgp_ipv6_community2_cmd,
10203 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10204 SHOW_STR
10205 BGP_STR
10206 "Address family\n"
10207 "Display routes matching the communities\n"
10208 "community number\n"
10209 "Do not send outside local AS (well-known community)\n"
10210 "Do not advertise to any peer (well-known community)\n"
10211 "Do not export to next AS (well-known community)\n"
10212 "community number\n"
10213 "Do not send outside local AS (well-known community)\n"
10214 "Do not advertise to any peer (well-known community)\n"
10215 "Do not export to next AS (well-known community)\n")
10216
10217ALIAS (show_bgp_community,
10218 show_bgp_community3_cmd,
10219 "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)",
10220 SHOW_STR
10221 BGP_STR
10222 "Display routes matching the communities\n"
10223 "community number\n"
10224 "Do not send outside local AS (well-known community)\n"
10225 "Do not advertise to any peer (well-known community)\n"
10226 "Do not export to next AS (well-known community)\n"
10227 "community number\n"
10228 "Do not send outside local AS (well-known community)\n"
10229 "Do not advertise to any peer (well-known community)\n"
10230 "Do not export to next AS (well-known community)\n"
10231 "community number\n"
10232 "Do not send outside local AS (well-known community)\n"
10233 "Do not advertise to any peer (well-known community)\n"
10234 "Do not export to next AS (well-known community)\n")
10235
10236ALIAS (show_bgp_community,
10237 show_bgp_ipv6_community3_cmd,
10238 "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)",
10239 SHOW_STR
10240 BGP_STR
10241 "Address family\n"
10242 "Display routes matching the communities\n"
10243 "community number\n"
10244 "Do not send outside local AS (well-known community)\n"
10245 "Do not advertise to any peer (well-known community)\n"
10246 "Do not export to next AS (well-known community)\n"
10247 "community number\n"
10248 "Do not send outside local AS (well-known community)\n"
10249 "Do not advertise to any peer (well-known community)\n"
10250 "Do not export to next AS (well-known community)\n"
10251 "community number\n"
10252 "Do not send outside local AS (well-known community)\n"
10253 "Do not advertise to any peer (well-known community)\n"
10254 "Do not export to next AS (well-known community)\n")
10255
10256ALIAS (show_bgp_community,
10257 show_bgp_community4_cmd,
10258 "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)",
10259 SHOW_STR
10260 BGP_STR
10261 "Display routes matching the communities\n"
10262 "community number\n"
10263 "Do not send outside local AS (well-known community)\n"
10264 "Do not advertise to any peer (well-known community)\n"
10265 "Do not export to next AS (well-known community)\n"
10266 "community number\n"
10267 "Do not send outside local AS (well-known community)\n"
10268 "Do not advertise to any peer (well-known community)\n"
10269 "Do not export to next AS (well-known community)\n"
10270 "community number\n"
10271 "Do not send outside local AS (well-known community)\n"
10272 "Do not advertise to any peer (well-known community)\n"
10273 "Do not export to next AS (well-known community)\n"
10274 "community number\n"
10275 "Do not send outside local AS (well-known community)\n"
10276 "Do not advertise to any peer (well-known community)\n"
10277 "Do not export to next AS (well-known community)\n")
10278
10279ALIAS (show_bgp_community,
10280 show_bgp_ipv6_community4_cmd,
10281 "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)",
10282 SHOW_STR
10283 BGP_STR
10284 "Address family\n"
10285 "Display routes matching the communities\n"
10286 "community number\n"
10287 "Do not send outside local AS (well-known community)\n"
10288 "Do not advertise to any peer (well-known community)\n"
10289 "Do not export to next AS (well-known community)\n"
10290 "community number\n"
10291 "Do not send outside local AS (well-known community)\n"
10292 "Do not advertise to any peer (well-known community)\n"
10293 "Do not export to next AS (well-known community)\n"
10294 "community number\n"
10295 "Do not send outside local AS (well-known community)\n"
10296 "Do not advertise to any peer (well-known community)\n"
10297 "Do not export to next AS (well-known community)\n"
10298 "community number\n"
10299 "Do not send outside local AS (well-known community)\n"
10300 "Do not advertise to any peer (well-known community)\n"
10301 "Do not export to next AS (well-known community)\n")
10302
10303/* old command */
10304DEFUN (show_ipv6_bgp_community,
10305 show_ipv6_bgp_community_cmd,
10306 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
10307 SHOW_STR
10308 IPV6_STR
10309 BGP_STR
10310 "Display routes matching the communities\n"
10311 "community number\n"
10312 "Do not send outside local AS (well-known community)\n"
10313 "Do not advertise to any peer (well-known community)\n"
10314 "Do not export to next AS (well-known community)\n")
10315{
95cbbd2a 10316 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 10317}
10318
10319/* old command */
10320ALIAS (show_ipv6_bgp_community,
10321 show_ipv6_bgp_community2_cmd,
10322 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10323 SHOW_STR
10324 IPV6_STR
10325 BGP_STR
10326 "Display routes matching the communities\n"
10327 "community number\n"
10328 "Do not send outside local AS (well-known community)\n"
10329 "Do not advertise to any peer (well-known community)\n"
10330 "Do not export to next AS (well-known community)\n"
10331 "community number\n"
10332 "Do not send outside local AS (well-known community)\n"
10333 "Do not advertise to any peer (well-known community)\n"
10334 "Do not export to next AS (well-known community)\n")
10335
10336/* old command */
10337ALIAS (show_ipv6_bgp_community,
10338 show_ipv6_bgp_community3_cmd,
10339 "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)",
10340 SHOW_STR
10341 IPV6_STR
10342 BGP_STR
10343 "Display routes matching the communities\n"
10344 "community number\n"
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 number\n"
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 number\n"
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
10357/* old command */
10358ALIAS (show_ipv6_bgp_community,
10359 show_ipv6_bgp_community4_cmd,
10360 "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)",
10361 SHOW_STR
10362 IPV6_STR
10363 BGP_STR
10364 "Display routes matching the communities\n"
10365 "community number\n"
10366 "Do not send outside local AS (well-known community)\n"
10367 "Do not advertise to any peer (well-known community)\n"
10368 "Do not export to next AS (well-known community)\n"
10369 "community number\n"
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 "community number\n"
10374 "Do not send outside local AS (well-known community)\n"
10375 "Do not advertise to any peer (well-known community)\n"
10376 "Do not export to next AS (well-known community)\n"
10377 "community number\n"
10378 "Do not send outside local AS (well-known community)\n"
10379 "Do not advertise to any peer (well-known community)\n"
10380 "Do not export to next AS (well-known community)\n")
10381
10382DEFUN (show_bgp_community_exact,
10383 show_bgp_community_exact_cmd,
10384 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10385 SHOW_STR
10386 BGP_STR
10387 "Display routes matching the communities\n"
10388 "community number\n"
10389 "Do not send outside local AS (well-known community)\n"
10390 "Do not advertise to any peer (well-known community)\n"
10391 "Do not export to next AS (well-known community)\n"
10392 "Exact match of the communities")
10393{
95cbbd2a 10394 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 10395}
10396
10397ALIAS (show_bgp_community_exact,
10398 show_bgp_ipv6_community_exact_cmd,
10399 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10400 SHOW_STR
10401 BGP_STR
10402 "Address family\n"
10403 "Display routes matching the communities\n"
10404 "community number\n"
10405 "Do not send outside local AS (well-known community)\n"
10406 "Do not advertise to any peer (well-known community)\n"
10407 "Do not export to next AS (well-known community)\n"
10408 "Exact match of the communities")
10409
10410ALIAS (show_bgp_community_exact,
10411 show_bgp_community2_exact_cmd,
10412 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10413 SHOW_STR
10414 BGP_STR
10415 "Display routes matching the communities\n"
10416 "community number\n"
10417 "Do not send outside local AS (well-known community)\n"
10418 "Do not advertise to any peer (well-known community)\n"
10419 "Do not export to next AS (well-known community)\n"
10420 "community number\n"
10421 "Do not send outside local AS (well-known community)\n"
10422 "Do not advertise to any peer (well-known community)\n"
10423 "Do not export to next AS (well-known community)\n"
10424 "Exact match of the communities")
10425
10426ALIAS (show_bgp_community_exact,
10427 show_bgp_ipv6_community2_exact_cmd,
10428 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10429 SHOW_STR
10430 BGP_STR
10431 "Address family\n"
10432 "Display routes matching the communities\n"
10433 "community number\n"
10434 "Do not send outside local AS (well-known community)\n"
10435 "Do not advertise to any peer (well-known community)\n"
10436 "Do not export to next AS (well-known community)\n"
10437 "community number\n"
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 "Exact match of the communities")
10442
10443ALIAS (show_bgp_community_exact,
10444 show_bgp_community3_exact_cmd,
10445 "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",
10446 SHOW_STR
10447 BGP_STR
10448 "Display routes matching the communities\n"
10449 "community number\n"
10450 "Do not send outside local AS (well-known community)\n"
10451 "Do not advertise to any peer (well-known community)\n"
10452 "Do not export to next AS (well-known community)\n"
10453 "community number\n"
10454 "Do not send outside local AS (well-known community)\n"
10455 "Do not advertise to any peer (well-known community)\n"
10456 "Do not export to next AS (well-known community)\n"
10457 "community number\n"
10458 "Do not send outside local AS (well-known community)\n"
10459 "Do not advertise to any peer (well-known community)\n"
10460 "Do not export to next AS (well-known community)\n"
10461 "Exact match of the communities")
10462
10463ALIAS (show_bgp_community_exact,
10464 show_bgp_ipv6_community3_exact_cmd,
10465 "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",
10466 SHOW_STR
10467 BGP_STR
10468 "Address family\n"
10469 "Display routes matching the communities\n"
10470 "community number\n"
10471 "Do not send outside local AS (well-known community)\n"
10472 "Do not advertise to any peer (well-known community)\n"
10473 "Do not export to next AS (well-known community)\n"
10474 "community number\n"
10475 "Do not send outside local AS (well-known community)\n"
10476 "Do not advertise to any peer (well-known community)\n"
10477 "Do not export to next AS (well-known community)\n"
10478 "community number\n"
10479 "Do not send outside local AS (well-known community)\n"
10480 "Do not advertise to any peer (well-known community)\n"
10481 "Do not export to next AS (well-known community)\n"
10482 "Exact match of the communities")
10483
10484ALIAS (show_bgp_community_exact,
10485 show_bgp_community4_exact_cmd,
10486 "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",
10487 SHOW_STR
10488 BGP_STR
10489 "Display routes matching the communities\n"
10490 "community number\n"
10491 "Do not send outside local AS (well-known community)\n"
10492 "Do not advertise to any peer (well-known community)\n"
10493 "Do not export to next AS (well-known community)\n"
10494 "community number\n"
10495 "Do not send outside local AS (well-known community)\n"
10496 "Do not advertise to any peer (well-known community)\n"
10497 "Do not export to next AS (well-known community)\n"
10498 "community number\n"
10499 "Do not send outside local AS (well-known community)\n"
10500 "Do not advertise to any peer (well-known community)\n"
10501 "Do not export to next AS (well-known community)\n"
10502 "community number\n"
10503 "Do not send outside local AS (well-known community)\n"
10504 "Do not advertise to any peer (well-known community)\n"
10505 "Do not export to next AS (well-known community)\n"
10506 "Exact match of the communities")
10507
10508ALIAS (show_bgp_community_exact,
10509 show_bgp_ipv6_community4_exact_cmd,
10510 "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",
10511 SHOW_STR
10512 BGP_STR
10513 "Address family\n"
10514 "Display routes matching the communities\n"
10515 "community number\n"
10516 "Do not send outside local AS (well-known community)\n"
10517 "Do not advertise to any peer (well-known community)\n"
10518 "Do not export to next AS (well-known community)\n"
10519 "community number\n"
10520 "Do not send outside local AS (well-known community)\n"
10521 "Do not advertise to any peer (well-known community)\n"
10522 "Do not export to next AS (well-known community)\n"
10523 "community number\n"
10524 "Do not send outside local AS (well-known community)\n"
10525 "Do not advertise to any peer (well-known community)\n"
10526 "Do not export to next AS (well-known community)\n"
10527 "community number\n"
10528 "Do not send outside local AS (well-known community)\n"
10529 "Do not advertise to any peer (well-known community)\n"
10530 "Do not export to next AS (well-known community)\n"
10531 "Exact match of the communities")
10532
10533/* old command */
10534DEFUN (show_ipv6_bgp_community_exact,
10535 show_ipv6_bgp_community_exact_cmd,
10536 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10537 SHOW_STR
10538 IPV6_STR
10539 BGP_STR
10540 "Display routes matching the communities\n"
10541 "community number\n"
10542 "Do not send outside local AS (well-known community)\n"
10543 "Do not advertise to any peer (well-known community)\n"
10544 "Do not export to next AS (well-known community)\n"
10545 "Exact match of the communities")
10546{
95cbbd2a 10547 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 10548}
10549
10550/* old command */
10551ALIAS (show_ipv6_bgp_community_exact,
10552 show_ipv6_bgp_community2_exact_cmd,
10553 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10554 SHOW_STR
10555 IPV6_STR
10556 BGP_STR
10557 "Display routes matching the communities\n"
10558 "community number\n"
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 number\n"
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 "Exact match of the communities")
10567
10568/* old command */
10569ALIAS (show_ipv6_bgp_community_exact,
10570 show_ipv6_bgp_community3_exact_cmd,
10571 "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",
10572 SHOW_STR
10573 IPV6_STR
10574 BGP_STR
10575 "Display routes matching the communities\n"
10576 "community number\n"
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 "community number\n"
10581 "Do not send outside local AS (well-known community)\n"
10582 "Do not advertise to any peer (well-known community)\n"
10583 "Do not export to next AS (well-known community)\n"
10584 "community number\n"
10585 "Do not send outside local AS (well-known community)\n"
10586 "Do not advertise to any peer (well-known community)\n"
10587 "Do not export to next AS (well-known community)\n"
10588 "Exact match of the communities")
10589
10590/* old command */
10591ALIAS (show_ipv6_bgp_community_exact,
10592 show_ipv6_bgp_community4_exact_cmd,
10593 "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",
10594 SHOW_STR
10595 IPV6_STR
10596 BGP_STR
10597 "Display routes matching the communities\n"
10598 "community number\n"
10599 "Do not send outside local AS (well-known community)\n"
10600 "Do not advertise to any peer (well-known community)\n"
10601 "Do not export to next AS (well-known community)\n"
10602 "community number\n"
10603 "Do not send outside local AS (well-known community)\n"
10604 "Do not advertise to any peer (well-known community)\n"
10605 "Do not export to next AS (well-known community)\n"
10606 "community number\n"
10607 "Do not send outside local AS (well-known community)\n"
10608 "Do not advertise to any peer (well-known community)\n"
10609 "Do not export to next AS (well-known community)\n"
10610 "community number\n"
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 "Exact match of the communities")
10615
10616/* old command */
10617DEFUN (show_ipv6_mbgp_community,
10618 show_ipv6_mbgp_community_cmd,
10619 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10620 SHOW_STR
10621 IPV6_STR
10622 MBGP_STR
10623 "Display routes matching the communities\n"
10624 "community number\n"
10625 "Do not send outside local AS (well-known community)\n"
10626 "Do not advertise to any peer (well-known community)\n"
10627 "Do not export to next AS (well-known community)\n")
10628{
95cbbd2a 10629 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
718e3744 10630}
10631
10632/* old command */
10633ALIAS (show_ipv6_mbgp_community,
10634 show_ipv6_mbgp_community2_cmd,
10635 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10636 SHOW_STR
10637 IPV6_STR
10638 MBGP_STR
10639 "Display routes matching the communities\n"
10640 "community number\n"
10641 "Do not send outside local AS (well-known community)\n"
10642 "Do not advertise to any peer (well-known community)\n"
10643 "Do not export to next AS (well-known community)\n"
10644 "community number\n"
10645 "Do not send outside local AS (well-known community)\n"
10646 "Do not advertise to any peer (well-known community)\n"
10647 "Do not export to next AS (well-known community)\n")
10648
10649/* old command */
10650ALIAS (show_ipv6_mbgp_community,
10651 show_ipv6_mbgp_community3_cmd,
10652 "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)",
10653 SHOW_STR
10654 IPV6_STR
10655 MBGP_STR
10656 "Display routes matching the communities\n"
10657 "community number\n"
10658 "Do not send outside local AS (well-known community)\n"
10659 "Do not advertise to any peer (well-known community)\n"
10660 "Do not export to next AS (well-known community)\n"
10661 "community number\n"
10662 "Do not send outside local AS (well-known community)\n"
10663 "Do not advertise to any peer (well-known community)\n"
10664 "Do not export to next AS (well-known community)\n"
10665 "community number\n"
10666 "Do not send outside local AS (well-known community)\n"
10667 "Do not advertise to any peer (well-known community)\n"
10668 "Do not export to next AS (well-known community)\n")
10669
10670/* old command */
10671ALIAS (show_ipv6_mbgp_community,
10672 show_ipv6_mbgp_community4_cmd,
10673 "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)",
10674 SHOW_STR
10675 IPV6_STR
10676 MBGP_STR
10677 "Display routes matching the communities\n"
10678 "community number\n"
10679 "Do not send outside local AS (well-known community)\n"
10680 "Do not advertise to any peer (well-known community)\n"
10681 "Do not export to next AS (well-known community)\n"
10682 "community number\n"
10683 "Do not send outside local AS (well-known community)\n"
10684 "Do not advertise to any peer (well-known community)\n"
10685 "Do not export to next AS (well-known community)\n"
10686 "community number\n"
10687 "Do not send outside local AS (well-known community)\n"
10688 "Do not advertise to any peer (well-known community)\n"
10689 "Do not export to next AS (well-known community)\n"
10690 "community number\n"
10691 "Do not send outside local AS (well-known community)\n"
10692 "Do not advertise to any peer (well-known community)\n"
10693 "Do not export to next AS (well-known community)\n")
10694
10695/* old command */
10696DEFUN (show_ipv6_mbgp_community_exact,
10697 show_ipv6_mbgp_community_exact_cmd,
10698 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10699 SHOW_STR
10700 IPV6_STR
10701 MBGP_STR
10702 "Display routes matching the communities\n"
10703 "community number\n"
10704 "Do not send outside local AS (well-known community)\n"
10705 "Do not advertise to any peer (well-known community)\n"
10706 "Do not export to next AS (well-known community)\n"
10707 "Exact match of the communities")
10708{
95cbbd2a 10709 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
718e3744 10710}
10711
10712/* old command */
10713ALIAS (show_ipv6_mbgp_community_exact,
10714 show_ipv6_mbgp_community2_exact_cmd,
10715 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10716 SHOW_STR
10717 IPV6_STR
10718 MBGP_STR
10719 "Display routes matching the communities\n"
10720 "community number\n"
10721 "Do not send outside local AS (well-known community)\n"
10722 "Do not advertise to any peer (well-known community)\n"
10723 "Do not export to next AS (well-known community)\n"
10724 "community number\n"
10725 "Do not send outside local AS (well-known community)\n"
10726 "Do not advertise to any peer (well-known community)\n"
10727 "Do not export to next AS (well-known community)\n"
10728 "Exact match of the communities")
10729
10730/* old command */
10731ALIAS (show_ipv6_mbgp_community_exact,
10732 show_ipv6_mbgp_community3_exact_cmd,
10733 "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",
10734 SHOW_STR
10735 IPV6_STR
10736 MBGP_STR
10737 "Display routes matching the communities\n"
10738 "community number\n"
10739 "Do not send outside local AS (well-known community)\n"
10740 "Do not advertise to any peer (well-known community)\n"
10741 "Do not export to next AS (well-known community)\n"
10742 "community number\n"
10743 "Do not send outside local AS (well-known community)\n"
10744 "Do not advertise to any peer (well-known community)\n"
10745 "Do not export to next AS (well-known community)\n"
10746 "community number\n"
10747 "Do not send outside local AS (well-known community)\n"
10748 "Do not advertise to any peer (well-known community)\n"
10749 "Do not export to next AS (well-known community)\n"
10750 "Exact match of the communities")
10751
10752/* old command */
10753ALIAS (show_ipv6_mbgp_community_exact,
10754 show_ipv6_mbgp_community4_exact_cmd,
10755 "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",
10756 SHOW_STR
10757 IPV6_STR
10758 MBGP_STR
10759 "Display routes matching the communities\n"
10760 "community number\n"
10761 "Do not send outside local AS (well-known community)\n"
10762 "Do not advertise to any peer (well-known community)\n"
10763 "Do not export to next AS (well-known community)\n"
10764 "community number\n"
10765 "Do not send outside local AS (well-known community)\n"
10766 "Do not advertise to any peer (well-known community)\n"
10767 "Do not export to next AS (well-known community)\n"
10768 "community number\n"
10769 "Do not send outside local AS (well-known community)\n"
10770 "Do not advertise to any peer (well-known community)\n"
10771 "Do not export to next AS (well-known community)\n"
10772 "community number\n"
10773 "Do not send outside local AS (well-known community)\n"
10774 "Do not advertise to any peer (well-known community)\n"
10775 "Do not export to next AS (well-known community)\n"
10776 "Exact match of the communities")
10777#endif /* HAVE_IPV6 */
6b0655a2 10778
94f2b392 10779static int
fd79ac91 10780bgp_show_community_list (struct vty *vty, const char *com, int exact,
4c9641ba 10781 afi_t afi, safi_t safi)
718e3744 10782{
10783 struct community_list *list;
10784
fee6e4e4 10785 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
718e3744 10786 if (list == NULL)
10787 {
10788 vty_out (vty, "%% %s is not a valid community-list name%s", com,
10789 VTY_NEWLINE);
10790 return CMD_WARNING;
10791 }
10792
5a646650 10793 return bgp_show (vty, NULL, afi, safi,
10794 (exact ? bgp_show_type_community_list_exact :
b05a1c8b 10795 bgp_show_type_community_list), list, 0);
718e3744 10796}
10797
10798DEFUN (show_ip_bgp_community_list,
10799 show_ip_bgp_community_list_cmd,
fee6e4e4 10800 "show ip bgp community-list (<1-500>|WORD)",
718e3744 10801 SHOW_STR
10802 IP_STR
10803 BGP_STR
10804 "Display routes matching the community-list\n"
fee6e4e4 10805 "community-list number\n"
718e3744 10806 "community-list name\n")
10807{
10808 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
10809}
10810
10811DEFUN (show_ip_bgp_ipv4_community_list,
10812 show_ip_bgp_ipv4_community_list_cmd,
fee6e4e4 10813 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
718e3744 10814 SHOW_STR
10815 IP_STR
10816 BGP_STR
10817 "Address family\n"
10818 "Address Family modifier\n"
10819 "Address Family modifier\n"
10820 "Display routes matching the community-list\n"
fee6e4e4 10821 "community-list number\n"
718e3744 10822 "community-list name\n")
10823{
10824 if (strncmp (argv[0], "m", 1) == 0)
10825 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
10826
10827 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
10828}
10829
10830DEFUN (show_ip_bgp_community_list_exact,
10831 show_ip_bgp_community_list_exact_cmd,
fee6e4e4 10832 "show ip bgp community-list (<1-500>|WORD) exact-match",
718e3744 10833 SHOW_STR
10834 IP_STR
10835 BGP_STR
10836 "Display routes matching the community-list\n"
fee6e4e4 10837 "community-list number\n"
718e3744 10838 "community-list name\n"
10839 "Exact match of the communities\n")
10840{
10841 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
10842}
10843
10844DEFUN (show_ip_bgp_ipv4_community_list_exact,
10845 show_ip_bgp_ipv4_community_list_exact_cmd,
fee6e4e4 10846 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
718e3744 10847 SHOW_STR
10848 IP_STR
10849 BGP_STR
10850 "Address family\n"
10851 "Address Family modifier\n"
10852 "Address Family modifier\n"
10853 "Display routes matching the community-list\n"
fee6e4e4 10854 "community-list number\n"
718e3744 10855 "community-list name\n"
10856 "Exact match of the communities\n")
10857{
10858 if (strncmp (argv[0], "m", 1) == 0)
10859 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
10860
10861 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
10862}
10863
10864#ifdef HAVE_IPV6
10865DEFUN (show_bgp_community_list,
10866 show_bgp_community_list_cmd,
fee6e4e4 10867 "show bgp community-list (<1-500>|WORD)",
718e3744 10868 SHOW_STR
10869 BGP_STR
10870 "Display routes matching the community-list\n"
fee6e4e4 10871 "community-list number\n"
718e3744 10872 "community-list name\n")
10873{
10874 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10875}
10876
10877ALIAS (show_bgp_community_list,
10878 show_bgp_ipv6_community_list_cmd,
fee6e4e4 10879 "show bgp ipv6 community-list (<1-500>|WORD)",
718e3744 10880 SHOW_STR
10881 BGP_STR
10882 "Address family\n"
10883 "Display routes matching the community-list\n"
fee6e4e4 10884 "community-list number\n"
e8e1946e 10885 "community-list name\n")
718e3744 10886
10887/* old command */
10888DEFUN (show_ipv6_bgp_community_list,
10889 show_ipv6_bgp_community_list_cmd,
10890 "show ipv6 bgp community-list WORD",
10891 SHOW_STR
10892 IPV6_STR
10893 BGP_STR
10894 "Display routes matching the community-list\n"
10895 "community-list name\n")
10896{
10897 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10898}
10899
10900/* old command */
10901DEFUN (show_ipv6_mbgp_community_list,
10902 show_ipv6_mbgp_community_list_cmd,
10903 "show ipv6 mbgp community-list WORD",
10904 SHOW_STR
10905 IPV6_STR
10906 MBGP_STR
10907 "Display routes matching the community-list\n"
10908 "community-list name\n")
10909{
10910 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
10911}
10912
10913DEFUN (show_bgp_community_list_exact,
10914 show_bgp_community_list_exact_cmd,
fee6e4e4 10915 "show bgp community-list (<1-500>|WORD) exact-match",
718e3744 10916 SHOW_STR
10917 BGP_STR
10918 "Display routes matching the community-list\n"
fee6e4e4 10919 "community-list number\n"
718e3744 10920 "community-list name\n"
10921 "Exact match of the communities\n")
10922{
10923 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10924}
10925
10926ALIAS (show_bgp_community_list_exact,
10927 show_bgp_ipv6_community_list_exact_cmd,
fee6e4e4 10928 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
718e3744 10929 SHOW_STR
10930 BGP_STR
10931 "Address family\n"
10932 "Display routes matching the community-list\n"
fee6e4e4 10933 "community-list number\n"
718e3744 10934 "community-list name\n"
10935 "Exact match of the communities\n")
10936
10937/* old command */
10938DEFUN (show_ipv6_bgp_community_list_exact,
10939 show_ipv6_bgp_community_list_exact_cmd,
10940 "show ipv6 bgp community-list WORD exact-match",
10941 SHOW_STR
10942 IPV6_STR
10943 BGP_STR
10944 "Display routes matching the community-list\n"
10945 "community-list name\n"
10946 "Exact match of the communities\n")
10947{
10948 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10949}
10950
10951/* old command */
10952DEFUN (show_ipv6_mbgp_community_list_exact,
10953 show_ipv6_mbgp_community_list_exact_cmd,
10954 "show ipv6 mbgp community-list WORD exact-match",
10955 SHOW_STR
10956 IPV6_STR
10957 MBGP_STR
10958 "Display routes matching the community-list\n"
10959 "community-list name\n"
10960 "Exact match of the communities\n")
10961{
10962 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
10963}
10964#endif /* HAVE_IPV6 */
6b0655a2 10965
94f2b392 10966static int
fd79ac91 10967bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
718e3744 10968 safi_t safi, enum bgp_show_type type)
10969{
10970 int ret;
10971 struct prefix *p;
10972
10973 p = prefix_new();
10974
10975 ret = str2prefix (prefix, p);
10976 if (! ret)
10977 {
10978 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
10979 return CMD_WARNING;
10980 }
10981
b05a1c8b 10982 ret = bgp_show (vty, NULL, afi, safi, type, p, 0);
5a646650 10983 prefix_free(p);
10984 return ret;
718e3744 10985}
10986
10987DEFUN (show_ip_bgp_prefix_longer,
10988 show_ip_bgp_prefix_longer_cmd,
10989 "show ip bgp A.B.C.D/M longer-prefixes",
10990 SHOW_STR
10991 IP_STR
10992 BGP_STR
10993 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10994 "Display route and more specific routes\n")
10995{
10996 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
10997 bgp_show_type_prefix_longer);
10998}
10999
11000DEFUN (show_ip_bgp_flap_prefix_longer,
11001 show_ip_bgp_flap_prefix_longer_cmd,
11002 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11003 SHOW_STR
11004 IP_STR
11005 BGP_STR
11006 "Display flap statistics of routes\n"
11007 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11008 "Display route and more specific routes\n")
11009{
11010 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11011 bgp_show_type_flap_prefix_longer);
11012}
11013
11014DEFUN (show_ip_bgp_ipv4_prefix_longer,
11015 show_ip_bgp_ipv4_prefix_longer_cmd,
11016 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11017 SHOW_STR
11018 IP_STR
11019 BGP_STR
11020 "Address family\n"
11021 "Address Family modifier\n"
11022 "Address Family modifier\n"
11023 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11024 "Display route and more specific routes\n")
11025{
11026 if (strncmp (argv[0], "m", 1) == 0)
11027 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
11028 bgp_show_type_prefix_longer);
11029
11030 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
11031 bgp_show_type_prefix_longer);
11032}
11033
11034DEFUN (show_ip_bgp_flap_address,
11035 show_ip_bgp_flap_address_cmd,
11036 "show ip bgp flap-statistics A.B.C.D",
11037 SHOW_STR
11038 IP_STR
11039 BGP_STR
11040 "Display flap statistics of routes\n"
11041 "Network in the BGP routing table to display\n")
11042{
11043 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11044 bgp_show_type_flap_address);
11045}
11046
11047DEFUN (show_ip_bgp_flap_prefix,
11048 show_ip_bgp_flap_prefix_cmd,
11049 "show ip bgp flap-statistics A.B.C.D/M",
11050 SHOW_STR
11051 IP_STR
11052 BGP_STR
11053 "Display flap statistics of routes\n"
11054 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11055{
11056 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11057 bgp_show_type_flap_prefix);
11058}
11059#ifdef HAVE_IPV6
11060DEFUN (show_bgp_prefix_longer,
11061 show_bgp_prefix_longer_cmd,
11062 "show bgp X:X::X:X/M longer-prefixes",
11063 SHOW_STR
11064 BGP_STR
11065 "IPv6 prefix <network>/<length>\n"
11066 "Display route and more specific routes\n")
11067{
11068 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11069 bgp_show_type_prefix_longer);
11070}
11071
11072ALIAS (show_bgp_prefix_longer,
11073 show_bgp_ipv6_prefix_longer_cmd,
11074 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11075 SHOW_STR
11076 BGP_STR
11077 "Address family\n"
11078 "IPv6 prefix <network>/<length>\n"
11079 "Display route and more specific routes\n")
11080
11081/* old command */
11082DEFUN (show_ipv6_bgp_prefix_longer,
11083 show_ipv6_bgp_prefix_longer_cmd,
11084 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11085 SHOW_STR
11086 IPV6_STR
11087 BGP_STR
11088 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11089 "Display route and more specific routes\n")
11090{
11091 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11092 bgp_show_type_prefix_longer);
11093}
11094
11095/* old command */
11096DEFUN (show_ipv6_mbgp_prefix_longer,
11097 show_ipv6_mbgp_prefix_longer_cmd,
11098 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11099 SHOW_STR
11100 IPV6_STR
11101 MBGP_STR
11102 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11103 "Display route and more specific routes\n")
11104{
11105 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
11106 bgp_show_type_prefix_longer);
11107}
11108#endif /* HAVE_IPV6 */
bb46e94f 11109
94f2b392 11110static struct peer *
fd79ac91 11111peer_lookup_in_view (struct vty *vty, const char *view_name,
11112 const char *ip_str)
bb46e94f 11113{
11114 int ret;
11115 struct bgp *bgp;
11116 struct peer *peer;
11117 union sockunion su;
11118
11119 /* BGP structure lookup. */
11120 if (view_name)
11121 {
11122 bgp = bgp_lookup_by_name (view_name);
11123 if (! bgp)
11124 {
11125 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11126 return NULL;
11127 }
11128 }
5228ad27 11129 else
bb46e94f 11130 {
11131 bgp = bgp_get_default ();
11132 if (! bgp)
11133 {
11134 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11135 return NULL;
11136 }
11137 }
11138
11139 /* Get peer sockunion. */
11140 ret = str2sockunion (ip_str, &su);
11141 if (ret < 0)
11142 {
a80beece
DS
11143 peer = peer_lookup_by_conf_if (bgp, ip_str);
11144 if (!peer)
11145 {
11146 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
11147 return NULL;
11148 }
11149 return peer;
bb46e94f 11150 }
11151
11152 /* Peer structure lookup. */
11153 peer = peer_lookup (bgp, &su);
11154 if (! peer)
11155 {
11156 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11157 return NULL;
11158 }
11159
11160 return peer;
11161}
6b0655a2 11162
2815e61f
PJ
11163enum bgp_stats
11164{
11165 BGP_STATS_MAXBITLEN = 0,
11166 BGP_STATS_RIB,
11167 BGP_STATS_PREFIXES,
11168 BGP_STATS_TOTPLEN,
11169 BGP_STATS_UNAGGREGATEABLE,
11170 BGP_STATS_MAX_AGGREGATEABLE,
11171 BGP_STATS_AGGREGATES,
11172 BGP_STATS_SPACE,
11173 BGP_STATS_ASPATH_COUNT,
11174 BGP_STATS_ASPATH_MAXHOPS,
11175 BGP_STATS_ASPATH_TOTHOPS,
11176 BGP_STATS_ASPATH_MAXSIZE,
11177 BGP_STATS_ASPATH_TOTSIZE,
11178 BGP_STATS_ASN_HIGHEST,
11179 BGP_STATS_MAX,
11180};
11181
11182static const char *table_stats_strs[] =
11183{
11184 [BGP_STATS_PREFIXES] = "Total Prefixes",
11185 [BGP_STATS_TOTPLEN] = "Average prefix length",
11186 [BGP_STATS_RIB] = "Total Advertisements",
11187 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11188 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11189 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11190 [BGP_STATS_SPACE] = "Address space advertised",
11191 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11192 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11193 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11194 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11195 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11196 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11197 [BGP_STATS_MAX] = NULL,
11198};
11199
11200struct bgp_table_stats
11201{
11202 struct bgp_table *table;
11203 unsigned long long counts[BGP_STATS_MAX];
11204};
11205
11206#if 0
11207#define TALLY_SIGFIG 100000
11208static unsigned long
11209ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11210{
11211 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11212 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11213 unsigned long ret = newtot / count;
11214
11215 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11216 return ret + 1;
11217 else
11218 return ret;
11219}
11220#endif
11221
11222static int
11223bgp_table_stats_walker (struct thread *t)
11224{
11225 struct bgp_node *rn;
11226 struct bgp_node *top;
11227 struct bgp_table_stats *ts = THREAD_ARG (t);
11228 unsigned int space = 0;
11229
53d9f67a
PJ
11230 if (!(top = bgp_table_top (ts->table)))
11231 return 0;
2815e61f
PJ
11232
11233 switch (top->p.family)
11234 {
11235 case AF_INET:
11236 space = IPV4_MAX_BITLEN;
11237 break;
11238 case AF_INET6:
11239 space = IPV6_MAX_BITLEN;
11240 break;
11241 }
11242
11243 ts->counts[BGP_STATS_MAXBITLEN] = space;
11244
11245 for (rn = top; rn; rn = bgp_route_next (rn))
11246 {
11247 struct bgp_info *ri;
67174041 11248 struct bgp_node *prn = bgp_node_parent_nolock (rn);
2815e61f
PJ
11249 unsigned int rinum = 0;
11250
11251 if (rn == top)
11252 continue;
11253
11254 if (!rn->info)
11255 continue;
11256
11257 ts->counts[BGP_STATS_PREFIXES]++;
11258 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11259
11260#if 0
11261 ts->counts[BGP_STATS_AVGPLEN]
11262 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11263 ts->counts[BGP_STATS_AVGPLEN],
11264 rn->p.prefixlen);
11265#endif
11266
11267 /* check if the prefix is included by any other announcements */
11268 while (prn && !prn->info)
67174041 11269 prn = bgp_node_parent_nolock (prn);
2815e61f
PJ
11270
11271 if (prn == NULL || prn == top)
8383a9bd
PJ
11272 {
11273 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11274 /* announced address space */
11275 if (space)
11276 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11277 }
2815e61f
PJ
11278 else if (prn->info)
11279 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11280
2815e61f
PJ
11281 for (ri = rn->info; ri; ri = ri->next)
11282 {
11283 rinum++;
11284 ts->counts[BGP_STATS_RIB]++;
11285
11286 if (ri->attr &&
11287 (CHECK_FLAG (ri->attr->flag,
11288 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11289 ts->counts[BGP_STATS_AGGREGATES]++;
11290
11291 /* as-path stats */
11292 if (ri->attr && ri->attr->aspath)
11293 {
11294 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11295 unsigned int size = aspath_size (ri->attr->aspath);
11296 as_t highest = aspath_highest (ri->attr->aspath);
11297
11298 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11299
11300 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11301 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11302
11303 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11304 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11305
11306 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11307 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11308#if 0
11309 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11310 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11311 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11312 hops);
11313 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11314 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11315 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11316 size);
11317#endif
11318 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11319 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11320 }
11321 }
11322 }
11323 return 0;
11324}
11325
11326static int
11327bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11328{
11329 struct bgp_table_stats ts;
11330 unsigned int i;
11331
11332 if (!bgp->rib[afi][safi])
11333 {
11334 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
11335 return CMD_WARNING;
11336 }
11337
11338 memset (&ts, 0, sizeof (ts));
11339 ts.table = bgp->rib[afi][safi];
11340 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
bb46e94f 11341
2815e61f
PJ
11342 vty_out (vty, "BGP %s RIB statistics%s%s",
11343 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11344
11345 for (i = 0; i < BGP_STATS_MAX; i++)
11346 {
11347 if (!table_stats_strs[i])
11348 continue;
11349
11350 switch (i)
11351 {
11352#if 0
11353 case BGP_STATS_ASPATH_AVGHOPS:
11354 case BGP_STATS_ASPATH_AVGSIZE:
11355 case BGP_STATS_AVGPLEN:
11356 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11357 vty_out (vty, "%12.2f",
11358 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11359 break;
11360#endif
11361 case BGP_STATS_ASPATH_TOTHOPS:
11362 case BGP_STATS_ASPATH_TOTSIZE:
11363 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11364 vty_out (vty, "%12.2f",
11365 ts.counts[i] ?
11366 (float)ts.counts[i] /
11367 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11368 : 0);
11369 break;
11370 case BGP_STATS_TOTPLEN:
11371 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11372 vty_out (vty, "%12.2f",
11373 ts.counts[i] ?
11374 (float)ts.counts[i] /
11375 (float)ts.counts[BGP_STATS_PREFIXES]
11376 : 0);
11377 break;
11378 case BGP_STATS_SPACE:
11379 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11380 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11381 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11382 break;
30a2231a 11383 vty_out (vty, "%30s: ", "%% announced ");
2815e61f
PJ
11384 vty_out (vty, "%12.2f%s",
11385 100 * (float)ts.counts[BGP_STATS_SPACE] /
56395af7 11386 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
2815e61f
PJ
11387 VTY_NEWLINE);
11388 vty_out (vty, "%30s: ", "/8 equivalent ");
11389 vty_out (vty, "%12.2f%s",
11390 (float)ts.counts[BGP_STATS_SPACE] /
11391 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11392 VTY_NEWLINE);
11393 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11394 break;
11395 vty_out (vty, "%30s: ", "/24 equivalent ");
11396 vty_out (vty, "%12.2f",
11397 (float)ts.counts[BGP_STATS_SPACE] /
11398 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11399 break;
11400 default:
11401 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11402 vty_out (vty, "%12llu", ts.counts[i]);
11403 }
11404
11405 vty_out (vty, "%s", VTY_NEWLINE);
11406 }
11407 return CMD_SUCCESS;
11408}
11409
11410static int
11411bgp_table_stats_vty (struct vty *vty, const char *name,
11412 const char *afi_str, const char *safi_str)
11413{
11414 struct bgp *bgp;
11415 afi_t afi;
11416 safi_t safi;
11417
11418 if (name)
11419 bgp = bgp_lookup_by_name (name);
11420 else
11421 bgp = bgp_get_default ();
11422
11423 if (!bgp)
11424 {
11425 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
11426 return CMD_WARNING;
11427 }
11428 if (strncmp (afi_str, "ipv", 3) == 0)
11429 {
11430 if (strncmp (afi_str, "ipv4", 4) == 0)
11431 afi = AFI_IP;
11432 else if (strncmp (afi_str, "ipv6", 4) == 0)
11433 afi = AFI_IP6;
11434 else
11435 {
11436 vty_out (vty, "%% Invalid address family %s%s",
11437 afi_str, VTY_NEWLINE);
11438 return CMD_WARNING;
11439 }
11440 if (strncmp (safi_str, "m", 1) == 0)
11441 safi = SAFI_MULTICAST;
11442 else if (strncmp (safi_str, "u", 1) == 0)
11443 safi = SAFI_UNICAST;
42e6d745
DO
11444 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
11445 safi = SAFI_MPLS_LABELED_VPN;
2815e61f
PJ
11446 else
11447 {
11448 vty_out (vty, "%% Invalid subsequent address family %s%s",
11449 safi_str, VTY_NEWLINE);
11450 return CMD_WARNING;
11451 }
11452 }
11453 else
11454 {
11455 vty_out (vty, "%% Invalid address family %s%s",
11456 afi_str, VTY_NEWLINE);
11457 return CMD_WARNING;
11458 }
11459
2815e61f
PJ
11460 return bgp_table_stats (vty, bgp, afi, safi);
11461}
11462
11463DEFUN (show_bgp_statistics,
11464 show_bgp_statistics_cmd,
11465 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
11466 SHOW_STR
11467 BGP_STR
11468 "Address family\n"
11469 "Address family\n"
11470 "Address Family modifier\n"
11471 "Address Family modifier\n"
11472 "BGP RIB advertisement statistics\n")
11473{
11474 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11475}
11476
11477ALIAS (show_bgp_statistics,
11478 show_bgp_statistics_vpnv4_cmd,
11479 "show bgp (ipv4) (vpnv4) statistics",
11480 SHOW_STR
11481 BGP_STR
11482 "Address family\n"
11483 "Address Family modifier\n"
11484 "BGP RIB advertisement statistics\n")
11485
11486DEFUN (show_bgp_statistics_view,
11487 show_bgp_statistics_view_cmd,
11488 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
11489 SHOW_STR
11490 BGP_STR
11491 "BGP view\n"
11492 "Address family\n"
11493 "Address family\n"
11494 "Address Family modifier\n"
11495 "Address Family modifier\n"
11496 "BGP RIB advertisement statistics\n")
11497{
11498 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11499}
11500
11501ALIAS (show_bgp_statistics_view,
11502 show_bgp_statistics_view_vpnv4_cmd,
11503 "show bgp view WORD (ipv4) (vpnv4) statistics",
11504 SHOW_STR
11505 BGP_STR
11506 "BGP view\n"
11507 "Address family\n"
11508 "Address Family modifier\n"
11509 "BGP RIB advertisement statistics\n")
6b0655a2 11510
ff7924f6
PJ
11511enum bgp_pcounts
11512{
11513 PCOUNT_ADJ_IN = 0,
11514 PCOUNT_DAMPED,
11515 PCOUNT_REMOVED,
11516 PCOUNT_HISTORY,
11517 PCOUNT_STALE,
11518 PCOUNT_VALID,
11519 PCOUNT_ALL,
11520 PCOUNT_COUNTED,
11521 PCOUNT_PFCNT, /* the figure we display to users */
11522 PCOUNT_MAX,
11523};
11524
11525static const char *pcount_strs[] =
11526{
11527 [PCOUNT_ADJ_IN] = "Adj-in",
11528 [PCOUNT_DAMPED] = "Damped",
11529 [PCOUNT_REMOVED] = "Removed",
11530 [PCOUNT_HISTORY] = "History",
11531 [PCOUNT_STALE] = "Stale",
11532 [PCOUNT_VALID] = "Valid",
11533 [PCOUNT_ALL] = "All RIB",
11534 [PCOUNT_COUNTED] = "PfxCt counted",
11535 [PCOUNT_PFCNT] = "Useable",
11536 [PCOUNT_MAX] = NULL,
11537};
11538
2815e61f
PJ
11539struct peer_pcounts
11540{
11541 unsigned int count[PCOUNT_MAX];
11542 const struct peer *peer;
11543 const struct bgp_table *table;
11544};
11545
ff7924f6 11546static int
2815e61f 11547bgp_peer_count_walker (struct thread *t)
ff7924f6
PJ
11548{
11549 struct bgp_node *rn;
2815e61f
PJ
11550 struct peer_pcounts *pc = THREAD_ARG (t);
11551 const struct peer *peer = pc->peer;
ff7924f6 11552
2815e61f 11553 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
ff7924f6
PJ
11554 {
11555 struct bgp_adj_in *ain;
2815e61f 11556 struct bgp_info *ri;
ff7924f6
PJ
11557
11558 for (ain = rn->adj_in; ain; ain = ain->next)
11559 if (ain->peer == peer)
2815e61f 11560 pc->count[PCOUNT_ADJ_IN]++;
ff7924f6 11561
ff7924f6
PJ
11562 for (ri = rn->info; ri; ri = ri->next)
11563 {
11564 char buf[SU_ADDRSTRLEN];
11565
11566 if (ri->peer != peer)
11567 continue;
11568
2815e61f 11569 pc->count[PCOUNT_ALL]++;
ff7924f6
PJ
11570
11571 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
2815e61f 11572 pc->count[PCOUNT_DAMPED]++;
ff7924f6 11573 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2815e61f 11574 pc->count[PCOUNT_HISTORY]++;
ff7924f6 11575 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
2815e61f 11576 pc->count[PCOUNT_REMOVED]++;
ff7924f6 11577 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2815e61f 11578 pc->count[PCOUNT_STALE]++;
ff7924f6 11579 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
2815e61f 11580 pc->count[PCOUNT_VALID]++;
1a392d46 11581 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2815e61f 11582 pc->count[PCOUNT_PFCNT]++;
ff7924f6
PJ
11583
11584 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
11585 {
2815e61f 11586 pc->count[PCOUNT_COUNTED]++;
1a392d46 11587 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 11588 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
ff7924f6
PJ
11589 peer->host,
11590 inet_ntop(rn->p.family, &rn->p.u.prefix,
11591 buf, SU_ADDRSTRLEN),
11592 rn->p.prefixlen,
11593 ri->flags);
11594 }
11595 else
11596 {
1a392d46 11597 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 11598 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
ff7924f6
PJ
11599 peer->host,
11600 inet_ntop(rn->p.family, &rn->p.u.prefix,
11601 buf, SU_ADDRSTRLEN),
11602 rn->p.prefixlen,
11603 ri->flags);
11604 }
11605 }
11606 }
2815e61f
PJ
11607 return 0;
11608}
ff7924f6 11609
2815e61f
PJ
11610static int
11611bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
11612{
11613 struct peer_pcounts pcounts = { .peer = peer };
11614 unsigned int i;
11615
11616 if (!peer || !peer->bgp || !peer->afc[afi][safi]
11617 || !peer->bgp->rib[afi][safi])
11618 {
11619 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11620 return CMD_WARNING;
11621 }
11622
11623 memset (&pcounts, 0, sizeof(pcounts));
11624 pcounts.peer = peer;
11625 pcounts.table = peer->bgp->rib[afi][safi];
11626
11627 /* in-place call via thread subsystem so as to record execution time
11628 * stats for the thread-walk (i.e. ensure this can't be blamed on
11629 * on just vty_read()).
11630 */
11631 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
11632
ff7924f6
PJ
11633 vty_out (vty, "Prefix counts for %s, %s%s",
11634 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
11635 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
11636 vty_out (vty, "%sCounts from RIB table walk:%s%s",
11637 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
11638
11639 for (i = 0; i < PCOUNT_MAX; i++)
2815e61f
PJ
11640 vty_out (vty, "%20s: %-10d%s",
11641 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
ff7924f6 11642
2815e61f 11643 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
ff7924f6
PJ
11644 {
11645 vty_out (vty, "%s [pcount] PfxCt drift!%s",
11646 peer->host, VTY_NEWLINE);
11647 vty_out (vty, "Please report this bug, with the above command output%s",
11648 VTY_NEWLINE);
11649 }
11650
11651 return CMD_SUCCESS;
11652}
11653
11654DEFUN (show_ip_bgp_neighbor_prefix_counts,
11655 show_ip_bgp_neighbor_prefix_counts_cmd,
a80beece 11656 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
ff7924f6
PJ
11657 SHOW_STR
11658 IP_STR
11659 BGP_STR
11660 "Detailed information on TCP and BGP neighbor connections\n"
11661 "Neighbor to display information about\n"
11662 "Neighbor to display information about\n"
a80beece 11663 "Neighbor on bgp configured interface\n"
ff7924f6
PJ
11664 "Display detailed prefix count information\n")
11665{
11666 struct peer *peer;
11667
11668 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11669 if (! peer)
11670 return CMD_WARNING;
11671
11672 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
11673}
11674
11675DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
11676 show_bgp_ipv6_neighbor_prefix_counts_cmd,
a80beece 11677 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
ff7924f6
PJ
11678 SHOW_STR
11679 BGP_STR
11680 "Address family\n"
11681 "Detailed information on TCP and BGP neighbor connections\n"
11682 "Neighbor to display information about\n"
11683 "Neighbor to display information about\n"
a80beece 11684 "Neighbor on bgp configured interface\n"
ff7924f6
PJ
11685 "Display detailed prefix count information\n")
11686{
11687 struct peer *peer;
11688
11689 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11690 if (! peer)
11691 return CMD_WARNING;
11692
11693 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
11694}
11695
11696DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
11697 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
a80beece 11698 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
ff7924f6
PJ
11699 SHOW_STR
11700 IP_STR
11701 BGP_STR
11702 "Address family\n"
11703 "Address Family modifier\n"
11704 "Address Family modifier\n"
11705 "Detailed information on TCP and BGP neighbor connections\n"
11706 "Neighbor to display information about\n"
11707 "Neighbor to display information about\n"
a80beece 11708 "Neighbor on bgp configured interface\n"
ff7924f6
PJ
11709 "Display detailed prefix count information\n")
11710{
11711 struct peer *peer;
11712
11713 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11714 if (! peer)
11715 return CMD_WARNING;
11716
11717 if (strncmp (argv[0], "m", 1) == 0)
11718 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
11719
11720 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
11721}
11722
11723DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
11724 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
a80beece 11725 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
ff7924f6
PJ
11726 SHOW_STR
11727 IP_STR
11728 BGP_STR
11729 "Address family\n"
11730 "Address Family modifier\n"
11731 "Address Family modifier\n"
11732 "Detailed information on TCP and BGP neighbor connections\n"
11733 "Neighbor to display information about\n"
11734 "Neighbor to display information about\n"
a80beece 11735 "Neighbor on bgp configured interface\n"
ff7924f6
PJ
11736 "Display detailed prefix count information\n")
11737{
11738 struct peer *peer;
11739
11740 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11741 if (! peer)
11742 return CMD_WARNING;
11743
11744 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
11745}
11746
94f2b392 11747static void
718e3744 11748show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
b05a1c8b 11749 int in, char *rmap_name)
718e3744 11750{
11751 struct bgp_table *table;
11752 struct bgp_adj_in *ain;
11753 struct bgp_adj_out *adj;
11754 unsigned long output_count;
0b16f239 11755 unsigned long filtered_count;
718e3744 11756 struct bgp_node *rn;
11757 int header1 = 1;
11758 struct bgp *bgp;
11759 int header2 = 1;
0b16f239
DS
11760 struct attr attr;
11761 struct attr_extra extra;
11762 int ret;
718e3744 11763
bb46e94f 11764 bgp = peer->bgp;
718e3744 11765
11766 if (! bgp)
11767 return;
11768
11769 table = bgp->rib[afi][safi];
11770
0b16f239 11771 output_count = filtered_count = 0;
47fc97cc 11772
718e3744 11773 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
11774 PEER_STATUS_DEFAULT_ORIGINATE))
11775 {
3f9c7369 11776 vty_out (vty, "BGP table version is %llu, local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
93406d87 11777 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11778 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 11779
11780 vty_out (vty, "Originating default network 0.0.0.0%s%s",
11781 VTY_NEWLINE, VTY_NEWLINE);
11782 header1 = 0;
11783 }
11784
0b16f239 11785 attr.extra = &extra;
718e3744 11786 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11787 if (in)
11788 {
11789 for (ain = rn->adj_in; ain; ain = ain->next)
11790 if (ain->peer == peer)
11791 {
11792 if (header1)
11793 {
11794 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
93406d87 11795 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11796 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 11797 header1 = 0;
11798 }
11799 if (header2)
11800 {
b05a1c8b 11801 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
718e3744 11802 header2 = 0;
11803 }
11804 if (ain->attr)
47fc97cc 11805 {
0b16f239
DS
11806 bgp_attr_dup(&attr, ain->attr);
11807 if (bgp_input_modifier(peer, &rn->p, &attr, afi,
11808 safi, rmap_name) != RMAP_DENY)
11809 {
b05a1c8b 11810 route_vty_out_tmp (vty, &rn->p, &attr, safi);
0b16f239
DS
11811 output_count++;
11812 }
11813 else
11814 filtered_count++;
718e3744 11815 }
11816 }
11817 }
11818 else
11819 {
3f9c7369
DS
11820 adj = bgp_adj_peer_lookup(peer, rn);
11821 if (adj)
11822 {
11823 if (header1)
11824 {
11825 vty_out (vty, "BGP table version is %llu, local router ID "
11826 "is %s%s", table->version,
11827 inet_ntoa (bgp->router_id), VTY_NEWLINE);
11828 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11829 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11830 header1 = 0;
11831 }
11832 if (header2)
11833 {
b05a1c8b 11834 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
3f9c7369
DS
11835 header2 = 0;
11836 }
11837 if (adj->attr)
11838 {
11839 if (!CHECK_FLAG(peer->af_flags[afi][safi],
11840 PEER_FLAG_REFLECTOR_CLIENT)
11841 || bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
11842 {
11843 bgp_attr_dup(&attr, adj->attr);
11844 ret = bgp_output_modifier(peer, &rn->p, &attr, afi,
11845 safi, rmap_name);
11846 }
11847 else
11848 ret = RMAP_PERMIT;
0b16f239 11849
3f9c7369
DS
11850 if (ret != RMAP_DENY)
11851 {
b05a1c8b 11852 route_vty_out_tmp (vty, &rn->p, &attr, safi);
3f9c7369
DS
11853 output_count++;
11854 }
11855 else
11856 filtered_count++;
11857 }
11858 }
718e3744 11859 }
47fc97cc 11860
718e3744 11861 if (output_count != 0)
11862 vty_out (vty, "%sTotal number of prefixes %ld%s",
11863 VTY_NEWLINE, output_count, VTY_NEWLINE);
11864}
11865
94f2b392 11866static int
47fc97cc 11867peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
b05a1c8b 11868 int in, char *rmap_name)
bb46e94f 11869{
718e3744 11870 if (! peer || ! peer->afc[afi][safi])
11871 {
11872 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11873 return CMD_WARNING;
11874 }
11875
11876 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11877 {
11878 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
11879 VTY_NEWLINE);
11880 return CMD_WARNING;
11881 }
11882
0b16f239
DS
11883 if (!in && (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)
11884 && !bgp_flag_check(peer->bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)))
11885 {
11886 vty_out (vty, "%% Cannot apply outgoing route-map on route-reflector clients%s",
11887 VTY_NEWLINE);
11888 vty_out (vty, "%% Enable bgp route-reflector allow-outbound-policy flag%s",
11889 VTY_NEWLINE);
11890 return CMD_WARNING;
11891 }
11892
b05a1c8b 11893 show_adj_route (vty, peer, afi, safi, in, rmap_name);
718e3744 11894
11895 return CMD_SUCCESS;
11896}
11897
2a71e9ce
TP
11898DEFUN (show_ip_bgp_view_neighbor_advertised_route,
11899 show_ip_bgp_view_neighbor_advertised_route_cmd,
a80beece 11900 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 11901 SHOW_STR
11902 IP_STR
11903 BGP_STR
2a71e9ce
TP
11904 "BGP view\n"
11905 "View name\n"
718e3744 11906 "Detailed information on TCP and BGP neighbor connections\n"
11907 "Neighbor to display information about\n"
11908 "Neighbor to display information about\n"
11909 "Display the routes advertised to a BGP neighbor\n")
11910{
bb46e94f 11911 struct peer *peer;
11912
2a71e9ce
TP
11913 if (argc == 2)
11914 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11915 else
11916 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11917
bb46e94f 11918 if (! peer)
11919 return CMD_WARNING;
0b16f239 11920
b05a1c8b 11921 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL);
718e3744 11922}
11923
0b16f239 11924DEFUN (show_ip_bgp_neighbor_advertised_route,
2a71e9ce 11925 show_ip_bgp_neighbor_advertised_route_cmd,
a80beece 11926 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
2a71e9ce
TP
11927 SHOW_STR
11928 IP_STR
11929 BGP_STR
11930 "Detailed information on TCP and BGP neighbor connections\n"
11931 "Neighbor to display information about\n"
11932 "Neighbor to display information about\n"
a80beece 11933 "Neighbor on bgp configured interface\n"
2a71e9ce
TP
11934 "Display the routes advertised to a BGP neighbor\n")
11935
0b16f239
DS
11936{
11937 struct peer *peer;
11938 char *rmap_name = NULL;
11939
11940 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11941
11942 if (! peer)
11943 return CMD_WARNING;
11944
11945 if (argc == 2)
11946 rmap_name = argv[1];
11947
b05a1c8b 11948 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name);
0b16f239
DS
11949}
11950
11951ALIAS (show_ip_bgp_neighbor_advertised_route,
11952 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
11953 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
11954 SHOW_STR
11955 IP_STR
11956 BGP_STR
11957 "Detailed information on TCP and BGP neighbor connections\n"
11958 "Neighbor to display information about\n"
11959 "Neighbor to display information about\n"
11960 "Neighbor on bgp configured interface\n"
11961 "Display the routes advertised to a BGP neighbor\n")
11962
718e3744 11963DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
11964 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
a80beece 11965 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 11966 SHOW_STR
11967 IP_STR
11968 BGP_STR
11969 "Address family\n"
11970 "Address Family modifier\n"
11971 "Address Family modifier\n"
11972 "Detailed information on TCP and BGP neighbor connections\n"
11973 "Neighbor to display information about\n"
11974 "Neighbor to display information about\n"
a80beece 11975 "Neighbor on bgp configured interface\n"
718e3744 11976 "Display the routes advertised to a BGP neighbor\n")
11977{
bb46e94f 11978 struct peer *peer;
0b16f239 11979 char *rmap_name = NULL;
bb46e94f 11980
11981 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11982 if (! peer)
11983 return CMD_WARNING;
11984
0b16f239
DS
11985 if (argc == 3)
11986 rmap_name = argv[2];
11987
718e3744 11988 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 11989 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name);
718e3744 11990
b05a1c8b 11991 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name);
718e3744 11992}
11993
0b16f239
DS
11994ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
11995 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
11996 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
11997 SHOW_STR
11998 IP_STR
11999 BGP_STR
12000 "Address family\n"
12001 "Address Family modifier\n"
12002 "Address Family modifier\n"
12003 "Detailed information on TCP and BGP neighbor connections\n"
12004 "Neighbor to display information about\n"
12005 "Neighbor to display information about\n"
12006 "Neighbor on bgp configured interface\n"
12007 "Display the routes advertised to a BGP neighbor\n"
12008 "Route-map to control what is displayed\n")
12009
718e3744 12010#ifdef HAVE_IPV6
bb46e94f 12011DEFUN (show_bgp_view_neighbor_advertised_route,
12012 show_bgp_view_neighbor_advertised_route_cmd,
a80beece 12013 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 12014 SHOW_STR
12015 BGP_STR
bb46e94f 12016 "BGP view\n"
12017 "View name\n"
718e3744 12018 "Detailed information on TCP and BGP neighbor connections\n"
12019 "Neighbor to display information about\n"
12020 "Neighbor to display information about\n"
a80beece 12021 "Neighbor on bgp configured interface\n"
718e3744 12022 "Display the routes advertised to a BGP neighbor\n")
12023{
bb46e94f 12024 struct peer *peer;
12025
12026 if (argc == 2)
12027 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12028 else
12029 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12030
12031 if (! peer)
0b16f239 12032 return CMD_WARNING;
bb46e94f 12033
b05a1c8b 12034 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL);
47fc97cc
DS
12035}
12036
0b16f239
DS
12037ALIAS (show_bgp_view_neighbor_advertised_route,
12038 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
12039 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
12040 SHOW_STR
12041 BGP_STR
12042 "BGP view\n"
12043 "View name\n"
12044 "Address family\n"
12045 "Detailed information on TCP and BGP neighbor connections\n"
12046 "Neighbor to display information about\n"
12047 "Neighbor to display information about\n"
12048 "Neighbor on bgp configured interface\n"
12049 "Display the routes advertised to a BGP neighbor\n")
12050
0b16f239
DS
12051DEFUN (show_bgp_neighbor_advertised_route,
12052 show_bgp_neighbor_advertised_route_cmd,
12053 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
bb46e94f 12054 SHOW_STR
12055 BGP_STR
bb46e94f 12056 "Detailed information on TCP and BGP neighbor connections\n"
12057 "Neighbor to display information about\n"
12058 "Neighbor to display information about\n"
a80beece 12059 "Neighbor on bgp configured interface\n"
0b16f239
DS
12060 "Display the routes advertised to a BGP neighbor\n")
12061
bb46e94f 12062{
12063 struct peer *peer;
0b16f239 12064 char *rmap_name = NULL;
bb46e94f 12065
0b16f239 12066 peer = peer_lookup_in_view (vty, NULL, argv[0]);
bb46e94f 12067
12068 if (! peer)
12069 return CMD_WARNING;
12070
0b16f239
DS
12071 if (argc == 2)
12072 rmap_name = argv[1];
12073
b05a1c8b 12074 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name);
718e3744 12075}
12076
0b16f239
DS
12077ALIAS (show_bgp_neighbor_advertised_route,
12078 show_bgp_neighbor_advertised_route_rmap_cmd,
12079 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
bb46e94f 12080 SHOW_STR
12081 BGP_STR
bb46e94f 12082 "Detailed information on TCP and BGP neighbor connections\n"
12083 "Neighbor to display information about\n"
12084 "Neighbor to display information about\n"
a80beece 12085 "Neighbor on bgp configured interface\n"
0b16f239 12086 "Display the routes advertised to a BGP neighbor\n")
bb46e94f 12087
0b16f239
DS
12088ALIAS (show_bgp_neighbor_advertised_route,
12089 show_bgp_ipv6_neighbor_advertised_route_cmd,
12090 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
bb46e94f 12091 SHOW_STR
12092 BGP_STR
0b16f239 12093 "Address family\n"
bb46e94f 12094 "Detailed information on TCP and BGP neighbor connections\n"
12095 "Neighbor to display information about\n"
12096 "Neighbor to display information about\n"
a80beece 12097 "Neighbor on bgp configured interface\n"
bb46e94f 12098 "Display the routes advertised to a BGP neighbor\n")
0b16f239
DS
12099
12100ALIAS (show_bgp_neighbor_advertised_route,
12101 show_bgp_ipv6_neighbor_advertised_route_rmap_cmd,
12102 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
718e3744 12103 SHOW_STR
12104 BGP_STR
12105 "Address family\n"
12106 "Detailed information on TCP and BGP neighbor connections\n"
12107 "Neighbor to display information about\n"
12108 "Neighbor to display information about\n"
a80beece 12109 "Neighbor on bgp configured interface\n"
718e3744 12110 "Display the routes advertised to a BGP neighbor\n")
12111
12112/* old command */
0b16f239 12113ALIAS (show_bgp_neighbor_advertised_route,
718e3744 12114 ipv6_bgp_neighbor_advertised_route_cmd,
a80beece 12115 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 12116 SHOW_STR
12117 IPV6_STR
12118 BGP_STR
12119 "Detailed information on TCP and BGP neighbor connections\n"
12120 "Neighbor to display information about\n"
12121 "Neighbor to display information about\n"
a80beece 12122 "Neighbor on bgp configured interface\n"
718e3744 12123 "Display the routes advertised to a BGP neighbor\n")
bb46e94f 12124
718e3744 12125/* old command */
12126DEFUN (ipv6_mbgp_neighbor_advertised_route,
12127 ipv6_mbgp_neighbor_advertised_route_cmd,
a80beece 12128 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 12129 SHOW_STR
12130 IPV6_STR
12131 MBGP_STR
12132 "Detailed information on TCP and BGP neighbor connections\n"
12133 "Neighbor to display information about\n"
12134 "Neighbor to display information about\n"
a80beece
DS
12135 "Neighbor on bgp configured interface\n"
12136 "Neighbor on bgp configured interface\n"
718e3744 12137 "Display the routes advertised to a BGP neighbor\n")
12138{
bb46e94f 12139 struct peer *peer;
12140
12141 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12142 if (! peer)
12143 return CMD_WARNING;
12144
b05a1c8b 12145 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL);
718e3744 12146}
12147#endif /* HAVE_IPV6 */
6b0655a2 12148
0b16f239
DS
12149DEFUN (show_bgp_view_neighbor_received_routes,
12150 show_bgp_view_neighbor_received_routes_cmd,
12151 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
12152 SHOW_STR
12153 BGP_STR
12154 "BGP view\n"
12155 "View name\n"
12156 "Detailed information on TCP and BGP neighbor connections\n"
12157 "Neighbor to display information about\n"
12158 "Neighbor to display information about\n"
12159 "Neighbor on bgp configured interface\n"
12160 "Display the received routes from neighbor\n")
12161{
12162 struct peer *peer;
12163
12164 if (argc == 2)
12165 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12166 else
12167 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12168
12169 if (! peer)
12170 return CMD_WARNING;
12171
b05a1c8b 12172 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL);
0b16f239
DS
12173}
12174
2a71e9ce
TP
12175DEFUN (show_ip_bgp_view_neighbor_received_routes,
12176 show_ip_bgp_view_neighbor_received_routes_cmd,
a80beece 12177 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12178 SHOW_STR
12179 IP_STR
12180 BGP_STR
2a71e9ce
TP
12181 "BGP view\n"
12182 "View name\n"
718e3744 12183 "Detailed information on TCP and BGP neighbor connections\n"
12184 "Neighbor to display information about\n"
12185 "Neighbor to display information about\n"
a80beece 12186 "Neighbor on bgp configured interface\n"
718e3744 12187 "Display the received routes from neighbor\n")
12188{
bb46e94f 12189 struct peer *peer;
12190
2a71e9ce
TP
12191 if (argc == 2)
12192 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12193 else
12194 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12195
bb46e94f 12196 if (! peer)
12197 return CMD_WARNING;
12198
b05a1c8b 12199 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL);
718e3744 12200}
12201
0b16f239
DS
12202ALIAS (show_bgp_view_neighbor_received_routes,
12203 show_bgp_view_ipv6_neighbor_received_routes_cmd,
12204 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
12205 SHOW_STR
12206 BGP_STR
12207 "BGP view\n"
12208 "View name\n"
12209 "Address family\n"
12210 "Detailed information on TCP and BGP neighbor connections\n"
12211 "Neighbor to display information about\n"
12212 "Neighbor to display information about\n"
12213 "Neighbor on bgp configured interface\n"
12214 "Display the received routes from neighbor\n")
12215
12216DEFUN (show_ip_bgp_neighbor_received_routes,
2a71e9ce 12217 show_ip_bgp_neighbor_received_routes_cmd,
a80beece 12218 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
2a71e9ce
TP
12219 SHOW_STR
12220 IP_STR
12221 BGP_STR
12222 "Detailed information on TCP and BGP neighbor connections\n"
12223 "Neighbor to display information about\n"
12224 "Neighbor to display information about\n"
a80beece 12225 "Neighbor on bgp configured interface\n"
2a71e9ce
TP
12226 "Display the received routes from neighbor\n")
12227
0b16f239
DS
12228{
12229 struct peer *peer;
12230 char *rmap_name = NULL;
12231
12232 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12233
12234 if (! peer)
12235 return CMD_WARNING;
12236
12237 if (argc == 2)
12238 rmap_name = argv[1];
12239
b05a1c8b 12240 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name);
0b16f239
DS
12241}
12242
12243ALIAS (show_ip_bgp_neighbor_received_routes,
12244 show_ip_bgp_neighbor_received_routes_rmap_cmd,
12245 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
12246 SHOW_STR
12247 IP_STR
12248 BGP_STR
12249 "Detailed information on TCP and BGP neighbor connections\n"
12250 "Neighbor to display information about\n"
12251 "Neighbor to display information about\n"
12252 "Neighbor on bgp configured interface\n"
12253 "Display the received routes from neighbor\n")
12254
718e3744 12255DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12256 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
a80beece 12257 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12258 SHOW_STR
12259 IP_STR
12260 BGP_STR
12261 "Address family\n"
12262 "Address Family modifier\n"
12263 "Address Family modifier\n"
12264 "Detailed information on TCP and BGP neighbor connections\n"
12265 "Neighbor to display information about\n"
12266 "Neighbor to display information about\n"
a80beece 12267 "Neighbor on bgp configured interface\n"
718e3744 12268 "Display the received routes from neighbor\n")
12269{
bb46e94f 12270 struct peer *peer;
0b16f239 12271 char *rmap_name = NULL;
bb46e94f 12272
12273 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12274 if (! peer)
12275 return CMD_WARNING;
0b16f239
DS
12276
12277 if (argc == 3)
12278 rmap_name = argv[2];
12279
718e3744 12280 if (strncmp (argv[0], "m", 1) == 0)
b05a1c8b 12281 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name);
718e3744 12282
b05a1c8b 12283 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name);
718e3744 12284}
12285
0b16f239
DS
12286ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
12287 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
12288 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
12289 SHOW_STR
12290 IP_STR
12291 BGP_STR
12292 "Address family\n"
12293 "Address Family modifier\n"
12294 "Address Family modifier\n"
12295 "Detailed information on TCP and BGP neighbor connections\n"
12296 "Neighbor to display information about\n"
12297 "Neighbor to display information about\n"
12298 "Neighbor on bgp configured interface\n"
12299 "Display the received routes from neighbor\n")
12300
95cbbd2a
ML
12301DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
12302 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
12303#ifdef HAVE_IPV6
a80beece 12304 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes)",
95cbbd2a 12305#else
a80beece 12306 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes)",
95cbbd2a
ML
12307#endif
12308 SHOW_STR
12309 BGP_STR
12310 "BGP view\n"
2b00515a 12311 "View name\n"
95cbbd2a
ML
12312 "Address family\n"
12313#ifdef HAVE_IPV6
12314 "Address family\n"
12315#endif
12316 "Address family modifier\n"
12317 "Address family modifier\n"
12318 "Detailed information on TCP and BGP neighbor connections\n"
12319 "Neighbor to display information about\n"
12320 "Neighbor to display information about\n"
a80beece 12321 "Neighbor on bgp configured interface\n"
95cbbd2a
ML
12322 "Display the advertised routes to neighbor\n"
12323 "Display the received routes from neighbor\n")
12324{
12325 int afi;
12326 int safi;
12327 int in;
12328 struct peer *peer;
12329
12330#ifdef HAVE_IPV6
12331 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
12332#else
12333 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12334#endif
12335
12336 if (! peer)
12337 return CMD_WARNING;
12338
12339#ifdef HAVE_IPV6
12340 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
12341 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12342 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
12343#else
12344 afi = AFI_IP;
12345 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12346 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
12347#endif
12348
b05a1c8b 12349 return peer_adj_routes (vty, peer, afi, safi, in, NULL);
95cbbd2a
ML
12350}
12351
718e3744 12352DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12353 show_ip_bgp_neighbor_received_prefix_filter_cmd,
a80beece 12354 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
718e3744 12355 SHOW_STR
12356 IP_STR
12357 BGP_STR
12358 "Detailed information on TCP and BGP neighbor connections\n"
12359 "Neighbor to display information about\n"
12360 "Neighbor to display information about\n"
a80beece 12361 "Neighbor on bgp configured interface\n"
718e3744 12362 "Display information received from a BGP neighbor\n"
12363 "Display the prefixlist filter\n")
12364{
12365 char name[BUFSIZ];
c63b83fe 12366 union sockunion su;
718e3744 12367 struct peer *peer;
c63b83fe 12368 int count, ret;
718e3744 12369
c63b83fe
JBD
12370 ret = str2sockunion (argv[0], &su);
12371 if (ret < 0)
12372 {
a80beece
DS
12373 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12374 if (!peer)
12375 {
12376 vty_out (vty, "Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12377 return CMD_WARNING;
12378 }
12379 }
12380 else
12381 {
12382 peer = peer_lookup (NULL, &su);
12383 if (! peer)
12384 return CMD_WARNING;
c63b83fe 12385 }
718e3744 12386
12387 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12388 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
12389 if (count)
12390 {
12391 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
12392 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
12393 }
12394
12395 return CMD_SUCCESS;
12396}
12397
12398DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
12399 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
a80beece 12400 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
718e3744 12401 SHOW_STR
12402 IP_STR
12403 BGP_STR
12404 "Address family\n"
12405 "Address Family modifier\n"
12406 "Address Family modifier\n"
12407 "Detailed information on TCP and BGP neighbor connections\n"
12408 "Neighbor to display information about\n"
12409 "Neighbor to display information about\n"
a80beece 12410 "Neighbor on bgp configured interface\n"
718e3744 12411 "Display information received from a BGP neighbor\n"
12412 "Display the prefixlist filter\n")
12413{
12414 char name[BUFSIZ];
c63b83fe 12415 union sockunion su;
718e3744 12416 struct peer *peer;
c63b83fe 12417 int count, ret;
718e3744 12418
c63b83fe
JBD
12419 ret = str2sockunion (argv[1], &su);
12420 if (ret < 0)
12421 {
a80beece
DS
12422 peer = peer_lookup_by_conf_if (NULL, argv[1]);
12423 if (!peer)
12424 {
12425 vty_out (vty, "Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
12426 return CMD_WARNING;
12427 }
12428 }
12429 else
12430 {
12431 peer = peer_lookup (NULL, &su);
12432 if (! peer)
12433 return CMD_WARNING;
c63b83fe 12434 }
718e3744 12435
12436 if (strncmp (argv[0], "m", 1) == 0)
12437 {
12438 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
12439 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
12440 if (count)
12441 {
12442 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
12443 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
12444 }
12445 }
12446 else
12447 {
12448 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12449 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
12450 if (count)
12451 {
12452 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
12453 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
12454 }
12455 }
12456
12457 return CMD_SUCCESS;
12458}
12459
12460
12461#ifdef HAVE_IPV6
bb46e94f 12462ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 12463 show_bgp_neighbor_received_routes_cmd,
a80beece 12464 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12465 SHOW_STR
12466 BGP_STR
12467 "Detailed information on TCP and BGP neighbor connections\n"
12468 "Neighbor to display information about\n"
12469 "Neighbor to display information about\n"
a80beece 12470 "Neighbor on bgp configured interface\n"
718e3744 12471 "Display the received routes from neighbor\n")
718e3744 12472
bb46e94f 12473ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 12474 show_bgp_ipv6_neighbor_received_routes_cmd,
a80beece 12475 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12476 SHOW_STR
12477 BGP_STR
12478 "Address family\n"
12479 "Detailed information on TCP and BGP neighbor connections\n"
12480 "Neighbor to display information about\n"
12481 "Neighbor to display information about\n"
a80beece 12482 "Neighbor on bgp configured interface\n"
718e3744 12483 "Display the received routes from neighbor\n")
12484
0b16f239
DS
12485ALIAS (show_bgp_view_neighbor_received_routes,
12486 show_bgp_neighbor_received_routes_rmap_cmd,
12487 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
12488 SHOW_STR
12489 BGP_STR
12490 "Detailed information on TCP and BGP neighbor connections\n"
12491 "Neighbor to display information about\n"
12492 "Neighbor to display information about\n"
12493 "Neighbor on bgp configured interface\n"
12494 "Display the received routes from neighbor\n")
12495
12496ALIAS (show_bgp_view_neighbor_received_routes,
12497 show_bgp_ipv6_neighbor_received_routes_rmap_cmd,
12498 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
12499 SHOW_STR
12500 BGP_STR
12501 "Address family\n"
12502 "Detailed information on TCP and BGP neighbor connections\n"
12503 "Neighbor to display information about\n"
12504 "Neighbor to display information about\n"
12505 "Neighbor on bgp configured interface\n"
12506 "Display the received routes from neighbor\n")
12507
718e3744 12508DEFUN (show_bgp_neighbor_received_prefix_filter,
12509 show_bgp_neighbor_received_prefix_filter_cmd,
a80beece 12510 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
718e3744 12511 SHOW_STR
12512 BGP_STR
12513 "Detailed information on TCP and BGP neighbor connections\n"
12514 "Neighbor to display information about\n"
12515 "Neighbor to display information about\n"
a80beece 12516 "Neighbor on bgp configured interface\n"
718e3744 12517 "Display information received from a BGP neighbor\n"
12518 "Display the prefixlist filter\n")
12519{
12520 char name[BUFSIZ];
c63b83fe 12521 union sockunion su;
718e3744 12522 struct peer *peer;
c63b83fe 12523 int count, ret;
718e3744 12524
c63b83fe
JBD
12525 ret = str2sockunion (argv[0], &su);
12526 if (ret < 0)
12527 {
a80beece
DS
12528 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12529 if (!peer)
12530 {
12531 vty_out (vty, "Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12532 return CMD_WARNING;
12533 }
12534 }
12535 else
12536 {
12537 peer = peer_lookup (NULL, &su);
12538 if (! peer)
12539 return CMD_WARNING;
c63b83fe 12540 }
718e3744 12541
12542 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12543 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12544 if (count)
12545 {
12546 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12547 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12548 }
12549
12550 return CMD_SUCCESS;
12551}
12552
12553ALIAS (show_bgp_neighbor_received_prefix_filter,
12554 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
a80beece 12555 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
718e3744 12556 SHOW_STR
12557 BGP_STR
12558 "Address family\n"
12559 "Detailed information on TCP and BGP neighbor connections\n"
12560 "Neighbor to display information about\n"
12561 "Neighbor to display information about\n"
a80beece 12562 "Neighbor on bgp configured interface\n"
718e3744 12563 "Display information received from a BGP neighbor\n"
12564 "Display the prefixlist filter\n")
12565
12566/* old command */
bb46e94f 12567ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 12568 ipv6_bgp_neighbor_received_routes_cmd,
a80beece 12569 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12570 SHOW_STR
12571 IPV6_STR
12572 BGP_STR
12573 "Detailed information on TCP and BGP neighbor connections\n"
12574 "Neighbor to display information about\n"
12575 "Neighbor to display information about\n"
a80beece 12576 "Neighbor on bgp configured interface\n"
718e3744 12577 "Display the received routes from neighbor\n")
718e3744 12578
12579/* old command */
12580DEFUN (ipv6_mbgp_neighbor_received_routes,
12581 ipv6_mbgp_neighbor_received_routes_cmd,
a80beece 12582 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12583 SHOW_STR
12584 IPV6_STR
12585 MBGP_STR
12586 "Detailed information on TCP and BGP neighbor connections\n"
12587 "Neighbor to display information about\n"
12588 "Neighbor to display information about\n"
a80beece 12589 "Neighbor on bgp configured interface\n"
718e3744 12590 "Display the received routes from neighbor\n")
12591{
bb46e94f 12592 struct peer *peer;
12593
12594 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12595 if (! peer)
12596 return CMD_WARNING;
12597
b05a1c8b 12598 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL);
bb46e94f 12599}
12600
12601DEFUN (show_bgp_view_neighbor_received_prefix_filter,
12602 show_bgp_view_neighbor_received_prefix_filter_cmd,
a80beece 12603 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
bb46e94f 12604 SHOW_STR
12605 BGP_STR
12606 "BGP view\n"
12607 "View name\n"
12608 "Detailed information on TCP and BGP neighbor connections\n"
12609 "Neighbor to display information about\n"
12610 "Neighbor to display information about\n"
a80beece 12611 "Neighbor on bgp configured interface\n"
bb46e94f 12612 "Display information received from a BGP neighbor\n"
12613 "Display the prefixlist filter\n")
12614{
12615 char name[BUFSIZ];
c63b83fe 12616 union sockunion su;
bb46e94f 12617 struct peer *peer;
12618 struct bgp *bgp;
c63b83fe 12619 int count, ret;
bb46e94f 12620
12621 /* BGP structure lookup. */
12622 bgp = bgp_lookup_by_name (argv[0]);
12623 if (bgp == NULL)
12624 {
12625 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12626 return CMD_WARNING;
12627 }
12628
c63b83fe
JBD
12629 ret = str2sockunion (argv[1], &su);
12630 if (ret < 0)
12631 {
a80beece
DS
12632 peer = peer_lookup_by_conf_if (bgp, argv[1]);
12633 if (!peer)
12634 {
12635 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
12636 return CMD_WARNING;
12637 }
12638 }
12639 else
12640 {
12641 peer = peer_lookup (bgp, &su);
12642 if (! peer)
12643 return CMD_WARNING;
c63b83fe 12644 }
bb46e94f 12645
12646 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12647 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12648 if (count)
12649 {
12650 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12651 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12652 }
12653
12654 return CMD_SUCCESS;
718e3744 12655}
bb46e94f 12656
12657ALIAS (show_bgp_view_neighbor_received_prefix_filter,
12658 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
a80beece 12659 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
bb46e94f 12660 SHOW_STR
12661 BGP_STR
12662 "BGP view\n"
12663 "View name\n"
12664 "Address family\n"
12665 "Detailed information on TCP and BGP neighbor connections\n"
12666 "Neighbor to display information about\n"
12667 "Neighbor to display information about\n"
a80beece 12668 "Neighbor on bgp configured interface\n"
bb46e94f 12669 "Display information received from a BGP neighbor\n"
12670 "Display the prefixlist filter\n")
718e3744 12671#endif /* HAVE_IPV6 */
6b0655a2 12672
94f2b392 12673static int
bb46e94f 12674bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
b05a1c8b 12675 safi_t safi, enum bgp_show_type type)
718e3744 12676{
718e3744 12677 if (! peer || ! peer->afc[afi][safi])
12678 {
12679 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
718e3744 12680 return CMD_WARNING;
12681 }
47fc97cc 12682
b05a1c8b 12683 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, 0);
718e3744 12684}
12685
12686DEFUN (show_ip_bgp_neighbor_routes,
12687 show_ip_bgp_neighbor_routes_cmd,
a80beece 12688 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 12689 SHOW_STR
12690 IP_STR
12691 BGP_STR
12692 "Detailed information on TCP and BGP neighbor connections\n"
12693 "Neighbor to display information about\n"
12694 "Neighbor to display information about\n"
a80beece 12695 "Neighbor on bgp configured interface\n"
718e3744 12696 "Display routes learned from neighbor\n")
12697{
bb46e94f 12698 struct peer *peer;
12699
12700 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12701 if (! peer)
12702 return CMD_WARNING;
12703
12704 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
b05a1c8b 12705 bgp_show_type_neighbor);
718e3744 12706}
12707
12708DEFUN (show_ip_bgp_neighbor_flap,
12709 show_ip_bgp_neighbor_flap_cmd,
a80beece 12710 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
718e3744 12711 SHOW_STR
12712 IP_STR
12713 BGP_STR
12714 "Detailed information on TCP and BGP neighbor connections\n"
12715 "Neighbor to display information about\n"
12716 "Neighbor to display information about\n"
a80beece 12717 "Neighbor on bgp configured interface\n"
718e3744 12718 "Display flap statistics of the routes learned from neighbor\n")
12719{
bb46e94f 12720 struct peer *peer;
12721
12722 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12723 if (! peer)
12724 return CMD_WARNING;
12725
12726 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
b05a1c8b 12727 bgp_show_type_flap_neighbor);
718e3744 12728}
12729
12730DEFUN (show_ip_bgp_neighbor_damp,
12731 show_ip_bgp_neighbor_damp_cmd,
a80beece 12732 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
718e3744 12733 SHOW_STR
12734 IP_STR
12735 BGP_STR
12736 "Detailed information on TCP and BGP neighbor connections\n"
12737 "Neighbor to display information about\n"
12738 "Neighbor to display information about\n"
a80beece 12739 "Neighbor on bgp configured interface\n"
718e3744 12740 "Display the dampened routes received from neighbor\n")
12741{
bb46e94f 12742 struct peer *peer;
12743
12744 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12745 if (! peer)
12746 return CMD_WARNING;
12747
12748 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
b05a1c8b 12749 bgp_show_type_damp_neighbor);
718e3744 12750}
12751
12752DEFUN (show_ip_bgp_ipv4_neighbor_routes,
12753 show_ip_bgp_ipv4_neighbor_routes_cmd,
a80beece 12754 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 12755 SHOW_STR
12756 IP_STR
12757 BGP_STR
12758 "Address family\n"
12759 "Address Family modifier\n"
12760 "Address Family modifier\n"
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"
718e3744 12765 "Display routes learned from neighbor\n")
12766{
bb46e94f 12767 struct peer *peer;
12768
12769 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12770 if (! peer)
12771 return CMD_WARNING;
12772
718e3744 12773 if (strncmp (argv[0], "m", 1) == 0)
bb46e94f 12774 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
b05a1c8b 12775 bgp_show_type_neighbor);
718e3744 12776
bb46e94f 12777 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
b05a1c8b 12778 bgp_show_type_neighbor);
718e3744 12779}
bb46e94f 12780
fee0f4c6 12781DEFUN (show_ip_bgp_view_rsclient,
12782 show_ip_bgp_view_rsclient_cmd,
a80beece 12783 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 12784 SHOW_STR
12785 IP_STR
12786 BGP_STR
12787 "BGP view\n"
2b00515a 12788 "View name\n"
fee0f4c6 12789 "Information about Route Server Client\n"
a80beece 12790 NEIGHBOR_ADDR_STR3)
fee0f4c6 12791{
12792 struct bgp_table *table;
12793 struct peer *peer;
12794
12795 if (argc == 2)
12796 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12797 else
12798 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12799
12800 if (! peer)
12801 return CMD_WARNING;
12802
12803 if (! peer->afc[AFI_IP][SAFI_UNICAST])
12804 {
12805 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12806 VTY_NEWLINE);
12807 return CMD_WARNING;
12808 }
12809
12810 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
12811 PEER_FLAG_RSERVER_CLIENT))
12812 {
12813 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12814 VTY_NEWLINE);
12815 return CMD_WARNING;
12816 }
12817
12818 table = peer->rib[AFI_IP][SAFI_UNICAST];
12819
47fc97cc 12820 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
b05a1c8b 12821 NULL, 0);
fee0f4c6 12822}
12823
12824ALIAS (show_ip_bgp_view_rsclient,
12825 show_ip_bgp_rsclient_cmd,
a80beece 12826 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 12827 SHOW_STR
12828 IP_STR
12829 BGP_STR
12830 "Information about Route Server Client\n"
a80beece 12831 NEIGHBOR_ADDR_STR3)
fee0f4c6 12832
95cbbd2a
ML
12833DEFUN (show_bgp_view_ipv4_safi_rsclient,
12834 show_bgp_view_ipv4_safi_rsclient_cmd,
a80beece 12835 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 12836 SHOW_STR
fee0f4c6 12837 BGP_STR
12838 "BGP view\n"
2b00515a 12839 "View name\n"
95cbbd2a
ML
12840 "Address family\n"
12841 "Address Family modifier\n"
12842 "Address Family modifier\n"
fee0f4c6 12843 "Information about Route Server Client\n"
a80beece 12844 NEIGHBOR_ADDR_STR3)
fee0f4c6 12845{
95cbbd2a 12846 struct bgp_table *table;
fee0f4c6 12847 struct peer *peer;
95cbbd2a 12848 safi_t safi;
fee0f4c6 12849
95cbbd2a
ML
12850 if (argc == 3) {
12851 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12852 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12853 } else {
12854 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12855 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12856 }
12857
12858 if (! peer)
12859 return CMD_WARNING;
12860
12861 if (! peer->afc[AFI_IP][safi])
fee0f4c6 12862 {
95cbbd2a
ML
12863 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12864 VTY_NEWLINE);
12865 return CMD_WARNING;
12866 }
12867
12868 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
12869 PEER_FLAG_RSERVER_CLIENT))
12870 {
12871 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12872 VTY_NEWLINE);
12873 return CMD_WARNING;
12874 }
12875
12876 table = peer->rib[AFI_IP][safi];
12877
47fc97cc 12878 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
b05a1c8b 12879 NULL, 0);
95cbbd2a
ML
12880}
12881
12882ALIAS (show_bgp_view_ipv4_safi_rsclient,
12883 show_bgp_ipv4_safi_rsclient_cmd,
a80beece 12884 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
95cbbd2a
ML
12885 SHOW_STR
12886 BGP_STR
12887 "Address family\n"
12888 "Address Family modifier\n"
12889 "Address Family modifier\n"
12890 "Information about Route Server Client\n"
a80beece 12891 NEIGHBOR_ADDR_STR3)
95cbbd2a
ML
12892
12893DEFUN (show_ip_bgp_view_rsclient_route,
12894 show_ip_bgp_view_rsclient_route_cmd,
a80beece 12895 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
95cbbd2a
ML
12896 SHOW_STR
12897 IP_STR
12898 BGP_STR
12899 "BGP view\n"
2b00515a 12900 "View name\n"
95cbbd2a 12901 "Information about Route Server Client\n"
a80beece 12902 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
12903 "Network in the BGP routing table to display\n")
12904{
12905 struct bgp *bgp;
12906 struct peer *peer;
12907
12908 /* BGP structure lookup. */
12909 if (argc == 3)
12910 {
12911 bgp = bgp_lookup_by_name (argv[0]);
12912 if (bgp == NULL)
12913 {
12914 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12915 return CMD_WARNING;
fee0f4c6 12916 }
12917 }
12918 else
12919 {
12920 bgp = bgp_get_default ();
12921 if (bgp == NULL)
12922 {
12923 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12924 return CMD_WARNING;
12925 }
12926 }
12927
12928 if (argc == 3)
12929 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12930 else
12931 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12932
12933 if (! peer)
12934 return CMD_WARNING;
12935
12936 if (! peer->afc[AFI_IP][SAFI_UNICAST])
12937 {
12938 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12939 VTY_NEWLINE);
12940 return CMD_WARNING;
b05a1c8b 12941 }
fee0f4c6 12942
12943 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
12944 PEER_FLAG_RSERVER_CLIENT))
12945 {
12946 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12947 VTY_NEWLINE);
12948 return CMD_WARNING;
12949 }
12950
12951 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
12952 (argc == 3) ? argv[2] : argv[1],
b05a1c8b 12953 AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, 0);
fee0f4c6 12954}
12955
12956ALIAS (show_ip_bgp_view_rsclient_route,
12957 show_ip_bgp_rsclient_route_cmd,
a80beece 12958 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
fee0f4c6 12959 SHOW_STR
12960 IP_STR
12961 BGP_STR
12962 "Information about Route Server Client\n"
a80beece 12963 NEIGHBOR_ADDR_STR3
fee0f4c6 12964 "Network in the BGP routing table to display\n")
12965
95cbbd2a
ML
12966DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
12967 show_bgp_view_ipv4_safi_rsclient_route_cmd,
a80beece 12968 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
95cbbd2a
ML
12969 SHOW_STR
12970 BGP_STR
12971 "BGP view\n"
2b00515a 12972 "View name\n"
95cbbd2a
ML
12973 "Address family\n"
12974 "Address Family modifier\n"
12975 "Address Family modifier\n"
12976 "Information about Route Server Client\n"
a80beece 12977 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
12978 "Network in the BGP routing table to display\n")
12979{
12980 struct bgp *bgp;
12981 struct peer *peer;
12982 safi_t safi;
12983
12984 /* BGP structure lookup. */
12985 if (argc == 4)
12986 {
12987 bgp = bgp_lookup_by_name (argv[0]);
12988 if (bgp == NULL)
12989 {
12990 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12991 return CMD_WARNING;
12992 }
12993 }
12994 else
12995 {
12996 bgp = bgp_get_default ();
12997 if (bgp == NULL)
12998 {
12999 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13000 return CMD_WARNING;
13001 }
13002 }
13003
13004 if (argc == 4) {
13005 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13006 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13007 } else {
13008 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13009 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13010 }
13011
13012 if (! peer)
13013 return CMD_WARNING;
13014
13015 if (! peer->afc[AFI_IP][safi])
13016 {
13017 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13018 VTY_NEWLINE);
13019 return CMD_WARNING;
13020}
13021
13022 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13023 PEER_FLAG_RSERVER_CLIENT))
13024 {
13025 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13026 VTY_NEWLINE);
13027 return CMD_WARNING;
13028 }
13029
13030 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
13031 (argc == 4) ? argv[3] : argv[2],
b05a1c8b 13032 AFI_IP, safi, NULL, 0, BGP_PATH_ALL, 0);
95cbbd2a
ML
13033}
13034
13035ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
13036 show_bgp_ipv4_safi_rsclient_route_cmd,
a80beece 13037 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
95cbbd2a
ML
13038 SHOW_STR
13039 BGP_STR
13040 "Address family\n"
13041 "Address Family modifier\n"
13042 "Address Family modifier\n"
13043 "Information about Route Server Client\n"
a80beece 13044 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13045 "Network in the BGP routing table to display\n")
13046
fee0f4c6 13047DEFUN (show_ip_bgp_view_rsclient_prefix,
13048 show_ip_bgp_view_rsclient_prefix_cmd,
a80beece 13049 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
fee0f4c6 13050 SHOW_STR
13051 IP_STR
13052 BGP_STR
13053 "BGP view\n"
2b00515a 13054 "View name\n"
fee0f4c6 13055 "Information about Route Server Client\n"
a80beece 13056 NEIGHBOR_ADDR_STR3
fee0f4c6 13057 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13058{
13059 struct bgp *bgp;
13060 struct peer *peer;
13061
13062 /* BGP structure lookup. */
13063 if (argc == 3)
13064 {
13065 bgp = bgp_lookup_by_name (argv[0]);
13066 if (bgp == NULL)
13067 {
13068 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13069 return CMD_WARNING;
13070 }
13071 }
13072 else
13073 {
13074 bgp = bgp_get_default ();
13075 if (bgp == NULL)
13076 {
13077 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13078 return CMD_WARNING;
13079 }
13080 }
13081
13082 if (argc == 3)
13083 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13084 else
13085 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13086
13087 if (! peer)
13088 return CMD_WARNING;
13089
13090 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13091 {
13092 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13093 VTY_NEWLINE);
13094 return CMD_WARNING;
13095}
13096
13097 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13098 PEER_FLAG_RSERVER_CLIENT))
13099{
13100 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13101 VTY_NEWLINE);
13102 return CMD_WARNING;
13103 }
13104
13105 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13106 (argc == 3) ? argv[2] : argv[1],
b05a1c8b 13107 AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, 0);
fee0f4c6 13108}
13109
13110ALIAS (show_ip_bgp_view_rsclient_prefix,
13111 show_ip_bgp_rsclient_prefix_cmd,
a80beece 13112 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
fee0f4c6 13113 SHOW_STR
13114 IP_STR
13115 BGP_STR
13116 "Information about Route Server Client\n"
a80beece 13117 NEIGHBOR_ADDR_STR3
fee0f4c6 13118 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13119
95cbbd2a
ML
13120DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
13121 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
a80beece 13122 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
95cbbd2a
ML
13123 SHOW_STR
13124 BGP_STR
13125 "BGP view\n"
2b00515a 13126 "View name\n"
95cbbd2a
ML
13127 "Address family\n"
13128 "Address Family modifier\n"
13129 "Address Family modifier\n"
13130 "Information about Route Server Client\n"
a80beece 13131 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13132 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13133{
13134 struct bgp *bgp;
13135 struct peer *peer;
13136 safi_t safi;
13137
13138 /* BGP structure lookup. */
13139 if (argc == 4)
13140 {
13141 bgp = bgp_lookup_by_name (argv[0]);
13142 if (bgp == NULL)
13143 {
13144 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13145 return CMD_WARNING;
13146 }
13147 }
13148 else
13149 {
13150 bgp = bgp_get_default ();
13151 if (bgp == NULL)
13152 {
13153 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13154 return CMD_WARNING;
13155 }
13156 }
13157
13158 if (argc == 4) {
13159 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13160 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13161 } else {
13162 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13163 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13164 }
13165
13166 if (! peer)
13167 return CMD_WARNING;
13168
13169 if (! peer->afc[AFI_IP][safi])
13170 {
13171 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13172 VTY_NEWLINE);
13173 return CMD_WARNING;
13174}
13175
13176 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13177 PEER_FLAG_RSERVER_CLIENT))
13178{
13179 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13180 VTY_NEWLINE);
13181 return CMD_WARNING;
13182 }
13183
13184 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
13185 (argc == 4) ? argv[3] : argv[2],
b05a1c8b 13186 AFI_IP, safi, NULL, 1, BGP_PATH_ALL, 0);
95cbbd2a
ML
13187}
13188
13189ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
13190 show_bgp_ipv4_safi_rsclient_prefix_cmd,
a80beece 13191 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
95cbbd2a
ML
13192 SHOW_STR
13193 BGP_STR
13194 "Address family\n"
13195 "Address Family modifier\n"
13196 "Address Family modifier\n"
13197 "Information about Route Server Client\n"
a80beece 13198 NEIGHBOR_ADDR_STR3
95cbbd2a 13199 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
fee0f4c6 13200
718e3744 13201#ifdef HAVE_IPV6
bb46e94f 13202DEFUN (show_bgp_view_neighbor_routes,
13203 show_bgp_view_neighbor_routes_cmd,
a80beece 13204 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 13205 SHOW_STR
13206 BGP_STR
bb46e94f 13207 "BGP view\n"
2b00515a 13208 "View name\n"
718e3744 13209 "Detailed information on TCP and BGP neighbor connections\n"
13210 "Neighbor to display information about\n"
13211 "Neighbor to display information about\n"
a80beece 13212 "Neighbor on bgp configured interface\n"
718e3744 13213 "Display routes learned from neighbor\n")
13214{
bb46e94f 13215 struct peer *peer;
13216
13217 if (argc == 2)
13218 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13219 else
13220 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13221
13222 if (! peer)
13223 return CMD_WARNING;
13224
13225 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
b05a1c8b 13226 bgp_show_type_neighbor);
718e3744 13227}
13228
bb46e94f 13229ALIAS (show_bgp_view_neighbor_routes,
13230 show_bgp_view_ipv6_neighbor_routes_cmd,
a80beece 13231 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes",
bb46e94f 13232 SHOW_STR
13233 BGP_STR
13234 "BGP view\n"
2b00515a 13235 "View name\n"
bb46e94f 13236 "Address family\n"
13237 "Detailed information on TCP and BGP neighbor connections\n"
13238 "Neighbor to display information about\n"
13239 "Neighbor to display information about\n"
a80beece 13240 "Neighbor on bgp configured interface\n"
bb46e94f 13241 "Display routes learned from neighbor\n")
13242
13243DEFUN (show_bgp_view_neighbor_damp,
13244 show_bgp_view_neighbor_damp_cmd,
a80beece 13245 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
bb46e94f 13246 SHOW_STR
13247 BGP_STR
13248 "BGP view\n"
2b00515a 13249 "View name\n"
bb46e94f 13250 "Detailed information on TCP and BGP neighbor connections\n"
13251 "Neighbor to display information about\n"
13252 "Neighbor to display information about\n"
a80beece 13253 "Neighbor on bgp configured interface\n"
bb46e94f 13254 "Display the dampened routes received from neighbor\n")
13255{
13256 struct peer *peer;
13257
13258 if (argc == 2)
13259 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13260 else
13261 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13262
13263 if (! peer)
13264 return CMD_WARNING;
13265
13266 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
b05a1c8b 13267 bgp_show_type_damp_neighbor);
bb46e94f 13268}
13269
13270ALIAS (show_bgp_view_neighbor_damp,
13271 show_bgp_view_ipv6_neighbor_damp_cmd,
a80beece 13272 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
bb46e94f 13273 SHOW_STR
13274 BGP_STR
13275 "BGP view\n"
2b00515a 13276 "View name\n"
bb46e94f 13277 "Address family\n"
13278 "Detailed information on TCP and BGP neighbor connections\n"
13279 "Neighbor to display information about\n"
13280 "Neighbor to display information about\n"
a80beece 13281 "Neighbor on bgp configured interface\n"
bb46e94f 13282 "Display the dampened routes received from neighbor\n")
13283
13284DEFUN (show_bgp_view_neighbor_flap,
13285 show_bgp_view_neighbor_flap_cmd,
a80beece 13286 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
bb46e94f 13287 SHOW_STR
13288 BGP_STR
13289 "BGP view\n"
2b00515a 13290 "View name\n"
bb46e94f 13291 "Detailed information on TCP and BGP neighbor connections\n"
13292 "Neighbor to display information about\n"
13293 "Neighbor to display information about\n"
a80beece 13294 "Neighbor on bgp configured interface\n"
bb46e94f 13295 "Display flap statistics of the routes learned from neighbor\n")
13296{
13297 struct peer *peer;
13298
13299 if (argc == 2)
13300 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13301 else
13302 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13303
13304 if (! peer)
13305 return CMD_WARNING;
13306
13307 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
b05a1c8b 13308 bgp_show_type_flap_neighbor);
bb46e94f 13309}
13310
13311ALIAS (show_bgp_view_neighbor_flap,
13312 show_bgp_view_ipv6_neighbor_flap_cmd,
a80beece 13313 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
bb46e94f 13314 SHOW_STR
13315 BGP_STR
13316 "BGP view\n"
2b00515a 13317 "View name\n"
bb46e94f 13318 "Address family\n"
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 flap statistics of the routes learned from neighbor\n")
13324
13325ALIAS (show_bgp_view_neighbor_routes,
13326 show_bgp_neighbor_routes_cmd,
a80beece 13327 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
bb46e94f 13328 SHOW_STR
13329 BGP_STR
13330 "Detailed information on TCP and BGP neighbor connections\n"
13331 "Neighbor to display information about\n"
13332 "Neighbor to display information about\n"
a80beece 13333 "Neighbor on bgp configured interface\n"
bb46e94f 13334 "Display routes learned from neighbor\n")
13335
13336
13337ALIAS (show_bgp_view_neighbor_routes,
718e3744 13338 show_bgp_ipv6_neighbor_routes_cmd,
a80beece 13339 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 13340 SHOW_STR
13341 BGP_STR
13342 "Address family\n"
13343 "Detailed information on TCP and BGP neighbor connections\n"
13344 "Neighbor to display information about\n"
13345 "Neighbor to display information about\n"
a80beece 13346 "Neighbor on bgp configured interface\n"
718e3744 13347 "Display routes learned from neighbor\n")
13348
13349/* old command */
bb46e94f 13350ALIAS (show_bgp_view_neighbor_routes,
718e3744 13351 ipv6_bgp_neighbor_routes_cmd,
a80beece 13352 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 13353 SHOW_STR
13354 IPV6_STR
13355 BGP_STR
13356 "Detailed information on TCP and BGP neighbor connections\n"
13357 "Neighbor to display information about\n"
13358 "Neighbor to display information about\n"
a80beece 13359 "Neighbor on bgp configured interface\n"
718e3744 13360 "Display routes learned from neighbor\n")
718e3744 13361
13362/* old command */
13363DEFUN (ipv6_mbgp_neighbor_routes,
13364 ipv6_mbgp_neighbor_routes_cmd,
a80beece 13365 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 13366 SHOW_STR
13367 IPV6_STR
13368 MBGP_STR
13369 "Detailed information on TCP and BGP neighbor connections\n"
13370 "Neighbor to display information about\n"
13371 "Neighbor to display information about\n"
a80beece 13372 "Neighbor on bgp configured interface\n"
718e3744 13373 "Display routes learned from neighbor\n")
13374{
bb46e94f 13375 struct peer *peer;
13376
13377 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13378 if (! peer)
13379 return CMD_WARNING;
13380
13381 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
b05a1c8b 13382 bgp_show_type_neighbor);
718e3744 13383}
bb46e94f 13384
13385ALIAS (show_bgp_view_neighbor_flap,
13386 show_bgp_neighbor_flap_cmd,
a80beece 13387 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
bb46e94f 13388 SHOW_STR
13389 BGP_STR
13390 "Detailed information on TCP and BGP neighbor connections\n"
13391 "Neighbor to display information about\n"
13392 "Neighbor to display information about\n"
a80beece 13393 "Neighbor on bgp configured interface\n"
bb46e94f 13394 "Display flap statistics of the routes learned from neighbor\n")
13395
13396ALIAS (show_bgp_view_neighbor_flap,
13397 show_bgp_ipv6_neighbor_flap_cmd,
a80beece 13398 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
bb46e94f 13399 SHOW_STR
13400 BGP_STR
13401 "Address family\n"
13402 "Detailed information on TCP and BGP neighbor connections\n"
13403 "Neighbor to display information about\n"
13404 "Neighbor to display information about\n"
a80beece 13405 "Neighbor on bgp configured interface\n"
bb46e94f 13406 "Display flap statistics of the routes learned from neighbor\n")
13407
13408ALIAS (show_bgp_view_neighbor_damp,
13409 show_bgp_neighbor_damp_cmd,
a80beece 13410 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
bb46e94f 13411 SHOW_STR
13412 BGP_STR
13413 "Detailed information on TCP and BGP neighbor connections\n"
13414 "Neighbor to display information about\n"
13415 "Neighbor to display information about\n"
a80beece 13416 "Neighbor on bgp configured interface\n"
bb46e94f 13417 "Display the dampened routes received from neighbor\n")
13418
13419ALIAS (show_bgp_view_neighbor_damp,
13420 show_bgp_ipv6_neighbor_damp_cmd,
a80beece 13421 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
bb46e94f 13422 SHOW_STR
13423 BGP_STR
13424 "Address family\n"
13425 "Detailed information on TCP and BGP neighbor connections\n"
13426 "Neighbor to display information about\n"
13427 "Neighbor to display information about\n"
a80beece 13428 "Neighbor on bgp configured interface\n"
c001ae62 13429 "Display the dampened routes received from neighbor\n")
fee0f4c6 13430
13431DEFUN (show_bgp_view_rsclient,
13432 show_bgp_view_rsclient_cmd,
a80beece 13433 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 13434 SHOW_STR
13435 BGP_STR
13436 "BGP view\n"
2b00515a 13437 "View name\n"
fee0f4c6 13438 "Information about Route Server Client\n"
a80beece 13439 NEIGHBOR_ADDR_STR3)
fee0f4c6 13440{
13441 struct bgp_table *table;
13442 struct peer *peer;
13443
13444 if (argc == 2)
13445 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13446 else
13447 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13448
13449 if (! peer)
13450 return CMD_WARNING;
13451
13452 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
13453 {
13454 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13455 VTY_NEWLINE);
13456 return CMD_WARNING;
13457 }
13458
13459 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
13460 PEER_FLAG_RSERVER_CLIENT))
13461 {
13462 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13463 VTY_NEWLINE);
13464 return CMD_WARNING;
13465 }
13466
13467 table = peer->rib[AFI_IP6][SAFI_UNICAST];
13468
47fc97cc 13469 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
b05a1c8b 13470 NULL, 0);
fee0f4c6 13471}
13472
13473ALIAS (show_bgp_view_rsclient,
13474 show_bgp_rsclient_cmd,
a80beece 13475 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 13476 SHOW_STR
13477 BGP_STR
13478 "Information about Route Server Client\n"
a80beece 13479 NEIGHBOR_ADDR_STR3)
fee0f4c6 13480
95cbbd2a
ML
13481DEFUN (show_bgp_view_ipv6_safi_rsclient,
13482 show_bgp_view_ipv6_safi_rsclient_cmd,
a80beece 13483 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
95cbbd2a
ML
13484 SHOW_STR
13485 BGP_STR
13486 "BGP view\n"
2b00515a 13487 "View name\n"
95cbbd2a
ML
13488 "Address family\n"
13489 "Address Family modifier\n"
13490 "Address Family modifier\n"
13491 "Information about Route Server Client\n"
a80beece 13492 NEIGHBOR_ADDR_STR3)
95cbbd2a
ML
13493{
13494 struct bgp_table *table;
13495 struct peer *peer;
13496 safi_t safi;
13497
13498 if (argc == 3) {
13499 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13500 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13501 } else {
13502 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13503 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13504 }
13505
13506 if (! peer)
13507 return CMD_WARNING;
13508
13509 if (! peer->afc[AFI_IP6][safi])
13510 {
13511 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13512 VTY_NEWLINE);
13513 return CMD_WARNING;
13514 }
13515
13516 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
13517 PEER_FLAG_RSERVER_CLIENT))
13518 {
13519 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13520 VTY_NEWLINE);
13521 return CMD_WARNING;
13522 }
13523
13524 table = peer->rib[AFI_IP6][safi];
13525
47fc97cc 13526 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
b05a1c8b 13527 NULL, 0);
95cbbd2a
ML
13528}
13529
13530ALIAS (show_bgp_view_ipv6_safi_rsclient,
13531 show_bgp_ipv6_safi_rsclient_cmd,
a80beece 13532 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
95cbbd2a
ML
13533 SHOW_STR
13534 BGP_STR
13535 "Address family\n"
13536 "Address Family modifier\n"
13537 "Address Family modifier\n"
13538 "Information about Route Server Client\n"
a80beece 13539 NEIGHBOR_ADDR_STR3)
95cbbd2a 13540
fee0f4c6 13541DEFUN (show_bgp_view_rsclient_route,
13542 show_bgp_view_rsclient_route_cmd,
a80beece 13543 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
fee0f4c6 13544 SHOW_STR
13545 BGP_STR
13546 "BGP view\n"
2b00515a 13547 "View name\n"
fee0f4c6 13548 "Information about Route Server Client\n"
a80beece 13549 NEIGHBOR_ADDR_STR3
fee0f4c6 13550 "Network in the BGP routing table to display\n")
13551{
13552 struct bgp *bgp;
13553 struct peer *peer;
13554
13555 /* BGP structure lookup. */
13556 if (argc == 3)
13557 {
13558 bgp = bgp_lookup_by_name (argv[0]);
13559 if (bgp == NULL)
13560 {
13561 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13562 return CMD_WARNING;
13563 }
13564 }
13565 else
13566 {
13567 bgp = bgp_get_default ();
13568 if (bgp == NULL)
13569 {
13570 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13571 return CMD_WARNING;
13572 }
13573 }
13574
13575 if (argc == 3)
13576 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13577 else
13578 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13579
13580 if (! peer)
13581 return CMD_WARNING;
13582
13583 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
13584 {
13585 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13586 VTY_NEWLINE);
13587 return CMD_WARNING;
13588 }
13589
13590 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
13591 PEER_FLAG_RSERVER_CLIENT))
13592 {
13593 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13594 VTY_NEWLINE);
13595 return CMD_WARNING;
13596 }
13597
13598 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
13599 (argc == 3) ? argv[2] : argv[1],
b05a1c8b 13600 AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, 0);
fee0f4c6 13601}
13602
13603ALIAS (show_bgp_view_rsclient_route,
13604 show_bgp_rsclient_route_cmd,
a80beece 13605 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
fee0f4c6 13606 SHOW_STR
13607 BGP_STR
13608 "Information about Route Server Client\n"
a80beece 13609 NEIGHBOR_ADDR_STR3
fee0f4c6 13610 "Network in the BGP routing table to display\n")
13611
95cbbd2a
ML
13612DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
13613 show_bgp_view_ipv6_safi_rsclient_route_cmd,
a80beece 13614 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
95cbbd2a
ML
13615 SHOW_STR
13616 BGP_STR
13617 "BGP view\n"
2b00515a 13618 "View name\n"
95cbbd2a
ML
13619 "Address family\n"
13620 "Address Family modifier\n"
13621 "Address Family modifier\n"
13622 "Information about Route Server Client\n"
a80beece 13623 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13624 "Network in the BGP routing table to display\n")
13625{
13626 struct bgp *bgp;
13627 struct peer *peer;
13628 safi_t safi;
13629
13630 /* BGP structure lookup. */
13631 if (argc == 4)
13632 {
13633 bgp = bgp_lookup_by_name (argv[0]);
13634 if (bgp == NULL)
13635 {
13636 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13637 return CMD_WARNING;
13638 }
13639 }
13640 else
13641 {
13642 bgp = bgp_get_default ();
13643 if (bgp == NULL)
13644 {
13645 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13646 return CMD_WARNING;
13647 }
13648 }
13649
13650 if (argc == 4) {
13651 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13652 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13653 } else {
13654 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13655 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13656 }
13657
13658 if (! peer)
13659 return CMD_WARNING;
13660
13661 if (! peer->afc[AFI_IP6][safi])
13662 {
13663 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13664 VTY_NEWLINE);
13665 return CMD_WARNING;
13666}
13667
13668 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
13669 PEER_FLAG_RSERVER_CLIENT))
13670 {
13671 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13672 VTY_NEWLINE);
13673 return CMD_WARNING;
13674 }
13675
13676 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
13677 (argc == 4) ? argv[3] : argv[2],
b05a1c8b 13678 AFI_IP6, safi, NULL, 0, BGP_PATH_ALL, 0);
95cbbd2a
ML
13679}
13680
13681ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
13682 show_bgp_ipv6_safi_rsclient_route_cmd,
a80beece 13683 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
95cbbd2a
ML
13684 SHOW_STR
13685 BGP_STR
13686 "Address family\n"
13687 "Address Family modifier\n"
13688 "Address Family modifier\n"
13689 "Information about Route Server Client\n"
a80beece 13690 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13691 "Network in the BGP routing table to display\n")
13692
fee0f4c6 13693DEFUN (show_bgp_view_rsclient_prefix,
13694 show_bgp_view_rsclient_prefix_cmd,
a80beece 13695 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
fee0f4c6 13696 SHOW_STR
13697 BGP_STR
13698 "BGP view\n"
2b00515a 13699 "View name\n"
fee0f4c6 13700 "Information about Route Server Client\n"
a80beece 13701 NEIGHBOR_ADDR_STR3
fee0f4c6 13702 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
13703{
13704 struct bgp *bgp;
13705 struct peer *peer;
13706
13707 /* BGP structure lookup. */
13708 if (argc == 3)
13709 {
13710 bgp = bgp_lookup_by_name (argv[0]);
13711 if (bgp == NULL)
13712 {
13713 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13714 return CMD_WARNING;
13715 }
13716 }
13717 else
13718 {
13719 bgp = bgp_get_default ();
13720 if (bgp == NULL)
13721 {
13722 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13723 return CMD_WARNING;
13724 }
13725 }
13726
13727 if (argc == 3)
13728 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13729 else
13730 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13731
13732 if (! peer)
13733 return CMD_WARNING;
13734
13735 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
13736 {
13737 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13738 VTY_NEWLINE);
13739 return CMD_WARNING;
13740 }
13741
13742 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
13743 PEER_FLAG_RSERVER_CLIENT))
13744 {
13745 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13746 VTY_NEWLINE);
13747 return CMD_WARNING;
13748 }
13749
13750 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
13751 (argc == 3) ? argv[2] : argv[1],
b05a1c8b 13752 AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, 0);
fee0f4c6 13753}
13754
13755ALIAS (show_bgp_view_rsclient_prefix,
13756 show_bgp_rsclient_prefix_cmd,
a80beece 13757 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
fee0f4c6 13758 SHOW_STR
13759 BGP_STR
13760 "Information about Route Server Client\n"
a80beece 13761 NEIGHBOR_ADDR_STR3
fee0f4c6 13762 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
13763
95cbbd2a
ML
13764DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
13765 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
a80beece 13766 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
95cbbd2a
ML
13767 SHOW_STR
13768 BGP_STR
13769 "BGP view\n"
2b00515a 13770 "View name\n"
95cbbd2a
ML
13771 "Address family\n"
13772 "Address Family modifier\n"
13773 "Address Family modifier\n"
13774 "Information about Route Server Client\n"
a80beece 13775 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13776 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
13777{
13778 struct bgp *bgp;
13779 struct peer *peer;
13780 safi_t safi;
13781
13782 /* BGP structure lookup. */
13783 if (argc == 4)
13784 {
13785 bgp = bgp_lookup_by_name (argv[0]);
13786 if (bgp == NULL)
13787 {
13788 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13789 return CMD_WARNING;
13790 }
13791 }
13792 else
13793 {
13794 bgp = bgp_get_default ();
13795 if (bgp == NULL)
13796 {
13797 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13798 return CMD_WARNING;
13799 }
13800 }
13801
13802 if (argc == 4) {
13803 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13804 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13805 } else {
13806 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13807 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13808 }
13809
13810 if (! peer)
13811 return CMD_WARNING;
13812
13813 if (! peer->afc[AFI_IP6][safi])
13814 {
13815 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13816 VTY_NEWLINE);
13817 return CMD_WARNING;
13818}
13819
13820 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
13821 PEER_FLAG_RSERVER_CLIENT))
13822{
13823 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13824 VTY_NEWLINE);
13825 return CMD_WARNING;
13826 }
13827
13828 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
13829 (argc == 4) ? argv[3] : argv[2],
b05a1c8b 13830 AFI_IP6, safi, NULL, 1, BGP_PATH_ALL, 0);
95cbbd2a
ML
13831}
13832
13833ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
13834 show_bgp_ipv6_safi_rsclient_prefix_cmd,
a80beece 13835 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
95cbbd2a
ML
13836 SHOW_STR
13837 BGP_STR
13838 "Address family\n"
13839 "Address Family modifier\n"
13840 "Address Family modifier\n"
13841 "Information about Route Server Client\n"
a80beece 13842 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13843 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
13844
718e3744 13845#endif /* HAVE_IPV6 */
6b0655a2 13846
718e3744 13847struct bgp_table *bgp_distance_table;
13848
13849struct bgp_distance
13850{
13851 /* Distance value for the IP source prefix. */
13852 u_char distance;
13853
13854 /* Name of the access-list to be matched. */
13855 char *access_list;
13856};
13857
94f2b392 13858static struct bgp_distance *
66e5cd87 13859bgp_distance_new (void)
718e3744 13860{
393deb9b 13861 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
718e3744 13862}
13863
94f2b392 13864static void
718e3744 13865bgp_distance_free (struct bgp_distance *bdistance)
13866{
13867 XFREE (MTYPE_BGP_DISTANCE, bdistance);
13868}
13869
94f2b392 13870static int
fd79ac91 13871bgp_distance_set (struct vty *vty, const char *distance_str,
13872 const char *ip_str, const char *access_list_str)
718e3744 13873{
13874 int ret;
13875 struct prefix_ipv4 p;
13876 u_char distance;
13877 struct bgp_node *rn;
13878 struct bgp_distance *bdistance;
13879
13880 ret = str2prefix_ipv4 (ip_str, &p);
13881 if (ret == 0)
13882 {
13883 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13884 return CMD_WARNING;
13885 }
13886
13887 distance = atoi (distance_str);
13888
13889 /* Get BGP distance node. */
13890 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
13891 if (rn->info)
13892 {
13893 bdistance = rn->info;
13894 bgp_unlock_node (rn);
13895 }
13896 else
13897 {
13898 bdistance = bgp_distance_new ();
13899 rn->info = bdistance;
13900 }
13901
13902 /* Set distance value. */
13903 bdistance->distance = distance;
13904
13905 /* Reset access-list configuration. */
13906 if (bdistance->access_list)
13907 {
13908 free (bdistance->access_list);
13909 bdistance->access_list = NULL;
13910 }
13911 if (access_list_str)
13912 bdistance->access_list = strdup (access_list_str);
13913
13914 return CMD_SUCCESS;
13915}
13916
94f2b392 13917static int
fd79ac91 13918bgp_distance_unset (struct vty *vty, const char *distance_str,
13919 const char *ip_str, const char *access_list_str)
718e3744 13920{
13921 int ret;
13922 struct prefix_ipv4 p;
13923 u_char distance;
13924 struct bgp_node *rn;
13925 struct bgp_distance *bdistance;
13926
13927 ret = str2prefix_ipv4 (ip_str, &p);
13928 if (ret == 0)
13929 {
13930 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13931 return CMD_WARNING;
13932 }
13933
13934 distance = atoi (distance_str);
13935
13936 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
13937 if (! rn)
13938 {
13939 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
13940 return CMD_WARNING;
13941 }
13942
13943 bdistance = rn->info;
13944
13945 if (bdistance->access_list)
13946 free (bdistance->access_list);
13947 bgp_distance_free (bdistance);
13948
13949 rn->info = NULL;
13950 bgp_unlock_node (rn);
13951 bgp_unlock_node (rn);
13952
13953 return CMD_SUCCESS;
13954}
13955
718e3744 13956/* Apply BGP information to distance method. */
13957u_char
13958bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
13959{
13960 struct bgp_node *rn;
13961 struct prefix_ipv4 q;
13962 struct peer *peer;
13963 struct bgp_distance *bdistance;
13964 struct access_list *alist;
13965 struct bgp_static *bgp_static;
13966
13967 if (! bgp)
13968 return 0;
13969
13970 if (p->family != AF_INET)
13971 return 0;
13972
13973 peer = rinfo->peer;
13974
13975 if (peer->su.sa.sa_family != AF_INET)
13976 return 0;
13977
13978 memset (&q, 0, sizeof (struct prefix_ipv4));
13979 q.family = AF_INET;
13980 q.prefix = peer->su.sin.sin_addr;
13981 q.prefixlen = IPV4_MAX_BITLEN;
13982
13983 /* Check source address. */
13984 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
13985 if (rn)
13986 {
13987 bdistance = rn->info;
13988 bgp_unlock_node (rn);
13989
13990 if (bdistance->access_list)
13991 {
13992 alist = access_list_lookup (AFI_IP, bdistance->access_list);
13993 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
13994 return bdistance->distance;
13995 }
13996 else
13997 return bdistance->distance;
13998 }
13999
14000 /* Backdoor check. */
14001 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
14002 if (rn)
14003 {
14004 bgp_static = rn->info;
14005 bgp_unlock_node (rn);
14006
14007 if (bgp_static->backdoor)
14008 {
14009 if (bgp->distance_local)
14010 return bgp->distance_local;
14011 else
14012 return ZEBRA_IBGP_DISTANCE_DEFAULT;
14013 }
14014 }
14015
6d85b15b 14016 if (peer->sort == BGP_PEER_EBGP)
718e3744 14017 {
14018 if (bgp->distance_ebgp)
14019 return bgp->distance_ebgp;
14020 return ZEBRA_EBGP_DISTANCE_DEFAULT;
14021 }
14022 else
14023 {
14024 if (bgp->distance_ibgp)
14025 return bgp->distance_ibgp;
14026 return ZEBRA_IBGP_DISTANCE_DEFAULT;
14027 }
14028}
14029
14030DEFUN (bgp_distance,
14031 bgp_distance_cmd,
14032 "distance bgp <1-255> <1-255> <1-255>",
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 = atoi (argv[0]);
14044 bgp->distance_ibgp = atoi (argv[1]);
14045 bgp->distance_local = atoi (argv[2]);
14046 return CMD_SUCCESS;
14047}
14048
14049DEFUN (no_bgp_distance,
14050 no_bgp_distance_cmd,
14051 "no distance bgp <1-255> <1-255> <1-255>",
14052 NO_STR
14053 "Define an administrative distance\n"
14054 "BGP distance\n"
14055 "Distance for routes external to the AS\n"
14056 "Distance for routes internal to the AS\n"
14057 "Distance for local routes\n")
14058{
14059 struct bgp *bgp;
14060
14061 bgp = vty->index;
14062
14063 bgp->distance_ebgp= 0;
14064 bgp->distance_ibgp = 0;
14065 bgp->distance_local = 0;
14066 return CMD_SUCCESS;
14067}
14068
14069ALIAS (no_bgp_distance,
14070 no_bgp_distance2_cmd,
14071 "no distance bgp",
14072 NO_STR
14073 "Define an administrative distance\n"
14074 "BGP distance\n")
14075
14076DEFUN (bgp_distance_source,
14077 bgp_distance_source_cmd,
14078 "distance <1-255> A.B.C.D/M",
14079 "Define an administrative distance\n"
14080 "Administrative distance\n"
14081 "IP source prefix\n")
14082{
14083 bgp_distance_set (vty, argv[0], argv[1], NULL);
14084 return CMD_SUCCESS;
14085}
14086
14087DEFUN (no_bgp_distance_source,
14088 no_bgp_distance_source_cmd,
14089 "no distance <1-255> A.B.C.D/M",
14090 NO_STR
14091 "Define an administrative distance\n"
14092 "Administrative distance\n"
14093 "IP source prefix\n")
14094{
14095 bgp_distance_unset (vty, argv[0], argv[1], NULL);
14096 return CMD_SUCCESS;
14097}
14098
14099DEFUN (bgp_distance_source_access_list,
14100 bgp_distance_source_access_list_cmd,
14101 "distance <1-255> A.B.C.D/M WORD",
14102 "Define an administrative distance\n"
14103 "Administrative distance\n"
14104 "IP source prefix\n"
14105 "Access list name\n")
14106{
14107 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
14108 return CMD_SUCCESS;
14109}
14110
14111DEFUN (no_bgp_distance_source_access_list,
14112 no_bgp_distance_source_access_list_cmd,
14113 "no distance <1-255> A.B.C.D/M WORD",
14114 NO_STR
14115 "Define an administrative distance\n"
14116 "Administrative distance\n"
14117 "IP source prefix\n"
14118 "Access list name\n")
14119{
14120 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
14121 return CMD_SUCCESS;
14122}
6b0655a2 14123
718e3744 14124DEFUN (bgp_damp_set,
14125 bgp_damp_set_cmd,
14126 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14127 "BGP Specific commands\n"
14128 "Enable route-flap dampening\n"
14129 "Half-life time for the penalty\n"
14130 "Value to start reusing a route\n"
14131 "Value to start suppressing a route\n"
14132 "Maximum duration to suppress a stable route\n")
14133{
14134 struct bgp *bgp;
14135 int half = DEFAULT_HALF_LIFE * 60;
14136 int reuse = DEFAULT_REUSE;
14137 int suppress = DEFAULT_SUPPRESS;
14138 int max = 4 * half;
14139
14140 if (argc == 4)
14141 {
14142 half = atoi (argv[0]) * 60;
14143 reuse = atoi (argv[1]);
14144 suppress = atoi (argv[2]);
14145 max = atoi (argv[3]) * 60;
14146 }
14147 else if (argc == 1)
14148 {
14149 half = atoi (argv[0]) * 60;
14150 max = 4 * half;
14151 }
14152
14153 bgp = vty->index;
14154 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
14155 half, reuse, suppress, max);
14156}
14157
14158ALIAS (bgp_damp_set,
14159 bgp_damp_set2_cmd,
14160 "bgp dampening <1-45>",
14161 "BGP Specific commands\n"
14162 "Enable route-flap dampening\n"
14163 "Half-life time for the penalty\n")
14164
14165ALIAS (bgp_damp_set,
14166 bgp_damp_set3_cmd,
14167 "bgp dampening",
14168 "BGP Specific commands\n"
14169 "Enable route-flap dampening\n")
14170
14171DEFUN (bgp_damp_unset,
14172 bgp_damp_unset_cmd,
14173 "no bgp dampening",
14174 NO_STR
14175 "BGP Specific commands\n"
14176 "Enable route-flap dampening\n")
14177{
14178 struct bgp *bgp;
14179
14180 bgp = vty->index;
14181 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
14182}
14183
14184ALIAS (bgp_damp_unset,
14185 bgp_damp_unset2_cmd,
14186 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14187 NO_STR
14188 "BGP Specific commands\n"
14189 "Enable route-flap dampening\n"
14190 "Half-life time for the penalty\n"
14191 "Value to start reusing a route\n"
14192 "Value to start suppressing a route\n"
14193 "Maximum duration to suppress a stable route\n")
14194
14195DEFUN (show_ip_bgp_dampened_paths,
14196 show_ip_bgp_dampened_paths_cmd,
14197 "show ip bgp dampened-paths",
14198 SHOW_STR
14199 IP_STR
14200 BGP_STR
14201 "Display paths suppressed due to dampening\n")
14202{
5a646650 14203 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
b05a1c8b 14204 NULL, 0);
718e3744 14205}
14206
14207DEFUN (show_ip_bgp_flap_statistics,
14208 show_ip_bgp_flap_statistics_cmd,
14209 "show ip bgp flap-statistics",
14210 SHOW_STR
14211 IP_STR
14212 BGP_STR
14213 "Display flap statistics of routes\n")
14214{
5a646650 14215 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
b05a1c8b 14216 bgp_show_type_flap_statistics, NULL, 0);
718e3744 14217}
6b0655a2 14218
718e3744 14219/* Display specified route of BGP table. */
94f2b392 14220static int
fd79ac91 14221bgp_clear_damp_route (struct vty *vty, const char *view_name,
14222 const char *ip_str, afi_t afi, safi_t safi,
14223 struct prefix_rd *prd, int prefix_check)
718e3744 14224{
14225 int ret;
14226 struct prefix match;
14227 struct bgp_node *rn;
14228 struct bgp_node *rm;
14229 struct bgp_info *ri;
14230 struct bgp_info *ri_temp;
14231 struct bgp *bgp;
14232 struct bgp_table *table;
14233
14234 /* BGP structure lookup. */
14235 if (view_name)
14236 {
14237 bgp = bgp_lookup_by_name (view_name);
14238 if (bgp == NULL)
14239 {
14240 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
14241 return CMD_WARNING;
14242 }
14243 }
14244 else
14245 {
14246 bgp = bgp_get_default ();
14247 if (bgp == NULL)
14248 {
14249 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
14250 return CMD_WARNING;
14251 }
14252 }
14253
14254 /* Check IP address argument. */
14255 ret = str2prefix (ip_str, &match);
14256 if (! ret)
14257 {
14258 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
14259 return CMD_WARNING;
14260 }
14261
14262 match.family = afi2family (afi);
14263
14264 if (safi == SAFI_MPLS_VPN)
14265 {
14266 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
14267 {
14268 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
14269 continue;
14270
14271 if ((table = rn->info) != NULL)
14272 if ((rm = bgp_node_match (table, &match)) != NULL)
6c88b44d
CC
14273 {
14274 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
14275 {
14276 ri = rm->info;
14277 while (ri)
14278 {
14279 if (ri->extra && ri->extra->damp_info)
14280 {
14281 ri_temp = ri->next;
14282 bgp_damp_info_free (ri->extra->damp_info, 1);
14283 ri = ri_temp;
14284 }
14285 else
14286 ri = ri->next;
14287 }
14288 }
14289
14290 bgp_unlock_node (rm);
14291 }
718e3744 14292 }
14293 }
14294 else
14295 {
14296 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
6c88b44d
CC
14297 {
14298 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
14299 {
14300 ri = rn->info;
14301 while (ri)
14302 {
14303 if (ri->extra && ri->extra->damp_info)
14304 {
14305 ri_temp = ri->next;
14306 bgp_damp_info_free (ri->extra->damp_info, 1);
14307 ri = ri_temp;
14308 }
14309 else
14310 ri = ri->next;
14311 }
14312 }
14313
14314 bgp_unlock_node (rn);
14315 }
718e3744 14316 }
14317
14318 return CMD_SUCCESS;
14319}
14320
14321DEFUN (clear_ip_bgp_dampening,
14322 clear_ip_bgp_dampening_cmd,
14323 "clear ip bgp dampening",
14324 CLEAR_STR
14325 IP_STR
14326 BGP_STR
14327 "Clear route flap dampening information\n")
14328{
14329 bgp_damp_info_clean ();
14330 return CMD_SUCCESS;
14331}
14332
14333DEFUN (clear_ip_bgp_dampening_prefix,
14334 clear_ip_bgp_dampening_prefix_cmd,
14335 "clear ip bgp dampening A.B.C.D/M",
14336 CLEAR_STR
14337 IP_STR
14338 BGP_STR
14339 "Clear route flap dampening information\n"
14340 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14341{
14342 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14343 SAFI_UNICAST, NULL, 1);
14344}
14345
14346DEFUN (clear_ip_bgp_dampening_address,
14347 clear_ip_bgp_dampening_address_cmd,
14348 "clear ip bgp dampening A.B.C.D",
14349 CLEAR_STR
14350 IP_STR
14351 BGP_STR
14352 "Clear route flap dampening information\n"
14353 "Network to clear damping information\n")
14354{
14355 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14356 SAFI_UNICAST, NULL, 0);
14357}
14358
14359DEFUN (clear_ip_bgp_dampening_address_mask,
14360 clear_ip_bgp_dampening_address_mask_cmd,
14361 "clear ip bgp dampening A.B.C.D A.B.C.D",
14362 CLEAR_STR
14363 IP_STR
14364 BGP_STR
14365 "Clear route flap dampening information\n"
14366 "Network to clear damping information\n"
14367 "Network mask\n")
14368{
14369 int ret;
14370 char prefix_str[BUFSIZ];
14371
14372 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
14373 if (! ret)
14374 {
14375 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
14376 return CMD_WARNING;
14377 }
14378
14379 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
14380 SAFI_UNICAST, NULL, 0);
14381}
6b0655a2 14382
94f2b392 14383static int
718e3744 14384bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
14385 afi_t afi, safi_t safi, int *write)
14386{
14387 struct bgp_node *prn;
14388 struct bgp_node *rn;
14389 struct bgp_table *table;
14390 struct prefix *p;
14391 struct prefix_rd *prd;
14392 struct bgp_static *bgp_static;
14393 u_int32_t label;
14394 char buf[SU_ADDRSTRLEN];
14395 char rdbuf[RD_ADDRSTRLEN];
14396
14397 /* Network configuration. */
14398 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
14399 if ((table = prn->info) != NULL)
14400 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
14401 if ((bgp_static = rn->info) != NULL)
14402 {
14403 p = &rn->p;
14404 prd = (struct prefix_rd *) &prn->p;
14405
14406 /* "address-family" display. */
14407 bgp_config_write_family_header (vty, afi, safi, write);
14408
14409 /* "network" configuration display. */
14410 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
14411 label = decode_label (bgp_static->tag);
14412
14413 vty_out (vty, " network %s/%d rd %s tag %d",
14414 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14415 p->prefixlen,
14416 rdbuf, label);
14417 vty_out (vty, "%s", VTY_NEWLINE);
14418 }
14419 return 0;
14420}
14421
14422/* Configuration of static route announcement and aggregate
14423 information. */
14424int
14425bgp_config_write_network (struct vty *vty, struct bgp *bgp,
14426 afi_t afi, safi_t safi, int *write)
14427{
14428 struct bgp_node *rn;
14429 struct prefix *p;
14430 struct bgp_static *bgp_static;
14431 struct bgp_aggregate *bgp_aggregate;
14432 char buf[SU_ADDRSTRLEN];
14433
14434 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
14435 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
14436
14437 /* Network configuration. */
14438 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
14439 if ((bgp_static = rn->info) != NULL)
14440 {
14441 p = &rn->p;
14442
14443 /* "address-family" display. */
14444 bgp_config_write_family_header (vty, afi, safi, write);
14445
14446 /* "network" configuration display. */
14447 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14448 {
14449 u_int32_t destination;
14450 struct in_addr netmask;
14451
14452 destination = ntohl (p->u.prefix4.s_addr);
14453 masklen2ip (p->prefixlen, &netmask);
14454 vty_out (vty, " network %s",
14455 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
14456
14457 if ((IN_CLASSC (destination) && p->prefixlen == 24)
14458 || (IN_CLASSB (destination) && p->prefixlen == 16)
14459 || (IN_CLASSA (destination) && p->prefixlen == 8)
14460 || p->u.prefix4.s_addr == 0)
14461 {
14462 /* Natural mask is not display. */
14463 }
14464 else
14465 vty_out (vty, " mask %s", inet_ntoa (netmask));
14466 }
14467 else
14468 {
14469 vty_out (vty, " network %s/%d",
14470 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14471 p->prefixlen);
14472 }
14473
14474 if (bgp_static->rmap.name)
14475 vty_out (vty, " route-map %s", bgp_static->rmap.name);
41367172
PJ
14476 else
14477 {
14478 if (bgp_static->backdoor)
14479 vty_out (vty, " backdoor");
41367172 14480 }
718e3744 14481
14482 vty_out (vty, "%s", VTY_NEWLINE);
14483 }
14484
14485 /* Aggregate-address configuration. */
14486 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
14487 if ((bgp_aggregate = rn->info) != NULL)
14488 {
14489 p = &rn->p;
14490
14491 /* "address-family" display. */
14492 bgp_config_write_family_header (vty, afi, safi, write);
14493
14494 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14495 {
14496 struct in_addr netmask;
14497
14498 masklen2ip (p->prefixlen, &netmask);
14499 vty_out (vty, " aggregate-address %s %s",
14500 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14501 inet_ntoa (netmask));
14502 }
14503 else
14504 {
14505 vty_out (vty, " aggregate-address %s/%d",
14506 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14507 p->prefixlen);
14508 }
14509
14510 if (bgp_aggregate->as_set)
14511 vty_out (vty, " as-set");
14512
14513 if (bgp_aggregate->summary_only)
14514 vty_out (vty, " summary-only");
14515
14516 vty_out (vty, "%s", VTY_NEWLINE);
14517 }
14518
14519 return 0;
14520}
14521
14522int
14523bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
14524{
14525 struct bgp_node *rn;
14526 struct bgp_distance *bdistance;
14527
14528 /* Distance configuration. */
14529 if (bgp->distance_ebgp
14530 && bgp->distance_ibgp
14531 && bgp->distance_local
14532 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
14533 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
14534 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
14535 vty_out (vty, " distance bgp %d %d %d%s",
14536 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
14537 VTY_NEWLINE);
14538
14539 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
14540 if ((bdistance = rn->info) != NULL)
14541 {
14542 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
14543 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
14544 bdistance->access_list ? bdistance->access_list : "",
14545 VTY_NEWLINE);
14546 }
14547
14548 return 0;
14549}
14550
14551/* Allocate routing table structure and install commands. */
14552void
66e5cd87 14553bgp_route_init (void)
718e3744 14554{
14555 /* Init BGP distance table. */
64e580a7 14556 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
718e3744 14557
14558 /* IPv4 BGP commands. */
73ac8160 14559 install_element (BGP_NODE, &bgp_table_map_cmd);
718e3744 14560 install_element (BGP_NODE, &bgp_network_cmd);
14561 install_element (BGP_NODE, &bgp_network_mask_cmd);
14562 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
14563 install_element (BGP_NODE, &bgp_network_route_map_cmd);
14564 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
14565 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
14566 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
14567 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
14568 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
73ac8160 14569 install_element (BGP_NODE, &no_bgp_table_map_cmd);
718e3744 14570 install_element (BGP_NODE, &no_bgp_network_cmd);
14571 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
14572 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
14573 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
14574 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
14575 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14576 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
14577 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
14578 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
14579
14580 install_element (BGP_NODE, &aggregate_address_cmd);
14581 install_element (BGP_NODE, &aggregate_address_mask_cmd);
14582 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
14583 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
14584 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
14585 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
14586 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
14587 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
14588 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
14589 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
14590 install_element (BGP_NODE, &no_aggregate_address_cmd);
14591 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
14592 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
14593 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
14594 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
14595 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
14596 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
14597 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
14598 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14599 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14600
14601 /* IPv4 unicast configuration. */
73ac8160 14602 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
718e3744 14603 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
14604 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
14605 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
14606 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
14607 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
14608 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 14609 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
c8f3fe30 14610 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
718e3744 14611 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
14612 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
14613 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
14614 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
14615 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
c8f3fe30 14616
718e3744 14617 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
14618 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
14619 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
14620 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
14621 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
14622 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
14623 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
14624 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
14625 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
14626 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
14627 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
14628 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
14629 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
14630 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
14631 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
14632 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
14633 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
14634 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
14635 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14636 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14637
14638 /* IPv4 multicast configuration. */
73ac8160 14639 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
718e3744 14640 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
14641 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
14642 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
14643 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
14644 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
14645 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 14646 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
718e3744 14647 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
14648 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
14649 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
14650 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
14651 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
14652 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14653 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
14654 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
14655 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
14656 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
14657 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
14658 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
14659 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
14660 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
14661 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
14662 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
14663 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
14664 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
14665 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
14666 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
14667 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
14668 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
14669 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
14670 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
14671 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14672 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14673
14674 install_element (VIEW_NODE, &show_ip_bgp_cmd);
14675 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 14676 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
718e3744 14677 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
14678 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
14679 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 14680 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 14681 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 14682 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14683 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14684 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
14685 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
14686 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14687 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 14688 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 14689 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
718e3744 14690 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14691 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14692 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
14693 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
14694 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
14695 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
14696 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14697 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
14698 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14699 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
14700 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14701 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
14702 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14703 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
14704 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14705 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
14706 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14707 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
14708 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
14709 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
14710 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
14711 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
14712 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
14713 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
14714 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
14715 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
14716 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
14717 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
14718 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
14719 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
718e3744 14720 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
14721 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
14722 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
14723 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
14724 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14725 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14726 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14727 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14728 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
14729 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14730 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
14731 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14732 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
14733 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14734 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
0b16f239 14735 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
718e3744 14736 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
0b16f239 14737 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
718e3744 14738 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
0b16f239 14739 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
718e3744 14740 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
0b16f239 14741 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
95cbbd2a 14742 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 14743 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
14744 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14745 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14746 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14747 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
14748 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
14749 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
14750 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
14751 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14752 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
14753 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
14754 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14755 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14756 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
14757 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
14758 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
fee0f4c6 14759 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
95cbbd2a 14760 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
fee0f4c6 14761 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 14762 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
fee0f4c6 14763 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 14764 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
2a71e9ce
TP
14765 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
14766 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
fee0f4c6 14767 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
95cbbd2a 14768 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
fee0f4c6 14769 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 14770 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
fee0f4c6 14771 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 14772 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
62687ff1
PJ
14773
14774 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
14775 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
14776 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
14777 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
62687ff1 14778 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 14779 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
62687ff1
PJ
14780 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14781 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
14782 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
14783 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14784 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 14785 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 14786 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
62687ff1
PJ
14787 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14788 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14789 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
14790 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
14791 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
14792 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
14793 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
14794 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
14795 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
14796 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
14797 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
14798 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
14799 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
14800 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
14801 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
14802 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
14803 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
62687ff1
PJ
14804 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
14805 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
14806 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
14807 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
14808 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14809 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14810 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14811 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14812 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 14813 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
62687ff1 14814 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 14815 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
62687ff1 14816 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 14817 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
62687ff1 14818 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 14819 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
718e3744 14820
14821 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
14822 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 14823 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
718e3744 14824 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
14825 install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd);
14826 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 14827 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 14828 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 14829 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14830 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14831 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
14832 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
14833 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14834 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 14835 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 14836 install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd);
718e3744 14837 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14838 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14839 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
14840 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
14841 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
14842 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
14843 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14844 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
14845 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14846 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
14847 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14848 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
14849 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14850 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
14851 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14852 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
14853 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14854 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
14855 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
14856 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
14857 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
14858 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
14859 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
14860 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
14861 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
14862 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
14863 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
14864 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
14865 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
14866 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
718e3744 14867 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
14868 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
14869 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
14870 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
14871 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14872 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14873 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14874 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14875 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
14876 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14877 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
14878 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14879 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
14880 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14881 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
0b16f239 14882 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
718e3744 14883 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
0b16f239 14884 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
718e3744 14885 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
0b16f239 14886 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
718e3744 14887 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
0b16f239 14888 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
95cbbd2a 14889 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 14890 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
14891 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14892 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14893 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14894 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
14895 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
14896 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
14897 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
14898 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14899 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
14900 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
14901 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14902 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14903 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
14904 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
14905 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
fee0f4c6 14906 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
95cbbd2a 14907 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
fee0f4c6 14908 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 14909 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
fee0f4c6 14910 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 14911 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
2a71e9ce
TP
14912 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
14913 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
fee0f4c6 14914 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
95cbbd2a 14915 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
fee0f4c6 14916 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 14917 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
fee0f4c6 14918 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 14919 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
718e3744 14920
14921 /* BGP dampening clear commands */
14922 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
14923 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
14924 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
14925 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
14926
ff7924f6
PJ
14927 /* prefix count */
14928 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
14929 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
14930 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
718e3744 14931#ifdef HAVE_IPV6
ff7924f6
PJ
14932 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
14933
718e3744 14934 /* New config IPv6 BGP commands. */
73ac8160 14935 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
718e3744 14936 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
14937 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
73ac8160 14938 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
718e3744 14939 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
14940 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
14941
14942 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
14943 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
14944 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
14945 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
73bfe0bd
B
14946
14947 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
14948 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
718e3744 14949
14950 /* Old config IPv6 BGP commands. */
14951 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
14952 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
14953
14954 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
14955 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
14956 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
14957 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
14958
14959 install_element (VIEW_NODE, &show_bgp_cmd);
14960 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 14961 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 14962 install_element (VIEW_NODE, &show_bgp_route_cmd);
14963 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 14964 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
14965 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
14966 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14967 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 14968 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
14969 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 14970 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c
DS
14971 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
14972 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14973 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 14974 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
14975 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
14976 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
14977 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
14978 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
14979 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
14980 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
14981 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
14982 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
14983 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
14984 install_element (VIEW_NODE, &show_bgp_community_cmd);
14985 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
14986 install_element (VIEW_NODE, &show_bgp_community2_cmd);
14987 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
14988 install_element (VIEW_NODE, &show_bgp_community3_cmd);
14989 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
14990 install_element (VIEW_NODE, &show_bgp_community4_cmd);
14991 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
14992 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
14993 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
14994 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
14995 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
14996 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
14997 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
14998 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
14999 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
15000 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
15001 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
15002 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
15003 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
15004 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
15005 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
15006 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
15007 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
15008 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
15009 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
15010 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
15011 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
15012 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
15013 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 15014 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
15015 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
15016 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
15017 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
fee0f4c6 15018 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
95cbbd2a 15019 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
fee0f4c6 15020 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 15021 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
fee0f4c6 15022 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 15023 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
bb46e94f 15024 install_element (VIEW_NODE, &show_bgp_view_cmd);
15025 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
15026 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
15027 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
15028 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
15029 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
15030 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
15031 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
15032 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
15033 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
15034 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
15035 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
15036 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
15037 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
15038 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
15039 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
15040 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
15041 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
fee0f4c6 15042 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
95cbbd2a 15043 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
fee0f4c6 15044 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 15045 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
fee0f4c6 15046 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 15047 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
62687ff1
PJ
15048
15049 /* Restricted:
15050 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
15051 */
15052 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
15053 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 15054 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
15055 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
15056 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
15057 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
62687ff1
PJ
15058 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
15059 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 15060 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c
DS
15061 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
15062 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
15063 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
62687ff1
PJ
15064 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
15065 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
15066 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
15067 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
15068 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
15069 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
15070 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
15071 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
15072 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
15073 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
15074 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
15075 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
15076 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
15077 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
15078 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
15079 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
15080 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 15081 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
62687ff1 15082 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 15083 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
62687ff1
PJ
15084 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
15085 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
15086 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
15087 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
15088 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
15089 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
15090 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 15091 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
62687ff1 15092 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 15093 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
718e3744 15094
15095 install_element (ENABLE_NODE, &show_bgp_cmd);
15096 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 15097 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 15098 install_element (ENABLE_NODE, &show_bgp_route_cmd);
15099 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 15100 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
15101 install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd);
15102 install_element (ENABLE_NODE, &show_bgp_ipv6_route_pathtype_cmd);
15103 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 15104 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
4092b06c
DS
15105 install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd);
15106 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
15107 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 15108 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 15109 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
718e3744 15110 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
15111 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
15112 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
15113 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
15114 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
15115 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
15116 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
15117 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
15118 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
15119 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
15120 install_element (ENABLE_NODE, &show_bgp_community_cmd);
15121 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
15122 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
15123 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
15124 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
15125 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
15126 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
15127 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
15128 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
15129 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
15130 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
15131 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
15132 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
15133 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
15134 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
15135 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
15136 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
15137 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
15138 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
15139 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
15140 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
15141 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
15142 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
15143 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
15144 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
15145 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
15146 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
15147 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
15148 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
15149 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 15150 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
15151 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
15152 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
15153 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
fee0f4c6 15154 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
95cbbd2a 15155 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
fee0f4c6 15156 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 15157 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
fee0f4c6 15158 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 15159 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
bb46e94f 15160 install_element (ENABLE_NODE, &show_bgp_view_cmd);
15161 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
15162 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
15163 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
15164 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
15165 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
15166 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
15167 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
15168 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
15169 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
15170 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
15171 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
15172 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
15173 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
15174 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
15175 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
15176 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
15177 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
fee0f4c6 15178 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
95cbbd2a 15179 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
fee0f4c6 15180 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 15181 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
fee0f4c6 15182 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 15183 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
2815e61f
PJ
15184
15185 /* Statistics */
15186 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
15187 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
15188 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
15189 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
15190
718e3744 15191 /* old command */
15192 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
15193 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
15194 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
15195 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
15196 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
15197 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
15198 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
15199 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
15200 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
15201 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
15202 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
15203 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
15204 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
15205 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
15206 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
15207 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
15208 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15209 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15210 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
15211 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
15212 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
15213 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
15214 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15215 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
15216 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
15217 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
15218 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
15219 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
15220 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
15221 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
15222 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
15223 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
15224 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
15225 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
15226 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15227 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
bb46e94f 15228
718e3744 15229 /* old command */
15230 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
15231 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
15232 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
15233 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
15234 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
15235 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
15236 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
15237 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
15238 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
15239 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
15240 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
15241 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
15242 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
15243 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
15244 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
15245 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
15246 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15247 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15248 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
15249 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
15250 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
15251 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
15252 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15253 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
15254 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
15255 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
15256 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
15257 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
15258 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
15259 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
15260 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
15261 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
15262 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
15263 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
15264 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15265 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
15266
15267 /* old command */
15268 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
15269 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
15270 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
15271 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
15272
15273 /* old command */
15274 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
15275 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
15276 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
15277 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
15278
15279 /* old command */
15280 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
15281 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
15282 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
15283 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
15284#endif /* HAVE_IPV6 */
15285
15286 install_element (BGP_NODE, &bgp_distance_cmd);
15287 install_element (BGP_NODE, &no_bgp_distance_cmd);
15288 install_element (BGP_NODE, &no_bgp_distance2_cmd);
15289 install_element (BGP_NODE, &bgp_distance_source_cmd);
15290 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
15291 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
15292 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
15293
15294 install_element (BGP_NODE, &bgp_damp_set_cmd);
15295 install_element (BGP_NODE, &bgp_damp_set2_cmd);
15296 install_element (BGP_NODE, &bgp_damp_set3_cmd);
15297 install_element (BGP_NODE, &bgp_damp_unset_cmd);
15298 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
15299 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
15300 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
15301 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
15302 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
15303 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
c8f3fe30
PJ
15304
15305 /* Deprecated AS-Pathlimit commands */
15306 install_element (BGP_NODE, &bgp_network_ttl_cmd);
15307 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
15308 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
15309 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
15310 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
15311 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
15312
15313 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
15314 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
15315 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
15316 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
15317 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
15318 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
15319
15320 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
15321 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
15322 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
15323 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
15324 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
15325 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
15326
15327 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
15328 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
15329 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
15330 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
15331 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
15332 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
15333
15334 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
15335 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
15336 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
15337 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
15338 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
15339 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
15340
15341 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
15342 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
15343 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
15344 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
15345 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
15346 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
3bde17f1
PJ
15347
15348#ifdef HAVE_IPV6
c8f3fe30
PJ
15349 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
15350 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
3bde17f1 15351#endif
718e3744 15352}
228da428
CC
15353
15354void
15355bgp_route_finish (void)
15356{
15357 bgp_table_unlock (bgp_distance_table);
15358 bgp_distance_table = NULL;
15359}