]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_route.c
build: Quagga 0.99.23-rc1
[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"
718e3744 58
59/* Extern from bgp_dump.c */
dde72586
SH
60extern const char *bgp_origin_str[];
61extern const char *bgp_origin_long_str[];
718e3744 62\f
94f2b392 63static struct bgp_node *
fee0f4c6 64bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
718e3744 65 struct prefix_rd *prd)
66{
67 struct bgp_node *rn;
68 struct bgp_node *prn = NULL;
da5b30f6
PJ
69
70 assert (table);
71 if (!table)
72 return NULL;
73
718e3744 74 if (safi == SAFI_MPLS_VPN)
75 {
fee0f4c6 76 prn = bgp_node_get (table, (struct prefix *) prd);
718e3744 77
78 if (prn->info == NULL)
64e580a7 79 prn->info = bgp_table_init (afi, safi);
718e3744 80 else
81 bgp_unlock_node (prn);
82 table = prn->info;
83 }
718e3744 84
85 rn = bgp_node_get (table, p);
86
87 if (safi == SAFI_MPLS_VPN)
88 rn->prn = prn;
89
90 return rn;
91}
92\f
fb982c25
PJ
93/* Allocate bgp_info_extra */
94static struct bgp_info_extra *
95bgp_info_extra_new (void)
96{
97 struct bgp_info_extra *new;
98 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
99 return new;
100}
101
102static void
103bgp_info_extra_free (struct bgp_info_extra **extra)
104{
105 if (extra && *extra)
106 {
107 if ((*extra)->damp_info)
108 bgp_damp_info_free ((*extra)->damp_info, 0);
109
110 (*extra)->damp_info = NULL;
111
112 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
113
114 *extra = NULL;
115 }
116}
117
118/* Get bgp_info extra information for the given bgp_info, lazy allocated
119 * if required.
120 */
121struct bgp_info_extra *
122bgp_info_extra_get (struct bgp_info *ri)
123{
124 if (!ri->extra)
125 ri->extra = bgp_info_extra_new();
126 return ri->extra;
127}
128
718e3744 129/* Allocate new bgp info structure. */
200df115 130static struct bgp_info *
66e5cd87 131bgp_info_new (void)
718e3744 132{
393deb9b 133 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
718e3744 134}
135
136/* Free bgp route information. */
200df115 137static void
718e3744 138bgp_info_free (struct bgp_info *binfo)
139{
140 if (binfo->attr)
f6f434b2 141 bgp_attr_unintern (&binfo->attr);
fb982c25
PJ
142
143 bgp_info_extra_free (&binfo->extra);
de8d5dff 144 bgp_info_mpath_free (&binfo->mpath);
718e3744 145
200df115 146 peer_unlock (binfo->peer); /* bgp_info peer reference */
147
718e3744 148 XFREE (MTYPE_BGP_ROUTE, binfo);
149}
150
200df115 151struct bgp_info *
152bgp_info_lock (struct bgp_info *binfo)
153{
154 binfo->lock++;
155 return binfo;
156}
157
158struct bgp_info *
159bgp_info_unlock (struct bgp_info *binfo)
160{
161 assert (binfo && binfo->lock > 0);
162 binfo->lock--;
163
164 if (binfo->lock == 0)
165 {
166#if 0
167 zlog_debug ("%s: unlocked and freeing", __func__);
168 zlog_backtrace (LOG_DEBUG);
169#endif
170 bgp_info_free (binfo);
171 return NULL;
172 }
173
174#if 0
175 if (binfo->lock == 1)
176 {
177 zlog_debug ("%s: unlocked to 1", __func__);
178 zlog_backtrace (LOG_DEBUG);
179 }
180#endif
181
182 return binfo;
183}
184
718e3744 185void
186bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
187{
188 struct bgp_info *top;
189
190 top = rn->info;
200df115 191
718e3744 192 ri->next = rn->info;
193 ri->prev = NULL;
194 if (top)
195 top->prev = ri;
196 rn->info = ri;
200df115 197
198 bgp_info_lock (ri);
199 bgp_lock_node (rn);
200 peer_lock (ri->peer); /* bgp_info peer reference */
718e3744 201}
202
b40d939b 203/* Do the actual removal of info from RIB, for use by bgp_process
204 completion callback *only* */
205static void
206bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
718e3744 207{
208 if (ri->next)
209 ri->next->prev = ri->prev;
210 if (ri->prev)
211 ri->prev->next = ri->next;
212 else
213 rn->info = ri->next;
200df115 214
de8d5dff 215 bgp_info_mpath_dequeue (ri);
200df115 216 bgp_info_unlock (ri);
217 bgp_unlock_node (rn);
718e3744 218}
219
b40d939b 220void
221bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
222{
1a392d46
PJ
223 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
224 /* set of previous already took care of pcount */
b40d939b 225 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
226}
227
8d45210e
AS
228/* undo the effects of a previous call to bgp_info_delete; typically
229 called when a route is deleted and then quickly re-added before the
230 deletion has been processed */
231static void
232bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
233{
234 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
235 /* unset of previous already took care of pcount */
236 SET_FLAG (ri->flags, BGP_INFO_VALID);
237}
238
1a392d46
PJ
239/* Adjust pcount as required */
240static void
241bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
242{
67174041
AS
243 struct bgp_table *table;
244
245 assert (rn && bgp_node_table (rn));
6f58544d
PJ
246 assert (ri && ri->peer && ri->peer->bgp);
247
67174041
AS
248 table = bgp_node_table (rn);
249
1a392d46 250 /* Ignore 'pcount' for RS-client tables */
67174041 251 if (table->type != BGP_TABLE_MAIN
1a392d46
PJ
252 || ri->peer == ri->peer->bgp->peer_self)
253 return;
254
255 if (BGP_INFO_HOLDDOWN (ri)
256 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
257 {
258
259 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
260
261 /* slight hack, but more robust against errors. */
67174041
AS
262 if (ri->peer->pcount[table->afi][table->safi])
263 ri->peer->pcount[table->afi][table->safi]--;
1a392d46
PJ
264 else
265 {
266 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
267 __func__, ri->peer->host);
268 zlog_backtrace (LOG_WARNING);
269 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
270 }
271 }
272 else if (!BGP_INFO_HOLDDOWN (ri)
273 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
274 {
275 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
67174041 276 ri->peer->pcount[table->afi][table->safi]++;
1a392d46
PJ
277 }
278}
279
280
281/* Set/unset bgp_info flags, adjusting any other state as needed.
282 * This is here primarily to keep prefix-count in check.
283 */
284void
285bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
286{
287 SET_FLAG (ri->flags, flag);
288
289 /* early bath if we know it's not a flag that changes useability state */
290 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
291 return;
292
293 bgp_pcount_adjust (rn, ri);
294}
295
296void
297bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
298{
299 UNSET_FLAG (ri->flags, flag);
300
301 /* early bath if we know it's not a flag that changes useability state */
302 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
303 return;
304
305 bgp_pcount_adjust (rn, ri);
306}
307
718e3744 308/* Get MED value. If MED value is missing and "bgp bestpath
309 missing-as-worst" is specified, treat it as the worst value. */
94f2b392 310static u_int32_t
718e3744 311bgp_med_value (struct attr *attr, struct bgp *bgp)
312{
313 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
314 return attr->med;
315 else
316 {
317 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
3b424979 318 return BGP_MED_MAX;
718e3744 319 else
320 return 0;
321 }
322}
323
324/* Compare two bgp route entity. br is preferable then return 1. */
94f2b392 325static int
96450faf
JB
326bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
327 int *paths_eq)
718e3744 328{
8ff56318
JBD
329 struct attr *newattr, *existattr;
330 struct attr_extra *newattre, *existattre;
331 bgp_peer_sort_t new_sort;
332 bgp_peer_sort_t exist_sort;
718e3744 333 u_int32_t new_pref;
334 u_int32_t exist_pref;
335 u_int32_t new_med;
336 u_int32_t exist_med;
8ff56318
JBD
337 u_int32_t new_weight;
338 u_int32_t exist_weight;
339 uint32_t newm, existm;
718e3744 340 struct in_addr new_id;
341 struct in_addr exist_id;
342 int new_cluster;
343 int exist_cluster;
8ff56318
JBD
344 int internal_as_route;
345 int confed_as_route;
718e3744 346 int ret;
96450faf
JB
347
348 *paths_eq = 0;
718e3744 349
350 /* 0. Null check. */
351 if (new == NULL)
352 return 0;
353 if (exist == NULL)
354 return 1;
355
8ff56318
JBD
356 newattr = new->attr;
357 existattr = exist->attr;
358 newattre = newattr->extra;
359 existattre = existattr->extra;
360
718e3744 361 /* 1. Weight check. */
8ff56318
JBD
362 new_weight = exist_weight = 0;
363
364 if (newattre)
365 new_weight = newattre->weight;
366 if (existattre)
367 exist_weight = existattre->weight;
368
fb982c25 369 if (new_weight > exist_weight)
718e3744 370 return 1;
fb982c25 371 if (new_weight < exist_weight)
718e3744 372 return 0;
373
374 /* 2. Local preference check. */
8ff56318
JBD
375 new_pref = exist_pref = bgp->default_local_pref;
376
377 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
378 new_pref = newattr->local_pref;
379 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
380 exist_pref = existattr->local_pref;
718e3744 381
718e3744 382 if (new_pref > exist_pref)
383 return 1;
384 if (new_pref < exist_pref)
385 return 0;
386
8ff56318
JBD
387 /* 3. Local route check. We prefer:
388 * - BGP_ROUTE_STATIC
389 * - BGP_ROUTE_AGGREGATE
390 * - BGP_ROUTE_REDISTRIBUTE
391 */
392 if (! (new->sub_type == BGP_ROUTE_NORMAL))
393 return 1;
394 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
395 return 0;
718e3744 396
397 /* 4. AS path length check. */
398 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
399 {
8ff56318
JBD
400 int exist_hops = aspath_count_hops (existattr->aspath);
401 int exist_confeds = aspath_count_confeds (existattr->aspath);
fe69a505 402
6811845b 403 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
404 {
fe69a505 405 int aspath_hops;
406
8ff56318
JBD
407 aspath_hops = aspath_count_hops (newattr->aspath);
408 aspath_hops += aspath_count_confeds (newattr->aspath);
fe69a505 409
410 if ( aspath_hops < (exist_hops + exist_confeds))
6811845b 411 return 1;
fe69a505 412 if ( aspath_hops > (exist_hops + exist_confeds))
6811845b 413 return 0;
414 }
415 else
416 {
8ff56318 417 int newhops = aspath_count_hops (newattr->aspath);
fe69a505 418
419 if (newhops < exist_hops)
6811845b 420 return 1;
fe69a505 421 if (newhops > exist_hops)
6811845b 422 return 0;
423 }
718e3744 424 }
425
426 /* 5. Origin check. */
8ff56318 427 if (newattr->origin < existattr->origin)
718e3744 428 return 1;
8ff56318 429 if (newattr->origin > existattr->origin)
718e3744 430 return 0;
431
432 /* 6. MED check. */
8ff56318
JBD
433 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
434 && aspath_count_hops (existattr->aspath) == 0);
435 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
436 && aspath_count_confeds (existattr->aspath) > 0
437 && aspath_count_hops (newattr->aspath) == 0
438 && aspath_count_hops (existattr->aspath) == 0);
718e3744 439
440 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
441 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
442 && confed_as_route)
8ff56318
JBD
443 || aspath_cmp_left (newattr->aspath, existattr->aspath)
444 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
718e3744 445 || internal_as_route)
446 {
447 new_med = bgp_med_value (new->attr, bgp);
448 exist_med = bgp_med_value (exist->attr, bgp);
449
450 if (new_med < exist_med)
451 return 1;
452 if (new_med > exist_med)
453 return 0;
454 }
455
456 /* 7. Peer type check. */
8ff56318
JBD
457 new_sort = new->peer->sort;
458 exist_sort = exist->peer->sort;
459
460 if (new_sort == BGP_PEER_EBGP
461 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
718e3744 462 return 1;
8ff56318
JBD
463 if (exist_sort == BGP_PEER_EBGP
464 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
718e3744 465 return 0;
466
467 /* 8. IGP metric check. */
8ff56318
JBD
468 newm = existm = 0;
469
470 if (new->extra)
471 newm = new->extra->igpmetric;
472 if (exist->extra)
473 existm = exist->extra->igpmetric;
474
96450faf
JB
475 if (newm < existm)
476 ret = 1;
477 if (newm > existm)
478 ret = 0;
718e3744 479
480 /* 9. Maximum path check. */
96450faf
JB
481 if (newm == existm)
482 {
2fdd455c
PM
483 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
484 {
485
486 /*
487 * For the two paths, all comparison steps till IGP metric
488 * have succeeded - including AS_PATH hop count. Since 'bgp
489 * bestpath as-path multipath-relax' knob is on, we don't need
490 * an exact match of AS_PATH. Thus, mark the paths are equal.
491 * That will trigger both these paths to get into the multipath
492 * array.
493 */
494 *paths_eq = 1;
495 }
496 else if (new->peer->sort == BGP_PEER_IBGP)
96450faf
JB
497 {
498 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
499 *paths_eq = 1;
500 }
501 else if (new->peer->as == exist->peer->as)
502 *paths_eq = 1;
503 }
504 else
505 {
506 /*
507 * TODO: If unequal cost ibgp multipath is enabled we can
508 * mark the paths as equal here instead of returning
509 */
510 return ret;
511 }
718e3744 512
513 /* 10. If both paths are external, prefer the path that was received
514 first (the oldest one). This step minimizes route-flap, since a
515 newer path won't displace an older one, even if it was the
516 preferred route based on the additional decision criteria below. */
517 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
8ff56318
JBD
518 && new_sort == BGP_PEER_EBGP
519 && exist_sort == BGP_PEER_EBGP)
718e3744 520 {
521 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
522 return 1;
523 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
524 return 0;
525 }
526
527 /* 11. Rourter-ID comparision. */
8ff56318
JBD
528 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
529 new_id.s_addr = newattre->originator_id.s_addr;
718e3744 530 else
531 new_id.s_addr = new->peer->remote_id.s_addr;
8ff56318
JBD
532 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
533 exist_id.s_addr = existattre->originator_id.s_addr;
718e3744 534 else
535 exist_id.s_addr = exist->peer->remote_id.s_addr;
536
537 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
538 return 1;
539 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
540 return 0;
541
542 /* 12. Cluster length comparision. */
8ff56318
JBD
543 new_cluster = exist_cluster = 0;
544
545 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
546 new_cluster = newattre->cluster->length;
547 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
548 exist_cluster = existattre->cluster->length;
718e3744 549
550 if (new_cluster < exist_cluster)
551 return 1;
552 if (new_cluster > exist_cluster)
553 return 0;
554
555 /* 13. Neighbor address comparision. */
556 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
557
558 if (ret == 1)
559 return 0;
560 if (ret == -1)
561 return 1;
562
563 return 1;
564}
565
94f2b392 566static enum filter_type
718e3744 567bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
568 afi_t afi, safi_t safi)
569{
570 struct bgp_filter *filter;
571
572 filter = &peer->filter[afi][safi];
573
650f76c2
PJ
574#define FILTER_EXIST_WARN(F,f,filter) \
575 if (BGP_DEBUG (update, UPDATE_IN) \
576 && !(F ## _IN (filter))) \
577 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
578 peer->host, #f, F ## _IN_NAME(filter));
579
580 if (DISTRIBUTE_IN_NAME (filter)) {
581 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
582
718e3744 583 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
584 return FILTER_DENY;
650f76c2 585 }
718e3744 586
650f76c2
PJ
587 if (PREFIX_LIST_IN_NAME (filter)) {
588 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
589
718e3744 590 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
591 return FILTER_DENY;
650f76c2 592 }
718e3744 593
650f76c2
PJ
594 if (FILTER_LIST_IN_NAME (filter)) {
595 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
596
718e3744 597 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
598 return FILTER_DENY;
650f76c2
PJ
599 }
600
718e3744 601 return FILTER_PERMIT;
650f76c2 602#undef FILTER_EXIST_WARN
718e3744 603}
604
94f2b392 605static enum filter_type
718e3744 606bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
607 afi_t afi, safi_t safi)
608{
609 struct bgp_filter *filter;
610
611 filter = &peer->filter[afi][safi];
612
650f76c2
PJ
613#define FILTER_EXIST_WARN(F,f,filter) \
614 if (BGP_DEBUG (update, UPDATE_OUT) \
615 && !(F ## _OUT (filter))) \
616 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
617 peer->host, #f, F ## _OUT_NAME(filter));
618
619 if (DISTRIBUTE_OUT_NAME (filter)) {
620 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
621
718e3744 622 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
623 return FILTER_DENY;
650f76c2 624 }
718e3744 625
650f76c2
PJ
626 if (PREFIX_LIST_OUT_NAME (filter)) {
627 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
628
718e3744 629 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
630 return FILTER_DENY;
650f76c2 631 }
718e3744 632
650f76c2
PJ
633 if (FILTER_LIST_OUT_NAME (filter)) {
634 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
635
718e3744 636 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
637 return FILTER_DENY;
650f76c2 638 }
718e3744 639
640 return FILTER_PERMIT;
650f76c2 641#undef FILTER_EXIST_WARN
718e3744 642}
643
644/* If community attribute includes no_export then return 1. */
94f2b392 645static int
718e3744 646bgp_community_filter (struct peer *peer, struct attr *attr)
647{
648 if (attr->community)
649 {
650 /* NO_ADVERTISE check. */
651 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
652 return 1;
653
654 /* NO_EXPORT check. */
6d85b15b 655 if (peer->sort == BGP_PEER_EBGP &&
718e3744 656 community_include (attr->community, COMMUNITY_NO_EXPORT))
657 return 1;
658
659 /* NO_EXPORT_SUBCONFED check. */
6d85b15b
JBD
660 if (peer->sort == BGP_PEER_EBGP
661 || peer->sort == BGP_PEER_CONFED)
718e3744 662 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
663 return 1;
664 }
665 return 0;
666}
667
668/* Route reflection loop check. */
669static int
670bgp_cluster_filter (struct peer *peer, struct attr *attr)
671{
672 struct in_addr cluster_id;
673
fb982c25 674 if (attr->extra && attr->extra->cluster)
718e3744 675 {
676 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
677 cluster_id = peer->bgp->cluster_id;
678 else
679 cluster_id = peer->bgp->router_id;
680
fb982c25 681 if (cluster_loop_check (attr->extra->cluster, cluster_id))
718e3744 682 return 1;
683 }
684 return 0;
685}
686\f
94f2b392 687static int
718e3744 688bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
689 afi_t afi, safi_t safi)
690{
691 struct bgp_filter *filter;
692 struct bgp_info info;
693 route_map_result_t ret;
694
695 filter = &peer->filter[afi][safi];
696
697 /* Apply default weight value. */
fb982c25
PJ
698 if (peer->weight)
699 (bgp_attr_extra_get (attr))->weight = peer->weight;
718e3744 700
701 /* Route map apply. */
702 if (ROUTE_MAP_IN_NAME (filter))
703 {
704 /* Duplicate current value to new strucutre for modification. */
705 info.peer = peer;
706 info.attr = attr;
707
ac41b2a2 708 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
709
718e3744 710 /* Apply BGP route map to the attribute. */
711 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
ac41b2a2 712
713 peer->rmap_type = 0;
714
718e3744 715 if (ret == RMAP_DENYMATCH)
716 {
717 /* Free newly generated AS path and community by route-map. */
718 bgp_attr_flush (attr);
719 return RMAP_DENY;
720 }
721 }
722 return RMAP_PERMIT;
723}
724\f
94f2b392 725static int
fee0f4c6 726bgp_export_modifier (struct peer *rsclient, struct peer *peer,
727 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
728{
729 struct bgp_filter *filter;
730 struct bgp_info info;
731 route_map_result_t ret;
732
733 filter = &peer->filter[afi][safi];
734
735 /* Route map apply. */
736 if (ROUTE_MAP_EXPORT_NAME (filter))
737 {
738 /* Duplicate current value to new strucutre for modification. */
739 info.peer = rsclient;
740 info.attr = attr;
741
742 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
743
744 /* Apply BGP route map to the attribute. */
745 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
746
747 rsclient->rmap_type = 0;
748
749 if (ret == RMAP_DENYMATCH)
750 {
751 /* Free newly generated AS path and community by route-map. */
752 bgp_attr_flush (attr);
753 return RMAP_DENY;
754 }
755 }
756 return RMAP_PERMIT;
757}
758
94f2b392 759static int
fee0f4c6 760bgp_import_modifier (struct peer *rsclient, struct peer *peer,
761 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
762{
763 struct bgp_filter *filter;
764 struct bgp_info info;
765 route_map_result_t ret;
766
767 filter = &rsclient->filter[afi][safi];
768
769 /* Apply default weight value. */
fb982c25
PJ
770 if (peer->weight)
771 (bgp_attr_extra_get (attr))->weight = peer->weight;
fee0f4c6 772
773 /* Route map apply. */
774 if (ROUTE_MAP_IMPORT_NAME (filter))
775 {
776 /* Duplicate current value to new strucutre for modification. */
777 info.peer = peer;
778 info.attr = attr;
779
780 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
781
782 /* Apply BGP route map to the attribute. */
783 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
784
785 peer->rmap_type = 0;
786
787 if (ret == RMAP_DENYMATCH)
788 {
789 /* Free newly generated AS path and community by route-map. */
790 bgp_attr_flush (attr);
791 return RMAP_DENY;
792 }
793 }
794 return RMAP_PERMIT;
795}
796\f
94f2b392 797static int
718e3744 798bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
799 struct attr *attr, afi_t afi, safi_t safi)
800{
801 int ret;
802 char buf[SU_ADDRSTRLEN];
803 struct bgp_filter *filter;
718e3744 804 struct peer *from;
805 struct bgp *bgp;
718e3744 806 int transparent;
807 int reflect;
0b597ef0 808 struct attr *riattr;
718e3744 809
810 from = ri->peer;
811 filter = &peer->filter[afi][safi];
812 bgp = peer->bgp;
0b597ef0 813 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
718e3744 814
750e8146
PJ
815 if (DISABLE_BGP_ANNOUNCE)
816 return 0;
718e3744 817
fee0f4c6 818 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
819 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
820 return 0;
821
718e3744 822 /* Do not send back route to sender. */
823 if (from == peer)
824 return 0;
825
826 /* Aggregate-address suppress check. */
fb982c25 827 if (ri->extra && ri->extra->suppress)
718e3744 828 if (! UNSUPPRESS_MAP_NAME (filter))
829 return 0;
830
831 /* Default route check. */
832 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
833 {
834 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
835 return 0;
836#ifdef HAVE_IPV6
837 else if (p->family == AF_INET6 && p->prefixlen == 0)
838 return 0;
839#endif /* HAVE_IPV6 */
840 }
841
286e1e71 842 /* Transparency check. */
843 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
844 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
845 transparent = 1;
846 else
847 transparent = 0;
848
718e3744 849 /* If community is not disabled check the no-export and local. */
0b597ef0 850 if (! transparent && bgp_community_filter (peer, riattr))
718e3744 851 return 0;
852
853 /* If the attribute has originator-id and it is same as remote
854 peer's id. */
0b597ef0 855 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
718e3744 856 {
0b597ef0 857 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
718e3744 858 {
859 if (BGP_DEBUG (filter, FILTER))
d2c1f16b 860 zlog (peer->log, LOG_DEBUG,
718e3744 861 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
862 peer->host,
863 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
864 p->prefixlen);
865 return 0;
866 }
867 }
868
869 /* ORF prefix-list filter check */
870 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
871 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
872 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
873 if (peer->orf_plist[afi][safi])
874 {
875 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
876 return 0;
877 }
878
879 /* Output filter check. */
0b597ef0 880 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
718e3744 881 {
882 if (BGP_DEBUG (filter, FILTER))
d2c1f16b 883 zlog (peer->log, LOG_DEBUG,
718e3744 884 "%s [Update:SEND] %s/%d is filtered",
885 peer->host,
886 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
887 p->prefixlen);
888 return 0;
889 }
890
891#ifdef BGP_SEND_ASPATH_CHECK
892 /* AS path loop check. */
0b597ef0 893 if (aspath_loop_check (riattr->aspath, peer->as))
718e3744 894 {
895 if (BGP_DEBUG (filter, FILTER))
d2c1f16b 896 zlog (peer->log, LOG_DEBUG,
aea339f7 897 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
718e3744 898 peer->host, peer->as);
899 return 0;
900 }
901#endif /* BGP_SEND_ASPATH_CHECK */
902
903 /* If we're a CONFED we need to loop check the CONFED ID too */
904 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
905 {
0b597ef0 906 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
718e3744 907 {
908 if (BGP_DEBUG (filter, FILTER))
d2c1f16b 909 zlog (peer->log, LOG_DEBUG,
aea339f7 910 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
718e3744 911 peer->host,
912 bgp->confed_id);
913 return 0;
914 }
915 }
916
917 /* Route-Reflect check. */
6d85b15b 918 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
718e3744 919 reflect = 1;
920 else
921 reflect = 0;
922
923 /* IBGP reflection check. */
924 if (reflect)
925 {
926 /* A route from a Client peer. */
927 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
928 {
929 /* Reflect to all the Non-Client peers and also to the
930 Client peers other than the originator. Originator check
931 is already done. So there is noting to do. */
932 /* no bgp client-to-client reflection check. */
933 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
934 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
935 return 0;
936 }
937 else
938 {
939 /* A route from a Non-client peer. Reflect to all other
940 clients. */
941 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
942 return 0;
943 }
944 }
41367172 945
718e3744 946 /* For modify attribute, copy it to temporary structure. */
0b597ef0 947 bgp_attr_dup (attr, riattr);
fb982c25 948
718e3744 949 /* If local-preference is not set. */
6d85b15b
JBD
950 if ((peer->sort == BGP_PEER_IBGP
951 || peer->sort == BGP_PEER_CONFED)
718e3744 952 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
953 {
954 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
955 attr->local_pref = bgp->default_local_pref;
956 }
957
689bb66c
PM
958 /* If originator-id is not set and the route is to be reflected,
959 set the originator id */
960 if (peer && from && peer->sort == BGP_PEER_IBGP &&
961 from->sort == BGP_PEER_IBGP &&
962 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
963 {
964 attr->extra = bgp_attr_extra_get(attr);
965 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
966 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
967 }
968
718e3744 969 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
6d85b15b 970 if (peer->sort == BGP_PEER_EBGP
718e3744 971 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
972 {
973 if (ri->peer != bgp->peer_self && ! transparent
974 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
975 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
976 }
977
978 /* next-hop-set */
979 if (transparent || reflect
980 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
981 && ((p->family == AF_INET && attr->nexthop.s_addr)
286e1e71 982#ifdef HAVE_IPV6
fee0f4c6 983 || (p->family == AF_INET6 &&
fb982c25 984 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
286e1e71 985#endif /* HAVE_IPV6 */
986 )))
718e3744 987 {
988 /* NEXT-HOP Unchanged. */
989 }
990 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
991 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
992#ifdef HAVE_IPV6
fee0f4c6 993 || (p->family == AF_INET6 &&
fb982c25 994 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
718e3744 995#endif /* HAVE_IPV6 */
6d85b15b 996 || (peer->sort == BGP_PEER_EBGP
718e3744 997 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
998 {
999 /* Set IPv4 nexthop. */
1000 if (p->family == AF_INET)
1001 {
1002 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
1003 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1004 IPV4_MAX_BYTELEN);
718e3744 1005 else
1006 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1007 }
1008#ifdef HAVE_IPV6
1009 /* Set IPv6 nexthop. */
1010 if (p->family == AF_INET6)
1011 {
1012 /* IPv6 global nexthop must be included. */
fb982c25 1013 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
718e3744 1014 IPV6_MAX_BYTELEN);
fb982c25 1015 attr->extra->mp_nexthop_len = 16;
718e3744 1016 }
1017#endif /* HAVE_IPV6 */
1018 }
1019
1020#ifdef HAVE_IPV6
1021 if (p->family == AF_INET6)
1022 {
fee0f4c6 1023 /* Left nexthop_local unchanged if so configured. */
1024 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1025 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1026 {
fb982c25
PJ
1027 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1028 attr->extra->mp_nexthop_len=32;
fee0f4c6 1029 else
fb982c25 1030 attr->extra->mp_nexthop_len=16;
fee0f4c6 1031 }
1032
1033 /* Default nexthop_local treatment for non-RS-Clients */
1034 else
1035 {
718e3744 1036 /* Link-local address should not be transit to different peer. */
fb982c25 1037 attr->extra->mp_nexthop_len = 16;
718e3744 1038
1039 /* Set link-local address for shared network peer. */
1040 if (peer->shared_network
1041 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1042 {
fb982c25 1043 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
718e3744 1044 IPV6_MAX_BYTELEN);
fb982c25 1045 attr->extra->mp_nexthop_len = 32;
718e3744 1046 }
1047
1048 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1049 address.*/
1050 if (reflect)
fb982c25 1051 attr->extra->mp_nexthop_len = 16;
718e3744 1052
1053 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1054 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
fb982c25 1055 attr->extra->mp_nexthop_len = 16;
718e3744 1056 }
fee0f4c6 1057
1058 }
718e3744 1059#endif /* HAVE_IPV6 */
1060
1061 /* If this is EBGP peer and remove-private-AS is set. */
6d85b15b 1062 if (peer->sort == BGP_PEER_EBGP
718e3744 1063 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1064 && aspath_private_as_check (attr->aspath))
1065 attr->aspath = aspath_empty_get ();
1066
1067 /* Route map & unsuppress-map apply. */
1068 if (ROUTE_MAP_OUT_NAME (filter)
fb982c25 1069 || (ri->extra && ri->extra->suppress) )
718e3744 1070 {
7c7fa1b4 1071 struct bgp_info info;
558d1fec
JBD
1072 struct attr dummy_attr;
1073 struct attr_extra dummy_extra;
1074
1075 dummy_attr.extra = &dummy_extra;
1076
718e3744 1077 info.peer = peer;
1078 info.attr = attr;
1079
1080 /* The route reflector is not allowed to modify the attributes
1081 of the reflected IBGP routes. */
6d85b15b
JBD
1082 if (from->sort == BGP_PEER_IBGP
1083 && peer->sort == BGP_PEER_IBGP)
718e3744 1084 {
fb982c25 1085 bgp_attr_dup (&dummy_attr, attr);
9eda90ce 1086 info.attr = &dummy_attr;
718e3744 1087 }
ac41b2a2 1088
1089 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1090
fb982c25 1091 if (ri->extra && ri->extra->suppress)
718e3744 1092 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1093 else
1094 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1095
ac41b2a2 1096 peer->rmap_type = 0;
558d1fec 1097
718e3744 1098 if (ret == RMAP_DENYMATCH)
1099 {
1100 bgp_attr_flush (attr);
1101 return 0;
1102 }
1103 }
1104 return 1;
1105}
1106
94f2b392 1107static int
fee0f4c6 1108bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1109 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
1110{
1111 int ret;
1112 char buf[SU_ADDRSTRLEN];
1113 struct bgp_filter *filter;
1114 struct bgp_info info;
1115 struct peer *from;
0b597ef0 1116 struct attr *riattr;
fee0f4c6 1117
1118 from = ri->peer;
1119 filter = &rsclient->filter[afi][safi];
0b597ef0 1120 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
fee0f4c6 1121
750e8146
PJ
1122 if (DISABLE_BGP_ANNOUNCE)
1123 return 0;
fee0f4c6 1124
1125 /* Do not send back route to sender. */
1126 if (from == rsclient)
1127 return 0;
1128
1129 /* Aggregate-address suppress check. */
fb982c25 1130 if (ri->extra && ri->extra->suppress)
fee0f4c6 1131 if (! UNSUPPRESS_MAP_NAME (filter))
1132 return 0;
1133
1134 /* Default route check. */
1135 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1136 PEER_STATUS_DEFAULT_ORIGINATE))
1137 {
1138 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1139 return 0;
1140#ifdef HAVE_IPV6
1141 else if (p->family == AF_INET6 && p->prefixlen == 0)
1142 return 0;
1143#endif /* HAVE_IPV6 */
1144 }
1145
1146 /* If the attribute has originator-id and it is same as remote
1147 peer's id. */
0b597ef0 1148 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
fee0f4c6 1149 {
fb982c25 1150 if (IPV4_ADDR_SAME (&rsclient->remote_id,
0b597ef0 1151 &riattr->extra->originator_id))
fee0f4c6 1152 {
1153 if (BGP_DEBUG (filter, FILTER))
d2c1f16b 1154 zlog (rsclient->log, LOG_DEBUG,
fee0f4c6 1155 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1156 rsclient->host,
1157 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1158 p->prefixlen);
1159 return 0;
1160 }
1161 }
1162
1163 /* ORF prefix-list filter check */
1164 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1165 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1166 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1167 if (rsclient->orf_plist[afi][safi])
1168 {
1169 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1170 return 0;
1171 }
1172
1173 /* Output filter check. */
0b597ef0 1174 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
fee0f4c6 1175 {
1176 if (BGP_DEBUG (filter, FILTER))
d2c1f16b 1177 zlog (rsclient->log, LOG_DEBUG,
fee0f4c6 1178 "%s [Update:SEND] %s/%d is filtered",
1179 rsclient->host,
1180 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1181 p->prefixlen);
1182 return 0;
1183 }
1184
1185#ifdef BGP_SEND_ASPATH_CHECK
1186 /* AS path loop check. */
0b597ef0 1187 if (aspath_loop_check (riattr->aspath, rsclient->as))
fee0f4c6 1188 {
1189 if (BGP_DEBUG (filter, FILTER))
d2c1f16b 1190 zlog (rsclient->log, LOG_DEBUG,
aea339f7 1191 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
fee0f4c6 1192 rsclient->host, rsclient->as);
1193 return 0;
1194 }
1195#endif /* BGP_SEND_ASPATH_CHECK */
1196
1197 /* For modify attribute, copy it to temporary structure. */
0b597ef0 1198 bgp_attr_dup (attr, riattr);
fee0f4c6 1199
1200 /* next-hop-set */
1201 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1202#ifdef HAVE_IPV6
1203 || (p->family == AF_INET6 &&
fb982c25 1204 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
fee0f4c6 1205#endif /* HAVE_IPV6 */
1206 )
1207 {
1208 /* Set IPv4 nexthop. */
1209 if (p->family == AF_INET)
1210 {
1211 if (safi == SAFI_MPLS_VPN)
fb982c25 1212 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
fee0f4c6 1213 IPV4_MAX_BYTELEN);
1214 else
1215 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1216 }
1217#ifdef HAVE_IPV6
1218 /* Set IPv6 nexthop. */
1219 if (p->family == AF_INET6)
1220 {
1221 /* IPv6 global nexthop must be included. */
fb982c25 1222 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
fee0f4c6 1223 IPV6_MAX_BYTELEN);
fb982c25 1224 attr->extra->mp_nexthop_len = 16;
fee0f4c6 1225 }
1226#endif /* HAVE_IPV6 */
1227 }
1228
1229#ifdef HAVE_IPV6
1230 if (p->family == AF_INET6)
1231 {
fb982c25 1232 struct attr_extra *attre = attr->extra;
558d1fec 1233
fee0f4c6 1234 /* Left nexthop_local unchanged if so configured. */
1235 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1236 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1237 {
fb982c25
PJ
1238 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1239 attre->mp_nexthop_len=32;
fee0f4c6 1240 else
fb982c25 1241 attre->mp_nexthop_len=16;
fee0f4c6 1242 }
1243
1244 /* Default nexthop_local treatment for RS-Clients */
1245 else
1246 {
1247 /* Announcer and RS-Client are both in the same network */
1248 if (rsclient->shared_network && from->shared_network &&
1249 (rsclient->ifindex == from->ifindex))
1250 {
fb982c25
PJ
1251 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1252 attre->mp_nexthop_len=32;
fee0f4c6 1253 else
fb982c25 1254 attre->mp_nexthop_len=16;
fee0f4c6 1255 }
1256
1257 /* Set link-local address for shared network peer. */
1258 else if (rsclient->shared_network
1259 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1260 {
fb982c25 1261 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
fee0f4c6 1262 IPV6_MAX_BYTELEN);
fb982c25 1263 attre->mp_nexthop_len = 32;
fee0f4c6 1264 }
1265
1266 else
fb982c25 1267 attre->mp_nexthop_len = 16;
fee0f4c6 1268 }
1269
1270 }
1271#endif /* HAVE_IPV6 */
1272
1273
1274 /* If this is EBGP peer and remove-private-AS is set. */
6d85b15b 1275 if (rsclient->sort == BGP_PEER_EBGP
fee0f4c6 1276 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1277 && aspath_private_as_check (attr->aspath))
1278 attr->aspath = aspath_empty_get ();
1279
1280 /* Route map & unsuppress-map apply. */
fb982c25 1281 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
fee0f4c6 1282 {
1283 info.peer = rsclient;
1284 info.attr = attr;
1285
1286 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1287
fb982c25 1288 if (ri->extra && ri->extra->suppress)
fee0f4c6 1289 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1290 else
1291 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1292
1293 rsclient->rmap_type = 0;
1294
1295 if (ret == RMAP_DENYMATCH)
1296 {
1297 bgp_attr_flush (attr);
1298 return 0;
1299 }
1300 }
1301
1302 return 1;
1303}
1304
1305struct bgp_info_pair
1306{
1307 struct bgp_info *old;
1308 struct bgp_info *new;
1309};
1310
94f2b392 1311static void
96450faf
JB
1312bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1313 struct bgp_maxpaths_cfg *mpath_cfg,
1314 struct bgp_info_pair *result)
718e3744 1315{
718e3744 1316 struct bgp_info *new_select;
1317 struct bgp_info *old_select;
fee0f4c6 1318 struct bgp_info *ri;
718e3744 1319 struct bgp_info *ri1;
1320 struct bgp_info *ri2;
b40d939b 1321 struct bgp_info *nextri = NULL;
96450faf
JB
1322 int paths_eq, do_mpath;
1323 struct list mp_list;
1324
1325 bgp_mp_list_init (&mp_list);
1326 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1327 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1328
718e3744 1329 /* bgp deterministic-med */
1330 new_select = NULL;
1331 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1332 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1333 {
1334 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1335 continue;
1336 if (BGP_INFO_HOLDDOWN (ri1))
1337 continue;
1338
1339 new_select = ri1;
6918e74b
JB
1340 if (do_mpath)
1341 bgp_mp_list_add (&mp_list, ri1);
1342 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
718e3744 1343 if (ri1->next)
1344 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1345 {
1346 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1347 continue;
1348 if (BGP_INFO_HOLDDOWN (ri2))
1349 continue;
1350
1351 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1352 || aspath_cmp_left_confed (ri1->attr->aspath,
1353 ri2->attr->aspath))
1354 {
6918e74b
JB
1355 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1356 old_select = ri2;
96450faf 1357 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
718e3744 1358 {
1a392d46 1359 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
718e3744 1360 new_select = ri2;
6918e74b
JB
1361 if (do_mpath && !paths_eq)
1362 {
1363 bgp_mp_list_clear (&mp_list);
1364 bgp_mp_list_add (&mp_list, ri2);
1365 }
718e3744 1366 }
1367
6918e74b
JB
1368 if (do_mpath && paths_eq)
1369 bgp_mp_list_add (&mp_list, ri2);
1370
1a392d46 1371 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
718e3744 1372 }
1373 }
1a392d46
PJ
1374 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1375 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
6918e74b
JB
1376
1377 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1378 bgp_mp_list_clear (&mp_list);
718e3744 1379 }
1380
1381 /* Check old selected route and new selected route. */
1382 old_select = NULL;
1383 new_select = NULL;
b40d939b 1384 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
718e3744 1385 {
1386 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1387 old_select = ri;
1388
1389 if (BGP_INFO_HOLDDOWN (ri))
b40d939b 1390 {
1391 /* reap REMOVED routes, if needs be
1392 * selected route must stay for a while longer though
1393 */
1394 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1395 && (ri != old_select))
1396 bgp_info_reap (rn, ri);
1397
1398 continue;
1399 }
718e3744 1400
1401 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1402 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1403 {
1a392d46 1404 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
718e3744 1405 continue;
1406 }
1a392d46
PJ
1407 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1408 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
718e3744 1409
96450faf
JB
1410 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1411 {
6918e74b
JB
1412 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1413 bgp_mp_dmed_deselect (new_select);
1414
96450faf
JB
1415 new_select = ri;
1416
1417 if (do_mpath && !paths_eq)
1418 {
1419 bgp_mp_list_clear (&mp_list);
1420 bgp_mp_list_add (&mp_list, ri);
1421 }
1422 }
6918e74b
JB
1423 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1424 bgp_mp_dmed_deselect (ri);
96450faf
JB
1425
1426 if (do_mpath && paths_eq)
1427 bgp_mp_list_add (&mp_list, ri);
718e3744 1428 }
b40d939b 1429
fee0f4c6 1430
6918e74b
JB
1431 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1432 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
96450faf 1433
0b597ef0 1434 bgp_info_mpath_aggregate_update (new_select, old_select);
96450faf
JB
1435 bgp_mp_list_clear (&mp_list);
1436
1437 result->old = old_select;
1438 result->new = new_select;
1439
1440 return;
fee0f4c6 1441}
1442
94f2b392 1443static int
fee0f4c6 1444bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
9eda90ce
PJ
1445 struct bgp_node *rn, afi_t afi, safi_t safi)
1446{
fee0f4c6 1447 struct prefix *p;
558d1fec
JBD
1448 struct attr attr;
1449 struct attr_extra extra;
fee0f4c6 1450
1451 p = &rn->p;
1452
9eda90ce
PJ
1453 /* Announce route to Established peer. */
1454 if (peer->status != Established)
fee0f4c6 1455 return 0;
718e3744 1456
9eda90ce
PJ
1457 /* Address family configuration check. */
1458 if (! peer->afc_nego[afi][safi])
fee0f4c6 1459 return 0;
718e3744 1460
9eda90ce 1461 /* First update is deferred until ORF or ROUTE-REFRESH is received */
fee0f4c6 1462 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1463 PEER_STATUS_ORF_WAIT_REFRESH))
1464 return 0;
718e3744 1465
558d1fec
JBD
1466 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1467 attr.extra = &extra;
1468
67174041 1469 switch (bgp_node_table (rn)->type)
fee0f4c6 1470 {
1471 case BGP_TABLE_MAIN:
718e3744 1472 /* Announcement to peer->conf. If the route is filtered,
1473 withdraw it. */
9eda90ce
PJ
1474 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1475 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
fee0f4c6 1476 else
1477 bgp_adj_out_unset (rn, peer, p, afi, safi);
1478 break;
1479 case BGP_TABLE_RSCLIENT:
1480 /* Announcement to peer->conf. If the route is filtered,
1481 withdraw it. */
9eda90ce
PJ
1482 if (selected &&
1483 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1484 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1485 else
1486 bgp_adj_out_unset (rn, peer, p, afi, safi);
fee0f4c6 1487 break;
1488 }
558d1fec 1489
fee0f4c6 1490 return 0;
200df115 1491}
fee0f4c6 1492
200df115 1493struct bgp_process_queue
fee0f4c6 1494{
200df115 1495 struct bgp *bgp;
1496 struct bgp_node *rn;
1497 afi_t afi;
1498 safi_t safi;
1499};
1500
1501static wq_item_status
0fb58d5d 1502bgp_process_rsclient (struct work_queue *wq, void *data)
200df115 1503{
0fb58d5d 1504 struct bgp_process_queue *pq = data;
200df115 1505 struct bgp *bgp = pq->bgp;
1506 struct bgp_node *rn = pq->rn;
1507 afi_t afi = pq->afi;
1508 safi_t safi = pq->safi;
fee0f4c6 1509 struct bgp_info *new_select;
1510 struct bgp_info *old_select;
1511 struct bgp_info_pair old_and_new;
1eb8ef25 1512 struct listnode *node, *nnode;
67174041 1513 struct peer *rsclient = bgp_node_table (rn)->owner;
200df115 1514
fee0f4c6 1515 /* Best path selection. */
96450faf 1516 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 1517 new_select = old_and_new.new;
1518 old_select = old_and_new.old;
1519
200df115 1520 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1521 {
228da428
CC
1522 if (rsclient->group)
1523 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1524 {
1525 /* Nothing to do. */
1526 if (old_select && old_select == new_select)
1527 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1528 continue;
1529
1530 if (old_select)
1531 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1532 if (new_select)
1533 {
1534 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1535 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d
JB
1536 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1537 }
228da428
CC
1538
1539 bgp_process_announce_selected (rsclient, new_select, rn,
1540 afi, safi);
1541 }
200df115 1542 }
1543 else
1544 {
b7395791 1545 if (old_select)
1a392d46 1546 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
b7395791 1547 if (new_select)
1548 {
1a392d46
PJ
1549 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1550 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 1551 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
b7395791 1552 }
9eda90ce 1553 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
200df115 1554 }
1555
b40d939b 1556 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1557 bgp_info_reap (rn, old_select);
1558
200df115 1559 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1560 return WQ_SUCCESS;
fee0f4c6 1561}
1562
200df115 1563static wq_item_status
0fb58d5d 1564bgp_process_main (struct work_queue *wq, void *data)
200df115 1565{
0fb58d5d 1566 struct bgp_process_queue *pq = data;
200df115 1567 struct bgp *bgp = pq->bgp;
1568 struct bgp_node *rn = pq->rn;
1569 afi_t afi = pq->afi;
1570 safi_t safi = pq->safi;
1571 struct prefix *p = &rn->p;
fee0f4c6 1572 struct bgp_info *new_select;
1573 struct bgp_info *old_select;
1574 struct bgp_info_pair old_and_new;
1eb8ef25 1575 struct listnode *node, *nnode;
fee0f4c6 1576 struct peer *peer;
fb982c25 1577
fee0f4c6 1578 /* Best path selection. */
96450faf 1579 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
fee0f4c6 1580 old_select = old_and_new.old;
1581 new_select = old_and_new.new;
1582
1583 /* Nothing to do. */
1584 if (old_select && old_select == new_select)
1585 {
1586 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
200df115 1587 {
8196f13d
JB
1588 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1589 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
5a616c08 1590 bgp_zebra_announce (p, old_select, bgp, safi);
200df115 1591
8196f13d 1592 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
200df115 1593 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1594 return WQ_SUCCESS;
1595 }
fee0f4c6 1596 }
1597
338b3424 1598 if (old_select)
1a392d46 1599 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
338b3424 1600 if (new_select)
1601 {
1a392d46
PJ
1602 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1603 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
8196f13d 1604 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
338b3424 1605 }
1606
1607
fee0f4c6 1608 /* Check each BGP peer. */
1eb8ef25 1609 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
fee0f4c6 1610 {
9eda90ce 1611 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
718e3744 1612 }
1613
1614 /* FIB update. */
5a616c08
B
1615 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1616 ! bgp_option_check (BGP_OPT_NO_FIB)))
718e3744 1617 {
1618 if (new_select
1619 && new_select->type == ZEBRA_ROUTE_BGP
1620 && new_select->sub_type == BGP_ROUTE_NORMAL)
5a616c08 1621 bgp_zebra_announce (p, new_select, bgp, safi);
718e3744 1622 else
1623 {
1624 /* Withdraw the route from the kernel. */
1625 if (old_select
1626 && old_select->type == ZEBRA_ROUTE_BGP
1627 && old_select->sub_type == BGP_ROUTE_NORMAL)
5a616c08 1628 bgp_zebra_withdraw (p, old_select, safi);
718e3744 1629 }
1630 }
b40d939b 1631
1632 /* Reap old select bgp_info, it it has been removed */
1633 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1634 bgp_info_reap (rn, old_select);
1635
200df115 1636 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1637 return WQ_SUCCESS;
718e3744 1638}
1639
200df115 1640static void
0fb58d5d 1641bgp_processq_del (struct work_queue *wq, void *data)
200df115 1642{
0fb58d5d 1643 struct bgp_process_queue *pq = data;
67174041 1644 struct bgp_table *table = bgp_node_table (pq->rn);
0fb58d5d 1645
228da428 1646 bgp_unlock (pq->bgp);
200df115 1647 bgp_unlock_node (pq->rn);
228da428 1648 bgp_table_unlock (table);
200df115 1649 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1650}
1651
1652static void
1653bgp_process_queue_init (void)
1654{
1655 bm->process_main_queue
1656 = work_queue_new (bm->master, "process_main_queue");
1657 bm->process_rsclient_queue
1658 = work_queue_new (bm->master, "process_rsclient_queue");
1659
1660 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1661 {
1662 zlog_err ("%s: Failed to allocate work queue", __func__);
1663 exit (1);
1664 }
1665
1666 bm->process_main_queue->spec.workfunc = &bgp_process_main;
200df115 1667 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
838bbde0
PJ
1668 bm->process_main_queue->spec.max_retries = 0;
1669 bm->process_main_queue->spec.hold = 50;
1670
1671 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1672 sizeof (struct work_queue *));
1673 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
200df115 1674}
1675
1676void
fee0f4c6 1677bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1678{
200df115 1679 struct bgp_process_queue *pqnode;
1680
1681 /* already scheduled for processing? */
1682 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1683 return;
1684
1685 if ( (bm->process_main_queue == NULL) ||
1686 (bm->process_rsclient_queue == NULL) )
1687 bgp_process_queue_init ();
1688
1689 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1690 sizeof (struct bgp_process_queue));
1691 if (!pqnode)
1692 return;
228da428
CC
1693
1694 /* all unlocked in bgp_processq_del */
67174041 1695 bgp_table_lock (bgp_node_table (rn));
228da428 1696 pqnode->rn = bgp_lock_node (rn);
200df115 1697 pqnode->bgp = bgp;
228da428 1698 bgp_lock (bgp);
200df115 1699 pqnode->afi = afi;
1700 pqnode->safi = safi;
1701
67174041 1702 switch (bgp_node_table (rn)->type)
fee0f4c6 1703 {
200df115 1704 case BGP_TABLE_MAIN:
1705 work_queue_add (bm->process_main_queue, pqnode);
1706 break;
1707 case BGP_TABLE_RSCLIENT:
1708 work_queue_add (bm->process_rsclient_queue, pqnode);
1709 break;
fee0f4c6 1710 }
200df115 1711
07ff4dc4 1712 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
200df115 1713 return;
fee0f4c6 1714}
0a486e5f 1715
94f2b392 1716static int
0a486e5f 1717bgp_maximum_prefix_restart_timer (struct thread *thread)
1718{
1719 struct peer *peer;
1720
1721 peer = THREAD_ARG (thread);
1722 peer->t_pmax_restart = NULL;
1723
1724 if (BGP_DEBUG (events, EVENTS))
1725 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1726 peer->host);
1727
1728 peer_clear (peer);
1729
1730 return 0;
1731}
1732
718e3744 1733int
5228ad27 1734bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1735 safi_t safi, int always)
718e3744 1736{
e0701b79 1737 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1738 return 0;
1739
1740 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
718e3744 1741 {
e0701b79 1742 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1743 && ! always)
1744 return 0;
1745
1746 zlog (peer->log, LOG_INFO,
0a486e5f 1747 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1748 "limit %ld", afi_safi_print (afi, safi), peer->host,
1749 peer->pcount[afi][safi], peer->pmax[afi][safi]);
e0701b79 1750 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1751
1752 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1753 return 0;
1754
1755 {
5228ad27 1756 u_int8_t ndata[7];
e0701b79 1757
1758 if (safi == SAFI_MPLS_VPN)
42e6d745 1759 safi = SAFI_MPLS_LABELED_VPN;
5228ad27 1760
1761 ndata[0] = (afi >> 8);
1762 ndata[1] = afi;
1763 ndata[2] = safi;
1764 ndata[3] = (peer->pmax[afi][safi] >> 24);
1765 ndata[4] = (peer->pmax[afi][safi] >> 16);
1766 ndata[5] = (peer->pmax[afi][safi] >> 8);
1767 ndata[6] = (peer->pmax[afi][safi]);
e0701b79 1768
1769 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1770 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1771 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1772 }
0a486e5f 1773
1774 /* restart timer start */
1775 if (peer->pmax_restart[afi][safi])
1776 {
1777 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1778
1779 if (BGP_DEBUG (events, EVENTS))
1780 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1781 peer->host, peer->v_pmax_restart);
1782
1783 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1784 peer->v_pmax_restart);
1785 }
1786
e0701b79 1787 return 1;
1788 }
1789 else
1790 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1791
1792 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1793 {
1794 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1795 && ! always)
1796 return 0;
1797
1798 zlog (peer->log, LOG_INFO,
0a486e5f 1799 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1800 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1801 peer->pmax[afi][safi]);
e0701b79 1802 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 1803 }
e0701b79 1804 else
1805 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
718e3744 1806 return 0;
1807}
1808
b40d939b 1809/* Unconditionally remove the route from the RIB, without taking
1810 * damping into consideration (eg, because the session went down)
1811 */
94f2b392 1812static void
718e3744 1813bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1814 afi_t afi, safi_t safi)
1815{
902212c3 1816 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1817
1818 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1819 bgp_info_delete (rn, ri); /* keep historical info */
1820
b40d939b 1821 bgp_process (peer->bgp, rn, afi, safi);
718e3744 1822}
1823
94f2b392 1824static void
718e3744 1825bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
b40d939b 1826 afi_t afi, safi_t safi)
718e3744 1827{
718e3744 1828 int status = BGP_DAMP_NONE;
1829
b40d939b 1830 /* apply dampening, if result is suppressed, we'll be retaining
1831 * the bgp_info in the RIB for historical reference.
1832 */
1833 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 1834 && peer->sort == BGP_PEER_EBGP)
b40d939b 1835 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1836 == BGP_DAMP_SUPPRESSED)
902212c3 1837 {
902212c3 1838 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1839 return;
1840 }
1841
1842 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 1843}
1844
94f2b392 1845static void
fee0f4c6 1846bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1847 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1848 int sub_type, struct prefix_rd *prd, u_char *tag)
1849{
1850 struct bgp_node *rn;
1851 struct bgp *bgp;
558d1fec
JBD
1852 struct attr new_attr;
1853 struct attr_extra new_extra;
fee0f4c6 1854 struct attr *attr_new;
1855 struct attr *attr_new2;
1856 struct bgp_info *ri;
1857 struct bgp_info *new;
fd79ac91 1858 const char *reason;
fee0f4c6 1859 char buf[SU_ADDRSTRLEN];
1860
1861 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1862 if (peer == rsclient)
1863 return;
1864
1865 bgp = peer->bgp;
1866 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1867
1868 /* Check previously received route. */
1869 for (ri = rn->info; ri; ri = ri->next)
1870 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1871 break;
1872
1873 /* AS path loop check. */
000e157c 1874 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
fee0f4c6 1875 {
1876 reason = "as-path contains our own AS;";
1877 goto filtered;
1878 }
1879
1880 /* Route reflector originator ID check. */
1881 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 1882 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
fee0f4c6 1883 {
1884 reason = "originator is us;";
1885 goto filtered;
1886 }
fb982c25 1887
558d1fec 1888 new_attr.extra = &new_extra;
fb982c25 1889 bgp_attr_dup (&new_attr, attr);
fee0f4c6 1890
1891 /* Apply export policy. */
1892 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1893 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1894 {
1895 reason = "export-policy;";
1896 goto filtered;
1897 }
1898
1899 attr_new2 = bgp_attr_intern (&new_attr);
fb982c25 1900
fee0f4c6 1901 /* Apply import policy. */
1902 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1903 {
f6f434b2 1904 bgp_attr_unintern (&attr_new2);
fee0f4c6 1905
1906 reason = "import-policy;";
1907 goto filtered;
1908 }
1909
1910 attr_new = bgp_attr_intern (&new_attr);
f6f434b2 1911 bgp_attr_unintern (&attr_new2);
fee0f4c6 1912
1913 /* IPv4 unicast next hop check. */
5a616c08 1914 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
fee0f4c6 1915 {
733cd9e5 1916 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
fee0f4c6 1917 if (new_attr.nexthop.s_addr == 0
733cd9e5 1918 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
fee0f4c6 1919 {
f6f434b2 1920 bgp_attr_unintern (&attr_new);
fee0f4c6 1921
1922 reason = "martian next-hop;";
1923 goto filtered;
1924 }
1925 }
558d1fec 1926
fee0f4c6 1927 /* If the update is implicit withdraw. */
1928 if (ri)
1929 {
65957886 1930 ri->uptime = bgp_clock ();
fee0f4c6 1931
1932 /* Same attribute comes in. */
16d2e241
PJ
1933 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1934 && attrhash_cmp (ri->attr, attr_new))
fee0f4c6 1935 {
1936
1a392d46 1937 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
fee0f4c6 1938
1939 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 1940 zlog (peer->log, LOG_DEBUG,
fee0f4c6 1941 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1942 peer->host,
1943 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1944 p->prefixlen, rsclient->host);
1945
228da428 1946 bgp_unlock_node (rn);
f6f434b2 1947 bgp_attr_unintern (&attr_new);
fee0f4c6 1948
228da428 1949 return;
fee0f4c6 1950 }
1951
16d2e241
PJ
1952 /* Withdraw/Announce before we fully processed the withdraw */
1953 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1954 bgp_info_restore (rn, ri);
1955
fee0f4c6 1956 /* Received Logging. */
1957 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 1958 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
fee0f4c6 1959 peer->host,
1960 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1961 p->prefixlen, rsclient->host);
1962
1963 /* The attribute is changed. */
1a392d46 1964 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
fee0f4c6 1965
1966 /* Update to new attribute. */
f6f434b2 1967 bgp_attr_unintern (&ri->attr);
fee0f4c6 1968 ri->attr = attr_new;
1969
1970 /* Update MPLS tag. */
1971 if (safi == SAFI_MPLS_VPN)
fb982c25 1972 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
fee0f4c6 1973
1a392d46 1974 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
fee0f4c6 1975
1976 /* Process change. */
1977 bgp_process (bgp, rn, afi, safi);
1978 bgp_unlock_node (rn);
1979
1980 return;
1981 }
1982
1983 /* Received Logging. */
1984 if (BGP_DEBUG (update, UPDATE_IN))
1985 {
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
1992 /* Make new BGP info. */
1993 new = bgp_info_new ();
1994 new->type = type;
1995 new->sub_type = sub_type;
1996 new->peer = peer;
1997 new->attr = attr_new;
65957886 1998 new->uptime = bgp_clock ();
fee0f4c6 1999
2000 /* Update MPLS tag. */
2001 if (safi == SAFI_MPLS_VPN)
fb982c25 2002 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
fee0f4c6 2003
1a392d46 2004 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
fee0f4c6 2005
2006 /* Register new BGP information. */
2007 bgp_info_add (rn, new);
200df115 2008
2009 /* route_node_get lock */
2010 bgp_unlock_node (rn);
2011
fee0f4c6 2012 /* Process change. */
2013 bgp_process (bgp, rn, afi, safi);
558d1fec 2014
fee0f4c6 2015 return;
2016
2017 filtered:
2018
2019 /* This BGP update is filtered. Log the reason then update BGP entry. */
2020 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 2021 zlog (peer->log, LOG_DEBUG,
fee0f4c6 2022 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2023 peer->host,
2024 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2025 p->prefixlen, rsclient->host, reason);
2026
2027 if (ri)
b40d939b 2028 bgp_rib_remove (rn, ri, peer, afi, safi);
fee0f4c6 2029
2030 bgp_unlock_node (rn);
558d1fec 2031
fee0f4c6 2032 return;
2033}
2034
94f2b392 2035static void
fee0f4c6 2036bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2037 struct peer *peer, struct prefix *p, int type, int sub_type,
2038 struct prefix_rd *prd, u_char *tag)
228da428 2039{
fee0f4c6 2040 struct bgp_node *rn;
2041 struct bgp_info *ri;
2042 char buf[SU_ADDRSTRLEN];
2043
2044 if (rsclient == peer)
228da428 2045 return;
fee0f4c6 2046
2047 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2048
2049 /* Lookup withdrawn route. */
2050 for (ri = rn->info; ri; ri = ri->next)
2051 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2052 break;
2053
2054 /* Withdraw specified route from routing table. */
2055 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
b40d939b 2056 bgp_rib_withdraw (rn, ri, peer, afi, safi);
fee0f4c6 2057 else if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 2058 zlog (peer->log, LOG_DEBUG,
fee0f4c6 2059 "%s Can't find the route %s/%d", peer->host,
2060 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2061 p->prefixlen);
2062
2063 /* Unlock bgp_node_get() lock. */
228da428
CC
2064 bgp_unlock_node (rn);
2065}
fee0f4c6 2066
94f2b392 2067static int
fee0f4c6 2068bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
718e3744 2069 afi_t afi, safi_t safi, int type, int sub_type,
2070 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2071{
2072 int ret;
2073 int aspath_loop_count = 0;
2074 struct bgp_node *rn;
2075 struct bgp *bgp;
558d1fec
JBD
2076 struct attr new_attr;
2077 struct attr_extra new_extra;
718e3744 2078 struct attr *attr_new;
2079 struct bgp_info *ri;
2080 struct bgp_info *new;
fd79ac91 2081 const char *reason;
718e3744 2082 char buf[SU_ADDRSTRLEN];
2083
2084 bgp = peer->bgp;
fee0f4c6 2085 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
fb982c25 2086
718e3744 2087 /* When peer's soft reconfiguration enabled. Record input packet in
2088 Adj-RIBs-In. */
343aa822
JBD
2089 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2090 && peer != bgp->peer_self)
718e3744 2091 bgp_adj_in_set (rn, peer, attr);
2092
2093 /* Check previously received route. */
2094 for (ri = rn->info; ri; ri = ri->next)
2095 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2096 break;
2097
2098 /* AS path local-as loop check. */
2099 if (peer->change_local_as)
2100 {
2101 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2102 aspath_loop_count = 1;
2103
2104 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2105 {
2106 reason = "as-path contains our own AS;";
2107 goto filtered;
2108 }
2109 }
2110
2111 /* AS path loop check. */
2112 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2113 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2114 && aspath_loop_check(attr->aspath, bgp->confed_id)
2115 > peer->allowas_in[afi][safi]))
2116 {
2117 reason = "as-path contains our own AS;";
2118 goto filtered;
2119 }
2120
2121 /* Route reflector originator ID check. */
2122 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
fb982c25 2123 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
718e3744 2124 {
2125 reason = "originator is us;";
2126 goto filtered;
2127 }
2128
2129 /* Route reflector cluster ID check. */
2130 if (bgp_cluster_filter (peer, attr))
2131 {
2132 reason = "reflected from the same cluster;";
2133 goto filtered;
2134 }
2135
2136 /* Apply incoming filter. */
2137 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2138 {
2139 reason = "filter;";
2140 goto filtered;
2141 }
2142
558d1fec 2143 new_attr.extra = &new_extra;
fb982c25 2144 bgp_attr_dup (&new_attr, attr);
718e3744 2145
558d1fec 2146 /* Apply incoming route-map. */
718e3744 2147 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2148 {
2149 reason = "route-map;";
2150 goto filtered;
2151 }
2152
2153 /* IPv4 unicast next hop check. */
2154 if (afi == AFI_IP && safi == SAFI_UNICAST)
2155 {
2156 /* If the peer is EBGP and nexthop is not on connected route,
2157 discard it. */
6d85b15b 2158 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
8e80bdf2 2159 && ! bgp_nexthop_onlink (afi, &new_attr)
6ffd2079 2160 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
718e3744 2161 {
2162 reason = "non-connected next-hop;";
2163 goto filtered;
2164 }
2165
733cd9e5 2166 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
718e3744 2167 must not be my own address. */
10f9bf3f
JBD
2168 if (new_attr.nexthop.s_addr == 0
2169 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2170 || bgp_nexthop_self (&new_attr))
718e3744 2171 {
2172 reason = "martian next-hop;";
2173 goto filtered;
2174 }
2175 }
2176
2177 attr_new = bgp_attr_intern (&new_attr);
2178
2179 /* If the update is implicit withdraw. */
2180 if (ri)
2181 {
65957886 2182 ri->uptime = bgp_clock ();
718e3744 2183
2184 /* Same attribute comes in. */
16d2e241
PJ
2185 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2186 && attrhash_cmp (ri->attr, attr_new))
718e3744 2187 {
1a392d46 2188 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 2189
2190 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2191 && peer->sort == BGP_PEER_EBGP
718e3744 2192 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2193 {
2194 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 2195 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
718e3744 2196 peer->host,
2197 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2198 p->prefixlen);
2199
902212c3 2200 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2201 {
2202 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2203 bgp_process (bgp, rn, afi, safi);
2204 }
718e3744 2205 }
16d2e241 2206 else /* Duplicate - odd */
718e3744 2207 {
2208 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 2209 zlog (peer->log, LOG_DEBUG,
718e3744 2210 "%s rcvd %s/%d...duplicate ignored",
2211 peer->host,
2212 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2213 p->prefixlen);
93406d87 2214
2215 /* graceful restart STALE flag unset. */
2216 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2217 {
1a392d46 2218 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
902212c3 2219 bgp_process (bgp, rn, afi, safi);
93406d87 2220 }
718e3744 2221 }
2222
2223 bgp_unlock_node (rn);
f6f434b2 2224 bgp_attr_unintern (&attr_new);
558d1fec 2225
718e3744 2226 return 0;
2227 }
2228
16d2e241
PJ
2229 /* Withdraw/Announce before we fully processed the withdraw */
2230 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2231 {
2232 if (BGP_DEBUG (update, UPDATE_IN))
2233 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2234 peer->host,
2235 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2236 p->prefixlen);
2237 bgp_info_restore (rn, ri);
2238 }
2239
718e3744 2240 /* Received Logging. */
2241 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 2242 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
718e3744 2243 peer->host,
2244 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2245 p->prefixlen);
2246
93406d87 2247 /* graceful restart STALE flag unset. */
2248 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1a392d46 2249 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
93406d87 2250
718e3744 2251 /* The attribute is changed. */
1a392d46 2252 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
902212c3 2253
2254 /* implicit withdraw, decrement aggregate and pcount here.
2255 * only if update is accepted, they'll increment below.
2256 */
902212c3 2257 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2258
718e3744 2259 /* Update bgp route dampening information. */
2260 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2261 && peer->sort == BGP_PEER_EBGP)
718e3744 2262 {
2263 /* This is implicit withdraw so we should update dampening
2264 information. */
2265 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2266 bgp_damp_withdraw (ri, rn, afi, safi, 1);
718e3744 2267 }
2268
718e3744 2269 /* Update to new attribute. */
f6f434b2 2270 bgp_attr_unintern (&ri->attr);
718e3744 2271 ri->attr = attr_new;
2272
2273 /* Update MPLS tag. */
2274 if (safi == SAFI_MPLS_VPN)
fb982c25 2275 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
718e3744 2276
2277 /* Update bgp route dampening information. */
2278 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
6d85b15b 2279 && peer->sort == BGP_PEER_EBGP)
718e3744 2280 {
2281 /* Now we do normal update dampening. */
2282 ret = bgp_damp_update (ri, rn, afi, safi);
2283 if (ret == BGP_DAMP_SUPPRESSED)
2284 {
2285 bgp_unlock_node (rn);
2286 return 0;
2287 }
2288 }
2289
2290 /* Nexthop reachability check. */
2291 if ((afi == AFI_IP || afi == AFI_IP6)
2292 && safi == SAFI_UNICAST
6d85b15b
JBD
2293 && (peer->sort == BGP_PEER_IBGP
2294 || peer->sort == BGP_PEER_CONFED
2295 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
6ffd2079 2296 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
718e3744 2297 {
2298 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
1a392d46 2299 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 2300 else
1a392d46 2301 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
718e3744 2302 }
2303 else
1a392d46 2304 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
718e3744 2305
2306 /* Process change. */
2307 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2308
2309 bgp_process (bgp, rn, afi, safi);
2310 bgp_unlock_node (rn);
558d1fec 2311
718e3744 2312 return 0;
2313 }
2314
2315 /* Received Logging. */
2316 if (BGP_DEBUG (update, UPDATE_IN))
2317 {
d2c1f16b 2318 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
718e3744 2319 peer->host,
2320 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2321 p->prefixlen);
2322 }
2323
718e3744 2324 /* Make new BGP info. */
2325 new = bgp_info_new ();
2326 new->type = type;
2327 new->sub_type = sub_type;
2328 new->peer = peer;
2329 new->attr = attr_new;
65957886 2330 new->uptime = bgp_clock ();
718e3744 2331
2332 /* Update MPLS tag. */
2333 if (safi == SAFI_MPLS_VPN)
fb982c25 2334 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
718e3744 2335
2336 /* Nexthop reachability check. */
2337 if ((afi == AFI_IP || afi == AFI_IP6)
2338 && safi == SAFI_UNICAST
6d85b15b
JBD
2339 && (peer->sort == BGP_PEER_IBGP
2340 || peer->sort == BGP_PEER_CONFED
2341 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
6ffd2079 2342 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
718e3744 2343 {
2344 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
1a392d46 2345 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 2346 else
1a392d46 2347 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
718e3744 2348 }
2349 else
1a392d46 2350 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
718e3744 2351
902212c3 2352 /* Increment prefix */
718e3744 2353 bgp_aggregate_increment (bgp, p, new, afi, safi);
2354
2355 /* Register new BGP information. */
2356 bgp_info_add (rn, new);
200df115 2357
2358 /* route_node_get lock */
2359 bgp_unlock_node (rn);
558d1fec 2360
718e3744 2361 /* If maximum prefix count is configured and current prefix
2362 count exeed it. */
e0701b79 2363 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2364 return -1;
718e3744 2365
2366 /* Process change. */
2367 bgp_process (bgp, rn, afi, safi);
2368
2369 return 0;
2370
2371 /* This BGP update is filtered. Log the reason then update BGP
2372 entry. */
2373 filtered:
2374 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 2375 zlog (peer->log, LOG_DEBUG,
718e3744 2376 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2377 peer->host,
2378 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2379 p->prefixlen, reason);
2380
2381 if (ri)
b40d939b 2382 bgp_rib_remove (rn, ri, peer, afi, safi);
718e3744 2383
2384 bgp_unlock_node (rn);
558d1fec 2385
718e3744 2386 return 0;
2387}
2388
fee0f4c6 2389int
2390bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2391 afi_t afi, safi_t safi, int type, int sub_type,
2392 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2393{
2394 struct peer *rsclient;
1eb8ef25 2395 struct listnode *node, *nnode;
fee0f4c6 2396 struct bgp *bgp;
2397 int ret;
2398
2399 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2400 soft_reconfig);
2401
2402 bgp = peer->bgp;
2403
2404 /* Process the update for each RS-client. */
1eb8ef25 2405 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 2406 {
2407 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2408 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2409 sub_type, prd, tag);
2410 }
2411
2412 return ret;
2413}
2414
718e3744 2415int
2416bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
94f2b392 2417 afi_t afi, safi_t safi, int type, int sub_type,
2418 struct prefix_rd *prd, u_char *tag)
718e3744 2419{
2420 struct bgp *bgp;
2421 char buf[SU_ADDRSTRLEN];
2422 struct bgp_node *rn;
2423 struct bgp_info *ri;
fee0f4c6 2424 struct peer *rsclient;
1eb8ef25 2425 struct listnode *node, *nnode;
718e3744 2426
2427 bgp = peer->bgp;
2428
fee0f4c6 2429 /* Process the withdraw for each RS-client. */
1eb8ef25 2430 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 2431 {
2432 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2433 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2434 }
2435
718e3744 2436 /* Logging. */
2437 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 2438 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
718e3744 2439 peer->host,
2440 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2441 p->prefixlen);
2442
2443 /* Lookup node. */
fee0f4c6 2444 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 2445
2446 /* If peer is soft reconfiguration enabled. Record input packet for
2447 further calculation. */
2448 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2449 && peer != bgp->peer_self)
2450 bgp_adj_in_unset (rn, peer);
2451
2452 /* Lookup withdrawn route. */
2453 for (ri = rn->info; ri; ri = ri->next)
2454 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2455 break;
2456
2457 /* Withdraw specified route from routing table. */
2458 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
b40d939b 2459 bgp_rib_withdraw (rn, ri, peer, afi, safi);
718e3744 2460 else if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 2461 zlog (peer->log, LOG_DEBUG,
718e3744 2462 "%s Can't find the route %s/%d", peer->host,
2463 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2464 p->prefixlen);
2465
2466 /* Unlock bgp_node_get() lock. */
2467 bgp_unlock_node (rn);
2468
2469 return 0;
2470}
2471\f
2472void
2473bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2474{
2475 struct bgp *bgp;
e16a4133 2476 struct attr attr;
577ac57b 2477 struct aspath *aspath;
718e3744 2478 struct prefix p;
718e3744 2479 struct peer *from;
dcab1bb8
CF
2480 struct bgp_node *rn;
2481 struct bgp_info *ri;
718e3744 2482 int ret = RMAP_DENYMATCH;
fb982c25 2483
b2497024 2484 if (!(afi == AFI_IP || afi == AFI_IP6))
fb982c25
PJ
2485 return;
2486
718e3744 2487 bgp = peer->bgp;
2488 from = bgp->peer_self;
fb982c25 2489
718e3744 2490 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2491 aspath = attr.aspath;
2492 attr.local_pref = bgp->default_local_pref;
2493 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2494
2495 if (afi == AFI_IP)
2496 str2prefix ("0.0.0.0/0", &p);
2497#ifdef HAVE_IPV6
2498 else if (afi == AFI_IP6)
2499 {
6182d65b
JBD
2500 struct attr_extra *ae = attr.extra;
2501
718e3744 2502 str2prefix ("::/0", &p);
2503
2504 /* IPv6 global nexthop must be included. */
fb982c25 2505 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
718e3744 2506 IPV6_MAX_BYTELEN);
fb982c25 2507 ae->mp_nexthop_len = 16;
718e3744 2508
2509 /* If the peer is on shared nextwork and we have link-local
2510 nexthop set it. */
2511 if (peer->shared_network
2512 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2513 {
fb982c25 2514 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
718e3744 2515 IPV6_MAX_BYTELEN);
fb982c25 2516 ae->mp_nexthop_len = 32;
718e3744 2517 }
2518 }
2519#endif /* HAVE_IPV6 */
718e3744 2520
2521 if (peer->default_rmap[afi][safi].name)
2522 {
fee0f4c6 2523 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
dcab1bb8
CF
2524 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2525 {
2526 for (ri = rn->info; ri; ri = ri->next)
2527 {
2528 struct attr dummy_attr;
2529 struct attr_extra dummy_extra;
2530 struct bgp_info info;
2531
2532 /* Provide dummy so the route-map can't modify the attributes */
2533 dummy_attr.extra = &dummy_extra;
2534 bgp_attr_dup(&dummy_attr, ri->attr);
2535 info.peer = ri->peer;
2536 info.attr = &dummy_attr;
2537
2538 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2539 RMAP_BGP, &info);
2540
2541 /* The route map might have set attributes. If we don't flush them
2542 * here, they will be leaked. */
2543 bgp_attr_flush(&dummy_attr);
2544 if (ret != RMAP_DENYMATCH)
2545 break;
2546 }
2547 if (ret != RMAP_DENYMATCH)
2548 break;
2549 }
fee0f4c6 2550 bgp->peer_self->rmap_type = 0;
2551
718e3744 2552 if (ret == RMAP_DENYMATCH)
dcab1bb8 2553 withdraw = 1;
718e3744 2554 }
2555
2556 if (withdraw)
2557 {
2558 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2559 bgp_default_withdraw_send (peer, afi, safi);
2560 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2561 }
2562 else
2563 {
dcab1bb8
CF
2564 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2565 {
2566 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2567 bgp_default_update_send (peer, &attr, afi, safi, from);
2568 }
718e3744 2569 }
fb982c25
PJ
2570
2571 bgp_attr_extra_free (&attr);
f6f434b2 2572 aspath_unintern (&aspath);
718e3744 2573}
2574\f
2575static void
2576bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
fee0f4c6 2577 struct bgp_table *table, int rsclient)
718e3744 2578{
2579 struct bgp_node *rn;
2580 struct bgp_info *ri;
558d1fec
JBD
2581 struct attr attr;
2582 struct attr_extra extra;
2583
718e3744 2584 if (! table)
fee0f4c6 2585 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
718e3744 2586
2587 if (safi != SAFI_MPLS_VPN
2588 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2589 bgp_default_originate (peer, afi, safi, 0);
2590
558d1fec
JBD
2591 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2592 attr.extra = &extra;
2593
718e3744 2594 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2595 for (ri = rn->info; ri; ri = ri->next)
2596 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2597 {
fee0f4c6 2598 if ( (rsclient) ?
2599 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2600 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
718e3744 2601 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2602 else
2603 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2604 }
2605}
2606
2607void
2608bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2609{
2610 struct bgp_node *rn;
2611 struct bgp_table *table;
2612
2613 if (peer->status != Established)
2614 return;
2615
2616 if (! peer->afc_nego[afi][safi])
2617 return;
2618
2619 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2620 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2621 return;
2622
2623 if (safi != SAFI_MPLS_VPN)
fee0f4c6 2624 bgp_announce_table (peer, afi, safi, NULL, 0);
718e3744 2625 else
2626 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2627 rn = bgp_route_next(rn))
2628 if ((table = (rn->info)) != NULL)
fee0f4c6 2629 bgp_announce_table (peer, afi, safi, table, 0);
2630
2631 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2632 bgp_announce_table (peer, afi, safi, NULL, 1);
718e3744 2633}
2634
2635void
2636bgp_announce_route_all (struct peer *peer)
2637{
2638 afi_t afi;
2639 safi_t safi;
2640
2641 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2642 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2643 bgp_announce_route (peer, afi, safi);
2644}
2645\f
2646static void
fee0f4c6 2647bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
8692c506 2648 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
fee0f4c6 2649{
2650 struct bgp_node *rn;
2651 struct bgp_adj_in *ain;
2652
2653 if (! table)
2654 table = rsclient->bgp->rib[afi][safi];
2655
2656 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2657 for (ain = rn->adj_in; ain; ain = ain->next)
2658 {
8692c506 2659 struct bgp_info *ri = rn->info;
d53d8fda 2660 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 2661
fee0f4c6 2662 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
d53d8fda 2663 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
fee0f4c6 2664 }
2665}
2666
2667void
2668bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2669{
2670 struct bgp_table *table;
2671 struct bgp_node *rn;
2672
2673 if (safi != SAFI_MPLS_VPN)
8692c506 2674 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
fee0f4c6 2675
2676 else
2677 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2678 rn = bgp_route_next (rn))
2679 if ((table = rn->info) != NULL)
8692c506
JBD
2680 {
2681 struct prefix_rd prd;
2682 prd.family = AF_UNSPEC;
2683 prd.prefixlen = 64;
2684 memcpy(&prd.val, rn->p.u.val, 8);
2685
2686 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2687 }
fee0f4c6 2688}
2689\f
2690static void
718e3744 2691bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
8692c506 2692 struct bgp_table *table, struct prefix_rd *prd)
718e3744 2693{
2694 int ret;
2695 struct bgp_node *rn;
2696 struct bgp_adj_in *ain;
2697
2698 if (! table)
2699 table = peer->bgp->rib[afi][safi];
2700
2701 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2702 for (ain = rn->adj_in; ain; ain = ain->next)
2703 {
2704 if (ain->peer == peer)
2705 {
8692c506 2706 struct bgp_info *ri = rn->info;
d53d8fda 2707 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
8692c506 2708
718e3744 2709 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2710 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
d53d8fda 2711 prd, tag, 1);
8692c506 2712
718e3744 2713 if (ret < 0)
2714 {
2715 bgp_unlock_node (rn);
2716 return;
2717 }
2718 continue;
2719 }
2720 }
2721}
2722
2723void
2724bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2725{
2726 struct bgp_node *rn;
2727 struct bgp_table *table;
2728
2729 if (peer->status != Established)
2730 return;
2731
2732 if (safi != SAFI_MPLS_VPN)
8692c506 2733 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
718e3744 2734 else
2735 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2736 rn = bgp_route_next (rn))
2737 if ((table = rn->info) != NULL)
8692c506
JBD
2738 {
2739 struct prefix_rd prd;
2740 prd.family = AF_UNSPEC;
2741 prd.prefixlen = 64;
2742 memcpy(&prd.val, rn->p.u.val, 8);
2743
2744 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2745 }
718e3744 2746}
2747\f
228da428
CC
2748
2749struct bgp_clear_node_queue
2750{
2751 struct bgp_node *rn;
2752 enum bgp_clear_route_type purpose;
2753};
2754
200df115 2755static wq_item_status
0fb58d5d 2756bgp_clear_route_node (struct work_queue *wq, void *data)
200df115 2757{
228da428
CC
2758 struct bgp_clear_node_queue *cnq = data;
2759 struct bgp_node *rn = cnq->rn;
64e580a7 2760 struct peer *peer = wq->spec.data;
718e3744 2761 struct bgp_info *ri;
67174041
AS
2762 afi_t afi = bgp_node_table (rn)->afi;
2763 safi_t safi = bgp_node_table (rn)->safi;
200df115 2764
64e580a7 2765 assert (rn && peer);
200df115 2766
64e580a7 2767 for (ri = rn->info; ri; ri = ri->next)
228da428 2768 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
200df115 2769 {
2770 /* graceful restart STALE flag set. */
64e580a7
PJ
2771 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2772 && peer->nsf[afi][safi]
200df115 2773 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
1a392d46
PJ
2774 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2775 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
200df115 2776 else
64e580a7 2777 bgp_rib_remove (rn, ri, peer, afi, safi);
200df115 2778 break;
2779 }
200df115 2780 return WQ_SUCCESS;
2781}
2782
2783static void
0fb58d5d 2784bgp_clear_node_queue_del (struct work_queue *wq, void *data)
200df115 2785{
228da428
CC
2786 struct bgp_clear_node_queue *cnq = data;
2787 struct bgp_node *rn = cnq->rn;
67174041 2788 struct bgp_table *table = bgp_node_table (rn);
64e580a7
PJ
2789
2790 bgp_unlock_node (rn);
228da428
CC
2791 bgp_table_unlock (table);
2792 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
200df115 2793}
2794
2795static void
94f2b392 2796bgp_clear_node_complete (struct work_queue *wq)
200df115 2797{
64e580a7
PJ
2798 struct peer *peer = wq->spec.data;
2799
3e0c78ef 2800 /* Tickle FSM to start moving again */
ca058a30 2801 BGP_EVENT_ADD (peer, Clearing_Completed);
228da428
CC
2802
2803 peer_unlock (peer); /* bgp_clear_route */
200df115 2804}
2805
2806static void
64e580a7 2807bgp_clear_node_queue_init (struct peer *peer)
200df115 2808{
a2943657 2809 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
64e580a7 2810
a2943657 2811 snprintf (wname, sizeof(wname), "clear %s", peer->host);
64e580a7
PJ
2812#undef CLEAR_QUEUE_NAME_LEN
2813
2814 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
200df115 2815 {
2816 zlog_err ("%s: Failed to allocate work queue", __func__);
2817 exit (1);
2818 }
64e580a7
PJ
2819 peer->clear_node_queue->spec.hold = 10;
2820 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2821 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2822 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2823 peer->clear_node_queue->spec.max_retries = 0;
2824
2825 /* we only 'lock' this peer reference when the queue is actually active */
2826 peer->clear_node_queue->spec.data = peer;
200df115 2827}
718e3744 2828
200df115 2829static void
2830bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
228da428
CC
2831 struct bgp_table *table, struct peer *rsclient,
2832 enum bgp_clear_route_type purpose)
200df115 2833{
200df115 2834 struct bgp_node *rn;
2835
f2c31acb 2836
718e3744 2837 if (! table)
fee0f4c6 2838 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
64e580a7 2839
6cf159b9 2840 /* If still no table => afi/safi isn't configured at all or smth. */
2841 if (! table)
2842 return;
65ca75e0
PJ
2843
2844 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2845 {
f2c31acb
PJ
2846 struct bgp_info *ri;
2847 struct bgp_adj_in *ain;
2848 struct bgp_adj_out *aout;
f2c31acb
PJ
2849
2850 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2851 * queued for every clearing peer, regardless of whether it is
2852 * relevant to the peer at hand.
2853 *
2854 * Overview: There are 3 different indices which need to be
2855 * scrubbed, potentially, when a peer is removed:
2856 *
2857 * 1 peer's routes visible via the RIB (ie accepted routes)
2858 * 2 peer's routes visible by the (optional) peer's adj-in index
2859 * 3 other routes visible by the peer's adj-out index
2860 *
2861 * 3 there is no hurry in scrubbing, once the struct peer is
2862 * removed from bgp->peer, we could just GC such deleted peer's
2863 * adj-outs at our leisure.
2864 *
2865 * 1 and 2 must be 'scrubbed' in some way, at least made
2866 * invisible via RIB index before peer session is allowed to be
2867 * brought back up. So one needs to know when such a 'search' is
2868 * complete.
2869 *
2870 * Ideally:
2871 *
2872 * - there'd be a single global queue or a single RIB walker
2873 * - rather than tracking which route_nodes still need to be
2874 * examined on a peer basis, we'd track which peers still
2875 * aren't cleared
2876 *
2877 * Given that our per-peer prefix-counts now should be reliable,
2878 * this may actually be achievable. It doesn't seem to be a huge
2879 * problem at this time,
2880 */
24e50f20
JBD
2881 for (ain = rn->adj_in; ain; ain = ain->next)
2882 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2883 {
2884 bgp_adj_in_remove (rn, ain);
2885 bgp_unlock_node (rn);
2886 break;
2887 }
2888 for (aout = rn->adj_out; aout; aout = aout->next)
2889 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2890 {
2891 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2892 bgp_unlock_node (rn);
2893 break;
2894 }
2895
f2c31acb 2896 for (ri = rn->info; ri; ri = ri->next)
228da428 2897 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
f2c31acb 2898 {
228da428
CC
2899 struct bgp_clear_node_queue *cnq;
2900
2901 /* both unlocked in bgp_clear_node_queue_del */
67174041 2902 bgp_table_lock (bgp_node_table (rn));
228da428
CC
2903 bgp_lock_node (rn);
2904 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2905 sizeof (struct bgp_clear_node_queue));
2906 cnq->rn = rn;
2907 cnq->purpose = purpose;
2908 work_queue_add (peer->clear_node_queue, cnq);
2909 break;
f2c31acb 2910 }
65ca75e0
PJ
2911 }
2912 return;
2913}
2914
2915void
228da428
CC
2916bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2917 enum bgp_clear_route_type purpose)
65ca75e0
PJ
2918{
2919 struct bgp_node *rn;
2920 struct bgp_table *table;
2921 struct peer *rsclient;
2922 struct listnode *node, *nnode;
6cf159b9 2923
64e580a7
PJ
2924 if (peer->clear_node_queue == NULL)
2925 bgp_clear_node_queue_init (peer);
200df115 2926
ca058a30
PJ
2927 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2928 * Idle until it receives a Clearing_Completed event. This protects
2929 * against peers which flap faster than we can we clear, which could
2930 * lead to:
64e580a7
PJ
2931 *
2932 * a) race with routes from the new session being installed before
2933 * clear_route_node visits the node (to delete the route of that
2934 * peer)
2935 * b) resource exhaustion, clear_route_node likely leads to an entry
2936 * on the process_main queue. Fast-flapping could cause that queue
2937 * to grow and grow.
200df115 2938 */
ca058a30
PJ
2939 if (!peer->clear_node_queue->thread)
2940 peer_lock (peer); /* bgp_clear_node_complete */
fee0f4c6 2941
228da428 2942 switch (purpose)
fee0f4c6 2943 {
228da428
CC
2944 case BGP_CLEAR_ROUTE_NORMAL:
2945 if (safi != SAFI_MPLS_VPN)
2946 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2947 else
2948 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2949 rn = bgp_route_next (rn))
2950 if ((table = rn->info) != NULL)
2951 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2952
2953 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2954 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2955 PEER_FLAG_RSERVER_CLIENT))
2956 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2957 break;
2958
2959 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2960 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2961 break;
2962
2963 default:
2964 assert (0);
2965 break;
fee0f4c6 2966 }
65ca75e0 2967
ca058a30 2968 /* If no routes were cleared, nothing was added to workqueue, the
f2c31acb
PJ
2969 * completion function won't be run by workqueue code - call it here.
2970 * XXX: Actually, this assumption doesn't hold, see
2971 * bgp_clear_route_table(), we queue all non-empty nodes.
ca058a30
PJ
2972 *
2973 * Additionally, there is a presumption in FSM that clearing is only
f2c31acb
PJ
2974 * really needed if peer state is Established - peers in
2975 * pre-Established states shouldn't have any route-update state
2976 * associated with them (in or out).
ca058a30 2977 *
f2c31acb
PJ
2978 * We still can get here in pre-Established though, through
2979 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2980 * check to ensure the assumption above holds.
ca058a30
PJ
2981 *
2982 * At some future point, this check could be move to the top of the
2983 * function, and do a quick early-return when state is
2984 * pre-Established, avoiding above list and table scans. Once we're
2985 * sure it is safe..
65ca75e0
PJ
2986 */
2987 if (!peer->clear_node_queue->thread)
2988 bgp_clear_node_complete (peer->clear_node_queue);
718e3744 2989}
2990
2991void
2992bgp_clear_route_all (struct peer *peer)
2993{
2994 afi_t afi;
2995 safi_t safi;
2996
2997 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2998 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
228da428 2999 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
718e3744 3000}
3001
3002void
3003bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3004{
3005 struct bgp_table *table;
3006 struct bgp_node *rn;
3007 struct bgp_adj_in *ain;
3008
3009 table = peer->bgp->rib[afi][safi];
3010
3011 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3012 for (ain = rn->adj_in; ain ; ain = ain->next)
3013 if (ain->peer == peer)
3014 {
3015 bgp_adj_in_remove (rn, ain);
3016 bgp_unlock_node (rn);
3017 break;
3018 }
3019}
93406d87 3020
3021void
3022bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3023{
3024 struct bgp_node *rn;
3025 struct bgp_info *ri;
3026 struct bgp_table *table;
3027
3028 table = peer->bgp->rib[afi][safi];
3029
3030 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3031 {
3032 for (ri = rn->info; ri; ri = ri->next)
3033 if (ri->peer == peer)
3034 {
3035 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3036 bgp_rib_remove (rn, ri, peer, afi, safi);
3037 break;
3038 }
3039 }
3040}
718e3744 3041\f
3042/* Delete all kernel routes. */
3043void
66e5cd87 3044bgp_cleanup_routes (void)
718e3744 3045{
3046 struct bgp *bgp;
1eb8ef25 3047 struct listnode *node, *nnode;
718e3744 3048 struct bgp_node *rn;
3049 struct bgp_table *table;
3050 struct bgp_info *ri;
3051
1eb8ef25 3052 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 3053 {
3054 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3055
3056 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3057 for (ri = rn->info; ri; ri = ri->next)
3058 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3059 && ri->type == ZEBRA_ROUTE_BGP
3060 && ri->sub_type == BGP_ROUTE_NORMAL)
5a616c08 3061 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
718e3744 3062
3063 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3064
3065 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3066 for (ri = rn->info; ri; ri = ri->next)
3067 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3068 && ri->type == ZEBRA_ROUTE_BGP
3069 && ri->sub_type == BGP_ROUTE_NORMAL)
5a616c08 3070 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
718e3744 3071 }
3072}
3073
3074void
66e5cd87 3075bgp_reset (void)
718e3744 3076{
3077 vty_reset ();
3078 bgp_zclient_reset ();
3079 access_list_reset ();
3080 prefix_list_reset ();
3081}
3082\f
3083/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3084 value. */
3085int
3086bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3087{
3088 u_char *pnt;
3089 u_char *lim;
3090 struct prefix p;
3091 int psize;
3092 int ret;
3093
3094 /* Check peer status. */
3095 if (peer->status != Established)
3096 return 0;
3097
3098 pnt = packet->nlri;
3099 lim = pnt + packet->length;
3100
3101 for (; pnt < lim; pnt += psize)
3102 {
3103 /* Clear prefix structure. */
3104 memset (&p, 0, sizeof (struct prefix));
3105
3106 /* Fetch prefix length. */
3107 p.prefixlen = *pnt++;
3108 p.family = afi2family (packet->afi);
3109
3110 /* Already checked in nlri_sanity_check(). We do double check
3111 here. */
3112 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3113 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3114 return -1;
3115
3116 /* Packet size overflow check. */
3117 psize = PSIZE (p.prefixlen);
3118
3119 /* When packet overflow occur return immediately. */
3120 if (pnt + psize > lim)
3121 return -1;
3122
3123 /* Fetch prefix from NLRI packet. */
3124 memcpy (&p.u.prefix, pnt, psize);
3125
3126 /* Check address. */
3127 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3128 {
3129 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3130 {
f5ba3874 3131 /*
3132 * From draft-ietf-idr-bgp4-22, Section 6.3:
3133 * If a BGP router receives an UPDATE message with a
3134 * semantically incorrect NLRI field, in which a prefix is
3135 * semantically incorrect (eg. an unexpected multicast IP
3136 * address), it should ignore the prefix.
3137 */
718e3744 3138 zlog (peer->log, LOG_ERR,
3139 "IPv4 unicast NLRI is multicast address %s",
3140 inet_ntoa (p.u.prefix4));
f5ba3874 3141
718e3744 3142 return -1;
3143 }
3144 }
3145
3146#ifdef HAVE_IPV6
3147 /* Check address. */
3148 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3149 {
3150 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3151 {
3152 char buf[BUFSIZ];
3153
3154 zlog (peer->log, LOG_WARNING,
3155 "IPv6 link-local NLRI received %s ignore this NLRI",
3156 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3157
3158 continue;
3159 }
3160 }
3161#endif /* HAVE_IPV6 */
3162
3163 /* Normal process. */
3164 if (attr)
3165 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3166 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3167 else
3168 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3169 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3170
3171 /* Address family configuration mismatch or maximum-prefix count
3172 overflow. */
3173 if (ret < 0)
3174 return -1;
3175 }
3176
3177 /* Packet length consistency check. */
3178 if (pnt != lim)
3179 return -1;
3180
3181 return 0;
3182}
3183
3184/* NLRI encode syntax check routine. */
3185int
3186bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3187 bgp_size_t length)
3188{
3189 u_char *end;
3190 u_char prefixlen;
3191 int psize;
3192
3193 end = pnt + length;
3194
3195 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3196 syntactic validity. If the field is syntactically incorrect,
3197 then the Error Subcode is set to Invalid Network Field. */
3198
3199 while (pnt < end)
3200 {
3201 prefixlen = *pnt++;
3202
3203 /* Prefix length check. */
3204 if ((afi == AFI_IP && prefixlen > 32)
3205 || (afi == AFI_IP6 && prefixlen > 128))
3206 {
3207 plog_err (peer->log,
3208 "%s [Error] Update packet error (wrong prefix length %d)",
3209 peer->host, prefixlen);
3210 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3211 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3212 return -1;
3213 }
3214
3215 /* Packet size overflow check. */
3216 psize = PSIZE (prefixlen);
3217
3218 if (pnt + psize > end)
3219 {
3220 plog_err (peer->log,
3221 "%s [Error] Update packet error"
3222 " (prefix data overflow prefix size is %d)",
3223 peer->host, psize);
3224 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3225 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3226 return -1;
3227 }
3228
3229 pnt += psize;
3230 }
3231
3232 /* Packet length consistency check. */
3233 if (pnt != end)
3234 {
3235 plog_err (peer->log,
3236 "%s [Error] Update packet error"
3237 " (prefix length mismatch with total length)",
3238 peer->host);
3239 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3240 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3241 return -1;
3242 }
3243 return 0;
3244}
3245\f
94f2b392 3246static struct bgp_static *
66e5cd87 3247bgp_static_new (void)
718e3744 3248{
393deb9b 3249 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
718e3744 3250}
3251
94f2b392 3252static void
718e3744 3253bgp_static_free (struct bgp_static *bgp_static)
3254{
3255 if (bgp_static->rmap.name)
3256 free (bgp_static->rmap.name);
3257 XFREE (MTYPE_BGP_STATIC, bgp_static);
3258}
3259
94f2b392 3260static void
fee0f4c6 3261bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3262 struct prefix *p, afi_t afi, safi_t safi)
3263{
3264 struct bgp_node *rn;
3265 struct bgp_info *ri;
3266
3267 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3268
3269 /* Check selected route and self inserted route. */
3270 for (ri = rn->info; ri; ri = ri->next)
3271 if (ri->peer == bgp->peer_self
3272 && ri->type == ZEBRA_ROUTE_BGP
3273 && ri->sub_type == BGP_ROUTE_STATIC)
3274 break;
3275
3276 /* Withdraw static BGP route from routing table. */
3277 if (ri)
3278 {
fee0f4c6 3279 bgp_info_delete (rn, ri);
1a392d46 3280 bgp_process (bgp, rn, afi, safi);
fee0f4c6 3281 }
3282
3283 /* Unlock bgp_node_lookup. */
3284 bgp_unlock_node (rn);
3285}
3286
94f2b392 3287static void
fee0f4c6 3288bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
fb982c25
PJ
3289 struct bgp_static *bgp_static,
3290 afi_t afi, safi_t safi)
fee0f4c6 3291{
3292 struct bgp_node *rn;
3293 struct bgp_info *ri;
3294 struct bgp_info *new;
3295 struct bgp_info info;
fee0f4c6 3296 struct attr *attr_new;
e16a4133 3297 struct attr attr;
558d1fec
JBD
3298 struct attr new_attr;
3299 struct attr_extra new_extra;
fee0f4c6 3300 struct bgp *bgp;
3301 int ret;
3302 char buf[SU_ADDRSTRLEN];
3303
3304 bgp = rsclient->bgp;
3305
06e110f9
PJ
3306 assert (bgp_static);
3307 if (!bgp_static)
3308 return;
3309
fee0f4c6 3310 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3311
3312 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
06e110f9
PJ
3313
3314 attr.nexthop = bgp_static->igpnexthop;
3315 attr.med = bgp_static->igpmetric;
3316 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
41367172 3317
41367172
PJ
3318 if (bgp_static->atomic)
3319 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3320
fee0f4c6 3321 /* Apply network route-map for export to this rsclient. */
3322 if (bgp_static->rmap.name)
3323 {
fb982c25 3324 struct attr attr_tmp = attr;
fee0f4c6 3325 info.peer = rsclient;
fb982c25
PJ
3326 info.attr = &attr_tmp;
3327
fee0f4c6 3328 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3329 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3330
3331 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3332
3333 rsclient->rmap_type = 0;
3334
3335 if (ret == RMAP_DENYMATCH)
3336 {
3337 /* Free uninterned attribute. */
fb982c25 3338 bgp_attr_flush (&attr_tmp);
fee0f4c6 3339
3340 /* Unintern original. */
f6f434b2 3341 aspath_unintern (&attr.aspath);
fee0f4c6 3342 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
fb982c25
PJ
3343 bgp_attr_extra_free (&attr);
3344
fee0f4c6 3345 return;
3346 }
fb982c25 3347 attr_new = bgp_attr_intern (&attr_tmp);
fee0f4c6 3348 }
3349 else
3350 attr_new = bgp_attr_intern (&attr);
558d1fec
JBD
3351
3352 new_attr.extra = &new_extra;
7badc263 3353 bgp_attr_dup(&new_attr, attr_new);
fb982c25 3354
fee0f4c6 3355 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3356
fb982c25
PJ
3357 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3358 == RMAP_DENY)
3359 {
fee0f4c6 3360 /* This BGP update is filtered. Log the reason then update BGP entry. */
3361 if (BGP_DEBUG (update, UPDATE_IN))
d2c1f16b 3362 zlog (rsclient->log, LOG_DEBUG,
fee0f4c6 3363 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3364 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3365 p->prefixlen, rsclient->host);
3366
3367 bgp->peer_self->rmap_type = 0;
3368
f6f434b2
PJ
3369 bgp_attr_unintern (&attr_new);
3370 aspath_unintern (&attr.aspath);
fb982c25 3371 bgp_attr_extra_free (&attr);
fee0f4c6 3372
3373 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3374
3375 return;
fb982c25 3376 }
fee0f4c6 3377
3378 bgp->peer_self->rmap_type = 0;
3379
f6f434b2 3380 bgp_attr_unintern (&attr_new);
fee0f4c6 3381 attr_new = bgp_attr_intern (&new_attr);
3382
3383 for (ri = rn->info; ri; ri = ri->next)
3384 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3385 && ri->sub_type == BGP_ROUTE_STATIC)
3386 break;
3387
3388 if (ri)
3389 {
8d45210e
AS
3390 if (attrhash_cmp (ri->attr, attr_new) &&
3391 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
fee0f4c6 3392 {
3393 bgp_unlock_node (rn);
f6f434b2
PJ
3394 bgp_attr_unintern (&attr_new);
3395 aspath_unintern (&attr.aspath);
fb982c25 3396 bgp_attr_extra_free (&attr);
fee0f4c6 3397 return;
3398 }
3399 else
3400 {
3401 /* The attribute is changed. */
1a392d46 3402 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
fee0f4c6 3403
3404 /* Rewrite BGP route information. */
8d45210e
AS
3405 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3406 bgp_info_restore(rn, ri);
f6f434b2 3407 bgp_attr_unintern (&ri->attr);
fee0f4c6 3408 ri->attr = attr_new;
65957886 3409 ri->uptime = bgp_clock ();
fee0f4c6 3410
3411 /* Process change. */
3412 bgp_process (bgp, rn, afi, safi);
3413 bgp_unlock_node (rn);
f6f434b2 3414 aspath_unintern (&attr.aspath);
fb982c25 3415 bgp_attr_extra_free (&attr);
fee0f4c6 3416 return;
fb982c25 3417 }
fee0f4c6 3418 }
fb982c25 3419
fee0f4c6 3420 /* Make new BGP info. */
3421 new = bgp_info_new ();
3422 new->type = ZEBRA_ROUTE_BGP;
3423 new->sub_type = BGP_ROUTE_STATIC;
3424 new->peer = bgp->peer_self;
3425 SET_FLAG (new->flags, BGP_INFO_VALID);
3426 new->attr = attr_new;
65957886 3427 new->uptime = bgp_clock ();
fee0f4c6 3428
3429 /* Register new BGP information. */
3430 bgp_info_add (rn, new);
200df115 3431
3432 /* route_node_get lock */
3433 bgp_unlock_node (rn);
3434
fee0f4c6 3435 /* Process change. */
3436 bgp_process (bgp, rn, afi, safi);
3437
3438 /* Unintern original. */
f6f434b2 3439 aspath_unintern (&attr.aspath);
fb982c25 3440 bgp_attr_extra_free (&attr);
fee0f4c6 3441}
3442
94f2b392 3443static void
fee0f4c6 3444bgp_static_update_main (struct bgp *bgp, struct prefix *p,
718e3744 3445 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3446{
3447 struct bgp_node *rn;
3448 struct bgp_info *ri;
3449 struct bgp_info *new;
3450 struct bgp_info info;
e16a4133 3451 struct attr attr;
718e3744 3452 struct attr *attr_new;
3453 int ret;
3454
dd8103a9
PJ
3455 assert (bgp_static);
3456 if (!bgp_static)
3457 return;
3458
fee0f4c6 3459 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 3460
3461 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
dd8103a9
PJ
3462
3463 attr.nexthop = bgp_static->igpnexthop;
3464 attr.med = bgp_static->igpmetric;
3465 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
718e3744 3466
41367172
PJ
3467 if (bgp_static->atomic)
3468 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3469
718e3744 3470 /* Apply route-map. */
3471 if (bgp_static->rmap.name)
3472 {
fb982c25 3473 struct attr attr_tmp = attr;
718e3744 3474 info.peer = bgp->peer_self;
286e1e71 3475 info.attr = &attr_tmp;
718e3744 3476
fee0f4c6 3477 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3478
718e3744 3479 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
286e1e71 3480
fee0f4c6 3481 bgp->peer_self->rmap_type = 0;
3482
718e3744 3483 if (ret == RMAP_DENYMATCH)
3484 {
3485 /* Free uninterned attribute. */
286e1e71 3486 bgp_attr_flush (&attr_tmp);
718e3744 3487
3488 /* Unintern original. */
f6f434b2 3489 aspath_unintern (&attr.aspath);
fb982c25 3490 bgp_attr_extra_free (&attr);
718e3744 3491 bgp_static_withdraw (bgp, p, afi, safi);
3492 return;
3493 }
286e1e71 3494 attr_new = bgp_attr_intern (&attr_tmp);
718e3744 3495 }
286e1e71 3496 else
3497 attr_new = bgp_attr_intern (&attr);
718e3744 3498
3499 for (ri = rn->info; ri; ri = ri->next)
3500 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3501 && ri->sub_type == BGP_ROUTE_STATIC)
3502 break;
3503
3504 if (ri)
3505 {
8d45210e
AS
3506 if (attrhash_cmp (ri->attr, attr_new) &&
3507 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
718e3744 3508 {
3509 bgp_unlock_node (rn);
f6f434b2
PJ
3510 bgp_attr_unintern (&attr_new);
3511 aspath_unintern (&attr.aspath);
fb982c25 3512 bgp_attr_extra_free (&attr);
718e3744 3513 return;
3514 }
3515 else
3516 {
3517 /* The attribute is changed. */
1a392d46 3518 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 3519
3520 /* Rewrite BGP route information. */
8d45210e
AS
3521 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3522 bgp_info_restore(rn, ri);
3523 else
3524 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
f6f434b2 3525 bgp_attr_unintern (&ri->attr);
718e3744 3526 ri->attr = attr_new;
65957886 3527 ri->uptime = bgp_clock ();
718e3744 3528
3529 /* Process change. */
3530 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3531 bgp_process (bgp, rn, afi, safi);
3532 bgp_unlock_node (rn);
f6f434b2 3533 aspath_unintern (&attr.aspath);
fb982c25 3534 bgp_attr_extra_free (&attr);
718e3744 3535 return;
3536 }
3537 }
3538
3539 /* Make new BGP info. */
3540 new = bgp_info_new ();
3541 new->type = ZEBRA_ROUTE_BGP;
3542 new->sub_type = BGP_ROUTE_STATIC;
3543 new->peer = bgp->peer_self;
3544 SET_FLAG (new->flags, BGP_INFO_VALID);
3545 new->attr = attr_new;
65957886 3546 new->uptime = bgp_clock ();
718e3744 3547
3548 /* Aggregate address increment. */
3549 bgp_aggregate_increment (bgp, p, new, afi, safi);
3550
3551 /* Register new BGP information. */
3552 bgp_info_add (rn, new);
200df115 3553
3554 /* route_node_get lock */
3555 bgp_unlock_node (rn);
3556
718e3744 3557 /* Process change. */
3558 bgp_process (bgp, rn, afi, safi);
3559
3560 /* Unintern original. */
f6f434b2 3561 aspath_unintern (&attr.aspath);
fb982c25 3562 bgp_attr_extra_free (&attr);
718e3744 3563}
3564
fee0f4c6 3565void
3566bgp_static_update (struct bgp *bgp, struct prefix *p,
3567 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3568{
3569 struct peer *rsclient;
1eb8ef25 3570 struct listnode *node, *nnode;
fee0f4c6 3571
3572 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3573
1eb8ef25 3574 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
fee0f4c6 3575 {
da5b30f6
PJ
3576 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3577 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
fee0f4c6 3578 }
3579}
3580
94f2b392 3581static void
4c9641ba
ML
3582bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3583 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 3584{
3585 struct bgp_node *rn;
3586 struct bgp_info *new;
fb982c25 3587
fee0f4c6 3588 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 3589
3590 /* Make new BGP info. */
3591 new = bgp_info_new ();
3592 new->type = ZEBRA_ROUTE_BGP;
3593 new->sub_type = BGP_ROUTE_STATIC;
3594 new->peer = bgp->peer_self;
3595 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3596 SET_FLAG (new->flags, BGP_INFO_VALID);
65957886 3597 new->uptime = bgp_clock ();
fb982c25
PJ
3598 new->extra = bgp_info_extra_new();
3599 memcpy (new->extra->tag, tag, 3);
718e3744 3600
3601 /* Aggregate address increment. */
200df115 3602 bgp_aggregate_increment (bgp, p, new, afi, safi);
718e3744 3603
3604 /* Register new BGP information. */
200df115 3605 bgp_info_add (rn, new);
718e3744 3606
200df115 3607 /* route_node_get lock */
3608 bgp_unlock_node (rn);
3609
718e3744 3610 /* Process change. */
3611 bgp_process (bgp, rn, afi, safi);
3612}
3613
3614void
3615bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3616 safi_t safi)
3617{
3618 struct bgp_node *rn;
3619 struct bgp_info *ri;
3620
fee0f4c6 3621 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
718e3744 3622
3623 /* Check selected route and self inserted route. */
3624 for (ri = rn->info; ri; ri = ri->next)
3625 if (ri->peer == bgp->peer_self
3626 && ri->type == ZEBRA_ROUTE_BGP
3627 && ri->sub_type == BGP_ROUTE_STATIC)
3628 break;
3629
3630 /* Withdraw static BGP route from routing table. */
3631 if (ri)
3632 {
3633 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
718e3744 3634 bgp_info_delete (rn, ri);
1a392d46 3635 bgp_process (bgp, rn, afi, safi);
718e3744 3636 }
3637
3638 /* Unlock bgp_node_lookup. */
3639 bgp_unlock_node (rn);
3640}
3641
fee0f4c6 3642void
3643bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3644{
3645 struct bgp_static *bgp_static;
3646 struct bgp *bgp;
3647 struct bgp_node *rn;
3648 struct prefix *p;
3649
3650 bgp = rsclient->bgp;
3651
3652 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3653 if ((bgp_static = rn->info) != NULL)
3654 {
3655 p = &rn->p;
3656
3657 bgp_static_update_rsclient (rsclient, p, bgp_static,
3658 afi, safi);
3659 }
3660}
3661
94f2b392 3662static void
4c9641ba
ML
3663bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3664 safi_t safi, struct prefix_rd *prd, u_char *tag)
718e3744 3665{
3666 struct bgp_node *rn;
3667 struct bgp_info *ri;
3668
fee0f4c6 3669 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
718e3744 3670
3671 /* Check selected route and self inserted route. */
3672 for (ri = rn->info; ri; ri = ri->next)
3673 if (ri->peer == bgp->peer_self
3674 && ri->type == ZEBRA_ROUTE_BGP
3675 && ri->sub_type == BGP_ROUTE_STATIC)
3676 break;
3677
3678 /* Withdraw static BGP route from routing table. */
3679 if (ri)
3680 {
3681 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
718e3744 3682 bgp_info_delete (rn, ri);
1a392d46 3683 bgp_process (bgp, rn, afi, safi);
718e3744 3684 }
3685
3686 /* Unlock bgp_node_lookup. */
3687 bgp_unlock_node (rn);
3688}
3689
3690/* Configure static BGP network. When user don't run zebra, static
3691 route should be installed as valid. */
94f2b392 3692static int
fd79ac91 3693bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
c8f3fe30 3694 afi_t afi, safi_t safi, const char *rmap, int backdoor)
718e3744 3695{
3696 int ret;
3697 struct prefix p;
3698 struct bgp_static *bgp_static;
3699 struct bgp_node *rn;
41367172 3700 u_char need_update = 0;
718e3744 3701
3702 /* Convert IP prefix string to struct prefix. */
3703 ret = str2prefix (ip_str, &p);
3704 if (! ret)
3705 {
3706 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3707 return CMD_WARNING;
3708 }
3709#ifdef HAVE_IPV6
3710 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3711 {
3712 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3713 VTY_NEWLINE);
3714 return CMD_WARNING;
3715 }
3716#endif /* HAVE_IPV6 */
3717
3718 apply_mask (&p);
3719
3720 /* Set BGP static route configuration. */
3721 rn = bgp_node_get (bgp->route[afi][safi], &p);
3722
3723 if (rn->info)
3724 {
3725 /* Configuration change. */
3726 bgp_static = rn->info;
3727
3728 /* Check previous routes are installed into BGP. */
c8f3fe30
PJ
3729 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3730 need_update = 1;
41367172 3731
718e3744 3732 bgp_static->backdoor = backdoor;
41367172 3733
718e3744 3734 if (rmap)
3735 {
3736 if (bgp_static->rmap.name)
3737 free (bgp_static->rmap.name);
3738 bgp_static->rmap.name = strdup (rmap);
3739 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3740 }
3741 else
3742 {
3743 if (bgp_static->rmap.name)
3744 free (bgp_static->rmap.name);
3745 bgp_static->rmap.name = NULL;
3746 bgp_static->rmap.map = NULL;
3747 bgp_static->valid = 0;
3748 }
3749 bgp_unlock_node (rn);
3750 }
3751 else
3752 {
3753 /* New configuration. */
3754 bgp_static = bgp_static_new ();
3755 bgp_static->backdoor = backdoor;
3756 bgp_static->valid = 0;
3757 bgp_static->igpmetric = 0;
3758 bgp_static->igpnexthop.s_addr = 0;
41367172 3759
718e3744 3760 if (rmap)
3761 {
3762 if (bgp_static->rmap.name)
3763 free (bgp_static->rmap.name);
3764 bgp_static->rmap.name = strdup (rmap);
3765 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3766 }
3767 rn->info = bgp_static;
3768 }
3769
3770 /* If BGP scan is not enabled, we should install this route here. */
3771 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3772 {
3773 bgp_static->valid = 1;
3774
3775 if (need_update)
3776 bgp_static_withdraw (bgp, &p, afi, safi);
3777
3778 if (! bgp_static->backdoor)
3779 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3780 }
3781
3782 return CMD_SUCCESS;
3783}
3784
3785/* Configure static BGP network. */
94f2b392 3786static int
fd79ac91 3787bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4c9641ba 3788 afi_t afi, safi_t safi)
718e3744 3789{
3790 int ret;
3791 struct prefix p;
3792 struct bgp_static *bgp_static;
3793 struct bgp_node *rn;
3794
3795 /* Convert IP prefix string to struct prefix. */
3796 ret = str2prefix (ip_str, &p);
3797 if (! ret)
3798 {
3799 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3800 return CMD_WARNING;
3801 }
3802#ifdef HAVE_IPV6
3803 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3804 {
3805 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3806 VTY_NEWLINE);
3807 return CMD_WARNING;
3808 }
3809#endif /* HAVE_IPV6 */
3810
3811 apply_mask (&p);
3812
3813 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3814 if (! rn)
3815 {
3816 vty_out (vty, "%% Can't find specified static route configuration.%s",
3817 VTY_NEWLINE);
3818 return CMD_WARNING;
3819 }
3820
3821 bgp_static = rn->info;
41367172 3822
718e3744 3823 /* Update BGP RIB. */
3824 if (! bgp_static->backdoor)
3825 bgp_static_withdraw (bgp, &p, afi, safi);
3826
3827 /* Clear configuration. */
3828 bgp_static_free (bgp_static);
3829 rn->info = NULL;
3830 bgp_unlock_node (rn);
3831 bgp_unlock_node (rn);
3832
3833 return CMD_SUCCESS;
3834}
3835
3836/* Called from bgp_delete(). Delete all static routes from the BGP
3837 instance. */
3838void
3839bgp_static_delete (struct bgp *bgp)
3840{
3841 afi_t afi;
3842 safi_t safi;
3843 struct bgp_node *rn;
3844 struct bgp_node *rm;
3845 struct bgp_table *table;
3846 struct bgp_static *bgp_static;
3847
3848 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3849 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3850 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3851 if (rn->info != NULL)
3852 {
3853 if (safi == SAFI_MPLS_VPN)
3854 {
3855 table = rn->info;
3856
3857 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3858 {
3859 bgp_static = rn->info;
3860 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3861 AFI_IP, SAFI_MPLS_VPN,
3862 (struct prefix_rd *)&rn->p,
3863 bgp_static->tag);
3864 bgp_static_free (bgp_static);
3865 rn->info = NULL;
3866 bgp_unlock_node (rn);
3867 }
3868 }
3869 else
3870 {
3871 bgp_static = rn->info;
3872 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3873 bgp_static_free (bgp_static);
3874 rn->info = NULL;
3875 bgp_unlock_node (rn);
3876 }
3877 }
3878}
3879
3880int
fd79ac91 3881bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3882 const char *tag_str)
718e3744 3883{
3884 int ret;
3885 struct prefix p;
3886 struct prefix_rd prd;
3887 struct bgp *bgp;
3888 struct bgp_node *prn;
3889 struct bgp_node *rn;
3890 struct bgp_table *table;
3891 struct bgp_static *bgp_static;
3892 u_char tag[3];
3893
3894 bgp = vty->index;
3895
3896 ret = str2prefix (ip_str, &p);
3897 if (! ret)
3898 {
3899 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3900 return CMD_WARNING;
3901 }
3902 apply_mask (&p);
3903
3904 ret = str2prefix_rd (rd_str, &prd);
3905 if (! ret)
3906 {
3907 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3908 return CMD_WARNING;
3909 }
3910
3911 ret = str2tag (tag_str, tag);
3912 if (! ret)
3913 {
3914 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3915 return CMD_WARNING;
3916 }
3917
3918 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3919 (struct prefix *)&prd);
3920 if (prn->info == NULL)
64e580a7 3921 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
718e3744 3922 else
3923 bgp_unlock_node (prn);
3924 table = prn->info;
3925
3926 rn = bgp_node_get (table, &p);
3927
3928 if (rn->info)
3929 {
3930 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3931 bgp_unlock_node (rn);
3932 }
3933 else
3934 {
3935 /* New configuration. */
3936 bgp_static = bgp_static_new ();
3937 bgp_static->valid = 1;
3938 memcpy (bgp_static->tag, tag, 3);
3939 rn->info = bgp_static;
3940
3941 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3942 }
3943
3944 return CMD_SUCCESS;
3945}
3946
3947/* Configure static BGP network. */
3948int
fd79ac91 3949bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3950 const char *rd_str, const char *tag_str)
718e3744 3951{
3952 int ret;
3953 struct bgp *bgp;
3954 struct prefix p;
3955 struct prefix_rd prd;
3956 struct bgp_node *prn;
3957 struct bgp_node *rn;
3958 struct bgp_table *table;
3959 struct bgp_static *bgp_static;
3960 u_char tag[3];
3961
3962 bgp = vty->index;
3963
3964 /* Convert IP prefix string to struct prefix. */
3965 ret = str2prefix (ip_str, &p);
3966 if (! ret)
3967 {
3968 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3969 return CMD_WARNING;
3970 }
3971 apply_mask (&p);
3972
3973 ret = str2prefix_rd (rd_str, &prd);
3974 if (! ret)
3975 {
3976 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3977 return CMD_WARNING;
3978 }
3979
3980 ret = str2tag (tag_str, tag);
3981 if (! ret)
3982 {
3983 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3984 return CMD_WARNING;
3985 }
3986
3987 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3988 (struct prefix *)&prd);
3989 if (prn->info == NULL)
64e580a7 3990 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
718e3744 3991 else
3992 bgp_unlock_node (prn);
3993 table = prn->info;
3994
3995 rn = bgp_node_lookup (table, &p);
3996
3997 if (rn)
3998 {
3999 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4000
4001 bgp_static = rn->info;
4002 bgp_static_free (bgp_static);
4003 rn->info = NULL;
4004 bgp_unlock_node (rn);
4005 bgp_unlock_node (rn);
4006 }
4007 else
4008 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4009
4010 return CMD_SUCCESS;
4011}
4012\f
4013DEFUN (bgp_network,
4014 bgp_network_cmd,
4015 "network A.B.C.D/M",
4016 "Specify a network to announce via BGP\n"
4017 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4018{
4019 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 4020 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4021}
4022
4023DEFUN (bgp_network_route_map,
4024 bgp_network_route_map_cmd,
4025 "network A.B.C.D/M route-map WORD",
4026 "Specify a network to announce via BGP\n"
4027 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4028 "Route-map to modify the attributes\n"
4029 "Name of the route map\n")
4030{
4031 return bgp_static_set (vty, vty->index, argv[0],
c8f3fe30 4032 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 4033}
4034
4035DEFUN (bgp_network_backdoor,
4036 bgp_network_backdoor_cmd,
4037 "network A.B.C.D/M backdoor",
4038 "Specify a network to announce via BGP\n"
4039 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4040 "Specify a BGP backdoor route\n")
4041{
41367172 4042 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
c8f3fe30 4043 NULL, 1);
718e3744 4044}
4045
4046DEFUN (bgp_network_mask,
4047 bgp_network_mask_cmd,
4048 "network A.B.C.D mask A.B.C.D",
4049 "Specify a network to announce via BGP\n"
4050 "Network number\n"
4051 "Network mask\n"
4052 "Network mask\n")
4053{
4054 int ret;
4055 char prefix_str[BUFSIZ];
41367172 4056
718e3744 4057 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4058 if (! ret)
4059 {
4060 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4061 return CMD_WARNING;
4062 }
4063
4064 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4065 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4066}
4067
4068DEFUN (bgp_network_mask_route_map,
4069 bgp_network_mask_route_map_cmd,
4070 "network A.B.C.D mask A.B.C.D route-map WORD",
4071 "Specify a network to announce via BGP\n"
4072 "Network number\n"
4073 "Network mask\n"
4074 "Network mask\n"
4075 "Route-map to modify the attributes\n"
4076 "Name of the route map\n")
4077{
4078 int ret;
4079 char prefix_str[BUFSIZ];
41367172 4080
718e3744 4081 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4082 if (! ret)
4083 {
4084 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4085 return CMD_WARNING;
4086 }
4087
4088 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4089 AFI_IP, bgp_node_safi (vty), argv[2], 0);
718e3744 4090}
4091
4092DEFUN (bgp_network_mask_backdoor,
4093 bgp_network_mask_backdoor_cmd,
4094 "network A.B.C.D mask A.B.C.D backdoor",
4095 "Specify a network to announce via BGP\n"
4096 "Network number\n"
4097 "Network mask\n"
4098 "Network mask\n"
4099 "Specify a BGP backdoor route\n")
4100{
4101 int ret;
4102 char prefix_str[BUFSIZ];
41367172 4103
718e3744 4104 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4105 if (! ret)
4106 {
4107 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4108 return CMD_WARNING;
4109 }
4110
41367172 4111 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 4112 NULL, 1);
718e3744 4113}
4114
4115DEFUN (bgp_network_mask_natural,
4116 bgp_network_mask_natural_cmd,
4117 "network A.B.C.D",
4118 "Specify a network to announce via BGP\n"
4119 "Network number\n")
4120{
4121 int ret;
4122 char prefix_str[BUFSIZ];
4123
4124 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4125 if (! ret)
4126 {
4127 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4128 return CMD_WARNING;
4129 }
4130
4131 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4132 AFI_IP, bgp_node_safi (vty), NULL, 0);
718e3744 4133}
4134
4135DEFUN (bgp_network_mask_natural_route_map,
4136 bgp_network_mask_natural_route_map_cmd,
4137 "network A.B.C.D route-map WORD",
4138 "Specify a network to announce via BGP\n"
4139 "Network number\n"
4140 "Route-map to modify the attributes\n"
4141 "Name of the route map\n")
4142{
4143 int ret;
4144 char prefix_str[BUFSIZ];
4145
4146 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4147 if (! ret)
4148 {
4149 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4150 return CMD_WARNING;
4151 }
4152
4153 return bgp_static_set (vty, vty->index, prefix_str,
c8f3fe30 4154 AFI_IP, bgp_node_safi (vty), argv[1], 0);
718e3744 4155}
4156
4157DEFUN (bgp_network_mask_natural_backdoor,
4158 bgp_network_mask_natural_backdoor_cmd,
4159 "network A.B.C.D backdoor",
4160 "Specify a network to announce via BGP\n"
4161 "Network number\n"
4162 "Specify a BGP backdoor route\n")
4163{
4164 int ret;
4165 char prefix_str[BUFSIZ];
4166
4167 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4168 if (! ret)
4169 {
4170 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4171 return CMD_WARNING;
4172 }
4173
41367172 4174 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
c8f3fe30 4175 NULL, 1);
718e3744 4176}
4177
4178DEFUN (no_bgp_network,
4179 no_bgp_network_cmd,
4180 "no network A.B.C.D/M",
4181 NO_STR
4182 "Specify a network to announce via BGP\n"
4183 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4184{
4185 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4186 bgp_node_safi (vty));
4187}
4188
4189ALIAS (no_bgp_network,
4190 no_bgp_network_route_map_cmd,
4191 "no network A.B.C.D/M route-map WORD",
4192 NO_STR
4193 "Specify a network to announce via BGP\n"
4194 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4195 "Route-map to modify the attributes\n"
4196 "Name of the route map\n")
4197
4198ALIAS (no_bgp_network,
4199 no_bgp_network_backdoor_cmd,
4200 "no network A.B.C.D/M backdoor",
4201 NO_STR
4202 "Specify a network to announce via BGP\n"
4203 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4204 "Specify a BGP backdoor route\n")
4205
4206DEFUN (no_bgp_network_mask,
4207 no_bgp_network_mask_cmd,
4208 "no network A.B.C.D mask A.B.C.D",
4209 NO_STR
4210 "Specify a network to announce via BGP\n"
4211 "Network number\n"
4212 "Network mask\n"
4213 "Network mask\n")
4214{
4215 int ret;
4216 char prefix_str[BUFSIZ];
4217
4218 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4219 if (! ret)
4220 {
4221 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4222 return CMD_WARNING;
4223 }
4224
4225 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4226 bgp_node_safi (vty));
4227}
4228
4229ALIAS (no_bgp_network_mask,
4230 no_bgp_network_mask_route_map_cmd,
4231 "no network A.B.C.D mask A.B.C.D route-map WORD",
4232 NO_STR
4233 "Specify a network to announce via BGP\n"
4234 "Network number\n"
4235 "Network mask\n"
4236 "Network mask\n"
4237 "Route-map to modify the attributes\n"
4238 "Name of the route map\n")
4239
4240ALIAS (no_bgp_network_mask,
4241 no_bgp_network_mask_backdoor_cmd,
4242 "no network A.B.C.D mask A.B.C.D backdoor",
4243 NO_STR
4244 "Specify a network to announce via BGP\n"
4245 "Network number\n"
4246 "Network mask\n"
4247 "Network mask\n"
4248 "Specify a BGP backdoor route\n")
4249
4250DEFUN (no_bgp_network_mask_natural,
4251 no_bgp_network_mask_natural_cmd,
4252 "no network A.B.C.D",
4253 NO_STR
4254 "Specify a network to announce via BGP\n"
4255 "Network number\n")
4256{
4257 int ret;
4258 char prefix_str[BUFSIZ];
4259
4260 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4261 if (! ret)
4262 {
4263 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4264 return CMD_WARNING;
4265 }
4266
4267 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4268 bgp_node_safi (vty));
4269}
4270
4271ALIAS (no_bgp_network_mask_natural,
4272 no_bgp_network_mask_natural_route_map_cmd,
4273 "no network A.B.C.D route-map WORD",
4274 NO_STR
4275 "Specify a network to announce via BGP\n"
4276 "Network number\n"
4277 "Route-map to modify the attributes\n"
4278 "Name of the route map\n")
4279
4280ALIAS (no_bgp_network_mask_natural,
4281 no_bgp_network_mask_natural_backdoor_cmd,
4282 "no network A.B.C.D backdoor",
4283 NO_STR
4284 "Specify a network to announce via BGP\n"
4285 "Network number\n"
4286 "Specify a BGP backdoor route\n")
4287
4288#ifdef HAVE_IPV6
4289DEFUN (ipv6_bgp_network,
4290 ipv6_bgp_network_cmd,
4291 "network X:X::X:X/M",
4292 "Specify a network to announce via BGP\n"
4293 "IPv6 prefix <network>/<length>\n")
4294{
73bfe0bd 4295 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
c8f3fe30 4296 NULL, 0);
718e3744 4297}
4298
4299DEFUN (ipv6_bgp_network_route_map,
4300 ipv6_bgp_network_route_map_cmd,
4301 "network X:X::X:X/M route-map WORD",
4302 "Specify a network to announce via BGP\n"
4303 "IPv6 prefix <network>/<length>\n"
4304 "Route-map to modify the attributes\n"
4305 "Name of the route map\n")
4306{
4307 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
c8f3fe30 4308 bgp_node_safi (vty), argv[1], 0);
718e3744 4309}
4310
4311DEFUN (no_ipv6_bgp_network,
4312 no_ipv6_bgp_network_cmd,
4313 "no network X:X::X:X/M",
4314 NO_STR
4315 "Specify a network to announce via BGP\n"
4316 "IPv6 prefix <network>/<length>\n")
4317{
73bfe0bd 4318 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
718e3744 4319}
4320
4321ALIAS (no_ipv6_bgp_network,
4322 no_ipv6_bgp_network_route_map_cmd,
4323 "no network X:X::X:X/M route-map WORD",
4324 NO_STR
4325 "Specify a network to announce via BGP\n"
4326 "IPv6 prefix <network>/<length>\n"
4327 "Route-map to modify the attributes\n"
4328 "Name of the route map\n")
4329
4330ALIAS (ipv6_bgp_network,
4331 old_ipv6_bgp_network_cmd,
4332 "ipv6 bgp network X:X::X:X/M",
4333 IPV6_STR
4334 BGP_STR
4335 "Specify a network to announce via BGP\n"
4336 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4337
4338ALIAS (no_ipv6_bgp_network,
4339 old_no_ipv6_bgp_network_cmd,
4340 "no ipv6 bgp network X:X::X:X/M",
4341 NO_STR
4342 IPV6_STR
4343 BGP_STR
4344 "Specify a network to announce via BGP\n"
4345 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4346#endif /* HAVE_IPV6 */
c8f3fe30
PJ
4347
4348/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4349ALIAS_DEPRECATED (bgp_network,
4350 bgp_network_ttl_cmd,
4351 "network A.B.C.D/M pathlimit <0-255>",
4352 "Specify a network to announce via BGP\n"
4353 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4354 "AS-Path hopcount limit attribute\n"
4355 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4356ALIAS_DEPRECATED (bgp_network_backdoor,
4357 bgp_network_backdoor_ttl_cmd,
4358 "network A.B.C.D/M backdoor pathlimit <0-255>",
4359 "Specify a network to announce via BGP\n"
4360 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4361 "Specify a BGP backdoor route\n"
4362 "AS-Path hopcount limit attribute\n"
4363 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4364ALIAS_DEPRECATED (bgp_network_mask,
4365 bgp_network_mask_ttl_cmd,
4366 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4367 "Specify a network to announce via BGP\n"
4368 "Network number\n"
4369 "Network mask\n"
4370 "Network mask\n"
4371 "AS-Path hopcount limit attribute\n"
4372 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4373ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4374 bgp_network_mask_backdoor_ttl_cmd,
4375 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4376 "Specify a network to announce via BGP\n"
4377 "Network number\n"
4378 "Network mask\n"
4379 "Network mask\n"
4380 "Specify a BGP backdoor route\n"
4381 "AS-Path hopcount limit attribute\n"
4382 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4383ALIAS_DEPRECATED (bgp_network_mask_natural,
4384 bgp_network_mask_natural_ttl_cmd,
4385 "network A.B.C.D pathlimit <0-255>",
4386 "Specify a network to announce via BGP\n"
4387 "Network number\n"
4388 "AS-Path hopcount limit attribute\n"
4389 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4390ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4391 bgp_network_mask_natural_backdoor_ttl_cmd,
2b00515a 4392 "network A.B.C.D backdoor pathlimit <1-255>",
c8f3fe30
PJ
4393 "Specify a network to announce via BGP\n"
4394 "Network number\n"
4395 "Specify a BGP backdoor route\n"
4396 "AS-Path hopcount limit attribute\n"
4397 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4398ALIAS_DEPRECATED (no_bgp_network,
4399 no_bgp_network_ttl_cmd,
4400 "no network A.B.C.D/M pathlimit <0-255>",
4401 NO_STR
4402 "Specify a network to announce via BGP\n"
4403 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4404 "AS-Path hopcount limit attribute\n"
4405 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4406ALIAS_DEPRECATED (no_bgp_network,
4407 no_bgp_network_backdoor_ttl_cmd,
4408 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4409 NO_STR
4410 "Specify a network to announce via BGP\n"
4411 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4412 "Specify a BGP backdoor route\n"
4413 "AS-Path hopcount limit attribute\n"
4414 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4415ALIAS_DEPRECATED (no_bgp_network,
4416 no_bgp_network_mask_ttl_cmd,
4417 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4418 NO_STR
4419 "Specify a network to announce via BGP\n"
4420 "Network number\n"
4421 "Network mask\n"
4422 "Network mask\n"
4423 "AS-Path hopcount limit attribute\n"
4424 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4425ALIAS_DEPRECATED (no_bgp_network_mask,
4426 no_bgp_network_mask_backdoor_ttl_cmd,
4427 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4428 NO_STR
4429 "Specify a network to announce via BGP\n"
4430 "Network number\n"
4431 "Network mask\n"
4432 "Network mask\n"
4433 "Specify a BGP backdoor route\n"
4434 "AS-Path hopcount limit attribute\n"
4435 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4436ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4437 no_bgp_network_mask_natural_ttl_cmd,
4438 "no network A.B.C.D pathlimit <0-255>",
4439 NO_STR
4440 "Specify a network to announce via BGP\n"
4441 "Network number\n"
4442 "AS-Path hopcount limit attribute\n"
4443 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4444ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4445 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4446 "no network A.B.C.D backdoor pathlimit <0-255>",
4447 NO_STR
4448 "Specify a network to announce via BGP\n"
4449 "Network number\n"
4450 "Specify a BGP backdoor route\n"
4451 "AS-Path hopcount limit attribute\n"
4452 "AS-Pathlimit TTL, in number of AS-Path hops\n")
3bde17f1 4453#ifdef HAVE_IPV6
c8f3fe30
PJ
4454ALIAS_DEPRECATED (ipv6_bgp_network,
4455 ipv6_bgp_network_ttl_cmd,
4456 "network X:X::X:X/M pathlimit <0-255>",
4457 "Specify a network to announce via BGP\n"
4458 "IPv6 prefix <network>/<length>\n"
4459 "AS-Path hopcount limit attribute\n"
4460 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4461ALIAS_DEPRECATED (no_ipv6_bgp_network,
4462 no_ipv6_bgp_network_ttl_cmd,
4463 "no network X:X::X:X/M pathlimit <0-255>",
4464 NO_STR
4465 "Specify a network to announce via BGP\n"
4466 "IPv6 prefix <network>/<length>\n"
4467 "AS-Path hopcount limit attribute\n"
4468 "AS-Pathlimit TTL, in number of AS-Path hops\n")
3bde17f1 4469#endif /* HAVE_IPV6 */
718e3744 4470\f
4471/* Aggreagete address:
4472
4473 advertise-map Set condition to advertise attribute
4474 as-set Generate AS set path information
4475 attribute-map Set attributes of aggregate
4476 route-map Set parameters of aggregate
4477 summary-only Filter more specific routes from updates
4478 suppress-map Conditionally filter more specific routes from updates
4479 <cr>
4480 */
4481struct bgp_aggregate
4482{
4483 /* Summary-only flag. */
4484 u_char summary_only;
4485
4486 /* AS set generation. */
4487 u_char as_set;
4488
4489 /* Route-map for aggregated route. */
4490 struct route_map *map;
4491
4492 /* Suppress-count. */
4493 unsigned long count;
4494
4495 /* SAFI configuration. */
4496 safi_t safi;
4497};
4498
94f2b392 4499static struct bgp_aggregate *
66e5cd87 4500bgp_aggregate_new (void)
718e3744 4501{
393deb9b 4502 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
718e3744 4503}
4504
94f2b392 4505static void
718e3744 4506bgp_aggregate_free (struct bgp_aggregate *aggregate)
4507{
4508 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4509}
4510
94f2b392 4511static void
718e3744 4512bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4513 afi_t afi, safi_t safi, struct bgp_info *del,
4514 struct bgp_aggregate *aggregate)
4515{
4516 struct bgp_table *table;
4517 struct bgp_node *top;
4518 struct bgp_node *rn;
4519 u_char origin;
4520 struct aspath *aspath = NULL;
4521 struct aspath *asmerge = NULL;
4522 struct community *community = NULL;
4523 struct community *commerge = NULL;
4524 struct in_addr nexthop;
4525 u_int32_t med = 0;
4526 struct bgp_info *ri;
4527 struct bgp_info *new;
4528 int first = 1;
4529 unsigned long match = 0;
4530
4531 /* Record adding route's nexthop and med. */
4532 if (rinew)
4533 {
4534 nexthop = rinew->attr->nexthop;
4535 med = rinew->attr->med;
4536 }
4537
4538 /* ORIGIN attribute: If at least one route among routes that are
4539 aggregated has ORIGIN with the value INCOMPLETE, then the
4540 aggregated route must have the ORIGIN attribute with the value
4541 INCOMPLETE. Otherwise, if at least one route among routes that
4542 are aggregated has ORIGIN with the value EGP, then the aggregated
4543 route must have the origin attribute with the value EGP. In all
4544 other case the value of the ORIGIN attribute of the aggregated
4545 route is INTERNAL. */
4546 origin = BGP_ORIGIN_IGP;
4547
4548 table = bgp->rib[afi][safi];
4549
4550 top = bgp_node_get (table, p);
4551 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4552 if (rn->p.prefixlen > p->prefixlen)
4553 {
4554 match = 0;
4555
4556 for (ri = rn->info; ri; ri = ri->next)
4557 {
4558 if (BGP_INFO_HOLDDOWN (ri))
4559 continue;
4560
4561 if (del && ri == del)
4562 continue;
4563
4564 if (! rinew && first)
4565 {
4566 nexthop = ri->attr->nexthop;
4567 med = ri->attr->med;
4568 first = 0;
4569 }
4570
4571#ifdef AGGREGATE_NEXTHOP_CHECK
4572 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4573 || ri->attr->med != med)
4574 {
4575 if (aspath)
4576 aspath_free (aspath);
4577 if (community)
4578 community_free (community);
4579 bgp_unlock_node (rn);
4580 bgp_unlock_node (top);
4581 return;
4582 }
4583#endif /* AGGREGATE_NEXTHOP_CHECK */
4584
4585 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4586 {
4587 if (aggregate->summary_only)
4588 {
fb982c25 4589 (bgp_info_extra_get (ri))->suppress++;
1a392d46 4590 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4591 match++;
4592 }
4593
4594 aggregate->count++;
4595
4596 if (aggregate->as_set)
4597 {
4598 if (origin < ri->attr->origin)
4599 origin = ri->attr->origin;
4600
4601 if (aspath)
4602 {
4603 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4604 aspath_free (aspath);
4605 aspath = asmerge;
4606 }
4607 else
4608 aspath = aspath_dup (ri->attr->aspath);
4609
4610 if (ri->attr->community)
4611 {
4612 if (community)
4613 {
4614 commerge = community_merge (community,
4615 ri->attr->community);
4616 community = community_uniq_sort (commerge);
4617 community_free (commerge);
4618 }
4619 else
4620 community = community_dup (ri->attr->community);
4621 }
4622 }
4623 }
4624 }
4625 if (match)
4626 bgp_process (bgp, rn, afi, safi);
4627 }
4628 bgp_unlock_node (top);
4629
4630 if (rinew)
4631 {
4632 aggregate->count++;
4633
4634 if (aggregate->summary_only)
fb982c25 4635 (bgp_info_extra_get (rinew))->suppress++;
718e3744 4636
4637 if (aggregate->as_set)
4638 {
4639 if (origin < rinew->attr->origin)
4640 origin = rinew->attr->origin;
4641
4642 if (aspath)
4643 {
4644 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4645 aspath_free (aspath);
4646 aspath = asmerge;
4647 }
4648 else
4649 aspath = aspath_dup (rinew->attr->aspath);
4650
4651 if (rinew->attr->community)
4652 {
4653 if (community)
4654 {
4655 commerge = community_merge (community,
4656 rinew->attr->community);
4657 community = community_uniq_sort (commerge);
4658 community_free (commerge);
4659 }
4660 else
4661 community = community_dup (rinew->attr->community);
4662 }
4663 }
4664 }
4665
4666 if (aggregate->count > 0)
4667 {
4668 rn = bgp_node_get (table, p);
4669 new = bgp_info_new ();
4670 new->type = ZEBRA_ROUTE_BGP;
4671 new->sub_type = BGP_ROUTE_AGGREGATE;
4672 new->peer = bgp->peer_self;
4673 SET_FLAG (new->flags, BGP_INFO_VALID);
4674 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
65957886 4675 new->uptime = bgp_clock ();
718e3744 4676
4677 bgp_info_add (rn, new);
200df115 4678 bgp_unlock_node (rn);
718e3744 4679 bgp_process (bgp, rn, afi, safi);
4680 }
4681 else
4682 {
4683 if (aspath)
4684 aspath_free (aspath);
4685 if (community)
4686 community_free (community);
4687 }
4688}
4689
4690void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4691 struct bgp_aggregate *);
4692
4693void
4694bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4695 struct bgp_info *ri, afi_t afi, safi_t safi)
4696{
4697 struct bgp_node *child;
4698 struct bgp_node *rn;
4699 struct bgp_aggregate *aggregate;
f018db83 4700 struct bgp_table *table;
718e3744 4701
4702 /* MPLS-VPN aggregation is not yet supported. */
4703 if (safi == SAFI_MPLS_VPN)
4704 return;
4705
f018db83
JBD
4706 table = bgp->aggregate[afi][safi];
4707
4708 /* No aggregates configured. */
67174041 4709 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
4710 return;
4711
718e3744 4712 if (p->prefixlen == 0)
4713 return;
4714
4715 if (BGP_INFO_HOLDDOWN (ri))
4716 return;
4717
bb782fb5 4718 child = bgp_node_get (table, p);
718e3744 4719
4720 /* Aggregate address configuration check. */
67174041 4721 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 4722 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4723 {
4724 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 4725 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
718e3744 4726 }
4727 bgp_unlock_node (child);
4728}
4729
4730void
4731bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4732 struct bgp_info *del, afi_t afi, safi_t safi)
4733{
4734 struct bgp_node *child;
4735 struct bgp_node *rn;
4736 struct bgp_aggregate *aggregate;
f018db83 4737 struct bgp_table *table;
718e3744 4738
4739 /* MPLS-VPN aggregation is not yet supported. */
4740 if (safi == SAFI_MPLS_VPN)
4741 return;
4742
f018db83
JBD
4743 table = bgp->aggregate[afi][safi];
4744
4745 /* No aggregates configured. */
67174041 4746 if (bgp_table_top_nolock (table) == NULL)
f018db83
JBD
4747 return;
4748
718e3744 4749 if (p->prefixlen == 0)
4750 return;
4751
bb782fb5 4752 child = bgp_node_get (table, p);
718e3744 4753
4754 /* Aggregate address configuration check. */
67174041 4755 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
718e3744 4756 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4757 {
4758 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
286e1e71 4759 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
718e3744 4760 }
4761 bgp_unlock_node (child);
4762}
4763
94f2b392 4764static void
718e3744 4765bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4766 struct bgp_aggregate *aggregate)
4767{
4768 struct bgp_table *table;
4769 struct bgp_node *top;
4770 struct bgp_node *rn;
4771 struct bgp_info *new;
4772 struct bgp_info *ri;
4773 unsigned long match;
4774 u_char origin = BGP_ORIGIN_IGP;
4775 struct aspath *aspath = NULL;
4776 struct aspath *asmerge = NULL;
4777 struct community *community = NULL;
4778 struct community *commerge = NULL;
4779
4780 table = bgp->rib[afi][safi];
4781
4782 /* Sanity check. */
4783 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4784 return;
4785 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4786 return;
4787
4788 /* If routes exists below this node, generate aggregate routes. */
4789 top = bgp_node_get (table, p);
4790 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4791 if (rn->p.prefixlen > p->prefixlen)
4792 {
4793 match = 0;
4794
4795 for (ri = rn->info; ri; ri = ri->next)
4796 {
4797 if (BGP_INFO_HOLDDOWN (ri))
4798 continue;
4799
4800 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4801 {
4802 /* summary-only aggregate route suppress aggregated
4803 route announcement. */
4804 if (aggregate->summary_only)
4805 {
fb982c25 4806 (bgp_info_extra_get (ri))->suppress++;
1a392d46 4807 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4808 match++;
4809 }
4810 /* as-set aggregate route generate origin, as path,
4811 community aggregation. */
4812 if (aggregate->as_set)
4813 {
4814 if (origin < ri->attr->origin)
4815 origin = ri->attr->origin;
4816
4817 if (aspath)
4818 {
4819 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4820 aspath_free (aspath);
4821 aspath = asmerge;
4822 }
4823 else
4824 aspath = aspath_dup (ri->attr->aspath);
4825
4826 if (ri->attr->community)
4827 {
4828 if (community)
4829 {
4830 commerge = community_merge (community,
4831 ri->attr->community);
4832 community = community_uniq_sort (commerge);
4833 community_free (commerge);
4834 }
4835 else
4836 community = community_dup (ri->attr->community);
4837 }
4838 }
4839 aggregate->count++;
4840 }
4841 }
4842
4843 /* If this node is suppressed, process the change. */
4844 if (match)
4845 bgp_process (bgp, rn, afi, safi);
4846 }
4847 bgp_unlock_node (top);
4848
4849 /* Add aggregate route to BGP table. */
4850 if (aggregate->count)
4851 {
4852 rn = bgp_node_get (table, p);
4853
4854 new = bgp_info_new ();
4855 new->type = ZEBRA_ROUTE_BGP;
4856 new->sub_type = BGP_ROUTE_AGGREGATE;
4857 new->peer = bgp->peer_self;
4858 SET_FLAG (new->flags, BGP_INFO_VALID);
4859 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
65957886 4860 new->uptime = bgp_clock ();
718e3744 4861
4862 bgp_info_add (rn, new);
200df115 4863 bgp_unlock_node (rn);
4864
718e3744 4865 /* Process change. */
4866 bgp_process (bgp, rn, afi, safi);
4867 }
4868}
4869
4870void
4871bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4872 safi_t safi, struct bgp_aggregate *aggregate)
4873{
4874 struct bgp_table *table;
4875 struct bgp_node *top;
4876 struct bgp_node *rn;
4877 struct bgp_info *ri;
4878 unsigned long match;
4879
4880 table = bgp->rib[afi][safi];
4881
4882 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4883 return;
4884 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4885 return;
4886
4887 /* If routes exists below this node, generate aggregate routes. */
4888 top = bgp_node_get (table, p);
4889 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4890 if (rn->p.prefixlen > p->prefixlen)
4891 {
4892 match = 0;
4893
4894 for (ri = rn->info; ri; ri = ri->next)
4895 {
4896 if (BGP_INFO_HOLDDOWN (ri))
4897 continue;
4898
4899 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4900 {
fb982c25 4901 if (aggregate->summary_only && ri->extra)
718e3744 4902 {
fb982c25 4903 ri->extra->suppress--;
718e3744 4904
fb982c25 4905 if (ri->extra->suppress == 0)
718e3744 4906 {
1a392d46 4907 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
718e3744 4908 match++;
4909 }
4910 }
4911 aggregate->count--;
4912 }
4913 }
4914
fb982c25 4915 /* If this node was suppressed, process the change. */
718e3744 4916 if (match)
4917 bgp_process (bgp, rn, afi, safi);
4918 }
4919 bgp_unlock_node (top);
4920
4921 /* Delete aggregate route from BGP table. */
4922 rn = bgp_node_get (table, p);
4923
4924 for (ri = rn->info; ri; ri = ri->next)
4925 if (ri->peer == bgp->peer_self
4926 && ri->type == ZEBRA_ROUTE_BGP
4927 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4928 break;
4929
4930 /* Withdraw static BGP route from routing table. */
4931 if (ri)
4932 {
718e3744 4933 bgp_info_delete (rn, ri);
1a392d46 4934 bgp_process (bgp, rn, afi, safi);
718e3744 4935 }
4936
4937 /* Unlock bgp_node_lookup. */
4938 bgp_unlock_node (rn);
4939}
4940
4941/* Aggregate route attribute. */
4942#define AGGREGATE_SUMMARY_ONLY 1
4943#define AGGREGATE_AS_SET 1
4944
94f2b392 4945static int
f6269b4f
RB
4946bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4947 afi_t afi, safi_t safi)
718e3744 4948{
4949 int ret;
4950 struct prefix p;
4951 struct bgp_node *rn;
4952 struct bgp *bgp;
4953 struct bgp_aggregate *aggregate;
4954
4955 /* Convert string to prefix structure. */
4956 ret = str2prefix (prefix_str, &p);
4957 if (!ret)
4958 {
4959 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4960 return CMD_WARNING;
4961 }
4962 apply_mask (&p);
4963
4964 /* Get BGP structure. */
4965 bgp = vty->index;
4966
4967 /* Old configuration check. */
f6269b4f
RB
4968 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4969 if (! rn)
718e3744 4970 {
f6269b4f
RB
4971 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4972 VTY_NEWLINE);
718e3744 4973 return CMD_WARNING;
4974 }
4975
f6269b4f
RB
4976 aggregate = rn->info;
4977 if (aggregate->safi & SAFI_UNICAST)
4978 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4979 if (aggregate->safi & SAFI_MULTICAST)
4980 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 4981
f6269b4f
RB
4982 /* Unlock aggregate address configuration. */
4983 rn->info = NULL;
4984 bgp_aggregate_free (aggregate);
4985 bgp_unlock_node (rn);
4986 bgp_unlock_node (rn);
718e3744 4987
4988 return CMD_SUCCESS;
4989}
4990
94f2b392 4991static int
f6269b4f
RB
4992bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4993 afi_t afi, safi_t safi,
4994 u_char summary_only, u_char as_set)
718e3744 4995{
4996 int ret;
4997 struct prefix p;
4998 struct bgp_node *rn;
4999 struct bgp *bgp;
5000 struct bgp_aggregate *aggregate;
5001
5002 /* Convert string to prefix structure. */
5003 ret = str2prefix (prefix_str, &p);
5004 if (!ret)
5005 {
5006 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5007 return CMD_WARNING;
5008 }
5009 apply_mask (&p);
5010
5011 /* Get BGP structure. */
5012 bgp = vty->index;
5013
5014 /* Old configuration check. */
f6269b4f
RB
5015 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5016
5017 if (rn->info)
718e3744 5018 {
f6269b4f 5019 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
368473f6 5020 /* try to remove the old entry */
f6269b4f
RB
5021 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5022 if (ret)
5023 {
368473f6
RB
5024 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5025 bgp_unlock_node (rn);
f6269b4f
RB
5026 return CMD_WARNING;
5027 }
718e3744 5028 }
5029
f6269b4f
RB
5030 /* Make aggregate address structure. */
5031 aggregate = bgp_aggregate_new ();
5032 aggregate->summary_only = summary_only;
5033 aggregate->as_set = as_set;
5034 aggregate->safi = safi;
5035 rn->info = aggregate;
718e3744 5036
f6269b4f
RB
5037 /* Aggregate address insert into BGP routing table. */
5038 if (safi & SAFI_UNICAST)
5039 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5040 if (safi & SAFI_MULTICAST)
5041 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
718e3744 5042
5043 return CMD_SUCCESS;
5044}
5045
5046DEFUN (aggregate_address,
5047 aggregate_address_cmd,
5048 "aggregate-address A.B.C.D/M",
5049 "Configure BGP aggregate entries\n"
5050 "Aggregate prefix\n")
5051{
5052 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5053}
5054
5055DEFUN (aggregate_address_mask,
5056 aggregate_address_mask_cmd,
5057 "aggregate-address A.B.C.D A.B.C.D",
5058 "Configure BGP aggregate entries\n"
5059 "Aggregate address\n"
5060 "Aggregate mask\n")
5061{
5062 int ret;
5063 char prefix_str[BUFSIZ];
5064
5065 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5066
5067 if (! ret)
5068 {
5069 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5070 return CMD_WARNING;
5071 }
5072
5073 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5074 0, 0);
5075}
5076
5077DEFUN (aggregate_address_summary_only,
5078 aggregate_address_summary_only_cmd,
5079 "aggregate-address A.B.C.D/M summary-only",
5080 "Configure BGP aggregate entries\n"
5081 "Aggregate prefix\n"
5082 "Filter more specific routes from updates\n")
5083{
5084 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5085 AGGREGATE_SUMMARY_ONLY, 0);
5086}
5087
5088DEFUN (aggregate_address_mask_summary_only,
5089 aggregate_address_mask_summary_only_cmd,
5090 "aggregate-address A.B.C.D A.B.C.D summary-only",
5091 "Configure BGP aggregate entries\n"
5092 "Aggregate address\n"
5093 "Aggregate mask\n"
5094 "Filter more specific routes from updates\n")
5095{
5096 int ret;
5097 char prefix_str[BUFSIZ];
5098
5099 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5100
5101 if (! ret)
5102 {
5103 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5104 return CMD_WARNING;
5105 }
5106
5107 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5108 AGGREGATE_SUMMARY_ONLY, 0);
5109}
5110
5111DEFUN (aggregate_address_as_set,
5112 aggregate_address_as_set_cmd,
5113 "aggregate-address A.B.C.D/M as-set",
5114 "Configure BGP aggregate entries\n"
5115 "Aggregate prefix\n"
5116 "Generate AS set path information\n")
5117{
5118 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5119 0, AGGREGATE_AS_SET);
5120}
5121
5122DEFUN (aggregate_address_mask_as_set,
5123 aggregate_address_mask_as_set_cmd,
5124 "aggregate-address A.B.C.D A.B.C.D as-set",
5125 "Configure BGP aggregate entries\n"
5126 "Aggregate address\n"
5127 "Aggregate mask\n"
5128 "Generate AS set path information\n")
5129{
5130 int ret;
5131 char prefix_str[BUFSIZ];
5132
5133 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5134
5135 if (! ret)
5136 {
5137 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5138 return CMD_WARNING;
5139 }
5140
5141 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5142 0, AGGREGATE_AS_SET);
5143}
5144
5145
5146DEFUN (aggregate_address_as_set_summary,
5147 aggregate_address_as_set_summary_cmd,
5148 "aggregate-address A.B.C.D/M as-set summary-only",
5149 "Configure BGP aggregate entries\n"
5150 "Aggregate prefix\n"
5151 "Generate AS set path information\n"
5152 "Filter more specific routes from updates\n")
5153{
5154 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5155 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5156}
5157
5158ALIAS (aggregate_address_as_set_summary,
5159 aggregate_address_summary_as_set_cmd,
5160 "aggregate-address A.B.C.D/M summary-only as-set",
5161 "Configure BGP aggregate entries\n"
5162 "Aggregate prefix\n"
5163 "Filter more specific routes from updates\n"
5164 "Generate AS set path information\n")
5165
5166DEFUN (aggregate_address_mask_as_set_summary,
5167 aggregate_address_mask_as_set_summary_cmd,
5168 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5169 "Configure BGP aggregate entries\n"
5170 "Aggregate address\n"
5171 "Aggregate mask\n"
5172 "Generate AS set path information\n"
5173 "Filter more specific routes from updates\n")
5174{
5175 int ret;
5176 char prefix_str[BUFSIZ];
5177
5178 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5179
5180 if (! ret)
5181 {
5182 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5183 return CMD_WARNING;
5184 }
5185
5186 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5187 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5188}
5189
5190ALIAS (aggregate_address_mask_as_set_summary,
5191 aggregate_address_mask_summary_as_set_cmd,
5192 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5193 "Configure BGP aggregate entries\n"
5194 "Aggregate address\n"
5195 "Aggregate mask\n"
5196 "Filter more specific routes from updates\n"
5197 "Generate AS set path information\n")
5198
5199DEFUN (no_aggregate_address,
5200 no_aggregate_address_cmd,
5201 "no aggregate-address A.B.C.D/M",
5202 NO_STR
5203 "Configure BGP aggregate entries\n"
5204 "Aggregate prefix\n")
5205{
5206 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5207}
5208
5209ALIAS (no_aggregate_address,
5210 no_aggregate_address_summary_only_cmd,
5211 "no aggregate-address A.B.C.D/M summary-only",
5212 NO_STR
5213 "Configure BGP aggregate entries\n"
5214 "Aggregate prefix\n"
5215 "Filter more specific routes from updates\n")
5216
5217ALIAS (no_aggregate_address,
5218 no_aggregate_address_as_set_cmd,
5219 "no aggregate-address A.B.C.D/M as-set",
5220 NO_STR
5221 "Configure BGP aggregate entries\n"
5222 "Aggregate prefix\n"
5223 "Generate AS set path information\n")
5224
5225ALIAS (no_aggregate_address,
5226 no_aggregate_address_as_set_summary_cmd,
5227 "no aggregate-address A.B.C.D/M as-set summary-only",
5228 NO_STR
5229 "Configure BGP aggregate entries\n"
5230 "Aggregate prefix\n"
5231 "Generate AS set path information\n"
5232 "Filter more specific routes from updates\n")
5233
5234ALIAS (no_aggregate_address,
5235 no_aggregate_address_summary_as_set_cmd,
5236 "no aggregate-address A.B.C.D/M summary-only as-set",
5237 NO_STR
5238 "Configure BGP aggregate entries\n"
5239 "Aggregate prefix\n"
5240 "Filter more specific routes from updates\n"
5241 "Generate AS set path information\n")
5242
5243DEFUN (no_aggregate_address_mask,
5244 no_aggregate_address_mask_cmd,
5245 "no aggregate-address A.B.C.D A.B.C.D",
5246 NO_STR
5247 "Configure BGP aggregate entries\n"
5248 "Aggregate address\n"
5249 "Aggregate mask\n")
5250{
5251 int ret;
5252 char prefix_str[BUFSIZ];
5253
5254 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5255
5256 if (! ret)
5257 {
5258 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5259 return CMD_WARNING;
5260 }
5261
5262 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5263}
5264
5265ALIAS (no_aggregate_address_mask,
5266 no_aggregate_address_mask_summary_only_cmd,
5267 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5268 NO_STR
5269 "Configure BGP aggregate entries\n"
5270 "Aggregate address\n"
5271 "Aggregate mask\n"
5272 "Filter more specific routes from updates\n")
5273
5274ALIAS (no_aggregate_address_mask,
5275 no_aggregate_address_mask_as_set_cmd,
5276 "no aggregate-address A.B.C.D A.B.C.D as-set",
5277 NO_STR
5278 "Configure BGP aggregate entries\n"
5279 "Aggregate address\n"
5280 "Aggregate mask\n"
5281 "Generate AS set path information\n")
5282
5283ALIAS (no_aggregate_address_mask,
5284 no_aggregate_address_mask_as_set_summary_cmd,
5285 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5286 NO_STR
5287 "Configure BGP aggregate entries\n"
5288 "Aggregate address\n"
5289 "Aggregate mask\n"
5290 "Generate AS set path information\n"
5291 "Filter more specific routes from updates\n")
5292
5293ALIAS (no_aggregate_address_mask,
5294 no_aggregate_address_mask_summary_as_set_cmd,
5295 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5296 NO_STR
5297 "Configure BGP aggregate entries\n"
5298 "Aggregate address\n"
5299 "Aggregate mask\n"
5300 "Filter more specific routes from updates\n"
5301 "Generate AS set path information\n")
5302
5303#ifdef HAVE_IPV6
5304DEFUN (ipv6_aggregate_address,
5305 ipv6_aggregate_address_cmd,
5306 "aggregate-address X:X::X:X/M",
5307 "Configure BGP aggregate entries\n"
5308 "Aggregate prefix\n")
5309{
5310 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5311}
5312
5313DEFUN (ipv6_aggregate_address_summary_only,
5314 ipv6_aggregate_address_summary_only_cmd,
5315 "aggregate-address X:X::X:X/M summary-only",
5316 "Configure BGP aggregate entries\n"
5317 "Aggregate prefix\n"
5318 "Filter more specific routes from updates\n")
5319{
5320 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5321 AGGREGATE_SUMMARY_ONLY, 0);
5322}
5323
5324DEFUN (no_ipv6_aggregate_address,
5325 no_ipv6_aggregate_address_cmd,
5326 "no aggregate-address X:X::X:X/M",
5327 NO_STR
5328 "Configure BGP aggregate entries\n"
5329 "Aggregate prefix\n")
5330{
5331 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5332}
5333
5334DEFUN (no_ipv6_aggregate_address_summary_only,
5335 no_ipv6_aggregate_address_summary_only_cmd,
5336 "no aggregate-address X:X::X:X/M summary-only",
5337 NO_STR
5338 "Configure BGP aggregate entries\n"
5339 "Aggregate prefix\n"
5340 "Filter more specific routes from updates\n")
5341{
5342 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5343}
5344
5345ALIAS (ipv6_aggregate_address,
5346 old_ipv6_aggregate_address_cmd,
5347 "ipv6 bgp aggregate-address X:X::X:X/M",
5348 IPV6_STR
5349 BGP_STR
5350 "Configure BGP aggregate entries\n"
5351 "Aggregate prefix\n")
5352
5353ALIAS (ipv6_aggregate_address_summary_only,
5354 old_ipv6_aggregate_address_summary_only_cmd,
5355 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5356 IPV6_STR
5357 BGP_STR
5358 "Configure BGP aggregate entries\n"
5359 "Aggregate prefix\n"
5360 "Filter more specific routes from updates\n")
5361
5362ALIAS (no_ipv6_aggregate_address,
5363 old_no_ipv6_aggregate_address_cmd,
5364 "no ipv6 bgp aggregate-address X:X::X:X/M",
5365 NO_STR
5366 IPV6_STR
5367 BGP_STR
5368 "Configure BGP aggregate entries\n"
5369 "Aggregate prefix\n")
5370
5371ALIAS (no_ipv6_aggregate_address_summary_only,
5372 old_no_ipv6_aggregate_address_summary_only_cmd,
5373 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5374 NO_STR
5375 IPV6_STR
5376 BGP_STR
5377 "Configure BGP aggregate entries\n"
5378 "Aggregate prefix\n"
5379 "Filter more specific routes from updates\n")
5380#endif /* HAVE_IPV6 */
5381\f
5382/* Redistribute route treatment. */
5383void
f04a80a5
SH
5384bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5385 const struct in6_addr *nexthop6,
718e3744 5386 u_int32_t metric, u_char type)
5387{
5388 struct bgp *bgp;
1eb8ef25 5389 struct listnode *node, *nnode;
718e3744 5390 struct bgp_info *new;
5391 struct bgp_info *bi;
5392 struct bgp_info info;
5393 struct bgp_node *bn;
e16a4133 5394 struct attr attr;
718e3744 5395 struct attr *new_attr;
5396 afi_t afi;
5397 int ret;
5398
5399 /* Make default attribute. */
5400 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5401 if (nexthop)
5402 attr.nexthop = *nexthop;
5403
f04a80a5
SH
5404#ifdef HAVE_IPV6
5405 if (nexthop6)
5406 {
5407 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5408 extra->mp_nexthop_global = *nexthop6;
5409 extra->mp_nexthop_len = 16;
5410 }
5411#endif
5412
718e3744 5413 attr.med = metric;
5414 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5415
1eb8ef25 5416 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 5417 {
5418 afi = family2afi (p->family);
5419
5420 if (bgp->redist[afi][type])
5421 {
558d1fec
JBD
5422 struct attr attr_new;
5423 struct attr_extra extra_new;
5424
718e3744 5425 /* Copy attribute for modification. */
558d1fec 5426 attr_new.extra = &extra_new;
fb982c25 5427 bgp_attr_dup (&attr_new, &attr);
718e3744 5428
5429 if (bgp->redist_metric_flag[afi][type])
5430 attr_new.med = bgp->redist_metric[afi][type];
5431
5432 /* Apply route-map. */
5433 if (bgp->rmap[afi][type].map)
5434 {
5435 info.peer = bgp->peer_self;
5436 info.attr = &attr_new;
5437
fee0f4c6 5438 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5439
718e3744 5440 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5441 &info);
fee0f4c6 5442
5443 bgp->peer_self->rmap_type = 0;
5444
718e3744 5445 if (ret == RMAP_DENYMATCH)
5446 {
5447 /* Free uninterned attribute. */
5448 bgp_attr_flush (&attr_new);
558d1fec 5449
718e3744 5450 /* Unintern original. */
f6f434b2 5451 aspath_unintern (&attr.aspath);
fb982c25 5452 bgp_attr_extra_free (&attr);
718e3744 5453 bgp_redistribute_delete (p, type);
5454 return;
5455 }
5456 }
5457
fb982c25
PJ
5458 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5459 afi, SAFI_UNICAST, p, NULL);
5460
718e3744 5461 new_attr = bgp_attr_intern (&attr_new);
558d1fec 5462
718e3744 5463 for (bi = bn->info; bi; bi = bi->next)
5464 if (bi->peer == bgp->peer_self
5465 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5466 break;
5467
5468 if (bi)
5469 {
8d45210e
AS
5470 if (attrhash_cmp (bi->attr, new_attr) &&
5471 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
718e3744 5472 {
f6f434b2
PJ
5473 bgp_attr_unintern (&new_attr);
5474 aspath_unintern (&attr.aspath);
fb982c25 5475 bgp_attr_extra_free (&attr);
718e3744 5476 bgp_unlock_node (bn);
5477 return;
5478 }
5479 else
5480 {
5481 /* The attribute is changed. */
1a392d46 5482 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
718e3744 5483
5484 /* Rewrite BGP route information. */
8d45210e
AS
5485 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5486 bgp_info_restore(bn, bi);
5487 else
5488 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
f6f434b2 5489 bgp_attr_unintern (&bi->attr);
718e3744 5490 bi->attr = new_attr;
65957886 5491 bi->uptime = bgp_clock ();
718e3744 5492
5493 /* Process change. */
5494 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5495 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5496 bgp_unlock_node (bn);
f6f434b2 5497 aspath_unintern (&attr.aspath);
fb982c25 5498 bgp_attr_extra_free (&attr);
718e3744 5499 return;
5500 }
5501 }
5502
5503 new = bgp_info_new ();
5504 new->type = type;
5505 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5506 new->peer = bgp->peer_self;
5507 SET_FLAG (new->flags, BGP_INFO_VALID);
5508 new->attr = new_attr;
65957886 5509 new->uptime = bgp_clock ();
718e3744 5510
5511 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5512 bgp_info_add (bn, new);
200df115 5513 bgp_unlock_node (bn);
718e3744 5514 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5515 }
5516 }
5517
5518 /* Unintern original. */
f6f434b2 5519 aspath_unintern (&attr.aspath);
fb982c25 5520 bgp_attr_extra_free (&attr);
718e3744 5521}
5522
5523void
5524bgp_redistribute_delete (struct prefix *p, u_char type)
5525{
5526 struct bgp *bgp;
1eb8ef25 5527 struct listnode *node, *nnode;
718e3744 5528 afi_t afi;
5529 struct bgp_node *rn;
5530 struct bgp_info *ri;
5531
1eb8ef25 5532 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
718e3744 5533 {
5534 afi = family2afi (p->family);
5535
5536 if (bgp->redist[afi][type])
5537 {
fee0f4c6 5538 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
718e3744 5539
5540 for (ri = rn->info; ri; ri = ri->next)
5541 if (ri->peer == bgp->peer_self
5542 && ri->type == type)
5543 break;
5544
5545 if (ri)
5546 {
5547 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
718e3744 5548 bgp_info_delete (rn, ri);
1a392d46 5549 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 5550 }
5551 bgp_unlock_node (rn);
5552 }
5553 }
5554}
5555
5556/* Withdraw specified route type's route. */
5557void
5558bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5559{
5560 struct bgp_node *rn;
5561 struct bgp_info *ri;
5562 struct bgp_table *table;
5563
5564 table = bgp->rib[afi][SAFI_UNICAST];
5565
5566 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5567 {
5568 for (ri = rn->info; ri; ri = ri->next)
5569 if (ri->peer == bgp->peer_self
5570 && ri->type == type)
5571 break;
5572
5573 if (ri)
5574 {
5575 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
718e3744 5576 bgp_info_delete (rn, ri);
1a392d46 5577 bgp_process (bgp, rn, afi, SAFI_UNICAST);
718e3744 5578 }
5579 }
5580}
5581\f
5582/* Static function to display route. */
94f2b392 5583static void
718e3744 5584route_vty_out_route (struct prefix *p, struct vty *vty)
5585{
5586 int len;
5587 u_int32_t destination;
5588 char buf[BUFSIZ];
5589
5590 if (p->family == AF_INET)
5591 {
5592 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5593 destination = ntohl (p->u.prefix4.s_addr);
5594
5595 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5596 || (IN_CLASSB (destination) && p->prefixlen == 16)
5597 || (IN_CLASSA (destination) && p->prefixlen == 8)
5598 || p->u.prefix4.s_addr == 0)
5599 {
5600 /* When mask is natural, mask is not displayed. */
5601 }
5602 else
5603 len += vty_out (vty, "/%d", p->prefixlen);
5604 }
5605 else
5606 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5607 p->prefixlen);
5608
5609 len = 17 - len;
5610 if (len < 1)
5611 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5612 else
5613 vty_out (vty, "%*s", len, " ");
5614}
5615
718e3744 5616enum bgp_display_type
5617{
5618 normal_list,
5619};
5620
b40d939b 5621/* Print the short form route status for a bgp_info */
5622static void
5623route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
718e3744 5624{
b40d939b 5625 /* Route status display. */
5626 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5627 vty_out (vty, "R");
5628 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
93406d87 5629 vty_out (vty, "S");
fb982c25 5630 else if (binfo->extra && binfo->extra->suppress)
718e3744 5631 vty_out (vty, "s");
5632 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5633 vty_out (vty, "*");
5634 else
5635 vty_out (vty, " ");
5636
5637 /* Selected */
5638 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5639 vty_out (vty, "h");
5640 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5641 vty_out (vty, "d");
5642 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5643 vty_out (vty, ">");
b366b518
BB
5644 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5645 vty_out (vty, "=");
718e3744 5646 else
5647 vty_out (vty, " ");
5648
5649 /* Internal route. */
5650 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5651 vty_out (vty, "i");
5652 else
b40d939b 5653 vty_out (vty, " ");
5654}
5655
5656/* called from terminal list command */
5657void
5658route_vty_out (struct vty *vty, struct prefix *p,
5659 struct bgp_info *binfo, int display, safi_t safi)
5660{
5661 struct attr *attr;
5662
5663 /* short status lead text */
5664 route_vty_short_status_out (vty, binfo);
718e3744 5665
5666 /* print prefix and mask */
5667 if (! display)
5668 route_vty_out_route (p, vty);
5669 else
5670 vty_out (vty, "%*s", 17, " ");
5671
5672 /* Print attribute */
5673 attr = binfo->attr;
5674 if (attr)
5675 {
5676 if (p->family == AF_INET)
5677 {
5678 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
5679 vty_out (vty, "%-16s",
5680 inet_ntoa (attr->extra->mp_nexthop_global_in));
718e3744 5681 else
5682 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5683 }
5684#ifdef HAVE_IPV6
5685 else if (p->family == AF_INET6)
5686 {
5687 int len;
5688 char buf[BUFSIZ];
5689
5690 len = vty_out (vty, "%s",
fb982c25
PJ
5691 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5692 buf, BUFSIZ));
718e3744 5693 len = 16 - len;
5694 if (len < 1)
5695 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5696 else
5697 vty_out (vty, "%*s", len, " ");
5698 }
5699#endif /* HAVE_IPV6 */
5700
5701 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
c099baf6 5702 vty_out (vty, "%10u", attr->med);
718e3744 5703 else
5704 vty_out (vty, " ");
5705
5706 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
c099baf6 5707 vty_out (vty, "%7u", attr->local_pref);
718e3744 5708 else
5709 vty_out (vty, " ");
5710
fb982c25 5711 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
718e3744 5712
b2518c1e
PJ
5713 /* Print aspath */
5714 if (attr->aspath)
841f7a57 5715 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 5716
b2518c1e 5717 /* Print origin */
718e3744 5718 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 5719 }
718e3744 5720 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 5721}
5722
5723/* called from terminal list command */
5724void
5725route_vty_out_tmp (struct vty *vty, struct prefix *p,
5726 struct attr *attr, safi_t safi)
5727{
5728 /* Route status display. */
5729 vty_out (vty, "*");
5730 vty_out (vty, ">");
5731 vty_out (vty, " ");
5732
5733 /* print prefix and mask */
5734 route_vty_out_route (p, vty);
5735
5736 /* Print attribute */
5737 if (attr)
5738 {
5739 if (p->family == AF_INET)
5740 {
5741 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
5742 vty_out (vty, "%-16s",
5743 inet_ntoa (attr->extra->mp_nexthop_global_in));
718e3744 5744 else
5745 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5746 }
5747#ifdef HAVE_IPV6
5748 else if (p->family == AF_INET6)
5749 {
5750 int len;
5751 char buf[BUFSIZ];
fb982c25
PJ
5752
5753 assert (attr->extra);
718e3744 5754
5755 len = vty_out (vty, "%s",
fb982c25
PJ
5756 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5757 buf, BUFSIZ));
718e3744 5758 len = 16 - len;
5759 if (len < 1)
5760 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5761 else
5762 vty_out (vty, "%*s", len, " ");
5763 }
5764#endif /* HAVE_IPV6 */
5765
5766 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
c099baf6 5767 vty_out (vty, "%10u", attr->med);
718e3744 5768 else
5769 vty_out (vty, " ");
5770
5771 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
c099baf6 5772 vty_out (vty, "%7u", attr->local_pref);
718e3744 5773 else
5774 vty_out (vty, " ");
fb982c25 5775
c099baf6 5776 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
fb982c25 5777
b2518c1e
PJ
5778 /* Print aspath */
5779 if (attr->aspath)
841f7a57 5780 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 5781
b2518c1e 5782 /* Print origin */
718e3744 5783 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
b2518c1e 5784 }
718e3744 5785
5786 vty_out (vty, "%s", VTY_NEWLINE);
5787}
5788
5a646650 5789void
718e3744 5790route_vty_out_tag (struct vty *vty, struct prefix *p,
5791 struct bgp_info *binfo, int display, safi_t safi)
5792{
5793 struct attr *attr;
718e3744 5794 u_int32_t label = 0;
fb982c25
PJ
5795
5796 if (!binfo->extra)
5797 return;
5798
b40d939b 5799 /* short status lead text */
5800 route_vty_short_status_out (vty, binfo);
5801
718e3744 5802 /* print prefix and mask */
5803 if (! display)
5804 route_vty_out_route (p, vty);
5805 else
5806 vty_out (vty, "%*s", 17, " ");
5807
5808 /* Print attribute */
5809 attr = binfo->attr;
5810 if (attr)
5811 {
5812 if (p->family == AF_INET)
5813 {
5814 if (safi == SAFI_MPLS_VPN)
fb982c25
PJ
5815 vty_out (vty, "%-16s",
5816 inet_ntoa (attr->extra->mp_nexthop_global_in));
718e3744 5817 else
5818 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5819 }
5820#ifdef HAVE_IPV6
5821 else if (p->family == AF_INET6)
5822 {
fb982c25 5823 assert (attr->extra);
718e3744 5824 char buf[BUFSIZ];
5825 char buf1[BUFSIZ];
fb982c25 5826 if (attr->extra->mp_nexthop_len == 16)
718e3744 5827 vty_out (vty, "%s",
fb982c25
PJ
5828 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5829 buf, BUFSIZ));
5830 else if (attr->extra->mp_nexthop_len == 32)
718e3744 5831 vty_out (vty, "%s(%s)",
fb982c25
PJ
5832 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5833 buf, BUFSIZ),
5834 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5835 buf1, BUFSIZ));
718e3744 5836
5837 }
5838#endif /* HAVE_IPV6 */
5839 }
5840
fb982c25 5841 label = decode_label (binfo->extra->tag);
718e3744 5842
5843 vty_out (vty, "notag/%d", label);
5844
5845 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 5846}
5847
5848/* dampening route */
5a646650 5849static void
718e3744 5850damp_route_vty_out (struct vty *vty, struct prefix *p,
5851 struct bgp_info *binfo, int display, safi_t safi)
5852{
5853 struct attr *attr;
718e3744 5854 int len;
50aef6f3 5855 char timebuf[BGP_UPTIME_LEN];
718e3744 5856
b40d939b 5857 /* short status lead text */
5858 route_vty_short_status_out (vty, binfo);
5859
718e3744 5860 /* print prefix and mask */
5861 if (! display)
5862 route_vty_out_route (p, vty);
5863 else
5864 vty_out (vty, "%*s", 17, " ");
5865
5866 len = vty_out (vty, "%s", binfo->peer->host);
5867 len = 17 - len;
5868 if (len < 1)
5869 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5870 else
5871 vty_out (vty, "%*s", len, " ");
5872
50aef6f3 5873 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
718e3744 5874
5875 /* Print attribute */
5876 attr = binfo->attr;
5877 if (attr)
5878 {
5879 /* Print aspath */
5880 if (attr->aspath)
841f7a57 5881 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 5882
5883 /* Print origin */
b2518c1e 5884 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 5885 }
5886 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 5887}
5888
718e3744 5889/* flap route */
5a646650 5890static void
718e3744 5891flap_route_vty_out (struct vty *vty, struct prefix *p,
5892 struct bgp_info *binfo, int display, safi_t safi)
5893{
5894 struct attr *attr;
5895 struct bgp_damp_info *bdi;
718e3744 5896 char timebuf[BGP_UPTIME_LEN];
5897 int len;
fb982c25
PJ
5898
5899 if (!binfo->extra)
5900 return;
5901
5902 bdi = binfo->extra->damp_info;
718e3744 5903
b40d939b 5904 /* short status lead text */
5905 route_vty_short_status_out (vty, binfo);
5906
718e3744 5907 /* print prefix and mask */
5908 if (! display)
5909 route_vty_out_route (p, vty);
5910 else
5911 vty_out (vty, "%*s", 17, " ");
5912
5913 len = vty_out (vty, "%s", binfo->peer->host);
5914 len = 16 - len;
5915 if (len < 1)
5916 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5917 else
5918 vty_out (vty, "%*s", len, " ");
5919
5920 len = vty_out (vty, "%d", bdi->flap);
5921 len = 5 - len;
5922 if (len < 1)
5923 vty_out (vty, " ");
5924 else
5925 vty_out (vty, "%*s ", len, " ");
5926
5927 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5928 timebuf, BGP_UPTIME_LEN));
5929
5930 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5931 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
50aef6f3 5932 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
718e3744 5933 else
5934 vty_out (vty, "%*s ", 8, " ");
5935
5936 /* Print attribute */
5937 attr = binfo->attr;
5938 if (attr)
5939 {
5940 /* Print aspath */
5941 if (attr->aspath)
841f7a57 5942 aspath_print_vty (vty, "%s", attr->aspath, " ");
718e3744 5943
5944 /* Print origin */
b2518c1e 5945 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
718e3744 5946 }
5947 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 5948}
5949
94f2b392 5950static void
718e3744 5951route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5952 struct bgp_info *binfo, afi_t afi, safi_t safi)
5953{
5954 char buf[INET6_ADDRSTRLEN];
5955 char buf1[BUFSIZ];
5956 struct attr *attr;
5957 int sockunion_vty_out (struct vty *, union sockunion *);
30b00176
JK
5958#ifdef HAVE_CLOCK_MONOTONIC
5959 time_t tbuf;
5960#endif
718e3744 5961
5962 attr = binfo->attr;
5963
5964 if (attr)
5965 {
5966 /* Line1 display AS-path, Aggregator */
5967 if (attr->aspath)
5968 {
5969 vty_out (vty, " ");
fe69a505 5970 if (aspath_count_hops (attr->aspath) == 0)
718e3744 5971 vty_out (vty, "Local");
5972 else
841f7a57 5973 aspath_print_vty (vty, "%s", attr->aspath, "");
718e3744 5974 }
5975
b40d939b 5976 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5977 vty_out (vty, ", (removed)");
93406d87 5978 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5979 vty_out (vty, ", (stale)");
5980 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
aea339f7 5981 vty_out (vty, ", (aggregated by %u %s)",
fb982c25
PJ
5982 attr->extra->aggregator_as,
5983 inet_ntoa (attr->extra->aggregator_addr));
93406d87 5984 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5985 vty_out (vty, ", (Received from a RR-client)");
5986 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5987 vty_out (vty, ", (Received from a RS-client)");
5988 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5989 vty_out (vty, ", (history entry)");
5990 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5991 vty_out (vty, ", (suppressed due to dampening)");
718e3744 5992 vty_out (vty, "%s", VTY_NEWLINE);
5993
5994 /* Line2 display Next-hop, Neighbor, Router-id */
5995 if (p->family == AF_INET)
5996 {
5997 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
fb982c25 5998 inet_ntoa (attr->extra->mp_nexthop_global_in) :
718e3744 5999 inet_ntoa (attr->nexthop));
6000 }
6001#ifdef HAVE_IPV6
6002 else
6003 {
fb982c25 6004 assert (attr->extra);
718e3744 6005 vty_out (vty, " %s",
fb982c25 6006 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
718e3744 6007 buf, INET6_ADDRSTRLEN));
6008 }
6009#endif /* HAVE_IPV6 */
6010
6011 if (binfo->peer == bgp->peer_self)
6012 {
6013 vty_out (vty, " from %s ",
6014 p->family == AF_INET ? "0.0.0.0" : "::");
6015 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6016 }
6017 else
6018 {
6019 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6020 vty_out (vty, " (inaccessible)");
fb982c25 6021 else if (binfo->extra && binfo->extra->igpmetric)
ddc943de 6022 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
eb821189 6023 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
718e3744 6024 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
fb982c25 6025 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
718e3744 6026 else
6027 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6028 }
6029 vty_out (vty, "%s", VTY_NEWLINE);
6030
6031#ifdef HAVE_IPV6
6032 /* display nexthop local */
fb982c25 6033 if (attr->extra && attr->extra->mp_nexthop_len == 32)
718e3744 6034 {
6035 vty_out (vty, " (%s)%s",
fb982c25 6036 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
718e3744 6037 buf, INET6_ADDRSTRLEN),
6038 VTY_NEWLINE);
6039 }
6040#endif /* HAVE_IPV6 */
6041
6042 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6043 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6044
6045 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
c099baf6 6046 vty_out (vty, ", metric %u", attr->med);
718e3744 6047
6048 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
c099baf6 6049 vty_out (vty, ", localpref %u", attr->local_pref);
718e3744 6050 else
c099baf6 6051 vty_out (vty, ", localpref %u", bgp->default_local_pref);
718e3744 6052
fb982c25 6053 if (attr->extra && attr->extra->weight != 0)
c099baf6 6054 vty_out (vty, ", weight %u", attr->extra->weight);
718e3744 6055
6056 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6057 vty_out (vty, ", valid");
6058
6059 if (binfo->peer != bgp->peer_self)
6060 {
6061 if (binfo->peer->as == binfo->peer->local_as)
6062 vty_out (vty, ", internal");
6063 else
6064 vty_out (vty, ", %s",
6065 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6066 }
6067 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6068 vty_out (vty, ", aggregated, local");
6069 else if (binfo->type != ZEBRA_ROUTE_BGP)
6070 vty_out (vty, ", sourced");
6071 else
6072 vty_out (vty, ", sourced, local");
6073
6074 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6075 vty_out (vty, ", atomic-aggregate");
6076
de8d5dff
JB
6077 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6078 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6079 bgp_info_mpath_count (binfo)))
6080 vty_out (vty, ", multipath");
6081
718e3744 6082 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6083 vty_out (vty, ", best");
6084
6085 vty_out (vty, "%s", VTY_NEWLINE);
6086
6087 /* Line 4 display Community */
6088 if (attr->community)
6089 vty_out (vty, " Community: %s%s", attr->community->str,
6090 VTY_NEWLINE);
6091
6092 /* Line 5 display Extended-community */
6093 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
fb982c25
PJ
6094 vty_out (vty, " Extended Community: %s%s",
6095 attr->extra->ecommunity->str, VTY_NEWLINE);
718e3744 6096
6097 /* Line 6 display Originator, Cluster-id */
6098 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6099 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6100 {
fb982c25 6101 assert (attr->extra);
718e3744 6102 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
fb982c25
PJ
6103 vty_out (vty, " Originator: %s",
6104 inet_ntoa (attr->extra->originator_id));
718e3744 6105
6106 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6107 {
6108 int i;
6109 vty_out (vty, ", Cluster list: ");
fb982c25
PJ
6110 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6111 vty_out (vty, "%s ",
6112 inet_ntoa (attr->extra->cluster->list[i]));
718e3744 6113 }
6114 vty_out (vty, "%s", VTY_NEWLINE);
6115 }
41367172 6116
fb982c25 6117 if (binfo->extra && binfo->extra->damp_info)
718e3744 6118 bgp_damp_info_vty (vty, binfo);
6119
6120 /* Line 7 display Uptime */
30b00176
JK
6121#ifdef HAVE_CLOCK_MONOTONIC
6122 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
213b6cd9 6123 vty_out (vty, " Last update: %s", ctime(&tbuf));
30b00176
JK
6124#else
6125 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6126#endif /* HAVE_CLOCK_MONOTONIC */
718e3744 6127 }
6128 vty_out (vty, "%s", VTY_NEWLINE);
b366b518
BB
6129}
6130
6131#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6132 "h history, * valid, > best, = multipath,%s"\
6133 " i internal, r RIB-failure, S Stale, R Removed%s"
93406d87 6134#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
718e3744 6135#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6136#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6137#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6138
6139enum bgp_show_type
6140{
6141 bgp_show_type_normal,
6142 bgp_show_type_regexp,
6143 bgp_show_type_prefix_list,
6144 bgp_show_type_filter_list,
6145 bgp_show_type_route_map,
6146 bgp_show_type_neighbor,
6147 bgp_show_type_cidr_only,
6148 bgp_show_type_prefix_longer,
6149 bgp_show_type_community_all,
6150 bgp_show_type_community,
6151 bgp_show_type_community_exact,
6152 bgp_show_type_community_list,
6153 bgp_show_type_community_list_exact,
6154 bgp_show_type_flap_statistics,
6155 bgp_show_type_flap_address,
6156 bgp_show_type_flap_prefix,
6157 bgp_show_type_flap_cidr_only,
6158 bgp_show_type_flap_regexp,
6159 bgp_show_type_flap_filter_list,
6160 bgp_show_type_flap_prefix_list,
6161 bgp_show_type_flap_prefix_longer,
6162 bgp_show_type_flap_route_map,
6163 bgp_show_type_flap_neighbor,
6164 bgp_show_type_dampend_paths,
6165 bgp_show_type_damp_neighbor
6166};
6167
5a646650 6168static int
fee0f4c6 6169bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
5a646650 6170 enum bgp_show_type type, void *output_arg)
718e3744 6171{
718e3744 6172 struct bgp_info *ri;
6173 struct bgp_node *rn;
718e3744 6174 int header = 1;
718e3744 6175 int display;
5a646650 6176 unsigned long output_count;
718e3744 6177
6178 /* This is first entry point, so reset total line. */
5a646650 6179 output_count = 0;
718e3744 6180
718e3744 6181 /* Start processing of routes. */
6182 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6183 if (rn->info != NULL)
6184 {
6185 display = 0;
6186
6187 for (ri = rn->info; ri; ri = ri->next)
6188 {
5a646650 6189 if (type == bgp_show_type_flap_statistics
718e3744 6190 || type == bgp_show_type_flap_address
6191 || type == bgp_show_type_flap_prefix
6192 || type == bgp_show_type_flap_cidr_only
6193 || type == bgp_show_type_flap_regexp
6194 || type == bgp_show_type_flap_filter_list
6195 || type == bgp_show_type_flap_prefix_list
6196 || type == bgp_show_type_flap_prefix_longer
6197 || type == bgp_show_type_flap_route_map
6198 || type == bgp_show_type_flap_neighbor
6199 || type == bgp_show_type_dampend_paths
6200 || type == bgp_show_type_damp_neighbor)
6201 {
fb982c25 6202 if (!(ri->extra && ri->extra->damp_info))
718e3744 6203 continue;
6204 }
6205 if (type == bgp_show_type_regexp
6206 || type == bgp_show_type_flap_regexp)
6207 {
5a646650 6208 regex_t *regex = output_arg;
718e3744 6209
6210 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6211 continue;
6212 }
6213 if (type == bgp_show_type_prefix_list
6214 || type == bgp_show_type_flap_prefix_list)
6215 {
5a646650 6216 struct prefix_list *plist = output_arg;
718e3744 6217
6218 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6219 continue;
6220 }
6221 if (type == bgp_show_type_filter_list
6222 || type == bgp_show_type_flap_filter_list)
6223 {
5a646650 6224 struct as_list *as_list = output_arg;
718e3744 6225
6226 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6227 continue;
6228 }
6229 if (type == bgp_show_type_route_map
6230 || type == bgp_show_type_flap_route_map)
6231 {
5a646650 6232 struct route_map *rmap = output_arg;
718e3744 6233 struct bgp_info binfo;
558d1fec
JBD
6234 struct attr dummy_attr;
6235 struct attr_extra dummy_extra;
718e3744 6236 int ret;
6237
558d1fec 6238 dummy_attr.extra = &dummy_extra;
fb982c25 6239 bgp_attr_dup (&dummy_attr, ri->attr);
558d1fec 6240
718e3744 6241 binfo.peer = ri->peer;
6242 binfo.attr = &dummy_attr;
6243
6244 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
718e3744 6245 if (ret == RMAP_DENYMATCH)
6246 continue;
6247 }
6248 if (type == bgp_show_type_neighbor
6249 || type == bgp_show_type_flap_neighbor
6250 || type == bgp_show_type_damp_neighbor)
6251 {
5a646650 6252 union sockunion *su = output_arg;
718e3744 6253
6254 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6255 continue;
6256 }
6257 if (type == bgp_show_type_cidr_only
6258 || type == bgp_show_type_flap_cidr_only)
6259 {
6260 u_int32_t destination;
6261
6262 destination = ntohl (rn->p.u.prefix4.s_addr);
6263 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6264 continue;
6265 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6266 continue;
6267 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6268 continue;
6269 }
6270 if (type == bgp_show_type_prefix_longer
6271 || type == bgp_show_type_flap_prefix_longer)
6272 {
5a646650 6273 struct prefix *p = output_arg;
718e3744 6274
6275 if (! prefix_match (p, &rn->p))
6276 continue;
6277 }
6278 if (type == bgp_show_type_community_all)
6279 {
6280 if (! ri->attr->community)
6281 continue;
6282 }
6283 if (type == bgp_show_type_community)
6284 {
5a646650 6285 struct community *com = output_arg;
718e3744 6286
6287 if (! ri->attr->community ||
6288 ! community_match (ri->attr->community, com))
6289 continue;
6290 }
6291 if (type == bgp_show_type_community_exact)
6292 {
5a646650 6293 struct community *com = output_arg;
718e3744 6294
6295 if (! ri->attr->community ||
6296 ! community_cmp (ri->attr->community, com))
6297 continue;
6298 }
6299 if (type == bgp_show_type_community_list)
6300 {
5a646650 6301 struct community_list *list = output_arg;
718e3744 6302
6303 if (! community_list_match (ri->attr->community, list))
6304 continue;
6305 }
6306 if (type == bgp_show_type_community_list_exact)
6307 {
5a646650 6308 struct community_list *list = output_arg;
718e3744 6309
6310 if (! community_list_exact_match (ri->attr->community, list))
6311 continue;
6312 }
6313 if (type == bgp_show_type_flap_address
6314 || type == bgp_show_type_flap_prefix)
6315 {
5a646650 6316 struct prefix *p = output_arg;
718e3744 6317
6318 if (! prefix_match (&rn->p, p))
6319 continue;
6320
6321 if (type == bgp_show_type_flap_prefix)
6322 if (p->prefixlen != rn->p.prefixlen)
6323 continue;
6324 }
6325 if (type == bgp_show_type_dampend_paths
6326 || type == bgp_show_type_damp_neighbor)
6327 {
6328 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6329 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6330 continue;
6331 }
6332
6333 if (header)
6334 {
93406d87 6335 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6336 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6337 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 6338 if (type == bgp_show_type_dampend_paths
6339 || type == bgp_show_type_damp_neighbor)
6340 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6341 else if (type == bgp_show_type_flap_statistics
6342 || type == bgp_show_type_flap_address
6343 || type == bgp_show_type_flap_prefix
6344 || type == bgp_show_type_flap_cidr_only
6345 || type == bgp_show_type_flap_regexp
6346 || type == bgp_show_type_flap_filter_list
6347 || type == bgp_show_type_flap_prefix_list
6348 || type == bgp_show_type_flap_prefix_longer
6349 || type == bgp_show_type_flap_route_map
6350 || type == bgp_show_type_flap_neighbor)
6351 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6352 else
6353 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
718e3744 6354 header = 0;
6355 }
6356
6357 if (type == bgp_show_type_dampend_paths
6358 || type == bgp_show_type_damp_neighbor)
5a646650 6359 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
718e3744 6360 else if (type == bgp_show_type_flap_statistics
6361 || type == bgp_show_type_flap_address
6362 || type == bgp_show_type_flap_prefix
6363 || type == bgp_show_type_flap_cidr_only
6364 || type == bgp_show_type_flap_regexp
6365 || type == bgp_show_type_flap_filter_list
6366 || type == bgp_show_type_flap_prefix_list
6367 || type == bgp_show_type_flap_prefix_longer
6368 || type == bgp_show_type_flap_route_map
6369 || type == bgp_show_type_flap_neighbor)
5a646650 6370 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
718e3744 6371 else
5a646650 6372 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
718e3744 6373 display++;
6374 }
6375 if (display)
5a646650 6376 output_count++;
718e3744 6377 }
6378
6379 /* No route is displayed */
5a646650 6380 if (output_count == 0)
718e3744 6381 {
6382 if (type == bgp_show_type_normal)
6383 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6384 }
6385 else
6386 vty_out (vty, "%sTotal number of prefixes %ld%s",
5a646650 6387 VTY_NEWLINE, output_count, VTY_NEWLINE);
718e3744 6388
6389 return CMD_SUCCESS;
6390}
6391
5a646650 6392static int
fee0f4c6 6393bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
5a646650 6394 enum bgp_show_type type, void *output_arg)
fee0f4c6 6395{
6396 struct bgp_table *table;
6397
6398 if (bgp == NULL) {
6399 bgp = bgp_get_default ();
6400 }
6401
6402 if (bgp == NULL)
6403 {
6404 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6405 return CMD_WARNING;
6406 }
6407
6408
6409 table = bgp->rib[afi][safi];
6410
5a646650 6411 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
fee0f4c6 6412}
6413
718e3744 6414/* Header of detailed BGP route information */
94f2b392 6415static void
718e3744 6416route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6417 struct bgp_node *rn,
6418 struct prefix_rd *prd, afi_t afi, safi_t safi)
6419{
6420 struct bgp_info *ri;
6421 struct prefix *p;
6422 struct peer *peer;
1eb8ef25 6423 struct listnode *node, *nnode;
718e3744 6424 char buf1[INET6_ADDRSTRLEN];
6425 char buf2[INET6_ADDRSTRLEN];
6426 int count = 0;
6427 int best = 0;
6428 int suppress = 0;
6429 int no_export = 0;
6430 int no_advertise = 0;
6431 int local_as = 0;
6432 int first = 0;
6433
6434 p = &rn->p;
6435 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6436 (safi == SAFI_MPLS_VPN ?
6437 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6438 safi == SAFI_MPLS_VPN ? ":" : "",
6439 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6440 p->prefixlen, VTY_NEWLINE);
6441
6442 for (ri = rn->info; ri; ri = ri->next)
6443 {
6444 count++;
6445 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6446 {
6447 best = count;
fb982c25 6448 if (ri->extra && ri->extra->suppress)
718e3744 6449 suppress = 1;
6450 if (ri->attr->community != NULL)
6451 {
6452 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6453 no_advertise = 1;
6454 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6455 no_export = 1;
6456 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6457 local_as = 1;
6458 }
6459 }
6460 }
6461
6462 vty_out (vty, "Paths: (%d available", count);
6463 if (best)
6464 {
6465 vty_out (vty, ", best #%d", best);
6466 if (safi == SAFI_UNICAST)
6467 vty_out (vty, ", table Default-IP-Routing-Table");
6468 }
6469 else
6470 vty_out (vty, ", no best path");
6471 if (no_advertise)
6472 vty_out (vty, ", not advertised to any peer");
6473 else if (no_export)
6474 vty_out (vty, ", not advertised to EBGP peer");
6475 else if (local_as)
6476 vty_out (vty, ", not advertised outside local AS");
6477 if (suppress)
6478 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6479 vty_out (vty, ")%s", VTY_NEWLINE);
6480
6481 /* advertised peer */
1eb8ef25 6482 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
718e3744 6483 {
6484 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6485 {
6486 if (! first)
6487 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6488 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6489 first = 1;
6490 }
6491 }
6492 if (! first)
6493 vty_out (vty, " Not advertised to any peer");
6494 vty_out (vty, "%s", VTY_NEWLINE);
6495}
6496
6497/* Display specified route of BGP table. */
94f2b392 6498static int
fee0f4c6 6499bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
fd79ac91 6500 struct bgp_table *rib, const char *ip_str,
6501 afi_t afi, safi_t safi, struct prefix_rd *prd,
6502 int prefix_check)
718e3744 6503{
6504 int ret;
6505 int header;
6506 int display = 0;
6507 struct prefix match;
6508 struct bgp_node *rn;
6509 struct bgp_node *rm;
6510 struct bgp_info *ri;
718e3744 6511 struct bgp_table *table;
6512
718e3744 6513 /* Check IP address argument. */
6514 ret = str2prefix (ip_str, &match);
6515 if (! ret)
6516 {
6517 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6518 return CMD_WARNING;
6519 }
6520
6521 match.family = afi2family (afi);
6522
6523 if (safi == SAFI_MPLS_VPN)
6524 {
fee0f4c6 6525 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
718e3744 6526 {
6527 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6528 continue;
6529
6530 if ((table = rn->info) != NULL)
6531 {
6532 header = 1;
6533
6534 if ((rm = bgp_node_match (table, &match)) != NULL)
6535 {
6536 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6c88b44d
CC
6537 {
6538 bgp_unlock_node (rm);
6539 continue;
6540 }
718e3744 6541
6542 for (ri = rm->info; ri; ri = ri->next)
6543 {
6544 if (header)
6545 {
6546 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6547 AFI_IP, SAFI_MPLS_VPN);
6548
6549 header = 0;
6550 }
6551 display++;
6552 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6553 }
6c88b44d
CC
6554
6555 bgp_unlock_node (rm);
718e3744 6556 }
6557 }
6558 }
6559 }
6560 else
6561 {
6562 header = 1;
6563
fee0f4c6 6564 if ((rn = bgp_node_match (rib, &match)) != NULL)
718e3744 6565 {
6566 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6567 {
6568 for (ri = rn->info; ri; ri = ri->next)
6569 {
6570 if (header)
6571 {
6572 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6573 header = 0;
6574 }
6575 display++;
6576 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6577 }
6578 }
6c88b44d
CC
6579
6580 bgp_unlock_node (rn);
718e3744 6581 }
6582 }
6583
6584 if (! display)
6585 {
6586 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6587 return CMD_WARNING;
6588 }
6589
6590 return CMD_SUCCESS;
6591}
6592
fee0f4c6 6593/* Display specified route of Main RIB */
94f2b392 6594static int
fd79ac91 6595bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
fee0f4c6 6596 afi_t afi, safi_t safi, struct prefix_rd *prd,
6597 int prefix_check)
6598{
6599 struct bgp *bgp;
6600
6601 /* BGP structure lookup. */
6602 if (view_name)
6603 {
6604 bgp = bgp_lookup_by_name (view_name);
6605 if (bgp == NULL)
6606 {
6607 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6608 return CMD_WARNING;
6609 }
6610 }
6611 else
6612 {
6613 bgp = bgp_get_default ();
6614 if (bgp == NULL)
6615 {
6616 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6617 return CMD_WARNING;
6618 }
6619 }
6620
6621 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6622 afi, safi, prd, prefix_check);
6623}
6624
718e3744 6625/* BGP route print out function. */
6626DEFUN (show_ip_bgp,
6627 show_ip_bgp_cmd,
6628 "show ip bgp",
6629 SHOW_STR
6630 IP_STR
6631 BGP_STR)
6632{
5a646650 6633 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
718e3744 6634}
6635
6636DEFUN (show_ip_bgp_ipv4,
6637 show_ip_bgp_ipv4_cmd,
6638 "show ip bgp ipv4 (unicast|multicast)",
6639 SHOW_STR
6640 IP_STR
6641 BGP_STR
6642 "Address family\n"
6643 "Address Family modifier\n"
6644 "Address Family modifier\n")
6645{
6646 if (strncmp (argv[0], "m", 1) == 0)
5a646650 6647 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6648 NULL);
718e3744 6649
5a646650 6650 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
718e3744 6651}
6652
95cbbd2a
ML
6653ALIAS (show_ip_bgp_ipv4,
6654 show_bgp_ipv4_safi_cmd,
6655 "show bgp ipv4 (unicast|multicast)",
6656 SHOW_STR
6657 BGP_STR
6658 "Address family\n"
6659 "Address Family modifier\n"
6660 "Address Family modifier\n")
6661
718e3744 6662DEFUN (show_ip_bgp_route,
6663 show_ip_bgp_route_cmd,
6664 "show ip bgp A.B.C.D",
6665 SHOW_STR
6666 IP_STR
6667 BGP_STR
6668 "Network in the BGP routing table to display\n")
6669{
6670 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6671}
6672
6673DEFUN (show_ip_bgp_ipv4_route,
6674 show_ip_bgp_ipv4_route_cmd,
6675 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6676 SHOW_STR
6677 IP_STR
6678 BGP_STR
6679 "Address family\n"
6680 "Address Family modifier\n"
6681 "Address Family modifier\n"
6682 "Network in the BGP routing table to display\n")
6683{
6684 if (strncmp (argv[0], "m", 1) == 0)
6685 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6686
6687 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6688}
6689
95cbbd2a
ML
6690ALIAS (show_ip_bgp_ipv4_route,
6691 show_bgp_ipv4_safi_route_cmd,
6692 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6693 SHOW_STR
6694 BGP_STR
6695 "Address family\n"
6696 "Address Family modifier\n"
6697 "Address Family modifier\n"
6698 "Network in the BGP routing table to display\n")
6699
718e3744 6700DEFUN (show_ip_bgp_vpnv4_all_route,
6701 show_ip_bgp_vpnv4_all_route_cmd,
6702 "show ip bgp vpnv4 all A.B.C.D",
6703 SHOW_STR
6704 IP_STR
6705 BGP_STR
6706 "Display VPNv4 NLRI specific information\n"
6707 "Display information about all VPNv4 NLRIs\n"
6708 "Network in the BGP routing table to display\n")
6709{
6710 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6711}
6712
6713DEFUN (show_ip_bgp_vpnv4_rd_route,
6714 show_ip_bgp_vpnv4_rd_route_cmd,
6715 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6716 SHOW_STR
6717 IP_STR
6718 BGP_STR
6719 "Display VPNv4 NLRI specific information\n"
6720 "Display information for a route distinguisher\n"
6721 "VPN Route Distinguisher\n"
6722 "Network in the BGP routing table to display\n")
6723{
6724 int ret;
6725 struct prefix_rd prd;
6726
6727 ret = str2prefix_rd (argv[0], &prd);
6728 if (! ret)
6729 {
6730 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6731 return CMD_WARNING;
6732 }
6733 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6734}
6735
6736DEFUN (show_ip_bgp_prefix,
6737 show_ip_bgp_prefix_cmd,
6738 "show ip bgp A.B.C.D/M",
6739 SHOW_STR
6740 IP_STR
6741 BGP_STR
6742 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6743{
6744 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6745}
6746
6747DEFUN (show_ip_bgp_ipv4_prefix,
6748 show_ip_bgp_ipv4_prefix_cmd,
6749 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6750 SHOW_STR
6751 IP_STR
6752 BGP_STR
6753 "Address family\n"
6754 "Address Family modifier\n"
6755 "Address Family modifier\n"
6756 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6757{
6758 if (strncmp (argv[0], "m", 1) == 0)
6759 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6760
6761 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6762}
6763
95cbbd2a
ML
6764ALIAS (show_ip_bgp_ipv4_prefix,
6765 show_bgp_ipv4_safi_prefix_cmd,
6766 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6767 SHOW_STR
6768 BGP_STR
6769 "Address family\n"
6770 "Address Family modifier\n"
6771 "Address Family modifier\n"
6772 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6773
718e3744 6774DEFUN (show_ip_bgp_vpnv4_all_prefix,
6775 show_ip_bgp_vpnv4_all_prefix_cmd,
6776 "show ip bgp vpnv4 all A.B.C.D/M",
6777 SHOW_STR
6778 IP_STR
6779 BGP_STR
6780 "Display VPNv4 NLRI specific information\n"
6781 "Display information about all VPNv4 NLRIs\n"
6782 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6783{
6784 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6785}
6786
6787DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6788 show_ip_bgp_vpnv4_rd_prefix_cmd,
6789 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6790 SHOW_STR
6791 IP_STR
6792 BGP_STR
6793 "Display VPNv4 NLRI specific information\n"
6794 "Display information for a route distinguisher\n"
6795 "VPN Route Distinguisher\n"
6796 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6797{
6798 int ret;
6799 struct prefix_rd prd;
6800
6801 ret = str2prefix_rd (argv[0], &prd);
6802 if (! ret)
6803 {
6804 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6805 return CMD_WARNING;
6806 }
6807 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6808}
6809
6810DEFUN (show_ip_bgp_view,
6811 show_ip_bgp_view_cmd,
6812 "show ip bgp view WORD",
6813 SHOW_STR
6814 IP_STR
6815 BGP_STR
6816 "BGP view\n"
2b00515a 6817 "View name\n")
718e3744 6818{
bb46e94f 6819 struct bgp *bgp;
6820
6821 /* BGP structure lookup. */
6822 bgp = bgp_lookup_by_name (argv[0]);
6823 if (bgp == NULL)
6824 {
6825 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6826 return CMD_WARNING;
6827 }
6828
5a646650 6829 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
718e3744 6830}
6831
6832DEFUN (show_ip_bgp_view_route,
6833 show_ip_bgp_view_route_cmd,
6834 "show ip bgp view WORD A.B.C.D",
6835 SHOW_STR
6836 IP_STR
6837 BGP_STR
6838 "BGP view\n"
2b00515a 6839 "View name\n"
718e3744 6840 "Network in the BGP routing table to display\n")
6841{
6842 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6843}
6844
6845DEFUN (show_ip_bgp_view_prefix,
6846 show_ip_bgp_view_prefix_cmd,
6847 "show ip bgp view WORD A.B.C.D/M",
6848 SHOW_STR
6849 IP_STR
6850 BGP_STR
6851 "BGP view\n"
2b00515a 6852 "View name\n"
718e3744 6853 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6854{
6855 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6856}
6857
6858#ifdef HAVE_IPV6
6859DEFUN (show_bgp,
6860 show_bgp_cmd,
6861 "show bgp",
6862 SHOW_STR
6863 BGP_STR)
6864{
5a646650 6865 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6866 NULL);
718e3744 6867}
6868
6869ALIAS (show_bgp,
6870 show_bgp_ipv6_cmd,
6871 "show bgp ipv6",
6872 SHOW_STR
6873 BGP_STR
6874 "Address family\n")
6875
95cbbd2a
ML
6876DEFUN (show_bgp_ipv6_safi,
6877 show_bgp_ipv6_safi_cmd,
6878 "show bgp ipv6 (unicast|multicast)",
6879 SHOW_STR
6880 BGP_STR
6881 "Address family\n"
6882 "Address Family modifier\n"
6883 "Address Family modifier\n")
6884{
6885 if (strncmp (argv[0], "m", 1) == 0)
6886 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6887 NULL);
6888
6889 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6890}
6891
718e3744 6892/* old command */
6893DEFUN (show_ipv6_bgp,
6894 show_ipv6_bgp_cmd,
6895 "show ipv6 bgp",
6896 SHOW_STR
6897 IP_STR
6898 BGP_STR)
6899{
5a646650 6900 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6901 NULL);
718e3744 6902}
6903
6904DEFUN (show_bgp_route,
6905 show_bgp_route_cmd,
6906 "show bgp X:X::X:X",
6907 SHOW_STR
6908 BGP_STR
6909 "Network in the BGP routing table to display\n")
6910{
6911 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6912}
6913
6914ALIAS (show_bgp_route,
6915 show_bgp_ipv6_route_cmd,
6916 "show bgp ipv6 X:X::X:X",
6917 SHOW_STR
6918 BGP_STR
6919 "Address family\n"
6920 "Network in the BGP routing table to display\n")
6921
95cbbd2a
ML
6922DEFUN (show_bgp_ipv6_safi_route,
6923 show_bgp_ipv6_safi_route_cmd,
6924 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6925 SHOW_STR
6926 BGP_STR
6927 "Address family\n"
6928 "Address Family modifier\n"
6929 "Address Family modifier\n"
6930 "Network in the BGP routing table to display\n")
6931{
6932 if (strncmp (argv[0], "m", 1) == 0)
6933 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6934
6935 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6936}
6937
718e3744 6938/* old command */
6939DEFUN (show_ipv6_bgp_route,
6940 show_ipv6_bgp_route_cmd,
6941 "show ipv6 bgp X:X::X:X",
6942 SHOW_STR
6943 IP_STR
6944 BGP_STR
6945 "Network in the BGP routing table to display\n")
6946{
6947 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6948}
6949
6950DEFUN (show_bgp_prefix,
6951 show_bgp_prefix_cmd,
6952 "show bgp X:X::X:X/M",
6953 SHOW_STR
6954 BGP_STR
6955 "IPv6 prefix <network>/<length>\n")
6956{
6957 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6958}
6959
6960ALIAS (show_bgp_prefix,
6961 show_bgp_ipv6_prefix_cmd,
6962 "show bgp ipv6 X:X::X:X/M",
6963 SHOW_STR
6964 BGP_STR
6965 "Address family\n"
6966 "IPv6 prefix <network>/<length>\n")
6967
95cbbd2a
ML
6968DEFUN (show_bgp_ipv6_safi_prefix,
6969 show_bgp_ipv6_safi_prefix_cmd,
6970 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6971 SHOW_STR
6972 BGP_STR
6973 "Address family\n"
6974 "Address Family modifier\n"
6975 "Address Family modifier\n"
6976 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6977{
6978 if (strncmp (argv[0], "m", 1) == 0)
6979 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6980
6981 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6982}
6983
718e3744 6984/* old command */
6985DEFUN (show_ipv6_bgp_prefix,
6986 show_ipv6_bgp_prefix_cmd,
6987 "show ipv6 bgp X:X::X:X/M",
6988 SHOW_STR
6989 IP_STR
6990 BGP_STR
6991 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6992{
6993 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6994}
6995
bb46e94f 6996DEFUN (show_bgp_view,
6997 show_bgp_view_cmd,
6998 "show bgp view WORD",
6999 SHOW_STR
7000 BGP_STR
7001 "BGP view\n"
7002 "View name\n")
7003{
7004 struct bgp *bgp;
7005
7006 /* BGP structure lookup. */
7007 bgp = bgp_lookup_by_name (argv[0]);
7008 if (bgp == NULL)
7009 {
7010 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7011 return CMD_WARNING;
7012 }
7013
5a646650 7014 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
bb46e94f 7015}
7016
7017ALIAS (show_bgp_view,
7018 show_bgp_view_ipv6_cmd,
7019 "show bgp view WORD ipv6",
7020 SHOW_STR
7021 BGP_STR
7022 "BGP view\n"
7023 "View name\n"
7024 "Address family\n")
7025
7026DEFUN (show_bgp_view_route,
7027 show_bgp_view_route_cmd,
7028 "show bgp view WORD X:X::X:X",
7029 SHOW_STR
7030 BGP_STR
7031 "BGP view\n"
7032 "View name\n"
7033 "Network in the BGP routing table to display\n")
7034{
7035 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7036}
7037
7038ALIAS (show_bgp_view_route,
7039 show_bgp_view_ipv6_route_cmd,
7040 "show bgp view WORD ipv6 X:X::X:X",
7041 SHOW_STR
7042 BGP_STR
7043 "BGP view\n"
7044 "View name\n"
7045 "Address family\n"
7046 "Network in the BGP routing table to display\n")
7047
7048DEFUN (show_bgp_view_prefix,
7049 show_bgp_view_prefix_cmd,
7050 "show bgp view WORD X:X::X:X/M",
7051 SHOW_STR
7052 BGP_STR
7053 "BGP view\n"
7054 "View name\n"
7055 "IPv6 prefix <network>/<length>\n")
7056{
7057 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7058}
7059
7060ALIAS (show_bgp_view_prefix,
7061 show_bgp_view_ipv6_prefix_cmd,
7062 "show bgp view WORD ipv6 X:X::X:X/M",
7063 SHOW_STR
7064 BGP_STR
7065 "BGP view\n"
7066 "View name\n"
7067 "Address family\n"
7068 "IPv6 prefix <network>/<length>\n")
7069
718e3744 7070/* old command */
7071DEFUN (show_ipv6_mbgp,
7072 show_ipv6_mbgp_cmd,
7073 "show ipv6 mbgp",
7074 SHOW_STR
7075 IP_STR
7076 MBGP_STR)
7077{
5a646650 7078 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7079 NULL);
718e3744 7080}
7081
7082/* old command */
7083DEFUN (show_ipv6_mbgp_route,
7084 show_ipv6_mbgp_route_cmd,
7085 "show ipv6 mbgp X:X::X:X",
7086 SHOW_STR
7087 IP_STR
7088 MBGP_STR
7089 "Network in the MBGP routing table to display\n")
7090{
7091 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7092}
7093
7094/* old command */
7095DEFUN (show_ipv6_mbgp_prefix,
7096 show_ipv6_mbgp_prefix_cmd,
7097 "show ipv6 mbgp X:X::X:X/M",
7098 SHOW_STR
7099 IP_STR
7100 MBGP_STR
7101 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7102{
7103 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7104}
7105#endif
7106\f
718e3744 7107
94f2b392 7108static int
fd79ac91 7109bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
718e3744 7110 safi_t safi, enum bgp_show_type type)
7111{
7112 int i;
7113 struct buffer *b;
7114 char *regstr;
7115 int first;
7116 regex_t *regex;
5a646650 7117 int rc;
718e3744 7118
7119 first = 0;
7120 b = buffer_new (1024);
7121 for (i = 0; i < argc; i++)
7122 {
7123 if (first)
7124 buffer_putc (b, ' ');
7125 else
7126 {
7127 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7128 continue;
7129 first = 1;
7130 }
7131
7132 buffer_putstr (b, argv[i]);
7133 }
7134 buffer_putc (b, '\0');
7135
7136 regstr = buffer_getstr (b);
7137 buffer_free (b);
7138
7139 regex = bgp_regcomp (regstr);
3b8b1855 7140 XFREE(MTYPE_TMP, regstr);
718e3744 7141 if (! regex)
7142 {
7143 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7144 VTY_NEWLINE);
7145 return CMD_WARNING;
7146 }
7147
5a646650 7148 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7149 bgp_regex_free (regex);
7150 return rc;
718e3744 7151}
7152
7153DEFUN (show_ip_bgp_regexp,
7154 show_ip_bgp_regexp_cmd,
7155 "show ip bgp regexp .LINE",
7156 SHOW_STR
7157 IP_STR
7158 BGP_STR
7159 "Display routes matching the AS path regular expression\n"
7160 "A regular-expression to match the BGP AS paths\n")
7161{
7162 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7163 bgp_show_type_regexp);
7164}
7165
7166DEFUN (show_ip_bgp_flap_regexp,
7167 show_ip_bgp_flap_regexp_cmd,
7168 "show ip bgp flap-statistics regexp .LINE",
7169 SHOW_STR
7170 IP_STR
7171 BGP_STR
7172 "Display flap statistics of routes\n"
7173 "Display routes matching the AS path regular expression\n"
7174 "A regular-expression to match the BGP AS paths\n")
7175{
7176 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7177 bgp_show_type_flap_regexp);
7178}
7179
7180DEFUN (show_ip_bgp_ipv4_regexp,
7181 show_ip_bgp_ipv4_regexp_cmd,
7182 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7183 SHOW_STR
7184 IP_STR
7185 BGP_STR
7186 "Address family\n"
7187 "Address Family modifier\n"
7188 "Address Family modifier\n"
7189 "Display routes matching the AS path regular expression\n"
7190 "A regular-expression to match the BGP AS paths\n")
7191{
7192 if (strncmp (argv[0], "m", 1) == 0)
7193 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7194 bgp_show_type_regexp);
7195
7196 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7197 bgp_show_type_regexp);
7198}
7199
7200#ifdef HAVE_IPV6
7201DEFUN (show_bgp_regexp,
7202 show_bgp_regexp_cmd,
7203 "show bgp regexp .LINE",
7204 SHOW_STR
7205 BGP_STR
7206 "Display routes matching the AS path regular expression\n"
7207 "A regular-expression to match the BGP AS paths\n")
7208{
7209 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7210 bgp_show_type_regexp);
7211}
7212
7213ALIAS (show_bgp_regexp,
7214 show_bgp_ipv6_regexp_cmd,
7215 "show bgp ipv6 regexp .LINE",
7216 SHOW_STR
7217 BGP_STR
7218 "Address family\n"
7219 "Display routes matching the AS path regular expression\n"
7220 "A regular-expression to match the BGP AS paths\n")
7221
7222/* old command */
7223DEFUN (show_ipv6_bgp_regexp,
7224 show_ipv6_bgp_regexp_cmd,
7225 "show ipv6 bgp regexp .LINE",
7226 SHOW_STR
7227 IP_STR
7228 BGP_STR
7229 "Display routes matching the AS path regular expression\n"
7230 "A regular-expression to match the BGP AS paths\n")
7231{
7232 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7233 bgp_show_type_regexp);
7234}
7235
7236/* old command */
7237DEFUN (show_ipv6_mbgp_regexp,
7238 show_ipv6_mbgp_regexp_cmd,
7239 "show ipv6 mbgp regexp .LINE",
7240 SHOW_STR
7241 IP_STR
7242 BGP_STR
7243 "Display routes matching the AS path regular expression\n"
7244 "A regular-expression to match the MBGP AS paths\n")
7245{
7246 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7247 bgp_show_type_regexp);
7248}
7249#endif /* HAVE_IPV6 */
7250\f
94f2b392 7251static int
fd79ac91 7252bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
718e3744 7253 safi_t safi, enum bgp_show_type type)
7254{
7255 struct prefix_list *plist;
7256
7257 plist = prefix_list_lookup (afi, prefix_list_str);
7258 if (plist == NULL)
7259 {
7260 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7261 prefix_list_str, VTY_NEWLINE);
7262 return CMD_WARNING;
7263 }
7264
5a646650 7265 return bgp_show (vty, NULL, afi, safi, type, plist);
718e3744 7266}
7267
7268DEFUN (show_ip_bgp_prefix_list,
7269 show_ip_bgp_prefix_list_cmd,
7270 "show ip bgp prefix-list WORD",
7271 SHOW_STR
7272 IP_STR
7273 BGP_STR
7274 "Display routes conforming to the prefix-list\n"
7275 "IP prefix-list name\n")
7276{
7277 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7278 bgp_show_type_prefix_list);
7279}
7280
7281DEFUN (show_ip_bgp_flap_prefix_list,
7282 show_ip_bgp_flap_prefix_list_cmd,
7283 "show ip bgp flap-statistics prefix-list WORD",
7284 SHOW_STR
7285 IP_STR
7286 BGP_STR
7287 "Display flap statistics of routes\n"
7288 "Display routes conforming to the prefix-list\n"
7289 "IP prefix-list name\n")
7290{
7291 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7292 bgp_show_type_flap_prefix_list);
7293}
7294
7295DEFUN (show_ip_bgp_ipv4_prefix_list,
7296 show_ip_bgp_ipv4_prefix_list_cmd,
7297 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7298 SHOW_STR
7299 IP_STR
7300 BGP_STR
7301 "Address family\n"
7302 "Address Family modifier\n"
7303 "Address Family modifier\n"
7304 "Display routes conforming to the prefix-list\n"
7305 "IP prefix-list name\n")
7306{
7307 if (strncmp (argv[0], "m", 1) == 0)
7308 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7309 bgp_show_type_prefix_list);
7310
7311 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7312 bgp_show_type_prefix_list);
7313}
7314
7315#ifdef HAVE_IPV6
7316DEFUN (show_bgp_prefix_list,
7317 show_bgp_prefix_list_cmd,
7318 "show bgp prefix-list WORD",
7319 SHOW_STR
7320 BGP_STR
7321 "Display routes conforming to the prefix-list\n"
7322 "IPv6 prefix-list name\n")
7323{
7324 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7325 bgp_show_type_prefix_list);
7326}
7327
7328ALIAS (show_bgp_prefix_list,
7329 show_bgp_ipv6_prefix_list_cmd,
7330 "show bgp ipv6 prefix-list WORD",
7331 SHOW_STR
7332 BGP_STR
7333 "Address family\n"
7334 "Display routes conforming to the prefix-list\n"
7335 "IPv6 prefix-list name\n")
7336
7337/* old command */
7338DEFUN (show_ipv6_bgp_prefix_list,
7339 show_ipv6_bgp_prefix_list_cmd,
7340 "show ipv6 bgp prefix-list WORD",
7341 SHOW_STR
7342 IPV6_STR
7343 BGP_STR
7344 "Display routes matching the prefix-list\n"
7345 "IPv6 prefix-list name\n")
7346{
7347 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7348 bgp_show_type_prefix_list);
7349}
7350
7351/* old command */
7352DEFUN (show_ipv6_mbgp_prefix_list,
7353 show_ipv6_mbgp_prefix_list_cmd,
7354 "show ipv6 mbgp prefix-list WORD",
7355 SHOW_STR
7356 IPV6_STR
7357 MBGP_STR
7358 "Display routes matching the prefix-list\n"
7359 "IPv6 prefix-list name\n")
7360{
7361 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7362 bgp_show_type_prefix_list);
7363}
7364#endif /* HAVE_IPV6 */
7365\f
94f2b392 7366static int
fd79ac91 7367bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
718e3744 7368 safi_t safi, enum bgp_show_type type)
7369{
7370 struct as_list *as_list;
7371
7372 as_list = as_list_lookup (filter);
7373 if (as_list == NULL)
7374 {
7375 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7376 return CMD_WARNING;
7377 }
7378
5a646650 7379 return bgp_show (vty, NULL, afi, safi, type, as_list);
718e3744 7380}
7381
7382DEFUN (show_ip_bgp_filter_list,
7383 show_ip_bgp_filter_list_cmd,
7384 "show ip bgp filter-list WORD",
7385 SHOW_STR
7386 IP_STR
7387 BGP_STR
7388 "Display routes conforming to the filter-list\n"
7389 "Regular expression access list name\n")
7390{
7391 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7392 bgp_show_type_filter_list);
7393}
7394
7395DEFUN (show_ip_bgp_flap_filter_list,
7396 show_ip_bgp_flap_filter_list_cmd,
7397 "show ip bgp flap-statistics filter-list WORD",
7398 SHOW_STR
7399 IP_STR
7400 BGP_STR
7401 "Display flap statistics of routes\n"
7402 "Display routes conforming to the filter-list\n"
7403 "Regular expression access list name\n")
7404{
7405 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7406 bgp_show_type_flap_filter_list);
7407}
7408
7409DEFUN (show_ip_bgp_ipv4_filter_list,
7410 show_ip_bgp_ipv4_filter_list_cmd,
7411 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7412 SHOW_STR
7413 IP_STR
7414 BGP_STR
7415 "Address family\n"
7416 "Address Family modifier\n"
7417 "Address Family modifier\n"
7418 "Display routes conforming to the filter-list\n"
7419 "Regular expression access list name\n")
7420{
7421 if (strncmp (argv[0], "m", 1) == 0)
7422 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7423 bgp_show_type_filter_list);
7424
7425 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7426 bgp_show_type_filter_list);
7427}
7428
7429#ifdef HAVE_IPV6
7430DEFUN (show_bgp_filter_list,
7431 show_bgp_filter_list_cmd,
7432 "show bgp filter-list WORD",
7433 SHOW_STR
7434 BGP_STR
7435 "Display routes conforming to the filter-list\n"
7436 "Regular expression access list name\n")
7437{
7438 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7439 bgp_show_type_filter_list);
7440}
7441
7442ALIAS (show_bgp_filter_list,
7443 show_bgp_ipv6_filter_list_cmd,
7444 "show bgp ipv6 filter-list WORD",
7445 SHOW_STR
7446 BGP_STR
7447 "Address family\n"
7448 "Display routes conforming to the filter-list\n"
7449 "Regular expression access list name\n")
7450
7451/* old command */
7452DEFUN (show_ipv6_bgp_filter_list,
7453 show_ipv6_bgp_filter_list_cmd,
7454 "show ipv6 bgp filter-list WORD",
7455 SHOW_STR
7456 IPV6_STR
7457 BGP_STR
7458 "Display routes conforming to the filter-list\n"
7459 "Regular expression access list name\n")
7460{
7461 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7462 bgp_show_type_filter_list);
7463}
7464
7465/* old command */
7466DEFUN (show_ipv6_mbgp_filter_list,
7467 show_ipv6_mbgp_filter_list_cmd,
7468 "show ipv6 mbgp filter-list WORD",
7469 SHOW_STR
7470 IPV6_STR
7471 MBGP_STR
7472 "Display routes conforming to the filter-list\n"
7473 "Regular expression access list name\n")
7474{
7475 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7476 bgp_show_type_filter_list);
7477}
7478#endif /* HAVE_IPV6 */
7479\f
94f2b392 7480static int
fd79ac91 7481bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
718e3744 7482 safi_t safi, enum bgp_show_type type)
7483{
7484 struct route_map *rmap;
7485
7486 rmap = route_map_lookup_by_name (rmap_str);
7487 if (! rmap)
7488 {
7489 vty_out (vty, "%% %s is not a valid route-map name%s",
7490 rmap_str, VTY_NEWLINE);
7491 return CMD_WARNING;
7492 }
7493
5a646650 7494 return bgp_show (vty, NULL, afi, safi, type, rmap);
718e3744 7495}
7496
7497DEFUN (show_ip_bgp_route_map,
7498 show_ip_bgp_route_map_cmd,
7499 "show ip bgp route-map WORD",
7500 SHOW_STR
7501 IP_STR
7502 BGP_STR
7503 "Display routes matching the route-map\n"
7504 "A route-map to match on\n")
7505{
7506 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7507 bgp_show_type_route_map);
7508}
7509
7510DEFUN (show_ip_bgp_flap_route_map,
7511 show_ip_bgp_flap_route_map_cmd,
7512 "show ip bgp flap-statistics route-map WORD",
7513 SHOW_STR
7514 IP_STR
7515 BGP_STR
7516 "Display flap statistics of routes\n"
7517 "Display routes matching the route-map\n"
7518 "A route-map to match on\n")
7519{
7520 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7521 bgp_show_type_flap_route_map);
7522}
7523
7524DEFUN (show_ip_bgp_ipv4_route_map,
7525 show_ip_bgp_ipv4_route_map_cmd,
7526 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7527 SHOW_STR
7528 IP_STR
7529 BGP_STR
7530 "Address family\n"
7531 "Address Family modifier\n"
7532 "Address Family modifier\n"
7533 "Display routes matching the route-map\n"
7534 "A route-map to match on\n")
7535{
7536 if (strncmp (argv[0], "m", 1) == 0)
7537 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7538 bgp_show_type_route_map);
7539
7540 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7541 bgp_show_type_route_map);
7542}
7543
7544DEFUN (show_bgp_route_map,
7545 show_bgp_route_map_cmd,
7546 "show bgp route-map WORD",
7547 SHOW_STR
7548 BGP_STR
7549 "Display routes matching the route-map\n"
7550 "A route-map to match on\n")
7551{
7552 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7553 bgp_show_type_route_map);
7554}
7555
7556ALIAS (show_bgp_route_map,
7557 show_bgp_ipv6_route_map_cmd,
7558 "show bgp ipv6 route-map WORD",
7559 SHOW_STR
7560 BGP_STR
7561 "Address family\n"
7562 "Display routes matching the route-map\n"
7563 "A route-map to match on\n")
7564\f
7565DEFUN (show_ip_bgp_cidr_only,
7566 show_ip_bgp_cidr_only_cmd,
7567 "show ip bgp cidr-only",
7568 SHOW_STR
7569 IP_STR
7570 BGP_STR
7571 "Display only routes with non-natural netmasks\n")
7572{
7573 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5a646650 7574 bgp_show_type_cidr_only, NULL);
718e3744 7575}
7576
7577DEFUN (show_ip_bgp_flap_cidr_only,
7578 show_ip_bgp_flap_cidr_only_cmd,
7579 "show ip bgp flap-statistics cidr-only",
7580 SHOW_STR
7581 IP_STR
7582 BGP_STR
7583 "Display flap statistics of routes\n"
7584 "Display only routes with non-natural netmasks\n")
7585{
7586 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5a646650 7587 bgp_show_type_flap_cidr_only, NULL);
718e3744 7588}
7589
7590DEFUN (show_ip_bgp_ipv4_cidr_only,
7591 show_ip_bgp_ipv4_cidr_only_cmd,
7592 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7593 SHOW_STR
7594 IP_STR
7595 BGP_STR
7596 "Address family\n"
7597 "Address Family modifier\n"
7598 "Address Family modifier\n"
7599 "Display only routes with non-natural netmasks\n")
7600{
7601 if (strncmp (argv[0], "m", 1) == 0)
7602 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
5a646650 7603 bgp_show_type_cidr_only, NULL);
718e3744 7604
7605 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5a646650 7606 bgp_show_type_cidr_only, NULL);
718e3744 7607}
7608\f
7609DEFUN (show_ip_bgp_community_all,
7610 show_ip_bgp_community_all_cmd,
7611 "show ip bgp community",
7612 SHOW_STR
7613 IP_STR
7614 BGP_STR
7615 "Display routes matching the communities\n")
7616{
7617 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5a646650 7618 bgp_show_type_community_all, NULL);
718e3744 7619}
7620
7621DEFUN (show_ip_bgp_ipv4_community_all,
7622 show_ip_bgp_ipv4_community_all_cmd,
7623 "show ip bgp ipv4 (unicast|multicast) community",
7624 SHOW_STR
7625 IP_STR
7626 BGP_STR
7627 "Address family\n"
7628 "Address Family modifier\n"
7629 "Address Family modifier\n"
7630 "Display routes matching the communities\n")
7631{
7632 if (strncmp (argv[0], "m", 1) == 0)
7633 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
5a646650 7634 bgp_show_type_community_all, NULL);
718e3744 7635
7636 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5a646650 7637 bgp_show_type_community_all, NULL);
718e3744 7638}
7639
7640#ifdef HAVE_IPV6
7641DEFUN (show_bgp_community_all,
7642 show_bgp_community_all_cmd,
7643 "show bgp community",
7644 SHOW_STR
7645 BGP_STR
7646 "Display routes matching the communities\n")
7647{
7648 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
5a646650 7649 bgp_show_type_community_all, NULL);
718e3744 7650}
7651
7652ALIAS (show_bgp_community_all,
7653 show_bgp_ipv6_community_all_cmd,
7654 "show bgp ipv6 community",
7655 SHOW_STR
7656 BGP_STR
7657 "Address family\n"
7658 "Display routes matching the communities\n")
7659
7660/* old command */
7661DEFUN (show_ipv6_bgp_community_all,
7662 show_ipv6_bgp_community_all_cmd,
7663 "show ipv6 bgp community",
7664 SHOW_STR
7665 IPV6_STR
7666 BGP_STR
7667 "Display routes matching the communities\n")
7668{
7669 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
5a646650 7670 bgp_show_type_community_all, NULL);
718e3744 7671}
7672
7673/* old command */
7674DEFUN (show_ipv6_mbgp_community_all,
7675 show_ipv6_mbgp_community_all_cmd,
7676 "show ipv6 mbgp community",
7677 SHOW_STR
7678 IPV6_STR
7679 MBGP_STR
7680 "Display routes matching the communities\n")
7681{
7682 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
5a646650 7683 bgp_show_type_community_all, NULL);
718e3744 7684}
7685#endif /* HAVE_IPV6 */
7686\f
94f2b392 7687static int
95cbbd2a
ML
7688bgp_show_community (struct vty *vty, const char *view_name, int argc,
7689 const char **argv, int exact, afi_t afi, safi_t safi)
718e3744 7690{
7691 struct community *com;
7692 struct buffer *b;
95cbbd2a 7693 struct bgp *bgp;
718e3744 7694 int i;
7695 char *str;
7696 int first = 0;
7697
95cbbd2a
ML
7698 /* BGP structure lookup */
7699 if (view_name)
7700 {
7701 bgp = bgp_lookup_by_name (view_name);
7702 if (bgp == NULL)
7703 {
7704 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7705 return CMD_WARNING;
7706 }
7707 }
7708 else
7709 {
7710 bgp = bgp_get_default ();
7711 if (bgp == NULL)
7712 {
7713 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7714 return CMD_WARNING;
7715 }
7716 }
7717
718e3744 7718 b = buffer_new (1024);
7719 for (i = 0; i < argc; i++)
7720 {
7721 if (first)
7722 buffer_putc (b, ' ');
7723 else
7724 {
7725 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7726 continue;
7727 first = 1;
7728 }
7729
7730 buffer_putstr (b, argv[i]);
7731 }
7732 buffer_putc (b, '\0');
7733
7734 str = buffer_getstr (b);
7735 buffer_free (b);
7736
7737 com = community_str2com (str);
3b8b1855 7738 XFREE (MTYPE_TMP, str);
718e3744 7739 if (! com)
7740 {
7741 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7742 return CMD_WARNING;
7743 }
7744
95cbbd2a 7745 return bgp_show (vty, bgp, afi, safi,
5a646650 7746 (exact ? bgp_show_type_community_exact :
7747 bgp_show_type_community), com);
718e3744 7748}
7749
7750DEFUN (show_ip_bgp_community,
7751 show_ip_bgp_community_cmd,
7752 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7753 SHOW_STR
7754 IP_STR
7755 BGP_STR
7756 "Display routes matching the communities\n"
7757 "community number\n"
7758 "Do not send outside local AS (well-known community)\n"
7759 "Do not advertise to any peer (well-known community)\n"
7760 "Do not export to next AS (well-known community)\n")
7761{
95cbbd2a 7762 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 7763}
7764
7765ALIAS (show_ip_bgp_community,
7766 show_ip_bgp_community2_cmd,
7767 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7768 SHOW_STR
7769 IP_STR
7770 BGP_STR
7771 "Display routes matching the communities\n"
7772 "community number\n"
7773 "Do not send outside local AS (well-known community)\n"
7774 "Do not advertise to any peer (well-known community)\n"
7775 "Do not export to next AS (well-known community)\n"
7776 "community number\n"
7777 "Do not send outside local AS (well-known community)\n"
7778 "Do not advertise to any peer (well-known community)\n"
7779 "Do not export to next AS (well-known community)\n")
7780
7781ALIAS (show_ip_bgp_community,
7782 show_ip_bgp_community3_cmd,
7783 "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)",
7784 SHOW_STR
7785 IP_STR
7786 BGP_STR
7787 "Display routes matching the communities\n"
7788 "community number\n"
7789 "Do not send outside local AS (well-known community)\n"
7790 "Do not advertise to any peer (well-known community)\n"
7791 "Do not export to next AS (well-known community)\n"
7792 "community number\n"
7793 "Do not send outside local AS (well-known community)\n"
7794 "Do not advertise to any peer (well-known community)\n"
7795 "Do not export to next AS (well-known community)\n"
7796 "community number\n"
7797 "Do not send outside local AS (well-known community)\n"
7798 "Do not advertise to any peer (well-known community)\n"
7799 "Do not export to next AS (well-known community)\n")
7800
7801ALIAS (show_ip_bgp_community,
7802 show_ip_bgp_community4_cmd,
7803 "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)",
7804 SHOW_STR
7805 IP_STR
7806 BGP_STR
7807 "Display routes matching the communities\n"
7808 "community number\n"
7809 "Do not send outside local AS (well-known community)\n"
7810 "Do not advertise to any peer (well-known community)\n"
7811 "Do not export to next AS (well-known community)\n"
7812 "community number\n"
7813 "Do not send outside local AS (well-known community)\n"
7814 "Do not advertise to any peer (well-known community)\n"
7815 "Do not export to next AS (well-known community)\n"
7816 "community number\n"
7817 "Do not send outside local AS (well-known community)\n"
7818 "Do not advertise to any peer (well-known community)\n"
7819 "Do not export to next AS (well-known community)\n"
7820 "community number\n"
7821 "Do not send outside local AS (well-known community)\n"
7822 "Do not advertise to any peer (well-known community)\n"
7823 "Do not export to next AS (well-known community)\n")
7824
7825DEFUN (show_ip_bgp_ipv4_community,
7826 show_ip_bgp_ipv4_community_cmd,
7827 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7828 SHOW_STR
7829 IP_STR
7830 BGP_STR
7831 "Address family\n"
7832 "Address Family modifier\n"
7833 "Address Family modifier\n"
7834 "Display routes matching the communities\n"
7835 "community number\n"
7836 "Do not send outside local AS (well-known community)\n"
7837 "Do not advertise to any peer (well-known community)\n"
7838 "Do not export to next AS (well-known community)\n")
7839{
7840 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 7841 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
718e3744 7842
95cbbd2a 7843 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
718e3744 7844}
7845
7846ALIAS (show_ip_bgp_ipv4_community,
7847 show_ip_bgp_ipv4_community2_cmd,
7848 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7849 SHOW_STR
7850 IP_STR
7851 BGP_STR
7852 "Address family\n"
7853 "Address Family modifier\n"
7854 "Address Family modifier\n"
7855 "Display routes matching the communities\n"
7856 "community number\n"
7857 "Do not send outside local AS (well-known community)\n"
7858 "Do not advertise to any peer (well-known community)\n"
7859 "Do not export to next AS (well-known community)\n"
7860 "community number\n"
7861 "Do not send outside local AS (well-known community)\n"
7862 "Do not advertise to any peer (well-known community)\n"
7863 "Do not export to next AS (well-known community)\n")
7864
7865ALIAS (show_ip_bgp_ipv4_community,
7866 show_ip_bgp_ipv4_community3_cmd,
7867 "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)",
7868 SHOW_STR
7869 IP_STR
7870 BGP_STR
7871 "Address family\n"
7872 "Address Family modifier\n"
7873 "Address Family modifier\n"
7874 "Display routes matching the communities\n"
7875 "community number\n"
7876 "Do not send outside local AS (well-known community)\n"
7877 "Do not advertise to any peer (well-known community)\n"
7878 "Do not export to next AS (well-known community)\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_ipv4_community,
7889 show_ip_bgp_ipv4_community4_cmd,
7890 "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)",
7891 SHOW_STR
7892 IP_STR
7893 BGP_STR
7894 "Address family\n"
7895 "Address Family modifier\n"
7896 "Address Family modifier\n"
7897 "Display routes matching the communities\n"
7898 "community number\n"
7899 "Do not send outside local AS (well-known community)\n"
7900 "Do not advertise to any peer (well-known community)\n"
7901 "Do not export to next AS (well-known community)\n"
7902 "community number\n"
7903 "Do not send outside local AS (well-known community)\n"
7904 "Do not advertise to any peer (well-known community)\n"
7905 "Do not export to next AS (well-known community)\n"
7906 "community number\n"
7907 "Do not send outside local AS (well-known community)\n"
7908 "Do not advertise to any peer (well-known community)\n"
7909 "Do not export to next AS (well-known community)\n"
7910 "community number\n"
7911 "Do not send outside local AS (well-known community)\n"
7912 "Do not advertise to any peer (well-known community)\n"
7913 "Do not export to next AS (well-known community)\n")
7914
95cbbd2a
ML
7915DEFUN (show_bgp_view_afi_safi_community_all,
7916 show_bgp_view_afi_safi_community_all_cmd,
7917#ifdef HAVE_IPV6
7918 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7919#else
7920 "show bgp view WORD ipv4 (unicast|multicast) community",
7921#endif
7922 SHOW_STR
7923 BGP_STR
7924 "BGP view\n"
2b00515a 7925 "View name\n"
95cbbd2a
ML
7926 "Address family\n"
7927#ifdef HAVE_IPV6
7928 "Address family\n"
7929#endif
7930 "Address Family modifier\n"
7931 "Address Family modifier\n"
2b00515a 7932 "Display routes matching the communities\n")
95cbbd2a
ML
7933{
7934 int afi;
7935 int safi;
7936 struct bgp *bgp;
7937
7938 /* BGP structure lookup. */
7939 bgp = bgp_lookup_by_name (argv[0]);
7940 if (bgp == NULL)
7941 {
7942 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7943 return CMD_WARNING;
7944 }
7945
7946#ifdef HAVE_IPV6
7947 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7948 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7949#else
7950 afi = AFI_IP;
7951 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7952#endif
7953 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7954}
7955
7956DEFUN (show_bgp_view_afi_safi_community,
7957 show_bgp_view_afi_safi_community_cmd,
7958#ifdef HAVE_IPV6
7959 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7960#else
7961 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7962#endif
7963 SHOW_STR
7964 BGP_STR
7965 "BGP view\n"
2b00515a 7966 "View name\n"
95cbbd2a
ML
7967 "Address family\n"
7968#ifdef HAVE_IPV6
7969 "Address family\n"
7970#endif
7971 "Address family modifier\n"
7972 "Address family modifier\n"
7973 "Display routes matching the communities\n"
7974 "community number\n"
7975 "Do not send outside local AS (well-known community)\n"
7976 "Do not advertise to any peer (well-known community)\n"
7977 "Do not export to next AS (well-known community)\n")
7978{
7979 int afi;
7980 int safi;
7981
7982#ifdef HAVE_IPV6
7983 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7984 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7985 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7986#else
7987 afi = AFI_IP;
7988 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7989 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7990#endif
7991}
7992
7993ALIAS (show_bgp_view_afi_safi_community,
7994 show_bgp_view_afi_safi_community2_cmd,
7995#ifdef HAVE_IPV6
7996 "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)",
7997#else
7998 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7999#endif
8000 SHOW_STR
8001 BGP_STR
8002 "BGP view\n"
2b00515a 8003 "View name\n"
95cbbd2a
ML
8004 "Address family\n"
8005#ifdef HAVE_IPV6
8006 "Address family\n"
8007#endif
8008 "Address family modifier\n"
8009 "Address family modifier\n"
8010 "Display routes matching the communities\n"
8011 "community number\n"
8012 "Do not send outside local AS (well-known community)\n"
8013 "Do not advertise to any peer (well-known community)\n"
8014 "Do not export to next AS (well-known community)\n"
8015 "community number\n"
8016 "Do not send outside local AS (well-known community)\n"
8017 "Do not advertise to any peer (well-known community)\n"
8018 "Do not export to next AS (well-known community)\n")
8019
8020ALIAS (show_bgp_view_afi_safi_community,
8021 show_bgp_view_afi_safi_community3_cmd,
8022#ifdef HAVE_IPV6
8023 "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)",
8024#else
8025 "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)",
8026#endif
8027 SHOW_STR
8028 BGP_STR
8029 "BGP view\n"
2b00515a 8030 "View name\n"
95cbbd2a
ML
8031 "Address family\n"
8032#ifdef HAVE_IPV6
8033 "Address family\n"
8034#endif
8035 "Address family modifier\n"
8036 "Address family modifier\n"
8037 "Display routes matching the communities\n"
8038 "community number\n"
8039 "Do not send outside local AS (well-known community)\n"
8040 "Do not advertise to any peer (well-known community)\n"
8041 "Do not export to next AS (well-known community)\n"
8042 "community number\n"
8043 "Do not send outside local AS (well-known community)\n"
8044 "Do not advertise to any peer (well-known community)\n"
8045 "Do not export to next AS (well-known community)\n"
8046 "community number\n"
8047 "Do not send outside local AS (well-known community)\n"
8048 "Do not advertise to any peer (well-known community)\n"
8049 "Do not export to next AS (well-known community)\n")
8050
8051ALIAS (show_bgp_view_afi_safi_community,
8052 show_bgp_view_afi_safi_community4_cmd,
8053#ifdef HAVE_IPV6
8054 "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)",
8055#else
8056 "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)",
8057#endif
8058 SHOW_STR
8059 BGP_STR
8060 "BGP view\n"
2b00515a 8061 "View name\n"
95cbbd2a
ML
8062 "Address family\n"
8063#ifdef HAVE_IPV6
8064 "Address family\n"
8065#endif
8066 "Address family modifier\n"
8067 "Address family modifier\n"
8068 "Display routes matching the communities\n"
8069 "community number\n"
8070 "Do not send outside local AS (well-known community)\n"
8071 "Do not advertise to any peer (well-known community)\n"
8072 "Do not export to next AS (well-known community)\n"
8073 "community number\n"
8074 "Do not send outside local AS (well-known community)\n"
8075 "Do not advertise to any peer (well-known community)\n"
8076 "Do not export to next AS (well-known community)\n"
8077 "community number\n"
8078 "Do not send outside local AS (well-known community)\n"
8079 "Do not advertise to any peer (well-known community)\n"
8080 "Do not export to next AS (well-known community)\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
718e3744 8086DEFUN (show_ip_bgp_community_exact,
8087 show_ip_bgp_community_exact_cmd,
8088 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8089 SHOW_STR
8090 IP_STR
8091 BGP_STR
8092 "Display routes matching the communities\n"
8093 "community number\n"
8094 "Do not send outside local AS (well-known community)\n"
8095 "Do not advertise to any peer (well-known community)\n"
8096 "Do not export to next AS (well-known community)\n"
8097 "Exact match of the communities")
8098{
95cbbd2a 8099 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 8100}
8101
8102ALIAS (show_ip_bgp_community_exact,
8103 show_ip_bgp_community2_exact_cmd,
8104 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8105 SHOW_STR
8106 IP_STR
8107 BGP_STR
8108 "Display routes matching the communities\n"
8109 "community number\n"
8110 "Do not send outside local AS (well-known community)\n"
8111 "Do not advertise to any peer (well-known community)\n"
8112 "Do not export to next AS (well-known community)\n"
8113 "community number\n"
8114 "Do not send outside local AS (well-known community)\n"
8115 "Do not advertise to any peer (well-known community)\n"
8116 "Do not export to next AS (well-known community)\n"
8117 "Exact match of the communities")
8118
8119ALIAS (show_ip_bgp_community_exact,
8120 show_ip_bgp_community3_exact_cmd,
8121 "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",
8122 SHOW_STR
8123 IP_STR
8124 BGP_STR
8125 "Display routes matching the communities\n"
8126 "community number\n"
8127 "Do not send outside local AS (well-known community)\n"
8128 "Do not advertise to any peer (well-known community)\n"
8129 "Do not export to next AS (well-known community)\n"
8130 "community number\n"
8131 "Do not send outside local AS (well-known community)\n"
8132 "Do not advertise to any peer (well-known community)\n"
8133 "Do not export to next AS (well-known community)\n"
8134 "community number\n"
8135 "Do not send outside local AS (well-known community)\n"
8136 "Do not advertise to any peer (well-known community)\n"
8137 "Do not export to next AS (well-known community)\n"
8138 "Exact match of the communities")
8139
8140ALIAS (show_ip_bgp_community_exact,
8141 show_ip_bgp_community4_exact_cmd,
8142 "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",
8143 SHOW_STR
8144 IP_STR
8145 BGP_STR
8146 "Display routes matching the communities\n"
8147 "community number\n"
8148 "Do not send outside local AS (well-known community)\n"
8149 "Do not advertise to any peer (well-known community)\n"
8150 "Do not export to next AS (well-known community)\n"
8151 "community number\n"
8152 "Do not send outside local AS (well-known community)\n"
8153 "Do not advertise to any peer (well-known community)\n"
8154 "Do not export to next AS (well-known community)\n"
8155 "community number\n"
8156 "Do not send outside local AS (well-known community)\n"
8157 "Do not advertise to any peer (well-known community)\n"
8158 "Do not export to next AS (well-known community)\n"
8159 "community number\n"
8160 "Do not send outside local AS (well-known community)\n"
8161 "Do not advertise to any peer (well-known community)\n"
8162 "Do not export to next AS (well-known community)\n"
8163 "Exact match of the communities")
8164
8165DEFUN (show_ip_bgp_ipv4_community_exact,
8166 show_ip_bgp_ipv4_community_exact_cmd,
8167 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8168 SHOW_STR
8169 IP_STR
8170 BGP_STR
8171 "Address family\n"
8172 "Address Family modifier\n"
8173 "Address Family modifier\n"
8174 "Display routes matching the communities\n"
8175 "community number\n"
8176 "Do not send outside local AS (well-known community)\n"
8177 "Do not advertise to any peer (well-known community)\n"
8178 "Do not export to next AS (well-known community)\n"
8179 "Exact match of the communities")
8180{
8181 if (strncmp (argv[0], "m", 1) == 0)
95cbbd2a 8182 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
718e3744 8183
95cbbd2a 8184 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
718e3744 8185}
8186
8187ALIAS (show_ip_bgp_ipv4_community_exact,
8188 show_ip_bgp_ipv4_community2_exact_cmd,
8189 "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",
8190 SHOW_STR
8191 IP_STR
8192 BGP_STR
8193 "Address family\n"
8194 "Address Family modifier\n"
8195 "Address Family modifier\n"
8196 "Display routes matching the communities\n"
8197 "community number\n"
8198 "Do not send outside local AS (well-known community)\n"
8199 "Do not advertise to any peer (well-known community)\n"
8200 "Do not export to next AS (well-known community)\n"
8201 "community number\n"
8202 "Do not send outside local AS (well-known community)\n"
8203 "Do not advertise to any peer (well-known community)\n"
8204 "Do not export to next AS (well-known community)\n"
8205 "Exact match of the communities")
8206
8207ALIAS (show_ip_bgp_ipv4_community_exact,
8208 show_ip_bgp_ipv4_community3_exact_cmd,
8209 "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",
8210 SHOW_STR
8211 IP_STR
8212 BGP_STR
8213 "Address family\n"
8214 "Address Family modifier\n"
8215 "Address Family modifier\n"
8216 "Display routes matching the communities\n"
8217 "community number\n"
8218 "Do not send outside local AS (well-known community)\n"
8219 "Do not advertise to any peer (well-known community)\n"
8220 "Do not export to next AS (well-known community)\n"
8221 "community number\n"
8222 "Do not send outside local AS (well-known community)\n"
8223 "Do not advertise to any peer (well-known community)\n"
8224 "Do not export to next AS (well-known community)\n"
8225 "community number\n"
8226 "Do not send outside local AS (well-known community)\n"
8227 "Do not advertise to any peer (well-known community)\n"
8228 "Do not export to next AS (well-known community)\n"
8229 "Exact match of the communities")
8230
8231ALIAS (show_ip_bgp_ipv4_community_exact,
8232 show_ip_bgp_ipv4_community4_exact_cmd,
8233 "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",
8234 SHOW_STR
8235 IP_STR
8236 BGP_STR
8237 "Address family\n"
8238 "Address Family modifier\n"
8239 "Address Family modifier\n"
8240 "Display routes matching the communities\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 "community number\n"
8246 "Do not send outside local AS (well-known community)\n"
8247 "Do not advertise to any peer (well-known community)\n"
8248 "Do not export to next AS (well-known community)\n"
8249 "community number\n"
8250 "Do not send outside local AS (well-known community)\n"
8251 "Do not advertise to any peer (well-known community)\n"
8252 "Do not export to next AS (well-known community)\n"
8253 "community number\n"
8254 "Do not send outside local AS (well-known community)\n"
8255 "Do not advertise to any peer (well-known community)\n"
8256 "Do not export to next AS (well-known community)\n"
8257 "Exact match of the communities")
8258
8259#ifdef HAVE_IPV6
8260DEFUN (show_bgp_community,
8261 show_bgp_community_cmd,
8262 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8263 SHOW_STR
8264 BGP_STR
8265 "Display routes matching the communities\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{
95cbbd2a 8271 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 8272}
8273
8274ALIAS (show_bgp_community,
8275 show_bgp_ipv6_community_cmd,
8276 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8277 SHOW_STR
8278 BGP_STR
8279 "Address family\n"
8280 "Display routes matching the communities\n"
8281 "community number\n"
8282 "Do not send outside local AS (well-known community)\n"
8283 "Do not advertise to any peer (well-known community)\n"
8284 "Do not export to next AS (well-known community)\n")
8285
8286ALIAS (show_bgp_community,
8287 show_bgp_community2_cmd,
8288 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8289 SHOW_STR
8290 BGP_STR
8291 "Display routes matching the communities\n"
8292 "community number\n"
8293 "Do not send outside local AS (well-known community)\n"
8294 "Do not advertise to any peer (well-known community)\n"
8295 "Do not export to next AS (well-known community)\n"
8296 "community number\n"
8297 "Do not send outside local AS (well-known community)\n"
8298 "Do not advertise to any peer (well-known community)\n"
8299 "Do not export to next AS (well-known community)\n")
8300
8301ALIAS (show_bgp_community,
8302 show_bgp_ipv6_community2_cmd,
8303 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8304 SHOW_STR
8305 BGP_STR
8306 "Address family\n"
8307 "Display routes matching the communities\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 "community number\n"
8313 "Do not send outside local AS (well-known community)\n"
8314 "Do not advertise to any peer (well-known community)\n"
8315 "Do not export to next AS (well-known community)\n")
8316
8317ALIAS (show_bgp_community,
8318 show_bgp_community3_cmd,
8319 "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)",
8320 SHOW_STR
8321 BGP_STR
8322 "Display routes matching the communities\n"
8323 "community number\n"
8324 "Do not send outside local AS (well-known community)\n"
8325 "Do not advertise to any peer (well-known community)\n"
8326 "Do not export to next AS (well-known community)\n"
8327 "community number\n"
8328 "Do not send outside local AS (well-known community)\n"
8329 "Do not advertise to any peer (well-known community)\n"
8330 "Do not export to next AS (well-known community)\n"
8331 "community number\n"
8332 "Do not send outside local AS (well-known community)\n"
8333 "Do not advertise to any peer (well-known community)\n"
8334 "Do not export to next AS (well-known community)\n")
8335
8336ALIAS (show_bgp_community,
8337 show_bgp_ipv6_community3_cmd,
8338 "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)",
8339 SHOW_STR
8340 BGP_STR
8341 "Address family\n"
8342 "Display routes matching the communities\n"
8343 "community number\n"
8344 "Do not send outside local AS (well-known community)\n"
8345 "Do not advertise to any peer (well-known community)\n"
8346 "Do not export to next AS (well-known community)\n"
8347 "community number\n"
8348 "Do not send outside local AS (well-known community)\n"
8349 "Do not advertise to any peer (well-known community)\n"
8350 "Do not export to next AS (well-known community)\n"
8351 "community number\n"
8352 "Do not send outside local AS (well-known community)\n"
8353 "Do not advertise to any peer (well-known community)\n"
8354 "Do not export to next AS (well-known community)\n")
8355
8356ALIAS (show_bgp_community,
8357 show_bgp_community4_cmd,
8358 "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)",
8359 SHOW_STR
8360 BGP_STR
8361 "Display routes matching the communities\n"
8362 "community number\n"
8363 "Do not send outside local AS (well-known community)\n"
8364 "Do not advertise to any peer (well-known community)\n"
8365 "Do not export to next AS (well-known community)\n"
8366 "community number\n"
8367 "Do not send outside local AS (well-known community)\n"
8368 "Do not advertise to any peer (well-known community)\n"
8369 "Do not export to next AS (well-known community)\n"
8370 "community number\n"
8371 "Do not send outside local AS (well-known community)\n"
8372 "Do not advertise to any peer (well-known community)\n"
8373 "Do not export to next AS (well-known community)\n"
8374 "community number\n"
8375 "Do not send outside local AS (well-known community)\n"
8376 "Do not advertise to any peer (well-known community)\n"
8377 "Do not export to next AS (well-known community)\n")
8378
8379ALIAS (show_bgp_community,
8380 show_bgp_ipv6_community4_cmd,
8381 "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)",
8382 SHOW_STR
8383 BGP_STR
8384 "Address family\n"
8385 "Display routes matching the communities\n"
8386 "community number\n"
8387 "Do not send outside local AS (well-known community)\n"
8388 "Do not advertise to any peer (well-known community)\n"
8389 "Do not export to next AS (well-known community)\n"
8390 "community number\n"
8391 "Do not send outside local AS (well-known community)\n"
8392 "Do not advertise to any peer (well-known community)\n"
8393 "Do not export to next AS (well-known community)\n"
8394 "community number\n"
8395 "Do not send outside local AS (well-known community)\n"
8396 "Do not advertise to any peer (well-known community)\n"
8397 "Do not export to next AS (well-known community)\n"
8398 "community number\n"
8399 "Do not send outside local AS (well-known community)\n"
8400 "Do not advertise to any peer (well-known community)\n"
8401 "Do not export to next AS (well-known community)\n")
8402
8403/* old command */
8404DEFUN (show_ipv6_bgp_community,
8405 show_ipv6_bgp_community_cmd,
8406 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8407 SHOW_STR
8408 IPV6_STR
8409 BGP_STR
8410 "Display routes matching the communities\n"
8411 "community number\n"
8412 "Do not send outside local AS (well-known community)\n"
8413 "Do not advertise to any peer (well-known community)\n"
8414 "Do not export to next AS (well-known community)\n")
8415{
95cbbd2a 8416 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
718e3744 8417}
8418
8419/* old command */
8420ALIAS (show_ipv6_bgp_community,
8421 show_ipv6_bgp_community2_cmd,
8422 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8423 SHOW_STR
8424 IPV6_STR
8425 BGP_STR
8426 "Display routes matching the communities\n"
8427 "community number\n"
8428 "Do not send outside local AS (well-known community)\n"
8429 "Do not advertise to any peer (well-known community)\n"
8430 "Do not export to next AS (well-known community)\n"
8431 "community number\n"
8432 "Do not send outside local AS (well-known community)\n"
8433 "Do not advertise to any peer (well-known community)\n"
8434 "Do not export to next AS (well-known community)\n")
8435
8436/* old command */
8437ALIAS (show_ipv6_bgp_community,
8438 show_ipv6_bgp_community3_cmd,
8439 "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)",
8440 SHOW_STR
8441 IPV6_STR
8442 BGP_STR
8443 "Display routes matching the communities\n"
8444 "community number\n"
8445 "Do not send outside local AS (well-known community)\n"
8446 "Do not advertise to any peer (well-known community)\n"
8447 "Do not export to next AS (well-known community)\n"
8448 "community number\n"
8449 "Do not send outside local AS (well-known community)\n"
8450 "Do not advertise to any peer (well-known community)\n"
8451 "Do not export to next AS (well-known community)\n"
8452 "community number\n"
8453 "Do not send outside local AS (well-known community)\n"
8454 "Do not advertise to any peer (well-known community)\n"
8455 "Do not export to next AS (well-known community)\n")
8456
8457/* old command */
8458ALIAS (show_ipv6_bgp_community,
8459 show_ipv6_bgp_community4_cmd,
8460 "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)",
8461 SHOW_STR
8462 IPV6_STR
8463 BGP_STR
8464 "Display routes matching the communities\n"
8465 "community number\n"
8466 "Do not send outside local AS (well-known community)\n"
8467 "Do not advertise to any peer (well-known community)\n"
8468 "Do not export to next AS (well-known community)\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
8482DEFUN (show_bgp_community_exact,
8483 show_bgp_community_exact_cmd,
8484 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8485 SHOW_STR
8486 BGP_STR
8487 "Display routes matching the communities\n"
8488 "community number\n"
8489 "Do not send outside local AS (well-known community)\n"
8490 "Do not advertise to any peer (well-known community)\n"
8491 "Do not export to next AS (well-known community)\n"
8492 "Exact match of the communities")
8493{
95cbbd2a 8494 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 8495}
8496
8497ALIAS (show_bgp_community_exact,
8498 show_bgp_ipv6_community_exact_cmd,
8499 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8500 SHOW_STR
8501 BGP_STR
8502 "Address family\n"
8503 "Display routes matching the communities\n"
8504 "community number\n"
8505 "Do not send outside local AS (well-known community)\n"
8506 "Do not advertise to any peer (well-known community)\n"
8507 "Do not export to next AS (well-known community)\n"
8508 "Exact match of the communities")
8509
8510ALIAS (show_bgp_community_exact,
8511 show_bgp_community2_exact_cmd,
8512 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8513 SHOW_STR
8514 BGP_STR
8515 "Display routes matching the communities\n"
8516 "community number\n"
8517 "Do not send outside local AS (well-known community)\n"
8518 "Do not advertise to any peer (well-known community)\n"
8519 "Do not export to next AS (well-known community)\n"
8520 "community number\n"
8521 "Do not send outside local AS (well-known community)\n"
8522 "Do not advertise to any peer (well-known community)\n"
8523 "Do not export to next AS (well-known community)\n"
8524 "Exact match of the communities")
8525
8526ALIAS (show_bgp_community_exact,
8527 show_bgp_ipv6_community2_exact_cmd,
8528 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8529 SHOW_STR
8530 BGP_STR
8531 "Address family\n"
8532 "Display routes matching the communities\n"
8533 "community number\n"
8534 "Do not send outside local AS (well-known community)\n"
8535 "Do not advertise to any peer (well-known community)\n"
8536 "Do not export to next AS (well-known community)\n"
8537 "community number\n"
8538 "Do not send outside local AS (well-known community)\n"
8539 "Do not advertise to any peer (well-known community)\n"
8540 "Do not export to next AS (well-known community)\n"
8541 "Exact match of the communities")
8542
8543ALIAS (show_bgp_community_exact,
8544 show_bgp_community3_exact_cmd,
8545 "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",
8546 SHOW_STR
8547 BGP_STR
8548 "Display routes matching the communities\n"
8549 "community number\n"
8550 "Do not send outside local AS (well-known community)\n"
8551 "Do not advertise to any peer (well-known community)\n"
8552 "Do not export to next AS (well-known community)\n"
8553 "community number\n"
8554 "Do not send outside local AS (well-known community)\n"
8555 "Do not advertise to any peer (well-known community)\n"
8556 "Do not export to next AS (well-known community)\n"
8557 "community number\n"
8558 "Do not send outside local AS (well-known community)\n"
8559 "Do not advertise to any peer (well-known community)\n"
8560 "Do not export to next AS (well-known community)\n"
8561 "Exact match of the communities")
8562
8563ALIAS (show_bgp_community_exact,
8564 show_bgp_ipv6_community3_exact_cmd,
8565 "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",
8566 SHOW_STR
8567 BGP_STR
8568 "Address family\n"
8569 "Display routes matching the communities\n"
8570 "community number\n"
8571 "Do not send outside local AS (well-known community)\n"
8572 "Do not advertise to any peer (well-known community)\n"
8573 "Do not export to next AS (well-known community)\n"
8574 "community number\n"
8575 "Do not send outside local AS (well-known community)\n"
8576 "Do not advertise to any peer (well-known community)\n"
8577 "Do not export to next AS (well-known community)\n"
8578 "community number\n"
8579 "Do not send outside local AS (well-known community)\n"
8580 "Do not advertise to any peer (well-known community)\n"
8581 "Do not export to next AS (well-known community)\n"
8582 "Exact match of the communities")
8583
8584ALIAS (show_bgp_community_exact,
8585 show_bgp_community4_exact_cmd,
8586 "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",
8587 SHOW_STR
8588 BGP_STR
8589 "Display routes matching the communities\n"
8590 "community number\n"
8591 "Do not send outside local AS (well-known community)\n"
8592 "Do not advertise to any peer (well-known community)\n"
8593 "Do not export to next AS (well-known community)\n"
8594 "community number\n"
8595 "Do not send outside local AS (well-known community)\n"
8596 "Do not advertise to any peer (well-known community)\n"
8597 "Do not export to next AS (well-known community)\n"
8598 "community number\n"
8599 "Do not send outside local AS (well-known community)\n"
8600 "Do not advertise to any peer (well-known community)\n"
8601 "Do not export to next AS (well-known community)\n"
8602 "community number\n"
8603 "Do not send outside local AS (well-known community)\n"
8604 "Do not advertise to any peer (well-known community)\n"
8605 "Do not export to next AS (well-known community)\n"
8606 "Exact match of the communities")
8607
8608ALIAS (show_bgp_community_exact,
8609 show_bgp_ipv6_community4_exact_cmd,
8610 "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",
8611 SHOW_STR
8612 BGP_STR
8613 "Address family\n"
8614 "Display routes matching the communities\n"
8615 "community number\n"
8616 "Do not send outside local AS (well-known community)\n"
8617 "Do not advertise to any peer (well-known community)\n"
8618 "Do not export to next AS (well-known community)\n"
8619 "community number\n"
8620 "Do not send outside local AS (well-known community)\n"
8621 "Do not advertise to any peer (well-known community)\n"
8622 "Do not export to next AS (well-known community)\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
8633/* old command */
8634DEFUN (show_ipv6_bgp_community_exact,
8635 show_ipv6_bgp_community_exact_cmd,
8636 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8637 SHOW_STR
8638 IPV6_STR
8639 BGP_STR
8640 "Display routes matching the communities\n"
8641 "community number\n"
8642 "Do not send outside local AS (well-known community)\n"
8643 "Do not advertise to any peer (well-known community)\n"
8644 "Do not export to next AS (well-known community)\n"
8645 "Exact match of the communities")
8646{
95cbbd2a 8647 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
718e3744 8648}
8649
8650/* old command */
8651ALIAS (show_ipv6_bgp_community_exact,
8652 show_ipv6_bgp_community2_exact_cmd,
8653 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8654 SHOW_STR
8655 IPV6_STR
8656 BGP_STR
8657 "Display routes matching the communities\n"
8658 "community number\n"
8659 "Do not send outside local AS (well-known community)\n"
8660 "Do not advertise to any peer (well-known community)\n"
8661 "Do not export to next AS (well-known community)\n"
8662 "community number\n"
8663 "Do not send outside local AS (well-known community)\n"
8664 "Do not advertise to any peer (well-known community)\n"
8665 "Do not export to next AS (well-known community)\n"
8666 "Exact match of the communities")
8667
8668/* old command */
8669ALIAS (show_ipv6_bgp_community_exact,
8670 show_ipv6_bgp_community3_exact_cmd,
8671 "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",
8672 SHOW_STR
8673 IPV6_STR
8674 BGP_STR
8675 "Display routes matching the communities\n"
8676 "community number\n"
8677 "Do not send outside local AS (well-known community)\n"
8678 "Do not advertise to any peer (well-known community)\n"
8679 "Do not export to next AS (well-known community)\n"
8680 "community number\n"
8681 "Do not send outside local AS (well-known community)\n"
8682 "Do not advertise to any peer (well-known community)\n"
8683 "Do not export to next AS (well-known community)\n"
8684 "community number\n"
8685 "Do not send outside local AS (well-known community)\n"
8686 "Do not advertise to any peer (well-known community)\n"
8687 "Do not export to next AS (well-known community)\n"
8688 "Exact match of the communities")
8689
8690/* old command */
8691ALIAS (show_ipv6_bgp_community_exact,
8692 show_ipv6_bgp_community4_exact_cmd,
8693 "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",
8694 SHOW_STR
8695 IPV6_STR
8696 BGP_STR
8697 "Display routes matching the communities\n"
8698 "community number\n"
8699 "Do not send outside local AS (well-known community)\n"
8700 "Do not advertise to any peer (well-known community)\n"
8701 "Do not export to next AS (well-known community)\n"
8702 "community number\n"
8703 "Do not send outside local AS (well-known community)\n"
8704 "Do not advertise to any peer (well-known community)\n"
8705 "Do not export to next AS (well-known community)\n"
8706 "community number\n"
8707 "Do not send outside local AS (well-known community)\n"
8708 "Do not advertise to any peer (well-known community)\n"
8709 "Do not export to next AS (well-known community)\n"
8710 "community number\n"
8711 "Do not send outside local AS (well-known community)\n"
8712 "Do not advertise to any peer (well-known community)\n"
8713 "Do not export to next AS (well-known community)\n"
8714 "Exact match of the communities")
8715
8716/* old command */
8717DEFUN (show_ipv6_mbgp_community,
8718 show_ipv6_mbgp_community_cmd,
8719 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8720 SHOW_STR
8721 IPV6_STR
8722 MBGP_STR
8723 "Display routes matching the communities\n"
8724 "community number\n"
8725 "Do not send outside local AS (well-known community)\n"
8726 "Do not advertise to any peer (well-known community)\n"
8727 "Do not export to next AS (well-known community)\n")
8728{
95cbbd2a 8729 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
718e3744 8730}
8731
8732/* old command */
8733ALIAS (show_ipv6_mbgp_community,
8734 show_ipv6_mbgp_community2_cmd,
8735 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8736 SHOW_STR
8737 IPV6_STR
8738 MBGP_STR
8739 "Display routes matching the communities\n"
8740 "community number\n"
8741 "Do not send outside local AS (well-known community)\n"
8742 "Do not advertise to any peer (well-known community)\n"
8743 "Do not export to next AS (well-known community)\n"
8744 "community number\n"
8745 "Do not send outside local AS (well-known community)\n"
8746 "Do not advertise to any peer (well-known community)\n"
8747 "Do not export to next AS (well-known community)\n")
8748
8749/* old command */
8750ALIAS (show_ipv6_mbgp_community,
8751 show_ipv6_mbgp_community3_cmd,
8752 "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)",
8753 SHOW_STR
8754 IPV6_STR
8755 MBGP_STR
8756 "Display routes matching the communities\n"
8757 "community number\n"
8758 "Do not send outside local AS (well-known community)\n"
8759 "Do not advertise to any peer (well-known community)\n"
8760 "Do not export to next AS (well-known community)\n"
8761 "community number\n"
8762 "Do not send outside local AS (well-known community)\n"
8763 "Do not advertise to any peer (well-known community)\n"
8764 "Do not export to next AS (well-known community)\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
8770/* old command */
8771ALIAS (show_ipv6_mbgp_community,
8772 show_ipv6_mbgp_community4_cmd,
8773 "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)",
8774 SHOW_STR
8775 IPV6_STR
8776 MBGP_STR
8777 "Display routes matching the communities\n"
8778 "community number\n"
8779 "Do not send outside local AS (well-known community)\n"
8780 "Do not advertise to any peer (well-known community)\n"
8781 "Do not export to next AS (well-known community)\n"
8782 "community number\n"
8783 "Do not send outside local AS (well-known community)\n"
8784 "Do not advertise to any peer (well-known community)\n"
8785 "Do not export to next AS (well-known community)\n"
8786 "community number\n"
8787 "Do not send outside local AS (well-known community)\n"
8788 "Do not advertise to any peer (well-known community)\n"
8789 "Do not export to next AS (well-known community)\n"
8790 "community number\n"
8791 "Do not send outside local AS (well-known community)\n"
8792 "Do not advertise to any peer (well-known community)\n"
8793 "Do not export to next AS (well-known community)\n")
8794
8795/* old command */
8796DEFUN (show_ipv6_mbgp_community_exact,
8797 show_ipv6_mbgp_community_exact_cmd,
8798 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8799 SHOW_STR
8800 IPV6_STR
8801 MBGP_STR
8802 "Display routes matching the communities\n"
8803 "community number\n"
8804 "Do not send outside local AS (well-known community)\n"
8805 "Do not advertise to any peer (well-known community)\n"
8806 "Do not export to next AS (well-known community)\n"
8807 "Exact match of the communities")
8808{
95cbbd2a 8809 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
718e3744 8810}
8811
8812/* old command */
8813ALIAS (show_ipv6_mbgp_community_exact,
8814 show_ipv6_mbgp_community2_exact_cmd,
8815 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8816 SHOW_STR
8817 IPV6_STR
8818 MBGP_STR
8819 "Display routes matching the communities\n"
8820 "community number\n"
8821 "Do not send outside local AS (well-known community)\n"
8822 "Do not advertise to any peer (well-known community)\n"
8823 "Do not export to next AS (well-known community)\n"
8824 "community number\n"
8825 "Do not send outside local AS (well-known community)\n"
8826 "Do not advertise to any peer (well-known community)\n"
8827 "Do not export to next AS (well-known community)\n"
8828 "Exact match of the communities")
8829
8830/* old command */
8831ALIAS (show_ipv6_mbgp_community_exact,
8832 show_ipv6_mbgp_community3_exact_cmd,
8833 "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",
8834 SHOW_STR
8835 IPV6_STR
8836 MBGP_STR
8837 "Display routes matching the communities\n"
8838 "community number\n"
8839 "Do not send outside local AS (well-known community)\n"
8840 "Do not advertise to any peer (well-known community)\n"
8841 "Do not export to next AS (well-known community)\n"
8842 "community number\n"
8843 "Do not send outside local AS (well-known community)\n"
8844 "Do not advertise to any peer (well-known community)\n"
8845 "Do not export to next AS (well-known community)\n"
8846 "community number\n"
8847 "Do not send outside local AS (well-known community)\n"
8848 "Do not advertise to any peer (well-known community)\n"
8849 "Do not export to next AS (well-known community)\n"
8850 "Exact match of the communities")
8851
8852/* old command */
8853ALIAS (show_ipv6_mbgp_community_exact,
8854 show_ipv6_mbgp_community4_exact_cmd,
8855 "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",
8856 SHOW_STR
8857 IPV6_STR
8858 MBGP_STR
8859 "Display routes matching the communities\n"
8860 "community number\n"
8861 "Do not send outside local AS (well-known community)\n"
8862 "Do not advertise to any peer (well-known community)\n"
8863 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8877#endif /* HAVE_IPV6 */
8878\f
94f2b392 8879static int
fd79ac91 8880bgp_show_community_list (struct vty *vty, const char *com, int exact,
4c9641ba 8881 afi_t afi, safi_t safi)
718e3744 8882{
8883 struct community_list *list;
8884
fee6e4e4 8885 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
718e3744 8886 if (list == NULL)
8887 {
8888 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8889 VTY_NEWLINE);
8890 return CMD_WARNING;
8891 }
8892
5a646650 8893 return bgp_show (vty, NULL, afi, safi,
8894 (exact ? bgp_show_type_community_list_exact :
8895 bgp_show_type_community_list), list);
718e3744 8896}
8897
8898DEFUN (show_ip_bgp_community_list,
8899 show_ip_bgp_community_list_cmd,
fee6e4e4 8900 "show ip bgp community-list (<1-500>|WORD)",
718e3744 8901 SHOW_STR
8902 IP_STR
8903 BGP_STR
8904 "Display routes matching the community-list\n"
fee6e4e4 8905 "community-list number\n"
718e3744 8906 "community-list name\n")
8907{
8908 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8909}
8910
8911DEFUN (show_ip_bgp_ipv4_community_list,
8912 show_ip_bgp_ipv4_community_list_cmd,
fee6e4e4 8913 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
718e3744 8914 SHOW_STR
8915 IP_STR
8916 BGP_STR
8917 "Address family\n"
8918 "Address Family modifier\n"
8919 "Address Family modifier\n"
8920 "Display routes matching the community-list\n"
fee6e4e4 8921 "community-list number\n"
718e3744 8922 "community-list name\n")
8923{
8924 if (strncmp (argv[0], "m", 1) == 0)
8925 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8926
8927 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8928}
8929
8930DEFUN (show_ip_bgp_community_list_exact,
8931 show_ip_bgp_community_list_exact_cmd,
fee6e4e4 8932 "show ip bgp community-list (<1-500>|WORD) exact-match",
718e3744 8933 SHOW_STR
8934 IP_STR
8935 BGP_STR
8936 "Display routes matching the community-list\n"
fee6e4e4 8937 "community-list number\n"
718e3744 8938 "community-list name\n"
8939 "Exact match of the communities\n")
8940{
8941 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8942}
8943
8944DEFUN (show_ip_bgp_ipv4_community_list_exact,
8945 show_ip_bgp_ipv4_community_list_exact_cmd,
fee6e4e4 8946 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
718e3744 8947 SHOW_STR
8948 IP_STR
8949 BGP_STR
8950 "Address family\n"
8951 "Address Family modifier\n"
8952 "Address Family modifier\n"
8953 "Display routes matching the community-list\n"
fee6e4e4 8954 "community-list number\n"
718e3744 8955 "community-list name\n"
8956 "Exact match of the communities\n")
8957{
8958 if (strncmp (argv[0], "m", 1) == 0)
8959 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8960
8961 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8962}
8963
8964#ifdef HAVE_IPV6
8965DEFUN (show_bgp_community_list,
8966 show_bgp_community_list_cmd,
fee6e4e4 8967 "show bgp community-list (<1-500>|WORD)",
718e3744 8968 SHOW_STR
8969 BGP_STR
8970 "Display routes matching the community-list\n"
fee6e4e4 8971 "community-list number\n"
718e3744 8972 "community-list name\n")
8973{
8974 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8975}
8976
8977ALIAS (show_bgp_community_list,
8978 show_bgp_ipv6_community_list_cmd,
fee6e4e4 8979 "show bgp ipv6 community-list (<1-500>|WORD)",
718e3744 8980 SHOW_STR
8981 BGP_STR
8982 "Address family\n"
8983 "Display routes matching the community-list\n"
fee6e4e4 8984 "community-list number\n"
e8e1946e 8985 "community-list name\n")
718e3744 8986
8987/* old command */
8988DEFUN (show_ipv6_bgp_community_list,
8989 show_ipv6_bgp_community_list_cmd,
8990 "show ipv6 bgp community-list WORD",
8991 SHOW_STR
8992 IPV6_STR
8993 BGP_STR
8994 "Display routes matching the community-list\n"
8995 "community-list name\n")
8996{
8997 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8998}
8999
9000/* old command */
9001DEFUN (show_ipv6_mbgp_community_list,
9002 show_ipv6_mbgp_community_list_cmd,
9003 "show ipv6 mbgp community-list WORD",
9004 SHOW_STR
9005 IPV6_STR
9006 MBGP_STR
9007 "Display routes matching the community-list\n"
9008 "community-list name\n")
9009{
9010 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9011}
9012
9013DEFUN (show_bgp_community_list_exact,
9014 show_bgp_community_list_exact_cmd,
fee6e4e4 9015 "show bgp community-list (<1-500>|WORD) exact-match",
718e3744 9016 SHOW_STR
9017 BGP_STR
9018 "Display routes matching the community-list\n"
fee6e4e4 9019 "community-list number\n"
718e3744 9020 "community-list name\n"
9021 "Exact match of the communities\n")
9022{
9023 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9024}
9025
9026ALIAS (show_bgp_community_list_exact,
9027 show_bgp_ipv6_community_list_exact_cmd,
fee6e4e4 9028 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
718e3744 9029 SHOW_STR
9030 BGP_STR
9031 "Address family\n"
9032 "Display routes matching the community-list\n"
fee6e4e4 9033 "community-list number\n"
718e3744 9034 "community-list name\n"
9035 "Exact match of the communities\n")
9036
9037/* old command */
9038DEFUN (show_ipv6_bgp_community_list_exact,
9039 show_ipv6_bgp_community_list_exact_cmd,
9040 "show ipv6 bgp community-list WORD exact-match",
9041 SHOW_STR
9042 IPV6_STR
9043 BGP_STR
9044 "Display routes matching the community-list\n"
9045 "community-list name\n"
9046 "Exact match of the communities\n")
9047{
9048 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9049}
9050
9051/* old command */
9052DEFUN (show_ipv6_mbgp_community_list_exact,
9053 show_ipv6_mbgp_community_list_exact_cmd,
9054 "show ipv6 mbgp community-list WORD exact-match",
9055 SHOW_STR
9056 IPV6_STR
9057 MBGP_STR
9058 "Display routes matching the community-list\n"
9059 "community-list name\n"
9060 "Exact match of the communities\n")
9061{
9062 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9063}
9064#endif /* HAVE_IPV6 */
9065\f
94f2b392 9066static int
fd79ac91 9067bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
718e3744 9068 safi_t safi, enum bgp_show_type type)
9069{
9070 int ret;
9071 struct prefix *p;
9072
9073 p = prefix_new();
9074
9075 ret = str2prefix (prefix, p);
9076 if (! ret)
9077 {
9078 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9079 return CMD_WARNING;
9080 }
9081
5a646650 9082 ret = bgp_show (vty, NULL, afi, safi, type, p);
9083 prefix_free(p);
9084 return ret;
718e3744 9085}
9086
9087DEFUN (show_ip_bgp_prefix_longer,
9088 show_ip_bgp_prefix_longer_cmd,
9089 "show ip bgp A.B.C.D/M longer-prefixes",
9090 SHOW_STR
9091 IP_STR
9092 BGP_STR
9093 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9094 "Display route and more specific routes\n")
9095{
9096 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9097 bgp_show_type_prefix_longer);
9098}
9099
9100DEFUN (show_ip_bgp_flap_prefix_longer,
9101 show_ip_bgp_flap_prefix_longer_cmd,
9102 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9103 SHOW_STR
9104 IP_STR
9105 BGP_STR
9106 "Display flap statistics of routes\n"
9107 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9108 "Display route and more specific routes\n")
9109{
9110 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9111 bgp_show_type_flap_prefix_longer);
9112}
9113
9114DEFUN (show_ip_bgp_ipv4_prefix_longer,
9115 show_ip_bgp_ipv4_prefix_longer_cmd,
9116 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9117 SHOW_STR
9118 IP_STR
9119 BGP_STR
9120 "Address family\n"
9121 "Address Family modifier\n"
9122 "Address Family modifier\n"
9123 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9124 "Display route and more specific routes\n")
9125{
9126 if (strncmp (argv[0], "m", 1) == 0)
9127 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9128 bgp_show_type_prefix_longer);
9129
9130 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9131 bgp_show_type_prefix_longer);
9132}
9133
9134DEFUN (show_ip_bgp_flap_address,
9135 show_ip_bgp_flap_address_cmd,
9136 "show ip bgp flap-statistics A.B.C.D",
9137 SHOW_STR
9138 IP_STR
9139 BGP_STR
9140 "Display flap statistics of routes\n"
9141 "Network in the BGP routing table to display\n")
9142{
9143 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9144 bgp_show_type_flap_address);
9145}
9146
9147DEFUN (show_ip_bgp_flap_prefix,
9148 show_ip_bgp_flap_prefix_cmd,
9149 "show ip bgp flap-statistics A.B.C.D/M",
9150 SHOW_STR
9151 IP_STR
9152 BGP_STR
9153 "Display flap statistics of routes\n"
9154 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9155{
9156 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9157 bgp_show_type_flap_prefix);
9158}
9159#ifdef HAVE_IPV6
9160DEFUN (show_bgp_prefix_longer,
9161 show_bgp_prefix_longer_cmd,
9162 "show bgp X:X::X:X/M longer-prefixes",
9163 SHOW_STR
9164 BGP_STR
9165 "IPv6 prefix <network>/<length>\n"
9166 "Display route and more specific routes\n")
9167{
9168 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9169 bgp_show_type_prefix_longer);
9170}
9171
9172ALIAS (show_bgp_prefix_longer,
9173 show_bgp_ipv6_prefix_longer_cmd,
9174 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9175 SHOW_STR
9176 BGP_STR
9177 "Address family\n"
9178 "IPv6 prefix <network>/<length>\n"
9179 "Display route and more specific routes\n")
9180
9181/* old command */
9182DEFUN (show_ipv6_bgp_prefix_longer,
9183 show_ipv6_bgp_prefix_longer_cmd,
9184 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9185 SHOW_STR
9186 IPV6_STR
9187 BGP_STR
9188 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9189 "Display route and more specific routes\n")
9190{
9191 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9192 bgp_show_type_prefix_longer);
9193}
9194
9195/* old command */
9196DEFUN (show_ipv6_mbgp_prefix_longer,
9197 show_ipv6_mbgp_prefix_longer_cmd,
9198 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9199 SHOW_STR
9200 IPV6_STR
9201 MBGP_STR
9202 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9203 "Display route and more specific routes\n")
9204{
9205 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9206 bgp_show_type_prefix_longer);
9207}
9208#endif /* HAVE_IPV6 */
bb46e94f 9209
94f2b392 9210static struct peer *
fd79ac91 9211peer_lookup_in_view (struct vty *vty, const char *view_name,
9212 const char *ip_str)
bb46e94f 9213{
9214 int ret;
9215 struct bgp *bgp;
9216 struct peer *peer;
9217 union sockunion su;
9218
9219 /* BGP structure lookup. */
9220 if (view_name)
9221 {
9222 bgp = bgp_lookup_by_name (view_name);
9223 if (! bgp)
9224 {
9225 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9226 return NULL;
9227 }
9228 }
5228ad27 9229 else
bb46e94f 9230 {
9231 bgp = bgp_get_default ();
9232 if (! bgp)
9233 {
9234 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9235 return NULL;
9236 }
9237 }
9238
9239 /* Get peer sockunion. */
9240 ret = str2sockunion (ip_str, &su);
9241 if (ret < 0)
9242 {
9243 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9244 return NULL;
9245 }
9246
9247 /* Peer structure lookup. */
9248 peer = peer_lookup (bgp, &su);
9249 if (! peer)
9250 {
9251 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9252 return NULL;
9253 }
9254
9255 return peer;
9256}
2815e61f
PJ
9257\f
9258enum bgp_stats
9259{
9260 BGP_STATS_MAXBITLEN = 0,
9261 BGP_STATS_RIB,
9262 BGP_STATS_PREFIXES,
9263 BGP_STATS_TOTPLEN,
9264 BGP_STATS_UNAGGREGATEABLE,
9265 BGP_STATS_MAX_AGGREGATEABLE,
9266 BGP_STATS_AGGREGATES,
9267 BGP_STATS_SPACE,
9268 BGP_STATS_ASPATH_COUNT,
9269 BGP_STATS_ASPATH_MAXHOPS,
9270 BGP_STATS_ASPATH_TOTHOPS,
9271 BGP_STATS_ASPATH_MAXSIZE,
9272 BGP_STATS_ASPATH_TOTSIZE,
9273 BGP_STATS_ASN_HIGHEST,
9274 BGP_STATS_MAX,
9275};
9276
9277static const char *table_stats_strs[] =
9278{
9279 [BGP_STATS_PREFIXES] = "Total Prefixes",
9280 [BGP_STATS_TOTPLEN] = "Average prefix length",
9281 [BGP_STATS_RIB] = "Total Advertisements",
9282 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9283 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9284 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9285 [BGP_STATS_SPACE] = "Address space advertised",
9286 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9287 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9288 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9289 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9290 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9291 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9292 [BGP_STATS_MAX] = NULL,
9293};
9294
9295struct bgp_table_stats
9296{
9297 struct bgp_table *table;
9298 unsigned long long counts[BGP_STATS_MAX];
9299};
9300
9301#if 0
9302#define TALLY_SIGFIG 100000
9303static unsigned long
9304ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9305{
9306 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9307 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9308 unsigned long ret = newtot / count;
9309
9310 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9311 return ret + 1;
9312 else
9313 return ret;
9314}
9315#endif
9316
9317static int
9318bgp_table_stats_walker (struct thread *t)
9319{
9320 struct bgp_node *rn;
9321 struct bgp_node *top;
9322 struct bgp_table_stats *ts = THREAD_ARG (t);
9323 unsigned int space = 0;
9324
53d9f67a
PJ
9325 if (!(top = bgp_table_top (ts->table)))
9326 return 0;
2815e61f
PJ
9327
9328 switch (top->p.family)
9329 {
9330 case AF_INET:
9331 space = IPV4_MAX_BITLEN;
9332 break;
9333 case AF_INET6:
9334 space = IPV6_MAX_BITLEN;
9335 break;
9336 }
9337
9338 ts->counts[BGP_STATS_MAXBITLEN] = space;
9339
9340 for (rn = top; rn; rn = bgp_route_next (rn))
9341 {
9342 struct bgp_info *ri;
67174041 9343 struct bgp_node *prn = bgp_node_parent_nolock (rn);
2815e61f
PJ
9344 unsigned int rinum = 0;
9345
9346 if (rn == top)
9347 continue;
9348
9349 if (!rn->info)
9350 continue;
9351
9352 ts->counts[BGP_STATS_PREFIXES]++;
9353 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9354
9355#if 0
9356 ts->counts[BGP_STATS_AVGPLEN]
9357 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9358 ts->counts[BGP_STATS_AVGPLEN],
9359 rn->p.prefixlen);
9360#endif
9361
9362 /* check if the prefix is included by any other announcements */
9363 while (prn && !prn->info)
67174041 9364 prn = bgp_node_parent_nolock (prn);
2815e61f
PJ
9365
9366 if (prn == NULL || prn == top)
8383a9bd
PJ
9367 {
9368 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9369 /* announced address space */
9370 if (space)
9371 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9372 }
2815e61f
PJ
9373 else if (prn->info)
9374 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9375
2815e61f
PJ
9376 for (ri = rn->info; ri; ri = ri->next)
9377 {
9378 rinum++;
9379 ts->counts[BGP_STATS_RIB]++;
9380
9381 if (ri->attr &&
9382 (CHECK_FLAG (ri->attr->flag,
9383 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9384 ts->counts[BGP_STATS_AGGREGATES]++;
9385
9386 /* as-path stats */
9387 if (ri->attr && ri->attr->aspath)
9388 {
9389 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9390 unsigned int size = aspath_size (ri->attr->aspath);
9391 as_t highest = aspath_highest (ri->attr->aspath);
9392
9393 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9394
9395 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9396 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9397
9398 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9399 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9400
9401 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9402 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9403#if 0
9404 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9405 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9406 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9407 hops);
9408 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9409 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9410 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9411 size);
9412#endif
9413 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9414 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9415 }
9416 }
9417 }
9418 return 0;
9419}
9420
9421static int
9422bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9423{
9424 struct bgp_table_stats ts;
9425 unsigned int i;
9426
9427 if (!bgp->rib[afi][safi])
9428 {
9429 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9430 return CMD_WARNING;
9431 }
9432
9433 memset (&ts, 0, sizeof (ts));
9434 ts.table = bgp->rib[afi][safi];
9435 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
bb46e94f 9436
2815e61f
PJ
9437 vty_out (vty, "BGP %s RIB statistics%s%s",
9438 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9439
9440 for (i = 0; i < BGP_STATS_MAX; i++)
9441 {
9442 if (!table_stats_strs[i])
9443 continue;
9444
9445 switch (i)
9446 {
9447#if 0
9448 case BGP_STATS_ASPATH_AVGHOPS:
9449 case BGP_STATS_ASPATH_AVGSIZE:
9450 case BGP_STATS_AVGPLEN:
9451 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9452 vty_out (vty, "%12.2f",
9453 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9454 break;
9455#endif
9456 case BGP_STATS_ASPATH_TOTHOPS:
9457 case BGP_STATS_ASPATH_TOTSIZE:
9458 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9459 vty_out (vty, "%12.2f",
9460 ts.counts[i] ?
9461 (float)ts.counts[i] /
9462 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9463 : 0);
9464 break;
9465 case BGP_STATS_TOTPLEN:
9466 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9467 vty_out (vty, "%12.2f",
9468 ts.counts[i] ?
9469 (float)ts.counts[i] /
9470 (float)ts.counts[BGP_STATS_PREFIXES]
9471 : 0);
9472 break;
9473 case BGP_STATS_SPACE:
9474 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9475 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9476 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9477 break;
30a2231a 9478 vty_out (vty, "%30s: ", "%% announced ");
2815e61f
PJ
9479 vty_out (vty, "%12.2f%s",
9480 100 * (float)ts.counts[BGP_STATS_SPACE] /
56395af7 9481 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
2815e61f
PJ
9482 VTY_NEWLINE);
9483 vty_out (vty, "%30s: ", "/8 equivalent ");
9484 vty_out (vty, "%12.2f%s",
9485 (float)ts.counts[BGP_STATS_SPACE] /
9486 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9487 VTY_NEWLINE);
9488 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9489 break;
9490 vty_out (vty, "%30s: ", "/24 equivalent ");
9491 vty_out (vty, "%12.2f",
9492 (float)ts.counts[BGP_STATS_SPACE] /
9493 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9494 break;
9495 default:
9496 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9497 vty_out (vty, "%12llu", ts.counts[i]);
9498 }
9499
9500 vty_out (vty, "%s", VTY_NEWLINE);
9501 }
9502 return CMD_SUCCESS;
9503}
9504
9505static int
9506bgp_table_stats_vty (struct vty *vty, const char *name,
9507 const char *afi_str, const char *safi_str)
9508{
9509 struct bgp *bgp;
9510 afi_t afi;
9511 safi_t safi;
9512
9513 if (name)
9514 bgp = bgp_lookup_by_name (name);
9515 else
9516 bgp = bgp_get_default ();
9517
9518 if (!bgp)
9519 {
9520 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9521 return CMD_WARNING;
9522 }
9523 if (strncmp (afi_str, "ipv", 3) == 0)
9524 {
9525 if (strncmp (afi_str, "ipv4", 4) == 0)
9526 afi = AFI_IP;
9527 else if (strncmp (afi_str, "ipv6", 4) == 0)
9528 afi = AFI_IP6;
9529 else
9530 {
9531 vty_out (vty, "%% Invalid address family %s%s",
9532 afi_str, VTY_NEWLINE);
9533 return CMD_WARNING;
9534 }
9535 if (strncmp (safi_str, "m", 1) == 0)
9536 safi = SAFI_MULTICAST;
9537 else if (strncmp (safi_str, "u", 1) == 0)
9538 safi = SAFI_UNICAST;
42e6d745
DO
9539 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9540 safi = SAFI_MPLS_LABELED_VPN;
2815e61f
PJ
9541 else
9542 {
9543 vty_out (vty, "%% Invalid subsequent address family %s%s",
9544 safi_str, VTY_NEWLINE);
9545 return CMD_WARNING;
9546 }
9547 }
9548 else
9549 {
9550 vty_out (vty, "%% Invalid address family %s%s",
9551 afi_str, VTY_NEWLINE);
9552 return CMD_WARNING;
9553 }
9554
2815e61f
PJ
9555 return bgp_table_stats (vty, bgp, afi, safi);
9556}
9557
9558DEFUN (show_bgp_statistics,
9559 show_bgp_statistics_cmd,
9560 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9561 SHOW_STR
9562 BGP_STR
9563 "Address family\n"
9564 "Address family\n"
9565 "Address Family modifier\n"
9566 "Address Family modifier\n"
9567 "BGP RIB advertisement statistics\n")
9568{
9569 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9570}
9571
9572ALIAS (show_bgp_statistics,
9573 show_bgp_statistics_vpnv4_cmd,
9574 "show bgp (ipv4) (vpnv4) statistics",
9575 SHOW_STR
9576 BGP_STR
9577 "Address family\n"
9578 "Address Family modifier\n"
9579 "BGP RIB advertisement statistics\n")
9580
9581DEFUN (show_bgp_statistics_view,
9582 show_bgp_statistics_view_cmd,
9583 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9584 SHOW_STR
9585 BGP_STR
9586 "BGP view\n"
9587 "Address family\n"
9588 "Address family\n"
9589 "Address Family modifier\n"
9590 "Address Family modifier\n"
9591 "BGP RIB advertisement statistics\n")
9592{
9593 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9594}
9595
9596ALIAS (show_bgp_statistics_view,
9597 show_bgp_statistics_view_vpnv4_cmd,
9598 "show bgp view WORD (ipv4) (vpnv4) statistics",
9599 SHOW_STR
9600 BGP_STR
9601 "BGP view\n"
9602 "Address family\n"
9603 "Address Family modifier\n"
9604 "BGP RIB advertisement statistics\n")
9605\f
ff7924f6
PJ
9606enum bgp_pcounts
9607{
9608 PCOUNT_ADJ_IN = 0,
9609 PCOUNT_DAMPED,
9610 PCOUNT_REMOVED,
9611 PCOUNT_HISTORY,
9612 PCOUNT_STALE,
9613 PCOUNT_VALID,
9614 PCOUNT_ALL,
9615 PCOUNT_COUNTED,
9616 PCOUNT_PFCNT, /* the figure we display to users */
9617 PCOUNT_MAX,
9618};
9619
9620static const char *pcount_strs[] =
9621{
9622 [PCOUNT_ADJ_IN] = "Adj-in",
9623 [PCOUNT_DAMPED] = "Damped",
9624 [PCOUNT_REMOVED] = "Removed",
9625 [PCOUNT_HISTORY] = "History",
9626 [PCOUNT_STALE] = "Stale",
9627 [PCOUNT_VALID] = "Valid",
9628 [PCOUNT_ALL] = "All RIB",
9629 [PCOUNT_COUNTED] = "PfxCt counted",
9630 [PCOUNT_PFCNT] = "Useable",
9631 [PCOUNT_MAX] = NULL,
9632};
9633
2815e61f
PJ
9634struct peer_pcounts
9635{
9636 unsigned int count[PCOUNT_MAX];
9637 const struct peer *peer;
9638 const struct bgp_table *table;
9639};
9640
ff7924f6 9641static int
2815e61f 9642bgp_peer_count_walker (struct thread *t)
ff7924f6
PJ
9643{
9644 struct bgp_node *rn;
2815e61f
PJ
9645 struct peer_pcounts *pc = THREAD_ARG (t);
9646 const struct peer *peer = pc->peer;
ff7924f6 9647
2815e61f 9648 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
ff7924f6
PJ
9649 {
9650 struct bgp_adj_in *ain;
2815e61f 9651 struct bgp_info *ri;
ff7924f6
PJ
9652
9653 for (ain = rn->adj_in; ain; ain = ain->next)
9654 if (ain->peer == peer)
2815e61f 9655 pc->count[PCOUNT_ADJ_IN]++;
ff7924f6 9656
ff7924f6
PJ
9657 for (ri = rn->info; ri; ri = ri->next)
9658 {
9659 char buf[SU_ADDRSTRLEN];
9660
9661 if (ri->peer != peer)
9662 continue;
9663
2815e61f 9664 pc->count[PCOUNT_ALL]++;
ff7924f6
PJ
9665
9666 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
2815e61f 9667 pc->count[PCOUNT_DAMPED]++;
ff7924f6 9668 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2815e61f 9669 pc->count[PCOUNT_HISTORY]++;
ff7924f6 9670 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
2815e61f 9671 pc->count[PCOUNT_REMOVED]++;
ff7924f6 9672 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2815e61f 9673 pc->count[PCOUNT_STALE]++;
ff7924f6 9674 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
2815e61f 9675 pc->count[PCOUNT_VALID]++;
1a392d46 9676 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2815e61f 9677 pc->count[PCOUNT_PFCNT]++;
ff7924f6
PJ
9678
9679 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9680 {
2815e61f 9681 pc->count[PCOUNT_COUNTED]++;
1a392d46 9682 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
ff7924f6
PJ
9683 plog_warn (peer->log,
9684 "%s [pcount] %s/%d is counted but flags 0x%x",
9685 peer->host,
9686 inet_ntop(rn->p.family, &rn->p.u.prefix,
9687 buf, SU_ADDRSTRLEN),
9688 rn->p.prefixlen,
9689 ri->flags);
9690 }
9691 else
9692 {
1a392d46 9693 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
ff7924f6
PJ
9694 plog_warn (peer->log,
9695 "%s [pcount] %s/%d not counted but flags 0x%x",
9696 peer->host,
9697 inet_ntop(rn->p.family, &rn->p.u.prefix,
9698 buf, SU_ADDRSTRLEN),
9699 rn->p.prefixlen,
9700 ri->flags);
9701 }
9702 }
9703 }
2815e61f
PJ
9704 return 0;
9705}
ff7924f6 9706
2815e61f
PJ
9707static int
9708bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9709{
9710 struct peer_pcounts pcounts = { .peer = peer };
9711 unsigned int i;
9712
9713 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9714 || !peer->bgp->rib[afi][safi])
9715 {
9716 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9717 return CMD_WARNING;
9718 }
9719
9720 memset (&pcounts, 0, sizeof(pcounts));
9721 pcounts.peer = peer;
9722 pcounts.table = peer->bgp->rib[afi][safi];
9723
9724 /* in-place call via thread subsystem so as to record execution time
9725 * stats for the thread-walk (i.e. ensure this can't be blamed on
9726 * on just vty_read()).
9727 */
9728 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9729
ff7924f6
PJ
9730 vty_out (vty, "Prefix counts for %s, %s%s",
9731 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9732 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9733 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9734 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9735
9736 for (i = 0; i < PCOUNT_MAX; i++)
2815e61f
PJ
9737 vty_out (vty, "%20s: %-10d%s",
9738 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
ff7924f6 9739
2815e61f 9740 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
ff7924f6
PJ
9741 {
9742 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9743 peer->host, VTY_NEWLINE);
9744 vty_out (vty, "Please report this bug, with the above command output%s",
9745 VTY_NEWLINE);
9746 }
9747
9748 return CMD_SUCCESS;
9749}
9750
9751DEFUN (show_ip_bgp_neighbor_prefix_counts,
9752 show_ip_bgp_neighbor_prefix_counts_cmd,
9753 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9754 SHOW_STR
9755 IP_STR
9756 BGP_STR
9757 "Detailed information on TCP and BGP neighbor connections\n"
9758 "Neighbor to display information about\n"
9759 "Neighbor to display information about\n"
9760 "Display detailed prefix count information\n")
9761{
9762 struct peer *peer;
9763
9764 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9765 if (! peer)
9766 return CMD_WARNING;
9767
9768 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9769}
9770
9771DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9772 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9773 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9774 SHOW_STR
9775 BGP_STR
9776 "Address family\n"
9777 "Detailed information on TCP and BGP neighbor connections\n"
9778 "Neighbor to display information about\n"
9779 "Neighbor to display information about\n"
9780 "Display detailed prefix count information\n")
9781{
9782 struct peer *peer;
9783
9784 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9785 if (! peer)
9786 return CMD_WARNING;
9787
9788 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9789}
9790
9791DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9792 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9793 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9794 SHOW_STR
9795 IP_STR
9796 BGP_STR
9797 "Address family\n"
9798 "Address Family modifier\n"
9799 "Address Family modifier\n"
9800 "Detailed information on TCP and BGP neighbor connections\n"
9801 "Neighbor to display information about\n"
9802 "Neighbor to display information about\n"
9803 "Display detailed prefix count information\n")
9804{
9805 struct peer *peer;
9806
9807 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9808 if (! peer)
9809 return CMD_WARNING;
9810
9811 if (strncmp (argv[0], "m", 1) == 0)
9812 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9813
9814 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9815}
9816
9817DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9818 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9819 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9820 SHOW_STR
9821 IP_STR
9822 BGP_STR
9823 "Address family\n"
9824 "Address Family modifier\n"
9825 "Address Family modifier\n"
9826 "Detailed information on TCP and BGP neighbor connections\n"
9827 "Neighbor to display information about\n"
9828 "Neighbor to display information about\n"
9829 "Display detailed prefix count information\n")
9830{
9831 struct peer *peer;
9832
9833 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9834 if (! peer)
9835 return CMD_WARNING;
9836
9837 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9838}
9839
9840
94f2b392 9841static void
718e3744 9842show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9843 int in)
9844{
9845 struct bgp_table *table;
9846 struct bgp_adj_in *ain;
9847 struct bgp_adj_out *adj;
9848 unsigned long output_count;
9849 struct bgp_node *rn;
9850 int header1 = 1;
9851 struct bgp *bgp;
9852 int header2 = 1;
9853
bb46e94f 9854 bgp = peer->bgp;
718e3744 9855
9856 if (! bgp)
9857 return;
9858
9859 table = bgp->rib[afi][safi];
9860
9861 output_count = 0;
9862
9863 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9864 PEER_STATUS_DEFAULT_ORIGINATE))
9865 {
9866 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
93406d87 9867 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9868 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 9869
9870 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9871 VTY_NEWLINE, VTY_NEWLINE);
9872 header1 = 0;
9873 }
9874
9875 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9876 if (in)
9877 {
9878 for (ain = rn->adj_in; ain; ain = ain->next)
9879 if (ain->peer == peer)
9880 {
9881 if (header1)
9882 {
9883 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
93406d87 9884 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9885 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 9886 header1 = 0;
9887 }
9888 if (header2)
9889 {
9890 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9891 header2 = 0;
9892 }
9893 if (ain->attr)
9894 {
9895 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9896 output_count++;
9897 }
9898 }
9899 }
9900 else
9901 {
9902 for (adj = rn->adj_out; adj; adj = adj->next)
9903 if (adj->peer == peer)
9904 {
9905 if (header1)
9906 {
9907 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
93406d87 9908 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9909 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
718e3744 9910 header1 = 0;
9911 }
9912 if (header2)
9913 {
9914 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9915 header2 = 0;
9916 }
9917 if (adj->attr)
9918 {
9919 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9920 output_count++;
9921 }
9922 }
9923 }
9924
9925 if (output_count != 0)
9926 vty_out (vty, "%sTotal number of prefixes %ld%s",
9927 VTY_NEWLINE, output_count, VTY_NEWLINE);
9928}
9929
94f2b392 9930static int
bb46e94f 9931peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9932{
718e3744 9933 if (! peer || ! peer->afc[afi][safi])
9934 {
9935 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9936 return CMD_WARNING;
9937 }
9938
9939 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9940 {
9941 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9942 VTY_NEWLINE);
9943 return CMD_WARNING;
9944 }
9945
9946 show_adj_route (vty, peer, afi, safi, in);
9947
9948 return CMD_SUCCESS;
9949}
9950
2a71e9ce
TP
9951DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9952 show_ip_bgp_view_neighbor_advertised_route_cmd,
9953 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
718e3744 9954 SHOW_STR
9955 IP_STR
9956 BGP_STR
2a71e9ce
TP
9957 "BGP view\n"
9958 "View name\n"
718e3744 9959 "Detailed information on TCP and BGP neighbor connections\n"
9960 "Neighbor to display information about\n"
9961 "Neighbor to display information about\n"
9962 "Display the routes advertised to a BGP neighbor\n")
9963{
bb46e94f 9964 struct peer *peer;
9965
2a71e9ce
TP
9966 if (argc == 2)
9967 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9968 else
9969 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9970
bb46e94f 9971 if (! peer)
9972 return CMD_WARNING;
9973
9974 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
718e3744 9975}
9976
2a71e9ce
TP
9977ALIAS (show_ip_bgp_view_neighbor_advertised_route,
9978 show_ip_bgp_neighbor_advertised_route_cmd,
9979 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9980 SHOW_STR
9981 IP_STR
9982 BGP_STR
9983 "Detailed information on TCP and BGP neighbor connections\n"
9984 "Neighbor to display information about\n"
9985 "Neighbor to display information about\n"
9986 "Display the routes advertised to a BGP neighbor\n")
9987
718e3744 9988DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9989 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9990 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9991 SHOW_STR
9992 IP_STR
9993 BGP_STR
9994 "Address family\n"
9995 "Address Family modifier\n"
9996 "Address Family modifier\n"
9997 "Detailed information on TCP and BGP neighbor connections\n"
9998 "Neighbor to display information about\n"
9999 "Neighbor to display information about\n"
10000 "Display the routes advertised to a BGP neighbor\n")
10001{
bb46e94f 10002 struct peer *peer;
10003
10004 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10005 if (! peer)
10006 return CMD_WARNING;
10007
718e3744 10008 if (strncmp (argv[0], "m", 1) == 0)
bb46e94f 10009 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
718e3744 10010
bb46e94f 10011 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
718e3744 10012}
10013
10014#ifdef HAVE_IPV6
bb46e94f 10015DEFUN (show_bgp_view_neighbor_advertised_route,
10016 show_bgp_view_neighbor_advertised_route_cmd,
10017 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
718e3744 10018 SHOW_STR
10019 BGP_STR
bb46e94f 10020 "BGP view\n"
10021 "View name\n"
718e3744 10022 "Detailed information on TCP and BGP neighbor connections\n"
10023 "Neighbor to display information about\n"
10024 "Neighbor to display information about\n"
10025 "Display the routes advertised to a BGP neighbor\n")
10026{
bb46e94f 10027 struct peer *peer;
10028
10029 if (argc == 2)
10030 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10031 else
10032 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10033
10034 if (! peer)
10035 return CMD_WARNING;
10036
10037 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10038}
10039
10040ALIAS (show_bgp_view_neighbor_advertised_route,
10041 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10042 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10043 SHOW_STR
10044 BGP_STR
10045 "BGP view\n"
10046 "View name\n"
10047 "Address family\n"
10048 "Detailed information on TCP and BGP neighbor connections\n"
10049 "Neighbor to display information about\n"
10050 "Neighbor to display information about\n"
10051 "Display the routes advertised to a BGP neighbor\n")
10052
10053DEFUN (show_bgp_view_neighbor_received_routes,
10054 show_bgp_view_neighbor_received_routes_cmd,
10055 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10056 SHOW_STR
10057 BGP_STR
10058 "BGP view\n"
10059 "View name\n"
10060 "Detailed information on TCP and BGP neighbor connections\n"
10061 "Neighbor to display information about\n"
10062 "Neighbor to display information about\n"
10063 "Display the received routes from neighbor\n")
10064{
10065 struct peer *peer;
10066
10067 if (argc == 2)
10068 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10069 else
10070 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10071
10072 if (! peer)
10073 return CMD_WARNING;
10074
10075 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
718e3744 10076}
10077
bb46e94f 10078ALIAS (show_bgp_view_neighbor_received_routes,
10079 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10080 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10081 SHOW_STR
10082 BGP_STR
10083 "BGP view\n"
10084 "View name\n"
10085 "Address family\n"
10086 "Detailed information on TCP and BGP neighbor connections\n"
10087 "Neighbor to display information about\n"
10088 "Neighbor to display information about\n"
10089 "Display the received routes from neighbor\n")
10090
10091ALIAS (show_bgp_view_neighbor_advertised_route,
10092 show_bgp_neighbor_advertised_route_cmd,
10093 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10094 SHOW_STR
10095 BGP_STR
10096 "Detailed information on TCP and BGP neighbor connections\n"
10097 "Neighbor to display information about\n"
10098 "Neighbor to display information about\n"
10099 "Display the routes advertised to a BGP neighbor\n")
10100
10101ALIAS (show_bgp_view_neighbor_advertised_route,
718e3744 10102 show_bgp_ipv6_neighbor_advertised_route_cmd,
10103 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10104 SHOW_STR
10105 BGP_STR
10106 "Address family\n"
10107 "Detailed information on TCP and BGP neighbor connections\n"
10108 "Neighbor to display information about\n"
10109 "Neighbor to display information about\n"
10110 "Display the routes advertised to a BGP neighbor\n")
10111
10112/* old command */
bb46e94f 10113ALIAS (show_bgp_view_neighbor_advertised_route,
718e3744 10114 ipv6_bgp_neighbor_advertised_route_cmd,
10115 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10116 SHOW_STR
10117 IPV6_STR
10118 BGP_STR
10119 "Detailed information on TCP and BGP neighbor connections\n"
10120 "Neighbor to display information about\n"
10121 "Neighbor to display information about\n"
10122 "Display the routes advertised to a BGP neighbor\n")
bb46e94f 10123
718e3744 10124/* old command */
10125DEFUN (ipv6_mbgp_neighbor_advertised_route,
10126 ipv6_mbgp_neighbor_advertised_route_cmd,
10127 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10128 SHOW_STR
10129 IPV6_STR
10130 MBGP_STR
10131 "Detailed information on TCP and BGP neighbor connections\n"
10132 "Neighbor to display information about\n"
10133 "Neighbor to display information about\n"
10134 "Display the routes advertised to a BGP neighbor\n")
10135{
bb46e94f 10136 struct peer *peer;
10137
10138 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10139 if (! peer)
10140 return CMD_WARNING;
10141
10142 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
718e3744 10143}
10144#endif /* HAVE_IPV6 */
10145\f
2a71e9ce
TP
10146DEFUN (show_ip_bgp_view_neighbor_received_routes,
10147 show_ip_bgp_view_neighbor_received_routes_cmd,
10148 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
718e3744 10149 SHOW_STR
10150 IP_STR
10151 BGP_STR
2a71e9ce
TP
10152 "BGP view\n"
10153 "View name\n"
718e3744 10154 "Detailed information on TCP and BGP neighbor connections\n"
10155 "Neighbor to display information about\n"
10156 "Neighbor to display information about\n"
10157 "Display the received routes from neighbor\n")
10158{
bb46e94f 10159 struct peer *peer;
10160
2a71e9ce
TP
10161 if (argc == 2)
10162 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10163 else
10164 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10165
bb46e94f 10166 if (! peer)
10167 return CMD_WARNING;
10168
10169 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
718e3744 10170}
10171
2a71e9ce
TP
10172ALIAS (show_ip_bgp_view_neighbor_received_routes,
10173 show_ip_bgp_neighbor_received_routes_cmd,
10174 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10175 SHOW_STR
10176 IP_STR
10177 BGP_STR
10178 "Detailed information on TCP and BGP neighbor connections\n"
10179 "Neighbor to display information about\n"
10180 "Neighbor to display information about\n"
10181 "Display the received routes from neighbor\n")
10182
718e3744 10183DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10184 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10185 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10186 SHOW_STR
10187 IP_STR
10188 BGP_STR
10189 "Address family\n"
10190 "Address Family modifier\n"
10191 "Address Family modifier\n"
10192 "Detailed information on TCP and BGP neighbor connections\n"
10193 "Neighbor to display information about\n"
10194 "Neighbor to display information about\n"
10195 "Display the received routes from neighbor\n")
10196{
bb46e94f 10197 struct peer *peer;
10198
10199 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10200 if (! peer)
10201 return CMD_WARNING;
10202
718e3744 10203 if (strncmp (argv[0], "m", 1) == 0)
bb46e94f 10204 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
718e3744 10205
bb46e94f 10206 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
718e3744 10207}
10208
95cbbd2a
ML
10209DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10210 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10211#ifdef HAVE_IPV6
10212 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10213#else
10214 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10215#endif
10216 SHOW_STR
10217 BGP_STR
10218 "BGP view\n"
2b00515a 10219 "View name\n"
95cbbd2a
ML
10220 "Address family\n"
10221#ifdef HAVE_IPV6
10222 "Address family\n"
10223#endif
10224 "Address family modifier\n"
10225 "Address family modifier\n"
10226 "Detailed information on TCP and BGP neighbor connections\n"
10227 "Neighbor to display information about\n"
10228 "Neighbor to display information about\n"
10229 "Display the advertised routes to neighbor\n"
10230 "Display the received routes from neighbor\n")
10231{
10232 int afi;
10233 int safi;
10234 int in;
10235 struct peer *peer;
10236
10237#ifdef HAVE_IPV6
10238 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10239#else
10240 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10241#endif
10242
10243 if (! peer)
10244 return CMD_WARNING;
10245
10246#ifdef HAVE_IPV6
10247 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10248 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10249 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10250#else
10251 afi = AFI_IP;
10252 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10253 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10254#endif
10255
10256 return peer_adj_routes (vty, peer, afi, safi, in);
10257}
10258
718e3744 10259DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10260 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10261 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10262 SHOW_STR
10263 IP_STR
10264 BGP_STR
10265 "Detailed information on TCP and BGP neighbor connections\n"
10266 "Neighbor to display information about\n"
10267 "Neighbor to display information about\n"
10268 "Display information received from a BGP neighbor\n"
10269 "Display the prefixlist filter\n")
10270{
10271 char name[BUFSIZ];
c63b83fe 10272 union sockunion su;
718e3744 10273 struct peer *peer;
c63b83fe 10274 int count, ret;
718e3744 10275
c63b83fe
JBD
10276 ret = str2sockunion (argv[0], &su);
10277 if (ret < 0)
10278 {
10279 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10280 return CMD_WARNING;
10281 }
718e3744 10282
c63b83fe 10283 peer = peer_lookup (NULL, &su);
718e3744 10284 if (! peer)
10285 return CMD_WARNING;
10286
10287 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10288 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10289 if (count)
10290 {
10291 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10292 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10293 }
10294
10295 return CMD_SUCCESS;
10296}
10297
10298DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10299 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10300 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10301 SHOW_STR
10302 IP_STR
10303 BGP_STR
10304 "Address family\n"
10305 "Address Family modifier\n"
10306 "Address Family modifier\n"
10307 "Detailed information on TCP and BGP neighbor connections\n"
10308 "Neighbor to display information about\n"
10309 "Neighbor to display information about\n"
10310 "Display information received from a BGP neighbor\n"
10311 "Display the prefixlist filter\n")
10312{
10313 char name[BUFSIZ];
c63b83fe 10314 union sockunion su;
718e3744 10315 struct peer *peer;
c63b83fe 10316 int count, ret;
718e3744 10317
c63b83fe
JBD
10318 ret = str2sockunion (argv[1], &su);
10319 if (ret < 0)
10320 {
10321 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10322 return CMD_WARNING;
10323 }
718e3744 10324
c63b83fe 10325 peer = peer_lookup (NULL, &su);
718e3744 10326 if (! peer)
10327 return CMD_WARNING;
10328
10329 if (strncmp (argv[0], "m", 1) == 0)
10330 {
10331 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10332 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10333 if (count)
10334 {
10335 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10336 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10337 }
10338 }
10339 else
10340 {
10341 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10342 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10343 if (count)
10344 {
10345 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10346 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10347 }
10348 }
10349
10350 return CMD_SUCCESS;
10351}
10352
10353
10354#ifdef HAVE_IPV6
bb46e94f 10355ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 10356 show_bgp_neighbor_received_routes_cmd,
10357 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10358 SHOW_STR
10359 BGP_STR
10360 "Detailed information on TCP and BGP neighbor connections\n"
10361 "Neighbor to display information about\n"
10362 "Neighbor to display information about\n"
10363 "Display the received routes from neighbor\n")
718e3744 10364
bb46e94f 10365ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 10366 show_bgp_ipv6_neighbor_received_routes_cmd,
10367 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10368 SHOW_STR
10369 BGP_STR
10370 "Address family\n"
10371 "Detailed information on TCP and BGP neighbor connections\n"
10372 "Neighbor to display information about\n"
10373 "Neighbor to display information about\n"
10374 "Display the received routes from neighbor\n")
10375
10376DEFUN (show_bgp_neighbor_received_prefix_filter,
10377 show_bgp_neighbor_received_prefix_filter_cmd,
10378 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10379 SHOW_STR
10380 BGP_STR
10381 "Detailed information on TCP and BGP neighbor connections\n"
10382 "Neighbor to display information about\n"
10383 "Neighbor to display information about\n"
10384 "Display information received from a BGP neighbor\n"
10385 "Display the prefixlist filter\n")
10386{
10387 char name[BUFSIZ];
c63b83fe 10388 union sockunion su;
718e3744 10389 struct peer *peer;
c63b83fe 10390 int count, ret;
718e3744 10391
c63b83fe
JBD
10392 ret = str2sockunion (argv[0], &su);
10393 if (ret < 0)
10394 {
10395 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10396 return CMD_WARNING;
10397 }
718e3744 10398
c63b83fe 10399 peer = peer_lookup (NULL, &su);
718e3744 10400 if (! peer)
10401 return CMD_WARNING;
10402
10403 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10404 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10405 if (count)
10406 {
10407 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10408 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10409 }
10410
10411 return CMD_SUCCESS;
10412}
10413
10414ALIAS (show_bgp_neighbor_received_prefix_filter,
10415 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10416 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10417 SHOW_STR
10418 BGP_STR
10419 "Address family\n"
10420 "Detailed information on TCP and BGP neighbor connections\n"
10421 "Neighbor to display information about\n"
10422 "Neighbor to display information about\n"
10423 "Display information received from a BGP neighbor\n"
10424 "Display the prefixlist filter\n")
10425
10426/* old command */
bb46e94f 10427ALIAS (show_bgp_view_neighbor_received_routes,
718e3744 10428 ipv6_bgp_neighbor_received_routes_cmd,
10429 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10430 SHOW_STR
10431 IPV6_STR
10432 BGP_STR
10433 "Detailed information on TCP and BGP neighbor connections\n"
10434 "Neighbor to display information about\n"
10435 "Neighbor to display information about\n"
10436 "Display the received routes from neighbor\n")
718e3744 10437
10438/* old command */
10439DEFUN (ipv6_mbgp_neighbor_received_routes,
10440 ipv6_mbgp_neighbor_received_routes_cmd,
10441 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10442 SHOW_STR
10443 IPV6_STR
10444 MBGP_STR
10445 "Detailed information on TCP and BGP neighbor connections\n"
10446 "Neighbor to display information about\n"
10447 "Neighbor to display information about\n"
10448 "Display the received routes from neighbor\n")
10449{
bb46e94f 10450 struct peer *peer;
10451
10452 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10453 if (! peer)
10454 return CMD_WARNING;
10455
10456 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
10457}
10458
10459DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10460 show_bgp_view_neighbor_received_prefix_filter_cmd,
10461 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10462 SHOW_STR
10463 BGP_STR
10464 "BGP view\n"
10465 "View name\n"
10466 "Detailed information on TCP and BGP neighbor connections\n"
10467 "Neighbor to display information about\n"
10468 "Neighbor to display information about\n"
10469 "Display information received from a BGP neighbor\n"
10470 "Display the prefixlist filter\n")
10471{
10472 char name[BUFSIZ];
c63b83fe 10473 union sockunion su;
bb46e94f 10474 struct peer *peer;
10475 struct bgp *bgp;
c63b83fe 10476 int count, ret;
bb46e94f 10477
10478 /* BGP structure lookup. */
10479 bgp = bgp_lookup_by_name (argv[0]);
10480 if (bgp == NULL)
10481 {
10482 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10483 return CMD_WARNING;
10484 }
10485
c63b83fe
JBD
10486 ret = str2sockunion (argv[1], &su);
10487 if (ret < 0)
10488 {
10489 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10490 return CMD_WARNING;
10491 }
bb46e94f 10492
c63b83fe 10493 peer = peer_lookup (bgp, &su);
bb46e94f 10494 if (! peer)
10495 return CMD_WARNING;
10496
10497 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10498 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10499 if (count)
10500 {
10501 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10502 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10503 }
10504
10505 return CMD_SUCCESS;
718e3744 10506}
bb46e94f 10507
10508ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10509 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10510 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10511 SHOW_STR
10512 BGP_STR
10513 "BGP view\n"
10514 "View name\n"
10515 "Address family\n"
10516 "Detailed information on TCP and BGP neighbor connections\n"
10517 "Neighbor to display information about\n"
10518 "Neighbor to display information about\n"
10519 "Display information received from a BGP neighbor\n"
10520 "Display the prefixlist filter\n")
718e3744 10521#endif /* HAVE_IPV6 */
10522\f
94f2b392 10523static int
bb46e94f 10524bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
718e3744 10525 safi_t safi, enum bgp_show_type type)
10526{
718e3744 10527 if (! peer || ! peer->afc[afi][safi])
10528 {
10529 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
718e3744 10530 return CMD_WARNING;
10531 }
10532
5a646650 10533 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
718e3744 10534}
10535
10536DEFUN (show_ip_bgp_neighbor_routes,
10537 show_ip_bgp_neighbor_routes_cmd,
10538 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10539 SHOW_STR
10540 IP_STR
10541 BGP_STR
10542 "Detailed information on TCP and BGP neighbor connections\n"
10543 "Neighbor to display information about\n"
10544 "Neighbor to display information about\n"
10545 "Display routes learned from neighbor\n")
10546{
bb46e94f 10547 struct peer *peer;
10548
10549 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10550 if (! peer)
10551 return CMD_WARNING;
10552
10553 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
718e3744 10554 bgp_show_type_neighbor);
10555}
10556
10557DEFUN (show_ip_bgp_neighbor_flap,
10558 show_ip_bgp_neighbor_flap_cmd,
10559 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10560 SHOW_STR
10561 IP_STR
10562 BGP_STR
10563 "Detailed information on TCP and BGP neighbor connections\n"
10564 "Neighbor to display information about\n"
10565 "Neighbor to display information about\n"
10566 "Display flap statistics of the routes learned from neighbor\n")
10567{
bb46e94f 10568 struct peer *peer;
10569
10570 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10571 if (! peer)
10572 return CMD_WARNING;
10573
10574 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
718e3744 10575 bgp_show_type_flap_neighbor);
10576}
10577
10578DEFUN (show_ip_bgp_neighbor_damp,
10579 show_ip_bgp_neighbor_damp_cmd,
10580 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10581 SHOW_STR
10582 IP_STR
10583 BGP_STR
10584 "Detailed information on TCP and BGP neighbor connections\n"
10585 "Neighbor to display information about\n"
10586 "Neighbor to display information about\n"
10587 "Display the dampened routes received from neighbor\n")
10588{
bb46e94f 10589 struct peer *peer;
10590
10591 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10592 if (! peer)
10593 return CMD_WARNING;
10594
10595 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
718e3744 10596 bgp_show_type_damp_neighbor);
10597}
10598
10599DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10600 show_ip_bgp_ipv4_neighbor_routes_cmd,
10601 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10602 SHOW_STR
10603 IP_STR
10604 BGP_STR
10605 "Address family\n"
10606 "Address Family modifier\n"
10607 "Address Family modifier\n"
10608 "Detailed information on TCP and BGP neighbor connections\n"
10609 "Neighbor to display information about\n"
10610 "Neighbor to display information about\n"
10611 "Display routes learned from neighbor\n")
10612{
bb46e94f 10613 struct peer *peer;
10614
10615 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10616 if (! peer)
10617 return CMD_WARNING;
10618
718e3744 10619 if (strncmp (argv[0], "m", 1) == 0)
bb46e94f 10620 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
718e3744 10621 bgp_show_type_neighbor);
10622
bb46e94f 10623 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
718e3744 10624 bgp_show_type_neighbor);
10625}
bb46e94f 10626
fee0f4c6 10627DEFUN (show_ip_bgp_view_rsclient,
10628 show_ip_bgp_view_rsclient_cmd,
10629 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10630 SHOW_STR
10631 IP_STR
10632 BGP_STR
10633 "BGP view\n"
2b00515a 10634 "View name\n"
fee0f4c6 10635 "Information about Route Server Client\n"
10636 NEIGHBOR_ADDR_STR)
10637{
10638 struct bgp_table *table;
10639 struct peer *peer;
10640
10641 if (argc == 2)
10642 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10643 else
10644 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10645
10646 if (! peer)
10647 return CMD_WARNING;
10648
10649 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10650 {
10651 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10652 VTY_NEWLINE);
10653 return CMD_WARNING;
10654 }
10655
10656 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10657 PEER_FLAG_RSERVER_CLIENT))
10658 {
10659 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10660 VTY_NEWLINE);
10661 return CMD_WARNING;
10662 }
10663
10664 table = peer->rib[AFI_IP][SAFI_UNICAST];
10665
5a646650 10666 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
fee0f4c6 10667}
10668
10669ALIAS (show_ip_bgp_view_rsclient,
10670 show_ip_bgp_rsclient_cmd,
10671 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10672 SHOW_STR
10673 IP_STR
10674 BGP_STR
10675 "Information about Route Server Client\n"
10676 NEIGHBOR_ADDR_STR)
10677
95cbbd2a
ML
10678DEFUN (show_bgp_view_ipv4_safi_rsclient,
10679 show_bgp_view_ipv4_safi_rsclient_cmd,
10680 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
fee0f4c6 10681 SHOW_STR
fee0f4c6 10682 BGP_STR
10683 "BGP view\n"
2b00515a 10684 "View name\n"
95cbbd2a
ML
10685 "Address family\n"
10686 "Address Family modifier\n"
10687 "Address Family modifier\n"
fee0f4c6 10688 "Information about Route Server Client\n"
95cbbd2a 10689 NEIGHBOR_ADDR_STR)
fee0f4c6 10690{
95cbbd2a 10691 struct bgp_table *table;
fee0f4c6 10692 struct peer *peer;
95cbbd2a 10693 safi_t safi;
fee0f4c6 10694
95cbbd2a
ML
10695 if (argc == 3) {
10696 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10697 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10698 } else {
10699 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10700 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10701 }
10702
10703 if (! peer)
10704 return CMD_WARNING;
10705
10706 if (! peer->afc[AFI_IP][safi])
fee0f4c6 10707 {
95cbbd2a
ML
10708 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10709 VTY_NEWLINE);
10710 return CMD_WARNING;
10711 }
10712
10713 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10714 PEER_FLAG_RSERVER_CLIENT))
10715 {
10716 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10717 VTY_NEWLINE);
10718 return CMD_WARNING;
10719 }
10720
10721 table = peer->rib[AFI_IP][safi];
10722
10723 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10724}
10725
10726ALIAS (show_bgp_view_ipv4_safi_rsclient,
10727 show_bgp_ipv4_safi_rsclient_cmd,
10728 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10729 SHOW_STR
10730 BGP_STR
10731 "Address family\n"
10732 "Address Family modifier\n"
10733 "Address Family modifier\n"
10734 "Information about Route Server Client\n"
10735 NEIGHBOR_ADDR_STR)
10736
10737DEFUN (show_ip_bgp_view_rsclient_route,
10738 show_ip_bgp_view_rsclient_route_cmd,
10739 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10740 SHOW_STR
10741 IP_STR
10742 BGP_STR
10743 "BGP view\n"
2b00515a 10744 "View name\n"
95cbbd2a
ML
10745 "Information about Route Server Client\n"
10746 NEIGHBOR_ADDR_STR
10747 "Network in the BGP routing table to display\n")
10748{
10749 struct bgp *bgp;
10750 struct peer *peer;
10751
10752 /* BGP structure lookup. */
10753 if (argc == 3)
10754 {
10755 bgp = bgp_lookup_by_name (argv[0]);
10756 if (bgp == NULL)
10757 {
10758 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10759 return CMD_WARNING;
fee0f4c6 10760 }
10761 }
10762 else
10763 {
10764 bgp = bgp_get_default ();
10765 if (bgp == NULL)
10766 {
10767 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10768 return CMD_WARNING;
10769 }
10770 }
10771
10772 if (argc == 3)
10773 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10774 else
10775 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10776
10777 if (! peer)
10778 return CMD_WARNING;
10779
10780 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10781 {
10782 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10783 VTY_NEWLINE);
10784 return CMD_WARNING;
10785}
10786
10787 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10788 PEER_FLAG_RSERVER_CLIENT))
10789 {
10790 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10791 VTY_NEWLINE);
10792 return CMD_WARNING;
10793 }
10794
10795 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10796 (argc == 3) ? argv[2] : argv[1],
10797 AFI_IP, SAFI_UNICAST, NULL, 0);
10798}
10799
10800ALIAS (show_ip_bgp_view_rsclient_route,
10801 show_ip_bgp_rsclient_route_cmd,
10802 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10803 SHOW_STR
10804 IP_STR
10805 BGP_STR
10806 "Information about Route Server Client\n"
10807 NEIGHBOR_ADDR_STR
10808 "Network in the BGP routing table to display\n")
10809
95cbbd2a
ML
10810DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10811 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10812 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10813 SHOW_STR
10814 BGP_STR
10815 "BGP view\n"
2b00515a 10816 "View name\n"
95cbbd2a
ML
10817 "Address family\n"
10818 "Address Family modifier\n"
10819 "Address Family modifier\n"
10820 "Information about Route Server Client\n"
10821 NEIGHBOR_ADDR_STR
10822 "Network in the BGP routing table to display\n")
10823{
10824 struct bgp *bgp;
10825 struct peer *peer;
10826 safi_t safi;
10827
10828 /* BGP structure lookup. */
10829 if (argc == 4)
10830 {
10831 bgp = bgp_lookup_by_name (argv[0]);
10832 if (bgp == NULL)
10833 {
10834 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10835 return CMD_WARNING;
10836 }
10837 }
10838 else
10839 {
10840 bgp = bgp_get_default ();
10841 if (bgp == NULL)
10842 {
10843 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10844 return CMD_WARNING;
10845 }
10846 }
10847
10848 if (argc == 4) {
10849 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10850 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10851 } else {
10852 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10853 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10854 }
10855
10856 if (! peer)
10857 return CMD_WARNING;
10858
10859 if (! peer->afc[AFI_IP][safi])
10860 {
10861 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10862 VTY_NEWLINE);
10863 return CMD_WARNING;
10864}
10865
10866 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10867 PEER_FLAG_RSERVER_CLIENT))
10868 {
10869 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10870 VTY_NEWLINE);
10871 return CMD_WARNING;
10872 }
10873
10874 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10875 (argc == 4) ? argv[3] : argv[2],
10876 AFI_IP, safi, NULL, 0);
10877}
10878
10879ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10880 show_bgp_ipv4_safi_rsclient_route_cmd,
10881 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10882 SHOW_STR
10883 BGP_STR
10884 "Address family\n"
10885 "Address Family modifier\n"
10886 "Address Family modifier\n"
10887 "Information about Route Server Client\n"
10888 NEIGHBOR_ADDR_STR
10889 "Network in the BGP routing table to display\n")
10890
fee0f4c6 10891DEFUN (show_ip_bgp_view_rsclient_prefix,
10892 show_ip_bgp_view_rsclient_prefix_cmd,
10893 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10894 SHOW_STR
10895 IP_STR
10896 BGP_STR
10897 "BGP view\n"
2b00515a 10898 "View name\n"
fee0f4c6 10899 "Information about Route Server Client\n"
10900 NEIGHBOR_ADDR_STR
10901 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10902{
10903 struct bgp *bgp;
10904 struct peer *peer;
10905
10906 /* BGP structure lookup. */
10907 if (argc == 3)
10908 {
10909 bgp = bgp_lookup_by_name (argv[0]);
10910 if (bgp == NULL)
10911 {
10912 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10913 return CMD_WARNING;
10914 }
10915 }
10916 else
10917 {
10918 bgp = bgp_get_default ();
10919 if (bgp == NULL)
10920 {
10921 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10922 return CMD_WARNING;
10923 }
10924 }
10925
10926 if (argc == 3)
10927 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10928 else
10929 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10930
10931 if (! peer)
10932 return CMD_WARNING;
10933
10934 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10935 {
10936 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10937 VTY_NEWLINE);
10938 return CMD_WARNING;
10939}
10940
10941 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10942 PEER_FLAG_RSERVER_CLIENT))
10943{
10944 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10945 VTY_NEWLINE);
10946 return CMD_WARNING;
10947 }
10948
10949 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10950 (argc == 3) ? argv[2] : argv[1],
10951 AFI_IP, SAFI_UNICAST, NULL, 1);
10952}
10953
10954ALIAS (show_ip_bgp_view_rsclient_prefix,
10955 show_ip_bgp_rsclient_prefix_cmd,
10956 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10957 SHOW_STR
10958 IP_STR
10959 BGP_STR
10960 "Information about Route Server Client\n"
10961 NEIGHBOR_ADDR_STR
10962 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10963
95cbbd2a
ML
10964DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10965 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10966 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10967 SHOW_STR
10968 BGP_STR
10969 "BGP view\n"
2b00515a 10970 "View name\n"
95cbbd2a
ML
10971 "Address family\n"
10972 "Address Family modifier\n"
10973 "Address Family modifier\n"
10974 "Information about Route Server Client\n"
10975 NEIGHBOR_ADDR_STR
10976 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10977{
10978 struct bgp *bgp;
10979 struct peer *peer;
10980 safi_t safi;
10981
10982 /* BGP structure lookup. */
10983 if (argc == 4)
10984 {
10985 bgp = bgp_lookup_by_name (argv[0]);
10986 if (bgp == NULL)
10987 {
10988 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10989 return CMD_WARNING;
10990 }
10991 }
10992 else
10993 {
10994 bgp = bgp_get_default ();
10995 if (bgp == NULL)
10996 {
10997 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10998 return CMD_WARNING;
10999 }
11000 }
11001
11002 if (argc == 4) {
11003 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11004 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11005 } else {
11006 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11007 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11008 }
11009
11010 if (! peer)
11011 return CMD_WARNING;
11012
11013 if (! peer->afc[AFI_IP][safi])
11014 {
11015 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11016 VTY_NEWLINE);
11017 return CMD_WARNING;
11018}
11019
11020 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11021 PEER_FLAG_RSERVER_CLIENT))
11022{
11023 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11024 VTY_NEWLINE);
11025 return CMD_WARNING;
11026 }
11027
11028 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11029 (argc == 4) ? argv[3] : argv[2],
11030 AFI_IP, safi, NULL, 1);
11031}
11032
11033ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11034 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11035 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11036 SHOW_STR
11037 BGP_STR
11038 "Address family\n"
11039 "Address Family modifier\n"
11040 "Address Family modifier\n"
11041 "Information about Route Server Client\n"
11042 NEIGHBOR_ADDR_STR
11043 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
fee0f4c6 11044
718e3744 11045#ifdef HAVE_IPV6
bb46e94f 11046DEFUN (show_bgp_view_neighbor_routes,
11047 show_bgp_view_neighbor_routes_cmd,
11048 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
718e3744 11049 SHOW_STR
11050 BGP_STR
bb46e94f 11051 "BGP view\n"
2b00515a 11052 "View name\n"
718e3744 11053 "Detailed information on TCP and BGP neighbor connections\n"
11054 "Neighbor to display information about\n"
11055 "Neighbor to display information about\n"
11056 "Display routes learned from neighbor\n")
11057{
bb46e94f 11058 struct peer *peer;
11059
11060 if (argc == 2)
11061 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11062 else
11063 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11064
11065 if (! peer)
11066 return CMD_WARNING;
11067
11068 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
718e3744 11069 bgp_show_type_neighbor);
11070}
11071
bb46e94f 11072ALIAS (show_bgp_view_neighbor_routes,
11073 show_bgp_view_ipv6_neighbor_routes_cmd,
11074 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11075 SHOW_STR
11076 BGP_STR
11077 "BGP view\n"
2b00515a 11078 "View name\n"
bb46e94f 11079 "Address family\n"
11080 "Detailed information on TCP and BGP neighbor connections\n"
11081 "Neighbor to display information about\n"
11082 "Neighbor to display information about\n"
11083 "Display routes learned from neighbor\n")
11084
11085DEFUN (show_bgp_view_neighbor_damp,
11086 show_bgp_view_neighbor_damp_cmd,
11087 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11088 SHOW_STR
11089 BGP_STR
11090 "BGP view\n"
2b00515a 11091 "View name\n"
bb46e94f 11092 "Detailed information on TCP and BGP neighbor connections\n"
11093 "Neighbor to display information about\n"
11094 "Neighbor to display information about\n"
11095 "Display the dampened routes received from neighbor\n")
11096{
11097 struct peer *peer;
11098
11099 if (argc == 2)
11100 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11101 else
11102 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11103
11104 if (! peer)
11105 return CMD_WARNING;
11106
11107 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11108 bgp_show_type_damp_neighbor);
11109}
11110
11111ALIAS (show_bgp_view_neighbor_damp,
11112 show_bgp_view_ipv6_neighbor_damp_cmd,
11113 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11114 SHOW_STR
11115 BGP_STR
11116 "BGP view\n"
2b00515a 11117 "View name\n"
bb46e94f 11118 "Address family\n"
11119 "Detailed information on TCP and BGP neighbor connections\n"
11120 "Neighbor to display information about\n"
11121 "Neighbor to display information about\n"
11122 "Display the dampened routes received from neighbor\n")
11123
11124DEFUN (show_bgp_view_neighbor_flap,
11125 show_bgp_view_neighbor_flap_cmd,
11126 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11127 SHOW_STR
11128 BGP_STR
11129 "BGP view\n"
2b00515a 11130 "View name\n"
bb46e94f 11131 "Detailed information on TCP and BGP neighbor connections\n"
11132 "Neighbor to display information about\n"
11133 "Neighbor to display information about\n"
11134 "Display flap statistics of the routes learned from neighbor\n")
11135{
11136 struct peer *peer;
11137
11138 if (argc == 2)
11139 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11140 else
11141 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11142
11143 if (! peer)
11144 return CMD_WARNING;
11145
11146 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11147 bgp_show_type_flap_neighbor);
11148}
11149
11150ALIAS (show_bgp_view_neighbor_flap,
11151 show_bgp_view_ipv6_neighbor_flap_cmd,
11152 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11153 SHOW_STR
11154 BGP_STR
11155 "BGP view\n"
2b00515a 11156 "View name\n"
bb46e94f 11157 "Address family\n"
11158 "Detailed information on TCP and BGP neighbor connections\n"
11159 "Neighbor to display information about\n"
11160 "Neighbor to display information about\n"
11161 "Display flap statistics of the routes learned from neighbor\n")
11162
11163ALIAS (show_bgp_view_neighbor_routes,
11164 show_bgp_neighbor_routes_cmd,
11165 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11166 SHOW_STR
11167 BGP_STR
11168 "Detailed information on TCP and BGP neighbor connections\n"
11169 "Neighbor to display information about\n"
11170 "Neighbor to display information about\n"
11171 "Display routes learned from neighbor\n")
11172
11173
11174ALIAS (show_bgp_view_neighbor_routes,
718e3744 11175 show_bgp_ipv6_neighbor_routes_cmd,
11176 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11177 SHOW_STR
11178 BGP_STR
11179 "Address family\n"
11180 "Detailed information on TCP and BGP neighbor connections\n"
11181 "Neighbor to display information about\n"
11182 "Neighbor to display information about\n"
11183 "Display routes learned from neighbor\n")
11184
11185/* old command */
bb46e94f 11186ALIAS (show_bgp_view_neighbor_routes,
718e3744 11187 ipv6_bgp_neighbor_routes_cmd,
11188 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11189 SHOW_STR
11190 IPV6_STR
11191 BGP_STR
11192 "Detailed information on TCP and BGP neighbor connections\n"
11193 "Neighbor to display information about\n"
11194 "Neighbor to display information about\n"
11195 "Display routes learned from neighbor\n")
718e3744 11196
11197/* old command */
11198DEFUN (ipv6_mbgp_neighbor_routes,
11199 ipv6_mbgp_neighbor_routes_cmd,
11200 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11201 SHOW_STR
11202 IPV6_STR
11203 MBGP_STR
11204 "Detailed information on TCP and BGP neighbor connections\n"
11205 "Neighbor to display information about\n"
11206 "Neighbor to display information about\n"
11207 "Display routes learned from neighbor\n")
11208{
bb46e94f 11209 struct peer *peer;
11210
11211 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11212 if (! peer)
11213 return CMD_WARNING;
11214
11215 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
718e3744 11216 bgp_show_type_neighbor);
11217}
bb46e94f 11218
11219ALIAS (show_bgp_view_neighbor_flap,
11220 show_bgp_neighbor_flap_cmd,
11221 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11222 SHOW_STR
11223 BGP_STR
11224 "Detailed information on TCP and BGP neighbor connections\n"
11225 "Neighbor to display information about\n"
11226 "Neighbor to display information about\n"
11227 "Display flap statistics of the routes learned from neighbor\n")
11228
11229ALIAS (show_bgp_view_neighbor_flap,
11230 show_bgp_ipv6_neighbor_flap_cmd,
11231 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11232 SHOW_STR
11233 BGP_STR
11234 "Address family\n"
11235 "Detailed information on TCP and BGP neighbor connections\n"
11236 "Neighbor to display information about\n"
11237 "Neighbor to display information about\n"
11238 "Display flap statistics of the routes learned from neighbor\n")
11239
11240ALIAS (show_bgp_view_neighbor_damp,
11241 show_bgp_neighbor_damp_cmd,
11242 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11243 SHOW_STR
11244 BGP_STR
11245 "Detailed information on TCP and BGP neighbor connections\n"
11246 "Neighbor to display information about\n"
11247 "Neighbor to display information about\n"
11248 "Display the dampened routes received from neighbor\n")
11249
11250ALIAS (show_bgp_view_neighbor_damp,
11251 show_bgp_ipv6_neighbor_damp_cmd,
11252 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11253 SHOW_STR
11254 BGP_STR
11255 "Address family\n"
11256 "Detailed information on TCP and BGP neighbor connections\n"
11257 "Neighbor to display information about\n"
11258 "Neighbor to display information about\n"
c001ae62 11259 "Display the dampened routes received from neighbor\n")
fee0f4c6 11260
11261DEFUN (show_bgp_view_rsclient,
11262 show_bgp_view_rsclient_cmd,
11263 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11264 SHOW_STR
11265 BGP_STR
11266 "BGP view\n"
2b00515a 11267 "View name\n"
fee0f4c6 11268 "Information about Route Server Client\n"
11269 NEIGHBOR_ADDR_STR)
11270{
11271 struct bgp_table *table;
11272 struct peer *peer;
11273
11274 if (argc == 2)
11275 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11276 else
11277 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11278
11279 if (! peer)
11280 return CMD_WARNING;
11281
11282 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11283 {
11284 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11285 VTY_NEWLINE);
11286 return CMD_WARNING;
11287 }
11288
11289 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11290 PEER_FLAG_RSERVER_CLIENT))
11291 {
11292 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11293 VTY_NEWLINE);
11294 return CMD_WARNING;
11295 }
11296
11297 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11298
5a646650 11299 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
fee0f4c6 11300}
11301
11302ALIAS (show_bgp_view_rsclient,
11303 show_bgp_rsclient_cmd,
11304 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11305 SHOW_STR
11306 BGP_STR
11307 "Information about Route Server Client\n"
11308 NEIGHBOR_ADDR_STR)
11309
95cbbd2a
ML
11310DEFUN (show_bgp_view_ipv6_safi_rsclient,
11311 show_bgp_view_ipv6_safi_rsclient_cmd,
11312 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11313 SHOW_STR
11314 BGP_STR
11315 "BGP view\n"
2b00515a 11316 "View name\n"
95cbbd2a
ML
11317 "Address family\n"
11318 "Address Family modifier\n"
11319 "Address Family modifier\n"
11320 "Information about Route Server Client\n"
11321 NEIGHBOR_ADDR_STR)
11322{
11323 struct bgp_table *table;
11324 struct peer *peer;
11325 safi_t safi;
11326
11327 if (argc == 3) {
11328 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11329 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11330 } else {
11331 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11332 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11333 }
11334
11335 if (! peer)
11336 return CMD_WARNING;
11337
11338 if (! peer->afc[AFI_IP6][safi])
11339 {
11340 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11341 VTY_NEWLINE);
11342 return CMD_WARNING;
11343 }
11344
11345 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11346 PEER_FLAG_RSERVER_CLIENT))
11347 {
11348 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11349 VTY_NEWLINE);
11350 return CMD_WARNING;
11351 }
11352
11353 table = peer->rib[AFI_IP6][safi];
11354
11355 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11356}
11357
11358ALIAS (show_bgp_view_ipv6_safi_rsclient,
11359 show_bgp_ipv6_safi_rsclient_cmd,
11360 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11361 SHOW_STR
11362 BGP_STR
11363 "Address family\n"
11364 "Address Family modifier\n"
11365 "Address Family modifier\n"
11366 "Information about Route Server Client\n"
11367 NEIGHBOR_ADDR_STR)
11368
fee0f4c6 11369DEFUN (show_bgp_view_rsclient_route,
11370 show_bgp_view_rsclient_route_cmd,
11371 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11372 SHOW_STR
11373 BGP_STR
11374 "BGP view\n"
2b00515a 11375 "View name\n"
fee0f4c6 11376 "Information about Route Server Client\n"
11377 NEIGHBOR_ADDR_STR
11378 "Network in the BGP routing table to display\n")
11379{
11380 struct bgp *bgp;
11381 struct peer *peer;
11382
11383 /* BGP structure lookup. */
11384 if (argc == 3)
11385 {
11386 bgp = bgp_lookup_by_name (argv[0]);
11387 if (bgp == NULL)
11388 {
11389 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11390 return CMD_WARNING;
11391 }
11392 }
11393 else
11394 {
11395 bgp = bgp_get_default ();
11396 if (bgp == NULL)
11397 {
11398 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11399 return CMD_WARNING;
11400 }
11401 }
11402
11403 if (argc == 3)
11404 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11405 else
11406 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11407
11408 if (! peer)
11409 return CMD_WARNING;
11410
11411 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11412 {
11413 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11414 VTY_NEWLINE);
11415 return CMD_WARNING;
11416 }
11417
11418 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11419 PEER_FLAG_RSERVER_CLIENT))
11420 {
11421 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11422 VTY_NEWLINE);
11423 return CMD_WARNING;
11424 }
11425
11426 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11427 (argc == 3) ? argv[2] : argv[1],
11428 AFI_IP6, SAFI_UNICAST, NULL, 0);
11429}
11430
11431ALIAS (show_bgp_view_rsclient_route,
11432 show_bgp_rsclient_route_cmd,
11433 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11434 SHOW_STR
11435 BGP_STR
11436 "Information about Route Server Client\n"
11437 NEIGHBOR_ADDR_STR
11438 "Network in the BGP routing table to display\n")
11439
95cbbd2a
ML
11440DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11441 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11442 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11443 SHOW_STR
11444 BGP_STR
11445 "BGP view\n"
2b00515a 11446 "View name\n"
95cbbd2a
ML
11447 "Address family\n"
11448 "Address Family modifier\n"
11449 "Address Family modifier\n"
11450 "Information about Route Server Client\n"
11451 NEIGHBOR_ADDR_STR
11452 "Network in the BGP routing table to display\n")
11453{
11454 struct bgp *bgp;
11455 struct peer *peer;
11456 safi_t safi;
11457
11458 /* BGP structure lookup. */
11459 if (argc == 4)
11460 {
11461 bgp = bgp_lookup_by_name (argv[0]);
11462 if (bgp == NULL)
11463 {
11464 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11465 return CMD_WARNING;
11466 }
11467 }
11468 else
11469 {
11470 bgp = bgp_get_default ();
11471 if (bgp == NULL)
11472 {
11473 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11474 return CMD_WARNING;
11475 }
11476 }
11477
11478 if (argc == 4) {
11479 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11480 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11481 } else {
11482 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11483 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11484 }
11485
11486 if (! peer)
11487 return CMD_WARNING;
11488
11489 if (! peer->afc[AFI_IP6][safi])
11490 {
11491 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11492 VTY_NEWLINE);
11493 return CMD_WARNING;
11494}
11495
11496 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11497 PEER_FLAG_RSERVER_CLIENT))
11498 {
11499 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11500 VTY_NEWLINE);
11501 return CMD_WARNING;
11502 }
11503
11504 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11505 (argc == 4) ? argv[3] : argv[2],
11506 AFI_IP6, safi, NULL, 0);
11507}
11508
11509ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11510 show_bgp_ipv6_safi_rsclient_route_cmd,
11511 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11512 SHOW_STR
11513 BGP_STR
11514 "Address family\n"
11515 "Address Family modifier\n"
11516 "Address Family modifier\n"
11517 "Information about Route Server Client\n"
11518 NEIGHBOR_ADDR_STR
11519 "Network in the BGP routing table to display\n")
11520
fee0f4c6 11521DEFUN (show_bgp_view_rsclient_prefix,
11522 show_bgp_view_rsclient_prefix_cmd,
11523 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11524 SHOW_STR
11525 BGP_STR
11526 "BGP view\n"
2b00515a 11527 "View name\n"
fee0f4c6 11528 "Information about Route Server Client\n"
11529 NEIGHBOR_ADDR_STR
11530 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11531{
11532 struct bgp *bgp;
11533 struct peer *peer;
11534
11535 /* BGP structure lookup. */
11536 if (argc == 3)
11537 {
11538 bgp = bgp_lookup_by_name (argv[0]);
11539 if (bgp == NULL)
11540 {
11541 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11542 return CMD_WARNING;
11543 }
11544 }
11545 else
11546 {
11547 bgp = bgp_get_default ();
11548 if (bgp == NULL)
11549 {
11550 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11551 return CMD_WARNING;
11552 }
11553 }
11554
11555 if (argc == 3)
11556 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11557 else
11558 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11559
11560 if (! peer)
11561 return CMD_WARNING;
11562
11563 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11564 {
11565 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11566 VTY_NEWLINE);
11567 return CMD_WARNING;
11568 }
11569
11570 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11571 PEER_FLAG_RSERVER_CLIENT))
11572 {
11573 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11574 VTY_NEWLINE);
11575 return CMD_WARNING;
11576 }
11577
11578 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11579 (argc == 3) ? argv[2] : argv[1],
11580 AFI_IP6, SAFI_UNICAST, NULL, 1);
11581}
11582
11583ALIAS (show_bgp_view_rsclient_prefix,
11584 show_bgp_rsclient_prefix_cmd,
11585 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11586 SHOW_STR
11587 BGP_STR
11588 "Information about Route Server Client\n"
11589 NEIGHBOR_ADDR_STR
11590 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11591
95cbbd2a
ML
11592DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11593 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11594 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11595 SHOW_STR
11596 BGP_STR
11597 "BGP view\n"
2b00515a 11598 "View name\n"
95cbbd2a
ML
11599 "Address family\n"
11600 "Address Family modifier\n"
11601 "Address Family modifier\n"
11602 "Information about Route Server Client\n"
11603 NEIGHBOR_ADDR_STR
11604 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11605{
11606 struct bgp *bgp;
11607 struct peer *peer;
11608 safi_t safi;
11609
11610 /* BGP structure lookup. */
11611 if (argc == 4)
11612 {
11613 bgp = bgp_lookup_by_name (argv[0]);
11614 if (bgp == NULL)
11615 {
11616 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11617 return CMD_WARNING;
11618 }
11619 }
11620 else
11621 {
11622 bgp = bgp_get_default ();
11623 if (bgp == NULL)
11624 {
11625 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11626 return CMD_WARNING;
11627 }
11628 }
11629
11630 if (argc == 4) {
11631 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11632 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11633 } else {
11634 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11635 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11636 }
11637
11638 if (! peer)
11639 return CMD_WARNING;
11640
11641 if (! peer->afc[AFI_IP6][safi])
11642 {
11643 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11644 VTY_NEWLINE);
11645 return CMD_WARNING;
11646}
11647
11648 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11649 PEER_FLAG_RSERVER_CLIENT))
11650{
11651 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11652 VTY_NEWLINE);
11653 return CMD_WARNING;
11654 }
11655
11656 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11657 (argc == 4) ? argv[3] : argv[2],
11658 AFI_IP6, safi, NULL, 1);
11659}
11660
11661ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11662 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11663 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11664 SHOW_STR
11665 BGP_STR
11666 "Address family\n"
11667 "Address Family modifier\n"
11668 "Address Family modifier\n"
11669 "Information about Route Server Client\n"
11670 NEIGHBOR_ADDR_STR
11671 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11672
718e3744 11673#endif /* HAVE_IPV6 */
11674\f
11675struct bgp_table *bgp_distance_table;
11676
11677struct bgp_distance
11678{
11679 /* Distance value for the IP source prefix. */
11680 u_char distance;
11681
11682 /* Name of the access-list to be matched. */
11683 char *access_list;
11684};
11685
94f2b392 11686static struct bgp_distance *
66e5cd87 11687bgp_distance_new (void)
718e3744 11688{
393deb9b 11689 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
718e3744 11690}
11691
94f2b392 11692static void
718e3744 11693bgp_distance_free (struct bgp_distance *bdistance)
11694{
11695 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11696}
11697
94f2b392 11698static int
fd79ac91 11699bgp_distance_set (struct vty *vty, const char *distance_str,
11700 const char *ip_str, const char *access_list_str)
718e3744 11701{
11702 int ret;
11703 struct prefix_ipv4 p;
11704 u_char distance;
11705 struct bgp_node *rn;
11706 struct bgp_distance *bdistance;
11707
11708 ret = str2prefix_ipv4 (ip_str, &p);
11709 if (ret == 0)
11710 {
11711 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11712 return CMD_WARNING;
11713 }
11714
11715 distance = atoi (distance_str);
11716
11717 /* Get BGP distance node. */
11718 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11719 if (rn->info)
11720 {
11721 bdistance = rn->info;
11722 bgp_unlock_node (rn);
11723 }
11724 else
11725 {
11726 bdistance = bgp_distance_new ();
11727 rn->info = bdistance;
11728 }
11729
11730 /* Set distance value. */
11731 bdistance->distance = distance;
11732
11733 /* Reset access-list configuration. */
11734 if (bdistance->access_list)
11735 {
11736 free (bdistance->access_list);
11737 bdistance->access_list = NULL;
11738 }
11739 if (access_list_str)
11740 bdistance->access_list = strdup (access_list_str);
11741
11742 return CMD_SUCCESS;
11743}
11744
94f2b392 11745static int
fd79ac91 11746bgp_distance_unset (struct vty *vty, const char *distance_str,
11747 const char *ip_str, const char *access_list_str)
718e3744 11748{
11749 int ret;
11750 struct prefix_ipv4 p;
11751 u_char distance;
11752 struct bgp_node *rn;
11753 struct bgp_distance *bdistance;
11754
11755 ret = str2prefix_ipv4 (ip_str, &p);
11756 if (ret == 0)
11757 {
11758 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11759 return CMD_WARNING;
11760 }
11761
11762 distance = atoi (distance_str);
11763
11764 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11765 if (! rn)
11766 {
11767 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11768 return CMD_WARNING;
11769 }
11770
11771 bdistance = rn->info;
11772
11773 if (bdistance->access_list)
11774 free (bdistance->access_list);
11775 bgp_distance_free (bdistance);
11776
11777 rn->info = NULL;
11778 bgp_unlock_node (rn);
11779 bgp_unlock_node (rn);
11780
11781 return CMD_SUCCESS;
11782}
11783
718e3744 11784/* Apply BGP information to distance method. */
11785u_char
11786bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11787{
11788 struct bgp_node *rn;
11789 struct prefix_ipv4 q;
11790 struct peer *peer;
11791 struct bgp_distance *bdistance;
11792 struct access_list *alist;
11793 struct bgp_static *bgp_static;
11794
11795 if (! bgp)
11796 return 0;
11797
11798 if (p->family != AF_INET)
11799 return 0;
11800
11801 peer = rinfo->peer;
11802
11803 if (peer->su.sa.sa_family != AF_INET)
11804 return 0;
11805
11806 memset (&q, 0, sizeof (struct prefix_ipv4));
11807 q.family = AF_INET;
11808 q.prefix = peer->su.sin.sin_addr;
11809 q.prefixlen = IPV4_MAX_BITLEN;
11810
11811 /* Check source address. */
11812 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11813 if (rn)
11814 {
11815 bdistance = rn->info;
11816 bgp_unlock_node (rn);
11817
11818 if (bdistance->access_list)
11819 {
11820 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11821 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11822 return bdistance->distance;
11823 }
11824 else
11825 return bdistance->distance;
11826 }
11827
11828 /* Backdoor check. */
11829 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11830 if (rn)
11831 {
11832 bgp_static = rn->info;
11833 bgp_unlock_node (rn);
11834
11835 if (bgp_static->backdoor)
11836 {
11837 if (bgp->distance_local)
11838 return bgp->distance_local;
11839 else
11840 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11841 }
11842 }
11843
6d85b15b 11844 if (peer->sort == BGP_PEER_EBGP)
718e3744 11845 {
11846 if (bgp->distance_ebgp)
11847 return bgp->distance_ebgp;
11848 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11849 }
11850 else
11851 {
11852 if (bgp->distance_ibgp)
11853 return bgp->distance_ibgp;
11854 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11855 }
11856}
11857
11858DEFUN (bgp_distance,
11859 bgp_distance_cmd,
11860 "distance bgp <1-255> <1-255> <1-255>",
11861 "Define an administrative distance\n"
11862 "BGP distance\n"
11863 "Distance for routes external to the AS\n"
11864 "Distance for routes internal to the AS\n"
11865 "Distance for local routes\n")
11866{
11867 struct bgp *bgp;
11868
11869 bgp = vty->index;
11870
11871 bgp->distance_ebgp = atoi (argv[0]);
11872 bgp->distance_ibgp = atoi (argv[1]);
11873 bgp->distance_local = atoi (argv[2]);
11874 return CMD_SUCCESS;
11875}
11876
11877DEFUN (no_bgp_distance,
11878 no_bgp_distance_cmd,
11879 "no distance bgp <1-255> <1-255> <1-255>",
11880 NO_STR
11881 "Define an administrative distance\n"
11882 "BGP distance\n"
11883 "Distance for routes external to the AS\n"
11884 "Distance for routes internal to the AS\n"
11885 "Distance for local routes\n")
11886{
11887 struct bgp *bgp;
11888
11889 bgp = vty->index;
11890
11891 bgp->distance_ebgp= 0;
11892 bgp->distance_ibgp = 0;
11893 bgp->distance_local = 0;
11894 return CMD_SUCCESS;
11895}
11896
11897ALIAS (no_bgp_distance,
11898 no_bgp_distance2_cmd,
11899 "no distance bgp",
11900 NO_STR
11901 "Define an administrative distance\n"
11902 "BGP distance\n")
11903
11904DEFUN (bgp_distance_source,
11905 bgp_distance_source_cmd,
11906 "distance <1-255> A.B.C.D/M",
11907 "Define an administrative distance\n"
11908 "Administrative distance\n"
11909 "IP source prefix\n")
11910{
11911 bgp_distance_set (vty, argv[0], argv[1], NULL);
11912 return CMD_SUCCESS;
11913}
11914
11915DEFUN (no_bgp_distance_source,
11916 no_bgp_distance_source_cmd,
11917 "no distance <1-255> A.B.C.D/M",
11918 NO_STR
11919 "Define an administrative distance\n"
11920 "Administrative distance\n"
11921 "IP source prefix\n")
11922{
11923 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11924 return CMD_SUCCESS;
11925}
11926
11927DEFUN (bgp_distance_source_access_list,
11928 bgp_distance_source_access_list_cmd,
11929 "distance <1-255> A.B.C.D/M WORD",
11930 "Define an administrative distance\n"
11931 "Administrative distance\n"
11932 "IP source prefix\n"
11933 "Access list name\n")
11934{
11935 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11936 return CMD_SUCCESS;
11937}
11938
11939DEFUN (no_bgp_distance_source_access_list,
11940 no_bgp_distance_source_access_list_cmd,
11941 "no distance <1-255> A.B.C.D/M WORD",
11942 NO_STR
11943 "Define an administrative distance\n"
11944 "Administrative distance\n"
11945 "IP source prefix\n"
11946 "Access list name\n")
11947{
11948 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11949 return CMD_SUCCESS;
11950}
11951\f
11952DEFUN (bgp_damp_set,
11953 bgp_damp_set_cmd,
11954 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11955 "BGP Specific commands\n"
11956 "Enable route-flap dampening\n"
11957 "Half-life time for the penalty\n"
11958 "Value to start reusing a route\n"
11959 "Value to start suppressing a route\n"
11960 "Maximum duration to suppress a stable route\n")
11961{
11962 struct bgp *bgp;
11963 int half = DEFAULT_HALF_LIFE * 60;
11964 int reuse = DEFAULT_REUSE;
11965 int suppress = DEFAULT_SUPPRESS;
11966 int max = 4 * half;
11967
11968 if (argc == 4)
11969 {
11970 half = atoi (argv[0]) * 60;
11971 reuse = atoi (argv[1]);
11972 suppress = atoi (argv[2]);
11973 max = atoi (argv[3]) * 60;
11974 }
11975 else if (argc == 1)
11976 {
11977 half = atoi (argv[0]) * 60;
11978 max = 4 * half;
11979 }
11980
11981 bgp = vty->index;
11982 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11983 half, reuse, suppress, max);
11984}
11985
11986ALIAS (bgp_damp_set,
11987 bgp_damp_set2_cmd,
11988 "bgp dampening <1-45>",
11989 "BGP Specific commands\n"
11990 "Enable route-flap dampening\n"
11991 "Half-life time for the penalty\n")
11992
11993ALIAS (bgp_damp_set,
11994 bgp_damp_set3_cmd,
11995 "bgp dampening",
11996 "BGP Specific commands\n"
11997 "Enable route-flap dampening\n")
11998
11999DEFUN (bgp_damp_unset,
12000 bgp_damp_unset_cmd,
12001 "no bgp dampening",
12002 NO_STR
12003 "BGP Specific commands\n"
12004 "Enable route-flap dampening\n")
12005{
12006 struct bgp *bgp;
12007
12008 bgp = vty->index;
12009 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12010}
12011
12012ALIAS (bgp_damp_unset,
12013 bgp_damp_unset2_cmd,
12014 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12015 NO_STR
12016 "BGP Specific commands\n"
12017 "Enable route-flap dampening\n"
12018 "Half-life time for the penalty\n"
12019 "Value to start reusing a route\n"
12020 "Value to start suppressing a route\n"
12021 "Maximum duration to suppress a stable route\n")
12022
12023DEFUN (show_ip_bgp_dampened_paths,
12024 show_ip_bgp_dampened_paths_cmd,
12025 "show ip bgp dampened-paths",
12026 SHOW_STR
12027 IP_STR
12028 BGP_STR
12029 "Display paths suppressed due to dampening\n")
12030{
5a646650 12031 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12032 NULL);
718e3744 12033}
12034
12035DEFUN (show_ip_bgp_flap_statistics,
12036 show_ip_bgp_flap_statistics_cmd,
12037 "show ip bgp flap-statistics",
12038 SHOW_STR
12039 IP_STR
12040 BGP_STR
12041 "Display flap statistics of routes\n")
12042{
5a646650 12043 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12044 bgp_show_type_flap_statistics, NULL);
718e3744 12045}
12046\f
12047/* Display specified route of BGP table. */
94f2b392 12048static int
fd79ac91 12049bgp_clear_damp_route (struct vty *vty, const char *view_name,
12050 const char *ip_str, afi_t afi, safi_t safi,
12051 struct prefix_rd *prd, int prefix_check)
718e3744 12052{
12053 int ret;
12054 struct prefix match;
12055 struct bgp_node *rn;
12056 struct bgp_node *rm;
12057 struct bgp_info *ri;
12058 struct bgp_info *ri_temp;
12059 struct bgp *bgp;
12060 struct bgp_table *table;
12061
12062 /* BGP structure lookup. */
12063 if (view_name)
12064 {
12065 bgp = bgp_lookup_by_name (view_name);
12066 if (bgp == NULL)
12067 {
12068 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12069 return CMD_WARNING;
12070 }
12071 }
12072 else
12073 {
12074 bgp = bgp_get_default ();
12075 if (bgp == NULL)
12076 {
12077 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12078 return CMD_WARNING;
12079 }
12080 }
12081
12082 /* Check IP address argument. */
12083 ret = str2prefix (ip_str, &match);
12084 if (! ret)
12085 {
12086 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12087 return CMD_WARNING;
12088 }
12089
12090 match.family = afi2family (afi);
12091
12092 if (safi == SAFI_MPLS_VPN)
12093 {
12094 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12095 {
12096 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12097 continue;
12098
12099 if ((table = rn->info) != NULL)
12100 if ((rm = bgp_node_match (table, &match)) != NULL)
6c88b44d
CC
12101 {
12102 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12103 {
12104 ri = rm->info;
12105 while (ri)
12106 {
12107 if (ri->extra && ri->extra->damp_info)
12108 {
12109 ri_temp = ri->next;
12110 bgp_damp_info_free (ri->extra->damp_info, 1);
12111 ri = ri_temp;
12112 }
12113 else
12114 ri = ri->next;
12115 }
12116 }
12117
12118 bgp_unlock_node (rm);
12119 }
718e3744 12120 }
12121 }
12122 else
12123 {
12124 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
6c88b44d
CC
12125 {
12126 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12127 {
12128 ri = rn->info;
12129 while (ri)
12130 {
12131 if (ri->extra && ri->extra->damp_info)
12132 {
12133 ri_temp = ri->next;
12134 bgp_damp_info_free (ri->extra->damp_info, 1);
12135 ri = ri_temp;
12136 }
12137 else
12138 ri = ri->next;
12139 }
12140 }
12141
12142 bgp_unlock_node (rn);
12143 }
718e3744 12144 }
12145
12146 return CMD_SUCCESS;
12147}
12148
12149DEFUN (clear_ip_bgp_dampening,
12150 clear_ip_bgp_dampening_cmd,
12151 "clear ip bgp dampening",
12152 CLEAR_STR
12153 IP_STR
12154 BGP_STR
12155 "Clear route flap dampening information\n")
12156{
12157 bgp_damp_info_clean ();
12158 return CMD_SUCCESS;
12159}
12160
12161DEFUN (clear_ip_bgp_dampening_prefix,
12162 clear_ip_bgp_dampening_prefix_cmd,
12163 "clear ip bgp dampening A.B.C.D/M",
12164 CLEAR_STR
12165 IP_STR
12166 BGP_STR
12167 "Clear route flap dampening information\n"
12168 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12169{
12170 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12171 SAFI_UNICAST, NULL, 1);
12172}
12173
12174DEFUN (clear_ip_bgp_dampening_address,
12175 clear_ip_bgp_dampening_address_cmd,
12176 "clear ip bgp dampening A.B.C.D",
12177 CLEAR_STR
12178 IP_STR
12179 BGP_STR
12180 "Clear route flap dampening information\n"
12181 "Network to clear damping information\n")
12182{
12183 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12184 SAFI_UNICAST, NULL, 0);
12185}
12186
12187DEFUN (clear_ip_bgp_dampening_address_mask,
12188 clear_ip_bgp_dampening_address_mask_cmd,
12189 "clear ip bgp dampening A.B.C.D A.B.C.D",
12190 CLEAR_STR
12191 IP_STR
12192 BGP_STR
12193 "Clear route flap dampening information\n"
12194 "Network to clear damping information\n"
12195 "Network mask\n")
12196{
12197 int ret;
12198 char prefix_str[BUFSIZ];
12199
12200 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12201 if (! ret)
12202 {
12203 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12204 return CMD_WARNING;
12205 }
12206
12207 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12208 SAFI_UNICAST, NULL, 0);
12209}
12210\f
94f2b392 12211static int
718e3744 12212bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12213 afi_t afi, safi_t safi, int *write)
12214{
12215 struct bgp_node *prn;
12216 struct bgp_node *rn;
12217 struct bgp_table *table;
12218 struct prefix *p;
12219 struct prefix_rd *prd;
12220 struct bgp_static *bgp_static;
12221 u_int32_t label;
12222 char buf[SU_ADDRSTRLEN];
12223 char rdbuf[RD_ADDRSTRLEN];
12224
12225 /* Network configuration. */
12226 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12227 if ((table = prn->info) != NULL)
12228 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12229 if ((bgp_static = rn->info) != NULL)
12230 {
12231 p = &rn->p;
12232 prd = (struct prefix_rd *) &prn->p;
12233
12234 /* "address-family" display. */
12235 bgp_config_write_family_header (vty, afi, safi, write);
12236
12237 /* "network" configuration display. */
12238 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12239 label = decode_label (bgp_static->tag);
12240
12241 vty_out (vty, " network %s/%d rd %s tag %d",
12242 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12243 p->prefixlen,
12244 rdbuf, label);
12245 vty_out (vty, "%s", VTY_NEWLINE);
12246 }
12247 return 0;
12248}
12249
12250/* Configuration of static route announcement and aggregate
12251 information. */
12252int
12253bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12254 afi_t afi, safi_t safi, int *write)
12255{
12256 struct bgp_node *rn;
12257 struct prefix *p;
12258 struct bgp_static *bgp_static;
12259 struct bgp_aggregate *bgp_aggregate;
12260 char buf[SU_ADDRSTRLEN];
12261
12262 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12263 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12264
12265 /* Network configuration. */
12266 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12267 if ((bgp_static = rn->info) != NULL)
12268 {
12269 p = &rn->p;
12270
12271 /* "address-family" display. */
12272 bgp_config_write_family_header (vty, afi, safi, write);
12273
12274 /* "network" configuration display. */
12275 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12276 {
12277 u_int32_t destination;
12278 struct in_addr netmask;
12279
12280 destination = ntohl (p->u.prefix4.s_addr);
12281 masklen2ip (p->prefixlen, &netmask);
12282 vty_out (vty, " network %s",
12283 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12284
12285 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12286 || (IN_CLASSB (destination) && p->prefixlen == 16)
12287 || (IN_CLASSA (destination) && p->prefixlen == 8)
12288 || p->u.prefix4.s_addr == 0)
12289 {
12290 /* Natural mask is not display. */
12291 }
12292 else
12293 vty_out (vty, " mask %s", inet_ntoa (netmask));
12294 }
12295 else
12296 {
12297 vty_out (vty, " network %s/%d",
12298 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12299 p->prefixlen);
12300 }
12301
12302 if (bgp_static->rmap.name)
12303 vty_out (vty, " route-map %s", bgp_static->rmap.name);
41367172
PJ
12304 else
12305 {
12306 if (bgp_static->backdoor)
12307 vty_out (vty, " backdoor");
41367172 12308 }
718e3744 12309
12310 vty_out (vty, "%s", VTY_NEWLINE);
12311 }
12312
12313 /* Aggregate-address configuration. */
12314 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12315 if ((bgp_aggregate = rn->info) != NULL)
12316 {
12317 p = &rn->p;
12318
12319 /* "address-family" display. */
12320 bgp_config_write_family_header (vty, afi, safi, write);
12321
12322 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12323 {
12324 struct in_addr netmask;
12325
12326 masklen2ip (p->prefixlen, &netmask);
12327 vty_out (vty, " aggregate-address %s %s",
12328 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12329 inet_ntoa (netmask));
12330 }
12331 else
12332 {
12333 vty_out (vty, " aggregate-address %s/%d",
12334 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12335 p->prefixlen);
12336 }
12337
12338 if (bgp_aggregate->as_set)
12339 vty_out (vty, " as-set");
12340
12341 if (bgp_aggregate->summary_only)
12342 vty_out (vty, " summary-only");
12343
12344 vty_out (vty, "%s", VTY_NEWLINE);
12345 }
12346
12347 return 0;
12348}
12349
12350int
12351bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12352{
12353 struct bgp_node *rn;
12354 struct bgp_distance *bdistance;
12355
12356 /* Distance configuration. */
12357 if (bgp->distance_ebgp
12358 && bgp->distance_ibgp
12359 && bgp->distance_local
12360 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12361 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12362 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12363 vty_out (vty, " distance bgp %d %d %d%s",
12364 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12365 VTY_NEWLINE);
12366
12367 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12368 if ((bdistance = rn->info) != NULL)
12369 {
12370 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12371 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12372 bdistance->access_list ? bdistance->access_list : "",
12373 VTY_NEWLINE);
12374 }
12375
12376 return 0;
12377}
12378
12379/* Allocate routing table structure and install commands. */
12380void
66e5cd87 12381bgp_route_init (void)
718e3744 12382{
12383 /* Init BGP distance table. */
64e580a7 12384 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
718e3744 12385
12386 /* IPv4 BGP commands. */
12387 install_element (BGP_NODE, &bgp_network_cmd);
12388 install_element (BGP_NODE, &bgp_network_mask_cmd);
12389 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12390 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12391 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12392 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12393 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12394 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12395 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12396 install_element (BGP_NODE, &no_bgp_network_cmd);
12397 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12398 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12399 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12400 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12401 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12402 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12403 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12404 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12405
12406 install_element (BGP_NODE, &aggregate_address_cmd);
12407 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12408 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12409 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12410 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12411 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12412 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12413 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12414 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12415 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12416 install_element (BGP_NODE, &no_aggregate_address_cmd);
12417 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12418 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12419 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12420 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12421 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12422 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12423 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12424 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12425 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12426
12427 /* IPv4 unicast configuration. */
12428 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12429 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12430 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12431 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12432 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12433 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
c8f3fe30 12434 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
718e3744 12435 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12436 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12437 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12438 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12439 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
c8f3fe30 12440
718e3744 12441 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12442 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12443 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12444 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12445 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12446 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12447 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12448 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12449 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12450 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12451 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12452 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12453 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12454 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12455 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12456 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12457 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12458 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12459 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12460 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12461
12462 /* IPv4 multicast configuration. */
12463 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12464 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12465 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12466 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12467 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12468 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12469 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12470 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12471 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12472 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12473 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12474 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12475 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12476 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12477 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12478 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12479 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12480 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12481 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12482 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12483 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12484 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12485 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12486 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12487 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12488 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12489 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12490 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12491 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12492 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12493 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12494 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12495
12496 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12497 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 12498 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
718e3744 12499 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 12501 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 12502 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12505 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
95cbbd2a 12506 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
718e3744 12507 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12508 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12515 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12516 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12517 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12528 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12529 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12530 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12531 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
12532 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12533 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12534 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12535 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12536 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
718e3744 12537 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12538 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12539 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12540 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12541 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12542 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12543 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12544 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12545 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12546 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12547 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12548 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12549 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12550 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12551 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12552 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12553 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12554 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
95cbbd2a 12555 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 12556 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12557 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12558 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12559 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12560 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12561 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12562 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12563 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12564 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12565 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12566 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12567 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12568 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12569 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12570 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12571 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
fee0f4c6 12572 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
95cbbd2a 12573 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
fee0f4c6 12574 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 12575 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
fee0f4c6 12576 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 12577 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
2a71e9ce
TP
12578 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12579 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
fee0f4c6 12580 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
95cbbd2a 12581 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
fee0f4c6 12582 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 12583 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
fee0f4c6 12584 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 12585 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
62687ff1
PJ
12586
12587 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12588 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12589 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 12590 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
62687ff1
PJ
12591 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12592 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12593 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
95cbbd2a 12594 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
62687ff1
PJ
12595 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12596 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12597 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12598 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12599 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12600 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12601 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12602 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12603 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12604 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12605 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12606 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
12607 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12608 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12609 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12610 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12611 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
62687ff1
PJ
12612 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12613 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12614 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12615 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12616 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12617 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12618 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12619 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12620 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 12621 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
62687ff1 12622 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 12623 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
62687ff1 12624 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 12625 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
62687ff1 12626 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 12627 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
718e3744 12628
12629 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12630 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
95cbbd2a 12631 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
718e3744 12632 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
95cbbd2a 12634 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
718e3744 12635 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12638 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
95cbbd2a 12639 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
718e3744 12640 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12641 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12648 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12649 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12650 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12661 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12662 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12663 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12664 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
95cbbd2a
ML
12665 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12666 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12667 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12668 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12669 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
718e3744 12670 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12671 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12672 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12673 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12674 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12675 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12676 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12677 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12678 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12679 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12680 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12681 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12682 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12683 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12684 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12685 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12686 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12687 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
95cbbd2a 12688 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
718e3744 12689 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12690 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12691 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12692 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12693 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12694 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12695 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12696 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12697 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12698 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12699 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12700 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12701 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12702 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12703 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12704 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
fee0f4c6 12705 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
95cbbd2a 12706 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
fee0f4c6 12707 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
95cbbd2a 12708 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
fee0f4c6 12709 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
95cbbd2a 12710 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
2a71e9ce
TP
12711 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12712 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
fee0f4c6 12713 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
95cbbd2a 12714 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
fee0f4c6 12715 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
95cbbd2a 12716 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
fee0f4c6 12717 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
95cbbd2a 12718 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
718e3744 12719
12720 /* BGP dampening clear commands */
12721 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12722 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12723 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12724 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12725
ff7924f6
PJ
12726 /* prefix count */
12727 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12728 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12729 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
718e3744 12730#ifdef HAVE_IPV6
ff7924f6
PJ
12731 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12732
718e3744 12733 /* New config IPv6 BGP commands. */
12734 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12735 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12736 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12737 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12738
12739 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12740 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12741 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12742 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
73bfe0bd
B
12743
12744 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12745 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
718e3744 12746
12747 /* Old config IPv6 BGP commands. */
12748 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12749 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12750
12751 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12752 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12753 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12754 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12755
12756 install_element (VIEW_NODE, &show_bgp_cmd);
12757 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 12758 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 12759 install_element (VIEW_NODE, &show_bgp_route_cmd);
12760 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 12761 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
718e3744 12762 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12763 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 12764 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
718e3744 12765 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12766 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12767 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12768 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12769 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12770 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12771 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12772 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12773 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12774 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12775 install_element (VIEW_NODE, &show_bgp_community_cmd);
12776 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12777 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12778 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12779 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12780 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12781 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12782 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12783 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12784 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12785 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12786 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12787 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12788 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12789 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12790 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12791 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12792 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12793 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12794 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12795 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12796 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12797 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12798 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12799 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12800 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12801 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12802 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12803 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12804 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 12805 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12806 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12807 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12808 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
fee0f4c6 12809 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
95cbbd2a 12810 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
fee0f4c6 12811 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 12812 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
fee0f4c6 12813 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 12814 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
bb46e94f 12815 install_element (VIEW_NODE, &show_bgp_view_cmd);
12816 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12817 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12818 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12819 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12820 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12821 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12822 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12823 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12824 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12825 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12826 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12827 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12828 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12829 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12830 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12831 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12832 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
fee0f4c6 12833 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
95cbbd2a 12834 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
fee0f4c6 12835 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 12836 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
fee0f4c6 12837 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 12838 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
62687ff1
PJ
12839
12840 /* Restricted:
12841 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12842 */
12843 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12844 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 12845 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
62687ff1
PJ
12846 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12847 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 12848 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
62687ff1
PJ
12849 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12850 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12851 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12852 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12853 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12854 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12855 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12856 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12857 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12858 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12859 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12860 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12861 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12862 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12863 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12864 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12865 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 12866 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
62687ff1 12867 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 12868 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
62687ff1
PJ
12869 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12870 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12871 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12872 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12873 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12874 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12875 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 12876 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
62687ff1 12877 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 12878 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
718e3744 12879
12880 install_element (ENABLE_NODE, &show_bgp_cmd);
12881 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
95cbbd2a 12882 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
718e3744 12883 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12884 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
95cbbd2a 12885 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
718e3744 12886 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
95cbbd2a 12888 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
718e3744 12889 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12890 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12892 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12895 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12914 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12916 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12917 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12918 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12919 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12920 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12921 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12922 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12923 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12924 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12925 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
bb46e94f 12929 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12930 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12931 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12932 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
fee0f4c6 12933 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
95cbbd2a 12934 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
fee0f4c6 12935 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
95cbbd2a 12936 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
fee0f4c6 12937 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
95cbbd2a 12938 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
bb46e94f 12939 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12940 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12941 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12942 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12943 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12944 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12945 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12946 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12947 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12948 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12949 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12950 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12951 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12952 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12953 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12954 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12955 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12956 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
fee0f4c6 12957 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
95cbbd2a 12958 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
fee0f4c6 12959 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
95cbbd2a 12960 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
fee0f4c6 12961 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
95cbbd2a 12962 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
2815e61f
PJ
12963
12964 /* Statistics */
12965 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12966 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12967 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12968 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12969
718e3744 12970 /* old command */
12971 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12972 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12973 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12974 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12975 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12976 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12977 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12978 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12979 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12980 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12981 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12982 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12983 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12984 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12985 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12986 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12987 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12988 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12989 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12990 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12991 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12992 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12993 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12994 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12995 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12996 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12997 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12998 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12999 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13000 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13001 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13002 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13003 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13004 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13005 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13006 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
bb46e94f 13007
718e3744 13008 /* old command */
13009 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13010 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13011 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13012 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13013 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13014 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13015 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13016 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13017 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13018 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13019 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13020 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13021 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13022 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13023 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13024 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13025 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13026 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13027 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13028 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13029 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13030 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13031 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13032 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13033 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13034 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13035 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13036 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13037 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13038 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13039 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13040 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13041 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13042 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13043 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13044 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13045
13046 /* old command */
13047 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13048 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13049 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13050 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13051
13052 /* old command */
13053 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13054 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13055 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13056 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13057
13058 /* old command */
13059 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13060 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13061 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13062 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13063#endif /* HAVE_IPV6 */
13064
13065 install_element (BGP_NODE, &bgp_distance_cmd);
13066 install_element (BGP_NODE, &no_bgp_distance_cmd);
13067 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13068 install_element (BGP_NODE, &bgp_distance_source_cmd);
13069 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13070 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13071 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13072
13073 install_element (BGP_NODE, &bgp_damp_set_cmd);
13074 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13075 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13076 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13077 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13078 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13079 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13080 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13081 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13082 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
c8f3fe30
PJ
13083
13084 /* Deprecated AS-Pathlimit commands */
13085 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13086 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13087 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13088 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13089 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13090 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13091
13092 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13093 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13094 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13095 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13096 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13097 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13098
13099 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13100 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13101 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13102 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13103 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13104 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13105
13106 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13107 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13108 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13109 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13110 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13111 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13112
13113 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13114 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13115 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13116 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13117 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13118 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13119
13120 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13121 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13122 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13123 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13124 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13125 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
3bde17f1
PJ
13126
13127#ifdef HAVE_IPV6
c8f3fe30
PJ
13128 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13129 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
3bde17f1 13130#endif
718e3744 13131}
228da428
CC
13132
13133void
13134bgp_route_finish (void)
13135{
13136 bgp_table_unlock (bgp_distance_table);
13137 bgp_distance_table = NULL;
13138}