]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_route.c
BGP: Add dynamic update group support
[mirror_frr.git] / bgpd / bgp_route.c
CommitLineData
718e3744 1/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "linklist.h"
25#include "memory.h"
26#include "command.h"
27#include "stream.h"
28#include "filter.h"
29#include "str.h"
30#include "log.h"
31#include "routemap.h"
32#include "buffer.h"
33#include "sockunion.h"
34#include "plist.h"
35#include "thread.h"
200df115 36#include "workqueue.h"
3f9c7369 37#include "queue.h"
718e3744 38
39#include "bgpd/bgpd.h"
40#include "bgpd/bgp_table.h"
41#include "bgpd/bgp_route.h"
42#include "bgpd/bgp_attr.h"
43#include "bgpd/bgp_debug.h"
44#include "bgpd/bgp_aspath.h"
45#include "bgpd/bgp_regex.h"
46#include "bgpd/bgp_community.h"
47#include "bgpd/bgp_ecommunity.h"
48#include "bgpd/bgp_clist.h"
49#include "bgpd/bgp_packet.h"
50#include "bgpd/bgp_filter.h"
51#include "bgpd/bgp_fsm.h"
52#include "bgpd/bgp_mplsvpn.h"
53#include "bgpd/bgp_nexthop.h"
54#include "bgpd/bgp_damp.h"
55#include "bgpd/bgp_advertise.h"
56#include "bgpd/bgp_zebra.h"
0a486e5f 57#include "bgpd/bgp_vty.h"
96450faf 58#include "bgpd/bgp_mpath.h"
fc9a856f 59#include "bgpd/bgp_nht.h"
3f9c7369 60#include "bgpd/bgp_updgrp.h"
718e3744 61
62/* Extern from bgp_dump.c */
dde72586
SH
63extern const char *bgp_origin_str[];
64extern const char *bgp_origin_long_str[];
47fc97cc 65char csv = ',';
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);
fb982c25 1144 attr->extra->mp_nexthop_len = 16;
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
PJ
1156 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1157 attr->extra->mp_nexthop_len=32;
fee0f4c6 1158 else
fb982c25 1159 attr->extra->mp_nexthop_len=16;
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. */
fb982c25 1166 attr->extra->mp_nexthop_len = 16;
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);
fb982c25 1174 attr->extra->mp_nexthop_len = 32;
718e3744 1175 }
1176
1177 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1178 address.*/
1179 if (reflect)
fb982c25 1180 attr->extra->mp_nexthop_len = 16;
718e3744 1181
1182 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1183 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
fb982c25 1184 attr->extra->mp_nexthop_len = 16;
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 {
1462 attr->extra->mp_nexthop_len = 16;
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)))
1469 attr->extra->mp_nexthop_len = 32;
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;
1496
1497 /*
1498 * The route reflector is not allowed to modify the attributes
1499 * of the reflected IBGP routes unless explicitly allowed.
1500 */
1501 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1502 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1503 {
1504 bgp_attr_dup (&dummy_attr, attr);
1505 info.attr = &dummy_attr;
1506 }
1507
1508 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1509
1510 if (ri->extra && ri->extra->suppress)
1511 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1512 else
1513 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1514
1515 peer->rmap_type = 0;
1516
1517 if (ret == RMAP_DENYMATCH)
1518 {
1519 bgp_attr_flush (attr);
1520 return 0;
1521 }
1522 }
1523
1524 /* After route-map has been applied, we check to see if the nexthop to
1525 * be carried in the attribute (that is used for the announcement) can
1526 * be cleared off or not. We do this in all cases where we would be
1527 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1528 * the global nexthop here; the link-local nexthop would have been cleared
1529 * already, and if not, it is required by the update formation code.
1530 * Also see earlier comments in this function.
1531 */
1532 if (!(CHECK_FLAG(attr->rmap_change_flags, BATTR_RMAP_NEXTHOP_CHANGED) ||
1533 transparent ||
1534 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)))
1535 {
1536 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF))
1537 {
1538 if (!reflect ||
1539 CHECK_FLAG (peer->af_flags[afi][safi],
1540 PEER_FLAG_FORCE_NEXTHOP_SELF))
1541 subgroup_announce_reset_nhop (p->family, attr);
1542 }
1543 else if (peer->sort == BGP_PEER_EBGP)
1544 {
1545 SUBGRP_FOREACH_PEER (subgrp, paf)
1546 {
1547 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1548 break;
1549 }
1550 if (!paf)
1551 subgroup_announce_reset_nhop (p->family, attr);
1552 }
1553 }
1554
1555 return 1;
1556}
1557
1558static int
1559bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1560 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
1561{
1562 int ret;
1563 char buf[SU_ADDRSTRLEN];
1564 struct bgp_filter *filter;
1565 struct bgp_info info;
1566 struct peer *from;
1567 struct attr *riattr;
1568
1569 from = ri->peer;
1570 filter = &rsclient->filter[afi][safi];
1571 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1572
1573 if (DISABLE_BGP_ANNOUNCE)
1574 return 0;
1575
1576 /* Do not send back route to sender. */
1577 if (from == rsclient)
1578 return 0;
1579
1580 /* Aggregate-address suppress check. */
1581 if (ri->extra && ri->extra->suppress)
1582 if (! UNSUPPRESS_MAP_NAME (filter))
1583 return 0;
1584
1585 /* Default route check. */
1586 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1587 PEER_STATUS_DEFAULT_ORIGINATE))
1588 {
1589 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1590 return 0;
1591#ifdef HAVE_IPV6
1592 else if (p->family == AF_INET6 && p->prefixlen == 0)
1593 return 0;
1594#endif /* HAVE_IPV6 */
1595 }
1596
1597 /* If the attribute has originator-id and it is same as remote
1598 peer's id. */
1599 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1600 {
1601 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1602 &riattr->extra->originator_id))
1603 {
1604 if (bgp_debug_update(rsclient, p, NULL, 0))
1605 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1606 rsclient->host,
1607 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1608 p->prefixlen);
1609 return 0;
1610 }
1611 }
1612
1613 /* ORF prefix-list filter check */
1614 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1615 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1616 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1617 if (rsclient->orf_plist[afi][safi])
1618 {
1619 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1620 return 0;
1621 }
1622
1623 /* Output filter check. */
1624 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
1625 {
1626 if (bgp_debug_update(rsclient, p, NULL, 0))
1627 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1628 rsclient->host,
1629 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1630 p->prefixlen);
1631 return 0;
1632 }
1633
1634#ifdef BGP_SEND_ASPATH_CHECK
1635 /* AS path loop check. */
1636 if (aspath_loop_check (riattr->aspath, rsclient->as))
1637 {
1638 if (bgp_debug_update(rsclient, p, NULL, 0))
1639 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
1640 rsclient->host, rsclient->as);
1641 return 0;
1642 }
1643#endif /* BGP_SEND_ASPATH_CHECK */
1644
1645 /* For modify attribute, copy it to temporary structure. */
1646 bgp_attr_dup (attr, riattr);
1647
1648 /* next-hop-set */
1649 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1650#ifdef HAVE_IPV6
1651 || (p->family == AF_INET6 &&
1652 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
1653#endif /* HAVE_IPV6 */
1654 )
1655 {
1656 /* Set IPv4 nexthop. */
1657 if (p->family == AF_INET)
1658 {
1659 if (safi == SAFI_MPLS_VPN)
1660 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
1661 IPV4_MAX_BYTELEN);
1662 else
1663 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1664 }
1665#ifdef HAVE_IPV6
1666 /* Set IPv6 nexthop. */
1667 if (p->family == AF_INET6)
1668 {
1669 /* IPv6 global nexthop must be included. */
1670 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
1671 IPV6_MAX_BYTELEN);
1672 attr->extra->mp_nexthop_len = 16;
1673 }
1674#endif /* HAVE_IPV6 */
1675 }
1676
1677#ifdef HAVE_IPV6
1678 if (p->family == AF_INET6)
1679 {
1680 struct attr_extra *attre = attr->extra;
1681
1682 /* Left nexthop_local unchanged if so configured. */
1683 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1684 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1685 {
1686 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1687 attre->mp_nexthop_len=32;
1688 else
1689 attre->mp_nexthop_len=16;
1690 }
1691
1692 /* Default nexthop_local treatment for RS-Clients */
1693 else
1694 {
1695 /* Announcer and RS-Client are both in the same network */
1696 if (rsclient->shared_network && from->shared_network &&
1697 (rsclient->ifindex == from->ifindex))
1698 {
1699 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1700 attre->mp_nexthop_len=32;
1701 else
1702 attre->mp_nexthop_len=16;
1703 }
1704
1705 /* Set link-local address for shared network peer. */
1706 else if (rsclient->shared_network
1707 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1708 {
1709 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
1710 IPV6_MAX_BYTELEN);
1711 attre->mp_nexthop_len = 32;
1712 }
1713
1714 else
1715 attre->mp_nexthop_len = 16;
1716 }
1717
1718 }
1719#endif /* HAVE_IPV6 */
1720
1721
1722 /* If this is EBGP peer and remove-private-AS is set. */
1723 if (rsclient->sort == BGP_PEER_EBGP
1724 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1725 && aspath_private_as_check (attr->aspath))
1726 attr->aspath = aspath_empty_get ();
1727
1728 /* Route map & unsuppress-map apply. */
1729 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
1730 {
1731 info.peer = rsclient;
1732 info.attr = attr;
1733
1734 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1735
1736 if (ri->extra && ri->extra->suppress)
1737 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1738 else
1739 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1740
1741 rsclient->rmap_type = 0;
1742
1743 if (ret == RMAP_DENYMATCH)
1744 {
1745 bgp_attr_flush (attr);
1746 return 0;
1747 }
1748 }
1749
1750 return 1;
1751}
1752
94f2b392 1753static int
3f9c7369
DS
1754subgroup_announce_check_rsclient (struct bgp_info *ri,
1755 struct update_subgroup *subgrp,
1756 struct prefix *p, struct attr *attr)
fee0f4c6 1757{
1758 int ret;
1759 char buf[SU_ADDRSTRLEN];
1760 struct bgp_filter *filter;
1761 struct bgp_info info;
1762 struct peer *from;
3f9c7369
DS
1763 struct peer *rsclient;
1764 struct peer *onlypeer;
0b597ef0 1765 struct attr *riattr;
5000f21c 1766 struct bgp *bgp;
3f9c7369
DS
1767 afi_t afi;
1768 safi_t safi;
1769
1770 if (DISABLE_BGP_ANNOUNCE)
1771 return 0;
fee0f4c6 1772
3f9c7369
DS
1773 afi = SUBGRP_AFI(subgrp);
1774 safi = SUBGRP_SAFI(subgrp);
1775 rsclient = SUBGRP_PEER(subgrp);
1776 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1777 (SUBGRP_PFIRST(subgrp))->peer : NULL);
fee0f4c6 1778 from = ri->peer;
1779 filter = &rsclient->filter[afi][safi];
5000f21c 1780 bgp = rsclient->bgp;
0b597ef0 1781 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
fee0f4c6 1782
fee0f4c6 1783 /* Do not send back route to sender. */
3f9c7369 1784 if (onlypeer && (from == onlypeer))
fee0f4c6 1785 return 0;
1786
1787 /* Aggregate-address suppress check. */
fb982c25 1788 if (ri->extra && ri->extra->suppress)
fee0f4c6 1789 if (! UNSUPPRESS_MAP_NAME (filter))
1790 return 0;
1791
1792 /* Default route check. */
1793 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1794 PEER_STATUS_DEFAULT_ORIGINATE))
1795 {
1796 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1797 return 0;
1798#ifdef HAVE_IPV6
1799 else if (p->family == AF_INET6 && p->prefixlen == 0)
1800 return 0;
1801#endif /* HAVE_IPV6 */
1802 }
1803
1804 /* If the attribute has originator-id and it is same as remote
1805 peer's id. */
3f9c7369 1806 if (onlypeer && riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
fee0f4c6 1807 {
3f9c7369 1808 if (IPV4_ADDR_SAME (&onlypeer->remote_id,
0b597ef0 1809 &riattr->extra->originator_id))
fee0f4c6 1810 {
3f9c7369 1811 if (bgp_debug_update(rsclient, p, subgrp->update_group, 0))
16286195 1812 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as remote router-id",
3f9c7369 1813 onlypeer->host,
16286195
DS
1814 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1815 p->prefixlen);
fee0f4c6 1816 return 0;
1817 }
1818 }
1819
1820 /* ORF prefix-list filter check */
1821 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1822 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1823 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1824 if (rsclient->orf_plist[afi][safi])
1825 {
1826 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1827 return 0;
1828 }
1829
1830 /* Output filter check. */
0b597ef0 1831 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
fee0f4c6 1832 {
3f9c7369 1833 if (bgp_debug_update(rsclient, p, subgrp->update_group, 0))
16286195
DS
1834 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1835 rsclient->host,
1836 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1837 p->prefixlen);
fee0f4c6 1838 return 0;
1839 }
1840
1841#ifdef BGP_SEND_ASPATH_CHECK
1842 /* AS path loop check. */
3f9c7369 1843 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
fee0f4c6 1844 {
3f9c7369 1845 if (bgp_debug_update(rsclient, p, subgrp->update_group, 0))
16286195 1846 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
3f9c7369 1847 onlypeer->host, onlypeer->as);
fee0f4c6 1848 return 0;
1849 }
1850#endif /* BGP_SEND_ASPATH_CHECK */
1851
1852 /* For modify attribute, copy it to temporary structure. */
0b597ef0 1853 bgp_attr_dup (attr, riattr);
fee0f4c6 1854
1855 /* next-hop-set */
1856 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1857#ifdef HAVE_IPV6
1858 || (p->family == AF_INET6 &&
fb982c25 1859 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
fee0f4c6 1860#endif /* HAVE_IPV6 */
1861 )
1862 {
1863 /* Set IPv4 nexthop. */
1864 if (p->family == AF_INET)
1865 {
1866 if (safi == SAFI_MPLS_VPN)
fb982c25 1867 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
fee0f4c6 1868 IPV4_MAX_BYTELEN);
1869 else
1870 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1871 }
1872#ifdef HAVE_IPV6
1873 /* Set IPv6 nexthop. */
1874 if (p->family == AF_INET6)
1875 {
1876 /* IPv6 global nexthop must be included. */
fb982c25 1877 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
fee0f4c6 1878 IPV6_MAX_BYTELEN);
fb982c25 1879 attr->extra->mp_nexthop_len = 16;
fee0f4c6 1880 }
1881#endif /* HAVE_IPV6 */
1882 }
1883
1884#ifdef HAVE_IPV6
1885 if (p->family == AF_INET6)
1886 {
fb982c25 1887 struct attr_extra *attre = attr->extra;
558d1fec 1888
fee0f4c6 1889 /* Left nexthop_local unchanged if so configured. */
3f9c7369 1890 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
fee0f4c6 1891 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1892 {
fb982c25
PJ
1893 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1894 attre->mp_nexthop_len=32;
fee0f4c6 1895 else
fb982c25 1896 attre->mp_nexthop_len=16;
fee0f4c6 1897 }
3f9c7369 1898
fee0f4c6 1899 /* Default nexthop_local treatment for RS-Clients */
3f9c7369
DS
1900 else
1901 {
1902 /* Announcer and RS-Client are both in the same network */
fee0f4c6 1903 if (rsclient->shared_network && from->shared_network &&
1904 (rsclient->ifindex == from->ifindex))
1905 {
fb982c25
PJ
1906 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1907 attre->mp_nexthop_len=32;
fee0f4c6 1908 else
fb982c25 1909 attre->mp_nexthop_len=16;
fee0f4c6 1910 }
1911
1912 /* Set link-local address for shared network peer. */
1913 else if (rsclient->shared_network
1914 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1915 {
fb982c25 1916 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
fee0f4c6 1917 IPV6_MAX_BYTELEN);
fb982c25 1918 attre->mp_nexthop_len = 32;
fee0f4c6 1919 }
1920
1921 else
fb982c25 1922 attre->mp_nexthop_len = 16;
fee0f4c6 1923 }
1924
1925 }
1926#endif /* HAVE_IPV6 */
1927
5000f21c 1928 bgp_peer_remove_private_as(bgp, afi, safi, rsclient, attr);
c7122e14 1929 bgp_peer_as_override(bgp, afi, safi, rsclient, attr);
fee0f4c6 1930
1931 /* Route map & unsuppress-map apply. */
fb982c25 1932 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
fee0f4c6 1933 {
1934 info.peer = rsclient;
1935 info.attr = attr;
1936
1937 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1938
fb982c25 1939 if (ri->extra && ri->extra->suppress)
fee0f4c6 1940 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1941 else
1942 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1943
1944 rsclient->rmap_type = 0;
1945
1946 if (ret == RMAP_DENYMATCH)
1947 {
1948 bgp_attr_flush (attr);
1949 return 0;
1950 }
1951 }
1952
1953 return 1;
1954}
1955
1956struct bgp_info_pair
1957{
1958 struct bgp_info *old;
1959 struct bgp_info *new;
1960};
1961
94f2b392 1962static void
96450faf
JB
1963bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1964 struct bgp_maxpaths_cfg *mpath_cfg,
1965 struct bgp_info_pair *result)
718e3744 1966{
718e3744 1967 struct bgp_info *new_select;
1968 struct bgp_info *old_select;
fee0f4c6 1969 struct bgp_info *ri;
718e3744 1970 struct bgp_info *ri1;
1971 struct bgp_info *ri2;
b40d939b 1972 struct bgp_info *nextri = NULL;
96450faf
JB
1973 int paths_eq, do_mpath;
1974 struct list mp_list;
d889623f 1975 char buf[INET6_BUFSIZ];
96450faf
JB
1976
1977 bgp_mp_list_init (&mp_list);
1978 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1979 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1980
718e3744 1981 /* bgp deterministic-med */
1982 new_select = NULL;
1983 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1984 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1985 {
1986 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1987 continue;
1988 if (BGP_INFO_HOLDDOWN (ri1))
1989 continue;
1990
1991 new_select = ri1;
6918e74b
JB
1992 if (do_mpath)
1993 bgp_mp_list_add (&mp_list, ri1);
1994 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
718e3744 1995 if (ri1->next)
1996 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1997 {
1998 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1999 continue;
2000 if (BGP_INFO_HOLDDOWN (ri2))
2001 continue;
2002
2003 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
2004 || aspath_cmp_left_confed (ri1->attr->aspath,
2005 ri2->attr->aspath))
2006 {
6918e74b
JB
2007 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
2008 old_select = ri2;
5e242b0d
DS
2009 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
2010 mpath_cfg))
718e3744 2011 {
1a392d46 2012 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
718e3744 2013 new_select = ri2;
6918e74b
JB
2014 if (do_mpath && !paths_eq)
2015 {
2016 bgp_mp_list_clear (&mp_list);
2017 bgp_mp_list_add (&mp_list, ri2);
2018 }
718e3744 2019 }
2020
6918e74b
JB
2021 if (do_mpath && paths_eq)
2022 bgp_mp_list_add (&mp_list, ri2);
2023
1a392d46 2024 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
718e3744 2025 }
2026 }
1a392d46
PJ
2027 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
2028 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
6918e74b
JB
2029
2030 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
2031 bgp_mp_list_clear (&mp_list);
718e3744 2032 }
2033
2034 /* Check old selected route and new selected route. */
2035 old_select = NULL;
2036 new_select = NULL;
b40d939b 2037 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
718e3744 2038 {
2039 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
2040 old_select = ri;
2041
2042 if (BGP_INFO_HOLDDOWN (ri))
b40d939b 2043 {
2044 /* reap REMOVED routes, if needs be
2045 * selected route must stay for a while longer though
2046 */
2047 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2048 && (ri != old_select))
2049 bgp_info_reap (rn, ri);
2050
2051 continue;
2052 }
718e3744 2053
2054 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
2055 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
2056 {
1a392d46 2057 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
718e3744 2058 continue;
2059 }
1a392d46
PJ
2060 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
2061 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
718e3744 2062
5e242b0d 2063 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg))
96450faf 2064 {
6918e74b
JB
2065 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
2066 bgp_mp_dmed_deselect (new_select);
2067
96450faf
JB
2068 new_select = ri;
2069
2070 if (do_mpath && !paths_eq)
2071 {
2072 bgp_mp_list_clear (&mp_list);
2073 bgp_mp_list_add (&mp_list, ri);
2074 }
2075 }
6918e74b
JB
2076 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
2077 bgp_mp_dmed_deselect (ri);
96450faf
JB
2078
2079 if (do_mpath && paths_eq)
2080 bgp_mp_list_add (&mp_list, ri);
718e3744 2081 }
b40d939b 2082
fee0f4c6 2083
6918e74b
JB
2084 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
2085 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
96450faf 2086
0b597ef0 2087 bgp_info_mpath_aggregate_update (new_select, old_select);
96450faf
JB
2088 bgp_mp_list_clear (&mp_list);
2089
2090 result->old = old_select;
2091 result->new = new_select;
2092
2093 return;
fee0f4c6 2094}
2095
3f9c7369
DS
2096/*
2097 * A new route/change in bestpath of an existing route. Evaluate the path
2098 * for advertisement to the subgroup.
2099 */
2100int
2101subgroup_process_announce_selected (struct update_subgroup *subgrp,
2102 struct bgp_info *selected,
2103 struct bgp_node *rn)
9eda90ce 2104{
fee0f4c6 2105 struct prefix *p;
3f9c7369
DS
2106 struct peer_af *paf;
2107 struct peer *onlypeer;
558d1fec
JBD
2108 struct attr attr;
2109 struct attr_extra extra;
3f9c7369
DS
2110 afi_t afi;
2111 safi_t safi;
fee0f4c6 2112
2113 p = &rn->p;
3f9c7369
DS
2114 afi = SUBGRP_AFI(subgrp);
2115 safi = SUBGRP_SAFI(subgrp);
2116 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
2117 (SUBGRP_PFIRST(subgrp))->peer : NULL);
718e3744 2118
9eda90ce 2119 /* First update is deferred until ORF or ROUTE-REFRESH is received */
3f9c7369
DS
2120 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
2121 PEER_STATUS_ORF_WAIT_REFRESH))
fee0f4c6 2122 return 0;
718e3744 2123
558d1fec
JBD
2124 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2125 attr.extra = &extra;
2126
67174041 2127 switch (bgp_node_table (rn)->type)
fee0f4c6 2128 {
2129 case BGP_TABLE_MAIN:
3f9c7369 2130 /* Announcement to the subgroup. If the route is filtered,
718e3744 2131 withdraw it. */
3f9c7369
DS
2132 if (selected && subgroup_announce_check(selected, subgrp, p, &attr))
2133 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
fee0f4c6 2134 else
3f9c7369
DS
2135 bgp_adj_out_unset_subgroup(rn, subgrp);
2136
fee0f4c6 2137 break;
2138 case BGP_TABLE_RSCLIENT:
3f9c7369 2139 /* Announcement to peer->conf. If the route is filtered,
fee0f4c6 2140 withdraw it. */
3f9c7369
DS
2141 if (selected &&
2142 subgroup_announce_check_rsclient (selected, subgrp, p, &attr))
2143 bgp_adj_out_set_subgroup (rn, subgrp, &attr, selected);
9eda90ce 2144 else
3f9c7369 2145 bgp_adj_out_unset_subgroup(rn, subgrp);
fee0f4c6 2146 break;
2147 }
558d1fec 2148
fee0f4c6 2149 return 0;
200df115 2150}
fee0f4c6 2151
3f9c7369 2152struct bgp_process_queue
fee0f4c6 2153{
200df115 2154 struct bgp *bgp;
2155 struct bgp_node *rn;
2156 afi_t afi;
2157 safi_t safi;
2158};
2159
2160static wq_item_status
0fb58d5d 2161bgp_process_rsclient (struct work_queue *wq, void *data)
200df115 2162{
0fb58d5d 2163 struct bgp_process_queue *pq = data;
200df115 2164 struct bgp *bgp = pq->bgp;
2165 struct bgp_node *rn = pq->rn;
2166 afi_t afi = pq->afi;
2167 safi_t safi = pq->safi;
fee0f4c6 2168 struct bgp_info *new_select;
2169 struct bgp_info *old_select;
2170 struct bgp_info_pair old_and_new;
1eb8ef25 2171 struct listnode *node, *nnode;
cb1faec9 2172 struct peer *rsclient;
3f9c7369
DS
2173 struct peer_af *paf;
2174 struct update_subgroup *subgrp;
cb1faec9
DS
2175
2176 /* Is it end of initial update? (after startup) */
2177 if (!rn)
2178 {
4a16ae86
DS
2179 /* This is just to keep the display sane in case all the peers are
2180 rsclients only */
2181 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
2182 sizeof(bgp->update_delay_zebra_resume_time));
2183
2184 bgp->rsclient_peers_update_hold = 0;
cb1faec9
DS
2185 bgp_start_routeadv(bgp);
2186 return WQ_SUCCESS;
2187 }
2188
2189 rsclient = bgp_node_table (rn)->owner;
2190
fee0f4c6 2191 /* Best path selection. */
96450faf 2192 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 2193 new_select = old_and_new.new;
2194 old_select = old_and_new.old;
2195
200df115 2196 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
2197 {
228da428
CC
2198 if (rsclient->group)
2199 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
2200 {
2201 /* Nothing to do. */
2202 if (old_select && old_select == new_select)
2203 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
2204 continue;
2205
2206 if (old_select)
2207 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
2208 if (new_select)
2209 {
2210 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
2211 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d
JB
2212 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
2213 }
228da428 2214
3f9c7369
DS
2215 paf = peer_af_find(rsclient, afi, safi);
2216 assert(paf);
2217 subgrp = PAF_SUBGRP(paf);
2218 if (!subgrp) /* not an established session */
2219 continue;
2220 subgroup_process_announce_selected (subgrp, new_select, rn);
228da428 2221 }
200df115 2222 }
2223 else
2224 {
b7395791 2225 if (old_select)
1a392d46 2226 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
b7395791 2227 if (new_select)
2228 {
1a392d46
PJ
2229 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
2230 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 2231 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
b7395791 2232 }
3f9c7369
DS
2233 paf = peer_af_find(rsclient, afi, safi);
2234 if (paf && (subgrp = PAF_SUBGRP(paf))) /* if an established session */
2235 subgroup_process_announce_selected (subgrp, new_select, rn);
200df115 2236 }
2237
b40d939b 2238 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
2239 bgp_info_reap (rn, old_select);
3f9c7369 2240
200df115 2241 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2242 return WQ_SUCCESS;
fee0f4c6 2243}
2244
200df115 2245static wq_item_status
0fb58d5d 2246bgp_process_main (struct work_queue *wq, void *data)
200df115 2247{
0fb58d5d 2248 struct bgp_process_queue *pq = data;
200df115 2249 struct bgp *bgp = pq->bgp;
2250 struct bgp_node *rn = pq->rn;
2251 afi_t afi = pq->afi;
2252 safi_t safi = pq->safi;
2253 struct prefix *p = &rn->p;
fee0f4c6 2254 struct bgp_info *new_select;
2255 struct bgp_info *old_select;
2256 struct bgp_info_pair old_and_new;
1eb8ef25 2257 struct listnode *node, *nnode;
fee0f4c6 2258 struct peer *peer;
cb1faec9
DS
2259
2260 /* Is it end of initial update? (after startup) */
2261 if (!rn)
2262 {
4a16ae86
DS
2263 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
2264 sizeof(bgp->update_delay_zebra_resume_time));
2265
2266 bgp->main_zebra_update_hold = 0;
2267 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2268 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2269 {
2270 bgp_zebra_announce_table(bgp, afi, safi);
2271 }
2272 bgp->main_peers_update_hold = 0;
2273
cb1faec9
DS
2274 bgp_start_routeadv(bgp);
2275 return WQ_SUCCESS;
2276 }
2277
fee0f4c6 2278 /* Best path selection. */
96450faf 2279 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 2280 old_select = old_and_new.old;
2281 new_select = old_and_new.new;
2282
2283 /* Nothing to do. */
8ad7271d 2284 if (old_select && old_select == new_select && !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR))
fee0f4c6 2285 {
2286 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
200df115 2287 {
8196f13d
JB
2288 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
2289 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
73ac8160 2290 bgp_zebra_announce (p, old_select, bgp, afi, safi);
200df115 2291
8196f13d 2292 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
200df115 2293 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2294 return WQ_SUCCESS;
2295 }
fee0f4c6 2296 }
2297
8ad7271d
DS
2298 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
2299 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
2300
3f9c7369
DS
2301 /* bestpath has changed; bump version */
2302 if (old_select || new_select)
2303 bgp_bump_version(rn);
2304
338b3424 2305 if (old_select)
1a392d46 2306 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
338b3424 2307 if (new_select)
2308 {
1a392d46
PJ
2309 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
2310 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 2311 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
338b3424 2312 }
2313
3f9c7369 2314 group_announce_route(bgp, afi, safi, rn, new_select);
718e3744 2315
2316 /* FIB update. */
5a616c08
B
2317 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
2318 ! bgp_option_check (BGP_OPT_NO_FIB)))
718e3744 2319 {
2320 if (new_select
2321 && new_select->type == ZEBRA_ROUTE_BGP
2322 && new_select->sub_type == BGP_ROUTE_NORMAL)
73ac8160 2323 bgp_zebra_announce (p, new_select, bgp, afi, safi);
718e3744 2324 else
2325 {
2326 /* Withdraw the route from the kernel. */
2327 if (old_select
2328 && old_select->type == ZEBRA_ROUTE_BGP
2329 && old_select->sub_type == BGP_ROUTE_NORMAL)
5a616c08 2330 bgp_zebra_withdraw (p, old_select, safi);
718e3744 2331 }
2332 }
b40d939b 2333
2334 /* Reap old select bgp_info, it it has been removed */
2335 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
2336 bgp_info_reap (rn, old_select);
2337
200df115 2338 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2339 return WQ_SUCCESS;
718e3744 2340}
2341
200df115 2342static void
0fb58d5d 2343bgp_processq_del (struct work_queue *wq, void *data)
200df115 2344{
0fb58d5d 2345 struct bgp_process_queue *pq = data;
cb1faec9
DS
2346 struct bgp_table *table;
2347
228da428 2348 bgp_unlock (pq->bgp);
cb1faec9
DS
2349 if (pq->rn)
2350 {
2351 table = bgp_node_table (pq->rn);
2352 bgp_unlock_node (pq->rn);
2353 bgp_table_unlock (table);
2354 }
200df115 2355 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
2356}
2357
f188f2c4 2358void
200df115 2359bgp_process_queue_init (void)
2360{
2361 bm->process_main_queue
2362 = work_queue_new (bm->master, "process_main_queue");
2363 bm->process_rsclient_queue
2364 = work_queue_new (bm->master, "process_rsclient_queue");
2365
2366 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
2367 {
2368 zlog_err ("%s: Failed to allocate work queue", __func__);
2369 exit (1);
2370 }
2371
2372 bm->process_main_queue->spec.workfunc = &bgp_process_main;
200df115 2373 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
838bbde0
PJ
2374 bm->process_main_queue->spec.max_retries = 0;
2375 bm->process_main_queue->spec.hold = 50;
d889623f
DS
2376 /* Use a higher yield value of 50ms for main queue processing */
2377 bm->process_main_queue->spec.yield = 50 * 1000L;
838bbde0
PJ
2378
2379 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
2380 sizeof (struct work_queue *));
2381 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
200df115 2382}
2383
2384void
fee0f4c6 2385bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
2386{
200df115 2387 struct bgp_process_queue *pqnode;
2388
2389 /* already scheduled for processing? */
2390 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
2391 return;
2392
2393 if ( (bm->process_main_queue == NULL) ||
2394 (bm->process_rsclient_queue == NULL) )
2395 bgp_process_queue_init ();
2396
2397 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2398 sizeof (struct bgp_process_queue));
2399 if (!pqnode)
2400 return;
228da428
CC
2401
2402 /* all unlocked in bgp_processq_del */
67174041 2403 bgp_table_lock (bgp_node_table (rn));
228da428 2404 pqnode->rn = bgp_lock_node (rn);
200df115 2405 pqnode->bgp = bgp;
228da428 2406 bgp_lock (bgp);
200df115 2407 pqnode->afi = afi;
2408 pqnode->safi = safi;
2409
67174041 2410 switch (bgp_node_table (rn)->type)
fee0f4c6 2411 {
200df115 2412 case BGP_TABLE_MAIN:
2413 work_queue_add (bm->process_main_queue, pqnode);
2414 break;
2415 case BGP_TABLE_RSCLIENT:
2416 work_queue_add (bm->process_rsclient_queue, pqnode);
2417 break;
fee0f4c6 2418 }
200df115 2419
07ff4dc4 2420 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
200df115 2421 return;
fee0f4c6 2422}
0a486e5f 2423
cb1faec9
DS
2424void
2425bgp_add_eoiu_mark (struct bgp *bgp, bgp_table_t type)
2426{
2427 struct bgp_process_queue *pqnode;
2428
2429 if ( (bm->process_main_queue == NULL) ||
2430 (bm->process_rsclient_queue == NULL) )
2431 bgp_process_queue_init ();
2432
2433 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2434 sizeof (struct bgp_process_queue));
2435 if (!pqnode)
2436 return;
2437
2438 pqnode->rn = NULL;
2439 pqnode->bgp = bgp;
2440 bgp_lock (bgp);
2441 switch (type)
2442 {
2443 case BGP_TABLE_MAIN:
2444 work_queue_add (bm->process_main_queue, pqnode);
2445 break;
2446 case BGP_TABLE_RSCLIENT:
2447 work_queue_add (bm->process_rsclient_queue, pqnode);
2448 break;
2449 }
2450
2451 return;
2452}
2453
94f2b392 2454static int
0a486e5f 2455bgp_maximum_prefix_restart_timer (struct thread *thread)
2456{
2457 struct peer *peer;
2458
2459 peer = THREAD_ARG (thread);
2460 peer->t_pmax_restart = NULL;
2461
16286195 2462 if (bgp_debug_neighbor_events(peer))
0a486e5f 2463 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
2464 peer->host);
2465
1ff9a340 2466 peer_clear (peer, NULL);
0a486e5f 2467
2468 return 0;
2469}
2470
718e3744 2471int
5228ad27 2472bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
2473 safi_t safi, int always)
718e3744 2474{
e0701b79 2475 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
2476 return 0;
2477
2478 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
718e3744 2479 {
e0701b79 2480 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
2481 && ! always)
2482 return 0;
2483
16286195
DS
2484 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
2485 "limit %ld", afi_safi_print (afi, safi), peer->host,
2486 peer->pcount[afi][safi], peer->pmax[afi][safi]);
e0701b79 2487 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2488
2489 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
2490 return 0;
2491
2492 {
5228ad27 2493 u_int8_t ndata[7];
e0701b79 2494
2495 if (safi == SAFI_MPLS_VPN)
42e6d745 2496 safi = SAFI_MPLS_LABELED_VPN;
5228ad27 2497
2498 ndata[0] = (afi >> 8);
2499 ndata[1] = afi;
2500 ndata[2] = safi;
2501 ndata[3] = (peer->pmax[afi][safi] >> 24);
2502 ndata[4] = (peer->pmax[afi][safi] >> 16);
2503 ndata[5] = (peer->pmax[afi][safi] >> 8);
2504 ndata[6] = (peer->pmax[afi][safi]);
e0701b79 2505
2506 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
2507 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
2508 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
2509 }
0a486e5f 2510
2511 /* restart timer start */
2512 if (peer->pmax_restart[afi][safi])
2513 {
2514 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
2515
16286195 2516 if (bgp_debug_neighbor_events(peer))
0a486e5f 2517 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2518 peer->host, peer->v_pmax_restart);
2519
2520 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2521 peer->v_pmax_restart);
2522 }
2523
e0701b79 2524 return 1;
2525 }
2526 else
2527 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2528
2529 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2530 {
2531 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2532 && ! always)
2533 return 0;
2534
16286195
DS
2535 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2536 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2537 peer->pmax[afi][safi]);
e0701b79 2538 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2539 }
e0701b79 2540 else
2541 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 2542 return 0;
2543}
2544
b40d939b 2545/* Unconditionally remove the route from the RIB, without taking
2546 * damping into consideration (eg, because the session went down)
2547 */
94f2b392 2548static void
718e3744 2549bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2550 afi_t afi, safi_t safi)
2551{
902212c3 2552 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2553
2554 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2555 bgp_info_delete (rn, ri); /* keep historical info */
2556
b40d939b 2557 bgp_process (peer->bgp, rn, afi, safi);
718e3744 2558}
2559
94f2b392 2560static void
718e3744 2561bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
b40d939b 2562 afi_t afi, safi_t safi)
718e3744 2563{
718e3744 2564 int status = BGP_DAMP_NONE;
2565
b40d939b 2566 /* apply dampening, if result is suppressed, we'll be retaining
2567 * the bgp_info in the RIB for historical reference.
2568 */
2569 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2570 && peer->sort == BGP_PEER_EBGP)
b40d939b 2571 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2572 == BGP_DAMP_SUPPRESSED)
902212c3 2573 {
902212c3 2574 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2575 return;
2576 }
2577
2578 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 2579}
2580
fb018d25 2581static struct bgp_info *
7c8ff89e 2582info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
fb018d25
DS
2583 struct bgp_node *rn)
2584{
2585 struct bgp_info *new;
2586
2587 /* Make new BGP info. */
2588 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2589 new->type = type;
7c8ff89e 2590 new->instance = instance;
fb018d25
DS
2591 new->sub_type = sub_type;
2592 new->peer = peer;
2593 new->attr = attr;
2594 new->uptime = bgp_clock ();
2595 new->net = rn;
2596 return new;
2597}
2598
94f2b392 2599static void
fee0f4c6 2600bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2601 struct attr *attr, struct peer *peer, struct prefix *p, int type,
2602 int sub_type, struct prefix_rd *prd, u_char *tag)
2603{
2604 struct bgp_node *rn;
2605 struct bgp *bgp;
558d1fec
JBD
2606 struct attr new_attr;
2607 struct attr_extra new_extra;
fee0f4c6 2608 struct attr *attr_new;
2609 struct attr *attr_new2;
2610 struct bgp_info *ri;
2611 struct bgp_info *new;
fd79ac91 2612 const char *reason;
fee0f4c6 2613 char buf[SU_ADDRSTRLEN];
2614
2615 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
2616 if (peer == rsclient)
2617 return;
2618
2619 bgp = peer->bgp;
2620 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2621
2622 /* Check previously received route. */
2623 for (ri = rn->info; ri; ri = ri->next)
2624 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2625 break;
2626
2627 /* AS path loop check. */
000e157c 2628 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
fee0f4c6 2629 {
2630 reason = "as-path contains our own AS;";
2631 goto filtered;
2632 }
2633
2634 /* Route reflector originator ID check. */
2635 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 2636 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
fee0f4c6 2637 {
2638 reason = "originator is us;";
2639 goto filtered;
2640 }
fb982c25 2641
558d1fec 2642 new_attr.extra = &new_extra;
fb982c25 2643 bgp_attr_dup (&new_attr, attr);
fee0f4c6 2644
2645 /* Apply export policy. */
2646 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
2647 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
2648 {
2649 reason = "export-policy;";
2650 goto filtered;
2651 }
2652
2653 attr_new2 = bgp_attr_intern (&new_attr);
fb982c25 2654
fee0f4c6 2655 /* Apply import policy. */
2656 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
2657 {
f6f434b2 2658 bgp_attr_unintern (&attr_new2);
fee0f4c6 2659
2660 reason = "import-policy;";
2661 goto filtered;
2662 }
2663
2664 attr_new = bgp_attr_intern (&new_attr);
f6f434b2 2665 bgp_attr_unintern (&attr_new2);
fee0f4c6 2666
2667 /* IPv4 unicast next hop check. */
5a616c08 2668 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
fee0f4c6 2669 {
733cd9e5 2670 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
fee0f4c6 2671 if (new_attr.nexthop.s_addr == 0
733cd9e5 2672 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
fee0f4c6 2673 {
f6f434b2 2674 bgp_attr_unintern (&attr_new);
fee0f4c6 2675
2676 reason = "martian next-hop;";
2677 goto filtered;
2678 }
2679 }
558d1fec 2680
fee0f4c6 2681 /* If the update is implicit withdraw. */
2682 if (ri)
2683 {
65957886 2684 ri->uptime = bgp_clock ();
fee0f4c6 2685
2686 /* Same attribute comes in. */
16d2e241
PJ
2687 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
2688 && attrhash_cmp (ri->attr, attr_new))
fee0f4c6 2689 {
2690
3f9c7369 2691 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2692 zlog_debug ("%s rcvd %s/%d for RS-client %s...duplicate ignored",
2693 peer->host,
2694 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2695 p->prefixlen, rsclient->host);
2696
fee0f4c6 2697
228da428 2698 bgp_unlock_node (rn);
f6f434b2 2699 bgp_attr_unintern (&attr_new);
fee0f4c6 2700
228da428 2701 return;
fee0f4c6 2702 }
2703
16d2e241
PJ
2704 /* Withdraw/Announce before we fully processed the withdraw */
2705 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2706 bgp_info_restore (rn, ri);
2707
fee0f4c6 2708 /* Received Logging. */
3f9c7369 2709 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2710 zlog_debug ("%s rcvd %s/%d for RS-client %s",
2711 peer->host,
2712 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2713 p->prefixlen, rsclient->host);
fee0f4c6 2714
2715 /* The attribute is changed. */
1a392d46 2716 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
fee0f4c6 2717
2718 /* Update to new attribute. */
f6f434b2 2719 bgp_attr_unintern (&ri->attr);
fee0f4c6 2720 ri->attr = attr_new;
2721
2722 /* Update MPLS tag. */
2723 if (safi == SAFI_MPLS_VPN)
fb982c25 2724 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
fee0f4c6 2725
1a392d46 2726 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
fee0f4c6 2727
2728 /* Process change. */
2729 bgp_process (bgp, rn, afi, safi);
2730 bgp_unlock_node (rn);
2731
2732 return;
2733 }
2734
2735 /* Received Logging. */
3f9c7369 2736 if (bgp_debug_update(peer, p, NULL, 1))
fee0f4c6 2737 {
16286195
DS
2738 zlog_debug ("%s rcvd %s/%d for RS-client %s",
2739 peer->host,
2740 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2741 p->prefixlen, rsclient->host);
fee0f4c6 2742 }
2743
7c8ff89e 2744 new = info_make(type, sub_type, 0, peer, attr_new, rn);
fee0f4c6 2745
2746 /* Update MPLS tag. */
2747 if (safi == SAFI_MPLS_VPN)
fb982c25 2748 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
fee0f4c6 2749
1a392d46 2750 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
fee0f4c6 2751
2752 /* Register new BGP information. */
2753 bgp_info_add (rn, new);
200df115 2754
2755 /* route_node_get lock */
2756 bgp_unlock_node (rn);
2757
fee0f4c6 2758 /* Process change. */
2759 bgp_process (bgp, rn, afi, safi);
558d1fec 2760
fee0f4c6 2761 return;
2762
2763 filtered:
2764
2765 /* This BGP update is filtered. Log the reason then update BGP entry. */
3f9c7369 2766 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2767 zlog_debug ("%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2768 peer->host,
2769 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2770 p->prefixlen, rsclient->host, reason);
fee0f4c6 2771
2772 if (ri)
b40d939b 2773 bgp_rib_remove (rn, ri, peer, afi, safi);
fee0f4c6 2774
2775 bgp_unlock_node (rn);
558d1fec 2776
fee0f4c6 2777 return;
2778}
2779
94f2b392 2780static void
fee0f4c6 2781bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2782 struct peer *peer, struct prefix *p, int type, int sub_type,
2783 struct prefix_rd *prd, u_char *tag)
228da428 2784{
fee0f4c6 2785 struct bgp_node *rn;
2786 struct bgp_info *ri;
2787 char buf[SU_ADDRSTRLEN];
2788
2789 if (rsclient == peer)
228da428 2790 return;
fee0f4c6 2791
2792 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2793
2794 /* Lookup withdrawn route. */
2795 for (ri = rn->info; ri; ri = ri->next)
2796 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2797 break;
2798
2799 /* Withdraw specified route from routing table. */
2800 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
b40d939b 2801 bgp_rib_withdraw (rn, ri, peer, afi, safi);
3f9c7369 2802 else if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2803 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2804 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2805 p->prefixlen);
fee0f4c6 2806
2807 /* Unlock bgp_node_get() lock. */
228da428
CC
2808 bgp_unlock_node (rn);
2809}
fee0f4c6 2810
94f2b392 2811static int
a82478b9
DS
2812bgp_update_main (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2813 struct attr *attr, afi_t afi, safi_t safi, int type,
2814 int sub_type, struct prefix_rd *prd, u_char *tag,
2815 int soft_reconfig)
718e3744 2816{
2817 int ret;
2818 int aspath_loop_count = 0;
2819 struct bgp_node *rn;
2820 struct bgp *bgp;
558d1fec
JBD
2821 struct attr new_attr;
2822 struct attr_extra new_extra;
718e3744 2823 struct attr *attr_new;
2824 struct bgp_info *ri;
2825 struct bgp_info *new;
fd79ac91 2826 const char *reason;
718e3744 2827 char buf[SU_ADDRSTRLEN];
fc9a856f 2828 int connected = 0;
718e3744 2829
2830 bgp = peer->bgp;
fee0f4c6 2831 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
fb982c25 2832
718e3744 2833 /* When peer's soft reconfiguration enabled. Record input packet in
2834 Adj-RIBs-In. */
343aa822
JBD
2835 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2836 && peer != bgp->peer_self)
718e3744 2837 bgp_adj_in_set (rn, peer, attr);
2838
2839 /* Check previously received route. */
2840 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
2841 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2842 ri->addpath_rx_id == addpath_id)
718e3744 2843 break;
2844
2845 /* AS path local-as loop check. */
2846 if (peer->change_local_as)
2847 {
2848 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2849 aspath_loop_count = 1;
2850
2851 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2852 {
2853 reason = "as-path contains our own AS;";
2854 goto filtered;
2855 }
2856 }
2857
2858 /* AS path loop check. */
2859 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2860 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2861 && aspath_loop_check(attr->aspath, bgp->confed_id)
2862 > peer->allowas_in[afi][safi]))
2863 {
2864 reason = "as-path contains our own AS;";
2865 goto filtered;
2866 }
2867
2868 /* Route reflector originator ID check. */
2869 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 2870 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
718e3744 2871 {
2872 reason = "originator is us;";
2873 goto filtered;
2874 }
2875
2876 /* Route reflector cluster ID check. */
2877 if (bgp_cluster_filter (peer, attr))
2878 {
2879 reason = "reflected from the same cluster;";
2880 goto filtered;
2881 }
2882
2883 /* Apply incoming filter. */
2884 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2885 {
2886 reason = "filter;";
2887 goto filtered;
2888 }
2889
558d1fec 2890 new_attr.extra = &new_extra;
fb982c25 2891 bgp_attr_dup (&new_attr, attr);
718e3744 2892
c460e572
DL
2893 /* Apply incoming route-map.
2894 * NB: new_attr may now contain newly allocated values from route-map "set"
2895 * commands, so we need bgp_attr_flush in the error paths, until we intern
2896 * the attr (which takes over the memory references) */
0b16f239 2897 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
718e3744 2898 {
2899 reason = "route-map;";
c460e572 2900 bgp_attr_flush (&new_attr);
718e3744 2901 goto filtered;
2902 }
2903
2904 /* IPv4 unicast next hop check. */
2905 if (afi == AFI_IP && safi == SAFI_UNICAST)
2906 {
733cd9e5 2907 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
718e3744 2908 must not be my own address. */
10f9bf3f
JBD
2909 if (new_attr.nexthop.s_addr == 0
2910 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2911 || bgp_nexthop_self (&new_attr))
718e3744 2912 {
2913 reason = "martian next-hop;";
c460e572 2914 bgp_attr_flush (&new_attr);
718e3744 2915 goto filtered;
2916 }
2917 }
2918
2919 attr_new = bgp_attr_intern (&new_attr);
2920
2921 /* If the update is implicit withdraw. */
2922 if (ri)
2923 {
65957886 2924 ri->uptime = bgp_clock ();
718e3744 2925
2926 /* Same attribute comes in. */
16d2e241
PJ
2927 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2928 && attrhash_cmp (ri->attr, attr_new))
718e3744 2929 {
718e3744 2930 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2931 && peer->sort == BGP_PEER_EBGP
718e3744 2932 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2933 {
3f9c7369 2934 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2935 zlog_debug ("%s rcvd %s/%d",
2936 peer->host,
2937 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2938 p->prefixlen);
718e3744 2939
902212c3 2940 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2941 {
2942 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2943 bgp_process (bgp, rn, afi, safi);
2944 }
718e3744 2945 }
16d2e241 2946 else /* Duplicate - odd */
718e3744 2947 {
3f9c7369 2948 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2949 {
2950 if (!peer->rcvd_attr_printed)
2951 {
2952 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2953 peer->rcvd_attr_printed = 1;
2954 }
2955
2956 zlog_debug ("%s rcvd %s/%d...duplicate ignored",
2957 peer->host,
2958 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2959 p->prefixlen);
2960 }
93406d87 2961
2962 /* graceful restart STALE flag unset. */
2963 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2964 {
1a392d46 2965 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
902212c3 2966 bgp_process (bgp, rn, afi, safi);
93406d87 2967 }
718e3744 2968 }
2969
2970 bgp_unlock_node (rn);
f6f434b2 2971 bgp_attr_unintern (&attr_new);
558d1fec 2972
718e3744 2973 return 0;
2974 }
2975
16d2e241
PJ
2976 /* Withdraw/Announce before we fully processed the withdraw */
2977 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2978 {
3f9c7369 2979 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2980 zlog_debug ("%s rcvd %s/%d, flapped quicker than processing",
2981 peer->host,
2982 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2983 p->prefixlen);
16d2e241
PJ
2984 bgp_info_restore (rn, ri);
2985 }
2986
718e3744 2987 /* Received Logging. */
3f9c7369 2988 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
2989 zlog_debug ("%s rcvd %s/%d",
2990 peer->host,
2991 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2992 p->prefixlen);
718e3744 2993
93406d87 2994 /* graceful restart STALE flag unset. */
2995 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1a392d46 2996 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
93406d87 2997
718e3744 2998 /* The attribute is changed. */
1a392d46 2999 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
902212c3 3000
3001 /* implicit withdraw, decrement aggregate and pcount here.
3002 * only if update is accepted, they'll increment below.
3003 */
902212c3 3004 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3005
718e3744 3006 /* Update bgp route dampening information. */
3007 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 3008 && peer->sort == BGP_PEER_EBGP)
718e3744 3009 {
3010 /* This is implicit withdraw so we should update dampening
3011 information. */
3012 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
3013 bgp_damp_withdraw (ri, rn, afi, safi, 1);
718e3744 3014 }
3015
718e3744 3016 /* Update to new attribute. */
f6f434b2 3017 bgp_attr_unintern (&ri->attr);
718e3744 3018 ri->attr = attr_new;
3019
3020 /* Update MPLS tag. */
3021 if (safi == SAFI_MPLS_VPN)
fb982c25 3022 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
718e3744 3023
3024 /* Update bgp route dampening information. */
3025 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 3026 && peer->sort == BGP_PEER_EBGP)
718e3744 3027 {
3028 /* Now we do normal update dampening. */
3029 ret = bgp_damp_update (ri, rn, afi, safi);
3030 if (ret == BGP_DAMP_SUPPRESSED)
3031 {
3032 bgp_unlock_node (rn);
3033 return 0;
3034 }
3035 }
3036
3037 /* Nexthop reachability check. */
fc9a856f 3038 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
718e3744 3039 {
fc9a856f
DS
3040 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
3041 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
3042 connected = 1;
3043 else
3044 connected = 0;
3045
3046 if (bgp_find_or_add_nexthop (afi, ri, NULL, connected))
1a392d46 3047 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 3048 else
fc9a856f
DS
3049 {
3050 if (BGP_DEBUG(nht, NHT))
3051 {
3052 char buf1[INET6_ADDRSTRLEN];
3053 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
3054 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3055 }
3056 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3057 }
718e3744 3058 }
3059 else
fc9a856f 3060 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 3061
3062 /* Process change. */
3063 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3064
3065 bgp_process (bgp, rn, afi, safi);
3066 bgp_unlock_node (rn);
558d1fec 3067
718e3744 3068 return 0;
a82478b9 3069 } // End of implicit withdraw
718e3744 3070
3071 /* Received Logging. */
3f9c7369 3072 if (bgp_debug_update(peer, p, NULL, 1))
718e3744 3073 {
16286195
DS
3074 if (!peer->rcvd_attr_printed)
3075 {
3076 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
3077 peer->rcvd_attr_printed = 1;
3078 }
3079
3080 zlog_debug ("%s rcvd %s/%d",
3081 peer->host,
3082 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3083 p->prefixlen);
718e3744 3084 }
3085
718e3744 3086 /* Make new BGP info. */
7c8ff89e 3087 new = info_make(type, sub_type, 0, peer, attr_new, rn);
718e3744 3088
3089 /* Update MPLS tag. */
3090 if (safi == SAFI_MPLS_VPN)
fb982c25 3091 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
718e3744 3092
3093 /* Nexthop reachability check. */
fc9a856f
DS
3094 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
3095 {
3096 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
3097 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
3098 connected = 1;
3099 else
3100 connected = 0;
3101
3102 if (bgp_find_or_add_nexthop (afi, new, NULL, connected))
1a392d46 3103 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 3104 else
fc9a856f
DS
3105 {
3106 if (BGP_DEBUG(nht, NHT))
3107 {
3108 char buf1[INET6_ADDRSTRLEN];
3109 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
3110 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3111 }
3112 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3113 }
718e3744 3114 }
3115 else
1a392d46 3116 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 3117
a82478b9
DS
3118 /* Addpath ID */
3119 new->addpath_rx_id = addpath_id;
3120 new->addpath_tx_id = 0;
3121
902212c3 3122 /* Increment prefix */
718e3744 3123 bgp_aggregate_increment (bgp, p, new, afi, safi);
3124
3125 /* Register new BGP information. */
3126 bgp_info_add (rn, new);
200df115 3127
3128 /* route_node_get lock */
3129 bgp_unlock_node (rn);
558d1fec 3130
718e3744 3131 /* If maximum prefix count is configured and current prefix
3132 count exeed it. */
e0701b79 3133 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
3134 return -1;
718e3744 3135
3136 /* Process change. */
3137 bgp_process (bgp, rn, afi, safi);
3138
3139 return 0;
3140
3141 /* This BGP update is filtered. Log the reason then update BGP
3142 entry. */
3143 filtered:
3f9c7369 3144 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
3145 {
3146 if (!peer->rcvd_attr_printed)
3147 {
3148 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
3149 peer->rcvd_attr_printed = 1;
3150 }
3151
3152 zlog_debug ("%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
3153 peer->host,
3154 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3155 p->prefixlen, reason);
3156 }
718e3744 3157
3158 if (ri)
b40d939b 3159 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 3160
3161 bgp_unlock_node (rn);
558d1fec 3162
718e3744 3163 return 0;
3164}
3165
fee0f4c6 3166int
a82478b9
DS
3167bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
3168 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
fee0f4c6 3169 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
3170{
3171 struct peer *rsclient;
1eb8ef25 3172 struct listnode *node, *nnode;
fee0f4c6 3173 struct bgp *bgp;
3174 int ret;
3175
a82478b9
DS
3176 ret = bgp_update_main (peer, p, addpath_id, attr, afi, safi, type, sub_type,
3177 prd, tag, soft_reconfig);
fee0f4c6 3178
3179 bgp = peer->bgp;
3180
3181 /* Process the update for each RS-client. */
1eb8ef25 3182 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 3183 {
3184 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
a82478b9
DS
3185 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p,
3186 type, sub_type, prd, tag);
fee0f4c6 3187 }
3188
3189 return ret;
3190}
3191
718e3744 3192int
a82478b9
DS
3193bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
3194 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
3195 struct prefix_rd *prd, u_char *tag)
718e3744 3196{
3197 struct bgp *bgp;
3198 char buf[SU_ADDRSTRLEN];
3199 struct bgp_node *rn;
3200 struct bgp_info *ri;
fee0f4c6 3201 struct peer *rsclient;
1eb8ef25 3202 struct listnode *node, *nnode;
718e3744 3203
3204 bgp = peer->bgp;
3205
fee0f4c6 3206 /* Process the withdraw for each RS-client. */
1eb8ef25 3207 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 3208 {
3209 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
a82478b9
DS
3210 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type,
3211 sub_type, prd, tag);
fee0f4c6 3212 }
3213
718e3744 3214 /* Logging. */
3f9c7369 3215 if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
3216 zlog_debug ("%s rcvd UPDATE about %s/%d -- withdrawn",
3217 peer->host,
3218 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3219 p->prefixlen);
718e3744 3220
3221 /* Lookup node. */
fee0f4c6 3222 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 3223
3224 /* If peer is soft reconfiguration enabled. Record input packet for
3225 further calculation. */
3226 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
3227 && peer != bgp->peer_self)
3228 bgp_adj_in_unset (rn, peer);
3229
3230 /* Lookup withdrawn route. */
3231 for (ri = rn->info; ri; ri = ri->next)
a82478b9
DS
3232 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
3233 ri->addpath_rx_id == addpath_id)
718e3744 3234 break;
3235
3236 /* Withdraw specified route from routing table. */
3237 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
b40d939b 3238 bgp_rib_withdraw (rn, ri, peer, afi, safi);
3f9c7369 3239 else if (bgp_debug_update(peer, p, NULL, 1))
16286195
DS
3240 zlog_debug ("%s Can't find the route %s/%d", peer->host,
3241 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3242 p->prefixlen);
718e3744 3243
3244 /* Unlock bgp_node_get() lock. */
3245 bgp_unlock_node (rn);
3246
3247 return 0;
3248}
6b0655a2 3249
718e3744 3250void
3251bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
3252{
3f9c7369
DS
3253 struct update_subgroup *subgrp;
3254 subgrp = peer_subgroup(peer, afi, safi);
3255 subgroup_default_originate(subgrp, withdraw);
3256}
6182d65b 3257
718e3744 3258
3f9c7369
DS
3259/*
3260 * bgp_stop_announce_route_timer
3261 */
3262void
3263bgp_stop_announce_route_timer (struct peer_af *paf)
3264{
3265 if (!paf->t_announce_route)
3266 return;
718e3744 3267
3f9c7369 3268 THREAD_TIMER_OFF (paf->t_announce_route);
718e3744 3269}
6b0655a2 3270
3f9c7369
DS
3271/*
3272 * bgp_announce_route_timer_expired
3273 *
3274 * Callback that is invoked when the route announcement timer for a
3275 * peer_af expires.
3276 */
3277static int
3278bgp_announce_route_timer_expired (struct thread *t)
718e3744 3279{
3f9c7369
DS
3280 struct peer_af *paf;
3281 struct peer *peer;
558d1fec 3282
718e3744 3283
3f9c7369
DS
3284 paf = THREAD_ARG (t);
3285 peer = paf->peer;
718e3744 3286
3f9c7369
DS
3287 assert (paf->t_announce_route);
3288 paf->t_announce_route = NULL;
558d1fec 3289
3f9c7369
DS
3290 if (peer->status != Established)
3291 return 0;
3292
3293 if (!peer->afc_nego[paf->afi][paf->safi])
3294 return 0;
3295
3296 peer_af_announce_route (paf, 1);
3297 return 0;
718e3744 3298}
3299
3f9c7369
DS
3300/*
3301 * bgp_announce_route
3302 *
3303 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
3304 */
718e3744 3305void
3306bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
3307{
3f9c7369
DS
3308 struct peer_af *paf;
3309 struct update_subgroup *subgrp;
718e3744 3310
3f9c7369
DS
3311 paf = peer_af_find (peer, afi, safi);
3312 if (!paf)
718e3744 3313 return;
3f9c7369 3314 subgrp = PAF_SUBGRP(paf);
718e3744 3315
3f9c7369
DS
3316 /*
3317 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
3318 * or a refresh has already been triggered.
3319 */
3320 if (!subgrp || paf->t_announce_route)
718e3744 3321 return;
3322
d889623f 3323 /*
3f9c7369
DS
3324 * Start a timer to stagger/delay the announce. This serves
3325 * two purposes - announcement can potentially be combined for
3326 * multiple peers and the announcement doesn't happen in the
3327 * vty context.
d889623f 3328 */
3f9c7369
DS
3329 THREAD_TIMER_MSEC_ON (master, paf->t_announce_route,
3330 bgp_announce_route_timer_expired, paf,
3331 (subgrp->peer_count == 1) ?
3332 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
3333 BGP_ANNOUNCE_ROUTE_DELAY_MS);
3334}
3335
3336/*
3337 * Announce routes from all AF tables to a peer.
3338 *
3339 * This should ONLY be called when there is a need to refresh the
3340 * routes to the peer based on a policy change for this peer alone
3341 * or a route refresh request received from the peer.
3342 * The operation will result in splitting the peer from its existing
3343 * subgroups and putting it in new subgroups.
3344 */
718e3744 3345void
3346bgp_announce_route_all (struct peer *peer)
3347{
3f9c7369
DS
3348 struct peer_af *paf;
3349 int af;
718e3744 3350 afi_t afi;
3351 safi_t safi;
3352
3353 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3354 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3355 bgp_announce_route (peer, afi, safi);
3356}
6b0655a2 3357
718e3744 3358static void
fee0f4c6 3359bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
8692c506 3360 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
fee0f4c6 3361{
3362 struct bgp_node *rn;
3363 struct bgp_adj_in *ain;
3364
3365 if (! table)
3366 table = rsclient->bgp->rib[afi][safi];
3367
3368 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3369 for (ain = rn->adj_in; ain; ain = ain->next)
3370 {
8692c506 3371 struct bgp_info *ri = rn->info;
d53d8fda 3372 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 3373
fee0f4c6 3374 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
d53d8fda 3375 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
fee0f4c6 3376 }
3377}
3378
3379void
3380bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3381{
3382 struct bgp_table *table;
3383 struct bgp_node *rn;
3384
3385 if (safi != SAFI_MPLS_VPN)
8692c506 3386 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
fee0f4c6 3387
3388 else
3389 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
3390 rn = bgp_route_next (rn))
3391 if ((table = rn->info) != NULL)
8692c506
JBD
3392 {
3393 struct prefix_rd prd;
3394 prd.family = AF_UNSPEC;
3395 prd.prefixlen = 64;
3396 memcpy(&prd.val, rn->p.u.val, 8);
3397
3398 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
3399 }
fee0f4c6 3400}
6b0655a2 3401
fee0f4c6 3402static void
718e3744 3403bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
8692c506 3404 struct bgp_table *table, struct prefix_rd *prd)
718e3744 3405{
3406 int ret;
3407 struct bgp_node *rn;
3408 struct bgp_adj_in *ain;
3409
3410 if (! table)
3411 table = peer->bgp->rib[afi][safi];
3412
3413 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3414 for (ain = rn->adj_in; ain; ain = ain->next)
3415 {
3416 if (ain->peer == peer)
3417 {
8692c506 3418 struct bgp_info *ri = rn->info;
d53d8fda 3419 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 3420
a82478b9
DS
3421 ret = bgp_update (peer, &rn->p, ri->addpath_rx_id, ain->attr,
3422 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
d53d8fda 3423 prd, tag, 1);
8692c506 3424
718e3744 3425 if (ret < 0)
3426 {
3427 bgp_unlock_node (rn);
3428 return;
3429 }
3430 continue;
3431 }
3432 }
3433}
3434
3435void
3436bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
3437{
3438 struct bgp_node *rn;
3439 struct bgp_table *table;
3440
3441 if (peer->status != Established)
3442 return;
3443
3444 if (safi != SAFI_MPLS_VPN)
8692c506 3445 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
718e3744 3446 else
3447 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3448 rn = bgp_route_next (rn))
3449 if ((table = rn->info) != NULL)
8692c506
JBD
3450 {
3451 struct prefix_rd prd;
3452 prd.family = AF_UNSPEC;
3453 prd.prefixlen = 64;
3454 memcpy(&prd.val, rn->p.u.val, 8);
3455
3456 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
3457 }
718e3744 3458}
6b0655a2 3459
228da428
CC
3460
3461struct bgp_clear_node_queue
3462{
3463 struct bgp_node *rn;
3464 enum bgp_clear_route_type purpose;
3465};
3466
200df115 3467static wq_item_status
0fb58d5d 3468bgp_clear_route_node (struct work_queue *wq, void *data)
200df115 3469{
228da428
CC
3470 struct bgp_clear_node_queue *cnq = data;
3471 struct bgp_node *rn = cnq->rn;
64e580a7 3472 struct peer *peer = wq->spec.data;
718e3744 3473 struct bgp_info *ri;
67174041
AS
3474 afi_t afi = bgp_node_table (rn)->afi;
3475 safi_t safi = bgp_node_table (rn)->safi;
200df115 3476
64e580a7 3477 assert (rn && peer);
200df115 3478
64e580a7 3479 for (ri = rn->info; ri; ri = ri->next)
228da428 3480 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
200df115 3481 {
3482 /* graceful restart STALE flag set. */
64e580a7
PJ
3483 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
3484 && peer->nsf[afi][safi]
200df115 3485 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
1a392d46
PJ
3486 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
3487 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
200df115 3488 else
64e580a7 3489 bgp_rib_remove (rn, ri, peer, afi, safi);
200df115 3490 break;
3491 }
200df115 3492 return WQ_SUCCESS;
3493}
3494
3495static void
0fb58d5d 3496bgp_clear_node_queue_del (struct work_queue *wq, void *data)
200df115 3497{
228da428
CC
3498 struct bgp_clear_node_queue *cnq = data;
3499 struct bgp_node *rn = cnq->rn;
67174041 3500 struct bgp_table *table = bgp_node_table (rn);
64e580a7
PJ
3501
3502 bgp_unlock_node (rn);
228da428
CC
3503 bgp_table_unlock (table);
3504 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
200df115 3505}
3506
3507static void
94f2b392 3508bgp_clear_node_complete (struct work_queue *wq)
200df115 3509{
64e580a7
PJ
3510 struct peer *peer = wq->spec.data;
3511
3e0c78ef 3512 /* Tickle FSM to start moving again */
ca058a30 3513 BGP_EVENT_ADD (peer, Clearing_Completed);
228da428
CC
3514
3515 peer_unlock (peer); /* bgp_clear_route */
200df115 3516}
3517
3518static void
64e580a7 3519bgp_clear_node_queue_init (struct peer *peer)
200df115 3520{
a2943657 3521 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
64e580a7 3522
a2943657 3523 snprintf (wname, sizeof(wname), "clear %s", peer->host);
64e580a7
PJ
3524#undef CLEAR_QUEUE_NAME_LEN
3525
3526 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
200df115 3527 {
3528 zlog_err ("%s: Failed to allocate work queue", __func__);
3529 exit (1);
3530 }
64e580a7
PJ
3531 peer->clear_node_queue->spec.hold = 10;
3532 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
3533 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
3534 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
3535 peer->clear_node_queue->spec.max_retries = 0;
3536
3537 /* we only 'lock' this peer reference when the queue is actually active */
3538 peer->clear_node_queue->spec.data = peer;
200df115 3539}
718e3744 3540
200df115 3541static void
3542bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
228da428
CC
3543 struct bgp_table *table, struct peer *rsclient,
3544 enum bgp_clear_route_type purpose)
200df115 3545{
200df115 3546 struct bgp_node *rn;
3547
f2c31acb 3548
718e3744 3549 if (! table)
fee0f4c6 3550 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
64e580a7 3551
6cf159b9 3552 /* If still no table => afi/safi isn't configured at all or smth. */
3553 if (! table)
3554 return;
65ca75e0
PJ
3555
3556 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3557 {
f2c31acb
PJ
3558 struct bgp_info *ri;
3559 struct bgp_adj_in *ain;
3560 struct bgp_adj_out *aout;
f2c31acb
PJ
3561
3562 /* XXX:TODO: This is suboptimal, every non-empty route_node is
3563 * queued for every clearing peer, regardless of whether it is
3564 * relevant to the peer at hand.
3565 *
3566 * Overview: There are 3 different indices which need to be
3567 * scrubbed, potentially, when a peer is removed:
3568 *
3569 * 1 peer's routes visible via the RIB (ie accepted routes)
3570 * 2 peer's routes visible by the (optional) peer's adj-in index
3571 * 3 other routes visible by the peer's adj-out index
3572 *
3573 * 3 there is no hurry in scrubbing, once the struct peer is
3574 * removed from bgp->peer, we could just GC such deleted peer's
3575 * adj-outs at our leisure.
3576 *
3577 * 1 and 2 must be 'scrubbed' in some way, at least made
3578 * invisible via RIB index before peer session is allowed to be
3579 * brought back up. So one needs to know when such a 'search' is
3580 * complete.
3581 *
3582 * Ideally:
3583 *
3584 * - there'd be a single global queue or a single RIB walker
3585 * - rather than tracking which route_nodes still need to be
3586 * examined on a peer basis, we'd track which peers still
3587 * aren't cleared
3588 *
3589 * Given that our per-peer prefix-counts now should be reliable,
3590 * this may actually be achievable. It doesn't seem to be a huge
3591 * problem at this time,
3592 */
24e50f20
JBD
3593 for (ain = rn->adj_in; ain; ain = ain->next)
3594 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
3595 {
3596 bgp_adj_in_remove (rn, ain);
3597 bgp_unlock_node (rn);
3598 break;
3599 }
3f9c7369
DS
3600
3601 /*
3602 * Can't do this anymore. adj-outs are not maintained per peer.
3603 *
24e50f20
JBD
3604 for (aout = rn->adj_out; aout; aout = aout->next)
3605 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
3606 {
3607 bgp_adj_out_remove (rn, aout, peer, afi, safi);
3608 bgp_unlock_node (rn);
3609 break;
3610 }
3f9c7369 3611 */
f2c31acb 3612 for (ri = rn->info; ri; ri = ri->next)
228da428 3613 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
f2c31acb 3614 {
228da428
CC
3615 struct bgp_clear_node_queue *cnq;
3616
3617 /* both unlocked in bgp_clear_node_queue_del */
67174041 3618 bgp_table_lock (bgp_node_table (rn));
228da428
CC
3619 bgp_lock_node (rn);
3620 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
3621 sizeof (struct bgp_clear_node_queue));
3622 cnq->rn = rn;
3623 cnq->purpose = purpose;
3624 work_queue_add (peer->clear_node_queue, cnq);
3625 break;
f2c31acb 3626 }
65ca75e0
PJ
3627 }
3628 return;
3629}
3630
3631void
228da428
CC
3632bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
3633 enum bgp_clear_route_type purpose)
65ca75e0
PJ
3634{
3635 struct bgp_node *rn;
3636 struct bgp_table *table;
3637 struct peer *rsclient;
3638 struct listnode *node, *nnode;
6cf159b9 3639
64e580a7
PJ
3640 if (peer->clear_node_queue == NULL)
3641 bgp_clear_node_queue_init (peer);
200df115 3642
ca058a30
PJ
3643 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3644 * Idle until it receives a Clearing_Completed event. This protects
3645 * against peers which flap faster than we can we clear, which could
3646 * lead to:
64e580a7
PJ
3647 *
3648 * a) race with routes from the new session being installed before
3649 * clear_route_node visits the node (to delete the route of that
3650 * peer)
3651 * b) resource exhaustion, clear_route_node likely leads to an entry
3652 * on the process_main queue. Fast-flapping could cause that queue
3653 * to grow and grow.
200df115 3654 */
ca058a30
PJ
3655 if (!peer->clear_node_queue->thread)
3656 peer_lock (peer); /* bgp_clear_node_complete */
fee0f4c6 3657
228da428 3658 switch (purpose)
fee0f4c6 3659 {
228da428
CC
3660 case BGP_CLEAR_ROUTE_NORMAL:
3661 if (safi != SAFI_MPLS_VPN)
3662 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3663 else
3664 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3665 rn = bgp_route_next (rn))
3666 if ((table = rn->info) != NULL)
3667 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3668
3669 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3670 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3671 PEER_FLAG_RSERVER_CLIENT))
3672 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3673 break;
3674
3675 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
3676 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3677 break;
3678
3679 default:
3680 assert (0);
3681 break;
fee0f4c6 3682 }
65ca75e0 3683
ca058a30 3684 /* If no routes were cleared, nothing was added to workqueue, the
f2c31acb
PJ
3685 * completion function won't be run by workqueue code - call it here.
3686 * XXX: Actually, this assumption doesn't hold, see
3687 * bgp_clear_route_table(), we queue all non-empty nodes.
ca058a30
PJ
3688 *
3689 * Additionally, there is a presumption in FSM that clearing is only
f2c31acb
PJ
3690 * really needed if peer state is Established - peers in
3691 * pre-Established states shouldn't have any route-update state
3692 * associated with them (in or out).
ca058a30 3693 *
f2c31acb
PJ
3694 * We still can get here in pre-Established though, through
3695 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
3696 * check to ensure the assumption above holds.
ca058a30
PJ
3697 *
3698 * At some future point, this check could be move to the top of the
3699 * function, and do a quick early-return when state is
3700 * pre-Established, avoiding above list and table scans. Once we're
3701 * sure it is safe..
65ca75e0
PJ
3702 */
3703 if (!peer->clear_node_queue->thread)
3704 bgp_clear_node_complete (peer->clear_node_queue);
718e3744 3705}
3706
3707void
3708bgp_clear_route_all (struct peer *peer)
3709{
3710 afi_t afi;
3711 safi_t safi;
3712
3713 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3714 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
228da428 3715 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
718e3744 3716}
3717
3718void
3719bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3720{
3721 struct bgp_table *table;
3722 struct bgp_node *rn;
3723 struct bgp_adj_in *ain;
3724
3725 table = peer->bgp->rib[afi][safi];
3726
3727 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3728 for (ain = rn->adj_in; ain ; ain = ain->next)
3729 if (ain->peer == peer)
3730 {
3731 bgp_adj_in_remove (rn, ain);
3732 bgp_unlock_node (rn);
3733 break;
3734 }
3735}
93406d87 3736
3737void
3738bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3739{
3740 struct bgp_node *rn;
3741 struct bgp_info *ri;
3742 struct bgp_table *table;
3743
3744 table = peer->bgp->rib[afi][safi];
3745
3746 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3747 {
3748 for (ri = rn->info; ri; ri = ri->next)
3749 if (ri->peer == peer)
3750 {
3751 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3752 bgp_rib_remove (rn, ri, peer, afi, safi);
3753 break;
3754 }
3755 }
3756}
6b0655a2 3757
718e3744 3758/* Delete all kernel routes. */
3759void
66e5cd87 3760bgp_cleanup_routes (void)
718e3744 3761{
3762 struct bgp *bgp;
1eb8ef25 3763 struct listnode *node, *nnode;
718e3744 3764 struct bgp_node *rn;
3765 struct bgp_table *table;
3766 struct bgp_info *ri;
3767
1eb8ef25 3768 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 3769 {
3770 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3771
3772 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3773 for (ri = rn->info; ri; ri = ri->next)
3774 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3775 && ri->type == ZEBRA_ROUTE_BGP
3776 && ri->sub_type == BGP_ROUTE_NORMAL)
5a616c08 3777 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
718e3744 3778
3779 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3780
3781 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3782 for (ri = rn->info; ri; ri = ri->next)
3783 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3784 && ri->type == ZEBRA_ROUTE_BGP
3785 && ri->sub_type == BGP_ROUTE_NORMAL)
5a616c08 3786 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
718e3744 3787 }
3788}
3789
3790void
66e5cd87 3791bgp_reset (void)
718e3744 3792{
3793 vty_reset ();
3794 bgp_zclient_reset ();
3795 access_list_reset ();
3796 prefix_list_reset ();
3797}
6b0655a2 3798
718e3744 3799/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3800 value. */
3801int
3802bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3803{
3804 u_char *pnt;
3805 u_char *lim;
3806 struct prefix p;
3807 int psize;
3808 int ret;
a82478b9
DS
3809 afi_t afi;
3810 safi_t safi;
3811 u_char addpath_encoded;
3812 u_int32_t addpath_id;
718e3744 3813
3814 /* Check peer status. */
3815 if (peer->status != Established)
3816 return 0;
3817
3818 pnt = packet->nlri;
3819 lim = pnt + packet->length;
a82478b9
DS
3820 afi = packet->afi;
3821 safi = packet->safi;
3822 addpath_id = 0;
3823
3824 addpath_encoded = (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3825 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
718e3744 3826
3827 for (; pnt < lim; pnt += psize)
3828 {
3829 /* Clear prefix structure. */
3830 memset (&p, 0, sizeof (struct prefix));
3831
a82478b9
DS
3832 if (addpath_encoded)
3833 {
3834 addpath_id = ntohl(*((uint32_t*) pnt));
3835 pnt += BGP_ADDPATH_ID_LEN;
3836 }
3837
718e3744 3838 /* Fetch prefix length. */
3839 p.prefixlen = *pnt++;
a82478b9 3840 p.family = afi2family (afi);
718e3744 3841
3842 /* Already checked in nlri_sanity_check(). We do double check
3843 here. */
a82478b9
DS
3844 if ((afi == AFI_IP && p.prefixlen > 32)
3845 || (afi == AFI_IP6 && p.prefixlen > 128))
718e3744 3846 return -1;
3847
3848 /* Packet size overflow check. */
3849 psize = PSIZE (p.prefixlen);
3850
3851 /* When packet overflow occur return immediately. */
3852 if (pnt + psize > lim)
3853 return -1;
3854
3855 /* Fetch prefix from NLRI packet. */
3856 memcpy (&p.u.prefix, pnt, psize);
3857
3858 /* Check address. */
a82478b9 3859 if (afi == AFI_IP && safi == SAFI_UNICAST)
718e3744 3860 {
3861 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3862 {
f5ba3874 3863 /*
3864 * From draft-ietf-idr-bgp4-22, Section 6.3:
3865 * If a BGP router receives an UPDATE message with a
3866 * semantically incorrect NLRI field, in which a prefix is
3867 * semantically incorrect (eg. an unexpected multicast IP
3868 * address), it should ignore the prefix.
3869 */
16286195
DS
3870 zlog_err ("IPv4 unicast NLRI is multicast address %s",
3871 inet_ntoa (p.u.prefix4));
f5ba3874 3872
718e3744 3873 return -1;
3874 }
3875 }
3876
3877#ifdef HAVE_IPV6
3878 /* Check address. */
a82478b9 3879 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
718e3744 3880 {
3881 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3882 {
3883 char buf[BUFSIZ];
3884
16286195
DS
3885 zlog_warn ("IPv6 link-local NLRI received %s ignore this NLRI",
3886 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
718e3744 3887
3888 continue;
3889 }
3890 }
3891#endif /* HAVE_IPV6 */
3892
3893 /* Normal process. */
3894 if (attr)
a82478b9 3895 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
718e3744 3896 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3897 else
a82478b9 3898 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
718e3744 3899 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3900
3901 /* Address family configuration mismatch or maximum-prefix count
3902 overflow. */
3903 if (ret < 0)
3904 return -1;
3905 }
3906
3907 /* Packet length consistency check. */
3908 if (pnt != lim)
3909 return -1;
3910
3911 return 0;
3912}
3913
3914/* NLRI encode syntax check routine. */
3915int
a82478b9 3916bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi, u_char *pnt,
d889623f 3917 bgp_size_t length, int *numpfx)
718e3744 3918{
3919 u_char *end;
3920 u_char prefixlen;
3921 int psize;
a82478b9 3922 u_char addpath_encoded;
718e3744 3923
d889623f 3924 *numpfx = 0;
718e3744 3925 end = pnt + length;
3926
a82478b9
DS
3927 addpath_encoded = (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3928 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3929
718e3744 3930 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3931 syntactic validity. If the field is syntactically incorrect,
3932 then the Error Subcode is set to Invalid Network Field. */
3933
3934 while (pnt < end)
3935 {
a82478b9
DS
3936 /* If the NLRI is encoded using addpath then the first 4 bytes are
3937 * the addpath ID. */
3938 if (addpath_encoded)
3939 pnt += BGP_ADDPATH_ID_LEN;
3940
718e3744 3941 prefixlen = *pnt++;
3942
3943 /* Prefix length check. */
3944 if ((afi == AFI_IP && prefixlen > 32)
3945 || (afi == AFI_IP6 && prefixlen > 128))
3946 {
16286195 3947 zlog_err ("%s [Error] Update packet error (wrong prefix length %d)",
718e3744 3948 peer->host, prefixlen);
3949 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3950 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3951 return -1;
3952 }
3953
3954 /* Packet size overflow check. */
3955 psize = PSIZE (prefixlen);
3956
3957 if (pnt + psize > end)
3958 {
16286195 3959 zlog_err ("%s [Error] Update packet error"
718e3744 3960 " (prefix data overflow prefix size is %d)",
3961 peer->host, psize);
3962 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3963 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3964 return -1;
3965 }
3966
3967 pnt += psize;
d889623f 3968 (*numpfx)++;
718e3744 3969 }
3970
3971 /* Packet length consistency check. */
3972 if (pnt != end)
3973 {
16286195 3974 zlog_err ("%s [Error] Update packet error"
718e3744 3975 " (prefix length mismatch with total length)",
3976 peer->host);
3977 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3978 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3979 return -1;
3980 }
3981 return 0;
3982}
6b0655a2 3983
94f2b392 3984static struct bgp_static *
66e5cd87 3985bgp_static_new (void)
718e3744 3986{
393deb9b 3987 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
718e3744 3988}
3989
94f2b392 3990static void
718e3744 3991bgp_static_free (struct bgp_static *bgp_static)
3992{
3993 if (bgp_static->rmap.name)
3994 free (bgp_static->rmap.name);
3995 XFREE (MTYPE_BGP_STATIC, bgp_static);
3996}
3997
94f2b392 3998static void
fee0f4c6 3999bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
4000 struct prefix *p, afi_t afi, safi_t safi)
4001{
4002 struct bgp_node *rn;
4003 struct bgp_info *ri;
4004
4005 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
4006
4007 /* Check selected route and self inserted route. */
4008 for (ri = rn->info; ri; ri = ri->next)
4009 if (ri->peer == bgp->peer_self
4010 && ri->type == ZEBRA_ROUTE_BGP
4011 && ri->sub_type == BGP_ROUTE_STATIC)
4012 break;
4013
4014 /* Withdraw static BGP route from routing table. */
4015 if (ri)
4016 {
fee0f4c6 4017 bgp_info_delete (rn, ri);
1a392d46 4018 bgp_process (bgp, rn, afi, safi);
fee0f4c6 4019 }
4020
4021 /* Unlock bgp_node_lookup. */
4022 bgp_unlock_node (rn);
4023}
4024
94f2b392 4025static void
fee0f4c6 4026bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
fb982c25
PJ
4027 struct bgp_static *bgp_static,
4028 afi_t afi, safi_t safi)
fee0f4c6 4029{
4030 struct bgp_node *rn;
4031 struct bgp_info *ri;
4032 struct bgp_info *new;
4033 struct bgp_info info;
fee0f4c6 4034 struct attr *attr_new;
e16a4133 4035 struct attr attr;
558d1fec
JBD
4036 struct attr new_attr;
4037 struct attr_extra new_extra;
fee0f4c6 4038 struct bgp *bgp;
4039 int ret;
4040 char buf[SU_ADDRSTRLEN];
4041
4042 bgp = rsclient->bgp;
4043
06e110f9
PJ
4044 assert (bgp_static);
4045 if (!bgp_static)
4046 return;
4047
fee0f4c6 4048 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
4049
4050 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
06e110f9
PJ
4051
4052 attr.nexthop = bgp_static->igpnexthop;
4053 attr.med = bgp_static->igpmetric;
4054 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
41367172 4055
41367172
PJ
4056 if (bgp_static->atomic)
4057 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
4058
fee0f4c6 4059 /* Apply network route-map for export to this rsclient. */
4060 if (bgp_static->rmap.name)
4061 {
fb982c25 4062 struct attr attr_tmp = attr;
fee0f4c6 4063 info.peer = rsclient;
fb982c25
PJ
4064 info.attr = &attr_tmp;
4065
fee0f4c6 4066 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
4067 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
4068
4069 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
4070
4071 rsclient->rmap_type = 0;
4072
4073 if (ret == RMAP_DENYMATCH)
4074 {
4075 /* Free uninterned attribute. */
fb982c25 4076 bgp_attr_flush (&attr_tmp);
fee0f4c6 4077
4078 /* Unintern original. */
f6f434b2 4079 aspath_unintern (&attr.aspath);
fee0f4c6 4080 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
fb982c25
PJ
4081 bgp_attr_extra_free (&attr);
4082
fee0f4c6 4083 return;
4084 }
fb982c25 4085 attr_new = bgp_attr_intern (&attr_tmp);
fee0f4c6 4086 }
4087 else
4088 attr_new = bgp_attr_intern (&attr);
558d1fec
JBD
4089
4090 new_attr.extra = &new_extra;
7badc263 4091 bgp_attr_dup(&new_attr, attr_new);
fb982c25 4092
fee0f4c6 4093 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
4094
fb982c25
PJ
4095 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
4096 == RMAP_DENY)
4097 {
fee0f4c6 4098 /* This BGP update is filtered. Log the reason then update BGP entry. */
3f9c7369 4099 if (bgp_debug_update(rsclient, p, NULL, 1))
16286195
DS
4100 zlog_debug ("Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
4101 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
4102 p->prefixlen, rsclient->host);
fee0f4c6 4103
4104 bgp->peer_self->rmap_type = 0;
4105
f6f434b2
PJ
4106 bgp_attr_unintern (&attr_new);
4107 aspath_unintern (&attr.aspath);
fb982c25 4108 bgp_attr_extra_free (&attr);
fee0f4c6 4109
4110 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
4111
4112 return;
fb982c25 4113 }
fee0f4c6 4114
4115 bgp->peer_self->rmap_type = 0;
4116
f6f434b2 4117 bgp_attr_unintern (&attr_new);
fee0f4c6 4118 attr_new = bgp_attr_intern (&new_attr);
4119
4120 for (ri = rn->info; ri; ri = ri->next)
4121 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
4122 && ri->sub_type == BGP_ROUTE_STATIC)
4123 break;
4124
4125 if (ri)
4126 {
8d45210e
AS
4127 if (attrhash_cmp (ri->attr, attr_new) &&
4128 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
fee0f4c6 4129 {
4130 bgp_unlock_node (rn);
f6f434b2
PJ
4131 bgp_attr_unintern (&attr_new);
4132 aspath_unintern (&attr.aspath);
fb982c25 4133 bgp_attr_extra_free (&attr);
fee0f4c6 4134 return;
4135 }
4136 else
4137 {
4138 /* The attribute is changed. */
1a392d46 4139 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
fee0f4c6 4140
4141 /* Rewrite BGP route information. */
8d45210e
AS
4142 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
4143 bgp_info_restore(rn, ri);
f6f434b2 4144 bgp_attr_unintern (&ri->attr);
fee0f4c6 4145 ri->attr = attr_new;
65957886 4146 ri->uptime = bgp_clock ();
fee0f4c6 4147
fc9a856f
DS
4148 /* Nexthop reachability check. */
4149 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4150 {
4151 if (bgp_find_or_add_nexthop (afi, ri, NULL, 0))
4152 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
4153 else
4154 {
4155 if (BGP_DEBUG(nht, NHT))
4156 {
4157 char buf1[INET6_ADDRSTRLEN];
4158 inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
4159 buf1, INET6_ADDRSTRLEN);
4160 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
4161 }
4162 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
4163 }
4164 }
fee0f4c6 4165 /* Process change. */
4166 bgp_process (bgp, rn, afi, safi);
4167 bgp_unlock_node (rn);
f6f434b2 4168 aspath_unintern (&attr.aspath);
fb982c25 4169 bgp_attr_extra_free (&attr);
fee0f4c6 4170 return;
fb982c25 4171 }
fee0f4c6 4172 }
fb018d25 4173
fee0f4c6 4174 /* Make new BGP info. */
7c8ff89e 4175 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
fb018d25 4176 attr_new, rn);
fc9a856f
DS
4177 /* Nexthop reachability check. */
4178 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4179 {
4180 if (bgp_find_or_add_nexthop (afi, new, NULL, 0))
4181 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
4182 else
4183 {
4184 if (BGP_DEBUG(nht, NHT))
4185 {
4186 char buf1[INET6_ADDRSTRLEN];
4187 inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
4188 buf1, INET6_ADDRSTRLEN);
4189 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
4190 }
4191 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
4192 }
4193 }
4194 else
4195 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
fee0f4c6 4196
4197 /* Register new BGP information. */
4198 bgp_info_add (rn, new);
200df115 4199
4200 /* route_node_get lock */
4201 bgp_unlock_node (rn);
4202
fee0f4c6 4203 /* Process change. */
4204 bgp_process (bgp, rn, afi, safi);
4205
4206 /* Unintern original. */
f6f434b2 4207 aspath_unintern (&attr.aspath);
fb982c25 4208 bgp_attr_extra_free (&attr);
fee0f4c6 4209}
4210
94f2b392 4211static void
fee0f4c6 4212bgp_static_update_main (struct bgp *bgp, struct prefix *p,
fc9a856f 4213 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
718e3744 4214{
4215 struct bgp_node *rn;
4216 struct bgp_info *ri;
4217 struct bgp_info *new;
4218 struct bgp_info info;
e16a4133 4219 struct attr attr;
718e3744 4220 struct attr *attr_new;
4221 int ret;
4222
dd8103a9
PJ
4223 assert (bgp_static);
4224 if (!bgp_static)
4225 return;
4226
fee0f4c6 4227 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 4228
4229 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
dd8103a9
PJ
4230
4231 attr.nexthop = bgp_static->igpnexthop;
4232 attr.med = bgp_static->igpmetric;
4233 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
718e3744 4234
41367172
PJ
4235 if (bgp_static->atomic)
4236 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
4237
718e3744 4238 /* Apply route-map. */
4239 if (bgp_static->rmap.name)
4240 {
fb982c25 4241 struct attr attr_tmp = attr;
718e3744 4242 info.peer = bgp->peer_self;
286e1e71 4243 info.attr = &attr_tmp;
718e3744 4244
fee0f4c6 4245 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
4246
718e3744 4247 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
286e1e71 4248
fee0f4c6 4249 bgp->peer_self->rmap_type = 0;
4250
718e3744 4251 if (ret == RMAP_DENYMATCH)
4252 {
4253 /* Free uninterned attribute. */
286e1e71 4254 bgp_attr_flush (&attr_tmp);
718e3744 4255
4256 /* Unintern original. */
f6f434b2 4257 aspath_unintern (&attr.aspath);
fb982c25 4258 bgp_attr_extra_free (&attr);
718e3744 4259 bgp_static_withdraw (bgp, p, afi, safi);
4260 return;
4261 }
286e1e71 4262 attr_new = bgp_attr_intern (&attr_tmp);
718e3744 4263 }
286e1e71 4264 else
4265 attr_new = bgp_attr_intern (&attr);
718e3744 4266
4267 for (ri = rn->info; ri; ri = ri->next)
4268 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
4269 && ri->sub_type == BGP_ROUTE_STATIC)
4270 break;
4271
4272 if (ri)
4273 {
8d45210e
AS
4274 if (attrhash_cmp (ri->attr, attr_new) &&
4275 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
718e3744 4276 {
4277 bgp_unlock_node (rn);
f6f434b2
PJ
4278 bgp_attr_unintern (&attr_new);
4279 aspath_unintern (&attr.aspath);
fb982c25 4280 bgp_attr_extra_free (&attr);
718e3744 4281 return;
4282 }
4283 else
4284 {
4285 /* The attribute is changed. */
1a392d46 4286 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4287
4288 /* Rewrite BGP route information. */
8d45210e
AS
4289 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
4290 bgp_info_restore(rn, ri);
4291 else
4292 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
f6f434b2 4293 bgp_attr_unintern (&ri->attr);
718e3744 4294 ri->attr = attr_new;
65957886 4295 ri->uptime = bgp_clock ();
718e3744 4296
fc9a856f
DS
4297 /* Nexthop reachability check. */
4298 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4299 {
4300 if (bgp_find_or_add_nexthop (afi, ri, NULL, 0))
4301 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
4302 else
4303 {
4304 if (BGP_DEBUG(nht, NHT))
4305 {
4306 char buf1[INET6_ADDRSTRLEN];
4307 inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
4308 buf1, INET6_ADDRSTRLEN);
4309 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
4310 }
4311 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
4312 }
4313 }
718e3744 4314 /* Process change. */
4315 bgp_aggregate_increment (bgp, p, ri, afi, safi);
4316 bgp_process (bgp, rn, afi, safi);
4317 bgp_unlock_node (rn);
f6f434b2 4318 aspath_unintern (&attr.aspath);
fb982c25 4319 bgp_attr_extra_free (&attr);
718e3744 4320 return;
4321 }
4322 }
4323
4324 /* Make new BGP info. */
7c8ff89e 4325 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
fb018d25 4326 rn);
fc9a856f
DS
4327 /* Nexthop reachability check. */
4328 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4329 {
4330 if (bgp_find_or_add_nexthop (afi, new, NULL, 0))
4331 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
4332 else
4333 {
4334 if (BGP_DEBUG(nht, NHT))
4335 {
4336 char buf1[INET6_ADDRSTRLEN];
4337 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1,
4338 INET6_ADDRSTRLEN);
4339 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
4340 }
4341 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
4342 }
4343 }
4344 else
4345 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 4346
4347 /* Aggregate address increment. */
4348 bgp_aggregate_increment (bgp, p, new, afi, safi);
4349
4350 /* Register new BGP information. */
4351 bgp_info_add (rn, new);
200df115 4352
4353 /* route_node_get lock */
4354 bgp_unlock_node (rn);
4355
718e3744 4356 /* Process change. */
4357 bgp_process (bgp, rn, afi, safi);
4358
4359 /* Unintern original. */
f6f434b2 4360 aspath_unintern (&attr.aspath);
fb982c25 4361 bgp_attr_extra_free (&attr);
718e3744 4362}
4363
fee0f4c6 4364void
4365bgp_static_update (struct bgp *bgp, struct prefix *p,
4366 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
4367{
4368 struct peer *rsclient;
1eb8ef25 4369 struct listnode *node, *nnode;
fee0f4c6 4370
4371 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
4372
1eb8ef25 4373 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 4374 {
da5b30f6
PJ
4375 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
4376 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
fee0f4c6 4377 }
4378}
4379
94f2b392 4380static void
4c9641ba
ML
4381bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
4382 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 4383{
4384 struct bgp_node *rn;
4385 struct bgp_info *new;
fb982c25 4386
fee0f4c6 4387 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 4388
4389 /* Make new BGP info. */
7c8ff89e 4390 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
fb018d25
DS
4391 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
4392
718e3744 4393 SET_FLAG (new->flags, BGP_INFO_VALID);
fb982c25
PJ
4394 new->extra = bgp_info_extra_new();
4395 memcpy (new->extra->tag, tag, 3);
718e3744 4396
4397 /* Aggregate address increment. */
200df115 4398 bgp_aggregate_increment (bgp, p, new, afi, safi);
718e3744 4399
4400 /* Register new BGP information. */
200df115 4401 bgp_info_add (rn, new);
718e3744 4402
200df115 4403 /* route_node_get lock */
4404 bgp_unlock_node (rn);
4405
718e3744 4406 /* Process change. */
4407 bgp_process (bgp, rn, afi, safi);
4408}
4409
4410void
4411bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
4412 safi_t safi)
4413{
4414 struct bgp_node *rn;
4415 struct bgp_info *ri;
4416
fee0f4c6 4417 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 4418
4419 /* Check selected route and self inserted route. */
4420 for (ri = rn->info; ri; ri = ri->next)
4421 if (ri->peer == bgp->peer_self
4422 && ri->type == ZEBRA_ROUTE_BGP
4423 && ri->sub_type == BGP_ROUTE_STATIC)
4424 break;
4425
4426 /* Withdraw static BGP route from routing table. */
4427 if (ri)
4428 {
4429 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
fc9a856f 4430 bgp_unlink_nexthop(ri);
718e3744 4431 bgp_info_delete (rn, ri);
1a392d46 4432 bgp_process (bgp, rn, afi, safi);
718e3744 4433 }
4434
4435 /* Unlock bgp_node_lookup. */
4436 bgp_unlock_node (rn);
4437}
4438
fee0f4c6 4439void
4440bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
4441{
4442 struct bgp_static *bgp_static;
4443 struct bgp *bgp;
4444 struct bgp_node *rn;
4445 struct prefix *p;
4446
4447 bgp = rsclient->bgp;
4448
4449 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4450 if ((bgp_static = rn->info) != NULL)
4451 {
4452 p = &rn->p;
4453
4454 bgp_static_update_rsclient (rsclient, p, bgp_static,
4455 afi, safi);
4456 }
4457}
4458
94f2b392 4459static void
4c9641ba
ML
4460bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
4461 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 4462{
4463 struct bgp_node *rn;
4464 struct bgp_info *ri;
4465
fee0f4c6 4466 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 4467
4468 /* Check selected route and self inserted route. */
4469 for (ri = rn->info; ri; ri = ri->next)
4470 if (ri->peer == bgp->peer_self
4471 && ri->type == ZEBRA_ROUTE_BGP
4472 && ri->sub_type == BGP_ROUTE_STATIC)
4473 break;
4474
4475 /* Withdraw static BGP route from routing table. */
4476 if (ri)
4477 {
4478 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
718e3744 4479 bgp_info_delete (rn, ri);
1a392d46 4480 bgp_process (bgp, rn, afi, safi);
718e3744 4481 }
4482
4483 /* Unlock bgp_node_lookup. */
4484 bgp_unlock_node (rn);
4485}
4486
4487/* Configure static BGP network. When user don't run zebra, static
4488 route should be installed as valid. */
94f2b392 4489static int
fd79ac91 4490bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
c8f3fe30 4491 afi_t afi, safi_t safi, const char *rmap, int backdoor)
718e3744 4492{
4493 int ret;
4494 struct prefix p;
4495 struct bgp_static *bgp_static;
4496 struct bgp_node *rn;
41367172 4497 u_char need_update = 0;
718e3744 4498
4499 /* Convert IP prefix string to struct prefix. */
4500 ret = str2prefix (ip_str, &p);
4501 if (! ret)
4502 {
4503 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4504 return CMD_WARNING;
4505 }
4506#ifdef HAVE_IPV6
4507 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4508 {
4509 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4510 VTY_NEWLINE);
4511 return CMD_WARNING;
4512 }
4513#endif /* HAVE_IPV6 */
4514
4515 apply_mask (&p);
4516
4517 /* Set BGP static route configuration. */
4518 rn = bgp_node_get (bgp->route[afi][safi], &p);
4519
4520 if (rn->info)
4521 {
4522 /* Configuration change. */
4523 bgp_static = rn->info;
4524
4525 /* Check previous routes are installed into BGP. */
c8f3fe30
PJ
4526 if (bgp_static->valid && bgp_static->backdoor != backdoor)
4527 need_update = 1;
41367172 4528
718e3744 4529 bgp_static->backdoor = backdoor;
41367172 4530
718e3744 4531 if (rmap)
4532 {
4533 if (bgp_static->rmap.name)
4534 free (bgp_static->rmap.name);
4535 bgp_static->rmap.name = strdup (rmap);
4536 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4537 }
4538 else
4539 {
4540 if (bgp_static->rmap.name)
4541 free (bgp_static->rmap.name);
4542 bgp_static->rmap.name = NULL;
4543 bgp_static->rmap.map = NULL;
4544 bgp_static->valid = 0;
4545 }
4546 bgp_unlock_node (rn);
4547 }
4548 else
4549 {
4550 /* New configuration. */
4551 bgp_static = bgp_static_new ();
4552 bgp_static->backdoor = backdoor;
4553 bgp_static->valid = 0;
4554 bgp_static->igpmetric = 0;
4555 bgp_static->igpnexthop.s_addr = 0;
41367172 4556
718e3744 4557 if (rmap)
4558 {
4559 if (bgp_static->rmap.name)
4560 free (bgp_static->rmap.name);
4561 bgp_static->rmap.name = strdup (rmap);
4562 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4563 }
4564 rn->info = bgp_static;
4565 }
4566
fc9a856f
DS
4567 bgp_static->valid = 1;
4568 if (need_update)
4569 bgp_static_withdraw (bgp, &p, afi, safi);
718e3744 4570
fc9a856f
DS
4571 if (! bgp_static->backdoor)
4572 bgp_static_update (bgp, &p, bgp_static, afi, safi);
718e3744 4573
4574 return CMD_SUCCESS;
4575}
4576
4577/* Configure static BGP network. */
94f2b392 4578static int
fd79ac91 4579bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4c9641ba 4580 afi_t afi, safi_t safi)
718e3744 4581{
4582 int ret;
4583 struct prefix p;
4584 struct bgp_static *bgp_static;
4585 struct bgp_node *rn;
4586
4587 /* Convert IP prefix string to struct prefix. */
4588 ret = str2prefix (ip_str, &p);
4589 if (! ret)
4590 {
4591 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4592 return CMD_WARNING;
4593 }
4594#ifdef HAVE_IPV6
4595 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4596 {
4597 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4598 VTY_NEWLINE);
4599 return CMD_WARNING;
4600 }
4601#endif /* HAVE_IPV6 */
4602
4603 apply_mask (&p);
4604
4605 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4606 if (! rn)
4607 {
4608 vty_out (vty, "%% Can't find specified static route configuration.%s",
4609 VTY_NEWLINE);
4610 return CMD_WARNING;
4611 }
4612
4613 bgp_static = rn->info;
41367172 4614
718e3744 4615 /* Update BGP RIB. */
4616 if (! bgp_static->backdoor)
4617 bgp_static_withdraw (bgp, &p, afi, safi);
4618
4619 /* Clear configuration. */
fc9a856f 4620 bgp_unlink_nexthop(bgp_static);
718e3744 4621 bgp_static_free (bgp_static);
4622 rn->info = NULL;
4623 bgp_unlock_node (rn);
4624 bgp_unlock_node (rn);
4625
4626 return CMD_SUCCESS;
4627}
4628
4629/* Called from bgp_delete(). Delete all static routes from the BGP
4630 instance. */
4631void
4632bgp_static_delete (struct bgp *bgp)
4633{
4634 afi_t afi;
4635 safi_t safi;
4636 struct bgp_node *rn;
4637 struct bgp_node *rm;
4638 struct bgp_table *table;
4639 struct bgp_static *bgp_static;
4640
4641 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4642 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4643 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4644 if (rn->info != NULL)
4645 {
4646 if (safi == SAFI_MPLS_VPN)
4647 {
4648 table = rn->info;
4649
4650 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4651 {
4652 bgp_static = rn->info;
4653 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
4654 AFI_IP, SAFI_MPLS_VPN,
4655 (struct prefix_rd *)&rn->p,
4656 bgp_static->tag);
4657 bgp_static_free (bgp_static);
4658 rn->info = NULL;
4659 bgp_unlock_node (rn);
4660 }
4661 }
4662 else
4663 {
4664 bgp_static = rn->info;
4665 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4666 bgp_static_free (bgp_static);
4667 rn->info = NULL;
4668 bgp_unlock_node (rn);
4669 }
4670 }
4671}
4672
4673int
fd79ac91 4674bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
4675 const char *tag_str)
718e3744 4676{
4677 int ret;
4678 struct prefix p;
4679 struct prefix_rd prd;
4680 struct bgp *bgp;
4681 struct bgp_node *prn;
4682 struct bgp_node *rn;
4683 struct bgp_table *table;
4684 struct bgp_static *bgp_static;
4685 u_char tag[3];
4686
4687 bgp = vty->index;
4688
4689 ret = str2prefix (ip_str, &p);
4690 if (! ret)
4691 {
4692 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4693 return CMD_WARNING;
4694 }
4695 apply_mask (&p);
4696
4697 ret = str2prefix_rd (rd_str, &prd);
4698 if (! ret)
4699 {
4700 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4701 return CMD_WARNING;
4702 }
4703
4704 ret = str2tag (tag_str, tag);
4705 if (! ret)
4706 {
4707 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4708 return CMD_WARNING;
4709 }
4710
4711 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4712 (struct prefix *)&prd);
4713 if (prn->info == NULL)
64e580a7 4714 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
718e3744 4715 else
4716 bgp_unlock_node (prn);
4717 table = prn->info;
4718
4719 rn = bgp_node_get (table, &p);
4720
4721 if (rn->info)
4722 {
4723 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4724 bgp_unlock_node (rn);
4725 }
4726 else
4727 {
4728 /* New configuration. */
4729 bgp_static = bgp_static_new ();
4730 bgp_static->valid = 1;
4731 memcpy (bgp_static->tag, tag, 3);
4732 rn->info = bgp_static;
4733
4734 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4735 }
4736
4737 return CMD_SUCCESS;
4738}
4739
4740/* Configure static BGP network. */
4741int
fd79ac91 4742bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
4743 const char *rd_str, const char *tag_str)
718e3744 4744{
4745 int ret;
4746 struct bgp *bgp;
4747 struct prefix p;
4748 struct prefix_rd prd;
4749 struct bgp_node *prn;
4750 struct bgp_node *rn;
4751 struct bgp_table *table;
4752 struct bgp_static *bgp_static;
4753 u_char tag[3];
4754
4755 bgp = vty->index;
4756
4757 /* Convert IP prefix string to struct prefix. */
4758 ret = str2prefix (ip_str, &p);
4759 if (! ret)
4760 {
4761 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4762 return CMD_WARNING;
4763 }
4764 apply_mask (&p);
4765
4766 ret = str2prefix_rd (rd_str, &prd);
4767 if (! ret)
4768 {
4769 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4770 return CMD_WARNING;
4771 }
4772
4773 ret = str2tag (tag_str, tag);
4774 if (! ret)
4775 {
4776 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4777 return CMD_WARNING;
4778 }
4779
4780 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4781 (struct prefix *)&prd);
4782 if (prn->info == NULL)
64e580a7 4783 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
718e3744 4784 else
4785 bgp_unlock_node (prn);
4786 table = prn->info;
4787
4788 rn = bgp_node_lookup (table, &p);
4789
4790 if (rn)
4791 {
4792 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4793
4794 bgp_static = rn->info;
4795 bgp_static_free (bgp_static);
4796 rn->info = NULL;
4797 bgp_unlock_node (rn);
4798 bgp_unlock_node (rn);
4799 }
4800 else
4801 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4802
4803 return CMD_SUCCESS;
4804}
6b0655a2 4805
73ac8160
DS
4806static int
4807bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4808 const char *rmap_name)
4809{
4810 struct bgp_rmap *rmap;
4811
4812 rmap = &bgp->table_map[afi][safi];
4813 if (rmap_name)
4814 {
4815 if (rmap->name)
4816 free (rmap->name);
4817 rmap->name = strdup (rmap_name);
4818 rmap->map = route_map_lookup_by_name (rmap_name);
4819 }
4820 else
4821 {
4822 if (rmap->name)
4823 free (rmap->name);
4824 rmap->name = NULL;
4825 rmap->map = NULL;
4826 }
4827
4828 bgp_zebra_announce_table(bgp, afi, safi);
4829
4830 return CMD_SUCCESS;
4831}
4832
4833static int
4834bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4835 const char *rmap_name)
4836{
4837 struct bgp_rmap *rmap;
4838
4839 rmap = &bgp->table_map[afi][safi];
4840 if (rmap->name)
4841 free (rmap->name);
4842 rmap->name = NULL;
4843 rmap->map = NULL;
4844
4845 bgp_zebra_announce_table(bgp, afi, safi);
4846
4847 return CMD_SUCCESS;
4848}
4849
4850int
4851bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4852 safi_t safi, int *write)
4853{
4854 if (bgp->table_map[afi][safi].name)
4855 {
4856 bgp_config_write_family_header (vty, afi, safi, write);
4857 vty_out (vty, " table-map %s%s",
4858 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4859 }
4860
4861 return 0;
4862}
4863
4864
4865DEFUN (bgp_table_map,
4866 bgp_table_map_cmd,
4867 "table-map WORD",
4868 "BGP table to RIB route download filter\n"
4869 "Name of the route map\n")
4870{
4871 return bgp_table_map_set (vty, vty->index,
4872 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4873}
4874DEFUN (no_bgp_table_map,
4875 no_bgp_table_map_cmd,
4876 "no table-map WORD",
4877 "BGP table to RIB route download filter\n"
4878 "Name of the route map\n")
4879{
4880 return bgp_table_map_unset (vty, vty->index,
4881 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4882}
4883
718e3744 4884DEFUN (bgp_network,
4885 bgp_network_cmd,
4886 "network A.B.C.D/M",
4887 "Specify a network to announce via BGP\n"
4888 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4889{
4890 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 4891 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4892}
4893
4894DEFUN (bgp_network_route_map,
4895 bgp_network_route_map_cmd,
4896 "network A.B.C.D/M route-map WORD",
4897 "Specify a network to announce via BGP\n"
4898 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4899 "Route-map to modify the attributes\n"
4900 "Name of the route map\n")
4901{
4902 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 4903 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 4904}
4905
4906DEFUN (bgp_network_backdoor,
4907 bgp_network_backdoor_cmd,
4908 "network A.B.C.D/M backdoor",
4909 "Specify a network to announce via BGP\n"
4910 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4911 "Specify a BGP backdoor route\n")
4912{
41367172 4913 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
c8f3fe30 4914 NULL, 1);
718e3744 4915}
4916
4917DEFUN (bgp_network_mask,
4918 bgp_network_mask_cmd,
4919 "network A.B.C.D mask A.B.C.D",
4920 "Specify a network to announce via BGP\n"
4921 "Network number\n"
4922 "Network mask\n"
4923 "Network mask\n")
4924{
4925 int ret;
4926 char prefix_str[BUFSIZ];
41367172 4927
718e3744 4928 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4929 if (! ret)
4930 {
4931 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4932 return CMD_WARNING;
4933 }
4934
4935 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4936 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4937}
4938
4939DEFUN (bgp_network_mask_route_map,
4940 bgp_network_mask_route_map_cmd,
4941 "network A.B.C.D mask A.B.C.D route-map WORD",
4942 "Specify a network to announce via BGP\n"
4943 "Network number\n"
4944 "Network mask\n"
4945 "Network mask\n"
4946 "Route-map to modify the attributes\n"
4947 "Name of the route map\n")
4948{
4949 int ret;
4950 char prefix_str[BUFSIZ];
41367172 4951
718e3744 4952 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4953 if (! ret)
4954 {
4955 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4956 return CMD_WARNING;
4957 }
4958
4959 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4960 AFI_IP, bgp_node_safi (vty), argv[2], 0);
718e3744 4961}
4962
4963DEFUN (bgp_network_mask_backdoor,
4964 bgp_network_mask_backdoor_cmd,
4965 "network A.B.C.D mask A.B.C.D backdoor",
4966 "Specify a network to announce via BGP\n"
4967 "Network number\n"
4968 "Network mask\n"
4969 "Network mask\n"
4970 "Specify a BGP backdoor route\n")
4971{
4972 int ret;
4973 char prefix_str[BUFSIZ];
41367172 4974
718e3744 4975 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4976 if (! ret)
4977 {
4978 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4979 return CMD_WARNING;
4980 }
4981
41367172 4982 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 4983 NULL, 1);
718e3744 4984}
4985
4986DEFUN (bgp_network_mask_natural,
4987 bgp_network_mask_natural_cmd,
4988 "network A.B.C.D",
4989 "Specify a network to announce via BGP\n"
4990 "Network number\n")
4991{
4992 int ret;
4993 char prefix_str[BUFSIZ];
4994
4995 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4996 if (! ret)
4997 {
4998 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4999 return CMD_WARNING;
5000 }
5001
5002 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 5003 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 5004}
5005
5006DEFUN (bgp_network_mask_natural_route_map,
5007 bgp_network_mask_natural_route_map_cmd,
5008 "network A.B.C.D route-map WORD",
5009 "Specify a network to announce via BGP\n"
5010 "Network number\n"
5011 "Route-map to modify the attributes\n"
5012 "Name of the route map\n")
5013{
5014 int ret;
5015 char prefix_str[BUFSIZ];
5016
5017 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
5018 if (! ret)
5019 {
5020 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5021 return CMD_WARNING;
5022 }
5023
5024 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 5025 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 5026}
5027
5028DEFUN (bgp_network_mask_natural_backdoor,
5029 bgp_network_mask_natural_backdoor_cmd,
5030 "network A.B.C.D backdoor",
5031 "Specify a network to announce via BGP\n"
5032 "Network number\n"
5033 "Specify a BGP backdoor route\n")
5034{
5035 int ret;
5036 char prefix_str[BUFSIZ];
5037
5038 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
5039 if (! ret)
5040 {
5041 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5042 return CMD_WARNING;
5043 }
5044
41367172 5045 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 5046 NULL, 1);
718e3744 5047}
5048
5049DEFUN (no_bgp_network,
5050 no_bgp_network_cmd,
5051 "no network A.B.C.D/M",
5052 NO_STR
5053 "Specify a network to announce via BGP\n"
5054 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5055{
5056 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
5057 bgp_node_safi (vty));
5058}
5059
5060ALIAS (no_bgp_network,
5061 no_bgp_network_route_map_cmd,
5062 "no network A.B.C.D/M route-map WORD",
5063 NO_STR
5064 "Specify a network to announce via BGP\n"
5065 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5066 "Route-map to modify the attributes\n"
5067 "Name of the route map\n")
5068
5069ALIAS (no_bgp_network,
5070 no_bgp_network_backdoor_cmd,
5071 "no network A.B.C.D/M backdoor",
5072 NO_STR
5073 "Specify a network to announce via BGP\n"
5074 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5075 "Specify a BGP backdoor route\n")
5076
5077DEFUN (no_bgp_network_mask,
5078 no_bgp_network_mask_cmd,
5079 "no network A.B.C.D mask A.B.C.D",
5080 NO_STR
5081 "Specify a network to announce via BGP\n"
5082 "Network number\n"
5083 "Network mask\n"
5084 "Network mask\n")
5085{
5086 int ret;
5087 char prefix_str[BUFSIZ];
5088
5089 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5090 if (! ret)
5091 {
5092 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5093 return CMD_WARNING;
5094 }
5095
5096 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
5097 bgp_node_safi (vty));
5098}
5099
5100ALIAS (no_bgp_network_mask,
5101 no_bgp_network_mask_route_map_cmd,
5102 "no network A.B.C.D mask A.B.C.D route-map WORD",
5103 NO_STR
5104 "Specify a network to announce via BGP\n"
5105 "Network number\n"
5106 "Network mask\n"
5107 "Network mask\n"
5108 "Route-map to modify the attributes\n"
5109 "Name of the route map\n")
5110
5111ALIAS (no_bgp_network_mask,
5112 no_bgp_network_mask_backdoor_cmd,
5113 "no network A.B.C.D mask A.B.C.D backdoor",
5114 NO_STR
5115 "Specify a network to announce via BGP\n"
5116 "Network number\n"
5117 "Network mask\n"
5118 "Network mask\n"
5119 "Specify a BGP backdoor route\n")
5120
5121DEFUN (no_bgp_network_mask_natural,
5122 no_bgp_network_mask_natural_cmd,
5123 "no network A.B.C.D",
5124 NO_STR
5125 "Specify a network to announce via BGP\n"
5126 "Network number\n")
5127{
5128 int ret;
5129 char prefix_str[BUFSIZ];
5130
5131 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
5132 if (! ret)
5133 {
5134 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5135 return CMD_WARNING;
5136 }
5137
5138 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
5139 bgp_node_safi (vty));
5140}
5141
5142ALIAS (no_bgp_network_mask_natural,
5143 no_bgp_network_mask_natural_route_map_cmd,
5144 "no network A.B.C.D route-map WORD",
5145 NO_STR
5146 "Specify a network to announce via BGP\n"
5147 "Network number\n"
5148 "Route-map to modify the attributes\n"
5149 "Name of the route map\n")
5150
5151ALIAS (no_bgp_network_mask_natural,
5152 no_bgp_network_mask_natural_backdoor_cmd,
5153 "no network A.B.C.D backdoor",
5154 NO_STR
5155 "Specify a network to announce via BGP\n"
5156 "Network number\n"
5157 "Specify a BGP backdoor route\n")
5158
5159#ifdef HAVE_IPV6
5160DEFUN (ipv6_bgp_network,
5161 ipv6_bgp_network_cmd,
5162 "network X:X::X:X/M",
5163 "Specify a network to announce via BGP\n"
5164 "IPv6 prefix <network>/<length>\n")
5165{
73bfe0bd 5166 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
c8f3fe30 5167 NULL, 0);
718e3744 5168}
5169
5170DEFUN (ipv6_bgp_network_route_map,
5171 ipv6_bgp_network_route_map_cmd,
5172 "network X:X::X:X/M route-map WORD",
5173 "Specify a network to announce via BGP\n"
5174 "IPv6 prefix <network>/<length>\n"
5175 "Route-map to modify the attributes\n"
5176 "Name of the route map\n")
5177{
5178 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
c8f3fe30 5179 bgp_node_safi (vty), argv[1], 0);
718e3744 5180}
5181
5182DEFUN (no_ipv6_bgp_network,
5183 no_ipv6_bgp_network_cmd,
5184 "no network X:X::X:X/M",
5185 NO_STR
5186 "Specify a network to announce via BGP\n"
5187 "IPv6 prefix <network>/<length>\n")
5188{
73bfe0bd 5189 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
718e3744 5190}
5191
5192ALIAS (no_ipv6_bgp_network,
5193 no_ipv6_bgp_network_route_map_cmd,
5194 "no network X:X::X:X/M route-map WORD",
5195 NO_STR
5196 "Specify a network to announce via BGP\n"
5197 "IPv6 prefix <network>/<length>\n"
5198 "Route-map to modify the attributes\n"
5199 "Name of the route map\n")
5200
5201ALIAS (ipv6_bgp_network,
5202 old_ipv6_bgp_network_cmd,
5203 "ipv6 bgp network X:X::X:X/M",
5204 IPV6_STR
5205 BGP_STR
5206 "Specify a network to announce via BGP\n"
5207 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5208
5209ALIAS (no_ipv6_bgp_network,
5210 old_no_ipv6_bgp_network_cmd,
5211 "no ipv6 bgp network X:X::X:X/M",
5212 NO_STR
5213 IPV6_STR
5214 BGP_STR
5215 "Specify a network to announce via BGP\n"
5216 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5217#endif /* HAVE_IPV6 */
c8f3fe30
PJ
5218
5219/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
5220ALIAS_DEPRECATED (bgp_network,
5221 bgp_network_ttl_cmd,
5222 "network A.B.C.D/M pathlimit <0-255>",
5223 "Specify a network to announce via BGP\n"
5224 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5225 "AS-Path hopcount limit attribute\n"
5226 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5227ALIAS_DEPRECATED (bgp_network_backdoor,
5228 bgp_network_backdoor_ttl_cmd,
5229 "network A.B.C.D/M backdoor pathlimit <0-255>",
5230 "Specify a network to announce via BGP\n"
5231 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5232 "Specify a BGP backdoor route\n"
5233 "AS-Path hopcount limit attribute\n"
5234 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5235ALIAS_DEPRECATED (bgp_network_mask,
5236 bgp_network_mask_ttl_cmd,
5237 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
5238 "Specify a network to announce via BGP\n"
5239 "Network number\n"
5240 "Network mask\n"
5241 "Network mask\n"
5242 "AS-Path hopcount limit attribute\n"
5243 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5244ALIAS_DEPRECATED (bgp_network_mask_backdoor,
5245 bgp_network_mask_backdoor_ttl_cmd,
5246 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
5247 "Specify a network to announce via BGP\n"
5248 "Network number\n"
5249 "Network mask\n"
5250 "Network mask\n"
5251 "Specify a BGP backdoor route\n"
5252 "AS-Path hopcount limit attribute\n"
5253 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5254ALIAS_DEPRECATED (bgp_network_mask_natural,
5255 bgp_network_mask_natural_ttl_cmd,
5256 "network A.B.C.D pathlimit <0-255>",
5257 "Specify a network to announce via BGP\n"
5258 "Network number\n"
5259 "AS-Path hopcount limit attribute\n"
5260 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5261ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
5262 bgp_network_mask_natural_backdoor_ttl_cmd,
2b00515a 5263 "network A.B.C.D backdoor pathlimit <1-255>",
c8f3fe30
PJ
5264 "Specify a network to announce via BGP\n"
5265 "Network number\n"
5266 "Specify a BGP backdoor route\n"
5267 "AS-Path hopcount limit attribute\n"
5268 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5269ALIAS_DEPRECATED (no_bgp_network,
5270 no_bgp_network_ttl_cmd,
5271 "no network A.B.C.D/M pathlimit <0-255>",
5272 NO_STR
5273 "Specify a network to announce via BGP\n"
5274 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5275 "AS-Path hopcount limit attribute\n"
5276 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5277ALIAS_DEPRECATED (no_bgp_network,
5278 no_bgp_network_backdoor_ttl_cmd,
5279 "no network A.B.C.D/M backdoor pathlimit <0-255>",
5280 NO_STR
5281 "Specify a network to announce via BGP\n"
5282 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
5283 "Specify a BGP backdoor route\n"
5284 "AS-Path hopcount limit attribute\n"
5285 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5286ALIAS_DEPRECATED (no_bgp_network,
5287 no_bgp_network_mask_ttl_cmd,
5288 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
5289 NO_STR
5290 "Specify a network to announce via BGP\n"
5291 "Network number\n"
5292 "Network mask\n"
5293 "Network mask\n"
5294 "AS-Path hopcount limit attribute\n"
5295 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5296ALIAS_DEPRECATED (no_bgp_network_mask,
5297 no_bgp_network_mask_backdoor_ttl_cmd,
5298 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
5299 NO_STR
5300 "Specify a network to announce via BGP\n"
5301 "Network number\n"
5302 "Network mask\n"
5303 "Network mask\n"
5304 "Specify a BGP backdoor route\n"
5305 "AS-Path hopcount limit attribute\n"
5306 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5307ALIAS_DEPRECATED (no_bgp_network_mask_natural,
5308 no_bgp_network_mask_natural_ttl_cmd,
5309 "no network A.B.C.D pathlimit <0-255>",
5310 NO_STR
5311 "Specify a network to announce via BGP\n"
5312 "Network number\n"
5313 "AS-Path hopcount limit attribute\n"
5314 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5315ALIAS_DEPRECATED (no_bgp_network_mask_natural,
5316 no_bgp_network_mask_natural_backdoor_ttl_cmd,
5317 "no network A.B.C.D backdoor pathlimit <0-255>",
5318 NO_STR
5319 "Specify a network to announce via BGP\n"
5320 "Network number\n"
5321 "Specify a BGP backdoor route\n"
5322 "AS-Path hopcount limit attribute\n"
5323 "AS-Pathlimit TTL, in number of AS-Path hops\n")
3bde17f1 5324#ifdef HAVE_IPV6
c8f3fe30
PJ
5325ALIAS_DEPRECATED (ipv6_bgp_network,
5326 ipv6_bgp_network_ttl_cmd,
5327 "network X:X::X:X/M pathlimit <0-255>",
5328 "Specify a network to announce via BGP\n"
5329 "IPv6 prefix <network>/<length>\n"
5330 "AS-Path hopcount limit attribute\n"
5331 "AS-Pathlimit TTL, in number of AS-Path hops\n")
5332ALIAS_DEPRECATED (no_ipv6_bgp_network,
5333 no_ipv6_bgp_network_ttl_cmd,
5334 "no network X:X::X:X/M pathlimit <0-255>",
5335 NO_STR
5336 "Specify a network to announce via BGP\n"
5337 "IPv6 prefix <network>/<length>\n"
5338 "AS-Path hopcount limit attribute\n"
5339 "AS-Pathlimit TTL, in number of AS-Path hops\n")
3bde17f1 5340#endif /* HAVE_IPV6 */
6b0655a2 5341
718e3744 5342/* Aggreagete address:
5343
5344 advertise-map Set condition to advertise attribute
5345 as-set Generate AS set path information
5346 attribute-map Set attributes of aggregate
5347 route-map Set parameters of aggregate
5348 summary-only Filter more specific routes from updates
5349 suppress-map Conditionally filter more specific routes from updates
5350 <cr>
5351 */
5352struct bgp_aggregate
5353{
5354 /* Summary-only flag. */
5355 u_char summary_only;
5356
5357 /* AS set generation. */
5358 u_char as_set;
5359
5360 /* Route-map for aggregated route. */
5361 struct route_map *map;
5362
5363 /* Suppress-count. */
5364 unsigned long count;
5365
5366 /* SAFI configuration. */
5367 safi_t safi;
5368};
5369
94f2b392 5370static struct bgp_aggregate *
66e5cd87 5371bgp_aggregate_new (void)
718e3744 5372{
393deb9b 5373 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
718e3744 5374}
5375
94f2b392 5376static void
718e3744 5377bgp_aggregate_free (struct bgp_aggregate *aggregate)
5378{
5379 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
5380}
5381
b5d58c32 5382/* Update an aggregate as routes are added/removed from the BGP table */
94f2b392 5383static void
718e3744 5384bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
5385 afi_t afi, safi_t safi, struct bgp_info *del,
5386 struct bgp_aggregate *aggregate)
5387{
5388 struct bgp_table *table;
5389 struct bgp_node *top;
5390 struct bgp_node *rn;
5391 u_char origin;
5392 struct aspath *aspath = NULL;
5393 struct aspath *asmerge = NULL;
5394 struct community *community = NULL;
5395 struct community *commerge = NULL;
5396 struct in_addr nexthop;
5397 u_int32_t med = 0;
5398 struct bgp_info *ri;
5399 struct bgp_info *new;
5400 int first = 1;
5401 unsigned long match = 0;
42f7e184 5402 u_char atomic_aggregate = 0;
718e3744 5403
5404 /* Record adding route's nexthop and med. */
5405 if (rinew)
5406 {
5407 nexthop = rinew->attr->nexthop;
5408 med = rinew->attr->med;
5409 }
5410
5411 /* ORIGIN attribute: If at least one route among routes that are
5412 aggregated has ORIGIN with the value INCOMPLETE, then the
5413 aggregated route must have the ORIGIN attribute with the value
5414 INCOMPLETE. Otherwise, if at least one route among routes that
5415 are aggregated has ORIGIN with the value EGP, then the aggregated
5416 route must have the origin attribute with the value EGP. In all
5417 other case the value of the ORIGIN attribute of the aggregated
5418 route is INTERNAL. */
5419 origin = BGP_ORIGIN_IGP;
5420
5421 table = bgp->rib[afi][safi];
5422
5423 top = bgp_node_get (table, p);
5424 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5425 if (rn->p.prefixlen > p->prefixlen)
5426 {
5427 match = 0;
5428
5429 for (ri = rn->info; ri; ri = ri->next)
5430 {
5431 if (BGP_INFO_HOLDDOWN (ri))
5432 continue;
5433
5434 if (del && ri == del)
5435 continue;
5436
5437 if (! rinew && first)
5438 {
5439 nexthop = ri->attr->nexthop;
5440 med = ri->attr->med;
5441 first = 0;
5442 }
5443
5444#ifdef AGGREGATE_NEXTHOP_CHECK
5445 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
5446 || ri->attr->med != med)
5447 {
5448 if (aspath)
5449 aspath_free (aspath);
5450 if (community)
5451 community_free (community);
5452 bgp_unlock_node (rn);
5453 bgp_unlock_node (top);
5454 return;
5455 }
5456#endif /* AGGREGATE_NEXTHOP_CHECK */
5457
42f7e184
DS
5458 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5459 atomic_aggregate = 1;
5460
718e3744 5461 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5462 {
5463 if (aggregate->summary_only)
5464 {
fb982c25 5465 (bgp_info_extra_get (ri))->suppress++;
1a392d46 5466 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5467 match++;
5468 }
5469
5470 aggregate->count++;
5471
b5d58c32
DS
5472 if (origin < ri->attr->origin)
5473 origin = ri->attr->origin;
5474
718e3744 5475 if (aggregate->as_set)
5476 {
718e3744 5477 if (aspath)
5478 {
5479 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5480 aspath_free (aspath);
5481 aspath = asmerge;
5482 }
5483 else
5484 aspath = aspath_dup (ri->attr->aspath);
5485
5486 if (ri->attr->community)
5487 {
5488 if (community)
5489 {
5490 commerge = community_merge (community,
5491 ri->attr->community);
5492 community = community_uniq_sort (commerge);
5493 community_free (commerge);
5494 }
5495 else
5496 community = community_dup (ri->attr->community);
5497 }
5498 }
5499 }
5500 }
5501 if (match)
5502 bgp_process (bgp, rn, afi, safi);
5503 }
5504 bgp_unlock_node (top);
5505
5506 if (rinew)
5507 {
5508 aggregate->count++;
5509
5510 if (aggregate->summary_only)
fb982c25 5511 (bgp_info_extra_get (rinew))->suppress++;
718e3744 5512
b5d58c32
DS
5513 if (origin < rinew->attr->origin)
5514 origin = rinew->attr->origin;
5515
718e3744 5516 if (aggregate->as_set)
5517 {
718e3744 5518 if (aspath)
5519 {
5520 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
5521 aspath_free (aspath);
5522 aspath = asmerge;
5523 }
5524 else
5525 aspath = aspath_dup (rinew->attr->aspath);
5526
5527 if (rinew->attr->community)
5528 {
5529 if (community)
5530 {
5531 commerge = community_merge (community,
5532 rinew->attr->community);
5533 community = community_uniq_sort (commerge);
5534 community_free (commerge);
5535 }
5536 else
5537 community = community_dup (rinew->attr->community);
5538 }
5539 }
5540 }
5541
5542 if (aggregate->count > 0)
5543 {
5544 rn = bgp_node_get (table, p);
7c8ff89e 5545 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 5546 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
5547 aggregate->as_set,
5548 atomic_aggregate), rn);
718e3744 5549 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 5550
5551 bgp_info_add (rn, new);
200df115 5552 bgp_unlock_node (rn);
718e3744 5553 bgp_process (bgp, rn, afi, safi);
5554 }
5555 else
5556 {
5557 if (aspath)
5558 aspath_free (aspath);
5559 if (community)
5560 community_free (community);
5561 }
5562}
5563
5564void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
5565 struct bgp_aggregate *);
5566
5567void
5568bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
5569 struct bgp_info *ri, afi_t afi, safi_t safi)
5570{
5571 struct bgp_node *child;
5572 struct bgp_node *rn;
5573 struct bgp_aggregate *aggregate;
f018db83 5574 struct bgp_table *table;
718e3744 5575
5576 /* MPLS-VPN aggregation is not yet supported. */
5577 if (safi == SAFI_MPLS_VPN)
5578 return;
5579
f018db83
JBD
5580 table = bgp->aggregate[afi][safi];
5581
5582 /* No aggregates configured. */
67174041 5583 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
5584 return;
5585
718e3744 5586 if (p->prefixlen == 0)
5587 return;
5588
5589 if (BGP_INFO_HOLDDOWN (ri))
5590 return;
5591
bb782fb5 5592 child = bgp_node_get (table, p);
718e3744 5593
5594 /* Aggregate address configuration check. */
67174041 5595 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 5596 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5597 {
5598 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 5599 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
718e3744 5600 }
5601 bgp_unlock_node (child);
5602}
5603
5604void
5605bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
5606 struct bgp_info *del, afi_t afi, safi_t safi)
5607{
5608 struct bgp_node *child;
5609 struct bgp_node *rn;
5610 struct bgp_aggregate *aggregate;
f018db83 5611 struct bgp_table *table;
718e3744 5612
5613 /* MPLS-VPN aggregation is not yet supported. */
5614 if (safi == SAFI_MPLS_VPN)
5615 return;
5616
f018db83
JBD
5617 table = bgp->aggregate[afi][safi];
5618
5619 /* No aggregates configured. */
67174041 5620 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
5621 return;
5622
718e3744 5623 if (p->prefixlen == 0)
5624 return;
5625
bb782fb5 5626 child = bgp_node_get (table, p);
718e3744 5627
5628 /* Aggregate address configuration check. */
67174041 5629 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 5630 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5631 {
5632 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 5633 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
718e3744 5634 }
5635 bgp_unlock_node (child);
5636}
5637
b5d58c32 5638/* Called via bgp_aggregate_set when the user configures aggregate-address */
94f2b392 5639static void
718e3744 5640bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5641 struct bgp_aggregate *aggregate)
5642{
5643 struct bgp_table *table;
5644 struct bgp_node *top;
5645 struct bgp_node *rn;
5646 struct bgp_info *new;
5647 struct bgp_info *ri;
5648 unsigned long match;
5649 u_char origin = BGP_ORIGIN_IGP;
5650 struct aspath *aspath = NULL;
5651 struct aspath *asmerge = NULL;
5652 struct community *community = NULL;
5653 struct community *commerge = NULL;
42f7e184 5654 u_char atomic_aggregate = 0;
718e3744 5655
5656 table = bgp->rib[afi][safi];
5657
5658 /* Sanity check. */
5659 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5660 return;
5661 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5662 return;
5663
5664 /* If routes exists below this node, generate aggregate routes. */
5665 top = bgp_node_get (table, p);
5666 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5667 if (rn->p.prefixlen > p->prefixlen)
5668 {
5669 match = 0;
5670
5671 for (ri = rn->info; ri; ri = ri->next)
5672 {
5673 if (BGP_INFO_HOLDDOWN (ri))
5674 continue;
5675
42f7e184
DS
5676 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5677 atomic_aggregate = 1;
5678
718e3744 5679 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5680 {
5681 /* summary-only aggregate route suppress aggregated
5682 route announcement. */
5683 if (aggregate->summary_only)
5684 {
fb982c25 5685 (bgp_info_extra_get (ri))->suppress++;
1a392d46 5686 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5687 match++;
5688 }
b5d58c32
DS
5689
5690 /* If at least one route among routes that are aggregated has
5691 * ORIGIN with the value INCOMPLETE, then the aggregated route
5692 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5693 * Otherwise, if at least one route among routes that are
5694 * aggregated has ORIGIN with the value EGP, then the aggregated
5695 * route MUST have the ORIGIN attribute with the value EGP.
5696 */
5697 if (origin < ri->attr->origin)
5698 origin = ri->attr->origin;
5699
718e3744 5700 /* as-set aggregate route generate origin, as path,
5701 community aggregation. */
5702 if (aggregate->as_set)
5703 {
718e3744 5704 if (aspath)
5705 {
5706 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5707 aspath_free (aspath);
5708 aspath = asmerge;
5709 }
5710 else
5711 aspath = aspath_dup (ri->attr->aspath);
5712
5713 if (ri->attr->community)
5714 {
5715 if (community)
5716 {
5717 commerge = community_merge (community,
5718 ri->attr->community);
5719 community = community_uniq_sort (commerge);
5720 community_free (commerge);
5721 }
5722 else
5723 community = community_dup (ri->attr->community);
5724 }
5725 }
5726 aggregate->count++;
5727 }
5728 }
5729
5730 /* If this node is suppressed, process the change. */
5731 if (match)
5732 bgp_process (bgp, rn, afi, safi);
5733 }
5734 bgp_unlock_node (top);
5735
5736 /* Add aggregate route to BGP table. */
5737 if (aggregate->count)
5738 {
5739 rn = bgp_node_get (table, p);
7c8ff89e 5740 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
fb018d25 5741 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
42f7e184
DS
5742 aggregate->as_set,
5743 atomic_aggregate), rn);
718e3744 5744 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 5745
5746 bgp_info_add (rn, new);
200df115 5747 bgp_unlock_node (rn);
5748
718e3744 5749 /* Process change. */
5750 bgp_process (bgp, rn, afi, safi);
5751 }
5752}
5753
5754void
5755bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5756 safi_t safi, struct bgp_aggregate *aggregate)
5757{
5758 struct bgp_table *table;
5759 struct bgp_node *top;
5760 struct bgp_node *rn;
5761 struct bgp_info *ri;
5762 unsigned long match;
5763
5764 table = bgp->rib[afi][safi];
5765
5766 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5767 return;
5768 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5769 return;
5770
5771 /* If routes exists below this node, generate aggregate routes. */
5772 top = bgp_node_get (table, p);
5773 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5774 if (rn->p.prefixlen > p->prefixlen)
5775 {
5776 match = 0;
5777
5778 for (ri = rn->info; ri; ri = ri->next)
5779 {
5780 if (BGP_INFO_HOLDDOWN (ri))
5781 continue;
5782
5783 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5784 {
fb982c25 5785 if (aggregate->summary_only && ri->extra)
718e3744 5786 {
fb982c25 5787 ri->extra->suppress--;
718e3744 5788
fb982c25 5789 if (ri->extra->suppress == 0)
718e3744 5790 {
1a392d46 5791 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 5792 match++;
5793 }
5794 }
5795 aggregate->count--;
5796 }
5797 }
5798
fb982c25 5799 /* If this node was suppressed, process the change. */
718e3744 5800 if (match)
5801 bgp_process (bgp, rn, afi, safi);
5802 }
5803 bgp_unlock_node (top);
5804
5805 /* Delete aggregate route from BGP table. */
5806 rn = bgp_node_get (table, p);
5807
5808 for (ri = rn->info; ri; ri = ri->next)
5809 if (ri->peer == bgp->peer_self
5810 && ri->type == ZEBRA_ROUTE_BGP
5811 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5812 break;
5813
5814 /* Withdraw static BGP route from routing table. */
5815 if (ri)
5816 {
718e3744 5817 bgp_info_delete (rn, ri);
1a392d46 5818 bgp_process (bgp, rn, afi, safi);
718e3744 5819 }
5820
5821 /* Unlock bgp_node_lookup. */
5822 bgp_unlock_node (rn);
5823}
5824
5825/* Aggregate route attribute. */
5826#define AGGREGATE_SUMMARY_ONLY 1
5827#define AGGREGATE_AS_SET 1
5828
94f2b392 5829static int
f6269b4f
RB
5830bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5831 afi_t afi, safi_t safi)
718e3744 5832{
5833 int ret;
5834 struct prefix p;
5835 struct bgp_node *rn;
5836 struct bgp *bgp;
5837 struct bgp_aggregate *aggregate;
5838
5839 /* Convert string to prefix structure. */
5840 ret = str2prefix (prefix_str, &p);
5841 if (!ret)
5842 {
5843 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5844 return CMD_WARNING;
5845 }
5846 apply_mask (&p);
5847
5848 /* Get BGP structure. */
5849 bgp = vty->index;
5850
5851 /* Old configuration check. */
f6269b4f
RB
5852 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5853 if (! rn)
718e3744 5854 {
f6269b4f
RB
5855 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5856 VTY_NEWLINE);
718e3744 5857 return CMD_WARNING;
5858 }
5859
f6269b4f
RB
5860 aggregate = rn->info;
5861 if (aggregate->safi & SAFI_UNICAST)
5862 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5863 if (aggregate->safi & SAFI_MULTICAST)
5864 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 5865
f6269b4f
RB
5866 /* Unlock aggregate address configuration. */
5867 rn->info = NULL;
5868 bgp_aggregate_free (aggregate);
5869 bgp_unlock_node (rn);
5870 bgp_unlock_node (rn);
718e3744 5871
5872 return CMD_SUCCESS;
5873}
5874
94f2b392 5875static int
f6269b4f
RB
5876bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5877 afi_t afi, safi_t safi,
5878 u_char summary_only, u_char as_set)
718e3744 5879{
5880 int ret;
5881 struct prefix p;
5882 struct bgp_node *rn;
5883 struct bgp *bgp;
5884 struct bgp_aggregate *aggregate;
5885
5886 /* Convert string to prefix structure. */
5887 ret = str2prefix (prefix_str, &p);
5888 if (!ret)
5889 {
5890 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5891 return CMD_WARNING;
5892 }
5893 apply_mask (&p);
5894
5895 /* Get BGP structure. */
5896 bgp = vty->index;
5897
5898 /* Old configuration check. */
f6269b4f
RB
5899 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5900
5901 if (rn->info)
718e3744 5902 {
f6269b4f 5903 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
368473f6 5904 /* try to remove the old entry */
f6269b4f
RB
5905 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5906 if (ret)
5907 {
368473f6
RB
5908 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5909 bgp_unlock_node (rn);
f6269b4f
RB
5910 return CMD_WARNING;
5911 }
718e3744 5912 }
5913
f6269b4f
RB
5914 /* Make aggregate address structure. */
5915 aggregate = bgp_aggregate_new ();
5916 aggregate->summary_only = summary_only;
5917 aggregate->as_set = as_set;
5918 aggregate->safi = safi;
5919 rn->info = aggregate;
718e3744 5920
f6269b4f
RB
5921 /* Aggregate address insert into BGP routing table. */
5922 if (safi & SAFI_UNICAST)
5923 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5924 if (safi & SAFI_MULTICAST)
5925 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 5926
5927 return CMD_SUCCESS;
5928}
5929
5930DEFUN (aggregate_address,
5931 aggregate_address_cmd,
5932 "aggregate-address A.B.C.D/M",
5933 "Configure BGP aggregate entries\n"
5934 "Aggregate prefix\n")
5935{
5936 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5937}
5938
5939DEFUN (aggregate_address_mask,
5940 aggregate_address_mask_cmd,
5941 "aggregate-address A.B.C.D A.B.C.D",
5942 "Configure BGP aggregate entries\n"
5943 "Aggregate address\n"
5944 "Aggregate mask\n")
5945{
5946 int ret;
5947 char prefix_str[BUFSIZ];
5948
5949 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5950
5951 if (! ret)
5952 {
5953 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5954 return CMD_WARNING;
5955 }
5956
5957 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5958 0, 0);
5959}
5960
5961DEFUN (aggregate_address_summary_only,
5962 aggregate_address_summary_only_cmd,
5963 "aggregate-address A.B.C.D/M summary-only",
5964 "Configure BGP aggregate entries\n"
5965 "Aggregate prefix\n"
5966 "Filter more specific routes from updates\n")
5967{
5968 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5969 AGGREGATE_SUMMARY_ONLY, 0);
5970}
5971
5972DEFUN (aggregate_address_mask_summary_only,
5973 aggregate_address_mask_summary_only_cmd,
5974 "aggregate-address A.B.C.D A.B.C.D summary-only",
5975 "Configure BGP aggregate entries\n"
5976 "Aggregate address\n"
5977 "Aggregate mask\n"
5978 "Filter more specific routes from updates\n")
5979{
5980 int ret;
5981 char prefix_str[BUFSIZ];
5982
5983 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5984
5985 if (! ret)
5986 {
5987 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5988 return CMD_WARNING;
5989 }
5990
5991 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5992 AGGREGATE_SUMMARY_ONLY, 0);
5993}
5994
5995DEFUN (aggregate_address_as_set,
5996 aggregate_address_as_set_cmd,
5997 "aggregate-address A.B.C.D/M as-set",
5998 "Configure BGP aggregate entries\n"
5999 "Aggregate prefix\n"
6000 "Generate AS set path information\n")
6001{
6002 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
6003 0, AGGREGATE_AS_SET);
6004}
6005
6006DEFUN (aggregate_address_mask_as_set,
6007 aggregate_address_mask_as_set_cmd,
6008 "aggregate-address A.B.C.D A.B.C.D as-set",
6009 "Configure BGP aggregate entries\n"
6010 "Aggregate address\n"
6011 "Aggregate mask\n"
6012 "Generate AS set path information\n")
6013{
6014 int ret;
6015 char prefix_str[BUFSIZ];
6016
6017 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6018
6019 if (! ret)
6020 {
6021 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6022 return CMD_WARNING;
6023 }
6024
6025 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
6026 0, AGGREGATE_AS_SET);
6027}
6028
6029
6030DEFUN (aggregate_address_as_set_summary,
6031 aggregate_address_as_set_summary_cmd,
6032 "aggregate-address A.B.C.D/M as-set summary-only",
6033 "Configure BGP aggregate entries\n"
6034 "Aggregate prefix\n"
6035 "Generate AS set path information\n"
6036 "Filter more specific routes from updates\n")
6037{
6038 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
6039 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
6040}
6041
6042ALIAS (aggregate_address_as_set_summary,
6043 aggregate_address_summary_as_set_cmd,
6044 "aggregate-address A.B.C.D/M summary-only as-set",
6045 "Configure BGP aggregate entries\n"
6046 "Aggregate prefix\n"
6047 "Filter more specific routes from updates\n"
6048 "Generate AS set path information\n")
6049
6050DEFUN (aggregate_address_mask_as_set_summary,
6051 aggregate_address_mask_as_set_summary_cmd,
6052 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
6053 "Configure BGP aggregate entries\n"
6054 "Aggregate address\n"
6055 "Aggregate mask\n"
6056 "Generate AS set path information\n"
6057 "Filter more specific routes from updates\n")
6058{
6059 int ret;
6060 char prefix_str[BUFSIZ];
6061
6062 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6063
6064 if (! ret)
6065 {
6066 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6067 return CMD_WARNING;
6068 }
6069
6070 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
6071 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
6072}
6073
6074ALIAS (aggregate_address_mask_as_set_summary,
6075 aggregate_address_mask_summary_as_set_cmd,
6076 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
6077 "Configure BGP aggregate entries\n"
6078 "Aggregate address\n"
6079 "Aggregate mask\n"
6080 "Filter more specific routes from updates\n"
6081 "Generate AS set path information\n")
6082
6083DEFUN (no_aggregate_address,
6084 no_aggregate_address_cmd,
6085 "no aggregate-address A.B.C.D/M",
6086 NO_STR
6087 "Configure BGP aggregate entries\n"
6088 "Aggregate prefix\n")
6089{
6090 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
6091}
6092
6093ALIAS (no_aggregate_address,
6094 no_aggregate_address_summary_only_cmd,
6095 "no aggregate-address A.B.C.D/M summary-only",
6096 NO_STR
6097 "Configure BGP aggregate entries\n"
6098 "Aggregate prefix\n"
6099 "Filter more specific routes from updates\n")
6100
6101ALIAS (no_aggregate_address,
6102 no_aggregate_address_as_set_cmd,
6103 "no aggregate-address A.B.C.D/M as-set",
6104 NO_STR
6105 "Configure BGP aggregate entries\n"
6106 "Aggregate prefix\n"
6107 "Generate AS set path information\n")
6108
6109ALIAS (no_aggregate_address,
6110 no_aggregate_address_as_set_summary_cmd,
6111 "no aggregate-address A.B.C.D/M as-set summary-only",
6112 NO_STR
6113 "Configure BGP aggregate entries\n"
6114 "Aggregate prefix\n"
6115 "Generate AS set path information\n"
6116 "Filter more specific routes from updates\n")
6117
6118ALIAS (no_aggregate_address,
6119 no_aggregate_address_summary_as_set_cmd,
6120 "no aggregate-address A.B.C.D/M summary-only as-set",
6121 NO_STR
6122 "Configure BGP aggregate entries\n"
6123 "Aggregate prefix\n"
6124 "Filter more specific routes from updates\n"
6125 "Generate AS set path information\n")
6126
6127DEFUN (no_aggregate_address_mask,
6128 no_aggregate_address_mask_cmd,
6129 "no aggregate-address A.B.C.D A.B.C.D",
6130 NO_STR
6131 "Configure BGP aggregate entries\n"
6132 "Aggregate address\n"
6133 "Aggregate mask\n")
6134{
6135 int ret;
6136 char prefix_str[BUFSIZ];
6137
6138 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
6139
6140 if (! ret)
6141 {
6142 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
6143 return CMD_WARNING;
6144 }
6145
6146 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
6147}
6148
6149ALIAS (no_aggregate_address_mask,
6150 no_aggregate_address_mask_summary_only_cmd,
6151 "no aggregate-address A.B.C.D A.B.C.D summary-only",
6152 NO_STR
6153 "Configure BGP aggregate entries\n"
6154 "Aggregate address\n"
6155 "Aggregate mask\n"
6156 "Filter more specific routes from updates\n")
6157
6158ALIAS (no_aggregate_address_mask,
6159 no_aggregate_address_mask_as_set_cmd,
6160 "no aggregate-address A.B.C.D A.B.C.D as-set",
6161 NO_STR
6162 "Configure BGP aggregate entries\n"
6163 "Aggregate address\n"
6164 "Aggregate mask\n"
6165 "Generate AS set path information\n")
6166
6167ALIAS (no_aggregate_address_mask,
6168 no_aggregate_address_mask_as_set_summary_cmd,
6169 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
6170 NO_STR
6171 "Configure BGP aggregate entries\n"
6172 "Aggregate address\n"
6173 "Aggregate mask\n"
6174 "Generate AS set path information\n"
6175 "Filter more specific routes from updates\n")
6176
6177ALIAS (no_aggregate_address_mask,
6178 no_aggregate_address_mask_summary_as_set_cmd,
6179 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
6180 NO_STR
6181 "Configure BGP aggregate entries\n"
6182 "Aggregate address\n"
6183 "Aggregate mask\n"
6184 "Filter more specific routes from updates\n"
6185 "Generate AS set path information\n")
6186
6187#ifdef HAVE_IPV6
6188DEFUN (ipv6_aggregate_address,
6189 ipv6_aggregate_address_cmd,
6190 "aggregate-address X:X::X:X/M",
6191 "Configure BGP aggregate entries\n"
6192 "Aggregate prefix\n")
6193{
6194 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
6195}
6196
6197DEFUN (ipv6_aggregate_address_summary_only,
6198 ipv6_aggregate_address_summary_only_cmd,
6199 "aggregate-address X:X::X:X/M summary-only",
6200 "Configure BGP aggregate entries\n"
6201 "Aggregate prefix\n"
6202 "Filter more specific routes from updates\n")
6203{
6204 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6205 AGGREGATE_SUMMARY_ONLY, 0);
6206}
6207
6208DEFUN (no_ipv6_aggregate_address,
6209 no_ipv6_aggregate_address_cmd,
6210 "no aggregate-address X:X::X:X/M",
6211 NO_STR
6212 "Configure BGP aggregate entries\n"
6213 "Aggregate prefix\n")
6214{
6215 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
6216}
6217
6218DEFUN (no_ipv6_aggregate_address_summary_only,
6219 no_ipv6_aggregate_address_summary_only_cmd,
6220 "no aggregate-address X:X::X:X/M summary-only",
6221 NO_STR
6222 "Configure BGP aggregate entries\n"
6223 "Aggregate prefix\n"
6224 "Filter more specific routes from updates\n")
6225{
6226 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
6227}
6228
6229ALIAS (ipv6_aggregate_address,
6230 old_ipv6_aggregate_address_cmd,
6231 "ipv6 bgp aggregate-address X:X::X:X/M",
6232 IPV6_STR
6233 BGP_STR
6234 "Configure BGP aggregate entries\n"
6235 "Aggregate prefix\n")
6236
6237ALIAS (ipv6_aggregate_address_summary_only,
6238 old_ipv6_aggregate_address_summary_only_cmd,
6239 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
6240 IPV6_STR
6241 BGP_STR
6242 "Configure BGP aggregate entries\n"
6243 "Aggregate prefix\n"
6244 "Filter more specific routes from updates\n")
6245
6246ALIAS (no_ipv6_aggregate_address,
6247 old_no_ipv6_aggregate_address_cmd,
6248 "no ipv6 bgp aggregate-address X:X::X:X/M",
6249 NO_STR
6250 IPV6_STR
6251 BGP_STR
6252 "Configure BGP aggregate entries\n"
6253 "Aggregate prefix\n")
6254
6255ALIAS (no_ipv6_aggregate_address_summary_only,
6256 old_no_ipv6_aggregate_address_summary_only_cmd,
6257 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
6258 NO_STR
6259 IPV6_STR
6260 BGP_STR
6261 "Configure BGP aggregate entries\n"
6262 "Aggregate prefix\n"
6263 "Filter more specific routes from updates\n")
6264#endif /* HAVE_IPV6 */
6b0655a2 6265
718e3744 6266/* Redistribute route treatment. */
6267void
f04a80a5 6268bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
bc413143 6269 const struct in6_addr *nexthop6, unsigned int ifindex,
7c8ff89e 6270 u_int32_t metric, u_char type, u_short instance, u_short tag)
718e3744 6271{
6272 struct bgp *bgp;
1eb8ef25 6273 struct listnode *node, *nnode;
718e3744 6274 struct bgp_info *new;
6275 struct bgp_info *bi;
6276 struct bgp_info info;
6277 struct bgp_node *bn;
e16a4133 6278 struct attr attr;
718e3744 6279 struct attr *new_attr;
6280 afi_t afi;
6281 int ret;
7c8ff89e 6282 struct bgp_redist *red;
718e3744 6283
6284 /* Make default attribute. */
6285 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
6286 if (nexthop)
6287 attr.nexthop = *nexthop;
bc413143 6288 attr.nh_ifindex = ifindex;
718e3744 6289
f04a80a5
SH
6290#ifdef HAVE_IPV6
6291 if (nexthop6)
6292 {
6293 struct attr_extra *extra = bgp_attr_extra_get(&attr);
6294 extra->mp_nexthop_global = *nexthop6;
6295 extra->mp_nexthop_len = 16;
6296 }
6297#endif
6298
718e3744 6299 attr.med = metric;
6300 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
0d9551dc 6301 attr.extra->tag = tag;
718e3744 6302
1eb8ef25 6303 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 6304 {
6305 afi = family2afi (p->family);
6306
7c8ff89e
DS
6307 red = bgp_redist_lookup(bgp, afi, type, instance);
6308 if (red)
718e3744 6309 {
558d1fec
JBD
6310 struct attr attr_new;
6311 struct attr_extra extra_new;
6312
718e3744 6313 /* Copy attribute for modification. */
558d1fec 6314 attr_new.extra = &extra_new;
fb982c25 6315 bgp_attr_dup (&attr_new, &attr);
718e3744 6316
7c8ff89e
DS
6317 if (red->redist_metric_flag)
6318 attr_new.med = red->redist_metric;
718e3744 6319
6320 /* Apply route-map. */
7c8ff89e 6321 if (red->rmap.map)
718e3744 6322 {
6323 info.peer = bgp->peer_self;
6324 info.attr = &attr_new;
6325
fee0f4c6 6326 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
6327
7c8ff89e 6328 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
fee0f4c6 6329
6330 bgp->peer_self->rmap_type = 0;
6331
718e3744 6332 if (ret == RMAP_DENYMATCH)
6333 {
6334 /* Free uninterned attribute. */
6335 bgp_attr_flush (&attr_new);
558d1fec 6336
718e3744 6337 /* Unintern original. */
f6f434b2 6338 aspath_unintern (&attr.aspath);
fb982c25 6339 bgp_attr_extra_free (&attr);
7c8ff89e 6340 bgp_redistribute_delete (p, type, instance);
718e3744 6341 return;
6342 }
6343 }
6344
fb982c25
PJ
6345 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
6346 afi, SAFI_UNICAST, p, NULL);
6347
718e3744 6348 new_attr = bgp_attr_intern (&attr_new);
558d1fec 6349
718e3744 6350 for (bi = bn->info; bi; bi = bi->next)
6351 if (bi->peer == bgp->peer_self
6352 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
6353 break;
6354
6355 if (bi)
6356 {
8d45210e
AS
6357 if (attrhash_cmp (bi->attr, new_attr) &&
6358 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
718e3744 6359 {
f6f434b2
PJ
6360 bgp_attr_unintern (&new_attr);
6361 aspath_unintern (&attr.aspath);
fb982c25 6362 bgp_attr_extra_free (&attr);
718e3744 6363 bgp_unlock_node (bn);
6364 return;
6365 }
6366 else
6367 {
6368 /* The attribute is changed. */
1a392d46 6369 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
718e3744 6370
6371 /* Rewrite BGP route information. */
8d45210e
AS
6372 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
6373 bgp_info_restore(bn, bi);
6374 else
6375 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
f6f434b2 6376 bgp_attr_unintern (&bi->attr);
718e3744 6377 bi->attr = new_attr;
65957886 6378 bi->uptime = bgp_clock ();
718e3744 6379
6380 /* Process change. */
6381 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
6382 bgp_process (bgp, bn, afi, SAFI_UNICAST);
6383 bgp_unlock_node (bn);
f6f434b2 6384 aspath_unintern (&attr.aspath);
fb982c25 6385 bgp_attr_extra_free (&attr);
718e3744 6386 return;
fb018d25 6387 }
718e3744 6388 }
6389
7c8ff89e 6390 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
fb018d25 6391 new_attr, bn);
718e3744 6392 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 6393
6394 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
6395 bgp_info_add (bn, new);
200df115 6396 bgp_unlock_node (bn);
718e3744 6397 bgp_process (bgp, bn, afi, SAFI_UNICAST);
6398 }
6399 }
6400
6401 /* Unintern original. */
f6f434b2 6402 aspath_unintern (&attr.aspath);
fb982c25 6403 bgp_attr_extra_free (&attr);
718e3744 6404}
6405
6406void
7c8ff89e 6407bgp_redistribute_delete (struct prefix *p, u_char type, u_short instance)
718e3744 6408{
6409 struct bgp *bgp;
1eb8ef25 6410 struct listnode *node, *nnode;
718e3744 6411 afi_t afi;
6412 struct bgp_node *rn;
6413 struct bgp_info *ri;
7c8ff89e 6414 struct bgp_redist *red;
718e3744 6415
1eb8ef25 6416 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 6417 {
6418 afi = family2afi (p->family);
6419
7c8ff89e
DS
6420 red = bgp_redist_lookup(bgp, afi, type, instance);
6421 if (red)
718e3744 6422 {
fee0f4c6 6423 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
718e3744 6424
6425 for (ri = rn->info; ri; ri = ri->next)
6426 if (ri->peer == bgp->peer_self
6427 && ri->type == type)
6428 break;
6429
6430 if (ri)
6431 {
6432 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
718e3744 6433 bgp_info_delete (rn, ri);
1a392d46 6434 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 6435 }
6436 bgp_unlock_node (rn);
6437 }
6438 }
6439}
6440
6441/* Withdraw specified route type's route. */
6442void
7c8ff89e 6443bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
718e3744 6444{
6445 struct bgp_node *rn;
6446 struct bgp_info *ri;
6447 struct bgp_table *table;
6448
6449 table = bgp->rib[afi][SAFI_UNICAST];
6450
6451 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6452 {
6453 for (ri = rn->info; ri; ri = ri->next)
6454 if (ri->peer == bgp->peer_self
7c8ff89e
DS
6455 && ri->type == type
6456 && ri->instance == instance)
718e3744 6457 break;
6458
6459 if (ri)
6460 {
6461 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
718e3744 6462 bgp_info_delete (rn, ri);
1a392d46 6463 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 6464 }
6465 }
6466}
6b0655a2 6467
718e3744 6468/* Static function to display route. */
94f2b392 6469static void
718e3744 6470route_vty_out_route (struct prefix *p, struct vty *vty)
6471{
6472 int len;
6473 u_int32_t destination;
6474 char buf[BUFSIZ];
6475
6476 if (p->family == AF_INET)
6477 {
6478 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
6479 destination = ntohl (p->u.prefix4.s_addr);
6480
6481 if ((IN_CLASSC (destination) && p->prefixlen == 24)
6482 || (IN_CLASSB (destination) && p->prefixlen == 16)
6483 || (IN_CLASSA (destination) && p->prefixlen == 8)
6484 || p->u.prefix4.s_addr == 0)
6485 {
6486 /* When mask is natural, mask is not displayed. */
6487 }
6488 else
6489 len += vty_out (vty, "/%d", p->prefixlen);
6490 }
6491 else
6492 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
6493 p->prefixlen);
6494
6495 len = 17 - len;
6496 if (len < 1)
6497 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
6498 else
6499 vty_out (vty, "%*s", len, " ");
6500}
6501
718e3744 6502enum bgp_display_type
6503{
6504 normal_list,
6505};
6506
b40d939b 6507/* Print the short form route status for a bgp_info */
6508static void
6509route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
718e3744 6510{
b40d939b 6511 /* Route status display. */
6512 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6513 vty_out (vty, "R");
6514 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
93406d87 6515 vty_out (vty, "S");
fb982c25 6516 else if (binfo->extra && binfo->extra->suppress)
718e3744 6517 vty_out (vty, "s");
31eba040
DS
6518 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6519 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
718e3744 6520 vty_out (vty, "*");
6521 else
6522 vty_out (vty, " ");
6523
6524 /* Selected */
6525 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6526 vty_out (vty, "h");
6527 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6528 vty_out (vty, "d");
6529 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6530 vty_out (vty, ">");
b366b518
BB
6531 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6532 vty_out (vty, "=");
718e3744 6533 else
6534 vty_out (vty, " ");
6535
6536 /* Internal route. */
6537 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6538 vty_out (vty, "i");
6539 else
b40d939b 6540 vty_out (vty, " ");
6541}
6542
6543/* called from terminal list command */
6544void
6545route_vty_out (struct vty *vty, struct prefix *p,
47fc97cc 6546 struct bgp_info *binfo, int display, safi_t safi, char *delim)
b40d939b 6547{
6548 struct attr *attr;
47fc97cc
DS
6549
6550 /* short status lead text */
b40d939b 6551 route_vty_short_status_out (vty, binfo);
47fc97cc
DS
6552
6553 if (delim)
6554 vty_out (vty, "%c", *delim);
6555
718e3744 6556 /* print prefix and mask */
6557 if (! display)
6558 route_vty_out_route (p, vty);
6559 else
6560 vty_out (vty, "%*s", 17, " ");
6561
47fc97cc
DS
6562 if (delim)
6563 vty_out (vty, "%c", *delim);
6564
718e3744 6565 /* Print attribute */
6566 attr = binfo->attr;
6567 if (attr)
6568 {
6569 if (p->family == AF_INET)
6570 {
6571 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
6572 vty_out (vty, "%-16s",
6573 inet_ntoa (attr->extra->mp_nexthop_global_in));
718e3744 6574 else
6575 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6576 }
6577#ifdef HAVE_IPV6
6578 else if (p->family == AF_INET6)
6579 {
6580 int len;
6581 char buf[BUFSIZ];
6582
6583 len = vty_out (vty, "%s",
fb982c25
PJ
6584 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6585 buf, BUFSIZ));
718e3744 6586 len = 16 - len;
6587 if (len < 1)
6588 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6589 else
6590 vty_out (vty, "%*s", len, " ");
6591 }
6592#endif /* HAVE_IPV6 */
6593
47fc97cc
DS
6594 if (delim)
6595 vty_out (vty, "%c", *delim);
6596
718e3744 6597 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
c099baf6 6598 vty_out (vty, "%10u", attr->med);
718e3744 6599 else
6600 vty_out (vty, " ");
6601
47fc97cc
DS
6602 if (delim)
6603 vty_out (vty, "%c", *delim);
6604
718e3744 6605 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
c099baf6 6606 vty_out (vty, "%7u", attr->local_pref);
718e3744 6607 else
6608 vty_out (vty, " ");
6609
47fc97cc
DS
6610 if (delim)
6611 vty_out (vty, "%c", *delim);
6612
fb982c25 6613 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
47fc97cc
DS
6614
6615 if (delim)
6616 vty_out (vty, "%c", *delim);
6617
b2518c1e
PJ
6618 /* Print aspath */
6619 if (attr->aspath)
841f7a57 6620 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 6621
47fc97cc
DS
6622 if (delim)
6623 vty_out (vty, "%c", *delim);
6624
b2518c1e 6625 /* Print origin */
718e3744 6626 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 6627 }
718e3744 6628 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6629}
6630
6631/* called from terminal list command */
6632void
6633route_vty_out_tmp (struct vty *vty, struct prefix *p,
47fc97cc 6634 struct attr *attr, safi_t safi, char *delim)
718e3744 6635{
6636 /* Route status display. */
6637 vty_out (vty, "*");
6638 vty_out (vty, ">");
6639 vty_out (vty, " ");
6640
47fc97cc
DS
6641 if (delim)
6642 vty_out (vty, "%c", *delim);
6643
718e3744 6644 /* print prefix and mask */
6645 route_vty_out_route (p, vty);
6646
47fc97cc
DS
6647 if (delim)
6648 vty_out (vty, "%c", *delim);
6649
718e3744 6650 /* Print attribute */
6651 if (attr)
6652 {
6653 if (p->family == AF_INET)
6654 {
6655 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
6656 vty_out (vty, "%-16s",
6657 inet_ntoa (attr->extra->mp_nexthop_global_in));
718e3744 6658 else
6659 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6660 }
6661#ifdef HAVE_IPV6
6662 else if (p->family == AF_INET6)
6663 {
6664 int len;
6665 char buf[BUFSIZ];
fb982c25
PJ
6666
6667 assert (attr->extra);
718e3744 6668
6669 len = vty_out (vty, "%s",
fb982c25
PJ
6670 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6671 buf, BUFSIZ));
718e3744 6672 len = 16 - len;
6673 if (len < 1)
6674 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6675 else
6676 vty_out (vty, "%*s", len, " ");
6677 }
6678#endif /* HAVE_IPV6 */
6679
47fc97cc
DS
6680 if (delim)
6681 vty_out (vty, "%c", *delim);
6682
718e3744 6683 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
c099baf6 6684 vty_out (vty, "%10u", attr->med);
718e3744 6685 else
6686 vty_out (vty, " ");
6687
47fc97cc
DS
6688 if (delim)
6689 vty_out (vty, "%c", *delim);
6690
718e3744 6691 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
c099baf6 6692 vty_out (vty, "%7u", attr->local_pref);
718e3744 6693 else
6694 vty_out (vty, " ");
fb982c25 6695
47fc97cc
DS
6696 if (delim)
6697 vty_out (vty, "%c", *delim);
6698
c099baf6 6699 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
fb982c25 6700
47fc97cc
DS
6701 if (delim)
6702 vty_out (vty, "%c", *delim);
6703
b2518c1e
PJ
6704 /* Print aspath */
6705 if (attr->aspath)
841f7a57 6706 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 6707
47fc97cc
DS
6708 if (delim)
6709 vty_out (vty, "%c", *delim);
6710
b2518c1e 6711 /* Print origin */
718e3744 6712 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 6713 }
718e3744 6714
6715 vty_out (vty, "%s", VTY_NEWLINE);
6716}
6717
5a646650 6718void
718e3744 6719route_vty_out_tag (struct vty *vty, struct prefix *p,
6720 struct bgp_info *binfo, int display, safi_t safi)
6721{
6722 struct attr *attr;
718e3744 6723 u_int32_t label = 0;
fb982c25
PJ
6724
6725 if (!binfo->extra)
6726 return;
6727
b40d939b 6728 /* short status lead text */
6729 route_vty_short_status_out (vty, binfo);
6730
718e3744 6731 /* print prefix and mask */
6732 if (! display)
6733 route_vty_out_route (p, vty);
6734 else
6735 vty_out (vty, "%*s", 17, " ");
6736
6737 /* Print attribute */
6738 attr = binfo->attr;
6739 if (attr)
6740 {
6741 if (p->family == AF_INET)
6742 {
6743 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
6744 vty_out (vty, "%-16s",
6745 inet_ntoa (attr->extra->mp_nexthop_global_in));
718e3744 6746 else
6747 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6748 }
6749#ifdef HAVE_IPV6
6750 else if (p->family == AF_INET6)
6751 {
fb982c25 6752 assert (attr->extra);
718e3744 6753 char buf[BUFSIZ];
6754 char buf1[BUFSIZ];
fb982c25 6755 if (attr->extra->mp_nexthop_len == 16)
718e3744 6756 vty_out (vty, "%s",
fb982c25
PJ
6757 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6758 buf, BUFSIZ));
6759 else if (attr->extra->mp_nexthop_len == 32)
718e3744 6760 vty_out (vty, "%s(%s)",
fb982c25
PJ
6761 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6762 buf, BUFSIZ),
6763 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6764 buf1, BUFSIZ));
718e3744 6765
6766 }
6767#endif /* HAVE_IPV6 */
6768 }
6769
fb982c25 6770 label = decode_label (binfo->extra->tag);
718e3744 6771
6772 vty_out (vty, "notag/%d", label);
6773
6774 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6775}
6776
6777/* dampening route */
5a646650 6778static void
718e3744 6779damp_route_vty_out (struct vty *vty, struct prefix *p,
6780 struct bgp_info *binfo, int display, safi_t safi)
6781{
6782 struct attr *attr;
718e3744 6783 int len;
50aef6f3 6784 char timebuf[BGP_UPTIME_LEN];
718e3744 6785
b40d939b 6786 /* short status lead text */
6787 route_vty_short_status_out (vty, binfo);
6788
718e3744 6789 /* print prefix and mask */
6790 if (! display)
6791 route_vty_out_route (p, vty);
6792 else
6793 vty_out (vty, "%*s", 17, " ");
6794
6795 len = vty_out (vty, "%s", binfo->peer->host);
6796 len = 17 - len;
6797 if (len < 1)
6798 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6799 else
6800 vty_out (vty, "%*s", len, " ");
6801
50aef6f3 6802 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
718e3744 6803
6804 /* Print attribute */
6805 attr = binfo->attr;
6806 if (attr)
6807 {
6808 /* Print aspath */
6809 if (attr->aspath)
841f7a57 6810 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 6811
6812 /* Print origin */
b2518c1e 6813 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 6814 }
6815 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6816}
6817
718e3744 6818/* flap route */
5a646650 6819static void
718e3744 6820flap_route_vty_out (struct vty *vty, struct prefix *p,
6821 struct bgp_info *binfo, int display, safi_t safi)
6822{
6823 struct attr *attr;
6824 struct bgp_damp_info *bdi;
718e3744 6825 char timebuf[BGP_UPTIME_LEN];
6826 int len;
fb982c25
PJ
6827
6828 if (!binfo->extra)
6829 return;
6830
6831 bdi = binfo->extra->damp_info;
718e3744 6832
b40d939b 6833 /* short status lead text */
6834 route_vty_short_status_out (vty, binfo);
6835
718e3744 6836 /* print prefix and mask */
6837 if (! display)
6838 route_vty_out_route (p, vty);
6839 else
6840 vty_out (vty, "%*s", 17, " ");
6841
6842 len = vty_out (vty, "%s", binfo->peer->host);
6843 len = 16 - len;
6844 if (len < 1)
6845 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6846 else
6847 vty_out (vty, "%*s", len, " ");
6848
6849 len = vty_out (vty, "%d", bdi->flap);
6850 len = 5 - len;
6851 if (len < 1)
6852 vty_out (vty, " ");
6853 else
6854 vty_out (vty, "%*s ", len, " ");
6855
6856 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6857 timebuf, BGP_UPTIME_LEN));
6858
6859 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6860 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
50aef6f3 6861 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
718e3744 6862 else
6863 vty_out (vty, "%*s ", 8, " ");
6864
6865 /* Print attribute */
6866 attr = binfo->attr;
6867 if (attr)
6868 {
6869 /* Print aspath */
6870 if (attr->aspath)
841f7a57 6871 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 6872
6873 /* Print origin */
b2518c1e 6874 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 6875 }
6876 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6877}
6878
94f2b392 6879static void
718e3744 6880route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6881 struct bgp_info *binfo, afi_t afi, safi_t safi)
6882{
6883 char buf[INET6_ADDRSTRLEN];
6884 char buf1[BUFSIZ];
6885 struct attr *attr;
6886 int sockunion_vty_out (struct vty *, union sockunion *);
30b00176
JK
6887#ifdef HAVE_CLOCK_MONOTONIC
6888 time_t tbuf;
6889#endif
718e3744 6890
6891 attr = binfo->attr;
6892
6893 if (attr)
6894 {
6895 /* Line1 display AS-path, Aggregator */
6896 if (attr->aspath)
6897 {
6898 vty_out (vty, " ");
fe69a505 6899 if (aspath_count_hops (attr->aspath) == 0)
718e3744 6900 vty_out (vty, "Local");
6901 else
841f7a57 6902 aspath_print_vty (vty, "%s", attr->aspath, "");
718e3744 6903 }
6904
b40d939b 6905 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6906 vty_out (vty, ", (removed)");
93406d87 6907 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6908 vty_out (vty, ", (stale)");
6909 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
aea339f7 6910 vty_out (vty, ", (aggregated by %u %s)",
fb982c25
PJ
6911 attr->extra->aggregator_as,
6912 inet_ntoa (attr->extra->aggregator_addr));
93406d87 6913 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6914 vty_out (vty, ", (Received from a RR-client)");
6915 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6916 vty_out (vty, ", (Received from a RS-client)");
6917 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6918 vty_out (vty, ", (history entry)");
6919 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6920 vty_out (vty, ", (suppressed due to dampening)");
718e3744 6921 vty_out (vty, "%s", VTY_NEWLINE);
6922
6923 /* Line2 display Next-hop, Neighbor, Router-id */
6924 if (p->family == AF_INET)
6925 {
6926 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
fb982c25 6927 inet_ntoa (attr->extra->mp_nexthop_global_in) :
718e3744 6928 inet_ntoa (attr->nexthop));
6929 }
6930#ifdef HAVE_IPV6
6931 else
6932 {
fb982c25 6933 assert (attr->extra);
718e3744 6934 vty_out (vty, " %s",
fb982c25 6935 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
718e3744 6936 buf, INET6_ADDRSTRLEN));
6937 }
6938#endif /* HAVE_IPV6 */
6939
6940 if (binfo->peer == bgp->peer_self)
6941 {
6942 vty_out (vty, " from %s ",
6943 p->family == AF_INET ? "0.0.0.0" : "::");
6944 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6945 }
6946 else
6947 {
6948 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6949 vty_out (vty, " (inaccessible)");
fb982c25 6950 else if (binfo->extra && binfo->extra->igpmetric)
ddc943de 6951 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
eb821189 6952 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
718e3744 6953 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
fb982c25 6954 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
718e3744 6955 else
6956 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6957 }
6958 vty_out (vty, "%s", VTY_NEWLINE);
6959
6960#ifdef HAVE_IPV6
6961 /* display nexthop local */
fb982c25 6962 if (attr->extra && attr->extra->mp_nexthop_len == 32)
718e3744 6963 {
6964 vty_out (vty, " (%s)%s",
fb982c25 6965 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
718e3744 6966 buf, INET6_ADDRSTRLEN),
6967 VTY_NEWLINE);
6968 }
6969#endif /* HAVE_IPV6 */
6970
0d9551dc 6971 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
718e3744 6972 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6973
6974 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
c099baf6 6975 vty_out (vty, ", metric %u", attr->med);
718e3744 6976
6977 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
c099baf6 6978 vty_out (vty, ", localpref %u", attr->local_pref);
718e3744 6979 else
c099baf6 6980 vty_out (vty, ", localpref %u", bgp->default_local_pref);
718e3744 6981
fb982c25 6982 if (attr->extra && attr->extra->weight != 0)
c099baf6 6983 vty_out (vty, ", weight %u", attr->extra->weight);
0d9551dc
DS
6984
6985 if (attr->extra && attr->extra->tag != 0)
6986 vty_out (vty, ", tag %d", attr->extra->tag);
718e3744 6987
31eba040
DS
6988 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6989 vty_out (vty, ", invalid");
6990 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
718e3744 6991 vty_out (vty, ", valid");
6992
6993 if (binfo->peer != bgp->peer_self)
6994 {
6995 if (binfo->peer->as == binfo->peer->local_as)
6996 vty_out (vty, ", internal");
6997 else
6998 vty_out (vty, ", %s",
6999 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
7000 }
7001 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
7002 vty_out (vty, ", aggregated, local");
7003 else if (binfo->type != ZEBRA_ROUTE_BGP)
7004 vty_out (vty, ", sourced");
7005 else
7006 vty_out (vty, ", sourced, local");
7007
7008 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
7009 vty_out (vty, ", atomic-aggregate");
7010
de8d5dff
JB
7011 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
7012 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
7013 bgp_info_mpath_count (binfo)))
7014 vty_out (vty, ", multipath");
7015
718e3744 7016 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
7017 vty_out (vty, ", best");
7018
7019 vty_out (vty, "%s", VTY_NEWLINE);
7020
7021 /* Line 4 display Community */
7022 if (attr->community)
7023 vty_out (vty, " Community: %s%s", attr->community->str,
7024 VTY_NEWLINE);
7025
7026 /* Line 5 display Extended-community */
7027 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
fb982c25
PJ
7028 vty_out (vty, " Extended Community: %s%s",
7029 attr->extra->ecommunity->str, VTY_NEWLINE);
718e3744 7030
7031 /* Line 6 display Originator, Cluster-id */
7032 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
7033 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
7034 {
fb982c25 7035 assert (attr->extra);
718e3744 7036 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
fb982c25
PJ
7037 vty_out (vty, " Originator: %s",
7038 inet_ntoa (attr->extra->originator_id));
718e3744 7039
7040 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
7041 {
7042 int i;
7043 vty_out (vty, ", Cluster list: ");
fb982c25
PJ
7044 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7045 vty_out (vty, "%s ",
7046 inet_ntoa (attr->extra->cluster->list[i]));
718e3744 7047 }
7048 vty_out (vty, "%s", VTY_NEWLINE);
7049 }
41367172 7050
fb982c25 7051 if (binfo->extra && binfo->extra->damp_info)
718e3744 7052 bgp_damp_info_vty (vty, binfo);
7053
a82478b9
DS
7054 /* Line 7 display Addpath IDs */
7055 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
7056 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
7057 binfo->addpath_rx_id, binfo->addpath_tx_id,
7058 VTY_NEWLINE);
7059
7060 /* Line 8 display Uptime */
30b00176
JK
7061#ifdef HAVE_CLOCK_MONOTONIC
7062 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
213b6cd9 7063 vty_out (vty, " Last update: %s", ctime(&tbuf));
30b00176
JK
7064#else
7065 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
7066#endif /* HAVE_CLOCK_MONOTONIC */
718e3744 7067 }
7068 vty_out (vty, "%s", VTY_NEWLINE);
b366b518
BB
7069}
7070
47fc97cc 7071#define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
718e3744 7072#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7073#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7074
7075enum bgp_show_type
7076{
7077 bgp_show_type_normal,
7078 bgp_show_type_regexp,
7079 bgp_show_type_prefix_list,
7080 bgp_show_type_filter_list,
7081 bgp_show_type_route_map,
7082 bgp_show_type_neighbor,
7083 bgp_show_type_cidr_only,
7084 bgp_show_type_prefix_longer,
7085 bgp_show_type_community_all,
7086 bgp_show_type_community,
7087 bgp_show_type_community_exact,
7088 bgp_show_type_community_list,
7089 bgp_show_type_community_list_exact,
7090 bgp_show_type_flap_statistics,
7091 bgp_show_type_flap_address,
7092 bgp_show_type_flap_prefix,
7093 bgp_show_type_flap_cidr_only,
7094 bgp_show_type_flap_regexp,
7095 bgp_show_type_flap_filter_list,
7096 bgp_show_type_flap_prefix_list,
7097 bgp_show_type_flap_prefix_longer,
7098 bgp_show_type_flap_route_map,
7099 bgp_show_type_flap_neighbor,
7100 bgp_show_type_dampend_paths,
7101 bgp_show_type_damp_neighbor
7102};
7103
5a646650 7104static int
fee0f4c6 7105bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
47fc97cc 7106 enum bgp_show_type type, void *output_arg, char *delim)
718e3744 7107{
718e3744 7108 struct bgp_info *ri;
7109 struct bgp_node *rn;
718e3744 7110 int header = 1;
718e3744 7111 int display;
5a646650 7112 unsigned long output_count;
718e3744 7113
7114 /* This is first entry point, so reset total line. */
5a646650 7115 output_count = 0;
718e3744 7116
718e3744 7117 /* Start processing of routes. */
7118 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7119 if (rn->info != NULL)
7120 {
7121 display = 0;
7122
7123 for (ri = rn->info; ri; ri = ri->next)
7124 {
5a646650 7125 if (type == bgp_show_type_flap_statistics
718e3744 7126 || type == bgp_show_type_flap_address
7127 || type == bgp_show_type_flap_prefix
7128 || type == bgp_show_type_flap_cidr_only
7129 || type == bgp_show_type_flap_regexp
7130 || type == bgp_show_type_flap_filter_list
7131 || type == bgp_show_type_flap_prefix_list
7132 || type == bgp_show_type_flap_prefix_longer
7133 || type == bgp_show_type_flap_route_map
7134 || type == bgp_show_type_flap_neighbor
7135 || type == bgp_show_type_dampend_paths
7136 || type == bgp_show_type_damp_neighbor)
7137 {
fb982c25 7138 if (!(ri->extra && ri->extra->damp_info))
718e3744 7139 continue;
7140 }
7141 if (type == bgp_show_type_regexp
7142 || type == bgp_show_type_flap_regexp)
7143 {
5a646650 7144 regex_t *regex = output_arg;
718e3744 7145
7146 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7147 continue;
7148 }
7149 if (type == bgp_show_type_prefix_list
7150 || type == bgp_show_type_flap_prefix_list)
7151 {
5a646650 7152 struct prefix_list *plist = output_arg;
718e3744 7153
7154 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7155 continue;
7156 }
7157 if (type == bgp_show_type_filter_list
7158 || type == bgp_show_type_flap_filter_list)
7159 {
5a646650 7160 struct as_list *as_list = output_arg;
718e3744 7161
7162 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7163 continue;
7164 }
7165 if (type == bgp_show_type_route_map
7166 || type == bgp_show_type_flap_route_map)
7167 {
5a646650 7168 struct route_map *rmap = output_arg;
718e3744 7169 struct bgp_info binfo;
558d1fec
JBD
7170 struct attr dummy_attr;
7171 struct attr_extra dummy_extra;
718e3744 7172 int ret;
7173
558d1fec 7174 dummy_attr.extra = &dummy_extra;
fb982c25 7175 bgp_attr_dup (&dummy_attr, ri->attr);
558d1fec 7176
718e3744 7177 binfo.peer = ri->peer;
7178 binfo.attr = &dummy_attr;
7179
7180 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
718e3744 7181 if (ret == RMAP_DENYMATCH)
7182 continue;
7183 }
7184 if (type == bgp_show_type_neighbor
7185 || type == bgp_show_type_flap_neighbor
7186 || type == bgp_show_type_damp_neighbor)
7187 {
5a646650 7188 union sockunion *su = output_arg;
718e3744 7189
7190 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7191 continue;
7192 }
7193 if (type == bgp_show_type_cidr_only
7194 || type == bgp_show_type_flap_cidr_only)
7195 {
7196 u_int32_t destination;
7197
7198 destination = ntohl (rn->p.u.prefix4.s_addr);
7199 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7200 continue;
7201 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7202 continue;
7203 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7204 continue;
7205 }
7206 if (type == bgp_show_type_prefix_longer
7207 || type == bgp_show_type_flap_prefix_longer)
7208 {
5a646650 7209 struct prefix *p = output_arg;
718e3744 7210
7211 if (! prefix_match (p, &rn->p))
7212 continue;
7213 }
7214 if (type == bgp_show_type_community_all)
7215 {
7216 if (! ri->attr->community)
7217 continue;
7218 }
7219 if (type == bgp_show_type_community)
7220 {
5a646650 7221 struct community *com = output_arg;
718e3744 7222
7223 if (! ri->attr->community ||
7224 ! community_match (ri->attr->community, com))
7225 continue;
7226 }
7227 if (type == bgp_show_type_community_exact)
7228 {
5a646650 7229 struct community *com = output_arg;
718e3744 7230
7231 if (! ri->attr->community ||
7232 ! community_cmp (ri->attr->community, com))
7233 continue;
7234 }
7235 if (type == bgp_show_type_community_list)
7236 {
5a646650 7237 struct community_list *list = output_arg;
718e3744 7238
7239 if (! community_list_match (ri->attr->community, list))
7240 continue;
7241 }
7242 if (type == bgp_show_type_community_list_exact)
7243 {
5a646650 7244 struct community_list *list = output_arg;
718e3744 7245
7246 if (! community_list_exact_match (ri->attr->community, list))
7247 continue;
7248 }
7249 if (type == bgp_show_type_flap_address
7250 || type == bgp_show_type_flap_prefix)
7251 {
5a646650 7252 struct prefix *p = output_arg;
718e3744 7253
7254 if (! prefix_match (&rn->p, p))
7255 continue;
7256
7257 if (type == bgp_show_type_flap_prefix)
7258 if (p->prefixlen != rn->p.prefixlen)
7259 continue;
7260 }
7261 if (type == bgp_show_type_dampend_paths
7262 || type == bgp_show_type_damp_neighbor)
7263 {
7264 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7265 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7266 continue;
7267 }
7268
47fc97cc
DS
7269 if (delim)
7270 {
7271 if (header)
7272 {
7273 vty_out (vty, BGP_SHOW_HEADER_CSV, VTY_NEWLINE);
7274 header = 0;
7275 }
7276 }
7277 else if (header)
718e3744 7278 {
3f9c7369 7279 vty_out (vty, "BGP table version is %llu, local router ID is %s%s", table->version, inet_ntoa (*router_id), VTY_NEWLINE);
93406d87 7280 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7281 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 7282 if (type == bgp_show_type_dampend_paths
7283 || type == bgp_show_type_damp_neighbor)
7284 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7285 else if (type == bgp_show_type_flap_statistics
7286 || type == bgp_show_type_flap_address
7287 || type == bgp_show_type_flap_prefix
7288 || type == bgp_show_type_flap_cidr_only
7289 || type == bgp_show_type_flap_regexp
7290 || type == bgp_show_type_flap_filter_list
7291 || type == bgp_show_type_flap_prefix_list
7292 || type == bgp_show_type_flap_prefix_longer
7293 || type == bgp_show_type_flap_route_map
7294 || type == bgp_show_type_flap_neighbor)
7295 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7296 else
7297 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
718e3744 7298 header = 0;
7299 }
7300
7301 if (type == bgp_show_type_dampend_paths
7302 || type == bgp_show_type_damp_neighbor)
5a646650 7303 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
718e3744 7304 else if (type == bgp_show_type_flap_statistics
7305 || type == bgp_show_type_flap_address
7306 || type == bgp_show_type_flap_prefix
7307 || type == bgp_show_type_flap_cidr_only
7308 || type == bgp_show_type_flap_regexp
7309 || type == bgp_show_type_flap_filter_list
7310 || type == bgp_show_type_flap_prefix_list
7311 || type == bgp_show_type_flap_prefix_longer
7312 || type == bgp_show_type_flap_route_map
7313 || type == bgp_show_type_flap_neighbor)
5a646650 7314 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
718e3744 7315 else
47fc97cc 7316 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, delim);
718e3744 7317 display++;
7318 }
7319 if (display)
5a646650 7320 output_count++;
718e3744 7321 }
7322
7323 /* No route is displayed */
5a646650 7324 if (output_count == 0)
718e3744 7325 {
7326 if (type == bgp_show_type_normal)
7327 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
7328 }
7329 else
7330 vty_out (vty, "%sTotal number of prefixes %ld%s",
5a646650 7331 VTY_NEWLINE, output_count, VTY_NEWLINE);
718e3744 7332
7333 return CMD_SUCCESS;
7334}
7335
5a646650 7336static int
fee0f4c6 7337bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
47fc97cc 7338 enum bgp_show_type type, void *output_arg, char *delim)
fee0f4c6 7339{
7340 struct bgp_table *table;
7341
7342 if (bgp == NULL) {
7343 bgp = bgp_get_default ();
7344 }
7345
7346 if (bgp == NULL)
7347 {
7348 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7349 return CMD_WARNING;
7350 }
7351
7352
7353 table = bgp->rib[afi][safi];
7354
47fc97cc 7355 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg, delim);
fee0f4c6 7356}
7357
718e3744 7358/* Header of detailed BGP route information */
94f2b392 7359static void
718e3744 7360route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7361 struct bgp_node *rn,
7362 struct prefix_rd *prd, afi_t afi, safi_t safi)
7363{
7364 struct bgp_info *ri;
7365 struct prefix *p;
7366 struct peer *peer;
1eb8ef25 7367 struct listnode *node, *nnode;
718e3744 7368 char buf1[INET6_ADDRSTRLEN];
7369 char buf2[INET6_ADDRSTRLEN];
7370 int count = 0;
7371 int best = 0;
7372 int suppress = 0;
7373 int no_export = 0;
7374 int no_advertise = 0;
7375 int local_as = 0;
7376 int first = 0;
7377
7378 p = &rn->p;
7379 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
7380 (safi == SAFI_MPLS_VPN ?
7381 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7382 safi == SAFI_MPLS_VPN ? ":" : "",
7383 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7384 p->prefixlen, VTY_NEWLINE);
7385
7386 for (ri = rn->info; ri; ri = ri->next)
7387 {
7388 count++;
7389 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7390 {
7391 best = count;
fb982c25 7392 if (ri->extra && ri->extra->suppress)
718e3744 7393 suppress = 1;
7394 if (ri->attr->community != NULL)
7395 {
7396 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7397 no_advertise = 1;
7398 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7399 no_export = 1;
7400 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7401 local_as = 1;
7402 }
7403 }
7404 }
7405
7406 vty_out (vty, "Paths: (%d available", count);
7407 if (best)
7408 {
7409 vty_out (vty, ", best #%d", best);
7410 if (safi == SAFI_UNICAST)
7411 vty_out (vty, ", table Default-IP-Routing-Table");
7412 }
7413 else
7414 vty_out (vty, ", no best path");
7415 if (no_advertise)
7416 vty_out (vty, ", not advertised to any peer");
7417 else if (no_export)
7418 vty_out (vty, ", not advertised to EBGP peer");
7419 else if (local_as)
7420 vty_out (vty, ", not advertised outside local AS");
7421 if (suppress)
7422 vty_out (vty, ", Advertisements suppressed by an aggregate.");
7423 vty_out (vty, ")%s", VTY_NEWLINE);
7424
7425 /* advertised peer */
1eb8ef25 7426 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
718e3744 7427 {
7428 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
7429 {
7430 if (! first)
7431 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
7432 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
7433 first = 1;
7434 }
7435 }
7436 if (! first)
7437 vty_out (vty, " Not advertised to any peer");
7438 vty_out (vty, "%s", VTY_NEWLINE);
7439}
7440
7441/* Display specified route of BGP table. */
94f2b392 7442static int
fee0f4c6 7443bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
fd79ac91 7444 struct bgp_table *rib, const char *ip_str,
7445 afi_t afi, safi_t safi, struct prefix_rd *prd,
4092b06c 7446 int prefix_check, enum bgp_path_type pathtype)
718e3744 7447{
7448 int ret;
7449 int header;
7450 int display = 0;
7451 struct prefix match;
7452 struct bgp_node *rn;
7453 struct bgp_node *rm;
7454 struct bgp_info *ri;
718e3744 7455 struct bgp_table *table;
7456
718e3744 7457 /* Check IP address argument. */
7458 ret = str2prefix (ip_str, &match);
7459 if (! ret)
7460 {
7461 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
7462 return CMD_WARNING;
7463 }
7464
7465 match.family = afi2family (afi);
7466
7467 if (safi == SAFI_MPLS_VPN)
7468 {
fee0f4c6 7469 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
718e3744 7470 {
7471 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
7472 continue;
7473
7474 if ((table = rn->info) != NULL)
7475 {
7476 header = 1;
7477
7478 if ((rm = bgp_node_match (table, &match)) != NULL)
7479 {
7480 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6c88b44d
CC
7481 {
7482 bgp_unlock_node (rm);
7483 continue;
7484 }
718e3744 7485
7486 for (ri = rm->info; ri; ri = ri->next)
7487 {
7488 if (header)
7489 {
7490 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
7491 AFI_IP, SAFI_MPLS_VPN);
7492
7493 header = 0;
7494 }
7495 display++;
4092b06c
DS
7496
7497 if (pathtype == BGP_PATH_ALL ||
7498 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7499 (pathtype == BGP_PATH_MULTIPATH &&
7500 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
7501 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
718e3744 7502 }
6c88b44d
CC
7503
7504 bgp_unlock_node (rm);
718e3744 7505 }
7506 }
7507 }
7508 }
7509 else
7510 {
7511 header = 1;
7512
fee0f4c6 7513 if ((rn = bgp_node_match (rib, &match)) != NULL)
718e3744 7514 {
7515 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
7516 {
7517 for (ri = rn->info; ri; ri = ri->next)
7518 {
7519 if (header)
7520 {
7521 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
7522 header = 0;
7523 }
7524 display++;
4092b06c
DS
7525
7526 if (pathtype == BGP_PATH_ALL ||
7527 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7528 (pathtype == BGP_PATH_MULTIPATH &&
7529 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
7530 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
718e3744 7531 }
7532 }
6c88b44d
CC
7533
7534 bgp_unlock_node (rn);
718e3744 7535 }
7536 }
7537
7538 if (! display)
7539 {
7540 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
7541 return CMD_WARNING;
7542 }
7543
7544 return CMD_SUCCESS;
7545}
7546
fee0f4c6 7547/* Display specified route of Main RIB */
94f2b392 7548static int
fd79ac91 7549bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
fee0f4c6 7550 afi_t afi, safi_t safi, struct prefix_rd *prd,
4092b06c 7551 int prefix_check, enum bgp_path_type pathtype)
fee0f4c6 7552{
7553 struct bgp *bgp;
7554
7555 /* BGP structure lookup. */
7556 if (view_name)
7557 {
7558 bgp = bgp_lookup_by_name (view_name);
7559 if (bgp == NULL)
7560 {
7561 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7562 return CMD_WARNING;
7563 }
7564 }
7565 else
7566 {
7567 bgp = bgp_get_default ();
7568 if (bgp == NULL)
7569 {
7570 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7571 return CMD_WARNING;
7572 }
7573 }
7574
7575 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
4092b06c 7576 afi, safi, prd, prefix_check, pathtype);
fee0f4c6 7577}
7578
718e3744 7579/* BGP route print out function. */
7580DEFUN (show_ip_bgp,
7581 show_ip_bgp_cmd,
7582 "show ip bgp",
7583 SHOW_STR
7584 IP_STR
7585 BGP_STR)
7586{
47fc97cc
DS
7587 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
7588}
7589
7590DEFUN (show_ip_bgp_csv,
7591 show_ip_bgp_csv_cmd,
7592 "show ip bgp csv",
7593 SHOW_STR
7594 IP_STR
7595 BGP_STR)
7596{
7597 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, &csv);
718e3744 7598}
7599
7600DEFUN (show_ip_bgp_ipv4,
7601 show_ip_bgp_ipv4_cmd,
7602 "show ip bgp ipv4 (unicast|multicast)",
7603 SHOW_STR
7604 IP_STR
7605 BGP_STR
7606 "Address family\n"
7607 "Address Family modifier\n"
7608 "Address Family modifier\n")
7609{
7610 if (strncmp (argv[0], "m", 1) == 0)
5a646650 7611 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
47fc97cc 7612 NULL, NULL);
718e3744 7613
47fc97cc 7614 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
718e3744 7615}
7616
95cbbd2a
ML
7617ALIAS (show_ip_bgp_ipv4,
7618 show_bgp_ipv4_safi_cmd,
7619 "show bgp ipv4 (unicast|multicast)",
7620 SHOW_STR
7621 BGP_STR
7622 "Address family\n"
7623 "Address Family modifier\n"
7624 "Address Family modifier\n")
7625
47fc97cc
DS
7626DEFUN (show_ip_bgp_ipv4_csv,
7627 show_bgp_ipv4_safi_csv_cmd,
7628 "show bgp ipv4 (unicast|multicast) csv",
7629 SHOW_STR
7630 BGP_STR
7631 "Address family\n"
7632 "Address Family modifier\n"
7633 "Address Family modifier\n")
7634{
7635 if (strncmp (argv[0], "m", 1) == 0)
7636 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7637 NULL, &csv);
7638
7639 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, &csv);
7640}
7641
718e3744 7642DEFUN (show_ip_bgp_route,
7643 show_ip_bgp_route_cmd,
7644 "show ip bgp A.B.C.D",
7645 SHOW_STR
7646 IP_STR
7647 BGP_STR
7648 "Network in the BGP routing table to display\n")
7649{
4092b06c
DS
7650 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7651}
7652
7653DEFUN (show_ip_bgp_route_pathtype,
7654 show_ip_bgp_route_pathtype_cmd,
7655 "show ip bgp A.B.C.D (bestpath|multipath)",
7656 SHOW_STR
7657 IP_STR
7658 BGP_STR
7659 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7660 "Display only the bestpath\n"
7661 "Display only multipaths\n")
7662{
7663 if (strncmp (argv[1], "b", 1) == 0)
7664 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7665 else
7666 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7667}
7668
7669DEFUN (show_bgp_ipv4_safi_route_pathtype,
7670 show_bgp_ipv4_safi_route_pathtype_cmd,
7671 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath)",
7672 SHOW_STR
7673 BGP_STR
7674 "Address family\n"
7675 "Address Family modifier\n"
7676 "Address Family modifier\n"
7677 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7678 "Display only the bestpath\n"
7679 "Display only multipaths\n")
7680{
7681 if (strncmp (argv[0], "m", 1) == 0)
7682 if (strncmp (argv[2], "b", 1) == 0)
7683 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
7684 else
7685 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
7686 else
7687 if (strncmp (argv[2], "b", 1) == 0)
7688 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7689 else
7690 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
718e3744 7691}
7692
7693DEFUN (show_ip_bgp_ipv4_route,
7694 show_ip_bgp_ipv4_route_cmd,
7695 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
7696 SHOW_STR
7697 IP_STR
7698 BGP_STR
7699 "Address family\n"
7700 "Address Family modifier\n"
7701 "Address Family modifier\n"
7702 "Network in the BGP routing table to display\n")
7703{
7704 if (strncmp (argv[0], "m", 1) == 0)
4092b06c 7705 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
718e3744 7706
4092b06c 7707 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
718e3744 7708}
7709
95cbbd2a
ML
7710ALIAS (show_ip_bgp_ipv4_route,
7711 show_bgp_ipv4_safi_route_cmd,
7712 "show bgp ipv4 (unicast|multicast) A.B.C.D",
7713 SHOW_STR
7714 BGP_STR
7715 "Address family\n"
7716 "Address Family modifier\n"
7717 "Address Family modifier\n"
7718 "Network in the BGP routing table to display\n")
7719
718e3744 7720DEFUN (show_ip_bgp_vpnv4_all_route,
7721 show_ip_bgp_vpnv4_all_route_cmd,
7722 "show ip bgp vpnv4 all A.B.C.D",
7723 SHOW_STR
7724 IP_STR
7725 BGP_STR
7726 "Display VPNv4 NLRI specific information\n"
7727 "Display information about all VPNv4 NLRIs\n"
7728 "Network in the BGP routing table to display\n")
7729{
4092b06c 7730 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
718e3744 7731}
7732
4092b06c 7733
718e3744 7734DEFUN (show_ip_bgp_vpnv4_rd_route,
7735 show_ip_bgp_vpnv4_rd_route_cmd,
7736 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
7737 SHOW_STR
7738 IP_STR
7739 BGP_STR
7740 "Display VPNv4 NLRI specific information\n"
7741 "Display information for a route distinguisher\n"
7742 "VPN Route Distinguisher\n"
7743 "Network in the BGP routing table to display\n")
7744{
7745 int ret;
7746 struct prefix_rd prd;
7747
7748 ret = str2prefix_rd (argv[0], &prd);
7749 if (! ret)
7750 {
7751 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7752 return CMD_WARNING;
7753 }
4092b06c 7754 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
718e3744 7755}
7756
7757DEFUN (show_ip_bgp_prefix,
7758 show_ip_bgp_prefix_cmd,
7759 "show ip bgp A.B.C.D/M",
7760 SHOW_STR
7761 IP_STR
7762 BGP_STR
7763 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7764{
4092b06c
DS
7765 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7766}
7767
7768DEFUN (show_ip_bgp_prefix_pathtype,
7769 show_ip_bgp_prefix_pathtype_cmd,
7770 "show ip bgp A.B.C.D/M (bestpath|multipath)",
7771 SHOW_STR
7772 IP_STR
7773 BGP_STR
7774 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7775 "Display only the bestpath\n"
7776 "Display only multipaths\n")
7777{
7778 if (strncmp (argv[1], "b", 1) == 0)
7779 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7780 else
7781 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
718e3744 7782}
7783
7784DEFUN (show_ip_bgp_ipv4_prefix,
7785 show_ip_bgp_ipv4_prefix_cmd,
7786 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
7787 SHOW_STR
7788 IP_STR
7789 BGP_STR
7790 "Address family\n"
7791 "Address Family modifier\n"
7792 "Address Family modifier\n"
7793 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7794{
7795 if (strncmp (argv[0], "m", 1) == 0)
4092b06c 7796 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
718e3744 7797
4092b06c 7798 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
718e3744 7799}
7800
95cbbd2a
ML
7801ALIAS (show_ip_bgp_ipv4_prefix,
7802 show_bgp_ipv4_safi_prefix_cmd,
7803 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
7804 SHOW_STR
7805 BGP_STR
7806 "Address family\n"
7807 "Address Family modifier\n"
7808 "Address Family modifier\n"
7809 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7810
4092b06c
DS
7811DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
7812 show_ip_bgp_ipv4_prefix_pathtype_cmd,
7813 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7814 SHOW_STR
7815 IP_STR
7816 BGP_STR
7817 "Address family\n"
7818 "Address Family modifier\n"
7819 "Address Family modifier\n"
7820 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7821 "Display only the bestpath\n"
7822 "Display only multipaths\n")
7823{
7824 if (strncmp (argv[0], "m", 1) == 0)
7825 if (strncmp (argv[2], "b", 1) == 0)
7826 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
7827 else
7828 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
7829 else
7830 if (strncmp (argv[2], "b", 1) == 0)
7831 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7832 else
7833 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7834}
7835
7836ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
7837 show_bgp_ipv4_safi_prefix_pathtype_cmd,
7838 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7839 SHOW_STR
7840 BGP_STR
7841 "Address family\n"
7842 "Address Family modifier\n"
7843 "Address Family modifier\n"
7844 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7845 "Display only the bestpath\n"
7846 "Display only multipaths\n")
7847
718e3744 7848DEFUN (show_ip_bgp_vpnv4_all_prefix,
7849 show_ip_bgp_vpnv4_all_prefix_cmd,
7850 "show ip bgp vpnv4 all A.B.C.D/M",
7851 SHOW_STR
7852 IP_STR
7853 BGP_STR
7854 "Display VPNv4 NLRI specific information\n"
7855 "Display information about all VPNv4 NLRIs\n"
7856 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7857{
4092b06c 7858 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL);
718e3744 7859}
7860
7861DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7862 show_ip_bgp_vpnv4_rd_prefix_cmd,
7863 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7864 SHOW_STR
7865 IP_STR
7866 BGP_STR
7867 "Display VPNv4 NLRI specific information\n"
7868 "Display information for a route distinguisher\n"
7869 "VPN Route Distinguisher\n"
7870 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7871{
7872 int ret;
7873 struct prefix_rd prd;
7874
7875 ret = str2prefix_rd (argv[0], &prd);
7876 if (! ret)
7877 {
7878 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7879 return CMD_WARNING;
7880 }
4092b06c 7881 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1, BGP_PATH_ALL);
718e3744 7882}
7883
7884DEFUN (show_ip_bgp_view,
7885 show_ip_bgp_view_cmd,
7886 "show ip bgp view WORD",
7887 SHOW_STR
7888 IP_STR
7889 BGP_STR
7890 "BGP view\n"
2b00515a 7891 "View name\n")
718e3744 7892{
bb46e94f 7893 struct bgp *bgp;
7894
7895 /* BGP structure lookup. */
7896 bgp = bgp_lookup_by_name (argv[0]);
7897 if (bgp == NULL)
7898 {
7899 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7900 return CMD_WARNING;
7901 }
7902
47fc97cc 7903 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
718e3744 7904}
7905
7906DEFUN (show_ip_bgp_view_route,
7907 show_ip_bgp_view_route_cmd,
7908 "show ip bgp view WORD A.B.C.D",
7909 SHOW_STR
7910 IP_STR
7911 BGP_STR
7912 "BGP view\n"
2b00515a 7913 "View name\n"
718e3744 7914 "Network in the BGP routing table to display\n")
7915{
4092b06c 7916 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
718e3744 7917}
7918
7919DEFUN (show_ip_bgp_view_prefix,
7920 show_ip_bgp_view_prefix_cmd,
7921 "show ip bgp view WORD A.B.C.D/M",
7922 SHOW_STR
7923 IP_STR
7924 BGP_STR
7925 "BGP view\n"
2b00515a 7926 "View name\n"
718e3744 7927 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7928{
4092b06c 7929 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
718e3744 7930}
7931
7932#ifdef HAVE_IPV6
7933DEFUN (show_bgp,
7934 show_bgp_cmd,
7935 "show bgp",
7936 SHOW_STR
7937 BGP_STR)
7938{
5a646650 7939 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
47fc97cc 7940 NULL, NULL);
718e3744 7941}
7942
7943ALIAS (show_bgp,
7944 show_bgp_ipv6_cmd,
7945 "show bgp ipv6",
7946 SHOW_STR
7947 BGP_STR
7948 "Address family\n")
7949
95cbbd2a
ML
7950DEFUN (show_bgp_ipv6_safi,
7951 show_bgp_ipv6_safi_cmd,
7952 "show bgp ipv6 (unicast|multicast)",
7953 SHOW_STR
7954 BGP_STR
7955 "Address family\n"
7956 "Address Family modifier\n"
7957 "Address Family modifier\n")
7958{
7959 if (strncmp (argv[0], "m", 1) == 0)
7960 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
47fc97cc 7961 NULL, NULL);
95cbbd2a 7962
47fc97cc
DS
7963 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
7964}
7965
7966DEFUN (show_bgp_ipv6_safi_csv,
7967 show_bgp_ipv6_safi_csv_cmd,
7968 "show bgp ipv6 (unicast|multicast) csv",
7969 SHOW_STR
7970 BGP_STR
7971 "Address family\n"
7972 "Address Family modifier\n"
7973 "Address Family modifier\n")
7974{
7975 if (strncmp (argv[0], "m", 1) == 0)
7976 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7977 NULL, &csv);
7978
7979 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, &csv);
95cbbd2a
ML
7980}
7981
718e3744 7982/* old command */
7983DEFUN (show_ipv6_bgp,
7984 show_ipv6_bgp_cmd,
7985 "show ipv6 bgp",
7986 SHOW_STR
7987 IP_STR
7988 BGP_STR)
7989{
5a646650 7990 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
47fc97cc 7991 NULL, NULL);
718e3744 7992}
7993
7994DEFUN (show_bgp_route,
7995 show_bgp_route_cmd,
7996 "show bgp X:X::X:X",
7997 SHOW_STR
7998 BGP_STR
7999 "Network in the BGP routing table to display\n")
8000{
4092b06c 8001 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
718e3744 8002}
8003
8004ALIAS (show_bgp_route,
8005 show_bgp_ipv6_route_cmd,
8006 "show bgp ipv6 X:X::X:X",
8007 SHOW_STR
8008 BGP_STR
8009 "Address family\n"
8010 "Network in the BGP routing table to display\n")
8011
95cbbd2a
ML
8012DEFUN (show_bgp_ipv6_safi_route,
8013 show_bgp_ipv6_safi_route_cmd,
8014 "show bgp ipv6 (unicast|multicast) X:X::X:X",
8015 SHOW_STR
8016 BGP_STR
8017 "Address family\n"
8018 "Address Family modifier\n"
8019 "Address Family modifier\n"
8020 "Network in the BGP routing table to display\n")
8021{
8022 if (strncmp (argv[0], "m", 1) == 0)
4092b06c 8023 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
95cbbd2a 8024
4092b06c
DS
8025 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
8026}
8027
8028DEFUN (show_bgp_route_pathtype,
8029 show_bgp_route_pathtype_cmd,
8030 "show bgp X:X::X:X (bestpath|multipath)",
8031 SHOW_STR
8032 BGP_STR
8033 "Network in the BGP routing table to display\n"
8034 "Display only the bestpath\n"
8035 "Display only multipaths\n")
8036{
8037 if (strncmp (argv[1], "b", 1) == 0)
8038 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
8039 else
8040 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
8041}
8042
8043ALIAS (show_bgp_route_pathtype,
8044 show_bgp_ipv6_route_pathtype_cmd,
8045 "show bgp ipv6 X:X::X:X (bestpath|multipath)",
8046 SHOW_STR
8047 BGP_STR
8048 "Address family\n"
8049 "Network in the BGP routing table to display\n"
8050 "Display only the bestpath\n"
8051 "Display only multipaths\n")
8052
8053DEFUN (show_bgp_ipv6_safi_route_pathtype,
8054 show_bgp_ipv6_safi_route_pathtype_cmd,
8055 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath)",
8056 SHOW_STR
8057 BGP_STR
8058 "Address family\n"
8059 "Address Family modifier\n"
8060 "Address Family modifier\n"
8061 "Network in the BGP routing table to display\n"
8062 "Display only the bestpath\n"
8063 "Display only multipaths\n")
8064{
8065 if (strncmp (argv[0], "m", 1) == 0)
8066 if (strncmp (argv[2], "b", 1) == 0)
8067 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
8068 else
8069 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
8070 else
8071 if (strncmp (argv[2], "b", 1) == 0)
8072 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
8073 else
8074 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
95cbbd2a
ML
8075}
8076
718e3744 8077/* old command */
8078DEFUN (show_ipv6_bgp_route,
8079 show_ipv6_bgp_route_cmd,
8080 "show ipv6 bgp X:X::X:X",
8081 SHOW_STR
8082 IP_STR
8083 BGP_STR
8084 "Network in the BGP routing table to display\n")
8085{
4092b06c 8086 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
718e3744 8087}
8088
8089DEFUN (show_bgp_prefix,
8090 show_bgp_prefix_cmd,
8091 "show bgp X:X::X:X/M",
8092 SHOW_STR
8093 BGP_STR
8094 "IPv6 prefix <network>/<length>\n")
8095{
4092b06c 8096 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
718e3744 8097}
8098
8099ALIAS (show_bgp_prefix,
8100 show_bgp_ipv6_prefix_cmd,
8101 "show bgp ipv6 X:X::X:X/M",
8102 SHOW_STR
8103 BGP_STR
8104 "Address family\n"
8105 "IPv6 prefix <network>/<length>\n")
8106
95cbbd2a
ML
8107DEFUN (show_bgp_ipv6_safi_prefix,
8108 show_bgp_ipv6_safi_prefix_cmd,
8109 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
8110 SHOW_STR
8111 BGP_STR
8112 "Address family\n"
8113 "Address Family modifier\n"
8114 "Address Family modifier\n"
8115 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
8116{
8117 if (strncmp (argv[0], "m", 1) == 0)
4092b06c 8118 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
95cbbd2a 8119
4092b06c
DS
8120 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
8121}
8122
8123DEFUN (show_bgp_prefix_pathtype,
8124 show_bgp_prefix_pathtype_cmd,
8125 "show bgp X:X::X:X/M (bestpath|multipath)",
8126 SHOW_STR
8127 BGP_STR
8128 "IPv6 prefix <network>/<length>\n"
8129 "Display only the bestpath\n"
8130 "Display only multipaths\n")
8131{
8132 if (strncmp (argv[1], "b", 1) == 0)
8133 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
8134 else
8135 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
8136}
8137
8138ALIAS (show_bgp_prefix_pathtype,
8139 show_bgp_ipv6_prefix_pathtype_cmd,
8140 "show bgp ipv6 X:X::X:X/M (bestpath|multipath)",
8141 SHOW_STR
8142 BGP_STR
8143 "Address family\n"
8144 "IPv6 prefix <network>/<length>\n"
8145 "Display only the bestpath\n"
8146 "Display only multipaths\n")
8147
8148DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8149 show_bgp_ipv6_safi_prefix_pathtype_cmd,
8150 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath)",
8151 SHOW_STR
8152 BGP_STR
8153 "Address family\n"
8154 "Address Family modifier\n"
8155 "Address Family modifier\n"
8156 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8157 "Display only the bestpath\n"
8158 "Display only multipaths\n")
8159{
8160 if (strncmp (argv[0], "m", 1) == 0)
8161 if (strncmp (argv[2], "b", 1) == 0)
8162 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
8163 else
8164 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
8165 else
8166 if (strncmp (argv[2], "b", 1) == 0)
8167 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
8168 else
8169 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
95cbbd2a
ML
8170}
8171
718e3744 8172/* old command */
8173DEFUN (show_ipv6_bgp_prefix,
8174 show_ipv6_bgp_prefix_cmd,
8175 "show ipv6 bgp X:X::X:X/M",
8176 SHOW_STR
8177 IP_STR
8178 BGP_STR
8179 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
8180{
4092b06c 8181 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
718e3744 8182}
8183
bb46e94f 8184DEFUN (show_bgp_view,
8185 show_bgp_view_cmd,
8186 "show bgp view WORD",
8187 SHOW_STR
8188 BGP_STR
8189 "BGP view\n"
8190 "View name\n")
8191{
8192 struct bgp *bgp;
8193
8194 /* BGP structure lookup. */
8195 bgp = bgp_lookup_by_name (argv[0]);
8196 if (bgp == NULL)
8197 {
8198 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8199 return CMD_WARNING;
8200 }
8201
47fc97cc 8202 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
bb46e94f 8203}
8204
8205ALIAS (show_bgp_view,
8206 show_bgp_view_ipv6_cmd,
8207 "show bgp view WORD ipv6",
8208 SHOW_STR
8209 BGP_STR
8210 "BGP view\n"
8211 "View name\n"
8212 "Address family\n")
8213
8214DEFUN (show_bgp_view_route,
8215 show_bgp_view_route_cmd,
8216 "show bgp view WORD X:X::X:X",
8217 SHOW_STR
8218 BGP_STR
8219 "BGP view\n"
8220 "View name\n"
8221 "Network in the BGP routing table to display\n")
8222{
4092b06c 8223 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
bb46e94f 8224}
8225
8226ALIAS (show_bgp_view_route,
8227 show_bgp_view_ipv6_route_cmd,
8228 "show bgp view WORD ipv6 X:X::X:X",
8229 SHOW_STR
8230 BGP_STR
8231 "BGP view\n"
8232 "View name\n"
8233 "Address family\n"
8234 "Network in the BGP routing table to display\n")
8235
8236DEFUN (show_bgp_view_prefix,
8237 show_bgp_view_prefix_cmd,
8238 "show bgp view WORD X:X::X:X/M",
8239 SHOW_STR
8240 BGP_STR
8241 "BGP view\n"
8242 "View name\n"
8243 "IPv6 prefix <network>/<length>\n")
8244{
4092b06c 8245 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
bb46e94f 8246}
8247
8248ALIAS (show_bgp_view_prefix,
8249 show_bgp_view_ipv6_prefix_cmd,
8250 "show bgp view WORD ipv6 X:X::X:X/M",
8251 SHOW_STR
8252 BGP_STR
8253 "BGP view\n"
8254 "View name\n"
8255 "Address family\n"
8256 "IPv6 prefix <network>/<length>\n")
8257
718e3744 8258/* old command */
8259DEFUN (show_ipv6_mbgp,
8260 show_ipv6_mbgp_cmd,
8261 "show ipv6 mbgp",
8262 SHOW_STR
8263 IP_STR
8264 MBGP_STR)
8265{
5a646650 8266 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
47fc97cc 8267 NULL, NULL);
718e3744 8268}
8269
8270/* old command */
8271DEFUN (show_ipv6_mbgp_route,
8272 show_ipv6_mbgp_route_cmd,
8273 "show ipv6 mbgp X:X::X:X",
8274 SHOW_STR
8275 IP_STR
8276 MBGP_STR
8277 "Network in the MBGP routing table to display\n")
8278{
4092b06c 8279 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
718e3744 8280}
8281
8282/* old command */
8283DEFUN (show_ipv6_mbgp_prefix,
8284 show_ipv6_mbgp_prefix_cmd,
8285 "show ipv6 mbgp X:X::X:X/M",
8286 SHOW_STR
8287 IP_STR
8288 MBGP_STR
8289 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
8290{
4092b06c 8291 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
718e3744 8292}
8293#endif
6b0655a2 8294
718e3744 8295
94f2b392 8296static int
fd79ac91 8297bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
718e3744 8298 safi_t safi, enum bgp_show_type type)
8299{
8300 int i;
8301 struct buffer *b;
8302 char *regstr;
8303 int first;
8304 regex_t *regex;
5a646650 8305 int rc;
718e3744 8306
8307 first = 0;
8308 b = buffer_new (1024);
8309 for (i = 0; i < argc; i++)
8310 {
8311 if (first)
8312 buffer_putc (b, ' ');
8313 else
8314 {
8315 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8316 continue;
8317 first = 1;
8318 }
8319
8320 buffer_putstr (b, argv[i]);
8321 }
8322 buffer_putc (b, '\0');
8323
8324 regstr = buffer_getstr (b);
8325 buffer_free (b);
8326
8327 regex = bgp_regcomp (regstr);
3b8b1855 8328 XFREE(MTYPE_TMP, regstr);
718e3744 8329 if (! regex)
8330 {
8331 vty_out (vty, "Can't compile regexp %s%s", argv[0],
8332 VTY_NEWLINE);
8333 return CMD_WARNING;
8334 }
8335
47fc97cc 8336 rc = bgp_show (vty, NULL, afi, safi, type, regex, NULL);
5a646650 8337 bgp_regex_free (regex);
8338 return rc;
718e3744 8339}
8340
8341DEFUN (show_ip_bgp_regexp,
8342 show_ip_bgp_regexp_cmd,
8343 "show ip bgp regexp .LINE",
8344 SHOW_STR
8345 IP_STR
8346 BGP_STR
8347 "Display routes matching the AS path regular expression\n"
8348 "A regular-expression to match the BGP AS paths\n")
8349{
8350 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8351 bgp_show_type_regexp);
8352}
8353
8354DEFUN (show_ip_bgp_flap_regexp,
8355 show_ip_bgp_flap_regexp_cmd,
8356 "show ip bgp flap-statistics regexp .LINE",
8357 SHOW_STR
8358 IP_STR
8359 BGP_STR
8360 "Display flap statistics of routes\n"
8361 "Display routes matching the AS path regular expression\n"
8362 "A regular-expression to match the BGP AS paths\n")
8363{
8364 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8365 bgp_show_type_flap_regexp);
8366}
8367
8368DEFUN (show_ip_bgp_ipv4_regexp,
8369 show_ip_bgp_ipv4_regexp_cmd,
8370 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
8371 SHOW_STR
8372 IP_STR
8373 BGP_STR
8374 "Address family\n"
8375 "Address Family modifier\n"
8376 "Address Family modifier\n"
8377 "Display routes matching the AS path regular expression\n"
8378 "A regular-expression to match the BGP AS paths\n")
8379{
8380 if (strncmp (argv[0], "m", 1) == 0)
8381 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
8382 bgp_show_type_regexp);
8383
8384 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8385 bgp_show_type_regexp);
8386}
8387
8388#ifdef HAVE_IPV6
8389DEFUN (show_bgp_regexp,
8390 show_bgp_regexp_cmd,
8391 "show bgp regexp .LINE",
8392 SHOW_STR
8393 BGP_STR
8394 "Display routes matching the AS path regular expression\n"
8395 "A regular-expression to match the BGP AS paths\n")
8396{
8397 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8398 bgp_show_type_regexp);
8399}
8400
8401ALIAS (show_bgp_regexp,
8402 show_bgp_ipv6_regexp_cmd,
8403 "show bgp ipv6 regexp .LINE",
8404 SHOW_STR
8405 BGP_STR
8406 "Address family\n"
8407 "Display routes matching the AS path regular expression\n"
8408 "A regular-expression to match the BGP AS paths\n")
8409
8410/* old command */
8411DEFUN (show_ipv6_bgp_regexp,
8412 show_ipv6_bgp_regexp_cmd,
8413 "show ipv6 bgp regexp .LINE",
8414 SHOW_STR
8415 IP_STR
8416 BGP_STR
8417 "Display routes matching the AS path regular expression\n"
8418 "A regular-expression to match the BGP AS paths\n")
8419{
8420 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8421 bgp_show_type_regexp);
8422}
8423
8424/* old command */
8425DEFUN (show_ipv6_mbgp_regexp,
8426 show_ipv6_mbgp_regexp_cmd,
8427 "show ipv6 mbgp regexp .LINE",
8428 SHOW_STR
8429 IP_STR
8430 BGP_STR
8431 "Display routes matching the AS path regular expression\n"
8432 "A regular-expression to match the MBGP AS paths\n")
8433{
8434 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
8435 bgp_show_type_regexp);
8436}
8437#endif /* HAVE_IPV6 */
6b0655a2 8438
94f2b392 8439static int
fd79ac91 8440bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
718e3744 8441 safi_t safi, enum bgp_show_type type)
8442{
8443 struct prefix_list *plist;
8444
8445 plist = prefix_list_lookup (afi, prefix_list_str);
8446 if (plist == NULL)
8447 {
8448 vty_out (vty, "%% %s is not a valid prefix-list name%s",
8449 prefix_list_str, VTY_NEWLINE);
8450 return CMD_WARNING;
8451 }
8452
47fc97cc 8453 return bgp_show (vty, NULL, afi, safi, type, plist, NULL);
718e3744 8454}
8455
8456DEFUN (show_ip_bgp_prefix_list,
8457 show_ip_bgp_prefix_list_cmd,
8458 "show ip bgp prefix-list WORD",
8459 SHOW_STR
8460 IP_STR
8461 BGP_STR
8462 "Display routes conforming to the prefix-list\n"
8463 "IP prefix-list name\n")
8464{
8465 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8466 bgp_show_type_prefix_list);
8467}
8468
8469DEFUN (show_ip_bgp_flap_prefix_list,
8470 show_ip_bgp_flap_prefix_list_cmd,
8471 "show ip bgp flap-statistics prefix-list WORD",
8472 SHOW_STR
8473 IP_STR
8474 BGP_STR
8475 "Display flap statistics of routes\n"
8476 "Display routes conforming to the prefix-list\n"
8477 "IP prefix-list name\n")
8478{
8479 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8480 bgp_show_type_flap_prefix_list);
8481}
8482
8483DEFUN (show_ip_bgp_ipv4_prefix_list,
8484 show_ip_bgp_ipv4_prefix_list_cmd,
8485 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
8486 SHOW_STR
8487 IP_STR
8488 BGP_STR
8489 "Address family\n"
8490 "Address Family modifier\n"
8491 "Address Family modifier\n"
8492 "Display routes conforming to the prefix-list\n"
8493 "IP prefix-list name\n")
8494{
8495 if (strncmp (argv[0], "m", 1) == 0)
8496 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8497 bgp_show_type_prefix_list);
8498
8499 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8500 bgp_show_type_prefix_list);
8501}
8502
8503#ifdef HAVE_IPV6
8504DEFUN (show_bgp_prefix_list,
8505 show_bgp_prefix_list_cmd,
8506 "show bgp prefix-list WORD",
8507 SHOW_STR
8508 BGP_STR
8509 "Display routes conforming to the prefix-list\n"
8510 "IPv6 prefix-list name\n")
8511{
8512 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8513 bgp_show_type_prefix_list);
8514}
8515
8516ALIAS (show_bgp_prefix_list,
8517 show_bgp_ipv6_prefix_list_cmd,
8518 "show bgp ipv6 prefix-list WORD",
8519 SHOW_STR
8520 BGP_STR
8521 "Address family\n"
8522 "Display routes conforming to the prefix-list\n"
8523 "IPv6 prefix-list name\n")
8524
8525/* old command */
8526DEFUN (show_ipv6_bgp_prefix_list,
8527 show_ipv6_bgp_prefix_list_cmd,
8528 "show ipv6 bgp prefix-list WORD",
8529 SHOW_STR
8530 IPV6_STR
8531 BGP_STR
8532 "Display routes matching the prefix-list\n"
8533 "IPv6 prefix-list name\n")
8534{
8535 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8536 bgp_show_type_prefix_list);
8537}
8538
8539/* old command */
8540DEFUN (show_ipv6_mbgp_prefix_list,
8541 show_ipv6_mbgp_prefix_list_cmd,
8542 "show ipv6 mbgp prefix-list WORD",
8543 SHOW_STR
8544 IPV6_STR
8545 MBGP_STR
8546 "Display routes matching the prefix-list\n"
8547 "IPv6 prefix-list name\n")
8548{
8549 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8550 bgp_show_type_prefix_list);
8551}
8552#endif /* HAVE_IPV6 */
6b0655a2 8553
94f2b392 8554static int
fd79ac91 8555bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
718e3744 8556 safi_t safi, enum bgp_show_type type)
8557{
8558 struct as_list *as_list;
8559
8560 as_list = as_list_lookup (filter);
8561 if (as_list == NULL)
8562 {
8563 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
8564 return CMD_WARNING;
8565 }
8566
47fc97cc 8567 return bgp_show (vty, NULL, afi, safi, type, as_list, NULL);
718e3744 8568}
8569
8570DEFUN (show_ip_bgp_filter_list,
8571 show_ip_bgp_filter_list_cmd,
8572 "show ip bgp filter-list WORD",
8573 SHOW_STR
8574 IP_STR
8575 BGP_STR
8576 "Display routes conforming to the filter-list\n"
8577 "Regular expression access list name\n")
8578{
8579 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8580 bgp_show_type_filter_list);
8581}
8582
8583DEFUN (show_ip_bgp_flap_filter_list,
8584 show_ip_bgp_flap_filter_list_cmd,
8585 "show ip bgp flap-statistics filter-list WORD",
8586 SHOW_STR
8587 IP_STR
8588 BGP_STR
8589 "Display flap statistics of routes\n"
8590 "Display routes conforming to the filter-list\n"
8591 "Regular expression access list name\n")
8592{
8593 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8594 bgp_show_type_flap_filter_list);
8595}
8596
8597DEFUN (show_ip_bgp_ipv4_filter_list,
8598 show_ip_bgp_ipv4_filter_list_cmd,
8599 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
8600 SHOW_STR
8601 IP_STR
8602 BGP_STR
8603 "Address family\n"
8604 "Address Family modifier\n"
8605 "Address Family modifier\n"
8606 "Display routes conforming to the filter-list\n"
8607 "Regular expression access list name\n")
8608{
8609 if (strncmp (argv[0], "m", 1) == 0)
8610 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8611 bgp_show_type_filter_list);
8612
8613 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8614 bgp_show_type_filter_list);
8615}
8616
8617#ifdef HAVE_IPV6
8618DEFUN (show_bgp_filter_list,
8619 show_bgp_filter_list_cmd,
8620 "show bgp filter-list WORD",
8621 SHOW_STR
8622 BGP_STR
8623 "Display routes conforming to the filter-list\n"
8624 "Regular expression access list name\n")
8625{
8626 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8627 bgp_show_type_filter_list);
8628}
8629
8630ALIAS (show_bgp_filter_list,
8631 show_bgp_ipv6_filter_list_cmd,
8632 "show bgp ipv6 filter-list WORD",
8633 SHOW_STR
8634 BGP_STR
8635 "Address family\n"
8636 "Display routes conforming to the filter-list\n"
8637 "Regular expression access list name\n")
8638
8639/* old command */
8640DEFUN (show_ipv6_bgp_filter_list,
8641 show_ipv6_bgp_filter_list_cmd,
8642 "show ipv6 bgp filter-list WORD",
8643 SHOW_STR
8644 IPV6_STR
8645 BGP_STR
8646 "Display routes conforming to the filter-list\n"
8647 "Regular expression access list name\n")
8648{
8649 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8650 bgp_show_type_filter_list);
8651}
8652
8653/* old command */
8654DEFUN (show_ipv6_mbgp_filter_list,
8655 show_ipv6_mbgp_filter_list_cmd,
8656 "show ipv6 mbgp filter-list WORD",
8657 SHOW_STR
8658 IPV6_STR
8659 MBGP_STR
8660 "Display routes conforming to the filter-list\n"
8661 "Regular expression access list name\n")
8662{
8663 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8664 bgp_show_type_filter_list);
8665}
8666#endif /* HAVE_IPV6 */
6b0655a2 8667
94f2b392 8668static int
fd79ac91 8669bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
718e3744 8670 safi_t safi, enum bgp_show_type type)
8671{
8672 struct route_map *rmap;
8673
8674 rmap = route_map_lookup_by_name (rmap_str);
8675 if (! rmap)
8676 {
8677 vty_out (vty, "%% %s is not a valid route-map name%s",
8678 rmap_str, VTY_NEWLINE);
8679 return CMD_WARNING;
8680 }
8681
47fc97cc 8682 return bgp_show (vty, NULL, afi, safi, type, rmap, NULL);
718e3744 8683}
8684
8685DEFUN (show_ip_bgp_route_map,
8686 show_ip_bgp_route_map_cmd,
8687 "show ip bgp route-map WORD",
8688 SHOW_STR
8689 IP_STR
8690 BGP_STR
8691 "Display routes matching the route-map\n"
8692 "A route-map to match on\n")
8693{
8694 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8695 bgp_show_type_route_map);
8696}
8697
8698DEFUN (show_ip_bgp_flap_route_map,
8699 show_ip_bgp_flap_route_map_cmd,
8700 "show ip bgp flap-statistics route-map WORD",
8701 SHOW_STR
8702 IP_STR
8703 BGP_STR
8704 "Display flap statistics of routes\n"
8705 "Display routes matching the route-map\n"
8706 "A route-map to match on\n")
8707{
8708 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8709 bgp_show_type_flap_route_map);
8710}
8711
8712DEFUN (show_ip_bgp_ipv4_route_map,
8713 show_ip_bgp_ipv4_route_map_cmd,
8714 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
8715 SHOW_STR
8716 IP_STR
8717 BGP_STR
8718 "Address family\n"
8719 "Address Family modifier\n"
8720 "Address Family modifier\n"
8721 "Display routes matching the route-map\n"
8722 "A route-map to match on\n")
8723{
8724 if (strncmp (argv[0], "m", 1) == 0)
8725 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8726 bgp_show_type_route_map);
8727
8728 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
8729 bgp_show_type_route_map);
8730}
8731
8732DEFUN (show_bgp_route_map,
8733 show_bgp_route_map_cmd,
8734 "show bgp route-map WORD",
8735 SHOW_STR
8736 BGP_STR
8737 "Display routes matching the route-map\n"
8738 "A route-map to match on\n")
8739{
8740 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8741 bgp_show_type_route_map);
8742}
8743
8744ALIAS (show_bgp_route_map,
8745 show_bgp_ipv6_route_map_cmd,
8746 "show bgp ipv6 route-map WORD",
8747 SHOW_STR
8748 BGP_STR
8749 "Address family\n"
8750 "Display routes matching the route-map\n"
8751 "A route-map to match on\n")
6b0655a2 8752
718e3744 8753DEFUN (show_ip_bgp_cidr_only,
8754 show_ip_bgp_cidr_only_cmd,
8755 "show ip bgp cidr-only",
8756 SHOW_STR
8757 IP_STR
8758 BGP_STR
8759 "Display only routes with non-natural netmasks\n")
8760{
8761 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
47fc97cc 8762 bgp_show_type_cidr_only, NULL, NULL);
718e3744 8763}
8764
8765DEFUN (show_ip_bgp_flap_cidr_only,
8766 show_ip_bgp_flap_cidr_only_cmd,
8767 "show ip bgp flap-statistics cidr-only",
8768 SHOW_STR
8769 IP_STR
8770 BGP_STR
8771 "Display flap statistics of routes\n"
8772 "Display only routes with non-natural netmasks\n")
8773{
8774 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
47fc97cc 8775 bgp_show_type_flap_cidr_only, NULL, NULL);
718e3744 8776}
8777
8778DEFUN (show_ip_bgp_ipv4_cidr_only,
8779 show_ip_bgp_ipv4_cidr_only_cmd,
8780 "show ip bgp ipv4 (unicast|multicast) cidr-only",
8781 SHOW_STR
8782 IP_STR
8783 BGP_STR
8784 "Address family\n"
8785 "Address Family modifier\n"
8786 "Address Family modifier\n"
8787 "Display only routes with non-natural netmasks\n")
8788{
8789 if (strncmp (argv[0], "m", 1) == 0)
8790 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
47fc97cc 8791 bgp_show_type_cidr_only, NULL, NULL);
718e3744 8792
8793 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
47fc97cc 8794 bgp_show_type_cidr_only, NULL, NULL);
718e3744 8795}
6b0655a2 8796
718e3744 8797DEFUN (show_ip_bgp_community_all,
8798 show_ip_bgp_community_all_cmd,
8799 "show ip bgp community",
8800 SHOW_STR
8801 IP_STR
8802 BGP_STR
8803 "Display routes matching the communities\n")
8804{
8805 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
47fc97cc 8806 bgp_show_type_community_all, NULL, NULL);
718e3744 8807}
8808
8809DEFUN (show_ip_bgp_ipv4_community_all,
8810 show_ip_bgp_ipv4_community_all_cmd,
8811 "show ip bgp ipv4 (unicast|multicast) community",
8812 SHOW_STR
8813 IP_STR
8814 BGP_STR
8815 "Address family\n"
8816 "Address Family modifier\n"
8817 "Address Family modifier\n"
8818 "Display routes matching the communities\n")
8819{
8820 if (strncmp (argv[0], "m", 1) == 0)
8821 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
47fc97cc 8822 bgp_show_type_community_all, NULL, NULL);
718e3744 8823
8824 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
47fc97cc 8825 bgp_show_type_community_all, NULL, NULL);
718e3744 8826}
8827
8828#ifdef HAVE_IPV6
8829DEFUN (show_bgp_community_all,
8830 show_bgp_community_all_cmd,
8831 "show bgp community",
8832 SHOW_STR
8833 BGP_STR
8834 "Display routes matching the communities\n")
8835{
8836 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
47fc97cc 8837 bgp_show_type_community_all, NULL, NULL);
718e3744 8838}
8839
8840ALIAS (show_bgp_community_all,
8841 show_bgp_ipv6_community_all_cmd,
8842 "show bgp ipv6 community",
8843 SHOW_STR
8844 BGP_STR
8845 "Address family\n"
8846 "Display routes matching the communities\n")
8847
8848/* old command */
8849DEFUN (show_ipv6_bgp_community_all,
8850 show_ipv6_bgp_community_all_cmd,
8851 "show ipv6 bgp community",
8852 SHOW_STR
8853 IPV6_STR
8854 BGP_STR
8855 "Display routes matching the communities\n")
8856{
8857 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
47fc97cc 8858 bgp_show_type_community_all, NULL, NULL);
718e3744 8859}
8860
8861/* old command */
8862DEFUN (show_ipv6_mbgp_community_all,
8863 show_ipv6_mbgp_community_all_cmd,
8864 "show ipv6 mbgp community",
8865 SHOW_STR
8866 IPV6_STR
8867 MBGP_STR
8868 "Display routes matching the communities\n")
8869{
8870 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
47fc97cc 8871 bgp_show_type_community_all, NULL, NULL);
718e3744 8872}
8873#endif /* HAVE_IPV6 */
6b0655a2 8874
94f2b392 8875static int
95cbbd2a
ML
8876bgp_show_community (struct vty *vty, const char *view_name, int argc,
8877 const char **argv, int exact, afi_t afi, safi_t safi)
718e3744 8878{
8879 struct community *com;
8880 struct buffer *b;
95cbbd2a 8881 struct bgp *bgp;
718e3744 8882 int i;
8883 char *str;
8884 int first = 0;
8885
95cbbd2a
ML
8886 /* BGP structure lookup */
8887 if (view_name)
8888 {
8889 bgp = bgp_lookup_by_name (view_name);
8890 if (bgp == NULL)
8891 {
8892 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8893 return CMD_WARNING;
8894 }
8895 }
8896 else
8897 {
8898 bgp = bgp_get_default ();
8899 if (bgp == NULL)
8900 {
8901 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8902 return CMD_WARNING;
8903 }
8904 }
8905
718e3744 8906 b = buffer_new (1024);
8907 for (i = 0; i < argc; i++)
8908 {
8909 if (first)
8910 buffer_putc (b, ' ');
8911 else
8912 {
8913 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8914 continue;
8915 first = 1;
8916 }
8917
8918 buffer_putstr (b, argv[i]);
8919 }
8920 buffer_putc (b, '\0');
8921
8922 str = buffer_getstr (b);
8923 buffer_free (b);
8924
8925 com = community_str2com (str);
3b8b1855 8926 XFREE (MTYPE_TMP, str);
718e3744 8927 if (! com)
8928 {
8929 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
8930 return CMD_WARNING;
8931 }
8932
95cbbd2a 8933 return bgp_show (vty, bgp, afi, safi,
5a646650 8934 (exact ? bgp_show_type_community_exact :
47fc97cc 8935 bgp_show_type_community), com, NULL);
718e3744 8936}
8937
8938DEFUN (show_ip_bgp_community,
8939 show_ip_bgp_community_cmd,
8940 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
8941 SHOW_STR
8942 IP_STR
8943 BGP_STR
8944 "Display routes matching the communities\n"
8945 "community number\n"
8946 "Do not send outside local AS (well-known community)\n"
8947 "Do not advertise to any peer (well-known community)\n"
8948 "Do not export to next AS (well-known community)\n")
8949{
95cbbd2a 8950 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 8951}
8952
8953ALIAS (show_ip_bgp_community,
8954 show_ip_bgp_community2_cmd,
8955 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8956 SHOW_STR
8957 IP_STR
8958 BGP_STR
8959 "Display routes matching the communities\n"
8960 "community number\n"
8961 "Do not send outside local AS (well-known community)\n"
8962 "Do not advertise to any peer (well-known community)\n"
8963 "Do not export to next AS (well-known community)\n"
8964 "community number\n"
8965 "Do not send outside local AS (well-known community)\n"
8966 "Do not advertise to any peer (well-known community)\n"
8967 "Do not export to next AS (well-known community)\n")
8968
8969ALIAS (show_ip_bgp_community,
8970 show_ip_bgp_community3_cmd,
8971 "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)",
8972 SHOW_STR
8973 IP_STR
8974 BGP_STR
8975 "Display routes matching the communities\n"
8976 "community number\n"
8977 "Do not send outside local AS (well-known community)\n"
8978 "Do not advertise to any peer (well-known community)\n"
8979 "Do not export to next AS (well-known community)\n"
8980 "community number\n"
8981 "Do not send outside local AS (well-known community)\n"
8982 "Do not advertise to any peer (well-known community)\n"
8983 "Do not export to next AS (well-known community)\n"
8984 "community number\n"
8985 "Do not send outside local AS (well-known community)\n"
8986 "Do not advertise to any peer (well-known community)\n"
8987 "Do not export to next AS (well-known community)\n")
8988
8989ALIAS (show_ip_bgp_community,
8990 show_ip_bgp_community4_cmd,
8991 "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)",
8992 SHOW_STR
8993 IP_STR
8994 BGP_STR
8995 "Display routes matching the communities\n"
8996 "community number\n"
8997 "Do not send outside local AS (well-known community)\n"
8998 "Do not advertise to any peer (well-known community)\n"
8999 "Do not export to next AS (well-known community)\n"
9000 "community number\n"
9001 "Do not send outside local AS (well-known community)\n"
9002 "Do not advertise to any peer (well-known community)\n"
9003 "Do not export to next AS (well-known community)\n"
9004 "community number\n"
9005 "Do not send outside local AS (well-known community)\n"
9006 "Do not advertise to any peer (well-known community)\n"
9007 "Do not export to next AS (well-known community)\n"
9008 "community number\n"
9009 "Do not send outside local AS (well-known community)\n"
9010 "Do not advertise to any peer (well-known community)\n"
9011 "Do not export to next AS (well-known community)\n")
9012
9013DEFUN (show_ip_bgp_ipv4_community,
9014 show_ip_bgp_ipv4_community_cmd,
9015 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9016 SHOW_STR
9017 IP_STR
9018 BGP_STR
9019 "Address family\n"
9020 "Address Family modifier\n"
9021 "Address Family modifier\n"
9022 "Display routes matching the communities\n"
9023 "community number\n"
9024 "Do not send outside local AS (well-known community)\n"
9025 "Do not advertise to any peer (well-known community)\n"
9026 "Do not export to next AS (well-known community)\n")
9027{
9028 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 9029 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
718e3744 9030
95cbbd2a 9031 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 9032}
9033
9034ALIAS (show_ip_bgp_ipv4_community,
9035 show_ip_bgp_ipv4_community2_cmd,
9036 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9037 SHOW_STR
9038 IP_STR
9039 BGP_STR
9040 "Address family\n"
9041 "Address Family modifier\n"
9042 "Address Family modifier\n"
9043 "Display routes matching the communities\n"
9044 "community number\n"
9045 "Do not send outside local AS (well-known community)\n"
9046 "Do not advertise to any peer (well-known community)\n"
9047 "Do not export to next AS (well-known community)\n"
9048 "community number\n"
9049 "Do not send outside local AS (well-known community)\n"
9050 "Do not advertise to any peer (well-known community)\n"
9051 "Do not export to next AS (well-known community)\n")
9052
9053ALIAS (show_ip_bgp_ipv4_community,
9054 show_ip_bgp_ipv4_community3_cmd,
9055 "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)",
9056 SHOW_STR
9057 IP_STR
9058 BGP_STR
9059 "Address family\n"
9060 "Address Family modifier\n"
9061 "Address Family modifier\n"
9062 "Display routes matching the communities\n"
9063 "community number\n"
9064 "Do not send outside local AS (well-known community)\n"
9065 "Do not advertise to any peer (well-known community)\n"
9066 "Do not export to next AS (well-known community)\n"
9067 "community number\n"
9068 "Do not send outside local AS (well-known community)\n"
9069 "Do not advertise to any peer (well-known community)\n"
9070 "Do not export to next AS (well-known community)\n"
9071 "community number\n"
9072 "Do not send outside local AS (well-known community)\n"
9073 "Do not advertise to any peer (well-known community)\n"
9074 "Do not export to next AS (well-known community)\n")
9075
9076ALIAS (show_ip_bgp_ipv4_community,
9077 show_ip_bgp_ipv4_community4_cmd,
9078 "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)",
9079 SHOW_STR
9080 IP_STR
9081 BGP_STR
9082 "Address family\n"
9083 "Address Family modifier\n"
9084 "Address Family modifier\n"
9085 "Display routes matching the communities\n"
9086 "community number\n"
9087 "Do not send outside local AS (well-known community)\n"
9088 "Do not advertise to any peer (well-known community)\n"
9089 "Do not export to next AS (well-known community)\n"
9090 "community number\n"
9091 "Do not send outside local AS (well-known community)\n"
9092 "Do not advertise to any peer (well-known community)\n"
9093 "Do not export to next AS (well-known community)\n"
9094 "community number\n"
9095 "Do not send outside local AS (well-known community)\n"
9096 "Do not advertise to any peer (well-known community)\n"
9097 "Do not export to next AS (well-known community)\n"
9098 "community number\n"
9099 "Do not send outside local AS (well-known community)\n"
9100 "Do not advertise to any peer (well-known community)\n"
9101 "Do not export to next AS (well-known community)\n")
9102
95cbbd2a
ML
9103DEFUN (show_bgp_view_afi_safi_community_all,
9104 show_bgp_view_afi_safi_community_all_cmd,
9105#ifdef HAVE_IPV6
9106 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
9107#else
9108 "show bgp view WORD ipv4 (unicast|multicast) community",
9109#endif
9110 SHOW_STR
9111 BGP_STR
9112 "BGP view\n"
2b00515a 9113 "View name\n"
95cbbd2a
ML
9114 "Address family\n"
9115#ifdef HAVE_IPV6
9116 "Address family\n"
9117#endif
9118 "Address Family modifier\n"
9119 "Address Family modifier\n"
2b00515a 9120 "Display routes matching the communities\n")
95cbbd2a
ML
9121{
9122 int afi;
9123 int safi;
9124 struct bgp *bgp;
9125
9126 /* BGP structure lookup. */
9127 bgp = bgp_lookup_by_name (argv[0]);
9128 if (bgp == NULL)
9129 {
9130 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9131 return CMD_WARNING;
9132 }
9133
9134#ifdef HAVE_IPV6
9135 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9136 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9137#else
9138 afi = AFI_IP;
9139 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9140#endif
47fc97cc 9141 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, NULL);
95cbbd2a
ML
9142}
9143
9144DEFUN (show_bgp_view_afi_safi_community,
9145 show_bgp_view_afi_safi_community_cmd,
9146#ifdef HAVE_IPV6
9147 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9148#else
9149 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9150#endif
9151 SHOW_STR
9152 BGP_STR
9153 "BGP view\n"
2b00515a 9154 "View name\n"
95cbbd2a
ML
9155 "Address family\n"
9156#ifdef HAVE_IPV6
9157 "Address family\n"
9158#endif
9159 "Address family modifier\n"
9160 "Address family modifier\n"
9161 "Display routes matching the communities\n"
9162 "community number\n"
9163 "Do not send outside local AS (well-known community)\n"
9164 "Do not advertise to any peer (well-known community)\n"
9165 "Do not export to next AS (well-known community)\n")
9166{
9167 int afi;
9168 int safi;
9169
9170#ifdef HAVE_IPV6
9171 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9172 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9173 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
9174#else
9175 afi = AFI_IP;
9176 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9177 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
9178#endif
9179}
9180
9181ALIAS (show_bgp_view_afi_safi_community,
9182 show_bgp_view_afi_safi_community2_cmd,
9183#ifdef HAVE_IPV6
9184 "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)",
9185#else
9186 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9187#endif
9188 SHOW_STR
9189 BGP_STR
9190 "BGP view\n"
2b00515a 9191 "View name\n"
95cbbd2a
ML
9192 "Address family\n"
9193#ifdef HAVE_IPV6
9194 "Address family\n"
9195#endif
9196 "Address family modifier\n"
9197 "Address family modifier\n"
9198 "Display routes matching the communities\n"
9199 "community number\n"
9200 "Do not send outside local AS (well-known community)\n"
9201 "Do not advertise to any peer (well-known community)\n"
9202 "Do not export to next AS (well-known community)\n"
9203 "community number\n"
9204 "Do not send outside local AS (well-known community)\n"
9205 "Do not advertise to any peer (well-known community)\n"
9206 "Do not export to next AS (well-known community)\n")
9207
9208ALIAS (show_bgp_view_afi_safi_community,
9209 show_bgp_view_afi_safi_community3_cmd,
9210#ifdef HAVE_IPV6
9211 "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)",
9212#else
9213 "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)",
9214#endif
9215 SHOW_STR
9216 BGP_STR
9217 "BGP view\n"
2b00515a 9218 "View name\n"
95cbbd2a
ML
9219 "Address family\n"
9220#ifdef HAVE_IPV6
9221 "Address family\n"
9222#endif
9223 "Address family modifier\n"
9224 "Address family modifier\n"
9225 "Display routes matching the communities\n"
9226 "community number\n"
9227 "Do not send outside local AS (well-known community)\n"
9228 "Do not advertise to any peer (well-known community)\n"
9229 "Do not export to next AS (well-known community)\n"
9230 "community number\n"
9231 "Do not send outside local AS (well-known community)\n"
9232 "Do not advertise to any peer (well-known community)\n"
9233 "Do not export to next AS (well-known community)\n"
9234 "community number\n"
9235 "Do not send outside local AS (well-known community)\n"
9236 "Do not advertise to any peer (well-known community)\n"
9237 "Do not export to next AS (well-known community)\n")
9238
9239ALIAS (show_bgp_view_afi_safi_community,
9240 show_bgp_view_afi_safi_community4_cmd,
9241#ifdef HAVE_IPV6
9242 "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)",
9243#else
9244 "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)",
9245#endif
9246 SHOW_STR
9247 BGP_STR
9248 "BGP view\n"
2b00515a 9249 "View name\n"
95cbbd2a
ML
9250 "Address family\n"
9251#ifdef HAVE_IPV6
9252 "Address family\n"
9253#endif
9254 "Address family modifier\n"
9255 "Address family modifier\n"
9256 "Display routes matching the communities\n"
9257 "community number\n"
9258 "Do not send outside local AS (well-known community)\n"
9259 "Do not advertise to any peer (well-known community)\n"
9260 "Do not export to next AS (well-known community)\n"
9261 "community number\n"
9262 "Do not send outside local AS (well-known community)\n"
9263 "Do not advertise to any peer (well-known community)\n"
9264 "Do not export to next AS (well-known community)\n"
9265 "community number\n"
9266 "Do not send outside local AS (well-known community)\n"
9267 "Do not advertise to any peer (well-known community)\n"
9268 "Do not export to next AS (well-known community)\n"
9269 "community number\n"
9270 "Do not send outside local AS (well-known community)\n"
9271 "Do not advertise to any peer (well-known community)\n"
9272 "Do not export to next AS (well-known community)\n")
9273
718e3744 9274DEFUN (show_ip_bgp_community_exact,
9275 show_ip_bgp_community_exact_cmd,
9276 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9277 SHOW_STR
9278 IP_STR
9279 BGP_STR
9280 "Display routes matching the communities\n"
9281 "community number\n"
9282 "Do not send outside local AS (well-known community)\n"
9283 "Do not advertise to any peer (well-known community)\n"
9284 "Do not export to next AS (well-known community)\n"
9285 "Exact match of the communities")
9286{
95cbbd2a 9287 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 9288}
9289
9290ALIAS (show_ip_bgp_community_exact,
9291 show_ip_bgp_community2_exact_cmd,
9292 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9293 SHOW_STR
9294 IP_STR
9295 BGP_STR
9296 "Display routes matching the communities\n"
9297 "community number\n"
9298 "Do not send outside local AS (well-known community)\n"
9299 "Do not advertise to any peer (well-known community)\n"
9300 "Do not export to next AS (well-known community)\n"
9301 "community number\n"
9302 "Do not send outside local AS (well-known community)\n"
9303 "Do not advertise to any peer (well-known community)\n"
9304 "Do not export to next AS (well-known community)\n"
9305 "Exact match of the communities")
9306
9307ALIAS (show_ip_bgp_community_exact,
9308 show_ip_bgp_community3_exact_cmd,
9309 "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",
9310 SHOW_STR
9311 IP_STR
9312 BGP_STR
9313 "Display routes matching the communities\n"
9314 "community number\n"
9315 "Do not send outside local AS (well-known community)\n"
9316 "Do not advertise to any peer (well-known community)\n"
9317 "Do not export to next AS (well-known community)\n"
9318 "community number\n"
9319 "Do not send outside local AS (well-known community)\n"
9320 "Do not advertise to any peer (well-known community)\n"
9321 "Do not export to next AS (well-known community)\n"
9322 "community number\n"
9323 "Do not send outside local AS (well-known community)\n"
9324 "Do not advertise to any peer (well-known community)\n"
9325 "Do not export to next AS (well-known community)\n"
9326 "Exact match of the communities")
9327
9328ALIAS (show_ip_bgp_community_exact,
9329 show_ip_bgp_community4_exact_cmd,
9330 "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",
9331 SHOW_STR
9332 IP_STR
9333 BGP_STR
9334 "Display routes matching the communities\n"
9335 "community number\n"
9336 "Do not send outside local AS (well-known community)\n"
9337 "Do not advertise to any peer (well-known community)\n"
9338 "Do not export to next AS (well-known community)\n"
9339 "community number\n"
9340 "Do not send outside local AS (well-known community)\n"
9341 "Do not advertise to any peer (well-known community)\n"
9342 "Do not export to next AS (well-known community)\n"
9343 "community number\n"
9344 "Do not send outside local AS (well-known community)\n"
9345 "Do not advertise to any peer (well-known community)\n"
9346 "Do not export to next AS (well-known community)\n"
9347 "community number\n"
9348 "Do not send outside local AS (well-known community)\n"
9349 "Do not advertise to any peer (well-known community)\n"
9350 "Do not export to next AS (well-known community)\n"
9351 "Exact match of the communities")
9352
9353DEFUN (show_ip_bgp_ipv4_community_exact,
9354 show_ip_bgp_ipv4_community_exact_cmd,
9355 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9356 SHOW_STR
9357 IP_STR
9358 BGP_STR
9359 "Address family\n"
9360 "Address Family modifier\n"
9361 "Address Family modifier\n"
9362 "Display routes matching the communities\n"
9363 "community number\n"
9364 "Do not send outside local AS (well-known community)\n"
9365 "Do not advertise to any peer (well-known community)\n"
9366 "Do not export to next AS (well-known community)\n"
9367 "Exact match of the communities")
9368{
9369 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 9370 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
718e3744 9371
95cbbd2a 9372 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 9373}
9374
9375ALIAS (show_ip_bgp_ipv4_community_exact,
9376 show_ip_bgp_ipv4_community2_exact_cmd,
9377 "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",
9378 SHOW_STR
9379 IP_STR
9380 BGP_STR
9381 "Address family\n"
9382 "Address Family modifier\n"
9383 "Address Family modifier\n"
9384 "Display routes matching the communities\n"
9385 "community number\n"
9386 "Do not send outside local AS (well-known community)\n"
9387 "Do not advertise to any peer (well-known community)\n"
9388 "Do not export to next AS (well-known community)\n"
9389 "community number\n"
9390 "Do not send outside local AS (well-known community)\n"
9391 "Do not advertise to any peer (well-known community)\n"
9392 "Do not export to next AS (well-known community)\n"
9393 "Exact match of the communities")
9394
9395ALIAS (show_ip_bgp_ipv4_community_exact,
9396 show_ip_bgp_ipv4_community3_exact_cmd,
9397 "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",
9398 SHOW_STR
9399 IP_STR
9400 BGP_STR
9401 "Address family\n"
9402 "Address Family modifier\n"
9403 "Address Family modifier\n"
9404 "Display routes matching the communities\n"
9405 "community number\n"
9406 "Do not send outside local AS (well-known community)\n"
9407 "Do not advertise to any peer (well-known community)\n"
9408 "Do not export to next AS (well-known community)\n"
9409 "community number\n"
9410 "Do not send outside local AS (well-known community)\n"
9411 "Do not advertise to any peer (well-known community)\n"
9412 "Do not export to next AS (well-known community)\n"
9413 "community number\n"
9414 "Do not send outside local AS (well-known community)\n"
9415 "Do not advertise to any peer (well-known community)\n"
9416 "Do not export to next AS (well-known community)\n"
9417 "Exact match of the communities")
9418
9419ALIAS (show_ip_bgp_ipv4_community_exact,
9420 show_ip_bgp_ipv4_community4_exact_cmd,
9421 "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",
9422 SHOW_STR
9423 IP_STR
9424 BGP_STR
9425 "Address family\n"
9426 "Address Family modifier\n"
9427 "Address Family modifier\n"
9428 "Display routes matching the communities\n"
9429 "community number\n"
9430 "Do not send outside local AS (well-known community)\n"
9431 "Do not advertise to any peer (well-known community)\n"
9432 "Do not export to next AS (well-known community)\n"
9433 "community number\n"
9434 "Do not send outside local AS (well-known community)\n"
9435 "Do not advertise to any peer (well-known community)\n"
9436 "Do not export to next AS (well-known community)\n"
9437 "community number\n"
9438 "Do not send outside local AS (well-known community)\n"
9439 "Do not advertise to any peer (well-known community)\n"
9440 "Do not export to next AS (well-known community)\n"
9441 "community number\n"
9442 "Do not send outside local AS (well-known community)\n"
9443 "Do not advertise to any peer (well-known community)\n"
9444 "Do not export to next AS (well-known community)\n"
9445 "Exact match of the communities")
9446
9447#ifdef HAVE_IPV6
9448DEFUN (show_bgp_community,
9449 show_bgp_community_cmd,
9450 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
9451 SHOW_STR
9452 BGP_STR
9453 "Display routes matching the communities\n"
9454 "community number\n"
9455 "Do not send outside local AS (well-known community)\n"
9456 "Do not advertise to any peer (well-known community)\n"
9457 "Do not export to next AS (well-known community)\n")
9458{
95cbbd2a 9459 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 9460}
9461
9462ALIAS (show_bgp_community,
9463 show_bgp_ipv6_community_cmd,
9464 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
9465 SHOW_STR
9466 BGP_STR
9467 "Address family\n"
9468 "Display routes matching the communities\n"
9469 "community number\n"
9470 "Do not send outside local AS (well-known community)\n"
9471 "Do not advertise to any peer (well-known community)\n"
9472 "Do not export to next AS (well-known community)\n")
9473
9474ALIAS (show_bgp_community,
9475 show_bgp_community2_cmd,
9476 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9477 SHOW_STR
9478 BGP_STR
9479 "Display routes matching the communities\n"
9480 "community number\n"
9481 "Do not send outside local AS (well-known community)\n"
9482 "Do not advertise to any peer (well-known community)\n"
9483 "Do not export to next AS (well-known community)\n"
9484 "community number\n"
9485 "Do not send outside local AS (well-known community)\n"
9486 "Do not advertise to any peer (well-known community)\n"
9487 "Do not export to next AS (well-known community)\n")
9488
9489ALIAS (show_bgp_community,
9490 show_bgp_ipv6_community2_cmd,
9491 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9492 SHOW_STR
9493 BGP_STR
9494 "Address family\n"
9495 "Display routes matching the communities\n"
9496 "community number\n"
9497 "Do not send outside local AS (well-known community)\n"
9498 "Do not advertise to any peer (well-known community)\n"
9499 "Do not export to next AS (well-known community)\n"
9500 "community number\n"
9501 "Do not send outside local AS (well-known community)\n"
9502 "Do not advertise to any peer (well-known community)\n"
9503 "Do not export to next AS (well-known community)\n")
9504
9505ALIAS (show_bgp_community,
9506 show_bgp_community3_cmd,
9507 "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)",
9508 SHOW_STR
9509 BGP_STR
9510 "Display routes matching the communities\n"
9511 "community number\n"
9512 "Do not send outside local AS (well-known community)\n"
9513 "Do not advertise to any peer (well-known community)\n"
9514 "Do not export to next AS (well-known community)\n"
9515 "community number\n"
9516 "Do not send outside local AS (well-known community)\n"
9517 "Do not advertise to any peer (well-known community)\n"
9518 "Do not export to next AS (well-known community)\n"
9519 "community number\n"
9520 "Do not send outside local AS (well-known community)\n"
9521 "Do not advertise to any peer (well-known community)\n"
9522 "Do not export to next AS (well-known community)\n")
9523
9524ALIAS (show_bgp_community,
9525 show_bgp_ipv6_community3_cmd,
9526 "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)",
9527 SHOW_STR
9528 BGP_STR
9529 "Address family\n"
9530 "Display routes matching the communities\n"
9531 "community number\n"
9532 "Do not send outside local AS (well-known community)\n"
9533 "Do not advertise to any peer (well-known community)\n"
9534 "Do not export to next AS (well-known community)\n"
9535 "community number\n"
9536 "Do not send outside local AS (well-known community)\n"
9537 "Do not advertise to any peer (well-known community)\n"
9538 "Do not export to next AS (well-known community)\n"
9539 "community number\n"
9540 "Do not send outside local AS (well-known community)\n"
9541 "Do not advertise to any peer (well-known community)\n"
9542 "Do not export to next AS (well-known community)\n")
9543
9544ALIAS (show_bgp_community,
9545 show_bgp_community4_cmd,
9546 "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)",
9547 SHOW_STR
9548 BGP_STR
9549 "Display routes matching the communities\n"
9550 "community number\n"
9551 "Do not send outside local AS (well-known community)\n"
9552 "Do not advertise to any peer (well-known community)\n"
9553 "Do not export to next AS (well-known community)\n"
9554 "community number\n"
9555 "Do not send outside local AS (well-known community)\n"
9556 "Do not advertise to any peer (well-known community)\n"
9557 "Do not export to next AS (well-known community)\n"
9558 "community number\n"
9559 "Do not send outside local AS (well-known community)\n"
9560 "Do not advertise to any peer (well-known community)\n"
9561 "Do not export to next AS (well-known community)\n"
9562 "community number\n"
9563 "Do not send outside local AS (well-known community)\n"
9564 "Do not advertise to any peer (well-known community)\n"
9565 "Do not export to next AS (well-known community)\n")
9566
9567ALIAS (show_bgp_community,
9568 show_bgp_ipv6_community4_cmd,
9569 "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)",
9570 SHOW_STR
9571 BGP_STR
9572 "Address family\n"
9573 "Display routes matching the communities\n"
9574 "community number\n"
9575 "Do not send outside local AS (well-known community)\n"
9576 "Do not advertise to any peer (well-known community)\n"
9577 "Do not export to next AS (well-known community)\n"
9578 "community number\n"
9579 "Do not send outside local AS (well-known community)\n"
9580 "Do not advertise to any peer (well-known community)\n"
9581 "Do not export to next AS (well-known community)\n"
9582 "community number\n"
9583 "Do not send outside local AS (well-known community)\n"
9584 "Do not advertise to any peer (well-known community)\n"
9585 "Do not export to next AS (well-known community)\n"
9586 "community number\n"
9587 "Do not send outside local AS (well-known community)\n"
9588 "Do not advertise to any peer (well-known community)\n"
9589 "Do not export to next AS (well-known community)\n")
9590
9591/* old command */
9592DEFUN (show_ipv6_bgp_community,
9593 show_ipv6_bgp_community_cmd,
9594 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
9595 SHOW_STR
9596 IPV6_STR
9597 BGP_STR
9598 "Display routes matching the communities\n"
9599 "community number\n"
9600 "Do not send outside local AS (well-known community)\n"
9601 "Do not advertise to any peer (well-known community)\n"
9602 "Do not export to next AS (well-known community)\n")
9603{
95cbbd2a 9604 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 9605}
9606
9607/* old command */
9608ALIAS (show_ipv6_bgp_community,
9609 show_ipv6_bgp_community2_cmd,
9610 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9611 SHOW_STR
9612 IPV6_STR
9613 BGP_STR
9614 "Display routes matching the communities\n"
9615 "community number\n"
9616 "Do not send outside local AS (well-known community)\n"
9617 "Do not advertise to any peer (well-known community)\n"
9618 "Do not export to next AS (well-known community)\n"
9619 "community number\n"
9620 "Do not send outside local AS (well-known community)\n"
9621 "Do not advertise to any peer (well-known community)\n"
9622 "Do not export to next AS (well-known community)\n")
9623
9624/* old command */
9625ALIAS (show_ipv6_bgp_community,
9626 show_ipv6_bgp_community3_cmd,
9627 "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)",
9628 SHOW_STR
9629 IPV6_STR
9630 BGP_STR
9631 "Display routes matching the communities\n"
9632 "community number\n"
9633 "Do not send outside local AS (well-known community)\n"
9634 "Do not advertise to any peer (well-known community)\n"
9635 "Do not export to next AS (well-known community)\n"
9636 "community number\n"
9637 "Do not send outside local AS (well-known community)\n"
9638 "Do not advertise to any peer (well-known community)\n"
9639 "Do not export to next AS (well-known community)\n"
9640 "community number\n"
9641 "Do not send outside local AS (well-known community)\n"
9642 "Do not advertise to any peer (well-known community)\n"
9643 "Do not export to next AS (well-known community)\n")
9644
9645/* old command */
9646ALIAS (show_ipv6_bgp_community,
9647 show_ipv6_bgp_community4_cmd,
9648 "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)",
9649 SHOW_STR
9650 IPV6_STR
9651 BGP_STR
9652 "Display routes matching the communities\n"
9653 "community number\n"
9654 "Do not send outside local AS (well-known community)\n"
9655 "Do not advertise to any peer (well-known community)\n"
9656 "Do not export to next AS (well-known community)\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 "community number\n"
9662 "Do not send outside local AS (well-known community)\n"
9663 "Do not advertise to any peer (well-known community)\n"
9664 "Do not export to next AS (well-known community)\n"
9665 "community number\n"
9666 "Do not send outside local AS (well-known community)\n"
9667 "Do not advertise to any peer (well-known community)\n"
9668 "Do not export to next AS (well-known community)\n")
9669
9670DEFUN (show_bgp_community_exact,
9671 show_bgp_community_exact_cmd,
9672 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9673 SHOW_STR
9674 BGP_STR
9675 "Display routes matching the communities\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 "Exact match of the communities")
9681{
95cbbd2a 9682 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 9683}
9684
9685ALIAS (show_bgp_community_exact,
9686 show_bgp_ipv6_community_exact_cmd,
9687 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9688 SHOW_STR
9689 BGP_STR
9690 "Address family\n"
9691 "Display routes matching the communities\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 "Exact match of the communities")
9697
9698ALIAS (show_bgp_community_exact,
9699 show_bgp_community2_exact_cmd,
9700 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9701 SHOW_STR
9702 BGP_STR
9703 "Display routes matching the communities\n"
9704 "community number\n"
9705 "Do not send outside local AS (well-known community)\n"
9706 "Do not advertise to any peer (well-known community)\n"
9707 "Do not export to next AS (well-known community)\n"
9708 "community number\n"
9709 "Do not send outside local AS (well-known community)\n"
9710 "Do not advertise to any peer (well-known community)\n"
9711 "Do not export to next AS (well-known community)\n"
9712 "Exact match of the communities")
9713
9714ALIAS (show_bgp_community_exact,
9715 show_bgp_ipv6_community2_exact_cmd,
9716 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9717 SHOW_STR
9718 BGP_STR
9719 "Address family\n"
9720 "Display routes matching the communities\n"
9721 "community number\n"
9722 "Do not send outside local AS (well-known community)\n"
9723 "Do not advertise to any peer (well-known community)\n"
9724 "Do not export to next AS (well-known community)\n"
9725 "community number\n"
9726 "Do not send outside local AS (well-known community)\n"
9727 "Do not advertise to any peer (well-known community)\n"
9728 "Do not export to next AS (well-known community)\n"
9729 "Exact match of the communities")
9730
9731ALIAS (show_bgp_community_exact,
9732 show_bgp_community3_exact_cmd,
9733 "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",
9734 SHOW_STR
9735 BGP_STR
9736 "Display routes matching the communities\n"
9737 "community number\n"
9738 "Do not send outside local AS (well-known community)\n"
9739 "Do not advertise to any peer (well-known community)\n"
9740 "Do not export to next AS (well-known community)\n"
9741 "community number\n"
9742 "Do not send outside local AS (well-known community)\n"
9743 "Do not advertise to any peer (well-known community)\n"
9744 "Do not export to next AS (well-known community)\n"
9745 "community number\n"
9746 "Do not send outside local AS (well-known community)\n"
9747 "Do not advertise to any peer (well-known community)\n"
9748 "Do not export to next AS (well-known community)\n"
9749 "Exact match of the communities")
9750
9751ALIAS (show_bgp_community_exact,
9752 show_bgp_ipv6_community3_exact_cmd,
9753 "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",
9754 SHOW_STR
9755 BGP_STR
9756 "Address family\n"
9757 "Display routes matching the communities\n"
9758 "community number\n"
9759 "Do not send outside local AS (well-known community)\n"
9760 "Do not advertise to any peer (well-known community)\n"
9761 "Do not export to next AS (well-known community)\n"
9762 "community number\n"
9763 "Do not send outside local AS (well-known community)\n"
9764 "Do not advertise to any peer (well-known community)\n"
9765 "Do not export to next AS (well-known community)\n"
9766 "community number\n"
9767 "Do not send outside local AS (well-known community)\n"
9768 "Do not advertise to any peer (well-known community)\n"
9769 "Do not export to next AS (well-known community)\n"
9770 "Exact match of the communities")
9771
9772ALIAS (show_bgp_community_exact,
9773 show_bgp_community4_exact_cmd,
9774 "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",
9775 SHOW_STR
9776 BGP_STR
9777 "Display routes matching the communities\n"
9778 "community number\n"
9779 "Do not send outside local AS (well-known community)\n"
9780 "Do not advertise to any peer (well-known community)\n"
9781 "Do not export to next AS (well-known community)\n"
9782 "community number\n"
9783 "Do not send outside local AS (well-known community)\n"
9784 "Do not advertise to any peer (well-known community)\n"
9785 "Do not export to next AS (well-known community)\n"
9786 "community number\n"
9787 "Do not send outside local AS (well-known community)\n"
9788 "Do not advertise to any peer (well-known community)\n"
9789 "Do not export to next AS (well-known community)\n"
9790 "community number\n"
9791 "Do not send outside local AS (well-known community)\n"
9792 "Do not advertise to any peer (well-known community)\n"
9793 "Do not export to next AS (well-known community)\n"
9794 "Exact match of the communities")
9795
9796ALIAS (show_bgp_community_exact,
9797 show_bgp_ipv6_community4_exact_cmd,
9798 "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",
9799 SHOW_STR
9800 BGP_STR
9801 "Address family\n"
9802 "Display routes matching the communities\n"
9803 "community number\n"
9804 "Do not send outside local AS (well-known community)\n"
9805 "Do not advertise to any peer (well-known community)\n"
9806 "Do not export to next AS (well-known community)\n"
9807 "community number\n"
9808 "Do not send outside local AS (well-known community)\n"
9809 "Do not advertise to any peer (well-known community)\n"
9810 "Do not export to next AS (well-known community)\n"
9811 "community number\n"
9812 "Do not send outside local AS (well-known community)\n"
9813 "Do not advertise to any peer (well-known community)\n"
9814 "Do not export to next AS (well-known community)\n"
9815 "community number\n"
9816 "Do not send outside local AS (well-known community)\n"
9817 "Do not advertise to any peer (well-known community)\n"
9818 "Do not export to next AS (well-known community)\n"
9819 "Exact match of the communities")
9820
9821/* old command */
9822DEFUN (show_ipv6_bgp_community_exact,
9823 show_ipv6_bgp_community_exact_cmd,
9824 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9825 SHOW_STR
9826 IPV6_STR
9827 BGP_STR
9828 "Display routes matching the communities\n"
9829 "community number\n"
9830 "Do not send outside local AS (well-known community)\n"
9831 "Do not advertise to any peer (well-known community)\n"
9832 "Do not export to next AS (well-known community)\n"
9833 "Exact match of the communities")
9834{
95cbbd2a 9835 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 9836}
9837
9838/* old command */
9839ALIAS (show_ipv6_bgp_community_exact,
9840 show_ipv6_bgp_community2_exact_cmd,
9841 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9842 SHOW_STR
9843 IPV6_STR
9844 BGP_STR
9845 "Display routes matching the communities\n"
9846 "community number\n"
9847 "Do not send outside local AS (well-known community)\n"
9848 "Do not advertise to any peer (well-known community)\n"
9849 "Do not export to next AS (well-known community)\n"
9850 "community number\n"
9851 "Do not send outside local AS (well-known community)\n"
9852 "Do not advertise to any peer (well-known community)\n"
9853 "Do not export to next AS (well-known community)\n"
9854 "Exact match of the communities")
9855
9856/* old command */
9857ALIAS (show_ipv6_bgp_community_exact,
9858 show_ipv6_bgp_community3_exact_cmd,
9859 "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",
9860 SHOW_STR
9861 IPV6_STR
9862 BGP_STR
9863 "Display routes matching the communities\n"
9864 "community number\n"
9865 "Do not send outside local AS (well-known community)\n"
9866 "Do not advertise to any peer (well-known community)\n"
9867 "Do not export to next AS (well-known community)\n"
9868 "community number\n"
9869 "Do not send outside local AS (well-known community)\n"
9870 "Do not advertise to any peer (well-known community)\n"
9871 "Do not export to next AS (well-known community)\n"
9872 "community number\n"
9873 "Do not send outside local AS (well-known community)\n"
9874 "Do not advertise to any peer (well-known community)\n"
9875 "Do not export to next AS (well-known community)\n"
9876 "Exact match of the communities")
9877
9878/* old command */
9879ALIAS (show_ipv6_bgp_community_exact,
9880 show_ipv6_bgp_community4_exact_cmd,
9881 "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",
9882 SHOW_STR
9883 IPV6_STR
9884 BGP_STR
9885 "Display routes matching the communities\n"
9886 "community number\n"
9887 "Do not send outside local AS (well-known community)\n"
9888 "Do not advertise to any peer (well-known community)\n"
9889 "Do not export to next AS (well-known community)\n"
9890 "community number\n"
9891 "Do not send outside local AS (well-known community)\n"
9892 "Do not advertise to any peer (well-known community)\n"
9893 "Do not export to next AS (well-known community)\n"
9894 "community number\n"
9895 "Do not send outside local AS (well-known community)\n"
9896 "Do not advertise to any peer (well-known community)\n"
9897 "Do not export to next AS (well-known community)\n"
9898 "community number\n"
9899 "Do not send outside local AS (well-known community)\n"
9900 "Do not advertise to any peer (well-known community)\n"
9901 "Do not export to next AS (well-known community)\n"
9902 "Exact match of the communities")
9903
9904/* old command */
9905DEFUN (show_ipv6_mbgp_community,
9906 show_ipv6_mbgp_community_cmd,
9907 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
9908 SHOW_STR
9909 IPV6_STR
9910 MBGP_STR
9911 "Display routes matching the communities\n"
9912 "community number\n"
9913 "Do not send outside local AS (well-known community)\n"
9914 "Do not advertise to any peer (well-known community)\n"
9915 "Do not export to next AS (well-known community)\n")
9916{
95cbbd2a 9917 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
718e3744 9918}
9919
9920/* old command */
9921ALIAS (show_ipv6_mbgp_community,
9922 show_ipv6_mbgp_community2_cmd,
9923 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9924 SHOW_STR
9925 IPV6_STR
9926 MBGP_STR
9927 "Display routes matching the communities\n"
9928 "community number\n"
9929 "Do not send outside local AS (well-known community)\n"
9930 "Do not advertise to any peer (well-known community)\n"
9931 "Do not export to next AS (well-known community)\n"
9932 "community number\n"
9933 "Do not send outside local AS (well-known community)\n"
9934 "Do not advertise to any peer (well-known community)\n"
9935 "Do not export to next AS (well-known community)\n")
9936
9937/* old command */
9938ALIAS (show_ipv6_mbgp_community,
9939 show_ipv6_mbgp_community3_cmd,
9940 "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)",
9941 SHOW_STR
9942 IPV6_STR
9943 MBGP_STR
9944 "Display routes matching the communities\n"
9945 "community number\n"
9946 "Do not send outside local AS (well-known community)\n"
9947 "Do not advertise to any peer (well-known community)\n"
9948 "Do not export to next AS (well-known community)\n"
9949 "community number\n"
9950 "Do not send outside local AS (well-known community)\n"
9951 "Do not advertise to any peer (well-known community)\n"
9952 "Do not export to next AS (well-known community)\n"
9953 "community number\n"
9954 "Do not send outside local AS (well-known community)\n"
9955 "Do not advertise to any peer (well-known community)\n"
9956 "Do not export to next AS (well-known community)\n")
9957
9958/* old command */
9959ALIAS (show_ipv6_mbgp_community,
9960 show_ipv6_mbgp_community4_cmd,
9961 "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)",
9962 SHOW_STR
9963 IPV6_STR
9964 MBGP_STR
9965 "Display routes matching the communities\n"
9966 "community number\n"
9967 "Do not send outside local AS (well-known community)\n"
9968 "Do not advertise to any peer (well-known community)\n"
9969 "Do not export to next AS (well-known community)\n"
9970 "community number\n"
9971 "Do not send outside local AS (well-known community)\n"
9972 "Do not advertise to any peer (well-known community)\n"
9973 "Do not export to next AS (well-known community)\n"
9974 "community number\n"
9975 "Do not send outside local AS (well-known community)\n"
9976 "Do not advertise to any peer (well-known community)\n"
9977 "Do not export to next AS (well-known community)\n"
9978 "community number\n"
9979 "Do not send outside local AS (well-known community)\n"
9980 "Do not advertise to any peer (well-known community)\n"
9981 "Do not export to next AS (well-known community)\n")
9982
9983/* old command */
9984DEFUN (show_ipv6_mbgp_community_exact,
9985 show_ipv6_mbgp_community_exact_cmd,
9986 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9987 SHOW_STR
9988 IPV6_STR
9989 MBGP_STR
9990 "Display routes matching the communities\n"
9991 "community number\n"
9992 "Do not send outside local AS (well-known community)\n"
9993 "Do not advertise to any peer (well-known community)\n"
9994 "Do not export to next AS (well-known community)\n"
9995 "Exact match of the communities")
9996{
95cbbd2a 9997 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
718e3744 9998}
9999
10000/* old command */
10001ALIAS (show_ipv6_mbgp_community_exact,
10002 show_ipv6_mbgp_community2_exact_cmd,
10003 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10004 SHOW_STR
10005 IPV6_STR
10006 MBGP_STR
10007 "Display routes matching the communities\n"
10008 "community number\n"
10009 "Do not send outside local AS (well-known community)\n"
10010 "Do not advertise to any peer (well-known community)\n"
10011 "Do not export to next AS (well-known community)\n"
10012 "community number\n"
10013 "Do not send outside local AS (well-known community)\n"
10014 "Do not advertise to any peer (well-known community)\n"
10015 "Do not export to next AS (well-known community)\n"
10016 "Exact match of the communities")
10017
10018/* old command */
10019ALIAS (show_ipv6_mbgp_community_exact,
10020 show_ipv6_mbgp_community3_exact_cmd,
10021 "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",
10022 SHOW_STR
10023 IPV6_STR
10024 MBGP_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
10040/* old command */
10041ALIAS (show_ipv6_mbgp_community_exact,
10042 show_ipv6_mbgp_community4_exact_cmd,
10043 "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",
10044 SHOW_STR
10045 IPV6_STR
10046 MBGP_STR
10047 "Display routes matching the communities\n"
10048 "community number\n"
10049 "Do not send outside local AS (well-known community)\n"
10050 "Do not advertise to any peer (well-known community)\n"
10051 "Do not export to next AS (well-known community)\n"
10052 "community number\n"
10053 "Do not send outside local AS (well-known community)\n"
10054 "Do not advertise to any peer (well-known community)\n"
10055 "Do not export to next AS (well-known community)\n"
10056 "community number\n"
10057 "Do not send outside local AS (well-known community)\n"
10058 "Do not advertise to any peer (well-known community)\n"
10059 "Do not export to next AS (well-known community)\n"
10060 "community number\n"
10061 "Do not send outside local AS (well-known community)\n"
10062 "Do not advertise to any peer (well-known community)\n"
10063 "Do not export to next AS (well-known community)\n"
10064 "Exact match of the communities")
10065#endif /* HAVE_IPV6 */
6b0655a2 10066
94f2b392 10067static int
fd79ac91 10068bgp_show_community_list (struct vty *vty, const char *com, int exact,
4c9641ba 10069 afi_t afi, safi_t safi)
718e3744 10070{
10071 struct community_list *list;
10072
fee6e4e4 10073 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
718e3744 10074 if (list == NULL)
10075 {
10076 vty_out (vty, "%% %s is not a valid community-list name%s", com,
10077 VTY_NEWLINE);
10078 return CMD_WARNING;
10079 }
10080
5a646650 10081 return bgp_show (vty, NULL, afi, safi,
10082 (exact ? bgp_show_type_community_list_exact :
47fc97cc 10083 bgp_show_type_community_list), list, NULL);
718e3744 10084}
10085
10086DEFUN (show_ip_bgp_community_list,
10087 show_ip_bgp_community_list_cmd,
fee6e4e4 10088 "show ip bgp community-list (<1-500>|WORD)",
718e3744 10089 SHOW_STR
10090 IP_STR
10091 BGP_STR
10092 "Display routes matching the community-list\n"
fee6e4e4 10093 "community-list number\n"
718e3744 10094 "community-list name\n")
10095{
10096 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
10097}
10098
10099DEFUN (show_ip_bgp_ipv4_community_list,
10100 show_ip_bgp_ipv4_community_list_cmd,
fee6e4e4 10101 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
718e3744 10102 SHOW_STR
10103 IP_STR
10104 BGP_STR
10105 "Address family\n"
10106 "Address Family modifier\n"
10107 "Address Family modifier\n"
10108 "Display routes matching the community-list\n"
fee6e4e4 10109 "community-list number\n"
718e3744 10110 "community-list name\n")
10111{
10112 if (strncmp (argv[0], "m", 1) == 0)
10113 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
10114
10115 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
10116}
10117
10118DEFUN (show_ip_bgp_community_list_exact,
10119 show_ip_bgp_community_list_exact_cmd,
fee6e4e4 10120 "show ip bgp community-list (<1-500>|WORD) exact-match",
718e3744 10121 SHOW_STR
10122 IP_STR
10123 BGP_STR
10124 "Display routes matching the community-list\n"
fee6e4e4 10125 "community-list number\n"
718e3744 10126 "community-list name\n"
10127 "Exact match of the communities\n")
10128{
10129 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
10130}
10131
10132DEFUN (show_ip_bgp_ipv4_community_list_exact,
10133 show_ip_bgp_ipv4_community_list_exact_cmd,
fee6e4e4 10134 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
718e3744 10135 SHOW_STR
10136 IP_STR
10137 BGP_STR
10138 "Address family\n"
10139 "Address Family modifier\n"
10140 "Address Family modifier\n"
10141 "Display routes matching the community-list\n"
fee6e4e4 10142 "community-list number\n"
718e3744 10143 "community-list name\n"
10144 "Exact match of the communities\n")
10145{
10146 if (strncmp (argv[0], "m", 1) == 0)
10147 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
10148
10149 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
10150}
10151
10152#ifdef HAVE_IPV6
10153DEFUN (show_bgp_community_list,
10154 show_bgp_community_list_cmd,
fee6e4e4 10155 "show bgp community-list (<1-500>|WORD)",
718e3744 10156 SHOW_STR
10157 BGP_STR
10158 "Display routes matching the community-list\n"
fee6e4e4 10159 "community-list number\n"
718e3744 10160 "community-list name\n")
10161{
10162 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10163}
10164
10165ALIAS (show_bgp_community_list,
10166 show_bgp_ipv6_community_list_cmd,
fee6e4e4 10167 "show bgp ipv6 community-list (<1-500>|WORD)",
718e3744 10168 SHOW_STR
10169 BGP_STR
10170 "Address family\n"
10171 "Display routes matching the community-list\n"
fee6e4e4 10172 "community-list number\n"
e8e1946e 10173 "community-list name\n")
718e3744 10174
10175/* old command */
10176DEFUN (show_ipv6_bgp_community_list,
10177 show_ipv6_bgp_community_list_cmd,
10178 "show ipv6 bgp community-list WORD",
10179 SHOW_STR
10180 IPV6_STR
10181 BGP_STR
10182 "Display routes matching the community-list\n"
10183 "community-list name\n")
10184{
10185 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10186}
10187
10188/* old command */
10189DEFUN (show_ipv6_mbgp_community_list,
10190 show_ipv6_mbgp_community_list_cmd,
10191 "show ipv6 mbgp community-list WORD",
10192 SHOW_STR
10193 IPV6_STR
10194 MBGP_STR
10195 "Display routes matching the community-list\n"
10196 "community-list name\n")
10197{
10198 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
10199}
10200
10201DEFUN (show_bgp_community_list_exact,
10202 show_bgp_community_list_exact_cmd,
fee6e4e4 10203 "show bgp community-list (<1-500>|WORD) exact-match",
718e3744 10204 SHOW_STR
10205 BGP_STR
10206 "Display routes matching the community-list\n"
fee6e4e4 10207 "community-list number\n"
718e3744 10208 "community-list name\n"
10209 "Exact match of the communities\n")
10210{
10211 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10212}
10213
10214ALIAS (show_bgp_community_list_exact,
10215 show_bgp_ipv6_community_list_exact_cmd,
fee6e4e4 10216 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
718e3744 10217 SHOW_STR
10218 BGP_STR
10219 "Address family\n"
10220 "Display routes matching the community-list\n"
fee6e4e4 10221 "community-list number\n"
718e3744 10222 "community-list name\n"
10223 "Exact match of the communities\n")
10224
10225/* old command */
10226DEFUN (show_ipv6_bgp_community_list_exact,
10227 show_ipv6_bgp_community_list_exact_cmd,
10228 "show ipv6 bgp community-list WORD exact-match",
10229 SHOW_STR
10230 IPV6_STR
10231 BGP_STR
10232 "Display routes matching the community-list\n"
10233 "community-list name\n"
10234 "Exact match of the communities\n")
10235{
10236 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10237}
10238
10239/* old command */
10240DEFUN (show_ipv6_mbgp_community_list_exact,
10241 show_ipv6_mbgp_community_list_exact_cmd,
10242 "show ipv6 mbgp community-list WORD exact-match",
10243 SHOW_STR
10244 IPV6_STR
10245 MBGP_STR
10246 "Display routes matching the community-list\n"
10247 "community-list name\n"
10248 "Exact match of the communities\n")
10249{
10250 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
10251}
10252#endif /* HAVE_IPV6 */
6b0655a2 10253
94f2b392 10254static int
fd79ac91 10255bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
718e3744 10256 safi_t safi, enum bgp_show_type type)
10257{
10258 int ret;
10259 struct prefix *p;
10260
10261 p = prefix_new();
10262
10263 ret = str2prefix (prefix, p);
10264 if (! ret)
10265 {
10266 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
10267 return CMD_WARNING;
10268 }
10269
47fc97cc 10270 ret = bgp_show (vty, NULL, afi, safi, type, p, NULL);
5a646650 10271 prefix_free(p);
10272 return ret;
718e3744 10273}
10274
10275DEFUN (show_ip_bgp_prefix_longer,
10276 show_ip_bgp_prefix_longer_cmd,
10277 "show ip bgp A.B.C.D/M longer-prefixes",
10278 SHOW_STR
10279 IP_STR
10280 BGP_STR
10281 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10282 "Display route and more specific routes\n")
10283{
10284 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
10285 bgp_show_type_prefix_longer);
10286}
10287
10288DEFUN (show_ip_bgp_flap_prefix_longer,
10289 show_ip_bgp_flap_prefix_longer_cmd,
10290 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
10291 SHOW_STR
10292 IP_STR
10293 BGP_STR
10294 "Display flap statistics of routes\n"
10295 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10296 "Display route and more specific routes\n")
10297{
10298 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
10299 bgp_show_type_flap_prefix_longer);
10300}
10301
10302DEFUN (show_ip_bgp_ipv4_prefix_longer,
10303 show_ip_bgp_ipv4_prefix_longer_cmd,
10304 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
10305 SHOW_STR
10306 IP_STR
10307 BGP_STR
10308 "Address family\n"
10309 "Address Family modifier\n"
10310 "Address Family modifier\n"
10311 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10312 "Display route and more specific routes\n")
10313{
10314 if (strncmp (argv[0], "m", 1) == 0)
10315 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
10316 bgp_show_type_prefix_longer);
10317
10318 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
10319 bgp_show_type_prefix_longer);
10320}
10321
10322DEFUN (show_ip_bgp_flap_address,
10323 show_ip_bgp_flap_address_cmd,
10324 "show ip bgp flap-statistics A.B.C.D",
10325 SHOW_STR
10326 IP_STR
10327 BGP_STR
10328 "Display flap statistics of routes\n"
10329 "Network in the BGP routing table to display\n")
10330{
10331 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
10332 bgp_show_type_flap_address);
10333}
10334
10335DEFUN (show_ip_bgp_flap_prefix,
10336 show_ip_bgp_flap_prefix_cmd,
10337 "show ip bgp flap-statistics A.B.C.D/M",
10338 SHOW_STR
10339 IP_STR
10340 BGP_STR
10341 "Display flap statistics of routes\n"
10342 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10343{
10344 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
10345 bgp_show_type_flap_prefix);
10346}
10347#ifdef HAVE_IPV6
10348DEFUN (show_bgp_prefix_longer,
10349 show_bgp_prefix_longer_cmd,
10350 "show bgp X:X::X:X/M longer-prefixes",
10351 SHOW_STR
10352 BGP_STR
10353 "IPv6 prefix <network>/<length>\n"
10354 "Display route and more specific routes\n")
10355{
10356 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
10357 bgp_show_type_prefix_longer);
10358}
10359
10360ALIAS (show_bgp_prefix_longer,
10361 show_bgp_ipv6_prefix_longer_cmd,
10362 "show bgp ipv6 X:X::X:X/M longer-prefixes",
10363 SHOW_STR
10364 BGP_STR
10365 "Address family\n"
10366 "IPv6 prefix <network>/<length>\n"
10367 "Display route and more specific routes\n")
10368
10369/* old command */
10370DEFUN (show_ipv6_bgp_prefix_longer,
10371 show_ipv6_bgp_prefix_longer_cmd,
10372 "show ipv6 bgp X:X::X:X/M longer-prefixes",
10373 SHOW_STR
10374 IPV6_STR
10375 BGP_STR
10376 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
10377 "Display route and more specific routes\n")
10378{
10379 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
10380 bgp_show_type_prefix_longer);
10381}
10382
10383/* old command */
10384DEFUN (show_ipv6_mbgp_prefix_longer,
10385 show_ipv6_mbgp_prefix_longer_cmd,
10386 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
10387 SHOW_STR
10388 IPV6_STR
10389 MBGP_STR
10390 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
10391 "Display route and more specific routes\n")
10392{
10393 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
10394 bgp_show_type_prefix_longer);
10395}
10396#endif /* HAVE_IPV6 */
bb46e94f 10397
94f2b392 10398static struct peer *
fd79ac91 10399peer_lookup_in_view (struct vty *vty, const char *view_name,
10400 const char *ip_str)
bb46e94f 10401{
10402 int ret;
10403 struct bgp *bgp;
10404 struct peer *peer;
10405 union sockunion su;
10406
10407 /* BGP structure lookup. */
10408 if (view_name)
10409 {
10410 bgp = bgp_lookup_by_name (view_name);
10411 if (! bgp)
10412 {
10413 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
10414 return NULL;
10415 }
10416 }
5228ad27 10417 else
bb46e94f 10418 {
10419 bgp = bgp_get_default ();
10420 if (! bgp)
10421 {
10422 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10423 return NULL;
10424 }
10425 }
10426
10427 /* Get peer sockunion. */
10428 ret = str2sockunion (ip_str, &su);
10429 if (ret < 0)
10430 {
a80beece
DS
10431 peer = peer_lookup_by_conf_if (bgp, ip_str);
10432 if (!peer)
10433 {
10434 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
10435 return NULL;
10436 }
10437 return peer;
bb46e94f 10438 }
10439
10440 /* Peer structure lookup. */
10441 peer = peer_lookup (bgp, &su);
10442 if (! peer)
10443 {
10444 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
10445 return NULL;
10446 }
10447
10448 return peer;
10449}
6b0655a2 10450
2815e61f
PJ
10451enum bgp_stats
10452{
10453 BGP_STATS_MAXBITLEN = 0,
10454 BGP_STATS_RIB,
10455 BGP_STATS_PREFIXES,
10456 BGP_STATS_TOTPLEN,
10457 BGP_STATS_UNAGGREGATEABLE,
10458 BGP_STATS_MAX_AGGREGATEABLE,
10459 BGP_STATS_AGGREGATES,
10460 BGP_STATS_SPACE,
10461 BGP_STATS_ASPATH_COUNT,
10462 BGP_STATS_ASPATH_MAXHOPS,
10463 BGP_STATS_ASPATH_TOTHOPS,
10464 BGP_STATS_ASPATH_MAXSIZE,
10465 BGP_STATS_ASPATH_TOTSIZE,
10466 BGP_STATS_ASN_HIGHEST,
10467 BGP_STATS_MAX,
10468};
10469
10470static const char *table_stats_strs[] =
10471{
10472 [BGP_STATS_PREFIXES] = "Total Prefixes",
10473 [BGP_STATS_TOTPLEN] = "Average prefix length",
10474 [BGP_STATS_RIB] = "Total Advertisements",
10475 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
10476 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
10477 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
10478 [BGP_STATS_SPACE] = "Address space advertised",
10479 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
10480 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
10481 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
10482 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
10483 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
10484 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
10485 [BGP_STATS_MAX] = NULL,
10486};
10487
10488struct bgp_table_stats
10489{
10490 struct bgp_table *table;
10491 unsigned long long counts[BGP_STATS_MAX];
10492};
10493
10494#if 0
10495#define TALLY_SIGFIG 100000
10496static unsigned long
10497ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
10498{
10499 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
10500 unsigned long res = (newtot * TALLY_SIGFIG) / count;
10501 unsigned long ret = newtot / count;
10502
10503 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
10504 return ret + 1;
10505 else
10506 return ret;
10507}
10508#endif
10509
10510static int
10511bgp_table_stats_walker (struct thread *t)
10512{
10513 struct bgp_node *rn;
10514 struct bgp_node *top;
10515 struct bgp_table_stats *ts = THREAD_ARG (t);
10516 unsigned int space = 0;
10517
53d9f67a
PJ
10518 if (!(top = bgp_table_top (ts->table)))
10519 return 0;
2815e61f
PJ
10520
10521 switch (top->p.family)
10522 {
10523 case AF_INET:
10524 space = IPV4_MAX_BITLEN;
10525 break;
10526 case AF_INET6:
10527 space = IPV6_MAX_BITLEN;
10528 break;
10529 }
10530
10531 ts->counts[BGP_STATS_MAXBITLEN] = space;
10532
10533 for (rn = top; rn; rn = bgp_route_next (rn))
10534 {
10535 struct bgp_info *ri;
67174041 10536 struct bgp_node *prn = bgp_node_parent_nolock (rn);
2815e61f
PJ
10537 unsigned int rinum = 0;
10538
10539 if (rn == top)
10540 continue;
10541
10542 if (!rn->info)
10543 continue;
10544
10545 ts->counts[BGP_STATS_PREFIXES]++;
10546 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
10547
10548#if 0
10549 ts->counts[BGP_STATS_AVGPLEN]
10550 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
10551 ts->counts[BGP_STATS_AVGPLEN],
10552 rn->p.prefixlen);
10553#endif
10554
10555 /* check if the prefix is included by any other announcements */
10556 while (prn && !prn->info)
67174041 10557 prn = bgp_node_parent_nolock (prn);
2815e61f
PJ
10558
10559 if (prn == NULL || prn == top)
8383a9bd
PJ
10560 {
10561 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
10562 /* announced address space */
10563 if (space)
10564 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
10565 }
2815e61f
PJ
10566 else if (prn->info)
10567 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
10568
2815e61f
PJ
10569 for (ri = rn->info; ri; ri = ri->next)
10570 {
10571 rinum++;
10572 ts->counts[BGP_STATS_RIB]++;
10573
10574 if (ri->attr &&
10575 (CHECK_FLAG (ri->attr->flag,
10576 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
10577 ts->counts[BGP_STATS_AGGREGATES]++;
10578
10579 /* as-path stats */
10580 if (ri->attr && ri->attr->aspath)
10581 {
10582 unsigned int hops = aspath_count_hops (ri->attr->aspath);
10583 unsigned int size = aspath_size (ri->attr->aspath);
10584 as_t highest = aspath_highest (ri->attr->aspath);
10585
10586 ts->counts[BGP_STATS_ASPATH_COUNT]++;
10587
10588 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
10589 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
10590
10591 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
10592 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
10593
10594 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
10595 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
10596#if 0
10597 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
10598 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
10599 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
10600 hops);
10601 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
10602 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
10603 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
10604 size);
10605#endif
10606 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
10607 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
10608 }
10609 }
10610 }
10611 return 0;
10612}
10613
10614static int
10615bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
10616{
10617 struct bgp_table_stats ts;
10618 unsigned int i;
10619
10620 if (!bgp->rib[afi][safi])
10621 {
10622 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
10623 return CMD_WARNING;
10624 }
10625
10626 memset (&ts, 0, sizeof (ts));
10627 ts.table = bgp->rib[afi][safi];
10628 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
bb46e94f 10629
2815e61f
PJ
10630 vty_out (vty, "BGP %s RIB statistics%s%s",
10631 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
10632
10633 for (i = 0; i < BGP_STATS_MAX; i++)
10634 {
10635 if (!table_stats_strs[i])
10636 continue;
10637
10638 switch (i)
10639 {
10640#if 0
10641 case BGP_STATS_ASPATH_AVGHOPS:
10642 case BGP_STATS_ASPATH_AVGSIZE:
10643 case BGP_STATS_AVGPLEN:
10644 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10645 vty_out (vty, "%12.2f",
10646 (float)ts.counts[i] / (float)TALLY_SIGFIG);
10647 break;
10648#endif
10649 case BGP_STATS_ASPATH_TOTHOPS:
10650 case BGP_STATS_ASPATH_TOTSIZE:
10651 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10652 vty_out (vty, "%12.2f",
10653 ts.counts[i] ?
10654 (float)ts.counts[i] /
10655 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
10656 : 0);
10657 break;
10658 case BGP_STATS_TOTPLEN:
10659 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10660 vty_out (vty, "%12.2f",
10661 ts.counts[i] ?
10662 (float)ts.counts[i] /
10663 (float)ts.counts[BGP_STATS_PREFIXES]
10664 : 0);
10665 break;
10666 case BGP_STATS_SPACE:
10667 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10668 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
10669 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
10670 break;
30a2231a 10671 vty_out (vty, "%30s: ", "%% announced ");
2815e61f
PJ
10672 vty_out (vty, "%12.2f%s",
10673 100 * (float)ts.counts[BGP_STATS_SPACE] /
56395af7 10674 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
2815e61f
PJ
10675 VTY_NEWLINE);
10676 vty_out (vty, "%30s: ", "/8 equivalent ");
10677 vty_out (vty, "%12.2f%s",
10678 (float)ts.counts[BGP_STATS_SPACE] /
10679 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
10680 VTY_NEWLINE);
10681 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
10682 break;
10683 vty_out (vty, "%30s: ", "/24 equivalent ");
10684 vty_out (vty, "%12.2f",
10685 (float)ts.counts[BGP_STATS_SPACE] /
10686 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
10687 break;
10688 default:
10689 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10690 vty_out (vty, "%12llu", ts.counts[i]);
10691 }
10692
10693 vty_out (vty, "%s", VTY_NEWLINE);
10694 }
10695 return CMD_SUCCESS;
10696}
10697
10698static int
10699bgp_table_stats_vty (struct vty *vty, const char *name,
10700 const char *afi_str, const char *safi_str)
10701{
10702 struct bgp *bgp;
10703 afi_t afi;
10704 safi_t safi;
10705
10706 if (name)
10707 bgp = bgp_lookup_by_name (name);
10708 else
10709 bgp = bgp_get_default ();
10710
10711 if (!bgp)
10712 {
10713 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
10714 return CMD_WARNING;
10715 }
10716 if (strncmp (afi_str, "ipv", 3) == 0)
10717 {
10718 if (strncmp (afi_str, "ipv4", 4) == 0)
10719 afi = AFI_IP;
10720 else if (strncmp (afi_str, "ipv6", 4) == 0)
10721 afi = AFI_IP6;
10722 else
10723 {
10724 vty_out (vty, "%% Invalid address family %s%s",
10725 afi_str, VTY_NEWLINE);
10726 return CMD_WARNING;
10727 }
10728 if (strncmp (safi_str, "m", 1) == 0)
10729 safi = SAFI_MULTICAST;
10730 else if (strncmp (safi_str, "u", 1) == 0)
10731 safi = SAFI_UNICAST;
42e6d745
DO
10732 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
10733 safi = SAFI_MPLS_LABELED_VPN;
2815e61f
PJ
10734 else
10735 {
10736 vty_out (vty, "%% Invalid subsequent address family %s%s",
10737 safi_str, VTY_NEWLINE);
10738 return CMD_WARNING;
10739 }
10740 }
10741 else
10742 {
10743 vty_out (vty, "%% Invalid address family %s%s",
10744 afi_str, VTY_NEWLINE);
10745 return CMD_WARNING;
10746 }
10747
2815e61f
PJ
10748 return bgp_table_stats (vty, bgp, afi, safi);
10749}
10750
10751DEFUN (show_bgp_statistics,
10752 show_bgp_statistics_cmd,
10753 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
10754 SHOW_STR
10755 BGP_STR
10756 "Address family\n"
10757 "Address family\n"
10758 "Address Family modifier\n"
10759 "Address Family modifier\n"
10760 "BGP RIB advertisement statistics\n")
10761{
10762 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
10763}
10764
10765ALIAS (show_bgp_statistics,
10766 show_bgp_statistics_vpnv4_cmd,
10767 "show bgp (ipv4) (vpnv4) statistics",
10768 SHOW_STR
10769 BGP_STR
10770 "Address family\n"
10771 "Address Family modifier\n"
10772 "BGP RIB advertisement statistics\n")
10773
10774DEFUN (show_bgp_statistics_view,
10775 show_bgp_statistics_view_cmd,
10776 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
10777 SHOW_STR
10778 BGP_STR
10779 "BGP view\n"
10780 "Address family\n"
10781 "Address family\n"
10782 "Address Family modifier\n"
10783 "Address Family modifier\n"
10784 "BGP RIB advertisement statistics\n")
10785{
10786 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
10787}
10788
10789ALIAS (show_bgp_statistics_view,
10790 show_bgp_statistics_view_vpnv4_cmd,
10791 "show bgp view WORD (ipv4) (vpnv4) statistics",
10792 SHOW_STR
10793 BGP_STR
10794 "BGP view\n"
10795 "Address family\n"
10796 "Address Family modifier\n"
10797 "BGP RIB advertisement statistics\n")
6b0655a2 10798
ff7924f6
PJ
10799enum bgp_pcounts
10800{
10801 PCOUNT_ADJ_IN = 0,
10802 PCOUNT_DAMPED,
10803 PCOUNT_REMOVED,
10804 PCOUNT_HISTORY,
10805 PCOUNT_STALE,
10806 PCOUNT_VALID,
10807 PCOUNT_ALL,
10808 PCOUNT_COUNTED,
10809 PCOUNT_PFCNT, /* the figure we display to users */
10810 PCOUNT_MAX,
10811};
10812
10813static const char *pcount_strs[] =
10814{
10815 [PCOUNT_ADJ_IN] = "Adj-in",
10816 [PCOUNT_DAMPED] = "Damped",
10817 [PCOUNT_REMOVED] = "Removed",
10818 [PCOUNT_HISTORY] = "History",
10819 [PCOUNT_STALE] = "Stale",
10820 [PCOUNT_VALID] = "Valid",
10821 [PCOUNT_ALL] = "All RIB",
10822 [PCOUNT_COUNTED] = "PfxCt counted",
10823 [PCOUNT_PFCNT] = "Useable",
10824 [PCOUNT_MAX] = NULL,
10825};
10826
2815e61f
PJ
10827struct peer_pcounts
10828{
10829 unsigned int count[PCOUNT_MAX];
10830 const struct peer *peer;
10831 const struct bgp_table *table;
10832};
10833
ff7924f6 10834static int
2815e61f 10835bgp_peer_count_walker (struct thread *t)
ff7924f6
PJ
10836{
10837 struct bgp_node *rn;
2815e61f
PJ
10838 struct peer_pcounts *pc = THREAD_ARG (t);
10839 const struct peer *peer = pc->peer;
ff7924f6 10840
2815e61f 10841 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
ff7924f6
PJ
10842 {
10843 struct bgp_adj_in *ain;
2815e61f 10844 struct bgp_info *ri;
ff7924f6
PJ
10845
10846 for (ain = rn->adj_in; ain; ain = ain->next)
10847 if (ain->peer == peer)
2815e61f 10848 pc->count[PCOUNT_ADJ_IN]++;
ff7924f6 10849
ff7924f6
PJ
10850 for (ri = rn->info; ri; ri = ri->next)
10851 {
10852 char buf[SU_ADDRSTRLEN];
10853
10854 if (ri->peer != peer)
10855 continue;
10856
2815e61f 10857 pc->count[PCOUNT_ALL]++;
ff7924f6
PJ
10858
10859 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
2815e61f 10860 pc->count[PCOUNT_DAMPED]++;
ff7924f6 10861 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2815e61f 10862 pc->count[PCOUNT_HISTORY]++;
ff7924f6 10863 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
2815e61f 10864 pc->count[PCOUNT_REMOVED]++;
ff7924f6 10865 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2815e61f 10866 pc->count[PCOUNT_STALE]++;
ff7924f6 10867 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
2815e61f 10868 pc->count[PCOUNT_VALID]++;
1a392d46 10869 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2815e61f 10870 pc->count[PCOUNT_PFCNT]++;
ff7924f6
PJ
10871
10872 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
10873 {
2815e61f 10874 pc->count[PCOUNT_COUNTED]++;
1a392d46 10875 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 10876 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
ff7924f6
PJ
10877 peer->host,
10878 inet_ntop(rn->p.family, &rn->p.u.prefix,
10879 buf, SU_ADDRSTRLEN),
10880 rn->p.prefixlen,
10881 ri->flags);
10882 }
10883 else
10884 {
1a392d46 10885 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
16286195 10886 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
ff7924f6
PJ
10887 peer->host,
10888 inet_ntop(rn->p.family, &rn->p.u.prefix,
10889 buf, SU_ADDRSTRLEN),
10890 rn->p.prefixlen,
10891 ri->flags);
10892 }
10893 }
10894 }
2815e61f
PJ
10895 return 0;
10896}
ff7924f6 10897
2815e61f
PJ
10898static int
10899bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
10900{
10901 struct peer_pcounts pcounts = { .peer = peer };
10902 unsigned int i;
10903
10904 if (!peer || !peer->bgp || !peer->afc[afi][safi]
10905 || !peer->bgp->rib[afi][safi])
10906 {
10907 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10908 return CMD_WARNING;
10909 }
10910
10911 memset (&pcounts, 0, sizeof(pcounts));
10912 pcounts.peer = peer;
10913 pcounts.table = peer->bgp->rib[afi][safi];
10914
10915 /* in-place call via thread subsystem so as to record execution time
10916 * stats for the thread-walk (i.e. ensure this can't be blamed on
10917 * on just vty_read()).
10918 */
10919 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
10920
ff7924f6
PJ
10921 vty_out (vty, "Prefix counts for %s, %s%s",
10922 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
10923 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
10924 vty_out (vty, "%sCounts from RIB table walk:%s%s",
10925 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
10926
10927 for (i = 0; i < PCOUNT_MAX; i++)
2815e61f
PJ
10928 vty_out (vty, "%20s: %-10d%s",
10929 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
ff7924f6 10930
2815e61f 10931 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
ff7924f6
PJ
10932 {
10933 vty_out (vty, "%s [pcount] PfxCt drift!%s",
10934 peer->host, VTY_NEWLINE);
10935 vty_out (vty, "Please report this bug, with the above command output%s",
10936 VTY_NEWLINE);
10937 }
10938
10939 return CMD_SUCCESS;
10940}
10941
10942DEFUN (show_ip_bgp_neighbor_prefix_counts,
10943 show_ip_bgp_neighbor_prefix_counts_cmd,
a80beece 10944 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
ff7924f6
PJ
10945 SHOW_STR
10946 IP_STR
10947 BGP_STR
10948 "Detailed information on TCP and BGP neighbor connections\n"
10949 "Neighbor to display information about\n"
10950 "Neighbor to display information about\n"
a80beece 10951 "Neighbor on bgp configured interface\n"
ff7924f6
PJ
10952 "Display detailed prefix count information\n")
10953{
10954 struct peer *peer;
10955
10956 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10957 if (! peer)
10958 return CMD_WARNING;
10959
10960 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
10961}
10962
10963DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
10964 show_bgp_ipv6_neighbor_prefix_counts_cmd,
a80beece 10965 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
ff7924f6
PJ
10966 SHOW_STR
10967 BGP_STR
10968 "Address family\n"
10969 "Detailed information on TCP and BGP neighbor connections\n"
10970 "Neighbor to display information about\n"
10971 "Neighbor to display information about\n"
a80beece 10972 "Neighbor on bgp configured interface\n"
ff7924f6
PJ
10973 "Display detailed prefix count information\n")
10974{
10975 struct peer *peer;
10976
10977 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10978 if (! peer)
10979 return CMD_WARNING;
10980
10981 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
10982}
10983
10984DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
10985 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
a80beece 10986 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
ff7924f6
PJ
10987 SHOW_STR
10988 IP_STR
10989 BGP_STR
10990 "Address family\n"
10991 "Address Family modifier\n"
10992 "Address Family modifier\n"
10993 "Detailed information on TCP and BGP neighbor connections\n"
10994 "Neighbor to display information about\n"
10995 "Neighbor to display information about\n"
a80beece 10996 "Neighbor on bgp configured interface\n"
ff7924f6
PJ
10997 "Display detailed prefix count information\n")
10998{
10999 struct peer *peer;
11000
11001 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11002 if (! peer)
11003 return CMD_WARNING;
11004
11005 if (strncmp (argv[0], "m", 1) == 0)
11006 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
11007
11008 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
11009}
11010
11011DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
11012 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
a80beece 11013 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
ff7924f6
PJ
11014 SHOW_STR
11015 IP_STR
11016 BGP_STR
11017 "Address family\n"
11018 "Address Family modifier\n"
11019 "Address Family modifier\n"
11020 "Detailed information on TCP and BGP neighbor connections\n"
11021 "Neighbor to display information about\n"
11022 "Neighbor to display information about\n"
a80beece 11023 "Neighbor on bgp configured interface\n"
ff7924f6
PJ
11024 "Display detailed prefix count information\n")
11025{
11026 struct peer *peer;
11027
11028 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11029 if (! peer)
11030 return CMD_WARNING;
11031
11032 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
11033}
11034
94f2b392 11035static void
718e3744 11036show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
0b16f239 11037 int in, char *delim, char *rmap_name)
718e3744 11038{
11039 struct bgp_table *table;
11040 struct bgp_adj_in *ain;
11041 struct bgp_adj_out *adj;
11042 unsigned long output_count;
0b16f239 11043 unsigned long filtered_count;
718e3744 11044 struct bgp_node *rn;
11045 int header1 = 1;
11046 struct bgp *bgp;
11047 int header2 = 1;
0b16f239
DS
11048 struct attr attr;
11049 struct attr_extra extra;
11050 int ret;
718e3744 11051
bb46e94f 11052 bgp = peer->bgp;
718e3744 11053
11054 if (! bgp)
11055 return;
11056
47fc97cc
DS
11057 if (delim)
11058 header1 = 0;
11059
718e3744 11060 table = bgp->rib[afi][safi];
11061
0b16f239 11062 output_count = filtered_count = 0;
47fc97cc 11063
718e3744 11064 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
11065 PEER_STATUS_DEFAULT_ORIGINATE))
11066 {
3f9c7369 11067 vty_out (vty, "BGP table version is %llu, local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
93406d87 11068 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11069 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 11070
11071 vty_out (vty, "Originating default network 0.0.0.0%s%s",
11072 VTY_NEWLINE, VTY_NEWLINE);
11073 header1 = 0;
11074 }
11075
0b16f239 11076 attr.extra = &extra;
718e3744 11077 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11078 if (in)
11079 {
11080 for (ain = rn->adj_in; ain; ain = ain->next)
11081 if (ain->peer == peer)
11082 {
11083 if (header1)
11084 {
11085 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
93406d87 11086 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11087 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 11088 header1 = 0;
11089 }
11090 if (header2)
11091 {
47fc97cc
DS
11092 if (delim)
11093 vty_out (vty, BGP_SHOW_HEADER_CSV, VTY_NEWLINE);
11094 else
11095 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
718e3744 11096 header2 = 0;
11097 }
11098 if (ain->attr)
47fc97cc 11099 {
0b16f239
DS
11100 bgp_attr_dup(&attr, ain->attr);
11101 if (bgp_input_modifier(peer, &rn->p, &attr, afi,
11102 safi, rmap_name) != RMAP_DENY)
11103 {
11104 route_vty_out_tmp (vty, &rn->p, &attr, safi, delim);
11105 output_count++;
11106 }
11107 else
11108 filtered_count++;
718e3744 11109 }
11110 }
11111 }
11112 else
11113 {
3f9c7369
DS
11114 adj = bgp_adj_peer_lookup(peer, rn);
11115 if (adj)
11116 {
11117 if (header1)
11118 {
11119 vty_out (vty, "BGP table version is %llu, local router ID "
11120 "is %s%s", table->version,
11121 inet_ntoa (bgp->router_id), VTY_NEWLINE);
11122 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11123 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11124 header1 = 0;
11125 }
11126 if (header2)
11127 {
11128 if (delim)
11129 vty_out (vty, BGP_SHOW_HEADER_CSV, VTY_NEWLINE);
11130 else
11131 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
11132 header2 = 0;
11133 }
11134 if (adj->attr)
11135 {
11136 if (!CHECK_FLAG(peer->af_flags[afi][safi],
11137 PEER_FLAG_REFLECTOR_CLIENT)
11138 || bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
11139 {
11140 bgp_attr_dup(&attr, adj->attr);
11141 ret = bgp_output_modifier(peer, &rn->p, &attr, afi,
11142 safi, rmap_name);
11143 }
11144 else
11145 ret = RMAP_PERMIT;
0b16f239 11146
3f9c7369
DS
11147 if (ret != RMAP_DENY)
11148 {
11149 route_vty_out_tmp (vty, &rn->p, &attr, safi, delim);
11150 output_count++;
11151 }
11152 else
11153 filtered_count++;
11154 }
11155 }
718e3744 11156 }
47fc97cc 11157
718e3744 11158 if (output_count != 0)
11159 vty_out (vty, "%sTotal number of prefixes %ld%s",
11160 VTY_NEWLINE, output_count, VTY_NEWLINE);
11161}
11162
94f2b392 11163static int
47fc97cc 11164peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
0b16f239 11165 int in, char *delim, char *rmap_name)
bb46e94f 11166{
718e3744 11167 if (! peer || ! peer->afc[afi][safi])
11168 {
11169 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11170 return CMD_WARNING;
11171 }
11172
11173 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11174 {
11175 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
11176 VTY_NEWLINE);
11177 return CMD_WARNING;
11178 }
11179
0b16f239
DS
11180 if (!in && (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)
11181 && !bgp_flag_check(peer->bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)))
11182 {
11183 vty_out (vty, "%% Cannot apply outgoing route-map on route-reflector clients%s",
11184 VTY_NEWLINE);
11185 vty_out (vty, "%% Enable bgp route-reflector allow-outbound-policy flag%s",
11186 VTY_NEWLINE);
11187 return CMD_WARNING;
11188 }
11189
11190 show_adj_route (vty, peer, afi, safi, in, delim, rmap_name);
718e3744 11191
11192 return CMD_SUCCESS;
11193}
11194
2a71e9ce
TP
11195DEFUN (show_ip_bgp_view_neighbor_advertised_route,
11196 show_ip_bgp_view_neighbor_advertised_route_cmd,
a80beece 11197 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 11198 SHOW_STR
11199 IP_STR
11200 BGP_STR
2a71e9ce
TP
11201 "BGP view\n"
11202 "View name\n"
718e3744 11203 "Detailed information on TCP and BGP neighbor connections\n"
11204 "Neighbor to display information about\n"
11205 "Neighbor to display information about\n"
11206 "Display the routes advertised to a BGP neighbor\n")
11207{
bb46e94f 11208 struct peer *peer;
11209
2a71e9ce
TP
11210 if (argc == 2)
11211 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11212 else
11213 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11214
bb46e94f 11215 if (! peer)
11216 return CMD_WARNING;
0b16f239
DS
11217
11218 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, NULL);
718e3744 11219}
11220
0b16f239 11221DEFUN (show_ip_bgp_neighbor_advertised_route,
2a71e9ce 11222 show_ip_bgp_neighbor_advertised_route_cmd,
a80beece 11223 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
2a71e9ce
TP
11224 SHOW_STR
11225 IP_STR
11226 BGP_STR
11227 "Detailed information on TCP and BGP neighbor connections\n"
11228 "Neighbor to display information about\n"
11229 "Neighbor to display information about\n"
a80beece 11230 "Neighbor on bgp configured interface\n"
2a71e9ce
TP
11231 "Display the routes advertised to a BGP neighbor\n")
11232
0b16f239
DS
11233{
11234 struct peer *peer;
11235 char *rmap_name = NULL;
11236
11237 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11238
11239 if (! peer)
11240 return CMD_WARNING;
11241
11242 if (argc == 2)
11243 rmap_name = argv[1];
11244
11245 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, rmap_name);
11246}
11247
11248ALIAS (show_ip_bgp_neighbor_advertised_route,
11249 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
11250 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
11251 SHOW_STR
11252 IP_STR
11253 BGP_STR
11254 "Detailed information on TCP and BGP neighbor connections\n"
11255 "Neighbor to display information about\n"
11256 "Neighbor to display information about\n"
11257 "Neighbor on bgp configured interface\n"
11258 "Display the routes advertised to a BGP neighbor\n")
11259
47fc97cc
DS
11260DEFUN (show_ip_bgp_neighbor_advertised_route_csv,
11261 show_ip_bgp_neighbor_advertised_route_csv_cmd,
a80beece 11262 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv",
47fc97cc
DS
11263 SHOW_STR
11264 IP_STR
11265 BGP_STR
11266 "BGP view\n"
11267 "View name\n"
11268 "Detailed information on TCP and BGP neighbor connections\n"
11269 "Neighbor to display information about\n"
11270 "Neighbor to display information about\n"
a80beece 11271 "Neighbor on bgp configured interface\n"
47fc97cc
DS
11272 "Display the routes advertised to a BGP neighbor\n")
11273{
11274 struct peer *peer;
0b16f239 11275 char *rmap_name = NULL;
47fc97cc 11276
0b16f239 11277 peer = peer_lookup_in_view (vty, NULL, argv[0]);
47fc97cc
DS
11278
11279 if (! peer)
11280 return CMD_WARNING;
11281
0b16f239
DS
11282 if (argc == 2)
11283 rmap_name = argv[1];
11284
11285 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, &csv, rmap_name);
47fc97cc
DS
11286}
11287
0b16f239
DS
11288ALIAS (show_ip_bgp_neighbor_advertised_route_csv,
11289 show_ip_bgp_neighbor_advertised_route_csv_rmap_cmd,
11290 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv route-map WORD",
11291 SHOW_STR
11292 IP_STR
11293 BGP_STR
11294 "BGP view\n"
11295 "View name\n"
11296 "Detailed information on TCP and BGP neighbor connections\n"
11297 "Neighbor to display information about\n"
11298 "Neighbor to display information about\n"
11299 "Neighbor on bgp configured interface\n"
11300 "Display the routes advertised to a BGP neighbor\n"
11301 "Apply this route-map to display what would've been advertised\n")
11302
718e3744 11303DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
11304 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
a80beece 11305 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 11306 SHOW_STR
11307 IP_STR
11308 BGP_STR
11309 "Address family\n"
11310 "Address Family modifier\n"
11311 "Address Family modifier\n"
11312 "Detailed information on TCP and BGP neighbor connections\n"
11313 "Neighbor to display information about\n"
11314 "Neighbor to display information about\n"
a80beece 11315 "Neighbor on bgp configured interface\n"
718e3744 11316 "Display the routes advertised to a BGP neighbor\n")
11317{
bb46e94f 11318 struct peer *peer;
0b16f239 11319 char *rmap_name = NULL;
bb46e94f 11320
11321 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11322 if (! peer)
11323 return CMD_WARNING;
11324
0b16f239
DS
11325 if (argc == 3)
11326 rmap_name = argv[2];
11327
718e3744 11328 if (strncmp (argv[0], "m", 1) == 0)
0b16f239 11329 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, NULL, rmap_name);
718e3744 11330
0b16f239 11331 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, rmap_name);
718e3744 11332}
11333
0b16f239
DS
11334ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
11335 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
11336 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
11337 SHOW_STR
11338 IP_STR
11339 BGP_STR
11340 "Address family\n"
11341 "Address Family modifier\n"
11342 "Address Family modifier\n"
11343 "Detailed information on TCP and BGP neighbor connections\n"
11344 "Neighbor to display information about\n"
11345 "Neighbor to display information about\n"
11346 "Neighbor on bgp configured interface\n"
11347 "Display the routes advertised to a BGP neighbor\n"
11348 "Route-map to control what is displayed\n")
11349
718e3744 11350#ifdef HAVE_IPV6
bb46e94f 11351DEFUN (show_bgp_view_neighbor_advertised_route,
11352 show_bgp_view_neighbor_advertised_route_cmd,
a80beece 11353 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 11354 SHOW_STR
11355 BGP_STR
bb46e94f 11356 "BGP view\n"
11357 "View name\n"
718e3744 11358 "Detailed information on TCP and BGP neighbor connections\n"
11359 "Neighbor to display information about\n"
11360 "Neighbor to display information about\n"
a80beece 11361 "Neighbor on bgp configured interface\n"
718e3744 11362 "Display the routes advertised to a BGP neighbor\n")
11363{
bb46e94f 11364 struct peer *peer;
11365
11366 if (argc == 2)
11367 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11368 else
11369 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11370
11371 if (! peer)
0b16f239 11372 return CMD_WARNING;
bb46e94f 11373
0b16f239 11374 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, NULL);
47fc97cc
DS
11375}
11376
0b16f239
DS
11377ALIAS (show_bgp_view_neighbor_advertised_route,
11378 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
11379 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
11380 SHOW_STR
11381 BGP_STR
11382 "BGP view\n"
11383 "View name\n"
11384 "Address family\n"
11385 "Detailed information on TCP and BGP neighbor connections\n"
11386 "Neighbor to display information about\n"
11387 "Neighbor to display information about\n"
11388 "Neighbor on bgp configured interface\n"
11389 "Display the routes advertised to a BGP neighbor\n")
11390
47fc97cc
DS
11391DEFUN (show_bgp_view_neighbor_advertised_route_csv,
11392 show_bgp_view_neighbor_advertised_route_csv_cmd,
a80beece 11393 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv",
47fc97cc
DS
11394 SHOW_STR
11395 BGP_STR
11396 "BGP view\n"
11397 "View name\n"
11398 "Detailed information on TCP and BGP neighbor connections\n"
11399 "Neighbor to display information about\n"
11400 "Neighbor to display information about\n"
a80beece 11401 "Neighbor on bgp configured interface\n"
47fc97cc
DS
11402 "Display the routes advertised to a BGP neighbor\n")
11403{
11404 struct peer *peer;
11405
11406 if (argc == 2)
11407 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11408 else
11409 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11410
11411 if (! peer)
11412 return CMD_WARNING;
11413
0b16f239 11414 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, &csv, NULL);
bb46e94f 11415}
11416
47fc97cc
DS
11417ALIAS (show_bgp_view_neighbor_advertised_route_csv,
11418 show_bgp_view_ipv6_neighbor_advertised_route_csv_cmd,
a80beece 11419 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv",
47fc97cc
DS
11420 SHOW_STR
11421 BGP_STR
11422 "BGP view\n"
11423 "View name\n"
11424 "Address family\n"
11425 "Detailed information on TCP and BGP neighbor connections\n"
11426 "Neighbor to display information about\n"
11427 "Neighbor to display information about\n"
a80beece 11428 "Neighbor on bgp configured interface\n"
47fc97cc
DS
11429 "Display the routes advertised to a BGP neighbor\n")
11430
0b16f239
DS
11431DEFUN (show_bgp_neighbor_advertised_route,
11432 show_bgp_neighbor_advertised_route_cmd,
11433 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
bb46e94f 11434 SHOW_STR
11435 BGP_STR
bb46e94f 11436 "Detailed information on TCP and BGP neighbor connections\n"
11437 "Neighbor to display information about\n"
11438 "Neighbor to display information about\n"
a80beece 11439 "Neighbor on bgp configured interface\n"
0b16f239
DS
11440 "Display the routes advertised to a BGP neighbor\n")
11441
bb46e94f 11442{
11443 struct peer *peer;
0b16f239 11444 char *rmap_name = NULL;
bb46e94f 11445
0b16f239 11446 peer = peer_lookup_in_view (vty, NULL, argv[0]);
bb46e94f 11447
11448 if (! peer)
11449 return CMD_WARNING;
11450
0b16f239
DS
11451 if (argc == 2)
11452 rmap_name = argv[1];
11453
11454 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, rmap_name);
718e3744 11455}
11456
0b16f239
DS
11457ALIAS (show_bgp_neighbor_advertised_route,
11458 show_bgp_neighbor_advertised_route_rmap_cmd,
11459 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
bb46e94f 11460 SHOW_STR
11461 BGP_STR
bb46e94f 11462 "Detailed information on TCP and BGP neighbor connections\n"
11463 "Neighbor to display information about\n"
11464 "Neighbor to display information about\n"
a80beece 11465 "Neighbor on bgp configured interface\n"
0b16f239 11466 "Display the routes advertised to a BGP neighbor\n")
bb46e94f 11467
0b16f239
DS
11468ALIAS (show_bgp_neighbor_advertised_route,
11469 show_bgp_ipv6_neighbor_advertised_route_cmd,
11470 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
bb46e94f 11471 SHOW_STR
11472 BGP_STR
0b16f239 11473 "Address family\n"
bb46e94f 11474 "Detailed information on TCP and BGP neighbor connections\n"
11475 "Neighbor to display information about\n"
11476 "Neighbor to display information about\n"
a80beece 11477 "Neighbor on bgp configured interface\n"
bb46e94f 11478 "Display the routes advertised to a BGP neighbor\n")
0b16f239
DS
11479
11480ALIAS (show_bgp_neighbor_advertised_route,
11481 show_bgp_ipv6_neighbor_advertised_route_rmap_cmd,
11482 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
718e3744 11483 SHOW_STR
11484 BGP_STR
11485 "Address family\n"
11486 "Detailed information on TCP and BGP neighbor connections\n"
11487 "Neighbor to display information about\n"
11488 "Neighbor to display information about\n"
a80beece 11489 "Neighbor on bgp configured interface\n"
718e3744 11490 "Display the routes advertised to a BGP neighbor\n")
11491
0b16f239 11492DEFUN (show_bgp_neighbor_advertised_route_csv,
47fc97cc 11493 show_bgp_neighbor_advertised_route_csv_cmd,
a80beece 11494 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv",
47fc97cc
DS
11495 SHOW_STR
11496 BGP_STR
11497 "Detailed information on TCP and BGP neighbor connections\n"
11498 "Neighbor to display information about\n"
11499 "Neighbor to display information about\n"
a80beece 11500 "Neighbor on bgp configured interface\n"
47fc97cc 11501 "Display the routes advertised to a BGP neighbor\n")
0b16f239
DS
11502{
11503 struct peer *peer;
11504 char *rmap_name = NULL;
47fc97cc 11505
0b16f239
DS
11506 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11507
11508 if (! peer)
11509 return CMD_WARNING;
11510
11511 if (argc == 2)
11512 rmap_name = argv[1];
11513
11514 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, &csv, rmap_name);
11515}
11516
11517ALIAS (show_bgp_neighbor_advertised_route_csv,
11518 show_bgp_neighbor_advertised_route_csv_rmap_cmd,
11519 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv route-map WORD",
11520 SHOW_STR
11521 BGP_STR
11522 "Detailed information on TCP and BGP neighbor connections\n"
11523 "Neighbor to display information about\n"
11524 "Neighbor to display information about\n"
11525 "Neighbor on bgp configured interface\n"
11526 "Display the routes advertised to a BGP neighbor\n")
11527
11528ALIAS (show_bgp_neighbor_advertised_route_csv,
47fc97cc 11529 show_bgp_ipv6_neighbor_advertised_route_csv_cmd,
a80beece 11530 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv",
47fc97cc
DS
11531 SHOW_STR
11532 BGP_STR
11533 "Address family\n"
11534 "Detailed information on TCP and BGP neighbor connections\n"
11535 "Neighbor to display information about\n"
11536 "Neighbor to display information about\n"
a80beece 11537 "Neighbor on bgp configured interface\n"
47fc97cc
DS
11538 "Display the routes advertised to a BGP neighbor\n")
11539
0b16f239
DS
11540ALIAS (show_bgp_neighbor_advertised_route_csv,
11541 show_bgp_ipv6_neighbor_advertised_route_csv_rmap_cmd,
11542 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv route-map WORD",
11543 SHOW_STR
11544 BGP_STR
11545 "Address family\n"
11546 "Detailed information on TCP and BGP neighbor connections\n"
11547 "Neighbor to display information about\n"
11548 "Neighbor to display information about\n"
11549 "Neighbor on bgp configured interface\n"
11550 "Display the routes advertised to a BGP neighbor\n")
11551
718e3744 11552/* old command */
0b16f239 11553ALIAS (show_bgp_neighbor_advertised_route,
718e3744 11554 ipv6_bgp_neighbor_advertised_route_cmd,
a80beece 11555 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 11556 SHOW_STR
11557 IPV6_STR
11558 BGP_STR
11559 "Detailed information on TCP and BGP neighbor connections\n"
11560 "Neighbor to display information about\n"
11561 "Neighbor to display information about\n"
a80beece 11562 "Neighbor on bgp configured interface\n"
718e3744 11563 "Display the routes advertised to a BGP neighbor\n")
bb46e94f 11564
718e3744 11565/* old command */
11566DEFUN (ipv6_mbgp_neighbor_advertised_route,
11567 ipv6_mbgp_neighbor_advertised_route_cmd,
a80beece 11568 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
718e3744 11569 SHOW_STR
11570 IPV6_STR
11571 MBGP_STR
11572 "Detailed information on TCP and BGP neighbor connections\n"
11573 "Neighbor to display information about\n"
11574 "Neighbor to display information about\n"
a80beece
DS
11575 "Neighbor on bgp configured interface\n"
11576 "Neighbor on bgp configured interface\n"
718e3744 11577 "Display the routes advertised to a BGP neighbor\n")
11578{
bb46e94f 11579 struct peer *peer;
11580
11581 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11582 if (! peer)
11583 return CMD_WARNING;
11584
0b16f239 11585 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, NULL);
718e3744 11586}
11587#endif /* HAVE_IPV6 */
6b0655a2 11588
0b16f239
DS
11589DEFUN (show_bgp_view_neighbor_received_routes,
11590 show_bgp_view_neighbor_received_routes_cmd,
11591 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11592 SHOW_STR
11593 BGP_STR
11594 "BGP view\n"
11595 "View name\n"
11596 "Detailed information on TCP and BGP neighbor connections\n"
11597 "Neighbor to display information about\n"
11598 "Neighbor to display information about\n"
11599 "Neighbor on bgp configured interface\n"
11600 "Display the received routes from neighbor\n")
11601{
11602 struct peer *peer;
11603
11604 if (argc == 2)
11605 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11606 else
11607 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11608
11609 if (! peer)
11610 return CMD_WARNING;
11611
11612 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, NULL);
11613}
11614
2a71e9ce
TP
11615DEFUN (show_ip_bgp_view_neighbor_received_routes,
11616 show_ip_bgp_view_neighbor_received_routes_cmd,
a80beece 11617 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 11618 SHOW_STR
11619 IP_STR
11620 BGP_STR
2a71e9ce
TP
11621 "BGP view\n"
11622 "View name\n"
718e3744 11623 "Detailed information on TCP and BGP neighbor connections\n"
11624 "Neighbor to display information about\n"
11625 "Neighbor to display information about\n"
a80beece 11626 "Neighbor on bgp configured interface\n"
718e3744 11627 "Display the received routes from neighbor\n")
11628{
bb46e94f 11629 struct peer *peer;
11630
2a71e9ce
TP
11631 if (argc == 2)
11632 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11633 else
11634 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11635
bb46e94f 11636 if (! peer)
11637 return CMD_WARNING;
11638
0b16f239 11639 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, NULL);
718e3744 11640}
11641
0b16f239
DS
11642ALIAS (show_bgp_view_neighbor_received_routes,
11643 show_bgp_view_ipv6_neighbor_received_routes_cmd,
11644 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11645 SHOW_STR
11646 BGP_STR
11647 "BGP view\n"
11648 "View name\n"
11649 "Address family\n"
11650 "Detailed information on TCP and BGP neighbor connections\n"
11651 "Neighbor to display information about\n"
11652 "Neighbor to display information about\n"
11653 "Neighbor on bgp configured interface\n"
11654 "Display the received routes from neighbor\n")
11655
11656DEFUN (show_ip_bgp_neighbor_received_routes,
2a71e9ce 11657 show_ip_bgp_neighbor_received_routes_cmd,
a80beece 11658 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
2a71e9ce
TP
11659 SHOW_STR
11660 IP_STR
11661 BGP_STR
11662 "Detailed information on TCP and BGP neighbor connections\n"
11663 "Neighbor to display information about\n"
11664 "Neighbor to display information about\n"
a80beece 11665 "Neighbor on bgp configured interface\n"
2a71e9ce
TP
11666 "Display the received routes from neighbor\n")
11667
0b16f239
DS
11668{
11669 struct peer *peer;
11670 char *rmap_name = NULL;
11671
11672 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11673
11674 if (! peer)
11675 return CMD_WARNING;
11676
11677 if (argc == 2)
11678 rmap_name = argv[1];
11679
11680 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, rmap_name);
11681}
11682
11683ALIAS (show_ip_bgp_neighbor_received_routes,
11684 show_ip_bgp_neighbor_received_routes_rmap_cmd,
11685 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
11686 SHOW_STR
11687 IP_STR
11688 BGP_STR
11689 "Detailed information on TCP and BGP neighbor connections\n"
11690 "Neighbor to display information about\n"
11691 "Neighbor to display information about\n"
11692 "Neighbor on bgp configured interface\n"
11693 "Display the received routes from neighbor\n")
11694
718e3744 11695DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
11696 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
a80beece 11697 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 11698 SHOW_STR
11699 IP_STR
11700 BGP_STR
11701 "Address family\n"
11702 "Address Family modifier\n"
11703 "Address Family modifier\n"
11704 "Detailed information on TCP and BGP neighbor connections\n"
11705 "Neighbor to display information about\n"
11706 "Neighbor to display information about\n"
a80beece 11707 "Neighbor on bgp configured interface\n"
718e3744 11708 "Display the received routes from neighbor\n")
11709{
bb46e94f 11710 struct peer *peer;
0b16f239 11711 char *rmap_name = NULL;
bb46e94f 11712
11713 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11714 if (! peer)
11715 return CMD_WARNING;
0b16f239
DS
11716
11717 if (argc == 3)
11718 rmap_name = argv[2];
11719
718e3744 11720 if (strncmp (argv[0], "m", 1) == 0)
0b16f239 11721 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, NULL, rmap_name);
718e3744 11722
0b16f239 11723 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, rmap_name);
718e3744 11724}
11725
0b16f239
DS
11726ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
11727 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
11728 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
11729 SHOW_STR
11730 IP_STR
11731 BGP_STR
11732 "Address family\n"
11733 "Address Family modifier\n"
11734 "Address Family modifier\n"
11735 "Detailed information on TCP and BGP neighbor connections\n"
11736 "Neighbor to display information about\n"
11737 "Neighbor to display information about\n"
11738 "Neighbor on bgp configured interface\n"
11739 "Display the received routes from neighbor\n")
11740
95cbbd2a
ML
11741DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
11742 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
11743#ifdef HAVE_IPV6
a80beece 11744 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes)",
95cbbd2a 11745#else
a80beece 11746 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes)",
95cbbd2a
ML
11747#endif
11748 SHOW_STR
11749 BGP_STR
11750 "BGP view\n"
2b00515a 11751 "View name\n"
95cbbd2a
ML
11752 "Address family\n"
11753#ifdef HAVE_IPV6
11754 "Address family\n"
11755#endif
11756 "Address family modifier\n"
11757 "Address family modifier\n"
11758 "Detailed information on TCP and BGP neighbor connections\n"
11759 "Neighbor to display information about\n"
11760 "Neighbor to display information about\n"
a80beece 11761 "Neighbor on bgp configured interface\n"
95cbbd2a
ML
11762 "Display the advertised routes to neighbor\n"
11763 "Display the received routes from neighbor\n")
11764{
11765 int afi;
11766 int safi;
11767 int in;
11768 struct peer *peer;
11769
11770#ifdef HAVE_IPV6
11771 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
11772#else
11773 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11774#endif
11775
11776 if (! peer)
11777 return CMD_WARNING;
11778
11779#ifdef HAVE_IPV6
11780 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
11781 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11782 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
11783#else
11784 afi = AFI_IP;
11785 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11786 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
11787#endif
11788
0b16f239 11789 return peer_adj_routes (vty, peer, afi, safi, in, NULL, NULL);
95cbbd2a
ML
11790}
11791
718e3744 11792DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
11793 show_ip_bgp_neighbor_received_prefix_filter_cmd,
a80beece 11794 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
718e3744 11795 SHOW_STR
11796 IP_STR
11797 BGP_STR
11798 "Detailed information on TCP and BGP neighbor connections\n"
11799 "Neighbor to display information about\n"
11800 "Neighbor to display information about\n"
a80beece 11801 "Neighbor on bgp configured interface\n"
718e3744 11802 "Display information received from a BGP neighbor\n"
11803 "Display the prefixlist filter\n")
11804{
11805 char name[BUFSIZ];
c63b83fe 11806 union sockunion su;
718e3744 11807 struct peer *peer;
c63b83fe 11808 int count, ret;
718e3744 11809
c63b83fe
JBD
11810 ret = str2sockunion (argv[0], &su);
11811 if (ret < 0)
11812 {
a80beece
DS
11813 peer = peer_lookup_by_conf_if (NULL, argv[0]);
11814 if (!peer)
11815 {
11816 vty_out (vty, "Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
11817 return CMD_WARNING;
11818 }
11819 }
11820 else
11821 {
11822 peer = peer_lookup (NULL, &su);
11823 if (! peer)
11824 return CMD_WARNING;
c63b83fe 11825 }
718e3744 11826
11827 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
11828 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
11829 if (count)
11830 {
11831 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
11832 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
11833 }
11834
11835 return CMD_SUCCESS;
11836}
11837
11838DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
11839 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
a80beece 11840 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
718e3744 11841 SHOW_STR
11842 IP_STR
11843 BGP_STR
11844 "Address family\n"
11845 "Address Family modifier\n"
11846 "Address Family modifier\n"
11847 "Detailed information on TCP and BGP neighbor connections\n"
11848 "Neighbor to display information about\n"
11849 "Neighbor to display information about\n"
a80beece 11850 "Neighbor on bgp configured interface\n"
718e3744 11851 "Display information received from a BGP neighbor\n"
11852 "Display the prefixlist filter\n")
11853{
11854 char name[BUFSIZ];
c63b83fe 11855 union sockunion su;
718e3744 11856 struct peer *peer;
c63b83fe 11857 int count, ret;
718e3744 11858
c63b83fe
JBD
11859 ret = str2sockunion (argv[1], &su);
11860 if (ret < 0)
11861 {
a80beece
DS
11862 peer = peer_lookup_by_conf_if (NULL, argv[1]);
11863 if (!peer)
11864 {
11865 vty_out (vty, "Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
11866 return CMD_WARNING;
11867 }
11868 }
11869 else
11870 {
11871 peer = peer_lookup (NULL, &su);
11872 if (! peer)
11873 return CMD_WARNING;
c63b83fe 11874 }
718e3744 11875
11876 if (strncmp (argv[0], "m", 1) == 0)
11877 {
11878 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
11879 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
11880 if (count)
11881 {
11882 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
11883 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
11884 }
11885 }
11886 else
11887 {
11888 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
11889 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
11890 if (count)
11891 {
11892 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
11893 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
11894 }
11895 }
11896
11897 return CMD_SUCCESS;
11898}
11899
11900
11901#ifdef HAVE_IPV6
bb46e94f 11902ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 11903 show_bgp_neighbor_received_routes_cmd,
a80beece 11904 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 11905 SHOW_STR
11906 BGP_STR
11907 "Detailed information on TCP and BGP neighbor connections\n"
11908 "Neighbor to display information about\n"
11909 "Neighbor to display information about\n"
a80beece 11910 "Neighbor on bgp configured interface\n"
718e3744 11911 "Display the received routes from neighbor\n")
718e3744 11912
bb46e94f 11913ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 11914 show_bgp_ipv6_neighbor_received_routes_cmd,
a80beece 11915 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 11916 SHOW_STR
11917 BGP_STR
11918 "Address family\n"
11919 "Detailed information on TCP and BGP neighbor connections\n"
11920 "Neighbor to display information about\n"
11921 "Neighbor to display information about\n"
a80beece 11922 "Neighbor on bgp configured interface\n"
718e3744 11923 "Display the received routes from neighbor\n")
11924
0b16f239
DS
11925ALIAS (show_bgp_view_neighbor_received_routes,
11926 show_bgp_neighbor_received_routes_rmap_cmd,
11927 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
11928 SHOW_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"
11933 "Neighbor on bgp configured interface\n"
11934 "Display the received routes from neighbor\n")
11935
11936ALIAS (show_bgp_view_neighbor_received_routes,
11937 show_bgp_ipv6_neighbor_received_routes_rmap_cmd,
11938 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
11939 SHOW_STR
11940 BGP_STR
11941 "Address family\n"
11942 "Detailed information on TCP and BGP neighbor connections\n"
11943 "Neighbor to display information about\n"
11944 "Neighbor to display information about\n"
11945 "Neighbor on bgp configured interface\n"
11946 "Display the received routes from neighbor\n")
11947
718e3744 11948DEFUN (show_bgp_neighbor_received_prefix_filter,
11949 show_bgp_neighbor_received_prefix_filter_cmd,
a80beece 11950 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
718e3744 11951 SHOW_STR
11952 BGP_STR
11953 "Detailed information on TCP and BGP neighbor connections\n"
11954 "Neighbor to display information about\n"
11955 "Neighbor to display information about\n"
a80beece 11956 "Neighbor on bgp configured interface\n"
718e3744 11957 "Display information received from a BGP neighbor\n"
11958 "Display the prefixlist filter\n")
11959{
11960 char name[BUFSIZ];
c63b83fe 11961 union sockunion su;
718e3744 11962 struct peer *peer;
c63b83fe 11963 int count, ret;
718e3744 11964
c63b83fe
JBD
11965 ret = str2sockunion (argv[0], &su);
11966 if (ret < 0)
11967 {
a80beece
DS
11968 peer = peer_lookup_by_conf_if (NULL, argv[0]);
11969 if (!peer)
11970 {
11971 vty_out (vty, "Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
11972 return CMD_WARNING;
11973 }
11974 }
11975 else
11976 {
11977 peer = peer_lookup (NULL, &su);
11978 if (! peer)
11979 return CMD_WARNING;
c63b83fe 11980 }
718e3744 11981
11982 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
11983 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
11984 if (count)
11985 {
11986 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
11987 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
11988 }
11989
11990 return CMD_SUCCESS;
11991}
11992
11993ALIAS (show_bgp_neighbor_received_prefix_filter,
11994 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
a80beece 11995 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
718e3744 11996 SHOW_STR
11997 BGP_STR
11998 "Address family\n"
11999 "Detailed information on TCP and BGP neighbor connections\n"
12000 "Neighbor to display information about\n"
12001 "Neighbor to display information about\n"
a80beece 12002 "Neighbor on bgp configured interface\n"
718e3744 12003 "Display information received from a BGP neighbor\n"
12004 "Display the prefixlist filter\n")
12005
12006/* old command */
bb46e94f 12007ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 12008 ipv6_bgp_neighbor_received_routes_cmd,
a80beece 12009 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12010 SHOW_STR
12011 IPV6_STR
12012 BGP_STR
12013 "Detailed information on TCP and BGP neighbor connections\n"
12014 "Neighbor to display information about\n"
12015 "Neighbor to display information about\n"
a80beece 12016 "Neighbor on bgp configured interface\n"
718e3744 12017 "Display the received routes from neighbor\n")
718e3744 12018
12019/* old command */
12020DEFUN (ipv6_mbgp_neighbor_received_routes,
12021 ipv6_mbgp_neighbor_received_routes_cmd,
a80beece 12022 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
718e3744 12023 SHOW_STR
12024 IPV6_STR
12025 MBGP_STR
12026 "Detailed information on TCP and BGP neighbor connections\n"
12027 "Neighbor to display information about\n"
12028 "Neighbor to display information about\n"
a80beece 12029 "Neighbor on bgp configured interface\n"
718e3744 12030 "Display the received routes from neighbor\n")
12031{
bb46e94f 12032 struct peer *peer;
12033
12034 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12035 if (! peer)
12036 return CMD_WARNING;
12037
0b16f239 12038 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, NULL);
bb46e94f 12039}
12040
12041DEFUN (show_bgp_view_neighbor_received_prefix_filter,
12042 show_bgp_view_neighbor_received_prefix_filter_cmd,
a80beece 12043 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
bb46e94f 12044 SHOW_STR
12045 BGP_STR
12046 "BGP view\n"
12047 "View name\n"
12048 "Detailed information on TCP and BGP neighbor connections\n"
12049 "Neighbor to display information about\n"
12050 "Neighbor to display information about\n"
a80beece 12051 "Neighbor on bgp configured interface\n"
bb46e94f 12052 "Display information received from a BGP neighbor\n"
12053 "Display the prefixlist filter\n")
12054{
12055 char name[BUFSIZ];
c63b83fe 12056 union sockunion su;
bb46e94f 12057 struct peer *peer;
12058 struct bgp *bgp;
c63b83fe 12059 int count, ret;
bb46e94f 12060
12061 /* BGP structure lookup. */
12062 bgp = bgp_lookup_by_name (argv[0]);
12063 if (bgp == NULL)
12064 {
12065 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12066 return CMD_WARNING;
12067 }
12068
c63b83fe
JBD
12069 ret = str2sockunion (argv[1], &su);
12070 if (ret < 0)
12071 {
a80beece
DS
12072 peer = peer_lookup_by_conf_if (bgp, argv[1]);
12073 if (!peer)
12074 {
12075 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
12076 return CMD_WARNING;
12077 }
12078 }
12079 else
12080 {
12081 peer = peer_lookup (bgp, &su);
12082 if (! peer)
12083 return CMD_WARNING;
c63b83fe 12084 }
bb46e94f 12085
12086 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12087 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12088 if (count)
12089 {
12090 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12091 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12092 }
12093
12094 return CMD_SUCCESS;
718e3744 12095}
bb46e94f 12096
12097ALIAS (show_bgp_view_neighbor_received_prefix_filter,
12098 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
a80beece 12099 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
bb46e94f 12100 SHOW_STR
12101 BGP_STR
12102 "BGP view\n"
12103 "View name\n"
12104 "Address family\n"
12105 "Detailed information on TCP and BGP neighbor connections\n"
12106 "Neighbor to display information about\n"
12107 "Neighbor to display information about\n"
a80beece 12108 "Neighbor on bgp configured interface\n"
bb46e94f 12109 "Display information received from a BGP neighbor\n"
12110 "Display the prefixlist filter\n")
718e3744 12111#endif /* HAVE_IPV6 */
6b0655a2 12112
94f2b392 12113static int
bb46e94f 12114bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
47fc97cc 12115 safi_t safi, enum bgp_show_type type, char *delim)
718e3744 12116{
718e3744 12117 if (! peer || ! peer->afc[afi][safi])
12118 {
12119 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
718e3744 12120 return CMD_WARNING;
12121 }
47fc97cc
DS
12122
12123 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, delim);
718e3744 12124}
12125
12126DEFUN (show_ip_bgp_neighbor_routes,
12127 show_ip_bgp_neighbor_routes_cmd,
a80beece 12128 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 12129 SHOW_STR
12130 IP_STR
12131 BGP_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 12135 "Neighbor on bgp configured interface\n"
718e3744 12136 "Display routes learned from neighbor\n")
12137{
bb46e94f 12138 struct peer *peer;
12139
12140 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12141 if (! peer)
12142 return CMD_WARNING;
12143
12144 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
47fc97cc
DS
12145 bgp_show_type_neighbor, NULL);
12146}
12147
12148DEFUN (show_ip_bgp_neighbor_routes_csv,
12149 show_ip_bgp_neighbor_routes_csv_cmd,
a80beece 12150 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes csv",
47fc97cc
DS
12151 SHOW_STR
12152 IP_STR
12153 BGP_STR
12154 "Detailed information on TCP and BGP neighbor connections\n"
12155 "Neighbor to display information about\n"
12156 "Neighbor to display information about\n"
a80beece 12157 "Neighbor on bgp configured interface\n"
47fc97cc
DS
12158 "Display routes learned from neighbor\n")
12159{
12160 struct peer *peer;
12161
12162 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12163 if (! peer)
12164 return CMD_WARNING;
12165
12166 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
12167 bgp_show_type_neighbor, &csv);
718e3744 12168}
12169
12170DEFUN (show_ip_bgp_neighbor_flap,
12171 show_ip_bgp_neighbor_flap_cmd,
a80beece 12172 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
718e3744 12173 SHOW_STR
12174 IP_STR
12175 BGP_STR
12176 "Detailed information on TCP and BGP neighbor connections\n"
12177 "Neighbor to display information about\n"
12178 "Neighbor to display information about\n"
a80beece 12179 "Neighbor on bgp configured interface\n"
718e3744 12180 "Display flap statistics of the routes learned from neighbor\n")
12181{
bb46e94f 12182 struct peer *peer;
12183
12184 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12185 if (! peer)
12186 return CMD_WARNING;
12187
12188 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
47fc97cc 12189 bgp_show_type_flap_neighbor, NULL);
718e3744 12190}
12191
12192DEFUN (show_ip_bgp_neighbor_damp,
12193 show_ip_bgp_neighbor_damp_cmd,
a80beece 12194 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
718e3744 12195 SHOW_STR
12196 IP_STR
12197 BGP_STR
12198 "Detailed information on TCP and BGP neighbor connections\n"
12199 "Neighbor to display information about\n"
12200 "Neighbor to display information about\n"
a80beece 12201 "Neighbor on bgp configured interface\n"
718e3744 12202 "Display the dampened routes received from neighbor\n")
12203{
bb46e94f 12204 struct peer *peer;
12205
12206 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12207 if (! peer)
12208 return CMD_WARNING;
12209
12210 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
47fc97cc 12211 bgp_show_type_damp_neighbor, NULL);
718e3744 12212}
12213
12214DEFUN (show_ip_bgp_ipv4_neighbor_routes,
12215 show_ip_bgp_ipv4_neighbor_routes_cmd,
a80beece 12216 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 12217 SHOW_STR
12218 IP_STR
12219 BGP_STR
12220 "Address family\n"
12221 "Address Family modifier\n"
12222 "Address Family modifier\n"
12223 "Detailed information on TCP and BGP neighbor connections\n"
12224 "Neighbor to display information about\n"
12225 "Neighbor to display information about\n"
a80beece 12226 "Neighbor on bgp configured interface\n"
718e3744 12227 "Display routes learned from neighbor\n")
12228{
bb46e94f 12229 struct peer *peer;
12230
12231 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12232 if (! peer)
12233 return CMD_WARNING;
12234
718e3744 12235 if (strncmp (argv[0], "m", 1) == 0)
bb46e94f 12236 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
47fc97cc 12237 bgp_show_type_neighbor, NULL);
718e3744 12238
bb46e94f 12239 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
47fc97cc 12240 bgp_show_type_neighbor, NULL);
718e3744 12241}
bb46e94f 12242
fee0f4c6 12243DEFUN (show_ip_bgp_view_rsclient,
12244 show_ip_bgp_view_rsclient_cmd,
a80beece 12245 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 12246 SHOW_STR
12247 IP_STR
12248 BGP_STR
12249 "BGP view\n"
2b00515a 12250 "View name\n"
fee0f4c6 12251 "Information about Route Server Client\n"
a80beece 12252 NEIGHBOR_ADDR_STR3)
fee0f4c6 12253{
12254 struct bgp_table *table;
12255 struct peer *peer;
12256
12257 if (argc == 2)
12258 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12259 else
12260 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12261
12262 if (! peer)
12263 return CMD_WARNING;
12264
12265 if (! peer->afc[AFI_IP][SAFI_UNICAST])
12266 {
12267 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12268 VTY_NEWLINE);
12269 return CMD_WARNING;
12270 }
12271
12272 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
12273 PEER_FLAG_RSERVER_CLIENT))
12274 {
12275 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12276 VTY_NEWLINE);
12277 return CMD_WARNING;
12278 }
12279
12280 table = peer->rib[AFI_IP][SAFI_UNICAST];
12281
47fc97cc
DS
12282 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
12283 NULL, NULL);
fee0f4c6 12284}
12285
12286ALIAS (show_ip_bgp_view_rsclient,
12287 show_ip_bgp_rsclient_cmd,
a80beece 12288 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 12289 SHOW_STR
12290 IP_STR
12291 BGP_STR
12292 "Information about Route Server Client\n"
a80beece 12293 NEIGHBOR_ADDR_STR3)
fee0f4c6 12294
95cbbd2a
ML
12295DEFUN (show_bgp_view_ipv4_safi_rsclient,
12296 show_bgp_view_ipv4_safi_rsclient_cmd,
a80beece 12297 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 12298 SHOW_STR
fee0f4c6 12299 BGP_STR
12300 "BGP view\n"
2b00515a 12301 "View name\n"
95cbbd2a
ML
12302 "Address family\n"
12303 "Address Family modifier\n"
12304 "Address Family modifier\n"
fee0f4c6 12305 "Information about Route Server Client\n"
a80beece 12306 NEIGHBOR_ADDR_STR3)
fee0f4c6 12307{
95cbbd2a 12308 struct bgp_table *table;
fee0f4c6 12309 struct peer *peer;
95cbbd2a 12310 safi_t safi;
fee0f4c6 12311
95cbbd2a
ML
12312 if (argc == 3) {
12313 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12314 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12315 } else {
12316 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12317 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12318 }
12319
12320 if (! peer)
12321 return CMD_WARNING;
12322
12323 if (! peer->afc[AFI_IP][safi])
fee0f4c6 12324 {
95cbbd2a
ML
12325 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12326 VTY_NEWLINE);
12327 return CMD_WARNING;
12328 }
12329
12330 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
12331 PEER_FLAG_RSERVER_CLIENT))
12332 {
12333 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12334 VTY_NEWLINE);
12335 return CMD_WARNING;
12336 }
12337
12338 table = peer->rib[AFI_IP][safi];
12339
47fc97cc
DS
12340 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
12341 NULL, NULL);
95cbbd2a
ML
12342}
12343
12344ALIAS (show_bgp_view_ipv4_safi_rsclient,
12345 show_bgp_ipv4_safi_rsclient_cmd,
a80beece 12346 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
95cbbd2a
ML
12347 SHOW_STR
12348 BGP_STR
12349 "Address family\n"
12350 "Address Family modifier\n"
12351 "Address Family modifier\n"
12352 "Information about Route Server Client\n"
a80beece 12353 NEIGHBOR_ADDR_STR3)
95cbbd2a
ML
12354
12355DEFUN (show_ip_bgp_view_rsclient_route,
12356 show_ip_bgp_view_rsclient_route_cmd,
a80beece 12357 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
95cbbd2a
ML
12358 SHOW_STR
12359 IP_STR
12360 BGP_STR
12361 "BGP view\n"
2b00515a 12362 "View name\n"
95cbbd2a 12363 "Information about Route Server Client\n"
a80beece 12364 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
12365 "Network in the BGP routing table to display\n")
12366{
12367 struct bgp *bgp;
12368 struct peer *peer;
12369
12370 /* BGP structure lookup. */
12371 if (argc == 3)
12372 {
12373 bgp = bgp_lookup_by_name (argv[0]);
12374 if (bgp == NULL)
12375 {
12376 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12377 return CMD_WARNING;
fee0f4c6 12378 }
12379 }
12380 else
12381 {
12382 bgp = bgp_get_default ();
12383 if (bgp == NULL)
12384 {
12385 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12386 return CMD_WARNING;
12387 }
12388 }
12389
12390 if (argc == 3)
12391 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12392 else
12393 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12394
12395 if (! peer)
12396 return CMD_WARNING;
12397
12398 if (! peer->afc[AFI_IP][SAFI_UNICAST])
12399 {
12400 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12401 VTY_NEWLINE);
12402 return CMD_WARNING;
12403}
12404
12405 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
12406 PEER_FLAG_RSERVER_CLIENT))
12407 {
12408 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12409 VTY_NEWLINE);
12410 return CMD_WARNING;
12411 }
12412
12413 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
12414 (argc == 3) ? argv[2] : argv[1],
4092b06c 12415 AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
fee0f4c6 12416}
12417
12418ALIAS (show_ip_bgp_view_rsclient_route,
12419 show_ip_bgp_rsclient_route_cmd,
a80beece 12420 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
fee0f4c6 12421 SHOW_STR
12422 IP_STR
12423 BGP_STR
12424 "Information about Route Server Client\n"
a80beece 12425 NEIGHBOR_ADDR_STR3
fee0f4c6 12426 "Network in the BGP routing table to display\n")
12427
95cbbd2a
ML
12428DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
12429 show_bgp_view_ipv4_safi_rsclient_route_cmd,
a80beece 12430 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
95cbbd2a
ML
12431 SHOW_STR
12432 BGP_STR
12433 "BGP view\n"
2b00515a 12434 "View name\n"
95cbbd2a
ML
12435 "Address family\n"
12436 "Address Family modifier\n"
12437 "Address Family modifier\n"
12438 "Information about Route Server Client\n"
a80beece 12439 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
12440 "Network in the BGP routing table to display\n")
12441{
12442 struct bgp *bgp;
12443 struct peer *peer;
12444 safi_t safi;
12445
12446 /* BGP structure lookup. */
12447 if (argc == 4)
12448 {
12449 bgp = bgp_lookup_by_name (argv[0]);
12450 if (bgp == NULL)
12451 {
12452 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12453 return CMD_WARNING;
12454 }
12455 }
12456 else
12457 {
12458 bgp = bgp_get_default ();
12459 if (bgp == NULL)
12460 {
12461 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12462 return CMD_WARNING;
12463 }
12464 }
12465
12466 if (argc == 4) {
12467 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12468 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12469 } else {
12470 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12471 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12472 }
12473
12474 if (! peer)
12475 return CMD_WARNING;
12476
12477 if (! peer->afc[AFI_IP][safi])
12478 {
12479 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12480 VTY_NEWLINE);
12481 return CMD_WARNING;
12482}
12483
12484 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
12485 PEER_FLAG_RSERVER_CLIENT))
12486 {
12487 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12488 VTY_NEWLINE);
12489 return CMD_WARNING;
12490 }
12491
12492 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
12493 (argc == 4) ? argv[3] : argv[2],
4092b06c 12494 AFI_IP, safi, NULL, 0, BGP_PATH_ALL);
95cbbd2a
ML
12495}
12496
12497ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
12498 show_bgp_ipv4_safi_rsclient_route_cmd,
a80beece 12499 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
95cbbd2a
ML
12500 SHOW_STR
12501 BGP_STR
12502 "Address family\n"
12503 "Address Family modifier\n"
12504 "Address Family modifier\n"
12505 "Information about Route Server Client\n"
a80beece 12506 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
12507 "Network in the BGP routing table to display\n")
12508
fee0f4c6 12509DEFUN (show_ip_bgp_view_rsclient_prefix,
12510 show_ip_bgp_view_rsclient_prefix_cmd,
a80beece 12511 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
fee0f4c6 12512 SHOW_STR
12513 IP_STR
12514 BGP_STR
12515 "BGP view\n"
2b00515a 12516 "View name\n"
fee0f4c6 12517 "Information about Route Server Client\n"
a80beece 12518 NEIGHBOR_ADDR_STR3
fee0f4c6 12519 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12520{
12521 struct bgp *bgp;
12522 struct peer *peer;
12523
12524 /* BGP structure lookup. */
12525 if (argc == 3)
12526 {
12527 bgp = bgp_lookup_by_name (argv[0]);
12528 if (bgp == NULL)
12529 {
12530 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12531 return CMD_WARNING;
12532 }
12533 }
12534 else
12535 {
12536 bgp = bgp_get_default ();
12537 if (bgp == NULL)
12538 {
12539 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12540 return CMD_WARNING;
12541 }
12542 }
12543
12544 if (argc == 3)
12545 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12546 else
12547 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12548
12549 if (! peer)
12550 return CMD_WARNING;
12551
12552 if (! peer->afc[AFI_IP][SAFI_UNICAST])
12553 {
12554 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12555 VTY_NEWLINE);
12556 return CMD_WARNING;
12557}
12558
12559 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
12560 PEER_FLAG_RSERVER_CLIENT))
12561{
12562 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12563 VTY_NEWLINE);
12564 return CMD_WARNING;
12565 }
12566
12567 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
12568 (argc == 3) ? argv[2] : argv[1],
4092b06c 12569 AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
fee0f4c6 12570}
12571
12572ALIAS (show_ip_bgp_view_rsclient_prefix,
12573 show_ip_bgp_rsclient_prefix_cmd,
a80beece 12574 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
fee0f4c6 12575 SHOW_STR
12576 IP_STR
12577 BGP_STR
12578 "Information about Route Server Client\n"
a80beece 12579 NEIGHBOR_ADDR_STR3
fee0f4c6 12580 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12581
95cbbd2a
ML
12582DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
12583 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
a80beece 12584 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
95cbbd2a
ML
12585 SHOW_STR
12586 BGP_STR
12587 "BGP view\n"
2b00515a 12588 "View name\n"
95cbbd2a
ML
12589 "Address family\n"
12590 "Address Family modifier\n"
12591 "Address Family modifier\n"
12592 "Information about Route Server Client\n"
a80beece 12593 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
12594 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12595{
12596 struct bgp *bgp;
12597 struct peer *peer;
12598 safi_t safi;
12599
12600 /* BGP structure lookup. */
12601 if (argc == 4)
12602 {
12603 bgp = bgp_lookup_by_name (argv[0]);
12604 if (bgp == NULL)
12605 {
12606 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12607 return CMD_WARNING;
12608 }
12609 }
12610 else
12611 {
12612 bgp = bgp_get_default ();
12613 if (bgp == NULL)
12614 {
12615 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12616 return CMD_WARNING;
12617 }
12618 }
12619
12620 if (argc == 4) {
12621 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12622 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12623 } else {
12624 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12625 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12626 }
12627
12628 if (! peer)
12629 return CMD_WARNING;
12630
12631 if (! peer->afc[AFI_IP][safi])
12632 {
12633 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12634 VTY_NEWLINE);
12635 return CMD_WARNING;
12636}
12637
12638 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
12639 PEER_FLAG_RSERVER_CLIENT))
12640{
12641 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12642 VTY_NEWLINE);
12643 return CMD_WARNING;
12644 }
12645
12646 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
12647 (argc == 4) ? argv[3] : argv[2],
4092b06c 12648 AFI_IP, safi, NULL, 1, BGP_PATH_ALL);
95cbbd2a
ML
12649}
12650
12651ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
12652 show_bgp_ipv4_safi_rsclient_prefix_cmd,
a80beece 12653 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
95cbbd2a
ML
12654 SHOW_STR
12655 BGP_STR
12656 "Address family\n"
12657 "Address Family modifier\n"
12658 "Address Family modifier\n"
12659 "Information about Route Server Client\n"
a80beece 12660 NEIGHBOR_ADDR_STR3
95cbbd2a 12661 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
fee0f4c6 12662
718e3744 12663#ifdef HAVE_IPV6
bb46e94f 12664DEFUN (show_bgp_view_neighbor_routes,
12665 show_bgp_view_neighbor_routes_cmd,
a80beece 12666 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 12667 SHOW_STR
12668 BGP_STR
bb46e94f 12669 "BGP view\n"
2b00515a 12670 "View name\n"
718e3744 12671 "Detailed information on TCP and BGP neighbor connections\n"
12672 "Neighbor to display information about\n"
12673 "Neighbor to display information about\n"
a80beece 12674 "Neighbor on bgp configured interface\n"
718e3744 12675 "Display routes learned from neighbor\n")
12676{
bb46e94f 12677 struct peer *peer;
12678
12679 if (argc == 2)
12680 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12681 else
12682 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12683
12684 if (! peer)
12685 return CMD_WARNING;
12686
12687 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
47fc97cc
DS
12688 bgp_show_type_neighbor, NULL);
12689}
12690
12691DEFUN (show_bgp_view_neighbor_routes_csv,
12692 show_bgp_view_neighbor_routes_csv_cmd,
a80beece 12693 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) routes csv",
47fc97cc
DS
12694 SHOW_STR
12695 BGP_STR
12696 "BGP view\n"
12697 "BGP view name\n"
12698 "Detailed information on TCP and BGP neighbor connections\n"
12699 "Neighbor to display information about\n"
12700 "Neighbor to display information about\n"
a80beece 12701 "Neighbor on bgp configured interface\n"
47fc97cc
DS
12702 "Display routes learned from neighbor\n")
12703{
12704 struct peer *peer;
12705
12706 if (argc == 2)
12707 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12708 else
12709 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12710
12711 if (! peer)
12712 return CMD_WARNING;
12713
12714 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
12715 bgp_show_type_neighbor, &csv);
718e3744 12716}
12717
bb46e94f 12718ALIAS (show_bgp_view_neighbor_routes,
12719 show_bgp_view_ipv6_neighbor_routes_cmd,
a80beece 12720 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes",
bb46e94f 12721 SHOW_STR
12722 BGP_STR
12723 "BGP view\n"
2b00515a 12724 "View name\n"
bb46e94f 12725 "Address family\n"
12726 "Detailed information on TCP and BGP neighbor connections\n"
12727 "Neighbor to display information about\n"
12728 "Neighbor to display information about\n"
a80beece 12729 "Neighbor on bgp configured interface\n"
bb46e94f 12730 "Display routes learned from neighbor\n")
12731
12732DEFUN (show_bgp_view_neighbor_damp,
12733 show_bgp_view_neighbor_damp_cmd,
a80beece 12734 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
bb46e94f 12735 SHOW_STR
12736 BGP_STR
12737 "BGP view\n"
2b00515a 12738 "View name\n"
bb46e94f 12739 "Detailed information on TCP and BGP neighbor connections\n"
12740 "Neighbor to display information about\n"
12741 "Neighbor to display information about\n"
a80beece 12742 "Neighbor on bgp configured interface\n"
bb46e94f 12743 "Display the dampened routes received from neighbor\n")
12744{
12745 struct peer *peer;
12746
12747 if (argc == 2)
12748 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12749 else
12750 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12751
12752 if (! peer)
12753 return CMD_WARNING;
12754
12755 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
47fc97cc 12756 bgp_show_type_damp_neighbor, NULL);
bb46e94f 12757}
12758
12759ALIAS (show_bgp_view_neighbor_damp,
12760 show_bgp_view_ipv6_neighbor_damp_cmd,
a80beece 12761 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
bb46e94f 12762 SHOW_STR
12763 BGP_STR
12764 "BGP view\n"
2b00515a 12765 "View name\n"
bb46e94f 12766 "Address family\n"
12767 "Detailed information on TCP and BGP neighbor connections\n"
12768 "Neighbor to display information about\n"
12769 "Neighbor to display information about\n"
a80beece 12770 "Neighbor on bgp configured interface\n"
bb46e94f 12771 "Display the dampened routes received from neighbor\n")
12772
12773DEFUN (show_bgp_view_neighbor_flap,
12774 show_bgp_view_neighbor_flap_cmd,
a80beece 12775 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
bb46e94f 12776 SHOW_STR
12777 BGP_STR
12778 "BGP view\n"
2b00515a 12779 "View name\n"
bb46e94f 12780 "Detailed information on TCP and BGP neighbor connections\n"
12781 "Neighbor to display information about\n"
12782 "Neighbor to display information about\n"
a80beece 12783 "Neighbor on bgp configured interface\n"
bb46e94f 12784 "Display flap statistics of the routes learned from neighbor\n")
12785{
12786 struct peer *peer;
12787
12788 if (argc == 2)
12789 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12790 else
12791 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12792
12793 if (! peer)
12794 return CMD_WARNING;
12795
12796 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
47fc97cc 12797 bgp_show_type_flap_neighbor, NULL);
bb46e94f 12798}
12799
12800ALIAS (show_bgp_view_neighbor_flap,
12801 show_bgp_view_ipv6_neighbor_flap_cmd,
a80beece 12802 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
bb46e94f 12803 SHOW_STR
12804 BGP_STR
12805 "BGP view\n"
2b00515a 12806 "View name\n"
bb46e94f 12807 "Address family\n"
12808 "Detailed information on TCP and BGP neighbor connections\n"
12809 "Neighbor to display information about\n"
12810 "Neighbor to display information about\n"
a80beece 12811 "Neighbor on bgp configured interface\n"
bb46e94f 12812 "Display flap statistics of the routes learned from neighbor\n")
12813
12814ALIAS (show_bgp_view_neighbor_routes,
12815 show_bgp_neighbor_routes_cmd,
a80beece 12816 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
bb46e94f 12817 SHOW_STR
12818 BGP_STR
12819 "Detailed information on TCP and BGP neighbor connections\n"
12820 "Neighbor to display information about\n"
12821 "Neighbor to display information about\n"
a80beece 12822 "Neighbor on bgp configured interface\n"
bb46e94f 12823 "Display routes learned from neighbor\n")
12824
12825
12826ALIAS (show_bgp_view_neighbor_routes,
718e3744 12827 show_bgp_ipv6_neighbor_routes_cmd,
a80beece 12828 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 12829 SHOW_STR
12830 BGP_STR
12831 "Address family\n"
12832 "Detailed information on TCP and BGP neighbor connections\n"
12833 "Neighbor to display information about\n"
12834 "Neighbor to display information about\n"
a80beece 12835 "Neighbor on bgp configured interface\n"
718e3744 12836 "Display routes learned from neighbor\n")
12837
12838/* old command */
bb46e94f 12839ALIAS (show_bgp_view_neighbor_routes,
718e3744 12840 ipv6_bgp_neighbor_routes_cmd,
a80beece 12841 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 12842 SHOW_STR
12843 IPV6_STR
12844 BGP_STR
12845 "Detailed information on TCP and BGP neighbor connections\n"
12846 "Neighbor to display information about\n"
12847 "Neighbor to display information about\n"
a80beece 12848 "Neighbor on bgp configured interface\n"
718e3744 12849 "Display routes learned from neighbor\n")
718e3744 12850
47fc97cc
DS
12851ALIAS (show_bgp_view_neighbor_routes_csv,
12852 show_bgp_neighbor_routes_csv_cmd,
a80beece 12853 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes csv",
47fc97cc
DS
12854 SHOW_STR
12855 BGP_STR
12856 "Detailed information on TCP and BGP neighbor connections\n"
12857 "Neighbor to display information about\n"
12858 "Neighbor to display information about\n"
a80beece 12859 "Neighbor on bgp configured interface\n"
47fc97cc
DS
12860 "Display routes learned from neighbor\n")
12861
12862
12863ALIAS (show_bgp_view_neighbor_routes_csv,
12864 show_bgp_ipv6_neighbor_routes_csv_cmd,
a80beece 12865 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes csv",
47fc97cc
DS
12866 SHOW_STR
12867 BGP_STR
12868 "Address family\n"
12869 "Detailed information on TCP and BGP neighbor connections\n"
12870 "Neighbor to display information about\n"
12871 "Neighbor to display information about\n"
a80beece 12872 "Neighbor on bgp configured interface\n"
47fc97cc
DS
12873 "Display routes learned from neighbor\n")
12874
12875/* old command */
12876ALIAS (show_bgp_view_neighbor_routes_csv,
12877 ipv6_bgp_neighbor_routes_csv_cmd,
a80beece 12878 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes csv",
47fc97cc
DS
12879 SHOW_STR
12880 IPV6_STR
12881 BGP_STR
12882 "Detailed information on TCP and BGP neighbor connections\n"
12883 "Neighbor to display information about\n"
12884 "Neighbor to display information about\n"
a80beece 12885 "Neighbor on bgp configured interface\n"
47fc97cc
DS
12886 "Display routes learned from neighbor\n")
12887
718e3744 12888/* old command */
12889DEFUN (ipv6_mbgp_neighbor_routes,
12890 ipv6_mbgp_neighbor_routes_cmd,
a80beece 12891 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
718e3744 12892 SHOW_STR
12893 IPV6_STR
12894 MBGP_STR
12895 "Detailed information on TCP and BGP neighbor connections\n"
12896 "Neighbor to display information about\n"
12897 "Neighbor to display information about\n"
a80beece 12898 "Neighbor on bgp configured interface\n"
718e3744 12899 "Display routes learned from neighbor\n")
12900{
bb46e94f 12901 struct peer *peer;
12902
12903 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12904 if (! peer)
12905 return CMD_WARNING;
12906
12907 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
47fc97cc 12908 bgp_show_type_neighbor, NULL);
718e3744 12909}
bb46e94f 12910
12911ALIAS (show_bgp_view_neighbor_flap,
12912 show_bgp_neighbor_flap_cmd,
a80beece 12913 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
bb46e94f 12914 SHOW_STR
12915 BGP_STR
12916 "Detailed information on TCP and BGP neighbor connections\n"
12917 "Neighbor to display information about\n"
12918 "Neighbor to display information about\n"
a80beece 12919 "Neighbor on bgp configured interface\n"
bb46e94f 12920 "Display flap statistics of the routes learned from neighbor\n")
12921
12922ALIAS (show_bgp_view_neighbor_flap,
12923 show_bgp_ipv6_neighbor_flap_cmd,
a80beece 12924 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
bb46e94f 12925 SHOW_STR
12926 BGP_STR
12927 "Address family\n"
12928 "Detailed information on TCP and BGP neighbor connections\n"
12929 "Neighbor to display information about\n"
12930 "Neighbor to display information about\n"
a80beece 12931 "Neighbor on bgp configured interface\n"
bb46e94f 12932 "Display flap statistics of the routes learned from neighbor\n")
12933
12934ALIAS (show_bgp_view_neighbor_damp,
12935 show_bgp_neighbor_damp_cmd,
a80beece 12936 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
bb46e94f 12937 SHOW_STR
12938 BGP_STR
12939 "Detailed information on TCP and BGP neighbor connections\n"
12940 "Neighbor to display information about\n"
12941 "Neighbor to display information about\n"
a80beece 12942 "Neighbor on bgp configured interface\n"
bb46e94f 12943 "Display the dampened routes received from neighbor\n")
12944
12945ALIAS (show_bgp_view_neighbor_damp,
12946 show_bgp_ipv6_neighbor_damp_cmd,
a80beece 12947 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
bb46e94f 12948 SHOW_STR
12949 BGP_STR
12950 "Address family\n"
12951 "Detailed information on TCP and BGP neighbor connections\n"
12952 "Neighbor to display information about\n"
12953 "Neighbor to display information about\n"
a80beece 12954 "Neighbor on bgp configured interface\n"
c001ae62 12955 "Display the dampened routes received from neighbor\n")
fee0f4c6 12956
12957DEFUN (show_bgp_view_rsclient,
12958 show_bgp_view_rsclient_cmd,
a80beece 12959 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 12960 SHOW_STR
12961 BGP_STR
12962 "BGP view\n"
2b00515a 12963 "View name\n"
fee0f4c6 12964 "Information about Route Server Client\n"
a80beece 12965 NEIGHBOR_ADDR_STR3)
fee0f4c6 12966{
12967 struct bgp_table *table;
12968 struct peer *peer;
12969
12970 if (argc == 2)
12971 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12972 else
12973 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12974
12975 if (! peer)
12976 return CMD_WARNING;
12977
12978 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
12979 {
12980 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12981 VTY_NEWLINE);
12982 return CMD_WARNING;
12983 }
12984
12985 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
12986 PEER_FLAG_RSERVER_CLIENT))
12987 {
12988 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12989 VTY_NEWLINE);
12990 return CMD_WARNING;
12991 }
12992
12993 table = peer->rib[AFI_IP6][SAFI_UNICAST];
12994
47fc97cc
DS
12995 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
12996 NULL, NULL);
fee0f4c6 12997}
12998
12999ALIAS (show_bgp_view_rsclient,
13000 show_bgp_rsclient_cmd,
a80beece 13001 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD)",
fee0f4c6 13002 SHOW_STR
13003 BGP_STR
13004 "Information about Route Server Client\n"
a80beece 13005 NEIGHBOR_ADDR_STR3)
fee0f4c6 13006
95cbbd2a
ML
13007DEFUN (show_bgp_view_ipv6_safi_rsclient,
13008 show_bgp_view_ipv6_safi_rsclient_cmd,
a80beece 13009 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
95cbbd2a
ML
13010 SHOW_STR
13011 BGP_STR
13012 "BGP view\n"
2b00515a 13013 "View name\n"
95cbbd2a
ML
13014 "Address family\n"
13015 "Address Family modifier\n"
13016 "Address Family modifier\n"
13017 "Information about Route Server Client\n"
a80beece 13018 NEIGHBOR_ADDR_STR3)
95cbbd2a
ML
13019{
13020 struct bgp_table *table;
13021 struct peer *peer;
13022 safi_t safi;
13023
13024 if (argc == 3) {
13025 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13026 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13027 } else {
13028 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13029 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13030 }
13031
13032 if (! peer)
13033 return CMD_WARNING;
13034
13035 if (! peer->afc[AFI_IP6][safi])
13036 {
13037 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13038 VTY_NEWLINE);
13039 return CMD_WARNING;
13040 }
13041
13042 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
13043 PEER_FLAG_RSERVER_CLIENT))
13044 {
13045 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13046 VTY_NEWLINE);
13047 return CMD_WARNING;
13048 }
13049
13050 table = peer->rib[AFI_IP6][safi];
13051
47fc97cc
DS
13052 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
13053 NULL, NULL);
95cbbd2a
ML
13054}
13055
13056ALIAS (show_bgp_view_ipv6_safi_rsclient,
13057 show_bgp_ipv6_safi_rsclient_cmd,
a80beece 13058 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
95cbbd2a
ML
13059 SHOW_STR
13060 BGP_STR
13061 "Address family\n"
13062 "Address Family modifier\n"
13063 "Address Family modifier\n"
13064 "Information about Route Server Client\n"
a80beece 13065 NEIGHBOR_ADDR_STR3)
95cbbd2a 13066
fee0f4c6 13067DEFUN (show_bgp_view_rsclient_route,
13068 show_bgp_view_rsclient_route_cmd,
a80beece 13069 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
fee0f4c6 13070 SHOW_STR
13071 BGP_STR
13072 "BGP view\n"
2b00515a 13073 "View name\n"
fee0f4c6 13074 "Information about Route Server Client\n"
a80beece 13075 NEIGHBOR_ADDR_STR3
fee0f4c6 13076 "Network in the BGP routing table to display\n")
13077{
13078 struct bgp *bgp;
13079 struct peer *peer;
13080
13081 /* BGP structure lookup. */
13082 if (argc == 3)
13083 {
13084 bgp = bgp_lookup_by_name (argv[0]);
13085 if (bgp == NULL)
13086 {
13087 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13088 return CMD_WARNING;
13089 }
13090 }
13091 else
13092 {
13093 bgp = bgp_get_default ();
13094 if (bgp == NULL)
13095 {
13096 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13097 return CMD_WARNING;
13098 }
13099 }
13100
13101 if (argc == 3)
13102 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13103 else
13104 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13105
13106 if (! peer)
13107 return CMD_WARNING;
13108
13109 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
13110 {
13111 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13112 VTY_NEWLINE);
13113 return CMD_WARNING;
13114 }
13115
13116 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
13117 PEER_FLAG_RSERVER_CLIENT))
13118 {
13119 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13120 VTY_NEWLINE);
13121 return CMD_WARNING;
13122 }
13123
13124 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
13125 (argc == 3) ? argv[2] : argv[1],
4092b06c 13126 AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
fee0f4c6 13127}
13128
13129ALIAS (show_bgp_view_rsclient_route,
13130 show_bgp_rsclient_route_cmd,
a80beece 13131 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
fee0f4c6 13132 SHOW_STR
13133 BGP_STR
13134 "Information about Route Server Client\n"
a80beece 13135 NEIGHBOR_ADDR_STR3
fee0f4c6 13136 "Network in the BGP routing table to display\n")
13137
95cbbd2a
ML
13138DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
13139 show_bgp_view_ipv6_safi_rsclient_route_cmd,
a80beece 13140 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
95cbbd2a
ML
13141 SHOW_STR
13142 BGP_STR
13143 "BGP view\n"
2b00515a 13144 "View name\n"
95cbbd2a
ML
13145 "Address family\n"
13146 "Address Family modifier\n"
13147 "Address Family modifier\n"
13148 "Information about Route Server Client\n"
a80beece 13149 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13150 "Network in the BGP routing table to display\n")
13151{
13152 struct bgp *bgp;
13153 struct peer *peer;
13154 safi_t safi;
13155
13156 /* BGP structure lookup. */
13157 if (argc == 4)
13158 {
13159 bgp = bgp_lookup_by_name (argv[0]);
13160 if (bgp == NULL)
13161 {
13162 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13163 return CMD_WARNING;
13164 }
13165 }
13166 else
13167 {
13168 bgp = bgp_get_default ();
13169 if (bgp == NULL)
13170 {
13171 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13172 return CMD_WARNING;
13173 }
13174 }
13175
13176 if (argc == 4) {
13177 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13178 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13179 } else {
13180 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13181 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13182 }
13183
13184 if (! peer)
13185 return CMD_WARNING;
13186
13187 if (! peer->afc[AFI_IP6][safi])
13188 {
13189 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13190 VTY_NEWLINE);
13191 return CMD_WARNING;
13192}
13193
13194 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
13195 PEER_FLAG_RSERVER_CLIENT))
13196 {
13197 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13198 VTY_NEWLINE);
13199 return CMD_WARNING;
13200 }
13201
13202 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
13203 (argc == 4) ? argv[3] : argv[2],
4092b06c 13204 AFI_IP6, safi, NULL, 0, BGP_PATH_ALL);
95cbbd2a
ML
13205}
13206
13207ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
13208 show_bgp_ipv6_safi_rsclient_route_cmd,
a80beece 13209 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
95cbbd2a
ML
13210 SHOW_STR
13211 BGP_STR
13212 "Address family\n"
13213 "Address Family modifier\n"
13214 "Address Family modifier\n"
13215 "Information about Route Server Client\n"
a80beece 13216 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13217 "Network in the BGP routing table to display\n")
13218
fee0f4c6 13219DEFUN (show_bgp_view_rsclient_prefix,
13220 show_bgp_view_rsclient_prefix_cmd,
a80beece 13221 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
fee0f4c6 13222 SHOW_STR
13223 BGP_STR
13224 "BGP view\n"
2b00515a 13225 "View name\n"
fee0f4c6 13226 "Information about Route Server Client\n"
a80beece 13227 NEIGHBOR_ADDR_STR3
fee0f4c6 13228 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
13229{
13230 struct bgp *bgp;
13231 struct peer *peer;
13232
13233 /* BGP structure lookup. */
13234 if (argc == 3)
13235 {
13236 bgp = bgp_lookup_by_name (argv[0]);
13237 if (bgp == NULL)
13238 {
13239 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13240 return CMD_WARNING;
13241 }
13242 }
13243 else
13244 {
13245 bgp = bgp_get_default ();
13246 if (bgp == NULL)
13247 {
13248 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13249 return CMD_WARNING;
13250 }
13251 }
13252
13253 if (argc == 3)
13254 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13255 else
13256 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13257
13258 if (! peer)
13259 return CMD_WARNING;
13260
13261 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
13262 {
13263 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13264 VTY_NEWLINE);
13265 return CMD_WARNING;
13266 }
13267
13268 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
13269 PEER_FLAG_RSERVER_CLIENT))
13270 {
13271 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13272 VTY_NEWLINE);
13273 return CMD_WARNING;
13274 }
13275
13276 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
13277 (argc == 3) ? argv[2] : argv[1],
4092b06c 13278 AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
fee0f4c6 13279}
13280
13281ALIAS (show_bgp_view_rsclient_prefix,
13282 show_bgp_rsclient_prefix_cmd,
a80beece 13283 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
fee0f4c6 13284 SHOW_STR
13285 BGP_STR
13286 "Information about Route Server Client\n"
a80beece 13287 NEIGHBOR_ADDR_STR3
fee0f4c6 13288 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
13289
95cbbd2a
ML
13290DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
13291 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
a80beece 13292 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
95cbbd2a
ML
13293 SHOW_STR
13294 BGP_STR
13295 "BGP view\n"
2b00515a 13296 "View name\n"
95cbbd2a
ML
13297 "Address family\n"
13298 "Address Family modifier\n"
13299 "Address Family modifier\n"
13300 "Information about Route Server Client\n"
a80beece 13301 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13302 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
13303{
13304 struct bgp *bgp;
13305 struct peer *peer;
13306 safi_t safi;
13307
13308 /* BGP structure lookup. */
13309 if (argc == 4)
13310 {
13311 bgp = bgp_lookup_by_name (argv[0]);
13312 if (bgp == NULL)
13313 {
13314 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13315 return CMD_WARNING;
13316 }
13317 }
13318 else
13319 {
13320 bgp = bgp_get_default ();
13321 if (bgp == NULL)
13322 {
13323 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13324 return CMD_WARNING;
13325 }
13326 }
13327
13328 if (argc == 4) {
13329 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13330 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13331 } else {
13332 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13333 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13334 }
13335
13336 if (! peer)
13337 return CMD_WARNING;
13338
13339 if (! peer->afc[AFI_IP6][safi])
13340 {
13341 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13342 VTY_NEWLINE);
13343 return CMD_WARNING;
13344}
13345
13346 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
13347 PEER_FLAG_RSERVER_CLIENT))
13348{
13349 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13350 VTY_NEWLINE);
13351 return CMD_WARNING;
13352 }
13353
13354 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
13355 (argc == 4) ? argv[3] : argv[2],
4092b06c 13356 AFI_IP6, safi, NULL, 1, BGP_PATH_ALL);
95cbbd2a
ML
13357}
13358
13359ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
13360 show_bgp_ipv6_safi_rsclient_prefix_cmd,
a80beece 13361 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
95cbbd2a
ML
13362 SHOW_STR
13363 BGP_STR
13364 "Address family\n"
13365 "Address Family modifier\n"
13366 "Address Family modifier\n"
13367 "Information about Route Server Client\n"
a80beece 13368 NEIGHBOR_ADDR_STR3
95cbbd2a
ML
13369 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
13370
718e3744 13371#endif /* HAVE_IPV6 */
6b0655a2 13372
718e3744 13373struct bgp_table *bgp_distance_table;
13374
13375struct bgp_distance
13376{
13377 /* Distance value for the IP source prefix. */
13378 u_char distance;
13379
13380 /* Name of the access-list to be matched. */
13381 char *access_list;
13382};
13383
94f2b392 13384static struct bgp_distance *
66e5cd87 13385bgp_distance_new (void)
718e3744 13386{
393deb9b 13387 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
718e3744 13388}
13389
94f2b392 13390static void
718e3744 13391bgp_distance_free (struct bgp_distance *bdistance)
13392{
13393 XFREE (MTYPE_BGP_DISTANCE, bdistance);
13394}
13395
94f2b392 13396static int
fd79ac91 13397bgp_distance_set (struct vty *vty, const char *distance_str,
13398 const char *ip_str, const char *access_list_str)
718e3744 13399{
13400 int ret;
13401 struct prefix_ipv4 p;
13402 u_char distance;
13403 struct bgp_node *rn;
13404 struct bgp_distance *bdistance;
13405
13406 ret = str2prefix_ipv4 (ip_str, &p);
13407 if (ret == 0)
13408 {
13409 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13410 return CMD_WARNING;
13411 }
13412
13413 distance = atoi (distance_str);
13414
13415 /* Get BGP distance node. */
13416 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
13417 if (rn->info)
13418 {
13419 bdistance = rn->info;
13420 bgp_unlock_node (rn);
13421 }
13422 else
13423 {
13424 bdistance = bgp_distance_new ();
13425 rn->info = bdistance;
13426 }
13427
13428 /* Set distance value. */
13429 bdistance->distance = distance;
13430
13431 /* Reset access-list configuration. */
13432 if (bdistance->access_list)
13433 {
13434 free (bdistance->access_list);
13435 bdistance->access_list = NULL;
13436 }
13437 if (access_list_str)
13438 bdistance->access_list = strdup (access_list_str);
13439
13440 return CMD_SUCCESS;
13441}
13442
94f2b392 13443static int
fd79ac91 13444bgp_distance_unset (struct vty *vty, const char *distance_str,
13445 const char *ip_str, const char *access_list_str)
718e3744 13446{
13447 int ret;
13448 struct prefix_ipv4 p;
13449 u_char distance;
13450 struct bgp_node *rn;
13451 struct bgp_distance *bdistance;
13452
13453 ret = str2prefix_ipv4 (ip_str, &p);
13454 if (ret == 0)
13455 {
13456 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13457 return CMD_WARNING;
13458 }
13459
13460 distance = atoi (distance_str);
13461
13462 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
13463 if (! rn)
13464 {
13465 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
13466 return CMD_WARNING;
13467 }
13468
13469 bdistance = rn->info;
13470
13471 if (bdistance->access_list)
13472 free (bdistance->access_list);
13473 bgp_distance_free (bdistance);
13474
13475 rn->info = NULL;
13476 bgp_unlock_node (rn);
13477 bgp_unlock_node (rn);
13478
13479 return CMD_SUCCESS;
13480}
13481
718e3744 13482/* Apply BGP information to distance method. */
13483u_char
13484bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
13485{
13486 struct bgp_node *rn;
13487 struct prefix_ipv4 q;
13488 struct peer *peer;
13489 struct bgp_distance *bdistance;
13490 struct access_list *alist;
13491 struct bgp_static *bgp_static;
13492
13493 if (! bgp)
13494 return 0;
13495
13496 if (p->family != AF_INET)
13497 return 0;
13498
13499 peer = rinfo->peer;
13500
13501 if (peer->su.sa.sa_family != AF_INET)
13502 return 0;
13503
13504 memset (&q, 0, sizeof (struct prefix_ipv4));
13505 q.family = AF_INET;
13506 q.prefix = peer->su.sin.sin_addr;
13507 q.prefixlen = IPV4_MAX_BITLEN;
13508
13509 /* Check source address. */
13510 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
13511 if (rn)
13512 {
13513 bdistance = rn->info;
13514 bgp_unlock_node (rn);
13515
13516 if (bdistance->access_list)
13517 {
13518 alist = access_list_lookup (AFI_IP, bdistance->access_list);
13519 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
13520 return bdistance->distance;
13521 }
13522 else
13523 return bdistance->distance;
13524 }
13525
13526 /* Backdoor check. */
13527 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
13528 if (rn)
13529 {
13530 bgp_static = rn->info;
13531 bgp_unlock_node (rn);
13532
13533 if (bgp_static->backdoor)
13534 {
13535 if (bgp->distance_local)
13536 return bgp->distance_local;
13537 else
13538 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13539 }
13540 }
13541
6d85b15b 13542 if (peer->sort == BGP_PEER_EBGP)
718e3744 13543 {
13544 if (bgp->distance_ebgp)
13545 return bgp->distance_ebgp;
13546 return ZEBRA_EBGP_DISTANCE_DEFAULT;
13547 }
13548 else
13549 {
13550 if (bgp->distance_ibgp)
13551 return bgp->distance_ibgp;
13552 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13553 }
13554}
13555
13556DEFUN (bgp_distance,
13557 bgp_distance_cmd,
13558 "distance bgp <1-255> <1-255> <1-255>",
13559 "Define an administrative distance\n"
13560 "BGP distance\n"
13561 "Distance for routes external to the AS\n"
13562 "Distance for routes internal to the AS\n"
13563 "Distance for local routes\n")
13564{
13565 struct bgp *bgp;
13566
13567 bgp = vty->index;
13568
13569 bgp->distance_ebgp = atoi (argv[0]);
13570 bgp->distance_ibgp = atoi (argv[1]);
13571 bgp->distance_local = atoi (argv[2]);
13572 return CMD_SUCCESS;
13573}
13574
13575DEFUN (no_bgp_distance,
13576 no_bgp_distance_cmd,
13577 "no distance bgp <1-255> <1-255> <1-255>",
13578 NO_STR
13579 "Define an administrative distance\n"
13580 "BGP distance\n"
13581 "Distance for routes external to the AS\n"
13582 "Distance for routes internal to the AS\n"
13583 "Distance for local routes\n")
13584{
13585 struct bgp *bgp;
13586
13587 bgp = vty->index;
13588
13589 bgp->distance_ebgp= 0;
13590 bgp->distance_ibgp = 0;
13591 bgp->distance_local = 0;
13592 return CMD_SUCCESS;
13593}
13594
13595ALIAS (no_bgp_distance,
13596 no_bgp_distance2_cmd,
13597 "no distance bgp",
13598 NO_STR
13599 "Define an administrative distance\n"
13600 "BGP distance\n")
13601
13602DEFUN (bgp_distance_source,
13603 bgp_distance_source_cmd,
13604 "distance <1-255> A.B.C.D/M",
13605 "Define an administrative distance\n"
13606 "Administrative distance\n"
13607 "IP source prefix\n")
13608{
13609 bgp_distance_set (vty, argv[0], argv[1], NULL);
13610 return CMD_SUCCESS;
13611}
13612
13613DEFUN (no_bgp_distance_source,
13614 no_bgp_distance_source_cmd,
13615 "no distance <1-255> A.B.C.D/M",
13616 NO_STR
13617 "Define an administrative distance\n"
13618 "Administrative distance\n"
13619 "IP source prefix\n")
13620{
13621 bgp_distance_unset (vty, argv[0], argv[1], NULL);
13622 return CMD_SUCCESS;
13623}
13624
13625DEFUN (bgp_distance_source_access_list,
13626 bgp_distance_source_access_list_cmd,
13627 "distance <1-255> A.B.C.D/M WORD",
13628 "Define an administrative distance\n"
13629 "Administrative distance\n"
13630 "IP source prefix\n"
13631 "Access list name\n")
13632{
13633 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
13634 return CMD_SUCCESS;
13635}
13636
13637DEFUN (no_bgp_distance_source_access_list,
13638 no_bgp_distance_source_access_list_cmd,
13639 "no distance <1-255> A.B.C.D/M WORD",
13640 NO_STR
13641 "Define an administrative distance\n"
13642 "Administrative distance\n"
13643 "IP source prefix\n"
13644 "Access list name\n")
13645{
13646 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
13647 return CMD_SUCCESS;
13648}
6b0655a2 13649
718e3744 13650DEFUN (bgp_damp_set,
13651 bgp_damp_set_cmd,
13652 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13653 "BGP Specific commands\n"
13654 "Enable route-flap dampening\n"
13655 "Half-life time for the penalty\n"
13656 "Value to start reusing a route\n"
13657 "Value to start suppressing a route\n"
13658 "Maximum duration to suppress a stable route\n")
13659{
13660 struct bgp *bgp;
13661 int half = DEFAULT_HALF_LIFE * 60;
13662 int reuse = DEFAULT_REUSE;
13663 int suppress = DEFAULT_SUPPRESS;
13664 int max = 4 * half;
13665
13666 if (argc == 4)
13667 {
13668 half = atoi (argv[0]) * 60;
13669 reuse = atoi (argv[1]);
13670 suppress = atoi (argv[2]);
13671 max = atoi (argv[3]) * 60;
13672 }
13673 else if (argc == 1)
13674 {
13675 half = atoi (argv[0]) * 60;
13676 max = 4 * half;
13677 }
13678
13679 bgp = vty->index;
13680 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
13681 half, reuse, suppress, max);
13682}
13683
13684ALIAS (bgp_damp_set,
13685 bgp_damp_set2_cmd,
13686 "bgp dampening <1-45>",
13687 "BGP Specific commands\n"
13688 "Enable route-flap dampening\n"
13689 "Half-life time for the penalty\n")
13690
13691ALIAS (bgp_damp_set,
13692 bgp_damp_set3_cmd,
13693 "bgp dampening",
13694 "BGP Specific commands\n"
13695 "Enable route-flap dampening\n")
13696
13697DEFUN (bgp_damp_unset,
13698 bgp_damp_unset_cmd,
13699 "no bgp dampening",
13700 NO_STR
13701 "BGP Specific commands\n"
13702 "Enable route-flap dampening\n")
13703{
13704 struct bgp *bgp;
13705
13706 bgp = vty->index;
13707 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
13708}
13709
13710ALIAS (bgp_damp_unset,
13711 bgp_damp_unset2_cmd,
13712 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13713 NO_STR
13714 "BGP Specific commands\n"
13715 "Enable route-flap dampening\n"
13716 "Half-life time for the penalty\n"
13717 "Value to start reusing a route\n"
13718 "Value to start suppressing a route\n"
13719 "Maximum duration to suppress a stable route\n")
13720
13721DEFUN (show_ip_bgp_dampened_paths,
13722 show_ip_bgp_dampened_paths_cmd,
13723 "show ip bgp dampened-paths",
13724 SHOW_STR
13725 IP_STR
13726 BGP_STR
13727 "Display paths suppressed due to dampening\n")
13728{
5a646650 13729 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
47fc97cc 13730 NULL, NULL);
718e3744 13731}
13732
13733DEFUN (show_ip_bgp_flap_statistics,
13734 show_ip_bgp_flap_statistics_cmd,
13735 "show ip bgp flap-statistics",
13736 SHOW_STR
13737 IP_STR
13738 BGP_STR
13739 "Display flap statistics of routes\n")
13740{
5a646650 13741 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
47fc97cc 13742 bgp_show_type_flap_statistics, NULL, NULL);
718e3744 13743}
6b0655a2 13744
718e3744 13745/* Display specified route of BGP table. */
94f2b392 13746static int
fd79ac91 13747bgp_clear_damp_route (struct vty *vty, const char *view_name,
13748 const char *ip_str, afi_t afi, safi_t safi,
13749 struct prefix_rd *prd, int prefix_check)
718e3744 13750{
13751 int ret;
13752 struct prefix match;
13753 struct bgp_node *rn;
13754 struct bgp_node *rm;
13755 struct bgp_info *ri;
13756 struct bgp_info *ri_temp;
13757 struct bgp *bgp;
13758 struct bgp_table *table;
13759
13760 /* BGP structure lookup. */
13761 if (view_name)
13762 {
13763 bgp = bgp_lookup_by_name (view_name);
13764 if (bgp == NULL)
13765 {
13766 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
13767 return CMD_WARNING;
13768 }
13769 }
13770 else
13771 {
13772 bgp = bgp_get_default ();
13773 if (bgp == NULL)
13774 {
13775 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
13776 return CMD_WARNING;
13777 }
13778 }
13779
13780 /* Check IP address argument. */
13781 ret = str2prefix (ip_str, &match);
13782 if (! ret)
13783 {
13784 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
13785 return CMD_WARNING;
13786 }
13787
13788 match.family = afi2family (afi);
13789
13790 if (safi == SAFI_MPLS_VPN)
13791 {
13792 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
13793 {
13794 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
13795 continue;
13796
13797 if ((table = rn->info) != NULL)
13798 if ((rm = bgp_node_match (table, &match)) != NULL)
6c88b44d
CC
13799 {
13800 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
13801 {
13802 ri = rm->info;
13803 while (ri)
13804 {
13805 if (ri->extra && ri->extra->damp_info)
13806 {
13807 ri_temp = ri->next;
13808 bgp_damp_info_free (ri->extra->damp_info, 1);
13809 ri = ri_temp;
13810 }
13811 else
13812 ri = ri->next;
13813 }
13814 }
13815
13816 bgp_unlock_node (rm);
13817 }
718e3744 13818 }
13819 }
13820 else
13821 {
13822 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
6c88b44d
CC
13823 {
13824 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
13825 {
13826 ri = rn->info;
13827 while (ri)
13828 {
13829 if (ri->extra && ri->extra->damp_info)
13830 {
13831 ri_temp = ri->next;
13832 bgp_damp_info_free (ri->extra->damp_info, 1);
13833 ri = ri_temp;
13834 }
13835 else
13836 ri = ri->next;
13837 }
13838 }
13839
13840 bgp_unlock_node (rn);
13841 }
718e3744 13842 }
13843
13844 return CMD_SUCCESS;
13845}
13846
13847DEFUN (clear_ip_bgp_dampening,
13848 clear_ip_bgp_dampening_cmd,
13849 "clear ip bgp dampening",
13850 CLEAR_STR
13851 IP_STR
13852 BGP_STR
13853 "Clear route flap dampening information\n")
13854{
13855 bgp_damp_info_clean ();
13856 return CMD_SUCCESS;
13857}
13858
13859DEFUN (clear_ip_bgp_dampening_prefix,
13860 clear_ip_bgp_dampening_prefix_cmd,
13861 "clear ip bgp dampening A.B.C.D/M",
13862 CLEAR_STR
13863 IP_STR
13864 BGP_STR
13865 "Clear route flap dampening information\n"
13866 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13867{
13868 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
13869 SAFI_UNICAST, NULL, 1);
13870}
13871
13872DEFUN (clear_ip_bgp_dampening_address,
13873 clear_ip_bgp_dampening_address_cmd,
13874 "clear ip bgp dampening A.B.C.D",
13875 CLEAR_STR
13876 IP_STR
13877 BGP_STR
13878 "Clear route flap dampening information\n"
13879 "Network to clear damping information\n")
13880{
13881 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
13882 SAFI_UNICAST, NULL, 0);
13883}
13884
13885DEFUN (clear_ip_bgp_dampening_address_mask,
13886 clear_ip_bgp_dampening_address_mask_cmd,
13887 "clear ip bgp dampening A.B.C.D A.B.C.D",
13888 CLEAR_STR
13889 IP_STR
13890 BGP_STR
13891 "Clear route flap dampening information\n"
13892 "Network to clear damping information\n"
13893 "Network mask\n")
13894{
13895 int ret;
13896 char prefix_str[BUFSIZ];
13897
13898 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
13899 if (! ret)
13900 {
13901 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
13902 return CMD_WARNING;
13903 }
13904
13905 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
13906 SAFI_UNICAST, NULL, 0);
13907}
6b0655a2 13908
94f2b392 13909static int
718e3744 13910bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
13911 afi_t afi, safi_t safi, int *write)
13912{
13913 struct bgp_node *prn;
13914 struct bgp_node *rn;
13915 struct bgp_table *table;
13916 struct prefix *p;
13917 struct prefix_rd *prd;
13918 struct bgp_static *bgp_static;
13919 u_int32_t label;
13920 char buf[SU_ADDRSTRLEN];
13921 char rdbuf[RD_ADDRSTRLEN];
13922
13923 /* Network configuration. */
13924 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
13925 if ((table = prn->info) != NULL)
13926 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
13927 if ((bgp_static = rn->info) != NULL)
13928 {
13929 p = &rn->p;
13930 prd = (struct prefix_rd *) &prn->p;
13931
13932 /* "address-family" display. */
13933 bgp_config_write_family_header (vty, afi, safi, write);
13934
13935 /* "network" configuration display. */
13936 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
13937 label = decode_label (bgp_static->tag);
13938
13939 vty_out (vty, " network %s/%d rd %s tag %d",
13940 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13941 p->prefixlen,
13942 rdbuf, label);
13943 vty_out (vty, "%s", VTY_NEWLINE);
13944 }
13945 return 0;
13946}
13947
13948/* Configuration of static route announcement and aggregate
13949 information. */
13950int
13951bgp_config_write_network (struct vty *vty, struct bgp *bgp,
13952 afi_t afi, safi_t safi, int *write)
13953{
13954 struct bgp_node *rn;
13955 struct prefix *p;
13956 struct bgp_static *bgp_static;
13957 struct bgp_aggregate *bgp_aggregate;
13958 char buf[SU_ADDRSTRLEN];
13959
13960 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
13961 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
13962
13963 /* Network configuration. */
13964 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
13965 if ((bgp_static = rn->info) != NULL)
13966 {
13967 p = &rn->p;
13968
13969 /* "address-family" display. */
13970 bgp_config_write_family_header (vty, afi, safi, write);
13971
13972 /* "network" configuration display. */
13973 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
13974 {
13975 u_int32_t destination;
13976 struct in_addr netmask;
13977
13978 destination = ntohl (p->u.prefix4.s_addr);
13979 masklen2ip (p->prefixlen, &netmask);
13980 vty_out (vty, " network %s",
13981 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
13982
13983 if ((IN_CLASSC (destination) && p->prefixlen == 24)
13984 || (IN_CLASSB (destination) && p->prefixlen == 16)
13985 || (IN_CLASSA (destination) && p->prefixlen == 8)
13986 || p->u.prefix4.s_addr == 0)
13987 {
13988 /* Natural mask is not display. */
13989 }
13990 else
13991 vty_out (vty, " mask %s", inet_ntoa (netmask));
13992 }
13993 else
13994 {
13995 vty_out (vty, " network %s/%d",
13996 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13997 p->prefixlen);
13998 }
13999
14000 if (bgp_static->rmap.name)
14001 vty_out (vty, " route-map %s", bgp_static->rmap.name);
41367172
PJ
14002 else
14003 {
14004 if (bgp_static->backdoor)
14005 vty_out (vty, " backdoor");
41367172 14006 }
718e3744 14007
14008 vty_out (vty, "%s", VTY_NEWLINE);
14009 }
14010
14011 /* Aggregate-address configuration. */
14012 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
14013 if ((bgp_aggregate = rn->info) != NULL)
14014 {
14015 p = &rn->p;
14016
14017 /* "address-family" display. */
14018 bgp_config_write_family_header (vty, afi, safi, write);
14019
14020 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14021 {
14022 struct in_addr netmask;
14023
14024 masklen2ip (p->prefixlen, &netmask);
14025 vty_out (vty, " aggregate-address %s %s",
14026 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14027 inet_ntoa (netmask));
14028 }
14029 else
14030 {
14031 vty_out (vty, " aggregate-address %s/%d",
14032 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14033 p->prefixlen);
14034 }
14035
14036 if (bgp_aggregate->as_set)
14037 vty_out (vty, " as-set");
14038
14039 if (bgp_aggregate->summary_only)
14040 vty_out (vty, " summary-only");
14041
14042 vty_out (vty, "%s", VTY_NEWLINE);
14043 }
14044
14045 return 0;
14046}
14047
14048int
14049bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
14050{
14051 struct bgp_node *rn;
14052 struct bgp_distance *bdistance;
14053
14054 /* Distance configuration. */
14055 if (bgp->distance_ebgp
14056 && bgp->distance_ibgp
14057 && bgp->distance_local
14058 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
14059 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
14060 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
14061 vty_out (vty, " distance bgp %d %d %d%s",
14062 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
14063 VTY_NEWLINE);
14064
14065 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
14066 if ((bdistance = rn->info) != NULL)
14067 {
14068 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
14069 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
14070 bdistance->access_list ? bdistance->access_list : "",
14071 VTY_NEWLINE);
14072 }
14073
14074 return 0;
14075}
14076
14077/* Allocate routing table structure and install commands. */
14078void
66e5cd87 14079bgp_route_init (void)
718e3744 14080{
14081 /* Init BGP distance table. */
64e580a7 14082 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
718e3744 14083
14084 /* IPv4 BGP commands. */
73ac8160 14085 install_element (BGP_NODE, &bgp_table_map_cmd);
718e3744 14086 install_element (BGP_NODE, &bgp_network_cmd);
14087 install_element (BGP_NODE, &bgp_network_mask_cmd);
14088 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
14089 install_element (BGP_NODE, &bgp_network_route_map_cmd);
14090 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
14091 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
14092 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
14093 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
14094 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
73ac8160 14095 install_element (BGP_NODE, &no_bgp_table_map_cmd);
718e3744 14096 install_element (BGP_NODE, &no_bgp_network_cmd);
14097 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
14098 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
14099 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
14100 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
14101 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14102 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
14103 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
14104 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
14105
14106 install_element (BGP_NODE, &aggregate_address_cmd);
14107 install_element (BGP_NODE, &aggregate_address_mask_cmd);
14108 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
14109 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
14110 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
14111 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
14112 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
14113 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
14114 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
14115 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
14116 install_element (BGP_NODE, &no_aggregate_address_cmd);
14117 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
14118 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
14119 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
14120 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
14121 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
14122 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
14123 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
14124 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14125 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14126
14127 /* IPv4 unicast configuration. */
73ac8160 14128 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
718e3744 14129 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
14130 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
14131 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
14132 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
14133 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
14134 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 14135 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
c8f3fe30 14136 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
718e3744 14137 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
14138 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
14139 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
14140 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
14141 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
c8f3fe30 14142
718e3744 14143 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
14144 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
14145 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
14146 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
14147 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
14148 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
14149 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
14150 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
14151 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
14152 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
14153 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
14154 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
14155 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
14156 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
14157 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
14158 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
14159 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
14160 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
14161 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14162 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14163
14164 /* IPv4 multicast configuration. */
73ac8160 14165 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
718e3744 14166 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
14167 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
14168 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
14169 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
14170 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
14171 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
73ac8160 14172 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
718e3744 14173 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
14174 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
14175 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
14176 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
14177 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
14178 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14179 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
14180 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
14181 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
14182 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
14183 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
14184 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
14185 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
14186 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
14187 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
14188 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
14189 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
14190 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
14191 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
14192 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
14193 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
14194 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
14195 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
14196 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
14197 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14198 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14199
14200 install_element (VIEW_NODE, &show_ip_bgp_cmd);
47fc97cc 14201 install_element (VIEW_NODE, &show_ip_bgp_csv_cmd);
718e3744 14202 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 14203 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
47fc97cc 14204 install_element (VIEW_NODE, &show_bgp_ipv4_safi_csv_cmd);
718e3744 14205 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
14206 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
14207 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 14208 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 14209 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 14210 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14211 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14212 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
14213 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
14214 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14215 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 14216 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 14217 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
718e3744 14218 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14219 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14220 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
14221 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
14222 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
14223 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
14224 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14225 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
14226 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14227 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
14228 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14229 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
14230 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14231 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
14232 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14233 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
14234 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14235 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
14236 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
14237 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
14238 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
14239 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
14240 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
14241 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
14242 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
14243 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
14244 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
14245 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
14246 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
14247 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
718e3744 14248 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
14249 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
14250 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
14251 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
14252 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14253 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14254 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14255 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14256 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
14257 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14258 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
14259 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14260 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
14261 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14262 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
0b16f239 14263 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
47fc97cc 14264 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_csv_cmd);
0b16f239 14265 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_csv_rmap_cmd);
718e3744 14266 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
0b16f239 14267 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
718e3744 14268 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
0b16f239 14269 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
718e3744 14270 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
0b16f239 14271 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
95cbbd2a 14272 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 14273 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
47fc97cc 14274 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_csv_cmd);
718e3744 14275 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14276 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14277 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14278 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
14279 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
14280 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
14281 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
14282 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14283 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
14284 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
14285 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14286 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14287 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
14288 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
14289 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
fee0f4c6 14290 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
95cbbd2a 14291 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
fee0f4c6 14292 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 14293 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
fee0f4c6 14294 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 14295 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
2a71e9ce
TP
14296 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
14297 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
fee0f4c6 14298 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
95cbbd2a 14299 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
fee0f4c6 14300 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 14301 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
fee0f4c6 14302 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 14303 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
62687ff1
PJ
14304
14305 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
14306 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
14307 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
14308 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
62687ff1 14309 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 14310 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
62687ff1
PJ
14311 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14312 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
14313 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
14314 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14315 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 14316 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 14317 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
62687ff1
PJ
14318 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14319 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14320 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
14321 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
14322 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
14323 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
14324 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
14325 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
14326 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
14327 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
14328 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
14329 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
14330 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
14331 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
14332 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
14333 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
14334 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
62687ff1
PJ
14335 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
14336 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
14337 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
14338 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
14339 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14340 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14341 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14342 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14343 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 14344 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
62687ff1 14345 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 14346 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
62687ff1 14347 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 14348 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
62687ff1 14349 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 14350 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
718e3744 14351
14352 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
47fc97cc 14353 install_element (ENABLE_NODE, &show_ip_bgp_csv_cmd);
718e3744 14354 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 14355 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
47fc97cc 14356 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_csv_cmd);
718e3744 14357 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
4092b06c
DS
14358 install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd);
14359 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
718e3744 14360 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 14361 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 14362 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14363 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14364 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
14365 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
4092b06c
DS
14366 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14367 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
95cbbd2a 14368 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
4092b06c 14369 install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd);
718e3744 14370 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14371 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14372 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
14373 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
14374 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
14375 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
14376 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14377 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
14378 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14379 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
14380 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14381 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
14382 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14383 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
14384 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14385 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
14386 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14387 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
14388 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
14389 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
14390 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
14391 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
14392 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
14393 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
14394 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
14395 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
14396 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
14397 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
14398 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
14399 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
718e3744 14400 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
14401 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
14402 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
14403 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
14404 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14405 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14406 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14407 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14408 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
14409 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14410 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
14411 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14412 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
14413 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14414 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
47fc97cc 14415 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_csv_cmd);
0b16f239
DS
14416 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
14417 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_csv_rmap_cmd);
718e3744 14418 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
0b16f239 14419 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
718e3744 14420 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
0b16f239 14421 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
718e3744 14422 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
0b16f239 14423 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
95cbbd2a 14424 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 14425 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
47fc97cc 14426 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_csv_cmd);
718e3744 14427 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14428 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14429 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14430 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
14431 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
14432 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
14433 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
14434 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14435 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
14436 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
14437 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14438 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14439 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
14440 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
14441 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
fee0f4c6 14442 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
95cbbd2a 14443 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
fee0f4c6 14444 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 14445 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
fee0f4c6 14446 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 14447 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
2a71e9ce
TP
14448 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
14449 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
fee0f4c6 14450 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
95cbbd2a 14451 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
fee0f4c6 14452 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 14453 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
fee0f4c6 14454 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 14455 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
718e3744 14456
14457 /* BGP dampening clear commands */
14458 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
14459 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
14460 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
14461 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
14462
ff7924f6
PJ
14463 /* prefix count */
14464 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
14465 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
14466 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
718e3744 14467#ifdef HAVE_IPV6
ff7924f6
PJ
14468 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
14469
718e3744 14470 /* New config IPv6 BGP commands. */
73ac8160 14471 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
718e3744 14472 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
14473 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
73ac8160 14474 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
718e3744 14475 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
14476 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
14477
14478 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
14479 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
14480 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
14481 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
73bfe0bd
B
14482
14483 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
14484 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
718e3744 14485
14486 /* Old config IPv6 BGP commands. */
14487 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
14488 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
14489
14490 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
14491 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
14492 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
14493 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
14494
14495 install_element (VIEW_NODE, &show_bgp_cmd);
14496 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 14497 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
47fc97cc 14498 install_element (VIEW_NODE, &show_bgp_ipv6_safi_csv_cmd);
718e3744 14499 install_element (VIEW_NODE, &show_bgp_route_cmd);
14500 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 14501 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
14502 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
14503 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14504 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 14505 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
14506 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 14507 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c
DS
14508 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
14509 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14510 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 14511 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
14512 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
14513 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
14514 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
14515 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
14516 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
14517 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
14518 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
14519 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
14520 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
14521 install_element (VIEW_NODE, &show_bgp_community_cmd);
14522 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
14523 install_element (VIEW_NODE, &show_bgp_community2_cmd);
14524 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
14525 install_element (VIEW_NODE, &show_bgp_community3_cmd);
14526 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
14527 install_element (VIEW_NODE, &show_bgp_community4_cmd);
14528 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
14529 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
14530 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
14531 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
14532 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
14533 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
14534 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
14535 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
14536 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
14537 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
14538 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
14539 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
14540 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14541 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
14542 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14543 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
14544 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
47fc97cc
DS
14545 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_csv_cmd);
14546 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_csv_cmd);
718e3744 14547 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
14548 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14549 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
14550 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
47fc97cc
DS
14551 install_element (VIEW_NODE, &show_bgp_neighbor_routes_csv_cmd);
14552 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_csv_cmd);
718e3744 14553 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14554 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 14555 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
14556 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14557 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
14558 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
fee0f4c6 14559 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
95cbbd2a 14560 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
fee0f4c6 14561 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 14562 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
fee0f4c6 14563 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 14564 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
bb46e94f 14565 install_element (VIEW_NODE, &show_bgp_view_cmd);
14566 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
14567 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
14568 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
14569 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
14570 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
14571 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
14572 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
47fc97cc
DS
14573 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_csv_cmd);
14574 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_csv_cmd);
bb46e94f 14575 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
14576 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
14577 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
47fc97cc 14578 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_csv_cmd);
bb46e94f 14579 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
14580 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
14581 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
14582 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
14583 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
14584 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
14585 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
fee0f4c6 14586 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
95cbbd2a 14587 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
fee0f4c6 14588 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 14589 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
fee0f4c6 14590 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 14591 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
62687ff1
PJ
14592
14593 /* Restricted:
14594 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
14595 */
14596 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
14597 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 14598 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
14599 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
14600 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14601 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
62687ff1
PJ
14602 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
14603 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 14604 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
4092b06c
DS
14605 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
14606 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14607 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
62687ff1
PJ
14608 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
14609 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
14610 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
14611 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
14612 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
14613 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
14614 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
14615 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
14616 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
14617 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
14618 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
14619 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
14620 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
14621 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
14622 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
14623 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
14624 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 14625 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
62687ff1 14626 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 14627 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
62687ff1
PJ
14628 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
14629 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
14630 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
14631 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
14632 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
14633 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
14634 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 14635 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
62687ff1 14636 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 14637 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
718e3744 14638
14639 install_element (ENABLE_NODE, &show_bgp_cmd);
14640 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 14641 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
47fc97cc 14642 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_csv_cmd);
718e3744 14643 install_element (ENABLE_NODE, &show_bgp_route_cmd);
14644 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 14645 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
4092b06c
DS
14646 install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd);
14647 install_element (ENABLE_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14648 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
718e3744 14649 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
4092b06c
DS
14650 install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd);
14651 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14652 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
718e3744 14653 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 14654 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
718e3744 14655 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
14656 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
14657 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
14658 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
14659 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
14660 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
14661 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
14662 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
14663 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
14664 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
14665 install_element (ENABLE_NODE, &show_bgp_community_cmd);
14666 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
14667 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
14668 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
14669 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
14670 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
14671 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
14672 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
14673 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
14674 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
14675 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
14676 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
14677 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
14678 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
14679 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
14680 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
14681 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
14682 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
14683 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
14684 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14685 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
14686 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14687 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
14688 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
47fc97cc
DS
14689 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_csv_cmd);
14690 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_csv_cmd);
718e3744 14691 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
14692 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14693 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
14694 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
47fc97cc
DS
14695 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_csv_cmd);
14696 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_csv_cmd);
718e3744 14697 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14698 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 14699 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
14700 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14701 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
14702 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
fee0f4c6 14703 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
95cbbd2a 14704 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
fee0f4c6 14705 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 14706 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
fee0f4c6 14707 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 14708 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
bb46e94f 14709 install_element (ENABLE_NODE, &show_bgp_view_cmd);
14710 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
14711 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
14712 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
14713 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
14714 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
14715 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
14716 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
47fc97cc
DS
14717 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_csv_cmd);
14718 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_csv_cmd);
bb46e94f 14719 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
14720 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
14721 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
47fc97cc 14722 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_csv_cmd);
bb46e94f 14723 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
14724 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
14725 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
14726 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
14727 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
14728 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
14729 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
fee0f4c6 14730 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
95cbbd2a 14731 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
fee0f4c6 14732 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 14733 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
fee0f4c6 14734 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 14735 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
2815e61f
PJ
14736
14737 /* Statistics */
14738 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
14739 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
14740 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
14741 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
14742
718e3744 14743 /* old command */
14744 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
14745 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
14746 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
14747 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
14748 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
14749 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
14750 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
14751 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
14752 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
14753 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
14754 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
14755 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
14756 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
14757 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
14758 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
14759 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
14760 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14761 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14762 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
14763 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
14764 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
14765 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
14766 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14767 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
14768 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
14769 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
14770 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
14771 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
14772 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
14773 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
14774 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14775 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14776 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
14777 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
14778 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
14779 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
bb46e94f 14780
718e3744 14781 /* old command */
14782 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
14783 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
14784 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
14785 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
14786 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
14787 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
14788 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
14789 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
14790 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
14791 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
14792 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
14793 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
14794 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
14795 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
14796 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
14797 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
14798 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14799 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14800 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
14801 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
14802 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
14803 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
14804 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14805 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
14806 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
14807 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
14808 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
14809 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
14810 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
14811 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
14812 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14813 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14814 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
14815 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
14816 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
14817 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
14818
14819 /* old command */
14820 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14821 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14822 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14823 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14824
14825 /* old command */
14826 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14827 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14828 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14829 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14830
14831 /* old command */
14832 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
14833 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
14834 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14835 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14836#endif /* HAVE_IPV6 */
14837
14838 install_element (BGP_NODE, &bgp_distance_cmd);
14839 install_element (BGP_NODE, &no_bgp_distance_cmd);
14840 install_element (BGP_NODE, &no_bgp_distance2_cmd);
14841 install_element (BGP_NODE, &bgp_distance_source_cmd);
14842 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
14843 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
14844 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
14845
14846 install_element (BGP_NODE, &bgp_damp_set_cmd);
14847 install_element (BGP_NODE, &bgp_damp_set2_cmd);
14848 install_element (BGP_NODE, &bgp_damp_set3_cmd);
14849 install_element (BGP_NODE, &bgp_damp_unset_cmd);
14850 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
14851 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
14852 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
14853 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
14854 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
14855 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
c8f3fe30
PJ
14856
14857 /* Deprecated AS-Pathlimit commands */
14858 install_element (BGP_NODE, &bgp_network_ttl_cmd);
14859 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
14860 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
14861 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
14862 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
14863 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
14864
14865 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
14866 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
14867 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
14868 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
14869 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
14870 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
14871
14872 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
14873 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
14874 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
14875 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
14876 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
14877 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
14878
14879 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
14880 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
14881 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
14882 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
14883 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
14884 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
14885
14886 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
14887 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
14888 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
14889 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
14890 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
14891 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
14892
14893 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
14894 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
14895 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
14896 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
14897 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
14898 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
3bde17f1
PJ
14899
14900#ifdef HAVE_IPV6
c8f3fe30
PJ
14901 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
14902 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
3bde17f1 14903#endif
718e3744 14904}
228da428
CC
14905
14906void
14907bgp_route_finish (void)
14908{
14909 bgp_table_unlock (bgp_distance_table);
14910 bgp_distance_table = NULL;
14911}