]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_route.c
Patch to produce output of BGP commands in csv format. Useful for easier scripting.
[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"
718e3744 37
38#include "bgpd/bgpd.h"
39#include "bgpd/bgp_table.h"
40#include "bgpd/bgp_route.h"
41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_debug.h"
43#include "bgpd/bgp_aspath.h"
44#include "bgpd/bgp_regex.h"
45#include "bgpd/bgp_community.h"
46#include "bgpd/bgp_ecommunity.h"
47#include "bgpd/bgp_clist.h"
48#include "bgpd/bgp_packet.h"
49#include "bgpd/bgp_filter.h"
50#include "bgpd/bgp_fsm.h"
51#include "bgpd/bgp_mplsvpn.h"
52#include "bgpd/bgp_nexthop.h"
53#include "bgpd/bgp_damp.h"
54#include "bgpd/bgp_advertise.h"
55#include "bgpd/bgp_zebra.h"
0a486e5f 56#include "bgpd/bgp_vty.h"
96450faf 57#include "bgpd/bgp_mpath.h"
fb018d25 58#include "bgpd/bgp_nht.c"
718e3744 59
60/* Extern from bgp_dump.c */
dde72586
SH
61extern const char *bgp_origin_str[];
62extern const char *bgp_origin_long_str[];
47fc97cc 63char csv = ',';
6b0655a2 64
94f2b392 65static struct bgp_node *
fee0f4c6 66bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
718e3744 67 struct prefix_rd *prd)
68{
69 struct bgp_node *rn;
70 struct bgp_node *prn = NULL;
da5b30f6
PJ
71
72 assert (table);
73 if (!table)
74 return NULL;
75
718e3744 76 if (safi == SAFI_MPLS_VPN)
77 {
fee0f4c6 78 prn = bgp_node_get (table, (struct prefix *) prd);
718e3744 79
80 if (prn->info == NULL)
64e580a7 81 prn->info = bgp_table_init (afi, safi);
718e3744 82 else
83 bgp_unlock_node (prn);
84 table = prn->info;
85 }
718e3744 86
87 rn = bgp_node_get (table, p);
88
89 if (safi == SAFI_MPLS_VPN)
90 rn->prn = prn;
91
92 return rn;
93}
6b0655a2 94
fb982c25
PJ
95/* Allocate bgp_info_extra */
96static struct bgp_info_extra *
97bgp_info_extra_new (void)
98{
99 struct bgp_info_extra *new;
100 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
101 return new;
102}
103
104static void
105bgp_info_extra_free (struct bgp_info_extra **extra)
106{
107 if (extra && *extra)
108 {
109 if ((*extra)->damp_info)
110 bgp_damp_info_free ((*extra)->damp_info, 0);
111
112 (*extra)->damp_info = NULL;
113
114 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
115
116 *extra = NULL;
117 }
118}
119
120/* Get bgp_info extra information for the given bgp_info, lazy allocated
121 * if required.
122 */
123struct bgp_info_extra *
124bgp_info_extra_get (struct bgp_info *ri)
125{
126 if (!ri->extra)
127 ri->extra = bgp_info_extra_new();
128 return ri->extra;
129}
130
718e3744 131/* Free bgp route information. */
200df115 132static void
718e3744 133bgp_info_free (struct bgp_info *binfo)
134{
135 if (binfo->attr)
f6f434b2 136 bgp_attr_unintern (&binfo->attr);
fb018d25
DS
137
138 bgp_unlink_nexthop(binfo);
fb982c25 139 bgp_info_extra_free (&binfo->extra);
de8d5dff 140 bgp_info_mpath_free (&binfo->mpath);
718e3744 141
200df115 142 peer_unlock (binfo->peer); /* bgp_info peer reference */
143
718e3744 144 XFREE (MTYPE_BGP_ROUTE, binfo);
145}
146
200df115 147struct bgp_info *
148bgp_info_lock (struct bgp_info *binfo)
149{
150 binfo->lock++;
151 return binfo;
152}
153
154struct bgp_info *
155bgp_info_unlock (struct bgp_info *binfo)
156{
157 assert (binfo && binfo->lock > 0);
158 binfo->lock--;
159
160 if (binfo->lock == 0)
161 {
162#if 0
163 zlog_debug ("%s: unlocked and freeing", __func__);
164 zlog_backtrace (LOG_DEBUG);
165#endif
166 bgp_info_free (binfo);
167 return NULL;
168 }
169
170#if 0
171 if (binfo->lock == 1)
172 {
173 zlog_debug ("%s: unlocked to 1", __func__);
174 zlog_backtrace (LOG_DEBUG);
175 }
176#endif
177
178 return binfo;
179}
180
718e3744 181void
182bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
183{
184 struct bgp_info *top;
185
186 top = rn->info;
200df115 187
718e3744 188 ri->next = rn->info;
189 ri->prev = NULL;
190 if (top)
191 top->prev = ri;
192 rn->info = ri;
200df115 193
194 bgp_info_lock (ri);
195 bgp_lock_node (rn);
196 peer_lock (ri->peer); /* bgp_info peer reference */
718e3744 197}
198
b40d939b 199/* Do the actual removal of info from RIB, for use by bgp_process
200 completion callback *only* */
201static void
202bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
718e3744 203{
204 if (ri->next)
205 ri->next->prev = ri->prev;
206 if (ri->prev)
207 ri->prev->next = ri->next;
208 else
209 rn->info = ri->next;
200df115 210
de8d5dff 211 bgp_info_mpath_dequeue (ri);
200df115 212 bgp_info_unlock (ri);
213 bgp_unlock_node (rn);
718e3744 214}
215
b40d939b 216void
217bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
218{
1a392d46
PJ
219 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
220 /* set of previous already took care of pcount */
b40d939b 221 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
222}
223
8d45210e
AS
224/* undo the effects of a previous call to bgp_info_delete; typically
225 called when a route is deleted and then quickly re-added before the
226 deletion has been processed */
227static void
228bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
229{
230 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
231 /* unset of previous already took care of pcount */
232 SET_FLAG (ri->flags, BGP_INFO_VALID);
233}
234
1a392d46
PJ
235/* Adjust pcount as required */
236static void
237bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
238{
67174041
AS
239 struct bgp_table *table;
240
241 assert (rn && bgp_node_table (rn));
6f58544d
PJ
242 assert (ri && ri->peer && ri->peer->bgp);
243
67174041
AS
244 table = bgp_node_table (rn);
245
1a392d46 246 /* Ignore 'pcount' for RS-client tables */
67174041 247 if (table->type != BGP_TABLE_MAIN
1a392d46
PJ
248 || ri->peer == ri->peer->bgp->peer_self)
249 return;
250
251 if (BGP_INFO_HOLDDOWN (ri)
252 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
253 {
254
255 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
256
257 /* slight hack, but more robust against errors. */
67174041
AS
258 if (ri->peer->pcount[table->afi][table->safi])
259 ri->peer->pcount[table->afi][table->safi]--;
1a392d46
PJ
260 else
261 {
262 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
263 __func__, ri->peer->host);
264 zlog_backtrace (LOG_WARNING);
265 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
266 }
267 }
268 else if (!BGP_INFO_HOLDDOWN (ri)
269 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
270 {
271 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
67174041 272 ri->peer->pcount[table->afi][table->safi]++;
1a392d46
PJ
273 }
274}
275
276
277/* Set/unset bgp_info flags, adjusting any other state as needed.
278 * This is here primarily to keep prefix-count in check.
279 */
280void
281bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
282{
283 SET_FLAG (ri->flags, flag);
284
285 /* early bath if we know it's not a flag that changes useability state */
286 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
287 return;
288
289 bgp_pcount_adjust (rn, ri);
290}
291
292void
293bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
294{
295 UNSET_FLAG (ri->flags, flag);
296
297 /* early bath if we know it's not a flag that changes useability state */
298 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
299 return;
300
301 bgp_pcount_adjust (rn, ri);
302}
303
718e3744 304/* Get MED value. If MED value is missing and "bgp bestpath
305 missing-as-worst" is specified, treat it as the worst value. */
94f2b392 306static u_int32_t
718e3744 307bgp_med_value (struct attr *attr, struct bgp *bgp)
308{
309 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
310 return attr->med;
311 else
312 {
313 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
3b424979 314 return BGP_MED_MAX;
718e3744 315 else
316 return 0;
317 }
318}
319
320/* Compare two bgp route entity. br is preferable then return 1. */
94f2b392 321static int
96450faf 322bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
5e242b0d 323 int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg)
718e3744 324{
8ff56318
JBD
325 struct attr *newattr, *existattr;
326 struct attr_extra *newattre, *existattre;
327 bgp_peer_sort_t new_sort;
328 bgp_peer_sort_t exist_sort;
718e3744 329 u_int32_t new_pref;
330 u_int32_t exist_pref;
331 u_int32_t new_med;
332 u_int32_t exist_med;
8ff56318
JBD
333 u_int32_t new_weight;
334 u_int32_t exist_weight;
335 uint32_t newm, existm;
718e3744 336 struct in_addr new_id;
337 struct in_addr exist_id;
338 int new_cluster;
339 int exist_cluster;
8ff56318
JBD
340 int internal_as_route;
341 int confed_as_route;
718e3744 342 int ret;
96450faf
JB
343
344 *paths_eq = 0;
718e3744 345
346 /* 0. Null check. */
347 if (new == NULL)
348 return 0;
349 if (exist == NULL)
350 return 1;
351
8ff56318
JBD
352 newattr = new->attr;
353 existattr = exist->attr;
354 newattre = newattr->extra;
355 existattre = existattr->extra;
356
718e3744 357 /* 1. Weight check. */
8ff56318
JBD
358 new_weight = exist_weight = 0;
359
360 if (newattre)
361 new_weight = newattre->weight;
362 if (existattre)
363 exist_weight = existattre->weight;
364
fb982c25 365 if (new_weight > exist_weight)
718e3744 366 return 1;
fb982c25 367 if (new_weight < exist_weight)
718e3744 368 return 0;
369
370 /* 2. Local preference check. */
8ff56318
JBD
371 new_pref = exist_pref = bgp->default_local_pref;
372
373 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
374 new_pref = newattr->local_pref;
375 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
376 exist_pref = existattr->local_pref;
718e3744 377
718e3744 378 if (new_pref > exist_pref)
379 return 1;
380 if (new_pref < exist_pref)
381 return 0;
382
8ff56318
JBD
383 /* 3. Local route check. We prefer:
384 * - BGP_ROUTE_STATIC
385 * - BGP_ROUTE_AGGREGATE
386 * - BGP_ROUTE_REDISTRIBUTE
387 */
388 if (! (new->sub_type == BGP_ROUTE_NORMAL))
389 return 1;
390 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
391 return 0;
718e3744 392
393 /* 4. AS path length check. */
394 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
395 {
8ff56318
JBD
396 int exist_hops = aspath_count_hops (existattr->aspath);
397 int exist_confeds = aspath_count_confeds (existattr->aspath);
fe69a505 398
6811845b 399 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
400 {
fe69a505 401 int aspath_hops;
402
8ff56318
JBD
403 aspath_hops = aspath_count_hops (newattr->aspath);
404 aspath_hops += aspath_count_confeds (newattr->aspath);
fe69a505 405
406 if ( aspath_hops < (exist_hops + exist_confeds))
6811845b 407 return 1;
fe69a505 408 if ( aspath_hops > (exist_hops + exist_confeds))
6811845b 409 return 0;
410 }
411 else
412 {
8ff56318 413 int newhops = aspath_count_hops (newattr->aspath);
fe69a505 414
415 if (newhops < exist_hops)
6811845b 416 return 1;
fe69a505 417 if (newhops > exist_hops)
6811845b 418 return 0;
419 }
718e3744 420 }
421
422 /* 5. Origin check. */
8ff56318 423 if (newattr->origin < existattr->origin)
718e3744 424 return 1;
8ff56318 425 if (newattr->origin > existattr->origin)
718e3744 426 return 0;
427
428 /* 6. MED check. */
8ff56318
JBD
429 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
430 && aspath_count_hops (existattr->aspath) == 0);
431 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
432 && aspath_count_confeds (existattr->aspath) > 0
433 && aspath_count_hops (newattr->aspath) == 0
434 && aspath_count_hops (existattr->aspath) == 0);
718e3744 435
436 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
437 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
438 && confed_as_route)
8ff56318
JBD
439 || aspath_cmp_left (newattr->aspath, existattr->aspath)
440 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
718e3744 441 || internal_as_route)
442 {
443 new_med = bgp_med_value (new->attr, bgp);
444 exist_med = bgp_med_value (exist->attr, bgp);
445
446 if (new_med < exist_med)
447 return 1;
448 if (new_med > exist_med)
449 return 0;
450 }
451
452 /* 7. Peer type check. */
8ff56318
JBD
453 new_sort = new->peer->sort;
454 exist_sort = exist->peer->sort;
455
456 if (new_sort == BGP_PEER_EBGP
457 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
718e3744 458 return 1;
8ff56318
JBD
459 if (exist_sort == BGP_PEER_EBGP
460 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
718e3744 461 return 0;
462
463 /* 8. IGP metric check. */
8ff56318
JBD
464 newm = existm = 0;
465
466 if (new->extra)
467 newm = new->extra->igpmetric;
468 if (exist->extra)
469 existm = exist->extra->igpmetric;
470
96450faf
JB
471 if (newm < existm)
472 ret = 1;
473 if (newm > existm)
474 ret = 0;
718e3744 475
5e242b0d
DS
476 /* 8.1. Same IGP metric. Compare the cluster list length as
477 representative of IGP hops metric. Rewrite the metric value
478 pair (newm, existm) with the cluster list length. Prefer the
479 path with smaller cluster list length. */
480 if (newm == existm)
481 {
482 if (peer_sort (new->peer) == BGP_PEER_IBGP
483 && peer_sort (exist->peer) == BGP_PEER_IBGP
484 && CHECK_FLAG (mpath_cfg->ibgp_flags,
485 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
486 {
487 newm = BGP_CLUSTER_LIST_LENGTH(new->attr);
488 existm = BGP_CLUSTER_LIST_LENGTH(exist->attr);
489 if (newm < existm)
490 ret = 1;
491 if (newm > existm)
492 ret = 0;
493 }
494 }
495
718e3744 496 /* 9. Maximum path check. */
96450faf
JB
497 if (newm == existm)
498 {
2fdd455c
PM
499 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
500 {
501
502 /*
503 * For the two paths, all comparison steps till IGP metric
504 * have succeeded - including AS_PATH hop count. Since 'bgp
505 * bestpath as-path multipath-relax' knob is on, we don't need
506 * an exact match of AS_PATH. Thus, mark the paths are equal.
507 * That will trigger both these paths to get into the multipath
508 * array.
509 */
510 *paths_eq = 1;
511 }
512 else if (new->peer->sort == BGP_PEER_IBGP)
96450faf
JB
513 {
514 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
515 *paths_eq = 1;
516 }
517 else if (new->peer->as == exist->peer->as)
518 *paths_eq = 1;
519 }
520 else
521 {
522 /*
523 * TODO: If unequal cost ibgp multipath is enabled we can
524 * mark the paths as equal here instead of returning
525 */
526 return ret;
527 }
718e3744 528
529 /* 10. If both paths are external, prefer the path that was received
530 first (the oldest one). This step minimizes route-flap, since a
531 newer path won't displace an older one, even if it was the
532 preferred route based on the additional decision criteria below. */
533 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
8ff56318
JBD
534 && new_sort == BGP_PEER_EBGP
535 && exist_sort == BGP_PEER_EBGP)
718e3744 536 {
537 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
538 return 1;
539 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
540 return 0;
541 }
542
543 /* 11. Rourter-ID comparision. */
8ff56318
JBD
544 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
545 new_id.s_addr = newattre->originator_id.s_addr;
718e3744 546 else
547 new_id.s_addr = new->peer->remote_id.s_addr;
8ff56318
JBD
548 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
549 exist_id.s_addr = existattre->originator_id.s_addr;
718e3744 550 else
551 exist_id.s_addr = exist->peer->remote_id.s_addr;
552
553 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
554 return 1;
555 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
556 return 0;
557
558 /* 12. Cluster length comparision. */
5e242b0d
DS
559 new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
560 exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
718e3744 561
562 if (new_cluster < exist_cluster)
563 return 1;
564 if (new_cluster > exist_cluster)
565 return 0;
566
567 /* 13. Neighbor address comparision. */
568 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
569
570 if (ret == 1)
571 return 0;
572 if (ret == -1)
573 return 1;
574
575 return 1;
576}
577
94f2b392 578static enum filter_type
718e3744 579bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
580 afi_t afi, safi_t safi)
581{
582 struct bgp_filter *filter;
583
584 filter = &peer->filter[afi][safi];
585
650f76c2
PJ
586#define FILTER_EXIST_WARN(F,f,filter) \
587 if (BGP_DEBUG (update, UPDATE_IN) \
588 && !(F ## _IN (filter))) \
589 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
590 peer->host, #f, F ## _IN_NAME(filter));
591
592 if (DISTRIBUTE_IN_NAME (filter)) {
593 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
594
718e3744 595 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
596 return FILTER_DENY;
650f76c2 597 }
718e3744 598
650f76c2
PJ
599 if (PREFIX_LIST_IN_NAME (filter)) {
600 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
601
718e3744 602 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
603 return FILTER_DENY;
650f76c2 604 }
718e3744 605
650f76c2
PJ
606 if (FILTER_LIST_IN_NAME (filter)) {
607 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
608
718e3744 609 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
610 return FILTER_DENY;
650f76c2
PJ
611 }
612
718e3744 613 return FILTER_PERMIT;
650f76c2 614#undef FILTER_EXIST_WARN
718e3744 615}
616
94f2b392 617static enum filter_type
718e3744 618bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
619 afi_t afi, safi_t safi)
620{
621 struct bgp_filter *filter;
622
623 filter = &peer->filter[afi][safi];
624
650f76c2
PJ
625#define FILTER_EXIST_WARN(F,f,filter) \
626 if (BGP_DEBUG (update, UPDATE_OUT) \
627 && !(F ## _OUT (filter))) \
628 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
629 peer->host, #f, F ## _OUT_NAME(filter));
630
631 if (DISTRIBUTE_OUT_NAME (filter)) {
632 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
633
718e3744 634 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
635 return FILTER_DENY;
650f76c2 636 }
718e3744 637
650f76c2
PJ
638 if (PREFIX_LIST_OUT_NAME (filter)) {
639 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
640
718e3744 641 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
642 return FILTER_DENY;
650f76c2 643 }
718e3744 644
650f76c2
PJ
645 if (FILTER_LIST_OUT_NAME (filter)) {
646 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
647
718e3744 648 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
649 return FILTER_DENY;
650f76c2 650 }
718e3744 651
652 return FILTER_PERMIT;
650f76c2 653#undef FILTER_EXIST_WARN
718e3744 654}
655
656/* If community attribute includes no_export then return 1. */
94f2b392 657static int
718e3744 658bgp_community_filter (struct peer *peer, struct attr *attr)
659{
660 if (attr->community)
661 {
662 /* NO_ADVERTISE check. */
663 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
664 return 1;
665
666 /* NO_EXPORT check. */
6d85b15b 667 if (peer->sort == BGP_PEER_EBGP &&
718e3744 668 community_include (attr->community, COMMUNITY_NO_EXPORT))
669 return 1;
670
671 /* NO_EXPORT_SUBCONFED check. */
6d85b15b
JBD
672 if (peer->sort == BGP_PEER_EBGP
673 || peer->sort == BGP_PEER_CONFED)
718e3744 674 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
675 return 1;
676 }
677 return 0;
678}
679
680/* Route reflection loop check. */
681static int
682bgp_cluster_filter (struct peer *peer, struct attr *attr)
683{
684 struct in_addr cluster_id;
685
fb982c25 686 if (attr->extra && attr->extra->cluster)
718e3744 687 {
688 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
689 cluster_id = peer->bgp->cluster_id;
690 else
691 cluster_id = peer->bgp->router_id;
692
fb982c25 693 if (cluster_loop_check (attr->extra->cluster, cluster_id))
718e3744 694 return 1;
695 }
696 return 0;
697}
6b0655a2 698
94f2b392 699static int
718e3744 700bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
701 afi_t afi, safi_t safi)
702{
703 struct bgp_filter *filter;
704 struct bgp_info info;
705 route_map_result_t ret;
706
707 filter = &peer->filter[afi][safi];
708
709 /* Apply default weight value. */
fb982c25
PJ
710 if (peer->weight)
711 (bgp_attr_extra_get (attr))->weight = peer->weight;
718e3744 712
713 /* Route map apply. */
714 if (ROUTE_MAP_IN_NAME (filter))
715 {
716 /* Duplicate current value to new strucutre for modification. */
717 info.peer = peer;
718 info.attr = attr;
719
ac41b2a2 720 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
721
718e3744 722 /* Apply BGP route map to the attribute. */
723 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
ac41b2a2 724
725 peer->rmap_type = 0;
726
718e3744 727 if (ret == RMAP_DENYMATCH)
c460e572
DL
728 /* caller has multiple error paths with bgp_attr_flush() */
729 return RMAP_DENY;
718e3744 730 }
731 return RMAP_PERMIT;
732}
6b0655a2 733
94f2b392 734static int
fee0f4c6 735bgp_export_modifier (struct peer *rsclient, struct peer *peer,
736 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
737{
738 struct bgp_filter *filter;
739 struct bgp_info info;
740 route_map_result_t ret;
741
742 filter = &peer->filter[afi][safi];
743
744 /* Route map apply. */
745 if (ROUTE_MAP_EXPORT_NAME (filter))
746 {
747 /* Duplicate current value to new strucutre for modification. */
748 info.peer = rsclient;
749 info.attr = attr;
750
751 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
752
753 /* Apply BGP route map to the attribute. */
754 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
755
756 rsclient->rmap_type = 0;
757
758 if (ret == RMAP_DENYMATCH)
759 {
760 /* Free newly generated AS path and community by route-map. */
761 bgp_attr_flush (attr);
762 return RMAP_DENY;
763 }
764 }
765 return RMAP_PERMIT;
766}
767
94f2b392 768static int
fee0f4c6 769bgp_import_modifier (struct peer *rsclient, struct peer *peer,
770 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
771{
772 struct bgp_filter *filter;
773 struct bgp_info info;
774 route_map_result_t ret;
775
776 filter = &rsclient->filter[afi][safi];
777
778 /* Apply default weight value. */
fb982c25
PJ
779 if (peer->weight)
780 (bgp_attr_extra_get (attr))->weight = peer->weight;
fee0f4c6 781
782 /* Route map apply. */
783 if (ROUTE_MAP_IMPORT_NAME (filter))
784 {
785 /* Duplicate current value to new strucutre for modification. */
786 info.peer = peer;
787 info.attr = attr;
788
789 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
790
791 /* Apply BGP route map to the attribute. */
792 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
793
794 peer->rmap_type = 0;
795
796 if (ret == RMAP_DENYMATCH)
797 {
798 /* Free newly generated AS path and community by route-map. */
799 bgp_attr_flush (attr);
800 return RMAP_DENY;
801 }
802 }
803 return RMAP_PERMIT;
804}
6b0655a2 805
94f2b392 806static int
718e3744 807bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
808 struct attr *attr, afi_t afi, safi_t safi)
809{
810 int ret;
811 char buf[SU_ADDRSTRLEN];
812 struct bgp_filter *filter;
718e3744 813 struct peer *from;
814 struct bgp *bgp;
718e3744 815 int transparent;
816 int reflect;
0b597ef0 817 struct attr *riattr;
718e3744 818
819 from = ri->peer;
820 filter = &peer->filter[afi][safi];
821 bgp = peer->bgp;
0b597ef0 822 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
718e3744 823
750e8146
PJ
824 if (DISABLE_BGP_ANNOUNCE)
825 return 0;
718e3744 826
fee0f4c6 827 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
828 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
829 return 0;
830
718e3744 831 /* Do not send back route to sender. */
832 if (from == peer)
833 return 0;
834
835 /* Aggregate-address suppress check. */
fb982c25 836 if (ri->extra && ri->extra->suppress)
718e3744 837 if (! UNSUPPRESS_MAP_NAME (filter))
838 return 0;
839
840 /* Default route check. */
841 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
842 {
843 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
844 return 0;
845#ifdef HAVE_IPV6
846 else if (p->family == AF_INET6 && p->prefixlen == 0)
847 return 0;
848#endif /* HAVE_IPV6 */
849 }
850
286e1e71 851 /* Transparency check. */
852 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
853 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
854 transparent = 1;
855 else
856 transparent = 0;
857
718e3744 858 /* If community is not disabled check the no-export and local. */
0b597ef0 859 if (! transparent && bgp_community_filter (peer, riattr))
718e3744 860 return 0;
861
862 /* If the attribute has originator-id and it is same as remote
863 peer's id. */
0b597ef0 864 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
718e3744 865 {
0b597ef0 866 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
718e3744 867 {
868 if (BGP_DEBUG (filter, FILTER))
d2c1f16b 869 zlog (peer->log, LOG_DEBUG,
718e3744 870 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
871 peer->host,
872 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
873 p->prefixlen);
874 return 0;
875 }
876 }
877
878 /* ORF prefix-list filter check */
879 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
880 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
881 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
882 if (peer->orf_plist[afi][safi])
883 {
884 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
885 return 0;
886 }
887
888 /* Output filter check. */
0b597ef0 889 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
718e3744 890 {
891 if (BGP_DEBUG (filter, FILTER))
d2c1f16b 892 zlog (peer->log, LOG_DEBUG,
718e3744 893 "%s [Update:SEND] %s/%d is filtered",
894 peer->host,
895 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
896 p->prefixlen);
897 return 0;
898 }
899
900#ifdef BGP_SEND_ASPATH_CHECK
901 /* AS path loop check. */
0b597ef0 902 if (aspath_loop_check (riattr->aspath, peer->as))
718e3744 903 {
904 if (BGP_DEBUG (filter, FILTER))
d2c1f16b 905 zlog (peer->log, LOG_DEBUG,
aea339f7 906 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
718e3744 907 peer->host, peer->as);
908 return 0;
909 }
910#endif /* BGP_SEND_ASPATH_CHECK */
911
912 /* If we're a CONFED we need to loop check the CONFED ID too */
913 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
914 {
0b597ef0 915 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
718e3744 916 {
917 if (BGP_DEBUG (filter, FILTER))
d2c1f16b 918 zlog (peer->log, LOG_DEBUG,
aea339f7 919 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
718e3744 920 peer->host,
921 bgp->confed_id);
922 return 0;
923 }
924 }
925
926 /* Route-Reflect check. */
6d85b15b 927 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
718e3744 928 reflect = 1;
929 else
930 reflect = 0;
931
932 /* IBGP reflection check. */
933 if (reflect)
934 {
935 /* A route from a Client peer. */
936 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
937 {
938 /* Reflect to all the Non-Client peers and also to the
939 Client peers other than the originator. Originator check
940 is already done. So there is noting to do. */
941 /* no bgp client-to-client reflection check. */
942 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
943 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
944 return 0;
945 }
946 else
947 {
948 /* A route from a Non-client peer. Reflect to all other
949 clients. */
950 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
951 return 0;
952 }
953 }
41367172 954
718e3744 955 /* For modify attribute, copy it to temporary structure. */
0b597ef0 956 bgp_attr_dup (attr, riattr);
fb982c25 957
718e3744 958 /* If local-preference is not set. */
6d85b15b
JBD
959 if ((peer->sort == BGP_PEER_IBGP
960 || peer->sort == BGP_PEER_CONFED)
718e3744 961 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
962 {
963 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
964 attr->local_pref = bgp->default_local_pref;
965 }
966
689bb66c
PM
967 /* If originator-id is not set and the route is to be reflected,
968 set the originator id */
969 if (peer && from && peer->sort == BGP_PEER_IBGP &&
970 from->sort == BGP_PEER_IBGP &&
971 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
972 {
973 attr->extra = bgp_attr_extra_get(attr);
974 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
975 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
976 }
977
718e3744 978 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
6d85b15b 979 if (peer->sort == BGP_PEER_EBGP
718e3744 980 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
981 {
982 if (ri->peer != bgp->peer_self && ! transparent
983 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
984 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
985 }
986
987 /* next-hop-set */
9e7a53c1
TT
988 if (transparent
989 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
718e3744 990 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
991 && ((p->family == AF_INET && attr->nexthop.s_addr)
286e1e71 992#ifdef HAVE_IPV6
fee0f4c6 993 || (p->family == AF_INET6 &&
fb982c25 994 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
286e1e71 995#endif /* HAVE_IPV6 */
996 )))
718e3744 997 {
998 /* NEXT-HOP Unchanged. */
999 }
1000 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
1001 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
1002#ifdef HAVE_IPV6
fee0f4c6 1003 || (p->family == AF_INET6 &&
fb982c25 1004 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
718e3744 1005#endif /* HAVE_IPV6 */
6d85b15b 1006 || (peer->sort == BGP_PEER_EBGP
718e3744 1007 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
1008 {
1009 /* Set IPv4 nexthop. */
1010 if (p->family == AF_INET)
1011 {
1012 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
1013 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1014 IPV4_MAX_BYTELEN);
718e3744 1015 else
1016 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1017 }
1018#ifdef HAVE_IPV6
1019 /* Set IPv6 nexthop. */
1020 if (p->family == AF_INET6)
1021 {
1022 /* IPv6 global nexthop must be included. */
fb982c25 1023 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
718e3744 1024 IPV6_MAX_BYTELEN);
fb982c25 1025 attr->extra->mp_nexthop_len = 16;
718e3744 1026 }
1027#endif /* HAVE_IPV6 */
1028 }
1029
1030#ifdef HAVE_IPV6
1031 if (p->family == AF_INET6)
1032 {
fee0f4c6 1033 /* Left nexthop_local unchanged if so configured. */
1034 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1035 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1036 {
fb982c25
PJ
1037 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1038 attr->extra->mp_nexthop_len=32;
fee0f4c6 1039 else
fb982c25 1040 attr->extra->mp_nexthop_len=16;
fee0f4c6 1041 }
1042
1043 /* Default nexthop_local treatment for non-RS-Clients */
1044 else
1045 {
718e3744 1046 /* Link-local address should not be transit to different peer. */
fb982c25 1047 attr->extra->mp_nexthop_len = 16;
718e3744 1048
1049 /* Set link-local address for shared network peer. */
1050 if (peer->shared_network
1051 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1052 {
fb982c25 1053 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
718e3744 1054 IPV6_MAX_BYTELEN);
fb982c25 1055 attr->extra->mp_nexthop_len = 32;
718e3744 1056 }
1057
1058 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1059 address.*/
1060 if (reflect)
fb982c25 1061 attr->extra->mp_nexthop_len = 16;
718e3744 1062
1063 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1064 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
fb982c25 1065 attr->extra->mp_nexthop_len = 16;
718e3744 1066 }
fee0f4c6 1067
1068 }
718e3744 1069#endif /* HAVE_IPV6 */
1070
1071 /* If this is EBGP peer and remove-private-AS is set. */
6d85b15b 1072 if (peer->sort == BGP_PEER_EBGP
718e3744 1073 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1074 && aspath_private_as_check (attr->aspath))
1075 attr->aspath = aspath_empty_get ();
1076
1077 /* Route map & unsuppress-map apply. */
1078 if (ROUTE_MAP_OUT_NAME (filter)
fb982c25 1079 || (ri->extra && ri->extra->suppress) )
718e3744 1080 {
7c7fa1b4 1081 struct bgp_info info;
558d1fec
JBD
1082 struct attr dummy_attr;
1083 struct attr_extra dummy_extra;
1084
1085 dummy_attr.extra = &dummy_extra;
1086
718e3744 1087 info.peer = peer;
1088 info.attr = attr;
1089
1090 /* The route reflector is not allowed to modify the attributes
1091 of the reflected IBGP routes. */
6d85b15b
JBD
1092 if (from->sort == BGP_PEER_IBGP
1093 && peer->sort == BGP_PEER_IBGP)
718e3744 1094 {
fb982c25 1095 bgp_attr_dup (&dummy_attr, attr);
9eda90ce 1096 info.attr = &dummy_attr;
718e3744 1097 }
ac41b2a2 1098
1099 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1100
fb982c25 1101 if (ri->extra && ri->extra->suppress)
718e3744 1102 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1103 else
1104 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1105
ac41b2a2 1106 peer->rmap_type = 0;
558d1fec 1107
718e3744 1108 if (ret == RMAP_DENYMATCH)
1109 {
1110 bgp_attr_flush (attr);
1111 return 0;
1112 }
1113 }
1114 return 1;
1115}
1116
94f2b392 1117static int
fee0f4c6 1118bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1119 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
1120{
1121 int ret;
1122 char buf[SU_ADDRSTRLEN];
1123 struct bgp_filter *filter;
1124 struct bgp_info info;
1125 struct peer *from;
0b597ef0 1126 struct attr *riattr;
fee0f4c6 1127
1128 from = ri->peer;
1129 filter = &rsclient->filter[afi][safi];
0b597ef0 1130 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
fee0f4c6 1131
750e8146
PJ
1132 if (DISABLE_BGP_ANNOUNCE)
1133 return 0;
fee0f4c6 1134
1135 /* Do not send back route to sender. */
1136 if (from == rsclient)
1137 return 0;
1138
1139 /* Aggregate-address suppress check. */
fb982c25 1140 if (ri->extra && ri->extra->suppress)
fee0f4c6 1141 if (! UNSUPPRESS_MAP_NAME (filter))
1142 return 0;
1143
1144 /* Default route check. */
1145 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1146 PEER_STATUS_DEFAULT_ORIGINATE))
1147 {
1148 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1149 return 0;
1150#ifdef HAVE_IPV6
1151 else if (p->family == AF_INET6 && p->prefixlen == 0)
1152 return 0;
1153#endif /* HAVE_IPV6 */
1154 }
1155
1156 /* If the attribute has originator-id and it is same as remote
1157 peer's id. */
0b597ef0 1158 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
fee0f4c6 1159 {
fb982c25 1160 if (IPV4_ADDR_SAME (&rsclient->remote_id,
0b597ef0 1161 &riattr->extra->originator_id))
fee0f4c6 1162 {
1163 if (BGP_DEBUG (filter, FILTER))
d2c1f16b 1164 zlog (rsclient->log, LOG_DEBUG,
fee0f4c6 1165 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1166 rsclient->host,
1167 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1168 p->prefixlen);
1169 return 0;
1170 }
1171 }
1172
1173 /* ORF prefix-list filter check */
1174 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1175 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1176 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1177 if (rsclient->orf_plist[afi][safi])
1178 {
1179 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1180 return 0;
1181 }
1182
1183 /* Output filter check. */
0b597ef0 1184 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
fee0f4c6 1185 {
1186 if (BGP_DEBUG (filter, FILTER))
d2c1f16b 1187 zlog (rsclient->log, LOG_DEBUG,
fee0f4c6 1188 "%s [Update:SEND] %s/%d is filtered",
1189 rsclient->host,
1190 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1191 p->prefixlen);
1192 return 0;
1193 }
1194
1195#ifdef BGP_SEND_ASPATH_CHECK
1196 /* AS path loop check. */
0b597ef0 1197 if (aspath_loop_check (riattr->aspath, rsclient->as))
fee0f4c6 1198 {
1199 if (BGP_DEBUG (filter, FILTER))
d2c1f16b 1200 zlog (rsclient->log, LOG_DEBUG,
aea339f7 1201 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
fee0f4c6 1202 rsclient->host, rsclient->as);
1203 return 0;
1204 }
1205#endif /* BGP_SEND_ASPATH_CHECK */
1206
1207 /* For modify attribute, copy it to temporary structure. */
0b597ef0 1208 bgp_attr_dup (attr, riattr);
fee0f4c6 1209
1210 /* next-hop-set */
1211 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1212#ifdef HAVE_IPV6
1213 || (p->family == AF_INET6 &&
fb982c25 1214 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
fee0f4c6 1215#endif /* HAVE_IPV6 */
1216 )
1217 {
1218 /* Set IPv4 nexthop. */
1219 if (p->family == AF_INET)
1220 {
1221 if (safi == SAFI_MPLS_VPN)
fb982c25 1222 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
fee0f4c6 1223 IPV4_MAX_BYTELEN);
1224 else
1225 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1226 }
1227#ifdef HAVE_IPV6
1228 /* Set IPv6 nexthop. */
1229 if (p->family == AF_INET6)
1230 {
1231 /* IPv6 global nexthop must be included. */
fb982c25 1232 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
fee0f4c6 1233 IPV6_MAX_BYTELEN);
fb982c25 1234 attr->extra->mp_nexthop_len = 16;
fee0f4c6 1235 }
1236#endif /* HAVE_IPV6 */
1237 }
1238
1239#ifdef HAVE_IPV6
1240 if (p->family == AF_INET6)
1241 {
fb982c25 1242 struct attr_extra *attre = attr->extra;
558d1fec 1243
fee0f4c6 1244 /* Left nexthop_local unchanged if so configured. */
1245 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1246 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1247 {
fb982c25
PJ
1248 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1249 attre->mp_nexthop_len=32;
fee0f4c6 1250 else
fb982c25 1251 attre->mp_nexthop_len=16;
fee0f4c6 1252 }
1253
1254 /* Default nexthop_local treatment for RS-Clients */
1255 else
1256 {
1257 /* Announcer and RS-Client are both in the same network */
1258 if (rsclient->shared_network && from->shared_network &&
1259 (rsclient->ifindex == from->ifindex))
1260 {
fb982c25
PJ
1261 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1262 attre->mp_nexthop_len=32;
fee0f4c6 1263 else
fb982c25 1264 attre->mp_nexthop_len=16;
fee0f4c6 1265 }
1266
1267 /* Set link-local address for shared network peer. */
1268 else if (rsclient->shared_network
1269 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1270 {
fb982c25 1271 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
fee0f4c6 1272 IPV6_MAX_BYTELEN);
fb982c25 1273 attre->mp_nexthop_len = 32;
fee0f4c6 1274 }
1275
1276 else
fb982c25 1277 attre->mp_nexthop_len = 16;
fee0f4c6 1278 }
1279
1280 }
1281#endif /* HAVE_IPV6 */
1282
1283
1284 /* If this is EBGP peer and remove-private-AS is set. */
6d85b15b 1285 if (rsclient->sort == BGP_PEER_EBGP
fee0f4c6 1286 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1287 && aspath_private_as_check (attr->aspath))
1288 attr->aspath = aspath_empty_get ();
1289
1290 /* Route map & unsuppress-map apply. */
fb982c25 1291 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
fee0f4c6 1292 {
1293 info.peer = rsclient;
1294 info.attr = attr;
1295
1296 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1297
fb982c25 1298 if (ri->extra && ri->extra->suppress)
fee0f4c6 1299 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1300 else
1301 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1302
1303 rsclient->rmap_type = 0;
1304
1305 if (ret == RMAP_DENYMATCH)
1306 {
1307 bgp_attr_flush (attr);
1308 return 0;
1309 }
1310 }
1311
1312 return 1;
1313}
1314
1315struct bgp_info_pair
1316{
1317 struct bgp_info *old;
1318 struct bgp_info *new;
1319};
1320
94f2b392 1321static void
96450faf
JB
1322bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1323 struct bgp_maxpaths_cfg *mpath_cfg,
1324 struct bgp_info_pair *result)
718e3744 1325{
718e3744 1326 struct bgp_info *new_select;
1327 struct bgp_info *old_select;
fee0f4c6 1328 struct bgp_info *ri;
718e3744 1329 struct bgp_info *ri1;
1330 struct bgp_info *ri2;
b40d939b 1331 struct bgp_info *nextri = NULL;
96450faf
JB
1332 int paths_eq, do_mpath;
1333 struct list mp_list;
1334
1335 bgp_mp_list_init (&mp_list);
1336 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1337 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1338
718e3744 1339 /* bgp deterministic-med */
1340 new_select = NULL;
1341 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1342 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1343 {
1344 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1345 continue;
1346 if (BGP_INFO_HOLDDOWN (ri1))
1347 continue;
1348
1349 new_select = ri1;
6918e74b
JB
1350 if (do_mpath)
1351 bgp_mp_list_add (&mp_list, ri1);
1352 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
718e3744 1353 if (ri1->next)
1354 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1355 {
1356 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1357 continue;
1358 if (BGP_INFO_HOLDDOWN (ri2))
1359 continue;
1360
1361 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1362 || aspath_cmp_left_confed (ri1->attr->aspath,
1363 ri2->attr->aspath))
1364 {
6918e74b
JB
1365 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1366 old_select = ri2;
5e242b0d
DS
1367 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
1368 mpath_cfg))
718e3744 1369 {
1a392d46 1370 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
718e3744 1371 new_select = ri2;
6918e74b
JB
1372 if (do_mpath && !paths_eq)
1373 {
1374 bgp_mp_list_clear (&mp_list);
1375 bgp_mp_list_add (&mp_list, ri2);
1376 }
718e3744 1377 }
1378
6918e74b
JB
1379 if (do_mpath && paths_eq)
1380 bgp_mp_list_add (&mp_list, ri2);
1381
1a392d46 1382 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
718e3744 1383 }
1384 }
1a392d46
PJ
1385 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1386 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
6918e74b
JB
1387
1388 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1389 bgp_mp_list_clear (&mp_list);
718e3744 1390 }
1391
1392 /* Check old selected route and new selected route. */
1393 old_select = NULL;
1394 new_select = NULL;
b40d939b 1395 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
718e3744 1396 {
1397 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1398 old_select = ri;
1399
1400 if (BGP_INFO_HOLDDOWN (ri))
b40d939b 1401 {
1402 /* reap REMOVED routes, if needs be
1403 * selected route must stay for a while longer though
1404 */
1405 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1406 && (ri != old_select))
1407 bgp_info_reap (rn, ri);
1408
1409 continue;
1410 }
718e3744 1411
1412 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1413 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1414 {
1a392d46 1415 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
718e3744 1416 continue;
1417 }
1a392d46
PJ
1418 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1419 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
718e3744 1420
5e242b0d 1421 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg))
96450faf 1422 {
6918e74b
JB
1423 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1424 bgp_mp_dmed_deselect (new_select);
1425
96450faf
JB
1426 new_select = ri;
1427
1428 if (do_mpath && !paths_eq)
1429 {
1430 bgp_mp_list_clear (&mp_list);
1431 bgp_mp_list_add (&mp_list, ri);
1432 }
1433 }
6918e74b
JB
1434 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1435 bgp_mp_dmed_deselect (ri);
96450faf
JB
1436
1437 if (do_mpath && paths_eq)
1438 bgp_mp_list_add (&mp_list, ri);
718e3744 1439 }
b40d939b 1440
fee0f4c6 1441
6918e74b
JB
1442 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1443 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
96450faf 1444
0b597ef0 1445 bgp_info_mpath_aggregate_update (new_select, old_select);
96450faf
JB
1446 bgp_mp_list_clear (&mp_list);
1447
1448 result->old = old_select;
1449 result->new = new_select;
1450
1451 return;
fee0f4c6 1452}
1453
94f2b392 1454static int
fee0f4c6 1455bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
9eda90ce
PJ
1456 struct bgp_node *rn, afi_t afi, safi_t safi)
1457{
fee0f4c6 1458 struct prefix *p;
558d1fec
JBD
1459 struct attr attr;
1460 struct attr_extra extra;
fee0f4c6 1461
1462 p = &rn->p;
1463
9eda90ce
PJ
1464 /* Announce route to Established peer. */
1465 if (peer->status != Established)
fee0f4c6 1466 return 0;
718e3744 1467
9eda90ce
PJ
1468 /* Address family configuration check. */
1469 if (! peer->afc_nego[afi][safi])
fee0f4c6 1470 return 0;
718e3744 1471
9eda90ce 1472 /* First update is deferred until ORF or ROUTE-REFRESH is received */
fee0f4c6 1473 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1474 PEER_STATUS_ORF_WAIT_REFRESH))
1475 return 0;
718e3744 1476
558d1fec
JBD
1477 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1478 attr.extra = &extra;
1479
67174041 1480 switch (bgp_node_table (rn)->type)
fee0f4c6 1481 {
1482 case BGP_TABLE_MAIN:
718e3744 1483 /* Announcement to peer->conf. If the route is filtered,
1484 withdraw it. */
9eda90ce
PJ
1485 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1486 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
fee0f4c6 1487 else
1488 bgp_adj_out_unset (rn, peer, p, afi, safi);
1489 break;
1490 case BGP_TABLE_RSCLIENT:
1491 /* Announcement to peer->conf. If the route is filtered,
1492 withdraw it. */
9eda90ce
PJ
1493 if (selected &&
1494 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1495 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1496 else
1497 bgp_adj_out_unset (rn, peer, p, afi, safi);
fee0f4c6 1498 break;
1499 }
558d1fec 1500
fee0f4c6 1501 return 0;
200df115 1502}
fee0f4c6 1503
200df115 1504struct bgp_process_queue
fee0f4c6 1505{
200df115 1506 struct bgp *bgp;
1507 struct bgp_node *rn;
1508 afi_t afi;
1509 safi_t safi;
1510};
1511
1512static wq_item_status
0fb58d5d 1513bgp_process_rsclient (struct work_queue *wq, void *data)
200df115 1514{
0fb58d5d 1515 struct bgp_process_queue *pq = data;
200df115 1516 struct bgp *bgp = pq->bgp;
1517 struct bgp_node *rn = pq->rn;
1518 afi_t afi = pq->afi;
1519 safi_t safi = pq->safi;
fee0f4c6 1520 struct bgp_info *new_select;
1521 struct bgp_info *old_select;
1522 struct bgp_info_pair old_and_new;
1eb8ef25 1523 struct listnode *node, *nnode;
67174041 1524 struct peer *rsclient = bgp_node_table (rn)->owner;
200df115 1525
fee0f4c6 1526 /* Best path selection. */
96450faf 1527 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 1528 new_select = old_and_new.new;
1529 old_select = old_and_new.old;
1530
200df115 1531 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1532 {
228da428
CC
1533 if (rsclient->group)
1534 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1535 {
1536 /* Nothing to do. */
1537 if (old_select && old_select == new_select)
1538 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1539 continue;
1540
1541 if (old_select)
1542 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1543 if (new_select)
1544 {
1545 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1546 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d
JB
1547 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1548 }
228da428
CC
1549
1550 bgp_process_announce_selected (rsclient, new_select, rn,
1551 afi, safi);
1552 }
200df115 1553 }
1554 else
1555 {
b7395791 1556 if (old_select)
1a392d46 1557 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
b7395791 1558 if (new_select)
1559 {
1a392d46
PJ
1560 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1561 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 1562 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
b7395791 1563 }
9eda90ce 1564 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
200df115 1565 }
1566
b40d939b 1567 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1568 bgp_info_reap (rn, old_select);
1569
200df115 1570 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1571 return WQ_SUCCESS;
fee0f4c6 1572}
1573
200df115 1574static wq_item_status
0fb58d5d 1575bgp_process_main (struct work_queue *wq, void *data)
200df115 1576{
0fb58d5d 1577 struct bgp_process_queue *pq = data;
200df115 1578 struct bgp *bgp = pq->bgp;
1579 struct bgp_node *rn = pq->rn;
1580 afi_t afi = pq->afi;
1581 safi_t safi = pq->safi;
1582 struct prefix *p = &rn->p;
fee0f4c6 1583 struct bgp_info *new_select;
1584 struct bgp_info *old_select;
1585 struct bgp_info_pair old_and_new;
1eb8ef25 1586 struct listnode *node, *nnode;
fee0f4c6 1587 struct peer *peer;
fb982c25 1588
fee0f4c6 1589 /* Best path selection. */
96450faf 1590 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 1591 old_select = old_and_new.old;
1592 new_select = old_and_new.new;
1593
1594 /* Nothing to do. */
1595 if (old_select && old_select == new_select)
1596 {
1597 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
200df115 1598 {
8196f13d
JB
1599 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1600 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
5a616c08 1601 bgp_zebra_announce (p, old_select, bgp, safi);
200df115 1602
8196f13d 1603 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
200df115 1604 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1605 return WQ_SUCCESS;
1606 }
fee0f4c6 1607 }
1608
338b3424 1609 if (old_select)
1a392d46 1610 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
338b3424 1611 if (new_select)
1612 {
1a392d46
PJ
1613 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1614 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 1615 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
338b3424 1616 }
1617
1618
fee0f4c6 1619 /* Check each BGP peer. */
1eb8ef25 1620 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
fee0f4c6 1621 {
9eda90ce 1622 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
718e3744 1623 }
1624
1625 /* FIB update. */
5a616c08
B
1626 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1627 ! bgp_option_check (BGP_OPT_NO_FIB)))
718e3744 1628 {
1629 if (new_select
1630 && new_select->type == ZEBRA_ROUTE_BGP
1631 && new_select->sub_type == BGP_ROUTE_NORMAL)
5a616c08 1632 bgp_zebra_announce (p, new_select, bgp, safi);
718e3744 1633 else
1634 {
1635 /* Withdraw the route from the kernel. */
1636 if (old_select
1637 && old_select->type == ZEBRA_ROUTE_BGP
1638 && old_select->sub_type == BGP_ROUTE_NORMAL)
5a616c08 1639 bgp_zebra_withdraw (p, old_select, safi);
718e3744 1640 }
1641 }
b40d939b 1642
1643 /* Reap old select bgp_info, it it has been removed */
1644 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1645 bgp_info_reap (rn, old_select);
1646
200df115 1647 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1648 return WQ_SUCCESS;
718e3744 1649}
1650
200df115 1651static void
0fb58d5d 1652bgp_processq_del (struct work_queue *wq, void *data)
200df115 1653{
0fb58d5d 1654 struct bgp_process_queue *pq = data;
67174041 1655 struct bgp_table *table = bgp_node_table (pq->rn);
0fb58d5d 1656
228da428 1657 bgp_unlock (pq->bgp);
200df115 1658 bgp_unlock_node (pq->rn);
228da428 1659 bgp_table_unlock (table);
200df115 1660 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1661}
1662
f188f2c4 1663void
200df115 1664bgp_process_queue_init (void)
1665{
1666 bm->process_main_queue
1667 = work_queue_new (bm->master, "process_main_queue");
1668 bm->process_rsclient_queue
1669 = work_queue_new (bm->master, "process_rsclient_queue");
1670
1671 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1672 {
1673 zlog_err ("%s: Failed to allocate work queue", __func__);
1674 exit (1);
1675 }
1676
1677 bm->process_main_queue->spec.workfunc = &bgp_process_main;
200df115 1678 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
838bbde0
PJ
1679 bm->process_main_queue->spec.max_retries = 0;
1680 bm->process_main_queue->spec.hold = 50;
1681
1682 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1683 sizeof (struct work_queue *));
1684 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
200df115 1685}
1686
1687void
fee0f4c6 1688bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1689{
200df115 1690 struct bgp_process_queue *pqnode;
1691
1692 /* already scheduled for processing? */
1693 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1694 return;
1695
1696 if ( (bm->process_main_queue == NULL) ||
1697 (bm->process_rsclient_queue == NULL) )
1698 bgp_process_queue_init ();
1699
1700 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1701 sizeof (struct bgp_process_queue));
1702 if (!pqnode)
1703 return;
228da428
CC
1704
1705 /* all unlocked in bgp_processq_del */
67174041 1706 bgp_table_lock (bgp_node_table (rn));
228da428 1707 pqnode->rn = bgp_lock_node (rn);
200df115 1708 pqnode->bgp = bgp;
228da428 1709 bgp_lock (bgp);
200df115 1710 pqnode->afi = afi;
1711 pqnode->safi = safi;
1712
67174041 1713 switch (bgp_node_table (rn)->type)
fee0f4c6 1714 {
200df115 1715 case BGP_TABLE_MAIN:
1716 work_queue_add (bm->process_main_queue, pqnode);
1717 break;
1718 case BGP_TABLE_RSCLIENT:
1719 work_queue_add (bm->process_rsclient_queue, pqnode);
1720 break;
fee0f4c6 1721 }
200df115 1722
07ff4dc4 1723 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
200df115 1724 return;
fee0f4c6 1725}
0a486e5f 1726
94f2b392 1727static int
0a486e5f 1728bgp_maximum_prefix_restart_timer (struct thread *thread)
1729{
1730 struct peer *peer;
1731
1732 peer = THREAD_ARG (thread);
1733 peer->t_pmax_restart = NULL;
1734
1735 if (BGP_DEBUG (events, EVENTS))
1736 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1737 peer->host);
1738
1739 peer_clear (peer);
1740
1741 return 0;
1742}
1743
718e3744 1744int
5228ad27 1745bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1746 safi_t safi, int always)
718e3744 1747{
e0701b79 1748 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1749 return 0;
1750
1751 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
718e3744 1752 {
e0701b79 1753 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1754 && ! always)
1755 return 0;
1756
1757 zlog (peer->log, LOG_INFO,
0a486e5f 1758 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1759 "limit %ld", afi_safi_print (afi, safi), peer->host,
1760 peer->pcount[afi][safi], peer->pmax[afi][safi]);
e0701b79 1761 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1762
1763 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1764 return 0;
1765
1766 {
5228ad27 1767 u_int8_t ndata[7];
e0701b79 1768
1769 if (safi == SAFI_MPLS_VPN)
42e6d745 1770 safi = SAFI_MPLS_LABELED_VPN;
5228ad27 1771
1772 ndata[0] = (afi >> 8);
1773 ndata[1] = afi;
1774 ndata[2] = safi;
1775 ndata[3] = (peer->pmax[afi][safi] >> 24);
1776 ndata[4] = (peer->pmax[afi][safi] >> 16);
1777 ndata[5] = (peer->pmax[afi][safi] >> 8);
1778 ndata[6] = (peer->pmax[afi][safi]);
e0701b79 1779
1780 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1781 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1782 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1783 }
0a486e5f 1784
1785 /* restart timer start */
1786 if (peer->pmax_restart[afi][safi])
1787 {
1788 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1789
1790 if (BGP_DEBUG (events, EVENTS))
1791 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1792 peer->host, peer->v_pmax_restart);
1793
1794 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1795 peer->v_pmax_restart);
1796 }
1797
e0701b79 1798 return 1;
1799 }
1800 else
1801 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1802
1803 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1804 {
1805 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1806 && ! always)
1807 return 0;
1808
1809 zlog (peer->log, LOG_INFO,
0a486e5f 1810 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1811 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1812 peer->pmax[afi][safi]);
e0701b79 1813 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 1814 }
e0701b79 1815 else
1816 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 1817 return 0;
1818}
1819
b40d939b 1820/* Unconditionally remove the route from the RIB, without taking
1821 * damping into consideration (eg, because the session went down)
1822 */
94f2b392 1823static void
718e3744 1824bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1825 afi_t afi, safi_t safi)
1826{
902212c3 1827 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1828
1829 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1830 bgp_info_delete (rn, ri); /* keep historical info */
1831
b40d939b 1832 bgp_process (peer->bgp, rn, afi, safi);
718e3744 1833}
1834
94f2b392 1835static void
718e3744 1836bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
b40d939b 1837 afi_t afi, safi_t safi)
718e3744 1838{
718e3744 1839 int status = BGP_DAMP_NONE;
1840
b40d939b 1841 /* apply dampening, if result is suppressed, we'll be retaining
1842 * the bgp_info in the RIB for historical reference.
1843 */
1844 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 1845 && peer->sort == BGP_PEER_EBGP)
b40d939b 1846 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1847 == BGP_DAMP_SUPPRESSED)
902212c3 1848 {
902212c3 1849 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1850 return;
1851 }
1852
1853 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 1854}
1855
fb018d25
DS
1856static struct bgp_info *
1857info_make (int type, int sub_type, struct peer *peer, struct attr *attr,
1858 struct bgp_node *rn)
1859{
1860 struct bgp_info *new;
1861
1862 /* Make new BGP info. */
1863 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
1864 new->type = type;
1865 new->sub_type = sub_type;
1866 new->peer = peer;
1867 new->attr = attr;
1868 new->uptime = bgp_clock ();
1869 new->net = rn;
1870 return new;
1871}
1872
94f2b392 1873static void
fee0f4c6 1874bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1875 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1876 int sub_type, struct prefix_rd *prd, u_char *tag)
1877{
1878 struct bgp_node *rn;
1879 struct bgp *bgp;
558d1fec
JBD
1880 struct attr new_attr;
1881 struct attr_extra new_extra;
fee0f4c6 1882 struct attr *attr_new;
1883 struct attr *attr_new2;
1884 struct bgp_info *ri;
1885 struct bgp_info *new;
fd79ac91 1886 const char *reason;
fee0f4c6 1887 char buf[SU_ADDRSTRLEN];
1888
1889 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1890 if (peer == rsclient)
1891 return;
1892
1893 bgp = peer->bgp;
1894 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1895
1896 /* Check previously received route. */
1897 for (ri = rn->info; ri; ri = ri->next)
1898 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1899 break;
1900
1901 /* AS path loop check. */
000e157c 1902 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
fee0f4c6 1903 {
1904 reason = "as-path contains our own AS;";
1905 goto filtered;
1906 }
1907
1908 /* Route reflector originator ID check. */
1909 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 1910 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
fee0f4c6 1911 {
1912 reason = "originator is us;";
1913 goto filtered;
1914 }
fb982c25 1915
558d1fec 1916 new_attr.extra = &new_extra;
fb982c25 1917 bgp_attr_dup (&new_attr, attr);
fee0f4c6 1918
1919 /* Apply export policy. */
1920 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1921 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1922 {
1923 reason = "export-policy;";
1924 goto filtered;
1925 }
1926
1927 attr_new2 = bgp_attr_intern (&new_attr);
fb982c25 1928
fee0f4c6 1929 /* Apply import policy. */
1930 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1931 {
f6f434b2 1932 bgp_attr_unintern (&attr_new2);
fee0f4c6 1933
1934 reason = "import-policy;";
1935 goto filtered;
1936 }
1937
1938 attr_new = bgp_attr_intern (&new_attr);
f6f434b2 1939 bgp_attr_unintern (&attr_new2);
fee0f4c6 1940
1941 /* IPv4 unicast next hop check. */
5a616c08 1942 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
fee0f4c6 1943 {
733cd9e5 1944 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
fee0f4c6 1945 if (new_attr.nexthop.s_addr == 0
733cd9e5 1946 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
fee0f4c6 1947 {
f6f434b2 1948 bgp_attr_unintern (&attr_new);
fee0f4c6 1949
1950 reason = "martian next-hop;";
1951 goto filtered;
1952 }
1953 }
558d1fec 1954
fee0f4c6 1955 /* If the update is implicit withdraw. */
1956 if (ri)
1957 {
65957886 1958 ri->uptime = bgp_clock ();
fee0f4c6 1959
1960 /* Same attribute comes in. */
16d2e241
PJ
1961 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1962 && attrhash_cmp (ri->attr, attr_new))
fee0f4c6 1963 {
1964
1a392d46 1965 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
fee0f4c6 1966
1967 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 1968 zlog (peer->log, LOG_DEBUG,
fee0f4c6 1969 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1970 peer->host,
1971 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1972 p->prefixlen, rsclient->host);
1973
228da428 1974 bgp_unlock_node (rn);
f6f434b2 1975 bgp_attr_unintern (&attr_new);
fee0f4c6 1976
228da428 1977 return;
fee0f4c6 1978 }
1979
16d2e241
PJ
1980 /* Withdraw/Announce before we fully processed the withdraw */
1981 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1982 bgp_info_restore (rn, ri);
1983
fee0f4c6 1984 /* Received Logging. */
1985 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 1986 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
fee0f4c6 1987 peer->host,
1988 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1989 p->prefixlen, rsclient->host);
1990
1991 /* The attribute is changed. */
1a392d46 1992 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
fee0f4c6 1993
1994 /* Update to new attribute. */
f6f434b2 1995 bgp_attr_unintern (&ri->attr);
fee0f4c6 1996 ri->attr = attr_new;
1997
1998 /* Update MPLS tag. */
1999 if (safi == SAFI_MPLS_VPN)
fb982c25 2000 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
fee0f4c6 2001
1a392d46 2002 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
fee0f4c6 2003
2004 /* Process change. */
2005 bgp_process (bgp, rn, afi, safi);
2006 bgp_unlock_node (rn);
2007
2008 return;
2009 }
2010
2011 /* Received Logging. */
2012 if (BGP_DEBUG (update, UPDATE_IN))
2013 {
d2c1f16b 2014 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
fee0f4c6 2015 peer->host,
2016 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2017 p->prefixlen, rsclient->host);
2018 }
2019
fb018d25 2020 new = info_make(type, sub_type, peer, attr_new, rn);
fee0f4c6 2021
2022 /* Update MPLS tag. */
2023 if (safi == SAFI_MPLS_VPN)
fb982c25 2024 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
fee0f4c6 2025
1a392d46 2026 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
fee0f4c6 2027
2028 /* Register new BGP information. */
2029 bgp_info_add (rn, new);
200df115 2030
2031 /* route_node_get lock */
2032 bgp_unlock_node (rn);
2033
fee0f4c6 2034 /* Process change. */
2035 bgp_process (bgp, rn, afi, safi);
558d1fec 2036
fee0f4c6 2037 return;
2038
2039 filtered:
2040
2041 /* This BGP update is filtered. Log the reason then update BGP entry. */
2042 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 2043 zlog (peer->log, LOG_DEBUG,
fee0f4c6 2044 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2045 peer->host,
2046 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2047 p->prefixlen, rsclient->host, reason);
2048
2049 if (ri)
b40d939b 2050 bgp_rib_remove (rn, ri, peer, afi, safi);
fee0f4c6 2051
2052 bgp_unlock_node (rn);
558d1fec 2053
fee0f4c6 2054 return;
2055}
2056
94f2b392 2057static void
fee0f4c6 2058bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2059 struct peer *peer, struct prefix *p, int type, int sub_type,
2060 struct prefix_rd *prd, u_char *tag)
228da428 2061{
fee0f4c6 2062 struct bgp_node *rn;
2063 struct bgp_info *ri;
2064 char buf[SU_ADDRSTRLEN];
2065
2066 if (rsclient == peer)
228da428 2067 return;
fee0f4c6 2068
2069 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2070
2071 /* Lookup withdrawn route. */
2072 for (ri = rn->info; ri; ri = ri->next)
2073 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2074 break;
2075
2076 /* Withdraw specified route from routing table. */
2077 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
b40d939b 2078 bgp_rib_withdraw (rn, ri, peer, afi, safi);
fee0f4c6 2079 else if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 2080 zlog (peer->log, LOG_DEBUG,
fee0f4c6 2081 "%s Can't find the route %s/%d", peer->host,
2082 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2083 p->prefixlen);
2084
2085 /* Unlock bgp_node_get() lock. */
228da428
CC
2086 bgp_unlock_node (rn);
2087}
fee0f4c6 2088
94f2b392 2089static int
fee0f4c6 2090bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
718e3744 2091 afi_t afi, safi_t safi, int type, int sub_type,
2092 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2093{
2094 int ret;
2095 int aspath_loop_count = 0;
2096 struct bgp_node *rn;
2097 struct bgp *bgp;
558d1fec
JBD
2098 struct attr new_attr;
2099 struct attr_extra new_extra;
718e3744 2100 struct attr *attr_new;
2101 struct bgp_info *ri;
2102 struct bgp_info *new;
fd79ac91 2103 const char *reason;
718e3744 2104 char buf[SU_ADDRSTRLEN];
2105
2106 bgp = peer->bgp;
fee0f4c6 2107 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
fb982c25 2108
718e3744 2109 /* When peer's soft reconfiguration enabled. Record input packet in
2110 Adj-RIBs-In. */
343aa822
JBD
2111 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2112 && peer != bgp->peer_self)
718e3744 2113 bgp_adj_in_set (rn, peer, attr);
2114
2115 /* Check previously received route. */
2116 for (ri = rn->info; ri; ri = ri->next)
2117 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2118 break;
2119
2120 /* AS path local-as loop check. */
2121 if (peer->change_local_as)
2122 {
2123 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2124 aspath_loop_count = 1;
2125
2126 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2127 {
2128 reason = "as-path contains our own AS;";
2129 goto filtered;
2130 }
2131 }
2132
2133 /* AS path loop check. */
2134 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2135 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2136 && aspath_loop_check(attr->aspath, bgp->confed_id)
2137 > peer->allowas_in[afi][safi]))
2138 {
2139 reason = "as-path contains our own AS;";
2140 goto filtered;
2141 }
2142
2143 /* Route reflector originator ID check. */
2144 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 2145 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
718e3744 2146 {
2147 reason = "originator is us;";
2148 goto filtered;
2149 }
2150
2151 /* Route reflector cluster ID check. */
2152 if (bgp_cluster_filter (peer, attr))
2153 {
2154 reason = "reflected from the same cluster;";
2155 goto filtered;
2156 }
2157
2158 /* Apply incoming filter. */
2159 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2160 {
2161 reason = "filter;";
2162 goto filtered;
2163 }
2164
558d1fec 2165 new_attr.extra = &new_extra;
fb982c25 2166 bgp_attr_dup (&new_attr, attr);
718e3744 2167
c460e572
DL
2168 /* Apply incoming route-map.
2169 * NB: new_attr may now contain newly allocated values from route-map "set"
2170 * commands, so we need bgp_attr_flush in the error paths, until we intern
2171 * the attr (which takes over the memory references) */
718e3744 2172 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2173 {
2174 reason = "route-map;";
c460e572 2175 bgp_attr_flush (&new_attr);
718e3744 2176 goto filtered;
2177 }
2178
2179 /* IPv4 unicast next hop check. */
2180 if (afi == AFI_IP && safi == SAFI_UNICAST)
2181 {
2182 /* If the peer is EBGP and nexthop is not on connected route,
2183 discard it. */
6d85b15b 2184 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
8e80bdf2 2185 && ! bgp_nexthop_onlink (afi, &new_attr)
6ffd2079 2186 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
718e3744 2187 {
2188 reason = "non-connected next-hop;";
c460e572 2189 bgp_attr_flush (&new_attr);
718e3744 2190 goto filtered;
2191 }
2192
733cd9e5 2193 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
718e3744 2194 must not be my own address. */
10f9bf3f
JBD
2195 if (new_attr.nexthop.s_addr == 0
2196 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2197 || bgp_nexthop_self (&new_attr))
718e3744 2198 {
2199 reason = "martian next-hop;";
c460e572 2200 bgp_attr_flush (&new_attr);
718e3744 2201 goto filtered;
2202 }
2203 }
2204
2205 attr_new = bgp_attr_intern (&new_attr);
2206
2207 /* If the update is implicit withdraw. */
2208 if (ri)
2209 {
65957886 2210 ri->uptime = bgp_clock ();
718e3744 2211
2212 /* Same attribute comes in. */
16d2e241
PJ
2213 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2214 && attrhash_cmp (ri->attr, attr_new))
718e3744 2215 {
1a392d46 2216 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 2217
2218 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2219 && peer->sort == BGP_PEER_EBGP
718e3744 2220 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2221 {
2222 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 2223 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
718e3744 2224 peer->host,
2225 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2226 p->prefixlen);
2227
902212c3 2228 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2229 {
2230 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2231 bgp_process (bgp, rn, afi, safi);
2232 }
718e3744 2233 }
16d2e241 2234 else /* Duplicate - odd */
718e3744 2235 {
2236 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 2237 zlog (peer->log, LOG_DEBUG,
718e3744 2238 "%s rcvd %s/%d...duplicate ignored",
2239 peer->host,
2240 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2241 p->prefixlen);
93406d87 2242
2243 /* graceful restart STALE flag unset. */
2244 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2245 {
1a392d46 2246 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
902212c3 2247 bgp_process (bgp, rn, afi, safi);
93406d87 2248 }
718e3744 2249 }
2250
2251 bgp_unlock_node (rn);
f6f434b2 2252 bgp_attr_unintern (&attr_new);
558d1fec 2253
718e3744 2254 return 0;
2255 }
2256
16d2e241
PJ
2257 /* Withdraw/Announce before we fully processed the withdraw */
2258 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2259 {
2260 if (BGP_DEBUG (update, UPDATE_IN))
2261 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2262 peer->host,
2263 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2264 p->prefixlen);
2265 bgp_info_restore (rn, ri);
2266 }
2267
718e3744 2268 /* Received Logging. */
2269 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 2270 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
718e3744 2271 peer->host,
2272 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2273 p->prefixlen);
2274
93406d87 2275 /* graceful restart STALE flag unset. */
2276 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1a392d46 2277 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
93406d87 2278
718e3744 2279 /* The attribute is changed. */
1a392d46 2280 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
902212c3 2281
2282 /* implicit withdraw, decrement aggregate and pcount here.
2283 * only if update is accepted, they'll increment below.
2284 */
902212c3 2285 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2286
718e3744 2287 /* Update bgp route dampening information. */
2288 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2289 && peer->sort == BGP_PEER_EBGP)
718e3744 2290 {
2291 /* This is implicit withdraw so we should update dampening
2292 information. */
2293 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2294 bgp_damp_withdraw (ri, rn, afi, safi, 1);
718e3744 2295 }
2296
718e3744 2297 /* Update to new attribute. */
f6f434b2 2298 bgp_attr_unintern (&ri->attr);
718e3744 2299 ri->attr = attr_new;
2300
2301 /* Update MPLS tag. */
2302 if (safi == SAFI_MPLS_VPN)
fb982c25 2303 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
718e3744 2304
2305 /* Update bgp route dampening information. */
2306 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2307 && peer->sort == BGP_PEER_EBGP)
718e3744 2308 {
2309 /* Now we do normal update dampening. */
2310 ret = bgp_damp_update (ri, rn, afi, safi);
2311 if (ret == BGP_DAMP_SUPPRESSED)
2312 {
2313 bgp_unlock_node (rn);
2314 return 0;
2315 }
2316 }
2317
2318 /* Nexthop reachability check. */
2319 if ((afi == AFI_IP || afi == AFI_IP6)
2320 && safi == SAFI_UNICAST
6d85b15b
JBD
2321 && (peer->sort == BGP_PEER_IBGP
2322 || peer->sort == BGP_PEER_CONFED
2323 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
6ffd2079 2324 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
718e3744 2325 {
fb018d25 2326 if (bgp_find_or_add_nexthop (afi, ri, NULL, NULL))
1a392d46 2327 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 2328 else
1a392d46 2329 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
718e3744 2330 }
2331 else
1a392d46 2332 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 2333
2334 /* Process change. */
2335 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2336
2337 bgp_process (bgp, rn, afi, safi);
2338 bgp_unlock_node (rn);
558d1fec 2339
718e3744 2340 return 0;
2341 }
2342
2343 /* Received Logging. */
2344 if (BGP_DEBUG (update, UPDATE_IN))
2345 {
d2c1f16b 2346 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
718e3744 2347 peer->host,
2348 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2349 p->prefixlen);
2350 }
2351
718e3744 2352 /* Make new BGP info. */
fb018d25 2353 new = info_make(type, sub_type, peer, attr_new, rn);
718e3744 2354
2355 /* Update MPLS tag. */
2356 if (safi == SAFI_MPLS_VPN)
fb982c25 2357 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
718e3744 2358
2359 /* Nexthop reachability check. */
2360 if ((afi == AFI_IP || afi == AFI_IP6)
2361 && safi == SAFI_UNICAST
6d85b15b
JBD
2362 && (peer->sort == BGP_PEER_IBGP
2363 || peer->sort == BGP_PEER_CONFED
2364 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
6ffd2079 2365 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
718e3744 2366 {
fb018d25 2367 if (bgp_find_or_add_nexthop (afi, new, NULL, NULL))
1a392d46 2368 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 2369 else
1a392d46 2370 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
718e3744 2371 }
2372 else
1a392d46 2373 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 2374
902212c3 2375 /* Increment prefix */
718e3744 2376 bgp_aggregate_increment (bgp, p, new, afi, safi);
2377
2378 /* Register new BGP information. */
2379 bgp_info_add (rn, new);
200df115 2380
2381 /* route_node_get lock */
2382 bgp_unlock_node (rn);
558d1fec 2383
718e3744 2384 /* If maximum prefix count is configured and current prefix
2385 count exeed it. */
e0701b79 2386 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2387 return -1;
718e3744 2388
2389 /* Process change. */
2390 bgp_process (bgp, rn, afi, safi);
2391
2392 return 0;
2393
2394 /* This BGP update is filtered. Log the reason then update BGP
2395 entry. */
2396 filtered:
2397 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 2398 zlog (peer->log, LOG_DEBUG,
718e3744 2399 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2400 peer->host,
2401 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2402 p->prefixlen, reason);
2403
2404 if (ri)
b40d939b 2405 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 2406
2407 bgp_unlock_node (rn);
558d1fec 2408
718e3744 2409 return 0;
2410}
2411
fee0f4c6 2412int
2413bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2414 afi_t afi, safi_t safi, int type, int sub_type,
2415 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2416{
2417 struct peer *rsclient;
1eb8ef25 2418 struct listnode *node, *nnode;
fee0f4c6 2419 struct bgp *bgp;
2420 int ret;
2421
2422 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2423 soft_reconfig);
2424
2425 bgp = peer->bgp;
2426
2427 /* Process the update for each RS-client. */
1eb8ef25 2428 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 2429 {
2430 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2431 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2432 sub_type, prd, tag);
2433 }
2434
2435 return ret;
2436}
2437
718e3744 2438int
2439bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
94f2b392 2440 afi_t afi, safi_t safi, int type, int sub_type,
2441 struct prefix_rd *prd, u_char *tag)
718e3744 2442{
2443 struct bgp *bgp;
2444 char buf[SU_ADDRSTRLEN];
2445 struct bgp_node *rn;
2446 struct bgp_info *ri;
fee0f4c6 2447 struct peer *rsclient;
1eb8ef25 2448 struct listnode *node, *nnode;
718e3744 2449
2450 bgp = peer->bgp;
2451
fee0f4c6 2452 /* Process the withdraw for each RS-client. */
1eb8ef25 2453 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 2454 {
2455 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2456 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2457 }
2458
718e3744 2459 /* Logging. */
2460 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 2461 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
718e3744 2462 peer->host,
2463 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2464 p->prefixlen);
2465
2466 /* Lookup node. */
fee0f4c6 2467 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 2468
2469 /* If peer is soft reconfiguration enabled. Record input packet for
2470 further calculation. */
2471 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2472 && peer != bgp->peer_self)
2473 bgp_adj_in_unset (rn, peer);
2474
2475 /* Lookup withdrawn route. */
2476 for (ri = rn->info; ri; ri = ri->next)
2477 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2478 break;
2479
2480 /* Withdraw specified route from routing table. */
2481 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
b40d939b 2482 bgp_rib_withdraw (rn, ri, peer, afi, safi);
718e3744 2483 else if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 2484 zlog (peer->log, LOG_DEBUG,
718e3744 2485 "%s Can't find the route %s/%d", peer->host,
2486 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2487 p->prefixlen);
2488
2489 /* Unlock bgp_node_get() lock. */
2490 bgp_unlock_node (rn);
2491
2492 return 0;
2493}
6b0655a2 2494
718e3744 2495void
2496bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2497{
2498 struct bgp *bgp;
e16a4133 2499 struct attr attr;
577ac57b 2500 struct aspath *aspath;
718e3744 2501 struct prefix p;
718e3744 2502 struct peer *from;
dcab1bb8
CF
2503 struct bgp_node *rn;
2504 struct bgp_info *ri;
718e3744 2505 int ret = RMAP_DENYMATCH;
fb982c25 2506
b2497024 2507 if (!(afi == AFI_IP || afi == AFI_IP6))
fb982c25
PJ
2508 return;
2509
718e3744 2510 bgp = peer->bgp;
2511 from = bgp->peer_self;
fb982c25 2512
718e3744 2513 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2514 aspath = attr.aspath;
2515 attr.local_pref = bgp->default_local_pref;
2516 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2517
2518 if (afi == AFI_IP)
2519 str2prefix ("0.0.0.0/0", &p);
2520#ifdef HAVE_IPV6
2521 else if (afi == AFI_IP6)
2522 {
6182d65b
JBD
2523 struct attr_extra *ae = attr.extra;
2524
718e3744 2525 str2prefix ("::/0", &p);
2526
2527 /* IPv6 global nexthop must be included. */
fb982c25 2528 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
718e3744 2529 IPV6_MAX_BYTELEN);
fb982c25 2530 ae->mp_nexthop_len = 16;
718e3744 2531
2532 /* If the peer is on shared nextwork and we have link-local
2533 nexthop set it. */
2534 if (peer->shared_network
2535 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2536 {
fb982c25 2537 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
718e3744 2538 IPV6_MAX_BYTELEN);
fb982c25 2539 ae->mp_nexthop_len = 32;
718e3744 2540 }
2541 }
2542#endif /* HAVE_IPV6 */
718e3744 2543
2544 if (peer->default_rmap[afi][safi].name)
2545 {
fee0f4c6 2546 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
dcab1bb8
CF
2547 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2548 {
2549 for (ri = rn->info; ri; ri = ri->next)
2550 {
2551 struct attr dummy_attr;
2552 struct attr_extra dummy_extra;
2553 struct bgp_info info;
2554
2555 /* Provide dummy so the route-map can't modify the attributes */
2556 dummy_attr.extra = &dummy_extra;
2557 bgp_attr_dup(&dummy_attr, ri->attr);
2558 info.peer = ri->peer;
2559 info.attr = &dummy_attr;
2560
2561 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2562 RMAP_BGP, &info);
2563
2564 /* The route map might have set attributes. If we don't flush them
2565 * here, they will be leaked. */
2566 bgp_attr_flush(&dummy_attr);
2567 if (ret != RMAP_DENYMATCH)
2568 break;
2569 }
2570 if (ret != RMAP_DENYMATCH)
2571 break;
2572 }
fee0f4c6 2573 bgp->peer_self->rmap_type = 0;
2574
718e3744 2575 if (ret == RMAP_DENYMATCH)
dcab1bb8 2576 withdraw = 1;
718e3744 2577 }
2578
2579 if (withdraw)
2580 {
2581 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2582 bgp_default_withdraw_send (peer, afi, safi);
2583 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2584 }
2585 else
2586 {
dcab1bb8
CF
2587 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2588 {
2589 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2590 bgp_default_update_send (peer, &attr, afi, safi, from);
2591 }
718e3744 2592 }
fb982c25
PJ
2593
2594 bgp_attr_extra_free (&attr);
f6f434b2 2595 aspath_unintern (&aspath);
718e3744 2596}
6b0655a2 2597
718e3744 2598static void
2599bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
fee0f4c6 2600 struct bgp_table *table, int rsclient)
718e3744 2601{
2602 struct bgp_node *rn;
2603 struct bgp_info *ri;
558d1fec
JBD
2604 struct attr attr;
2605 struct attr_extra extra;
2606
718e3744 2607 if (! table)
fee0f4c6 2608 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
718e3744 2609
f188f2c4
DS
2610 if (safi != SAFI_MPLS_VPN)
2611 {
2612 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2613 {
2614 bgp_default_originate (peer, afi, safi, 0);
2615 }
2616 else
2617 {
2618 /* Send the withdraw if it was postponed during read-only mode. */
2619 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2620 bgp_default_originate (peer, afi, safi, 1);
2621 }
2622 }
718e3744 2623
558d1fec
JBD
2624 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2625 attr.extra = &extra;
2626
718e3744 2627 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2628 for (ri = rn->info; ri; ri = ri->next)
2629 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2630 {
fee0f4c6 2631 if ( (rsclient) ?
2632 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2633 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
718e3744 2634 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2635 else
2636 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2637 }
2638}
2639
2640void
2641bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2642{
2643 struct bgp_node *rn;
2644 struct bgp_table *table;
2645
2646 if (peer->status != Established)
2647 return;
2648
2649 if (! peer->afc_nego[afi][safi])
2650 return;
2651
2652 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2653 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2654 return;
2655
2656 if (safi != SAFI_MPLS_VPN)
fee0f4c6 2657 bgp_announce_table (peer, afi, safi, NULL, 0);
718e3744 2658 else
2659 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2660 rn = bgp_route_next(rn))
2661 if ((table = (rn->info)) != NULL)
fee0f4c6 2662 bgp_announce_table (peer, afi, safi, table, 0);
2663
2664 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2665 bgp_announce_table (peer, afi, safi, NULL, 1);
718e3744 2666}
2667
2668void
2669bgp_announce_route_all (struct peer *peer)
2670{
2671 afi_t afi;
2672 safi_t safi;
2673
f188f2c4
DS
2674 if (bgp_update_delay_active(peer->bgp))
2675 return;
2676
718e3744 2677 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2678 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2679 bgp_announce_route (peer, afi, safi);
2680}
6b0655a2 2681
718e3744 2682static void
fee0f4c6 2683bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
8692c506 2684 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
fee0f4c6 2685{
2686 struct bgp_node *rn;
2687 struct bgp_adj_in *ain;
2688
2689 if (! table)
2690 table = rsclient->bgp->rib[afi][safi];
2691
2692 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2693 for (ain = rn->adj_in; ain; ain = ain->next)
2694 {
8692c506 2695 struct bgp_info *ri = rn->info;
d53d8fda 2696 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 2697
fee0f4c6 2698 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
d53d8fda 2699 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
fee0f4c6 2700 }
2701}
2702
2703void
2704bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2705{
2706 struct bgp_table *table;
2707 struct bgp_node *rn;
2708
2709 if (safi != SAFI_MPLS_VPN)
8692c506 2710 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
fee0f4c6 2711
2712 else
2713 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2714 rn = bgp_route_next (rn))
2715 if ((table = rn->info) != NULL)
8692c506
JBD
2716 {
2717 struct prefix_rd prd;
2718 prd.family = AF_UNSPEC;
2719 prd.prefixlen = 64;
2720 memcpy(&prd.val, rn->p.u.val, 8);
2721
2722 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2723 }
fee0f4c6 2724}
6b0655a2 2725
fee0f4c6 2726static void
718e3744 2727bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
8692c506 2728 struct bgp_table *table, struct prefix_rd *prd)
718e3744 2729{
2730 int ret;
2731 struct bgp_node *rn;
2732 struct bgp_adj_in *ain;
2733
2734 if (! table)
2735 table = peer->bgp->rib[afi][safi];
2736
2737 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2738 for (ain = rn->adj_in; ain; ain = ain->next)
2739 {
2740 if (ain->peer == peer)
2741 {
8692c506 2742 struct bgp_info *ri = rn->info;
d53d8fda 2743 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 2744
718e3744 2745 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2746 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
d53d8fda 2747 prd, tag, 1);
8692c506 2748
718e3744 2749 if (ret < 0)
2750 {
2751 bgp_unlock_node (rn);
2752 return;
2753 }
2754 continue;
2755 }
2756 }
2757}
2758
2759void
2760bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2761{
2762 struct bgp_node *rn;
2763 struct bgp_table *table;
2764
2765 if (peer->status != Established)
2766 return;
2767
2768 if (safi != SAFI_MPLS_VPN)
8692c506 2769 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
718e3744 2770 else
2771 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2772 rn = bgp_route_next (rn))
2773 if ((table = rn->info) != NULL)
8692c506
JBD
2774 {
2775 struct prefix_rd prd;
2776 prd.family = AF_UNSPEC;
2777 prd.prefixlen = 64;
2778 memcpy(&prd.val, rn->p.u.val, 8);
2779
2780 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2781 }
718e3744 2782}
6b0655a2 2783
228da428
CC
2784
2785struct bgp_clear_node_queue
2786{
2787 struct bgp_node *rn;
2788 enum bgp_clear_route_type purpose;
2789};
2790
200df115 2791static wq_item_status
0fb58d5d 2792bgp_clear_route_node (struct work_queue *wq, void *data)
200df115 2793{
228da428
CC
2794 struct bgp_clear_node_queue *cnq = data;
2795 struct bgp_node *rn = cnq->rn;
64e580a7 2796 struct peer *peer = wq->spec.data;
718e3744 2797 struct bgp_info *ri;
67174041
AS
2798 afi_t afi = bgp_node_table (rn)->afi;
2799 safi_t safi = bgp_node_table (rn)->safi;
200df115 2800
64e580a7 2801 assert (rn && peer);
200df115 2802
64e580a7 2803 for (ri = rn->info; ri; ri = ri->next)
228da428 2804 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
200df115 2805 {
2806 /* graceful restart STALE flag set. */
64e580a7
PJ
2807 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2808 && peer->nsf[afi][safi]
200df115 2809 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
1a392d46
PJ
2810 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2811 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
200df115 2812 else
64e580a7 2813 bgp_rib_remove (rn, ri, peer, afi, safi);
200df115 2814 break;
2815 }
200df115 2816 return WQ_SUCCESS;
2817}
2818
2819static void
0fb58d5d 2820bgp_clear_node_queue_del (struct work_queue *wq, void *data)
200df115 2821{
228da428
CC
2822 struct bgp_clear_node_queue *cnq = data;
2823 struct bgp_node *rn = cnq->rn;
67174041 2824 struct bgp_table *table = bgp_node_table (rn);
64e580a7
PJ
2825
2826 bgp_unlock_node (rn);
228da428
CC
2827 bgp_table_unlock (table);
2828 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
200df115 2829}
2830
2831static void
94f2b392 2832bgp_clear_node_complete (struct work_queue *wq)
200df115 2833{
64e580a7
PJ
2834 struct peer *peer = wq->spec.data;
2835
3e0c78ef 2836 /* Tickle FSM to start moving again */
ca058a30 2837 BGP_EVENT_ADD (peer, Clearing_Completed);
228da428
CC
2838
2839 peer_unlock (peer); /* bgp_clear_route */
200df115 2840}
2841
2842static void
64e580a7 2843bgp_clear_node_queue_init (struct peer *peer)
200df115 2844{
a2943657 2845 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
64e580a7 2846
a2943657 2847 snprintf (wname, sizeof(wname), "clear %s", peer->host);
64e580a7
PJ
2848#undef CLEAR_QUEUE_NAME_LEN
2849
2850 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
200df115 2851 {
2852 zlog_err ("%s: Failed to allocate work queue", __func__);
2853 exit (1);
2854 }
64e580a7
PJ
2855 peer->clear_node_queue->spec.hold = 10;
2856 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2857 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2858 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2859 peer->clear_node_queue->spec.max_retries = 0;
2860
2861 /* we only 'lock' this peer reference when the queue is actually active */
2862 peer->clear_node_queue->spec.data = peer;
200df115 2863}
718e3744 2864
200df115 2865static void
2866bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
228da428
CC
2867 struct bgp_table *table, struct peer *rsclient,
2868 enum bgp_clear_route_type purpose)
200df115 2869{
200df115 2870 struct bgp_node *rn;
2871
f2c31acb 2872
718e3744 2873 if (! table)
fee0f4c6 2874 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
64e580a7 2875
6cf159b9 2876 /* If still no table => afi/safi isn't configured at all or smth. */
2877 if (! table)
2878 return;
65ca75e0
PJ
2879
2880 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2881 {
f2c31acb
PJ
2882 struct bgp_info *ri;
2883 struct bgp_adj_in *ain;
2884 struct bgp_adj_out *aout;
f2c31acb
PJ
2885
2886 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2887 * queued for every clearing peer, regardless of whether it is
2888 * relevant to the peer at hand.
2889 *
2890 * Overview: There are 3 different indices which need to be
2891 * scrubbed, potentially, when a peer is removed:
2892 *
2893 * 1 peer's routes visible via the RIB (ie accepted routes)
2894 * 2 peer's routes visible by the (optional) peer's adj-in index
2895 * 3 other routes visible by the peer's adj-out index
2896 *
2897 * 3 there is no hurry in scrubbing, once the struct peer is
2898 * removed from bgp->peer, we could just GC such deleted peer's
2899 * adj-outs at our leisure.
2900 *
2901 * 1 and 2 must be 'scrubbed' in some way, at least made
2902 * invisible via RIB index before peer session is allowed to be
2903 * brought back up. So one needs to know when such a 'search' is
2904 * complete.
2905 *
2906 * Ideally:
2907 *
2908 * - there'd be a single global queue or a single RIB walker
2909 * - rather than tracking which route_nodes still need to be
2910 * examined on a peer basis, we'd track which peers still
2911 * aren't cleared
2912 *
2913 * Given that our per-peer prefix-counts now should be reliable,
2914 * this may actually be achievable. It doesn't seem to be a huge
2915 * problem at this time,
2916 */
24e50f20
JBD
2917 for (ain = rn->adj_in; ain; ain = ain->next)
2918 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2919 {
2920 bgp_adj_in_remove (rn, ain);
2921 bgp_unlock_node (rn);
2922 break;
2923 }
2924 for (aout = rn->adj_out; aout; aout = aout->next)
2925 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2926 {
2927 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2928 bgp_unlock_node (rn);
2929 break;
2930 }
2931
f2c31acb 2932 for (ri = rn->info; ri; ri = ri->next)
228da428 2933 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
f2c31acb 2934 {
228da428
CC
2935 struct bgp_clear_node_queue *cnq;
2936
2937 /* both unlocked in bgp_clear_node_queue_del */
67174041 2938 bgp_table_lock (bgp_node_table (rn));
228da428
CC
2939 bgp_lock_node (rn);
2940 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2941 sizeof (struct bgp_clear_node_queue));
2942 cnq->rn = rn;
2943 cnq->purpose = purpose;
2944 work_queue_add (peer->clear_node_queue, cnq);
2945 break;
f2c31acb 2946 }
65ca75e0
PJ
2947 }
2948 return;
2949}
2950
2951void
228da428
CC
2952bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2953 enum bgp_clear_route_type purpose)
65ca75e0
PJ
2954{
2955 struct bgp_node *rn;
2956 struct bgp_table *table;
2957 struct peer *rsclient;
2958 struct listnode *node, *nnode;
6cf159b9 2959
64e580a7
PJ
2960 if (peer->clear_node_queue == NULL)
2961 bgp_clear_node_queue_init (peer);
200df115 2962
ca058a30
PJ
2963 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2964 * Idle until it receives a Clearing_Completed event. This protects
2965 * against peers which flap faster than we can we clear, which could
2966 * lead to:
64e580a7
PJ
2967 *
2968 * a) race with routes from the new session being installed before
2969 * clear_route_node visits the node (to delete the route of that
2970 * peer)
2971 * b) resource exhaustion, clear_route_node likely leads to an entry
2972 * on the process_main queue. Fast-flapping could cause that queue
2973 * to grow and grow.
200df115 2974 */
ca058a30
PJ
2975 if (!peer->clear_node_queue->thread)
2976 peer_lock (peer); /* bgp_clear_node_complete */
fee0f4c6 2977
228da428 2978 switch (purpose)
fee0f4c6 2979 {
228da428
CC
2980 case BGP_CLEAR_ROUTE_NORMAL:
2981 if (safi != SAFI_MPLS_VPN)
2982 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2983 else
2984 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2985 rn = bgp_route_next (rn))
2986 if ((table = rn->info) != NULL)
2987 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2988
2989 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2990 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2991 PEER_FLAG_RSERVER_CLIENT))
2992 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2993 break;
2994
2995 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2996 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2997 break;
2998
2999 default:
3000 assert (0);
3001 break;
fee0f4c6 3002 }
65ca75e0 3003
ca058a30 3004 /* If no routes were cleared, nothing was added to workqueue, the
f2c31acb
PJ
3005 * completion function won't be run by workqueue code - call it here.
3006 * XXX: Actually, this assumption doesn't hold, see
3007 * bgp_clear_route_table(), we queue all non-empty nodes.
ca058a30
PJ
3008 *
3009 * Additionally, there is a presumption in FSM that clearing is only
f2c31acb
PJ
3010 * really needed if peer state is Established - peers in
3011 * pre-Established states shouldn't have any route-update state
3012 * associated with them (in or out).
ca058a30 3013 *
f2c31acb
PJ
3014 * We still can get here in pre-Established though, through
3015 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
3016 * check to ensure the assumption above holds.
ca058a30
PJ
3017 *
3018 * At some future point, this check could be move to the top of the
3019 * function, and do a quick early-return when state is
3020 * pre-Established, avoiding above list and table scans. Once we're
3021 * sure it is safe..
65ca75e0
PJ
3022 */
3023 if (!peer->clear_node_queue->thread)
3024 bgp_clear_node_complete (peer->clear_node_queue);
718e3744 3025}
3026
3027void
3028bgp_clear_route_all (struct peer *peer)
3029{
3030 afi_t afi;
3031 safi_t safi;
3032
3033 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3034 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
228da428 3035 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
718e3744 3036}
3037
3038void
3039bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3040{
3041 struct bgp_table *table;
3042 struct bgp_node *rn;
3043 struct bgp_adj_in *ain;
3044
3045 table = peer->bgp->rib[afi][safi];
3046
3047 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3048 for (ain = rn->adj_in; ain ; ain = ain->next)
3049 if (ain->peer == peer)
3050 {
3051 bgp_adj_in_remove (rn, ain);
3052 bgp_unlock_node (rn);
3053 break;
3054 }
3055}
93406d87 3056
3057void
3058bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3059{
3060 struct bgp_node *rn;
3061 struct bgp_info *ri;
3062 struct bgp_table *table;
3063
3064 table = peer->bgp->rib[afi][safi];
3065
3066 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3067 {
3068 for (ri = rn->info; ri; ri = ri->next)
3069 if (ri->peer == peer)
3070 {
3071 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3072 bgp_rib_remove (rn, ri, peer, afi, safi);
3073 break;
3074 }
3075 }
3076}
6b0655a2 3077
718e3744 3078/* Delete all kernel routes. */
3079void
66e5cd87 3080bgp_cleanup_routes (void)
718e3744 3081{
3082 struct bgp *bgp;
1eb8ef25 3083 struct listnode *node, *nnode;
718e3744 3084 struct bgp_node *rn;
3085 struct bgp_table *table;
3086 struct bgp_info *ri;
3087
1eb8ef25 3088 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 3089 {
3090 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3091
3092 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3093 for (ri = rn->info; ri; ri = ri->next)
3094 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3095 && ri->type == ZEBRA_ROUTE_BGP
3096 && ri->sub_type == BGP_ROUTE_NORMAL)
5a616c08 3097 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
718e3744 3098
3099 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3100
3101 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3102 for (ri = rn->info; ri; ri = ri->next)
3103 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3104 && ri->type == ZEBRA_ROUTE_BGP
3105 && ri->sub_type == BGP_ROUTE_NORMAL)
5a616c08 3106 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
718e3744 3107 }
3108}
3109
3110void
66e5cd87 3111bgp_reset (void)
718e3744 3112{
3113 vty_reset ();
3114 bgp_zclient_reset ();
3115 access_list_reset ();
3116 prefix_list_reset ();
3117}
6b0655a2 3118
718e3744 3119/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3120 value. */
3121int
3122bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3123{
3124 u_char *pnt;
3125 u_char *lim;
3126 struct prefix p;
3127 int psize;
3128 int ret;
3129
3130 /* Check peer status. */
3131 if (peer->status != Established)
3132 return 0;
3133
3134 pnt = packet->nlri;
3135 lim = pnt + packet->length;
3136
3137 for (; pnt < lim; pnt += psize)
3138 {
3139 /* Clear prefix structure. */
3140 memset (&p, 0, sizeof (struct prefix));
3141
3142 /* Fetch prefix length. */
3143 p.prefixlen = *pnt++;
3144 p.family = afi2family (packet->afi);
3145
3146 /* Already checked in nlri_sanity_check(). We do double check
3147 here. */
3148 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3149 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3150 return -1;
3151
3152 /* Packet size overflow check. */
3153 psize = PSIZE (p.prefixlen);
3154
3155 /* When packet overflow occur return immediately. */
3156 if (pnt + psize > lim)
3157 return -1;
3158
3159 /* Fetch prefix from NLRI packet. */
3160 memcpy (&p.u.prefix, pnt, psize);
3161
3162 /* Check address. */
3163 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3164 {
3165 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3166 {
f5ba3874 3167 /*
3168 * From draft-ietf-idr-bgp4-22, Section 6.3:
3169 * If a BGP router receives an UPDATE message with a
3170 * semantically incorrect NLRI field, in which a prefix is
3171 * semantically incorrect (eg. an unexpected multicast IP
3172 * address), it should ignore the prefix.
3173 */
718e3744 3174 zlog (peer->log, LOG_ERR,
3175 "IPv4 unicast NLRI is multicast address %s",
3176 inet_ntoa (p.u.prefix4));
f5ba3874 3177
718e3744 3178 return -1;
3179 }
3180 }
3181
3182#ifdef HAVE_IPV6
3183 /* Check address. */
3184 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3185 {
3186 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3187 {
3188 char buf[BUFSIZ];
3189
3190 zlog (peer->log, LOG_WARNING,
3191 "IPv6 link-local NLRI received %s ignore this NLRI",
3192 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3193
3194 continue;
3195 }
3196 }
3197#endif /* HAVE_IPV6 */
3198
3199 /* Normal process. */
3200 if (attr)
3201 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3202 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3203 else
3204 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3205 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3206
3207 /* Address family configuration mismatch or maximum-prefix count
3208 overflow. */
3209 if (ret < 0)
3210 return -1;
3211 }
3212
3213 /* Packet length consistency check. */
3214 if (pnt != lim)
3215 return -1;
3216
3217 return 0;
3218}
3219
3220/* NLRI encode syntax check routine. */
3221int
3222bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3223 bgp_size_t length)
3224{
3225 u_char *end;
3226 u_char prefixlen;
3227 int psize;
3228
3229 end = pnt + length;
3230
3231 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3232 syntactic validity. If the field is syntactically incorrect,
3233 then the Error Subcode is set to Invalid Network Field. */
3234
3235 while (pnt < end)
3236 {
3237 prefixlen = *pnt++;
3238
3239 /* Prefix length check. */
3240 if ((afi == AFI_IP && prefixlen > 32)
3241 || (afi == AFI_IP6 && prefixlen > 128))
3242 {
3243 plog_err (peer->log,
3244 "%s [Error] Update packet error (wrong prefix length %d)",
3245 peer->host, prefixlen);
3246 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3247 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3248 return -1;
3249 }
3250
3251 /* Packet size overflow check. */
3252 psize = PSIZE (prefixlen);
3253
3254 if (pnt + psize > end)
3255 {
3256 plog_err (peer->log,
3257 "%s [Error] Update packet error"
3258 " (prefix data overflow prefix size is %d)",
3259 peer->host, psize);
3260 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3261 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3262 return -1;
3263 }
3264
3265 pnt += psize;
3266 }
3267
3268 /* Packet length consistency check. */
3269 if (pnt != end)
3270 {
3271 plog_err (peer->log,
3272 "%s [Error] Update packet error"
3273 " (prefix length mismatch with total length)",
3274 peer->host);
3275 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3276 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3277 return -1;
3278 }
3279 return 0;
3280}
6b0655a2 3281
94f2b392 3282static struct bgp_static *
66e5cd87 3283bgp_static_new (void)
718e3744 3284{
393deb9b 3285 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
718e3744 3286}
3287
94f2b392 3288static void
718e3744 3289bgp_static_free (struct bgp_static *bgp_static)
3290{
3291 if (bgp_static->rmap.name)
3292 free (bgp_static->rmap.name);
3293 XFREE (MTYPE_BGP_STATIC, bgp_static);
3294}
3295
94f2b392 3296static void
fee0f4c6 3297bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3298 struct prefix *p, afi_t afi, safi_t safi)
3299{
3300 struct bgp_node *rn;
3301 struct bgp_info *ri;
3302
3303 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3304
3305 /* Check selected route and self inserted route. */
3306 for (ri = rn->info; ri; ri = ri->next)
3307 if (ri->peer == bgp->peer_self
3308 && ri->type == ZEBRA_ROUTE_BGP
3309 && ri->sub_type == BGP_ROUTE_STATIC)
3310 break;
3311
3312 /* Withdraw static BGP route from routing table. */
3313 if (ri)
3314 {
fee0f4c6 3315 bgp_info_delete (rn, ri);
1a392d46 3316 bgp_process (bgp, rn, afi, safi);
fee0f4c6 3317 }
3318
3319 /* Unlock bgp_node_lookup. */
3320 bgp_unlock_node (rn);
3321}
3322
94f2b392 3323static void
fee0f4c6 3324bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
fb982c25
PJ
3325 struct bgp_static *bgp_static,
3326 afi_t afi, safi_t safi)
fee0f4c6 3327{
3328 struct bgp_node *rn;
3329 struct bgp_info *ri;
3330 struct bgp_info *new;
3331 struct bgp_info info;
fee0f4c6 3332 struct attr *attr_new;
e16a4133 3333 struct attr attr;
558d1fec
JBD
3334 struct attr new_attr;
3335 struct attr_extra new_extra;
fee0f4c6 3336 struct bgp *bgp;
3337 int ret;
3338 char buf[SU_ADDRSTRLEN];
3339
3340 bgp = rsclient->bgp;
3341
06e110f9
PJ
3342 assert (bgp_static);
3343 if (!bgp_static)
3344 return;
3345
fee0f4c6 3346 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3347
3348 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
06e110f9
PJ
3349
3350 attr.nexthop = bgp_static->igpnexthop;
3351 attr.med = bgp_static->igpmetric;
3352 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
41367172 3353
41367172
PJ
3354 if (bgp_static->atomic)
3355 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3356
fee0f4c6 3357 /* Apply network route-map for export to this rsclient. */
3358 if (bgp_static->rmap.name)
3359 {
fb982c25 3360 struct attr attr_tmp = attr;
fee0f4c6 3361 info.peer = rsclient;
fb982c25
PJ
3362 info.attr = &attr_tmp;
3363
fee0f4c6 3364 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3365 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3366
3367 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3368
3369 rsclient->rmap_type = 0;
3370
3371 if (ret == RMAP_DENYMATCH)
3372 {
3373 /* Free uninterned attribute. */
fb982c25 3374 bgp_attr_flush (&attr_tmp);
fee0f4c6 3375
3376 /* Unintern original. */
f6f434b2 3377 aspath_unintern (&attr.aspath);
fee0f4c6 3378 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
fb982c25
PJ
3379 bgp_attr_extra_free (&attr);
3380
fee0f4c6 3381 return;
3382 }
fb982c25 3383 attr_new = bgp_attr_intern (&attr_tmp);
fee0f4c6 3384 }
3385 else
3386 attr_new = bgp_attr_intern (&attr);
558d1fec
JBD
3387
3388 new_attr.extra = &new_extra;
7badc263 3389 bgp_attr_dup(&new_attr, attr_new);
fb982c25 3390
fee0f4c6 3391 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3392
fb982c25
PJ
3393 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3394 == RMAP_DENY)
3395 {
fee0f4c6 3396 /* This BGP update is filtered. Log the reason then update BGP entry. */
3397 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 3398 zlog (rsclient->log, LOG_DEBUG,
fee0f4c6 3399 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3400 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3401 p->prefixlen, rsclient->host);
3402
3403 bgp->peer_self->rmap_type = 0;
3404
f6f434b2
PJ
3405 bgp_attr_unintern (&attr_new);
3406 aspath_unintern (&attr.aspath);
fb982c25 3407 bgp_attr_extra_free (&attr);
fee0f4c6 3408
3409 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3410
3411 return;
fb982c25 3412 }
fee0f4c6 3413
3414 bgp->peer_self->rmap_type = 0;
3415
f6f434b2 3416 bgp_attr_unintern (&attr_new);
fee0f4c6 3417 attr_new = bgp_attr_intern (&new_attr);
3418
3419 for (ri = rn->info; ri; ri = ri->next)
3420 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3421 && ri->sub_type == BGP_ROUTE_STATIC)
3422 break;
3423
3424 if (ri)
3425 {
8d45210e
AS
3426 if (attrhash_cmp (ri->attr, attr_new) &&
3427 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
fee0f4c6 3428 {
3429 bgp_unlock_node (rn);
f6f434b2
PJ
3430 bgp_attr_unintern (&attr_new);
3431 aspath_unintern (&attr.aspath);
fb982c25 3432 bgp_attr_extra_free (&attr);
fee0f4c6 3433 return;
3434 }
3435 else
3436 {
3437 /* The attribute is changed. */
1a392d46 3438 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
fee0f4c6 3439
3440 /* Rewrite BGP route information. */
8d45210e
AS
3441 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3442 bgp_info_restore(rn, ri);
f6f434b2 3443 bgp_attr_unintern (&ri->attr);
fee0f4c6 3444 ri->attr = attr_new;
65957886 3445 ri->uptime = bgp_clock ();
fee0f4c6 3446
3447 /* Process change. */
3448 bgp_process (bgp, rn, afi, safi);
3449 bgp_unlock_node (rn);
f6f434b2 3450 aspath_unintern (&attr.aspath);
fb982c25 3451 bgp_attr_extra_free (&attr);
fee0f4c6 3452 return;
fb982c25 3453 }
fee0f4c6 3454 }
fb018d25 3455
fee0f4c6 3456 /* Make new BGP info. */
fb018d25
DS
3457 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3458 attr_new, rn);
fee0f4c6 3459 SET_FLAG (new->flags, BGP_INFO_VALID);
fee0f4c6 3460
3461 /* Register new BGP information. */
3462 bgp_info_add (rn, new);
200df115 3463
3464 /* route_node_get lock */
3465 bgp_unlock_node (rn);
3466
fee0f4c6 3467 /* Process change. */
3468 bgp_process (bgp, rn, afi, safi);
3469
3470 /* Unintern original. */
f6f434b2 3471 aspath_unintern (&attr.aspath);
fb982c25 3472 bgp_attr_extra_free (&attr);
fee0f4c6 3473}
3474
94f2b392 3475static void
fee0f4c6 3476bgp_static_update_main (struct bgp *bgp, struct prefix *p,
718e3744 3477 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3478{
3479 struct bgp_node *rn;
3480 struct bgp_info *ri;
3481 struct bgp_info *new;
3482 struct bgp_info info;
e16a4133 3483 struct attr attr;
718e3744 3484 struct attr *attr_new;
3485 int ret;
3486
dd8103a9
PJ
3487 assert (bgp_static);
3488 if (!bgp_static)
3489 return;
3490
fee0f4c6 3491 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 3492
3493 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
dd8103a9
PJ
3494
3495 attr.nexthop = bgp_static->igpnexthop;
3496 attr.med = bgp_static->igpmetric;
3497 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
718e3744 3498
41367172
PJ
3499 if (bgp_static->atomic)
3500 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3501
718e3744 3502 /* Apply route-map. */
3503 if (bgp_static->rmap.name)
3504 {
fb982c25 3505 struct attr attr_tmp = attr;
718e3744 3506 info.peer = bgp->peer_self;
286e1e71 3507 info.attr = &attr_tmp;
718e3744 3508
fee0f4c6 3509 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3510
718e3744 3511 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
286e1e71 3512
fee0f4c6 3513 bgp->peer_self->rmap_type = 0;
3514
718e3744 3515 if (ret == RMAP_DENYMATCH)
3516 {
3517 /* Free uninterned attribute. */
286e1e71 3518 bgp_attr_flush (&attr_tmp);
718e3744 3519
3520 /* Unintern original. */
f6f434b2 3521 aspath_unintern (&attr.aspath);
fb982c25 3522 bgp_attr_extra_free (&attr);
718e3744 3523 bgp_static_withdraw (bgp, p, afi, safi);
3524 return;
3525 }
286e1e71 3526 attr_new = bgp_attr_intern (&attr_tmp);
718e3744 3527 }
286e1e71 3528 else
3529 attr_new = bgp_attr_intern (&attr);
718e3744 3530
3531 for (ri = rn->info; ri; ri = ri->next)
3532 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3533 && ri->sub_type == BGP_ROUTE_STATIC)
3534 break;
3535
3536 if (ri)
3537 {
8d45210e
AS
3538 if (attrhash_cmp (ri->attr, attr_new) &&
3539 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
718e3744 3540 {
3541 bgp_unlock_node (rn);
f6f434b2
PJ
3542 bgp_attr_unintern (&attr_new);
3543 aspath_unintern (&attr.aspath);
fb982c25 3544 bgp_attr_extra_free (&attr);
718e3744 3545 return;
3546 }
3547 else
3548 {
3549 /* The attribute is changed. */
1a392d46 3550 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 3551
3552 /* Rewrite BGP route information. */
8d45210e
AS
3553 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3554 bgp_info_restore(rn, ri);
3555 else
3556 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
f6f434b2 3557 bgp_attr_unintern (&ri->attr);
718e3744 3558 ri->attr = attr_new;
65957886 3559 ri->uptime = bgp_clock ();
718e3744 3560
3561 /* Process change. */
3562 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3563 bgp_process (bgp, rn, afi, safi);
3564 bgp_unlock_node (rn);
f6f434b2 3565 aspath_unintern (&attr.aspath);
fb982c25 3566 bgp_attr_extra_free (&attr);
718e3744 3567 return;
3568 }
3569 }
3570
3571 /* Make new BGP info. */
fb018d25
DS
3572 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self, attr_new,
3573 rn);
718e3744 3574 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 3575
3576 /* Aggregate address increment. */
3577 bgp_aggregate_increment (bgp, p, new, afi, safi);
3578
3579 /* Register new BGP information. */
3580 bgp_info_add (rn, new);
200df115 3581
3582 /* route_node_get lock */
3583 bgp_unlock_node (rn);
3584
718e3744 3585 /* Process change. */
3586 bgp_process (bgp, rn, afi, safi);
3587
3588 /* Unintern original. */
f6f434b2 3589 aspath_unintern (&attr.aspath);
fb982c25 3590 bgp_attr_extra_free (&attr);
718e3744 3591}
3592
fee0f4c6 3593void
3594bgp_static_update (struct bgp *bgp, struct prefix *p,
3595 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3596{
3597 struct peer *rsclient;
1eb8ef25 3598 struct listnode *node, *nnode;
fee0f4c6 3599
3600 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3601
1eb8ef25 3602 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 3603 {
da5b30f6
PJ
3604 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3605 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
fee0f4c6 3606 }
3607}
3608
94f2b392 3609static void
4c9641ba
ML
3610bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3611 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 3612{
3613 struct bgp_node *rn;
3614 struct bgp_info *new;
fb982c25 3615
fee0f4c6 3616 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 3617
3618 /* Make new BGP info. */
fb018d25
DS
3619 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3620 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
3621
718e3744 3622 SET_FLAG (new->flags, BGP_INFO_VALID);
fb982c25
PJ
3623 new->extra = bgp_info_extra_new();
3624 memcpy (new->extra->tag, tag, 3);
718e3744 3625
3626 /* Aggregate address increment. */
200df115 3627 bgp_aggregate_increment (bgp, p, new, afi, safi);
718e3744 3628
3629 /* Register new BGP information. */
200df115 3630 bgp_info_add (rn, new);
718e3744 3631
200df115 3632 /* route_node_get lock */
3633 bgp_unlock_node (rn);
3634
718e3744 3635 /* Process change. */
3636 bgp_process (bgp, rn, afi, safi);
3637}
3638
3639void
3640bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3641 safi_t safi)
3642{
3643 struct bgp_node *rn;
3644 struct bgp_info *ri;
3645
fee0f4c6 3646 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 3647
3648 /* Check selected route and self inserted route. */
3649 for (ri = rn->info; ri; ri = ri->next)
3650 if (ri->peer == bgp->peer_self
3651 && ri->type == ZEBRA_ROUTE_BGP
3652 && ri->sub_type == BGP_ROUTE_STATIC)
3653 break;
3654
3655 /* Withdraw static BGP route from routing table. */
3656 if (ri)
3657 {
3658 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
718e3744 3659 bgp_info_delete (rn, ri);
1a392d46 3660 bgp_process (bgp, rn, afi, safi);
718e3744 3661 }
3662
3663 /* Unlock bgp_node_lookup. */
3664 bgp_unlock_node (rn);
3665}
3666
fee0f4c6 3667void
3668bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3669{
3670 struct bgp_static *bgp_static;
3671 struct bgp *bgp;
3672 struct bgp_node *rn;
3673 struct prefix *p;
3674
3675 bgp = rsclient->bgp;
3676
3677 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3678 if ((bgp_static = rn->info) != NULL)
3679 {
3680 p = &rn->p;
3681
3682 bgp_static_update_rsclient (rsclient, p, bgp_static,
3683 afi, safi);
3684 }
3685}
3686
94f2b392 3687static void
4c9641ba
ML
3688bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3689 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 3690{
3691 struct bgp_node *rn;
3692 struct bgp_info *ri;
3693
fee0f4c6 3694 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 3695
3696 /* Check selected route and self inserted route. */
3697 for (ri = rn->info; ri; ri = ri->next)
3698 if (ri->peer == bgp->peer_self
3699 && ri->type == ZEBRA_ROUTE_BGP
3700 && ri->sub_type == BGP_ROUTE_STATIC)
3701 break;
3702
3703 /* Withdraw static BGP route from routing table. */
3704 if (ri)
3705 {
3706 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
718e3744 3707 bgp_info_delete (rn, ri);
1a392d46 3708 bgp_process (bgp, rn, afi, safi);
718e3744 3709 }
3710
3711 /* Unlock bgp_node_lookup. */
3712 bgp_unlock_node (rn);
3713}
3714
3715/* Configure static BGP network. When user don't run zebra, static
3716 route should be installed as valid. */
94f2b392 3717static int
fd79ac91 3718bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
c8f3fe30 3719 afi_t afi, safi_t safi, const char *rmap, int backdoor)
718e3744 3720{
3721 int ret;
3722 struct prefix p;
3723 struct bgp_static *bgp_static;
3724 struct bgp_node *rn;
41367172 3725 u_char need_update = 0;
718e3744 3726
3727 /* Convert IP prefix string to struct prefix. */
3728 ret = str2prefix (ip_str, &p);
3729 if (! ret)
3730 {
3731 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3732 return CMD_WARNING;
3733 }
3734#ifdef HAVE_IPV6
3735 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3736 {
3737 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3738 VTY_NEWLINE);
3739 return CMD_WARNING;
3740 }
3741#endif /* HAVE_IPV6 */
3742
3743 apply_mask (&p);
3744
3745 /* Set BGP static route configuration. */
3746 rn = bgp_node_get (bgp->route[afi][safi], &p);
3747
3748 if (rn->info)
3749 {
3750 /* Configuration change. */
3751 bgp_static = rn->info;
3752
3753 /* Check previous routes are installed into BGP. */
c8f3fe30
PJ
3754 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3755 need_update = 1;
41367172 3756
718e3744 3757 bgp_static->backdoor = backdoor;
41367172 3758
718e3744 3759 if (rmap)
3760 {
3761 if (bgp_static->rmap.name)
3762 free (bgp_static->rmap.name);
3763 bgp_static->rmap.name = strdup (rmap);
3764 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3765 }
3766 else
3767 {
3768 if (bgp_static->rmap.name)
3769 free (bgp_static->rmap.name);
3770 bgp_static->rmap.name = NULL;
3771 bgp_static->rmap.map = NULL;
3772 bgp_static->valid = 0;
3773 }
3774 bgp_unlock_node (rn);
3775 }
3776 else
3777 {
3778 /* New configuration. */
3779 bgp_static = bgp_static_new ();
3780 bgp_static->backdoor = backdoor;
3781 bgp_static->valid = 0;
3782 bgp_static->igpmetric = 0;
3783 bgp_static->igpnexthop.s_addr = 0;
41367172 3784
718e3744 3785 if (rmap)
3786 {
3787 if (bgp_static->rmap.name)
3788 free (bgp_static->rmap.name);
3789 bgp_static->rmap.name = strdup (rmap);
3790 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3791 }
3792 rn->info = bgp_static;
3793 }
3794
3795 /* If BGP scan is not enabled, we should install this route here. */
3796 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3797 {
3798 bgp_static->valid = 1;
3799
3800 if (need_update)
3801 bgp_static_withdraw (bgp, &p, afi, safi);
3802
3803 if (! bgp_static->backdoor)
3804 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3805 }
3806
3807 return CMD_SUCCESS;
3808}
3809
3810/* Configure static BGP network. */
94f2b392 3811static int
fd79ac91 3812bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4c9641ba 3813 afi_t afi, safi_t safi)
718e3744 3814{
3815 int ret;
3816 struct prefix p;
3817 struct bgp_static *bgp_static;
3818 struct bgp_node *rn;
3819
3820 /* Convert IP prefix string to struct prefix. */
3821 ret = str2prefix (ip_str, &p);
3822 if (! ret)
3823 {
3824 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3825 return CMD_WARNING;
3826 }
3827#ifdef HAVE_IPV6
3828 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3829 {
3830 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3831 VTY_NEWLINE);
3832 return CMD_WARNING;
3833 }
3834#endif /* HAVE_IPV6 */
3835
3836 apply_mask (&p);
3837
3838 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3839 if (! rn)
3840 {
3841 vty_out (vty, "%% Can't find specified static route configuration.%s",
3842 VTY_NEWLINE);
3843 return CMD_WARNING;
3844 }
3845
3846 bgp_static = rn->info;
41367172 3847
718e3744 3848 /* Update BGP RIB. */
3849 if (! bgp_static->backdoor)
3850 bgp_static_withdraw (bgp, &p, afi, safi);
3851
3852 /* Clear configuration. */
3853 bgp_static_free (bgp_static);
3854 rn->info = NULL;
3855 bgp_unlock_node (rn);
3856 bgp_unlock_node (rn);
3857
3858 return CMD_SUCCESS;
3859}
3860
3861/* Called from bgp_delete(). Delete all static routes from the BGP
3862 instance. */
3863void
3864bgp_static_delete (struct bgp *bgp)
3865{
3866 afi_t afi;
3867 safi_t safi;
3868 struct bgp_node *rn;
3869 struct bgp_node *rm;
3870 struct bgp_table *table;
3871 struct bgp_static *bgp_static;
3872
3873 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3874 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3875 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3876 if (rn->info != NULL)
3877 {
3878 if (safi == SAFI_MPLS_VPN)
3879 {
3880 table = rn->info;
3881
3882 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3883 {
3884 bgp_static = rn->info;
3885 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3886 AFI_IP, SAFI_MPLS_VPN,
3887 (struct prefix_rd *)&rn->p,
3888 bgp_static->tag);
3889 bgp_static_free (bgp_static);
3890 rn->info = NULL;
3891 bgp_unlock_node (rn);
3892 }
3893 }
3894 else
3895 {
3896 bgp_static = rn->info;
3897 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3898 bgp_static_free (bgp_static);
3899 rn->info = NULL;
3900 bgp_unlock_node (rn);
3901 }
3902 }
3903}
3904
3905int
fd79ac91 3906bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3907 const char *tag_str)
718e3744 3908{
3909 int ret;
3910 struct prefix p;
3911 struct prefix_rd prd;
3912 struct bgp *bgp;
3913 struct bgp_node *prn;
3914 struct bgp_node *rn;
3915 struct bgp_table *table;
3916 struct bgp_static *bgp_static;
3917 u_char tag[3];
3918
3919 bgp = vty->index;
3920
3921 ret = str2prefix (ip_str, &p);
3922 if (! ret)
3923 {
3924 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3925 return CMD_WARNING;
3926 }
3927 apply_mask (&p);
3928
3929 ret = str2prefix_rd (rd_str, &prd);
3930 if (! ret)
3931 {
3932 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3933 return CMD_WARNING;
3934 }
3935
3936 ret = str2tag (tag_str, tag);
3937 if (! ret)
3938 {
3939 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3940 return CMD_WARNING;
3941 }
3942
3943 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3944 (struct prefix *)&prd);
3945 if (prn->info == NULL)
64e580a7 3946 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
718e3744 3947 else
3948 bgp_unlock_node (prn);
3949 table = prn->info;
3950
3951 rn = bgp_node_get (table, &p);
3952
3953 if (rn->info)
3954 {
3955 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3956 bgp_unlock_node (rn);
3957 }
3958 else
3959 {
3960 /* New configuration. */
3961 bgp_static = bgp_static_new ();
3962 bgp_static->valid = 1;
3963 memcpy (bgp_static->tag, tag, 3);
3964 rn->info = bgp_static;
3965
3966 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3967 }
3968
3969 return CMD_SUCCESS;
3970}
3971
3972/* Configure static BGP network. */
3973int
fd79ac91 3974bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3975 const char *rd_str, const char *tag_str)
718e3744 3976{
3977 int ret;
3978 struct bgp *bgp;
3979 struct prefix p;
3980 struct prefix_rd prd;
3981 struct bgp_node *prn;
3982 struct bgp_node *rn;
3983 struct bgp_table *table;
3984 struct bgp_static *bgp_static;
3985 u_char tag[3];
3986
3987 bgp = vty->index;
3988
3989 /* Convert IP prefix string to struct prefix. */
3990 ret = str2prefix (ip_str, &p);
3991 if (! ret)
3992 {
3993 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3994 return CMD_WARNING;
3995 }
3996 apply_mask (&p);
3997
3998 ret = str2prefix_rd (rd_str, &prd);
3999 if (! ret)
4000 {
4001 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4002 return CMD_WARNING;
4003 }
4004
4005 ret = str2tag (tag_str, tag);
4006 if (! ret)
4007 {
4008 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4009 return CMD_WARNING;
4010 }
4011
4012 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4013 (struct prefix *)&prd);
4014 if (prn->info == NULL)
64e580a7 4015 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
718e3744 4016 else
4017 bgp_unlock_node (prn);
4018 table = prn->info;
4019
4020 rn = bgp_node_lookup (table, &p);
4021
4022 if (rn)
4023 {
4024 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4025
4026 bgp_static = rn->info;
4027 bgp_static_free (bgp_static);
4028 rn->info = NULL;
4029 bgp_unlock_node (rn);
4030 bgp_unlock_node (rn);
4031 }
4032 else
4033 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4034
4035 return CMD_SUCCESS;
4036}
6b0655a2 4037
718e3744 4038DEFUN (bgp_network,
4039 bgp_network_cmd,
4040 "network A.B.C.D/M",
4041 "Specify a network to announce via BGP\n"
4042 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4043{
4044 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 4045 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4046}
4047
4048DEFUN (bgp_network_route_map,
4049 bgp_network_route_map_cmd,
4050 "network A.B.C.D/M route-map WORD",
4051 "Specify a network to announce via BGP\n"
4052 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4053 "Route-map to modify the attributes\n"
4054 "Name of the route map\n")
4055{
4056 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 4057 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 4058}
4059
4060DEFUN (bgp_network_backdoor,
4061 bgp_network_backdoor_cmd,
4062 "network A.B.C.D/M backdoor",
4063 "Specify a network to announce via BGP\n"
4064 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4065 "Specify a BGP backdoor route\n")
4066{
41367172 4067 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
c8f3fe30 4068 NULL, 1);
718e3744 4069}
4070
4071DEFUN (bgp_network_mask,
4072 bgp_network_mask_cmd,
4073 "network A.B.C.D mask A.B.C.D",
4074 "Specify a network to announce via BGP\n"
4075 "Network number\n"
4076 "Network mask\n"
4077 "Network mask\n")
4078{
4079 int ret;
4080 char prefix_str[BUFSIZ];
41367172 4081
718e3744 4082 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4083 if (! ret)
4084 {
4085 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4086 return CMD_WARNING;
4087 }
4088
4089 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4090 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4091}
4092
4093DEFUN (bgp_network_mask_route_map,
4094 bgp_network_mask_route_map_cmd,
4095 "network A.B.C.D mask A.B.C.D route-map WORD",
4096 "Specify a network to announce via BGP\n"
4097 "Network number\n"
4098 "Network mask\n"
4099 "Network mask\n"
4100 "Route-map to modify the attributes\n"
4101 "Name of the route map\n")
4102{
4103 int ret;
4104 char prefix_str[BUFSIZ];
41367172 4105
718e3744 4106 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4107 if (! ret)
4108 {
4109 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4110 return CMD_WARNING;
4111 }
4112
4113 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4114 AFI_IP, bgp_node_safi (vty), argv[2], 0);
718e3744 4115}
4116
4117DEFUN (bgp_network_mask_backdoor,
4118 bgp_network_mask_backdoor_cmd,
4119 "network A.B.C.D mask A.B.C.D backdoor",
4120 "Specify a network to announce via BGP\n"
4121 "Network number\n"
4122 "Network mask\n"
4123 "Network mask\n"
4124 "Specify a BGP backdoor route\n")
4125{
4126 int ret;
4127 char prefix_str[BUFSIZ];
41367172 4128
718e3744 4129 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4130 if (! ret)
4131 {
4132 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4133 return CMD_WARNING;
4134 }
4135
41367172 4136 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 4137 NULL, 1);
718e3744 4138}
4139
4140DEFUN (bgp_network_mask_natural,
4141 bgp_network_mask_natural_cmd,
4142 "network A.B.C.D",
4143 "Specify a network to announce via BGP\n"
4144 "Network number\n")
4145{
4146 int ret;
4147 char prefix_str[BUFSIZ];
4148
4149 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4150 if (! ret)
4151 {
4152 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4153 return CMD_WARNING;
4154 }
4155
4156 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4157 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4158}
4159
4160DEFUN (bgp_network_mask_natural_route_map,
4161 bgp_network_mask_natural_route_map_cmd,
4162 "network A.B.C.D route-map WORD",
4163 "Specify a network to announce via BGP\n"
4164 "Network number\n"
4165 "Route-map to modify the attributes\n"
4166 "Name of the route map\n")
4167{
4168 int ret;
4169 char prefix_str[BUFSIZ];
4170
4171 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4172 if (! ret)
4173 {
4174 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4175 return CMD_WARNING;
4176 }
4177
4178 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4179 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 4180}
4181
4182DEFUN (bgp_network_mask_natural_backdoor,
4183 bgp_network_mask_natural_backdoor_cmd,
4184 "network A.B.C.D backdoor",
4185 "Specify a network to announce via BGP\n"
4186 "Network number\n"
4187 "Specify a BGP backdoor route\n")
4188{
4189 int ret;
4190 char prefix_str[BUFSIZ];
4191
4192 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4193 if (! ret)
4194 {
4195 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4196 return CMD_WARNING;
4197 }
4198
41367172 4199 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 4200 NULL, 1);
718e3744 4201}
4202
4203DEFUN (no_bgp_network,
4204 no_bgp_network_cmd,
4205 "no network A.B.C.D/M",
4206 NO_STR
4207 "Specify a network to announce via BGP\n"
4208 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4209{
4210 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4211 bgp_node_safi (vty));
4212}
4213
4214ALIAS (no_bgp_network,
4215 no_bgp_network_route_map_cmd,
4216 "no network A.B.C.D/M route-map WORD",
4217 NO_STR
4218 "Specify a network to announce via BGP\n"
4219 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4220 "Route-map to modify the attributes\n"
4221 "Name of the route map\n")
4222
4223ALIAS (no_bgp_network,
4224 no_bgp_network_backdoor_cmd,
4225 "no network A.B.C.D/M backdoor",
4226 NO_STR
4227 "Specify a network to announce via BGP\n"
4228 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4229 "Specify a BGP backdoor route\n")
4230
4231DEFUN (no_bgp_network_mask,
4232 no_bgp_network_mask_cmd,
4233 "no network A.B.C.D mask A.B.C.D",
4234 NO_STR
4235 "Specify a network to announce via BGP\n"
4236 "Network number\n"
4237 "Network mask\n"
4238 "Network mask\n")
4239{
4240 int ret;
4241 char prefix_str[BUFSIZ];
4242
4243 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4244 if (! ret)
4245 {
4246 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4247 return CMD_WARNING;
4248 }
4249
4250 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4251 bgp_node_safi (vty));
4252}
4253
4254ALIAS (no_bgp_network_mask,
4255 no_bgp_network_mask_route_map_cmd,
4256 "no network A.B.C.D mask A.B.C.D route-map WORD",
4257 NO_STR
4258 "Specify a network to announce via BGP\n"
4259 "Network number\n"
4260 "Network mask\n"
4261 "Network mask\n"
4262 "Route-map to modify the attributes\n"
4263 "Name of the route map\n")
4264
4265ALIAS (no_bgp_network_mask,
4266 no_bgp_network_mask_backdoor_cmd,
4267 "no network A.B.C.D mask A.B.C.D backdoor",
4268 NO_STR
4269 "Specify a network to announce via BGP\n"
4270 "Network number\n"
4271 "Network mask\n"
4272 "Network mask\n"
4273 "Specify a BGP backdoor route\n")
4274
4275DEFUN (no_bgp_network_mask_natural,
4276 no_bgp_network_mask_natural_cmd,
4277 "no network A.B.C.D",
4278 NO_STR
4279 "Specify a network to announce via BGP\n"
4280 "Network number\n")
4281{
4282 int ret;
4283 char prefix_str[BUFSIZ];
4284
4285 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4286 if (! ret)
4287 {
4288 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4289 return CMD_WARNING;
4290 }
4291
4292 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4293 bgp_node_safi (vty));
4294}
4295
4296ALIAS (no_bgp_network_mask_natural,
4297 no_bgp_network_mask_natural_route_map_cmd,
4298 "no network A.B.C.D route-map WORD",
4299 NO_STR
4300 "Specify a network to announce via BGP\n"
4301 "Network number\n"
4302 "Route-map to modify the attributes\n"
4303 "Name of the route map\n")
4304
4305ALIAS (no_bgp_network_mask_natural,
4306 no_bgp_network_mask_natural_backdoor_cmd,
4307 "no network A.B.C.D backdoor",
4308 NO_STR
4309 "Specify a network to announce via BGP\n"
4310 "Network number\n"
4311 "Specify a BGP backdoor route\n")
4312
4313#ifdef HAVE_IPV6
4314DEFUN (ipv6_bgp_network,
4315 ipv6_bgp_network_cmd,
4316 "network X:X::X:X/M",
4317 "Specify a network to announce via BGP\n"
4318 "IPv6 prefix <network>/<length>\n")
4319{
73bfe0bd 4320 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
c8f3fe30 4321 NULL, 0);
718e3744 4322}
4323
4324DEFUN (ipv6_bgp_network_route_map,
4325 ipv6_bgp_network_route_map_cmd,
4326 "network X:X::X:X/M route-map WORD",
4327 "Specify a network to announce via BGP\n"
4328 "IPv6 prefix <network>/<length>\n"
4329 "Route-map to modify the attributes\n"
4330 "Name of the route map\n")
4331{
4332 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
c8f3fe30 4333 bgp_node_safi (vty), argv[1], 0);
718e3744 4334}
4335
4336DEFUN (no_ipv6_bgp_network,
4337 no_ipv6_bgp_network_cmd,
4338 "no network X:X::X:X/M",
4339 NO_STR
4340 "Specify a network to announce via BGP\n"
4341 "IPv6 prefix <network>/<length>\n")
4342{
73bfe0bd 4343 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
718e3744 4344}
4345
4346ALIAS (no_ipv6_bgp_network,
4347 no_ipv6_bgp_network_route_map_cmd,
4348 "no network X:X::X:X/M route-map WORD",
4349 NO_STR
4350 "Specify a network to announce via BGP\n"
4351 "IPv6 prefix <network>/<length>\n"
4352 "Route-map to modify the attributes\n"
4353 "Name of the route map\n")
4354
4355ALIAS (ipv6_bgp_network,
4356 old_ipv6_bgp_network_cmd,
4357 "ipv6 bgp network X:X::X:X/M",
4358 IPV6_STR
4359 BGP_STR
4360 "Specify a network to announce via BGP\n"
4361 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4362
4363ALIAS (no_ipv6_bgp_network,
4364 old_no_ipv6_bgp_network_cmd,
4365 "no ipv6 bgp network X:X::X:X/M",
4366 NO_STR
4367 IPV6_STR
4368 BGP_STR
4369 "Specify a network to announce via BGP\n"
4370 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4371#endif /* HAVE_IPV6 */
c8f3fe30
PJ
4372
4373/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4374ALIAS_DEPRECATED (bgp_network,
4375 bgp_network_ttl_cmd,
4376 "network A.B.C.D/M pathlimit <0-255>",
4377 "Specify a network to announce via BGP\n"
4378 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4379 "AS-Path hopcount limit attribute\n"
4380 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4381ALIAS_DEPRECATED (bgp_network_backdoor,
4382 bgp_network_backdoor_ttl_cmd,
4383 "network A.B.C.D/M backdoor pathlimit <0-255>",
4384 "Specify a network to announce via BGP\n"
4385 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4386 "Specify a BGP backdoor route\n"
4387 "AS-Path hopcount limit attribute\n"
4388 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4389ALIAS_DEPRECATED (bgp_network_mask,
4390 bgp_network_mask_ttl_cmd,
4391 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4392 "Specify a network to announce via BGP\n"
4393 "Network number\n"
4394 "Network mask\n"
4395 "Network mask\n"
4396 "AS-Path hopcount limit attribute\n"
4397 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4398ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4399 bgp_network_mask_backdoor_ttl_cmd,
4400 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4401 "Specify a network to announce via BGP\n"
4402 "Network number\n"
4403 "Network mask\n"
4404 "Network mask\n"
4405 "Specify a BGP backdoor route\n"
4406 "AS-Path hopcount limit attribute\n"
4407 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4408ALIAS_DEPRECATED (bgp_network_mask_natural,
4409 bgp_network_mask_natural_ttl_cmd,
4410 "network A.B.C.D pathlimit <0-255>",
4411 "Specify a network to announce via BGP\n"
4412 "Network number\n"
4413 "AS-Path hopcount limit attribute\n"
4414 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4415ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4416 bgp_network_mask_natural_backdoor_ttl_cmd,
2b00515a 4417 "network A.B.C.D backdoor pathlimit <1-255>",
c8f3fe30
PJ
4418 "Specify a network to announce via BGP\n"
4419 "Network number\n"
4420 "Specify a BGP backdoor route\n"
4421 "AS-Path hopcount limit attribute\n"
4422 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4423ALIAS_DEPRECATED (no_bgp_network,
4424 no_bgp_network_ttl_cmd,
4425 "no network A.B.C.D/M pathlimit <0-255>",
4426 NO_STR
4427 "Specify a network to announce via BGP\n"
4428 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4429 "AS-Path hopcount limit attribute\n"
4430 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4431ALIAS_DEPRECATED (no_bgp_network,
4432 no_bgp_network_backdoor_ttl_cmd,
4433 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4434 NO_STR
4435 "Specify a network to announce via BGP\n"
4436 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4437 "Specify a BGP backdoor route\n"
4438 "AS-Path hopcount limit attribute\n"
4439 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4440ALIAS_DEPRECATED (no_bgp_network,
4441 no_bgp_network_mask_ttl_cmd,
4442 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4443 NO_STR
4444 "Specify a network to announce via BGP\n"
4445 "Network number\n"
4446 "Network mask\n"
4447 "Network mask\n"
4448 "AS-Path hopcount limit attribute\n"
4449 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4450ALIAS_DEPRECATED (no_bgp_network_mask,
4451 no_bgp_network_mask_backdoor_ttl_cmd,
4452 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4453 NO_STR
4454 "Specify a network to announce via BGP\n"
4455 "Network number\n"
4456 "Network mask\n"
4457 "Network mask\n"
4458 "Specify a BGP backdoor route\n"
4459 "AS-Path hopcount limit attribute\n"
4460 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4461ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4462 no_bgp_network_mask_natural_ttl_cmd,
4463 "no network A.B.C.D pathlimit <0-255>",
4464 NO_STR
4465 "Specify a network to announce via BGP\n"
4466 "Network number\n"
4467 "AS-Path hopcount limit attribute\n"
4468 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4469ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4470 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4471 "no network A.B.C.D backdoor pathlimit <0-255>",
4472 NO_STR
4473 "Specify a network to announce via BGP\n"
4474 "Network number\n"
4475 "Specify a BGP backdoor route\n"
4476 "AS-Path hopcount limit attribute\n"
4477 "AS-Pathlimit TTL, in number of AS-Path hops\n")
3bde17f1 4478#ifdef HAVE_IPV6
c8f3fe30
PJ
4479ALIAS_DEPRECATED (ipv6_bgp_network,
4480 ipv6_bgp_network_ttl_cmd,
4481 "network X:X::X:X/M pathlimit <0-255>",
4482 "Specify a network to announce via BGP\n"
4483 "IPv6 prefix <network>/<length>\n"
4484 "AS-Path hopcount limit attribute\n"
4485 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4486ALIAS_DEPRECATED (no_ipv6_bgp_network,
4487 no_ipv6_bgp_network_ttl_cmd,
4488 "no network X:X::X:X/M pathlimit <0-255>",
4489 NO_STR
4490 "Specify a network to announce via BGP\n"
4491 "IPv6 prefix <network>/<length>\n"
4492 "AS-Path hopcount limit attribute\n"
4493 "AS-Pathlimit TTL, in number of AS-Path hops\n")
3bde17f1 4494#endif /* HAVE_IPV6 */
6b0655a2 4495
718e3744 4496/* Aggreagete address:
4497
4498 advertise-map Set condition to advertise attribute
4499 as-set Generate AS set path information
4500 attribute-map Set attributes of aggregate
4501 route-map Set parameters of aggregate
4502 summary-only Filter more specific routes from updates
4503 suppress-map Conditionally filter more specific routes from updates
4504 <cr>
4505 */
4506struct bgp_aggregate
4507{
4508 /* Summary-only flag. */
4509 u_char summary_only;
4510
4511 /* AS set generation. */
4512 u_char as_set;
4513
4514 /* Route-map for aggregated route. */
4515 struct route_map *map;
4516
4517 /* Suppress-count. */
4518 unsigned long count;
4519
4520 /* SAFI configuration. */
4521 safi_t safi;
4522};
4523
94f2b392 4524static struct bgp_aggregate *
66e5cd87 4525bgp_aggregate_new (void)
718e3744 4526{
393deb9b 4527 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
718e3744 4528}
4529
94f2b392 4530static void
718e3744 4531bgp_aggregate_free (struct bgp_aggregate *aggregate)
4532{
4533 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4534}
4535
94f2b392 4536static void
718e3744 4537bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4538 afi_t afi, safi_t safi, struct bgp_info *del,
4539 struct bgp_aggregate *aggregate)
4540{
4541 struct bgp_table *table;
4542 struct bgp_node *top;
4543 struct bgp_node *rn;
4544 u_char origin;
4545 struct aspath *aspath = NULL;
4546 struct aspath *asmerge = NULL;
4547 struct community *community = NULL;
4548 struct community *commerge = NULL;
4549 struct in_addr nexthop;
4550 u_int32_t med = 0;
4551 struct bgp_info *ri;
4552 struct bgp_info *new;
4553 int first = 1;
4554 unsigned long match = 0;
4555
4556 /* Record adding route's nexthop and med. */
4557 if (rinew)
4558 {
4559 nexthop = rinew->attr->nexthop;
4560 med = rinew->attr->med;
4561 }
4562
4563 /* ORIGIN attribute: If at least one route among routes that are
4564 aggregated has ORIGIN with the value INCOMPLETE, then the
4565 aggregated route must have the ORIGIN attribute with the value
4566 INCOMPLETE. Otherwise, if at least one route among routes that
4567 are aggregated has ORIGIN with the value EGP, then the aggregated
4568 route must have the origin attribute with the value EGP. In all
4569 other case the value of the ORIGIN attribute of the aggregated
4570 route is INTERNAL. */
4571 origin = BGP_ORIGIN_IGP;
4572
4573 table = bgp->rib[afi][safi];
4574
4575 top = bgp_node_get (table, p);
4576 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4577 if (rn->p.prefixlen > p->prefixlen)
4578 {
4579 match = 0;
4580
4581 for (ri = rn->info; ri; ri = ri->next)
4582 {
4583 if (BGP_INFO_HOLDDOWN (ri))
4584 continue;
4585
4586 if (del && ri == del)
4587 continue;
4588
4589 if (! rinew && first)
4590 {
4591 nexthop = ri->attr->nexthop;
4592 med = ri->attr->med;
4593 first = 0;
4594 }
4595
4596#ifdef AGGREGATE_NEXTHOP_CHECK
4597 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4598 || ri->attr->med != med)
4599 {
4600 if (aspath)
4601 aspath_free (aspath);
4602 if (community)
4603 community_free (community);
4604 bgp_unlock_node (rn);
4605 bgp_unlock_node (top);
4606 return;
4607 }
4608#endif /* AGGREGATE_NEXTHOP_CHECK */
4609
4610 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4611 {
4612 if (aggregate->summary_only)
4613 {
fb982c25 4614 (bgp_info_extra_get (ri))->suppress++;
1a392d46 4615 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4616 match++;
4617 }
4618
4619 aggregate->count++;
4620
4621 if (aggregate->as_set)
4622 {
4623 if (origin < ri->attr->origin)
4624 origin = ri->attr->origin;
4625
4626 if (aspath)
4627 {
4628 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4629 aspath_free (aspath);
4630 aspath = asmerge;
4631 }
4632 else
4633 aspath = aspath_dup (ri->attr->aspath);
4634
4635 if (ri->attr->community)
4636 {
4637 if (community)
4638 {
4639 commerge = community_merge (community,
4640 ri->attr->community);
4641 community = community_uniq_sort (commerge);
4642 community_free (commerge);
4643 }
4644 else
4645 community = community_dup (ri->attr->community);
4646 }
4647 }
4648 }
4649 }
4650 if (match)
4651 bgp_process (bgp, rn, afi, safi);
4652 }
4653 bgp_unlock_node (top);
4654
4655 if (rinew)
4656 {
4657 aggregate->count++;
4658
4659 if (aggregate->summary_only)
fb982c25 4660 (bgp_info_extra_get (rinew))->suppress++;
718e3744 4661
4662 if (aggregate->as_set)
4663 {
4664 if (origin < rinew->attr->origin)
4665 origin = rinew->attr->origin;
4666
4667 if (aspath)
4668 {
4669 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4670 aspath_free (aspath);
4671 aspath = asmerge;
4672 }
4673 else
4674 aspath = aspath_dup (rinew->attr->aspath);
4675
4676 if (rinew->attr->community)
4677 {
4678 if (community)
4679 {
4680 commerge = community_merge (community,
4681 rinew->attr->community);
4682 community = community_uniq_sort (commerge);
4683 community_free (commerge);
4684 }
4685 else
4686 community = community_dup (rinew->attr->community);
4687 }
4688 }
4689 }
4690
4691 if (aggregate->count > 0)
4692 {
4693 rn = bgp_node_get (table, p);
fb018d25
DS
4694 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
4695 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
4696 aggregate->as_set), rn);
718e3744 4697 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 4698
4699 bgp_info_add (rn, new);
200df115 4700 bgp_unlock_node (rn);
718e3744 4701 bgp_process (bgp, rn, afi, safi);
4702 }
4703 else
4704 {
4705 if (aspath)
4706 aspath_free (aspath);
4707 if (community)
4708 community_free (community);
4709 }
4710}
4711
4712void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4713 struct bgp_aggregate *);
4714
4715void
4716bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4717 struct bgp_info *ri, afi_t afi, safi_t safi)
4718{
4719 struct bgp_node *child;
4720 struct bgp_node *rn;
4721 struct bgp_aggregate *aggregate;
f018db83 4722 struct bgp_table *table;
718e3744 4723
4724 /* MPLS-VPN aggregation is not yet supported. */
4725 if (safi == SAFI_MPLS_VPN)
4726 return;
4727
f018db83
JBD
4728 table = bgp->aggregate[afi][safi];
4729
4730 /* No aggregates configured. */
67174041 4731 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
4732 return;
4733
718e3744 4734 if (p->prefixlen == 0)
4735 return;
4736
4737 if (BGP_INFO_HOLDDOWN (ri))
4738 return;
4739
bb782fb5 4740 child = bgp_node_get (table, p);
718e3744 4741
4742 /* Aggregate address configuration check. */
67174041 4743 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 4744 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4745 {
4746 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 4747 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
718e3744 4748 }
4749 bgp_unlock_node (child);
4750}
4751
4752void
4753bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4754 struct bgp_info *del, afi_t afi, safi_t safi)
4755{
4756 struct bgp_node *child;
4757 struct bgp_node *rn;
4758 struct bgp_aggregate *aggregate;
f018db83 4759 struct bgp_table *table;
718e3744 4760
4761 /* MPLS-VPN aggregation is not yet supported. */
4762 if (safi == SAFI_MPLS_VPN)
4763 return;
4764
f018db83
JBD
4765 table = bgp->aggregate[afi][safi];
4766
4767 /* No aggregates configured. */
67174041 4768 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
4769 return;
4770
718e3744 4771 if (p->prefixlen == 0)
4772 return;
4773
bb782fb5 4774 child = bgp_node_get (table, p);
718e3744 4775
4776 /* Aggregate address configuration check. */
67174041 4777 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 4778 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4779 {
4780 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 4781 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
718e3744 4782 }
4783 bgp_unlock_node (child);
4784}
4785
94f2b392 4786static void
718e3744 4787bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4788 struct bgp_aggregate *aggregate)
4789{
4790 struct bgp_table *table;
4791 struct bgp_node *top;
4792 struct bgp_node *rn;
4793 struct bgp_info *new;
4794 struct bgp_info *ri;
4795 unsigned long match;
4796 u_char origin = BGP_ORIGIN_IGP;
4797 struct aspath *aspath = NULL;
4798 struct aspath *asmerge = NULL;
4799 struct community *community = NULL;
4800 struct community *commerge = NULL;
4801
4802 table = bgp->rib[afi][safi];
4803
4804 /* Sanity check. */
4805 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4806 return;
4807 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4808 return;
4809
4810 /* If routes exists below this node, generate aggregate routes. */
4811 top = bgp_node_get (table, p);
4812 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4813 if (rn->p.prefixlen > p->prefixlen)
4814 {
4815 match = 0;
4816
4817 for (ri = rn->info; ri; ri = ri->next)
4818 {
4819 if (BGP_INFO_HOLDDOWN (ri))
4820 continue;
4821
4822 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4823 {
4824 /* summary-only aggregate route suppress aggregated
4825 route announcement. */
4826 if (aggregate->summary_only)
4827 {
fb982c25 4828 (bgp_info_extra_get (ri))->suppress++;
1a392d46 4829 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4830 match++;
4831 }
4832 /* as-set aggregate route generate origin, as path,
4833 community aggregation. */
4834 if (aggregate->as_set)
4835 {
4836 if (origin < ri->attr->origin)
4837 origin = ri->attr->origin;
4838
4839 if (aspath)
4840 {
4841 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4842 aspath_free (aspath);
4843 aspath = asmerge;
4844 }
4845 else
4846 aspath = aspath_dup (ri->attr->aspath);
4847
4848 if (ri->attr->community)
4849 {
4850 if (community)
4851 {
4852 commerge = community_merge (community,
4853 ri->attr->community);
4854 community = community_uniq_sort (commerge);
4855 community_free (commerge);
4856 }
4857 else
4858 community = community_dup (ri->attr->community);
4859 }
4860 }
4861 aggregate->count++;
4862 }
4863 }
4864
4865 /* If this node is suppressed, process the change. */
4866 if (match)
4867 bgp_process (bgp, rn, afi, safi);
4868 }
4869 bgp_unlock_node (top);
4870
4871 /* Add aggregate route to BGP table. */
4872 if (aggregate->count)
4873 {
4874 rn = bgp_node_get (table, p);
fb018d25
DS
4875 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
4876 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
4877 aggregate->as_set), rn);
718e3744 4878 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 4879
4880 bgp_info_add (rn, new);
200df115 4881 bgp_unlock_node (rn);
4882
718e3744 4883 /* Process change. */
4884 bgp_process (bgp, rn, afi, safi);
4885 }
4886}
4887
4888void
4889bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4890 safi_t safi, struct bgp_aggregate *aggregate)
4891{
4892 struct bgp_table *table;
4893 struct bgp_node *top;
4894 struct bgp_node *rn;
4895 struct bgp_info *ri;
4896 unsigned long match;
4897
4898 table = bgp->rib[afi][safi];
4899
4900 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4901 return;
4902 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4903 return;
4904
4905 /* If routes exists below this node, generate aggregate routes. */
4906 top = bgp_node_get (table, p);
4907 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4908 if (rn->p.prefixlen > p->prefixlen)
4909 {
4910 match = 0;
4911
4912 for (ri = rn->info; ri; ri = ri->next)
4913 {
4914 if (BGP_INFO_HOLDDOWN (ri))
4915 continue;
4916
4917 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4918 {
fb982c25 4919 if (aggregate->summary_only && ri->extra)
718e3744 4920 {
fb982c25 4921 ri->extra->suppress--;
718e3744 4922
fb982c25 4923 if (ri->extra->suppress == 0)
718e3744 4924 {
1a392d46 4925 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4926 match++;
4927 }
4928 }
4929 aggregate->count--;
4930 }
4931 }
4932
fb982c25 4933 /* If this node was suppressed, process the change. */
718e3744 4934 if (match)
4935 bgp_process (bgp, rn, afi, safi);
4936 }
4937 bgp_unlock_node (top);
4938
4939 /* Delete aggregate route from BGP table. */
4940 rn = bgp_node_get (table, p);
4941
4942 for (ri = rn->info; ri; ri = ri->next)
4943 if (ri->peer == bgp->peer_self
4944 && ri->type == ZEBRA_ROUTE_BGP
4945 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4946 break;
4947
4948 /* Withdraw static BGP route from routing table. */
4949 if (ri)
4950 {
718e3744 4951 bgp_info_delete (rn, ri);
1a392d46 4952 bgp_process (bgp, rn, afi, safi);
718e3744 4953 }
4954
4955 /* Unlock bgp_node_lookup. */
4956 bgp_unlock_node (rn);
4957}
4958
4959/* Aggregate route attribute. */
4960#define AGGREGATE_SUMMARY_ONLY 1
4961#define AGGREGATE_AS_SET 1
4962
94f2b392 4963static int
f6269b4f
RB
4964bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4965 afi_t afi, safi_t safi)
718e3744 4966{
4967 int ret;
4968 struct prefix p;
4969 struct bgp_node *rn;
4970 struct bgp *bgp;
4971 struct bgp_aggregate *aggregate;
4972
4973 /* Convert string to prefix structure. */
4974 ret = str2prefix (prefix_str, &p);
4975 if (!ret)
4976 {
4977 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4978 return CMD_WARNING;
4979 }
4980 apply_mask (&p);
4981
4982 /* Get BGP structure. */
4983 bgp = vty->index;
4984
4985 /* Old configuration check. */
f6269b4f
RB
4986 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4987 if (! rn)
718e3744 4988 {
f6269b4f
RB
4989 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4990 VTY_NEWLINE);
718e3744 4991 return CMD_WARNING;
4992 }
4993
f6269b4f
RB
4994 aggregate = rn->info;
4995 if (aggregate->safi & SAFI_UNICAST)
4996 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4997 if (aggregate->safi & SAFI_MULTICAST)
4998 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 4999
f6269b4f
RB
5000 /* Unlock aggregate address configuration. */
5001 rn->info = NULL;
5002 bgp_aggregate_free (aggregate);
5003 bgp_unlock_node (rn);
5004 bgp_unlock_node (rn);
718e3744 5005
5006 return CMD_SUCCESS;
5007}
5008
94f2b392 5009static int
f6269b4f
RB
5010bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5011 afi_t afi, safi_t safi,
5012 u_char summary_only, u_char as_set)
718e3744 5013{
5014 int ret;
5015 struct prefix p;
5016 struct bgp_node *rn;
5017 struct bgp *bgp;
5018 struct bgp_aggregate *aggregate;
5019
5020 /* Convert string to prefix structure. */
5021 ret = str2prefix (prefix_str, &p);
5022 if (!ret)
5023 {
5024 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5025 return CMD_WARNING;
5026 }
5027 apply_mask (&p);
5028
5029 /* Get BGP structure. */
5030 bgp = vty->index;
5031
5032 /* Old configuration check. */
f6269b4f
RB
5033 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5034
5035 if (rn->info)
718e3744 5036 {
f6269b4f 5037 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
368473f6 5038 /* try to remove the old entry */
f6269b4f
RB
5039 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5040 if (ret)
5041 {
368473f6
RB
5042 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5043 bgp_unlock_node (rn);
f6269b4f
RB
5044 return CMD_WARNING;
5045 }
718e3744 5046 }
5047
f6269b4f
RB
5048 /* Make aggregate address structure. */
5049 aggregate = bgp_aggregate_new ();
5050 aggregate->summary_only = summary_only;
5051 aggregate->as_set = as_set;
5052 aggregate->safi = safi;
5053 rn->info = aggregate;
718e3744 5054
f6269b4f
RB
5055 /* Aggregate address insert into BGP routing table. */
5056 if (safi & SAFI_UNICAST)
5057 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5058 if (safi & SAFI_MULTICAST)
5059 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 5060
5061 return CMD_SUCCESS;
5062}
5063
5064DEFUN (aggregate_address,
5065 aggregate_address_cmd,
5066 "aggregate-address A.B.C.D/M",
5067 "Configure BGP aggregate entries\n"
5068 "Aggregate prefix\n")
5069{
5070 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5071}
5072
5073DEFUN (aggregate_address_mask,
5074 aggregate_address_mask_cmd,
5075 "aggregate-address A.B.C.D A.B.C.D",
5076 "Configure BGP aggregate entries\n"
5077 "Aggregate address\n"
5078 "Aggregate mask\n")
5079{
5080 int ret;
5081 char prefix_str[BUFSIZ];
5082
5083 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5084
5085 if (! ret)
5086 {
5087 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5088 return CMD_WARNING;
5089 }
5090
5091 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5092 0, 0);
5093}
5094
5095DEFUN (aggregate_address_summary_only,
5096 aggregate_address_summary_only_cmd,
5097 "aggregate-address A.B.C.D/M summary-only",
5098 "Configure BGP aggregate entries\n"
5099 "Aggregate prefix\n"
5100 "Filter more specific routes from updates\n")
5101{
5102 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5103 AGGREGATE_SUMMARY_ONLY, 0);
5104}
5105
5106DEFUN (aggregate_address_mask_summary_only,
5107 aggregate_address_mask_summary_only_cmd,
5108 "aggregate-address A.B.C.D A.B.C.D summary-only",
5109 "Configure BGP aggregate entries\n"
5110 "Aggregate address\n"
5111 "Aggregate mask\n"
5112 "Filter more specific routes from updates\n")
5113{
5114 int ret;
5115 char prefix_str[BUFSIZ];
5116
5117 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5118
5119 if (! ret)
5120 {
5121 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5122 return CMD_WARNING;
5123 }
5124
5125 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5126 AGGREGATE_SUMMARY_ONLY, 0);
5127}
5128
5129DEFUN (aggregate_address_as_set,
5130 aggregate_address_as_set_cmd,
5131 "aggregate-address A.B.C.D/M as-set",
5132 "Configure BGP aggregate entries\n"
5133 "Aggregate prefix\n"
5134 "Generate AS set path information\n")
5135{
5136 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5137 0, AGGREGATE_AS_SET);
5138}
5139
5140DEFUN (aggregate_address_mask_as_set,
5141 aggregate_address_mask_as_set_cmd,
5142 "aggregate-address A.B.C.D A.B.C.D as-set",
5143 "Configure BGP aggregate entries\n"
5144 "Aggregate address\n"
5145 "Aggregate mask\n"
5146 "Generate AS set path information\n")
5147{
5148 int ret;
5149 char prefix_str[BUFSIZ];
5150
5151 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5152
5153 if (! ret)
5154 {
5155 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5156 return CMD_WARNING;
5157 }
5158
5159 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5160 0, AGGREGATE_AS_SET);
5161}
5162
5163
5164DEFUN (aggregate_address_as_set_summary,
5165 aggregate_address_as_set_summary_cmd,
5166 "aggregate-address A.B.C.D/M as-set summary-only",
5167 "Configure BGP aggregate entries\n"
5168 "Aggregate prefix\n"
5169 "Generate AS set path information\n"
5170 "Filter more specific routes from updates\n")
5171{
5172 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5173 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5174}
5175
5176ALIAS (aggregate_address_as_set_summary,
5177 aggregate_address_summary_as_set_cmd,
5178 "aggregate-address A.B.C.D/M summary-only as-set",
5179 "Configure BGP aggregate entries\n"
5180 "Aggregate prefix\n"
5181 "Filter more specific routes from updates\n"
5182 "Generate AS set path information\n")
5183
5184DEFUN (aggregate_address_mask_as_set_summary,
5185 aggregate_address_mask_as_set_summary_cmd,
5186 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5187 "Configure BGP aggregate entries\n"
5188 "Aggregate address\n"
5189 "Aggregate mask\n"
5190 "Generate AS set path information\n"
5191 "Filter more specific routes from updates\n")
5192{
5193 int ret;
5194 char prefix_str[BUFSIZ];
5195
5196 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5197
5198 if (! ret)
5199 {
5200 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5201 return CMD_WARNING;
5202 }
5203
5204 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5205 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5206}
5207
5208ALIAS (aggregate_address_mask_as_set_summary,
5209 aggregate_address_mask_summary_as_set_cmd,
5210 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5211 "Configure BGP aggregate entries\n"
5212 "Aggregate address\n"
5213 "Aggregate mask\n"
5214 "Filter more specific routes from updates\n"
5215 "Generate AS set path information\n")
5216
5217DEFUN (no_aggregate_address,
5218 no_aggregate_address_cmd,
5219 "no aggregate-address A.B.C.D/M",
5220 NO_STR
5221 "Configure BGP aggregate entries\n"
5222 "Aggregate prefix\n")
5223{
5224 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5225}
5226
5227ALIAS (no_aggregate_address,
5228 no_aggregate_address_summary_only_cmd,
5229 "no aggregate-address A.B.C.D/M summary-only",
5230 NO_STR
5231 "Configure BGP aggregate entries\n"
5232 "Aggregate prefix\n"
5233 "Filter more specific routes from updates\n")
5234
5235ALIAS (no_aggregate_address,
5236 no_aggregate_address_as_set_cmd,
5237 "no aggregate-address A.B.C.D/M as-set",
5238 NO_STR
5239 "Configure BGP aggregate entries\n"
5240 "Aggregate prefix\n"
5241 "Generate AS set path information\n")
5242
5243ALIAS (no_aggregate_address,
5244 no_aggregate_address_as_set_summary_cmd,
5245 "no aggregate-address A.B.C.D/M as-set summary-only",
5246 NO_STR
5247 "Configure BGP aggregate entries\n"
5248 "Aggregate prefix\n"
5249 "Generate AS set path information\n"
5250 "Filter more specific routes from updates\n")
5251
5252ALIAS (no_aggregate_address,
5253 no_aggregate_address_summary_as_set_cmd,
5254 "no aggregate-address A.B.C.D/M summary-only as-set",
5255 NO_STR
5256 "Configure BGP aggregate entries\n"
5257 "Aggregate prefix\n"
5258 "Filter more specific routes from updates\n"
5259 "Generate AS set path information\n")
5260
5261DEFUN (no_aggregate_address_mask,
5262 no_aggregate_address_mask_cmd,
5263 "no aggregate-address A.B.C.D A.B.C.D",
5264 NO_STR
5265 "Configure BGP aggregate entries\n"
5266 "Aggregate address\n"
5267 "Aggregate mask\n")
5268{
5269 int ret;
5270 char prefix_str[BUFSIZ];
5271
5272 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5273
5274 if (! ret)
5275 {
5276 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5277 return CMD_WARNING;
5278 }
5279
5280 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5281}
5282
5283ALIAS (no_aggregate_address_mask,
5284 no_aggregate_address_mask_summary_only_cmd,
5285 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5286 NO_STR
5287 "Configure BGP aggregate entries\n"
5288 "Aggregate address\n"
5289 "Aggregate mask\n"
5290 "Filter more specific routes from updates\n")
5291
5292ALIAS (no_aggregate_address_mask,
5293 no_aggregate_address_mask_as_set_cmd,
5294 "no aggregate-address A.B.C.D A.B.C.D as-set",
5295 NO_STR
5296 "Configure BGP aggregate entries\n"
5297 "Aggregate address\n"
5298 "Aggregate mask\n"
5299 "Generate AS set path information\n")
5300
5301ALIAS (no_aggregate_address_mask,
5302 no_aggregate_address_mask_as_set_summary_cmd,
5303 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5304 NO_STR
5305 "Configure BGP aggregate entries\n"
5306 "Aggregate address\n"
5307 "Aggregate mask\n"
5308 "Generate AS set path information\n"
5309 "Filter more specific routes from updates\n")
5310
5311ALIAS (no_aggregate_address_mask,
5312 no_aggregate_address_mask_summary_as_set_cmd,
5313 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5314 NO_STR
5315 "Configure BGP aggregate entries\n"
5316 "Aggregate address\n"
5317 "Aggregate mask\n"
5318 "Filter more specific routes from updates\n"
5319 "Generate AS set path information\n")
5320
5321#ifdef HAVE_IPV6
5322DEFUN (ipv6_aggregate_address,
5323 ipv6_aggregate_address_cmd,
5324 "aggregate-address X:X::X:X/M",
5325 "Configure BGP aggregate entries\n"
5326 "Aggregate prefix\n")
5327{
5328 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5329}
5330
5331DEFUN (ipv6_aggregate_address_summary_only,
5332 ipv6_aggregate_address_summary_only_cmd,
5333 "aggregate-address X:X::X:X/M summary-only",
5334 "Configure BGP aggregate entries\n"
5335 "Aggregate prefix\n"
5336 "Filter more specific routes from updates\n")
5337{
5338 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5339 AGGREGATE_SUMMARY_ONLY, 0);
5340}
5341
5342DEFUN (no_ipv6_aggregate_address,
5343 no_ipv6_aggregate_address_cmd,
5344 "no aggregate-address X:X::X:X/M",
5345 NO_STR
5346 "Configure BGP aggregate entries\n"
5347 "Aggregate prefix\n")
5348{
5349 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5350}
5351
5352DEFUN (no_ipv6_aggregate_address_summary_only,
5353 no_ipv6_aggregate_address_summary_only_cmd,
5354 "no aggregate-address X:X::X:X/M summary-only",
5355 NO_STR
5356 "Configure BGP aggregate entries\n"
5357 "Aggregate prefix\n"
5358 "Filter more specific routes from updates\n")
5359{
5360 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5361}
5362
5363ALIAS (ipv6_aggregate_address,
5364 old_ipv6_aggregate_address_cmd,
5365 "ipv6 bgp aggregate-address X:X::X:X/M",
5366 IPV6_STR
5367 BGP_STR
5368 "Configure BGP aggregate entries\n"
5369 "Aggregate prefix\n")
5370
5371ALIAS (ipv6_aggregate_address_summary_only,
5372 old_ipv6_aggregate_address_summary_only_cmd,
5373 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5374 IPV6_STR
5375 BGP_STR
5376 "Configure BGP aggregate entries\n"
5377 "Aggregate prefix\n"
5378 "Filter more specific routes from updates\n")
5379
5380ALIAS (no_ipv6_aggregate_address,
5381 old_no_ipv6_aggregate_address_cmd,
5382 "no ipv6 bgp aggregate-address X:X::X:X/M",
5383 NO_STR
5384 IPV6_STR
5385 BGP_STR
5386 "Configure BGP aggregate entries\n"
5387 "Aggregate prefix\n")
5388
5389ALIAS (no_ipv6_aggregate_address_summary_only,
5390 old_no_ipv6_aggregate_address_summary_only_cmd,
5391 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5392 NO_STR
5393 IPV6_STR
5394 BGP_STR
5395 "Configure BGP aggregate entries\n"
5396 "Aggregate prefix\n"
5397 "Filter more specific routes from updates\n")
5398#endif /* HAVE_IPV6 */
6b0655a2 5399
718e3744 5400/* Redistribute route treatment. */
5401void
f04a80a5
SH
5402bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5403 const struct in6_addr *nexthop6,
718e3744 5404 u_int32_t metric, u_char type)
5405{
5406 struct bgp *bgp;
1eb8ef25 5407 struct listnode *node, *nnode;
718e3744 5408 struct bgp_info *new;
5409 struct bgp_info *bi;
5410 struct bgp_info info;
5411 struct bgp_node *bn;
e16a4133 5412 struct attr attr;
718e3744 5413 struct attr *new_attr;
5414 afi_t afi;
5415 int ret;
5416
5417 /* Make default attribute. */
5418 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5419 if (nexthop)
5420 attr.nexthop = *nexthop;
5421
f04a80a5
SH
5422#ifdef HAVE_IPV6
5423 if (nexthop6)
5424 {
5425 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5426 extra->mp_nexthop_global = *nexthop6;
5427 extra->mp_nexthop_len = 16;
5428 }
5429#endif
5430
718e3744 5431 attr.med = metric;
5432 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5433
1eb8ef25 5434 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 5435 {
5436 afi = family2afi (p->family);
5437
5438 if (bgp->redist[afi][type])
5439 {
558d1fec
JBD
5440 struct attr attr_new;
5441 struct attr_extra extra_new;
5442
718e3744 5443 /* Copy attribute for modification. */
558d1fec 5444 attr_new.extra = &extra_new;
fb982c25 5445 bgp_attr_dup (&attr_new, &attr);
718e3744 5446
5447 if (bgp->redist_metric_flag[afi][type])
5448 attr_new.med = bgp->redist_metric[afi][type];
5449
5450 /* Apply route-map. */
5451 if (bgp->rmap[afi][type].map)
5452 {
5453 info.peer = bgp->peer_self;
5454 info.attr = &attr_new;
5455
fee0f4c6 5456 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5457
718e3744 5458 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5459 &info);
fee0f4c6 5460
5461 bgp->peer_self->rmap_type = 0;
5462
718e3744 5463 if (ret == RMAP_DENYMATCH)
5464 {
5465 /* Free uninterned attribute. */
5466 bgp_attr_flush (&attr_new);
558d1fec 5467
718e3744 5468 /* Unintern original. */
f6f434b2 5469 aspath_unintern (&attr.aspath);
fb982c25 5470 bgp_attr_extra_free (&attr);
718e3744 5471 bgp_redistribute_delete (p, type);
5472 return;
5473 }
5474 }
5475
fb982c25
PJ
5476 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5477 afi, SAFI_UNICAST, p, NULL);
5478
718e3744 5479 new_attr = bgp_attr_intern (&attr_new);
558d1fec 5480
718e3744 5481 for (bi = bn->info; bi; bi = bi->next)
5482 if (bi->peer == bgp->peer_self
5483 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5484 break;
5485
5486 if (bi)
5487 {
8d45210e
AS
5488 if (attrhash_cmp (bi->attr, new_attr) &&
5489 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
718e3744 5490 {
f6f434b2
PJ
5491 bgp_attr_unintern (&new_attr);
5492 aspath_unintern (&attr.aspath);
fb982c25 5493 bgp_attr_extra_free (&attr);
718e3744 5494 bgp_unlock_node (bn);
5495 return;
5496 }
5497 else
5498 {
5499 /* The attribute is changed. */
1a392d46 5500 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
718e3744 5501
5502 /* Rewrite BGP route information. */
8d45210e
AS
5503 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5504 bgp_info_restore(bn, bi);
5505 else
5506 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
f6f434b2 5507 bgp_attr_unintern (&bi->attr);
718e3744 5508 bi->attr = new_attr;
65957886 5509 bi->uptime = bgp_clock ();
718e3744 5510
5511 /* Process change. */
5512 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5513 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5514 bgp_unlock_node (bn);
f6f434b2 5515 aspath_unintern (&attr.aspath);
fb982c25 5516 bgp_attr_extra_free (&attr);
718e3744 5517 return;
fb018d25 5518 }
718e3744 5519 }
5520
fb018d25
DS
5521 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, bgp->peer_self,
5522 new_attr, bn);
718e3744 5523 SET_FLAG (new->flags, BGP_INFO_VALID);
718e3744 5524
5525 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5526 bgp_info_add (bn, new);
200df115 5527 bgp_unlock_node (bn);
718e3744 5528 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5529 }
5530 }
5531
5532 /* Unintern original. */
f6f434b2 5533 aspath_unintern (&attr.aspath);
fb982c25 5534 bgp_attr_extra_free (&attr);
718e3744 5535}
5536
5537void
5538bgp_redistribute_delete (struct prefix *p, u_char type)
5539{
5540 struct bgp *bgp;
1eb8ef25 5541 struct listnode *node, *nnode;
718e3744 5542 afi_t afi;
5543 struct bgp_node *rn;
5544 struct bgp_info *ri;
5545
1eb8ef25 5546 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 5547 {
5548 afi = family2afi (p->family);
5549
5550 if (bgp->redist[afi][type])
5551 {
fee0f4c6 5552 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
718e3744 5553
5554 for (ri = rn->info; ri; ri = ri->next)
5555 if (ri->peer == bgp->peer_self
5556 && ri->type == type)
5557 break;
5558
5559 if (ri)
5560 {
5561 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
718e3744 5562 bgp_info_delete (rn, ri);
1a392d46 5563 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 5564 }
5565 bgp_unlock_node (rn);
5566 }
5567 }
5568}
5569
5570/* Withdraw specified route type's route. */
5571void
5572bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5573{
5574 struct bgp_node *rn;
5575 struct bgp_info *ri;
5576 struct bgp_table *table;
5577
5578 table = bgp->rib[afi][SAFI_UNICAST];
5579
5580 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5581 {
5582 for (ri = rn->info; ri; ri = ri->next)
5583 if (ri->peer == bgp->peer_self
5584 && ri->type == type)
5585 break;
5586
5587 if (ri)
5588 {
5589 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
718e3744 5590 bgp_info_delete (rn, ri);
1a392d46 5591 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 5592 }
5593 }
5594}
6b0655a2 5595
718e3744 5596/* Static function to display route. */
94f2b392 5597static void
718e3744 5598route_vty_out_route (struct prefix *p, struct vty *vty)
5599{
5600 int len;
5601 u_int32_t destination;
5602 char buf[BUFSIZ];
5603
5604 if (p->family == AF_INET)
5605 {
5606 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5607 destination = ntohl (p->u.prefix4.s_addr);
5608
5609 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5610 || (IN_CLASSB (destination) && p->prefixlen == 16)
5611 || (IN_CLASSA (destination) && p->prefixlen == 8)
5612 || p->u.prefix4.s_addr == 0)
5613 {
5614 /* When mask is natural, mask is not displayed. */
5615 }
5616 else
5617 len += vty_out (vty, "/%d", p->prefixlen);
5618 }
5619 else
5620 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5621 p->prefixlen);
5622
5623 len = 17 - len;
5624 if (len < 1)
5625 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5626 else
5627 vty_out (vty, "%*s", len, " ");
5628}
5629
718e3744 5630enum bgp_display_type
5631{
5632 normal_list,
5633};
5634
b40d939b 5635/* Print the short form route status for a bgp_info */
5636static void
5637route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
718e3744 5638{
b40d939b 5639 /* Route status display. */
5640 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5641 vty_out (vty, "R");
5642 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
93406d87 5643 vty_out (vty, "S");
fb982c25 5644 else if (binfo->extra && binfo->extra->suppress)
718e3744 5645 vty_out (vty, "s");
5646 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5647 vty_out (vty, "*");
5648 else
5649 vty_out (vty, " ");
5650
5651 /* Selected */
5652 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5653 vty_out (vty, "h");
5654 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5655 vty_out (vty, "d");
5656 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5657 vty_out (vty, ">");
b366b518
BB
5658 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5659 vty_out (vty, "=");
718e3744 5660 else
5661 vty_out (vty, " ");
5662
5663 /* Internal route. */
5664 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5665 vty_out (vty, "i");
5666 else
b40d939b 5667 vty_out (vty, " ");
5668}
5669
5670/* called from terminal list command */
5671void
5672route_vty_out (struct vty *vty, struct prefix *p,
47fc97cc 5673 struct bgp_info *binfo, int display, safi_t safi, char *delim)
b40d939b 5674{
5675 struct attr *attr;
47fc97cc
DS
5676
5677 /* short status lead text */
b40d939b 5678 route_vty_short_status_out (vty, binfo);
47fc97cc
DS
5679
5680 if (delim)
5681 vty_out (vty, "%c", *delim);
5682
718e3744 5683 /* print prefix and mask */
5684 if (! display)
5685 route_vty_out_route (p, vty);
5686 else
5687 vty_out (vty, "%*s", 17, " ");
5688
47fc97cc
DS
5689 if (delim)
5690 vty_out (vty, "%c", *delim);
5691
718e3744 5692 /* Print attribute */
5693 attr = binfo->attr;
5694 if (attr)
5695 {
5696 if (p->family == AF_INET)
5697 {
5698 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
5699 vty_out (vty, "%-16s",
5700 inet_ntoa (attr->extra->mp_nexthop_global_in));
718e3744 5701 else
5702 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5703 }
5704#ifdef HAVE_IPV6
5705 else if (p->family == AF_INET6)
5706 {
5707 int len;
5708 char buf[BUFSIZ];
5709
5710 len = vty_out (vty, "%s",
fb982c25
PJ
5711 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5712 buf, BUFSIZ));
718e3744 5713 len = 16 - len;
5714 if (len < 1)
5715 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5716 else
5717 vty_out (vty, "%*s", len, " ");
5718 }
5719#endif /* HAVE_IPV6 */
5720
47fc97cc
DS
5721 if (delim)
5722 vty_out (vty, "%c", *delim);
5723
718e3744 5724 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
c099baf6 5725 vty_out (vty, "%10u", attr->med);
718e3744 5726 else
5727 vty_out (vty, " ");
5728
47fc97cc
DS
5729 if (delim)
5730 vty_out (vty, "%c", *delim);
5731
718e3744 5732 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
c099baf6 5733 vty_out (vty, "%7u", attr->local_pref);
718e3744 5734 else
5735 vty_out (vty, " ");
5736
47fc97cc
DS
5737 if (delim)
5738 vty_out (vty, "%c", *delim);
5739
fb982c25 5740 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
47fc97cc
DS
5741
5742 if (delim)
5743 vty_out (vty, "%c", *delim);
5744
b2518c1e
PJ
5745 /* Print aspath */
5746 if (attr->aspath)
841f7a57 5747 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 5748
47fc97cc
DS
5749 if (delim)
5750 vty_out (vty, "%c", *delim);
5751
b2518c1e 5752 /* Print origin */
718e3744 5753 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 5754 }
718e3744 5755 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 5756}
5757
5758/* called from terminal list command */
5759void
5760route_vty_out_tmp (struct vty *vty, struct prefix *p,
47fc97cc 5761 struct attr *attr, safi_t safi, char *delim)
718e3744 5762{
5763 /* Route status display. */
5764 vty_out (vty, "*");
5765 vty_out (vty, ">");
5766 vty_out (vty, " ");
5767
47fc97cc
DS
5768 if (delim)
5769 vty_out (vty, "%c", *delim);
5770
718e3744 5771 /* print prefix and mask */
5772 route_vty_out_route (p, vty);
5773
47fc97cc
DS
5774 if (delim)
5775 vty_out (vty, "%c", *delim);
5776
718e3744 5777 /* Print attribute */
5778 if (attr)
5779 {
5780 if (p->family == AF_INET)
5781 {
5782 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
5783 vty_out (vty, "%-16s",
5784 inet_ntoa (attr->extra->mp_nexthop_global_in));
718e3744 5785 else
5786 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5787 }
5788#ifdef HAVE_IPV6
5789 else if (p->family == AF_INET6)
5790 {
5791 int len;
5792 char buf[BUFSIZ];
fb982c25
PJ
5793
5794 assert (attr->extra);
718e3744 5795
5796 len = vty_out (vty, "%s",
fb982c25
PJ
5797 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5798 buf, BUFSIZ));
718e3744 5799 len = 16 - len;
5800 if (len < 1)
5801 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5802 else
5803 vty_out (vty, "%*s", len, " ");
5804 }
5805#endif /* HAVE_IPV6 */
5806
47fc97cc
DS
5807 if (delim)
5808 vty_out (vty, "%c", *delim);
5809
718e3744 5810 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
c099baf6 5811 vty_out (vty, "%10u", attr->med);
718e3744 5812 else
5813 vty_out (vty, " ");
5814
47fc97cc
DS
5815 if (delim)
5816 vty_out (vty, "%c", *delim);
5817
718e3744 5818 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
c099baf6 5819 vty_out (vty, "%7u", attr->local_pref);
718e3744 5820 else
5821 vty_out (vty, " ");
fb982c25 5822
47fc97cc
DS
5823 if (delim)
5824 vty_out (vty, "%c", *delim);
5825
c099baf6 5826 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
fb982c25 5827
47fc97cc
DS
5828 if (delim)
5829 vty_out (vty, "%c", *delim);
5830
b2518c1e
PJ
5831 /* Print aspath */
5832 if (attr->aspath)
841f7a57 5833 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 5834
47fc97cc
DS
5835 if (delim)
5836 vty_out (vty, "%c", *delim);
5837
b2518c1e 5838 /* Print origin */
718e3744 5839 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 5840 }
718e3744 5841
5842 vty_out (vty, "%s", VTY_NEWLINE);
5843}
5844
5a646650 5845void
718e3744 5846route_vty_out_tag (struct vty *vty, struct prefix *p,
5847 struct bgp_info *binfo, int display, safi_t safi)
5848{
5849 struct attr *attr;
718e3744 5850 u_int32_t label = 0;
fb982c25
PJ
5851
5852 if (!binfo->extra)
5853 return;
5854
b40d939b 5855 /* short status lead text */
5856 route_vty_short_status_out (vty, binfo);
5857
718e3744 5858 /* print prefix and mask */
5859 if (! display)
5860 route_vty_out_route (p, vty);
5861 else
5862 vty_out (vty, "%*s", 17, " ");
5863
5864 /* Print attribute */
5865 attr = binfo->attr;
5866 if (attr)
5867 {
5868 if (p->family == AF_INET)
5869 {
5870 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
5871 vty_out (vty, "%-16s",
5872 inet_ntoa (attr->extra->mp_nexthop_global_in));
718e3744 5873 else
5874 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5875 }
5876#ifdef HAVE_IPV6
5877 else if (p->family == AF_INET6)
5878 {
fb982c25 5879 assert (attr->extra);
718e3744 5880 char buf[BUFSIZ];
5881 char buf1[BUFSIZ];
fb982c25 5882 if (attr->extra->mp_nexthop_len == 16)
718e3744 5883 vty_out (vty, "%s",
fb982c25
PJ
5884 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5885 buf, BUFSIZ));
5886 else if (attr->extra->mp_nexthop_len == 32)
718e3744 5887 vty_out (vty, "%s(%s)",
fb982c25
PJ
5888 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5889 buf, BUFSIZ),
5890 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5891 buf1, BUFSIZ));
718e3744 5892
5893 }
5894#endif /* HAVE_IPV6 */
5895 }
5896
fb982c25 5897 label = decode_label (binfo->extra->tag);
718e3744 5898
5899 vty_out (vty, "notag/%d", label);
5900
5901 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 5902}
5903
5904/* dampening route */
5a646650 5905static void
718e3744 5906damp_route_vty_out (struct vty *vty, struct prefix *p,
5907 struct bgp_info *binfo, int display, safi_t safi)
5908{
5909 struct attr *attr;
718e3744 5910 int len;
50aef6f3 5911 char timebuf[BGP_UPTIME_LEN];
718e3744 5912
b40d939b 5913 /* short status lead text */
5914 route_vty_short_status_out (vty, binfo);
5915
718e3744 5916 /* print prefix and mask */
5917 if (! display)
5918 route_vty_out_route (p, vty);
5919 else
5920 vty_out (vty, "%*s", 17, " ");
5921
5922 len = vty_out (vty, "%s", binfo->peer->host);
5923 len = 17 - len;
5924 if (len < 1)
5925 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5926 else
5927 vty_out (vty, "%*s", len, " ");
5928
50aef6f3 5929 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
718e3744 5930
5931 /* Print attribute */
5932 attr = binfo->attr;
5933 if (attr)
5934 {
5935 /* Print aspath */
5936 if (attr->aspath)
841f7a57 5937 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 5938
5939 /* Print origin */
b2518c1e 5940 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 5941 }
5942 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 5943}
5944
718e3744 5945/* flap route */
5a646650 5946static void
718e3744 5947flap_route_vty_out (struct vty *vty, struct prefix *p,
5948 struct bgp_info *binfo, int display, safi_t safi)
5949{
5950 struct attr *attr;
5951 struct bgp_damp_info *bdi;
718e3744 5952 char timebuf[BGP_UPTIME_LEN];
5953 int len;
fb982c25
PJ
5954
5955 if (!binfo->extra)
5956 return;
5957
5958 bdi = binfo->extra->damp_info;
718e3744 5959
b40d939b 5960 /* short status lead text */
5961 route_vty_short_status_out (vty, binfo);
5962
718e3744 5963 /* print prefix and mask */
5964 if (! display)
5965 route_vty_out_route (p, vty);
5966 else
5967 vty_out (vty, "%*s", 17, " ");
5968
5969 len = vty_out (vty, "%s", binfo->peer->host);
5970 len = 16 - len;
5971 if (len < 1)
5972 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5973 else
5974 vty_out (vty, "%*s", len, " ");
5975
5976 len = vty_out (vty, "%d", bdi->flap);
5977 len = 5 - len;
5978 if (len < 1)
5979 vty_out (vty, " ");
5980 else
5981 vty_out (vty, "%*s ", len, " ");
5982
5983 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5984 timebuf, BGP_UPTIME_LEN));
5985
5986 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5987 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
50aef6f3 5988 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
718e3744 5989 else
5990 vty_out (vty, "%*s ", 8, " ");
5991
5992 /* Print attribute */
5993 attr = binfo->attr;
5994 if (attr)
5995 {
5996 /* Print aspath */
5997 if (attr->aspath)
841f7a57 5998 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 5999
6000 /* Print origin */
b2518c1e 6001 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 6002 }
6003 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 6004}
6005
94f2b392 6006static void
718e3744 6007route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6008 struct bgp_info *binfo, afi_t afi, safi_t safi)
6009{
6010 char buf[INET6_ADDRSTRLEN];
6011 char buf1[BUFSIZ];
6012 struct attr *attr;
6013 int sockunion_vty_out (struct vty *, union sockunion *);
30b00176
JK
6014#ifdef HAVE_CLOCK_MONOTONIC
6015 time_t tbuf;
6016#endif
718e3744 6017
6018 attr = binfo->attr;
6019
6020 if (attr)
6021 {
6022 /* Line1 display AS-path, Aggregator */
6023 if (attr->aspath)
6024 {
6025 vty_out (vty, " ");
fe69a505 6026 if (aspath_count_hops (attr->aspath) == 0)
718e3744 6027 vty_out (vty, "Local");
6028 else
841f7a57 6029 aspath_print_vty (vty, "%s", attr->aspath, "");
718e3744 6030 }
6031
b40d939b 6032 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6033 vty_out (vty, ", (removed)");
93406d87 6034 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6035 vty_out (vty, ", (stale)");
6036 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
aea339f7 6037 vty_out (vty, ", (aggregated by %u %s)",
fb982c25
PJ
6038 attr->extra->aggregator_as,
6039 inet_ntoa (attr->extra->aggregator_addr));
93406d87 6040 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6041 vty_out (vty, ", (Received from a RR-client)");
6042 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6043 vty_out (vty, ", (Received from a RS-client)");
6044 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6045 vty_out (vty, ", (history entry)");
6046 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6047 vty_out (vty, ", (suppressed due to dampening)");
718e3744 6048 vty_out (vty, "%s", VTY_NEWLINE);
6049
6050 /* Line2 display Next-hop, Neighbor, Router-id */
6051 if (p->family == AF_INET)
6052 {
6053 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
fb982c25 6054 inet_ntoa (attr->extra->mp_nexthop_global_in) :
718e3744 6055 inet_ntoa (attr->nexthop));
6056 }
6057#ifdef HAVE_IPV6
6058 else
6059 {
fb982c25 6060 assert (attr->extra);
718e3744 6061 vty_out (vty, " %s",
fb982c25 6062 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
718e3744 6063 buf, INET6_ADDRSTRLEN));
6064 }
6065#endif /* HAVE_IPV6 */
6066
6067 if (binfo->peer == bgp->peer_self)
6068 {
6069 vty_out (vty, " from %s ",
6070 p->family == AF_INET ? "0.0.0.0" : "::");
6071 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6072 }
6073 else
6074 {
6075 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6076 vty_out (vty, " (inaccessible)");
fb982c25 6077 else if (binfo->extra && binfo->extra->igpmetric)
ddc943de 6078 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
eb821189 6079 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
718e3744 6080 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
fb982c25 6081 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
718e3744 6082 else
6083 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6084 }
6085 vty_out (vty, "%s", VTY_NEWLINE);
6086
6087#ifdef HAVE_IPV6
6088 /* display nexthop local */
fb982c25 6089 if (attr->extra && attr->extra->mp_nexthop_len == 32)
718e3744 6090 {
6091 vty_out (vty, " (%s)%s",
fb982c25 6092 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
718e3744 6093 buf, INET6_ADDRSTRLEN),
6094 VTY_NEWLINE);
6095 }
6096#endif /* HAVE_IPV6 */
6097
6098 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6099 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6100
6101 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
c099baf6 6102 vty_out (vty, ", metric %u", attr->med);
718e3744 6103
6104 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
c099baf6 6105 vty_out (vty, ", localpref %u", attr->local_pref);
718e3744 6106 else
c099baf6 6107 vty_out (vty, ", localpref %u", bgp->default_local_pref);
718e3744 6108
fb982c25 6109 if (attr->extra && attr->extra->weight != 0)
c099baf6 6110 vty_out (vty, ", weight %u", attr->extra->weight);
718e3744 6111
6112 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6113 vty_out (vty, ", valid");
6114
6115 if (binfo->peer != bgp->peer_self)
6116 {
6117 if (binfo->peer->as == binfo->peer->local_as)
6118 vty_out (vty, ", internal");
6119 else
6120 vty_out (vty, ", %s",
6121 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6122 }
6123 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6124 vty_out (vty, ", aggregated, local");
6125 else if (binfo->type != ZEBRA_ROUTE_BGP)
6126 vty_out (vty, ", sourced");
6127 else
6128 vty_out (vty, ", sourced, local");
6129
6130 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6131 vty_out (vty, ", atomic-aggregate");
6132
de8d5dff
JB
6133 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6134 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6135 bgp_info_mpath_count (binfo)))
6136 vty_out (vty, ", multipath");
6137
718e3744 6138 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6139 vty_out (vty, ", best");
6140
6141 vty_out (vty, "%s", VTY_NEWLINE);
6142
6143 /* Line 4 display Community */
6144 if (attr->community)
6145 vty_out (vty, " Community: %s%s", attr->community->str,
6146 VTY_NEWLINE);
6147
6148 /* Line 5 display Extended-community */
6149 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
fb982c25
PJ
6150 vty_out (vty, " Extended Community: %s%s",
6151 attr->extra->ecommunity->str, VTY_NEWLINE);
718e3744 6152
6153 /* Line 6 display Originator, Cluster-id */
6154 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6155 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6156 {
fb982c25 6157 assert (attr->extra);
718e3744 6158 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
fb982c25
PJ
6159 vty_out (vty, " Originator: %s",
6160 inet_ntoa (attr->extra->originator_id));
718e3744 6161
6162 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6163 {
6164 int i;
6165 vty_out (vty, ", Cluster list: ");
fb982c25
PJ
6166 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6167 vty_out (vty, "%s ",
6168 inet_ntoa (attr->extra->cluster->list[i]));
718e3744 6169 }
6170 vty_out (vty, "%s", VTY_NEWLINE);
6171 }
41367172 6172
fb982c25 6173 if (binfo->extra && binfo->extra->damp_info)
718e3744 6174 bgp_damp_info_vty (vty, binfo);
6175
6176 /* Line 7 display Uptime */
30b00176
JK
6177#ifdef HAVE_CLOCK_MONOTONIC
6178 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
213b6cd9 6179 vty_out (vty, " Last update: %s", ctime(&tbuf));
30b00176
JK
6180#else
6181 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6182#endif /* HAVE_CLOCK_MONOTONIC */
718e3744 6183 }
6184 vty_out (vty, "%s", VTY_NEWLINE);
b366b518
BB
6185}
6186
6187#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6188 "h history, * valid, > best, = multipath,%s"\
6189 " i internal, r RIB-failure, S Stale, R Removed%s"
93406d87 6190#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
718e3744 6191#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
47fc97cc 6192#define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
718e3744 6193#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6194#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6195
6196enum bgp_show_type
6197{
6198 bgp_show_type_normal,
6199 bgp_show_type_regexp,
6200 bgp_show_type_prefix_list,
6201 bgp_show_type_filter_list,
6202 bgp_show_type_route_map,
6203 bgp_show_type_neighbor,
6204 bgp_show_type_cidr_only,
6205 bgp_show_type_prefix_longer,
6206 bgp_show_type_community_all,
6207 bgp_show_type_community,
6208 bgp_show_type_community_exact,
6209 bgp_show_type_community_list,
6210 bgp_show_type_community_list_exact,
6211 bgp_show_type_flap_statistics,
6212 bgp_show_type_flap_address,
6213 bgp_show_type_flap_prefix,
6214 bgp_show_type_flap_cidr_only,
6215 bgp_show_type_flap_regexp,
6216 bgp_show_type_flap_filter_list,
6217 bgp_show_type_flap_prefix_list,
6218 bgp_show_type_flap_prefix_longer,
6219 bgp_show_type_flap_route_map,
6220 bgp_show_type_flap_neighbor,
6221 bgp_show_type_dampend_paths,
6222 bgp_show_type_damp_neighbor
6223};
6224
5a646650 6225static int
fee0f4c6 6226bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
47fc97cc 6227 enum bgp_show_type type, void *output_arg, char *delim)
718e3744 6228{
718e3744 6229 struct bgp_info *ri;
6230 struct bgp_node *rn;
718e3744 6231 int header = 1;
718e3744 6232 int display;
5a646650 6233 unsigned long output_count;
718e3744 6234
6235 /* This is first entry point, so reset total line. */
5a646650 6236 output_count = 0;
718e3744 6237
718e3744 6238 /* Start processing of routes. */
6239 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6240 if (rn->info != NULL)
6241 {
6242 display = 0;
6243
6244 for (ri = rn->info; ri; ri = ri->next)
6245 {
5a646650 6246 if (type == bgp_show_type_flap_statistics
718e3744 6247 || type == bgp_show_type_flap_address
6248 || type == bgp_show_type_flap_prefix
6249 || type == bgp_show_type_flap_cidr_only
6250 || type == bgp_show_type_flap_regexp
6251 || type == bgp_show_type_flap_filter_list
6252 || type == bgp_show_type_flap_prefix_list
6253 || type == bgp_show_type_flap_prefix_longer
6254 || type == bgp_show_type_flap_route_map
6255 || type == bgp_show_type_flap_neighbor
6256 || type == bgp_show_type_dampend_paths
6257 || type == bgp_show_type_damp_neighbor)
6258 {
fb982c25 6259 if (!(ri->extra && ri->extra->damp_info))
718e3744 6260 continue;
6261 }
6262 if (type == bgp_show_type_regexp
6263 || type == bgp_show_type_flap_regexp)
6264 {
5a646650 6265 regex_t *regex = output_arg;
718e3744 6266
6267 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6268 continue;
6269 }
6270 if (type == bgp_show_type_prefix_list
6271 || type == bgp_show_type_flap_prefix_list)
6272 {
5a646650 6273 struct prefix_list *plist = output_arg;
718e3744 6274
6275 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6276 continue;
6277 }
6278 if (type == bgp_show_type_filter_list
6279 || type == bgp_show_type_flap_filter_list)
6280 {
5a646650 6281 struct as_list *as_list = output_arg;
718e3744 6282
6283 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6284 continue;
6285 }
6286 if (type == bgp_show_type_route_map
6287 || type == bgp_show_type_flap_route_map)
6288 {
5a646650 6289 struct route_map *rmap = output_arg;
718e3744 6290 struct bgp_info binfo;
558d1fec
JBD
6291 struct attr dummy_attr;
6292 struct attr_extra dummy_extra;
718e3744 6293 int ret;
6294
558d1fec 6295 dummy_attr.extra = &dummy_extra;
fb982c25 6296 bgp_attr_dup (&dummy_attr, ri->attr);
558d1fec 6297
718e3744 6298 binfo.peer = ri->peer;
6299 binfo.attr = &dummy_attr;
6300
6301 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
718e3744 6302 if (ret == RMAP_DENYMATCH)
6303 continue;
6304 }
6305 if (type == bgp_show_type_neighbor
6306 || type == bgp_show_type_flap_neighbor
6307 || type == bgp_show_type_damp_neighbor)
6308 {
5a646650 6309 union sockunion *su = output_arg;
718e3744 6310
6311 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6312 continue;
6313 }
6314 if (type == bgp_show_type_cidr_only
6315 || type == bgp_show_type_flap_cidr_only)
6316 {
6317 u_int32_t destination;
6318
6319 destination = ntohl (rn->p.u.prefix4.s_addr);
6320 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6321 continue;
6322 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6323 continue;
6324 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6325 continue;
6326 }
6327 if (type == bgp_show_type_prefix_longer
6328 || type == bgp_show_type_flap_prefix_longer)
6329 {
5a646650 6330 struct prefix *p = output_arg;
718e3744 6331
6332 if (! prefix_match (p, &rn->p))
6333 continue;
6334 }
6335 if (type == bgp_show_type_community_all)
6336 {
6337 if (! ri->attr->community)
6338 continue;
6339 }
6340 if (type == bgp_show_type_community)
6341 {
5a646650 6342 struct community *com = output_arg;
718e3744 6343
6344 if (! ri->attr->community ||
6345 ! community_match (ri->attr->community, com))
6346 continue;
6347 }
6348 if (type == bgp_show_type_community_exact)
6349 {
5a646650 6350 struct community *com = output_arg;
718e3744 6351
6352 if (! ri->attr->community ||
6353 ! community_cmp (ri->attr->community, com))
6354 continue;
6355 }
6356 if (type == bgp_show_type_community_list)
6357 {
5a646650 6358 struct community_list *list = output_arg;
718e3744 6359
6360 if (! community_list_match (ri->attr->community, list))
6361 continue;
6362 }
6363 if (type == bgp_show_type_community_list_exact)
6364 {
5a646650 6365 struct community_list *list = output_arg;
718e3744 6366
6367 if (! community_list_exact_match (ri->attr->community, list))
6368 continue;
6369 }
6370 if (type == bgp_show_type_flap_address
6371 || type == bgp_show_type_flap_prefix)
6372 {
5a646650 6373 struct prefix *p = output_arg;
718e3744 6374
6375 if (! prefix_match (&rn->p, p))
6376 continue;
6377
6378 if (type == bgp_show_type_flap_prefix)
6379 if (p->prefixlen != rn->p.prefixlen)
6380 continue;
6381 }
6382 if (type == bgp_show_type_dampend_paths
6383 || type == bgp_show_type_damp_neighbor)
6384 {
6385 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6386 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6387 continue;
6388 }
6389
47fc97cc
DS
6390 if (delim)
6391 {
6392 if (header)
6393 {
6394 vty_out (vty, BGP_SHOW_HEADER_CSV, VTY_NEWLINE);
6395 header = 0;
6396 }
6397 }
6398 else if (header)
718e3744 6399 {
93406d87 6400 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6401 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6402 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 6403 if (type == bgp_show_type_dampend_paths
6404 || type == bgp_show_type_damp_neighbor)
6405 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6406 else if (type == bgp_show_type_flap_statistics
6407 || type == bgp_show_type_flap_address
6408 || type == bgp_show_type_flap_prefix
6409 || type == bgp_show_type_flap_cidr_only
6410 || type == bgp_show_type_flap_regexp
6411 || type == bgp_show_type_flap_filter_list
6412 || type == bgp_show_type_flap_prefix_list
6413 || type == bgp_show_type_flap_prefix_longer
6414 || type == bgp_show_type_flap_route_map
6415 || type == bgp_show_type_flap_neighbor)
6416 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6417 else
6418 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
718e3744 6419 header = 0;
6420 }
6421
6422 if (type == bgp_show_type_dampend_paths
6423 || type == bgp_show_type_damp_neighbor)
5a646650 6424 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
718e3744 6425 else if (type == bgp_show_type_flap_statistics
6426 || type == bgp_show_type_flap_address
6427 || type == bgp_show_type_flap_prefix
6428 || type == bgp_show_type_flap_cidr_only
6429 || type == bgp_show_type_flap_regexp
6430 || type == bgp_show_type_flap_filter_list
6431 || type == bgp_show_type_flap_prefix_list
6432 || type == bgp_show_type_flap_prefix_longer
6433 || type == bgp_show_type_flap_route_map
6434 || type == bgp_show_type_flap_neighbor)
5a646650 6435 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
718e3744 6436 else
47fc97cc 6437 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, delim);
718e3744 6438 display++;
6439 }
6440 if (display)
5a646650 6441 output_count++;
718e3744 6442 }
6443
6444 /* No route is displayed */
5a646650 6445 if (output_count == 0)
718e3744 6446 {
6447 if (type == bgp_show_type_normal)
6448 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6449 }
6450 else
6451 vty_out (vty, "%sTotal number of prefixes %ld%s",
5a646650 6452 VTY_NEWLINE, output_count, VTY_NEWLINE);
718e3744 6453
6454 return CMD_SUCCESS;
6455}
6456
5a646650 6457static int
fee0f4c6 6458bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
47fc97cc 6459 enum bgp_show_type type, void *output_arg, char *delim)
fee0f4c6 6460{
6461 struct bgp_table *table;
6462
6463 if (bgp == NULL) {
6464 bgp = bgp_get_default ();
6465 }
6466
6467 if (bgp == NULL)
6468 {
6469 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6470 return CMD_WARNING;
6471 }
6472
6473
6474 table = bgp->rib[afi][safi];
6475
47fc97cc 6476 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg, delim);
fee0f4c6 6477}
6478
718e3744 6479/* Header of detailed BGP route information */
94f2b392 6480static void
718e3744 6481route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6482 struct bgp_node *rn,
6483 struct prefix_rd *prd, afi_t afi, safi_t safi)
6484{
6485 struct bgp_info *ri;
6486 struct prefix *p;
6487 struct peer *peer;
1eb8ef25 6488 struct listnode *node, *nnode;
718e3744 6489 char buf1[INET6_ADDRSTRLEN];
6490 char buf2[INET6_ADDRSTRLEN];
6491 int count = 0;
6492 int best = 0;
6493 int suppress = 0;
6494 int no_export = 0;
6495 int no_advertise = 0;
6496 int local_as = 0;
6497 int first = 0;
6498
6499 p = &rn->p;
6500 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6501 (safi == SAFI_MPLS_VPN ?
6502 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6503 safi == SAFI_MPLS_VPN ? ":" : "",
6504 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6505 p->prefixlen, VTY_NEWLINE);
6506
6507 for (ri = rn->info; ri; ri = ri->next)
6508 {
6509 count++;
6510 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6511 {
6512 best = count;
fb982c25 6513 if (ri->extra && ri->extra->suppress)
718e3744 6514 suppress = 1;
6515 if (ri->attr->community != NULL)
6516 {
6517 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6518 no_advertise = 1;
6519 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6520 no_export = 1;
6521 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6522 local_as = 1;
6523 }
6524 }
6525 }
6526
6527 vty_out (vty, "Paths: (%d available", count);
6528 if (best)
6529 {
6530 vty_out (vty, ", best #%d", best);
6531 if (safi == SAFI_UNICAST)
6532 vty_out (vty, ", table Default-IP-Routing-Table");
6533 }
6534 else
6535 vty_out (vty, ", no best path");
6536 if (no_advertise)
6537 vty_out (vty, ", not advertised to any peer");
6538 else if (no_export)
6539 vty_out (vty, ", not advertised to EBGP peer");
6540 else if (local_as)
6541 vty_out (vty, ", not advertised outside local AS");
6542 if (suppress)
6543 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6544 vty_out (vty, ")%s", VTY_NEWLINE);
6545
6546 /* advertised peer */
1eb8ef25 6547 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
718e3744 6548 {
6549 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6550 {
6551 if (! first)
6552 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6553 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6554 first = 1;
6555 }
6556 }
6557 if (! first)
6558 vty_out (vty, " Not advertised to any peer");
6559 vty_out (vty, "%s", VTY_NEWLINE);
6560}
6561
6562/* Display specified route of BGP table. */
94f2b392 6563static int
fee0f4c6 6564bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
fd79ac91 6565 struct bgp_table *rib, const char *ip_str,
6566 afi_t afi, safi_t safi, struct prefix_rd *prd,
6567 int prefix_check)
718e3744 6568{
6569 int ret;
6570 int header;
6571 int display = 0;
6572 struct prefix match;
6573 struct bgp_node *rn;
6574 struct bgp_node *rm;
6575 struct bgp_info *ri;
718e3744 6576 struct bgp_table *table;
6577
718e3744 6578 /* Check IP address argument. */
6579 ret = str2prefix (ip_str, &match);
6580 if (! ret)
6581 {
6582 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6583 return CMD_WARNING;
6584 }
6585
6586 match.family = afi2family (afi);
6587
6588 if (safi == SAFI_MPLS_VPN)
6589 {
fee0f4c6 6590 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
718e3744 6591 {
6592 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6593 continue;
6594
6595 if ((table = rn->info) != NULL)
6596 {
6597 header = 1;
6598
6599 if ((rm = bgp_node_match (table, &match)) != NULL)
6600 {
6601 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6c88b44d
CC
6602 {
6603 bgp_unlock_node (rm);
6604 continue;
6605 }
718e3744 6606
6607 for (ri = rm->info; ri; ri = ri->next)
6608 {
6609 if (header)
6610 {
6611 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6612 AFI_IP, SAFI_MPLS_VPN);
6613
6614 header = 0;
6615 }
6616 display++;
6617 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6618 }
6c88b44d
CC
6619
6620 bgp_unlock_node (rm);
718e3744 6621 }
6622 }
6623 }
6624 }
6625 else
6626 {
6627 header = 1;
6628
fee0f4c6 6629 if ((rn = bgp_node_match (rib, &match)) != NULL)
718e3744 6630 {
6631 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6632 {
6633 for (ri = rn->info; ri; ri = ri->next)
6634 {
6635 if (header)
6636 {
6637 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6638 header = 0;
6639 }
6640 display++;
6641 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6642 }
6643 }
6c88b44d
CC
6644
6645 bgp_unlock_node (rn);
718e3744 6646 }
6647 }
6648
6649 if (! display)
6650 {
6651 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6652 return CMD_WARNING;
6653 }
6654
6655 return CMD_SUCCESS;
6656}
6657
fee0f4c6 6658/* Display specified route of Main RIB */
94f2b392 6659static int
fd79ac91 6660bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
fee0f4c6 6661 afi_t afi, safi_t safi, struct prefix_rd *prd,
6662 int prefix_check)
6663{
6664 struct bgp *bgp;
6665
6666 /* BGP structure lookup. */
6667 if (view_name)
6668 {
6669 bgp = bgp_lookup_by_name (view_name);
6670 if (bgp == NULL)
6671 {
6672 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6673 return CMD_WARNING;
6674 }
6675 }
6676 else
6677 {
6678 bgp = bgp_get_default ();
6679 if (bgp == NULL)
6680 {
6681 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6682 return CMD_WARNING;
6683 }
6684 }
6685
6686 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6687 afi, safi, prd, prefix_check);
6688}
6689
718e3744 6690/* BGP route print out function. */
6691DEFUN (show_ip_bgp,
6692 show_ip_bgp_cmd,
6693 "show ip bgp",
6694 SHOW_STR
6695 IP_STR
6696 BGP_STR)
6697{
47fc97cc
DS
6698 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
6699}
6700
6701DEFUN (show_ip_bgp_csv,
6702 show_ip_bgp_csv_cmd,
6703 "show ip bgp csv",
6704 SHOW_STR
6705 IP_STR
6706 BGP_STR)
6707{
6708 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, &csv);
718e3744 6709}
6710
6711DEFUN (show_ip_bgp_ipv4,
6712 show_ip_bgp_ipv4_cmd,
6713 "show ip bgp ipv4 (unicast|multicast)",
6714 SHOW_STR
6715 IP_STR
6716 BGP_STR
6717 "Address family\n"
6718 "Address Family modifier\n"
6719 "Address Family modifier\n")
6720{
6721 if (strncmp (argv[0], "m", 1) == 0)
5a646650 6722 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
47fc97cc 6723 NULL, NULL);
718e3744 6724
47fc97cc 6725 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
718e3744 6726}
6727
95cbbd2a
ML
6728ALIAS (show_ip_bgp_ipv4,
6729 show_bgp_ipv4_safi_cmd,
6730 "show bgp ipv4 (unicast|multicast)",
6731 SHOW_STR
6732 BGP_STR
6733 "Address family\n"
6734 "Address Family modifier\n"
6735 "Address Family modifier\n")
6736
47fc97cc
DS
6737DEFUN (show_ip_bgp_ipv4_csv,
6738 show_bgp_ipv4_safi_csv_cmd,
6739 "show bgp ipv4 (unicast|multicast) csv",
6740 SHOW_STR
6741 BGP_STR
6742 "Address family\n"
6743 "Address Family modifier\n"
6744 "Address Family modifier\n")
6745{
6746 if (strncmp (argv[0], "m", 1) == 0)
6747 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6748 NULL, &csv);
6749
6750 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, &csv);
6751}
6752
718e3744 6753DEFUN (show_ip_bgp_route,
6754 show_ip_bgp_route_cmd,
6755 "show ip bgp A.B.C.D",
6756 SHOW_STR
6757 IP_STR
6758 BGP_STR
6759 "Network in the BGP routing table to display\n")
6760{
6761 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6762}
6763
6764DEFUN (show_ip_bgp_ipv4_route,
6765 show_ip_bgp_ipv4_route_cmd,
6766 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6767 SHOW_STR
6768 IP_STR
6769 BGP_STR
6770 "Address family\n"
6771 "Address Family modifier\n"
6772 "Address Family modifier\n"
6773 "Network in the BGP routing table to display\n")
6774{
6775 if (strncmp (argv[0], "m", 1) == 0)
6776 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6777
6778 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6779}
6780
95cbbd2a
ML
6781ALIAS (show_ip_bgp_ipv4_route,
6782 show_bgp_ipv4_safi_route_cmd,
6783 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6784 SHOW_STR
6785 BGP_STR
6786 "Address family\n"
6787 "Address Family modifier\n"
6788 "Address Family modifier\n"
6789 "Network in the BGP routing table to display\n")
6790
718e3744 6791DEFUN (show_ip_bgp_vpnv4_all_route,
6792 show_ip_bgp_vpnv4_all_route_cmd,
6793 "show ip bgp vpnv4 all A.B.C.D",
6794 SHOW_STR
6795 IP_STR
6796 BGP_STR
6797 "Display VPNv4 NLRI specific information\n"
6798 "Display information about all VPNv4 NLRIs\n"
6799 "Network in the BGP routing table to display\n")
6800{
6801 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6802}
6803
6804DEFUN (show_ip_bgp_vpnv4_rd_route,
6805 show_ip_bgp_vpnv4_rd_route_cmd,
6806 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6807 SHOW_STR
6808 IP_STR
6809 BGP_STR
6810 "Display VPNv4 NLRI specific information\n"
6811 "Display information for a route distinguisher\n"
6812 "VPN Route Distinguisher\n"
6813 "Network in the BGP routing table to display\n")
6814{
6815 int ret;
6816 struct prefix_rd prd;
6817
6818 ret = str2prefix_rd (argv[0], &prd);
6819 if (! ret)
6820 {
6821 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6822 return CMD_WARNING;
6823 }
6824 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6825}
6826
6827DEFUN (show_ip_bgp_prefix,
6828 show_ip_bgp_prefix_cmd,
6829 "show ip bgp A.B.C.D/M",
6830 SHOW_STR
6831 IP_STR
6832 BGP_STR
6833 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6834{
6835 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6836}
6837
6838DEFUN (show_ip_bgp_ipv4_prefix,
6839 show_ip_bgp_ipv4_prefix_cmd,
6840 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6841 SHOW_STR
6842 IP_STR
6843 BGP_STR
6844 "Address family\n"
6845 "Address Family modifier\n"
6846 "Address Family modifier\n"
6847 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6848{
6849 if (strncmp (argv[0], "m", 1) == 0)
6850 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6851
6852 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6853}
6854
95cbbd2a
ML
6855ALIAS (show_ip_bgp_ipv4_prefix,
6856 show_bgp_ipv4_safi_prefix_cmd,
6857 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6858 SHOW_STR
6859 BGP_STR
6860 "Address family\n"
6861 "Address Family modifier\n"
6862 "Address Family modifier\n"
6863 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6864
718e3744 6865DEFUN (show_ip_bgp_vpnv4_all_prefix,
6866 show_ip_bgp_vpnv4_all_prefix_cmd,
6867 "show ip bgp vpnv4 all A.B.C.D/M",
6868 SHOW_STR
6869 IP_STR
6870 BGP_STR
6871 "Display VPNv4 NLRI specific information\n"
6872 "Display information about all VPNv4 NLRIs\n"
6873 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6874{
6875 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6876}
6877
6878DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6879 show_ip_bgp_vpnv4_rd_prefix_cmd,
6880 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6881 SHOW_STR
6882 IP_STR
6883 BGP_STR
6884 "Display VPNv4 NLRI specific information\n"
6885 "Display information for a route distinguisher\n"
6886 "VPN Route Distinguisher\n"
6887 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6888{
6889 int ret;
6890 struct prefix_rd prd;
6891
6892 ret = str2prefix_rd (argv[0], &prd);
6893 if (! ret)
6894 {
6895 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6896 return CMD_WARNING;
6897 }
6898 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6899}
6900
6901DEFUN (show_ip_bgp_view,
6902 show_ip_bgp_view_cmd,
6903 "show ip bgp view WORD",
6904 SHOW_STR
6905 IP_STR
6906 BGP_STR
6907 "BGP view\n"
2b00515a 6908 "View name\n")
718e3744 6909{
bb46e94f 6910 struct bgp *bgp;
6911
6912 /* BGP structure lookup. */
6913 bgp = bgp_lookup_by_name (argv[0]);
6914 if (bgp == NULL)
6915 {
6916 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6917 return CMD_WARNING;
6918 }
6919
47fc97cc 6920 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
718e3744 6921}
6922
6923DEFUN (show_ip_bgp_view_route,
6924 show_ip_bgp_view_route_cmd,
6925 "show ip bgp view WORD A.B.C.D",
6926 SHOW_STR
6927 IP_STR
6928 BGP_STR
6929 "BGP view\n"
2b00515a 6930 "View name\n"
718e3744 6931 "Network in the BGP routing table to display\n")
6932{
6933 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6934}
6935
6936DEFUN (show_ip_bgp_view_prefix,
6937 show_ip_bgp_view_prefix_cmd,
6938 "show ip bgp view WORD A.B.C.D/M",
6939 SHOW_STR
6940 IP_STR
6941 BGP_STR
6942 "BGP view\n"
2b00515a 6943 "View name\n"
718e3744 6944 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6945{
6946 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6947}
6948
6949#ifdef HAVE_IPV6
6950DEFUN (show_bgp,
6951 show_bgp_cmd,
6952 "show bgp",
6953 SHOW_STR
6954 BGP_STR)
6955{
5a646650 6956 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
47fc97cc 6957 NULL, NULL);
718e3744 6958}
6959
6960ALIAS (show_bgp,
6961 show_bgp_ipv6_cmd,
6962 "show bgp ipv6",
6963 SHOW_STR
6964 BGP_STR
6965 "Address family\n")
6966
95cbbd2a
ML
6967DEFUN (show_bgp_ipv6_safi,
6968 show_bgp_ipv6_safi_cmd,
6969 "show bgp ipv6 (unicast|multicast)",
6970 SHOW_STR
6971 BGP_STR
6972 "Address family\n"
6973 "Address Family modifier\n"
6974 "Address Family modifier\n")
6975{
6976 if (strncmp (argv[0], "m", 1) == 0)
6977 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
47fc97cc 6978 NULL, NULL);
95cbbd2a 6979
47fc97cc
DS
6980 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
6981}
6982
6983DEFUN (show_bgp_ipv6_safi_csv,
6984 show_bgp_ipv6_safi_csv_cmd,
6985 "show bgp ipv6 (unicast|multicast) csv",
6986 SHOW_STR
6987 BGP_STR
6988 "Address family\n"
6989 "Address Family modifier\n"
6990 "Address Family modifier\n")
6991{
6992 if (strncmp (argv[0], "m", 1) == 0)
6993 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6994 NULL, &csv);
6995
6996 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, &csv);
95cbbd2a
ML
6997}
6998
718e3744 6999/* old command */
7000DEFUN (show_ipv6_bgp,
7001 show_ipv6_bgp_cmd,
7002 "show ipv6 bgp",
7003 SHOW_STR
7004 IP_STR
7005 BGP_STR)
7006{
5a646650 7007 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
47fc97cc 7008 NULL, NULL);
718e3744 7009}
7010
7011DEFUN (show_bgp_route,
7012 show_bgp_route_cmd,
7013 "show bgp X:X::X:X",
7014 SHOW_STR
7015 BGP_STR
7016 "Network in the BGP routing table to display\n")
7017{
7018 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7019}
7020
7021ALIAS (show_bgp_route,
7022 show_bgp_ipv6_route_cmd,
7023 "show bgp ipv6 X:X::X:X",
7024 SHOW_STR
7025 BGP_STR
7026 "Address family\n"
7027 "Network in the BGP routing table to display\n")
7028
95cbbd2a
ML
7029DEFUN (show_bgp_ipv6_safi_route,
7030 show_bgp_ipv6_safi_route_cmd,
7031 "show bgp ipv6 (unicast|multicast) X:X::X:X",
7032 SHOW_STR
7033 BGP_STR
7034 "Address family\n"
7035 "Address Family modifier\n"
7036 "Address Family modifier\n"
7037 "Network in the BGP routing table to display\n")
7038{
7039 if (strncmp (argv[0], "m", 1) == 0)
7040 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7041
7042 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7043}
7044
718e3744 7045/* old command */
7046DEFUN (show_ipv6_bgp_route,
7047 show_ipv6_bgp_route_cmd,
7048 "show ipv6 bgp X:X::X:X",
7049 SHOW_STR
7050 IP_STR
7051 BGP_STR
7052 "Network in the BGP routing table to display\n")
7053{
7054 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7055}
7056
7057DEFUN (show_bgp_prefix,
7058 show_bgp_prefix_cmd,
7059 "show bgp X:X::X:X/M",
7060 SHOW_STR
7061 BGP_STR
7062 "IPv6 prefix <network>/<length>\n")
7063{
7064 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7065}
7066
7067ALIAS (show_bgp_prefix,
7068 show_bgp_ipv6_prefix_cmd,
7069 "show bgp ipv6 X:X::X:X/M",
7070 SHOW_STR
7071 BGP_STR
7072 "Address family\n"
7073 "IPv6 prefix <network>/<length>\n")
7074
95cbbd2a
ML
7075DEFUN (show_bgp_ipv6_safi_prefix,
7076 show_bgp_ipv6_safi_prefix_cmd,
7077 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7078 SHOW_STR
7079 BGP_STR
7080 "Address family\n"
7081 "Address Family modifier\n"
7082 "Address Family modifier\n"
7083 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7084{
7085 if (strncmp (argv[0], "m", 1) == 0)
7086 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7087
7088 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7089}
7090
718e3744 7091/* old command */
7092DEFUN (show_ipv6_bgp_prefix,
7093 show_ipv6_bgp_prefix_cmd,
7094 "show ipv6 bgp X:X::X:X/M",
7095 SHOW_STR
7096 IP_STR
7097 BGP_STR
7098 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7099{
7100 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7101}
7102
bb46e94f 7103DEFUN (show_bgp_view,
7104 show_bgp_view_cmd,
7105 "show bgp view WORD",
7106 SHOW_STR
7107 BGP_STR
7108 "BGP view\n"
7109 "View name\n")
7110{
7111 struct bgp *bgp;
7112
7113 /* BGP structure lookup. */
7114 bgp = bgp_lookup_by_name (argv[0]);
7115 if (bgp == NULL)
7116 {
7117 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7118 return CMD_WARNING;
7119 }
7120
47fc97cc 7121 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
bb46e94f 7122}
7123
7124ALIAS (show_bgp_view,
7125 show_bgp_view_ipv6_cmd,
7126 "show bgp view WORD ipv6",
7127 SHOW_STR
7128 BGP_STR
7129 "BGP view\n"
7130 "View name\n"
7131 "Address family\n")
7132
7133DEFUN (show_bgp_view_route,
7134 show_bgp_view_route_cmd,
7135 "show bgp view WORD X:X::X:X",
7136 SHOW_STR
7137 BGP_STR
7138 "BGP view\n"
7139 "View name\n"
7140 "Network in the BGP routing table to display\n")
7141{
7142 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7143}
7144
7145ALIAS (show_bgp_view_route,
7146 show_bgp_view_ipv6_route_cmd,
7147 "show bgp view WORD ipv6 X:X::X:X",
7148 SHOW_STR
7149 BGP_STR
7150 "BGP view\n"
7151 "View name\n"
7152 "Address family\n"
7153 "Network in the BGP routing table to display\n")
7154
7155DEFUN (show_bgp_view_prefix,
7156 show_bgp_view_prefix_cmd,
7157 "show bgp view WORD X:X::X:X/M",
7158 SHOW_STR
7159 BGP_STR
7160 "BGP view\n"
7161 "View name\n"
7162 "IPv6 prefix <network>/<length>\n")
7163{
7164 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7165}
7166
7167ALIAS (show_bgp_view_prefix,
7168 show_bgp_view_ipv6_prefix_cmd,
7169 "show bgp view WORD ipv6 X:X::X:X/M",
7170 SHOW_STR
7171 BGP_STR
7172 "BGP view\n"
7173 "View name\n"
7174 "Address family\n"
7175 "IPv6 prefix <network>/<length>\n")
7176
718e3744 7177/* old command */
7178DEFUN (show_ipv6_mbgp,
7179 show_ipv6_mbgp_cmd,
7180 "show ipv6 mbgp",
7181 SHOW_STR
7182 IP_STR
7183 MBGP_STR)
7184{
5a646650 7185 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
47fc97cc 7186 NULL, NULL);
718e3744 7187}
7188
7189/* old command */
7190DEFUN (show_ipv6_mbgp_route,
7191 show_ipv6_mbgp_route_cmd,
7192 "show ipv6 mbgp X:X::X:X",
7193 SHOW_STR
7194 IP_STR
7195 MBGP_STR
7196 "Network in the MBGP routing table to display\n")
7197{
7198 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7199}
7200
7201/* old command */
7202DEFUN (show_ipv6_mbgp_prefix,
7203 show_ipv6_mbgp_prefix_cmd,
7204 "show ipv6 mbgp X:X::X:X/M",
7205 SHOW_STR
7206 IP_STR
7207 MBGP_STR
7208 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7209{
7210 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7211}
7212#endif
6b0655a2 7213
718e3744 7214
94f2b392 7215static int
fd79ac91 7216bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
718e3744 7217 safi_t safi, enum bgp_show_type type)
7218{
7219 int i;
7220 struct buffer *b;
7221 char *regstr;
7222 int first;
7223 regex_t *regex;
5a646650 7224 int rc;
718e3744 7225
7226 first = 0;
7227 b = buffer_new (1024);
7228 for (i = 0; i < argc; i++)
7229 {
7230 if (first)
7231 buffer_putc (b, ' ');
7232 else
7233 {
7234 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7235 continue;
7236 first = 1;
7237 }
7238
7239 buffer_putstr (b, argv[i]);
7240 }
7241 buffer_putc (b, '\0');
7242
7243 regstr = buffer_getstr (b);
7244 buffer_free (b);
7245
7246 regex = bgp_regcomp (regstr);
3b8b1855 7247 XFREE(MTYPE_TMP, regstr);
718e3744 7248 if (! regex)
7249 {
7250 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7251 VTY_NEWLINE);
7252 return CMD_WARNING;
7253 }
7254
47fc97cc 7255 rc = bgp_show (vty, NULL, afi, safi, type, regex, NULL);
5a646650 7256 bgp_regex_free (regex);
7257 return rc;
718e3744 7258}
7259
7260DEFUN (show_ip_bgp_regexp,
7261 show_ip_bgp_regexp_cmd,
7262 "show ip bgp regexp .LINE",
7263 SHOW_STR
7264 IP_STR
7265 BGP_STR
7266 "Display routes matching the AS path regular expression\n"
7267 "A regular-expression to match the BGP AS paths\n")
7268{
7269 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7270 bgp_show_type_regexp);
7271}
7272
7273DEFUN (show_ip_bgp_flap_regexp,
7274 show_ip_bgp_flap_regexp_cmd,
7275 "show ip bgp flap-statistics regexp .LINE",
7276 SHOW_STR
7277 IP_STR
7278 BGP_STR
7279 "Display flap statistics of routes\n"
7280 "Display routes matching the AS path regular expression\n"
7281 "A regular-expression to match the BGP AS paths\n")
7282{
7283 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7284 bgp_show_type_flap_regexp);
7285}
7286
7287DEFUN (show_ip_bgp_ipv4_regexp,
7288 show_ip_bgp_ipv4_regexp_cmd,
7289 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7290 SHOW_STR
7291 IP_STR
7292 BGP_STR
7293 "Address family\n"
7294 "Address Family modifier\n"
7295 "Address Family modifier\n"
7296 "Display routes matching the AS path regular expression\n"
7297 "A regular-expression to match the BGP AS paths\n")
7298{
7299 if (strncmp (argv[0], "m", 1) == 0)
7300 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7301 bgp_show_type_regexp);
7302
7303 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7304 bgp_show_type_regexp);
7305}
7306
7307#ifdef HAVE_IPV6
7308DEFUN (show_bgp_regexp,
7309 show_bgp_regexp_cmd,
7310 "show bgp regexp .LINE",
7311 SHOW_STR
7312 BGP_STR
7313 "Display routes matching the AS path regular expression\n"
7314 "A regular-expression to match the BGP AS paths\n")
7315{
7316 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7317 bgp_show_type_regexp);
7318}
7319
7320ALIAS (show_bgp_regexp,
7321 show_bgp_ipv6_regexp_cmd,
7322 "show bgp ipv6 regexp .LINE",
7323 SHOW_STR
7324 BGP_STR
7325 "Address family\n"
7326 "Display routes matching the AS path regular expression\n"
7327 "A regular-expression to match the BGP AS paths\n")
7328
7329/* old command */
7330DEFUN (show_ipv6_bgp_regexp,
7331 show_ipv6_bgp_regexp_cmd,
7332 "show ipv6 bgp regexp .LINE",
7333 SHOW_STR
7334 IP_STR
7335 BGP_STR
7336 "Display routes matching the AS path regular expression\n"
7337 "A regular-expression to match the BGP AS paths\n")
7338{
7339 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7340 bgp_show_type_regexp);
7341}
7342
7343/* old command */
7344DEFUN (show_ipv6_mbgp_regexp,
7345 show_ipv6_mbgp_regexp_cmd,
7346 "show ipv6 mbgp regexp .LINE",
7347 SHOW_STR
7348 IP_STR
7349 BGP_STR
7350 "Display routes matching the AS path regular expression\n"
7351 "A regular-expression to match the MBGP AS paths\n")
7352{
7353 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7354 bgp_show_type_regexp);
7355}
7356#endif /* HAVE_IPV6 */
6b0655a2 7357
94f2b392 7358static int
fd79ac91 7359bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
718e3744 7360 safi_t safi, enum bgp_show_type type)
7361{
7362 struct prefix_list *plist;
7363
7364 plist = prefix_list_lookup (afi, prefix_list_str);
7365 if (plist == NULL)
7366 {
7367 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7368 prefix_list_str, VTY_NEWLINE);
7369 return CMD_WARNING;
7370 }
7371
47fc97cc 7372 return bgp_show (vty, NULL, afi, safi, type, plist, NULL);
718e3744 7373}
7374
7375DEFUN (show_ip_bgp_prefix_list,
7376 show_ip_bgp_prefix_list_cmd,
7377 "show ip bgp prefix-list WORD",
7378 SHOW_STR
7379 IP_STR
7380 BGP_STR
7381 "Display routes conforming to the prefix-list\n"
7382 "IP prefix-list name\n")
7383{
7384 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7385 bgp_show_type_prefix_list);
7386}
7387
7388DEFUN (show_ip_bgp_flap_prefix_list,
7389 show_ip_bgp_flap_prefix_list_cmd,
7390 "show ip bgp flap-statistics prefix-list WORD",
7391 SHOW_STR
7392 IP_STR
7393 BGP_STR
7394 "Display flap statistics of routes\n"
7395 "Display routes conforming to the prefix-list\n"
7396 "IP prefix-list name\n")
7397{
7398 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7399 bgp_show_type_flap_prefix_list);
7400}
7401
7402DEFUN (show_ip_bgp_ipv4_prefix_list,
7403 show_ip_bgp_ipv4_prefix_list_cmd,
7404 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7405 SHOW_STR
7406 IP_STR
7407 BGP_STR
7408 "Address family\n"
7409 "Address Family modifier\n"
7410 "Address Family modifier\n"
7411 "Display routes conforming to the prefix-list\n"
7412 "IP prefix-list name\n")
7413{
7414 if (strncmp (argv[0], "m", 1) == 0)
7415 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7416 bgp_show_type_prefix_list);
7417
7418 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7419 bgp_show_type_prefix_list);
7420}
7421
7422#ifdef HAVE_IPV6
7423DEFUN (show_bgp_prefix_list,
7424 show_bgp_prefix_list_cmd,
7425 "show bgp prefix-list WORD",
7426 SHOW_STR
7427 BGP_STR
7428 "Display routes conforming to the prefix-list\n"
7429 "IPv6 prefix-list name\n")
7430{
7431 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7432 bgp_show_type_prefix_list);
7433}
7434
7435ALIAS (show_bgp_prefix_list,
7436 show_bgp_ipv6_prefix_list_cmd,
7437 "show bgp ipv6 prefix-list WORD",
7438 SHOW_STR
7439 BGP_STR
7440 "Address family\n"
7441 "Display routes conforming to the prefix-list\n"
7442 "IPv6 prefix-list name\n")
7443
7444/* old command */
7445DEFUN (show_ipv6_bgp_prefix_list,
7446 show_ipv6_bgp_prefix_list_cmd,
7447 "show ipv6 bgp prefix-list WORD",
7448 SHOW_STR
7449 IPV6_STR
7450 BGP_STR
7451 "Display routes matching the prefix-list\n"
7452 "IPv6 prefix-list name\n")
7453{
7454 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7455 bgp_show_type_prefix_list);
7456}
7457
7458/* old command */
7459DEFUN (show_ipv6_mbgp_prefix_list,
7460 show_ipv6_mbgp_prefix_list_cmd,
7461 "show ipv6 mbgp prefix-list WORD",
7462 SHOW_STR
7463 IPV6_STR
7464 MBGP_STR
7465 "Display routes matching the prefix-list\n"
7466 "IPv6 prefix-list name\n")
7467{
7468 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7469 bgp_show_type_prefix_list);
7470}
7471#endif /* HAVE_IPV6 */
6b0655a2 7472
94f2b392 7473static int
fd79ac91 7474bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
718e3744 7475 safi_t safi, enum bgp_show_type type)
7476{
7477 struct as_list *as_list;
7478
7479 as_list = as_list_lookup (filter);
7480 if (as_list == NULL)
7481 {
7482 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7483 return CMD_WARNING;
7484 }
7485
47fc97cc 7486 return bgp_show (vty, NULL, afi, safi, type, as_list, NULL);
718e3744 7487}
7488
7489DEFUN (show_ip_bgp_filter_list,
7490 show_ip_bgp_filter_list_cmd,
7491 "show ip bgp filter-list WORD",
7492 SHOW_STR
7493 IP_STR
7494 BGP_STR
7495 "Display routes conforming to the filter-list\n"
7496 "Regular expression access list name\n")
7497{
7498 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7499 bgp_show_type_filter_list);
7500}
7501
7502DEFUN (show_ip_bgp_flap_filter_list,
7503 show_ip_bgp_flap_filter_list_cmd,
7504 "show ip bgp flap-statistics filter-list WORD",
7505 SHOW_STR
7506 IP_STR
7507 BGP_STR
7508 "Display flap statistics of routes\n"
7509 "Display routes conforming to the filter-list\n"
7510 "Regular expression access list name\n")
7511{
7512 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7513 bgp_show_type_flap_filter_list);
7514}
7515
7516DEFUN (show_ip_bgp_ipv4_filter_list,
7517 show_ip_bgp_ipv4_filter_list_cmd,
7518 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7519 SHOW_STR
7520 IP_STR
7521 BGP_STR
7522 "Address family\n"
7523 "Address Family modifier\n"
7524 "Address Family modifier\n"
7525 "Display routes conforming to the filter-list\n"
7526 "Regular expression access list name\n")
7527{
7528 if (strncmp (argv[0], "m", 1) == 0)
7529 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7530 bgp_show_type_filter_list);
7531
7532 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7533 bgp_show_type_filter_list);
7534}
7535
7536#ifdef HAVE_IPV6
7537DEFUN (show_bgp_filter_list,
7538 show_bgp_filter_list_cmd,
7539 "show bgp filter-list WORD",
7540 SHOW_STR
7541 BGP_STR
7542 "Display routes conforming to the filter-list\n"
7543 "Regular expression access list name\n")
7544{
7545 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7546 bgp_show_type_filter_list);
7547}
7548
7549ALIAS (show_bgp_filter_list,
7550 show_bgp_ipv6_filter_list_cmd,
7551 "show bgp ipv6 filter-list WORD",
7552 SHOW_STR
7553 BGP_STR
7554 "Address family\n"
7555 "Display routes conforming to the filter-list\n"
7556 "Regular expression access list name\n")
7557
7558/* old command */
7559DEFUN (show_ipv6_bgp_filter_list,
7560 show_ipv6_bgp_filter_list_cmd,
7561 "show ipv6 bgp filter-list WORD",
7562 SHOW_STR
7563 IPV6_STR
7564 BGP_STR
7565 "Display routes conforming to the filter-list\n"
7566 "Regular expression access list name\n")
7567{
7568 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7569 bgp_show_type_filter_list);
7570}
7571
7572/* old command */
7573DEFUN (show_ipv6_mbgp_filter_list,
7574 show_ipv6_mbgp_filter_list_cmd,
7575 "show ipv6 mbgp filter-list WORD",
7576 SHOW_STR
7577 IPV6_STR
7578 MBGP_STR
7579 "Display routes conforming to the filter-list\n"
7580 "Regular expression access list name\n")
7581{
7582 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7583 bgp_show_type_filter_list);
7584}
7585#endif /* HAVE_IPV6 */
6b0655a2 7586
94f2b392 7587static int
fd79ac91 7588bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
718e3744 7589 safi_t safi, enum bgp_show_type type)
7590{
7591 struct route_map *rmap;
7592
7593 rmap = route_map_lookup_by_name (rmap_str);
7594 if (! rmap)
7595 {
7596 vty_out (vty, "%% %s is not a valid route-map name%s",
7597 rmap_str, VTY_NEWLINE);
7598 return CMD_WARNING;
7599 }
7600
47fc97cc 7601 return bgp_show (vty, NULL, afi, safi, type, rmap, NULL);
718e3744 7602}
7603
7604DEFUN (show_ip_bgp_route_map,
7605 show_ip_bgp_route_map_cmd,
7606 "show ip bgp route-map WORD",
7607 SHOW_STR
7608 IP_STR
7609 BGP_STR
7610 "Display routes matching the route-map\n"
7611 "A route-map to match on\n")
7612{
7613 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7614 bgp_show_type_route_map);
7615}
7616
7617DEFUN (show_ip_bgp_flap_route_map,
7618 show_ip_bgp_flap_route_map_cmd,
7619 "show ip bgp flap-statistics route-map WORD",
7620 SHOW_STR
7621 IP_STR
7622 BGP_STR
7623 "Display flap statistics of routes\n"
7624 "Display routes matching the route-map\n"
7625 "A route-map to match on\n")
7626{
7627 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7628 bgp_show_type_flap_route_map);
7629}
7630
7631DEFUN (show_ip_bgp_ipv4_route_map,
7632 show_ip_bgp_ipv4_route_map_cmd,
7633 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7634 SHOW_STR
7635 IP_STR
7636 BGP_STR
7637 "Address family\n"
7638 "Address Family modifier\n"
7639 "Address Family modifier\n"
7640 "Display routes matching the route-map\n"
7641 "A route-map to match on\n")
7642{
7643 if (strncmp (argv[0], "m", 1) == 0)
7644 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7645 bgp_show_type_route_map);
7646
7647 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7648 bgp_show_type_route_map);
7649}
7650
7651DEFUN (show_bgp_route_map,
7652 show_bgp_route_map_cmd,
7653 "show bgp route-map WORD",
7654 SHOW_STR
7655 BGP_STR
7656 "Display routes matching the route-map\n"
7657 "A route-map to match on\n")
7658{
7659 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7660 bgp_show_type_route_map);
7661}
7662
7663ALIAS (show_bgp_route_map,
7664 show_bgp_ipv6_route_map_cmd,
7665 "show bgp ipv6 route-map WORD",
7666 SHOW_STR
7667 BGP_STR
7668 "Address family\n"
7669 "Display routes matching the route-map\n"
7670 "A route-map to match on\n")
6b0655a2 7671
718e3744 7672DEFUN (show_ip_bgp_cidr_only,
7673 show_ip_bgp_cidr_only_cmd,
7674 "show ip bgp cidr-only",
7675 SHOW_STR
7676 IP_STR
7677 BGP_STR
7678 "Display only routes with non-natural netmasks\n")
7679{
7680 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
47fc97cc 7681 bgp_show_type_cidr_only, NULL, NULL);
718e3744 7682}
7683
7684DEFUN (show_ip_bgp_flap_cidr_only,
7685 show_ip_bgp_flap_cidr_only_cmd,
7686 "show ip bgp flap-statistics cidr-only",
7687 SHOW_STR
7688 IP_STR
7689 BGP_STR
7690 "Display flap statistics of routes\n"
7691 "Display only routes with non-natural netmasks\n")
7692{
7693 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
47fc97cc 7694 bgp_show_type_flap_cidr_only, NULL, NULL);
718e3744 7695}
7696
7697DEFUN (show_ip_bgp_ipv4_cidr_only,
7698 show_ip_bgp_ipv4_cidr_only_cmd,
7699 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7700 SHOW_STR
7701 IP_STR
7702 BGP_STR
7703 "Address family\n"
7704 "Address Family modifier\n"
7705 "Address Family modifier\n"
7706 "Display only routes with non-natural netmasks\n")
7707{
7708 if (strncmp (argv[0], "m", 1) == 0)
7709 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
47fc97cc 7710 bgp_show_type_cidr_only, NULL, NULL);
718e3744 7711
7712 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
47fc97cc 7713 bgp_show_type_cidr_only, NULL, NULL);
718e3744 7714}
6b0655a2 7715
718e3744 7716DEFUN (show_ip_bgp_community_all,
7717 show_ip_bgp_community_all_cmd,
7718 "show ip bgp community",
7719 SHOW_STR
7720 IP_STR
7721 BGP_STR
7722 "Display routes matching the communities\n")
7723{
7724 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
47fc97cc 7725 bgp_show_type_community_all, NULL, NULL);
718e3744 7726}
7727
7728DEFUN (show_ip_bgp_ipv4_community_all,
7729 show_ip_bgp_ipv4_community_all_cmd,
7730 "show ip bgp ipv4 (unicast|multicast) community",
7731 SHOW_STR
7732 IP_STR
7733 BGP_STR
7734 "Address family\n"
7735 "Address Family modifier\n"
7736 "Address Family modifier\n"
7737 "Display routes matching the communities\n")
7738{
7739 if (strncmp (argv[0], "m", 1) == 0)
7740 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
47fc97cc 7741 bgp_show_type_community_all, NULL, NULL);
718e3744 7742
7743 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
47fc97cc 7744 bgp_show_type_community_all, NULL, NULL);
718e3744 7745}
7746
7747#ifdef HAVE_IPV6
7748DEFUN (show_bgp_community_all,
7749 show_bgp_community_all_cmd,
7750 "show bgp community",
7751 SHOW_STR
7752 BGP_STR
7753 "Display routes matching the communities\n")
7754{
7755 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
47fc97cc 7756 bgp_show_type_community_all, NULL, NULL);
718e3744 7757}
7758
7759ALIAS (show_bgp_community_all,
7760 show_bgp_ipv6_community_all_cmd,
7761 "show bgp ipv6 community",
7762 SHOW_STR
7763 BGP_STR
7764 "Address family\n"
7765 "Display routes matching the communities\n")
7766
7767/* old command */
7768DEFUN (show_ipv6_bgp_community_all,
7769 show_ipv6_bgp_community_all_cmd,
7770 "show ipv6 bgp community",
7771 SHOW_STR
7772 IPV6_STR
7773 BGP_STR
7774 "Display routes matching the communities\n")
7775{
7776 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
47fc97cc 7777 bgp_show_type_community_all, NULL, NULL);
718e3744 7778}
7779
7780/* old command */
7781DEFUN (show_ipv6_mbgp_community_all,
7782 show_ipv6_mbgp_community_all_cmd,
7783 "show ipv6 mbgp community",
7784 SHOW_STR
7785 IPV6_STR
7786 MBGP_STR
7787 "Display routes matching the communities\n")
7788{
7789 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
47fc97cc 7790 bgp_show_type_community_all, NULL, NULL);
718e3744 7791}
7792#endif /* HAVE_IPV6 */
6b0655a2 7793
94f2b392 7794static int
95cbbd2a
ML
7795bgp_show_community (struct vty *vty, const char *view_name, int argc,
7796 const char **argv, int exact, afi_t afi, safi_t safi)
718e3744 7797{
7798 struct community *com;
7799 struct buffer *b;
95cbbd2a 7800 struct bgp *bgp;
718e3744 7801 int i;
7802 char *str;
7803 int first = 0;
7804
95cbbd2a
ML
7805 /* BGP structure lookup */
7806 if (view_name)
7807 {
7808 bgp = bgp_lookup_by_name (view_name);
7809 if (bgp == NULL)
7810 {
7811 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7812 return CMD_WARNING;
7813 }
7814 }
7815 else
7816 {
7817 bgp = bgp_get_default ();
7818 if (bgp == NULL)
7819 {
7820 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7821 return CMD_WARNING;
7822 }
7823 }
7824
718e3744 7825 b = buffer_new (1024);
7826 for (i = 0; i < argc; i++)
7827 {
7828 if (first)
7829 buffer_putc (b, ' ');
7830 else
7831 {
7832 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7833 continue;
7834 first = 1;
7835 }
7836
7837 buffer_putstr (b, argv[i]);
7838 }
7839 buffer_putc (b, '\0');
7840
7841 str = buffer_getstr (b);
7842 buffer_free (b);
7843
7844 com = community_str2com (str);
3b8b1855 7845 XFREE (MTYPE_TMP, str);
718e3744 7846 if (! com)
7847 {
7848 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7849 return CMD_WARNING;
7850 }
7851
95cbbd2a 7852 return bgp_show (vty, bgp, afi, safi,
5a646650 7853 (exact ? bgp_show_type_community_exact :
47fc97cc 7854 bgp_show_type_community), com, NULL);
718e3744 7855}
7856
7857DEFUN (show_ip_bgp_community,
7858 show_ip_bgp_community_cmd,
7859 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7860 SHOW_STR
7861 IP_STR
7862 BGP_STR
7863 "Display routes matching the communities\n"
7864 "community number\n"
7865 "Do not send outside local AS (well-known community)\n"
7866 "Do not advertise to any peer (well-known community)\n"
7867 "Do not export to next AS (well-known community)\n")
7868{
95cbbd2a 7869 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 7870}
7871
7872ALIAS (show_ip_bgp_community,
7873 show_ip_bgp_community2_cmd,
7874 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7875 SHOW_STR
7876 IP_STR
7877 BGP_STR
7878 "Display routes matching the communities\n"
7879 "community number\n"
7880 "Do not send outside local AS (well-known community)\n"
7881 "Do not advertise to any peer (well-known community)\n"
7882 "Do not export to next AS (well-known community)\n"
7883 "community number\n"
7884 "Do not send outside local AS (well-known community)\n"
7885 "Do not advertise to any peer (well-known community)\n"
7886 "Do not export to next AS (well-known community)\n")
7887
7888ALIAS (show_ip_bgp_community,
7889 show_ip_bgp_community3_cmd,
7890 "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)",
7891 SHOW_STR
7892 IP_STR
7893 BGP_STR
7894 "Display routes matching the communities\n"
7895 "community number\n"
7896 "Do not send outside local AS (well-known community)\n"
7897 "Do not advertise to any peer (well-known community)\n"
7898 "Do not export to next AS (well-known community)\n"
7899 "community number\n"
7900 "Do not send outside local AS (well-known community)\n"
7901 "Do not advertise to any peer (well-known community)\n"
7902 "Do not export to next AS (well-known community)\n"
7903 "community number\n"
7904 "Do not send outside local AS (well-known community)\n"
7905 "Do not advertise to any peer (well-known community)\n"
7906 "Do not export to next AS (well-known community)\n")
7907
7908ALIAS (show_ip_bgp_community,
7909 show_ip_bgp_community4_cmd,
7910 "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)",
7911 SHOW_STR
7912 IP_STR
7913 BGP_STR
7914 "Display routes matching the communities\n"
7915 "community number\n"
7916 "Do not send outside local AS (well-known community)\n"
7917 "Do not advertise to any peer (well-known community)\n"
7918 "Do not export to next AS (well-known community)\n"
7919 "community number\n"
7920 "Do not send outside local AS (well-known community)\n"
7921 "Do not advertise to any peer (well-known community)\n"
7922 "Do not export to next AS (well-known community)\n"
7923 "community number\n"
7924 "Do not send outside local AS (well-known community)\n"
7925 "Do not advertise to any peer (well-known community)\n"
7926 "Do not export to next AS (well-known community)\n"
7927 "community number\n"
7928 "Do not send outside local AS (well-known community)\n"
7929 "Do not advertise to any peer (well-known community)\n"
7930 "Do not export to next AS (well-known community)\n")
7931
7932DEFUN (show_ip_bgp_ipv4_community,
7933 show_ip_bgp_ipv4_community_cmd,
7934 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7935 SHOW_STR
7936 IP_STR
7937 BGP_STR
7938 "Address family\n"
7939 "Address Family modifier\n"
7940 "Address Family modifier\n"
7941 "Display routes matching the communities\n"
7942 "community number\n"
7943 "Do not send outside local AS (well-known community)\n"
7944 "Do not advertise to any peer (well-known community)\n"
7945 "Do not export to next AS (well-known community)\n")
7946{
7947 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 7948 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
718e3744 7949
95cbbd2a 7950 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 7951}
7952
7953ALIAS (show_ip_bgp_ipv4_community,
7954 show_ip_bgp_ipv4_community2_cmd,
7955 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7956 SHOW_STR
7957 IP_STR
7958 BGP_STR
7959 "Address family\n"
7960 "Address Family modifier\n"
7961 "Address Family modifier\n"
7962 "Display routes matching the communities\n"
7963 "community number\n"
7964 "Do not send outside local AS (well-known community)\n"
7965 "Do not advertise to any peer (well-known community)\n"
7966 "Do not export to next AS (well-known community)\n"
7967 "community number\n"
7968 "Do not send outside local AS (well-known community)\n"
7969 "Do not advertise to any peer (well-known community)\n"
7970 "Do not export to next AS (well-known community)\n")
7971
7972ALIAS (show_ip_bgp_ipv4_community,
7973 show_ip_bgp_ipv4_community3_cmd,
7974 "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)",
7975 SHOW_STR
7976 IP_STR
7977 BGP_STR
7978 "Address family\n"
7979 "Address Family modifier\n"
7980 "Address Family modifier\n"
7981 "Display routes matching the communities\n"
7982 "community number\n"
7983 "Do not send outside local AS (well-known community)\n"
7984 "Do not advertise to any peer (well-known community)\n"
7985 "Do not export to next AS (well-known community)\n"
7986 "community number\n"
7987 "Do not send outside local AS (well-known community)\n"
7988 "Do not advertise to any peer (well-known community)\n"
7989 "Do not export to next AS (well-known community)\n"
7990 "community number\n"
7991 "Do not send outside local AS (well-known community)\n"
7992 "Do not advertise to any peer (well-known community)\n"
7993 "Do not export to next AS (well-known community)\n")
7994
7995ALIAS (show_ip_bgp_ipv4_community,
7996 show_ip_bgp_ipv4_community4_cmd,
7997 "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)",
7998 SHOW_STR
7999 IP_STR
8000 BGP_STR
8001 "Address family\n"
8002 "Address Family modifier\n"
8003 "Address Family modifier\n"
8004 "Display routes matching the communities\n"
8005 "community number\n"
8006 "Do not send outside local AS (well-known community)\n"
8007 "Do not advertise to any peer (well-known community)\n"
8008 "Do not export to next AS (well-known community)\n"
8009 "community number\n"
8010 "Do not send outside local AS (well-known community)\n"
8011 "Do not advertise to any peer (well-known community)\n"
8012 "Do not export to next AS (well-known community)\n"
8013 "community number\n"
8014 "Do not send outside local AS (well-known community)\n"
8015 "Do not advertise to any peer (well-known community)\n"
8016 "Do not export to next AS (well-known community)\n"
8017 "community number\n"
8018 "Do not send outside local AS (well-known community)\n"
8019 "Do not advertise to any peer (well-known community)\n"
8020 "Do not export to next AS (well-known community)\n")
8021
95cbbd2a
ML
8022DEFUN (show_bgp_view_afi_safi_community_all,
8023 show_bgp_view_afi_safi_community_all_cmd,
8024#ifdef HAVE_IPV6
8025 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
8026#else
8027 "show bgp view WORD ipv4 (unicast|multicast) community",
8028#endif
8029 SHOW_STR
8030 BGP_STR
8031 "BGP view\n"
2b00515a 8032 "View name\n"
95cbbd2a
ML
8033 "Address family\n"
8034#ifdef HAVE_IPV6
8035 "Address family\n"
8036#endif
8037 "Address Family modifier\n"
8038 "Address Family modifier\n"
2b00515a 8039 "Display routes matching the communities\n")
95cbbd2a
ML
8040{
8041 int afi;
8042 int safi;
8043 struct bgp *bgp;
8044
8045 /* BGP structure lookup. */
8046 bgp = bgp_lookup_by_name (argv[0]);
8047 if (bgp == NULL)
8048 {
8049 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8050 return CMD_WARNING;
8051 }
8052
8053#ifdef HAVE_IPV6
8054 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8055 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8056#else
8057 afi = AFI_IP;
8058 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8059#endif
47fc97cc 8060 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, NULL);
95cbbd2a
ML
8061}
8062
8063DEFUN (show_bgp_view_afi_safi_community,
8064 show_bgp_view_afi_safi_community_cmd,
8065#ifdef HAVE_IPV6
8066 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
8067#else
8068 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
8069#endif
8070 SHOW_STR
8071 BGP_STR
8072 "BGP view\n"
2b00515a 8073 "View name\n"
95cbbd2a
ML
8074 "Address family\n"
8075#ifdef HAVE_IPV6
8076 "Address family\n"
8077#endif
8078 "Address family modifier\n"
8079 "Address family modifier\n"
8080 "Display routes matching the communities\n"
8081 "community number\n"
8082 "Do not send outside local AS (well-known community)\n"
8083 "Do not advertise to any peer (well-known community)\n"
8084 "Do not export to next AS (well-known community)\n")
8085{
8086 int afi;
8087 int safi;
8088
8089#ifdef HAVE_IPV6
8090 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8091 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8092 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
8093#else
8094 afi = AFI_IP;
8095 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8096 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
8097#endif
8098}
8099
8100ALIAS (show_bgp_view_afi_safi_community,
8101 show_bgp_view_afi_safi_community2_cmd,
8102#ifdef HAVE_IPV6
8103 "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)",
8104#else
8105 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8106#endif
8107 SHOW_STR
8108 BGP_STR
8109 "BGP view\n"
2b00515a 8110 "View name\n"
95cbbd2a
ML
8111 "Address family\n"
8112#ifdef HAVE_IPV6
8113 "Address family\n"
8114#endif
8115 "Address family modifier\n"
8116 "Address family modifier\n"
8117 "Display routes matching the communities\n"
8118 "community number\n"
8119 "Do not send outside local AS (well-known community)\n"
8120 "Do not advertise to any peer (well-known community)\n"
8121 "Do not export to next AS (well-known community)\n"
8122 "community number\n"
8123 "Do not send outside local AS (well-known community)\n"
8124 "Do not advertise to any peer (well-known community)\n"
8125 "Do not export to next AS (well-known community)\n")
8126
8127ALIAS (show_bgp_view_afi_safi_community,
8128 show_bgp_view_afi_safi_community3_cmd,
8129#ifdef HAVE_IPV6
8130 "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)",
8131#else
8132 "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)",
8133#endif
8134 SHOW_STR
8135 BGP_STR
8136 "BGP view\n"
2b00515a 8137 "View name\n"
95cbbd2a
ML
8138 "Address family\n"
8139#ifdef HAVE_IPV6
8140 "Address family\n"
8141#endif
8142 "Address family modifier\n"
8143 "Address family modifier\n"
8144 "Display routes matching the communities\n"
8145 "community number\n"
8146 "Do not send outside local AS (well-known community)\n"
8147 "Do not advertise to any peer (well-known community)\n"
8148 "Do not export to next AS (well-known community)\n"
8149 "community number\n"
8150 "Do not send outside local AS (well-known community)\n"
8151 "Do not advertise to any peer (well-known community)\n"
8152 "Do not export to next AS (well-known community)\n"
8153 "community number\n"
8154 "Do not send outside local AS (well-known community)\n"
8155 "Do not advertise to any peer (well-known community)\n"
8156 "Do not export to next AS (well-known community)\n")
8157
8158ALIAS (show_bgp_view_afi_safi_community,
8159 show_bgp_view_afi_safi_community4_cmd,
8160#ifdef HAVE_IPV6
8161 "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)",
8162#else
8163 "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)",
8164#endif
8165 SHOW_STR
8166 BGP_STR
8167 "BGP view\n"
2b00515a 8168 "View name\n"
95cbbd2a
ML
8169 "Address family\n"
8170#ifdef HAVE_IPV6
8171 "Address family\n"
8172#endif
8173 "Address family modifier\n"
8174 "Address family modifier\n"
8175 "Display routes matching the communities\n"
8176 "community number\n"
8177 "Do not send outside local AS (well-known community)\n"
8178 "Do not advertise to any peer (well-known community)\n"
8179 "Do not export to next AS (well-known community)\n"
8180 "community number\n"
8181 "Do not send outside local AS (well-known community)\n"
8182 "Do not advertise to any peer (well-known community)\n"
8183 "Do not export to next AS (well-known community)\n"
8184 "community number\n"
8185 "Do not send outside local AS (well-known community)\n"
8186 "Do not advertise to any peer (well-known community)\n"
8187 "Do not export to next AS (well-known community)\n"
8188 "community number\n"
8189 "Do not send outside local AS (well-known community)\n"
8190 "Do not advertise to any peer (well-known community)\n"
8191 "Do not export to next AS (well-known community)\n")
8192
718e3744 8193DEFUN (show_ip_bgp_community_exact,
8194 show_ip_bgp_community_exact_cmd,
8195 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8196 SHOW_STR
8197 IP_STR
8198 BGP_STR
8199 "Display routes matching the communities\n"
8200 "community number\n"
8201 "Do not send outside local AS (well-known community)\n"
8202 "Do not advertise to any peer (well-known community)\n"
8203 "Do not export to next AS (well-known community)\n"
8204 "Exact match of the communities")
8205{
95cbbd2a 8206 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 8207}
8208
8209ALIAS (show_ip_bgp_community_exact,
8210 show_ip_bgp_community2_exact_cmd,
8211 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8212 SHOW_STR
8213 IP_STR
8214 BGP_STR
8215 "Display routes matching the communities\n"
8216 "community number\n"
8217 "Do not send outside local AS (well-known community)\n"
8218 "Do not advertise to any peer (well-known community)\n"
8219 "Do not export to next AS (well-known community)\n"
8220 "community number\n"
8221 "Do not send outside local AS (well-known community)\n"
8222 "Do not advertise to any peer (well-known community)\n"
8223 "Do not export to next AS (well-known community)\n"
8224 "Exact match of the communities")
8225
8226ALIAS (show_ip_bgp_community_exact,
8227 show_ip_bgp_community3_exact_cmd,
8228 "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",
8229 SHOW_STR
8230 IP_STR
8231 BGP_STR
8232 "Display routes matching the communities\n"
8233 "community number\n"
8234 "Do not send outside local AS (well-known community)\n"
8235 "Do not advertise to any peer (well-known community)\n"
8236 "Do not export to next AS (well-known community)\n"
8237 "community number\n"
8238 "Do not send outside local AS (well-known community)\n"
8239 "Do not advertise to any peer (well-known community)\n"
8240 "Do not export to next AS (well-known community)\n"
8241 "community number\n"
8242 "Do not send outside local AS (well-known community)\n"
8243 "Do not advertise to any peer (well-known community)\n"
8244 "Do not export to next AS (well-known community)\n"
8245 "Exact match of the communities")
8246
8247ALIAS (show_ip_bgp_community_exact,
8248 show_ip_bgp_community4_exact_cmd,
8249 "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",
8250 SHOW_STR
8251 IP_STR
8252 BGP_STR
8253 "Display routes matching the communities\n"
8254 "community number\n"
8255 "Do not send outside local AS (well-known community)\n"
8256 "Do not advertise to any peer (well-known community)\n"
8257 "Do not export to next AS (well-known community)\n"
8258 "community number\n"
8259 "Do not send outside local AS (well-known community)\n"
8260 "Do not advertise to any peer (well-known community)\n"
8261 "Do not export to next AS (well-known community)\n"
8262 "community number\n"
8263 "Do not send outside local AS (well-known community)\n"
8264 "Do not advertise to any peer (well-known community)\n"
8265 "Do not export to next AS (well-known community)\n"
8266 "community number\n"
8267 "Do not send outside local AS (well-known community)\n"
8268 "Do not advertise to any peer (well-known community)\n"
8269 "Do not export to next AS (well-known community)\n"
8270 "Exact match of the communities")
8271
8272DEFUN (show_ip_bgp_ipv4_community_exact,
8273 show_ip_bgp_ipv4_community_exact_cmd,
8274 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8275 SHOW_STR
8276 IP_STR
8277 BGP_STR
8278 "Address family\n"
8279 "Address Family modifier\n"
8280 "Address Family modifier\n"
8281 "Display routes matching the communities\n"
8282 "community number\n"
8283 "Do not send outside local AS (well-known community)\n"
8284 "Do not advertise to any peer (well-known community)\n"
8285 "Do not export to next AS (well-known community)\n"
8286 "Exact match of the communities")
8287{
8288 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 8289 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
718e3744 8290
95cbbd2a 8291 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 8292}
8293
8294ALIAS (show_ip_bgp_ipv4_community_exact,
8295 show_ip_bgp_ipv4_community2_exact_cmd,
8296 "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",
8297 SHOW_STR
8298 IP_STR
8299 BGP_STR
8300 "Address family\n"
8301 "Address Family modifier\n"
8302 "Address Family modifier\n"
8303 "Display routes matching the communities\n"
8304 "community number\n"
8305 "Do not send outside local AS (well-known community)\n"
8306 "Do not advertise to any peer (well-known community)\n"
8307 "Do not export to next AS (well-known community)\n"
8308 "community number\n"
8309 "Do not send outside local AS (well-known community)\n"
8310 "Do not advertise to any peer (well-known community)\n"
8311 "Do not export to next AS (well-known community)\n"
8312 "Exact match of the communities")
8313
8314ALIAS (show_ip_bgp_ipv4_community_exact,
8315 show_ip_bgp_ipv4_community3_exact_cmd,
8316 "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",
8317 SHOW_STR
8318 IP_STR
8319 BGP_STR
8320 "Address family\n"
8321 "Address Family modifier\n"
8322 "Address Family modifier\n"
8323 "Display routes matching the communities\n"
8324 "community number\n"
8325 "Do not send outside local AS (well-known community)\n"
8326 "Do not advertise to any peer (well-known community)\n"
8327 "Do not export to next AS (well-known community)\n"
8328 "community number\n"
8329 "Do not send outside local AS (well-known community)\n"
8330 "Do not advertise to any peer (well-known community)\n"
8331 "Do not export to next AS (well-known community)\n"
8332 "community number\n"
8333 "Do not send outside local AS (well-known community)\n"
8334 "Do not advertise to any peer (well-known community)\n"
8335 "Do not export to next AS (well-known community)\n"
8336 "Exact match of the communities")
8337
8338ALIAS (show_ip_bgp_ipv4_community_exact,
8339 show_ip_bgp_ipv4_community4_exact_cmd,
8340 "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",
8341 SHOW_STR
8342 IP_STR
8343 BGP_STR
8344 "Address family\n"
8345 "Address Family modifier\n"
8346 "Address Family modifier\n"
8347 "Display routes matching the communities\n"
8348 "community number\n"
8349 "Do not send outside local AS (well-known community)\n"
8350 "Do not advertise to any peer (well-known community)\n"
8351 "Do not export to next AS (well-known community)\n"
8352 "community number\n"
8353 "Do not send outside local AS (well-known community)\n"
8354 "Do not advertise to any peer (well-known community)\n"
8355 "Do not export to next AS (well-known community)\n"
8356 "community number\n"
8357 "Do not send outside local AS (well-known community)\n"
8358 "Do not advertise to any peer (well-known community)\n"
8359 "Do not export to next AS (well-known community)\n"
8360 "community number\n"
8361 "Do not send outside local AS (well-known community)\n"
8362 "Do not advertise to any peer (well-known community)\n"
8363 "Do not export to next AS (well-known community)\n"
8364 "Exact match of the communities")
8365
8366#ifdef HAVE_IPV6
8367DEFUN (show_bgp_community,
8368 show_bgp_community_cmd,
8369 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8370 SHOW_STR
8371 BGP_STR
8372 "Display routes matching the communities\n"
8373 "community number\n"
8374 "Do not send outside local AS (well-known community)\n"
8375 "Do not advertise to any peer (well-known community)\n"
8376 "Do not export to next AS (well-known community)\n")
8377{
95cbbd2a 8378 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 8379}
8380
8381ALIAS (show_bgp_community,
8382 show_bgp_ipv6_community_cmd,
8383 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8384 SHOW_STR
8385 BGP_STR
8386 "Address family\n"
8387 "Display routes matching the communities\n"
8388 "community number\n"
8389 "Do not send outside local AS (well-known community)\n"
8390 "Do not advertise to any peer (well-known community)\n"
8391 "Do not export to next AS (well-known community)\n")
8392
8393ALIAS (show_bgp_community,
8394 show_bgp_community2_cmd,
8395 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8396 SHOW_STR
8397 BGP_STR
8398 "Display routes matching the communities\n"
8399 "community number\n"
8400 "Do not send outside local AS (well-known community)\n"
8401 "Do not advertise to any peer (well-known community)\n"
8402 "Do not export to next AS (well-known community)\n"
8403 "community number\n"
8404 "Do not send outside local AS (well-known community)\n"
8405 "Do not advertise to any peer (well-known community)\n"
8406 "Do not export to next AS (well-known community)\n")
8407
8408ALIAS (show_bgp_community,
8409 show_bgp_ipv6_community2_cmd,
8410 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8411 SHOW_STR
8412 BGP_STR
8413 "Address family\n"
8414 "Display routes matching the communities\n"
8415 "community number\n"
8416 "Do not send outside local AS (well-known community)\n"
8417 "Do not advertise to any peer (well-known community)\n"
8418 "Do not export to next AS (well-known community)\n"
8419 "community number\n"
8420 "Do not send outside local AS (well-known community)\n"
8421 "Do not advertise to any peer (well-known community)\n"
8422 "Do not export to next AS (well-known community)\n")
8423
8424ALIAS (show_bgp_community,
8425 show_bgp_community3_cmd,
8426 "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)",
8427 SHOW_STR
8428 BGP_STR
8429 "Display routes matching the communities\n"
8430 "community number\n"
8431 "Do not send outside local AS (well-known community)\n"
8432 "Do not advertise to any peer (well-known community)\n"
8433 "Do not export to next AS (well-known community)\n"
8434 "community number\n"
8435 "Do not send outside local AS (well-known community)\n"
8436 "Do not advertise to any peer (well-known community)\n"
8437 "Do not export to next AS (well-known community)\n"
8438 "community number\n"
8439 "Do not send outside local AS (well-known community)\n"
8440 "Do not advertise to any peer (well-known community)\n"
8441 "Do not export to next AS (well-known community)\n")
8442
8443ALIAS (show_bgp_community,
8444 show_bgp_ipv6_community3_cmd,
8445 "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)",
8446 SHOW_STR
8447 BGP_STR
8448 "Address family\n"
8449 "Display routes matching the communities\n"
8450 "community number\n"
8451 "Do not send outside local AS (well-known community)\n"
8452 "Do not advertise to any peer (well-known community)\n"
8453 "Do not export to next AS (well-known community)\n"
8454 "community number\n"
8455 "Do not send outside local AS (well-known community)\n"
8456 "Do not advertise to any peer (well-known community)\n"
8457 "Do not export to next AS (well-known community)\n"
8458 "community number\n"
8459 "Do not send outside local AS (well-known community)\n"
8460 "Do not advertise to any peer (well-known community)\n"
8461 "Do not export to next AS (well-known community)\n")
8462
8463ALIAS (show_bgp_community,
8464 show_bgp_community4_cmd,
8465 "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)",
8466 SHOW_STR
8467 BGP_STR
8468 "Display routes matching the communities\n"
8469 "community number\n"
8470 "Do not send outside local AS (well-known community)\n"
8471 "Do not advertise to any peer (well-known community)\n"
8472 "Do not export to next AS (well-known community)\n"
8473 "community number\n"
8474 "Do not send outside local AS (well-known community)\n"
8475 "Do not advertise to any peer (well-known community)\n"
8476 "Do not export to next AS (well-known community)\n"
8477 "community number\n"
8478 "Do not send outside local AS (well-known community)\n"
8479 "Do not advertise to any peer (well-known community)\n"
8480 "Do not export to next AS (well-known community)\n"
8481 "community number\n"
8482 "Do not send outside local AS (well-known community)\n"
8483 "Do not advertise to any peer (well-known community)\n"
8484 "Do not export to next AS (well-known community)\n")
8485
8486ALIAS (show_bgp_community,
8487 show_bgp_ipv6_community4_cmd,
8488 "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)",
8489 SHOW_STR
8490 BGP_STR
8491 "Address family\n"
8492 "Display routes matching the communities\n"
8493 "community number\n"
8494 "Do not send outside local AS (well-known community)\n"
8495 "Do not advertise to any peer (well-known community)\n"
8496 "Do not export to next AS (well-known community)\n"
8497 "community number\n"
8498 "Do not send outside local AS (well-known community)\n"
8499 "Do not advertise to any peer (well-known community)\n"
8500 "Do not export to next AS (well-known community)\n"
8501 "community number\n"
8502 "Do not send outside local AS (well-known community)\n"
8503 "Do not advertise to any peer (well-known community)\n"
8504 "Do not export to next AS (well-known community)\n"
8505 "community number\n"
8506 "Do not send outside local AS (well-known community)\n"
8507 "Do not advertise to any peer (well-known community)\n"
8508 "Do not export to next AS (well-known community)\n")
8509
8510/* old command */
8511DEFUN (show_ipv6_bgp_community,
8512 show_ipv6_bgp_community_cmd,
8513 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8514 SHOW_STR
8515 IPV6_STR
8516 BGP_STR
8517 "Display routes matching the communities\n"
8518 "community number\n"
8519 "Do not send outside local AS (well-known community)\n"
8520 "Do not advertise to any peer (well-known community)\n"
8521 "Do not export to next AS (well-known community)\n")
8522{
95cbbd2a 8523 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 8524}
8525
8526/* old command */
8527ALIAS (show_ipv6_bgp_community,
8528 show_ipv6_bgp_community2_cmd,
8529 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8530 SHOW_STR
8531 IPV6_STR
8532 BGP_STR
8533 "Display routes matching the communities\n"
8534 "community number\n"
8535 "Do not send outside local AS (well-known community)\n"
8536 "Do not advertise to any peer (well-known community)\n"
8537 "Do not export to next AS (well-known community)\n"
8538 "community number\n"
8539 "Do not send outside local AS (well-known community)\n"
8540 "Do not advertise to any peer (well-known community)\n"
8541 "Do not export to next AS (well-known community)\n")
8542
8543/* old command */
8544ALIAS (show_ipv6_bgp_community,
8545 show_ipv6_bgp_community3_cmd,
8546 "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)",
8547 SHOW_STR
8548 IPV6_STR
8549 BGP_STR
8550 "Display routes matching the communities\n"
8551 "community number\n"
8552 "Do not send outside local AS (well-known community)\n"
8553 "Do not advertise to any peer (well-known community)\n"
8554 "Do not export to next AS (well-known community)\n"
8555 "community number\n"
8556 "Do not send outside local AS (well-known community)\n"
8557 "Do not advertise to any peer (well-known community)\n"
8558 "Do not export to next AS (well-known community)\n"
8559 "community number\n"
8560 "Do not send outside local AS (well-known community)\n"
8561 "Do not advertise to any peer (well-known community)\n"
8562 "Do not export to next AS (well-known community)\n")
8563
8564/* old command */
8565ALIAS (show_ipv6_bgp_community,
8566 show_ipv6_bgp_community4_cmd,
8567 "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)",
8568 SHOW_STR
8569 IPV6_STR
8570 BGP_STR
8571 "Display routes matching the communities\n"
8572 "community number\n"
8573 "Do not send outside local AS (well-known community)\n"
8574 "Do not advertise to any peer (well-known community)\n"
8575 "Do not export to next AS (well-known community)\n"
8576 "community number\n"
8577 "Do not send outside local AS (well-known community)\n"
8578 "Do not advertise to any peer (well-known community)\n"
8579 "Do not export to next AS (well-known community)\n"
8580 "community number\n"
8581 "Do not send outside local AS (well-known community)\n"
8582 "Do not advertise to any peer (well-known community)\n"
8583 "Do not export to next AS (well-known community)\n"
8584 "community number\n"
8585 "Do not send outside local AS (well-known community)\n"
8586 "Do not advertise to any peer (well-known community)\n"
8587 "Do not export to next AS (well-known community)\n")
8588
8589DEFUN (show_bgp_community_exact,
8590 show_bgp_community_exact_cmd,
8591 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8592 SHOW_STR
8593 BGP_STR
8594 "Display routes matching the communities\n"
8595 "community number\n"
8596 "Do not send outside local AS (well-known community)\n"
8597 "Do not advertise to any peer (well-known community)\n"
8598 "Do not export to next AS (well-known community)\n"
8599 "Exact match of the communities")
8600{
95cbbd2a 8601 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 8602}
8603
8604ALIAS (show_bgp_community_exact,
8605 show_bgp_ipv6_community_exact_cmd,
8606 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8607 SHOW_STR
8608 BGP_STR
8609 "Address family\n"
8610 "Display routes matching the communities\n"
8611 "community number\n"
8612 "Do not send outside local AS (well-known community)\n"
8613 "Do not advertise to any peer (well-known community)\n"
8614 "Do not export to next AS (well-known community)\n"
8615 "Exact match of the communities")
8616
8617ALIAS (show_bgp_community_exact,
8618 show_bgp_community2_exact_cmd,
8619 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8620 SHOW_STR
8621 BGP_STR
8622 "Display routes matching the communities\n"
8623 "community number\n"
8624 "Do not send outside local AS (well-known community)\n"
8625 "Do not advertise to any peer (well-known community)\n"
8626 "Do not export to next AS (well-known community)\n"
8627 "community number\n"
8628 "Do not send outside local AS (well-known community)\n"
8629 "Do not advertise to any peer (well-known community)\n"
8630 "Do not export to next AS (well-known community)\n"
8631 "Exact match of the communities")
8632
8633ALIAS (show_bgp_community_exact,
8634 show_bgp_ipv6_community2_exact_cmd,
8635 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8636 SHOW_STR
8637 BGP_STR
8638 "Address family\n"
8639 "Display routes matching the communities\n"
8640 "community number\n"
8641 "Do not send outside local AS (well-known community)\n"
8642 "Do not advertise to any peer (well-known community)\n"
8643 "Do not export to next AS (well-known community)\n"
8644 "community number\n"
8645 "Do not send outside local AS (well-known community)\n"
8646 "Do not advertise to any peer (well-known community)\n"
8647 "Do not export to next AS (well-known community)\n"
8648 "Exact match of the communities")
8649
8650ALIAS (show_bgp_community_exact,
8651 show_bgp_community3_exact_cmd,
8652 "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",
8653 SHOW_STR
8654 BGP_STR
8655 "Display routes matching the communities\n"
8656 "community number\n"
8657 "Do not send outside local AS (well-known community)\n"
8658 "Do not advertise to any peer (well-known community)\n"
8659 "Do not export to next AS (well-known community)\n"
8660 "community number\n"
8661 "Do not send outside local AS (well-known community)\n"
8662 "Do not advertise to any peer (well-known community)\n"
8663 "Do not export to next AS (well-known community)\n"
8664 "community number\n"
8665 "Do not send outside local AS (well-known community)\n"
8666 "Do not advertise to any peer (well-known community)\n"
8667 "Do not export to next AS (well-known community)\n"
8668 "Exact match of the communities")
8669
8670ALIAS (show_bgp_community_exact,
8671 show_bgp_ipv6_community3_exact_cmd,
8672 "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",
8673 SHOW_STR
8674 BGP_STR
8675 "Address family\n"
8676 "Display routes matching the communities\n"
8677 "community number\n"
8678 "Do not send outside local AS (well-known community)\n"
8679 "Do not advertise to any peer (well-known community)\n"
8680 "Do not export to next AS (well-known community)\n"
8681 "community number\n"
8682 "Do not send outside local AS (well-known community)\n"
8683 "Do not advertise to any peer (well-known community)\n"
8684 "Do not export to next AS (well-known community)\n"
8685 "community number\n"
8686 "Do not send outside local AS (well-known community)\n"
8687 "Do not advertise to any peer (well-known community)\n"
8688 "Do not export to next AS (well-known community)\n"
8689 "Exact match of the communities")
8690
8691ALIAS (show_bgp_community_exact,
8692 show_bgp_community4_exact_cmd,
8693 "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",
8694 SHOW_STR
8695 BGP_STR
8696 "Display routes matching the communities\n"
8697 "community number\n"
8698 "Do not send outside local AS (well-known community)\n"
8699 "Do not advertise to any peer (well-known community)\n"
8700 "Do not export to next AS (well-known community)\n"
8701 "community number\n"
8702 "Do not send outside local AS (well-known community)\n"
8703 "Do not advertise to any peer (well-known community)\n"
8704 "Do not export to next AS (well-known community)\n"
8705 "community number\n"
8706 "Do not send outside local AS (well-known community)\n"
8707 "Do not advertise to any peer (well-known community)\n"
8708 "Do not export to next AS (well-known community)\n"
8709 "community number\n"
8710 "Do not send outside local AS (well-known community)\n"
8711 "Do not advertise to any peer (well-known community)\n"
8712 "Do not export to next AS (well-known community)\n"
8713 "Exact match of the communities")
8714
8715ALIAS (show_bgp_community_exact,
8716 show_bgp_ipv6_community4_exact_cmd,
8717 "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",
8718 SHOW_STR
8719 BGP_STR
8720 "Address family\n"
8721 "Display routes matching the communities\n"
8722 "community number\n"
8723 "Do not send outside local AS (well-known community)\n"
8724 "Do not advertise to any peer (well-known community)\n"
8725 "Do not export to next AS (well-known community)\n"
8726 "community number\n"
8727 "Do not send outside local AS (well-known community)\n"
8728 "Do not advertise to any peer (well-known community)\n"
8729 "Do not export to next AS (well-known community)\n"
8730 "community number\n"
8731 "Do not send outside local AS (well-known community)\n"
8732 "Do not advertise to any peer (well-known community)\n"
8733 "Do not export to next AS (well-known community)\n"
8734 "community number\n"
8735 "Do not send outside local AS (well-known community)\n"
8736 "Do not advertise to any peer (well-known community)\n"
8737 "Do not export to next AS (well-known community)\n"
8738 "Exact match of the communities")
8739
8740/* old command */
8741DEFUN (show_ipv6_bgp_community_exact,
8742 show_ipv6_bgp_community_exact_cmd,
8743 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8744 SHOW_STR
8745 IPV6_STR
8746 BGP_STR
8747 "Display routes matching the communities\n"
8748 "community number\n"
8749 "Do not send outside local AS (well-known community)\n"
8750 "Do not advertise to any peer (well-known community)\n"
8751 "Do not export to next AS (well-known community)\n"
8752 "Exact match of the communities")
8753{
95cbbd2a 8754 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 8755}
8756
8757/* old command */
8758ALIAS (show_ipv6_bgp_community_exact,
8759 show_ipv6_bgp_community2_exact_cmd,
8760 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8761 SHOW_STR
8762 IPV6_STR
8763 BGP_STR
8764 "Display routes matching the communities\n"
8765 "community number\n"
8766 "Do not send outside local AS (well-known community)\n"
8767 "Do not advertise to any peer (well-known community)\n"
8768 "Do not export to next AS (well-known community)\n"
8769 "community number\n"
8770 "Do not send outside local AS (well-known community)\n"
8771 "Do not advertise to any peer (well-known community)\n"
8772 "Do not export to next AS (well-known community)\n"
8773 "Exact match of the communities")
8774
8775/* old command */
8776ALIAS (show_ipv6_bgp_community_exact,
8777 show_ipv6_bgp_community3_exact_cmd,
8778 "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",
8779 SHOW_STR
8780 IPV6_STR
8781 BGP_STR
8782 "Display routes matching the communities\n"
8783 "community number\n"
8784 "Do not send outside local AS (well-known community)\n"
8785 "Do not advertise to any peer (well-known community)\n"
8786 "Do not export to next AS (well-known community)\n"
8787 "community number\n"
8788 "Do not send outside local AS (well-known community)\n"
8789 "Do not advertise to any peer (well-known community)\n"
8790 "Do not export to next AS (well-known community)\n"
8791 "community number\n"
8792 "Do not send outside local AS (well-known community)\n"
8793 "Do not advertise to any peer (well-known community)\n"
8794 "Do not export to next AS (well-known community)\n"
8795 "Exact match of the communities")
8796
8797/* old command */
8798ALIAS (show_ipv6_bgp_community_exact,
8799 show_ipv6_bgp_community4_exact_cmd,
8800 "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",
8801 SHOW_STR
8802 IPV6_STR
8803 BGP_STR
8804 "Display routes matching the communities\n"
8805 "community number\n"
8806 "Do not send outside local AS (well-known community)\n"
8807 "Do not advertise to any peer (well-known community)\n"
8808 "Do not export to next AS (well-known community)\n"
8809 "community number\n"
8810 "Do not send outside local AS (well-known community)\n"
8811 "Do not advertise to any peer (well-known community)\n"
8812 "Do not export to next AS (well-known community)\n"
8813 "community number\n"
8814 "Do not send outside local AS (well-known community)\n"
8815 "Do not advertise to any peer (well-known community)\n"
8816 "Do not export to next AS (well-known community)\n"
8817 "community number\n"
8818 "Do not send outside local AS (well-known community)\n"
8819 "Do not advertise to any peer (well-known community)\n"
8820 "Do not export to next AS (well-known community)\n"
8821 "Exact match of the communities")
8822
8823/* old command */
8824DEFUN (show_ipv6_mbgp_community,
8825 show_ipv6_mbgp_community_cmd,
8826 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8827 SHOW_STR
8828 IPV6_STR
8829 MBGP_STR
8830 "Display routes matching the communities\n"
8831 "community number\n"
8832 "Do not send outside local AS (well-known community)\n"
8833 "Do not advertise to any peer (well-known community)\n"
8834 "Do not export to next AS (well-known community)\n")
8835{
95cbbd2a 8836 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
718e3744 8837}
8838
8839/* old command */
8840ALIAS (show_ipv6_mbgp_community,
8841 show_ipv6_mbgp_community2_cmd,
8842 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8843 SHOW_STR
8844 IPV6_STR
8845 MBGP_STR
8846 "Display routes matching the communities\n"
8847 "community number\n"
8848 "Do not send outside local AS (well-known community)\n"
8849 "Do not advertise to any peer (well-known community)\n"
8850 "Do not export to next AS (well-known community)\n"
8851 "community number\n"
8852 "Do not send outside local AS (well-known community)\n"
8853 "Do not advertise to any peer (well-known community)\n"
8854 "Do not export to next AS (well-known community)\n")
8855
8856/* old command */
8857ALIAS (show_ipv6_mbgp_community,
8858 show_ipv6_mbgp_community3_cmd,
8859 "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)",
8860 SHOW_STR
8861 IPV6_STR
8862 MBGP_STR
8863 "Display routes matching the communities\n"
8864 "community number\n"
8865 "Do not send outside local AS (well-known community)\n"
8866 "Do not advertise to any peer (well-known community)\n"
8867 "Do not export to next AS (well-known community)\n"
8868 "community number\n"
8869 "Do not send outside local AS (well-known community)\n"
8870 "Do not advertise to any peer (well-known community)\n"
8871 "Do not export to next AS (well-known community)\n"
8872 "community number\n"
8873 "Do not send outside local AS (well-known community)\n"
8874 "Do not advertise to any peer (well-known community)\n"
8875 "Do not export to next AS (well-known community)\n")
8876
8877/* old command */
8878ALIAS (show_ipv6_mbgp_community,
8879 show_ipv6_mbgp_community4_cmd,
8880 "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)",
8881 SHOW_STR
8882 IPV6_STR
8883 MBGP_STR
8884 "Display routes matching the communities\n"
8885 "community number\n"
8886 "Do not send outside local AS (well-known community)\n"
8887 "Do not advertise to any peer (well-known community)\n"
8888 "Do not export to next AS (well-known community)\n"
8889 "community number\n"
8890 "Do not send outside local AS (well-known community)\n"
8891 "Do not advertise to any peer (well-known community)\n"
8892 "Do not export to next AS (well-known community)\n"
8893 "community number\n"
8894 "Do not send outside local AS (well-known community)\n"
8895 "Do not advertise to any peer (well-known community)\n"
8896 "Do not export to next AS (well-known community)\n"
8897 "community number\n"
8898 "Do not send outside local AS (well-known community)\n"
8899 "Do not advertise to any peer (well-known community)\n"
8900 "Do not export to next AS (well-known community)\n")
8901
8902/* old command */
8903DEFUN (show_ipv6_mbgp_community_exact,
8904 show_ipv6_mbgp_community_exact_cmd,
8905 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8906 SHOW_STR
8907 IPV6_STR
8908 MBGP_STR
8909 "Display routes matching the communities\n"
8910 "community number\n"
8911 "Do not send outside local AS (well-known community)\n"
8912 "Do not advertise to any peer (well-known community)\n"
8913 "Do not export to next AS (well-known community)\n"
8914 "Exact match of the communities")
8915{
95cbbd2a 8916 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
718e3744 8917}
8918
8919/* old command */
8920ALIAS (show_ipv6_mbgp_community_exact,
8921 show_ipv6_mbgp_community2_exact_cmd,
8922 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8923 SHOW_STR
8924 IPV6_STR
8925 MBGP_STR
8926 "Display routes matching the communities\n"
8927 "community number\n"
8928 "Do not send outside local AS (well-known community)\n"
8929 "Do not advertise to any peer (well-known community)\n"
8930 "Do not export to next AS (well-known community)\n"
8931 "community number\n"
8932 "Do not send outside local AS (well-known community)\n"
8933 "Do not advertise to any peer (well-known community)\n"
8934 "Do not export to next AS (well-known community)\n"
8935 "Exact match of the communities")
8936
8937/* old command */
8938ALIAS (show_ipv6_mbgp_community_exact,
8939 show_ipv6_mbgp_community3_exact_cmd,
8940 "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",
8941 SHOW_STR
8942 IPV6_STR
8943 MBGP_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 "community number\n"
8950 "Do not send outside local AS (well-known community)\n"
8951 "Do not advertise to any peer (well-known community)\n"
8952 "Do not export to next AS (well-known community)\n"
8953 "community number\n"
8954 "Do not send outside local AS (well-known community)\n"
8955 "Do not advertise to any peer (well-known community)\n"
8956 "Do not export to next AS (well-known community)\n"
8957 "Exact match of the communities")
8958
8959/* old command */
8960ALIAS (show_ipv6_mbgp_community_exact,
8961 show_ipv6_mbgp_community4_exact_cmd,
8962 "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",
8963 SHOW_STR
8964 IPV6_STR
8965 MBGP_STR
8966 "Display routes matching the communities\n"
8967 "community number\n"
8968 "Do not send outside local AS (well-known community)\n"
8969 "Do not advertise to any peer (well-known community)\n"
8970 "Do not export to next AS (well-known community)\n"
8971 "community number\n"
8972 "Do not send outside local AS (well-known community)\n"
8973 "Do not advertise to any peer (well-known community)\n"
8974 "Do not export to next AS (well-known community)\n"
8975 "community number\n"
8976 "Do not send outside local AS (well-known community)\n"
8977 "Do not advertise to any peer (well-known community)\n"
8978 "Do not export to next AS (well-known community)\n"
8979 "community number\n"
8980 "Do not send outside local AS (well-known community)\n"
8981 "Do not advertise to any peer (well-known community)\n"
8982 "Do not export to next AS (well-known community)\n"
8983 "Exact match of the communities")
8984#endif /* HAVE_IPV6 */
6b0655a2 8985
94f2b392 8986static int
fd79ac91 8987bgp_show_community_list (struct vty *vty, const char *com, int exact,
4c9641ba 8988 afi_t afi, safi_t safi)
718e3744 8989{
8990 struct community_list *list;
8991
fee6e4e4 8992 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
718e3744 8993 if (list == NULL)
8994 {
8995 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8996 VTY_NEWLINE);
8997 return CMD_WARNING;
8998 }
8999
5a646650 9000 return bgp_show (vty, NULL, afi, safi,
9001 (exact ? bgp_show_type_community_list_exact :
47fc97cc 9002 bgp_show_type_community_list), list, NULL);
718e3744 9003}
9004
9005DEFUN (show_ip_bgp_community_list,
9006 show_ip_bgp_community_list_cmd,
fee6e4e4 9007 "show ip bgp community-list (<1-500>|WORD)",
718e3744 9008 SHOW_STR
9009 IP_STR
9010 BGP_STR
9011 "Display routes matching the community-list\n"
fee6e4e4 9012 "community-list number\n"
718e3744 9013 "community-list name\n")
9014{
9015 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
9016}
9017
9018DEFUN (show_ip_bgp_ipv4_community_list,
9019 show_ip_bgp_ipv4_community_list_cmd,
fee6e4e4 9020 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
718e3744 9021 SHOW_STR
9022 IP_STR
9023 BGP_STR
9024 "Address family\n"
9025 "Address Family modifier\n"
9026 "Address Family modifier\n"
9027 "Display routes matching the community-list\n"
fee6e4e4 9028 "community-list number\n"
718e3744 9029 "community-list name\n")
9030{
9031 if (strncmp (argv[0], "m", 1) == 0)
9032 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
9033
9034 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
9035}
9036
9037DEFUN (show_ip_bgp_community_list_exact,
9038 show_ip_bgp_community_list_exact_cmd,
fee6e4e4 9039 "show ip bgp community-list (<1-500>|WORD) exact-match",
718e3744 9040 SHOW_STR
9041 IP_STR
9042 BGP_STR
9043 "Display routes matching the community-list\n"
fee6e4e4 9044 "community-list number\n"
718e3744 9045 "community-list name\n"
9046 "Exact match of the communities\n")
9047{
9048 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
9049}
9050
9051DEFUN (show_ip_bgp_ipv4_community_list_exact,
9052 show_ip_bgp_ipv4_community_list_exact_cmd,
fee6e4e4 9053 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
718e3744 9054 SHOW_STR
9055 IP_STR
9056 BGP_STR
9057 "Address family\n"
9058 "Address Family modifier\n"
9059 "Address Family modifier\n"
9060 "Display routes matching the community-list\n"
fee6e4e4 9061 "community-list number\n"
718e3744 9062 "community-list name\n"
9063 "Exact match of the communities\n")
9064{
9065 if (strncmp (argv[0], "m", 1) == 0)
9066 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
9067
9068 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
9069}
9070
9071#ifdef HAVE_IPV6
9072DEFUN (show_bgp_community_list,
9073 show_bgp_community_list_cmd,
fee6e4e4 9074 "show bgp community-list (<1-500>|WORD)",
718e3744 9075 SHOW_STR
9076 BGP_STR
9077 "Display routes matching the community-list\n"
fee6e4e4 9078 "community-list number\n"
718e3744 9079 "community-list name\n")
9080{
9081 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9082}
9083
9084ALIAS (show_bgp_community_list,
9085 show_bgp_ipv6_community_list_cmd,
fee6e4e4 9086 "show bgp ipv6 community-list (<1-500>|WORD)",
718e3744 9087 SHOW_STR
9088 BGP_STR
9089 "Address family\n"
9090 "Display routes matching the community-list\n"
fee6e4e4 9091 "community-list number\n"
e8e1946e 9092 "community-list name\n")
718e3744 9093
9094/* old command */
9095DEFUN (show_ipv6_bgp_community_list,
9096 show_ipv6_bgp_community_list_cmd,
9097 "show ipv6 bgp community-list WORD",
9098 SHOW_STR
9099 IPV6_STR
9100 BGP_STR
9101 "Display routes matching the community-list\n"
9102 "community-list name\n")
9103{
9104 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9105}
9106
9107/* old command */
9108DEFUN (show_ipv6_mbgp_community_list,
9109 show_ipv6_mbgp_community_list_cmd,
9110 "show ipv6 mbgp community-list WORD",
9111 SHOW_STR
9112 IPV6_STR
9113 MBGP_STR
9114 "Display routes matching the community-list\n"
9115 "community-list name\n")
9116{
9117 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9118}
9119
9120DEFUN (show_bgp_community_list_exact,
9121 show_bgp_community_list_exact_cmd,
fee6e4e4 9122 "show bgp community-list (<1-500>|WORD) exact-match",
718e3744 9123 SHOW_STR
9124 BGP_STR
9125 "Display routes matching the community-list\n"
fee6e4e4 9126 "community-list number\n"
718e3744 9127 "community-list name\n"
9128 "Exact match of the communities\n")
9129{
9130 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9131}
9132
9133ALIAS (show_bgp_community_list_exact,
9134 show_bgp_ipv6_community_list_exact_cmd,
fee6e4e4 9135 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
718e3744 9136 SHOW_STR
9137 BGP_STR
9138 "Address family\n"
9139 "Display routes matching the community-list\n"
fee6e4e4 9140 "community-list number\n"
718e3744 9141 "community-list name\n"
9142 "Exact match of the communities\n")
9143
9144/* old command */
9145DEFUN (show_ipv6_bgp_community_list_exact,
9146 show_ipv6_bgp_community_list_exact_cmd,
9147 "show ipv6 bgp community-list WORD exact-match",
9148 SHOW_STR
9149 IPV6_STR
9150 BGP_STR
9151 "Display routes matching the community-list\n"
9152 "community-list name\n"
9153 "Exact match of the communities\n")
9154{
9155 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9156}
9157
9158/* old command */
9159DEFUN (show_ipv6_mbgp_community_list_exact,
9160 show_ipv6_mbgp_community_list_exact_cmd,
9161 "show ipv6 mbgp community-list WORD exact-match",
9162 SHOW_STR
9163 IPV6_STR
9164 MBGP_STR
9165 "Display routes matching the community-list\n"
9166 "community-list name\n"
9167 "Exact match of the communities\n")
9168{
9169 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9170}
9171#endif /* HAVE_IPV6 */
6b0655a2 9172
94f2b392 9173static int
fd79ac91 9174bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
718e3744 9175 safi_t safi, enum bgp_show_type type)
9176{
9177 int ret;
9178 struct prefix *p;
9179
9180 p = prefix_new();
9181
9182 ret = str2prefix (prefix, p);
9183 if (! ret)
9184 {
9185 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9186 return CMD_WARNING;
9187 }
9188
47fc97cc 9189 ret = bgp_show (vty, NULL, afi, safi, type, p, NULL);
5a646650 9190 prefix_free(p);
9191 return ret;
718e3744 9192}
9193
9194DEFUN (show_ip_bgp_prefix_longer,
9195 show_ip_bgp_prefix_longer_cmd,
9196 "show ip bgp A.B.C.D/M longer-prefixes",
9197 SHOW_STR
9198 IP_STR
9199 BGP_STR
9200 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9201 "Display route and more specific routes\n")
9202{
9203 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9204 bgp_show_type_prefix_longer);
9205}
9206
9207DEFUN (show_ip_bgp_flap_prefix_longer,
9208 show_ip_bgp_flap_prefix_longer_cmd,
9209 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9210 SHOW_STR
9211 IP_STR
9212 BGP_STR
9213 "Display flap statistics of routes\n"
9214 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9215 "Display route and more specific routes\n")
9216{
9217 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9218 bgp_show_type_flap_prefix_longer);
9219}
9220
9221DEFUN (show_ip_bgp_ipv4_prefix_longer,
9222 show_ip_bgp_ipv4_prefix_longer_cmd,
9223 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9224 SHOW_STR
9225 IP_STR
9226 BGP_STR
9227 "Address family\n"
9228 "Address Family modifier\n"
9229 "Address Family modifier\n"
9230 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9231 "Display route and more specific routes\n")
9232{
9233 if (strncmp (argv[0], "m", 1) == 0)
9234 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9235 bgp_show_type_prefix_longer);
9236
9237 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9238 bgp_show_type_prefix_longer);
9239}
9240
9241DEFUN (show_ip_bgp_flap_address,
9242 show_ip_bgp_flap_address_cmd,
9243 "show ip bgp flap-statistics A.B.C.D",
9244 SHOW_STR
9245 IP_STR
9246 BGP_STR
9247 "Display flap statistics of routes\n"
9248 "Network in the BGP routing table to display\n")
9249{
9250 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9251 bgp_show_type_flap_address);
9252}
9253
9254DEFUN (show_ip_bgp_flap_prefix,
9255 show_ip_bgp_flap_prefix_cmd,
9256 "show ip bgp flap-statistics A.B.C.D/M",
9257 SHOW_STR
9258 IP_STR
9259 BGP_STR
9260 "Display flap statistics of routes\n"
9261 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9262{
9263 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9264 bgp_show_type_flap_prefix);
9265}
9266#ifdef HAVE_IPV6
9267DEFUN (show_bgp_prefix_longer,
9268 show_bgp_prefix_longer_cmd,
9269 "show bgp X:X::X:X/M longer-prefixes",
9270 SHOW_STR
9271 BGP_STR
9272 "IPv6 prefix <network>/<length>\n"
9273 "Display route and more specific routes\n")
9274{
9275 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9276 bgp_show_type_prefix_longer);
9277}
9278
9279ALIAS (show_bgp_prefix_longer,
9280 show_bgp_ipv6_prefix_longer_cmd,
9281 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9282 SHOW_STR
9283 BGP_STR
9284 "Address family\n"
9285 "IPv6 prefix <network>/<length>\n"
9286 "Display route and more specific routes\n")
9287
9288/* old command */
9289DEFUN (show_ipv6_bgp_prefix_longer,
9290 show_ipv6_bgp_prefix_longer_cmd,
9291 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9292 SHOW_STR
9293 IPV6_STR
9294 BGP_STR
9295 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9296 "Display route and more specific routes\n")
9297{
9298 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9299 bgp_show_type_prefix_longer);
9300}
9301
9302/* old command */
9303DEFUN (show_ipv6_mbgp_prefix_longer,
9304 show_ipv6_mbgp_prefix_longer_cmd,
9305 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9306 SHOW_STR
9307 IPV6_STR
9308 MBGP_STR
9309 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9310 "Display route and more specific routes\n")
9311{
9312 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9313 bgp_show_type_prefix_longer);
9314}
9315#endif /* HAVE_IPV6 */
bb46e94f 9316
94f2b392 9317static struct peer *
fd79ac91 9318peer_lookup_in_view (struct vty *vty, const char *view_name,
9319 const char *ip_str)
bb46e94f 9320{
9321 int ret;
9322 struct bgp *bgp;
9323 struct peer *peer;
9324 union sockunion su;
9325
9326 /* BGP structure lookup. */
9327 if (view_name)
9328 {
9329 bgp = bgp_lookup_by_name (view_name);
9330 if (! bgp)
9331 {
9332 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9333 return NULL;
9334 }
9335 }
5228ad27 9336 else
bb46e94f 9337 {
9338 bgp = bgp_get_default ();
9339 if (! bgp)
9340 {
9341 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9342 return NULL;
9343 }
9344 }
9345
9346 /* Get peer sockunion. */
9347 ret = str2sockunion (ip_str, &su);
9348 if (ret < 0)
9349 {
9350 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9351 return NULL;
9352 }
9353
9354 /* Peer structure lookup. */
9355 peer = peer_lookup (bgp, &su);
9356 if (! peer)
9357 {
9358 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9359 return NULL;
9360 }
9361
9362 return peer;
9363}
6b0655a2 9364
2815e61f
PJ
9365enum bgp_stats
9366{
9367 BGP_STATS_MAXBITLEN = 0,
9368 BGP_STATS_RIB,
9369 BGP_STATS_PREFIXES,
9370 BGP_STATS_TOTPLEN,
9371 BGP_STATS_UNAGGREGATEABLE,
9372 BGP_STATS_MAX_AGGREGATEABLE,
9373 BGP_STATS_AGGREGATES,
9374 BGP_STATS_SPACE,
9375 BGP_STATS_ASPATH_COUNT,
9376 BGP_STATS_ASPATH_MAXHOPS,
9377 BGP_STATS_ASPATH_TOTHOPS,
9378 BGP_STATS_ASPATH_MAXSIZE,
9379 BGP_STATS_ASPATH_TOTSIZE,
9380 BGP_STATS_ASN_HIGHEST,
9381 BGP_STATS_MAX,
9382};
9383
9384static const char *table_stats_strs[] =
9385{
9386 [BGP_STATS_PREFIXES] = "Total Prefixes",
9387 [BGP_STATS_TOTPLEN] = "Average prefix length",
9388 [BGP_STATS_RIB] = "Total Advertisements",
9389 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9390 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9391 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9392 [BGP_STATS_SPACE] = "Address space advertised",
9393 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9394 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9395 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9396 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9397 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9398 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9399 [BGP_STATS_MAX] = NULL,
9400};
9401
9402struct bgp_table_stats
9403{
9404 struct bgp_table *table;
9405 unsigned long long counts[BGP_STATS_MAX];
9406};
9407
9408#if 0
9409#define TALLY_SIGFIG 100000
9410static unsigned long
9411ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9412{
9413 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9414 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9415 unsigned long ret = newtot / count;
9416
9417 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9418 return ret + 1;
9419 else
9420 return ret;
9421}
9422#endif
9423
9424static int
9425bgp_table_stats_walker (struct thread *t)
9426{
9427 struct bgp_node *rn;
9428 struct bgp_node *top;
9429 struct bgp_table_stats *ts = THREAD_ARG (t);
9430 unsigned int space = 0;
9431
53d9f67a
PJ
9432 if (!(top = bgp_table_top (ts->table)))
9433 return 0;
2815e61f
PJ
9434
9435 switch (top->p.family)
9436 {
9437 case AF_INET:
9438 space = IPV4_MAX_BITLEN;
9439 break;
9440 case AF_INET6:
9441 space = IPV6_MAX_BITLEN;
9442 break;
9443 }
9444
9445 ts->counts[BGP_STATS_MAXBITLEN] = space;
9446
9447 for (rn = top; rn; rn = bgp_route_next (rn))
9448 {
9449 struct bgp_info *ri;
67174041 9450 struct bgp_node *prn = bgp_node_parent_nolock (rn);
2815e61f
PJ
9451 unsigned int rinum = 0;
9452
9453 if (rn == top)
9454 continue;
9455
9456 if (!rn->info)
9457 continue;
9458
9459 ts->counts[BGP_STATS_PREFIXES]++;
9460 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9461
9462#if 0
9463 ts->counts[BGP_STATS_AVGPLEN]
9464 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9465 ts->counts[BGP_STATS_AVGPLEN],
9466 rn->p.prefixlen);
9467#endif
9468
9469 /* check if the prefix is included by any other announcements */
9470 while (prn && !prn->info)
67174041 9471 prn = bgp_node_parent_nolock (prn);
2815e61f
PJ
9472
9473 if (prn == NULL || prn == top)
8383a9bd
PJ
9474 {
9475 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9476 /* announced address space */
9477 if (space)
9478 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9479 }
2815e61f
PJ
9480 else if (prn->info)
9481 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9482
2815e61f
PJ
9483 for (ri = rn->info; ri; ri = ri->next)
9484 {
9485 rinum++;
9486 ts->counts[BGP_STATS_RIB]++;
9487
9488 if (ri->attr &&
9489 (CHECK_FLAG (ri->attr->flag,
9490 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9491 ts->counts[BGP_STATS_AGGREGATES]++;
9492
9493 /* as-path stats */
9494 if (ri->attr && ri->attr->aspath)
9495 {
9496 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9497 unsigned int size = aspath_size (ri->attr->aspath);
9498 as_t highest = aspath_highest (ri->attr->aspath);
9499
9500 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9501
9502 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9503 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9504
9505 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9506 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9507
9508 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9509 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9510#if 0
9511 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9512 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9513 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9514 hops);
9515 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9516 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9517 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9518 size);
9519#endif
9520 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9521 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9522 }
9523 }
9524 }
9525 return 0;
9526}
9527
9528static int
9529bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9530{
9531 struct bgp_table_stats ts;
9532 unsigned int i;
9533
9534 if (!bgp->rib[afi][safi])
9535 {
9536 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9537 return CMD_WARNING;
9538 }
9539
9540 memset (&ts, 0, sizeof (ts));
9541 ts.table = bgp->rib[afi][safi];
9542 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
bb46e94f 9543
2815e61f
PJ
9544 vty_out (vty, "BGP %s RIB statistics%s%s",
9545 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9546
9547 for (i = 0; i < BGP_STATS_MAX; i++)
9548 {
9549 if (!table_stats_strs[i])
9550 continue;
9551
9552 switch (i)
9553 {
9554#if 0
9555 case BGP_STATS_ASPATH_AVGHOPS:
9556 case BGP_STATS_ASPATH_AVGSIZE:
9557 case BGP_STATS_AVGPLEN:
9558 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9559 vty_out (vty, "%12.2f",
9560 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9561 break;
9562#endif
9563 case BGP_STATS_ASPATH_TOTHOPS:
9564 case BGP_STATS_ASPATH_TOTSIZE:
9565 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9566 vty_out (vty, "%12.2f",
9567 ts.counts[i] ?
9568 (float)ts.counts[i] /
9569 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9570 : 0);
9571 break;
9572 case BGP_STATS_TOTPLEN:
9573 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9574 vty_out (vty, "%12.2f",
9575 ts.counts[i] ?
9576 (float)ts.counts[i] /
9577 (float)ts.counts[BGP_STATS_PREFIXES]
9578 : 0);
9579 break;
9580 case BGP_STATS_SPACE:
9581 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9582 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9583 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9584 break;
30a2231a 9585 vty_out (vty, "%30s: ", "%% announced ");
2815e61f
PJ
9586 vty_out (vty, "%12.2f%s",
9587 100 * (float)ts.counts[BGP_STATS_SPACE] /
56395af7 9588 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
2815e61f
PJ
9589 VTY_NEWLINE);
9590 vty_out (vty, "%30s: ", "/8 equivalent ");
9591 vty_out (vty, "%12.2f%s",
9592 (float)ts.counts[BGP_STATS_SPACE] /
9593 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9594 VTY_NEWLINE);
9595 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9596 break;
9597 vty_out (vty, "%30s: ", "/24 equivalent ");
9598 vty_out (vty, "%12.2f",
9599 (float)ts.counts[BGP_STATS_SPACE] /
9600 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9601 break;
9602 default:
9603 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9604 vty_out (vty, "%12llu", ts.counts[i]);
9605 }
9606
9607 vty_out (vty, "%s", VTY_NEWLINE);
9608 }
9609 return CMD_SUCCESS;
9610}
9611
9612static int
9613bgp_table_stats_vty (struct vty *vty, const char *name,
9614 const char *afi_str, const char *safi_str)
9615{
9616 struct bgp *bgp;
9617 afi_t afi;
9618 safi_t safi;
9619
9620 if (name)
9621 bgp = bgp_lookup_by_name (name);
9622 else
9623 bgp = bgp_get_default ();
9624
9625 if (!bgp)
9626 {
9627 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9628 return CMD_WARNING;
9629 }
9630 if (strncmp (afi_str, "ipv", 3) == 0)
9631 {
9632 if (strncmp (afi_str, "ipv4", 4) == 0)
9633 afi = AFI_IP;
9634 else if (strncmp (afi_str, "ipv6", 4) == 0)
9635 afi = AFI_IP6;
9636 else
9637 {
9638 vty_out (vty, "%% Invalid address family %s%s",
9639 afi_str, VTY_NEWLINE);
9640 return CMD_WARNING;
9641 }
9642 if (strncmp (safi_str, "m", 1) == 0)
9643 safi = SAFI_MULTICAST;
9644 else if (strncmp (safi_str, "u", 1) == 0)
9645 safi = SAFI_UNICAST;
42e6d745
DO
9646 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9647 safi = SAFI_MPLS_LABELED_VPN;
2815e61f
PJ
9648 else
9649 {
9650 vty_out (vty, "%% Invalid subsequent address family %s%s",
9651 safi_str, VTY_NEWLINE);
9652 return CMD_WARNING;
9653 }
9654 }
9655 else
9656 {
9657 vty_out (vty, "%% Invalid address family %s%s",
9658 afi_str, VTY_NEWLINE);
9659 return CMD_WARNING;
9660 }
9661
2815e61f
PJ
9662 return bgp_table_stats (vty, bgp, afi, safi);
9663}
9664
9665DEFUN (show_bgp_statistics,
9666 show_bgp_statistics_cmd,
9667 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9668 SHOW_STR
9669 BGP_STR
9670 "Address family\n"
9671 "Address family\n"
9672 "Address Family modifier\n"
9673 "Address Family modifier\n"
9674 "BGP RIB advertisement statistics\n")
9675{
9676 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9677}
9678
9679ALIAS (show_bgp_statistics,
9680 show_bgp_statistics_vpnv4_cmd,
9681 "show bgp (ipv4) (vpnv4) statistics",
9682 SHOW_STR
9683 BGP_STR
9684 "Address family\n"
9685 "Address Family modifier\n"
9686 "BGP RIB advertisement statistics\n")
9687
9688DEFUN (show_bgp_statistics_view,
9689 show_bgp_statistics_view_cmd,
9690 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9691 SHOW_STR
9692 BGP_STR
9693 "BGP view\n"
9694 "Address family\n"
9695 "Address family\n"
9696 "Address Family modifier\n"
9697 "Address Family modifier\n"
9698 "BGP RIB advertisement statistics\n")
9699{
9700 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9701}
9702
9703ALIAS (show_bgp_statistics_view,
9704 show_bgp_statistics_view_vpnv4_cmd,
9705 "show bgp view WORD (ipv4) (vpnv4) statistics",
9706 SHOW_STR
9707 BGP_STR
9708 "BGP view\n"
9709 "Address family\n"
9710 "Address Family modifier\n"
9711 "BGP RIB advertisement statistics\n")
6b0655a2 9712
ff7924f6
PJ
9713enum bgp_pcounts
9714{
9715 PCOUNT_ADJ_IN = 0,
9716 PCOUNT_DAMPED,
9717 PCOUNT_REMOVED,
9718 PCOUNT_HISTORY,
9719 PCOUNT_STALE,
9720 PCOUNT_VALID,
9721 PCOUNT_ALL,
9722 PCOUNT_COUNTED,
9723 PCOUNT_PFCNT, /* the figure we display to users */
9724 PCOUNT_MAX,
9725};
9726
9727static const char *pcount_strs[] =
9728{
9729 [PCOUNT_ADJ_IN] = "Adj-in",
9730 [PCOUNT_DAMPED] = "Damped",
9731 [PCOUNT_REMOVED] = "Removed",
9732 [PCOUNT_HISTORY] = "History",
9733 [PCOUNT_STALE] = "Stale",
9734 [PCOUNT_VALID] = "Valid",
9735 [PCOUNT_ALL] = "All RIB",
9736 [PCOUNT_COUNTED] = "PfxCt counted",
9737 [PCOUNT_PFCNT] = "Useable",
9738 [PCOUNT_MAX] = NULL,
9739};
9740
2815e61f
PJ
9741struct peer_pcounts
9742{
9743 unsigned int count[PCOUNT_MAX];
9744 const struct peer *peer;
9745 const struct bgp_table *table;
9746};
9747
ff7924f6 9748static int
2815e61f 9749bgp_peer_count_walker (struct thread *t)
ff7924f6
PJ
9750{
9751 struct bgp_node *rn;
2815e61f
PJ
9752 struct peer_pcounts *pc = THREAD_ARG (t);
9753 const struct peer *peer = pc->peer;
ff7924f6 9754
2815e61f 9755 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
ff7924f6
PJ
9756 {
9757 struct bgp_adj_in *ain;
2815e61f 9758 struct bgp_info *ri;
ff7924f6
PJ
9759
9760 for (ain = rn->adj_in; ain; ain = ain->next)
9761 if (ain->peer == peer)
2815e61f 9762 pc->count[PCOUNT_ADJ_IN]++;
ff7924f6 9763
ff7924f6
PJ
9764 for (ri = rn->info; ri; ri = ri->next)
9765 {
9766 char buf[SU_ADDRSTRLEN];
9767
9768 if (ri->peer != peer)
9769 continue;
9770
2815e61f 9771 pc->count[PCOUNT_ALL]++;
ff7924f6
PJ
9772
9773 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
2815e61f 9774 pc->count[PCOUNT_DAMPED]++;
ff7924f6 9775 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2815e61f 9776 pc->count[PCOUNT_HISTORY]++;
ff7924f6 9777 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
2815e61f 9778 pc->count[PCOUNT_REMOVED]++;
ff7924f6 9779 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2815e61f 9780 pc->count[PCOUNT_STALE]++;
ff7924f6 9781 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
2815e61f 9782 pc->count[PCOUNT_VALID]++;
1a392d46 9783 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2815e61f 9784 pc->count[PCOUNT_PFCNT]++;
ff7924f6
PJ
9785
9786 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9787 {
2815e61f 9788 pc->count[PCOUNT_COUNTED]++;
1a392d46 9789 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
ff7924f6
PJ
9790 plog_warn (peer->log,
9791 "%s [pcount] %s/%d is counted but flags 0x%x",
9792 peer->host,
9793 inet_ntop(rn->p.family, &rn->p.u.prefix,
9794 buf, SU_ADDRSTRLEN),
9795 rn->p.prefixlen,
9796 ri->flags);
9797 }
9798 else
9799 {
1a392d46 9800 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
ff7924f6
PJ
9801 plog_warn (peer->log,
9802 "%s [pcount] %s/%d not counted but flags 0x%x",
9803 peer->host,
9804 inet_ntop(rn->p.family, &rn->p.u.prefix,
9805 buf, SU_ADDRSTRLEN),
9806 rn->p.prefixlen,
9807 ri->flags);
9808 }
9809 }
9810 }
2815e61f
PJ
9811 return 0;
9812}
ff7924f6 9813
2815e61f
PJ
9814static int
9815bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9816{
9817 struct peer_pcounts pcounts = { .peer = peer };
9818 unsigned int i;
9819
9820 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9821 || !peer->bgp->rib[afi][safi])
9822 {
9823 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9824 return CMD_WARNING;
9825 }
9826
9827 memset (&pcounts, 0, sizeof(pcounts));
9828 pcounts.peer = peer;
9829 pcounts.table = peer->bgp->rib[afi][safi];
9830
9831 /* in-place call via thread subsystem so as to record execution time
9832 * stats for the thread-walk (i.e. ensure this can't be blamed on
9833 * on just vty_read()).
9834 */
9835 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9836
ff7924f6
PJ
9837 vty_out (vty, "Prefix counts for %s, %s%s",
9838 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9839 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9840 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9841 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9842
9843 for (i = 0; i < PCOUNT_MAX; i++)
2815e61f
PJ
9844 vty_out (vty, "%20s: %-10d%s",
9845 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
ff7924f6 9846
2815e61f 9847 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
ff7924f6
PJ
9848 {
9849 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9850 peer->host, VTY_NEWLINE);
9851 vty_out (vty, "Please report this bug, with the above command output%s",
9852 VTY_NEWLINE);
9853 }
9854
9855 return CMD_SUCCESS;
9856}
9857
9858DEFUN (show_ip_bgp_neighbor_prefix_counts,
9859 show_ip_bgp_neighbor_prefix_counts_cmd,
9860 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9861 SHOW_STR
9862 IP_STR
9863 BGP_STR
9864 "Detailed information on TCP and BGP neighbor connections\n"
9865 "Neighbor to display information about\n"
9866 "Neighbor to display information about\n"
9867 "Display detailed prefix count information\n")
9868{
9869 struct peer *peer;
9870
9871 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9872 if (! peer)
9873 return CMD_WARNING;
9874
9875 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9876}
9877
9878DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9879 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9880 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9881 SHOW_STR
9882 BGP_STR
9883 "Address family\n"
9884 "Detailed information on TCP and BGP neighbor connections\n"
9885 "Neighbor to display information about\n"
9886 "Neighbor to display information about\n"
9887 "Display detailed prefix count information\n")
9888{
9889 struct peer *peer;
9890
9891 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9892 if (! peer)
9893 return CMD_WARNING;
9894
9895 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9896}
9897
9898DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9899 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9900 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9901 SHOW_STR
9902 IP_STR
9903 BGP_STR
9904 "Address family\n"
9905 "Address Family modifier\n"
9906 "Address Family modifier\n"
9907 "Detailed information on TCP and BGP neighbor connections\n"
9908 "Neighbor to display information about\n"
9909 "Neighbor to display information about\n"
9910 "Display detailed prefix count information\n")
9911{
9912 struct peer *peer;
9913
9914 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9915 if (! peer)
9916 return CMD_WARNING;
9917
9918 if (strncmp (argv[0], "m", 1) == 0)
9919 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9920
9921 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9922}
9923
9924DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9925 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9926 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9927 SHOW_STR
9928 IP_STR
9929 BGP_STR
9930 "Address family\n"
9931 "Address Family modifier\n"
9932 "Address Family modifier\n"
9933 "Detailed information on TCP and BGP neighbor connections\n"
9934 "Neighbor to display information about\n"
9935 "Neighbor to display information about\n"
9936 "Display detailed prefix count information\n")
9937{
9938 struct peer *peer;
9939
9940 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9941 if (! peer)
9942 return CMD_WARNING;
9943
9944 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9945}
9946
9947
94f2b392 9948static void
718e3744 9949show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
47fc97cc 9950 int in, char *delim)
718e3744 9951{
9952 struct bgp_table *table;
9953 struct bgp_adj_in *ain;
9954 struct bgp_adj_out *adj;
9955 unsigned long output_count;
9956 struct bgp_node *rn;
9957 int header1 = 1;
9958 struct bgp *bgp;
9959 int header2 = 1;
9960
bb46e94f 9961 bgp = peer->bgp;
718e3744 9962
9963 if (! bgp)
9964 return;
9965
47fc97cc
DS
9966 if (delim)
9967 header1 = 0;
9968
718e3744 9969 table = bgp->rib[afi][safi];
9970
9971 output_count = 0;
47fc97cc 9972
718e3744 9973 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9974 PEER_STATUS_DEFAULT_ORIGINATE))
9975 {
9976 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
93406d87 9977 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9978 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 9979
9980 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9981 VTY_NEWLINE, VTY_NEWLINE);
9982 header1 = 0;
9983 }
9984
9985 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9986 if (in)
9987 {
9988 for (ain = rn->adj_in; ain; ain = ain->next)
9989 if (ain->peer == peer)
9990 {
9991 if (header1)
9992 {
9993 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
93406d87 9994 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9995 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 9996 header1 = 0;
9997 }
9998 if (header2)
9999 {
47fc97cc
DS
10000 if (delim)
10001 vty_out (vty, BGP_SHOW_HEADER_CSV, VTY_NEWLINE);
10002 else
10003 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
718e3744 10004 header2 = 0;
10005 }
10006 if (ain->attr)
47fc97cc
DS
10007 {
10008 route_vty_out_tmp (vty, &rn->p, ain->attr, safi, delim);
718e3744 10009 output_count++;
10010 }
10011 }
10012 }
10013 else
10014 {
10015 for (adj = rn->adj_out; adj; adj = adj->next)
10016 if (adj->peer == peer)
10017 {
10018 if (header1)
10019 {
10020 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
93406d87 10021 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10022 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 10023 header1 = 0;
10024 }
10025 if (header2)
10026 {
47fc97cc
DS
10027 if (delim)
10028 vty_out (vty, BGP_SHOW_HEADER_CSV, VTY_NEWLINE);
10029 else
10030 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
718e3744 10031 header2 = 0;
10032 }
10033 if (adj->attr)
47fc97cc
DS
10034 {
10035 route_vty_out_tmp (vty, &rn->p, adj->attr, safi, delim);
718e3744 10036 output_count++;
10037 }
10038 }
10039 }
47fc97cc 10040
718e3744 10041 if (output_count != 0)
10042 vty_out (vty, "%sTotal number of prefixes %ld%s",
10043 VTY_NEWLINE, output_count, VTY_NEWLINE);
10044}
10045
94f2b392 10046static int
47fc97cc
DS
10047peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
10048 int in, char *delim)
bb46e94f 10049{
718e3744 10050 if (! peer || ! peer->afc[afi][safi])
10051 {
10052 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10053 return CMD_WARNING;
10054 }
10055
10056 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10057 {
10058 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
10059 VTY_NEWLINE);
10060 return CMD_WARNING;
10061 }
10062
47fc97cc 10063 show_adj_route (vty, peer, afi, safi, in, delim);
718e3744 10064
10065 return CMD_SUCCESS;
10066}
10067
2a71e9ce
TP
10068DEFUN (show_ip_bgp_view_neighbor_advertised_route,
10069 show_ip_bgp_view_neighbor_advertised_route_cmd,
10070 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
718e3744 10071 SHOW_STR
10072 IP_STR
10073 BGP_STR
2a71e9ce
TP
10074 "BGP view\n"
10075 "View name\n"
718e3744 10076 "Detailed information on TCP and BGP neighbor connections\n"
10077 "Neighbor to display information about\n"
10078 "Neighbor to display information about\n"
10079 "Display the routes advertised to a BGP neighbor\n")
10080{
bb46e94f 10081 struct peer *peer;
10082
2a71e9ce
TP
10083 if (argc == 2)
10084 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10085 else
10086 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10087
bb46e94f 10088 if (! peer)
10089 return CMD_WARNING;
10090
47fc97cc 10091 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL);
718e3744 10092}
10093
2a71e9ce
TP
10094ALIAS (show_ip_bgp_view_neighbor_advertised_route,
10095 show_ip_bgp_neighbor_advertised_route_cmd,
10096 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10097 SHOW_STR
10098 IP_STR
10099 BGP_STR
10100 "Detailed information on TCP and BGP neighbor connections\n"
10101 "Neighbor to display information about\n"
10102 "Neighbor to display information about\n"
10103 "Display the routes advertised to a BGP neighbor\n")
10104
47fc97cc
DS
10105DEFUN (show_ip_bgp_neighbor_advertised_route_csv,
10106 show_ip_bgp_neighbor_advertised_route_csv_cmd,
10107 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes csv",
10108 SHOW_STR
10109 IP_STR
10110 BGP_STR
10111 "BGP view\n"
10112 "View name\n"
10113 "Detailed information on TCP and BGP neighbor connections\n"
10114 "Neighbor to display information about\n"
10115 "Neighbor to display information about\n"
10116 "Display the routes advertised to a BGP neighbor\n")
10117{
10118 struct peer *peer;
10119
10120 if (argc == 2)
10121 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10122 else
10123 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10124
10125 if (! peer)
10126 return CMD_WARNING;
10127
10128 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, &csv);
10129}
10130
718e3744 10131DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
10132 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
10133 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10134 SHOW_STR
10135 IP_STR
10136 BGP_STR
10137 "Address family\n"
10138 "Address Family modifier\n"
10139 "Address Family modifier\n"
10140 "Detailed information on TCP and BGP neighbor connections\n"
10141 "Neighbor to display information about\n"
10142 "Neighbor to display information about\n"
10143 "Display the routes advertised to a BGP neighbor\n")
10144{
bb46e94f 10145 struct peer *peer;
10146
10147 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10148 if (! peer)
10149 return CMD_WARNING;
10150
718e3744 10151 if (strncmp (argv[0], "m", 1) == 0)
47fc97cc 10152 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, NULL);
718e3744 10153
47fc97cc 10154 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL);
718e3744 10155}
10156
10157#ifdef HAVE_IPV6
bb46e94f 10158DEFUN (show_bgp_view_neighbor_advertised_route,
10159 show_bgp_view_neighbor_advertised_route_cmd,
10160 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
718e3744 10161 SHOW_STR
10162 BGP_STR
bb46e94f 10163 "BGP view\n"
10164 "View name\n"
718e3744 10165 "Detailed information on TCP and BGP neighbor connections\n"
10166 "Neighbor to display information about\n"
10167 "Neighbor to display information about\n"
10168 "Display the routes advertised to a BGP neighbor\n")
10169{
bb46e94f 10170 struct peer *peer;
10171
10172 if (argc == 2)
10173 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10174 else
10175 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10176
10177 if (! peer)
10178 return CMD_WARNING;
10179
47fc97cc
DS
10180 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL);
10181}
10182
10183DEFUN (show_bgp_view_neighbor_advertised_route_csv,
10184 show_bgp_view_neighbor_advertised_route_csv_cmd,
10185 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes csv",
10186 SHOW_STR
10187 BGP_STR
10188 "BGP view\n"
10189 "View name\n"
10190 "Detailed information on TCP and BGP neighbor connections\n"
10191 "Neighbor to display information about\n"
10192 "Neighbor to display information about\n"
10193 "Display the routes advertised to a BGP neighbor\n")
10194{
10195 struct peer *peer;
10196
10197 if (argc == 2)
10198 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10199 else
10200 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10201
10202 if (! peer)
10203 return CMD_WARNING;
10204
10205 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, &csv);
bb46e94f 10206}
10207
10208ALIAS (show_bgp_view_neighbor_advertised_route,
10209 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10210 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10211 SHOW_STR
10212 BGP_STR
10213 "BGP view\n"
10214 "View name\n"
10215 "Address family\n"
10216 "Detailed information on TCP and BGP neighbor connections\n"
10217 "Neighbor to display information about\n"
10218 "Neighbor to display information about\n"
10219 "Display the routes advertised to a BGP neighbor\n")
10220
47fc97cc
DS
10221ALIAS (show_bgp_view_neighbor_advertised_route_csv,
10222 show_bgp_view_ipv6_neighbor_advertised_route_csv_cmd,
10223 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes csv",
10224 SHOW_STR
10225 BGP_STR
10226 "BGP view\n"
10227 "View name\n"
10228 "Address family\n"
10229 "Detailed information on TCP and BGP neighbor connections\n"
10230 "Neighbor to display information about\n"
10231 "Neighbor to display information about\n"
10232 "Display the routes advertised to a BGP neighbor\n")
10233
bb46e94f 10234DEFUN (show_bgp_view_neighbor_received_routes,
10235 show_bgp_view_neighbor_received_routes_cmd,
10236 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10237 SHOW_STR
10238 BGP_STR
10239 "BGP view\n"
10240 "View name\n"
10241 "Detailed information on TCP and BGP neighbor connections\n"
10242 "Neighbor to display information about\n"
10243 "Neighbor to display information about\n"
10244 "Display the received routes from neighbor\n")
10245{
10246 struct peer *peer;
10247
10248 if (argc == 2)
10249 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10250 else
10251 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10252
10253 if (! peer)
10254 return CMD_WARNING;
10255
47fc97cc 10256 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL);
718e3744 10257}
10258
bb46e94f 10259ALIAS (show_bgp_view_neighbor_received_routes,
10260 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10261 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10262 SHOW_STR
10263 BGP_STR
10264 "BGP view\n"
10265 "View name\n"
10266 "Address family\n"
10267 "Detailed information on TCP and BGP neighbor connections\n"
10268 "Neighbor to display information about\n"
10269 "Neighbor to display information about\n"
10270 "Display the received routes from neighbor\n")
10271
10272ALIAS (show_bgp_view_neighbor_advertised_route,
10273 show_bgp_neighbor_advertised_route_cmd,
10274 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10275 SHOW_STR
10276 BGP_STR
10277 "Detailed information on TCP and BGP neighbor connections\n"
10278 "Neighbor to display information about\n"
10279 "Neighbor to display information about\n"
10280 "Display the routes advertised to a BGP neighbor\n")
10281
10282ALIAS (show_bgp_view_neighbor_advertised_route,
718e3744 10283 show_bgp_ipv6_neighbor_advertised_route_cmd,
10284 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10285 SHOW_STR
10286 BGP_STR
10287 "Address family\n"
10288 "Detailed information on TCP and BGP neighbor connections\n"
10289 "Neighbor to display information about\n"
10290 "Neighbor to display information about\n"
10291 "Display the routes advertised to a BGP neighbor\n")
10292
47fc97cc
DS
10293ALIAS (show_bgp_view_neighbor_advertised_route_csv,
10294 show_bgp_neighbor_advertised_route_csv_cmd,
10295 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes csv",
10296 SHOW_STR
10297 BGP_STR
10298 "Detailed information on TCP and BGP neighbor connections\n"
10299 "Neighbor to display information about\n"
10300 "Neighbor to display information about\n"
10301 "Display the routes advertised to a BGP neighbor\n")
10302
10303ALIAS (show_bgp_view_neighbor_advertised_route_csv,
10304 show_bgp_ipv6_neighbor_advertised_route_csv_cmd,
10305 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes csv",
10306 SHOW_STR
10307 BGP_STR
10308 "Address family\n"
10309 "Detailed information on TCP and BGP neighbor connections\n"
10310 "Neighbor to display information about\n"
10311 "Neighbor to display information about\n"
10312 "Display the routes advertised to a BGP neighbor\n")
10313
718e3744 10314/* old command */
bb46e94f 10315ALIAS (show_bgp_view_neighbor_advertised_route,
718e3744 10316 ipv6_bgp_neighbor_advertised_route_cmd,
10317 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10318 SHOW_STR
10319 IPV6_STR
10320 BGP_STR
10321 "Detailed information on TCP and BGP neighbor connections\n"
10322 "Neighbor to display information about\n"
10323 "Neighbor to display information about\n"
10324 "Display the routes advertised to a BGP neighbor\n")
bb46e94f 10325
718e3744 10326/* old command */
10327DEFUN (ipv6_mbgp_neighbor_advertised_route,
10328 ipv6_mbgp_neighbor_advertised_route_cmd,
10329 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10330 SHOW_STR
10331 IPV6_STR
10332 MBGP_STR
10333 "Detailed information on TCP and BGP neighbor connections\n"
10334 "Neighbor to display information about\n"
10335 "Neighbor to display information about\n"
10336 "Display the routes advertised to a BGP neighbor\n")
10337{
bb46e94f 10338 struct peer *peer;
10339
10340 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10341 if (! peer)
10342 return CMD_WARNING;
10343
47fc97cc 10344 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL);
718e3744 10345}
10346#endif /* HAVE_IPV6 */
6b0655a2 10347
2a71e9ce
TP
10348DEFUN (show_ip_bgp_view_neighbor_received_routes,
10349 show_ip_bgp_view_neighbor_received_routes_cmd,
10350 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
718e3744 10351 SHOW_STR
10352 IP_STR
10353 BGP_STR
2a71e9ce
TP
10354 "BGP view\n"
10355 "View name\n"
718e3744 10356 "Detailed information on TCP and BGP neighbor connections\n"
10357 "Neighbor to display information about\n"
10358 "Neighbor to display information about\n"
10359 "Display the received routes from neighbor\n")
10360{
bb46e94f 10361 struct peer *peer;
10362
2a71e9ce
TP
10363 if (argc == 2)
10364 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10365 else
10366 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10367
bb46e94f 10368 if (! peer)
10369 return CMD_WARNING;
10370
47fc97cc 10371 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL);
718e3744 10372}
10373
2a71e9ce
TP
10374ALIAS (show_ip_bgp_view_neighbor_received_routes,
10375 show_ip_bgp_neighbor_received_routes_cmd,
10376 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10377 SHOW_STR
10378 IP_STR
10379 BGP_STR
10380 "Detailed information on TCP and BGP neighbor connections\n"
10381 "Neighbor to display information about\n"
10382 "Neighbor to display information about\n"
10383 "Display the received routes from neighbor\n")
10384
718e3744 10385DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10386 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10387 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10388 SHOW_STR
10389 IP_STR
10390 BGP_STR
10391 "Address family\n"
10392 "Address Family modifier\n"
10393 "Address Family modifier\n"
10394 "Detailed information on TCP and BGP neighbor connections\n"
10395 "Neighbor to display information about\n"
10396 "Neighbor to display information about\n"
10397 "Display the received routes from neighbor\n")
10398{
bb46e94f 10399 struct peer *peer;
10400
10401 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10402 if (! peer)
10403 return CMD_WARNING;
10404
718e3744 10405 if (strncmp (argv[0], "m", 1) == 0)
47fc97cc 10406 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, NULL);
718e3744 10407
47fc97cc 10408 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL);
718e3744 10409}
10410
95cbbd2a
ML
10411DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10412 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10413#ifdef HAVE_IPV6
10414 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10415#else
10416 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10417#endif
10418 SHOW_STR
10419 BGP_STR
10420 "BGP view\n"
2b00515a 10421 "View name\n"
95cbbd2a
ML
10422 "Address family\n"
10423#ifdef HAVE_IPV6
10424 "Address family\n"
10425#endif
10426 "Address family modifier\n"
10427 "Address family modifier\n"
10428 "Detailed information on TCP and BGP neighbor connections\n"
10429 "Neighbor to display information about\n"
10430 "Neighbor to display information about\n"
10431 "Display the advertised routes to neighbor\n"
10432 "Display the received routes from neighbor\n")
10433{
10434 int afi;
10435 int safi;
10436 int in;
10437 struct peer *peer;
10438
10439#ifdef HAVE_IPV6
10440 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10441#else
10442 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10443#endif
10444
10445 if (! peer)
10446 return CMD_WARNING;
10447
10448#ifdef HAVE_IPV6
10449 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10450 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10451 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10452#else
10453 afi = AFI_IP;
10454 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10455 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10456#endif
10457
47fc97cc 10458 return peer_adj_routes (vty, peer, afi, safi, in, NULL);
95cbbd2a
ML
10459}
10460
718e3744 10461DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10462 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10463 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10464 SHOW_STR
10465 IP_STR
10466 BGP_STR
10467 "Detailed information on TCP and BGP neighbor connections\n"
10468 "Neighbor to display information about\n"
10469 "Neighbor to display information about\n"
10470 "Display information received from a BGP neighbor\n"
10471 "Display the prefixlist filter\n")
10472{
10473 char name[BUFSIZ];
c63b83fe 10474 union sockunion su;
718e3744 10475 struct peer *peer;
c63b83fe 10476 int count, ret;
718e3744 10477
c63b83fe
JBD
10478 ret = str2sockunion (argv[0], &su);
10479 if (ret < 0)
10480 {
10481 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10482 return CMD_WARNING;
10483 }
718e3744 10484
c63b83fe 10485 peer = peer_lookup (NULL, &su);
718e3744 10486 if (! peer)
10487 return CMD_WARNING;
10488
10489 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10490 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10491 if (count)
10492 {
10493 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10494 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10495 }
10496
10497 return CMD_SUCCESS;
10498}
10499
10500DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10501 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10502 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10503 SHOW_STR
10504 IP_STR
10505 BGP_STR
10506 "Address family\n"
10507 "Address Family modifier\n"
10508 "Address Family modifier\n"
10509 "Detailed information on TCP and BGP neighbor connections\n"
10510 "Neighbor to display information about\n"
10511 "Neighbor to display information about\n"
10512 "Display information received from a BGP neighbor\n"
10513 "Display the prefixlist filter\n")
10514{
10515 char name[BUFSIZ];
c63b83fe 10516 union sockunion su;
718e3744 10517 struct peer *peer;
c63b83fe 10518 int count, ret;
718e3744 10519
c63b83fe
JBD
10520 ret = str2sockunion (argv[1], &su);
10521 if (ret < 0)
10522 {
10523 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10524 return CMD_WARNING;
10525 }
718e3744 10526
c63b83fe 10527 peer = peer_lookup (NULL, &su);
718e3744 10528 if (! peer)
10529 return CMD_WARNING;
10530
10531 if (strncmp (argv[0], "m", 1) == 0)
10532 {
10533 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10534 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10535 if (count)
10536 {
10537 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10538 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10539 }
10540 }
10541 else
10542 {
10543 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10544 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10545 if (count)
10546 {
10547 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10548 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10549 }
10550 }
10551
10552 return CMD_SUCCESS;
10553}
10554
10555
10556#ifdef HAVE_IPV6
bb46e94f 10557ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 10558 show_bgp_neighbor_received_routes_cmd,
10559 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10560 SHOW_STR
10561 BGP_STR
10562 "Detailed information on TCP and BGP neighbor connections\n"
10563 "Neighbor to display information about\n"
10564 "Neighbor to display information about\n"
10565 "Display the received routes from neighbor\n")
718e3744 10566
bb46e94f 10567ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 10568 show_bgp_ipv6_neighbor_received_routes_cmd,
10569 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10570 SHOW_STR
10571 BGP_STR
10572 "Address family\n"
10573 "Detailed information on TCP and BGP neighbor connections\n"
10574 "Neighbor to display information about\n"
10575 "Neighbor to display information about\n"
10576 "Display the received routes from neighbor\n")
10577
10578DEFUN (show_bgp_neighbor_received_prefix_filter,
10579 show_bgp_neighbor_received_prefix_filter_cmd,
10580 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10581 SHOW_STR
10582 BGP_STR
10583 "Detailed information on TCP and BGP neighbor connections\n"
10584 "Neighbor to display information about\n"
10585 "Neighbor to display information about\n"
10586 "Display information received from a BGP neighbor\n"
10587 "Display the prefixlist filter\n")
10588{
10589 char name[BUFSIZ];
c63b83fe 10590 union sockunion su;
718e3744 10591 struct peer *peer;
c63b83fe 10592 int count, ret;
718e3744 10593
c63b83fe
JBD
10594 ret = str2sockunion (argv[0], &su);
10595 if (ret < 0)
10596 {
10597 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10598 return CMD_WARNING;
10599 }
718e3744 10600
c63b83fe 10601 peer = peer_lookup (NULL, &su);
718e3744 10602 if (! peer)
10603 return CMD_WARNING;
10604
10605 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10606 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10607 if (count)
10608 {
10609 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10610 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10611 }
10612
10613 return CMD_SUCCESS;
10614}
10615
10616ALIAS (show_bgp_neighbor_received_prefix_filter,
10617 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10618 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10619 SHOW_STR
10620 BGP_STR
10621 "Address family\n"
10622 "Detailed information on TCP and BGP neighbor connections\n"
10623 "Neighbor to display information about\n"
10624 "Neighbor to display information about\n"
10625 "Display information received from a BGP neighbor\n"
10626 "Display the prefixlist filter\n")
10627
10628/* old command */
bb46e94f 10629ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 10630 ipv6_bgp_neighbor_received_routes_cmd,
10631 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10632 SHOW_STR
10633 IPV6_STR
10634 BGP_STR
10635 "Detailed information on TCP and BGP neighbor connections\n"
10636 "Neighbor to display information about\n"
10637 "Neighbor to display information about\n"
10638 "Display the received routes from neighbor\n")
718e3744 10639
10640/* old command */
10641DEFUN (ipv6_mbgp_neighbor_received_routes,
10642 ipv6_mbgp_neighbor_received_routes_cmd,
10643 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10644 SHOW_STR
10645 IPV6_STR
10646 MBGP_STR
10647 "Detailed information on TCP and BGP neighbor connections\n"
10648 "Neighbor to display information about\n"
10649 "Neighbor to display information about\n"
10650 "Display the received routes from neighbor\n")
10651{
bb46e94f 10652 struct peer *peer;
10653
10654 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10655 if (! peer)
10656 return CMD_WARNING;
10657
47fc97cc 10658 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL);
bb46e94f 10659}
10660
10661DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10662 show_bgp_view_neighbor_received_prefix_filter_cmd,
10663 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10664 SHOW_STR
10665 BGP_STR
10666 "BGP view\n"
10667 "View name\n"
10668 "Detailed information on TCP and BGP neighbor connections\n"
10669 "Neighbor to display information about\n"
10670 "Neighbor to display information about\n"
10671 "Display information received from a BGP neighbor\n"
10672 "Display the prefixlist filter\n")
10673{
10674 char name[BUFSIZ];
c63b83fe 10675 union sockunion su;
bb46e94f 10676 struct peer *peer;
10677 struct bgp *bgp;
c63b83fe 10678 int count, ret;
bb46e94f 10679
10680 /* BGP structure lookup. */
10681 bgp = bgp_lookup_by_name (argv[0]);
10682 if (bgp == NULL)
10683 {
10684 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10685 return CMD_WARNING;
10686 }
10687
c63b83fe
JBD
10688 ret = str2sockunion (argv[1], &su);
10689 if (ret < 0)
10690 {
10691 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10692 return CMD_WARNING;
10693 }
bb46e94f 10694
c63b83fe 10695 peer = peer_lookup (bgp, &su);
bb46e94f 10696 if (! peer)
10697 return CMD_WARNING;
10698
10699 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10700 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10701 if (count)
10702 {
10703 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10704 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10705 }
10706
10707 return CMD_SUCCESS;
718e3744 10708}
bb46e94f 10709
10710ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10711 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10712 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10713 SHOW_STR
10714 BGP_STR
10715 "BGP view\n"
10716 "View name\n"
10717 "Address family\n"
10718 "Detailed information on TCP and BGP neighbor connections\n"
10719 "Neighbor to display information about\n"
10720 "Neighbor to display information about\n"
10721 "Display information received from a BGP neighbor\n"
10722 "Display the prefixlist filter\n")
718e3744 10723#endif /* HAVE_IPV6 */
6b0655a2 10724
94f2b392 10725static int
bb46e94f 10726bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
47fc97cc 10727 safi_t safi, enum bgp_show_type type, char *delim)
718e3744 10728{
718e3744 10729 if (! peer || ! peer->afc[afi][safi])
10730 {
10731 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
718e3744 10732 return CMD_WARNING;
10733 }
47fc97cc
DS
10734
10735 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, delim);
718e3744 10736}
10737
10738DEFUN (show_ip_bgp_neighbor_routes,
10739 show_ip_bgp_neighbor_routes_cmd,
10740 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10741 SHOW_STR
10742 IP_STR
10743 BGP_STR
10744 "Detailed information on TCP and BGP neighbor connections\n"
10745 "Neighbor to display information about\n"
10746 "Neighbor to display information about\n"
10747 "Display routes learned from neighbor\n")
10748{
bb46e94f 10749 struct peer *peer;
10750
10751 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10752 if (! peer)
10753 return CMD_WARNING;
10754
10755 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
47fc97cc
DS
10756 bgp_show_type_neighbor, NULL);
10757}
10758
10759DEFUN (show_ip_bgp_neighbor_routes_csv,
10760 show_ip_bgp_neighbor_routes_csv_cmd,
10761 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes csv",
10762 SHOW_STR
10763 IP_STR
10764 BGP_STR
10765 "Detailed information on TCP and BGP neighbor connections\n"
10766 "Neighbor to display information about\n"
10767 "Neighbor to display information about\n"
10768 "Display routes learned from neighbor\n")
10769{
10770 struct peer *peer;
10771
10772 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10773 if (! peer)
10774 return CMD_WARNING;
10775
10776 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
10777 bgp_show_type_neighbor, &csv);
718e3744 10778}
10779
10780DEFUN (show_ip_bgp_neighbor_flap,
10781 show_ip_bgp_neighbor_flap_cmd,
10782 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10783 SHOW_STR
10784 IP_STR
10785 BGP_STR
10786 "Detailed information on TCP and BGP neighbor connections\n"
10787 "Neighbor to display information about\n"
10788 "Neighbor to display information about\n"
10789 "Display flap statistics of the routes learned from neighbor\n")
10790{
bb46e94f 10791 struct peer *peer;
10792
10793 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10794 if (! peer)
10795 return CMD_WARNING;
10796
10797 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
47fc97cc 10798 bgp_show_type_flap_neighbor, NULL);
718e3744 10799}
10800
10801DEFUN (show_ip_bgp_neighbor_damp,
10802 show_ip_bgp_neighbor_damp_cmd,
10803 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10804 SHOW_STR
10805 IP_STR
10806 BGP_STR
10807 "Detailed information on TCP and BGP neighbor connections\n"
10808 "Neighbor to display information about\n"
10809 "Neighbor to display information about\n"
10810 "Display the dampened routes received from neighbor\n")
10811{
bb46e94f 10812 struct peer *peer;
10813
10814 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10815 if (! peer)
10816 return CMD_WARNING;
10817
10818 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
47fc97cc 10819 bgp_show_type_damp_neighbor, NULL);
718e3744 10820}
10821
10822DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10823 show_ip_bgp_ipv4_neighbor_routes_cmd,
10824 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10825 SHOW_STR
10826 IP_STR
10827 BGP_STR
10828 "Address family\n"
10829 "Address Family modifier\n"
10830 "Address Family modifier\n"
10831 "Detailed information on TCP and BGP neighbor connections\n"
10832 "Neighbor to display information about\n"
10833 "Neighbor to display information about\n"
10834 "Display routes learned from neighbor\n")
10835{
bb46e94f 10836 struct peer *peer;
10837
10838 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10839 if (! peer)
10840 return CMD_WARNING;
10841
718e3744 10842 if (strncmp (argv[0], "m", 1) == 0)
bb46e94f 10843 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
47fc97cc 10844 bgp_show_type_neighbor, NULL);
718e3744 10845
bb46e94f 10846 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
47fc97cc 10847 bgp_show_type_neighbor, NULL);
718e3744 10848}
bb46e94f 10849
fee0f4c6 10850DEFUN (show_ip_bgp_view_rsclient,
10851 show_ip_bgp_view_rsclient_cmd,
10852 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10853 SHOW_STR
10854 IP_STR
10855 BGP_STR
10856 "BGP view\n"
2b00515a 10857 "View name\n"
fee0f4c6 10858 "Information about Route Server Client\n"
10859 NEIGHBOR_ADDR_STR)
10860{
10861 struct bgp_table *table;
10862 struct peer *peer;
10863
10864 if (argc == 2)
10865 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10866 else
10867 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10868
10869 if (! peer)
10870 return CMD_WARNING;
10871
10872 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10873 {
10874 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10875 VTY_NEWLINE);
10876 return CMD_WARNING;
10877 }
10878
10879 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10880 PEER_FLAG_RSERVER_CLIENT))
10881 {
10882 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10883 VTY_NEWLINE);
10884 return CMD_WARNING;
10885 }
10886
10887 table = peer->rib[AFI_IP][SAFI_UNICAST];
10888
47fc97cc
DS
10889 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
10890 NULL, NULL);
fee0f4c6 10891}
10892
10893ALIAS (show_ip_bgp_view_rsclient,
10894 show_ip_bgp_rsclient_cmd,
10895 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10896 SHOW_STR
10897 IP_STR
10898 BGP_STR
10899 "Information about Route Server Client\n"
10900 NEIGHBOR_ADDR_STR)
10901
95cbbd2a
ML
10902DEFUN (show_bgp_view_ipv4_safi_rsclient,
10903 show_bgp_view_ipv4_safi_rsclient_cmd,
10904 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
fee0f4c6 10905 SHOW_STR
fee0f4c6 10906 BGP_STR
10907 "BGP view\n"
2b00515a 10908 "View name\n"
95cbbd2a
ML
10909 "Address family\n"
10910 "Address Family modifier\n"
10911 "Address Family modifier\n"
fee0f4c6 10912 "Information about Route Server Client\n"
95cbbd2a 10913 NEIGHBOR_ADDR_STR)
fee0f4c6 10914{
95cbbd2a 10915 struct bgp_table *table;
fee0f4c6 10916 struct peer *peer;
95cbbd2a 10917 safi_t safi;
fee0f4c6 10918
95cbbd2a
ML
10919 if (argc == 3) {
10920 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10921 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10922 } else {
10923 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10924 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10925 }
10926
10927 if (! peer)
10928 return CMD_WARNING;
10929
10930 if (! peer->afc[AFI_IP][safi])
fee0f4c6 10931 {
95cbbd2a
ML
10932 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10933 VTY_NEWLINE);
10934 return CMD_WARNING;
10935 }
10936
10937 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10938 PEER_FLAG_RSERVER_CLIENT))
10939 {
10940 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10941 VTY_NEWLINE);
10942 return CMD_WARNING;
10943 }
10944
10945 table = peer->rib[AFI_IP][safi];
10946
47fc97cc
DS
10947 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
10948 NULL, NULL);
95cbbd2a
ML
10949}
10950
10951ALIAS (show_bgp_view_ipv4_safi_rsclient,
10952 show_bgp_ipv4_safi_rsclient_cmd,
10953 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10954 SHOW_STR
10955 BGP_STR
10956 "Address family\n"
10957 "Address Family modifier\n"
10958 "Address Family modifier\n"
10959 "Information about Route Server Client\n"
10960 NEIGHBOR_ADDR_STR)
10961
10962DEFUN (show_ip_bgp_view_rsclient_route,
10963 show_ip_bgp_view_rsclient_route_cmd,
10964 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10965 SHOW_STR
10966 IP_STR
10967 BGP_STR
10968 "BGP view\n"
2b00515a 10969 "View name\n"
95cbbd2a
ML
10970 "Information about Route Server Client\n"
10971 NEIGHBOR_ADDR_STR
10972 "Network in the BGP routing table to display\n")
10973{
10974 struct bgp *bgp;
10975 struct peer *peer;
10976
10977 /* BGP structure lookup. */
10978 if (argc == 3)
10979 {
10980 bgp = bgp_lookup_by_name (argv[0]);
10981 if (bgp == NULL)
10982 {
10983 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10984 return CMD_WARNING;
fee0f4c6 10985 }
10986 }
10987 else
10988 {
10989 bgp = bgp_get_default ();
10990 if (bgp == NULL)
10991 {
10992 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10993 return CMD_WARNING;
10994 }
10995 }
10996
10997 if (argc == 3)
10998 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10999 else
11000 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11001
11002 if (! peer)
11003 return CMD_WARNING;
11004
11005 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11006 {
11007 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11008 VTY_NEWLINE);
11009 return CMD_WARNING;
11010}
11011
11012 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11013 PEER_FLAG_RSERVER_CLIENT))
11014 {
11015 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11016 VTY_NEWLINE);
11017 return CMD_WARNING;
11018 }
11019
11020 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
11021 (argc == 3) ? argv[2] : argv[1],
11022 AFI_IP, SAFI_UNICAST, NULL, 0);
11023}
11024
11025ALIAS (show_ip_bgp_view_rsclient_route,
11026 show_ip_bgp_rsclient_route_cmd,
11027 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11028 SHOW_STR
11029 IP_STR
11030 BGP_STR
11031 "Information about Route Server Client\n"
11032 NEIGHBOR_ADDR_STR
11033 "Network in the BGP routing table to display\n")
11034
95cbbd2a
ML
11035DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
11036 show_bgp_view_ipv4_safi_rsclient_route_cmd,
11037 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11038 SHOW_STR
11039 BGP_STR
11040 "BGP view\n"
2b00515a 11041 "View name\n"
95cbbd2a
ML
11042 "Address family\n"
11043 "Address Family modifier\n"
11044 "Address Family modifier\n"
11045 "Information about Route Server Client\n"
11046 NEIGHBOR_ADDR_STR
11047 "Network in the BGP routing table to display\n")
11048{
11049 struct bgp *bgp;
11050 struct peer *peer;
11051 safi_t safi;
11052
11053 /* BGP structure lookup. */
11054 if (argc == 4)
11055 {
11056 bgp = bgp_lookup_by_name (argv[0]);
11057 if (bgp == NULL)
11058 {
11059 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11060 return CMD_WARNING;
11061 }
11062 }
11063 else
11064 {
11065 bgp = bgp_get_default ();
11066 if (bgp == NULL)
11067 {
11068 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11069 return CMD_WARNING;
11070 }
11071 }
11072
11073 if (argc == 4) {
11074 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11075 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11076 } else {
11077 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11078 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11079 }
11080
11081 if (! peer)
11082 return CMD_WARNING;
11083
11084 if (! peer->afc[AFI_IP][safi])
11085 {
11086 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11087 VTY_NEWLINE);
11088 return CMD_WARNING;
11089}
11090
11091 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11092 PEER_FLAG_RSERVER_CLIENT))
11093 {
11094 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11095 VTY_NEWLINE);
11096 return CMD_WARNING;
11097 }
11098
11099 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11100 (argc == 4) ? argv[3] : argv[2],
11101 AFI_IP, safi, NULL, 0);
11102}
11103
11104ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
11105 show_bgp_ipv4_safi_rsclient_route_cmd,
11106 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11107 SHOW_STR
11108 BGP_STR
11109 "Address family\n"
11110 "Address Family modifier\n"
11111 "Address Family modifier\n"
11112 "Information about Route Server Client\n"
11113 NEIGHBOR_ADDR_STR
11114 "Network in the BGP routing table to display\n")
11115
fee0f4c6 11116DEFUN (show_ip_bgp_view_rsclient_prefix,
11117 show_ip_bgp_view_rsclient_prefix_cmd,
11118 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11119 SHOW_STR
11120 IP_STR
11121 BGP_STR
11122 "BGP view\n"
2b00515a 11123 "View name\n"
fee0f4c6 11124 "Information about Route Server Client\n"
11125 NEIGHBOR_ADDR_STR
11126 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11127{
11128 struct bgp *bgp;
11129 struct peer *peer;
11130
11131 /* BGP structure lookup. */
11132 if (argc == 3)
11133 {
11134 bgp = bgp_lookup_by_name (argv[0]);
11135 if (bgp == NULL)
11136 {
11137 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11138 return CMD_WARNING;
11139 }
11140 }
11141 else
11142 {
11143 bgp = bgp_get_default ();
11144 if (bgp == NULL)
11145 {
11146 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11147 return CMD_WARNING;
11148 }
11149 }
11150
11151 if (argc == 3)
11152 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11153 else
11154 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11155
11156 if (! peer)
11157 return CMD_WARNING;
11158
11159 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11160 {
11161 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11162 VTY_NEWLINE);
11163 return CMD_WARNING;
11164}
11165
11166 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11167 PEER_FLAG_RSERVER_CLIENT))
11168{
11169 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11170 VTY_NEWLINE);
11171 return CMD_WARNING;
11172 }
11173
11174 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
11175 (argc == 3) ? argv[2] : argv[1],
11176 AFI_IP, SAFI_UNICAST, NULL, 1);
11177}
11178
11179ALIAS (show_ip_bgp_view_rsclient_prefix,
11180 show_ip_bgp_rsclient_prefix_cmd,
11181 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11182 SHOW_STR
11183 IP_STR
11184 BGP_STR
11185 "Information about Route Server Client\n"
11186 NEIGHBOR_ADDR_STR
11187 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11188
95cbbd2a
ML
11189DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
11190 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
11191 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11192 SHOW_STR
11193 BGP_STR
11194 "BGP view\n"
2b00515a 11195 "View name\n"
95cbbd2a
ML
11196 "Address family\n"
11197 "Address Family modifier\n"
11198 "Address Family modifier\n"
11199 "Information about Route Server Client\n"
11200 NEIGHBOR_ADDR_STR
11201 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11202{
11203 struct bgp *bgp;
11204 struct peer *peer;
11205 safi_t safi;
11206
11207 /* BGP structure lookup. */
11208 if (argc == 4)
11209 {
11210 bgp = bgp_lookup_by_name (argv[0]);
11211 if (bgp == NULL)
11212 {
11213 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11214 return CMD_WARNING;
11215 }
11216 }
11217 else
11218 {
11219 bgp = bgp_get_default ();
11220 if (bgp == NULL)
11221 {
11222 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11223 return CMD_WARNING;
11224 }
11225 }
11226
11227 if (argc == 4) {
11228 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11229 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11230 } else {
11231 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11232 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11233 }
11234
11235 if (! peer)
11236 return CMD_WARNING;
11237
11238 if (! peer->afc[AFI_IP][safi])
11239 {
11240 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11241 VTY_NEWLINE);
11242 return CMD_WARNING;
11243}
11244
11245 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11246 PEER_FLAG_RSERVER_CLIENT))
11247{
11248 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11249 VTY_NEWLINE);
11250 return CMD_WARNING;
11251 }
11252
11253 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11254 (argc == 4) ? argv[3] : argv[2],
11255 AFI_IP, safi, NULL, 1);
11256}
11257
11258ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11259 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11260 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11261 SHOW_STR
11262 BGP_STR
11263 "Address family\n"
11264 "Address Family modifier\n"
11265 "Address Family modifier\n"
11266 "Information about Route Server Client\n"
11267 NEIGHBOR_ADDR_STR
11268 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
fee0f4c6 11269
718e3744 11270#ifdef HAVE_IPV6
bb46e94f 11271DEFUN (show_bgp_view_neighbor_routes,
11272 show_bgp_view_neighbor_routes_cmd,
11273 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
718e3744 11274 SHOW_STR
11275 BGP_STR
bb46e94f 11276 "BGP view\n"
2b00515a 11277 "View name\n"
718e3744 11278 "Detailed information on TCP and BGP neighbor connections\n"
11279 "Neighbor to display information about\n"
11280 "Neighbor to display information about\n"
11281 "Display routes learned from neighbor\n")
11282{
bb46e94f 11283 struct peer *peer;
11284
11285 if (argc == 2)
11286 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11287 else
11288 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11289
11290 if (! peer)
11291 return CMD_WARNING;
11292
11293 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
47fc97cc
DS
11294 bgp_show_type_neighbor, NULL);
11295}
11296
11297DEFUN (show_bgp_view_neighbor_routes_csv,
11298 show_bgp_view_neighbor_routes_csv_cmd,
11299 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes csv",
11300 SHOW_STR
11301 BGP_STR
11302 "BGP view\n"
11303 "BGP view name\n"
11304 "Detailed information on TCP and BGP neighbor connections\n"
11305 "Neighbor to display information about\n"
11306 "Neighbor to display information about\n"
11307 "Display routes learned from neighbor\n")
11308{
11309 struct peer *peer;
11310
11311 if (argc == 2)
11312 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11313 else
11314 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11315
11316 if (! peer)
11317 return CMD_WARNING;
11318
11319 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11320 bgp_show_type_neighbor, &csv);
718e3744 11321}
11322
bb46e94f 11323ALIAS (show_bgp_view_neighbor_routes,
11324 show_bgp_view_ipv6_neighbor_routes_cmd,
11325 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11326 SHOW_STR
11327 BGP_STR
11328 "BGP view\n"
2b00515a 11329 "View name\n"
bb46e94f 11330 "Address family\n"
11331 "Detailed information on TCP and BGP neighbor connections\n"
11332 "Neighbor to display information about\n"
11333 "Neighbor to display information about\n"
11334 "Display routes learned from neighbor\n")
11335
11336DEFUN (show_bgp_view_neighbor_damp,
11337 show_bgp_view_neighbor_damp_cmd,
11338 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11339 SHOW_STR
11340 BGP_STR
11341 "BGP view\n"
2b00515a 11342 "View name\n"
bb46e94f 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 "Display the dampened routes received from neighbor\n")
11347{
11348 struct peer *peer;
11349
11350 if (argc == 2)
11351 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11352 else
11353 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11354
11355 if (! peer)
11356 return CMD_WARNING;
11357
11358 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
47fc97cc 11359 bgp_show_type_damp_neighbor, NULL);
bb46e94f 11360}
11361
11362ALIAS (show_bgp_view_neighbor_damp,
11363 show_bgp_view_ipv6_neighbor_damp_cmd,
11364 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11365 SHOW_STR
11366 BGP_STR
11367 "BGP view\n"
2b00515a 11368 "View name\n"
bb46e94f 11369 "Address family\n"
11370 "Detailed information on TCP and BGP neighbor connections\n"
11371 "Neighbor to display information about\n"
11372 "Neighbor to display information about\n"
11373 "Display the dampened routes received from neighbor\n")
11374
11375DEFUN (show_bgp_view_neighbor_flap,
11376 show_bgp_view_neighbor_flap_cmd,
11377 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11378 SHOW_STR
11379 BGP_STR
11380 "BGP view\n"
2b00515a 11381 "View name\n"
bb46e94f 11382 "Detailed information on TCP and BGP neighbor connections\n"
11383 "Neighbor to display information about\n"
11384 "Neighbor to display information about\n"
11385 "Display flap statistics of the routes learned from neighbor\n")
11386{
11387 struct peer *peer;
11388
11389 if (argc == 2)
11390 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11391 else
11392 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11393
11394 if (! peer)
11395 return CMD_WARNING;
11396
11397 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
47fc97cc 11398 bgp_show_type_flap_neighbor, NULL);
bb46e94f 11399}
11400
11401ALIAS (show_bgp_view_neighbor_flap,
11402 show_bgp_view_ipv6_neighbor_flap_cmd,
11403 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11404 SHOW_STR
11405 BGP_STR
11406 "BGP view\n"
2b00515a 11407 "View name\n"
bb46e94f 11408 "Address family\n"
11409 "Detailed information on TCP and BGP neighbor connections\n"
11410 "Neighbor to display information about\n"
11411 "Neighbor to display information about\n"
11412 "Display flap statistics of the routes learned from neighbor\n")
11413
11414ALIAS (show_bgp_view_neighbor_routes,
11415 show_bgp_neighbor_routes_cmd,
11416 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11417 SHOW_STR
11418 BGP_STR
11419 "Detailed information on TCP and BGP neighbor connections\n"
11420 "Neighbor to display information about\n"
11421 "Neighbor to display information about\n"
11422 "Display routes learned from neighbor\n")
11423
11424
11425ALIAS (show_bgp_view_neighbor_routes,
718e3744 11426 show_bgp_ipv6_neighbor_routes_cmd,
11427 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11428 SHOW_STR
11429 BGP_STR
11430 "Address family\n"
11431 "Detailed information on TCP and BGP neighbor connections\n"
11432 "Neighbor to display information about\n"
11433 "Neighbor to display information about\n"
11434 "Display routes learned from neighbor\n")
11435
11436/* old command */
bb46e94f 11437ALIAS (show_bgp_view_neighbor_routes,
718e3744 11438 ipv6_bgp_neighbor_routes_cmd,
11439 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11440 SHOW_STR
11441 IPV6_STR
11442 BGP_STR
11443 "Detailed information on TCP and BGP neighbor connections\n"
11444 "Neighbor to display information about\n"
11445 "Neighbor to display information about\n"
11446 "Display routes learned from neighbor\n")
718e3744 11447
47fc97cc
DS
11448ALIAS (show_bgp_view_neighbor_routes_csv,
11449 show_bgp_neighbor_routes_csv_cmd,
11450 "show bgp neighbors (A.B.C.D|X:X::X:X) routes csv",
11451 SHOW_STR
11452 BGP_STR
11453 "Detailed information on TCP and BGP neighbor connections\n"
11454 "Neighbor to display information about\n"
11455 "Neighbor to display information about\n"
11456 "Display routes learned from neighbor\n")
11457
11458
11459ALIAS (show_bgp_view_neighbor_routes_csv,
11460 show_bgp_ipv6_neighbor_routes_csv_cmd,
11461 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes csv",
11462 SHOW_STR
11463 BGP_STR
11464 "Address family\n"
11465 "Detailed information on TCP and BGP neighbor connections\n"
11466 "Neighbor to display information about\n"
11467 "Neighbor to display information about\n"
11468 "Display routes learned from neighbor\n")
11469
11470/* old command */
11471ALIAS (show_bgp_view_neighbor_routes_csv,
11472 ipv6_bgp_neighbor_routes_csv_cmd,
11473 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes csv",
11474 SHOW_STR
11475 IPV6_STR
11476 BGP_STR
11477 "Detailed information on TCP and BGP neighbor connections\n"
11478 "Neighbor to display information about\n"
11479 "Neighbor to display information about\n"
11480 "Display routes learned from neighbor\n")
11481
718e3744 11482/* old command */
11483DEFUN (ipv6_mbgp_neighbor_routes,
11484 ipv6_mbgp_neighbor_routes_cmd,
11485 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11486 SHOW_STR
11487 IPV6_STR
11488 MBGP_STR
11489 "Detailed information on TCP and BGP neighbor connections\n"
11490 "Neighbor to display information about\n"
11491 "Neighbor to display information about\n"
11492 "Display routes learned from neighbor\n")
11493{
bb46e94f 11494 struct peer *peer;
11495
11496 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11497 if (! peer)
11498 return CMD_WARNING;
11499
11500 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
47fc97cc 11501 bgp_show_type_neighbor, NULL);
718e3744 11502}
bb46e94f 11503
11504ALIAS (show_bgp_view_neighbor_flap,
11505 show_bgp_neighbor_flap_cmd,
11506 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11507 SHOW_STR
11508 BGP_STR
11509 "Detailed information on TCP and BGP neighbor connections\n"
11510 "Neighbor to display information about\n"
11511 "Neighbor to display information about\n"
11512 "Display flap statistics of the routes learned from neighbor\n")
11513
11514ALIAS (show_bgp_view_neighbor_flap,
11515 show_bgp_ipv6_neighbor_flap_cmd,
11516 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11517 SHOW_STR
11518 BGP_STR
11519 "Address family\n"
11520 "Detailed information on TCP and BGP neighbor connections\n"
11521 "Neighbor to display information about\n"
11522 "Neighbor to display information about\n"
11523 "Display flap statistics of the routes learned from neighbor\n")
11524
11525ALIAS (show_bgp_view_neighbor_damp,
11526 show_bgp_neighbor_damp_cmd,
11527 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11528 SHOW_STR
11529 BGP_STR
11530 "Detailed information on TCP and BGP neighbor connections\n"
11531 "Neighbor to display information about\n"
11532 "Neighbor to display information about\n"
11533 "Display the dampened routes received from neighbor\n")
11534
11535ALIAS (show_bgp_view_neighbor_damp,
11536 show_bgp_ipv6_neighbor_damp_cmd,
11537 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11538 SHOW_STR
11539 BGP_STR
11540 "Address family\n"
11541 "Detailed information on TCP and BGP neighbor connections\n"
11542 "Neighbor to display information about\n"
11543 "Neighbor to display information about\n"
c001ae62 11544 "Display the dampened routes received from neighbor\n")
fee0f4c6 11545
11546DEFUN (show_bgp_view_rsclient,
11547 show_bgp_view_rsclient_cmd,
11548 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11549 SHOW_STR
11550 BGP_STR
11551 "BGP view\n"
2b00515a 11552 "View name\n"
fee0f4c6 11553 "Information about Route Server Client\n"
11554 NEIGHBOR_ADDR_STR)
11555{
11556 struct bgp_table *table;
11557 struct peer *peer;
11558
11559 if (argc == 2)
11560 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11561 else
11562 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11563
11564 if (! peer)
11565 return CMD_WARNING;
11566
11567 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11568 {
11569 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11570 VTY_NEWLINE);
11571 return CMD_WARNING;
11572 }
11573
11574 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11575 PEER_FLAG_RSERVER_CLIENT))
11576 {
11577 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11578 VTY_NEWLINE);
11579 return CMD_WARNING;
11580 }
11581
11582 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11583
47fc97cc
DS
11584 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
11585 NULL, NULL);
fee0f4c6 11586}
11587
11588ALIAS (show_bgp_view_rsclient,
11589 show_bgp_rsclient_cmd,
11590 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11591 SHOW_STR
11592 BGP_STR
11593 "Information about Route Server Client\n"
11594 NEIGHBOR_ADDR_STR)
11595
95cbbd2a
ML
11596DEFUN (show_bgp_view_ipv6_safi_rsclient,
11597 show_bgp_view_ipv6_safi_rsclient_cmd,
11598 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11599 SHOW_STR
11600 BGP_STR
11601 "BGP view\n"
2b00515a 11602 "View name\n"
95cbbd2a
ML
11603 "Address family\n"
11604 "Address Family modifier\n"
11605 "Address Family modifier\n"
11606 "Information about Route Server Client\n"
11607 NEIGHBOR_ADDR_STR)
11608{
11609 struct bgp_table *table;
11610 struct peer *peer;
11611 safi_t safi;
11612
11613 if (argc == 3) {
11614 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11615 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11616 } else {
11617 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11618 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11619 }
11620
11621 if (! peer)
11622 return CMD_WARNING;
11623
11624 if (! peer->afc[AFI_IP6][safi])
11625 {
11626 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11627 VTY_NEWLINE);
11628 return CMD_WARNING;
11629 }
11630
11631 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11632 PEER_FLAG_RSERVER_CLIENT))
11633 {
11634 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11635 VTY_NEWLINE);
11636 return CMD_WARNING;
11637 }
11638
11639 table = peer->rib[AFI_IP6][safi];
11640
47fc97cc
DS
11641 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
11642 NULL, NULL);
95cbbd2a
ML
11643}
11644
11645ALIAS (show_bgp_view_ipv6_safi_rsclient,
11646 show_bgp_ipv6_safi_rsclient_cmd,
11647 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11648 SHOW_STR
11649 BGP_STR
11650 "Address family\n"
11651 "Address Family modifier\n"
11652 "Address Family modifier\n"
11653 "Information about Route Server Client\n"
11654 NEIGHBOR_ADDR_STR)
11655
fee0f4c6 11656DEFUN (show_bgp_view_rsclient_route,
11657 show_bgp_view_rsclient_route_cmd,
11658 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11659 SHOW_STR
11660 BGP_STR
11661 "BGP view\n"
2b00515a 11662 "View name\n"
fee0f4c6 11663 "Information about Route Server Client\n"
11664 NEIGHBOR_ADDR_STR
11665 "Network in the BGP routing table to display\n")
11666{
11667 struct bgp *bgp;
11668 struct peer *peer;
11669
11670 /* BGP structure lookup. */
11671 if (argc == 3)
11672 {
11673 bgp = bgp_lookup_by_name (argv[0]);
11674 if (bgp == NULL)
11675 {
11676 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11677 return CMD_WARNING;
11678 }
11679 }
11680 else
11681 {
11682 bgp = bgp_get_default ();
11683 if (bgp == NULL)
11684 {
11685 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11686 return CMD_WARNING;
11687 }
11688 }
11689
11690 if (argc == 3)
11691 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11692 else
11693 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11694
11695 if (! peer)
11696 return CMD_WARNING;
11697
11698 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11699 {
11700 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11701 VTY_NEWLINE);
11702 return CMD_WARNING;
11703 }
11704
11705 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11706 PEER_FLAG_RSERVER_CLIENT))
11707 {
11708 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11709 VTY_NEWLINE);
11710 return CMD_WARNING;
11711 }
11712
11713 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11714 (argc == 3) ? argv[2] : argv[1],
11715 AFI_IP6, SAFI_UNICAST, NULL, 0);
11716}
11717
11718ALIAS (show_bgp_view_rsclient_route,
11719 show_bgp_rsclient_route_cmd,
11720 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11721 SHOW_STR
11722 BGP_STR
11723 "Information about Route Server Client\n"
11724 NEIGHBOR_ADDR_STR
11725 "Network in the BGP routing table to display\n")
11726
95cbbd2a
ML
11727DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11728 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11729 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11730 SHOW_STR
11731 BGP_STR
11732 "BGP view\n"
2b00515a 11733 "View name\n"
95cbbd2a
ML
11734 "Address family\n"
11735 "Address Family modifier\n"
11736 "Address Family modifier\n"
11737 "Information about Route Server Client\n"
11738 NEIGHBOR_ADDR_STR
11739 "Network in the BGP routing table to display\n")
11740{
11741 struct bgp *bgp;
11742 struct peer *peer;
11743 safi_t safi;
11744
11745 /* BGP structure lookup. */
11746 if (argc == 4)
11747 {
11748 bgp = bgp_lookup_by_name (argv[0]);
11749 if (bgp == NULL)
11750 {
11751 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11752 return CMD_WARNING;
11753 }
11754 }
11755 else
11756 {
11757 bgp = bgp_get_default ();
11758 if (bgp == NULL)
11759 {
11760 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11761 return CMD_WARNING;
11762 }
11763 }
11764
11765 if (argc == 4) {
11766 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11767 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11768 } else {
11769 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11770 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11771 }
11772
11773 if (! peer)
11774 return CMD_WARNING;
11775
11776 if (! peer->afc[AFI_IP6][safi])
11777 {
11778 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11779 VTY_NEWLINE);
11780 return CMD_WARNING;
11781}
11782
11783 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11784 PEER_FLAG_RSERVER_CLIENT))
11785 {
11786 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11787 VTY_NEWLINE);
11788 return CMD_WARNING;
11789 }
11790
11791 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11792 (argc == 4) ? argv[3] : argv[2],
11793 AFI_IP6, safi, NULL, 0);
11794}
11795
11796ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11797 show_bgp_ipv6_safi_rsclient_route_cmd,
11798 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11799 SHOW_STR
11800 BGP_STR
11801 "Address family\n"
11802 "Address Family modifier\n"
11803 "Address Family modifier\n"
11804 "Information about Route Server Client\n"
11805 NEIGHBOR_ADDR_STR
11806 "Network in the BGP routing table to display\n")
11807
fee0f4c6 11808DEFUN (show_bgp_view_rsclient_prefix,
11809 show_bgp_view_rsclient_prefix_cmd,
11810 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11811 SHOW_STR
11812 BGP_STR
11813 "BGP view\n"
2b00515a 11814 "View name\n"
fee0f4c6 11815 "Information about Route Server Client\n"
11816 NEIGHBOR_ADDR_STR
11817 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11818{
11819 struct bgp *bgp;
11820 struct peer *peer;
11821
11822 /* BGP structure lookup. */
11823 if (argc == 3)
11824 {
11825 bgp = bgp_lookup_by_name (argv[0]);
11826 if (bgp == NULL)
11827 {
11828 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11829 return CMD_WARNING;
11830 }
11831 }
11832 else
11833 {
11834 bgp = bgp_get_default ();
11835 if (bgp == NULL)
11836 {
11837 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11838 return CMD_WARNING;
11839 }
11840 }
11841
11842 if (argc == 3)
11843 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11844 else
11845 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11846
11847 if (! peer)
11848 return CMD_WARNING;
11849
11850 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11851 {
11852 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11853 VTY_NEWLINE);
11854 return CMD_WARNING;
11855 }
11856
11857 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11858 PEER_FLAG_RSERVER_CLIENT))
11859 {
11860 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11861 VTY_NEWLINE);
11862 return CMD_WARNING;
11863 }
11864
11865 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11866 (argc == 3) ? argv[2] : argv[1],
11867 AFI_IP6, SAFI_UNICAST, NULL, 1);
11868}
11869
11870ALIAS (show_bgp_view_rsclient_prefix,
11871 show_bgp_rsclient_prefix_cmd,
11872 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11873 SHOW_STR
11874 BGP_STR
11875 "Information about Route Server Client\n"
11876 NEIGHBOR_ADDR_STR
11877 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11878
95cbbd2a
ML
11879DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11880 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11881 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11882 SHOW_STR
11883 BGP_STR
11884 "BGP view\n"
2b00515a 11885 "View name\n"
95cbbd2a
ML
11886 "Address family\n"
11887 "Address Family modifier\n"
11888 "Address Family modifier\n"
11889 "Information about Route Server Client\n"
11890 NEIGHBOR_ADDR_STR
11891 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11892{
11893 struct bgp *bgp;
11894 struct peer *peer;
11895 safi_t safi;
11896
11897 /* BGP structure lookup. */
11898 if (argc == 4)
11899 {
11900 bgp = bgp_lookup_by_name (argv[0]);
11901 if (bgp == NULL)
11902 {
11903 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11904 return CMD_WARNING;
11905 }
11906 }
11907 else
11908 {
11909 bgp = bgp_get_default ();
11910 if (bgp == NULL)
11911 {
11912 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11913 return CMD_WARNING;
11914 }
11915 }
11916
11917 if (argc == 4) {
11918 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11919 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11920 } else {
11921 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11922 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11923 }
11924
11925 if (! peer)
11926 return CMD_WARNING;
11927
11928 if (! peer->afc[AFI_IP6][safi])
11929 {
11930 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11931 VTY_NEWLINE);
11932 return CMD_WARNING;
11933}
11934
11935 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11936 PEER_FLAG_RSERVER_CLIENT))
11937{
11938 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11939 VTY_NEWLINE);
11940 return CMD_WARNING;
11941 }
11942
11943 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11944 (argc == 4) ? argv[3] : argv[2],
11945 AFI_IP6, safi, NULL, 1);
11946}
11947
11948ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11949 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11950 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11951 SHOW_STR
11952 BGP_STR
11953 "Address family\n"
11954 "Address Family modifier\n"
11955 "Address Family modifier\n"
11956 "Information about Route Server Client\n"
11957 NEIGHBOR_ADDR_STR
11958 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11959
718e3744 11960#endif /* HAVE_IPV6 */
6b0655a2 11961
718e3744 11962struct bgp_table *bgp_distance_table;
11963
11964struct bgp_distance
11965{
11966 /* Distance value for the IP source prefix. */
11967 u_char distance;
11968
11969 /* Name of the access-list to be matched. */
11970 char *access_list;
11971};
11972
94f2b392 11973static struct bgp_distance *
66e5cd87 11974bgp_distance_new (void)
718e3744 11975{
393deb9b 11976 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
718e3744 11977}
11978
94f2b392 11979static void
718e3744 11980bgp_distance_free (struct bgp_distance *bdistance)
11981{
11982 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11983}
11984
94f2b392 11985static int
fd79ac91 11986bgp_distance_set (struct vty *vty, const char *distance_str,
11987 const char *ip_str, const char *access_list_str)
718e3744 11988{
11989 int ret;
11990 struct prefix_ipv4 p;
11991 u_char distance;
11992 struct bgp_node *rn;
11993 struct bgp_distance *bdistance;
11994
11995 ret = str2prefix_ipv4 (ip_str, &p);
11996 if (ret == 0)
11997 {
11998 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11999 return CMD_WARNING;
12000 }
12001
12002 distance = atoi (distance_str);
12003
12004 /* Get BGP distance node. */
12005 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
12006 if (rn->info)
12007 {
12008 bdistance = rn->info;
12009 bgp_unlock_node (rn);
12010 }
12011 else
12012 {
12013 bdistance = bgp_distance_new ();
12014 rn->info = bdistance;
12015 }
12016
12017 /* Set distance value. */
12018 bdistance->distance = distance;
12019
12020 /* Reset access-list configuration. */
12021 if (bdistance->access_list)
12022 {
12023 free (bdistance->access_list);
12024 bdistance->access_list = NULL;
12025 }
12026 if (access_list_str)
12027 bdistance->access_list = strdup (access_list_str);
12028
12029 return CMD_SUCCESS;
12030}
12031
94f2b392 12032static int
fd79ac91 12033bgp_distance_unset (struct vty *vty, const char *distance_str,
12034 const char *ip_str, const char *access_list_str)
718e3744 12035{
12036 int ret;
12037 struct prefix_ipv4 p;
12038 u_char distance;
12039 struct bgp_node *rn;
12040 struct bgp_distance *bdistance;
12041
12042 ret = str2prefix_ipv4 (ip_str, &p);
12043 if (ret == 0)
12044 {
12045 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
12046 return CMD_WARNING;
12047 }
12048
12049 distance = atoi (distance_str);
12050
12051 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
12052 if (! rn)
12053 {
12054 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
12055 return CMD_WARNING;
12056 }
12057
12058 bdistance = rn->info;
12059
12060 if (bdistance->access_list)
12061 free (bdistance->access_list);
12062 bgp_distance_free (bdistance);
12063
12064 rn->info = NULL;
12065 bgp_unlock_node (rn);
12066 bgp_unlock_node (rn);
12067
12068 return CMD_SUCCESS;
12069}
12070
718e3744 12071/* Apply BGP information to distance method. */
12072u_char
12073bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
12074{
12075 struct bgp_node *rn;
12076 struct prefix_ipv4 q;
12077 struct peer *peer;
12078 struct bgp_distance *bdistance;
12079 struct access_list *alist;
12080 struct bgp_static *bgp_static;
12081
12082 if (! bgp)
12083 return 0;
12084
12085 if (p->family != AF_INET)
12086 return 0;
12087
12088 peer = rinfo->peer;
12089
12090 if (peer->su.sa.sa_family != AF_INET)
12091 return 0;
12092
12093 memset (&q, 0, sizeof (struct prefix_ipv4));
12094 q.family = AF_INET;
12095 q.prefix = peer->su.sin.sin_addr;
12096 q.prefixlen = IPV4_MAX_BITLEN;
12097
12098 /* Check source address. */
12099 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
12100 if (rn)
12101 {
12102 bdistance = rn->info;
12103 bgp_unlock_node (rn);
12104
12105 if (bdistance->access_list)
12106 {
12107 alist = access_list_lookup (AFI_IP, bdistance->access_list);
12108 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
12109 return bdistance->distance;
12110 }
12111 else
12112 return bdistance->distance;
12113 }
12114
12115 /* Backdoor check. */
12116 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
12117 if (rn)
12118 {
12119 bgp_static = rn->info;
12120 bgp_unlock_node (rn);
12121
12122 if (bgp_static->backdoor)
12123 {
12124 if (bgp->distance_local)
12125 return bgp->distance_local;
12126 else
12127 return ZEBRA_IBGP_DISTANCE_DEFAULT;
12128 }
12129 }
12130
6d85b15b 12131 if (peer->sort == BGP_PEER_EBGP)
718e3744 12132 {
12133 if (bgp->distance_ebgp)
12134 return bgp->distance_ebgp;
12135 return ZEBRA_EBGP_DISTANCE_DEFAULT;
12136 }
12137 else
12138 {
12139 if (bgp->distance_ibgp)
12140 return bgp->distance_ibgp;
12141 return ZEBRA_IBGP_DISTANCE_DEFAULT;
12142 }
12143}
12144
12145DEFUN (bgp_distance,
12146 bgp_distance_cmd,
12147 "distance bgp <1-255> <1-255> <1-255>",
12148 "Define an administrative distance\n"
12149 "BGP distance\n"
12150 "Distance for routes external to the AS\n"
12151 "Distance for routes internal to the AS\n"
12152 "Distance for local routes\n")
12153{
12154 struct bgp *bgp;
12155
12156 bgp = vty->index;
12157
12158 bgp->distance_ebgp = atoi (argv[0]);
12159 bgp->distance_ibgp = atoi (argv[1]);
12160 bgp->distance_local = atoi (argv[2]);
12161 return CMD_SUCCESS;
12162}
12163
12164DEFUN (no_bgp_distance,
12165 no_bgp_distance_cmd,
12166 "no distance bgp <1-255> <1-255> <1-255>",
12167 NO_STR
12168 "Define an administrative distance\n"
12169 "BGP distance\n"
12170 "Distance for routes external to the AS\n"
12171 "Distance for routes internal to the AS\n"
12172 "Distance for local routes\n")
12173{
12174 struct bgp *bgp;
12175
12176 bgp = vty->index;
12177
12178 bgp->distance_ebgp= 0;
12179 bgp->distance_ibgp = 0;
12180 bgp->distance_local = 0;
12181 return CMD_SUCCESS;
12182}
12183
12184ALIAS (no_bgp_distance,
12185 no_bgp_distance2_cmd,
12186 "no distance bgp",
12187 NO_STR
12188 "Define an administrative distance\n"
12189 "BGP distance\n")
12190
12191DEFUN (bgp_distance_source,
12192 bgp_distance_source_cmd,
12193 "distance <1-255> A.B.C.D/M",
12194 "Define an administrative distance\n"
12195 "Administrative distance\n"
12196 "IP source prefix\n")
12197{
12198 bgp_distance_set (vty, argv[0], argv[1], NULL);
12199 return CMD_SUCCESS;
12200}
12201
12202DEFUN (no_bgp_distance_source,
12203 no_bgp_distance_source_cmd,
12204 "no distance <1-255> A.B.C.D/M",
12205 NO_STR
12206 "Define an administrative distance\n"
12207 "Administrative distance\n"
12208 "IP source prefix\n")
12209{
12210 bgp_distance_unset (vty, argv[0], argv[1], NULL);
12211 return CMD_SUCCESS;
12212}
12213
12214DEFUN (bgp_distance_source_access_list,
12215 bgp_distance_source_access_list_cmd,
12216 "distance <1-255> A.B.C.D/M WORD",
12217 "Define an administrative distance\n"
12218 "Administrative distance\n"
12219 "IP source prefix\n"
12220 "Access list name\n")
12221{
12222 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
12223 return CMD_SUCCESS;
12224}
12225
12226DEFUN (no_bgp_distance_source_access_list,
12227 no_bgp_distance_source_access_list_cmd,
12228 "no distance <1-255> A.B.C.D/M WORD",
12229 NO_STR
12230 "Define an administrative distance\n"
12231 "Administrative distance\n"
12232 "IP source prefix\n"
12233 "Access list name\n")
12234{
12235 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
12236 return CMD_SUCCESS;
12237}
6b0655a2 12238
718e3744 12239DEFUN (bgp_damp_set,
12240 bgp_damp_set_cmd,
12241 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12242 "BGP Specific commands\n"
12243 "Enable route-flap dampening\n"
12244 "Half-life time for the penalty\n"
12245 "Value to start reusing a route\n"
12246 "Value to start suppressing a route\n"
12247 "Maximum duration to suppress a stable route\n")
12248{
12249 struct bgp *bgp;
12250 int half = DEFAULT_HALF_LIFE * 60;
12251 int reuse = DEFAULT_REUSE;
12252 int suppress = DEFAULT_SUPPRESS;
12253 int max = 4 * half;
12254
12255 if (argc == 4)
12256 {
12257 half = atoi (argv[0]) * 60;
12258 reuse = atoi (argv[1]);
12259 suppress = atoi (argv[2]);
12260 max = atoi (argv[3]) * 60;
12261 }
12262 else if (argc == 1)
12263 {
12264 half = atoi (argv[0]) * 60;
12265 max = 4 * half;
12266 }
12267
12268 bgp = vty->index;
12269 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
12270 half, reuse, suppress, max);
12271}
12272
12273ALIAS (bgp_damp_set,
12274 bgp_damp_set2_cmd,
12275 "bgp dampening <1-45>",
12276 "BGP Specific commands\n"
12277 "Enable route-flap dampening\n"
12278 "Half-life time for the penalty\n")
12279
12280ALIAS (bgp_damp_set,
12281 bgp_damp_set3_cmd,
12282 "bgp dampening",
12283 "BGP Specific commands\n"
12284 "Enable route-flap dampening\n")
12285
12286DEFUN (bgp_damp_unset,
12287 bgp_damp_unset_cmd,
12288 "no bgp dampening",
12289 NO_STR
12290 "BGP Specific commands\n"
12291 "Enable route-flap dampening\n")
12292{
12293 struct bgp *bgp;
12294
12295 bgp = vty->index;
12296 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12297}
12298
12299ALIAS (bgp_damp_unset,
12300 bgp_damp_unset2_cmd,
12301 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12302 NO_STR
12303 "BGP Specific commands\n"
12304 "Enable route-flap dampening\n"
12305 "Half-life time for the penalty\n"
12306 "Value to start reusing a route\n"
12307 "Value to start suppressing a route\n"
12308 "Maximum duration to suppress a stable route\n")
12309
12310DEFUN (show_ip_bgp_dampened_paths,
12311 show_ip_bgp_dampened_paths_cmd,
12312 "show ip bgp dampened-paths",
12313 SHOW_STR
12314 IP_STR
12315 BGP_STR
12316 "Display paths suppressed due to dampening\n")
12317{
5a646650 12318 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
47fc97cc 12319 NULL, NULL);
718e3744 12320}
12321
12322DEFUN (show_ip_bgp_flap_statistics,
12323 show_ip_bgp_flap_statistics_cmd,
12324 "show ip bgp flap-statistics",
12325 SHOW_STR
12326 IP_STR
12327 BGP_STR
12328 "Display flap statistics of routes\n")
12329{
5a646650 12330 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
47fc97cc 12331 bgp_show_type_flap_statistics, NULL, NULL);
718e3744 12332}
6b0655a2 12333
718e3744 12334/* Display specified route of BGP table. */
94f2b392 12335static int
fd79ac91 12336bgp_clear_damp_route (struct vty *vty, const char *view_name,
12337 const char *ip_str, afi_t afi, safi_t safi,
12338 struct prefix_rd *prd, int prefix_check)
718e3744 12339{
12340 int ret;
12341 struct prefix match;
12342 struct bgp_node *rn;
12343 struct bgp_node *rm;
12344 struct bgp_info *ri;
12345 struct bgp_info *ri_temp;
12346 struct bgp *bgp;
12347 struct bgp_table *table;
12348
12349 /* BGP structure lookup. */
12350 if (view_name)
12351 {
12352 bgp = bgp_lookup_by_name (view_name);
12353 if (bgp == NULL)
12354 {
12355 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12356 return CMD_WARNING;
12357 }
12358 }
12359 else
12360 {
12361 bgp = bgp_get_default ();
12362 if (bgp == NULL)
12363 {
12364 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12365 return CMD_WARNING;
12366 }
12367 }
12368
12369 /* Check IP address argument. */
12370 ret = str2prefix (ip_str, &match);
12371 if (! ret)
12372 {
12373 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12374 return CMD_WARNING;
12375 }
12376
12377 match.family = afi2family (afi);
12378
12379 if (safi == SAFI_MPLS_VPN)
12380 {
12381 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12382 {
12383 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12384 continue;
12385
12386 if ((table = rn->info) != NULL)
12387 if ((rm = bgp_node_match (table, &match)) != NULL)
6c88b44d
CC
12388 {
12389 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12390 {
12391 ri = rm->info;
12392 while (ri)
12393 {
12394 if (ri->extra && ri->extra->damp_info)
12395 {
12396 ri_temp = ri->next;
12397 bgp_damp_info_free (ri->extra->damp_info, 1);
12398 ri = ri_temp;
12399 }
12400 else
12401 ri = ri->next;
12402 }
12403 }
12404
12405 bgp_unlock_node (rm);
12406 }
718e3744 12407 }
12408 }
12409 else
12410 {
12411 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
6c88b44d
CC
12412 {
12413 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12414 {
12415 ri = rn->info;
12416 while (ri)
12417 {
12418 if (ri->extra && ri->extra->damp_info)
12419 {
12420 ri_temp = ri->next;
12421 bgp_damp_info_free (ri->extra->damp_info, 1);
12422 ri = ri_temp;
12423 }
12424 else
12425 ri = ri->next;
12426 }
12427 }
12428
12429 bgp_unlock_node (rn);
12430 }
718e3744 12431 }
12432
12433 return CMD_SUCCESS;
12434}
12435
12436DEFUN (clear_ip_bgp_dampening,
12437 clear_ip_bgp_dampening_cmd,
12438 "clear ip bgp dampening",
12439 CLEAR_STR
12440 IP_STR
12441 BGP_STR
12442 "Clear route flap dampening information\n")
12443{
12444 bgp_damp_info_clean ();
12445 return CMD_SUCCESS;
12446}
12447
12448DEFUN (clear_ip_bgp_dampening_prefix,
12449 clear_ip_bgp_dampening_prefix_cmd,
12450 "clear ip bgp dampening A.B.C.D/M",
12451 CLEAR_STR
12452 IP_STR
12453 BGP_STR
12454 "Clear route flap dampening information\n"
12455 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12456{
12457 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12458 SAFI_UNICAST, NULL, 1);
12459}
12460
12461DEFUN (clear_ip_bgp_dampening_address,
12462 clear_ip_bgp_dampening_address_cmd,
12463 "clear ip bgp dampening A.B.C.D",
12464 CLEAR_STR
12465 IP_STR
12466 BGP_STR
12467 "Clear route flap dampening information\n"
12468 "Network to clear damping information\n")
12469{
12470 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12471 SAFI_UNICAST, NULL, 0);
12472}
12473
12474DEFUN (clear_ip_bgp_dampening_address_mask,
12475 clear_ip_bgp_dampening_address_mask_cmd,
12476 "clear ip bgp dampening A.B.C.D A.B.C.D",
12477 CLEAR_STR
12478 IP_STR
12479 BGP_STR
12480 "Clear route flap dampening information\n"
12481 "Network to clear damping information\n"
12482 "Network mask\n")
12483{
12484 int ret;
12485 char prefix_str[BUFSIZ];
12486
12487 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12488 if (! ret)
12489 {
12490 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12491 return CMD_WARNING;
12492 }
12493
12494 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12495 SAFI_UNICAST, NULL, 0);
12496}
6b0655a2 12497
94f2b392 12498static int
718e3744 12499bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12500 afi_t afi, safi_t safi, int *write)
12501{
12502 struct bgp_node *prn;
12503 struct bgp_node *rn;
12504 struct bgp_table *table;
12505 struct prefix *p;
12506 struct prefix_rd *prd;
12507 struct bgp_static *bgp_static;
12508 u_int32_t label;
12509 char buf[SU_ADDRSTRLEN];
12510 char rdbuf[RD_ADDRSTRLEN];
12511
12512 /* Network configuration. */
12513 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12514 if ((table = prn->info) != NULL)
12515 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12516 if ((bgp_static = rn->info) != NULL)
12517 {
12518 p = &rn->p;
12519 prd = (struct prefix_rd *) &prn->p;
12520
12521 /* "address-family" display. */
12522 bgp_config_write_family_header (vty, afi, safi, write);
12523
12524 /* "network" configuration display. */
12525 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12526 label = decode_label (bgp_static->tag);
12527
12528 vty_out (vty, " network %s/%d rd %s tag %d",
12529 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12530 p->prefixlen,
12531 rdbuf, label);
12532 vty_out (vty, "%s", VTY_NEWLINE);
12533 }
12534 return 0;
12535}
12536
12537/* Configuration of static route announcement and aggregate
12538 information. */
12539int
12540bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12541 afi_t afi, safi_t safi, int *write)
12542{
12543 struct bgp_node *rn;
12544 struct prefix *p;
12545 struct bgp_static *bgp_static;
12546 struct bgp_aggregate *bgp_aggregate;
12547 char buf[SU_ADDRSTRLEN];
12548
12549 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12550 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12551
12552 /* Network configuration. */
12553 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12554 if ((bgp_static = rn->info) != NULL)
12555 {
12556 p = &rn->p;
12557
12558 /* "address-family" display. */
12559 bgp_config_write_family_header (vty, afi, safi, write);
12560
12561 /* "network" configuration display. */
12562 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12563 {
12564 u_int32_t destination;
12565 struct in_addr netmask;
12566
12567 destination = ntohl (p->u.prefix4.s_addr);
12568 masklen2ip (p->prefixlen, &netmask);
12569 vty_out (vty, " network %s",
12570 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12571
12572 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12573 || (IN_CLASSB (destination) && p->prefixlen == 16)
12574 || (IN_CLASSA (destination) && p->prefixlen == 8)
12575 || p->u.prefix4.s_addr == 0)
12576 {
12577 /* Natural mask is not display. */
12578 }
12579 else
12580 vty_out (vty, " mask %s", inet_ntoa (netmask));
12581 }
12582 else
12583 {
12584 vty_out (vty, " network %s/%d",
12585 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12586 p->prefixlen);
12587 }
12588
12589 if (bgp_static->rmap.name)
12590 vty_out (vty, " route-map %s", bgp_static->rmap.name);
41367172
PJ
12591 else
12592 {
12593 if (bgp_static->backdoor)
12594 vty_out (vty, " backdoor");
41367172 12595 }
718e3744 12596
12597 vty_out (vty, "%s", VTY_NEWLINE);
12598 }
12599
12600 /* Aggregate-address configuration. */
12601 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12602 if ((bgp_aggregate = rn->info) != NULL)
12603 {
12604 p = &rn->p;
12605
12606 /* "address-family" display. */
12607 bgp_config_write_family_header (vty, afi, safi, write);
12608
12609 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12610 {
12611 struct in_addr netmask;
12612
12613 masklen2ip (p->prefixlen, &netmask);
12614 vty_out (vty, " aggregate-address %s %s",
12615 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12616 inet_ntoa (netmask));
12617 }
12618 else
12619 {
12620 vty_out (vty, " aggregate-address %s/%d",
12621 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12622 p->prefixlen);
12623 }
12624
12625 if (bgp_aggregate->as_set)
12626 vty_out (vty, " as-set");
12627
12628 if (bgp_aggregate->summary_only)
12629 vty_out (vty, " summary-only");
12630
12631 vty_out (vty, "%s", VTY_NEWLINE);
12632 }
12633
12634 return 0;
12635}
12636
12637int
12638bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12639{
12640 struct bgp_node *rn;
12641 struct bgp_distance *bdistance;
12642
12643 /* Distance configuration. */
12644 if (bgp->distance_ebgp
12645 && bgp->distance_ibgp
12646 && bgp->distance_local
12647 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12648 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12649 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12650 vty_out (vty, " distance bgp %d %d %d%s",
12651 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12652 VTY_NEWLINE);
12653
12654 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12655 if ((bdistance = rn->info) != NULL)
12656 {
12657 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12658 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12659 bdistance->access_list ? bdistance->access_list : "",
12660 VTY_NEWLINE);
12661 }
12662
12663 return 0;
12664}
12665
12666/* Allocate routing table structure and install commands. */
12667void
66e5cd87 12668bgp_route_init (void)
718e3744 12669{
12670 /* Init BGP distance table. */
64e580a7 12671 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
718e3744 12672
12673 /* IPv4 BGP commands. */
12674 install_element (BGP_NODE, &bgp_network_cmd);
12675 install_element (BGP_NODE, &bgp_network_mask_cmd);
12676 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12677 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12678 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12679 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12680 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12681 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12682 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12683 install_element (BGP_NODE, &no_bgp_network_cmd);
12684 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12685 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12686 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12687 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12688 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12689 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12690 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12691 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12692
12693 install_element (BGP_NODE, &aggregate_address_cmd);
12694 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12695 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12696 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12697 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12698 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12699 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12700 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12701 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12702 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12703 install_element (BGP_NODE, &no_aggregate_address_cmd);
12704 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12705 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12706 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12707 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12708 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12709 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12710 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12711 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12712 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12713
12714 /* IPv4 unicast configuration. */
12715 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12716 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12717 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12718 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12719 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12720 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
c8f3fe30 12721 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
718e3744 12722 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12723 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12724 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12725 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12726 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
c8f3fe30 12727
718e3744 12728 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12729 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12730 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12731 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12732 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12733 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12734 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12735 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12736 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12737 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12738 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12739 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12740 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12741 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12742 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12743 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12744 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12745 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12746 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12747 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12748
12749 /* IPv4 multicast configuration. */
12750 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12751 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12752 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12753 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12754 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12755 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12756 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12757 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12758 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12759 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12760 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12761 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12762 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12763 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12764 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12765 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12766 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12767 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12768 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12769 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12770 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12771 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12772 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12773 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12774 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12775 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12776 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12777 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12778 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12779 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12780 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12781 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12782
12783 install_element (VIEW_NODE, &show_ip_bgp_cmd);
47fc97cc 12784 install_element (VIEW_NODE, &show_ip_bgp_csv_cmd);
718e3744 12785 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 12786 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
47fc97cc 12787 install_element (VIEW_NODE, &show_bgp_ipv4_safi_csv_cmd);
718e3744 12788 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12789 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 12790 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 12791 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12792 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12793 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12794 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
95cbbd2a 12795 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
718e3744 12796 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12797 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12798 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12799 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12800 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12801 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12802 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12803 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12804 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12805 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12806 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12807 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12808 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12809 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12810 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12811 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12812 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12813 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12814 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12815 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12816 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12817 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12818 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12819 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12820 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
12821 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12822 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12823 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12824 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12825 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
718e3744 12826 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12827 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12828 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12829 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12830 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12831 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12832 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12833 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12834 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12835 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12836 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12837 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12838 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12839 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12840 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
47fc97cc 12841 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_csv_cmd);
718e3744 12842 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12843 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12844 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
95cbbd2a 12845 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 12846 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
47fc97cc 12847 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_csv_cmd);
718e3744 12848 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12849 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12850 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12851 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12852 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12853 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12854 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12855 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12856 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12857 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12858 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12859 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12860 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12861 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12862 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
fee0f4c6 12863 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
95cbbd2a 12864 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
fee0f4c6 12865 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 12866 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
fee0f4c6 12867 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 12868 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
2a71e9ce
TP
12869 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12870 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
fee0f4c6 12871 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
95cbbd2a 12872 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
fee0f4c6 12873 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 12874 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
fee0f4c6 12875 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 12876 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
62687ff1
PJ
12877
12878 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12879 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12880 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 12881 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
62687ff1
PJ
12882 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12883 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12884 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
95cbbd2a 12885 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
62687ff1
PJ
12886 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12887 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12888 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12889 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12890 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12891 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12892 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12893 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12894 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12895 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12896 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12897 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
12898 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12899 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12900 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12901 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12902 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
62687ff1
PJ
12903 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12904 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12905 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12906 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12907 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12908 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12909 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12910 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12911 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 12912 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
62687ff1 12913 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 12914 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
62687ff1 12915 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 12916 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
62687ff1 12917 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 12918 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
718e3744 12919
12920 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
47fc97cc 12921 install_element (ENABLE_NODE, &show_ip_bgp_csv_cmd);
718e3744 12922 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 12923 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
47fc97cc 12924 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_csv_cmd);
718e3744 12925 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12926 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 12927 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 12928 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12929 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12930 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12931 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
95cbbd2a 12932 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
718e3744 12933 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12934 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12935 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12936 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12937 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12938 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12939 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12940 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12941 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12942 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12943 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12944 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12945 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12946 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12947 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12948 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12949 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12950 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12951 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12952 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12953 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12954 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12955 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12956 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12957 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
12958 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12959 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12960 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12961 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12962 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
718e3744 12963 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12964 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12965 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12966 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12967 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12968 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12969 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12970 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12971 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12972 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12973 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12974 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12975 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12976 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12977 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
47fc97cc 12978 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_csv_cmd);
718e3744 12979 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12980 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12981 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
95cbbd2a 12982 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 12983 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
47fc97cc 12984 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_csv_cmd);
718e3744 12985 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12986 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12987 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12988 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12989 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12990 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12991 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12992 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12993 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12994 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12995 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12996 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12997 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12998 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12999 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
fee0f4c6 13000 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
95cbbd2a 13001 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
fee0f4c6 13002 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 13003 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
fee0f4c6 13004 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 13005 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
2a71e9ce
TP
13006 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
13007 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
fee0f4c6 13008 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
95cbbd2a 13009 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
fee0f4c6 13010 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 13011 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
fee0f4c6 13012 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 13013 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
718e3744 13014
13015 /* BGP dampening clear commands */
13016 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
13017 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
13018 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
13019 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
13020
ff7924f6
PJ
13021 /* prefix count */
13022 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
13023 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
13024 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
718e3744 13025#ifdef HAVE_IPV6
ff7924f6
PJ
13026 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
13027
718e3744 13028 /* New config IPv6 BGP commands. */
13029 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
13030 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
13031 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
13032 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
13033
13034 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
13035 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
13036 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
13037 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
73bfe0bd
B
13038
13039 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
13040 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
718e3744 13041
13042 /* Old config IPv6 BGP commands. */
13043 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
13044 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
13045
13046 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
13047 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
13048 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
13049 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
13050
13051 install_element (VIEW_NODE, &show_bgp_cmd);
13052 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 13053 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
47fc97cc 13054 install_element (VIEW_NODE, &show_bgp_ipv6_safi_csv_cmd);
718e3744 13055 install_element (VIEW_NODE, &show_bgp_route_cmd);
13056 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 13057 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
718e3744 13058 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
13059 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 13060 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
718e3744 13061 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
13062 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
13063 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
13064 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
13065 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
13066 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
13067 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
13068 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
13069 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
13070 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
13071 install_element (VIEW_NODE, &show_bgp_community_cmd);
13072 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
13073 install_element (VIEW_NODE, &show_bgp_community2_cmd);
13074 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
13075 install_element (VIEW_NODE, &show_bgp_community3_cmd);
13076 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
13077 install_element (VIEW_NODE, &show_bgp_community4_cmd);
13078 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
13079 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
13080 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
13081 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
13082 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
13083 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
13084 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
13085 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
13086 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
13087 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
13088 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
13089 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
13090 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13091 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
13092 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13093 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
13094 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
47fc97cc
DS
13095 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_csv_cmd);
13096 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_csv_cmd);
718e3744 13097 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
13098 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13099 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
13100 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
47fc97cc
DS
13101 install_element (VIEW_NODE, &show_bgp_neighbor_routes_csv_cmd);
13102 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_csv_cmd);
718e3744 13103 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13104 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 13105 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
13106 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13107 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
13108 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
fee0f4c6 13109 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
95cbbd2a 13110 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
fee0f4c6 13111 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 13112 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
fee0f4c6 13113 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 13114 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
bb46e94f 13115 install_element (VIEW_NODE, &show_bgp_view_cmd);
13116 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
13117 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
13118 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
13119 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
13120 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
13121 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13122 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
47fc97cc
DS
13123 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_csv_cmd);
13124 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_csv_cmd);
bb46e94f 13125 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13126 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13127 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
47fc97cc 13128 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_csv_cmd);
bb46e94f 13129 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13130 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13131 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13132 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
13133 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13134 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
13135 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
fee0f4c6 13136 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
95cbbd2a 13137 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
fee0f4c6 13138 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 13139 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
fee0f4c6 13140 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 13141 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
62687ff1
PJ
13142
13143 /* Restricted:
13144 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
13145 */
13146 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
13147 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 13148 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
62687ff1
PJ
13149 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
13150 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 13151 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
62687ff1
PJ
13152 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
13153 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
13154 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
13155 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
13156 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
13157 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
13158 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
13159 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
13160 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
13161 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
13162 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
13163 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
13164 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
13165 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
13166 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
13167 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
13168 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 13169 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
62687ff1 13170 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 13171 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
62687ff1
PJ
13172 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
13173 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
13174 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
13175 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
13176 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13177 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13178 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 13179 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
62687ff1 13180 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 13181 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
718e3744 13182
13183 install_element (ENABLE_NODE, &show_bgp_cmd);
13184 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 13185 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
47fc97cc 13186 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_csv_cmd);
718e3744 13187 install_element (ENABLE_NODE, &show_bgp_route_cmd);
13188 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 13189 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
718e3744 13190 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
13191 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 13192 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
718e3744 13193 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
13194 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
13195 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
13196 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
13197 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
13198 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
13199 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
13200 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
13201 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
13202 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
13203 install_element (ENABLE_NODE, &show_bgp_community_cmd);
13204 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
13205 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
13206 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
13207 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
13208 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
13209 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
13210 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
13211 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
13212 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
13213 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
13214 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
13215 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
13216 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
13217 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
13218 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
13219 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
13220 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
13221 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
13222 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13223 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
13224 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13225 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
13226 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
47fc97cc
DS
13227 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_csv_cmd);
13228 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_csv_cmd);
718e3744 13229 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
13230 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13231 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
13232 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
47fc97cc
DS
13233 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_csv_cmd);
13234 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_csv_cmd);
718e3744 13235 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13236 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 13237 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
13238 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13239 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
13240 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
fee0f4c6 13241 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
95cbbd2a 13242 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
fee0f4c6 13243 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 13244 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
fee0f4c6 13245 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 13246 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
bb46e94f 13247 install_element (ENABLE_NODE, &show_bgp_view_cmd);
13248 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
13249 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
13250 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
13251 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
13252 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
13253 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13254 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
47fc97cc
DS
13255 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_csv_cmd);
13256 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_csv_cmd);
bb46e94f 13257 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13258 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13259 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
47fc97cc 13260 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_csv_cmd);
bb46e94f 13261 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13262 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13263 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13264 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
13265 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13266 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
13267 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
fee0f4c6 13268 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
95cbbd2a 13269 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
fee0f4c6 13270 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 13271 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
fee0f4c6 13272 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 13273 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
2815e61f
PJ
13274
13275 /* Statistics */
13276 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
13277 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
13278 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
13279 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
13280
718e3744 13281 /* old command */
13282 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
13283 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
13284 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
13285 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
13286 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
13287 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
13288 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
13289 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
13290 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
13291 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
13292 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
13293 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
13294 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
13295 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
13296 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
13297 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
13298 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13299 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13300 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
13301 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
13302 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
13303 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
13304 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13305 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
13306 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
13307 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
13308 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
13309 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
13310 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13311 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13312 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13313 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13314 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13315 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13316 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13317 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
bb46e94f 13318
718e3744 13319 /* old command */
13320 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13321 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13322 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13323 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13324 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13325 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13326 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13327 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13328 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13329 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13330 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13331 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13332 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13333 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13334 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13335 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13336 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13337 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13338 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13339 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13340 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13341 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13342 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13343 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13344 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13345 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13346 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13347 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13348 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13349 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13350 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13351 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13352 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13353 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13354 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13355 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13356
13357 /* old command */
13358 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13359 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13360 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13361 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13362
13363 /* old command */
13364 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13365 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13366 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13367 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13368
13369 /* old command */
13370 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13371 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13372 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13373 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13374#endif /* HAVE_IPV6 */
13375
13376 install_element (BGP_NODE, &bgp_distance_cmd);
13377 install_element (BGP_NODE, &no_bgp_distance_cmd);
13378 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13379 install_element (BGP_NODE, &bgp_distance_source_cmd);
13380 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13381 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13382 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13383
13384 install_element (BGP_NODE, &bgp_damp_set_cmd);
13385 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13386 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13387 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13388 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13389 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13390 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13391 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13392 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13393 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
c8f3fe30
PJ
13394
13395 /* Deprecated AS-Pathlimit commands */
13396 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13397 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13398 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13399 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13400 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13401 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13402
13403 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13404 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13405 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13406 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13407 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13408 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13409
13410 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13411 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13412 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13413 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13414 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13415 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13416
13417 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13418 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13419 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13420 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13421 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13422 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13423
13424 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13425 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13426 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13427 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13428 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13429 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13430
13431 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13432 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13433 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13434 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13435 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13436 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
3bde17f1
PJ
13437
13438#ifdef HAVE_IPV6
c8f3fe30
PJ
13439 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13440 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
3bde17f1 13441#endif
718e3744 13442}
228da428
CC
13443
13444void
13445bgp_route_finish (void)
13446{
13447 bgp_table_unlock (bgp_distance_table);
13448 bgp_distance_table = NULL;
13449}